@syncular/client 0.59.0 → 0.60.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 +27 -27
- package/dist/apply.d.ts +6 -5
- package/dist/apply.js +52 -25
- package/dist/authority.js +21 -16
- package/dist/blob.d.ts +4 -4
- package/dist/bun-database.js +3 -16
- package/dist/client.d.ts +57 -66
- package/dist/client.js +701 -796
- package/dist/devtools.d.ts +2 -2
- package/dist/devtools.js +3 -3
- package/dist/diagnostics.d.ts +17 -28
- package/dist/diagnostics.js +1 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/failed-overlay.js +4 -1
- package/dist/http.js +10 -4
- package/dist/invalidation.d.ts +3 -4
- package/dist/invalidation.js +9 -22
- package/dist/native-bridge.d.ts +7 -16
- package/dist/native-bridge.js +16 -41
- package/dist/node-database.js +16 -25
- package/dist/outbox.js +1 -0
- package/dist/progress.d.ts +2 -2
- package/dist/query-guard.d.ts +15 -6
- package/dist/query-guard.js +38 -6
- package/dist/reactive-store.js +2 -2
- package/dist/remote.js +9 -9
- package/dist/schema.d.ts +3 -2
- package/dist/schema.js +28 -12
- package/dist/state.d.ts +69 -36
- package/dist/state.js +178 -89
- package/dist/sync-scheduler.js +2 -2
- package/dist/transport.d.ts +2 -2
- package/dist/window.d.ts +30 -52
- package/dist/window.js +33 -77
- package/dist/worker-core.js +6 -6
- package/dist/worker-host.d.ts +9 -8
- package/dist/worker-host.js +11 -11
- package/dist/worker-protocol.d.ts +9 -8
- package/package.json +3 -3
- package/src/apply.ts +87 -33
- package/src/authority.ts +31 -17
- package/src/blob.ts +4 -3
- package/src/bun-database.ts +9 -14
- package/src/client.ts +886 -1037
- package/src/devtools.ts +5 -5
- package/src/diagnostics.ts +17 -37
- package/src/errors.ts +1 -1
- package/src/failed-overlay.ts +6 -1
- package/src/http.ts +13 -8
- package/src/invalidation.ts +9 -29
- package/src/native-bridge.ts +22 -58
- package/src/node-database.ts +26 -27
- package/src/outbox.ts +1 -0
- package/src/progress.ts +2 -2
- package/src/query-guard.ts +45 -8
- package/src/reactive-store.ts +2 -2
- package/src/remote.ts +12 -16
- package/src/schema.ts +48 -13
- package/src/state.ts +246 -125
- package/src/sync-scheduler.ts +2 -2
- package/src/transport.ts +2 -2
- package/src/window.ts +55 -134
- package/src/worker-core.ts +6 -6
- package/src/worker-host.ts +13 -16
- package/src/worker-protocol.ts +8 -8
package/dist/sync-scheduler.js
CHANGED
|
@@ -14,7 +14,7 @@ export function installSyncScheduler(client, options = {}) {
|
|
|
14
14
|
let backgroundReady = false;
|
|
15
15
|
let backgroundDue = Number.POSITIVE_INFINITY;
|
|
16
16
|
let cancelBackground;
|
|
17
|
-
// §7.
|
|
17
|
+
// §7.7 backoff for drives that end without a client retry intent.
|
|
18
18
|
let retryDelayMs = 250;
|
|
19
19
|
const report = (error) => {
|
|
20
20
|
if (options.onError !== undefined) {
|
|
@@ -70,7 +70,7 @@ export function installSyncScheduler(client, options = {}) {
|
|
|
70
70
|
if (stopped)
|
|
71
71
|
return;
|
|
72
72
|
report(error);
|
|
73
|
-
// §7.
|
|
73
|
+
// §7.8: a retryable drive rejection owes another drive. A retryable
|
|
74
74
|
// round failure already handed this loop its background intent; the
|
|
75
75
|
// drive deadline did not. An unreachable endpoint waits for the
|
|
76
76
|
// host's connectivity resume (§1.8).
|
package/dist/transport.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* One combined push+pull round trip: SSP2 request bytes → response bytes.
|
|
9
|
-
* `signal` aborts when the `syncUntilIdle` deadline elapses (§7.
|
|
9
|
+
* `signal` aborts when the `syncUntilIdle` deadline elapses (§7.8); a
|
|
10
10
|
* transport that honors it releases the round instead of holding it open.
|
|
11
11
|
*/
|
|
12
12
|
export type SyncTransport = (request: Uint8Array, signal?: AbortSignal) => Promise<Uint8Array>;
|
|
@@ -32,7 +32,7 @@ export interface SegmentFetchRequest {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly byteLength?: number;
|
|
34
34
|
readonly onProgress?: (bytesReceived: number) => void;
|
|
35
|
-
/** Aborts with the round when the `syncUntilIdle` deadline elapses (§7.
|
|
35
|
+
/** Aborts with the round when the `syncUntilIdle` deadline elapses (§7.8). */
|
|
36
36
|
readonly signal?: AbortSignal;
|
|
37
37
|
}
|
|
38
38
|
/**
|
package/dist/window.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
export declare const PENDING_EVICTIONS = "
|
|
1
|
+
export declare const PENDING_EVICTIONS = "_syncular_pending_evictions";
|
|
2
2
|
export declare const WINDOWS_TABLE = "_syncular_windows";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Windows (SPEC.md §4.8).
|
|
5
5
|
*
|
|
6
6
|
* A window is a partial local replica keyed by scope VALUES: the client
|
|
7
|
-
* holds
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* mutation of one — so it needs zero wire or server changes.
|
|
7
|
+
* holds the units of a chosen set of values of a window BASE (one scope
|
|
8
|
+
* variable plus fixed values). Windowing is a set difference on §4.1 units,
|
|
9
|
+
* never a mutation of one, so it needs no wire or server change.
|
|
11
10
|
*
|
|
12
|
-
* This module owns the registry bookkeeping
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* transaction and the invalidation choke point.
|
|
11
|
+
* This module owns the registry bookkeeping. The eviction that fuses with a
|
|
12
|
+
* shrink (E1–E4) lives on the client, which holds the DB transaction and the
|
|
13
|
+
* invalidation choke point.
|
|
16
14
|
*/
|
|
17
|
-
import { type ScopeMap } from '@syncular/core';
|
|
15
|
+
import { type ScopeMap, type UnitScopes } from '@syncular/core';
|
|
18
16
|
import type { ClientDatabase } from './database.js';
|
|
19
17
|
export type TimeBucketUnit = 'month';
|
|
20
18
|
/** Derive the immutable UTC scope value stored when a row is created. */
|
|
@@ -22,55 +20,35 @@ export declare function creationTimeBucket(createdAtMs: number, unit: TimeBucket
|
|
|
22
20
|
/** Return a rolling UTC month window ordered from oldest to newest. */
|
|
23
21
|
export declare function last(count: number, unit: TimeBucketUnit, nowMs?: number): string[];
|
|
24
22
|
/**
|
|
25
|
-
* A window base:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* subscription verbatim.
|
|
23
|
+
* A window base (§4.8): the selected scope variable plus the fixed scope
|
|
24
|
+
* values every unit of its family shares. A base names no table: each unit
|
|
25
|
+
* covers every table declaring its variables (§4.1).
|
|
29
26
|
*/
|
|
30
27
|
export interface WindowBase {
|
|
31
|
-
readonly table: string;
|
|
32
28
|
/** The scope variable whose values are the window units. */
|
|
33
29
|
readonly variable: string;
|
|
34
|
-
/**
|
|
35
|
-
readonly fixedScopes?:
|
|
36
|
-
readonly params?: string;
|
|
37
|
-
}
|
|
38
|
-
/** A live unit in the registry: its value and the subscription it drives. */
|
|
39
|
-
export interface WindowUnit {
|
|
40
|
-
readonly unit: string;
|
|
41
|
-
readonly subId: string;
|
|
30
|
+
/** One value per other variable, shared by every unit. */
|
|
31
|
+
readonly fixedScopes?: UnitScopes;
|
|
42
32
|
}
|
|
43
|
-
|
|
44
|
-
readonly baseKey: string;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A stable, server-opaque key for a window base — table + variable +
|
|
48
|
-
* canonical fixed scopes. Two `setWindow` calls with the same base
|
|
49
|
-
* address the same registry rows.
|
|
50
|
-
*/
|
|
33
|
+
/** A stable key for a window base: variable + canonical fixed scopes. */
|
|
51
34
|
export declare function windowBaseKey(base: WindowBase): string;
|
|
52
|
-
/** The
|
|
53
|
-
export declare function
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*/
|
|
60
|
-
export declare function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export declare function getWindowUnitBySubId(db: ClientDatabase, subId: string): RegisteredWindowUnit | undefined;
|
|
65
|
-
export declare function insertWindowUnit(db: ClientDatabase, baseKey: string, unit: string, subId: string): void;
|
|
66
|
-
export declare function deleteWindowUnit(db: ClientDatabase, baseKey: string, unit: string): void;
|
|
67
|
-
/** Is a single scope value windowed-in for this base? (the oracle, I3) */
|
|
68
|
-
export declare function isUnitLive(db: ClientDatabase, baseKey: string, unit: string): boolean;
|
|
35
|
+
/** The unit of one window value: the fixed scopes plus the value. */
|
|
36
|
+
export declare function windowUnitScopes(base: WindowBase, value: string): UnitScopes;
|
|
37
|
+
/** Registry rows for a base, ordered by value: value → unit id. */
|
|
38
|
+
export declare function loadWindowUnits(db: ClientDatabase, baseKey: string): {
|
|
39
|
+
readonly value: string;
|
|
40
|
+
readonly unitId: string;
|
|
41
|
+
}[];
|
|
42
|
+
/** Every window registry row that references a unit (§4.1 references). */
|
|
43
|
+
export declare function windowRefs(db: ClientDatabase, unitId: string): {
|
|
44
|
+
readonly baseKey: string;
|
|
45
|
+
readonly value: string;
|
|
46
|
+
}[];
|
|
69
47
|
export interface PendingEviction {
|
|
70
|
-
readonly
|
|
48
|
+
readonly unitId: string;
|
|
71
49
|
readonly table: string;
|
|
72
50
|
readonly effective: ScopeMap;
|
|
73
51
|
}
|
|
74
|
-
export declare function savePendingEviction(db: ClientDatabase,
|
|
75
|
-
export declare function deletePendingEviction(db: ClientDatabase,
|
|
52
|
+
export declare function savePendingEviction(db: ClientDatabase, entry: PendingEviction): void;
|
|
53
|
+
export declare function deletePendingEviction(db: ClientDatabase, unitId: string, table?: string): void;
|
|
76
54
|
export declare function loadPendingEvictions(db: ClientDatabase): PendingEviction[];
|
package/dist/window.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
export const PENDING_EVICTIONS = '
|
|
1
|
+
export const PENDING_EVICTIONS = '_syncular_pending_evictions';
|
|
2
2
|
export const WINDOWS_TABLE = '_syncular_windows';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Windows (SPEC.md §4.8).
|
|
5
5
|
*
|
|
6
6
|
* A window is a partial local replica keyed by scope VALUES: the client
|
|
7
|
-
* holds
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* mutation of one — so it needs zero wire or server changes.
|
|
7
|
+
* holds the units of a chosen set of values of a window BASE (one scope
|
|
8
|
+
* variable plus fixed values). Windowing is a set difference on §4.1 units,
|
|
9
|
+
* never a mutation of one, so it needs no wire or server change.
|
|
11
10
|
*
|
|
12
|
-
* This module owns the registry bookkeeping
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* transaction and the invalidation choke point.
|
|
11
|
+
* This module owns the registry bookkeeping. The eviction that fuses with a
|
|
12
|
+
* shrink (E1–E4) lives on the client, which holds the DB transaction and the
|
|
13
|
+
* invalidation choke point.
|
|
16
14
|
*/
|
|
17
|
-
import {
|
|
15
|
+
import { canonicalUnitJson, } from '@syncular/core';
|
|
18
16
|
import { invalidRequest } from './errors.js';
|
|
19
17
|
const MAX_TIME_BUCKET_MS = 253_402_300_799_999;
|
|
20
18
|
function monthBucket(year, month) {
|
|
@@ -54,85 +52,43 @@ export function last(count, unit, nowMs = Date.now()) {
|
|
|
54
52
|
}
|
|
55
53
|
return units;
|
|
56
54
|
}
|
|
57
|
-
/**
|
|
58
|
-
* A stable, server-opaque key for a window base — table + variable +
|
|
59
|
-
* canonical fixed scopes. Two `setWindow` calls with the same base
|
|
60
|
-
* address the same registry rows.
|
|
61
|
-
*/
|
|
55
|
+
/** A stable key for a window base: variable + canonical fixed scopes. */
|
|
62
56
|
export function windowBaseKey(base) {
|
|
63
|
-
|
|
64
|
-
return `${base.table}\0${base.variable}\0${fixed}`;
|
|
65
|
-
}
|
|
66
|
-
/** The full requested scope map for one unit (fixed scopes + the unit). */
|
|
67
|
-
export function unitScopes(base, unit) {
|
|
68
|
-
const scopes = {};
|
|
69
|
-
for (const [variable, values] of Object.entries(base.fixedScopes ?? {})) {
|
|
70
|
-
scopes[variable] = [...values];
|
|
71
|
-
}
|
|
72
|
-
scopes[base.variable] = [unit];
|
|
73
|
-
return scopes;
|
|
57
|
+
return `${base.variable}\0${canonicalUnitJson(base.fixedScopes ?? {})}`;
|
|
74
58
|
}
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* not interpreted by the server (§4.1), so the exact hash is pure client
|
|
79
|
-
* convention; SHA-256 matches the SPEC's worked example.
|
|
80
|
-
*/
|
|
81
|
-
export async function deriveSubId(base, unit) {
|
|
82
|
-
const canonical = canonicalScopeJson(unitScopes(base, unit));
|
|
83
|
-
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical));
|
|
84
|
-
let hex = '';
|
|
85
|
-
for (const byte of new Uint8Array(digest)) {
|
|
86
|
-
hex += byte.toString(16).padStart(2, '0');
|
|
87
|
-
}
|
|
88
|
-
return `w:${base.table}:${hex.slice(0, 16)}`;
|
|
59
|
+
/** The unit of one window value: the fixed scopes plus the value. */
|
|
60
|
+
export function windowUnitScopes(base, value) {
|
|
61
|
+
return { ...base.fixedScopes, [base.variable]: value };
|
|
89
62
|
}
|
|
90
|
-
/**
|
|
63
|
+
/** Registry rows for a base, ordered by value: value → unit id. */
|
|
91
64
|
export function loadWindowUnits(db, baseKey) {
|
|
92
65
|
return db
|
|
93
66
|
.query(`SELECT unit,sub_id FROM ${WINDOWS_TABLE} WHERE base=? ORDER BY unit`, [baseKey])
|
|
94
|
-
.map((row) => ({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const row = db.query(`SELECT base, unit, sub_id FROM ${WINDOWS_TABLE}
|
|
99
|
-
WHERE sub_id = ? LIMIT 1`, [subId])[0];
|
|
100
|
-
return row === undefined
|
|
101
|
-
? undefined
|
|
102
|
-
: {
|
|
103
|
-
baseKey: row.base,
|
|
104
|
-
unit: row.unit,
|
|
105
|
-
subId: row.sub_id,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
export function insertWindowUnit(db, baseKey, unit, subId) {
|
|
109
|
-
db.exec(`INSERT OR REPLACE INTO ${WINDOWS_TABLE}(base,unit,sub_id)VALUES(?,?,?)`, [baseKey, unit, subId]);
|
|
110
|
-
}
|
|
111
|
-
export function deleteWindowUnit(db, baseKey, unit) {
|
|
112
|
-
db.exec(`DELETE FROM ${WINDOWS_TABLE} WHERE base=? AND unit=?`, [
|
|
113
|
-
baseKey,
|
|
114
|
-
unit,
|
|
115
|
-
]);
|
|
67
|
+
.map((row) => ({
|
|
68
|
+
value: row.unit,
|
|
69
|
+
unitId: row.sub_id,
|
|
70
|
+
}));
|
|
116
71
|
}
|
|
117
|
-
/**
|
|
118
|
-
export function
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
72
|
+
/** Every window registry row that references a unit (§4.1 references). */
|
|
73
|
+
export function windowRefs(db, unitId) {
|
|
74
|
+
return db
|
|
75
|
+
.query(`SELECT base,unit FROM ${WINDOWS_TABLE} WHERE sub_id=?`, [unitId])
|
|
76
|
+
.map((row) => ({
|
|
77
|
+
baseKey: row.base,
|
|
78
|
+
value: row.unit,
|
|
79
|
+
}));
|
|
123
80
|
}
|
|
124
|
-
export function savePendingEviction(db,
|
|
125
|
-
db.exec(`INSERT OR REPLACE INTO ${PENDING_EVICTIONS}(
|
|
126
|
-
VALUES (?, ?, ?)`, [subId, table, JSON.stringify(effective)]);
|
|
81
|
+
export function savePendingEviction(db, entry) {
|
|
82
|
+
db.exec(`INSERT OR REPLACE INTO ${PENDING_EVICTIONS}(unit_id,tbl,effective_scopes)VALUES(?,?,?)`, [entry.unitId, entry.table, JSON.stringify(entry.effective)]);
|
|
127
83
|
}
|
|
128
|
-
export function deletePendingEviction(db,
|
|
129
|
-
db.exec(`DELETE FROM ${PENDING_EVICTIONS} WHERE
|
|
84
|
+
export function deletePendingEviction(db, unitId, table) {
|
|
85
|
+
db.exec(`DELETE FROM ${PENDING_EVICTIONS} WHERE unit_id=?${table === undefined ? '' : ' AND tbl=?'}`, table === undefined ? [unitId] : [unitId, table]);
|
|
130
86
|
}
|
|
131
87
|
export function loadPendingEvictions(db) {
|
|
132
88
|
return db
|
|
133
|
-
.query(`SELECT
|
|
89
|
+
.query(`SELECT unit_id,tbl,effective_scopes FROM ${PENDING_EVICTIONS}`)
|
|
134
90
|
.map((row) => ({
|
|
135
|
-
|
|
91
|
+
unitId: row.unit_id,
|
|
136
92
|
table: row.tbl,
|
|
137
93
|
effective: JSON.parse(row.effective_scopes),
|
|
138
94
|
}));
|
package/dist/worker-core.js
CHANGED
|
@@ -76,7 +76,7 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
|
|
|
76
76
|
let autoSyncScheduled = false;
|
|
77
77
|
let cancelBackground;
|
|
78
78
|
let backgroundDue = Number.POSITIVE_INFINITY;
|
|
79
|
-
// §7.
|
|
79
|
+
// §7.7 backoff for drives that end without a client retry intent.
|
|
80
80
|
let retryDelayMs = 250;
|
|
81
81
|
const scheduleBackground = overrides.scheduleBackground ??
|
|
82
82
|
((callback, delayMs) => {
|
|
@@ -127,7 +127,7 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
|
|
|
127
127
|
t: 'event',
|
|
128
128
|
event: { kind: 'synced', error: toErrorShape(error) },
|
|
129
129
|
});
|
|
130
|
-
// §7.
|
|
130
|
+
// §7.8: a retryable drive rejection owes another drive. A retryable
|
|
131
131
|
// round failure already handed this loop its background intent; the
|
|
132
132
|
// drive deadline did not. An unreachable endpoint waits for the
|
|
133
133
|
// host's connectivity resume (§1.8).
|
|
@@ -360,8 +360,8 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
|
|
|
360
360
|
'commitOutcomes',
|
|
361
361
|
'resolveCommitOutcome',
|
|
362
362
|
'pendingCommits',
|
|
363
|
-
'
|
|
364
|
-
'
|
|
363
|
+
'units',
|
|
364
|
+
'unit',
|
|
365
365
|
'connectRealtime',
|
|
366
366
|
'disconnectRealtime',
|
|
367
367
|
'setPresence',
|
|
@@ -415,7 +415,7 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
|
|
|
415
415
|
},
|
|
416
416
|
resetClientId: () => requireClient().resetClientId(),
|
|
417
417
|
localRevision: () => requireClient().localRevision,
|
|
418
|
-
diagnosticsSnapshot: (
|
|
418
|
+
diagnosticsSnapshot: () => {
|
|
419
419
|
const running = requireClient();
|
|
420
420
|
// The first pull makes the worker a push source: no tab has asked for
|
|
421
421
|
// diagnostics before it, so no snapshot is built per revision until then.
|
|
@@ -423,7 +423,7 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
|
|
|
423
423
|
pushingDiagnostics = true;
|
|
424
424
|
running.onDiagnostics(postDiagnostics);
|
|
425
425
|
}
|
|
426
|
-
return workerDiagnostics(running.diagnosticsSnapshot(
|
|
426
|
+
return workerDiagnostics(running.diagnosticsSnapshot());
|
|
427
427
|
},
|
|
428
428
|
setHeaders: (next) => {
|
|
429
429
|
headers = next;
|
package/dist/worker-host.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ import type { PromiseMethods } from './client.js';
|
|
|
25
25
|
*/
|
|
26
26
|
import { type PresenceErrorCode, type WakeReason } from '@syncular/core';
|
|
27
27
|
import type { BlobRef, CachedBlob } from './blob.js';
|
|
28
|
-
import type { ConflictRecord, CurrentBaseProof, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, RejectionRecord, SecurityLifecycle, SnapshotRead, SnapshotReadRequest,
|
|
28
|
+
import type { ConflictRecord, CurrentBaseProof, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, RejectionRecord, SecurityLifecycle, SnapshotRead, SnapshotReadRequest, SyncClientConfig, SyncClientLimits, SyncSummary, SyncIdleOptions, SyncIdleResult, WindowState } from './client.js';
|
|
29
29
|
import type { SqlRow, SqlValue } from './database.js';
|
|
30
30
|
import type { DevtoolsRegistrar } from './devtools.js';
|
|
31
|
-
import { ClientDiagnosticsEmitter, type ClientDiagnosticsListener, type
|
|
31
|
+
import { ClientDiagnosticsEmitter, type ClientDiagnosticsListener, type ClientDiagnosticsSnapshot, type RealtimePolicy } from './diagnostics.js';
|
|
32
32
|
import type { EncryptionKeyringConfig } from './encryption.js';
|
|
33
33
|
import { ClientSyncError } from './errors.js';
|
|
34
34
|
import { ChangeEmitter, type ClientChangeListener, InvalidationEmitter, type InvalidationListener, type LocalRevision, type SyncStatusSnapshot } from './invalidation.js';
|
|
@@ -40,7 +40,8 @@ import type { OutboxCommit } from './outbox.js';
|
|
|
40
40
|
import type { CommitOutcome, CommitOutcomeQuery, ResolveCommitOutcomeInput } from './outcomes.js';
|
|
41
41
|
import { type PreviousVersionAudit, type PreviousVersionReadSpec, type PreviousVersionSnapshot } from './previous-version.js';
|
|
42
42
|
import type { ClientSchema } from './schema.js';
|
|
43
|
-
import type {
|
|
43
|
+
import type { UnitScopes } from '@syncular/core';
|
|
44
|
+
import type { UnitRecord } from './state.js';
|
|
44
45
|
import type { WindowBase } from './window.js';
|
|
45
46
|
import { type LocalAuthorityState, type SyncWorkerEvent, type WorkerApi, type WorkerDatabaseInit, type WorkerEndpoints, type WorkerErrorShape, type WorkerSecurityActivation } from './worker-protocol.js';
|
|
46
47
|
/** Classify startup without echoing a chunk URL or bundler text to UI/logs. */
|
|
@@ -239,8 +240,8 @@ export declare class SyncClientHandle implements PromiseMethods<WorkerApi> {
|
|
|
239
240
|
* worker still holds the database files.
|
|
240
241
|
*/
|
|
241
242
|
takeOver(): Promise<void>;
|
|
242
|
-
subscribe(
|
|
243
|
-
subscribeMany(
|
|
243
|
+
subscribe(scopes: UnitScopes): Promise<string>;
|
|
244
|
+
subscribeMany(units: readonly UnitScopes[]): Promise<string[]>;
|
|
244
245
|
securityLifecycle(): Promise<SecurityLifecycle>;
|
|
245
246
|
beginSecurityPreflight(): Promise<void>;
|
|
246
247
|
activateSecurity(options?: WorkerSecurityActivation): Promise<void>;
|
|
@@ -275,7 +276,7 @@ export declare class SyncClientHandle implements PromiseMethods<WorkerApi> {
|
|
|
275
276
|
snapshotRead<Row = SqlRow>(spec: SnapshotReadRequest): Promise<SnapshotRead<Row>>;
|
|
276
277
|
localRevision(): Promise<LocalRevision>;
|
|
277
278
|
statusSnapshot(): Promise<SyncStatusSnapshot>;
|
|
278
|
-
diagnosticsSnapshot(
|
|
279
|
+
diagnosticsSnapshot(): Promise<ClientDiagnosticsSnapshot>;
|
|
279
280
|
conflicts(): Promise<readonly ConflictRecord[]>;
|
|
280
281
|
rejections(): Promise<readonly RejectionRecord[]>;
|
|
281
282
|
commitOutcome(clientCommitId: string): Promise<CommitOutcome | undefined>;
|
|
@@ -283,8 +284,8 @@ export declare class SyncClientHandle implements PromiseMethods<WorkerApi> {
|
|
|
283
284
|
resolveCommitOutcome(input: ResolveCommitOutcomeInput): Promise<CommitOutcome>;
|
|
284
285
|
/** §7.4.5: true while a schema-bump reset + first re-bootstrap runs. */
|
|
285
286
|
pendingCommits(): Promise<OutboxCommit[]>;
|
|
286
|
-
|
|
287
|
-
|
|
287
|
+
units(): Promise<UnitRecord[]>;
|
|
288
|
+
unit(id: string): Promise<UnitRecord | undefined>;
|
|
288
289
|
connectRealtime(): Promise<void>;
|
|
289
290
|
disconnectRealtime(): Promise<void>;
|
|
290
291
|
/** §8.6: publish/clear a scope-keyed presence document. */
|
package/dist/worker-host.js
CHANGED
|
@@ -137,7 +137,7 @@ export class SyncClientHandle {
|
|
|
137
137
|
clientId: () => this.#clientId,
|
|
138
138
|
role: () => this.#role,
|
|
139
139
|
outbox: async () => (await this.statusSnapshot()).outbox,
|
|
140
|
-
|
|
140
|
+
units: () => this.units(),
|
|
141
141
|
conflicts: async () => (await this.conflicts()).length,
|
|
142
142
|
rejections: async () => (await this.rejections()).length,
|
|
143
143
|
syncNeeded: async () => (await this.statusSnapshot()).syncNeeded,
|
|
@@ -303,11 +303,11 @@ export class SyncClientHandle {
|
|
|
303
303
|
}
|
|
304
304
|
return this.#core.invoke(method, args);
|
|
305
305
|
}
|
|
306
|
-
subscribe(
|
|
307
|
-
return this.#call('subscribe', [
|
|
306
|
+
subscribe(scopes) {
|
|
307
|
+
return this.#call('subscribe', [scopes]);
|
|
308
308
|
}
|
|
309
|
-
subscribeMany(
|
|
310
|
-
return this.#call('subscribeMany', [
|
|
309
|
+
subscribeMany(units) {
|
|
310
|
+
return this.#call('subscribeMany', [units]);
|
|
311
311
|
}
|
|
312
312
|
securityLifecycle() {
|
|
313
313
|
return this.#call('securityLifecycle', []);
|
|
@@ -391,8 +391,8 @@ export class SyncClientHandle {
|
|
|
391
391
|
statusSnapshot() {
|
|
392
392
|
return this.#call('statusSnapshot', []);
|
|
393
393
|
}
|
|
394
|
-
async diagnosticsSnapshot(
|
|
395
|
-
const snapshot = await this.#call('diagnosticsSnapshot', [
|
|
394
|
+
async diagnosticsSnapshot() {
|
|
395
|
+
const snapshot = await this.#call('diagnosticsSnapshot', []);
|
|
396
396
|
return withClientDiagnosticsHost(snapshot, {
|
|
397
397
|
...snapshot.host,
|
|
398
398
|
kind: 'worker',
|
|
@@ -418,11 +418,11 @@ export class SyncClientHandle {
|
|
|
418
418
|
pendingCommits() {
|
|
419
419
|
return this.#call('pendingCommits', []);
|
|
420
420
|
}
|
|
421
|
-
|
|
422
|
-
return this.#call('
|
|
421
|
+
units() {
|
|
422
|
+
return this.#call('units', []);
|
|
423
423
|
}
|
|
424
|
-
|
|
425
|
-
return this.#call('
|
|
424
|
+
unit(id) {
|
|
425
|
+
return this.#call('unit', [id]);
|
|
426
426
|
}
|
|
427
427
|
connectRealtime() {
|
|
428
428
|
return this.#call('connectRealtime', []);
|
|
@@ -19,7 +19,7 @@ import type { SyncProgress } from './progress.js';
|
|
|
19
19
|
*/
|
|
20
20
|
import type { PresenceErrorCode, WakeReason } from '@syncular/core';
|
|
21
21
|
import type { BlobRef, CachedBlob } from './blob.js';
|
|
22
|
-
import type { ConflictRecord, CurrentBaseProof, ClientSnapshotMethods, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, SecurityLifecycle,
|
|
22
|
+
import type { ConflictRecord, CurrentBaseProof, ClientSnapshotMethods, MutationInput, PresencePeer, QueryReadSpec, QuerySnapshot, SecurityLifecycle, SyncClientConfig, SyncClientLimits, SyncSummary, SyncIdleOptions, SyncIdleResult, WindowState } from './client.js';
|
|
23
23
|
import type { SqlRow, SqlValue } from './database.js';
|
|
24
24
|
import type { ClientDiagnosticsSnapshot, RealtimePolicy } from './diagnostics.js';
|
|
25
25
|
import type { EncryptionKeyringConfig } from './encryption.js';
|
|
@@ -30,7 +30,8 @@ import type { OutboxCommit } from './outbox.js';
|
|
|
30
30
|
import type { CommitOutcome } from './outcomes.js';
|
|
31
31
|
import type { PreviousVersionAudit, PreviousVersionReadSpec, PreviousVersionSnapshot } from './previous-version.js';
|
|
32
32
|
import type { ClientSchema } from './schema.js';
|
|
33
|
-
import type {
|
|
33
|
+
import type { UnitScopes } from '@syncular/core';
|
|
34
|
+
import type { UnitRecord } from './state.js';
|
|
34
35
|
import type { WindowBase } from './window.js';
|
|
35
36
|
/** The handle exists but this tab lost the leader election. */
|
|
36
37
|
export declare const NOT_LEADER_CODE = "client.not_leader";
|
|
@@ -133,12 +134,12 @@ export interface WorkerApi extends Omit<ClientSnapshotMethods, 'querySnapshot'>
|
|
|
133
134
|
securityLifecycle(): SecurityLifecycle;
|
|
134
135
|
beginSecurityPreflight(): Promise<void>;
|
|
135
136
|
activateSecurity(options?: WorkerSecurityActivation): Promise<void>;
|
|
136
|
-
subscribe(
|
|
137
|
-
subscribeMany(
|
|
137
|
+
subscribe(scopes: UnitScopes): string;
|
|
138
|
+
subscribeMany(units: readonly UnitScopes[]): string[];
|
|
138
139
|
unsubscribe(id: string): void;
|
|
139
|
-
/** §4.8
|
|
140
|
+
/** §4.8 windows: set the windowed-in values of a base. */
|
|
140
141
|
setWindow(base: WindowBase, units: readonly string[]): Promise<void>;
|
|
141
|
-
/** §4.8 completeness oracle
|
|
142
|
+
/** §4.8 completeness oracle: the windowed-in values of a base. */
|
|
142
143
|
windowState(base: WindowBase): WindowState;
|
|
143
144
|
mutate(mutations: readonly MutationInput[]): string;
|
|
144
145
|
/** Partial-update convenience: read-merge-write one full-row upsert. */
|
|
@@ -167,8 +168,8 @@ export interface WorkerApi extends Omit<ClientSnapshotMethods, 'querySnapshot'>
|
|
|
167
168
|
querySnapshot(spec: QueryReadSpec): QuerySnapshot;
|
|
168
169
|
localRevision(): LocalRevision;
|
|
169
170
|
pendingCommits(): OutboxCommit[];
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
units(): UnitRecord[];
|
|
172
|
+
unit(id: string): UnitRecord | undefined;
|
|
172
173
|
connectRealtime(): Promise<void>;
|
|
173
174
|
disconnectRealtime(): void;
|
|
174
175
|
/** §8.6 presence: publish/clear a scope-keyed presence document. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.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",
|
|
@@ -113,11 +113,11 @@
|
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
115
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
116
|
-
"@syncular/core": "0.
|
|
116
|
+
"@syncular/core": "0.60.0"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@electric-sql/pglite": "^0.5.4",
|
|
120
|
-
"@syncular/server": "0.
|
|
120
|
+
"@syncular/server": "0.60.0",
|
|
121
121
|
"playwright": "1.63.0",
|
|
122
122
|
"vite": "8.3.4"
|
|
123
123
|
}
|