@syncular/client 0.80.0 → 0.82.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.
@@ -19,6 +19,9 @@ export interface ReactiveQuerySpec<Row> {
19
19
  readonly mapRow?: (row: Readonly<Record<string, SqlValue>>) => Row;
20
20
  readonly rowKey?: (row: Row) => readonly SqlValue[];
21
21
  readonly claimCoverage?: boolean;
22
+ /** Notify observers of the revision of an empty first answer. Off by
23
+ * default; `getSnapshot` returns that revision either way. */
24
+ readonly publishFirstAnswer?: boolean;
22
25
  }
23
26
  export type LiveQueryPhase = 'loading' | 'partial' | 'ready' | 'blocked' | 'error';
24
27
  export interface LiveQueryResult<Row> {
@@ -454,16 +454,21 @@ class QueryEntry {
454
454
  this.#requestRead();
455
455
  }
456
456
  #publish(next) {
457
- // A revision change alone publishes nothing, except the first answer:
458
- // an empty answered read differs from an unread one by its revision.
459
- if ((next.revision === undefined) === (this.#state.revision === undefined) &&
460
- next.rows === this.#state.rows &&
457
+ // A revision change alone publishes nothing. The first answer's revision
458
+ // notifies only a query that opts in; getSnapshot returns it either way.
459
+ const firstAnswer = (next.revision === undefined) !== (this.#state.revision === undefined);
460
+ if (next.rows === this.#state.rows &&
461
461
  next.phase === this.#state.phase &&
462
462
  next.error === this.#state.error &&
463
463
  next.isRefreshing === this.#state.isRefreshing &&
464
464
  canonicalValue(next.availability) ===
465
465
  canonicalValue(this.#state.availability)) {
466
- return;
466
+ if (!firstAnswer)
467
+ return;
468
+ if (this.spec.publishFirstAnswer !== true) {
469
+ this.#state = next;
470
+ return;
471
+ }
467
472
  }
468
473
  this.#state =
469
474
  next.revision === undefined &&
@@ -928,6 +933,7 @@ export class ReactiveClientStore {
928
933
  dependencies,
929
934
  coverage,
930
935
  claimCoverage: spec.claimCoverage !== false,
936
+ publishFirstAnswer: spec.publishFirstAnswer === true,
931
937
  ...(mapRowId === undefined ? {} : { mapRow: mapRowId }),
932
938
  });
933
939
  let entry = this.#queries.get(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/client",
3
- "version": "0.80.0",
3
+ "version": "0.82.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.80.0"
124
+ "@syncular/core": "0.82.0"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@electric-sql/pglite": "^0.5.4",
128
- "@syncular/server": "0.80.0",
128
+ "@syncular/server": "0.82.0",
129
129
  "playwright": "1.63.0",
130
130
  "vite": "8.3.4"
131
131
  }
@@ -36,6 +36,9 @@ export interface ReactiveQuerySpec<Row> {
36
36
  readonly mapRow?: (row: Readonly<Record<string, SqlValue>>) => Row;
37
37
  readonly rowKey?: (row: Row) => readonly SqlValue[];
38
38
  readonly claimCoverage?: boolean;
39
+ /** Notify observers of the revision of an empty first answer. Off by
40
+ * default; `getSnapshot` returns that revision either way. */
41
+ readonly publishFirstAnswer?: boolean;
39
42
  }
40
43
 
41
44
  export type LiveQueryPhase =
@@ -601,10 +604,11 @@ class QueryEntry<Row> implements ExternalStoreEntry<LiveQueryResult<Row>> {
601
604
  }
602
605
 
603
606
  #publish(next: LiveQueryResult<Row>): void {
604
- // A revision change alone publishes nothing, except the first answer:
605
- // an empty answered read differs from an unread one by its revision.
607
+ // A revision change alone publishes nothing. The first answer's revision
608
+ // notifies only a query that opts in; getSnapshot returns it either way.
609
+ const firstAnswer =
610
+ (next.revision === undefined) !== (this.#state.revision === undefined);
606
611
  if (
607
- (next.revision === undefined) === (this.#state.revision === undefined) &&
608
612
  next.rows === this.#state.rows &&
609
613
  next.phase === this.#state.phase &&
610
614
  next.error === this.#state.error &&
@@ -612,7 +616,11 @@ class QueryEntry<Row> implements ExternalStoreEntry<LiveQueryResult<Row>> {
612
616
  canonicalValue(next.availability) ===
613
617
  canonicalValue(this.#state.availability)
614
618
  ) {
615
- return;
619
+ if (!firstAnswer) return;
620
+ if (this.spec.publishFirstAnswer !== true) {
621
+ this.#state = next;
622
+ return;
623
+ }
616
624
  }
617
625
  this.#state =
618
626
  next.revision === undefined &&
@@ -1118,6 +1126,7 @@ export class ReactiveClientStore {
1118
1126
  dependencies,
1119
1127
  coverage,
1120
1128
  claimCoverage: spec.claimCoverage !== false,
1129
+ publishFirstAnswer: spec.publishFirstAnswer === true,
1121
1130
  ...(mapRowId === undefined ? {} : { mapRow: mapRowId }),
1122
1131
  });
1123
1132
  let entry = this.#queries.get(key) as QueryEntry<Row> | undefined;