indexeddbshim 9.0.0 → 10.0.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.
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v9.0.0 - 1/5/2022 */
1
+ /*! indexeddbshim - v9.0.0 - 2/26/2022 */
2
2
 
3
3
  'use strict';
4
4
 
@@ -36,6 +36,42 @@ function _objectSpread2$1(target) {
36
36
  return target;
37
37
  }
38
38
 
39
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
40
+ try {
41
+ var info = gen[key](arg);
42
+ var value = info.value;
43
+ } catch (error) {
44
+ reject(error);
45
+ return;
46
+ }
47
+
48
+ if (info.done) {
49
+ resolve(value);
50
+ } else {
51
+ Promise.resolve(value).then(_next, _throw);
52
+ }
53
+ }
54
+
55
+ function _asyncToGenerator(fn) {
56
+ return function () {
57
+ var self = this,
58
+ args = arguments;
59
+ return new Promise(function (resolve, reject) {
60
+ var gen = fn.apply(self, args);
61
+
62
+ function _next(value) {
63
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
64
+ }
65
+
66
+ function _throw(err) {
67
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
68
+ }
69
+
70
+ _next(undefined);
71
+ });
72
+ };
73
+ }
74
+
39
75
  function _defineProperty$1(obj, key, value) {
40
76
  if (key in obj) {
41
77
  Object.defineProperty(obj, key, {
@@ -845,7 +881,7 @@ function setPrototypeOfCustomEvent() {
845
881
  Object.setPrototypeOf(ShimCustomEvent.prototype, ShimEvent.prototype);
846
882
  } // Todo: Move to own library (but allowing WeakMaps to be passed in for sharing here)
847
883
 
848
- const map$1 = {};
884
+ const map = {};
849
885
  const CFG = {};
850
886
  [// Boolean for verbose reporting
851
887
  'DEBUG', // Effectively defaults to false (ignored unless `true`)
@@ -950,7 +986,7 @@ const CFG = {};
950
986
 
951
987
  Object.defineProperty(CFG, prop, {
952
988
  get() {
953
- return map$1[prop];
989
+ return map[prop];
954
990
  },
955
991
 
956
992
  set(val) {
@@ -958,7 +994,7 @@ const CFG = {};
958
994
  validator(val);
959
995
  }
960
996
 
961
- map$1[prop] = val;
997
+ map[prop] = val;
962
998
  }
963
999
 
964
1000
  });
@@ -1274,7 +1310,7 @@ function isNullish(v) {
1274
1310
  return v === null || v === undefined;
1275
1311
  }
1276
1312
 
1277
- function hasOwn$2(obj, prop) {
1313
+ function hasOwn(obj, prop) {
1278
1314
  return Object.prototype.hasOwnProperty.call(obj, prop);
1279
1315
  }
1280
1316
 
@@ -1970,14 +2006,14 @@ var syncPromiseCommonjs = SyncPromise;
1970
2006
  */
1971
2007
 
1972
2008
  function cmp(first, second) {
1973
- const encodedKey1 = encode$2(first);
1974
- const encodedKey2 = encode$2(second);
2009
+ const encodedKey1 = encode$1(first);
2010
+ const encodedKey2 = encode$1(second);
1975
2011
  const result = encodedKey1 > encodedKey2 ? 1 : encodedKey1 === encodedKey2 ? 0 : -1;
1976
2012
 
1977
2013
  if (CFG.DEBUG) {
1978
2014
  // verify that the keys encoded correctly
1979
- let decodedKey1 = decode$2(encodedKey1);
1980
- let decodedKey2 = decode$2(encodedKey2);
2015
+ let decodedKey1 = decode$1(encodedKey1);
2016
+ let decodedKey2 = decode$1(encodedKey2);
1981
2017
 
1982
2018
  if (typeof first === 'object') {
1983
2019
  first = JSON.stringify(first);
@@ -2189,7 +2225,7 @@ const types = {
2189
2225
  const encoded = [];
2190
2226
 
2191
2227
  for (const [i, item] of key.entries()) {
2192
- const encodedItem = encode$2(item, true); // encode the array item
2228
+ const encodedItem = encode$1(item, true); // encode the array item
2193
2229
 
2194
2230
  encoded[i] = encodedItem;
2195
2231
  }
@@ -2205,7 +2241,7 @@ const types = {
2205
2241
 
2206
2242
  for (let i = 0; i < decoded.length; i++) {
2207
2243
  const item = decoded[i];
2208
- const decodedItem = decode$2(item, true); // decode the item
2244
+ const decodedItem = decode$1(item, true); // decode the item
2209
2245
 
2210
2246
  decoded[i] = decodedItem;
2211
2247
  }
@@ -2798,9 +2834,9 @@ function checkKeyCouldBeInjectedIntoValue(value, keyPath) {
2798
2834
  function isKeyInRange(key, range, checkCached) {
2799
2835
  let lowerMatch = range.lower === undefined;
2800
2836
  let upperMatch = range.upper === undefined;
2801
- const encodedKey = encode$2(key, true);
2802
- const lower = checkCached ? range.__lowerCached : encode$2(range.lower, true);
2803
- const upper = checkCached ? range.__upperCached : encode$2(range.upper, true);
2837
+ const encodedKey = encode$1(key, true);
2838
+ const lower = checkCached ? range.__lowerCached : encode$1(range.lower, true);
2839
+ const upper = checkCached ? range.__upperCached : encode$1(range.upper, true);
2804
2840
 
2805
2841
  if (range.lower !== undefined) {
2806
2842
  if (range.lowerOpen && encodedKey > lower) {
@@ -2950,7 +2986,7 @@ function convertKeyToValue(key) {
2950
2986
  */
2951
2987
 
2952
2988
 
2953
- function encode$2(key, inArray) {
2989
+ function encode$1(key, inArray) {
2954
2990
  // Bad keys like `null`, `object`, `boolean`, 'function', 'symbol' should not be passed here due to prior validation
2955
2991
  if (key === undefined) {
2956
2992
  return null;
@@ -2968,7 +3004,7 @@ function encode$2(key, inArray) {
2968
3004
  */
2969
3005
 
2970
3006
 
2971
- function decode$2(key, inArray) {
3007
+ function decode$1(key, inArray) {
2972
3008
  if (typeof key !== 'string') {
2973
3009
  return undefined;
2974
3010
  }
@@ -2984,7 +3020,7 @@ function decode$2(key, inArray) {
2984
3020
 
2985
3021
 
2986
3022
  function roundTrip(key, inArray) {
2987
- return decode$2(encode$2(key, inArray), inArray);
3023
+ return decode$1(encode$1(key, inArray), inArray);
2988
3024
  }
2989
3025
 
2990
3026
  const MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
@@ -3150,8 +3186,8 @@ function possiblyUpdateKeyGenerator(tx, store, key, successCb, sqlFailCb) {
3150
3186
 
3151
3187
  var Key = /*#__PURE__*/Object.freeze({
3152
3188
  __proto__: null,
3153
- encode: encode$2,
3154
- decode: decode$2,
3189
+ encode: encode$1,
3190
+ decode: decode$1,
3155
3191
  roundTrip: roundTrip,
3156
3192
  convertKeyToValue: convertKeyToValue,
3157
3193
  convertValueToKeyValueDecoded: convertValueToKeyValueDecoded,
@@ -3216,7 +3252,7 @@ IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
3216
3252
  }
3217
3253
 
3218
3254
  if (lower !== undefined && upper !== undefined && lower !== upper) {
3219
- if (encode$2(lower) > encode$2(upper)) {
3255
+ if (encode$1(lower) > encode$1(upper)) {
3220
3256
  throw createDOMException('DataError', '`lower` must not be greater than `upper` argument in `bound()` call.');
3221
3257
  }
3222
3258
  }
@@ -3325,11 +3361,11 @@ function setSQLForKeyRange(range, quotedKeyColumnName, sql, sqlValues, addAnd, c
3325
3361
  const hasUpper = range.upper !== undefined;
3326
3362
 
3327
3363
  if (hasLower) {
3328
- encodedLowerKey = checkCached ? range.__lowerCached : encode$2(range.lower);
3364
+ encodedLowerKey = checkCached ? range.__lowerCached : encode$1(range.lower);
3329
3365
  }
3330
3366
 
3331
3367
  if (hasUpper) {
3332
- encodedUpperKey = checkCached ? range.__upperCached : encode$2(range.upper);
3368
+ encodedUpperKey = checkCached ? range.__upperCached : encode$1(range.upper);
3333
3369
  }
3334
3370
 
3335
3371
  if (hasLower) {
@@ -4198,3297 +4234,1256 @@ Object.defineProperty(IDBTransaction, 'prototype', {
4198
4234
  writable: false
4199
4235
  });
4200
4236
 
4201
- function _typeof(obj) {
4202
- "@babel/helpers - typeof";
4237
+ function ownKeys(e, t) {
4238
+ var r = Object.keys(e);
4203
4239
 
4204
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
4205
- _typeof = function (obj) {
4206
- return typeof obj;
4207
- };
4208
- } else {
4209
- _typeof = function (obj) {
4210
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
4211
- };
4240
+ if (Object.getOwnPropertySymbols) {
4241
+ var n = Object.getOwnPropertySymbols(e);
4242
+ t && (n = n.filter(function (t) {
4243
+ return Object.getOwnPropertyDescriptor(e, t).enumerable;
4244
+ })), r.push.apply(r, n);
4212
4245
  }
4213
4246
 
4214
- return _typeof(obj);
4247
+ return r;
4215
4248
  }
4216
4249
 
4217
- function _classCallCheck(instance, Constructor) {
4218
- if (!(instance instanceof Constructor)) {
4219
- throw new TypeError("Cannot call a class as a function");
4250
+ function _objectSpread2(e) {
4251
+ for (var t = 1; t < arguments.length; t++) {
4252
+ var r = null != arguments[t] ? arguments[t] : {};
4253
+ t % 2 ? ownKeys(Object(r), !0).forEach(function (t) {
4254
+ _defineProperty(e, t, r[t]);
4255
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach(function (t) {
4256
+ Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
4257
+ });
4220
4258
  }
4259
+
4260
+ return e;
4221
4261
  }
4222
4262
 
4223
- function _defineProperties(target, props) {
4224
- for (var i = 0; i < props.length; i++) {
4225
- var descriptor = props[i];
4226
- descriptor.enumerable = descriptor.enumerable || false;
4227
- descriptor.configurable = true;
4228
- if ("value" in descriptor) descriptor.writable = true;
4229
- Object.defineProperty(target, descriptor.key, descriptor);
4230
- }
4263
+ function _typeof(e) {
4264
+ return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
4265
+ return typeof e;
4266
+ } : function (e) {
4267
+ return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
4268
+ })(e);
4231
4269
  }
4232
4270
 
4233
- function _createClass(Constructor, protoProps, staticProps) {
4234
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
4235
- if (staticProps) _defineProperties(Constructor, staticProps);
4236
- return Constructor;
4271
+ function _classCallCheck(e, t) {
4272
+ if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
4237
4273
  }
4238
4274
 
4239
- function _defineProperty(obj, key, value) {
4240
- if (key in obj) {
4241
- Object.defineProperty(obj, key, {
4242
- value: value,
4243
- enumerable: true,
4244
- configurable: true,
4245
- writable: true
4246
- });
4247
- } else {
4248
- obj[key] = value;
4275
+ function _defineProperties(e, t) {
4276
+ for (var r = 0; r < t.length; r++) {
4277
+ var n = t[r];
4278
+ n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n);
4249
4279
  }
4250
-
4251
- return obj;
4252
4280
  }
4253
4281
 
4254
- function ownKeys(object, enumerableOnly) {
4255
- var keys = Object.keys(object);
4256
-
4257
- if (Object.getOwnPropertySymbols) {
4258
- var symbols = Object.getOwnPropertySymbols(object);
4259
- if (enumerableOnly) symbols = symbols.filter(function (sym) {
4260
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
4261
- });
4262
- keys.push.apply(keys, symbols);
4263
- }
4282
+ function _createClass(e, t, r) {
4283
+ return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), Object.defineProperty(e, "prototype", {
4284
+ writable: !1
4285
+ }), e;
4286
+ }
4264
4287
 
4265
- return keys;
4288
+ function _defineProperty(e, t, r) {
4289
+ return t in e ? Object.defineProperty(e, t, {
4290
+ value: r,
4291
+ enumerable: !0,
4292
+ configurable: !0,
4293
+ writable: !0
4294
+ }) : e[t] = r, e;
4266
4295
  }
4267
4296
 
4268
- function _objectSpread2(target) {
4269
- for (var i = 1; i < arguments.length; i++) {
4270
- var source = arguments[i] != null ? arguments[i] : {};
4297
+ function _slicedToArray(e, t) {
4298
+ return function _arrayWithHoles(e) {
4299
+ if (Array.isArray(e)) return e;
4300
+ }(e) || function _iterableToArrayLimit(e, t) {
4301
+ var r = null == e ? null : "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
4271
4302
 
4272
- if (i % 2) {
4273
- ownKeys(Object(source), true).forEach(function (key) {
4274
- _defineProperty(target, key, source[key]);
4275
- });
4276
- } else if (Object.getOwnPropertyDescriptors) {
4277
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
4278
- } else {
4279
- ownKeys(Object(source)).forEach(function (key) {
4280
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
4281
- });
4282
- }
4283
- }
4303
+ if (null != r) {
4304
+ var n,
4305
+ a,
4306
+ o = [],
4307
+ i = !0,
4308
+ s = !1;
4284
4309
 
4285
- return target;
4286
- }
4310
+ try {
4311
+ for (r = r.call(e); !(i = (n = r.next()).done) && (o.push(n.value), !t || o.length !== t); i = !0);
4312
+ } catch (e) {
4313
+ s = !0, a = e;
4314
+ } finally {
4315
+ try {
4316
+ i || null == r.return || r.return();
4317
+ } finally {
4318
+ if (s) throw a;
4319
+ }
4320
+ }
4287
4321
 
4288
- function _slicedToArray(arr, i) {
4289
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
4322
+ return o;
4323
+ }
4324
+ }(e, t) || _unsupportedIterableToArray(e, t) || function _nonIterableRest() {
4325
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4326
+ }();
4290
4327
  }
4291
4328
 
4292
- function _toConsumableArray(arr) {
4293
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
4329
+ function _unsupportedIterableToArray(e, t) {
4330
+ if (e) {
4331
+ if ("string" == typeof e) return _arrayLikeToArray(e, t);
4332
+ var r = Object.prototype.toString.call(e).slice(8, -1);
4333
+ return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0;
4334
+ }
4294
4335
  }
4295
4336
 
4296
- function _arrayWithoutHoles(arr) {
4297
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
4298
- }
4337
+ function _arrayLikeToArray(e, t) {
4338
+ (null == t || t > e.length) && (t = e.length);
4299
4339
 
4300
- function _arrayWithHoles(arr) {
4301
- if (Array.isArray(arr)) return arr;
4302
- }
4340
+ for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
4303
4341
 
4304
- function _iterableToArray(iter) {
4305
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
4342
+ return n;
4306
4343
  }
4307
4344
 
4308
- function _iterableToArrayLimit(arr, i) {
4309
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
4310
- var _arr = [];
4311
- var _n = true;
4312
- var _d = false;
4313
- var _e = undefined;
4345
+ var e = _createClass(function TypesonPromise(e) {
4346
+ _classCallCheck(this, TypesonPromise), this.p = new Promise(e);
4347
+ });
4314
4348
 
4315
- try {
4316
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
4317
- _arr.push(_s.value);
4349
+ e.__typeson__type__ = "TypesonPromise", "undefined" != typeof Symbol && (e.prototype[Symbol.toStringTag] = "TypesonPromise"), e.prototype.then = function (t, r) {
4350
+ var n = this;
4351
+ return new e(function (e, a) {
4352
+ n.p.then(function (r) {
4353
+ e(t ? t(r) : r);
4354
+ }).catch(function (e) {
4355
+ return r ? r(e) : Promise.reject(e);
4356
+ }).then(e, a);
4357
+ });
4358
+ }, e.prototype.catch = function (e) {
4359
+ return this.then(null, e);
4360
+ }, e.resolve = function (t) {
4361
+ return new e(function (e) {
4362
+ e(t);
4363
+ });
4364
+ }, e.reject = function (t) {
4365
+ return new e(function (e, r) {
4366
+ r(t);
4367
+ });
4368
+ }, ["all", "race", "allSettled"].forEach(function (t) {
4369
+ e[t] = function (r) {
4370
+ return new e(function (e, n) {
4371
+ Promise[t](r.map(function (e) {
4372
+ return e && e.constructor && "TypesonPromise" === e.constructor.__typeson__type__ ? e.p : e;
4373
+ })).then(e, n);
4374
+ });
4375
+ };
4376
+ });
4377
+ var t = {}.toString,
4378
+ r = {}.hasOwnProperty,
4379
+ n = Object.getPrototypeOf,
4380
+ a = r.toString;
4318
4381
 
4319
- if (i && _arr.length === i) break;
4320
- }
4321
- } catch (err) {
4322
- _d = true;
4323
- _e = err;
4324
- } finally {
4325
- try {
4326
- if (!_n && _i["return"] != null) _i["return"]();
4327
- } finally {
4328
- if (_d) throw _e;
4329
- }
4330
- }
4382
+ function isThenable(e, t) {
4383
+ return isObject(e) && "function" == typeof e.then && (!t || "function" == typeof e.catch);
4384
+ }
4331
4385
 
4332
- return _arr;
4386
+ function toStringTag(e) {
4387
+ return t.call(e).slice(8, -1);
4333
4388
  }
4334
4389
 
4335
- function _unsupportedIterableToArray(o, minLen) {
4336
- if (!o) return;
4337
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
4338
- var n = Object.prototype.toString.call(o).slice(8, -1);
4339
- if (n === "Object" && o.constructor) n = o.constructor.name;
4340
- if (n === "Map" || n === "Set") return Array.from(o);
4341
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
4390
+ function hasConstructorOf(e, t) {
4391
+ if (!e || "object" !== _typeof(e)) return !1;
4392
+ var o = n(e);
4393
+ if (!o) return null === t;
4394
+ var i = r.call(o, "constructor") && o.constructor;
4395
+ return "function" != typeof i ? null === t : t === i || null !== t && a.call(i) === a.call(t) || "function" == typeof t && "string" == typeof i.__typeson__type__ && i.__typeson__type__ === t.__typeson__type__;
4342
4396
  }
4343
4397
 
4344
- function _arrayLikeToArray(arr, len) {
4345
- if (len == null || len > arr.length) len = arr.length;
4398
+ function isPlainObject(e) {
4399
+ return !(!e || "Object" !== toStringTag(e)) && (!n(e) || hasConstructorOf(e, Object));
4400
+ }
4346
4401
 
4347
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
4402
+ function isUserObject(e) {
4403
+ if (!e || "Object" !== toStringTag(e)) return !1;
4404
+ var t = n(e);
4405
+ return !t || hasConstructorOf(e, Object) || isUserObject(t);
4406
+ }
4348
4407
 
4349
- return arr2;
4408
+ function isObject(e) {
4409
+ return e && "object" === _typeof(e);
4350
4410
  }
4351
4411
 
4352
- function _nonIterableSpread() {
4353
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4412
+ function escapeKeyPathComponent(e) {
4413
+ return e.replace(/~/g, "~0").replace(/\./g, "~1");
4354
4414
  }
4355
4415
 
4356
- function _nonIterableRest() {
4357
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4416
+ function unescapeKeyPathComponent(e) {
4417
+ return e.replace(/~1/g, ".").replace(/~0/g, "~");
4358
4418
  }
4359
- /**
4360
- * @callback TypesonFulfilled
4361
- * @returns {Promise<any>|any}
4362
- */
4363
4419
 
4364
- /**
4365
- * @callback TypesonRejected
4366
- * @returns {Promise<any>|any}
4367
- */
4420
+ function getByKeyPath(e, t) {
4421
+ if ("" === t) return e;
4422
+ var r = t.indexOf(".");
4368
4423
 
4369
- /**
4370
- * @callback TypesonResolve
4371
- * @param {any} value
4372
- * @returns {Promise<any>}
4373
- */
4424
+ if (r > -1) {
4425
+ var n = e[unescapeKeyPathComponent(t.slice(0, r))];
4426
+ return void 0 === n ? void 0 : getByKeyPath(n, t.slice(r + 1));
4427
+ }
4374
4428
 
4375
- /**
4376
- * @callback TypesonReject
4377
- * @param {Error|any} error
4378
- * @returns {Promise<any>}
4379
- */
4429
+ return e[unescapeKeyPathComponent(t)];
4430
+ }
4380
4431
 
4381
- /**
4382
- * @callback TypesonResolveReject
4383
- * @param {TypesonResolve} typesonResolve
4384
- * @param {TypesonReject} typesonReject
4385
- * @returns {Promise<any>}
4386
- */
4432
+ function setAtKeyPath(e, t, r) {
4433
+ if ("" === t) return r;
4434
+ var n = t.indexOf(".");
4435
+ return n > -1 ? setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0, n))], t.slice(n + 1), r) : (e[unescapeKeyPathComponent(t)] = r, e);
4436
+ }
4387
4437
 
4388
- /* eslint-disable block-spacing, space-before-function-paren,
4389
- space-before-blocks, space-infix-ops, semi, promise/avoid-new,
4390
- jsdoc/require-jsdoc */
4438
+ function getJSONType(e) {
4439
+ return null === e ? "null" : Array.isArray(e) ? "array" : _typeof(e);
4440
+ }
4391
4441
 
4392
- /**
4393
- * We keep this function minimized so if using two instances of this
4394
- * library, where one is minimized and one is not, it will still work
4395
- * with `hasConstructorOf`.
4396
- * With ES6 classes, we may be able to simply use `class TypesonPromise
4397
- * extends Promise` and add a string tag for detection.
4398
- * @param {TypesonResolveReject} f
4399
- */
4442
+ function _await(e, t, r) {
4443
+ return r ? t ? t(e) : e : (e && e.then || (e = Promise.resolve(e)), t ? e.then(t) : e);
4444
+ }
4400
4445
 
4446
+ var o = Object.keys,
4447
+ i = Array.isArray,
4448
+ s = {}.hasOwnProperty,
4449
+ c = ["type", "replaced", "iterateIn", "iterateUnsetNumeric"];
4401
4450
 
4402
- var TypesonPromise = function TypesonPromise(f) {
4403
- _classCallCheck(this, TypesonPromise);
4451
+ function _async(e) {
4452
+ return function () {
4453
+ for (var t = [], r = 0; r < arguments.length; r++) t[r] = arguments[r];
4404
4454
 
4405
- this.p = new Promise(f);
4406
- };
4407
- /* eslint-enable block-spacing, space-before-function-paren,
4408
- space-before-blocks, space-infix-ops, semi, promise/avoid-new,
4409
- jsdoc/require-jsdoc */
4410
- // eslint-disable-next-line max-len
4411
- // class TypesonPromise extends Promise {get[Symbol.toStringTag](){return 'TypesonPromise'};} // eslint-disable-line keyword-spacing, space-before-function-paren, space-before-blocks, block-spacing, semi
4455
+ try {
4456
+ return Promise.resolve(e.apply(this, t));
4457
+ } catch (e) {
4458
+ return Promise.reject(e);
4459
+ }
4460
+ };
4461
+ }
4412
4462
 
4463
+ function nestedPathsFirst(e, t) {
4464
+ if ("" === e.keypath) return -1;
4465
+ var r = e.keypath.match(/\./g) || 0,
4466
+ n = t.keypath.match(/\./g) || 0;
4467
+ return r && (r = r.length), n && (n = n.length), r > n ? -1 : r < n ? 1 : e.keypath < t.keypath ? -1 : e.keypath > t.keypath;
4468
+ }
4413
4469
 
4414
- TypesonPromise.__typeson__type__ = 'TypesonPromise'; // Note: core-js-bundle provides a `Symbol` polyfill
4470
+ var u = function () {
4471
+ function Typeson(e) {
4472
+ _classCallCheck(this, Typeson), this.options = e, this.plainObjectReplacers = [], this.nonplainObjectReplacers = [], this.revivers = {}, this.types = {};
4473
+ }
4415
4474
 
4416
- /* istanbul ignore else */
4475
+ return _createClass(Typeson, [{
4476
+ key: "stringify",
4477
+ value: function stringify(e, t, r, n) {
4478
+ n = _objectSpread2(_objectSpread2(_objectSpread2({}, this.options), n), {}, {
4479
+ stringification: !0
4480
+ });
4481
+ var a = this.encapsulate(e, null, n);
4482
+ return i(a) ? JSON.stringify(a[0], t, r) : a.then(function (e) {
4483
+ return JSON.stringify(e, t, r);
4484
+ });
4485
+ }
4486
+ }, {
4487
+ key: "stringifySync",
4488
+ value: function stringifySync(e, t, r, n) {
4489
+ return this.stringify(e, t, r, _objectSpread2(_objectSpread2({
4490
+ throwOnBadSyncType: !0
4491
+ }, n), {}, {
4492
+ sync: !0
4493
+ }));
4494
+ }
4495
+ }, {
4496
+ key: "stringifyAsync",
4497
+ value: function stringifyAsync(e, t, r, n) {
4498
+ return this.stringify(e, t, r, _objectSpread2(_objectSpread2({
4499
+ throwOnBadSyncType: !0
4500
+ }, n), {}, {
4501
+ sync: !1
4502
+ }));
4503
+ }
4504
+ }, {
4505
+ key: "parse",
4506
+ value: function parse(e, t, r) {
4507
+ return r = _objectSpread2(_objectSpread2(_objectSpread2({}, this.options), r), {}, {
4508
+ parse: !0
4509
+ }), this.revive(JSON.parse(e, t), r);
4510
+ }
4511
+ }, {
4512
+ key: "parseSync",
4513
+ value: function parseSync(e, t, r) {
4514
+ return this.parse(e, t, _objectSpread2(_objectSpread2({
4515
+ throwOnBadSyncType: !0
4516
+ }, r), {}, {
4517
+ sync: !0
4518
+ }));
4519
+ }
4520
+ }, {
4521
+ key: "parseAsync",
4522
+ value: function parseAsync(e, t, r) {
4523
+ return this.parse(e, t, _objectSpread2(_objectSpread2({
4524
+ throwOnBadSyncType: !0
4525
+ }, r), {}, {
4526
+ sync: !1
4527
+ }));
4528
+ }
4529
+ }, {
4530
+ key: "specialTypeNames",
4531
+ value: function specialTypeNames(e, t) {
4532
+ var r = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
4533
+ return r.returnTypeNames = !0, this.encapsulate(e, t, r);
4534
+ }
4535
+ }, {
4536
+ key: "rootTypeName",
4537
+ value: function rootTypeName(e, t) {
4538
+ var r = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
4539
+ return r.iterateNone = !0, this.encapsulate(e, t, r);
4540
+ }
4541
+ }, {
4542
+ key: "encapsulate",
4543
+ value: function encapsulate(t, r, n) {
4544
+ var a = _async(function (t, r) {
4545
+ return _await(Promise.all(r.map(function (e) {
4546
+ return e[1].p;
4547
+ })), function (n) {
4548
+ return _await(Promise.all(n.map(_async(function (n) {
4549
+ var o = !1,
4550
+ i = [],
4551
+ s = _slicedToArray(r.splice(0, 1), 1),
4552
+ c = _slicedToArray(s[0], 7),
4553
+ u = c[0],
4554
+ l = c[2],
4555
+ f = c[3],
4556
+ y = c[4],
4557
+ p = c[5],
4558
+ d = c[6],
4559
+ v = _encapsulate(u, n, l, f, i, !0, d),
4560
+ b = hasConstructorOf(v, e);
4561
+
4562
+ return function _invoke(e, t) {
4563
+ var r = e();
4564
+ return r && r.then ? r.then(t) : t(r);
4565
+ }(function () {
4566
+ if (u && b) return _await(v.p, function (e) {
4567
+ y[p] = e;
4568
+ var r = a(t, i);
4569
+ return o = !0, r;
4570
+ });
4571
+ }, function (e) {
4572
+ return o ? e : (u ? y[p] = v : t = b ? v.p : v, a(t, i));
4573
+ });
4574
+ }))), function () {
4575
+ return t;
4576
+ });
4577
+ });
4578
+ }),
4579
+ u = (n = _objectSpread2(_objectSpread2({
4580
+ sync: !0
4581
+ }, this.options), n)).sync,
4582
+ l = this,
4583
+ f = {},
4584
+ y = [],
4585
+ p = [],
4586
+ d = [],
4587
+ v = !("cyclic" in n) || n.cyclic,
4588
+ b = n.encapsulateObserver,
4589
+ h = _encapsulate("", t, v, r || {}, d);
4590
+
4591
+ function finish(e) {
4592
+ var t = Object.values(f);
4593
+ if (n.iterateNone) return t.length ? t[0] : getJSONType(e);
4594
+
4595
+ if (t.length) {
4596
+ if (n.returnTypeNames) return function _toConsumableArray(e) {
4597
+ return function _arrayWithoutHoles(e) {
4598
+ if (Array.isArray(e)) return _arrayLikeToArray(e);
4599
+ }(e) || function _iterableToArray(e) {
4600
+ if ("undefined" != typeof Symbol && null != e[Symbol.iterator] || null != e["@@iterator"]) return Array.from(e);
4601
+ }(e) || _unsupportedIterableToArray(e) || function _nonIterableSpread() {
4602
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4603
+ }();
4604
+ }(new Set(t));
4605
+ e && isPlainObject(e) && !s.call(e, "$types") ? e.$types = f : e = {
4606
+ $: e,
4607
+ $types: {
4608
+ $: f
4609
+ }
4610
+ };
4611
+ } else isObject(e) && s.call(e, "$types") && (e = {
4612
+ $: e,
4613
+ $types: !0
4614
+ });
4417
4615
 
4418
- if (typeof Symbol !== 'undefined') {
4419
- // Ensure `isUserObject` will return `false` for `TypesonPromise`
4420
- TypesonPromise.prototype[Symbol.toStringTag] = 'TypesonPromise';
4421
- }
4422
- /**
4423
- *
4424
- * @param {TypesonFulfilled} [onFulfilled]
4425
- * @param {TypesonRejected} [onRejected]
4426
- * @returns {TypesonPromise}
4427
- */
4616
+ return !n.returnTypeNames && e;
4617
+ }
4428
4618
 
4619
+ function _adaptBuiltinStateObjectProperties(e, t, r) {
4620
+ Object.assign(e, t);
4621
+ var n = c.map(function (t) {
4622
+ var r = e[t];
4623
+ return delete e[t], r;
4624
+ });
4625
+ r(), c.forEach(function (t, r) {
4626
+ e[t] = n[r];
4627
+ });
4628
+ }
4429
4629
 
4430
- TypesonPromise.prototype.then = function (onFulfilled, onRejected) {
4431
- var _this = this;
4630
+ function _encapsulate(t, r, a, c, u, d, v) {
4631
+ var h,
4632
+ g = {},
4633
+ m = _typeof(r),
4634
+ O = b ? function (n) {
4635
+ var o = v || c.type || getJSONType(r);
4636
+ b(Object.assign(n || g, {
4637
+ keypath: t,
4638
+ value: r,
4639
+ cyclic: a,
4640
+ stateObj: c,
4641
+ promisesData: u,
4642
+ resolvingTypesonPromise: d,
4643
+ awaitingTypesonPromise: hasConstructorOf(r, e)
4644
+ }, {
4645
+ type: o
4646
+ }));
4647
+ } : null;
4432
4648
 
4433
- return new TypesonPromise(function (typesonResolve, typesonReject) {
4434
- // eslint-disable-next-line promise/catch-or-return
4435
- _this.p.then(function (res) {
4436
- // eslint-disable-next-line promise/always-return
4437
- typesonResolve(onFulfilled ? onFulfilled(res) : res);
4438
- })["catch"](function (res) {
4439
- return onRejected ? onRejected(res) : Promise.reject(res);
4440
- }).then(typesonResolve, typesonReject);
4441
- });
4442
- };
4443
- /**
4444
- *
4445
- * @param {TypesonRejected} onRejected
4446
- * @returns {TypesonPromise}
4447
- */
4649
+ if (["string", "boolean", "number", "undefined"].includes(m)) return void 0 === r || Number.isNaN(r) || r === Number.NEGATIVE_INFINITY || r === Number.POSITIVE_INFINITY ? (h = c.replaced ? r : replace(t, r, c, u, !1, d, O)) !== r && (g = {
4650
+ replaced: h
4651
+ }) : h = r, O && O(), h;
4652
+ if (null === r) return O && O(), r;
4653
+
4654
+ if (a && !c.iterateIn && !c.iterateUnsetNumeric && r && "object" === _typeof(r)) {
4655
+ var S = y.indexOf(r);
4656
+ if (!(S < 0)) return f[t] = "#", O && O({
4657
+ cyclicKeypath: p[S]
4658
+ }), "#" + p[S];
4659
+ !0 === a && (y.push(r), p.push(t));
4660
+ }
4448
4661
 
4662
+ var _,
4663
+ w = isPlainObject(r),
4664
+ A = i(r),
4665
+ j = (w || A) && (!l.plainObjectReplacers.length || c.replaced) || c.iterateIn ? r : replace(t, r, c, u, w || A, null, O);
4666
+
4667
+ if (j !== r ? (h = j, g = {
4668
+ replaced: j
4669
+ }) : "" === t && hasConstructorOf(r, e) ? (u.push([t, r, a, c, void 0, void 0, c.type]), h = r) : A && "object" !== c.iterateIn || "array" === c.iterateIn ? (_ = new Array(r.length), g = {
4670
+ clone: _
4671
+ }) : (["function", "symbol"].includes(_typeof(r)) || "toJSON" in r || hasConstructorOf(r, e) || hasConstructorOf(r, Promise) || hasConstructorOf(r, ArrayBuffer)) && !w && "object" !== c.iterateIn ? h = r : (_ = {}, c.addLength && (_.length = r.length), g = {
4672
+ clone: _
4673
+ }), O && O(), n.iterateNone) return _ || h;
4674
+ if (!_) return h;
4675
+
4676
+ if (c.iterateIn) {
4677
+ var T = function _loop(n) {
4678
+ var o = {
4679
+ ownKeys: s.call(r, n)
4680
+ };
4449
4681
 
4450
- TypesonPromise.prototype["catch"] = function (onRejected) {
4451
- return this.then(null, onRejected);
4452
- };
4453
- /**
4454
- *
4455
- * @param {any} v
4456
- * @returns {TypesonPromise}
4457
- */
4682
+ _adaptBuiltinStateObjectProperties(c, o, function () {
4683
+ var o = t + (t ? "." : "") + escapeKeyPathComponent(n),
4684
+ i = _encapsulate(o, r[n], Boolean(a), c, u, d);
4458
4685
 
4686
+ hasConstructorOf(i, e) ? u.push([o, i, Boolean(a), c, _, n, c.type]) : void 0 !== i && (_[n] = i);
4687
+ });
4688
+ };
4459
4689
 
4460
- TypesonPromise.resolve = function (v) {
4461
- return new TypesonPromise(function (typesonResolve) {
4462
- typesonResolve(v);
4463
- });
4464
- };
4465
- /**
4466
- *
4467
- * @param {any} v
4468
- * @returns {TypesonPromise}
4469
- */
4690
+ for (var I in r) T(I);
4470
4691
 
4692
+ O && O({
4693
+ endIterateIn: !0,
4694
+ end: !0
4695
+ });
4696
+ } else o(r).forEach(function (n) {
4697
+ var o = t + (t ? "." : "") + escapeKeyPathComponent(n);
4471
4698
 
4472
- TypesonPromise.reject = function (v) {
4473
- return new TypesonPromise(function (typesonResolve, typesonReject) {
4474
- typesonReject(v);
4475
- });
4476
- };
4699
+ _adaptBuiltinStateObjectProperties(c, {
4700
+ ownKeys: !0
4701
+ }, function () {
4702
+ var t = _encapsulate(o, r[n], Boolean(a), c, u, d);
4477
4703
 
4478
- ['all', 'race', 'allSettled'].forEach(function (meth) {
4479
- /**
4480
- *
4481
- * @param {Promise<any>[]} promArr
4482
- * @returns {TypesonPromise}
4483
- */
4484
- TypesonPromise[meth] = function (promArr) {
4485
- return new TypesonPromise(function (typesonResolve, typesonReject) {
4486
- // eslint-disable-next-line promise/catch-or-return
4487
- Promise[meth](promArr.map(function (prom) {
4488
- return prom && prom.constructor && prom.constructor.__typeson__type__ === 'TypesonPromise' ? prom.p : prom;
4489
- })).then(typesonResolve, typesonReject);
4490
- });
4491
- };
4492
- });
4493
- var _ref = {},
4494
- toStr = _ref.toString,
4495
- hasOwn$1 = {}.hasOwnProperty,
4496
- getProto = Object.getPrototypeOf,
4497
- fnToString = hasOwn$1.toString;
4498
- /**
4499
- * Second argument not in use internally, but provided for utility.
4500
- * @param {any} v
4501
- * @param {boolean} catchCheck
4502
- * @returns {boolean}
4503
- */
4704
+ hasConstructorOf(t, e) ? u.push([o, t, Boolean(a), c, _, n, c.type]) : void 0 !== t && (_[n] = t);
4705
+ });
4706
+ }), O && O({
4707
+ endIterateOwn: !0,
4708
+ end: !0
4709
+ });
4504
4710
 
4505
- function isThenable(v, catchCheck) {
4506
- return isObject(v) && typeof v.then === 'function' && (!catchCheck || typeof v["catch"] === 'function');
4507
- }
4508
- /**
4509
- *
4510
- * @param {any} val
4511
- * @returns {string}
4512
- */
4711
+ if (c.iterateUnsetNumeric) {
4712
+ for (var P = r.length, N = function _loop2(n) {
4713
+ if (!(n in r)) {
4714
+ var o = t + (t ? "." : "") + n;
4513
4715
 
4716
+ _adaptBuiltinStateObjectProperties(c, {
4717
+ ownKeys: !1
4718
+ }, function () {
4719
+ var t = _encapsulate(o, void 0, Boolean(a), c, u, d);
4514
4720
 
4515
- function toStringTag(val) {
4516
- return toStr.call(val).slice(8, -1);
4517
- }
4518
- /**
4519
- * This function is dependent on both constructors
4520
- * being identical so any minimization is expected of both.
4521
- * @param {any} a
4522
- * @param {GenericFunction} b
4523
- * @returns {boolean}
4524
- */
4721
+ hasConstructorOf(t, e) ? u.push([o, t, Boolean(a), c, _, n, c.type]) : void 0 !== t && (_[n] = t);
4722
+ });
4723
+ }
4724
+ }, C = 0; C < P; C++) N(C);
4525
4725
 
4726
+ O && O({
4727
+ endIterateUnsetNumeric: !0,
4728
+ end: !0
4729
+ });
4730
+ }
4526
4731
 
4527
- function hasConstructorOf(a, b) {
4528
- if (!a || _typeof(a) !== 'object') {
4529
- return false;
4530
- }
4732
+ return _;
4733
+ }
4531
4734
 
4532
- var proto = getProto(a);
4735
+ function replace(e, t, r, n, a, o, i) {
4736
+ for (var s = a ? l.plainObjectReplacers : l.nonplainObjectReplacers, c = s.length; c--;) {
4737
+ var y = s[c];
4533
4738
 
4534
- if (!proto) {
4535
- return b === null;
4536
- }
4739
+ if (y.test(t, r)) {
4740
+ var p = y.type;
4537
4741
 
4538
- var Ctor = hasOwn$1.call(proto, 'constructor') && proto.constructor;
4742
+ if (l.revivers[p]) {
4743
+ var d = f[e];
4744
+ f[e] = d ? [p].concat(d) : p;
4745
+ }
4539
4746
 
4540
- if (typeof Ctor !== 'function') {
4541
- return b === null;
4542
- }
4747
+ return Object.assign(r, {
4748
+ type: p,
4749
+ replaced: !0
4750
+ }), !u && y.replaceAsync || y.replace ? (i && i({
4751
+ replacing: !0
4752
+ }), _encapsulate(e, y[u || !y.replaceAsync ? "replace" : "replaceAsync"](t, r), v && "readonly", r, n, o, p)) : (i && i({
4753
+ typeDetected: !0
4754
+ }), _encapsulate(e, t, v && "readonly", r, n, o, p));
4755
+ }
4756
+ }
4543
4757
 
4544
- if (b === Ctor) {
4545
- return true;
4546
- }
4758
+ return t;
4759
+ }
4547
4760
 
4548
- if (b !== null && fnToString.call(Ctor) === fnToString.call(b)) {
4549
- return true;
4550
- }
4761
+ return d.length ? u && n.throwOnBadSyncType ? function () {
4762
+ throw new TypeError("Sync method requested but async result obtained");
4763
+ }() : Promise.resolve(a(h, d)).then(finish) : !u && n.throwOnBadSyncType ? function () {
4764
+ throw new TypeError("Async method requested but sync result obtained");
4765
+ }() : n.stringification && u ? [finish(h)] : u ? finish(h) : Promise.resolve(finish(h));
4766
+ }
4767
+ }, {
4768
+ key: "encapsulateSync",
4769
+ value: function encapsulateSync(e, t, r) {
4770
+ return this.encapsulate(e, t, _objectSpread2(_objectSpread2({
4771
+ throwOnBadSyncType: !0
4772
+ }, r), {}, {
4773
+ sync: !0
4774
+ }));
4775
+ }
4776
+ }, {
4777
+ key: "encapsulateAsync",
4778
+ value: function encapsulateAsync(e, t, r) {
4779
+ return this.encapsulate(e, t, _objectSpread2(_objectSpread2({
4780
+ throwOnBadSyncType: !0
4781
+ }, r), {}, {
4782
+ sync: !1
4783
+ }));
4784
+ }
4785
+ }, {
4786
+ key: "revive",
4787
+ value: function revive(t, r) {
4788
+ var n = t && t.$types;
4789
+ if (!n) return t;
4790
+ if (!0 === n) return t.$;
4551
4791
 
4552
- if (typeof b === 'function' && typeof Ctor.__typeson__type__ === 'string' && Ctor.__typeson__type__ === b.__typeson__type__) {
4553
- return true;
4554
- }
4792
+ var a = (r = _objectSpread2(_objectSpread2({
4793
+ sync: !0
4794
+ }, this.options), r)).sync,
4795
+ s = [],
4796
+ c = {},
4797
+ u = !0;
4555
4798
 
4556
- return false;
4557
- }
4558
- /**
4559
- *
4560
- * @param {any} val
4561
- * @returns {boolean}
4562
- */
4799
+ n.$ && isPlainObject(n.$) && (t = t.$, n = n.$, u = !1);
4800
+ var f = this;
4563
4801
 
4802
+ function executeReviver(e, t) {
4803
+ var r = _slicedToArray(f.revivers[e] || [], 1)[0];
4564
4804
 
4565
- function isPlainObject(val) {
4566
- // Mirrors jQuery's
4567
- if (!val || toStringTag(val) !== 'Object') {
4568
- return false;
4569
- }
4805
+ if (!r) throw new Error("Unregistered type: " + e);
4806
+ return a && !("revive" in r) ? t : r[a && r.revive ? "revive" : !a && r.reviveAsync ? "reviveAsync" : "revive"](t, c);
4807
+ }
4570
4808
 
4571
- var proto = getProto(val);
4809
+ var y = [];
4572
4810
 
4573
- if (!proto) {
4574
- // `Object.create(null)`
4575
- return true;
4576
- }
4811
+ function checkUndefined(e) {
4812
+ return hasConstructorOf(e, l) ? void 0 : e;
4813
+ }
4577
4814
 
4578
- return hasConstructorOf(val, Object);
4579
- }
4580
- /**
4581
- *
4582
- * @param {any} val
4583
- * @returns {boolean}
4584
- */
4815
+ var p,
4816
+ d = function revivePlainObjects() {
4817
+ var r = [];
4818
+ if (Object.entries(n).forEach(function (e) {
4819
+ var t = _slicedToArray(e, 2),
4820
+ a = t[0],
4821
+ o = t[1];
4585
4822
 
4823
+ "#" !== o && [].concat(o).forEach(function (e) {
4824
+ _slicedToArray(f.revivers[e] || [null, {}], 2)[1].plain && (r.push({
4825
+ keypath: a,
4826
+ type: e
4827
+ }), delete n[a]);
4828
+ });
4829
+ }), r.length) return r.sort(nestedPathsFirst).reduce(function reducer(r, n) {
4830
+ var a = n.keypath,
4831
+ o = n.type;
4832
+ if (isThenable(r)) return r.then(function (e) {
4833
+ return reducer(e, {
4834
+ keypath: a,
4835
+ type: o
4836
+ });
4837
+ });
4838
+ var i = getByKeyPath(t, a);
4839
+ if (hasConstructorOf(i = executeReviver(o, i), e)) return i.then(function (e) {
4840
+ var r = setAtKeyPath(t, a, e);
4841
+ r === e && (t = r);
4842
+ });
4843
+ var s = setAtKeyPath(t, a, i);
4844
+ s === i && (t = s);
4845
+ }, void 0);
4846
+ }();
4847
+
4848
+ return hasConstructorOf(d, e) ? p = d.then(function () {
4849
+ return t;
4850
+ }) : (p = function _revive(t, r, a, c, f) {
4851
+ if (!u || "$types" !== t) {
4852
+ var p = n[t],
4853
+ d = i(r);
4854
+
4855
+ if (d || isPlainObject(r)) {
4856
+ var v = d ? new Array(r.length) : {};
4857
+
4858
+ for (o(r).forEach(function (n) {
4859
+ var o = _revive(t + (t ? "." : "") + escapeKeyPathComponent(n), r[n], a || v, v, n),
4860
+ i = function set(e) {
4861
+ return hasConstructorOf(e, l) ? v[n] = void 0 : void 0 !== e && (v[n] = e), e;
4862
+ };
4586
4863
 
4587
- function isUserObject(val) {
4588
- if (!val || toStringTag(val) !== 'Object') {
4589
- return false;
4590
- }
4864
+ hasConstructorOf(o, e) ? y.push(o.then(function (e) {
4865
+ return i(e);
4866
+ })) : i(o);
4867
+ }), r = v; s.length;) {
4868
+ var b = _slicedToArray(s[0], 4),
4869
+ h = b[0],
4870
+ g = b[1],
4871
+ m = b[2],
4872
+ O = b[3],
4873
+ S = getByKeyPath(h, g);
4874
+
4875
+ if (void 0 === S) break;
4876
+ m[O] = S, s.splice(0, 1);
4877
+ }
4878
+ }
4591
4879
 
4592
- var proto = getProto(val);
4880
+ if (!p) return r;
4593
4881
 
4594
- if (!proto) {
4595
- // `Object.create(null)`
4596
- return true;
4597
- }
4882
+ if ("#" === p) {
4883
+ var _ = getByKeyPath(a, r.slice(1));
4598
4884
 
4599
- return hasConstructorOf(val, Object) || isUserObject(proto);
4600
- }
4601
- /**
4602
- *
4603
- * @param {any} v
4604
- * @returns {boolean}
4605
- */
4606
-
4607
-
4608
- function isObject(v) {
4609
- return v && _typeof(v) === 'object';
4610
- }
4611
- /**
4612
- *
4613
- * @param {string} keyPathComponent
4614
- * @returns {string}
4615
- */
4616
-
4617
-
4618
- function escapeKeyPathComponent(keyPathComponent) {
4619
- return keyPathComponent.replace(/~/g, '~0').replace(/\./g, '~1');
4620
- }
4621
- /**
4622
- *
4623
- * @param {string} keyPathComponent
4624
- * @returns {string}
4625
- */
4626
-
4627
-
4628
- function unescapeKeyPathComponent(keyPathComponent) {
4629
- return keyPathComponent.replace(/~1/g, '.').replace(/~0/g, '~');
4630
- }
4631
- /**
4632
- * @param {PlainObject|GenericArray} obj
4633
- * @param {string} keyPath
4634
- * @returns {any}
4635
- */
4636
-
4637
-
4638
- function getByKeyPath(obj, keyPath) {
4639
- if (keyPath === '') {
4640
- return obj;
4641
- }
4642
-
4643
- var period = keyPath.indexOf('.');
4644
-
4645
- if (period > -1) {
4646
- var innerObj = obj[unescapeKeyPathComponent(keyPath.slice(0, period))];
4647
- return innerObj === undefined ? undefined : getByKeyPath(innerObj, keyPath.slice(period + 1));
4648
- }
4649
-
4650
- return obj[unescapeKeyPathComponent(keyPath)];
4651
- }
4652
- /**
4653
- *
4654
- * @param {PlainObject} obj
4655
- * @param {string} keyPath
4656
- * @param {any} value
4657
- * @returns {any}
4658
- */
4659
-
4660
-
4661
- function setAtKeyPath(obj, keyPath, value) {
4662
- if (keyPath === '') {
4663
- return value;
4664
- }
4665
-
4666
- var period = keyPath.indexOf('.');
4667
-
4668
- if (period > -1) {
4669
- var innerObj = obj[unescapeKeyPathComponent(keyPath.slice(0, period))];
4670
- return setAtKeyPath(innerObj, keyPath.slice(period + 1), value);
4671
- }
4672
-
4673
- obj[unescapeKeyPathComponent(keyPath)] = value;
4674
- return obj;
4675
- }
4676
- /**
4677
- *
4678
- * @param {external:JSON} value
4679
- * @returns {"null"|"array"|"undefined"|"boolean"|"number"|"string"|
4680
- * "object"|"symbol"}
4681
- */
4682
-
4683
-
4684
- function getJSONType(value) {
4685
- return value === null ? 'null' : Array.isArray(value) ? 'array' : _typeof(value);
4686
- }
4687
-
4688
- function _await(value, then, direct) {
4689
- if (direct) {
4690
- return then ? then(value) : value;
4691
- }
4692
-
4693
- if (!value || !value.then) {
4694
- value = Promise.resolve(value);
4695
- }
4696
-
4697
- return then ? value.then(then) : value;
4698
- }
4699
-
4700
- var keys = Object.keys,
4701
- isArray = Array.isArray,
4702
- hasOwn = {}.hasOwnProperty,
4703
- internalStateObjPropsToIgnore = ['type', 'replaced', 'iterateIn', 'iterateUnsetNumeric'];
4704
- /**
4705
- * Handle plain object revivers first so reference setting can use
4706
- * revived type (e.g., array instead of object); assumes revived
4707
- * has same structure or will otherwise break subsequent references.
4708
- * @param {PlainObjectType} a
4709
- * @param {PlainObjectType} b
4710
- * @returns {1|-1|boolean}
4711
- */
4712
-
4713
- function _async(f) {
4714
- return function () {
4715
- for (var args = [], i = 0; i < arguments.length; i++) {
4716
- args[i] = arguments[i];
4717
- }
4718
-
4719
- try {
4720
- return Promise.resolve(f.apply(this, args));
4721
- } catch (e) {
4722
- return Promise.reject(e);
4723
- }
4724
- };
4725
- }
4726
- /**
4727
- * @callback Tester
4728
- * @param {any} value
4729
- * @param {StateObject} stateobj
4730
- * @returns {boolean}
4731
- */
4732
-
4733
- /**
4734
- * @callback Replacer
4735
- * @param {any} value
4736
- * @param {StateObject} stateObj
4737
- * @returns {any} Should be JSON-stringifiable
4738
- */
4739
-
4740
- /**
4741
- * @callback Reviver
4742
- * @param {JSON} value
4743
- * @param {StateObject} stateObj
4744
- * @returns {any}
4745
- */
4746
-
4747
- /**
4748
- * @typedef {PlainObject} TypesonOptions
4749
- * @property {boolean} stringification Auto-set by `stringify`
4750
- */
4751
-
4752
- /**
4753
- * An instance of this class can be used to call `stringify()` and `parse()`.
4754
- * Typeson resolves cyclic references by default. Can also be extended to
4755
- * support custom types using the register() method.
4756
- *
4757
- * @class
4758
- * @param {{cyclic: boolean}} [options] - if cyclic (default true),
4759
- * cyclic references will be handled gracefully.
4760
- */
4761
-
4762
-
4763
- function _invoke(body, then) {
4764
- var result = body();
4765
-
4766
- if (result && result.then) {
4767
- return result.then(then);
4768
- }
4769
-
4770
- return then(result);
4771
- }
4772
-
4773
- function nestedPathsFirst(a, b) {
4774
- if (a.keypath === '') {
4775
- return -1;
4776
- }
4777
-
4778
- var as = a.keypath.match(/\./g) || 0;
4779
- var bs = b.keypath.match(/\./g) || 0;
4780
-
4781
- if (as) {
4782
- as = as.length;
4783
- }
4784
-
4785
- if (bs) {
4786
- bs = bs.length;
4787
- }
4788
-
4789
- return as > bs ? -1 : as < bs ? 1 : a.keypath < b.keypath ? -1 : a.keypath > b.keypath;
4790
- }
4791
-
4792
- var Typeson = /*#__PURE__*/function () {
4793
- /**
4794
- * @param {TypesonOptions} options
4795
- */
4796
- function Typeson(options) {
4797
- _classCallCheck(this, Typeson);
4798
-
4799
- this.options = options; // Replacers signature: replace (value). Returns falsy if not
4800
- // replacing. Otherwise ['Date', value.getTime()]
4801
-
4802
- this.plainObjectReplacers = [];
4803
- this.nonplainObjectReplacers = []; // Revivers: [{type => reviver}, {plain: boolean}].
4804
- // Sample: [{'Date': value => new Date(value)}, {plain: false}]
4805
-
4806
- this.revivers = {};
4807
- /** Types registered via `register()`. */
4808
-
4809
- this.types = {};
4810
- }
4811
- /**
4812
- * @typedef {null|boolean|number|string|GenericArray|PlainObject} JSON
4813
- */
4814
-
4815
- /**
4816
- * @callback JSONReplacer
4817
- * @param {""|string} key
4818
- * @param {JSON} value
4819
- * @returns {number|string|boolean|null|PlainObject|undefined}
4820
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The%20replacer%20parameter
4821
- */
4822
-
4823
- /**
4824
- * Serialize given object to Typeson.
4825
- * Initial arguments work identical to those of `JSON.stringify`.
4826
- * The `replacer` argument has nothing to do with our replacers.
4827
- * @param {any} obj
4828
- * @param {JSONReplacer|string[]} replacer
4829
- * @param {number|string} space
4830
- * @param {TypesonOptions} opts
4831
- * @returns {string|Promise<string>} Promise resolves to a string
4832
- */
4833
-
4834
-
4835
- _createClass(Typeson, [{
4836
- key: "stringify",
4837
- value: function stringify(obj, replacer, space, opts) {
4838
- opts = _objectSpread2(_objectSpread2(_objectSpread2({}, this.options), opts), {}, {
4839
- stringification: true
4840
- });
4841
- var encapsulated = this.encapsulate(obj, null, opts);
4842
-
4843
- if (isArray(encapsulated)) {
4844
- return JSON.stringify(encapsulated[0], replacer, space);
4845
- }
4846
-
4847
- return encapsulated.then(function (res) {
4848
- return JSON.stringify(res, replacer, space);
4849
- });
4850
- }
4851
- /**
4852
- * Also sync but throws on non-sync result.
4853
- * @param {any} obj
4854
- * @param {JSONReplacer|string[]} replacer
4855
- * @param {number|string} space
4856
- * @param {TypesonOptions} opts
4857
- * @returns {string}
4858
- */
4859
-
4860
- }, {
4861
- key: "stringifySync",
4862
- value: function stringifySync(obj, replacer, space, opts) {
4863
- return this.stringify(obj, replacer, space, _objectSpread2(_objectSpread2({
4864
- throwOnBadSyncType: true
4865
- }, opts), {}, {
4866
- sync: true
4867
- }));
4868
- }
4869
- /**
4870
- *
4871
- * @param {any} obj
4872
- * @param {JSONReplacer|string[]} replacer
4873
- * @param {number|string} space
4874
- * @param {TypesonOptions} opts
4875
- * @returns {Promise<string>}
4876
- */
4877
-
4878
- }, {
4879
- key: "stringifyAsync",
4880
- value: function stringifyAsync(obj, replacer, space, opts) {
4881
- return this.stringify(obj, replacer, space, _objectSpread2(_objectSpread2({
4882
- throwOnBadSyncType: true
4883
- }, opts), {}, {
4884
- sync: false
4885
- }));
4886
- }
4887
- /**
4888
- * @callback JSONReviver
4889
- * @param {string} key
4890
- * @param {JSON} value
4891
- * @returns {JSON}
4892
- */
4893
-
4894
- /**
4895
- * Parse Typeson back into an obejct.
4896
- * Initial arguments works identical to those of `JSON.parse()`.
4897
- * @param {string} text
4898
- * @param {JSONReviver} reviver This JSON reviver has nothing to do with
4899
- * our revivers.
4900
- * @param {TypesonOptions} opts
4901
- * @returns {external:JSON}
4902
- */
4903
-
4904
- }, {
4905
- key: "parse",
4906
- value: function parse(text, reviver, opts) {
4907
- opts = _objectSpread2(_objectSpread2(_objectSpread2({}, this.options), opts), {}, {
4908
- parse: true
4909
- });
4910
- return this.revive(JSON.parse(text, reviver), opts);
4911
- }
4912
- /**
4913
- * Also sync but throws on non-sync result.
4914
- * @param {string} text
4915
- * @param {JSONReviver} reviver This JSON reviver has nothing to do with
4916
- * our revivers.
4917
- * @param {TypesonOptions} opts
4918
- * @returns {external:JSON}
4919
- */
4920
-
4921
- }, {
4922
- key: "parseSync",
4923
- value: function parseSync(text, reviver, opts) {
4924
- return this.parse(text, reviver, _objectSpread2(_objectSpread2({
4925
- throwOnBadSyncType: true
4926
- }, opts), {}, {
4927
- sync: true
4928
- }));
4929
- }
4930
- /**
4931
- * @param {string} text
4932
- * @param {JSONReviver} reviver This JSON reviver has nothing to do with
4933
- * our revivers.
4934
- * @param {TypesonOptions} opts
4935
- * @returns {Promise<external:JSON>} Resolves to `external:JSON`
4936
- */
4937
-
4938
- }, {
4939
- key: "parseAsync",
4940
- value: function parseAsync(text, reviver, opts) {
4941
- return this.parse(text, reviver, _objectSpread2(_objectSpread2({
4942
- throwOnBadSyncType: true
4943
- }, opts), {}, {
4944
- sync: false
4945
- }));
4946
- }
4947
- /**
4948
- * @typedef {} StateObject
4949
- */
4950
-
4951
- /**
4952
- *
4953
- * @param {any} obj
4954
- * @param {StateObject} stateObj
4955
- * @param {TypesonOptions} [opts={}]
4956
- * @returns {string[]|false}
4957
- */
4958
-
4959
- }, {
4960
- key: "specialTypeNames",
4961
- value: function specialTypeNames(obj, stateObj) {
4962
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4963
- opts.returnTypeNames = true;
4964
- return this.encapsulate(obj, stateObj, opts);
4965
- }
4966
- /**
4967
- *
4968
- * @param {any} obj
4969
- * @param {PlainObject} stateObj
4970
- * @param {PlainObject} [opts={}]
4971
- * @returns {Promise<any>|GenericArray|PlainObject|string|false}
4972
- */
4973
-
4974
- }, {
4975
- key: "rootTypeName",
4976
- value: function rootTypeName(obj, stateObj) {
4977
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4978
- opts.iterateNone = true;
4979
- return this.encapsulate(obj, stateObj, opts);
4980
- }
4981
- /**
4982
- * Encapsulate a complex object into a plain Object by replacing
4983
- * registered types with plain objects representing the types data.
4984
- *
4985
- * This method is used internally by `Typeson.stringify()`.
4986
- * @param {any} obj - Object to encapsulate.
4987
- * @param {PlainObject} stateObj
4988
- * @param {PlainObject} opts
4989
- * @returns {Promise<any>|GenericArray|PlainObject|string|false}
4990
- */
4991
-
4992
- }, {
4993
- key: "encapsulate",
4994
- value: function encapsulate(obj, stateObj, opts) {
4995
- /**
4996
- *
4997
- * @param {any} ret
4998
- * @param {GenericArray} promisesData
4999
- * @returns {Promise<any>}
5000
- */
5001
- var checkPromises = _async(function (ret, promisesData) {
5002
- return _await(Promise.all(promisesData.map(function (pd) {
5003
- return pd[1].p;
5004
- })), function (promResults) {
5005
- return _await(Promise.all(promResults.map(_async(function (promResult) {
5006
- var _exit = false;
5007
- var newPromisesData = [];
5008
-
5009
- var _promisesData$splice = promisesData.splice(0, 1),
5010
- _promisesData$splice2 = _slicedToArray(_promisesData$splice, 1),
5011
- prData = _promisesData$splice2[0];
5012
-
5013
- var _prData = _slicedToArray(prData, 7),
5014
- keyPath = _prData[0],
5015
- cyclic = _prData[2],
5016
- stateObj = _prData[3],
5017
- parentObj = _prData[4],
5018
- key = _prData[5],
5019
- detectedType = _prData[6];
5020
-
5021
- var encaps = _encapsulate(keyPath, promResult, cyclic, stateObj, newPromisesData, true, detectedType);
5022
-
5023
- var isTypesonPromise = hasConstructorOf(encaps, TypesonPromise); // Handle case where an embedded custom type itself
5024
- // returns a `Typeson.Promise`
5025
-
5026
- return _invoke(function () {
5027
- if (keyPath && isTypesonPromise) {
5028
- return _await(encaps.p, function (encaps2) {
5029
- parentObj[key] = encaps2;
5030
- _exit = true;
5031
- return checkPromises(ret, newPromisesData);
5032
- });
5033
- }
5034
- }, function (_result) {
5035
- if (_exit) return _result;
5036
-
5037
- if (keyPath) {
5038
- parentObj[key] = encaps;
5039
- } else if (isTypesonPromise) {
5040
- ret = encaps.p;
5041
- } else {
5042
- // If this is itself a `Typeson.Promise` (because the
5043
- // original value supplied was a `Promise` or
5044
- // because the supplied custom type value resolved
5045
- // to one), returning it below will be fine since
5046
- // a `Promise` is expected anyways given current
5047
- // config (and if not a `Promise`, it will be ready
5048
- // as the resolve value)
5049
- ret = encaps;
5050
- }
5051
-
5052
- return checkPromises(ret, newPromisesData);
5053
- });
5054
- }))), function () {
5055
- return ret;
5056
- });
5057
- });
5058
- });
5059
- /**
5060
- * @typedef {PlainObject} OwnKeysObject
5061
- * @property {boolean} ownKeys
5062
- */
5063
-
5064
- /**
5065
- * @callback BuiltinStateObjectPropertiesCallback
5066
- * @returns {void}
5067
- */
5068
-
5069
- /**
5070
- *
5071
- * @param {StateObject} stateObj
5072
- * @param {OwnKeysObject} ownKeysObj
5073
- * @param {BuiltinStateObjectPropertiesCallback} cb
5074
- * @returns {undefined}
5075
- */
5076
-
5077
-
5078
- opts = _objectSpread2(_objectSpread2({
5079
- sync: true
5080
- }, this.options), opts);
5081
- var _opts = opts,
5082
- sync = _opts.sync;
5083
- var that = this,
5084
- types = {},
5085
- refObjs = [],
5086
- // For checking cyclic references
5087
- refKeys = [],
5088
- // For checking cyclic references
5089
- promisesDataRoot = []; // Clone the object deeply while at the same time replacing any
5090
- // special types or cyclic reference:
5091
-
5092
- var cyclic = 'cyclic' in opts ? opts.cyclic : true;
5093
- var _opts2 = opts,
5094
- encapsulateObserver = _opts2.encapsulateObserver;
5095
-
5096
- var ret = _encapsulate('', obj, cyclic, stateObj || {}, promisesDataRoot);
5097
- /**
5098
- *
5099
- * @param {any} ret
5100
- * @returns {GenericArray|PlainObject|string|false}
5101
- */
5102
-
5103
-
5104
- function finish(ret) {
5105
- // Add `$types` to result only if we ever bumped into a
5106
- // special type (or special case where object has own `$types`)
5107
- var typeNames = Object.values(types);
5108
-
5109
- if (opts.iterateNone) {
5110
- if (typeNames.length) {
5111
- return typeNames[0];
5112
- }
5113
-
5114
- return Typeson.getJSONType(ret);
5115
- }
5116
-
5117
- if (typeNames.length) {
5118
- if (opts.returnTypeNames) {
5119
- return _toConsumableArray(new Set(typeNames));
5120
- } // Special if array (or a primitive) was serialized
5121
- // because JSON would ignore custom `$types` prop on it
5122
-
5123
-
5124
- if (!ret || !isPlainObject(ret) || // Also need to handle if this is an object with its
5125
- // own `$types` property (to avoid ambiguity)
5126
- hasOwn.call(ret, '$types')) {
5127
- ret = {
5128
- $: ret,
5129
- $types: {
5130
- $: types
5131
- }
5132
- };
5133
- } else {
5134
- ret.$types = types;
5135
- } // No special types
5136
-
5137
- } else if (isObject(ret) && hasOwn.call(ret, '$types')) {
5138
- ret = {
5139
- $: ret,
5140
- $types: true
5141
- };
5142
- }
5143
-
5144
- if (opts.returnTypeNames) {
5145
- return false;
5146
- }
5147
-
5148
- return ret;
5149
- }
5150
-
5151
- function _adaptBuiltinStateObjectProperties(stateObj, ownKeysObj, cb) {
5152
- Object.assign(stateObj, ownKeysObj);
5153
- var vals = internalStateObjPropsToIgnore.map(function (prop) {
5154
- var tmp = stateObj[prop];
5155
- delete stateObj[prop];
5156
- return tmp;
5157
- }); // eslint-disable-next-line node/callback-return
5158
-
5159
- cb();
5160
- internalStateObjPropsToIgnore.forEach(function (prop, i) {
5161
- stateObj[prop] = vals[i];
5162
- });
5163
- }
5164
- /**
5165
- *
5166
- * @param {string} keypath
5167
- * @param {any} value
5168
- * @param {boolean} cyclic
5169
- * @param {PlainObject} stateObj
5170
- * @param {boolean} promisesData
5171
- * @param {boolean} resolvingTypesonPromise
5172
- * @param {string} detectedType
5173
- * @returns {any}
5174
- */
5175
-
5176
-
5177
- function _encapsulate(keypath, value, cyclic, stateObj, promisesData, resolvingTypesonPromise, detectedType) {
5178
- var ret;
5179
- var observerData = {};
5180
-
5181
- var $typeof = _typeof(value);
5182
-
5183
- var runObserver = encapsulateObserver ? function (obj) {
5184
- var type = detectedType || stateObj.type || Typeson.getJSONType(value);
5185
- encapsulateObserver(Object.assign(obj || observerData, {
5186
- keypath: keypath,
5187
- value: value,
5188
- cyclic: cyclic,
5189
- stateObj: stateObj,
5190
- promisesData: promisesData,
5191
- resolvingTypesonPromise: resolvingTypesonPromise,
5192
- awaitingTypesonPromise: hasConstructorOf(value, TypesonPromise)
5193
- }, {
5194
- type: type
5195
- }));
5196
- } : null;
5197
-
5198
- if (['string', 'boolean', 'number', 'undefined'].includes($typeof)) {
5199
- if (value === undefined || Number.isNaN(value) || value === Number.NEGATIVE_INFINITY || value === Number.POSITIVE_INFINITY) {
5200
- ret = stateObj.replaced ? value : replace(keypath, value, stateObj, promisesData, false, resolvingTypesonPromise, runObserver);
5201
-
5202
- if (ret !== value) {
5203
- observerData = {
5204
- replaced: ret
5205
- };
5206
- }
5207
- } else {
5208
- ret = value;
5209
- }
5210
-
5211
- if (runObserver) {
5212
- runObserver();
5213
- }
5214
-
5215
- return ret;
5216
- }
5217
-
5218
- if (value === null) {
5219
- if (runObserver) {
5220
- runObserver();
5221
- }
5222
-
5223
- return value;
5224
- }
5225
-
5226
- if (cyclic && !stateObj.iterateIn && !stateObj.iterateUnsetNumeric && value && _typeof(value) === 'object') {
5227
- // Options set to detect cyclic references and be able
5228
- // to rewrite them.
5229
- var refIndex = refObjs.indexOf(value);
5230
-
5231
- if (refIndex < 0) {
5232
- if (cyclic === true) {
5233
- refObjs.push(value);
5234
- refKeys.push(keypath);
5235
- }
5236
- } else {
5237
- types[keypath] = '#';
5238
-
5239
- if (runObserver) {
5240
- runObserver({
5241
- cyclicKeypath: refKeys[refIndex]
5242
- });
5243
- }
5244
-
5245
- return '#' + refKeys[refIndex];
5246
- }
5247
- }
5248
-
5249
- var isPlainObj = isPlainObject(value);
5250
- var isArr = isArray(value);
5251
- var replaced = // Running replace will cause infinite loop as will test
5252
- // positive again
5253
- (isPlainObj || isArr) && (!that.plainObjectReplacers.length || stateObj.replaced) || stateObj.iterateIn ? // Optimization: if plain object and no plain-object
5254
- // replacers, don't try finding a replacer
5255
- value : replace(keypath, value, stateObj, promisesData, isPlainObj || isArr, null, runObserver);
5256
- var clone;
5257
-
5258
- if (replaced !== value) {
5259
- ret = replaced;
5260
- observerData = {
5261
- replaced: replaced
5262
- };
5263
- } else {
5264
- // eslint-disable-next-line no-lonely-if
5265
- if (keypath === '' && hasConstructorOf(value, TypesonPromise)) {
5266
- promisesData.push([keypath, value, cyclic, stateObj, undefined, undefined, stateObj.type]);
5267
- ret = value;
5268
- } else if (isArr && stateObj.iterateIn !== 'object' || stateObj.iterateIn === 'array') {
5269
- // eslint-disable-next-line unicorn/no-new-array -- Sparse
5270
- clone = new Array(value.length);
5271
- observerData = {
5272
- clone: clone
5273
- };
5274
- } else if (!['function', 'symbol'].includes(_typeof(value)) && !('toJSON' in value) && !hasConstructorOf(value, TypesonPromise) && !hasConstructorOf(value, Promise) && !hasConstructorOf(value, ArrayBuffer) || isPlainObj || stateObj.iterateIn === 'object') {
5275
- clone = {};
5276
-
5277
- if (stateObj.addLength) {
5278
- clone.length = value.length;
5279
- }
5280
-
5281
- observerData = {
5282
- clone: clone
5283
- };
5284
- } else {
5285
- ret = value; // Only clone vanilla objects and arrays
5286
- }
5287
- }
5288
-
5289
- if (runObserver) {
5290
- runObserver();
5291
- }
5292
-
5293
- if (opts.iterateNone) {
5294
- return clone || ret;
5295
- }
5296
-
5297
- if (!clone) {
5298
- return ret;
5299
- } // Iterate object or array
5300
-
5301
-
5302
- if (stateObj.iterateIn) {
5303
- var _loop = function _loop(key) {
5304
- var ownKeysObj = {
5305
- ownKeys: hasOwn.call(value, key)
5306
- };
5307
-
5308
- _adaptBuiltinStateObjectProperties(stateObj, ownKeysObj, function () {
5309
- var kp = keypath + (keypath ? '.' : '') + escapeKeyPathComponent(key);
5310
-
5311
- var val = _encapsulate(kp, value[key], Boolean(cyclic), stateObj, promisesData, resolvingTypesonPromise);
5312
-
5313
- if (hasConstructorOf(val, TypesonPromise)) {
5314
- promisesData.push([kp, val, Boolean(cyclic), stateObj, clone, key, stateObj.type]);
5315
- } else if (val !== undefined) {
5316
- clone[key] = val;
5317
- }
5318
- });
5319
- }; // eslint-disable-next-line guard-for-in
5320
-
5321
-
5322
- for (var key in value) {
5323
- _loop(key);
5324
- }
5325
-
5326
- if (runObserver) {
5327
- runObserver({
5328
- endIterateIn: true,
5329
- end: true
5330
- });
5331
- }
5332
- } else {
5333
- // Note: Non-indexes on arrays won't survive stringify so
5334
- // somewhat wasteful for arrays, but so too is iterating
5335
- // all numeric indexes on sparse arrays when not wanted
5336
- // or filtering own keys for positive integers
5337
- keys(value).forEach(function (key) {
5338
- var kp = keypath + (keypath ? '.' : '') + escapeKeyPathComponent(key);
5339
- var ownKeysObj = {
5340
- ownKeys: true
5341
- };
5342
-
5343
- _adaptBuiltinStateObjectProperties(stateObj, ownKeysObj, function () {
5344
- var val = _encapsulate(kp, value[key], Boolean(cyclic), stateObj, promisesData, resolvingTypesonPromise);
5345
-
5346
- if (hasConstructorOf(val, TypesonPromise)) {
5347
- promisesData.push([kp, val, Boolean(cyclic), stateObj, clone, key, stateObj.type]);
5348
- } else if (val !== undefined) {
5349
- clone[key] = val;
5350
- }
5351
- });
5352
- });
5353
-
5354
- if (runObserver) {
5355
- runObserver({
5356
- endIterateOwn: true,
5357
- end: true
5358
- });
5359
- }
5360
- } // Iterate array for non-own numeric properties (we can't
5361
- // replace the prior loop though as it iterates non-integer
5362
- // keys)
5363
-
5364
-
5365
- if (stateObj.iterateUnsetNumeric) {
5366
- var vl = value.length;
5367
-
5368
- var _loop2 = function _loop2(i) {
5369
- if (!(i in value)) {
5370
- // No need to escape numeric
5371
- var kp = keypath + (keypath ? '.' : '') + i;
5372
- var ownKeysObj = {
5373
- ownKeys: false
5374
- };
5375
-
5376
- _adaptBuiltinStateObjectProperties(stateObj, ownKeysObj, function () {
5377
- var val = _encapsulate(kp, undefined, Boolean(cyclic), stateObj, promisesData, resolvingTypesonPromise);
5378
-
5379
- if (hasConstructorOf(val, TypesonPromise)) {
5380
- promisesData.push([kp, val, Boolean(cyclic), stateObj, clone, i, stateObj.type]);
5381
- } else if (val !== undefined) {
5382
- clone[i] = val;
5383
- }
5384
- });
5385
- }
5386
- };
5387
-
5388
- for (var i = 0; i < vl; i++) {
5389
- _loop2(i);
5390
- }
5391
-
5392
- if (runObserver) {
5393
- runObserver({
5394
- endIterateUnsetNumeric: true,
5395
- end: true
5396
- });
5397
- }
5398
- }
5399
-
5400
- return clone;
5401
- }
5402
- /**
5403
- * @typedef {PlainObject} KeyPathEvent
5404
- * @property {string} cyclicKeypath
5405
- */
5406
-
5407
- /**
5408
- * @typedef {PlainObject} EndIterateInEvent
5409
- * @property {boolean} endIterateIn
5410
- * @property {boolean} end
5411
- */
5412
-
5413
- /**
5414
- * @typedef {PlainObject} EndIterateUnsetNumericEvent
5415
- * @property {boolean} endIterateUnsetNumeric
5416
- * @property {boolean} end
5417
- */
5418
-
5419
- /**
5420
- * @typedef {PlainObject} TypeDetectedEvent
5421
- * @property {boolean} typeDetected
5422
- */
5423
-
5424
- /**
5425
- * @typedef {PlainObject} ReplacingEvent
5426
- * @property {boolean} replacing
5427
- */
5428
-
5429
- /**
5430
- * @callback Observer
5431
- * @param {KeyPathEvent|EndIterateInEvent|EndIterateUnsetNumericEvent|
5432
- * TypeDetectedEvent|ReplacingEvent} [event]
5433
- * @returns {void}
5434
- */
5435
-
5436
- /**
5437
- *
5438
- * @param {string} keypath
5439
- * @param {any} value
5440
- * @param {PlainObject} stateObj
5441
- * @param {GenericArray} promisesData
5442
- * @param {boolean} plainObject
5443
- * @param {boolean} resolvingTypesonPromise
5444
- * @param {Observer} [runObserver]
5445
- * @returns {any}
5446
- */
5447
-
5448
-
5449
- function replace(keypath, value, stateObj, promisesData, plainObject, resolvingTypesonPromise, runObserver) {
5450
- // Encapsulate registered types
5451
- var replacers = plainObject ? that.plainObjectReplacers : that.nonplainObjectReplacers;
5452
- var i = replacers.length;
5453
-
5454
- while (i--) {
5455
- var replacer = replacers[i];
5456
-
5457
- if (replacer.test(value, stateObj)) {
5458
- var type = replacer.type;
5459
-
5460
- if (that.revivers[type]) {
5461
- // Record the type only if a corresponding reviver
5462
- // exists. This is to support specs where only
5463
- // replacement is done.
5464
- // For example, ensuring deep cloning of the object,
5465
- // or replacing a type to its equivalent without
5466
- // the need to revive it.
5467
- var existing = types[keypath]; // type can comprise an array of types (see test
5468
- // "should support intermediate types")
5469
-
5470
- types[keypath] = existing ? [type].concat(existing) : type;
5471
- }
5472
-
5473
- Object.assign(stateObj, {
5474
- type: type,
5475
- replaced: true
5476
- });
5477
-
5478
- if ((sync || !replacer.replaceAsync) && !replacer.replace) {
5479
- if (runObserver) {
5480
- runObserver({
5481
- typeDetected: true
5482
- });
5483
- }
5484
-
5485
- return _encapsulate(keypath, value, cyclic && 'readonly', stateObj, promisesData, resolvingTypesonPromise, type);
5486
- }
5487
-
5488
- if (runObserver) {
5489
- runObserver({
5490
- replacing: true
5491
- });
5492
- } // Now, also traverse the result in case it contains its
5493
- // own types to replace
5494
-
5495
-
5496
- var replaceMethod = sync || !replacer.replaceAsync ? 'replace' : 'replaceAsync';
5497
- return _encapsulate(keypath, replacer[replaceMethod](value, stateObj), cyclic && 'readonly', stateObj, promisesData, resolvingTypesonPromise, type);
5498
- }
5499
- }
5500
-
5501
- return value;
5502
- }
5503
-
5504
- return promisesDataRoot.length ? sync && opts.throwOnBadSyncType ? function () {
5505
- throw new TypeError('Sync method requested but async result obtained');
5506
- }() : Promise.resolve(checkPromises(ret, promisesDataRoot)).then(finish) : !sync && opts.throwOnBadSyncType ? function () {
5507
- throw new TypeError('Async method requested but sync result obtained');
5508
- }() // If this is a synchronous request for stringification, yet
5509
- // a promise is the result, we don't want to resolve leading
5510
- // to an async result, so we return an array to avoid
5511
- // ambiguity
5512
- : opts.stringification && sync ? [finish(ret)] : sync ? finish(ret) : Promise.resolve(finish(ret));
5513
- }
5514
- /**
5515
- * Also sync but throws on non-sync result.
5516
- * @param {any} obj
5517
- * @param {StateObject} stateObj
5518
- * @param {TypesonOptions} opts
5519
- * @returns {any}
5520
- */
5521
-
5522
- }, {
5523
- key: "encapsulateSync",
5524
- value: function encapsulateSync(obj, stateObj, opts) {
5525
- return this.encapsulate(obj, stateObj, _objectSpread2(_objectSpread2({
5526
- throwOnBadSyncType: true
5527
- }, opts), {}, {
5528
- sync: true
5529
- }));
5530
- }
5531
- /**
5532
- * @param {any} obj
5533
- * @param {StateObject} stateObj
5534
- * @param {TypesonOptions} opts
5535
- * @returns {any}
5536
- */
5537
-
5538
- }, {
5539
- key: "encapsulateAsync",
5540
- value: function encapsulateAsync(obj, stateObj, opts) {
5541
- return this.encapsulate(obj, stateObj, _objectSpread2(_objectSpread2({
5542
- throwOnBadSyncType: true
5543
- }, opts), {}, {
5544
- sync: false
5545
- }));
5546
- }
5547
- /**
5548
- * Revive an encapsulated object.
5549
- * This method is used internally by `Typeson.parse()`.
5550
- * @param {PlainObject} obj - Object to revive. If it has `$types` member,
5551
- * the properties that are listed there will be replaced with its true
5552
- * type instead of just plain objects.
5553
- * @param {TypesonOptions} opts
5554
- * @throws TypeError If mismatch between sync/async type and result
5555
- * @returns {Promise<any>|any} If async, returns a Promise that resolves
5556
- * to `any`.
5557
- */
5558
-
5559
- }, {
5560
- key: "revive",
5561
- value: function revive(obj, opts) {
5562
- var types = obj && obj.$types; // No type info added. Revival not needed.
5563
-
5564
- if (!types) {
5565
- return obj;
5566
- } // Object happened to have own `$types` property but with
5567
- // no actual types, so we unescape and return that object
5568
-
5569
-
5570
- if (types === true) {
5571
- return obj.$;
5572
- }
5573
-
5574
- opts = _objectSpread2(_objectSpread2({
5575
- sync: true
5576
- }, this.options), opts);
5577
- var _opts3 = opts,
5578
- sync = _opts3.sync;
5579
- var keyPathResolutions = [];
5580
- var stateObj = {};
5581
- var ignore$Types = true; // Special when root object is not a trivial Object, it will
5582
- // be encapsulated in `$`. It will also be encapsulated in
5583
- // `$` if it has its own `$` property to avoid ambiguity
5584
-
5585
- if (types.$ && isPlainObject(types.$)) {
5586
- obj = obj.$;
5587
- types = types.$;
5588
- ignore$Types = false;
5589
- }
5590
-
5591
- var that = this;
5592
- /**
5593
- * @callback RevivalReducer
5594
- * @param {any} value
5595
- * @param {string} type
5596
- * @returns {any}
5597
- */
5598
-
5599
- /**
5600
- *
5601
- * @param {string} type
5602
- * @param {any} val
5603
- * @throws {Error}
5604
- * @returns {any}
5605
- */
5606
-
5607
- function executeReviver(type, val) {
5608
- var _ref = that.revivers[type] || [],
5609
- _ref2 = _slicedToArray(_ref, 1),
5610
- reviver = _ref2[0];
5611
-
5612
- if (!reviver) {
5613
- throw new Error('Unregistered type: ' + type);
5614
- } // Only `sync` expected here, as problematic async would
5615
- // be missing both `reviver` and `reviverAsync`, and
5616
- // encapsulation shouldn't have added types, so
5617
- // should have made an early exit
5618
-
5619
-
5620
- if (sync && !('revive' in reviver)) {
5621
- // Just return value as is
5622
- return val;
5623
- }
5624
-
5625
- return reviver[sync && reviver.revive ? 'revive' : !sync && reviver.reviveAsync ? 'reviveAsync' : 'revive'](val, stateObj);
5626
- }
5627
- /**
5628
- *
5629
- * @returns {void|TypesonPromise<void>}
5630
- */
5631
-
5632
-
5633
- function revivePlainObjects() {
5634
- // const references = [];
5635
- // const reviveTypes = [];
5636
- var plainObjectTypes = [];
5637
- Object.entries(types).forEach(function (_ref3) {
5638
- var _ref4 = _slicedToArray(_ref3, 2),
5639
- keypath = _ref4[0],
5640
- type = _ref4[1];
5641
-
5642
- if (type === '#') {
5643
- /*
5644
- references.push({
5645
- keypath,
5646
- reference: getByKeyPath(obj, keypath)
5647
- });
5648
- */
5649
- return;
5650
- }
5651
-
5652
- [].concat(type).forEach(function (type) {
5653
- var _ref5 = that.revivers[type] || [null, {}],
5654
- _ref6 = _slicedToArray(_ref5, 2),
5655
- plain = _ref6[1].plain;
5656
-
5657
- if (!plain) {
5658
- // reviveTypes.push({keypath, type});
5659
- return;
5660
- }
5661
-
5662
- plainObjectTypes.push({
5663
- keypath: keypath,
5664
- type: type
5665
- });
5666
- delete types[keypath]; // Avoid repeating
5667
- });
5668
- });
5669
-
5670
- if (!plainObjectTypes.length) {
5671
- return undefined;
5672
- } // console.log(plainObjectTypes.sort(nestedPathsFirst));
5673
-
5674
- /**
5675
- * @typedef {PlainObject} PlainObjectType
5676
- * @property {string} keypath
5677
- * @property {string} type
5678
- */
5679
-
5680
-
5681
- return plainObjectTypes.sort(nestedPathsFirst).reduce(function reducer(possibleTypesonPromise, _ref7) {
5682
- var keypath = _ref7.keypath,
5683
- type = _ref7.type;
5684
-
5685
- if (isThenable(possibleTypesonPromise)) {
5686
- return possibleTypesonPromise.then(function (val) {
5687
- return reducer(val, {
5688
- keypath: keypath,
5689
- type: type
5690
- });
5691
- });
5692
- } // console.log('obj', JSON.stringify(keypath), obj);
5693
-
5694
-
5695
- var val = getByKeyPath(obj, keypath);
5696
- val = executeReviver(type, val);
5697
-
5698
- if (hasConstructorOf(val, TypesonPromise)) {
5699
- return val.then(function (v) {
5700
- var newVal = setAtKeyPath(obj, keypath, v);
5701
-
5702
- if (newVal === v) {
5703
- obj = newVal;
5704
- }
5705
-
5706
- return undefined;
5707
- });
5708
- }
5709
-
5710
- var newVal = setAtKeyPath(obj, keypath, val);
5711
-
5712
- if (newVal === val) {
5713
- obj = newVal;
5714
- }
5715
-
5716
- return undefined;
5717
- }, undefined // This argument must be explicit
5718
- ); // references.forEach(({keypath, reference}) => {});
5719
- // reviveTypes.sort(nestedPathsFirst).forEach(() => {});
5720
- }
5721
-
5722
- var revivalPromises = [];
5723
- /**
5724
- *
5725
- * @param {string} keypath
5726
- * @param {any} value
5727
- * @param {?(GenericArray|PlainObject)} target
5728
- * @param {GenericArray|PlainObject} [clone]
5729
- * @param {string} [key]
5730
- * @returns {any}
5731
- */
5732
-
5733
- function _revive(keypath, value, target, clone, key) {
5734
- if (ignore$Types && keypath === '$types') {
5735
- return undefined;
5736
- }
5737
-
5738
- var type = types[keypath];
5739
- var isArr = isArray(value);
5740
-
5741
- if (isArr || isPlainObject(value)) {
5742
- // eslint-disable-next-line unicorn/no-new-array -- Sparse
5743
- var _clone = isArr ? new Array(value.length) : {}; // Iterate object or array
5744
-
5745
-
5746
- keys(value).forEach(function (k) {
5747
- var val = _revive(keypath + (keypath ? '.' : '') + escapeKeyPathComponent(k), value[k], target || _clone, _clone, k);
5748
-
5749
- var set = function set(v) {
5750
- if (hasConstructorOf(v, Undefined)) {
5751
- _clone[k] = undefined;
5752
- } else if (v !== undefined) {
5753
- _clone[k] = v;
5754
- }
5755
-
5756
- return v;
5757
- };
5758
-
5759
- if (hasConstructorOf(val, TypesonPromise)) {
5760
- revivalPromises.push(val.then(function (ret) {
5761
- return set(ret);
5762
- }));
5763
- } else {
5764
- set(val);
5765
- }
5766
- });
5767
- value = _clone; // Try to resolve cyclic reference as soon as available
5768
-
5769
- while (keyPathResolutions.length) {
5770
- var _keyPathResolutions$ = _slicedToArray(keyPathResolutions[0], 4),
5771
- _target = _keyPathResolutions$[0],
5772
- keyPath = _keyPathResolutions$[1],
5773
- _clone2 = _keyPathResolutions$[2],
5774
- k = _keyPathResolutions$[3];
5775
-
5776
- var val = getByKeyPath(_target, keyPath); // Typeson.Undefined not expected here as not cyclic or
5777
- // `undefined`
5778
-
5779
- if (val !== undefined) {
5780
- _clone2[k] = val;
5781
- } else {
5782
- break;
5783
- }
5784
-
5785
- keyPathResolutions.splice(0, 1);
5786
- }
5787
- }
5788
-
5789
- if (!type) {
5790
- return value;
5791
- }
5792
-
5793
- if (type === '#') {
5794
- var _ret = getByKeyPath(target, value.slice(1));
5795
-
5796
- if (_ret === undefined) {
5797
- // Cyclic reference not yet available
5798
- keyPathResolutions.push([target, value.slice(1), clone, key]);
5799
- }
5800
-
5801
- return _ret;
5802
- } // `type` can be an array here
5803
-
5804
-
5805
- return [].concat(type).reduce(function reducer(val, typ) {
5806
- if (hasConstructorOf(val, TypesonPromise)) {
5807
- return val.then(function (v) {
5808
- // TypesonPromise here too
5809
- return reducer(v, typ);
5810
- });
5811
- }
5812
-
5813
- return executeReviver(typ, val);
5814
- }, value);
5815
- }
5816
- /**
5817
- *
5818
- * @param {any} retrn
5819
- * @returns {undefined|any}
5820
- */
5821
-
5822
-
5823
- function checkUndefined(retrn) {
5824
- return hasConstructorOf(retrn, Undefined) ? undefined : retrn;
5825
- }
5826
-
5827
- var possibleTypesonPromise = revivePlainObjects();
5828
- var ret;
5829
-
5830
- if (hasConstructorOf(possibleTypesonPromise, TypesonPromise)) {
5831
- ret = possibleTypesonPromise.then(function () {
5832
- return obj;
5833
- });
5834
- } else {
5835
- ret = _revive('', obj, null);
5836
-
5837
- if (revivalPromises.length) {
5838
- // Ensure children resolved
5839
- ret = TypesonPromise.resolve(ret).then(function (r) {
5840
- return TypesonPromise.all([// May be a TypesonPromise or not
5841
- r].concat(revivalPromises));
5842
- }).then(function (_ref8) {
5843
- var _ref9 = _slicedToArray(_ref8, 1),
5844
- r = _ref9[0];
5845
-
5846
- return r;
5847
- });
5848
- }
5849
- }
5850
-
5851
- return isThenable(ret) ? sync && opts.throwOnBadSyncType ? function () {
5852
- throw new TypeError('Sync method requested but async result obtained');
5853
- }() : hasConstructorOf(ret, TypesonPromise) ? ret.p.then(checkUndefined) : ret : !sync && opts.throwOnBadSyncType ? function () {
5854
- throw new TypeError('Async method requested but sync result obtained');
5855
- }() : sync ? checkUndefined(ret) : Promise.resolve(checkUndefined(ret));
5856
- }
5857
- /**
5858
- * Also sync but throws on non-sync result.
5859
- * @param {any} obj
5860
- * @param {TypesonOptions} opts
5861
- * @returns {any}
5862
- */
5863
-
5864
- }, {
5865
- key: "reviveSync",
5866
- value: function reviveSync(obj, opts) {
5867
- return this.revive(obj, _objectSpread2(_objectSpread2({
5868
- throwOnBadSyncType: true
5869
- }, opts), {}, {
5870
- sync: true
5871
- }));
5872
- }
5873
- /**
5874
- * @param {any} obj
5875
- * @param {TypesonOptions} opts
5876
- * @returns {Promise<any>}
5877
- */
5878
-
5879
- }, {
5880
- key: "reviveAsync",
5881
- value: function reviveAsync(obj, opts) {
5882
- return this.revive(obj, _objectSpread2(_objectSpread2({
5883
- throwOnBadSyncType: true
5884
- }, opts), {}, {
5885
- sync: false
5886
- }));
5887
- }
5888
- /**
5889
- * @typedef {Tester|Replacer|Reviver} Spec
5890
- */
5891
-
5892
- /**
5893
- * Register types.
5894
- * For examples on how to use this method, see
5895
- * {@link https://github.com/dfahlander/typeson-registry/tree/master/types}.
5896
- * @param {object<string,Spec[]>[]} typeSpecSets -
5897
- * Types and their functions [test, encapsulate, revive];
5898
- * @param {TypesonOptions} opts
5899
- * @returns {Typeson}
5900
- */
5901
-
5902
- }, {
5903
- key: "register",
5904
- value: function register(typeSpecSets, opts) {
5905
- opts = opts || {};
5906
- [].concat(typeSpecSets).forEach(function R(typeSpec) {
5907
- var _this = this; // Allow arrays of arrays of arrays...
5908
-
5909
-
5910
- if (isArray(typeSpec)) {
5911
- return typeSpec.map(function (typSpec) {
5912
- return R.call(_this, typSpec);
5913
- });
5914
- }
5915
-
5916
- typeSpec && keys(typeSpec).forEach(function (typeId) {
5917
- if (typeId === '#') {
5918
- throw new TypeError('# cannot be used as a type name as it is reserved ' + 'for cyclic objects');
5919
- } else if (Typeson.JSON_TYPES.includes(typeId)) {
5920
- throw new TypeError('Plain JSON object types are reserved as type names');
5921
- }
5922
-
5923
- var spec = typeSpec[typeId];
5924
- var replacers = spec && spec.testPlainObjects ? this.plainObjectReplacers : this.nonplainObjectReplacers;
5925
- var existingReplacer = replacers.filter(function (r) {
5926
- return r.type === typeId;
5927
- });
5928
-
5929
- if (existingReplacer.length) {
5930
- // Remove existing spec and replace with this one.
5931
- replacers.splice(replacers.indexOf(existingReplacer[0]), 1);
5932
- delete this.revivers[typeId];
5933
- delete this.types[typeId];
5934
- }
5935
-
5936
- if (typeof spec === 'function') {
5937
- // Support registering just a class without replacer/reviver
5938
- var Class = spec;
5939
- spec = {
5940
- test: function test(x) {
5941
- return x && x.constructor === Class;
5942
- },
5943
- replace: function replace(x) {
5944
- return _objectSpread2({}, x);
5945
- },
5946
- revive: function revive(x) {
5947
- return Object.assign(Object.create(Class.prototype), x);
5948
- }
5949
- };
5950
- } else if (isArray(spec)) {
5951
- var _spec = spec,
5952
- _spec2 = _slicedToArray(_spec, 3),
5953
- test = _spec2[0],
5954
- replace = _spec2[1],
5955
- revive = _spec2[2];
5956
-
5957
- spec = {
5958
- test: test,
5959
- replace: replace,
5960
- revive: revive
5961
- };
5962
- }
5963
-
5964
- if (!spec || !spec.test) {
5965
- return;
5966
- }
5967
-
5968
- var replacerObj = {
5969
- type: typeId,
5970
- test: spec.test.bind(spec)
5971
- };
5972
-
5973
- if (spec.replace) {
5974
- replacerObj.replace = spec.replace.bind(spec);
5975
- }
5976
-
5977
- if (spec.replaceAsync) {
5978
- replacerObj.replaceAsync = spec.replaceAsync.bind(spec);
5979
- }
5980
-
5981
- var start = typeof opts.fallback === 'number' ? opts.fallback : opts.fallback ? 0 : Number.POSITIVE_INFINITY;
5982
-
5983
- if (spec.testPlainObjects) {
5984
- this.plainObjectReplacers.splice(start, 0, replacerObj);
5985
- } else {
5986
- this.nonplainObjectReplacers.splice(start, 0, replacerObj);
5987
- } // Todo: We might consider a testAsync type
5988
-
5989
-
5990
- if (spec.revive || spec.reviveAsync) {
5991
- var reviverObj = {};
5992
-
5993
- if (spec.revive) {
5994
- reviverObj.revive = spec.revive.bind(spec);
5995
- }
5996
-
5997
- if (spec.reviveAsync) {
5998
- reviverObj.reviveAsync = spec.reviveAsync.bind(spec);
5999
- }
6000
-
6001
- this.revivers[typeId] = [reviverObj, {
6002
- plain: spec.testPlainObjects
6003
- }];
6004
- } // Record to be retrieved via public types property.
6005
-
6006
-
6007
- this.types[typeId] = spec;
6008
- }, this);
6009
- }, this);
6010
- return this;
6011
- }
6012
- }]);
6013
-
6014
- return Typeson;
6015
- }();
6016
- /**
6017
- * We keep this function minimized so if using two instances of this
6018
- * library, where one is minimized and one is not, it will still work
6019
- * with `hasConstructorOf`.
6020
- * @class
6021
- */
6022
-
6023
-
6024
- var Undefined = function Undefined() {
6025
- _classCallCheck(this, Undefined);
6026
- }; // eslint-disable-line space-before-blocks
6027
-
6028
-
6029
- Undefined.__typeson__type__ = 'TypesonUndefined'; // The following provide classes meant to avoid clashes with other values
6030
- // To insist `undefined` should be added
6031
-
6032
- Typeson.Undefined = Undefined; // To support async encapsulation/stringification
6033
-
6034
- Typeson.Promise = TypesonPromise; // Some fundamental type-checking utilities
6035
-
6036
- Typeson.isThenable = isThenable;
6037
- Typeson.toStringTag = toStringTag;
6038
- Typeson.hasConstructorOf = hasConstructorOf;
6039
- Typeson.isObject = isObject;
6040
- Typeson.isPlainObject = isPlainObject;
6041
- Typeson.isUserObject = isUserObject;
6042
- Typeson.escapeKeyPathComponent = escapeKeyPathComponent;
6043
- Typeson.unescapeKeyPathComponent = unescapeKeyPathComponent;
6044
- Typeson.getByKeyPath = getByKeyPath;
6045
- Typeson.getJSONType = getJSONType;
6046
- Typeson.JSON_TYPES = ['null', 'boolean', 'number', 'string', 'array', 'object'];
6047
-
6048
- /*
6049
- * base64-arraybuffer
6050
- * https://github.com/niklasvh/base64-arraybuffer
6051
- *
6052
- * Copyright (c) 2017 Brett Zamir, 2012 Niklas von Hertzen
6053
- * Licensed under the MIT license.
6054
- */
6055
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
6056
-
6057
- var lookup = new Uint8Array(256);
6058
-
6059
- for (var i = 0; i < chars.length; i++) {
6060
- lookup[chars.charCodeAt(i)] = i;
6061
- }
6062
- /**
6063
- * @param {ArrayBuffer} arraybuffer
6064
- * @param {Integer} byteOffset
6065
- * @param {Integer} lngth
6066
- * @returns {string}
6067
- */
6068
-
6069
-
6070
- var encode$1 = function encode(arraybuffer, byteOffset, lngth) {
6071
- if (lngth === null || lngth === undefined) {
6072
- lngth = arraybuffer.byteLength; // Needed for Safari
6073
- }
6074
-
6075
- var bytes = new Uint8Array(arraybuffer, byteOffset || 0, // Default needed for Safari
6076
- lngth);
6077
- var len = bytes.length;
6078
- var base64 = '';
6079
-
6080
- for (var _i = 0; _i < len; _i += 3) {
6081
- base64 += chars[bytes[_i] >> 2];
6082
- base64 += chars[(bytes[_i] & 3) << 4 | bytes[_i + 1] >> 4];
6083
- base64 += chars[(bytes[_i + 1] & 15) << 2 | bytes[_i + 2] >> 6];
6084
- base64 += chars[bytes[_i + 2] & 63];
6085
- }
6086
-
6087
- if (len % 3 === 2) {
6088
- base64 = base64.slice(0, -1) + '=';
6089
- } else if (len % 3 === 1) {
6090
- base64 = base64.slice(0, -2) + '==';
6091
- }
6092
-
6093
- return base64;
6094
- };
6095
- /**
6096
- * @param {string} base64
6097
- * @returns {ArrayBuffer}
6098
- */
6099
-
6100
-
6101
- var decode$1 = function decode(base64) {
6102
- var len = base64.length;
6103
- var bufferLength = base64.length * 0.75;
6104
- var p = 0;
6105
- var encoded1, encoded2, encoded3, encoded4;
6106
-
6107
- if (base64[base64.length - 1] === '=') {
6108
- bufferLength--;
6109
-
6110
- if (base64[base64.length - 2] === '=') {
6111
- bufferLength--;
6112
- }
6113
- }
6114
-
6115
- var arraybuffer = new ArrayBuffer(bufferLength),
6116
- bytes = new Uint8Array(arraybuffer);
6117
-
6118
- for (var _i2 = 0; _i2 < len; _i2 += 4) {
6119
- encoded1 = lookup[base64.charCodeAt(_i2)];
6120
- encoded2 = lookup[base64.charCodeAt(_i2 + 1)];
6121
- encoded3 = lookup[base64.charCodeAt(_i2 + 2)];
6122
- encoded4 = lookup[base64.charCodeAt(_i2 + 3)];
6123
- bytes[p++] = encoded1 << 2 | encoded2 >> 4;
6124
- bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
6125
- bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
6126
- }
6127
-
6128
- return arraybuffer;
6129
- };
6130
-
6131
- const arraybuffer = {
6132
- arraybuffer: {
6133
- test(x) {
6134
- return Typeson.toStringTag(x) === 'ArrayBuffer';
6135
- },
6136
-
6137
- replace(b, stateObj) {
6138
- if (!stateObj.buffers) {
6139
- stateObj.buffers = [];
6140
- }
6141
-
6142
- const index = stateObj.buffers.indexOf(b);
6143
-
6144
- if (index > -1) {
6145
- return {
6146
- index
6147
- };
6148
- }
6149
-
6150
- stateObj.buffers.push(b);
6151
- return encode$1(b);
6152
- },
6153
-
6154
- revive(b64, stateObj) {
6155
- if (!stateObj.buffers) {
6156
- stateObj.buffers = [];
6157
- }
6158
-
6159
- if (typeof b64 === 'object') {
6160
- return stateObj.buffers[b64.index];
6161
- }
6162
-
6163
- const buffer = decode$1(b64);
6164
- stateObj.buffers.push(buffer);
6165
- return buffer;
6166
- }
6167
-
6168
- }
6169
- };
6170
- // See also typed-arrays!
6171
-
6172
- /* globals BigInt */
6173
- const bigintObject = {
6174
- bigintObject: {
6175
- test(x) {
6176
- return typeof x === 'object' && Typeson.hasConstructorOf(x, BigInt);
6177
- },
6178
-
6179
- replace(n) {
6180
- return String(n);
6181
- },
6182
-
6183
- revive(s) {
6184
- // Filed this to avoid error: https://github.com/eslint/eslint/issues/11810
6185
- // eslint-disable-next-line no-new-object
6186
- return new Object(BigInt(s));
6187
- }
6188
-
6189
- }
6190
- };
6191
-
6192
- /* globals BigInt */
6193
- const bigint = {
6194
- bigint: {
6195
- test(x) {
6196
- return typeof x === 'bigint';
6197
- },
6198
-
6199
- replace(n) {
6200
- return String(n);
6201
- },
6202
-
6203
- revive(s) {
6204
- return BigInt(s);
6205
- }
6206
-
6207
- }
6208
- };
6209
-
6210
- /**
6211
- * Not currently in use internally, but provided for parity.
6212
- * @param {ArrayBuffer} buf
6213
- * @returns {Uint8Array}
6214
- */
6215
- /**
6216
- *
6217
- * @param {string} str
6218
- * @returns {ArrayBuffer}
6219
- */
6220
-
6221
-
6222
- function string2arraybuffer(str) {
6223
- /*
6224
- // UTF-8 approaches
6225
- const utf8 = unescape(encodeURIComponent(str));
6226
- const arr = new Uint8Array(utf8.length);
6227
- for (let i = 0; i < utf8.length; i++) {
6228
- arr[i] = utf8.charCodeAt(i);
6229
- }
6230
- return arr.buffer;
6231
- const utf8 = [];
6232
- for (let i = 0; i < str.length; i++) {
6233
- let charcode = str.charCodeAt(i);
6234
- if (charcode < 0x80) utf8.push(charcode);
6235
- else if (charcode < 0x800) {
6236
- utf8.push(0xc0 | (charcode >> 6),
6237
- 0x80 | (charcode & 0x3f));
6238
- } else if (charcode < 0xd800 || charcode >= 0xe000) {
6239
- utf8.push(0xe0 | (charcode >> 12),
6240
- 0x80 | ((charcode >> 6) & 0x3f),
6241
- 0x80 | (charcode & 0x3f));
6242
- // surrogate pair
6243
- } else {
6244
- i++;
6245
- // UTF-16 encodes 0x10000-0x10FFFF by
6246
- // subtracting 0x10000 and splitting the
6247
- // 20 bits of 0x0-0xFFFFF into two halves
6248
- charcode = 0x10000 + (((charcode & 0x3ff) << 10) |
6249
- (str.charCodeAt(i) & 0x3ff));
6250
- utf8.push(0xf0 | (charcode >> 18),
6251
- 0x80 | ((charcode >> 12) & 0x3f),
6252
- 0x80 | ((charcode >> 6) & 0x3f),
6253
- 0x80 | (charcode & 0x3f));
6254
- }
6255
- }
6256
- return utf8;
6257
- */
6258
-
6259
- /*
6260
- // Working UTF-16 options (equivalents)
6261
- const buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
6262
- const bufView = new Uint16Array(buf);
6263
- for (let i = 0, strLen = str.length; i < strLen; i++) {
6264
- bufView[i] = str.charCodeAt(i);
6265
- }
6266
- return buf;
6267
- */
6268
- const array = new Uint8Array(str.length);
6269
-
6270
- for (let i = 0; i < str.length; i++) {
6271
- array[i] = str.charCodeAt(i); // & 0xff;
6272
- }
6273
-
6274
- return array.buffer;
6275
- }
6276
-
6277
- /* globals XMLHttpRequest, Blob, FileReader */
6278
- const blob = {
6279
- blob: {
6280
- test(x) {
6281
- return Typeson.toStringTag(x) === 'Blob';
6282
- },
6283
-
6284
- replace(b) {
6285
- // Sync
6286
- const req = new XMLHttpRequest();
6287
- req.overrideMimeType('text/plain; charset=x-user-defined');
6288
- req.open('GET', URL.createObjectURL(b), false); // Sync
6289
-
6290
- req.send(); // Seems not feasible to accurately simulate
6291
-
6292
- /* istanbul ignore next */
6293
-
6294
- if (req.status !== 200 && req.status !== 0) {
6295
- throw new Error('Bad Blob access: ' + req.status);
6296
- }
6297
-
6298
- return {
6299
- type: b.type,
6300
- stringContents: req.responseText
6301
- };
6302
- },
6303
-
6304
- revive({
6305
- type,
6306
- stringContents
6307
- }) {
6308
- return new Blob([string2arraybuffer(stringContents)], {
6309
- type
6310
- });
6311
- },
6312
-
6313
- replaceAsync(b) {
6314
- return new Typeson.Promise((resolve, reject) => {
6315
- /*
6316
- if (b.isClosed) { // On MDN, but not in https://w3c.github.io/FileAPI/#dfn-Blob
6317
- reject(new Error('The Blob is closed'));
6318
- return;
6319
- }
6320
- */
6321
- const reader = new FileReader();
6322
- reader.addEventListener('load', () => {
6323
- resolve({
6324
- type: b.type,
6325
- stringContents: reader.result
6326
- });
6327
- }); // Seems not feasible to accurately simulate
6328
-
6329
- /* istanbul ignore next */
6330
-
6331
- reader.addEventListener('error', () => {
6332
- reject(reader.error);
6333
- });
6334
- reader.readAsBinaryString(b);
6335
- });
6336
- }
6337
-
6338
- }
6339
- };
6340
-
6341
- /* globals performance */
6342
- // The `performance` global is optional
6343
-
6344
- /**
6345
- * @todo We could use `import generateUUID from 'uuid/v4';` (but it needs
6346
- * crypto library, etc.; `rollup-plugin-node-builtins` doesn't recommend
6347
- * using its own version and though there is <https://www.npmjs.com/package/crypto-browserify>,
6348
- * it may be troublesome to bundle and not strongly needed)
6349
- * @returns {string}
6350
- */
6351
- function generateUUID() {
6352
- // Adapted from original: public domain/MIT: http://stackoverflow.com/a/8809472/271577
6353
-
6354
- /* istanbul ignore next */
6355
- let d = Date.now() + ( // use high-precision timer if available
6356
- // istanbul ignore next
6357
- typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : 0);
6358
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/gu, function (c) {
6359
- /* eslint-disable no-bitwise */
6360
- const r = Math.trunc((d + Math.random() * 16) % 16);
6361
- d = Math.floor(d / 16);
6362
- return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
6363
- /* eslint-enable no-bitwise */
6364
- });
6365
- }
6366
-
6367
- const cloneableObjectsByUUID = {};
6368
- const cloneable = {
6369
- cloneable: {
6370
- test(x) {
6371
- return x && typeof x === 'object' && typeof x[Symbol.for('cloneEncapsulate')] === 'function';
6372
- },
6373
-
6374
- replace(clonable) {
6375
- const encapsulated = clonable[Symbol.for('cloneEncapsulate')]();
6376
- const uuid = generateUUID();
6377
- cloneableObjectsByUUID[uuid] = clonable;
6378
- return {
6379
- uuid,
6380
- encapsulated
6381
- };
6382
- },
6383
-
6384
- revive({
6385
- uuid,
6386
- encapsulated
6387
- }) {
6388
- return cloneableObjectsByUUID[uuid][Symbol.for('cloneRevive')](encapsulated);
6389
- }
6390
-
6391
- }
6392
- };
6393
-
6394
- /* globals crypto */
6395
- const cryptokey = {
6396
- cryptokey: {
6397
- test(x) {
6398
- return Typeson.toStringTag(x) === 'CryptoKey' && x.extractable;
6399
- },
6400
-
6401
- replaceAsync(key) {
6402
- return new Typeson.Promise((resolve, reject) => {
6403
- // eslint-disable-next-line promise/catch-or-return
6404
- crypto.subtle.exportKey('jwk', key).catch(
6405
- /* eslint-disable promise/prefer-await-to-callbacks */
6406
- // istanbul ignore next
6407
- err => {
6408
- /* eslint-enable promise/prefer-await-to-callbacks */
6409
- // eslint-disable-next-line max-len
6410
- // istanbul ignore next -- Our format should be valid and our key extractable
6411
- reject(err);
6412
- } // eslint-disable-next-line max-len
6413
- // eslint-disable-next-line promise/always-return, promise/prefer-await-to-then
6414
- ).then(jwk => {
6415
- resolve({
6416
- jwk,
6417
- algorithm: key.algorithm,
6418
- usages: key.usages
6419
- });
6420
- });
6421
- });
6422
- },
6423
-
6424
- revive({
6425
- jwk,
6426
- algorithm,
6427
- usages
6428
- }) {
6429
- return crypto.subtle.importKey('jwk', jwk, algorithm, true, usages);
6430
- }
6431
-
6432
- }
6433
- };
6434
-
6435
- const dataview = {
6436
- dataview: {
6437
- test(x) {
6438
- return Typeson.toStringTag(x) === 'DataView';
6439
- },
6440
-
6441
- replace({
6442
- buffer,
6443
- byteOffset,
6444
- byteLength
6445
- }, stateObj) {
6446
- if (!stateObj.buffers) {
6447
- stateObj.buffers = [];
6448
- }
6449
-
6450
- const index = stateObj.buffers.indexOf(buffer);
6451
-
6452
- if (index > -1) {
6453
- return {
6454
- index,
6455
- byteOffset,
6456
- byteLength
6457
- };
6458
- }
6459
-
6460
- stateObj.buffers.push(buffer);
6461
- return {
6462
- encoded: encode$1(buffer),
6463
- byteOffset,
6464
- byteLength
6465
- };
6466
- },
6467
-
6468
- revive(b64Obj, stateObj) {
6469
- if (!stateObj.buffers) {
6470
- stateObj.buffers = [];
6471
- }
6472
-
6473
- const {
6474
- byteOffset,
6475
- byteLength,
6476
- encoded,
6477
- index
6478
- } = b64Obj;
6479
- let buffer;
6480
-
6481
- if ('index' in b64Obj) {
6482
- buffer = stateObj.buffers[index];
6483
- } else {
6484
- buffer = decode$1(encoded);
6485
- stateObj.buffers.push(buffer);
6486
- }
6487
-
6488
- return new DataView(buffer, byteOffset, byteLength);
6489
- }
6490
-
6491
- }
6492
- };
6493
-
6494
- const date = {
6495
- date: {
6496
- test(x) {
6497
- return Typeson.toStringTag(x) === 'Date';
6498
- },
6499
-
6500
- replace(dt) {
6501
- const time = dt.getTime();
6502
-
6503
- if (Number.isNaN(time)) {
6504
- return 'NaN';
6505
- }
6506
-
6507
- return time;
6508
- },
6509
-
6510
- revive(time) {
6511
- if (time === 'NaN') {
6512
- return new Date(Number.NaN);
6513
- }
6514
-
6515
- return new Date(time);
6516
- }
6517
-
6518
- }
6519
- };
6520
-
6521
- const error = {
6522
- error: {
6523
- test(x) {
6524
- return Typeson.toStringTag(x) === 'Error';
6525
- },
6526
-
6527
- replace({
6528
- name,
6529
- message
6530
- }) {
6531
- return {
6532
- name,
6533
- message
6534
- };
6535
- },
6536
-
6537
- revive({
6538
- name,
6539
- message
6540
- }) {
6541
- const e = new Error(message);
6542
- e.name = name;
6543
- return e;
6544
- }
6545
-
6546
- }
6547
- }; // See also errors.js that may be registered after having registered this type.
6548
-
6549
- /* eslint-env browser, node */
6550
- /* istanbul ignore next */
6551
-
6552
- const _global$2 = typeof self === 'undefined' ? global : self;
6553
-
6554
- const errors = {}; // Comprises all built-in errors.
6555
-
6556
- ['TypeError', 'RangeError', 'SyntaxError', 'ReferenceError', 'EvalError', 'URIError', 'InternalError' // non-standard
6557
- ].forEach(errName => {
6558
- const Cnstrctr = _global$2[errName];
6559
-
6560
- if (Cnstrctr) {
6561
- errors[errName.toLowerCase()] = {
6562
- test(x) {
6563
- return Typeson.hasConstructorOf(x, Cnstrctr);
6564
- },
6565
-
6566
- replace(e) {
6567
- return e.message;
6568
- },
6569
-
6570
- revive(message) {
6571
- return new Cnstrctr(message);
6572
- }
6573
-
6574
- };
6575
- }
6576
- });
6577
-
6578
- /* globals XMLHttpRequest, File, FileReader */
6579
- const file = {
6580
- file: {
6581
- test(x) {
6582
- return Typeson.toStringTag(x) === 'File';
6583
- },
6584
-
6585
- replace(f) {
6586
- // Sync
6587
- const req = new XMLHttpRequest();
6588
- req.overrideMimeType('text/plain; charset=x-user-defined');
6589
- req.open('GET', URL.createObjectURL(f), false); // Sync
6590
-
6591
- req.send(); // Seems not feasible to accurately simulate
6592
-
6593
- /* istanbul ignore next */
6594
-
6595
- if (req.status !== 200 && req.status !== 0) {
6596
- throw new Error('Bad File access: ' + req.status);
6597
- }
6598
-
6599
- return {
6600
- type: f.type,
6601
- stringContents: req.responseText,
6602
- name: f.name,
6603
- lastModified: f.lastModified
6604
- };
6605
- },
6606
-
6607
- revive({
6608
- name,
6609
- type,
6610
- stringContents,
6611
- lastModified
6612
- }) {
6613
- return new File([string2arraybuffer(stringContents)], name, {
6614
- type,
6615
- lastModified
6616
- });
6617
- },
6618
-
6619
- replaceAsync(f) {
6620
- return new Typeson.Promise(function (resolve, reject) {
6621
- /*
6622
- if (f.isClosed) { // On MDN, but not in https://w3c.github.io/FileAPI/#dfn-Blob
6623
- reject(new Error('The File is closed'));
6624
- return;
6625
- }
6626
- */
6627
- const reader = new FileReader();
6628
- reader.addEventListener('load', function () {
6629
- resolve({
6630
- type: f.type,
6631
- stringContents: reader.result,
6632
- name: f.name,
6633
- lastModified: f.lastModified
6634
- });
6635
- }); // Seems not feasible to accurately simulate
6636
-
6637
- /* istanbul ignore next */
6638
-
6639
- reader.addEventListener('error', function () {
6640
- reject(reader.error);
6641
- });
6642
- reader.readAsBinaryString(f);
6643
- });
6644
- }
6645
-
6646
- }
6647
- };
6648
-
6649
- const filelist = {
6650
- file: file.file,
6651
- filelist: {
6652
- test(x) {
6653
- return Typeson.toStringTag(x) === 'FileList';
6654
- },
6655
-
6656
- replace(fl) {
6657
- const arr = [];
6658
-
6659
- for (let i = 0; i < fl.length; i++) {
6660
- arr[i] = fl.item(i);
6661
- }
6662
-
6663
- return arr;
6664
- },
6665
-
6666
- revive(o) {
6667
- /**
6668
- * `FileList` polyfill.
6669
- */
6670
- class FileList {
6671
- /**
6672
- * Set private properties and length.
6673
- */
6674
- constructor() {
6675
- // eslint-disable-next-line prefer-rest-params
6676
- this._files = arguments[0];
6677
- this.length = this._files.length;
6678
- }
6679
- /**
6680
- * @param {Integer} index
6681
- * @returns {File}
6682
- */
6683
-
6684
-
6685
- item(index) {
6686
- return this._files[index];
6687
- }
6688
- /* eslint-disable class-methods-use-this */
6689
-
6690
- /**
6691
- * @returns {"FileList"}
6692
- */
6693
-
6694
-
6695
- get [Symbol.toStringTag]() {
6696
- /* eslint-enable class-methods-use-this */
6697
- return 'FileList';
6698
- }
6699
-
6700
- }
6701
-
6702
- return new FileList(o);
6703
- }
6704
-
6705
- }
6706
- };
6707
-
6708
- /* globals createImageBitmap */
6709
- const imagebitmap = {
6710
- imagebitmap: {
6711
- test(x) {
6712
- return Typeson.toStringTag(x) === 'ImageBitmap' || // In Node, our polyfill sets the dataset on a canvas
6713
- // element as JSDom no longer allows overriding toStringTag
6714
- x && x.dataset && x.dataset.toStringTag === 'ImageBitmap';
6715
- },
6716
-
6717
- replace(bm) {
6718
- const canvas = document.createElement('canvas');
6719
- const ctx = canvas.getContext('2d');
6720
- ctx.drawImage(bm, 0, 0); // Although `width` and `height` are part of `ImageBitMap`,
6721
- // these will be auto-created for us when reviving with the
6722
- // data URL (and they are not settable even if they weren't)
6723
- // return {
6724
- // width: bm.width, height: bm.height, dataURL: canvas.toDataURL()
6725
- // };
6726
-
6727
- return canvas.toDataURL();
6728
- },
6729
-
6730
- revive(o) {
6731
- /*
6732
- var req = new XMLHttpRequest();
6733
- req.open('GET', o, false); // Sync
6734
- if (req.status !== 200 && req.status !== 0) {
6735
- throw new Error('Bad ImageBitmap access: ' + req.status);
6736
- }
6737
- req.send();
6738
- return req.responseText;
6739
- */
6740
- const canvas = document.createElement('canvas');
6741
- const ctx = canvas.getContext('2d');
6742
- const img = document.createElement('img'); // The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
6743
-
6744
- img.addEventListener('load', function () {
6745
- ctx.drawImage(img, 0, 0);
6746
- });
6747
- img.src = o; // Works in contexts allowing an `ImageBitmap` (We might use
6748
- // `OffscreenCanvas.transferToBitmap` when supported)
6749
-
6750
- return canvas;
6751
- },
6752
-
6753
- reviveAsync(o) {
6754
- const canvas = document.createElement('canvas');
6755
- const ctx = canvas.getContext('2d');
6756
- const img = document.createElement('img'); // The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
6757
-
6758
- img.addEventListener('load', function () {
6759
- ctx.drawImage(img, 0, 0);
6760
- });
6761
- img.src = o; // o.dataURL;
6762
-
6763
- return createImageBitmap(canvas); // Returns a promise
6764
- }
6765
-
6766
- }
6767
- };
6768
-
6769
- /* globals ImageData */
6770
- const imagedata = {
6771
- imagedata: {
6772
- test(x) {
6773
- return Typeson.toStringTag(x) === 'ImageData';
6774
- },
6775
-
6776
- replace(d) {
6777
- return {
6778
- // Ensure `length` gets preserved for revival
6779
- array: [...d.data],
6780
- width: d.width,
6781
- height: d.height
6782
- };
6783
- },
4885
+ return void 0 === _ && s.push([a, r.slice(1), c, f]), _;
4886
+ }
6784
4887
 
6785
- revive(o) {
6786
- return new ImageData(new Uint8ClampedArray(o.array), o.width, o.height);
4888
+ return [].concat(p).reduce(function reducer(t, r) {
4889
+ return hasConstructorOf(t, e) ? t.then(function (e) {
4890
+ return reducer(e, r);
4891
+ }) : executeReviver(r, t);
4892
+ }, r);
4893
+ }
4894
+ }("", t, null), y.length && (p = e.resolve(p).then(function (t) {
4895
+ return e.all([t].concat(y));
4896
+ }).then(function (e) {
4897
+ return _slicedToArray(e, 1)[0];
4898
+ }))), isThenable(p) ? a && r.throwOnBadSyncType ? function () {
4899
+ throw new TypeError("Sync method requested but async result obtained");
4900
+ }() : hasConstructorOf(p, e) ? p.p.then(checkUndefined) : p : !a && r.throwOnBadSyncType ? function () {
4901
+ throw new TypeError("Async method requested but sync result obtained");
4902
+ }() : a ? checkUndefined(p) : Promise.resolve(checkUndefined(p));
6787
4903
  }
6788
-
6789
- }
6790
- };
6791
-
6792
- const infinity = {
6793
- infinity: {
6794
- test(x) {
6795
- return x === Number.POSITIVE_INFINITY;
6796
- },
6797
-
6798
- replace(n) {
6799
- return 'Infinity';
6800
- },
6801
-
6802
- revive(s) {
6803
- return Number.POSITIVE_INFINITY;
4904
+ }, {
4905
+ key: "reviveSync",
4906
+ value: function reviveSync(e, t) {
4907
+ return this.revive(e, _objectSpread2(_objectSpread2({
4908
+ throwOnBadSyncType: !0
4909
+ }, t), {}, {
4910
+ sync: !0
4911
+ }));
6804
4912
  }
4913
+ }, {
4914
+ key: "reviveAsync",
4915
+ value: function reviveAsync(e, t) {
4916
+ return this.revive(e, _objectSpread2(_objectSpread2({
4917
+ throwOnBadSyncType: !0
4918
+ }, t), {}, {
4919
+ sync: !1
4920
+ }));
4921
+ }
4922
+ }, {
4923
+ key: "register",
4924
+ value: function register(e, t) {
4925
+ var r = this;
4926
+ t = t || {};
4927
+
4928
+ var n = function R(e) {
4929
+ i(e) ? e.forEach(function (e) {
4930
+ return R(e);
4931
+ }) : e && o(e).forEach(function (n) {
4932
+ if ("#" === n) throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");
4933
+ if (f.includes(n)) throw new TypeError("Plain JSON object types are reserved as type names");
4934
+ var a = e[n],
4935
+ o = a && a.testPlainObjects ? r.plainObjectReplacers : r.nonplainObjectReplacers,
4936
+ s = o.filter(function (e) {
4937
+ return e.type === n;
4938
+ });
6805
4939
 
6806
- }
6807
- };
6808
-
6809
- const IntlCollator = {
6810
- test(x) {
6811
- return Typeson.hasConstructorOf(x, Intl.Collator);
6812
- },
6813
-
6814
- replace(c) {
6815
- return c.resolvedOptions();
6816
- },
6817
-
6818
- revive(options) {
6819
- return new Intl.Collator(options.locale, options);
6820
- }
4940
+ if (s.length && (o.splice(o.indexOf(s[0]), 1), delete r.revivers[n], delete r.types[n]), "function" == typeof a) {
4941
+ var c = a;
4942
+ a = {
4943
+ test: function test(e) {
4944
+ return e && e.constructor === c;
4945
+ },
4946
+ replace: function replace(e) {
4947
+ return _objectSpread2({}, e);
4948
+ },
4949
+ revive: function revive(e) {
4950
+ return Object.assign(Object.create(c.prototype), e);
4951
+ }
4952
+ };
4953
+ } else if (i(a)) {
4954
+ var u = _slicedToArray(a, 3);
6821
4955
 
6822
- };
6823
- const IntlDateTimeFormat = {
6824
- test(x) {
6825
- return Typeson.hasConstructorOf(x, Intl.DateTimeFormat);
6826
- },
4956
+ a = {
4957
+ test: u[0],
4958
+ replace: u[1],
4959
+ revive: u[2]
4960
+ };
4961
+ }
6827
4962
 
6828
- replace(dtf) {
6829
- return dtf.resolvedOptions();
6830
- },
4963
+ if (a && a.test) {
4964
+ var l = {
4965
+ type: n,
4966
+ test: a.test.bind(a)
4967
+ };
4968
+ a.replace && (l.replace = a.replace.bind(a)), a.replaceAsync && (l.replaceAsync = a.replaceAsync.bind(a));
4969
+ var y = "number" == typeof t.fallback ? t.fallback : t.fallback ? 0 : Number.POSITIVE_INFINITY;
4970
+
4971
+ if (a.testPlainObjects ? r.plainObjectReplacers.splice(y, 0, l) : r.nonplainObjectReplacers.splice(y, 0, l), a.revive || a.reviveAsync) {
4972
+ var p = {};
4973
+ a.revive && (p.revive = a.revive.bind(a)), a.reviveAsync && (p.reviveAsync = a.reviveAsync.bind(a)), r.revivers[n] = [p, {
4974
+ plain: a.testPlainObjects
4975
+ }];
4976
+ }
6831
4977
 
6832
- revive(options) {
6833
- return new Intl.DateTimeFormat(options.locale, options);
6834
- }
4978
+ r.types[n] = a;
4979
+ }
4980
+ });
4981
+ };
6835
4982
 
6836
- };
6837
- const IntlNumberFormat = {
6838
- test(x) {
6839
- return Typeson.hasConstructorOf(x, Intl.NumberFormat);
6840
- },
4983
+ return [].concat(e).forEach(function (e) {
4984
+ return n(e);
4985
+ }), this;
4986
+ }
4987
+ }]), Typeson;
4988
+ }(),
4989
+ l = _createClass(function Undefined() {
4990
+ _classCallCheck(this, Undefined);
4991
+ });
6841
4992
 
6842
- replace(nf) {
6843
- return nf.resolvedOptions();
6844
- },
4993
+ l.__typeson__type__ = "TypesonUndefined";
6845
4994
 
6846
- revive(options) {
6847
- return new Intl.NumberFormat(options.locale, options);
6848
- }
4995
+ for (var f = ["null", "boolean", "number", "string", "array", "object"], y = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", p = new Uint8Array(256), d = 0; d < y.length; d++) p[y.codePointAt(d)] = d;
6849
4996
 
6850
- };
6851
- const intlTypes = {
6852
- IntlCollator,
6853
- IntlDateTimeFormat,
6854
- IntlNumberFormat
6855
- };
4997
+ var v = function encode(e, t, r) {
4998
+ null == r && (r = e.byteLength);
6856
4999
 
6857
- const map = {
6858
- map: {
6859
- test(x) {
6860
- return Typeson.toStringTag(x) === 'Map';
6861
- },
5000
+ for (var n = new Uint8Array(e, t || 0, r), a = n.length, o = "", i = 0; i < a; i += 3) o += y[n[i] >> 2], o += y[(3 & n[i]) << 4 | n[i + 1] >> 4], o += y[(15 & n[i + 1]) << 2 | n[i + 2] >> 6], o += y[63 & n[i + 2]];
6862
5001
 
6863
- replace(mp) {
6864
- return [...mp.entries()];
6865
- },
5002
+ return a % 3 == 2 ? o = o.slice(0, -1) + "=" : a % 3 == 1 && (o = o.slice(0, -2) + "=="), o;
5003
+ },
5004
+ b = function decode(e) {
5005
+ var t,
5006
+ r,
5007
+ n,
5008
+ a,
5009
+ o = e.length,
5010
+ i = .75 * e.length,
5011
+ s = 0;
5012
+ "=" === e[e.length - 1] && (i--, "=" === e[e.length - 2] && i--);
6866
5013
 
6867
- revive(entries) {
6868
- return new Map(entries);
6869
- }
5014
+ for (var c = new ArrayBuffer(i), u = new Uint8Array(c), l = 0; l < o; l += 4) t = p[e.codePointAt(l)], r = p[e.codePointAt(l + 1)], n = p[e.codePointAt(l + 2)], a = p[e.codePointAt(l + 3)], u[s++] = t << 2 | r >> 4, u[s++] = (15 & r) << 4 | n >> 2, u[s++] = (3 & n) << 6 | 63 & a;
6870
5015
 
6871
- }
5016
+ return c;
6872
5017
  };
6873
5018
 
6874
- const nan = {
6875
- nan: {
6876
- test(x) {
6877
- return Number.isNaN(x);
6878
- },
6879
-
6880
- replace(n) {
6881
- return 'NaN';
5019
+ const h = {
5020
+ arraybuffer: {
5021
+ test: e => "ArrayBuffer" === toStringTag(e),
5022
+
5023
+ replace(e, t) {
5024
+ t.buffers || (t.buffers = []);
5025
+ const r = t.buffers.indexOf(e);
5026
+ return r > -1 ? {
5027
+ index: r
5028
+ } : (t.buffers.push(e), v(e));
6882
5029
  },
6883
5030
 
6884
- revive(s) {
6885
- return Number.NaN;
5031
+ revive(e, t) {
5032
+ if (t.buffers || (t.buffers = []), "object" == typeof e) return t.buffers[e.index];
5033
+ const r = b(e);
5034
+ return t.buffers.push(r), r;
6886
5035
  }
6887
5036
 
6888
5037
  }
5038
+ },
5039
+ g = {
5040
+ bigintObject: {
5041
+ test: e => "object" == typeof e && hasConstructorOf(e, BigInt),
5042
+ replace: e => String(e),
5043
+ revive: e => new Object(BigInt(e))
5044
+ }
5045
+ },
5046
+ m = {
5047
+ bigint: {
5048
+ test: e => "bigint" == typeof e,
5049
+ replace: e => String(e),
5050
+ revive: e => BigInt(e)
5051
+ }
6889
5052
  };
6890
5053
 
6891
- const negativeInfinity = {
6892
- negativeInfinity: {
6893
- test(x) {
6894
- return x === Number.NEGATIVE_INFINITY;
6895
- },
5054
+ function string2arraybuffer(e) {
5055
+ const t = new Uint8Array(e.length);
6896
5056
 
6897
- replace(n) {
6898
- return '-Infinity';
6899
- },
5057
+ for (let r = 0; r < e.length; r++) t[r] = e.charCodeAt(r);
6900
5058
 
6901
- revive(s) {
6902
- return Number.NEGATIVE_INFINITY;
6903
- }
5059
+ return t.buffer;
5060
+ }
6904
5061
 
6905
- }
6906
- };
5062
+ const O = {
5063
+ blob: {
5064
+ test: e => "Blob" === toStringTag(e),
6907
5065
 
6908
- const nonbuiltinIgnore = {
6909
- nonbuiltinIgnore: {
6910
- test(x) {
6911
- return x && typeof x === 'object' && !Array.isArray(x) && !['Object', // `Proxy` and `Reflect`, two other built-in objects, will also
6912
- // have a `toStringTag` of `Object`; we don't want built-in
6913
- // function objects, however
6914
- 'Boolean', 'Number', 'String', 'Error', 'RegExp', 'Math', 'Date', 'Map', 'Set', 'JSON', 'ArrayBuffer', 'SharedArrayBuffer', 'DataView', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'Promise', 'String Iterator', 'Array Iterator', 'Map Iterator', 'Set Iterator', 'WeakMap', 'WeakSet', 'Atomics', 'Module'].includes(Typeson.toStringTag(x));
5066
+ replace(e) {
5067
+ const t = new XMLHttpRequest();
5068
+ if (t.overrideMimeType("text/plain; charset=x-user-defined"), t.open("GET", URL.createObjectURL(e), !1), t.send(), 200 !== t.status && 0 !== t.status) throw new Error("Bad Blob access: " + t.status);
5069
+ return {
5070
+ type: e.type,
5071
+ stringContents: t.responseText
5072
+ };
6915
5073
  },
6916
5074
 
6917
- replace(rexp) {// Not in use
6918
- }
6919
-
5075
+ revive: ({
5076
+ type: e,
5077
+ stringContents: t
5078
+ }) => new Blob([string2arraybuffer(t)], {
5079
+ type: e
5080
+ }),
5081
+ replaceAsync: t => new e((e, r) => {
5082
+ const n = new FileReader();
5083
+ n.addEventListener("load", () => {
5084
+ e({
5085
+ type: t.type,
5086
+ stringContents: n.result
5087
+ });
5088
+ }), n.addEventListener("error", () => {
5089
+ r(n.error);
5090
+ }), n.readAsBinaryString(t);
5091
+ })
6920
5092
  }
6921
5093
  };
6922
5094
 
6923
- // This module is for objectified primitives (such as `new Number(3)` or
6924
- const primitiveObjects = {
6925
- // String Object (not primitive string which need no type spec)
6926
- StringObject: {
6927
- test(x) {
6928
- return Typeson.toStringTag(x) === 'String' && typeof x === 'object';
6929
- },
6930
-
6931
- replace(s) {
6932
- return String(s);
6933
- },
5095
+ const w = {
5096
+ cryptokey: {
5097
+ test: e => "CryptoKey" === toStringTag(e) && e.extractable,
5098
+ replaceAsync: t => new e( /*#__PURE__*/function () {
5099
+ var _ref = _asyncToGenerator(function* (e, r) {
5100
+ let n;
6934
5101
 
6935
- // convert to primitive string
6936
- revive(s) {
6937
- return new String(s);
6938
- } // Revive to an objectified string
5102
+ try {
5103
+ n = yield crypto.subtle.exportKey("jwk", t);
5104
+ } catch (e) {
5105
+ return void r(e);
5106
+ }
6939
5107
 
5108
+ e({
5109
+ jwk: n,
5110
+ algorithm: t.algorithm,
5111
+ usages: t.usages
5112
+ });
5113
+ });
6940
5114
 
6941
- },
6942
- // Boolean Object (not primitive boolean which need no type spec)
6943
- BooleanObject: {
6944
- test(x) {
6945
- return Typeson.toStringTag(x) === 'Boolean' && typeof x === 'object';
6946
- },
5115
+ return function (_x, _x2) {
5116
+ return _ref.apply(this, arguments);
5117
+ };
5118
+ }()),
5119
+ revive: ({
5120
+ jwk: e,
5121
+ algorithm: t,
5122
+ usages: r
5123
+ }) => crypto.subtle.importKey("jwk", e, t, !0, r)
5124
+ }
5125
+ },
5126
+ A = {
5127
+ dataview: {
5128
+ test: e => "DataView" === toStringTag(e),
6947
5129
 
6948
- replace(b) {
6949
- return Boolean(b);
5130
+ replace({
5131
+ buffer: e,
5132
+ byteOffset: t,
5133
+ byteLength: r
5134
+ }, n) {
5135
+ n.buffers || (n.buffers = []);
5136
+ const a = n.buffers.indexOf(e);
5137
+ return a > -1 ? {
5138
+ index: a,
5139
+ byteOffset: t,
5140
+ byteLength: r
5141
+ } : (n.buffers.push(e), {
5142
+ encoded: v(e),
5143
+ byteOffset: t,
5144
+ byteLength: r
5145
+ });
6950
5146
  },
6951
5147
 
6952
- // convert to primitive boolean
6953
- revive(b) {
6954
- // Revive to an objectified Boolean
6955
- return new Boolean(b);
5148
+ revive(e, t) {
5149
+ t.buffers || (t.buffers = []);
5150
+ const {
5151
+ byteOffset: r,
5152
+ byteLength: n,
5153
+ encoded: a,
5154
+ index: o
5155
+ } = e;
5156
+ let i;
5157
+ return "index" in e ? i = t.buffers[o] : (i = b(a), t.buffers.push(i)), new DataView(i, r, n);
6956
5158
  }
6957
5159
 
6958
- },
6959
- // Number Object (not primitive number which need no type spec)
6960
- NumberObject: {
6961
- test(x) {
6962
- return Typeson.toStringTag(x) === 'Number' && typeof x === 'object';
6963
- },
6964
-
6965
- replace(n) {
6966
- return Number(n);
6967
- },
6968
-
6969
- // convert to primitive number
6970
- revive(n) {
6971
- return new Number(n);
6972
- } // Revive to an objectified number
6973
-
6974
-
6975
5160
  }
6976
- };
5161
+ },
5162
+ j = {
5163
+ date: {
5164
+ test: e => "Date" === toStringTag(e),
6977
5165
 
6978
- const regexp = {
6979
- regexp: {
6980
- test(x) {
6981
- return Typeson.toStringTag(x) === 'RegExp';
5166
+ replace(e) {
5167
+ const t = e.getTime();
5168
+ return Number.isNaN(t) ? "NaN" : t;
6982
5169
  },
6983
5170
 
6984
- replace(rexp) {
5171
+ revive: e => "NaN" === e ? new Date(Number.NaN) : new Date(e)
5172
+ }
5173
+ },
5174
+ I = "undefined" == typeof self ? global : self,
5175
+ P = {};
5176
+ ["TypeError", "RangeError", "SyntaxError", "ReferenceError", "EvalError", "URIError", "InternalError"].forEach(e => {
5177
+ const t = I[e];
5178
+ t && (P[e.toLowerCase()] = {
5179
+ test: e => hasConstructorOf(e, t),
5180
+ replace: e => e.message,
5181
+ revive: e => new t(e)
5182
+ });
5183
+ });
5184
+ const N = {
5185
+ file: {
5186
+ test: e => "File" === toStringTag(e),
5187
+
5188
+ replace(e) {
5189
+ const t = new XMLHttpRequest();
5190
+ if (t.overrideMimeType("text/plain; charset=x-user-defined"), t.open("GET", URL.createObjectURL(e), !1), t.send(), 200 !== t.status && 0 !== t.status) throw new Error("Bad File access: " + t.status);
6985
5191
  return {
6986
- source: rexp.source,
6987
- flags: (rexp.global ? 'g' : '') + (rexp.ignoreCase ? 'i' : '') + (rexp.multiline ? 'm' : '') + (rexp.sticky ? 'y' : '') + (rexp.unicode ? 'u' : '')
5192
+ type: e.type,
5193
+ stringContents: t.responseText,
5194
+ name: e.name,
5195
+ lastModified: e.lastModified
6988
5196
  };
6989
5197
  },
6990
5198
 
6991
- revive({
6992
- source,
6993
- flags
6994
- }) {
6995
- return new RegExp(source, flags);
6996
- }
5199
+ revive: ({
5200
+ name: e,
5201
+ type: t,
5202
+ stringContents: r,
5203
+ lastModified: n
5204
+ }) => new File([string2arraybuffer(r)], e, {
5205
+ type: t,
5206
+ lastModified: n
5207
+ }),
5208
+ replaceAsync: t => new e(function (e, r) {
5209
+ const n = new FileReader();
5210
+ n.addEventListener("load", function () {
5211
+ e({
5212
+ type: t.type,
5213
+ stringContents: n.result,
5214
+ name: t.name,
5215
+ lastModified: t.lastModified
5216
+ });
5217
+ }), n.addEventListener("error", function () {
5218
+ r(n.error);
5219
+ }), n.readAsBinaryString(t);
5220
+ })
5221
+ }
5222
+ },
5223
+ C = {
5224
+ file: N.file,
5225
+ filelist: {
5226
+ test: e => "FileList" === toStringTag(e),
6997
5227
 
6998
- }
6999
- };
5228
+ replace(e) {
5229
+ const t = [];
7000
5230
 
7001
- // Here we allow the exact same non-plain object, function, and symbol
7002
- const resurrectableObjectsByUUID = {};
7003
- const resurrectable = {
7004
- resurrectable: {
7005
- test(x) {
7006
- return x && !Array.isArray(x) && ['object', 'function', 'symbol'].includes(typeof x);
7007
- },
5231
+ for (let r = 0; r < e.length; r++) t[r] = e.item(r);
7008
5232
 
7009
- replace(rsrrctble) {
7010
- const uuid = generateUUID();
7011
- resurrectableObjectsByUUID[uuid] = rsrrctble;
7012
- return uuid;
5233
+ return t;
7013
5234
  },
7014
5235
 
7015
- revive(serializedResurrectable) {
7016
- return resurrectableObjectsByUUID[serializedResurrectable];
7017
- }
5236
+ revive(e) {
5237
+ class FileList {
5238
+ constructor() {
5239
+ this._files = arguments[0], this.length = this._files.length;
5240
+ }
7018
5241
 
7019
- }
7020
- };
5242
+ item(e) {
5243
+ return this._files[e];
5244
+ }
7021
5245
 
7022
- const set = {
7023
- set: {
7024
- test(x) {
7025
- return Typeson.toStringTag(x) === 'Set';
7026
- },
5246
+ get [Symbol.toStringTag]() {
5247
+ return "FileList";
5248
+ }
7027
5249
 
7028
- replace(st) {
7029
- return [...st.values()];
7030
- },
5250
+ }
7031
5251
 
7032
- revive(values) {
7033
- return new Set(values);
5252
+ return new FileList(e);
7034
5253
  }
7035
5254
 
7036
5255
  }
7037
- };
7038
-
7039
- /* eslint-env browser, node */
7040
- /* istanbul ignore next */
7041
-
7042
- const _global$1 = typeof self === 'undefined' ? global : self; // Support all kinds of typed arrays (views of ArrayBuffers)
7043
-
7044
-
7045
- const typedArraysSocketIO = {};
7046
- ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array'].forEach(function (typeName) {
7047
- const arrType = typeName;
7048
- const TypedArray = _global$1[typeName];
7049
- /* istanbul ignore if */
7050
-
7051
- if (!TypedArray) {
7052
- return;
7053
- }
5256
+ },
5257
+ E = {
5258
+ imagebitmap: {
5259
+ test: e => "ImageBitmap" === toStringTag(e) || e && e.dataset && "ImageBitmap" === e.dataset.toStringTag,
7054
5260
 
7055
- typedArraysSocketIO[typeName.toLowerCase()] = {
7056
- test(x) {
7057
- return Typeson.toStringTag(x) === arrType;
5261
+ replace(e) {
5262
+ const t = document.createElement("canvas");
5263
+ return t.getContext("2d").drawImage(e, 0, 0), t.toDataURL();
7058
5264
  },
7059
5265
 
7060
- replace(a) {
7061
- return (a.byteOffset === 0 && a.byteLength === a.buffer.byteLength ? a // socket.io supports streaming ArrayBuffers.
7062
- // If we have a typed array representing a portion
7063
- // of the buffer, we need to clone
7064
- // the buffer before leaving it to socket.io.
7065
- : a.slice(0)).buffer;
5266
+ revive(e) {
5267
+ const t = document.createElement("canvas"),
5268
+ r = t.getContext("2d"),
5269
+ n = document.createElement("img");
5270
+ return n.addEventListener("load", function () {
5271
+ r.drawImage(n, 0, 0);
5272
+ }), n.src = e, t;
7066
5273
  },
7067
5274
 
7068
- revive(buf) {
7069
- // One may configure socket.io to revive binary data as
7070
- // Buffer or Blob.
7071
- // We should therefore not rely on that the instance we
7072
- // get here is an ArrayBuffer
7073
- // If not, let's assume user wants to receive it as
7074
- // configured with socket.io.
7075
- return Typeson.toStringTag(buf) === 'ArrayBuffer' ? new TypedArray(buf) : buf;
5275
+ reviveAsync(e) {
5276
+ const t = document.createElement("canvas"),
5277
+ r = t.getContext("2d"),
5278
+ n = document.createElement("img");
5279
+ return n.addEventListener("load", function () {
5280
+ r.drawImage(n, 0, 0);
5281
+ }), n.src = e, createImageBitmap(t);
7076
5282
  }
7077
5283
 
7078
- };
7079
- });
7080
-
7081
- /* eslint-env browser, node */
7082
- /* istanbul ignore next */
7083
-
7084
- const _global = typeof self === 'undefined' ? global : self;
7085
-
7086
- const typedArrays = {};
7087
- ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array'].forEach(function (typeName) {
7088
- const arrType = typeName;
7089
- const TypedArray = _global[arrType];
7090
- /* istanbul ignore if */
7091
-
7092
- if (!TypedArray) {
7093
- return;
7094
5284
  }
7095
-
7096
- typedArrays[typeName.toLowerCase()] = {
7097
- test(x) {
7098
- return Typeson.toStringTag(x) === arrType;
7099
- },
5285
+ },
5286
+ x = {
5287
+ imagedata: {
5288
+ test: e => "ImageData" === toStringTag(e),
5289
+ replace: e => ({
5290
+ array: [...e.data],
5291
+ width: e.width,
5292
+ height: e.height
5293
+ }),
5294
+ revive: e => new ImageData(new Uint8ClampedArray(e.array), e.width, e.height)
5295
+ }
5296
+ },
5297
+ k = {
5298
+ infinity: {
5299
+ test: e => e === Number.POSITIVE_INFINITY,
5300
+ replace: e => "Infinity",
5301
+ revive: e => Number.POSITIVE_INFINITY
5302
+ }
5303
+ },
5304
+ B = {
5305
+ test: e => hasConstructorOf(e, Intl.Collator),
5306
+ replace: e => e.resolvedOptions(),
5307
+ revive: e => new Intl.Collator(e.locale, e)
5308
+ },
5309
+ U = {
5310
+ IntlCollator: B,
5311
+ IntlDateTimeFormat: {
5312
+ test: e => hasConstructorOf(e, Intl.DateTimeFormat),
5313
+ replace: e => e.resolvedOptions(),
5314
+ revive: e => new Intl.DateTimeFormat(e.locale, e)
5315
+ },
5316
+ IntlNumberFormat: {
5317
+ test: e => hasConstructorOf(e, Intl.NumberFormat),
5318
+ replace: e => e.resolvedOptions(),
5319
+ revive: e => new Intl.NumberFormat(e.locale, e)
5320
+ }
5321
+ },
5322
+ K = {
5323
+ map: {
5324
+ test: e => "Map" === toStringTag(e),
5325
+ replace: e => [...e.entries()],
5326
+ revive: e => new Map(e)
5327
+ }
5328
+ },
5329
+ L = {
5330
+ nan: {
5331
+ test: e => Number.isNaN(e),
5332
+ replace: e => "NaN",
5333
+ revive: e => Number.NaN
5334
+ }
5335
+ },
5336
+ F = {
5337
+ negativeInfinity: {
5338
+ test: e => e === Number.NEGATIVE_INFINITY,
5339
+ replace: e => "-Infinity",
5340
+ revive: e => Number.NEGATIVE_INFINITY
5341
+ }
5342
+ },
5343
+ M = {
5344
+ StringObject: {
5345
+ test: e => "String" === toStringTag(e) && "object" == typeof e,
5346
+ replace: e => String(e),
5347
+ revive: e => new String(e)
5348
+ },
5349
+ BooleanObject: {
5350
+ test: e => "Boolean" === toStringTag(e) && "object" == typeof e,
5351
+ replace: e => Boolean(e),
5352
+ revive: e => new Boolean(e)
5353
+ },
5354
+ NumberObject: {
5355
+ test: e => "Number" === toStringTag(e) && "object" == typeof e,
5356
+ replace: e => Number(e),
5357
+ revive: e => new Number(e)
5358
+ }
5359
+ },
5360
+ $ = {
5361
+ regexp: {
5362
+ test: e => "RegExp" === toStringTag(e),
5363
+ replace: e => ({
5364
+ source: e.source,
5365
+ flags: (e.global ? "g" : "") + (e.ignoreCase ? "i" : "") + (e.multiline ? "m" : "") + (e.sticky ? "y" : "") + (e.unicode ? "u" : "")
5366
+ }),
5367
+ revive: ({
5368
+ source: e,
5369
+ flags: t
5370
+ }) => new RegExp(e, t)
5371
+ }
5372
+ },
5373
+ Y = {
5374
+ set: {
5375
+ test: e => "Set" === toStringTag(e),
5376
+ replace: e => [...e.values()],
5377
+ revive: e => new Set(e)
5378
+ }
5379
+ },
5380
+ q = "undefined" == typeof self ? global : self,
5381
+ W = {};
5382
+ ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array"].forEach(function (e) {
5383
+ const t = e,
5384
+ r = q[e];
5385
+ r && (W[e.toLowerCase()] = {
5386
+ test: e => toStringTag(e) === t,
5387
+ replace: e => (0 === e.byteOffset && e.byteLength === e.buffer.byteLength ? e : e.slice(0)).buffer,
5388
+ revive: e => "ArrayBuffer" === toStringTag(e) ? new r(e) : e
5389
+ });
5390
+ });
5391
+ const G = "undefined" == typeof self ? global : self,
5392
+ H = {};
5393
+ ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array"].forEach(function (e) {
5394
+ const t = e,
5395
+ r = G[t];
5396
+ r && (H[e.toLowerCase()] = {
5397
+ test: e => toStringTag(e) === t,
7100
5398
 
7101
5399
  replace({
7102
- buffer,
7103
- byteOffset,
7104
- length: l
7105
- }, stateObj) {
7106
- if (!stateObj.buffers) {
7107
- stateObj.buffers = [];
7108
- }
7109
-
7110
- const index = stateObj.buffers.indexOf(buffer);
7111
-
7112
- if (index > -1) {
7113
- return {
7114
- index,
7115
- byteOffset,
7116
- length: l
7117
- };
7118
- }
7119
-
7120
- stateObj.buffers.push(buffer);
7121
- return {
7122
- encoded: encode$1(buffer),
7123
- byteOffset,
7124
- length: l
7125
- };
5400
+ buffer: e,
5401
+ byteOffset: t,
5402
+ length: r
5403
+ }, n) {
5404
+ n.buffers || (n.buffers = []);
5405
+ const a = n.buffers.indexOf(e);
5406
+ return a > -1 ? {
5407
+ index: a,
5408
+ byteOffset: t,
5409
+ length: r
5410
+ } : (n.buffers.push(e), {
5411
+ encoded: v(e),
5412
+ byteOffset: t,
5413
+ length: r
5414
+ });
7126
5415
  },
7127
5416
 
7128
- revive(b64Obj, stateObj) {
7129
- if (!stateObj.buffers) {
7130
- stateObj.buffers = [];
7131
- }
7132
-
5417
+ revive(e, t) {
5418
+ t.buffers || (t.buffers = []);
7133
5419
  const {
7134
- byteOffset,
7135
- length: len,
7136
- encoded,
7137
- index
7138
- } = b64Obj;
7139
- let buffer;
7140
-
7141
- if ('index' in b64Obj) {
7142
- buffer = stateObj.buffers[index];
7143
- } else {
7144
- buffer = decode$1(encoded);
7145
- stateObj.buffers.push(buffer);
7146
- }
7147
-
7148
- return new TypedArray(buffer, byteOffset, len);
5420
+ byteOffset: n,
5421
+ length: a,
5422
+ encoded: o,
5423
+ index: i
5424
+ } = e;
5425
+ let s;
5426
+ return "index" in e ? s = t.buffers[i] : (s = b(o), t.buffers.push(s)), new r(s, n, a);
7149
5427
  }
7150
5428
 
7151
- };
5429
+ });
7152
5430
  });
7153
-
7154
- // This does not preserve `undefined` in sparse arrays; see the `undefined`
7155
- const undef$1 = {
5431
+ const X = {
7156
5432
  undef: {
7157
- test(x, stateObj) {
7158
- return typeof x === 'undefined' && (stateObj.ownKeys || !('ownKeys' in stateObj));
7159
- },
7160
-
7161
- replace(n) {
7162
- return 0;
7163
- },
7164
-
7165
- revive(s) {
7166
- // Will add `undefined` (returning `undefined` would instead
7167
- // avoid explicitly setting)
7168
- return new Typeson.Undefined();
7169
- }
7170
-
5433
+ test: (e, t) => void 0 === e && (t.ownKeys || !("ownKeys" in t)),
5434
+ replace: e => 0,
5435
+ revive: e => new l()
7171
5436
  }
7172
- };
7173
-
7174
- const userObject = {
5437
+ },
5438
+ z = {
7175
5439
  userObject: {
7176
- test(x, stateObj) {
7177
- return Typeson.isUserObject(x);
7178
- },
7179
-
7180
- replace(n) {
7181
- return _objectSpread2$1({}, n);
7182
- },
7183
-
7184
- revive(s) {
7185
- return s;
7186
- }
7187
-
5440
+ test: (e, t) => isUserObject(e),
5441
+ replace: e => _objectSpread2$1({}, e),
5442
+ revive: e => e
7188
5443
  }
7189
- };
7190
-
7191
- const arrayNonindexKeys = [{
5444
+ },
5445
+ Q = [{
7192
5446
  arrayNonindexKeys: {
7193
- testPlainObjects: true,
7194
-
7195
- test(x, stateObj) {
7196
- if (Array.isArray(x)) {
7197
- if ( // By avoiding serializing arrays into objects which
7198
- // have only positive-integer keys, we reduce
7199
- // size and improve revival performance; arrays with
7200
- // non-index keys will be larger however
7201
- Object.keys(x).some(k => {
7202
- // No need to check for `isNaN` or
7203
- // `isNaN(Number.parseInt())` as `NaN` will be
7204
- // treated as a string.
7205
- // No need to do check as
7206
- // `Number.parseInt(Number())` since scientific
7207
- // notation will be pre-resolved if a number
7208
- // was given, and it will otherwise be a string
7209
- return String(Number.parseInt(k)) !== k;
7210
- })) {
7211
- stateObj.iterateIn = 'object';
7212
- stateObj.addLength = true;
7213
- }
5447
+ testPlainObjects: !0,
5448
+ test: (e, t) => !!Array.isArray(e) && (Object.keys(e).some(e => String(Number.parseInt(e)) !== e) && (t.iterateIn = "object", t.addLength = !0), !0),
5449
+ replace: (e, t) => (t.iterateUnsetNumeric = !0, e),
7214
5450
 
7215
- return true;
7216
- }
7217
-
7218
- return false;
7219
- },
7220
-
7221
- replace(a, stateObj) {
7222
- // Catch sparse undefined
7223
- stateObj.iterateUnsetNumeric = true;
7224
- return a;
7225
- },
7226
-
7227
- revive(o) {
7228
- if (Array.isArray(o)) {
7229
- return o;
7230
- }
7231
-
7232
- const arr = []; // No map here as may be a sparse array (including
7233
- // with `length` set)
7234
- // Todo: Reenable when Node `engines` >= 7
7235
- // Object.entries(o).forEach(([key, val]) => {
7236
-
7237
- Object.keys(o).forEach(key => {
7238
- const val = o[key];
7239
- arr[key] = val;
7240
- });
7241
- return arr;
5451
+ revive(e) {
5452
+ if (Array.isArray(e)) return e;
5453
+ const t = [];
5454
+ return Object.keys(e).forEach(r => {
5455
+ const n = e[r];
5456
+ t[r] = n;
5457
+ }), t;
7242
5458
  }
7243
5459
 
7244
5460
  }
7245
5461
  }, {
7246
5462
  sparseUndefined: {
7247
- test(x, stateObj) {
7248
- return typeof x === 'undefined' && stateObj.ownKeys === false;
7249
- },
7250
-
7251
- replace(n) {
7252
- return 0;
7253
- },
7254
-
7255
- revive(s) {
7256
- return undefined;
7257
- } // Will avoid adding anything
7258
-
7259
-
7260
- }
7261
- }];
7262
-
7263
- const specialNumbers = [nan, infinity, negativeInfinity];
7264
-
7265
- /* This preset includes types that are built-in into the JavaScript
7266
- language itself, this should work universally.
7267
-
7268
- Types that were added in ES6 or beyond will be checked before inclusion
7269
- so that this module can be consumed by both ES5 and ES6 environments.
7270
-
7271
- Some types cannot be encapsulated because their inner state is private:
7272
- `WeakMap`, `WeakSet`.
7273
-
7274
- The Function type is not included because their closures would not be
7275
- serialized, so a revived Function that uses closures would not behave
7276
- as expected.
7277
-
7278
- Symbols are similarly not included.
7279
- */
7280
- const expObj$1 = [undef$1, // ES5
7281
- arrayNonindexKeys, primitiveObjects, specialNumbers, date, error, errors, regexp].concat( // ES2015 (ES6)
7282
-
7283
- /* istanbul ignore next */
7284
- typeof Map === 'function' ? map : [],
7285
- /* istanbul ignore next */
7286
- typeof Set === 'function' ? set : [],
7287
- /* istanbul ignore next */
7288
- typeof ArrayBuffer === 'function' ? arraybuffer : [],
7289
- /* istanbul ignore next */
7290
- typeof Uint8Array === 'function' ? typedArrays : [],
7291
- /* istanbul ignore next */
7292
- typeof DataView === 'function' ? dataview : [],
7293
- /* istanbul ignore next */
7294
- typeof Intl !== 'undefined' ? intlTypes : [],
7295
- /* istanbul ignore next */
7296
- typeof BigInt !== 'undefined' ? [bigint, bigintObject] : []);
7297
-
7298
- /*
7299
- When communicating via `postMessage()` (`Worker.postMessage()` or
7300
- `window.postMessage()`), the browser will use a similar algorithm as Typeson
7301
- does to encapsulate and revive all items in the structure (aka the structured
7302
- clone algorithm). This algorithm supports all built-in types as well as many
7303
- DOM types. Therefore, only types that are not included in the structured clone
7304
- algorithm need to be registered, which is:
7305
-
7306
- * Error
7307
- * Specific Errors like SyntaxError, TypeError, etc.
7308
- * Any custom type you want to send across window- or worker boundraries
7309
-
7310
- This preset will only include the Error types and you can register your
7311
- custom types after having registered these.
7312
- */
7313
- const postmessage = [error, errors];
7314
-
7315
- const socketio = [expObj$1, // Leave ArrayBuffer as is, and let socket.io stream it instead.
7316
- {
7317
- arraybuffer: null
7318
- }, // Encapsulate TypedArrays in ArrayBuffers instead of base64 strings.
7319
- typedArraysSocketIO];
7320
-
7321
- const sparseUndefined = [{
7322
- sparseArrays: {
7323
- testPlainObjects: true,
7324
-
7325
- test(x) {
7326
- return Array.isArray(x);
7327
- },
5463
+ test: (e, t) => void 0 === e && !1 === t.ownKeys,
5464
+ replace: e => 0,
7328
5465
 
7329
- replace(a, stateObj) {
7330
- stateObj.iterateUnsetNumeric = true;
7331
- return a;
7332
- }
5466
+ revive(e) {}
7333
5467
 
7334
5468
  }
7335
- }, {
7336
- sparseUndefined: {
7337
- test(x, stateObj) {
7338
- return typeof x === 'undefined' && stateObj.ownKeys === false;
7339
- },
7340
-
7341
- replace(n) {
7342
- return 0;
7343
- },
7344
-
7345
- revive(s) {
7346
- return undefined;
7347
- } // Will avoid adding anything
7348
-
7349
-
7350
- }
7351
- }];
7352
-
7353
- /* This preset includes types for the Structured Cloning Algorithm. */
7354
- const expObj = [// Todo: Might also register synchronous `ImageBitmap` and
7355
- // `Blob`/`File`/`FileList`?
7356
- // ES5
7357
- userObject, // Processed last (non-builtin)
7358
- undef$1, arrayNonindexKeys, primitiveObjects, specialNumbers, date, regexp, // Non-built-ins
7359
- imagedata, imagebitmap, // Async return
7360
- file, filelist, blob].concat( // ES2015 (ES6)
7361
-
7362
- /* istanbul ignore next */
7363
- typeof Map === 'function' ? map : [],
7364
- /* istanbul ignore next */
7365
- typeof Set === 'function' ? set : [],
7366
- /* istanbul ignore next */
7367
- typeof ArrayBuffer === 'function' ? arraybuffer : [],
7368
- /* istanbul ignore next */
7369
- typeof Uint8Array === 'function' ? typedArrays : [],
7370
- /* istanbul ignore next */
7371
- typeof DataView === 'function' ? dataview : [],
7372
- /* istanbul ignore next */
7373
- typeof Intl !== 'undefined' ? intlTypes : [],
7374
- /* istanbul ignore next */
7375
- typeof crypto !== 'undefined' ? cryptokey : [],
7376
- /* istanbul ignore next */
7377
- typeof BigInt !== 'undefined' ? [bigint, bigintObject] : []);
7378
-
7379
- /* globals DOMException */
7380
- var structuredCloningThrowing = expObj.concat({
5469
+ }],
5470
+ Z = [L, k, F],
5471
+ ae = [z, X, Q, M, Z, j, $, x, E, N, C, O].concat("function" == typeof Map ? K : [], "function" == typeof Set ? Y : [], "function" == typeof ArrayBuffer ? h : [], "function" == typeof Uint8Array ? H : [], "function" == typeof DataView ? A : [], "undefined" != typeof Intl ? U : [], "undefined" != typeof crypto ? w : [], "undefined" != typeof BigInt ? [m, g] : []);
5472
+ var oe = ae.concat({
7381
5473
  checkDataCloneException: {
7382
- test(val) {
7383
- // Should also throw with:
7384
- // 1. `IsDetachedBuffer` (a process not called within the
7385
- // ECMAScript spec)
7386
- // 2. `IsCallable` (covered by `typeof === 'function'` or a
7387
- // function's `toStringTag`)
7388
- // 3. internal slots besides [[Prototype]] or [[Extensible]] (e.g.,
7389
- // [[PromiseState]] or [[WeakMapData]])
7390
- // 4. exotic object (e.g., `Proxy`) (unless an `%ObjectPrototype%`
7391
- // intrinsic object) (which does not have default
7392
- // behavior for one or more of the essential internal methods
7393
- // that are limited to the following for non-function objects
7394
- // (we auto-exclude functions):
7395
- // [[GetPrototypeOf]],[[SetPrototypeOf]],[[IsExtensible]],
7396
- // [[PreventExtensions]],[[GetOwnProperty]],
7397
- // [[DefineOwnProperty]],[[HasProperty]],
7398
- // [[Get]],[[Set]],[[Delete]],[[OwnPropertyKeys]]);
7399
- // except for the standard, built-in exotic objects, we'd need
7400
- // to know whether these methods had distinct behaviors
7401
- // Note: There is no apparent way for us to detect a `Proxy` and
7402
- // reject (Chrome at least is not rejecting anyways)
7403
- const stringTag = {}.toString.call(val).slice(8, -1);
7404
-
7405
- if ([// Symbol's `toStringTag` is only "Symbol" for its initial
7406
- // value, so we check `typeof`
7407
- 'symbol', // All functions including bound function exotic objects
7408
- 'function'].includes(typeof val) || [// A non-array exotic object
7409
- 'Arguments', // A non-array exotic object
7410
- 'Module', // `Error` and other errors have the [[ErrorData]] internal
7411
- // slot and give "Error"
7412
- 'Error', // Promise instances have an extra slot ([[PromiseState]])
7413
- // but not throwing in Chrome `postMessage`
7414
- 'Promise', // WeakMap instances have an extra slot ([[WeakMapData]])
7415
- // but not throwing in Chrome `postMessage`
7416
- 'WeakMap', // WeakSet instances have an extra slot ([[WeakSetData]])
7417
- // but not throwing in Chrome `postMessage`
7418
- 'WeakSet', // HTML-SPECIFIC
7419
- 'Event', // Also in Node `worker_threads` (currently experimental)
7420
- 'MessageChannel'].includes(stringTag) ||
7421
- /*
7422
- // isClosed is no longer documented
7423
- ((stringTag === 'Blob' || stringTag === 'File') &&
7424
- val.isClosed) ||
7425
- */
7426
- val && typeof val === 'object' && // Duck-type DOM node objects (non-array exotic?
7427
- // objects which cannot be cloned by the SCA)
7428
- typeof val.nodeType === 'number' && typeof val.insertBefore === 'function') {
7429
- throw new DOMException('The object cannot be cloned.', 'DataCloneError');
7430
- }
7431
-
7432
- return false;
5474
+ test(e) {
5475
+ const t = {}.toString.call(e).slice(8, -1);
5476
+ if (["symbol", "function"].includes(typeof e) || ["Arguments", "Module", "Error", "Promise", "WeakMap", "WeakSet", "Event", "MessageChannel"].includes(t) || e && "object" == typeof e && "number" == typeof e.nodeType && "function" == typeof e.insertBefore) throw new DOMException("The object cannot be cloned.", "DataCloneError");
5477
+ return !1;
7433
5478
  }
7434
5479
 
7435
5480
  }
7436
5481
  });
7437
5482
 
7438
- const undef = [sparseUndefined, undef$1];
7439
-
7440
- const universal = [expObj$1 // TODO: Add types that are de-facto universal even though not
7441
- // built-in into ecmasript standard.
7442
- ];
7443
-
7444
- // This file is auto-generated from `build.js`
7445
- Typeson.types = {
7446
- arraybuffer,
7447
- bigintObject,
7448
- bigint,
7449
- blob,
7450
- cloneable,
7451
- cryptokey,
7452
- dataview,
7453
- date,
7454
- error,
7455
- errors,
7456
- file,
7457
- filelist,
7458
- imagebitmap,
7459
- imagedata,
7460
- infinity,
7461
- intlTypes,
7462
- map,
7463
- nan,
7464
- negativeInfinity,
7465
- nonbuiltinIgnore,
7466
- primitiveObjects,
7467
- regexp,
7468
- resurrectable,
7469
- set,
7470
- typedArraysSocketio: typedArraysSocketIO,
7471
- typedArrays,
7472
- undef: undef$1,
7473
- userObject
7474
- };
7475
- Typeson.presets = {
7476
- arrayNonindexKeys,
7477
- builtin: expObj$1,
7478
- postmessage,
7479
- socketio,
7480
- sparseUndefined,
7481
- specialNumbers,
7482
- structuredCloningThrowing,
7483
- structuredCloning: expObj,
7484
- undef: undef,
7485
- universal
7486
- };
7487
-
7488
- let typeson = new Typeson().register(Typeson.presets.structuredCloningThrowing);
5483
+ let typeson = new u().register(oe);
7489
5484
 
7490
5485
  function register(func) {
7491
- typeson = new Typeson().register(func(Typeson.presets.structuredCloningThrowing));
5486
+ typeson = new u().register(func(oe));
7492
5487
  } // We are keeping the callback approach for now in case we wish to reexpose
7493
5488
  // `Blob`, `File`, `FileList` asynchronously (though in such a case, we
7494
5489
  // should probably refactor as a Promise)
@@ -7502,11 +5497,11 @@ function encode(obj, func) {
7502
5497
  ret = typeson.stringifySync(obj);
7503
5498
  } catch (err) {
7504
5499
  // SCA in typeson-registry using `DOMException` which is not defined (e.g., in Node)
7505
- if (Typeson.hasConstructorOf(err, ReferenceError) || // SCA in typeson-registry threw a cloning error and we are in a
5500
+ if (hasConstructorOf(err, ReferenceError) || // SCA in typeson-registry threw a cloning error and we are in a
7506
5501
  // supporting environment (e.g., the browser) where `ShimDOMException` is
7507
5502
  // an alias for `DOMException`; if typeson-registry ever uses our shim
7508
5503
  // to throw, we can use this condition alone.
7509
- Typeson.hasConstructorOf(err, ShimDOMException)) {
5504
+ hasConstructorOf(err, ShimDOMException)) {
7510
5505
  throw createDOMException('DataCloneError', 'The object cannot be cloned.');
7511
5506
  } // We should rethrow non-cloning exceptions like from
7512
5507
  // throwing getters (as in the W3C test, key-conversion-exceptions.htm)
@@ -7722,7 +5717,7 @@ IDBIndex.__createIndex = function (store, index) {
7722
5717
  throw new Error('Go to catch; ignore bad indexKey');
7723
5718
  }
7724
5719
 
7725
- indexKey = encode$2(indexKey.value, index.multiEntry);
5720
+ indexKey = encode$1(indexKey.value, index.multiEntry);
7726
5721
 
7727
5722
  if (index.unique) {
7728
5723
  if (indexValues[indexKey]) {
@@ -8123,11 +6118,11 @@ function executeFetchIndexData(count, unboundedDisallowed, index, hasKey, range,
8123
6118
  tx.executeSql(sql.join(' '), sqlValues, function (tx, data) {
8124
6119
  const records = [];
8125
6120
  let recordCount = 0;
8126
- const decode$1 = isCount ? () => {
6121
+ const decode$2 = isCount ? () => {
8127
6122
  /* */
8128
6123
  } : opType === 'key' ? record => {
8129
6124
  // Key.convertValueToKey(record.key); // Already validated before storage
8130
- return decode$2(unescapeSQLiteResponse(record.key));
6125
+ return decode$1(unescapeSQLiteResponse(record.key));
8131
6126
  } : record => {
8132
6127
  // when opType is value
8133
6128
  return decode(unescapeSQLiteResponse(record.value));
@@ -8135,11 +6130,11 @@ function executeFetchIndexData(count, unboundedDisallowed, index, hasKey, range,
8135
6130
 
8136
6131
  if (index.multiEntry) {
8137
6132
  const escapedIndexNameForKeyCol = escapeIndexNameForSQLKeyColumn(index.name);
8138
- const encodedKey = encode$2(range, index.multiEntry);
6133
+ const encodedKey = encode$1(range, index.multiEntry);
8139
6134
 
8140
6135
  for (let i = 0; i < data.rows.length; i++) {
8141
6136
  const row = data.rows.item(i);
8142
- const rowKey = decode$2(row[escapedIndexNameForKeyCol]);
6137
+ const rowKey = decode$1(row[escapedIndexNameForKeyCol]);
8143
6138
  let record;
8144
6139
 
8145
6140
  if (hasKey && (multiChecks && range.some(check => rowKey.includes(check)) || // More precise than our SQL
@@ -8154,7 +6149,7 @@ function executeFetchIndexData(count, unboundedDisallowed, index, hasKey, range,
8154
6149
  }
8155
6150
 
8156
6151
  if (record) {
8157
- records.push(decode$1(record));
6152
+ records.push(decode$2(record));
8158
6153
 
8159
6154
  if (unboundedDisallowed) {
8160
6155
  break;
@@ -8166,7 +6161,7 @@ function executeFetchIndexData(count, unboundedDisallowed, index, hasKey, range,
8166
6161
  const record = data.rows.item(i);
8167
6162
 
8168
6163
  if (record) {
8169
- records.push(decode$1(record));
6164
+ records.push(decode$2(record));
8170
6165
  }
8171
6166
  }
8172
6167
 
@@ -8196,12 +6191,12 @@ function buildFetchIndexDataSQL(nullDisallowed, index, range, opType, multiCheck
8196
6191
  range.forEach((innerKey, i) => {
8197
6192
  if (i > 0) sql.push('OR');
8198
6193
  sql.push(escapeIndexNameForSQL(index.name), "LIKE ? ESCAPE '^' ");
8199
- sqlValues.push('%' + sqlLIKEEscape(encode$2(innerKey, index.multiEntry)) + '%');
6194
+ sqlValues.push('%' + sqlLIKEEscape(encode$1(innerKey, index.multiEntry)) + '%');
8200
6195
  });
8201
6196
  sql.push(')');
8202
6197
  } else if (index.multiEntry) {
8203
6198
  sql.push('AND', escapeIndexNameForSQL(index.name), "LIKE ? ESCAPE '^'");
8204
- sqlValues.push('%' + sqlLIKEEscape(encode$2(range, index.multiEntry)) + '%');
6199
+ sqlValues.push('%' + sqlLIKEEscape(encode$1(range, index.multiEntry)) + '%');
8205
6200
  } else {
8206
6201
  const convertedRange = convertValueToKeyRange(range, nullDisallowed);
8207
6202
  setSQLForKeyRange(convertedRange, escapeIndexNameForSQL(index.name), sql, sqlValues, true, false);
@@ -8249,7 +6244,7 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
8249
6244
  } = storeProperties;
8250
6245
 
8251
6246
  for (const indexName in indexList) {
8252
- if (hasOwn$2(indexList, indexName)) {
6247
+ if (hasOwn(indexList, indexName)) {
8253
6248
  const index = IDBIndex.__createInstance(me, indexList[indexName]);
8254
6249
 
8255
6250
  me.__indexes[index.name] = index;
@@ -8655,7 +6650,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
8655
6650
  return;
8656
6651
  }
8657
6652
 
8658
- paramMap[index.__currentName] = encode$2(indexKey, index.multiEntry);
6653
+ paramMap[index.__currentName] = encode$1(indexKey, index.multiEntry);
8659
6654
  }
8660
6655
 
8661
6656
  if (index.unique) {
@@ -8685,7 +6680,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
8685
6680
  // Key.convertValueToKey(primaryKey); // Already run
8686
6681
  sqlStart.push(sqlQuote('key'), ',');
8687
6682
  sqlEnd.push('?,');
8688
- insertSqlValues.push(escapeSQLiteStatement(encode$2(clonedKeyOrCurrentNumber)));
6683
+ insertSqlValues.push(escapeSQLiteStatement(encode$1(clonedKeyOrCurrentNumber)));
8689
6684
  }
8690
6685
 
8691
6686
  Object.entries(paramMap).forEach(([key, stmt]) => {
@@ -8787,7 +6782,7 @@ IDBObjectStore.prototype.__overwrite = function (tx, key, cb, error) {
8787
6782
  // Key.convertValueToKey(key); // Already run
8788
6783
 
8789
6784
  const sql = 'DELETE FROM ' + escapeStoreNameForSQL(me.__currentName) + ' WHERE "key" = ?';
8790
- const encodedKey = encode$2(key);
6785
+ const encodedKey = encode$1(key);
8791
6786
  tx.executeSql(sql, [escapeSQLiteStatement(encodedKey)], function (tx, data) {
8792
6787
  CFG.DEBUG && console.log('Did the row with the', key, 'exist?', data.rowsAffected);
8793
6788
  cb(tx);
@@ -8886,7 +6881,7 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
8886
6881
  if (getKey) {
8887
6882
  for (let i = 0; i < data.rows.length; i++) {
8888
6883
  // Key.convertValueToKey(data.rows.item(i).key); // Already validated before storage
8889
- ret.push(decode$2(unescapeSQLiteResponse(data.rows.item(i).key), false));
6884
+ ret.push(decode$1(unescapeSQLiteResponse(data.rows.item(i).key), false));
8890
6885
  }
8891
6886
  } else {
8892
6887
  for (let i = 0; i < data.rows.length; i++) {
@@ -10439,8 +8434,8 @@ IDBCursor.__super = function IDBCursor(query, direction, store, source, keyColum
10439
8434
 
10440
8435
  if (range !== undefined) {
10441
8436
  // Encode the key range and cache the encoded values, so we don't have to re-encode them over and over
10442
- range.__lowerCached = range.lower !== undefined && encode$2(range.lower, this.__multiEntryIndex);
10443
- range.__upperCached = range.upper !== undefined && encode$2(range.upper, this.__multiEntryIndex);
8437
+ range.__lowerCached = range.lower !== undefined && encode$1(range.lower, this.__multiEntryIndex);
8438
+ range.__upperCached = range.upper !== undefined && encode$1(range.upper, this.__multiEntryIndex);
10444
8439
  }
10445
8440
 
10446
8441
  this.__gotValue = true;
@@ -10480,17 +8475,17 @@ IDBCursor.prototype.__findBasic = function (key, primaryKey, tx, success, error,
10480
8475
  if (primaryKey !== undefined) {
10481
8476
  sql.push('AND', quotedKey, op + '= ?'); // Key.convertValueToKey(primaryKey); // Already checked by `continuePrimaryKey`
10482
8477
 
10483
- sqlValues.push(encode$2(primaryKey));
8478
+ sqlValues.push(encode$1(primaryKey));
10484
8479
  }
10485
8480
 
10486
8481
  if (key !== undefined) {
10487
8482
  sql.push('AND', quotedKeyColumnName, op + '= ?'); // Key.convertValueToKey(key); // Already checked by `continue` or `continuePrimaryKey`
10488
8483
 
10489
- sqlValues.push(encode$2(key));
8484
+ sqlValues.push(encode$1(key));
10490
8485
  } else if (continueCall && me.__key !== undefined) {
10491
8486
  sql.push('AND', quotedKeyColumnName, op + ' ?'); // Key.convertValueToKey(me.__key); // Already checked when stored
10492
8487
 
10493
- sqlValues.push(encode$2(me.__key));
8488
+ sqlValues.push(encode$1(me.__key));
10494
8489
  }
10495
8490
 
10496
8491
  if (!me.__count) {
@@ -10571,17 +8566,17 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
10571
8566
  if (primaryKey !== undefined) {
10572
8567
  sql.push('AND', quotedKey, op + '= ?'); // Key.convertValueToKey(primaryKey); // Already checked by `continuePrimaryKey`
10573
8568
 
10574
- sqlValues.push(encode$2(primaryKey));
8569
+ sqlValues.push(encode$1(primaryKey));
10575
8570
  }
10576
8571
 
10577
8572
  if (key !== undefined) {
10578
8573
  sql.push('AND', quotedKeyColumnName, op + '= ?'); // Key.convertValueToKey(key); // Already checked by `continue` or `continuePrimaryKey`
10579
8574
 
10580
- sqlValues.push(encode$2(key));
8575
+ sqlValues.push(encode$1(key));
10581
8576
  } else if (me.__key !== undefined) {
10582
8577
  sql.push('AND', quotedKeyColumnName, op + ' ?'); // Key.convertValueToKey(me.__key); // Already checked when entered
10583
8578
 
10584
- sqlValues.push(encode$2(me.__key));
8579
+ sqlValues.push(encode$1(me.__key));
10585
8580
  }
10586
8581
 
10587
8582
  if (!me.__count) {
@@ -10610,7 +8605,7 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
10610
8605
 
10611
8606
  for (let i = 0; i < data.rows.length; i++) {
10612
8607
  const rowItem = data.rows.item(i);
10613
- const rowKey = decode$2(rowItem[me.__keyColumnName], true);
8608
+ const rowKey = decode$1(rowItem[me.__keyColumnName], true);
10614
8609
  const matches = findMultiEntryMatches(rowKey, me.__range);
10615
8610
  ct += matches.length;
10616
8611
  }
@@ -10623,12 +8618,12 @@ IDBCursor.prototype.__findMultiEntry = function (key, primaryKey, tx, success, e
10623
8618
 
10624
8619
  for (let i = 0; i < data.rows.length; i++) {
10625
8620
  const rowItem = data.rows.item(i);
10626
- const rowKey = decode$2(rowItem[me.__keyColumnName], true);
8621
+ const rowKey = decode$1(rowItem[me.__keyColumnName], true);
10627
8622
  const matches = findMultiEntryMatches(rowKey, me.__range);
10628
8623
 
10629
8624
  for (const matchingKey of matches) {
10630
8625
  const clone = {
10631
- matchingKey: encode$2(matchingKey, true),
8626
+ matchingKey: encode$1(matchingKey, true),
10632
8627
  key: rowItem.key
10633
8628
  };
10634
8629
  clone[me.__keyColumnName] = rowItem[me.__keyColumnName];
@@ -10750,11 +8745,11 @@ IDBCursor.prototype.__decode = function (rowItem, callback) {
10750
8745
  const encKey = unescapeSQLiteResponse(me.__multiEntryIndex ? rowItem.matchingKey : rowItem[me.__keyColumnName]);
10751
8746
  const encVal = unescapeSQLiteResponse(rowItem[me.__valueColumnName]);
10752
8747
  const encPrimaryKey = unescapeSQLiteResponse(rowItem.key);
10753
- const key = decode$2(encKey, me.__multiEntryIndex);
8748
+ const key = decode$1(encKey, me.__multiEntryIndex);
10754
8749
 
10755
8750
  const val = me.__valueDecoder.decode(encVal);
10756
8751
 
10757
- const primaryKey = decode$2(encPrimaryKey);
8752
+ const primaryKey = decode$1(encPrimaryKey);
10758
8753
  callback(key, val, primaryKey, encKey
10759
8754
  /*, encVal, encPrimaryKey */
10760
8755
  );
@@ -10837,7 +8832,7 @@ IDBCursor.prototype.__continueFinish = function (key, primaryKey, advanceState)
10837
8832
  cursorContinue(tx, args, success, error);
10838
8833
  }
10839
8834
 
10840
- if (me.__unique && !me.__multiEntryIndex && encKey === encode$2(me.key, me.__multiEntryIndex)) {
8835
+ if (me.__unique && !me.__multiEntryIndex && encKey === encode$1(me.key, me.__multiEntryIndex)) {
10841
8836
  cursorContinue(tx, args, success, error);
10842
8837
  return;
10843
8838
  }
@@ -10991,7 +8986,7 @@ IDBCursor.prototype.delete = function () {
10991
8986
  const sql = 'DELETE FROM ' + escapeStoreNameForSQL(me.__store.__currentName) + ' WHERE "key" = ?';
10992
8987
  CFG.DEBUG && console.log(sql, key, primaryKey); // Key.convertValueToKey(primaryKey); // Already checked when entered
10993
8988
 
10994
- tx.executeSql(sql, [escapeSQLiteStatement(encode$2(primaryKey))], function (tx, data) {
8989
+ tx.executeSql(sql, [escapeSQLiteStatement(encode$1(primaryKey))], function (tx, data) {
10995
8990
  if (data.rowsAffected === 1) {
10996
8991
  // We don't invalidate the cache (as we don't access it anymore
10997
8992
  // and it will set the index off)