@powersync/react-native 0.0.0-dev-20260311081226 → 0.0.0-dev-20260414110516

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.
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var common = require('@powersync/common');
4
4
  var react = require('@powersync/react');
5
5
  var reactNative = require('react-native');
6
- var asyncMutex = require('async-mutex');
7
6
 
8
7
  function getDefaultExportFromCjs (x) {
9
8
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -19208,14 +19207,18 @@ class ReactNativeRemote extends common.AbstractRemote {
19208
19207
  createTextDecoder() {
19209
19208
  return new textEncodingExports.TextDecoder();
19210
19209
  }
19211
- async postStreamRaw(options, mapLine) {
19210
+ get supportsStreamingBinaryResponses() {
19211
+ // We have to pass textStreaming: true to get streamed responses at all, and those don't support binary data.
19212
+ return false;
19213
+ }
19214
+ async fetchStreamRaw(options) {
19212
19215
  const timeout = reactNative.Platform.OS == 'android'
19213
19216
  ? setTimeout(() => {
19214
19217
  this.logger.warn(`HTTP Streaming POST is taking longer than ${Math.ceil(STREAMING_POST_TIMEOUT_MS / 1000)} seconds to resolve. If using a debug build, please ensure Flipper Network plugin is disabled.`);
19215
19218
  }, STREAMING_POST_TIMEOUT_MS)
19216
19219
  : null;
19217
19220
  try {
19218
- return await super.postStreamRaw({
19221
+ return await super.fetchStreamRaw({
19219
19222
  ...options,
19220
19223
  fetchOptions: {
19221
19224
  ...options.fetchOptions,
@@ -19227,7 +19230,7 @@ class ReactNativeRemote extends common.AbstractRemote {
19227
19230
  // @ts-expect-error https://github.com/react-native-community/fetch#enable-text-streaming
19228
19231
  reactNative: { textStreaming: true }
19229
19232
  }
19230
- }, mapLine);
19233
+ });
19231
19234
  }
19232
19235
  finally {
19233
19236
  if (timeout) {
@@ -19258,8 +19261,8 @@ class ReactNativeStreamingSyncImplementation extends common.AbstractStreamingSyn
19258
19261
  return;
19259
19262
  }
19260
19263
  this.locks = new Map();
19261
- this.locks.set(common.LockType.CRUD, new asyncMutex.Mutex());
19262
- this.locks.set(common.LockType.SYNC, new asyncMutex.Mutex());
19264
+ this.locks.set(common.LockType.CRUD, new common.Mutex());
19265
+ this.locks.set(common.LockType.SYNC, new common.Mutex());
19263
19266
  if (identifier) {
19264
19267
  LOCKS.set(identifier, this.locks);
19265
19268
  }
@@ -19270,11 +19273,8 @@ class ReactNativeStreamingSyncImplementation extends common.AbstractStreamingSyn
19270
19273
  throw new Error(`Lock type ${lockOptions.type} not found`);
19271
19274
  }
19272
19275
  return lock.runExclusive(async () => {
19273
- if (lockOptions.signal?.aborted) {
19274
- throw new Error('Aborted');
19275
- }
19276
19276
  return lockOptions.callback();
19277
- });
19277
+ }, lockOptions.signal);
19278
19278
  }
19279
19279
  }
19280
19280
 
@@ -19300,15 +19300,9 @@ function uint8ArrayToArrayBuffer(array) {
19300
19300
  }
19301
19301
  }
19302
19302
 
19303
- /**
19304
- * Adapter for React Native Quick SQLite
19305
- */
19306
- class RNQSDBAdapter extends common.BaseObserver {
19303
+ class RNQSConnectionPool extends common.BaseObserver {
19307
19304
  baseDB;
19308
19305
  name;
19309
- getAll;
19310
- getOptional;
19311
- get;
19312
19306
  constructor(baseDB, name) {
19313
19307
  super();
19314
19308
  this.baseDB = baseDB;
@@ -19317,41 +19311,48 @@ class RNQSDBAdapter extends common.BaseObserver {
19317
19311
  baseDB.registerTablesChangedHook((update) => {
19318
19312
  this.iterateListeners((cb) => cb.tablesUpdated?.(update));
19319
19313
  });
19320
- const topLevelUtils = this.generateDBHelpers({
19321
- // Arrow function binds `this` for use in readOnlyExecute
19322
- execute: (sql, params) => this.readOnlyExecute(sql, params)
19323
- });
19324
- // Only assigning get helpers
19325
- this.getAll = topLevelUtils.getAll;
19326
- this.getOptional = topLevelUtils.getOptional;
19327
- this.get = topLevelUtils.get;
19328
19314
  }
19329
19315
  close() {
19330
19316
  return this.baseDB.close();
19331
19317
  }
19332
19318
  readLock(fn, options) {
19333
- return this.baseDB.readLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19334
- }
19335
- readTransaction(fn, options) {
19336
- return this.baseDB.readTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19319
+ return this.baseDB.readLock((dbTx) => fn(this.generateContext(dbTx)), options);
19337
19320
  }
19338
19321
  writeLock(fn, options) {
19339
- return this.baseDB.writeLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19322
+ return this.baseDB.writeLock((dbTx) => fn(this.generateContext(dbTx)), options);
19340
19323
  }
19341
- writeTransaction(fn, options) {
19342
- return this.baseDB.writeTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19324
+ generateContext(ctx) {
19325
+ return new QuickSqliteContext(ctx);
19326
+ }
19327
+ async refreshSchema() {
19328
+ await this.baseDB.refreshSchema();
19329
+ }
19330
+ }
19331
+ class QuickSqliteExecutor {
19332
+ context;
19333
+ constructor(context) {
19334
+ this.context = context;
19343
19335
  }
19344
19336
  execute(query, params) {
19345
- return this.baseDB.execute(query, params);
19337
+ return this.context.execute(query, params);
19346
19338
  }
19347
19339
  /**
19348
19340
  * 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
19349
19341
  */
19350
19342
  async executeRaw(query, params) {
19351
- const result = await this.baseDB.execute(query, params);
19343
+ const result = await this.context.execute(query, params);
19352
19344
  const rows = result.rows?._array ?? [];
19353
19345
  return rows.map((row) => Object.values(row));
19354
19346
  }
19347
+ }
19348
+ class QuickSqliteContext extends common.DBGetUtilsDefaultMixin(QuickSqliteExecutor) {
19349
+ }
19350
+ /**
19351
+ * Adapter for React Native Quick SQLite
19352
+ */
19353
+ class RNQSDBAdapter extends common.DBAdapterDefaultMixin(RNQSConnectionPool) {
19354
+ // We don't want the default implementation here, RNQS does not support executeBatch for lock contexts so that would
19355
+ // be less efficient.
19355
19356
  async executeBatch(query, params = []) {
19356
19357
  const commands = [];
19357
19358
  for (let i = 0; i < params.length; i++) {
@@ -19362,64 +19363,6 @@ class RNQSDBAdapter extends common.BaseObserver {
19362
19363
  rowsAffected: result.rowsAffected ? result.rowsAffected : 0
19363
19364
  };
19364
19365
  }
19365
- generateContext(ctx) {
19366
- return {
19367
- ...ctx,
19368
- // 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
19369
- executeRaw: async (sql, params) => {
19370
- const result = await ctx.execute(sql, params);
19371
- const rows = result.rows?._array ?? [];
19372
- return rows.map((row) => Object.values(row));
19373
- }
19374
- };
19375
- }
19376
- /**
19377
- * This provides a top-level read only execute method which is executed inside a read-lock.
19378
- * This is necessary since the high level `execute` method uses a write-lock under
19379
- * the hood. Helper methods such as `get`, `getAll` and `getOptional` are read only,
19380
- * and should use this method.
19381
- */
19382
- readOnlyExecute(sql, params) {
19383
- return this.baseDB.readLock((ctx) => ctx.execute(sql, params));
19384
- }
19385
- /**
19386
- * Adds DB get utils to lock contexts and transaction contexts
19387
- * @param tx
19388
- * @returns
19389
- */
19390
- generateDBHelpers(tx) {
19391
- return {
19392
- ...tx,
19393
- /**
19394
- * Execute a read-only query and return results
19395
- */
19396
- getAll: async (sql, parameters) => {
19397
- const res = await tx.execute(sql, parameters);
19398
- return res.rows?._array ?? [];
19399
- },
19400
- /**
19401
- * Execute a read-only query and return the first result, or null if the ResultSet is empty.
19402
- */
19403
- getOptional: async (sql, parameters) => {
19404
- const res = await tx.execute(sql, parameters);
19405
- return res.rows?.item(0) ?? null;
19406
- },
19407
- /**
19408
- * Execute a read-only query and return the first result, error if the ResultSet is empty.
19409
- */
19410
- get: async (sql, parameters) => {
19411
- const res = await tx.execute(sql, parameters);
19412
- const first = res.rows?.item(0);
19413
- if (!first) {
19414
- throw new Error('Result set is empty');
19415
- }
19416
- return first;
19417
- }
19418
- };
19419
- }
19420
- async refreshSchema() {
19421
- await this.baseDB.refreshSchema();
19422
- }
19423
19366
  }
19424
19367
 
19425
19368
  /**