@syncular/client 0.63.0 → 0.65.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 +1 -0
- package/dist/client.js +2 -4
- package/dist/dev-profiler.d.ts +127 -0
- package/dist/dev-profiler.js +338 -0
- package/dist/devtools.d.ts +5 -0
- package/dist/devtools.js +13 -10
- package/dist/encryption.d.ts +3 -2
- package/dist/encryption.js +4 -3
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +35 -0
- package/dist/multi-tab.js +2 -15
- package/dist/worker-core.d.ts +4 -1
- package/dist/worker-core.js +3 -20
- package/package.json +11 -3
- package/src/client.ts +2 -3
- package/src/dev-profiler.ts +525 -0
- package/src/devtools.ts +17 -14
- package/src/encryption.ts +9 -3
- package/src/errors.ts +40 -0
- package/src/multi-tab.ts +2 -17
- package/src/worker-core.ts +8 -23
package/src/encryption.ts
CHANGED
|
@@ -211,8 +211,9 @@ export async function encryptRowValues<T extends RowValue | undefined>(
|
|
|
211
211
|
* (returns a new array). Called at the apply seam (§4.5 COMMIT, §5.6 rows
|
|
212
212
|
* segment) AFTER the row codec decodes: an encrypted column's ciphertext
|
|
213
213
|
* envelope `bytes` becomes its plaintext declared-type value for the local
|
|
214
|
-
* mirror. A
|
|
215
|
-
*
|
|
214
|
+
* mirror. A missing key throws {@link DecryptError} coded
|
|
215
|
+
* `client.encryption_key_missing` with the table and key id in `details`; a
|
|
216
|
+
* wrong key or malformed envelope throws `client.decrypt_failed` (§5.11).
|
|
216
217
|
*/
|
|
217
218
|
export async function decryptRowValues(
|
|
218
219
|
config: EncryptionConfig | undefined,
|
|
@@ -235,7 +236,12 @@ export async function decryptRowValues(
|
|
|
235
236
|
throw new DecryptError('encrypted columns need an encryption config');
|
|
236
237
|
}
|
|
237
238
|
out[i] = deserializeGuard(
|
|
238
|
-
await decryptValue(
|
|
239
|
+
await decryptValue(
|
|
240
|
+
declaredTypeOf(column),
|
|
241
|
+
value,
|
|
242
|
+
config.keyProvider,
|
|
243
|
+
table.name,
|
|
244
|
+
),
|
|
239
245
|
);
|
|
240
246
|
}
|
|
241
247
|
return out;
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { DecryptError } from '@syncular/core';
|
|
1
2
|
import type { RealtimeState } from './diagnostics';
|
|
3
|
+
import { WORKER_FAILED_CODE, type WorkerErrorShape } from './worker-protocol';
|
|
2
4
|
|
|
3
5
|
/** A persistent local store is temporarily owned by another live engine. */
|
|
4
6
|
export const STORAGE_BUSY_CODE = 'client.storage_busy';
|
|
@@ -235,3 +237,41 @@ export function classifySqliteFailure(error: unknown): {
|
|
|
235
237
|
Object.defineProperty(failure, 'cause', { value: error });
|
|
236
238
|
return { sqliteCode, code, error: failure };
|
|
237
239
|
}
|
|
240
|
+
|
|
241
|
+
/** A stable error identity: lowercase dotted segments, at most 96 chars. */
|
|
242
|
+
export function isStableCode(code: string): boolean {
|
|
243
|
+
return code.length <= 96 && /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+$/.test(code);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The structured-clone form of a failure that crosses a Worker or tab
|
|
248
|
+
* boundary. Any error carrying a stable `code` (a `ClientSyncError` or a
|
|
249
|
+
* `@syncular/core` error such as `DecryptError`) keeps its
|
|
250
|
+
* code, `retryable` and details (SPEC §5.11); only an uncoded failure
|
|
251
|
+
* becomes `client.worker_failed`.
|
|
252
|
+
*/
|
|
253
|
+
export function toErrorShape(caught: unknown): WorkerErrorShape {
|
|
254
|
+
const error = classifySqliteFailure(caught).error;
|
|
255
|
+
if (
|
|
256
|
+
error instanceof Error &&
|
|
257
|
+
'code' in error &&
|
|
258
|
+
typeof error.code === 'string' &&
|
|
259
|
+
isStableCode(error.code)
|
|
260
|
+
) {
|
|
261
|
+
const details =
|
|
262
|
+
error instanceof ClientSyncError || error instanceof DecryptError
|
|
263
|
+
? error.details
|
|
264
|
+
: undefined;
|
|
265
|
+
return {
|
|
266
|
+
code: error.code,
|
|
267
|
+
message: error.message,
|
|
268
|
+
retryable: 'retryable' in error && error.retryable === true,
|
|
269
|
+
...(details !== undefined ? { details } : {}),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
code: WORKER_FAILED_CODE,
|
|
274
|
+
message: error instanceof Error ? error.message : String(error),
|
|
275
|
+
retryable: false,
|
|
276
|
+
};
|
|
277
|
+
}
|
package/src/multi-tab.ts
CHANGED
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
* state waits on that lock for each tab that called it; the grant means the
|
|
71
71
|
* tab is gone.
|
|
72
72
|
*/
|
|
73
|
-
import { ClientSyncError } from './errors';
|
|
73
|
+
import { ClientSyncError, toErrorShape } from './errors';
|
|
74
74
|
import {
|
|
75
75
|
type LeaderLease,
|
|
76
76
|
type LeaderLock,
|
|
@@ -410,22 +410,7 @@ export class LeaderBridge<E = SyncWorkerEvent> {
|
|
|
410
410
|
},
|
|
411
411
|
(error: unknown) => {
|
|
412
412
|
if (this.#closed) return;
|
|
413
|
-
const shape =
|
|
414
|
-
error instanceof ClientSyncError
|
|
415
|
-
? {
|
|
416
|
-
code: error.code,
|
|
417
|
-
message: error.message,
|
|
418
|
-
retryable: error.retryable,
|
|
419
|
-
...(error.details !== undefined
|
|
420
|
-
? { details: error.details }
|
|
421
|
-
: {}),
|
|
422
|
-
}
|
|
423
|
-
: {
|
|
424
|
-
code: WORKER_FAILED_CODE,
|
|
425
|
-
message:
|
|
426
|
-
error instanceof Error ? error.message : 'unknown error',
|
|
427
|
-
retryable: false,
|
|
428
|
-
};
|
|
413
|
+
const shape = toErrorShape(error);
|
|
429
414
|
this.#channel.postMessage({
|
|
430
415
|
t: 'res',
|
|
431
416
|
epoch: this.#epoch,
|
package/src/worker-core.ts
CHANGED
|
@@ -22,10 +22,10 @@ import {
|
|
|
22
22
|
} from './diagnostics';
|
|
23
23
|
import { encryptionConfigFromKeyring } from './encryption';
|
|
24
24
|
import {
|
|
25
|
-
classifySqliteFailure,
|
|
26
25
|
ClientSyncError,
|
|
27
26
|
invalidRequest,
|
|
28
27
|
STORAGE_BUSY_CODE,
|
|
28
|
+
toErrorShape,
|
|
29
29
|
} from './errors';
|
|
30
30
|
import {
|
|
31
31
|
httpBlobTransport,
|
|
@@ -49,7 +49,6 @@ import {
|
|
|
49
49
|
WORKER_METHOD_UNAVAILABLE_CODE,
|
|
50
50
|
type WorkerApi,
|
|
51
51
|
type WorkerCallMessage,
|
|
52
|
-
type WorkerErrorShape,
|
|
53
52
|
type WorkerInitConfig,
|
|
54
53
|
type WorkerInitResult,
|
|
55
54
|
type WorkerMethod,
|
|
@@ -73,7 +72,11 @@ export interface SyncWorkerOverrides {
|
|
|
73
72
|
callback: () => void,
|
|
74
73
|
delayMs: number,
|
|
75
74
|
) => () => void;
|
|
76
|
-
|
|
75
|
+
/** `http` reads the current host auth set, as the default transport does. */
|
|
76
|
+
readonly createTransport?: (
|
|
77
|
+
config: WorkerInitConfig,
|
|
78
|
+
http: { readonly headers: () => Readonly<Record<string, string>> },
|
|
79
|
+
) => SyncTransport;
|
|
77
80
|
readonly createSegments?: (
|
|
78
81
|
config: WorkerInitConfig,
|
|
79
82
|
) => SegmentDownloader | undefined;
|
|
@@ -146,23 +149,6 @@ interface WorkerScope {
|
|
|
146
149
|
): void;
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
function toErrorShape(caught: unknown): WorkerErrorShape {
|
|
150
|
-
const error = classifySqliteFailure(caught).error;
|
|
151
|
-
if (error instanceof ClientSyncError) {
|
|
152
|
-
return {
|
|
153
|
-
code: error.code,
|
|
154
|
-
message: error.message,
|
|
155
|
-
retryable: error.retryable,
|
|
156
|
-
...(error.details !== undefined ? { details: error.details } : {}),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
code: WORKER_FAILED_CODE,
|
|
161
|
-
message: error instanceof Error ? error.message : String(error),
|
|
162
|
-
retryable: false,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
152
|
/**
|
|
167
153
|
* ArrayBuffers safe to transfer out of a query result: whole-buffer
|
|
168
154
|
* views only (a view into a larger/pooled buffer is cloned instead —
|
|
@@ -416,7 +402,7 @@ export function startSyncWorkerCore(
|
|
|
416
402
|
}
|
|
417
403
|
const remote =
|
|
418
404
|
overrides.createTransport !== undefined
|
|
419
|
-
? overrides.createTransport(config)
|
|
405
|
+
? overrides.createTransport(config, http)
|
|
420
406
|
: httpSyncTransport(config.endpoints.syncUrl, http);
|
|
421
407
|
const remoteSegments =
|
|
422
408
|
overrides.createSegments !== undefined
|
|
@@ -720,8 +706,7 @@ async function defaultOpenDatabase(
|
|
|
720
706
|
if (config.database.mode !== 'persistent') {
|
|
721
707
|
throw new ClientSyncError(
|
|
722
708
|
WORKER_FAILED_CODE,
|
|
723
|
-
"database mode 'custom' requires
|
|
724
|
-
'worker bootstrap (startSyncWorker({ openDatabase }))',
|
|
709
|
+
"database mode 'custom' requires startSyncWorker({ openDatabase })",
|
|
725
710
|
);
|
|
726
711
|
}
|
|
727
712
|
return openPersistentWasmDatabase(config.database.name, {
|