@cf-sync/client 0.3.1 → 0.3.2
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/dist/index.js +31 -2
- package/docs/guide/defining-your-app.md +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11,6 +11,36 @@ function request(req) {
|
|
|
11
11
|
req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB request failed"));
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Row writes per batch. Each put structured-clones its value synchronously
|
|
16
|
+
* on the calling thread, so a bootstrap's worth of puts issued at once is
|
|
17
|
+
* one long main-thread task; batches let the page breathe between them.
|
|
18
|
+
*/
|
|
19
|
+
const WRITE_BATCH = 1e3;
|
|
20
|
+
/**
|
|
21
|
+
* Issues the row ops in batches, each queued from the previous batch's last
|
|
22
|
+
* request callback — the transaction stays active inside request callbacks,
|
|
23
|
+
* so every op still commits in the one transaction.
|
|
24
|
+
*/
|
|
25
|
+
function writeRows(rowStore, ops) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
let i = 0;
|
|
28
|
+
const next = () => {
|
|
29
|
+
let last = null;
|
|
30
|
+
for (const end = Math.min(i + WRITE_BATCH, ops.length); i < end; i++) {
|
|
31
|
+
const op = ops[i];
|
|
32
|
+
last = op.op === "put" ? rowStore.put(op.value, [op.tbl, op.id]) : rowStore.delete([op.tbl, op.id]);
|
|
33
|
+
}
|
|
34
|
+
if (!last || i >= ops.length) {
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
last.onsuccess = next;
|
|
39
|
+
last.onerror = () => reject(last.error ?? /* @__PURE__ */ new Error("IndexedDB request failed"));
|
|
40
|
+
};
|
|
41
|
+
next();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
14
44
|
function txnDone(txn) {
|
|
15
45
|
return new Promise((resolve, reject) => {
|
|
16
46
|
txn.oncomplete = () => resolve();
|
|
@@ -118,8 +148,7 @@ var IndexedDBSyncStore = class {
|
|
|
118
148
|
if (!(!update.clear && stored !== void 0 && stored.cursor.backendId === update.cursor.backendId && stored.cursor.version >= update.cursor.version)) {
|
|
119
149
|
const rowStore = txn.objectStore(ROWS);
|
|
120
150
|
if (update.clear) rowStore.clear();
|
|
121
|
-
|
|
122
|
-
else rowStore.delete([op.tbl, op.id]);
|
|
151
|
+
await writeRows(rowStore, update.ops);
|
|
123
152
|
metaStore.put({
|
|
124
153
|
schemaVersion: update.schemaVersion,
|
|
125
154
|
cursor: update.cursor
|
|
@@ -54,7 +54,7 @@ for (const { id } of tx.list('checklists', { where: { studyId, assignedTo: userI
|
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
On the server the filter runs in SQL, and each table and field you filter on gets an index the first time a list uses it, so a filtered read does not walk the table. The client's optimistic run still walks its collection, so a mutator that filters once per item in a large batch should build its own lookup up front.
|
|
58
58
|
|
|
59
59
|
The definitions can also be written directly inside `defineApp({ mutators: { ... } })` — inference is identical either way. `defineMutators` is only *required* when declaring an [`authContext`](/guide/auth#reading-the-verdict-in-mutators), its third argument.
|
|
60
60
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cf-sync/client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Browser client for cf-sync: SyncClient (optimistic mutations, offline outbox, IndexedDB mirror, presence) and a TanStack DB collection adapter, with React hooks",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cf-sync/protocol": "^0.2.
|
|
43
|
+
"@cf-sync/protocol": "^0.2.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@tanstack/db": "^0.8.0 || ^0.9.0",
|