@taladb/react-native 0.9.2 → 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.
@@ -241,6 +241,7 @@ Value TalaDBHostObject::awaitJobAsPromise(Runtime &rt, TalaDbJob *job, bool pars
241
241
  std::vector<PropNameID> TalaDBHostObject::getPropertyNames(Runtime &rt) {
242
242
  std::vector<std::string> names = {
243
243
  "insert", "insertMany",
244
+ "replaceManyWithIds", "deleteManyWithIds",
244
245
  "find", "findOne",
245
246
  "updateOne", "updateMany",
246
247
  "deleteOne", "deleteMany",
@@ -313,6 +314,46 @@ Value TalaDBHostObject::get(Runtime &rt, const PropNameID &propName) {
313
314
  });
314
315
  }
315
316
 
317
+ // ------------------------------------------------------------------
318
+ // replaceManyWithIds(collection: string, docs: object[], origin: string): string[]
319
+ // ------------------------------------------------------------------
320
+ if (name == "replaceManyWithIds") {
321
+ return Function::createFromHostFunction(
322
+ rt, PropNameID::forAscii(rt, "replaceManyWithIds"), 3,
323
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
324
+ if (count < 3) throw JSError(rt, "replaceManyWithIds requires 3 arguments");
325
+ auto col = args[0].getString(rt).utf8(rt);
326
+ auto docsJson = stringify(rt, args[1]);
327
+ auto origin = args[2].getString(rt).utf8(rt);
328
+ char *result = taladb_replace_many_with_ids(
329
+ db_, col.c_str(), docsJson.c_str(), origin.c_str());
330
+ if (!result) throw ffiError(rt, "taladb_replace_many_with_ids failed");
331
+ std::string json(result);
332
+ taladb_free_string(result);
333
+ return parse(rt, json);
334
+ });
335
+ }
336
+
337
+ // ------------------------------------------------------------------
338
+ // deleteManyWithIds(collection: string, ids: string[], origin: string): number
339
+ // ------------------------------------------------------------------
340
+ if (name == "deleteManyWithIds") {
341
+ return Function::createFromHostFunction(
342
+ rt, PropNameID::forAscii(rt, "deleteManyWithIds"), 3,
343
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
344
+ if (count < 3) throw JSError(rt, "deleteManyWithIds requires 3 arguments");
345
+ auto col = args[0].getString(rt).utf8(rt);
346
+ auto idsJson = stringify(rt, args[1]);
347
+ auto origin = args[2].getString(rt).utf8(rt);
348
+ char *result = taladb_delete_many_with_ids(
349
+ db_, col.c_str(), idsJson.c_str(), origin.c_str());
350
+ if (!result) throw ffiError(rt, "taladb_delete_many_with_ids failed");
351
+ std::string json(result);
352
+ taladb_free_string(result);
353
+ return parse(rt, json);
354
+ });
355
+ }
356
+
316
357
  // ------------------------------------------------------------------
317
358
  // find(collection: string, filter: object | null): object[]
318
359
  // ------------------------------------------------------------------
package/cpp/taladb.h CHANGED
@@ -79,6 +79,39 @@ char *taladb_insert_many(TalaDbHandle *handle,
79
79
  const char *collection,
80
80
  const char *docs_json);
81
81
 
82
+ /* -------------------------------------------------------------------------
83
+ * Replication writes — id-addressed upsert / delete
84
+ * ---------------------------------------------------------------------- */
85
+
86
+ /**
87
+ * Upsert many documents by caller-supplied `_id`, in one commit.
88
+ *
89
+ * Unlike taladb_insert_many(), which discards `_id` and mints a fresh ULID, this
90
+ * honours the id on each document — which is what makes a replication upsert
91
+ * idempotent across repeated fetches of the same remote row.
92
+ *
93
+ * `origin` is "remote" (authoritative rows replicated in from an origin) or
94
+ * "local" (ordinary user writes). Remote rows are marked so they never replicate
95
+ * back out.
96
+ *
97
+ * Returns a JSON array of ULID strings, or NULL on error.
98
+ * Caller must free with taladb_free_string().
99
+ */
100
+ char *taladb_replace_many_with_ids(TalaDbHandle *handle,
101
+ const char *collection,
102
+ const char *docs_json,
103
+ const char *origin);
104
+
105
+ /**
106
+ * Delete many documents by id, in one commit.
107
+ * Returns a JSON number (the count removed), or NULL on error.
108
+ * Caller must free with taladb_free_string().
109
+ */
110
+ char *taladb_delete_many_with_ids(TalaDbHandle *handle,
111
+ const char *collection,
112
+ const char *ids_json,
113
+ const char *origin);
114
+
82
115
  /* -------------------------------------------------------------------------
83
116
  * Find
84
117
  * ---------------------------------------------------------------------- */
@@ -241,6 +241,7 @@ Value TalaDBHostObject::awaitJobAsPromise(Runtime &rt, TalaDbJob *job, bool pars
241
241
  std::vector<PropNameID> TalaDBHostObject::getPropertyNames(Runtime &rt) {
242
242
  std::vector<std::string> names = {
243
243
  "insert", "insertMany",
244
+ "replaceManyWithIds", "deleteManyWithIds",
244
245
  "find", "findOne",
245
246
  "updateOne", "updateMany",
246
247
  "deleteOne", "deleteMany",
@@ -313,6 +314,46 @@ Value TalaDBHostObject::get(Runtime &rt, const PropNameID &propName) {
313
314
  });
314
315
  }
315
316
 
317
+ // ------------------------------------------------------------------
318
+ // replaceManyWithIds(collection: string, docs: object[], origin: string): string[]
319
+ // ------------------------------------------------------------------
320
+ if (name == "replaceManyWithIds") {
321
+ return Function::createFromHostFunction(
322
+ rt, PropNameID::forAscii(rt, "replaceManyWithIds"), 3,
323
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
324
+ if (count < 3) throw JSError(rt, "replaceManyWithIds requires 3 arguments");
325
+ auto col = args[0].getString(rt).utf8(rt);
326
+ auto docsJson = stringify(rt, args[1]);
327
+ auto origin = args[2].getString(rt).utf8(rt);
328
+ char *result = taladb_replace_many_with_ids(
329
+ db_, col.c_str(), docsJson.c_str(), origin.c_str());
330
+ if (!result) throw ffiError(rt, "taladb_replace_many_with_ids failed");
331
+ std::string json(result);
332
+ taladb_free_string(result);
333
+ return parse(rt, json);
334
+ });
335
+ }
336
+
337
+ // ------------------------------------------------------------------
338
+ // deleteManyWithIds(collection: string, ids: string[], origin: string): number
339
+ // ------------------------------------------------------------------
340
+ if (name == "deleteManyWithIds") {
341
+ return Function::createFromHostFunction(
342
+ rt, PropNameID::forAscii(rt, "deleteManyWithIds"), 3,
343
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
344
+ if (count < 3) throw JSError(rt, "deleteManyWithIds requires 3 arguments");
345
+ auto col = args[0].getString(rt).utf8(rt);
346
+ auto idsJson = stringify(rt, args[1]);
347
+ auto origin = args[2].getString(rt).utf8(rt);
348
+ char *result = taladb_delete_many_with_ids(
349
+ db_, col.c_str(), idsJson.c_str(), origin.c_str());
350
+ if (!result) throw ffiError(rt, "taladb_delete_many_with_ids failed");
351
+ std::string json(result);
352
+ taladb_free_string(result);
353
+ return parse(rt, json);
354
+ });
355
+ }
356
+
316
357
  // ------------------------------------------------------------------
317
358
  // find(collection: string, filter: object | null): object[]
318
359
  // ------------------------------------------------------------------
@@ -79,6 +79,39 @@ char *taladb_insert_many(TalaDbHandle *handle,
79
79
  const char *collection,
80
80
  const char *docs_json);
81
81
 
82
+ /* -------------------------------------------------------------------------
83
+ * Replication writes — id-addressed upsert / delete
84
+ * ---------------------------------------------------------------------- */
85
+
86
+ /**
87
+ * Upsert many documents by caller-supplied `_id`, in one commit.
88
+ *
89
+ * Unlike taladb_insert_many(), which discards `_id` and mints a fresh ULID, this
90
+ * honours the id on each document — which is what makes a replication upsert
91
+ * idempotent across repeated fetches of the same remote row.
92
+ *
93
+ * `origin` is "remote" (authoritative rows replicated in from an origin) or
94
+ * "local" (ordinary user writes). Remote rows are marked so they never replicate
95
+ * back out.
96
+ *
97
+ * Returns a JSON array of ULID strings, or NULL on error.
98
+ * Caller must free with taladb_free_string().
99
+ */
100
+ char *taladb_replace_many_with_ids(TalaDbHandle *handle,
101
+ const char *collection,
102
+ const char *docs_json,
103
+ const char *origin);
104
+
105
+ /**
106
+ * Delete many documents by id, in one commit.
107
+ * Returns a JSON number (the count removed), or NULL on error.
108
+ * Caller must free with taladb_free_string().
109
+ */
110
+ char *taladb_delete_many_with_ids(TalaDbHandle *handle,
111
+ const char *collection,
112
+ const char *ids_json,
113
+ const char *origin);
114
+
82
115
  /* -------------------------------------------------------------------------
83
116
  * Find
84
117
  * ---------------------------------------------------------------------- */
@@ -241,6 +241,7 @@ Value TalaDBHostObject::awaitJobAsPromise(Runtime &rt, TalaDbJob *job, bool pars
241
241
  std::vector<PropNameID> TalaDBHostObject::getPropertyNames(Runtime &rt) {
242
242
  std::vector<std::string> names = {
243
243
  "insert", "insertMany",
244
+ "replaceManyWithIds", "deleteManyWithIds",
244
245
  "find", "findOne",
245
246
  "updateOne", "updateMany",
246
247
  "deleteOne", "deleteMany",
@@ -313,6 +314,46 @@ Value TalaDBHostObject::get(Runtime &rt, const PropNameID &propName) {
313
314
  });
314
315
  }
315
316
 
317
+ // ------------------------------------------------------------------
318
+ // replaceManyWithIds(collection: string, docs: object[], origin: string): string[]
319
+ // ------------------------------------------------------------------
320
+ if (name == "replaceManyWithIds") {
321
+ return Function::createFromHostFunction(
322
+ rt, PropNameID::forAscii(rt, "replaceManyWithIds"), 3,
323
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
324
+ if (count < 3) throw JSError(rt, "replaceManyWithIds requires 3 arguments");
325
+ auto col = args[0].getString(rt).utf8(rt);
326
+ auto docsJson = stringify(rt, args[1]);
327
+ auto origin = args[2].getString(rt).utf8(rt);
328
+ char *result = taladb_replace_many_with_ids(
329
+ db_, col.c_str(), docsJson.c_str(), origin.c_str());
330
+ if (!result) throw ffiError(rt, "taladb_replace_many_with_ids failed");
331
+ std::string json(result);
332
+ taladb_free_string(result);
333
+ return parse(rt, json);
334
+ });
335
+ }
336
+
337
+ // ------------------------------------------------------------------
338
+ // deleteManyWithIds(collection: string, ids: string[], origin: string): number
339
+ // ------------------------------------------------------------------
340
+ if (name == "deleteManyWithIds") {
341
+ return Function::createFromHostFunction(
342
+ rt, PropNameID::forAscii(rt, "deleteManyWithIds"), 3,
343
+ [this](Runtime &rt, const Value &, const Value *args, size_t count) -> Value {
344
+ if (count < 3) throw JSError(rt, "deleteManyWithIds requires 3 arguments");
345
+ auto col = args[0].getString(rt).utf8(rt);
346
+ auto idsJson = stringify(rt, args[1]);
347
+ auto origin = args[2].getString(rt).utf8(rt);
348
+ char *result = taladb_delete_many_with_ids(
349
+ db_, col.c_str(), idsJson.c_str(), origin.c_str());
350
+ if (!result) throw ffiError(rt, "taladb_delete_many_with_ids failed");
351
+ std::string json(result);
352
+ taladb_free_string(result);
353
+ return parse(rt, json);
354
+ });
355
+ }
356
+
316
357
  // ------------------------------------------------------------------
317
358
  // find(collection: string, filter: object | null): object[]
318
359
  // ------------------------------------------------------------------
@@ -79,6 +79,39 @@ char *taladb_insert_many(TalaDbHandle *handle,
79
79
  const char *collection,
80
80
  const char *docs_json);
81
81
 
82
+ /* -------------------------------------------------------------------------
83
+ * Replication writes — id-addressed upsert / delete
84
+ * ---------------------------------------------------------------------- */
85
+
86
+ /**
87
+ * Upsert many documents by caller-supplied `_id`, in one commit.
88
+ *
89
+ * Unlike taladb_insert_many(), which discards `_id` and mints a fresh ULID, this
90
+ * honours the id on each document — which is what makes a replication upsert
91
+ * idempotent across repeated fetches of the same remote row.
92
+ *
93
+ * `origin` is "remote" (authoritative rows replicated in from an origin) or
94
+ * "local" (ordinary user writes). Remote rows are marked so they never replicate
95
+ * back out.
96
+ *
97
+ * Returns a JSON array of ULID strings, or NULL on error.
98
+ * Caller must free with taladb_free_string().
99
+ */
100
+ char *taladb_replace_many_with_ids(TalaDbHandle *handle,
101
+ const char *collection,
102
+ const char *docs_json,
103
+ const char *origin);
104
+
105
+ /**
106
+ * Delete many documents by id, in one commit.
107
+ * Returns a JSON number (the count removed), or NULL on error.
108
+ * Caller must free with taladb_free_string().
109
+ */
110
+ char *taladb_delete_many_with_ids(TalaDbHandle *handle,
111
+ const char *collection,
112
+ const char *ids_json,
113
+ const char *origin);
114
+
82
115
  /* -------------------------------------------------------------------------
83
116
  * Find
84
117
  * ---------------------------------------------------------------------- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taladb/react-native",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "TalaDB React Native module — document and vector database via JSI HostObject",
5
5
  "main": "src/index",
6
6
  "types": "src/index.tsx",
@@ -31,6 +31,29 @@ export interface Spec extends TurboModule {
31
31
  /** Insert multiple documents. Returns an array of ULID string ids. */
32
32
  insertMany(collection: string, docs: Object[]): string[];
33
33
 
34
+ /**
35
+ * Upsert many documents **by caller-supplied `_id`**, in one commit.
36
+ *
37
+ * Unlike `insertMany`, which discards `_id` and mints a fresh ULID, this honours
38
+ * the id on each document — which is what makes a replication upsert idempotent
39
+ * across repeated fetches of the same remote row.
40
+ *
41
+ * `origin` is `'remote'` for authoritative rows replicated in from an origin, or
42
+ * `'local'` for ordinary user writes.
43
+ */
44
+ replaceManyWithIds(
45
+ collection: string,
46
+ docs: Object[],
47
+ origin: 'local' | 'remote',
48
+ ): string[];
49
+
50
+ /** Delete many documents by id, in one commit. Returns the number removed. */
51
+ deleteManyWithIds(
52
+ collection: string,
53
+ ids: string[],
54
+ origin: 'local' | 'remote',
55
+ ): number;
56
+
34
57
  /** Find documents matching the filter. */
35
58
  find(collection: string, filter: Object | null): Object[];
36
59
 
package/src/index.tsx CHANGED
@@ -56,6 +56,16 @@ export type Update = Record<string, unknown>;
56
56
  export interface Collection<T extends Document = Document> {
57
57
  insert(doc: Omit<T, '_id'>): string;
58
58
  insertMany(docs: Omit<T, '_id'>[]): string[];
59
+ /**
60
+ * Upsert many documents **by `_id`**, in one commit. Requires an `_id` on every
61
+ * document — for replicated rows that comes from `deriveDocId(collection, key)`.
62
+ *
63
+ * `origin: 'remote'` marks rows as replicated in from an authoritative origin so
64
+ * they are never replicated back out; it defaults to `'local'`.
65
+ */
66
+ replaceManyWithIds(docs: T[], origin?: 'local' | 'remote'): string[];
67
+ /** Delete many documents by id, in one commit. Returns the number removed. */
68
+ deleteManyWithIds(ids: string[], origin?: 'local' | 'remote'): number;
59
69
  find(filter?: Filter): T[];
60
70
  findOne(filter: Filter): T | null;
61
71
  updateOne(filter: Filter, update: Update): boolean;
@@ -79,6 +89,16 @@ export interface DB {
79
89
  interface JsiTalaDB {
80
90
  insert(collection: string, doc: Object): string;
81
91
  insertMany(collection: string, docs: Object[]): string[];
92
+ replaceManyWithIds(
93
+ collection: string,
94
+ docs: Object[],
95
+ origin: 'local' | 'remote',
96
+ ): string[];
97
+ deleteManyWithIds(
98
+ collection: string,
99
+ ids: string[],
100
+ origin: 'local' | 'remote',
101
+ ): number;
82
102
  find(collection: string, filter: Object | null): Object[];
83
103
  findOne(collection: string, filter: Object | null): Object | null;
84
104
  updateOne(collection: string, filter: Object, update: Object): boolean;
@@ -114,6 +134,10 @@ function collection<T extends Document>(colName: string): Collection<T> {
114
134
  return {
115
135
  insert: (doc) => native().insert(colName, doc as Object),
116
136
  insertMany: (docs) => native().insertMany(colName, docs as Object[]),
137
+ replaceManyWithIds: (docs, origin = 'local') =>
138
+ native().replaceManyWithIds(colName, docs as Object[], origin),
139
+ deleteManyWithIds: (ids, origin = 'local') =>
140
+ native().deleteManyWithIds(colName, ids, origin),
117
141
  find: (filter?) => native().find(colName, filter ?? null) as T[],
118
142
  findOne: (filter) => native().findOne(colName, filter) as T | null,
119
143
  updateOne: (filter, update) => native().updateOne(colName, filter, update),