@taladb/web 0.9.3 → 0.9.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taladb/web",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "TalaDB WASM bindings — document queries and vector search in the browser",
5
5
  "main": "pkg/taladb_web.js",
6
6
  "types": "pkg/taladb_web.d.ts",
package/pkg/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "thinkgrid-labs"
6
6
  ],
7
7
  "description": "TalaDB browser WASM bindings (wasm-bindgen + OPFS) and Cloudflare Workers",
8
- "version": "0.9.3",
8
+ "version": "0.9.4",
9
9
  "license": "MIT",
10
10
  "files": [
11
11
  "taladb_web_bg.wasm",
@@ -36,6 +36,10 @@ export class CollectionWasm {
36
36
  * Delete all matching documents. Returns the count deleted.
37
37
  */
38
38
  deleteMany(filter: any): number;
39
+ /**
40
+ * Delete many documents by id, in one commit. Returns the number removed.
41
+ */
42
+ deleteManyWithIds(ids: any, origin: string): number;
39
43
  /**
40
44
  * Delete the first matching document. Returns true if deleted.
41
45
  */
@@ -77,6 +81,18 @@ export class CollectionWasm {
77
81
  * Insert multiple documents. Returns an array of ULID string ids.
78
82
  */
79
83
  insertMany(docs: any): any;
84
+ /**
85
+ * Upsert many documents **by caller-supplied `_id`**, in one commit.
86
+ *
87
+ * Unlike [`Self::insert_many`] — which mints a fresh ULID and discards `_id` —
88
+ * this honours the id on each document, which is what lets replication address
89
+ * a remote row by a *derived* id so repeated fetches converge on one document
90
+ * instead of duplicating it.
91
+ *
92
+ * `origin` is `"remote"` for authoritative rows replicated in from an origin,
93
+ * or `"local"` for ordinary user writes.
94
+ */
95
+ replaceManyWithIds(docs: any, origin: string): any;
80
96
  /**
81
97
  * Update all matching documents. Returns the count updated.
82
98
  */
@@ -211,6 +227,10 @@ export class WorkerDB {
211
227
  * Delete all matching documents. Returns the count deleted.
212
228
  */
213
229
  deleteMany(collection: string, filter_json: string): number;
230
+ /**
231
+ * Delete many documents by id, in one commit. Returns the number removed.
232
+ */
233
+ deleteManyWithIds(collection: string, ids_json: string, origin: string): number;
214
234
  /**
215
235
  * Delete the first matching document. Returns `true` / `false`.
216
236
  */
@@ -355,6 +375,19 @@ export class WorkerDB {
355
375
  * of `{ document, reason, changedAt }`.
356
376
  */
357
377
  quarantined(collection: string): string;
378
+ /**
379
+ * Upsert many documents **by caller-supplied `_id`**, in one commit.
380
+ *
381
+ * Unlike `insert_many` — which discards `_id` and mints a fresh ULID — this
382
+ * honours the id in each document. That is what lets the replication
383
+ * coordinator address a remote row by a *derived* id (see `deriveDocId`) and
384
+ * have repeated fetches converge on one document instead of duplicating it.
385
+ *
386
+ * `origin` is `"remote"` for authoritative rows replicated in from an origin,
387
+ * or `"local"` for ordinary user writes. Remote rows are marked so they can
388
+ * never replicate back out — see `Collection::replace_many_with_ids`.
389
+ */
390
+ replaceManyWithIds(collection: string, docs_json: string, origin: string): string;
358
391
  /**
359
392
  * Set write durability: `eventual = true` batches OPFS fsyncs for
360
393
  * throughput (call `flush()` to force), `false` (default) fsyncs each
@@ -453,6 +486,7 @@ export interface InitOutput {
453
486
  readonly workerdb_createIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
454
487
  readonly workerdb_createVectorIndex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number];
455
488
  readonly workerdb_deleteMany: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
489
+ readonly workerdb_deleteManyWithIds: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
456
490
  readonly workerdb_deleteOne: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
457
491
  readonly workerdb_dropCompoundIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
458
492
  readonly workerdb_dropFtsIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
@@ -476,6 +510,7 @@ export interface InitOutput {
476
510
  readonly workerdb_openWithOpfs: (a: any) => [number, number, number];
477
511
  readonly workerdb_openWithSnapshot: (a: number, b: number) => [number, number, number];
478
512
  readonly workerdb_quarantined: (a: number, b: number, c: number) => [number, number, number, number];
513
+ readonly workerdb_replaceManyWithIds: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
479
514
  readonly workerdb_setDurability: (a: number, b: number) => void;
480
515
  readonly workerdb_setUserVersion: (a: number, b: number) => [number, number];
481
516
  readonly workerdb_syncPending: (a: number) => bigint;
@@ -492,6 +527,7 @@ export interface InitOutput {
492
527
  readonly collectionwasm_createIndex: (a: number, b: number, c: number) => [number, number];
493
528
  readonly collectionwasm_createVectorIndex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number];
494
529
  readonly collectionwasm_deleteMany: (a: number, b: any) => [number, number, number];
530
+ readonly collectionwasm_deleteManyWithIds: (a: number, b: any, c: number, d: number) => [number, number, number];
495
531
  readonly collectionwasm_deleteOne: (a: number, b: any) => [number, number, number];
496
532
  readonly collectionwasm_dropCompoundIndex: (a: number, b: number, c: number) => [number, number];
497
533
  readonly collectionwasm_dropIndex: (a: number, b: number, c: number) => [number, number];
@@ -501,6 +537,7 @@ export interface InitOutput {
501
537
  readonly collectionwasm_findOne: (a: number, b: any) => [number, number, number];
502
538
  readonly collectionwasm_insert: (a: number, b: any) => [number, number, number, number];
503
539
  readonly collectionwasm_insertMany: (a: number, b: any) => [number, number, number];
540
+ readonly collectionwasm_replaceManyWithIds: (a: number, b: any, c: number, d: number) => [number, number, number];
504
541
  readonly collectionwasm_updateMany: (a: number, b: any, c: any) => [number, number, number];
505
542
  readonly collectionwasm_updateOne: (a: number, b: any, c: any) => [number, number, number];
506
543
  readonly collectionwasm_upgradeVectorIndex: (a: number, b: number, c: number) => [number, number];
@@ -514,9 +551,9 @@ export interface InitOutput {
514
551
  readonly taladbwasm_setUserVersion: (a: number, b: number) => [number, number];
515
552
  readonly taladbwasm_userVersion: (a: number) => [number, number, number];
516
553
  readonly init: () => void;
517
- readonly opfs_open_backend: (a: number, b: number) => any;
518
554
  readonly idb_load_snapshot: (a: number, b: number) => any;
519
555
  readonly idb_save_snapshot: (a: number, b: number, c: number, d: number) => any;
556
+ readonly opfs_open_backend: (a: number, b: number) => any;
520
557
  readonly is_opfs_available: () => any;
521
558
  readonly opfs_delete_snapshot: (a: number, b: number) => any;
522
559
  readonly opfs_flush_snapshot: (a: number, b: number, c: number, d: number) => any;
package/pkg/taladb_web.js CHANGED
@@ -106,6 +106,21 @@ export class CollectionWasm {
106
106
  }
107
107
  return ret[0] >>> 0;
108
108
  }
109
+ /**
110
+ * Delete many documents by id, in one commit. Returns the number removed.
111
+ * @param {any} ids
112
+ * @param {string} origin
113
+ * @returns {number}
114
+ */
115
+ deleteManyWithIds(ids, origin) {
116
+ const ptr0 = passStringToWasm0(origin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
117
+ const len0 = WASM_VECTOR_LEN;
118
+ const ret = wasm.collectionwasm_deleteManyWithIds(this.__wbg_ptr, ids, ptr0, len0);
119
+ if (ret[2]) {
120
+ throw takeFromExternrefTable0(ret[1]);
121
+ }
122
+ return ret[0] >>> 0;
123
+ }
109
124
  /**
110
125
  * Delete the first matching document. Returns true if deleted.
111
126
  * @param {any} filter
@@ -237,6 +252,29 @@ export class CollectionWasm {
237
252
  }
238
253
  return takeFromExternrefTable0(ret[0]);
239
254
  }
255
+ /**
256
+ * Upsert many documents **by caller-supplied `_id`**, in one commit.
257
+ *
258
+ * Unlike [`Self::insert_many`] — which mints a fresh ULID and discards `_id` —
259
+ * this honours the id on each document, which is what lets replication address
260
+ * a remote row by a *derived* id so repeated fetches converge on one document
261
+ * instead of duplicating it.
262
+ *
263
+ * `origin` is `"remote"` for authoritative rows replicated in from an origin,
264
+ * or `"local"` for ordinary user writes.
265
+ * @param {any} docs
266
+ * @param {string} origin
267
+ * @returns {any}
268
+ */
269
+ replaceManyWithIds(docs, origin) {
270
+ const ptr0 = passStringToWasm0(origin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
271
+ const len0 = WASM_VECTOR_LEN;
272
+ const ret = wasm.collectionwasm_replaceManyWithIds(this.__wbg_ptr, docs, ptr0, len0);
273
+ if (ret[2]) {
274
+ throw takeFromExternrefTable0(ret[1]);
275
+ }
276
+ return takeFromExternrefTable0(ret[0]);
277
+ }
240
278
  /**
241
279
  * Update all matching documents. Returns the count updated.
242
280
  * @param {any} filter
@@ -640,6 +678,26 @@ export class WorkerDB {
640
678
  }
641
679
  return ret[0] >>> 0;
642
680
  }
681
+ /**
682
+ * Delete many documents by id, in one commit. Returns the number removed.
683
+ * @param {string} collection
684
+ * @param {string} ids_json
685
+ * @param {string} origin
686
+ * @returns {number}
687
+ */
688
+ deleteManyWithIds(collection, ids_json, origin) {
689
+ const ptr0 = passStringToWasm0(collection, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
690
+ const len0 = WASM_VECTOR_LEN;
691
+ const ptr1 = passStringToWasm0(ids_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
692
+ const len1 = WASM_VECTOR_LEN;
693
+ const ptr2 = passStringToWasm0(origin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
694
+ const len2 = WASM_VECTOR_LEN;
695
+ const ret = wasm.workerdb_deleteManyWithIds(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
696
+ if (ret[2]) {
697
+ throw takeFromExternrefTable0(ret[1]);
698
+ }
699
+ return ret[0] >>> 0;
700
+ }
643
701
  /**
644
702
  * Delete the first matching document. Returns `true` / `false`.
645
703
  * @param {string} collection
@@ -1157,6 +1215,46 @@ export class WorkerDB {
1157
1215
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1158
1216
  }
1159
1217
  }
1218
+ /**
1219
+ * Upsert many documents **by caller-supplied `_id`**, in one commit.
1220
+ *
1221
+ * Unlike `insert_many` — which discards `_id` and mints a fresh ULID — this
1222
+ * honours the id in each document. That is what lets the replication
1223
+ * coordinator address a remote row by a *derived* id (see `deriveDocId`) and
1224
+ * have repeated fetches converge on one document instead of duplicating it.
1225
+ *
1226
+ * `origin` is `"remote"` for authoritative rows replicated in from an origin,
1227
+ * or `"local"` for ordinary user writes. Remote rows are marked so they can
1228
+ * never replicate back out — see `Collection::replace_many_with_ids`.
1229
+ * @param {string} collection
1230
+ * @param {string} docs_json
1231
+ * @param {string} origin
1232
+ * @returns {string}
1233
+ */
1234
+ replaceManyWithIds(collection, docs_json, origin) {
1235
+ let deferred5_0;
1236
+ let deferred5_1;
1237
+ try {
1238
+ const ptr0 = passStringToWasm0(collection, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1239
+ const len0 = WASM_VECTOR_LEN;
1240
+ const ptr1 = passStringToWasm0(docs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1241
+ const len1 = WASM_VECTOR_LEN;
1242
+ const ptr2 = passStringToWasm0(origin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1243
+ const len2 = WASM_VECTOR_LEN;
1244
+ const ret = wasm.workerdb_replaceManyWithIds(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
1245
+ var ptr4 = ret[0];
1246
+ var len4 = ret[1];
1247
+ if (ret[3]) {
1248
+ ptr4 = 0; len4 = 0;
1249
+ throw takeFromExternrefTable0(ret[2]);
1250
+ }
1251
+ deferred5_0 = ptr4;
1252
+ deferred5_1 = len4;
1253
+ return getStringFromWasm0(ptr4, len4);
1254
+ } finally {
1255
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
1256
+ }
1257
+ }
1160
1258
  /**
1161
1259
  * Set write durability: `eventual = true` batches OPFS fsyncs for
1162
1260
  * throughput (call `flush()` to force), `false` (default) fsyncs each
@@ -1972,17 +2070,17 @@ function __wbg_get_imports() {
1972
2070
  return ret;
1973
2071
  },
1974
2072
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1975
- // Cast intrinsic for `Closure(Closure { dtor_idx: 144, function: Function { arguments: [Externref], shim_idx: 145, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2073
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 141, function: Function { arguments: [Externref], shim_idx: 142, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1976
2074
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_60ce93de3f474933___closure__destroy___dyn_core_7d5f0a2ba6a62c33___ops__function__FnMut__wasm_bindgen_60ce93de3f474933___JsValue____Output_______, wasm_bindgen_60ce93de3f474933___convert__closures_____invoke___wasm_bindgen_60ce93de3f474933___JsValue______true_);
1977
2075
  return ret;
1978
2076
  },
1979
2077
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1980
- // Cast intrinsic for `Closure(Closure { dtor_idx: 224, function: Function { arguments: [], shim_idx: 225, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2078
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 222, function: Function { arguments: [], shim_idx: 223, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1981
2079
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_60ce93de3f474933___closure__destroy___dyn_core_7d5f0a2ba6a62c33___ops__function__FnMut_____Output_______, wasm_bindgen_60ce93de3f474933___convert__closures_____invoke_______true_);
1982
2080
  return ret;
1983
2081
  },
1984
2082
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1985
- // Cast intrinsic for `Closure(Closure { dtor_idx: 700, function: Function { arguments: [Externref], shim_idx: 701, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2083
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 698, function: Function { arguments: [Externref], shim_idx: 699, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1986
2084
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_60ce93de3f474933___closure__destroy___dyn_core_7d5f0a2ba6a62c33___ops__function__FnMut__wasm_bindgen_60ce93de3f474933___JsValue____Output___core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_60ce93de3f474933___JsError___, wasm_bindgen_60ce93de3f474933___convert__closures_____invoke___wasm_bindgen_60ce93de3f474933___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_60ce93de3f474933___JsError___true_);
1987
2085
  return ret;
1988
2086
  },
Binary file
@@ -11,6 +11,7 @@ export const workerdb_createFtsIndex: (a: number, b: number, c: number, d: numbe
11
11
  export const workerdb_createIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
12
12
  export const workerdb_createVectorIndex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number];
13
13
  export const workerdb_deleteMany: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
14
+ export const workerdb_deleteManyWithIds: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
14
15
  export const workerdb_deleteOne: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
15
16
  export const workerdb_dropCompoundIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
16
17
  export const workerdb_dropFtsIndex: (a: number, b: number, c: number, d: number, e: number) => [number, number];
@@ -34,6 +35,7 @@ export const workerdb_openWithConfigAndSnapshot: (a: number, b: number, c: numbe
34
35
  export const workerdb_openWithOpfs: (a: any) => [number, number, number];
35
36
  export const workerdb_openWithSnapshot: (a: number, b: number) => [number, number, number];
36
37
  export const workerdb_quarantined: (a: number, b: number, c: number) => [number, number, number, number];
38
+ export const workerdb_replaceManyWithIds: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
37
39
  export const workerdb_setDurability: (a: number, b: number) => void;
38
40
  export const workerdb_setUserVersion: (a: number, b: number) => [number, number];
39
41
  export const workerdb_syncPending: (a: number) => bigint;
@@ -50,6 +52,7 @@ export const collectionwasm_createCompoundIndex: (a: number, b: number, c: numbe
50
52
  export const collectionwasm_createIndex: (a: number, b: number, c: number) => [number, number];
51
53
  export const collectionwasm_createVectorIndex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number];
52
54
  export const collectionwasm_deleteMany: (a: number, b: any) => [number, number, number];
55
+ export const collectionwasm_deleteManyWithIds: (a: number, b: any, c: number, d: number) => [number, number, number];
53
56
  export const collectionwasm_deleteOne: (a: number, b: any) => [number, number, number];
54
57
  export const collectionwasm_dropCompoundIndex: (a: number, b: number, c: number) => [number, number];
55
58
  export const collectionwasm_dropIndex: (a: number, b: number, c: number) => [number, number];
@@ -59,6 +62,7 @@ export const collectionwasm_findNearest: (a: number, b: number, c: number, d: nu
59
62
  export const collectionwasm_findOne: (a: number, b: any) => [number, number, number];
60
63
  export const collectionwasm_insert: (a: number, b: any) => [number, number, number, number];
61
64
  export const collectionwasm_insertMany: (a: number, b: any) => [number, number, number];
65
+ export const collectionwasm_replaceManyWithIds: (a: number, b: any, c: number, d: number) => [number, number, number];
62
66
  export const collectionwasm_updateMany: (a: number, b: any, c: any) => [number, number, number];
63
67
  export const collectionwasm_updateOne: (a: number, b: any, c: any) => [number, number, number];
64
68
  export const collectionwasm_upgradeVectorIndex: (a: number, b: number, c: number) => [number, number];
@@ -72,9 +76,9 @@ export const taladbwasm_openWithSnapshot: (a: number, b: number) => [number, num
72
76
  export const taladbwasm_setUserVersion: (a: number, b: number) => [number, number];
73
77
  export const taladbwasm_userVersion: (a: number) => [number, number, number];
74
78
  export const init: () => void;
75
- export const opfs_open_backend: (a: number, b: number) => any;
76
79
  export const idb_load_snapshot: (a: number, b: number) => any;
77
80
  export const idb_save_snapshot: (a: number, b: number, c: number, d: number) => any;
81
+ export const opfs_open_backend: (a: number, b: number) => any;
78
82
  export const is_opfs_available: () => any;
79
83
  export const opfs_delete_snapshot: (a: number, b: number) => any;
80
84
  export const opfs_flush_snapshot: (a: number, b: number, c: number, d: number) => any;
@@ -432,6 +432,18 @@ async function dispatch(op, args) {
432
432
  return result;
433
433
  }
434
434
 
435
+ case 'replaceManyWithIds': {
436
+ const result = db.replaceManyWithIds(args.collection, args.docsJson, args.origin);
437
+ onWriteCommitted();
438
+ return result;
439
+ }
440
+
441
+ case 'deleteManyWithIds': {
442
+ const result = db.deleteManyWithIds(args.collection, args.idsJson, args.origin);
443
+ onWriteCommitted();
444
+ return result;
445
+ }
446
+
435
447
  case 'find':
436
448
  return db.find(args.collection, args.filterJson ?? 'null');
437
449