@dreamlake/dreamdb 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -0
- package/browser/dreamdb.d.ts +326 -0
- package/browser/dreamdb.js +9 -0
- package/{dreamdb_bg.js → browser/dreamdb_bg.js} +612 -2
- package/browser/dreamdb_bg.wasm +0 -0
- package/browser/dreamdb_bg.wasm.d.ts +56 -0
- package/browser-extras.mjs +193 -0
- package/browser.mjs +4 -0
- package/index.d.ts +541 -1
- package/node/dreamdb.cjs +1762 -0
- package/node/dreamdb.d.cts +425 -0
- package/node/dreamdb_bg.wasm +0 -0
- package/node/dreamdb_bg.wasm.d.ts +72 -0
- package/node.cjs +10 -0
- package/node.mjs +19 -0
- package/package.json +40 -16
- package/web/dreamdb.d.ts +407 -0
- package/web/dreamdb.js +1558 -0
- package/web/dreamdb_bg.wasm +0 -0
- package/web/dreamdb_bg.wasm.d.ts +56 -0
- package/web.mjs +17 -0
- package/dreamdb.d.ts +0 -150
- package/dreamdb.js +0 -9
- package/dreamdb_bg.wasm +0 -0
- package/index.js +0 -6
package/index.d.ts
CHANGED
|
@@ -1,4 +1,445 @@
|
|
|
1
|
-
|
|
1
|
+
// @dreamlake/dreamdb — generated by build.sh from the write-full build's
|
|
2
|
+
// declarations plus the hand-written additions below. Do not edit by hand.
|
|
3
|
+
|
|
4
|
+
// wasm-bindgen emits `[Symbol.dispose]()` on every exported class. That symbol
|
|
5
|
+
// only exists in the `esnext.disposable` lib, so without this reference the
|
|
6
|
+
// package fails to type-check for anyone whose `target` is es2022 or earlier —
|
|
7
|
+
// which is most people, and the error points at our .d.ts rather than at their
|
|
8
|
+
// tsconfig. Referencing the lib here fixes it for the consumer.
|
|
9
|
+
/// <reference lib="esnext.disposable" />
|
|
10
|
+
|
|
11
|
+
/* tslint:disable */
|
|
12
|
+
/* eslint-disable */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Dataset creation, layers, merge, compaction and history.
|
|
16
|
+
*
|
|
17
|
+
* **Node only.** The browser build exports a stub whose every method throws:
|
|
18
|
+
* the index builders it needs cost ~123 KB gzipped and require training data
|
|
19
|
+
* that does not belong in a tab. It is typed on both ends so that code shared
|
|
20
|
+
* between server and client type-checks once.
|
|
21
|
+
*/
|
|
22
|
+
export class Authoring {
|
|
23
|
+
private constructor();
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
/**
|
|
27
|
+
* Add an embedding column whose index artifacts already exist.
|
|
28
|
+
*
|
|
29
|
+
* `spatialIndex` and `compressor` are base32 multihashes of objects the
|
|
30
|
+
* caller has already trained and uploaded (the CLI's `rebuild_exact` /
|
|
31
|
+
* index builders produce them). They are required rather than optional
|
|
32
|
+
* because training an IVF index inside a wasm module means holding the
|
|
33
|
+
* full training set in a 32-bit address space — the failure mode is an
|
|
34
|
+
* allocation abort that reaches JS as a bare `unreachable`.
|
|
35
|
+
*
|
|
36
|
+
* `rerank` stores exact f32 vectors alongside the compressed ones. Leave
|
|
37
|
+
* it on unless you have measured that you can live without it: with it
|
|
38
|
+
* off, reads decode 1-bit reconstructions and relevance degrades in a way
|
|
39
|
+
* no API-level check can see.
|
|
40
|
+
*/
|
|
41
|
+
addEmbeddingLayer(name: string, parent_field: string, dim: number, algorithm: string, spatial_index: string, compressor: string, rerank: boolean, version: number | null | undefined, samples: Array<any>): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Add a field to the schema of an existing dataset.
|
|
44
|
+
*/
|
|
45
|
+
addField(field: any): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Add an image column over an existing field's anchors.
|
|
48
|
+
* `samples` is `[[anchor, Uint8Array], …]`.
|
|
49
|
+
*/
|
|
50
|
+
addImageLayer(name: string, parent_field: string, samples: Array<any>, mime: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Add a scalar column over an existing field's anchors.
|
|
53
|
+
*
|
|
54
|
+
* `samples` is `[[anchor, value], …]`; anchors must already exist in the
|
|
55
|
+
* parent field. `valueType` is one of
|
|
56
|
+
* `int|float|bool|string|categorical|timestamp`.
|
|
57
|
+
*/
|
|
58
|
+
addScalarLayer(name: string, parent_field: string, value_type: string, samples: Array<any>): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Fork the current manifest to a new ref name.
|
|
61
|
+
*/
|
|
62
|
+
branch(new_name: string): Promise<Authoring>;
|
|
63
|
+
/**
|
|
64
|
+
* Collapse per-cell fragments. Returns
|
|
65
|
+
* `{cellsExamined, cellsCompacted, fragmentsCollapsed, manifest?}`.
|
|
66
|
+
*
|
|
67
|
+
* This is the cheapest latency lever there is on a sharded ingest: on the
|
|
68
|
+
* `vision-mixed` corpus it took 32,782 buckets to 3,122 in 1m48s, for no
|
|
69
|
+
* change in results and no extra hardware. `manifest` is absent when
|
|
70
|
+
* nothing needed compacting — a no-op, not a failure.
|
|
71
|
+
*/
|
|
72
|
+
compact(modality: string | null | undefined, threshold: number, max_cells: number): Promise<any>;
|
|
73
|
+
/**
|
|
74
|
+
* Create a new dataset and publish `refs/<name>`.
|
|
75
|
+
*
|
|
76
|
+
* `schema` is an array of field descriptors — see `marshal::schema_from_js`
|
|
77
|
+
* for the accepted shapes.
|
|
78
|
+
*
|
|
79
|
+
* Note the core's own constraint, surfaced rather than papered over:
|
|
80
|
+
* embedding fields declaring `dreamdb.ivf-cosine` / `dreamdb.imi-cosine`
|
|
81
|
+
* cannot be created here, because those index families need training data
|
|
82
|
+
* that does not exist yet at create time. Create with the default
|
|
83
|
+
* `dreamdb.lsh-cosine` and add a trained index as a layer once you have
|
|
84
|
+
* vectors, or build the index with the CLI.
|
|
85
|
+
*/
|
|
86
|
+
static create(name: string, schema: Array<any>, base: string, backend: any): Promise<Authoring>;
|
|
87
|
+
/**
|
|
88
|
+
* Delete a ref. Does not delete the objects it pointed at — they stay
|
|
89
|
+
* reachable by manifest hash, which is what makes this recoverable.
|
|
90
|
+
*/
|
|
91
|
+
deleteRef(name: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Ref names under `refs/`. Requires a backend implementing `list`.
|
|
94
|
+
*/
|
|
95
|
+
listRefs(): Promise<string[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Merge one or more branches into this ref. Returns the new manifest hash.
|
|
98
|
+
*/
|
|
99
|
+
mergeMany(branches: string[]): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Open an existing ref for authoring.
|
|
102
|
+
*/
|
|
103
|
+
static open(uri: string, backend: any): Promise<Authoring>;
|
|
104
|
+
/**
|
|
105
|
+
* Set a human-readable description on the dataset.
|
|
106
|
+
*/
|
|
107
|
+
setDescription(text: string): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* A `Writer` sharing this handle — for append/commit/snapshot.
|
|
110
|
+
*/
|
|
111
|
+
writer(): Writer;
|
|
112
|
+
/**
|
|
113
|
+
* The ref this handle writes to.
|
|
114
|
+
*/
|
|
115
|
+
readonly refName: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A `fetch`-backed backend rooted at a base URL.
|
|
120
|
+
*/
|
|
121
|
+
export class S3Backend {
|
|
122
|
+
free(): void;
|
|
123
|
+
[Symbol.dispose](): void;
|
|
124
|
+
/**
|
|
125
|
+
* Fetch `path` (relative to the base URL) and resolve to its bytes.
|
|
126
|
+
* `opts.noCache` is accepted for API compatibility (currently a no-op:
|
|
127
|
+
* content is hash-addressed; refs are read fresh each page load anyway).
|
|
128
|
+
*/
|
|
129
|
+
get(path: string, _opts: any): Promise<Uint8Array>;
|
|
130
|
+
/**
|
|
131
|
+
* List object paths under `prefix`. Stub (returns empty); the current
|
|
132
|
+
* consumer read paths don't require listing.
|
|
133
|
+
*/
|
|
134
|
+
list(_prefix: string): Promise<Array<any>>;
|
|
135
|
+
/**
|
|
136
|
+
* Construct rooted at `base_url` (trailing slash trimmed).
|
|
137
|
+
*/
|
|
138
|
+
constructor(base_url: string);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export class Space {
|
|
142
|
+
private constructor();
|
|
143
|
+
free(): void;
|
|
144
|
+
[Symbol.dispose](): void;
|
|
145
|
+
/**
|
|
146
|
+
* Open a Space from a `.../refs/<name>` or `.../manifests/<hash>` URI,
|
|
147
|
+
* resolving the ref (if any) and loading the manifest. If `backend` is
|
|
148
|
+
* provided it handles IO (relative paths); otherwise a direct-fetch
|
|
149
|
+
* connector rooted at the parsed base URL is used (the `dreamdb-demo`
|
|
150
|
+
* no-backend path).
|
|
151
|
+
*/
|
|
152
|
+
static fromUri(uri: string, backend: any): Promise<Space>;
|
|
153
|
+
/**
|
|
154
|
+
* Walk the manifest DAG from HEAD, up to `max_depth` entries. Each entry:
|
|
155
|
+
* `{ manifestHash, ts, writer, tracks: [{modality, address}] }`.
|
|
156
|
+
*/
|
|
157
|
+
history(max_depth?: number | null): Promise<Array<any>>;
|
|
158
|
+
/**
|
|
159
|
+
* Hybrid search fusing a lexical (BM25) sub-query and a dense (vector)
|
|
160
|
+
* sub-query per spec/0015 §5/§6. Returns the fused `[{ anchor, score }]`
|
|
161
|
+
* list sorted by fused score descending — the same scored shape as
|
|
162
|
+
* `queryVector`.
|
|
163
|
+
*
|
|
164
|
+
* `vector` is the dense sub-query embedding (a `Float32Array`). `opts` is a
|
|
165
|
+
* plain JS object:
|
|
166
|
+
* ```js
|
|
167
|
+
* {
|
|
168
|
+
* textField, textQuery, // BM25 sub-query (required)
|
|
169
|
+
* vectorField, // dense field the `vector` targets (required)
|
|
170
|
+
* topK = 10, // fused results to return
|
|
171
|
+
* fusion = 'rrf', // 'rrf' | 'linear' | 'max' | 'pareto'
|
|
172
|
+
* rrfK = 60, // RRF rank constant (fusion='rrf')
|
|
173
|
+
* textWeight = 1, vectorWeight = 1, // Linear weights (fusion='linear')
|
|
174
|
+
* textK = topK, vectorK = topK, // per-sub-query candidate depths
|
|
175
|
+
* textRequired = false, vectorRequired = false, // §5.3 boolean-AND gates
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_hybrid`.
|
|
180
|
+
* (v0 does not expose the optional scalar pre/post-filter; it runs with no
|
|
181
|
+
* scalar gate.)
|
|
182
|
+
*/
|
|
183
|
+
queryHybrid(vector: Float32Array, opts: any): Promise<Array<any>>;
|
|
184
|
+
/**
|
|
185
|
+
* Scalar-index lookup: every anchor whose `field` satisfies `op value`
|
|
186
|
+
* (spec/0011). Returns a `BigUint64Array`-style `Array` of anchors,
|
|
187
|
+
* tombstone-suppressed, sorted ascending and deduped.
|
|
188
|
+
*
|
|
189
|
+
* This is the expansion half of a compact lexical index. A BM25 index
|
|
190
|
+
* built over a scalar field's DISTINCT values returns one representative
|
|
191
|
+
* anchor per matched value; resolving that value back to *every* record
|
|
192
|
+
* carrying it is a scalar-index lookup, not a text-index concern. Keeping
|
|
193
|
+
* the split this way is what lets the text index stay small enough to
|
|
194
|
+
* load in a browser — indexing one document per record instead produced a
|
|
195
|
+
* 406 MB object for ~1,700 distinct strings.
|
|
196
|
+
*
|
|
197
|
+
* `op` is one of `==`, `!=`, `<`, `<=`, `>`, `>=`. `value` may be a
|
|
198
|
+
* string, number, or boolean; strings match both `String` and
|
|
199
|
+
* `Categorical` scalar fields.
|
|
200
|
+
*/
|
|
201
|
+
queryScalar(field: string, op: string, value: any): Promise<Array<any>>;
|
|
202
|
+
/**
|
|
203
|
+
* Lexical BM25 text search over a text `field` (spec/0015 §3.6).
|
|
204
|
+
*
|
|
205
|
+
* Tokenizes `query` with the built-in `dreamdb.utf8-words` tokenizer
|
|
206
|
+
* (lowercase + split on non-alphanumeric — pure Rust, compiled into the
|
|
207
|
+
* wasm; no external model needed even though the field's embeddings were
|
|
208
|
+
* produced elsewhere), scores docs with BM25, and suppresses tombstoned
|
|
209
|
+
* anchors. Returns `[{ anchor, score }]` sorted by score descending — the
|
|
210
|
+
* same scored shape as `queryVector`.
|
|
211
|
+
*
|
|
212
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_text`.
|
|
213
|
+
*/
|
|
214
|
+
queryText(field: string, query: string, top_k: number): Promise<Array<any>>;
|
|
215
|
+
/**
|
|
216
|
+
* Top-K cosine vector search over an embedding `field`. `opts` may be a
|
|
217
|
+
* number (topK) or `{ topK?, probeCount? }`. Returns `[{ anchor, score }]`
|
|
218
|
+
* sorted by score descending — the shape dreamdb-ts's `queryVector` yields.
|
|
219
|
+
*
|
|
220
|
+
* Delegates to the real (tested) `dreamdb-dataset` query path: ADC cull +
|
|
221
|
+
* two-pass rerank + HotShard merge + tombstone suppression.
|
|
222
|
+
*/
|
|
223
|
+
queryVector(field: string, query: Float32Array, opts: any): Promise<Array<any>>;
|
|
224
|
+
/**
|
|
225
|
+
* Read a scalar track as a `Map<anchorString, value>`. Single-anchor
|
|
226
|
+
* entries resolve from the track index; multi-anchor entries fetch (and
|
|
227
|
+
* de-dupe) their bucket and roaring-decode the anchor set.
|
|
228
|
+
*/
|
|
229
|
+
readScalarColumn(track: any, _opts: any): Promise<Map<any, any>>;
|
|
230
|
+
/**
|
|
231
|
+
* Fetch a track object and return its `object_index` (array of CBOR
|
|
232
|
+
* entries). Inline indexes only — paged indexes are not resolved (matching
|
|
233
|
+
* dreamdb-ts, which also doesn't support them on this path).
|
|
234
|
+
*/
|
|
235
|
+
resolveObjectIndex(track: any): Promise<Array<any>>;
|
|
236
|
+
/**
|
|
237
|
+
* Base32 hash of the manifest's first timeline.
|
|
238
|
+
*/
|
|
239
|
+
timelineId(): string;
|
|
240
|
+
/**
|
|
241
|
+
* Find a track by its resolved `key` or by `modality`.
|
|
242
|
+
*/
|
|
243
|
+
trackFor(key_or_modality: string): any;
|
|
244
|
+
/**
|
|
245
|
+
* List resolved tracks from this manifest.
|
|
246
|
+
*/
|
|
247
|
+
tracks(): Array<any>;
|
|
248
|
+
/**
|
|
249
|
+
* The base URL objects are fetched relative to (consumers build their own
|
|
250
|
+
* object URLs from this — e.g. `dreamdb-demo`'s track readers).
|
|
251
|
+
*/
|
|
252
|
+
readonly connectorBase: string;
|
|
253
|
+
/**
|
|
254
|
+
* The manifest's base32 multihash.
|
|
255
|
+
*/
|
|
256
|
+
readonly manifestHash: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* A write handle onto a ref.
|
|
261
|
+
*/
|
|
262
|
+
export class Writer {
|
|
263
|
+
private constructor();
|
|
264
|
+
free(): void;
|
|
265
|
+
[Symbol.dispose](): void;
|
|
266
|
+
/**
|
|
267
|
+
* Append records and commit in one call.
|
|
268
|
+
*
|
|
269
|
+
* `samples` is an array of `{ anchor?: bigint|number, <field>: value }`.
|
|
270
|
+
* See `marshal::samples_from_js` for the accepted field shapes.
|
|
271
|
+
*
|
|
272
|
+
* Committing here rather than exposing a separate staged mode is
|
|
273
|
+
* deliberate for the browser surface: a staged write that is never
|
|
274
|
+
* committed leaves uploaded objects unreferenced, and a tab can close at
|
|
275
|
+
* any moment. `appendStaged` exists on the Node surface where the process
|
|
276
|
+
* lifetime is under the caller's control.
|
|
277
|
+
*/
|
|
278
|
+
appendMany(samples: Array<any>): Promise<number>;
|
|
279
|
+
/**
|
|
280
|
+
* Flush staged entries and publish a new manifest.
|
|
281
|
+
*
|
|
282
|
+
* Fails with a CAS conflict if the ref moved underneath this writer. That
|
|
283
|
+
* is not retried automatically: an automatic retry would hide a logical
|
|
284
|
+
* conflict, and the caller is the only one who knows whether re-applying
|
|
285
|
+
* its records on top of the new head is correct.
|
|
286
|
+
*/
|
|
287
|
+
commit(): Promise<string>;
|
|
288
|
+
/**
|
|
289
|
+
* Tombstone records by anchor. Returns the new manifest hash.
|
|
290
|
+
*/
|
|
291
|
+
deleteRecords(anchors: BigUint64Array, reason?: string | null): Promise<string>;
|
|
292
|
+
/**
|
|
293
|
+
* Open a ref for writing.
|
|
294
|
+
*
|
|
295
|
+
* `uri` is the same `.../refs/<name>` form `Space.fromUri` takes; a
|
|
296
|
+
* `.../manifests/<hash>` URI is rejected rather than silently opening
|
|
297
|
+
* something unwritable, because a manifest hash names an immutable
|
|
298
|
+
* snapshot — there is nothing for a commit to advance.
|
|
299
|
+
*
|
|
300
|
+
* `backend` must implement `put` (Backend contract v2). Passing a
|
|
301
|
+
* read-only backend fails at the first write with a clear message rather
|
|
302
|
+
* than here, since the connector cannot know what the JS object omits
|
|
303
|
+
* until it calls it.
|
|
304
|
+
*/
|
|
305
|
+
static open(uri: string, backend: any): Promise<Writer>;
|
|
306
|
+
/**
|
|
307
|
+
* Tag the current manifest with an immutable label (`refs/<ref>@<label>`).
|
|
308
|
+
*/
|
|
309
|
+
snapshot(label: string): Promise<string>;
|
|
310
|
+
/**
|
|
311
|
+
* Current manifest hash, base32.
|
|
312
|
+
*/
|
|
313
|
+
readonly manifestHash: string;
|
|
314
|
+
/**
|
|
315
|
+
* The ref this writer advances.
|
|
316
|
+
*/
|
|
317
|
+
readonly refName: string;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Install a panic hook that logs the panic message AND its `file:line:col`
|
|
322
|
+
* to the console before the wasm trap surfaces to JS.
|
|
323
|
+
*
|
|
324
|
+
* Without this, every Rust panic reaches JavaScript as a bare
|
|
325
|
+
* `RuntimeError: unreachable` with nothing but wasm frame offsets — and it is
|
|
326
|
+
* indistinguishable from an allocation failure, since Rust's alloc-error
|
|
327
|
+
* handler also aborts. That ambiguity cost real debugging time: a browser
|
|
328
|
+
* `unreachable` from exhausting wasm32's 32-bit address space on an oversized
|
|
329
|
+
* index was initially read as an integer-overflow panic.
|
|
330
|
+
*
|
|
331
|
+
* Zero new deps — uses the already-enabled `web-sys` `console` feature.
|
|
332
|
+
* Runs once at module init.
|
|
333
|
+
*/
|
|
334
|
+
export function __wasm_init(): void;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Parse an object path and re-format it. Byte-identity of the result is the
|
|
338
|
+
* actual assertion: a parser that silently drops a component still "parses".
|
|
339
|
+
*/
|
|
340
|
+
export function addressRoundTrip(path: string): string;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The address variant name (`Genesis`, `Manifest`, `Ref`, …) for a path.
|
|
344
|
+
*
|
|
345
|
+
* Derived from the Debug representation rather than a hand-written match.
|
|
346
|
+
* `DreamDbAddress` has seventeen variants and gains one whenever the protocol
|
|
347
|
+
* does; a match arm per variant would be a second list to keep in sync, and
|
|
348
|
+
* the vectors only ever assert the name.
|
|
349
|
+
*/
|
|
350
|
+
export function addressVariant(path: string): string;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Encode arbitrary bytes as lowercase RFC-4648 base32 (no padding).
|
|
354
|
+
*
|
|
355
|
+
* Byte-identical to `dreamdb-ts`'s `bytesToBase32` (alphabet
|
|
356
|
+
* `abcdefghijklmnopqrstuvwxyz234567`) and to `dreamdb_core`'s multihash
|
|
357
|
+
* `to_base32`, which is how object addresses are spelled on disk.
|
|
358
|
+
*/
|
|
359
|
+
export function bytesToBase32(bytes: Uint8Array): string;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Decode a single CBOR value from `bytes` into its JS representation.
|
|
363
|
+
*/
|
|
364
|
+
export function decodeCbor(bytes: Uint8Array): any;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Canonically encode a JS value as CBOR, returning the bytes.
|
|
368
|
+
*
|
|
369
|
+
* Canonical here means what spec/0002 §3.1 means: map keys sorted by their
|
|
370
|
+
* encoded bytes, shortest-form integers, no indefinite lengths. Two writers
|
|
371
|
+
* that disagree on this produce different content hashes for the same logical
|
|
372
|
+
* object, and every address derived from them diverges.
|
|
373
|
+
*/
|
|
374
|
+
export function encodeCbor(value: any): Uint8Array;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Parse a modality tag into `{class, encoding, trackKind, objectKind, params,
|
|
378
|
+
* flags}`, or throw if it is invalid.
|
|
379
|
+
*
|
|
380
|
+
* `params` is a plain object of the `key=value` segments and `flags` an array
|
|
381
|
+
* of the bare ones (`bucketed`, `graph`). They are separate because the
|
|
382
|
+
* grammar treats them differently and merging them would make a flag
|
|
383
|
+
* indistinguishable from a parameter whose value happened to be empty.
|
|
384
|
+
*/
|
|
385
|
+
export function modalityParse(tag: string): any;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* BLAKE3-256 multihash of `bytes`, base32 (the form used in object paths).
|
|
389
|
+
*/
|
|
390
|
+
export function multihashBase32(bytes: Uint8Array): string;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* BLAKE3-256 multihash of `bytes` as lowercase hex (33 bytes: tag + digest).
|
|
394
|
+
*/
|
|
395
|
+
export function multihashHex(bytes: Uint8Array): string;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* DreamDB's half-open `[start, end)` → an HTTP `Range` header value.
|
|
399
|
+
*
|
|
400
|
+
* The off-by-one here is worth a vector of its own: HTTP ranges are
|
|
401
|
+
* *inclusive* of the end byte. Getting it wrong reads one byte too few from
|
|
402
|
+
* every object, which corrupts decode in ways that look like anything but an
|
|
403
|
+
* off-by-one.
|
|
404
|
+
*/
|
|
405
|
+
export function rangeHeader(start: bigint, end: bigint): string;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Round-trip a spatial key through its base-2 form, per spec/0002 §6.
|
|
409
|
+
*
|
|
410
|
+
* Returns the re-encoded string, so a caller can assert byte-identity rather
|
|
411
|
+
* than merely "it parsed".
|
|
412
|
+
*/
|
|
413
|
+
export function spatialKeyRoundTrip(bits: string): string;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* The 16-char hex address form → TimeAnchor. Throws on a malformed input
|
|
417
|
+
* (wrong length, uppercase) rather than coercing it.
|
|
418
|
+
*/
|
|
419
|
+
export function timeAnchorFromHex(s: string): bigint;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* TimeAnchor → the 16-char hex used in addresses.
|
|
423
|
+
*/
|
|
424
|
+
export function timeAnchorHex(value: bigint): string;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Which time bucket an anchor falls in, given a duration like `"1s"`/`"60s"`.
|
|
428
|
+
*/
|
|
429
|
+
export function timeBucket(t_start: bigint, duration: string): bigint;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Package version — useful for consumers to confirm which build is loaded.
|
|
433
|
+
*/
|
|
434
|
+
export function version(): string;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* The all-zero spatial-key path segment used for non-spatial (fragment) object
|
|
438
|
+
* addresses. Matches `dreamdb-ts`'s `ZERO_SPATIAL_KEY` constant exactly.
|
|
439
|
+
*/
|
|
440
|
+
export function zeroSpatialKey(): string;
|
|
441
|
+
|
|
442
|
+
// ── hand-written additions ──────────────────────────────────────────────────
|
|
2
443
|
|
|
3
444
|
/** Zero spatial-key path segment for non-spatial (fragment) object addresses. */
|
|
4
445
|
export const ZERO_SPATIAL_KEY: string
|
|
@@ -14,3 +455,102 @@ export interface ResolvedTrack {
|
|
|
14
455
|
timeline: string
|
|
15
456
|
coverage: unknown
|
|
16
457
|
}
|
|
458
|
+
|
|
459
|
+
/** Outcome of a conditional write. */
|
|
460
|
+
export type PutStatus = 'created' | 'exists' | 'casFailed'
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Backend contract v2 — the IO surface the SDK calls into.
|
|
464
|
+
*
|
|
465
|
+
* `get` is the only required method; a backend with just `get` is the v1
|
|
466
|
+
* read-only shape and still works for reading. Write entry points check for
|
|
467
|
+
* `put` up front and refuse with a message naming what is missing, because
|
|
468
|
+
* discovering it mid-commit leaves unreferenced objects in the bucket.
|
|
469
|
+
*
|
|
470
|
+
* The ETag is not decoration. `publish` picks `If-Match: <etag>` when it knows
|
|
471
|
+
* the ref's current version and `If-None-Match: *` when it does not — so a
|
|
472
|
+
* backend that never returns an ETag silently downgrades every ref update to
|
|
473
|
+
* create-only, and the *second* commit to a ref fails while the first
|
|
474
|
+
* succeeded. On S3 that also requires `ExposeHeaders: ["ETag"]` in the bucket's
|
|
475
|
+
* CORS rule; without it the browser cannot read the header at all.
|
|
476
|
+
*/
|
|
477
|
+
export interface Backend {
|
|
478
|
+
/** Inclusive byte range. Returning a bare Uint8Array is the accepted v1 shape. */
|
|
479
|
+
get(
|
|
480
|
+
path: string,
|
|
481
|
+
range?: { start: number; end: number },
|
|
482
|
+
): Promise<Uint8Array | { bytes: Uint8Array; etag?: string }>
|
|
483
|
+
|
|
484
|
+
head?(path: string): Promise<{ exists?: boolean; etag?: string; size?: number }>
|
|
485
|
+
|
|
486
|
+
put?(
|
|
487
|
+
path: string,
|
|
488
|
+
bytes: Uint8Array,
|
|
489
|
+
opts?: { ifMatch?: string; ifNoneMatchStar?: boolean },
|
|
490
|
+
): Promise<{ status: PutStatus; etag?: string }>
|
|
491
|
+
|
|
492
|
+
delete?(path: string): Promise<void>
|
|
493
|
+
|
|
494
|
+
list?(prefix: string): Promise<string[]>
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Options for {@link PresignedBackend}. */
|
|
498
|
+
export interface PresignedBackendOptions {
|
|
499
|
+
/** Base URL reads are issued against. */
|
|
500
|
+
readBase: string
|
|
501
|
+
/**
|
|
502
|
+
* Mint presigned URLs for a batch of paths. One commit writes buckets,
|
|
503
|
+
* tracks, a manifest and a ref — signing them individually turns a commit
|
|
504
|
+
* into N server round trips.
|
|
505
|
+
*/
|
|
506
|
+
mintPut(
|
|
507
|
+
paths: string[],
|
|
508
|
+
opts?: { ifMatch?: string },
|
|
509
|
+
): Promise<Record<string, { url: string; headers?: Record<string, string> }>>
|
|
510
|
+
/**
|
|
511
|
+
* Server-side conditional write of the 33-byte ref object. Required for the
|
|
512
|
+
* default `refStrategy: 'proxy'`.
|
|
513
|
+
*/
|
|
514
|
+
commitRef?(
|
|
515
|
+
path: string,
|
|
516
|
+
opts: { ifMatch?: string; ifNoneMatchStar?: boolean },
|
|
517
|
+
bytes: Uint8Array,
|
|
518
|
+
): Promise<{ status: PutStatus; etag?: string }>
|
|
519
|
+
/**
|
|
520
|
+
* `'proxy'` (default) has your server perform the ref's conditional PUT with
|
|
521
|
+
* real credentials — identical behaviour on S3, R2, MinIO and GCS.
|
|
522
|
+
* `'presign'` signs a conditional PUT and sends it from the browser: fewer
|
|
523
|
+
* moving parts, but whether `If-Match` survives presigning is
|
|
524
|
+
* provider-specific and GCS uses `x-goog-if-generation-match` instead.
|
|
525
|
+
*/
|
|
526
|
+
refStrategy?: 'proxy' | 'presign'
|
|
527
|
+
/** Override read URL construction. */
|
|
528
|
+
readUrl?(path: string): string
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Browser Backend that reads over `fetch` and writes through short-lived
|
|
533
|
+
* presigned URLs minted by your server. Credentials never enter the browser.
|
|
534
|
+
*
|
|
535
|
+
* Browser and web entry points only — see {@link PresignedBackendOptions}.
|
|
536
|
+
*/
|
|
537
|
+
export class PresignedBackend implements Backend {
|
|
538
|
+
constructor(options: PresignedBackendOptions)
|
|
539
|
+
get(path: string, range?: { start: number; end: number }): Promise<{ bytes: Uint8Array; etag?: string }>
|
|
540
|
+
head(path: string): Promise<{ exists?: boolean; etag?: string; size?: number }>
|
|
541
|
+
put(
|
|
542
|
+
path: string,
|
|
543
|
+
bytes: Uint8Array,
|
|
544
|
+
opts?: { ifMatch?: string; ifNoneMatchStar?: boolean },
|
|
545
|
+
): Promise<{ status: PutStatus; etag?: string }>
|
|
546
|
+
// No `delete`: object deletion is not part of the browser write channel.
|
|
547
|
+
// `deleteRecords` writes tombstones, and dropping a ref is Node-only.
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Fetch and instantiate the wasm module.
|
|
552
|
+
*
|
|
553
|
+
* Exported only from `@dreamlake/dreamdb/web`, the no-bundler entry point. The
|
|
554
|
+
* bundler and Node builds instantiate themselves and have nothing to await.
|
|
555
|
+
*/
|
|
556
|
+
export default function ready(input?: unknown): Promise<unknown>
|