doxum 0.1.34 → 0.1.35
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 +12 -0
- package/dist/advanced.cjs +1 -1
- package/dist/advanced.js +1 -1
- package/dist/index.cjs +56 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +56 -19
- package/dist/index.js.map +1 -1
- package/dist/{transform-RghG_Qxs.js → transform-3mj0eStL.js} +8 -2
- package/dist/transform-3mj0eStL.js.map +1 -0
- package/dist/{transform-Bt1Mwgrj.cjs → transform-D45KWMzj.cjs} +9 -3
- package/dist/transform-D45KWMzj.cjs.map +1 -0
- package/package.json +1 -1
- package/skills/doxum-runtime/SKILL.md +2 -2
- package/skills/doxum-runtime/references/projections.md +27 -0
- package/skills/doxum-runtime/references/public-api.md +19 -14
- package/skills/doxum-runtime/references/recipes.md +23 -0
- package/dist/transform-Bt1Mwgrj.cjs.map +0 -1
- package/dist/transform-RghG_Qxs.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -29,10 +29,18 @@ declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
|
29
29
|
declare function observe<S extends ObjectSchema<object>, P extends CollectionPath>(document: ReadonlyDocument<S>, selector: (path: SchemaPath<S>) => P): KeyedProjection<CollectionId<P>, ReadonlyValue<CollectionEntry<P>>>;
|
|
30
30
|
declare function observe<S extends ObjectSchema<object>, P>(document: ReadonlyDocument<S>, selector: (path: SchemaPath<S>) => P): Projection<PathValueOf<P>>;
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region core/src/projection/dependency.d.ts
|
|
33
|
+
type ProjectionDependencies = Readonly<Record<string, Projection<unknown>>> & Partial<Record<keyof Projection<unknown>, never>>;
|
|
34
|
+
type ProjectionValues<D extends ProjectionDependencies> = { readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never };
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region core/src/projection/keyed/entries.d.ts
|
|
37
|
+
type KeyedEntries<K extends string, V> = readonly (readonly [K, V])[];
|
|
38
|
+
//#endregion
|
|
32
39
|
//#region core/src/projection/keyed/composition.d.ts
|
|
33
40
|
type Equality$2<T> = (previous: T, next: T) => boolean;
|
|
34
41
|
declare function createKeyedFrom<K extends string, V>(source: Projection<readonly V[]>, keyOf: (value: NoInfer<V>) => Synchronous<K>, equality?: Equality$2<V>): KeyedProjection<K, V>;
|
|
35
42
|
declare function createKeyedFrom<K extends string, V>(source: readonly V[], keyOf: (value: NoInfer<V>) => Synchronous<K>, equality?: Equality$2<V>): KeyedProjection<K, V>;
|
|
43
|
+
declare function createKeyedFromEntries<const D extends ProjectionDependencies, K extends string, V>(dependencies: D, compute: (values: ProjectionValues<D>) => Synchronous<KeyedEntries<K, V>>, equality?: Equality$2<NoInfer<V>>): KeyedProjection<K, V>;
|
|
36
44
|
declare function createKeyedMerge<K extends string, V>(sources: readonly KeyedProjection<K, V>[], options: {
|
|
37
45
|
readonly conflict: 'error' | 'first' | 'last';
|
|
38
46
|
readonly equality?: Equality$2<V>;
|
|
@@ -47,14 +55,11 @@ declare function createKeyedMerge<K extends string, V>(sources: readonly KeyedPr
|
|
|
47
55
|
}): KeyedProjection<K, V>;
|
|
48
56
|
//#endregion
|
|
49
57
|
//#region core/src/projection/keyed/flat-map.d.ts
|
|
50
|
-
type Entries<K extends string, V> = readonly (readonly [K, V])[];
|
|
51
58
|
type Equality$1<V> = (previous: V, next: V) => boolean;
|
|
52
|
-
declare function createKeyedFlatMap<K extends string, V, O extends string, T>(source: KeyedProjection<K, V>, select: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<
|
|
53
|
-
declare function createKeyedFlatMap<K extends string, V, const D extends object, O extends string, T>(source: KeyedProjection<K, V>, dependencies: D & KeyedDependencies<NoInfer<K>, NoInfer<V>, D>, select: (value: NoInfer<V>, key: NoInfer<K>, dependencies: KeyedDependencyValues<D>) => Synchronous<
|
|
59
|
+
declare function createKeyedFlatMap<K extends string, V, O extends string, T>(source: KeyedProjection<K, V>, select: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<KeyedEntries<O, T>>, equality?: Equality$1<T>): KeyedProjection<O, T>;
|
|
60
|
+
declare function createKeyedFlatMap<K extends string, V, const D extends object, O extends string, T>(source: KeyedProjection<K, V>, dependencies: D & KeyedDependencies<NoInfer<K>, NoInfer<V>, D>, select: (value: NoInfer<V>, key: NoInfer<K>, dependencies: KeyedDependencyValues<D>) => Synchronous<KeyedEntries<O, T>>, equality?: Equality$1<T>): KeyedProjection<O, T>;
|
|
54
61
|
//#endregion
|
|
55
62
|
//#region core/src/projection/derive.d.ts
|
|
56
|
-
type ProjectionDependencies = Readonly<Record<string, Projection<unknown>>>;
|
|
57
|
-
type ProjectionValues<D extends ProjectionDependencies> = { readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never };
|
|
58
63
|
type Equality<T> = (previous: T, next: T) => boolean;
|
|
59
64
|
declare function createValueDerive<const D extends ProjectionDependencies, T>(dependencies: D, compute: (values: ProjectionValues<D>) => Synchronous<T>, equality?: Equality<T>): Projection<T>;
|
|
60
65
|
declare const derive: typeof createValueDerive & {
|
|
@@ -67,6 +72,7 @@ declare const derive: typeof createValueDerive & {
|
|
|
67
72
|
entries: <K extends string, V>(source: KeyedProjection<K, V>) => Projection<readonly (readonly [K, V])[]>;
|
|
68
73
|
get: <K extends string, V>(source: KeyedProjection<K, V>, key: Projection<NoInfer<K> | undefined>, equality?: (previous: V | undefined, next: V | undefined) => boolean) => Projection<V | undefined>;
|
|
69
74
|
from: typeof createKeyedFrom;
|
|
75
|
+
fromEntries: typeof createKeyedFromEntries;
|
|
70
76
|
merge: typeof createKeyedMerge;
|
|
71
77
|
groupBy: {
|
|
72
78
|
<K extends string, V, G extends string>(source: KeyedProjection<K, V>, selector: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<G | readonly G[]>): KeyedProjection<G, readonly K[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,10 +29,18 @@ declare function observe<T>(readable: Readable<T>): Projection<T>;
|
|
|
29
29
|
declare function observe<S extends ObjectSchema<object>, P extends CollectionPath>(document: ReadonlyDocument<S>, selector: (path: SchemaPath<S>) => P): KeyedProjection<CollectionId<P>, ReadonlyValue<CollectionEntry<P>>>;
|
|
30
30
|
declare function observe<S extends ObjectSchema<object>, P>(document: ReadonlyDocument<S>, selector: (path: SchemaPath<S>) => P): Projection<PathValueOf<P>>;
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region core/src/projection/dependency.d.ts
|
|
33
|
+
type ProjectionDependencies = Readonly<Record<string, Projection<unknown>>> & Partial<Record<keyof Projection<unknown>, never>>;
|
|
34
|
+
type ProjectionValues<D extends ProjectionDependencies> = { readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never };
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region core/src/projection/keyed/entries.d.ts
|
|
37
|
+
type KeyedEntries<K extends string, V> = readonly (readonly [K, V])[];
|
|
38
|
+
//#endregion
|
|
32
39
|
//#region core/src/projection/keyed/composition.d.ts
|
|
33
40
|
type Equality$2<T> = (previous: T, next: T) => boolean;
|
|
34
41
|
declare function createKeyedFrom<K extends string, V>(source: Projection<readonly V[]>, keyOf: (value: NoInfer<V>) => Synchronous<K>, equality?: Equality$2<V>): KeyedProjection<K, V>;
|
|
35
42
|
declare function createKeyedFrom<K extends string, V>(source: readonly V[], keyOf: (value: NoInfer<V>) => Synchronous<K>, equality?: Equality$2<V>): KeyedProjection<K, V>;
|
|
43
|
+
declare function createKeyedFromEntries<const D extends ProjectionDependencies, K extends string, V>(dependencies: D, compute: (values: ProjectionValues<D>) => Synchronous<KeyedEntries<K, V>>, equality?: Equality$2<NoInfer<V>>): KeyedProjection<K, V>;
|
|
36
44
|
declare function createKeyedMerge<K extends string, V>(sources: readonly KeyedProjection<K, V>[], options: {
|
|
37
45
|
readonly conflict: 'error' | 'first' | 'last';
|
|
38
46
|
readonly equality?: Equality$2<V>;
|
|
@@ -47,14 +55,11 @@ declare function createKeyedMerge<K extends string, V>(sources: readonly KeyedPr
|
|
|
47
55
|
}): KeyedProjection<K, V>;
|
|
48
56
|
//#endregion
|
|
49
57
|
//#region core/src/projection/keyed/flat-map.d.ts
|
|
50
|
-
type Entries<K extends string, V> = readonly (readonly [K, V])[];
|
|
51
58
|
type Equality$1<V> = (previous: V, next: V) => boolean;
|
|
52
|
-
declare function createKeyedFlatMap<K extends string, V, O extends string, T>(source: KeyedProjection<K, V>, select: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<
|
|
53
|
-
declare function createKeyedFlatMap<K extends string, V, const D extends object, O extends string, T>(source: KeyedProjection<K, V>, dependencies: D & KeyedDependencies<NoInfer<K>, NoInfer<V>, D>, select: (value: NoInfer<V>, key: NoInfer<K>, dependencies: KeyedDependencyValues<D>) => Synchronous<
|
|
59
|
+
declare function createKeyedFlatMap<K extends string, V, O extends string, T>(source: KeyedProjection<K, V>, select: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<KeyedEntries<O, T>>, equality?: Equality$1<T>): KeyedProjection<O, T>;
|
|
60
|
+
declare function createKeyedFlatMap<K extends string, V, const D extends object, O extends string, T>(source: KeyedProjection<K, V>, dependencies: D & KeyedDependencies<NoInfer<K>, NoInfer<V>, D>, select: (value: NoInfer<V>, key: NoInfer<K>, dependencies: KeyedDependencyValues<D>) => Synchronous<KeyedEntries<O, T>>, equality?: Equality$1<T>): KeyedProjection<O, T>;
|
|
54
61
|
//#endregion
|
|
55
62
|
//#region core/src/projection/derive.d.ts
|
|
56
|
-
type ProjectionDependencies = Readonly<Record<string, Projection<unknown>>>;
|
|
57
|
-
type ProjectionValues<D extends ProjectionDependencies> = { readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never };
|
|
58
63
|
type Equality<T> = (previous: T, next: T) => boolean;
|
|
59
64
|
declare function createValueDerive<const D extends ProjectionDependencies, T>(dependencies: D, compute: (values: ProjectionValues<D>) => Synchronous<T>, equality?: Equality<T>): Projection<T>;
|
|
60
65
|
declare const derive: typeof createValueDerive & {
|
|
@@ -67,6 +72,7 @@ declare const derive: typeof createValueDerive & {
|
|
|
67
72
|
entries: <K extends string, V>(source: KeyedProjection<K, V>) => Projection<readonly (readonly [K, V])[]>;
|
|
68
73
|
get: <K extends string, V>(source: KeyedProjection<K, V>, key: Projection<NoInfer<K> | undefined>, equality?: (previous: V | undefined, next: V | undefined) => boolean) => Projection<V | undefined>;
|
|
69
74
|
from: typeof createKeyedFrom;
|
|
75
|
+
fromEntries: typeof createKeyedFromEntries;
|
|
70
76
|
merge: typeof createKeyedMerge;
|
|
71
77
|
groupBy: {
|
|
72
78
|
<K extends string, V, G extends string>(source: KeyedProjection<K, V>, selector: (value: NoInfer<V>, key: NoInfer<K>) => Synchronous<G | readonly G[]>): KeyedProjection<G, readonly K[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ownProjections, C as
|
|
1
|
+
import { A as ownProjections, C as snapshotProjectionValues, D as defineProcessor, E as snapshotCollectionView, M as projectionRef, N as profile, O as defineSource, S as compileProjectionDependencies, T as mapRead, _ as assertSynchronous, a as collectionChangeTouchesKey, b as ProjectionError, c as assertKeyedProjection, d as outputKind, f as createKeyRelation, g as assertScope, h as snapshotArray, i as collectionChangeIntersects, j as producerOf, k as isProjection, l as compileKeyedDependencies, m as sameArray, n as keyedAbsent, o as collectionHasStructuralChange, p as iterableMatchesArray, s as createCollectionChange, t as createKeyedTransform, u as createKeyedDependencyRuntime, v as createScheduler, w as collectionView, x as collectKeyedInvalidation, y as ProjectionDisposedError } from "./transform-3mj0eStL.js";
|
|
2
2
|
import { n as isPlainObject, r as isRecord, t as installOwn } from "./record-B2yRhYsc.js";
|
|
3
3
|
import { c as AddressIndex, d as invalidValue, f as children, g as validate, h as parent, i as contextOf, l as MutationRejected, m as is, o as decodeChanges, p as contains$1, r as bindContext, s as sealChanges, t as assertRuntimeWritable, u as fail } from "./driver-B7RR-VfX.js";
|
|
4
4
|
//#region core/src/schema/model.ts
|
|
@@ -2774,6 +2774,12 @@ const isExternalSource = (source) => {
|
|
|
2774
2774
|
return (candidate.kind === "value" || candidate.kind === "collection") && typeof candidate.current === "function" && typeof candidate.revision === "function" && typeof candidate.subscribe === "function";
|
|
2775
2775
|
};
|
|
2776
2776
|
//#endregion
|
|
2777
|
+
//#region core/src/projection/keyed/entries.ts
|
|
2778
|
+
/** Shared entry boundary; membership and duplicate policy belong to each operation. */
|
|
2779
|
+
function assertKeyedEntry(entry, name) {
|
|
2780
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string") throw new TypeError(`${name} entries must be [string key, value] tuples.`);
|
|
2781
|
+
}
|
|
2782
|
+
//#endregion
|
|
2777
2783
|
//#region core/src/projection/keyed/flat-map.ts
|
|
2778
2784
|
function createKeyedFlatMap(source, dependenciesOrSelect, selectOrEquality, maybeEquality) {
|
|
2779
2785
|
const name = "derive.keyed.flatMap";
|
|
@@ -2820,7 +2826,7 @@ function createKeyedFlatMap(source, dependenciesOrSelect, selectOrEquality, mayb
|
|
|
2820
2826
|
if (!Array.isArray(entries)) throw new TypeError(`${name} selector must return an array of entries.`);
|
|
2821
2827
|
const keys = [];
|
|
2822
2828
|
for (const entry of entries) {
|
|
2823
|
-
|
|
2829
|
+
assertKeyedEntry(entry, name);
|
|
2824
2830
|
const [key, child] = entry;
|
|
2825
2831
|
const owner = ownerByOutput.get(key);
|
|
2826
2832
|
if (proposals.has(key) || owner !== void 0 && !replaced.has(owner)) throw new TypeError(`${name} duplicate key ${JSON.stringify(key)}.`);
|
|
@@ -2907,6 +2913,25 @@ const assertCollectionSources = (sources, expected) => {
|
|
|
2907
2913
|
if (sources.length !== expected) throw new Error("derive.keyed.merge resolved an invalid dependency count.");
|
|
2908
2914
|
for (const source of sources) if (source.kind !== "collection") throw new Error("derive.keyed.merge requires collection inputs.");
|
|
2909
2915
|
};
|
|
2916
|
+
/** Complete ordered result reconciliation, without retaining a second member/value cache. */
|
|
2917
|
+
const stageKeyedSnapshot = (values, output, keyOf, valueOf, name) => {
|
|
2918
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2919
|
+
const order = new Array(values.length);
|
|
2920
|
+
const previous = output.previous.ids();
|
|
2921
|
+
profile.collectionView.idsScanned(values.length + previous.length);
|
|
2922
|
+
for (let index = 0; index < values.length; index++) {
|
|
2923
|
+
const value = values[index];
|
|
2924
|
+
const key = keyOf(value);
|
|
2925
|
+
assertSynchronous(key);
|
|
2926
|
+
if (typeof key !== "string") throw new TypeError(`${name} key selector must return a string.`);
|
|
2927
|
+
if (seen.has(key)) throw new TypeError(`${name} duplicate key ${JSON.stringify(key)}.`);
|
|
2928
|
+
seen.add(key);
|
|
2929
|
+
order[index] = key;
|
|
2930
|
+
output.output.set(key, valueOf(value));
|
|
2931
|
+
}
|
|
2932
|
+
for (const key of previous) if (!seen.has(key)) output.output.remove(key);
|
|
2933
|
+
output.output.order(order);
|
|
2934
|
+
};
|
|
2910
2935
|
function createKeyedFrom(source, keyOf, equality) {
|
|
2911
2936
|
if (typeof keyOf !== "function") throw new TypeError("derive.keyed.from requires a key selector.");
|
|
2912
2937
|
const outputEquality = assertEquality(equality, "derive.keyed.from");
|
|
@@ -2936,25 +2961,38 @@ function createKeyedFrom(source, keyOf, equality) {
|
|
|
2936
2961
|
values = scalar.value;
|
|
2937
2962
|
}
|
|
2938
2963
|
if (!values) throw new Error("derive.keyed.from has no source values.");
|
|
2939
|
-
|
|
2940
|
-
const order = new Array(values.length);
|
|
2941
|
-
for (let index = 0; index < values.length; index++) {
|
|
2942
|
-
const value = values[index];
|
|
2943
|
-
const key = keyOf(value);
|
|
2944
|
-
assertSynchronous(key);
|
|
2945
|
-
if (typeof key !== "string") throw new TypeError("derive.keyed.from key selector must return a string.");
|
|
2946
|
-
if (seen.has(key)) throw new TypeError(`derive.keyed.from duplicate key ${JSON.stringify(key)}.`);
|
|
2947
|
-
seen.add(key);
|
|
2948
|
-
order[index] = key;
|
|
2949
|
-
output.output.set(key, value);
|
|
2950
|
-
}
|
|
2951
|
-
for (const previousKey of output.previous.ids()) if (!seen.has(previousKey)) output.output.remove(previousKey);
|
|
2952
|
-
output.output.order(order);
|
|
2964
|
+
stageKeyedSnapshot(values, output, keyOf, (value) => value, "derive.keyed.from");
|
|
2953
2965
|
} }),
|
|
2954
2966
|
name: "derive.keyed.from"
|
|
2955
2967
|
});
|
|
2956
2968
|
return projection;
|
|
2957
2969
|
}
|
|
2970
|
+
function createKeyedFromEntries(dependencies, compute, equality) {
|
|
2971
|
+
const name = "derive.keyed.fromEntries";
|
|
2972
|
+
const compiled = compileProjectionDependencies(dependencies, name);
|
|
2973
|
+
if (typeof compute !== "function") throw new TypeError(`${name} requires a compute callback.`);
|
|
2974
|
+
const outputEquality = assertEquality(equality, name);
|
|
2975
|
+
const [projection] = defineProcessor({
|
|
2976
|
+
dependencies: compiled.projections,
|
|
2977
|
+
outputs: [{
|
|
2978
|
+
kind: "collection",
|
|
2979
|
+
equality: outputEquality
|
|
2980
|
+
}],
|
|
2981
|
+
name,
|
|
2982
|
+
create: () => ({ evaluate: (evaluation) => {
|
|
2983
|
+
const output = evaluation.outputs[0];
|
|
2984
|
+
if (output.kind !== "collection") throw new Error(`${name} requires a collection output.`);
|
|
2985
|
+
const entries = compute(snapshotProjectionValues(compiled.names, evaluation.sources));
|
|
2986
|
+
assertSynchronous(entries);
|
|
2987
|
+
if (!Array.isArray(entries)) throw new TypeError(`${name} compute must return an array of entries.`);
|
|
2988
|
+
stageKeyedSnapshot(entries, output, (entry) => {
|
|
2989
|
+
assertKeyedEntry(entry, name);
|
|
2990
|
+
return entry[0];
|
|
2991
|
+
}, (entry) => entry[1], name);
|
|
2992
|
+
} })
|
|
2993
|
+
});
|
|
2994
|
+
return projection;
|
|
2995
|
+
}
|
|
2958
2996
|
function createKeyedMerge(sources, options) {
|
|
2959
2997
|
if (!Array.isArray(sources)) throw new TypeError("derive.keyed.merge sources must be an array of keyed projections.");
|
|
2960
2998
|
const capturedSources = snapshotArray(sources);
|
|
@@ -3583,6 +3621,7 @@ const keyedDerive = Object.assign(createKeyedDerive, {
|
|
|
3583
3621
|
entries: createKeyedEntries,
|
|
3584
3622
|
get: createKeyedGet,
|
|
3585
3623
|
from: createKeyedFrom,
|
|
3624
|
+
fromEntries: createKeyedFromEntries,
|
|
3586
3625
|
merge: createKeyedMerge,
|
|
3587
3626
|
groupBy: createKeyedGroupBy,
|
|
3588
3627
|
flatMap: createKeyedFlatMap,
|
|
@@ -3606,9 +3645,7 @@ function createValueDerive(dependencies, compute, equality = Object.is) {
|
|
|
3606
3645
|
create: () => ({ evaluate: (evaluation) => {
|
|
3607
3646
|
const output = evaluation.outputs[0];
|
|
3608
3647
|
if (output.kind !== "value") throw new Error("derive requires a value output.");
|
|
3609
|
-
const
|
|
3610
|
-
for (let index = 0; index < names.length; index++) values[names[index]] = snapshotDependencyValue(evaluation.sources[index]);
|
|
3611
|
-
const next = compute(Object.freeze(values));
|
|
3648
|
+
const next = compute(snapshotProjectionValues(names, evaluation.sources));
|
|
3612
3649
|
assertSynchronous(next);
|
|
3613
3650
|
output.output.set(next);
|
|
3614
3651
|
} })
|