@noy-db/hub 0.7.0-pre.12 → 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.
Files changed (67) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/dist/cargo/index.js +1 -1
  3. package/dist/chunk-66TQOPFM.js +37 -0
  4. package/dist/chunk-66TQOPFM.js.map +1 -0
  5. package/dist/{chunk-H7XCIM3Z.js → chunk-AJQY44CE.js} +43 -16
  6. package/dist/chunk-AJQY44CE.js.map +1 -0
  7. package/dist/{chunk-E5OHKSBD.js → chunk-BMELYFHU.js} +2 -2
  8. package/dist/chunk-BWXGSSFX.js +1589 -0
  9. package/dist/chunk-BWXGSSFX.js.map +1 -0
  10. package/dist/{chunk-HN4FNA4X.js → chunk-COTPDJR5.js} +8 -8
  11. package/dist/{chunk-E3EBMC4G.js → chunk-E2MYJGSG.js} +2 -2
  12. package/dist/{chunk-JJR2JIN4.js → chunk-FFBYRWDJ.js} +2 -2
  13. package/dist/{chunk-WQF3QABE.js → chunk-IHFXR2VQ.js} +9 -79
  14. package/dist/chunk-IHFXR2VQ.js.map +1 -0
  15. package/dist/chunk-MGOXJIBV.js +176 -0
  16. package/dist/chunk-MGOXJIBV.js.map +1 -0
  17. package/dist/{chunk-KL7AS3HV.js → chunk-PDD75NUZ.js} +5 -2
  18. package/dist/chunk-PDD75NUZ.js.map +1 -0
  19. package/dist/chunk-RTBJ5IOO.js +87 -0
  20. package/dist/chunk-RTBJ5IOO.js.map +1 -0
  21. package/dist/{chunk-7NTBVFGD.js → chunk-SXCYYMVS.js} +2 -2
  22. package/dist/{chunk-THNJ3IKU.js → chunk-ULUMAZ5S.js} +2 -2
  23. package/dist/{chunk-NO272T7Q.js → chunk-V4PXLYWM.js} +2 -31
  24. package/dist/chunk-V4PXLYWM.js.map +1 -0
  25. package/dist/{chunk-SWVNZQVR.js → chunk-YPXNAP72.js} +2 -169
  26. package/dist/chunk-YPXNAP72.js.map +1 -0
  27. package/dist/{chunk-XMF3GKUR.js → chunk-ZVCC36XQ.js} +50 -870
  28. package/dist/chunk-ZVCC36XQ.js.map +1 -0
  29. package/dist/{collection-facade-MGGHQ3HU.js → collection-facade-4ACKIDDY.js} +4 -3
  30. package/dist/derivations/index.js +6 -2
  31. package/dist/{dispatch-XEBHUGBV.js → dispatch-MSTR5VBI.js} +10 -5
  32. package/dist/dispatch-MSTR5VBI.js.map +1 -0
  33. package/dist/{dispatch-44J4TL72.js → dispatch-PDP5TA73.js} +5 -5
  34. package/dist/{executor-KSPGNVDO.js → executor-YDDC5XGY.js} +4 -3
  35. package/dist/index.js +25 -21
  36. package/dist/index.js.map +1 -1
  37. package/dist/lazy/index.js +3 -2
  38. package/dist/materialized-views/index.js +4 -3
  39. package/dist/{noydb-JJXPICIC.js → noydb-2C6QQJ5S.js} +12 -9
  40. package/dist/pod/index.js +12 -9
  41. package/dist/{registry-BZQIVNNO.js → registry-D2YXKRYC.js} +7 -3
  42. package/dist/search/index.js +1 -1
  43. package/dist/{stale-KSPG6LFX.js → stale-2CHKZTMK.js} +2 -2
  44. package/dist/with-formula/derivations/registry.d.ts +6 -7
  45. package/dist/with-shape/introspection/describe.d.ts +29 -9
  46. package/package.json +3 -3
  47. package/dist/chunk-7BE7ZDVQ.js +0 -722
  48. package/dist/chunk-7BE7ZDVQ.js.map +0 -1
  49. package/dist/chunk-H7XCIM3Z.js.map +0 -1
  50. package/dist/chunk-KL7AS3HV.js.map +0 -1
  51. package/dist/chunk-NO272T7Q.js.map +0 -1
  52. package/dist/chunk-SWVNZQVR.js.map +0 -1
  53. package/dist/chunk-WQF3QABE.js.map +0 -1
  54. package/dist/chunk-XMF3GKUR.js.map +0 -1
  55. package/dist/dispatch-XEBHUGBV.js.map +0 -1
  56. /package/dist/{chunk-E5OHKSBD.js.map → chunk-BMELYFHU.js.map} +0 -0
  57. /package/dist/{chunk-HN4FNA4X.js.map → chunk-COTPDJR5.js.map} +0 -0
  58. /package/dist/{chunk-E3EBMC4G.js.map → chunk-E2MYJGSG.js.map} +0 -0
  59. /package/dist/{chunk-JJR2JIN4.js.map → chunk-FFBYRWDJ.js.map} +0 -0
  60. /package/dist/{chunk-7NTBVFGD.js.map → chunk-SXCYYMVS.js.map} +0 -0
  61. /package/dist/{chunk-THNJ3IKU.js.map → chunk-ULUMAZ5S.js.map} +0 -0
  62. /package/dist/{collection-facade-MGGHQ3HU.js.map → collection-facade-4ACKIDDY.js.map} +0 -0
  63. /package/dist/{dispatch-44J4TL72.js.map → dispatch-PDP5TA73.js.map} +0 -0
  64. /package/dist/{executor-KSPGNVDO.js.map → executor-YDDC5XGY.js.map} +0 -0
  65. /package/dist/{noydb-JJXPICIC.js.map → noydb-2C6QQJ5S.js.map} +0 -0
  66. /package/dist/{registry-BZQIVNNO.js.map → registry-D2YXKRYC.js.map} +0 -0
  67. /package/dist/{stale-KSPG6LFX.js.map → stale-2CHKZTMK.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveStaleOnRead
3
- } from "./chunk-KL7AS3HV.js";
3
+ } from "./chunk-PDD75NUZ.js";
4
4
  import {
5
5
  isManifestReservedCollection
6
6
  } from "./chunk-EPFF7LOX.js";
@@ -19,11 +19,9 @@ import {
19
19
  loadFence
20
20
  } from "./chunk-GM4IM7TC.js";
21
21
  import {
22
- VectorSet,
23
22
  buildPersistedIndexCallbacks,
24
- encodeVecId,
25
23
  syncTierSearch
26
- } from "./chunk-WQF3QABE.js";
24
+ } from "./chunk-IHFXR2VQ.js";
27
25
  import {
28
26
  isBaseLive,
29
27
  liveBaseIdSet
@@ -34,11 +32,6 @@ import {
34
32
  import {
35
33
  NO_ATTESTATION
36
34
  } from "./chunk-Q7HZX3IF.js";
37
- import {
38
- NO_CLASSIFIED,
39
- guardClassifiedCompat,
40
- resolveClassifiedFields
41
- } from "./chunk-KCUIMITG.js";
42
35
  import {
43
36
  NO_TIERS,
44
37
  classifySealedShred,
@@ -71,17 +64,45 @@ import {
71
64
  } from "./chunk-Y4MJQ2UG.js";
72
65
  import {
73
66
  DEFAULT_POSTURE,
67
+ EXPORT_REDACTION_MARKER,
74
68
  ViaGraph,
69
+ ViaPipeline,
75
70
  buildDescription,
71
+ collectKnownFieldNames,
72
+ computedEntryParts,
76
73
  deriveZodFields,
77
- resolveDescribeFieldIds
78
- } from "./chunk-7BE7ZDVQ.js";
74
+ exportRedact,
75
+ guardReconcileCollisions,
76
+ mergeViaFields,
77
+ resolveCollectionConfig,
78
+ resolveComputedEdges,
79
+ resolveDescribeFieldIds,
80
+ resolveVirtualMoneyFields
81
+ } from "./chunk-BWXGSSFX.js";
79
82
  import {
80
83
  findMatchingIdsByPairs
81
84
  } from "./chunk-TFMM5DBB.js";
85
+ import {
86
+ encodeVecId
87
+ } from "./chunk-RTBJ5IOO.js";
88
+ import {
89
+ NO_CLASSIFIED,
90
+ guardClassifiedCompat,
91
+ resolveClassifiedFields
92
+ } from "./chunk-KCUIMITG.js";
82
93
  import {
83
94
  derivePersistedSchema
84
95
  } from "./chunk-URHRIAV6.js";
96
+ import {
97
+ findRollupSpecForIntent,
98
+ forgetDerivedFanout,
99
+ ledgerAuditHook,
100
+ putDerivedOutput,
101
+ resolveRollupDeleteIntents,
102
+ runGraphDispatchWave,
103
+ selfWriteFieldEqual,
104
+ touchFor
105
+ } from "./chunk-MGOXJIBV.js";
85
106
  import {
86
107
  buildLookupAltIndex,
87
108
  buildLookupSnapshotRows,
@@ -90,22 +111,13 @@ import {
90
111
  coerceLookupKey,
91
112
  collectLookupDictCompat,
92
113
  enforceStaticDictOnPut,
93
- findRollupSpecForIntent,
94
- forgetDerivedFanout,
95
- isLookupDescriptor,
96
- ledgerAuditHook,
97
114
  matchesReferencingValue,
98
- putDerivedOutput,
99
115
  registerLookupRefEdges,
100
116
  reservedDictDepsOf,
101
117
  resolveDictSource,
102
118
  resolveLabelFromMap,
103
- resolveRollupDeleteIntents,
104
- runGraphDispatchWave,
105
- selfWriteFieldEqual,
106
- touchFor,
107
119
  updateReferencingRecords
108
- } from "./chunk-SWVNZQVR.js";
120
+ } from "./chunk-YPXNAP72.js";
109
121
  import {
110
122
  OverlayedCollection
111
123
  } from "./chunk-SKGMN35F.js";
@@ -149,7 +161,7 @@ import {
149
161
  InvertedIndex,
150
162
  MemoryIndexStore,
151
163
  NO_SEARCH
152
- } from "./chunk-HN4FNA4X.js";
164
+ } from "./chunk-COTPDJR5.js";
153
165
  import {
154
166
  NO_SEALED_RECORD
155
167
  } from "./chunk-6YXCPL4T.js";
@@ -173,10 +185,11 @@ import {
173
185
  normalizeIndexDefs
174
186
  } from "./chunk-I3ISCYT7.js";
175
187
  import {
176
- IMPLICIT_LAZY,
177
- Lru,
188
+ IMPLICIT_LAZY
189
+ } from "./chunk-66TQOPFM.js";
190
+ import {
178
191
  estimateRecordBytes
179
- } from "./chunk-NO272T7Q.js";
192
+ } from "./chunk-V4PXLYWM.js";
180
193
  import {
181
194
  canonicalGroupKey
182
195
  } from "./chunk-XZHEOSQ2.js";
@@ -196,8 +209,6 @@ import {
196
209
  NO_I18N,
197
210
  getAtPath,
198
211
  isDictCollectionName,
199
- isDictKeyDescriptor,
200
- isI18nTextDescriptor,
201
212
  isStaticDictDescriptor
202
213
  } from "./chunk-TRGTKX5E.js";
203
214
  import {
@@ -321,7 +332,6 @@ import {
321
332
  EchoCeremonyRequiredError,
322
333
  ElevationExpiredError,
323
334
  ExportCapabilityError,
324
- FieldNotQueryableError,
325
335
  ForgetStrategyNotConfiguredError,
326
336
  ImportCapabilityError,
327
337
  IndexWriteFailureError,
@@ -348,7 +358,6 @@ import {
348
358
  USER_ENVELOPE_COLLECTION,
349
359
  UniqueConstraintError,
350
360
  UnsupportedIndexOptionError,
351
- UnsupportedTierCompositionError,
352
361
  ValidationError,
353
362
  isConflictError
354
363
  } from "./chunk-7O3Y4PPD.js";
@@ -604,370 +613,6 @@ function populateCollectionRegistries(r, collectionName, options, effectiveViaFi
604
613
  }
605
614
  }
606
615
 
607
- // src/kernel/via/pipeline.ts
608
- var ViaPipeline = class _ViaPipeline {
609
- constructor(bindings, taint) {
610
- this.bindings = bindings;
611
- this.taint = taint;
612
- const moneyVias = bindings.filter((b) => b.brand === "money");
613
- const computedVias = bindings.filter((b) => b.brand === "computed");
614
- const restBindings = bindings.filter((b) => b.brand !== "money" && b.brand !== "computed");
615
- this._presentOrder = [...moneyVias, ...computedVias, ...restBindings];
616
- this._presentLateBoundary = moneyVias.length + computedVias.length;
617
- }
618
- bindings;
619
- taint;
620
- /**
621
- * Present-phase-ONLY order (#665, corrected under #665 review) — a stable
622
- * THREE-WAY partition of `bindings` computed once here at construction:
623
- * every `'money'`-brand binding first (existing relative order), then
624
- * every `'computed'`-brand binding (existing relative order), then
625
- * everything else (existing relative order). `present()` folds over this
626
- * instead of `bindings` so a `mode: 'virtual'` computed field's value
627
- * exists before i18n/lookup's dressing `present()` hooks run on it
628
- * (today's `compileVias` order is money→i18n→lookup→classified→
629
- * blob→computed, `collection-config.ts:554`, so dressing unconditionally
630
- * ran BEFORE the value it dresses existed). This reorder is binding-level,
631
- * not conditioned on any particular field composition — it applies to
632
- * EVERY collection that compiles a `'computed'` binding at all, not only
633
- * ones stacking a dresser on the SAME field as a computed one. EVERY other
634
- * phase (`ingest`/`encodeWrite`/`encodeAtRest`/`enforceWrite`/etc.) keeps
635
- * folding over `bindings` unchanged — those write/query phases need
636
- * money-first (`_applyMoneyFields` PREPENDS money, `_applyClassifiedFields`
637
- * APPENDS classified to preserve it, `kernel/collection.ts:1275-1284,1364-
638
- * 1368`).
639
- *
640
- * Money is deliberately carved OUT of the generic "everything else" slice
641
- * and kept FIRST — the original two-way `[computed..., rest...]` partition
642
- * regressed money's composed-field behavior from a benign missing-dressing
643
- * gap into VALUE CORRUPTION: money's `present()` DECODES its input as a
644
- * STORED SCALED-INT (and derives `<field>Formatted` from it) — it is not a
645
- * pure dressing CONSUMER like i18n/lookup, which only ADD a `<field>Label`
646
- * key and never rewrite the field's own value. Running money AFTER
647
- * computed on a field composing `computed(virtual)` + `money(...)` on
648
- * ITSELF means money's decode sees the virtual field's raw MAJOR-unit
649
- * output (e.g. `21`) and misreads it as a scaled-int, producing a
650
- * corrupted value (`'0.21'`) instead of the pre-#665 result (the raw `21`
651
- * surviving untouched, with no `Formatted` key added — a benign
652
- * missing-dressing gap, not a wrong value). Money-first restores money's
653
- * exact pre-#665 present position — byte-identical money behavior; the
654
- * materialized composition pins from the #631 work and the money suites
655
- * all ran under money-first. i18n/lookup are genuine dressing consumers
656
- * (they only ADD, never rewrite), so they stay after computed, which is
657
- * the fix #665 intended. A `'taint'` binding (appended LAST by
658
- * `via/graph-wiring.ts#applyTaintOverlay`) stays last here too (it's
659
- * neither money nor computed, so it lands at the tail of the "everything
660
- * else" slice), preserving its "runs after computed, redacts tainted
661
- * virtual output" contract (`via/taint-binding.ts`'s `taintBinding` doc
662
- * comment).
663
- *
664
- * Money-dressing a virtual computed field's OWN output (the composed
665
- * `computed(virtual) + money` case) is NOT resolved by this partition
666
- * alone — #669 resolves it with a separate mid-fold hook instead:
667
- * `NoydbVia.presentLate` runs after every binding's `present()` in this
668
- * money+computed segment, before the "everything else" segment below, so
669
- * money can quantize/reinterpret a virtual field's fresh MAJOR-UNITS
670
- * output as if it were a stored value, without perturbing this ordering
671
- * or the #665 invariant above it (`_presentLateBoundary` below marks
672
- * exactly where that mid-fold point sits within `_presentOrder`).
673
- */
674
- _presentOrder;
675
- /** #669 — index into `_presentOrder` where the money+computed segment ends and the
676
- * "everything else" segment begins (`moneyVias.length + computedVias.length`);
677
- * `present()` runs every binding's `presentLate` at exactly this boundary. */
678
- _presentLateBoundary;
679
- /** undefined when there is nothing to enforce — the zero-via fast path is
680
- * `this.via === undefined` (#553: keeps an all-plain collection sync). A
681
- * `'*'`-defaulted output collection (#642) counts as "something to enforce"
682
- * even with zero field-specific postures and zero bindings. */
683
- static build(bindings, taint) {
684
- if (bindings.length === 0 && (!taint || taint.postures.size === 0 && taint.defaultPosture === void 0)) return void 0;
685
- return new _ViaPipeline(bindings, taint);
686
- }
687
- /** Refuse a write before crypto runs: awaits each binding's `enforceWrite` in order — first throw wins. */
688
- async enforceWrite(record, ctx) {
689
- for (const b of this.bindings) if (b.enforceWrite) await b.enforceWrite(record, ctx);
690
- }
691
- ingest(record) {
692
- let r = record;
693
- for (const b of this.bindings) if (b.ingest) r = b.ingest(r);
694
- return r;
695
- }
696
- canonicalizeStored(record) {
697
- let r = record;
698
- for (const b of this.bindings) if (b.canonicalizeStored) r = b.canonicalizeStored(r);
699
- return r;
700
- }
701
- async encodeWrite(record, ctx) {
702
- let r = record;
703
- for (const b of this.bindings) if (b.encodeWrite) r = await b.encodeWrite(r, ctx);
704
- return r;
705
- }
706
- /**
707
- * Final write-pipeline stage: folds each binding's `encodeAtRest` in
708
- * order, threading the record and accumulating the sealed-slot map. A
709
- * field belongs to exactly one via feature — two bindings sealing the
710
- * same field is a brand-keyed collision and throws.
711
- */
712
- async encodeAtRest(record, crypto) {
713
- let r = record;
714
- let sealed;
715
- const sealedBy = /* @__PURE__ */ new Map();
716
- for (const b of this.bindings) {
717
- if (!b.encodeAtRest) continue;
718
- const result = await b.encodeAtRest(r, crypto);
719
- r = result.record;
720
- if (!result.sealed) continue;
721
- for (const [field, ref2] of Object.entries(result.sealed)) {
722
- const priorBrand = sealedBy.get(field);
723
- if (priorBrand !== void 0) {
724
- throw new ValidationError(
725
- `via encodeAtRest: field "${field}" sealed by binding "${priorBrand}" is also sealed by binding "${b.brand}"`
726
- );
727
- }
728
- sealedBy.set(field, b.brand);
729
- sealed ??= {};
730
- sealed[field] = ref2;
731
- }
732
- }
733
- return sealed ? { record: r, sealed } : { record: r };
734
- }
735
- /** First read-pipeline stage: folds each binding's `decodeAtRest` in order. */
736
- async decodeAtRest(record, sealed, crypto, opts) {
737
- let r = record;
738
- for (const b of this.bindings) if (b.decodeAtRest) r = await b.decodeAtRest(r, sealed, crypto, opts);
739
- return r;
740
- }
741
- async present(record, ctx) {
742
- let r = record;
743
- for (let i = 0; i < this._presentLateBoundary; i++) {
744
- const b = this._presentOrder[i];
745
- if (b.present) r = await b.present(r, ctx);
746
- }
747
- for (const b of this.bindings) if (b.presentLate) r = await b.presentLate(r, ctx);
748
- for (let i = this._presentLateBoundary; i < this._presentOrder.length; i++) {
749
- const b = this._presentOrder[i];
750
- if (b.present) r = await b.present(r, ctx);
751
- }
752
- return r;
753
- }
754
- buildClause(field, op, value) {
755
- for (const b of this.bindings) {
756
- const payload = b.buildClause?.(field, op, value);
757
- if (payload !== void 0) return { brand: b.brand, payload };
758
- }
759
- return void 0;
760
- }
761
- evaluateClause(clause, actual, op) {
762
- const b = this.bindings.find((x) => x.brand === clause.brand);
763
- return b?.evaluateClause ? b.evaluateClause(actual, op, clause.payload) : false;
764
- }
765
- /**
766
- * Resolve a `buildClause` payload to an index-probe operand (#625) —
767
- * mirrors `evaluateClause`'s brand dispatch. `undefined` (a binding
768
- * with no `indexProbe`, or one that declines to probe this op/payload)
769
- * means the caller (`candidateRecords()`) must fall back to a scan.
770
- */
771
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
772
- indexProbe(clause, op) {
773
- const b = this.bindings.find((x) => x.brand === clause.brand);
774
- return b?.indexProbe ? b.indexProbe(op, clause.payload) : void 0;
775
- }
776
- /**
777
- * Resolve a raw STORED field value to its canonical eager-index bucket
778
- * key (#672) — folds every binding's `canonicalizeIndexKey`, first
779
- * non-undefined wins (same fold discipline as `buildClause`). `undefined`
780
- * means no binding claims `field` (or the value can't be canonicalized)
781
- * — the caller buckets the raw stringified value, unchanged from before
782
- * this hook existed.
783
- */
784
- canonicalizeIndexKey(field, rawValue) {
785
- for (const b of this.bindings) {
786
- const key = b.canonicalizeIndexKey?.(field, rawValue);
787
- if (key !== void 0) return key;
788
- }
789
- return void 0;
790
- }
791
- decodeResults(record) {
792
- let r = record;
793
- for (const b of this.bindings) if (b.decodeResults) r = b.decodeResults(r);
794
- return r;
795
- }
796
- /** undefined = no binding covers the field → caller falls back to generic compare. */
797
- compareForOrder(field, a, b) {
798
- for (const bind of this.bindings) {
799
- const c = bind.compareForOrder?.(field, a, b);
800
- if (c !== void 0) return c;
801
- }
802
- return void 0;
803
- }
804
- /** undefined = no binding resolves an order-sort label for `key` at `field`/`locale` (#650 Task 7 —
805
- * the `orderBy(..., {by:'label'})` per-call-locale channel `compareForOrder` above can't serve). */
806
- resolveOrderLabel(field, key, locale) {
807
- for (const bind of this.bindings) {
808
- const label = bind.resolveOrderLabel?.(field, key, locale);
809
- if (label !== void 0) return label;
810
- }
811
- return void 0;
812
- }
813
- /**
814
- * Which posture governs `field`, if any binding covers it — `undefined`
815
- * means no binding declares `field` (the generic, non-via query path
816
- * applies). #629 Task 8's posture consumer: `.where()`/`.orderBy()`
817
- * consult this before building/evaluating a clause, refusing fields whose
818
- * posture is `queryable: 'none'` (e.g. blob); every other posture
819
- * ('det-exact'/'ordered'/'full') is left to the existing per-binding
820
- * buildClause/evaluateClause/compareForOrder machinery, unchanged.
821
- *
822
- * #638 Task 3: the graph-computed taint overlay is consulted FIRST — a
823
- * derived field's assigned (most-restrictive-of-sources) posture wins over
824
- * whatever a binding would otherwise report for that field name (no
825
- * binding covers a computed/derived field today, so this never actually
826
- * shadows one — see `via/taint-binding.ts`'s `taintBinding.covers`, which
827
- * only claims the sealed subset for `encodeAtRest`/`decodeAtRest`, not for
828
- * this lookup).
829
- */
830
- postureFor(field) {
831
- const t = this.taint?.postures.get(field);
832
- if (t) return t;
833
- for (const b of this.bindings) {
834
- if (b.covers?.(field)) return b.posture;
835
- }
836
- return this.taint?.defaultPosture;
837
- }
838
- /**
839
- * Refuse any field-based reducer over a `queryable: 'none'` field (blob) —
840
- * metadata-only: walks each reducer's `.field` and checks posture, no
841
- * rewriting. Reducers with no `.field` (e.g. `count()`) are skipped.
842
- *
843
- * Shared by `wrapReducers` below (which ALSO applies each binding's
844
- * rewrite, e.g. money's exact-BigInt reducer swap) and by
845
- * `ScanBuilder.aggregate()` (#629 Task 8 review fix wave 1), which must
846
- * call THIS, not `wrapReducers` — wiring full `wrapReducers` into
847
- * `ScanBuilder.aggregate()` would newly activate money/i18n reducer
848
- * wrapping on a path that has never run it, a parity-breaking behavior
849
- * change for existing brands.
850
- */
851
- refuseUnqueryableReducers(spec) {
852
- for (const reducer of Object.values(spec)) {
853
- const field = reducer?.field;
854
- if (field !== void 0 && this.postureFor(field)?.queryable === "none") {
855
- throw new FieldNotQueryableError(field);
856
- }
857
- }
858
- }
859
- /**
860
- * Rewrite an aggregate spec (money exact reducers), then refuse any
861
- * field-based reducer over a `queryable: 'none'` field (blob) — the same
862
- * posture gate `.where()`/`.orderBy()` apply, extended to `.aggregate()`
863
- * (both the bare-spec and builder forms funnel through here).
864
- */
865
- wrapReducers(spec) {
866
- this.refuseUnqueryableReducers(spec);
867
- let s = spec;
868
- for (const b of this.bindings) if (b.wrapReducers) s = b.wrapReducers(s);
869
- return s;
870
- }
871
- /**
872
- * Deliberate export-layer redaction (#629 Task 9's posture consumer):
873
- * for every OWN field the decoded record carries, if the covering
874
- * binding's posture declares `exportable: false` (classified today;
875
- * money/i18n/blob are all `true`), replace the value with
876
- * {@link EXPORT_REDACTION_MARKER} — the same `'[sealed]'` string
877
- * `SealedHandle.toJSON()` (`kernel/types.ts`) already emits, so this is
878
- * byte-parity with today's accidental redaction, now independent of the
879
- * field's runtime shape. `SealedHandle.toJSON()` stays untouched as
880
- * defense-in-depth: a record read via `collection.get()` and
881
- * JSON.stringify'd outside `exportStream()` still gets the accident's
882
- * redaction on its own. Never mutates the input; returns a new object
883
- * only when a field was actually redacted.
884
- */
885
- redactForExport(record) {
886
- let out;
887
- for (const field of Object.keys(record)) {
888
- if (this.postureFor(field)?.exportable === false) {
889
- out ??= { ...record };
890
- out[field] = EXPORT_REDACTION_MARKER;
891
- }
892
- }
893
- return out ?? record;
894
- }
895
- /**
896
- * Shared fold over a subset of `this.bindings`: runs each binding's
897
- * `erase`, concatenating shredded/retainedShared counts and residue.
898
- * Consults `posture.forgettable` (#629 Task 10) — a binding declaring
899
- * `forgettable: false` is skipped even if it defines `erase` (none does
900
- * today; a future non-forgettable binding is supported without a brand check).
901
- */
902
- async foldErase(ctx, bindings) {
903
- let shredded = 0;
904
- let retainedShared = 0;
905
- const residue = [];
906
- for (const b of bindings) {
907
- if (!b.erase || b.posture.forgettable === false) continue;
908
- const report = await b.erase(ctx);
909
- shredded += report.shredded;
910
- retainedShared += report.retainedShared ?? 0;
911
- residue.push(...report.residue);
912
- }
913
- return retainedShared > 0 ? { shredded, residue, retainedShared } : { shredded, residue };
914
- }
915
- /** `forget()`'s per-ref erasure door: folds every binding's `erase`. */
916
- async erase(ctx) {
917
- return this.foldErase(ctx, this.bindings);
918
- }
919
- /**
920
- * `forget()`'s SEALED-posture-only erase fold (#629 Task 10, `Collection._onViaErase`'s
921
- * one caller) — classified today; metadata-filtered on
922
- * `posture.encryptedAtRest`, not brand-checked. `undefined` when no
923
- * sealed-posture binding is compiled in — `vault.ts` then falls back to
924
- * its own bare-`sensitive` classification, which no via binding covers.
925
- */
926
- async eraseSealed(ctx) {
927
- const sealed = this.bindings.filter((b) => b.posture.encryptedAtRest === "sealed");
928
- return sealed.length === 0 ? void 0 : this.foldErase(ctx, sealed);
929
- }
930
- /** True iff any binding implements decodeResults (query fast-path gating). */
931
- get hasResultDecode() {
932
- return this.bindings.some((b) => b.decodeResults !== void 0);
933
- }
934
- /**
935
- * True iff any binding declares an at-rest hook (`encodeAtRest`/
936
- * `decodeAtRest`) — the codec boundary's async-stack gate (#629 Task 3
937
- * consults this to choose between the hook path and today's inline
938
- * sealed-slot path; a stack with only sync hooks, e.g. money-only, stays
939
- * `false`).
940
- */
941
- get hasAtRestHooks() {
942
- return this.bindings.some((b) => b.encodeAtRest !== void 0 || b.decodeAtRest !== void 0);
943
- }
944
- /**
945
- * Fold every binding's `describeFragment()` into one `brand -> fragment`
946
- * map (#650 Task 7 — the first-ever consumer; `describeFragment` was
947
- * declared at `via/index.ts:136` since #623 with zero callers until this task).
948
- * `undefined` when no compiled binding implements it. Consumed by
949
- * `Collection.describe()`/`describeAsync()`, threaded to `buildDescription`
950
- * as `BuildDescriptionInput.viaFragments`.
951
- */
952
- describeFragments() {
953
- let out;
954
- for (const b of this.bindings) {
955
- const f = b.describeFragment?.();
956
- if (f !== void 0) {
957
- out ??= {};
958
- out[b.brand] = f;
959
- }
960
- }
961
- return out;
962
- }
963
- };
964
- var EXPORT_REDACTION_MARKER = "[sealed]";
965
- function exportRedact(coll, record) {
966
- if (record === null || typeof record !== "object") return record;
967
- const via2 = coll._via;
968
- return via2 ? via2.redactForExport(record) : record;
969
- }
970
-
971
616
  // src/kernel/lazy-count.ts
972
617
  var COUNT_PAGE_SIZE = 1e3;
973
618
  function isLive(env, storeCiphertext) {
@@ -1679,469 +1324,6 @@ async function commitSequentially(ctx, entries, priors) {
1679
1324
  }
1680
1325
  }
1681
1326
 
1682
- // src/kernel/via/compose.ts
1683
- function via(...descriptors) {
1684
- if (descriptors.length === 0) {
1685
- throw new ValidationError("via(): at least one descriptor is required, e.g. via(money({ currency: 'EUR' }))");
1686
- }
1687
- return { _noydbVia: true, descriptors };
1688
- }
1689
- function isViaFieldSpec(x) {
1690
- return typeof x === "object" && x !== null && x._noydbVia === true;
1691
- }
1692
- function mergeViaFields(sources) {
1693
- for (const field of Object.keys(sources.dictKeyFields ?? {})) {
1694
- if (sources.lookupFields && field in sources.lookupFields) {
1695
- throw new ValidationError(
1696
- `mergeViaFields(): field "${field}" is declared in both \`dictKeyFields\` and \`lookupFields\` \u2014 declare it in one place only.`
1697
- );
1698
- }
1699
- }
1700
- if (!sources.viaFields || Object.keys(sources.viaFields).length === 0) {
1701
- return {
1702
- moneyFields: sources.moneyFields,
1703
- i18nFields: sources.i18nFields,
1704
- dictKeyFields: sources.dictKeyFields,
1705
- computedFields: void 0,
1706
- lookupFields: sources.lookupFields
1707
- };
1708
- }
1709
- const sugarFieldNames = /* @__PURE__ */ new Set([
1710
- ...Object.keys(sources.moneyFields ?? {}),
1711
- ...Object.keys(sources.i18nFields ?? {}),
1712
- ...Object.keys(sources.dictKeyFields ?? {}),
1713
- ...Object.keys(sources.lookupFields ?? {})
1714
- ]);
1715
- const viaMoney = {};
1716
- const viaI18nText = {};
1717
- const viaDictKey = {};
1718
- const viaComputed = {};
1719
- const viaLookup = {};
1720
- for (const [field, spec] of Object.entries(sources.viaFields)) {
1721
- if (sugarFieldNames.has(field)) {
1722
- throw new ValidationError(
1723
- `via(): field "${field}" is declared via both a sugar key and \`viaFields\` \u2014 declare it in one place only.`
1724
- );
1725
- }
1726
- for (const descriptor of spec.descriptors) {
1727
- if (descriptor._viaBrand === "money") {
1728
- viaMoney[field] = descriptor;
1729
- } else if (descriptor._viaBrand === "i18n") {
1730
- if (isI18nTextDescriptor(descriptor)) viaI18nText[field] = descriptor;
1731
- else if (isDictKeyDescriptor(descriptor) || isStaticDictDescriptor(descriptor)) viaDictKey[field] = descriptor;
1732
- } else if (descriptor._viaBrand === "computed") {
1733
- viaComputed[field] = descriptor;
1734
- } else if (descriptor._viaBrand === "lookup" && isLookupDescriptor(descriptor)) {
1735
- viaLookup[field] = descriptor;
1736
- } else {
1737
- throw new ValidationError(`via(): field "${field}" has a descriptor with unrecognized _viaBrand "${descriptor._viaBrand}" \u2014 via() only supports money/i18n/computed/lookup descriptors today.`);
1738
- }
1739
- }
1740
- }
1741
- return {
1742
- moneyFields: Object.keys(viaMoney).length > 0 ? { ...sources.moneyFields ?? {}, ...viaMoney } : sources.moneyFields,
1743
- i18nFields: Object.keys(viaI18nText).length > 0 ? { ...sources.i18nFields ?? {}, ...viaI18nText } : sources.i18nFields,
1744
- dictKeyFields: Object.keys(viaDictKey).length > 0 ? { ...sources.dictKeyFields ?? {}, ...viaDictKey } : sources.dictKeyFields,
1745
- computedFields: Object.keys(viaComputed).length > 0 ? viaComputed : void 0,
1746
- lookupFields: Object.keys(viaLookup).length > 0 ? { ...sources.lookupFields ?? {}, ...viaLookup } : sources.lookupFields
1747
- };
1748
- }
1749
- var VIA_FIELD_MAP_FAMILY = {
1750
- moneyFields: "money",
1751
- i18nFields: "i18n",
1752
- dictKeyFields: "i18n",
1753
- lookupFields: "lookup",
1754
- classifiedFields: "classified",
1755
- blobFields: "blob",
1756
- computed: "computed"
1757
- };
1758
- function guardCrossBindingFieldCollisions(fieldMaps, callerPrefix = "compileVias()") {
1759
- const claimantsByField = /* @__PURE__ */ new Map();
1760
- for (const [sourceKey, map] of Object.entries(fieldMaps)) {
1761
- for (const field of Object.keys(map ?? {})) {
1762
- const claimants = claimantsByField.get(field) ?? /* @__PURE__ */ new Set();
1763
- claimants.add(sourceKey);
1764
- claimantsByField.set(field, claimants);
1765
- }
1766
- }
1767
- for (const [field, sourceKeys] of claimantsByField) {
1768
- const families = new Set([...sourceKeys].map((key) => VIA_FIELD_MAP_FAMILY[key]));
1769
- if (families.size < 2) continue;
1770
- if (sourceKeys.size === 2 && families.has("computed")) {
1771
- const other = [...families].find((f) => f !== "computed");
1772
- if (other === "money" || other === "i18n" || other === "lookup") continue;
1773
- }
1774
- const keys = [...sourceKeys].sort().map((k) => `\`${k}\``);
1775
- const joined = keys.length === 2 ? keys.join(" and ") : `${keys.slice(0, -1).join(", ")}, and ${keys[keys.length - 1]}`;
1776
- throw new ValidationError(
1777
- `${callerPrefix}: field "${field}" is declared in both ${joined} \u2014 a field cannot be claimed by two different via-binding families. Declare it in one place only.`
1778
- );
1779
- }
1780
- }
1781
- function guardReconcileCollisions(existingVia, incomingFieldMaps) {
1782
- guardCrossBindingFieldCollisions(incomingFieldMaps, "guardReconcileCollisions()");
1783
- if (!existingVia) return;
1784
- const existingBindings = existingVia.bindings.filter((b) => b.brand !== "taint");
1785
- for (const [sourceKey, map] of Object.entries(incomingFieldMaps)) {
1786
- const incomingFamily = VIA_FIELD_MAP_FAMILY[sourceKey];
1787
- if (incomingFamily === void 0) continue;
1788
- for (const field of Object.keys(map ?? {})) {
1789
- const existingFamilies = new Set(
1790
- existingBindings.filter((b) => b.covers?.(field)).map((b) => b.brand)
1791
- );
1792
- for (const existingFamily of existingFamilies) {
1793
- if (existingFamily === incomingFamily) continue;
1794
- const isExempt = existingFamily === "computed" && (incomingFamily === "money" || incomingFamily === "i18n" || incomingFamily === "lookup") || incomingFamily === "computed" && (existingFamily === "money" || existingFamily === "i18n" || existingFamily === "lookup");
1795
- if (isExempt) continue;
1796
- throw new ValidationError(
1797
- `vault.collection(): field "${field}" is already bound by the "${existingFamily}" via family on this collection \u2014 an incoming \`${sourceKey}\` declaration cannot claim it for a different family ("${incomingFamily}"). Declare it in one place only.`
1798
- );
1799
- }
1800
- }
1801
- }
1802
- }
1803
-
1804
- // src/kernel/collection-config.ts
1805
- function computedEntryParts(entry) {
1806
- if (typeof entry === "function") return { fn: entry, mode: "materialized" };
1807
- return { fn: entry.fn, ...entry.deps !== void 0 ? { deps: entry.deps } : {}, mode: entry.mode ?? "materialized" };
1808
- }
1809
- function unifyComputedFields(opts, viaComputedFields) {
1810
- return { ...opts.computed ?? {}, ...viaComputedFields ?? {} };
1811
- }
1812
- function compileVias(opts, classifiedGuardCtx, eraseCfgOut) {
1813
- const { moneyFields, i18nFields, dictKeyFields, computedFields, lookupFields } = mergeViaFields(opts);
1814
- const allComputedFields = unifyComputedFields(opts, computedFields);
1815
- guardCrossBindingFieldCollisions({
1816
- moneyFields,
1817
- i18nFields,
1818
- dictKeyFields,
1819
- lookupFields,
1820
- classifiedFields: opts.classifiedFields !== void 0 ? resolveClassifiedFields(opts.name, opts.classifiedFields).byField : void 0,
1821
- blobFields: opts.blobFields,
1822
- computed: allComputedFields
1823
- });
1824
- const bindings = [];
1825
- const virtualFields = /* @__PURE__ */ new Map();
1826
- for (const [field, entry] of Object.entries(allComputedFields)) {
1827
- const parts = computedEntryParts(entry);
1828
- if (parts.mode === "virtual") {
1829
- virtualFields.set(field, { _viaBrand: "computed", fn: parts.fn, mode: "virtual", ...parts.deps !== void 0 ? { deps: parts.deps } : {} });
1830
- }
1831
- }
1832
- if (moneyFields) {
1833
- const virtualMoney = resolveVirtualMoneyFields(Object.keys(moneyFields), (f) => virtualFields.has(f));
1834
- bindings.push(viaBinder("money")({ moneyFields, ...virtualMoney.size > 0 ? { virtualMoneyFields: virtualMoney } : {} }));
1835
- }
1836
- if (i18nFields || dictKeyFields) {
1837
- const densify = i18nFields ? Object.fromEntries(
1838
- Object.entries(i18nFields).filter(([, d]) => d.options.densifyOnWrite === true)
1839
- ) : {};
1840
- const i18nDensifyFields = Object.keys(densify).length > 0 ? densify : void 0;
1841
- bindings.push(viaBinder("i18n")({
1842
- ...i18nFields !== void 0 ? { i18nFields } : {},
1843
- ...dictKeyFields !== void 0 ? { dictKeyFields } : {},
1844
- ...i18nDensifyFields !== void 0 ? { i18nDensifyFields } : {},
1845
- strategy: opts.strategies.i18n,
1846
- ...opts.defaultLocale !== void 0 ? { defaultLocale: opts.defaultLocale } : {},
1847
- ...opts.autoTranslateHook !== void 0 ? { autoTranslateHook: opts.autoTranslateHook } : {},
1848
- ...opts.dictLabelResolver !== void 0 ? { dictLabelResolver: opts.dictLabelResolver } : {},
1849
- ...opts.i18nPutValidator !== void 0 ? { i18nPutValidator: opts.i18nPutValidator } : {},
1850
- collectionName: opts.name
1851
- }));
1852
- }
1853
- if (lookupFields !== void 0) {
1854
- bindings.push(viaBinder("lookup")({
1855
- lookupFields,
1856
- ...opts.lookupLabelResolver !== void 0 ? { lookupLabelResolver: opts.lookupLabelResolver } : {},
1857
- ...opts.getLookupBacking !== void 0 ? { getLookupBacking: opts.getLookupBacking } : {},
1858
- ...opts.membership !== void 0 ? { membership: opts.membership } : {},
1859
- ...opts.getAltIndex !== void 0 ? { getAltIndex: opts.getAltIndex } : {},
1860
- ...opts.snapshotFor !== void 0 ? { snapshotFor: opts.snapshotFor } : {},
1861
- collectionName: opts.name
1862
- }));
1863
- }
1864
- if (opts.classifiedFields !== void 0) {
1865
- const classifiedCfg = {
1866
- entries: opts.classifiedFields,
1867
- collectionName: opts.name,
1868
- guardCtx: classifiedGuardCtx
1869
- };
1870
- if (eraseCfgOut) eraseCfgOut.classified = classifiedCfg;
1871
- bindings.push(viaBinder("classified")(classifiedCfg));
1872
- }
1873
- if (opts.blobFields !== void 0) {
1874
- bindings.push(viaBinder("blob")({
1875
- fields: opts.blobFields,
1876
- collectionName: opts.name
1877
- }));
1878
- }
1879
- if (virtualFields.size > 0) {
1880
- bindings.push(viaBinder("computed")({ virtualFields }));
1881
- }
1882
- return bindings;
1883
- }
1884
- function resolveVirtualMoneyFields(moneyFieldNames, isVirtual) {
1885
- const out = /* @__PURE__ */ new Set();
1886
- for (const field of moneyFieldNames) if (isVirtual(field)) out.add(field);
1887
- return out;
1888
- }
1889
- function collectKnownFieldNames(parts) {
1890
- return /* @__PURE__ */ new Set([
1891
- ...Object.keys(parts.moneyFields ?? {}),
1892
- ...Object.keys(parts.i18nFields ?? {}),
1893
- ...Object.keys(parts.dictKeyFields ?? {}),
1894
- ...Object.keys(parts.classifiedFields ?? {}),
1895
- ...Object.keys(parts.computed ?? {}),
1896
- ...Object.keys(parts.lookupFields ?? {})
1897
- ]);
1898
- }
1899
- var EMPTY_KNOWN_FIELDS = /* @__PURE__ */ new Set();
1900
- function resolveComputedEdges(collectionName, computed, hasClassifiedFields, knownFields = EMPTY_KNOWN_FIELDS) {
1901
- if (!computed) return [];
1902
- const edges = [];
1903
- for (const [field, entry] of Object.entries(computed)) {
1904
- const parts = computedEntryParts(entry);
1905
- const deps = parts.deps;
1906
- if (deps === void 0) {
1907
- if (hasClassifiedFields) {
1908
- throw new ValidationError(
1909
- `Collection "${collectionName}": computed field "${field}" has no declared \`deps\` and the collection declares classified fields \u2014 an opaque computed function could silently copy a classified field's plaintext into an ordinary, unredacted field. Declare \`deps\` naming the source fields it reads, e.g. computed: { ${field}: { fn, deps: [...] } } or via(computed(fn, { deps: [...] })).`
1910
- );
1911
- }
1912
- continue;
1913
- }
1914
- if (deps.length === 0) {
1915
- throw new ValidationError(`Collection "${collectionName}": computed field "${field}"'s \`deps\` must be non-empty.`);
1916
- }
1917
- for (const dep of deps) {
1918
- if (typeof dep !== "string" || dep.length === 0) {
1919
- throw new ValidationError(`Collection "${collectionName}": computed field "${field}"'s \`deps\` entries must be non-empty strings.`);
1920
- }
1921
- if (hasClassifiedFields && !knownFields.has(dep)) {
1922
- throw new ValidationError(
1923
- `Collection "${collectionName}": computed field "${field}"'s \`deps\` entry "${dep}" does not name a declared field, and the collection declares classified fields \u2014 an opaque computed function could silently copy a classified field's plaintext into an ordinary, unredacted field via a mistyped/unknown dep name. Declare \`deps\` naming only known fields (money/i18n/dictKey/classified/computed) \u2014 check "${dep}" for a typo.`
1924
- );
1925
- }
1926
- }
1927
- edges.push({
1928
- target: { collection: collectionName, field },
1929
- sources: deps.map((d) => ({ collection: collectionName, field: d })),
1930
- grain: parts.mode === "virtual" ? "virtual" : "record"
1931
- });
1932
- }
1933
- return edges;
1934
- }
1935
- function resolveViaDepsEdges(collectionName, bindings, knownFields) {
1936
- const edges = [];
1937
- for (const binding of bindings) {
1938
- if (!binding.deps || binding.deps.length === 0) continue;
1939
- for (const dep of binding.deps) {
1940
- if (!knownFields.has(dep)) {
1941
- throw new ValidationError(
1942
- `Collection "${collectionName}": via binding "${binding.brand}" deps references undeclared field "${dep}".`
1943
- );
1944
- }
1945
- }
1946
- const sources = binding.deps.map((d) => ({ collection: collectionName, field: d }));
1947
- for (const field of knownFields) {
1948
- if (binding.covers?.(field)) edges.push({ target: { collection: collectionName, field }, sources });
1949
- }
1950
- }
1951
- return edges;
1952
- }
1953
- function resolveCollectionConfig(opts) {
1954
- if (opts.embeddings && opts.crdt) {
1955
- throw new Error(
1956
- `Collection "${opts.name}": embeddings are not supported on CRDT collections (L2). Use a non-CRDT collection for semantic search.`
1957
- );
1958
- }
1959
- if (opts.sensitive && opts.sensitive.length > 0 && opts.crdt) {
1960
- throw new Error(
1961
- `Collection "${opts.name}": sensitive (structural group-encryption) is not supported on CRDT collections \u2014 the CRDT write path bypasses per-field sealing, so the fields would be stored in the ordinary encrypted body with no \`_sealed\` slot and no per-field key. Use a non-CRDT collection for sealed fields.`
1962
- );
1963
- }
1964
- if (opts.tiers && opts.tiers.length > 0 && opts.blobFields !== void 0 && Object.keys(opts.blobFields).length > 0 && opts.perRecordKeys !== true) {
1965
- throw new UnsupportedTierCompositionError(
1966
- "blobs",
1967
- `Collection "${opts.name}": tiered collections that declare blobFields require \`perRecordKeys: true\` \u2014 legacy (non-perRecordKeys) blobs have no per-blob content CEK and cannot be tier-isolated on elevate/demote.`
1968
- );
1969
- }
1970
- if (opts.tiers && opts.tiers.length > 0 && opts.blobFields !== void 0) {
1971
- for (const [field, policy] of Object.entries(opts.blobFields)) {
1972
- if (policy?.external && policy.public === true) {
1973
- throw new UnsupportedTierCompositionError(
1974
- "blobs",
1975
- `Collection "${opts.name}": blob field "${field}" cannot be both \`external: true, public: true\` and declared on a tiered collection \u2014 the object key is deterministic and its bytes are world-readable by design, so tier-invisibility can never be enforced for it once elevated. Use a private/presigned external field (\`public\` omitted or \`false\`) or move this field to a non-tiered collection.`
1976
- );
1977
- }
1978
- }
1979
- }
1980
- if (opts.tiers && opts.tiers.length > 0 && opts.encrypted === false) {
1981
- throw new UnsupportedTierCompositionError(
1982
- "plaintext",
1983
- `Collection "${opts.name}": tiers are per-tier ENCRYPTION keys \u2014 a plaintext collection (\`encrypted: false\`) has nothing to re-key, so \`putAtTier\`/\`elevate\` would encrypt/decrypt incoherently. Use an encrypted collection.`
1984
- );
1985
- }
1986
- if (opts.tiers && opts.tiers.length > 0 && opts.crdt !== void 0 && ((opts.derivationSource?.registry().strategiesForSource(opts.name).length ?? 0) > 0 || (opts.materializedViewSource?.registry().mvsForSource(opts.name).length ?? 0) > 0)) {
1987
- throw new UnsupportedTierCompositionError(
1988
- "crdt-derivation",
1989
- `Collection "${opts.name}": tiers + crdt cannot be combined with this collection acting as a derivation/rollup source (#739) \u2014 the tier-aware pre-move decode \`syncDerived\` uses on elevate()/demote() does not resolve CRDT state, so a registered derivation/rollup reads raw CrdtState instead of the record and silently no-ops. Use a non-CRDT collection for a tiered derivation/rollup source, or move the derivation off this collection.`
1990
- );
1991
- }
1992
- const effectiveViaFields = mergeViaFields(opts);
1993
- const resolvedClassified = opts.classifiedFields !== void 0 ? resolveClassifiedFields(opts.name, opts.classifiedFields) : void 0;
1994
- const allComputed = unifyComputedFields(opts, effectiveViaFields.computedFields);
1995
- const materializedComputed = {};
1996
- for (const [field, entry] of Object.entries(allComputed)) {
1997
- if (computedEntryParts(entry).mode !== "virtual") materializedComputed[field] = entry;
1998
- }
1999
- let mergedComputed = Object.keys(materializedComputed).length > 0 ? materializedComputed : void 0;
2000
- if (resolvedClassified !== void 0) {
2001
- for (const key of Object.keys(allComputed)) {
2002
- if (resolvedClassified.riderComputed[key] !== void 0) {
2003
- throw new ClassifiedConfigError(opts.name, `computed field "${key}" collides with a rider companion`);
2004
- }
2005
- }
2006
- mergedComputed = { ...resolvedClassified.riderComputed, ...materializedComputed };
2007
- }
2008
- let deterministicFields;
2009
- if (opts.deterministicFields && opts.deterministicFields.length > 0) {
2010
- if (opts.acknowledgeDeterministicRisk !== true) {
2011
- throw new Error(
2012
- `Collection "${opts.name}": deterministicFields requires \`acknowledgeDeterministicRisk: true\`. Deterministic encryption leaks equality between records \u2014 two records with the same field value produce identical ciphertexts visible to anyone with store access. If that trade-off is acceptable for your threat model, set \`acknowledgeDeterministicRisk: true\` to enable.`
2013
- );
2014
- }
2015
- deterministicFields = Object.freeze(new Set(opts.deterministicFields));
2016
- } else {
2017
- deterministicFields = null;
2018
- }
2019
- const guardIndexedFields = /* @__PURE__ */ new Set();
2020
- for (const ix of opts.indexes ?? []) {
2021
- if (typeof ix === "string") guardIndexedFields.add(ix);
2022
- else if (Array.isArray(ix)) for (const f of ix) guardIndexedFields.add(f);
2023
- else for (const f of ix.fields) guardIndexedFields.add(f);
2024
- }
2025
- const embeddingSources = opts.embeddings === void 0 ? [] : typeof opts.embeddings.source === "string" ? [opts.embeddings.source] : [...opts.embeddings.source];
2026
- const classifiedGuardCtx = {
2027
- perRecordKeys: opts.perRecordKeys === true,
2028
- crdt: opts.crdt !== void 0,
2029
- hasConflictPolicy: opts.conflictPolicy !== void 0,
2030
- storeCiphertext: opts.encrypted,
2031
- deterministicFields,
2032
- indexedFields: guardIndexedFields,
2033
- textIndexFields: new Set(opts.textIndexes ?? []),
2034
- vectorSourceFields: new Set(embeddingSources),
2035
- subjectKeyField: opts.subjectKeyField,
2036
- bareSensitiveFields: new Set(opts.sensitive ?? []),
2037
- acknowledgeEquatableRisk: opts.acknowledgeEquatableRisk === true
2038
- };
2039
- if (resolvedClassified !== void 0) {
2040
- guardClassifiedCompat(opts.name, resolvedClassified.byField, classifiedGuardCtx);
2041
- }
2042
- const classifiedSensitive = resolvedClassified === void 0 ? [] : Object.entries(resolvedClassified.byField).filter(([, s]) => s.storage === "recoverable").map(([f]) => f);
2043
- const sensitiveList = [...opts.sensitive ?? [], ...classifiedSensitive];
2044
- const sensitiveFields = sensitiveList.length > 0 ? Object.freeze(new Set(sensitiveList)) : Object.freeze(/* @__PURE__ */ new Set());
2045
- const vdigEntries = resolvedClassified === void 0 ? [] : Object.entries(resolvedClassified.byField).filter(([, s]) => s.storage === "digest-only").map(([f, s]) => [f, {
2046
- normalize: s.verifyNormalize ?? "password",
2047
- notLastN: s.notLastN ?? 0,
2048
- equatable: s.equatable === true,
2049
- ...s.rotateDays !== void 0 ? { rotateDays: s.rotateDays } : {}
2050
- }]);
2051
- const vdigFields = vdigEntries.length > 0 ? new Map(vdigEntries) : null;
2052
- const perRecordCek = opts.perRecordKeys === true;
2053
- const cekCache = perRecordCek ? new Lru({ maxRecords: 4096 }) : null;
2054
- const viaEraseCfgOut = {};
2055
- const via2 = ViaPipeline.build(compileVias(opts, classifiedGuardCtx, viaEraseCfgOut));
2056
- const knownFields = collectKnownFieldNames({
2057
- moneyFields: effectiveViaFields.moneyFields,
2058
- i18nFields: effectiveViaFields.i18nFields,
2059
- dictKeyFields: effectiveViaFields.dictKeyFields,
2060
- classifiedFields: resolvedClassified?.byField,
2061
- computed: allComputed,
2062
- lookupFields: effectiveViaFields.lookupFields
2063
- });
2064
- const computedEdges = resolveComputedEdges(opts.name, allComputed, resolvedClassified !== void 0, knownFields);
2065
- const viaDepsEdges = resolveViaDepsEdges(opts.name, via2?.bindings ?? [], knownFields);
2066
- return {
2067
- adapter: opts.adapter,
2068
- vault: opts.vault,
2069
- name: opts.name,
2070
- keyring: opts.keyring,
2071
- storeCiphertext: opts.encrypted,
2072
- ramCiphertext: opts.ramCiphertext ?? false,
2073
- emitter: opts.emitter,
2074
- writeQueue: opts.writeQueue,
2075
- schemaUpdateGate: opts.schemaUpdateGate,
2076
- schemaFence: opts.schemaFence,
2077
- writeHooks: opts.writeHooks,
2078
- subsystemBus: opts.subsystemBus,
2079
- activeTxId: opts.activeTxId,
2080
- strategies: opts.strategies,
2081
- objectStore: opts.objectStore,
2082
- blobFields: opts.blobFields,
2083
- reconcileOnOpen: opts.reconcileOnOpen ?? "off",
2084
- getDEK: opts.getDEK,
2085
- onDirty: opts.onDirty,
2086
- tabCoordinated: opts.tabCoordinated,
2087
- historyConfig: opts.historyConfig ?? { enabled: true },
2088
- historyConfigExplicit: opts.historyConfigExplicit ?? false,
2089
- schema: opts.schema,
2090
- ledger: opts.ledger,
2091
- refEnforcer: opts.refEnforcer,
2092
- joinResolver: opts.joinResolver,
2093
- i18nFields: effectiveViaFields.i18nFields,
2094
- textIndexes: opts.textIndexes,
2095
- embeddings: opts.embeddings,
2096
- vectorSet: opts.embeddings ? new VectorSet() : void 0,
2097
- dictKeyFields: effectiveViaFields.dictKeyFields,
2098
- lookupFields: effectiveViaFields.lookupFields,
2099
- // #650 Task 6 — the sync join-dressing hook (#626 retirement, spec §5);
2100
- // `undefined` when this collection declares neither i18nText nor lookup
2101
- // fields, matching today's `i18nFields`-absent JoinableSource shape.
2102
- presentForJoin: buildPresentForJoin(effectiveViaFields.i18nFields, effectiveViaFields.lookupFields, opts.snapshotFor),
2103
- fieldMeta: opts.fieldMeta,
2104
- meta: opts.meta,
2105
- _refs: opts.declaredRefs ?? {},
2106
- via: via2,
2107
- classifiedEraseCfg: viaEraseCfgOut.classified,
2108
- moneyFields: effectiveViaFields.moneyFields,
2109
- classified: resolvedClassified,
2110
- classifiedGuardCtx,
2111
- computed: mergedComputed,
2112
- computedEdges,
2113
- viaDepsEdges,
2114
- // #638 Task 7 — every declared computed field name (both modes, both surfaces); the
2115
- // reconcile path's cross-call depsless-computed leak-guard memory
2116
- // (`via/graph-wiring.ts#registerCollectionGraphSources`) reads this instead of
2117
- // `Object.keys(opts.computed ?? {})` alone, so a via(computed(...))-declared field
2118
- // participates in that guard identically to a sugar-declared one.
2119
- computedFieldNames: Object.keys(allComputed),
2120
- dictLabelResolver: opts.dictLabelResolver,
2121
- getDictionary: opts.getDictionary,
2122
- i18nPutValidator: opts.i18nPutValidator,
2123
- autoTranslateHook: opts.autoTranslateHook,
2124
- defaultLocale: opts.defaultLocale,
2125
- crdtMode: opts.crdt,
2126
- syncAdapter: opts.syncAdapter,
2127
- onAccess: opts.onAccess,
2128
- derivationSource: opts.derivationSource,
2129
- materializedViewSource: opts.materializedViewSource,
2130
- graphDispatch: opts.graphDispatch,
2131
- tiers: opts.tiers && opts.tiers.length > 0 ? new Set(opts.tiers) : null,
2132
- tierMode: opts.tierMode ?? "invisibility",
2133
- blobTierPolicy: opts.blobTierPolicy ?? "isolate",
2134
- onCrossTierAccess: opts.onCrossTierAccess,
2135
- addSubjectRef: opts.addSubjectRef,
2136
- deterministicFields,
2137
- sensitiveFields,
2138
- vdigFields,
2139
- perRecordCek,
2140
- cekCache,
2141
- provenance: opts.provenance === true
2142
- };
2143
- }
2144
-
2145
1327
  // src/with-formula/computed/lazy.ts
2146
1328
  var loadComputed = lazy(() => import("./computed-LSEZYRJS.js"));
2147
1329
  async function loadEvalComputedFields() {
@@ -3140,7 +2322,7 @@ var Collection = class {
3140
2322
  }
3141
2323
  }
3142
2324
  if (this.materializedViewSource !== void 0) {
3143
- const { resolveStaleMVOnRead } = await import("./stale-KSPG6LFX.js");
2325
+ const { resolveStaleMVOnRead } = await import("./stale-2CHKZTMK.js");
3144
2326
  await resolveStaleMVOnRead(this.materializedViewSource, this.name, this.#dispatchCtx({ collection: this.name, id: "resolve-on-read" }));
3145
2327
  }
3146
2328
  let record;
@@ -3672,7 +2854,7 @@ var Collection = class {
3672
2854
  */
3673
2855
  async dispatchMaterializedViews(id, record, wave) {
3674
2856
  if (this.materializedViewSource === void 0) return;
3675
- const { dispatchMaterializedViews } = await import("./dispatch-44J4TL72.js");
2857
+ const { dispatchMaterializedViews } = await import("./dispatch-PDP5TA73.js");
3676
2858
  return dispatchMaterializedViews(this.#mvDispatchCtx(this.materializedViewSource), id, record, wave);
3677
2859
  }
3678
2860
  /**
@@ -3838,13 +3020,13 @@ var Collection = class {
3838
3020
  * dispatch wave's per-target dedup; `undefined` on the local-write path (byte-identical). */
3839
3021
  async dispatchDerivations(id, record, version, wave, prior) {
3840
3022
  if (this.derivationSource === void 0) return;
3841
- const { dispatchDerivations } = await import("./dispatch-XEBHUGBV.js");
3023
+ const { dispatchDerivations } = await import("./dispatch-MSTR5VBI.js");
3842
3024
  return dispatchDerivations(this.#derivationDispatchCtx(), id, record, version, wave, prior);
3843
3025
  }
3844
3026
  /** @internal — trigger fan-out for a deleted parent (#1249); see dispatch.ts. */
3845
3027
  async dispatchTriggerDerivationsOnDelete(id, deleted) {
3846
3028
  if (this.derivationSource === void 0) return;
3847
- const { dispatchTriggerDerivationsOnDelete } = await import("./dispatch-XEBHUGBV.js");
3029
+ const { dispatchTriggerDerivationsOnDelete } = await import("./dispatch-MSTR5VBI.js");
3848
3030
  return dispatchTriggerDerivationsOnDelete(this.#derivationDispatchCtx(), id, deleted);
3849
3031
  }
3850
3032
  /**
@@ -4156,7 +3338,7 @@ var Collection = class {
4156
3338
  */
4157
3339
  async dispatchArrayDerivationsOnDelete(id, eraseRecordShapeToo = false) {
4158
3340
  if (this.derivationSource === void 0) return 0;
4159
- const { dispatchArrayDerivationsOnDelete } = await import("./dispatch-XEBHUGBV.js");
3341
+ const { dispatchArrayDerivationsOnDelete } = await import("./dispatch-MSTR5VBI.js");
4160
3342
  return dispatchArrayDerivationsOnDelete(this.#derivationDeleteCtx(this.derivationSource), id, eraseRecordShapeToo);
4161
3343
  }
4162
3344
  /**
@@ -4170,7 +3352,7 @@ var Collection = class {
4170
3352
  */
4171
3353
  async dispatchMaterializedViewsOnDelete(id) {
4172
3354
  if (this.materializedViewSource === void 0) return { deleted: 0, residueUndecodable: [], residueDeclined: [] };
4173
- const { dispatchMaterializedViewsOnDelete } = await import("./dispatch-44J4TL72.js");
3355
+ const { dispatchMaterializedViewsOnDelete } = await import("./dispatch-PDP5TA73.js");
4174
3356
  return dispatchMaterializedViewsOnDelete(this.#mvDispatchCtx(this.materializedViewSource), id);
4175
3357
  }
4176
3358
  /**
@@ -4190,7 +3372,7 @@ var Collection = class {
4190
3372
  );
4191
3373
  }
4192
3374
  if (this.materializedViewSource !== void 0) {
4193
- const { resolveStaleMVOnRead } = await import("./stale-KSPG6LFX.js");
3375
+ const { resolveStaleMVOnRead } = await import("./stale-2CHKZTMK.js");
4194
3376
  await resolveStaleMVOnRead(this.materializedViewSource, this.name, this.#dispatchCtx({ collection: this.name, id: "resolve-on-read" }));
4195
3377
  }
4196
3378
  await this.ensureHydrated();
@@ -8621,7 +7803,7 @@ var Vault = class {
8621
7803
  // Vaults without derivations skip this so `Collection.put`'s
8622
7804
  // `if (this.derivationSource)` branch no-ops without touching the
8623
7805
  // derivation service code.
8624
- ...this.derivationRegistry !== null ? (this.derivationRegistry.validateFieldsFor(collectionName, options?.schema, Object.keys({ ...options?.fieldMeta, ...options?.moneyFields, ...options?.dictKeyFields, ...options?.refs, ...options?.computed, ...options?.i18nFields, ...options?.lookupFields, ...options?.blobFields, ...options?.classifiedFields })), {
7806
+ ...this.derivationRegistry !== null ? (this.derivationRegistry.validateFieldsFor(collectionName, options?.schema, Object.keys({ ...options?.fieldMeta, ...options?.moneyFields, ...options?.dictKeyFields, ...options?.refs, ...options?.computed, ...options?.i18nFields, ...options?.lookupFields, ...options?.blobFields, ...options?.classifiedFields }), options), {
8625
7807
  derivationSource: {
8626
7808
  registry: () => this.derivationRegistry,
8627
7809
  getCollection: (name) => this.collection(name),
@@ -9904,7 +9086,7 @@ var Vault = class {
9904
9086
  async _initDerivations(handles) {
9905
9087
  if (handles.length === 0) return;
9906
9088
  const [{ DerivationRegistry }, { ReadOnlyVaultFacade }] = await Promise.all([
9907
- import("./registry-BZQIVNNO.js"),
9089
+ import("./registry-D2YXKRYC.js"),
9908
9090
  import("./read-only-facade-CHCKSEPD.js")
9909
9091
  ]);
9910
9092
  const registry = new DerivationRegistry();
@@ -10024,14 +9206,14 @@ var Vault = class {
10024
9206
  if (!reg) {
10025
9207
  throw new Error(`refreshView: no MV registered with name "${name}"`);
10026
9208
  }
10027
- const { MaterializedViewExecutor } = await import("./executor-KSPGNVDO.js");
9209
+ const { MaterializedViewExecutor } = await import("./executor-YDDC5XGY.js");
10028
9210
  const result = await MaterializedViewExecutor.refresh(reg, {
10029
9211
  getCollection: (n) => this.collection(n),
10030
9212
  getActiveTxContext: () => this.noydb._activeTxContextOrNull,
10031
9213
  getQueryContext: () => this,
10032
9214
  dispatchCtx: this._dispatchCtx({ collection: name, id: "refreshView" })
10033
9215
  });
10034
- const { clearMVStaleFully } = await import("./stale-KSPG6LFX.js");
9216
+ const { clearMVStaleFully } = await import("./stale-2CHKZTMK.js");
10035
9217
  await clearMVStaleFully(this.adapter, this.name, registry, name);
10036
9218
  return result;
10037
9219
  }
@@ -14334,8 +13516,6 @@ function normalizeSyncTargets(sync) {
14334
13516
  export {
14335
13517
  memoryStore,
14336
13518
  withArchive,
14337
- via,
14338
- isViaFieldSpec,
14339
13519
  Collection,
14340
13520
  ELEVATION_AUDIT_COLLECTION,
14341
13521
  ElevatedHandle,
@@ -14350,4 +13530,4 @@ export {
14350
13530
  Noydb,
14351
13531
  createNoydb
14352
13532
  };
14353
- //# sourceMappingURL=chunk-XMF3GKUR.js.map
13533
+ //# sourceMappingURL=chunk-ZVCC36XQ.js.map