@automerge/automerge-repo-react-hooks 2.5.6 → 2.6.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1460,8 +1460,9 @@ function useDocHandle(id, { suspense } = { suspense: false }) {
1460
1460
  );
1461
1461
  if (id && !currentHandle) {
1462
1462
  const progress = repo.findWithProgress(id);
1463
- if (progress.state === "ready") {
1464
- currentHandle = progress.handle;
1463
+ const state = progress.peek();
1464
+ if (state.state === "ready") {
1465
+ currentHandle = state.handle;
1465
1466
  }
1466
1467
  }
1467
1468
  let wrapper = id ? wrapperCache.get(id) : void 0;
@@ -1555,8 +1556,9 @@ function useDocHandles(ids, { suspense = false } = {}) {
1555
1556
  } catch (e) {
1556
1557
  continue;
1557
1558
  }
1558
- if (progress.state === "ready") {
1559
- map.set(id, progress.handle);
1559
+ const state = progress.peek();
1560
+ if (state.state === "ready") {
1561
+ map.set(id, state.handle);
1560
1562
  }
1561
1563
  }
1562
1564
  return map;
@@ -3122,1589 +3124,831 @@ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }
3122
3124
  return t;
3123
3125
  };
3124
3126
 
3125
- var browser = {exports: {}};
3126
-
3127
- /**
3128
- * Helpers.
3129
- */
3130
-
3131
- var ms;
3132
- var hasRequiredMs;
3133
-
3134
- function requireMs () {
3135
- if (hasRequiredMs) return ms;
3136
- hasRequiredMs = 1;
3137
- var s = 1000;
3138
- var m = s * 60;
3139
- var h = m * 60;
3140
- var d = h * 24;
3141
- var w = d * 7;
3142
- var y = d * 365.25;
3143
-
3144
- /**
3145
- * Parse or format the given `val`.
3146
- *
3147
- * Options:
3148
- *
3149
- * - `long` verbose formatting [false]
3150
- *
3151
- * @param {String|Number} val
3152
- * @param {Object} [options]
3153
- * @throws {Error} throw an error if val is not a non-empty string or a number
3154
- * @return {String|Number}
3155
- * @api public
3156
- */
3127
+ let decoder;
3128
+ try {
3129
+ decoder = new TextDecoder();
3130
+ } catch(error) {}
3131
+ let src;
3132
+ let srcEnd;
3133
+ let position$1 = 0;
3134
+ const LEGACY_RECORD_INLINE_ID = 105;
3135
+ const RECORD_DEFINITIONS_ID = 0xdffe;
3136
+ const RECORD_INLINE_ID = 0xdfff; // temporary first-come first-serve tag // proposed tag: 0x7265 // 're'
3137
+ const BUNDLED_STRINGS_ID = 0xdff9;
3138
+ const PACKED_REFERENCE_TAG_ID = 6;
3139
+ const STOP_CODE = {};
3140
+ let maxArraySize = 112810000; // This is the maximum array size in V8. We would potentially detect and set it higher
3141
+ // for JSC, but this is pretty large and should be sufficient for most use cases
3142
+ let maxMapSize = 16810000; // JavaScript has a fixed maximum map size of about 16710000, but JS itself enforces this,
3143
+ let currentDecoder = {};
3144
+ let currentStructures;
3145
+ let srcString;
3146
+ let srcStringStart = 0;
3147
+ let srcStringEnd = 0;
3148
+ let bundledStrings$1;
3149
+ let referenceMap;
3150
+ let currentExtensions = [];
3151
+ let currentExtensionRanges = [];
3152
+ let packedValues;
3153
+ let dataView;
3154
+ let restoreMapsAsObject;
3155
+ let defaultOptions = {
3156
+ useRecords: false,
3157
+ mapsAsObjects: true
3158
+ };
3159
+ let sequentialMode = false;
3160
+ let inlineObjectReadThreshold = 2;
3161
+ // no-eval build
3162
+ try {
3163
+ new Function('');
3164
+ } catch(error) {
3165
+ // if eval variants are not supported, do not create inline object readers ever
3166
+ inlineObjectReadThreshold = Infinity;
3167
+ }
3157
3168
 
3158
- ms = function (val, options) {
3159
- options = options || {};
3160
- var type = typeof val;
3161
- if (type === 'string' && val.length > 0) {
3162
- return parse(val);
3163
- } else if (type === 'number' && isFinite(val)) {
3164
- return options.long ? fmtLong(val) : fmtShort(val);
3165
- }
3166
- throw new Error(
3167
- 'val is not a non-empty string or a valid number. val=' +
3168
- JSON.stringify(val)
3169
- );
3170
- };
3171
3169
 
3172
- /**
3173
- * Parse the given `str` and return milliseconds.
3174
- *
3175
- * @param {String} str
3176
- * @return {Number}
3177
- * @api private
3178
- */
3179
3170
 
3180
- function parse(str) {
3181
- str = String(str);
3182
- if (str.length > 100) {
3183
- return;
3184
- }
3185
- var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
3186
- str
3187
- );
3188
- if (!match) {
3189
- return;
3190
- }
3191
- var n = parseFloat(match[1]);
3192
- var type = (match[2] || 'ms').toLowerCase();
3193
- switch (type) {
3194
- case 'years':
3195
- case 'year':
3196
- case 'yrs':
3197
- case 'yr':
3198
- case 'y':
3199
- return n * y;
3200
- case 'weeks':
3201
- case 'week':
3202
- case 'w':
3203
- return n * w;
3204
- case 'days':
3205
- case 'day':
3206
- case 'd':
3207
- return n * d;
3208
- case 'hours':
3209
- case 'hour':
3210
- case 'hrs':
3211
- case 'hr':
3212
- case 'h':
3213
- return n * h;
3214
- case 'minutes':
3215
- case 'minute':
3216
- case 'mins':
3217
- case 'min':
3218
- case 'm':
3219
- return n * m;
3220
- case 'seconds':
3221
- case 'second':
3222
- case 'secs':
3223
- case 'sec':
3224
- case 's':
3225
- return n * s;
3226
- case 'milliseconds':
3227
- case 'millisecond':
3228
- case 'msecs':
3229
- case 'msec':
3230
- case 'ms':
3231
- return n;
3232
- default:
3233
- return undefined;
3234
- }
3171
+ class Decoder {
3172
+ constructor(options) {
3173
+ if (options) {
3174
+ if ((options.keyMap || options._keyMap) && !options.useRecords) {
3175
+ options.useRecords = false;
3176
+ options.mapsAsObjects = true;
3177
+ }
3178
+ if (options.useRecords === false && options.mapsAsObjects === undefined)
3179
+ options.mapsAsObjects = true;
3180
+ if (options.getStructures)
3181
+ options.getShared = options.getStructures;
3182
+ if (options.getShared && !options.structures)
3183
+ (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
3184
+ if (options.keyMap) {
3185
+ this.mapKey = new Map();
3186
+ for (let [k,v] of Object.entries(options.keyMap)) this.mapKey.set(v,k);
3187
+ }
3188
+ }
3189
+ Object.assign(this, options);
3235
3190
  }
3236
-
3237
- /**
3238
- * Short format for `ms`.
3239
- *
3240
- * @param {Number} ms
3241
- * @return {String}
3242
- * @api private
3243
- */
3244
-
3245
- function fmtShort(ms) {
3246
- var msAbs = Math.abs(ms);
3247
- if (msAbs >= d) {
3248
- return Math.round(ms / d) + 'd';
3249
- }
3250
- if (msAbs >= h) {
3251
- return Math.round(ms / h) + 'h';
3252
- }
3253
- if (msAbs >= m) {
3254
- return Math.round(ms / m) + 'm';
3255
- }
3256
- if (msAbs >= s) {
3257
- return Math.round(ms / s) + 's';
3258
- }
3259
- return ms + 'ms';
3191
+ /*
3192
+ decodeKey(key) {
3193
+ return this.keyMap
3194
+ ? Object.keys(this.keyMap)[Object.values(this.keyMap).indexOf(key)] || key
3195
+ : key
3260
3196
  }
3261
-
3262
- /**
3263
- * Long format for `ms`.
3264
- *
3265
- * @param {Number} ms
3266
- * @return {String}
3267
- * @api private
3268
- */
3269
-
3270
- function fmtLong(ms) {
3271
- var msAbs = Math.abs(ms);
3272
- if (msAbs >= d) {
3273
- return plural(ms, msAbs, d, 'day');
3274
- }
3275
- if (msAbs >= h) {
3276
- return plural(ms, msAbs, h, 'hour');
3277
- }
3278
- if (msAbs >= m) {
3279
- return plural(ms, msAbs, m, 'minute');
3280
- }
3281
- if (msAbs >= s) {
3282
- return plural(ms, msAbs, s, 'second');
3283
- }
3284
- return ms + ' ms';
3197
+ */
3198
+ decodeKey(key) {
3199
+ return this.keyMap ? this.mapKey.get(key) || key : key
3285
3200
  }
3286
-
3287
- /**
3288
- * Pluralization helper.
3289
- */
3290
-
3291
- function plural(ms, msAbs, n, name) {
3292
- var isPlural = msAbs >= n * 1.5;
3293
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
3201
+
3202
+ encodeKey(key) {
3203
+ return this.keyMap && this.keyMap.hasOwnProperty(key) ? this.keyMap[key] : key
3294
3204
  }
3295
- return ms;
3296
- }
3297
3205
 
3298
- var common;
3299
- var hasRequiredCommon;
3300
-
3301
- function requireCommon () {
3302
- if (hasRequiredCommon) return common;
3303
- hasRequiredCommon = 1;
3304
- /**
3305
- * This is the common logic for both the Node.js and web browser
3306
- * implementations of `debug()`.
3307
- */
3206
+ encodeKeys(rec) {
3207
+ if (!this._keyMap) return rec
3208
+ let map = new Map();
3209
+ for (let [k,v] of Object.entries(rec)) map.set((this._keyMap.hasOwnProperty(k) ? this._keyMap[k] : k), v);
3210
+ return map
3211
+ }
3308
3212
 
3309
- function setup(env) {
3310
- createDebug.debug = createDebug;
3311
- createDebug.default = createDebug;
3312
- createDebug.coerce = coerce;
3313
- createDebug.disable = disable;
3314
- createDebug.enable = enable;
3315
- createDebug.enabled = enabled;
3316
- createDebug.humanize = requireMs();
3317
- createDebug.destroy = destroy;
3318
-
3319
- Object.keys(env).forEach(key => {
3320
- createDebug[key] = env[key];
3321
- });
3322
-
3323
- /**
3324
- * The currently active debug mode names, and names to skip.
3325
- */
3326
-
3327
- createDebug.names = [];
3328
- createDebug.skips = [];
3329
-
3330
- /**
3331
- * Map of special "%n" handling functions, for the debug "format" argument.
3332
- *
3333
- * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
3334
- */
3335
- createDebug.formatters = {};
3336
-
3337
- /**
3338
- * Selects a color for a debug namespace
3339
- * @param {String} namespace The namespace string for the debug instance to be colored
3340
- * @return {Number|String} An ANSI color code for the given namespace
3341
- * @api private
3342
- */
3343
- function selectColor(namespace) {
3344
- let hash = 0;
3345
-
3346
- for (let i = 0; i < namespace.length; i++) {
3347
- hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
3348
- hash |= 0; // Convert to 32bit integer
3213
+ decodeKeys(map) {
3214
+ if (!this._keyMap || map.constructor.name != 'Map') return map
3215
+ if (!this._mapKey) {
3216
+ this._mapKey = new Map();
3217
+ for (let [k,v] of Object.entries(this._keyMap)) this._mapKey.set(v,k);
3218
+ }
3219
+ let res = {};
3220
+ //map.forEach((v,k) => res[Object.keys(this._keyMap)[Object.values(this._keyMap).indexOf(k)] || k] = v)
3221
+ map.forEach((v,k) => res[safeKey(this._mapKey.has(k) ? this._mapKey.get(k) : k)] = v);
3222
+ return res
3223
+ }
3224
+
3225
+ mapDecode(source, end) {
3226
+
3227
+ let res = this.decode(source);
3228
+ if (this._keyMap) {
3229
+ //Experiemntal support for Optimised KeyMap decoding
3230
+ switch (res.constructor.name) {
3231
+ case 'Array': return res.map(r => this.decodeKeys(r))
3232
+ //case 'Map': return this.decodeKeys(res)
3349
3233
  }
3350
-
3351
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
3352
3234
  }
3353
- createDebug.selectColor = selectColor;
3354
-
3355
- /**
3356
- * Create a debugger with the given `namespace`.
3357
- *
3358
- * @param {String} namespace
3359
- * @return {Function}
3360
- * @api public
3361
- */
3362
- function createDebug(namespace) {
3363
- let prevTime;
3364
- let enableOverride = null;
3365
- let namespacesCache;
3366
- let enabledCache;
3367
-
3368
- function debug(...args) {
3369
- // Disabled?
3370
- if (!debug.enabled) {
3371
- return;
3372
- }
3373
-
3374
- const self = debug;
3375
-
3376
- // Set `diff` timestamp
3377
- const curr = Number(new Date());
3378
- const ms = curr - (prevTime || curr);
3379
- self.diff = ms;
3380
- self.prev = prevTime;
3381
- self.curr = curr;
3382
- prevTime = curr;
3383
-
3384
- args[0] = createDebug.coerce(args[0]);
3235
+ return res
3236
+ }
3385
3237
 
3386
- if (typeof args[0] !== 'string') {
3387
- // Anything else let's inspect with %O
3388
- args.unshift('%O');
3238
+ decode(source, end) {
3239
+ if (src) {
3240
+ // re-entrant execution, save the state and restore it after we do this decode
3241
+ return saveState(() => {
3242
+ clearSource();
3243
+ return this ? this.decode(source, end) : Decoder.prototype.decode.call(defaultOptions, source, end)
3244
+ })
3245
+ }
3246
+ srcEnd = end > -1 ? end : source.length;
3247
+ position$1 = 0;
3248
+ srcStringEnd = 0;
3249
+ srcString = null;
3250
+ bundledStrings$1 = null;
3251
+ src = source;
3252
+ // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
3253
+ // technique for getting data from a database where it can be copied into an existing buffer instead of creating
3254
+ // new ones
3255
+ try {
3256
+ dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
3257
+ } catch(error) {
3258
+ // if it doesn't have a buffer, maybe it is the wrong type of object
3259
+ src = null;
3260
+ if (source instanceof Uint8Array)
3261
+ throw error
3262
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
3263
+ }
3264
+ if (this instanceof Decoder) {
3265
+ currentDecoder = this;
3266
+ packedValues = this.sharedValues &&
3267
+ (this.pack ? new Array(this.maxPrivatePackedValues || 16).concat(this.sharedValues) :
3268
+ this.sharedValues);
3269
+ if (this.structures) {
3270
+ currentStructures = this.structures;
3271
+ return checkedRead()
3272
+ } else if (!currentStructures || currentStructures.length > 0) {
3273
+ currentStructures = [];
3274
+ }
3275
+ } else {
3276
+ currentDecoder = defaultOptions;
3277
+ if (!currentStructures || currentStructures.length > 0)
3278
+ currentStructures = [];
3279
+ packedValues = null;
3280
+ }
3281
+ return checkedRead()
3282
+ }
3283
+ decodeMultiple(source, forEach) {
3284
+ let values, lastPosition = 0;
3285
+ try {
3286
+ let size = source.length;
3287
+ sequentialMode = true;
3288
+ let value = this ? this.decode(source, size) : defaultDecoder.decode(source, size);
3289
+ if (forEach) {
3290
+ if (forEach(value) === false) {
3291
+ return
3389
3292
  }
3390
-
3391
- // Apply any `formatters` transformations
3392
- let index = 0;
3393
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
3394
- // If we encounter an escaped % then don't increase the array index
3395
- if (match === '%%') {
3396
- return '%';
3397
- }
3398
- index++;
3399
- const formatter = createDebug.formatters[format];
3400
- if (typeof formatter === 'function') {
3401
- const val = args[index];
3402
- match = formatter.call(self, val);
3403
-
3404
- // Now we need to remove `args[index]` since it's inlined in the `format`
3405
- args.splice(index, 1);
3406
- index--;
3293
+ while(position$1 < size) {
3294
+ lastPosition = position$1;
3295
+ if (forEach(checkedRead()) === false) {
3296
+ return
3407
3297
  }
3408
- return match;
3409
- });
3410
-
3411
- // Apply env-specific formatting (colors, etc.)
3412
- createDebug.formatArgs.call(self, args);
3413
-
3414
- const logFn = self.log || createDebug.log;
3415
- logFn.apply(self, args);
3298
+ }
3416
3299
  }
3417
-
3418
- debug.namespace = namespace;
3419
- debug.useColors = createDebug.useColors();
3420
- debug.color = createDebug.selectColor(namespace);
3421
- debug.extend = extend;
3422
- debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
3423
-
3424
- Object.defineProperty(debug, 'enabled', {
3425
- enumerable: true,
3426
- configurable: false,
3427
- get: () => {
3428
- if (enableOverride !== null) {
3429
- return enableOverride;
3430
- }
3431
- if (namespacesCache !== createDebug.namespaces) {
3432
- namespacesCache = createDebug.namespaces;
3433
- enabledCache = createDebug.enabled(namespace);
3434
- }
3435
-
3436
- return enabledCache;
3437
- },
3438
- set: v => {
3439
- enableOverride = v;
3300
+ else {
3301
+ values = [ value ];
3302
+ while(position$1 < size) {
3303
+ lastPosition = position$1;
3304
+ values.push(checkedRead());
3440
3305
  }
3441
- });
3442
-
3443
- // Env-specific initialization logic for debug instances
3444
- if (typeof createDebug.init === 'function') {
3445
- createDebug.init(debug);
3306
+ return values
3446
3307
  }
3447
-
3448
- return debug;
3308
+ } catch(error) {
3309
+ error.lastPosition = lastPosition;
3310
+ error.values = values;
3311
+ throw error
3312
+ } finally {
3313
+ sequentialMode = false;
3314
+ clearSource();
3449
3315
  }
3450
-
3451
- function extend(namespace, delimiter) {
3452
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
3453
- newDebug.log = this.log;
3454
- return newDebug;
3316
+ }
3317
+ }
3318
+ function checkedRead() {
3319
+ try {
3320
+ let result = read();
3321
+ if (bundledStrings$1) {
3322
+ if (position$1 >= bundledStrings$1.postBundlePosition) {
3323
+ let error = new Error('Unexpected bundle position');
3324
+ error.incomplete = true;
3325
+ throw error
3326
+ }
3327
+ // bundled strings to skip past
3328
+ position$1 = bundledStrings$1.postBundlePosition;
3329
+ bundledStrings$1 = null;
3455
3330
  }
3456
3331
 
3457
- /**
3458
- * Enables a debug mode by namespaces. This can include modes
3459
- * separated by a colon and wildcards.
3460
- *
3461
- * @param {String} namespaces
3462
- * @api public
3463
- */
3464
- function enable(namespaces) {
3465
- createDebug.save(namespaces);
3466
- createDebug.namespaces = namespaces;
3467
-
3468
- createDebug.names = [];
3469
- createDebug.skips = [];
3470
-
3471
- const split = (typeof namespaces === 'string' ? namespaces : '')
3472
- .trim()
3473
- .replace(/\s+/g, ',')
3474
- .split(',')
3475
- .filter(Boolean);
3476
-
3477
- for (const ns of split) {
3478
- if (ns[0] === '-') {
3479
- createDebug.skips.push(ns.slice(1));
3480
- } else {
3481
- createDebug.names.push(ns);
3482
- }
3483
- }
3332
+ if (position$1 == srcEnd) {
3333
+ // finished reading this source, cleanup references
3334
+ currentStructures = null;
3335
+ src = null;
3336
+ if (referenceMap)
3337
+ referenceMap = null;
3338
+ } else if (position$1 > srcEnd) {
3339
+ // over read
3340
+ let error = new Error('Unexpected end of CBOR data');
3341
+ error.incomplete = true;
3342
+ throw error
3343
+ } else if (!sequentialMode) {
3344
+ throw new Error('Data read, but end of buffer not reached')
3484
3345
  }
3346
+ // else more to read, but we are reading sequentially, so don't clear source yet
3347
+ return result
3348
+ } catch(error) {
3349
+ clearSource();
3350
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
3351
+ error.incomplete = true;
3352
+ }
3353
+ throw error
3354
+ }
3355
+ }
3485
3356
 
3486
- /**
3487
- * Checks if the given string matches a namespace template, honoring
3488
- * asterisks as wildcards.
3489
- *
3490
- * @param {String} search
3491
- * @param {String} template
3492
- * @return {Boolean}
3493
- */
3494
- function matchesTemplate(search, template) {
3495
- let searchIndex = 0;
3496
- let templateIndex = 0;
3497
- let starIndex = -1;
3498
- let matchIndex = 0;
3499
-
3500
- while (searchIndex < search.length) {
3501
- if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
3502
- // Match character or proceed with wildcard
3503
- if (template[templateIndex] === '*') {
3504
- starIndex = templateIndex;
3505
- matchIndex = searchIndex;
3506
- templateIndex++; // Skip the '*'
3507
- } else {
3508
- searchIndex++;
3509
- templateIndex++;
3357
+ function read() {
3358
+ let token = src[position$1++];
3359
+ let majorType = token >> 5;
3360
+ token = token & 0x1f;
3361
+ if (token > 0x17) {
3362
+ switch (token) {
3363
+ case 0x18:
3364
+ token = src[position$1++];
3365
+ break
3366
+ case 0x19:
3367
+ if (majorType == 7) {
3368
+ return getFloat16()
3369
+ }
3370
+ token = dataView.getUint16(position$1);
3371
+ position$1 += 2;
3372
+ break
3373
+ case 0x1a:
3374
+ if (majorType == 7) {
3375
+ let value = dataView.getFloat32(position$1);
3376
+ if (currentDecoder.useFloat32 > 2) {
3377
+ // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
3378
+ let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
3379
+ position$1 += 4;
3380
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
3510
3381
  }
3511
- } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
3512
- // Backtrack to the last '*' and try to match more characters
3513
- templateIndex = starIndex + 1;
3514
- matchIndex++;
3515
- searchIndex = matchIndex;
3516
- } else {
3517
- return false; // No match
3382
+ position$1 += 4;
3383
+ return value
3518
3384
  }
3519
- }
3520
-
3521
- // Handle trailing '*' in template
3522
- while (templateIndex < template.length && template[templateIndex] === '*') {
3523
- templateIndex++;
3524
- }
3525
-
3526
- return templateIndex === template.length;
3527
- }
3528
-
3529
- /**
3530
- * Disable debug output.
3531
- *
3532
- * @return {String} namespaces
3533
- * @api public
3534
- */
3535
- function disable() {
3536
- const namespaces = [
3537
- ...createDebug.names,
3538
- ...createDebug.skips.map(namespace => '-' + namespace)
3539
- ].join(',');
3540
- createDebug.enable('');
3541
- return namespaces;
3542
- }
3543
-
3544
- /**
3545
- * Returns true if the given mode name is enabled, false otherwise.
3546
- *
3547
- * @param {String} name
3548
- * @return {Boolean}
3549
- * @api public
3550
- */
3551
- function enabled(name) {
3552
- for (const skip of createDebug.skips) {
3553
- if (matchesTemplate(name, skip)) {
3554
- return false;
3385
+ token = dataView.getUint32(position$1);
3386
+ position$1 += 4;
3387
+ break
3388
+ case 0x1b:
3389
+ if (majorType == 7) {
3390
+ let value = dataView.getFloat64(position$1);
3391
+ position$1 += 8;
3392
+ return value
3555
3393
  }
3556
- }
3557
-
3558
- for (const ns of createDebug.names) {
3559
- if (matchesTemplate(name, ns)) {
3560
- return true;
3394
+ if (majorType > 1) {
3395
+ if (dataView.getUint32(position$1) > 0)
3396
+ throw new Error('JavaScript does not support arrays, maps, or strings with length over 4294967295')
3397
+ token = dataView.getUint32(position$1 + 4);
3398
+ } else if (currentDecoder.int64AsNumber) {
3399
+ token = dataView.getUint32(position$1) * 0x100000000;
3400
+ token += dataView.getUint32(position$1 + 4);
3401
+ } else
3402
+ token = dataView.getBigUint64(position$1);
3403
+ position$1 += 8;
3404
+ break
3405
+ case 0x1f:
3406
+ // indefinite length
3407
+ switch(majorType) {
3408
+ case 2: // byte string
3409
+ case 3: // text string
3410
+ throw new Error('Indefinite length not supported for byte or text strings')
3411
+ case 4: // array
3412
+ let array = [];
3413
+ let value, i = 0;
3414
+ while ((value = read()) != STOP_CODE) {
3415
+ if (i >= maxArraySize) throw new Error(`Array length exceeds ${maxArraySize}`)
3416
+ array[i++] = value;
3417
+ }
3418
+ return majorType == 4 ? array : majorType == 3 ? array.join('') : Buffer.concat(array)
3419
+ case 5: // map
3420
+ let key;
3421
+ if (currentDecoder.mapsAsObjects) {
3422
+ let object = {};
3423
+ let i = 0;
3424
+ if (currentDecoder.keyMap) {
3425
+ while((key = read()) != STOP_CODE) {
3426
+ if (i++ >= maxMapSize) throw new Error(`Property count exceeds ${maxMapSize}`)
3427
+ object[safeKey(currentDecoder.decodeKey(key))] = read();
3428
+ }
3429
+ }
3430
+ else {
3431
+ while ((key = read()) != STOP_CODE) {
3432
+ if (i++ >= maxMapSize) throw new Error(`Property count exceeds ${maxMapSize}`)
3433
+ object[safeKey(key)] = read();
3434
+ }
3435
+ }
3436
+ return object
3437
+ } else {
3438
+ if (restoreMapsAsObject) {
3439
+ currentDecoder.mapsAsObjects = true;
3440
+ restoreMapsAsObject = false;
3441
+ }
3442
+ let map = new Map();
3443
+ if (currentDecoder.keyMap) {
3444
+ let i = 0;
3445
+ while((key = read()) != STOP_CODE) {
3446
+ if (i++ >= maxMapSize) {
3447
+ throw new Error(`Map size exceeds ${maxMapSize}`);
3448
+ }
3449
+ map.set(currentDecoder.decodeKey(key), read());
3450
+ }
3451
+ }
3452
+ else {
3453
+ let i = 0;
3454
+ while ((key = read()) != STOP_CODE) {
3455
+ if (i++ >= maxMapSize) {
3456
+ throw new Error(`Map size exceeds ${maxMapSize}`);
3457
+ }
3458
+ map.set(key, read());
3459
+ }
3460
+ }
3461
+ return map
3462
+ }
3463
+ case 7:
3464
+ return STOP_CODE
3465
+ default:
3466
+ throw new Error('Invalid major type for indefinite length ' + majorType)
3561
3467
  }
3562
- }
3563
-
3564
- return false;
3565
- }
3566
-
3567
- /**
3568
- * Coerce `val`.
3569
- *
3570
- * @param {Mixed} val
3571
- * @return {Mixed}
3572
- * @api private
3573
- */
3574
- function coerce(val) {
3575
- if (val instanceof Error) {
3576
- return val.stack || val.message;
3577
- }
3578
- return val;
3579
- }
3580
-
3581
- /**
3582
- * XXX DO NOT USE. This is a temporary stub function.
3583
- * XXX It WILL be removed in the next major release.
3584
- */
3585
- function destroy() {
3586
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
3468
+ default:
3469
+ throw new Error('Unknown token ' + token)
3587
3470
  }
3588
-
3589
- createDebug.enable(createDebug.load());
3590
-
3591
- return createDebug;
3592
3471
  }
3593
-
3594
- common = setup;
3595
- return common;
3596
- }
3597
-
3598
- /* eslint-env browser */
3599
-
3600
- var hasRequiredBrowser;
3601
-
3602
- function requireBrowser () {
3603
- if (hasRequiredBrowser) return browser.exports;
3604
- hasRequiredBrowser = 1;
3605
- (function (module, exports) {
3606
- /**
3607
- * This is the web browser implementation of `debug()`.
3608
- */
3609
-
3610
- exports.formatArgs = formatArgs;
3611
- exports.save = save;
3612
- exports.load = load;
3613
- exports.useColors = useColors;
3614
- exports.storage = localstorage();
3615
- exports.destroy = (() => {
3616
- let warned = false;
3617
-
3618
- return () => {
3619
- if (!warned) {
3620
- warned = true;
3621
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
3622
- }
3623
- };
3624
- })();
3625
-
3626
- /**
3627
- * Colors.
3628
- */
3629
-
3630
- exports.colors = [
3631
- '#0000CC',
3632
- '#0000FF',
3633
- '#0033CC',
3634
- '#0033FF',
3635
- '#0066CC',
3636
- '#0066FF',
3637
- '#0099CC',
3638
- '#0099FF',
3639
- '#00CC00',
3640
- '#00CC33',
3641
- '#00CC66',
3642
- '#00CC99',
3643
- '#00CCCC',
3644
- '#00CCFF',
3645
- '#3300CC',
3646
- '#3300FF',
3647
- '#3333CC',
3648
- '#3333FF',
3649
- '#3366CC',
3650
- '#3366FF',
3651
- '#3399CC',
3652
- '#3399FF',
3653
- '#33CC00',
3654
- '#33CC33',
3655
- '#33CC66',
3656
- '#33CC99',
3657
- '#33CCCC',
3658
- '#33CCFF',
3659
- '#6600CC',
3660
- '#6600FF',
3661
- '#6633CC',
3662
- '#6633FF',
3663
- '#66CC00',
3664
- '#66CC33',
3665
- '#9900CC',
3666
- '#9900FF',
3667
- '#9933CC',
3668
- '#9933FF',
3669
- '#99CC00',
3670
- '#99CC33',
3671
- '#CC0000',
3672
- '#CC0033',
3673
- '#CC0066',
3674
- '#CC0099',
3675
- '#CC00CC',
3676
- '#CC00FF',
3677
- '#CC3300',
3678
- '#CC3333',
3679
- '#CC3366',
3680
- '#CC3399',
3681
- '#CC33CC',
3682
- '#CC33FF',
3683
- '#CC6600',
3684
- '#CC6633',
3685
- '#CC9900',
3686
- '#CC9933',
3687
- '#CCCC00',
3688
- '#CCCC33',
3689
- '#FF0000',
3690
- '#FF0033',
3691
- '#FF0066',
3692
- '#FF0099',
3693
- '#FF00CC',
3694
- '#FF00FF',
3695
- '#FF3300',
3696
- '#FF3333',
3697
- '#FF3366',
3698
- '#FF3399',
3699
- '#FF33CC',
3700
- '#FF33FF',
3701
- '#FF6600',
3702
- '#FF6633',
3703
- '#FF9900',
3704
- '#FF9933',
3705
- '#FFCC00',
3706
- '#FFCC33'
3707
- ];
3708
-
3709
- /**
3710
- * Currently only WebKit-based Web Inspectors, Firefox >= v31,
3711
- * and the Firebug extension (any Firefox version) are known
3712
- * to support "%c" CSS customizations.
3713
- *
3714
- * TODO: add a `localStorage` variable to explicitly enable/disable colors
3715
- */
3716
-
3717
- // eslint-disable-next-line complexity
3718
- function useColors() {
3719
- // NB: In an Electron preload script, document will be defined but not fully
3720
- // initialized. Since we know we're in Chrome, we'll just detect this case
3721
- // explicitly
3722
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
3723
- return true;
3472
+ switch (majorType) {
3473
+ case 0: // positive int
3474
+ return token
3475
+ case 1: // negative int
3476
+ return ~token
3477
+ case 2: // buffer
3478
+ return readBin(token)
3479
+ case 3: // string
3480
+ if (srcStringEnd >= position$1) {
3481
+ return srcString.slice(position$1 - srcStringStart, (position$1 += token) - srcStringStart)
3724
3482
  }
3725
-
3726
- // Internet Explorer and Edge do not support colors.
3727
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
3728
- return false;
3483
+ if (srcStringEnd == 0 && srcEnd < 140 && token < 32) {
3484
+ // for small blocks, avoiding the overhead of the extract call is helpful
3485
+ let string = token < 16 ? shortStringInJS(token) : longStringInJS(token);
3486
+ if (string != null)
3487
+ return string
3729
3488
  }
3730
-
3731
- let m;
3732
-
3733
- // Is webkit? http://stackoverflow.com/a/16459606/376773
3734
- // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
3735
- // eslint-disable-next-line no-return-assign
3736
- return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
3737
- // Is firebug? http://stackoverflow.com/a/398120/376773
3738
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
3739
- // Is firefox >= v31?
3740
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
3741
- (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
3742
- // Double check webkit in userAgent just in case we are in a worker
3743
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
3744
- }
3745
-
3746
- /**
3747
- * Colorize log arguments if enabled.
3748
- *
3749
- * @api public
3750
- */
3751
-
3752
- function formatArgs(args) {
3753
- args[0] = (this.useColors ? '%c' : '') +
3754
- this.namespace +
3755
- (this.useColors ? ' %c' : ' ') +
3756
- args[0] +
3757
- (this.useColors ? '%c ' : ' ') +
3758
- '+' + module.exports.humanize(this.diff);
3759
-
3760
- if (!this.useColors) {
3761
- return;
3489
+ return readFixedString(token)
3490
+ case 4: // array
3491
+ if (token >= maxArraySize) throw new Error(`Array length exceeds ${maxArraySize}`)
3492
+ let array = new Array(token);
3493
+ //if (currentDecoder.keyMap) for (let i = 0; i < token; i++) array[i] = currentDecoder.decodeKey(read())
3494
+ //else
3495
+ for (let i = 0; i < token; i++) array[i] = read();
3496
+ return array
3497
+ case 5: // map
3498
+ if (token >= maxMapSize) throw new Error(`Map size exceeds ${maxArraySize}`)
3499
+ if (currentDecoder.mapsAsObjects) {
3500
+ let object = {};
3501
+ if (currentDecoder.keyMap) for (let i = 0; i < token; i++) object[safeKey(currentDecoder.decodeKey(read()))] = read();
3502
+ else for (let i = 0; i < token; i++) object[safeKey(read())] = read();
3503
+ return object
3504
+ } else {
3505
+ if (restoreMapsAsObject) {
3506
+ currentDecoder.mapsAsObjects = true;
3507
+ restoreMapsAsObject = false;
3508
+ }
3509
+ let map = new Map();
3510
+ if (currentDecoder.keyMap) for (let i = 0; i < token; i++) map.set(currentDecoder.decodeKey(read()),read());
3511
+ else for (let i = 0; i < token; i++) map.set(read(), read());
3512
+ return map
3762
3513
  }
3763
-
3764
- const c = 'color: ' + this.color;
3765
- args.splice(1, 0, c, 'color: inherit');
3766
-
3767
- // The final "%c" is somewhat tricky, because there could be other
3768
- // arguments passed either before or after the %c, so we need to
3769
- // figure out the correct index to insert the CSS into
3770
- let index = 0;
3771
- let lastC = 0;
3772
- args[0].replace(/%[a-zA-Z%]/g, match => {
3773
- if (match === '%%') {
3774
- return;
3514
+ case 6: // extension
3515
+ if (token >= BUNDLED_STRINGS_ID) {
3516
+ let structure = currentStructures[token & 0x1fff]; // check record structures first
3517
+ // At some point we may provide an option for dynamic tag assignment with a range like token >= 8 && (token < 16 || (token > 0x80 && token < 0xc0) || (token > 0x130 && token < 0x4000))
3518
+ if (structure) {
3519
+ if (!structure.read) structure.read = createStructureReader(structure);
3520
+ return structure.read()
3775
3521
  }
3776
- index++;
3777
- if (match === '%c') {
3778
- // We only are interested in the *last* %c
3779
- // (the user may have provided their own)
3780
- lastC = index;
3522
+ if (token < 0x10000) {
3523
+ if (token == RECORD_INLINE_ID) { // we do a special check for this so that we can keep the
3524
+ // currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
3525
+ let length = readJustLength();
3526
+ let id = read();
3527
+ let structure = read();
3528
+ recordDefinition(id, structure);
3529
+ let object = {};
3530
+ if (currentDecoder.keyMap) for (let i = 2; i < length; i++) {
3531
+ let key = currentDecoder.decodeKey(structure[i - 2]);
3532
+ object[safeKey(key)] = read();
3533
+ }
3534
+ else for (let i = 2; i < length; i++) {
3535
+ let key = structure[i - 2];
3536
+ object[safeKey(key)] = read();
3537
+ }
3538
+ return object
3539
+ }
3540
+ else if (token == RECORD_DEFINITIONS_ID) {
3541
+ let length = readJustLength();
3542
+ let id = read();
3543
+ for (let i = 2; i < length; i++) {
3544
+ recordDefinition(id++, read());
3545
+ }
3546
+ return read()
3547
+ } else if (token == BUNDLED_STRINGS_ID) {
3548
+ return readBundleExt()
3549
+ }
3550
+ if (currentDecoder.getShared) {
3551
+ loadShared();
3552
+ structure = currentStructures[token & 0x1fff];
3553
+ if (structure) {
3554
+ if (!structure.read)
3555
+ structure.read = createStructureReader(structure);
3556
+ return structure.read()
3557
+ }
3558
+ }
3781
3559
  }
3782
- });
3783
-
3784
- args.splice(lastC, 0, c);
3785
- }
3786
-
3787
- /**
3788
- * Invokes `console.debug()` when available.
3789
- * No-op when `console.debug` is not a "function".
3790
- * If `console.debug` is not available, falls back
3791
- * to `console.log`.
3792
- *
3793
- * @api public
3794
- */
3795
- exports.log = console.debug || console.log || (() => {});
3796
-
3797
- /**
3798
- * Save `namespaces`.
3799
- *
3800
- * @param {String} namespaces
3801
- * @api private
3802
- */
3803
- function save(namespaces) {
3804
- try {
3805
- if (namespaces) {
3806
- exports.storage.setItem('debug', namespaces);
3807
- } else {
3808
- exports.storage.removeItem('debug');
3560
+ }
3561
+ let extension = currentExtensions[token];
3562
+ if (extension) {
3563
+ if (extension.handlesRead)
3564
+ return extension(read)
3565
+ else
3566
+ return extension(read())
3567
+ } else {
3568
+ let input = read();
3569
+ for (let i = 0; i < currentExtensionRanges.length; i++) {
3570
+ let value = currentExtensionRanges[i](token, input);
3571
+ if (value !== undefined)
3572
+ return value
3809
3573
  }
3810
- } catch (error) {
3811
- // Swallow
3812
- // XXX (@Qix-) should we be logging these?
3574
+ return new Tag(input, token)
3813
3575
  }
3814
- }
3815
-
3816
- /**
3817
- * Load `namespaces`.
3818
- *
3819
- * @return {String} returns the previously persisted debug modes
3820
- * @api private
3821
- */
3822
- function load() {
3823
- let r;
3824
- try {
3825
- r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ;
3826
- } catch (error) {
3827
- // Swallow
3828
- // XXX (@Qix-) should we be logging these?
3576
+ case 7: // fixed value
3577
+ switch (token) {
3578
+ case 0x14: return false
3579
+ case 0x15: return true
3580
+ case 0x16: return null
3581
+ case 0x17: return; // undefined
3582
+ case 0x1f:
3583
+ default:
3584
+ let packedValue = (packedValues || getPackedValues())[token];
3585
+ if (packedValue !== undefined)
3586
+ return packedValue
3587
+ throw new Error('Unknown token ' + token)
3829
3588
  }
3830
-
3831
- // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
3832
- if (!r && typeof process !== 'undefined' && 'env' in process) {
3833
- r = process.env.DEBUG;
3589
+ default: // negative int
3590
+ if (isNaN(token)) {
3591
+ let error = new Error('Unexpected end of CBOR data');
3592
+ error.incomplete = true;
3593
+ throw error
3834
3594
  }
3835
-
3836
- return r;
3595
+ throw new Error('Unknown CBOR token ' + token)
3596
+ }
3597
+ }
3598
+ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
3599
+ function createStructureReader(structure) {
3600
+ if (!structure) throw new Error('Structure is required in record definition');
3601
+ function readObject() {
3602
+ // get the array size from the header
3603
+ let length = src[position$1++];
3604
+ //let majorType = token >> 5
3605
+ length = length & 0x1f;
3606
+ if (length > 0x17) {
3607
+ switch (length) {
3608
+ case 0x18:
3609
+ length = src[position$1++];
3610
+ break
3611
+ case 0x19:
3612
+ length = dataView.getUint16(position$1);
3613
+ position$1 += 2;
3614
+ break
3615
+ case 0x1a:
3616
+ length = dataView.getUint32(position$1);
3617
+ position$1 += 4;
3618
+ break
3619
+ default:
3620
+ throw new Error('Expected array header, but got ' + src[position$1 - 1])
3621
+ }
3622
+ }
3623
+ // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
3624
+ let compiledReader = this.compiledReader; // first look to see if we have the fast compiled function
3625
+ while(compiledReader) {
3626
+ // we have a fast compiled object literal reader
3627
+ if (compiledReader.propertyCount === length)
3628
+ return compiledReader(read) // with the right length, so we use it
3629
+ compiledReader = compiledReader.next; // see if there is another reader with the right length
3630
+ }
3631
+ if (this.slowReads++ >= inlineObjectReadThreshold) { // create a fast compiled reader
3632
+ let array = this.length == length ? this : this.slice(0, length);
3633
+ compiledReader = currentDecoder.keyMap
3634
+ ? new Function('r', 'return {' + array.map(k => currentDecoder.decodeKey(k)).map(k => validName.test(k) ? safeKey(k) + ':r()' : ('[' + JSON.stringify(k) + ']:r()')).join(',') + '}')
3635
+ : new Function('r', 'return {' + array.map(key => validName.test(key) ? safeKey(key) + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}');
3636
+ if (this.compiledReader)
3637
+ compiledReader.next = this.compiledReader; // if there is an existing one, we store multiple readers as a linked list because it is usually pretty rare to have multiple readers (of different length) for the same structure
3638
+ compiledReader.propertyCount = length;
3639
+ this.compiledReader = compiledReader;
3640
+ return compiledReader(read)
3837
3641
  }
3642
+ let object = {};
3643
+ if (currentDecoder.keyMap) for (let i = 0; i < length; i++) object[safeKey(currentDecoder.decodeKey(this[i]))] = read();
3644
+ else for (let i = 0; i < length; i++) {
3645
+ object[safeKey(this[i])] = read();
3646
+ }
3647
+ return object
3648
+ }
3649
+ structure.slowReads = 0;
3650
+ return readObject
3651
+ }
3838
3652
 
3839
- /**
3840
- * Localstorage attempts to return the localstorage.
3841
- *
3842
- * This is necessary because safari throws
3843
- * when a user disables cookies/localstorage
3844
- * and you attempt to access it.
3845
- *
3846
- * @return {LocalStorage}
3847
- * @api private
3848
- */
3653
+ function safeKey(key) {
3654
+ // protect against prototype pollution
3655
+ if (typeof key === 'string') return key === '__proto__' ? '__proto_' : key
3656
+ if (typeof key === 'number' || typeof key === 'boolean' || typeof key === 'bigint') return key.toString();
3657
+ if (key == null) return key + '';
3658
+ // protect against expensive (DoS) string conversions
3659
+ throw new Error('Invalid property name type ' + typeof key);
3660
+ }
3849
3661
 
3850
- function localstorage() {
3851
- try {
3852
- // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
3853
- // The Browser also has localStorage in the global context.
3854
- return localStorage;
3855
- } catch (error) {
3856
- // Swallow
3857
- // XXX (@Qix-) should we be logging these?
3662
+ let readFixedString = readStringJS;
3663
+ function readStringJS(length) {
3664
+ let result;
3665
+ if (length < 16) {
3666
+ if (result = shortStringInJS(length))
3667
+ return result
3668
+ }
3669
+ if (length > 64 && decoder)
3670
+ return decoder.decode(src.subarray(position$1, position$1 += length))
3671
+ const end = position$1 + length;
3672
+ const units = [];
3673
+ result = '';
3674
+ while (position$1 < end) {
3675
+ const byte1 = src[position$1++];
3676
+ if ((byte1 & 0x80) === 0) {
3677
+ // 1 byte
3678
+ units.push(byte1);
3679
+ } else if ((byte1 & 0xe0) === 0xc0) {
3680
+ // 2 bytes
3681
+ const byte2 = src[position$1++] & 0x3f;
3682
+ units.push(((byte1 & 0x1f) << 6) | byte2);
3683
+ } else if ((byte1 & 0xf0) === 0xe0) {
3684
+ // 3 bytes
3685
+ const byte2 = src[position$1++] & 0x3f;
3686
+ const byte3 = src[position$1++] & 0x3f;
3687
+ units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
3688
+ } else if ((byte1 & 0xf8) === 0xf0) {
3689
+ // 4 bytes
3690
+ const byte2 = src[position$1++] & 0x3f;
3691
+ const byte3 = src[position$1++] & 0x3f;
3692
+ const byte4 = src[position$1++] & 0x3f;
3693
+ let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
3694
+ if (unit > 0xffff) {
3695
+ unit -= 0x10000;
3696
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
3697
+ unit = 0xdc00 | (unit & 0x3ff);
3858
3698
  }
3699
+ units.push(unit);
3700
+ } else {
3701
+ units.push(byte1);
3859
3702
  }
3860
3703
 
3861
- module.exports = requireCommon()(exports);
3862
-
3863
- const {formatters} = module.exports;
3704
+ if (units.length >= 0x1000) {
3705
+ result += fromCharCode.apply(String, units);
3706
+ units.length = 0;
3707
+ }
3708
+ }
3864
3709
 
3865
- /**
3866
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
3867
- */
3710
+ if (units.length > 0) {
3711
+ result += fromCharCode.apply(String, units);
3712
+ }
3868
3713
 
3869
- formatters.j = function (v) {
3870
- try {
3871
- return JSON.stringify(v);
3872
- } catch (error) {
3873
- return '[UnexpectedJSONParseError]: ' + error.message;
3874
- }
3875
- };
3876
- } (browser, browser.exports));
3877
- return browser.exports;
3714
+ return result
3878
3715
  }
3879
-
3880
- var browserExports = requireBrowser();
3881
- const debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
3882
-
3883
- let decoder;
3884
- try {
3885
- decoder = new TextDecoder();
3886
- } catch(error) {}
3887
- let src;
3888
- let srcEnd;
3889
- let position$1 = 0;
3890
- const LEGACY_RECORD_INLINE_ID = 105;
3891
- const RECORD_DEFINITIONS_ID = 0xdffe;
3892
- const RECORD_INLINE_ID = 0xdfff; // temporary first-come first-serve tag // proposed tag: 0x7265 // 're'
3893
- const BUNDLED_STRINGS_ID = 0xdff9;
3894
- const PACKED_REFERENCE_TAG_ID = 6;
3895
- const STOP_CODE = {};
3896
- let maxArraySize = 112810000; // This is the maximum array size in V8. We would potentially detect and set it higher
3897
- // for JSC, but this is pretty large and should be sufficient for most use cases
3898
- let maxMapSize = 16810000; // JavaScript has a fixed maximum map size of about 16710000, but JS itself enforces this,
3899
- let currentDecoder = {};
3900
- let currentStructures;
3901
- let srcString;
3902
- let srcStringStart = 0;
3903
- let srcStringEnd = 0;
3904
- let bundledStrings$1;
3905
- let referenceMap;
3906
- let currentExtensions = [];
3907
- let currentExtensionRanges = [];
3908
- let packedValues;
3909
- let dataView;
3910
- let restoreMapsAsObject;
3911
- let defaultOptions = {
3912
- useRecords: false,
3913
- mapsAsObjects: true
3914
- };
3915
- let sequentialMode = false;
3916
- let inlineObjectReadThreshold = 2;
3917
- // no-eval build
3918
- try {
3919
- new Function('');
3920
- } catch(error) {
3921
- // if eval variants are not supported, do not create inline object readers ever
3922
- inlineObjectReadThreshold = Infinity;
3716
+ let fromCharCode = String.fromCharCode;
3717
+ function longStringInJS(length) {
3718
+ let start = position$1;
3719
+ let bytes = new Array(length);
3720
+ for (let i = 0; i < length; i++) {
3721
+ const byte = src[position$1++];
3722
+ if ((byte & 0x80) > 0) {
3723
+ position$1 = start;
3724
+ return
3725
+ }
3726
+ bytes[i] = byte;
3727
+ }
3728
+ return fromCharCode.apply(String, bytes)
3923
3729
  }
3924
-
3925
-
3926
-
3927
- class Decoder {
3928
- constructor(options) {
3929
- if (options) {
3930
- if ((options.keyMap || options._keyMap) && !options.useRecords) {
3931
- options.useRecords = false;
3932
- options.mapsAsObjects = true;
3730
+ function shortStringInJS(length) {
3731
+ if (length < 4) {
3732
+ if (length < 2) {
3733
+ if (length === 0)
3734
+ return ''
3735
+ else {
3736
+ let a = src[position$1++];
3737
+ if ((a & 0x80) > 1) {
3738
+ position$1 -= 1;
3739
+ return
3740
+ }
3741
+ return fromCharCode(a)
3933
3742
  }
3934
- if (options.useRecords === false && options.mapsAsObjects === undefined)
3935
- options.mapsAsObjects = true;
3936
- if (options.getStructures)
3937
- options.getShared = options.getStructures;
3938
- if (options.getShared && !options.structures)
3939
- (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
3940
- if (options.keyMap) {
3941
- this.mapKey = new Map();
3942
- for (let [k,v] of Object.entries(options.keyMap)) this.mapKey.set(v,k);
3743
+ } else {
3744
+ let a = src[position$1++];
3745
+ let b = src[position$1++];
3746
+ if ((a & 0x80) > 0 || (b & 0x80) > 0) {
3747
+ position$1 -= 2;
3748
+ return
3943
3749
  }
3944
- }
3945
- Object.assign(this, options);
3946
- }
3947
- /*
3948
- decodeKey(key) {
3949
- return this.keyMap
3950
- ? Object.keys(this.keyMap)[Object.values(this.keyMap).indexOf(key)] || key
3951
- : key
3952
- }
3953
- */
3954
- decodeKey(key) {
3955
- return this.keyMap ? this.mapKey.get(key) || key : key
3956
- }
3957
-
3958
- encodeKey(key) {
3959
- return this.keyMap && this.keyMap.hasOwnProperty(key) ? this.keyMap[key] : key
3960
- }
3961
-
3962
- encodeKeys(rec) {
3963
- if (!this._keyMap) return rec
3964
- let map = new Map();
3965
- for (let [k,v] of Object.entries(rec)) map.set((this._keyMap.hasOwnProperty(k) ? this._keyMap[k] : k), v);
3966
- return map
3967
- }
3968
-
3969
- decodeKeys(map) {
3970
- if (!this._keyMap || map.constructor.name != 'Map') return map
3971
- if (!this._mapKey) {
3972
- this._mapKey = new Map();
3973
- for (let [k,v] of Object.entries(this._keyMap)) this._mapKey.set(v,k);
3974
- }
3975
- let res = {};
3976
- //map.forEach((v,k) => res[Object.keys(this._keyMap)[Object.values(this._keyMap).indexOf(k)] || k] = v)
3977
- map.forEach((v,k) => res[safeKey(this._mapKey.has(k) ? this._mapKey.get(k) : k)] = v);
3978
- return res
3979
- }
3980
-
3981
- mapDecode(source, end) {
3982
-
3983
- let res = this.decode(source);
3984
- if (this._keyMap) {
3985
- //Experiemntal support for Optimised KeyMap decoding
3986
- switch (res.constructor.name) {
3987
- case 'Array': return res.map(r => this.decodeKeys(r))
3988
- //case 'Map': return this.decodeKeys(res)
3750
+ if (length < 3)
3751
+ return fromCharCode(a, b)
3752
+ let c = src[position$1++];
3753
+ if ((c & 0x80) > 0) {
3754
+ position$1 -= 3;
3755
+ return
3989
3756
  }
3757
+ return fromCharCode(a, b, c)
3990
3758
  }
3991
- return res
3992
- }
3993
-
3994
- decode(source, end) {
3995
- if (src) {
3996
- // re-entrant execution, save the state and restore it after we do this decode
3997
- return saveState(() => {
3998
- clearSource();
3999
- return this ? this.decode(source, end) : Decoder.prototype.decode.call(defaultOptions, source, end)
4000
- })
4001
- }
4002
- srcEnd = end > -1 ? end : source.length;
4003
- position$1 = 0;
4004
- srcStringEnd = 0;
4005
- srcString = null;
4006
- bundledStrings$1 = null;
4007
- src = source;
4008
- // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
4009
- // technique for getting data from a database where it can be copied into an existing buffer instead of creating
4010
- // new ones
4011
- try {
4012
- dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
4013
- } catch(error) {
4014
- // if it doesn't have a buffer, maybe it is the wrong type of object
4015
- src = null;
4016
- if (source instanceof Uint8Array)
4017
- throw error
4018
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
4019
- }
4020
- if (this instanceof Decoder) {
4021
- currentDecoder = this;
4022
- packedValues = this.sharedValues &&
4023
- (this.pack ? new Array(this.maxPrivatePackedValues || 16).concat(this.sharedValues) :
4024
- this.sharedValues);
4025
- if (this.structures) {
4026
- currentStructures = this.structures;
4027
- return checkedRead()
4028
- } else if (!currentStructures || currentStructures.length > 0) {
4029
- currentStructures = [];
4030
- }
4031
- } else {
4032
- currentDecoder = defaultOptions;
4033
- if (!currentStructures || currentStructures.length > 0)
4034
- currentStructures = [];
4035
- packedValues = null;
3759
+ } else {
3760
+ let a = src[position$1++];
3761
+ let b = src[position$1++];
3762
+ let c = src[position$1++];
3763
+ let d = src[position$1++];
3764
+ if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
3765
+ position$1 -= 4;
3766
+ return
4036
3767
  }
4037
- return checkedRead()
4038
- }
4039
- decodeMultiple(source, forEach) {
4040
- let values, lastPosition = 0;
4041
- try {
4042
- let size = source.length;
4043
- sequentialMode = true;
4044
- let value = this ? this.decode(source, size) : defaultDecoder.decode(source, size);
4045
- if (forEach) {
4046
- if (forEach(value) === false) {
3768
+ if (length < 6) {
3769
+ if (length === 4)
3770
+ return fromCharCode(a, b, c, d)
3771
+ else {
3772
+ let e = src[position$1++];
3773
+ if ((e & 0x80) > 0) {
3774
+ position$1 -= 5;
4047
3775
  return
4048
3776
  }
4049
- while(position$1 < size) {
4050
- lastPosition = position$1;
4051
- if (forEach(checkedRead()) === false) {
3777
+ return fromCharCode(a, b, c, d, e)
3778
+ }
3779
+ } else if (length < 8) {
3780
+ let e = src[position$1++];
3781
+ let f = src[position$1++];
3782
+ if ((e & 0x80) > 0 || (f & 0x80) > 0) {
3783
+ position$1 -= 6;
3784
+ return
3785
+ }
3786
+ if (length < 7)
3787
+ return fromCharCode(a, b, c, d, e, f)
3788
+ let g = src[position$1++];
3789
+ if ((g & 0x80) > 0) {
3790
+ position$1 -= 7;
3791
+ return
3792
+ }
3793
+ return fromCharCode(a, b, c, d, e, f, g)
3794
+ } else {
3795
+ let e = src[position$1++];
3796
+ let f = src[position$1++];
3797
+ let g = src[position$1++];
3798
+ let h = src[position$1++];
3799
+ if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
3800
+ position$1 -= 8;
3801
+ return
3802
+ }
3803
+ if (length < 10) {
3804
+ if (length === 8)
3805
+ return fromCharCode(a, b, c, d, e, f, g, h)
3806
+ else {
3807
+ let i = src[position$1++];
3808
+ if ((i & 0x80) > 0) {
3809
+ position$1 -= 9;
4052
3810
  return
4053
3811
  }
3812
+ return fromCharCode(a, b, c, d, e, f, g, h, i)
4054
3813
  }
4055
- }
4056
- else {
4057
- values = [ value ];
4058
- while(position$1 < size) {
4059
- lastPosition = position$1;
4060
- values.push(checkedRead());
3814
+ } else if (length < 12) {
3815
+ let i = src[position$1++];
3816
+ let j = src[position$1++];
3817
+ if ((i & 0x80) > 0 || (j & 0x80) > 0) {
3818
+ position$1 -= 10;
3819
+ return
4061
3820
  }
4062
- return values
4063
- }
4064
- } catch(error) {
4065
- error.lastPosition = lastPosition;
4066
- error.values = values;
4067
- throw error
4068
- } finally {
4069
- sequentialMode = false;
4070
- clearSource();
4071
- }
4072
- }
4073
- }
4074
- function checkedRead() {
4075
- try {
4076
- let result = read();
4077
- if (bundledStrings$1) {
4078
- if (position$1 >= bundledStrings$1.postBundlePosition) {
4079
- let error = new Error('Unexpected bundle position');
4080
- error.incomplete = true;
4081
- throw error
4082
- }
4083
- // bundled strings to skip past
4084
- position$1 = bundledStrings$1.postBundlePosition;
4085
- bundledStrings$1 = null;
4086
- }
4087
-
4088
- if (position$1 == srcEnd) {
4089
- // finished reading this source, cleanup references
4090
- currentStructures = null;
4091
- src = null;
4092
- if (referenceMap)
4093
- referenceMap = null;
4094
- } else if (position$1 > srcEnd) {
4095
- // over read
4096
- let error = new Error('Unexpected end of CBOR data');
4097
- error.incomplete = true;
4098
- throw error
4099
- } else if (!sequentialMode) {
4100
- throw new Error('Data read, but end of buffer not reached')
4101
- }
4102
- // else more to read, but we are reading sequentially, so don't clear source yet
4103
- return result
4104
- } catch(error) {
4105
- clearSource();
4106
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
4107
- error.incomplete = true;
4108
- }
4109
- throw error
4110
- }
4111
- }
4112
-
4113
- function read() {
4114
- let token = src[position$1++];
4115
- let majorType = token >> 5;
4116
- token = token & 0x1f;
4117
- if (token > 0x17) {
4118
- switch (token) {
4119
- case 0x18:
4120
- token = src[position$1++];
4121
- break
4122
- case 0x19:
4123
- if (majorType == 7) {
4124
- return getFloat16()
4125
- }
4126
- token = dataView.getUint16(position$1);
4127
- position$1 += 2;
4128
- break
4129
- case 0x1a:
4130
- if (majorType == 7) {
4131
- let value = dataView.getFloat32(position$1);
4132
- if (currentDecoder.useFloat32 > 2) {
4133
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
4134
- let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
4135
- position$1 += 4;
4136
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
4137
- }
4138
- position$1 += 4;
4139
- return value
4140
- }
4141
- token = dataView.getUint32(position$1);
4142
- position$1 += 4;
4143
- break
4144
- case 0x1b:
4145
- if (majorType == 7) {
4146
- let value = dataView.getFloat64(position$1);
4147
- position$1 += 8;
4148
- return value
4149
- }
4150
- if (majorType > 1) {
4151
- if (dataView.getUint32(position$1) > 0)
4152
- throw new Error('JavaScript does not support arrays, maps, or strings with length over 4294967295')
4153
- token = dataView.getUint32(position$1 + 4);
4154
- } else if (currentDecoder.int64AsNumber) {
4155
- token = dataView.getUint32(position$1) * 0x100000000;
4156
- token += dataView.getUint32(position$1 + 4);
4157
- } else
4158
- token = dataView.getBigUint64(position$1);
4159
- position$1 += 8;
4160
- break
4161
- case 0x1f:
4162
- // indefinite length
4163
- switch(majorType) {
4164
- case 2: // byte string
4165
- case 3: // text string
4166
- throw new Error('Indefinite length not supported for byte or text strings')
4167
- case 4: // array
4168
- let array = [];
4169
- let value, i = 0;
4170
- while ((value = read()) != STOP_CODE) {
4171
- if (i >= maxArraySize) throw new Error(`Array length exceeds ${maxArraySize}`)
4172
- array[i++] = value;
4173
- }
4174
- return majorType == 4 ? array : majorType == 3 ? array.join('') : Buffer.concat(array)
4175
- case 5: // map
4176
- let key;
4177
- if (currentDecoder.mapsAsObjects) {
4178
- let object = {};
4179
- let i = 0;
4180
- if (currentDecoder.keyMap) {
4181
- while((key = read()) != STOP_CODE) {
4182
- if (i++ >= maxMapSize) throw new Error(`Property count exceeds ${maxMapSize}`)
4183
- object[safeKey(currentDecoder.decodeKey(key))] = read();
4184
- }
4185
- }
4186
- else {
4187
- while ((key = read()) != STOP_CODE) {
4188
- if (i++ >= maxMapSize) throw new Error(`Property count exceeds ${maxMapSize}`)
4189
- object[safeKey(key)] = read();
4190
- }
4191
- }
4192
- return object
4193
- } else {
4194
- if (restoreMapsAsObject) {
4195
- currentDecoder.mapsAsObjects = true;
4196
- restoreMapsAsObject = false;
4197
- }
4198
- let map = new Map();
4199
- if (currentDecoder.keyMap) {
4200
- let i = 0;
4201
- while((key = read()) != STOP_CODE) {
4202
- if (i++ >= maxMapSize) {
4203
- throw new Error(`Map size exceeds ${maxMapSize}`);
4204
- }
4205
- map.set(currentDecoder.decodeKey(key), read());
4206
- }
4207
- }
4208
- else {
4209
- let i = 0;
4210
- while ((key = read()) != STOP_CODE) {
4211
- if (i++ >= maxMapSize) {
4212
- throw new Error(`Map size exceeds ${maxMapSize}`);
4213
- }
4214
- map.set(key, read());
4215
- }
4216
- }
4217
- return map
4218
- }
4219
- case 7:
4220
- return STOP_CODE
4221
- default:
4222
- throw new Error('Invalid major type for indefinite length ' + majorType)
3821
+ if (length < 11)
3822
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j)
3823
+ let k = src[position$1++];
3824
+ if ((k & 0x80) > 0) {
3825
+ position$1 -= 11;
3826
+ return
4223
3827
  }
4224
- default:
4225
- throw new Error('Unknown token ' + token)
4226
- }
4227
- }
4228
- switch (majorType) {
4229
- case 0: // positive int
4230
- return token
4231
- case 1: // negative int
4232
- return ~token
4233
- case 2: // buffer
4234
- return readBin(token)
4235
- case 3: // string
4236
- if (srcStringEnd >= position$1) {
4237
- return srcString.slice(position$1 - srcStringStart, (position$1 += token) - srcStringStart)
4238
- }
4239
- if (srcStringEnd == 0 && srcEnd < 140 && token < 32) {
4240
- // for small blocks, avoiding the overhead of the extract call is helpful
4241
- let string = token < 16 ? shortStringInJS(token) : longStringInJS(token);
4242
- if (string != null)
4243
- return string
4244
- }
4245
- return readFixedString(token)
4246
- case 4: // array
4247
- if (token >= maxArraySize) throw new Error(`Array length exceeds ${maxArraySize}`)
4248
- let array = new Array(token);
4249
- //if (currentDecoder.keyMap) for (let i = 0; i < token; i++) array[i] = currentDecoder.decodeKey(read())
4250
- //else
4251
- for (let i = 0; i < token; i++) array[i] = read();
4252
- return array
4253
- case 5: // map
4254
- if (token >= maxMapSize) throw new Error(`Map size exceeds ${maxArraySize}`)
4255
- if (currentDecoder.mapsAsObjects) {
4256
- let object = {};
4257
- if (currentDecoder.keyMap) for (let i = 0; i < token; i++) object[safeKey(currentDecoder.decodeKey(read()))] = read();
4258
- else for (let i = 0; i < token; i++) object[safeKey(read())] = read();
4259
- return object
3828
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
4260
3829
  } else {
4261
- if (restoreMapsAsObject) {
4262
- currentDecoder.mapsAsObjects = true;
4263
- restoreMapsAsObject = false;
4264
- }
4265
- let map = new Map();
4266
- if (currentDecoder.keyMap) for (let i = 0; i < token; i++) map.set(currentDecoder.decodeKey(read()),read());
4267
- else for (let i = 0; i < token; i++) map.set(read(), read());
4268
- return map
4269
- }
4270
- case 6: // extension
4271
- if (token >= BUNDLED_STRINGS_ID) {
4272
- let structure = currentStructures[token & 0x1fff]; // check record structures first
4273
- // At some point we may provide an option for dynamic tag assignment with a range like token >= 8 && (token < 16 || (token > 0x80 && token < 0xc0) || (token > 0x130 && token < 0x4000))
4274
- if (structure) {
4275
- if (!structure.read) structure.read = createStructureReader(structure);
4276
- return structure.read()
3830
+ let i = src[position$1++];
3831
+ let j = src[position$1++];
3832
+ let k = src[position$1++];
3833
+ let l = src[position$1++];
3834
+ if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
3835
+ position$1 -= 12;
3836
+ return
4277
3837
  }
4278
- if (token < 0x10000) {
4279
- if (token == RECORD_INLINE_ID) { // we do a special check for this so that we can keep the
4280
- // currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
4281
- let length = readJustLength();
4282
- let id = read();
4283
- let structure = read();
4284
- recordDefinition(id, structure);
4285
- let object = {};
4286
- if (currentDecoder.keyMap) for (let i = 2; i < length; i++) {
4287
- let key = currentDecoder.decodeKey(structure[i - 2]);
4288
- object[safeKey(key)] = read();
4289
- }
4290
- else for (let i = 2; i < length; i++) {
4291
- let key = structure[i - 2];
4292
- object[safeKey(key)] = read();
4293
- }
4294
- return object
4295
- }
4296
- else if (token == RECORD_DEFINITIONS_ID) {
4297
- let length = readJustLength();
4298
- let id = read();
4299
- for (let i = 2; i < length; i++) {
4300
- recordDefinition(id++, read());
3838
+ if (length < 14) {
3839
+ if (length === 12)
3840
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
3841
+ else {
3842
+ let m = src[position$1++];
3843
+ if ((m & 0x80) > 0) {
3844
+ position$1 -= 13;
3845
+ return
4301
3846
  }
4302
- return read()
4303
- } else if (token == BUNDLED_STRINGS_ID) {
4304
- return readBundleExt()
3847
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
4305
3848
  }
4306
- if (currentDecoder.getShared) {
4307
- loadShared();
4308
- structure = currentStructures[token & 0x1fff];
4309
- if (structure) {
4310
- if (!structure.read)
4311
- structure.read = createStructureReader(structure);
4312
- return structure.read()
4313
- }
3849
+ } else {
3850
+ let m = src[position$1++];
3851
+ let n = src[position$1++];
3852
+ if ((m & 0x80) > 0 || (n & 0x80) > 0) {
3853
+ position$1 -= 14;
3854
+ return
4314
3855
  }
3856
+ if (length < 15)
3857
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
3858
+ let o = src[position$1++];
3859
+ if ((o & 0x80) > 0) {
3860
+ position$1 -= 15;
3861
+ return
3862
+ }
3863
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
4315
3864
  }
4316
3865
  }
4317
- let extension = currentExtensions[token];
4318
- if (extension) {
4319
- if (extension.handlesRead)
4320
- return extension(read)
4321
- else
4322
- return extension(read())
4323
- } else {
4324
- let input = read();
4325
- for (let i = 0; i < currentExtensionRanges.length; i++) {
4326
- let value = currentExtensionRanges[i](token, input);
4327
- if (value !== undefined)
4328
- return value
4329
- }
4330
- return new Tag(input, token)
4331
- }
4332
- case 7: // fixed value
4333
- switch (token) {
4334
- case 0x14: return false
4335
- case 0x15: return true
4336
- case 0x16: return null
4337
- case 0x17: return; // undefined
4338
- case 0x1f:
4339
- default:
4340
- let packedValue = (packedValues || getPackedValues())[token];
4341
- if (packedValue !== undefined)
4342
- return packedValue
4343
- throw new Error('Unknown token ' + token)
4344
- }
4345
- default: // negative int
4346
- if (isNaN(token)) {
4347
- let error = new Error('Unexpected end of CBOR data');
4348
- error.incomplete = true;
4349
- throw error
4350
- }
4351
- throw new Error('Unknown CBOR token ' + token)
4352
- }
4353
- }
4354
- const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
4355
- function createStructureReader(structure) {
4356
- if (!structure) throw new Error('Structure is required in record definition');
4357
- function readObject() {
4358
- // get the array size from the header
4359
- let length = src[position$1++];
4360
- //let majorType = token >> 5
4361
- length = length & 0x1f;
4362
- if (length > 0x17) {
4363
- switch (length) {
4364
- case 0x18:
4365
- length = src[position$1++];
4366
- break
4367
- case 0x19:
4368
- length = dataView.getUint16(position$1);
4369
- position$1 += 2;
4370
- break
4371
- case 0x1a:
4372
- length = dataView.getUint32(position$1);
4373
- position$1 += 4;
4374
- break
4375
- default:
4376
- throw new Error('Expected array header, but got ' + src[position$1 - 1])
4377
- }
4378
- }
4379
- // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
4380
- let compiledReader = this.compiledReader; // first look to see if we have the fast compiled function
4381
- while(compiledReader) {
4382
- // we have a fast compiled object literal reader
4383
- if (compiledReader.propertyCount === length)
4384
- return compiledReader(read) // with the right length, so we use it
4385
- compiledReader = compiledReader.next; // see if there is another reader with the right length
4386
- }
4387
- if (this.slowReads++ >= inlineObjectReadThreshold) { // create a fast compiled reader
4388
- let array = this.length == length ? this : this.slice(0, length);
4389
- compiledReader = currentDecoder.keyMap
4390
- ? new Function('r', 'return {' + array.map(k => currentDecoder.decodeKey(k)).map(k => validName.test(k) ? safeKey(k) + ':r()' : ('[' + JSON.stringify(k) + ']:r()')).join(',') + '}')
4391
- : new Function('r', 'return {' + array.map(key => validName.test(key) ? safeKey(key) + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}');
4392
- if (this.compiledReader)
4393
- compiledReader.next = this.compiledReader; // if there is an existing one, we store multiple readers as a linked list because it is usually pretty rare to have multiple readers (of different length) for the same structure
4394
- compiledReader.propertyCount = length;
4395
- this.compiledReader = compiledReader;
4396
- return compiledReader(read)
4397
- }
4398
- let object = {};
4399
- if (currentDecoder.keyMap) for (let i = 0; i < length; i++) object[safeKey(currentDecoder.decodeKey(this[i]))] = read();
4400
- else for (let i = 0; i < length; i++) {
4401
- object[safeKey(this[i])] = read();
4402
3866
  }
4403
- return object
4404
3867
  }
4405
- structure.slowReads = 0;
4406
- return readObject
4407
3868
  }
4408
3869
 
4409
- function safeKey(key) {
4410
- // protect against prototype pollution
4411
- if (typeof key === 'string') return key === '__proto__' ? '__proto_' : key
4412
- if (typeof key === 'number' || typeof key === 'boolean' || typeof key === 'bigint') return key.toString();
4413
- if (key == null) return key + '';
4414
- // protect against expensive (DoS) string conversions
4415
- throw new Error('Invalid property name type ' + typeof key);
3870
+ function readBin(length) {
3871
+ return currentDecoder.copyBuffers ?
3872
+ // specifically use the copying slice (not the node one)
3873
+ Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
3874
+ src.subarray(position$1, position$1 += length)
4416
3875
  }
3876
+ let f32Array = new Float32Array(1);
3877
+ let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
3878
+ function getFloat16() {
3879
+ let byte0 = src[position$1++];
3880
+ let byte1 = src[position$1++];
3881
+ let exponent = (byte0 & 0x7f) >> 2;
3882
+ if (exponent === 0x1f) { // specials
3883
+ if (byte1 || (byte0 & 3))
3884
+ return NaN;
3885
+ return (byte0 & 0x80) ? -Infinity : Infinity;
3886
+ }
3887
+ if (exponent === 0) { // sub-normals
3888
+ // significand with 10 fractional bits and divided by 2^14
3889
+ let abs = (((byte0 & 3) << 8) | byte1) / (1 << 24);
3890
+ return (byte0 & 0x80) ? -abs : abs
3891
+ }
4417
3892
 
4418
- let readFixedString = readStringJS;
4419
- function readStringJS(length) {
4420
- let result;
4421
- if (length < 16) {
4422
- if (result = shortStringInJS(length))
4423
- return result
3893
+ u8Array[3] = (byte0 & 0x80) | // sign bit
3894
+ ((exponent >> 1) + 56); // 4 of 5 of the exponent bits, re-offset-ed
3895
+ u8Array[2] = ((byte0 & 7) << 5) | // last exponent bit and first two mantissa bits
3896
+ (byte1 >> 3); // next 5 bits of mantissa
3897
+ u8Array[1] = byte1 << 5; // last three bits of mantissa
3898
+ u8Array[0] = 0;
3899
+ return f32Array[0];
3900
+ }
3901
+
3902
+ new Array(4096);
3903
+
3904
+ class Tag {
3905
+ constructor(value, tag) {
3906
+ this.value = value;
3907
+ this.tag = tag;
4424
3908
  }
4425
- if (length > 64 && decoder)
4426
- return decoder.decode(src.subarray(position$1, position$1 += length))
4427
- const end = position$1 + length;
4428
- const units = [];
4429
- result = '';
4430
- while (position$1 < end) {
4431
- const byte1 = src[position$1++];
4432
- if ((byte1 & 0x80) === 0) {
4433
- // 1 byte
4434
- units.push(byte1);
4435
- } else if ((byte1 & 0xe0) === 0xc0) {
4436
- // 2 bytes
4437
- const byte2 = src[position$1++] & 0x3f;
4438
- units.push(((byte1 & 0x1f) << 6) | byte2);
4439
- } else if ((byte1 & 0xf0) === 0xe0) {
4440
- // 3 bytes
4441
- const byte2 = src[position$1++] & 0x3f;
4442
- const byte3 = src[position$1++] & 0x3f;
4443
- units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
4444
- } else if ((byte1 & 0xf8) === 0xf0) {
4445
- // 4 bytes
4446
- const byte2 = src[position$1++] & 0x3f;
4447
- const byte3 = src[position$1++] & 0x3f;
4448
- const byte4 = src[position$1++] & 0x3f;
4449
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
4450
- if (unit > 0xffff) {
4451
- unit -= 0x10000;
4452
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
4453
- unit = 0xdc00 | (unit & 0x3ff);
4454
- }
4455
- units.push(unit);
4456
- } else {
4457
- units.push(byte1);
4458
- }
3909
+ }
4459
3910
 
4460
- if (units.length >= 0x1000) {
4461
- result += fromCharCode.apply(String, units);
4462
- units.length = 0;
4463
- }
3911
+ currentExtensions[0] = (dateString) => {
3912
+ // string date extension
3913
+ return new Date(dateString)
3914
+ };
3915
+
3916
+ currentExtensions[1] = (epochSec) => {
3917
+ // numeric date extension
3918
+ return new Date(Math.round(epochSec * 1000))
3919
+ };
3920
+
3921
+ currentExtensions[2] = (buffer) => {
3922
+ // bigint extension
3923
+ let value = BigInt(0);
3924
+ for (let i = 0, l = buffer.byteLength; i < l; i++) {
3925
+ value = BigInt(buffer[i]) + (value << BigInt(8));
4464
3926
  }
3927
+ return value
3928
+ };
4465
3929
 
4466
- if (units.length > 0) {
4467
- result += fromCharCode.apply(String, units);
3930
+ currentExtensions[3] = (buffer) => {
3931
+ // negative bigint extension
3932
+ return BigInt(-1) - currentExtensions[2](buffer)
3933
+ };
3934
+ currentExtensions[4] = (fraction) => {
3935
+ // best to reparse to maintain accuracy
3936
+ return +(fraction[1] + 'e' + fraction[0])
3937
+ };
3938
+
3939
+ currentExtensions[5] = (fraction) => {
3940
+ // probably not sufficiently accurate
3941
+ return fraction[1] * Math.exp(fraction[0] * Math.log(2))
3942
+ };
3943
+
3944
+ // the registration of the record definition extension
3945
+ const recordDefinition = (id, structure) => {
3946
+ id = id - 0xe000;
3947
+ let existingStructure = currentStructures[id];
3948
+ if (existingStructure && existingStructure.isShared) {
3949
+ (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
4468
3950
  }
4469
-
4470
- return result
4471
- }
4472
- let fromCharCode = String.fromCharCode;
4473
- function longStringInJS(length) {
4474
- let start = position$1;
4475
- let bytes = new Array(length);
4476
- for (let i = 0; i < length; i++) {
4477
- const byte = src[position$1++];
4478
- if ((byte & 0x80) > 0) {
4479
- position$1 = start;
4480
- return
4481
- }
4482
- bytes[i] = byte;
4483
- }
4484
- return fromCharCode.apply(String, bytes)
4485
- }
4486
- function shortStringInJS(length) {
4487
- if (length < 4) {
4488
- if (length < 2) {
4489
- if (length === 0)
4490
- return ''
4491
- else {
4492
- let a = src[position$1++];
4493
- if ((a & 0x80) > 1) {
4494
- position$1 -= 1;
4495
- return
4496
- }
4497
- return fromCharCode(a)
4498
- }
4499
- } else {
4500
- let a = src[position$1++];
4501
- let b = src[position$1++];
4502
- if ((a & 0x80) > 0 || (b & 0x80) > 0) {
4503
- position$1 -= 2;
4504
- return
4505
- }
4506
- if (length < 3)
4507
- return fromCharCode(a, b)
4508
- let c = src[position$1++];
4509
- if ((c & 0x80) > 0) {
4510
- position$1 -= 3;
4511
- return
4512
- }
4513
- return fromCharCode(a, b, c)
4514
- }
4515
- } else {
4516
- let a = src[position$1++];
4517
- let b = src[position$1++];
4518
- let c = src[position$1++];
4519
- let d = src[position$1++];
4520
- if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
4521
- position$1 -= 4;
4522
- return
4523
- }
4524
- if (length < 6) {
4525
- if (length === 4)
4526
- return fromCharCode(a, b, c, d)
4527
- else {
4528
- let e = src[position$1++];
4529
- if ((e & 0x80) > 0) {
4530
- position$1 -= 5;
4531
- return
4532
- }
4533
- return fromCharCode(a, b, c, d, e)
4534
- }
4535
- } else if (length < 8) {
4536
- let e = src[position$1++];
4537
- let f = src[position$1++];
4538
- if ((e & 0x80) > 0 || (f & 0x80) > 0) {
4539
- position$1 -= 6;
4540
- return
4541
- }
4542
- if (length < 7)
4543
- return fromCharCode(a, b, c, d, e, f)
4544
- let g = src[position$1++];
4545
- if ((g & 0x80) > 0) {
4546
- position$1 -= 7;
4547
- return
4548
- }
4549
- return fromCharCode(a, b, c, d, e, f, g)
4550
- } else {
4551
- let e = src[position$1++];
4552
- let f = src[position$1++];
4553
- let g = src[position$1++];
4554
- let h = src[position$1++];
4555
- if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
4556
- position$1 -= 8;
4557
- return
4558
- }
4559
- if (length < 10) {
4560
- if (length === 8)
4561
- return fromCharCode(a, b, c, d, e, f, g, h)
4562
- else {
4563
- let i = src[position$1++];
4564
- if ((i & 0x80) > 0) {
4565
- position$1 -= 9;
4566
- return
4567
- }
4568
- return fromCharCode(a, b, c, d, e, f, g, h, i)
4569
- }
4570
- } else if (length < 12) {
4571
- let i = src[position$1++];
4572
- let j = src[position$1++];
4573
- if ((i & 0x80) > 0 || (j & 0x80) > 0) {
4574
- position$1 -= 10;
4575
- return
4576
- }
4577
- if (length < 11)
4578
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
4579
- let k = src[position$1++];
4580
- if ((k & 0x80) > 0) {
4581
- position$1 -= 11;
4582
- return
4583
- }
4584
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
4585
- } else {
4586
- let i = src[position$1++];
4587
- let j = src[position$1++];
4588
- let k = src[position$1++];
4589
- let l = src[position$1++];
4590
- if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
4591
- position$1 -= 12;
4592
- return
4593
- }
4594
- if (length < 14) {
4595
- if (length === 12)
4596
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
4597
- else {
4598
- let m = src[position$1++];
4599
- if ((m & 0x80) > 0) {
4600
- position$1 -= 13;
4601
- return
4602
- }
4603
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
4604
- }
4605
- } else {
4606
- let m = src[position$1++];
4607
- let n = src[position$1++];
4608
- if ((m & 0x80) > 0 || (n & 0x80) > 0) {
4609
- position$1 -= 14;
4610
- return
4611
- }
4612
- if (length < 15)
4613
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
4614
- let o = src[position$1++];
4615
- if ((o & 0x80) > 0) {
4616
- position$1 -= 15;
4617
- return
4618
- }
4619
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
4620
- }
4621
- }
4622
- }
4623
- }
4624
- }
4625
-
4626
- function readBin(length) {
4627
- return currentDecoder.copyBuffers ?
4628
- // specifically use the copying slice (not the node one)
4629
- Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
4630
- src.subarray(position$1, position$1 += length)
4631
- }
4632
- let f32Array = new Float32Array(1);
4633
- let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
4634
- function getFloat16() {
4635
- let byte0 = src[position$1++];
4636
- let byte1 = src[position$1++];
4637
- let exponent = (byte0 & 0x7f) >> 2;
4638
- if (exponent === 0x1f) { // specials
4639
- if (byte1 || (byte0 & 3))
4640
- return NaN;
4641
- return (byte0 & 0x80) ? -Infinity : Infinity;
4642
- }
4643
- if (exponent === 0) { // sub-normals
4644
- // significand with 10 fractional bits and divided by 2^14
4645
- let abs = (((byte0 & 3) << 8) | byte1) / (1 << 24);
4646
- return (byte0 & 0x80) ? -abs : abs
4647
- }
4648
-
4649
- u8Array[3] = (byte0 & 0x80) | // sign bit
4650
- ((exponent >> 1) + 56); // 4 of 5 of the exponent bits, re-offset-ed
4651
- u8Array[2] = ((byte0 & 7) << 5) | // last exponent bit and first two mantissa bits
4652
- (byte1 >> 3); // next 5 bits of mantissa
4653
- u8Array[1] = byte1 << 5; // last three bits of mantissa
4654
- u8Array[0] = 0;
4655
- return f32Array[0];
4656
- }
4657
-
4658
- new Array(4096);
4659
-
4660
- class Tag {
4661
- constructor(value, tag) {
4662
- this.value = value;
4663
- this.tag = tag;
4664
- }
4665
- }
4666
-
4667
- currentExtensions[0] = (dateString) => {
4668
- // string date extension
4669
- return new Date(dateString)
4670
- };
4671
-
4672
- currentExtensions[1] = (epochSec) => {
4673
- // numeric date extension
4674
- return new Date(Math.round(epochSec * 1000))
4675
- };
4676
-
4677
- currentExtensions[2] = (buffer) => {
4678
- // bigint extension
4679
- let value = BigInt(0);
4680
- for (let i = 0, l = buffer.byteLength; i < l; i++) {
4681
- value = BigInt(buffer[i]) + (value << BigInt(8));
4682
- }
4683
- return value
4684
- };
4685
-
4686
- currentExtensions[3] = (buffer) => {
4687
- // negative bigint extension
4688
- return BigInt(-1) - currentExtensions[2](buffer)
4689
- };
4690
- currentExtensions[4] = (fraction) => {
4691
- // best to reparse to maintain accuracy
4692
- return +(fraction[1] + 'e' + fraction[0])
4693
- };
4694
-
4695
- currentExtensions[5] = (fraction) => {
4696
- // probably not sufficiently accurate
4697
- return fraction[1] * Math.exp(fraction[0] * Math.log(2))
4698
- };
4699
-
4700
- // the registration of the record definition extension
4701
- const recordDefinition = (id, structure) => {
4702
- id = id - 0xe000;
4703
- let existingStructure = currentStructures[id];
4704
- if (existingStructure && existingStructure.isShared) {
4705
- (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
4706
- }
4707
- currentStructures[id] = structure;
3951
+ currentStructures[id] = structure;
4708
3952
 
4709
3953
  structure.read = createStructureReader(structure);
4710
3954
  };
@@ -5677,569 +4921,1327 @@ class Encoder extends Decoder {
5677
4921
  encode(object[key]);
5678
4922
  size++;
5679
4923
  }
5680
- } else {
5681
- for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
5682
- encode(key);
5683
- encode(object[key]);
5684
- size++;
4924
+ } else {
4925
+ for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
4926
+ encode(key);
4927
+ encode(object[key]);
4928
+ size++;
4929
+ }
4930
+ }
4931
+ target[objectOffset++ + start] = size >> 8;
4932
+ target[objectOffset + start] = size & 0xff;
4933
+ } :
4934
+ (object, skipValues) => {
4935
+ let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
4936
+ let newTransitions = 0;
4937
+ let length = 0;
4938
+ let parentRecordId;
4939
+ let keys;
4940
+ if (this.keyMap) {
4941
+ keys = Object.keys(object).map(k => this.encodeKey(k));
4942
+ length = keys.length;
4943
+ for (let i = 0; i < length; i++) {
4944
+ let key = keys[i];
4945
+ nextTransition = transition[key];
4946
+ if (!nextTransition) {
4947
+ nextTransition = transition[key] = Object.create(null);
4948
+ newTransitions++;
4949
+ }
4950
+ transition = nextTransition;
4951
+ }
4952
+ } else {
4953
+ for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
4954
+ nextTransition = transition[key];
4955
+ if (!nextTransition) {
4956
+ if (transition[RECORD_SYMBOL] & 0x100000) {// this indicates it is a brancheable/extendable terminal node, so we will use this record id and extend it
4957
+ parentRecordId = transition[RECORD_SYMBOL] & 0xffff;
4958
+ }
4959
+ nextTransition = transition[key] = Object.create(null);
4960
+ newTransitions++;
4961
+ }
4962
+ transition = nextTransition;
4963
+ length++;
4964
+ }
4965
+ }
4966
+ let recordId = transition[RECORD_SYMBOL];
4967
+ if (recordId !== undefined) {
4968
+ recordId &= 0xffff;
4969
+ target[position++] = 0xd9;
4970
+ target[position++] = (recordId >> 8) | 0xe0;
4971
+ target[position++] = recordId & 0xff;
4972
+ } else {
4973
+ if (!keys)
4974
+ keys = transition.__keys__ || (transition.__keys__ = Object.keys(object));
4975
+ if (parentRecordId === undefined) {
4976
+ recordId = structures.nextId++;
4977
+ if (!recordId) {
4978
+ recordId = 0;
4979
+ structures.nextId = 1;
4980
+ }
4981
+ if (recordId >= MAX_STRUCTURES) {// cycle back around
4982
+ structures.nextId = (recordId = maxSharedStructures) + 1;
4983
+ }
4984
+ } else {
4985
+ recordId = parentRecordId;
4986
+ }
4987
+ structures[recordId] = keys;
4988
+ if (recordId < maxSharedStructures) {
4989
+ target[position++] = 0xd9;
4990
+ target[position++] = (recordId >> 8) | 0xe0;
4991
+ target[position++] = recordId & 0xff;
4992
+ transition = structures.transitions;
4993
+ for (let i = 0; i < length; i++) {
4994
+ if (transition[RECORD_SYMBOL] === undefined || (transition[RECORD_SYMBOL] & 0x100000))
4995
+ transition[RECORD_SYMBOL] = recordId;
4996
+ transition = transition[keys[i]];
4997
+ }
4998
+ transition[RECORD_SYMBOL] = recordId | 0x100000; // indicates it is a extendable terminal
4999
+ hasSharedUpdate = true;
5000
+ } else {
5001
+ transition[RECORD_SYMBOL] = recordId;
5002
+ targetView.setUint32(position, 0xd9dfff00); // tag two byte, then record definition id
5003
+ position += 3;
5004
+ if (newTransitions)
5005
+ transitionsCount += serializationsSinceTransitionRebuild * newTransitions;
5006
+ // record the removal of the id, we can maintain our shared structure
5007
+ if (recordIdsToRemove.length >= MAX_STRUCTURES - maxSharedStructures)
5008
+ recordIdsToRemove.shift()[RECORD_SYMBOL] = undefined; // we are cycling back through, and have to remove old ones
5009
+ recordIdsToRemove.push(transition);
5010
+ writeArrayHeader(length + 2);
5011
+ encode(0xe000 + recordId);
5012
+ encode(keys);
5013
+ if (skipValues) return; // special exit for iterator
5014
+ for (let key in object)
5015
+ if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
5016
+ encode(object[key]);
5017
+ return
5018
+ }
5019
+ }
5020
+ if (length < 0x18) { // write the array header
5021
+ target[position++] = 0x80 | length;
5022
+ } else {
5023
+ writeArrayHeader(length);
5024
+ }
5025
+ if (skipValues) return; // special exit for iterator
5026
+ for (let key in object)
5027
+ if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
5028
+ encode(object[key]);
5029
+ };
5030
+ const makeRoom = (end) => {
5031
+ let newSize;
5032
+ if (end > 0x1000000) {
5033
+ // special handling for really large buffers
5034
+ if ((end - start) > MAX_BUFFER_SIZE)
5035
+ throw new Error('Encoded buffer would be larger than maximum buffer size')
5036
+ newSize = Math.min(MAX_BUFFER_SIZE,
5037
+ Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
5038
+ } else // faster handling for smaller buffers
5039
+ newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
5040
+ let newBuffer = new ByteArrayAllocate(newSize);
5041
+ targetView = new DataView(newBuffer.buffer, 0, newSize);
5042
+ if (target.copy)
5043
+ target.copy(newBuffer, 0, start, end);
5044
+ else
5045
+ newBuffer.set(target.slice(start, end));
5046
+ position -= start;
5047
+ start = 0;
5048
+ safeEnd = newBuffer.length - 10;
5049
+ return target = newBuffer
5050
+ };
5051
+ let chunkThreshold = 100;
5052
+ let continuedChunkThreshold = 1000;
5053
+ this.encodeAsIterable = function(value, options) {
5054
+ return startEncoding(value, options, encodeObjectAsIterable);
5055
+ };
5056
+ this.encodeAsAsyncIterable = function(value, options) {
5057
+ return startEncoding(value, options, encodeObjectAsAsyncIterable);
5058
+ };
5059
+
5060
+ function* encodeObjectAsIterable(object, iterateProperties, finalIterable) {
5061
+ let constructor = object.constructor;
5062
+ if (constructor === Object) {
5063
+ let useRecords = encoder.useRecords !== false;
5064
+ if (useRecords)
5065
+ writeObject(object, true); // write the record identifier
5066
+ else
5067
+ writeEntityLength(Object.keys(object).length, 0xa0);
5068
+ for (let key in object) {
5069
+ let value = object[key];
5070
+ if (!useRecords) encode(key);
5071
+ if (value && typeof value === 'object') {
5072
+ if (iterateProperties[key])
5073
+ yield* encodeObjectAsIterable(value, iterateProperties[key]);
5074
+ else
5075
+ yield* tryEncode(value, iterateProperties, key);
5076
+ } else encode(value);
5077
+ }
5078
+ } else if (constructor === Array) {
5079
+ let length = object.length;
5080
+ writeArrayHeader(length);
5081
+ for (let i = 0; i < length; i++) {
5082
+ let value = object[i];
5083
+ if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
5084
+ if (iterateProperties.element)
5085
+ yield* encodeObjectAsIterable(value, iterateProperties.element);
5086
+ else
5087
+ yield* tryEncode(value, iterateProperties, 'element');
5088
+ } else encode(value);
5089
+ }
5090
+ } else if (object[Symbol.iterator] && !object.buffer) { // iterator, but exclude typed arrays
5091
+ target[position++] = 0x9f; // start indefinite array
5092
+ for (let value of object) {
5093
+ if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
5094
+ if (iterateProperties.element)
5095
+ yield* encodeObjectAsIterable(value, iterateProperties.element);
5096
+ else
5097
+ yield* tryEncode(value, iterateProperties, 'element');
5098
+ } else encode(value);
5099
+ }
5100
+ target[position++] = 0xff; // stop byte
5101
+ } else if (isBlob(object)){
5102
+ writeEntityLength(object.size, 0x40); // encode as binary data
5103
+ yield target.subarray(start, position);
5104
+ yield object; // directly return blobs, they have to be encoded asynchronously
5105
+ restartEncoding();
5106
+ } else if (object[Symbol.asyncIterator]) {
5107
+ target[position++] = 0x9f; // start indefinite array
5108
+ yield target.subarray(start, position);
5109
+ yield object; // directly return async iterators, they have to be encoded asynchronously
5110
+ restartEncoding();
5111
+ target[position++] = 0xff; // stop byte
5112
+ } else {
5113
+ encode(object);
5114
+ }
5115
+ if (finalIterable && position > start) yield target.subarray(start, position);
5116
+ else if (position - start > chunkThreshold) {
5117
+ yield target.subarray(start, position);
5118
+ restartEncoding();
5119
+ }
5120
+ }
5121
+ function* tryEncode(value, iterateProperties, key) {
5122
+ let restart = position - start;
5123
+ try {
5124
+ encode(value);
5125
+ if (position - start > chunkThreshold) {
5126
+ yield target.subarray(start, position);
5127
+ restartEncoding();
5128
+ }
5129
+ } catch (error) {
5130
+ if (error.iteratorNotHandled) {
5131
+ iterateProperties[key] = {};
5132
+ position = start + restart; // restart our position so we don't have partial data from last encode
5133
+ yield* encodeObjectAsIterable.call(this, value, iterateProperties[key]);
5134
+ } else throw error;
5135
+ }
5136
+ }
5137
+ function restartEncoding() {
5138
+ chunkThreshold = continuedChunkThreshold;
5139
+ encoder.encode(null, THROW_ON_ITERABLE); // restart encoding
5140
+ }
5141
+ function startEncoding(value, options, encodeIterable) {
5142
+ if (options && options.chunkThreshold) // explicitly specified chunk sizes
5143
+ chunkThreshold = continuedChunkThreshold = options.chunkThreshold;
5144
+ else // we start with a smaller threshold to get initial bytes sent quickly
5145
+ chunkThreshold = 100;
5146
+ if (value && typeof value === 'object') {
5147
+ encoder.encode(null, THROW_ON_ITERABLE); // start encoding
5148
+ return encodeIterable(value, encoder.iterateProperties || (encoder.iterateProperties = {}), true);
5149
+ }
5150
+ return [encoder.encode(value)];
5151
+ }
5152
+
5153
+ async function* encodeObjectAsAsyncIterable(value, iterateProperties) {
5154
+ for (let encodedValue of encodeObjectAsIterable(value, iterateProperties, true)) {
5155
+ let constructor = encodedValue.constructor;
5156
+ if (constructor === ByteArray || constructor === Uint8Array)
5157
+ yield encodedValue;
5158
+ else if (isBlob(encodedValue)) {
5159
+ let reader = encodedValue.stream().getReader();
5160
+ let next;
5161
+ while (!(next = await reader.read()).done) {
5162
+ yield next.value;
5163
+ }
5164
+ } else if (encodedValue[Symbol.asyncIterator]) {
5165
+ for await (let asyncValue of encodedValue) {
5166
+ restartEncoding();
5167
+ if (asyncValue)
5168
+ yield* encodeObjectAsAsyncIterable(asyncValue, iterateProperties.async || (iterateProperties.async = {}));
5169
+ else yield encoder.encode(asyncValue);
5170
+ }
5171
+ } else {
5172
+ yield encodedValue;
5173
+ }
5174
+ }
5175
+ }
5176
+ }
5177
+ useBuffer(buffer) {
5178
+ // this means we are finished using our own buffer and we can write over it safely
5179
+ target = buffer;
5180
+ targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
5181
+ position = 0;
5182
+ }
5183
+ clearSharedData() {
5184
+ if (this.structures)
5185
+ this.structures = [];
5186
+ if (this.sharedValues)
5187
+ this.sharedValues = undefined;
5188
+ }
5189
+ updateSharedData() {
5190
+ let lastVersion = this.sharedVersion || 0;
5191
+ this.sharedVersion = lastVersion + 1;
5192
+ let structuresCopy = this.structures.slice(0);
5193
+ let sharedData = new SharedData(structuresCopy, this.sharedValues, this.sharedVersion);
5194
+ let saveResults = this.saveShared(sharedData,
5195
+ existingShared => (existingShared && existingShared.version || 0) == lastVersion);
5196
+ if (saveResults === false) {
5197
+ // get updated structures and try again if the update failed
5198
+ sharedData = this.getShared() || {};
5199
+ this.structures = sharedData.structures || [];
5200
+ this.sharedValues = sharedData.packedValues;
5201
+ this.sharedVersion = sharedData.version;
5202
+ this.structures.nextId = this.structures.length;
5203
+ } else {
5204
+ // restore structures
5205
+ structuresCopy.forEach((structure, i) => this.structures[i] = structure);
5206
+ }
5207
+ // saveShared may fail to write and reload, or may have reloaded to check compatibility and overwrite saved data, either way load the correct shared data
5208
+ return saveResults
5209
+ }
5210
+ }
5211
+ function writeEntityLength(length, majorValue) {
5212
+ if (length < 0x18)
5213
+ target[position++] = majorValue | length;
5214
+ else if (length < 0x100) {
5215
+ target[position++] = majorValue | 0x18;
5216
+ target[position++] = length;
5217
+ } else if (length < 0x10000) {
5218
+ target[position++] = majorValue | 0x19;
5219
+ target[position++] = length >> 8;
5220
+ target[position++] = length & 0xff;
5221
+ } else {
5222
+ target[position++] = majorValue | 0x1a;
5223
+ targetView.setUint32(position, length);
5224
+ position += 4;
5225
+ }
5226
+
5227
+ }
5228
+ class SharedData {
5229
+ constructor(structures, values, version) {
5230
+ this.structures = structures;
5231
+ this.packedValues = values;
5232
+ this.version = version;
5233
+ }
5234
+ }
5235
+
5236
+ function writeArrayHeader(length) {
5237
+ if (length < 0x18)
5238
+ target[position++] = 0x80 | length;
5239
+ else if (length < 0x100) {
5240
+ target[position++] = 0x98;
5241
+ target[position++] = length;
5242
+ } else if (length < 0x10000) {
5243
+ target[position++] = 0x99;
5244
+ target[position++] = length >> 8;
5245
+ target[position++] = length & 0xff;
5246
+ } else {
5247
+ target[position++] = 0x9a;
5248
+ targetView.setUint32(position, length);
5249
+ position += 4;
5250
+ }
5251
+ }
5252
+
5253
+ const BlobConstructor = typeof Blob === 'undefined' ? function(){} : Blob;
5254
+ function isBlob(object) {
5255
+ if (object instanceof BlobConstructor)
5256
+ return true;
5257
+ let tag = object[Symbol.toStringTag];
5258
+ return tag === 'Blob' || tag === 'File';
5259
+ }
5260
+ function findRepetitiveStrings(value, packedValues) {
5261
+ switch(typeof value) {
5262
+ case 'string':
5263
+ if (value.length > 3) {
5264
+ if (packedValues.objectMap[value] > -1 || packedValues.values.length >= packedValues.maxValues)
5265
+ return
5266
+ let packedStatus = packedValues.get(value);
5267
+ if (packedStatus) {
5268
+ if (++packedStatus.count == 2) {
5269
+ packedValues.values.push(value);
5270
+ }
5271
+ } else {
5272
+ packedValues.set(value, {
5273
+ count: 1,
5274
+ });
5275
+ if (packedValues.samplingPackedValues) {
5276
+ let status = packedValues.samplingPackedValues.get(value);
5277
+ if (status)
5278
+ status.count++;
5279
+ else
5280
+ packedValues.samplingPackedValues.set(value, {
5281
+ count: 1,
5282
+ });
5283
+ }
5284
+ }
5285
+ }
5286
+ break
5287
+ case 'object':
5288
+ if (value) {
5289
+ if (value instanceof Array) {
5290
+ for (let i = 0, l = value.length; i < l; i++) {
5291
+ findRepetitiveStrings(value[i], packedValues);
5292
+ }
5293
+
5294
+ } else {
5295
+ let includeKeys = !packedValues.encoder.useRecords;
5296
+ for (var key in value) {
5297
+ if (value.hasOwnProperty(key)) {
5298
+ if (includeKeys)
5299
+ findRepetitiveStrings(key, packedValues);
5300
+ findRepetitiveStrings(value[key], packedValues);
5301
+ }
5302
+ }
5303
+ }
5304
+ }
5305
+ break
5306
+ case 'function': console.log(value);
5307
+ }
5308
+ }
5309
+ const isLittleEndianMachine = new Uint8Array(new Uint16Array([1]).buffer)[0] == 1;
5310
+ extensionClasses = [ Date, Set, Error, RegExp, Tag, ArrayBuffer,
5311
+ Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array,
5312
+ typeof BigUint64Array == 'undefined' ? function() {} : BigUint64Array, Int8Array, Int16Array, Int32Array,
5313
+ typeof BigInt64Array == 'undefined' ? function() {} : BigInt64Array,
5314
+ Float32Array, Float64Array, SharedData ];
5315
+
5316
+ //Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/
5317
+ extensions = [{ // Date
5318
+ tag: 1,
5319
+ encode(date, encode) {
5320
+ let seconds = date.getTime() / 1000;
5321
+ if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
5322
+ // Timestamp 32
5323
+ target[position++] = 0x1a;
5324
+ targetView.setUint32(position, seconds);
5325
+ position += 4;
5326
+ } else {
5327
+ // Timestamp float64
5328
+ target[position++] = 0xfb;
5329
+ targetView.setFloat64(position, seconds);
5330
+ position += 8;
5331
+ }
5332
+ }
5333
+ }, { // Set
5334
+ tag: 258, // https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
5335
+ encode(set, encode) {
5336
+ let array = Array.from(set);
5337
+ encode(array);
5338
+ }
5339
+ }, { // Error
5340
+ tag: 27, // http://cbor.schmorp.de/generic-object
5341
+ encode(error, encode) {
5342
+ encode([ error.name, error.message ]);
5343
+ }
5344
+ }, { // RegExp
5345
+ tag: 27, // http://cbor.schmorp.de/generic-object
5346
+ encode(regex, encode) {
5347
+ encode([ 'RegExp', regex.source, regex.flags ]);
5348
+ }
5349
+ }, { // Tag
5350
+ getTag(tag) {
5351
+ return tag.tag
5352
+ },
5353
+ encode(tag, encode) {
5354
+ encode(tag.value);
5355
+ }
5356
+ }, { // ArrayBuffer
5357
+ encode(arrayBuffer, encode, makeRoom) {
5358
+ writeBuffer(arrayBuffer, makeRoom);
5359
+ }
5360
+ }, { // Uint8Array
5361
+ getTag(typedArray) {
5362
+ if (typedArray.constructor === Uint8Array) {
5363
+ if (this.tagUint8Array || hasNodeBuffer && this.tagUint8Array !== false)
5364
+ return 64;
5365
+ } // else no tag
5366
+ },
5367
+ encode(typedArray, encode, makeRoom) {
5368
+ writeBuffer(typedArray, makeRoom);
5369
+ }
5370
+ },
5371
+ typedArrayEncoder(68, 1),
5372
+ typedArrayEncoder(69, 2),
5373
+ typedArrayEncoder(70, 4),
5374
+ typedArrayEncoder(71, 8),
5375
+ typedArrayEncoder(72, 1),
5376
+ typedArrayEncoder(77, 2),
5377
+ typedArrayEncoder(78, 4),
5378
+ typedArrayEncoder(79, 8),
5379
+ typedArrayEncoder(85, 4),
5380
+ typedArrayEncoder(86, 8),
5381
+ {
5382
+ encode(sharedData, encode) { // write SharedData
5383
+ let packedValues = sharedData.packedValues || [];
5384
+ let sharedStructures = sharedData.structures || [];
5385
+ if (packedValues.values.length > 0) {
5386
+ target[position++] = 0xd8; // one-byte tag
5387
+ target[position++] = 51; // tag 51 for packed shared structures https://www.potaroo.net/ietf/ids/draft-ietf-cbor-packed-03.txt
5388
+ writeArrayHeader(4);
5389
+ let valuesArray = packedValues.values;
5390
+ encode(valuesArray);
5391
+ writeArrayHeader(0); // prefixes
5392
+ writeArrayHeader(0); // suffixes
5393
+ packedObjectMap = Object.create(sharedPackedObjectMap || null);
5394
+ for (let i = 0, l = valuesArray.length; i < l; i++) {
5395
+ packedObjectMap[valuesArray[i]] = i;
5396
+ }
5397
+ }
5398
+ if (sharedStructures) {
5399
+ targetView.setUint32(position, 0xd9dffe00);
5400
+ position += 3;
5401
+ let definitions = sharedStructures.slice(0);
5402
+ definitions.unshift(0xe000);
5403
+ definitions.push(new Tag(sharedData.version, 0x53687264));
5404
+ encode(definitions);
5405
+ } else
5406
+ encode(new Tag(sharedData.version, 0x53687264));
5407
+ }
5408
+ }];
5409
+ function typedArrayEncoder(tag, size) {
5410
+ if (!isLittleEndianMachine && size > 1)
5411
+ tag -= 4; // the big endian equivalents are 4 less
5412
+ return {
5413
+ tag: tag,
5414
+ encode: function writeExtBuffer(typedArray, encode) {
5415
+ let length = typedArray.byteLength;
5416
+ let offset = typedArray.byteOffset || 0;
5417
+ let buffer = typedArray.buffer || typedArray;
5418
+ encode(hasNodeBuffer ? Buffer$1.from(buffer, offset, length) :
5419
+ new Uint8Array(buffer, offset, length));
5420
+ }
5421
+ }
5422
+ }
5423
+ function writeBuffer(buffer, makeRoom) {
5424
+ let length = buffer.byteLength;
5425
+ if (length < 0x18) {
5426
+ target[position++] = 0x40 + length;
5427
+ } else if (length < 0x100) {
5428
+ target[position++] = 0x58;
5429
+ target[position++] = length;
5430
+ } else if (length < 0x10000) {
5431
+ target[position++] = 0x59;
5432
+ target[position++] = length >> 8;
5433
+ target[position++] = length & 0xff;
5434
+ } else {
5435
+ target[position++] = 0x5a;
5436
+ targetView.setUint32(position, length);
5437
+ position += 4;
5438
+ }
5439
+ if (position + length >= target.length) {
5440
+ makeRoom(position + length);
5441
+ }
5442
+ // if it is already a typed array (has an ArrayBuffer), use that, but if it is an ArrayBuffer itself,
5443
+ // must wrap it to set it.
5444
+ target.set(buffer.buffer ? buffer : new Uint8Array(buffer), position);
5445
+ position += length;
5446
+ }
5447
+
5448
+ function insertIds(serialized, idsToInsert) {
5449
+ // insert the ids that need to be referenced for structured clones
5450
+ let nextId;
5451
+ let distanceToMove = idsToInsert.length * 2;
5452
+ let lastEnd = serialized.length - distanceToMove;
5453
+ idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
5454
+ for (let id = 0; id < idsToInsert.length; id++) {
5455
+ let referee = idsToInsert[id];
5456
+ referee.id = id;
5457
+ for (let position of referee.references) {
5458
+ serialized[position++] = id >> 8;
5459
+ serialized[position] = id & 0xff;
5460
+ }
5461
+ }
5462
+ while (nextId = idsToInsert.pop()) {
5463
+ let offset = nextId.offset;
5464
+ serialized.copyWithin(offset + distanceToMove, offset, lastEnd);
5465
+ distanceToMove -= 2;
5466
+ let position = offset + distanceToMove;
5467
+ serialized[position++] = 0xd8;
5468
+ serialized[position++] = 28; // http://cbor.schmorp.de/value-sharing
5469
+ lastEnd = offset;
5470
+ }
5471
+ return serialized
5472
+ }
5473
+ function writeBundles(start, encode) {
5474
+ targetView.setUint32(bundledStrings.position + start, position - bundledStrings.position - start + 1); // the offset to bundle
5475
+ let writeStrings = bundledStrings;
5476
+ bundledStrings = null;
5477
+ encode(writeStrings[0]);
5478
+ encode(writeStrings[1]);
5479
+ }
5480
+ let defaultEncoder = new Encoder({ useRecords: false });
5481
+ defaultEncoder.encode;
5482
+ defaultEncoder.encodeAsIterable;
5483
+ defaultEncoder.encodeAsAsyncIterable;
5484
+ const REUSE_BUFFER_MODE = 512;
5485
+ const RESET_BUFFER_MODE = 1024;
5486
+ const THROW_ON_ITERABLE = 2048;
5487
+
5488
+ var browser = {exports: {}};
5489
+
5490
+ /**
5491
+ * Helpers.
5492
+ */
5493
+
5494
+ var ms;
5495
+ var hasRequiredMs;
5496
+
5497
+ function requireMs () {
5498
+ if (hasRequiredMs) return ms;
5499
+ hasRequiredMs = 1;
5500
+ var s = 1000;
5501
+ var m = s * 60;
5502
+ var h = m * 60;
5503
+ var d = h * 24;
5504
+ var w = d * 7;
5505
+ var y = d * 365.25;
5506
+
5507
+ /**
5508
+ * Parse or format the given `val`.
5509
+ *
5510
+ * Options:
5511
+ *
5512
+ * - `long` verbose formatting [false]
5513
+ *
5514
+ * @param {String|Number} val
5515
+ * @param {Object} [options]
5516
+ * @throws {Error} throw an error if val is not a non-empty string or a number
5517
+ * @return {String|Number}
5518
+ * @api public
5519
+ */
5520
+
5521
+ ms = function (val, options) {
5522
+ options = options || {};
5523
+ var type = typeof val;
5524
+ if (type === 'string' && val.length > 0) {
5525
+ return parse(val);
5526
+ } else if (type === 'number' && isFinite(val)) {
5527
+ return options.long ? fmtLong(val) : fmtShort(val);
5528
+ }
5529
+ throw new Error(
5530
+ 'val is not a non-empty string or a valid number. val=' +
5531
+ JSON.stringify(val)
5532
+ );
5533
+ };
5534
+
5535
+ /**
5536
+ * Parse the given `str` and return milliseconds.
5537
+ *
5538
+ * @param {String} str
5539
+ * @return {Number}
5540
+ * @api private
5541
+ */
5542
+
5543
+ function parse(str) {
5544
+ str = String(str);
5545
+ if (str.length > 100) {
5546
+ return;
5547
+ }
5548
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
5549
+ str
5550
+ );
5551
+ if (!match) {
5552
+ return;
5553
+ }
5554
+ var n = parseFloat(match[1]);
5555
+ var type = (match[2] || 'ms').toLowerCase();
5556
+ switch (type) {
5557
+ case 'years':
5558
+ case 'year':
5559
+ case 'yrs':
5560
+ case 'yr':
5561
+ case 'y':
5562
+ return n * y;
5563
+ case 'weeks':
5564
+ case 'week':
5565
+ case 'w':
5566
+ return n * w;
5567
+ case 'days':
5568
+ case 'day':
5569
+ case 'd':
5570
+ return n * d;
5571
+ case 'hours':
5572
+ case 'hour':
5573
+ case 'hrs':
5574
+ case 'hr':
5575
+ case 'h':
5576
+ return n * h;
5577
+ case 'minutes':
5578
+ case 'minute':
5579
+ case 'mins':
5580
+ case 'min':
5581
+ case 'm':
5582
+ return n * m;
5583
+ case 'seconds':
5584
+ case 'second':
5585
+ case 'secs':
5586
+ case 'sec':
5587
+ case 's':
5588
+ return n * s;
5589
+ case 'milliseconds':
5590
+ case 'millisecond':
5591
+ case 'msecs':
5592
+ case 'msec':
5593
+ case 'ms':
5594
+ return n;
5595
+ default:
5596
+ return undefined;
5597
+ }
5598
+ }
5599
+
5600
+ /**
5601
+ * Short format for `ms`.
5602
+ *
5603
+ * @param {Number} ms
5604
+ * @return {String}
5605
+ * @api private
5606
+ */
5607
+
5608
+ function fmtShort(ms) {
5609
+ var msAbs = Math.abs(ms);
5610
+ if (msAbs >= d) {
5611
+ return Math.round(ms / d) + 'd';
5612
+ }
5613
+ if (msAbs >= h) {
5614
+ return Math.round(ms / h) + 'h';
5615
+ }
5616
+ if (msAbs >= m) {
5617
+ return Math.round(ms / m) + 'm';
5618
+ }
5619
+ if (msAbs >= s) {
5620
+ return Math.round(ms / s) + 's';
5621
+ }
5622
+ return ms + 'ms';
5623
+ }
5624
+
5625
+ /**
5626
+ * Long format for `ms`.
5627
+ *
5628
+ * @param {Number} ms
5629
+ * @return {String}
5630
+ * @api private
5631
+ */
5632
+
5633
+ function fmtLong(ms) {
5634
+ var msAbs = Math.abs(ms);
5635
+ if (msAbs >= d) {
5636
+ return plural(ms, msAbs, d, 'day');
5637
+ }
5638
+ if (msAbs >= h) {
5639
+ return plural(ms, msAbs, h, 'hour');
5640
+ }
5641
+ if (msAbs >= m) {
5642
+ return plural(ms, msAbs, m, 'minute');
5643
+ }
5644
+ if (msAbs >= s) {
5645
+ return plural(ms, msAbs, s, 'second');
5646
+ }
5647
+ return ms + ' ms';
5648
+ }
5649
+
5650
+ /**
5651
+ * Pluralization helper.
5652
+ */
5653
+
5654
+ function plural(ms, msAbs, n, name) {
5655
+ var isPlural = msAbs >= n * 1.5;
5656
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
5657
+ }
5658
+ return ms;
5659
+ }
5660
+
5661
+ var common;
5662
+ var hasRequiredCommon;
5663
+
5664
+ function requireCommon () {
5665
+ if (hasRequiredCommon) return common;
5666
+ hasRequiredCommon = 1;
5667
+ /**
5668
+ * This is the common logic for both the Node.js and web browser
5669
+ * implementations of `debug()`.
5670
+ */
5671
+
5672
+ function setup(env) {
5673
+ createDebug.debug = createDebug;
5674
+ createDebug.default = createDebug;
5675
+ createDebug.coerce = coerce;
5676
+ createDebug.disable = disable;
5677
+ createDebug.enable = enable;
5678
+ createDebug.enabled = enabled;
5679
+ createDebug.humanize = requireMs();
5680
+ createDebug.destroy = destroy;
5681
+
5682
+ Object.keys(env).forEach(key => {
5683
+ createDebug[key] = env[key];
5684
+ });
5685
+
5686
+ /**
5687
+ * The currently active debug mode names, and names to skip.
5688
+ */
5689
+
5690
+ createDebug.names = [];
5691
+ createDebug.skips = [];
5692
+
5693
+ /**
5694
+ * Map of special "%n" handling functions, for the debug "format" argument.
5695
+ *
5696
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
5697
+ */
5698
+ createDebug.formatters = {};
5699
+
5700
+ /**
5701
+ * Selects a color for a debug namespace
5702
+ * @param {String} namespace The namespace string for the debug instance to be colored
5703
+ * @return {Number|String} An ANSI color code for the given namespace
5704
+ * @api private
5705
+ */
5706
+ function selectColor(namespace) {
5707
+ let hash = 0;
5708
+
5709
+ for (let i = 0; i < namespace.length; i++) {
5710
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
5711
+ hash |= 0; // Convert to 32bit integer
5712
+ }
5713
+
5714
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
5715
+ }
5716
+ createDebug.selectColor = selectColor;
5717
+
5718
+ /**
5719
+ * Create a debugger with the given `namespace`.
5720
+ *
5721
+ * @param {String} namespace
5722
+ * @return {Function}
5723
+ * @api public
5724
+ */
5725
+ function createDebug(namespace) {
5726
+ let prevTime;
5727
+ let enableOverride = null;
5728
+ let namespacesCache;
5729
+ let enabledCache;
5730
+
5731
+ function debug(...args) {
5732
+ // Disabled?
5733
+ if (!debug.enabled) {
5734
+ return;
5735
+ }
5736
+
5737
+ const self = debug;
5738
+
5739
+ // Set `diff` timestamp
5740
+ const curr = Number(new Date());
5741
+ const ms = curr - (prevTime || curr);
5742
+ self.diff = ms;
5743
+ self.prev = prevTime;
5744
+ self.curr = curr;
5745
+ prevTime = curr;
5746
+
5747
+ args[0] = createDebug.coerce(args[0]);
5748
+
5749
+ if (typeof args[0] !== 'string') {
5750
+ // Anything else let's inspect with %O
5751
+ args.unshift('%O');
5685
5752
  }
5686
- }
5687
- target[objectOffset++ + start] = size >> 8;
5688
- target[objectOffset + start] = size & 0xff;
5689
- } :
5690
- (object, skipValues) => {
5691
- let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
5692
- let newTransitions = 0;
5693
- let length = 0;
5694
- let parentRecordId;
5695
- let keys;
5696
- if (this.keyMap) {
5697
- keys = Object.keys(object).map(k => this.encodeKey(k));
5698
- length = keys.length;
5699
- for (let i = 0; i < length; i++) {
5700
- let key = keys[i];
5701
- nextTransition = transition[key];
5702
- if (!nextTransition) {
5703
- nextTransition = transition[key] = Object.create(null);
5704
- newTransitions++;
5753
+
5754
+ // Apply any `formatters` transformations
5755
+ let index = 0;
5756
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
5757
+ // If we encounter an escaped % then don't increase the array index
5758
+ if (match === '%%') {
5759
+ return '%';
5705
5760
  }
5706
- transition = nextTransition;
5707
- }
5708
- } else {
5709
- for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
5710
- nextTransition = transition[key];
5711
- if (!nextTransition) {
5712
- if (transition[RECORD_SYMBOL] & 0x100000) {// this indicates it is a brancheable/extendable terminal node, so we will use this record id and extend it
5713
- parentRecordId = transition[RECORD_SYMBOL] & 0xffff;
5714
- }
5715
- nextTransition = transition[key] = Object.create(null);
5716
- newTransitions++;
5761
+ index++;
5762
+ const formatter = createDebug.formatters[format];
5763
+ if (typeof formatter === 'function') {
5764
+ const val = args[index];
5765
+ match = formatter.call(self, val);
5766
+
5767
+ // Now we need to remove `args[index]` since it's inlined in the `format`
5768
+ args.splice(index, 1);
5769
+ index--;
5717
5770
  }
5718
- transition = nextTransition;
5719
- length++;
5720
- }
5771
+ return match;
5772
+ });
5773
+
5774
+ // Apply env-specific formatting (colors, etc.)
5775
+ createDebug.formatArgs.call(self, args);
5776
+
5777
+ const logFn = self.log || createDebug.log;
5778
+ logFn.apply(self, args);
5721
5779
  }
5722
- let recordId = transition[RECORD_SYMBOL];
5723
- if (recordId !== undefined) {
5724
- recordId &= 0xffff;
5725
- target[position++] = 0xd9;
5726
- target[position++] = (recordId >> 8) | 0xe0;
5727
- target[position++] = recordId & 0xff;
5728
- } else {
5729
- if (!keys)
5730
- keys = transition.__keys__ || (transition.__keys__ = Object.keys(object));
5731
- if (parentRecordId === undefined) {
5732
- recordId = structures.nextId++;
5733
- if (!recordId) {
5734
- recordId = 0;
5735
- structures.nextId = 1;
5736
- }
5737
- if (recordId >= MAX_STRUCTURES) {// cycle back around
5738
- structures.nextId = (recordId = maxSharedStructures) + 1;
5780
+
5781
+ debug.namespace = namespace;
5782
+ debug.useColors = createDebug.useColors();
5783
+ debug.color = createDebug.selectColor(namespace);
5784
+ debug.extend = extend;
5785
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
5786
+
5787
+ Object.defineProperty(debug, 'enabled', {
5788
+ enumerable: true,
5789
+ configurable: false,
5790
+ get: () => {
5791
+ if (enableOverride !== null) {
5792
+ return enableOverride;
5739
5793
  }
5740
- } else {
5741
- recordId = parentRecordId;
5742
- }
5743
- structures[recordId] = keys;
5744
- if (recordId < maxSharedStructures) {
5745
- target[position++] = 0xd9;
5746
- target[position++] = (recordId >> 8) | 0xe0;
5747
- target[position++] = recordId & 0xff;
5748
- transition = structures.transitions;
5749
- for (let i = 0; i < length; i++) {
5750
- if (transition[RECORD_SYMBOL] === undefined || (transition[RECORD_SYMBOL] & 0x100000))
5751
- transition[RECORD_SYMBOL] = recordId;
5752
- transition = transition[keys[i]];
5794
+ if (namespacesCache !== createDebug.namespaces) {
5795
+ namespacesCache = createDebug.namespaces;
5796
+ enabledCache = createDebug.enabled(namespace);
5753
5797
  }
5754
- transition[RECORD_SYMBOL] = recordId | 0x100000; // indicates it is a extendable terminal
5755
- hasSharedUpdate = true;
5756
- } else {
5757
- transition[RECORD_SYMBOL] = recordId;
5758
- targetView.setUint32(position, 0xd9dfff00); // tag two byte, then record definition id
5759
- position += 3;
5760
- if (newTransitions)
5761
- transitionsCount += serializationsSinceTransitionRebuild * newTransitions;
5762
- // record the removal of the id, we can maintain our shared structure
5763
- if (recordIdsToRemove.length >= MAX_STRUCTURES - maxSharedStructures)
5764
- recordIdsToRemove.shift()[RECORD_SYMBOL] = undefined; // we are cycling back through, and have to remove old ones
5765
- recordIdsToRemove.push(transition);
5766
- writeArrayHeader(length + 2);
5767
- encode(0xe000 + recordId);
5768
- encode(keys);
5769
- if (skipValues) return; // special exit for iterator
5770
- for (let key in object)
5771
- if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
5772
- encode(object[key]);
5773
- return
5798
+
5799
+ return enabledCache;
5800
+ },
5801
+ set: v => {
5802
+ enableOverride = v;
5774
5803
  }
5804
+ });
5805
+
5806
+ // Env-specific initialization logic for debug instances
5807
+ if (typeof createDebug.init === 'function') {
5808
+ createDebug.init(debug);
5775
5809
  }
5776
- if (length < 0x18) { // write the array header
5777
- target[position++] = 0x80 | length;
5778
- } else {
5779
- writeArrayHeader(length);
5780
- }
5781
- if (skipValues) return; // special exit for iterator
5782
- for (let key in object)
5783
- if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
5784
- encode(object[key]);
5785
- };
5786
- const makeRoom = (end) => {
5787
- let newSize;
5788
- if (end > 0x1000000) {
5789
- // special handling for really large buffers
5790
- if ((end - start) > MAX_BUFFER_SIZE)
5791
- throw new Error('Encoded buffer would be larger than maximum buffer size')
5792
- newSize = Math.min(MAX_BUFFER_SIZE,
5793
- Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
5794
- } else // faster handling for smaller buffers
5795
- newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
5796
- let newBuffer = new ByteArrayAllocate(newSize);
5797
- targetView = new DataView(newBuffer.buffer, 0, newSize);
5798
- if (target.copy)
5799
- target.copy(newBuffer, 0, start, end);
5800
- else
5801
- newBuffer.set(target.slice(start, end));
5802
- position -= start;
5803
- start = 0;
5804
- safeEnd = newBuffer.length - 10;
5805
- return target = newBuffer
5806
- };
5807
- let chunkThreshold = 100;
5808
- let continuedChunkThreshold = 1000;
5809
- this.encodeAsIterable = function(value, options) {
5810
- return startEncoding(value, options, encodeObjectAsIterable);
5811
- };
5812
- this.encodeAsAsyncIterable = function(value, options) {
5813
- return startEncoding(value, options, encodeObjectAsAsyncIterable);
5814
- };
5815
5810
 
5816
- function* encodeObjectAsIterable(object, iterateProperties, finalIterable) {
5817
- let constructor = object.constructor;
5818
- if (constructor === Object) {
5819
- let useRecords = encoder.useRecords !== false;
5820
- if (useRecords)
5821
- writeObject(object, true); // write the record identifier
5822
- else
5823
- writeEntityLength(Object.keys(object).length, 0xa0);
5824
- for (let key in object) {
5825
- let value = object[key];
5826
- if (!useRecords) encode(key);
5827
- if (value && typeof value === 'object') {
5828
- if (iterateProperties[key])
5829
- yield* encodeObjectAsIterable(value, iterateProperties[key]);
5830
- else
5831
- yield* tryEncode(value, iterateProperties, key);
5832
- } else encode(value);
5833
- }
5834
- } else if (constructor === Array) {
5835
- let length = object.length;
5836
- writeArrayHeader(length);
5837
- for (let i = 0; i < length; i++) {
5838
- let value = object[i];
5839
- if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
5840
- if (iterateProperties.element)
5841
- yield* encodeObjectAsIterable(value, iterateProperties.element);
5842
- else
5843
- yield* tryEncode(value, iterateProperties, 'element');
5844
- } else encode(value);
5811
+ return debug;
5812
+ }
5813
+
5814
+ function extend(namespace, delimiter) {
5815
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
5816
+ newDebug.log = this.log;
5817
+ return newDebug;
5818
+ }
5819
+
5820
+ /**
5821
+ * Enables a debug mode by namespaces. This can include modes
5822
+ * separated by a colon and wildcards.
5823
+ *
5824
+ * @param {String} namespaces
5825
+ * @api public
5826
+ */
5827
+ function enable(namespaces) {
5828
+ createDebug.save(namespaces);
5829
+ createDebug.namespaces = namespaces;
5830
+
5831
+ createDebug.names = [];
5832
+ createDebug.skips = [];
5833
+
5834
+ const split = (typeof namespaces === 'string' ? namespaces : '')
5835
+ .trim()
5836
+ .replace(/\s+/g, ',')
5837
+ .split(',')
5838
+ .filter(Boolean);
5839
+
5840
+ for (const ns of split) {
5841
+ if (ns[0] === '-') {
5842
+ createDebug.skips.push(ns.slice(1));
5843
+ } else {
5844
+ createDebug.names.push(ns);
5845
5845
  }
5846
- } else if (object[Symbol.iterator] && !object.buffer) { // iterator, but exclude typed arrays
5847
- target[position++] = 0x9f; // start indefinite array
5848
- for (let value of object) {
5849
- if (value && (typeof value === 'object' || position - start > chunkThreshold)) {
5850
- if (iterateProperties.element)
5851
- yield* encodeObjectAsIterable(value, iterateProperties.element);
5852
- else
5853
- yield* tryEncode(value, iterateProperties, 'element');
5854
- } else encode(value);
5846
+ }
5847
+ }
5848
+
5849
+ /**
5850
+ * Checks if the given string matches a namespace template, honoring
5851
+ * asterisks as wildcards.
5852
+ *
5853
+ * @param {String} search
5854
+ * @param {String} template
5855
+ * @return {Boolean}
5856
+ */
5857
+ function matchesTemplate(search, template) {
5858
+ let searchIndex = 0;
5859
+ let templateIndex = 0;
5860
+ let starIndex = -1;
5861
+ let matchIndex = 0;
5862
+
5863
+ while (searchIndex < search.length) {
5864
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
5865
+ // Match character or proceed with wildcard
5866
+ if (template[templateIndex] === '*') {
5867
+ starIndex = templateIndex;
5868
+ matchIndex = searchIndex;
5869
+ templateIndex++; // Skip the '*'
5870
+ } else {
5871
+ searchIndex++;
5872
+ templateIndex++;
5873
+ }
5874
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
5875
+ // Backtrack to the last '*' and try to match more characters
5876
+ templateIndex = starIndex + 1;
5877
+ matchIndex++;
5878
+ searchIndex = matchIndex;
5879
+ } else {
5880
+ return false; // No match
5855
5881
  }
5856
- target[position++] = 0xff; // stop byte
5857
- } else if (isBlob(object)){
5858
- writeEntityLength(object.size, 0x40); // encode as binary data
5859
- yield target.subarray(start, position);
5860
- yield object; // directly return blobs, they have to be encoded asynchronously
5861
- restartEncoding();
5862
- } else if (object[Symbol.asyncIterator]) {
5863
- target[position++] = 0x9f; // start indefinite array
5864
- yield target.subarray(start, position);
5865
- yield object; // directly return async iterators, they have to be encoded asynchronously
5866
- restartEncoding();
5867
- target[position++] = 0xff; // stop byte
5868
- } else {
5869
- encode(object);
5870
5882
  }
5871
- if (finalIterable && position > start) yield target.subarray(start, position);
5872
- else if (position - start > chunkThreshold) {
5873
- yield target.subarray(start, position);
5874
- restartEncoding();
5883
+
5884
+ // Handle trailing '*' in template
5885
+ while (templateIndex < template.length && template[templateIndex] === '*') {
5886
+ templateIndex++;
5875
5887
  }
5888
+
5889
+ return templateIndex === template.length;
5876
5890
  }
5877
- function* tryEncode(value, iterateProperties, key) {
5878
- let restart = position - start;
5879
- try {
5880
- encode(value);
5881
- if (position - start > chunkThreshold) {
5882
- yield target.subarray(start, position);
5883
- restartEncoding();
5891
+
5892
+ /**
5893
+ * Disable debug output.
5894
+ *
5895
+ * @return {String} namespaces
5896
+ * @api public
5897
+ */
5898
+ function disable() {
5899
+ const namespaces = [
5900
+ ...createDebug.names,
5901
+ ...createDebug.skips.map(namespace => '-' + namespace)
5902
+ ].join(',');
5903
+ createDebug.enable('');
5904
+ return namespaces;
5905
+ }
5906
+
5907
+ /**
5908
+ * Returns true if the given mode name is enabled, false otherwise.
5909
+ *
5910
+ * @param {String} name
5911
+ * @return {Boolean}
5912
+ * @api public
5913
+ */
5914
+ function enabled(name) {
5915
+ for (const skip of createDebug.skips) {
5916
+ if (matchesTemplate(name, skip)) {
5917
+ return false;
5918
+ }
5919
+ }
5920
+
5921
+ for (const ns of createDebug.names) {
5922
+ if (matchesTemplate(name, ns)) {
5923
+ return true;
5884
5924
  }
5885
- } catch (error) {
5886
- if (error.iteratorNotHandled) {
5887
- iterateProperties[key] = {};
5888
- position = start + restart; // restart our position so we don't have partial data from last encode
5889
- yield* encodeObjectAsIterable.call(this, value, iterateProperties[key]);
5890
- } else throw error;
5891
5925
  }
5926
+
5927
+ return false;
5892
5928
  }
5893
- function restartEncoding() {
5894
- chunkThreshold = continuedChunkThreshold;
5895
- encoder.encode(null, THROW_ON_ITERABLE); // restart encoding
5929
+
5930
+ /**
5931
+ * Coerce `val`.
5932
+ *
5933
+ * @param {Mixed} val
5934
+ * @return {Mixed}
5935
+ * @api private
5936
+ */
5937
+ function coerce(val) {
5938
+ if (val instanceof Error) {
5939
+ return val.stack || val.message;
5940
+ }
5941
+ return val;
5896
5942
  }
5897
- function startEncoding(value, options, encodeIterable) {
5898
- if (options && options.chunkThreshold) // explicitly specified chunk sizes
5899
- chunkThreshold = continuedChunkThreshold = options.chunkThreshold;
5900
- else // we start with a smaller threshold to get initial bytes sent quickly
5901
- chunkThreshold = 100;
5902
- if (value && typeof value === 'object') {
5903
- encoder.encode(null, THROW_ON_ITERABLE); // start encoding
5904
- return encodeIterable(value, encoder.iterateProperties || (encoder.iterateProperties = {}), true);
5943
+
5944
+ /**
5945
+ * XXX DO NOT USE. This is a temporary stub function.
5946
+ * XXX It WILL be removed in the next major release.
5947
+ */
5948
+ function destroy() {
5949
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
5950
+ }
5951
+
5952
+ createDebug.enable(createDebug.load());
5953
+
5954
+ return createDebug;
5955
+ }
5956
+
5957
+ common = setup;
5958
+ return common;
5959
+ }
5960
+
5961
+ /* eslint-env browser */
5962
+
5963
+ var hasRequiredBrowser;
5964
+
5965
+ function requireBrowser () {
5966
+ if (hasRequiredBrowser) return browser.exports;
5967
+ hasRequiredBrowser = 1;
5968
+ (function (module, exports) {
5969
+ /**
5970
+ * This is the web browser implementation of `debug()`.
5971
+ */
5972
+
5973
+ exports.formatArgs = formatArgs;
5974
+ exports.save = save;
5975
+ exports.load = load;
5976
+ exports.useColors = useColors;
5977
+ exports.storage = localstorage();
5978
+ exports.destroy = (() => {
5979
+ let warned = false;
5980
+
5981
+ return () => {
5982
+ if (!warned) {
5983
+ warned = true;
5984
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
5985
+ }
5986
+ };
5987
+ })();
5988
+
5989
+ /**
5990
+ * Colors.
5991
+ */
5992
+
5993
+ exports.colors = [
5994
+ '#0000CC',
5995
+ '#0000FF',
5996
+ '#0033CC',
5997
+ '#0033FF',
5998
+ '#0066CC',
5999
+ '#0066FF',
6000
+ '#0099CC',
6001
+ '#0099FF',
6002
+ '#00CC00',
6003
+ '#00CC33',
6004
+ '#00CC66',
6005
+ '#00CC99',
6006
+ '#00CCCC',
6007
+ '#00CCFF',
6008
+ '#3300CC',
6009
+ '#3300FF',
6010
+ '#3333CC',
6011
+ '#3333FF',
6012
+ '#3366CC',
6013
+ '#3366FF',
6014
+ '#3399CC',
6015
+ '#3399FF',
6016
+ '#33CC00',
6017
+ '#33CC33',
6018
+ '#33CC66',
6019
+ '#33CC99',
6020
+ '#33CCCC',
6021
+ '#33CCFF',
6022
+ '#6600CC',
6023
+ '#6600FF',
6024
+ '#6633CC',
6025
+ '#6633FF',
6026
+ '#66CC00',
6027
+ '#66CC33',
6028
+ '#9900CC',
6029
+ '#9900FF',
6030
+ '#9933CC',
6031
+ '#9933FF',
6032
+ '#99CC00',
6033
+ '#99CC33',
6034
+ '#CC0000',
6035
+ '#CC0033',
6036
+ '#CC0066',
6037
+ '#CC0099',
6038
+ '#CC00CC',
6039
+ '#CC00FF',
6040
+ '#CC3300',
6041
+ '#CC3333',
6042
+ '#CC3366',
6043
+ '#CC3399',
6044
+ '#CC33CC',
6045
+ '#CC33FF',
6046
+ '#CC6600',
6047
+ '#CC6633',
6048
+ '#CC9900',
6049
+ '#CC9933',
6050
+ '#CCCC00',
6051
+ '#CCCC33',
6052
+ '#FF0000',
6053
+ '#FF0033',
6054
+ '#FF0066',
6055
+ '#FF0099',
6056
+ '#FF00CC',
6057
+ '#FF00FF',
6058
+ '#FF3300',
6059
+ '#FF3333',
6060
+ '#FF3366',
6061
+ '#FF3399',
6062
+ '#FF33CC',
6063
+ '#FF33FF',
6064
+ '#FF6600',
6065
+ '#FF6633',
6066
+ '#FF9900',
6067
+ '#FF9933',
6068
+ '#FFCC00',
6069
+ '#FFCC33'
6070
+ ];
6071
+
6072
+ /**
6073
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
6074
+ * and the Firebug extension (any Firefox version) are known
6075
+ * to support "%c" CSS customizations.
6076
+ *
6077
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
6078
+ */
6079
+
6080
+ // eslint-disable-next-line complexity
6081
+ function useColors() {
6082
+ // NB: In an Electron preload script, document will be defined but not fully
6083
+ // initialized. Since we know we're in Chrome, we'll just detect this case
6084
+ // explicitly
6085
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
6086
+ return true;
5905
6087
  }
5906
- return [encoder.encode(value)];
5907
- }
5908
6088
 
5909
- async function* encodeObjectAsAsyncIterable(value, iterateProperties) {
5910
- for (let encodedValue of encodeObjectAsIterable(value, iterateProperties, true)) {
5911
- let constructor = encodedValue.constructor;
5912
- if (constructor === ByteArray || constructor === Uint8Array)
5913
- yield encodedValue;
5914
- else if (isBlob(encodedValue)) {
5915
- let reader = encodedValue.stream().getReader();
5916
- let next;
5917
- while (!(next = await reader.read()).done) {
5918
- yield next.value;
5919
- }
5920
- } else if (encodedValue[Symbol.asyncIterator]) {
5921
- for await (let asyncValue of encodedValue) {
5922
- restartEncoding();
5923
- if (asyncValue)
5924
- yield* encodeObjectAsAsyncIterable(asyncValue, iterateProperties.async || (iterateProperties.async = {}));
5925
- else yield encoder.encode(asyncValue);
5926
- }
5927
- } else {
5928
- yield encodedValue;
5929
- }
6089
+ // Internet Explorer and Edge do not support colors.
6090
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
6091
+ return false;
5930
6092
  }
6093
+
6094
+ let m;
6095
+
6096
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
6097
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
6098
+ // eslint-disable-next-line no-return-assign
6099
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
6100
+ // Is firebug? http://stackoverflow.com/a/398120/376773
6101
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
6102
+ // Is firefox >= v31?
6103
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
6104
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
6105
+ // Double check webkit in userAgent just in case we are in a worker
6106
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
5931
6107
  }
5932
- }
5933
- useBuffer(buffer) {
5934
- // this means we are finished using our own buffer and we can write over it safely
5935
- target = buffer;
5936
- targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
5937
- position = 0;
5938
- }
5939
- clearSharedData() {
5940
- if (this.structures)
5941
- this.structures = [];
5942
- if (this.sharedValues)
5943
- this.sharedValues = undefined;
5944
- }
5945
- updateSharedData() {
5946
- let lastVersion = this.sharedVersion || 0;
5947
- this.sharedVersion = lastVersion + 1;
5948
- let structuresCopy = this.structures.slice(0);
5949
- let sharedData = new SharedData(structuresCopy, this.sharedValues, this.sharedVersion);
5950
- let saveResults = this.saveShared(sharedData,
5951
- existingShared => (existingShared && existingShared.version || 0) == lastVersion);
5952
- if (saveResults === false) {
5953
- // get updated structures and try again if the update failed
5954
- sharedData = this.getShared() || {};
5955
- this.structures = sharedData.structures || [];
5956
- this.sharedValues = sharedData.packedValues;
5957
- this.sharedVersion = sharedData.version;
5958
- this.structures.nextId = this.structures.length;
5959
- } else {
5960
- // restore structures
5961
- structuresCopy.forEach((structure, i) => this.structures[i] = structure);
5962
- }
5963
- // saveShared may fail to write and reload, or may have reloaded to check compatibility and overwrite saved data, either way load the correct shared data
5964
- return saveResults
5965
- }
5966
- }
5967
- function writeEntityLength(length, majorValue) {
5968
- if (length < 0x18)
5969
- target[position++] = majorValue | length;
5970
- else if (length < 0x100) {
5971
- target[position++] = majorValue | 0x18;
5972
- target[position++] = length;
5973
- } else if (length < 0x10000) {
5974
- target[position++] = majorValue | 0x19;
5975
- target[position++] = length >> 8;
5976
- target[position++] = length & 0xff;
5977
- } else {
5978
- target[position++] = majorValue | 0x1a;
5979
- targetView.setUint32(position, length);
5980
- position += 4;
5981
- }
5982
6108
 
5983
- }
5984
- class SharedData {
5985
- constructor(structures, values, version) {
5986
- this.structures = structures;
5987
- this.packedValues = values;
5988
- this.version = version;
5989
- }
5990
- }
6109
+ /**
6110
+ * Colorize log arguments if enabled.
6111
+ *
6112
+ * @api public
6113
+ */
5991
6114
 
5992
- function writeArrayHeader(length) {
5993
- if (length < 0x18)
5994
- target[position++] = 0x80 | length;
5995
- else if (length < 0x100) {
5996
- target[position++] = 0x98;
5997
- target[position++] = length;
5998
- } else if (length < 0x10000) {
5999
- target[position++] = 0x99;
6000
- target[position++] = length >> 8;
6001
- target[position++] = length & 0xff;
6002
- } else {
6003
- target[position++] = 0x9a;
6004
- targetView.setUint32(position, length);
6005
- position += 4;
6006
- }
6007
- }
6115
+ function formatArgs(args) {
6116
+ args[0] = (this.useColors ? '%c' : '') +
6117
+ this.namespace +
6118
+ (this.useColors ? ' %c' : ' ') +
6119
+ args[0] +
6120
+ (this.useColors ? '%c ' : ' ') +
6121
+ '+' + module.exports.humanize(this.diff);
6008
6122
 
6009
- const BlobConstructor = typeof Blob === 'undefined' ? function(){} : Blob;
6010
- function isBlob(object) {
6011
- if (object instanceof BlobConstructor)
6012
- return true;
6013
- let tag = object[Symbol.toStringTag];
6014
- return tag === 'Blob' || tag === 'File';
6015
- }
6016
- function findRepetitiveStrings(value, packedValues) {
6017
- switch(typeof value) {
6018
- case 'string':
6019
- if (value.length > 3) {
6020
- if (packedValues.objectMap[value] > -1 || packedValues.values.length >= packedValues.maxValues)
6021
- return
6022
- let packedStatus = packedValues.get(value);
6023
- if (packedStatus) {
6024
- if (++packedStatus.count == 2) {
6025
- packedValues.values.push(value);
6026
- }
6027
- } else {
6028
- packedValues.set(value, {
6029
- count: 1,
6030
- });
6031
- if (packedValues.samplingPackedValues) {
6032
- let status = packedValues.samplingPackedValues.get(value);
6033
- if (status)
6034
- status.count++;
6035
- else
6036
- packedValues.samplingPackedValues.set(value, {
6037
- count: 1,
6038
- });
6039
- }
6040
- }
6123
+ if (!this.useColors) {
6124
+ return;
6041
6125
  }
6042
- break
6043
- case 'object':
6044
- if (value) {
6045
- if (value instanceof Array) {
6046
- for (let i = 0, l = value.length; i < l; i++) {
6047
- findRepetitiveStrings(value[i], packedValues);
6048
- }
6049
6126
 
6127
+ const c = 'color: ' + this.color;
6128
+ args.splice(1, 0, c, 'color: inherit');
6129
+
6130
+ // The final "%c" is somewhat tricky, because there could be other
6131
+ // arguments passed either before or after the %c, so we need to
6132
+ // figure out the correct index to insert the CSS into
6133
+ let index = 0;
6134
+ let lastC = 0;
6135
+ args[0].replace(/%[a-zA-Z%]/g, match => {
6136
+ if (match === '%%') {
6137
+ return;
6138
+ }
6139
+ index++;
6140
+ if (match === '%c') {
6141
+ // We only are interested in the *last* %c
6142
+ // (the user may have provided their own)
6143
+ lastC = index;
6144
+ }
6145
+ });
6146
+
6147
+ args.splice(lastC, 0, c);
6148
+ }
6149
+
6150
+ /**
6151
+ * Invokes `console.debug()` when available.
6152
+ * No-op when `console.debug` is not a "function".
6153
+ * If `console.debug` is not available, falls back
6154
+ * to `console.log`.
6155
+ *
6156
+ * @api public
6157
+ */
6158
+ exports.log = console.debug || console.log || (() => {});
6159
+
6160
+ /**
6161
+ * Save `namespaces`.
6162
+ *
6163
+ * @param {String} namespaces
6164
+ * @api private
6165
+ */
6166
+ function save(namespaces) {
6167
+ try {
6168
+ if (namespaces) {
6169
+ exports.storage.setItem('debug', namespaces);
6050
6170
  } else {
6051
- let includeKeys = !packedValues.encoder.useRecords;
6052
- for (var key in value) {
6053
- if (value.hasOwnProperty(key)) {
6054
- if (includeKeys)
6055
- findRepetitiveStrings(key, packedValues);
6056
- findRepetitiveStrings(value[key], packedValues);
6057
- }
6058
- }
6171
+ exports.storage.removeItem('debug');
6059
6172
  }
6173
+ } catch (error) {
6174
+ // Swallow
6175
+ // XXX (@Qix-) should we be logging these?
6060
6176
  }
6061
- break
6062
- case 'function': console.log(value);
6063
- }
6064
- }
6065
- const isLittleEndianMachine = new Uint8Array(new Uint16Array([1]).buffer)[0] == 1;
6066
- extensionClasses = [ Date, Set, Error, RegExp, Tag, ArrayBuffer,
6067
- Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array,
6068
- typeof BigUint64Array == 'undefined' ? function() {} : BigUint64Array, Int8Array, Int16Array, Int32Array,
6069
- typeof BigInt64Array == 'undefined' ? function() {} : BigInt64Array,
6070
- Float32Array, Float64Array, SharedData ];
6071
-
6072
- //Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/
6073
- extensions = [{ // Date
6074
- tag: 1,
6075
- encode(date, encode) {
6076
- let seconds = date.getTime() / 1000;
6077
- if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
6078
- // Timestamp 32
6079
- target[position++] = 0x1a;
6080
- targetView.setUint32(position, seconds);
6081
- position += 4;
6082
- } else {
6083
- // Timestamp float64
6084
- target[position++] = 0xfb;
6085
- targetView.setFloat64(position, seconds);
6086
- position += 8;
6087
6177
  }
6088
- }
6089
- }, { // Set
6090
- tag: 258, // https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
6091
- encode(set, encode) {
6092
- let array = Array.from(set);
6093
- encode(array);
6094
- }
6095
- }, { // Error
6096
- tag: 27, // http://cbor.schmorp.de/generic-object
6097
- encode(error, encode) {
6098
- encode([ error.name, error.message ]);
6099
- }
6100
- }, { // RegExp
6101
- tag: 27, // http://cbor.schmorp.de/generic-object
6102
- encode(regex, encode) {
6103
- encode([ 'RegExp', regex.source, regex.flags ]);
6104
- }
6105
- }, { // Tag
6106
- getTag(tag) {
6107
- return tag.tag
6108
- },
6109
- encode(tag, encode) {
6110
- encode(tag.value);
6111
- }
6112
- }, { // ArrayBuffer
6113
- encode(arrayBuffer, encode, makeRoom) {
6114
- writeBuffer(arrayBuffer, makeRoom);
6115
- }
6116
- }, { // Uint8Array
6117
- getTag(typedArray) {
6118
- if (typedArray.constructor === Uint8Array) {
6119
- if (this.tagUint8Array || hasNodeBuffer && this.tagUint8Array !== false)
6120
- return 64;
6121
- } // else no tag
6122
- },
6123
- encode(typedArray, encode, makeRoom) {
6124
- writeBuffer(typedArray, makeRoom);
6125
- }
6126
- },
6127
- typedArrayEncoder(68, 1),
6128
- typedArrayEncoder(69, 2),
6129
- typedArrayEncoder(70, 4),
6130
- typedArrayEncoder(71, 8),
6131
- typedArrayEncoder(72, 1),
6132
- typedArrayEncoder(77, 2),
6133
- typedArrayEncoder(78, 4),
6134
- typedArrayEncoder(79, 8),
6135
- typedArrayEncoder(85, 4),
6136
- typedArrayEncoder(86, 8),
6137
- {
6138
- encode(sharedData, encode) { // write SharedData
6139
- let packedValues = sharedData.packedValues || [];
6140
- let sharedStructures = sharedData.structures || [];
6141
- if (packedValues.values.length > 0) {
6142
- target[position++] = 0xd8; // one-byte tag
6143
- target[position++] = 51; // tag 51 for packed shared structures https://www.potaroo.net/ietf/ids/draft-ietf-cbor-packed-03.txt
6144
- writeArrayHeader(4);
6145
- let valuesArray = packedValues.values;
6146
- encode(valuesArray);
6147
- writeArrayHeader(0); // prefixes
6148
- writeArrayHeader(0); // suffixes
6149
- packedObjectMap = Object.create(sharedPackedObjectMap || null);
6150
- for (let i = 0, l = valuesArray.length; i < l; i++) {
6151
- packedObjectMap[valuesArray[i]] = i;
6178
+
6179
+ /**
6180
+ * Load `namespaces`.
6181
+ *
6182
+ * @return {String} returns the previously persisted debug modes
6183
+ * @api private
6184
+ */
6185
+ function load() {
6186
+ let r;
6187
+ try {
6188
+ r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ;
6189
+ } catch (error) {
6190
+ // Swallow
6191
+ // XXX (@Qix-) should we be logging these?
6152
6192
  }
6193
+
6194
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
6195
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
6196
+ r = process.env.DEBUG;
6197
+ }
6198
+
6199
+ return r;
6153
6200
  }
6154
- if (sharedStructures) {
6155
- targetView.setUint32(position, 0xd9dffe00);
6156
- position += 3;
6157
- let definitions = sharedStructures.slice(0);
6158
- definitions.unshift(0xe000);
6159
- definitions.push(new Tag(sharedData.version, 0x53687264));
6160
- encode(definitions);
6161
- } else
6162
- encode(new Tag(sharedData.version, 0x53687264));
6163
- }
6164
- }];
6165
- function typedArrayEncoder(tag, size) {
6166
- if (!isLittleEndianMachine && size > 1)
6167
- tag -= 4; // the big endian equivalents are 4 less
6168
- return {
6169
- tag: tag,
6170
- encode: function writeExtBuffer(typedArray, encode) {
6171
- let length = typedArray.byteLength;
6172
- let offset = typedArray.byteOffset || 0;
6173
- let buffer = typedArray.buffer || typedArray;
6174
- encode(hasNodeBuffer ? Buffer$1.from(buffer, offset, length) :
6175
- new Uint8Array(buffer, offset, length));
6176
- }
6177
- }
6178
- }
6179
- function writeBuffer(buffer, makeRoom) {
6180
- let length = buffer.byteLength;
6181
- if (length < 0x18) {
6182
- target[position++] = 0x40 + length;
6183
- } else if (length < 0x100) {
6184
- target[position++] = 0x58;
6185
- target[position++] = length;
6186
- } else if (length < 0x10000) {
6187
- target[position++] = 0x59;
6188
- target[position++] = length >> 8;
6189
- target[position++] = length & 0xff;
6190
- } else {
6191
- target[position++] = 0x5a;
6192
- targetView.setUint32(position, length);
6193
- position += 4;
6194
- }
6195
- if (position + length >= target.length) {
6196
- makeRoom(position + length);
6197
- }
6198
- // if it is already a typed array (has an ArrayBuffer), use that, but if it is an ArrayBuffer itself,
6199
- // must wrap it to set it.
6200
- target.set(buffer.buffer ? buffer : new Uint8Array(buffer), position);
6201
- position += length;
6202
- }
6203
6201
 
6204
- function insertIds(serialized, idsToInsert) {
6205
- // insert the ids that need to be referenced for structured clones
6206
- let nextId;
6207
- let distanceToMove = idsToInsert.length * 2;
6208
- let lastEnd = serialized.length - distanceToMove;
6209
- idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
6210
- for (let id = 0; id < idsToInsert.length; id++) {
6211
- let referee = idsToInsert[id];
6212
- referee.id = id;
6213
- for (let position of referee.references) {
6214
- serialized[position++] = id >> 8;
6215
- serialized[position] = id & 0xff;
6202
+ /**
6203
+ * Localstorage attempts to return the localstorage.
6204
+ *
6205
+ * This is necessary because safari throws
6206
+ * when a user disables cookies/localstorage
6207
+ * and you attempt to access it.
6208
+ *
6209
+ * @return {LocalStorage}
6210
+ * @api private
6211
+ */
6212
+
6213
+ function localstorage() {
6214
+ try {
6215
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
6216
+ // The Browser also has localStorage in the global context.
6217
+ return localStorage;
6218
+ } catch (error) {
6219
+ // Swallow
6220
+ // XXX (@Qix-) should we be logging these?
6221
+ }
6216
6222
  }
6217
- }
6218
- while (nextId = idsToInsert.pop()) {
6219
- let offset = nextId.offset;
6220
- serialized.copyWithin(offset + distanceToMove, offset, lastEnd);
6221
- distanceToMove -= 2;
6222
- let position = offset + distanceToMove;
6223
- serialized[position++] = 0xd8;
6224
- serialized[position++] = 28; // http://cbor.schmorp.de/value-sharing
6225
- lastEnd = offset;
6226
- }
6227
- return serialized
6228
- }
6229
- function writeBundles(start, encode) {
6230
- targetView.setUint32(bundledStrings.position + start, position - bundledStrings.position - start + 1); // the offset to bundle
6231
- let writeStrings = bundledStrings;
6232
- bundledStrings = null;
6233
- encode(writeStrings[0]);
6234
- encode(writeStrings[1]);
6223
+
6224
+ module.exports = requireCommon()(exports);
6225
+
6226
+ const {formatters} = module.exports;
6227
+
6228
+ /**
6229
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
6230
+ */
6231
+
6232
+ formatters.j = function (v) {
6233
+ try {
6234
+ return JSON.stringify(v);
6235
+ } catch (error) {
6236
+ return '[UnexpectedJSONParseError]: ' + error.message;
6237
+ }
6238
+ };
6239
+ } (browser, browser.exports));
6240
+ return browser.exports;
6235
6241
  }
6236
- let defaultEncoder = new Encoder({ useRecords: false });
6237
- defaultEncoder.encode;
6238
- defaultEncoder.encodeAsIterable;
6239
- defaultEncoder.encodeAsAsyncIterable;
6240
- const REUSE_BUFFER_MODE = 512;
6241
- const RESET_BUFFER_MODE = 1024;
6242
- const THROW_ON_ITERABLE = 2048;
6242
+
6243
+ var browserExports = requireBrowser();
6244
+ const debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
6243
6245
 
6244
6246
  var sha256$1 = {exports: {}};
6245
6247
 
@@ -6688,13 +6690,6 @@ debug("automerge-repo:collectionsync");
6688
6690
  */
6689
6691
  new FinalizationRegistry(cleanup => cleanup());
6690
6692
 
6691
- /* c8 ignore start */
6692
- /**
6693
- * A promise that never settles
6694
- */
6695
- new Promise(() => { });
6696
- /* c8 ignore end */
6697
-
6698
6693
  const DEFAULT_HEARTBEAT_INTERVAL_MS = 15_000;
6699
6694
  const DEFAULT_PEER_TTL_MS = 3 * DEFAULT_HEARTBEAT_INTERVAL_MS;
6700
6695
  const PRESENCE_MESSAGE_MARKER = "__presence";