taladb 0.7.9 → 0.8.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.
@@ -69,6 +69,9 @@ function applySchema(col, options) {
69
69
  };
70
70
  }
71
71
  function detectPlatform() {
72
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
73
+ return "react-native";
74
+ }
72
75
  if (globalThis.nativeCallSyncHook !== void 0) {
73
76
  return "react-native";
74
77
  }
@@ -309,30 +312,36 @@ async function createNativeDB(_dbName) {
309
312
  }
310
313
  const native = maybeNative;
311
314
  function wrapCollection(name, opts) {
312
- const col = native.collection(name);
313
315
  const wrapped = {
314
- insert: async (doc) => col.insert(doc),
315
- insertMany: async (docs) => col.insertMany(docs),
316
- find: async (filter) => col.find(filter ?? {}),
317
- findOne: async (filter) => col.findOne(filter ?? {}),
318
- updateOne: async (filter, update) => col.updateOne(filter, update),
319
- updateMany: async (filter, update) => col.updateMany(filter, update),
320
- deleteOne: async (filter) => col.deleteOne(filter),
321
- deleteMany: async (filter) => col.deleteMany(filter),
322
- count: async (filter) => col.count(filter ?? {}),
323
- createIndex: async (field) => col.createIndex(field),
324
- dropIndex: async (field) => col.dropIndex(field),
325
- createFtsIndex: async (field) => col.createFtsIndex(field),
326
- dropFtsIndex: async (field) => col.dropFtsIndex(field),
327
- createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null, options.indexType ?? null, options.hnswM ?? null, options.hnswEfConstruction ?? null),
328
- dropVectorIndex: async (field) => col.dropVectorIndex(field),
329
- upgradeVectorIndex: async (field) => col.upgradeVectorIndex(field),
330
- listIndexes: async () => JSON.parse(col.listIndexes()),
316
+ insert: async (doc) => native.insert(name, doc),
317
+ insertMany: async (docs) => native.insertMany(name, docs),
318
+ find: async (filter) => native.find(name, filter ?? {}),
319
+ findOne: async (filter) => native.findOne(name, filter ?? {}),
320
+ updateOne: async (filter, update) => native.updateOne(name, filter, update),
321
+ updateMany: async (filter, update) => native.updateMany(name, filter, update),
322
+ deleteOne: async (filter) => native.deleteOne(name, filter),
323
+ deleteMany: async (filter) => native.deleteMany(name, filter),
324
+ count: async (filter) => native.count(name, filter ?? {}),
325
+ createIndex: async (field) => native.createIndex(name, field),
326
+ dropIndex: async (field) => native.dropIndex(name, field),
327
+ createFtsIndex: async (field) => native.createFtsIndex(name, field),
328
+ dropFtsIndex: async (field) => native.dropFtsIndex(name, field),
329
+ createVectorIndex: async (field, options) => {
330
+ const opts2 = {};
331
+ if (options.metric) opts2.metric = options.metric;
332
+ if (options.hnswM || options.hnswEfConstruction) {
333
+ opts2.hnsw = { m: options.hnswM, efConstruction: options.hnswEfConstruction };
334
+ }
335
+ return native.createVectorIndex(name, field, options.dimensions, opts2);
336
+ },
337
+ dropVectorIndex: async (field) => native.dropVectorIndex(name, field),
338
+ upgradeVectorIndex: async (field) => native.upgradeVectorIndex(name, field),
339
+ listIndexes: async () => ({}),
331
340
  findNearest: async (field, vector, topK, filter) => {
332
- const raw = col.findNearest(field, vector, topK, filter ?? null);
341
+ const raw = native.findNearest(name, field, vector, topK, filter ?? null);
333
342
  return raw;
334
343
  },
335
- subscribe: (filter, callback) => makePoller(async () => col.find(filter ?? {}), callback)
344
+ subscribe: (filter, callback) => makePoller(async () => native.find(name, filter ?? {}), callback)
336
345
  };
337
346
  return opts ? applySchema(wrapped, opts) : wrapped;
338
347
  }
package/dist/index.js CHANGED
@@ -42,6 +42,14 @@ var ENDPOINT_FIELDS = [
42
42
  "update_endpoint",
43
43
  "delete_endpoint"
44
44
  ];
45
+ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
46
+ function isLocalhostUrl(url) {
47
+ try {
48
+ return LOCALHOST_HOSTS.has(new URL(url).hostname);
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
45
53
  function validateConfig(config) {
46
54
  const sync = config.sync;
47
55
  if (!sync) return;
@@ -52,6 +60,11 @@ function validateConfig(config) {
52
60
  `TalaDB config: invalid endpoint URL "${url}" \u2014 must start with http:// or https://`
53
61
  );
54
62
  }
63
+ if (url?.startsWith("http://") && !isLocalhostUrl(url)) {
64
+ console.warn(
65
+ `[TalaDB] sync endpoint "${url}" uses plaintext HTTP \u2014 use HTTPS in production to prevent changeset interception`
66
+ );
67
+ }
55
68
  }
56
69
  }
57
70
  async function loadConfig(configPath) {
@@ -151,6 +164,9 @@ function applySchema(col, options) {
151
164
  };
152
165
  }
153
166
  function detectPlatform() {
167
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
168
+ return "react-native";
169
+ }
154
170
  if (globalThis.nativeCallSyncHook !== void 0) {
155
171
  return "react-native";
156
172
  }
@@ -391,30 +407,36 @@ async function createNativeDB(_dbName) {
391
407
  }
392
408
  const native = maybeNative;
393
409
  function wrapCollection(name, opts) {
394
- const col = native.collection(name);
395
410
  const wrapped = {
396
- insert: async (doc) => col.insert(doc),
397
- insertMany: async (docs) => col.insertMany(docs),
398
- find: async (filter) => col.find(filter ?? {}),
399
- findOne: async (filter) => col.findOne(filter ?? {}),
400
- updateOne: async (filter, update) => col.updateOne(filter, update),
401
- updateMany: async (filter, update) => col.updateMany(filter, update),
402
- deleteOne: async (filter) => col.deleteOne(filter),
403
- deleteMany: async (filter) => col.deleteMany(filter),
404
- count: async (filter) => col.count(filter ?? {}),
405
- createIndex: async (field) => col.createIndex(field),
406
- dropIndex: async (field) => col.dropIndex(field),
407
- createFtsIndex: async (field) => col.createFtsIndex(field),
408
- dropFtsIndex: async (field) => col.dropFtsIndex(field),
409
- createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null, options.indexType ?? null, options.hnswM ?? null, options.hnswEfConstruction ?? null),
410
- dropVectorIndex: async (field) => col.dropVectorIndex(field),
411
- upgradeVectorIndex: async (field) => col.upgradeVectorIndex(field),
412
- listIndexes: async () => JSON.parse(col.listIndexes()),
411
+ insert: async (doc) => native.insert(name, doc),
412
+ insertMany: async (docs) => native.insertMany(name, docs),
413
+ find: async (filter) => native.find(name, filter ?? {}),
414
+ findOne: async (filter) => native.findOne(name, filter ?? {}),
415
+ updateOne: async (filter, update) => native.updateOne(name, filter, update),
416
+ updateMany: async (filter, update) => native.updateMany(name, filter, update),
417
+ deleteOne: async (filter) => native.deleteOne(name, filter),
418
+ deleteMany: async (filter) => native.deleteMany(name, filter),
419
+ count: async (filter) => native.count(name, filter ?? {}),
420
+ createIndex: async (field) => native.createIndex(name, field),
421
+ dropIndex: async (field) => native.dropIndex(name, field),
422
+ createFtsIndex: async (field) => native.createFtsIndex(name, field),
423
+ dropFtsIndex: async (field) => native.dropFtsIndex(name, field),
424
+ createVectorIndex: async (field, options) => {
425
+ const opts2 = {};
426
+ if (options.metric) opts2.metric = options.metric;
427
+ if (options.hnswM || options.hnswEfConstruction) {
428
+ opts2.hnsw = { m: options.hnswM, efConstruction: options.hnswEfConstruction };
429
+ }
430
+ return native.createVectorIndex(name, field, options.dimensions, opts2);
431
+ },
432
+ dropVectorIndex: async (field) => native.dropVectorIndex(name, field),
433
+ upgradeVectorIndex: async (field) => native.upgradeVectorIndex(name, field),
434
+ listIndexes: async () => ({}),
413
435
  findNearest: async (field, vector, topK, filter) => {
414
- const raw = col.findNearest(field, vector, topK, filter ?? null);
436
+ const raw = native.findNearest(name, field, vector, topK, filter ?? null);
415
437
  return raw;
416
438
  },
417
- subscribe: (filter, callback) => makePoller(async () => col.find(filter ?? {}), callback)
439
+ subscribe: (filter, callback) => makePoller(async () => native.find(name, filter ?? {}), callback)
418
440
  };
419
441
  return opts ? applySchema(wrapped, opts) : wrapped;
420
442
  }
package/dist/index.mjs CHANGED
@@ -5,6 +5,14 @@ var ENDPOINT_FIELDS = [
5
5
  "update_endpoint",
6
6
  "delete_endpoint"
7
7
  ];
8
+ var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
9
+ function isLocalhostUrl(url) {
10
+ try {
11
+ return LOCALHOST_HOSTS.has(new URL(url).hostname);
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
8
16
  function validateConfig(config) {
9
17
  const sync = config.sync;
10
18
  if (!sync) return;
@@ -15,6 +23,11 @@ function validateConfig(config) {
15
23
  `TalaDB config: invalid endpoint URL "${url}" \u2014 must start with http:// or https://`
16
24
  );
17
25
  }
26
+ if (url?.startsWith("http://") && !isLocalhostUrl(url)) {
27
+ console.warn(
28
+ `[TalaDB] sync endpoint "${url}" uses plaintext HTTP \u2014 use HTTPS in production to prevent changeset interception`
29
+ );
30
+ }
18
31
  }
19
32
  }
20
33
  async function loadConfig(configPath) {
@@ -113,6 +126,9 @@ function applySchema(col, options) {
113
126
  };
114
127
  }
115
128
  function detectPlatform() {
129
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
130
+ return "react-native";
131
+ }
116
132
  if (globalThis.nativeCallSyncHook !== void 0) {
117
133
  return "react-native";
118
134
  }
@@ -353,30 +369,36 @@ async function createNativeDB(_dbName) {
353
369
  }
354
370
  const native = maybeNative;
355
371
  function wrapCollection(name, opts) {
356
- const col = native.collection(name);
357
372
  const wrapped = {
358
- insert: async (doc) => col.insert(doc),
359
- insertMany: async (docs) => col.insertMany(docs),
360
- find: async (filter) => col.find(filter ?? {}),
361
- findOne: async (filter) => col.findOne(filter ?? {}),
362
- updateOne: async (filter, update) => col.updateOne(filter, update),
363
- updateMany: async (filter, update) => col.updateMany(filter, update),
364
- deleteOne: async (filter) => col.deleteOne(filter),
365
- deleteMany: async (filter) => col.deleteMany(filter),
366
- count: async (filter) => col.count(filter ?? {}),
367
- createIndex: async (field) => col.createIndex(field),
368
- dropIndex: async (field) => col.dropIndex(field),
369
- createFtsIndex: async (field) => col.createFtsIndex(field),
370
- dropFtsIndex: async (field) => col.dropFtsIndex(field),
371
- createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null, options.indexType ?? null, options.hnswM ?? null, options.hnswEfConstruction ?? null),
372
- dropVectorIndex: async (field) => col.dropVectorIndex(field),
373
- upgradeVectorIndex: async (field) => col.upgradeVectorIndex(field),
374
- listIndexes: async () => JSON.parse(col.listIndexes()),
373
+ insert: async (doc) => native.insert(name, doc),
374
+ insertMany: async (docs) => native.insertMany(name, docs),
375
+ find: async (filter) => native.find(name, filter ?? {}),
376
+ findOne: async (filter) => native.findOne(name, filter ?? {}),
377
+ updateOne: async (filter, update) => native.updateOne(name, filter, update),
378
+ updateMany: async (filter, update) => native.updateMany(name, filter, update),
379
+ deleteOne: async (filter) => native.deleteOne(name, filter),
380
+ deleteMany: async (filter) => native.deleteMany(name, filter),
381
+ count: async (filter) => native.count(name, filter ?? {}),
382
+ createIndex: async (field) => native.createIndex(name, field),
383
+ dropIndex: async (field) => native.dropIndex(name, field),
384
+ createFtsIndex: async (field) => native.createFtsIndex(name, field),
385
+ dropFtsIndex: async (field) => native.dropFtsIndex(name, field),
386
+ createVectorIndex: async (field, options) => {
387
+ const opts2 = {};
388
+ if (options.metric) opts2.metric = options.metric;
389
+ if (options.hnswM || options.hnswEfConstruction) {
390
+ opts2.hnsw = { m: options.hnswM, efConstruction: options.hnswEfConstruction };
391
+ }
392
+ return native.createVectorIndex(name, field, options.dimensions, opts2);
393
+ },
394
+ dropVectorIndex: async (field) => native.dropVectorIndex(name, field),
395
+ upgradeVectorIndex: async (field) => native.upgradeVectorIndex(name, field),
396
+ listIndexes: async () => ({}),
375
397
  findNearest: async (field, vector, topK, filter) => {
376
- const raw = col.findNearest(field, vector, topK, filter ?? null);
398
+ const raw = native.findNearest(name, field, vector, topK, filter ?? null);
377
399
  return raw;
378
400
  },
379
- subscribe: (filter, callback) => makePoller(async () => col.find(filter ?? {}), callback)
401
+ subscribe: (filter, callback) => makePoller(async () => native.find(name, filter ?? {}), callback)
380
402
  };
381
403
  return opts ? applySchema(wrapped, opts) : wrapped;
382
404
  }
@@ -69,6 +69,9 @@ function applySchema(col, options) {
69
69
  };
70
70
  }
71
71
  function detectPlatform() {
72
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
73
+ return "react-native";
74
+ }
72
75
  if (globalThis.nativeCallSyncHook !== void 0) {
73
76
  return "react-native";
74
77
  }
@@ -123,7 +126,7 @@ function makePoller(findFn, callback) {
123
126
  };
124
127
  }
125
128
  async function createBrowserDB(dbName, config) {
126
- const workerUrl = new URL("@taladb/web/worker/taladb.worker.js", import.meta.url);
129
+ const workerUrl = new URL("@taladb/web/worker/taladb.worker.js", "react-native://unreachable");
127
130
  const worker = new Worker(workerUrl, { type: "module", name: "taladb" });
128
131
  const proxy = new WorkerProxy(worker);
129
132
  const configJson = config !== void 0 ? JSON.stringify(config) : void 0;
@@ -259,7 +262,7 @@ async function createBrowserDB(dbName, config) {
259
262
  };
260
263
  }
261
264
  async function createNodeDB(dbName, config) {
262
- const { TalaDBNode } = await import("@taladb/node");
265
+ const { TalaDBNode } = await import("./node-A4LKRSW5.mjs");
263
266
  const configJson = config !== void 0 ? JSON.stringify(config) : null;
264
267
  const db = TalaDBNode.open(dbName, configJson);
265
268
  function wrapCollection(name, opts) {
@@ -309,30 +312,36 @@ async function createNativeDB(_dbName) {
309
312
  }
310
313
  const native = maybeNative;
311
314
  function wrapCollection(name, opts) {
312
- const col = native.collection(name);
313
315
  const wrapped = {
314
- insert: async (doc) => col.insert(doc),
315
- insertMany: async (docs) => col.insertMany(docs),
316
- find: async (filter) => col.find(filter ?? {}),
317
- findOne: async (filter) => col.findOne(filter ?? {}),
318
- updateOne: async (filter, update) => col.updateOne(filter, update),
319
- updateMany: async (filter, update) => col.updateMany(filter, update),
320
- deleteOne: async (filter) => col.deleteOne(filter),
321
- deleteMany: async (filter) => col.deleteMany(filter),
322
- count: async (filter) => col.count(filter ?? {}),
323
- createIndex: async (field) => col.createIndex(field),
324
- dropIndex: async (field) => col.dropIndex(field),
325
- createFtsIndex: async (field) => col.createFtsIndex(field),
326
- dropFtsIndex: async (field) => col.dropFtsIndex(field),
327
- createVectorIndex: async (field, options) => col.createVectorIndex(field, options.dimensions, options.metric ?? null, options.indexType ?? null, options.hnswM ?? null, options.hnswEfConstruction ?? null),
328
- dropVectorIndex: async (field) => col.dropVectorIndex(field),
329
- upgradeVectorIndex: async (field) => col.upgradeVectorIndex(field),
330
- listIndexes: async () => JSON.parse(col.listIndexes()),
316
+ insert: async (doc) => native.insert(name, doc),
317
+ insertMany: async (docs) => native.insertMany(name, docs),
318
+ find: async (filter) => native.find(name, filter ?? {}),
319
+ findOne: async (filter) => native.findOne(name, filter ?? {}),
320
+ updateOne: async (filter, update) => native.updateOne(name, filter, update),
321
+ updateMany: async (filter, update) => native.updateMany(name, filter, update),
322
+ deleteOne: async (filter) => native.deleteOne(name, filter),
323
+ deleteMany: async (filter) => native.deleteMany(name, filter),
324
+ count: async (filter) => native.count(name, filter ?? {}),
325
+ createIndex: async (field) => native.createIndex(name, field),
326
+ dropIndex: async (field) => native.dropIndex(name, field),
327
+ createFtsIndex: async (field) => native.createFtsIndex(name, field),
328
+ dropFtsIndex: async (field) => native.dropFtsIndex(name, field),
329
+ createVectorIndex: async (field, options) => {
330
+ const opts2 = {};
331
+ if (options.metric) opts2.metric = options.metric;
332
+ if (options.hnswM || options.hnswEfConstruction) {
333
+ opts2.hnsw = { m: options.hnswM, efConstruction: options.hnswEfConstruction };
334
+ }
335
+ return native.createVectorIndex(name, field, options.dimensions, opts2);
336
+ },
337
+ dropVectorIndex: async (field) => native.dropVectorIndex(name, field),
338
+ upgradeVectorIndex: async (field) => native.upgradeVectorIndex(name, field),
339
+ listIndexes: async () => ({}),
331
340
  findNearest: async (field, vector, topK, filter) => {
332
- const raw = col.findNearest(field, vector, topK, filter ?? null);
341
+ const raw = native.findNearest(name, field, vector, topK, filter ?? null);
333
342
  return raw;
334
343
  },
335
- subscribe: (filter, callback) => makePoller(async () => col.find(filter ?? {}), callback)
344
+ subscribe: (filter, callback) => makePoller(async () => native.find(name, filter ?? {}), callback)
336
345
  };
337
346
  return opts ? applySchema(wrapped, opts) : wrapped;
338
347
  }
@@ -0,0 +1,5 @@
1
+ // src/stubs/node.ts
2
+ var TalaDBNode = null;
3
+ export {
4
+ TalaDBNode
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taladb",
3
- "version": "0.7.9",
3
+ "version": "0.8.0",
4
4
  "description": "Local-first document and vector database for React, React Native, and Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",