@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/dist/index.cjs CHANGED
@@ -71,7 +71,21 @@ async function loadWasm(input) {
71
71
  get_json: glue.get_json,
72
72
  put_json: glue.put_json,
73
73
  instance_element_count: glue.instance_element_count,
74
- lens_from_combinators: glue.lens_from_combinators,
74
+ auto_generate_protolens: glue.auto_generate_protolens,
75
+ instantiate_protolens: glue.instantiate_protolens,
76
+ protolens_complement_spec: glue.protolens_complement_spec,
77
+ protolens_from_diff: glue.protolens_from_diff,
78
+ protolens_compose: glue.protolens_compose,
79
+ protolens_chain_to_json: glue.protolens_chain_to_json,
80
+ factorize_morphism: glue.factorize_morphism,
81
+ symmetric_lens_from_schemas: glue.symmetric_lens_from_schemas,
82
+ symmetric_lens_sync: glue.symmetric_lens_sync,
83
+ apply_protolens_step: glue.apply_protolens_step,
84
+ protolens_from_json: glue.protolens_from_json,
85
+ protolens_fuse: glue.protolens_fuse,
86
+ protolens_lift: glue.protolens_lift,
87
+ protolens_check_applicability: glue.protolens_check_applicability,
88
+ protolens_fleet: glue.protolens_fleet,
75
89
  check_lens_laws: glue.check_lens_laws,
76
90
  check_get_put: glue.check_get_put,
77
91
  check_put_get: glue.check_put_get,
@@ -97,7 +111,16 @@ async function loadWasm(input) {
97
111
  vcs_merge: glue.vcs_merge,
98
112
  vcs_stash: glue.vcs_stash,
99
113
  vcs_stash_pop: glue.vcs_stash_pop,
100
- vcs_blame: glue.vcs_blame
114
+ vcs_blame: glue.vcs_blame,
115
+ // Phase 7: Data versioning
116
+ store_dataset: glue.store_dataset,
117
+ get_dataset: glue.get_dataset,
118
+ migrate_dataset_forward: glue.migrate_dataset_forward,
119
+ migrate_dataset_backward: glue.migrate_dataset_backward,
120
+ check_dataset_staleness: glue.check_dataset_staleness,
121
+ store_protocol_definition: glue.store_protocol_definition,
122
+ get_protocol_definition: glue.get_protocol_definition,
123
+ get_migration_complement: glue.get_migration_complement
101
124
  };
102
125
  const memory = initOutput.memory;
103
126
  if (!memory) {
@@ -171,30 +194,212 @@ function packMigrationMapping(mapping) {
171
194
  hyper_resolver: []
172
195
  });
173
196
  }
174
- function renameField(oldName, newName) {
175
- return { type: "rename-field", old: oldName, new: newName };
176
- }
177
- function addField(name, vertexKind, defaultValue) {
178
- return { type: "add-field", name, vertexKind, default: defaultValue };
179
- }
180
- function removeField(name) {
181
- return { type: "remove-field", name };
182
- }
183
- function wrapInObject(fieldName) {
184
- return { type: "wrap-in-object", fieldName };
185
- }
186
- function hoistField(host, field) {
187
- return { type: "hoist-field", host, field };
188
- }
189
- function coerceType(fromKind, toKind) {
190
- return { type: "coerce-type", fromKind, toKind };
191
- }
192
- function compose(first, second) {
193
- return { type: "compose", first, second };
194
- }
195
- function pipeline(combinators) {
196
- const [first, ...rest] = combinators;
197
- return rest.reduce((acc, c) => compose(acc, c), first);
197
+ class ProtolensChainHandle {
198
+ #handle;
199
+ #wasm;
200
+ constructor(handle, wasm) {
201
+ this.#handle = handle;
202
+ this.#wasm = wasm;
203
+ }
204
+ /** The underlying WASM handle. Internal use only. */
205
+ get _handle() {
206
+ return this.#handle;
207
+ }
208
+ /**
209
+ * Auto-generate a protolens chain between two schemas.
210
+ *
211
+ * @param schema1 - The source schema
212
+ * @param schema2 - The target schema
213
+ * @param wasm - The WASM module
214
+ * @returns A ProtolensChainHandle wrapping the generated chain
215
+ * @throws {@link WasmError} if the WASM call fails
216
+ */
217
+ static autoGenerate(schema1, schema2, wasm) {
218
+ try {
219
+ const rawHandle = wasm.exports.auto_generate_protolens(schema1._handle.id, schema2._handle.id);
220
+ return new ProtolensChainHandle(createHandle(rawHandle, wasm), wasm);
221
+ } catch (error) {
222
+ throw new WasmError(
223
+ `auto_generate_protolens failed: ${error instanceof Error ? error.message : String(error)}`,
224
+ { cause: error }
225
+ );
226
+ }
227
+ }
228
+ /**
229
+ * Instantiate this protolens chain against a concrete schema.
230
+ *
231
+ * @param schema - The schema to instantiate against
232
+ * @returns A LensHandle for the instantiated lens
233
+ * @throws {@link WasmError} if the WASM call fails
234
+ */
235
+ instantiate(schema) {
236
+ try {
237
+ const rawHandle = this.#wasm.exports.instantiate_protolens(this.#handle.id, schema._handle.id);
238
+ return new LensHandle(createHandle(rawHandle, this.#wasm), this.#wasm);
239
+ } catch (error) {
240
+ throw new WasmError(
241
+ `instantiate_protolens failed: ${error instanceof Error ? error.message : String(error)}`,
242
+ { cause: error }
243
+ );
244
+ }
245
+ }
246
+ /**
247
+ * Get the complement specification for instantiation against a schema.
248
+ *
249
+ * @param schema - The schema to check requirements against
250
+ * @returns The complement spec describing defaults and captured data
251
+ * @throws {@link WasmError} if the WASM call fails
252
+ */
253
+ requirements(schema) {
254
+ try {
255
+ const bytes = this.#wasm.exports.protolens_complement_spec(this.#handle.id, schema._handle.id);
256
+ return unpackFromWasm(bytes);
257
+ } catch (error) {
258
+ throw new WasmError(
259
+ `protolens_complement_spec failed: ${error instanceof Error ? error.message : String(error)}`,
260
+ { cause: error }
261
+ );
262
+ }
263
+ }
264
+ /**
265
+ * Compose this chain with another protolens chain.
266
+ *
267
+ * @param other - The chain to compose with (applied second)
268
+ * @returns A new ProtolensChainHandle for the composed chain
269
+ * @throws {@link WasmError} if the WASM call fails
270
+ */
271
+ compose(other) {
272
+ try {
273
+ const rawHandle = this.#wasm.exports.protolens_compose(this.#handle.id, other.#handle.id);
274
+ return new ProtolensChainHandle(createHandle(rawHandle, this.#wasm), this.#wasm);
275
+ } catch (error) {
276
+ throw new WasmError(
277
+ `protolens_compose failed: ${error instanceof Error ? error.message : String(error)}`,
278
+ { cause: error }
279
+ );
280
+ }
281
+ }
282
+ /**
283
+ * Serialize this chain to a JSON string.
284
+ *
285
+ * @returns A JSON representation of the chain
286
+ * @throws {@link WasmError} if the WASM call fails
287
+ */
288
+ toJson() {
289
+ try {
290
+ const bytes = this.#wasm.exports.protolens_chain_to_json(this.#handle.id);
291
+ return new TextDecoder().decode(bytes);
292
+ } catch (error) {
293
+ throw new WasmError(
294
+ `protolens_chain_to_json failed: ${error instanceof Error ? error.message : String(error)}`,
295
+ { cause: error }
296
+ );
297
+ }
298
+ }
299
+ /**
300
+ * Deserialize a protolens chain from JSON via WASM.
301
+ *
302
+ * @param json - JSON string representing a protolens chain
303
+ * @param wasm - The WASM module
304
+ * @returns A ProtolensChainHandle wrapping the deserialized chain
305
+ * @throws {@link WasmError} if the WASM call fails or JSON is invalid
306
+ */
307
+ static fromJson(json, wasm) {
308
+ try {
309
+ const jsonBytes = new TextEncoder().encode(json);
310
+ const rawHandle = wasm.exports.protolens_from_json(jsonBytes);
311
+ return new ProtolensChainHandle(createHandle(rawHandle, wasm), wasm);
312
+ } catch (error) {
313
+ throw new WasmError(
314
+ `protolens_from_json failed: ${error instanceof Error ? error.message : String(error)}`,
315
+ { cause: error }
316
+ );
317
+ }
318
+ }
319
+ /**
320
+ * Fuse this chain into a single protolens step.
321
+ *
322
+ * Composes all steps into a single step with a composite complement,
323
+ * avoiding intermediate schema materialization.
324
+ *
325
+ * @returns A new ProtolensChainHandle containing the fused step
326
+ * @throws {@link WasmError} if the WASM call fails
327
+ */
328
+ fuse() {
329
+ try {
330
+ const rawHandle = this.#wasm.exports.protolens_fuse(this.#handle.id);
331
+ return new ProtolensChainHandle(createHandle(rawHandle, this.#wasm), this.#wasm);
332
+ } catch (error) {
333
+ throw new WasmError(
334
+ `protolens_fuse failed: ${error instanceof Error ? error.message : String(error)}`,
335
+ { cause: error }
336
+ );
337
+ }
338
+ }
339
+ /**
340
+ * Check whether this chain can be instantiated at a given schema.
341
+ *
342
+ * @param schema - The schema to check against
343
+ * @returns An object with `applicable` boolean and `reasons` array
344
+ * @throws {@link WasmError} if the WASM call fails
345
+ */
346
+ checkApplicability(schema) {
347
+ try {
348
+ const bytes = this.#wasm.exports.protolens_check_applicability(this.#handle.id, schema._handle.id);
349
+ return unpackFromWasm(bytes);
350
+ } catch (error) {
351
+ throw new WasmError(
352
+ `protolens_check_applicability failed: ${error instanceof Error ? error.message : String(error)}`,
353
+ { cause: error }
354
+ );
355
+ }
356
+ }
357
+ /**
358
+ * Lift this chain along a theory morphism.
359
+ *
360
+ * Given a morphism between theories, produces a new chain that operates
361
+ * on schemas of the codomain theory instead of the domain theory.
362
+ *
363
+ * @param morphismBytes - MessagePack-encoded theory morphism
364
+ * @returns A new ProtolensChainHandle for the lifted chain
365
+ * @throws {@link WasmError} if the WASM call fails
366
+ */
367
+ lift(morphismBytes) {
368
+ try {
369
+ const rawHandle = this.#wasm.exports.protolens_lift(this.#handle.id, morphismBytes);
370
+ return new ProtolensChainHandle(createHandle(rawHandle, this.#wasm), this.#wasm);
371
+ } catch (error) {
372
+ throw new WasmError(
373
+ `protolens_lift failed: ${error instanceof Error ? error.message : String(error)}`,
374
+ { cause: error }
375
+ );
376
+ }
377
+ }
378
+ /**
379
+ * Apply this chain to a fleet of schemas.
380
+ *
381
+ * Checks applicability and instantiates the chain against each schema.
382
+ *
383
+ * @param schemas - Array of schema handles to apply the chain to
384
+ * @returns Fleet result with applied/skipped schema names and reasons
385
+ * @throws {@link WasmError} if the WASM call fails
386
+ */
387
+ applyToFleet(schemas) {
388
+ try {
389
+ const handles = new Uint32Array(schemas.map((s) => s._handle.id));
390
+ const bytes = this.#wasm.exports.protolens_fleet(this.#handle.id, handles);
391
+ return unpackFromWasm(bytes);
392
+ } catch (error) {
393
+ throw new WasmError(
394
+ `protolens_fleet failed: ${error instanceof Error ? error.message : String(error)}`,
395
+ { cause: error }
396
+ );
397
+ }
398
+ }
399
+ /** Release the underlying WASM resource. */
400
+ [Symbol.dispose]() {
401
+ this.#handle[Symbol.dispose]();
402
+ }
198
403
  }
199
404
  class LensHandle {
200
405
  #handle;
@@ -207,6 +412,53 @@ class LensHandle {
207
412
  get _handle() {
208
413
  return this.#handle;
209
414
  }
415
+ /**
416
+ * Auto-generate a lens between two schemas.
417
+ *
418
+ * Generates a protolens chain and immediately instantiates it.
419
+ *
420
+ * @param schema1 - The source schema
421
+ * @param schema2 - The target schema
422
+ * @param wasm - The WASM module
423
+ * @returns A LensHandle wrapping the generated lens
424
+ * @throws {@link WasmError} if the WASM call fails
425
+ */
426
+ static autoGenerate(schema1, schema2, wasm) {
427
+ try {
428
+ const rawHandle = wasm.exports.auto_generate_protolens(schema1._handle.id, schema2._handle.id);
429
+ const chainHandle = createHandle(rawHandle, wasm);
430
+ const lensRaw = wasm.exports.instantiate_protolens(chainHandle.id, schema1._handle.id);
431
+ chainHandle[Symbol.dispose]();
432
+ const handle = createHandle(lensRaw, wasm);
433
+ return new LensHandle(handle, wasm);
434
+ } catch (error) {
435
+ throw new WasmError(
436
+ `autoGenerate failed: ${error instanceof Error ? error.message : String(error)}`,
437
+ { cause: error }
438
+ );
439
+ }
440
+ }
441
+ /**
442
+ * Create a lens by instantiating a protolens chain against a schema.
443
+ *
444
+ * @param chain - The protolens chain to instantiate
445
+ * @param schema - The schema to instantiate against
446
+ * @param wasm - The WASM module
447
+ * @returns A LensHandle wrapping the instantiated lens
448
+ * @throws {@link WasmError} if the WASM call fails
449
+ */
450
+ static fromChain(chain, schema, wasm) {
451
+ try {
452
+ const rawHandle = wasm.exports.instantiate_protolens(chain._handle.id, schema._handle.id);
453
+ const handle = createHandle(rawHandle, wasm);
454
+ return new LensHandle(handle, wasm);
455
+ } catch (error) {
456
+ throw new WasmError(
457
+ `fromChain failed: ${error instanceof Error ? error.message : String(error)}`,
458
+ { cause: error }
459
+ );
460
+ }
461
+ }
210
462
  /**
211
463
  * Forward projection: extract the view from a record.
212
464
  *
@@ -324,40 +576,74 @@ class LensHandle {
324
576
  this.#handle[Symbol.dispose]();
325
577
  }
326
578
  }
327
- function fromCombinators(schema, protocol, wasm, ...combinators) {
328
- const wireCombs = combinators.map(combinatorToWire);
329
- const combBytes = packToWasm(wireCombs);
330
- try {
331
- const rawHandle = wasm.exports.lens_from_combinators(
332
- schema._handle.id,
333
- protocol._handle.id,
334
- combBytes
335
- );
336
- const handle = createHandle(rawHandle, wasm);
337
- return new LensHandle(handle, wasm);
338
- } catch (error) {
339
- throw new WasmError(
340
- `lens_from_combinators failed: ${error instanceof Error ? error.message : String(error)}`,
341
- { cause: error }
342
- );
579
+ class SymmetricLensHandle {
580
+ #handle;
581
+ #wasm;
582
+ constructor(handle, wasm) {
583
+ this.#handle = handle;
584
+ this.#wasm = wasm;
343
585
  }
344
- }
345
- function combinatorToWire(combinator) {
346
- switch (combinator.type) {
347
- case "rename-field":
348
- return { RenameField: { old: combinator.old, new: combinator.new } };
349
- case "add-field":
350
- return { AddField: { name: combinator.name, vertex_kind: combinator.vertexKind, default: combinator.default } };
351
- case "remove-field":
352
- return { RemoveField: { name: combinator.name } };
353
- case "wrap-in-object":
354
- return { WrapInObject: { field_name: combinator.fieldName } };
355
- case "hoist-field":
356
- return { HoistField: { host: combinator.host, field: combinator.field } };
357
- case "coerce-type":
358
- return { CoerceType: { from_kind: combinator.fromKind, to_kind: combinator.toKind } };
359
- case "compose":
360
- return { Compose: [combinatorToWire(combinator.first), combinatorToWire(combinator.second)] };
586
+ /**
587
+ * Create a symmetric lens between two schemas.
588
+ *
589
+ * @param schema1 - The left schema
590
+ * @param schema2 - The right schema
591
+ * @param wasm - The WASM module
592
+ * @returns A SymmetricLensHandle for bidirectional sync
593
+ * @throws {@link WasmError} if the WASM call fails
594
+ */
595
+ static fromSchemas(schema1, schema2, wasm) {
596
+ try {
597
+ const rawHandle = wasm.exports.symmetric_lens_from_schemas(schema1._handle.id, schema2._handle.id);
598
+ return new SymmetricLensHandle(createHandle(rawHandle, wasm), wasm);
599
+ } catch (error) {
600
+ throw new WasmError(
601
+ `symmetric_lens_from_schemas failed: ${error instanceof Error ? error.message : String(error)}`,
602
+ { cause: error }
603
+ );
604
+ }
605
+ }
606
+ /**
607
+ * Synchronize left view to right view.
608
+ *
609
+ * @param leftView - MessagePack-encoded left view data
610
+ * @param leftComplement - Opaque complement bytes from a prior sync
611
+ * @returns The synchronized right view and updated complement
612
+ * @throws {@link WasmError} if the WASM call fails
613
+ */
614
+ syncLeftToRight(leftView, leftComplement) {
615
+ try {
616
+ const bytes = this.#wasm.exports.symmetric_lens_sync(this.#handle.id, leftView, leftComplement, 0);
617
+ return unpackFromWasm(bytes);
618
+ } catch (error) {
619
+ throw new WasmError(
620
+ `symmetric_lens_sync (left-to-right) failed: ${error instanceof Error ? error.message : String(error)}`,
621
+ { cause: error }
622
+ );
623
+ }
624
+ }
625
+ /**
626
+ * Synchronize right view to left view.
627
+ *
628
+ * @param rightView - MessagePack-encoded right view data
629
+ * @param rightComplement - Opaque complement bytes from a prior sync
630
+ * @returns The synchronized left view and updated complement
631
+ * @throws {@link WasmError} if the WASM call fails
632
+ */
633
+ syncRightToLeft(rightView, rightComplement) {
634
+ try {
635
+ const bytes = this.#wasm.exports.symmetric_lens_sync(this.#handle.id, rightView, rightComplement, 1);
636
+ return unpackFromWasm(bytes);
637
+ } catch (error) {
638
+ throw new WasmError(
639
+ `symmetric_lens_sync (right-to-left) failed: ${error instanceof Error ? error.message : String(error)}`,
640
+ { cause: error }
641
+ );
642
+ }
643
+ }
644
+ /** Release the underlying WASM resource. */
645
+ [Symbol.dispose]() {
646
+ this.#handle[Symbol.dispose]();
361
647
  }
362
648
  }
363
649
  class FullDiffReport {
@@ -1703,6 +1989,70 @@ class Repository {
1703
1989
  this.#handle[Symbol.dispose]();
1704
1990
  }
1705
1991
  }
1992
+ class DataSetHandle {
1993
+ #handle;
1994
+ #wasm;
1995
+ constructor(handle, wasm) {
1996
+ this.#handle = handle;
1997
+ this.#wasm = wasm;
1998
+ }
1999
+ /** The WASM handle for this data set. Internal use only. */
2000
+ get _handle() {
2001
+ return this.#handle;
2002
+ }
2003
+ /** Store a data set from a JavaScript object, bound to a schema. */
2004
+ static fromData(data, schema, wasm) {
2005
+ const jsonBytes = new TextEncoder().encode(JSON.stringify(data));
2006
+ const rawHandle = wasm.exports.store_dataset(schema._handle.id, jsonBytes);
2007
+ return new DataSetHandle(createHandle(rawHandle, wasm), wasm);
2008
+ }
2009
+ /** Retrieve the data as MessagePack-encoded bytes. */
2010
+ getData() {
2011
+ const bytes = this.#wasm.exports.get_dataset(this.#handle.id);
2012
+ return unpackFromWasm(bytes);
2013
+ }
2014
+ /** Migrate this data set forward to a new schema. */
2015
+ migrateForward(srcSchema, tgtSchema) {
2016
+ const bytes = this.#wasm.exports.migrate_dataset_forward(
2017
+ this.#handle.id,
2018
+ srcSchema._handle.id,
2019
+ tgtSchema._handle.id
2020
+ );
2021
+ const result = unpackFromWasm(bytes);
2022
+ const complementBytes = this.#wasm.exports.get_dataset(result.complement_handle);
2023
+ this.#wasm.exports.free_handle(result.complement_handle);
2024
+ return {
2025
+ data: new DataSetHandle(createHandle(result.data_handle, this.#wasm), this.#wasm),
2026
+ complement: new Uint8Array(complementBytes)
2027
+ };
2028
+ }
2029
+ /** Migrate this data set backward using a complement. */
2030
+ migrateBackward(complement, srcSchema, tgtSchema) {
2031
+ const rawHandle = this.#wasm.exports.migrate_dataset_backward(
2032
+ this.#handle.id,
2033
+ complement,
2034
+ srcSchema._handle.id,
2035
+ tgtSchema._handle.id
2036
+ );
2037
+ return new DataSetHandle(createHandle(rawHandle, this.#wasm), this.#wasm);
2038
+ }
2039
+ /** Check if this data set is stale relative to a schema. */
2040
+ isStale(schema) {
2041
+ const bytes = this.#wasm.exports.check_dataset_staleness(
2042
+ this.#handle.id,
2043
+ schema._handle.id
2044
+ );
2045
+ const raw = unpackFromWasm(bytes);
2046
+ return {
2047
+ stale: raw.stale,
2048
+ dataSchemaId: raw.data_schema_id,
2049
+ targetSchemaId: raw.target_schema_id
2050
+ };
2051
+ }
2052
+ [Symbol.dispose]() {
2053
+ this.#handle[Symbol.dispose]();
2054
+ }
2055
+ }
1706
2056
  class Panproto {
1707
2057
  #wasm;
1708
2058
  #protocols;
@@ -1932,6 +2282,76 @@ class Panproto {
1932
2282
  initRepo(protocolName) {
1933
2283
  return Repository.init(protocolName, this.#wasm);
1934
2284
  }
2285
+ /**
2286
+ * Convert data from one schema to another using an auto-generated lens.
2287
+ *
2288
+ * This is a convenience method that generates a protolens, applies the
2289
+ * forward projection, and disposes the lens automatically.
2290
+ *
2291
+ * @param data - The input data (Uint8Array of MessagePack, or a plain object)
2292
+ * @param opts - Conversion options specifying source and target schemas
2293
+ * @returns The converted data
2294
+ * @throws {@link WasmError} if lens generation or conversion fails
2295
+ */
2296
+ async convert(data, opts) {
2297
+ const lens = LensHandle.autoGenerate(opts.from, opts.to, this.#wasm);
2298
+ try {
2299
+ const input = data instanceof Uint8Array ? data : packToWasm(data);
2300
+ const result = lens.get(input);
2301
+ return result.view;
2302
+ } finally {
2303
+ lens[Symbol.dispose]();
2304
+ }
2305
+ }
2306
+ /**
2307
+ * Create an auto-generated lens between two schemas.
2308
+ *
2309
+ * @param from - The source schema
2310
+ * @param to - The target schema
2311
+ * @returns A LensHandle for the generated lens
2312
+ * @throws {@link WasmError} if lens generation fails
2313
+ */
2314
+ lens(from, to) {
2315
+ return LensHandle.autoGenerate(from, to, this.#wasm);
2316
+ }
2317
+ /**
2318
+ * Create a protolens chain between two schemas.
2319
+ *
2320
+ * The returned chain is schema-independent and can be instantiated
2321
+ * against different concrete schemas.
2322
+ *
2323
+ * @param from - The source schema
2324
+ * @param to - The target schema
2325
+ * @returns A ProtolensChainHandle for the generated chain
2326
+ * @throws {@link WasmError} if chain generation fails
2327
+ */
2328
+ protolensChain(from, to) {
2329
+ return ProtolensChainHandle.autoGenerate(from, to, this.#wasm);
2330
+ }
2331
+ /**
2332
+ * Store and track a data set against a schema.
2333
+ *
2334
+ * @param data - The data to store (array of records or a single object)
2335
+ * @param schema - The schema this data conforms to
2336
+ * @returns A disposable DataSetHandle
2337
+ */
2338
+ dataSet(data, schema) {
2339
+ return DataSetHandle.fromData(data, schema, this.#wasm);
2340
+ }
2341
+ /**
2342
+ * Migrate data forward between two schemas.
2343
+ *
2344
+ * Auto-generates a lens and migrates each record, returning the
2345
+ * migrated data and a complement for backward migration.
2346
+ *
2347
+ * @param data - The data set to migrate
2348
+ * @param from - The source schema
2349
+ * @param to - The target schema
2350
+ * @returns The migration result with new data and complement
2351
+ */
2352
+ migrateData(data, from, to) {
2353
+ return data.migrateForward(from, to);
2354
+ }
1935
2355
  /**
1936
2356
  * Release all WASM resources held by this instance.
1937
2357
  *
@@ -2065,11 +2485,23 @@ function migrateModel(sortInterp, morphism, wasm) {
2065
2485
  const resultBytes = wasm.exports.migrate_model(modelBytes, morphBytes);
2066
2486
  return unpackFromWasm(resultBytes);
2067
2487
  }
2488
+ function factorizeMorphism(morphismBytes, domain, codomain, wasm) {
2489
+ try {
2490
+ const bytes = wasm.exports.factorize_morphism(morphismBytes, domain._handle.id, codomain._handle.id);
2491
+ return unpackFromWasm(bytes);
2492
+ } catch (error) {
2493
+ throw new WasmError(
2494
+ `factorize_morphism failed: ${error instanceof Error ? error.message : String(error)}`,
2495
+ { cause: error }
2496
+ );
2497
+ }
2498
+ }
2068
2499
  exports.ATPROTO_SPEC = ATPROTO_SPEC;
2069
2500
  exports.BUILTIN_PROTOCOLS = BUILTIN_PROTOCOLS;
2070
2501
  exports.BuiltSchema = BuiltSchema;
2071
2502
  exports.CompatReport = CompatReport;
2072
2503
  exports.CompiledMigration = CompiledMigration;
2504
+ exports.DataSetHandle = DataSetHandle;
2073
2505
  exports.ExistenceCheckError = ExistenceCheckError;
2074
2506
  exports.FullDiffReport = FullDiffReport;
2075
2507
  exports.GRAPHQL_SPEC = GRAPHQL_SPEC;
@@ -2084,27 +2516,21 @@ exports.PROTOCOL_CATEGORIES = PROTOCOL_CATEGORIES;
2084
2516
  exports.Panproto = Panproto;
2085
2517
  exports.PanprotoError = PanprotoError;
2086
2518
  exports.Protocol = Protocol;
2519
+ exports.ProtolensChainHandle = ProtolensChainHandle;
2087
2520
  exports.Repository = Repository;
2088
2521
  exports.SQL_SPEC = SQL_SPEC;
2089
2522
  exports.SchemaBuilder = SchemaBuilder;
2090
2523
  exports.SchemaValidationError = SchemaValidationError;
2524
+ exports.SymmetricLensHandle = SymmetricLensHandle;
2091
2525
  exports.TheoryBuilder = TheoryBuilder;
2092
2526
  exports.TheoryHandle = TheoryHandle;
2093
2527
  exports.ValidationResult = ValidationResult;
2094
2528
  exports.WasmError = WasmError;
2095
- exports.addField = addField;
2096
2529
  exports.checkMorphism = checkMorphism;
2097
- exports.coerceType = coerceType;
2098
2530
  exports.colimit = colimit;
2099
- exports.compose = compose;
2100
2531
  exports.createTheory = createTheory;
2101
- exports.fromCombinators = fromCombinators;
2532
+ exports.factorizeMorphism = factorizeMorphism;
2102
2533
  exports.getBuiltinProtocol = getBuiltinProtocol;
2103
2534
  exports.getProtocolNames = getProtocolNames;
2104
- exports.hoistField = hoistField;
2105
2535
  exports.migrateModel = migrateModel;
2106
- exports.pipeline = pipeline;
2107
- exports.removeField = removeField;
2108
- exports.renameField = renameField;
2109
- exports.wrapInObject = wrapInObject;
2110
2536
  //# sourceMappingURL=index.cjs.map