@syncular/client 0.85.0 → 0.86.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 -3
- package/dist/apply.d.ts +1 -1
- package/dist/apply.js +25 -26
- package/dist/client.d.ts +19 -9
- package/dist/client.js +62 -45
- package/dist/encryption.js +3 -9
- package/dist/failed-overlay.d.ts +8 -2
- package/dist/failed-overlay.js +31 -20
- package/dist/native-bridge.d.ts +3 -2
- package/dist/native-bridge.js +5 -1
- package/dist/outcomes.d.ts +2 -1
- package/dist/outcomes.js +2 -4
- package/dist/progress.d.ts +4 -0
- package/dist/progress.js +14 -2
- package/dist/realtime-supervisor.d.ts +4 -1
- package/dist/realtime-supervisor.js +2 -2
- package/dist/sync-scheduler.d.ts +8 -2
- package/dist/sync-scheduler.js +11 -3
- package/dist/worker-core.js +7 -2
- package/dist/worker-host.d.ts +5 -0
- package/dist/worker-host.js +6 -0
- package/dist/worker-protocol.d.ts +2 -0
- package/package.json +3 -3
- package/src/apply.ts +34 -47
- package/src/client.ts +85 -53
- package/src/encryption.ts +8 -15
- package/src/failed-overlay.ts +37 -23
- package/src/native-bridge.ts +5 -1
- package/src/outcomes.ts +2 -6
- package/src/progress.ts +18 -2
- package/src/realtime-supervisor.ts +7 -3
- package/src/sync-scheduler.ts +17 -5
- package/src/worker-core.ts +5 -2
- package/src/worker-host.ts +13 -0
- package/src/worker-protocol.ts +2 -0
package/src/worker-core.ts
CHANGED
|
@@ -235,6 +235,7 @@ export function startSyncWorkerCore(
|
|
|
235
235
|
|
|
236
236
|
// -- SPEC §7.5 host loop: event-driven intents, no interactive polling --
|
|
237
237
|
let autoSync = true;
|
|
238
|
+
let coalesceMs = 0;
|
|
238
239
|
let autoSyncScheduled = false;
|
|
239
240
|
let cancelBackground: (() => void) | undefined;
|
|
240
241
|
let backgroundDue = Number.POSITIVE_INFINITY;
|
|
@@ -273,7 +274,7 @@ export function startSyncWorkerCore(
|
|
|
273
274
|
// let every wake-up that arrives while this round waits behind the
|
|
274
275
|
// running one queue its own full drive (§8.4 coalescing).
|
|
275
276
|
autoSyncScheduled = false;
|
|
276
|
-
return running.syncUntilIdle();
|
|
277
|
+
return running.syncUntilIdle({ skipEmpty: true });
|
|
277
278
|
})
|
|
278
279
|
.then((summary) => {
|
|
279
280
|
retryDelayMs = 250;
|
|
@@ -344,7 +345,8 @@ export function startSyncWorkerCore(
|
|
|
344
345
|
return;
|
|
345
346
|
}
|
|
346
347
|
autoSyncScheduled = true;
|
|
347
|
-
|
|
348
|
+
if (coalesceMs > 0) scheduleBackground(runAutoSync, coalesceMs);
|
|
349
|
+
else queueMicrotask(runAutoSync);
|
|
348
350
|
}
|
|
349
351
|
|
|
350
352
|
function requireClient(): SyncClient {
|
|
@@ -383,6 +385,7 @@ export function startSyncWorkerCore(
|
|
|
383
385
|
);
|
|
384
386
|
}
|
|
385
387
|
autoSync = config.autoSync ?? true;
|
|
388
|
+
coalesceMs = config.coalesceMs ?? 0;
|
|
386
389
|
headers = config.headers ?? {};
|
|
387
390
|
const http = { headers: () => headers };
|
|
388
391
|
|
package/src/worker-host.ts
CHANGED
|
@@ -223,6 +223,11 @@ export interface SyncClientHandleConfig {
|
|
|
223
223
|
readonly previousVersionContext?: SyncClientConfig['previousVersionContext'];
|
|
224
224
|
/** Worker-side host loop (§8.4); default true. */
|
|
225
225
|
readonly autoSync?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* §8.4: milliseconds a queued `autoSync` drive waits before it starts, so
|
|
228
|
+
* the claims and writes of one burst ride in one round. Default 0.
|
|
229
|
+
*/
|
|
230
|
+
readonly coalesceMs?: number;
|
|
226
231
|
/**
|
|
227
232
|
* Default: Web Locks. A runtime without Web Locks refuses the handle with
|
|
228
233
|
* `client.web_locks_unavailable` unless the host injects a lock.
|
|
@@ -1121,6 +1126,9 @@ function buildInitConfig(
|
|
|
1121
1126
|
? { previousVersionContext: config.previousVersionContext }
|
|
1122
1127
|
: {}),
|
|
1123
1128
|
...(config.autoSync !== undefined ? { autoSync: config.autoSync } : {}),
|
|
1129
|
+
...(config.coalesceMs !== undefined
|
|
1130
|
+
? { coalesceMs: config.coalesceMs }
|
|
1131
|
+
: {}),
|
|
1124
1132
|
};
|
|
1125
1133
|
}
|
|
1126
1134
|
|
|
@@ -1164,6 +1172,11 @@ export async function createSyncClientHandle(
|
|
|
1164
1172
|
config: SyncClientHandleConfig,
|
|
1165
1173
|
): Promise<SyncClientHandle> {
|
|
1166
1174
|
const resolvedConfig = resolveReplicaConfig(config);
|
|
1175
|
+
if (
|
|
1176
|
+
config.coalesceMs !== undefined &&
|
|
1177
|
+
!(Number.isFinite(config.coalesceMs) && config.coalesceMs >= 0)
|
|
1178
|
+
)
|
|
1179
|
+
throw invalidRequest('coalesceMs must be a non-negative finite number');
|
|
1167
1180
|
const lock = resolvedConfig.leaderLock ?? defaultLeaderLock();
|
|
1168
1181
|
const lockName = resolvedConfig.lockName ?? 'syncular-leader';
|
|
1169
1182
|
const invalidation = new InvalidationEmitter();
|
package/src/worker-protocol.ts
CHANGED
|
@@ -160,6 +160,8 @@ export interface WorkerInitConfig {
|
|
|
160
160
|
* `syncUntilIdle` rounds inside the worker. Default true.
|
|
161
161
|
*/
|
|
162
162
|
readonly autoSync?: boolean;
|
|
163
|
+
/** Delay of a queued `autoSync` drive (§8.4); validated by the handle. */
|
|
164
|
+
readonly coalesceMs?: number;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
/** Successful init reply. */
|