@panproto/core 0.6.0 → 0.8.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/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  [![npm](https://img.shields.io/npm/v/@panproto/core)](https://www.npmjs.com/package/@panproto/core)
4
4
  [![MIT](https://img.shields.io/badge/license-MIT-blue.svg)](../../LICENSE)
5
5
 
6
- TypeScript SDK for panproto. Protocol-aware schema migration via [generalized algebraic theories](https://ncatlab.org/nlab/show/generalized+algebraic+theory).
6
+ TypeScript SDK for panproto. Protocol-aware schema migration via [generalized algebraic theories](https://ncatlab.org/nlab/show/generalized+algebraic+theory), with automatic lens generation via [protolenses](https://ncatlab.org/nlab/show/natural+transformation).
7
7
 
8
- This package wraps the panproto WASM module, providing a typed, ergonomic API for defining protocols, building schemas, computing migrations, and applying lens-based transformations from JavaScript and TypeScript.
8
+ This package wraps the panproto WASM module, providing a typed, ergonomic API for defining protocols, building schemas, computing migrations, and applying protolens-based transformations from JavaScript and TypeScript.
9
9
 
10
10
  Requires Node.js >= 20.
11
11
 
@@ -23,26 +23,35 @@ import { Panproto } from '@panproto/core';
23
23
  const panproto = await Panproto.init();
24
24
  const atproto = panproto.protocol('atproto');
25
25
 
26
- // Build a schema
27
- const schema = atproto.schema()
26
+ // Build schemas
27
+ const oldSchema = atproto.schema()
28
28
  .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })
29
29
  .vertex('post:body', 'object')
30
30
  .edge('post', 'post:body', 'record-schema')
31
31
  .build();
32
32
 
33
- // Diff two schemas
34
- const diff = panproto.diff(oldSchema, newSchema);
33
+ const newSchema = atproto.schema()
34
+ .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })
35
+ .vertex('post:body', 'object')
36
+ .vertex('post:body.title', 'string')
37
+ .edge('post', 'post:body', 'record-schema')
38
+ .edge('post:body', 'post:body.title', 'prop', { name: 'title' })
39
+ .build();
40
+
41
+ // One-liner data conversion between schema versions
42
+ const converted = panproto.convert(record, oldSchema, newSchema);
35
43
 
36
- // Compile and apply a migration
37
- const migration = panproto.migration(srcSchema, tgtSchema)
38
- .map('old_id', 'new_id')
39
- .compile();
44
+ // Auto-generate a lens with full control
45
+ const lens = panproto.lens(oldSchema, newSchema);
46
+ const { view, complement } = lens.get(record);
47
+ const restored = lens.put(modifiedView, complement);
40
48
 
41
- const lifted = migration.lift(record);
49
+ // Build a reusable protolens chain (schema-independent)
50
+ const chain = panproto.protolensChain(oldSchema, newSchema);
51
+ const result = chain.apply(record);
42
52
 
43
- // Bidirectional lens
44
- const { view, complement } = migration.get(record);
45
- const restored = migration.put(modifiedView, complement);
53
+ // Factorize a theory morphism into elementary steps
54
+ const factors = panproto.factorizeMorphism(morphism);
46
55
  ```
47
56
 
48
57
  ## API
@@ -52,6 +61,10 @@ const restored = migration.put(modifiedView, complement);
52
61
  | Export | Description |
53
62
  |--------|-------------|
54
63
  | `Panproto` | Main entry point; call `Panproto.init()` to load the WASM module |
64
+ | `Panproto.convert()` | One-liner data conversion between two schemas via auto-generated protolens |
65
+ | `Panproto.lens()` | Auto-generate a lens between two schemas |
66
+ | `Panproto.protolensChain()` | Build a reusable, schema-independent protolens chain |
67
+ | `Panproto.factorizeMorphism()` | Decompose a theory morphism into elementary endofunctors |
55
68
  | `Protocol` | Protocol handle with schema builder factory |
56
69
  | `SchemaBuilder` / `BuiltSchema` | Fluent schema construction |
57
70
  | `MigrationBuilder` / `CompiledMigration` | Migration construction, compilation, and application |
@@ -59,13 +72,22 @@ const restored = migration.put(modifiedView, complement);
59
72
  | `IoRegistry` | Protocol-aware parse/emit for all 76 formats |
60
73
  | `Repository` | Schematic version control (init, commit, branch, merge) |
61
74
 
62
- ### Lens combinators
75
+ ### Protolenses
63
76
 
64
77
  | Export | Description |
65
78
  |--------|-------------|
66
- | `renameField` / `addField` / `removeField` | Field-level transformations |
67
- | `wrapInObject` / `hoistField` / `coerceType` | Structural transformations |
68
- | `compose` / `pipeline` | Cambria-style combinator composition |
79
+ | `LensHandle` | Lens with `get`, `put`, and `autoGenerate()` for automatic lens derivation |
80
+ | `LensHandle.autoGenerate()` | Auto-generate a lens between two schemas |
81
+ | `ProtolensChainHandle` | Reusable, schema-independent protolens chain with `apply` and `instantiate` |
82
+ | `ProtolensChainHandle.fuse()` | Fuse chain into single step |
83
+ | `ProtolensChainHandle.checkApplicability()` | Check applicability with reasons |
84
+ | `ProtolensChainHandle.applyToFleet()` | Apply to multiple schemas |
85
+ | `ProtolensChainHandle.lift()` | Lift along theory morphism |
86
+ | `ProtolensChainHandle.fromJson()` | Deserialize from JSON |
87
+ | `SymmetricLensHandle` | Symmetric (bidirectional) lens for two-way synchronization |
88
+ | `DataSetHandle` | Handle to versioned data set with migrate/staleness methods |
89
+ | `Panproto.dataSet()` | Store and track a data set |
90
+ | `Panproto.migrateData()` | Migrate data between schemas |
69
91
 
70
92
  ### Breaking change analysis
71
93
 
@@ -0,0 +1,58 @@
1
+ import { CoverageReport, OpticKind } from './types.js';
2
+ import { BuiltSchema } from './schema.js';
3
+ import { CompiledMigration } from './migration.js';
4
+ import { ProtolensChainHandle } from './lens.js';
5
+ import { Panproto } from './panproto.js';
6
+ /**
7
+ * Migration analysis utilities for dry-run testing and optic classification.
8
+ *
9
+ * Wraps a `Panproto` instance and provides coverage analysis for migrations
10
+ * and optic kind classification for protolens chains.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const panproto = await Panproto.init();
15
+ * const analysis = new MigrationAnalysis(panproto);
16
+ *
17
+ * const report = analysis.dryRun(compiled, records, srcSchema, tgtSchema);
18
+ * console.log(`Coverage: ${(report.coverageRatio * 100).toFixed(1)}%`);
19
+ *
20
+ * const chain = panproto.protolensChain(srcSchema, tgtSchema);
21
+ * const kind = analysis.opticKind(chain, srcSchema);
22
+ * ```
23
+ */
24
+ export declare class MigrationAnalysis {
25
+ #private;
26
+ /**
27
+ * Create a new migration analysis instance.
28
+ *
29
+ * @param panproto - The Panproto instance providing WASM access
30
+ */
31
+ constructor(panproto: Panproto);
32
+ /**
33
+ * Run a dry-run migration and return a coverage report.
34
+ *
35
+ * Tests each instance record against the compiled migration without
36
+ * persisting results, producing detailed failure information for
37
+ * records that cannot be migrated.
38
+ *
39
+ * @param compiled - The compiled migration to test
40
+ * @param instances - Array of instance records (plain objects)
41
+ * @param srcSchema - The source schema the instances conform to
42
+ * @param tgtSchema - The target schema
43
+ * @returns A coverage report with per-record success/failure data
44
+ */
45
+ dryRun(compiled: CompiledMigration, instances: unknown[], srcSchema: BuiltSchema, tgtSchema: BuiltSchema): CoverageReport;
46
+ /**
47
+ * Classify the optic kind of a protolens chain.
48
+ *
49
+ * Determines whether the chain represents an isomorphism, lens, prism,
50
+ * affine transformation, or traversal based on its complement structure.
51
+ *
52
+ * @param chain - The protolens chain to classify
53
+ * @param schema - The schema to check the chain against
54
+ * @returns The optic kind classification
55
+ */
56
+ opticKind(chain: ProtolensChainHandle, schema: BuiltSchema): OpticKind;
57
+ }
58
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,cAAc,EAGd,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAuJ9C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,iBAAiB;;IAG5B;;;;OAIG;gBACS,QAAQ,EAAE,QAAQ;IAI9B;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,QAAQ,EAAE,iBAAiB,EAC3B,SAAS,EAAE,OAAO,EAAE,EACpB,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,WAAW,GACrB,cAAc;IAIjB;;;;;;;;;OASG;IACH,SAAS,CAAC,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS;CAGvE"}
package/dist/data.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { WasmModule } from './types.js';
2
+ import { WasmHandle } from './wasm.js';
3
+ import { BuiltSchema } from './schema.js';
4
+ /** A handle to a versioned data set in the WASM store. */
5
+ export declare class DataSetHandle implements Disposable {
6
+ #private;
7
+ constructor(handle: WasmHandle, wasm: WasmModule);
8
+ /** The WASM handle for this data set. Internal use only. */
9
+ get _handle(): WasmHandle;
10
+ /** Store a data set from a JavaScript object, bound to a schema. */
11
+ static fromData(data: unknown, schema: BuiltSchema, wasm: WasmModule): DataSetHandle;
12
+ /** Retrieve the data as MessagePack-encoded bytes. */
13
+ getData(): unknown;
14
+ /** Migrate this data set forward to a new schema. */
15
+ migrateForward(srcSchema: BuiltSchema, tgtSchema: BuiltSchema): MigrationResult;
16
+ /** Migrate this data set backward using a complement. */
17
+ migrateBackward(complement: Uint8Array, srcSchema: BuiltSchema, tgtSchema: BuiltSchema): DataSetHandle;
18
+ /** Check if this data set is stale relative to a schema. */
19
+ isStale(schema: BuiltSchema): StalenessResult;
20
+ [Symbol.dispose](): void;
21
+ }
22
+ /** Result of a forward data migration. */
23
+ export interface MigrationResult {
24
+ /** The migrated data set at the target schema. */
25
+ readonly data: DataSetHandle;
26
+ /** The complement bytes needed for backward migration. */
27
+ readonly complement: Uint8Array;
28
+ }
29
+ /** Result of a staleness check. */
30
+ export interface StalenessResult {
31
+ /** Whether the data set is stale relative to the target schema. */
32
+ readonly stale: boolean;
33
+ /** The schema ID the data was written against. */
34
+ readonly dataSchemaId: string;
35
+ /** The schema ID being compared to. */
36
+ readonly targetSchemaId: string;
37
+ }
38
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AAC;CACjC"}
@@ -0,0 +1,146 @@
1
+ import { Expr, ConflictStrategy, EnrichmentSummary } from './types.js';
2
+ import { BuiltSchema } from './schema.js';
3
+ /**
4
+ * An individual default enrichment entry.
5
+ *
6
+ * Binds a default expression to a vertex, used when forward migration
7
+ * encounters a missing value.
8
+ */
9
+ interface DefaultEntry {
10
+ readonly vertex: string;
11
+ readonly expr: Expr;
12
+ }
13
+ /**
14
+ * An individual coercion enrichment entry.
15
+ *
16
+ * Defines how to convert values from one kind to another.
17
+ */
18
+ interface CoercionEntry {
19
+ readonly from: string;
20
+ readonly to: string;
21
+ readonly expr: Expr;
22
+ }
23
+ /**
24
+ * An individual merger enrichment entry.
25
+ *
26
+ * Defines how to merge two values at a given vertex during conflict resolution.
27
+ */
28
+ interface MergerEntry {
29
+ readonly vertex: string;
30
+ readonly expr: Expr;
31
+ }
32
+ /**
33
+ * An individual conflict policy enrichment entry.
34
+ *
35
+ * Determines the strategy for resolving conflicts at a vertex.
36
+ */
37
+ interface PolicyEntry {
38
+ readonly vertex: string;
39
+ readonly strategy: ConflictStrategy;
40
+ }
41
+ /**
42
+ * Immutable fluent builder for enriching a schema with default expressions,
43
+ * coercion functions, merge strategies, and conflict policies.
44
+ *
45
+ * Each mutation method returns a new `SchemaEnrichment` instance,
46
+ * leaving the original unchanged.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { SchemaEnrichment } from '@panproto/core';
51
+ * import { ExprBuilder } from '@panproto/core';
52
+ *
53
+ * const enriched = new SchemaEnrichment(schema)
54
+ * .addDefault('post:title', ExprBuilder.lit({ type: 'str', value: 'Untitled' }))
55
+ * .addCoercion('int', 'float', ExprBuilder.builtin('IntToFloat', ExprBuilder.var_('x')))
56
+ * .addPolicy('post:body', { type: 'keep_left' })
57
+ * .build();
58
+ * ```
59
+ */
60
+ export declare class SchemaEnrichment {
61
+ #private;
62
+ constructor(schema: BuiltSchema, defaults?: readonly DefaultEntry[], coercions?: readonly CoercionEntry[], mergers?: readonly MergerEntry[], policies?: readonly PolicyEntry[]);
63
+ /**
64
+ * Add a default expression for a vertex.
65
+ *
66
+ * The expression is evaluated when forward migration encounters a
67
+ * missing value at the given vertex.
68
+ *
69
+ * @param vertex - The vertex identifier to attach the default to
70
+ * @param expr - The default expression
71
+ * @returns A new enrichment with the default added
72
+ * @throws {@link PanprotoError} if the vertex is not in the schema
73
+ */
74
+ addDefault(vertex: string, expr: Expr): SchemaEnrichment;
75
+ /**
76
+ * Add a coercion function between two value kinds.
77
+ *
78
+ * The expression defines how to convert values from `fromKind` to
79
+ * `toKind`. It receives a single argument (the source value) and
80
+ * must produce a value of the target kind.
81
+ *
82
+ * @param fromKind - Source value kind (e.g., 'int')
83
+ * @param toKind - Target value kind (e.g., 'float')
84
+ * @param expr - The coercion expression
85
+ * @returns A new enrichment with the coercion added
86
+ * @throws {@link PanprotoError} if a coercion for this pair already exists
87
+ */
88
+ addCoercion(fromKind: string, toKind: string, expr: Expr): SchemaEnrichment;
89
+ /**
90
+ * Add a merger expression for a vertex.
91
+ *
92
+ * The expression defines how to merge two conflicting values at the
93
+ * given vertex. It receives two arguments (left and right values)
94
+ * and must produce a single merged value.
95
+ *
96
+ * @param vertex - The vertex identifier to attach the merger to
97
+ * @param expr - The merger expression
98
+ * @returns A new enrichment with the merger added
99
+ * @throws {@link PanprotoError} if the vertex is not in the schema
100
+ */
101
+ addMerger(vertex: string, expr: Expr): SchemaEnrichment;
102
+ /**
103
+ * Add a conflict resolution policy for a vertex.
104
+ *
105
+ * @param vertex - The vertex identifier
106
+ * @param strategy - The conflict resolution strategy
107
+ * @returns A new enrichment with the policy added
108
+ * @throws {@link PanprotoError} if the vertex is not in the schema
109
+ */
110
+ addPolicy(vertex: string, strategy: ConflictStrategy): SchemaEnrichment;
111
+ /**
112
+ * Remove the default expression for a vertex.
113
+ *
114
+ * @param vertex - The vertex identifier
115
+ * @returns A new enrichment with the default removed
116
+ * @throws {@link PanprotoError} if no default exists for the vertex
117
+ */
118
+ removeDefault(vertex: string): SchemaEnrichment;
119
+ /**
120
+ * Remove the coercion function for a value kind pair.
121
+ *
122
+ * @param fromKind - Source value kind
123
+ * @param toKind - Target value kind
124
+ * @returns A new enrichment with the coercion removed
125
+ * @throws {@link PanprotoError} if no coercion exists for the pair
126
+ */
127
+ removeCoercion(fromKind: string, toKind: string): SchemaEnrichment;
128
+ /**
129
+ * List all enrichments currently attached.
130
+ *
131
+ * @returns An enrichment summary with defaults, coercions, mergers, and policies
132
+ */
133
+ listEnrichments(): EnrichmentSummary;
134
+ /**
135
+ * Build the enriched schema.
136
+ *
137
+ * Returns a new `BuiltSchema` with the enrichments recorded in the
138
+ * schema data. The underlying WASM handle is shared with the original
139
+ * schema (enrichments are metadata that the SDK tracks client-side).
140
+ *
141
+ * @returns A new BuiltSchema with enrichment metadata
142
+ */
143
+ build(): BuiltSchema;
144
+ }
145
+ export {};
146
+ //# sourceMappingURL=enrichment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enrichment.d.ts","sourceRoot":"","sources":["../src/enrichment.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,UAAU,YAAY;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED;;;;GAIG;AACH,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED;;;;GAIG;AACH,UAAU,WAAW;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED;;;;GAIG;AACH,UAAU,WAAW;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAgB;;gBAQzB,MAAM,EAAE,WAAW,EACnB,QAAQ,GAAE,SAAS,YAAY,EAAO,EACtC,SAAS,GAAE,SAAS,aAAa,EAAO,EACxC,OAAO,GAAE,SAAS,WAAW,EAAO,EACpC,QAAQ,GAAE,SAAS,WAAW,EAAO;IASvC;;;;;;;;;;OAUG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,gBAAgB;IAkBxD;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,gBAAgB;IAgB3E;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,gBAAgB;IAkBvD;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,gBAAgB;IAkBvE;;;;;;OAMG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAiB/C;;;;;;;OAOG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAmBlE;;;;OAIG;IACH,eAAe,IAAI,iBAAiB;IASpC;;;;;;;;OAQG;IACH,KAAK,IAAI,WAAW;CAyErB"}
package/dist/expr.d.ts ADDED
@@ -0,0 +1,145 @@
1
+ import { Expr, Literal, Pattern, BuiltinOp } from './types.js';
2
+ /**
3
+ * Static factory for constructing expression AST nodes.
4
+ *
5
+ * All methods return immutable {@link Expr} values suitable for use in
6
+ * schema enrichments, directed equations, and conflict policies.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { ExprBuilder as E } from '@panproto/core';
11
+ *
12
+ * // Lambda that adds 1 to its argument
13
+ * const addOne = E.lam('x', E.add(E.var_('x'), E.lit({ type: 'int', value: 1 })));
14
+ *
15
+ * // Record literal
16
+ * const record = E.record({ name: E.lit({ type: 'str', value: 'default' }) });
17
+ * ```
18
+ */
19
+ export declare class ExprBuilder {
20
+ /** This class is not instantiable; all methods are static. */
21
+ private constructor();
22
+ /**
23
+ * Create a variable reference expression.
24
+ *
25
+ * @param name - The variable name to reference
26
+ * @returns A variable expression node
27
+ */
28
+ static var_(name: string): Expr;
29
+ /**
30
+ * Create a literal expression.
31
+ *
32
+ * @param value - The literal value
33
+ * @returns A literal expression node
34
+ */
35
+ static lit(value: Literal): Expr;
36
+ /**
37
+ * Create a lambda (anonymous function) expression.
38
+ *
39
+ * @param param - The parameter name
40
+ * @param body - The function body expression
41
+ * @returns A lambda expression node
42
+ */
43
+ static lam(param: string, body: Expr): Expr;
44
+ /**
45
+ * Create a function application expression.
46
+ *
47
+ * When multiple arguments are provided, they are applied left-to-right
48
+ * via currying: `app(f, a, b)` becomes `app(app(f, a), b)`.
49
+ *
50
+ * @param func - The function expression
51
+ * @param args - One or more argument expressions
52
+ * @returns An application expression node (possibly nested)
53
+ */
54
+ static app(func: Expr, ...args: Expr[]): Expr;
55
+ /**
56
+ * Create a let-binding expression.
57
+ *
58
+ * Binds `value` to `name` in the scope of `body`.
59
+ *
60
+ * @param name - The variable name to bind
61
+ * @param value - The value expression to bind
62
+ * @param body - The body expression where the binding is in scope
63
+ * @returns A let expression node
64
+ */
65
+ static let_(name: string, value: Expr, body: Expr): Expr;
66
+ /**
67
+ * Create a field access expression.
68
+ *
69
+ * @param expr - The record expression to access
70
+ * @param name - The field name
71
+ * @returns A field access expression node
72
+ */
73
+ static field(expr: Expr, name: string): Expr;
74
+ /**
75
+ * Create a record literal expression.
76
+ *
77
+ * @param fields - A mapping of field names to expressions
78
+ * @returns A record expression node
79
+ */
80
+ static record(fields: Record<string, Expr>): Expr;
81
+ /**
82
+ * Create a list literal expression.
83
+ *
84
+ * @param items - The list element expressions
85
+ * @returns A list expression node
86
+ */
87
+ static list(...items: Expr[]): Expr;
88
+ /**
89
+ * Create a pattern-match expression.
90
+ *
91
+ * @param scrutinee - The expression to match against
92
+ * @param arms - Pattern-expression pairs tried in order
93
+ * @returns A match expression node
94
+ */
95
+ static match_(scrutinee: Expr, arms: [Pattern, Expr][]): Expr;
96
+ /**
97
+ * Create a builtin operation expression.
98
+ *
99
+ * @param op - The builtin operation name
100
+ * @param args - Argument expressions for the operation
101
+ * @returns A builtin expression node
102
+ */
103
+ static builtin(op: BuiltinOp, ...args: Expr[]): Expr;
104
+ /**
105
+ * Create an index expression for list or record access.
106
+ *
107
+ * @param expr - The collection expression
108
+ * @param index - The index expression
109
+ * @returns An index expression node
110
+ */
111
+ static index(expr: Expr, index: Expr): Expr;
112
+ /**
113
+ * Add two expressions.
114
+ *
115
+ * @param a - Left operand
116
+ * @param b - Right operand
117
+ * @returns A builtin 'Add' expression
118
+ */
119
+ static add(a: Expr, b: Expr): Expr;
120
+ /**
121
+ * Subtract two expressions.
122
+ *
123
+ * @param a - Left operand
124
+ * @param b - Right operand
125
+ * @returns A builtin 'Sub' expression
126
+ */
127
+ static sub(a: Expr, b: Expr): Expr;
128
+ /**
129
+ * Multiply two expressions.
130
+ *
131
+ * @param a - Left operand
132
+ * @param b - Right operand
133
+ * @returns A builtin 'Mul' expression
134
+ */
135
+ static mul(a: Expr, b: Expr): Expr;
136
+ /**
137
+ * Concatenate two expressions (strings or lists).
138
+ *
139
+ * @param a - Left operand
140
+ * @param b - Right operand
141
+ * @returns A builtin 'Concat' expression
142
+ */
143
+ static concat(a: Expr, b: Expr): Expr;
144
+ }
145
+ //# sourceMappingURL=expr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../src/expr.ts"],"names":[],"mappings":"AAAA;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pD;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI;IAQ3C;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI;IAIlC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI;IAIlC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI;IAIlC;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI;CAGtC"}
package/dist/gat.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { WasmModule, TheorySpec, TheoryMorphism, MorphismCheckResult } from './types.js';
2
2
  import { WasmHandle } from './wasm.js';
3
+ import { ElementaryStep } from './protolens.js';
3
4
  /**
4
5
  * A disposable handle to a WASM-side Theory resource.
5
6
  *
@@ -96,4 +97,19 @@ export declare function checkMorphism(morphism: TheoryMorphism, domain: TheoryHa
96
97
  * @returns Reindexed sort interpretations
97
98
  */
98
99
  export declare function migrateModel(sortInterp: Record<string, unknown[]>, morphism: TheoryMorphism, wasm: WasmModule): Record<string, unknown[]>;
100
+ /**
101
+ * Factorize a morphism into elementary steps.
102
+ *
103
+ * Decomposes a theory morphism into a sequence of elementary schema
104
+ * transformations (renames, additions, removals, etc.) suitable for
105
+ * constructing protolens chains.
106
+ *
107
+ * @param morphismBytes - MessagePack-encoded morphism data
108
+ * @param domain - Handle to the domain theory
109
+ * @param codomain - Handle to the codomain theory
110
+ * @param wasm - The WASM module
111
+ * @returns A sequence of elementary steps
112
+ * @throws {@link WasmError} if factorization fails
113
+ */
114
+ export declare function factorizeMorphism(morphismBytes: Uint8Array, domain: TheoryHandle, codomain: TheoryHandle, wasm: WasmModule): ElementaryStep[];
99
115
  //# sourceMappingURL=gat.d.ts.map
package/dist/gat.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"gat.d.ts","sourceRoot":"","sources":["../src/gat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,cAAc,EACd,mBAAmB,EAIpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAGrD;;;;GAIG;AACH,qBAAa,YAAa,YAAW,UAAU;;IAE7C,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;gBAEf,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU;IAKhD,0CAA0C;IAC1C,IAAI,OAAO,IAAI,UAAU,CAExB;IAED,6CAA6C;IAC7C,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;;gBAOZ,IAAI,EAAE,MAAM;IAQxB,wDAAwD;IACxD,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKjC,yCAAyC;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKxB,4CAA4C;IAC5C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI;IAK3E,wBAAwB;IACxB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAKlE,+BAA+B;IAC/B,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,OAA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