datalevin-node 1.0.2 → 1.2.10

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/src/form.js ADDED
@@ -0,0 +1,408 @@
1
+ function tokenText(value, prefix) {
2
+ if (typeof value !== "string") {
3
+ throw new TypeError(`Datalevin token names must be strings, got ${typeof value}.`);
4
+ }
5
+ const text = prefix && value.startsWith(prefix) ? value.slice(prefix.length) : value;
6
+ if (text.length === 0) {
7
+ throw new TypeError("Datalevin token names must not be empty.");
8
+ }
9
+ if (/\s/.test(text)) {
10
+ throw new TypeError(`Datalevin token names must not contain whitespace: ${JSON.stringify(value)}.`);
11
+ }
12
+ return text;
13
+ }
14
+
15
+ function tokenPool() {
16
+ const references = new Map();
17
+ const finalizer = new FinalizationRegistry(({ name, reference }) => {
18
+ if (references.get(name) === reference) {
19
+ references.delete(name);
20
+ }
21
+ });
22
+
23
+ return {
24
+ get(name) {
25
+ const value = references.get(name)?.deref();
26
+ if (value === undefined) {
27
+ references.delete(name);
28
+ }
29
+ return value;
30
+ },
31
+ set(name, value) {
32
+ const reference = new WeakRef(value);
33
+ references.set(name, reference);
34
+ finalizer.register(value, { name, reference });
35
+ }
36
+ };
37
+ }
38
+
39
+ const KEYWORDS = tokenPool();
40
+ const DATALOG_SYMBOLS = tokenPool();
41
+ const UUIDS = tokenPool();
42
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
43
+
44
+ export class Keyword {
45
+ constructor(name) {
46
+ const text = tokenText(name, ":");
47
+ const existing = KEYWORDS.get(text);
48
+ if (existing !== undefined) {
49
+ return existing;
50
+ }
51
+ this.name = text;
52
+ Object.freeze(this);
53
+ KEYWORDS.set(text, this);
54
+ }
55
+
56
+ toString() {
57
+ return `:${this.name}`;
58
+ }
59
+ }
60
+
61
+ export class DatalogSymbol {
62
+ constructor(name) {
63
+ const text = tokenText(name, "");
64
+ const existing = DATALOG_SYMBOLS.get(text);
65
+ if (existing !== undefined) {
66
+ return existing;
67
+ }
68
+ this.name = text;
69
+ Object.freeze(this);
70
+ DATALOG_SYMBOLS.set(text, this);
71
+ }
72
+
73
+ toString() {
74
+ return this.name;
75
+ }
76
+ }
77
+
78
+ export class Uuid {
79
+ constructor(value) {
80
+ if (value instanceof Uuid) {
81
+ return value;
82
+ }
83
+ if (typeof value !== "string") {
84
+ throw new TypeError(`Datalevin UUID values must be strings, got ${typeof value}.`);
85
+ }
86
+ const text = value.toLowerCase();
87
+ if (!UUID_PATTERN.test(text)) {
88
+ throw new TypeError(`Invalid UUID value: ${JSON.stringify(value)}.`);
89
+ }
90
+ const existing = UUIDS.get(text);
91
+ if (existing !== undefined) {
92
+ return existing;
93
+ }
94
+ this.value = text;
95
+ Object.freeze(this);
96
+ UUIDS.set(text, this);
97
+ }
98
+
99
+ toString() {
100
+ return this.value;
101
+ }
102
+
103
+ toJSON() {
104
+ return this.value;
105
+ }
106
+ }
107
+
108
+ export function uuid(value) {
109
+ return value instanceof Uuid ? value : new Uuid(value);
110
+ }
111
+
112
+ export class Form {
113
+ toForm() {
114
+ throw new TypeError(`${this.constructor.name}.toForm() is not implemented.`);
115
+ }
116
+ }
117
+
118
+ export class EdnList extends Form {
119
+ constructor(...items) {
120
+ super();
121
+ this.items = immutableSnapshot(items);
122
+ Object.freeze(this);
123
+ }
124
+
125
+ get length() {
126
+ return this.items.length;
127
+ }
128
+
129
+ at(index) {
130
+ return this.items.at(index);
131
+ }
132
+
133
+ [Symbol.iterator]() {
134
+ return this.items[Symbol.iterator]();
135
+ }
136
+
137
+ toForm() {
138
+ return this;
139
+ }
140
+
141
+ asData() {
142
+ return formData(this);
143
+ }
144
+ }
145
+
146
+ export function ednList(...items) {
147
+ return new EdnList(...items);
148
+ }
149
+
150
+ export function quote(value) {
151
+ return new EdnList(new DatalogSymbol("quote"), value);
152
+ }
153
+
154
+ const IMMUTABLE_SNAPSHOTS = new WeakSet();
155
+ const DATE_MUTATORS = [
156
+ "setDate",
157
+ "setFullYear",
158
+ "setHours",
159
+ "setMilliseconds",
160
+ "setMinutes",
161
+ "setMonth",
162
+ "setSeconds",
163
+ "setTime",
164
+ "setUTCDate",
165
+ "setUTCFullYear",
166
+ "setUTCHours",
167
+ "setUTCMilliseconds",
168
+ "setUTCMinutes",
169
+ "setUTCMonth",
170
+ "setUTCSeconds",
171
+ "setYear"
172
+ ];
173
+ const BYTE_MUTATORS = new Set(["copyWithin", "fill", "reverse", "set", "sort"]);
174
+
175
+ function mutationError() {
176
+ throw new TypeError("Datalevin form snapshots are immutable.");
177
+ }
178
+
179
+ function readonlyMap(entries) {
180
+ const target = new Map(entries);
181
+ Object.freeze(target);
182
+ let result;
183
+ result = new Proxy(target, {
184
+ get(current, property) {
185
+ if (property === "set" || property === "delete" || property === "clear") {
186
+ return mutationError;
187
+ }
188
+ if (property === "valueOf") {
189
+ return () => result;
190
+ }
191
+ if (property === "forEach") {
192
+ return (callback, thisArg) => current.forEach(
193
+ (item, key) => callback.call(thisArg, item, key, result)
194
+ );
195
+ }
196
+ const item = Reflect.get(current, property, current);
197
+ return typeof item === "function" ? item.bind(current) : item;
198
+ },
199
+ set: mutationError,
200
+ defineProperty: mutationError,
201
+ deleteProperty: mutationError,
202
+ setPrototypeOf: mutationError
203
+ });
204
+ IMMUTABLE_SNAPSHOTS.add(result);
205
+ return result;
206
+ }
207
+
208
+ function readonlySet(items) {
209
+ const target = new Set(items);
210
+ Object.freeze(target);
211
+ let result;
212
+ result = new Proxy(target, {
213
+ get(current, property) {
214
+ if (property === "add" || property === "delete" || property === "clear") {
215
+ return mutationError;
216
+ }
217
+ if (property === "valueOf") {
218
+ return () => result;
219
+ }
220
+ if (property === "forEach") {
221
+ return (callback, thisArg) => current.forEach(
222
+ (item) => callback.call(thisArg, item, item, result)
223
+ );
224
+ }
225
+ const item = Reflect.get(current, property, current);
226
+ return typeof item === "function" ? item.bind(current) : item;
227
+ },
228
+ set: mutationError,
229
+ defineProperty: mutationError,
230
+ deleteProperty: mutationError,
231
+ setPrototypeOf: mutationError
232
+ });
233
+ IMMUTABLE_SNAPSHOTS.add(result);
234
+ return result;
235
+ }
236
+
237
+ function readonlyDate(value) {
238
+ const target = new Date(value.getTime());
239
+ Object.freeze(target);
240
+ const result = new Proxy(target, {
241
+ get(current, property) {
242
+ if (DATE_MUTATORS.includes(property)) {
243
+ return mutationError;
244
+ }
245
+ const item = Reflect.get(current, property, current);
246
+ return typeof item === "function" ? item.bind(current) : item;
247
+ },
248
+ set: mutationError,
249
+ defineProperty: mutationError,
250
+ deleteProperty: mutationError,
251
+ setPrototypeOf: mutationError
252
+ });
253
+ IMMUTABLE_SNAPSHOTS.add(result);
254
+ return result;
255
+ }
256
+
257
+ function readonlyBytes(value) {
258
+ const target = Uint8Array.from(value);
259
+ let result;
260
+ result = new Proxy(target, {
261
+ get(current, property) {
262
+ if (property === "buffer") {
263
+ return current.buffer.slice(
264
+ current.byteOffset,
265
+ current.byteOffset + current.byteLength
266
+ );
267
+ }
268
+ if (property === "subarray") {
269
+ return (...args) => Uint8Array.from(current.subarray(...args));
270
+ }
271
+ if (property === "valueOf") {
272
+ return () => result;
273
+ }
274
+ if (BYTE_MUTATORS.has(property)) {
275
+ return mutationError;
276
+ }
277
+ const item = Reflect.get(current, property, current);
278
+ return typeof item === "function" ? item.bind(current) : item;
279
+ },
280
+ set: mutationError,
281
+ defineProperty: mutationError,
282
+ deleteProperty: mutationError,
283
+ setPrototypeOf: mutationError
284
+ });
285
+ IMMUTABLE_SNAPSHOTS.add(result);
286
+ return result;
287
+ }
288
+
289
+ function plainObject(value) {
290
+ if (value === null || typeof value !== "object") {
291
+ return false;
292
+ }
293
+ const prototype = Object.getPrototypeOf(value);
294
+ return prototype === Object.prototype || prototype === null;
295
+ }
296
+
297
+ function withContainer(value, active, build) {
298
+ if (active.has(value)) {
299
+ throw new TypeError("Datalevin forms cannot contain cyclic containers.");
300
+ }
301
+ active.add(value);
302
+ try {
303
+ return build();
304
+ } finally {
305
+ active.delete(value);
306
+ }
307
+ }
308
+
309
+ export function immutableSnapshot(value, active = new Set()) {
310
+ if (
311
+ value === null
312
+ || (typeof value !== "object" && typeof value !== "function")
313
+ || value instanceof Keyword
314
+ || value instanceof DatalogSymbol
315
+ || value instanceof Uuid
316
+ || value instanceof Form
317
+ || IMMUTABLE_SNAPSHOTS.has(value)
318
+ ) {
319
+ return value;
320
+ }
321
+
322
+ if (value instanceof Date) {
323
+ return readonlyDate(value);
324
+ }
325
+ if (value instanceof Uint8Array) {
326
+ return readonlyBytes(value);
327
+ }
328
+ if (Array.isArray(value)) {
329
+ return withContainer(value, active, () => {
330
+ const result = value.map((item) => immutableSnapshot(item, active));
331
+ IMMUTABLE_SNAPSHOTS.add(result);
332
+ return Object.freeze(result);
333
+ });
334
+ }
335
+ if (value instanceof Map) {
336
+ return withContainer(value, active, () => readonlyMap(
337
+ Array.from(
338
+ value,
339
+ ([key, item]) => [
340
+ immutableSnapshot(key, active),
341
+ immutableSnapshot(item, active)
342
+ ]
343
+ )
344
+ ));
345
+ }
346
+ if (value instanceof Set) {
347
+ return withContainer(value, active, () => readonlySet(
348
+ Array.from(value, (item) => immutableSnapshot(item, active))
349
+ ));
350
+ }
351
+ if (plainObject(value)) {
352
+ return withContainer(value, active, () => {
353
+ const result = Object.create(Object.getPrototypeOf(value));
354
+ for (const [key, item] of Object.entries(value)) {
355
+ Object.defineProperty(result, key, {
356
+ configurable: false,
357
+ enumerable: true,
358
+ value: immutableSnapshot(item, active),
359
+ writable: false
360
+ });
361
+ }
362
+ IMMUTABLE_SNAPSHOTS.add(result);
363
+ return Object.freeze(result);
364
+ });
365
+ }
366
+
367
+ // Backend handles and other non-structural host objects are atomic values.
368
+ return value;
369
+ }
370
+
371
+ export class RawForm extends Form {
372
+ constructor(value) {
373
+ super();
374
+ this.value = immutableSnapshot(value);
375
+ Object.freeze(this);
376
+ }
377
+
378
+ toForm() {
379
+ return this.value;
380
+ }
381
+ }
382
+
383
+ export function formData(value) {
384
+ if (value instanceof EdnList) {
385
+ return new EdnList(...Array.from(value, formData));
386
+ }
387
+ if (value instanceof Form) {
388
+ return formData(value.toForm());
389
+ }
390
+ if (value instanceof Keyword || value instanceof DatalogSymbol) {
391
+ return value.toString();
392
+ }
393
+ if (value instanceof Map) {
394
+ return new Map(Array.from(value, ([key, item]) => [formData(key), formData(item)]));
395
+ }
396
+ if (value instanceof Set) {
397
+ return new Set(Array.from(value, formData));
398
+ }
399
+ if (Array.isArray(value)) {
400
+ return value.map(formData);
401
+ }
402
+ if (plainObject(value)) {
403
+ return Object.fromEntries(
404
+ Object.entries(value).map(([key, item]) => [key, formData(item)])
405
+ );
406
+ }
407
+ return value;
408
+ }
package/src/index.js CHANGED
@@ -1,6 +1,15 @@
1
1
  export { Client } from "./client.js";
2
2
  export { Connection } from "./connection.js";
3
3
  export { Database } from "./database.js";
4
+ export {
5
+ PreparedRead,
6
+ executePrepared,
7
+ indexAttr,
8
+ prepareGetValue,
9
+ preparePull,
10
+ prepareQuery,
11
+ transactAck
12
+ } from "./prepared.js";
4
13
  export { Entity } from "./entity.js";
5
14
  export {
6
15
  DatalevinConfigurationError,
@@ -34,6 +43,7 @@ export {
34
43
  initDb,
35
44
  jvmStarted,
36
45
  keyword,
46
+ listenDb,
37
47
  maxEid,
38
48
  newClient,
39
49
  newLlamaEmbedder,
@@ -58,12 +68,34 @@ export {
58
68
  txEnsure,
59
69
  txRetract,
60
70
  txRetractEntity,
71
+ unlistenDb,
72
+ updateKv,
61
73
  vectorAttr,
62
74
  vectorOptions,
63
75
  withTransaction,
64
76
  writeEdn
65
77
  } from "./interop.js";
66
78
  export { interop } from "./raw.js";
79
+ export {
80
+ DatalogSymbol,
81
+ EdnList,
82
+ Keyword,
83
+ Uuid,
84
+ ednList,
85
+ quote,
86
+ uuid
87
+ } from "./form.js";
88
+ export {
89
+ FulltextOptions,
90
+ IdocMatchOptions,
91
+ PullAttr,
92
+ PullNested,
93
+ PullSelector,
94
+ Query,
95
+ VectorSearchOptions,
96
+ q
97
+ } from "./query.js";
98
+ export { LookupRef, PatchOp, TxData, tx } from "./transaction.js";
67
99
  export { KV, KVTransaction, RawBuffer, RawKV } from "./kv.js";
68
100
  export { LlamaEmbedder, LlamaGenerator } from "./llm.js";
69
101
  export {
@@ -81,5 +113,10 @@ export {
81
113
  prefixTokenFilter,
82
114
  unaccentTokenFilter
83
115
  } from "./search.js";
84
- export { UdfRegistry, createUdfRegistry, udfDescriptor } from "./udf.js";
116
+ export {
117
+ UdfDescriptor,
118
+ UdfRegistry,
119
+ createUdfRegistry,
120
+ udfDescriptor
121
+ } from "./udf.js";
85
122
  export { VectorIndex } from "./vector.js";
package/src/interop.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { toEdnForm, toJava, toJs, toQueryInput } from "./convert.js";
2
2
  import { DatalevinError } from "./errors.js";
3
3
  import { callJavaMethod, classes, javaBridgeModule, jvmStarted, startJvm } from "./jvm.js";
4
+ import { bindNativeCallback, registryFromOpts, withNativeScope } from "./native.js";
4
5
 
5
6
  export const CONNECTION_WITH_TRANSACTION_UNSUPPORTED =
6
7
  "Connection withTransaction is not exposed by the JavaScript binding because Java interface callbacks deadlock when the callback calls back into Datalevin. Use transact() for a single Datalog transaction, or KV withTransaction for explicit KV transactions.";
@@ -41,10 +42,10 @@ async function normalizeInteropArgs(args = []) {
41
42
  async function createFunctionProxy(fn) {
42
43
  const { newProxy } = await javaBridgeModule();
43
44
  return newProxy("java.util.function.Function", {
44
- apply: async (value) => {
45
+ apply: bindNativeCallback(async (value) => {
45
46
  const result = await fn(value);
46
47
  return toJava(result === undefined ? null : result);
47
- }
48
+ })
48
49
  });
49
50
  }
50
51
 
@@ -69,6 +70,12 @@ async function withInterfaceProxyEventLoop(fn) {
69
70
  }
70
71
 
71
72
  class InteropBindings {
73
+ async registerType(handle, typeName, definition) {
74
+ const cls = await classes();
75
+ return callJavaMethod(cls.interop, "registerType",
76
+ await unwrapInteropHandle(handle), String(typeName), await toJava(definition));
77
+ }
78
+
72
79
  async apiInfoRaw() {
73
80
  const cls = await classes();
74
81
  return callJavaMethod(cls.datalevin, "apiInfo");
@@ -102,6 +109,34 @@ class InteropBindings {
102
109
  );
103
110
  }
104
111
 
112
+ async preparePull(db, selector, opts = null) {
113
+ const cls = await classes();
114
+ return callJavaMethod(cls.interop, "preparePull", db, selector, await toJava(opts));
115
+ }
116
+
117
+ async prepareQuery(db, query) {
118
+ const cls = await classes();
119
+ return callJavaMethod(cls.interop, "prepareQuery", db, query);
120
+ }
121
+
122
+ async prepareGetValue(kv, dbiName, kType, vType, ignoreKey) {
123
+ const cls = await classes();
124
+ return callJavaMethod(cls.interop, "prepareGetValue", kv, dbiName,
125
+ await toJava(kType), await toJava(vType), ignoreKey);
126
+ }
127
+
128
+ async connectionTransactAck(conn, txData, txMeta = null) {
129
+ const cls = await classes();
130
+ return callJavaMethod(cls.interop, "connectionTransactAck", await unwrapInteropHandle(conn),
131
+ await toJava(txData), await toJava(txMeta));
132
+ }
133
+
134
+ async connectionIndexAttr(conn, attr) {
135
+ const cls = await classes();
136
+ return callJavaMethod(cls.interop, "connectionIndexAttr", await unwrapInteropHandle(conn),
137
+ await toJava(attr));
138
+ }
139
+
105
140
  async clientInvoke(functionName, args = null) {
106
141
  const cls = await classes();
107
142
  return callJavaMethod(
@@ -161,6 +196,22 @@ class InteropBindings {
161
196
  return callJavaMethod(cls.interop, "connectionDbBridge", handle);
162
197
  }
163
198
 
199
+ async connectionQuery(handle, query, inputs, { form = false } = {}) {
200
+ const cls = await classes();
201
+ const bridgeMethod = form
202
+ ? "connectionQueryFormBridge"
203
+ : "connectionQueryBridge";
204
+ if (typeof cls.interop[bridgeMethod] === "function") {
205
+ return callJavaMethod(cls.interop, bridgeMethod, handle, query, inputs);
206
+ }
207
+
208
+ // Compatibility for runtimes predating the in-JVM query bridge. Runtime
209
+ // builds that return SpillableSet require the bridge method above.
210
+ const method = form ? "queryForm" : "query";
211
+ const result = await callJavaMethod(handle, method, query, inputs);
212
+ return callJavaMethod(cls.interop, "bridgeResult", result);
213
+ }
214
+
164
215
  async connectionEntity(handle, eid) {
165
216
  const cls = await classes();
166
217
  return callJavaMethod(
@@ -352,6 +403,19 @@ class InteropBindings {
352
403
  );
353
404
  }
354
405
 
406
+ async connectionListenDb(handle, keyOrListener, listener = null) {
407
+ const cls = await classes();
408
+ const raw = await unwrapInteropHandle(handle);
409
+ return hasValue(listener)
410
+ ? callJavaMethod(cls.interop, "connectionListenDb", raw, await toJava(keyOrListener), listener)
411
+ : callJavaMethod(cls.interop, "connectionListenDb", raw, keyOrListener);
412
+ }
413
+
414
+ async connectionUnlistenDb(handle, key) {
415
+ const cls = await classes();
416
+ await callJavaMethod(cls.interop, "connectionUnlistenDb", await unwrapInteropHandle(handle), await toJava(key));
417
+ }
418
+
355
419
  async connectionDatoms(handle, index, c1 = null, c2 = null, c3 = null, limit = null) {
356
420
  const cls = await classes();
357
421
  return callJavaMethod(
@@ -515,9 +579,33 @@ class InteropBindings {
515
579
  return Boolean(await callJavaMethod(handle, "closed"));
516
580
  }
517
581
 
582
+ async keyValueUpdate(handle, dbi, key, fn, kType, vType, args) {
583
+ const cls = await classes();
584
+ const values = [await unwrapInteropHandle(handle), dbi, await toJava(key)];
585
+ const typesAndArgs = [await toJava(kType), await toJava(vType), await toJava(args)];
586
+ if (typeof fn === "string") {
587
+ return callJavaMethod(cls.interop, "keyValueUpdateSource", ...values, fn, ...typesAndArgs);
588
+ }
589
+ const { newProxy } = await javaBridgeModule();
590
+ const proxy = newProxy("datalevin.UdfFunction", {
591
+ invoke: bindNativeCallback(async (items) => {
592
+ const result = await fn(...await toJs(items));
593
+ return toJava(result === undefined ? null : result);
594
+ })
595
+ });
596
+ try {
597
+ return await callJavaMethod(cls.interop, "keyValueUpdate", ...values, proxy, ...typesAndArgs);
598
+ } finally {
599
+ proxy.reset?.();
600
+ }
601
+ }
602
+
518
603
  async keyValueBeginTransaction(handle) {
519
604
  const cls = await classes();
520
- return callJavaMethod(cls.interop, "keyValueBeginTransaction", await unwrapInteropHandle(handle));
605
+ const method = typeof cls.interop.keyValueBeginTransactionBridge === "function"
606
+ ? "keyValueBeginTransactionBridge"
607
+ : "keyValueBeginTransaction";
608
+ return callJavaMethod(cls.interop, method, await unwrapInteropHandle(handle));
521
609
  }
522
610
 
523
611
  async keyValueCommitTransaction(tx) {
@@ -1334,6 +1422,11 @@ class InteropBindings {
1334
1422
  return callJavaMethod(cls.interop, "registerUdf", registry, await toJava(descriptor), fn);
1335
1423
  }
1336
1424
 
1425
+ async bindNativeType(registry, typeName, deserialize) {
1426
+ const cls = await classes();
1427
+ return callJavaMethod(cls.interop, "bindNativeType", registry, typeName, await toJava(deserialize));
1428
+ }
1429
+
1337
1430
  async unregisterUdf(registry, descriptor) {
1338
1431
  const cls = await classes();
1339
1432
  return callJavaMethod(cls.interop, "unregisterUdf", registry, await toJava(descriptor));
@@ -1486,16 +1579,18 @@ export async function execJson(op, args = null) {
1486
1579
 
1487
1580
  export async function connect(dir = null, { schema = null, opts = null, shared = false } = {}) {
1488
1581
  const { Connection } = await import("./connection.js");
1489
- return new Connection(await _BINDINGS.createConnection(dir, schema, opts, { shared }));
1582
+ return withNativeScope(registryFromOpts(opts, dir), async () =>
1583
+ new Connection(await _BINDINGS.createConnection(dir, schema, opts, { shared })));
1490
1584
  }
1491
1585
 
1492
1586
  export async function initDb(datoms, { dir = null, schema = null, opts = null } = {}) {
1493
1587
  const { Connection } = await import("./connection.js");
1494
- return new Connection(await _BINDINGS.initDb(datoms, dir, schema, opts));
1588
+ return withNativeScope(registryFromOpts(opts, dir), async () =>
1589
+ new Connection(await _BINDINGS.initDb(datoms, dir, schema, opts)));
1495
1590
  }
1496
1591
 
1497
1592
  export async function fillDb(conn, datoms) {
1498
- await _BINDINGS.fillDb(conn, datoms);
1593
+ await withNativeScope(conn?._nativeRegistry ?? null, () => _BINDINGS.fillDb(conn, datoms));
1499
1594
  return conn;
1500
1595
  }
1501
1596
 
@@ -1515,6 +1610,18 @@ export async function txDataToSimulatedReport(conn, txData) {
1515
1610
  return conn.txDataToSimulatedReport(txData);
1516
1611
  }
1517
1612
 
1613
+ export async function listenDb(conn, callback, key = null) {
1614
+ return conn.listenDb(callback, key);
1615
+ }
1616
+
1617
+ export async function unlistenDb(conn, key) {
1618
+ return conn.unlistenDb(key);
1619
+ }
1620
+
1621
+ export async function updateKv(kv, dbiName, key, fn, opts = {}) {
1622
+ return kv.update(dbiName, key, fn, opts);
1623
+ }
1624
+
1518
1625
  export async function datalogKv(conn) {
1519
1626
  return conn.datalogKv();
1520
1627
  }
@@ -1583,6 +1690,7 @@ export function schemaAttr({
1583
1690
  cardinality = null,
1584
1691
  unique = null,
1585
1692
  index = null,
1693
+ noIndex = null,
1586
1694
  fulltext = null,
1587
1695
  isComponent = null,
1588
1696
  noHistory = null,
@@ -1617,6 +1725,9 @@ export function schemaAttr({
1617
1725
  if (index !== null && index !== undefined) {
1618
1726
  spec[":db/index"] = Boolean(index);
1619
1727
  }
1728
+ if (noIndex !== null && noIndex !== undefined) {
1729
+ spec[":db/noindex"] = Boolean(noIndex);
1730
+ }
1620
1731
  if (fulltext !== null && fulltext !== undefined) {
1621
1732
  spec[":db/fulltext"] = Boolean(fulltext);
1622
1733
  }
@@ -2050,7 +2161,8 @@ export function datomAdded(value) {
2050
2161
 
2051
2162
  export async function openKv(dir, opts = null) {
2052
2163
  const { KV } = await import("./kv.js");
2053
- return new KV(await _BINDINGS.openKeyValue(dir, opts));
2164
+ return withNativeScope(registryFromOpts(opts, dir), async () =>
2165
+ new KV(await _BINDINGS.openKeyValue(dir, opts)));
2054
2166
  }
2055
2167
 
2056
2168
  export async function newSearchEngine(kv, opts = null) {