@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
@@ -569,12 +569,30 @@ class SyncStatus {
569
569
  return {
570
570
  connected: this.connected,
571
571
  connecting: this.connecting,
572
- dataFlow: this.dataFlowStatus,
572
+ dataFlow: {
573
+ ...this.dataFlowStatus,
574
+ uploadError: this.serializeError(this.dataFlowStatus.uploadError),
575
+ downloadError: this.serializeError(this.dataFlowStatus.downloadError)
576
+ },
573
577
  lastSyncedAt: this.lastSyncedAt,
574
578
  hasSynced: this.hasSynced,
575
579
  priorityStatusEntries: this.priorityStatusEntries
576
580
  };
577
581
  }
582
+ /**
583
+ * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
584
+ * This explicitly serializes errors in the SyncStatus.
585
+ */
586
+ serializeError(error) {
587
+ if (typeof error == 'undefined') {
588
+ return undefined;
589
+ }
590
+ return {
591
+ name: error.name,
592
+ message: error.message,
593
+ stack: error.stack
594
+ };
595
+ }
578
596
  static comparePriorities(a, b) {
579
597
  return b.priority - a.priority; // Reverse because higher priorities have lower numbers
580
598
  }
@@ -1929,7 +1947,7 @@ var hasRequiredFrames;
1929
1947
  function requireFrames () {
1930
1948
  if (hasRequiredFrames) return Frames;
1931
1949
  hasRequiredFrames = 1;
1932
- (function (exports) {
1950
+ (function (exports$1) {
1933
1951
  /*
1934
1952
  * Copyright 2021-2022 the original author or authors.
1935
1953
  *
@@ -1945,8 +1963,8 @@ function requireFrames () {
1945
1963
  * See the License for the specific language governing permissions and
1946
1964
  * limitations under the License.
1947
1965
  */
1948
- Object.defineProperty(exports, "__esModule", { value: true });
1949
- exports.Frame = exports.Lengths = exports.Flags = exports.FrameTypes = void 0;
1966
+ Object.defineProperty(exports$1, "__esModule", { value: true });
1967
+ exports$1.Frame = exports$1.Lengths = exports$1.Flags = exports$1.FrameTypes = void 0;
1950
1968
  var FrameTypes;
1951
1969
  (function (FrameTypes) {
1952
1970
  FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
@@ -1965,7 +1983,7 @@ function requireFrames () {
1965
1983
  FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
1966
1984
  FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
1967
1985
  FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
1968
- })(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
1986
+ })(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
1969
1987
  (function (Flags) {
1970
1988
  Flags[Flags["NONE"] = 0] = "NONE";
1971
1989
  Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
@@ -1976,7 +1994,7 @@ function requireFrames () {
1976
1994
  Flags[Flags["NEXT"] = 32] = "NEXT";
1977
1995
  Flags[Flags["RESPOND"] = 128] = "RESPOND";
1978
1996
  Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
1979
- })(exports.Flags || (exports.Flags = {}));
1997
+ })(exports$1.Flags || (exports$1.Flags = {}));
1980
1998
  (function (Flags) {
1981
1999
  function hasMetadata(flags) {
1982
2000
  return (flags & Flags.METADATA) === Flags.METADATA;
@@ -2010,13 +2028,13 @@ function requireFrames () {
2010
2028
  return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
2011
2029
  }
2012
2030
  Flags.hasResume = hasResume;
2013
- })(exports.Flags || (exports.Flags = {}));
2031
+ })(exports$1.Flags || (exports$1.Flags = {}));
2014
2032
  (function (Lengths) {
2015
2033
  Lengths[Lengths["FRAME"] = 3] = "FRAME";
2016
2034
  Lengths[Lengths["HEADER"] = 6] = "HEADER";
2017
2035
  Lengths[Lengths["METADATA"] = 3] = "METADATA";
2018
2036
  Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
2019
- })(exports.Lengths || (exports.Lengths = {}));
2037
+ })(exports$1.Lengths || (exports$1.Lengths = {}));
2020
2038
  (function (Frame) {
2021
2039
  function isConnection(frame) {
2022
2040
  return frame.streamId === 0;
@@ -2027,7 +2045,7 @@ function requireFrames () {
2027
2045
  frame.type <= FrameTypes.REQUEST_CHANNEL);
2028
2046
  }
2029
2047
  Frame.isRequest = isRequest;
2030
- })(exports.Frame || (exports.Frame = {}));
2048
+ })(exports$1.Frame || (exports$1.Frame = {}));
2031
2049
 
2032
2050
  } (Frames));
2033
2051
  return Frames;
@@ -2038,7 +2056,7 @@ var hasRequiredCodecs;
2038
2056
  function requireCodecs () {
2039
2057
  if (hasRequiredCodecs) return Codecs;
2040
2058
  hasRequiredCodecs = 1;
2041
- (function (exports) {
2059
+ (function (exports$1) {
2042
2060
  var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
2043
2061
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2044
2062
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -2066,22 +2084,22 @@ function requireCodecs () {
2066
2084
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2067
2085
  }
2068
2086
  };
2069
- Object.defineProperty(exports, "__esModule", { value: true });
2070
- 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;
2087
+ Object.defineProperty(exports$1, "__esModule", { value: true });
2088
+ 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;
2071
2089
  var Frames_1 = requireFrames();
2072
- exports.FLAGS_MASK = 0x3ff; // low 10 bits
2073
- exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
2074
- exports.MAX_CODE = 0x7fffffff; // uint31
2075
- exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
2076
- exports.MAX_LIFETIME = 0x7fffffff; // uint31
2077
- exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
2078
- exports.MAX_MIME_LENGTH = 0xff; // int8
2079
- exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
2080
- exports.MAX_REQUEST_N = 0x7fffffff; // uint31
2081
- exports.MAX_RESUME_LENGTH = 0xffff; // uint16
2082
- exports.MAX_STREAM_ID = 0x7fffffff; // uint31
2083
- exports.MAX_TTL = 0x7fffffff; // uint31
2084
- exports.MAX_VERSION = 0xffff; // uint16
2090
+ exports$1.FLAGS_MASK = 0x3ff; // low 10 bits
2091
+ exports$1.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
2092
+ exports$1.MAX_CODE = 0x7fffffff; // uint31
2093
+ exports$1.MAX_KEEPALIVE = 0x7fffffff; // uint31
2094
+ exports$1.MAX_LIFETIME = 0x7fffffff; // uint31
2095
+ exports$1.MAX_METADATA_LENGTH = 0xffffff; // uint24
2096
+ exports$1.MAX_MIME_LENGTH = 0xff; // int8
2097
+ exports$1.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
2098
+ exports$1.MAX_REQUEST_N = 0x7fffffff; // uint31
2099
+ exports$1.MAX_RESUME_LENGTH = 0xffff; // uint16
2100
+ exports$1.MAX_STREAM_ID = 0x7fffffff; // uint31
2101
+ exports$1.MAX_TTL = 0x7fffffff; // uint31
2102
+ exports$1.MAX_VERSION = 0xffff; // uint16
2085
2103
  /**
2086
2104
  * Mimimum value that would overflow bitwise operators (2^32).
2087
2105
  */
@@ -2095,7 +2113,7 @@ function requireCodecs () {
2095
2113
  var val3 = buffer.readUInt8(offset + 2);
2096
2114
  return val1 | val2 | val3;
2097
2115
  }
2098
- exports.readUInt24BE = readUInt24BE;
2116
+ exports$1.readUInt24BE = readUInt24BE;
2099
2117
  /**
2100
2118
  * Writes a uint24 to a buffer starting at the given offset, returning the
2101
2119
  * offset of the next byte.
@@ -2105,7 +2123,7 @@ function requireCodecs () {
2105
2123
  offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
2106
2124
  return buffer.writeUInt8(value & 0xff, offset); // 1st byte
2107
2125
  }
2108
- exports.writeUInt24BE = writeUInt24BE;
2126
+ exports$1.writeUInt24BE = writeUInt24BE;
2109
2127
  /**
2110
2128
  * Read a uint64 (technically supports up to 53 bits per JS number
2111
2129
  * representation).
@@ -2115,7 +2133,7 @@ function requireCodecs () {
2115
2133
  var low = buffer.readUInt32BE(offset + 4);
2116
2134
  return high * BITWISE_OVERFLOW + low;
2117
2135
  }
2118
- exports.readUInt64BE = readUInt64BE;
2136
+ exports$1.readUInt64BE = readUInt64BE;
2119
2137
  /**
2120
2138
  * Write a uint64 (technically supports up to 53 bits per JS number
2121
2139
  * representation).
@@ -2126,7 +2144,7 @@ function requireCodecs () {
2126
2144
  offset = buffer.writeUInt32BE(high, offset); // first half of uint64
2127
2145
  return buffer.writeUInt32BE(low, offset); // second half of uint64
2128
2146
  }
2129
- exports.writeUInt64BE = writeUInt64BE;
2147
+ exports$1.writeUInt64BE = writeUInt64BE;
2130
2148
  /**
2131
2149
  * Frame header is:
2132
2150
  * - stream id (uint32 = 4)
@@ -2144,7 +2162,7 @@ function requireCodecs () {
2144
2162
  var frameLength = readUInt24BE(buffer, 0);
2145
2163
  return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
2146
2164
  }
2147
- exports.deserializeFrameWithLength = deserializeFrameWithLength;
2165
+ exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
2148
2166
  /**
2149
2167
  * Given a buffer that may contain zero or more length-prefixed frames followed
2150
2168
  * by zero or more bytes of a (partial) subsequent frame, returns an array of
@@ -2177,7 +2195,7 @@ function requireCodecs () {
2177
2195
  }
2178
2196
  });
2179
2197
  }
2180
- exports.deserializeFrames = deserializeFrames;
2198
+ exports$1.deserializeFrames = deserializeFrames;
2181
2199
  /**
2182
2200
  * Writes a frame to a buffer with a length prefix.
2183
2201
  */
@@ -2188,7 +2206,7 @@ function requireCodecs () {
2188
2206
  buffer.copy(lengthPrefixed, UINT24_SIZE);
2189
2207
  return lengthPrefixed;
2190
2208
  }
2191
- exports.serializeFrameWithLength = serializeFrameWithLength;
2209
+ exports$1.serializeFrameWithLength = serializeFrameWithLength;
2192
2210
  /**
2193
2211
  * Read a frame from the buffer.
2194
2212
  */
@@ -2203,8 +2221,8 @@ function requireCodecs () {
2203
2221
  // );
2204
2222
  var typeAndFlags = buffer.readUInt16BE(offset);
2205
2223
  offset += 2;
2206
- var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
2207
- var flags = typeAndFlags & exports.FLAGS_MASK; // keep lowest 10 bits
2224
+ var type = typeAndFlags >>> exports$1.FRAME_TYPE_OFFFSET; // keep highest 6 bits
2225
+ var flags = typeAndFlags & exports$1.FLAGS_MASK; // keep lowest 10 bits
2208
2226
  switch (type) {
2209
2227
  case Frames_1.FrameTypes.SETUP:
2210
2228
  return deserializeSetupFrame(buffer, streamId, flags);
@@ -2241,7 +2259,7 @@ function requireCodecs () {
2241
2259
  // );
2242
2260
  }
2243
2261
  }
2244
- exports.deserializeFrame = deserializeFrame;
2262
+ exports$1.deserializeFrame = deserializeFrame;
2245
2263
  /**
2246
2264
  * Convert the frame to a (binary) buffer.
2247
2265
  */
@@ -2280,7 +2298,7 @@ function requireCodecs () {
2280
2298
  // );
2281
2299
  }
2282
2300
  }
2283
- exports.serializeFrame = serializeFrame;
2301
+ exports$1.serializeFrame = serializeFrame;
2284
2302
  /**
2285
2303
  * Byte size of frame without size prefix
2286
2304
  */
@@ -2319,7 +2337,7 @@ function requireCodecs () {
2319
2337
  // );
2320
2338
  }
2321
2339
  }
2322
- exports.sizeOfFrame = sizeOfFrame;
2340
+ exports$1.sizeOfFrame = sizeOfFrame;
2323
2341
  /**
2324
2342
  * Writes a SETUP frame into a new buffer and returns it.
2325
2343
  *
@@ -2954,7 +2972,7 @@ function requireCodecs () {
2954
2972
  function writeHeader(frame, buffer) {
2955
2973
  var offset = buffer.writeInt32BE(frame.streamId, 0);
2956
2974
  // shift frame to high 6 bits, extract lowest 10 bits from flags
2957
- return buffer.writeUInt16BE((frame.type << exports.FRAME_TYPE_OFFFSET) | (frame.flags & exports.FLAGS_MASK), offset);
2975
+ return buffer.writeUInt16BE((frame.type << exports$1.FRAME_TYPE_OFFFSET) | (frame.flags & exports$1.FLAGS_MASK), offset);
2958
2976
  }
2959
2977
  /**
2960
2978
  * Determine the length of the payload section of a frame. Only applies to
@@ -3035,7 +3053,7 @@ function requireCodecs () {
3035
3053
  };
3036
3054
  return Deserializer;
3037
3055
  }());
3038
- exports.Deserializer = Deserializer;
3056
+ exports$1.Deserializer = Deserializer;
3039
3057
 
3040
3058
  } (Codecs));
3041
3059
  return Codecs;
@@ -3181,7 +3199,7 @@ var hasRequiredErrors;
3181
3199
  function requireErrors () {
3182
3200
  if (hasRequiredErrors) return Errors;
3183
3201
  hasRequiredErrors = 1;
3184
- (function (exports) {
3202
+ (function (exports$1) {
3185
3203
  /*
3186
3204
  * Copyright 2021-2022 the original author or authors.
3187
3205
  *
@@ -3212,8 +3230,8 @@ function requireErrors () {
3212
3230
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3213
3231
  };
3214
3232
  })();
3215
- Object.defineProperty(exports, "__esModule", { value: true });
3216
- exports.ErrorCodes = exports.RSocketError = void 0;
3233
+ Object.defineProperty(exports$1, "__esModule", { value: true });
3234
+ exports$1.ErrorCodes = exports$1.RSocketError = void 0;
3217
3235
  var RSocketError = /** @class */ (function (_super) {
3218
3236
  __extends(RSocketError, _super);
3219
3237
  function RSocketError(code, message) {
@@ -3223,7 +3241,7 @@ function requireErrors () {
3223
3241
  }
3224
3242
  return RSocketError;
3225
3243
  }(Error));
3226
- exports.RSocketError = RSocketError;
3244
+ exports$1.RSocketError = RSocketError;
3227
3245
  (function (ErrorCodes) {
3228
3246
  ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
3229
3247
  ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
@@ -3237,7 +3255,7 @@ function requireErrors () {
3237
3255
  ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
3238
3256
  ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
3239
3257
  ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
3240
- })(exports.ErrorCodes || (exports.ErrorCodes = {}));
3258
+ })(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
3241
3259
 
3242
3260
  } (Errors));
3243
3261
  return Errors;
@@ -3279,7 +3297,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
3279
3297
  function requireClientServerMultiplexerDemultiplexer () {
3280
3298
  if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
3281
3299
  hasRequiredClientServerMultiplexerDemultiplexer = 1;
3282
- (function (exports) {
3300
+ (function (exports$1) {
3283
3301
  /*
3284
3302
  * Copyright 2021-2022 the original author or authors.
3285
3303
  *
@@ -3346,8 +3364,8 @@ function requireClientServerMultiplexerDemultiplexer () {
3346
3364
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3347
3365
  }
3348
3366
  };
3349
- Object.defineProperty(exports, "__esModule", { value: true });
3350
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports.ResumableClientServerInputMultiplexerDemultiplexer = exports.ClientServerInputMultiplexerDemultiplexer = exports.StreamIdGenerator = void 0;
3367
+ Object.defineProperty(exports$1, "__esModule", { value: true });
3368
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports$1.ResumableClientServerInputMultiplexerDemultiplexer = exports$1.ClientServerInputMultiplexerDemultiplexer = exports$1.StreamIdGenerator = void 0;
3351
3369
  var _1 = requireDist();
3352
3370
  var Deferred_1 = requireDeferred();
3353
3371
  var Errors_1 = requireErrors();
@@ -3370,7 +3388,7 @@ function requireClientServerMultiplexerDemultiplexer () {
3370
3388
  };
3371
3389
  return StreamIdGeneratorImpl;
3372
3390
  }());
3373
- })(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
3391
+ })(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
3374
3392
  var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
3375
3393
  __extends(ClientServerInputMultiplexerDemultiplexer, _super);
3376
3394
  function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
@@ -3459,7 +3477,7 @@ function requireClientServerMultiplexerDemultiplexer () {
3459
3477
  };
3460
3478
  return ClientServerInputMultiplexerDemultiplexer;
3461
3479
  }(Deferred_1.Deferred));
3462
- exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
3480
+ exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
3463
3481
  var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
3464
3482
  __extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
3465
3483
  function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
@@ -3616,7 +3634,7 @@ function requireClientServerMultiplexerDemultiplexer () {
3616
3634
  };
3617
3635
  return ResumableClientServerInputMultiplexerDemultiplexer;
3618
3636
  }(ClientServerInputMultiplexerDemultiplexer));
3619
- exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
3637
+ exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
3620
3638
  var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
3621
3639
  function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
3622
3640
  this.outbound = outbound;
@@ -3673,7 +3691,7 @@ function requireClientServerMultiplexerDemultiplexer () {
3673
3691
  };
3674
3692
  return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
3675
3693
  }());
3676
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
3694
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
3677
3695
 
3678
3696
  } (ClientServerMultiplexerDemultiplexer));
3679
3697
  return ClientServerMultiplexerDemultiplexer;
@@ -6659,7 +6677,7 @@ var hasRequiredDist;
6659
6677
  function requireDist () {
6660
6678
  if (hasRequiredDist) return dist;
6661
6679
  hasRequiredDist = 1;
6662
- (function (exports) {
6680
+ (function (exports$1) {
6663
6681
  /*
6664
6682
  * Copyright 2021-2022 the original author or authors.
6665
6683
  *
@@ -6682,19 +6700,19 @@ function requireDist () {
6682
6700
  if (k2 === undefined) k2 = k;
6683
6701
  o[k2] = m[k];
6684
6702
  }));
6685
- var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
6686
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
6703
+ var __exportStar = (dist && dist.__exportStar) || function(m, exports$1) {
6704
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
6687
6705
  };
6688
- Object.defineProperty(exports, "__esModule", { value: true });
6689
- __exportStar(requireCodecs(), exports);
6690
- __exportStar(requireCommon(), exports);
6691
- __exportStar(requireDeferred(), exports);
6692
- __exportStar(requireErrors(), exports);
6693
- __exportStar(requireFrames(), exports);
6694
- __exportStar(requireRSocket(), exports);
6695
- __exportStar(requireRSocketConnector(), exports);
6696
- __exportStar(requireRSocketServer(), exports);
6697
- __exportStar(requireTransport(), exports);
6706
+ Object.defineProperty(exports$1, "__esModule", { value: true });
6707
+ __exportStar(requireCodecs(), exports$1);
6708
+ __exportStar(requireCommon(), exports$1);
6709
+ __exportStar(requireDeferred(), exports$1);
6710
+ __exportStar(requireErrors(), exports$1);
6711
+ __exportStar(requireFrames(), exports$1);
6712
+ __exportStar(requireRSocket(), exports$1);
6713
+ __exportStar(requireRSocketConnector(), exports$1);
6714
+ __exportStar(requireRSocketServer(), exports$1);
6715
+ __exportStar(requireTransport(), exports$1);
6698
6716
 
6699
6717
  } (dist));
6700
6718
  return dist;
@@ -6702,7 +6720,7 @@ function requireDist () {
6702
6720
 
6703
6721
  var distExports = requireDist();
6704
6722
 
6705
- var version = "1.43.1";
6723
+ var version = "1.45.0";
6706
6724
  var PACKAGE = {
6707
6725
  version: version};
6708
6726
 
@@ -7629,6 +7647,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
7629
7647
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
7630
7648
  };
7631
7649
  const DEFAULT_STREAM_CONNECTION_OPTIONS = {
7650
+ appMetadata: {},
7632
7651
  connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
7633
7652
  clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
7634
7653
  fetchStrategy: FetchStrategy.Buffered,
@@ -8007,6 +8026,11 @@ The next upload iteration will be delayed.`);
8007
8026
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
8008
8027
  ...(options ?? {})
8009
8028
  };
8029
+ // Validate app metadata
8030
+ const invalidMetadata = Object.entries(resolvedOptions.appMetadata).filter(([_, value]) => typeof value != 'string');
8031
+ if (invalidMetadata.length > 0) {
8032
+ throw new Error(`Invalid appMetadata provided. Only string values are allowed. Invalid values: ${invalidMetadata.map(([key, value]) => `${key}: ${value}`).join(', ')}`);
8033
+ }
8010
8034
  const clientImplementation = resolvedOptions.clientImplementation;
8011
8035
  this.updateSyncStatus({ clientImplementation });
8012
8036
  if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
@@ -8042,6 +8066,7 @@ The next upload iteration will be delayed.`);
8042
8066
  include_checksum: true,
8043
8067
  raw_data: true,
8044
8068
  parameters: resolvedOptions.params,
8069
+ app_metadata: resolvedOptions.appMetadata,
8045
8070
  client_id: clientId
8046
8071
  }
8047
8072
  };
@@ -8401,6 +8426,7 @@ The next upload iteration will be delayed.`);
8401
8426
  try {
8402
8427
  const options = {
8403
8428
  parameters: resolvedOptions.params,
8429
+ app_metadata: resolvedOptions.appMetadata,
8404
8430
  active_streams: this.activeStreams,
8405
8431
  include_defaults: resolvedOptions.includeDefaultStreams
8406
8432
  };
@@ -9059,11 +9085,11 @@ class AbstractPowerSyncDatabase extends BaseObserver {
9059
9085
  .map((n) => parseInt(n));
9060
9086
  }
9061
9087
  catch (e) {
9062
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
9088
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
9063
9089
  }
9064
- // Validate >=0.4.5 <1.0.0
9065
- if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 5)) {
9066
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}`);
9090
+ // Validate >=0.4.10 <1.0.0
9091
+ if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 10)) {
9092
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}`);
9067
9093
  }
9068
9094
  }
9069
9095
  async resolveOfflineSyncStatus() {
@@ -10183,6 +10209,27 @@ class SyncDataBatch {
10183
10209
  }
10184
10210
  }
10185
10211
 
10212
+ /**
10213
+ * Thrown when an underlying database connection is closed.
10214
+ * This is particularly relevant when worker connections are marked as closed while
10215
+ * operations are still in progress.
10216
+ */
10217
+ class ConnectionClosedError extends Error {
10218
+ static NAME = 'ConnectionClosedError';
10219
+ static MATCHES(input) {
10220
+ /**
10221
+ * If there are weird package issues which cause multiple versions of classes to be present, the instanceof
10222
+ * check might fail. This also performs a failsafe check.
10223
+ * This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
10224
+ */
10225
+ return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
10226
+ }
10227
+ constructor(message) {
10228
+ super(message);
10229
+ this.name = ConnectionClosedError.NAME;
10230
+ }
10231
+ }
10232
+
10186
10233
  // https://www.sqlite.org/lang_expr.html#castexpr
10187
10234
  var ColumnType;
10188
10235
  (function (ColumnType) {
@@ -10737,5 +10784,5 @@ const parseQuery = (query, parameters) => {
10737
10784
  return { sqlStatement, parameters: parameters };
10738
10785
  };
10739
10786
 
10740
- 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 };
10787
+ 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 };
10741
10788
  //# sourceMappingURL=bundle.node.mjs.map