data-modelling-sdk 1.1.0

Shared SDK for model operations across platforms (API, WASM, Native)
Documentation

Data Modelling SDK

Shared SDK for model operations across platforms (API, WASM, Native).

Copyright (c) 2025 Mark Olliver - Licensed under MIT

Features

  • Storage Backends: File system, browser storage (IndexedDB/localStorage), and HTTP API
  • Model Loading/Saving: Load and save models from various storage backends
  • Import/Export: Import from SQL, ODCL, JSON Schema, AVRO, Protobuf; Export to various formats
  • Validation: Table and relationship validation (naming conflicts, circular dependencies)

Usage

File System Backend (Native Apps)

use data_modelling_sdk::storage::filesystem::FileSystemStorageBackend;
use data_modelling_sdk::model::ModelLoader;

let storage = FileSystemStorageBackend::new("/path/to/workspace");
let loader = ModelLoader::new(storage);
let result = loader.load_model("workspace_path").await?;

Browser Storage Backend (WASM Apps)

use data_modelling_sdk::storage::browser::BrowserStorageBackend;
use data_modelling_sdk::model::ModelLoader;

let storage = BrowserStorageBackend::new("db_name", "store_name");
let loader = ModelLoader::new(storage);
let result = loader.load_model("workspace_path").await?;

API Backend (Online Mode)

use data_modelling_sdk::storage::api::ApiStorageBackend;
use data_modelling_sdk::model::ModelLoader;

let storage = ApiStorageBackend::new("http://localhost:8081/api/v1", Some("session_id"));
let loader = ModelLoader::new(storage);
let result = loader.load_model("workspace_path").await?;

WASM Bindings (Browser/Offline Mode)

The SDK exposes WASM bindings for parsing and export operations, enabling offline functionality in web applications.

Build the WASM module:

wasm-pack build --target web --out-dir pkg --features wasm

Use in JavaScript/TypeScript:

import init, { parseOdcsYaml, exportToOdcsYaml } from './pkg/data_modelling_sdk.js';

// Initialize the module
await init();

// Parse ODCS YAML
const yaml = `apiVersion: v3.1.0
kind: DataContract
name: users
schema:
  fields:
    - name: id
      type: bigint`;

const resultJson = parseOdcsYaml(yaml);
const result = JSON.parse(resultJson);
console.log('Parsed tables:', result.tables);

// Export to ODCS YAML
const workspace = {
  tables: [{
    id: "550e8400-e29b-41d4-a716-446655440000",
    name: "users",
    columns: [{ name: "id", data_type: "bigint", nullable: false, primary_key: true }]
  }],
  relationships: []
};

const exportedYaml = exportToOdcsYaml(JSON.stringify(workspace));
console.log('Exported YAML:', exportedYaml);

Available WASM Functions:

  • parseOdcsYaml(yamlContent: string): string - Parse ODCS YAML to workspace structure
  • exportToOdcsYaml(workspaceJson: string): string - Export workspace to ODCS YAML
  • importFromSql(sqlContent: string, dialect: string): string - Import from SQL
  • importFromAvro(avroContent: string): string - Import from AVRO schema
  • importFromJsonSchema(jsonSchemaContent: string): string - Import from JSON Schema
  • importFromProtobuf(protobufContent: string): string - Import from Protobuf
  • exportToSql(workspaceJson: string, dialect: string): string - Export to SQL
  • exportToAvro(workspaceJson: string): string - Export to AVRO schema
  • exportToJsonSchema(workspaceJson: string): string - Export to JSON Schema
  • exportToProtobuf(workspaceJson: string): string - Export to Protobuf

Development

Pre-commit Hooks

This project uses pre-commit hooks to ensure code quality. Install them with:

# Install pre-commit (if not already installed)
pip install pre-commit

# Install the git hooks
pre-commit install

# Run hooks manually on all files
pre-commit run --all-files

The hooks will automatically run on git commit and check:

  • Rust formatting (cargo fmt)
  • Rust linting (cargo clippy)
  • Security audit (cargo audit)
  • File formatting (trailing whitespace, end of file, etc.)
  • YAML/TOML/JSON syntax

CI/CD

GitHub Actions workflows automatically run on push and pull requests:

  • Lint: Format check, clippy, and security audit
  • Test: Unit and integration tests on Linux, macOS, and Windows
  • Build: Release build verification
  • Publish: Automatic publishing to crates.io on main branch (after all checks pass)

Status

The SDK structure is in place. The actual implementation of import/export/validation logic is being migrated incrementally from the parent crate. Currently, the SDK provides:

  • ✅ Storage backend abstraction and implementations
  • ✅ Model loader/saver structure
  • ✅ Import/export module structure
  • ✅ Validation module structure
  • ⏳ Full implementation of parsers/exporters (in progress)