@powersync/common 1.43.1 → 1.45.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.
Files changed (36) hide show
  1. package/dist/bundle.cjs +129 -81
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +129 -82
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +117 -69
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +117 -70
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +178 -150
  10. package/lib/client/AbstractPowerSyncDatabase.d.ts +1 -1
  11. package/lib/client/AbstractPowerSyncDatabase.js +5 -5
  12. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  13. package/lib/client/ConnectionManager.d.ts +1 -1
  14. package/lib/client/ConnectionManager.js.map +1 -1
  15. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +4 -0
  16. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +8 -0
  17. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  18. package/lib/client/sync/stream/streaming-sync-types.d.ts +4 -0
  19. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -1
  20. package/lib/db/ConnectionClosedError.d.ts +10 -0
  21. package/lib/db/ConnectionClosedError.js +21 -0
  22. package/lib/db/ConnectionClosedError.js.map +1 -0
  23. package/lib/db/crud/SyncStatus.d.ts +11 -2
  24. package/lib/db/crud/SyncStatus.js +19 -1
  25. package/lib/db/crud/SyncStatus.js.map +1 -1
  26. package/lib/index.d.ts +1 -0
  27. package/lib/index.js +1 -0
  28. package/lib/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/client/AbstractPowerSyncDatabase.ts +8 -8
  31. package/src/client/ConnectionManager.ts +1 -1
  32. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +19 -2
  33. package/src/client/sync/stream/streaming-sync-types.ts +5 -0
  34. package/src/db/ConnectionClosedError.ts +23 -0
  35. package/src/db/crud/SyncStatus.ts +22 -3
  36. package/src/index.ts +1 -0
package/dist/bundle.mjs CHANGED
@@ -720,12 +720,30 @@ class SyncStatus {
720
720
  return {
721
721
  connected: this.connected,
722
722
  connecting: this.connecting,
723
- dataFlow: this.dataFlowStatus,
723
+ dataFlow: {
724
+ ...this.dataFlowStatus,
725
+ uploadError: this.serializeError(this.dataFlowStatus.uploadError),
726
+ downloadError: this.serializeError(this.dataFlowStatus.downloadError)
727
+ },
724
728
  lastSyncedAt: this.lastSyncedAt,
725
729
  hasSynced: this.hasSynced,
726
730
  priorityStatusEntries: this.priorityStatusEntries
727
731
  };
728
732
  }
733
+ /**
734
+ * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
735
+ * This explicitly serializes errors in the SyncStatus.
736
+ */
737
+ serializeError(error) {
738
+ if (typeof error == 'undefined') {
739
+ return undefined;
740
+ }
741
+ return {
742
+ name: error.name,
743
+ message: error.message,
744
+ stack: error.stack
745
+ };
746
+ }
729
747
  static comparePriorities(a, b) {
730
748
  return b.priority - a.priority; // Reverse because higher priorities have lower numbers
731
749
  }
@@ -2338,7 +2356,7 @@ var hasRequiredBuffer$1;
2338
2356
  function requireBuffer$1 () {
2339
2357
  if (hasRequiredBuffer$1) return buffer$1;
2340
2358
  hasRequiredBuffer$1 = 1;
2341
- (function (exports) {
2359
+ (function (exports$1) {
2342
2360
 
2343
2361
  const base64 = requireBase64Js();
2344
2362
  const ieee754 = requireIeee754();
@@ -2347,12 +2365,12 @@ function requireBuffer$1 () {
2347
2365
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
2348
2366
  : null;
2349
2367
 
2350
- exports.Buffer = Buffer;
2351
- exports.SlowBuffer = SlowBuffer;
2352
- exports.INSPECT_MAX_BYTES = 50;
2368
+ exports$1.Buffer = Buffer;
2369
+ exports$1.SlowBuffer = SlowBuffer;
2370
+ exports$1.INSPECT_MAX_BYTES = 50;
2353
2371
 
2354
2372
  const K_MAX_LENGTH = 0x7fffffff;
2355
- exports.kMaxLength = K_MAX_LENGTH;
2373
+ exports$1.kMaxLength = K_MAX_LENGTH;
2356
2374
 
2357
2375
  /**
2358
2376
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -2948,7 +2966,7 @@ function requireBuffer$1 () {
2948
2966
 
2949
2967
  Buffer.prototype.inspect = function inspect () {
2950
2968
  let str = '';
2951
- const max = exports.INSPECT_MAX_BYTES;
2969
+ const max = exports$1.INSPECT_MAX_BYTES;
2952
2970
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
2953
2971
  if (this.length > max) str += ' ... ';
2954
2972
  return '<Buffer ' + str + '>'
@@ -4456,7 +4474,7 @@ var hasRequiredBuffer;
4456
4474
  function requireBuffer () {
4457
4475
  if (hasRequiredBuffer) return buffer;
4458
4476
  hasRequiredBuffer = 1;
4459
- (function (exports) {
4477
+ (function (exports$1) {
4460
4478
 
4461
4479
  var base64 = requireBase64Js();
4462
4480
  var ieee754 = requireIeee754();
@@ -4465,12 +4483,12 @@ function requireBuffer () {
4465
4483
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
4466
4484
  : null;
4467
4485
 
4468
- exports.Buffer = Buffer;
4469
- exports.SlowBuffer = SlowBuffer;
4470
- exports.INSPECT_MAX_BYTES = 50;
4486
+ exports$1.Buffer = Buffer;
4487
+ exports$1.SlowBuffer = SlowBuffer;
4488
+ exports$1.INSPECT_MAX_BYTES = 50;
4471
4489
 
4472
4490
  var K_MAX_LENGTH = 0x7fffffff;
4473
- exports.kMaxLength = K_MAX_LENGTH;
4491
+ exports$1.kMaxLength = K_MAX_LENGTH;
4474
4492
 
4475
4493
  /**
4476
4494
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -5067,7 +5085,7 @@ function requireBuffer () {
5067
5085
 
5068
5086
  Buffer.prototype.inspect = function inspect () {
5069
5087
  var str = '';
5070
- var max = exports.INSPECT_MAX_BYTES;
5088
+ var max = exports$1.INSPECT_MAX_BYTES;
5071
5089
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
5072
5090
  if (this.length > max) str += ' ... ';
5073
5091
  return '<Buffer ' + str + '>'
@@ -6280,7 +6298,7 @@ var hasRequiredFrames;
6280
6298
  function requireFrames () {
6281
6299
  if (hasRequiredFrames) return Frames;
6282
6300
  hasRequiredFrames = 1;
6283
- (function (exports) {
6301
+ (function (exports$1) {
6284
6302
  /*
6285
6303
  * Copyright 2021-2022 the original author or authors.
6286
6304
  *
@@ -6296,8 +6314,8 @@ function requireFrames () {
6296
6314
  * See the License for the specific language governing permissions and
6297
6315
  * limitations under the License.
6298
6316
  */
6299
- Object.defineProperty(exports, "__esModule", { value: true });
6300
- exports.Frame = exports.Lengths = exports.Flags = exports.FrameTypes = void 0;
6317
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6318
+ exports$1.Frame = exports$1.Lengths = exports$1.Flags = exports$1.FrameTypes = void 0;
6301
6319
  var FrameTypes;
6302
6320
  (function (FrameTypes) {
6303
6321
  FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
@@ -6316,7 +6334,7 @@ function requireFrames () {
6316
6334
  FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
6317
6335
  FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
6318
6336
  FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
6319
- })(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
6337
+ })(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
6320
6338
  (function (Flags) {
6321
6339
  Flags[Flags["NONE"] = 0] = "NONE";
6322
6340
  Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
@@ -6327,7 +6345,7 @@ function requireFrames () {
6327
6345
  Flags[Flags["NEXT"] = 32] = "NEXT";
6328
6346
  Flags[Flags["RESPOND"] = 128] = "RESPOND";
6329
6347
  Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
6330
- })(exports.Flags || (exports.Flags = {}));
6348
+ })(exports$1.Flags || (exports$1.Flags = {}));
6331
6349
  (function (Flags) {
6332
6350
  function hasMetadata(flags) {
6333
6351
  return (flags & Flags.METADATA) === Flags.METADATA;
@@ -6361,13 +6379,13 @@ function requireFrames () {
6361
6379
  return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
6362
6380
  }
6363
6381
  Flags.hasResume = hasResume;
6364
- })(exports.Flags || (exports.Flags = {}));
6382
+ })(exports$1.Flags || (exports$1.Flags = {}));
6365
6383
  (function (Lengths) {
6366
6384
  Lengths[Lengths["FRAME"] = 3] = "FRAME";
6367
6385
  Lengths[Lengths["HEADER"] = 6] = "HEADER";
6368
6386
  Lengths[Lengths["METADATA"] = 3] = "METADATA";
6369
6387
  Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
6370
- })(exports.Lengths || (exports.Lengths = {}));
6388
+ })(exports$1.Lengths || (exports$1.Lengths = {}));
6371
6389
  (function (Frame) {
6372
6390
  function isConnection(frame) {
6373
6391
  return frame.streamId === 0;
@@ -6378,7 +6396,7 @@ function requireFrames () {
6378
6396
  frame.type <= FrameTypes.REQUEST_CHANNEL);
6379
6397
  }
6380
6398
  Frame.isRequest = isRequest;
6381
- })(exports.Frame || (exports.Frame = {}));
6399
+ })(exports$1.Frame || (exports$1.Frame = {}));
6382
6400
 
6383
6401
  } (Frames));
6384
6402
  return Frames;
@@ -6389,7 +6407,7 @@ var hasRequiredCodecs;
6389
6407
  function requireCodecs () {
6390
6408
  if (hasRequiredCodecs) return Codecs;
6391
6409
  hasRequiredCodecs = 1;
6392
- (function (exports) {
6410
+ (function (exports$1) {
6393
6411
  var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
6394
6412
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
6395
6413
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -6417,22 +6435,22 @@ function requireCodecs () {
6417
6435
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6418
6436
  }
6419
6437
  };
6420
- Object.defineProperty(exports, "__esModule", { value: true });
6421
- exports.Deserializer = exports.sizeOfFrame = exports.serializeFrame = exports.deserializeFrame = exports.serializeFrameWithLength = exports.deserializeFrames = exports.deserializeFrameWithLength = exports.writeUInt64BE = exports.readUInt64BE = exports.writeUInt24BE = exports.readUInt24BE = exports.MAX_VERSION = exports.MAX_TTL = exports.MAX_STREAM_ID = exports.MAX_RESUME_LENGTH = exports.MAX_REQUEST_N = exports.MAX_REQUEST_COUNT = exports.MAX_MIME_LENGTH = exports.MAX_METADATA_LENGTH = exports.MAX_LIFETIME = exports.MAX_KEEPALIVE = exports.MAX_CODE = exports.FRAME_TYPE_OFFFSET = exports.FLAGS_MASK = void 0;
6438
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6439
+ exports$1.Deserializer = exports$1.sizeOfFrame = exports$1.serializeFrame = exports$1.deserializeFrame = exports$1.serializeFrameWithLength = exports$1.deserializeFrames = exports$1.deserializeFrameWithLength = exports$1.writeUInt64BE = exports$1.readUInt64BE = exports$1.writeUInt24BE = exports$1.readUInt24BE = exports$1.MAX_VERSION = exports$1.MAX_TTL = exports$1.MAX_STREAM_ID = exports$1.MAX_RESUME_LENGTH = exports$1.MAX_REQUEST_N = exports$1.MAX_REQUEST_COUNT = exports$1.MAX_MIME_LENGTH = exports$1.MAX_METADATA_LENGTH = exports$1.MAX_LIFETIME = exports$1.MAX_KEEPALIVE = exports$1.MAX_CODE = exports$1.FRAME_TYPE_OFFFSET = exports$1.FLAGS_MASK = void 0;
6422
6440
  var Frames_1 = requireFrames();
6423
- exports.FLAGS_MASK = 0x3ff; // low 10 bits
6424
- exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
6425
- exports.MAX_CODE = 0x7fffffff; // uint31
6426
- exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
6427
- exports.MAX_LIFETIME = 0x7fffffff; // uint31
6428
- exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
6429
- exports.MAX_MIME_LENGTH = 0xff; // int8
6430
- exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
6431
- exports.MAX_REQUEST_N = 0x7fffffff; // uint31
6432
- exports.MAX_RESUME_LENGTH = 0xffff; // uint16
6433
- exports.MAX_STREAM_ID = 0x7fffffff; // uint31
6434
- exports.MAX_TTL = 0x7fffffff; // uint31
6435
- exports.MAX_VERSION = 0xffff; // uint16
6441
+ exports$1.FLAGS_MASK = 0x3ff; // low 10 bits
6442
+ exports$1.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
6443
+ exports$1.MAX_CODE = 0x7fffffff; // uint31
6444
+ exports$1.MAX_KEEPALIVE = 0x7fffffff; // uint31
6445
+ exports$1.MAX_LIFETIME = 0x7fffffff; // uint31
6446
+ exports$1.MAX_METADATA_LENGTH = 0xffffff; // uint24
6447
+ exports$1.MAX_MIME_LENGTH = 0xff; // int8
6448
+ exports$1.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
6449
+ exports$1.MAX_REQUEST_N = 0x7fffffff; // uint31
6450
+ exports$1.MAX_RESUME_LENGTH = 0xffff; // uint16
6451
+ exports$1.MAX_STREAM_ID = 0x7fffffff; // uint31
6452
+ exports$1.MAX_TTL = 0x7fffffff; // uint31
6453
+ exports$1.MAX_VERSION = 0xffff; // uint16
6436
6454
  /**
6437
6455
  * Mimimum value that would overflow bitwise operators (2^32).
6438
6456
  */
@@ -6446,7 +6464,7 @@ function requireCodecs () {
6446
6464
  var val3 = buffer.readUInt8(offset + 2);
6447
6465
  return val1 | val2 | val3;
6448
6466
  }
6449
- exports.readUInt24BE = readUInt24BE;
6467
+ exports$1.readUInt24BE = readUInt24BE;
6450
6468
  /**
6451
6469
  * Writes a uint24 to a buffer starting at the given offset, returning the
6452
6470
  * offset of the next byte.
@@ -6456,7 +6474,7 @@ function requireCodecs () {
6456
6474
  offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
6457
6475
  return buffer.writeUInt8(value & 0xff, offset); // 1st byte
6458
6476
  }
6459
- exports.writeUInt24BE = writeUInt24BE;
6477
+ exports$1.writeUInt24BE = writeUInt24BE;
6460
6478
  /**
6461
6479
  * Read a uint64 (technically supports up to 53 bits per JS number
6462
6480
  * representation).
@@ -6466,7 +6484,7 @@ function requireCodecs () {
6466
6484
  var low = buffer.readUInt32BE(offset + 4);
6467
6485
  return high * BITWISE_OVERFLOW + low;
6468
6486
  }
6469
- exports.readUInt64BE = readUInt64BE;
6487
+ exports$1.readUInt64BE = readUInt64BE;
6470
6488
  /**
6471
6489
  * Write a uint64 (technically supports up to 53 bits per JS number
6472
6490
  * representation).
@@ -6477,7 +6495,7 @@ function requireCodecs () {
6477
6495
  offset = buffer.writeUInt32BE(high, offset); // first half of uint64
6478
6496
  return buffer.writeUInt32BE(low, offset); // second half of uint64
6479
6497
  }
6480
- exports.writeUInt64BE = writeUInt64BE;
6498
+ exports$1.writeUInt64BE = writeUInt64BE;
6481
6499
  /**
6482
6500
  * Frame header is:
6483
6501
  * - stream id (uint32 = 4)
@@ -6495,7 +6513,7 @@ function requireCodecs () {
6495
6513
  var frameLength = readUInt24BE(buffer, 0);
6496
6514
  return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
6497
6515
  }
6498
- exports.deserializeFrameWithLength = deserializeFrameWithLength;
6516
+ exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
6499
6517
  /**
6500
6518
  * Given a buffer that may contain zero or more length-prefixed frames followed
6501
6519
  * by zero or more bytes of a (partial) subsequent frame, returns an array of
@@ -6528,7 +6546,7 @@ function requireCodecs () {
6528
6546
  }
6529
6547
  });
6530
6548
  }
6531
- exports.deserializeFrames = deserializeFrames;
6549
+ exports$1.deserializeFrames = deserializeFrames;
6532
6550
  /**
6533
6551
  * Writes a frame to a buffer with a length prefix.
6534
6552
  */
@@ -6539,7 +6557,7 @@ function requireCodecs () {
6539
6557
  buffer.copy(lengthPrefixed, UINT24_SIZE);
6540
6558
  return lengthPrefixed;
6541
6559
  }
6542
- exports.serializeFrameWithLength = serializeFrameWithLength;
6560
+ exports$1.serializeFrameWithLength = serializeFrameWithLength;
6543
6561
  /**
6544
6562
  * Read a frame from the buffer.
6545
6563
  */
@@ -6554,8 +6572,8 @@ function requireCodecs () {
6554
6572
  // );
6555
6573
  var typeAndFlags = buffer.readUInt16BE(offset);
6556
6574
  offset += 2;
6557
- var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
6558
- var flags = typeAndFlags & exports.FLAGS_MASK; // keep lowest 10 bits
6575
+ var type = typeAndFlags >>> exports$1.FRAME_TYPE_OFFFSET; // keep highest 6 bits
6576
+ var flags = typeAndFlags & exports$1.FLAGS_MASK; // keep lowest 10 bits
6559
6577
  switch (type) {
6560
6578
  case Frames_1.FrameTypes.SETUP:
6561
6579
  return deserializeSetupFrame(buffer, streamId, flags);
@@ -6592,7 +6610,7 @@ function requireCodecs () {
6592
6610
  // );
6593
6611
  }
6594
6612
  }
6595
- exports.deserializeFrame = deserializeFrame;
6613
+ exports$1.deserializeFrame = deserializeFrame;
6596
6614
  /**
6597
6615
  * Convert the frame to a (binary) buffer.
6598
6616
  */
@@ -6631,7 +6649,7 @@ function requireCodecs () {
6631
6649
  // );
6632
6650
  }
6633
6651
  }
6634
- exports.serializeFrame = serializeFrame;
6652
+ exports$1.serializeFrame = serializeFrame;
6635
6653
  /**
6636
6654
  * Byte size of frame without size prefix
6637
6655
  */
@@ -6670,7 +6688,7 @@ function requireCodecs () {
6670
6688
  // );
6671
6689
  }
6672
6690
  }
6673
- exports.sizeOfFrame = sizeOfFrame;
6691
+ exports$1.sizeOfFrame = sizeOfFrame;
6674
6692
  /**
6675
6693
  * Writes a SETUP frame into a new buffer and returns it.
6676
6694
  *
@@ -7305,7 +7323,7 @@ function requireCodecs () {
7305
7323
  function writeHeader(frame, buffer) {
7306
7324
  var offset = buffer.writeInt32BE(frame.streamId, 0);
7307
7325
  // shift frame to high 6 bits, extract lowest 10 bits from flags
7308
- return buffer.writeUInt16BE((frame.type << exports.FRAME_TYPE_OFFFSET) | (frame.flags & exports.FLAGS_MASK), offset);
7326
+ return buffer.writeUInt16BE((frame.type << exports$1.FRAME_TYPE_OFFFSET) | (frame.flags & exports$1.FLAGS_MASK), offset);
7309
7327
  }
7310
7328
  /**
7311
7329
  * Determine the length of the payload section of a frame. Only applies to
@@ -7386,7 +7404,7 @@ function requireCodecs () {
7386
7404
  };
7387
7405
  return Deserializer;
7388
7406
  }());
7389
- exports.Deserializer = Deserializer;
7407
+ exports$1.Deserializer = Deserializer;
7390
7408
 
7391
7409
  } (Codecs));
7392
7410
  return Codecs;
@@ -7532,7 +7550,7 @@ var hasRequiredErrors;
7532
7550
  function requireErrors () {
7533
7551
  if (hasRequiredErrors) return Errors;
7534
7552
  hasRequiredErrors = 1;
7535
- (function (exports) {
7553
+ (function (exports$1) {
7536
7554
  /*
7537
7555
  * Copyright 2021-2022 the original author or authors.
7538
7556
  *
@@ -7563,8 +7581,8 @@ function requireErrors () {
7563
7581
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
7564
7582
  };
7565
7583
  })();
7566
- Object.defineProperty(exports, "__esModule", { value: true });
7567
- exports.ErrorCodes = exports.RSocketError = void 0;
7584
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7585
+ exports$1.ErrorCodes = exports$1.RSocketError = void 0;
7568
7586
  var RSocketError = /** @class */ (function (_super) {
7569
7587
  __extends(RSocketError, _super);
7570
7588
  function RSocketError(code, message) {
@@ -7574,7 +7592,7 @@ function requireErrors () {
7574
7592
  }
7575
7593
  return RSocketError;
7576
7594
  }(Error));
7577
- exports.RSocketError = RSocketError;
7595
+ exports$1.RSocketError = RSocketError;
7578
7596
  (function (ErrorCodes) {
7579
7597
  ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
7580
7598
  ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
@@ -7588,7 +7606,7 @@ function requireErrors () {
7588
7606
  ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
7589
7607
  ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
7590
7608
  ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
7591
- })(exports.ErrorCodes || (exports.ErrorCodes = {}));
7609
+ })(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
7592
7610
 
7593
7611
  } (Errors));
7594
7612
  return Errors;
@@ -7630,7 +7648,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
7630
7648
  function requireClientServerMultiplexerDemultiplexer () {
7631
7649
  if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
7632
7650
  hasRequiredClientServerMultiplexerDemultiplexer = 1;
7633
- (function (exports) {
7651
+ (function (exports$1) {
7634
7652
  /*
7635
7653
  * Copyright 2021-2022 the original author or authors.
7636
7654
  *
@@ -7697,8 +7715,8 @@ function requireClientServerMultiplexerDemultiplexer () {
7697
7715
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7698
7716
  }
7699
7717
  };
7700
- Object.defineProperty(exports, "__esModule", { value: true });
7701
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports.ResumableClientServerInputMultiplexerDemultiplexer = exports.ClientServerInputMultiplexerDemultiplexer = exports.StreamIdGenerator = void 0;
7718
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7719
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports$1.ResumableClientServerInputMultiplexerDemultiplexer = exports$1.ClientServerInputMultiplexerDemultiplexer = exports$1.StreamIdGenerator = void 0;
7702
7720
  var _1 = requireDist();
7703
7721
  var Deferred_1 = requireDeferred();
7704
7722
  var Errors_1 = requireErrors();
@@ -7721,7 +7739,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7721
7739
  };
7722
7740
  return StreamIdGeneratorImpl;
7723
7741
  }());
7724
- })(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
7742
+ })(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
7725
7743
  var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7726
7744
  __extends(ClientServerInputMultiplexerDemultiplexer, _super);
7727
7745
  function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
@@ -7810,7 +7828,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7810
7828
  };
7811
7829
  return ClientServerInputMultiplexerDemultiplexer;
7812
7830
  }(Deferred_1.Deferred));
7813
- exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
7831
+ exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
7814
7832
  var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7815
7833
  __extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
7816
7834
  function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
@@ -7967,7 +7985,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7967
7985
  };
7968
7986
  return ResumableClientServerInputMultiplexerDemultiplexer;
7969
7987
  }(ClientServerInputMultiplexerDemultiplexer));
7970
- exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
7988
+ exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
7971
7989
  var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
7972
7990
  function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
7973
7991
  this.outbound = outbound;
@@ -8024,7 +8042,7 @@ function requireClientServerMultiplexerDemultiplexer () {
8024
8042
  };
8025
8043
  return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8026
8044
  }());
8027
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8045
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8028
8046
 
8029
8047
  } (ClientServerMultiplexerDemultiplexer));
8030
8048
  return ClientServerMultiplexerDemultiplexer;
@@ -11010,7 +11028,7 @@ var hasRequiredDist;
11010
11028
  function requireDist () {
11011
11029
  if (hasRequiredDist) return dist;
11012
11030
  hasRequiredDist = 1;
11013
- (function (exports) {
11031
+ (function (exports$1) {
11014
11032
  /*
11015
11033
  * Copyright 2021-2022 the original author or authors.
11016
11034
  *
@@ -11033,19 +11051,19 @@ function requireDist () {
11033
11051
  if (k2 === undefined) k2 = k;
11034
11052
  o[k2] = m[k];
11035
11053
  }));
11036
- var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
11037
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11054
+ var __exportStar = (dist && dist.__exportStar) || function(m, exports$1) {
11055
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
11038
11056
  };
11039
- Object.defineProperty(exports, "__esModule", { value: true });
11040
- __exportStar(requireCodecs(), exports);
11041
- __exportStar(requireCommon(), exports);
11042
- __exportStar(requireDeferred(), exports);
11043
- __exportStar(requireErrors(), exports);
11044
- __exportStar(requireFrames(), exports);
11045
- __exportStar(requireRSocket(), exports);
11046
- __exportStar(requireRSocketConnector(), exports);
11047
- __exportStar(requireRSocketServer(), exports);
11048
- __exportStar(requireTransport(), exports);
11057
+ Object.defineProperty(exports$1, "__esModule", { value: true });
11058
+ __exportStar(requireCodecs(), exports$1);
11059
+ __exportStar(requireCommon(), exports$1);
11060
+ __exportStar(requireDeferred(), exports$1);
11061
+ __exportStar(requireErrors(), exports$1);
11062
+ __exportStar(requireFrames(), exports$1);
11063
+ __exportStar(requireRSocket(), exports$1);
11064
+ __exportStar(requireRSocketConnector(), exports$1);
11065
+ __exportStar(requireRSocketServer(), exports$1);
11066
+ __exportStar(requireTransport(), exports$1);
11049
11067
 
11050
11068
  } (dist));
11051
11069
  return dist;
@@ -11053,7 +11071,7 @@ function requireDist () {
11053
11071
 
11054
11072
  var distExports = requireDist();
11055
11073
 
11056
- var version = "1.43.1";
11074
+ var version = "1.45.0";
11057
11075
  var PACKAGE = {
11058
11076
  version: version};
11059
11077
 
@@ -11980,6 +11998,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
11980
11998
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
11981
11999
  };
11982
12000
  const DEFAULT_STREAM_CONNECTION_OPTIONS = {
12001
+ appMetadata: {},
11983
12002
  connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
11984
12003
  clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
11985
12004
  fetchStrategy: FetchStrategy.Buffered,
@@ -12358,6 +12377,11 @@ The next upload iteration will be delayed.`);
12358
12377
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
12359
12378
  ...(options ?? {})
12360
12379
  };
12380
+ // Validate app metadata
12381
+ const invalidMetadata = Object.entries(resolvedOptions.appMetadata).filter(([_, value]) => typeof value != 'string');
12382
+ if (invalidMetadata.length > 0) {
12383
+ throw new Error(`Invalid appMetadata provided. Only string values are allowed. Invalid values: ${invalidMetadata.map(([key, value]) => `${key}: ${value}`).join(', ')}`);
12384
+ }
12361
12385
  const clientImplementation = resolvedOptions.clientImplementation;
12362
12386
  this.updateSyncStatus({ clientImplementation });
12363
12387
  if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
@@ -12393,6 +12417,7 @@ The next upload iteration will be delayed.`);
12393
12417
  include_checksum: true,
12394
12418
  raw_data: true,
12395
12419
  parameters: resolvedOptions.params,
12420
+ app_metadata: resolvedOptions.appMetadata,
12396
12421
  client_id: clientId
12397
12422
  }
12398
12423
  };
@@ -12752,6 +12777,7 @@ The next upload iteration will be delayed.`);
12752
12777
  try {
12753
12778
  const options = {
12754
12779
  parameters: resolvedOptions.params,
12780
+ app_metadata: resolvedOptions.appMetadata,
12755
12781
  active_streams: this.activeStreams,
12756
12782
  include_defaults: resolvedOptions.includeDefaultStreams
12757
12783
  };
@@ -13410,11 +13436,11 @@ class AbstractPowerSyncDatabase extends BaseObserver {
13410
13436
  .map((n) => parseInt(n));
13411
13437
  }
13412
13438
  catch (e) {
13413
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
13439
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
13414
13440
  }
13415
- // Validate >=0.4.5 <1.0.0
13416
- if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 5)) {
13417
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}`);
13441
+ // Validate >=0.4.10 <1.0.0
13442
+ if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 10)) {
13443
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}`);
13418
13444
  }
13419
13445
  }
13420
13446
  async resolveOfflineSyncStatus() {
@@ -14534,6 +14560,27 @@ class SyncDataBatch {
14534
14560
  }
14535
14561
  }
14536
14562
 
14563
+ /**
14564
+ * Thrown when an underlying database connection is closed.
14565
+ * This is particularly relevant when worker connections are marked as closed while
14566
+ * operations are still in progress.
14567
+ */
14568
+ class ConnectionClosedError extends Error {
14569
+ static NAME = 'ConnectionClosedError';
14570
+ static MATCHES(input) {
14571
+ /**
14572
+ * If there are weird package issues which cause multiple versions of classes to be present, the instanceof
14573
+ * check might fail. This also performs a failsafe check.
14574
+ * This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
14575
+ */
14576
+ return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
14577
+ }
14578
+ constructor(message) {
14579
+ super(message);
14580
+ this.name = ConnectionClosedError.NAME;
14581
+ }
14582
+ }
14583
+
14537
14584
  // https://www.sqlite.org/lang_expr.html#castexpr
14538
14585
  var ColumnType;
14539
14586
  (function (ColumnType) {
@@ -15088,5 +15135,5 @@ const parseQuery = (query, parameters) => {
15088
15135
  return { sqlStatement, parameters: parameters };
15089
15136
  };
15090
15137
 
15091
- export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, Table, TableV2, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
15138
+ export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, Table, TableV2, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
15092
15139
  //# sourceMappingURL=bundle.mjs.map