@powersync/common 1.27.1 → 1.28.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.
@@ -183,6 +183,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
183
183
  * Cannot be used while connected - this should only be called before {@link AbstractPowerSyncDatabase.connect}.
184
184
  */
185
185
  updateSchema(schema: Schema): Promise<void>;
186
+ get logger(): Logger.ILogger;
186
187
  /**
187
188
  * Wait for initialization to complete.
188
189
  * While initializing is automatic, this helps to catch and report initialization errors.
@@ -250,6 +250,9 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
250
250
  await this.database.refreshSchema();
251
251
  this.iterateListeners(async (cb) => cb.schemaChanged?.(schema));
252
252
  }
253
+ get logger() {
254
+ return this.options.logger;
255
+ }
253
256
  /**
254
257
  * Wait for initialization to complete.
255
258
  * While initializing is automatic, this helps to catch and report initialization errors.
@@ -260,6 +263,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
260
263
  // Use the options passed in during connect, or fallback to the options set during database creation or fallback to the default options
261
264
  resolvedConnectionOptions(options) {
262
265
  return {
266
+ ...options,
263
267
  retryDelayMs: options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay ?? DEFAULT_RETRY_DELAY_MS,
264
268
  crudUploadThrottleMs: options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs ?? DEFAULT_CRUD_UPLOAD_THROTTLE_MS
265
269
  };
@@ -274,11 +278,8 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
274
278
  if (this.closed) {
275
279
  throw new Error('Cannot connect using a closed client');
276
280
  }
277
- const { retryDelayMs, crudUploadThrottleMs } = this.resolvedConnectionOptions(options);
278
- this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, {
279
- retryDelayMs,
280
- crudUploadThrottleMs
281
- });
281
+ const resolvedConnectOptions = this.resolvedConnectionOptions(options);
282
+ this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, resolvedConnectOptions);
282
283
  this.syncStatusListenerDisposer = this.syncStreamImplementation.registerListener({
283
284
  statusChanged: (status) => {
284
285
  this.currentStatus = new SyncStatus({
@@ -54,6 +54,13 @@ export type AbstractRemoteOptions = {
54
54
  * Binding should be done before passing here.
55
55
  */
56
56
  fetchImplementation: FetchImplementation | FetchImplementationProvider;
57
+ /**
58
+ * Optional options to pass directly to all `fetch` calls.
59
+ *
60
+ * This can include fields such as `dispatcher` (e.g. for proxy support),
61
+ * `cache`, or any other fetch-compatible options.
62
+ */
63
+ fetchOptions?: {};
57
64
  };
58
65
  export declare const DEFAULT_REMOTE_OPTIONS: AbstractRemoteOptions;
59
66
  export declare abstract class AbstractRemote {
@@ -84,6 +91,7 @@ export declare abstract class AbstractRemote {
84
91
  * Provides a BSON implementation. The import nature of this varies depending on the platform
85
92
  */
86
93
  abstract getBSON(): Promise<BSONImplementation>;
94
+ protected createSocket(url: string): WebSocket;
87
95
  /**
88
96
  * Connects to the sync/stream websocket endpoint
89
97
  */
@@ -44,7 +44,8 @@ export const DEFAULT_REMOTE_OPTIONS = {
44
44
  socketUrlTransformer: (url) => url.replace(/^https?:\/\//, function (match) {
45
45
  return match === 'https://' ? 'wss://' : 'ws://';
46
46
  }),
47
- fetchImplementation: new FetchImplementationProvider()
47
+ fetchImplementation: new FetchImplementationProvider(),
48
+ fetchOptions: {}
48
49
  };
49
50
  export class AbstractRemote {
50
51
  connector;
@@ -153,6 +154,9 @@ export class AbstractRemote {
153
154
  }
154
155
  return res;
155
156
  }
157
+ createSocket(url) {
158
+ return new WebSocket(url);
159
+ }
156
160
  /**
157
161
  * Connects to the sync/stream websocket endpoint
158
162
  */
@@ -167,7 +171,8 @@ export class AbstractRemote {
167
171
  const userAgent = this.getUserAgent();
168
172
  const connector = new RSocketConnector({
169
173
  transport: new WebsocketClientTransport({
170
- url: this.options.socketUrlTransformer(request.url)
174
+ url: this.options.socketUrlTransformer(request.url),
175
+ wsCreator: (url) => this.createSocket(url)
171
176
  }),
172
177
  setup: {
173
178
  keepAlive: KEEP_ALIVE_MS,
@@ -318,6 +323,7 @@ export class AbstractRemote {
318
323
  body: JSON.stringify(data),
319
324
  signal: controller.signal,
320
325
  cache: 'no-store',
326
+ ...(this.options.fetchOptions ?? {}),
321
327
  ...options.fetchOptions
322
328
  }).catch((ex) => {
323
329
  if (ex.name == 'AbortError') {
package/lib/index.d.ts CHANGED
@@ -32,5 +32,6 @@ export * from './db/DBAdapter.js';
32
32
  export * from './utils/AbortOperation.js';
33
33
  export * from './utils/BaseObserver.js';
34
34
  export * from './utils/DataStream.js';
35
+ export * from './utils/Logger.js';
35
36
  export * from './utils/parseQuery.js';
36
37
  export * from './types/types.js';
package/lib/index.js CHANGED
@@ -32,5 +32,6 @@ export * from './db/DBAdapter.js';
32
32
  export * from './utils/AbortOperation.js';
33
33
  export * from './utils/BaseObserver.js';
34
34
  export * from './utils/DataStream.js';
35
+ export * from './utils/Logger.js';
35
36
  export * from './utils/parseQuery.js';
36
37
  export * from './types/types.js';
@@ -0,0 +1,31 @@
1
+ import Logger, { type ILogger, type ILogLevel } from 'js-logger';
2
+ export { GlobalLogger, ILogger, ILoggerOpts, ILogHandler, ILogLevel } from 'js-logger';
3
+ export declare const LogLevel: {
4
+ TRACE: Logger.ILogLevel;
5
+ DEBUG: Logger.ILogLevel;
6
+ INFO: Logger.ILogLevel;
7
+ TIME: Logger.ILogLevel;
8
+ WARN: Logger.ILogLevel;
9
+ ERROR: Logger.ILogLevel;
10
+ OFF: Logger.ILogLevel;
11
+ };
12
+ export interface CreateLoggerOptions {
13
+ logLevel?: ILogLevel;
14
+ }
15
+ /**
16
+ * Retrieves the base (default) logger instance.
17
+ *
18
+ * This base logger controls the default logging configuration and is shared
19
+ * across all loggers created with `createLogger`. Adjusting settings on this
20
+ * base logger affects all loggers derived from it unless explicitly overridden.
21
+ *
22
+ */
23
+ export declare function createBaseLogger(): typeof Logger;
24
+ /**
25
+ * Creates and configures a new named logger based on the base logger.
26
+ *
27
+ * Named loggers allow specific modules or areas of your application to have
28
+ * their own logging levels and behaviors. These loggers inherit configuration
29
+ * from the base logger by default but can override settings independently.
30
+ */
31
+ export declare function createLogger(name: string, options?: CreateLoggerOptions): ILogger;
@@ -0,0 +1,36 @@
1
+ import Logger from 'js-logger';
2
+ const TypedLogger = Logger;
3
+ export const LogLevel = {
4
+ TRACE: TypedLogger.TRACE,
5
+ DEBUG: TypedLogger.DEBUG,
6
+ INFO: TypedLogger.INFO,
7
+ TIME: TypedLogger.TIME,
8
+ WARN: TypedLogger.WARN,
9
+ ERROR: TypedLogger.ERROR,
10
+ OFF: TypedLogger.OFF
11
+ };
12
+ /**
13
+ * Retrieves the base (default) logger instance.
14
+ *
15
+ * This base logger controls the default logging configuration and is shared
16
+ * across all loggers created with `createLogger`. Adjusting settings on this
17
+ * base logger affects all loggers derived from it unless explicitly overridden.
18
+ *
19
+ */
20
+ export function createBaseLogger() {
21
+ return Logger;
22
+ }
23
+ /**
24
+ * Creates and configures a new named logger based on the base logger.
25
+ *
26
+ * Named loggers allow specific modules or areas of your application to have
27
+ * their own logging levels and behaviors. These loggers inherit configuration
28
+ * from the base logger by default but can override settings independently.
29
+ */
30
+ export function createLogger(name, options = {}) {
31
+ const logger = Logger.get(name);
32
+ if (options.logLevel) {
33
+ logger.setLevel(options.logLevel);
34
+ }
35
+ return logger;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "1.27.1",
3
+ "version": "1.28.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"