@panproto/core 0.1.0 → 0.2.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 +104 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +104 -32
- package/dist/index.js.map +1 -1
- package/dist/lens.d.ts +123 -0
- package/dist/lens.d.ts.map +1 -0
- package/dist/migration.d.ts +133 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/msgpack.d.ts +63 -0
- package/dist/msgpack.d.ts.map +1 -0
- package/dist/panproto.d.ts +114 -0
- package/dist/panproto.d.ts.map +1 -0
- package/dist/protocol.d.ts +65 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/schema.d.ts +107 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/types.d.ts +175 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/wasm.d.ts +61 -0
- package/dist/wasm.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/lens.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lens and combinator API for bidirectional transformations.
|
|
3
|
+
*
|
|
4
|
+
* Every migration is a lens with `get` (forward projection) and
|
|
5
|
+
* `put` (restore from complement). This module provides Cambria-style
|
|
6
|
+
* combinators that compose into migrations.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/** Rename a field from one name to another. */
|
|
11
|
+
export interface RenameFieldCombinator {
|
|
12
|
+
readonly type: 'rename-field';
|
|
13
|
+
readonly old: string;
|
|
14
|
+
readonly new: string;
|
|
15
|
+
}
|
|
16
|
+
/** Add a new field with a default value. */
|
|
17
|
+
export interface AddFieldCombinator {
|
|
18
|
+
readonly type: 'add-field';
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly vertexKind: string;
|
|
21
|
+
readonly default: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Remove a field from the schema. */
|
|
24
|
+
export interface RemoveFieldCombinator {
|
|
25
|
+
readonly type: 'remove-field';
|
|
26
|
+
readonly name: string;
|
|
27
|
+
}
|
|
28
|
+
/** Wrap a value inside a new object with a given field name. */
|
|
29
|
+
export interface WrapInObjectCombinator {
|
|
30
|
+
readonly type: 'wrap-in-object';
|
|
31
|
+
readonly fieldName: string;
|
|
32
|
+
}
|
|
33
|
+
/** Hoist a nested field up to the host level. */
|
|
34
|
+
export interface HoistFieldCombinator {
|
|
35
|
+
readonly type: 'hoist-field';
|
|
36
|
+
readonly host: string;
|
|
37
|
+
readonly field: string;
|
|
38
|
+
}
|
|
39
|
+
/** Coerce a value from one type to another. */
|
|
40
|
+
export interface CoerceTypeCombinator {
|
|
41
|
+
readonly type: 'coerce-type';
|
|
42
|
+
readonly fromKind: string;
|
|
43
|
+
readonly toKind: string;
|
|
44
|
+
}
|
|
45
|
+
/** Sequential composition of two combinators. */
|
|
46
|
+
export interface ComposeCombinator {
|
|
47
|
+
readonly type: 'compose';
|
|
48
|
+
readonly first: Combinator;
|
|
49
|
+
readonly second: Combinator;
|
|
50
|
+
}
|
|
51
|
+
/** A lens combinator (Cambria-style). */
|
|
52
|
+
export type Combinator = RenameFieldCombinator | AddFieldCombinator | RemoveFieldCombinator | WrapInObjectCombinator | HoistFieldCombinator | CoerceTypeCombinator | ComposeCombinator;
|
|
53
|
+
/**
|
|
54
|
+
* Create a rename-field combinator.
|
|
55
|
+
*
|
|
56
|
+
* @param oldName - The current field name
|
|
57
|
+
* @param newName - The desired field name
|
|
58
|
+
* @returns A rename-field combinator
|
|
59
|
+
*/
|
|
60
|
+
export declare function renameField(oldName: string, newName: string): RenameFieldCombinator;
|
|
61
|
+
/**
|
|
62
|
+
* Create an add-field combinator.
|
|
63
|
+
*
|
|
64
|
+
* @param name - The field name to add
|
|
65
|
+
* @param vertexKind - The vertex kind for the new field
|
|
66
|
+
* @param defaultValue - The default value for the field
|
|
67
|
+
* @returns An add-field combinator
|
|
68
|
+
*/
|
|
69
|
+
export declare function addField(name: string, vertexKind: string, defaultValue: unknown): AddFieldCombinator;
|
|
70
|
+
/**
|
|
71
|
+
* Create a remove-field combinator.
|
|
72
|
+
*
|
|
73
|
+
* @param name - The field name to remove
|
|
74
|
+
* @returns A remove-field combinator
|
|
75
|
+
*/
|
|
76
|
+
export declare function removeField(name: string): RemoveFieldCombinator;
|
|
77
|
+
/**
|
|
78
|
+
* Create a wrap-in-object combinator.
|
|
79
|
+
*
|
|
80
|
+
* @param fieldName - The field name for the wrapper object
|
|
81
|
+
* @returns A wrap-in-object combinator
|
|
82
|
+
*/
|
|
83
|
+
export declare function wrapInObject(fieldName: string): WrapInObjectCombinator;
|
|
84
|
+
/**
|
|
85
|
+
* Create a hoist-field combinator.
|
|
86
|
+
*
|
|
87
|
+
* @param host - The host vertex to hoist into
|
|
88
|
+
* @param field - The nested field to hoist
|
|
89
|
+
* @returns A hoist-field combinator
|
|
90
|
+
*/
|
|
91
|
+
export declare function hoistField(host: string, field: string): HoistFieldCombinator;
|
|
92
|
+
/**
|
|
93
|
+
* Create a coerce-type combinator.
|
|
94
|
+
*
|
|
95
|
+
* @param fromKind - The source type kind
|
|
96
|
+
* @param toKind - The target type kind
|
|
97
|
+
* @returns A coerce-type combinator
|
|
98
|
+
*/
|
|
99
|
+
export declare function coerceType(fromKind: string, toKind: string): CoerceTypeCombinator;
|
|
100
|
+
/**
|
|
101
|
+
* Compose two combinators sequentially.
|
|
102
|
+
*
|
|
103
|
+
* @param first - The combinator applied first
|
|
104
|
+
* @param second - The combinator applied second
|
|
105
|
+
* @returns A composed combinator
|
|
106
|
+
*/
|
|
107
|
+
export declare function compose(first: Combinator, second: Combinator): ComposeCombinator;
|
|
108
|
+
/**
|
|
109
|
+
* Compose a chain of combinators left-to-right.
|
|
110
|
+
*
|
|
111
|
+
* @param combinators - The combinators to compose (at least one required)
|
|
112
|
+
* @returns The composed combinator
|
|
113
|
+
* @throws If the combinators array is empty
|
|
114
|
+
*/
|
|
115
|
+
export declare function pipeline(combinators: readonly [Combinator, ...Combinator[]]): Combinator;
|
|
116
|
+
/**
|
|
117
|
+
* Serialize a combinator to a plain object for MessagePack encoding.
|
|
118
|
+
*
|
|
119
|
+
* @param combinator - The combinator to serialize
|
|
120
|
+
* @returns A plain object suitable for MessagePack encoding
|
|
121
|
+
*/
|
|
122
|
+
export declare function combinatorToWire(combinator: Combinator): Record<string, unknown>;
|
|
123
|
+
//# sourceMappingURL=lens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lens.d.ts","sourceRoot":"","sources":["../src/lens.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,sCAAsC;AACtC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,gEAAgE;AAChE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;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,MAAM,EAAE,UAAU,GAAG,iBAAiB,CAEhF;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,UAAU,CAGxF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBhF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { WasmModule, Edge, LiftResult, GetResult, ExistenceReport, MigrationSpec } from './types.js';
|
|
2
|
+
import { WasmHandle } from './wasm.js';
|
|
3
|
+
import { BuiltSchema } from './schema.js';
|
|
4
|
+
/**
|
|
5
|
+
* Fluent builder for constructing migrations between two schemas.
|
|
6
|
+
*
|
|
7
|
+
* Each mutation method returns a new `MigrationBuilder` instance,
|
|
8
|
+
* leaving the original unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const migration = panproto.migration(oldSchema, newSchema)
|
|
13
|
+
* .map('post', 'post')
|
|
14
|
+
* .map('post:body', 'post:body')
|
|
15
|
+
* .mapEdge(oldEdge, newEdge)
|
|
16
|
+
* .compile();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class MigrationBuilder {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(src: BuiltSchema, tgt: BuiltSchema, wasm: WasmModule, vertexMap?: ReadonlyMap<string, string>, edgeMap?: readonly [Edge, Edge][], resolvers?: readonly [[string, string], Edge][]);
|
|
22
|
+
/**
|
|
23
|
+
* Map a source vertex to a target vertex.
|
|
24
|
+
*
|
|
25
|
+
* @param srcVertex - Vertex id in the source schema
|
|
26
|
+
* @param tgtVertex - Vertex id in the target schema
|
|
27
|
+
* @returns A new builder with the mapping added
|
|
28
|
+
*/
|
|
29
|
+
map(srcVertex: string, tgtVertex: string): MigrationBuilder;
|
|
30
|
+
/**
|
|
31
|
+
* Map a source edge to a target edge.
|
|
32
|
+
*
|
|
33
|
+
* @param srcEdge - Edge in the source schema
|
|
34
|
+
* @param tgtEdge - Edge in the target schema
|
|
35
|
+
* @returns A new builder with the edge mapping added
|
|
36
|
+
*/
|
|
37
|
+
mapEdge(srcEdge: Edge, tgtEdge: Edge): MigrationBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Add a resolver for ancestor contraction ambiguity.
|
|
40
|
+
*
|
|
41
|
+
* When a migration contracts nodes and the resulting edge between
|
|
42
|
+
* two vertex kinds is ambiguous, a resolver specifies which edge to use.
|
|
43
|
+
*
|
|
44
|
+
* @param srcKind - Source vertex kind in the contracted pair
|
|
45
|
+
* @param tgtKind - Target vertex kind in the contracted pair
|
|
46
|
+
* @param resolvedEdge - The edge to use for this pair
|
|
47
|
+
* @returns A new builder with the resolver added
|
|
48
|
+
*/
|
|
49
|
+
resolve(srcKind: string, tgtKind: string, resolvedEdge: Edge): MigrationBuilder;
|
|
50
|
+
/**
|
|
51
|
+
* Get the current migration specification.
|
|
52
|
+
*
|
|
53
|
+
* @returns The migration spec with all accumulated mappings
|
|
54
|
+
*/
|
|
55
|
+
toSpec(): MigrationSpec;
|
|
56
|
+
/**
|
|
57
|
+
* Compile the migration for fast per-record application.
|
|
58
|
+
*
|
|
59
|
+
* Sends the migration specification to WASM for compilation.
|
|
60
|
+
* The resulting `CompiledMigration` can be used to transform records.
|
|
61
|
+
*
|
|
62
|
+
* @returns A compiled migration ready for record transformation
|
|
63
|
+
* @throws {@link MigrationError} if compilation fails
|
|
64
|
+
*/
|
|
65
|
+
compile(): CompiledMigration;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A compiled migration that can efficiently transform records via WASM.
|
|
69
|
+
*
|
|
70
|
+
* Implements `Disposable` for automatic cleanup of the WASM resource.
|
|
71
|
+
*/
|
|
72
|
+
export declare class CompiledMigration implements Disposable {
|
|
73
|
+
#private;
|
|
74
|
+
constructor(handle: WasmHandle, wasm: WasmModule, spec: MigrationSpec);
|
|
75
|
+
/** The WASM handle for this migration. Internal use only. */
|
|
76
|
+
get _handle(): WasmHandle;
|
|
77
|
+
/** The migration specification used to build this migration. */
|
|
78
|
+
get spec(): MigrationSpec;
|
|
79
|
+
/**
|
|
80
|
+
* Transform a record using this migration (forward direction).
|
|
81
|
+
*
|
|
82
|
+
* This is the hot path: data goes through WASM as MessagePack bytes
|
|
83
|
+
* with no intermediate JS-heap allocation.
|
|
84
|
+
*
|
|
85
|
+
* @param record - The input record to transform
|
|
86
|
+
* @returns The transformed record
|
|
87
|
+
* @throws {@link WasmError} if the WASM call fails
|
|
88
|
+
*/
|
|
89
|
+
lift(record: unknown): LiftResult;
|
|
90
|
+
/**
|
|
91
|
+
* Bidirectional get: extract view and complement from a record.
|
|
92
|
+
*
|
|
93
|
+
* The complement captures data discarded by the forward projection,
|
|
94
|
+
* enabling lossless round-tripping via `put()`.
|
|
95
|
+
*
|
|
96
|
+
* @param record - The input record
|
|
97
|
+
* @returns The projected view and opaque complement bytes
|
|
98
|
+
* @throws {@link WasmError} if the WASM call fails
|
|
99
|
+
*/
|
|
100
|
+
get(record: unknown): GetResult;
|
|
101
|
+
/**
|
|
102
|
+
* Bidirectional put: restore a full record from a modified view and complement.
|
|
103
|
+
*
|
|
104
|
+
* @param view - The (possibly modified) projected view
|
|
105
|
+
* @param complement - The complement from a prior `get()` call
|
|
106
|
+
* @returns The restored full record
|
|
107
|
+
* @throws {@link WasmError} if the WASM call fails
|
|
108
|
+
*/
|
|
109
|
+
put(view: unknown, complement: Uint8Array): LiftResult;
|
|
110
|
+
/** Release the WASM-side compiled migration resource. */
|
|
111
|
+
[Symbol.dispose](): void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check existence conditions for a migration between two schemas.
|
|
115
|
+
*
|
|
116
|
+
* @param src - Source schema handle
|
|
117
|
+
* @param tgt - Target schema handle
|
|
118
|
+
* @param spec - The migration specification
|
|
119
|
+
* @param wasm - The WASM module
|
|
120
|
+
* @returns The existence report
|
|
121
|
+
*/
|
|
122
|
+
export declare function checkExistence(protoHandle: number, src: BuiltSchema, tgt: BuiltSchema, spec: MigrationSpec, wasm: WasmModule): ExistenceReport;
|
|
123
|
+
/**
|
|
124
|
+
* Compose two compiled migrations into a single migration.
|
|
125
|
+
*
|
|
126
|
+
* @param m1 - First migration (applied first)
|
|
127
|
+
* @param m2 - Second migration (applied second)
|
|
128
|
+
* @param wasm - The WASM module
|
|
129
|
+
* @returns A new compiled migration representing m2 . m1
|
|
130
|
+
* @throws {@link MigrationError} if composition fails
|
|
131
|
+
*/
|
|
132
|
+
export declare function composeMigrations(m1: CompiledMigration, m2: CompiledMigration, wasm: WasmModule): CompiledMigration;
|
|
133
|
+
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAgB;;gBASzB,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,UAAU,EAChB,SAAS,GAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAa,EAClD,OAAO,GAAE,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAO,EACrC,SAAS,GAAE,SAAS,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAO;IAUrD;;;;;;OAMG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,gBA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ities for the WASM boundary.
|
|
3
|
+
*
|
|
4
|
+
* All structured data crossing the WASM boundary is serialized as MessagePack
|
|
5
|
+
* byte slices. This module wraps `@msgpack/msgpack` with typed helpers.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Encode a value to MessagePack bytes for sending to WASM.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to encode
|
|
13
|
+
* @returns MessagePack-encoded bytes
|
|
14
|
+
*/
|
|
15
|
+
export declare function packToWasm(value: unknown): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Decode MessagePack bytes received from WASM.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - The expected decoded type
|
|
20
|
+
* @param bytes - MessagePack-encoded bytes from WASM
|
|
21
|
+
* @returns The decoded value
|
|
22
|
+
*/
|
|
23
|
+
export declare function unpackFromWasm<T = unknown>(bytes: Uint8Array): T;
|
|
24
|
+
/**
|
|
25
|
+
* Encode a schema operations list for the `build_schema` entry point.
|
|
26
|
+
*
|
|
27
|
+
* @param ops - Array of builder operations
|
|
28
|
+
* @returns MessagePack-encoded bytes
|
|
29
|
+
*/
|
|
30
|
+
export declare function packSchemaOps(ops: readonly SchemaOp[]): Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* Encode a migration mapping for WASM entry points.
|
|
33
|
+
*
|
|
34
|
+
* @param mapping - The migration mapping object
|
|
35
|
+
* @returns MessagePack-encoded bytes
|
|
36
|
+
*/
|
|
37
|
+
export declare function packMigrationMapping(mapping: MigrationMapping): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* A single schema builder operation sent to WASM.
|
|
40
|
+
*
|
|
41
|
+
* Uses serde internally-tagged format: the `op` field acts as the
|
|
42
|
+
* discriminant and all variant fields sit at the same level.
|
|
43
|
+
*/
|
|
44
|
+
export interface SchemaOp {
|
|
45
|
+
readonly op: 'vertex' | 'edge' | 'hyper_edge' | 'constraint' | 'required';
|
|
46
|
+
readonly [key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** Wire format for an edge (matches Rust serialization). */
|
|
49
|
+
export interface EdgeWire {
|
|
50
|
+
readonly src: string;
|
|
51
|
+
readonly tgt: string;
|
|
52
|
+
readonly kind: string;
|
|
53
|
+
readonly name: string | null;
|
|
54
|
+
}
|
|
55
|
+
/** A migration mapping sent to WASM (matches Rust `Migration` struct). */
|
|
56
|
+
export interface MigrationMapping {
|
|
57
|
+
readonly vertex_map: Record<string, string>;
|
|
58
|
+
readonly edge_map: Map<EdgeWire, EdgeWire>;
|
|
59
|
+
readonly hyper_edge_map: Record<string, string>;
|
|
60
|
+
readonly label_map: Map<readonly [string, string], string>;
|
|
61
|
+
readonly resolver: Map<readonly [string, string], EdgeWire>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=msgpack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgpack.d.ts","sourceRoot":"","sources":["../src/msgpack.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAErD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,CAAC,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,QAAQ,EAAE,GAAG,UAAU,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAE1E;AAMD;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,GAAG,UAAU,CAAC;IAC1E,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,4DAA4D;AAC5D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;CAC7D"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ProtocolSpec, DiffReport } from './types.js';
|
|
2
|
+
import { WasmGlueModule } from './wasm.js';
|
|
3
|
+
import { Protocol } from './protocol.js';
|
|
4
|
+
import { BuiltSchema } from './schema.js';
|
|
5
|
+
import { MigrationBuilder, CompiledMigration } from './migration.js';
|
|
6
|
+
/**
|
|
7
|
+
* The main entry point for the panproto SDK.
|
|
8
|
+
*
|
|
9
|
+
* Create an instance with {@link Panproto.init}, then use it to define
|
|
10
|
+
* protocols, build schemas, compile migrations, and diff schemas.
|
|
11
|
+
*
|
|
12
|
+
* Implements `Disposable` so it can be used with `using` to automatically
|
|
13
|
+
* clean up all WASM resources.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const panproto = await Panproto.init();
|
|
18
|
+
* const atproto = panproto.protocol('atproto');
|
|
19
|
+
*
|
|
20
|
+
* const schema = atproto.schema()
|
|
21
|
+
* .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })
|
|
22
|
+
* .vertex('post:body', 'object')
|
|
23
|
+
* .edge('post', 'post:body', 'record-schema')
|
|
24
|
+
* .build();
|
|
25
|
+
*
|
|
26
|
+
* const migration = panproto.migration(oldSchema, newSchema)
|
|
27
|
+
* .map('post', 'post')
|
|
28
|
+
* .compile();
|
|
29
|
+
*
|
|
30
|
+
* const result = migration.lift(inputRecord);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class Panproto implements Disposable {
|
|
34
|
+
#private;
|
|
35
|
+
private constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the panproto SDK by loading the WASM module.
|
|
38
|
+
*
|
|
39
|
+
* @param input - URL to the wasm-bindgen glue module, or a pre-imported
|
|
40
|
+
* glue module object (for bundler environments like Vite).
|
|
41
|
+
* Defaults to the bundled glue module.
|
|
42
|
+
* @returns An initialized Panproto instance
|
|
43
|
+
* @throws {@link import('./types.js').WasmError} if WASM loading fails
|
|
44
|
+
*/
|
|
45
|
+
static init(input?: string | URL | WasmGlueModule): Promise<Panproto>;
|
|
46
|
+
/**
|
|
47
|
+
* Get or register a protocol by name.
|
|
48
|
+
*
|
|
49
|
+
* If the protocol is a built-in (e.g., 'atproto', 'sql'), it is
|
|
50
|
+
* automatically registered on first access. Custom protocols must
|
|
51
|
+
* be registered first with {@link Panproto.defineProtocol}.
|
|
52
|
+
*
|
|
53
|
+
* @param name - The protocol name
|
|
54
|
+
* @returns The protocol instance
|
|
55
|
+
* @throws {@link PanprotoError} if the protocol is not found
|
|
56
|
+
*/
|
|
57
|
+
protocol(name: string): Protocol;
|
|
58
|
+
/**
|
|
59
|
+
* Define and register a custom protocol.
|
|
60
|
+
*
|
|
61
|
+
* @param spec - The protocol specification
|
|
62
|
+
* @returns The registered protocol
|
|
63
|
+
* @throws {@link PanprotoError} if registration fails
|
|
64
|
+
*/
|
|
65
|
+
defineProtocol(spec: ProtocolSpec): Protocol;
|
|
66
|
+
/**
|
|
67
|
+
* Start building a migration between two schemas.
|
|
68
|
+
*
|
|
69
|
+
* @param src - The source schema
|
|
70
|
+
* @param tgt - The target schema
|
|
71
|
+
* @returns A migration builder
|
|
72
|
+
*/
|
|
73
|
+
migration(src: BuiltSchema, tgt: BuiltSchema): MigrationBuilder;
|
|
74
|
+
/**
|
|
75
|
+
* Check existence conditions for a proposed migration.
|
|
76
|
+
*
|
|
77
|
+
* Verifies that the migration specification satisfies all
|
|
78
|
+
* protocol-derived constraints (edge coverage, kind consistency,
|
|
79
|
+
* required fields, etc.).
|
|
80
|
+
*
|
|
81
|
+
* @param src - The source schema
|
|
82
|
+
* @param tgt - The target schema
|
|
83
|
+
* @param builder - The migration builder with mappings
|
|
84
|
+
* @returns The existence report
|
|
85
|
+
*/
|
|
86
|
+
checkExistence(src: BuiltSchema, tgt: BuiltSchema, builder: MigrationBuilder): import('./types.js').ExistenceReport;
|
|
87
|
+
/**
|
|
88
|
+
* Compose two compiled migrations into a single migration.
|
|
89
|
+
*
|
|
90
|
+
* The resulting migration is equivalent to applying `m1` then `m2`.
|
|
91
|
+
*
|
|
92
|
+
* @param m1 - First migration (applied first)
|
|
93
|
+
* @param m2 - Second migration (applied second)
|
|
94
|
+
* @returns The composed migration
|
|
95
|
+
* @throws {@link import('./types.js').MigrationError} if composition fails
|
|
96
|
+
*/
|
|
97
|
+
compose(m1: CompiledMigration, m2: CompiledMigration): CompiledMigration;
|
|
98
|
+
/**
|
|
99
|
+
* Diff two schemas and produce a compatibility report.
|
|
100
|
+
*
|
|
101
|
+
* @param oldSchema - The old/source schema
|
|
102
|
+
* @param newSchema - The new/target schema
|
|
103
|
+
* @returns A diff report with changes and compatibility classification
|
|
104
|
+
*/
|
|
105
|
+
diff(oldSchema: BuiltSchema, newSchema: BuiltSchema): DiffReport;
|
|
106
|
+
/**
|
|
107
|
+
* Release all WASM resources held by this instance.
|
|
108
|
+
*
|
|
109
|
+
* Disposes all cached protocols. After disposal, this instance
|
|
110
|
+
* must not be used.
|
|
111
|
+
*/
|
|
112
|
+
[Symbol.dispose](): void;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=panproto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panproto.d.ts","sourceRoot":"","sources":["../src/panproto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAc,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,QAAQ,EAGT,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAGlB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,QAAS,YAAW,UAAU;;IAIzC,OAAO;IAKP;;;;;;;;OAQG;WACU,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK3E;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAiBhC;;;;;;OAMG;IACH,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ;IAM5C;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,GAAG,gBAAgB;IAI/D;;;;;;;;;;;OAWG;IACH,cAAc,CACZ,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,gBAAgB,GACxB,OAAO,YAAY,EAAE,eAAe;IAUvC;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,GAAG,iBAAiB;IAIxE;;;;;;OAMG;IACH,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,GAAG,UAAU;IAQhE;;;;;OAKG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAMzB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { WasmModule, ProtocolSpec } from './types.js';
|
|
2
|
+
import { WasmHandle } from './wasm.js';
|
|
3
|
+
import { SchemaBuilder } from './schema.js';
|
|
4
|
+
/**
|
|
5
|
+
* A registered protocol with a WASM-side handle.
|
|
6
|
+
*
|
|
7
|
+
* Provides a fluent API for building schemas within this protocol.
|
|
8
|
+
* Implements `Disposable` for automatic cleanup.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Protocol implements Disposable {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(handle: WasmHandle, spec: ProtocolSpec, wasm: WasmModule);
|
|
13
|
+
/** The protocol name. */
|
|
14
|
+
get name(): string;
|
|
15
|
+
/** The full protocol specification. */
|
|
16
|
+
get spec(): ProtocolSpec;
|
|
17
|
+
/** The WASM handle. Internal use only. */
|
|
18
|
+
get _handle(): WasmHandle;
|
|
19
|
+
/**
|
|
20
|
+
* Start building a schema within this protocol.
|
|
21
|
+
*
|
|
22
|
+
* @returns A new `SchemaBuilder` bound to this protocol
|
|
23
|
+
*/
|
|
24
|
+
schema(): SchemaBuilder;
|
|
25
|
+
/** Release the WASM-side protocol resource. */
|
|
26
|
+
[Symbol.dispose](): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Define a protocol by sending its specification to WASM.
|
|
30
|
+
*
|
|
31
|
+
* @param spec - The protocol specification
|
|
32
|
+
* @param wasm - The WASM module
|
|
33
|
+
* @returns A registered protocol with a WASM handle
|
|
34
|
+
* @throws {@link PanprotoError} if the WASM call fails
|
|
35
|
+
*/
|
|
36
|
+
export declare function defineProtocol(spec: ProtocolSpec, wasm: WasmModule): Protocol;
|
|
37
|
+
/**
|
|
38
|
+
* Built-in ATProto protocol specification.
|
|
39
|
+
*
|
|
40
|
+
* Schema theory: colimit(ThGraph, ThConstraint, ThMulti).
|
|
41
|
+
* Instance theory: ThWType + ThMeta.
|
|
42
|
+
*/
|
|
43
|
+
export declare const ATPROTO_SPEC: ProtocolSpec;
|
|
44
|
+
/**
|
|
45
|
+
* Built-in SQL protocol specification.
|
|
46
|
+
*
|
|
47
|
+
* Schema theory: colimit(ThHypergraph, ThConstraint).
|
|
48
|
+
* Instance theory: ThFunctor.
|
|
49
|
+
*/
|
|
50
|
+
export declare const SQL_SPEC: ProtocolSpec;
|
|
51
|
+
/**
|
|
52
|
+
* Built-in Protobuf protocol specification.
|
|
53
|
+
*/
|
|
54
|
+
export declare const PROTOBUF_SPEC: ProtocolSpec;
|
|
55
|
+
/**
|
|
56
|
+
* Built-in GraphQL protocol specification.
|
|
57
|
+
*/
|
|
58
|
+
export declare const GRAPHQL_SPEC: ProtocolSpec;
|
|
59
|
+
/**
|
|
60
|
+
* Built-in JSON Schema protocol specification.
|
|
61
|
+
*/
|
|
62
|
+
export declare const JSON_SCHEMA_SPEC: ProtocolSpec;
|
|
63
|
+
/** Registry of built-in protocol specs, keyed by name. */
|
|
64
|
+
export declare const BUILTIN_PROTOCOLS: ReadonlyMap<string, ProtocolSpec>;
|
|
65
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAY,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;GAKG;AACH,qBAAa,QAAS,YAAW,UAAU;;gBAK7B,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU;IAMpE,yBAAyB;IACzB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,uCAAuC;IACvC,IAAI,IAAI,IAAI,YAAY,CAEvB;IAED,0CAA0C;IAC1C,IAAI,OAAO,IAAI,UAAU,CAExB;IAED;;;;OAIG;IACH,MAAM,IAAI,aAAa;IAIvB,+CAA+C;IAC/C,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,CAyB7E;AAMD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,YAqB1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,YAWtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,YAW3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,YAY1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,YAW9B,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAM9D,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { WasmModule, Vertex, Edge, HyperEdge, Constraint, VertexOptions, EdgeOptions, SchemaData } from './types.js';
|
|
2
|
+
import { WasmHandle } from './wasm.js';
|
|
3
|
+
import { SchemaOp } from './msgpack.js';
|
|
4
|
+
/**
|
|
5
|
+
* Immutable fluent builder for constructing schemas.
|
|
6
|
+
*
|
|
7
|
+
* Each mutation method returns a new `SchemaBuilder` instance,
|
|
8
|
+
* leaving the original unchanged. The builder accumulates operations
|
|
9
|
+
* that are sent to WASM on `.build()`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const schema = builder
|
|
14
|
+
* .vertex('post', 'record', { nsid: 'app.bsky.feed.post' })
|
|
15
|
+
* .vertex('post:body', 'object')
|
|
16
|
+
* .edge('post', 'post:body', 'record-schema')
|
|
17
|
+
* .build();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class SchemaBuilder {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(protocolName: string, protocolHandle: WasmHandle, wasm: WasmModule, ops?: readonly SchemaOp[], vertices?: ReadonlyMap<string, Vertex>, edges?: readonly Edge[], hyperEdges?: ReadonlyMap<string, HyperEdge>, constraints?: ReadonlyMap<string, readonly Constraint[]>, required?: ReadonlyMap<string, readonly Edge[]>);
|
|
23
|
+
/**
|
|
24
|
+
* Add a vertex to the schema.
|
|
25
|
+
*
|
|
26
|
+
* @param id - Unique vertex identifier
|
|
27
|
+
* @param kind - Vertex kind (e.g., 'record', 'object', 'string')
|
|
28
|
+
* @param options - Optional vertex configuration (nsid, etc.)
|
|
29
|
+
* @returns A new builder with the vertex added
|
|
30
|
+
* @throws {@link SchemaValidationError} if vertex id is already in use
|
|
31
|
+
*/
|
|
32
|
+
vertex(id: string, kind: string, options?: VertexOptions): SchemaBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Add a directed edge to the schema.
|
|
35
|
+
*
|
|
36
|
+
* @param src - Source vertex id
|
|
37
|
+
* @param tgt - Target vertex id
|
|
38
|
+
* @param kind - Edge kind (e.g., 'record-schema', 'prop')
|
|
39
|
+
* @param options - Optional edge configuration (name, etc.)
|
|
40
|
+
* @returns A new builder with the edge added
|
|
41
|
+
* @throws {@link SchemaValidationError} if source or target vertex does not exist
|
|
42
|
+
*/
|
|
43
|
+
edge(src: string, tgt: string, kind: string, options?: EdgeOptions): SchemaBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Add a hyperedge to the schema.
|
|
46
|
+
*
|
|
47
|
+
* Only valid if the protocol's schema theory includes ThHypergraph.
|
|
48
|
+
*
|
|
49
|
+
* @param id - Unique hyperedge identifier
|
|
50
|
+
* @param kind - Hyperedge kind
|
|
51
|
+
* @param signature - Label-to-vertex mapping
|
|
52
|
+
* @param parentLabel - The label identifying the parent in the signature
|
|
53
|
+
* @returns A new builder with the hyperedge added
|
|
54
|
+
*/
|
|
55
|
+
hyperEdge(id: string, kind: string, signature: Record<string, string>, parentLabel: string): SchemaBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Add a constraint to a vertex.
|
|
58
|
+
*
|
|
59
|
+
* @param vertexId - The vertex to constrain
|
|
60
|
+
* @param sort - Constraint sort (e.g., 'maxLength')
|
|
61
|
+
* @param value - Constraint value
|
|
62
|
+
* @returns A new builder with the constraint added
|
|
63
|
+
*/
|
|
64
|
+
constraint(vertexId: string, sort: string, value: string): SchemaBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Mark edges as required for a vertex.
|
|
67
|
+
*
|
|
68
|
+
* @param vertexId - The vertex with required edges
|
|
69
|
+
* @param edges - The edges that are required
|
|
70
|
+
* @returns A new builder with the requirement added
|
|
71
|
+
*/
|
|
72
|
+
required(vertexId: string, edges: readonly Edge[]): SchemaBuilder;
|
|
73
|
+
/**
|
|
74
|
+
* Validate and build the schema.
|
|
75
|
+
*
|
|
76
|
+
* Sends all accumulated operations to WASM for validation and construction.
|
|
77
|
+
* Returns a `BuiltSchema` that holds the WASM handle and local data.
|
|
78
|
+
*
|
|
79
|
+
* @returns The validated, built schema
|
|
80
|
+
* @throws {@link SchemaValidationError} if the schema is invalid
|
|
81
|
+
*/
|
|
82
|
+
build(): BuiltSchema;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A validated, built schema with a WASM-side handle.
|
|
86
|
+
*
|
|
87
|
+
* Implements `Disposable` for automatic cleanup of the WASM resource.
|
|
88
|
+
*/
|
|
89
|
+
export declare class BuiltSchema implements Disposable {
|
|
90
|
+
#private;
|
|
91
|
+
constructor(handle: WasmHandle, data: SchemaData, wasm: WasmModule);
|
|
92
|
+
/** The WASM handle for this schema. Internal use only. */
|
|
93
|
+
get _handle(): WasmHandle;
|
|
94
|
+
/** The WASM module reference. Internal use only. */
|
|
95
|
+
get _wasm(): WasmModule;
|
|
96
|
+
/** The schema data (vertices, edges, constraints, etc.). */
|
|
97
|
+
get data(): SchemaData;
|
|
98
|
+
/** The protocol name this schema belongs to. */
|
|
99
|
+
get protocol(): string;
|
|
100
|
+
/** All vertices in the schema. */
|
|
101
|
+
get vertices(): Readonly<Record<string, Vertex>>;
|
|
102
|
+
/** All edges in the schema. */
|
|
103
|
+
get edges(): readonly Edge[];
|
|
104
|
+
/** Release the WASM-side schema resource. */
|
|
105
|
+
[Symbol.dispose](): void;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,MAAM,EACN,IAAI,EACJ,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAa;;gBAYtB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,UAAU,EAC1B,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,SAAS,QAAQ,EAAO,EAC7B,QAAQ,GAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAa,EACjD,KAAK,GAAE,SAAS,IAAI,EAAO,EAC3B,UAAU,GAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAa,EACtD,WAAW,GAAE,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAa,EACnE,QAAQ,GAAE,W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