@powersync/common 1.22.2 → 1.23.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.
@@ -10,25 +10,18 @@ import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnecto
10
10
  import { BucketStorageAdapter } from './sync/bucket/BucketStorageAdapter.js';
11
11
  import { CrudBatch } from './sync/bucket/CrudBatch.js';
12
12
  import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
13
- import { PowerSyncConnectionOptions, StreamingSyncImplementation, StreamingSyncImplementationListener } from './sync/stream/AbstractStreamingSyncImplementation.js';
13
+ import { type AdditionalConnectionOptions, type PowerSyncConnectionOptions, StreamingSyncImplementation, StreamingSyncImplementationListener, type RequiredAdditionalConnectionOptions } from './sync/stream/AbstractStreamingSyncImplementation.js';
14
14
  export interface DisconnectAndClearOptions {
15
15
  /** When set to false, data in local-only tables is preserved. */
16
16
  clearLocal?: boolean;
17
17
  }
18
- export interface BasePowerSyncDatabaseOptions {
18
+ export interface BasePowerSyncDatabaseOptions extends AdditionalConnectionOptions {
19
19
  /** Schema used for the local database. */
20
20
  schema: Schema;
21
21
  /**
22
- * Delay for retrying sync streaming operations
23
- * from the PowerSync backend after an error occurs.
22
+ * @deprecated Use {@link retryDelayMs} instead as this will be removed in future releases.
24
23
  */
25
24
  retryDelay?: number;
26
- /**
27
- * Backend Connector CRUD operations are throttled
28
- * to occur at most every `crudUploadThrottleMs`
29
- * milliseconds.
30
- */
31
- crudUploadThrottleMs?: number;
32
25
  logger?: ILogger;
33
26
  }
34
27
  export interface PowerSyncDatabaseOptions extends BasePowerSyncDatabaseOptions {
@@ -89,7 +82,7 @@ export interface PowerSyncCloseOptions {
89
82
  export declare const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions;
90
83
  export declare const DEFAULT_WATCH_THROTTLE_MS = 30;
91
84
  export declare const DEFAULT_POWERSYNC_DB_OPTIONS: {
92
- retryDelay: number;
85
+ retryDelayMs: number;
93
86
  logger: Logger.ILogger;
94
87
  crudUploadThrottleMs: number;
95
88
  };
@@ -152,7 +145,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
152
145
  * Opens the DBAdapter given open options using a default open factory
153
146
  */
154
147
  protected abstract openDBAdapter(options: PowerSyncDatabaseOptionsWithSettings): DBAdapter;
155
- protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector): StreamingSyncImplementation;
148
+ protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: RequiredAdditionalConnectionOptions): StreamingSyncImplementation;
156
149
  protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
157
150
  /**
158
151
  * @returns A promise which will resolve once initialization is completed.
@@ -185,6 +178,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
185
178
  * While initializing is automatic, this helps to catch and report initialization errors.
186
179
  */
187
180
  init(): Promise<void>;
181
+ resolvedConnectionOptions(options?: PowerSyncConnectionOptions): RequiredAdditionalConnectionOptions;
188
182
  /**
189
183
  * Connects to stream of events from the PowerSync instance.
190
184
  */
@@ -13,7 +13,7 @@ import { PSInternalTable } from './sync/bucket/BucketStorageAdapter.js';
13
13
  import { CrudBatch } from './sync/bucket/CrudBatch.js';
14
14
  import { CrudEntry } from './sync/bucket/CrudEntry.js';
15
15
  import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
16
- import { DEFAULT_CRUD_UPLOAD_THROTTLE_MS } from './sync/stream/AbstractStreamingSyncImplementation.js';
16
+ import { DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_RETRY_DELAY_MS } from './sync/stream/AbstractStreamingSyncImplementation.js';
17
17
  import { runOnSchemaChange } from './runOnSchemaChange.js';
18
18
  const POWERSYNC_TABLE_MATCH = /(^ps_data__|^ps_data_local__)/;
19
19
  const DEFAULT_DISCONNECT_CLEAR_OPTIONS = {
@@ -24,7 +24,7 @@ export const DEFAULT_POWERSYNC_CLOSE_OPTIONS = {
24
24
  };
25
25
  export const DEFAULT_WATCH_THROTTLE_MS = 30;
26
26
  export const DEFAULT_POWERSYNC_DB_OPTIONS = {
27
- retryDelay: 5000,
27
+ retryDelayMs: 5000,
28
28
  logger: Logger.get('PowerSyncDatabase'),
29
29
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
30
30
  };
@@ -222,6 +222,13 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
222
222
  async init() {
223
223
  return this.waitForReady();
224
224
  }
225
+ // Use the options passed in during connect, or fallback to the options set during database creation or fallback to the default options
226
+ resolvedConnectionOptions(options) {
227
+ return {
228
+ retryDelayMs: options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay ?? DEFAULT_RETRY_DELAY_MS,
229
+ crudUploadThrottleMs: options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs ?? DEFAULT_CRUD_UPLOAD_THROTTLE_MS
230
+ };
231
+ }
225
232
  /**
226
233
  * Connects to stream of events from the PowerSync instance.
227
234
  */
@@ -232,7 +239,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
232
239
  if (this.closed) {
233
240
  throw new Error('Cannot connect using a closed client');
234
241
  }
235
- this.syncStreamImplementation = this.generateSyncStreamImplementation(connector);
242
+ const { retryDelayMs, crudUploadThrottleMs } = this.resolvedConnectionOptions(options);
243
+ this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, {
244
+ retryDelayMs,
245
+ crudUploadThrottleMs,
246
+ });
236
247
  this.syncStatusListenerDisposer = this.syncStreamImplementation.registerListener({
237
248
  statusChanged: (status) => {
238
249
  this.currentStatus = new SyncStatus({
@@ -20,10 +20,9 @@ export interface LockOptions<T> {
20
20
  type: LockType;
21
21
  signal?: AbortSignal;
22
22
  }
23
- export interface AbstractStreamingSyncImplementationOptions {
23
+ export interface AbstractStreamingSyncImplementationOptions extends AdditionalConnectionOptions {
24
24
  adapter: BucketStorageAdapter;
25
25
  uploadCrud: () => Promise<void>;
26
- crudUploadThrottleMs?: number;
27
26
  /**
28
27
  * An identifier for which PowerSync DB this sync implementation is
29
28
  * linked to. Most commonly DB name, but not restricted to DB name.
@@ -31,7 +30,6 @@ export interface AbstractStreamingSyncImplementationOptions {
31
30
  identifier?: string;
32
31
  logger?: ILogger;
33
32
  remote: AbstractRemote;
34
- retryDelayMs?: number;
35
33
  }
36
34
  export interface StreamingSyncImplementationListener extends BaseListener {
37
35
  /**
@@ -48,7 +46,10 @@ export interface StreamingSyncImplementationListener extends BaseListener {
48
46
  * Configurable options to be used when connecting to the PowerSync
49
47
  * backend instance.
50
48
  */
51
- export interface PowerSyncConnectionOptions {
49
+ export interface PowerSyncConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {
50
+ }
51
+ /** @internal */
52
+ export interface BaseConnectionOptions {
52
53
  /**
53
54
  * The connection method to use when streaming updates from
54
55
  * the PowerSync backend instance.
@@ -60,6 +61,22 @@ export interface PowerSyncConnectionOptions {
60
61
  */
61
62
  params?: Record<string, StreamingSyncRequestParameterType>;
62
63
  }
64
+ /** @internal */
65
+ export interface AdditionalConnectionOptions {
66
+ /**
67
+ * Delay for retrying sync streaming operations
68
+ * from the PowerSync backend after an error occurs.
69
+ */
70
+ retryDelayMs?: number;
71
+ /**
72
+ * Backend Connector CRUD operations are throttled
73
+ * to occur at most every `crudUploadThrottleMs`
74
+ * milliseconds.
75
+ */
76
+ crudUploadThrottleMs?: number;
77
+ }
78
+ /** @internal */
79
+ export type RequiredAdditionalConnectionOptions = Required<AdditionalConnectionOptions>;
63
80
  export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener>, Disposable {
64
81
  /**
65
82
  * Connects to the sync service
@@ -80,12 +97,14 @@ export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncI
80
97
  waitForStatus(status: SyncStatusOptions): Promise<void>;
81
98
  }
82
99
  export declare const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
100
+ export declare const DEFAULT_RETRY_DELAY_MS = 5000;
83
101
  export declare const DEFAULT_STREAMING_SYNC_OPTIONS: {
84
102
  retryDelayMs: number;
85
103
  logger: Logger.ILogger;
86
104
  crudUploadThrottleMs: number;
87
105
  };
88
- export declare const DEFAULT_STREAM_CONNECTION_OPTIONS: Required<PowerSyncConnectionOptions>;
106
+ export type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
107
+ export declare const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions;
89
108
  export declare abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> implements StreamingSyncImplementation {
90
109
  protected _lastSyncedAt: Date | null;
91
110
  protected options: AbstractStreamingSyncImplementationOptions;
@@ -16,8 +16,9 @@ export var SyncStreamConnectionMethod;
16
16
  SyncStreamConnectionMethod["WEB_SOCKET"] = "web-socket";
17
17
  })(SyncStreamConnectionMethod || (SyncStreamConnectionMethod = {}));
18
18
  export const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000;
19
+ export const DEFAULT_RETRY_DELAY_MS = 5000;
19
20
  export const DEFAULT_STREAMING_SYNC_OPTIONS = {
20
- retryDelayMs: 5000,
21
+ retryDelayMs: DEFAULT_RETRY_DELAY_MS,
21
22
  logger: Logger.get('PowerSyncStream'),
22
23
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
23
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "1.22.2",
3
+ "version": "1.23.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"