@noy-db/hub 0.1.0-pre.3

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 (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -0
  3. package/dist/aggregate/index.cjs +476 -0
  4. package/dist/aggregate/index.cjs.map +1 -0
  5. package/dist/aggregate/index.d.cts +38 -0
  6. package/dist/aggregate/index.d.ts +38 -0
  7. package/dist/aggregate/index.js +53 -0
  8. package/dist/aggregate/index.js.map +1 -0
  9. package/dist/blobs/index.cjs +1480 -0
  10. package/dist/blobs/index.cjs.map +1 -0
  11. package/dist/blobs/index.d.cts +45 -0
  12. package/dist/blobs/index.d.ts +45 -0
  13. package/dist/blobs/index.js +48 -0
  14. package/dist/blobs/index.js.map +1 -0
  15. package/dist/bundle/index.cjs +436 -0
  16. package/dist/bundle/index.cjs.map +1 -0
  17. package/dist/bundle/index.d.cts +7 -0
  18. package/dist/bundle/index.d.ts +7 -0
  19. package/dist/bundle/index.js +40 -0
  20. package/dist/bundle/index.js.map +1 -0
  21. package/dist/chunk-2QR2PQTT.js +217 -0
  22. package/dist/chunk-2QR2PQTT.js.map +1 -0
  23. package/dist/chunk-4OWFYIDQ.js +79 -0
  24. package/dist/chunk-4OWFYIDQ.js.map +1 -0
  25. package/dist/chunk-5AATM2M2.js +90 -0
  26. package/dist/chunk-5AATM2M2.js.map +1 -0
  27. package/dist/chunk-ACLDOTNQ.js +543 -0
  28. package/dist/chunk-ACLDOTNQ.js.map +1 -0
  29. package/dist/chunk-BTDCBVJW.js +160 -0
  30. package/dist/chunk-BTDCBVJW.js.map +1 -0
  31. package/dist/chunk-CIMZBAZB.js +72 -0
  32. package/dist/chunk-CIMZBAZB.js.map +1 -0
  33. package/dist/chunk-E445ICYI.js +365 -0
  34. package/dist/chunk-E445ICYI.js.map +1 -0
  35. package/dist/chunk-EXQRC2L4.js +722 -0
  36. package/dist/chunk-EXQRC2L4.js.map +1 -0
  37. package/dist/chunk-FZU343FL.js +32 -0
  38. package/dist/chunk-FZU343FL.js.map +1 -0
  39. package/dist/chunk-GJILMRPO.js +354 -0
  40. package/dist/chunk-GJILMRPO.js.map +1 -0
  41. package/dist/chunk-GOUT6DND.js +1285 -0
  42. package/dist/chunk-GOUT6DND.js.map +1 -0
  43. package/dist/chunk-J66GRPNH.js +111 -0
  44. package/dist/chunk-J66GRPNH.js.map +1 -0
  45. package/dist/chunk-M2F2JAWB.js +464 -0
  46. package/dist/chunk-M2F2JAWB.js.map +1 -0
  47. package/dist/chunk-M5INGEFC.js +84 -0
  48. package/dist/chunk-M5INGEFC.js.map +1 -0
  49. package/dist/chunk-M62XNWRA.js +72 -0
  50. package/dist/chunk-M62XNWRA.js.map +1 -0
  51. package/dist/chunk-MR4424N3.js +275 -0
  52. package/dist/chunk-MR4424N3.js.map +1 -0
  53. package/dist/chunk-NPC4LFV5.js +132 -0
  54. package/dist/chunk-NPC4LFV5.js.map +1 -0
  55. package/dist/chunk-NXFEYLVG.js +311 -0
  56. package/dist/chunk-NXFEYLVG.js.map +1 -0
  57. package/dist/chunk-R36SIKES.js +79 -0
  58. package/dist/chunk-R36SIKES.js.map +1 -0
  59. package/dist/chunk-TDR6T5CJ.js +381 -0
  60. package/dist/chunk-TDR6T5CJ.js.map +1 -0
  61. package/dist/chunk-UF3BUNQZ.js +1 -0
  62. package/dist/chunk-UF3BUNQZ.js.map +1 -0
  63. package/dist/chunk-UQFSPSWG.js +1109 -0
  64. package/dist/chunk-UQFSPSWG.js.map +1 -0
  65. package/dist/chunk-USKYUS74.js +793 -0
  66. package/dist/chunk-USKYUS74.js.map +1 -0
  67. package/dist/chunk-XCL3WP6J.js +121 -0
  68. package/dist/chunk-XCL3WP6J.js.map +1 -0
  69. package/dist/chunk-XHFOENR2.js +680 -0
  70. package/dist/chunk-XHFOENR2.js.map +1 -0
  71. package/dist/chunk-ZFKD4QMV.js +430 -0
  72. package/dist/chunk-ZFKD4QMV.js.map +1 -0
  73. package/dist/chunk-ZLMV3TUA.js +490 -0
  74. package/dist/chunk-ZLMV3TUA.js.map +1 -0
  75. package/dist/chunk-ZRG4V3F5.js +17 -0
  76. package/dist/chunk-ZRG4V3F5.js.map +1 -0
  77. package/dist/consent/index.cjs +204 -0
  78. package/dist/consent/index.cjs.map +1 -0
  79. package/dist/consent/index.d.cts +24 -0
  80. package/dist/consent/index.d.ts +24 -0
  81. package/dist/consent/index.js +23 -0
  82. package/dist/consent/index.js.map +1 -0
  83. package/dist/crdt/index.cjs +152 -0
  84. package/dist/crdt/index.cjs.map +1 -0
  85. package/dist/crdt/index.d.cts +30 -0
  86. package/dist/crdt/index.d.ts +30 -0
  87. package/dist/crdt/index.js +24 -0
  88. package/dist/crdt/index.js.map +1 -0
  89. package/dist/crypto-IVKU7YTT.js +44 -0
  90. package/dist/crypto-IVKU7YTT.js.map +1 -0
  91. package/dist/delegation-XDJCBTI2.js +16 -0
  92. package/dist/delegation-XDJCBTI2.js.map +1 -0
  93. package/dist/dev-unlock-CeXic1xC.d.cts +263 -0
  94. package/dist/dev-unlock-KrKkcqD3.d.ts +263 -0
  95. package/dist/hash-9KO1BGxh.d.cts +63 -0
  96. package/dist/hash-ChfJjRjQ.d.ts +63 -0
  97. package/dist/history/index.cjs +1215 -0
  98. package/dist/history/index.cjs.map +1 -0
  99. package/dist/history/index.d.cts +62 -0
  100. package/dist/history/index.d.ts +62 -0
  101. package/dist/history/index.js +79 -0
  102. package/dist/history/index.js.map +1 -0
  103. package/dist/i18n/index.cjs +746 -0
  104. package/dist/i18n/index.cjs.map +1 -0
  105. package/dist/i18n/index.d.cts +38 -0
  106. package/dist/i18n/index.d.ts +38 -0
  107. package/dist/i18n/index.js +55 -0
  108. package/dist/i18n/index.js.map +1 -0
  109. package/dist/index-BRHBCmLt.d.ts +1940 -0
  110. package/dist/index-C8kQtmOk.d.ts +380 -0
  111. package/dist/index-DN-J-5wT.d.cts +1940 -0
  112. package/dist/index-DhjMjz7L.d.cts +380 -0
  113. package/dist/index.cjs +14756 -0
  114. package/dist/index.cjs.map +1 -0
  115. package/dist/index.d.cts +269 -0
  116. package/dist/index.d.ts +269 -0
  117. package/dist/index.js +6085 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/indexing/index.cjs +736 -0
  120. package/dist/indexing/index.cjs.map +1 -0
  121. package/dist/indexing/index.d.cts +36 -0
  122. package/dist/indexing/index.d.ts +36 -0
  123. package/dist/indexing/index.js +77 -0
  124. package/dist/indexing/index.js.map +1 -0
  125. package/dist/lazy-builder-BwEoBQZ9.d.ts +304 -0
  126. package/dist/lazy-builder-CZVLKh0Z.d.cts +304 -0
  127. package/dist/ledger-2NX4L7PN.js +33 -0
  128. package/dist/ledger-2NX4L7PN.js.map +1 -0
  129. package/dist/mime-magic-CBBSOkjm.d.cts +50 -0
  130. package/dist/mime-magic-CBBSOkjm.d.ts +50 -0
  131. package/dist/periods/index.cjs +1035 -0
  132. package/dist/periods/index.cjs.map +1 -0
  133. package/dist/periods/index.d.cts +21 -0
  134. package/dist/periods/index.d.ts +21 -0
  135. package/dist/periods/index.js +25 -0
  136. package/dist/periods/index.js.map +1 -0
  137. package/dist/predicate-SBHmi6D0.d.cts +161 -0
  138. package/dist/predicate-SBHmi6D0.d.ts +161 -0
  139. package/dist/query/index.cjs +1957 -0
  140. package/dist/query/index.cjs.map +1 -0
  141. package/dist/query/index.d.cts +3 -0
  142. package/dist/query/index.d.ts +3 -0
  143. package/dist/query/index.js +62 -0
  144. package/dist/query/index.js.map +1 -0
  145. package/dist/session/index.cjs +487 -0
  146. package/dist/session/index.cjs.map +1 -0
  147. package/dist/session/index.d.cts +45 -0
  148. package/dist/session/index.d.ts +45 -0
  149. package/dist/session/index.js +44 -0
  150. package/dist/session/index.js.map +1 -0
  151. package/dist/shadow/index.cjs +133 -0
  152. package/dist/shadow/index.cjs.map +1 -0
  153. package/dist/shadow/index.d.cts +16 -0
  154. package/dist/shadow/index.d.ts +16 -0
  155. package/dist/shadow/index.js +20 -0
  156. package/dist/shadow/index.js.map +1 -0
  157. package/dist/store/index.cjs +1069 -0
  158. package/dist/store/index.cjs.map +1 -0
  159. package/dist/store/index.d.cts +491 -0
  160. package/dist/store/index.d.ts +491 -0
  161. package/dist/store/index.js +34 -0
  162. package/dist/store/index.js.map +1 -0
  163. package/dist/strategy-BSxFXGzb.d.cts +110 -0
  164. package/dist/strategy-BSxFXGzb.d.ts +110 -0
  165. package/dist/strategy-D-SrOLCl.d.cts +548 -0
  166. package/dist/strategy-D-SrOLCl.d.ts +548 -0
  167. package/dist/sync/index.cjs +1062 -0
  168. package/dist/sync/index.cjs.map +1 -0
  169. package/dist/sync/index.d.cts +42 -0
  170. package/dist/sync/index.d.ts +42 -0
  171. package/dist/sync/index.js +28 -0
  172. package/dist/sync/index.js.map +1 -0
  173. package/dist/team/index.cjs +1233 -0
  174. package/dist/team/index.cjs.map +1 -0
  175. package/dist/team/index.d.cts +117 -0
  176. package/dist/team/index.d.ts +117 -0
  177. package/dist/team/index.js +39 -0
  178. package/dist/team/index.js.map +1 -0
  179. package/dist/tx/index.cjs +212 -0
  180. package/dist/tx/index.cjs.map +1 -0
  181. package/dist/tx/index.d.cts +20 -0
  182. package/dist/tx/index.d.ts +20 -0
  183. package/dist/tx/index.js +20 -0
  184. package/dist/tx/index.js.map +1 -0
  185. package/dist/types-BZpCZB8N.d.ts +7526 -0
  186. package/dist/types-Bfs0qr5F.d.cts +7526 -0
  187. package/dist/ulid-COREQ2RQ.js +9 -0
  188. package/dist/ulid-COREQ2RQ.js.map +1 -0
  189. package/dist/util/index.cjs +230 -0
  190. package/dist/util/index.cjs.map +1 -0
  191. package/dist/util/index.d.cts +77 -0
  192. package/dist/util/index.d.ts +77 -0
  193. package/dist/util/index.js +190 -0
  194. package/dist/util/index.js.map +1 -0
  195. package/package.json +244 -0
@@ -0,0 +1,380 @@
1
+ import { aU as BundleRecipient, aR as Vault } from './types-BZpCZB8N.js';
2
+
3
+ /**
4
+ * `.noydb` container format — byte layout, header schema, validators.
5
+ *
6
+ *. Wraps a `vault.dump()` JSON string in a thin
7
+ * binary container with a magic-byte prefix, a minimum-disclosure
8
+ * unencrypted header, and a compressed body.
9
+ *
10
+ * **Byte layout** (read in order from offset 0):
11
+ *
12
+ * ```
13
+ * +--------+--------+--------+--------+
14
+ * | N=78 | D=68 | B=66 | 1=49 | Magic 'NDB1' (4 bytes)
15
+ * +--------+--------+--------+--------+
16
+ * | flags | compr | header_length (uint32 BE) |
17
+ * +--------+--------+--------+--------+--------+--------+--------+
18
+ * | header_length bytes of UTF-8 JSON header ...
19
+ * +--------+--------+
20
+ * | compressed body bytes ...
21
+ * ```
22
+ *
23
+ * Total fixed prefix before the header JSON is **10 bytes**:
24
+ * - 4 bytes magic
25
+ * - 1 byte flags
26
+ * - 1 byte compression algorithm
27
+ * - 4 bytes header length (uint32 big-endian)
28
+ *
29
+ * **Why a binary container** at all? `vault.dump()` already
30
+ * produces a JSON string with encrypted records inside. Wrapping it
31
+ * again seems redundant — but the wrap is what makes the file safe
32
+ * to drop into cloud storage (Drive, Dropbox, iCloud) without
33
+ * leaking the vault name and exporter identity through the
34
+ * cloud's metadata API. The minimum-disclosure header is the only
35
+ * thing visible without downloading and decompressing the body.
36
+ * The dump JSON inside the body still contains the original
37
+ * metadata, but that's only readable by someone who already has the
38
+ * file bytes — the same person who could read the encrypted records
39
+ * with the right passphrase.
40
+ *
41
+ * **Why minimum disclosure** in the header? Because consumers will
42
+ * inevitably store these in services where the filename, file size,
43
+ * and any unencrypted metadata are indexed for search. A field like
44
+ * `vault: "Acme Corp"` would let an attacker (or a curious
45
+ * cloud admin) enumerate which compartments exist and who exported
46
+ * them, even with zero access to the encrypted body. The header
47
+ * carries only what's needed to identify the file as a NOYDB
48
+ * bundle and verify its integrity — nothing about the contents.
49
+ */
50
+ /** Magic bytes 'NDB1' (ASCII), identifying a NOYDB bundle. */
51
+ declare const NOYDB_BUNDLE_MAGIC: Uint8Array<ArrayBuffer>;
52
+ /** Total fixed prefix before the header JSON: 4+1+1+4 bytes. */
53
+ declare const NOYDB_BUNDLE_PREFIX_BYTES = 10;
54
+ /** Current bundle format version. Bumped on layout changes. */
55
+ declare const NOYDB_BUNDLE_FORMAT_VERSION = 1;
56
+ /**
57
+ * Bitfield interpretation of the flags byte.
58
+ *
59
+ * Bit 0 — body is compressed (0 = raw, 1 = compressed)
60
+ * Bit 1 — header carries an integrity hash over the body bytes
61
+ * Bits 2-7 — reserved, must be 0 in
62
+ */
63
+ declare const FLAG_COMPRESSED = 1;
64
+ declare const FLAG_HAS_INTEGRITY_HASH = 2;
65
+ /**
66
+ * Compression algorithm encoding for the byte at offset 5.
67
+ *
68
+ * `none` is admitted for round-trip testing and for callers that
69
+ * want to bundle without compression (e.g. when piping into a
70
+ * separately compressed transport). `gzip` is the universally
71
+ * available baseline (Node 18+, all modern browsers). `brotli` is
72
+ * preferred when the runtime supports it — typically 30-50% smaller
73
+ * for JSON payloads — but Node 22+ / Chrome 124+ / Firefox 122+
74
+ * are required, so the writer feature-detects at runtime and falls
75
+ * back to gzip. The reader must handle all three.
76
+ */
77
+ declare const COMPRESSION_NONE = 0;
78
+ declare const COMPRESSION_GZIP = 1;
79
+ declare const COMPRESSION_BROTLI = 2;
80
+ type CompressionAlgo = 0 | 1 | 2;
81
+ /**
82
+ * The unencrypted header carried in every `.noydb` bundle.
83
+ *
84
+ * **Minimum-disclosure rules:** these are the ONLY allowed keys.
85
+ * Any other key in a parsed header causes
86
+ * `validateBundleHeader` to throw. The set is kept short to
87
+ * minimize attack surface from cloud-storage metadata indexing —
88
+ * see the file-level doc comment for the rationale.
89
+ *
90
+ * Forbidden in particular:
91
+ * - `vault` / `_compartment` — would leak the tenant name
92
+ * - `exporter` / `_exported_by` — would leak user identity
93
+ * - `timestamp` / `_exported_at` — would leak activity timing
94
+ * - `kdfParams` / salt fields — would leak crypto config that
95
+ * could narrow brute-force search space
96
+ * - any field starting with `_` (reserved by the dump format)
97
+ */
98
+ interface NoydbBundleHeader {
99
+ /** Bundle format version — bumped on layout changes. */
100
+ readonly formatVersion: number;
101
+ /**
102
+ * Opaque ULID identifier — generated once per vault and
103
+ * stable across re-exports of the same vault. Does not
104
+ * leak any information about contents (the timestamp prefix is
105
+ * just monotonicity for sortability, not exporter activity —
106
+ * see `bundle/ulid.ts` for the design notes).
107
+ */
108
+ readonly handle: string;
109
+ /** Compressed body length in bytes. Lets readers verify completeness without decompressing. */
110
+ readonly bodyBytes: number;
111
+ /** SHA-256 of the compressed body bytes (lowercase hex). Lets readers verify integrity without decompressing. */
112
+ readonly bodySha256: string;
113
+ }
114
+ /**
115
+ * Validate a parsed bundle header. Throws on any deviation from
116
+ * the minimum-disclosure schema:
117
+ *
118
+ * - Missing required field
119
+ * - Wrong type for any field
120
+ * - Any extra key not in `ALLOWED_HEADER_KEYS`
121
+ * - Unsupported `formatVersion`
122
+ * - Negative or non-integer `bodyBytes`
123
+ * - Malformed `handle` (must be 26-char Crockford base32)
124
+ * - Malformed `bodySha256` (must be 64-char lowercase hex)
125
+ *
126
+ * The error messages name the offending field so consumers can
127
+ * fix the producer rather than the reader.
128
+ */
129
+ declare function validateBundleHeader(parsed: unknown): asserts parsed is NoydbBundleHeader;
130
+ /**
131
+ * Encode a header object to UTF-8 JSON bytes after validating
132
+ * minimum disclosure. Used by the writer to serialize the header
133
+ * region of the container.
134
+ */
135
+ declare function encodeBundleHeader(header: NoydbBundleHeader): Uint8Array;
136
+ /**
137
+ * Verify the magic prefix of a bundle. Returns true if the first
138
+ * 4 bytes match `NDB1`. Used by readers as a fast file-type check
139
+ * before any further parsing.
140
+ */
141
+ declare function hasNoydbBundleMagic(bytes: Uint8Array): boolean;
142
+
143
+ /**
144
+ * `.noydb` container primitives — write, read, header-only read.
145
+ *
146
+ *. Wraps a `vault.dump()` JSON string in the
147
+ * binary container described in `format.ts`.
148
+ *
149
+ * **Three primitives:**
150
+ *
151
+ * - `writeNoydbBundle(vault, opts?)` — produces the
152
+ * full container bytes ready to write to disk or upload
153
+ * - `readNoydbBundleHeader(bytes)` — parses just the header
154
+ * without decompressing the body, fast file-type and
155
+ * metadata read for cloud listing UIs
156
+ * - `readNoydbBundle(bytes)` — full read: validates magic,
157
+ * header, integrity hash, and decompresses the body to
158
+ * return the original `dump()` JSON string for use with
159
+ * `vault.load()`
160
+ *
161
+ * **Compression strategy:** brotli when available (Node 22+,
162
+ * Chrome 124+, Firefox 122+), gzip fallback elsewhere. The
163
+ * algorithm choice is encoded in the format byte at offset 5,
164
+ * so readers handle either transparently. Brotli wins ~30-50%
165
+ * on JSON payloads with repeated keys (which vault dumps
166
+ * are).
167
+ *
168
+ * **Why split read/load?** `readNoydbBundle` returns the
169
+ * *unwrapped JSON string*, not a Vault object. The caller
170
+ * is responsible for piping that JSON into
171
+ * `vault.load(json, passphrase)`. Splitting the layers
172
+ * keeps the bundle module free of any crypto/passphrase
173
+ * concerns — it's purely a format layer. The same `readNoydbBundle`
174
+ * call can also feed verification tools, format inspectors, or
175
+ * archive utilities that don't care about decryption.
176
+ */
177
+
178
+ /**
179
+ * Options accepted by `writeNoydbBundle`.
180
+ *
181
+ * - `compression: 'auto'` (default) — try brotli, fall back to gzip
182
+ * - `compression: 'brotli'` — force brotli, throw if unsupported
183
+ * - `compression: 'gzip'` — force gzip
184
+ * - `compression: 'none'` — no compression (round-trip testing only)
185
+ *
186
+ * **Slice filtering** (added in ):
187
+ * - `collections` — allowlist of collection names to include. Internal
188
+ * collections (keyrings, ledger) and excluded user collections are
189
+ * dropped from the bundle. Records inside included collections are
190
+ * carried through verbatim.
191
+ * - `since` — only records whose envelope `_ts` is on/after the given
192
+ * instant survive. Operates on the unencrypted envelope timestamp,
193
+ * so plaintext access to records is not required.
194
+ *
195
+ * Both filters intersect (AND). When neither is provided the bundle is
196
+ * a whole-vault snapshot, identical to today's behaviour.
197
+ */
198
+ interface WriteNoydbBundleOptions {
199
+ readonly compression?: 'auto' | 'brotli' | 'gzip' | 'none';
200
+ /** Allowlist of user-collection names to include. */
201
+ readonly collections?: readonly string[];
202
+ /**
203
+ * Drop records whose envelope `_ts` is strictly older than this
204
+ * instant. Accepts a `Date` or any ISO-8601 string parseable by
205
+ * `new Date()`.
206
+ */
207
+ readonly since?: Date | string;
208
+ /**
209
+ * Plaintext-pipeline record predicate. Decrypts each record
210
+ * with the vault's per-collection DEK, runs the predicate, and
211
+ * keeps the original ciphertext for survivors (no re-encrypt —
212
+ * preserves zero-knowledge cleanly). Records the predicate returns
213
+ * `false` for are dropped from the bundle.
214
+ *
215
+ * Async predicates are supported. Mutating the record from inside
216
+ * the predicate is undefined behaviour.
217
+ */
218
+ readonly where?: (record: unknown, ctx: {
219
+ collection: string;
220
+ id: string;
221
+ }) => boolean | Promise<boolean>;
222
+ /**
223
+ * Hierarchical-tier ceiling. Records whose envelope `_tier`
224
+ * is strictly greater than this number are dropped. Operates on the
225
+ * envelope `_tier` (no decryption needed) — vault.exportStream is
226
+ * referenced in the issue body for symmetry, but the tier value
227
+ * lives on the unencrypted envelope. Vault without tiers is a no-op.
228
+ */
229
+ readonly tierAtMost?: number;
230
+ /**
231
+ * Single-recipient re-keying shorthand. When set, the
232
+ * bundle's keyring is replaced with one freshly-derived entry sealed
233
+ * with this passphrase. The recipient inherits the source keyring's
234
+ * userId, role, and permissions. Mutually exclusive with `recipients`.
235
+ */
236
+ readonly exportPassphrase?: string;
237
+ /**
238
+ * Multi-recipient re-keying. Replaces the bundle's keyring
239
+ * map with one slot per recipient, each sealed with its own
240
+ * passphrase. DEKs are unwrapped from the source keyring once and
241
+ * re-wrapped per recipient — record ciphertext is unchanged.
242
+ *
243
+ * Mutually exclusive with `exportPassphrase`. When neither is set,
244
+ * the bundle inherits the source keyring as-is (today's behaviour,
245
+ * suited to personal backup-and-restore).
246
+ */
247
+ readonly recipients?: readonly BundleRecipient[];
248
+ }
249
+ /**
250
+ * Result returned by `readNoydbBundle`. The caller is expected to
251
+ * pass `dumpJson` into `vault.load(json, passphrase)` to
252
+ * actually restore a vault. Splitting the layers keeps the
253
+ * bundle module free of crypto concerns — see file-level docs.
254
+ */
255
+ interface NoydbBundleReadResult {
256
+ readonly header: NoydbBundleHeader;
257
+ readonly dumpJson: string;
258
+ }
259
+ /** Test-only: reset the brotli detection cache between tests. */
260
+ declare function resetBrotliSupportCache(): void;
261
+ /**
262
+ * Write a `.noydb` bundle for the given vault.
263
+ *
264
+ * Pipeline:
265
+ * 1. Resolve or create the compartment's stable bundle handle
266
+ * via `vault.getBundleHandle()` — same handle on
267
+ * every export from the same vault instance, so cloud
268
+ * adapters can use it as a primary key.
269
+ * 2. `vault.dump()` → JSON string with encrypted records
270
+ * inside.
271
+ * 3. UTF-8 encode the dump string.
272
+ * 4. Compress (brotli if available, gzip fallback by default).
273
+ * 5. Compute SHA-256 of the compressed body for integrity.
274
+ * 6. Build the minimum-disclosure header from format version,
275
+ * handle, body length, body sha.
276
+ * 7. Serialize: magic (4) + flags (1) + algo (1) + headerLen (4)
277
+ * + header JSON (N) + compressed body (M).
278
+ *
279
+ * The output is a single `Uint8Array`. Consumers writing to disk
280
+ * pass it to `fs.writeFile`; consumers uploading to cloud storage
281
+ * pass it as the request body. The `@noy-db/file` adapter wraps
282
+ * this with a `saveBundle(path, vault)` helper.
283
+ */
284
+ declare function writeNoydbBundle(vault: Vault, opts?: WriteNoydbBundleOptions): Promise<Uint8Array>;
285
+ /**
286
+ * Read just the bundle header — no body decompression, no
287
+ * integrity verification. Fast (O(prefix + header bytes)) and
288
+ * intended for cloud-listing UIs that want to show the handle and
289
+ * size before downloading the full body.
290
+ *
291
+ * Returns the same `NoydbBundleHeader` shape as the writer, with
292
+ * minimum-disclosure validation already applied.
293
+ */
294
+ declare function readNoydbBundleHeader(bytes: Uint8Array): NoydbBundleHeader;
295
+ /**
296
+ * Read a full `.noydb` bundle: validate magic + header, verify
297
+ * integrity hash over the body bytes, decompress, and return the
298
+ * original `vault.dump()` JSON string ready to pass to
299
+ * `vault.load()`.
300
+ *
301
+ * Throws `BundleIntegrityError` if the body's actual SHA-256 does
302
+ * not match the value declared in the header. Distinct from a
303
+ * format error so consumers can pattern-match in catch blocks
304
+ * (corrupted-in-transit vs malformed-by-producer).
305
+ *
306
+ * Note: this function does NOT take a passphrase. The dump JSON
307
+ * inside the body still contains encrypted records — restoring
308
+ * the vault requires `vault.load(dumpJson, passphrase)`
309
+ * after this call. Splitting the layers keeps the bundle module
310
+ * free of crypto concerns and lets the same code feed format
311
+ * inspectors that never decrypt anything.
312
+ */
313
+ declare function readNoydbBundle(bytes: Uint8Array): Promise<NoydbBundleReadResult>;
314
+
315
+ /**
316
+ * Minimal ULID generator — zero dependencies, Web Crypto API only.
317
+ *
318
+ *. Used by the bundle writer to generate stable opaque
319
+ * handles for `.noydb` containers.
320
+ *
321
+ * **What's a ULID?** A 128-bit identifier encoded as 26 Crockford
322
+ * base32 characters. Layout:
323
+ *
324
+ * ```
325
+ * 01HYABCDEFGHJKMNPQRSTVWXYZ
326
+ * |--------||---------------|
327
+ * 48-bit 80-bit
328
+ * timestamp randomness
329
+ * ```
330
+ *
331
+ * The first 10 chars encode a millisecond Unix timestamp (so ULIDs
332
+ * sort lexicographically by creation time), and the remaining 16
333
+ * chars are random. Crockford base32 omits I/L/O/U to avoid
334
+ * ambiguity in handwriting and URLs.
335
+ *
336
+ * **Why hand-roll instead of pulling in `ulid`?** The package adds
337
+ * a dep, the implementation is ~30 lines, and the bundle module
338
+ * is the only consumer. Adding `ulid` would also drag in its own
339
+ * crypto polyfill that we don't need on Node 18+ or modern
340
+ * browsers.
341
+ *
342
+ * **Privacy consideration:** the timestamp prefix is observable in
343
+ * the bundle header. This is a deliberate trade-off:
344
+ * - Pro: lexicographic sortability lets bundle adapters list
345
+ * newest-first without an extra index.
346
+ * - Con: a casual observer can read the bundle's creation time
347
+ * from the handle. They cannot read it from any OTHER field
348
+ * (the header explicitly forbids `_exported_at`), and a
349
+ * creation timestamp is the same kind of metadata that
350
+ * filesystem mtime would already expose for a downloaded
351
+ * bundle. The leak is therefore equivalent to what's already
352
+ * visible from the file's mtime — not a new exposure.
353
+ *
354
+ * If a future use case needs timestamp-free handles, a v2 of the
355
+ * format could specify "use the random portion only" without a
356
+ * format break — `validateBundleHeader` only checks the regex
357
+ * shape, not the encoded timestamp.
358
+ */
359
+ /**
360
+ * Generate a fresh ULID. Uses `crypto.getRandomValues` for the
361
+ * randomness portion — same Web Crypto API the rest of the
362
+ * codebase uses for IVs and salt.
363
+ *
364
+ * Returns a 26-character string. Calling twice in the same
365
+ * millisecond produces two distinct ULIDs (the random portion
366
+ * differs); ULIDs from the same millisecond are NOT guaranteed
367
+ * to be monotonically ordered relative to each other, only
368
+ * relative to ULIDs from a different millisecond. The bundle
369
+ * format never relies on intra-millisecond ordering.
370
+ */
371
+ declare function generateULID(): string;
372
+ /**
373
+ * Validate that a string is a syntactically well-formed ULID. Used
374
+ * by the bundle header validator. Does NOT verify that the
375
+ * timestamp portion decodes to a sensible date — the format only
376
+ * cares about the encoding shape.
377
+ */
378
+ declare function isULID(value: string): boolean;
379
+
380
+ export { type CompressionAlgo as C, FLAG_COMPRESSED as F, NOYDB_BUNDLE_FORMAT_VERSION as N, type WriteNoydbBundleOptions as W, NOYDB_BUNDLE_MAGIC as a, NOYDB_BUNDLE_PREFIX_BYTES as b, type NoydbBundleHeader as c, type NoydbBundleReadResult as d, readNoydbBundleHeader as e, resetBrotliSupportCache as f, generateULID as g, hasNoydbBundleMagic as h, isULID as i, COMPRESSION_BROTLI as j, COMPRESSION_GZIP as k, COMPRESSION_NONE as l, FLAG_HAS_INTEGRITY_HASH as m, encodeBundleHeader as n, readNoydbBundle as r, validateBundleHeader as v, writeNoydbBundle as w };