doxum 0.1.16 → 0.1.17

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.
@@ -0,0 +1,101 @@
1
+ import { J as Infer, L as CollectionId, R as CollectionNode, Z as ObjectNode, _ as Unsubscribe, et as PathValueOf, m as Synchronous, nt as SchemaPath, s as DocumentReadable, tt as ReadonlyValue, v as Readable, x as CollectionImpact, z as CollectionPath } from "./contract-CATCCVu5.js";
2
+
3
+ //#region core/src/projection/contract.d.ts
4
+ /** The one processor-facing collection transition protocol. */
5
+ type CollectionChange<K extends string, V> = {
6
+ readonly kind: 'reset';
7
+ } | {
8
+ readonly kind: 'incremental';
9
+ readonly added: readonly {
10
+ readonly key: K;
11
+ readonly after: V;
12
+ }[];
13
+ readonly updated: readonly {
14
+ readonly key: K;
15
+ readonly before: V;
16
+ readonly after: V;
17
+ }[];
18
+ readonly removed: readonly {
19
+ readonly key: K;
20
+ readonly before: V;
21
+ }[];
22
+ readonly order?: {
23
+ readonly before: readonly K[];
24
+ readonly after: readonly K[];
25
+ };
26
+ };
27
+ type CollectionRead<K extends string, V> = {
28
+ get(key: K): V | undefined;
29
+ has(key: K): boolean;
30
+ ids(): readonly K[];
31
+ };
32
+ type ExternalCollectionRead<K extends string, V> = {
33
+ readonly get: (key: K) => V | undefined;
34
+ readonly has: (key: K) => boolean;
35
+ readonly ids: () => readonly K[];
36
+ };
37
+ type ExternalValueSource<T> = {
38
+ readonly kind: 'value';
39
+ current(): T;
40
+ revision(): number;
41
+ subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;
42
+ };
43
+ type ExternalCollectionSource<K extends string, V> = {
44
+ readonly kind: 'collection';
45
+ current(): ExternalCollectionRead<K, V>;
46
+ revision(): number;
47
+ subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;
48
+ };
49
+ type ExternalValueEvent<T> = {
50
+ readonly value: T;
51
+ readonly revision: number;
52
+ readonly reset?: boolean;
53
+ readonly cause?: unknown;
54
+ };
55
+ type ExternalCollectionEvent<K extends string, V> = {
56
+ /** Stable read from the source before this event or external batch. */readonly previous: ExternalCollectionRead<K, V>;
57
+ readonly revision: number; /** Optional document-style hint; the adapter resolves the canonical change. */
58
+ readonly impact?: CollectionImpact<K>;
59
+ readonly cause?: unknown;
60
+ };
61
+ type CollectionDraft<K extends string, V> = {
62
+ set(key: K, value: V): void;
63
+ remove(key: K): void;
64
+ order(ids: readonly K[]): void;
65
+ };
66
+ declare class ProjectionError extends Error {
67
+ readonly phase: 'processor' | 'listener' | 'source' | 'blocked';
68
+ readonly identity: string;
69
+ readonly revisions: readonly number[];
70
+ constructor(phase: 'processor' | 'listener' | 'source' | 'blocked', identity: string, revisions: readonly number[], cause: unknown);
71
+ }
72
+ declare class ProjectionDisposedError extends Error {
73
+ constructor();
74
+ }
75
+ //#endregion
76
+ //#region core/src/projection/definition.d.ts
77
+ declare const projectionDefinition: unique symbol;
78
+ declare const projectionChanges: unique symbol;
79
+ declare const writableInput: unique symbol;
80
+ /** A lazy, reusable projection definition with no runtime-owned state. */
81
+ type Projection<T, C = undefined> = {
82
+ readonly [projectionDefinition]: T;
83
+ readonly [projectionChanges]: C;
84
+ };
85
+ /** A runtime-local writable projection definition. */
86
+ type Input<T> = Projection<T> & {
87
+ readonly [writableInput]: true;
88
+ };
89
+ type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
90
+ declare const input: <T>(initial: T, equality?: (previous: T, next: T) => boolean) => Input<T>;
91
+ /** Establish a lazy reactive boundary from a document, readable, or external source. */
92
+ declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
93
+ declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
94
+ declare function observe<K extends string, V>(source: ExternalCollectionSource<K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
95
+ declare function observe<T>(readable: Readable<T>): Projection<T>;
96
+ declare function observe<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<ReadonlyMap<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>, CollectionChange<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>>;
97
+ declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
98
+ declare function derive<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
99
+ //#endregion
100
+ export { observe as a, CollectionRead as c, ExternalCollectionSource as d, ExternalValueEvent as f, ProjectionError as h, input as i, ExternalCollectionEvent as l, ProjectionDisposedError as m, Projection as n, CollectionChange as o, ExternalValueSource as p, derive as r, CollectionDraft as s, Input as t, ExternalCollectionRead as u };
101
+ //# sourceMappingURL=definition-BdLGD8Rq.d.ts.map
@@ -0,0 +1,101 @@
1
+ import { J as Infer, L as CollectionId, R as CollectionNode, Z as ObjectNode, _ as Unsubscribe, et as PathValueOf, m as Synchronous, nt as SchemaPath, s as DocumentReadable, tt as ReadonlyValue, v as Readable, x as CollectionImpact, z as CollectionPath } from "./contract-XmKnroJq.cjs";
2
+
3
+ //#region core/src/projection/contract.d.ts
4
+ /** The one processor-facing collection transition protocol. */
5
+ type CollectionChange<K extends string, V> = {
6
+ readonly kind: 'reset';
7
+ } | {
8
+ readonly kind: 'incremental';
9
+ readonly added: readonly {
10
+ readonly key: K;
11
+ readonly after: V;
12
+ }[];
13
+ readonly updated: readonly {
14
+ readonly key: K;
15
+ readonly before: V;
16
+ readonly after: V;
17
+ }[];
18
+ readonly removed: readonly {
19
+ readonly key: K;
20
+ readonly before: V;
21
+ }[];
22
+ readonly order?: {
23
+ readonly before: readonly K[];
24
+ readonly after: readonly K[];
25
+ };
26
+ };
27
+ type CollectionRead<K extends string, V> = {
28
+ get(key: K): V | undefined;
29
+ has(key: K): boolean;
30
+ ids(): readonly K[];
31
+ };
32
+ type ExternalCollectionRead<K extends string, V> = {
33
+ readonly get: (key: K) => V | undefined;
34
+ readonly has: (key: K) => boolean;
35
+ readonly ids: () => readonly K[];
36
+ };
37
+ type ExternalValueSource<T> = {
38
+ readonly kind: 'value';
39
+ current(): T;
40
+ revision(): number;
41
+ subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;
42
+ };
43
+ type ExternalCollectionSource<K extends string, V> = {
44
+ readonly kind: 'collection';
45
+ current(): ExternalCollectionRead<K, V>;
46
+ revision(): number;
47
+ subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;
48
+ };
49
+ type ExternalValueEvent<T> = {
50
+ readonly value: T;
51
+ readonly revision: number;
52
+ readonly reset?: boolean;
53
+ readonly cause?: unknown;
54
+ };
55
+ type ExternalCollectionEvent<K extends string, V> = {
56
+ /** Stable read from the source before this event or external batch. */readonly previous: ExternalCollectionRead<K, V>;
57
+ readonly revision: number; /** Optional document-style hint; the adapter resolves the canonical change. */
58
+ readonly impact?: CollectionImpact<K>;
59
+ readonly cause?: unknown;
60
+ };
61
+ type CollectionDraft<K extends string, V> = {
62
+ set(key: K, value: V): void;
63
+ remove(key: K): void;
64
+ order(ids: readonly K[]): void;
65
+ };
66
+ declare class ProjectionError extends Error {
67
+ readonly phase: 'processor' | 'listener' | 'source' | 'blocked';
68
+ readonly identity: string;
69
+ readonly revisions: readonly number[];
70
+ constructor(phase: 'processor' | 'listener' | 'source' | 'blocked', identity: string, revisions: readonly number[], cause: unknown);
71
+ }
72
+ declare class ProjectionDisposedError extends Error {
73
+ constructor();
74
+ }
75
+ //#endregion
76
+ //#region core/src/projection/definition.d.ts
77
+ declare const projectionDefinition: unique symbol;
78
+ declare const projectionChanges: unique symbol;
79
+ declare const writableInput: unique symbol;
80
+ /** A lazy, reusable projection definition with no runtime-owned state. */
81
+ type Projection<T, C = undefined> = {
82
+ readonly [projectionDefinition]: T;
83
+ readonly [projectionChanges]: C;
84
+ };
85
+ /** A runtime-local writable projection definition. */
86
+ type Input<T> = Projection<T> & {
87
+ readonly [writableInput]: true;
88
+ };
89
+ type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
90
+ declare const input: <T>(initial: T, equality?: (previous: T, next: T) => boolean) => Input<T>;
91
+ /** Establish a lazy reactive boundary from a document, readable, or external source. */
92
+ declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
93
+ declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
94
+ declare function observe<K extends string, V>(source: ExternalCollectionSource<K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
95
+ declare function observe<T>(readable: Readable<T>): Projection<T>;
96
+ declare function observe<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<ReadonlyMap<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>, CollectionChange<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>>;
97
+ declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
98
+ declare function derive<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
99
+ //#endregion
100
+ export { observe as a, CollectionRead as c, ExternalCollectionSource as d, ExternalValueEvent as f, ProjectionError as h, input as i, ExternalCollectionEvent as l, ProjectionDisposedError as m, Projection as n, CollectionChange as o, ExternalValueSource as p, derive as r, CollectionDraft as s, Input as t, ExternalCollectionRead as u };
101
+ //# sourceMappingURL=definition-Bf8Z7xtX.d.cts.map
@@ -38,7 +38,6 @@ function derive(dependencies, compute, equality = Object.is) {
38
38
  isEqual: equality
39
39
  });
40
40
  }
41
- /** Internal source adapters used by observe, not exported publicly. */
42
41
  const defineReadable = (readable, equality = Object.is) => define({
43
42
  kind: "readable",
44
43
  readable,
@@ -69,4 +68,4 @@ const defineIncrementalCollection = (definition) => define({
69
68
  //#endregion
70
69
  export { input as a, derive as i, defineIncrementalValue as n, observe as o, definitionOf as r, defineIncrementalCollection as t };
71
70
 
72
- //# sourceMappingURL=definition-c6XQXzvK.js.map
71
+ //# sourceMappingURL=definition-DUo1lfQ8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-DUo1lfQ8.js","names":[],"sources":["../core/src/projection/definition.ts"],"sourcesContent":["import type { DocumentReadable, Synchronous } from '../runtime/contract';\nimport type {\n CollectionId,\n CollectionPath,\n CollectionNode as SchemaCollectionNode,\n Infer,\n ObjectNode,\n ReadonlyValue,\n SchemaPath,\n PathValueOf,\n} from '../schema';\nimport type { Readable } from './readable';\nimport type {\n CollectionChange,\n ExternalCollectionSource,\n ExternalValueSource,\n GraphSources,\n} from './contract';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const projectionChanges: unique symbol;\ndeclare const writableInput: unique symbol;\n\n/** A lazy, reusable projection definition with no runtime-owned state. */\nexport type Projection<T, C = undefined> = {\n readonly [projectionDefinition]: T;\n readonly [projectionChanges]: C;\n};\n\n/** A runtime-local writable projection definition. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\ntype ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = {\n readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never;\n};\n\ntype Equality = (a: unknown, b: unknown) => boolean;\ntype PathSelector<S extends ObjectNode> = (path: SchemaPath<S['shape']>) => unknown;\n\ntype Definition =\n | { readonly kind: 'input'; readonly initial: unknown; readonly isEqual?: Equality }\n | { readonly kind: 'readable'; readonly readable: Readable<unknown>; readonly isEqual?: Equality }\n | { readonly kind: 'source-value'; readonly source: ExternalValueSource<unknown> }\n | {\n readonly kind: 'source-collection';\n readonly source: ExternalCollectionSource<string, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: DocumentReadable<ObjectNode>;\n readonly selector?: PathSelector<ObjectNode>;\n }\n | {\n readonly kind: 'derive';\n readonly dependencies: readonly Projection<unknown, unknown>[];\n readonly compute: (...values: readonly unknown[]) => unknown;\n readonly isEqual?: Equality;\n }\n | {\n readonly kind: 'incremental-value';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n }\n | {\n readonly kind: 'incremental-collection';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n };\n\ntype DefinitionProjection = Projection<unknown, unknown>;\nconst definitions = new WeakMap<object, Definition>();\n\nconst define = <T, C = undefined>(definition: Definition): Projection<T, C> => {\n const handle = Object.freeze({}) as Projection<T, C>;\n definitions.set(handle, definition);\n return handle;\n};\n\nexport const definitionOf = (projection: DefinitionProjection): Definition => {\n const definition = definitions.get(projection);\n if (!definition) throw new TypeError('Unknown projection definition.');\n return definition;\n};\n\nexport const input = <T>(\n initial: T,\n equality: (previous: T, next: T) => boolean = Object.is\n): Input<T> => define<T>({ kind: 'input', initial, isEqual: equality as Equality }) as Input<T>;\n\n/** Establish a lazy reactive boundary from a document, readable, or external source. */\nexport function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;\nexport function observe<T>(source: ExternalValueSource<T>): Projection<T>;\nexport function observe<K extends string, V>(\n source: ExternalCollectionSource<K, V>\n): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;\nexport function observe<T>(readable: Readable<T>): Projection<T>;\nexport function observe<S extends ObjectNode, P extends CollectionPath>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<\n ReadonlyMap<CollectionId<P>, ReadonlyValue<Infer<SchemaCollectionNode<P>>>>,\n CollectionChange<CollectionId<P>, ReadonlyValue<Infer<SchemaCollectionNode<P>>>>\n>;\nexport function observe<S extends ObjectNode, P>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<PathValueOf<P>>;\nexport function observe<S extends ObjectNode>(\n document:\n | DocumentReadable<S>\n | Readable<unknown>\n | ExternalValueSource<unknown>\n | ExternalCollectionSource<string, unknown>,\n selector?: PathSelector<S>\n): Projection<unknown, unknown> {\n if (isExternalSource(document))\n return document.kind === 'collection'\n ? defineExternalCollection(document)\n : defineExternalValue(document);\n if ('current' in document && typeof document.current === 'function')\n return defineReadable(document as Readable<unknown>);\n return define({\n kind: 'document',\n document: document as DocumentReadable<ObjectNode>,\n selector: selector as PathSelector<ObjectNode> | undefined,\n });\n}\n\nconst isExternalSource = (\n source: unknown\n): source is ExternalValueSource<unknown> | ExternalCollectionSource<string, unknown> => {\n if (!source || typeof source !== 'object') return false;\n const candidate = source as {\n readonly kind?: unknown;\n readonly current?: unknown;\n readonly revision?: unknown;\n readonly subscribe?: unknown;\n };\n return (\n (candidate.kind === 'value' || candidate.kind === 'collection') &&\n typeof candidate.current === 'function' &&\n typeof candidate.revision === 'function' &&\n typeof candidate.subscribe === 'function'\n );\n};\n\nexport function derive<const D extends readonly Projection<unknown, unknown>[], T>(\n dependencies: D,\n compute: (...values: ProjectionValues<D>) => Synchronous<T>,\n equality: (previous: T, next: T) => boolean = Object.is\n): Projection<T> {\n if (!Array.isArray(dependencies) || dependencies.some(value => !definitions.has(value)))\n throw new TypeError('derive dependencies must be projections.');\n const frozen = Object.freeze([...dependencies]) as readonly Projection<unknown, unknown>[];\n return define<T>({\n kind: 'derive',\n dependencies: frozen,\n compute: compute as (...values: readonly unknown[]) => unknown,\n isEqual: equality as Equality,\n });\n}\n\nexport const defineReadable = <T>(\n readable: Readable<T>,\n equality: (a: T, b: T) => boolean = Object.is\n): Projection<T> => define<T>({ kind: 'readable', readable, isEqual: equality as Equality });\n\nexport const defineExternalValue = <T>(source: ExternalValueSource<T>): Projection<T> =>\n define<T>({ kind: 'source-value', source: source as ExternalValueSource<unknown> });\n\nexport const defineExternalCollection = <K extends string, V>(\n source: ExternalCollectionSource<K, V>\n): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>> =>\n define<ReadonlyMap<K, V>, CollectionChange<K, V>>({\n kind: 'source-collection',\n source: source as unknown as ExternalCollectionSource<string, unknown>,\n });\n\nexport const defineIncrementalValue = <T>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: T, b: T) => boolean;\n readonly name?: string;\n}): Projection<T> =>\n define<T>({\n kind: 'incremental-value',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\nexport const defineIncrementalCollection = <K extends string, V>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: V, b: V) => boolean;\n readonly name?: string;\n}): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>> =>\n define<ReadonlyMap<K, V>, CollectionChange<K, V>>({\n kind: 'incremental-collection',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n"],"mappings":";AA0EA,MAAM,8BAAc,IAAI,SAA6B;AAErD,MAAM,UAA4B,eAA6C;CAC7E,MAAM,SAAS,OAAO,OAAO,EAAE,CAAC;AAChC,aAAY,IAAI,QAAQ,WAAW;AACnC,QAAO;;AAGT,MAAa,gBAAgB,eAAiD;CAC5E,MAAM,aAAa,YAAY,IAAI,WAAW;AAC9C,KAAI,CAAC,WAAY,OAAM,IAAI,UAAU,iCAAiC;AACtE,QAAO;;AAGT,MAAa,SACX,SACA,WAA8C,OAAO,OACxC,OAAU;CAAE,MAAM;CAAS;CAAS,SAAS;CAAsB,CAAC;AAoBnF,SAAgB,QACd,UAKA,UAC8B;AAC9B,KAAI,iBAAiB,SAAS,CAC5B,QAAO,SAAS,SAAS,eACrB,yBAAyB,SAAS,GAClC,oBAAoB,SAAS;AACnC,KAAI,aAAa,YAAY,OAAO,SAAS,YAAY,WACvD,QAAO,eAAe,SAA8B;AACtD,QAAO,OAAO;EACZ,MAAM;EACI;EACA;EACX,CAAC;;AAGJ,MAAM,oBACJ,WACuF;AACvF,KAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;CAClD,MAAM,YAAY;AAMlB,SACG,UAAU,SAAS,WAAW,UAAU,SAAS,iBAClD,OAAO,UAAU,YAAY,cAC7B,OAAO,UAAU,aAAa,cAC9B,OAAO,UAAU,cAAc;;AAInC,SAAgB,OACd,cACA,SACA,WAA8C,OAAO,IACtC;AACf,KAAI,CAAC,MAAM,QAAQ,aAAa,IAAI,aAAa,MAAK,UAAS,CAAC,YAAY,IAAI,MAAM,CAAC,CACrF,OAAM,IAAI,UAAU,2CAA2C;AAEjE,QAAO,OAAU;EACf,MAAM;EACN,cAHa,OAAO,OAAO,CAAC,GAAG,aAAa,CAGxB;EACX;EACT,SAAS;EACV,CAAC;;AAGJ,MAAa,kBACX,UACA,WAAoC,OAAO,OACzB,OAAU;CAAE,MAAM;CAAY;CAAU,SAAS;CAAsB,CAAC;AAE5F,MAAa,uBAA0B,WACrC,OAAU;CAAE,MAAM;CAAwB;CAAwC,CAAC;AAErF,MAAa,4BACX,WAEA,OAAkD;CAChD,MAAM;CACE;CACT,CAAC;AAEJ,MAAa,0BAA6B,eAMxC,OAAU;CACR,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC;AAEJ,MAAa,+BAAoD,eAM/D,OAAkD;CAChD,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC"}
@@ -38,7 +38,6 @@ function derive(dependencies, compute, equality = Object.is) {
38
38
  isEqual: equality
39
39
  });
40
40
  }
41
- /** Internal source adapters used by observe, not exported publicly. */
42
41
  const defineReadable = (readable, equality = Object.is) => define({
43
42
  kind: "readable",
44
43
  readable,
@@ -104,4 +103,4 @@ Object.defineProperty(exports, "observe", {
104
103
  }
105
104
  });
106
105
 
107
- //# sourceMappingURL=definition-Z6TagMup.cjs.map
106
+ //# sourceMappingURL=definition-De6rhTlZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-De6rhTlZ.cjs","names":[],"sources":["../core/src/projection/definition.ts"],"sourcesContent":["import type { DocumentReadable, Synchronous } from '../runtime/contract';\nimport type {\n CollectionId,\n CollectionPath,\n CollectionNode as SchemaCollectionNode,\n Infer,\n ObjectNode,\n ReadonlyValue,\n SchemaPath,\n PathValueOf,\n} from '../schema';\nimport type { Readable } from './readable';\nimport type {\n CollectionChange,\n ExternalCollectionSource,\n ExternalValueSource,\n GraphSources,\n} from './contract';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const projectionChanges: unique symbol;\ndeclare const writableInput: unique symbol;\n\n/** A lazy, reusable projection definition with no runtime-owned state. */\nexport type Projection<T, C = undefined> = {\n readonly [projectionDefinition]: T;\n readonly [projectionChanges]: C;\n};\n\n/** A runtime-local writable projection definition. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\ntype ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = {\n readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never;\n};\n\ntype Equality = (a: unknown, b: unknown) => boolean;\ntype PathSelector<S extends ObjectNode> = (path: SchemaPath<S['shape']>) => unknown;\n\ntype Definition =\n | { readonly kind: 'input'; readonly initial: unknown; readonly isEqual?: Equality }\n | { readonly kind: 'readable'; readonly readable: Readable<unknown>; readonly isEqual?: Equality }\n | { readonly kind: 'source-value'; readonly source: ExternalValueSource<unknown> }\n | {\n readonly kind: 'source-collection';\n readonly source: ExternalCollectionSource<string, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: DocumentReadable<ObjectNode>;\n readonly selector?: PathSelector<ObjectNode>;\n }\n | {\n readonly kind: 'derive';\n readonly dependencies: readonly Projection<unknown, unknown>[];\n readonly compute: (...values: readonly unknown[]) => unknown;\n readonly isEqual?: Equality;\n }\n | {\n readonly kind: 'incremental-value';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n }\n | {\n readonly kind: 'incremental-collection';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n };\n\ntype DefinitionProjection = Projection<unknown, unknown>;\nconst definitions = new WeakMap<object, Definition>();\n\nconst define = <T, C = undefined>(definition: Definition): Projection<T, C> => {\n const handle = Object.freeze({}) as Projection<T, C>;\n definitions.set(handle, definition);\n return handle;\n};\n\nexport const definitionOf = (projection: DefinitionProjection): Definition => {\n const definition = definitions.get(projection);\n if (!definition) throw new TypeError('Unknown projection definition.');\n return definition;\n};\n\nexport const input = <T>(\n initial: T,\n equality: (previous: T, next: T) => boolean = Object.is\n): Input<T> => define<T>({ kind: 'input', initial, isEqual: equality as Equality }) as Input<T>;\n\n/** Establish a lazy reactive boundary from a document, readable, or external source. */\nexport function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;\nexport function observe<T>(source: ExternalValueSource<T>): Projection<T>;\nexport function observe<K extends string, V>(\n source: ExternalCollectionSource<K, V>\n): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;\nexport function observe<T>(readable: Readable<T>): Projection<T>;\nexport function observe<S extends ObjectNode, P extends CollectionPath>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<\n ReadonlyMap<CollectionId<P>, ReadonlyValue<Infer<SchemaCollectionNode<P>>>>,\n CollectionChange<CollectionId<P>, ReadonlyValue<Infer<SchemaCollectionNode<P>>>>\n>;\nexport function observe<S extends ObjectNode, P>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<PathValueOf<P>>;\nexport function observe<S extends ObjectNode>(\n document:\n | DocumentReadable<S>\n | Readable<unknown>\n | ExternalValueSource<unknown>\n | ExternalCollectionSource<string, unknown>,\n selector?: PathSelector<S>\n): Projection<unknown, unknown> {\n if (isExternalSource(document))\n return document.kind === 'collection'\n ? defineExternalCollection(document)\n : defineExternalValue(document);\n if ('current' in document && typeof document.current === 'function')\n return defineReadable(document as Readable<unknown>);\n return define({\n kind: 'document',\n document: document as DocumentReadable<ObjectNode>,\n selector: selector as PathSelector<ObjectNode> | undefined,\n });\n}\n\nconst isExternalSource = (\n source: unknown\n): source is ExternalValueSource<unknown> | ExternalCollectionSource<string, unknown> => {\n if (!source || typeof source !== 'object') return false;\n const candidate = source as {\n readonly kind?: unknown;\n readonly current?: unknown;\n readonly revision?: unknown;\n readonly subscribe?: unknown;\n };\n return (\n (candidate.kind === 'value' || candidate.kind === 'collection') &&\n typeof candidate.current === 'function' &&\n typeof candidate.revision === 'function' &&\n typeof candidate.subscribe === 'function'\n );\n};\n\nexport function derive<const D extends readonly Projection<unknown, unknown>[], T>(\n dependencies: D,\n compute: (...values: ProjectionValues<D>) => Synchronous<T>,\n equality: (previous: T, next: T) => boolean = Object.is\n): Projection<T> {\n if (!Array.isArray(dependencies) || dependencies.some(value => !definitions.has(value)))\n throw new TypeError('derive dependencies must be projections.');\n const frozen = Object.freeze([...dependencies]) as readonly Projection<unknown, unknown>[];\n return define<T>({\n kind: 'derive',\n dependencies: frozen,\n compute: compute as (...values: readonly unknown[]) => unknown,\n isEqual: equality as Equality,\n });\n}\n\nexport const defineReadable = <T>(\n readable: Readable<T>,\n equality: (a: T, b: T) => boolean = Object.is\n): Projection<T> => define<T>({ kind: 'readable', readable, isEqual: equality as Equality });\n\nexport const defineExternalValue = <T>(source: ExternalValueSource<T>): Projection<T> =>\n define<T>({ kind: 'source-value', source: source as ExternalValueSource<unknown> });\n\nexport const defineExternalCollection = <K extends string, V>(\n source: ExternalCollectionSource<K, V>\n): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>> =>\n define<ReadonlyMap<K, V>, CollectionChange<K, V>>({\n kind: 'source-collection',\n source: source as unknown as ExternalCollectionSource<string, unknown>,\n });\n\nexport const defineIncrementalValue = <T>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: T, b: T) => boolean;\n readonly name?: string;\n}): Projection<T> =>\n define<T>({\n kind: 'incremental-value',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\nexport const defineIncrementalCollection = <K extends string, V>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: V, b: V) => boolean;\n readonly name?: string;\n}): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>> =>\n define<ReadonlyMap<K, V>, CollectionChange<K, V>>({\n kind: 'incremental-collection',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n"],"mappings":";AA0EA,MAAM,8BAAc,IAAI,SAA6B;AAErD,MAAM,UAA4B,eAA6C;CAC7E,MAAM,SAAS,OAAO,OAAO,EAAE,CAAC;AAChC,aAAY,IAAI,QAAQ,WAAW;AACnC,QAAO;;AAGT,MAAa,gBAAgB,eAAiD;CAC5E,MAAM,aAAa,YAAY,IAAI,WAAW;AAC9C,KAAI,CAAC,WAAY,OAAM,IAAI,UAAU,iCAAiC;AACtE,QAAO;;AAGT,MAAa,SACX,SACA,WAA8C,OAAO,OACxC,OAAU;CAAE,MAAM;CAAS;CAAS,SAAS;CAAsB,CAAC;AAoBnF,SAAgB,QACd,UAKA,UAC8B;AAC9B,KAAI,iBAAiB,SAAS,CAC5B,QAAO,SAAS,SAAS,eACrB,yBAAyB,SAAS,GAClC,oBAAoB,SAAS;AACnC,KAAI,aAAa,YAAY,OAAO,SAAS,YAAY,WACvD,QAAO,eAAe,SAA8B;AACtD,QAAO,OAAO;EACZ,MAAM;EACI;EACA;EACX,CAAC;;AAGJ,MAAM,oBACJ,WACuF;AACvF,KAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;CAClD,MAAM,YAAY;AAMlB,SACG,UAAU,SAAS,WAAW,UAAU,SAAS,iBAClD,OAAO,UAAU,YAAY,cAC7B,OAAO,UAAU,aAAa,cAC9B,OAAO,UAAU,cAAc;;AAInC,SAAgB,OACd,cACA,SACA,WAA8C,OAAO,IACtC;AACf,KAAI,CAAC,MAAM,QAAQ,aAAa,IAAI,aAAa,MAAK,UAAS,CAAC,YAAY,IAAI,MAAM,CAAC,CACrF,OAAM,IAAI,UAAU,2CAA2C;AAEjE,QAAO,OAAU;EACf,MAAM;EACN,cAHa,OAAO,OAAO,CAAC,GAAG,aAAa,CAGxB;EACX;EACT,SAAS;EACV,CAAC;;AAGJ,MAAa,kBACX,UACA,WAAoC,OAAO,OACzB,OAAU;CAAE,MAAM;CAAY;CAAU,SAAS;CAAsB,CAAC;AAE5F,MAAa,uBAA0B,WACrC,OAAU;CAAE,MAAM;CAAwB;CAAwC,CAAC;AAErF,MAAa,4BACX,WAEA,OAAkD;CAChD,MAAM;CACE;CACT,CAAC;AAEJ,MAAa,0BAA6B,eAMxC,OAAU;CACR,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC;AAEJ,MAAa,+BAAoD,eAM/D,OAAkD;CAChD,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC"}