@noy-db/hub 0.1.0-pre.9 → 0.2.0-pre.1

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 (253) hide show
  1. package/dist/aggregate/index.cjs +91 -36
  2. package/dist/aggregate/index.cjs.map +1 -1
  3. package/dist/aggregate/index.d.cts +2 -2
  4. package/dist/aggregate/index.d.ts +2 -2
  5. package/dist/aggregate/index.js +16 -9
  6. package/dist/aggregate/index.js.map +1 -1
  7. package/dist/blobs/index.cjs.map +1 -1
  8. package/dist/blobs/index.d.cts +6 -6
  9. package/dist/blobs/index.d.ts +6 -6
  10. package/dist/blobs/index.js +4 -4
  11. package/dist/bundle/index.cjs +298 -7
  12. package/dist/bundle/index.cjs.map +1 -1
  13. package/dist/bundle/index.d.cts +6 -6
  14. package/dist/bundle/index.d.ts +6 -6
  15. package/dist/bundle/index.js +15 -4
  16. package/dist/{chunk-GOUT6DND.js → chunk-23TTQXVO.js} +173 -91
  17. package/dist/chunk-23TTQXVO.js.map +1 -0
  18. package/dist/{chunk-CIMZBAZB.js → chunk-2AXFIYHT.js} +1 -1
  19. package/dist/chunk-2AXFIYHT.js.map +1 -0
  20. package/dist/chunk-34YSDCDP.js +73 -0
  21. package/dist/chunk-34YSDCDP.js.map +1 -0
  22. package/dist/{chunk-AVVPZ4BC.js → chunk-4TFSM22V.js} +4 -4
  23. package/dist/{chunk-QGZRWRSL.js → chunk-537VFZTR.js} +4 -4
  24. package/dist/{chunk-M62XNWRA.js → chunk-5DWL3JBF.js} +2 -2
  25. package/dist/{chunk-PTVMYYON.js → chunk-5SCJ5UEF.js} +3 -3
  26. package/dist/chunk-5ZGZ6HIZ.js +100 -0
  27. package/dist/chunk-5ZGZ6HIZ.js.map +1 -0
  28. package/dist/chunk-6HPZY4ON.js +291 -0
  29. package/dist/chunk-6HPZY4ON.js.map +1 -0
  30. package/dist/{chunk-EXHNQEV4.js → chunk-7H6DOO3E.js} +239 -11
  31. package/dist/chunk-7H6DOO3E.js.map +1 -0
  32. package/dist/{chunk-ACLDOTNQ.js → chunk-ADQ5MQ54.js} +275 -3
  33. package/dist/chunk-ADQ5MQ54.js.map +1 -0
  34. package/dist/chunk-CBAHB2BF.js +893 -0
  35. package/dist/chunk-CBAHB2BF.js.map +1 -0
  36. package/dist/chunk-DPMFBCV6.js +296 -0
  37. package/dist/chunk-DPMFBCV6.js.map +1 -0
  38. package/dist/chunk-DYBQG5PQ.js +34 -0
  39. package/dist/chunk-DYBQG5PQ.js.map +1 -0
  40. package/dist/{chunk-ZFKD4QMV.js → chunk-DYECX3IX.js} +3 -3
  41. package/dist/chunk-EGQYGYIU.js +51 -0
  42. package/dist/chunk-EGQYGYIU.js.map +1 -0
  43. package/dist/chunk-FCXOFQAJ.js +79 -0
  44. package/dist/chunk-FCXOFQAJ.js.map +1 -0
  45. package/dist/chunk-HB3Z2GCR.js +124 -0
  46. package/dist/chunk-HB3Z2GCR.js.map +1 -0
  47. package/dist/{chunk-SCZXXXU4.js → chunk-I6MX32UC.js} +7 -32
  48. package/dist/chunk-I6MX32UC.js.map +1 -0
  49. package/dist/{chunk-VQBTTTUN.js → chunk-KESP7GOK.js} +4 -4
  50. package/dist/{chunk-VQBTTTUN.js.map → chunk-KESP7GOK.js.map} +1 -1
  51. package/dist/{chunk-NXFEYLVG.js → chunk-MIQHZESA.js} +4 -3
  52. package/dist/{chunk-NXFEYLVG.js.map → chunk-MIQHZESA.js.map} +1 -1
  53. package/dist/chunk-MKSA2V7A.js +19 -0
  54. package/dist/chunk-MKSA2V7A.js.map +1 -0
  55. package/dist/{chunk-M5INGEFC.js → chunk-MRIBLZL3.js} +3 -1
  56. package/dist/chunk-MRIBLZL3.js.map +1 -0
  57. package/dist/{chunk-MDDTIZUO.js → chunk-NIOHFJPJ.js} +6 -6
  58. package/dist/chunk-OMLIZL2P.js +61 -0
  59. package/dist/chunk-OMLIZL2P.js.map +1 -0
  60. package/dist/{chunk-USKYUS74.js → chunk-P7EQ2S5O.js} +2 -2
  61. package/dist/{chunk-WDM5XGGS.js → chunk-PA6R5ZCI.js} +181 -11
  62. package/dist/chunk-PA6R5ZCI.js.map +1 -0
  63. package/dist/chunk-PEULZC6M.js +118 -0
  64. package/dist/chunk-PEULZC6M.js.map +1 -0
  65. package/dist/chunk-RD5LYKD6.js +82 -0
  66. package/dist/chunk-RD5LYKD6.js.map +1 -0
  67. package/dist/chunk-SIZWEV2Y.js +145 -0
  68. package/dist/chunk-SIZWEV2Y.js.map +1 -0
  69. package/dist/{chunk-QAVUREFT.js → chunk-UA4RI7OT.js} +12 -6
  70. package/dist/chunk-UA4RI7OT.js.map +1 -0
  71. package/dist/chunk-UMLVJTYV.js +20 -0
  72. package/dist/chunk-UMLVJTYV.js.map +1 -0
  73. package/dist/chunk-UZXLQCHP.js +53 -0
  74. package/dist/chunk-UZXLQCHP.js.map +1 -0
  75. package/dist/{chunk-2CSJGFCB.js → chunk-VMIO4IXG.js} +5 -5
  76. package/dist/{chunk-MR4424N3.js → chunk-WCA2NROQ.js} +2 -2
  77. package/dist/{chunk-TDR6T5CJ.js → chunk-XGSOTWYX.js} +91 -132
  78. package/dist/chunk-XGSOTWYX.js.map +1 -0
  79. package/dist/{chunk-NPC4LFV5.js → chunk-YMYK7US4.js} +2 -2
  80. package/dist/{chunk-RKJ6OL7K.js → chunk-YS3POABP.js} +1 -1
  81. package/dist/chunk-YS3POABP.js.map +1 -0
  82. package/dist/chunk-Z72JH4KG.js +209 -0
  83. package/dist/chunk-Z72JH4KG.js.map +1 -0
  84. package/dist/{chunk-R36SIKES.js → chunk-ZNOEIM6Y.js} +2 -2
  85. package/dist/consent/index.cjs.map +1 -1
  86. package/dist/consent/index.d.cts +6 -6
  87. package/dist/consent/index.d.ts +6 -6
  88. package/dist/consent/index.js +3 -3
  89. package/dist/{crypto-IVKU7YTT.js → crypto-A7FRXYHC.js} +3 -3
  90. package/dist/{delegation-2DBS2EOH.js → delegation-YBA4X4JN.js} +5 -4
  91. package/dist/derivations/index.cjs +351 -0
  92. package/dist/derivations/index.cjs.map +1 -0
  93. package/dist/derivations/index.d.cts +71 -0
  94. package/dist/derivations/index.d.ts +71 -0
  95. package/dist/derivations/index.js +27 -0
  96. package/dist/{dev-unlock-BdPp68qn.d.ts → dev-unlock-D9s-loPr.d.ts} +1 -1
  97. package/dist/{dev-unlock-Da1B0TIK.d.cts → dev-unlock-DRwVSy2S.d.cts} +1 -1
  98. package/dist/executor-7E3VFGW7.js +11 -0
  99. package/dist/executor-CEWX2FQI.js +8 -0
  100. package/dist/executor-CEWX2FQI.js.map +1 -0
  101. package/dist/executor-X4SQ3ZLC.js +8 -0
  102. package/dist/executor-X4SQ3ZLC.js.map +1 -0
  103. package/dist/fanout-sidecar-VJ52RIEY.js +51 -0
  104. package/dist/fanout-sidecar-VJ52RIEY.js.map +1 -0
  105. package/dist/guards/index.cjs +315 -0
  106. package/dist/guards/index.cjs.map +1 -0
  107. package/dist/guards/index.d.cts +30 -0
  108. package/dist/guards/index.d.ts +30 -0
  109. package/dist/guards/index.js +29 -0
  110. package/dist/guards/index.js.map +1 -0
  111. package/dist/{hash-lsoL3eEW.d.ts → hash-DXXXusyk.d.ts} +1 -1
  112. package/dist/{hash-BEfzPKwo.d.cts → hash-DtRih9MQ.d.cts} +1 -1
  113. package/dist/history/index.cjs +8 -1
  114. package/dist/history/index.cjs.map +1 -1
  115. package/dist/history/index.d.cts +7 -7
  116. package/dist/history/index.d.ts +7 -7
  117. package/dist/history/index.js +6 -6
  118. package/dist/i18n/index.cjs +81 -0
  119. package/dist/i18n/index.cjs.map +1 -1
  120. package/dist/i18n/index.d.cts +6 -6
  121. package/dist/i18n/index.d.ts +6 -6
  122. package/dist/i18n/index.js +19 -6
  123. package/dist/i18n/index.js.map +1 -1
  124. package/dist/{index-8QDuznDr.d.ts → index-4agOpzqd.d.ts} +174 -3
  125. package/dist/{index-6xNpPsxR.d.cts → index-CNwA-B6-.d.ts} +303 -5
  126. package/dist/{index-DJTf9yxn.d.ts → index-CmVgTkqk.d.cts} +303 -5
  127. package/dist/{index-CywCC1qZ.d.cts → index-hdFvZkBP.d.cts} +174 -3
  128. package/dist/index.cjs +5615 -979
  129. package/dist/index.cjs.map +1 -1
  130. package/dist/index.d.cts +207 -16
  131. package/dist/index.d.ts +207 -16
  132. package/dist/index.js +2302 -741
  133. package/dist/index.js.map +1 -1
  134. package/dist/indexing/index.cjs +2 -0
  135. package/dist/indexing/index.cjs.map +1 -1
  136. package/dist/indexing/index.d.cts +3 -3
  137. package/dist/indexing/index.d.ts +3 -3
  138. package/dist/indexing/index.js +4 -4
  139. package/dist/{lazy-builder-CZVLKh0Z.d.cts → lazy-builder-C-rPfWG0.d.cts} +1 -1
  140. package/dist/{lazy-builder-BwEoBQZ9.d.ts → lazy-builder-Rpd-V3jP.d.ts} +1 -1
  141. package/dist/{ledger-QZTTHQAQ.js → ledger-3TXNP47J.js} +6 -6
  142. package/dist/ledger-3TXNP47J.js.map +1 -0
  143. package/dist/materialized-views/index.cjs +837 -0
  144. package/dist/materialized-views/index.cjs.map +1 -0
  145. package/dist/materialized-views/index.d.cts +183 -0
  146. package/dist/materialized-views/index.d.ts +183 -0
  147. package/dist/materialized-views/index.js +45 -0
  148. package/dist/materialized-views/index.js.map +1 -0
  149. package/dist/overlay-views/index.cjs +359 -0
  150. package/dist/overlay-views/index.cjs.map +1 -0
  151. package/dist/overlay-views/index.d.cts +81 -0
  152. package/dist/overlay-views/index.d.ts +81 -0
  153. package/dist/overlay-views/index.js +23 -0
  154. package/dist/overlay-views/index.js.map +1 -0
  155. package/dist/periods/index.cjs +7 -1
  156. package/dist/periods/index.cjs.map +1 -1
  157. package/dist/periods/index.d.cts +6 -6
  158. package/dist/periods/index.d.ts +6 -6
  159. package/dist/periods/index.js +6 -6
  160. package/dist/{predicate-SBHmi6D0.d.cts → predicate-Dnu81tsS.d.cts} +25 -1
  161. package/dist/{predicate-SBHmi6D0.d.ts → predicate-Dnu81tsS.d.ts} +25 -1
  162. package/dist/{public-envelope-6JTACYJV.js → public-envelope-PY6NKFLI.js} +4 -4
  163. package/dist/public-envelope-PY6NKFLI.js.map +1 -0
  164. package/dist/query/index.cjs +302 -124
  165. package/dist/query/index.cjs.map +1 -1
  166. package/dist/query/index.d.cts +3 -3
  167. package/dist/query/index.d.ts +3 -3
  168. package/dist/query/index.js +26 -11
  169. package/dist/read-only-facade-ITU6L7BL.js +7 -0
  170. package/dist/read-only-facade-ITU6L7BL.js.map +1 -0
  171. package/dist/registry-3L3N3PTG.js +10 -0
  172. package/dist/registry-3L3N3PTG.js.map +1 -0
  173. package/dist/registry-O47PUPSY.js +8 -0
  174. package/dist/registry-O47PUPSY.js.map +1 -0
  175. package/dist/registry-RFGGMVNJ.js +7 -0
  176. package/dist/registry-RFGGMVNJ.js.map +1 -0
  177. package/dist/registry-WLLMODKN.js +8 -0
  178. package/dist/registry-WLLMODKN.js.map +1 -0
  179. package/dist/session/index.cjs +7 -1
  180. package/dist/session/index.cjs.map +1 -1
  181. package/dist/session/index.d.cts +7 -7
  182. package/dist/session/index.d.ts +7 -7
  183. package/dist/session/index.js +10 -3
  184. package/dist/session/index.js.map +1 -1
  185. package/dist/shadow/index.cjs.map +1 -1
  186. package/dist/shadow/index.d.cts +6 -6
  187. package/dist/shadow/index.d.ts +6 -6
  188. package/dist/shadow/index.js +2 -2
  189. package/dist/stale-HSC5YO2O.js +13 -0
  190. package/dist/stale-HSC5YO2O.js.map +1 -0
  191. package/dist/store/index.cjs +14 -0
  192. package/dist/store/index.cjs.map +1 -1
  193. package/dist/store/index.d.cts +6 -6
  194. package/dist/store/index.d.ts +6 -6
  195. package/dist/store/index.js +5 -2
  196. package/dist/{strategy-D-SrOLCl.d.cts → strategy-DSTrsZ8t.d.cts} +72 -19
  197. package/dist/{strategy-D-SrOLCl.d.ts → strategy-DSTrsZ8t.d.ts} +72 -19
  198. package/dist/sync/index.cjs.map +1 -1
  199. package/dist/sync/index.d.cts +5 -5
  200. package/dist/sync/index.d.ts +5 -5
  201. package/dist/sync/index.js +4 -4
  202. package/dist/team/index.cjs +1554 -2
  203. package/dist/team/index.cjs.map +1 -1
  204. package/dist/team/index.d.cts +6 -6
  205. package/dist/team/index.d.ts +6 -6
  206. package/dist/team/index.js +76 -9
  207. package/dist/tx/index.cjs +296 -44
  208. package/dist/tx/index.cjs.map +1 -1
  209. package/dist/tx/index.d.cts +6 -6
  210. package/dist/tx/index.d.ts +6 -6
  211. package/dist/tx/index.js +2 -2
  212. package/dist/{types-Bnb82f5R.d.cts → types-C4lwMKKF.d.cts} +2605 -328
  213. package/dist/{types-Bo7NSXJr.d.ts → types-DW9RGSSs.d.ts} +2605 -328
  214. package/dist/util/index.cjs.map +1 -1
  215. package/dist/util/index.js +1 -1
  216. package/dist/with-derivation-C8LDlV7t.d.cts +13 -0
  217. package/dist/with-derivation-g-pGoMzL.d.ts +13 -0
  218. package/dist/with-guard-DWOCK4Ca.d.ts +18 -0
  219. package/dist/with-guard-jI1x9Z3k.d.cts +18 -0
  220. package/dist/with-materialized-view-DaKR-N6J.d.ts +27 -0
  221. package/dist/with-materialized-view-DcTx4H3j.d.cts +27 -0
  222. package/dist/with-overlayed-view-D-6oWAgM.d.cts +13 -0
  223. package/dist/with-overlayed-view-N7jYuNOS.d.ts +13 -0
  224. package/package.json +53 -2
  225. package/dist/chunk-4PWAI7Q4.js +0 -79
  226. package/dist/chunk-4PWAI7Q4.js.map +0 -1
  227. package/dist/chunk-ACLDOTNQ.js.map +0 -1
  228. package/dist/chunk-BTDCBVJW.js +0 -160
  229. package/dist/chunk-BTDCBVJW.js.map +0 -1
  230. package/dist/chunk-CIMZBAZB.js.map +0 -1
  231. package/dist/chunk-EXHNQEV4.js.map +0 -1
  232. package/dist/chunk-GOUT6DND.js.map +0 -1
  233. package/dist/chunk-M5INGEFC.js.map +0 -1
  234. package/dist/chunk-QAVUREFT.js.map +0 -1
  235. package/dist/chunk-RKJ6OL7K.js.map +0 -1
  236. package/dist/chunk-SCZXXXU4.js.map +0 -1
  237. package/dist/chunk-TDR6T5CJ.js.map +0 -1
  238. package/dist/chunk-WDM5XGGS.js.map +0 -1
  239. /package/dist/{chunk-AVVPZ4BC.js.map → chunk-4TFSM22V.js.map} +0 -0
  240. /package/dist/{chunk-QGZRWRSL.js.map → chunk-537VFZTR.js.map} +0 -0
  241. /package/dist/{chunk-M62XNWRA.js.map → chunk-5DWL3JBF.js.map} +0 -0
  242. /package/dist/{chunk-PTVMYYON.js.map → chunk-5SCJ5UEF.js.map} +0 -0
  243. /package/dist/{chunk-ZFKD4QMV.js.map → chunk-DYECX3IX.js.map} +0 -0
  244. /package/dist/{chunk-MDDTIZUO.js.map → chunk-NIOHFJPJ.js.map} +0 -0
  245. /package/dist/{chunk-USKYUS74.js.map → chunk-P7EQ2S5O.js.map} +0 -0
  246. /package/dist/{chunk-2CSJGFCB.js.map → chunk-VMIO4IXG.js.map} +0 -0
  247. /package/dist/{chunk-MR4424N3.js.map → chunk-WCA2NROQ.js.map} +0 -0
  248. /package/dist/{chunk-NPC4LFV5.js.map → chunk-YMYK7US4.js.map} +0 -0
  249. /package/dist/{chunk-R36SIKES.js.map → chunk-ZNOEIM6Y.js.map} +0 -0
  250. /package/dist/{crypto-IVKU7YTT.js.map → crypto-A7FRXYHC.js.map} +0 -0
  251. /package/dist/{delegation-2DBS2EOH.js.map → delegation-YBA4X4JN.js.map} +0 -0
  252. /package/dist/{ledger-QZTTHQAQ.js.map → derivations/index.js.map} +0 -0
  253. /package/dist/{public-envelope-6JTACYJV.js.map → executor-7E3VFGW7.js.map} +0 -0
@@ -0,0 +1,71 @@
1
+ export { w as withDerivation } from '../with-derivation-g-pGoMzL.js';
2
+ import { aw as DerivationStrategy, ax as DerivationContext } from '../types-DW9RGSSs.js';
3
+ export { ay as ArrayOutputSpec, az as DerivationRegistry, aA as DerivationStrategyHandle, aB as DerivedFromMeta, aC as OutputSpec, aD as RecordOutputSpec } from '../types-DW9RGSSs.js';
4
+ export { e as DerivationCapExceededError, f as DerivationCycleError, g as DerivationDepthError, h as DerivationOutputShapeError, i as DerivationOutputUnknownError } from '../index-CNwA-B6-.js';
5
+ import '../lazy-builder-Rpd-V3jP.js';
6
+ import '../predicate-Dnu81tsS.js';
7
+ import '../strategy-DSTrsZ8t.js';
8
+ import '../strategy-BSxFXGzb.js';
9
+
10
+ interface RunResult {
11
+ outputs: Record<string, OutputResult>;
12
+ failed: boolean;
13
+ }
14
+ /**
15
+ * Per-output result of a strategy invocation. Discriminated by
16
+ * `kind`:
17
+ *
18
+ * - `record` — the existing v1 shape: one value (or a "skipped"
19
+ * marker if the output was optional and `derive` returned null).
20
+ * - `array` — the #200 shape: a list of `(key, value)` entries.
21
+ * The caller diffs these against the previously-emitted key set
22
+ * (loaded from the fanout sidecar) to compute deletes + upserts.
23
+ */
24
+ type OutputResult = RecordOutputResult | ArrayOutputResult | FailedOutputResult;
25
+ interface RecordOutputResult {
26
+ kind: 'record';
27
+ value: Record<string, unknown>;
28
+ ok: true;
29
+ /**
30
+ * `true` when an optional output (#144) returned `null` /
31
+ * `undefined`. The caller deletes any previously-emitted output at
32
+ * the same id (mirrors "tombstone for derived data"); a never-emitted
33
+ * output is a silent no-op. `ok: true` because skipping is a
34
+ * successful outcome, not a failure.
35
+ */
36
+ skipped?: boolean;
37
+ }
38
+ interface ArrayOutputResult {
39
+ kind: 'array';
40
+ ok: true;
41
+ /** One `(key, value)` per derived row. Empty array means "all prior outputs for this source go." */
42
+ entries: ReadonlyArray<{
43
+ readonly key: string;
44
+ readonly value: Record<string, unknown>;
45
+ }>;
46
+ }
47
+ interface FailedOutputResult {
48
+ kind: 'failed';
49
+ ok: false;
50
+ error: Error;
51
+ /** Always empty on failure; present so consumers don't have to narrow. */
52
+ value: Record<string, unknown>;
53
+ }
54
+ /**
55
+ * Stateless functions that execute a derivation strategy. Persistence
56
+ * (encrypt + store.put) is the caller's job — typically
57
+ * `DerivationRegistry.onSourceWrite` which iterates run() results and
58
+ * writes each output via `Collection.put`.
59
+ */
60
+ declare const DerivationExecutor: {
61
+ /**
62
+ * Run `derive` once, validate output shape against the spec, stamp
63
+ * `_derivedFrom` onto every output. Returns per-output success or
64
+ * failure; throws only for shape mismatches (a contract violation).
65
+ */
66
+ run<TSource extends Record<string, unknown>, TOutputs extends Record<string, Record<string, unknown>>>(strategy: DerivationStrategy<TSource, TOutputs>, source: TSource & {
67
+ id: string;
68
+ }, sourceVersion: number, strategyHash: string, ctx: DerivationContext): Promise<RunResult>;
69
+ };
70
+
71
+ export { DerivationExecutor, DerivationStrategy };
@@ -0,0 +1,27 @@
1
+ import {
2
+ withDerivation
3
+ } from "../chunk-EGQYGYIU.js";
4
+ import {
5
+ DerivationRegistry
6
+ } from "../chunk-FCXOFQAJ.js";
7
+ import {
8
+ DerivationExecutor
9
+ } from "../chunk-HB3Z2GCR.js";
10
+ import {
11
+ DerivationCapExceededError,
12
+ DerivationCycleError,
13
+ DerivationDepthError,
14
+ DerivationOutputShapeError,
15
+ DerivationOutputUnknownError
16
+ } from "../chunk-ADQ5MQ54.js";
17
+ export {
18
+ DerivationCapExceededError,
19
+ DerivationCycleError,
20
+ DerivationDepthError,
21
+ DerivationExecutor,
22
+ DerivationOutputShapeError,
23
+ DerivationOutputUnknownError,
24
+ DerivationRegistry,
25
+ withDerivation
26
+ };
27
+ //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { aq as Role, ar as UnlockedKeyring } from './types-Bo7NSXJr.js';
1
+ import { aL as Role, aM as UnlockedKeyring } from './types-DW9RGSSs.js';
2
2
 
3
3
  /**
4
4
  * Session tokens —
@@ -1,4 +1,4 @@
1
- import { aq as Role, ar as UnlockedKeyring } from './types-Bnb82f5R.cjs';
1
+ import { aL as Role, aM as UnlockedKeyring } from './types-C4lwMKKF.cjs';
2
2
 
3
3
  /**
4
4
  * Session tokens —
@@ -0,0 +1,11 @@
1
+ import {
2
+ MaterializedViewExecutor
3
+ } from "./chunk-SIZWEV2Y.js";
4
+ import "./chunk-DPMFBCV6.js";
5
+ import "./chunk-XGSOTWYX.js";
6
+ import "./chunk-MRIBLZL3.js";
7
+ import "./chunk-ADQ5MQ54.js";
8
+ export {
9
+ MaterializedViewExecutor
10
+ };
11
+ //# sourceMappingURL=executor-7E3VFGW7.js.map
@@ -0,0 +1,8 @@
1
+ import {
2
+ GuardExecutor
3
+ } from "./chunk-34YSDCDP.js";
4
+ import "./chunk-ADQ5MQ54.js";
5
+ export {
6
+ GuardExecutor
7
+ };
8
+ //# sourceMappingURL=executor-CEWX2FQI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ DerivationExecutor
3
+ } from "./chunk-HB3Z2GCR.js";
4
+ import "./chunk-ADQ5MQ54.js";
5
+ export {
6
+ DerivationExecutor
7
+ };
8
+ //# sourceMappingURL=executor-X4SQ3ZLC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,51 @@
1
+ import {
2
+ NOYDB_FORMAT_VERSION
3
+ } from "./chunk-YS3POABP.js";
4
+
5
+ // src/derivations/fanout-sidecar.ts
6
+ function recordId(source, sourceId, outputKey) {
7
+ return `derivations-fanout/${source}/${sourceId}/${outputKey}`;
8
+ }
9
+ async function loadFanoutSidecar(store, vault, source, sourceId, outputKey) {
10
+ const envelope = await store.get(vault, "_meta", recordId(source, sourceId, outputKey));
11
+ if (!envelope) return void 0;
12
+ try {
13
+ const parsed = JSON.parse(envelope._data);
14
+ if (parsed._noydb_fanout !== 1) return void 0;
15
+ if (!Array.isArray(parsed.keys)) return void 0;
16
+ return parsed;
17
+ } catch {
18
+ return void 0;
19
+ }
20
+ }
21
+ async function saveFanoutSidecar(store, vault, payload) {
22
+ const doc = {
23
+ _noydb_fanout: 1,
24
+ source: payload.source,
25
+ sourceId: payload.sourceId,
26
+ outputKey: payload.outputKey,
27
+ outputCollection: payload.outputCollection,
28
+ keys: payload.keys,
29
+ emittedAt: (/* @__PURE__ */ new Date()).toISOString()
30
+ };
31
+ const id = recordId(payload.source, payload.sourceId, payload.outputKey);
32
+ const prior = await store.get(vault, "_meta", id);
33
+ const envelope = {
34
+ _noydb: NOYDB_FORMAT_VERSION,
35
+ _v: (prior?._v ?? 0) + 1,
36
+ _ts: (/* @__PURE__ */ new Date()).toISOString(),
37
+ // AES-GCM bypassed — sidecar is system metadata, no user data inside.
38
+ _iv: "",
39
+ _data: JSON.stringify(doc)
40
+ };
41
+ await store.put(vault, "_meta", id, envelope);
42
+ }
43
+ async function deleteFanoutSidecar(store, vault, source, sourceId, outputKey) {
44
+ await store.delete(vault, "_meta", recordId(source, sourceId, outputKey));
45
+ }
46
+ export {
47
+ deleteFanoutSidecar,
48
+ loadFanoutSidecar,
49
+ saveFanoutSidecar
50
+ };
51
+ //# sourceMappingURL=fanout-sidecar-VJ52RIEY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/derivations/fanout-sidecar.ts"],"sourcesContent":["/**\n * Per-source-row fanout sidecar for `shape: 'array'` derivations (#200).\n *\n * Each `(sourceCollection, sourceId, outputKey)` triple gets its own\n * envelope at:\n *\n * _meta/derivations-fanout/<sourceCollection>/<sourceId>/<outputKey>\n *\n * The envelope records the last-emitted derived row ids so the\n * dispatcher can compute the diff on every source-row update in O(1):\n * read prior keys, compute `toDelete = prev \\ new`, write new, persist\n * back.\n *\n * Stored as plain JSON with AES-GCM bypassed (same pattern as\n * `_meta/policy`, `_meta/recovery-paper`, `_meta/sealed-passphrase`,\n * etc.): the sidecar is system metadata, not user data, and the\n * derived outputs themselves carry their own encryption envelopes.\n *\n * @module\n */\nimport type { NoydbStore, EncryptedEnvelope } from '../types.js'\nimport { NOYDB_FORMAT_VERSION } from '../types.js'\n\n/** Magic-prefixed JSON payload at `_meta/<recordId>`. */\nexport interface FanoutSidecar {\n readonly _noydb_fanout: 1\n /** Source collection name. */\n readonly source: string\n /** Source record id. */\n readonly sourceId: string\n /** Strategy output key (the key in `strategy.outputs`). */\n readonly outputKey: string\n /** Output collection name (audit / forensics). */\n readonly outputCollection: string\n /** Derived-row ids last emitted for this (source, output) pair. */\n readonly keys: ReadonlyArray<string>\n /** ISO timestamp of last dispatch. */\n readonly emittedAt: string\n}\n\n/**\n * Build the canonical `_meta` record id for a fanout sidecar.\n *\n * The full path inside the store is `_meta/<this-string>`. We pack the\n * full triple into the id so a single `_meta` collection holds all\n * sidecars (collection-per-source would proliferate names; the\n * existing `_meta` flat namespace is cheaper).\n */\nfunction recordId(source: string, sourceId: string, outputKey: string): string {\n // Use `/` as a separator. None of the components is supposed to\n // contain it (collection names + output keys are bare identifiers;\n // source ids are typically ULIDs / UUIDs / app-chosen strings\n // without slashes). If a future source carries `/` in its id, we'd\n // need an escape; deferred until that's a real case.\n return `derivations-fanout/${source}/${sourceId}/${outputKey}`\n}\n\n/** Read the sidecar; returns empty if absent. */\nexport async function loadFanoutSidecar(\n store: NoydbStore,\n vault: string,\n source: string,\n sourceId: string,\n outputKey: string,\n): Promise<FanoutSidecar | undefined> {\n const envelope = await store.get(vault, '_meta', recordId(source, sourceId, outputKey))\n if (!envelope) return undefined\n try {\n const parsed = JSON.parse(envelope._data) as FanoutSidecar\n if (parsed._noydb_fanout !== 1) return undefined\n if (!Array.isArray(parsed.keys)) return undefined\n return parsed\n } catch {\n return undefined\n }\n}\n\n/** Persist (insert/replace) the sidecar with a fresh key set. */\nexport async function saveFanoutSidecar(\n store: NoydbStore,\n vault: string,\n payload: {\n readonly source: string\n readonly sourceId: string\n readonly outputKey: string\n readonly outputCollection: string\n readonly keys: ReadonlyArray<string>\n },\n): Promise<void> {\n const doc: FanoutSidecar = {\n _noydb_fanout: 1,\n source: payload.source,\n sourceId: payload.sourceId,\n outputKey: payload.outputKey,\n outputCollection: payload.outputCollection,\n keys: payload.keys,\n emittedAt: new Date().toISOString(),\n }\n const id = recordId(payload.source, payload.sourceId, payload.outputKey)\n const prior = await store.get(vault, '_meta', id)\n const envelope: EncryptedEnvelope = {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: (prior?._v ?? 0) + 1,\n _ts: new Date().toISOString(),\n // AES-GCM bypassed — sidecar is system metadata, no user data inside.\n _iv: '',\n _data: JSON.stringify(doc),\n }\n await store.put(vault, '_meta', id, envelope)\n}\n\n/** Delete the sidecar (used on source-row delete cascade). */\nexport async function deleteFanoutSidecar(\n store: NoydbStore,\n vault: string,\n source: string,\n sourceId: string,\n outputKey: string,\n): Promise<void> {\n await store.delete(vault, '_meta', recordId(source, sourceId, outputKey))\n}\n"],"mappings":";;;;;AAgDA,SAAS,SAAS,QAAgB,UAAkB,WAA2B;AAM7E,SAAO,sBAAsB,MAAM,IAAI,QAAQ,IAAI,SAAS;AAC9D;AAGA,eAAsB,kBACpB,OACA,OACA,QACA,UACA,WACoC;AACpC,QAAM,WAAW,MAAM,MAAM,IAAI,OAAO,SAAS,SAAS,QAAQ,UAAU,SAAS,CAAC;AACtF,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,SAAS,KAAK;AACxC,QAAI,OAAO,kBAAkB,EAAG,QAAO;AACvC,QAAI,CAAC,MAAM,QAAQ,OAAO,IAAI,EAAG,QAAO;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,eAAsB,kBACpB,OACA,OACA,SAOe;AACf,QAAM,MAAqB;AAAA,IACzB,eAAe;AAAA,IACf,QAAQ,QAAQ;AAAA,IAChB,UAAU,QAAQ;AAAA,IAClB,WAAW,QAAQ;AAAA,IACnB,kBAAkB,QAAQ;AAAA,IAC1B,MAAM,QAAQ;AAAA,IACd,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AACA,QAAM,KAAK,SAAS,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,SAAS;AACvE,QAAM,QAAQ,MAAM,MAAM,IAAI,OAAO,SAAS,EAAE;AAChD,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,KAAK,OAAO,MAAM,KAAK;AAAA,IACvB,MAAK,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,IAE5B,KAAK;AAAA,IACL,OAAO,KAAK,UAAU,GAAG;AAAA,EAC3B;AACA,QAAM,MAAM,IAAI,OAAO,SAAS,IAAI,QAAQ;AAC9C;AAGA,eAAsB,oBACpB,OACA,OACA,QACA,UACA,WACe;AACf,QAAM,MAAM,OAAO,OAAO,SAAS,SAAS,QAAQ,UAAU,SAAS,CAAC;AAC1E;","names":[]}
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/guards/index.ts
21
+ var guards_exports = {};
22
+ __export(guards_exports, {
23
+ AmendmentForbiddenError: () => AmendmentForbiddenError,
24
+ FieldFrozenError: () => FieldFrozenError,
25
+ GuardExecutor: () => GuardExecutor,
26
+ GuardRegistry: () => GuardRegistry,
27
+ InvariantError: () => InvariantError,
28
+ ReadOnlyVaultFacade: () => ReadOnlyVaultFacade,
29
+ RecordLockedError: () => RecordLockedError,
30
+ withGuard: () => withGuard
31
+ });
32
+ module.exports = __toCommonJS(guards_exports);
33
+
34
+ // src/errors.ts
35
+ var NoydbError = class extends Error {
36
+ /** Machine-readable error code. Stable across library versions. */
37
+ code;
38
+ constructor(code, message) {
39
+ super(message);
40
+ this.name = "NoydbError";
41
+ this.code = code;
42
+ }
43
+ };
44
+ var RecordLockedError = class extends NoydbError {
45
+ collection;
46
+ id;
47
+ reason;
48
+ constructor(collection, id, reason) {
49
+ super(
50
+ "RECORD_LOCKED",
51
+ `Cannot modify ${collection}/${id} \u2014 locked by guard: ${reason}. Use withTransactions({ amendment: true, reason }) with admin/owner role to override.`
52
+ );
53
+ this.name = "RecordLockedError";
54
+ this.collection = collection;
55
+ this.id = id;
56
+ this.reason = reason;
57
+ }
58
+ };
59
+ var FieldFrozenError = class extends NoydbError {
60
+ collection;
61
+ id;
62
+ fields;
63
+ constructor(collection, id, fields) {
64
+ super(
65
+ "FIELD_FROZEN",
66
+ `Cannot change frozen field(s) on ${collection}/${id}: ${fields.join(", ")}. Use withTransactions({ amendment: true, reason }) with admin/owner role to override.`
67
+ );
68
+ this.name = "FieldFrozenError";
69
+ this.collection = collection;
70
+ this.id = id;
71
+ this.fields = fields;
72
+ }
73
+ };
74
+ var InvariantError = class extends NoydbError {
75
+ constructor(message) {
76
+ super("INVARIANT_VIOLATED", message);
77
+ this.name = "InvariantError";
78
+ }
79
+ };
80
+ var AmendmentForbiddenError = class extends NoydbError {
81
+ userId;
82
+ role;
83
+ constructor(userId, role) {
84
+ super(
85
+ "AMENDMENT_FORBIDDEN",
86
+ `User "${userId}" with role "${role}" cannot open an amendment transaction. Amendments require admin or owner role.`
87
+ );
88
+ this.name = "AmendmentForbiddenError";
89
+ this.userId = userId;
90
+ this.role = role;
91
+ }
92
+ };
93
+ var ValidationError = class extends NoydbError {
94
+ constructor(message = "Validation error") {
95
+ super("VALIDATION_ERROR", message);
96
+ this.name = "ValidationError";
97
+ }
98
+ };
99
+
100
+ // src/guards/with-guard.ts
101
+ function withGuard(strategy) {
102
+ if (!strategy.collection || strategy.collection.length === 0) {
103
+ throw new ValidationError("withGuard: collection name is required");
104
+ }
105
+ return {
106
+ __noydb_strategy: "guard",
107
+ spec: strategy
108
+ };
109
+ }
110
+
111
+ // src/guards/registry.ts
112
+ var GuardRegistry = class {
113
+ _byCollection = /* @__PURE__ */ new Map();
114
+ _amendmentChanges = null;
115
+ _amendmentMeta = null;
116
+ /** Register a guard. Multiple guards per collection are allowed. */
117
+ register(spec) {
118
+ const existing = this._byCollection.get(spec.collection);
119
+ if (existing) existing.push(spec);
120
+ else this._byCollection.set(spec.collection, [spec]);
121
+ }
122
+ /** All guards registered against `collection` in registration order. */
123
+ guardsFor(collection) {
124
+ return this._byCollection.get(collection) ?? [];
125
+ }
126
+ /**
127
+ * Run every guard's `check` for this collection. First throw wins —
128
+ * remaining guards are not invoked. Guards without a `check` skip.
129
+ */
130
+ async runChecks(collection, incoming, ctx) {
131
+ const guards = this._byCollection.get(collection);
132
+ if (!guards) return;
133
+ for (const g of guards) {
134
+ if (g.check) {
135
+ await g.check(
136
+ incoming,
137
+ ctx
138
+ );
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * Run every guard's `onDelete` for this collection. First throw wins —
144
+ * remaining guards are not invoked. Guards without an `onDelete` skip.
145
+ * Mirrors {@link runChecks} but for the delete path.
146
+ */
147
+ async runOnDelete(collection, existing, ctx) {
148
+ const guards = this._byCollection.get(collection);
149
+ if (!guards) return;
150
+ for (const g of guards) {
151
+ if (g.onDelete) {
152
+ await g.onDelete(
153
+ existing,
154
+ ctx
155
+ );
156
+ }
157
+ }
158
+ }
159
+ /** True if any guard for `collection` declares an `amendment` block. */
160
+ hasAmendment(collection) {
161
+ const guards = this._byCollection.get(collection);
162
+ if (!guards) return false;
163
+ return guards.some((g) => g.amendment !== void 0);
164
+ }
165
+ /** Open a new amendment change-collection window. */
166
+ beginAmendment() {
167
+ this._amendmentChanges = /* @__PURE__ */ new Map();
168
+ this._amendmentMeta = /* @__PURE__ */ new Map();
169
+ }
170
+ /** True iff we're currently inside an amendment transaction. */
171
+ isAmendmentActive() {
172
+ return this._amendmentChanges !== null;
173
+ }
174
+ /**
175
+ * Record a {before, after} pair for the active amendment. `vBefore`
176
+ * and `vAfter` are stored in a parallel meta structure so the public
177
+ * {@link GuardChange} shape handed to invariant callbacks stays
178
+ * `{ before, after }` only — the audit ledger reads version metadata
179
+ * via {@link consumeMeta}.
180
+ */
181
+ collectChange(collection, id, before, after, vBefore = 0, vAfter = 0) {
182
+ if (this._amendmentChanges === null || this._amendmentMeta === null) {
183
+ throw new Error("GuardRegistry.collectChange called outside an amendment");
184
+ }
185
+ const list = this._amendmentChanges.get(collection);
186
+ const entry = { before, after };
187
+ if (list) list.push(entry);
188
+ else this._amendmentChanges.set(collection, [entry]);
189
+ const metaList = this._amendmentMeta.get(collection);
190
+ const metaEntry = { id, vBefore, vAfter };
191
+ if (metaList) metaList.push(metaEntry);
192
+ else this._amendmentMeta.set(collection, [metaEntry]);
193
+ }
194
+ /**
195
+ * Drain the change-set and close the amendment window. The caller
196
+ * (transaction commit) feeds these to each affected guard's invariant.
197
+ */
198
+ consumeChanges() {
199
+ const out = this._amendmentChanges ?? /* @__PURE__ */ new Map();
200
+ this._amendmentChanges = null;
201
+ return out;
202
+ }
203
+ /**
204
+ * Drain the parallel id/version metadata captured during the
205
+ * amendment. Returned as a flat list with `collection` denormalised
206
+ * so the audit ledger can emit one `{ collection, id, vBefore,
207
+ * vAfter }` tuple per record. Must be called AFTER
208
+ * {@link consumeChanges} (or independently) — calling it closes the
209
+ * meta window in the same way.
210
+ */
211
+ consumeMeta() {
212
+ const out = [];
213
+ if (this._amendmentMeta) {
214
+ for (const [collection, list] of this._amendmentMeta) {
215
+ for (const m of list) {
216
+ out.push({ collection, id: m.id, vBefore: m.vBefore, vAfter: m.vAfter });
217
+ }
218
+ }
219
+ }
220
+ this._amendmentMeta = null;
221
+ return out;
222
+ }
223
+ };
224
+
225
+ // src/guards/executor.ts
226
+ var GuardExecutor = {
227
+ /**
228
+ * Compare existing vs incoming for each `frozenFields.fields` entry
229
+ * when `frozenFields.when(existing)` is true. Throws
230
+ * `FieldFrozenError` listing every changed frozen field.
231
+ */
232
+ async checkFrozenFields(guard, id, existing, incoming) {
233
+ const ff = guard.frozenFields;
234
+ if (!ff) return;
235
+ if (existing === null) return;
236
+ if (!ff.when(existing)) return;
237
+ const changed = [];
238
+ for (const f of ff.fields) {
239
+ if (existing[f] !== incoming[f]) {
240
+ if (!deepEqual(existing[f], incoming[f])) changed.push(String(f));
241
+ }
242
+ }
243
+ if (changed.length > 0) {
244
+ throw new FieldFrozenError(guard.collection, id, changed);
245
+ }
246
+ },
247
+ /**
248
+ * Run a single guard's invariant over its slice of the change-set.
249
+ * Any throw is converted to `InvariantError` unless it already is one.
250
+ */
251
+ async runInvariant(guard, changes, ctx) {
252
+ const amendment = guard.amendment;
253
+ if (!amendment) return;
254
+ try {
255
+ await amendment.invariant(changes, ctx);
256
+ } catch (err) {
257
+ if (err instanceof InvariantError) throw err;
258
+ throw new InvariantError(
259
+ err instanceof Error ? err.message : `invariant violated: ${String(err)}`
260
+ );
261
+ }
262
+ }
263
+ };
264
+ function deepEqual(a, b) {
265
+ if (a === b) return true;
266
+ if (a === null || b === null) return a === b;
267
+ if (typeof a !== typeof b) return false;
268
+ if (typeof a !== "object") return a === b;
269
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
270
+ if (Array.isArray(a)) {
271
+ const aa = a;
272
+ const bb = b;
273
+ if (aa.length !== bb.length) return false;
274
+ for (let i = 0; i < aa.length; i++) if (!deepEqual(aa[i], bb[i])) return false;
275
+ return true;
276
+ }
277
+ const ao = a;
278
+ const bo = b;
279
+ const ak = Object.keys(ao);
280
+ const bk = Object.keys(bo);
281
+ if (ak.length !== bk.length) return false;
282
+ for (const k of ak) {
283
+ if (!Object.prototype.hasOwnProperty.call(bo, k)) return false;
284
+ if (!deepEqual(ao[k], bo[k])) return false;
285
+ }
286
+ return true;
287
+ }
288
+
289
+ // src/guards/read-only-facade.ts
290
+ var ReadOnlyVaultFacade = class {
291
+ _vault;
292
+ constructor(vault) {
293
+ this._vault = vault;
294
+ }
295
+ collection(name) {
296
+ const c = this._vault.collection(name);
297
+ return {
298
+ get: (id) => c.get(id),
299
+ list: () => c.list(),
300
+ query: () => c.query()
301
+ };
302
+ }
303
+ };
304
+ // Annotate the CommonJS export names for ESM import in node:
305
+ 0 && (module.exports = {
306
+ AmendmentForbiddenError,
307
+ FieldFrozenError,
308
+ GuardExecutor,
309
+ GuardRegistry,
310
+ InvariantError,
311
+ ReadOnlyVaultFacade,
312
+ RecordLockedError,
313
+ withGuard
314
+ });
315
+ //# sourceMappingURL=index.cjs.map