@syncular/client 0.86.0 → 0.90.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.
Files changed (45) hide show
  1. package/README.md +3 -1
  2. package/dist/blob.d.ts +0 -4
  3. package/dist/blob.js +7 -22
  4. package/dist/client.d.ts +12 -1
  5. package/dist/client.js +441 -422
  6. package/dist/diagnostics.d.ts +2 -4
  7. package/dist/diagnostics.js +3 -17
  8. package/dist/encryption.js +2 -21
  9. package/dist/errors.d.ts +2 -0
  10. package/dist/errors.js +4 -0
  11. package/dist/failed-overlay.js +2 -2
  12. package/dist/local-purge.d.ts +1 -0
  13. package/dist/local-purge.js +1 -1
  14. package/dist/local-rebootstrap-receipt.js +2 -2
  15. package/dist/local-rebootstrap.js +1 -1
  16. package/dist/native-bridge.d.ts +6 -2
  17. package/dist/native-bridge.js +24 -11
  18. package/dist/outcomes.d.ts +11 -0
  19. package/dist/outcomes.js +19 -16
  20. package/dist/previous-version.js +23 -35
  21. package/dist/schema.js +14 -13
  22. package/dist/state.d.ts +16 -4
  23. package/dist/state.js +83 -44
  24. package/dist/worker-core.js +7 -8
  25. package/dist/worker-host.d.ts +5 -2
  26. package/dist/worker-host.js +9 -0
  27. package/dist/worker-protocol.d.ts +2 -1
  28. package/package.json +3 -3
  29. package/src/blob.ts +7 -24
  30. package/src/client.ts +615 -501
  31. package/src/diagnostics.ts +3 -19
  32. package/src/encryption.ts +7 -25
  33. package/src/errors.ts +5 -0
  34. package/src/failed-overlay.ts +2 -6
  35. package/src/local-purge.ts +1 -1
  36. package/src/local-rebootstrap-receipt.ts +2 -5
  37. package/src/local-rebootstrap.ts +1 -2
  38. package/src/native-bridge.ts +35 -13
  39. package/src/outcomes.ts +34 -25
  40. package/src/previous-version.ts +31 -40
  41. package/src/schema.ts +13 -13
  42. package/src/state.ts +107 -64
  43. package/src/worker-core.ts +9 -16
  44. package/src/worker-host.ts +17 -1
  45. package/src/worker-protocol.ts +2 -0
package/README.md CHANGED
@@ -430,7 +430,9 @@ results, or app state alongside it. See SPEC §7.6.
430
430
  ## Durable commit outcomes
431
431
 
432
432
  `SyncClient` and every host bridge expose `commitOutcome(id)`,
433
- `commitOutcomes({ limit?, activeOnly? })`, and `resolveCommitOutcome(input)`.
433
+ `commitOutcomes({ limit?, activeOnly? })`, `commitDelivery(id)`, and
434
+ `resolveCommitOutcome(input)`. `commitDelivery` answers `pending`, `known` with
435
+ the outcome, or `unknown` when neither the outbox nor the journal holds the ID.
434
436
  Final `applied`, `cached`, `conflict`, and `rejected` results are journaled in
435
437
  the same SQLite transaction that drains their outbox commit. Conflict entries
436
438
  retain the losing operation plus `serverVersion`/`serverRow`; active failures
package/dist/blob.d.ts CHANGED
@@ -101,10 +101,6 @@ export declare function listPendingUploads(db: ClientDatabase): {
101
101
  }[];
102
102
  export declare function recordPendingUpload(db: ClientDatabase, blobId: string, nowMs: number, mediaType?: string): void;
103
103
  export declare function clearPendingUpload(db: ClientDatabase, blobId: string): void;
104
- /**
105
- * All `blob_ref` column names per table.
106
- */
107
- export declare function blobRefColumnsBySchema(schema: CompiledClientSchema): Map<string, string[]>;
108
104
  export declare function schemaHasBlobs(schema: CompiledClientSchema): boolean;
109
105
  export declare function deleteUnreferencedCachedBlobs(db: ClientDatabase, schema: CompiledClientSchema): void;
110
106
  export type { BlobRef };
package/dist/blob.js CHANGED
@@ -7,18 +7,15 @@ export const BLOB_COMMIT_REFS = '_syncular_blob_commit_refs';
7
7
  * A small upload row queues each staged body for transfer before push.
8
8
  */
9
9
  import { parseBlobRef, serializeBlobRef } from '@syncular/core';
10
- import { ClientSyncError } from './errors.js';
11
- import { quoteIdent, tableExists } from './schema.js';
10
+ import { ClientSyncError, localStateCorrupt } from './errors.js';
11
+ import { bytesToHex, quoteIdent, tableExists } from './schema.js';
12
12
  /** `"sha256:" + hex` of the bytes — the content address (§5.9.1). */
13
13
  export async function computeBlobId(bytes) {
14
14
  const input = bytes.buffer instanceof ArrayBuffer
15
15
  ? new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)
16
16
  : bytes.slice();
17
17
  const digest = await crypto.subtle.digest('SHA-256', input);
18
- const hex = [...new Uint8Array(digest)]
19
- .map((b) => b.toString(16).padStart(2, '0'))
20
- .join('');
21
- return `sha256:${hex}`;
18
+ return `sha256:${bytesToHex(new Uint8Array(digest))}`;
22
19
  }
23
20
  export function ensureBlobSchema(db) {
24
21
  if (tableExists(db, '_syncular_blobs')) {
@@ -26,15 +23,7 @@ export function ensureBlobSchema(db) {
26
23
  .query('PRAGMA table_info(_syncular_blobs)')
27
24
  .map((row) => row.name)
28
25
  .sort();
29
- const expected = [
30
- 'blob_id',
31
- 'byte_length',
32
- 'bytes',
33
- 'created_at_ms',
34
- 'media_type',
35
- ].sort();
36
- if (columns.length !== expected.length ||
37
- columns.some((column, index) => column !== expected[index])) {
26
+ if (columns.join() !== 'blob_id,byte_length,bytes,created_at_ms,media_type') {
38
27
  throw new ClientSyncError('sync.schema_mismatch', 'Local blob schema is incompatible');
39
28
  }
40
29
  }
@@ -90,7 +79,7 @@ export function listPendingUploads(db) {
90
79
  .map((row) => {
91
80
  if (typeof row.blob_id !== 'string' ||
92
81
  (row.media_type !== null && typeof row.media_type !== 'string')) {
93
- throw new ClientSyncError('sync.local_corrupt', 'Pending blob upload metadata is invalid');
82
+ throw localStateCorrupt('Pending blob upload metadata is invalid');
94
83
  }
95
84
  return {
96
85
  blobId: row.blob_id,
@@ -107,7 +96,7 @@ export function clearPendingUpload(db, blobId) {
107
96
  /**
108
97
  * All `blob_ref` column names per table.
109
98
  */
110
- export function blobRefColumnsBySchema(schema) {
99
+ function blobRefColumnsBySchema(schema) {
111
100
  const out = new Map();
112
101
  for (const table of schema.tables.values()) {
113
102
  const cols = table.columns
@@ -119,11 +108,7 @@ export function blobRefColumnsBySchema(schema) {
119
108
  return out;
120
109
  }
121
110
  export function schemaHasBlobs(schema) {
122
- for (const table of schema.tables.values()) {
123
- if (table.columns.some((c) => c.type === 'blob_ref'))
124
- return true;
125
- }
126
- return false;
111
+ return blobRefColumnsBySchema(schema).size > 0;
127
112
  }
128
113
  /** The cached bodies no upload, pending commit, or visible row references. */
129
114
  function unreferencedBlobsSql(schema) {
package/dist/client.d.ts CHANGED
@@ -39,6 +39,12 @@ export type MutationInput = {
39
39
  readonly baseVersion?: number;
40
40
  };
41
41
  export type { CommitOperationOutcome, CommitOutcome, CommitOutcomeQuery, RetainedCommitRow, ConflictRecord, RejectionRecord, ResolveCommitOutcomeInput, } from './outcomes.js';
42
+ /** §7.2.2: without `replacement`, the decision keeps the local intent. */
43
+ export interface ReplaceCommitOutcomeInput {
44
+ readonly clientCommitId: string;
45
+ readonly sequence: number;
46
+ readonly replacement?: readonly MutationInput[] | undefined;
47
+ }
42
48
  export interface SchemaFloor {
43
49
  readonly requiredSchemaVersion?: number;
44
50
  readonly latestSchemaVersion?: number;
@@ -409,7 +415,7 @@ export interface SnapshotRead<Row = SqlRow> {
409
415
  */
410
416
  export declare function windowComplete(state: WindowState, unit: string): boolean;
411
417
  /** Canonical client reads, shared by synchronous cores and promise hosts. */
412
- export type ClientSnapshotMethods = Pick<SyncClient, 'querySnapshot' | 'snapshotRead' | 'statusSnapshot' | 'diagnosticsSnapshot' | 'conflicts' | 'rejections' | 'commitOutcome' | 'commitOutcomes' | 'resolveCommitOutcome'>;
418
+ export type ClientSnapshotMethods = Pick<SyncClient, 'querySnapshot' | 'snapshotRead' | 'statusSnapshot' | 'diagnosticsSnapshot' | 'conflicts' | 'rejections' | 'commitOutcome' | 'commitOutcomes' | 'resolveCommitOutcome' | 'commitDelivery'>;
413
419
  /** Project a method contract across an asynchronous host boundary. */
414
420
  export type PromiseMethods<Methods> = {
415
421
  [Key in keyof Methods]: Methods[Key] extends (...args: infer Args) => infer Result ? (...args: Args) => Promise<Awaited<Result>> : never;
@@ -574,6 +580,11 @@ export declare class SyncClient {
574
580
  * dismissed. The transition is one-way and survives restart.
575
581
  */
576
582
  resolveCommitOutcome(input: ResolveCommitOutcomeInput): CommitOutcome;
583
+ /**
584
+ * §7.2.2: record a decision against an active failure as a held
585
+ * replacement commit, written once a later drive proves its base.
586
+ */
587
+ replaceCommitOutcome(input: ReplaceCommitOutcomeInput): string;
577
588
  /** True when syncing is stopped pending a client upgrade. */
578
589
  get stopped(): boolean;
579
590
  /**