doxum 0.1.13 → 0.1.14

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.
Files changed (41) hide show
  1. package/README.md +4 -0
  2. package/dist/advanced.cjs +1 -1
  3. package/dist/advanced.d.cts +1 -1
  4. package/dist/advanced.d.ts +1 -1
  5. package/dist/advanced.js +1 -1
  6. package/dist/{definition-177L4Amk.cjs → definition-BDW6i7fp.cjs} +8 -20
  7. package/dist/{definition-177L4Amk.cjs.map → definition-BDW6i7fp.cjs.map} +1 -1
  8. package/dist/{definition-kxnWUvX9.d.cts → definition-DN6yW2vi.d.cts} +37 -36
  9. package/dist/{definition-BlMeHwdz.d.ts → definition-Dr8tHwTD.d.ts} +37 -36
  10. package/dist/{definition-DXrKMVs7.js → definition-wOvuklwp.js} +9 -3
  11. package/dist/{definition-DXrKMVs7.js.map → definition-wOvuklwp.js.map} +1 -1
  12. package/dist/index.cjs +2 -2
  13. package/dist/index.d.cts +3 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +2 -2
  16. package/dist/integration-WniqaEPW.cjs +30 -0
  17. package/dist/integration-WniqaEPW.cjs.map +1 -0
  18. package/dist/{integration-Bco8ZB16.js → integration-zB8e-uNP.js} +3 -7
  19. package/dist/integration-zB8e-uNP.js.map +1 -0
  20. package/dist/integration.cjs +2 -5
  21. package/dist/integration.d.cts +3 -7
  22. package/dist/integration.d.ts +3 -7
  23. package/dist/integration.js +3 -3
  24. package/dist/react.cjs +2 -2
  25. package/dist/react.js +2 -2
  26. package/dist/{store-DcDpDgjk.cjs → store-6wMvZthf.cjs} +4 -6
  27. package/dist/store-6wMvZthf.cjs.map +1 -0
  28. package/dist/{store-P5dJ7TVe.d.ts → store-BCR20XSb.d.ts} +2 -2
  29. package/dist/{store-CtgvCVFg.js → store-PLKs1KnS.js} +4 -6
  30. package/dist/store-PLKs1KnS.js.map +1 -0
  31. package/dist/{store-CDeqZEE3.d.cts → store-jJ3SNYKH.d.cts} +2 -2
  32. package/package.json +1 -1
  33. package/skills/doxum-runtime/references/guide.en.md +2 -1
  34. package/skills/doxum-runtime/references/guide.zh-CN.md +2 -1
  35. package/skills/doxum-runtime/references/projections.en.md +8 -1
  36. package/skills/doxum-runtime/references/projections.zh-CN.md +7 -1
  37. package/dist/integration-Bco8ZB16.js.map +0 -1
  38. package/dist/integration-CEUn96tx.cjs +0 -52
  39. package/dist/integration-CEUn96tx.cjs.map +0 -1
  40. package/dist/store-CtgvCVFg.js.map +0 -1
  41. package/dist/store-DcDpDgjk.cjs.map +0 -1
@@ -3,55 +3,53 @@ import { J as Infer, L as CollectionId, R as CollectionNode, Z as ObjectNode, _
3
3
  //#region core/src/projection/contract.d.ts
4
4
  /** Opaque application metadata identifying the action that produced a source event. */
5
5
  type Cause = unknown;
6
- type BatchContext = {
7
- readonly id: number;
8
- readonly cause?: Cause;
9
- };
10
6
  type BatchOptions = {
11
7
  readonly cause?: Cause;
12
8
  };
13
- type CollectionEntryTransition<K extends string, V> = {
14
- readonly key: K;
15
- readonly kind: 'added' | 'updated' | 'removed';
16
- readonly before: V | undefined;
17
- readonly after: V | undefined;
18
- };
19
- type ValueContext<T, D = unknown> = {
20
- readonly value: T;
21
- readonly previous: T;
22
- readonly changed: boolean;
23
- readonly revision: number;
24
- readonly reset: boolean;
25
- readonly detail?: D;
26
- readonly cause?: Cause;
27
- readonly batch?: BatchContext;
28
- };
29
9
  type CollectionRead<K extends string, V> = {
30
10
  get(key: K): V | undefined;
31
11
  has(key: K): boolean;
32
12
  ids(): readonly K[];
33
13
  };
34
- type CollectionContext<K extends string, V, D = unknown> = CollectionRead<K, V> & {
35
- readonly previous: CollectionRead<K, V>;
36
- readonly change: CollectionImpact<K> | undefined;
37
- readonly revision: number;
38
- readonly reset: boolean;
39
- readonly transitions: (keys?: Iterable<K>) => readonly CollectionEntryTransition<K, V>[];
40
- readonly detail?: D;
41
- readonly cause?: Cause;
42
- readonly batch?: BatchContext;
14
+ type ExternalCollectionRead<K extends string, V> = {
15
+ readonly get: (key: K) => V | undefined;
16
+ readonly has: (key: K) => boolean;
17
+ readonly ids: () => readonly K[];
43
18
  };
44
19
  type ExternalValueSource<T, D = unknown> = {
45
20
  readonly kind: 'value';
46
21
  current(): T;
47
22
  revision(): number;
48
- subscribe(listener: (event: ValueContext<T, D>) => void): Unsubscribe;
23
+ subscribe(listener: (event: ExternalValueEvent<T, D>) => void): Unsubscribe;
49
24
  };
50
25
  type ExternalCollectionSource<K extends string, V, D = unknown> = {
51
26
  readonly kind: 'collection';
52
- current(): CollectionRead<K, V>;
27
+ current(): ExternalCollectionRead<K, V>;
53
28
  revision(): number;
54
- subscribe(listener: (event: CollectionContext<K, V, D>) => void): Unsubscribe;
29
+ subscribe(listener: (event: ExternalCollectionEvent<K, V, D>) => void): Unsubscribe;
30
+ };
31
+ type ExternalValueEvent<T, D = unknown> = {
32
+ readonly value: T;
33
+ readonly revision: number;
34
+ readonly reset?: boolean;
35
+ readonly detail?: D;
36
+ readonly cause?: Cause;
37
+ readonly batch?: {
38
+ readonly id: number;
39
+ readonly cause?: Cause;
40
+ };
41
+ };
42
+ type ExternalCollectionEvent<K extends string, V, D = unknown> = {
43
+ readonly previous: ExternalCollectionRead<K, V>;
44
+ readonly revision: number;
45
+ readonly reset?: boolean;
46
+ readonly change?: CollectionImpact<K>;
47
+ readonly detail?: D;
48
+ readonly cause?: Cause;
49
+ readonly batch?: {
50
+ readonly id: number;
51
+ readonly cause?: Cause;
52
+ };
55
53
  };
56
54
  type CollectionDraft<K extends string, V> = {
57
55
  set(key: K, value: V): void;
@@ -85,14 +83,17 @@ type PublicCollection<K extends string, V> = ReadonlyMap<K, V>;
85
83
  type ObservedCollection<P extends CollectionPath> = PublicCollection<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>;
86
84
  declare const input: <T>(initial: T, equality?: (previous: T, next: T) => boolean) => Input<T>;
87
85
  /**
88
- * Establishes a reactive boundary from a document. The selector is compiled
89
- * when the definition is materialized, so declarations stay lazy and reusable.
86
+ * Establishes a reactive boundary from a document, readable, or external
87
+ * source. The selector is compiled when the definition is materialized, so
88
+ * declarations stay lazy and reusable.
90
89
  */
91
90
  declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
91
+ declare function observe<T, D>(source: ExternalValueSource<T, D>): Projection<T>;
92
+ declare function observe<K extends string, V, D>(source: ExternalCollectionSource<K, V, D>): Projection<PublicCollection<K, V>>;
92
93
  declare function observe<T>(readable: Readable<T>): Projection<T>;
93
94
  declare function observe<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<ObservedCollection<P>>;
94
95
  declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
95
96
  declare function derive<const D extends readonly Projection<unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
96
97
  //#endregion
97
- export { derive as a, BatchOptions as c, ExternalCollectionSource as d, ExternalValueSource as f, PublicCollection as i, CollectionDraft as l, ProjectionError as m, Projection as n, input as o, ProjectionDisposedError as p, ProjectionValues as r, observe as s, Input as t, CollectionRead as u };
98
- //# sourceMappingURL=definition-kxnWUvX9.d.cts.map
98
+ export { ProjectionError as _, derive as a, BatchOptions as c, ExternalCollectionEvent as d, ExternalCollectionRead as f, ProjectionDisposedError as g, ExternalValueSource as h, PublicCollection as i, CollectionDraft as l, ExternalValueEvent as m, Projection as n, input as o, ExternalCollectionSource as p, ProjectionValues as r, observe as s, Input as t, CollectionRead as u };
99
+ //# sourceMappingURL=definition-DN6yW2vi.d.cts.map
@@ -3,55 +3,53 @@ import { J as Infer, L as CollectionId, R as CollectionNode, Z as ObjectNode, _
3
3
  //#region core/src/projection/contract.d.ts
4
4
  /** Opaque application metadata identifying the action that produced a source event. */
5
5
  type Cause = unknown;
6
- type BatchContext = {
7
- readonly id: number;
8
- readonly cause?: Cause;
9
- };
10
6
  type BatchOptions = {
11
7
  readonly cause?: Cause;
12
8
  };
13
- type CollectionEntryTransition<K extends string, V> = {
14
- readonly key: K;
15
- readonly kind: 'added' | 'updated' | 'removed';
16
- readonly before: V | undefined;
17
- readonly after: V | undefined;
18
- };
19
- type ValueContext<T, D = unknown> = {
20
- readonly value: T;
21
- readonly previous: T;
22
- readonly changed: boolean;
23
- readonly revision: number;
24
- readonly reset: boolean;
25
- readonly detail?: D;
26
- readonly cause?: Cause;
27
- readonly batch?: BatchContext;
28
- };
29
9
  type CollectionRead<K extends string, V> = {
30
10
  get(key: K): V | undefined;
31
11
  has(key: K): boolean;
32
12
  ids(): readonly K[];
33
13
  };
34
- type CollectionContext<K extends string, V, D = unknown> = CollectionRead<K, V> & {
35
- readonly previous: CollectionRead<K, V>;
36
- readonly change: CollectionImpact<K> | undefined;
37
- readonly revision: number;
38
- readonly reset: boolean;
39
- readonly transitions: (keys?: Iterable<K>) => readonly CollectionEntryTransition<K, V>[];
40
- readonly detail?: D;
41
- readonly cause?: Cause;
42
- readonly batch?: BatchContext;
14
+ type ExternalCollectionRead<K extends string, V> = {
15
+ readonly get: (key: K) => V | undefined;
16
+ readonly has: (key: K) => boolean;
17
+ readonly ids: () => readonly K[];
43
18
  };
44
19
  type ExternalValueSource<T, D = unknown> = {
45
20
  readonly kind: 'value';
46
21
  current(): T;
47
22
  revision(): number;
48
- subscribe(listener: (event: ValueContext<T, D>) => void): Unsubscribe;
23
+ subscribe(listener: (event: ExternalValueEvent<T, D>) => void): Unsubscribe;
49
24
  };
50
25
  type ExternalCollectionSource<K extends string, V, D = unknown> = {
51
26
  readonly kind: 'collection';
52
- current(): CollectionRead<K, V>;
27
+ current(): ExternalCollectionRead<K, V>;
53
28
  revision(): number;
54
- subscribe(listener: (event: CollectionContext<K, V, D>) => void): Unsubscribe;
29
+ subscribe(listener: (event: ExternalCollectionEvent<K, V, D>) => void): Unsubscribe;
30
+ };
31
+ type ExternalValueEvent<T, D = unknown> = {
32
+ readonly value: T;
33
+ readonly revision: number;
34
+ readonly reset?: boolean;
35
+ readonly detail?: D;
36
+ readonly cause?: Cause;
37
+ readonly batch?: {
38
+ readonly id: number;
39
+ readonly cause?: Cause;
40
+ };
41
+ };
42
+ type ExternalCollectionEvent<K extends string, V, D = unknown> = {
43
+ readonly previous: ExternalCollectionRead<K, V>;
44
+ readonly revision: number;
45
+ readonly reset?: boolean;
46
+ readonly change?: CollectionImpact<K>;
47
+ readonly detail?: D;
48
+ readonly cause?: Cause;
49
+ readonly batch?: {
50
+ readonly id: number;
51
+ readonly cause?: Cause;
52
+ };
55
53
  };
56
54
  type CollectionDraft<K extends string, V> = {
57
55
  set(key: K, value: V): void;
@@ -85,14 +83,17 @@ type PublicCollection<K extends string, V> = ReadonlyMap<K, V>;
85
83
  type ObservedCollection<P extends CollectionPath> = PublicCollection<CollectionId<P>, ReadonlyValue<Infer<CollectionNode<P>>>>;
86
84
  declare const input: <T>(initial: T, equality?: (previous: T, next: T) => boolean) => Input<T>;
87
85
  /**
88
- * Establishes a reactive boundary from a document. The selector is compiled
89
- * when the definition is materialized, so declarations stay lazy and reusable.
86
+ * Establishes a reactive boundary from a document, readable, or external
87
+ * source. The selector is compiled when the definition is materialized, so
88
+ * declarations stay lazy and reusable.
90
89
  */
91
90
  declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
91
+ declare function observe<T, D>(source: ExternalValueSource<T, D>): Projection<T>;
92
+ declare function observe<K extends string, V, D>(source: ExternalCollectionSource<K, V, D>): Projection<PublicCollection<K, V>>;
92
93
  declare function observe<T>(readable: Readable<T>): Projection<T>;
93
94
  declare function observe<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<ObservedCollection<P>>;
94
95
  declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
95
96
  declare function derive<const D extends readonly Projection<unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
96
97
  //#endregion
97
- export { derive as a, BatchOptions as c, ExternalCollectionSource as d, ExternalValueSource as f, PublicCollection as i, CollectionDraft as l, ProjectionError as m, Projection as n, input as o, ProjectionDisposedError as p, ProjectionValues as r, observe as s, Input as t, CollectionRead as u };
98
- //# sourceMappingURL=definition-BlMeHwdz.d.ts.map
98
+ export { ProjectionError as _, derive as a, BatchOptions as c, ExternalCollectionEvent as d, ExternalCollectionRead as f, ProjectionDisposedError as g, ExternalValueSource as h, PublicCollection as i, CollectionDraft as l, ExternalValueEvent as m, Projection as n, input as o, ExternalCollectionSource as p, ProjectionValues as r, observe as s, Input as t, CollectionRead as u };
99
+ //# sourceMappingURL=definition-Dr8tHwTD.d.ts.map
@@ -735,6 +735,7 @@ const input = (initial, equality = Object.is) => define({
735
735
  isEqual: equality
736
736
  });
737
737
  function observe(document, selector) {
738
+ if (isExternalSource(document)) return document.kind === "collection" ? defineExternalCollection(document) : defineExternalValue(document);
738
739
  if ("current" in document && typeof document.current === "function") return defineReadable(document);
739
740
  return define({
740
741
  kind: "document",
@@ -742,6 +743,11 @@ function observe(document, selector) {
742
743
  selector
743
744
  });
744
745
  }
746
+ const isExternalSource = (source) => {
747
+ if (!source || typeof source !== "object") return false;
748
+ const candidate = source;
749
+ return (candidate.kind === "value" || candidate.kind === "collection") && typeof candidate.current === "function" && typeof candidate.revision === "function" && typeof candidate.subscribe === "function";
750
+ };
745
751
  function derive(dependencies, compute, equality = Object.is) {
746
752
  if (!Array.isArray(dependencies) || dependencies.some((value) => !definitions.has(value))) throw new TypeError("derive dependencies must be projections.");
747
753
  return define({
@@ -751,7 +757,7 @@ function derive(dependencies, compute, equality = Object.is) {
751
757
  isEqual: equality
752
758
  });
753
759
  }
754
- /** Internal adapters used by the integration boundary, not exported publicly. */
760
+ /** Internal source adapters used by observe, not exported publicly. */
755
761
  const defineReadable = (readable, equality = Object.is) => define({
756
762
  kind: "readable",
757
763
  readable,
@@ -780,6 +786,6 @@ const defineIncrementalCollection = (definition) => define({
780
786
  name: definition.name
781
787
  });
782
788
  //#endregion
783
- export { copyValue as _, defineReadable as a, input as c, createAccess as d, replace as f, checkValue as g, checkKey as h, defineIncrementalValue as i, observe as l, ParseError as m, defineExternalValue as n, definitionOf as o, snapshot as p, defineIncrementalCollection as r, derive as s, defineExternalCollection as t, collectionAccess as u, equalValue as v, parse as y };
789
+ export { input as a, createAccess as c, ParseError as d, checkKey as f, parse as g, equalValue as h, derive as i, replace as l, copyValue as m, defineIncrementalValue as n, observe as o, checkValue as p, definitionOf as r, collectionAccess as s, defineIncrementalCollection as t, snapshot as u };
784
790
 
785
- //# sourceMappingURL=definition-DXrKMVs7.js.map
791
+ //# sourceMappingURL=definition-wOvuklwp.js.map