@powersync/web 1.27.1 → 1.28.1

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 (40) hide show
  1. package/dist/index.umd.js +64 -26
  2. package/dist/index.umd.js.map +1 -1
  3. package/dist/worker/SharedSyncImplementation.umd.js +13640 -440
  4. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  5. package/dist/worker/WASQLiteDB.umd.js +13467 -161
  6. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  7. package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js +66 -38
  8. package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +1 -1
  9. package/lib/package.json +6 -5
  10. package/lib/tsconfig.tsbuildinfo +1 -1
  11. package/package.json +7 -6
  12. package/src/db/PowerSyncDatabase.ts +224 -0
  13. package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +47 -0
  14. package/src/db/adapters/AbstractWebSQLOpenFactory.ts +48 -0
  15. package/src/db/adapters/AsyncDatabaseConnection.ts +40 -0
  16. package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +358 -0
  17. package/src/db/adapters/SSRDBAdapter.ts +94 -0
  18. package/src/db/adapters/WebDBAdapter.ts +20 -0
  19. package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +175 -0
  20. package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +444 -0
  21. package/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts +86 -0
  22. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +134 -0
  23. package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +24 -0
  24. package/src/db/adapters/web-sql-flags.ts +135 -0
  25. package/src/db/sync/SSRWebStreamingSyncImplementation.ts +89 -0
  26. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +274 -0
  27. package/src/db/sync/WebRemote.ts +59 -0
  28. package/src/db/sync/WebStreamingSyncImplementation.ts +34 -0
  29. package/src/db/sync/userAgent.ts +78 -0
  30. package/src/index.ts +13 -0
  31. package/src/shared/navigator.ts +9 -0
  32. package/src/worker/db/WASQLiteDB.worker.ts +112 -0
  33. package/src/worker/db/open-worker-database.ts +62 -0
  34. package/src/worker/sync/AbstractSharedSyncClientProvider.ts +21 -0
  35. package/src/worker/sync/BroadcastLogger.ts +142 -0
  36. package/src/worker/sync/SharedSyncImplementation.ts +520 -0
  37. package/src/worker/sync/SharedSyncImplementation.worker.ts +14 -0
  38. package/src/worker/sync/WorkerClient.ts +106 -0
  39. package/dist/worker/node_modules_crypto-browserify_index_js.umd.js +0 -33734
  40. package/dist/worker/node_modules_crypto-browserify_index_js.umd.js.map +0 -1
@@ -5,9 +5,8 @@
5
5
  /*!********************************************!*\
6
6
  !*** ../../node_modules/bson/lib/bson.mjs ***!
7
7
  \********************************************/
8
- /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
8
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
9
9
 
10
- __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
11
10
  __webpack_require__.r(__webpack_exports__);
12
11
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
13
12
  /* harmony export */ BSON: () => (/* binding */ bson),
@@ -258,14 +257,7 @@ function tryWriteBasicLatin(destination, source, offset) {
258
257
  function nodejsMathRandomBytes(byteLength) {
259
258
  return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
260
259
  }
261
- const nodejsRandomBytes = await (async () => {
262
- try {
263
- return (await __webpack_require__.e(/*! import() */ "node_modules_crypto-browserify_index_js").then(__webpack_require__.t.bind(__webpack_require__, /*! crypto */ "../../node_modules/crypto-browserify/index.js", 19))).randomBytes;
264
- }
265
- catch {
266
- return nodejsMathRandomBytes;
267
- }
268
- })();
260
+ const nodejsRandomBytes = nodejsMathRandomBytes;
269
261
  const nodeJsByteUtils = {
270
262
  toLocalBufferType(potentialBuffer) {
271
263
  if (Buffer.isBuffer(potentialBuffer)) {
@@ -790,6 +782,7 @@ class Binary extends BSONValue {
790
782
  if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
791
783
  throw new BSONError('Binary datatype field is not Int8');
792
784
  }
785
+ validateBinaryVector(this);
793
786
  return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
794
787
  }
795
788
  toFloat32Array() {
@@ -799,6 +792,7 @@ class Binary extends BSONValue {
799
792
  if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
800
793
  throw new BSONError('Binary datatype field is not Float32');
801
794
  }
795
+ validateBinaryVector(this);
802
796
  const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
803
797
  if (NumberUtils.isBigEndian)
804
798
  ByteUtils.swap32(floatBytes);
@@ -811,6 +805,7 @@ class Binary extends BSONValue {
811
805
  if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
812
806
  throw new BSONError('Binary datatype field is not packed bit');
813
807
  }
808
+ validateBinaryVector(this);
814
809
  return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
815
810
  }
816
811
  toBits() {
@@ -820,6 +815,7 @@ class Binary extends BSONValue {
820
815
  if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
821
816
  throw new BSONError('Binary datatype field is not packed bit');
822
817
  }
818
+ validateBinaryVector(this);
823
819
  const byteCount = this.length() - 2;
824
820
  const bitCount = byteCount * 8 - this.buffer[1];
825
821
  const bits = new Int8Array(bitCount);
@@ -838,7 +834,9 @@ class Binary extends BSONValue {
838
834
  buffer[1] = 0;
839
835
  const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
840
836
  buffer.set(intBytes, 2);
841
- return new this(buffer, this.SUBTYPE_VECTOR);
837
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
838
+ validateBinaryVector(bin);
839
+ return bin;
842
840
  }
843
841
  static fromFloat32Array(array) {
844
842
  const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
@@ -848,14 +846,18 @@ class Binary extends BSONValue {
848
846
  binaryBytes.set(floatBytes, 2);
849
847
  if (NumberUtils.isBigEndian)
850
848
  ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
851
- return new this(binaryBytes, this.SUBTYPE_VECTOR);
849
+ const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
850
+ validateBinaryVector(bin);
851
+ return bin;
852
852
  }
853
853
  static fromPackedBits(array, padding = 0) {
854
854
  const buffer = ByteUtils.allocate(array.byteLength + 2);
855
855
  buffer[0] = Binary.VECTOR_TYPE.PackedBit;
856
856
  buffer[1] = padding;
857
857
  buffer.set(array, 2);
858
- return new this(buffer, this.SUBTYPE_VECTOR);
858
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
859
+ validateBinaryVector(bin);
860
+ return bin;
859
861
  }
860
862
  static fromBits(bits) {
861
863
  const byteLength = (bits.length + 7) >>> 3;
@@ -905,6 +907,11 @@ function validateBinaryVector(vector) {
905
907
  padding !== 0) {
906
908
  throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
907
909
  }
910
+ if (datatype === Binary.VECTOR_TYPE.Float32) {
911
+ if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
912
+ throw new BSONError('Invalid Vector: Float32 vector must contain a multiple of 4 bytes');
913
+ }
914
+ }
908
915
  if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
909
916
  throw new BSONError('Invalid Vector: padding must be zero for packed bit vectors that are empty');
910
917
  }
@@ -4416,6 +4423,29 @@ EJSON.serialize = EJSONserialize;
4416
4423
  EJSON.deserialize = EJSONdeserialize;
4417
4424
  Object.freeze(EJSON);
4418
4425
 
4426
+ const BSONElementType = {
4427
+ double: 1,
4428
+ string: 2,
4429
+ object: 3,
4430
+ array: 4,
4431
+ binData: 5,
4432
+ undefined: 6,
4433
+ objectId: 7,
4434
+ bool: 8,
4435
+ date: 9,
4436
+ null: 10,
4437
+ regex: 11,
4438
+ dbPointer: 12,
4439
+ javascript: 13,
4440
+ symbol: 14,
4441
+ javascriptWithScope: 15,
4442
+ int: 16,
4443
+ timestamp: 17,
4444
+ long: 18,
4445
+ decimal: 19,
4446
+ minKey: 255,
4447
+ maxKey: 127
4448
+ };
4419
4449
  function getSize(source, offset) {
4420
4450
  try {
4421
4451
  return NumberUtils.getNonnegativeInt32LE(source, offset);
@@ -4460,48 +4490,48 @@ function parseToElements(bytes, startOffset = 0) {
4460
4490
  const nameLength = findNull(bytes, offset) - nameOffset;
4461
4491
  offset += nameLength + 1;
4462
4492
  let length;
4463
- if (type === 1 ||
4464
- type === 18 ||
4465
- type === 9 ||
4466
- type === 17) {
4493
+ if (type === BSONElementType.double ||
4494
+ type === BSONElementType.long ||
4495
+ type === BSONElementType.date ||
4496
+ type === BSONElementType.timestamp) {
4467
4497
  length = 8;
4468
4498
  }
4469
- else if (type === 16) {
4499
+ else if (type === BSONElementType.int) {
4470
4500
  length = 4;
4471
4501
  }
4472
- else if (type === 7) {
4502
+ else if (type === BSONElementType.objectId) {
4473
4503
  length = 12;
4474
4504
  }
4475
- else if (type === 19) {
4505
+ else if (type === BSONElementType.decimal) {
4476
4506
  length = 16;
4477
4507
  }
4478
- else if (type === 8) {
4508
+ else if (type === BSONElementType.bool) {
4479
4509
  length = 1;
4480
4510
  }
4481
- else if (type === 10 ||
4482
- type === 6 ||
4483
- type === 127 ||
4484
- type === 255) {
4511
+ else if (type === BSONElementType.null ||
4512
+ type === BSONElementType.undefined ||
4513
+ type === BSONElementType.maxKey ||
4514
+ type === BSONElementType.minKey) {
4485
4515
  length = 0;
4486
4516
  }
4487
- else if (type === 11) {
4517
+ else if (type === BSONElementType.regex) {
4488
4518
  length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
4489
4519
  }
4490
- else if (type === 3 ||
4491
- type === 4 ||
4492
- type === 15) {
4520
+ else if (type === BSONElementType.object ||
4521
+ type === BSONElementType.array ||
4522
+ type === BSONElementType.javascriptWithScope) {
4493
4523
  length = getSize(bytes, offset);
4494
4524
  }
4495
- else if (type === 2 ||
4496
- type === 5 ||
4497
- type === 12 ||
4498
- type === 13 ||
4499
- type === 14) {
4525
+ else if (type === BSONElementType.string ||
4526
+ type === BSONElementType.binData ||
4527
+ type === BSONElementType.dbPointer ||
4528
+ type === BSONElementType.javascript ||
4529
+ type === BSONElementType.symbol) {
4500
4530
  length = getSize(bytes, offset) + 4;
4501
- if (type === 5) {
4531
+ if (type === BSONElementType.binData) {
4502
4532
  length += 1;
4503
4533
  }
4504
- if (type === 12) {
4534
+ if (type === BSONElementType.dbPointer) {
4505
4535
  length += 12;
4506
4536
  }
4507
4537
  }
@@ -4609,8 +4639,6 @@ var bson = /*#__PURE__*/Object.freeze({
4609
4639
 
4610
4640
  //# sourceMappingURL=bson.mjs.map
4611
4641
 
4612
- __webpack_async_result__();
4613
- } catch(e) { __webpack_async_result__(e); } }, 1);
4614
4642
 
4615
4643
  /***/ })
4616
4644