@powersync/common 0.0.0-dev-20250916075127 → 0.0.0-dev-20250922105207

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.4.5 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
226
+ throw new Error(`Unsupported powersync extension version. Need >=0.3.11 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
227
227
  }
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}`);
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}`);
231
231
  }
232
232
  }
233
233
  async updateHasSynced() {
@@ -1,3 +1,4 @@
1
+ import { ILogger } from 'js-logger';
1
2
  import { DBAdapter } from '../db/DBAdapter.js';
2
3
  export interface SQLOpenOptions {
3
4
  /**
@@ -21,6 +22,7 @@ export interface SQLOpenOptions {
21
22
  * debugMode: process.env.NODE_ENV !== 'production'
22
23
  */
23
24
  debugMode?: boolean;
25
+ logger?: ILogger;
24
26
  }
25
27
  export interface SQLOpenFactory {
26
28
  /**
@@ -382,9 +382,6 @@ export class AbstractRemote {
382
382
  * Aborting the active fetch request while it is being consumed seems to throw
383
383
  * an unhandled exception on the window level.
384
384
  */
385
- if (abortSignal?.aborted) {
386
- throw new AbortOperation('Abort request received before making postStreamRaw request');
387
- }
388
385
  const controller = new AbortController();
389
386
  let requestResolved = false;
390
387
  abortSignal?.addEventListener('abort', () => {
@@ -439,9 +439,7 @@ The next upload iteration will be delayed.`);
439
439
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
440
440
  ...(options ?? {})
441
441
  };
442
- const clientImplementation = resolvedOptions.clientImplementation;
443
- this.updateSyncStatus({ clientImplementation });
444
- if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
442
+ if (resolvedOptions.clientImplementation == SyncClientImplementation.JAVASCRIPT) {
445
443
  await this.legacyStreamingSyncIteration(signal, resolvedOptions);
446
444
  }
447
445
  else {
@@ -695,9 +693,6 @@ The next upload iteration will be delayed.`);
695
693
  const remote = this.options.remote;
696
694
  let receivingLines = null;
697
695
  let hadSyncLine = false;
698
- if (signal.aborted) {
699
- throw new AbortOperation('Connection request has been aborted');
700
- }
701
696
  const abortController = new AbortController();
702
697
  signal.addEventListener('abort', () => abortController.abort());
703
698
  // Pending sync lines received from the service, as well as local events that trigger a powersync_control
@@ -939,8 +934,7 @@ The next upload iteration will be delayed.`);
939
934
  ...this.syncStatus.dataFlowStatus,
940
935
  ...options.dataFlow
941
936
  },
942
- priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries,
943
- clientImplementation: options.clientImplementation ?? this.syncStatus.clientImplementation
937
+ priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries
944
938
  });
945
939
  if (!this.syncStatus.isEqual(updatedStatus)) {
946
940
  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.withDiff<Database['todos']>(`
326
+ * const newTodos = await context.getAll<Database['todos']>(`
327
327
  * SELECT
328
328
  * todos.*
329
329
  * FROM
@@ -65,14 +65,12 @@ export declare enum WatchedQueryListenerEvent {
65
65
  ON_DATA = "onData",
66
66
  ON_ERROR = "onError",
67
67
  ON_STATE_CHANGE = "onStateChange",
68
- SETTINGS_WILL_UPDATE = "settingsWillUpdate",
69
68
  CLOSED = "closed"
70
69
  }
71
70
  export interface WatchedQueryListener<Data> extends BaseListener {
72
71
  [WatchedQueryListenerEvent.ON_DATA]?: (data: Data) => void | Promise<void>;
73
72
  [WatchedQueryListenerEvent.ON_ERROR]?: (error: Error) => void | Promise<void>;
74
73
  [WatchedQueryListenerEvent.ON_STATE_CHANGE]?: (state: WatchedQueryState<Data>) => void | Promise<void>;
75
- [WatchedQueryListenerEvent.SETTINGS_WILL_UPDATE]?: () => void;
76
74
  [WatchedQueryListenerEvent.CLOSED]?: () => void | Promise<void>;
77
75
  }
78
76
  export declare const DEFAULT_WATCH_THROTTLE_MS = 30;
@@ -3,7 +3,6 @@ export var WatchedQueryListenerEvent;
3
3
  WatchedQueryListenerEvent["ON_DATA"] = "onData";
4
4
  WatchedQueryListenerEvent["ON_ERROR"] = "onError";
5
5
  WatchedQueryListenerEvent["ON_STATE_CHANGE"] = "onStateChange";
6
- WatchedQueryListenerEvent["SETTINGS_WILL_UPDATE"] = "settingsWillUpdate";
7
6
  WatchedQueryListenerEvent["CLOSED"] = "closed";
8
7
  })(WatchedQueryListenerEvent || (WatchedQueryListenerEvent = {}));
9
8
  export const DEFAULT_WATCH_THROTTLE_MS = 30;
@@ -40,7 +40,6 @@ 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, signal: AbortSignal): Promise<void>;
44
43
  /**
45
44
  * Updates the underlying query.
46
45
  */
@@ -54,7 +53,7 @@ export declare abstract class AbstractQueryProcessor<Data = unknown[], Settings
54
53
  /**
55
54
  * Configures base DB listeners and links the query to listeners.
56
55
  */
57
- protected init(signal: AbortSignal): Promise<void>;
56
+ protected init(): Promise<void>;
58
57
  close(): Promise<void>;
59
58
  /**
60
59
  * Runs a callback and reports errors to the error listeners.
@@ -1,5 +1,4 @@
1
1
  import { MetaBaseObserver } from '../../../utils/MetaBaseObserver.js';
2
- import { WatchedQueryListenerEvent } from '../WatchedQuery.js';
3
2
  /**
4
3
  * Performs underlying watching and yields a stream of results.
5
4
  * @internal
@@ -21,7 +20,7 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
21
20
  this._closed = false;
22
21
  this.state = this.constructInitialState();
23
22
  this.disposeListeners = null;
24
- this.initialized = this.init(this.abortController.signal);
23
+ this.initialized = this.init();
25
24
  }
26
25
  constructInitialState() {
27
26
  return {
@@ -35,40 +34,25 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
35
34
  get reportFetching() {
36
35
  return this.options.watchOptions.reportFetching ?? true;
37
36
  }
38
- async updateSettingsInternal(settings, signal) {
39
- // This may have been aborted while awaiting or if multiple calls to `updateSettings` were made
40
- if (this._closed || signal.aborted) {
41
- return;
42
- }
43
- this.options.watchOptions = settings;
44
- this.iterateListeners((l) => l[WatchedQueryListenerEvent.SETTINGS_WILL_UPDATE]?.());
37
+ /**
38
+ * Updates the underlying query.
39
+ */
40
+ async updateSettings(settings) {
41
+ await this.initialized;
45
42
  if (!this.state.isFetching && this.reportFetching) {
46
43
  await this.updateState({
47
44
  isFetching: true
48
45
  });
49
46
  }
47
+ this.options.watchOptions = settings;
48
+ this.abortController.abort();
49
+ this.abortController = new AbortController();
50
50
  await this.runWithReporting(() => this.linkQuery({
51
- abortSignal: signal,
51
+ abortSignal: this.abortController.signal,
52
52
  settings
53
53
  }));
54
54
  }
55
- /**
56
- * Updates the underlying query.
57
- */
58
- async updateSettings(settings) {
59
- // Abort the previous request
60
- this.abortController.abort();
61
- // Keep track of this controller's abort status
62
- const abortController = new AbortController();
63
- // Allow this to be aborted externally
64
- this.abortController = abortController;
65
- await this.initialized;
66
- return this.updateSettingsInternal(settings, abortController.signal);
67
- }
68
55
  async updateState(update) {
69
- if (this._closed) {
70
- return;
71
- }
72
56
  if (typeof update.error !== 'undefined') {
73
57
  await this.iterateAsyncListenersWithError(async (l) => l.onError?.(update.error));
74
58
  // An error always stops for the current fetching state
@@ -84,7 +68,7 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
84
68
  /**
85
69
  * Configures base DB listeners and links the query to listeners.
86
70
  */
87
- async init(signal) {
71
+ async init() {
88
72
  const { db } = this.options;
89
73
  const disposeCloseListener = db.registerListener({
90
74
  closing: async () => {
@@ -105,15 +89,16 @@ export class AbstractQueryProcessor extends MetaBaseObserver {
105
89
  disposeSchemaListener();
106
90
  };
107
91
  // Initial setup
108
- await this.runWithReporting(async () => {
109
- await this.updateSettingsInternal(this.options.watchOptions, signal);
92
+ this.runWithReporting(async () => {
93
+ await this.updateSettings(this.options.watchOptions);
110
94
  });
111
95
  }
112
96
  async close() {
113
- this._closed = true;
97
+ await this.initialized;
114
98
  this.abortController.abort();
115
99
  this.disposeListeners?.();
116
100
  this.disposeListeners = null;
101
+ this._closed = true;
117
102
  this.iterateListeners((l) => l.closed?.());
118
103
  this.listeners.clear();
119
104
  }
@@ -113,7 +113,7 @@ export class DifferentialQueryProcessor extends AbstractQueryProcessor {
113
113
  });
114
114
  db.onChangeWithCallback({
115
115
  onChange: async () => {
116
- if (this.closed || abortSignal.aborted) {
116
+ if (this.closed) {
117
117
  return;
118
118
  }
119
119
  // This fires for each change of the relevant tables
@@ -130,9 +130,6 @@ 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
- }
136
133
  if (this.reportFetching) {
137
134
  partialStateUpdate.isFetching = false;
138
135
  }
@@ -148,9 +145,6 @@ export class DifferentialQueryProcessor extends AbstractQueryProcessor {
148
145
  data: diff.all
149
146
  });
150
147
  }
151
- if (this.state.error) {
152
- partialStateUpdate.error = null;
153
- }
154
148
  if (Object.keys(partialStateUpdate).length > 0) {
155
149
  await this.updateState(partialStateUpdate);
156
150
  }
@@ -26,7 +26,7 @@ export class OnChangeQueryProcessor extends AbstractQueryProcessor {
26
26
  });
27
27
  db.onChangeWithCallback({
28
28
  onChange: async () => {
29
- if (this.closed || abortSignal.aborted) {
29
+ if (this.closed) {
30
30
  return;
31
31
  }
32
32
  // This fires for each change of the relevant tables
@@ -43,9 +43,6 @@ 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
- }
49
46
  if (this.reportFetching) {
50
47
  partialStateUpdate.isFetching = false;
51
48
  }
@@ -58,9 +55,6 @@ export class OnChangeQueryProcessor extends AbstractQueryProcessor {
58
55
  data: result
59
56
  });
60
57
  }
61
- if (this.state.error) {
62
- partialStateUpdate.error = null;
63
- }
64
58
  if (Object.keys(partialStateUpdate).length > 0) {
65
59
  await this.updateState(partialStateUpdate);
66
60
  }
@@ -1,4 +1,3 @@
1
- import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js';
2
1
  import { InternalProgressInformation, SyncProgress } from './SyncProgress.js';
3
2
  export type SyncDataFlowStatus = Partial<{
4
3
  downloading: boolean;
@@ -33,18 +32,10 @@ export type SyncStatusOptions = {
33
32
  lastSyncedAt?: Date;
34
33
  hasSynced?: boolean;
35
34
  priorityStatusEntries?: SyncPriorityStatus[];
36
- clientImplementation?: SyncClientImplementation;
37
35
  };
38
36
  export declare class SyncStatus {
39
37
  protected options: SyncStatusOptions;
40
38
  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;
48
39
  /**
49
40
  * Indicates if the client is currently connected to the PowerSync service.
50
41
  *
@@ -4,15 +4,6 @@ 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
- }
16
7
  /**
17
8
  * Indicates if the client is currently connected to the PowerSync service.
18
9
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "0.0.0-dev-20250916075127",
3
+ "version": "0.0.0-dev-20250922105207",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"