doxum 0.1.17 → 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 +30 -3
- 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/{definition-Bf8Z7xtX.d.cts → advanced-GTwIWcn6.d.cts} +44 -7
- package/dist/{definition-BdLGD8Rq.d.ts → advanced-c0F3gpLG.d.ts} +44 -7
- package/dist/advanced.cjs +2 -149
- package/dist/advanced.d.cts +2 -39
- package/dist/advanced.d.ts +2 -39
- package/dist/advanced.js +1 -148
- package/dist/index.cjs +346 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +342 -33
- package/dist/index.js.map +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/skills/doxum-runtime/references/projections.en.md +13 -1
- package/skills/doxum-runtime/references/projections.zh-CN.md +9 -1
- package/dist/advanced.cjs.map +0 -1
- package/dist/advanced.js.map +0 -1
- package/dist/definition-DUo1lfQ8.js +0 -71
- package/dist/definition-DUo1lfQ8.js.map +0 -1
- package/dist/definition-De6rhTlZ.cjs +0 -106
- package/dist/definition-De6rhTlZ.cjs.map +0 -1
|
@@ -77,17 +77,19 @@ declare class ProjectionDisposedError extends Error {
|
|
|
77
77
|
declare const projectionDefinition: unique symbol;
|
|
78
78
|
declare const projectionChanges: unique symbol;
|
|
79
79
|
declare const writableInput: unique symbol;
|
|
80
|
-
/** A lazy
|
|
80
|
+
/** A lazy definition with no materialized state; root definitions are reusable. */
|
|
81
81
|
type Projection<T, C = undefined> = {
|
|
82
82
|
readonly [projectionDefinition]: T;
|
|
83
83
|
readonly [projectionChanges]: C;
|
|
84
84
|
};
|
|
85
85
|
/** A runtime-local writable projection definition. */
|
|
86
|
-
type Input<T> = Projection<T> & {
|
|
86
|
+
type Input<T, C = undefined> = Projection<T, C> & {
|
|
87
87
|
readonly [writableInput]: true;
|
|
88
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
|
|
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
|
+
};
|
|
91
93
|
/** Establish a lazy reactive boundary from a document, readable, or external source. */
|
|
92
94
|
declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
|
|
93
95
|
declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
|
|
@@ -95,7 +97,42 @@ declare function observe<K extends string, V>(source: ExternalCollectionSource<K
|
|
|
95
97
|
declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
96
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>>>>>;
|
|
97
99
|
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>;
|
|
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>;
|
|
99
136
|
//#endregion
|
|
100
|
-
export {
|
|
101
|
-
//# sourceMappingURL=
|
|
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
|
|
@@ -77,17 +77,19 @@ declare class ProjectionDisposedError extends Error {
|
|
|
77
77
|
declare const projectionDefinition: unique symbol;
|
|
78
78
|
declare const projectionChanges: unique symbol;
|
|
79
79
|
declare const writableInput: unique symbol;
|
|
80
|
-
/** A lazy
|
|
80
|
+
/** A lazy definition with no materialized state; root definitions are reusable. */
|
|
81
81
|
type Projection<T, C = undefined> = {
|
|
82
82
|
readonly [projectionDefinition]: T;
|
|
83
83
|
readonly [projectionChanges]: C;
|
|
84
84
|
};
|
|
85
85
|
/** A runtime-local writable projection definition. */
|
|
86
|
-
type Input<T> = Projection<T> & {
|
|
86
|
+
type Input<T, C = undefined> = Projection<T, C> & {
|
|
87
87
|
readonly [writableInput]: true;
|
|
88
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
|
|
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
|
+
};
|
|
91
93
|
/** Establish a lazy reactive boundary from a document, readable, or external source. */
|
|
92
94
|
declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
|
|
93
95
|
declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
|
|
@@ -95,7 +97,42 @@ declare function observe<K extends string, V>(source: ExternalCollectionSource<K
|
|
|
95
97
|
declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
96
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>>>>>;
|
|
97
99
|
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>;
|
|
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>;
|
|
99
136
|
//#endregion
|
|
100
|
-
export {
|
|
101
|
-
//# sourceMappingURL=
|
|
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,150 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
//#region core/src/projection/advanced.ts
|
|
5
|
-
const resetCollectionChange = Object.freeze({ kind: "reset" });
|
|
6
|
-
const isRebuild = (value) => value !== null && typeof value === "object" && value.kind === "rebuild";
|
|
7
|
-
const collectionChange = (source) => {
|
|
8
|
-
if (!source || typeof source !== "object" || !("kind" in source)) return void 0;
|
|
9
|
-
if (source.kind !== "collection") return void 0;
|
|
10
|
-
return source.change;
|
|
11
|
-
};
|
|
12
|
-
const sourceCause = (sources) => {
|
|
13
|
-
for (const source of Object.values(sources)) if (source && typeof source === "object" && "kind" in source) {
|
|
14
|
-
const cause = source.cause;
|
|
15
|
-
if (cause !== void 0) return cause;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const collectionView = (read) => {
|
|
19
|
-
const entries = function* () {
|
|
20
|
-
for (const key of read.ids()) yield [key, read.get(key)];
|
|
21
|
-
};
|
|
22
|
-
const values = function* () {
|
|
23
|
-
for (const key of read.ids()) yield read.get(key);
|
|
24
|
-
};
|
|
25
|
-
const view = {
|
|
26
|
-
get: (key) => read.get(key),
|
|
27
|
-
has: (key) => read.has(key),
|
|
28
|
-
get size() {
|
|
29
|
-
return read.ids().length;
|
|
30
|
-
},
|
|
31
|
-
keys: () => read.ids()[Symbol.iterator](),
|
|
32
|
-
values,
|
|
33
|
-
entries,
|
|
34
|
-
forEach: (callback, thisArg) => {
|
|
35
|
-
for (const key of read.ids()) callback.call(thisArg, read.get(key), key, view);
|
|
36
|
-
},
|
|
37
|
-
[Symbol.iterator]: entries
|
|
38
|
-
};
|
|
39
|
-
return Object.freeze(view);
|
|
40
|
-
};
|
|
41
|
-
const publicSource = (source) => {
|
|
42
|
-
if (!source || typeof source !== "object") return source;
|
|
43
|
-
if (!("kind" in source)) return source;
|
|
44
|
-
if (source.kind === "value") return source.value;
|
|
45
|
-
if (source.kind === "document") return require_scope.snapshot(source.read);
|
|
46
|
-
if (source.kind === "collection") {
|
|
47
|
-
const read = source.read;
|
|
48
|
-
return collectionView(read);
|
|
49
|
-
}
|
|
50
|
-
return source;
|
|
51
|
-
};
|
|
52
|
-
const publicInputs = (sources, initial = false) => {
|
|
53
|
-
const values = [];
|
|
54
|
-
const changes = [];
|
|
55
|
-
for (const key of Object.keys(sources).sort((left, right) => Number(left.slice(1)) - Number(right.slice(1)))) {
|
|
56
|
-
const source = sources[key];
|
|
57
|
-
values.push(publicSource(source));
|
|
58
|
-
changes.push(initial && source && typeof source === "object" && "kind" in source && source.kind === "collection" ? resetCollectionChange : collectionChange(source));
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
values,
|
|
62
|
-
changes
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
function createIncrementalValue(dependencies, processor) {
|
|
66
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
67
|
-
let state = Object.create(null);
|
|
68
|
-
let current;
|
|
69
|
-
const build = (sources) => {
|
|
70
|
-
state = Object.create(null);
|
|
71
|
-
const publicInputsForBuild = publicInputs(sources, true);
|
|
72
|
-
const result = processor({
|
|
73
|
-
sources: publicInputsForBuild.values,
|
|
74
|
-
changes: publicInputsForBuild.changes,
|
|
75
|
-
previous: void 0,
|
|
76
|
-
reset: true,
|
|
77
|
-
cause: sourceCause(sources),
|
|
78
|
-
state
|
|
79
|
-
});
|
|
80
|
-
if (isRebuild(result)) throw new TypeError("Initial incremental processor cannot rebuild.");
|
|
81
|
-
current = result;
|
|
82
|
-
return {
|
|
83
|
-
value: current,
|
|
84
|
-
update: (nextSources) => {
|
|
85
|
-
const publicInputsForUpdate = publicInputs(nextSources);
|
|
86
|
-
const next = processor({
|
|
87
|
-
sources: publicInputsForUpdate.values,
|
|
88
|
-
changes: publicInputsForUpdate.changes,
|
|
89
|
-
previous: current,
|
|
90
|
-
reset: false,
|
|
91
|
-
cause: sourceCause(nextSources),
|
|
92
|
-
state
|
|
93
|
-
});
|
|
94
|
-
if (isRebuild(next)) return next;
|
|
95
|
-
current = next;
|
|
96
|
-
return {
|
|
97
|
-
kind: "changed",
|
|
98
|
-
value: current
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
return require_definition.defineIncrementalValue({
|
|
104
|
-
dependencies: dependencyMap,
|
|
105
|
-
build
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function dependenciesOf(dependencies) {
|
|
109
|
-
return Object.fromEntries(dependencies.map((dependency, index) => [`d${index}`, dependency]));
|
|
110
|
-
}
|
|
111
|
-
function createIncrementalCollection(dependencies, processor) {
|
|
112
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
113
|
-
let state = Object.create(null);
|
|
114
|
-
const build = (input) => {
|
|
115
|
-
state = Object.create(null);
|
|
116
|
-
const publicInputsForBuild = publicInputs(input.sources, true);
|
|
117
|
-
if (processor({
|
|
118
|
-
sources: publicInputsForBuild.values,
|
|
119
|
-
changes: publicInputsForBuild.changes,
|
|
120
|
-
previous: input.previous,
|
|
121
|
-
next: input.next,
|
|
122
|
-
reset: true,
|
|
123
|
-
cause: sourceCause(input.sources),
|
|
124
|
-
state,
|
|
125
|
-
output: input.output
|
|
126
|
-
})?.kind === "rebuild") throw new TypeError("Initial incremental collection processor cannot rebuild.");
|
|
127
|
-
return { update: (nextInput) => {
|
|
128
|
-
const publicInputsForUpdate = publicInputs(nextInput.sources);
|
|
129
|
-
return processor({
|
|
130
|
-
sources: publicInputsForUpdate.values,
|
|
131
|
-
changes: publicInputsForUpdate.changes,
|
|
132
|
-
previous: nextInput.previous,
|
|
133
|
-
next: nextInput.next,
|
|
134
|
-
reset: false,
|
|
135
|
-
cause: sourceCause(nextInput.sources),
|
|
136
|
-
state,
|
|
137
|
-
output: nextInput.output
|
|
138
|
-
});
|
|
139
|
-
} };
|
|
140
|
-
};
|
|
141
|
-
return require_definition.defineIncrementalCollection({
|
|
142
|
-
dependencies: dependencyMap,
|
|
143
|
-
build
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const incremental = Object.assign(createIncrementalValue, { collection: createIncrementalCollection });
|
|
147
|
-
//#endregion
|
|
148
|
-
exports.incremental = incremental;
|
|
149
|
-
|
|
150
|
-
//# 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,39 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region core/src/projection/advanced.d.ts
|
|
4
|
-
type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
|
|
5
|
-
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 };
|
|
6
|
-
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
7
|
-
readonly sources: ProjectionValues<D>;
|
|
8
|
-
readonly changes: ProjectionChanges<D>;
|
|
9
|
-
readonly previous: T | undefined;
|
|
10
|
-
readonly reset: boolean;
|
|
11
|
-
readonly cause: unknown;
|
|
12
|
-
readonly state: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
15
|
-
readonly kind: 'rebuild';
|
|
16
|
-
};
|
|
17
|
-
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
18
|
-
readonly sources: ProjectionValues<D>;
|
|
19
|
-
readonly changes: ProjectionChanges<D>;
|
|
20
|
-
readonly previous: CollectionRead<K, V>;
|
|
21
|
-
readonly next: CollectionRead<K, V>;
|
|
22
|
-
readonly reset: boolean;
|
|
23
|
-
readonly cause: unknown;
|
|
24
|
-
readonly state: Record<string, unknown>;
|
|
25
|
-
readonly output: CollectionDraft<K, V>;
|
|
26
|
-
};
|
|
27
|
-
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
28
|
-
readonly kind: 'rebuild';
|
|
29
|
-
};
|
|
30
|
-
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
31
|
-
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
32
|
-
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>>;
|
|
33
|
-
declare const incremental: typeof createIncrementalValue & {
|
|
34
|
-
collection: typeof createIncrementalCollection;
|
|
35
|
-
};
|
|
36
|
-
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { type CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalValueContext, IncrementalValueProcessor, incremental };
|
|
39
|
-
//# 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,39 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region core/src/projection/advanced.d.ts
|
|
4
|
-
type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
|
|
5
|
-
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 };
|
|
6
|
-
type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
|
|
7
|
-
readonly sources: ProjectionValues<D>;
|
|
8
|
-
readonly changes: ProjectionChanges<D>;
|
|
9
|
-
readonly previous: T | undefined;
|
|
10
|
-
readonly reset: boolean;
|
|
11
|
-
readonly cause: unknown;
|
|
12
|
-
readonly state: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | {
|
|
15
|
-
readonly kind: 'rebuild';
|
|
16
|
-
};
|
|
17
|
-
type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
|
|
18
|
-
readonly sources: ProjectionValues<D>;
|
|
19
|
-
readonly changes: ProjectionChanges<D>;
|
|
20
|
-
readonly previous: CollectionRead<K, V>;
|
|
21
|
-
readonly next: CollectionRead<K, V>;
|
|
22
|
-
readonly reset: boolean;
|
|
23
|
-
readonly cause: unknown;
|
|
24
|
-
readonly state: Record<string, unknown>;
|
|
25
|
-
readonly output: CollectionDraft<K, V>;
|
|
26
|
-
};
|
|
27
|
-
type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | {
|
|
28
|
-
readonly kind: 'rebuild';
|
|
29
|
-
};
|
|
30
|
-
type DependencyMap<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D as `d${Extract<K, number>}`]: D[K] };
|
|
31
|
-
declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
|
|
32
|
-
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>>;
|
|
33
|
-
declare const incremental: typeof createIncrementalValue & {
|
|
34
|
-
collection: typeof createIncrementalCollection;
|
|
35
|
-
};
|
|
36
|
-
type IncrementalDependencies<D extends readonly Projection<unknown, unknown>[]> = DependencyMap<D>;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { type CollectionChange, IncrementalCollectionContext, IncrementalCollectionProcessor, IncrementalDependencies, IncrementalValueContext, IncrementalValueProcessor, incremental };
|
|
39
|
-
//# 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 };
|
package/dist/advanced.js
CHANGED
|
@@ -1,149 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as defineIncrementalValue, t as defineIncrementalCollection } from "./definition-DUo1lfQ8.js";
|
|
3
|
-
//#region core/src/projection/advanced.ts
|
|
4
|
-
const resetCollectionChange = Object.freeze({ kind: "reset" });
|
|
5
|
-
const isRebuild = (value) => value !== null && typeof value === "object" && value.kind === "rebuild";
|
|
6
|
-
const collectionChange = (source) => {
|
|
7
|
-
if (!source || typeof source !== "object" || !("kind" in source)) return void 0;
|
|
8
|
-
if (source.kind !== "collection") return void 0;
|
|
9
|
-
return source.change;
|
|
10
|
-
};
|
|
11
|
-
const sourceCause = (sources) => {
|
|
12
|
-
for (const source of Object.values(sources)) if (source && typeof source === "object" && "kind" in source) {
|
|
13
|
-
const cause = source.cause;
|
|
14
|
-
if (cause !== void 0) return cause;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const collectionView = (read) => {
|
|
18
|
-
const entries = function* () {
|
|
19
|
-
for (const key of read.ids()) yield [key, read.get(key)];
|
|
20
|
-
};
|
|
21
|
-
const values = function* () {
|
|
22
|
-
for (const key of read.ids()) yield read.get(key);
|
|
23
|
-
};
|
|
24
|
-
const view = {
|
|
25
|
-
get: (key) => read.get(key),
|
|
26
|
-
has: (key) => read.has(key),
|
|
27
|
-
get size() {
|
|
28
|
-
return read.ids().length;
|
|
29
|
-
},
|
|
30
|
-
keys: () => read.ids()[Symbol.iterator](),
|
|
31
|
-
values,
|
|
32
|
-
entries,
|
|
33
|
-
forEach: (callback, thisArg) => {
|
|
34
|
-
for (const key of read.ids()) callback.call(thisArg, read.get(key), key, view);
|
|
35
|
-
},
|
|
36
|
-
[Symbol.iterator]: entries
|
|
37
|
-
};
|
|
38
|
-
return Object.freeze(view);
|
|
39
|
-
};
|
|
40
|
-
const publicSource = (source) => {
|
|
41
|
-
if (!source || typeof source !== "object") return source;
|
|
42
|
-
if (!("kind" in source)) return source;
|
|
43
|
-
if (source.kind === "value") return source.value;
|
|
44
|
-
if (source.kind === "document") return snapshot(source.read);
|
|
45
|
-
if (source.kind === "collection") {
|
|
46
|
-
const read = source.read;
|
|
47
|
-
return collectionView(read);
|
|
48
|
-
}
|
|
49
|
-
return source;
|
|
50
|
-
};
|
|
51
|
-
const publicInputs = (sources, initial = false) => {
|
|
52
|
-
const values = [];
|
|
53
|
-
const changes = [];
|
|
54
|
-
for (const key of Object.keys(sources).sort((left, right) => Number(left.slice(1)) - Number(right.slice(1)))) {
|
|
55
|
-
const source = sources[key];
|
|
56
|
-
values.push(publicSource(source));
|
|
57
|
-
changes.push(initial && source && typeof source === "object" && "kind" in source && source.kind === "collection" ? resetCollectionChange : collectionChange(source));
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
values,
|
|
61
|
-
changes
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
function createIncrementalValue(dependencies, processor) {
|
|
65
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
66
|
-
let state = Object.create(null);
|
|
67
|
-
let current;
|
|
68
|
-
const build = (sources) => {
|
|
69
|
-
state = Object.create(null);
|
|
70
|
-
const publicInputsForBuild = publicInputs(sources, true);
|
|
71
|
-
const result = processor({
|
|
72
|
-
sources: publicInputsForBuild.values,
|
|
73
|
-
changes: publicInputsForBuild.changes,
|
|
74
|
-
previous: void 0,
|
|
75
|
-
reset: true,
|
|
76
|
-
cause: sourceCause(sources),
|
|
77
|
-
state
|
|
78
|
-
});
|
|
79
|
-
if (isRebuild(result)) throw new TypeError("Initial incremental processor cannot rebuild.");
|
|
80
|
-
current = result;
|
|
81
|
-
return {
|
|
82
|
-
value: current,
|
|
83
|
-
update: (nextSources) => {
|
|
84
|
-
const publicInputsForUpdate = publicInputs(nextSources);
|
|
85
|
-
const next = processor({
|
|
86
|
-
sources: publicInputsForUpdate.values,
|
|
87
|
-
changes: publicInputsForUpdate.changes,
|
|
88
|
-
previous: current,
|
|
89
|
-
reset: false,
|
|
90
|
-
cause: sourceCause(nextSources),
|
|
91
|
-
state
|
|
92
|
-
});
|
|
93
|
-
if (isRebuild(next)) return next;
|
|
94
|
-
current = next;
|
|
95
|
-
return {
|
|
96
|
-
kind: "changed",
|
|
97
|
-
value: current
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
return defineIncrementalValue({
|
|
103
|
-
dependencies: dependencyMap,
|
|
104
|
-
build
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function dependenciesOf(dependencies) {
|
|
108
|
-
return Object.fromEntries(dependencies.map((dependency, index) => [`d${index}`, dependency]));
|
|
109
|
-
}
|
|
110
|
-
function createIncrementalCollection(dependencies, processor) {
|
|
111
|
-
const dependencyMap = dependenciesOf(dependencies);
|
|
112
|
-
let state = Object.create(null);
|
|
113
|
-
const build = (input) => {
|
|
114
|
-
state = Object.create(null);
|
|
115
|
-
const publicInputsForBuild = publicInputs(input.sources, true);
|
|
116
|
-
if (processor({
|
|
117
|
-
sources: publicInputsForBuild.values,
|
|
118
|
-
changes: publicInputsForBuild.changes,
|
|
119
|
-
previous: input.previous,
|
|
120
|
-
next: input.next,
|
|
121
|
-
reset: true,
|
|
122
|
-
cause: sourceCause(input.sources),
|
|
123
|
-
state,
|
|
124
|
-
output: input.output
|
|
125
|
-
})?.kind === "rebuild") throw new TypeError("Initial incremental collection processor cannot rebuild.");
|
|
126
|
-
return { update: (nextInput) => {
|
|
127
|
-
const publicInputsForUpdate = publicInputs(nextInput.sources);
|
|
128
|
-
return processor({
|
|
129
|
-
sources: publicInputsForUpdate.values,
|
|
130
|
-
changes: publicInputsForUpdate.changes,
|
|
131
|
-
previous: nextInput.previous,
|
|
132
|
-
next: nextInput.next,
|
|
133
|
-
reset: false,
|
|
134
|
-
cause: sourceCause(nextInput.sources),
|
|
135
|
-
state,
|
|
136
|
-
output: nextInput.output
|
|
137
|
-
});
|
|
138
|
-
} };
|
|
139
|
-
};
|
|
140
|
-
return defineIncrementalCollection({
|
|
141
|
-
dependencies: dependencyMap,
|
|
142
|
-
build
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
const incremental = Object.assign(createIncrementalValue, { collection: createIncrementalCollection });
|
|
146
|
-
//#endregion
|
|
1
|
+
import { t as incremental } from "./advanced-DgRnyRAc.js";
|
|
147
2
|
export { incremental };
|
|
148
|
-
|
|
149
|
-
//# sourceMappingURL=advanced.js.map
|