doxum 0.1.12 → 0.1.13

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 (64) hide show
  1. package/README.md +44 -39
  2. package/dist/advanced.cjs +116 -0
  3. package/dist/advanced.cjs.map +1 -0
  4. package/dist/advanced.d.cts +42 -0
  5. package/dist/advanced.d.ts +42 -0
  6. package/dist/advanced.js +115 -0
  7. package/dist/advanced.js.map +1 -0
  8. package/dist/{contract-CeAnEPBA.d.ts → contract-BT53Gg94.d.ts} +5 -4
  9. package/dist/{contract-DtGVSXSK.d.cts → contract-XmKnroJq.d.cts} +5 -4
  10. package/dist/definition-177L4Amk.cjs +898 -0
  11. package/dist/definition-177L4Amk.cjs.map +1 -0
  12. package/dist/definition-BlMeHwdz.d.ts +98 -0
  13. package/dist/definition-DXrKMVs7.js +785 -0
  14. package/dist/definition-DXrKMVs7.js.map +1 -0
  15. package/dist/definition-kxnWUvX9.d.cts +98 -0
  16. package/dist/{driver-xOIkwrB8.cjs → driver-BCyfqxsl.cjs} +1 -1
  17. package/dist/{driver-xOIkwrB8.cjs.map → driver-BCyfqxsl.cjs.map} +1 -1
  18. package/dist/{driver-BlR81Dqg.js → driver-CSnhMjbP.js} +1 -1
  19. package/dist/{driver-BlR81Dqg.js.map → driver-CSnhMjbP.js.map} +1 -1
  20. package/dist/index.cjs +31 -29
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +5 -4
  23. package/dist/index.d.ts +5 -4
  24. package/dist/index.js +7 -6
  25. package/dist/index.js.map +1 -1
  26. package/dist/{integration-CWjttg7H.js → integration-Bco8ZB16.js} +7 -3
  27. package/dist/integration-Bco8ZB16.js.map +1 -0
  28. package/dist/integration-CEUn96tx.cjs +52 -0
  29. package/dist/integration-CEUn96tx.cjs.map +1 -0
  30. package/dist/integration.cjs +7 -3
  31. package/dist/integration.d.cts +7 -3
  32. package/dist/integration.d.ts +7 -3
  33. package/dist/integration.js +3 -3
  34. package/dist/local-sync.cjs +1 -1
  35. package/dist/local-sync.d.cts +1 -1
  36. package/dist/local-sync.d.ts +1 -1
  37. package/dist/local-sync.js +1 -1
  38. package/dist/react.cjs +63 -36
  39. package/dist/react.cjs.map +1 -1
  40. package/dist/react.d.cts +8 -7
  41. package/dist/react.d.ts +8 -7
  42. package/dist/react.js +63 -35
  43. package/dist/react.js.map +1 -1
  44. package/dist/store-CDeqZEE3.d.cts +28 -0
  45. package/dist/{store-7XBEcR8s.js → store-CtgvCVFg.js} +585 -922
  46. package/dist/store-CtgvCVFg.js.map +1 -0
  47. package/dist/{store-DBv58dns.cjs → store-DcDpDgjk.cjs} +595 -992
  48. package/dist/store-DcDpDgjk.cjs.map +1 -0
  49. package/dist/store-P5dJ7TVe.d.ts +28 -0
  50. package/package.json +6 -1
  51. package/skills/doxum-runtime/SKILL.md +5 -7
  52. package/skills/doxum-runtime/references/guide.en.md +12 -16
  53. package/skills/doxum-runtime/references/guide.zh-CN.md +9 -14
  54. package/skills/doxum-runtime/references/patterns.en.md +12 -20
  55. package/skills/doxum-runtime/references/patterns.zh-CN.md +12 -18
  56. package/skills/doxum-runtime/references/projections.en.md +56 -199
  57. package/skills/doxum-runtime/references/projections.zh-CN.md +50 -180
  58. package/dist/integration-BShL68Nc.cjs +0 -30
  59. package/dist/integration-BShL68Nc.cjs.map +0 -1
  60. package/dist/integration-CWjttg7H.js.map +0 -1
  61. package/dist/store-2i8pYXqa.d.ts +0 -263
  62. package/dist/store-7XBEcR8s.js.map +0 -1
  63. package/dist/store-DBv58dns.cjs.map +0 -1
  64. package/dist/store-Ks80xWS_.d.cts +0 -263
@@ -1,263 +0,0 @@
1
- import { B as CollectionPath, C as CollectionAccess, Q as ObjectNode, R as CollectionId, T as Read, _ as Unsubscribe, m as Synchronous, ot as ValueSchemaNode, r as DocumentCommit, rt as SchemaPath, s as DocumentReadable, tt as PathPick, v as Readable, x as CollectionImpact, z as CollectionNode } from "./contract-DtGVSXSK.cjs";
2
-
3
- //#region core/src/projection/contract.d.ts
4
- declare const sourceContext: unique symbol;
5
- type EngineSource<T> = {
6
- readonly [sourceContext]: T;
7
- };
8
- type EngineSources = Readonly<Record<string, EngineSource<unknown>>>;
9
- type EngineInputs<S extends EngineSources> = { readonly [K in keyof S]: S[K] extends EngineSource<infer T> ? T : never };
10
- type DocumentInput<S extends ObjectNode> = {
11
- readonly read: Read<S>;
12
- readonly revision: number;
13
- readonly commits: readonly DocumentCommit<S>[];
14
- readonly reset: boolean;
15
- };
16
- type DocumentCollectionInput<S extends ObjectNode, N extends ValueSchemaNode, K extends string = string> = {
17
- readonly read: CollectionAccess<K, N>;
18
- readonly revision: number;
19
- readonly commits: readonly DocumentCommit<S>[];
20
- readonly reset: boolean;
21
- readonly candidates: {
22
- readonly keys: readonly K[];
23
- readonly orderDirty: boolean;
24
- };
25
- };
26
- type DocumentSource<S extends ObjectNode> = EngineSource<DocumentInput<S>> & {
27
- collection<P extends CollectionPath>(pick: (path: SchemaPath<S['shape']>) => P): DocumentCollectionSource<S, CollectionNode<P>, CollectionId<P>>;
28
- targets(...targets: readonly [PathPick<S>, ...PathPick<S>[]]): EngineSource<DocumentInput<S>>;
29
- };
30
- type DocumentCollectionSource<S extends ObjectNode, N extends ValueSchemaNode, K extends string = string> = EngineSource<DocumentCollectionInput<S, N, K>>;
31
- type ValueInput<T> = {
32
- readonly value: T;
33
- readonly previous: T;
34
- readonly changed: boolean;
35
- readonly revision: number;
36
- readonly reset: boolean;
37
- };
38
- type EngineInput<T> = {
39
- readonly source: EngineSource<ValueInput<T>>;
40
- set(value: T): void;
41
- };
42
- type ValueUpdate<T> = {
43
- readonly kind: 'unchanged';
44
- } | {
45
- readonly kind: 'changed';
46
- readonly value: T;
47
- } | {
48
- readonly kind: 'rebuild';
49
- };
50
- type EngineValueSpec<S extends EngineSources, T> = {
51
- readonly name?: string;
52
- readonly sources: S;
53
- readonly build: (sources: EngineInputs<S>) => {
54
- readonly value: T;
55
- readonly update: (sources: EngineInputs<S>) => ValueUpdate<NoInfer<T>>;
56
- };
57
- };
58
- type MaterializedValue<T> = Readable<T> & EngineSource<ValueInput<T>> & {
59
- rebuild(): void;
60
- dispose(): void;
61
- };
62
- type CollectionRead<K extends string, V> = {
63
- get(key: K): V | undefined;
64
- has(key: K): boolean;
65
- ids(): readonly K[];
66
- };
67
- type CollectionInput<K extends string, V> = CollectionRead<K, V> & {
68
- readonly change: CollectionImpact<K> | undefined;
69
- readonly revision: number;
70
- readonly reset: boolean;
71
- };
72
- type MaterializedCollection<K extends string, V> = EngineSource<CollectionInput<K, V>> & {
73
- current(): CollectionRead<K, V>;
74
- readonly ids: Readable<readonly K[]>;
75
- readonly all: Readable<readonly V[]>;
76
- item(key: K): Readable<V | undefined>;
77
- revision(): number;
78
- subscribe(listener: (change: CollectionImpact<K>) => void): Unsubscribe;
79
- rebuild(): void;
80
- dispose(): void;
81
- };
82
- type MaterializedCollectionWriter<K extends string, V> = {
83
- set(key: K, value: V): void;
84
- remove(key: K): void;
85
- order(ids: readonly K[]): void;
86
- replace(entries: readonly (readonly [K, V])[]): void;
87
- };
88
- type EngineCollectionProcess<S extends EngineSources, K extends string, V> = {
89
- readonly sources: EngineInputs<S>;
90
- readonly previous: CollectionRead<K, V>;
91
- readonly next: CollectionRead<K, V>;
92
- readonly writer: MaterializedCollectionWriter<K, V>;
93
- };
94
- type EngineCollectionSpec<S extends EngineSources, K extends string, V> = {
95
- readonly name?: string;
96
- readonly sources: S;
97
- readonly isEqual?: (previous: V, next: V) => boolean;
98
- readonly build: (input: EngineCollectionProcess<S, K, V>) => {
99
- readonly update: (input: EngineCollectionProcess<S, K, V>) => void | {
100
- readonly kind: 'rebuild';
101
- };
102
- };
103
- };
104
- declare class ProjectionError extends Error {
105
- readonly phase: 'processor' | 'listener' | 'source' | 'blocked';
106
- readonly identity: string;
107
- readonly revisions: readonly number[];
108
- constructor(phase: 'processor' | 'listener' | 'source' | 'blocked', identity: string, revisions: readonly number[], cause: unknown);
109
- }
110
- declare class ProjectionDisposedError extends Error {
111
- constructor();
112
- }
113
- type ProjectionEngine = {
114
- document<S extends ObjectNode>(runtime: DocumentReadable<S>): DocumentSource<S>;
115
- fromReadable<T>(readable: Readable<T>, options?: {
116
- readonly isEqual?: (a: T, b: T) => boolean;
117
- }): EngineSource<ValueInput<T>>;
118
- input<T>(initial: T, options?: {
119
- readonly isEqual?: (a: T, b: T) => boolean;
120
- }): EngineInput<T>;
121
- value<S extends EngineSources, T>(sources: S, compute: (sources: EngineInputs<S>) => Synchronous<T>, options?: {
122
- readonly isEqual?: (a: NoInfer<T>, b: NoInfer<T>) => boolean;
123
- }): MaterializedValue<T>;
124
- value<S extends EngineSources, T>(spec: EngineValueSpec<S, T>, options?: {
125
- readonly isEqual?: (a: NoInfer<T>, b: NoInfer<T>) => boolean;
126
- }): MaterializedValue<T>;
127
- collection<V, K extends string = string>(): <S extends EngineSources>(spec: EngineCollectionSpec<S, K, V>) => MaterializedCollection<K, V>;
128
- map<S extends ObjectNode, N extends ValueSchemaNode, K extends string, V>(source: DocumentCollectionSource<S, N, K>, mapper: (id: K, entry: Read<N>) => Synchronous<V>, options?: {
129
- readonly isEqual?: (a: V, b: V) => boolean;
130
- }): MaterializedCollection<K, V>;
131
- map<K extends string, V, R>(source: MaterializedCollection<K, V>, mapper: (id: K, entry: V) => Synchronous<R>, options?: {
132
- readonly isEqual?: (a: NoInfer<R>, b: NoInfer<R>) => boolean;
133
- }): MaterializedCollection<K, R>;
134
- batch<T>(run: () => Synchronous<T>): T;
135
- dispose(): void;
136
- };
137
- //#endregion
138
- //#region core/src/projection/definition.d.ts
139
- declare const projectionDefinition: unique symbol;
140
- declare const writableInput: unique symbol;
141
- type Projection<T, E = T, K extends 'source' | 'value' | 'collection' = 'source' | 'value' | 'collection'> = {
142
- readonly [projectionDefinition]: {
143
- readonly value: T;
144
- readonly event: E;
145
- readonly kind: K;
146
- };
147
- };
148
- type ProjectionSources = Readonly<Record<string, Projection<unknown, unknown, 'source' | 'value' | 'collection'>>>;
149
- type ProjectionValues<S extends ProjectionSources> = { readonly [K in keyof S]: S[K] extends Projection<infer T, unknown, 'source' | 'value' | 'collection'> ? T : never };
150
- type ProjectionEvents<S extends ProjectionSources> = { readonly [K in keyof S]: S[K] extends Projection<unknown, infer E, 'source' | 'value' | 'collection'> ? E : never };
151
- type ValueProjection<T, E = ValueEvent<T>> = Projection<T, E, 'value'>;
152
- type InputProjection<T> = ValueProjection<T> & {
153
- readonly [writableInput]: true;
154
- };
155
- type CollectionProjection<K extends string, V, E = CollectionEvent<K, V>> = Projection<CollectionRead<K, V>, E, 'collection'>;
156
- type CollectionSource<K extends string, V, E> = Projection<CollectionRead<K, V>, E, 'source'>;
157
- type DocumentProjection<S extends ObjectNode> = Projection<Read<S>, DocumentEvent<S>, 'source'>;
158
- type DocumentCollectionProjection<S extends ObjectNode, N extends ValueSchemaNode, K extends string = string> = CollectionSource<K, Read<N>, DocumentCollectionEvent<S, N, K>>;
159
- type ValueEvent<T> = {
160
- readonly value: T;
161
- readonly previous: T;
162
- readonly changed: boolean;
163
- readonly revision: number;
164
- readonly reset: boolean;
165
- };
166
- type DocumentEvent<S extends ObjectNode> = {
167
- readonly read: Read<S>;
168
- readonly revision: number;
169
- readonly commits: readonly DocumentCommit<S>[];
170
- readonly reset: boolean;
171
- };
172
- type DocumentCollectionEvent<S extends ObjectNode, N extends ValueSchemaNode, K extends string = string> = {
173
- readonly read: CollectionAccess<K, N>;
174
- readonly revision: number;
175
- readonly commits: readonly DocumentCommit<S>[];
176
- readonly reset: boolean;
177
- readonly candidates: {
178
- readonly keys: readonly K[];
179
- readonly orderDirty: boolean;
180
- };
181
- };
182
- type CollectionEvent<K extends string, V> = CollectionRead<K, V> & {
183
- readonly change: CollectionImpact<K> | undefined;
184
- readonly revision: number;
185
- readonly reset: boolean;
186
- };
187
- declare const input: <T>(initial: T, options?: {
188
- readonly isEqual?: (a: T, b: T) => boolean;
189
- }) => InputProjection<T>;
190
- type AdvancedValueSpec<S extends ProjectionSources, T> = {
191
- readonly kind: 'value';
192
- readonly name?: string;
193
- readonly sources: S;
194
- readonly build: (sources: ProjectionEvents<S>) => {
195
- readonly value: T;
196
- readonly update: (sources: ProjectionEvents<S>) => ValueUpdate<NoInfer<T>>;
197
- };
198
- readonly isEqual?: (previous: T, next: T) => boolean;
199
- };
200
- type AdvancedCollectionSpec<S extends ProjectionSources, K extends string, V> = {
201
- readonly kind: 'collection';
202
- readonly name?: string;
203
- readonly sources: S;
204
- readonly build: (input: AdvancedCollectionProcess<S, K, V>) => {
205
- readonly update: (input: AdvancedCollectionProcess<S, K, V>) => void | {
206
- readonly kind: 'rebuild';
207
- };
208
- };
209
- readonly isEqual?: (previous: V, next: V) => boolean;
210
- };
211
- type AdvancedCollectionProcess<S extends ProjectionSources, K extends string, V> = {
212
- readonly sources: ProjectionEvents<S>;
213
- readonly previous: CollectionRead<K, V>;
214
- readonly next: CollectionRead<K, V>;
215
- readonly writer: MaterializedCollectionWriter<K, V>;
216
- };
217
- declare function project<T>(readable: Readable<T>): ValueProjection<T>;
218
- declare function project<S extends ObjectNode>(document: DocumentReadable<S>): DocumentProjection<S>;
219
- declare function project<S extends ObjectNode>(document: DocumentReadable<S>, targets: readonly [PathPick<S>, ...PathPick<S>[]]): DocumentProjection<S>;
220
- declare function project<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, pick: (path: SchemaPath<S['shape']>) => P): DocumentCollectionProjection<S, CollectionNode<P>, CollectionId<P>>;
221
- declare function project<S extends ObjectNode, P extends CollectionPath, V>(document: DocumentReadable<S>, pick: (path: SchemaPath<S['shape']>) => P, mapper: (id: CollectionId<P>, entry: Read<CollectionNode<P>>) => Synchronous<V>, options?: {
222
- readonly isEqual?: (a: V, b: V) => boolean;
223
- }): CollectionProjection<CollectionId<P>, V>;
224
- declare function project<K extends string, V, E, R>(source: Projection<CollectionRead<K, V>, E, 'source' | 'collection'>, mapper: (id: K, entry: V) => Synchronous<R>, options?: {
225
- readonly isEqual?: (a: R, b: R) => boolean;
226
- }): CollectionProjection<K, R>;
227
- declare function project<S extends ProjectionSources, T>(sources: S, compute: (sources: ProjectionValues<S>) => Synchronous<T>, options?: {
228
- readonly isEqual?: (a: T, b: T) => boolean;
229
- }): ValueProjection<T>;
230
- declare function project<S extends ProjectionSources, T>(spec: AdvancedValueSpec<S, T>): ValueProjection<T>;
231
- declare function project<V, K extends string = string, S extends ProjectionSources = ProjectionSources>(spec: AdvancedCollectionSpec<S, K, V>): CollectionProjection<K, V>;
232
- //#endregion
233
- //#region core/src/projection/runtime.d.ts
234
- declare const createProjectionEngine: (options: {
235
- readonly onError: (error: ProjectionError) => void;
236
- }) => ProjectionEngine;
237
- //#endregion
238
- //#region core/src/projection/store.d.ts
239
- type ProjectionStore = {
240
- get<K extends string, V>(projection: CollectionProjection<K, V>): CollectionRead<K, V>;
241
- get<T>(projection: ValueProjection<T>): T;
242
- item<K extends string, V>(projection: CollectionProjection<K, V>, key: K): Readable<V | undefined>;
243
- set<T>(projection: InputProjection<T>, value: T): void;
244
- subscribe<K extends string, V>(projection: CollectionProjection<K, V>, listener: (change: CollectionImpact<K>) => void): Unsubscribe;
245
- subscribe<T>(projection: ValueProjection<T>, listener: () => void): Unsubscribe;
246
- revision(projection: ValueProjection<unknown> | CollectionProjection<string, unknown>): number;
247
- rebuild(projection: ValueProjection<unknown> | CollectionProjection<string, unknown>): void;
248
- release(projection: ValueProjection<unknown> | CollectionProjection<string, unknown>): void;
249
- batch<T>(run: () => T): T;
250
- dispose(): void;
251
- };
252
- declare const projectionStoreDebug: (store: ProjectionStore) => Readonly<{
253
- nodes: number;
254
- sources: number;
255
- subscriptions: number;
256
- pending: number;
257
- }>;
258
- declare const createProjectionStore: (options: {
259
- readonly onError: Parameters<typeof createProjectionEngine>[0]["onError"];
260
- }) => ProjectionStore;
261
- //#endregion
262
- export { ProjectionDisposedError as C, project as S, ProjectionSources as _, AdvancedCollectionSpec as a, ValueProjection as b, CollectionProjection as c, DocumentCollectionProjection as d, DocumentEvent as f, ProjectionEvents as g, Projection as h, AdvancedCollectionProcess as i, CollectionSource as l, InputProjection as m, createProjectionStore as n, AdvancedValueSpec as o, DocumentProjection as p, projectionStoreDebug as r, CollectionEvent as s, ProjectionStore as t, DocumentCollectionEvent as u, ProjectionValues as v, ProjectionError as w, input as x, ValueEvent as y };
263
- //# sourceMappingURL=store-Ks80xWS_.d.cts.map