@foretag/tanstack-db-surrealdb 0.1.16 → 0.1.18

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 CHANGED
@@ -1,8 +1,6 @@
1
1
  # TanstackDB SurrealDB Collections
2
2
 
3
- > Note: Please note this Software is Pre-release pending testing and not yet recommended for production use.
4
-
5
- Add Offline / Local First Caching & Syncing to your SurrealDB app with TanstackDB and Loro (CRDTs). For SurrealDB v3.alpha-13 and SurrealDB JS SDK v2 (and above).
3
+ Add Offline / Local First Caching & Syncing to your SurrealDB app with TanstackDB and Loro (CRDTs). For SurrealDB v3-alpha.16 and SurrealDB JS SDK v2 (and above).
6
4
 
7
5
  - Local / Offline first applications with TanstackDB and Loro
8
6
  - High performance with Low resource consumption
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ function manageTable(db, useLoro, { name, ...args }) {
81
81
  let killed = false;
82
82
  let live;
83
83
  const on = ({ action, value }) => {
84
- console.debug("[surreal live]", name, action, value);
84
+ console.debug("[Surreal Live]", name, action, value);
85
85
  if (action === "KILLED") return;
86
86
  if (action === "CREATE") cb({ type: "insert", row: value });
87
87
  else if (action === "UPDATE")
@@ -289,6 +289,11 @@ function surrealCollectionOptions({
289
289
  commit,
290
290
  markReady
291
291
  }) => {
292
+ if (!db.isFeatureSupported(import_surrealdb2.Features.LiveQueries)) {
293
+ markReady();
294
+ return () => {
295
+ };
296
+ }
292
297
  let offLive = null;
293
298
  const makeTombstone = (id2) => ({
294
299
  id: new import_surrealdb2.RecordId(config.table.name, id2).toString(),
@@ -299,11 +304,8 @@ function surrealCollectionOptions({
299
304
  try {
300
305
  const serverRows = await table.listAll();
301
306
  begin();
302
- if (useLoro) {
303
- reconcileBoot(serverRows, write);
304
- } else {
305
- diffAndEmit(serverRows, write);
306
- }
307
+ if (useLoro) reconcileBoot(serverRows, write);
308
+ else diffAndEmit(serverRows, write);
307
309
  commit();
308
310
  markReady();
309
311
  await flushPushQueue();
@@ -386,9 +388,7 @@ function surrealCollectionOptions({
386
388
  for (const m of p.transaction.mutations) {
387
389
  if (m.type !== "delete") continue;
388
390
  const id2 = m.key;
389
- if (useLoro) {
390
- loroRemove(keyOf(id2));
391
- }
391
+ if (useLoro) loroRemove(keyOf(id2));
392
392
  await table.softDelete(new import_surrealdb2.RecordId(config.table.name, keyOf(id2)));
393
393
  }
394
394
  return resultRows;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  import { LoroDoc } from "loro-crdt";
3
- import { RecordId } from "surrealdb";
3
+ import { Features as Features2, RecordId } from "surrealdb";
4
4
 
5
5
  // src/table.ts
6
6
  import {
@@ -63,7 +63,7 @@ function manageTable(db, useLoro, { name, ...args }) {
63
63
  let killed = false;
64
64
  let live;
65
65
  const on = ({ action, value }) => {
66
- console.debug("[surreal live]", name, action, value);
66
+ console.debug("[Surreal Live]", name, action, value);
67
67
  if (action === "KILLED") return;
68
68
  if (action === "CREATE") cb({ type: "insert", row: value });
69
69
  else if (action === "UPDATE")
@@ -271,6 +271,11 @@ function surrealCollectionOptions({
271
271
  commit,
272
272
  markReady
273
273
  }) => {
274
+ if (!db.isFeatureSupported(Features2.LiveQueries)) {
275
+ markReady();
276
+ return () => {
277
+ };
278
+ }
274
279
  let offLive = null;
275
280
  const makeTombstone = (id2) => ({
276
281
  id: new RecordId(config.table.name, id2).toString(),
@@ -281,11 +286,8 @@ function surrealCollectionOptions({
281
286
  try {
282
287
  const serverRows = await table.listAll();
283
288
  begin();
284
- if (useLoro) {
285
- reconcileBoot(serverRows, write);
286
- } else {
287
- diffAndEmit(serverRows, write);
288
- }
289
+ if (useLoro) reconcileBoot(serverRows, write);
290
+ else diffAndEmit(serverRows, write);
289
291
  commit();
290
292
  markReady();
291
293
  await flushPushQueue();
@@ -368,9 +370,7 @@ function surrealCollectionOptions({
368
370
  for (const m of p.transaction.mutations) {
369
371
  if (m.type !== "delete") continue;
370
372
  const id2 = m.key;
371
- if (useLoro) {
372
- loroRemove(keyOf(id2));
373
- }
373
+ if (useLoro) loroRemove(keyOf(id2));
374
374
  await table.softDelete(new RecordId(config.table.name, keyOf(id2)));
375
375
  }
376
376
  return resultRows;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foretag/tanstack-db-surrealdb",
3
3
  "description": "Add Offline / Local First Caching & Syncing to your SurrealDB app with TanstackDB and Loro (CRDTs)",
4
- "version": "0.1.16",
4
+ "version": "0.1.18",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
@@ -43,13 +43,13 @@
43
43
  "loro-crdt": "^1.10.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "@tanstack/db": "^0.5.10",
46
+ "@tanstack/db": "^0.5.11",
47
47
  "@tanstack/query-db-collection": "^1.0.0",
48
48
  "surrealdb": "2.0.0-alpha.14"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@biomejs/biome": "^2.3.8",
52
- "@tanstack/svelte-db": "^0.1.53",
52
+ "@tanstack/svelte-db": "^0.1.54",
53
53
  "surrealdb": "2.0.0-alpha.14",
54
54
  "tsup": "^8.5.1"
55
55
  }