@noy-db/hub 0.7.0-pre.11 → 0.7.0-pre.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.
- package/CHANGELOG.md +142 -0
- package/dist/as/index.js +3 -2
- package/dist/as/index.js.map +1 -1
- package/dist/{backup-VASRVLDZ.js → backup-R6A4VZRX.js} +4 -4
- package/dist/cargo/index.js +2 -2
- package/dist/chunk-66TQOPFM.js +37 -0
- package/dist/chunk-66TQOPFM.js.map +1 -0
- package/dist/{chunk-OEA5NVSU.js → chunk-AJQY44CE.js} +86 -6
- package/dist/chunk-AJQY44CE.js.map +1 -0
- package/dist/{chunk-S5AMPTNE.js → chunk-BMELYFHU.js} +2 -2
- package/dist/{chunk-T6PSWLAR.js → chunk-BUE2D7PX.js} +25 -2
- package/dist/chunk-BUE2D7PX.js.map +1 -0
- package/dist/chunk-BWXGSSFX.js +1589 -0
- package/dist/chunk-BWXGSSFX.js.map +1 -0
- package/dist/{chunk-HN4FNA4X.js → chunk-COTPDJR5.js} +8 -8
- package/dist/{chunk-E3EBMC4G.js → chunk-E2MYJGSG.js} +2 -2
- package/dist/{chunk-JJR2JIN4.js → chunk-FFBYRWDJ.js} +2 -2
- package/dist/{chunk-WQF3QABE.js → chunk-IHFXR2VQ.js} +9 -79
- package/dist/chunk-IHFXR2VQ.js.map +1 -0
- package/dist/chunk-MGOXJIBV.js +176 -0
- package/dist/chunk-MGOXJIBV.js.map +1 -0
- package/dist/chunk-PDD75NUZ.js +87 -0
- package/dist/chunk-PDD75NUZ.js.map +1 -0
- package/dist/chunk-RTBJ5IOO.js +87 -0
- package/dist/chunk-RTBJ5IOO.js.map +1 -0
- package/dist/chunk-RXLYKVTF.js +17 -0
- package/dist/chunk-RXLYKVTF.js.map +1 -0
- package/dist/{chunk-ESVREVWN.js → chunk-SXCYYMVS.js} +2 -2
- package/dist/chunk-TFMM5DBB.js +20 -0
- package/dist/chunk-TFMM5DBB.js.map +1 -0
- package/dist/chunk-TPHAGLUH.js +30 -0
- package/dist/chunk-TPHAGLUH.js.map +1 -0
- package/dist/{chunk-THNJ3IKU.js → chunk-ULUMAZ5S.js} +2 -2
- package/dist/{chunk-NO272T7Q.js → chunk-V4PXLYWM.js} +2 -31
- package/dist/chunk-V4PXLYWM.js.map +1 -0
- package/dist/{chunk-A5WZEPXJ.js → chunk-VGICZPVE.js} +5 -3
- package/dist/{chunk-A5WZEPXJ.js.map → chunk-VGICZPVE.js.map} +1 -1
- package/dist/{chunk-KHKKD62N.js → chunk-VYYM3MEN.js} +2 -16
- package/dist/chunk-VYYM3MEN.js.map +1 -0
- package/dist/{chunk-SWVNZQVR.js → chunk-YPXNAP72.js} +2 -169
- package/dist/chunk-YPXNAP72.js.map +1 -0
- package/dist/{chunk-I6DGKPTY.js → chunk-ZVCC36XQ.js} +101 -1273
- package/dist/chunk-ZVCC36XQ.js.map +1 -0
- package/dist/{collection-facade-MGGHQ3HU.js → collection-facade-4ACKIDDY.js} +4 -3
- package/dist/derivations/index.js +21 -6
- package/dist/dispatch-MSTR5VBI.js +255 -0
- package/dist/dispatch-MSTR5VBI.js.map +1 -0
- package/dist/{dispatch-44J4TL72.js → dispatch-PDP5TA73.js} +5 -5
- package/dist/{executor-KSPGNVDO.js → executor-YDDC5XGY.js} +4 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -35
- package/dist/index.js.map +1 -1
- package/dist/introspection/index.js +3 -2
- package/dist/kernel/collection.d.ts +11 -6
- package/dist/kernel/match-pairs.d.ts +30 -0
- package/dist/lazy/index.js +3 -2
- package/dist/materialized-views/index.js +4 -3
- package/dist/{noydb-QJFZAH34.js → noydb-2C6QQJ5S.js} +17 -12
- package/dist/pod/index.js +17 -12
- package/dist/registry-D2YXKRYC.js +33 -0
- package/dist/search/index.js +1 -1
- package/dist/{stale-KSPG6LFX.js → stale-2CHKZTMK.js} +2 -2
- package/dist/{walk-G3CZIL4L.js → walk-P3E6QSNC.js} +4 -3
- package/dist/with-formula/derivations/dispatch.d.ts +16 -1
- package/dist/with-formula/derivations/registry.d.ts +20 -6
- package/dist/with-formula/derivations/trigger-match.d.ts +52 -0
- package/dist/with-formula/derivations/types.d.ts +23 -0
- package/dist/with-shape/introspection/behaviors.d.ts +7 -0
- package/dist/with-shape/introspection/describe.d.ts +30 -0
- package/package.json +3 -3
- package/dist/chunk-I6DGKPTY.js.map +0 -1
- package/dist/chunk-KHKKD62N.js.map +0 -1
- package/dist/chunk-NO272T7Q.js.map +0 -1
- package/dist/chunk-OEA5NVSU.js.map +0 -1
- package/dist/chunk-SWVNZQVR.js.map +0 -1
- package/dist/chunk-T6PSWLAR.js.map +0 -1
- package/dist/chunk-UB5CRTFF.js +0 -344
- package/dist/chunk-UB5CRTFF.js.map +0 -1
- package/dist/chunk-WQF3QABE.js.map +0 -1
- package/dist/chunk-YPMW26SL.js +0 -81
- package/dist/chunk-YPMW26SL.js.map +0 -1
- package/dist/dispatch-IM52HDXT.js +0 -194
- package/dist/dispatch-IM52HDXT.js.map +0 -1
- package/dist/registry-FZXPQRAB.js +0 -18
- /package/dist/{backup-VASRVLDZ.js.map → backup-R6A4VZRX.js.map} +0 -0
- /package/dist/{chunk-S5AMPTNE.js.map → chunk-BMELYFHU.js.map} +0 -0
- /package/dist/{chunk-HN4FNA4X.js.map → chunk-COTPDJR5.js.map} +0 -0
- /package/dist/{chunk-E3EBMC4G.js.map → chunk-E2MYJGSG.js.map} +0 -0
- /package/dist/{chunk-JJR2JIN4.js.map → chunk-FFBYRWDJ.js.map} +0 -0
- /package/dist/{chunk-ESVREVWN.js.map → chunk-SXCYYMVS.js.map} +0 -0
- /package/dist/{chunk-THNJ3IKU.js.map → chunk-ULUMAZ5S.js.map} +0 -0
- /package/dist/{collection-facade-MGGHQ3HU.js.map → collection-facade-4ACKIDDY.js.map} +0 -0
- /package/dist/{dispatch-44J4TL72.js.map → dispatch-PDP5TA73.js.map} +0 -0
- /package/dist/{executor-KSPGNVDO.js.map → executor-YDDC5XGY.js.map} +0 -0
- /package/dist/{noydb-QJFZAH34.js.map → noydb-2C6QQJ5S.js.map} +0 -0
- /package/dist/{registry-FZXPQRAB.js.map → registry-D2YXKRYC.js.map} +0 -0
- /package/dist/{stale-KSPG6LFX.js.map → stale-2CHKZTMK.js.map} +0 -0
- /package/dist/{walk-G3CZIL4L.js.map → walk-P3E6QSNC.js.map} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAtPath
|
|
3
|
+
} from "./chunk-TRGTKX5E.js";
|
|
4
|
+
import {
|
|
5
|
+
EmbeddingModelMismatchError
|
|
6
|
+
} from "./chunk-7O3Y4PPD.js";
|
|
7
|
+
|
|
8
|
+
// src/with-lookup/embeddings/descriptor.ts
|
|
9
|
+
function embeddingSourceText(record, source) {
|
|
10
|
+
const fields = typeof source === "string" ? [source] : source;
|
|
11
|
+
const parts = [];
|
|
12
|
+
for (const f of fields) {
|
|
13
|
+
for (const leaf of getAtPath(record, f)) {
|
|
14
|
+
if (typeof leaf === "string" && leaf !== "") parts.push(leaf);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return parts.join(" ");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/with-lookup/embeddings/vec-id.ts
|
|
21
|
+
function encodeVecId(collection, recordId) {
|
|
22
|
+
if (collection.includes("/")) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`encodeVecId: collection name "${collection}" must not contain "/" \u2014 it would make the "${collection}/${recordId}" _vec id ambiguous against another collection's rows.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return `${collection}/${recordId}`;
|
|
28
|
+
}
|
|
29
|
+
function decodeVecId(collection, vecId) {
|
|
30
|
+
const prefix = `${collection}/`;
|
|
31
|
+
if (!vecId.startsWith(prefix)) return null;
|
|
32
|
+
return vecId.slice(prefix.length);
|
|
33
|
+
}
|
|
34
|
+
function isVecIdFor(collection, vecId) {
|
|
35
|
+
return vecId.startsWith(`${collection}/`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/with-lookup/embeddings/cosine.ts
|
|
39
|
+
function cosine(a, b) {
|
|
40
|
+
if (a.length !== b.length) return 0;
|
|
41
|
+
let dot = 0, na = 0, nb = 0;
|
|
42
|
+
for (let i = 0; i < a.length; i++) {
|
|
43
|
+
const x = a[i], y = b[i];
|
|
44
|
+
dot += x * y;
|
|
45
|
+
na += x * x;
|
|
46
|
+
nb += y * y;
|
|
47
|
+
}
|
|
48
|
+
if (na === 0 || nb === 0) return 0;
|
|
49
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/with-lookup/embeddings/vector-set.ts
|
|
53
|
+
var VectorSet = class {
|
|
54
|
+
vectors;
|
|
55
|
+
get loaded() {
|
|
56
|
+
return this.vectors !== void 0;
|
|
57
|
+
}
|
|
58
|
+
async ensureLoaded(load) {
|
|
59
|
+
if (this.vectors === void 0) this.vectors = await load();
|
|
60
|
+
}
|
|
61
|
+
markDirty() {
|
|
62
|
+
this.vectors = void 0;
|
|
63
|
+
}
|
|
64
|
+
cosineTopK(query, k, opts = {}) {
|
|
65
|
+
const all = this.vectors ?? [];
|
|
66
|
+
const minScore = opts.minScore ?? -Infinity;
|
|
67
|
+
const hits = [];
|
|
68
|
+
for (const v of all) {
|
|
69
|
+
if (opts.expectModel !== void 0 && v.model !== opts.expectModel) {
|
|
70
|
+
throw new EmbeddingModelMismatchError(opts.expectModel, v.model);
|
|
71
|
+
}
|
|
72
|
+
const score = cosine(query, v.vec);
|
|
73
|
+
if (score >= minScore) hits.push({ id: v.id, score });
|
|
74
|
+
}
|
|
75
|
+
hits.sort((a, b) => b.score - a.score);
|
|
76
|
+
return hits.slice(0, k);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
embeddingSourceText,
|
|
82
|
+
VectorSet,
|
|
83
|
+
encodeVecId,
|
|
84
|
+
decodeVecId,
|
|
85
|
+
isVecIdFor
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=chunk-RTBJ5IOO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/with-lookup/embeddings/descriptor.ts","../src/with-lookup/embeddings/vec-id.ts","../src/with-lookup/embeddings/cosine.ts","../src/with-lookup/embeddings/vector-set.ts"],"sourcesContent":["/** Per-collection embedding config (L2). The encode hook is host/remote — no bundled model. */\nimport { getAtPath } from '../../via/i18n/core.js'\n\nexport interface EmbeddingDescriptor {\n readonly source: string | readonly string[]\n readonly encode: (text: string) => Promise<Float32Array>\n readonly dim: number\n readonly model: string\n}\n\n/** Concatenate the record's source-field text (skips empties; supports nested/[]-wildcard paths). */\nexport function embeddingSourceText(record: Record<string, unknown>, source: string | readonly string[]): string {\n const fields = typeof source === 'string' ? [source] : source\n const parts: string[] = []\n for (const f of fields) {\n for (const leaf of getAtPath(record, f)) {\n if (typeof leaf === 'string' && leaf !== '') parts.push(leaf)\n }\n }\n return parts.join(' ')\n}\n","/**\n * Collection-namespaced `_vec` side-car ids (#726).\n *\n * `_vec` embedding side-cars used to be keyed by the bare record id,\n * vault-wide — two collections sharing a record id shared one `_vec` row.\n * This was verified to be a clobber/crash bug, NOT a confidentiality leak:\n * every collection has its own DEK, and AES-GCM auth-tag verification means\n * decrypting a foreign collection's `_vec` row under the wrong DEK throws\n * `TamperedError` rather than returning wrong plaintext — no disclosure\n * mechanism exists. The real bug was id collision: a same-id write/forget in\n * one collection could clobber or delete the other collection's row, and a\n * collection whose `similarTo()` / cold semantic `retrieve()` encountered a\n * foreign same-id row crashed with an uncaught `TamperedError` (a DoS). The\n * store-collection bucket stays the literal `'_vec'`; the id becomes\n * composite: `${collection}/${recordId}`. Mirrors `encodeIdxId`\n * (`../indexing/persisted-indexes.js`).\n *\n * Decode is deliberately NOT split-on-`/`: the collection is always known\n * at the decode site (`ctx.name`), so `decodeVecId` strips that known\n * prefix — correct even when `recordId` itself contains `/`.\n *\n * Precondition: `collection` itself must not contain `/` — otherwise\n * `${collection}/${recordId}` is ambiguous (e.g. collection `'a'` would\n * misattribute collection `'a/b'`'s rows via prefix match in `isVecIdFor`).\n * Collection names are NOT currently restricted to a `/`-free charset by\n * `vault.collection()`, so `encodeVecId` enforces the precondition itself,\n * failing loud at the write boundary rather than silently misencoding.\n */\n\n/**\n * Encode the `_vec` side-car id for a (collection, recordId) pair.\n * Format: `<collection>/<recordId>` — no escaping; `recordId` may contain `/`.\n *\n * Throws if `collection` contains `/`: that would make the composite id\n * ambiguous against `isVecIdFor`'s prefix match (collection `'a'` would\n * appear to own collection `'a/b'`'s rows), reintroducing the clobber/crash\n * risk the namespacing fix exists to close.\n */\nexport function encodeVecId(collection: string, recordId: string): string {\n if (collection.includes('/')) {\n throw new Error(\n `encodeVecId: collection name \"${collection}\" must not contain \"/\" — ` +\n `it would make the \"${collection}/${recordId}\" _vec id ambiguous against another collection's rows.`,\n )\n }\n return `${collection}/${recordId}`\n}\n\n/**\n * Decode a `_vec` id back to the bare record id, given the KNOWN owning\n * collection — strips the `<collection>/` prefix rather than splitting on\n * `/`, so a `recordId` containing `/` round-trips correctly. Returns `null`\n * if `vecId` does not belong to `collection`.\n */\nexport function decodeVecId(collection: string, vecId: string): string | null {\n const prefix = `${collection}/`\n if (!vecId.startsWith(prefix)) return null\n return vecId.slice(prefix.length)\n}\n\n/** Predicate form of {@link decodeVecId} — used to filter `list()` results. */\nexport function isVecIdFor(collection: string, vecId: string): boolean {\n return vecId.startsWith(`${collection}/`)\n}\n","/** Cosine similarity in [-1,1]; 0 on zero-norm or length mismatch (no NaN). (L2) */\nexport function cosine(a: Float32Array | number[], b: Float32Array | number[]): number {\n if (a.length !== b.length) return 0\n let dot = 0, na = 0, nb = 0\n for (let i = 0; i < a.length; i++) {\n const x = a[i]!, y = b[i]!\n dot += x * y; na += x * x; nb += y * y\n }\n if (na === 0 || nb === 0) return 0\n return dot / (Math.sqrt(na) * Math.sqrt(nb))\n}\n","/** In-memory vector set for L2 semantic retrieval. Loaded once per session from\n * decrypted _vec sidecars (injected loader), brute-force cosine kNN, model-guarded. */\nimport { cosine } from './cosine.js'\nimport { EmbeddingModelMismatchError } from '../../kernel/errors.js'\n\nexport interface StoredVector { readonly id: string; readonly vec: Float32Array; readonly model: string }\nexport interface VectorHit { readonly id: string; readonly score: number }\n\nexport class VectorSet {\n private vectors: StoredVector[] | undefined\n get loaded(): boolean { return this.vectors !== undefined }\n\n async ensureLoaded(load: () => Promise<StoredVector[]>): Promise<void> {\n if (this.vectors === undefined) this.vectors = await load()\n }\n\n markDirty(): void { this.vectors = undefined }\n\n cosineTopK(query: Float32Array, k: number, opts: { minScore?: number; expectModel?: string } = {}): VectorHit[] {\n const all = this.vectors ?? []\n const minScore = opts.minScore ?? -Infinity\n const hits: VectorHit[] = []\n for (const v of all) {\n if (opts.expectModel !== undefined && v.model !== opts.expectModel) {\n throw new EmbeddingModelMismatchError(opts.expectModel, v.model)\n }\n const score = cosine(query, v.vec)\n if (score >= minScore) hits.push({ id: v.id, score })\n }\n hits.sort((a, b) => b.score - a.score)\n return hits.slice(0, k)\n }\n}\n"],"mappings":";;;;;;;;AAWO,SAAS,oBAAoB,QAAiC,QAA4C;AAC/G,QAAM,SAAS,OAAO,WAAW,WAAW,CAAC,MAAM,IAAI;AACvD,QAAM,QAAkB,CAAC;AACzB,aAAW,KAAK,QAAQ;AACtB,eAAW,QAAQ,UAAU,QAAQ,CAAC,GAAG;AACvC,UAAI,OAAO,SAAS,YAAY,SAAS,GAAI,OAAM,KAAK,IAAI;AAAA,IAC9D;AAAA,EACF;AACA,SAAO,MAAM,KAAK,GAAG;AACvB;;;ACkBO,SAAS,YAAY,YAAoB,UAA0B;AACxE,MAAI,WAAW,SAAS,GAAG,GAAG;AAC5B,UAAM,IAAI;AAAA,MACR,iCAAiC,UAAU,oDACnB,UAAU,IAAI,QAAQ;AAAA,IAChD;AAAA,EACF;AACA,SAAO,GAAG,UAAU,IA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AG;AACjC,UAAI,SAAS,SAAU,MAAK,KAAK,EAAE,IAAI,EAAE,IAAI,MAAM,CAAC;AAAA,IACtD;AACA,SAAK,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACrC,WAAO,KAAK,MAAM,GAAG,CAAC;AAAA,EACxB;AACF;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/with-shape/introspection/derivation-key.ts
|
|
2
|
+
function fallbackDerivationName(outputCollections, source, used) {
|
|
3
|
+
const base = outputCollections.length > 0 ? [...outputCollections].sort().join("+") : source;
|
|
4
|
+
if (!used.has(base)) return base;
|
|
5
|
+
let occurrence = 1;
|
|
6
|
+
let candidate = `${base}#${occurrence}`;
|
|
7
|
+
while (used.has(candidate)) {
|
|
8
|
+
occurrence++;
|
|
9
|
+
candidate = `${base}#${occurrence}`;
|
|
10
|
+
}
|
|
11
|
+
return candidate;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
fallbackDerivationName
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=chunk-RXLYKVTF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/with-shape/introspection/derivation-key.ts"],"sourcesContent":["/**\n * The deterministic fallback key for an UNNAMED derivation, shared by\n * `dumpSchema`'s `describeDerivations` (walk.ts) and `listBehaviors`'s\n * `buildDerivationEntries` (behaviors.ts) so the two surfaces always key the\n * same unnamed derivation identically.\n *\n * Base key = the derivation's output-collection names, sorted and joined by\n * `+` (or `source` when it has no outputs). On collision with any key already\n * assigned in this enumeration (named or fallback, passed in `used`), a\n * deterministic `#occurrence` suffix is appended (`base`, `base#1`, `base#2`, …)\n * so two derivations with the same output set both appear.\n *\n * Takes the already-extracted output-collection list + source (rather than a\n * `DerivationSpec`) so both the typed builder and walk.ts's duck-typed registry\n * walk can call it without a shared concrete type.\n */\nexport function fallbackDerivationName(\n outputCollections: readonly string[],\n source: string,\n used: ReadonlySet<string>,\n): string {\n const base = outputCollections.length > 0 ? [...outputCollections].sort().join('+') : source\n if (!used.has(base)) return base\n let occurrence = 1\n let candidate = `${base}#${occurrence}`\n while (used.has(candidate)) {\n occurrence++\n candidate = `${base}#${occurrence}`\n }\n return candidate\n}\n"],"mappings":";AAgBO,SAAS,uBACd,mBACA,QACA,MACQ;AACR,QAAM,OAAO,kBAAkB,SAAS,IAAI,CAAC,GAAG,iBAAiB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;AACtF,MAAI,CAAC,KAAK,IAAI,IAAI,EAAG,QAAO;AAC5B,MAAI,aAAa;AACjB,MAAI,YAAY,GAAG,IAAI,IAAI,UAAU;AACrC,SAAO,KAAK,IAAI,SAAS,GAAG;AAC1B;AACA,gBAAY,GAAG,IAAI,IAAI,UAAU;AAAA,EACnC;AACA,SAAO;AACT;","names":[]}
|
|
@@ -252,7 +252,7 @@ async function createOwnerOnAdoptedPartition(store, vaultName, opts) {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
if (isManaged(opts)) {
|
|
255
|
-
const { createNoydb } = await import("./noydb-
|
|
255
|
+
const { createNoydb } = await import("./noydb-2C6QQJ5S.js");
|
|
256
256
|
const db = await createNoydb({
|
|
257
257
|
store,
|
|
258
258
|
user: userId,
|
|
@@ -307,4 +307,4 @@ export {
|
|
|
307
307
|
withCargo,
|
|
308
308
|
describeExtraction
|
|
309
309
|
};
|
|
310
|
-
//# sourceMappingURL=chunk-
|
|
310
|
+
//# sourceMappingURL=chunk-SXCYYMVS.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/kernel/match-pairs.ts
|
|
2
|
+
var scalar = (v) => typeof v === "string" || typeof v === "number" ? String(v) : null;
|
|
3
|
+
function recordMatchesPairs(rec, pairs) {
|
|
4
|
+
return pairs.every((p) => scalar(rec[p.field]) === p.value);
|
|
5
|
+
}
|
|
6
|
+
async function findMatchingIdsByPairs(residualPairs, io) {
|
|
7
|
+
if (io.indexCandidates !== null && residualPairs.length === 0) return [...io.indexCandidates];
|
|
8
|
+
const ids = io.indexCandidates ?? await io.listIds();
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const id of ids) {
|
|
11
|
+
const rec = await io.getRecord(id);
|
|
12
|
+
if (rec !== null && recordMatchesPairs(rec, residualPairs)) out.push(id);
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
findMatchingIdsByPairs
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-TFMM5DBB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kernel/match-pairs.ts"],"sourcesContent":["/**\n * Kernel-side matching primitives for composite `triggerBy` fan-out (#1249).\n *\n * Lives in the kernel (not `with-formula/derivations/`) so `collection.ts` can\n * import it statically without dragging derivations code into the floor\n * bundle — the module used to be dynamically imported from `collection.ts`\n * while also being statically imported by `registry.ts`/`dispatch.ts`,\n * which merged it into a chunk that `dist/index.js` ended up pulling in\n * statically.\n * @module\n */\n\nconst scalar = (v: unknown): string | null =>\n (typeof v === 'string' || typeof v === 'number') ? String(v) : null\n\n/** Conjunction over one candidate record, same coercion as tupleFromWritten. */\nexport function recordMatchesPairs(\n rec: Record<string, unknown>,\n pairs: ReadonlyArray<{ field: string; value: string }>,\n): boolean {\n return pairs.every((p) => scalar(rec[p.field]) === p.value)\n}\n\n/** Scan/filter core for composite fan-out. `residualPairs` are the pairs NOT\n * already decided by `indexCandidates` (the id set from an equality index for\n * ONE pair, or null when no pair is indexed). When the index alone decides\n * membership (`indexCandidates` non-null and no residual pairs left), this\n * returns the index's answer verbatim with ZERO record reads — matching the\n * old single-field `_findMatchingIds`' `[...hit]` fast path exactly. */\nexport async function findMatchingIdsByPairs(\n residualPairs: ReadonlyArray<{ field: string; value: string }>,\n io: {\n indexCandidates: ReadonlyArray<string> | null\n listIds: () => Promise<ReadonlyArray<string>>\n getRecord: (id: string) => Promise<Record<string, unknown> | null>\n },\n): Promise<string[]> {\n if (io.indexCandidates !== null && residualPairs.length === 0) return [...io.indexCandidates]\n const ids = io.indexCandidates ?? await io.listIds()\n const out: string[] = []\n for (const id of ids) {\n const rec = await io.getRecord(id)\n if (rec !== null && recordMatchesPairs(rec, residualPairs)) out.push(id)\n }\n return out\n}\n"],"mappings":";AAYA,IAAM,SAAS,CAAC,MACb,OAAO,MAAM,YAAY,OAAO,MAAM,WAAY,OAAO,CAAC,IAAI;AAG1D,SAAS,mBACd,KACA,OACS;AACT,SAAO,MAAM,MAAM,CAAC,MAAM,OAAO,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK;AAC5D;AAQA,eAAsB,uBACpB,eACA,IAKmB;AACnB,MAAI,GAAG,oBAAoB,QAAQ,cAAc,WAAW,EAAG,QAAO,CAAC,GAAG,GAAG,eAAe;AAC5F,QAAM,MAAM,GAAG,mBAAmB,MAAM,GAAG,QAAQ;AACnD,QAAM,MAAgB,CAAC;AACvB,aAAW,MAAM,KAAK;AACpB,UAAM,MAAM,MAAM,GAAG,UAAU,EAAE;AACjC,QAAI,QAAQ,QAAQ,mBAAmB,KAAK,aAAa,EAAG,KAAI,KAAK,EAAE;AAAA,EACzE;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/with-formula/derivations/trigger-match.ts
|
|
2
|
+
function normalizeTriggerBy(triggerBy) {
|
|
3
|
+
if (triggerBy === void 0) return [];
|
|
4
|
+
return triggerBy.map((t) => ({
|
|
5
|
+
collection: t.collection,
|
|
6
|
+
match: t.match ?? [{ from: "id", to: t.on }],
|
|
7
|
+
...t.maxFanout !== void 0 ? { maxFanout: t.maxFanout } : {}
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
var scalar = (v) => typeof v === "string" || typeof v === "number" ? String(v) : null;
|
|
11
|
+
function tupleFromWritten(match, writtenId, record) {
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const pair of match) {
|
|
14
|
+
const v = pair.from === "id" ? writtenId : scalar(record?.[pair.from]);
|
|
15
|
+
if (v === null) return null;
|
|
16
|
+
out.push({ field: pair.to, value: v });
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function sameTuple(a, b) {
|
|
21
|
+
if (a === null || b === null) return a === b;
|
|
22
|
+
return a.length === b.length && a.every((p, i) => p.field === b[i].field && p.value === b[i].value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
normalizeTriggerBy,
|
|
27
|
+
tupleFromWritten,
|
|
28
|
+
sameTuple
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-TPHAGLUH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/with-formula/derivations/trigger-match.ts"],"sourcesContent":["/**\n * Pure helpers behind composite `triggerBy` (#1249).\n *\n * A trigger entry is a CONJUNCTION of equality pairs: a source record\n * matches when EVERY pair satisfies String(source[to]) === String(written[from]).\n * `from: 'id'` reads the written record's id (winning over any stored field\n * named `id`, matching dispatch's `{ ...incoming, id }` convention). The\n * legacy `on` form normalizes to `[{ from: 'id', to: on }]` so everything\n * downstream has ONE shape.\n *\n * Scalar coercion is verbatim from `_findMatchingIds`: both sides must be\n * string | number; anything else fails the pair (never throws).\n * Spec: docs/superpowers/specs/2026-08-29-composite-triggerby-design.md §4-§5.\n * @module\n */\n\nexport interface MatchPair { readonly from: string; readonly to: string }\n\nexport interface NormalizedTrigger {\n readonly collection: string\n readonly match: ReadonlyArray<MatchPair>\n readonly maxFanout?: number\n}\n\ninterface RawTrigger {\n readonly collection: string\n readonly on?: string\n readonly match?: ReadonlyArray<MatchPair>\n readonly maxFanout?: number\n}\n\nexport function normalizeTriggerBy(triggerBy: ReadonlyArray<RawTrigger> | undefined): NormalizedTrigger[] {\n if (triggerBy === undefined) return []\n return triggerBy.map((t) => ({\n collection: t.collection,\n match: t.match ?? [{ from: 'id', to: t.on! }],\n ...(t.maxFanout !== undefined ? { maxFanout: t.maxFanout } : {}),\n }))\n}\n\nconst scalar = (v: unknown): string | null =>\n (typeof v === 'string' || typeof v === 'number') ? String(v) : null\n\n/**\n * The value tuple a written record presents to one trigger entry.\n * `null` means \"this record cannot address any source\" (a from-field is\n * absent or non-scalar) — a legitimate no-match, not an error.\n */\nexport function tupleFromWritten(\n match: ReadonlyArray<MatchPair>,\n writtenId: string,\n record: Record<string, unknown> | null,\n): Array<{ field: string; value: string }> | null {\n const out: Array<{ field: string; value: string }> = []\n for (const pair of match) {\n const v = pair.from === 'id' ? writtenId : scalar(record?.[pair.from])\n if (v === null) return null\n out.push({ field: pair.to, value: v })\n }\n return out\n}\n\n/** Any single component differing means NOT the same tuple (spec §7). */\nexport function sameTuple(\n a: Array<{ field: string; value: string }> | null,\n b: Array<{ field: string; value: string }> | null,\n): boolean {\n if (a === null || b === null) return a === b\n return a.length === b.length && a.every((p, i) => p.field === b[i]!.field && p.value === b[i]!.value)\n}\n\n/** Moved to the kernel (#1249) so `collection.ts` can import statically without\n * dragging derivations code into the floor bundle; re-exported here for\n * compatibility with existing consumers of this module. */\nexport { recordMatchesPairs, findMatchingIdsByPairs } from '../../kernel/match-pairs.js'\n"],"mappings":";AA+BO,SAAS,mBAAmB,WAAuE;AACxG,MAAI,cAAc,OAAW,QAAO,CAAC;AACrC,SAAO,UAAU,IAAI,CAAC,OAAO;AAAA,IAC3B,YAAY,EAAE;AAAA,IACd,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,MAAM,IAAI,EAAE,GAAI,CAAC;AAAA,IAC5C,GAAI,EAAE,cAAc,SAAY,EAAE,WAAW,EAAE,UAAU,IAAI,CAAC;AAAA,EAChE,EAAE;AACJ;AAEA,IAAM,SAAS,CAAC,MACb,OAAO,MAAM,YAAY,OAAO,MAAM,WAAY,OAAO,CAAC,IAAI;AAO1D,SAAS,iBACd,OACA,WACA,QACgD;AAChD,QAAM,MAA+C,CAAC;AACtD,aAAW,QAAQ,OAAO;AACxB,UAAM,IAAI,KAAK,SAAS,OAAO,YAAY,OAAO,SAAS,KAAK,IAAI,CAAC;AACrE,QAAI,MAAM,KAAM,QAAO;AACvB,QAAI,KAAK,EAAE,OAAO,KAAK,IAAI,OAAO,EAAE,CAAC;AAAA,EACvC;AACA,SAAO;AACT;AAGO,SAAS,UACd,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,KAAM,QAAO,MAAM;AAC3C,SAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,EAAG,SAAS,EAAE,UAAU,EAAE,CAAC,EAAG,KAAK;AACtG;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildLazyCache
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-66TQOPFM.js";
|
|
4
4
|
|
|
5
5
|
// src/with-store/lazy/active.ts
|
|
6
6
|
function withLazy() {
|
|
@@ -14,4 +14,4 @@ function withLazy() {
|
|
|
14
14
|
export {
|
|
15
15
|
withLazy
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-ULUMAZ5S.js.map
|
|
@@ -157,38 +157,9 @@ function estimateRecordBytes(record) {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
// src/port/with/lazy-strategy.ts
|
|
161
|
-
function buildLazyCache(collection, cache) {
|
|
162
|
-
if (!cache || cache.maxRecords === void 0 && cache.maxBytes === void 0) {
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Collection "${collection}": lazy mode (prefetch: false) requires a cache option with maxRecords and/or maxBytes. An unbounded lazy cache defeats the purpose.`
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
const lruOptions = {};
|
|
168
|
-
if (cache.maxRecords !== void 0) lruOptions.maxRecords = cache.maxRecords;
|
|
169
|
-
if (cache.maxBytes !== void 0) lruOptions.maxBytes = parseBytes(cache.maxBytes);
|
|
170
|
-
return new Lru(lruOptions);
|
|
171
|
-
}
|
|
172
|
-
var implicitLazyWarned = false;
|
|
173
|
-
var IMPLICIT_LAZY = {
|
|
174
|
-
createCache(collection, cache) {
|
|
175
|
-
if (!implicitLazyWarned) {
|
|
176
|
-
implicitLazyWarned = true;
|
|
177
|
-
if (!(typeof process !== "undefined" && process.env["NODE_ENV"] === "test")) {
|
|
178
|
-
console.warn(
|
|
179
|
-
`[noy-db] Collection "${collection}": lazy mode (prefetch: false) without the lazy service is deprecated \u2014 pass \`lazyStrategy: withLazy()\` (from "@noy-db/hub/lazy") to createNoydb(). The implicit path will be removed at 1.0.`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return buildLazyCache(collection, cache);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
160
|
export {
|
|
188
161
|
Lru,
|
|
189
162
|
parseBytes,
|
|
190
|
-
estimateRecordBytes
|
|
191
|
-
buildLazyCache,
|
|
192
|
-
IMPLICIT_LAZY
|
|
163
|
+
estimateRecordBytes
|
|
193
164
|
};
|
|
194
|
-
//# sourceMappingURL=chunk-
|
|
165
|
+
//# sourceMappingURL=chunk-V4PXLYWM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kernel/cache/lru.ts","../src/kernel/cache/policy.ts"],"sourcesContent":["/**\n * Generic LRU cache for `Collection`'s lazy hydration mode.\n *\n * Backed by a JavaScript `Map`, which preserves insertion order. Promotion\n * is implemented as `delete()` + `set()` — O(1) on `Map` since both\n * operations are constant-time. Eviction walks the iterator from the front\n * (least recently used) until both budgets are satisfied.\n *\n * ships in-memory only. The cache is never persisted; on collection\n * close every entry is dropped. Persisting cache state is a follow-up\n * once the access patterns from real consumers tell us whether it would\n * pay back the complexity.\n */\n\nexport interface LruEntry<V> {\n /** The cached value. */\n readonly value: V\n /**\n * Approximate decrypted byte size of the entry. Used by the byte-budget\n * eviction path. Callers compute this once at insert time and pass it\n * in — recomputing on every access would dominate the per-record cost.\n */\n readonly size: number\n}\n\nexport interface LruOptions {\n /** Maximum number of entries before eviction. Required if `maxBytes` is unset. */\n maxRecords?: number\n /** Maximum total bytes before eviction. Computed from per-entry `size`. */\n maxBytes?: number\n}\n\nexport interface LruStats {\n /** Total cache hits since construction (or `resetStats()`). */\n hits: number\n /** Total cache misses since construction (or `resetStats()`). */\n misses: number\n /** Total entries evicted since construction (or `resetStats()`). */\n evictions: number\n /** Current number of cached entries. */\n size: number\n /** Current sum of cached entry sizes (in bytes, approximate). */\n bytes: number\n}\n\n/**\n * O(1) LRU cache. Both `get()` and `set()` promote the touched entry to\n * the most-recently-used end. Eviction happens after every insert and\n * walks the front of the Map iterator dropping entries until both\n * budgets are satisfied.\n */\nexport class Lru<K, V> {\n private readonly entries = new Map<K, LruEntry<V>>()\n private readonly maxRecords: number | undefined\n private readonly maxBytes: number | undefined\n private currentBytes = 0\n private hits = 0\n private misses = 0\n private evictions = 0\n\n constructor(options: LruOptions) {\n if (options.maxRecords === undefined && options.maxBytes === undefined) {\n throw new Error('Lru: must specify maxRecords, maxBytes, or both')\n }\n this.maxRecords = options.maxRecords\n this.maxBytes = options.maxBytes\n }\n\n /**\n * Look up a key. Hits promote the entry to most-recently-used; misses\n * return undefined. Both update the running stats counters.\n */\n get(key: K): V | undefined {\n const entry = this.entries.get(key)\n if (!entry) {\n this.misses++\n return undefined\n }\n // Promote: re-insert moves the entry to the end of the iteration order.\n this.entries.delete(key)\n this.entries.set(key, entry)\n this.hits++\n return entry.value\n }\n\n /**\n * Insert or update a key. If the key already exists, its size is\n * accounted for and the entry is promoted to MRU. After insertion,\n * eviction runs to maintain both budgets.\n */\n set(key: K, value: V, size: number): void {\n const existing = this.entries.get(key)\n if (existing) {\n // Update path: subtract the old size before adding the new one.\n this.currentBytes -= existing.size\n this.entries.delete(key)\n }\n this.entries.set(key, { value, size })\n this.currentBytes += size\n this.evictUntilUnderBudget()\n }\n\n /**\n * Remove a key without affecting hit/miss stats. Used by `Collection.delete()`.\n * Returns true if the key was present.\n */\n remove(key: K): boolean {\n const existing = this.entries.get(key)\n if (!existing) return false\n this.currentBytes -= existing.size\n this.entries.delete(key)\n return true\n }\n\n /** True if the cache currently holds an entry for the given key. */\n has(key: K): boolean {\n return this.entries.has(key)\n }\n\n /**\n * Drop every entry. Stats counters survive — call `resetStats()` if you\n * want a clean slate. Used by `Collection.invalidate()` on key rotation.\n */\n clear(): void {\n this.entries.clear()\n this.currentBytes = 0\n }\n\n /** Reset hit/miss/eviction counters to zero. Does NOT touch entries. */\n resetStats(): void {\n this.hits = 0\n this.misses = 0\n this.evictions = 0\n }\n\n /** Snapshot of current cache statistics. Cheap — no copying. */\n stats(): LruStats {\n return {\n hits: this.hits,\n misses: this.misses,\n evictions: this.evictions,\n size: this.entries.size,\n bytes: this.currentBytes,\n }\n }\n\n /**\n * Iterate over all currently-cached values. Order is least-recently-used\n * first. Used by tests and devtools — production callers should use\n * `Collection.scan()` instead.\n */\n *values(): IterableIterator<V> {\n for (const entry of this.entries.values()) yield entry.value\n }\n\n /**\n * Walk the cache from the LRU end and drop entries until both budgets\n * are satisfied. Called after every `set()`. Single pass — entries are\n * never re-promoted during eviction.\n */\n private evictUntilUnderBudget(): void {\n while (this.overBudget()) {\n const oldest = this.entries.keys().next()\n if (oldest.done) return // empty cache; nothing more to evict\n const key = oldest.value\n const entry = this.entries.get(key)\n if (entry) this.currentBytes -= entry.size\n this.entries.delete(key)\n this.evictions++\n }\n }\n\n private overBudget(): boolean {\n if (this.maxRecords !== undefined && this.entries.size > this.maxRecords) return true\n if (this.maxBytes !== undefined && this.currentBytes > this.maxBytes) return true\n return false\n }\n}\n","/**\n * Cache policy helpers — parse human-friendly byte budgets into raw numbers.\n *\n * Accepted shapes (case-insensitive on suffix):\n * number — interpreted as raw bytes\n * '1024' — string of digits, raw bytes\n * '50KB' — kilobytes (×1024)\n * '50MB' — megabytes (×1024²)\n * '1GB' — gigabytes (×1024³)\n *\n * Decimals are accepted (`'1.5GB'` → 1610612736 bytes).\n *\n * Anything else throws — better to fail loud at construction time than\n * to silently treat a typo as 0 bytes (which would evict everything).\n */\n\nconst UNITS: Record<string, number> = {\n '': 1,\n 'B': 1,\n 'KB': 1024,\n 'MB': 1024 * 1024,\n 'GB': 1024 * 1024 * 1024,\n // 'TB' deliberately not supported — if you need it, you're not using NOYDB.\n}\n\n/** Parse a byte budget into a positive integer number of bytes. */\nexport function parseBytes(input: number | string): number {\n if (typeof input === 'number') {\n if (!Number.isFinite(input) || input <= 0) {\n throw new Error(`parseBytes: numeric input must be a positive finite number, got ${String(input)}`)\n }\n return Math.floor(input)\n }\n\n const trimmed = input.trim()\n if (trimmed === '') {\n throw new Error('parseBytes: empty string is not a valid byte budget')\n }\n\n // Accept either a bare number or a number followed by a unit suffix.\n // Regex: optional sign, digits with optional decimal, optional unit.\n const match = /^([0-9]+(?:\\.[0-9]+)?)\\s*([A-Za-z]*)$/.exec(trimmed)\n if (!match) {\n throw new Error(`parseBytes: invalid byte budget \"${input}\". Expected format: \"1024\", \"50KB\", \"50MB\", \"1GB\"`)\n }\n\n const value = parseFloat(match[1]!)\n const unit = (match[2] ?? '').toUpperCase()\n\n if (!(unit in UNITS)) {\n throw new Error(`parseBytes: unknown unit \"${match[2]}\" in \"${input}\". Supported: B, KB, MB, GB`)\n }\n\n const bytes = Math.floor(value * UNITS[unit]!)\n if (bytes <= 0) {\n throw new Error(`parseBytes: byte budget must be > 0, got ${bytes} from \"${input}\"`)\n }\n return bytes\n}\n\n/**\n * Estimate the in-memory byte size of a decrypted record.\n *\n * Uses `JSON.stringify().length` as a stand-in for actual heap usage.\n * It's a deliberate approximation: real V8 heap size includes pointer\n * overhead, hidden classes, and string interning that we can't measure\n * from JavaScript. The JSON length is a stable, monotonic proxy that\n * costs O(record size) per insert — fine when records are typically\n * < 1 KB and the cache eviction is the slow path anyway.\n *\n * Returns `0` (and the caller must treat it as 1 for accounting) if\n * stringification throws on circular references; this is documented\n * but in practice records always come from JSON-decoded envelopes.\n */\nexport function estimateRecordBytes(record: unknown): number {\n try {\n return JSON.stringify(record).length\n } catch {\n return 0\n }\n}\n"],"mappings":";AAmDO,IAAM,MAAN,MAAgB;AAAA,EACJ,UAAU,oBAAI,IAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACT,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,SAAqB;AAC/B,QAAI,QAAQ,eAAe,UAAa,QAAQ,aAAa,QAAW;AACtE,YAAM,IAAI,MAAM,iDAAiD;AAAA,IACnE;AACA,SAAK,aAAa,QAAQ;AAC1B,SAAK,WAAW,QAAQ;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,KAAuB;AACzB,UAAM,QAAQ,KAAK,QAAQ,IAAI,GAAG;AAClC,QAAI,CAAC,OAAO;AACV,WAAK;AACL,aAAO;AAAA,IACT;AAEA,SAAK,QAAQ,OAAO,GAAG;AACvB,SAAK,QAAQ,IAAI,KAAK,KAAK;AAC3B,SAAK;AACL,WAAO,MAAM;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,KAAQ,OAAU,MAAoB;AACxC,UAAM,WAAW,KAAK,QAAQ,IAAI,GAAG;AACrC,QAAI,UAAU;AAEZ,WAAK,gBAAgB,SAAS;AAC9B,WAAK,QAAQ,OAAO,GAAG;AAAA,IACzB;AACA,SAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,KAAK,CAAC;AACrC,SAAK,gBAAgB;AACrB,SAAK,sBAAsB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,KAAiB;AACtB,UAAM,WAAW,KAAK,QAAQ,IAAI,GAAG;AACrC,QAAI,CAAC,SAAU,QAAO;AACtB,SAAK,gBAAgB,SAAS;AAC9B,SAAK,QAA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derivePersistedSchema
|
|
7
9
|
} from "./chunk-URHRIAV6.js";
|
|
@@ -238,4 +240,4 @@ function summariseAggregateOp(value) {
|
|
|
238
240
|
export {
|
|
239
241
|
dumpVaultSchema
|
|
240
242
|
};
|
|
241
|
-
//# sourceMappingURL=chunk-
|
|
243
|
+
//# sourceMappingURL=chunk-VGICZPVE.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/with-shape/introspection/walk.ts"],"sourcesContent":["/**\n * Orchestrate the structural walk of a Vault, producing a\n * {@link VaultSchemaSnapshot}. Called from `Vault.dumpSchema()`.\n *\n * @module\n */\n\nimport { derivePersistedSchema } from '../persisted-schemas/derive.js'\nimport { loadPersistedSchema } from '../persisted-schemas/storage.js'\nimport { fallbackDerivationName } from './derivation-key.js'\nimport { jsonSchemaToFields } from './fields.js'\nimport type {\n CollectionConfig,\n CollectionDescriptor,\n CollectionStats,\n DumpSchemaOptions,\n FieldDescriptor,\n InternalCollectionStats,\n MaterializedViewDescriptor,\n OverlayViewDescriptor,\n DerivationDescriptor,\n VaultSchemaSnapshot,\n} from './types.js'\nimport type { Collection } from '../../kernel/collection.js'\nimport type { NoydbStore } from '../../kernel/types.js'\nimport type { UnlockedKeyring } from '../../with-party/team/keyring.js'\nimport type { RefRegistry } from '../../kernel/refs.js'\nimport type { VaultMeta } from './meta.js'\nimport type { EnclaveKey } from '../../kernel/enclave/index.js'\n\n/**\n * The minimal slice of Vault internal state the walker needs.\n * Exposed via `vault._introspectState()` to keep the public Vault\n * surface narrow.\n *\n * @internal\n */\nexport interface VaultIntrospectState {\n readonly name: string\n readonly adapter: NoydbStore\n readonly collectionCache: Map<string, Collection<unknown>>\n readonly refRegistry: RefRegistry\n readonly getDEK: (collectionName: string) => Promise<EnclaveKey>\n /** The active unlocked keyring — role/permissions/userId for access-scoped ops. */\n readonly keyring: UnlockedKeyring\n readonly subsystems: Record<string, boolean>\n /** Vault-level descriptive metadata, when set via `openVault({meta})`. */\n readonly vaultMeta?: VaultMeta\n // Typed loosely on purpose — these are private service registries\n // accessed only for \"is anything registered\" enumeration.\n readonly mvRegistry: unknown\n readonly overlayRegistry: unknown\n readonly derivationRegistry: unknown\n /**\n * Returns the registered schema-update strategy names for a collection,\n * or `undefined` when none are registered. Populated from\n * `vault.#schemaUpdateNames` in `_introspectState()`.\n */\n readonly getCollectionSchemaUpdateNames?: (col: string) => readonly string[] | undefined\n /**\n * Returns `true` when the collection has an archive policy registered\n * in `vault.archiveRegistry`, `false` otherwise. Populated from\n * `vault.archiveRegistry` in `_introspectState()`.\n */\n readonly hasCollectionArchive?: (col: string) => boolean\n}\n\nconst INTERNAL_PREFIX = '_'\n\n/** Reserved internal collections always present in any real vault. */\nconst KNOWN_INTERNAL_NAMES = ['_keyring', '_ledger', '_meta', '_schemas', '_deltas']\n\nexport async function dumpVaultSchema(\n vault: { _introspectState(): VaultIntrospectState },\n opts: DumpSchemaOptions,\n): Promise<VaultSchemaSnapshot> {\n const state = vault._introspectState()\n const sampleSize = opts.sampleSize ?? 50\n const withStats = opts.withStats === true\n\n // 1. User-facing collections — alphabetical for diff stability\n const cacheNames = [...state.collectionCache.keys()]\n const storageNames = (await safeListAllCollections(state.adapter, state.name))\n .filter((n) => !n.startsWith(INTERNAL_PREFIX))\n const allNames = Array.from(new Set([...cacheNames, ...storageNames])).sort()\n\n const collections: Record<string, CollectionDescriptor> = {}\n for (const name of allNames) {\n collections[name] = await describeCollection(state, name, sampleSize, withStats)\n }\n\n // 2. Materialized views (placeholder — real walk in MV slice 2 follow-up)\n const materializedViews = describeMVs(state.mvRegistry)\n // 3. Overlay views\n const overlayViews = describeOverlays(state.overlayRegistry)\n // 4. Derivations\n const derivations = describeDerivations(state.derivationRegistry)\n\n // 5. Internal collections — only with stats\n let internal: Record<string, InternalCollectionStats> | undefined\n if (withStats) {\n internal = {}\n for (const name of KNOWN_INTERNAL_NAMES) {\n const stats = await statsForCollection(state.adapter, state.name, name)\n if (stats.records > 0) {\n internal[name] = { records: stats.records, bytes: stats.bytes }\n }\n }\n }\n\n const snap: VaultSchemaSnapshot = {\n _noydb_snapshot: 1,\n vault: state.name,\n emittedAt: new Date().toISOString(),\n subsystems: state.subsystems,\n ...(state.vaultMeta !== undefined ? { meta: state.vaultMeta } : {}),\n collections,\n materializedViews,\n overlayViews,\n derivations,\n ...(internal !== undefined ? { internal } : {}),\n }\n return snap\n}\n\nasync function safeListAllCollections(adapter: NoydbStore, vault: string): Promise<string[]> {\n try {\n const snap = await adapter.loadAll(vault)\n return Object.keys(snap)\n } catch {\n return []\n }\n}\n\nasync function describeCollection(\n state: VaultIntrospectState,\n collectionName: string,\n sampleSize: number,\n withStats: boolean,\n): Promise<CollectionDescriptor> {\n let fields: Record<string, FieldDescriptor> = {}\n let validator: CollectionDescriptor['validator']\n\n const refsRaw = state.refRegistry.getOutbound(collectionName)\n const refs: CollectionDescriptor['refs'] = {}\n for (const [name, desc] of Object.entries(refsRaw)) {\n refs[name] = { target: desc.target, mode: desc.mode, ...(desc.isArray ? { isArray: true } : {}) }\n }\n\n // 1. Try the persisted Route B envelope first.\n try {\n const dek = await state.getDEK(collectionName)\n const persisted = await loadPersistedSchema(state.adapter, state.name, collectionName, dek)\n if (persisted) {\n validator = { kind: persisted.kind, source: 'persisted' }\n if (persisted.jsonSchema) {\n fields = jsonSchemaToFields(persisted.jsonSchema, 'persisted', refsRaw)\n }\n }\n } catch {\n // No DEK or decrypt failure — fall through to live-validator\n }\n\n const liveColl = state.collectionCache.get(collectionName)\n\n // 2. Try the live in-process validator (when no persisted envelope).\n if (!validator) {\n const schema = liveColl?.getSchema()\n if (schema) {\n try {\n const derived = await derivePersistedSchema(schema)\n validator = { kind: derived.kind, source: 'live-validator' }\n if (derived.jsonSchema) {\n fields = jsonSchemaToFields(derived.jsonSchema, 'live-validator', refsRaw)\n }\n } catch {\n // Derivation failed (e.g. missing peer-dep) — silently leave fields empty\n }\n }\n }\n\n // 3. Sampling fallback — deferred to a follow-up. For now: empty when no schema.\n if (Object.keys(fields).length === 0 && sampleSize > 0) {\n // Sampling path not implemented in baseline slice 2; reserved for follow-up.\n }\n\n // Populate collection-level meta and config from the live collection when available.\n const collMeta = liveColl?.getMeta()\n const collConfig = liveColl?.getConfig()\n\n // Thread vault-level config (archive + schemaUpdate) that the Collection cannot see.\n const archivePresent = state.hasCollectionArchive?.(collectionName) === true\n const schemaUpdateNames = state.getCollectionSchemaUpdateNames?.(collectionName)\n const hasSchemaUpdate = schemaUpdateNames !== undefined && schemaUpdateNames.length > 0\n\n // Merge Collection-level config with vault-level fields. Omit config entirely\n // when all sources are empty.\n let mergedConfig: CollectionConfig | undefined\n if (collConfig !== undefined || archivePresent || hasSchemaUpdate) {\n mergedConfig = {\n ...(collConfig ?? {}),\n ...(archivePresent ? { archive: true as const } : {}),\n ...(hasSchemaUpdate ? { schemaUpdate: schemaUpdateNames } : {}),\n }\n }\n\n const descriptor: CollectionDescriptor = {\n fields,\n indexes: liveColl?.getDeclaredIndexes() ?? [],\n refs,\n ...(validator ? { validator } : {}),\n ...(collMeta !== undefined ? { meta: collMeta } : {}),\n ...(mergedConfig !== undefined ? { config: mergedConfig } : {}),\n }\n if (withStats) {\n const stats = await statsForCollection(state.adapter, state.name, collectionName)\n ;(descriptor as { stats?: CollectionStats }).stats = stats\n }\n return descriptor\n}\n\nasync function statsForCollection(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n): Promise<CollectionStats> {\n const ids = await adapter.list(vault, collection)\n if (ids.length === 0) {\n return { records: 0, bytes: 0, bytesAvg: 0, bytesMin: 0, bytesMax: 0, oldest: '', newest: '' }\n }\n let total = 0\n let min = Number.POSITIVE_INFINITY\n let max = 0\n let oldest = ''\n let newest = ''\n for (const id of ids) {\n const env = await adapter.get(vault, collection, id)\n if (!env) continue\n const size = env._data.length\n total += size\n if (size < min) min = size\n if (size > max) max = size\n if (env._ts < oldest) oldest = env._ts\n if (env._ts > newest) newest = env._ts\n }\n return {\n records: ids.length,\n bytes: total,\n bytesAvg: Math.round(total / ids.length),\n bytesMin: min === Number.POSITIVE_INFINITY ? 0 : min,\n bytesMax: max,\n oldest: oldest === '' ? '' : oldest,\n newest,\n }\n}\n\nfunction describeMVs(registry: unknown): Record<string, MaterializedViewDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const items = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, MaterializedViewDescriptor> = {}\n // Each item is RegisteredMV { spec, dependencies, outputCollection, ... }\n for (const item of items) {\n const reg = item as {\n spec?: {\n name?: string\n unionSources?: ReadonlyArray<{ collection: string }>\n groupBy?: string | ReadonlyArray<string>\n aggregate?: Record<string, unknown>\n refresh?: string\n }\n dependencies?: ReadonlySet<string>\n }\n const spec = reg.spec\n if (!spec?.name) continue\n const sources = spec.unionSources\n ? spec.unionSources.map((u) => u.collection)\n : (reg.dependencies ? [...reg.dependencies].sort() : [])\n const groupBy = spec.groupBy\n ? Array.isArray(spec.groupBy) ? [...spec.groupBy] : [spec.groupBy]\n : undefined\n const aggregate = spec.aggregate ? Object.fromEntries(\n Object.entries(spec.aggregate).map(([k, v]) => [k, summariseAggregateOp(v)]),\n ) : undefined\n out[spec.name] = {\n sources,\n ...(groupBy ? { groupBy } : {}),\n ...(aggregate ? { aggregate } : {}),\n refresh: spec.refresh ?? 'eager',\n }\n }\n return out\n}\n\nfunction describeOverlays(registry: unknown): Record<string, OverlayViewDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const specs = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, OverlayViewDescriptor> = {}\n for (const spec of specs) {\n const s = spec as { name?: string; base?: string; overlay?: string }\n if (!s.name || !s.base || !s.overlay) continue\n out[s.name] = { base: s.base, overlay: s.overlay }\n }\n return out\n}\n\nfunction describeDerivations(registry: unknown): Record<string, DerivationDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const items = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, DerivationDescriptor> = {}\n const used = new Set<string>()\n // Pre-seed with every explicit name BEFORE keying any derivation, so an\n // unnamed derivation's fallback key never collides with (and clobbers) a\n // named one, regardless of registration order (#973).\n for (const item of items) {\n const reg = item as { spec?: { name?: string }; name?: string }\n const explicitName = (reg.spec ?? reg).name\n if (explicitName !== undefined) used.add(explicitName)\n }\n for (const item of items) {\n // `all()` on DerivationRegistry returns RegisteredStrategy objects:\n // { spec: DerivationSpec, strategyHash }. Read `spec` and fall\n // back to the item itself for forward-compat with other registries.\n const reg = item as { spec?: { name?: string; source?: string; outputs?: Record<string, { collection: string }> }; name?: string; source?: string; outputs?: Record<string, { collection: string }> }\n const s = reg.spec ?? reg\n if (!s.source) continue\n const outputCollections = s.outputs\n ? Object.values(s.outputs).map((o) => (o as { collection: string }).collection)\n : []\n // Named derivations key by their (vault-unique) `name`. Unnamed ones key\n // by the shared collision-safe fallback (sorted output collections, else\n // source, with a `#occurrence` suffix on collision) — the SAME algorithm\n // `listBehaviors` uses (`./derivation-key.ts`) so both surfaces key an\n // unnamed derivation identically.\n const key = s.name ?? fallbackDerivationName(outputCollections, s.source, used)\n if (s.name === undefined) used.add(key)\n out[key] = {\n source: s.source,\n outputs: outputCollections,\n ...(s.name !== undefined ? { name: s.name } : {}),\n }\n }\n return out\n}\n\nfunction listFromRegistry(reg: Record<string, unknown>): readonly unknown[] {\n // Registries expose different accessor methods; try the common ones.\n for (const method of ['all', 'list', 'specs', 'values']) {\n const fn = reg[method]\n if (typeof fn === 'function') {\n try {\n const out = (fn as () => unknown).call(reg)\n if (Array.isArray(out)) return out\n if (out && typeof (out as { values?: () => unknown }).values === 'function') {\n return [...(out as { values: () => Iterable<unknown> }).values()]\n }\n } catch {\n continue\n }\n }\n }\n return []\n}\n\nfunction summariseAggregateOp(value: unknown): string {\n if (value && typeof value === 'object') {\n const op = (value as { op?: string; kind?: string; field?: string }).op\n ?? (value as { kind?: string }).kind\n const field = (value as { field?: string }).field\n if (op && field) return `${op}(${field})`\n if (op) return op\n }\n return String(value)\n}\n"],"mappings":";;;;;;;;;;;;AA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;AACtC,QAAI,GAAG,IAAI;AAAA,MACT,QAAQ,EAAE;AAAA,MACV,SAAS;AAAA,MACT,GAAI,EAAE,SAAS,SAAY,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;AAAA,IACjD;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,iBAAiB,KAAkD;AAE1E,aAAW,UAAU,CAAC,OAAO,QAAQ,SAAS,QAAQ,GAAG;AACvD,UAAM,KAAK,IAAI,MAAM;AACrB,QAAI,OAAO,OAAO,YAAY;AAC5B,UAAI;AACF,cAAM,MAAO,GAAqB,KAAK,GAAG;AAC1C,YAAI,MAAM,QAAQ,GAAG,EAAG,QAAO;AAC/B,YAAI,OAAO,OAAQ,IAAmC,WAAW,YAAY;AAC3E,iBAAO,CAAC,GAAI,IAA4C,OAAO,CAAC;AAAA,QAClE;AAAA,MACF,QAAQ;AACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC;AACV;AAEA,SAAS,qBAAqB,OAAwB;AACpD,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,KAAM,MAAyD,MAC/D,MAA4B;AAClC,UAAM,QAAS,MAA6B;AAC5C,QAAI,MAAM,MAAO,QAAO,GAAG,EAAE,IAAI,KAAK;AACtC,QAAI,GAAI,QAAO;AAAA,EACjB;AACA,SAAO,OAAO,KAAK;AACrB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/with-shape/introspection/walk.ts"],"sourcesContent":["/**\n * Orchestrate the structural walk of a Vault, producing a\n * {@link VaultSchemaSnapshot}. Called from `Vault.dumpSchema()`.\n *\n * @module\n */\n\nimport { derivePersistedSchema } from '../persisted-schemas/derive.js'\nimport { loadPersistedSchema } from '../persisted-schemas/storage.js'\nimport { fallbackDerivationName } from './derivation-key.js'\nimport { jsonSchemaToFields } from './fields.js'\nimport type {\n CollectionConfig,\n CollectionDescriptor,\n CollectionStats,\n DumpSchemaOptions,\n FieldDescriptor,\n InternalCollectionStats,\n MaterializedViewDescriptor,\n OverlayViewDescriptor,\n DerivationDescriptor,\n VaultSchemaSnapshot,\n} from './types.js'\nimport type { Collection } from '../../kernel/collection.js'\nimport type { NoydbStore } from '../../kernel/types.js'\nimport type { UnlockedKeyring } from '../../with-party/team/keyring.js'\nimport type { RefRegistry } from '../../kernel/refs.js'\nimport type { VaultMeta } from './meta.js'\nimport type { EnclaveKey } from '../../kernel/enclave/index.js'\n\n/**\n * The minimal slice of Vault internal state the walker needs.\n * Exposed via `vault._introspectState()` to keep the public Vault\n * surface narrow.\n *\n * @internal\n */\nexport interface VaultIntrospectState {\n readonly name: string\n readonly adapter: NoydbStore\n readonly collectionCache: Map<string, Collection<unknown>>\n readonly refRegistry: RefRegistry\n readonly getDEK: (collectionName: string) => Promise<EnclaveKey>\n /** The active unlocked keyring — role/permissions/userId for access-scoped ops. */\n readonly keyring: UnlockedKeyring\n readonly subsystems: Record<string, boolean>\n /** Vault-level descriptive metadata, when set via `openVault({meta})`. */\n readonly vaultMeta?: VaultMeta\n // Typed loosely on purpose — these are private service registries\n // accessed only for \"is anything registered\" enumeration.\n readonly mvRegistry: unknown\n readonly overlayRegistry: unknown\n readonly derivationRegistry: unknown\n /**\n * Returns the registered schema-update strategy names for a collection,\n * or `undefined` when none are registered. Populated from\n * `vault.#schemaUpdateNames` in `_introspectState()`.\n */\n readonly getCollectionSchemaUpdateNames?: (col: string) => readonly string[] | undefined\n /**\n * Returns `true` when the collection has an archive policy registered\n * in `vault.archiveRegistry`, `false` otherwise. Populated from\n * `vault.archiveRegistry` in `_introspectState()`.\n */\n readonly hasCollectionArchive?: (col: string) => boolean\n}\n\nconst INTERNAL_PREFIX = '_'\n\n/** Reserved internal collections always present in any real vault. */\nconst KNOWN_INTERNAL_NAMES = ['_keyring', '_ledger', '_meta', '_schemas', '_deltas']\n\nexport async function dumpVaultSchema(\n vault: { _introspectState(): VaultIntrospectState },\n opts: DumpSchemaOptions,\n): Promise<VaultSchemaSnapshot> {\n const state = vault._introspectState()\n const sampleSize = opts.sampleSize ?? 50\n const withStats = opts.withStats === true\n\n // 1. User-facing collections — alphabetical for diff stability\n const cacheNames = [...state.collectionCache.keys()]\n const storageNames = (await safeListAllCollections(state.adapter, state.name))\n .filter((n) => !n.startsWith(INTERNAL_PREFIX))\n const allNames = Array.from(new Set([...cacheNames, ...storageNames])).sort()\n\n const collections: Record<string, CollectionDescriptor> = {}\n for (const name of allNames) {\n collections[name] = await describeCollection(state, name, sampleSize, withStats)\n }\n\n // 2. Materialized views (placeholder — real walk in MV slice 2 follow-up)\n const materializedViews = describeMVs(state.mvRegistry)\n // 3. Overlay views\n const overlayViews = describeOverlays(state.overlayRegistry)\n // 4. Derivations\n const derivations = describeDerivations(state.derivationRegistry)\n\n // 5. Internal collections — only with stats\n let internal: Record<string, InternalCollectionStats> | undefined\n if (withStats) {\n internal = {}\n for (const name of KNOWN_INTERNAL_NAMES) {\n const stats = await statsForCollection(state.adapter, state.name, name)\n if (stats.records > 0) {\n internal[name] = { records: stats.records, bytes: stats.bytes }\n }\n }\n }\n\n const snap: VaultSchemaSnapshot = {\n _noydb_snapshot: 1,\n vault: state.name,\n emittedAt: new Date().toISOString(),\n subsystems: state.subsystems,\n ...(state.vaultMeta !== undefined ? { meta: state.vaultMeta } : {}),\n collections,\n materializedViews,\n overlayViews,\n derivations,\n ...(internal !== undefined ? { internal } : {}),\n }\n return snap\n}\n\nasync function safeListAllCollections(adapter: NoydbStore, vault: string): Promise<string[]> {\n try {\n const snap = await adapter.loadAll(vault)\n return Object.keys(snap)\n } catch {\n return []\n }\n}\n\nasync function describeCollection(\n state: VaultIntrospectState,\n collectionName: string,\n sampleSize: number,\n withStats: boolean,\n): Promise<CollectionDescriptor> {\n let fields: Record<string, FieldDescriptor> = {}\n let validator: CollectionDescriptor['validator']\n\n const refsRaw = state.refRegistry.getOutbound(collectionName)\n const refs: CollectionDescriptor['refs'] = {}\n for (const [name, desc] of Object.entries(refsRaw)) {\n refs[name] = { target: desc.target, mode: desc.mode, ...(desc.isArray ? { isArray: true } : {}) }\n }\n\n // 1. Try the persisted Route B envelope first.\n try {\n const dek = await state.getDEK(collectionName)\n const persisted = await loadPersistedSchema(state.adapter, state.name, collectionName, dek)\n if (persisted) {\n validator = { kind: persisted.kind, source: 'persisted' }\n if (persisted.jsonSchema) {\n fields = jsonSchemaToFields(persisted.jsonSchema, 'persisted', refsRaw)\n }\n }\n } catch {\n // No DEK or decrypt failure — fall through to live-validator\n }\n\n const liveColl = state.collectionCache.get(collectionName)\n\n // 2. Try the live in-process validator (when no persisted envelope).\n if (!validator) {\n const schema = liveColl?.getSchema()\n if (schema) {\n try {\n const derived = await derivePersistedSchema(schema)\n validator = { kind: derived.kind, source: 'live-validator' }\n if (derived.jsonSchema) {\n fields = jsonSchemaToFields(derived.jsonSchema, 'live-validator', refsRaw)\n }\n } catch {\n // Derivation failed (e.g. missing peer-dep) — silently leave fields empty\n }\n }\n }\n\n // 3. Sampling fallback — deferred to a follow-up. For now: empty when no schema.\n if (Object.keys(fields).length === 0 && sampleSize > 0) {\n // Sampling path not implemented in baseline slice 2; reserved for follow-up.\n }\n\n // Populate collection-level meta and config from the live collection when available.\n const collMeta = liveColl?.getMeta()\n const collConfig = liveColl?.getConfig()\n\n // Thread vault-level config (archive + schemaUpdate) that the Collection cannot see.\n const archivePresent = state.hasCollectionArchive?.(collectionName) === true\n const schemaUpdateNames = state.getCollectionSchemaUpdateNames?.(collectionName)\n const hasSchemaUpdate = schemaUpdateNames !== undefined && schemaUpdateNames.length > 0\n\n // Merge Collection-level config with vault-level fields. Omit config entirely\n // when all sources are empty.\n let mergedConfig: CollectionConfig | undefined\n if (collConfig !== undefined || archivePresent || hasSchemaUpdate) {\n mergedConfig = {\n ...(collConfig ?? {}),\n ...(archivePresent ? { archive: true as const } : {}),\n ...(hasSchemaUpdate ? { schemaUpdate: schemaUpdateNames } : {}),\n }\n }\n\n const descriptor: CollectionDescriptor = {\n fields,\n indexes: liveColl?.getDeclaredIndexes() ?? [],\n refs,\n ...(validator ? { validator } : {}),\n ...(collMeta !== undefined ? { meta: collMeta } : {}),\n ...(mergedConfig !== undefined ? { config: mergedConfig } : {}),\n }\n if (withStats) {\n const stats = await statsForCollection(state.adapter, state.name, collectionName)\n ;(descriptor as { stats?: CollectionStats }).stats = stats\n }\n return descriptor\n}\n\nasync function statsForCollection(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n): Promise<CollectionStats> {\n const ids = await adapter.list(vault, collection)\n if (ids.length === 0) {\n return { records: 0, bytes: 0, bytesAvg: 0, bytesMin: 0, bytesMax: 0, oldest: '', newest: '' }\n }\n let total = 0\n let min = Number.POSITIVE_INFINITY\n let max = 0\n let oldest = ''\n let newest = ''\n for (const id of ids) {\n const env = await adapter.get(vault, collection, id)\n if (!env) continue\n const size = env._data.length\n total += size\n if (size < min) min = size\n if (size > max) max = size\n if (env._ts < oldest) oldest = env._ts\n if (env._ts > newest) newest = env._ts\n }\n return {\n records: ids.length,\n bytes: total,\n bytesAvg: Math.round(total / ids.length),\n bytesMin: min === Number.POSITIVE_INFINITY ? 0 : min,\n bytesMax: max,\n oldest: oldest === '' ? '' : oldest,\n newest,\n }\n}\n\nfunction describeMVs(registry: unknown): Record<string, MaterializedViewDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const items = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, MaterializedViewDescriptor> = {}\n // Each item is RegisteredMV { spec, dependencies, outputCollection, ... }\n for (const item of items) {\n const reg = item as {\n spec?: {\n name?: string\n unionSources?: ReadonlyArray<{ collection: string }>\n groupBy?: string | ReadonlyArray<string>\n aggregate?: Record<string, unknown>\n refresh?: string\n }\n dependencies?: ReadonlySet<string>\n }\n const spec = reg.spec\n if (!spec?.name) continue\n const sources = spec.unionSources\n ? spec.unionSources.map((u) => u.collection)\n : (reg.dependencies ? [...reg.dependencies].sort() : [])\n const groupBy = spec.groupBy\n ? Array.isArray(spec.groupBy) ? [...spec.groupBy] : [spec.groupBy]\n : undefined\n const aggregate = spec.aggregate ? Object.fromEntries(\n Object.entries(spec.aggregate).map(([k, v]) => [k, summariseAggregateOp(v)]),\n ) : undefined\n out[spec.name] = {\n sources,\n ...(groupBy ? { groupBy } : {}),\n ...(aggregate ? { aggregate } : {}),\n refresh: spec.refresh ?? 'eager',\n }\n }\n return out\n}\n\nfunction describeOverlays(registry: unknown): Record<string, OverlayViewDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const specs = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, OverlayViewDescriptor> = {}\n for (const spec of specs) {\n const s = spec as { name?: string; base?: string; overlay?: string }\n if (!s.name || !s.base || !s.overlay) continue\n out[s.name] = { base: s.base, overlay: s.overlay }\n }\n return out\n}\n\nfunction describeDerivations(registry: unknown): Record<string, DerivationDescriptor> {\n if (!registry || typeof registry !== 'object') return {}\n const items = listFromRegistry(registry as Record<string, unknown>)\n const out: Record<string, DerivationDescriptor> = {}\n const used = new Set<string>()\n // Pre-seed with every explicit name BEFORE keying any derivation, so an\n // unnamed derivation's fallback key never collides with (and clobbers) a\n // named one, regardless of registration order (#973).\n for (const item of items) {\n const reg = item as { spec?: { name?: string }; name?: string }\n const explicitName = (reg.spec ?? reg).name\n if (explicitName !== undefined) used.add(explicitName)\n }\n for (const item of items) {\n // `all()` on DerivationRegistry returns RegisteredStrategy objects:\n // { spec: DerivationSpec, strategyHash }. Read `spec` and fall\n // back to the item itself for forward-compat with other registries.\n const reg = item as { spec?: { name?: string; source?: string; outputs?: Record<string, { collection: string }> }; name?: string; source?: string; outputs?: Record<string, { collection: string }> }\n const s = reg.spec ?? reg\n if (!s.source) continue\n const outputCollections = s.outputs\n ? Object.values(s.outputs).map((o) => (o as { collection: string }).collection)\n : []\n // Named derivations key by their (vault-unique) `name`. Unnamed ones key\n // by the shared collision-safe fallback (sorted output collections, else\n // source, with a `#occurrence` suffix on collision) — the SAME algorithm\n // `listBehaviors` uses (`./derivation-key.ts`) so both surfaces key an\n // unnamed derivation identically.\n const key = s.name ?? fallbackDerivationName(outputCollections, s.source, used)\n if (s.name === undefined) used.add(key)\n out[key] = {\n source: s.source,\n outputs: outputCollections,\n ...(s.name !== undefined ? { name: s.name } : {}),\n }\n }\n return out\n}\n\nfunction listFromRegistry(reg: Record<string, unknown>): readonly unknown[] {\n // Registries expose different accessor methods; try the common ones.\n for (const method of ['all', 'list', 'specs', 'values']) {\n const fn = reg[method]\n if (typeof fn === 'function') {\n try {\n const out = (fn as () => unknown).call(reg)\n if (Array.isArray(out)) return out\n if (out && typeof (out as { values?: () => unknown }).values === 'function') {\n return [...(out as { values: () => Iterable<unknown> }).values()]\n }\n } catch {\n continue\n }\n }\n }\n return []\n}\n\nfunction summariseAggregateOp(value: unknown): string {\n if (value && typeof value === 'object') {\n const op = (value as { op?: string; kind?: string; field?: string }).op\n ?? (value as { kind?: string }).kind\n const field = (value as { field?: string }).field\n if (op && field) return `${op}(${field})`\n if (op) return op\n }\n return String(value)\n}\n"],"mappings":";;;;;;;;;;;;;;AAmEA,IAAM,kBAAkB;AAGxB,IAAM,uBAAuB,CAAC,YAAY,WAAW,SAAS,YAAY,SAAS;AAEnF,eAAsB,gBACpB,OACA,MAC8B;AAC9B,QAAM,QAAQ,MAAM,iBAAiB;AACrC,QAAM,aAAa,KAAK,cAAc;AACtC,QAAM,YAAY,KAAK,cAAc;AAGrC,QAAM,aAAa,CAAC,GAAG,MAAM,gBAAgB,KAAK,CAAC;AACnD,QAAM,gBAAgB,MAAM,uBAAuB,MAAM,SAAS,MAAM,IAAI,GACzE,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,eAAe,CAAC;AAC/C,QAAM,WAAW,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAG,YAAY,GAAG,YAAY,CAAC,CAAC,EAAE,KAAK;AAE5E,QAAM,cAAoD,CAAC;AAC3D,aAAW,QAAQ,UAAU;AAC3B,gBAAY,IAAI,IAAI,MAAM,mBAAmB,OAAO,MAAM,YAAY,SAAS;AAAA,EACjF;AAGA,QAAM,oB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wB;AACpD,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,KAAM,MAAyD,MAC/D,MAA4B;AAClC,UAAM,QAAS,MAA6B;AAC5C,QAAI,MAAM,MAAO,QAAO,GAAG,EAAE,IAAI,KAAK;AACtC,QAAI,GAAI,QAAO;AAAA,EACjB;AACA,SAAO,OAAO,KAAK;AACrB;","names":[]}
|
|
@@ -92,21 +92,7 @@ function jsonSchemaToFields(jsonSchema, source, refs) {
|
|
|
92
92
|
return fields;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// src/with-shape/introspection/derivation-key.ts
|
|
96
|
-
function fallbackDerivationName(outputCollections, source, used) {
|
|
97
|
-
const base = outputCollections.length > 0 ? [...outputCollections].sort().join("+") : source;
|
|
98
|
-
if (!used.has(base)) return base;
|
|
99
|
-
let occurrence = 1;
|
|
100
|
-
let candidate = `${base}#${occurrence}`;
|
|
101
|
-
while (used.has(candidate)) {
|
|
102
|
-
occurrence++;
|
|
103
|
-
candidate = `${base}#${occurrence}`;
|
|
104
|
-
}
|
|
105
|
-
return candidate;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
95
|
export {
|
|
109
|
-
jsonSchemaToFields
|
|
110
|
-
fallbackDerivationName
|
|
96
|
+
jsonSchemaToFields
|
|
111
97
|
};
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-VYYM3MEN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/with-shape/introspection/fields.ts"],"sourcesContent":["/**\n * Map a JSON Schema (Draft 2020-12 produced by `zod-to-json-schema`) into\n * the {@link FieldDescriptor} map consumed by {@link VaultSchemaSnapshot}.\n *\n * Used by both the persisted-schema path (decrypted envelope body) and the\n * live-validator path (in-process derivation).\n *\n * @module\n */\n\nimport type { FieldDescriptor, FieldSource } from './types.js'\n\ninterface JsonSchemaShape {\n type?: string | string[]\n properties?: Record<string, JsonSchemaShape>\n required?: string[]\n enum?: unknown[]\n const?: unknown\n minLength?: number\n maxLength?: number\n pattern?: string\n minimum?: number\n maximum?: number\n exclusiveMinimum?: number\n exclusiveMaximum?: number\n format?: string\n items?: JsonSchemaShape\n oneOf?: JsonSchemaShape[]\n anyOf?: JsonSchemaShape[]\n}\n\nfunction jsonSchemaType(node: JsonSchemaShape): string {\n if (Array.isArray(node.type)) {\n const non = node.type.filter((t) => t !== 'null')\n return non[0] ?? 'opaque'\n }\n if (node.enum && Array.isArray(node.enum)) return 'enum'\n // JSON Schema `const` is used by zod-to-json-schema for z.literal(...)\n if (node.const !== undefined) return 'enum'\n if (typeof node.type === 'string') return node.type\n return 'opaque'\n}\n\n// #657 — zod v4's native `toJSONSchema()` injects a ±Number.MAX_SAFE_INTEGER\n// bound on every `.int()` field (a JS-safe-integer representability fact,\n// not authored validation intent — `type: 'integer'` already carries it).\n// Empirically verified: `z.number().int()` → `{type:'integer', minimum:\n// -9007199254740991, maximum:9007199254740991}`, and — critically — zod\n// emits NO metadata distinguishing that derived bound from an authored one\n// at the exact same value (`z.number().min(-9007199254740991)\n// .max(9007199254740991)` on a plain, non-int number produces a\n// byte-identical minimum/maximum). Without that distinguishing signal, a\n// value-based filter gated on `type === 'integer'` is the pragmatic call:\n// it never touches a non-int field's authored bound (whatever its value),\n// and an authored `.int().min(Number.MAX_SAFE_INTEGER)` is pathological\n// either way, so folding it into the same omission is an acceptable trade.\nfunction isIntSentinel(node: JsonSchemaShape, value: number): boolean {\n return node.type === 'integer' && Math.abs(value) === Number.MAX_SAFE_INTEGER\n}\n\nfunction constraintsFor(node: JsonSchemaShape): Record<string, unknown> | undefined {\n const out: Record<string, unknown> = {}\n if (node.enum) out.values = node.enum\n // JSON Schema `const` (used by zod-to-json-schema for z.literal) — treat like a single-value enum\n if (node.const !== undefined) out.values = [node.const]\n if (node.minLength !== undefined) out.minLength = node.minLength\n if (node.maxLength !== undefined) out.maxLength = node.maxLength\n if (node.pattern !== undefined) out.pattern = node.pattern\n if (node.format !== undefined) out.format = node.format\n if (node.minimum !== undefined && !isIntSentinel(node, node.minimum)) out.minimum = node.minimum\n if (node.maximum !== undefined && !isIntSentinel(node, node.maximum)) out.maximum = node.maximum\n if (node.exclusiveMinimum !== undefined) out.gt = node.exclusiveMinimum\n if (node.exclusiveMaximum !== undefined) out.lt = node.exclusiveMaximum\n return Object.keys(out).length === 0 ? undefined : out\n}\n\n/**\n * Extract fields from a single JSON Schema object node (must have `properties`).\n * Used by both the plain-object path and the per-member extraction in the union path.\n */\nfunction extractObjectFields(\n obj: JsonSchemaShape,\n source: FieldSource,\n refs?: Record<string, { target: string; mode: string }>,\n): { fields: Record<string, FieldDescriptor>; required: Set<string> } {\n const required = new Set(Array.isArray(obj.required) ? obj.required : [])\n const fields: Record<string, FieldDescriptor> = {}\n if (!obj.properties || typeof obj.properties !== 'object') return { fields, required }\n\n for (const [name, node] of Object.entries(obj.properties)) {\n const descriptor: FieldDescriptor = {\n type: jsonSchemaType(node),\n source,\n ...(required.has(name) ? {} : { optional: true }),\n ...(refs?.[name] ? { references: `${refs[name].target}.id` } : {}),\n }\n const constraints = constraintsFor(node)\n if (constraints) (descriptor as { constraints?: Record<string, unknown> }).constraints = constraints\n fields[name] = descriptor\n }\n\n return { fields, required }\n}\n\n/**\n * Merge field descriptors from multiple union members.\n *\n * Merge rules:\n * - Emit the UNION of all field names so no member's fields are hidden.\n * - A field is required (optional=false/absent) only when it is required in\n * EVERY member; otherwise it is marked optional=true.\n * - For the discriminator field (appears in every member with a `const` value),\n * collect the const values from all members and surface them as constraints.values\n * so the caller can see the full literal set.\n * - For conflicting types across members, first-seen wins.\n */\nfunction mergeUnionMembers(\n members: JsonSchemaShape[],\n source: FieldSource,\n refs?: Record<string, { target: string; mode: string }>,\n): Record<string, FieldDescriptor> {\n if (members.length === 0) return {}\n\n // Extract per-member fields + required sets\n const extracted = members\n .filter((m) => m.properties && typeof m.properties === 'object')\n .map((m) => extractObjectFields(m, source, refs))\n\n if (extracted.length === 0) return {}\n\n // Collect all field names across all members\n const allNames = new Set<string>()\n for (const { fields } of extracted) {\n for (const name of Object.keys(fields)) allNames.add(name)\n }\n\n const memberCount = extracted.length\n const out: Record<string, FieldDescriptor> = {}\n\n for (const name of allNames) {\n // Which members contain this field?\n const presentIn = extracted.filter(({ fields }) => name in fields)\n const requiredInAll = presentIn.length === memberCount\n && presentIn.every(({ required }) => required.has(name))\n\n // Use first-seen descriptor as the base (presentIn is always non-empty here since\n // we iterate names that appeared in at least one member's fields)\n const base = presentIn[0]!.fields[name]!\n\n // For discriminator-like fields: collect const/enum values across all members\n // to surface the full literal set in constraints.values\n const allValues: unknown[] = []\n for (const { fields } of presentIn) {\n const fd = fields[name]\n if (fd?.constraints?.values && Array.isArray(fd.constraints.values)) {\n for (const v of fd.constraints.values) {\n if (!allValues.includes(v)) allValues.push(v)\n }\n }\n }\n\n const mergedConstraints: Record<string, unknown> | undefined =\n allValues.length > 0\n ? { ...(base.constraints ?? {}), values: allValues }\n : base.constraints\n\n const descriptor: FieldDescriptor = {\n type: base.type,\n source,\n ...(requiredInAll ? {} : { optional: true }),\n ...(base.references ? { references: base.references } : {}),\n }\n if (mergedConstraints) {\n (descriptor as { constraints?: Record<string, unknown> }).constraints = mergedConstraints\n }\n out[name] = descriptor\n }\n\n return out\n}\n\nexport function jsonSchemaToFields(\n jsonSchema: unknown,\n source: FieldSource,\n refs?: Record<string, { target: string; mode: string }>,\n): Record<string, FieldDescriptor> {\n if (!jsonSchema || typeof jsonSchema !== 'object') return {}\n const root = jsonSchema as JsonSchemaShape\n\n // Handle discriminated unions: zod-to-json-schema emits anyOf/oneOf for z.discriminatedUnion\n const unionMembers = root.anyOf ?? root.oneOf\n if (Array.isArray(unionMembers) && unionMembers.length > 0) {\n return mergeUnionMembers(unionMembers, source, refs)\n }\n\n if (!root.properties || typeof root.properties !== 'object') return {}\n\n const { fields } = extractObjectFields(root, source, refs)\n return fields\n}\n"],"mappings":";AA+BA,SAAS,eAAe,MAA+B;AACrD,MAAI,M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