@panproto/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -353,7 +353,13 @@ class SchemaBuilder {
|
|
|
353
353
|
),
|
|
354
354
|
required: Object.fromEntries(
|
|
355
355
|
Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]])
|
|
356
|
-
)
|
|
356
|
+
),
|
|
357
|
+
variants: {},
|
|
358
|
+
orderings: {},
|
|
359
|
+
recursionPoints: {},
|
|
360
|
+
usageModes: {},
|
|
361
|
+
spans: {},
|
|
362
|
+
nominal: {}
|
|
357
363
|
};
|
|
358
364
|
return new BuiltSchema(handle, data, this.#wasm);
|
|
359
365
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/types.ts","../src/wasm.ts","../src/msgpack.ts","../src/schema.ts","../src/protocol.ts","../src/migration.ts","../src/panproto.ts","../src/lens.ts"],"sourcesContent":["/**\n * Core type definitions for the @panproto/core SDK.\n *\n * These types mirror the Rust-side structures but use JavaScript idioms:\n * - `HashMap<K,V>` becomes `Map<K,V>` or `Record<string, V>` for string keys\n * - `Option<T>` becomes `T | undefined`\n * - `Vec<T>` becomes `T[]`\n * - `Result<T,E>` becomes thrown `PanprotoError` or return value\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Handle types (opaque wrappers — never expose raw u32)\n// ---------------------------------------------------------------------------\n\n/** Opaque handle to a WASM-side resource. */\nexport interface Handle {\n readonly __brand: unique symbol;\n readonly id: number;\n}\n\n/** Branded handle for a protocol resource. */\nexport interface ProtocolHandle extends Handle {\n readonly __kind: 'protocol';\n}\n\n/** Branded handle for a schema resource. */\nexport interface SchemaHandle extends Handle {\n readonly __kind: 'schema';\n}\n\n/** Branded handle for a compiled migration resource. */\nexport interface MigrationHandle extends Handle {\n readonly __kind: 'migration';\n}\n\n// ---------------------------------------------------------------------------\n// Protocol\n// ---------------------------------------------------------------------------\n\n/** Rule constraining which vertex kinds an edge can connect. */\nexport interface EdgeRule {\n readonly edgeKind: string;\n /** Allowed source vertex kinds. Empty array means any. */\n readonly srcKinds: readonly string[];\n /** Allowed target vertex kinds. Empty array means any. */\n readonly tgtKinds: readonly string[];\n}\n\n/** A protocol specification defining schema/instance theories and validation rules. */\nexport interface ProtocolSpec {\n readonly name: string;\n readonly schemaTheory: string;\n readonly instanceTheory: string;\n readonly edgeRules: readonly EdgeRule[];\n readonly objKinds: readonly string[];\n readonly constraintSorts: readonly string[];\n}\n\n// ---------------------------------------------------------------------------\n// Schema\n// ---------------------------------------------------------------------------\n\n/** Options for vertex creation. */\nexport interface VertexOptions {\n readonly nsid?: string;\n}\n\n/** A vertex in a schema graph. */\nexport interface Vertex {\n readonly id: string;\n readonly kind: string;\n readonly nsid?: string | undefined;\n}\n\n/** A directed edge in a schema graph. */\nexport interface Edge {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name?: string | undefined;\n}\n\n/** A hyperedge with a labeled signature. */\nexport interface HyperEdge {\n readonly id: string;\n readonly kind: string;\n readonly signature: Readonly<Record<string, string>>;\n readonly parentLabel: string;\n}\n\n/** A constraint on a vertex (sort + value). */\nexport interface Constraint {\n readonly sort: string;\n readonly value: string;\n}\n\n/** Options for edge creation. */\nexport interface EdgeOptions {\n readonly name?: string;\n}\n\n/** Serializable schema representation. */\nexport interface SchemaData {\n readonly protocol: string;\n readonly vertices: Readonly<Record<string, Vertex>>;\n readonly edges: readonly Edge[];\n readonly hyperEdges: Readonly<Record<string, HyperEdge>>;\n readonly constraints: Readonly<Record<string, readonly Constraint[]>>;\n readonly required: Readonly<Record<string, readonly Edge[]>>;\n}\n\n// ---------------------------------------------------------------------------\n// Migration\n// ---------------------------------------------------------------------------\n\n/** A vertex mapping entry for migration building. */\nexport interface VertexMapping {\n readonly src: string;\n readonly tgt: string;\n}\n\n/** A migration specification (maps between two schemas). */\nexport interface MigrationSpec {\n readonly vertexMap: Readonly<Record<string, string>>;\n readonly edgeMap: readonly [Edge, Edge][];\n readonly resolvers: readonly [[string, string], Edge][];\n}\n\n/** Result of applying a compiled migration to a record. */\nexport interface LiftResult {\n readonly data: unknown;\n}\n\n/** Get result for bidirectional lens operation. */\nexport interface GetResult {\n readonly view: unknown;\n readonly complement: Uint8Array;\n}\n\n// ---------------------------------------------------------------------------\n// Diff / Compatibility\n// ---------------------------------------------------------------------------\n\n/** A single change detected between two schemas. */\nexport interface SchemaChange {\n readonly kind: 'vertex-added' | 'vertex-removed' | 'edge-added' | 'edge-removed'\n | 'constraint-added' | 'constraint-removed' | 'constraint-changed'\n | 'kind-changed' | 'required-added' | 'required-removed';\n readonly path: string;\n readonly detail?: string | undefined;\n}\n\n/** Compatibility classification. */\nexport type Compatibility = 'fully-compatible' | 'backward-compatible' | 'breaking';\n\n/** Schema diff report. */\nexport interface DiffReport {\n readonly compatibility: Compatibility;\n readonly changes: readonly SchemaChange[];\n}\n\n// ---------------------------------------------------------------------------\n// Existence checking\n// ---------------------------------------------------------------------------\n\n/** A structured existence error. */\nexport interface ExistenceError {\n readonly kind: 'edge-missing' | 'kind-inconsistency' | 'label-inconsistency'\n | 'required-field-missing' | 'constraint-tightened' | 'resolver-invalid'\n | 'well-formedness' | 'signature-coherence' | 'simultaneity' | 'reachability-risk';\n readonly message: string;\n readonly detail?: Record<string, unknown> | undefined;\n}\n\n/** Result of existence checking. */\nexport interface ExistenceReport {\n readonly valid: boolean;\n readonly errors: readonly ExistenceError[];\n}\n\n// ---------------------------------------------------------------------------\n// WASM module interface\n// ---------------------------------------------------------------------------\n\n/** The raw WASM module interface (10 entry points). */\nexport interface WasmExports {\n define_protocol(spec: Uint8Array): number;\n build_schema(proto: number, ops: Uint8Array): number;\n check_existence(proto: number, src: number, tgt: number, mapping: Uint8Array): Uint8Array;\n compile_migration(src: number, tgt: number, mapping: Uint8Array): number;\n lift_record(migration: number, record: Uint8Array): Uint8Array;\n get_record(migration: number, record: Uint8Array): Uint8Array;\n put_record(migration: number, view: Uint8Array, complement: Uint8Array): Uint8Array;\n compose_migrations(m1: number, m2: number): number;\n diff_schemas(s1: number, s2: number): Uint8Array;\n free_handle(handle: number): void;\n}\n\n/** WASM module wrapper including exports and memory. */\nexport interface WasmModule {\n readonly exports: WasmExports;\n readonly memory: WebAssembly.Memory;\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** Base error class for all panproto errors. */\nexport class PanprotoError extends Error {\n override readonly name: string = 'PanprotoError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/** Error from WASM boundary. */\nexport class WasmError extends PanprotoError {\n override readonly name = 'WasmError';\n}\n\n/** Error from schema validation. */\nexport class SchemaValidationError extends PanprotoError {\n override readonly name = 'SchemaValidationError';\n\n constructor(\n message: string,\n readonly errors: readonly string[],\n ) {\n super(message);\n }\n}\n\n/** Error from migration compilation. */\nexport class MigrationError extends PanprotoError {\n override readonly name = 'MigrationError';\n}\n\n/** Error from existence checking. */\nexport class ExistenceCheckError extends PanprotoError {\n override readonly name = 'ExistenceCheckError';\n\n constructor(\n message: string,\n readonly report: ExistenceReport,\n ) {\n super(message);\n }\n}\n","/**\n * WASM loading and handle management.\n *\n * Manages the lifecycle of WASM-side resources via opaque handles.\n * Uses `Symbol.dispose` for automatic cleanup and `FinalizationRegistry`\n * as a safety net for leaked handles.\n *\n * @module\n */\n\nimport type { WasmModule, WasmExports } from './types.js';\nimport { WasmError } from './types.js';\n\n/** Default wasm-bindgen glue module URL (relative to package root). */\nconst DEFAULT_GLUE_URL = new URL('./panproto_wasm.js', import.meta.url);\n\n/**\n * Shape of a pre-imported wasm-bindgen glue module.\n *\n * The `default` export is the wasm-bindgen init function. We type it\n * loosely so any wasm-bindgen output module satisfies the interface.\n */\nexport interface WasmGlueModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n default: (...args: any[]) => Promise<{ memory: WebAssembly.Memory }>;\n define_protocol: WasmExports['define_protocol'];\n build_schema: WasmExports['build_schema'];\n check_existence: WasmExports['check_existence'];\n compile_migration: WasmExports['compile_migration'];\n lift_record: WasmExports['lift_record'];\n get_record: WasmExports['get_record'];\n put_record: WasmExports['put_record'];\n compose_migrations: WasmExports['compose_migrations'];\n diff_schemas: WasmExports['diff_schemas'];\n free_handle: WasmExports['free_handle'];\n}\n\n/**\n * Load the panproto WASM module.\n *\n * Accepts either:\n * - A URL to the wasm-bindgen `.js` glue module (loaded via dynamic import)\n * - A pre-imported wasm-bindgen glue module object (for bundler environments like Vite)\n *\n * @param input - URL string, URL object, or pre-imported glue module.\n * Defaults to the bundled glue module URL.\n * @returns The initialized WASM module\n * @throws {@link WasmError} if loading or instantiation fails\n */\nexport async function loadWasm(input?: string | URL | WasmGlueModule): Promise<WasmModule> {\n try {\n let glue: WasmGlueModule;\n\n if (input && typeof input === 'object' && 'default' in input && typeof input.default === 'function') {\n // Pre-imported glue module — used in bundler environments (Vite, webpack)\n glue = input;\n } else {\n // Dynamic import from URL\n const url = (input as string | URL | undefined) ?? DEFAULT_GLUE_URL;\n glue = await import(/* @vite-ignore */ String(url));\n }\n\n const initOutput = await glue.default();\n\n const exports: WasmExports = {\n define_protocol: glue.define_protocol,\n build_schema: glue.build_schema,\n check_existence: glue.check_existence,\n compile_migration: glue.compile_migration,\n lift_record: glue.lift_record,\n get_record: glue.get_record,\n put_record: glue.put_record,\n compose_migrations: glue.compose_migrations,\n diff_schemas: glue.diff_schemas,\n free_handle: glue.free_handle,\n };\n\n const memory: WebAssembly.Memory = initOutput.memory;\n\n if (!memory) {\n throw new WasmError('WASM module missing memory export');\n }\n\n return { exports, memory };\n } catch (error) {\n if (error instanceof WasmError) throw error;\n throw new WasmError(\n `Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Handle registry — prevents resource leaks\n// ---------------------------------------------------------------------------\n\n/** Weak reference registry for leaked handle detection. */\nconst leakedHandleRegistry = new FinalizationRegistry<CleanupInfo>((info) => {\n // Safety net: if a disposable wrapper is GC'd without being disposed,\n // free the underlying WASM handle.\n try {\n info.freeHandle(info.handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n});\n\ninterface CleanupInfo {\n readonly handle: number;\n readonly freeHandle: (h: number) => void;\n}\n\n/**\n * A disposable wrapper around a WASM handle.\n *\n * Implements `Symbol.dispose` for use with `using` declarations.\n * A `FinalizationRegistry` acts as a safety net for handles that\n * are not explicitly disposed.\n */\nexport class WasmHandle implements Disposable {\n #handle: number;\n #disposed = false;\n readonly #freeHandle: (h: number) => void;\n\n constructor(handle: number, freeHandle: (h: number) => void) {\n this.#handle = handle;\n this.#freeHandle = freeHandle;\n\n leakedHandleRegistry.register(this, { handle, freeHandle }, this);\n }\n\n /** The raw WASM handle id. Only for internal use within the SDK. */\n get id(): number {\n if (this.#disposed) {\n throw new WasmError('Attempted to use a disposed handle');\n }\n return this.#handle;\n }\n\n /** Whether this handle has been disposed. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /** Release the underlying WASM resource. */\n [Symbol.dispose](): void {\n if (this.#disposed) return;\n this.#disposed = true;\n\n leakedHandleRegistry.unregister(this);\n\n try {\n this.#freeHandle(this.#handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n }\n}\n\n/**\n * Create a managed handle that will be freed when disposed.\n *\n * @param rawHandle - The u32 handle from WASM\n * @param wasm - The WASM module for freeing\n * @returns A disposable wrapper\n */\nexport function createHandle(rawHandle: number, wasm: WasmModule): WasmHandle {\n return new WasmHandle(rawHandle, (h) => wasm.exports.free_handle(h));\n}\n","/**\n * MessagePack encode/decode utilities for the WASM boundary.\n *\n * All structured data crossing the WASM boundary is serialized as MessagePack\n * byte slices. This module wraps `@msgpack/msgpack` with typed helpers.\n *\n * @module\n */\n\nimport { encode, decode } from '@msgpack/msgpack';\n\n/**\n * Encode a value to MessagePack bytes for sending to WASM.\n *\n * @param value - The value to encode\n * @returns MessagePack-encoded bytes\n */\nexport function packToWasm(value: unknown): Uint8Array {\n return encode(value);\n}\n\n/**\n * Decode MessagePack bytes received from WASM.\n *\n * @typeParam T - The expected decoded type\n * @param bytes - MessagePack-encoded bytes from WASM\n * @returns The decoded value\n */\nexport function unpackFromWasm<T = unknown>(bytes: Uint8Array): T {\n return decode(bytes) as T;\n}\n\n/**\n * Encode a schema operations list for the `build_schema` entry point.\n *\n * @param ops - Array of builder operations\n * @returns MessagePack-encoded bytes\n */\nexport function packSchemaOps(ops: readonly SchemaOp[]): Uint8Array {\n return encode(ops);\n}\n\n/**\n * Encode a migration mapping for WASM entry points.\n *\n * @param mapping - The migration mapping object\n * @returns MessagePack-encoded bytes\n */\nexport function packMigrationMapping(mapping: MigrationMapping): Uint8Array {\n return encode(mapping);\n}\n\n// ---------------------------------------------------------------------------\n// Internal types for structured WASM messages\n// ---------------------------------------------------------------------------\n\n/**\n * A single schema builder operation sent to WASM.\n *\n * Uses serde internally-tagged format: the `op` field acts as the\n * discriminant and all variant fields sit at the same level.\n */\nexport interface SchemaOp {\n readonly op: 'vertex' | 'edge' | 'hyper_edge' | 'constraint' | 'required';\n readonly [key: string]: unknown;\n}\n\n/** Wire format for an edge (matches Rust serialization). */\nexport interface EdgeWire {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name: string | null;\n}\n\n/** A migration mapping sent to WASM (matches Rust `Migration` struct). */\nexport interface MigrationMapping {\n readonly vertex_map: Record<string, string>;\n readonly edge_map: Map<EdgeWire, EdgeWire>;\n readonly hyper_edge_map: Record<string, string>;\n readonly label_map: Map<readonly [string, string], string>;\n readonly resolver: Map<readonly [string, string], EdgeWire>;\n}\n","/**\n * Fluent schema builder API.\n *\n * Builders are immutable: each method returns a new builder instance.\n * Call `.build()` to validate and produce the final schema.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Vertex,\n Edge,\n HyperEdge,\n Constraint,\n VertexOptions,\n EdgeOptions,\n SchemaData,\n} from './types.js';\nimport { SchemaValidationError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport type { SchemaOp } from './msgpack.js';\nimport { packSchemaOps } from './msgpack.js';\n\n/**\n * Immutable fluent builder for constructing schemas.\n *\n * Each mutation method returns a new `SchemaBuilder` instance,\n * leaving the original unchanged. The builder accumulates operations\n * that are sent to WASM on `.build()`.\n *\n * @example\n * ```typescript\n * const schema = builder\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n * ```\n */\nexport class SchemaBuilder {\n readonly #protocolName: string;\n readonly #protocolHandle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #ops: readonly SchemaOp[];\n readonly #vertices: ReadonlyMap<string, Vertex>;\n readonly #edges: readonly Edge[];\n readonly #hyperEdges: ReadonlyMap<string, HyperEdge>;\n readonly #constraints: ReadonlyMap<string, readonly Constraint[]>;\n readonly #required: ReadonlyMap<string, readonly Edge[]>;\n\n constructor(\n protocolName: string,\n protocolHandle: WasmHandle,\n wasm: WasmModule,\n ops: readonly SchemaOp[] = [],\n vertices: ReadonlyMap<string, Vertex> = new Map(),\n edges: readonly Edge[] = [],\n hyperEdges: ReadonlyMap<string, HyperEdge> = new Map(),\n constraints: ReadonlyMap<string, readonly Constraint[]> = new Map(),\n required: ReadonlyMap<string, readonly Edge[]> = new Map(),\n ) {\n this.#protocolName = protocolName;\n this.#protocolHandle = protocolHandle;\n this.#wasm = wasm;\n this.#ops = ops;\n this.#vertices = vertices;\n this.#edges = edges;\n this.#hyperEdges = hyperEdges;\n this.#constraints = constraints;\n this.#required = required;\n }\n\n /**\n * Add a vertex to the schema.\n *\n * @param id - Unique vertex identifier\n * @param kind - Vertex kind (e.g., 'record', 'object', 'string')\n * @param options - Optional vertex configuration (nsid, etc.)\n * @returns A new builder with the vertex added\n * @throws {@link SchemaValidationError} if vertex id is already in use\n */\n vertex(id: string, kind: string, options?: VertexOptions): SchemaBuilder {\n if (this.#vertices.has(id)) {\n throw new SchemaValidationError(\n `Vertex \"${id}\" already exists in schema`,\n [`Duplicate vertex id: ${id}`],\n );\n }\n\n const vertex: Vertex = {\n id,\n kind,\n nsid: options?.nsid,\n };\n\n const op: SchemaOp = {\n op: 'vertex',\n id,\n kind,\n nsid: options?.nsid ?? null,\n };\n\n const newVertices = new Map(this.#vertices);\n newVertices.set(id, vertex);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n newVertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a directed edge to the schema.\n *\n * @param src - Source vertex id\n * @param tgt - Target vertex id\n * @param kind - Edge kind (e.g., 'record-schema', 'prop')\n * @param options - Optional edge configuration (name, etc.)\n * @returns A new builder with the edge added\n * @throws {@link SchemaValidationError} if source or target vertex does not exist\n */\n edge(src: string, tgt: string, kind: string, options?: EdgeOptions): SchemaBuilder {\n if (!this.#vertices.has(src)) {\n throw new SchemaValidationError(\n `Edge source \"${src}\" does not exist`,\n [`Unknown source vertex: ${src}`],\n );\n }\n if (!this.#vertices.has(tgt)) {\n throw new SchemaValidationError(\n `Edge target \"${tgt}\" does not exist`,\n [`Unknown target vertex: ${tgt}`],\n );\n }\n\n const edge: Edge = {\n src,\n tgt,\n kind,\n name: options?.name,\n };\n\n const op: SchemaOp = {\n op: 'edge',\n src,\n tgt,\n kind,\n name: options?.name ?? null,\n };\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n [...this.#edges, edge],\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a hyperedge to the schema.\n *\n * Only valid if the protocol's schema theory includes ThHypergraph.\n *\n * @param id - Unique hyperedge identifier\n * @param kind - Hyperedge kind\n * @param signature - Label-to-vertex mapping\n * @param parentLabel - The label identifying the parent in the signature\n * @returns A new builder with the hyperedge added\n */\n hyperEdge(\n id: string,\n kind: string,\n signature: Record<string, string>,\n parentLabel: string,\n ): SchemaBuilder {\n const he: HyperEdge = { id, kind, signature, parentLabel };\n\n const op: SchemaOp = {\n op: 'hyper_edge',\n id,\n kind,\n signature,\n parent: parentLabel,\n };\n\n const newHyperEdges = new Map(this.#hyperEdges);\n newHyperEdges.set(id, he);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n newHyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a constraint to a vertex.\n *\n * @param vertexId - The vertex to constrain\n * @param sort - Constraint sort (e.g., 'maxLength')\n * @param value - Constraint value\n * @returns A new builder with the constraint added\n */\n constraint(vertexId: string, sort: string, value: string): SchemaBuilder {\n const c: Constraint = { sort, value };\n\n const op: SchemaOp = {\n op: 'constraint',\n vertex: vertexId,\n sort,\n value,\n };\n\n const existing = this.#constraints.get(vertexId) ?? [];\n const newConstraints = new Map(this.#constraints);\n newConstraints.set(vertexId, [...existing, c]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n newConstraints,\n this.#required,\n );\n }\n\n /**\n * Mark edges as required for a vertex.\n *\n * @param vertexId - The vertex with required edges\n * @param edges - The edges that are required\n * @returns A new builder with the requirement added\n */\n required(vertexId: string, edges: readonly Edge[]): SchemaBuilder {\n const op: SchemaOp = {\n op: 'required',\n vertex: vertexId,\n edges: edges.map((e) => ({\n src: e.src,\n tgt: e.tgt,\n kind: e.kind,\n name: e.name ?? null,\n })),\n };\n\n const existing = this.#required.get(vertexId) ?? [];\n const newRequired = new Map(this.#required);\n newRequired.set(vertexId, [...existing, ...edges]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n newRequired,\n );\n }\n\n /**\n * Validate and build the schema.\n *\n * Sends all accumulated operations to WASM for validation and construction.\n * Returns a `BuiltSchema` that holds the WASM handle and local data.\n *\n * @returns The validated, built schema\n * @throws {@link SchemaValidationError} if the schema is invalid\n */\n build(): BuiltSchema {\n const opsBytes = packSchemaOps([...this.#ops]);\n const rawHandle = this.#wasm.exports.build_schema(\n this.#protocolHandle.id,\n opsBytes,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n\n const data: SchemaData = {\n protocol: this.#protocolName,\n vertices: Object.fromEntries(this.#vertices),\n edges: [...this.#edges],\n hyperEdges: Object.fromEntries(this.#hyperEdges),\n constraints: Object.fromEntries(\n Array.from(this.#constraints.entries()).map(([k, v]) => [k, [...v]]),\n ),\n required: Object.fromEntries(\n Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]]),\n ),\n };\n\n return new BuiltSchema(handle, data, this.#wasm);\n }\n}\n\n/**\n * A validated, built schema with a WASM-side handle.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class BuiltSchema implements Disposable {\n readonly #handle: WasmHandle;\n readonly #data: SchemaData;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, data: SchemaData, wasm: WasmModule) {\n this.#handle = handle;\n this.#data = data;\n this.#wasm = wasm;\n }\n\n /** The WASM handle for this schema. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The WASM module reference. Internal use only. */\n get _wasm(): WasmModule {\n return this.#wasm;\n }\n\n /** The schema data (vertices, edges, constraints, etc.). */\n get data(): SchemaData {\n return this.#data;\n }\n\n /** The protocol name this schema belongs to. */\n get protocol(): string {\n return this.#data.protocol;\n }\n\n /** All vertices in the schema. */\n get vertices(): Readonly<Record<string, Vertex>> {\n return this.#data.vertices;\n }\n\n /** All edges in the schema. */\n get edges(): readonly Edge[] {\n return this.#data.edges;\n }\n\n /** Release the WASM-side schema resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n","/**\n * Protocol definition helpers.\n *\n * A protocol specifies the schema theory and instance theory used by\n * a family of schemas (e.g., ATProto, SQL, Protobuf). This module\n * provides helpers for defining and looking up protocols.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, EdgeRule } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm } from './msgpack.js';\nimport { SchemaBuilder } from './schema.js';\n\n/**\n * A registered protocol with a WASM-side handle.\n *\n * Provides a fluent API for building schemas within this protocol.\n * Implements `Disposable` for automatic cleanup.\n */\nexport class Protocol implements Disposable {\n readonly #handle: WasmHandle;\n readonly #spec: ProtocolSpec;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, spec: ProtocolSpec, wasm: WasmModule) {\n this.#handle = handle;\n this.#spec = spec;\n this.#wasm = wasm;\n }\n\n /** The protocol name. */\n get name(): string {\n return this.#spec.name;\n }\n\n /** The full protocol specification. */\n get spec(): ProtocolSpec {\n return this.#spec;\n }\n\n /** The WASM handle. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /**\n * Start building a schema within this protocol.\n *\n * @returns A new `SchemaBuilder` bound to this protocol\n */\n schema(): SchemaBuilder {\n return new SchemaBuilder(this.#spec.name, this.#handle, this.#wasm);\n }\n\n /** Release the WASM-side protocol resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Define a protocol by sending its specification to WASM.\n *\n * @param spec - The protocol specification\n * @param wasm - The WASM module\n * @returns A registered protocol with a WASM handle\n * @throws {@link PanprotoError} if the WASM call fails\n */\nexport function defineProtocol(spec: ProtocolSpec, wasm: WasmModule): Protocol {\n const wireSpec = {\n name: spec.name,\n schema_theory: spec.schemaTheory,\n instance_theory: spec.instanceTheory,\n edge_rules: spec.edgeRules.map((r) => ({\n edge_kind: r.edgeKind,\n src_kinds: [...r.srcKinds],\n tgt_kinds: [...r.tgtKinds],\n })),\n obj_kinds: [...spec.objKinds],\n constraint_sorts: [...spec.constraintSorts],\n };\n\n try {\n const bytes = packToWasm(wireSpec);\n const rawHandle = wasm.exports.define_protocol(bytes);\n const handle = createHandle(rawHandle, wasm);\n return new Protocol(handle, spec, wasm);\n } catch (error) {\n throw new PanprotoError(\n `Failed to define protocol \"${spec.name}\": ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Built-in protocol specs\n// ---------------------------------------------------------------------------\n\n/**\n * Built-in ATProto protocol specification.\n *\n * Schema theory: colimit(ThGraph, ThConstraint, ThMulti).\n * Instance theory: ThWType + ThMeta.\n */\nexport const ATPROTO_SPEC: ProtocolSpec = {\n name: 'atproto',\n schemaTheory: 'ThATProtoSchema',\n instanceTheory: 'ThATProtoInstance',\n edgeRules: [\n { edgeKind: 'record-schema', srcKinds: ['record'], tgtKinds: ['object'] },\n { edgeKind: 'prop', srcKinds: ['object', 'query', 'procedure', 'subscription'], tgtKinds: [] },\n { edgeKind: 'items', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['union'], tgtKinds: [] },\n { edgeKind: 'ref', srcKinds: [], tgtKinds: [] },\n { edgeKind: 'self-ref', srcKinds: [], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: [\n 'record', 'object', 'array', 'union', 'string', 'integer', 'boolean',\n 'bytes', 'cid-link', 'blob', 'unknown', 'token', 'query', 'procedure',\n 'subscription', 'ref',\n ],\n constraintSorts: [\n 'minLength', 'maxLength', 'minimum', 'maximum', 'maxGraphemes',\n 'enum', 'const', 'default', 'closed',\n ],\n};\n\n/**\n * Built-in SQL protocol specification.\n *\n * Schema theory: colimit(ThHypergraph, ThConstraint).\n * Instance theory: ThFunctor.\n */\nexport const SQL_SPEC: ProtocolSpec = {\n name: 'sql',\n schemaTheory: 'ThConstrainedHypergraph',\n instanceTheory: 'ThFunctor',\n edgeRules: [\n { edgeKind: 'column', srcKinds: ['table'], tgtKinds: ['type'] },\n { edgeKind: 'fk', srcKinds: ['table'], tgtKinds: ['table'] },\n { edgeKind: 'pk', srcKinds: ['table'], tgtKinds: ['column'] },\n ] satisfies EdgeRule[],\n objKinds: ['table'],\n constraintSorts: ['nullable', 'unique', 'check', 'default'],\n};\n\n/**\n * Built-in Protobuf protocol specification.\n */\nexport const PROTOBUF_SPEC: ProtocolSpec = {\n name: 'protobuf',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['message'], tgtKinds: [] },\n { edgeKind: 'nested', srcKinds: ['message'], tgtKinds: ['message', 'enum'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['message'],\n constraintSorts: ['field-number', 'repeated', 'optional', 'map-key', 'map-value'],\n};\n\n/**\n * Built-in GraphQL protocol specification.\n */\nexport const GRAPHQL_SPEC: ProtocolSpec = {\n name: 'graphql',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['type', 'input'], tgtKinds: [] },\n { edgeKind: 'implements', srcKinds: ['type'], tgtKinds: ['interface'] },\n { edgeKind: 'member', srcKinds: ['union'], tgtKinds: ['type'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['type', 'input'],\n constraintSorts: ['non-null', 'list', 'deprecated'],\n};\n\n/**\n * Built-in JSON Schema protocol specification.\n */\nexport const JSON_SCHEMA_SPEC: ProtocolSpec = {\n name: 'json-schema',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'property', srcKinds: ['object'], tgtKinds: [] },\n { edgeKind: 'item', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['oneOf', 'anyOf'], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: ['object'],\n constraintSorts: ['minLength', 'maxLength', 'minimum', 'maximum', 'pattern', 'format', 'required'],\n};\n\n/** Registry of built-in protocol specs, keyed by name. */\nexport const BUILTIN_PROTOCOLS: ReadonlyMap<string, ProtocolSpec> = new Map([\n ['atproto', ATPROTO_SPEC],\n ['sql', SQL_SPEC],\n ['protobuf', PROTOBUF_SPEC],\n ['graphql', GRAPHQL_SPEC],\n ['json-schema', JSON_SCHEMA_SPEC],\n]);\n","/**\n * Migration builder and compiled migration wrapper.\n *\n * Migrations define a mapping between two schemas. Once compiled,\n * they can efficiently transform records via WASM.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Edge,\n LiftResult,\n GetResult,\n ExistenceReport,\n MigrationSpec,\n} from './types.js';\nimport { MigrationError, WasmError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm, unpackFromWasm, packMigrationMapping } from './msgpack.js';\nimport type { BuiltSchema } from './schema.js';\n\n/**\n * Fluent builder for constructing migrations between two schemas.\n *\n * Each mutation method returns a new `MigrationBuilder` instance,\n * leaving the original unchanged.\n *\n * @example\n * ```typescript\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .map('post:body', 'post:body')\n * .mapEdge(oldEdge, newEdge)\n * .compile();\n * ```\n */\nexport class MigrationBuilder {\n readonly #src: BuiltSchema;\n readonly #tgt: BuiltSchema;\n readonly #wasm: WasmModule;\n readonly #vertexMap: ReadonlyMap<string, string>;\n readonly #edgeMap: readonly [Edge, Edge][];\n readonly #resolvers: readonly [[string, string], Edge][];\n\n constructor(\n src: BuiltSchema,\n tgt: BuiltSchema,\n wasm: WasmModule,\n vertexMap: ReadonlyMap<string, string> = new Map(),\n edgeMap: readonly [Edge, Edge][] = [],\n resolvers: readonly [[string, string], Edge][] = [],\n ) {\n this.#src = src;\n this.#tgt = tgt;\n this.#wasm = wasm;\n this.#vertexMap = vertexMap;\n this.#edgeMap = edgeMap;\n this.#resolvers = resolvers;\n }\n\n /**\n * Map a source vertex to a target vertex.\n *\n * @param srcVertex - Vertex id in the source schema\n * @param tgtVertex - Vertex id in the target schema\n * @returns A new builder with the mapping added\n */\n map(srcVertex: string, tgtVertex: string): MigrationBuilder {\n const newMap = new Map(this.#vertexMap);\n newMap.set(srcVertex, tgtVertex);\n\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n newMap,\n this.#edgeMap,\n this.#resolvers,\n );\n }\n\n /**\n * Map a source edge to a target edge.\n *\n * @param srcEdge - Edge in the source schema\n * @param tgtEdge - Edge in the target schema\n * @returns A new builder with the edge mapping added\n */\n mapEdge(srcEdge: Edge, tgtEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n [...this.#edgeMap, [srcEdge, tgtEdge]],\n this.#resolvers,\n );\n }\n\n /**\n * Add a resolver for ancestor contraction ambiguity.\n *\n * When a migration contracts nodes and the resulting edge between\n * two vertex kinds is ambiguous, a resolver specifies which edge to use.\n *\n * @param srcKind - Source vertex kind in the contracted pair\n * @param tgtKind - Target vertex kind in the contracted pair\n * @param resolvedEdge - The edge to use for this pair\n * @returns A new builder with the resolver added\n */\n resolve(srcKind: string, tgtKind: string, resolvedEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n this.#edgeMap,\n [...this.#resolvers, [[srcKind, tgtKind], resolvedEdge]],\n );\n }\n\n /**\n * Get the current migration specification.\n *\n * @returns The migration spec with all accumulated mappings\n */\n toSpec(): MigrationSpec {\n return {\n vertexMap: Object.fromEntries(this.#vertexMap),\n edgeMap: [...this.#edgeMap],\n resolvers: [...this.#resolvers],\n };\n }\n\n /**\n * Compile the migration for fast per-record application.\n *\n * Sends the migration specification to WASM for compilation.\n * The resulting `CompiledMigration` can be used to transform records.\n *\n * @returns A compiled migration ready for record transformation\n * @throws {@link MigrationError} if compilation fails\n */\n compile(): CompiledMigration {\n const edgeMap = new Map(\n this.#edgeMap.map(([src, tgt]) => [\n { src: src.src, tgt: src.tgt, kind: src.kind, name: src.name ?? null },\n { src: tgt.src, tgt: tgt.tgt, kind: tgt.kind, name: tgt.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n this.#resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: Object.fromEntries(this.#vertexMap),\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n try {\n const rawHandle = this.#wasm.exports.compile_migration(\n this.#src._handle.id,\n this.#tgt._handle.id,\n mapping,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n return new CompiledMigration(handle, this.#wasm, this.toSpec());\n } catch (error) {\n throw new MigrationError(\n `Failed to compile migration: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n}\n\n/**\n * A compiled migration that can efficiently transform records via WASM.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class CompiledMigration implements Disposable {\n readonly #handle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #spec: MigrationSpec;\n\n constructor(handle: WasmHandle, wasm: WasmModule, spec: MigrationSpec) {\n this.#handle = handle;\n this.#wasm = wasm;\n this.#spec = spec;\n }\n\n /** The WASM handle for this migration. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The migration specification used to build this migration. */\n get spec(): MigrationSpec {\n return this.#spec;\n }\n\n /**\n * Transform a record using this migration (forward direction).\n *\n * This is the hot path: data goes through WASM as MessagePack bytes\n * with no intermediate JS-heap allocation.\n *\n * @param record - The input record to transform\n * @returns The transformed record\n * @throws {@link WasmError} if the WASM call fails\n */\n lift(record: unknown): LiftResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.lift_record(\n this.#handle.id,\n inputBytes,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `lift_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional get: extract view and complement from a record.\n *\n * The complement captures data discarded by the forward projection,\n * enabling lossless round-tripping via `put()`.\n *\n * @param record - The input record\n * @returns The projected view and opaque complement bytes\n * @throws {@link WasmError} if the WASM call fails\n */\n get(record: unknown): GetResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.get_record(\n this.#handle.id,\n inputBytes,\n );\n const result = unpackFromWasm<{ view: unknown; complement: Uint8Array }>(outputBytes);\n return {\n view: result.view,\n complement: result.complement instanceof Uint8Array\n ? result.complement\n : new Uint8Array(result.complement as ArrayBuffer),\n };\n } catch (error) {\n throw new WasmError(\n `get_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional put: restore a full record from a modified view and complement.\n *\n * @param view - The (possibly modified) projected view\n * @param complement - The complement from a prior `get()` call\n * @returns The restored full record\n * @throws {@link WasmError} if the WASM call fails\n */\n put(view: unknown, complement: Uint8Array): LiftResult {\n const viewBytes = packToWasm(view);\n\n try {\n const outputBytes = this.#wasm.exports.put_record(\n this.#handle.id,\n viewBytes,\n complement,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `put_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /** Release the WASM-side compiled migration resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Check existence conditions for a migration between two schemas.\n *\n * @param src - Source schema handle\n * @param tgt - Target schema handle\n * @param spec - The migration specification\n * @param wasm - The WASM module\n * @returns The existence report\n */\nexport function checkExistence(\n protoHandle: number,\n src: BuiltSchema,\n tgt: BuiltSchema,\n spec: MigrationSpec,\n wasm: WasmModule,\n): ExistenceReport {\n const edgeMap = new Map(\n spec.edgeMap.map(([s, t]) => [\n { src: s.src, tgt: s.tgt, kind: s.kind, name: s.name ?? null },\n { src: t.src, tgt: t.tgt, kind: t.kind, name: t.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n spec.resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: spec.vertexMap,\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n const resultBytes = wasm.exports.check_existence(\n protoHandle,\n src._handle.id,\n tgt._handle.id,\n mapping,\n );\n\n return unpackFromWasm<ExistenceReport>(resultBytes);\n}\n\n/**\n * Compose two compiled migrations into a single migration.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @param wasm - The WASM module\n * @returns A new compiled migration representing m2 . m1\n * @throws {@link MigrationError} if composition fails\n */\nexport function composeMigrations(\n m1: CompiledMigration,\n m2: CompiledMigration,\n wasm: WasmModule,\n): CompiledMigration {\n try {\n const rawHandle = wasm.exports.compose_migrations(\n m1._handle.id,\n m2._handle.id,\n );\n const handle = createHandle(rawHandle, wasm);\n\n // Compose vertex maps: if m1 maps A->B and m2 maps B->C, composed maps A->C.\n // Vertices in m1 whose target is not remapped by m2 pass through unchanged.\n const composedVertexMap: Record<string, string> = {};\n for (const [src, intermediate] of Object.entries(m1.spec.vertexMap)) {\n const final_ = m2.spec.vertexMap[intermediate];\n composedVertexMap[src] = final_ ?? intermediate;\n }\n\n // Concatenate edge maps and resolvers from both migrations. The WASM side\n // performs the actual composition; this spec is a best-effort reconstruction\n // for introspection purposes.\n const composedSpec: MigrationSpec = {\n vertexMap: composedVertexMap,\n edgeMap: [...m1.spec.edgeMap, ...m2.spec.edgeMap],\n resolvers: [...m1.spec.resolvers, ...m2.spec.resolvers],\n };\n\n return new CompiledMigration(handle, wasm, composedSpec);\n } catch (error) {\n throw new MigrationError(\n `Failed to compose migrations: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n","/**\n * Main Panproto class — the primary entry point for the SDK.\n *\n * Wraps the WASM module and provides the high-level API for working\n * with protocols, schemas, migrations, and diffs.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, DiffReport } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { loadWasm, type WasmGlueModule } from './wasm.js';\nimport {\n Protocol,\n defineProtocol,\n BUILTIN_PROTOCOLS,\n} from './protocol.js';\nimport type { BuiltSchema } from './schema.js';\nimport {\n MigrationBuilder,\n CompiledMigration,\n checkExistence,\n composeMigrations,\n} from './migration.js';\nimport { unpackFromWasm } from './msgpack.js';\n\n/**\n * The main entry point for the panproto SDK.\n *\n * Create an instance with {@link Panproto.init}, then use it to define\n * protocols, build schemas, compile migrations, and diff schemas.\n *\n * Implements `Disposable` so it can be used with `using` to automatically\n * clean up all WASM resources.\n *\n * @example\n * ```typescript\n * const panproto = await Panproto.init();\n * const atproto = panproto.protocol('atproto');\n *\n * const schema = atproto.schema()\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n *\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .compile();\n *\n * const result = migration.lift(inputRecord);\n * ```\n */\nexport class Panproto implements Disposable {\n readonly #wasm: WasmModule;\n readonly #protocols: Map<string, Protocol>;\n\n private constructor(wasm: WasmModule) {\n this.#wasm = wasm;\n this.#protocols = new Map();\n }\n\n /**\n * Initialize the panproto SDK by loading the WASM module.\n *\n * @param input - URL to the wasm-bindgen glue module, or a pre-imported\n * glue module object (for bundler environments like Vite).\n * Defaults to the bundled glue module.\n * @returns An initialized Panproto instance\n * @throws {@link import('./types.js').WasmError} if WASM loading fails\n */\n static async init(input?: string | URL | WasmGlueModule): Promise<Panproto> {\n const wasm = await loadWasm(input);\n return new Panproto(wasm);\n }\n\n /**\n * Get or register a protocol by name.\n *\n * If the protocol is a built-in (e.g., 'atproto', 'sql'), it is\n * automatically registered on first access. Custom protocols must\n * be registered first with {@link Panproto.defineProtocol}.\n *\n * @param name - The protocol name\n * @returns The protocol instance\n * @throws {@link PanprotoError} if the protocol is not found\n */\n protocol(name: string): Protocol {\n const cached = this.#protocols.get(name);\n if (cached) return cached;\n\n // Try built-in protocols\n const builtinSpec = BUILTIN_PROTOCOLS.get(name);\n if (builtinSpec) {\n const proto = defineProtocol(builtinSpec, this.#wasm);\n this.#protocols.set(name, proto);\n return proto;\n }\n\n throw new PanprotoError(\n `Protocol \"${name}\" not found. Register it with defineProtocol() first.`,\n );\n }\n\n /**\n * Define and register a custom protocol.\n *\n * @param spec - The protocol specification\n * @returns The registered protocol\n * @throws {@link PanprotoError} if registration fails\n */\n defineProtocol(spec: ProtocolSpec): Protocol {\n const proto = defineProtocol(spec, this.#wasm);\n this.#protocols.set(spec.name, proto);\n return proto;\n }\n\n /**\n * Start building a migration between two schemas.\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @returns A migration builder\n */\n migration(src: BuiltSchema, tgt: BuiltSchema): MigrationBuilder {\n return new MigrationBuilder(src, tgt, this.#wasm);\n }\n\n /**\n * Check existence conditions for a proposed migration.\n *\n * Verifies that the migration specification satisfies all\n * protocol-derived constraints (edge coverage, kind consistency,\n * required fields, etc.).\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @param builder - The migration builder with mappings\n * @returns The existence report\n */\n checkExistence(\n src: BuiltSchema,\n tgt: BuiltSchema,\n builder: MigrationBuilder,\n ): import('./types.js').ExistenceReport {\n const proto = this.#protocols.get(src.protocol);\n if (!proto) {\n throw new PanprotoError(\n `Protocol \"${src.protocol}\" not registered. Call protocol() first.`,\n );\n }\n return checkExistence(proto._handle.id, src, tgt, builder.toSpec(), this.#wasm);\n }\n\n /**\n * Compose two compiled migrations into a single migration.\n *\n * The resulting migration is equivalent to applying `m1` then `m2`.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @returns The composed migration\n * @throws {@link import('./types.js').MigrationError} if composition fails\n */\n compose(m1: CompiledMigration, m2: CompiledMigration): CompiledMigration {\n return composeMigrations(m1, m2, this.#wasm);\n }\n\n /**\n * Diff two schemas and produce a compatibility report.\n *\n * @param oldSchema - The old/source schema\n * @param newSchema - The new/target schema\n * @returns A diff report with changes and compatibility classification\n */\n diff(oldSchema: BuiltSchema, newSchema: BuiltSchema): DiffReport {\n const resultBytes = this.#wasm.exports.diff_schemas(\n oldSchema._handle.id,\n newSchema._handle.id,\n );\n return unpackFromWasm<DiffReport>(resultBytes);\n }\n\n /**\n * Release all WASM resources held by this instance.\n *\n * Disposes all cached protocols. After disposal, this instance\n * must not be used.\n */\n [Symbol.dispose](): void {\n for (const proto of this.#protocols.values()) {\n proto[Symbol.dispose]();\n }\n this.#protocols.clear();\n }\n}\n","/**\n * Lens and combinator API for bidirectional transformations.\n *\n * Every migration is a lens with `get` (forward projection) and\n * `put` (restore from complement). This module provides Cambria-style\n * combinators that compose into migrations.\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Combinator types\n// ---------------------------------------------------------------------------\n\n/** Rename a field from one name to another. */\nexport interface RenameFieldCombinator {\n readonly type: 'rename-field';\n readonly old: string;\n readonly new: string;\n}\n\n/** Add a new field with a default value. */\nexport interface AddFieldCombinator {\n readonly type: 'add-field';\n readonly name: string;\n readonly vertexKind: string;\n readonly default: unknown;\n}\n\n/** Remove a field from the schema. */\nexport interface RemoveFieldCombinator {\n readonly type: 'remove-field';\n readonly name: string;\n}\n\n/** Wrap a value inside a new object with a given field name. */\nexport interface WrapInObjectCombinator {\n readonly type: 'wrap-in-object';\n readonly fieldName: string;\n}\n\n/** Hoist a nested field up to the host level. */\nexport interface HoistFieldCombinator {\n readonly type: 'hoist-field';\n readonly host: string;\n readonly field: string;\n}\n\n/** Coerce a value from one type to another. */\nexport interface CoerceTypeCombinator {\n readonly type: 'coerce-type';\n readonly fromKind: string;\n readonly toKind: string;\n}\n\n/** Sequential composition of two combinators. */\nexport interface ComposeCombinator {\n readonly type: 'compose';\n readonly first: Combinator;\n readonly second: Combinator;\n}\n\n/** A lens combinator (Cambria-style). */\nexport type Combinator =\n | RenameFieldCombinator\n | AddFieldCombinator\n | RemoveFieldCombinator\n | WrapInObjectCombinator\n | HoistFieldCombinator\n | CoerceTypeCombinator\n | ComposeCombinator;\n\n// ---------------------------------------------------------------------------\n// Combinator constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Create a rename-field combinator.\n *\n * @param oldName - The current field name\n * @param newName - The desired field name\n * @returns A rename-field combinator\n */\nexport function renameField(oldName: string, newName: string): RenameFieldCombinator {\n return { type: 'rename-field', old: oldName, new: newName };\n}\n\n/**\n * Create an add-field combinator.\n *\n * @param name - The field name to add\n * @param vertexKind - The vertex kind for the new field\n * @param defaultValue - The default value for the field\n * @returns An add-field combinator\n */\nexport function addField(name: string, vertexKind: string, defaultValue: unknown): AddFieldCombinator {\n return { type: 'add-field', name, vertexKind, default: defaultValue };\n}\n\n/**\n * Create a remove-field combinator.\n *\n * @param name - The field name to remove\n * @returns A remove-field combinator\n */\nexport function removeField(name: string): RemoveFieldCombinator {\n return { type: 'remove-field', name };\n}\n\n/**\n * Create a wrap-in-object combinator.\n *\n * @param fieldName - The field name for the wrapper object\n * @returns A wrap-in-object combinator\n */\nexport function wrapInObject(fieldName: string): WrapInObjectCombinator {\n return { type: 'wrap-in-object', fieldName };\n}\n\n/**\n * Create a hoist-field combinator.\n *\n * @param host - The host vertex to hoist into\n * @param field - The nested field to hoist\n * @returns A hoist-field combinator\n */\nexport function hoistField(host: string, field: string): HoistFieldCombinator {\n return { type: 'hoist-field', host, field };\n}\n\n/**\n * Create a coerce-type combinator.\n *\n * @param fromKind - The source type kind\n * @param toKind - The target type kind\n * @returns A coerce-type combinator\n */\nexport function coerceType(fromKind: string, toKind: string): CoerceTypeCombinator {\n return { type: 'coerce-type', fromKind, toKind };\n}\n\n/**\n * Compose two combinators sequentially.\n *\n * @param first - The combinator applied first\n * @param second - The combinator applied second\n * @returns A composed combinator\n */\nexport function compose(first: Combinator, second: Combinator): ComposeCombinator {\n return { type: 'compose', first, second };\n}\n\n/**\n * Compose a chain of combinators left-to-right.\n *\n * @param combinators - The combinators to compose (at least one required)\n * @returns The composed combinator\n * @throws If the combinators array is empty\n */\nexport function pipeline(combinators: readonly [Combinator, ...Combinator[]]): Combinator {\n const [first, ...rest] = combinators;\n return rest.reduce<Combinator>((acc, c) => compose(acc, c), first);\n}\n\n/**\n * Serialize a combinator to a plain object for MessagePack encoding.\n *\n * @param combinator - The combinator to serialize\n * @returns A plain object suitable for MessagePack encoding\n */\nexport function combinatorToWire(combinator: Combinator): Record<string, unknown> {\n switch (combinator.type) {\n case 'rename-field':\n return { RenameField: { old: combinator.old, new: combinator.new } };\n case 'add-field':\n return { AddField: { name: combinator.name, vertex_kind: combinator.vertexKind, default: combinator.default } };\n case 'remove-field':\n return { RemoveField: { name: combinator.name } };\n case 'wrap-in-object':\n return { WrapInObject: { field_name: combinator.fieldName } };\n case 'hoist-field':\n return { HoistField: { host: combinator.host, field: combinator.field } };\n case 'coerce-type':\n return { CoerceType: { from_kind: combinator.fromKind, to_kind: combinator.toKind } };\n case 'compose':\n return { Compose: [combinatorToWire(combinator.first), combinatorToWire(combinator.second)] };\n }\n}\n"],"names":["exports","encode","decode"],"mappings":";;;;AAmNO,MAAM,sBAAsB,MAAM;AAAA,EACrB,OAAe;AAAA,EAEjC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF;AAGO,MAAM,kBA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AO,OAAO,IAAU;AACvB,eAAW,SAAS,KAAK,WAAW,OAAA,GAAU;AAC5C,YAAM,OAAO,OAAO,EAAA;AAAA,IACtB;AACA,SAAK,WAAW,MAAA;AAAA,EAClB;AACF;AChHO,SAAS,YAAY,SAAiB,SAAwC;AACnF,SAAO,EAAE,MAAM,gBAAgB,KAAK,SAAS,KAAK,QAAA;AACpD;AAUO,SAAS,SAAS,MAAc,YAAoB,cAA2C;AACpG,SAAO,EAAE,MAAM,aAAa,MAAM,YAAY,SAAS,aAAA;AACzD;AAQO,SAAS,YAAY,MAAqC;AAC/D,SAAO,EAAE,MAAM,gBAAgB,KAAA;AACjC;AAQO,SAAS,aAAa,WAA2C;AACtE,SAAO,EAAE,MAAM,kBAAkB,UAAA;AACnC;AASO,SAAS,WAAW,MAAc,OAAqC;AAC5E,SAAO,EAAE,MAAM,eAAe,MAAM,MAAA;AACtC;AASO,SAAS,WAAW,UAAkB,QAAsC;AACjF,SAAO,EAAE,MAAM,eAAe,UAAU,OAAA;AAC1C;AASO,SAAS,QAAQ,OAAmB,QAAuC;AAChF,SAAO,EAAE,MAAM,WAAW,OAAO,OAAA;AACnC;AASO,SAAS,SAAS,aAAiE;AACxF,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,SAAO,KAAK,OAAmB,CAAC,KAAK,MAAM,QAAQ,KAAK,CAAC,GAAG,KAAK;AACnE;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/types.ts","../src/wasm.ts","../src/msgpack.ts","../src/schema.ts","../src/protocol.ts","../src/migration.ts","../src/panproto.ts","../src/lens.ts"],"sourcesContent":["/**\n * Core type definitions for the @panproto/core SDK.\n *\n * These types mirror the Rust-side structures but use JavaScript idioms:\n * - `HashMap<K,V>` becomes `Map<K,V>` or `Record<string, V>` for string keys\n * - `Option<T>` becomes `T | undefined`\n * - `Vec<T>` becomes `T[]`\n * - `Result<T,E>` becomes thrown `PanprotoError` or return value\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Handle types (opaque wrappers — never expose raw u32)\n// ---------------------------------------------------------------------------\n\n/** Opaque handle to a WASM-side resource. */\nexport interface Handle {\n readonly __brand: unique symbol;\n readonly id: number;\n}\n\n/** Branded handle for a protocol resource. */\nexport interface ProtocolHandle extends Handle {\n readonly __kind: 'protocol';\n}\n\n/** Branded handle for a schema resource. */\nexport interface SchemaHandle extends Handle {\n readonly __kind: 'schema';\n}\n\n/** Branded handle for a compiled migration resource. */\nexport interface MigrationHandle extends Handle {\n readonly __kind: 'migration';\n}\n\n// ---------------------------------------------------------------------------\n// Protocol\n// ---------------------------------------------------------------------------\n\n/** Rule constraining which vertex kinds an edge can connect. */\nexport interface EdgeRule {\n readonly edgeKind: string;\n /** Allowed source vertex kinds. Empty array means any. */\n readonly srcKinds: readonly string[];\n /** Allowed target vertex kinds. Empty array means any. */\n readonly tgtKinds: readonly string[];\n}\n\n/** A protocol specification defining schema/instance theories and validation rules. */\nexport interface ProtocolSpec {\n readonly name: string;\n readonly schemaTheory: string;\n readonly instanceTheory: string;\n readonly edgeRules: readonly EdgeRule[];\n readonly objKinds: readonly string[];\n readonly constraintSorts: readonly string[];\n}\n\n// ---------------------------------------------------------------------------\n// Schema\n// ---------------------------------------------------------------------------\n\n/** Options for vertex creation. */\nexport interface VertexOptions {\n readonly nsid?: string;\n}\n\n/** A vertex in a schema graph. */\nexport interface Vertex {\n readonly id: string;\n readonly kind: string;\n readonly nsid?: string | undefined;\n}\n\n/** A directed edge in a schema graph. */\nexport interface Edge {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name?: string | undefined;\n}\n\n/** A hyperedge with a labeled signature. */\nexport interface HyperEdge {\n readonly id: string;\n readonly kind: string;\n readonly signature: Readonly<Record<string, string>>;\n readonly parentLabel: string;\n}\n\n/** A constraint on a vertex (sort + value). */\nexport interface Constraint {\n readonly sort: string;\n readonly value: string;\n}\n\n/** A variant in a schema graph (union member). */\nexport interface Variant {\n readonly id: string;\n readonly parent_vertex: string;\n readonly tag?: string | undefined;\n}\n\n/** A recursion point (mu-binding site). */\nexport interface RecursionPoint {\n readonly mu_id: string;\n readonly target_vertex: string;\n}\n\n/** Usage mode for a vertex (structural, linear, or affine). */\nexport type UsageMode = 'structural' | 'linear' | 'affine';\n\n/** A span between two vertices. */\nexport interface Span {\n readonly id: string;\n readonly left: string;\n readonly right: string;\n}\n\n/** Options for edge creation. */\nexport interface EdgeOptions {\n readonly name?: string;\n}\n\n/** Serializable schema representation. */\nexport interface SchemaData {\n readonly protocol: string;\n readonly vertices: Readonly<Record<string, Vertex>>;\n readonly edges: readonly Edge[];\n readonly hyperEdges: Readonly<Record<string, HyperEdge>>;\n readonly constraints: Readonly<Record<string, readonly Constraint[]>>;\n readonly required: Readonly<Record<string, readonly Edge[]>>;\n readonly variants: Readonly<Record<string, readonly Variant[]>>;\n readonly orderings: Readonly<Record<string, number>>;\n readonly recursionPoints: Readonly<Record<string, RecursionPoint>>;\n readonly usageModes: Readonly<Record<string, UsageMode>>;\n readonly spans: Readonly<Record<string, Span>>;\n readonly nominal: Readonly<Record<string, boolean>>;\n}\n\n// ---------------------------------------------------------------------------\n// Migration\n// ---------------------------------------------------------------------------\n\n/** A vertex mapping entry for migration building. */\nexport interface VertexMapping {\n readonly src: string;\n readonly tgt: string;\n}\n\n/** A migration specification (maps between two schemas). */\nexport interface MigrationSpec {\n readonly vertexMap: Readonly<Record<string, string>>;\n readonly edgeMap: readonly [Edge, Edge][];\n readonly resolvers: readonly [[string, string], Edge][];\n}\n\n/** Result of applying a compiled migration to a record. */\nexport interface LiftResult {\n readonly data: unknown;\n}\n\n/** Get result for bidirectional lens operation. */\nexport interface GetResult {\n readonly view: unknown;\n readonly complement: Uint8Array;\n}\n\n// ---------------------------------------------------------------------------\n// Diff / Compatibility\n// ---------------------------------------------------------------------------\n\n/** A single change detected between two schemas. */\nexport interface SchemaChange {\n readonly kind: 'vertex-added' | 'vertex-removed' | 'edge-added' | 'edge-removed'\n | 'constraint-added' | 'constraint-removed' | 'constraint-changed'\n | 'kind-changed' | 'required-added' | 'required-removed';\n readonly path: string;\n readonly detail?: string | undefined;\n}\n\n/** Compatibility classification. */\nexport type Compatibility = 'fully-compatible' | 'backward-compatible' | 'breaking';\n\n/** Schema diff report. */\nexport interface DiffReport {\n readonly compatibility: Compatibility;\n readonly changes: readonly SchemaChange[];\n}\n\n// ---------------------------------------------------------------------------\n// Existence checking\n// ---------------------------------------------------------------------------\n\n/** A structured existence error. */\nexport interface ExistenceError {\n readonly kind: 'edge-missing' | 'kind-inconsistency' | 'label-inconsistency'\n | 'required-field-missing' | 'constraint-tightened' | 'resolver-invalid'\n | 'well-formedness' | 'signature-coherence' | 'simultaneity' | 'reachability-risk';\n readonly message: string;\n readonly detail?: Record<string, unknown> | undefined;\n}\n\n/** Result of existence checking. */\nexport interface ExistenceReport {\n readonly valid: boolean;\n readonly errors: readonly ExistenceError[];\n}\n\n// ---------------------------------------------------------------------------\n// WASM module interface\n// ---------------------------------------------------------------------------\n\n/** The raw WASM module interface (10 entry points). */\nexport interface WasmExports {\n define_protocol(spec: Uint8Array): number;\n build_schema(proto: number, ops: Uint8Array): number;\n check_existence(proto: number, src: number, tgt: number, mapping: Uint8Array): Uint8Array;\n compile_migration(src: number, tgt: number, mapping: Uint8Array): number;\n lift_record(migration: number, record: Uint8Array): Uint8Array;\n get_record(migration: number, record: Uint8Array): Uint8Array;\n put_record(migration: number, view: Uint8Array, complement: Uint8Array): Uint8Array;\n compose_migrations(m1: number, m2: number): number;\n diff_schemas(s1: number, s2: number): Uint8Array;\n free_handle(handle: number): void;\n}\n\n/** WASM module wrapper including exports and memory. */\nexport interface WasmModule {\n readonly exports: WasmExports;\n readonly memory: WebAssembly.Memory;\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** Base error class for all panproto errors. */\nexport class PanprotoError extends Error {\n override readonly name: string = 'PanprotoError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/** Error from WASM boundary. */\nexport class WasmError extends PanprotoError {\n override readonly name = 'WasmError';\n}\n\n/** Error from schema validation. */\nexport class SchemaValidationError extends PanprotoError {\n override readonly name = 'SchemaValidationError';\n\n constructor(\n message: string,\n readonly errors: readonly string[],\n ) {\n super(message);\n }\n}\n\n/** Error from migration compilation. */\nexport class MigrationError extends PanprotoError {\n override readonly name = 'MigrationError';\n}\n\n/** Error from existence checking. */\nexport class ExistenceCheckError extends PanprotoError {\n override readonly name = 'ExistenceCheckError';\n\n constructor(\n message: string,\n readonly report: ExistenceReport,\n ) {\n super(message);\n }\n}\n","/**\n * WASM loading and handle management.\n *\n * Manages the lifecycle of WASM-side resources via opaque handles.\n * Uses `Symbol.dispose` for automatic cleanup and `FinalizationRegistry`\n * as a safety net for leaked handles.\n *\n * @module\n */\n\nimport type { WasmModule, WasmExports } from './types.js';\nimport { WasmError } from './types.js';\n\n/** Default wasm-bindgen glue module URL (relative to package root). */\nconst DEFAULT_GLUE_URL = new URL('./panproto_wasm.js', import.meta.url);\n\n/**\n * Shape of a pre-imported wasm-bindgen glue module.\n *\n * The `default` export is the wasm-bindgen init function. We type it\n * loosely so any wasm-bindgen output module satisfies the interface.\n */\nexport interface WasmGlueModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n default: (...args: any[]) => Promise<{ memory: WebAssembly.Memory }>;\n define_protocol: WasmExports['define_protocol'];\n build_schema: WasmExports['build_schema'];\n check_existence: WasmExports['check_existence'];\n compile_migration: WasmExports['compile_migration'];\n lift_record: WasmExports['lift_record'];\n get_record: WasmExports['get_record'];\n put_record: WasmExports['put_record'];\n compose_migrations: WasmExports['compose_migrations'];\n diff_schemas: WasmExports['diff_schemas'];\n free_handle: WasmExports['free_handle'];\n}\n\n/**\n * Load the panproto WASM module.\n *\n * Accepts either:\n * - A URL to the wasm-bindgen `.js` glue module (loaded via dynamic import)\n * - A pre-imported wasm-bindgen glue module object (for bundler environments like Vite)\n *\n * @param input - URL string, URL object, or pre-imported glue module.\n * Defaults to the bundled glue module URL.\n * @returns The initialized WASM module\n * @throws {@link WasmError} if loading or instantiation fails\n */\nexport async function loadWasm(input?: string | URL | WasmGlueModule): Promise<WasmModule> {\n try {\n let glue: WasmGlueModule;\n\n if (input && typeof input === 'object' && 'default' in input && typeof input.default === 'function') {\n // Pre-imported glue module — used in bundler environments (Vite, webpack)\n glue = input;\n } else {\n // Dynamic import from URL\n const url = (input as string | URL | undefined) ?? DEFAULT_GLUE_URL;\n glue = await import(/* @vite-ignore */ String(url));\n }\n\n const initOutput = await glue.default();\n\n const exports: WasmExports = {\n define_protocol: glue.define_protocol,\n build_schema: glue.build_schema,\n check_existence: glue.check_existence,\n compile_migration: glue.compile_migration,\n lift_record: glue.lift_record,\n get_record: glue.get_record,\n put_record: glue.put_record,\n compose_migrations: glue.compose_migrations,\n diff_schemas: glue.diff_schemas,\n free_handle: glue.free_handle,\n };\n\n const memory: WebAssembly.Memory = initOutput.memory;\n\n if (!memory) {\n throw new WasmError('WASM module missing memory export');\n }\n\n return { exports, memory };\n } catch (error) {\n if (error instanceof WasmError) throw error;\n throw new WasmError(\n `Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Handle registry — prevents resource leaks\n// ---------------------------------------------------------------------------\n\n/** Weak reference registry for leaked handle detection. */\nconst leakedHandleRegistry = new FinalizationRegistry<CleanupInfo>((info) => {\n // Safety net: if a disposable wrapper is GC'd without being disposed,\n // free the underlying WASM handle.\n try {\n info.freeHandle(info.handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n});\n\ninterface CleanupInfo {\n readonly handle: number;\n readonly freeHandle: (h: number) => void;\n}\n\n/**\n * A disposable wrapper around a WASM handle.\n *\n * Implements `Symbol.dispose` for use with `using` declarations.\n * A `FinalizationRegistry` acts as a safety net for handles that\n * are not explicitly disposed.\n */\nexport class WasmHandle implements Disposable {\n #handle: number;\n #disposed = false;\n readonly #freeHandle: (h: number) => void;\n\n constructor(handle: number, freeHandle: (h: number) => void) {\n this.#handle = handle;\n this.#freeHandle = freeHandle;\n\n leakedHandleRegistry.register(this, { handle, freeHandle }, this);\n }\n\n /** The raw WASM handle id. Only for internal use within the SDK. */\n get id(): number {\n if (this.#disposed) {\n throw new WasmError('Attempted to use a disposed handle');\n }\n return this.#handle;\n }\n\n /** Whether this handle has been disposed. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /** Release the underlying WASM resource. */\n [Symbol.dispose](): void {\n if (this.#disposed) return;\n this.#disposed = true;\n\n leakedHandleRegistry.unregister(this);\n\n try {\n this.#freeHandle(this.#handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n }\n}\n\n/**\n * Create a managed handle that will be freed when disposed.\n *\n * @param rawHandle - The u32 handle from WASM\n * @param wasm - The WASM module for freeing\n * @returns A disposable wrapper\n */\nexport function createHandle(rawHandle: number, wasm: WasmModule): WasmHandle {\n return new WasmHandle(rawHandle, (h) => wasm.exports.free_handle(h));\n}\n","/**\n * MessagePack encode/decode utilities for the WASM boundary.\n *\n * All structured data crossing the WASM boundary is serialized as MessagePack\n * byte slices. This module wraps `@msgpack/msgpack` with typed helpers.\n *\n * @module\n */\n\nimport { encode, decode } from '@msgpack/msgpack';\n\n/**\n * Encode a value to MessagePack bytes for sending to WASM.\n *\n * @param value - The value to encode\n * @returns MessagePack-encoded bytes\n */\nexport function packToWasm(value: unknown): Uint8Array {\n return encode(value);\n}\n\n/**\n * Decode MessagePack bytes received from WASM.\n *\n * @typeParam T - The expected decoded type\n * @param bytes - MessagePack-encoded bytes from WASM\n * @returns The decoded value\n */\nexport function unpackFromWasm<T = unknown>(bytes: Uint8Array): T {\n return decode(bytes) as T;\n}\n\n/**\n * Encode a schema operations list for the `build_schema` entry point.\n *\n * @param ops - Array of builder operations\n * @returns MessagePack-encoded bytes\n */\nexport function packSchemaOps(ops: readonly SchemaOp[]): Uint8Array {\n return encode(ops);\n}\n\n/**\n * Encode a migration mapping for WASM entry points.\n *\n * @param mapping - The migration mapping object\n * @returns MessagePack-encoded bytes\n */\nexport function packMigrationMapping(mapping: MigrationMapping): Uint8Array {\n return encode(mapping);\n}\n\n// ---------------------------------------------------------------------------\n// Internal types for structured WASM messages\n// ---------------------------------------------------------------------------\n\n/**\n * A single schema builder operation sent to WASM.\n *\n * Uses serde internally-tagged format: the `op` field acts as the\n * discriminant and all variant fields sit at the same level.\n */\nexport interface SchemaOp {\n readonly op: 'vertex' | 'edge' | 'hyper_edge' | 'constraint' | 'required';\n readonly [key: string]: unknown;\n}\n\n/** Wire format for an edge (matches Rust serialization). */\nexport interface EdgeWire {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name: string | null;\n}\n\n/** A migration mapping sent to WASM (matches Rust `Migration` struct). */\nexport interface MigrationMapping {\n readonly vertex_map: Record<string, string>;\n readonly edge_map: Map<EdgeWire, EdgeWire>;\n readonly hyper_edge_map: Record<string, string>;\n readonly label_map: Map<readonly [string, string], string>;\n readonly resolver: Map<readonly [string, string], EdgeWire>;\n}\n","/**\n * Fluent schema builder API.\n *\n * Builders are immutable: each method returns a new builder instance.\n * Call `.build()` to validate and produce the final schema.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Vertex,\n Edge,\n HyperEdge,\n Constraint,\n VertexOptions,\n EdgeOptions,\n SchemaData,\n} from './types.js';\nimport { SchemaValidationError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport type { SchemaOp } from './msgpack.js';\nimport { packSchemaOps } from './msgpack.js';\n\n/**\n * Immutable fluent builder for constructing schemas.\n *\n * Each mutation method returns a new `SchemaBuilder` instance,\n * leaving the original unchanged. The builder accumulates operations\n * that are sent to WASM on `.build()`.\n *\n * @example\n * ```typescript\n * const schema = builder\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n * ```\n */\nexport class SchemaBuilder {\n readonly #protocolName: string;\n readonly #protocolHandle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #ops: readonly SchemaOp[];\n readonly #vertices: ReadonlyMap<string, Vertex>;\n readonly #edges: readonly Edge[];\n readonly #hyperEdges: ReadonlyMap<string, HyperEdge>;\n readonly #constraints: ReadonlyMap<string, readonly Constraint[]>;\n readonly #required: ReadonlyMap<string, readonly Edge[]>;\n\n constructor(\n protocolName: string,\n protocolHandle: WasmHandle,\n wasm: WasmModule,\n ops: readonly SchemaOp[] = [],\n vertices: ReadonlyMap<string, Vertex> = new Map(),\n edges: readonly Edge[] = [],\n hyperEdges: ReadonlyMap<string, HyperEdge> = new Map(),\n constraints: ReadonlyMap<string, readonly Constraint[]> = new Map(),\n required: ReadonlyMap<string, readonly Edge[]> = new Map(),\n ) {\n this.#protocolName = protocolName;\n this.#protocolHandle = protocolHandle;\n this.#wasm = wasm;\n this.#ops = ops;\n this.#vertices = vertices;\n this.#edges = edges;\n this.#hyperEdges = hyperEdges;\n this.#constraints = constraints;\n this.#required = required;\n }\n\n /**\n * Add a vertex to the schema.\n *\n * @param id - Unique vertex identifier\n * @param kind - Vertex kind (e.g., 'record', 'object', 'string')\n * @param options - Optional vertex configuration (nsid, etc.)\n * @returns A new builder with the vertex added\n * @throws {@link SchemaValidationError} if vertex id is already in use\n */\n vertex(id: string, kind: string, options?: VertexOptions): SchemaBuilder {\n if (this.#vertices.has(id)) {\n throw new SchemaValidationError(\n `Vertex \"${id}\" already exists in schema`,\n [`Duplicate vertex id: ${id}`],\n );\n }\n\n const vertex: Vertex = {\n id,\n kind,\n nsid: options?.nsid,\n };\n\n const op: SchemaOp = {\n op: 'vertex',\n id,\n kind,\n nsid: options?.nsid ?? null,\n };\n\n const newVertices = new Map(this.#vertices);\n newVertices.set(id, vertex);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n newVertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a directed edge to the schema.\n *\n * @param src - Source vertex id\n * @param tgt - Target vertex id\n * @param kind - Edge kind (e.g., 'record-schema', 'prop')\n * @param options - Optional edge configuration (name, etc.)\n * @returns A new builder with the edge added\n * @throws {@link SchemaValidationError} if source or target vertex does not exist\n */\n edge(src: string, tgt: string, kind: string, options?: EdgeOptions): SchemaBuilder {\n if (!this.#vertices.has(src)) {\n throw new SchemaValidationError(\n `Edge source \"${src}\" does not exist`,\n [`Unknown source vertex: ${src}`],\n );\n }\n if (!this.#vertices.has(tgt)) {\n throw new SchemaValidationError(\n `Edge target \"${tgt}\" does not exist`,\n [`Unknown target vertex: ${tgt}`],\n );\n }\n\n const edge: Edge = {\n src,\n tgt,\n kind,\n name: options?.name,\n };\n\n const op: SchemaOp = {\n op: 'edge',\n src,\n tgt,\n kind,\n name: options?.name ?? null,\n };\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n [...this.#edges, edge],\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a hyperedge to the schema.\n *\n * Only valid if the protocol's schema theory includes ThHypergraph.\n *\n * @param id - Unique hyperedge identifier\n * @param kind - Hyperedge kind\n * @param signature - Label-to-vertex mapping\n * @param parentLabel - The label identifying the parent in the signature\n * @returns A new builder with the hyperedge added\n */\n hyperEdge(\n id: string,\n kind: string,\n signature: Record<string, string>,\n parentLabel: string,\n ): SchemaBuilder {\n const he: HyperEdge = { id, kind, signature, parentLabel };\n\n const op: SchemaOp = {\n op: 'hyper_edge',\n id,\n kind,\n signature,\n parent: parentLabel,\n };\n\n const newHyperEdges = new Map(this.#hyperEdges);\n newHyperEdges.set(id, he);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n newHyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a constraint to a vertex.\n *\n * @param vertexId - The vertex to constrain\n * @param sort - Constraint sort (e.g., 'maxLength')\n * @param value - Constraint value\n * @returns A new builder with the constraint added\n */\n constraint(vertexId: string, sort: string, value: string): SchemaBuilder {\n const c: Constraint = { sort, value };\n\n const op: SchemaOp = {\n op: 'constraint',\n vertex: vertexId,\n sort,\n value,\n };\n\n const existing = this.#constraints.get(vertexId) ?? [];\n const newConstraints = new Map(this.#constraints);\n newConstraints.set(vertexId, [...existing, c]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n newConstraints,\n this.#required,\n );\n }\n\n /**\n * Mark edges as required for a vertex.\n *\n * @param vertexId - The vertex with required edges\n * @param edges - The edges that are required\n * @returns A new builder with the requirement added\n */\n required(vertexId: string, edges: readonly Edge[]): SchemaBuilder {\n const op: SchemaOp = {\n op: 'required',\n vertex: vertexId,\n edges: edges.map((e) => ({\n src: e.src,\n tgt: e.tgt,\n kind: e.kind,\n name: e.name ?? null,\n })),\n };\n\n const existing = this.#required.get(vertexId) ?? [];\n const newRequired = new Map(this.#required);\n newRequired.set(vertexId, [...existing, ...edges]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n newRequired,\n );\n }\n\n /**\n * Validate and build the schema.\n *\n * Sends all accumulated operations to WASM for validation and construction.\n * Returns a `BuiltSchema` that holds the WASM handle and local data.\n *\n * @returns The validated, built schema\n * @throws {@link SchemaValidationError} if the schema is invalid\n */\n build(): BuiltSchema {\n const opsBytes = packSchemaOps([...this.#ops]);\n const rawHandle = this.#wasm.exports.build_schema(\n this.#protocolHandle.id,\n opsBytes,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n\n const data: SchemaData = {\n protocol: this.#protocolName,\n vertices: Object.fromEntries(this.#vertices),\n edges: [...this.#edges],\n hyperEdges: Object.fromEntries(this.#hyperEdges),\n constraints: Object.fromEntries(\n Array.from(this.#constraints.entries()).map(([k, v]) => [k, [...v]]),\n ),\n required: Object.fromEntries(\n Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]]),\n ),\n variants: {},\n orderings: {},\n recursionPoints: {},\n usageModes: {},\n spans: {},\n nominal: {},\n };\n\n return new BuiltSchema(handle, data, this.#wasm);\n }\n}\n\n/**\n * A validated, built schema with a WASM-side handle.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class BuiltSchema implements Disposable {\n readonly #handle: WasmHandle;\n readonly #data: SchemaData;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, data: SchemaData, wasm: WasmModule) {\n this.#handle = handle;\n this.#data = data;\n this.#wasm = wasm;\n }\n\n /** The WASM handle for this schema. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The WASM module reference. Internal use only. */\n get _wasm(): WasmModule {\n return this.#wasm;\n }\n\n /** The schema data (vertices, edges, constraints, etc.). */\n get data(): SchemaData {\n return this.#data;\n }\n\n /** The protocol name this schema belongs to. */\n get protocol(): string {\n return this.#data.protocol;\n }\n\n /** All vertices in the schema. */\n get vertices(): Readonly<Record<string, Vertex>> {\n return this.#data.vertices;\n }\n\n /** All edges in the schema. */\n get edges(): readonly Edge[] {\n return this.#data.edges;\n }\n\n /** Release the WASM-side schema resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n","/**\n * Protocol definition helpers.\n *\n * A protocol specifies the schema theory and instance theory used by\n * a family of schemas (e.g., ATProto, SQL, Protobuf). This module\n * provides helpers for defining and looking up protocols.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, EdgeRule } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm } from './msgpack.js';\nimport { SchemaBuilder } from './schema.js';\n\n/**\n * A registered protocol with a WASM-side handle.\n *\n * Provides a fluent API for building schemas within this protocol.\n * Implements `Disposable` for automatic cleanup.\n */\nexport class Protocol implements Disposable {\n readonly #handle: WasmHandle;\n readonly #spec: ProtocolSpec;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, spec: ProtocolSpec, wasm: WasmModule) {\n this.#handle = handle;\n this.#spec = spec;\n this.#wasm = wasm;\n }\n\n /** The protocol name. */\n get name(): string {\n return this.#spec.name;\n }\n\n /** The full protocol specification. */\n get spec(): ProtocolSpec {\n return this.#spec;\n }\n\n /** The WASM handle. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /**\n * Start building a schema within this protocol.\n *\n * @returns A new `SchemaBuilder` bound to this protocol\n */\n schema(): SchemaBuilder {\n return new SchemaBuilder(this.#spec.name, this.#handle, this.#wasm);\n }\n\n /** Release the WASM-side protocol resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Define a protocol by sending its specification to WASM.\n *\n * @param spec - The protocol specification\n * @param wasm - The WASM module\n * @returns A registered protocol with a WASM handle\n * @throws {@link PanprotoError} if the WASM call fails\n */\nexport function defineProtocol(spec: ProtocolSpec, wasm: WasmModule): Protocol {\n const wireSpec = {\n name: spec.name,\n schema_theory: spec.schemaTheory,\n instance_theory: spec.instanceTheory,\n edge_rules: spec.edgeRules.map((r) => ({\n edge_kind: r.edgeKind,\n src_kinds: [...r.srcKinds],\n tgt_kinds: [...r.tgtKinds],\n })),\n obj_kinds: [...spec.objKinds],\n constraint_sorts: [...spec.constraintSorts],\n };\n\n try {\n const bytes = packToWasm(wireSpec);\n const rawHandle = wasm.exports.define_protocol(bytes);\n const handle = createHandle(rawHandle, wasm);\n return new Protocol(handle, spec, wasm);\n } catch (error) {\n throw new PanprotoError(\n `Failed to define protocol \"${spec.name}\": ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Built-in protocol specs\n// ---------------------------------------------------------------------------\n\n/**\n * Built-in ATProto protocol specification.\n *\n * Schema theory: colimit(ThGraph, ThConstraint, ThMulti).\n * Instance theory: ThWType + ThMeta.\n */\nexport const ATPROTO_SPEC: ProtocolSpec = {\n name: 'atproto',\n schemaTheory: 'ThATProtoSchema',\n instanceTheory: 'ThATProtoInstance',\n edgeRules: [\n { edgeKind: 'record-schema', srcKinds: ['record'], tgtKinds: ['object'] },\n { edgeKind: 'prop', srcKinds: ['object', 'query', 'procedure', 'subscription'], tgtKinds: [] },\n { edgeKind: 'items', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['union'], tgtKinds: [] },\n { edgeKind: 'ref', srcKinds: [], tgtKinds: [] },\n { edgeKind: 'self-ref', srcKinds: [], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: [\n 'record', 'object', 'array', 'union', 'string', 'integer', 'boolean',\n 'bytes', 'cid-link', 'blob', 'unknown', 'token', 'query', 'procedure',\n 'subscription', 'ref',\n ],\n constraintSorts: [\n 'minLength', 'maxLength', 'minimum', 'maximum', 'maxGraphemes',\n 'enum', 'const', 'default', 'closed',\n ],\n};\n\n/**\n * Built-in SQL protocol specification.\n *\n * Schema theory: colimit(ThHypergraph, ThConstraint).\n * Instance theory: ThFunctor.\n */\nexport const SQL_SPEC: ProtocolSpec = {\n name: 'sql',\n schemaTheory: 'ThConstrainedHypergraph',\n instanceTheory: 'ThFunctor',\n edgeRules: [\n { edgeKind: 'column', srcKinds: ['table'], tgtKinds: ['type'] },\n { edgeKind: 'fk', srcKinds: ['table'], tgtKinds: ['table'] },\n { edgeKind: 'pk', srcKinds: ['table'], tgtKinds: ['column'] },\n ] satisfies EdgeRule[],\n objKinds: ['table'],\n constraintSorts: ['nullable', 'unique', 'check', 'default'],\n};\n\n/**\n * Built-in Protobuf protocol specification.\n */\nexport const PROTOBUF_SPEC: ProtocolSpec = {\n name: 'protobuf',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['message'], tgtKinds: [] },\n { edgeKind: 'nested', srcKinds: ['message'], tgtKinds: ['message', 'enum'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['message'],\n constraintSorts: ['field-number', 'repeated', 'optional', 'map-key', 'map-value'],\n};\n\n/**\n * Built-in GraphQL protocol specification.\n */\nexport const GRAPHQL_SPEC: ProtocolSpec = {\n name: 'graphql',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['type', 'input'], tgtKinds: [] },\n { edgeKind: 'implements', srcKinds: ['type'], tgtKinds: ['interface'] },\n { edgeKind: 'member', srcKinds: ['union'], tgtKinds: ['type'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['type', 'input'],\n constraintSorts: ['non-null', 'list', 'deprecated'],\n};\n\n/**\n * Built-in JSON Schema protocol specification.\n */\nexport const JSON_SCHEMA_SPEC: ProtocolSpec = {\n name: 'json-schema',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'property', srcKinds: ['object'], tgtKinds: [] },\n { edgeKind: 'item', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['oneOf', 'anyOf'], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: ['object'],\n constraintSorts: ['minLength', 'maxLength', 'minimum', 'maximum', 'pattern', 'format', 'required'],\n};\n\n/** Registry of built-in protocol specs, keyed by name. */\nexport const BUILTIN_PROTOCOLS: ReadonlyMap<string, ProtocolSpec> = new Map([\n ['atproto', ATPROTO_SPEC],\n ['sql', SQL_SPEC],\n ['protobuf', PROTOBUF_SPEC],\n ['graphql', GRAPHQL_SPEC],\n ['json-schema', JSON_SCHEMA_SPEC],\n]);\n","/**\n * Migration builder and compiled migration wrapper.\n *\n * Migrations define a mapping between two schemas. Once compiled,\n * they can efficiently transform records via WASM.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Edge,\n LiftResult,\n GetResult,\n ExistenceReport,\n MigrationSpec,\n} from './types.js';\nimport { MigrationError, WasmError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm, unpackFromWasm, packMigrationMapping } from './msgpack.js';\nimport type { BuiltSchema } from './schema.js';\n\n/**\n * Fluent builder for constructing migrations between two schemas.\n *\n * Each mutation method returns a new `MigrationBuilder` instance,\n * leaving the original unchanged.\n *\n * @example\n * ```typescript\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .map('post:body', 'post:body')\n * .mapEdge(oldEdge, newEdge)\n * .compile();\n * ```\n */\nexport class MigrationBuilder {\n readonly #src: BuiltSchema;\n readonly #tgt: BuiltSchema;\n readonly #wasm: WasmModule;\n readonly #vertexMap: ReadonlyMap<string, string>;\n readonly #edgeMap: readonly [Edge, Edge][];\n readonly #resolvers: readonly [[string, string], Edge][];\n\n constructor(\n src: BuiltSchema,\n tgt: BuiltSchema,\n wasm: WasmModule,\n vertexMap: ReadonlyMap<string, string> = new Map(),\n edgeMap: readonly [Edge, Edge][] = [],\n resolvers: readonly [[string, string], Edge][] = [],\n ) {\n this.#src = src;\n this.#tgt = tgt;\n this.#wasm = wasm;\n this.#vertexMap = vertexMap;\n this.#edgeMap = edgeMap;\n this.#resolvers = resolvers;\n }\n\n /**\n * Map a source vertex to a target vertex.\n *\n * @param srcVertex - Vertex id in the source schema\n * @param tgtVertex - Vertex id in the target schema\n * @returns A new builder with the mapping added\n */\n map(srcVertex: string, tgtVertex: string): MigrationBuilder {\n const newMap = new Map(this.#vertexMap);\n newMap.set(srcVertex, tgtVertex);\n\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n newMap,\n this.#edgeMap,\n this.#resolvers,\n );\n }\n\n /**\n * Map a source edge to a target edge.\n *\n * @param srcEdge - Edge in the source schema\n * @param tgtEdge - Edge in the target schema\n * @returns A new builder with the edge mapping added\n */\n mapEdge(srcEdge: Edge, tgtEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n [...this.#edgeMap, [srcEdge, tgtEdge]],\n this.#resolvers,\n );\n }\n\n /**\n * Add a resolver for ancestor contraction ambiguity.\n *\n * When a migration contracts nodes and the resulting edge between\n * two vertex kinds is ambiguous, a resolver specifies which edge to use.\n *\n * @param srcKind - Source vertex kind in the contracted pair\n * @param tgtKind - Target vertex kind in the contracted pair\n * @param resolvedEdge - The edge to use for this pair\n * @returns A new builder with the resolver added\n */\n resolve(srcKind: string, tgtKind: string, resolvedEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n this.#edgeMap,\n [...this.#resolvers, [[srcKind, tgtKind], resolvedEdge]],\n );\n }\n\n /**\n * Get the current migration specification.\n *\n * @returns The migration spec with all accumulated mappings\n */\n toSpec(): MigrationSpec {\n return {\n vertexMap: Object.fromEntries(this.#vertexMap),\n edgeMap: [...this.#edgeMap],\n resolvers: [...this.#resolvers],\n };\n }\n\n /**\n * Compile the migration for fast per-record application.\n *\n * Sends the migration specification to WASM for compilation.\n * The resulting `CompiledMigration` can be used to transform records.\n *\n * @returns A compiled migration ready for record transformation\n * @throws {@link MigrationError} if compilation fails\n */\n compile(): CompiledMigration {\n const edgeMap = new Map(\n this.#edgeMap.map(([src, tgt]) => [\n { src: src.src, tgt: src.tgt, kind: src.kind, name: src.name ?? null },\n { src: tgt.src, tgt: tgt.tgt, kind: tgt.kind, name: tgt.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n this.#resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: Object.fromEntries(this.#vertexMap),\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n try {\n const rawHandle = this.#wasm.exports.compile_migration(\n this.#src._handle.id,\n this.#tgt._handle.id,\n mapping,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n return new CompiledMigration(handle, this.#wasm, this.toSpec());\n } catch (error) {\n throw new MigrationError(\n `Failed to compile migration: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n}\n\n/**\n * A compiled migration that can efficiently transform records via WASM.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class CompiledMigration implements Disposable {\n readonly #handle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #spec: MigrationSpec;\n\n constructor(handle: WasmHandle, wasm: WasmModule, spec: MigrationSpec) {\n this.#handle = handle;\n this.#wasm = wasm;\n this.#spec = spec;\n }\n\n /** The WASM handle for this migration. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The migration specification used to build this migration. */\n get spec(): MigrationSpec {\n return this.#spec;\n }\n\n /**\n * Transform a record using this migration (forward direction).\n *\n * This is the hot path: data goes through WASM as MessagePack bytes\n * with no intermediate JS-heap allocation.\n *\n * @param record - The input record to transform\n * @returns The transformed record\n * @throws {@link WasmError} if the WASM call fails\n */\n lift(record: unknown): LiftResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.lift_record(\n this.#handle.id,\n inputBytes,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `lift_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional get: extract view and complement from a record.\n *\n * The complement captures data discarded by the forward projection,\n * enabling lossless round-tripping via `put()`.\n *\n * @param record - The input record\n * @returns The projected view and opaque complement bytes\n * @throws {@link WasmError} if the WASM call fails\n */\n get(record: unknown): GetResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.get_record(\n this.#handle.id,\n inputBytes,\n );\n const result = unpackFromWasm<{ view: unknown; complement: Uint8Array }>(outputBytes);\n return {\n view: result.view,\n complement: result.complement instanceof Uint8Array\n ? result.complement\n : new Uint8Array(result.complement as ArrayBuffer),\n };\n } catch (error) {\n throw new WasmError(\n `get_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional put: restore a full record from a modified view and complement.\n *\n * @param view - The (possibly modified) projected view\n * @param complement - The complement from a prior `get()` call\n * @returns The restored full record\n * @throws {@link WasmError} if the WASM call fails\n */\n put(view: unknown, complement: Uint8Array): LiftResult {\n const viewBytes = packToWasm(view);\n\n try {\n const outputBytes = this.#wasm.exports.put_record(\n this.#handle.id,\n viewBytes,\n complement,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `put_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /** Release the WASM-side compiled migration resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Check existence conditions for a migration between two schemas.\n *\n * @param src - Source schema handle\n * @param tgt - Target schema handle\n * @param spec - The migration specification\n * @param wasm - The WASM module\n * @returns The existence report\n */\nexport function checkExistence(\n protoHandle: number,\n src: BuiltSchema,\n tgt: BuiltSchema,\n spec: MigrationSpec,\n wasm: WasmModule,\n): ExistenceReport {\n const edgeMap = new Map(\n spec.edgeMap.map(([s, t]) => [\n { src: s.src, tgt: s.tgt, kind: s.kind, name: s.name ?? null },\n { src: t.src, tgt: t.tgt, kind: t.kind, name: t.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n spec.resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: spec.vertexMap,\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n const resultBytes = wasm.exports.check_existence(\n protoHandle,\n src._handle.id,\n tgt._handle.id,\n mapping,\n );\n\n return unpackFromWasm<ExistenceReport>(resultBytes);\n}\n\n/**\n * Compose two compiled migrations into a single migration.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @param wasm - The WASM module\n * @returns A new compiled migration representing m2 . m1\n * @throws {@link MigrationError} if composition fails\n */\nexport function composeMigrations(\n m1: CompiledMigration,\n m2: CompiledMigration,\n wasm: WasmModule,\n): CompiledMigration {\n try {\n const rawHandle = wasm.exports.compose_migrations(\n m1._handle.id,\n m2._handle.id,\n );\n const handle = createHandle(rawHandle, wasm);\n\n // Compose vertex maps: if m1 maps A->B and m2 maps B->C, composed maps A->C.\n // Vertices in m1 whose target is not remapped by m2 pass through unchanged.\n const composedVertexMap: Record<string, string> = {};\n for (const [src, intermediate] of Object.entries(m1.spec.vertexMap)) {\n const final_ = m2.spec.vertexMap[intermediate];\n composedVertexMap[src] = final_ ?? intermediate;\n }\n\n // Concatenate edge maps and resolvers from both migrations. The WASM side\n // performs the actual composition; this spec is a best-effort reconstruction\n // for introspection purposes.\n const composedSpec: MigrationSpec = {\n vertexMap: composedVertexMap,\n edgeMap: [...m1.spec.edgeMap, ...m2.spec.edgeMap],\n resolvers: [...m1.spec.resolvers, ...m2.spec.resolvers],\n };\n\n return new CompiledMigration(handle, wasm, composedSpec);\n } catch (error) {\n throw new MigrationError(\n `Failed to compose migrations: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n","/**\n * Main Panproto class — the primary entry point for the SDK.\n *\n * Wraps the WASM module and provides the high-level API for working\n * with protocols, schemas, migrations, and diffs.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, DiffReport } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { loadWasm, type WasmGlueModule } from './wasm.js';\nimport {\n Protocol,\n defineProtocol,\n BUILTIN_PROTOCOLS,\n} from './protocol.js';\nimport type { BuiltSchema } from './schema.js';\nimport {\n MigrationBuilder,\n CompiledMigration,\n checkExistence,\n composeMigrations,\n} from './migration.js';\nimport { unpackFromWasm } from './msgpack.js';\n\n/**\n * The main entry point for the panproto SDK.\n *\n * Create an instance with {@link Panproto.init}, then use it to define\n * protocols, build schemas, compile migrations, and diff schemas.\n *\n * Implements `Disposable` so it can be used with `using` to automatically\n * clean up all WASM resources.\n *\n * @example\n * ```typescript\n * const panproto = await Panproto.init();\n * const atproto = panproto.protocol('atproto');\n *\n * const schema = atproto.schema()\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n *\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .compile();\n *\n * const result = migration.lift(inputRecord);\n * ```\n */\nexport class Panproto implements Disposable {\n readonly #wasm: WasmModule;\n readonly #protocols: Map<string, Protocol>;\n\n private constructor(wasm: WasmModule) {\n this.#wasm = wasm;\n this.#protocols = new Map();\n }\n\n /**\n * Initialize the panproto SDK by loading the WASM module.\n *\n * @param input - URL to the wasm-bindgen glue module, or a pre-imported\n * glue module object (for bundler environments like Vite).\n * Defaults to the bundled glue module.\n * @returns An initialized Panproto instance\n * @throws {@link import('./types.js').WasmError} if WASM loading fails\n */\n static async init(input?: string | URL | WasmGlueModule): Promise<Panproto> {\n const wasm = await loadWasm(input);\n return new Panproto(wasm);\n }\n\n /**\n * Get or register a protocol by name.\n *\n * If the protocol is a built-in (e.g., 'atproto', 'sql'), it is\n * automatically registered on first access. Custom protocols must\n * be registered first with {@link Panproto.defineProtocol}.\n *\n * @param name - The protocol name\n * @returns The protocol instance\n * @throws {@link PanprotoError} if the protocol is not found\n */\n protocol(name: string): Protocol {\n const cached = this.#protocols.get(name);\n if (cached) return cached;\n\n // Try built-in protocols\n const builtinSpec = BUILTIN_PROTOCOLS.get(name);\n if (builtinSpec) {\n const proto = defineProtocol(builtinSpec, this.#wasm);\n this.#protocols.set(name, proto);\n return proto;\n }\n\n throw new PanprotoError(\n `Protocol \"${name}\" not found. Register it with defineProtocol() first.`,\n );\n }\n\n /**\n * Define and register a custom protocol.\n *\n * @param spec - The protocol specification\n * @returns The registered protocol\n * @throws {@link PanprotoError} if registration fails\n */\n defineProtocol(spec: ProtocolSpec): Protocol {\n const proto = defineProtocol(spec, this.#wasm);\n this.#protocols.set(spec.name, proto);\n return proto;\n }\n\n /**\n * Start building a migration between two schemas.\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @returns A migration builder\n */\n migration(src: BuiltSchema, tgt: BuiltSchema): MigrationBuilder {\n return new MigrationBuilder(src, tgt, this.#wasm);\n }\n\n /**\n * Check existence conditions for a proposed migration.\n *\n * Verifies that the migration specification satisfies all\n * protocol-derived constraints (edge coverage, kind consistency,\n * required fields, etc.).\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @param builder - The migration builder with mappings\n * @returns The existence report\n */\n checkExistence(\n src: BuiltSchema,\n tgt: BuiltSchema,\n builder: MigrationBuilder,\n ): import('./types.js').ExistenceReport {\n const proto = this.#protocols.get(src.protocol);\n if (!proto) {\n throw new PanprotoError(\n `Protocol \"${src.protocol}\" not registered. Call protocol() first.`,\n );\n }\n return checkExistence(proto._handle.id, src, tgt, builder.toSpec(), this.#wasm);\n }\n\n /**\n * Compose two compiled migrations into a single migration.\n *\n * The resulting migration is equivalent to applying `m1` then `m2`.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @returns The composed migration\n * @throws {@link import('./types.js').MigrationError} if composition fails\n */\n compose(m1: CompiledMigration, m2: CompiledMigration): CompiledMigration {\n return composeMigrations(m1, m2, this.#wasm);\n }\n\n /**\n * Diff two schemas and produce a compatibility report.\n *\n * @param oldSchema - The old/source schema\n * @param newSchema - The new/target schema\n * @returns A diff report with changes and compatibility classification\n */\n diff(oldSchema: BuiltSchema, newSchema: BuiltSchema): DiffReport {\n const resultBytes = this.#wasm.exports.diff_schemas(\n oldSchema._handle.id,\n newSchema._handle.id,\n );\n return unpackFromWasm<DiffReport>(resultBytes);\n }\n\n /**\n * Release all WASM resources held by this instance.\n *\n * Disposes all cached protocols. After disposal, this instance\n * must not be used.\n */\n [Symbol.dispose](): void {\n for (const proto of this.#protocols.values()) {\n proto[Symbol.dispose]();\n }\n this.#protocols.clear();\n }\n}\n","/**\n * Lens and combinator API for bidirectional transformations.\n *\n * Every migration is a lens with `get` (forward projection) and\n * `put` (restore from complement). This module provides Cambria-style\n * combinators that compose into migrations.\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Combinator types\n// ---------------------------------------------------------------------------\n\n/** Rename a field from one name to another. */\nexport interface RenameFieldCombinator {\n readonly type: 'rename-field';\n readonly old: string;\n readonly new: string;\n}\n\n/** Add a new field with a default value. */\nexport interface AddFieldCombinator {\n readonly type: 'add-field';\n readonly name: string;\n readonly vertexKind: string;\n readonly default: unknown;\n}\n\n/** Remove a field from the schema. */\nexport interface RemoveFieldCombinator {\n readonly type: 'remove-field';\n readonly name: string;\n}\n\n/** Wrap a value inside a new object with a given field name. */\nexport interface WrapInObjectCombinator {\n readonly type: 'wrap-in-object';\n readonly fieldName: string;\n}\n\n/** Hoist a nested field up to the host level. */\nexport interface HoistFieldCombinator {\n readonly type: 'hoist-field';\n readonly host: string;\n readonly field: string;\n}\n\n/** Coerce a value from one type to another. */\nexport interface CoerceTypeCombinator {\n readonly type: 'coerce-type';\n readonly fromKind: string;\n readonly toKind: string;\n}\n\n/** Sequential composition of two combinators. */\nexport interface ComposeCombinator {\n readonly type: 'compose';\n readonly first: Combinator;\n readonly second: Combinator;\n}\n\n/** A lens combinator (Cambria-style). */\nexport type Combinator =\n | RenameFieldCombinator\n | AddFieldCombinator\n | RemoveFieldCombinator\n | WrapInObjectCombinator\n | HoistFieldCombinator\n | CoerceTypeCombinator\n | ComposeCombinator;\n\n// ---------------------------------------------------------------------------\n// Combinator constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Create a rename-field combinator.\n *\n * @param oldName - The current field name\n * @param newName - The desired field name\n * @returns A rename-field combinator\n */\nexport function renameField(oldName: string, newName: string): RenameFieldCombinator {\n return { type: 'rename-field', old: oldName, new: newName };\n}\n\n/**\n * Create an add-field combinator.\n *\n * @param name - The field name to add\n * @param vertexKind - The vertex kind for the new field\n * @param defaultValue - The default value for the field\n * @returns An add-field combinator\n */\nexport function addField(name: string, vertexKind: string, defaultValue: unknown): AddFieldCombinator {\n return { type: 'add-field', name, vertexKind, default: defaultValue };\n}\n\n/**\n * Create a remove-field combinator.\n *\n * @param name - The field name to remove\n * @returns A remove-field combinator\n */\nexport function removeField(name: string): RemoveFieldCombinator {\n return { type: 'remove-field', name };\n}\n\n/**\n * Create a wrap-in-object combinator.\n *\n * @param fieldName - The field name for the wrapper object\n * @returns A wrap-in-object combinator\n */\nexport function wrapInObject(fieldName: string): WrapInObjectCombinator {\n return { type: 'wrap-in-object', fieldName };\n}\n\n/**\n * Create a hoist-field combinator.\n *\n * @param host - The host vertex to hoist into\n * @param field - The nested field to hoist\n * @returns A hoist-field combinator\n */\nexport function hoistField(host: string, field: string): HoistFieldCombinator {\n return { type: 'hoist-field', host, field };\n}\n\n/**\n * Create a coerce-type combinator.\n *\n * @param fromKind - The source type kind\n * @param toKind - The target type kind\n * @returns A coerce-type combinator\n */\nexport function coerceType(fromKind: string, toKind: string): CoerceTypeCombinator {\n return { type: 'coerce-type', fromKind, toKind };\n}\n\n/**\n * Compose two combinators sequentially.\n *\n * @param first - The combinator applied first\n * @param second - The combinator applied second\n * @returns A composed combinator\n */\nexport function compose(first: Combinator, second: Combinator): ComposeCombinator {\n return { type: 'compose', first, second };\n}\n\n/**\n * Compose a chain of combinators left-to-right.\n *\n * @param combinators - The combinators to compose (at least one required)\n * @returns The composed combinator\n * @throws If the combinators array is empty\n */\nexport function pipeline(combinators: readonly [Combinator, ...Combinator[]]): Combinator {\n const [first, ...rest] = combinators;\n return rest.reduce<Combinator>((acc, c) => compose(acc, c), first);\n}\n\n/**\n * Serialize a combinator to a plain object for MessagePack encoding.\n *\n * @param combinator - The combinator to serialize\n * @returns A plain object suitable for MessagePack encoding\n */\nexport function combinatorToWire(combinator: Combinator): Record<string, unknown> {\n switch (combinator.type) {\n case 'rename-field':\n return { RenameField: { old: combinator.old, new: combinator.new } };\n case 'add-field':\n return { AddField: { name: combinator.name, vertex_kind: combinator.vertexKind, default: combinator.default } };\n case 'remove-field':\n return { RemoveField: { name: combinator.name } };\n case 'wrap-in-object':\n return { WrapInObject: { field_name: combinator.fieldName } };\n case 'hoist-field':\n return { HoistField: { host: combinator.host, field: combinator.field } };\n case 'coerce-type':\n return { CoerceType: { from_kind: combinator.fromKind, to_kind: combinator.toKind } };\n case 'compose':\n return { Compose: [combinatorToWire(combinator.first), combinatorToWire(combinator.second)] };\n }\n}\n"],"names":["exports","encode","decode"],"mappings":";;;;AAgPO,MAAM,sBAAsB,MAAM;AAAA,EACrB,OAAe;AAAA,EAEjC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF;AAGO,MAAM,kBAAkB,cAAc;AAAA,EACzB,OAAO;AAC3B;AAGO,MAAM,8BAA8B,cAAc;AAAA,EAGvD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AAGO,MAAM,uBAAuB,cAAc;AAAA,EAC9B,OAAO;AAC3B;AAGO,MAAM,4BAA4B,cAAc;AAAA,EAGrD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AC1QA,MAAM,mBAAmB,IAAA,IAAA,wQAAA;AAmCzB,eAAsB,SAAS,OAA4D;AACzF,MAAI;AACF,QAAI;AAEJ,QAAI,SAAS,OAAO,UAAU,YAAY,aAAa,SAAS,OAAO,MAAM,YAAY,YAAY;AAEnG,aAAO;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gBAAgB,KAAA;AACjC;AAQO,SAAS,aAAa,WAA2C;AACtE,SAAO,EAAE,MAAM,kBAAkB,UAAA;AACnC;AASO,SAAS,WAAW,MAAc,OAAqC;AAC5E,SAAO,EAAE,MAAM,eAAe,MAAM,MAAA;AACtC;AASO,SAAS,WAAW,UAAkB,QAAsC;AACjF,SAAO,EAAE,MAAM,eAAe,UAAU,OAAA;AAC1C;AASO,SAAS,QAAQ,OAAmB,QAAuC;AAChF,SAAO,EAAE,MAAM,WAAW,OAAO,OAAA;AACnC;AASO,SAAS,SAAS,aAAiE;AACxF,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,SAAO,KAAK,OAAmB,CAAC,KAAK,MAAM,QAAQ,KAAK,CAAC,GAAG,KAAK;AACnE;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export { SchemaBuilder, BuiltSchema } from './schema.js';
|
|
|
26
26
|
export { MigrationBuilder, CompiledMigration } from './migration.js';
|
|
27
27
|
export { renameField, addField, removeField, wrapInObject, hoistField, coerceType, compose, pipeline, } from './lens.js';
|
|
28
28
|
export type { Combinator, RenameFieldCombinator, AddFieldCombinator, RemoveFieldCombinator, WrapInObjectCombinator, HoistFieldCombinator, CoerceTypeCombinator, ComposeCombinator, } from './lens.js';
|
|
29
|
-
export type { ProtocolSpec, EdgeRule, Vertex, Edge, HyperEdge, Constraint, VertexOptions, EdgeOptions, SchemaData, MigrationSpec, LiftResult, GetResult, DiffReport, SchemaChange, Compatibility, ExistenceReport, ExistenceError, WasmModule, WasmExports, } from './types.js';
|
|
29
|
+
export type { ProtocolSpec, EdgeRule, Vertex, Edge, HyperEdge, Constraint, Variant, RecursionPoint, UsageMode, Span, VertexOptions, EdgeOptions, SchemaData, MigrationSpec, LiftResult, GetResult, DiffReport, SchemaChange, Compatibility, ExistenceReport, ExistenceError, WasmModule, WasmExports, } from './types.js';
|
|
30
30
|
export type { WasmGlueModule } from './wasm.js';
|
|
31
31
|
export { PanprotoError, WasmError, SchemaValidationError, MigrationError, ExistenceCheckError, } from './types.js';
|
|
32
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGrE,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGrE,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,SAAS,EACT,UAAU,EACV,OAAO,EACP,cAAc,EACd,SAAS,EACT,IAAI,EACJ,aAAa,EACb,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -350,7 +350,13 @@ class SchemaBuilder {
|
|
|
350
350
|
),
|
|
351
351
|
required: Object.fromEntries(
|
|
352
352
|
Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]])
|
|
353
|
-
)
|
|
353
|
+
),
|
|
354
|
+
variants: {},
|
|
355
|
+
orderings: {},
|
|
356
|
+
recursionPoints: {},
|
|
357
|
+
usageModes: {},
|
|
358
|
+
spans: {},
|
|
359
|
+
nominal: {}
|
|
354
360
|
};
|
|
355
361
|
return new BuiltSchema(handle, data, this.#wasm);
|
|
356
362
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/types.ts","../src/wasm.ts","../src/msgpack.ts","../src/schema.ts","../src/protocol.ts","../src/migration.ts","../src/panproto.ts","../src/lens.ts"],"sourcesContent":["/**\n * Core type definitions for the @panproto/core SDK.\n *\n * These types mirror the Rust-side structures but use JavaScript idioms:\n * - `HashMap<K,V>` becomes `Map<K,V>` or `Record<string, V>` for string keys\n * - `Option<T>` becomes `T | undefined`\n * - `Vec<T>` becomes `T[]`\n * - `Result<T,E>` becomes thrown `PanprotoError` or return value\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Handle types (opaque wrappers — never expose raw u32)\n// ---------------------------------------------------------------------------\n\n/** Opaque handle to a WASM-side resource. */\nexport interface Handle {\n readonly __brand: unique symbol;\n readonly id: number;\n}\n\n/** Branded handle for a protocol resource. */\nexport interface ProtocolHandle extends Handle {\n readonly __kind: 'protocol';\n}\n\n/** Branded handle for a schema resource. */\nexport interface SchemaHandle extends Handle {\n readonly __kind: 'schema';\n}\n\n/** Branded handle for a compiled migration resource. */\nexport interface MigrationHandle extends Handle {\n readonly __kind: 'migration';\n}\n\n// ---------------------------------------------------------------------------\n// Protocol\n// ---------------------------------------------------------------------------\n\n/** Rule constraining which vertex kinds an edge can connect. */\nexport interface EdgeRule {\n readonly edgeKind: string;\n /** Allowed source vertex kinds. Empty array means any. */\n readonly srcKinds: readonly string[];\n /** Allowed target vertex kinds. Empty array means any. */\n readonly tgtKinds: readonly string[];\n}\n\n/** A protocol specification defining schema/instance theories and validation rules. */\nexport interface ProtocolSpec {\n readonly name: string;\n readonly schemaTheory: string;\n readonly instanceTheory: string;\n readonly edgeRules: readonly EdgeRule[];\n readonly objKinds: readonly string[];\n readonly constraintSorts: readonly string[];\n}\n\n// ---------------------------------------------------------------------------\n// Schema\n// ---------------------------------------------------------------------------\n\n/** Options for vertex creation. */\nexport interface VertexOptions {\n readonly nsid?: string;\n}\n\n/** A vertex in a schema graph. */\nexport interface Vertex {\n readonly id: string;\n readonly kind: string;\n readonly nsid?: string | undefined;\n}\n\n/** A directed edge in a schema graph. */\nexport interface Edge {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name?: string | undefined;\n}\n\n/** A hyperedge with a labeled signature. */\nexport interface HyperEdge {\n readonly id: string;\n readonly kind: string;\n readonly signature: Readonly<Record<string, string>>;\n readonly parentLabel: string;\n}\n\n/** A constraint on a vertex (sort + value). */\nexport interface Constraint {\n readonly sort: string;\n readonly value: string;\n}\n\n/** Options for edge creation. */\nexport interface EdgeOptions {\n readonly name?: string;\n}\n\n/** Serializable schema representation. */\nexport interface SchemaData {\n readonly protocol: string;\n readonly vertices: Readonly<Record<string, Vertex>>;\n readonly edges: readonly Edge[];\n readonly hyperEdges: Readonly<Record<string, HyperEdge>>;\n readonly constraints: Readonly<Record<string, readonly Constraint[]>>;\n readonly required: Readonly<Record<string, readonly Edge[]>>;\n}\n\n// ---------------------------------------------------------------------------\n// Migration\n// ---------------------------------------------------------------------------\n\n/** A vertex mapping entry for migration building. */\nexport interface VertexMapping {\n readonly src: string;\n readonly tgt: string;\n}\n\n/** A migration specification (maps between two schemas). */\nexport interface MigrationSpec {\n readonly vertexMap: Readonly<Record<string, string>>;\n readonly edgeMap: readonly [Edge, Edge][];\n readonly resolvers: readonly [[string, string], Edge][];\n}\n\n/** Result of applying a compiled migration to a record. */\nexport interface LiftResult {\n readonly data: unknown;\n}\n\n/** Get result for bidirectional lens operation. */\nexport interface GetResult {\n readonly view: unknown;\n readonly complement: Uint8Array;\n}\n\n// ---------------------------------------------------------------------------\n// Diff / Compatibility\n// ---------------------------------------------------------------------------\n\n/** A single change detected between two schemas. */\nexport interface SchemaChange {\n readonly kind: 'vertex-added' | 'vertex-removed' | 'edge-added' | 'edge-removed'\n | 'constraint-added' | 'constraint-removed' | 'constraint-changed'\n | 'kind-changed' | 'required-added' | 'required-removed';\n readonly path: string;\n readonly detail?: string | undefined;\n}\n\n/** Compatibility classification. */\nexport type Compatibility = 'fully-compatible' | 'backward-compatible' | 'breaking';\n\n/** Schema diff report. */\nexport interface DiffReport {\n readonly compatibility: Compatibility;\n readonly changes: readonly SchemaChange[];\n}\n\n// ---------------------------------------------------------------------------\n// Existence checking\n// ---------------------------------------------------------------------------\n\n/** A structured existence error. */\nexport interface ExistenceError {\n readonly kind: 'edge-missing' | 'kind-inconsistency' | 'label-inconsistency'\n | 'required-field-missing' | 'constraint-tightened' | 'resolver-invalid'\n | 'well-formedness' | 'signature-coherence' | 'simultaneity' | 'reachability-risk';\n readonly message: string;\n readonly detail?: Record<string, unknown> | undefined;\n}\n\n/** Result of existence checking. */\nexport interface ExistenceReport {\n readonly valid: boolean;\n readonly errors: readonly ExistenceError[];\n}\n\n// ---------------------------------------------------------------------------\n// WASM module interface\n// ---------------------------------------------------------------------------\n\n/** The raw WASM module interface (10 entry points). */\nexport interface WasmExports {\n define_protocol(spec: Uint8Array): number;\n build_schema(proto: number, ops: Uint8Array): number;\n check_existence(proto: number, src: number, tgt: number, mapping: Uint8Array): Uint8Array;\n compile_migration(src: number, tgt: number, mapping: Uint8Array): number;\n lift_record(migration: number, record: Uint8Array): Uint8Array;\n get_record(migration: number, record: Uint8Array): Uint8Array;\n put_record(migration: number, view: Uint8Array, complement: Uint8Array): Uint8Array;\n compose_migrations(m1: number, m2: number): number;\n diff_schemas(s1: number, s2: number): Uint8Array;\n free_handle(handle: number): void;\n}\n\n/** WASM module wrapper including exports and memory. */\nexport interface WasmModule {\n readonly exports: WasmExports;\n readonly memory: WebAssembly.Memory;\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** Base error class for all panproto errors. */\nexport class PanprotoError extends Error {\n override readonly name: string = 'PanprotoError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/** Error from WASM boundary. */\nexport class WasmError extends PanprotoError {\n override readonly name = 'WasmError';\n}\n\n/** Error from schema validation. */\nexport class SchemaValidationError extends PanprotoError {\n override readonly name = 'SchemaValidationError';\n\n constructor(\n message: string,\n readonly errors: readonly string[],\n ) {\n super(message);\n }\n}\n\n/** Error from migration compilation. */\nexport class MigrationError extends PanprotoError {\n override readonly name = 'MigrationError';\n}\n\n/** Error from existence checking. */\nexport class ExistenceCheckError extends PanprotoError {\n override readonly name = 'ExistenceCheckError';\n\n constructor(\n message: string,\n readonly report: ExistenceReport,\n ) {\n super(message);\n }\n}\n","/**\n * WASM loading and handle management.\n *\n * Manages the lifecycle of WASM-side resources via opaque handles.\n * Uses `Symbol.dispose` for automatic cleanup and `FinalizationRegistry`\n * as a safety net for leaked handles.\n *\n * @module\n */\n\nimport type { WasmModule, WasmExports } from './types.js';\nimport { WasmError } from './types.js';\n\n/** Default wasm-bindgen glue module URL (relative to package root). */\nconst DEFAULT_GLUE_URL = new URL('./panproto_wasm.js', import.meta.url);\n\n/**\n * Shape of a pre-imported wasm-bindgen glue module.\n *\n * The `default` export is the wasm-bindgen init function. We type it\n * loosely so any wasm-bindgen output module satisfies the interface.\n */\nexport interface WasmGlueModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n default: (...args: any[]) => Promise<{ memory: WebAssembly.Memory }>;\n define_protocol: WasmExports['define_protocol'];\n build_schema: WasmExports['build_schema'];\n check_existence: WasmExports['check_existence'];\n compile_migration: WasmExports['compile_migration'];\n lift_record: WasmExports['lift_record'];\n get_record: WasmExports['get_record'];\n put_record: WasmExports['put_record'];\n compose_migrations: WasmExports['compose_migrations'];\n diff_schemas: WasmExports['diff_schemas'];\n free_handle: WasmExports['free_handle'];\n}\n\n/**\n * Load the panproto WASM module.\n *\n * Accepts either:\n * - A URL to the wasm-bindgen `.js` glue module (loaded via dynamic import)\n * - A pre-imported wasm-bindgen glue module object (for bundler environments like Vite)\n *\n * @param input - URL string, URL object, or pre-imported glue module.\n * Defaults to the bundled glue module URL.\n * @returns The initialized WASM module\n * @throws {@link WasmError} if loading or instantiation fails\n */\nexport async function loadWasm(input?: string | URL | WasmGlueModule): Promise<WasmModule> {\n try {\n let glue: WasmGlueModule;\n\n if (input && typeof input === 'object' && 'default' in input && typeof input.default === 'function') {\n // Pre-imported glue module — used in bundler environments (Vite, webpack)\n glue = input;\n } else {\n // Dynamic import from URL\n const url = (input as string | URL | undefined) ?? DEFAULT_GLUE_URL;\n glue = await import(/* @vite-ignore */ String(url));\n }\n\n const initOutput = await glue.default();\n\n const exports: WasmExports = {\n define_protocol: glue.define_protocol,\n build_schema: glue.build_schema,\n check_existence: glue.check_existence,\n compile_migration: glue.compile_migration,\n lift_record: glue.lift_record,\n get_record: glue.get_record,\n put_record: glue.put_record,\n compose_migrations: glue.compose_migrations,\n diff_schemas: glue.diff_schemas,\n free_handle: glue.free_handle,\n };\n\n const memory: WebAssembly.Memory = initOutput.memory;\n\n if (!memory) {\n throw new WasmError('WASM module missing memory export');\n }\n\n return { exports, memory };\n } catch (error) {\n if (error instanceof WasmError) throw error;\n throw new WasmError(\n `Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Handle registry — prevents resource leaks\n// ---------------------------------------------------------------------------\n\n/** Weak reference registry for leaked handle detection. */\nconst leakedHandleRegistry = new FinalizationRegistry<CleanupInfo>((info) => {\n // Safety net: if a disposable wrapper is GC'd without being disposed,\n // free the underlying WASM handle.\n try {\n info.freeHandle(info.handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n});\n\ninterface CleanupInfo {\n readonly handle: number;\n readonly freeHandle: (h: number) => void;\n}\n\n/**\n * A disposable wrapper around a WASM handle.\n *\n * Implements `Symbol.dispose` for use with `using` declarations.\n * A `FinalizationRegistry` acts as a safety net for handles that\n * are not explicitly disposed.\n */\nexport class WasmHandle implements Disposable {\n #handle: number;\n #disposed = false;\n readonly #freeHandle: (h: number) => void;\n\n constructor(handle: number, freeHandle: (h: number) => void) {\n this.#handle = handle;\n this.#freeHandle = freeHandle;\n\n leakedHandleRegistry.register(this, { handle, freeHandle }, this);\n }\n\n /** The raw WASM handle id. Only for internal use within the SDK. */\n get id(): number {\n if (this.#disposed) {\n throw new WasmError('Attempted to use a disposed handle');\n }\n return this.#handle;\n }\n\n /** Whether this handle has been disposed. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /** Release the underlying WASM resource. */\n [Symbol.dispose](): void {\n if (this.#disposed) return;\n this.#disposed = true;\n\n leakedHandleRegistry.unregister(this);\n\n try {\n this.#freeHandle(this.#handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n }\n}\n\n/**\n * Create a managed handle that will be freed when disposed.\n *\n * @param rawHandle - The u32 handle from WASM\n * @param wasm - The WASM module for freeing\n * @returns A disposable wrapper\n */\nexport function createHandle(rawHandle: number, wasm: WasmModule): WasmHandle {\n return new WasmHandle(rawHandle, (h) => wasm.exports.free_handle(h));\n}\n","/**\n * MessagePack encode/decode utilities for the WASM boundary.\n *\n * All structured data crossing the WASM boundary is serialized as MessagePack\n * byte slices. This module wraps `@msgpack/msgpack` with typed helpers.\n *\n * @module\n */\n\nimport { encode, decode } from '@msgpack/msgpack';\n\n/**\n * Encode a value to MessagePack bytes for sending to WASM.\n *\n * @param value - The value to encode\n * @returns MessagePack-encoded bytes\n */\nexport function packToWasm(value: unknown): Uint8Array {\n return encode(value);\n}\n\n/**\n * Decode MessagePack bytes received from WASM.\n *\n * @typeParam T - The expected decoded type\n * @param bytes - MessagePack-encoded bytes from WASM\n * @returns The decoded value\n */\nexport function unpackFromWasm<T = unknown>(bytes: Uint8Array): T {\n return decode(bytes) as T;\n}\n\n/**\n * Encode a schema operations list for the `build_schema` entry point.\n *\n * @param ops - Array of builder operations\n * @returns MessagePack-encoded bytes\n */\nexport function packSchemaOps(ops: readonly SchemaOp[]): Uint8Array {\n return encode(ops);\n}\n\n/**\n * Encode a migration mapping for WASM entry points.\n *\n * @param mapping - The migration mapping object\n * @returns MessagePack-encoded bytes\n */\nexport function packMigrationMapping(mapping: MigrationMapping): Uint8Array {\n return encode(mapping);\n}\n\n// ---------------------------------------------------------------------------\n// Internal types for structured WASM messages\n// ---------------------------------------------------------------------------\n\n/**\n * A single schema builder operation sent to WASM.\n *\n * Uses serde internally-tagged format: the `op` field acts as the\n * discriminant and all variant fields sit at the same level.\n */\nexport interface SchemaOp {\n readonly op: 'vertex' | 'edge' | 'hyper_edge' | 'constraint' | 'required';\n readonly [key: string]: unknown;\n}\n\n/** Wire format for an edge (matches Rust serialization). */\nexport interface EdgeWire {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name: string | null;\n}\n\n/** A migration mapping sent to WASM (matches Rust `Migration` struct). */\nexport interface MigrationMapping {\n readonly vertex_map: Record<string, string>;\n readonly edge_map: Map<EdgeWire, EdgeWire>;\n readonly hyper_edge_map: Record<string, string>;\n readonly label_map: Map<readonly [string, string], string>;\n readonly resolver: Map<readonly [string, string], EdgeWire>;\n}\n","/**\n * Fluent schema builder API.\n *\n * Builders are immutable: each method returns a new builder instance.\n * Call `.build()` to validate and produce the final schema.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Vertex,\n Edge,\n HyperEdge,\n Constraint,\n VertexOptions,\n EdgeOptions,\n SchemaData,\n} from './types.js';\nimport { SchemaValidationError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport type { SchemaOp } from './msgpack.js';\nimport { packSchemaOps } from './msgpack.js';\n\n/**\n * Immutable fluent builder for constructing schemas.\n *\n * Each mutation method returns a new `SchemaBuilder` instance,\n * leaving the original unchanged. The builder accumulates operations\n * that are sent to WASM on `.build()`.\n *\n * @example\n * ```typescript\n * const schema = builder\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n * ```\n */\nexport class SchemaBuilder {\n readonly #protocolName: string;\n readonly #protocolHandle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #ops: readonly SchemaOp[];\n readonly #vertices: ReadonlyMap<string, Vertex>;\n readonly #edges: readonly Edge[];\n readonly #hyperEdges: ReadonlyMap<string, HyperEdge>;\n readonly #constraints: ReadonlyMap<string, readonly Constraint[]>;\n readonly #required: ReadonlyMap<string, readonly Edge[]>;\n\n constructor(\n protocolName: string,\n protocolHandle: WasmHandle,\n wasm: WasmModule,\n ops: readonly SchemaOp[] = [],\n vertices: ReadonlyMap<string, Vertex> = new Map(),\n edges: readonly Edge[] = [],\n hyperEdges: ReadonlyMap<string, HyperEdge> = new Map(),\n constraints: ReadonlyMap<string, readonly Constraint[]> = new Map(),\n required: ReadonlyMap<string, readonly Edge[]> = new Map(),\n ) {\n this.#protocolName = protocolName;\n this.#protocolHandle = protocolHandle;\n this.#wasm = wasm;\n this.#ops = ops;\n this.#vertices = vertices;\n this.#edges = edges;\n this.#hyperEdges = hyperEdges;\n this.#constraints = constraints;\n this.#required = required;\n }\n\n /**\n * Add a vertex to the schema.\n *\n * @param id - Unique vertex identifier\n * @param kind - Vertex kind (e.g., 'record', 'object', 'string')\n * @param options - Optional vertex configuration (nsid, etc.)\n * @returns A new builder with the vertex added\n * @throws {@link SchemaValidationError} if vertex id is already in use\n */\n vertex(id: string, kind: string, options?: VertexOptions): SchemaBuilder {\n if (this.#vertices.has(id)) {\n throw new SchemaValidationError(\n `Vertex \"${id}\" already exists in schema`,\n [`Duplicate vertex id: ${id}`],\n );\n }\n\n const vertex: Vertex = {\n id,\n kind,\n nsid: options?.nsid,\n };\n\n const op: SchemaOp = {\n op: 'vertex',\n id,\n kind,\n nsid: options?.nsid ?? null,\n };\n\n const newVertices = new Map(this.#vertices);\n newVertices.set(id, vertex);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n newVertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a directed edge to the schema.\n *\n * @param src - Source vertex id\n * @param tgt - Target vertex id\n * @param kind - Edge kind (e.g., 'record-schema', 'prop')\n * @param options - Optional edge configuration (name, etc.)\n * @returns A new builder with the edge added\n * @throws {@link SchemaValidationError} if source or target vertex does not exist\n */\n edge(src: string, tgt: string, kind: string, options?: EdgeOptions): SchemaBuilder {\n if (!this.#vertices.has(src)) {\n throw new SchemaValidationError(\n `Edge source \"${src}\" does not exist`,\n [`Unknown source vertex: ${src}`],\n );\n }\n if (!this.#vertices.has(tgt)) {\n throw new SchemaValidationError(\n `Edge target \"${tgt}\" does not exist`,\n [`Unknown target vertex: ${tgt}`],\n );\n }\n\n const edge: Edge = {\n src,\n tgt,\n kind,\n name: options?.name,\n };\n\n const op: SchemaOp = {\n op: 'edge',\n src,\n tgt,\n kind,\n name: options?.name ?? null,\n };\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n [...this.#edges, edge],\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a hyperedge to the schema.\n *\n * Only valid if the protocol's schema theory includes ThHypergraph.\n *\n * @param id - Unique hyperedge identifier\n * @param kind - Hyperedge kind\n * @param signature - Label-to-vertex mapping\n * @param parentLabel - The label identifying the parent in the signature\n * @returns A new builder with the hyperedge added\n */\n hyperEdge(\n id: string,\n kind: string,\n signature: Record<string, string>,\n parentLabel: string,\n ): SchemaBuilder {\n const he: HyperEdge = { id, kind, signature, parentLabel };\n\n const op: SchemaOp = {\n op: 'hyper_edge',\n id,\n kind,\n signature,\n parent: parentLabel,\n };\n\n const newHyperEdges = new Map(this.#hyperEdges);\n newHyperEdges.set(id, he);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n newHyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a constraint to a vertex.\n *\n * @param vertexId - The vertex to constrain\n * @param sort - Constraint sort (e.g., 'maxLength')\n * @param value - Constraint value\n * @returns A new builder with the constraint added\n */\n constraint(vertexId: string, sort: string, value: string): SchemaBuilder {\n const c: Constraint = { sort, value };\n\n const op: SchemaOp = {\n op: 'constraint',\n vertex: vertexId,\n sort,\n value,\n };\n\n const existing = this.#constraints.get(vertexId) ?? [];\n const newConstraints = new Map(this.#constraints);\n newConstraints.set(vertexId, [...existing, c]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n newConstraints,\n this.#required,\n );\n }\n\n /**\n * Mark edges as required for a vertex.\n *\n * @param vertexId - The vertex with required edges\n * @param edges - The edges that are required\n * @returns A new builder with the requirement added\n */\n required(vertexId: string, edges: readonly Edge[]): SchemaBuilder {\n const op: SchemaOp = {\n op: 'required',\n vertex: vertexId,\n edges: edges.map((e) => ({\n src: e.src,\n tgt: e.tgt,\n kind: e.kind,\n name: e.name ?? null,\n })),\n };\n\n const existing = this.#required.get(vertexId) ?? [];\n const newRequired = new Map(this.#required);\n newRequired.set(vertexId, [...existing, ...edges]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n newRequired,\n );\n }\n\n /**\n * Validate and build the schema.\n *\n * Sends all accumulated operations to WASM for validation and construction.\n * Returns a `BuiltSchema` that holds the WASM handle and local data.\n *\n * @returns The validated, built schema\n * @throws {@link SchemaValidationError} if the schema is invalid\n */\n build(): BuiltSchema {\n const opsBytes = packSchemaOps([...this.#ops]);\n const rawHandle = this.#wasm.exports.build_schema(\n this.#protocolHandle.id,\n opsBytes,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n\n const data: SchemaData = {\n protocol: this.#protocolName,\n vertices: Object.fromEntries(this.#vertices),\n edges: [...this.#edges],\n hyperEdges: Object.fromEntries(this.#hyperEdges),\n constraints: Object.fromEntries(\n Array.from(this.#constraints.entries()).map(([k, v]) => [k, [...v]]),\n ),\n required: Object.fromEntries(\n Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]]),\n ),\n };\n\n return new BuiltSchema(handle, data, this.#wasm);\n }\n}\n\n/**\n * A validated, built schema with a WASM-side handle.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class BuiltSchema implements Disposable {\n readonly #handle: WasmHandle;\n readonly #data: SchemaData;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, data: SchemaData, wasm: WasmModule) {\n this.#handle = handle;\n this.#data = data;\n this.#wasm = wasm;\n }\n\n /** The WASM handle for this schema. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The WASM module reference. Internal use only. */\n get _wasm(): WasmModule {\n return this.#wasm;\n }\n\n /** The schema data (vertices, edges, constraints, etc.). */\n get data(): SchemaData {\n return this.#data;\n }\n\n /** The protocol name this schema belongs to. */\n get protocol(): string {\n return this.#data.protocol;\n }\n\n /** All vertices in the schema. */\n get vertices(): Readonly<Record<string, Vertex>> {\n return this.#data.vertices;\n }\n\n /** All edges in the schema. */\n get edges(): readonly Edge[] {\n return this.#data.edges;\n }\n\n /** Release the WASM-side schema resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n","/**\n * Protocol definition helpers.\n *\n * A protocol specifies the schema theory and instance theory used by\n * a family of schemas (e.g., ATProto, SQL, Protobuf). This module\n * provides helpers for defining and looking up protocols.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, EdgeRule } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm } from './msgpack.js';\nimport { SchemaBuilder } from './schema.js';\n\n/**\n * A registered protocol with a WASM-side handle.\n *\n * Provides a fluent API for building schemas within this protocol.\n * Implements `Disposable` for automatic cleanup.\n */\nexport class Protocol implements Disposable {\n readonly #handle: WasmHandle;\n readonly #spec: ProtocolSpec;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, spec: ProtocolSpec, wasm: WasmModule) {\n this.#handle = handle;\n this.#spec = spec;\n this.#wasm = wasm;\n }\n\n /** The protocol name. */\n get name(): string {\n return this.#spec.name;\n }\n\n /** The full protocol specification. */\n get spec(): ProtocolSpec {\n return this.#spec;\n }\n\n /** The WASM handle. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /**\n * Start building a schema within this protocol.\n *\n * @returns A new `SchemaBuilder` bound to this protocol\n */\n schema(): SchemaBuilder {\n return new SchemaBuilder(this.#spec.name, this.#handle, this.#wasm);\n }\n\n /** Release the WASM-side protocol resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Define a protocol by sending its specification to WASM.\n *\n * @param spec - The protocol specification\n * @param wasm - The WASM module\n * @returns A registered protocol with a WASM handle\n * @throws {@link PanprotoError} if the WASM call fails\n */\nexport function defineProtocol(spec: ProtocolSpec, wasm: WasmModule): Protocol {\n const wireSpec = {\n name: spec.name,\n schema_theory: spec.schemaTheory,\n instance_theory: spec.instanceTheory,\n edge_rules: spec.edgeRules.map((r) => ({\n edge_kind: r.edgeKind,\n src_kinds: [...r.srcKinds],\n tgt_kinds: [...r.tgtKinds],\n })),\n obj_kinds: [...spec.objKinds],\n constraint_sorts: [...spec.constraintSorts],\n };\n\n try {\n const bytes = packToWasm(wireSpec);\n const rawHandle = wasm.exports.define_protocol(bytes);\n const handle = createHandle(rawHandle, wasm);\n return new Protocol(handle, spec, wasm);\n } catch (error) {\n throw new PanprotoError(\n `Failed to define protocol \"${spec.name}\": ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Built-in protocol specs\n// ---------------------------------------------------------------------------\n\n/**\n * Built-in ATProto protocol specification.\n *\n * Schema theory: colimit(ThGraph, ThConstraint, ThMulti).\n * Instance theory: ThWType + ThMeta.\n */\nexport const ATPROTO_SPEC: ProtocolSpec = {\n name: 'atproto',\n schemaTheory: 'ThATProtoSchema',\n instanceTheory: 'ThATProtoInstance',\n edgeRules: [\n { edgeKind: 'record-schema', srcKinds: ['record'], tgtKinds: ['object'] },\n { edgeKind: 'prop', srcKinds: ['object', 'query', 'procedure', 'subscription'], tgtKinds: [] },\n { edgeKind: 'items', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['union'], tgtKinds: [] },\n { edgeKind: 'ref', srcKinds: [], tgtKinds: [] },\n { edgeKind: 'self-ref', srcKinds: [], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: [\n 'record', 'object', 'array', 'union', 'string', 'integer', 'boolean',\n 'bytes', 'cid-link', 'blob', 'unknown', 'token', 'query', 'procedure',\n 'subscription', 'ref',\n ],\n constraintSorts: [\n 'minLength', 'maxLength', 'minimum', 'maximum', 'maxGraphemes',\n 'enum', 'const', 'default', 'closed',\n ],\n};\n\n/**\n * Built-in SQL protocol specification.\n *\n * Schema theory: colimit(ThHypergraph, ThConstraint).\n * Instance theory: ThFunctor.\n */\nexport const SQL_SPEC: ProtocolSpec = {\n name: 'sql',\n schemaTheory: 'ThConstrainedHypergraph',\n instanceTheory: 'ThFunctor',\n edgeRules: [\n { edgeKind: 'column', srcKinds: ['table'], tgtKinds: ['type'] },\n { edgeKind: 'fk', srcKinds: ['table'], tgtKinds: ['table'] },\n { edgeKind: 'pk', srcKinds: ['table'], tgtKinds: ['column'] },\n ] satisfies EdgeRule[],\n objKinds: ['table'],\n constraintSorts: ['nullable', 'unique', 'check', 'default'],\n};\n\n/**\n * Built-in Protobuf protocol specification.\n */\nexport const PROTOBUF_SPEC: ProtocolSpec = {\n name: 'protobuf',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['message'], tgtKinds: [] },\n { edgeKind: 'nested', srcKinds: ['message'], tgtKinds: ['message', 'enum'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['message'],\n constraintSorts: ['field-number', 'repeated', 'optional', 'map-key', 'map-value'],\n};\n\n/**\n * Built-in GraphQL protocol specification.\n */\nexport const GRAPHQL_SPEC: ProtocolSpec = {\n name: 'graphql',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['type', 'input'], tgtKinds: [] },\n { edgeKind: 'implements', srcKinds: ['type'], tgtKinds: ['interface'] },\n { edgeKind: 'member', srcKinds: ['union'], tgtKinds: ['type'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['type', 'input'],\n constraintSorts: ['non-null', 'list', 'deprecated'],\n};\n\n/**\n * Built-in JSON Schema protocol specification.\n */\nexport const JSON_SCHEMA_SPEC: ProtocolSpec = {\n name: 'json-schema',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'property', srcKinds: ['object'], tgtKinds: [] },\n { edgeKind: 'item', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['oneOf', 'anyOf'], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: ['object'],\n constraintSorts: ['minLength', 'maxLength', 'minimum', 'maximum', 'pattern', 'format', 'required'],\n};\n\n/** Registry of built-in protocol specs, keyed by name. */\nexport const BUILTIN_PROTOCOLS: ReadonlyMap<string, ProtocolSpec> = new Map([\n ['atproto', ATPROTO_SPEC],\n ['sql', SQL_SPEC],\n ['protobuf', PROTOBUF_SPEC],\n ['graphql', GRAPHQL_SPEC],\n ['json-schema', JSON_SCHEMA_SPEC],\n]);\n","/**\n * Migration builder and compiled migration wrapper.\n *\n * Migrations define a mapping between two schemas. Once compiled,\n * they can efficiently transform records via WASM.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Edge,\n LiftResult,\n GetResult,\n ExistenceReport,\n MigrationSpec,\n} from './types.js';\nimport { MigrationError, WasmError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm, unpackFromWasm, packMigrationMapping } from './msgpack.js';\nimport type { BuiltSchema } from './schema.js';\n\n/**\n * Fluent builder for constructing migrations between two schemas.\n *\n * Each mutation method returns a new `MigrationBuilder` instance,\n * leaving the original unchanged.\n *\n * @example\n * ```typescript\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .map('post:body', 'post:body')\n * .mapEdge(oldEdge, newEdge)\n * .compile();\n * ```\n */\nexport class MigrationBuilder {\n readonly #src: BuiltSchema;\n readonly #tgt: BuiltSchema;\n readonly #wasm: WasmModule;\n readonly #vertexMap: ReadonlyMap<string, string>;\n readonly #edgeMap: readonly [Edge, Edge][];\n readonly #resolvers: readonly [[string, string], Edge][];\n\n constructor(\n src: BuiltSchema,\n tgt: BuiltSchema,\n wasm: WasmModule,\n vertexMap: ReadonlyMap<string, string> = new Map(),\n edgeMap: readonly [Edge, Edge][] = [],\n resolvers: readonly [[string, string], Edge][] = [],\n ) {\n this.#src = src;\n this.#tgt = tgt;\n this.#wasm = wasm;\n this.#vertexMap = vertexMap;\n this.#edgeMap = edgeMap;\n this.#resolvers = resolvers;\n }\n\n /**\n * Map a source vertex to a target vertex.\n *\n * @param srcVertex - Vertex id in the source schema\n * @param tgtVertex - Vertex id in the target schema\n * @returns A new builder with the mapping added\n */\n map(srcVertex: string, tgtVertex: string): MigrationBuilder {\n const newMap = new Map(this.#vertexMap);\n newMap.set(srcVertex, tgtVertex);\n\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n newMap,\n this.#edgeMap,\n this.#resolvers,\n );\n }\n\n /**\n * Map a source edge to a target edge.\n *\n * @param srcEdge - Edge in the source schema\n * @param tgtEdge - Edge in the target schema\n * @returns A new builder with the edge mapping added\n */\n mapEdge(srcEdge: Edge, tgtEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n [...this.#edgeMap, [srcEdge, tgtEdge]],\n this.#resolvers,\n );\n }\n\n /**\n * Add a resolver for ancestor contraction ambiguity.\n *\n * When a migration contracts nodes and the resulting edge between\n * two vertex kinds is ambiguous, a resolver specifies which edge to use.\n *\n * @param srcKind - Source vertex kind in the contracted pair\n * @param tgtKind - Target vertex kind in the contracted pair\n * @param resolvedEdge - The edge to use for this pair\n * @returns A new builder with the resolver added\n */\n resolve(srcKind: string, tgtKind: string, resolvedEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n this.#edgeMap,\n [...this.#resolvers, [[srcKind, tgtKind], resolvedEdge]],\n );\n }\n\n /**\n * Get the current migration specification.\n *\n * @returns The migration spec with all accumulated mappings\n */\n toSpec(): MigrationSpec {\n return {\n vertexMap: Object.fromEntries(this.#vertexMap),\n edgeMap: [...this.#edgeMap],\n resolvers: [...this.#resolvers],\n };\n }\n\n /**\n * Compile the migration for fast per-record application.\n *\n * Sends the migration specification to WASM for compilation.\n * The resulting `CompiledMigration` can be used to transform records.\n *\n * @returns A compiled migration ready for record transformation\n * @throws {@link MigrationError} if compilation fails\n */\n compile(): CompiledMigration {\n const edgeMap = new Map(\n this.#edgeMap.map(([src, tgt]) => [\n { src: src.src, tgt: src.tgt, kind: src.kind, name: src.name ?? null },\n { src: tgt.src, tgt: tgt.tgt, kind: tgt.kind, name: tgt.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n this.#resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: Object.fromEntries(this.#vertexMap),\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n try {\n const rawHandle = this.#wasm.exports.compile_migration(\n this.#src._handle.id,\n this.#tgt._handle.id,\n mapping,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n return new CompiledMigration(handle, this.#wasm, this.toSpec());\n } catch (error) {\n throw new MigrationError(\n `Failed to compile migration: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n}\n\n/**\n * A compiled migration that can efficiently transform records via WASM.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class CompiledMigration implements Disposable {\n readonly #handle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #spec: MigrationSpec;\n\n constructor(handle: WasmHandle, wasm: WasmModule, spec: MigrationSpec) {\n this.#handle = handle;\n this.#wasm = wasm;\n this.#spec = spec;\n }\n\n /** The WASM handle for this migration. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The migration specification used to build this migration. */\n get spec(): MigrationSpec {\n return this.#spec;\n }\n\n /**\n * Transform a record using this migration (forward direction).\n *\n * This is the hot path: data goes through WASM as MessagePack bytes\n * with no intermediate JS-heap allocation.\n *\n * @param record - The input record to transform\n * @returns The transformed record\n * @throws {@link WasmError} if the WASM call fails\n */\n lift(record: unknown): LiftResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.lift_record(\n this.#handle.id,\n inputBytes,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `lift_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional get: extract view and complement from a record.\n *\n * The complement captures data discarded by the forward projection,\n * enabling lossless round-tripping via `put()`.\n *\n * @param record - The input record\n * @returns The projected view and opaque complement bytes\n * @throws {@link WasmError} if the WASM call fails\n */\n get(record: unknown): GetResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.get_record(\n this.#handle.id,\n inputBytes,\n );\n const result = unpackFromWasm<{ view: unknown; complement: Uint8Array }>(outputBytes);\n return {\n view: result.view,\n complement: result.complement instanceof Uint8Array\n ? result.complement\n : new Uint8Array(result.complement as ArrayBuffer),\n };\n } catch (error) {\n throw new WasmError(\n `get_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional put: restore a full record from a modified view and complement.\n *\n * @param view - The (possibly modified) projected view\n * @param complement - The complement from a prior `get()` call\n * @returns The restored full record\n * @throws {@link WasmError} if the WASM call fails\n */\n put(view: unknown, complement: Uint8Array): LiftResult {\n const viewBytes = packToWasm(view);\n\n try {\n const outputBytes = this.#wasm.exports.put_record(\n this.#handle.id,\n viewBytes,\n complement,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `put_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /** Release the WASM-side compiled migration resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Check existence conditions for a migration between two schemas.\n *\n * @param src - Source schema handle\n * @param tgt - Target schema handle\n * @param spec - The migration specification\n * @param wasm - The WASM module\n * @returns The existence report\n */\nexport function checkExistence(\n protoHandle: number,\n src: BuiltSchema,\n tgt: BuiltSchema,\n spec: MigrationSpec,\n wasm: WasmModule,\n): ExistenceReport {\n const edgeMap = new Map(\n spec.edgeMap.map(([s, t]) => [\n { src: s.src, tgt: s.tgt, kind: s.kind, name: s.name ?? null },\n { src: t.src, tgt: t.tgt, kind: t.kind, name: t.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n spec.resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: spec.vertexMap,\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n const resultBytes = wasm.exports.check_existence(\n protoHandle,\n src._handle.id,\n tgt._handle.id,\n mapping,\n );\n\n return unpackFromWasm<ExistenceReport>(resultBytes);\n}\n\n/**\n * Compose two compiled migrations into a single migration.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @param wasm - The WASM module\n * @returns A new compiled migration representing m2 . m1\n * @throws {@link MigrationError} if composition fails\n */\nexport function composeMigrations(\n m1: CompiledMigration,\n m2: CompiledMigration,\n wasm: WasmModule,\n): CompiledMigration {\n try {\n const rawHandle = wasm.exports.compose_migrations(\n m1._handle.id,\n m2._handle.id,\n );\n const handle = createHandle(rawHandle, wasm);\n\n // Compose vertex maps: if m1 maps A->B and m2 maps B->C, composed maps A->C.\n // Vertices in m1 whose target is not remapped by m2 pass through unchanged.\n const composedVertexMap: Record<string, string> = {};\n for (const [src, intermediate] of Object.entries(m1.spec.vertexMap)) {\n const final_ = m2.spec.vertexMap[intermediate];\n composedVertexMap[src] = final_ ?? intermediate;\n }\n\n // Concatenate edge maps and resolvers from both migrations. The WASM side\n // performs the actual composition; this spec is a best-effort reconstruction\n // for introspection purposes.\n const composedSpec: MigrationSpec = {\n vertexMap: composedVertexMap,\n edgeMap: [...m1.spec.edgeMap, ...m2.spec.edgeMap],\n resolvers: [...m1.spec.resolvers, ...m2.spec.resolvers],\n };\n\n return new CompiledMigration(handle, wasm, composedSpec);\n } catch (error) {\n throw new MigrationError(\n `Failed to compose migrations: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n","/**\n * Main Panproto class — the primary entry point for the SDK.\n *\n * Wraps the WASM module and provides the high-level API for working\n * with protocols, schemas, migrations, and diffs.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, DiffReport } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { loadWasm, type WasmGlueModule } from './wasm.js';\nimport {\n Protocol,\n defineProtocol,\n BUILTIN_PROTOCOLS,\n} from './protocol.js';\nimport type { BuiltSchema } from './schema.js';\nimport {\n MigrationBuilder,\n CompiledMigration,\n checkExistence,\n composeMigrations,\n} from './migration.js';\nimport { unpackFromWasm } from './msgpack.js';\n\n/**\n * The main entry point for the panproto SDK.\n *\n * Create an instance with {@link Panproto.init}, then use it to define\n * protocols, build schemas, compile migrations, and diff schemas.\n *\n * Implements `Disposable` so it can be used with `using` to automatically\n * clean up all WASM resources.\n *\n * @example\n * ```typescript\n * const panproto = await Panproto.init();\n * const atproto = panproto.protocol('atproto');\n *\n * const schema = atproto.schema()\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n *\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .compile();\n *\n * const result = migration.lift(inputRecord);\n * ```\n */\nexport class Panproto implements Disposable {\n readonly #wasm: WasmModule;\n readonly #protocols: Map<string, Protocol>;\n\n private constructor(wasm: WasmModule) {\n this.#wasm = wasm;\n this.#protocols = new Map();\n }\n\n /**\n * Initialize the panproto SDK by loading the WASM module.\n *\n * @param input - URL to the wasm-bindgen glue module, or a pre-imported\n * glue module object (for bundler environments like Vite).\n * Defaults to the bundled glue module.\n * @returns An initialized Panproto instance\n * @throws {@link import('./types.js').WasmError} if WASM loading fails\n */\n static async init(input?: string | URL | WasmGlueModule): Promise<Panproto> {\n const wasm = await loadWasm(input);\n return new Panproto(wasm);\n }\n\n /**\n * Get or register a protocol by name.\n *\n * If the protocol is a built-in (e.g., 'atproto', 'sql'), it is\n * automatically registered on first access. Custom protocols must\n * be registered first with {@link Panproto.defineProtocol}.\n *\n * @param name - The protocol name\n * @returns The protocol instance\n * @throws {@link PanprotoError} if the protocol is not found\n */\n protocol(name: string): Protocol {\n const cached = this.#protocols.get(name);\n if (cached) return cached;\n\n // Try built-in protocols\n const builtinSpec = BUILTIN_PROTOCOLS.get(name);\n if (builtinSpec) {\n const proto = defineProtocol(builtinSpec, this.#wasm);\n this.#protocols.set(name, proto);\n return proto;\n }\n\n throw new PanprotoError(\n `Protocol \"${name}\" not found. Register it with defineProtocol() first.`,\n );\n }\n\n /**\n * Define and register a custom protocol.\n *\n * @param spec - The protocol specification\n * @returns The registered protocol\n * @throws {@link PanprotoError} if registration fails\n */\n defineProtocol(spec: ProtocolSpec): Protocol {\n const proto = defineProtocol(spec, this.#wasm);\n this.#protocols.set(spec.name, proto);\n return proto;\n }\n\n /**\n * Start building a migration between two schemas.\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @returns A migration builder\n */\n migration(src: BuiltSchema, tgt: BuiltSchema): MigrationBuilder {\n return new MigrationBuilder(src, tgt, this.#wasm);\n }\n\n /**\n * Check existence conditions for a proposed migration.\n *\n * Verifies that the migration specification satisfies all\n * protocol-derived constraints (edge coverage, kind consistency,\n * required fields, etc.).\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @param builder - The migration builder with mappings\n * @returns The existence report\n */\n checkExistence(\n src: BuiltSchema,\n tgt: BuiltSchema,\n builder: MigrationBuilder,\n ): import('./types.js').ExistenceReport {\n const proto = this.#protocols.get(src.protocol);\n if (!proto) {\n throw new PanprotoError(\n `Protocol \"${src.protocol}\" not registered. Call protocol() first.`,\n );\n }\n return checkExistence(proto._handle.id, src, tgt, builder.toSpec(), this.#wasm);\n }\n\n /**\n * Compose two compiled migrations into a single migration.\n *\n * The resulting migration is equivalent to applying `m1` then `m2`.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @returns The composed migration\n * @throws {@link import('./types.js').MigrationError} if composition fails\n */\n compose(m1: CompiledMigration, m2: CompiledMigration): CompiledMigration {\n return composeMigrations(m1, m2, this.#wasm);\n }\n\n /**\n * Diff two schemas and produce a compatibility report.\n *\n * @param oldSchema - The old/source schema\n * @param newSchema - The new/target schema\n * @returns A diff report with changes and compatibility classification\n */\n diff(oldSchema: BuiltSchema, newSchema: BuiltSchema): DiffReport {\n const resultBytes = this.#wasm.exports.diff_schemas(\n oldSchema._handle.id,\n newSchema._handle.id,\n );\n return unpackFromWasm<DiffReport>(resultBytes);\n }\n\n /**\n * Release all WASM resources held by this instance.\n *\n * Disposes all cached protocols. After disposal, this instance\n * must not be used.\n */\n [Symbol.dispose](): void {\n for (const proto of this.#protocols.values()) {\n proto[Symbol.dispose]();\n }\n this.#protocols.clear();\n }\n}\n","/**\n * Lens and combinator API for bidirectional transformations.\n *\n * Every migration is a lens with `get` (forward projection) and\n * `put` (restore from complement). This module provides Cambria-style\n * combinators that compose into migrations.\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Combinator types\n// ---------------------------------------------------------------------------\n\n/** Rename a field from one name to another. */\nexport interface RenameFieldCombinator {\n readonly type: 'rename-field';\n readonly old: string;\n readonly new: string;\n}\n\n/** Add a new field with a default value. */\nexport interface AddFieldCombinator {\n readonly type: 'add-field';\n readonly name: string;\n readonly vertexKind: string;\n readonly default: unknown;\n}\n\n/** Remove a field from the schema. */\nexport interface RemoveFieldCombinator {\n readonly type: 'remove-field';\n readonly name: string;\n}\n\n/** Wrap a value inside a new object with a given field name. */\nexport interface WrapInObjectCombinator {\n readonly type: 'wrap-in-object';\n readonly fieldName: string;\n}\n\n/** Hoist a nested field up to the host level. */\nexport interface HoistFieldCombinator {\n readonly type: 'hoist-field';\n readonly host: string;\n readonly field: string;\n}\n\n/** Coerce a value from one type to another. */\nexport interface CoerceTypeCombinator {\n readonly type: 'coerce-type';\n readonly fromKind: string;\n readonly toKind: string;\n}\n\n/** Sequential composition of two combinators. */\nexport interface ComposeCombinator {\n readonly type: 'compose';\n readonly first: Combinator;\n readonly second: Combinator;\n}\n\n/** A lens combinator (Cambria-style). */\nexport type Combinator =\n | RenameFieldCombinator\n | AddFieldCombinator\n | RemoveFieldCombinator\n | WrapInObjectCombinator\n | HoistFieldCombinator\n | CoerceTypeCombinator\n | ComposeCombinator;\n\n// ---------------------------------------------------------------------------\n// Combinator constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Create a rename-field combinator.\n *\n * @param oldName - The current field name\n * @param newName - The desired field name\n * @returns A rename-field combinator\n */\nexport function renameField(oldName: string, newName: string): RenameFieldCombinator {\n return { type: 'rename-field', old: oldName, new: newName };\n}\n\n/**\n * Create an add-field combinator.\n *\n * @param name - The field name to add\n * @param vertexKind - The vertex kind for the new field\n * @param defaultValue - The default value for the field\n * @returns An add-field combinator\n */\nexport function addField(name: string, vertexKind: string, defaultValue: unknown): AddFieldCombinator {\n return { type: 'add-field', name, vertexKind, default: defaultValue };\n}\n\n/**\n * Create a remove-field combinator.\n *\n * @param name - The field name to remove\n * @returns A remove-field combinator\n */\nexport function removeField(name: string): RemoveFieldCombinator {\n return { type: 'remove-field', name };\n}\n\n/**\n * Create a wrap-in-object combinator.\n *\n * @param fieldName - The field name for the wrapper object\n * @returns A wrap-in-object combinator\n */\nexport function wrapInObject(fieldName: string): WrapInObjectCombinator {\n return { type: 'wrap-in-object', fieldName };\n}\n\n/**\n * Create a hoist-field combinator.\n *\n * @param host - The host vertex to hoist into\n * @param field - The nested field to hoist\n * @returns A hoist-field combinator\n */\nexport function hoistField(host: string, field: string): HoistFieldCombinator {\n return { type: 'hoist-field', host, field };\n}\n\n/**\n * Create a coerce-type combinator.\n *\n * @param fromKind - The source type kind\n * @param toKind - The target type kind\n * @returns A coerce-type combinator\n */\nexport function coerceType(fromKind: string, toKind: string): CoerceTypeCombinator {\n return { type: 'coerce-type', fromKind, toKind };\n}\n\n/**\n * Compose two combinators sequentially.\n *\n * @param first - The combinator applied first\n * @param second - The combinator applied second\n * @returns A composed combinator\n */\nexport function compose(first: Combinator, second: Combinator): ComposeCombinator {\n return { type: 'compose', first, second };\n}\n\n/**\n * Compose a chain of combinators left-to-right.\n *\n * @param combinators - The combinators to compose (at least one required)\n * @returns The composed combinator\n * @throws If the combinators array is empty\n */\nexport function pipeline(combinators: readonly [Combinator, ...Combinator[]]): Combinator {\n const [first, ...rest] = combinators;\n return rest.reduce<Combinator>((acc, c) => compose(acc, c), first);\n}\n\n/**\n * Serialize a combinator to a plain object for MessagePack encoding.\n *\n * @param combinator - The combinator to serialize\n * @returns A plain object suitable for MessagePack encoding\n */\nexport function combinatorToWire(combinator: Combinator): Record<string, unknown> {\n switch (combinator.type) {\n case 'rename-field':\n return { RenameField: { old: combinator.old, new: combinator.new } };\n case 'add-field':\n return { AddField: { name: combinator.name, vertex_kind: combinator.vertexKind, default: combinator.default } };\n case 'remove-field':\n return { RemoveField: { name: combinator.name } };\n case 'wrap-in-object':\n return { WrapInObject: { field_name: combinator.fieldName } };\n case 'hoist-field':\n return { HoistField: { host: combinator.host, field: combinator.field } };\n case 'coerce-type':\n return { CoerceType: { from_kind: combinator.fromKind, to_kind: combinator.toKind } };\n case 'compose':\n return { Compose: [combinatorToWire(combinator.first), combinatorToWire(combinator.second)] };\n }\n}\n"],"names":["exports"],"mappings":";AAmNO,MAAM,sBAAsB,MAAM;AAAA,EACrB,OAAe;AAAA,EAEjC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF;AAGO,MAAM,kBAAkB,cAAc;AAAA,EACzB,OAAO;AAC3B;AAGO,MAAM,8BAA8B,cAAc;AAAA,EAGvD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AAGO,MAAM,uBAAuB,cAAc;AAAA,EAC9B,OAAO;AAC3B;AAGO,MAAM,4BAA4B,cAAc;AAAA,EAGrD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AC7OA,MAAM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M,gBAAgB,KAAA;AACjC;AAQO,SAAS,aAAa,WAA2C;AACtE,SAAO,EAAE,MAAM,kBAAkB,UAAA;AACnC;AASO,SAAS,WAAW,MAAc,OAAqC;AAC5E,SAAO,EAAE,MAAM,eAAe,MAAM,MAAA;AACtC;AASO,SAAS,WAAW,UAAkB,QAAsC;AACjF,SAAO,EAAE,MAAM,eAAe,UAAU,OAAA;AAC1C;AASO,SAAS,QAAQ,OAAmB,QAAuC;AAChF,SAAO,EAAE,MAAM,WAAW,OAAO,OAAA;AACnC;AASO,SAAS,SAAS,aAAiE;AACxF,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,SAAO,KAAK,OAAmB,CAAC,KAAK,MAAM,QAAQ,KAAK,CAAC,GAAG,KAAK;AACnE;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/types.ts","../src/wasm.ts","../src/msgpack.ts","../src/schema.ts","../src/protocol.ts","../src/migration.ts","../src/panproto.ts","../src/lens.ts"],"sourcesContent":["/**\n * Core type definitions for the @panproto/core SDK.\n *\n * These types mirror the Rust-side structures but use JavaScript idioms:\n * - `HashMap<K,V>` becomes `Map<K,V>` or `Record<string, V>` for string keys\n * - `Option<T>` becomes `T | undefined`\n * - `Vec<T>` becomes `T[]`\n * - `Result<T,E>` becomes thrown `PanprotoError` or return value\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Handle types (opaque wrappers — never expose raw u32)\n// ---------------------------------------------------------------------------\n\n/** Opaque handle to a WASM-side resource. */\nexport interface Handle {\n readonly __brand: unique symbol;\n readonly id: number;\n}\n\n/** Branded handle for a protocol resource. */\nexport interface ProtocolHandle extends Handle {\n readonly __kind: 'protocol';\n}\n\n/** Branded handle for a schema resource. */\nexport interface SchemaHandle extends Handle {\n readonly __kind: 'schema';\n}\n\n/** Branded handle for a compiled migration resource. */\nexport interface MigrationHandle extends Handle {\n readonly __kind: 'migration';\n}\n\n// ---------------------------------------------------------------------------\n// Protocol\n// ---------------------------------------------------------------------------\n\n/** Rule constraining which vertex kinds an edge can connect. */\nexport interface EdgeRule {\n readonly edgeKind: string;\n /** Allowed source vertex kinds. Empty array means any. */\n readonly srcKinds: readonly string[];\n /** Allowed target vertex kinds. Empty array means any. */\n readonly tgtKinds: readonly string[];\n}\n\n/** A protocol specification defining schema/instance theories and validation rules. */\nexport interface ProtocolSpec {\n readonly name: string;\n readonly schemaTheory: string;\n readonly instanceTheory: string;\n readonly edgeRules: readonly EdgeRule[];\n readonly objKinds: readonly string[];\n readonly constraintSorts: readonly string[];\n}\n\n// ---------------------------------------------------------------------------\n// Schema\n// ---------------------------------------------------------------------------\n\n/** Options for vertex creation. */\nexport interface VertexOptions {\n readonly nsid?: string;\n}\n\n/** A vertex in a schema graph. */\nexport interface Vertex {\n readonly id: string;\n readonly kind: string;\n readonly nsid?: string | undefined;\n}\n\n/** A directed edge in a schema graph. */\nexport interface Edge {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name?: string | undefined;\n}\n\n/** A hyperedge with a labeled signature. */\nexport interface HyperEdge {\n readonly id: string;\n readonly kind: string;\n readonly signature: Readonly<Record<string, string>>;\n readonly parentLabel: string;\n}\n\n/** A constraint on a vertex (sort + value). */\nexport interface Constraint {\n readonly sort: string;\n readonly value: string;\n}\n\n/** A variant in a schema graph (union member). */\nexport interface Variant {\n readonly id: string;\n readonly parent_vertex: string;\n readonly tag?: string | undefined;\n}\n\n/** A recursion point (mu-binding site). */\nexport interface RecursionPoint {\n readonly mu_id: string;\n readonly target_vertex: string;\n}\n\n/** Usage mode for a vertex (structural, linear, or affine). */\nexport type UsageMode = 'structural' | 'linear' | 'affine';\n\n/** A span between two vertices. */\nexport interface Span {\n readonly id: string;\n readonly left: string;\n readonly right: string;\n}\n\n/** Options for edge creation. */\nexport interface EdgeOptions {\n readonly name?: string;\n}\n\n/** Serializable schema representation. */\nexport interface SchemaData {\n readonly protocol: string;\n readonly vertices: Readonly<Record<string, Vertex>>;\n readonly edges: readonly Edge[];\n readonly hyperEdges: Readonly<Record<string, HyperEdge>>;\n readonly constraints: Readonly<Record<string, readonly Constraint[]>>;\n readonly required: Readonly<Record<string, readonly Edge[]>>;\n readonly variants: Readonly<Record<string, readonly Variant[]>>;\n readonly orderings: Readonly<Record<string, number>>;\n readonly recursionPoints: Readonly<Record<string, RecursionPoint>>;\n readonly usageModes: Readonly<Record<string, UsageMode>>;\n readonly spans: Readonly<Record<string, Span>>;\n readonly nominal: Readonly<Record<string, boolean>>;\n}\n\n// ---------------------------------------------------------------------------\n// Migration\n// ---------------------------------------------------------------------------\n\n/** A vertex mapping entry for migration building. */\nexport interface VertexMapping {\n readonly src: string;\n readonly tgt: string;\n}\n\n/** A migration specification (maps between two schemas). */\nexport interface MigrationSpec {\n readonly vertexMap: Readonly<Record<string, string>>;\n readonly edgeMap: readonly [Edge, Edge][];\n readonly resolvers: readonly [[string, string], Edge][];\n}\n\n/** Result of applying a compiled migration to a record. */\nexport interface LiftResult {\n readonly data: unknown;\n}\n\n/** Get result for bidirectional lens operation. */\nexport interface GetResult {\n readonly view: unknown;\n readonly complement: Uint8Array;\n}\n\n// ---------------------------------------------------------------------------\n// Diff / Compatibility\n// ---------------------------------------------------------------------------\n\n/** A single change detected between two schemas. */\nexport interface SchemaChange {\n readonly kind: 'vertex-added' | 'vertex-removed' | 'edge-added' | 'edge-removed'\n | 'constraint-added' | 'constraint-removed' | 'constraint-changed'\n | 'kind-changed' | 'required-added' | 'required-removed';\n readonly path: string;\n readonly detail?: string | undefined;\n}\n\n/** Compatibility classification. */\nexport type Compatibility = 'fully-compatible' | 'backward-compatible' | 'breaking';\n\n/** Schema diff report. */\nexport interface DiffReport {\n readonly compatibility: Compatibility;\n readonly changes: readonly SchemaChange[];\n}\n\n// ---------------------------------------------------------------------------\n// Existence checking\n// ---------------------------------------------------------------------------\n\n/** A structured existence error. */\nexport interface ExistenceError {\n readonly kind: 'edge-missing' | 'kind-inconsistency' | 'label-inconsistency'\n | 'required-field-missing' | 'constraint-tightened' | 'resolver-invalid'\n | 'well-formedness' | 'signature-coherence' | 'simultaneity' | 'reachability-risk';\n readonly message: string;\n readonly detail?: Record<string, unknown> | undefined;\n}\n\n/** Result of existence checking. */\nexport interface ExistenceReport {\n readonly valid: boolean;\n readonly errors: readonly ExistenceError[];\n}\n\n// ---------------------------------------------------------------------------\n// WASM module interface\n// ---------------------------------------------------------------------------\n\n/** The raw WASM module interface (10 entry points). */\nexport interface WasmExports {\n define_protocol(spec: Uint8Array): number;\n build_schema(proto: number, ops: Uint8Array): number;\n check_existence(proto: number, src: number, tgt: number, mapping: Uint8Array): Uint8Array;\n compile_migration(src: number, tgt: number, mapping: Uint8Array): number;\n lift_record(migration: number, record: Uint8Array): Uint8Array;\n get_record(migration: number, record: Uint8Array): Uint8Array;\n put_record(migration: number, view: Uint8Array, complement: Uint8Array): Uint8Array;\n compose_migrations(m1: number, m2: number): number;\n diff_schemas(s1: number, s2: number): Uint8Array;\n free_handle(handle: number): void;\n}\n\n/** WASM module wrapper including exports and memory. */\nexport interface WasmModule {\n readonly exports: WasmExports;\n readonly memory: WebAssembly.Memory;\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/** Base error class for all panproto errors. */\nexport class PanprotoError extends Error {\n override readonly name: string = 'PanprotoError';\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/** Error from WASM boundary. */\nexport class WasmError extends PanprotoError {\n override readonly name = 'WasmError';\n}\n\n/** Error from schema validation. */\nexport class SchemaValidationError extends PanprotoError {\n override readonly name = 'SchemaValidationError';\n\n constructor(\n message: string,\n readonly errors: readonly string[],\n ) {\n super(message);\n }\n}\n\n/** Error from migration compilation. */\nexport class MigrationError extends PanprotoError {\n override readonly name = 'MigrationError';\n}\n\n/** Error from existence checking. */\nexport class ExistenceCheckError extends PanprotoError {\n override readonly name = 'ExistenceCheckError';\n\n constructor(\n message: string,\n readonly report: ExistenceReport,\n ) {\n super(message);\n }\n}\n","/**\n * WASM loading and handle management.\n *\n * Manages the lifecycle of WASM-side resources via opaque handles.\n * Uses `Symbol.dispose` for automatic cleanup and `FinalizationRegistry`\n * as a safety net for leaked handles.\n *\n * @module\n */\n\nimport type { WasmModule, WasmExports } from './types.js';\nimport { WasmError } from './types.js';\n\n/** Default wasm-bindgen glue module URL (relative to package root). */\nconst DEFAULT_GLUE_URL = new URL('./panproto_wasm.js', import.meta.url);\n\n/**\n * Shape of a pre-imported wasm-bindgen glue module.\n *\n * The `default` export is the wasm-bindgen init function. We type it\n * loosely so any wasm-bindgen output module satisfies the interface.\n */\nexport interface WasmGlueModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n default: (...args: any[]) => Promise<{ memory: WebAssembly.Memory }>;\n define_protocol: WasmExports['define_protocol'];\n build_schema: WasmExports['build_schema'];\n check_existence: WasmExports['check_existence'];\n compile_migration: WasmExports['compile_migration'];\n lift_record: WasmExports['lift_record'];\n get_record: WasmExports['get_record'];\n put_record: WasmExports['put_record'];\n compose_migrations: WasmExports['compose_migrations'];\n diff_schemas: WasmExports['diff_schemas'];\n free_handle: WasmExports['free_handle'];\n}\n\n/**\n * Load the panproto WASM module.\n *\n * Accepts either:\n * - A URL to the wasm-bindgen `.js` glue module (loaded via dynamic import)\n * - A pre-imported wasm-bindgen glue module object (for bundler environments like Vite)\n *\n * @param input - URL string, URL object, or pre-imported glue module.\n * Defaults to the bundled glue module URL.\n * @returns The initialized WASM module\n * @throws {@link WasmError} if loading or instantiation fails\n */\nexport async function loadWasm(input?: string | URL | WasmGlueModule): Promise<WasmModule> {\n try {\n let glue: WasmGlueModule;\n\n if (input && typeof input === 'object' && 'default' in input && typeof input.default === 'function') {\n // Pre-imported glue module — used in bundler environments (Vite, webpack)\n glue = input;\n } else {\n // Dynamic import from URL\n const url = (input as string | URL | undefined) ?? DEFAULT_GLUE_URL;\n glue = await import(/* @vite-ignore */ String(url));\n }\n\n const initOutput = await glue.default();\n\n const exports: WasmExports = {\n define_protocol: glue.define_protocol,\n build_schema: glue.build_schema,\n check_existence: glue.check_existence,\n compile_migration: glue.compile_migration,\n lift_record: glue.lift_record,\n get_record: glue.get_record,\n put_record: glue.put_record,\n compose_migrations: glue.compose_migrations,\n diff_schemas: glue.diff_schemas,\n free_handle: glue.free_handle,\n };\n\n const memory: WebAssembly.Memory = initOutput.memory;\n\n if (!memory) {\n throw new WasmError('WASM module missing memory export');\n }\n\n return { exports, memory };\n } catch (error) {\n if (error instanceof WasmError) throw error;\n throw new WasmError(\n `Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Handle registry — prevents resource leaks\n// ---------------------------------------------------------------------------\n\n/** Weak reference registry for leaked handle detection. */\nconst leakedHandleRegistry = new FinalizationRegistry<CleanupInfo>((info) => {\n // Safety net: if a disposable wrapper is GC'd without being disposed,\n // free the underlying WASM handle.\n try {\n info.freeHandle(info.handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n});\n\ninterface CleanupInfo {\n readonly handle: number;\n readonly freeHandle: (h: number) => void;\n}\n\n/**\n * A disposable wrapper around a WASM handle.\n *\n * Implements `Symbol.dispose` for use with `using` declarations.\n * A `FinalizationRegistry` acts as a safety net for handles that\n * are not explicitly disposed.\n */\nexport class WasmHandle implements Disposable {\n #handle: number;\n #disposed = false;\n readonly #freeHandle: (h: number) => void;\n\n constructor(handle: number, freeHandle: (h: number) => void) {\n this.#handle = handle;\n this.#freeHandle = freeHandle;\n\n leakedHandleRegistry.register(this, { handle, freeHandle }, this);\n }\n\n /** The raw WASM handle id. Only for internal use within the SDK. */\n get id(): number {\n if (this.#disposed) {\n throw new WasmError('Attempted to use a disposed handle');\n }\n return this.#handle;\n }\n\n /** Whether this handle has been disposed. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /** Release the underlying WASM resource. */\n [Symbol.dispose](): void {\n if (this.#disposed) return;\n this.#disposed = true;\n\n leakedHandleRegistry.unregister(this);\n\n try {\n this.#freeHandle(this.#handle);\n } catch {\n // WASM module may already be torn down; swallow.\n }\n }\n}\n\n/**\n * Create a managed handle that will be freed when disposed.\n *\n * @param rawHandle - The u32 handle from WASM\n * @param wasm - The WASM module for freeing\n * @returns A disposable wrapper\n */\nexport function createHandle(rawHandle: number, wasm: WasmModule): WasmHandle {\n return new WasmHandle(rawHandle, (h) => wasm.exports.free_handle(h));\n}\n","/**\n * MessagePack encode/decode utilities for the WASM boundary.\n *\n * All structured data crossing the WASM boundary is serialized as MessagePack\n * byte slices. This module wraps `@msgpack/msgpack` with typed helpers.\n *\n * @module\n */\n\nimport { encode, decode } from '@msgpack/msgpack';\n\n/**\n * Encode a value to MessagePack bytes for sending to WASM.\n *\n * @param value - The value to encode\n * @returns MessagePack-encoded bytes\n */\nexport function packToWasm(value: unknown): Uint8Array {\n return encode(value);\n}\n\n/**\n * Decode MessagePack bytes received from WASM.\n *\n * @typeParam T - The expected decoded type\n * @param bytes - MessagePack-encoded bytes from WASM\n * @returns The decoded value\n */\nexport function unpackFromWasm<T = unknown>(bytes: Uint8Array): T {\n return decode(bytes) as T;\n}\n\n/**\n * Encode a schema operations list for the `build_schema` entry point.\n *\n * @param ops - Array of builder operations\n * @returns MessagePack-encoded bytes\n */\nexport function packSchemaOps(ops: readonly SchemaOp[]): Uint8Array {\n return encode(ops);\n}\n\n/**\n * Encode a migration mapping for WASM entry points.\n *\n * @param mapping - The migration mapping object\n * @returns MessagePack-encoded bytes\n */\nexport function packMigrationMapping(mapping: MigrationMapping): Uint8Array {\n return encode(mapping);\n}\n\n// ---------------------------------------------------------------------------\n// Internal types for structured WASM messages\n// ---------------------------------------------------------------------------\n\n/**\n * A single schema builder operation sent to WASM.\n *\n * Uses serde internally-tagged format: the `op` field acts as the\n * discriminant and all variant fields sit at the same level.\n */\nexport interface SchemaOp {\n readonly op: 'vertex' | 'edge' | 'hyper_edge' | 'constraint' | 'required';\n readonly [key: string]: unknown;\n}\n\n/** Wire format for an edge (matches Rust serialization). */\nexport interface EdgeWire {\n readonly src: string;\n readonly tgt: string;\n readonly kind: string;\n readonly name: string | null;\n}\n\n/** A migration mapping sent to WASM (matches Rust `Migration` struct). */\nexport interface MigrationMapping {\n readonly vertex_map: Record<string, string>;\n readonly edge_map: Map<EdgeWire, EdgeWire>;\n readonly hyper_edge_map: Record<string, string>;\n readonly label_map: Map<readonly [string, string], string>;\n readonly resolver: Map<readonly [string, string], EdgeWire>;\n}\n","/**\n * Fluent schema builder API.\n *\n * Builders are immutable: each method returns a new builder instance.\n * Call `.build()` to validate and produce the final schema.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Vertex,\n Edge,\n HyperEdge,\n Constraint,\n VertexOptions,\n EdgeOptions,\n SchemaData,\n} from './types.js';\nimport { SchemaValidationError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport type { SchemaOp } from './msgpack.js';\nimport { packSchemaOps } from './msgpack.js';\n\n/**\n * Immutable fluent builder for constructing schemas.\n *\n * Each mutation method returns a new `SchemaBuilder` instance,\n * leaving the original unchanged. The builder accumulates operations\n * that are sent to WASM on `.build()`.\n *\n * @example\n * ```typescript\n * const schema = builder\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n * ```\n */\nexport class SchemaBuilder {\n readonly #protocolName: string;\n readonly #protocolHandle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #ops: readonly SchemaOp[];\n readonly #vertices: ReadonlyMap<string, Vertex>;\n readonly #edges: readonly Edge[];\n readonly #hyperEdges: ReadonlyMap<string, HyperEdge>;\n readonly #constraints: ReadonlyMap<string, readonly Constraint[]>;\n readonly #required: ReadonlyMap<string, readonly Edge[]>;\n\n constructor(\n protocolName: string,\n protocolHandle: WasmHandle,\n wasm: WasmModule,\n ops: readonly SchemaOp[] = [],\n vertices: ReadonlyMap<string, Vertex> = new Map(),\n edges: readonly Edge[] = [],\n hyperEdges: ReadonlyMap<string, HyperEdge> = new Map(),\n constraints: ReadonlyMap<string, readonly Constraint[]> = new Map(),\n required: ReadonlyMap<string, readonly Edge[]> = new Map(),\n ) {\n this.#protocolName = protocolName;\n this.#protocolHandle = protocolHandle;\n this.#wasm = wasm;\n this.#ops = ops;\n this.#vertices = vertices;\n this.#edges = edges;\n this.#hyperEdges = hyperEdges;\n this.#constraints = constraints;\n this.#required = required;\n }\n\n /**\n * Add a vertex to the schema.\n *\n * @param id - Unique vertex identifier\n * @param kind - Vertex kind (e.g., 'record', 'object', 'string')\n * @param options - Optional vertex configuration (nsid, etc.)\n * @returns A new builder with the vertex added\n * @throws {@link SchemaValidationError} if vertex id is already in use\n */\n vertex(id: string, kind: string, options?: VertexOptions): SchemaBuilder {\n if (this.#vertices.has(id)) {\n throw new SchemaValidationError(\n `Vertex \"${id}\" already exists in schema`,\n [`Duplicate vertex id: ${id}`],\n );\n }\n\n const vertex: Vertex = {\n id,\n kind,\n nsid: options?.nsid,\n };\n\n const op: SchemaOp = {\n op: 'vertex',\n id,\n kind,\n nsid: options?.nsid ?? null,\n };\n\n const newVertices = new Map(this.#vertices);\n newVertices.set(id, vertex);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n newVertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a directed edge to the schema.\n *\n * @param src - Source vertex id\n * @param tgt - Target vertex id\n * @param kind - Edge kind (e.g., 'record-schema', 'prop')\n * @param options - Optional edge configuration (name, etc.)\n * @returns A new builder with the edge added\n * @throws {@link SchemaValidationError} if source or target vertex does not exist\n */\n edge(src: string, tgt: string, kind: string, options?: EdgeOptions): SchemaBuilder {\n if (!this.#vertices.has(src)) {\n throw new SchemaValidationError(\n `Edge source \"${src}\" does not exist`,\n [`Unknown source vertex: ${src}`],\n );\n }\n if (!this.#vertices.has(tgt)) {\n throw new SchemaValidationError(\n `Edge target \"${tgt}\" does not exist`,\n [`Unknown target vertex: ${tgt}`],\n );\n }\n\n const edge: Edge = {\n src,\n tgt,\n kind,\n name: options?.name,\n };\n\n const op: SchemaOp = {\n op: 'edge',\n src,\n tgt,\n kind,\n name: options?.name ?? null,\n };\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n [...this.#edges, edge],\n this.#hyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a hyperedge to the schema.\n *\n * Only valid if the protocol's schema theory includes ThHypergraph.\n *\n * @param id - Unique hyperedge identifier\n * @param kind - Hyperedge kind\n * @param signature - Label-to-vertex mapping\n * @param parentLabel - The label identifying the parent in the signature\n * @returns A new builder with the hyperedge added\n */\n hyperEdge(\n id: string,\n kind: string,\n signature: Record<string, string>,\n parentLabel: string,\n ): SchemaBuilder {\n const he: HyperEdge = { id, kind, signature, parentLabel };\n\n const op: SchemaOp = {\n op: 'hyper_edge',\n id,\n kind,\n signature,\n parent: parentLabel,\n };\n\n const newHyperEdges = new Map(this.#hyperEdges);\n newHyperEdges.set(id, he);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n newHyperEdges,\n this.#constraints,\n this.#required,\n );\n }\n\n /**\n * Add a constraint to a vertex.\n *\n * @param vertexId - The vertex to constrain\n * @param sort - Constraint sort (e.g., 'maxLength')\n * @param value - Constraint value\n * @returns A new builder with the constraint added\n */\n constraint(vertexId: string, sort: string, value: string): SchemaBuilder {\n const c: Constraint = { sort, value };\n\n const op: SchemaOp = {\n op: 'constraint',\n vertex: vertexId,\n sort,\n value,\n };\n\n const existing = this.#constraints.get(vertexId) ?? [];\n const newConstraints = new Map(this.#constraints);\n newConstraints.set(vertexId, [...existing, c]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n newConstraints,\n this.#required,\n );\n }\n\n /**\n * Mark edges as required for a vertex.\n *\n * @param vertexId - The vertex with required edges\n * @param edges - The edges that are required\n * @returns A new builder with the requirement added\n */\n required(vertexId: string, edges: readonly Edge[]): SchemaBuilder {\n const op: SchemaOp = {\n op: 'required',\n vertex: vertexId,\n edges: edges.map((e) => ({\n src: e.src,\n tgt: e.tgt,\n kind: e.kind,\n name: e.name ?? null,\n })),\n };\n\n const existing = this.#required.get(vertexId) ?? [];\n const newRequired = new Map(this.#required);\n newRequired.set(vertexId, [...existing, ...edges]);\n\n return new SchemaBuilder(\n this.#protocolName,\n this.#protocolHandle,\n this.#wasm,\n [...this.#ops, op],\n this.#vertices,\n this.#edges,\n this.#hyperEdges,\n this.#constraints,\n newRequired,\n );\n }\n\n /**\n * Validate and build the schema.\n *\n * Sends all accumulated operations to WASM for validation and construction.\n * Returns a `BuiltSchema` that holds the WASM handle and local data.\n *\n * @returns The validated, built schema\n * @throws {@link SchemaValidationError} if the schema is invalid\n */\n build(): BuiltSchema {\n const opsBytes = packSchemaOps([...this.#ops]);\n const rawHandle = this.#wasm.exports.build_schema(\n this.#protocolHandle.id,\n opsBytes,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n\n const data: SchemaData = {\n protocol: this.#protocolName,\n vertices: Object.fromEntries(this.#vertices),\n edges: [...this.#edges],\n hyperEdges: Object.fromEntries(this.#hyperEdges),\n constraints: Object.fromEntries(\n Array.from(this.#constraints.entries()).map(([k, v]) => [k, [...v]]),\n ),\n required: Object.fromEntries(\n Array.from(this.#required.entries()).map(([k, v]) => [k, [...v]]),\n ),\n variants: {},\n orderings: {},\n recursionPoints: {},\n usageModes: {},\n spans: {},\n nominal: {},\n };\n\n return new BuiltSchema(handle, data, this.#wasm);\n }\n}\n\n/**\n * A validated, built schema with a WASM-side handle.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class BuiltSchema implements Disposable {\n readonly #handle: WasmHandle;\n readonly #data: SchemaData;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, data: SchemaData, wasm: WasmModule) {\n this.#handle = handle;\n this.#data = data;\n this.#wasm = wasm;\n }\n\n /** The WASM handle for this schema. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The WASM module reference. Internal use only. */\n get _wasm(): WasmModule {\n return this.#wasm;\n }\n\n /** The schema data (vertices, edges, constraints, etc.). */\n get data(): SchemaData {\n return this.#data;\n }\n\n /** The protocol name this schema belongs to. */\n get protocol(): string {\n return this.#data.protocol;\n }\n\n /** All vertices in the schema. */\n get vertices(): Readonly<Record<string, Vertex>> {\n return this.#data.vertices;\n }\n\n /** All edges in the schema. */\n get edges(): readonly Edge[] {\n return this.#data.edges;\n }\n\n /** Release the WASM-side schema resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n","/**\n * Protocol definition helpers.\n *\n * A protocol specifies the schema theory and instance theory used by\n * a family of schemas (e.g., ATProto, SQL, Protobuf). This module\n * provides helpers for defining and looking up protocols.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, EdgeRule } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm } from './msgpack.js';\nimport { SchemaBuilder } from './schema.js';\n\n/**\n * A registered protocol with a WASM-side handle.\n *\n * Provides a fluent API for building schemas within this protocol.\n * Implements `Disposable` for automatic cleanup.\n */\nexport class Protocol implements Disposable {\n readonly #handle: WasmHandle;\n readonly #spec: ProtocolSpec;\n readonly #wasm: WasmModule;\n\n constructor(handle: WasmHandle, spec: ProtocolSpec, wasm: WasmModule) {\n this.#handle = handle;\n this.#spec = spec;\n this.#wasm = wasm;\n }\n\n /** The protocol name. */\n get name(): string {\n return this.#spec.name;\n }\n\n /** The full protocol specification. */\n get spec(): ProtocolSpec {\n return this.#spec;\n }\n\n /** The WASM handle. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /**\n * Start building a schema within this protocol.\n *\n * @returns A new `SchemaBuilder` bound to this protocol\n */\n schema(): SchemaBuilder {\n return new SchemaBuilder(this.#spec.name, this.#handle, this.#wasm);\n }\n\n /** Release the WASM-side protocol resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Define a protocol by sending its specification to WASM.\n *\n * @param spec - The protocol specification\n * @param wasm - The WASM module\n * @returns A registered protocol with a WASM handle\n * @throws {@link PanprotoError} if the WASM call fails\n */\nexport function defineProtocol(spec: ProtocolSpec, wasm: WasmModule): Protocol {\n const wireSpec = {\n name: spec.name,\n schema_theory: spec.schemaTheory,\n instance_theory: spec.instanceTheory,\n edge_rules: spec.edgeRules.map((r) => ({\n edge_kind: r.edgeKind,\n src_kinds: [...r.srcKinds],\n tgt_kinds: [...r.tgtKinds],\n })),\n obj_kinds: [...spec.objKinds],\n constraint_sorts: [...spec.constraintSorts],\n };\n\n try {\n const bytes = packToWasm(wireSpec);\n const rawHandle = wasm.exports.define_protocol(bytes);\n const handle = createHandle(rawHandle, wasm);\n return new Protocol(handle, spec, wasm);\n } catch (error) {\n throw new PanprotoError(\n `Failed to define protocol \"${spec.name}\": ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Built-in protocol specs\n// ---------------------------------------------------------------------------\n\n/**\n * Built-in ATProto protocol specification.\n *\n * Schema theory: colimit(ThGraph, ThConstraint, ThMulti).\n * Instance theory: ThWType + ThMeta.\n */\nexport const ATPROTO_SPEC: ProtocolSpec = {\n name: 'atproto',\n schemaTheory: 'ThATProtoSchema',\n instanceTheory: 'ThATProtoInstance',\n edgeRules: [\n { edgeKind: 'record-schema', srcKinds: ['record'], tgtKinds: ['object'] },\n { edgeKind: 'prop', srcKinds: ['object', 'query', 'procedure', 'subscription'], tgtKinds: [] },\n { edgeKind: 'items', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['union'], tgtKinds: [] },\n { edgeKind: 'ref', srcKinds: [], tgtKinds: [] },\n { edgeKind: 'self-ref', srcKinds: [], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: [\n 'record', 'object', 'array', 'union', 'string', 'integer', 'boolean',\n 'bytes', 'cid-link', 'blob', 'unknown', 'token', 'query', 'procedure',\n 'subscription', 'ref',\n ],\n constraintSorts: [\n 'minLength', 'maxLength', 'minimum', 'maximum', 'maxGraphemes',\n 'enum', 'const', 'default', 'closed',\n ],\n};\n\n/**\n * Built-in SQL protocol specification.\n *\n * Schema theory: colimit(ThHypergraph, ThConstraint).\n * Instance theory: ThFunctor.\n */\nexport const SQL_SPEC: ProtocolSpec = {\n name: 'sql',\n schemaTheory: 'ThConstrainedHypergraph',\n instanceTheory: 'ThFunctor',\n edgeRules: [\n { edgeKind: 'column', srcKinds: ['table'], tgtKinds: ['type'] },\n { edgeKind: 'fk', srcKinds: ['table'], tgtKinds: ['table'] },\n { edgeKind: 'pk', srcKinds: ['table'], tgtKinds: ['column'] },\n ] satisfies EdgeRule[],\n objKinds: ['table'],\n constraintSorts: ['nullable', 'unique', 'check', 'default'],\n};\n\n/**\n * Built-in Protobuf protocol specification.\n */\nexport const PROTOBUF_SPEC: ProtocolSpec = {\n name: 'protobuf',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['message'], tgtKinds: [] },\n { edgeKind: 'nested', srcKinds: ['message'], tgtKinds: ['message', 'enum'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['message'],\n constraintSorts: ['field-number', 'repeated', 'optional', 'map-key', 'map-value'],\n};\n\n/**\n * Built-in GraphQL protocol specification.\n */\nexport const GRAPHQL_SPEC: ProtocolSpec = {\n name: 'graphql',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'field', srcKinds: ['type', 'input'], tgtKinds: [] },\n { edgeKind: 'implements', srcKinds: ['type'], tgtKinds: ['interface'] },\n { edgeKind: 'member', srcKinds: ['union'], tgtKinds: ['type'] },\n { edgeKind: 'value', srcKinds: ['enum'], tgtKinds: ['enum-value'] },\n ] satisfies EdgeRule[],\n objKinds: ['type', 'input'],\n constraintSorts: ['non-null', 'list', 'deprecated'],\n};\n\n/**\n * Built-in JSON Schema protocol specification.\n */\nexport const JSON_SCHEMA_SPEC: ProtocolSpec = {\n name: 'json-schema',\n schemaTheory: 'ThConstrainedGraph',\n instanceTheory: 'ThWType',\n edgeRules: [\n { edgeKind: 'property', srcKinds: ['object'], tgtKinds: [] },\n { edgeKind: 'item', srcKinds: ['array'], tgtKinds: [] },\n { edgeKind: 'variant', srcKinds: ['oneOf', 'anyOf'], tgtKinds: [] },\n ] satisfies EdgeRule[],\n objKinds: ['object'],\n constraintSorts: ['minLength', 'maxLength', 'minimum', 'maximum', 'pattern', 'format', 'required'],\n};\n\n/** Registry of built-in protocol specs, keyed by name. */\nexport const BUILTIN_PROTOCOLS: ReadonlyMap<string, ProtocolSpec> = new Map([\n ['atproto', ATPROTO_SPEC],\n ['sql', SQL_SPEC],\n ['protobuf', PROTOBUF_SPEC],\n ['graphql', GRAPHQL_SPEC],\n ['json-schema', JSON_SCHEMA_SPEC],\n]);\n","/**\n * Migration builder and compiled migration wrapper.\n *\n * Migrations define a mapping between two schemas. Once compiled,\n * they can efficiently transform records via WASM.\n *\n * @module\n */\n\nimport type {\n WasmModule,\n Edge,\n LiftResult,\n GetResult,\n ExistenceReport,\n MigrationSpec,\n} from './types.js';\nimport { MigrationError, WasmError } from './types.js';\nimport { WasmHandle, createHandle } from './wasm.js';\nimport { packToWasm, unpackFromWasm, packMigrationMapping } from './msgpack.js';\nimport type { BuiltSchema } from './schema.js';\n\n/**\n * Fluent builder for constructing migrations between two schemas.\n *\n * Each mutation method returns a new `MigrationBuilder` instance,\n * leaving the original unchanged.\n *\n * @example\n * ```typescript\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .map('post:body', 'post:body')\n * .mapEdge(oldEdge, newEdge)\n * .compile();\n * ```\n */\nexport class MigrationBuilder {\n readonly #src: BuiltSchema;\n readonly #tgt: BuiltSchema;\n readonly #wasm: WasmModule;\n readonly #vertexMap: ReadonlyMap<string, string>;\n readonly #edgeMap: readonly [Edge, Edge][];\n readonly #resolvers: readonly [[string, string], Edge][];\n\n constructor(\n src: BuiltSchema,\n tgt: BuiltSchema,\n wasm: WasmModule,\n vertexMap: ReadonlyMap<string, string> = new Map(),\n edgeMap: readonly [Edge, Edge][] = [],\n resolvers: readonly [[string, string], Edge][] = [],\n ) {\n this.#src = src;\n this.#tgt = tgt;\n this.#wasm = wasm;\n this.#vertexMap = vertexMap;\n this.#edgeMap = edgeMap;\n this.#resolvers = resolvers;\n }\n\n /**\n * Map a source vertex to a target vertex.\n *\n * @param srcVertex - Vertex id in the source schema\n * @param tgtVertex - Vertex id in the target schema\n * @returns A new builder with the mapping added\n */\n map(srcVertex: string, tgtVertex: string): MigrationBuilder {\n const newMap = new Map(this.#vertexMap);\n newMap.set(srcVertex, tgtVertex);\n\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n newMap,\n this.#edgeMap,\n this.#resolvers,\n );\n }\n\n /**\n * Map a source edge to a target edge.\n *\n * @param srcEdge - Edge in the source schema\n * @param tgtEdge - Edge in the target schema\n * @returns A new builder with the edge mapping added\n */\n mapEdge(srcEdge: Edge, tgtEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n [...this.#edgeMap, [srcEdge, tgtEdge]],\n this.#resolvers,\n );\n }\n\n /**\n * Add a resolver for ancestor contraction ambiguity.\n *\n * When a migration contracts nodes and the resulting edge between\n * two vertex kinds is ambiguous, a resolver specifies which edge to use.\n *\n * @param srcKind - Source vertex kind in the contracted pair\n * @param tgtKind - Target vertex kind in the contracted pair\n * @param resolvedEdge - The edge to use for this pair\n * @returns A new builder with the resolver added\n */\n resolve(srcKind: string, tgtKind: string, resolvedEdge: Edge): MigrationBuilder {\n return new MigrationBuilder(\n this.#src,\n this.#tgt,\n this.#wasm,\n this.#vertexMap,\n this.#edgeMap,\n [...this.#resolvers, [[srcKind, tgtKind], resolvedEdge]],\n );\n }\n\n /**\n * Get the current migration specification.\n *\n * @returns The migration spec with all accumulated mappings\n */\n toSpec(): MigrationSpec {\n return {\n vertexMap: Object.fromEntries(this.#vertexMap),\n edgeMap: [...this.#edgeMap],\n resolvers: [...this.#resolvers],\n };\n }\n\n /**\n * Compile the migration for fast per-record application.\n *\n * Sends the migration specification to WASM for compilation.\n * The resulting `CompiledMigration` can be used to transform records.\n *\n * @returns A compiled migration ready for record transformation\n * @throws {@link MigrationError} if compilation fails\n */\n compile(): CompiledMigration {\n const edgeMap = new Map(\n this.#edgeMap.map(([src, tgt]) => [\n { src: src.src, tgt: src.tgt, kind: src.kind, name: src.name ?? null },\n { src: tgt.src, tgt: tgt.tgt, kind: tgt.kind, name: tgt.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n this.#resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: Object.fromEntries(this.#vertexMap),\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n try {\n const rawHandle = this.#wasm.exports.compile_migration(\n this.#src._handle.id,\n this.#tgt._handle.id,\n mapping,\n );\n\n const handle = createHandle(rawHandle, this.#wasm);\n return new CompiledMigration(handle, this.#wasm, this.toSpec());\n } catch (error) {\n throw new MigrationError(\n `Failed to compile migration: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n}\n\n/**\n * A compiled migration that can efficiently transform records via WASM.\n *\n * Implements `Disposable` for automatic cleanup of the WASM resource.\n */\nexport class CompiledMigration implements Disposable {\n readonly #handle: WasmHandle;\n readonly #wasm: WasmModule;\n readonly #spec: MigrationSpec;\n\n constructor(handle: WasmHandle, wasm: WasmModule, spec: MigrationSpec) {\n this.#handle = handle;\n this.#wasm = wasm;\n this.#spec = spec;\n }\n\n /** The WASM handle for this migration. Internal use only. */\n get _handle(): WasmHandle {\n return this.#handle;\n }\n\n /** The migration specification used to build this migration. */\n get spec(): MigrationSpec {\n return this.#spec;\n }\n\n /**\n * Transform a record using this migration (forward direction).\n *\n * This is the hot path: data goes through WASM as MessagePack bytes\n * with no intermediate JS-heap allocation.\n *\n * @param record - The input record to transform\n * @returns The transformed record\n * @throws {@link WasmError} if the WASM call fails\n */\n lift(record: unknown): LiftResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.lift_record(\n this.#handle.id,\n inputBytes,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `lift_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional get: extract view and complement from a record.\n *\n * The complement captures data discarded by the forward projection,\n * enabling lossless round-tripping via `put()`.\n *\n * @param record - The input record\n * @returns The projected view and opaque complement bytes\n * @throws {@link WasmError} if the WASM call fails\n */\n get(record: unknown): GetResult {\n const inputBytes = packToWasm(record);\n\n try {\n const outputBytes = this.#wasm.exports.get_record(\n this.#handle.id,\n inputBytes,\n );\n const result = unpackFromWasm<{ view: unknown; complement: Uint8Array }>(outputBytes);\n return {\n view: result.view,\n complement: result.complement instanceof Uint8Array\n ? result.complement\n : new Uint8Array(result.complement as ArrayBuffer),\n };\n } catch (error) {\n throw new WasmError(\n `get_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /**\n * Bidirectional put: restore a full record from a modified view and complement.\n *\n * @param view - The (possibly modified) projected view\n * @param complement - The complement from a prior `get()` call\n * @returns The restored full record\n * @throws {@link WasmError} if the WASM call fails\n */\n put(view: unknown, complement: Uint8Array): LiftResult {\n const viewBytes = packToWasm(view);\n\n try {\n const outputBytes = this.#wasm.exports.put_record(\n this.#handle.id,\n viewBytes,\n complement,\n );\n const data = unpackFromWasm(outputBytes);\n return { data };\n } catch (error) {\n throw new WasmError(\n `put_record failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n }\n\n /** Release the WASM-side compiled migration resource. */\n [Symbol.dispose](): void {\n this.#handle[Symbol.dispose]();\n }\n}\n\n/**\n * Check existence conditions for a migration between two schemas.\n *\n * @param src - Source schema handle\n * @param tgt - Target schema handle\n * @param spec - The migration specification\n * @param wasm - The WASM module\n * @returns The existence report\n */\nexport function checkExistence(\n protoHandle: number,\n src: BuiltSchema,\n tgt: BuiltSchema,\n spec: MigrationSpec,\n wasm: WasmModule,\n): ExistenceReport {\n const edgeMap = new Map(\n spec.edgeMap.map(([s, t]) => [\n { src: s.src, tgt: s.tgt, kind: s.kind, name: s.name ?? null },\n { src: t.src, tgt: t.tgt, kind: t.kind, name: t.name ?? null },\n ] as const),\n );\n const resolver = new Map(\n spec.resolvers.map(([[s, t], e]) => [\n [s, t] as const,\n { src: e.src, tgt: e.tgt, kind: e.kind, name: e.name ?? null },\n ] as const),\n );\n const mapping = packMigrationMapping({\n vertex_map: spec.vertexMap,\n edge_map: edgeMap,\n hyper_edge_map: {},\n label_map: new Map(),\n resolver,\n });\n\n const resultBytes = wasm.exports.check_existence(\n protoHandle,\n src._handle.id,\n tgt._handle.id,\n mapping,\n );\n\n return unpackFromWasm<ExistenceReport>(resultBytes);\n}\n\n/**\n * Compose two compiled migrations into a single migration.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @param wasm - The WASM module\n * @returns A new compiled migration representing m2 . m1\n * @throws {@link MigrationError} if composition fails\n */\nexport function composeMigrations(\n m1: CompiledMigration,\n m2: CompiledMigration,\n wasm: WasmModule,\n): CompiledMigration {\n try {\n const rawHandle = wasm.exports.compose_migrations(\n m1._handle.id,\n m2._handle.id,\n );\n const handle = createHandle(rawHandle, wasm);\n\n // Compose vertex maps: if m1 maps A->B and m2 maps B->C, composed maps A->C.\n // Vertices in m1 whose target is not remapped by m2 pass through unchanged.\n const composedVertexMap: Record<string, string> = {};\n for (const [src, intermediate] of Object.entries(m1.spec.vertexMap)) {\n const final_ = m2.spec.vertexMap[intermediate];\n composedVertexMap[src] = final_ ?? intermediate;\n }\n\n // Concatenate edge maps and resolvers from both migrations. The WASM side\n // performs the actual composition; this spec is a best-effort reconstruction\n // for introspection purposes.\n const composedSpec: MigrationSpec = {\n vertexMap: composedVertexMap,\n edgeMap: [...m1.spec.edgeMap, ...m2.spec.edgeMap],\n resolvers: [...m1.spec.resolvers, ...m2.spec.resolvers],\n };\n\n return new CompiledMigration(handle, wasm, composedSpec);\n } catch (error) {\n throw new MigrationError(\n `Failed to compose migrations: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n","/**\n * Main Panproto class — the primary entry point for the SDK.\n *\n * Wraps the WASM module and provides the high-level API for working\n * with protocols, schemas, migrations, and diffs.\n *\n * @module\n */\n\nimport type { WasmModule, ProtocolSpec, DiffReport } from './types.js';\nimport { PanprotoError } from './types.js';\nimport { loadWasm, type WasmGlueModule } from './wasm.js';\nimport {\n Protocol,\n defineProtocol,\n BUILTIN_PROTOCOLS,\n} from './protocol.js';\nimport type { BuiltSchema } from './schema.js';\nimport {\n MigrationBuilder,\n CompiledMigration,\n checkExistence,\n composeMigrations,\n} from './migration.js';\nimport { unpackFromWasm } from './msgpack.js';\n\n/**\n * The main entry point for the panproto SDK.\n *\n * Create an instance with {@link Panproto.init}, then use it to define\n * protocols, build schemas, compile migrations, and diff schemas.\n *\n * Implements `Disposable` so it can be used with `using` to automatically\n * clean up all WASM resources.\n *\n * @example\n * ```typescript\n * const panproto = await Panproto.init();\n * const atproto = panproto.protocol('atproto');\n *\n * const schema = atproto.schema()\n * .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })\n * .vertex('post:body', 'object')\n * .edge('post', 'post:body', 'record-schema')\n * .build();\n *\n * const migration = panproto.migration(oldSchema, newSchema)\n * .map('post', 'post')\n * .compile();\n *\n * const result = migration.lift(inputRecord);\n * ```\n */\nexport class Panproto implements Disposable {\n readonly #wasm: WasmModule;\n readonly #protocols: Map<string, Protocol>;\n\n private constructor(wasm: WasmModule) {\n this.#wasm = wasm;\n this.#protocols = new Map();\n }\n\n /**\n * Initialize the panproto SDK by loading the WASM module.\n *\n * @param input - URL to the wasm-bindgen glue module, or a pre-imported\n * glue module object (for bundler environments like Vite).\n * Defaults to the bundled glue module.\n * @returns An initialized Panproto instance\n * @throws {@link import('./types.js').WasmError} if WASM loading fails\n */\n static async init(input?: string | URL | WasmGlueModule): Promise<Panproto> {\n const wasm = await loadWasm(input);\n return new Panproto(wasm);\n }\n\n /**\n * Get or register a protocol by name.\n *\n * If the protocol is a built-in (e.g., 'atproto', 'sql'), it is\n * automatically registered on first access. Custom protocols must\n * be registered first with {@link Panproto.defineProtocol}.\n *\n * @param name - The protocol name\n * @returns The protocol instance\n * @throws {@link PanprotoError} if the protocol is not found\n */\n protocol(name: string): Protocol {\n const cached = this.#protocols.get(name);\n if (cached) return cached;\n\n // Try built-in protocols\n const builtinSpec = BUILTIN_PROTOCOLS.get(name);\n if (builtinSpec) {\n const proto = defineProtocol(builtinSpec, this.#wasm);\n this.#protocols.set(name, proto);\n return proto;\n }\n\n throw new PanprotoError(\n `Protocol \"${name}\" not found. Register it with defineProtocol() first.`,\n );\n }\n\n /**\n * Define and register a custom protocol.\n *\n * @param spec - The protocol specification\n * @returns The registered protocol\n * @throws {@link PanprotoError} if registration fails\n */\n defineProtocol(spec: ProtocolSpec): Protocol {\n const proto = defineProtocol(spec, this.#wasm);\n this.#protocols.set(spec.name, proto);\n return proto;\n }\n\n /**\n * Start building a migration between two schemas.\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @returns A migration builder\n */\n migration(src: BuiltSchema, tgt: BuiltSchema): MigrationBuilder {\n return new MigrationBuilder(src, tgt, this.#wasm);\n }\n\n /**\n * Check existence conditions for a proposed migration.\n *\n * Verifies that the migration specification satisfies all\n * protocol-derived constraints (edge coverage, kind consistency,\n * required fields, etc.).\n *\n * @param src - The source schema\n * @param tgt - The target schema\n * @param builder - The migration builder with mappings\n * @returns The existence report\n */\n checkExistence(\n src: BuiltSchema,\n tgt: BuiltSchema,\n builder: MigrationBuilder,\n ): import('./types.js').ExistenceReport {\n const proto = this.#protocols.get(src.protocol);\n if (!proto) {\n throw new PanprotoError(\n `Protocol \"${src.protocol}\" not registered. Call protocol() first.`,\n );\n }\n return checkExistence(proto._handle.id, src, tgt, builder.toSpec(), this.#wasm);\n }\n\n /**\n * Compose two compiled migrations into a single migration.\n *\n * The resulting migration is equivalent to applying `m1` then `m2`.\n *\n * @param m1 - First migration (applied first)\n * @param m2 - Second migration (applied second)\n * @returns The composed migration\n * @throws {@link import('./types.js').MigrationError} if composition fails\n */\n compose(m1: CompiledMigration, m2: CompiledMigration): CompiledMigration {\n return composeMigrations(m1, m2, this.#wasm);\n }\n\n /**\n * Diff two schemas and produce a compatibility report.\n *\n * @param oldSchema - The old/source schema\n * @param newSchema - The new/target schema\n * @returns A diff report with changes and compatibility classification\n */\n diff(oldSchema: BuiltSchema, newSchema: BuiltSchema): DiffReport {\n const resultBytes = this.#wasm.exports.diff_schemas(\n oldSchema._handle.id,\n newSchema._handle.id,\n );\n return unpackFromWasm<DiffReport>(resultBytes);\n }\n\n /**\n * Release all WASM resources held by this instance.\n *\n * Disposes all cached protocols. After disposal, this instance\n * must not be used.\n */\n [Symbol.dispose](): void {\n for (const proto of this.#protocols.values()) {\n proto[Symbol.dispose]();\n }\n this.#protocols.clear();\n }\n}\n","/**\n * Lens and combinator API for bidirectional transformations.\n *\n * Every migration is a lens with `get` (forward projection) and\n * `put` (restore from complement). This module provides Cambria-style\n * combinators that compose into migrations.\n *\n * @module\n */\n\n// ---------------------------------------------------------------------------\n// Combinator types\n// ---------------------------------------------------------------------------\n\n/** Rename a field from one name to another. */\nexport interface RenameFieldCombinator {\n readonly type: 'rename-field';\n readonly old: string;\n readonly new: string;\n}\n\n/** Add a new field with a default value. */\nexport interface AddFieldCombinator {\n readonly type: 'add-field';\n readonly name: string;\n readonly vertexKind: string;\n readonly default: unknown;\n}\n\n/** Remove a field from the schema. */\nexport interface RemoveFieldCombinator {\n readonly type: 'remove-field';\n readonly name: string;\n}\n\n/** Wrap a value inside a new object with a given field name. */\nexport interface WrapInObjectCombinator {\n readonly type: 'wrap-in-object';\n readonly fieldName: string;\n}\n\n/** Hoist a nested field up to the host level. */\nexport interface HoistFieldCombinator {\n readonly type: 'hoist-field';\n readonly host: string;\n readonly field: string;\n}\n\n/** Coerce a value from one type to another. */\nexport interface CoerceTypeCombinator {\n readonly type: 'coerce-type';\n readonly fromKind: string;\n readonly toKind: string;\n}\n\n/** Sequential composition of two combinators. */\nexport interface ComposeCombinator {\n readonly type: 'compose';\n readonly first: Combinator;\n readonly second: Combinator;\n}\n\n/** A lens combinator (Cambria-style). */\nexport type Combinator =\n | RenameFieldCombinator\n | AddFieldCombinator\n | RemoveFieldCombinator\n | WrapInObjectCombinator\n | HoistFieldCombinator\n | CoerceTypeCombinator\n | ComposeCombinator;\n\n// ---------------------------------------------------------------------------\n// Combinator constructors\n// ---------------------------------------------------------------------------\n\n/**\n * Create a rename-field combinator.\n *\n * @param oldName - The current field name\n * @param newName - The desired field name\n * @returns A rename-field combinator\n */\nexport function renameField(oldName: string, newName: string): RenameFieldCombinator {\n return { type: 'rename-field', old: oldName, new: newName };\n}\n\n/**\n * Create an add-field combinator.\n *\n * @param name - The field name to add\n * @param vertexKind - The vertex kind for the new field\n * @param defaultValue - The default value for the field\n * @returns An add-field combinator\n */\nexport function addField(name: string, vertexKind: string, defaultValue: unknown): AddFieldCombinator {\n return { type: 'add-field', name, vertexKind, default: defaultValue };\n}\n\n/**\n * Create a remove-field combinator.\n *\n * @param name - The field name to remove\n * @returns A remove-field combinator\n */\nexport function removeField(name: string): RemoveFieldCombinator {\n return { type: 'remove-field', name };\n}\n\n/**\n * Create a wrap-in-object combinator.\n *\n * @param fieldName - The field name for the wrapper object\n * @returns A wrap-in-object combinator\n */\nexport function wrapInObject(fieldName: string): WrapInObjectCombinator {\n return { type: 'wrap-in-object', fieldName };\n}\n\n/**\n * Create a hoist-field combinator.\n *\n * @param host - The host vertex to hoist into\n * @param field - The nested field to hoist\n * @returns A hoist-field combinator\n */\nexport function hoistField(host: string, field: string): HoistFieldCombinator {\n return { type: 'hoist-field', host, field };\n}\n\n/**\n * Create a coerce-type combinator.\n *\n * @param fromKind - The source type kind\n * @param toKind - The target type kind\n * @returns A coerce-type combinator\n */\nexport function coerceType(fromKind: string, toKind: string): CoerceTypeCombinator {\n return { type: 'coerce-type', fromKind, toKind };\n}\n\n/**\n * Compose two combinators sequentially.\n *\n * @param first - The combinator applied first\n * @param second - The combinator applied second\n * @returns A composed combinator\n */\nexport function compose(first: Combinator, second: Combinator): ComposeCombinator {\n return { type: 'compose', first, second };\n}\n\n/**\n * Compose a chain of combinators left-to-right.\n *\n * @param combinators - The combinators to compose (at least one required)\n * @returns The composed combinator\n * @throws If the combinators array is empty\n */\nexport function pipeline(combinators: readonly [Combinator, ...Combinator[]]): Combinator {\n const [first, ...rest] = combinators;\n return rest.reduce<Combinator>((acc, c) => compose(acc, c), first);\n}\n\n/**\n * Serialize a combinator to a plain object for MessagePack encoding.\n *\n * @param combinator - The combinator to serialize\n * @returns A plain object suitable for MessagePack encoding\n */\nexport function combinatorToWire(combinator: Combinator): Record<string, unknown> {\n switch (combinator.type) {\n case 'rename-field':\n return { RenameField: { old: combinator.old, new: combinator.new } };\n case 'add-field':\n return { AddField: { name: combinator.name, vertex_kind: combinator.vertexKind, default: combinator.default } };\n case 'remove-field':\n return { RemoveField: { name: combinator.name } };\n case 'wrap-in-object':\n return { WrapInObject: { field_name: combinator.fieldName } };\n case 'hoist-field':\n return { HoistField: { host: combinator.host, field: combinator.field } };\n case 'coerce-type':\n return { CoerceType: { from_kind: combinator.fromKind, to_kind: combinator.toKind } };\n case 'compose':\n return { Compose: [combinatorToWire(combinator.first), combinatorToWire(combinator.second)] };\n }\n}\n"],"names":["exports"],"mappings":";AAgPO,MAAM,sBAAsB,MAAM;AAAA,EACrB,OAAe;AAAA,EAEjC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF;AAGO,MAAM,kBAAkB,cAAc;AAAA,EACzB,OAAO;AAC3B;AAGO,MAAM,8BAA8B,cAAc;AAAA,EAGvD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AAGO,MAAM,uBAAuB,cAAc;AAAA,EAC9B,OAAO;AAC3B;AAGO,MAAM,4BAA4B,cAAc;AAAA,EAGrD,YACE,SACS,QACT;AACA,UAAM,OAAO;AAFJ,SAAA,SAAA;AAAA,EAGX;AAAA,EAPkB,OAAO;AAQ3B;AC1QA,MAAM,mBAAmB,IAAA,IAAA,sBAAA,YAAA,GAAA;AAmCzB,eAAsB,SAAS,OAA4D;AACzF,MAAI;AACF,QAAI;AAEJ,QAAI,SAAS,OAAO,UAAU,YAAY,aAAa,SAAS,OAAO,MAAM,YAAY,YAAY;AAEnG,aAAO;AAAA,IACT,OAAO;AAEL,YAAM,MAAO,SAAsC;AACnD,aAAO,MAAM;AAAA;AAAA,QAA0B,OAAO,GAAG;AAAA;AAAA,IACnD;AAEA,UAAM,aAAa,MAAM,KAAK,QAAA;AAE9B,UAAMA,YAAuB;AAAA,MAC3B,iBAAiB,KAAK;AAAA,MACtB,cAAc,KAAK;AAAA,MACnB,iBAAiB,KAAK;AAAA,MACtB,mBAAmB,KAAK;AAAA,MACxB,aAAa,KAAK;AAAA,MAClB,YAAY,KAAK;AAAA,MACjB,YAAY,KAAK;AAAA,MACjB,oBAAoB,KAAK;AAAA,MACzB,cAAc,KAAK;AAAA,MACnB,aAAa,K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sort: string;
|
|
73
73
|
readonly value: string;
|
|
74
74
|
}
|
|
75
|
+
/** A variant in a schema graph (union member). */
|
|
76
|
+
export interface Variant {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly parent_vertex: string;
|
|
79
|
+
readonly tag?: string | undefined;
|
|
80
|
+
}
|
|
81
|
+
/** A recursion point (mu-binding site). */
|
|
82
|
+
export interface RecursionPoint {
|
|
83
|
+
readonly mu_id: string;
|
|
84
|
+
readonly target_vertex: string;
|
|
85
|
+
}
|
|
86
|
+
/** Usage mode for a vertex (structural, linear, or affine). */
|
|
87
|
+
export type UsageMode = 'structural' | 'linear' | 'affine';
|
|
88
|
+
/** A span between two vertices. */
|
|
89
|
+
export interface Span {
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly left: string;
|
|
92
|
+
readonly right: string;
|
|
93
|
+
}
|
|
75
94
|
/** Options for edge creation. */
|
|
76
95
|
export interface EdgeOptions {
|
|
77
96
|
readonly name?: string;
|
|
@@ -84,6 +103,12 @@ export interface SchemaData {
|
|
|
84
103
|
readonly hyperEdges: Readonly<Record<string, HyperEdge>>;
|
|
85
104
|
readonly constraints: Readonly<Record<string, readonly Constraint[]>>;
|
|
86
105
|
readonly required: Readonly<Record<string, readonly Edge[]>>;
|
|
106
|
+
readonly variants: Readonly<Record<string, readonly Variant[]>>;
|
|
107
|
+
readonly orderings: Readonly<Record<string, number>>;
|
|
108
|
+
readonly recursionPoints: Readonly<Record<string, RecursionPoint>>;
|
|
109
|
+
readonly usageModes: Readonly<Record<string, UsageMode>>;
|
|
110
|
+
readonly spans: Readonly<Record<string, Span>>;
|
|
111
|
+
readonly nominal: Readonly<Record<string, boolean>>;
|
|
87
112
|
}
|
|
88
113
|
/** A vertex mapping entry for migration building. */
|
|
89
114
|
export interface VertexMapping {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"A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e;CAInC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panproto/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TypeScript SDK for panproto — protocol-aware schema migration via generalized algebraic theories",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"oxlint": "^0.16.0",
|
|
37
37
|
"typescript": "^5.8.0",
|
|
38
38
|
"vite": "^6.0.0",
|
|
39
|
+
"vite-plugin-dts": "^4.5.4",
|
|
39
40
|
"vitest": "^3.0.0"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|