@panticonic/pi-chord 0.99.2-vibestudio.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/LICENSE +21 -0
- package/README.md +264 -0
- package/SOURCE.json +8858 -0
- package/dist/api.d.ts +20 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +77 -0
- package/dist/api.js.map +1 -0
- package/dist/bundler.d.ts +6 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/bundler.js +3 -0
- package/dist/bundler.js.map +1 -0
- package/dist/context/index.d.ts +24 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +97 -0
- package/dist/context/index.js.map +1 -0
- package/dist/delta/apply-immutable-trusted.d.ts +4 -0
- package/dist/delta/apply-immutable-trusted.d.ts.map +1 -0
- package/dist/delta/apply-immutable-trusted.js +127 -0
- package/dist/delta/apply-immutable-trusted.js.map +1 -0
- package/dist/delta/diff.d.ts +5 -0
- package/dist/delta/diff.d.ts.map +1 -0
- package/dist/delta/diff.js +433 -0
- package/dist/delta/diff.js.map +1 -0
- package/dist/delta/draft.d.ts +5 -0
- package/dist/delta/draft.d.ts.map +1 -0
- package/dist/delta/draft.js +2 -0
- package/dist/delta/draft.js.map +1 -0
- package/dist/delta/index.d.ts +111 -0
- package/dist/delta/index.d.ts.map +1 -0
- package/dist/delta/index.js +648 -0
- package/dist/delta/index.js.map +1 -0
- package/dist/delta/revision-validator.d.ts +7 -0
- package/dist/delta/revision-validator.d.ts.map +1 -0
- package/dist/delta/revision-validator.js +71 -0
- package/dist/delta/revision-validator.js.map +1 -0
- package/dist/delta/tracker.d.ts +26 -0
- package/dist/delta/tracker.d.ts.map +1 -0
- package/dist/delta/tracker.js +2069 -0
- package/dist/delta/tracker.js.map +1 -0
- package/dist/facets/host.d.ts +12 -0
- package/dist/facets/host.d.ts.map +1 -0
- package/dist/facets/host.js +763 -0
- package/dist/facets/host.js.map +1 -0
- package/dist/facets/loader.d.ts +3 -0
- package/dist/facets/loader.d.ts.map +1 -0
- package/dist/facets/loader.js +5 -0
- package/dist/facets/loader.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +10 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +124 -0
- package/dist/json.js.map +1 -0
- package/dist/node/bundle-loader.d.ts +30 -0
- package/dist/node/bundle-loader.d.ts.map +1 -0
- package/dist/node/bundle-loader.js +377 -0
- package/dist/node/bundle-loader.js.map +1 -0
- package/dist/node/bundle.d.ts +26 -0
- package/dist/node/bundle.d.ts.map +1 -0
- package/dist/node/bundle.js +183 -0
- package/dist/node/bundle.js.map +1 -0
- package/dist/node/manifest.d.ts +36 -0
- package/dist/node/manifest.d.ts.map +1 -0
- package/dist/node/manifest.js +6 -0
- package/dist/node/manifest.js.map +1 -0
- package/dist/node/package.d.ts +15 -0
- package/dist/node/package.d.ts.map +1 -0
- package/dist/node/package.js +199 -0
- package/dist/node/package.js.map +1 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/services/consumer.d.ts +11 -0
- package/dist/services/consumer.d.ts.map +1 -0
- package/dist/services/consumer.js +585 -0
- package/dist/services/consumer.js.map +1 -0
- package/dist/services/errors.d.ts +8 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +22 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/handle.d.ts +15 -0
- package/dist/services/handle.d.ts.map +1 -0
- package/dist/services/handle.js +101 -0
- package/dist/services/handle.js.map +1 -0
- package/dist/services/instances.d.ts +26 -0
- package/dist/services/instances.d.ts.map +1 -0
- package/dist/services/instances.js +140 -0
- package/dist/services/instances.js.map +1 -0
- package/dist/services/loopback.d.ts +5 -0
- package/dist/services/loopback.d.ts.map +1 -0
- package/dist/services/loopback.js +15 -0
- package/dist/services/loopback.js.map +1 -0
- package/dist/services/provider.d.ts +37 -0
- package/dist/services/provider.d.ts.map +1 -0
- package/dist/services/provider.js +521 -0
- package/dist/services/provider.js.map +1 -0
- package/dist/services/state-codec.d.ts +15 -0
- package/dist/services/state-codec.d.ts.map +1 -0
- package/dist/services/state-codec.js +133 -0
- package/dist/services/state-codec.js.map +1 -0
- package/dist/services/state-internals.d.ts +13 -0
- package/dist/services/state-internals.d.ts.map +1 -0
- package/dist/services/state-internals.js +10 -0
- package/dist/services/state-internals.js.map +1 -0
- package/dist/services/state.d.ts +28 -0
- package/dist/services/state.d.ts.map +1 -0
- package/dist/services/state.js +397 -0
- package/dist/services/state.js.map +1 -0
- package/dist/services/wire.d.ts +63 -0
- package/dist/services/wire.d.ts.map +1 -0
- package/dist/services/wire.js +186 -0
- package/dist/services/wire.js.map +1 -0
- package/dist/types.d.ts +273 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +62 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AttachedReplicatedState, Facet, FacetHost, FacetLoader, FacetOptions, MutableReplicatedState, RemoteServiceBinding, RemoteServiceBindingOptions, RemoteServiceContract, ReplicatedStateSource, ReplicatedStateSourceOptions, Service } from "./types.ts";
|
|
2
|
+
/** Create an active host for one complete set of facets. */
|
|
3
|
+
export declare function createFacetHost(options: FacetOptions): Promise<FacetHost>;
|
|
4
|
+
export declare function createStaticFacetLoader(facets: readonly Facet[]): FacetLoader;
|
|
5
|
+
export declare function combineFacetLoaders(loaders: readonly FacetLoader[]): FacetLoader;
|
|
6
|
+
export declare function defineFacet(facet: Facet): Facet;
|
|
7
|
+
export declare function defineService<T>(id: string, options: {
|
|
8
|
+
readonly local: true;
|
|
9
|
+
}): Service<T>;
|
|
10
|
+
export declare function defineService<T>(id: string, ...options: [RemoteServiceContract<T>] extends [never] ? readonly [options: never] : readonly [options?: {
|
|
11
|
+
readonly local?: false;
|
|
12
|
+
}]): Service<T>;
|
|
13
|
+
export declare function createRemoteServiceBinding(options: RemoteServiceBindingOptions): RemoteServiceBinding;
|
|
14
|
+
export declare function replicatedState<T>(source: ReplicatedStateSource<T>, options?: ReplicatedStateSourceOptions): AttachedReplicatedState<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Create authoritative state by taking immutable ownership of an alias-free strict-JSON root.
|
|
17
|
+
* The caller must not mutate `initial` after this call.
|
|
18
|
+
*/
|
|
19
|
+
export declare function replicatedState<T extends object>(initial: T): MutableReplicatedState<T>;
|
|
20
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,uBAAuB,EACvB,KAAK,EACL,SAAS,EACT,WAAW,EACX,YAAY,EAEZ,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,EAC5B,OAAO,EACP,MAAM,YAAY,CAAC;AAEpB,4DAA4D;AAC5D,wBAAsB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAQ/E;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,WAAW,CAO7E;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,CA0BhF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5F,wBAAgB,aAAa,CAAC,CAAC,EAC9B,EAAE,EAAE,MAAM,EACV,GAAG,OAAO,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACnD,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,GACzB,SAAS,CAAC,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,GAChD,OAAO,CAAC,CAAC,CAAC,CAAC;AAQd,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,oBAAoB,CAErG;AAED,wBAAgB,eAAe,CAAC,CAAC,EAChC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAChC,OAAO,CAAC,EAAE,4BAA4B,GACpC,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAC9B;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FacetKernel } from "./facets/host.js";
|
|
2
|
+
import { disposeLoadedFacets } from "./facets/loader.js";
|
|
3
|
+
import { RemoteServiceBindingImpl } from "./services/consumer.js";
|
|
4
|
+
import { attachReplicatedStateSource, MutableReplicatedStateImpl } from "./services/state.js";
|
|
5
|
+
/** Create an active host for one complete set of facets. */
|
|
6
|
+
export async function createFacetHost(options) {
|
|
7
|
+
const kernel = new FacetKernel(options);
|
|
8
|
+
await kernel.activate();
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
services: kernel.provider,
|
|
11
|
+
reload: (facets) => kernel.reload(facets),
|
|
12
|
+
dispose: () => kernel.dispose(),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function createStaticFacetLoader(facets) {
|
|
16
|
+
const loadedFacets = Object.freeze([...facets]);
|
|
17
|
+
return {
|
|
18
|
+
async load() {
|
|
19
|
+
return { facets: loadedFacets, async dispose() { } };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function combineFacetLoaders(loaders) {
|
|
24
|
+
return {
|
|
25
|
+
async load() {
|
|
26
|
+
const loaded = [];
|
|
27
|
+
try {
|
|
28
|
+
for (const loader of loaders)
|
|
29
|
+
loaded.push(await loader.load());
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const cleanupErrors = await disposeLoadedFacets(loaded.reverse());
|
|
33
|
+
if (cleanupErrors.length > 0) {
|
|
34
|
+
throw new AggregateError([error, ...cleanupErrors], "Facet loading and cleanup failed");
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
let disposed = false;
|
|
39
|
+
return {
|
|
40
|
+
facets: Object.freeze(loaded.flatMap(({ facets }) => facets)),
|
|
41
|
+
async dispose() {
|
|
42
|
+
if (disposed)
|
|
43
|
+
return;
|
|
44
|
+
disposed = true;
|
|
45
|
+
const errors = await disposeLoadedFacets([...loaded].reverse());
|
|
46
|
+
if (errors.length === 1)
|
|
47
|
+
throw errors[0];
|
|
48
|
+
if (errors.length > 1)
|
|
49
|
+
throw new AggregateError(errors, "Failed to dispose loaded facets");
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function defineFacet(facet) {
|
|
56
|
+
return facet;
|
|
57
|
+
}
|
|
58
|
+
export function defineService(id, options) {
|
|
59
|
+
if (id.length === 0)
|
|
60
|
+
throw new TypeError("Service ID must not be empty");
|
|
61
|
+
// TODO: check if the reserved namespace should be part of Chord.
|
|
62
|
+
if (id.startsWith("$chord."))
|
|
63
|
+
throw new TypeError("Service IDs beginning with $chord. are reserved");
|
|
64
|
+
return Object.freeze({ id, local: options?.local ?? false });
|
|
65
|
+
}
|
|
66
|
+
export function createRemoteServiceBinding(options) {
|
|
67
|
+
return new RemoteServiceBindingImpl(options);
|
|
68
|
+
}
|
|
69
|
+
export function replicatedState(initialOrSource, options) {
|
|
70
|
+
if (isReplicatedStateSource(initialOrSource))
|
|
71
|
+
return attachReplicatedStateSource(initialOrSource, options);
|
|
72
|
+
return new MutableReplicatedStateImpl(initialOrSource);
|
|
73
|
+
}
|
|
74
|
+
function isReplicatedStateSource(value) {
|
|
75
|
+
return typeof value.attach === "function";
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAiB9F,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAqB;IAC1D,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IACxB,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,CAAC,MAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAC3D,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;KAC/B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAwB;IAC/D,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAChD,OAAO;QACN,KAAK,CAAC,IAAI;YACT,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,KA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C;AAED,MAAM,UAAU,WAAW,CAAC,KAAY;IACvC,OAAO,KAAK,CAAC;AACd,CAAC;AASD,MAAM,UAAU,aAAa,CAAC,EAAU,EAAE,OAAsC;IAC/E,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACzE,iEAAiE;IACjE,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IACrG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAoC;IAC9E,OAAO,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAWD,MAAM,UAAU,eAAe,CAC9B,eAAwD,EACxD,OAAsC;IAEtC,IAAI,uBAAuB,CAAC,eAAe,CAAC;QAAE,OAAO,2BAA2B,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC3G,OAAO,IAAI,0BAA0B,CAAC,eAAe,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa;IAC7C,OAAO,OAAQ,KAAuC,CAAC,MAAM,KAAK,UAAU,CAAC;AAC9E,CAAC","sourcesContent":["import { FacetKernel } from \"./facets/host.ts\";\nimport { disposeLoadedFacets } from \"./facets/loader.ts\";\nimport { RemoteServiceBindingImpl } from \"./services/consumer.ts\";\nimport { attachReplicatedStateSource, MutableReplicatedStateImpl } from \"./services/state.ts\";\nimport type {\n\tAttachedReplicatedState,\n\tFacet,\n\tFacetHost,\n\tFacetLoader,\n\tFacetOptions,\n\tLoadedFacets,\n\tMutableReplicatedState,\n\tRemoteServiceBinding,\n\tRemoteServiceBindingOptions,\n\tRemoteServiceContract,\n\tReplicatedStateSource,\n\tReplicatedStateSourceOptions,\n\tService,\n} from \"./types.ts\";\n\n/** Create an active host for one complete set of facets. */\nexport async function createFacetHost(options: FacetOptions): Promise<FacetHost> {\n\tconst kernel = new FacetKernel(options);\n\tawait kernel.activate();\n\treturn Object.freeze({\n\t\tservices: kernel.provider,\n\t\treload: (facets: readonly Facet[]) => kernel.reload(facets),\n\t\tdispose: () => kernel.dispose(),\n\t});\n}\n\nexport function createStaticFacetLoader(facets: readonly Facet[]): FacetLoader {\n\tconst loadedFacets = Object.freeze([...facets]);\n\treturn {\n\t\tasync load() {\n\t\t\treturn { facets: loadedFacets, async dispose() {} };\n\t\t},\n\t};\n}\n\nexport function combineFacetLoaders(loaders: readonly FacetLoader[]): FacetLoader {\n\treturn {\n\t\tasync load() {\n\t\t\tconst loaded: LoadedFacets[] = [];\n\t\t\ttry {\n\t\t\t\tfor (const loader of loaders) loaded.push(await loader.load());\n\t\t\t} catch (error) {\n\t\t\t\tconst cleanupErrors = await disposeLoadedFacets(loaded.reverse());\n\t\t\t\tif (cleanupErrors.length > 0) {\n\t\t\t\t\tthrow new AggregateError([error, ...cleanupErrors], \"Facet loading and cleanup failed\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tlet disposed = false;\n\t\t\treturn {\n\t\t\t\tfacets: Object.freeze(loaded.flatMap(({ facets }) => facets)),\n\t\t\t\tasync dispose() {\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tdisposed = true;\n\t\t\t\t\tconst errors = await disposeLoadedFacets([...loaded].reverse());\n\t\t\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose loaded facets\");\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function defineFacet(facet: Facet): Facet {\n\treturn facet;\n}\n\nexport function defineService<T>(id: string, options: { readonly local: true }): Service<T>;\nexport function defineService<T>(\n\tid: string,\n\t...options: [RemoteServiceContract<T>] extends [never]\n\t\t? readonly [options: never]\n\t\t: readonly [options?: { readonly local?: false }]\n): Service<T>;\nexport function defineService(id: string, options?: { readonly local?: boolean }): Service<unknown> {\n\tif (id.length === 0) throw new TypeError(\"Service ID must not be empty\");\n\t// TODO: check if the reserved namespace should be part of Chord.\n\tif (id.startsWith(\"$chord.\")) throw new TypeError(\"Service IDs beginning with $chord. are reserved\");\n\treturn Object.freeze({ id, local: options?.local ?? false });\n}\n\nexport function createRemoteServiceBinding(options: RemoteServiceBindingOptions): RemoteServiceBinding {\n\treturn new RemoteServiceBindingImpl(options);\n}\n\nexport function replicatedState<T>(\n\tsource: ReplicatedStateSource<T>,\n\toptions?: ReplicatedStateSourceOptions,\n): AttachedReplicatedState<T>;\n/**\n * Create authoritative state by taking immutable ownership of an alias-free strict-JSON root.\n * The caller must not mutate `initial` after this call.\n */\nexport function replicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\nexport function replicatedState(\n\tinitialOrSource: object | ReplicatedStateSource<unknown>,\n\toptions?: ReplicatedStateSourceOptions,\n): MutableReplicatedState<object> | AttachedReplicatedState<unknown> {\n\tif (isReplicatedStateSource(initialOrSource)) return attachReplicatedStateSource(initialOrSource, options);\n\treturn new MutableReplicatedStateImpl(initialOrSource);\n}\n\nfunction isReplicatedStateSource(value: object): value is ReplicatedStateSource<unknown> {\n\treturn typeof (value as { readonly attach?: unknown }).attach === \"function\";\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { BundleFacetsOptions, BundleFacetsResult, FacetBundlePlatform, } from "./node/bundle.ts";
|
|
2
|
+
export { bundleFacets } from "./node/bundle.ts";
|
|
3
|
+
export type { FacetBundleEntry, FacetBundleManifest } from "./node/manifest.ts";
|
|
4
|
+
export type { BundleFacetPackageOptions, BundleFacetPackageResult } from "./node/package.ts";
|
|
5
|
+
export { bundleFacetPackage } from "./node/package.ts";
|
|
6
|
+
//# sourceMappingURL=bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAChF,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/bundler.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export type {\n\tBundleFacetsOptions,\n\tBundleFacetsResult,\n\tFacetBundlePlatform,\n} from \"./node/bundle.ts\";\nexport { bundleFacets } from \"./node/bundle.ts\";\nexport type { FacetBundleEntry, FacetBundleManifest } from \"./node/manifest.ts\";\nexport type { BundleFacetPackageOptions, BundleFacetPackageResult } from \"./node/package.ts\";\nexport { bundleFacetPackage } from \"./node/package.ts\";\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context, ContextKey } from "../types.ts";
|
|
2
|
+
export declare const BACKGROUND_CONTEXT: Context;
|
|
3
|
+
export declare const TODO_CONTEXT: Context;
|
|
4
|
+
export declare function createContextKey<T>(description: string): ContextKey<T>;
|
|
5
|
+
/** Derive a context containing one additional or replaced value. */
|
|
6
|
+
export declare function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context;
|
|
7
|
+
/**
|
|
8
|
+
* Derive a context cancelled by either the parent signal or the supplied signal.
|
|
9
|
+
* The parent context remains unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withAbortSignal(signal: AbortSignal, context: Context): Context;
|
|
12
|
+
/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */
|
|
13
|
+
export declare function withoutAbortSignal(context: Context): Context;
|
|
14
|
+
/** Derive an independently cancellable child context. */
|
|
15
|
+
export declare function withCancel(context: Context): {
|
|
16
|
+
readonly context: Context;
|
|
17
|
+
readonly cancel: (reason?: unknown) => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Observe a promise until it settles or the invocation is cancelled.
|
|
21
|
+
* Cancellation rejects only this waiter; it does not cancel the underlying promise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function awaitWithContext<T>(promise: Promise<T>, context: Context): Promise<T>;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAsDvD,eAAO,MAAM,kBAAkB,EAAE,OAA0D,CAAC;AAC5F,eAAO,MAAM,YAAY,EAAE,OAAoD,CAAC;AAEhF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAEtE;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAE1F;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAI9E;AAED,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,CAMA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAkBrF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const ABORT_SIGNAL_CONTEXT_KEY = Object.freeze({
|
|
2
|
+
token: Symbol("chord.abortSignal"),
|
|
3
|
+
});
|
|
4
|
+
class BaseContext {
|
|
5
|
+
get abortSignal() {
|
|
6
|
+
return this.value(ABORT_SIGNAL_CONTEXT_KEY);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class EmptyContext extends BaseContext {
|
|
10
|
+
#name;
|
|
11
|
+
constructor(name) {
|
|
12
|
+
super();
|
|
13
|
+
this.#name = name;
|
|
14
|
+
}
|
|
15
|
+
value(_key) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return this.#name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class ContextValue extends BaseContext {
|
|
23
|
+
#parent;
|
|
24
|
+
#key;
|
|
25
|
+
#value;
|
|
26
|
+
constructor(parent, key, value) {
|
|
27
|
+
super();
|
|
28
|
+
this.#parent = parent;
|
|
29
|
+
this.#key = key;
|
|
30
|
+
this.#value = value;
|
|
31
|
+
}
|
|
32
|
+
value(key) {
|
|
33
|
+
if (key.token === this.#key.token)
|
|
34
|
+
return this.#value;
|
|
35
|
+
return this.#parent.value(key);
|
|
36
|
+
}
|
|
37
|
+
toString() {
|
|
38
|
+
return `${this.#parent}.WithValue(${this.#key.token.description ?? "anonymous"})`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const BACKGROUND_CONTEXT = new EmptyContext("[Context BACKGROUND_CONTEXT]");
|
|
42
|
+
export const TODO_CONTEXT = new EmptyContext("[Context TODO_CONTEXT]");
|
|
43
|
+
export function createContextKey(description) {
|
|
44
|
+
return Object.freeze({ token: Symbol(description) });
|
|
45
|
+
}
|
|
46
|
+
/** Derive a context containing one additional or replaced value. */
|
|
47
|
+
export function withContextValue(key, value, parent) {
|
|
48
|
+
return new ContextValue(parent, key, value);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derive a context cancelled by either the parent signal or the supplied signal.
|
|
52
|
+
* The parent context remains unchanged.
|
|
53
|
+
*/
|
|
54
|
+
export function withAbortSignal(signal, context) {
|
|
55
|
+
const parentSignal = context.abortSignal;
|
|
56
|
+
const combined = parentSignal === undefined ? signal : AbortSignal.any([parentSignal, signal]);
|
|
57
|
+
return withContextValue(ABORT_SIGNAL_CONTEXT_KEY, combined, context);
|
|
58
|
+
}
|
|
59
|
+
/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */
|
|
60
|
+
export function withoutAbortSignal(context) {
|
|
61
|
+
return withContextValue(ABORT_SIGNAL_CONTEXT_KEY, undefined, context);
|
|
62
|
+
}
|
|
63
|
+
/** Derive an independently cancellable child context. */
|
|
64
|
+
export function withCancel(context) {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
return {
|
|
67
|
+
context: withAbortSignal(controller.signal, context),
|
|
68
|
+
cancel: (reason) => controller.abort(reason),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Observe a promise until it settles or the invocation is cancelled.
|
|
73
|
+
* Cancellation rejects only this waiter; it does not cancel the underlying promise.
|
|
74
|
+
*/
|
|
75
|
+
export function awaitWithContext(promise, context) {
|
|
76
|
+
const signal = context.abortSignal;
|
|
77
|
+
if (signal === undefined)
|
|
78
|
+
return promise;
|
|
79
|
+
if (signal.aborted)
|
|
80
|
+
return Promise.reject(abortError(signal));
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const onAbort = () => reject(abortError(signal));
|
|
83
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
84
|
+
void promise.then((value) => {
|
|
85
|
+
signal.removeEventListener("abort", onAbort);
|
|
86
|
+
resolve(value);
|
|
87
|
+
}, (error) => {
|
|
88
|
+
signal.removeEventListener("abort", onAbort);
|
|
89
|
+
reject(error);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function abortError(signal) {
|
|
94
|
+
const reason = signal.reason;
|
|
95
|
+
return reason instanceof Error ? reason : new DOMException("The operation was aborted", "AbortError");
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAAwC,MAAM,CAAC,MAAM,CAAC;IACnF,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC;CAClC,CAAC,CAAC;AAEH,MAAe,WAAW;IAIzB,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC7C,CAAC;CACD;AAED,MAAM,YAAa,SAAQ,WAAW;IAC5B,KAAK,CAAS;IAEvB,YAAY,IAAY;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAI,IAAmB;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAED,MAAM,YAAgB,SAAQ,WAAW;IAC/B,OAAO,CAAU;IACjB,IAAI,CAAgB;IACpB,MAAM,CAAI;IAEnB,YAAY,MAAe,EAAE,GAAkB,EAAE,KAAQ;QACxD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MA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AC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,CAAC;QACf,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAAmB;IACtC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IACtC,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvG,CAAC","sourcesContent":["import type { Context, ContextKey } from \"../types.ts\";\n\nconst ABORT_SIGNAL_CONTEXT_KEY: ContextKey<AbortSignal | undefined> = Object.freeze({\n\ttoken: Symbol(\"chord.abortSignal\"),\n});\n\nabstract class BaseContext implements Context {\n\tabstract value<T>(key: ContextKey<T>): T | undefined;\n\tabstract toString(): string;\n\n\tget abortSignal(): AbortSignal | undefined {\n\t\treturn this.value(ABORT_SIGNAL_CONTEXT_KEY);\n\t}\n}\n\nclass EmptyContext extends BaseContext {\n\treadonly #name: string;\n\n\tconstructor(name: string) {\n\t\tsuper();\n\t\tthis.#name = name;\n\t}\n\n\tvalue<T>(_key: ContextKey<T>): T | undefined {\n\t\treturn undefined;\n\t}\n\n\ttoString(): string {\n\t\treturn this.#name;\n\t}\n}\n\nclass ContextValue<T> extends BaseContext {\n\treadonly #parent: Context;\n\treadonly #key: ContextKey<T>;\n\treadonly #value: T;\n\n\tconstructor(parent: Context, key: ContextKey<T>, value: T) {\n\t\tsuper();\n\t\tthis.#parent = parent;\n\t\tthis.#key = key;\n\t\tthis.#value = value;\n\t}\n\n\tvalue<Value>(key: ContextKey<Value>): Value | undefined {\n\t\tif (key.token === this.#key.token) return this.#value as unknown as Value;\n\t\treturn this.#parent.value(key);\n\t}\n\n\ttoString(): string {\n\t\treturn `${this.#parent}.WithValue(${this.#key.token.description ?? \"anonymous\"})`;\n\t}\n}\n\nexport const BACKGROUND_CONTEXT: Context = new EmptyContext(\"[Context BACKGROUND_CONTEXT]\");\nexport const TODO_CONTEXT: Context = new EmptyContext(\"[Context TODO_CONTEXT]\");\n\nexport function createContextKey<T>(description: string): ContextKey<T> {\n\treturn Object.freeze({ token: Symbol(description) });\n}\n\n/** Derive a context containing one additional or replaced value. */\nexport function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context {\n\treturn new ContextValue(parent, key, value);\n}\n\n/**\n * Derive a context cancelled by either the parent signal or the supplied signal.\n * The parent context remains unchanged.\n */\nexport function withAbortSignal(signal: AbortSignal, context: Context): Context {\n\tconst parentSignal = context.abortSignal;\n\tconst combined = parentSignal === undefined ? signal : AbortSignal.any([parentSignal, signal]);\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, combined, context);\n}\n\n/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */\nexport function withoutAbortSignal(context: Context): Context {\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, undefined, context);\n}\n\n/** Derive an independently cancellable child context. */\nexport function withCancel(context: Context): {\n\treadonly context: Context;\n\treadonly cancel: (reason?: unknown) => void;\n} {\n\tconst controller = new AbortController();\n\treturn {\n\t\tcontext: withAbortSignal(controller.signal, context),\n\t\tcancel: (reason?: unknown) => controller.abort(reason),\n\t};\n}\n\n/**\n * Observe a promise until it settles or the invocation is cancelled.\n * Cancellation rejects only this waiter; it does not cancel the underlying promise.\n */\nexport function awaitWithContext<T>(promise: Promise<T>, context: Context): Promise<T> {\n\tconst signal = context.abortSignal;\n\tif (signal === undefined) return promise;\n\tif (signal.aborted) return Promise.reject(abortError(signal));\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = (): void => reject(abortError(signal));\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(\n\t\t\t(value) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(error);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction abortError(signal: AbortSignal): Error {\n\tconst reason: unknown = signal.reason;\n\treturn reason instanceof Error ? reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Op } from "./index.ts";
|
|
2
|
+
/** Apply self-produced trusted operations while copying each touched container once. */
|
|
3
|
+
export declare function applyImmutableTrusted<T>(target: T, operations: readonly Op[]): T;
|
|
4
|
+
//# sourceMappingURL=apply-immutable-trusted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-immutable-trusted.d.ts","sourceRoot":"","sources":["../../src/delta/apply-immutable-trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAa,MAAM,YAAY,CAAC;AAYhD,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CA8ChF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const DATA_DESCRIPTOR = {
|
|
2
|
+
value: undefined,
|
|
3
|
+
writable: true,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
};
|
|
7
|
+
/** Apply self-produced trusted operations while copying each touched container once. */
|
|
8
|
+
export function applyImmutableTrusted(target, operations) {
|
|
9
|
+
let root = target;
|
|
10
|
+
const owned = new WeakSet();
|
|
11
|
+
for (const operation of operations) {
|
|
12
|
+
if (operation[0] === "r") {
|
|
13
|
+
root = operation[1];
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (operation[0] === "p" || operation[0] === "m") {
|
|
17
|
+
const copied = copyPath(root, operation[1], operation[1].length, owned);
|
|
18
|
+
root = copied.root;
|
|
19
|
+
if (!Array.isArray(copied.target))
|
|
20
|
+
throw new TypeError("Trusted array operation target is not an array");
|
|
21
|
+
if (operation[0] === "p")
|
|
22
|
+
spliceTrusted(copied.target, operation[2], operation[3], operation[4]);
|
|
23
|
+
else
|
|
24
|
+
permuteTrusted(copied.target, operation[2]);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const path = operation[1];
|
|
28
|
+
const copied = copyPath(root, path, path.length - 1, owned);
|
|
29
|
+
root = copied.root;
|
|
30
|
+
const key = path[path.length - 1];
|
|
31
|
+
switch (operation[0]) {
|
|
32
|
+
case "s":
|
|
33
|
+
defineData(copied.target, key, operation[2]);
|
|
34
|
+
break;
|
|
35
|
+
case "d":
|
|
36
|
+
if (Array.isArray(copied.target)) {
|
|
37
|
+
if (typeof key !== "number")
|
|
38
|
+
throw new TypeError("Trusted array deletion key is not numeric");
|
|
39
|
+
spliceTrusted(copied.target, key, 1, []);
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
Reflect.deleteProperty(copied.target, key);
|
|
43
|
+
break;
|
|
44
|
+
case "a": {
|
|
45
|
+
const current = read(copied.target, key);
|
|
46
|
+
if (typeof current !== "string")
|
|
47
|
+
throw new TypeError("Trusted append target is not a string");
|
|
48
|
+
defineData(copied.target, key, `${current}${operation[2]}`);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "t": {
|
|
52
|
+
const current = read(copied.target, key);
|
|
53
|
+
if (typeof current !== "string")
|
|
54
|
+
throw new TypeError("Trusted truncate target is not a string");
|
|
55
|
+
defineData(copied.target, key, current.slice(operation[2]));
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return root;
|
|
61
|
+
}
|
|
62
|
+
function copyPath(root, path, length, owned) {
|
|
63
|
+
if (!isContainer(root))
|
|
64
|
+
throw new TypeError("Trusted operation root is not a container");
|
|
65
|
+
let copiedRoot = root;
|
|
66
|
+
if (!owned.has(root)) {
|
|
67
|
+
copiedRoot = shallowCopy(root);
|
|
68
|
+
owned.add(copiedRoot);
|
|
69
|
+
}
|
|
70
|
+
let destination = copiedRoot;
|
|
71
|
+
for (let index = 0; index < length; index++) {
|
|
72
|
+
const segment = path[index];
|
|
73
|
+
const child = read(destination, segment);
|
|
74
|
+
if (!isContainer(child))
|
|
75
|
+
throw new TypeError("Trusted operation path is not a container");
|
|
76
|
+
if (owned.has(child)) {
|
|
77
|
+
destination = child;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const copy = shallowCopy(child);
|
|
81
|
+
defineData(destination, segment, copy);
|
|
82
|
+
owned.add(copy);
|
|
83
|
+
destination = copy;
|
|
84
|
+
}
|
|
85
|
+
return { root: copiedRoot, target: destination };
|
|
86
|
+
}
|
|
87
|
+
function shallowCopy(value) {
|
|
88
|
+
if (Array.isArray(value))
|
|
89
|
+
return Array.from(value);
|
|
90
|
+
const result = Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype);
|
|
91
|
+
for (const key of Object.keys(value))
|
|
92
|
+
defineData(result, key, value[key]);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function read(target, key) {
|
|
96
|
+
return target[key];
|
|
97
|
+
}
|
|
98
|
+
function defineData(target, key, value) {
|
|
99
|
+
DATA_DESCRIPTOR.value = value;
|
|
100
|
+
Object.defineProperty(target, key, DATA_DESCRIPTOR);
|
|
101
|
+
DATA_DESCRIPTOR.value = undefined;
|
|
102
|
+
}
|
|
103
|
+
function spliceTrusted(target, start, remove, items) {
|
|
104
|
+
const oldLength = target.length;
|
|
105
|
+
const delta = items.length - remove;
|
|
106
|
+
if (delta > 0) {
|
|
107
|
+
target.length = oldLength + delta;
|
|
108
|
+
target.copyWithin(start + items.length, start + remove, oldLength);
|
|
109
|
+
}
|
|
110
|
+
else if (delta < 0) {
|
|
111
|
+
target.copyWithin(start + items.length, start + remove, oldLength);
|
|
112
|
+
target.length = oldLength + delta;
|
|
113
|
+
}
|
|
114
|
+
for (let index = 0; index < items.length; index++)
|
|
115
|
+
defineData(target, start + index, items[index]);
|
|
116
|
+
}
|
|
117
|
+
function permuteTrusted(target, permutation) {
|
|
118
|
+
if (target.length !== permutation.length)
|
|
119
|
+
throw new TypeError("Trusted permutation length mismatch");
|
|
120
|
+
const previous = target.slice();
|
|
121
|
+
for (let index = 0; index < permutation.length; index++)
|
|
122
|
+
target[index] = previous[permutation[index]];
|
|
123
|
+
}
|
|
124
|
+
function isContainer(value) {
|
|
125
|
+
return value !== null && typeof value === "object";
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=apply-immutable-trusted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-immutable-trusted.js","sourceRoot":"","sources":["../../src/delta/apply-immutable-trusted.ts"],"names":[],"mappings":"AAMA,MAAM,eAAe,GAAuB;IAC3C,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;CAClB,CAAC;AAEF,wFAAwF;AACxF,MAAM,UAAU,qBAAqB,CAAI,MAAS,EAAE,UAAyB;IAC5E,IAAI,IAAI,GAAG,MAA8B,CAAC;IAC1C,MAAM,KAAK,GAAG,IAAI,OAAO,EAAU,CAAC;IACpC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACpB,SAAS;QACV,CAAC;QACD,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACxE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACnB,IAAI,CAAC,KAAK,CAAC,OAA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AG,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE;QAAE,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAE,CAAE,CAAC;AACzG,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC","sourcesContent":["import type { JsonValue } from \"../types.ts\";\nimport type { Op, Path, Seg } from \"./index.ts\";\n\ntype JsonContainer = JsonValue[] | Record<string, JsonValue>;\ntype CopiedPath = { root: JsonValue; target: JsonContainer };\n\nconst DATA_DESCRIPTOR: PropertyDescriptor = {\n\tvalue: undefined,\n\twritable: true,\n\tenumerable: true,\n\tconfigurable: true,\n};\n\n/** Apply self-produced trusted operations while copying each touched container once. */\nexport function applyImmutableTrusted<T>(target: T, operations: readonly Op[]): T {\n\tlet root = target as unknown as JsonValue;\n\tconst owned = new WeakSet<object>();\n\tfor (const operation of operations) {\n\t\tif (operation[0] === \"r\") {\n\t\t\troot = operation[1];\n\t\t\tcontinue;\n\t\t}\n\t\tif (operation[0] === \"p\" || operation[0] === \"m\") {\n\t\t\tconst copied = copyPath(root, operation[1], operation[1].length, owned);\n\t\t\troot = copied.root;\n\t\t\tif (!Array.isArray(copied.target)) throw new TypeError(\"Trusted array operation target is not an array\");\n\t\t\tif (operation[0] === \"p\") spliceTrusted(copied.target, operation[2], operation[3], operation[4]);\n\t\t\telse permuteTrusted(copied.target, operation[2]);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = operation[1];\n\t\tconst copied = copyPath(root, path, path.length - 1, owned);\n\t\troot = copied.root;\n\t\tconst key = path[path.length - 1]!;\n\t\tswitch (operation[0]) {\n\t\t\tcase \"s\":\n\t\t\t\tdefineData(copied.target, key, operation[2]);\n\t\t\t\tbreak;\n\t\t\tcase \"d\":\n\t\t\t\tif (Array.isArray(copied.target)) {\n\t\t\t\t\tif (typeof key !== \"number\") throw new TypeError(\"Trusted array deletion key is not numeric\");\n\t\t\t\t\tspliceTrusted(copied.target, key, 1, []);\n\t\t\t\t} else Reflect.deleteProperty(copied.target, key);\n\t\t\t\tbreak;\n\t\t\tcase \"a\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted append target is not a string\");\n\t\t\t\tdefineData(copied.target, key, `${current}${operation[2]}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"t\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted truncate target is not a string\");\n\t\t\t\tdefineData(copied.target, key, current.slice(operation[2]));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\nfunction copyPath(root: JsonValue, path: Path, length: number, owned: WeakSet<object>): CopiedPath {\n\tif (!isContainer(root)) throw new TypeError(\"Trusted operation root is not a container\");\n\tlet copiedRoot = root;\n\tif (!owned.has(root)) {\n\t\tcopiedRoot = shallowCopy(root);\n\t\towned.add(copiedRoot);\n\t}\n\tlet destination = copiedRoot as JsonContainer;\n\tfor (let index = 0; index < length; index++) {\n\t\tconst segment = path[index]!;\n\t\tconst child = read(destination, segment);\n\t\tif (!isContainer(child)) throw new TypeError(\"Trusted operation path is not a container\");\n\t\tif (owned.has(child)) {\n\t\t\tdestination = child;\n\t\t\tcontinue;\n\t\t}\n\t\tconst copy = shallowCopy(child);\n\t\tdefineData(destination, segment, copy);\n\t\towned.add(copy);\n\t\tdestination = copy;\n\t}\n\treturn { root: copiedRoot, target: destination };\n}\n\nfunction shallowCopy(value: JsonContainer): JsonContainer {\n\tif (Array.isArray(value)) return Array.from(value);\n\tconst result = Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype) as Record<\n\t\tstring,\n\t\tJsonValue\n\t>;\n\tfor (const key of Object.keys(value)) defineData(result, key, value[key]!);\n\treturn result;\n}\n\nfunction read(target: JsonContainer, key: Seg): JsonValue {\n\treturn (target as Record<Seg, JsonValue>)[key]!;\n}\n\nfunction defineData(target: JsonContainer, key: Seg, value: JsonValue): void {\n\tDATA_DESCRIPTOR.value = value;\n\tObject.defineProperty(target, key, DATA_DESCRIPTOR);\n\tDATA_DESCRIPTOR.value = undefined;\n}\n\nfunction spliceTrusted(target: JsonValue[], start: number, remove: number, items: readonly JsonValue[]): void {\n\tconst oldLength = target.length;\n\tconst delta = items.length - remove;\n\tif (delta > 0) {\n\t\ttarget.length = oldLength + delta;\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t} else if (delta < 0) {\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t\ttarget.length = oldLength + delta;\n\t}\n\tfor (let index = 0; index < items.length; index++) defineData(target, start + index, items[index]!);\n}\n\nfunction permuteTrusted(target: JsonValue[], permutation: readonly number[]): void {\n\tif (target.length !== permutation.length) throw new TypeError(\"Trusted permutation length mismatch\");\n\tconst previous = target.slice();\n\tfor (let index = 0; index < permutation.length; index++) target[index] = previous[permutation[index]!]!;\n}\n\nfunction isContainer(value: unknown): value is JsonContainer {\n\treturn value !== null && typeof value === \"object\";\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JsonValue } from "../types.ts";
|
|
2
|
+
import { type Op } from "./index.ts";
|
|
3
|
+
/** Compute a compact operation batch from two immutable JSON revisions. */
|
|
4
|
+
export declare function diffRevisions(before: JsonValue, after: JsonValue): Op[];
|
|
5
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/delta/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAqB,KAAK,EAAE,EAAmD,MAAM,YAAY,CAAC;AA8fzG,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,EAAE,EAAE,CAUvE"}
|