@syncular/client 0.60.0 → 0.61.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/dist/http.js +9 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/native-bridge.d.ts +9 -2
- package/dist/native-bridge.js +13 -0
- package/dist/worker-host.js +12 -3
- package/package.json +3 -3
- package/src/http.ts +9 -1
- package/src/index.ts +4 -0
- package/src/native-bridge.ts +24 -1
- package/src/worker-host.ts +14 -3
package/dist/http.js
CHANGED
|
@@ -182,7 +182,15 @@ async function readBody(response, onProgress, maxBytes) {
|
|
|
182
182
|
}
|
|
183
183
|
if (received !== reported)
|
|
184
184
|
onProgress?.(received);
|
|
185
|
-
|
|
185
|
+
// One allocation of the body's size. A Blob of the chunks and its
|
|
186
|
+
// arrayBuffer() kept one more full copy resident until garbage collection.
|
|
187
|
+
const bytes = new Uint8Array(received);
|
|
188
|
+
let offset = 0;
|
|
189
|
+
for (const chunk of chunks) {
|
|
190
|
+
bytes.set(chunk, offset);
|
|
191
|
+
offset += chunk.byteLength;
|
|
192
|
+
}
|
|
193
|
+
return bytes;
|
|
186
194
|
}
|
|
187
195
|
export function httpSegmentDownloader(segmentsBaseUrl, options) {
|
|
188
196
|
const doFetch = options?.fetch ?? fetch;
|
package/dist/index.d.ts
CHANGED
|
@@ -42,4 +42,5 @@ export * from './transport.js';
|
|
|
42
42
|
export * from './window.js';
|
|
43
43
|
export * from './worker-host.js';
|
|
44
44
|
export * from './worker-protocol.js';
|
|
45
|
+
export { unitId, type UnitScopes } from '@syncular/core';
|
|
45
46
|
export { ProgressEmitter, type SyncProgress, type SyncProgressListener, } from './progress.js';
|
package/dist/index.js
CHANGED
|
@@ -35,4 +35,7 @@ export * from './transport.js';
|
|
|
35
35
|
export * from './window.js';
|
|
36
36
|
export * from './worker-host.js';
|
|
37
37
|
export * from './worker-protocol.js';
|
|
38
|
+
// §4.1: the unit id of a scope map, for `unit(id)` and `unsubscribe(id)`
|
|
39
|
+
// before (or without) a `subscribe`.
|
|
40
|
+
export { unitId } from '@syncular/core';
|
|
38
41
|
export { ProgressEmitter, } from './progress.js';
|
package/dist/native-bridge.d.ts
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* `{$bigint: decimal}`, the convention of the Rust command router. The browser
|
|
12
12
|
* client and worker entries never import this module.
|
|
13
13
|
*/
|
|
14
|
-
import { type ClientSnapshotMethods, type CurrentBaseProof, type MutationInput, type PresencePeer, type PromiseMethods, type QueryReadSpec, type QuerySnapshot, type SecurityLifecycle, type SnapshotRead, type SnapshotReadRequest, type SyncClientConfig, type WindowState } from './client.js';
|
|
14
|
+
import { type ClientSnapshotMethods, type CurrentBaseProof, type MutationInput, type PresencePeer, type PromiseMethods, type QueryReadSpec, type QuerySnapshot, type SecurityLifecycle, type SnapshotRead, type SnapshotReadRequest, type SyncClient, type SyncClientConfig, type UnitCatchup, type WindowState } from './client.js';
|
|
15
15
|
import type { SqlRow, SqlValue } from './database.js';
|
|
16
16
|
import type { PresenceErrorCode, UnitScopes } from '@syncular/core';
|
|
17
|
+
export { unitId, type UnitScopes } from '@syncular/core';
|
|
17
18
|
import { type ClientDiagnosticsListener, type ClientDiagnosticsSnapshot } from './diagnostics.js';
|
|
18
19
|
import type { EncryptionKeyringConfig } from './encryption.js';
|
|
19
20
|
import type { ClientChangeListener, InvalidationListener, SyncStatusSnapshot } from './invalidation.js';
|
|
@@ -22,6 +23,7 @@ import { type LocalDataRebootstrapInput, type LocalDataRebootstrapResult } from
|
|
|
22
23
|
import type { CommitOutcome, CommitOutcomeQuery, ConflictRecord, RejectionRecord, ResolveCommitOutcomeInput } from './outcomes.js';
|
|
23
24
|
import { type PreviousVersionAudit, type PreviousVersionReadSpec, type PreviousVersionSnapshot } from './previous-version.js';
|
|
24
25
|
import { type SyncProgress, type SyncProgressListener } from './progress.js';
|
|
26
|
+
import type { UnitRecord } from './state.js';
|
|
25
27
|
import type { WindowBase } from './window.js';
|
|
26
28
|
/** A driver-protocol reply: `{result}` on success or `{error}` on failure. */
|
|
27
29
|
export interface NativeReply {
|
|
@@ -87,7 +89,7 @@ export declare function nativeCreateParams(config: NativeCreateConfig, ErrorType
|
|
|
87
89
|
* returns a promise from one host round trip; React hooks accept the
|
|
88
90
|
* canonical snapshot interface directly.
|
|
89
91
|
*/
|
|
90
|
-
export declare abstract class NativeBridgeClient implements PromiseMethods<ClientSnapshotMethods
|
|
92
|
+
export declare abstract class NativeBridgeClient implements PromiseMethods<ClientSnapshotMethods & Pick<SyncClient, 'unit' | 'units' | 'unitCatchup'>> {
|
|
91
93
|
#private;
|
|
92
94
|
/**
|
|
93
95
|
* `release` detaches the host event listener; the bridge calls it once,
|
|
@@ -202,6 +204,11 @@ export declare abstract class NativeBridgeClient implements PromiseMethods<Clien
|
|
|
202
204
|
/** Register several units in one local transaction; returns their ids. */
|
|
203
205
|
subscribeMany(units: readonly UnitScopes[]): Promise<string[]>;
|
|
204
206
|
unsubscribe(id: string): Promise<void>;
|
|
207
|
+
/** Every unit in registration order (§4.1), including revoked and failed. */
|
|
208
|
+
units(): Promise<UnitRecord[]>;
|
|
209
|
+
unit(id: string): Promise<UnitRecord | undefined>;
|
|
210
|
+
/** §7.5: one unit's persisted catch-up state (never the owner cache). */
|
|
211
|
+
unitCatchup(id: string): Promise<UnitCatchup>;
|
|
205
212
|
setWindow(base: WindowBase, units: readonly string[]): Promise<void>;
|
|
206
213
|
windowState(base: WindowBase): Promise<WindowState>;
|
|
207
214
|
sync(): Promise<unknown>;
|
package/dist/native-bridge.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* client and worker entries never import this module.
|
|
13
13
|
*/
|
|
14
14
|
import { SECURITY_PREFLIGHT_REQUIRED_CODE, } from './client.js';
|
|
15
|
+
export { unitId } from '@syncular/core';
|
|
15
16
|
import { CLIENT_DIAGNOSTICS_VERSION, withClientDiagnosticsHost, } from './diagnostics.js';
|
|
16
17
|
import { decodeLocalDataRebootstrapResult, } from './local-rebootstrap.js';
|
|
17
18
|
import { decodePreviousVersionAuditResult, decodePreviousVersionDiscardResult, decodePreviousVersionSnapshot, } from './previous-version.js';
|
|
@@ -667,6 +668,18 @@ export class NativeBridgeClient {
|
|
|
667
668
|
async unsubscribe(id) {
|
|
668
669
|
await this.command('unsubscribe', { id });
|
|
669
670
|
}
|
|
671
|
+
/** Every unit in registration order (§4.1), including revoked and failed. */
|
|
672
|
+
async units() {
|
|
673
|
+
return (await this.command('units', {})).units;
|
|
674
|
+
}
|
|
675
|
+
async unit(id) {
|
|
676
|
+
return ((await this.command('unit', { id }))
|
|
677
|
+
.unit ?? undefined);
|
|
678
|
+
}
|
|
679
|
+
/** §7.5: one unit's persisted catch-up state (never the owner cache). */
|
|
680
|
+
async unitCatchup(id) {
|
|
681
|
+
return (await this.snapshotRead({ statements: [], units: [id] })).units[0];
|
|
682
|
+
}
|
|
670
683
|
async setWindow(base, units) {
|
|
671
684
|
await this.command('setWindow', { base, units });
|
|
672
685
|
}
|
package/dist/worker-host.js
CHANGED
|
@@ -597,9 +597,18 @@ async function startWorkerCore(options) {
|
|
|
597
597
|
config: initConfig,
|
|
598
598
|
});
|
|
599
599
|
});
|
|
600
|
-
// A config callback is a consumer from the first round.
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
// A config callback is a consumer from the first round. Under security
|
|
601
|
+
// preflight the core refuses the snapshot after the pull registered the
|
|
602
|
+
// worker as a push source, and activateSecurity() emits the first one.
|
|
603
|
+
if (config.onDiagnostics !== undefined) {
|
|
604
|
+
await invoke('diagnosticsSnapshot', []).catch((error) => {
|
|
605
|
+
if (config.securityPreflight !== true ||
|
|
606
|
+
!(error instanceof ClientSyncError) ||
|
|
607
|
+
error.code !== 'client.security_preflight_required') {
|
|
608
|
+
throw error;
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
}
|
|
603
612
|
return {
|
|
604
613
|
clientId: initResult.clientId,
|
|
605
614
|
invoke,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.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.61.0"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@electric-sql/pglite": "^0.5.4",
|
|
120
|
-
"@syncular/server": "0.
|
|
120
|
+
"@syncular/server": "0.61.0",
|
|
121
121
|
"playwright": "1.63.0",
|
|
122
122
|
"vite": "8.3.4"
|
|
123
123
|
}
|
package/src/http.ts
CHANGED
|
@@ -273,7 +273,15 @@ async function readBody(
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
if (received !== reported) onProgress?.(received);
|
|
276
|
-
|
|
276
|
+
// One allocation of the body's size. A Blob of the chunks and its
|
|
277
|
+
// arrayBuffer() kept one more full copy resident until garbage collection.
|
|
278
|
+
const bytes = new Uint8Array(received);
|
|
279
|
+
let offset = 0;
|
|
280
|
+
for (const chunk of chunks) {
|
|
281
|
+
bytes.set(chunk, offset);
|
|
282
|
+
offset += chunk.byteLength;
|
|
283
|
+
}
|
|
284
|
+
return bytes;
|
|
277
285
|
}
|
|
278
286
|
|
|
279
287
|
export function httpSegmentDownloader(
|
package/src/index.ts
CHANGED
|
@@ -59,6 +59,10 @@ export * from './window';
|
|
|
59
59
|
export * from './worker-host';
|
|
60
60
|
export * from './worker-protocol';
|
|
61
61
|
|
|
62
|
+
// §4.1: the unit id of a scope map, for `unit(id)` and `unsubscribe(id)`
|
|
63
|
+
// before (or without) a `subscribe`.
|
|
64
|
+
export { unitId, type UnitScopes } from '@syncular/core';
|
|
65
|
+
|
|
62
66
|
export {
|
|
63
67
|
ProgressEmitter,
|
|
64
68
|
type SyncProgress,
|
package/src/native-bridge.ts
CHANGED
|
@@ -23,11 +23,14 @@ import {
|
|
|
23
23
|
type SecurityLifecycle,
|
|
24
24
|
type SnapshotRead,
|
|
25
25
|
type SnapshotReadRequest,
|
|
26
|
+
type SyncClient,
|
|
26
27
|
type SyncClientConfig,
|
|
28
|
+
type UnitCatchup,
|
|
27
29
|
type WindowState,
|
|
28
30
|
} from './client';
|
|
29
31
|
import type { SqlRow, SqlValue } from './database';
|
|
30
32
|
import type { PresenceErrorCode, UnitScopes } from '@syncular/core';
|
|
33
|
+
export { unitId, type UnitScopes } from '@syncular/core';
|
|
31
34
|
import {
|
|
32
35
|
CLIENT_DIAGNOSTICS_VERSION,
|
|
33
36
|
type ClientDiagnosticsListener,
|
|
@@ -68,6 +71,7 @@ import {
|
|
|
68
71
|
type SyncProgress,
|
|
69
72
|
type SyncProgressListener,
|
|
70
73
|
} from './progress';
|
|
74
|
+
import type { UnitRecord } from './state';
|
|
71
75
|
import type { WindowBase } from './window';
|
|
72
76
|
|
|
73
77
|
/** A driver-protocol reply: `{result}` on success or `{error}` on failure. */
|
|
@@ -289,7 +293,9 @@ type OutcomeRowValue = ConflictRecord['serverRow'][string];
|
|
|
289
293
|
* returns a promise from one host round trip; React hooks accept the
|
|
290
294
|
* canonical snapshot interface directly.
|
|
291
295
|
*/
|
|
292
|
-
export abstract class NativeBridgeClient implements PromiseMethods<
|
|
296
|
+
export abstract class NativeBridgeClient implements PromiseMethods<
|
|
297
|
+
ClientSnapshotMethods & Pick<SyncClient, 'unit' | 'units' | 'unitCatchup'>
|
|
298
|
+
> {
|
|
293
299
|
readonly #kind: 'tauri' | 'react-native';
|
|
294
300
|
readonly #Error: typeof NativeSyncError;
|
|
295
301
|
readonly #release: () => void;
|
|
@@ -1008,6 +1014,23 @@ export abstract class NativeBridgeClient implements PromiseMethods<ClientSnapsho
|
|
|
1008
1014
|
await this.command('unsubscribe', { id });
|
|
1009
1015
|
}
|
|
1010
1016
|
|
|
1017
|
+
/** Every unit in registration order (§4.1), including revoked and failed. */
|
|
1018
|
+
async units(): Promise<UnitRecord[]> {
|
|
1019
|
+
return ((await this.command('units', {})) as { units: UnitRecord[] }).units;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
async unit(id: string): Promise<UnitRecord | undefined> {
|
|
1023
|
+
return (
|
|
1024
|
+
((await this.command('unit', { id })) as { unit: UnitRecord | null })
|
|
1025
|
+
.unit ?? undefined
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/** §7.5: one unit's persisted catch-up state (never the owner cache). */
|
|
1030
|
+
async unitCatchup(id: string): Promise<UnitCatchup> {
|
|
1031
|
+
return (await this.snapshotRead({ statements: [], units: [id] })).units[0]!;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1011
1034
|
async setWindow(base: WindowBase, units: readonly string[]): Promise<void> {
|
|
1012
1035
|
await this.command('setWindow', { base, units });
|
|
1013
1036
|
}
|
package/src/worker-host.ts
CHANGED
|
@@ -998,9 +998,20 @@ async function startWorkerCore(options: {
|
|
|
998
998
|
} as MainToWorkerMessage);
|
|
999
999
|
},
|
|
1000
1000
|
);
|
|
1001
|
-
// A config callback is a consumer from the first round.
|
|
1002
|
-
|
|
1003
|
-
|
|
1001
|
+
// A config callback is a consumer from the first round. Under security
|
|
1002
|
+
// preflight the core refuses the snapshot after the pull registered the
|
|
1003
|
+
// worker as a push source, and activateSecurity() emits the first one.
|
|
1004
|
+
if (config.onDiagnostics !== undefined) {
|
|
1005
|
+
await invoke('diagnosticsSnapshot', []).catch((error: unknown) => {
|
|
1006
|
+
if (
|
|
1007
|
+
config.securityPreflight !== true ||
|
|
1008
|
+
!(error instanceof ClientSyncError) ||
|
|
1009
|
+
error.code !== 'client.security_preflight_required'
|
|
1010
|
+
) {
|
|
1011
|
+
throw error;
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1004
1015
|
return {
|
|
1005
1016
|
clientId: initResult.clientId,
|
|
1006
1017
|
invoke,
|