@syncular/client 0.91.0 → 0.92.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.
@@ -8,7 +8,7 @@
8
8
  * bridge between the positional `RowValue[]` and the `@syncular/core` §5.11
9
9
  * envelope primitives.
10
10
  */
11
- import { DecryptError, decryptValue, EncryptError, encryptValue, KEY_LENGTH, } from '@syncular/core';
11
+ import { DecryptError, decryptValue, EncryptError, encryptValue, KEY_LENGTH, definedObject, } from '@syncular/core';
12
12
  import { invalidRequest } from './errors.js';
13
13
  /**
14
14
  * Convert a portable keyring into the direct-client encryption contract.
@@ -27,12 +27,10 @@ export function encryptionConfigFromKeyring(keyring) {
27
27
  // a prototype-chain name like "constructor" must read as a missing key
28
28
  // and take the clean DecryptError path.
29
29
  keyProvider: (keyId) => Object.hasOwn(keyring.keys, keyId) ? keyring.keys[keyId] : undefined,
30
- ...(keyring.keyIdColumns !== undefined
31
- ? { keyIdColumns: keyring.keyIdColumns }
32
- : {}),
33
- ...(keyring.missingKey !== undefined
34
- ? { missingKey: keyring.missingKey }
35
- : {}),
30
+ ...definedObject({
31
+ keyIdColumns: keyring.keyIdColumns,
32
+ missingKey: keyring.missingKey,
33
+ }),
36
34
  };
37
35
  }
38
36
  function encryptionKeyId(config, table, rowId, values) {
package/dist/errors.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DecryptError } from '@syncular/core';
1
+ import { DecryptError, definedObject } from '@syncular/core';
2
2
  import { WORKER_FAILED_CODE } from './worker-protocol.js';
3
3
  /** A persistent local store is temporarily owned by another live engine. */
4
4
  export const STORAGE_BUSY_CODE = 'client.storage_busy';
@@ -192,12 +192,12 @@ export function toErrorShape(caught) {
192
192
  const details = error instanceof ClientSyncError || error instanceof DecryptError
193
193
  ? error.details
194
194
  : undefined;
195
- return {
195
+ return definedObject({
196
196
  code: error.code,
197
197
  message: error.message,
198
198
  retryable: 'retryable' in error && error.retryable === true,
199
- ...(details !== undefined ? { details } : {}),
200
- };
199
+ details,
200
+ });
201
201
  }
202
202
  return {
203
203
  code: WORKER_FAILED_CODE,
package/dist/http.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { definedObject } from '@syncular/core';
1
2
  import { SSP2_CONTENT_TYPE } from './content-type.js';
2
3
  import { ClientSyncError, transportFailed } from './errors.js';
3
4
  import { hexToBytes } from './schema.js';
@@ -19,7 +20,7 @@ async function transfer(message, operation, httpStatus) {
19
20
  : 'unknown';
20
21
  throw transportFailed(message, {
21
22
  causeKind,
22
- ...(httpStatus !== undefined ? { httpStatus } : {}),
23
+ ...definedObject({ httpStatus }),
23
24
  });
24
25
  }
25
26
  }
@@ -73,7 +74,7 @@ export function httpSyncTransport(syncUrl, options) {
73
74
  ...hostHeaders(options),
74
75
  },
75
76
  body: request.slice().buffer,
76
- ...(signal !== undefined ? { signal } : {}),
77
+ ...definedObject({ signal }),
77
78
  }));
78
79
  if (!response.ok)
79
80
  await throwHttpError(response);
@@ -211,10 +212,10 @@ export function httpSegmentDownloader(segmentsBaseUrl, options) {
211
212
  'X-Syncular-Scopes': request.requestedScopesJson,
212
213
  ...hostHeaders(options),
213
214
  },
214
- ...(request.signal !== undefined ? { signal: request.signal } : {}),
215
+ ...definedObject({ signal: request.signal }),
215
216
  }, request.onProgress, false, request.byteLength);
216
217
  // Deliberately headerless: the URL is the bearer grant (§5.4).
217
- const fetchUrl = (url, onProgress, signal, byteLength) => download(url, signal !== undefined ? { signal } : undefined, onProgress, true, byteLength);
218
+ const fetchUrl = (url, onProgress, signal, byteLength) => download(url, signal && { signal }, onProgress, true, byteLength);
218
219
  return Object.assign(direct, { fetchUrl });
219
220
  }
220
221
  /**
@@ -235,7 +236,7 @@ export function httpBlobTransport(blobsBaseUrl, options) {
235
236
  ...hostHeaders(options),
236
237
  },
237
238
  body: bytes.slice().buffer,
238
- ...(signal !== undefined ? { signal } : {}),
239
+ ...definedObject({ signal }),
239
240
  }));
240
241
  if (!response.ok)
241
242
  await throwHttpError(response);
@@ -291,9 +292,9 @@ export function httpBlobTransport(blobsBaseUrl, options) {
291
292
  },
292
293
  body: JSON.stringify({
293
294
  byteLength,
294
- ...(mediaType !== undefined ? { mediaType } : {}),
295
+ mediaType,
295
296
  }),
296
- ...(signal !== undefined ? { signal } : {}),
297
+ ...definedObject({ signal }),
297
298
  }));
298
299
  if (!response.ok)
299
300
  await throwHttpError(response);
@@ -319,7 +320,7 @@ export function httpBlobTransport(blobsBaseUrl, options) {
319
320
  'x-amz-checksum-sha256': checksum,
320
321
  },
321
322
  body,
322
- ...(signal !== undefined ? { signal } : {}),
323
+ ...definedObject({ signal }),
323
324
  }));
324
325
  if (!response.ok) {
325
326
  throw transportFailed('signed blob upload failed', {
@@ -86,9 +86,10 @@ export declare const TAKEOVER_REFUSED_CODE = "client.takeover_refused";
86
86
  /**
87
87
  * Version of the leader/follower wire and the forwarded handle API. Bump it
88
88
  * with every change to a message shape or to a forwarded method's arguments
89
- * or result, so tabs of different builds never serve each other.
89
+ * or result, so tabs of different builds never serve each other;
90
+ * test/multi-tab-protocol.test.ts pins the surface's fingerprint to it.
90
91
  */
91
- export declare const MULTI_TAB_PROTOCOL_VERSION = 3;
92
+ export declare const MULTI_TAB_PROTOCOL_VERSION = 4;
92
93
  /** What a tab must share with its leader to be served by it. */
93
94
  export interface TabIdentity {
94
95
  readonly protocol: number;
package/dist/multi-tab.js CHANGED
@@ -86,9 +86,10 @@ export const TAKEOVER_REFUSED_CODE = 'client.takeover_refused';
86
86
  /**
87
87
  * Version of the leader/follower wire and the forwarded handle API. Bump it
88
88
  * with every change to a message shape or to a forwarded method's arguments
89
- * or result, so tabs of different builds never serve each other.
89
+ * or result, so tabs of different builds never serve each other;
90
+ * test/multi-tab-protocol.test.ts pins the surface's fingerprint to it.
90
91
  */
91
- export const MULTI_TAB_PROTOCOL_VERSION = 3;
92
+ export const MULTI_TAB_PROTOCOL_VERSION = 4;
92
93
  /**
93
94
  * Order a peer's identity against our own: -1 older, 0 same, 1 newer. A peer
94
95
  * from before protocol 1 sends no identity and is older.
@@ -450,7 +450,8 @@ class QueryEntry {
450
450
  const rowChange = batch.tables.some((change) => this.spec.dependencies.some((dependency) => dependency.table === change.table));
451
451
  if (rowChange && this.#claimError !== undefined)
452
452
  this.reclaim();
453
- else
453
+ // A running read reads again only when its snapshot predates the batch.
454
+ else if (!this.#running)
454
455
  this.#requestRead();
455
456
  }
456
457
  #publish(next) {
@@ -582,9 +583,11 @@ class QueryEntry {
582
583
  return;
583
584
  const generation = this.#generation;
584
585
  this.#running = true;
586
+ let asked = this.#desiredRevision;
585
587
  try {
586
588
  do {
587
589
  this.#requested = false;
590
+ asked = this.#desiredRevision;
588
591
  if (localReadsBlocked(this.store.availabilitySnapshot()))
589
592
  break;
590
593
  if (generation !== this.#generation || this.#listeners.size === 0)
@@ -659,6 +662,9 @@ class QueryEntry {
659
662
  this.#gate();
660
663
  return;
661
664
  }
665
+ // A batch that arrived during the failed read reads again.
666
+ if (this.#desiredRevision > asked)
667
+ this.#requested = true;
662
668
  // SPEC §7.5: a failed latest read is never `ready`; the last
663
669
  // successful rows and revision stay available beside the error.
664
670
  this.#publish({
package/dist/schema.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * DDL, the generated row codec, mutation helpers, and the §3.3 purge
5
5
  * mapping (scope variable → local column).
6
6
  */
7
- import type { RowColumn, RowValue } from '@syncular/core';
7
+ import { type RowColumn, type RowValue } from '@syncular/core';
8
8
  import type { ClientDatabase, SqlRow, SqlValue } from './database.js';
9
9
  /** `'prefix:{variable}'` shorthand (column name = variable) or explicit. */
10
10
  export type ScopePatternSpec = string | {
package/dist/schema.js CHANGED
@@ -5,6 +5,13 @@ import { OUTBOX_TABLE, OUTBOX_IMAGES } from './outbox.js';
5
5
  import { OUTCOMES_TABLE } from './outcomes.js';
6
6
  import { META_TABLE, pruneUnknownUnits, resetUnits, UNITS_TABLE, } from './state.js';
7
7
  import { ensureFailedOverlaySchema, RETAINED_ROWS } from './failed-overlay.js';
8
+ /**
9
+ * Client schema IR (SPEC.md §2.4, §3.1) — the same shape the server
10
+ * compiles and is emitted by codegen. Drives local table
11
+ * DDL, the generated row codec, mutation helpers, and the §3.3 purge
12
+ * mapping (scope variable → local column).
13
+ */
14
+ import { definedObject } from '@syncular/core';
8
15
  import { invalidRequest, localStateCorrupt } from './errors.js';
9
16
  import { snakeToCamel } from './naming.js';
10
17
  const PATTERN_RE = /^([^{}]+):\{([^{}:]+)\}$/;
@@ -127,9 +134,7 @@ export function compileClientSchema(schema) {
127
134
  }
128
135
  tables.set(table.name, {
129
136
  name: table.name,
130
- ...(table.generation !== undefined
131
- ? { generation: table.generation }
132
- : {}),
137
+ ...definedObject({ generation: table.generation }),
133
138
  columns: table.columns,
134
139
  primaryKey: table.primaryKey,
135
140
  primaryKeyIndex,
@@ -1,18 +1,3 @@
1
- /**
2
- * Worker-side bootstrap: constructs the WHOLE
3
- * client core — SyncClient + transports + realtime + SQLite — inside the
4
- * worker and serves the `worker-protocol` RPC over postMessage.
5
- *
6
- * Browsers get the defaults: opfs-sahpool persistence and the fetch/WS
7
- * transports from `./http`, wired from `WorkerInitConfig.endpoints`.
8
- * Tests inject a database factory (bun:sqlite) through `overrides` — the
9
- * same bootstrap, the same RPC, a different SQLite.
10
- *
11
- * The §8.4 host loop lives HERE: wake-ups (hello/`sync` events, delta
12
- * drops) coalesce into one intent-driven `syncUntilIdle` round in the worker;
13
- * RPC-driven and auto-driven sync rounds serialize on one queue because
14
- * the core owns exactly one loop.
15
- */
16
1
  import type { defineAuthorityReads } from './authority.js';
17
2
  import { SyncClient } from './client.js';
18
3
  import type { ClientDatabase } from './database.js';
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Worker-side bootstrap: constructs the WHOLE
3
+ * client core — SyncClient + transports + realtime + SQLite — inside the
4
+ * worker and serves the `worker-protocol` RPC over postMessage.
5
+ *
6
+ * Browsers get the defaults: opfs-sahpool persistence and the fetch/WS
7
+ * transports from `./http`, wired from `WorkerInitConfig.endpoints`.
8
+ * Tests inject a database factory (bun:sqlite) through `overrides` — the
9
+ * same bootstrap, the same RPC, a different SQLite.
10
+ *
11
+ * The §8.4 host loop lives HERE: wake-ups (hello/`sync` events, delta
12
+ * drops) coalesce into one intent-driven `syncUntilIdle` round in the worker;
13
+ * RPC-driven and auto-driven sync rounds serialize on one queue because
14
+ * the core owns exactly one loop.
15
+ */
16
+ import { definedObject } from '@syncular/core';
1
17
  import { SyncClient } from './client.js';
2
18
  import { withClientDiagnosticsHost, } from './diagnostics.js';
3
19
  import { encryptionConfigFromKeyring } from './encryption.js';
@@ -219,12 +235,8 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
219
235
  // Retain the leader lease while the previous worker's OPFS handles
220
236
  // drain. Only opening is retried; core initialization has not started.
221
237
  const delayMs = Math.min(50 * 2 ** attempt, 1000);
222
- if (overrides.waitForStorageRetry !== undefined) {
223
- await overrides.waitForStorageRetry(delayMs);
224
- }
225
- else {
226
- await new Promise((resolve) => setTimeout(resolve, delayMs));
227
- }
238
+ await (overrides.waitForStorageRetry?.(delayMs) ??
239
+ new Promise((resolve) => setTimeout(resolve, delayMs)));
228
240
  }
229
241
  }
230
242
  const remote = overrides.createTransport !== undefined
@@ -248,14 +260,24 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
248
260
  let realtimeConnector;
249
261
  offline = config.transportEnabled === false;
250
262
  const started = new SyncClient({
263
+ ...definedObject({
264
+ segments: bindings.segments,
265
+ blobs,
266
+ clientId: config.clientId,
267
+ limits: config.limits,
268
+ retainFailedCommits: config.retainFailedCommits,
269
+ realtimePolicy: config.realtimePolicy,
270
+ realtimeHeartbeatMs: config.realtimeHeartbeatMs,
271
+ encryption: config.encryption && encryptionConfigFromKeyring(config.encryption),
272
+ authorityReads: config.authorityReads &&
273
+ overrides.createAuthorityReads(config.authorityReads),
274
+ securityPreflight: config.securityPreflight,
275
+ previousVersionContext: config.previousVersionContext,
276
+ }),
251
277
  transportEnabled: !offline,
252
278
  database,
253
279
  schema: config.schema,
254
280
  transport: bindings.transport,
255
- ...(bindings.segments !== undefined
256
- ? { segments: bindings.segments }
257
- : {}),
258
- ...(blobs !== undefined ? { blobs } : {}),
259
281
  realtime: (handlers, clientId) => {
260
282
  // §12.2: a local authority has no realtime channel.
261
283
  if (realtimeConnector === undefined || local?.active()) {
@@ -263,32 +285,7 @@ export function startSyncWorkerCore(overrides, createLocalAuthority) {
263
285
  }
264
286
  return realtimeConnector(handlers, clientId);
265
287
  },
266
- ...(config.clientId !== undefined ? { clientId: config.clientId } : {}),
267
- ...(config.limits !== undefined ? { limits: config.limits } : {}),
268
- ...(config.retainFailedCommits !== undefined
269
- ? { retainFailedCommits: config.retainFailedCommits }
270
- : {}),
271
- ...(config.realtimePolicy !== undefined
272
- ? { realtimePolicy: config.realtimePolicy }
273
- : {}),
274
- ...(config.realtimeHeartbeatMs !== undefined
275
- ? { realtimeHeartbeatMs: config.realtimeHeartbeatMs }
276
- : {}),
277
288
  schedule: scheduleBackground,
278
- ...(config.encryption !== undefined
279
- ? { encryption: encryptionConfigFromKeyring(config.encryption) }
280
- : {}),
281
- ...(config.authorityReads !== undefined
282
- ? {
283
- authorityReads: overrides.createAuthorityReads(config.authorityReads),
284
- }
285
- : {}),
286
- ...(config.securityPreflight !== undefined
287
- ? { securityPreflight: config.securityPreflight }
288
- : {}),
289
- ...(config.previousVersionContext !== undefined
290
- ? { previousVersionContext: config.previousVersionContext }
291
- : {}),
292
289
  onSyncNeeded: (reason) => {
293
290
  emit({ kind: 'sync-needed', reason });
294
291
  consumeSyncIntent({ kind: 'interactive' });
@@ -501,10 +498,8 @@ async function defaultOpenDatabase(config) {
501
498
  if (config.database.mode !== 'persistent') {
502
499
  throw new ClientSyncError(WORKER_FAILED_CODE, "database mode 'custom' requires startSyncWorker({ openDatabase })");
503
500
  }
504
- return openPersistentWasmDatabase(config.database.name, {
505
- ...(config.database.directory !== undefined
506
- ? { directory: config.database.directory }
507
- : {}),
508
- ...(config.takeOverStorage === true ? { takeOver: true } : {}),
509
- });
501
+ return openPersistentWasmDatabase(config.database.name, definedObject({
502
+ directory: config.database.directory,
503
+ takeOver: config.takeOverStorage || undefined,
504
+ }));
510
505
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/client",
3
- "version": "0.91.0",
3
+ "version": "0.92.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",
@@ -121,11 +121,11 @@
121
121
  },
122
122
  "dependencies": {
123
123
  "@sqlite.org/sqlite-wasm": "^3.53.0-build1",
124
- "@syncular/core": "0.91.0"
124
+ "@syncular/core": "0.92.0"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@electric-sql/pglite": "^0.5.4",
128
- "@syncular/server": "0.91.0",
128
+ "@syncular/server": "0.92.0",
129
129
  "playwright": "1.63.0",
130
130
  "vite": "8.3.4"
131
131
  }
package/src/apply.ts CHANGED
@@ -41,6 +41,14 @@ import {
41
41
  /** Lets the client wrap the physical write in its revision transaction. */
42
42
  export type ApplyTransaction = (fn: () => OverlayScope) => unknown;
43
43
 
44
+ /**
45
+ * A step of a generator-driven apply (§1.4 rule 4): the row count of the
46
+ * block it writes next, a negative boundary before work that runs outside a
47
+ * coalesced apply transaction, or async work the driver awaits outside any
48
+ * transaction and whose result it passes back.
49
+ */
50
+ export type ApplyStep = number | (() => Promise<unknown>);
51
+
44
52
  function upsertSql(table: CompiledClientTable): string {
45
53
  const names = [
46
54
  ...table.columns.map((column) => quoteIdent(column.name)),
@@ -601,13 +609,13 @@ export async function applySqliteSegment(
601
609
  if (count !== descriptor.rowCount)
602
610
  imageInvalid('image row count does not match descriptor');
603
611
  const names = table.columns.map((column) => quoteIdent(column.name));
604
- const insertNames = [...names, quoteIdent(SYNC_VERSION_COLUMN)];
612
+ const version = quoteIdent(SYNC_VERSION_COLUMN);
613
+ const insertNames = [...names, version];
605
614
  const primaryKey = quoteIdent(table.primaryKey);
606
615
  const updates = insertNames
607
616
  .filter((name) => name !== primaryKey)
608
617
  .map((name) => `${name}=excluded.${name}`)
609
618
  .join(', ');
610
- const version = quoteIdent(SYNC_VERSION_COLUMN);
611
619
  // A statement copies the `rows` rows after `from`; NULL keys cannot
612
620
  // hide between statements.
613
621
  const range = (from: SqlValue | undefined, rows: number) => {
@@ -677,7 +685,7 @@ export async function applySqliteSegment(
677
685
  );
678
686
  for (;;) {
679
687
  db.exec(
680
- `INSERT INTO ${quoteIdent(table.name)}(${insertNames.join(', ')})SELECT ${[...names, quoteIdent('_syncular_version')].join(', ')} FROM ${source} AS image WHERE ${where} AND NOT EXISTS(SELECT 1 FROM ${quoteIdent(table.name)} AS held WHERE held.${primaryKey}=image.${primaryKey} AND held.${version}>=image._syncular_version) ON CONFLICT(${primaryKey})DO UPDATE SET ${updates}`,
688
+ `INSERT INTO ${quoteIdent(table.name)}(${insertNames.join(', ')})SELECT ${names.join(', ')}, "_syncular_version" FROM ${source} AS image WHERE ${where} AND NOT EXISTS(SELECT 1 FROM ${quoteIdent(table.name)} AS held WHERE held.${primaryKey}=image.${primaryKey} AND held.${version}>=image._syncular_version) ON CONFLICT(${primaryKey})DO UPDATE SET ${updates}`,
681
689
  params,
682
690
  );
683
691
  const copied = Number(
@@ -736,14 +744,17 @@ export async function applySqliteSegment(
736
744
  }
737
745
 
738
746
  /**
739
- * Apply a decoded rows segment: each block in one local transaction
747
+ * Apply a decoded rows segment: each block in its own transaction call
740
748
  * (§5.2/§1.4); `clearFirst` implements the §5.6 fresh-bootstrap first-page
741
- * delete inside the first block's transaction. Each row record carries its
749
+ * delete inside the first block's. Each row record carries its
742
750
  * `serverVersion` (§5.2), which lands in `_sync_version` exactly like a
743
751
  * `COMMIT` change's `rowVersion` (§5.6) — bootstrapped rows seed §6.2
744
- * `baseVersion` conflict detection immediately.
752
+ * `baseVersion` conflict detection immediately. The generator yields each
753
+ * block's row count before its write, so the caller can commit and yield to
754
+ * local reads there (§1.4 rule 4), and yields the async decryption as a step
755
+ * the caller awaits outside any transaction.
745
756
  */
746
- export async function applyRowsSegment(
757
+ export function* applyRowsSegment(
747
758
  db: ClientDatabase,
748
759
  schema: CompiledClientSchema,
749
760
  table: CompiledClientTable,
@@ -759,41 +770,47 @@ export async function applyRowsSegment(
759
770
  readonly isCurrent?: () => boolean;
760
771
  },
761
772
  encryption?: EncryptionConfig,
762
- ): Promise<number> {
773
+ ): Generator<ApplyStep, number, unknown> {
763
774
  validateSegmentColumns(schema, table, segment);
764
775
  let applied = 0;
765
776
  let first = true;
766
- const blocks: readonly (readonly SegmentRow[])[] =
777
+ type Row = SegmentRow & { readonly sealed?: SealedRow | undefined };
778
+ let blocks: readonly (readonly Row[])[] =
767
779
  segment.blocks.length > 0 ? segment.blocks : [[]];
768
- for (const block of blocks) {
769
- if (options.isCurrent?.() === false) break;
770
- // §5.11: decrypt this block's rows before opening the sync transaction
771
- // (WebCrypto is async; the SQLite transaction is not). Decrypt failure
772
- // aborts before any write in this block.
773
- // The rows decrypt concurrently; the first failing row in block order
774
- // decides the error.
775
- let rows: readonly {
776
- values: readonly RowValue[];
777
- serverVersion: number;
778
- sealed?: SealedRow | undefined;
779
- }[] = block;
780
- if (table.hasEncryptedColumns) {
780
+ // §5.11: decrypt the segment's rows before any write (WebCrypto is async;
781
+ // the SQLite transaction is not). The rows decrypt concurrently; the first
782
+ // failing row in segment order decides the error, before any block writes.
783
+ if (table.hasEncryptedColumns)
784
+ blocks = (yield async () => {
781
785
  const { decryptOrSealRowValues } = await import('./encryption');
782
- const settled = await Promise.allSettled(
783
- block.map(async (row) => ({
784
- ...(await decryptOrSealRowValues(encryption, table, row.values)),
785
- serverVersion: row.serverVersion,
786
- })),
786
+ return (
787
+ await Promise.all(
788
+ blocks.map((block) =>
789
+ Promise.allSettled(
790
+ block.map(async (row) => ({
791
+ ...(await decryptOrSealRowValues(
792
+ encryption,
793
+ table,
794
+ row.values,
795
+ )),
796
+ serverVersion: row.serverVersion,
797
+ })),
798
+ ),
799
+ ),
800
+ )
801
+ ).map((block) =>
802
+ block.map((result) => {
803
+ if (result.status === 'rejected') throw result.reason;
804
+ return result.value;
805
+ }),
787
806
  );
788
- rows = settled.map((result) => {
789
- if (result.status === 'rejected') throw result.reason;
790
- return result.value;
791
- });
792
- }
793
- if (options.isCurrent?.() === false) break;
807
+ }) as readonly (readonly Row[])[];
808
+ for (const rows of blocks) {
794
809
  const clearThisBlock = first && options.clearFirst;
795
810
  first = false;
796
811
  if (!clearThisBlock && rows.length === 0) continue;
812
+ yield rows.length;
813
+ if (options.isCurrent?.() === false) break;
797
814
  (options.transaction ?? ((fn) => db.transaction(fn)))(() => {
798
815
  const scope: OverlayScope = [
799
816
  ...(hasUniqueIndex(table) ? [JSON.stringify([table.name])] : []),
@@ -828,7 +845,6 @@ export async function applyRowsSegment(
828
845
  return rebaseScope(scope, kept, skipped);
829
846
  });
830
847
  options.onProgress?.(applied);
831
- await yieldToHost();
832
848
  }
833
849
  options.onProgress?.(applied);
834
850
  return applied;