@syncular/client 0.53.1 → 0.55.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.
- package/README.md +10 -0
- package/dist/client.js +30 -23
- package/dist/invalidation.d.ts +8 -0
- package/dist/invalidation.js +7 -0
- package/dist/worker-core.d.ts +77 -0
- package/dist/worker-core.js +505 -0
- package/dist/worker-entry.d.ts +3 -55
- package/dist/worker-entry.js +4 -553
- package/dist/worker-local-authority.d.ts +3 -0
- package/dist/worker-local-authority.js +70 -0
- package/dist/worker-protocol.d.ts +2 -0
- package/dist/worker-protocol.js +2 -0
- package/dist/worker-remote.d.ts +5 -0
- package/dist/worker-remote.js +5 -0
- package/package.json +12 -4
- package/src/client.ts +42 -21
- package/src/invalidation.ts +19 -0
- package/src/worker-core.ts +713 -0
- package/src/worker-entry.ts +5 -743
- package/src/worker-local-authority.ts +106 -0
- package/src/worker-protocol.ts +3 -0
- package/src/worker-remote.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "Syncular TypeScript client core — offline-first sync over SQLite (WASM/OPFS, Bun, Node)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -74,6 +74,14 @@
|
|
|
74
74
|
"default": "./dist/worker-entry.js"
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
+
"./worker/remote": {
|
|
78
|
+
"bun": "./src/worker-remote.ts",
|
|
79
|
+
"browser": "./dist/worker-remote.js",
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/worker-remote.d.ts",
|
|
82
|
+
"default": "./dist/worker-remote.js"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
77
85
|
"./authority": {
|
|
78
86
|
"bun": "./src/authority.ts",
|
|
79
87
|
"browser": "./dist/authority.js",
|
|
@@ -97,12 +105,12 @@
|
|
|
97
105
|
},
|
|
98
106
|
"dependencies": {
|
|
99
107
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
100
|
-
"@syncular/core": "0.
|
|
108
|
+
"@syncular/core": "0.55.0"
|
|
101
109
|
},
|
|
102
110
|
"devDependencies": {
|
|
103
|
-
"@syncular/server": "0.53.1",
|
|
104
|
-
"playwright": "1.63.0",
|
|
105
111
|
"@electric-sql/pglite": "^0.5.4",
|
|
112
|
+
"@syncular/server": "0.55.0",
|
|
113
|
+
"playwright": "1.63.0",
|
|
106
114
|
"vite": "8.3.4"
|
|
107
115
|
}
|
|
108
116
|
}
|
package/src/client.ts
CHANGED
|
@@ -922,13 +922,10 @@ export class SyncClient {
|
|
|
922
922
|
#needsPull = false;
|
|
923
923
|
readonly #progress = new ProgressEmitter();
|
|
924
924
|
#progressAttempt = 0;
|
|
925
|
-
#syncing = false;
|
|
926
925
|
/**
|
|
927
926
|
* True from the synchronous entry of `sync()` until its serialized round
|
|
928
927
|
* settles — the "one loop owns the database" guard that rejects a
|
|
929
|
-
* concurrent `sync()` before the op chain would queue it.
|
|
930
|
-
* `#syncing`, which is true only while `#runSync`'s body actually runs
|
|
931
|
-
* (the fast-bail the delta path reads).
|
|
928
|
+
* concurrent `sync()` before the op chain would queue it.
|
|
932
929
|
*/
|
|
933
930
|
#syncOutstanding = false;
|
|
934
931
|
/**
|
|
@@ -4347,10 +4344,7 @@ export class SyncClient {
|
|
|
4347
4344
|
schemaFloor: this.#schemaFloor,
|
|
4348
4345
|
};
|
|
4349
4346
|
}
|
|
4350
|
-
|
|
4351
|
-
// Cleared before the round, not after: a wake-up (or a delta dropped
|
|
4352
|
-
// because this pull is mid-flight) that lands during the round must
|
|
4353
|
-
// survive it — the reference server keeps no replay buffer (§8.2).
|
|
4347
|
+
// A wake-up that lands during the round must survive it (§8.4).
|
|
4354
4348
|
this.#setSyncNeeded(false);
|
|
4355
4349
|
try {
|
|
4356
4350
|
await this.#drainPendingEvictions();
|
|
@@ -4554,8 +4548,6 @@ export class SyncClient {
|
|
|
4554
4548
|
this.#emitSyncIntent(intent);
|
|
4555
4549
|
}
|
|
4556
4550
|
throw error;
|
|
4557
|
-
} finally {
|
|
4558
|
-
this.#syncing = false;
|
|
4559
4551
|
}
|
|
4560
4552
|
}
|
|
4561
4553
|
|
|
@@ -5096,19 +5088,26 @@ export class SyncClient {
|
|
|
5096
5088
|
|
|
5097
5089
|
async #handleRealtimeBinary(bytes: Uint8Array): Promise<void> {
|
|
5098
5090
|
if (!this.#transportEnabled) return;
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
// worth it. (An optimization; the op chain below is the correctness
|
|
5103
|
-
// mechanism — it also excludes a delta from racing a `setWindow` or a
|
|
5104
|
-
// sync round that started between this check and the apply.)
|
|
5105
|
-
this.#setSyncNeeded(true);
|
|
5106
|
-
return;
|
|
5107
|
-
}
|
|
5091
|
+
const resetEpoch = this.#localResetEpoch;
|
|
5092
|
+
const securityEpoch = this.#securityEpoch;
|
|
5093
|
+
const transportEpoch = this.#transportEpoch;
|
|
5108
5094
|
// Serialize the apply on the operation chain: a delta must never
|
|
5109
5095
|
// interleave its transactions or share the `#batch` accumulator with a
|
|
5110
5096
|
// pull round or a `setWindow` at an await point (§8.2).
|
|
5111
5097
|
await this.#serialize(async () => {
|
|
5098
|
+
if (
|
|
5099
|
+
!this.#started ||
|
|
5100
|
+
!this.#transportEnabled ||
|
|
5101
|
+
this.#securityLifecycle !== 'active' ||
|
|
5102
|
+
securityEpoch !== this.#securityEpoch ||
|
|
5103
|
+
transportEpoch !== this.#transportEpoch
|
|
5104
|
+
)
|
|
5105
|
+
return;
|
|
5106
|
+
if (resetEpoch !== this.#localResetEpoch) {
|
|
5107
|
+
this.#setSyncNeeded(true);
|
|
5108
|
+
this.#emitSyncNeeded('catchup-required');
|
|
5109
|
+
return;
|
|
5110
|
+
}
|
|
5112
5111
|
try {
|
|
5113
5112
|
const message = decodeMessage(bytes);
|
|
5114
5113
|
if (message.msgKind !== 'response') return;
|
|
@@ -5445,7 +5444,11 @@ export class SyncClient {
|
|
|
5445
5444
|
break;
|
|
5446
5445
|
}
|
|
5447
5446
|
case 'COMMIT':
|
|
5448
|
-
if (
|
|
5447
|
+
if (
|
|
5448
|
+
section !== undefined &&
|
|
5449
|
+
!section.skip &&
|
|
5450
|
+
section.sub !== undefined
|
|
5451
|
+
) {
|
|
5449
5452
|
const changes = frame.changes.filter((change) => {
|
|
5450
5453
|
if (change.op !== 'delete') return true;
|
|
5451
5454
|
const table = frame.tables[change.tableIndex];
|
|
@@ -5457,7 +5460,12 @@ export class SyncClient {
|
|
|
5457
5460
|
);
|
|
5458
5461
|
});
|
|
5459
5462
|
if (changes.length > 0) {
|
|
5460
|
-
await this.#applyCommit(
|
|
5463
|
+
await this.#applyCommit(
|
|
5464
|
+
{ ...frame, changes },
|
|
5465
|
+
summary,
|
|
5466
|
+
section.sub.id,
|
|
5467
|
+
mode,
|
|
5468
|
+
);
|
|
5461
5469
|
}
|
|
5462
5470
|
}
|
|
5463
5471
|
break;
|
|
@@ -5875,6 +5883,8 @@ export class SyncClient {
|
|
|
5875
5883
|
async #applyCommit(
|
|
5876
5884
|
frame: CommitFrame,
|
|
5877
5885
|
summary: MutableSummary,
|
|
5886
|
+
subscriptionId: string,
|
|
5887
|
+
source: 'delta' | 'pull',
|
|
5878
5888
|
): Promise<void> {
|
|
5879
5889
|
await applyCommitFrame(
|
|
5880
5890
|
this.#db,
|
|
@@ -5886,6 +5896,17 @@ export class SyncClient {
|
|
|
5886
5896
|
this.#recordCommitChanges(batch, frame);
|
|
5887
5897
|
const result = fn();
|
|
5888
5898
|
this.#replayOutbox(result, false);
|
|
5899
|
+
for (const table of new Set(
|
|
5900
|
+
frame.changes.map((change) => frame.tables[change.tableIndex]),
|
|
5901
|
+
)) {
|
|
5902
|
+
if (table !== undefined)
|
|
5903
|
+
batch.appliedCommit({
|
|
5904
|
+
subscriptionId,
|
|
5905
|
+
table,
|
|
5906
|
+
commitSeq: frame.commitSeq,
|
|
5907
|
+
source,
|
|
5908
|
+
});
|
|
5909
|
+
}
|
|
5889
5910
|
return result;
|
|
5890
5911
|
}),
|
|
5891
5912
|
);
|
package/src/invalidation.ts
CHANGED
|
@@ -49,6 +49,13 @@ export interface ClientChangeBatch {
|
|
|
49
49
|
readonly conflictsChanged: boolean;
|
|
50
50
|
readonly rejectionsChanged: boolean;
|
|
51
51
|
readonly outcomesChanged: boolean;
|
|
52
|
+
/** Server COMMIT frames applied by this transaction, when present. */
|
|
53
|
+
readonly appliedCommits?: readonly {
|
|
54
|
+
readonly subscriptionId: string;
|
|
55
|
+
readonly table: string;
|
|
56
|
+
readonly commitSeq: number;
|
|
57
|
+
readonly source: 'delta' | 'pull';
|
|
58
|
+
}[];
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export type ClientChangeListener = (batch: ClientChangeBatch) => void;
|
|
@@ -93,6 +100,15 @@ export class ChangeAccumulator {
|
|
|
93
100
|
#conflicts = false;
|
|
94
101
|
#rejections = false;
|
|
95
102
|
#outcomes = false;
|
|
103
|
+
readonly #appliedCommits: NonNullable<
|
|
104
|
+
ClientChangeBatch['appliedCommits']
|
|
105
|
+
>[number][] = [];
|
|
106
|
+
|
|
107
|
+
appliedCommit(
|
|
108
|
+
entry: NonNullable<ClientChangeBatch['appliedCommits']>[number],
|
|
109
|
+
): void {
|
|
110
|
+
this.#appliedCommits.push(entry);
|
|
111
|
+
}
|
|
96
112
|
|
|
97
113
|
/** Mark a whole table dirty, discarding any weaker scope-only facts. */
|
|
98
114
|
table(name: string): void {
|
|
@@ -214,6 +230,9 @@ export class ChangeAccumulator {
|
|
|
214
230
|
conflictsChanged: this.#conflicts,
|
|
215
231
|
rejectionsChanged: this.#rejections,
|
|
216
232
|
outcomesChanged: this.#outcomes,
|
|
233
|
+
...(this.#appliedCommits.length > 0
|
|
234
|
+
? { appliedCommits: this.#appliedCommits }
|
|
235
|
+
: {}),
|
|
217
236
|
};
|
|
218
237
|
}
|
|
219
238
|
}
|