@panproto/core 0.6.0 → 0.7.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
 
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":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,0DAA0D;AAC1D,qBAAa,aAAc,YAAW,UAAU;;gBAIlC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU;IAKhD,4DAA4D;IAC5D,IAAI,OAAO,IAAI,UAAU,CAExB;IAED,oEAAoE;IACpE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,aAAa;IAMpF,sDAAsD;IACtD,OAAO,IAAI,OAAO;IAKlB,qDAAqD;IACrD,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,GAAG,eAAe;IAmB/E,yDAAyD;IACzD,eAAe,CACb,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,WAAW,GACrB,aAAa;IAUhB,4DAA4D;IAC5D,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,eAAe;IAiB7C,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB;AAED,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CACjC;AAED,mCAAmC;AACnC,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,kDAAkD;IAClD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,uCAAuC;IACvC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC"}
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 C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