@powersync/web 1.21.0 → 1.22.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.
- package/dist/index.umd.js +1053 -690
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +228 -172
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +66 -65
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js +565 -384
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_crypto-browserify_index_js.umd.js +326 -189
- package/dist/worker/node_modules_crypto-browserify_index_js.umd.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/db/PowerSyncDatabase.d.ts +1 -2
- package/lib/src/db/PowerSyncDatabase.js +1 -12
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +15 -9
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +18 -11
- package/lib/src/worker/sync/SharedSyncImplementation.js +145 -94
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +11 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -2642,16 +2642,16 @@ function fromByteArray (uint8) {
|
|
|
2642
2642
|
var w = this.words[i];
|
|
2643
2643
|
var word = (((w << off) | carry) & 0xffffff).toString(16);
|
|
2644
2644
|
carry = (w >>> (24 - off)) & 0xffffff;
|
|
2645
|
-
if (carry !== 0 || i !== this.length - 1) {
|
|
2646
|
-
out = zeros[6 - word.length] + word + out;
|
|
2647
|
-
} else {
|
|
2648
|
-
out = word + out;
|
|
2649
|
-
}
|
|
2650
2645
|
off += 2;
|
|
2651
2646
|
if (off >= 26) {
|
|
2652
2647
|
off -= 26;
|
|
2653
2648
|
i--;
|
|
2654
2649
|
}
|
|
2650
|
+
if (carry !== 0 || i !== this.length - 1) {
|
|
2651
|
+
out = zeros[6 - word.length] + word + out;
|
|
2652
|
+
} else {
|
|
2653
|
+
out = word + out;
|
|
2654
|
+
}
|
|
2655
2655
|
}
|
|
2656
2656
|
if (carry !== 0) {
|
|
2657
2657
|
out = carry.toString(16) + out;
|
|
@@ -4111,6 +4111,7 @@ function fromByteArray (uint8) {
|
|
|
4111
4111
|
this.words[i] = carry;
|
|
4112
4112
|
this.length++;
|
|
4113
4113
|
}
|
|
4114
|
+
this.length = num === 0 ? 1 : this.length;
|
|
4114
4115
|
|
|
4115
4116
|
return this;
|
|
4116
4117
|
};
|
|
@@ -9036,6 +9037,7 @@ module.exports = crt;
|
|
|
9036
9037
|
this.words[i] = carry;
|
|
9037
9038
|
this.length++;
|
|
9038
9039
|
}
|
|
9040
|
+
this.length = num === 0 ? 1 : this.length;
|
|
9039
9041
|
|
|
9040
9042
|
return isNegNum ? this.ineg() : this;
|
|
9041
9043
|
};
|
|
@@ -12991,6 +12993,7 @@ module.exports = verify;
|
|
|
12991
12993
|
this.words[i] = carry;
|
|
12992
12994
|
this.length++;
|
|
12993
12995
|
}
|
|
12996
|
+
this.length = num === 0 ? 1 : this.length;
|
|
12994
12997
|
|
|
12995
12998
|
return isNegNum ? this.ineg() : this;
|
|
12996
12999
|
};
|
|
@@ -17362,20 +17365,31 @@ SafeBuffer.allocUnsafeSlow = function (size) {
|
|
|
17362
17365
|
"use strict";
|
|
17363
17366
|
|
|
17364
17367
|
|
|
17365
|
-
|
|
17366
|
-
|
|
17367
|
-
|
|
17368
|
+
const TypedArrayPrototypeGetSymbolToStringTag = (() => {
|
|
17369
|
+
const g = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
17370
|
+
return (value) => g.call(value);
|
|
17371
|
+
})();
|
|
17368
17372
|
function isUint8Array(value) {
|
|
17369
|
-
return
|
|
17373
|
+
return TypedArrayPrototypeGetSymbolToStringTag(value) === 'Uint8Array';
|
|
17370
17374
|
}
|
|
17371
|
-
function
|
|
17372
|
-
return
|
|
17375
|
+
function isAnyArrayBuffer(value) {
|
|
17376
|
+
return (typeof value === 'object' &&
|
|
17377
|
+
value != null &&
|
|
17378
|
+
Symbol.toStringTag in value &&
|
|
17379
|
+
(value[Symbol.toStringTag] === 'ArrayBuffer' ||
|
|
17380
|
+
value[Symbol.toStringTag] === 'SharedArrayBuffer'));
|
|
17373
17381
|
}
|
|
17374
|
-
function
|
|
17375
|
-
return Object.prototype.toString.call(
|
|
17382
|
+
function isRegExp(regexp) {
|
|
17383
|
+
return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === '[object RegExp]';
|
|
17376
17384
|
}
|
|
17377
|
-
function
|
|
17378
|
-
return
|
|
17385
|
+
function isMap(value) {
|
|
17386
|
+
return (typeof value === 'object' &&
|
|
17387
|
+
value != null &&
|
|
17388
|
+
Symbol.toStringTag in value &&
|
|
17389
|
+
value[Symbol.toStringTag] === 'Map');
|
|
17390
|
+
}
|
|
17391
|
+
function isDate(date) {
|
|
17392
|
+
return date instanceof Date || Object.prototype.toString.call(date) === '[object Date]';
|
|
17379
17393
|
}
|
|
17380
17394
|
function defaultInspect(x, _options) {
|
|
17381
17395
|
return JSON.stringify(x, (k, v) => {
|
|
@@ -17399,8 +17413,9 @@ function getStylizeFunction(options) {
|
|
|
17399
17413
|
}
|
|
17400
17414
|
|
|
17401
17415
|
const BSON_MAJOR_VERSION = 6;
|
|
17416
|
+
const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
|
|
17402
17417
|
const BSON_INT32_MAX = 0x7fffffff;
|
|
17403
|
-
const BSON_INT32_MIN = -
|
|
17418
|
+
const BSON_INT32_MIN = -2147483648;
|
|
17404
17419
|
const BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
17405
17420
|
const BSON_INT64_MIN = -Math.pow(2, 63);
|
|
17406
17421
|
const JS_INT_MAX = Math.pow(2, 53);
|
|
@@ -17591,7 +17606,7 @@ const nodeJsByteUtils = {
|
|
|
17591
17606
|
stringTag === '[object SharedArrayBuffer]') {
|
|
17592
17607
|
return Buffer.from(potentialBuffer);
|
|
17593
17608
|
}
|
|
17594
|
-
throw new BSONError(`Cannot create Buffer from
|
|
17609
|
+
throw new BSONError(`Cannot create Buffer from the passed potentialBuffer.`);
|
|
17595
17610
|
},
|
|
17596
17611
|
allocate(size) {
|
|
17597
17612
|
return Buffer.alloc(size);
|
|
@@ -17649,7 +17664,10 @@ const nodeJsByteUtils = {
|
|
|
17649
17664
|
}
|
|
17650
17665
|
return nodeJsByteUtils.toLocalBufferType(buffer).write(source, byteOffset, undefined, 'utf8');
|
|
17651
17666
|
},
|
|
17652
|
-
randomBytes: nodejsRandomBytes
|
|
17667
|
+
randomBytes: nodejsRandomBytes,
|
|
17668
|
+
swap32(buffer) {
|
|
17669
|
+
return nodeJsByteUtils.toLocalBufferType(buffer).swap32();
|
|
17670
|
+
}
|
|
17653
17671
|
};
|
|
17654
17672
|
|
|
17655
17673
|
function isReactNative() {
|
|
@@ -17694,7 +17712,7 @@ const webByteUtils = {
|
|
|
17694
17712
|
stringTag === '[object SharedArrayBuffer]') {
|
|
17695
17713
|
return new Uint8Array(potentialUint8array);
|
|
17696
17714
|
}
|
|
17697
|
-
throw new BSONError(`Cannot make a Uint8Array from
|
|
17715
|
+
throw new BSONError(`Cannot make a Uint8Array from passed potentialBuffer.`);
|
|
17698
17716
|
},
|
|
17699
17717
|
allocate(size) {
|
|
17700
17718
|
if (typeof size !== 'number') {
|
|
@@ -17766,14 +17784,30 @@ const webByteUtils = {
|
|
|
17766
17784
|
uint8array.set(bytes, byteOffset);
|
|
17767
17785
|
return bytes.byteLength;
|
|
17768
17786
|
},
|
|
17769
|
-
randomBytes: webRandomBytes
|
|
17787
|
+
randomBytes: webRandomBytes,
|
|
17788
|
+
swap32(buffer) {
|
|
17789
|
+
if (buffer.length % 4 !== 0) {
|
|
17790
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits');
|
|
17791
|
+
}
|
|
17792
|
+
for (let i = 0; i < buffer.length; i += 4) {
|
|
17793
|
+
const byte0 = buffer[i];
|
|
17794
|
+
const byte1 = buffer[i + 1];
|
|
17795
|
+
const byte2 = buffer[i + 2];
|
|
17796
|
+
const byte3 = buffer[i + 3];
|
|
17797
|
+
buffer[i] = byte3;
|
|
17798
|
+
buffer[i + 1] = byte2;
|
|
17799
|
+
buffer[i + 2] = byte1;
|
|
17800
|
+
buffer[i + 3] = byte0;
|
|
17801
|
+
}
|
|
17802
|
+
return buffer;
|
|
17803
|
+
}
|
|
17770
17804
|
};
|
|
17771
17805
|
|
|
17772
17806
|
const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
|
|
17773
17807
|
const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
|
17774
17808
|
|
|
17775
17809
|
class BSONValue {
|
|
17776
|
-
get [
|
|
17810
|
+
get [BSON_VERSION_SYMBOL]() {
|
|
17777
17811
|
return BSON_MAJOR_VERSION;
|
|
17778
17812
|
}
|
|
17779
17813
|
[Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
|
|
@@ -17781,6 +17815,140 @@ class BSONValue {
|
|
|
17781
17815
|
}
|
|
17782
17816
|
}
|
|
17783
17817
|
|
|
17818
|
+
const FLOAT = new Float64Array(1);
|
|
17819
|
+
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
|
|
17820
|
+
FLOAT[0] = -1;
|
|
17821
|
+
const isBigEndian = FLOAT_BYTES[7] === 0;
|
|
17822
|
+
const NumberUtils = {
|
|
17823
|
+
isBigEndian,
|
|
17824
|
+
getNonnegativeInt32LE(source, offset) {
|
|
17825
|
+
if (source[offset + 3] > 127) {
|
|
17826
|
+
throw new RangeError(`Size cannot be negative at offset: ${offset}`);
|
|
17827
|
+
}
|
|
17828
|
+
return (source[offset] |
|
|
17829
|
+
(source[offset + 1] << 8) |
|
|
17830
|
+
(source[offset + 2] << 16) |
|
|
17831
|
+
(source[offset + 3] << 24));
|
|
17832
|
+
},
|
|
17833
|
+
getInt32LE(source, offset) {
|
|
17834
|
+
return (source[offset] |
|
|
17835
|
+
(source[offset + 1] << 8) |
|
|
17836
|
+
(source[offset + 2] << 16) |
|
|
17837
|
+
(source[offset + 3] << 24));
|
|
17838
|
+
},
|
|
17839
|
+
getUint32LE(source, offset) {
|
|
17840
|
+
return (source[offset] +
|
|
17841
|
+
source[offset + 1] * 256 +
|
|
17842
|
+
source[offset + 2] * 65536 +
|
|
17843
|
+
source[offset + 3] * 16777216);
|
|
17844
|
+
},
|
|
17845
|
+
getUint32BE(source, offset) {
|
|
17846
|
+
return (source[offset + 3] +
|
|
17847
|
+
source[offset + 2] * 256 +
|
|
17848
|
+
source[offset + 1] * 65536 +
|
|
17849
|
+
source[offset] * 16777216);
|
|
17850
|
+
},
|
|
17851
|
+
getBigInt64LE(source, offset) {
|
|
17852
|
+
const hi = BigInt(source[offset + 4] +
|
|
17853
|
+
source[offset + 5] * 256 +
|
|
17854
|
+
source[offset + 6] * 65536 +
|
|
17855
|
+
(source[offset + 7] << 24));
|
|
17856
|
+
const lo = BigInt(source[offset] +
|
|
17857
|
+
source[offset + 1] * 256 +
|
|
17858
|
+
source[offset + 2] * 65536 +
|
|
17859
|
+
source[offset + 3] * 16777216);
|
|
17860
|
+
return (hi << BigInt(32)) + lo;
|
|
17861
|
+
},
|
|
17862
|
+
getFloat64LE: isBigEndian
|
|
17863
|
+
? (source, offset) => {
|
|
17864
|
+
FLOAT_BYTES[7] = source[offset];
|
|
17865
|
+
FLOAT_BYTES[6] = source[offset + 1];
|
|
17866
|
+
FLOAT_BYTES[5] = source[offset + 2];
|
|
17867
|
+
FLOAT_BYTES[4] = source[offset + 3];
|
|
17868
|
+
FLOAT_BYTES[3] = source[offset + 4];
|
|
17869
|
+
FLOAT_BYTES[2] = source[offset + 5];
|
|
17870
|
+
FLOAT_BYTES[1] = source[offset + 6];
|
|
17871
|
+
FLOAT_BYTES[0] = source[offset + 7];
|
|
17872
|
+
return FLOAT[0];
|
|
17873
|
+
}
|
|
17874
|
+
: (source, offset) => {
|
|
17875
|
+
FLOAT_BYTES[0] = source[offset];
|
|
17876
|
+
FLOAT_BYTES[1] = source[offset + 1];
|
|
17877
|
+
FLOAT_BYTES[2] = source[offset + 2];
|
|
17878
|
+
FLOAT_BYTES[3] = source[offset + 3];
|
|
17879
|
+
FLOAT_BYTES[4] = source[offset + 4];
|
|
17880
|
+
FLOAT_BYTES[5] = source[offset + 5];
|
|
17881
|
+
FLOAT_BYTES[6] = source[offset + 6];
|
|
17882
|
+
FLOAT_BYTES[7] = source[offset + 7];
|
|
17883
|
+
return FLOAT[0];
|
|
17884
|
+
},
|
|
17885
|
+
setInt32BE(destination, offset, value) {
|
|
17886
|
+
destination[offset + 3] = value;
|
|
17887
|
+
value >>>= 8;
|
|
17888
|
+
destination[offset + 2] = value;
|
|
17889
|
+
value >>>= 8;
|
|
17890
|
+
destination[offset + 1] = value;
|
|
17891
|
+
value >>>= 8;
|
|
17892
|
+
destination[offset] = value;
|
|
17893
|
+
return 4;
|
|
17894
|
+
},
|
|
17895
|
+
setInt32LE(destination, offset, value) {
|
|
17896
|
+
destination[offset] = value;
|
|
17897
|
+
value >>>= 8;
|
|
17898
|
+
destination[offset + 1] = value;
|
|
17899
|
+
value >>>= 8;
|
|
17900
|
+
destination[offset + 2] = value;
|
|
17901
|
+
value >>>= 8;
|
|
17902
|
+
destination[offset + 3] = value;
|
|
17903
|
+
return 4;
|
|
17904
|
+
},
|
|
17905
|
+
setBigInt64LE(destination, offset, value) {
|
|
17906
|
+
const mask32bits = BigInt(0xffff_ffff);
|
|
17907
|
+
let lo = Number(value & mask32bits);
|
|
17908
|
+
destination[offset] = lo;
|
|
17909
|
+
lo >>= 8;
|
|
17910
|
+
destination[offset + 1] = lo;
|
|
17911
|
+
lo >>= 8;
|
|
17912
|
+
destination[offset + 2] = lo;
|
|
17913
|
+
lo >>= 8;
|
|
17914
|
+
destination[offset + 3] = lo;
|
|
17915
|
+
let hi = Number((value >> BigInt(32)) & mask32bits);
|
|
17916
|
+
destination[offset + 4] = hi;
|
|
17917
|
+
hi >>= 8;
|
|
17918
|
+
destination[offset + 5] = hi;
|
|
17919
|
+
hi >>= 8;
|
|
17920
|
+
destination[offset + 6] = hi;
|
|
17921
|
+
hi >>= 8;
|
|
17922
|
+
destination[offset + 7] = hi;
|
|
17923
|
+
return 8;
|
|
17924
|
+
},
|
|
17925
|
+
setFloat64LE: isBigEndian
|
|
17926
|
+
? (destination, offset, value) => {
|
|
17927
|
+
FLOAT[0] = value;
|
|
17928
|
+
destination[offset] = FLOAT_BYTES[7];
|
|
17929
|
+
destination[offset + 1] = FLOAT_BYTES[6];
|
|
17930
|
+
destination[offset + 2] = FLOAT_BYTES[5];
|
|
17931
|
+
destination[offset + 3] = FLOAT_BYTES[4];
|
|
17932
|
+
destination[offset + 4] = FLOAT_BYTES[3];
|
|
17933
|
+
destination[offset + 5] = FLOAT_BYTES[2];
|
|
17934
|
+
destination[offset + 6] = FLOAT_BYTES[1];
|
|
17935
|
+
destination[offset + 7] = FLOAT_BYTES[0];
|
|
17936
|
+
return 8;
|
|
17937
|
+
}
|
|
17938
|
+
: (destination, offset, value) => {
|
|
17939
|
+
FLOAT[0] = value;
|
|
17940
|
+
destination[offset] = FLOAT_BYTES[0];
|
|
17941
|
+
destination[offset + 1] = FLOAT_BYTES[1];
|
|
17942
|
+
destination[offset + 2] = FLOAT_BYTES[2];
|
|
17943
|
+
destination[offset + 3] = FLOAT_BYTES[3];
|
|
17944
|
+
destination[offset + 4] = FLOAT_BYTES[4];
|
|
17945
|
+
destination[offset + 5] = FLOAT_BYTES[5];
|
|
17946
|
+
destination[offset + 6] = FLOAT_BYTES[6];
|
|
17947
|
+
destination[offset + 7] = FLOAT_BYTES[7];
|
|
17948
|
+
return 8;
|
|
17949
|
+
}
|
|
17950
|
+
};
|
|
17951
|
+
|
|
17784
17952
|
class Binary extends BSONValue {
|
|
17785
17953
|
get _bsontype() {
|
|
17786
17954
|
return 'Binary';
|
|
@@ -17853,7 +18021,8 @@ class Binary extends BSONValue {
|
|
|
17853
18021
|
}
|
|
17854
18022
|
read(position, length) {
|
|
17855
18023
|
length = length && length > 0 ? length : this.position;
|
|
17856
|
-
|
|
18024
|
+
const end = position + length;
|
|
18025
|
+
return this.buffer.subarray(position, end > this.position ? this.position : end);
|
|
17857
18026
|
}
|
|
17858
18027
|
value() {
|
|
17859
18028
|
return this.buffer.length === this.position
|
|
@@ -17877,6 +18046,9 @@ class Binary extends BSONValue {
|
|
|
17877
18046
|
}
|
|
17878
18047
|
toExtendedJSON(options) {
|
|
17879
18048
|
options = options || {};
|
|
18049
|
+
if (this.sub_type === Binary.SUBTYPE_VECTOR) {
|
|
18050
|
+
validateBinaryVector(this);
|
|
18051
|
+
}
|
|
17880
18052
|
const base64String = ByteUtils.toBase64(this.buffer);
|
|
17881
18053
|
const subType = Number(this.sub_type).toString(16);
|
|
17882
18054
|
if (options.legacy) {
|
|
@@ -17894,7 +18066,7 @@ class Binary extends BSONValue {
|
|
|
17894
18066
|
}
|
|
17895
18067
|
toUUID() {
|
|
17896
18068
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
17897
|
-
return new UUID(this.buffer.
|
|
18069
|
+
return new UUID(this.buffer.subarray(0, this.position));
|
|
17898
18070
|
}
|
|
17899
18071
|
throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`);
|
|
17900
18072
|
}
|
|
@@ -17936,6 +18108,99 @@ class Binary extends BSONValue {
|
|
|
17936
18108
|
const subTypeArg = inspect(this.sub_type, options);
|
|
17937
18109
|
return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
|
|
17938
18110
|
}
|
|
18111
|
+
toInt8Array() {
|
|
18112
|
+
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
18113
|
+
throw new BSONError('Binary sub_type is not Vector');
|
|
18114
|
+
}
|
|
18115
|
+
if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
|
|
18116
|
+
throw new BSONError('Binary datatype field is not Int8');
|
|
18117
|
+
}
|
|
18118
|
+
return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
18119
|
+
}
|
|
18120
|
+
toFloat32Array() {
|
|
18121
|
+
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
18122
|
+
throw new BSONError('Binary sub_type is not Vector');
|
|
18123
|
+
}
|
|
18124
|
+
if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
|
|
18125
|
+
throw new BSONError('Binary datatype field is not Float32');
|
|
18126
|
+
}
|
|
18127
|
+
const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
18128
|
+
if (NumberUtils.isBigEndian)
|
|
18129
|
+
ByteUtils.swap32(floatBytes);
|
|
18130
|
+
return new Float32Array(floatBytes.buffer);
|
|
18131
|
+
}
|
|
18132
|
+
toPackedBits() {
|
|
18133
|
+
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
18134
|
+
throw new BSONError('Binary sub_type is not Vector');
|
|
18135
|
+
}
|
|
18136
|
+
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
18137
|
+
throw new BSONError('Binary datatype field is not packed bit');
|
|
18138
|
+
}
|
|
18139
|
+
return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
18140
|
+
}
|
|
18141
|
+
toBits() {
|
|
18142
|
+
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
18143
|
+
throw new BSONError('Binary sub_type is not Vector');
|
|
18144
|
+
}
|
|
18145
|
+
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
18146
|
+
throw new BSONError('Binary datatype field is not packed bit');
|
|
18147
|
+
}
|
|
18148
|
+
const byteCount = this.length() - 2;
|
|
18149
|
+
const bitCount = byteCount * 8 - this.buffer[1];
|
|
18150
|
+
const bits = new Int8Array(bitCount);
|
|
18151
|
+
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
|
18152
|
+
const byteOffset = (bitOffset / 8) | 0;
|
|
18153
|
+
const byte = this.buffer[byteOffset + 2];
|
|
18154
|
+
const shift = 7 - (bitOffset % 8);
|
|
18155
|
+
const bit = (byte >> shift) & 1;
|
|
18156
|
+
bits[bitOffset] = bit;
|
|
18157
|
+
}
|
|
18158
|
+
return bits;
|
|
18159
|
+
}
|
|
18160
|
+
static fromInt8Array(array) {
|
|
18161
|
+
const buffer = ByteUtils.allocate(array.byteLength + 2);
|
|
18162
|
+
buffer[0] = Binary.VECTOR_TYPE.Int8;
|
|
18163
|
+
buffer[1] = 0;
|
|
18164
|
+
const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
18165
|
+
buffer.set(intBytes, 2);
|
|
18166
|
+
return new this(buffer, this.SUBTYPE_VECTOR);
|
|
18167
|
+
}
|
|
18168
|
+
static fromFloat32Array(array) {
|
|
18169
|
+
const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
|
|
18170
|
+
binaryBytes[0] = Binary.VECTOR_TYPE.Float32;
|
|
18171
|
+
binaryBytes[1] = 0;
|
|
18172
|
+
const floatBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
18173
|
+
binaryBytes.set(floatBytes, 2);
|
|
18174
|
+
if (NumberUtils.isBigEndian)
|
|
18175
|
+
ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
|
|
18176
|
+
return new this(binaryBytes, this.SUBTYPE_VECTOR);
|
|
18177
|
+
}
|
|
18178
|
+
static fromPackedBits(array, padding = 0) {
|
|
18179
|
+
const buffer = ByteUtils.allocate(array.byteLength + 2);
|
|
18180
|
+
buffer[0] = Binary.VECTOR_TYPE.PackedBit;
|
|
18181
|
+
buffer[1] = padding;
|
|
18182
|
+
buffer.set(array, 2);
|
|
18183
|
+
return new this(buffer, this.SUBTYPE_VECTOR);
|
|
18184
|
+
}
|
|
18185
|
+
static fromBits(bits) {
|
|
18186
|
+
const byteLength = (bits.length + 7) >>> 3;
|
|
18187
|
+
const bytes = new Uint8Array(byteLength + 2);
|
|
18188
|
+
bytes[0] = Binary.VECTOR_TYPE.PackedBit;
|
|
18189
|
+
const remainder = bits.length % 8;
|
|
18190
|
+
bytes[1] = remainder === 0 ? 0 : 8 - remainder;
|
|
18191
|
+
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
|
18192
|
+
const byteOffset = bitOffset >>> 3;
|
|
18193
|
+
const bit = bits[bitOffset];
|
|
18194
|
+
if (bit !== 0 && bit !== 1) {
|
|
18195
|
+
throw new BSONError(`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`);
|
|
18196
|
+
}
|
|
18197
|
+
if (bit === 0)
|
|
18198
|
+
continue;
|
|
18199
|
+
const shift = 7 - (bitOffset % 8);
|
|
18200
|
+
bytes[byteOffset + 2] |= bit << shift;
|
|
18201
|
+
}
|
|
18202
|
+
return new this(bytes, Binary.SUBTYPE_VECTOR);
|
|
18203
|
+
}
|
|
17939
18204
|
}
|
|
17940
18205
|
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
17941
18206
|
Binary.BUFFER_SIZE = 256;
|
|
@@ -17948,7 +18213,30 @@ Binary.SUBTYPE_MD5 = 5;
|
|
|
17948
18213
|
Binary.SUBTYPE_ENCRYPTED = 6;
|
|
17949
18214
|
Binary.SUBTYPE_COLUMN = 7;
|
|
17950
18215
|
Binary.SUBTYPE_SENSITIVE = 8;
|
|
18216
|
+
Binary.SUBTYPE_VECTOR = 9;
|
|
17951
18217
|
Binary.SUBTYPE_USER_DEFINED = 128;
|
|
18218
|
+
Binary.VECTOR_TYPE = Object.freeze({
|
|
18219
|
+
Int8: 0x03,
|
|
18220
|
+
Float32: 0x27,
|
|
18221
|
+
PackedBit: 0x10
|
|
18222
|
+
});
|
|
18223
|
+
function validateBinaryVector(vector) {
|
|
18224
|
+
if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
|
|
18225
|
+
return;
|
|
18226
|
+
const size = vector.position;
|
|
18227
|
+
const datatype = vector.buffer[0];
|
|
18228
|
+
const padding = vector.buffer[1];
|
|
18229
|
+
if ((datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) &&
|
|
18230
|
+
padding !== 0) {
|
|
18231
|
+
throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
|
|
18232
|
+
}
|
|
18233
|
+
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
|
|
18234
|
+
throw new BSONError('Invalid Vector: padding must be zero for packed bit vectors that are empty');
|
|
18235
|
+
}
|
|
18236
|
+
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding > 7) {
|
|
18237
|
+
throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${padding}`);
|
|
18238
|
+
}
|
|
18239
|
+
}
|
|
17952
18240
|
const UUID_BYTE_LENGTH = 16;
|
|
17953
18241
|
const UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
|
|
17954
18242
|
const UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
|
|
@@ -18270,7 +18558,7 @@ class Long extends BSONValue {
|
|
|
18270
18558
|
return Long.MAX_UNSIGNED_VALUE;
|
|
18271
18559
|
}
|
|
18272
18560
|
else {
|
|
18273
|
-
if (value <= -
|
|
18561
|
+
if (value <= -9223372036854776e3)
|
|
18274
18562
|
return Long.MIN_VALUE;
|
|
18275
18563
|
if (value + 1 >= TWO_PWR_63_DBL)
|
|
18276
18564
|
return Long.MAX_VALUE;
|
|
@@ -18429,7 +18717,7 @@ class Long extends BSONValue {
|
|
|
18429
18717
|
throw new BSONError('division by zero');
|
|
18430
18718
|
if (wasm) {
|
|
18431
18719
|
if (!this.unsigned &&
|
|
18432
|
-
this.high === -
|
|
18720
|
+
this.high === -2147483648 &&
|
|
18433
18721
|
divisor.low === -1 &&
|
|
18434
18722
|
divisor.high === -1) {
|
|
18435
18723
|
return this;
|
|
@@ -18950,7 +19238,7 @@ class Decimal128 extends BSONValue {
|
|
|
18950
19238
|
if (typeof bytes === 'string') {
|
|
18951
19239
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
18952
19240
|
}
|
|
18953
|
-
else if (isUint8Array(bytes)) {
|
|
19241
|
+
else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
|
|
18954
19242
|
if (bytes.byteLength !== 16) {
|
|
18955
19243
|
throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
|
|
18956
19244
|
}
|
|
@@ -19560,135 +19848,8 @@ class MinKey extends BSONValue {
|
|
|
19560
19848
|
}
|
|
19561
19849
|
}
|
|
19562
19850
|
|
|
19563
|
-
const FLOAT = new Float64Array(1);
|
|
19564
|
-
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
|
|
19565
|
-
FLOAT[0] = -1;
|
|
19566
|
-
const isBigEndian = FLOAT_BYTES[7] === 0;
|
|
19567
|
-
const NumberUtils = {
|
|
19568
|
-
getNonnegativeInt32LE(source, offset) {
|
|
19569
|
-
if (source[offset + 3] > 127) {
|
|
19570
|
-
throw new RangeError(`Size cannot be negative at offset: ${offset}`);
|
|
19571
|
-
}
|
|
19572
|
-
return (source[offset] |
|
|
19573
|
-
(source[offset + 1] << 8) |
|
|
19574
|
-
(source[offset + 2] << 16) |
|
|
19575
|
-
(source[offset + 3] << 24));
|
|
19576
|
-
},
|
|
19577
|
-
getInt32LE(source, offset) {
|
|
19578
|
-
return (source[offset] |
|
|
19579
|
-
(source[offset + 1] << 8) |
|
|
19580
|
-
(source[offset + 2] << 16) |
|
|
19581
|
-
(source[offset + 3] << 24));
|
|
19582
|
-
},
|
|
19583
|
-
getUint32LE(source, offset) {
|
|
19584
|
-
return (source[offset] +
|
|
19585
|
-
source[offset + 1] * 256 +
|
|
19586
|
-
source[offset + 2] * 65536 +
|
|
19587
|
-
source[offset + 3] * 16777216);
|
|
19588
|
-
},
|
|
19589
|
-
getUint32BE(source, offset) {
|
|
19590
|
-
return (source[offset + 3] +
|
|
19591
|
-
source[offset + 2] * 256 +
|
|
19592
|
-
source[offset + 1] * 65536 +
|
|
19593
|
-
source[offset] * 16777216);
|
|
19594
|
-
},
|
|
19595
|
-
getBigInt64LE(source, offset) {
|
|
19596
|
-
const lo = NumberUtils.getUint32LE(source, offset);
|
|
19597
|
-
const hi = NumberUtils.getUint32LE(source, offset + 4);
|
|
19598
|
-
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
19599
|
-
},
|
|
19600
|
-
getFloat64LE: isBigEndian
|
|
19601
|
-
? (source, offset) => {
|
|
19602
|
-
FLOAT_BYTES[7] = source[offset];
|
|
19603
|
-
FLOAT_BYTES[6] = source[offset + 1];
|
|
19604
|
-
FLOAT_BYTES[5] = source[offset + 2];
|
|
19605
|
-
FLOAT_BYTES[4] = source[offset + 3];
|
|
19606
|
-
FLOAT_BYTES[3] = source[offset + 4];
|
|
19607
|
-
FLOAT_BYTES[2] = source[offset + 5];
|
|
19608
|
-
FLOAT_BYTES[1] = source[offset + 6];
|
|
19609
|
-
FLOAT_BYTES[0] = source[offset + 7];
|
|
19610
|
-
return FLOAT[0];
|
|
19611
|
-
}
|
|
19612
|
-
: (source, offset) => {
|
|
19613
|
-
FLOAT_BYTES[0] = source[offset];
|
|
19614
|
-
FLOAT_BYTES[1] = source[offset + 1];
|
|
19615
|
-
FLOAT_BYTES[2] = source[offset + 2];
|
|
19616
|
-
FLOAT_BYTES[3] = source[offset + 3];
|
|
19617
|
-
FLOAT_BYTES[4] = source[offset + 4];
|
|
19618
|
-
FLOAT_BYTES[5] = source[offset + 5];
|
|
19619
|
-
FLOAT_BYTES[6] = source[offset + 6];
|
|
19620
|
-
FLOAT_BYTES[7] = source[offset + 7];
|
|
19621
|
-
return FLOAT[0];
|
|
19622
|
-
},
|
|
19623
|
-
setInt32BE(destination, offset, value) {
|
|
19624
|
-
destination[offset + 3] = value;
|
|
19625
|
-
value >>>= 8;
|
|
19626
|
-
destination[offset + 2] = value;
|
|
19627
|
-
value >>>= 8;
|
|
19628
|
-
destination[offset + 1] = value;
|
|
19629
|
-
value >>>= 8;
|
|
19630
|
-
destination[offset] = value;
|
|
19631
|
-
return 4;
|
|
19632
|
-
},
|
|
19633
|
-
setInt32LE(destination, offset, value) {
|
|
19634
|
-
destination[offset] = value;
|
|
19635
|
-
value >>>= 8;
|
|
19636
|
-
destination[offset + 1] = value;
|
|
19637
|
-
value >>>= 8;
|
|
19638
|
-
destination[offset + 2] = value;
|
|
19639
|
-
value >>>= 8;
|
|
19640
|
-
destination[offset + 3] = value;
|
|
19641
|
-
return 4;
|
|
19642
|
-
},
|
|
19643
|
-
setBigInt64LE(destination, offset, value) {
|
|
19644
|
-
const mask32bits = BigInt(4294967295);
|
|
19645
|
-
let lo = Number(value & mask32bits);
|
|
19646
|
-
destination[offset] = lo;
|
|
19647
|
-
lo >>= 8;
|
|
19648
|
-
destination[offset + 1] = lo;
|
|
19649
|
-
lo >>= 8;
|
|
19650
|
-
destination[offset + 2] = lo;
|
|
19651
|
-
lo >>= 8;
|
|
19652
|
-
destination[offset + 3] = lo;
|
|
19653
|
-
let hi = Number((value >> BigInt(32)) & mask32bits);
|
|
19654
|
-
destination[offset + 4] = hi;
|
|
19655
|
-
hi >>= 8;
|
|
19656
|
-
destination[offset + 5] = hi;
|
|
19657
|
-
hi >>= 8;
|
|
19658
|
-
destination[offset + 6] = hi;
|
|
19659
|
-
hi >>= 8;
|
|
19660
|
-
destination[offset + 7] = hi;
|
|
19661
|
-
return 8;
|
|
19662
|
-
},
|
|
19663
|
-
setFloat64LE: isBigEndian
|
|
19664
|
-
? (destination, offset, value) => {
|
|
19665
|
-
FLOAT[0] = value;
|
|
19666
|
-
destination[offset] = FLOAT_BYTES[7];
|
|
19667
|
-
destination[offset + 1] = FLOAT_BYTES[6];
|
|
19668
|
-
destination[offset + 2] = FLOAT_BYTES[5];
|
|
19669
|
-
destination[offset + 3] = FLOAT_BYTES[4];
|
|
19670
|
-
destination[offset + 4] = FLOAT_BYTES[3];
|
|
19671
|
-
destination[offset + 5] = FLOAT_BYTES[2];
|
|
19672
|
-
destination[offset + 6] = FLOAT_BYTES[1];
|
|
19673
|
-
destination[offset + 7] = FLOAT_BYTES[0];
|
|
19674
|
-
return 8;
|
|
19675
|
-
}
|
|
19676
|
-
: (destination, offset, value) => {
|
|
19677
|
-
FLOAT[0] = value;
|
|
19678
|
-
destination[offset] = FLOAT_BYTES[0];
|
|
19679
|
-
destination[offset + 1] = FLOAT_BYTES[1];
|
|
19680
|
-
destination[offset + 2] = FLOAT_BYTES[2];
|
|
19681
|
-
destination[offset + 3] = FLOAT_BYTES[3];
|
|
19682
|
-
destination[offset + 4] = FLOAT_BYTES[4];
|
|
19683
|
-
destination[offset + 5] = FLOAT_BYTES[5];
|
|
19684
|
-
destination[offset + 6] = FLOAT_BYTES[6];
|
|
19685
|
-
destination[offset + 7] = FLOAT_BYTES[7];
|
|
19686
|
-
return 8;
|
|
19687
|
-
}
|
|
19688
|
-
};
|
|
19689
|
-
|
|
19690
|
-
const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
|
|
19691
19851
|
let PROCESS_UNIQUE = null;
|
|
19852
|
+
const __idCache = new WeakMap();
|
|
19692
19853
|
class ObjectId extends BSONValue {
|
|
19693
19854
|
get _bsontype() {
|
|
19694
19855
|
return 'ObjectId';
|
|
@@ -19717,8 +19878,11 @@ class ObjectId extends BSONValue {
|
|
|
19717
19878
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
19718
19879
|
}
|
|
19719
19880
|
else if (typeof workingId === 'string') {
|
|
19720
|
-
if (
|
|
19881
|
+
if (ObjectId.validateHexString(workingId)) {
|
|
19721
19882
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
19883
|
+
if (ObjectId.cacheHexString) {
|
|
19884
|
+
__idCache.set(this, workingId);
|
|
19885
|
+
}
|
|
19722
19886
|
}
|
|
19723
19887
|
else {
|
|
19724
19888
|
throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
|
|
@@ -19727,9 +19891,6 @@ class ObjectId extends BSONValue {
|
|
|
19727
19891
|
else {
|
|
19728
19892
|
throw new BSONError('Argument passed in does not match the accepted types');
|
|
19729
19893
|
}
|
|
19730
|
-
if (ObjectId.cacheHexString) {
|
|
19731
|
-
this.__id = ByteUtils.toHex(this.id);
|
|
19732
|
-
}
|
|
19733
19894
|
}
|
|
19734
19895
|
get id() {
|
|
19735
19896
|
return this.buffer;
|
|
@@ -19737,16 +19898,32 @@ class ObjectId extends BSONValue {
|
|
|
19737
19898
|
set id(value) {
|
|
19738
19899
|
this.buffer = value;
|
|
19739
19900
|
if (ObjectId.cacheHexString) {
|
|
19740
|
-
this
|
|
19901
|
+
__idCache.set(this, ByteUtils.toHex(value));
|
|
19902
|
+
}
|
|
19903
|
+
}
|
|
19904
|
+
static validateHexString(string) {
|
|
19905
|
+
if (string?.length !== 24)
|
|
19906
|
+
return false;
|
|
19907
|
+
for (let i = 0; i < 24; i++) {
|
|
19908
|
+
const char = string.charCodeAt(i);
|
|
19909
|
+
if ((char >= 48 && char <= 57) ||
|
|
19910
|
+
(char >= 97 && char <= 102) ||
|
|
19911
|
+
(char >= 65 && char <= 70)) {
|
|
19912
|
+
continue;
|
|
19913
|
+
}
|
|
19914
|
+
return false;
|
|
19741
19915
|
}
|
|
19916
|
+
return true;
|
|
19742
19917
|
}
|
|
19743
19918
|
toHexString() {
|
|
19744
|
-
if (ObjectId.cacheHexString
|
|
19745
|
-
|
|
19919
|
+
if (ObjectId.cacheHexString) {
|
|
19920
|
+
const __id = __idCache.get(this);
|
|
19921
|
+
if (__id)
|
|
19922
|
+
return __id;
|
|
19746
19923
|
}
|
|
19747
19924
|
const hexString = ByteUtils.toHex(this.id);
|
|
19748
|
-
if (ObjectId.cacheHexString
|
|
19749
|
-
this
|
|
19925
|
+
if (ObjectId.cacheHexString) {
|
|
19926
|
+
__idCache.set(this, hexString);
|
|
19750
19927
|
}
|
|
19751
19928
|
return hexString;
|
|
19752
19929
|
}
|
|
@@ -19852,6 +20029,8 @@ class ObjectId extends BSONValue {
|
|
|
19852
20029
|
static isValid(id) {
|
|
19853
20030
|
if (id == null)
|
|
19854
20031
|
return false;
|
|
20032
|
+
if (typeof id === 'string')
|
|
20033
|
+
return ObjectId.validateHexString(id);
|
|
19855
20034
|
try {
|
|
19856
20035
|
new ObjectId(id);
|
|
19857
20036
|
return true;
|
|
@@ -19868,6 +20047,9 @@ class ObjectId extends BSONValue {
|
|
|
19868
20047
|
static fromExtendedJSON(doc) {
|
|
19869
20048
|
return new ObjectId(doc.$oid);
|
|
19870
20049
|
}
|
|
20050
|
+
isCached() {
|
|
20051
|
+
return ObjectId.cacheHexString && __idCache.has(this);
|
|
20052
|
+
}
|
|
19871
20053
|
inspect(depth, options, inspect) {
|
|
19872
20054
|
inspect ??= defaultInspect;
|
|
19873
20055
|
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
|
@@ -19922,7 +20104,7 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
19922
20104
|
case 'object':
|
|
19923
20105
|
if (value != null &&
|
|
19924
20106
|
typeof value._bsontype === 'string' &&
|
|
19925
|
-
value[
|
|
20107
|
+
value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
19926
20108
|
throw new BSONVersionError();
|
|
19927
20109
|
}
|
|
19928
20110
|
else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
@@ -20025,8 +20207,14 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
20025
20207
|
ByteUtils.utf8ByteLength(value.toString()) +
|
|
20026
20208
|
1);
|
|
20027
20209
|
}
|
|
20210
|
+
return 0;
|
|
20211
|
+
case 'bigint':
|
|
20212
|
+
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
20213
|
+
case 'symbol':
|
|
20214
|
+
return 0;
|
|
20215
|
+
default:
|
|
20216
|
+
throw new BSONError(`Unrecognized JS type: ${typeof value}`);
|
|
20028
20217
|
}
|
|
20029
|
-
return 0;
|
|
20030
20218
|
}
|
|
20031
20219
|
|
|
20032
20220
|
function alphabetize(str) {
|
|
@@ -20126,6 +20314,12 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
20126
20314
|
get _bsontype() {
|
|
20127
20315
|
return 'Timestamp';
|
|
20128
20316
|
}
|
|
20317
|
+
get i() {
|
|
20318
|
+
return this.low >>> 0;
|
|
20319
|
+
}
|
|
20320
|
+
get t() {
|
|
20321
|
+
return this.high >>> 0;
|
|
20322
|
+
}
|
|
20129
20323
|
constructor(low) {
|
|
20130
20324
|
if (low == null) {
|
|
20131
20325
|
super(0, 0, true);
|
|
@@ -20151,10 +20345,10 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
20151
20345
|
if (i < 0 || Number.isNaN(i)) {
|
|
20152
20346
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
|
20153
20347
|
}
|
|
20154
|
-
if (t >
|
|
20348
|
+
if (t > 0xffff_ffff) {
|
|
20155
20349
|
throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
|
|
20156
20350
|
}
|
|
20157
|
-
if (i >
|
|
20351
|
+
if (i > 0xffff_ffff) {
|
|
20158
20352
|
throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
|
|
20159
20353
|
}
|
|
20160
20354
|
super(i, t, true);
|
|
@@ -20181,7 +20375,7 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
20181
20375
|
return new Timestamp(Long.fromString(str, true, optRadix));
|
|
20182
20376
|
}
|
|
20183
20377
|
toExtendedJSON() {
|
|
20184
|
-
return { $timestamp: { t: this.
|
|
20378
|
+
return { $timestamp: { t: this.t, i: this.i } };
|
|
20185
20379
|
}
|
|
20186
20380
|
static fromExtendedJSON(doc) {
|
|
20187
20381
|
const i = Long.isLong(doc.$timestamp.i)
|
|
@@ -20194,8 +20388,8 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
20194
20388
|
}
|
|
20195
20389
|
inspect(depth, options, inspect) {
|
|
20196
20390
|
inspect ??= defaultInspect;
|
|
20197
|
-
const t = inspect(this.
|
|
20198
|
-
const i = inspect(this.
|
|
20391
|
+
const t = inspect(this.t, options);
|
|
20392
|
+
const i = inspect(this.i, options);
|
|
20199
20393
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
20200
20394
|
}
|
|
20201
20395
|
}
|
|
@@ -20278,9 +20472,8 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
20278
20472
|
throw new BSONError('corrupt bson message');
|
|
20279
20473
|
const object = isArray ? [] : {};
|
|
20280
20474
|
let arrayIndex = 0;
|
|
20281
|
-
const done = false;
|
|
20282
20475
|
let isPossibleDBRef = isArray ? false : null;
|
|
20283
|
-
while (
|
|
20476
|
+
while (true) {
|
|
20284
20477
|
const elementType = buffer[index++];
|
|
20285
20478
|
if (elementType === 0)
|
|
20286
20479
|
break;
|
|
@@ -20352,7 +20545,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
20352
20545
|
if (objectSize <= 0 || objectSize > buffer.length - index)
|
|
20353
20546
|
throw new BSONError('bad embedded document length in bson');
|
|
20354
20547
|
if (raw) {
|
|
20355
|
-
value = buffer.
|
|
20548
|
+
value = buffer.subarray(index, index + objectSize);
|
|
20356
20549
|
}
|
|
20357
20550
|
else {
|
|
20358
20551
|
let objectOptions = options;
|
|
@@ -20424,49 +20617,23 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
20424
20617
|
throw new BSONError('Negative binary type element size found');
|
|
20425
20618
|
if (binarySize > buffer.byteLength)
|
|
20426
20619
|
throw new BSONError('Binary type size larger than document size');
|
|
20427
|
-
if (
|
|
20428
|
-
|
|
20429
|
-
|
|
20430
|
-
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20434
|
-
|
|
20435
|
-
|
|
20436
|
-
|
|
20437
|
-
|
|
20438
|
-
|
|
20439
|
-
value = ByteUtils.toLocalBufferType(buffer.slice(index, index + binarySize));
|
|
20440
|
-
}
|
|
20441
|
-
else {
|
|
20442
|
-
value = new Binary(buffer.slice(index, index + binarySize), subType);
|
|
20443
|
-
if (subType === BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
|
|
20444
|
-
value = value.toUUID();
|
|
20445
|
-
}
|
|
20446
|
-
}
|
|
20620
|
+
if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
20621
|
+
binarySize = NumberUtils.getInt32LE(buffer, index);
|
|
20622
|
+
index += 4;
|
|
20623
|
+
if (binarySize < 0)
|
|
20624
|
+
throw new BSONError('Negative binary type element size found for subtype 0x02');
|
|
20625
|
+
if (binarySize > totalBinarySize - 4)
|
|
20626
|
+
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
|
|
20627
|
+
if (binarySize < totalBinarySize - 4)
|
|
20628
|
+
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
|
|
20629
|
+
}
|
|
20630
|
+
if (promoteBuffers && promoteValues) {
|
|
20631
|
+
value = ByteUtils.toLocalBufferType(buffer.subarray(index, index + binarySize));
|
|
20447
20632
|
}
|
|
20448
20633
|
else {
|
|
20449
|
-
|
|
20450
|
-
|
|
20451
|
-
|
|
20452
|
-
if (binarySize < 0)
|
|
20453
|
-
throw new BSONError('Negative binary type element size found for subtype 0x02');
|
|
20454
|
-
if (binarySize > totalBinarySize - 4)
|
|
20455
|
-
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
|
|
20456
|
-
if (binarySize < totalBinarySize - 4)
|
|
20457
|
-
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
|
|
20458
|
-
}
|
|
20459
|
-
if (promoteBuffers && promoteValues) {
|
|
20460
|
-
value = ByteUtils.allocateUnsafe(binarySize);
|
|
20461
|
-
for (i = 0; i < binarySize; i++) {
|
|
20462
|
-
value[i] = buffer[index + i];
|
|
20463
|
-
}
|
|
20464
|
-
}
|
|
20465
|
-
else {
|
|
20466
|
-
value = new Binary(buffer.slice(index, index + binarySize), subType);
|
|
20467
|
-
if (subType === BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
|
|
20468
|
-
value = value.toUUID();
|
|
20469
|
-
}
|
|
20634
|
+
value = new Binary(buffer.subarray(index, index + binarySize), subType);
|
|
20635
|
+
if (subType === BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
|
|
20636
|
+
value = value.toUUID();
|
|
20470
20637
|
}
|
|
20471
20638
|
}
|
|
20472
20639
|
index = index + binarySize;
|
|
@@ -20888,6 +21055,9 @@ function serializeBinary(buffer, key, value, index) {
|
|
|
20888
21055
|
size = size - 4;
|
|
20889
21056
|
index += NumberUtils.setInt32LE(buffer, index, size);
|
|
20890
21057
|
}
|
|
21058
|
+
if (value.sub_type === Binary.SUBTYPE_VECTOR) {
|
|
21059
|
+
validateBinaryVector(value);
|
|
21060
|
+
}
|
|
20891
21061
|
if (size <= 16) {
|
|
20892
21062
|
for (let i = 0; i < size; i++)
|
|
20893
21063
|
buffer[index + i] = data[i];
|
|
@@ -20964,79 +21134,83 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
20964
21134
|
if (typeof value?.toBSON === 'function') {
|
|
20965
21135
|
value = value.toBSON();
|
|
20966
21136
|
}
|
|
20967
|
-
|
|
20968
|
-
|
|
20969
|
-
}
|
|
20970
|
-
else if (typeof value === 'number') {
|
|
20971
|
-
index = serializeNumber(buffer, key, value, index);
|
|
20972
|
-
}
|
|
20973
|
-
else if (typeof value === 'bigint') {
|
|
20974
|
-
index = serializeBigInt(buffer, key, value, index);
|
|
20975
|
-
}
|
|
20976
|
-
else if (typeof value === 'boolean') {
|
|
20977
|
-
index = serializeBoolean(buffer, key, value, index);
|
|
20978
|
-
}
|
|
20979
|
-
else if (value instanceof Date || isDate(value)) {
|
|
20980
|
-
index = serializeDate(buffer, key, value, index);
|
|
20981
|
-
}
|
|
20982
|
-
else if (value === undefined) {
|
|
21137
|
+
const type = typeof value;
|
|
21138
|
+
if (value === undefined) {
|
|
20983
21139
|
index = serializeNull(buffer, key, value, index);
|
|
20984
21140
|
}
|
|
20985
21141
|
else if (value === null) {
|
|
20986
21142
|
index = serializeNull(buffer, key, value, index);
|
|
20987
21143
|
}
|
|
20988
|
-
else if (
|
|
20989
|
-
index =
|
|
20990
|
-
}
|
|
20991
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
20992
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
20993
|
-
}
|
|
20994
|
-
else if (typeof value === 'object' && value._bsontype == null) {
|
|
20995
|
-
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21144
|
+
else if (type === 'string') {
|
|
21145
|
+
index = serializeString(buffer, key, value, index);
|
|
20996
21146
|
}
|
|
20997
|
-
else if (
|
|
20998
|
-
|
|
20999
|
-
throw new BSONVersionError();
|
|
21147
|
+
else if (type === 'number') {
|
|
21148
|
+
index = serializeNumber(buffer, key, value, index);
|
|
21000
21149
|
}
|
|
21001
|
-
else if (
|
|
21002
|
-
index =
|
|
21150
|
+
else if (type === 'bigint') {
|
|
21151
|
+
index = serializeBigInt(buffer, key, value, index);
|
|
21003
21152
|
}
|
|
21004
|
-
else if (
|
|
21005
|
-
index =
|
|
21153
|
+
else if (type === 'boolean') {
|
|
21154
|
+
index = serializeBoolean(buffer, key, value, index);
|
|
21006
21155
|
}
|
|
21007
|
-
else if (
|
|
21008
|
-
|
|
21156
|
+
else if (type === 'object' && value._bsontype == null) {
|
|
21157
|
+
if (value instanceof Date || isDate(value)) {
|
|
21158
|
+
index = serializeDate(buffer, key, value, index);
|
|
21159
|
+
}
|
|
21160
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
21161
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
21162
|
+
}
|
|
21163
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
21164
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
21165
|
+
}
|
|
21166
|
+
else {
|
|
21167
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21168
|
+
}
|
|
21009
21169
|
}
|
|
21010
|
-
else if (
|
|
21011
|
-
|
|
21170
|
+
else if (type === 'object') {
|
|
21171
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
21172
|
+
throw new BSONVersionError();
|
|
21173
|
+
}
|
|
21174
|
+
else if (value._bsontype === 'ObjectId') {
|
|
21175
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
21176
|
+
}
|
|
21177
|
+
else if (value._bsontype === 'Decimal128') {
|
|
21178
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
21179
|
+
}
|
|
21180
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
21181
|
+
index = serializeLong(buffer, key, value, index);
|
|
21182
|
+
}
|
|
21183
|
+
else if (value._bsontype === 'Double') {
|
|
21184
|
+
index = serializeDouble(buffer, key, value, index);
|
|
21185
|
+
}
|
|
21186
|
+
else if (value._bsontype === 'Code') {
|
|
21187
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21188
|
+
}
|
|
21189
|
+
else if (value._bsontype === 'Binary') {
|
|
21190
|
+
index = serializeBinary(buffer, key, value, index);
|
|
21191
|
+
}
|
|
21192
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
21193
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
21194
|
+
}
|
|
21195
|
+
else if (value._bsontype === 'DBRef') {
|
|
21196
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21197
|
+
}
|
|
21198
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
21199
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21200
|
+
}
|
|
21201
|
+
else if (value._bsontype === 'Int32') {
|
|
21202
|
+
index = serializeInt32(buffer, key, value, index);
|
|
21203
|
+
}
|
|
21204
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21205
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
21206
|
+
}
|
|
21207
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
21208
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21209
|
+
}
|
|
21012
21210
|
}
|
|
21013
|
-
else if (
|
|
21211
|
+
else if (type === 'function' && serializeFunctions) {
|
|
21014
21212
|
index = serializeFunction(buffer, key, value, index);
|
|
21015
21213
|
}
|
|
21016
|
-
else if (value._bsontype === 'Code') {
|
|
21017
|
-
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21018
|
-
}
|
|
21019
|
-
else if (value._bsontype === 'Binary') {
|
|
21020
|
-
index = serializeBinary(buffer, key, value, index);
|
|
21021
|
-
}
|
|
21022
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
21023
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
21024
|
-
}
|
|
21025
|
-
else if (value._bsontype === 'DBRef') {
|
|
21026
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21027
|
-
}
|
|
21028
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
21029
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21030
|
-
}
|
|
21031
|
-
else if (value._bsontype === 'Int32') {
|
|
21032
|
-
index = serializeInt32(buffer, key, value, index);
|
|
21033
|
-
}
|
|
21034
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21035
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
21036
|
-
}
|
|
21037
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
21038
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21039
|
-
}
|
|
21040
21214
|
}
|
|
21041
21215
|
}
|
|
21042
21216
|
else if (object instanceof Map || isMap(object)) {
|
|
@@ -21047,8 +21221,8 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
21047
21221
|
done = !!entry.done;
|
|
21048
21222
|
if (done)
|
|
21049
21223
|
continue;
|
|
21050
|
-
const key = entry.value[0];
|
|
21051
|
-
let value = entry.value[1];
|
|
21224
|
+
const key = entry.value ? entry.value[0] : undefined;
|
|
21225
|
+
let value = entry.value ? entry.value[1] : undefined;
|
|
21052
21226
|
if (typeof value?.toBSON === 'function') {
|
|
21053
21227
|
value = value.toBSON();
|
|
21054
21228
|
}
|
|
@@ -21066,7 +21240,14 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
21066
21240
|
}
|
|
21067
21241
|
}
|
|
21068
21242
|
}
|
|
21069
|
-
if (
|
|
21243
|
+
if (value === undefined) {
|
|
21244
|
+
if (ignoreUndefined === false)
|
|
21245
|
+
index = serializeNull(buffer, key, value, index);
|
|
21246
|
+
}
|
|
21247
|
+
else if (value === null) {
|
|
21248
|
+
index = serializeNull(buffer, key, value, index);
|
|
21249
|
+
}
|
|
21250
|
+
else if (type === 'string') {
|
|
21070
21251
|
index = serializeString(buffer, key, value, index);
|
|
21071
21252
|
}
|
|
21072
21253
|
else if (type === 'number') {
|
|
@@ -21078,64 +21259,64 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
21078
21259
|
else if (type === 'boolean') {
|
|
21079
21260
|
index = serializeBoolean(buffer, key, value, index);
|
|
21080
21261
|
}
|
|
21081
|
-
else if (value instanceof Date || isDate(value)) {
|
|
21082
|
-
index = serializeDate(buffer, key, value, index);
|
|
21083
|
-
}
|
|
21084
|
-
else if (value === null || (value === undefined && ignoreUndefined === false)) {
|
|
21085
|
-
index = serializeNull(buffer, key, value, index);
|
|
21086
|
-
}
|
|
21087
|
-
else if (isUint8Array(value)) {
|
|
21088
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
21089
|
-
}
|
|
21090
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
21091
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
21092
|
-
}
|
|
21093
21262
|
else if (type === 'object' && value._bsontype == null) {
|
|
21094
|
-
|
|
21095
|
-
|
|
21096
|
-
|
|
21097
|
-
value
|
|
21098
|
-
|
|
21099
|
-
|
|
21100
|
-
|
|
21101
|
-
|
|
21102
|
-
|
|
21103
|
-
|
|
21104
|
-
|
|
21105
|
-
|
|
21106
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
21107
|
-
index = serializeLong(buffer, key, value, index);
|
|
21108
|
-
}
|
|
21109
|
-
else if (value._bsontype === 'Double') {
|
|
21110
|
-
index = serializeDouble(buffer, key, value, index);
|
|
21263
|
+
if (value instanceof Date || isDate(value)) {
|
|
21264
|
+
index = serializeDate(buffer, key, value, index);
|
|
21265
|
+
}
|
|
21266
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
21267
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
21268
|
+
}
|
|
21269
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
21270
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
21271
|
+
}
|
|
21272
|
+
else {
|
|
21273
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21274
|
+
}
|
|
21111
21275
|
}
|
|
21112
|
-
else if (
|
|
21113
|
-
|
|
21276
|
+
else if (type === 'object') {
|
|
21277
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
21278
|
+
throw new BSONVersionError();
|
|
21279
|
+
}
|
|
21280
|
+
else if (value._bsontype === 'ObjectId') {
|
|
21281
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
21282
|
+
}
|
|
21283
|
+
else if (value._bsontype === 'Decimal128') {
|
|
21284
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
21285
|
+
}
|
|
21286
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
21287
|
+
index = serializeLong(buffer, key, value, index);
|
|
21288
|
+
}
|
|
21289
|
+
else if (value._bsontype === 'Double') {
|
|
21290
|
+
index = serializeDouble(buffer, key, value, index);
|
|
21291
|
+
}
|
|
21292
|
+
else if (value._bsontype === 'Code') {
|
|
21293
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21294
|
+
}
|
|
21295
|
+
else if (value._bsontype === 'Binary') {
|
|
21296
|
+
index = serializeBinary(buffer, key, value, index);
|
|
21297
|
+
}
|
|
21298
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
21299
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
21300
|
+
}
|
|
21301
|
+
else if (value._bsontype === 'DBRef') {
|
|
21302
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21303
|
+
}
|
|
21304
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
21305
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21306
|
+
}
|
|
21307
|
+
else if (value._bsontype === 'Int32') {
|
|
21308
|
+
index = serializeInt32(buffer, key, value, index);
|
|
21309
|
+
}
|
|
21310
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21311
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
21312
|
+
}
|
|
21313
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
21314
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21315
|
+
}
|
|
21114
21316
|
}
|
|
21115
|
-
else if (
|
|
21317
|
+
else if (type === 'function' && serializeFunctions) {
|
|
21116
21318
|
index = serializeFunction(buffer, key, value, index);
|
|
21117
21319
|
}
|
|
21118
|
-
else if (value._bsontype === 'Binary') {
|
|
21119
|
-
index = serializeBinary(buffer, key, value, index);
|
|
21120
|
-
}
|
|
21121
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
21122
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
21123
|
-
}
|
|
21124
|
-
else if (value._bsontype === 'DBRef') {
|
|
21125
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21126
|
-
}
|
|
21127
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
21128
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21129
|
-
}
|
|
21130
|
-
else if (value._bsontype === 'Int32') {
|
|
21131
|
-
index = serializeInt32(buffer, key, value, index);
|
|
21132
|
-
}
|
|
21133
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21134
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
21135
|
-
}
|
|
21136
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
21137
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21138
|
-
}
|
|
21139
21320
|
}
|
|
21140
21321
|
}
|
|
21141
21322
|
else {
|
|
@@ -21164,7 +21345,14 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
21164
21345
|
}
|
|
21165
21346
|
}
|
|
21166
21347
|
}
|
|
21167
|
-
if (
|
|
21348
|
+
if (value === undefined) {
|
|
21349
|
+
if (ignoreUndefined === false)
|
|
21350
|
+
index = serializeNull(buffer, key, value, index);
|
|
21351
|
+
}
|
|
21352
|
+
else if (value === null) {
|
|
21353
|
+
index = serializeNull(buffer, key, value, index);
|
|
21354
|
+
}
|
|
21355
|
+
else if (type === 'string') {
|
|
21168
21356
|
index = serializeString(buffer, key, value, index);
|
|
21169
21357
|
}
|
|
21170
21358
|
else if (type === 'number') {
|
|
@@ -21176,68 +21364,64 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
21176
21364
|
else if (type === 'boolean') {
|
|
21177
21365
|
index = serializeBoolean(buffer, key, value, index);
|
|
21178
21366
|
}
|
|
21179
|
-
else if (value instanceof Date || isDate(value)) {
|
|
21180
|
-
index = serializeDate(buffer, key, value, index);
|
|
21181
|
-
}
|
|
21182
|
-
else if (value === undefined) {
|
|
21183
|
-
if (ignoreUndefined === false)
|
|
21184
|
-
index = serializeNull(buffer, key, value, index);
|
|
21185
|
-
}
|
|
21186
|
-
else if (value === null) {
|
|
21187
|
-
index = serializeNull(buffer, key, value, index);
|
|
21188
|
-
}
|
|
21189
|
-
else if (isUint8Array(value)) {
|
|
21190
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
21191
|
-
}
|
|
21192
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
21193
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
21194
|
-
}
|
|
21195
21367
|
else if (type === 'object' && value._bsontype == null) {
|
|
21196
|
-
|
|
21197
|
-
|
|
21198
|
-
|
|
21199
|
-
value
|
|
21200
|
-
|
|
21201
|
-
|
|
21202
|
-
|
|
21203
|
-
|
|
21204
|
-
|
|
21205
|
-
|
|
21206
|
-
|
|
21207
|
-
|
|
21208
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
21209
|
-
index = serializeLong(buffer, key, value, index);
|
|
21210
|
-
}
|
|
21211
|
-
else if (value._bsontype === 'Double') {
|
|
21212
|
-
index = serializeDouble(buffer, key, value, index);
|
|
21368
|
+
if (value instanceof Date || isDate(value)) {
|
|
21369
|
+
index = serializeDate(buffer, key, value, index);
|
|
21370
|
+
}
|
|
21371
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
21372
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
21373
|
+
}
|
|
21374
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
21375
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
21376
|
+
}
|
|
21377
|
+
else {
|
|
21378
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21379
|
+
}
|
|
21213
21380
|
}
|
|
21214
|
-
else if (
|
|
21215
|
-
|
|
21381
|
+
else if (type === 'object') {
|
|
21382
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
21383
|
+
throw new BSONVersionError();
|
|
21384
|
+
}
|
|
21385
|
+
else if (value._bsontype === 'ObjectId') {
|
|
21386
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
21387
|
+
}
|
|
21388
|
+
else if (value._bsontype === 'Decimal128') {
|
|
21389
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
21390
|
+
}
|
|
21391
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
21392
|
+
index = serializeLong(buffer, key, value, index);
|
|
21393
|
+
}
|
|
21394
|
+
else if (value._bsontype === 'Double') {
|
|
21395
|
+
index = serializeDouble(buffer, key, value, index);
|
|
21396
|
+
}
|
|
21397
|
+
else if (value._bsontype === 'Code') {
|
|
21398
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
21399
|
+
}
|
|
21400
|
+
else if (value._bsontype === 'Binary') {
|
|
21401
|
+
index = serializeBinary(buffer, key, value, index);
|
|
21402
|
+
}
|
|
21403
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
21404
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
21405
|
+
}
|
|
21406
|
+
else if (value._bsontype === 'DBRef') {
|
|
21407
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21408
|
+
}
|
|
21409
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
21410
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21411
|
+
}
|
|
21412
|
+
else if (value._bsontype === 'Int32') {
|
|
21413
|
+
index = serializeInt32(buffer, key, value, index);
|
|
21414
|
+
}
|
|
21415
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21416
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
21417
|
+
}
|
|
21418
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
21419
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21420
|
+
}
|
|
21216
21421
|
}
|
|
21217
|
-
else if (
|
|
21422
|
+
else if (type === 'function' && serializeFunctions) {
|
|
21218
21423
|
index = serializeFunction(buffer, key, value, index);
|
|
21219
21424
|
}
|
|
21220
|
-
else if (value._bsontype === 'Binary') {
|
|
21221
|
-
index = serializeBinary(buffer, key, value, index);
|
|
21222
|
-
}
|
|
21223
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
21224
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
21225
|
-
}
|
|
21226
|
-
else if (value._bsontype === 'DBRef') {
|
|
21227
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
21228
|
-
}
|
|
21229
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
21230
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
21231
|
-
}
|
|
21232
|
-
else if (value._bsontype === 'Int32') {
|
|
21233
|
-
index = serializeInt32(buffer, key, value, index);
|
|
21234
|
-
}
|
|
21235
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
21236
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
21237
|
-
}
|
|
21238
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
21239
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
21240
|
-
}
|
|
21241
21425
|
}
|
|
21242
21426
|
}
|
|
21243
21427
|
path.delete(object);
|
|
@@ -21489,7 +21673,7 @@ function serializeDocument(doc, options) {
|
|
|
21489
21673
|
else if (doc != null &&
|
|
21490
21674
|
typeof doc === 'object' &&
|
|
21491
21675
|
typeof doc._bsontype === 'string' &&
|
|
21492
|
-
doc[
|
|
21676
|
+
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
21493
21677
|
throw new BSONVersionError();
|
|
21494
21678
|
}
|
|
21495
21679
|
else if (isBSONType(doc)) {
|
|
@@ -23635,105 +23819,174 @@ var hexSliceLookupTable = (function () {
|
|
|
23635
23819
|
\***********************************************/
|
|
23636
23820
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
23637
23821
|
|
|
23638
|
-
|
|
23639
|
-
var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform)
|
|
23640
|
-
var StringDecoder = (__webpack_require__(/*! string_decoder */ "../../node_modules/string_decoder/lib/string_decoder.js").StringDecoder)
|
|
23641
|
-
var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js")
|
|
23822
|
+
"use strict";
|
|
23642
23823
|
|
|
23643
|
-
function CipherBase (hashMode) {
|
|
23644
|
-
Transform.call(this)
|
|
23645
|
-
this.hashMode = typeof hashMode === 'string'
|
|
23646
|
-
if (this.hashMode) {
|
|
23647
|
-
this[hashMode] = this._finalOrDigest
|
|
23648
|
-
} else {
|
|
23649
|
-
this.final = this._finalOrDigest
|
|
23650
|
-
}
|
|
23651
|
-
if (this._final) {
|
|
23652
|
-
this.__final = this._final
|
|
23653
|
-
this._final = null
|
|
23654
|
-
}
|
|
23655
|
-
this._decoder = null
|
|
23656
|
-
this._encoding = null
|
|
23657
|
-
}
|
|
23658
|
-
inherits(CipherBase, Transform)
|
|
23659
23824
|
|
|
23660
|
-
|
|
23661
|
-
|
|
23662
|
-
|
|
23663
|
-
|
|
23825
|
+
var Buffer = (__webpack_require__(/*! safe-buffer */ "../../node_modules/safe-buffer/index.js").Buffer);
|
|
23826
|
+
var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform);
|
|
23827
|
+
var StringDecoder = (__webpack_require__(/*! string_decoder */ "../../node_modules/string_decoder/lib/string_decoder.js").StringDecoder);
|
|
23828
|
+
var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js");
|
|
23829
|
+
|
|
23830
|
+
function CipherBase(hashMode) {
|
|
23831
|
+
Transform.call(this);
|
|
23832
|
+
this.hashMode = typeof hashMode === 'string';
|
|
23833
|
+
if (this.hashMode) {
|
|
23834
|
+
this[hashMode] = this._finalOrDigest;
|
|
23835
|
+
} else {
|
|
23836
|
+
this['final'] = this._finalOrDigest;
|
|
23837
|
+
}
|
|
23838
|
+
if (this._final) {
|
|
23839
|
+
this.__final = this._final;
|
|
23840
|
+
this._final = null;
|
|
23841
|
+
}
|
|
23842
|
+
this._decoder = null;
|
|
23843
|
+
this._encoding = null;
|
|
23844
|
+
}
|
|
23845
|
+
inherits(CipherBase, Transform);
|
|
23846
|
+
|
|
23847
|
+
var useUint8Array = typeof Uint8Array !== 'undefined';
|
|
23848
|
+
var useArrayBuffer = typeof ArrayBuffer !== 'undefined'
|
|
23849
|
+
&& typeof Uint8Array !== 'undefined'
|
|
23850
|
+
&& ArrayBuffer.isView
|
|
23851
|
+
&& (Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT);
|
|
23852
|
+
|
|
23853
|
+
function toBuffer(data, encoding) {
|
|
23854
|
+
/*
|
|
23855
|
+
* No need to do anything for exact instance
|
|
23856
|
+
* This is only valid when safe-buffer.Buffer === buffer.Buffer, i.e. when Buffer.from/Buffer.alloc existed
|
|
23857
|
+
*/
|
|
23858
|
+
if (data instanceof Buffer) {
|
|
23859
|
+
return data;
|
|
23860
|
+
}
|
|
23664
23861
|
|
|
23665
|
-
|
|
23666
|
-
|
|
23862
|
+
// Convert strings to Buffer
|
|
23863
|
+
if (typeof data === 'string') {
|
|
23864
|
+
return Buffer.from(data, encoding);
|
|
23865
|
+
}
|
|
23667
23866
|
|
|
23668
|
-
|
|
23669
|
-
|
|
23670
|
-
|
|
23867
|
+
/*
|
|
23868
|
+
* Wrap any TypedArray instances and DataViews
|
|
23869
|
+
* Makes sense only on engines with full TypedArray support -- let Buffer detect that
|
|
23870
|
+
*/
|
|
23871
|
+
if (useArrayBuffer && ArrayBuffer.isView(data)) {
|
|
23872
|
+
// Bug in Node.js <6.3.1, which treats this as out-of-bounds
|
|
23873
|
+
if (data.byteLength === 0) {
|
|
23874
|
+
return Buffer.alloc(0);
|
|
23875
|
+
}
|
|
23876
|
+
|
|
23877
|
+
var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
23878
|
+
/*
|
|
23879
|
+
* Recheck result size, as offset/length doesn't work on Node.js <5.10
|
|
23880
|
+
* We just go to Uint8Array case if this fails
|
|
23881
|
+
*/
|
|
23882
|
+
if (res.byteLength === data.byteLength) {
|
|
23883
|
+
return res;
|
|
23884
|
+
}
|
|
23885
|
+
}
|
|
23886
|
+
|
|
23887
|
+
/*
|
|
23888
|
+
* Uint8Array in engines where Buffer.from might not work with ArrayBuffer, just copy over
|
|
23889
|
+
* Doesn't make sense with other TypedArray instances
|
|
23890
|
+
*/
|
|
23891
|
+
if (useUint8Array && data instanceof Uint8Array) {
|
|
23892
|
+
return Buffer.from(data);
|
|
23893
|
+
}
|
|
23671
23894
|
|
|
23672
|
-
|
|
23895
|
+
/*
|
|
23896
|
+
* Old Buffer polyfill on an engine that doesn't have TypedArray support
|
|
23897
|
+
* Also, this is from a different Buffer polyfill implementation then we have, as instanceof check failed
|
|
23898
|
+
* Convert to our current Buffer implementation
|
|
23899
|
+
*/
|
|
23900
|
+
if (
|
|
23901
|
+
Buffer.isBuffer(data)
|
|
23902
|
+
&& data.constructor
|
|
23903
|
+
&& typeof data.constructor.isBuffer === 'function'
|
|
23904
|
+
&& data.constructor.isBuffer(data)
|
|
23905
|
+
) {
|
|
23906
|
+
return Buffer.from(data);
|
|
23907
|
+
}
|
|
23908
|
+
|
|
23909
|
+
throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.');
|
|
23673
23910
|
}
|
|
23674
23911
|
|
|
23675
|
-
CipherBase.prototype.
|
|
23912
|
+
CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
|
|
23913
|
+
var bufferData = toBuffer(data, inputEnc); // asserts correct input type
|
|
23914
|
+
var outData = this._update(bufferData);
|
|
23915
|
+
if (this.hashMode) {
|
|
23916
|
+
return this;
|
|
23917
|
+
}
|
|
23918
|
+
|
|
23919
|
+
if (outputEnc) {
|
|
23920
|
+
outData = this._toString(outData, outputEnc);
|
|
23921
|
+
}
|
|
23922
|
+
|
|
23923
|
+
return outData;
|
|
23924
|
+
};
|
|
23925
|
+
|
|
23926
|
+
CipherBase.prototype.setAutoPadding = function () {};
|
|
23676
23927
|
CipherBase.prototype.getAuthTag = function () {
|
|
23677
|
-
|
|
23678
|
-
}
|
|
23928
|
+
throw new Error('trying to get auth tag in unsupported state');
|
|
23929
|
+
};
|
|
23679
23930
|
|
|
23680
23931
|
CipherBase.prototype.setAuthTag = function () {
|
|
23681
|
-
|
|
23682
|
-
}
|
|
23932
|
+
throw new Error('trying to set auth tag in unsupported state');
|
|
23933
|
+
};
|
|
23683
23934
|
|
|
23684
23935
|
CipherBase.prototype.setAAD = function () {
|
|
23685
|
-
|
|
23686
|
-
}
|
|
23936
|
+
throw new Error('trying to set aad in unsupported state');
|
|
23937
|
+
};
|
|
23687
23938
|
|
|
23688
23939
|
CipherBase.prototype._transform = function (data, _, next) {
|
|
23689
|
-
|
|
23690
|
-
|
|
23691
|
-
|
|
23692
|
-
|
|
23693
|
-
|
|
23694
|
-
|
|
23695
|
-
|
|
23696
|
-
|
|
23697
|
-
|
|
23698
|
-
|
|
23699
|
-
|
|
23700
|
-
|
|
23701
|
-
}
|
|
23940
|
+
var err;
|
|
23941
|
+
try {
|
|
23942
|
+
if (this.hashMode) {
|
|
23943
|
+
this._update(data);
|
|
23944
|
+
} else {
|
|
23945
|
+
this.push(this._update(data));
|
|
23946
|
+
}
|
|
23947
|
+
} catch (e) {
|
|
23948
|
+
err = e;
|
|
23949
|
+
} finally {
|
|
23950
|
+
next(err);
|
|
23951
|
+
}
|
|
23952
|
+
};
|
|
23702
23953
|
CipherBase.prototype._flush = function (done) {
|
|
23703
|
-
|
|
23704
|
-
|
|
23705
|
-
|
|
23706
|
-
|
|
23707
|
-
|
|
23708
|
-
|
|
23954
|
+
var err;
|
|
23955
|
+
try {
|
|
23956
|
+
this.push(this.__final());
|
|
23957
|
+
} catch (e) {
|
|
23958
|
+
err = e;
|
|
23959
|
+
}
|
|
23709
23960
|
|
|
23710
|
-
|
|
23711
|
-
}
|
|
23961
|
+
done(err);
|
|
23962
|
+
};
|
|
23712
23963
|
CipherBase.prototype._finalOrDigest = function (outputEnc) {
|
|
23713
|
-
|
|
23714
|
-
|
|
23715
|
-
|
|
23716
|
-
|
|
23717
|
-
|
|
23718
|
-
}
|
|
23964
|
+
var outData = this.__final() || Buffer.alloc(0);
|
|
23965
|
+
if (outputEnc) {
|
|
23966
|
+
outData = this._toString(outData, outputEnc, true);
|
|
23967
|
+
}
|
|
23968
|
+
return outData;
|
|
23969
|
+
};
|
|
23719
23970
|
|
|
23720
23971
|
CipherBase.prototype._toString = function (value, enc, fin) {
|
|
23721
|
-
|
|
23722
|
-
|
|
23723
|
-
|
|
23724
|
-
|
|
23972
|
+
if (!this._decoder) {
|
|
23973
|
+
this._decoder = new StringDecoder(enc);
|
|
23974
|
+
this._encoding = enc;
|
|
23975
|
+
}
|
|
23725
23976
|
|
|
23726
|
-
|
|
23977
|
+
if (this._encoding !== enc) {
|
|
23978
|
+
throw new Error('can’t switch encodings');
|
|
23979
|
+
}
|
|
23727
23980
|
|
|
23728
|
-
|
|
23729
|
-
|
|
23730
|
-
|
|
23731
|
-
|
|
23981
|
+
var out = this._decoder.write(value);
|
|
23982
|
+
if (fin) {
|
|
23983
|
+
out += this._decoder.end();
|
|
23984
|
+
}
|
|
23732
23985
|
|
|
23733
|
-
|
|
23734
|
-
}
|
|
23986
|
+
return out;
|
|
23987
|
+
};
|
|
23735
23988
|
|
|
23736
|
-
module.exports = CipherBase
|
|
23989
|
+
module.exports = CipherBase;
|
|
23737
23990
|
|
|
23738
23991
|
|
|
23739
23992
|
/***/ }),
|
|
@@ -24184,101 +24437,107 @@ module.exports = Hmac
|
|
|
24184
24437
|
"use strict";
|
|
24185
24438
|
|
|
24186
24439
|
|
|
24187
|
-
|
|
24188
|
-
exports.
|
|
24189
|
-
|
|
24440
|
+
// eslint-disable-next-line no-multi-assign
|
|
24441
|
+
exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = __webpack_require__(/*! randombytes */ "../../node_modules/randombytes/browser.js");
|
|
24442
|
+
|
|
24443
|
+
// eslint-disable-next-line no-multi-assign
|
|
24444
|
+
exports.createHash = exports.Hash = __webpack_require__(/*! create-hash */ "../../node_modules/create-hash/browser.js");
|
|
24445
|
+
|
|
24446
|
+
// eslint-disable-next-line no-multi-assign
|
|
24447
|
+
exports.createHmac = exports.Hmac = __webpack_require__(/*! create-hmac */ "../../node_modules/create-hmac/browser.js");
|
|
24448
|
+
|
|
24449
|
+
var algos = __webpack_require__(/*! browserify-sign/algos */ "../../node_modules/browserify-sign/algos.js");
|
|
24450
|
+
var algoKeys = Object.keys(algos);
|
|
24451
|
+
var hashes = [
|
|
24452
|
+
'sha1',
|
|
24453
|
+
'sha224',
|
|
24454
|
+
'sha256',
|
|
24455
|
+
'sha384',
|
|
24456
|
+
'sha512',
|
|
24457
|
+
'md5',
|
|
24458
|
+
'rmd160'
|
|
24459
|
+
].concat(algoKeys);
|
|
24190
24460
|
|
|
24191
|
-
var algos = __webpack_require__(/*! browserify-sign/algos */ "../../node_modules/browserify-sign/algos.js")
|
|
24192
|
-
var algoKeys = Object.keys(algos)
|
|
24193
|
-
var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
|
|
24194
24461
|
exports.getHashes = function () {
|
|
24195
|
-
|
|
24196
|
-
}
|
|
24462
|
+
return hashes;
|
|
24463
|
+
};
|
|
24197
24464
|
|
|
24198
|
-
var p = __webpack_require__(/*! pbkdf2 */ "../../node_modules/pbkdf2/browser.js")
|
|
24199
|
-
exports.pbkdf2 = p.pbkdf2
|
|
24200
|
-
exports.pbkdf2Sync = p.pbkdf2Sync
|
|
24465
|
+
var p = __webpack_require__(/*! pbkdf2 */ "../../node_modules/pbkdf2/browser.js");
|
|
24466
|
+
exports.pbkdf2 = p.pbkdf2;
|
|
24467
|
+
exports.pbkdf2Sync = p.pbkdf2Sync;
|
|
24201
24468
|
|
|
24202
|
-
var aes = __webpack_require__(/*! browserify-cipher */ "../../node_modules/browserify-cipher/browser.js")
|
|
24469
|
+
var aes = __webpack_require__(/*! browserify-cipher */ "../../node_modules/browserify-cipher/browser.js");
|
|
24203
24470
|
|
|
24204
|
-
exports.Cipher = aes.Cipher
|
|
24205
|
-
exports.createCipher = aes.createCipher
|
|
24206
|
-
exports.Cipheriv = aes.Cipheriv
|
|
24207
|
-
exports.createCipheriv = aes.createCipheriv
|
|
24208
|
-
exports.Decipher = aes.Decipher
|
|
24209
|
-
exports.createDecipher = aes.createDecipher
|
|
24210
|
-
exports.Decipheriv = aes.Decipheriv
|
|
24211
|
-
exports.createDecipheriv = aes.createDecipheriv
|
|
24212
|
-
exports.getCiphers = aes.getCiphers
|
|
24213
|
-
exports.listCiphers = aes.listCiphers
|
|
24471
|
+
exports.Cipher = aes.Cipher;
|
|
24472
|
+
exports.createCipher = aes.createCipher;
|
|
24473
|
+
exports.Cipheriv = aes.Cipheriv;
|
|
24474
|
+
exports.createCipheriv = aes.createCipheriv;
|
|
24475
|
+
exports.Decipher = aes.Decipher;
|
|
24476
|
+
exports.createDecipher = aes.createDecipher;
|
|
24477
|
+
exports.Decipheriv = aes.Decipheriv;
|
|
24478
|
+
exports.createDecipheriv = aes.createDecipheriv;
|
|
24479
|
+
exports.getCiphers = aes.getCiphers;
|
|
24480
|
+
exports.listCiphers = aes.listCiphers;
|
|
24214
24481
|
|
|
24215
|
-
var dh = __webpack_require__(/*! diffie-hellman */ "../../node_modules/diffie-hellman/browser.js")
|
|
24482
|
+
var dh = __webpack_require__(/*! diffie-hellman */ "../../node_modules/diffie-hellman/browser.js");
|
|
24216
24483
|
|
|
24217
|
-
exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
|
|
24218
|
-
exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
|
|
24219
|
-
exports.getDiffieHellman = dh.getDiffieHellman
|
|
24220
|
-
exports.createDiffieHellman = dh.createDiffieHellman
|
|
24221
|
-
exports.DiffieHellman = dh.DiffieHellman
|
|
24484
|
+
exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
|
|
24485
|
+
exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
|
|
24486
|
+
exports.getDiffieHellman = dh.getDiffieHellman;
|
|
24487
|
+
exports.createDiffieHellman = dh.createDiffieHellman;
|
|
24488
|
+
exports.DiffieHellman = dh.DiffieHellman;
|
|
24222
24489
|
|
|
24223
|
-
var sign = __webpack_require__(/*! browserify-sign */ "../../node_modules/browserify-sign/browser/index.js")
|
|
24490
|
+
var sign = __webpack_require__(/*! browserify-sign */ "../../node_modules/browserify-sign/browser/index.js");
|
|
24224
24491
|
|
|
24225
|
-
exports.createSign = sign.createSign
|
|
24226
|
-
exports.Sign = sign.Sign
|
|
24227
|
-
exports.createVerify = sign.createVerify
|
|
24228
|
-
exports.Verify = sign.Verify
|
|
24492
|
+
exports.createSign = sign.createSign;
|
|
24493
|
+
exports.Sign = sign.Sign;
|
|
24494
|
+
exports.createVerify = sign.createVerify;
|
|
24495
|
+
exports.Verify = sign.Verify;
|
|
24229
24496
|
|
|
24230
|
-
exports.createECDH = __webpack_require__(/*! create-ecdh */ "../../node_modules/create-ecdh/browser.js")
|
|
24497
|
+
exports.createECDH = __webpack_require__(/*! create-ecdh */ "../../node_modules/create-ecdh/browser.js");
|
|
24231
24498
|
|
|
24232
|
-
var publicEncrypt = __webpack_require__(/*! public-encrypt */ "../../node_modules/public-encrypt/browser.js")
|
|
24499
|
+
var publicEncrypt = __webpack_require__(/*! public-encrypt */ "../../node_modules/public-encrypt/browser.js");
|
|
24233
24500
|
|
|
24234
|
-
exports.publicEncrypt = publicEncrypt.publicEncrypt
|
|
24235
|
-
exports.privateEncrypt = publicEncrypt.privateEncrypt
|
|
24236
|
-
exports.publicDecrypt = publicEncrypt.publicDecrypt
|
|
24237
|
-
exports.privateDecrypt = publicEncrypt.privateDecrypt
|
|
24501
|
+
exports.publicEncrypt = publicEncrypt.publicEncrypt;
|
|
24502
|
+
exports.privateEncrypt = publicEncrypt.privateEncrypt;
|
|
24503
|
+
exports.publicDecrypt = publicEncrypt.publicDecrypt;
|
|
24504
|
+
exports.privateDecrypt = publicEncrypt.privateDecrypt;
|
|
24238
24505
|
|
|
24239
24506
|
// the least I can do is make error messages for the rest of the node.js/crypto api.
|
|
24240
|
-
//
|
|
24507
|
+
// [
|
|
24241
24508
|
// 'createCredentials'
|
|
24242
24509
|
// ].forEach(function (name) {
|
|
24243
24510
|
// exports[name] = function () {
|
|
24244
|
-
// throw new Error(
|
|
24245
|
-
//
|
|
24246
|
-
//
|
|
24247
|
-
// 'https://github.com/crypto-browserify/crypto-browserify'
|
|
24248
|
-
// ].join('\n'))
|
|
24249
|
-
// }
|
|
24250
|
-
// })
|
|
24511
|
+
// throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
|
|
24512
|
+
// };
|
|
24513
|
+
// });
|
|
24251
24514
|
|
|
24252
|
-
var rf = __webpack_require__(/*! randomfill */ "../../node_modules/randomfill/browser.js")
|
|
24515
|
+
var rf = __webpack_require__(/*! randomfill */ "../../node_modules/randomfill/browser.js");
|
|
24253
24516
|
|
|
24254
|
-
exports.randomFill = rf.randomFill
|
|
24255
|
-
exports.randomFillSync = rf.randomFillSync
|
|
24517
|
+
exports.randomFill = rf.randomFill;
|
|
24518
|
+
exports.randomFillSync = rf.randomFillSync;
|
|
24256
24519
|
|
|
24257
24520
|
exports.createCredentials = function () {
|
|
24258
|
-
|
|
24259
|
-
|
|
24260
|
-
'we accept pull requests',
|
|
24261
|
-
'https://github.com/crypto-browserify/crypto-browserify'
|
|
24262
|
-
].join('\n'))
|
|
24263
|
-
}
|
|
24521
|
+
throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
|
|
24522
|
+
};
|
|
24264
24523
|
|
|
24265
24524
|
exports.constants = {
|
|
24266
|
-
|
|
24267
|
-
|
|
24268
|
-
|
|
24269
|
-
|
|
24270
|
-
|
|
24271
|
-
|
|
24272
|
-
|
|
24273
|
-
|
|
24274
|
-
|
|
24275
|
-
|
|
24276
|
-
|
|
24277
|
-
|
|
24278
|
-
|
|
24279
|
-
|
|
24280
|
-
|
|
24281
|
-
}
|
|
24525
|
+
DH_CHECK_P_NOT_SAFE_PRIME: 2,
|
|
24526
|
+
DH_CHECK_P_NOT_PRIME: 1,
|
|
24527
|
+
DH_UNABLE_TO_CHECK_GENERATOR: 4,
|
|
24528
|
+
DH_NOT_SUITABLE_GENERATOR: 8,
|
|
24529
|
+
NPN_ENABLED: 1,
|
|
24530
|
+
ALPN_ENABLED: 1,
|
|
24531
|
+
RSA_PKCS1_PADDING: 1,
|
|
24532
|
+
RSA_SSLV23_PADDING: 2,
|
|
24533
|
+
RSA_NO_PADDING: 3,
|
|
24534
|
+
RSA_PKCS1_OAEP_PADDING: 4,
|
|
24535
|
+
RSA_X931_PADDING: 5,
|
|
24536
|
+
RSA_PKCS1_PSS_PADDING: 6,
|
|
24537
|
+
POINT_CONVERSION_COMPRESSED: 2,
|
|
24538
|
+
POINT_CONVERSION_UNCOMPRESSED: 4,
|
|
24539
|
+
POINT_CONVERSION_HYBRID: 6
|
|
24540
|
+
};
|
|
24282
24541
|
|
|
24283
24542
|
|
|
24284
24543
|
/***/ }),
|
|
@@ -27698,8 +27957,27 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
|
|
|
27698
27957
|
}
|
|
27699
27958
|
};
|
|
27700
27959
|
|
|
27701
|
-
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
|
|
27702
|
-
var
|
|
27960
|
+
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
|
|
27961
|
+
var byteLength;
|
|
27962
|
+
if (BN.isBN(msg) || typeof msg === 'number') {
|
|
27963
|
+
msg = new BN(msg, 16);
|
|
27964
|
+
byteLength = msg.byteLength();
|
|
27965
|
+
} else if (typeof msg === 'object') {
|
|
27966
|
+
// BN assumes an array-like input and asserts length
|
|
27967
|
+
byteLength = msg.length;
|
|
27968
|
+
msg = new BN(msg, 16);
|
|
27969
|
+
} else {
|
|
27970
|
+
// BN converts the value to string
|
|
27971
|
+
var str = msg.toString();
|
|
27972
|
+
// HEX encoding
|
|
27973
|
+
byteLength = (str.length + 1) >>> 1;
|
|
27974
|
+
msg = new BN(str, 16);
|
|
27975
|
+
}
|
|
27976
|
+
// Allow overriding
|
|
27977
|
+
if (typeof bitLength !== 'number') {
|
|
27978
|
+
bitLength = byteLength * 8;
|
|
27979
|
+
}
|
|
27980
|
+
var delta = bitLength - this.n.bitLength();
|
|
27703
27981
|
if (delta > 0)
|
|
27704
27982
|
msg = msg.ushrn(delta);
|
|
27705
27983
|
if (!truncOnly && msg.cmp(this.n) >= 0)
|
|
@@ -27716,8 +27994,18 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
|
|
|
27716
27994
|
if (!options)
|
|
27717
27995
|
options = {};
|
|
27718
27996
|
|
|
27997
|
+
if (typeof msg !== 'string' && typeof msg !== 'number' && !BN.isBN(msg)) {
|
|
27998
|
+
assert(typeof msg === 'object' && msg && typeof msg.length === 'number',
|
|
27999
|
+
'Expected message to be an array-like, a hex string, or a BN instance');
|
|
28000
|
+
assert((msg.length >>> 0) === msg.length); // non-negative 32-bit integer
|
|
28001
|
+
for (var i = 0; i < msg.length; i++) assert((msg[i] & 255) === msg[i]);
|
|
28002
|
+
}
|
|
28003
|
+
|
|
27719
28004
|
key = this.keyFromPrivate(key, enc);
|
|
27720
|
-
msg = this._truncateToN(
|
|
28005
|
+
msg = this._truncateToN(msg, false, options.msgBitLength);
|
|
28006
|
+
|
|
28007
|
+
// Would fail further checks, but let's make the error message clear
|
|
28008
|
+
assert(!msg.isNeg(), 'Can not sign a negative message');
|
|
27721
28009
|
|
|
27722
28010
|
// Zero-extend key to provide enough entropy
|
|
27723
28011
|
var bytes = this.n.byteLength();
|
|
@@ -27726,6 +28014,9 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
|
|
|
27726
28014
|
// Zero-extend nonce to have the same byte size as N
|
|
27727
28015
|
var nonce = msg.toArray('be', bytes);
|
|
27728
28016
|
|
|
28017
|
+
// Recheck nonce to be bijective to msg
|
|
28018
|
+
assert((new BN(nonce)).eq(msg), 'Can not sign message');
|
|
28019
|
+
|
|
27729
28020
|
// Instantiate Hmac_DRBG
|
|
27730
28021
|
var drbg = new HmacDRBG({
|
|
27731
28022
|
hash: this.hash,
|
|
@@ -27773,8 +28064,11 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
|
|
|
27773
28064
|
}
|
|
27774
28065
|
};
|
|
27775
28066
|
|
|
27776
|
-
EC.prototype.verify = function verify(msg, signature, key, enc) {
|
|
27777
|
-
|
|
28067
|
+
EC.prototype.verify = function verify(msg, signature, key, enc, options) {
|
|
28068
|
+
if (!options)
|
|
28069
|
+
options = {};
|
|
28070
|
+
|
|
28071
|
+
msg = this._truncateToN(msg, false, options.msgBitLength);
|
|
27778
28072
|
key = this.keyFromPublic(key, enc);
|
|
27779
28073
|
signature = new Signature(signature, 'hex');
|
|
27780
28074
|
|
|
@@ -27985,8 +28279,8 @@ KeyPair.prototype.sign = function sign(msg, enc, options) {
|
|
|
27985
28279
|
return this.ec.sign(msg, this, enc, options);
|
|
27986
28280
|
};
|
|
27987
28281
|
|
|
27988
|
-
KeyPair.prototype.verify = function verify(msg, signature) {
|
|
27989
|
-
return this.ec.verify(msg, signature, this);
|
|
28282
|
+
KeyPair.prototype.verify = function verify(msg, signature, options) {
|
|
28283
|
+
return this.ec.verify(msg, signature, this, undefined, options);
|
|
27990
28284
|
};
|
|
27991
28285
|
|
|
27992
28286
|
KeyPair.prototype.inspect = function inspect() {
|
|
@@ -29429,7 +29723,7 @@ utils.intFromLE = intFromLE;
|
|
|
29429
29723
|
/***/ ((module) => {
|
|
29430
29724
|
|
|
29431
29725
|
"use strict";
|
|
29432
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"elliptic","version":"6.
|
|
29726
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"elliptic","version":"6.6.1","description":"EC cryptography","main":"lib/elliptic.js","files":["lib"],"scripts":{"lint":"eslint lib test","lint:fix":"npm run lint -- --fix","unit":"istanbul test _mocha --reporter=spec test/index.js","test":"npm run lint && npm run unit","version":"grunt dist && git add dist/"},"repository":{"type":"git","url":"git@github.com:indutny/elliptic"},"keywords":["EC","Elliptic","curve","Cryptography"],"author":"Fedor Indutny <fedor@indutny.com>","license":"MIT","bugs":{"url":"https://github.com/indutny/elliptic/issues"},"homepage":"https://github.com/indutny/elliptic","devDependencies":{"brfs":"^2.0.2","coveralls":"^3.1.0","eslint":"^7.6.0","grunt":"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1","istanbul":"^0.4.5","mocha":"^8.0.1"},"dependencies":{"bn.js":"^4.11.9","brorand":"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1","inherits":"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}');
|
|
29433
29727
|
|
|
29434
29728
|
/***/ }),
|
|
29435
29729
|
|
|
@@ -30005,15 +30299,9 @@ module.exports = EVP_BytesToKey
|
|
|
30005
30299
|
"use strict";
|
|
30006
30300
|
|
|
30007
30301
|
var Buffer = (__webpack_require__(/*! safe-buffer */ "../../node_modules/safe-buffer/index.js").Buffer)
|
|
30008
|
-
var Transform = (__webpack_require__(/*!
|
|
30302
|
+
var Transform = (__webpack_require__(/*! stream */ "../../node_modules/stream-browserify/index.js").Transform)
|
|
30009
30303
|
var inherits = __webpack_require__(/*! inherits */ "../../node_modules/inherits/inherits_browser.js")
|
|
30010
30304
|
|
|
30011
|
-
function throwIfNotStringOrBuffer (val, prefix) {
|
|
30012
|
-
if (!Buffer.isBuffer(val) && typeof val !== 'string') {
|
|
30013
|
-
throw new TypeError(prefix + ' must be a string or a buffer')
|
|
30014
|
-
}
|
|
30015
|
-
}
|
|
30016
|
-
|
|
30017
30305
|
function HashBase (blockSize) {
|
|
30018
30306
|
Transform.call(this)
|
|
30019
30307
|
|
|
@@ -30049,10 +30337,59 @@ HashBase.prototype._flush = function (callback) {
|
|
|
30049
30337
|
callback(error)
|
|
30050
30338
|
}
|
|
30051
30339
|
|
|
30340
|
+
var useUint8Array = typeof Uint8Array !== 'undefined'
|
|
30341
|
+
var useArrayBuffer = typeof ArrayBuffer !== 'undefined' &&
|
|
30342
|
+
typeof Uint8Array !== 'undefined' &&
|
|
30343
|
+
ArrayBuffer.isView &&
|
|
30344
|
+
(Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT)
|
|
30345
|
+
|
|
30346
|
+
function toBuffer (data, encoding) {
|
|
30347
|
+
// No need to do anything for exact instance
|
|
30348
|
+
// This is only valid when safe-buffer.Buffer === buffer.Buffer, i.e. when Buffer.from/Buffer.alloc existed
|
|
30349
|
+
if (data instanceof Buffer) return data
|
|
30350
|
+
|
|
30351
|
+
// Convert strings to Buffer
|
|
30352
|
+
if (typeof data === 'string') return Buffer.from(data, encoding)
|
|
30353
|
+
|
|
30354
|
+
/*
|
|
30355
|
+
* Wrap any TypedArray instances and DataViews
|
|
30356
|
+
* Makes sense only on engines with full TypedArray support -- let Buffer detect that
|
|
30357
|
+
*/
|
|
30358
|
+
if (useArrayBuffer && ArrayBuffer.isView(data)) {
|
|
30359
|
+
if (data.byteLength === 0) return Buffer.alloc(0) // Bug in Node.js <6.3.1, which treats this as out-of-bounds
|
|
30360
|
+
var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
|
30361
|
+
// Recheck result size, as offset/length doesn't work on Node.js <5.10
|
|
30362
|
+
// We just go to Uint8Array case if this fails
|
|
30363
|
+
if (res.byteLength === data.byteLength) return res
|
|
30364
|
+
}
|
|
30365
|
+
|
|
30366
|
+
/*
|
|
30367
|
+
* Uint8Array in engines where Buffer.from might not work with ArrayBuffer, just copy over
|
|
30368
|
+
* Doesn't make sense with other TypedArray instances
|
|
30369
|
+
*/
|
|
30370
|
+
if (useUint8Array && data instanceof Uint8Array) return Buffer.from(data)
|
|
30371
|
+
|
|
30372
|
+
/*
|
|
30373
|
+
* Old Buffer polyfill on an engine that doesn't have TypedArray support
|
|
30374
|
+
* Also, this is from a different Buffer polyfill implementation then we have, as instanceof check failed
|
|
30375
|
+
* Convert to our current Buffer implementation
|
|
30376
|
+
*/
|
|
30377
|
+
if (
|
|
30378
|
+
Buffer.isBuffer(data) &&
|
|
30379
|
+
data.constructor &&
|
|
30380
|
+
typeof data.constructor.isBuffer === 'function' &&
|
|
30381
|
+
data.constructor.isBuffer(data)
|
|
30382
|
+
) {
|
|
30383
|
+
return Buffer.from(data)
|
|
30384
|
+
}
|
|
30385
|
+
|
|
30386
|
+
throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')
|
|
30387
|
+
}
|
|
30388
|
+
|
|
30052
30389
|
HashBase.prototype.update = function (data, encoding) {
|
|
30053
|
-
throwIfNotStringOrBuffer(data, 'Data')
|
|
30054
30390
|
if (this._finalized) throw new Error('Digest already called')
|
|
30055
|
-
|
|
30391
|
+
|
|
30392
|
+
data = toBuffer(data, encoding) // asserts correct input type
|
|
30056
30393
|
|
|
30057
30394
|
// consume data
|
|
30058
30395
|
var block = this._block
|
|
@@ -36291,25 +36628,6 @@ module.exports = {
|
|
|
36291
36628
|
module.exports = __webpack_require__(/*! events */ "../../node_modules/events/events.js").EventEmitter;
|
|
36292
36629
|
|
|
36293
36630
|
|
|
36294
|
-
/***/ }),
|
|
36295
|
-
|
|
36296
|
-
/***/ "../../node_modules/readable-stream/readable-browser.js":
|
|
36297
|
-
/*!**************************************************************!*\
|
|
36298
|
-
!*** ../../node_modules/readable-stream/readable-browser.js ***!
|
|
36299
|
-
\**************************************************************/
|
|
36300
|
-
/***/ ((module, exports, __webpack_require__) => {
|
|
36301
|
-
|
|
36302
|
-
exports = module.exports = __webpack_require__(/*! ./lib/_stream_readable.js */ "../../node_modules/readable-stream/lib/_stream_readable.js");
|
|
36303
|
-
exports.Stream = exports;
|
|
36304
|
-
exports.Readable = exports;
|
|
36305
|
-
exports.Writable = __webpack_require__(/*! ./lib/_stream_writable.js */ "../../node_modules/readable-stream/lib/_stream_writable.js");
|
|
36306
|
-
exports.Duplex = __webpack_require__(/*! ./lib/_stream_duplex.js */ "../../node_modules/readable-stream/lib/_stream_duplex.js");
|
|
36307
|
-
exports.Transform = __webpack_require__(/*! ./lib/_stream_transform.js */ "../../node_modules/readable-stream/lib/_stream_transform.js");
|
|
36308
|
-
exports.PassThrough = __webpack_require__(/*! ./lib/_stream_passthrough.js */ "../../node_modules/readable-stream/lib/_stream_passthrough.js");
|
|
36309
|
-
exports.finished = __webpack_require__(/*! ./lib/internal/streams/end-of-stream.js */ "../../node_modules/readable-stream/lib/internal/streams/end-of-stream.js");
|
|
36310
|
-
exports.pipeline = __webpack_require__(/*! ./lib/internal/streams/pipeline.js */ "../../node_modules/readable-stream/lib/internal/streams/pipeline.js");
|
|
36311
|
-
|
|
36312
|
-
|
|
36313
36631
|
/***/ }),
|
|
36314
36632
|
|
|
36315
36633
|
/***/ "../../node_modules/ripemd160/index.js":
|
|
@@ -38223,21 +38541,10 @@ class PowerSyncDatabase extends _powersync_common__WEBPACK_IMPORTED_MODULE_0__.A
|
|
|
38223
38541
|
disconnect: options.disconnect ?? !this.resolvedFlags.enableMultiTabs
|
|
38224
38542
|
});
|
|
38225
38543
|
}
|
|
38226
|
-
connect(connector, options) {
|
|
38227
|
-
/**
|
|
38228
|
-
* Using React strict mode might cause calls to connect to fire multiple times
|
|
38229
|
-
* Connect is wrapped inside a lock in order to prevent race conditions internally between multiple
|
|
38230
|
-
* connection attempts.
|
|
38231
|
-
*/
|
|
38232
|
-
return this.runExclusive(() => {
|
|
38233
|
-
this.options.logger?.debug('Attempting to connect to PowerSync instance');
|
|
38234
|
-
return super.connect(connector, options);
|
|
38235
|
-
});
|
|
38236
|
-
}
|
|
38237
38544
|
generateBucketStorageAdapter() {
|
|
38238
38545
|
return new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.SqliteBucketStorage(this.database, _powersync_common__WEBPACK_IMPORTED_MODULE_0__.AbstractPowerSyncDatabase.transactionMutex);
|
|
38239
38546
|
}
|
|
38240
|
-
runExclusive(cb) {
|
|
38547
|
+
async runExclusive(cb) {
|
|
38241
38548
|
if (this.resolvedFlags.ssrMode) {
|
|
38242
38549
|
return PowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
|
|
38243
38550
|
}
|
|
@@ -39757,9 +40064,6 @@ class SharedWebStreamingSyncImplementation extends _WebStreamingSyncImplementati
|
|
|
39757
40064
|
*/
|
|
39758
40065
|
async connect(options) {
|
|
39759
40066
|
await this.waitForReady();
|
|
39760
|
-
// This is needed since a new tab won't have any reference to the
|
|
39761
|
-
// shared worker sync implementation since that is only created on the first call to `connect`.
|
|
39762
|
-
await this.disconnect();
|
|
39763
40067
|
return this.syncManager.connect(options);
|
|
39764
40068
|
}
|
|
39765
40069
|
async disconnect() {
|
|
@@ -39775,12 +40079,21 @@ class SharedWebStreamingSyncImplementation extends _WebStreamingSyncImplementati
|
|
|
39775
40079
|
}
|
|
39776
40080
|
async dispose() {
|
|
39777
40081
|
await this.waitForReady();
|
|
39778
|
-
|
|
39779
|
-
|
|
39780
|
-
|
|
39781
|
-
|
|
39782
|
-
|
|
39783
|
-
|
|
40082
|
+
await new Promise((resolve) => {
|
|
40083
|
+
// Listen for the close acknowledgment from the worker
|
|
40084
|
+
this.messagePort.addEventListener('message', (event) => {
|
|
40085
|
+
const payload = event.data;
|
|
40086
|
+
if (payload?.event === _worker_sync_SharedSyncImplementation__WEBPACK_IMPORTED_MODULE_2__.SharedSyncClientEvent.CLOSE_ACK) {
|
|
40087
|
+
resolve();
|
|
40088
|
+
}
|
|
40089
|
+
});
|
|
40090
|
+
// Signal the shared worker that this client is closing its connection to the worker
|
|
40091
|
+
const closeMessagePayload = {
|
|
40092
|
+
event: _worker_sync_SharedSyncImplementation__WEBPACK_IMPORTED_MODULE_2__.SharedSyncClientEvent.CLOSE_CLIENT,
|
|
40093
|
+
data: {}
|
|
40094
|
+
};
|
|
40095
|
+
this.messagePort.postMessage(closeMessagePayload);
|
|
40096
|
+
});
|
|
39784
40097
|
// Release the proxy
|
|
39785
40098
|
this.syncManager[comlink__WEBPACK_IMPORTED_MODULE_0__.releaseProxy]();
|
|
39786
40099
|
this.messagePort.close();
|
|
@@ -40258,9 +40571,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
40258
40571
|
/* harmony import */ var _db_sync_WebStreamingSyncImplementation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../db/sync/WebStreamingSyncImplementation */ "./lib/src/db/sync/WebStreamingSyncImplementation.js");
|
|
40259
40572
|
/* harmony import */ var _db_adapters_LockedAsyncDatabaseAdapter__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../db/adapters/LockedAsyncDatabaseAdapter */ "./lib/src/db/adapters/LockedAsyncDatabaseAdapter.js");
|
|
40260
40573
|
/* harmony import */ var _db_adapters_WorkerWrappedAsyncDatabaseConnection__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../db/adapters/WorkerWrappedAsyncDatabaseConnection */ "./lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js");
|
|
40261
|
-
/* harmony import */ var
|
|
40262
|
-
/* harmony import */ var _BroadcastLogger__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./BroadcastLogger */ "./lib/src/worker/sync/BroadcastLogger.js");
|
|
40263
|
-
|
|
40574
|
+
/* harmony import */ var _BroadcastLogger__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./BroadcastLogger */ "./lib/src/worker/sync/BroadcastLogger.js");
|
|
40264
40575
|
|
|
40265
40576
|
|
|
40266
40577
|
|
|
@@ -40270,6 +40581,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
40270
40581
|
|
|
40271
40582
|
|
|
40272
40583
|
/**
|
|
40584
|
+
* @internal
|
|
40273
40585
|
* Manual message events for shared sync clients
|
|
40274
40586
|
*/
|
|
40275
40587
|
var SharedSyncClientEvent;
|
|
@@ -40279,14 +40591,20 @@ var SharedSyncClientEvent;
|
|
|
40279
40591
|
* close it's connection to the client.
|
|
40280
40592
|
*/
|
|
40281
40593
|
SharedSyncClientEvent["CLOSE_CLIENT"] = "close-client";
|
|
40594
|
+
SharedSyncClientEvent["CLOSE_ACK"] = "close-ack";
|
|
40282
40595
|
})(SharedSyncClientEvent || (SharedSyncClientEvent = {}));
|
|
40596
|
+
/**
|
|
40597
|
+
* HACK: The shared implementation wraps and provides its own
|
|
40598
|
+
* PowerSyncBackendConnector when generating the streaming sync implementation.
|
|
40599
|
+
* We provide this unused placeholder when connecting with the ConnectionManager.
|
|
40600
|
+
*/
|
|
40601
|
+
const CONNECTOR_PLACEHOLDER = {};
|
|
40283
40602
|
/**
|
|
40284
40603
|
* @internal
|
|
40285
40604
|
* Shared sync implementation which runs inside a shared webworker
|
|
40286
40605
|
*/
|
|
40287
40606
|
class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODULE_0__.BaseObserver {
|
|
40288
40607
|
ports;
|
|
40289
|
-
syncStreamClient;
|
|
40290
40608
|
isInitialized;
|
|
40291
40609
|
statusListener;
|
|
40292
40610
|
fetchCredentialsController;
|
|
@@ -40295,6 +40613,8 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40295
40613
|
syncParams;
|
|
40296
40614
|
logger;
|
|
40297
40615
|
lastConnectOptions;
|
|
40616
|
+
portMutex;
|
|
40617
|
+
connectionManager;
|
|
40298
40618
|
syncStatus;
|
|
40299
40619
|
broadCastLogger;
|
|
40300
40620
|
constructor() {
|
|
@@ -40302,9 +40622,9 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40302
40622
|
this.ports = [];
|
|
40303
40623
|
this.dbAdapter = null;
|
|
40304
40624
|
this.syncParams = null;
|
|
40305
|
-
this.syncStreamClient = null;
|
|
40306
40625
|
this.logger = (0,_powersync_common__WEBPACK_IMPORTED_MODULE_0__.createLogger)('shared-sync');
|
|
40307
40626
|
this.lastConnectOptions = undefined;
|
|
40627
|
+
this.portMutex = new async_mutex__WEBPACK_IMPORTED_MODULE_1__.Mutex();
|
|
40308
40628
|
this.isInitialized = new Promise((resolve) => {
|
|
40309
40629
|
const callback = this.registerListener({
|
|
40310
40630
|
initialized: () => {
|
|
@@ -40314,21 +40634,44 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40314
40634
|
});
|
|
40315
40635
|
});
|
|
40316
40636
|
this.syncStatus = new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.SyncStatus({});
|
|
40317
|
-
this.broadCastLogger = new
|
|
40318
|
-
|
|
40319
|
-
|
|
40320
|
-
|
|
40321
|
-
|
|
40322
|
-
|
|
40323
|
-
|
|
40324
|
-
|
|
40325
|
-
|
|
40637
|
+
this.broadCastLogger = new _BroadcastLogger__WEBPACK_IMPORTED_MODULE_7__.BroadcastLogger(this.ports);
|
|
40638
|
+
this.connectionManager = new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.ConnectionManager({
|
|
40639
|
+
createSyncImplementation: async () => {
|
|
40640
|
+
return this.portMutex.runExclusive(async () => {
|
|
40641
|
+
await this.waitForReady();
|
|
40642
|
+
if (!this.dbAdapter) {
|
|
40643
|
+
await this.openInternalDB();
|
|
40644
|
+
}
|
|
40645
|
+
const sync = this.generateStreamingImplementation();
|
|
40646
|
+
const onDispose = sync.registerListener({
|
|
40647
|
+
statusChanged: (status) => {
|
|
40648
|
+
this.updateAllStatuses(status.toJSON());
|
|
40649
|
+
}
|
|
40650
|
+
});
|
|
40651
|
+
return {
|
|
40652
|
+
sync,
|
|
40653
|
+
onDispose
|
|
40654
|
+
};
|
|
40655
|
+
});
|
|
40656
|
+
},
|
|
40657
|
+
logger: this.logger
|
|
40658
|
+
});
|
|
40326
40659
|
}
|
|
40327
40660
|
get lastSyncedAt() {
|
|
40328
|
-
return this.
|
|
40661
|
+
return this.connectionManager.syncStreamImplementation?.lastSyncedAt;
|
|
40329
40662
|
}
|
|
40330
40663
|
get isConnected() {
|
|
40331
|
-
return this.
|
|
40664
|
+
return this.connectionManager.syncStreamImplementation?.isConnected ?? false;
|
|
40665
|
+
}
|
|
40666
|
+
async waitForStatus(status) {
|
|
40667
|
+
return this.withSyncImplementation(async (sync) => {
|
|
40668
|
+
return sync.waitForStatus(status);
|
|
40669
|
+
});
|
|
40670
|
+
}
|
|
40671
|
+
async waitUntilStatusMatches(predicate) {
|
|
40672
|
+
return this.withSyncImplementation(async (sync) => {
|
|
40673
|
+
return sync.waitUntilStatusMatches(predicate);
|
|
40674
|
+
});
|
|
40332
40675
|
}
|
|
40333
40676
|
async waitForReady() {
|
|
40334
40677
|
return this.isInitialized;
|
|
@@ -40341,25 +40684,34 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40341
40684
|
* Configures the DBAdapter connection and a streaming sync client.
|
|
40342
40685
|
*/
|
|
40343
40686
|
async setParams(params) {
|
|
40344
|
-
|
|
40345
|
-
|
|
40346
|
-
|
|
40347
|
-
|
|
40348
|
-
|
|
40349
|
-
|
|
40350
|
-
|
|
40351
|
-
|
|
40352
|
-
|
|
40353
|
-
//
|
|
40354
|
-
this.
|
|
40355
|
-
|
|
40356
|
-
|
|
40357
|
-
|
|
40687
|
+
await this.portMutex.runExclusive(async () => {
|
|
40688
|
+
if (this.syncParams) {
|
|
40689
|
+
// Cannot modify already existing sync implementation params
|
|
40690
|
+
// But we can ask for a DB adapter, if required, at this point.
|
|
40691
|
+
if (!this.dbAdapter) {
|
|
40692
|
+
await this.openInternalDB();
|
|
40693
|
+
}
|
|
40694
|
+
return;
|
|
40695
|
+
}
|
|
40696
|
+
// First time setting params
|
|
40697
|
+
this.syncParams = params;
|
|
40698
|
+
if (params.streamOptions?.flags?.broadcastLogs) {
|
|
40699
|
+
this.logger = this.broadCastLogger;
|
|
40700
|
+
}
|
|
40701
|
+
self.onerror = (event) => {
|
|
40702
|
+
// Share any uncaught events on the broadcast logger
|
|
40703
|
+
this.logger.error('Uncaught exception in PowerSync shared sync worker', event);
|
|
40704
|
+
};
|
|
40705
|
+
if (!this.dbAdapter) {
|
|
40706
|
+
await this.openInternalDB();
|
|
40707
|
+
}
|
|
40708
|
+
this.iterateListeners((l) => l.initialized?.());
|
|
40709
|
+
});
|
|
40358
40710
|
}
|
|
40359
40711
|
async dispose() {
|
|
40360
40712
|
await this.waitForReady();
|
|
40361
40713
|
this.statusListener?.();
|
|
40362
|
-
return this.
|
|
40714
|
+
return this.connectionManager.close();
|
|
40363
40715
|
}
|
|
40364
40716
|
/**
|
|
40365
40717
|
* Connects to the PowerSync backend instance.
|
|
@@ -40368,99 +40720,110 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40368
40720
|
* connects.
|
|
40369
40721
|
*/
|
|
40370
40722
|
async connect(options) {
|
|
40371
|
-
|
|
40372
|
-
|
|
40373
|
-
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_7__.getNavigatorLocks)().request('shared-sync-connect', async () => {
|
|
40374
|
-
if (!this.dbAdapter) {
|
|
40375
|
-
await this.openInternalDB();
|
|
40376
|
-
}
|
|
40377
|
-
this.syncStreamClient = this.generateStreamingImplementation();
|
|
40378
|
-
this.lastConnectOptions = options;
|
|
40379
|
-
this.syncStreamClient.registerListener({
|
|
40380
|
-
statusChanged: (status) => {
|
|
40381
|
-
this.updateAllStatuses(status.toJSON());
|
|
40382
|
-
}
|
|
40383
|
-
});
|
|
40384
|
-
await this.syncStreamClient.connect(options);
|
|
40385
|
-
});
|
|
40723
|
+
this.lastConnectOptions = options;
|
|
40724
|
+
return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options);
|
|
40386
40725
|
}
|
|
40387
40726
|
async disconnect() {
|
|
40388
|
-
|
|
40389
|
-
// This effectively queues connect and disconnect calls. Ensuring multiple tabs' requests are synchronized
|
|
40390
|
-
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_7__.getNavigatorLocks)().request('shared-sync-connect', async () => {
|
|
40391
|
-
await this.syncStreamClient?.disconnect();
|
|
40392
|
-
await this.syncStreamClient?.dispose();
|
|
40393
|
-
this.syncStreamClient = null;
|
|
40394
|
-
});
|
|
40727
|
+
return this.connectionManager.disconnect();
|
|
40395
40728
|
}
|
|
40396
40729
|
/**
|
|
40397
40730
|
* Adds a new client tab's message port to the list of connected ports
|
|
40398
40731
|
*/
|
|
40399
|
-
addPort(port) {
|
|
40400
|
-
|
|
40401
|
-
|
|
40402
|
-
|
|
40403
|
-
|
|
40404
|
-
|
|
40405
|
-
|
|
40406
|
-
|
|
40407
|
-
|
|
40408
|
-
|
|
40409
|
-
|
|
40732
|
+
async addPort(port) {
|
|
40733
|
+
await this.portMutex.runExclusive(() => {
|
|
40734
|
+
const portProvider = {
|
|
40735
|
+
port,
|
|
40736
|
+
clientProvider: comlink__WEBPACK_IMPORTED_MODULE_2__.wrap(port)
|
|
40737
|
+
};
|
|
40738
|
+
this.ports.push(portProvider);
|
|
40739
|
+
// Give the newly connected client the latest status
|
|
40740
|
+
const status = this.connectionManager.syncStreamImplementation?.syncStatus;
|
|
40741
|
+
if (status) {
|
|
40742
|
+
portProvider.clientProvider.statusChanged(status.toJSON());
|
|
40743
|
+
}
|
|
40744
|
+
});
|
|
40410
40745
|
}
|
|
40411
40746
|
/**
|
|
40412
40747
|
* Removes a message port client from this manager's managed
|
|
40413
40748
|
* clients.
|
|
40414
40749
|
*/
|
|
40415
40750
|
async removePort(port) {
|
|
40416
|
-
|
|
40417
|
-
if
|
|
40418
|
-
|
|
40419
|
-
|
|
40420
|
-
|
|
40421
|
-
|
|
40422
|
-
|
|
40423
|
-
|
|
40424
|
-
/**
|
|
40425
|
-
* The port might currently be in use. Any active functions might
|
|
40426
|
-
* not resolve. Abort them here.
|
|
40427
|
-
*/
|
|
40428
|
-
[this.fetchCredentialsController, this.uploadDataController].forEach((abortController) => {
|
|
40429
|
-
if (abortController?.activePort.port == port) {
|
|
40430
|
-
abortController.controller.abort(new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.AbortOperation('Closing pending requests after client port is removed'));
|
|
40751
|
+
// Remove the port within a mutex context.
|
|
40752
|
+
// Warns if the port is not found. This should not happen in practice.
|
|
40753
|
+
// We return early if the port is not found.
|
|
40754
|
+
const { trackedPort, shouldReconnect } = await this.portMutex.runExclusive(async () => {
|
|
40755
|
+
const index = this.ports.findIndex((p) => p.port == port);
|
|
40756
|
+
if (index < 0) {
|
|
40757
|
+
this.logger.warn(`Could not remove port ${port} since it is not present in active ports.`);
|
|
40758
|
+
return {};
|
|
40431
40759
|
}
|
|
40760
|
+
const trackedPort = this.ports[index];
|
|
40761
|
+
// Remove from the list of active ports
|
|
40762
|
+
this.ports.splice(index, 1);
|
|
40763
|
+
/**
|
|
40764
|
+
* The port might currently be in use. Any active functions might
|
|
40765
|
+
* not resolve. Abort them here.
|
|
40766
|
+
*/
|
|
40767
|
+
[this.fetchCredentialsController, this.uploadDataController].forEach((abortController) => {
|
|
40768
|
+
if (abortController?.activePort.port == port) {
|
|
40769
|
+
abortController.controller.abort(new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.AbortOperation('Closing pending requests after client port is removed'));
|
|
40770
|
+
}
|
|
40771
|
+
});
|
|
40772
|
+
const shouldReconnect = !!this.connectionManager.syncStreamImplementation && this.ports.length > 0;
|
|
40773
|
+
return {
|
|
40774
|
+
shouldReconnect,
|
|
40775
|
+
trackedPort
|
|
40776
|
+
};
|
|
40432
40777
|
});
|
|
40433
|
-
|
|
40778
|
+
if (!trackedPort) {
|
|
40779
|
+
// We could not find the port to remove
|
|
40780
|
+
return () => { };
|
|
40781
|
+
}
|
|
40434
40782
|
if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
|
|
40435
40783
|
if (shouldReconnect) {
|
|
40436
|
-
await this.disconnect();
|
|
40784
|
+
await this.connectionManager.disconnect();
|
|
40437
40785
|
}
|
|
40438
40786
|
// Clearing the adapter will result in a new one being opened in connect
|
|
40439
40787
|
this.dbAdapter = null;
|
|
40440
40788
|
if (shouldReconnect) {
|
|
40441
|
-
await this.connect(this.lastConnectOptions);
|
|
40789
|
+
await this.connectionManager.connect(CONNECTOR_PLACEHOLDER, this.lastConnectOptions);
|
|
40442
40790
|
}
|
|
40443
40791
|
}
|
|
40444
40792
|
if (trackedPort.db) {
|
|
40445
|
-
trackedPort.db.close();
|
|
40793
|
+
await trackedPort.db.close();
|
|
40446
40794
|
}
|
|
40447
40795
|
// Release proxy
|
|
40448
|
-
trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
|
|
40796
|
+
return () => trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
|
|
40449
40797
|
}
|
|
40450
40798
|
triggerCrudUpload() {
|
|
40451
|
-
this.
|
|
40452
|
-
|
|
40453
|
-
|
|
40454
|
-
await this.waitForReady();
|
|
40455
|
-
return this.syncStreamClient.obtainLock(lockOptions);
|
|
40799
|
+
this.withSyncImplementation(async (sync) => {
|
|
40800
|
+
sync.triggerCrudUpload();
|
|
40801
|
+
});
|
|
40456
40802
|
}
|
|
40457
40803
|
async hasCompletedSync() {
|
|
40458
|
-
|
|
40459
|
-
|
|
40804
|
+
return this.withSyncImplementation(async (sync) => {
|
|
40805
|
+
return sync.hasCompletedSync();
|
|
40806
|
+
});
|
|
40460
40807
|
}
|
|
40461
40808
|
async getWriteCheckpoint() {
|
|
40809
|
+
return this.withSyncImplementation(async (sync) => {
|
|
40810
|
+
return sync.getWriteCheckpoint();
|
|
40811
|
+
});
|
|
40812
|
+
}
|
|
40813
|
+
async withSyncImplementation(callback) {
|
|
40462
40814
|
await this.waitForReady();
|
|
40463
|
-
|
|
40815
|
+
if (this.connectionManager.syncStreamImplementation) {
|
|
40816
|
+
return callback(this.connectionManager.syncStreamImplementation);
|
|
40817
|
+
}
|
|
40818
|
+
const sync = await new Promise((resolve) => {
|
|
40819
|
+
const dispose = this.connectionManager.registerListener({
|
|
40820
|
+
syncStreamCreated: (sync) => {
|
|
40821
|
+
resolve(sync);
|
|
40822
|
+
dispose?.();
|
|
40823
|
+
}
|
|
40824
|
+
});
|
|
40825
|
+
});
|
|
40826
|
+
return callback(sync);
|
|
40464
40827
|
}
|
|
40465
40828
|
generateStreamingImplementation() {
|
|
40466
40829
|
// This should only be called after initialization has completed
|
|
@@ -40563,13 +40926,13 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40563
40926
|
* A function only used for unit tests which updates the internal
|
|
40564
40927
|
* sync stream client and all tab client's sync status
|
|
40565
40928
|
*/
|
|
40566
|
-
_testUpdateAllStatuses(status) {
|
|
40567
|
-
if (!this.
|
|
40929
|
+
async _testUpdateAllStatuses(status) {
|
|
40930
|
+
if (!this.connectionManager.syncStreamImplementation) {
|
|
40568
40931
|
// This is just for testing purposes
|
|
40569
|
-
this.
|
|
40932
|
+
this.connectionManager.syncStreamImplementation = this.generateStreamingImplementation();
|
|
40570
40933
|
}
|
|
40571
40934
|
// Only assigning, don't call listeners for this test
|
|
40572
|
-
this.
|
|
40935
|
+
this.connectionManager.syncStreamImplementation.syncStatus = new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.SyncStatus(status);
|
|
40573
40936
|
this.updateAllStatuses(status);
|
|
40574
40937
|
}
|
|
40575
40938
|
}
|