@powersync/common 0.0.0-dev-20250828091657 → 0.0.0-dev-20250909205633

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.
@@ -223,11 +223,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
223
223
  .map((n) => parseInt(n));
224
224
  }
225
225
  catch (e) {
226
- throw new Error(`Unsupported powersync extension version. Need >=0.3.11 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
226
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
227
227
  }
228
- // Validate >=0.3.11 <1.0.0
229
- if (versionInts[0] != 0 || versionInts[1] < 3 || (versionInts[1] == 3 && versionInts[2] < 11)) {
230
- throw new Error(`Unsupported powersync extension version. Need >=0.3.11 <1.0.0, got: ${this.sdkVersion}`);
228
+ // Validate >=0.4.5 <1.0.0
229
+ if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 5)) {
230
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}`);
231
231
  }
232
232
  }
233
233
  async updateHasSynced() {
@@ -439,7 +439,9 @@ The next upload iteration will be delayed.`);
439
439
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
440
440
  ...(options ?? {})
441
441
  };
442
- if (resolvedOptions.clientImplementation == SyncClientImplementation.JAVASCRIPT) {
442
+ const clientImplementation = resolvedOptions.clientImplementation;
443
+ this.updateSyncStatus({ clientImplementation });
444
+ if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
443
445
  await this.legacyStreamingSyncIteration(signal, resolvedOptions);
444
446
  }
445
447
  else {
@@ -937,7 +939,8 @@ The next upload iteration will be delayed.`);
937
939
  ...this.syncStatus.dataFlowStatus,
938
940
  ...options.dataFlow
939
941
  },
940
- priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries
942
+ priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries,
943
+ clientImplementation: options.clientImplementation ?? this.syncStatus.clientImplementation
941
944
  });
942
945
  if (!this.syncStatus.isEqual(updatedStatus)) {
943
946
  this.syncStatus = updatedStatus;
@@ -323,7 +323,7 @@ export interface TriggerManager {
323
323
  * },
324
324
  * onChange: async (context) => {
325
325
  * // Fetches the todo records that were inserted during this diff
326
- * const newTodos = await context.getAll<Database['todos']>(`
326
+ * const newTodos = await context.withDiff<Database['todos']>(`
327
327
  * SELECT
328
328
  * todos.*
329
329
  * FROM
@@ -40,6 +40,7 @@ export declare abstract class AbstractQueryProcessor<Data = unknown[], Settings
40
40
  constructor(options: AbstractQueryProcessorOptions<Data, Settings>);
41
41
  protected constructInitialState(): WatchedQueryState<Data>;
42
42
  protected get reportFetching(): boolean;
43
+ protected updateSettingsInternal(settings: Settings): Promise<void>;
43
44
  /**
44
45
  * Updates the underlying query.
45
46
  */
@@ -34,24 +34,35 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
34
34
  get reportFetching() {
35
35
  return this.options.watchOptions.reportFetching ?? true;
36
36
  }
37
- /**
38
- * Updates the underlying query.
39
- */
40
- async updateSettings(settings) {
41
- await this.initialized;
37
+ async updateSettingsInternal(settings) {
38
+ // Abort any previous requests
39
+ this.abortController.abort();
40
+ // Keep track of this controller's abort status
41
+ const abortController = new AbortController();
42
+ // Allow this to be aborted externally
43
+ this.abortController = abortController;
44
+ // This may have been aborted while awaiting or if multiple calls to `updateSettings` were made
45
+ if (abortController.signal.aborted) {
46
+ return;
47
+ }
48
+ this.options.watchOptions = settings;
42
49
  if (!this.state.isFetching && this.reportFetching) {
43
50
  await this.updateState({
44
51
  isFetching: true
45
52
  });
46
53
  }
47
- this.options.watchOptions = settings;
48
- this.abortController.abort();
49
- this.abortController = new AbortController();
50
54
  await this.runWithReporting(() => this.linkQuery({
51
- abortSignal: this.abortController.signal,
55
+ abortSignal: abortController.signal,
52
56
  settings
53
57
  }));
54
58
  }
59
+ /**
60
+ * Updates the underlying query.
61
+ */
62
+ async updateSettings(settings) {
63
+ await this.initialized;
64
+ return this.updateSettingsInternal(settings);
65
+ }
55
66
  async updateState(update) {
56
67
  if (typeof update.error !== 'undefined') {
57
68
  await this.iterateAsyncListenersWithError(async (l) => l.onError?.(update.error));
@@ -89,8 +100,8 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
89
100
  disposeSchemaListener();
90
101
  };
91
102
  // Initial setup
92
- this.runWithReporting(async () => {
93
- await this.updateSettings(this.options.watchOptions);
103
+ await this.runWithReporting(async () => {
104
+ await this.updateSettingsInternal(this.options.watchOptions);
94
105
  });
95
106
  }
96
107
  async close() {
@@ -113,7 +113,7 @@ export class DifferentialQueryProcessor extends AbstractQueryProcessor {
113
113
  });
114
114
  db.onChangeWithCallback({
115
115
  onChange: async () => {
116
- if (this.closed) {
116
+ if (this.closed || abortSignal.aborted) {
117
117
  return;
118
118
  }
119
119
  // This fires for each change of the relevant tables
@@ -130,6 +130,9 @@ export class DifferentialQueryProcessor extends AbstractQueryProcessor {
130
130
  parameters: [...compiledQuery.parameters],
131
131
  db: this.options.db
132
132
  });
133
+ if (abortSignal.aborted) {
134
+ return;
135
+ }
133
136
  if (this.reportFetching) {
134
137
  partialStateUpdate.isFetching = false;
135
138
  }
@@ -26,7 +26,7 @@ export class OnChangeQueryProcessor extends AbstractQueryProcessor {
26
26
  });
27
27
  db.onChangeWithCallback({
28
28
  onChange: async () => {
29
- if (this.closed) {
29
+ if (this.closed || abortSignal.aborted) {
30
30
  return;
31
31
  }
32
32
  // This fires for each change of the relevant tables
@@ -43,6 +43,9 @@ export class OnChangeQueryProcessor extends AbstractQueryProcessor {
43
43
  parameters: [...compiledQuery.parameters],
44
44
  db: this.options.db
45
45
  });
46
+ if (abortSignal.aborted) {
47
+ return;
48
+ }
46
49
  if (this.reportFetching) {
47
50
  partialStateUpdate.isFetching = false;
48
51
  }
@@ -1,3 +1,4 @@
1
+ import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js';
1
2
  import { InternalProgressInformation, SyncProgress } from './SyncProgress.js';
2
3
  export type SyncDataFlowStatus = Partial<{
3
4
  downloading: boolean;
@@ -32,10 +33,18 @@ export type SyncStatusOptions = {
32
33
  lastSyncedAt?: Date;
33
34
  hasSynced?: boolean;
34
35
  priorityStatusEntries?: SyncPriorityStatus[];
36
+ clientImplementation?: SyncClientImplementation;
35
37
  };
36
38
  export declare class SyncStatus {
37
39
  protected options: SyncStatusOptions;
38
40
  constructor(options: SyncStatusOptions);
41
+ /**
42
+ * Returns the used sync client implementation (either the one implemented in JavaScript or the newer Rust-based
43
+ * implementation).
44
+ *
45
+ * This information is only available after a connection has been requested.
46
+ */
47
+ get clientImplementation(): SyncClientImplementation | undefined;
39
48
  /**
40
49
  * Indicates if the client is currently connected to the PowerSync service.
41
50
  *
@@ -4,6 +4,15 @@ export class SyncStatus {
4
4
  constructor(options) {
5
5
  this.options = options;
6
6
  }
7
+ /**
8
+ * Returns the used sync client implementation (either the one implemented in JavaScript or the newer Rust-based
9
+ * implementation).
10
+ *
11
+ * This information is only available after a connection has been requested.
12
+ */
13
+ get clientImplementation() {
14
+ return this.options.clientImplementation;
15
+ }
7
16
  /**
8
17
  * Indicates if the client is currently connected to the PowerSync service.
9
18
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "0.0.0-dev-20250828091657",
3
+ "version": "0.0.0-dev-20250909205633",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"