doxum 0.1.16 → 0.1.18
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/README.md +31 -4
- package/dist/advanced-DgRnyRAc.js +233 -0
- package/dist/advanced-DgRnyRAc.js.map +1 -0
- package/dist/advanced-Dgu8-bPS.cjs +274 -0
- package/dist/advanced-Dgu8-bPS.cjs.map +1 -0
- package/dist/advanced-GTwIWcn6.d.cts +138 -0
- package/dist/advanced-c0F3gpLG.d.ts +138 -0
- package/dist/advanced.cjs +2 -165
- package/dist/advanced.d.cts +2 -42
- package/dist/advanced.d.ts +2 -42
- package/dist/advanced.js +1 -164
- package/dist/index.cjs +1195 -874
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.js +1192 -871
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +5 -10
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +6 -8
- package/dist/react.d.ts +6 -8
- package/dist/react.js +6 -10
- package/dist/react.js.map +1 -1
- package/package.json +3 -2
- package/skills/doxum-runtime/SKILL.md +2 -1
- package/skills/doxum-runtime/references/patterns.en.md +4 -4
- package/skills/doxum-runtime/references/patterns.zh-CN.md +2 -2
- package/skills/doxum-runtime/references/projections.en.md +19 -4
- package/skills/doxum-runtime/references/projections.zh-CN.md +15 -4
- package/dist/advanced.cjs.map +0 -1
- package/dist/advanced.js.map +0 -1
- package/dist/definition-C__VJqA4.d.cts +0 -136
- package/dist/definition-Dc1Udkop.d.ts +0 -136
- package/dist/definition-Z6TagMup.cjs +0 -107
- package/dist/definition-Z6TagMup.cjs.map +0 -1
- package/dist/definition-c6XQXzvK.js +0 -72
- package/dist/definition-c6XQXzvK.js.map +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
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 definition with no materialized state; root definitions are reusable. */
|
|
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, C = undefined> = Projection<T, C> & {
|
|
87
|
+
readonly [writableInput]: true;
|
|
88
|
+
};
|
|
89
|
+
type ProjectionValues$1<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
|
+
collection: <K extends string, V>(initial?: ReadonlyMap<K, V>) => Input<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
92
|
+
};
|
|
93
|
+
/** Establish a lazy reactive boundary from a document, readable, or external source. */
|
|
94
|
+
declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
|
|
95
|
+
declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
|
|
96
|
+
declare function observe<K extends string, V>(source: ExternalCollectionSource<K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
97
|
+
declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
98
|
+
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>>>>>;
|
|
99
|
+
declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
|
|
100
|
+
declare function derive<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues$1<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region core/src/projection/advanced.d.ts
|
|
103
|
+
type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
|
|
104
|
+
type ProjectionChanges<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<unknown, infer C> ? [C] extends [undefined] ? undefined : C | undefined : undefined };
|
|
105
|
+
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
106
|
+
readonly sources: ProjectionValues<D>;
|
|
107
|
+
readonly changes: ProjectionChanges<D>;
|
|
108
|
+
readonly previous: T | undefined;
|
|
109
|
+
readonly reset: boolean;
|
|
110
|
+
readonly cause: unknown;
|
|
111
|
+
readonly state: Record<string, unknown>;
|
|
112
|
+
};
|
|
113
|
+
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
114
|
+
readonly kind: 'rebuild';
|
|
115
|
+
};
|
|
116
|
+
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
117
|
+
readonly sources: ProjectionValues<D>;
|
|
118
|
+
readonly changes: ProjectionChanges<D>;
|
|
119
|
+
readonly previous: CollectionRead<K, V>;
|
|
120
|
+
readonly next: CollectionRead<K, V>;
|
|
121
|
+
readonly reset: boolean;
|
|
122
|
+
readonly cause: unknown;
|
|
123
|
+
readonly state: Record<string, unknown>;
|
|
124
|
+
readonly output: CollectionDraft<K, V>;
|
|
125
|
+
};
|
|
126
|
+
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
127
|
+
readonly kind: 'rebuild';
|
|
128
|
+
};
|
|
129
|
+
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
130
|
+
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
131
|
+
declare function createIncrementalCollection<const D extends readonly Projection<unknown, unknown>[], K extends string, V>(dependencies: D, processor: IncrementalCollectionProcessor<D, K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
132
|
+
declare const incremental: typeof createIncrementalValue & {
|
|
133
|
+
collection: typeof createIncrementalCollection;
|
|
134
|
+
};
|
|
135
|
+
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
136
|
+
//#endregion
|
|
137
|
+
export { ExternalValueSource as _, IncrementalValueProcessor as a, Projection as c, observe as d, CollectionChange as f, ExternalValueEvent as g, ExternalCollectionSource as h, IncrementalValueContext as i, derive as l, ExternalCollectionRead as m, IncrementalCollectionProcessor as n, incremental as o, ExternalCollectionEvent as p, IncrementalDependencies as r, Input as s, IncrementalCollectionContext as t, input as u, ProjectionDisposedError as v, ProjectionError as y };
|
|
138
|
+
//# sourceMappingURL=advanced-GTwIWcn6.d.cts.map
|
|
@@ -0,0 +1,138 @@
|
|
|
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 definition with no materialized state; root definitions are reusable. */
|
|
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, C = undefined> = Projection<T, C> & {
|
|
87
|
+
readonly [writableInput]: true;
|
|
88
|
+
};
|
|
89
|
+
type ProjectionValues$1<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
|
+
collection: <K extends string, V>(initial?: ReadonlyMap<K, V>) => Input<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
92
|
+
};
|
|
93
|
+
/** Establish a lazy reactive boundary from a document, readable, or external source. */
|
|
94
|
+
declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
|
|
95
|
+
declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
|
|
96
|
+
declare function observe<K extends string, V>(source: ExternalCollectionSource<K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
97
|
+
declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
98
|
+
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>>>>>;
|
|
99
|
+
declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
|
|
100
|
+
declare function derive<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues$1<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region core/src/projection/advanced.d.ts
|
|
103
|
+
type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
|
|
104
|
+
type ProjectionChanges<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<unknown, infer C> ? [C] extends [undefined] ? undefined : C | undefined : undefined };
|
|
105
|
+
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
106
|
+
readonly sources: ProjectionValues<D>;
|
|
107
|
+
readonly changes: ProjectionChanges<D>;
|
|
108
|
+
readonly previous: T | undefined;
|
|
109
|
+
readonly reset: boolean;
|
|
110
|
+
readonly cause: unknown;
|
|
111
|
+
readonly state: Record<string, unknown>;
|
|
112
|
+
};
|
|
113
|
+
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
114
|
+
readonly kind: 'rebuild';
|
|
115
|
+
};
|
|
116
|
+
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
117
|
+
readonly sources: ProjectionValues<D>;
|
|
118
|
+
readonly changes: ProjectionChanges<D>;
|
|
119
|
+
readonly previous: CollectionRead<K, V>;
|
|
120
|
+
readonly next: CollectionRead<K, V>;
|
|
121
|
+
readonly reset: boolean;
|
|
122
|
+
readonly cause: unknown;
|
|
123
|
+
readonly state: Record<string, unknown>;
|
|
124
|
+
readonly output: CollectionDraft<K, V>;
|
|
125
|
+
};
|
|
126
|
+
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
127
|
+
readonly kind: 'rebuild';
|
|
128
|
+
};
|
|
129
|
+
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
130
|
+
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
131
|
+
declare function createIncrementalCollection<const D extends readonly Projection<unknown, unknown>[], K extends string, V>(dependencies: D, processor: IncrementalCollectionProcessor<D, K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
|
|
132
|
+
declare const incremental: typeof createIncrementalValue & {
|
|
133
|
+
collection: typeof createIncrementalCollection;
|
|
134
|
+
};
|
|
135
|
+
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
136
|
+
//#endregion
|
|
137
|
+
export { ExternalValueSource as _, IncrementalValueProcessor as a, Projection as c, observe as d, CollectionChange as f, ExternalValueEvent as g, ExternalCollectionSource as h, IncrementalValueContext as i, derive as l, ExternalCollectionRead as m, IncrementalCollectionProcessor as n, incremental as o, ExternalCollectionEvent as p, IncrementalDependencies as r, Input as s, IncrementalCollectionContext as t, input as u, ProjectionDisposedError as v, ProjectionError as y };
|
|
138
|
+
//# sourceMappingURL=advanced-c0F3gpLG.d.ts.map
|
package/dist/advanced.cjs
CHANGED
|
@@ -1,166 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
//#region core/src/projection/advanced.ts
|
|
5
|
-
const dependenciesOf = (dependencies) => Object.fromEntries(dependencies.map((dependency, index) => [`d${index}`, dependency]));
|
|
6
|
-
const resetCollectionChange = Object.freeze({ kind: "reset" });
|
|
7
|
-
const isCollectionSource = (source) => Boolean(source && typeof source === "object" && "ids" in source && typeof source.ids === "function" && "previous" in source && "transitions" in source && typeof source.transitions === "function");
|
|
8
|
-
const collectionChange = (source) => {
|
|
9
|
-
if (!isCollectionSource(source)) return void 0;
|
|
10
|
-
if (source.reset || source.change?.kind === "reset") return resetCollectionChange;
|
|
11
|
-
const impact = source.change;
|
|
12
|
-
if (!impact) return void 0;
|
|
13
|
-
const added = [];
|
|
14
|
-
const updated = [];
|
|
15
|
-
const removed = [];
|
|
16
|
-
for (const transition of source.transitions()) if (transition.kind === "added") added.push({
|
|
17
|
-
key: transition.key,
|
|
18
|
-
kind: transition.kind,
|
|
19
|
-
after: transition.after
|
|
20
|
-
});
|
|
21
|
-
else if (transition.kind === "updated") updated.push(transition);
|
|
22
|
-
else removed.push({
|
|
23
|
-
key: transition.key,
|
|
24
|
-
kind: transition.kind,
|
|
25
|
-
before: transition.before
|
|
26
|
-
});
|
|
27
|
-
const order = impact.orderChanged ? {
|
|
28
|
-
before: Object.freeze([...source.previous.ids()]),
|
|
29
|
-
after: Object.freeze([...source.ids()])
|
|
30
|
-
} : void 0;
|
|
31
|
-
if (!added.length && !updated.length && !removed.length && !order) return void 0;
|
|
32
|
-
return Object.freeze({
|
|
33
|
-
kind: "incremental",
|
|
34
|
-
added: Object.freeze(added),
|
|
35
|
-
updated: Object.freeze(updated),
|
|
36
|
-
removed: Object.freeze(removed),
|
|
37
|
-
...order ? { order: Object.freeze(order) } : {}
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const sourceCause = (sources) => {
|
|
41
|
-
for (const source of Object.values(sources)) if (source && typeof source === "object" && "cause" in source && source.cause !== void 0) return source.cause;
|
|
42
|
-
};
|
|
43
|
-
const publicSource = (source) => {
|
|
44
|
-
if (!source || typeof source !== "object") return source;
|
|
45
|
-
if ("value" in source) return source.value;
|
|
46
|
-
if ("read" in source) {
|
|
47
|
-
const read = source.read;
|
|
48
|
-
if (read && typeof read === "object" && "ids" in read && typeof read.ids === "function") {
|
|
49
|
-
const result = /* @__PURE__ */ new Map();
|
|
50
|
-
for (const id of read.ids()) result.set(id, read.get(id));
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
return require_scope.snapshot(read);
|
|
54
|
-
}
|
|
55
|
-
if ("ids" in source && typeof source.ids === "function") {
|
|
56
|
-
const result = /* @__PURE__ */ new Map();
|
|
57
|
-
const read = source;
|
|
58
|
-
for (const id of read.ids()) result.set(id, read.get(id));
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
return source;
|
|
62
|
-
};
|
|
63
|
-
const publicInputs = (sources, initial = false) => {
|
|
64
|
-
const values = [];
|
|
65
|
-
const changes = [];
|
|
66
|
-
for (const key of Object.keys(sources).sort((left, right) => Number(left.slice(1)) - Number(right.slice(1)))) {
|
|
67
|
-
const source = sources[key];
|
|
68
|
-
values.push(publicSource(source));
|
|
69
|
-
changes.push(initial && isCollectionSource(source) ? resetCollectionChange : collectionChange(source));
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
values,
|
|
73
|
-
changes
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const normalizeValue = (result) => result && typeof result === "object" && result.kind === "value" ? {
|
|
77
|
-
value: result.value,
|
|
78
|
-
state: result.state
|
|
79
|
-
} : { value: result };
|
|
80
|
-
function createIncrementalValue(dependencies, processor) {
|
|
81
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
82
|
-
let state = Object.create(null);
|
|
83
|
-
let current;
|
|
84
|
-
const build = (sources) => {
|
|
85
|
-
state = Object.create(null);
|
|
86
|
-
const publicInputsForBuild = publicInputs(sources, true);
|
|
87
|
-
const result = processor({
|
|
88
|
-
sources: publicInputsForBuild.values,
|
|
89
|
-
changes: publicInputsForBuild.changes,
|
|
90
|
-
previous: void 0,
|
|
91
|
-
reset: true,
|
|
92
|
-
cause: sourceCause(sources),
|
|
93
|
-
state
|
|
94
|
-
});
|
|
95
|
-
if (result && typeof result === "object" && "kind" in result) throw new TypeError("Initial incremental processor cannot rebuild.");
|
|
96
|
-
const normalized = normalizeValue(result);
|
|
97
|
-
current = normalized.value;
|
|
98
|
-
if (normalized.state) state = normalized.state;
|
|
99
|
-
return {
|
|
100
|
-
value: current,
|
|
101
|
-
update: (nextSources) => {
|
|
102
|
-
const publicInputsForUpdate = publicInputs(nextSources);
|
|
103
|
-
const next = processor({
|
|
104
|
-
sources: publicInputsForUpdate.values,
|
|
105
|
-
changes: publicInputsForUpdate.changes,
|
|
106
|
-
previous: current,
|
|
107
|
-
reset: false,
|
|
108
|
-
cause: sourceCause(nextSources),
|
|
109
|
-
state
|
|
110
|
-
});
|
|
111
|
-
if (next && typeof next === "object" && "kind" in next) return next;
|
|
112
|
-
const nextValue = normalizeValue(next);
|
|
113
|
-
current = nextValue.value;
|
|
114
|
-
if (nextValue.state) state = nextValue.state;
|
|
115
|
-
return {
|
|
116
|
-
kind: "changed",
|
|
117
|
-
value: current
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
return require_definition.defineIncrementalValue({
|
|
123
|
-
dependencies: dependencyMap,
|
|
124
|
-
build
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
function createIncrementalCollection(dependencies, processor) {
|
|
128
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
129
|
-
let state = Object.create(null);
|
|
130
|
-
const build = (input) => {
|
|
131
|
-
state = Object.create(null);
|
|
132
|
-
const publicInputsForBuild = publicInputs(input.sources, true);
|
|
133
|
-
if (processor({
|
|
134
|
-
sources: publicInputsForBuild.values,
|
|
135
|
-
changes: publicInputsForBuild.changes,
|
|
136
|
-
previous: input.previous,
|
|
137
|
-
next: input.next,
|
|
138
|
-
reset: true,
|
|
139
|
-
cause: sourceCause(input.sources),
|
|
140
|
-
state,
|
|
141
|
-
output: input.writer
|
|
142
|
-
})?.kind === "rebuild") throw new TypeError("Initial incremental collection processor cannot rebuild.");
|
|
143
|
-
return { update: (nextInput) => {
|
|
144
|
-
const publicInputsForUpdate = publicInputs(nextInput.sources);
|
|
145
|
-
return processor({
|
|
146
|
-
sources: publicInputsForUpdate.values,
|
|
147
|
-
changes: publicInputsForUpdate.changes,
|
|
148
|
-
previous: nextInput.previous,
|
|
149
|
-
next: nextInput.next,
|
|
150
|
-
reset: false,
|
|
151
|
-
cause: sourceCause(nextInput.sources),
|
|
152
|
-
state,
|
|
153
|
-
output: nextInput.writer
|
|
154
|
-
});
|
|
155
|
-
} };
|
|
156
|
-
};
|
|
157
|
-
return require_definition.defineIncrementalCollection({
|
|
158
|
-
dependencies: dependencyMap,
|
|
159
|
-
build
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
const incremental = Object.assign(createIncrementalValue, { collection: createIncrementalCollection });
|
|
163
|
-
//#endregion
|
|
164
|
-
exports.incremental = incremental;
|
|
165
|
-
|
|
166
|
-
//# sourceMappingURL=advanced.cjs.map
|
|
2
|
+
const require_advanced = require("./advanced-Dgu8-bPS.cjs");
|
|
3
|
+
exports.incremental = require_advanced.incremental;
|
package/dist/advanced.d.cts
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
//#region core/src/projection/advanced.d.ts
|
|
4
|
-
type IncrementalState = Record<string, unknown>;
|
|
5
|
-
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
6
|
-
readonly sources: ProjectionValues<D>;
|
|
7
|
-
readonly changes: ProjectionChanges<D>;
|
|
8
|
-
readonly previous: T | undefined;
|
|
9
|
-
readonly reset: boolean;
|
|
10
|
-
readonly cause: unknown;
|
|
11
|
-
readonly state: IncrementalState;
|
|
12
|
-
};
|
|
13
|
-
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
14
|
-
readonly kind: 'value';
|
|
15
|
-
readonly value: T;
|
|
16
|
-
readonly state?: IncrementalState;
|
|
17
|
-
} | {
|
|
18
|
-
readonly kind: 'rebuild';
|
|
19
|
-
};
|
|
20
|
-
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
21
|
-
readonly sources: ProjectionValues<D>;
|
|
22
|
-
readonly changes: ProjectionChanges<D>;
|
|
23
|
-
readonly previous: CollectionRead<K, V>;
|
|
24
|
-
readonly next: CollectionRead<K, V>;
|
|
25
|
-
readonly reset: boolean;
|
|
26
|
-
readonly cause: unknown;
|
|
27
|
-
readonly state: IncrementalState;
|
|
28
|
-
readonly output: CollectionDraft<K, V>;
|
|
29
|
-
};
|
|
30
|
-
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
31
|
-
readonly kind: 'rebuild';
|
|
32
|
-
};
|
|
33
|
-
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
34
|
-
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
35
|
-
declare function createIncrementalCollection<const D extends readonly Projection<unknown, unknown>[], K extends string, V>(dependencies: D, processor: IncrementalCollectionProcessor<D, K, V>): CollectionProjection<K, V>;
|
|
36
|
-
declare const incremental: typeof createIncrementalValue & {
|
|
37
|
-
collection: typeof createIncrementalCollection;
|
|
38
|
-
};
|
|
39
|
-
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { type CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalState, IncrementalValueContext, IncrementalValueProcessor, incremental };
|
|
42
|
-
//# sourceMappingURL=advanced.d.cts.map
|
|
1
|
+
import { a as IncrementalValueProcessor, f as CollectionChange, i as IncrementalValueContext, n as IncrementalCollectionProcessor, o as incremental, r as IncrementalDependencies, t as IncrementalCollectionContext } from "./advanced-GTwIWcn6.cjs";
|
|
2
|
+
export { CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalValueContext, IncrementalValueProcessor, incremental };
|
package/dist/advanced.d.ts
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
//#region core/src/projection/advanced.d.ts
|
|
4
|
-
type IncrementalState = Record<string, unknown>;
|
|
5
|
-
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
6
|
-
readonly sources: ProjectionValues<D>;
|
|
7
|
-
readonly changes: ProjectionChanges<D>;
|
|
8
|
-
readonly previous: T | undefined;
|
|
9
|
-
readonly reset: boolean;
|
|
10
|
-
readonly cause: unknown;
|
|
11
|
-
readonly state: IncrementalState;
|
|
12
|
-
};
|
|
13
|
-
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
14
|
-
readonly kind: 'value';
|
|
15
|
-
readonly value: T;
|
|
16
|
-
readonly state?: IncrementalState;
|
|
17
|
-
} | {
|
|
18
|
-
readonly kind: 'rebuild';
|
|
19
|
-
};
|
|
20
|
-
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
21
|
-
readonly sources: ProjectionValues<D>;
|
|
22
|
-
readonly changes: ProjectionChanges<D>;
|
|
23
|
-
readonly previous: CollectionRead<K, V>;
|
|
24
|
-
readonly next: CollectionRead<K, V>;
|
|
25
|
-
readonly reset: boolean;
|
|
26
|
-
readonly cause: unknown;
|
|
27
|
-
readonly state: IncrementalState;
|
|
28
|
-
readonly output: CollectionDraft<K, V>;
|
|
29
|
-
};
|
|
30
|
-
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
31
|
-
readonly kind: 'rebuild';
|
|
32
|
-
};
|
|
33
|
-
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
34
|
-
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
35
|
-
declare function createIncrementalCollection<const D extends readonly Projection<unknown, unknown>[], K extends string, V>(dependencies: D, processor: IncrementalCollectionProcessor<D, K, V>): CollectionProjection<K, V>;
|
|
36
|
-
declare const incremental: typeof createIncrementalValue & {
|
|
37
|
-
collection: typeof createIncrementalCollection;
|
|
38
|
-
};
|
|
39
|
-
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { type CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalState, IncrementalValueContext, IncrementalValueProcessor, incremental };
|
|
42
|
-
//# sourceMappingURL=advanced.d.ts.map
|
|
1
|
+
import { a as IncrementalValueProcessor, f as CollectionChange, i as IncrementalValueContext, n as IncrementalCollectionProcessor, o as incremental, r as IncrementalDependencies, t as IncrementalCollectionContext } from "./advanced-c0F3gpLG.js";
|
|
2
|
+
export { CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalValueContext, IncrementalValueProcessor, incremental };
|