@syncular/client 0.77.3 → 0.77.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.
- package/dist/client.js +41 -39
- package/package.json +3 -3
- package/src/client.ts +44 -43
package/dist/client.js
CHANGED
|
@@ -168,6 +168,8 @@ export class SyncClient {
|
|
|
168
168
|
#transportEnabled;
|
|
169
169
|
#transportEpoch = 0;
|
|
170
170
|
#registrationEpoch = 0;
|
|
171
|
+
/** The units of each window base's latest `setWindow` (§4.8). */
|
|
172
|
+
#windowTargets = new Map();
|
|
171
173
|
#now;
|
|
172
174
|
#outcomeRetentionMaxEntries;
|
|
173
175
|
#retainFailedCommits;
|
|
@@ -336,8 +338,7 @@ export class SyncClient {
|
|
|
336
338
|
? 'unsupported'
|
|
337
339
|
: 'disconnected';
|
|
338
340
|
this.#encryption = config.encryption;
|
|
339
|
-
this.#securityLifecycle =
|
|
340
|
-
config.securityPreflight === true ? 'preflight' : 'active';
|
|
341
|
+
this.#securityLifecycle = config.securityPreflight ? 'preflight' : 'active';
|
|
341
342
|
this.#now = config.now ?? Date.now;
|
|
342
343
|
const outcomeRetentionMaxEntries = config.limits?.outcomeRetentionMaxEntries ?? 1_000;
|
|
343
344
|
if (!Number.isSafeInteger(outcomeRetentionMaxEntries) ||
|
|
@@ -2082,43 +2083,44 @@ export class SyncClient {
|
|
|
2082
2083
|
async setWindowCommand(base, units) {
|
|
2083
2084
|
this.#requireActive();
|
|
2084
2085
|
let changed = false;
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
this.#
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2086
|
+
const baseKey = windowBaseKey(base);
|
|
2087
|
+
const wanted = new Set(units);
|
|
2088
|
+
const live = loadWindowUnits(this.#db, baseKey);
|
|
2089
|
+
// §7.8: a widen registers like `subscribe` and never waits for a
|
|
2090
|
+
// running round.
|
|
2091
|
+
for (const value of wanted) {
|
|
2092
|
+
if (live.some((entry) => entry.value === value))
|
|
2093
|
+
continue;
|
|
2094
|
+
this.#applyBatch((batch) => {
|
|
2095
|
+
const { id, changed: registered } = this.#holdUnit(windowUnitScopes(base, value), false);
|
|
2096
|
+
this.#db.exec(`INSERT OR REPLACE INTO ${WINDOWS_TABLE}(base,unit,sub_id)VALUES(?,?,?)`, [baseKey, value, id]);
|
|
2097
|
+
this.#needsPull ||= registered;
|
|
2098
|
+
batch.window(baseKey, value);
|
|
2099
|
+
batch.status();
|
|
2100
|
+
});
|
|
2101
|
+
changed = true;
|
|
2102
|
+
this.#registrationEpoch += 1;
|
|
2103
|
+
}
|
|
2104
|
+
this.#windowTargets.set(baseKey, wanted);
|
|
2105
|
+
// A shrink yields between eviction chunks, so it runs on the chain; a
|
|
2106
|
+
// later change of the base supersedes a release that has not run.
|
|
2107
|
+
const leaving = live.filter((entry) => !wanted.has(entry.value));
|
|
2108
|
+
if (leaving.length > 0)
|
|
2109
|
+
await this.#serialize(async () => {
|
|
2110
|
+
for (const { value, unitId: id } of leaving) {
|
|
2111
|
+
if (this.#windowTargets.get(baseKey) !== wanted)
|
|
2112
|
+
return;
|
|
2113
|
+
await this.#releaseWindowUnit(baseKey, value, id);
|
|
2114
|
+
changed = true;
|
|
2115
|
+
this.#registrationEpoch += 1;
|
|
2116
|
+
}
|
|
2117
|
+
});
|
|
2118
|
+
const sync = {
|
|
2119
|
+
kind: this.#transportEnabled && changed ? 'interactive' : 'none',
|
|
2118
2120
|
};
|
|
2119
|
-
if (
|
|
2120
|
-
this.#emitSyncIntent(
|
|
2121
|
-
return { value: undefined, effects };
|
|
2121
|
+
if (sync.kind !== 'none')
|
|
2122
|
+
this.#emitSyncIntent(sync);
|
|
2123
|
+
return { value: undefined, effects: { sync } };
|
|
2122
2124
|
}
|
|
2123
2125
|
/**
|
|
2124
2126
|
* The completeness oracle (§4.8): which values of a base are windowed-in
|
|
@@ -3226,7 +3228,7 @@ export class SyncClient {
|
|
|
3226
3228
|
this.#roundFailureCode = unseen;
|
|
3227
3229
|
// §7.8: a round the drive deadline aborted ends with the deadline's
|
|
3228
3230
|
// error, whichever transport call observed the abort.
|
|
3229
|
-
const error = signal?.aborted
|
|
3231
|
+
const error = signal?.aborted ? signal.reason : caught;
|
|
3230
3232
|
// §7.3.5: a request-level lease code stops-and-surfaces — record it
|
|
3231
3233
|
// in leaseState (no local-data purge, §7.3.4) and re-throw. Not a
|
|
3232
3234
|
// silent retry: the app drives recovery to a live resolver. The
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.77.
|
|
3
|
+
"version": "0.77.4",
|
|
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",
|
|
@@ -121,11 +121,11 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
124
|
-
"@syncular/core": "0.77.
|
|
124
|
+
"@syncular/core": "0.77.4"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|
|
127
127
|
"@electric-sql/pglite": "^0.5.4",
|
|
128
|
-
"@syncular/server": "0.77.
|
|
128
|
+
"@syncular/server": "0.77.4",
|
|
129
129
|
"playwright": "1.63.0",
|
|
130
130
|
"vite": "8.3.4"
|
|
131
131
|
}
|
package/src/client.ts
CHANGED
|
@@ -127,7 +127,6 @@ import {
|
|
|
127
127
|
ChangeAccumulator,
|
|
128
128
|
ChangeEmitter,
|
|
129
129
|
type ClientChangeListener,
|
|
130
|
-
type CommandEffects,
|
|
131
130
|
type CommandResult,
|
|
132
131
|
InvalidationEmitter,
|
|
133
132
|
type InvalidationListener,
|
|
@@ -957,6 +956,8 @@ export class SyncClient {
|
|
|
957
956
|
#transportEnabled: boolean;
|
|
958
957
|
#transportEpoch = 0;
|
|
959
958
|
#registrationEpoch = 0;
|
|
959
|
+
/** The units of each window base's latest `setWindow` (§4.8). */
|
|
960
|
+
readonly #windowTargets = new Map<string, ReadonlySet<string>>();
|
|
960
961
|
readonly #now: () => number;
|
|
961
962
|
readonly #outcomeRetentionMaxEntries: number;
|
|
962
963
|
readonly #retainFailedCommits: boolean;
|
|
@@ -1151,8 +1152,7 @@ export class SyncClient {
|
|
|
1151
1152
|
? 'unsupported'
|
|
1152
1153
|
: 'disconnected';
|
|
1153
1154
|
this.#encryption = config.encryption;
|
|
1154
|
-
this.#securityLifecycle =
|
|
1155
|
-
config.securityPreflight === true ? 'preflight' : 'active';
|
|
1155
|
+
this.#securityLifecycle = config.securityPreflight ? 'preflight' : 'active';
|
|
1156
1156
|
this.#now = config.now ?? Date.now;
|
|
1157
1157
|
const outcomeRetentionMaxEntries =
|
|
1158
1158
|
config.limits?.outcomeRetentionMaxEntries ?? 1_000;
|
|
@@ -3242,46 +3242,47 @@ export class SyncClient {
|
|
|
3242
3242
|
): Promise<CommandResult<void>> {
|
|
3243
3243
|
this.#requireActive();
|
|
3244
3244
|
let changed = false;
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
)
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3245
|
+
const baseKey = windowBaseKey(base);
|
|
3246
|
+
const wanted = new Set(units);
|
|
3247
|
+
const live = loadWindowUnits(this.#db, baseKey);
|
|
3248
|
+
// §7.8: a widen registers like `subscribe` and never waits for a
|
|
3249
|
+
// running round.
|
|
3250
|
+
for (const value of wanted) {
|
|
3251
|
+
if (live.some((entry) => entry.value === value)) continue;
|
|
3252
|
+
this.#applyBatch((batch) => {
|
|
3253
|
+
const { id, changed: registered } = this.#holdUnit(
|
|
3254
|
+
windowUnitScopes(base, value),
|
|
3255
|
+
false,
|
|
3256
|
+
);
|
|
3257
|
+
this.#db.exec(
|
|
3258
|
+
`INSERT OR REPLACE INTO ${WINDOWS_TABLE}(base,unit,sub_id)VALUES(?,?,?)`,
|
|
3259
|
+
[baseKey, value, id],
|
|
3260
|
+
);
|
|
3261
|
+
this.#needsPull ||= registered;
|
|
3262
|
+
batch.window(baseKey, value);
|
|
3263
|
+
batch.status();
|
|
3264
|
+
});
|
|
3265
|
+
changed = true;
|
|
3266
|
+
this.#registrationEpoch += 1;
|
|
3267
|
+
}
|
|
3268
|
+
this.#windowTargets.set(baseKey, wanted);
|
|
3269
|
+
// A shrink yields between eviction chunks, so it runs on the chain; a
|
|
3270
|
+
// later change of the base supersedes a release that has not run.
|
|
3271
|
+
const leaving = live.filter((entry) => !wanted.has(entry.value));
|
|
3272
|
+
if (leaving.length > 0)
|
|
3273
|
+
await this.#serialize(async () => {
|
|
3274
|
+
for (const { value, unitId: id } of leaving) {
|
|
3275
|
+
if (this.#windowTargets.get(baseKey) !== wanted) return;
|
|
3276
|
+
await this.#releaseWindowUnit(baseKey, value, id);
|
|
3277
|
+
changed = true;
|
|
3278
|
+
this.#registrationEpoch += 1;
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
const sync: SyncIntent = {
|
|
3282
|
+
kind: this.#transportEnabled && changed ? 'interactive' : 'none',
|
|
3282
3283
|
};
|
|
3283
|
-
if (
|
|
3284
|
-
return { value: undefined, effects };
|
|
3284
|
+
if (sync.kind !== 'none') this.#emitSyncIntent(sync);
|
|
3285
|
+
return { value: undefined, effects: { sync } };
|
|
3285
3286
|
}
|
|
3286
3287
|
|
|
3287
3288
|
/**
|
|
@@ -4673,7 +4674,7 @@ export class SyncClient {
|
|
|
4673
4674
|
if (unseen !== undefined) this.#roundFailureCode = unseen;
|
|
4674
4675
|
// §7.8: a round the drive deadline aborted ends with the deadline's
|
|
4675
4676
|
// error, whichever transport call observed the abort.
|
|
4676
|
-
const error: unknown = signal?.aborted
|
|
4677
|
+
const error: unknown = signal?.aborted ? signal.reason : caught;
|
|
4677
4678
|
// §7.3.5: a request-level lease code stops-and-surfaces — record it
|
|
4678
4679
|
// in leaseState (no local-data purge, §7.3.4) and re-throw. Not a
|
|
4679
4680
|
// silent retry: the app drives recovery to a live resolver. The
|