@dreamlake/dreamdb 0.1.0 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @dreamlake/dreamdb
2
+
3
+ TypeScript driver for [DreamDB](https://dreamdb.dreamlake.ai) — a storage and retrieval protocol for multimodal signals anchored to a shared timeline.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @dreamlake/dreamdb
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```typescript
14
+ import { Dataset, Schema, MemoryBackend } from '@dreamlake/dreamdb'
15
+
16
+ // Define a schema
17
+ const schema = new Schema()
18
+ schema.addEmbedding('embedding', 16)
19
+ schema.addImage('image', 'jpeg')
20
+ schema.addScalarCategorical('label')
21
+
22
+ // Create a dataset (in-memory for testing, or use S3Backend for production)
23
+ const backend = new MemoryBackend()
24
+ const ds = await Dataset.create('my-dataset', schema, backend)
25
+
26
+ // Append samples
27
+ await ds.appendMany([
28
+ { embedding: new Float32Array([...]), image: new Uint8Array([...]), label: 'cat' },
29
+ { embedding: new Float32Array([...]), image: new Uint8Array([...]), label: 'dog' },
30
+ ])
31
+
32
+ // Vector query — find the 5 nearest neighbors
33
+ const batches = await ds.iterVector({
34
+ field: 'embedding',
35
+ query: new Float32Array([...]),
36
+ topK: 5,
37
+ })
38
+ ```
39
+
40
+ ## Browser usage
41
+
42
+ ```typescript
43
+ import { S3Backend, Space } from '@dreamlake/dreamdb'
44
+
45
+ const backend = new S3Backend('https://your-bucket.s3.amazonaws.com')
46
+ const space = new Space(backend)
47
+
48
+ // Resolve a ref to its manifest
49
+ const manifest = await space.resolveRef('my-dataset')
50
+ console.log(manifest.tracks)
51
+ ```
52
+
53
+ ## Documentation
54
+
55
+ - [Installation](https://dreamdb.dreamlake.ai/installation)
56
+ - [TypeScript SDK Reference](https://dreamdb.dreamlake.ai/typescript-sdk)
57
+ - [Protocol Specification](https://dreamdb.dreamlake.ai/spec-overview)
58
+ - [Browser Demo](https://demo.dreamdb.dreamlake.ai)
59
+
60
+ ## License
61
+
62
+ MIT
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ __export(index_exports, {
27
27
  SCALAR_ENCODING_MAP: () => SCALAR_ENCODING_MAP,
28
28
  Schema: () => Schema,
29
29
  Space: () => Space,
30
+ ZERO_SPATIAL_KEY: () => ZERO_SPATIAL_KEY,
30
31
  base32ToBytes: () => base32ToBytes,
31
32
  bitsFromProjections: () => bitsFromProjections,
32
33
  bitsToBase2: () => bitsToBase2,
@@ -376,16 +377,33 @@ var S3Backend = class {
376
377
  return path;
377
378
  }
378
379
  async list(prefix) {
379
- const url = `${this.baseUrl}?list-type=2&prefix=${encodeURIComponent(prefix)}`;
380
- const r = await fetch(url);
381
- if (!r.ok) throw new Error(`LIST ${url}: HTTP ${r.status}`);
382
- const text = await r.text();
383
380
  const keys = [];
384
- const regex = /<Key>([^<]+)<\/Key>/g;
385
- let match;
386
- while ((match = regex.exec(text)) !== null) {
387
- keys.push(match[1]);
388
- }
381
+ let continuationToken;
382
+ do {
383
+ let url = `${this.baseUrl}?list-type=2&prefix=${encodeURIComponent(prefix)}`;
384
+ if (continuationToken) {
385
+ url += `&continuation-token=${encodeURIComponent(continuationToken)}`;
386
+ }
387
+ const r = await fetch(url);
388
+ if (!r.ok) throw new Error(`LIST ${url}: HTTP ${r.status}`);
389
+ const text = await r.text();
390
+ const regex = /<Key>([^<]+)<\/Key>/g;
391
+ let match;
392
+ while ((match = regex.exec(text)) !== null) {
393
+ keys.push(match[1]);
394
+ }
395
+ const truncatedMatch = text.match(/<IsTruncated>(\w+)<\/IsTruncated>/);
396
+ const isTruncated = truncatedMatch?.[1] === "true";
397
+ if (isTruncated) {
398
+ const tokenMatch = text.match(
399
+ /<NextContinuationToken>([^<]+)<\/NextContinuationToken>/
400
+ );
401
+ continuationToken = tokenMatch?.[1];
402
+ if (!continuationToken) break;
403
+ } else {
404
+ continuationToken = void 0;
405
+ }
406
+ } while (continuationToken);
389
407
  return keys;
390
408
  }
391
409
  async delete(path) {
@@ -1365,6 +1383,17 @@ var Space = class _Space {
1365
1383
  }
1366
1384
  };
1367
1385
 
1386
+ // src/types.ts
1387
+ var ZERO_SPATIAL_KEY = "0000000000000000";
1388
+ var SCALAR_ENCODING_MAP = {
1389
+ categorical: "cat",
1390
+ bool: "bool",
1391
+ int: "i64",
1392
+ float: "f64",
1393
+ string: "str",
1394
+ timestamp: "ts"
1395
+ };
1396
+
1368
1397
  // src/dataset.ts
1369
1398
  var Schema = class {
1370
1399
  fields = [];
@@ -1674,7 +1703,7 @@ var Dataset = class _Dataset {
1674
1703
  const fragHash = contentHash(data);
1675
1704
  const fragHashB32 = bytesToBase32(fragHash);
1676
1705
  await this.backend.put(
1677
- `${this._timelineHash}/${modality}/0000000000000000/${fragHashB32}`,
1706
+ `${this._timelineHash}/${modality}/${ZERO_SPATIAL_KEY}/${fragHashB32}`,
1678
1707
  data
1679
1708
  );
1680
1709
  newEntries.push([
@@ -1922,7 +1951,7 @@ var Dataset = class _Dataset {
1922
1951
  const fragHash = bytesToBase32(e[3]);
1923
1952
  try {
1924
1953
  const fragBytes = await this.backend.get(
1925
- `${this._timelineHash}/${bfMod}/0000000000000000/${fragHash}`
1954
+ `${this._timelineHash}/${bfMod}/${ZERO_SPATIAL_KEY}/${fragHash}`
1926
1955
  );
1927
1956
  fieldData.set(tStart, fragBytes);
1928
1957
  } catch {
@@ -2225,16 +2254,6 @@ function schemaFromCbor(obj) {
2225
2254
  }
2226
2255
  return schema;
2227
2256
  }
2228
-
2229
- // src/types.ts
2230
- var SCALAR_ENCODING_MAP = {
2231
- categorical: "cat",
2232
- bool: "bool",
2233
- int: "i64",
2234
- float: "f64",
2235
- string: "str",
2236
- timestamp: "ts"
2237
- };
2238
2257
  // Annotate the CommonJS export names for ESM import in node:
2239
2258
  0 && (module.exports = {
2240
2259
  Dataset,
@@ -2244,6 +2263,7 @@ var SCALAR_ENCODING_MAP = {
2244
2263
  SCALAR_ENCODING_MAP,
2245
2264
  Schema,
2246
2265
  Space,
2266
+ ZERO_SPATIAL_KEY,
2247
2267
  base32ToBytes,
2248
2268
  bitsFromProjections,
2249
2269
  bitsToBase2,