@powersync/common 0.0.0-dev-20251203144301 → 0.0.0-dev-20260112083235

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 (33) hide show
  1. package/dist/bundle.cjs +116 -82
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +116 -83
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +104 -70
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +104 -71
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +25 -2
  10. package/lib/client/AbstractPowerSyncDatabase.d.ts +2 -2
  11. package/lib/client/AbstractPowerSyncDatabase.js +7 -7
  12. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  13. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +4 -0
  14. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +8 -0
  15. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  16. package/lib/client/sync/stream/streaming-sync-types.d.ts +4 -0
  17. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -1
  18. package/lib/db/ConnectionClosedError.d.ts +10 -0
  19. package/lib/db/ConnectionClosedError.js +21 -0
  20. package/lib/db/ConnectionClosedError.js.map +1 -0
  21. package/lib/db/crud/SyncStatus.d.ts +4 -0
  22. package/lib/db/crud/SyncStatus.js +4 -0
  23. package/lib/db/crud/SyncStatus.js.map +1 -1
  24. package/lib/index.d.ts +1 -0
  25. package/lib/index.js +1 -0
  26. package/lib/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/client/AbstractPowerSyncDatabase.ts +10 -10
  29. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +18 -0
  30. package/src/client/sync/stream/streaming-sync-types.ts +5 -0
  31. package/src/db/ConnectionClosedError.ts +23 -0
  32. package/src/db/crud/SyncStatus.ts +4 -0
  33. package/src/index.ts +1 -0
package/dist/bundle.mjs CHANGED
@@ -730,6 +730,10 @@ class SyncStatus {
730
730
  priorityStatusEntries: this.priorityStatusEntries
731
731
  };
732
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
+ */
733
737
  serializeError(error) {
734
738
  if (typeof error == 'undefined') {
735
739
  return undefined;
@@ -2352,7 +2356,7 @@ var hasRequiredBuffer$1;
2352
2356
  function requireBuffer$1 () {
2353
2357
  if (hasRequiredBuffer$1) return buffer$1;
2354
2358
  hasRequiredBuffer$1 = 1;
2355
- (function (exports) {
2359
+ (function (exports$1) {
2356
2360
 
2357
2361
  const base64 = requireBase64Js();
2358
2362
  const ieee754 = requireIeee754();
@@ -2361,12 +2365,12 @@ function requireBuffer$1 () {
2361
2365
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
2362
2366
  : null;
2363
2367
 
2364
- exports.Buffer = Buffer;
2365
- exports.SlowBuffer = SlowBuffer;
2366
- exports.INSPECT_MAX_BYTES = 50;
2368
+ exports$1.Buffer = Buffer;
2369
+ exports$1.SlowBuffer = SlowBuffer;
2370
+ exports$1.INSPECT_MAX_BYTES = 50;
2367
2371
 
2368
2372
  const K_MAX_LENGTH = 0x7fffffff;
2369
- exports.kMaxLength = K_MAX_LENGTH;
2373
+ exports$1.kMaxLength = K_MAX_LENGTH;
2370
2374
 
2371
2375
  /**
2372
2376
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -2962,7 +2966,7 @@ function requireBuffer$1 () {
2962
2966
 
2963
2967
  Buffer.prototype.inspect = function inspect () {
2964
2968
  let str = '';
2965
- const max = exports.INSPECT_MAX_BYTES;
2969
+ const max = exports$1.INSPECT_MAX_BYTES;
2966
2970
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
2967
2971
  if (this.length > max) str += ' ... ';
2968
2972
  return '<Buffer ' + str + '>'
@@ -4470,7 +4474,7 @@ var hasRequiredBuffer;
4470
4474
  function requireBuffer () {
4471
4475
  if (hasRequiredBuffer) return buffer;
4472
4476
  hasRequiredBuffer = 1;
4473
- (function (exports) {
4477
+ (function (exports$1) {
4474
4478
 
4475
4479
  var base64 = requireBase64Js();
4476
4480
  var ieee754 = requireIeee754();
@@ -4479,12 +4483,12 @@ function requireBuffer () {
4479
4483
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
4480
4484
  : null;
4481
4485
 
4482
- exports.Buffer = Buffer;
4483
- exports.SlowBuffer = SlowBuffer;
4484
- exports.INSPECT_MAX_BYTES = 50;
4486
+ exports$1.Buffer = Buffer;
4487
+ exports$1.SlowBuffer = SlowBuffer;
4488
+ exports$1.INSPECT_MAX_BYTES = 50;
4485
4489
 
4486
4490
  var K_MAX_LENGTH = 0x7fffffff;
4487
- exports.kMaxLength = K_MAX_LENGTH;
4491
+ exports$1.kMaxLength = K_MAX_LENGTH;
4488
4492
 
4489
4493
  /**
4490
4494
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -5081,7 +5085,7 @@ function requireBuffer () {
5081
5085
 
5082
5086
  Buffer.prototype.inspect = function inspect () {
5083
5087
  var str = '';
5084
- var max = exports.INSPECT_MAX_BYTES;
5088
+ var max = exports$1.INSPECT_MAX_BYTES;
5085
5089
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
5086
5090
  if (this.length > max) str += ' ... ';
5087
5091
  return '<Buffer ' + str + '>'
@@ -6294,7 +6298,7 @@ var hasRequiredFrames;
6294
6298
  function requireFrames () {
6295
6299
  if (hasRequiredFrames) return Frames;
6296
6300
  hasRequiredFrames = 1;
6297
- (function (exports) {
6301
+ (function (exports$1) {
6298
6302
  /*
6299
6303
  * Copyright 2021-2022 the original author or authors.
6300
6304
  *
@@ -6310,8 +6314,8 @@ function requireFrames () {
6310
6314
  * See the License for the specific language governing permissions and
6311
6315
  * limitations under the License.
6312
6316
  */
6313
- Object.defineProperty(exports, "__esModule", { value: true });
6314
- 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;
6315
6319
  var FrameTypes;
6316
6320
  (function (FrameTypes) {
6317
6321
  FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
@@ -6330,7 +6334,7 @@ function requireFrames () {
6330
6334
  FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
6331
6335
  FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
6332
6336
  FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
6333
- })(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
6337
+ })(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
6334
6338
  (function (Flags) {
6335
6339
  Flags[Flags["NONE"] = 0] = "NONE";
6336
6340
  Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
@@ -6341,7 +6345,7 @@ function requireFrames () {
6341
6345
  Flags[Flags["NEXT"] = 32] = "NEXT";
6342
6346
  Flags[Flags["RESPOND"] = 128] = "RESPOND";
6343
6347
  Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
6344
- })(exports.Flags || (exports.Flags = {}));
6348
+ })(exports$1.Flags || (exports$1.Flags = {}));
6345
6349
  (function (Flags) {
6346
6350
  function hasMetadata(flags) {
6347
6351
  return (flags & Flags.METADATA) === Flags.METADATA;
@@ -6375,13 +6379,13 @@ function requireFrames () {
6375
6379
  return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
6376
6380
  }
6377
6381
  Flags.hasResume = hasResume;
6378
- })(exports.Flags || (exports.Flags = {}));
6382
+ })(exports$1.Flags || (exports$1.Flags = {}));
6379
6383
  (function (Lengths) {
6380
6384
  Lengths[Lengths["FRAME"] = 3] = "FRAME";
6381
6385
  Lengths[Lengths["HEADER"] = 6] = "HEADER";
6382
6386
  Lengths[Lengths["METADATA"] = 3] = "METADATA";
6383
6387
  Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
6384
- })(exports.Lengths || (exports.Lengths = {}));
6388
+ })(exports$1.Lengths || (exports$1.Lengths = {}));
6385
6389
  (function (Frame) {
6386
6390
  function isConnection(frame) {
6387
6391
  return frame.streamId === 0;
@@ -6392,7 +6396,7 @@ function requireFrames () {
6392
6396
  frame.type <= FrameTypes.REQUEST_CHANNEL);
6393
6397
  }
6394
6398
  Frame.isRequest = isRequest;
6395
- })(exports.Frame || (exports.Frame = {}));
6399
+ })(exports$1.Frame || (exports$1.Frame = {}));
6396
6400
 
6397
6401
  } (Frames));
6398
6402
  return Frames;
@@ -6403,7 +6407,7 @@ var hasRequiredCodecs;
6403
6407
  function requireCodecs () {
6404
6408
  if (hasRequiredCodecs) return Codecs;
6405
6409
  hasRequiredCodecs = 1;
6406
- (function (exports) {
6410
+ (function (exports$1) {
6407
6411
  var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
6408
6412
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
6409
6413
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -6431,22 +6435,22 @@ function requireCodecs () {
6431
6435
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6432
6436
  }
6433
6437
  };
6434
- Object.defineProperty(exports, "__esModule", { value: true });
6435
- 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;
6436
6440
  var Frames_1 = requireFrames();
6437
- exports.FLAGS_MASK = 0x3ff; // low 10 bits
6438
- exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
6439
- exports.MAX_CODE = 0x7fffffff; // uint31
6440
- exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
6441
- exports.MAX_LIFETIME = 0x7fffffff; // uint31
6442
- exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
6443
- exports.MAX_MIME_LENGTH = 0xff; // int8
6444
- exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
6445
- exports.MAX_REQUEST_N = 0x7fffffff; // uint31
6446
- exports.MAX_RESUME_LENGTH = 0xffff; // uint16
6447
- exports.MAX_STREAM_ID = 0x7fffffff; // uint31
6448
- exports.MAX_TTL = 0x7fffffff; // uint31
6449
- 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
6450
6454
  /**
6451
6455
  * Mimimum value that would overflow bitwise operators (2^32).
6452
6456
  */
@@ -6460,7 +6464,7 @@ function requireCodecs () {
6460
6464
  var val3 = buffer.readUInt8(offset + 2);
6461
6465
  return val1 | val2 | val3;
6462
6466
  }
6463
- exports.readUInt24BE = readUInt24BE;
6467
+ exports$1.readUInt24BE = readUInt24BE;
6464
6468
  /**
6465
6469
  * Writes a uint24 to a buffer starting at the given offset, returning the
6466
6470
  * offset of the next byte.
@@ -6470,7 +6474,7 @@ function requireCodecs () {
6470
6474
  offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
6471
6475
  return buffer.writeUInt8(value & 0xff, offset); // 1st byte
6472
6476
  }
6473
- exports.writeUInt24BE = writeUInt24BE;
6477
+ exports$1.writeUInt24BE = writeUInt24BE;
6474
6478
  /**
6475
6479
  * Read a uint64 (technically supports up to 53 bits per JS number
6476
6480
  * representation).
@@ -6480,7 +6484,7 @@ function requireCodecs () {
6480
6484
  var low = buffer.readUInt32BE(offset + 4);
6481
6485
  return high * BITWISE_OVERFLOW + low;
6482
6486
  }
6483
- exports.readUInt64BE = readUInt64BE;
6487
+ exports$1.readUInt64BE = readUInt64BE;
6484
6488
  /**
6485
6489
  * Write a uint64 (technically supports up to 53 bits per JS number
6486
6490
  * representation).
@@ -6491,7 +6495,7 @@ function requireCodecs () {
6491
6495
  offset = buffer.writeUInt32BE(high, offset); // first half of uint64
6492
6496
  return buffer.writeUInt32BE(low, offset); // second half of uint64
6493
6497
  }
6494
- exports.writeUInt64BE = writeUInt64BE;
6498
+ exports$1.writeUInt64BE = writeUInt64BE;
6495
6499
  /**
6496
6500
  * Frame header is:
6497
6501
  * - stream id (uint32 = 4)
@@ -6509,7 +6513,7 @@ function requireCodecs () {
6509
6513
  var frameLength = readUInt24BE(buffer, 0);
6510
6514
  return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
6511
6515
  }
6512
- exports.deserializeFrameWithLength = deserializeFrameWithLength;
6516
+ exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
6513
6517
  /**
6514
6518
  * Given a buffer that may contain zero or more length-prefixed frames followed
6515
6519
  * by zero or more bytes of a (partial) subsequent frame, returns an array of
@@ -6542,7 +6546,7 @@ function requireCodecs () {
6542
6546
  }
6543
6547
  });
6544
6548
  }
6545
- exports.deserializeFrames = deserializeFrames;
6549
+ exports$1.deserializeFrames = deserializeFrames;
6546
6550
  /**
6547
6551
  * Writes a frame to a buffer with a length prefix.
6548
6552
  */
@@ -6553,7 +6557,7 @@ function requireCodecs () {
6553
6557
  buffer.copy(lengthPrefixed, UINT24_SIZE);
6554
6558
  return lengthPrefixed;
6555
6559
  }
6556
- exports.serializeFrameWithLength = serializeFrameWithLength;
6560
+ exports$1.serializeFrameWithLength = serializeFrameWithLength;
6557
6561
  /**
6558
6562
  * Read a frame from the buffer.
6559
6563
  */
@@ -6568,8 +6572,8 @@ function requireCodecs () {
6568
6572
  // );
6569
6573
  var typeAndFlags = buffer.readUInt16BE(offset);
6570
6574
  offset += 2;
6571
- var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
6572
- 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
6573
6577
  switch (type) {
6574
6578
  case Frames_1.FrameTypes.SETUP:
6575
6579
  return deserializeSetupFrame(buffer, streamId, flags);
@@ -6606,7 +6610,7 @@ function requireCodecs () {
6606
6610
  // );
6607
6611
  }
6608
6612
  }
6609
- exports.deserializeFrame = deserializeFrame;
6613
+ exports$1.deserializeFrame = deserializeFrame;
6610
6614
  /**
6611
6615
  * Convert the frame to a (binary) buffer.
6612
6616
  */
@@ -6645,7 +6649,7 @@ function requireCodecs () {
6645
6649
  // );
6646
6650
  }
6647
6651
  }
6648
- exports.serializeFrame = serializeFrame;
6652
+ exports$1.serializeFrame = serializeFrame;
6649
6653
  /**
6650
6654
  * Byte size of frame without size prefix
6651
6655
  */
@@ -6684,7 +6688,7 @@ function requireCodecs () {
6684
6688
  // );
6685
6689
  }
6686
6690
  }
6687
- exports.sizeOfFrame = sizeOfFrame;
6691
+ exports$1.sizeOfFrame = sizeOfFrame;
6688
6692
  /**
6689
6693
  * Writes a SETUP frame into a new buffer and returns it.
6690
6694
  *
@@ -7319,7 +7323,7 @@ function requireCodecs () {
7319
7323
  function writeHeader(frame, buffer) {
7320
7324
  var offset = buffer.writeInt32BE(frame.streamId, 0);
7321
7325
  // shift frame to high 6 bits, extract lowest 10 bits from flags
7322
- 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);
7323
7327
  }
7324
7328
  /**
7325
7329
  * Determine the length of the payload section of a frame. Only applies to
@@ -7400,7 +7404,7 @@ function requireCodecs () {
7400
7404
  };
7401
7405
  return Deserializer;
7402
7406
  }());
7403
- exports.Deserializer = Deserializer;
7407
+ exports$1.Deserializer = Deserializer;
7404
7408
 
7405
7409
  } (Codecs));
7406
7410
  return Codecs;
@@ -7546,7 +7550,7 @@ var hasRequiredErrors;
7546
7550
  function requireErrors () {
7547
7551
  if (hasRequiredErrors) return Errors;
7548
7552
  hasRequiredErrors = 1;
7549
- (function (exports) {
7553
+ (function (exports$1) {
7550
7554
  /*
7551
7555
  * Copyright 2021-2022 the original author or authors.
7552
7556
  *
@@ -7577,8 +7581,8 @@ function requireErrors () {
7577
7581
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
7578
7582
  };
7579
7583
  })();
7580
- Object.defineProperty(exports, "__esModule", { value: true });
7581
- exports.ErrorCodes = exports.RSocketError = void 0;
7584
+ Object.defineProperty(exports$1, "__esModule", { value: true });
7585
+ exports$1.ErrorCodes = exports$1.RSocketError = void 0;
7582
7586
  var RSocketError = /** @class */ (function (_super) {
7583
7587
  __extends(RSocketError, _super);
7584
7588
  function RSocketError(code, message) {
@@ -7588,7 +7592,7 @@ function requireErrors () {
7588
7592
  }
7589
7593
  return RSocketError;
7590
7594
  }(Error));
7591
- exports.RSocketError = RSocketError;
7595
+ exports$1.RSocketError = RSocketError;
7592
7596
  (function (ErrorCodes) {
7593
7597
  ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
7594
7598
  ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
@@ -7602,7 +7606,7 @@ function requireErrors () {
7602
7606
  ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
7603
7607
  ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
7604
7608
  ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
7605
- })(exports.ErrorCodes || (exports.ErrorCodes = {}));
7609
+ })(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
7606
7610
 
7607
7611
  } (Errors));
7608
7612
  return Errors;
@@ -7644,7 +7648,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
7644
7648
  function requireClientServerMultiplexerDemultiplexer () {
7645
7649
  if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
7646
7650
  hasRequiredClientServerMultiplexerDemultiplexer = 1;
7647
- (function (exports) {
7651
+ (function (exports$1) {
7648
7652
  /*
7649
7653
  * Copyright 2021-2022 the original author or authors.
7650
7654
  *
@@ -7711,8 +7715,8 @@ function requireClientServerMultiplexerDemultiplexer () {
7711
7715
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7712
7716
  }
7713
7717
  };
7714
- Object.defineProperty(exports, "__esModule", { value: true });
7715
- 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;
7716
7720
  var _1 = requireDist();
7717
7721
  var Deferred_1 = requireDeferred();
7718
7722
  var Errors_1 = requireErrors();
@@ -7735,7 +7739,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7735
7739
  };
7736
7740
  return StreamIdGeneratorImpl;
7737
7741
  }());
7738
- })(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
7742
+ })(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
7739
7743
  var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7740
7744
  __extends(ClientServerInputMultiplexerDemultiplexer, _super);
7741
7745
  function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
@@ -7824,7 +7828,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7824
7828
  };
7825
7829
  return ClientServerInputMultiplexerDemultiplexer;
7826
7830
  }(Deferred_1.Deferred));
7827
- exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
7831
+ exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
7828
7832
  var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7829
7833
  __extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
7830
7834
  function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
@@ -7981,7 +7985,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7981
7985
  };
7982
7986
  return ResumableClientServerInputMultiplexerDemultiplexer;
7983
7987
  }(ClientServerInputMultiplexerDemultiplexer));
7984
- exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
7988
+ exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
7985
7989
  var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
7986
7990
  function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
7987
7991
  this.outbound = outbound;
@@ -8038,7 +8042,7 @@ function requireClientServerMultiplexerDemultiplexer () {
8038
8042
  };
8039
8043
  return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8040
8044
  }());
8041
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8045
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8042
8046
 
8043
8047
  } (ClientServerMultiplexerDemultiplexer));
8044
8048
  return ClientServerMultiplexerDemultiplexer;
@@ -11024,7 +11028,7 @@ var hasRequiredDist;
11024
11028
  function requireDist () {
11025
11029
  if (hasRequiredDist) return dist;
11026
11030
  hasRequiredDist = 1;
11027
- (function (exports) {
11031
+ (function (exports$1) {
11028
11032
  /*
11029
11033
  * Copyright 2021-2022 the original author or authors.
11030
11034
  *
@@ -11047,19 +11051,19 @@ function requireDist () {
11047
11051
  if (k2 === undefined) k2 = k;
11048
11052
  o[k2] = m[k];
11049
11053
  }));
11050
- var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
11051
- 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);
11052
11056
  };
11053
- Object.defineProperty(exports, "__esModule", { value: true });
11054
- __exportStar(requireCodecs(), exports);
11055
- __exportStar(requireCommon(), exports);
11056
- __exportStar(requireDeferred(), exports);
11057
- __exportStar(requireErrors(), exports);
11058
- __exportStar(requireFrames(), exports);
11059
- __exportStar(requireRSocket(), exports);
11060
- __exportStar(requireRSocketConnector(), exports);
11061
- __exportStar(requireRSocketServer(), exports);
11062
- __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);
11063
11067
 
11064
11068
  } (dist));
11065
11069
  return dist;
@@ -11067,7 +11071,7 @@ function requireDist () {
11067
11071
 
11068
11072
  var distExports = requireDist();
11069
11073
 
11070
- var version = "1.43.1";
11074
+ var version = "1.45.0";
11071
11075
  var PACKAGE = {
11072
11076
  version: version};
11073
11077
 
@@ -11994,6 +11998,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
11994
11998
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
11995
11999
  };
11996
12000
  const DEFAULT_STREAM_CONNECTION_OPTIONS = {
12001
+ appMetadata: {},
11997
12002
  connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
11998
12003
  clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
11999
12004
  fetchStrategy: FetchStrategy.Buffered,
@@ -12372,6 +12377,11 @@ The next upload iteration will be delayed.`);
12372
12377
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
12373
12378
  ...(options ?? {})
12374
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
+ }
12375
12385
  const clientImplementation = resolvedOptions.clientImplementation;
12376
12386
  this.updateSyncStatus({ clientImplementation });
12377
12387
  if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
@@ -12407,6 +12417,7 @@ The next upload iteration will be delayed.`);
12407
12417
  include_checksum: true,
12408
12418
  raw_data: true,
12409
12419
  parameters: resolvedOptions.params,
12420
+ app_metadata: resolvedOptions.appMetadata,
12410
12421
  client_id: clientId
12411
12422
  }
12412
12423
  };
@@ -12766,6 +12777,7 @@ The next upload iteration will be delayed.`);
12766
12777
  try {
12767
12778
  const options = {
12768
12779
  parameters: resolvedOptions.params,
12780
+ app_metadata: resolvedOptions.appMetadata,
12769
12781
  active_streams: this.activeStreams,
12770
12782
  include_defaults: resolvedOptions.includeDefaultStreams
12771
12783
  };
@@ -13402,14 +13414,14 @@ class AbstractPowerSyncDatabase extends BaseObserver {
13402
13414
  async initialize() {
13403
13415
  await this._initialize();
13404
13416
  await this.bucketStorageAdapter.init();
13405
- await this._loadVersion();
13417
+ await this.loadVersion();
13406
13418
  await this.updateSchema(this.options.schema);
13407
13419
  await this.resolveOfflineSyncStatus();
13408
13420
  await this.database.execute('PRAGMA RECURSIVE_TRIGGERS=TRUE');
13409
13421
  this.ready = true;
13410
13422
  this.iterateListeners((cb) => cb.initialized?.());
13411
13423
  }
13412
- async _loadVersion() {
13424
+ async loadVersion() {
13413
13425
  try {
13414
13426
  const { version } = await this.database.get('SELECT powersync_rs_version() as version');
13415
13427
  this.sdkVersion = version;
@@ -13424,11 +13436,11 @@ class AbstractPowerSyncDatabase extends BaseObserver {
13424
13436
  .map((n) => parseInt(n));
13425
13437
  }
13426
13438
  catch (e) {
13427
- 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}`);
13428
13440
  }
13429
- // Validate >=0.4.5 <1.0.0
13430
- if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 5)) {
13431
- 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}`);
13432
13444
  }
13433
13445
  }
13434
13446
  async resolveOfflineSyncStatus() {
@@ -14548,6 +14560,27 @@ class SyncDataBatch {
14548
14560
  }
14549
14561
  }
14550
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
+
14551
14584
  // https://www.sqlite.org/lang_expr.html#castexpr
14552
14585
  var ColumnType;
14553
14586
  (function (ColumnType) {
@@ -15102,5 +15135,5 @@ const parseQuery = (query, parameters) => {
15102
15135
  return { sqlStatement, parameters: parameters };
15103
15136
  };
15104
15137
 
15105
- 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 };
15106
15139
  //# sourceMappingURL=bundle.mjs.map