@powersync/common 0.0.0-dev-20251209082930 → 0.0.0-dev-20260120150240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/bundle.cjs +366 -2142
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +365 -2143
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +153 -100
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +152 -101
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +26 -3
  10. package/lib/client/AbstractPowerSyncDatabase.d.ts +1 -1
  11. package/lib/client/AbstractPowerSyncDatabase.js +2 -2
  12. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  13. package/lib/client/sync/stream/AbstractRemote.js +41 -32
  14. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  15. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +4 -0
  16. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +8 -0
  17. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  18. package/lib/client/sync/stream/streaming-sync-types.d.ts +4 -0
  19. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -1
  20. package/lib/db/ConnectionClosedError.d.ts +10 -0
  21. package/lib/db/ConnectionClosedError.js +21 -0
  22. package/lib/db/ConnectionClosedError.js.map +1 -0
  23. package/lib/db/crud/SyncStatus.d.ts +4 -0
  24. package/lib/db/crud/SyncStatus.js +4 -0
  25. package/lib/db/crud/SyncStatus.js.map +1 -1
  26. package/lib/index.d.ts +2 -0
  27. package/lib/index.js +2 -0
  28. package/lib/index.js.map +1 -1
  29. package/lib/utils/DataStream.js +11 -2
  30. package/lib/utils/DataStream.js.map +1 -1
  31. package/package.json +4 -3
  32. package/src/client/AbstractPowerSyncDatabase.ts +2 -2
  33. package/src/client/sync/stream/AbstractRemote.ts +47 -35
  34. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +19 -2
  35. package/src/client/sync/stream/streaming-sync-types.ts +5 -0
  36. package/src/db/ConnectionClosedError.ts +23 -0
  37. package/src/db/crud/SyncStatus.ts +4 -0
  38. package/src/index.ts +2 -0
  39. package/src/utils/DataStream.ts +13 -2
package/dist/bundle.mjs CHANGED
@@ -730,6 +730,10 @@ class SyncStatus {
730
730
  priorityStatusEntries: this.priorityStatusEntries
731
731
  };
732
732
  }
733
+ /**
734
+ * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
735
+ * This explicitly serializes errors in the SyncStatus.
736
+ */
733
737
  serializeError(error) {
734
738
  if (typeof error == 'undefined') {
735
739
  return undefined;
@@ -2083,7 +2087,7 @@ class SyncDataBucket {
2083
2087
  }
2084
2088
  }
2085
2089
 
2086
- var buffer$1 = {};
2090
+ var buffer = {};
2087
2091
 
2088
2092
  var base64Js = {};
2089
2093
 
@@ -2347,12 +2351,12 @@ function requireIeee754 () {
2347
2351
  * @license MIT
2348
2352
  */
2349
2353
 
2350
- var hasRequiredBuffer$1;
2354
+ var hasRequiredBuffer;
2351
2355
 
2352
- function requireBuffer$1 () {
2353
- if (hasRequiredBuffer$1) return buffer$1;
2354
- hasRequiredBuffer$1 = 1;
2355
- (function (exports) {
2356
+ function requireBuffer () {
2357
+ if (hasRequiredBuffer) return buffer;
2358
+ hasRequiredBuffer = 1;
2359
+ (function (exports$1) {
2356
2360
 
2357
2361
  const base64 = requireBase64Js();
2358
2362
  const ieee754 = requireIeee754();
@@ -2361,12 +2365,12 @@ function requireBuffer$1 () {
2361
2365
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
2362
2366
  : null;
2363
2367
 
2364
- exports.Buffer = Buffer;
2365
- exports.SlowBuffer = SlowBuffer;
2366
- exports.INSPECT_MAX_BYTES = 50;
2368
+ exports$1.Buffer = Buffer;
2369
+ exports$1.SlowBuffer = SlowBuffer;
2370
+ exports$1.INSPECT_MAX_BYTES = 50;
2367
2371
 
2368
2372
  const K_MAX_LENGTH = 0x7fffffff;
2369
- exports.kMaxLength = K_MAX_LENGTH;
2373
+ exports$1.kMaxLength = K_MAX_LENGTH;
2370
2374
 
2371
2375
  /**
2372
2376
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -2962,7 +2966,7 @@ function requireBuffer$1 () {
2962
2966
 
2963
2967
  Buffer.prototype.inspect = function inspect () {
2964
2968
  let str = '';
2965
- const max = exports.INSPECT_MAX_BYTES;
2969
+ const max = exports$1.INSPECT_MAX_BYTES;
2966
2970
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
2967
2971
  if (this.length > max) str += ' ... ';
2968
2972
  return '<Buffer ' + str + '>'
@@ -3866,2019 +3870,39 @@ function requireBuffer$1 () {
3866
3870
  buf[offset + 6] = lo;
3867
3871
  lo = lo >> 8;
3868
3872
  buf[offset + 5] = lo;
3869
- lo = lo >> 8;
3870
- buf[offset + 4] = lo;
3871
- let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
3872
- buf[offset + 3] = hi;
3873
- hi = hi >> 8;
3874
- buf[offset + 2] = hi;
3875
- hi = hi >> 8;
3876
- buf[offset + 1] = hi;
3877
- hi = hi >> 8;
3878
- buf[offset] = hi;
3879
- return offset + 8
3880
- }
3881
-
3882
- Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
3883
- return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3884
- });
3885
-
3886
- Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
3887
- return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3888
- });
3889
-
3890
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
3891
- value = +value;
3892
- offset = offset >>> 0;
3893
- if (!noAssert) {
3894
- const limit = Math.pow(2, (8 * byteLength) - 1);
3895
-
3896
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
3897
- }
3898
-
3899
- let i = 0;
3900
- let mul = 1;
3901
- let sub = 0;
3902
- this[offset] = value & 0xFF;
3903
- while (++i < byteLength && (mul *= 0x100)) {
3904
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
3905
- sub = 1;
3906
- }
3907
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
3908
- }
3909
-
3910
- return offset + byteLength
3911
- };
3912
-
3913
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
3914
- value = +value;
3915
- offset = offset >>> 0;
3916
- if (!noAssert) {
3917
- const limit = Math.pow(2, (8 * byteLength) - 1);
3918
-
3919
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
3920
- }
3921
-
3922
- let i = byteLength - 1;
3923
- let mul = 1;
3924
- let sub = 0;
3925
- this[offset + i] = value & 0xFF;
3926
- while (--i >= 0 && (mul *= 0x100)) {
3927
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
3928
- sub = 1;
3929
- }
3930
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
3931
- }
3932
-
3933
- return offset + byteLength
3934
- };
3935
-
3936
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
3937
- value = +value;
3938
- offset = offset >>> 0;
3939
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
3940
- if (value < 0) value = 0xff + value + 1;
3941
- this[offset] = (value & 0xff);
3942
- return offset + 1
3943
- };
3944
-
3945
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
3946
- value = +value;
3947
- offset = offset >>> 0;
3948
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
3949
- this[offset] = (value & 0xff);
3950
- this[offset + 1] = (value >>> 8);
3951
- return offset + 2
3952
- };
3953
-
3954
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
3955
- value = +value;
3956
- offset = offset >>> 0;
3957
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
3958
- this[offset] = (value >>> 8);
3959
- this[offset + 1] = (value & 0xff);
3960
- return offset + 2
3961
- };
3962
-
3963
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
3964
- value = +value;
3965
- offset = offset >>> 0;
3966
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
3967
- this[offset] = (value & 0xff);
3968
- this[offset + 1] = (value >>> 8);
3969
- this[offset + 2] = (value >>> 16);
3970
- this[offset + 3] = (value >>> 24);
3971
- return offset + 4
3972
- };
3973
-
3974
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
3975
- value = +value;
3976
- offset = offset >>> 0;
3977
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
3978
- if (value < 0) value = 0xffffffff + value + 1;
3979
- this[offset] = (value >>> 24);
3980
- this[offset + 1] = (value >>> 16);
3981
- this[offset + 2] = (value >>> 8);
3982
- this[offset + 3] = (value & 0xff);
3983
- return offset + 4
3984
- };
3985
-
3986
- Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
3987
- return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3988
- });
3989
-
3990
- Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
3991
- return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3992
- });
3993
-
3994
- function checkIEEE754 (buf, value, offset, ext, max, min) {
3995
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
3996
- if (offset < 0) throw new RangeError('Index out of range')
3997
- }
3998
-
3999
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
4000
- value = +value;
4001
- offset = offset >>> 0;
4002
- if (!noAssert) {
4003
- checkIEEE754(buf, value, offset, 4);
4004
- }
4005
- ieee754.write(buf, value, offset, littleEndian, 23, 4);
4006
- return offset + 4
4007
- }
4008
-
4009
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
4010
- return writeFloat(this, value, offset, true, noAssert)
4011
- };
4012
-
4013
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
4014
- return writeFloat(this, value, offset, false, noAssert)
4015
- };
4016
-
4017
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
4018
- value = +value;
4019
- offset = offset >>> 0;
4020
- if (!noAssert) {
4021
- checkIEEE754(buf, value, offset, 8);
4022
- }
4023
- ieee754.write(buf, value, offset, littleEndian, 52, 8);
4024
- return offset + 8
4025
- }
4026
-
4027
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
4028
- return writeDouble(this, value, offset, true, noAssert)
4029
- };
4030
-
4031
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
4032
- return writeDouble(this, value, offset, false, noAssert)
4033
- };
4034
-
4035
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
4036
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
4037
- if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
4038
- if (!start) start = 0;
4039
- if (!end && end !== 0) end = this.length;
4040
- if (targetStart >= target.length) targetStart = target.length;
4041
- if (!targetStart) targetStart = 0;
4042
- if (end > 0 && end < start) end = start;
4043
-
4044
- // Copy 0 bytes; we're done
4045
- if (end === start) return 0
4046
- if (target.length === 0 || this.length === 0) return 0
4047
-
4048
- // Fatal error conditions
4049
- if (targetStart < 0) {
4050
- throw new RangeError('targetStart out of bounds')
4051
- }
4052
- if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
4053
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
4054
-
4055
- // Are we oob?
4056
- if (end > this.length) end = this.length;
4057
- if (target.length - targetStart < end - start) {
4058
- end = target.length - targetStart + start;
4059
- }
4060
-
4061
- const len = end - start;
4062
-
4063
- if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
4064
- // Use built-in when available, missing from IE11
4065
- this.copyWithin(targetStart, start, end);
4066
- } else {
4067
- Uint8Array.prototype.set.call(
4068
- target,
4069
- this.subarray(start, end),
4070
- targetStart
4071
- );
4072
- }
4073
-
4074
- return len
4075
- };
4076
-
4077
- // Usage:
4078
- // buffer.fill(number[, offset[, end]])
4079
- // buffer.fill(buffer[, offset[, end]])
4080
- // buffer.fill(string[, offset[, end]][, encoding])
4081
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
4082
- // Handle string cases:
4083
- if (typeof val === 'string') {
4084
- if (typeof start === 'string') {
4085
- encoding = start;
4086
- start = 0;
4087
- end = this.length;
4088
- } else if (typeof end === 'string') {
4089
- encoding = end;
4090
- end = this.length;
4091
- }
4092
- if (encoding !== undefined && typeof encoding !== 'string') {
4093
- throw new TypeError('encoding must be a string')
4094
- }
4095
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
4096
- throw new TypeError('Unknown encoding: ' + encoding)
4097
- }
4098
- if (val.length === 1) {
4099
- const code = val.charCodeAt(0);
4100
- if ((encoding === 'utf8' && code < 128) ||
4101
- encoding === 'latin1') {
4102
- // Fast path: If `val` fits into a single byte, use that numeric value.
4103
- val = code;
4104
- }
4105
- }
4106
- } else if (typeof val === 'number') {
4107
- val = val & 255;
4108
- } else if (typeof val === 'boolean') {
4109
- val = Number(val);
4110
- }
4111
-
4112
- // Invalid ranges are not set to a default, so can range check early.
4113
- if (start < 0 || this.length < start || this.length < end) {
4114
- throw new RangeError('Out of range index')
4115
- }
4116
-
4117
- if (end <= start) {
4118
- return this
4119
- }
4120
-
4121
- start = start >>> 0;
4122
- end = end === undefined ? this.length : end >>> 0;
4123
-
4124
- if (!val) val = 0;
4125
-
4126
- let i;
4127
- if (typeof val === 'number') {
4128
- for (i = start; i < end; ++i) {
4129
- this[i] = val;
4130
- }
4131
- } else {
4132
- const bytes = Buffer.isBuffer(val)
4133
- ? val
4134
- : Buffer.from(val, encoding);
4135
- const len = bytes.length;
4136
- if (len === 0) {
4137
- throw new TypeError('The value "' + val +
4138
- '" is invalid for argument "value"')
4139
- }
4140
- for (i = 0; i < end - start; ++i) {
4141
- this[i + start] = bytes[i % len];
4142
- }
4143
- }
4144
-
4145
- return this
4146
- };
4147
-
4148
- // CUSTOM ERRORS
4149
- // =============
4150
-
4151
- // Simplified versions from Node, changed for Buffer-only usage
4152
- const errors = {};
4153
- function E (sym, getMessage, Base) {
4154
- errors[sym] = class NodeError extends Base {
4155
- constructor () {
4156
- super();
4157
-
4158
- Object.defineProperty(this, 'message', {
4159
- value: getMessage.apply(this, arguments),
4160
- writable: true,
4161
- configurable: true
4162
- });
4163
-
4164
- // Add the error code to the name to include it in the stack trace.
4165
- this.name = `${this.name} [${sym}]`;
4166
- // Access the stack to generate the error message including the error code
4167
- // from the name.
4168
- this.stack; // eslint-disable-line no-unused-expressions
4169
- // Reset the name to the actual name.
4170
- delete this.name;
4171
- }
4172
-
4173
- get code () {
4174
- return sym
4175
- }
4176
-
4177
- set code (value) {
4178
- Object.defineProperty(this, 'code', {
4179
- configurable: true,
4180
- enumerable: true,
4181
- value,
4182
- writable: true
4183
- });
4184
- }
4185
-
4186
- toString () {
4187
- return `${this.name} [${sym}]: ${this.message}`
4188
- }
4189
- };
4190
- }
4191
-
4192
- E('ERR_BUFFER_OUT_OF_BOUNDS',
4193
- function (name) {
4194
- if (name) {
4195
- return `${name} is outside of buffer bounds`
4196
- }
4197
-
4198
- return 'Attempt to access memory outside buffer bounds'
4199
- }, RangeError);
4200
- E('ERR_INVALID_ARG_TYPE',
4201
- function (name, actual) {
4202
- return `The "${name}" argument must be of type number. Received type ${typeof actual}`
4203
- }, TypeError);
4204
- E('ERR_OUT_OF_RANGE',
4205
- function (str, range, input) {
4206
- let msg = `The value of "${str}" is out of range.`;
4207
- let received = input;
4208
- if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
4209
- received = addNumericalSeparator(String(input));
4210
- } else if (typeof input === 'bigint') {
4211
- received = String(input);
4212
- if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
4213
- received = addNumericalSeparator(received);
4214
- }
4215
- received += 'n';
4216
- }
4217
- msg += ` It must be ${range}. Received ${received}`;
4218
- return msg
4219
- }, RangeError);
4220
-
4221
- function addNumericalSeparator (val) {
4222
- let res = '';
4223
- let i = val.length;
4224
- const start = val[0] === '-' ? 1 : 0;
4225
- for (; i >= start + 4; i -= 3) {
4226
- res = `_${val.slice(i - 3, i)}${res}`;
4227
- }
4228
- return `${val.slice(0, i)}${res}`
4229
- }
4230
-
4231
- // CHECK FUNCTIONS
4232
- // ===============
4233
-
4234
- function checkBounds (buf, offset, byteLength) {
4235
- validateNumber(offset, 'offset');
4236
- if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
4237
- boundsError(offset, buf.length - (byteLength + 1));
4238
- }
4239
- }
4240
-
4241
- function checkIntBI (value, min, max, buf, offset, byteLength) {
4242
- if (value > max || value < min) {
4243
- const n = typeof min === 'bigint' ? 'n' : '';
4244
- let range;
4245
- {
4246
- if (min === 0 || min === BigInt(0)) {
4247
- range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
4248
- } else {
4249
- range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
4250
- `${(byteLength + 1) * 8 - 1}${n}`;
4251
- }
4252
- }
4253
- throw new errors.ERR_OUT_OF_RANGE('value', range, value)
4254
- }
4255
- checkBounds(buf, offset, byteLength);
4256
- }
4257
-
4258
- function validateNumber (value, name) {
4259
- if (typeof value !== 'number') {
4260
- throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
4261
- }
4262
- }
4263
-
4264
- function boundsError (value, length, type) {
4265
- if (Math.floor(value) !== value) {
4266
- validateNumber(value, type);
4267
- throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
4268
- }
4269
-
4270
- if (length < 0) {
4271
- throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
4272
- }
4273
-
4274
- throw new errors.ERR_OUT_OF_RANGE('offset',
4275
- `>= ${0} and <= ${length}`,
4276
- value)
4277
- }
4278
-
4279
- // HELPER FUNCTIONS
4280
- // ================
4281
-
4282
- const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
4283
-
4284
- function base64clean (str) {
4285
- // Node takes equal signs as end of the Base64 encoding
4286
- str = str.split('=')[0];
4287
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
4288
- str = str.trim().replace(INVALID_BASE64_RE, '');
4289
- // Node converts strings with length < 2 to ''
4290
- if (str.length < 2) return ''
4291
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
4292
- while (str.length % 4 !== 0) {
4293
- str = str + '=';
4294
- }
4295
- return str
4296
- }
4297
-
4298
- function utf8ToBytes (string, units) {
4299
- units = units || Infinity;
4300
- let codePoint;
4301
- const length = string.length;
4302
- let leadSurrogate = null;
4303
- const bytes = [];
4304
-
4305
- for (let i = 0; i < length; ++i) {
4306
- codePoint = string.charCodeAt(i);
4307
-
4308
- // is surrogate component
4309
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
4310
- // last char was a lead
4311
- if (!leadSurrogate) {
4312
- // no lead yet
4313
- if (codePoint > 0xDBFF) {
4314
- // unexpected trail
4315
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4316
- continue
4317
- } else if (i + 1 === length) {
4318
- // unpaired lead
4319
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4320
- continue
4321
- }
4322
-
4323
- // valid lead
4324
- leadSurrogate = codePoint;
4325
-
4326
- continue
4327
- }
4328
-
4329
- // 2 leads in a row
4330
- if (codePoint < 0xDC00) {
4331
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4332
- leadSurrogate = codePoint;
4333
- continue
4334
- }
4335
-
4336
- // valid surrogate pair
4337
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
4338
- } else if (leadSurrogate) {
4339
- // valid bmp char, but last char was a lead
4340
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
4341
- }
4342
-
4343
- leadSurrogate = null;
4344
-
4345
- // encode utf8
4346
- if (codePoint < 0x80) {
4347
- if ((units -= 1) < 0) break
4348
- bytes.push(codePoint);
4349
- } else if (codePoint < 0x800) {
4350
- if ((units -= 2) < 0) break
4351
- bytes.push(
4352
- codePoint >> 0x6 | 0xC0,
4353
- codePoint & 0x3F | 0x80
4354
- );
4355
- } else if (codePoint < 0x10000) {
4356
- if ((units -= 3) < 0) break
4357
- bytes.push(
4358
- codePoint >> 0xC | 0xE0,
4359
- codePoint >> 0x6 & 0x3F | 0x80,
4360
- codePoint & 0x3F | 0x80
4361
- );
4362
- } else if (codePoint < 0x110000) {
4363
- if ((units -= 4) < 0) break
4364
- bytes.push(
4365
- codePoint >> 0x12 | 0xF0,
4366
- codePoint >> 0xC & 0x3F | 0x80,
4367
- codePoint >> 0x6 & 0x3F | 0x80,
4368
- codePoint & 0x3F | 0x80
4369
- );
4370
- } else {
4371
- throw new Error('Invalid code point')
4372
- }
4373
- }
4374
-
4375
- return bytes
4376
- }
4377
-
4378
- function asciiToBytes (str) {
4379
- const byteArray = [];
4380
- for (let i = 0; i < str.length; ++i) {
4381
- // Node's code seems to be doing this and not & 0x7F..
4382
- byteArray.push(str.charCodeAt(i) & 0xFF);
4383
- }
4384
- return byteArray
4385
- }
4386
-
4387
- function utf16leToBytes (str, units) {
4388
- let c, hi, lo;
4389
- const byteArray = [];
4390
- for (let i = 0; i < str.length; ++i) {
4391
- if ((units -= 2) < 0) break
4392
-
4393
- c = str.charCodeAt(i);
4394
- hi = c >> 8;
4395
- lo = c % 256;
4396
- byteArray.push(lo);
4397
- byteArray.push(hi);
4398
- }
4399
-
4400
- return byteArray
4401
- }
4402
-
4403
- function base64ToBytes (str) {
4404
- return base64.toByteArray(base64clean(str))
4405
- }
4406
-
4407
- function blitBuffer (src, dst, offset, length) {
4408
- let i;
4409
- for (i = 0; i < length; ++i) {
4410
- if ((i + offset >= dst.length) || (i >= src.length)) break
4411
- dst[i + offset] = src[i];
4412
- }
4413
- return i
4414
- }
4415
-
4416
- // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
4417
- // the `instanceof` check but they should be treated as of that type.
4418
- // See: https://github.com/feross/buffer/issues/166
4419
- function isInstance (obj, type) {
4420
- return obj instanceof type ||
4421
- (obj != null && obj.constructor != null && obj.constructor.name != null &&
4422
- obj.constructor.name === type.name)
4423
- }
4424
- function numberIsNaN (obj) {
4425
- // For IE11 support
4426
- return obj !== obj // eslint-disable-line no-self-compare
4427
- }
4428
-
4429
- // Create lookup table for `toString('hex')`
4430
- // See: https://github.com/feross/buffer/issues/219
4431
- const hexSliceLookupTable = (function () {
4432
- const alphabet = '0123456789abcdef';
4433
- const table = new Array(256);
4434
- for (let i = 0; i < 16; ++i) {
4435
- const i16 = i * 16;
4436
- for (let j = 0; j < 16; ++j) {
4437
- table[i16 + j] = alphabet[i] + alphabet[j];
4438
- }
4439
- }
4440
- return table
4441
- })();
4442
-
4443
- // Return not function with Error if BigInt not supported
4444
- function defineBigIntMethod (fn) {
4445
- return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
4446
- }
4447
-
4448
- function BufferBigIntNotDefined () {
4449
- throw new Error('BigInt not supported')
4450
- }
4451
- } (buffer$1));
4452
- return buffer$1;
4453
- }
4454
-
4455
- var bufferExports$1 = requireBuffer$1();
4456
-
4457
- var dist = {};
4458
-
4459
- var buffer = {};
4460
-
4461
- /*!
4462
- * The buffer module from node.js, for the browser.
4463
- *
4464
- * @author Feross Aboukhadijeh <https://feross.org>
4465
- * @license MIT
4466
- */
4467
-
4468
- var hasRequiredBuffer;
4469
-
4470
- function requireBuffer () {
4471
- if (hasRequiredBuffer) return buffer;
4472
- hasRequiredBuffer = 1;
4473
- (function (exports) {
4474
-
4475
- var base64 = requireBase64Js();
4476
- var ieee754 = requireIeee754();
4477
- var customInspectSymbol =
4478
- (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
4479
- ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
4480
- : null;
4481
-
4482
- exports.Buffer = Buffer;
4483
- exports.SlowBuffer = SlowBuffer;
4484
- exports.INSPECT_MAX_BYTES = 50;
4485
-
4486
- var K_MAX_LENGTH = 0x7fffffff;
4487
- exports.kMaxLength = K_MAX_LENGTH;
4488
-
4489
- /**
4490
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
4491
- * === true Use Uint8Array implementation (fastest)
4492
- * === false Print warning and recommend using `buffer` v4.x which has an Object
4493
- * implementation (most compatible, even IE6)
4494
- *
4495
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
4496
- * Opera 11.6+, iOS 4.2+.
4497
- *
4498
- * We report that the browser does not support typed arrays if the are not subclassable
4499
- * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
4500
- * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
4501
- * for __proto__ and has a buggy typed array implementation.
4502
- */
4503
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
4504
-
4505
- if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
4506
- typeof console.error === 'function') {
4507
- console.error(
4508
- 'This browser lacks typed array (Uint8Array) support which is required by ' +
4509
- '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
4510
- );
4511
- }
4512
-
4513
- function typedArraySupport () {
4514
- // Can typed array instances can be augmented?
4515
- try {
4516
- var arr = new Uint8Array(1);
4517
- var proto = { foo: function () { return 42 } };
4518
- Object.setPrototypeOf(proto, Uint8Array.prototype);
4519
- Object.setPrototypeOf(arr, proto);
4520
- return arr.foo() === 42
4521
- } catch (e) {
4522
- return false
4523
- }
4524
- }
4525
-
4526
- Object.defineProperty(Buffer.prototype, 'parent', {
4527
- enumerable: true,
4528
- get: function () {
4529
- if (!Buffer.isBuffer(this)) return undefined
4530
- return this.buffer
4531
- }
4532
- });
4533
-
4534
- Object.defineProperty(Buffer.prototype, 'offset', {
4535
- enumerable: true,
4536
- get: function () {
4537
- if (!Buffer.isBuffer(this)) return undefined
4538
- return this.byteOffset
4539
- }
4540
- });
4541
-
4542
- function createBuffer (length) {
4543
- if (length > K_MAX_LENGTH) {
4544
- throw new RangeError('The value "' + length + '" is invalid for option "size"')
4545
- }
4546
- // Return an augmented `Uint8Array` instance
4547
- var buf = new Uint8Array(length);
4548
- Object.setPrototypeOf(buf, Buffer.prototype);
4549
- return buf
4550
- }
4551
-
4552
- /**
4553
- * The Buffer constructor returns instances of `Uint8Array` that have their
4554
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
4555
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
4556
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
4557
- * returns a single octet.
4558
- *
4559
- * The `Uint8Array` prototype remains unmodified.
4560
- */
4561
-
4562
- function Buffer (arg, encodingOrOffset, length) {
4563
- // Common case.
4564
- if (typeof arg === 'number') {
4565
- if (typeof encodingOrOffset === 'string') {
4566
- throw new TypeError(
4567
- 'The "string" argument must be of type string. Received type number'
4568
- )
4569
- }
4570
- return allocUnsafe(arg)
4571
- }
4572
- return from(arg, encodingOrOffset, length)
4573
- }
4574
-
4575
- Buffer.poolSize = 8192; // not used by this implementation
4576
-
4577
- function from (value, encodingOrOffset, length) {
4578
- if (typeof value === 'string') {
4579
- return fromString(value, encodingOrOffset)
4580
- }
4581
-
4582
- if (ArrayBuffer.isView(value)) {
4583
- return fromArrayView(value)
4584
- }
4585
-
4586
- if (value == null) {
4587
- throw new TypeError(
4588
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
4589
- 'or Array-like Object. Received type ' + (typeof value)
4590
- )
4591
- }
4592
-
4593
- if (isInstance(value, ArrayBuffer) ||
4594
- (value && isInstance(value.buffer, ArrayBuffer))) {
4595
- return fromArrayBuffer(value, encodingOrOffset, length)
4596
- }
4597
-
4598
- if (typeof SharedArrayBuffer !== 'undefined' &&
4599
- (isInstance(value, SharedArrayBuffer) ||
4600
- (value && isInstance(value.buffer, SharedArrayBuffer)))) {
4601
- return fromArrayBuffer(value, encodingOrOffset, length)
4602
- }
4603
-
4604
- if (typeof value === 'number') {
4605
- throw new TypeError(
4606
- 'The "value" argument must not be of type number. Received type number'
4607
- )
4608
- }
4609
-
4610
- var valueOf = value.valueOf && value.valueOf();
4611
- if (valueOf != null && valueOf !== value) {
4612
- return Buffer.from(valueOf, encodingOrOffset, length)
4613
- }
4614
-
4615
- var b = fromObject(value);
4616
- if (b) return b
4617
-
4618
- if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
4619
- typeof value[Symbol.toPrimitive] === 'function') {
4620
- return Buffer.from(
4621
- value[Symbol.toPrimitive]('string'), encodingOrOffset, length
4622
- )
4623
- }
4624
-
4625
- throw new TypeError(
4626
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
4627
- 'or Array-like Object. Received type ' + (typeof value)
4628
- )
4629
- }
4630
-
4631
- /**
4632
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
4633
- * if value is a number.
4634
- * Buffer.from(str[, encoding])
4635
- * Buffer.from(array)
4636
- * Buffer.from(buffer)
4637
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
4638
- **/
4639
- Buffer.from = function (value, encodingOrOffset, length) {
4640
- return from(value, encodingOrOffset, length)
4641
- };
4642
-
4643
- // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
4644
- // https://github.com/feross/buffer/pull/148
4645
- Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
4646
- Object.setPrototypeOf(Buffer, Uint8Array);
4647
-
4648
- function assertSize (size) {
4649
- if (typeof size !== 'number') {
4650
- throw new TypeError('"size" argument must be of type number')
4651
- } else if (size < 0) {
4652
- throw new RangeError('The value "' + size + '" is invalid for option "size"')
4653
- }
4654
- }
4655
-
4656
- function alloc (size, fill, encoding) {
4657
- assertSize(size);
4658
- if (size <= 0) {
4659
- return createBuffer(size)
4660
- }
4661
- if (fill !== undefined) {
4662
- // Only pay attention to encoding if it's a string. This
4663
- // prevents accidentally sending in a number that would
4664
- // be interpreted as a start offset.
4665
- return typeof encoding === 'string'
4666
- ? createBuffer(size).fill(fill, encoding)
4667
- : createBuffer(size).fill(fill)
4668
- }
4669
- return createBuffer(size)
4670
- }
4671
-
4672
- /**
4673
- * Creates a new filled Buffer instance.
4674
- * alloc(size[, fill[, encoding]])
4675
- **/
4676
- Buffer.alloc = function (size, fill, encoding) {
4677
- return alloc(size, fill, encoding)
4678
- };
4679
-
4680
- function allocUnsafe (size) {
4681
- assertSize(size);
4682
- return createBuffer(size < 0 ? 0 : checked(size) | 0)
4683
- }
4684
-
4685
- /**
4686
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
4687
- * */
4688
- Buffer.allocUnsafe = function (size) {
4689
- return allocUnsafe(size)
4690
- };
4691
- /**
4692
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
4693
- */
4694
- Buffer.allocUnsafeSlow = function (size) {
4695
- return allocUnsafe(size)
4696
- };
4697
-
4698
- function fromString (string, encoding) {
4699
- if (typeof encoding !== 'string' || encoding === '') {
4700
- encoding = 'utf8';
4701
- }
4702
-
4703
- if (!Buffer.isEncoding(encoding)) {
4704
- throw new TypeError('Unknown encoding: ' + encoding)
4705
- }
4706
-
4707
- var length = byteLength(string, encoding) | 0;
4708
- var buf = createBuffer(length);
4709
-
4710
- var actual = buf.write(string, encoding);
4711
-
4712
- if (actual !== length) {
4713
- // Writing a hex string, for example, that contains invalid characters will
4714
- // cause everything after the first invalid character to be ignored. (e.g.
4715
- // 'abxxcd' will be treated as 'ab')
4716
- buf = buf.slice(0, actual);
4717
- }
4718
-
4719
- return buf
4720
- }
4721
-
4722
- function fromArrayLike (array) {
4723
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
4724
- var buf = createBuffer(length);
4725
- for (var i = 0; i < length; i += 1) {
4726
- buf[i] = array[i] & 255;
4727
- }
4728
- return buf
4729
- }
4730
-
4731
- function fromArrayView (arrayView) {
4732
- if (isInstance(arrayView, Uint8Array)) {
4733
- var copy = new Uint8Array(arrayView);
4734
- return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
4735
- }
4736
- return fromArrayLike(arrayView)
4737
- }
4738
-
4739
- function fromArrayBuffer (array, byteOffset, length) {
4740
- if (byteOffset < 0 || array.byteLength < byteOffset) {
4741
- throw new RangeError('"offset" is outside of buffer bounds')
4742
- }
4743
-
4744
- if (array.byteLength < byteOffset + (length || 0)) {
4745
- throw new RangeError('"length" is outside of buffer bounds')
4746
- }
4747
-
4748
- var buf;
4749
- if (byteOffset === undefined && length === undefined) {
4750
- buf = new Uint8Array(array);
4751
- } else if (length === undefined) {
4752
- buf = new Uint8Array(array, byteOffset);
4753
- } else {
4754
- buf = new Uint8Array(array, byteOffset, length);
4755
- }
4756
-
4757
- // Return an augmented `Uint8Array` instance
4758
- Object.setPrototypeOf(buf, Buffer.prototype);
4759
-
4760
- return buf
4761
- }
4762
-
4763
- function fromObject (obj) {
4764
- if (Buffer.isBuffer(obj)) {
4765
- var len = checked(obj.length) | 0;
4766
- var buf = createBuffer(len);
4767
-
4768
- if (buf.length === 0) {
4769
- return buf
4770
- }
4771
-
4772
- obj.copy(buf, 0, 0, len);
4773
- return buf
4774
- }
4775
-
4776
- if (obj.length !== undefined) {
4777
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
4778
- return createBuffer(0)
4779
- }
4780
- return fromArrayLike(obj)
4781
- }
4782
-
4783
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
4784
- return fromArrayLike(obj.data)
4785
- }
4786
- }
4787
-
4788
- function checked (length) {
4789
- // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
4790
- // length is NaN (which is otherwise coerced to zero.)
4791
- if (length >= K_MAX_LENGTH) {
4792
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
4793
- 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
4794
- }
4795
- return length | 0
4796
- }
4797
-
4798
- function SlowBuffer (length) {
4799
- if (+length != length) { // eslint-disable-line eqeqeq
4800
- length = 0;
4801
- }
4802
- return Buffer.alloc(+length)
4803
- }
4804
-
4805
- Buffer.isBuffer = function isBuffer (b) {
4806
- return b != null && b._isBuffer === true &&
4807
- b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
4808
- };
4809
-
4810
- Buffer.compare = function compare (a, b) {
4811
- if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
4812
- if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
4813
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
4814
- throw new TypeError(
4815
- 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
4816
- )
4817
- }
4818
-
4819
- if (a === b) return 0
4820
-
4821
- var x = a.length;
4822
- var y = b.length;
4823
-
4824
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
4825
- if (a[i] !== b[i]) {
4826
- x = a[i];
4827
- y = b[i];
4828
- break
4829
- }
4830
- }
4831
-
4832
- if (x < y) return -1
4833
- if (y < x) return 1
4834
- return 0
4835
- };
4836
-
4837
- Buffer.isEncoding = function isEncoding (encoding) {
4838
- switch (String(encoding).toLowerCase()) {
4839
- case 'hex':
4840
- case 'utf8':
4841
- case 'utf-8':
4842
- case 'ascii':
4843
- case 'latin1':
4844
- case 'binary':
4845
- case 'base64':
4846
- case 'ucs2':
4847
- case 'ucs-2':
4848
- case 'utf16le':
4849
- case 'utf-16le':
4850
- return true
4851
- default:
4852
- return false
4853
- }
4854
- };
4855
-
4856
- Buffer.concat = function concat (list, length) {
4857
- if (!Array.isArray(list)) {
4858
- throw new TypeError('"list" argument must be an Array of Buffers')
4859
- }
4860
-
4861
- if (list.length === 0) {
4862
- return Buffer.alloc(0)
4863
- }
4864
-
4865
- var i;
4866
- if (length === undefined) {
4867
- length = 0;
4868
- for (i = 0; i < list.length; ++i) {
4869
- length += list[i].length;
4870
- }
4871
- }
4872
-
4873
- var buffer = Buffer.allocUnsafe(length);
4874
- var pos = 0;
4875
- for (i = 0; i < list.length; ++i) {
4876
- var buf = list[i];
4877
- if (isInstance(buf, Uint8Array)) {
4878
- if (pos + buf.length > buffer.length) {
4879
- Buffer.from(buf).copy(buffer, pos);
4880
- } else {
4881
- Uint8Array.prototype.set.call(
4882
- buffer,
4883
- buf,
4884
- pos
4885
- );
4886
- }
4887
- } else if (!Buffer.isBuffer(buf)) {
4888
- throw new TypeError('"list" argument must be an Array of Buffers')
4889
- } else {
4890
- buf.copy(buffer, pos);
4891
- }
4892
- pos += buf.length;
4893
- }
4894
- return buffer
4895
- };
4896
-
4897
- function byteLength (string, encoding) {
4898
- if (Buffer.isBuffer(string)) {
4899
- return string.length
4900
- }
4901
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
4902
- return string.byteLength
4903
- }
4904
- if (typeof string !== 'string') {
4905
- throw new TypeError(
4906
- 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
4907
- 'Received type ' + typeof string
4908
- )
4909
- }
4910
-
4911
- var len = string.length;
4912
- var mustMatch = (arguments.length > 2 && arguments[2] === true);
4913
- if (!mustMatch && len === 0) return 0
4914
-
4915
- // Use a for loop to avoid recursion
4916
- var loweredCase = false;
4917
- for (;;) {
4918
- switch (encoding) {
4919
- case 'ascii':
4920
- case 'latin1':
4921
- case 'binary':
4922
- return len
4923
- case 'utf8':
4924
- case 'utf-8':
4925
- return utf8ToBytes(string).length
4926
- case 'ucs2':
4927
- case 'ucs-2':
4928
- case 'utf16le':
4929
- case 'utf-16le':
4930
- return len * 2
4931
- case 'hex':
4932
- return len >>> 1
4933
- case 'base64':
4934
- return base64ToBytes(string).length
4935
- default:
4936
- if (loweredCase) {
4937
- return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
4938
- }
4939
- encoding = ('' + encoding).toLowerCase();
4940
- loweredCase = true;
4941
- }
4942
- }
4943
- }
4944
- Buffer.byteLength = byteLength;
4945
-
4946
- function slowToString (encoding, start, end) {
4947
- var loweredCase = false;
4948
-
4949
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
4950
- // property of a typed array.
4951
-
4952
- // This behaves neither like String nor Uint8Array in that we set start/end
4953
- // to their upper/lower bounds if the value passed is out of range.
4954
- // undefined is handled specially as per ECMA-262 6th Edition,
4955
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
4956
- if (start === undefined || start < 0) {
4957
- start = 0;
4958
- }
4959
- // Return early if start > this.length. Done here to prevent potential uint32
4960
- // coercion fail below.
4961
- if (start > this.length) {
4962
- return ''
4963
- }
4964
-
4965
- if (end === undefined || end > this.length) {
4966
- end = this.length;
4967
- }
4968
-
4969
- if (end <= 0) {
4970
- return ''
4971
- }
4972
-
4973
- // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
4974
- end >>>= 0;
4975
- start >>>= 0;
4976
-
4977
- if (end <= start) {
4978
- return ''
4979
- }
4980
-
4981
- if (!encoding) encoding = 'utf8';
4982
-
4983
- while (true) {
4984
- switch (encoding) {
4985
- case 'hex':
4986
- return hexSlice(this, start, end)
4987
-
4988
- case 'utf8':
4989
- case 'utf-8':
4990
- return utf8Slice(this, start, end)
4991
-
4992
- case 'ascii':
4993
- return asciiSlice(this, start, end)
4994
-
4995
- case 'latin1':
4996
- case 'binary':
4997
- return latin1Slice(this, start, end)
4998
-
4999
- case 'base64':
5000
- return base64Slice(this, start, end)
5001
-
5002
- case 'ucs2':
5003
- case 'ucs-2':
5004
- case 'utf16le':
5005
- case 'utf-16le':
5006
- return utf16leSlice(this, start, end)
5007
-
5008
- default:
5009
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
5010
- encoding = (encoding + '').toLowerCase();
5011
- loweredCase = true;
5012
- }
5013
- }
5014
- }
5015
-
5016
- // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
5017
- // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
5018
- // reliably in a browserify context because there could be multiple different
5019
- // copies of the 'buffer' package in use. This method works even for Buffer
5020
- // instances that were created from another copy of the `buffer` package.
5021
- // See: https://github.com/feross/buffer/issues/154
5022
- Buffer.prototype._isBuffer = true;
5023
-
5024
- function swap (b, n, m) {
5025
- var i = b[n];
5026
- b[n] = b[m];
5027
- b[m] = i;
5028
- }
5029
-
5030
- Buffer.prototype.swap16 = function swap16 () {
5031
- var len = this.length;
5032
- if (len % 2 !== 0) {
5033
- throw new RangeError('Buffer size must be a multiple of 16-bits')
5034
- }
5035
- for (var i = 0; i < len; i += 2) {
5036
- swap(this, i, i + 1);
5037
- }
5038
- return this
5039
- };
5040
-
5041
- Buffer.prototype.swap32 = function swap32 () {
5042
- var len = this.length;
5043
- if (len % 4 !== 0) {
5044
- throw new RangeError('Buffer size must be a multiple of 32-bits')
5045
- }
5046
- for (var i = 0; i < len; i += 4) {
5047
- swap(this, i, i + 3);
5048
- swap(this, i + 1, i + 2);
5049
- }
5050
- return this
5051
- };
5052
-
5053
- Buffer.prototype.swap64 = function swap64 () {
5054
- var len = this.length;
5055
- if (len % 8 !== 0) {
5056
- throw new RangeError('Buffer size must be a multiple of 64-bits')
5057
- }
5058
- for (var i = 0; i < len; i += 8) {
5059
- swap(this, i, i + 7);
5060
- swap(this, i + 1, i + 6);
5061
- swap(this, i + 2, i + 5);
5062
- swap(this, i + 3, i + 4);
5063
- }
5064
- return this
5065
- };
5066
-
5067
- Buffer.prototype.toString = function toString () {
5068
- var length = this.length;
5069
- if (length === 0) return ''
5070
- if (arguments.length === 0) return utf8Slice(this, 0, length)
5071
- return slowToString.apply(this, arguments)
5072
- };
5073
-
5074
- Buffer.prototype.toLocaleString = Buffer.prototype.toString;
5075
-
5076
- Buffer.prototype.equals = function equals (b) {
5077
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
5078
- if (this === b) return true
5079
- return Buffer.compare(this, b) === 0
5080
- };
5081
-
5082
- Buffer.prototype.inspect = function inspect () {
5083
- var str = '';
5084
- var max = exports.INSPECT_MAX_BYTES;
5085
- str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
5086
- if (this.length > max) str += ' ... ';
5087
- return '<Buffer ' + str + '>'
5088
- };
5089
- if (customInspectSymbol) {
5090
- Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
5091
- }
5092
-
5093
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
5094
- if (isInstance(target, Uint8Array)) {
5095
- target = Buffer.from(target, target.offset, target.byteLength);
5096
- }
5097
- if (!Buffer.isBuffer(target)) {
5098
- throw new TypeError(
5099
- 'The "target" argument must be one of type Buffer or Uint8Array. ' +
5100
- 'Received type ' + (typeof target)
5101
- )
5102
- }
5103
-
5104
- if (start === undefined) {
5105
- start = 0;
5106
- }
5107
- if (end === undefined) {
5108
- end = target ? target.length : 0;
5109
- }
5110
- if (thisStart === undefined) {
5111
- thisStart = 0;
5112
- }
5113
- if (thisEnd === undefined) {
5114
- thisEnd = this.length;
5115
- }
5116
-
5117
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
5118
- throw new RangeError('out of range index')
5119
- }
5120
-
5121
- if (thisStart >= thisEnd && start >= end) {
5122
- return 0
5123
- }
5124
- if (thisStart >= thisEnd) {
5125
- return -1
5126
- }
5127
- if (start >= end) {
5128
- return 1
5129
- }
5130
-
5131
- start >>>= 0;
5132
- end >>>= 0;
5133
- thisStart >>>= 0;
5134
- thisEnd >>>= 0;
5135
-
5136
- if (this === target) return 0
5137
-
5138
- var x = thisEnd - thisStart;
5139
- var y = end - start;
5140
- var len = Math.min(x, y);
5141
-
5142
- var thisCopy = this.slice(thisStart, thisEnd);
5143
- var targetCopy = target.slice(start, end);
5144
-
5145
- for (var i = 0; i < len; ++i) {
5146
- if (thisCopy[i] !== targetCopy[i]) {
5147
- x = thisCopy[i];
5148
- y = targetCopy[i];
5149
- break
5150
- }
5151
- }
5152
-
5153
- if (x < y) return -1
5154
- if (y < x) return 1
5155
- return 0
5156
- };
5157
-
5158
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
5159
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
5160
- //
5161
- // Arguments:
5162
- // - buffer - a Buffer to search
5163
- // - val - a string, Buffer, or number
5164
- // - byteOffset - an index into `buffer`; will be clamped to an int32
5165
- // - encoding - an optional encoding, relevant is val is a string
5166
- // - dir - true for indexOf, false for lastIndexOf
5167
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
5168
- // Empty buffer means no match
5169
- if (buffer.length === 0) return -1
5170
-
5171
- // Normalize byteOffset
5172
- if (typeof byteOffset === 'string') {
5173
- encoding = byteOffset;
5174
- byteOffset = 0;
5175
- } else if (byteOffset > 0x7fffffff) {
5176
- byteOffset = 0x7fffffff;
5177
- } else if (byteOffset < -2147483648) {
5178
- byteOffset = -2147483648;
5179
- }
5180
- byteOffset = +byteOffset; // Coerce to Number.
5181
- if (numberIsNaN(byteOffset)) {
5182
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
5183
- byteOffset = dir ? 0 : (buffer.length - 1);
5184
- }
5185
-
5186
- // Normalize byteOffset: negative offsets start from the end of the buffer
5187
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
5188
- if (byteOffset >= buffer.length) {
5189
- if (dir) return -1
5190
- else byteOffset = buffer.length - 1;
5191
- } else if (byteOffset < 0) {
5192
- if (dir) byteOffset = 0;
5193
- else return -1
5194
- }
5195
-
5196
- // Normalize val
5197
- if (typeof val === 'string') {
5198
- val = Buffer.from(val, encoding);
5199
- }
5200
-
5201
- // Finally, search either indexOf (if dir is true) or lastIndexOf
5202
- if (Buffer.isBuffer(val)) {
5203
- // Special case: looking for empty string/buffer always fails
5204
- if (val.length === 0) {
5205
- return -1
5206
- }
5207
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
5208
- } else if (typeof val === 'number') {
5209
- val = val & 0xFF; // Search for a byte value [0-255]
5210
- if (typeof Uint8Array.prototype.indexOf === 'function') {
5211
- if (dir) {
5212
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
5213
- } else {
5214
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
5215
- }
5216
- }
5217
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
5218
- }
5219
-
5220
- throw new TypeError('val must be string, number or Buffer')
5221
- }
5222
-
5223
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
5224
- var indexSize = 1;
5225
- var arrLength = arr.length;
5226
- var valLength = val.length;
5227
-
5228
- if (encoding !== undefined) {
5229
- encoding = String(encoding).toLowerCase();
5230
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
5231
- encoding === 'utf16le' || encoding === 'utf-16le') {
5232
- if (arr.length < 2 || val.length < 2) {
5233
- return -1
5234
- }
5235
- indexSize = 2;
5236
- arrLength /= 2;
5237
- valLength /= 2;
5238
- byteOffset /= 2;
5239
- }
5240
- }
5241
-
5242
- function read (buf, i) {
5243
- if (indexSize === 1) {
5244
- return buf[i]
5245
- } else {
5246
- return buf.readUInt16BE(i * indexSize)
5247
- }
5248
- }
5249
-
5250
- var i;
5251
- if (dir) {
5252
- var foundIndex = -1;
5253
- for (i = byteOffset; i < arrLength; i++) {
5254
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
5255
- if (foundIndex === -1) foundIndex = i;
5256
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
5257
- } else {
5258
- if (foundIndex !== -1) i -= i - foundIndex;
5259
- foundIndex = -1;
5260
- }
5261
- }
5262
- } else {
5263
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
5264
- for (i = byteOffset; i >= 0; i--) {
5265
- var found = true;
5266
- for (var j = 0; j < valLength; j++) {
5267
- if (read(arr, i + j) !== read(val, j)) {
5268
- found = false;
5269
- break
5270
- }
5271
- }
5272
- if (found) return i
5273
- }
5274
- }
5275
-
5276
- return -1
5277
- }
5278
-
5279
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
5280
- return this.indexOf(val, byteOffset, encoding) !== -1
5281
- };
5282
-
5283
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
5284
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
5285
- };
5286
-
5287
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
5288
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
5289
- };
5290
-
5291
- function hexWrite (buf, string, offset, length) {
5292
- offset = Number(offset) || 0;
5293
- var remaining = buf.length - offset;
5294
- if (!length) {
5295
- length = remaining;
5296
- } else {
5297
- length = Number(length);
5298
- if (length > remaining) {
5299
- length = remaining;
5300
- }
5301
- }
5302
-
5303
- var strLen = string.length;
5304
-
5305
- if (length > strLen / 2) {
5306
- length = strLen / 2;
5307
- }
5308
- for (var i = 0; i < length; ++i) {
5309
- var parsed = parseInt(string.substr(i * 2, 2), 16);
5310
- if (numberIsNaN(parsed)) return i
5311
- buf[offset + i] = parsed;
5312
- }
5313
- return i
5314
- }
5315
-
5316
- function utf8Write (buf, string, offset, length) {
5317
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
5318
- }
5319
-
5320
- function asciiWrite (buf, string, offset, length) {
5321
- return blitBuffer(asciiToBytes(string), buf, offset, length)
5322
- }
5323
-
5324
- function base64Write (buf, string, offset, length) {
5325
- return blitBuffer(base64ToBytes(string), buf, offset, length)
5326
- }
5327
-
5328
- function ucs2Write (buf, string, offset, length) {
5329
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
5330
- }
5331
-
5332
- Buffer.prototype.write = function write (string, offset, length, encoding) {
5333
- // Buffer#write(string)
5334
- if (offset === undefined) {
5335
- encoding = 'utf8';
5336
- length = this.length;
5337
- offset = 0;
5338
- // Buffer#write(string, encoding)
5339
- } else if (length === undefined && typeof offset === 'string') {
5340
- encoding = offset;
5341
- length = this.length;
5342
- offset = 0;
5343
- // Buffer#write(string, offset[, length][, encoding])
5344
- } else if (isFinite(offset)) {
5345
- offset = offset >>> 0;
5346
- if (isFinite(length)) {
5347
- length = length >>> 0;
5348
- if (encoding === undefined) encoding = 'utf8';
5349
- } else {
5350
- encoding = length;
5351
- length = undefined;
5352
- }
5353
- } else {
5354
- throw new Error(
5355
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
5356
- )
5357
- }
5358
-
5359
- var remaining = this.length - offset;
5360
- if (length === undefined || length > remaining) length = remaining;
5361
-
5362
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
5363
- throw new RangeError('Attempt to write outside buffer bounds')
5364
- }
5365
-
5366
- if (!encoding) encoding = 'utf8';
5367
-
5368
- var loweredCase = false;
5369
- for (;;) {
5370
- switch (encoding) {
5371
- case 'hex':
5372
- return hexWrite(this, string, offset, length)
5373
-
5374
- case 'utf8':
5375
- case 'utf-8':
5376
- return utf8Write(this, string, offset, length)
5377
-
5378
- case 'ascii':
5379
- case 'latin1':
5380
- case 'binary':
5381
- return asciiWrite(this, string, offset, length)
5382
-
5383
- case 'base64':
5384
- // Warning: maxLength not taken into account in base64Write
5385
- return base64Write(this, string, offset, length)
5386
-
5387
- case 'ucs2':
5388
- case 'ucs-2':
5389
- case 'utf16le':
5390
- case 'utf-16le':
5391
- return ucs2Write(this, string, offset, length)
5392
-
5393
- default:
5394
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
5395
- encoding = ('' + encoding).toLowerCase();
5396
- loweredCase = true;
5397
- }
5398
- }
5399
- };
5400
-
5401
- Buffer.prototype.toJSON = function toJSON () {
5402
- return {
5403
- type: 'Buffer',
5404
- data: Array.prototype.slice.call(this._arr || this, 0)
5405
- }
5406
- };
5407
-
5408
- function base64Slice (buf, start, end) {
5409
- if (start === 0 && end === buf.length) {
5410
- return base64.fromByteArray(buf)
5411
- } else {
5412
- return base64.fromByteArray(buf.slice(start, end))
5413
- }
5414
- }
5415
-
5416
- function utf8Slice (buf, start, end) {
5417
- end = Math.min(buf.length, end);
5418
- var res = [];
5419
-
5420
- var i = start;
5421
- while (i < end) {
5422
- var firstByte = buf[i];
5423
- var codePoint = null;
5424
- var bytesPerSequence = (firstByte > 0xEF)
5425
- ? 4
5426
- : (firstByte > 0xDF)
5427
- ? 3
5428
- : (firstByte > 0xBF)
5429
- ? 2
5430
- : 1;
5431
-
5432
- if (i + bytesPerSequence <= end) {
5433
- var secondByte, thirdByte, fourthByte, tempCodePoint;
5434
-
5435
- switch (bytesPerSequence) {
5436
- case 1:
5437
- if (firstByte < 0x80) {
5438
- codePoint = firstByte;
5439
- }
5440
- break
5441
- case 2:
5442
- secondByte = buf[i + 1];
5443
- if ((secondByte & 0xC0) === 0x80) {
5444
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
5445
- if (tempCodePoint > 0x7F) {
5446
- codePoint = tempCodePoint;
5447
- }
5448
- }
5449
- break
5450
- case 3:
5451
- secondByte = buf[i + 1];
5452
- thirdByte = buf[i + 2];
5453
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
5454
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
5455
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
5456
- codePoint = tempCodePoint;
5457
- }
5458
- }
5459
- break
5460
- case 4:
5461
- secondByte = buf[i + 1];
5462
- thirdByte = buf[i + 2];
5463
- fourthByte = buf[i + 3];
5464
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
5465
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
5466
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
5467
- codePoint = tempCodePoint;
5468
- }
5469
- }
5470
- }
5471
- }
5472
-
5473
- if (codePoint === null) {
5474
- // we did not generate a valid codePoint so insert a
5475
- // replacement char (U+FFFD) and advance only 1 byte
5476
- codePoint = 0xFFFD;
5477
- bytesPerSequence = 1;
5478
- } else if (codePoint > 0xFFFF) {
5479
- // encode to utf16 (surrogate pair dance)
5480
- codePoint -= 0x10000;
5481
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
5482
- codePoint = 0xDC00 | codePoint & 0x3FF;
5483
- }
5484
-
5485
- res.push(codePoint);
5486
- i += bytesPerSequence;
5487
- }
5488
-
5489
- return decodeCodePointsArray(res)
5490
- }
5491
-
5492
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
5493
- // the lowest limit is Chrome, with 0x10000 args.
5494
- // We go 1 magnitude less, for safety
5495
- var MAX_ARGUMENTS_LENGTH = 0x1000;
5496
-
5497
- function decodeCodePointsArray (codePoints) {
5498
- var len = codePoints.length;
5499
- if (len <= MAX_ARGUMENTS_LENGTH) {
5500
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
5501
- }
5502
-
5503
- // Decode in chunks to avoid "call stack size exceeded".
5504
- var res = '';
5505
- var i = 0;
5506
- while (i < len) {
5507
- res += String.fromCharCode.apply(
5508
- String,
5509
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
5510
- );
5511
- }
5512
- return res
5513
- }
5514
-
5515
- function asciiSlice (buf, start, end) {
5516
- var ret = '';
5517
- end = Math.min(buf.length, end);
5518
-
5519
- for (var i = start; i < end; ++i) {
5520
- ret += String.fromCharCode(buf[i] & 0x7F);
5521
- }
5522
- return ret
5523
- }
5524
-
5525
- function latin1Slice (buf, start, end) {
5526
- var ret = '';
5527
- end = Math.min(buf.length, end);
5528
-
5529
- for (var i = start; i < end; ++i) {
5530
- ret += String.fromCharCode(buf[i]);
5531
- }
5532
- return ret
5533
- }
5534
-
5535
- function hexSlice (buf, start, end) {
5536
- var len = buf.length;
5537
-
5538
- if (!start || start < 0) start = 0;
5539
- if (!end || end < 0 || end > len) end = len;
5540
-
5541
- var out = '';
5542
- for (var i = start; i < end; ++i) {
5543
- out += hexSliceLookupTable[buf[i]];
5544
- }
5545
- return out
5546
- }
5547
-
5548
- function utf16leSlice (buf, start, end) {
5549
- var bytes = buf.slice(start, end);
5550
- var res = '';
5551
- // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
5552
- for (var i = 0; i < bytes.length - 1; i += 2) {
5553
- res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
5554
- }
5555
- return res
5556
- }
5557
-
5558
- Buffer.prototype.slice = function slice (start, end) {
5559
- var len = this.length;
5560
- start = ~~start;
5561
- end = end === undefined ? len : ~~end;
5562
-
5563
- if (start < 0) {
5564
- start += len;
5565
- if (start < 0) start = 0;
5566
- } else if (start > len) {
5567
- start = len;
5568
- }
5569
-
5570
- if (end < 0) {
5571
- end += len;
5572
- if (end < 0) end = 0;
5573
- } else if (end > len) {
5574
- end = len;
5575
- }
5576
-
5577
- if (end < start) end = start;
5578
-
5579
- var newBuf = this.subarray(start, end);
5580
- // Return an augmented `Uint8Array` instance
5581
- Object.setPrototypeOf(newBuf, Buffer.prototype);
5582
-
5583
- return newBuf
5584
- };
5585
-
5586
- /*
5587
- * Need to make sure that buffer isn't trying to write out of bounds.
5588
- */
5589
- function checkOffset (offset, ext, length) {
5590
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
5591
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
5592
- }
5593
-
5594
- Buffer.prototype.readUintLE =
5595
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
5596
- offset = offset >>> 0;
5597
- byteLength = byteLength >>> 0;
5598
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5599
-
5600
- var val = this[offset];
5601
- var mul = 1;
5602
- var i = 0;
5603
- while (++i < byteLength && (mul *= 0x100)) {
5604
- val += this[offset + i] * mul;
5605
- }
5606
-
5607
- return val
5608
- };
5609
-
5610
- Buffer.prototype.readUintBE =
5611
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
5612
- offset = offset >>> 0;
5613
- byteLength = byteLength >>> 0;
5614
- if (!noAssert) {
5615
- checkOffset(offset, byteLength, this.length);
5616
- }
5617
-
5618
- var val = this[offset + --byteLength];
5619
- var mul = 1;
5620
- while (byteLength > 0 && (mul *= 0x100)) {
5621
- val += this[offset + --byteLength] * mul;
5622
- }
5623
-
5624
- return val
5625
- };
5626
-
5627
- Buffer.prototype.readUint8 =
5628
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
5629
- offset = offset >>> 0;
5630
- if (!noAssert) checkOffset(offset, 1, this.length);
5631
- return this[offset]
5632
- };
5633
-
5634
- Buffer.prototype.readUint16LE =
5635
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
5636
- offset = offset >>> 0;
5637
- if (!noAssert) checkOffset(offset, 2, this.length);
5638
- return this[offset] | (this[offset + 1] << 8)
5639
- };
5640
-
5641
- Buffer.prototype.readUint16BE =
5642
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
5643
- offset = offset >>> 0;
5644
- if (!noAssert) checkOffset(offset, 2, this.length);
5645
- return (this[offset] << 8) | this[offset + 1]
5646
- };
5647
-
5648
- Buffer.prototype.readUint32LE =
5649
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
5650
- offset = offset >>> 0;
5651
- if (!noAssert) checkOffset(offset, 4, this.length);
5652
-
5653
- return ((this[offset]) |
5654
- (this[offset + 1] << 8) |
5655
- (this[offset + 2] << 16)) +
5656
- (this[offset + 3] * 0x1000000)
5657
- };
5658
-
5659
- Buffer.prototype.readUint32BE =
5660
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
5661
- offset = offset >>> 0;
5662
- if (!noAssert) checkOffset(offset, 4, this.length);
5663
-
5664
- return (this[offset] * 0x1000000) +
5665
- ((this[offset + 1] << 16) |
5666
- (this[offset + 2] << 8) |
5667
- this[offset + 3])
5668
- };
5669
-
5670
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
5671
- offset = offset >>> 0;
5672
- byteLength = byteLength >>> 0;
5673
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5674
-
5675
- var val = this[offset];
5676
- var mul = 1;
5677
- var i = 0;
5678
- while (++i < byteLength && (mul *= 0x100)) {
5679
- val += this[offset + i] * mul;
5680
- }
5681
- mul *= 0x80;
5682
-
5683
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5684
-
5685
- return val
5686
- };
5687
-
5688
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
5689
- offset = offset >>> 0;
5690
- byteLength = byteLength >>> 0;
5691
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5692
-
5693
- var i = byteLength;
5694
- var mul = 1;
5695
- var val = this[offset + --i];
5696
- while (i > 0 && (mul *= 0x100)) {
5697
- val += this[offset + --i] * mul;
5698
- }
5699
- mul *= 0x80;
5700
-
5701
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5702
-
5703
- return val
5704
- };
5705
-
5706
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
5707
- offset = offset >>> 0;
5708
- if (!noAssert) checkOffset(offset, 1, this.length);
5709
- if (!(this[offset] & 0x80)) return (this[offset])
5710
- return ((0xff - this[offset] + 1) * -1)
5711
- };
5712
-
5713
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
5714
- offset = offset >>> 0;
5715
- if (!noAssert) checkOffset(offset, 2, this.length);
5716
- var val = this[offset] | (this[offset + 1] << 8);
5717
- return (val & 0x8000) ? val | 0xFFFF0000 : val
5718
- };
5719
-
5720
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
5721
- offset = offset >>> 0;
5722
- if (!noAssert) checkOffset(offset, 2, this.length);
5723
- var val = this[offset + 1] | (this[offset] << 8);
5724
- return (val & 0x8000) ? val | 0xFFFF0000 : val
5725
- };
5726
-
5727
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
5728
- offset = offset >>> 0;
5729
- if (!noAssert) checkOffset(offset, 4, this.length);
5730
-
5731
- return (this[offset]) |
5732
- (this[offset + 1] << 8) |
5733
- (this[offset + 2] << 16) |
5734
- (this[offset + 3] << 24)
5735
- };
5736
-
5737
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
5738
- offset = offset >>> 0;
5739
- if (!noAssert) checkOffset(offset, 4, this.length);
5740
-
5741
- return (this[offset] << 24) |
5742
- (this[offset + 1] << 16) |
5743
- (this[offset + 2] << 8) |
5744
- (this[offset + 3])
5745
- };
5746
-
5747
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
5748
- offset = offset >>> 0;
5749
- if (!noAssert) checkOffset(offset, 4, this.length);
5750
- return ieee754.read(this, offset, true, 23, 4)
5751
- };
5752
-
5753
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
5754
- offset = offset >>> 0;
5755
- if (!noAssert) checkOffset(offset, 4, this.length);
5756
- return ieee754.read(this, offset, false, 23, 4)
5757
- };
5758
-
5759
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
5760
- offset = offset >>> 0;
5761
- if (!noAssert) checkOffset(offset, 8, this.length);
5762
- return ieee754.read(this, offset, true, 52, 8)
5763
- };
5764
-
5765
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
5766
- offset = offset >>> 0;
5767
- if (!noAssert) checkOffset(offset, 8, this.length);
5768
- return ieee754.read(this, offset, false, 52, 8)
5769
- };
5770
-
5771
- function checkInt (buf, value, offset, ext, max, min) {
5772
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
5773
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
5774
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
5775
- }
5776
-
5777
- Buffer.prototype.writeUintLE =
5778
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
5779
- value = +value;
5780
- offset = offset >>> 0;
5781
- byteLength = byteLength >>> 0;
5782
- if (!noAssert) {
5783
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5784
- checkInt(this, value, offset, byteLength, maxBytes, 0);
5785
- }
5786
-
5787
- var mul = 1;
5788
- var i = 0;
5789
- this[offset] = value & 0xFF;
5790
- while (++i < byteLength && (mul *= 0x100)) {
5791
- this[offset + i] = (value / mul) & 0xFF;
5792
- }
5793
-
5794
- return offset + byteLength
5795
- };
5796
-
5797
- Buffer.prototype.writeUintBE =
5798
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
5799
- value = +value;
5800
- offset = offset >>> 0;
5801
- byteLength = byteLength >>> 0;
5802
- if (!noAssert) {
5803
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5804
- checkInt(this, value, offset, byteLength, maxBytes, 0);
5805
- }
5806
-
5807
- var i = byteLength - 1;
5808
- var mul = 1;
5809
- this[offset + i] = value & 0xFF;
5810
- while (--i >= 0 && (mul *= 0x100)) {
5811
- this[offset + i] = (value / mul) & 0xFF;
5812
- }
5813
-
5814
- return offset + byteLength
5815
- };
5816
-
5817
- Buffer.prototype.writeUint8 =
5818
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
5819
- value = +value;
5820
- offset = offset >>> 0;
5821
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
5822
- this[offset] = (value & 0xff);
5823
- return offset + 1
5824
- };
5825
-
5826
- Buffer.prototype.writeUint16LE =
5827
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
5828
- value = +value;
5829
- offset = offset >>> 0;
5830
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5831
- this[offset] = (value & 0xff);
5832
- this[offset + 1] = (value >>> 8);
5833
- return offset + 2
5834
- };
5835
-
5836
- Buffer.prototype.writeUint16BE =
5837
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
5838
- value = +value;
5839
- offset = offset >>> 0;
5840
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5841
- this[offset] = (value >>> 8);
5842
- this[offset + 1] = (value & 0xff);
5843
- return offset + 2
5844
- };
3873
+ lo = lo >> 8;
3874
+ buf[offset + 4] = lo;
3875
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
3876
+ buf[offset + 3] = hi;
3877
+ hi = hi >> 8;
3878
+ buf[offset + 2] = hi;
3879
+ hi = hi >> 8;
3880
+ buf[offset + 1] = hi;
3881
+ hi = hi >> 8;
3882
+ buf[offset] = hi;
3883
+ return offset + 8
3884
+ }
5845
3885
 
5846
- Buffer.prototype.writeUint32LE =
5847
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
5848
- value = +value;
5849
- offset = offset >>> 0;
5850
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5851
- this[offset + 3] = (value >>> 24);
5852
- this[offset + 2] = (value >>> 16);
5853
- this[offset + 1] = (value >>> 8);
5854
- this[offset] = (value & 0xff);
5855
- return offset + 4
5856
- };
3886
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
3887
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3888
+ });
5857
3889
 
5858
- Buffer.prototype.writeUint32BE =
5859
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
5860
- value = +value;
5861
- offset = offset >>> 0;
5862
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5863
- this[offset] = (value >>> 24);
5864
- this[offset + 1] = (value >>> 16);
5865
- this[offset + 2] = (value >>> 8);
5866
- this[offset + 3] = (value & 0xff);
5867
- return offset + 4
5868
- };
3890
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
3891
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
3892
+ });
5869
3893
 
5870
3894
  Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
5871
3895
  value = +value;
5872
3896
  offset = offset >>> 0;
5873
3897
  if (!noAssert) {
5874
- var limit = Math.pow(2, (8 * byteLength) - 1);
3898
+ const limit = Math.pow(2, (8 * byteLength) - 1);
5875
3899
 
5876
3900
  checkInt(this, value, offset, byteLength, limit - 1, -limit);
5877
3901
  }
5878
3902
 
5879
- var i = 0;
5880
- var mul = 1;
5881
- var sub = 0;
3903
+ let i = 0;
3904
+ let mul = 1;
3905
+ let sub = 0;
5882
3906
  this[offset] = value & 0xFF;
5883
3907
  while (++i < byteLength && (mul *= 0x100)) {
5884
3908
  if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
@@ -5894,14 +3918,14 @@ function requireBuffer () {
5894
3918
  value = +value;
5895
3919
  offset = offset >>> 0;
5896
3920
  if (!noAssert) {
5897
- var limit = Math.pow(2, (8 * byteLength) - 1);
3921
+ const limit = Math.pow(2, (8 * byteLength) - 1);
5898
3922
 
5899
3923
  checkInt(this, value, offset, byteLength, limit - 1, -limit);
5900
3924
  }
5901
3925
 
5902
- var i = byteLength - 1;
5903
- var mul = 1;
5904
- var sub = 0;
3926
+ let i = byteLength - 1;
3927
+ let mul = 1;
3928
+ let sub = 0;
5905
3929
  this[offset + i] = value & 0xFF;
5906
3930
  while (--i >= 0 && (mul *= 0x100)) {
5907
3931
  if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
@@ -5963,6 +3987,14 @@ function requireBuffer () {
5963
3987
  return offset + 4
5964
3988
  };
5965
3989
 
3990
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
3991
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3992
+ });
3993
+
3994
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
3995
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
3996
+ });
3997
+
5966
3998
  function checkIEEE754 (buf, value, offset, ext, max, min) {
5967
3999
  if (offset + ext > buf.length) throw new RangeError('Index out of range')
5968
4000
  if (offset < 0) throw new RangeError('Index out of range')
@@ -6030,7 +4062,7 @@ function requireBuffer () {
6030
4062
  end = target.length - targetStart + start;
6031
4063
  }
6032
4064
 
6033
- var len = end - start;
4065
+ const len = end - start;
6034
4066
 
6035
4067
  if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
6036
4068
  // Use built-in when available, missing from IE11
@@ -6068,7 +4100,7 @@ function requireBuffer () {
6068
4100
  throw new TypeError('Unknown encoding: ' + encoding)
6069
4101
  }
6070
4102
  if (val.length === 1) {
6071
- var code = val.charCodeAt(0);
4103
+ const code = val.charCodeAt(0);
6072
4104
  if ((encoding === 'utf8' && code < 128) ||
6073
4105
  encoding === 'latin1') {
6074
4106
  // Fast path: If `val` fits into a single byte, use that numeric value.
@@ -6095,16 +4127,16 @@ function requireBuffer () {
6095
4127
 
6096
4128
  if (!val) val = 0;
6097
4129
 
6098
- var i;
4130
+ let i;
6099
4131
  if (typeof val === 'number') {
6100
4132
  for (i = start; i < end; ++i) {
6101
4133
  this[i] = val;
6102
4134
  }
6103
4135
  } else {
6104
- var bytes = Buffer.isBuffer(val)
4136
+ const bytes = Buffer.isBuffer(val)
6105
4137
  ? val
6106
4138
  : Buffer.from(val, encoding);
6107
- var len = bytes.length;
4139
+ const len = bytes.length;
6108
4140
  if (len === 0) {
6109
4141
  throw new TypeError('The value "' + val +
6110
4142
  '" is invalid for argument "value"')
@@ -6117,10 +4149,141 @@ function requireBuffer () {
6117
4149
  return this
6118
4150
  };
6119
4151
 
4152
+ // CUSTOM ERRORS
4153
+ // =============
4154
+
4155
+ // Simplified versions from Node, changed for Buffer-only usage
4156
+ const errors = {};
4157
+ function E (sym, getMessage, Base) {
4158
+ errors[sym] = class NodeError extends Base {
4159
+ constructor () {
4160
+ super();
4161
+
4162
+ Object.defineProperty(this, 'message', {
4163
+ value: getMessage.apply(this, arguments),
4164
+ writable: true,
4165
+ configurable: true
4166
+ });
4167
+
4168
+ // Add the error code to the name to include it in the stack trace.
4169
+ this.name = `${this.name} [${sym}]`;
4170
+ // Access the stack to generate the error message including the error code
4171
+ // from the name.
4172
+ this.stack; // eslint-disable-line no-unused-expressions
4173
+ // Reset the name to the actual name.
4174
+ delete this.name;
4175
+ }
4176
+
4177
+ get code () {
4178
+ return sym
4179
+ }
4180
+
4181
+ set code (value) {
4182
+ Object.defineProperty(this, 'code', {
4183
+ configurable: true,
4184
+ enumerable: true,
4185
+ value,
4186
+ writable: true
4187
+ });
4188
+ }
4189
+
4190
+ toString () {
4191
+ return `${this.name} [${sym}]: ${this.message}`
4192
+ }
4193
+ };
4194
+ }
4195
+
4196
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
4197
+ function (name) {
4198
+ if (name) {
4199
+ return `${name} is outside of buffer bounds`
4200
+ }
4201
+
4202
+ return 'Attempt to access memory outside buffer bounds'
4203
+ }, RangeError);
4204
+ E('ERR_INVALID_ARG_TYPE',
4205
+ function (name, actual) {
4206
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
4207
+ }, TypeError);
4208
+ E('ERR_OUT_OF_RANGE',
4209
+ function (str, range, input) {
4210
+ let msg = `The value of "${str}" is out of range.`;
4211
+ let received = input;
4212
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
4213
+ received = addNumericalSeparator(String(input));
4214
+ } else if (typeof input === 'bigint') {
4215
+ received = String(input);
4216
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
4217
+ received = addNumericalSeparator(received);
4218
+ }
4219
+ received += 'n';
4220
+ }
4221
+ msg += ` It must be ${range}. Received ${received}`;
4222
+ return msg
4223
+ }, RangeError);
4224
+
4225
+ function addNumericalSeparator (val) {
4226
+ let res = '';
4227
+ let i = val.length;
4228
+ const start = val[0] === '-' ? 1 : 0;
4229
+ for (; i >= start + 4; i -= 3) {
4230
+ res = `_${val.slice(i - 3, i)}${res}`;
4231
+ }
4232
+ return `${val.slice(0, i)}${res}`
4233
+ }
4234
+
4235
+ // CHECK FUNCTIONS
4236
+ // ===============
4237
+
4238
+ function checkBounds (buf, offset, byteLength) {
4239
+ validateNumber(offset, 'offset');
4240
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
4241
+ boundsError(offset, buf.length - (byteLength + 1));
4242
+ }
4243
+ }
4244
+
4245
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
4246
+ if (value > max || value < min) {
4247
+ const n = typeof min === 'bigint' ? 'n' : '';
4248
+ let range;
4249
+ {
4250
+ if (min === 0 || min === BigInt(0)) {
4251
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
4252
+ } else {
4253
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
4254
+ `${(byteLength + 1) * 8 - 1}${n}`;
4255
+ }
4256
+ }
4257
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
4258
+ }
4259
+ checkBounds(buf, offset, byteLength);
4260
+ }
4261
+
4262
+ function validateNumber (value, name) {
4263
+ if (typeof value !== 'number') {
4264
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
4265
+ }
4266
+ }
4267
+
4268
+ function boundsError (value, length, type) {
4269
+ if (Math.floor(value) !== value) {
4270
+ validateNumber(value, type);
4271
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
4272
+ }
4273
+
4274
+ if (length < 0) {
4275
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
4276
+ }
4277
+
4278
+ throw new errors.ERR_OUT_OF_RANGE('offset',
4279
+ `>= ${0} and <= ${length}`,
4280
+ value)
4281
+ }
4282
+
6120
4283
  // HELPER FUNCTIONS
6121
4284
  // ================
6122
4285
 
6123
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
4286
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
6124
4287
 
6125
4288
  function base64clean (str) {
6126
4289
  // Node takes equal signs as end of the Base64 encoding
@@ -6138,12 +4301,12 @@ function requireBuffer () {
6138
4301
 
6139
4302
  function utf8ToBytes (string, units) {
6140
4303
  units = units || Infinity;
6141
- var codePoint;
6142
- var length = string.length;
6143
- var leadSurrogate = null;
6144
- var bytes = [];
4304
+ let codePoint;
4305
+ const length = string.length;
4306
+ let leadSurrogate = null;
4307
+ const bytes = [];
6145
4308
 
6146
- for (var i = 0; i < length; ++i) {
4309
+ for (let i = 0; i < length; ++i) {
6147
4310
  codePoint = string.charCodeAt(i);
6148
4311
 
6149
4312
  // is surrogate component
@@ -6217,8 +4380,8 @@ function requireBuffer () {
6217
4380
  }
6218
4381
 
6219
4382
  function asciiToBytes (str) {
6220
- var byteArray = [];
6221
- for (var i = 0; i < str.length; ++i) {
4383
+ const byteArray = [];
4384
+ for (let i = 0; i < str.length; ++i) {
6222
4385
  // Node's code seems to be doing this and not & 0x7F..
6223
4386
  byteArray.push(str.charCodeAt(i) & 0xFF);
6224
4387
  }
@@ -6226,9 +4389,9 @@ function requireBuffer () {
6226
4389
  }
6227
4390
 
6228
4391
  function utf16leToBytes (str, units) {
6229
- var c, hi, lo;
6230
- var byteArray = [];
6231
- for (var i = 0; i < str.length; ++i) {
4392
+ let c, hi, lo;
4393
+ const byteArray = [];
4394
+ for (let i = 0; i < str.length; ++i) {
6232
4395
  if ((units -= 2) < 0) break
6233
4396
 
6234
4397
  c = str.charCodeAt(i);
@@ -6246,7 +4409,8 @@ function requireBuffer () {
6246
4409
  }
6247
4410
 
6248
4411
  function blitBuffer (src, dst, offset, length) {
6249
- for (var i = 0; i < length; ++i) {
4412
+ let i;
4413
+ for (i = 0; i < length; ++i) {
6250
4414
  if ((i + offset >= dst.length) || (i >= src.length)) break
6251
4415
  dst[i + offset] = src[i];
6252
4416
  }
@@ -6268,23 +4432,34 @@ function requireBuffer () {
6268
4432
 
6269
4433
  // Create lookup table for `toString('hex')`
6270
4434
  // See: https://github.com/feross/buffer/issues/219
6271
- var hexSliceLookupTable = (function () {
6272
- var alphabet = '0123456789abcdef';
6273
- var table = new Array(256);
6274
- for (var i = 0; i < 16; ++i) {
6275
- var i16 = i * 16;
6276
- for (var j = 0; j < 16; ++j) {
4435
+ const hexSliceLookupTable = (function () {
4436
+ const alphabet = '0123456789abcdef';
4437
+ const table = new Array(256);
4438
+ for (let i = 0; i < 16; ++i) {
4439
+ const i16 = i * 16;
4440
+ for (let j = 0; j < 16; ++j) {
6277
4441
  table[i16 + j] = alphabet[i] + alphabet[j];
6278
4442
  }
6279
4443
  }
6280
4444
  return table
6281
- })();
4445
+ })();
4446
+
4447
+ // Return not function with Error if BigInt not supported
4448
+ function defineBigIntMethod (fn) {
4449
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
4450
+ }
4451
+
4452
+ function BufferBigIntNotDefined () {
4453
+ throw new Error('BigInt not supported')
4454
+ }
6282
4455
  } (buffer));
6283
4456
  return buffer;
6284
4457
  }
6285
4458
 
6286
4459
  var bufferExports = requireBuffer();
6287
4460
 
4461
+ var dist = {};
4462
+
6288
4463
  var Codecs = {};
6289
4464
 
6290
4465
  var Frames = {};
@@ -6294,7 +4469,7 @@ var hasRequiredFrames;
6294
4469
  function requireFrames () {
6295
4470
  if (hasRequiredFrames) return Frames;
6296
4471
  hasRequiredFrames = 1;
6297
- (function (exports) {
4472
+ (function (exports$1) {
6298
4473
  /*
6299
4474
  * Copyright 2021-2022 the original author or authors.
6300
4475
  *
@@ -6310,8 +4485,8 @@ function requireFrames () {
6310
4485
  * See the License for the specific language governing permissions and
6311
4486
  * limitations under the License.
6312
4487
  */
6313
- Object.defineProperty(exports, "__esModule", { value: true });
6314
- exports.Frame = exports.Lengths = exports.Flags = exports.FrameTypes = void 0;
4488
+ Object.defineProperty(exports$1, "__esModule", { value: true });
4489
+ exports$1.Frame = exports$1.Lengths = exports$1.Flags = exports$1.FrameTypes = void 0;
6315
4490
  var FrameTypes;
6316
4491
  (function (FrameTypes) {
6317
4492
  FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
@@ -6330,7 +4505,7 @@ function requireFrames () {
6330
4505
  FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
6331
4506
  FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
6332
4507
  FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
6333
- })(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
4508
+ })(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
6334
4509
  (function (Flags) {
6335
4510
  Flags[Flags["NONE"] = 0] = "NONE";
6336
4511
  Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
@@ -6341,7 +4516,7 @@ function requireFrames () {
6341
4516
  Flags[Flags["NEXT"] = 32] = "NEXT";
6342
4517
  Flags[Flags["RESPOND"] = 128] = "RESPOND";
6343
4518
  Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
6344
- })(exports.Flags || (exports.Flags = {}));
4519
+ })(exports$1.Flags || (exports$1.Flags = {}));
6345
4520
  (function (Flags) {
6346
4521
  function hasMetadata(flags) {
6347
4522
  return (flags & Flags.METADATA) === Flags.METADATA;
@@ -6375,13 +4550,13 @@ function requireFrames () {
6375
4550
  return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
6376
4551
  }
6377
4552
  Flags.hasResume = hasResume;
6378
- })(exports.Flags || (exports.Flags = {}));
4553
+ })(exports$1.Flags || (exports$1.Flags = {}));
6379
4554
  (function (Lengths) {
6380
4555
  Lengths[Lengths["FRAME"] = 3] = "FRAME";
6381
4556
  Lengths[Lengths["HEADER"] = 6] = "HEADER";
6382
4557
  Lengths[Lengths["METADATA"] = 3] = "METADATA";
6383
4558
  Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
6384
- })(exports.Lengths || (exports.Lengths = {}));
4559
+ })(exports$1.Lengths || (exports$1.Lengths = {}));
6385
4560
  (function (Frame) {
6386
4561
  function isConnection(frame) {
6387
4562
  return frame.streamId === 0;
@@ -6392,7 +4567,7 @@ function requireFrames () {
6392
4567
  frame.type <= FrameTypes.REQUEST_CHANNEL);
6393
4568
  }
6394
4569
  Frame.isRequest = isRequest;
6395
- })(exports.Frame || (exports.Frame = {}));
4570
+ })(exports$1.Frame || (exports$1.Frame = {}));
6396
4571
 
6397
4572
  } (Frames));
6398
4573
  return Frames;
@@ -6403,7 +4578,7 @@ var hasRequiredCodecs;
6403
4578
  function requireCodecs () {
6404
4579
  if (hasRequiredCodecs) return Codecs;
6405
4580
  hasRequiredCodecs = 1;
6406
- (function (exports) {
4581
+ (function (exports$1) {
6407
4582
  var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
6408
4583
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
6409
4584
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -6431,22 +4606,22 @@ function requireCodecs () {
6431
4606
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6432
4607
  }
6433
4608
  };
6434
- Object.defineProperty(exports, "__esModule", { value: true });
6435
- exports.Deserializer = exports.sizeOfFrame = exports.serializeFrame = exports.deserializeFrame = exports.serializeFrameWithLength = exports.deserializeFrames = exports.deserializeFrameWithLength = exports.writeUInt64BE = exports.readUInt64BE = exports.writeUInt24BE = exports.readUInt24BE = exports.MAX_VERSION = exports.MAX_TTL = exports.MAX_STREAM_ID = exports.MAX_RESUME_LENGTH = exports.MAX_REQUEST_N = exports.MAX_REQUEST_COUNT = exports.MAX_MIME_LENGTH = exports.MAX_METADATA_LENGTH = exports.MAX_LIFETIME = exports.MAX_KEEPALIVE = exports.MAX_CODE = exports.FRAME_TYPE_OFFFSET = exports.FLAGS_MASK = void 0;
4609
+ Object.defineProperty(exports$1, "__esModule", { value: true });
4610
+ exports$1.Deserializer = exports$1.sizeOfFrame = exports$1.serializeFrame = exports$1.deserializeFrame = exports$1.serializeFrameWithLength = exports$1.deserializeFrames = exports$1.deserializeFrameWithLength = exports$1.writeUInt64BE = exports$1.readUInt64BE = exports$1.writeUInt24BE = exports$1.readUInt24BE = exports$1.MAX_VERSION = exports$1.MAX_TTL = exports$1.MAX_STREAM_ID = exports$1.MAX_RESUME_LENGTH = exports$1.MAX_REQUEST_N = exports$1.MAX_REQUEST_COUNT = exports$1.MAX_MIME_LENGTH = exports$1.MAX_METADATA_LENGTH = exports$1.MAX_LIFETIME = exports$1.MAX_KEEPALIVE = exports$1.MAX_CODE = exports$1.FRAME_TYPE_OFFFSET = exports$1.FLAGS_MASK = void 0;
6436
4611
  var Frames_1 = requireFrames();
6437
- exports.FLAGS_MASK = 0x3ff; // low 10 bits
6438
- exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
6439
- exports.MAX_CODE = 0x7fffffff; // uint31
6440
- exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
6441
- exports.MAX_LIFETIME = 0x7fffffff; // uint31
6442
- exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
6443
- exports.MAX_MIME_LENGTH = 0xff; // int8
6444
- exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
6445
- exports.MAX_REQUEST_N = 0x7fffffff; // uint31
6446
- exports.MAX_RESUME_LENGTH = 0xffff; // uint16
6447
- exports.MAX_STREAM_ID = 0x7fffffff; // uint31
6448
- exports.MAX_TTL = 0x7fffffff; // uint31
6449
- exports.MAX_VERSION = 0xffff; // uint16
4612
+ exports$1.FLAGS_MASK = 0x3ff; // low 10 bits
4613
+ exports$1.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
4614
+ exports$1.MAX_CODE = 0x7fffffff; // uint31
4615
+ exports$1.MAX_KEEPALIVE = 0x7fffffff; // uint31
4616
+ exports$1.MAX_LIFETIME = 0x7fffffff; // uint31
4617
+ exports$1.MAX_METADATA_LENGTH = 0xffffff; // uint24
4618
+ exports$1.MAX_MIME_LENGTH = 0xff; // int8
4619
+ exports$1.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
4620
+ exports$1.MAX_REQUEST_N = 0x7fffffff; // uint31
4621
+ exports$1.MAX_RESUME_LENGTH = 0xffff; // uint16
4622
+ exports$1.MAX_STREAM_ID = 0x7fffffff; // uint31
4623
+ exports$1.MAX_TTL = 0x7fffffff; // uint31
4624
+ exports$1.MAX_VERSION = 0xffff; // uint16
6450
4625
  /**
6451
4626
  * Mimimum value that would overflow bitwise operators (2^32).
6452
4627
  */
@@ -6460,7 +4635,7 @@ function requireCodecs () {
6460
4635
  var val3 = buffer.readUInt8(offset + 2);
6461
4636
  return val1 | val2 | val3;
6462
4637
  }
6463
- exports.readUInt24BE = readUInt24BE;
4638
+ exports$1.readUInt24BE = readUInt24BE;
6464
4639
  /**
6465
4640
  * Writes a uint24 to a buffer starting at the given offset, returning the
6466
4641
  * offset of the next byte.
@@ -6470,7 +4645,7 @@ function requireCodecs () {
6470
4645
  offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
6471
4646
  return buffer.writeUInt8(value & 0xff, offset); // 1st byte
6472
4647
  }
6473
- exports.writeUInt24BE = writeUInt24BE;
4648
+ exports$1.writeUInt24BE = writeUInt24BE;
6474
4649
  /**
6475
4650
  * Read a uint64 (technically supports up to 53 bits per JS number
6476
4651
  * representation).
@@ -6480,7 +4655,7 @@ function requireCodecs () {
6480
4655
  var low = buffer.readUInt32BE(offset + 4);
6481
4656
  return high * BITWISE_OVERFLOW + low;
6482
4657
  }
6483
- exports.readUInt64BE = readUInt64BE;
4658
+ exports$1.readUInt64BE = readUInt64BE;
6484
4659
  /**
6485
4660
  * Write a uint64 (technically supports up to 53 bits per JS number
6486
4661
  * representation).
@@ -6491,7 +4666,7 @@ function requireCodecs () {
6491
4666
  offset = buffer.writeUInt32BE(high, offset); // first half of uint64
6492
4667
  return buffer.writeUInt32BE(low, offset); // second half of uint64
6493
4668
  }
6494
- exports.writeUInt64BE = writeUInt64BE;
4669
+ exports$1.writeUInt64BE = writeUInt64BE;
6495
4670
  /**
6496
4671
  * Frame header is:
6497
4672
  * - stream id (uint32 = 4)
@@ -6509,7 +4684,7 @@ function requireCodecs () {
6509
4684
  var frameLength = readUInt24BE(buffer, 0);
6510
4685
  return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
6511
4686
  }
6512
- exports.deserializeFrameWithLength = deserializeFrameWithLength;
4687
+ exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
6513
4688
  /**
6514
4689
  * Given a buffer that may contain zero or more length-prefixed frames followed
6515
4690
  * by zero or more bytes of a (partial) subsequent frame, returns an array of
@@ -6542,7 +4717,7 @@ function requireCodecs () {
6542
4717
  }
6543
4718
  });
6544
4719
  }
6545
- exports.deserializeFrames = deserializeFrames;
4720
+ exports$1.deserializeFrames = deserializeFrames;
6546
4721
  /**
6547
4722
  * Writes a frame to a buffer with a length prefix.
6548
4723
  */
@@ -6553,7 +4728,7 @@ function requireCodecs () {
6553
4728
  buffer.copy(lengthPrefixed, UINT24_SIZE);
6554
4729
  return lengthPrefixed;
6555
4730
  }
6556
- exports.serializeFrameWithLength = serializeFrameWithLength;
4731
+ exports$1.serializeFrameWithLength = serializeFrameWithLength;
6557
4732
  /**
6558
4733
  * Read a frame from the buffer.
6559
4734
  */
@@ -6568,8 +4743,8 @@ function requireCodecs () {
6568
4743
  // );
6569
4744
  var typeAndFlags = buffer.readUInt16BE(offset);
6570
4745
  offset += 2;
6571
- var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
6572
- var flags = typeAndFlags & exports.FLAGS_MASK; // keep lowest 10 bits
4746
+ var type = typeAndFlags >>> exports$1.FRAME_TYPE_OFFFSET; // keep highest 6 bits
4747
+ var flags = typeAndFlags & exports$1.FLAGS_MASK; // keep lowest 10 bits
6573
4748
  switch (type) {
6574
4749
  case Frames_1.FrameTypes.SETUP:
6575
4750
  return deserializeSetupFrame(buffer, streamId, flags);
@@ -6606,7 +4781,7 @@ function requireCodecs () {
6606
4781
  // );
6607
4782
  }
6608
4783
  }
6609
- exports.deserializeFrame = deserializeFrame;
4784
+ exports$1.deserializeFrame = deserializeFrame;
6610
4785
  /**
6611
4786
  * Convert the frame to a (binary) buffer.
6612
4787
  */
@@ -6645,7 +4820,7 @@ function requireCodecs () {
6645
4820
  // );
6646
4821
  }
6647
4822
  }
6648
- exports.serializeFrame = serializeFrame;
4823
+ exports$1.serializeFrame = serializeFrame;
6649
4824
  /**
6650
4825
  * Byte size of frame without size prefix
6651
4826
  */
@@ -6684,7 +4859,7 @@ function requireCodecs () {
6684
4859
  // );
6685
4860
  }
6686
4861
  }
6687
- exports.sizeOfFrame = sizeOfFrame;
4862
+ exports$1.sizeOfFrame = sizeOfFrame;
6688
4863
  /**
6689
4864
  * Writes a SETUP frame into a new buffer and returns it.
6690
4865
  *
@@ -7319,7 +5494,7 @@ function requireCodecs () {
7319
5494
  function writeHeader(frame, buffer) {
7320
5495
  var offset = buffer.writeInt32BE(frame.streamId, 0);
7321
5496
  // shift frame to high 6 bits, extract lowest 10 bits from flags
7322
- return buffer.writeUInt16BE((frame.type << exports.FRAME_TYPE_OFFFSET) | (frame.flags & exports.FLAGS_MASK), offset);
5497
+ return buffer.writeUInt16BE((frame.type << exports$1.FRAME_TYPE_OFFFSET) | (frame.flags & exports$1.FLAGS_MASK), offset);
7323
5498
  }
7324
5499
  /**
7325
5500
  * Determine the length of the payload section of a frame. Only applies to
@@ -7400,7 +5575,7 @@ function requireCodecs () {
7400
5575
  };
7401
5576
  return Deserializer;
7402
5577
  }());
7403
- exports.Deserializer = Deserializer;
5578
+ exports$1.Deserializer = Deserializer;
7404
5579
 
7405
5580
  } (Codecs));
7406
5581
  return Codecs;
@@ -7546,7 +5721,7 @@ var hasRequiredErrors;
7546
5721
  function requireErrors () {
7547
5722
  if (hasRequiredErrors) return Errors;
7548
5723
  hasRequiredErrors = 1;
7549
- (function (exports) {
5724
+ (function (exports$1) {
7550
5725
  /*
7551
5726
  * Copyright 2021-2022 the original author or authors.
7552
5727
  *
@@ -7577,8 +5752,8 @@ function requireErrors () {
7577
5752
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
7578
5753
  };
7579
5754
  })();
7580
- Object.defineProperty(exports, "__esModule", { value: true });
7581
- exports.ErrorCodes = exports.RSocketError = void 0;
5755
+ Object.defineProperty(exports$1, "__esModule", { value: true });
5756
+ exports$1.ErrorCodes = exports$1.RSocketError = void 0;
7582
5757
  var RSocketError = /** @class */ (function (_super) {
7583
5758
  __extends(RSocketError, _super);
7584
5759
  function RSocketError(code, message) {
@@ -7588,7 +5763,7 @@ function requireErrors () {
7588
5763
  }
7589
5764
  return RSocketError;
7590
5765
  }(Error));
7591
- exports.RSocketError = RSocketError;
5766
+ exports$1.RSocketError = RSocketError;
7592
5767
  (function (ErrorCodes) {
7593
5768
  ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
7594
5769
  ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
@@ -7602,7 +5777,7 @@ function requireErrors () {
7602
5777
  ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
7603
5778
  ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
7604
5779
  ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
7605
- })(exports.ErrorCodes || (exports.ErrorCodes = {}));
5780
+ })(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
7606
5781
 
7607
5782
  } (Errors));
7608
5783
  return Errors;
@@ -7644,7 +5819,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
7644
5819
  function requireClientServerMultiplexerDemultiplexer () {
7645
5820
  if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
7646
5821
  hasRequiredClientServerMultiplexerDemultiplexer = 1;
7647
- (function (exports) {
5822
+ (function (exports$1) {
7648
5823
  /*
7649
5824
  * Copyright 2021-2022 the original author or authors.
7650
5825
  *
@@ -7711,8 +5886,8 @@ function requireClientServerMultiplexerDemultiplexer () {
7711
5886
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7712
5887
  }
7713
5888
  };
7714
- Object.defineProperty(exports, "__esModule", { value: true });
7715
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports.ResumableClientServerInputMultiplexerDemultiplexer = exports.ClientServerInputMultiplexerDemultiplexer = exports.StreamIdGenerator = void 0;
5889
+ Object.defineProperty(exports$1, "__esModule", { value: true });
5890
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports$1.ResumableClientServerInputMultiplexerDemultiplexer = exports$1.ClientServerInputMultiplexerDemultiplexer = exports$1.StreamIdGenerator = void 0;
7716
5891
  var _1 = requireDist();
7717
5892
  var Deferred_1 = requireDeferred();
7718
5893
  var Errors_1 = requireErrors();
@@ -7735,7 +5910,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7735
5910
  };
7736
5911
  return StreamIdGeneratorImpl;
7737
5912
  }());
7738
- })(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
5913
+ })(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
7739
5914
  var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7740
5915
  __extends(ClientServerInputMultiplexerDemultiplexer, _super);
7741
5916
  function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
@@ -7824,7 +5999,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7824
5999
  };
7825
6000
  return ClientServerInputMultiplexerDemultiplexer;
7826
6001
  }(Deferred_1.Deferred));
7827
- exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
6002
+ exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
7828
6003
  var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
7829
6004
  __extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
7830
6005
  function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
@@ -7981,7 +6156,7 @@ function requireClientServerMultiplexerDemultiplexer () {
7981
6156
  };
7982
6157
  return ResumableClientServerInputMultiplexerDemultiplexer;
7983
6158
  }(ClientServerInputMultiplexerDemultiplexer));
7984
- exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
6159
+ exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
7985
6160
  var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
7986
6161
  function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
7987
6162
  this.outbound = outbound;
@@ -8038,7 +6213,7 @@ function requireClientServerMultiplexerDemultiplexer () {
8038
6213
  };
8039
6214
  return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8040
6215
  }());
8041
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
6216
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
8042
6217
 
8043
6218
  } (ClientServerMultiplexerDemultiplexer));
8044
6219
  return ClientServerMultiplexerDemultiplexer;
@@ -11024,7 +9199,7 @@ var hasRequiredDist;
11024
9199
  function requireDist () {
11025
9200
  if (hasRequiredDist) return dist;
11026
9201
  hasRequiredDist = 1;
11027
- (function (exports) {
9202
+ (function (exports$1) {
11028
9203
  /*
11029
9204
  * Copyright 2021-2022 the original author or authors.
11030
9205
  *
@@ -11047,19 +9222,19 @@ function requireDist () {
11047
9222
  if (k2 === undefined) k2 = k;
11048
9223
  o[k2] = m[k];
11049
9224
  }));
11050
- var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
11051
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
9225
+ var __exportStar = (dist && dist.__exportStar) || function(m, exports$1) {
9226
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
11052
9227
  };
11053
- Object.defineProperty(exports, "__esModule", { value: true });
11054
- __exportStar(requireCodecs(), exports);
11055
- __exportStar(requireCommon(), exports);
11056
- __exportStar(requireDeferred(), exports);
11057
- __exportStar(requireErrors(), exports);
11058
- __exportStar(requireFrames(), exports);
11059
- __exportStar(requireRSocket(), exports);
11060
- __exportStar(requireRSocketConnector(), exports);
11061
- __exportStar(requireRSocketServer(), exports);
11062
- __exportStar(requireTransport(), exports);
9228
+ Object.defineProperty(exports$1, "__esModule", { value: true });
9229
+ __exportStar(requireCodecs(), exports$1);
9230
+ __exportStar(requireCommon(), exports$1);
9231
+ __exportStar(requireDeferred(), exports$1);
9232
+ __exportStar(requireErrors(), exports$1);
9233
+ __exportStar(requireFrames(), exports$1);
9234
+ __exportStar(requireRSocket(), exports$1);
9235
+ __exportStar(requireRSocketConnector(), exports$1);
9236
+ __exportStar(requireRSocketServer(), exports$1);
9237
+ __exportStar(requireTransport(), exports$1);
11063
9238
 
11064
9239
  } (dist));
11065
9240
  return dist;
@@ -11067,7 +9242,7 @@ function requireDist () {
11067
9242
 
11068
9243
  var distExports = requireDist();
11069
9244
 
11070
- var version = "1.43.1";
9245
+ var version = "1.45.0";
11071
9246
  var PACKAGE = {
11072
9247
  version: version};
11073
9248
 
@@ -11138,6 +9313,16 @@ class DataStream extends BaseObserver {
11138
9313
  * @returns a Data payload or Null if the stream closed.
11139
9314
  */
11140
9315
  async read() {
9316
+ if (this.closed) {
9317
+ return null;
9318
+ }
9319
+ // Wait for any pending processing to complete first.
9320
+ // This ensures we register our listener before calling processQueue(),
9321
+ // avoiding a race where processQueue() sees no reader and returns early.
9322
+ if (this.processingPromise) {
9323
+ await this.processingPromise;
9324
+ }
9325
+ // Re-check after await - stream may have closed while we were waiting
11141
9326
  if (this.closed) {
11142
9327
  return null;
11143
9328
  }
@@ -11177,7 +9362,7 @@ class DataStream extends BaseObserver {
11177
9362
  }
11178
9363
  const promise = (this.processingPromise = this._processQueue());
11179
9364
  promise.finally(() => {
11180
- return (this.processingPromise = null);
9365
+ this.processingPromise = null;
11181
9366
  });
11182
9367
  return promise;
11183
9368
  }
@@ -11209,7 +9394,6 @@ class DataStream extends BaseObserver {
11209
9394
  this.notifyDataAdded = null;
11210
9395
  }
11211
9396
  if (this.dataQueue.length > 0) {
11212
- // Next tick
11213
9397
  setTimeout(() => this.processQueue());
11214
9398
  }
11215
9399
  }
@@ -11589,7 +9773,7 @@ class AbstractRemote {
11589
9773
  else {
11590
9774
  contents = JSON.stringify(js);
11591
9775
  }
11592
- return bufferExports$1.Buffer.from(contents);
9776
+ return bufferExports.Buffer.from(contents);
11593
9777
  }
11594
9778
  const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;
11595
9779
  const request = await this.buildRequest(path);
@@ -11829,7 +10013,11 @@ class AbstractRemote {
11829
10013
  };
11830
10014
  const stream = new DataStream({
11831
10015
  logger: this.logger,
11832
- mapLine: mapLine
10016
+ mapLine: mapLine,
10017
+ pressure: {
10018
+ highWaterMark: 20,
10019
+ lowWaterMark: 10
10020
+ }
11833
10021
  });
11834
10022
  abortSignal?.addEventListener('abort', () => {
11835
10023
  closeReader();
@@ -11837,42 +10025,47 @@ class AbstractRemote {
11837
10025
  });
11838
10026
  const decoder = this.createTextDecoder();
11839
10027
  let buffer = '';
11840
- const l = stream.registerListener({
11841
- lowWater: async () => {
11842
- if (stream.closed || abortSignal?.aborted || readerReleased) {
10028
+ const consumeStream = async () => {
10029
+ while (!stream.closed && !abortSignal?.aborted && !readerReleased) {
10030
+ const { done, value } = await reader.read();
10031
+ if (done) {
10032
+ const remaining = buffer.trim();
10033
+ if (remaining.length != 0) {
10034
+ stream.enqueueData(remaining);
10035
+ }
10036
+ stream.close();
10037
+ await closeReader();
11843
10038
  return;
11844
10039
  }
11845
- try {
11846
- let didCompleteLine = false;
11847
- while (!didCompleteLine) {
11848
- const { done, value } = await reader.read();
11849
- if (done) {
11850
- const remaining = buffer.trim();
11851
- if (remaining.length != 0) {
11852
- stream.enqueueData(remaining);
11853
- }
11854
- stream.close();
11855
- await closeReader();
11856
- return;
11857
- }
11858
- const data = decoder.decode(value, { stream: true });
11859
- buffer += data;
11860
- const lines = buffer.split('\n');
11861
- for (var i = 0; i < lines.length - 1; i++) {
11862
- var l = lines[i].trim();
11863
- if (l.length > 0) {
11864
- stream.enqueueData(l);
11865
- didCompleteLine = true;
11866
- }
11867
- }
11868
- buffer = lines[lines.length - 1];
10040
+ const data = decoder.decode(value, { stream: true });
10041
+ buffer += data;
10042
+ const lines = buffer.split('\n');
10043
+ for (var i = 0; i < lines.length - 1; i++) {
10044
+ var l = lines[i].trim();
10045
+ if (l.length > 0) {
10046
+ stream.enqueueData(l);
11869
10047
  }
11870
10048
  }
11871
- catch (ex) {
11872
- stream.close();
11873
- throw ex;
10049
+ buffer = lines[lines.length - 1];
10050
+ // Implement backpressure by waiting for the low water mark to be reached
10051
+ if (stream.dataQueue.length > stream.highWatermark) {
10052
+ await new Promise((resolve) => {
10053
+ const dispose = stream.registerListener({
10054
+ lowWater: async () => {
10055
+ resolve();
10056
+ dispose();
10057
+ },
10058
+ closed: () => {
10059
+ resolve();
10060
+ dispose();
10061
+ }
10062
+ });
10063
+ });
11874
10064
  }
11875
- },
10065
+ }
10066
+ };
10067
+ consumeStream().catch(ex => this.logger.error('Error consuming stream', ex));
10068
+ const l = stream.registerListener({
11876
10069
  closed: () => {
11877
10070
  closeReader();
11878
10071
  l?.();
@@ -11994,6 +10187,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
11994
10187
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
11995
10188
  };
11996
10189
  const DEFAULT_STREAM_CONNECTION_OPTIONS = {
10190
+ appMetadata: {},
11997
10191
  connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
11998
10192
  clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
11999
10193
  fetchStrategy: FetchStrategy.Buffered,
@@ -12372,6 +10566,11 @@ The next upload iteration will be delayed.`);
12372
10566
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
12373
10567
  ...(options ?? {})
12374
10568
  };
10569
+ // Validate app metadata
10570
+ const invalidMetadata = Object.entries(resolvedOptions.appMetadata).filter(([_, value]) => typeof value != 'string');
10571
+ if (invalidMetadata.length > 0) {
10572
+ throw new Error(`Invalid appMetadata provided. Only string values are allowed. Invalid values: ${invalidMetadata.map(([key, value]) => `${key}: ${value}`).join(', ')}`);
10573
+ }
12375
10574
  const clientImplementation = resolvedOptions.clientImplementation;
12376
10575
  this.updateSyncStatus({ clientImplementation });
12377
10576
  if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
@@ -12407,6 +10606,7 @@ The next upload iteration will be delayed.`);
12407
10606
  include_checksum: true,
12408
10607
  raw_data: true,
12409
10608
  parameters: resolvedOptions.params,
10609
+ app_metadata: resolvedOptions.appMetadata,
12410
10610
  client_id: clientId
12411
10611
  }
12412
10612
  };
@@ -12766,6 +10966,7 @@ The next upload iteration will be delayed.`);
12766
10966
  try {
12767
10967
  const options = {
12768
10968
  parameters: resolvedOptions.params,
10969
+ app_metadata: resolvedOptions.appMetadata,
12769
10970
  active_streams: this.activeStreams,
12770
10971
  include_defaults: resolvedOptions.includeDefaultStreams
12771
10972
  };
@@ -13402,14 +11603,14 @@ class AbstractPowerSyncDatabase extends BaseObserver {
13402
11603
  async initialize() {
13403
11604
  await this._initialize();
13404
11605
  await this.bucketStorageAdapter.init();
13405
- await this._loadVersion();
11606
+ await this.loadVersion();
13406
11607
  await this.updateSchema(this.options.schema);
13407
11608
  await this.resolveOfflineSyncStatus();
13408
11609
  await this.database.execute('PRAGMA RECURSIVE_TRIGGERS=TRUE');
13409
11610
  this.ready = true;
13410
11611
  this.iterateListeners((cb) => cb.initialized?.());
13411
11612
  }
13412
- async _loadVersion() {
11613
+ async loadVersion() {
13413
11614
  try {
13414
11615
  const { version } = await this.database.get('SELECT powersync_rs_version() as version');
13415
11616
  this.sdkVersion = version;
@@ -14548,6 +12749,27 @@ class SyncDataBatch {
14548
12749
  }
14549
12750
  }
14550
12751
 
12752
+ /**
12753
+ * Thrown when an underlying database connection is closed.
12754
+ * This is particularly relevant when worker connections are marked as closed while
12755
+ * operations are still in progress.
12756
+ */
12757
+ class ConnectionClosedError extends Error {
12758
+ static NAME = 'ConnectionClosedError';
12759
+ static MATCHES(input) {
12760
+ /**
12761
+ * If there are weird package issues which cause multiple versions of classes to be present, the instanceof
12762
+ * check might fail. This also performs a failsafe check.
12763
+ * This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
12764
+ */
12765
+ return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
12766
+ }
12767
+ constructor(message) {
12768
+ super(message);
12769
+ this.name = ConnectionClosedError.NAME;
12770
+ }
12771
+ }
12772
+
14551
12773
  // https://www.sqlite.org/lang_expr.html#castexpr
14552
12774
  var ColumnType;
14553
12775
  (function (ColumnType) {
@@ -15102,5 +13324,5 @@ const parseQuery = (query, parameters) => {
15102
13324
  return { sqlStatement, parameters: parameters };
15103
13325
  };
15104
13326
 
15105
- export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, Table, TableV2, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
13327
+ export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RawTable, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, Table, TableV2, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
15106
13328
  //# sourceMappingURL=bundle.mjs.map