@es-joy/jsoe 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +3 -0
- package/.eslintrc.cjs +1 -0
- package/.ncurc.cjs +9 -0
- package/CHANGES.md +4 -0
- package/demo/index.html +8 -0
- package/demo/index.js +1 -1
- package/dist/formatAndTypeChoices.d.ts +56 -0
- package/dist/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/formats/indexedDBKey.d.ts +4 -0
- package/dist/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/formats/json.d.ts +4 -0
- package/dist/formats/json.d.ts.map +1 -0
- package/dist/formats/schemaAndArbitrary.d.ts +6 -0
- package/dist/formats/schemaAndArbitrary.d.ts.map +1 -0
- package/dist/formats/schemaOnly.d.ts +6 -0
- package/dist/formats/schemaOnly.d.ts.map +1 -0
- package/dist/formats/structuredCloning.d.ts +20 -0
- package/dist/formats/structuredCloning.d.ts.map +1 -0
- package/dist/formats.d.ts +26 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/fundamentalTypes/BooleanObjectType.d.ts +8 -0
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/arrayReferenceType.d.ts +8 -0
- package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/fundamentalTypes/arrayType.d.ts +60 -0
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/fundamentalTypes/dateType.d.ts +26 -0
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/fundamentalTypes/objectReferenceType.d.ts +8 -0
- package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/regexpType.d.ts +8 -0
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/src/deepEqual.d.ts +3 -0
- package/dist/src/deepEqual.d.ts.map +1 -0
- package/dist/src/formatAndTypeChoices.d.ts +47 -0
- package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/src/formats/indexedDBKey.d.ts +9 -0
- package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/src/formats/json.d.ts +9 -0
- package/dist/src/formats/json.d.ts.map +1 -0
- package/dist/src/formats/schemaAndArbitrary.d.ts +6 -0
- package/dist/src/formats/schemaAndArbitrary.d.ts.map +1 -0
- package/dist/src/formats/schemaOnly.d.ts +6 -0
- package/dist/src/formats/schemaOnly.d.ts.map +1 -0
- package/dist/src/formats/structuredCloning.d.ts +15 -0
- package/dist/src/formats/structuredCloning.d.ts.map +1 -0
- package/dist/src/formats.d.ts +18 -0
- package/dist/src/formats.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +6 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts +6 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/dateType.d.ts +6 -0
- package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts +6 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/subTypes/blobHTMLType.d.ts +26 -0
- package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/src/subTypes/falseType.d.ts +6 -0
- package/dist/src/subTypes/falseType.d.ts.map +1 -0
- package/dist/src/subTypes/trueType.d.ts +6 -0
- package/dist/src/subTypes/trueType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialNumberSuperType.d.ts +11 -0
- package/dist/src/superTypes/SpecialNumberSuperType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialRealNumberSuperType.d.ts +6 -0
- package/dist/src/superTypes/SpecialRealNumberSuperType.d.ts.map +1 -0
- package/dist/src/typeChoices.d.ts +30 -0
- package/dist/src/typeChoices.d.ts.map +1 -0
- package/dist/src/types.d.ts +333 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/dialogs.d.ts +29 -0
- package/dist/src/utils/dialogs.d.ts.map +1 -0
- package/dist/src/utils/jsonPointer.d.ts +42 -0
- package/dist/src/utils/jsonPointer.d.ts.map +1 -0
- package/dist/src/utils/templateUtils.d.ts +59 -0
- package/dist/src/utils/templateUtils.d.ts.map +1 -0
- package/dist/src/utils/types.d.ts +2 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/subTypes/blobHTMLType.d.ts +14 -0
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/subTypes/falseType.d.ts +8 -0
- package/dist/subTypes/falseType.d.ts.map +1 -0
- package/dist/subTypes/trueType.d.ts +8 -0
- package/dist/subTypes/trueType.d.ts.map +1 -0
- package/dist/superTypes/SpecialNumberSuperType.d.ts +14 -0
- package/dist/superTypes/SpecialNumberSuperType.d.ts.map +1 -0
- package/dist/superTypes/SpecialRealNumberSuperType.d.ts +6 -0
- package/dist/superTypes/SpecialRealNumberSuperType.d.ts.map +1 -0
- package/dist/typeChoices.d.ts +103 -0
- package/dist/typeChoices.d.ts.map +1 -0
- package/dist/types.d.ts +523 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/dialogs.d.ts +109 -0
- package/dist/utils/dialogs.d.ts.map +1 -0
- package/dist/utils/jsonPointer.d.ts +46 -0
- package/dist/utils/jsonPointer.d.ts.map +1 -0
- package/dist/utils/templateUtils.d.ts +59 -0
- package/dist/utils/templateUtils.d.ts.map +1 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/vendor/jamilih/dist/jml-es.d.ts +436 -0
- package/dist/vendor/jamilih/dist/jml-es.d.ts.map +1 -0
- package/dist/vendor/typeson-registry/dist/index.d.ts +400 -0
- package/dist/vendor/typeson-registry/dist/index.d.ts.map +1 -0
- package/dist/vendor-imports.d.ts +3 -0
- package/dist/vendor-imports.d.ts.map +1 -0
- package/package.json +16 -11
- package/postorder-traversal.js +58 -0
- package/src/formatAndTypeChoices.js +95 -50
- package/src/formats/indexedDBKey.js +49 -57
- package/src/formats/json.js +47 -56
- package/src/formats/schemaOnly.js +12 -2
- package/src/formats/structuredCloning.js +162 -105
- package/src/formats.js +38 -10
- package/src/fundamentalTypes/BooleanObjectType.js +6 -4
- package/src/fundamentalTypes/NumberObjectType.js +5 -3
- package/src/fundamentalTypes/StringObjectType.js +1 -1
- package/src/fundamentalTypes/arrayReferenceType.js +29 -14
- package/src/fundamentalTypes/arrayType.js +789 -278
- package/src/fundamentalTypes/bigintType.js +2 -2
- package/src/fundamentalTypes/dateType.js +42 -14
- package/src/fundamentalTypes/nullType.js +1 -1
- package/src/fundamentalTypes/numberType.js +2 -2
- package/src/fundamentalTypes/objectReferenceType.js +7 -5
- package/src/fundamentalTypes/regexpType.js +45 -24
- package/src/fundamentalTypes/sparseUndefinedType.js +7 -1
- package/src/fundamentalTypes/stringType.js +1 -1
- package/src/fundamentalTypes/undefinedType.js +2 -2
- package/src/subTypes/blobHTMLType.js +42 -22
- package/src/subTypes/falseType.js +2 -2
- package/src/subTypes/trueType.js +2 -2
- package/src/superTypes/SpecialNumberSuperType.js +13 -6
- package/src/superTypes/SpecialRealNumberSuperType.js +11 -5
- package/src/typeChoices.js +137 -55
- package/src/types.js +309 -146
- package/src/utils/dialogs.js +98 -29
- package/src/utils/jsonPointer.js +4 -0
- package/src/utils/templateUtils.js +27 -12
- package/src/vendor-imports.js +8 -0
- package/tsconfig.json +18 -0
- package/typings/sceditor.d.ts +20 -0
- package/vendor/jamilih/dist/jml-es.js +1019 -389
- package/vendor/jamilih/dist/jml.d.ts +436 -0
- package/vendor/jamilih/package.json +136 -0
- package/vendor/typeson-registry/dist/index.js +365 -83
|
@@ -1,91 +1,103 @@
|
|
|
1
|
-
function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n);}return r}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t]);})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t));}));}return e}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n);}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,r){return (t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a,i,c=[],s=!0,u=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1;}else for(;!(s=(n=a.call(r)).done)&&(c.push(n.value),c.length!==t);s=!0);}catch(e){u=!0,o=e;}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(u)throw o}}return c}}(e,t)||_unsupportedIterableToArray(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}(e)||function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||_unsupportedIterableToArray(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);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}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(e,"string");return "symbol"==typeof t?t:String(t)}var e=_createClass((function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e);}));e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(e.prototype[Symbol.toStringTag]="TypesonPromise"),e.prototype.then=function(t,r){var n=this;return new e((function(e,o){n.p.then((function(r){e(t?t(r):r);})).catch((function(e){return r?r(e):Promise.reject(e)})).then(e,o);}))},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(t){return new e((function(e){e(t);}))},e.reject=function(t){return new e((function(e,r){r(t);}))},["all","race","allSettled"].forEach((function(t){e[t]=function(r){return new e((function(e,n){Promise[t](r.map((function(e){return e&&e.constructor&&"TypesonPromise"===e.constructor.__typeson__type__?e.p:e}))).then(e,n);}))};}));var t={}.toString,r={}.hasOwnProperty,n=Object.getPrototypeOf,o=r.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return t.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return !1;var a=n(e);if(!a)return null===t;var i=r.call(a,"constructor")&&a.constructor;return "function"!=typeof i?null===t:t===i||(null!==t&&o.call(i)===o.call(t)||"function"==typeof t&&"string"==typeof i.__typeson__type__&&i.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return !(!e||"Object"!==toStringTag(e))&&(!n(e)||hasConstructorOf(e,Object))}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return !1;var t=n(e);return !t||(hasConstructorOf(e,Object)||isUserObject(t))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/''/g,"''''").replace(/^$/,"''").replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~").replace(/^''$/,"").replace(/''''/g,"''")}function getByKeyPath(e,t){if(""===t)return e;var r=t.indexOf(".");if(r>-1){var n=e[unescapeKeyPathComponent(t.slice(0,r))];return void 0===n?void 0:getByKeyPath(n,t.slice(r+1))}return e[unescapeKeyPathComponent(t)]}function setAtKeyPath(e,t,r){if(""===t)return r;var n=t.indexOf(".");return n>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,n))],t.slice(n+1),r):(e[unescapeKeyPathComponent(t)]=r,e)}function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)}function _await(e,t,r){return r?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}var a=Object.keys,i$1=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function _async(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];try{return Promise.resolve(e.apply(this,t))}catch(e){return Promise.reject(e)}}}function nestedPathsFirst(e,t){if(""===e.keypath)return -1;var r=e.keypath.match(/\./g)||0,n=t.keypath.match(/\./g)||0;return r&&(r=r.length),n&&(n=n.length),r>n?-1:r<n?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var u=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={};}return _createClass(Typeson,[{key:"stringify",value:function stringify(e,t,r,n){n=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),n),{},{stringification:!0});var o=this.encapsulate(e,null,n);return i$1(o)?JSON.stringify(o[0],t,r):o.then((function(e){return JSON.stringify(e,t,r)}))}},{key:"stringifySync",value:function stringifySync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!1}))}},{key:"parse",value:function parse(e,t,r){return r=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),r),{},{parse:!0}),this.revive(JSON.parse(e,t),r)}},{key:"parseSync",value:function parseSync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.returnTypeNames=!0,this.encapsulate(e,t,r)}},{key:"rootTypeName",value:function rootTypeName(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.iterateNone=!0,this.encapsulate(e,t,r)}},{key:"encapsulate",value:function encapsulate(t,r,n){var o=_async((function(t,r){return _await(Promise.all(r.map((function(e){return e[1].p}))),(function(n){return _await(Promise.all(n.map(_async((function(n){var a=!1,i=[],c=_slicedToArray(r.splice(0,1),1),s=_slicedToArray(c[0],7),u=s[0],p=s[2],l=s[3],y=s[4],f=s[5],h=s[6],v=_encapsulate(u,n,p,l,i,!0,h),b=hasConstructorOf(v,e);return function _invoke(e,t){var r=e();return r&&r.then?r.then(t):t(r)}((function(){if(u&&b)return _await(v.p,(function(e){y[f]=e;var r=o(t,i);return a=!0,r}))}),(function(e){return a?e:(u?y[f]=v:t=b?v.p:v,o(t,i))}))})))),(function(){return t}))}))})),u=(n=_objectSpread2(_objectSpread2({sync:!0},this.options),n)).sync,p=this,l={},y=[],f=[],h=[],v=!("cyclic"in n)||n.cyclic,b=n.encapsulateObserver,d=_encapsulate("",t,v,r||{},h);function finish(e){var t=Object.values(l);if(n.iterateNone)return t.length?t[0]:getJSONType(e);if(t.length){if(n.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=l:e={$:e,$types:{$:l}};}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return !n.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,r){Object.assign(e,t);var n=s.map((function(t){var r=e[t];return delete e[t],r}));r(),s.forEach((function(t,r){e[t]=n[r];}));}function _encapsulate(t,r,o,s,u,h,v){var d,_={},O=_typeof(r),j=b?function(n){var a=v||s.type||getJSONType(r);b(Object.assign(n||_,{keypath:t,value:r,cyclic:o,stateObj:s,promisesData:u,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(r,e)},{type:a}));}:null;if(["string","boolean","number","undefined"].includes(O))return void 0===r||Number.isNaN(r)||r===Number.NEGATIVE_INFINITY||r===Number.POSITIVE_INFINITY||0===r?(d=s.replaced?r:replace(t,r,s,u,!1,h,j))!==r&&(_={replaced:d}):d=r,j&&j(),d;if(null===r)return j&&j(),r;if(o&&!s.iterateIn&&!s.iterateUnsetNumeric&&r&&"object"===_typeof(r)){var m=y.indexOf(r);if(!(m<0))return l[t]="#",j&&j({cyclicKeypath:f[m]}),"#"+f[m];!0===o&&(y.push(r),f.push(t));}var g,S=isPlainObject(r),P=i$1(r),T=(S||P)&&(!p.plainObjectReplacers.length||s.replaced)||s.iterateIn?r:replace(t,r,s,u,S||P,null,j);if(T!==r?(d=T,_={replaced:T}):""===t&&hasConstructorOf(r,e)?(u.push([t,r,o,s,void 0,void 0,s.type]),d=r):P&&"object"!==s.iterateIn||"array"===s.iterateIn?(g=new Array(r.length),_={clone:g}):(["function","symbol"].includes(_typeof(r))||"toJSON"in r||hasConstructorOf(r,e)||hasConstructorOf(r,Promise)||hasConstructorOf(r,ArrayBuffer))&&!S&&"object"!==s.iterateIn?d=r:(g={},s.addLength&&(g.length=r.length),_={clone:g}),j&&j(),n.iterateNone)return g||d;if(!g)return d;if(s.iterateIn){var w=function _loop(n){var a={ownKeys:c.call(r,n)};_adaptBuiltinStateObjectProperties(s,a,(function(){var a=t+(t?".":"")+escapeKeyPathComponent(n),i=_encapsulate(a,r[n],Boolean(o),s,u,h);hasConstructorOf(i,e)?u.push([a,i,Boolean(o),s,g,n,s.type]):void 0!==i&&(g[n]=i);}));};for(var A in r)w(A);j&&j({endIterateIn:!0,end:!0});}else a(r).forEach((function(n){var a=t+(t?".":"")+escapeKeyPathComponent(n);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(a,r[n],Boolean(o),s,u,h);hasConstructorOf(t,e)?u.push([a,t,Boolean(o),s,g,n,s.type]):void 0!==t&&(g[n]=t);}));})),j&&j({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=r.length,k=function _loop2(n){if(!(n in r)){var a=t+(t?".":"")+n;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(a,void 0,Boolean(o),s,u,h);hasConstructorOf(t,e)?u.push([a,t,Boolean(o),s,g,n,s.type]):void 0!==t&&(g[n]=t);}));}},N=0;N<C;N++)k(N);j&&j({endIterateUnsetNumeric:!0,end:!0});}return g}function replace(e,t,r,n,o,a,i){for(var c=o?p.plainObjectReplacers:p.nonplainObjectReplacers,s=c.length;s--;){var y=c[s];if(y.test(t,r)){var f=y.type;if(p.revivers[f]){var h=l[e];l[e]=h?[f].concat(h):f;}return Object.assign(r,{type:f,replaced:!0}),!u&&y.replaceAsync||y.replace?(i&&i({replacing:!0}),_encapsulate(e,y[u||!y.replaceAsync?"replace":"replaceAsync"](t,r),v&&"readonly",r,n,a,f)):(i&&i({typeDetected:!0}),_encapsulate(e,t,v&&"readonly",r,n,a,f))}}return t}return h.length?u&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(o(d,h)).then(finish):!u&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():n.stringification&&u?[finish(d)]:u?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"revive",value:function revive(t,r){var n=t&&t.$types;if(!n)return t;if(!0===n)return t.$;var o=(r=_objectSpread2(_objectSpread2({sync:!0},this.options),r)).sync,c=[],s={},u=!0;n.$&&isPlainObject(n.$)&&(t=t.$,n=n.$,u=!1);var l=this;function executeReviver(e,t){var r=_slicedToArray(l.revivers[e]||[],1)[0];if(!r)throw new Error("Unregistered type: "+e);return o&&!("revive"in r)?t:r[o&&r.revive?"revive":!o&&r.reviveAsync?"reviveAsync":"revive"](t,s)}var y=[];function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var f,h=function revivePlainObjects(){var r=[];if(Object.entries(n).forEach((function(e){var t=_slicedToArray(e,2),o=t[0],a=t[1];"#"!==a&&[].concat(a).forEach((function(e){_slicedToArray(l.revivers[e]||[null,{}],2)[1].plain&&(r.push({keypath:o,type:e}),delete n[o]);}));})),r.length)return r.sort(nestedPathsFirst).reduce((function reducer(r,n){var o=n.keypath,a=n.type;if(isThenable(r))return r.then((function(e){return reducer(e,{keypath:o,type:a})}));var i=getByKeyPath(t,o);if(hasConstructorOf(i=executeReviver(a,i),e))return i.then((function(e){var r=setAtKeyPath(t,o,e);r===e&&(t=r);}));var c=setAtKeyPath(t,o,i);c===i&&(t=c);}),void 0)}();return hasConstructorOf(h,e)?f=h.then((function(){return t})):(f=function _revive(t,r,o,s,l){if(!u||"$types"!==t){var f=n[t],h=i$1(r);if(h||isPlainObject(r)){var v=h?new Array(r.length):{};for(a(r).forEach((function(n){var a=_revive(t+(t?".":"")+escapeKeyPathComponent(n),r[n],o||v,v,n),i=function set(e){return hasConstructorOf(e,p)?v[n]=void 0:void 0!==e&&(v[n]=e),e};hasConstructorOf(a,e)?y.push(a.then((function(e){return i(e)}))):i(a);})),r=v;c.length;){var b=_slicedToArray(c[0],4),d=b[0],_=b[1],O=b[2],j=b[3],m=getByKeyPath(d,_);if(void 0===m)break;O[j]=m,c.splice(0,1);}}if(!f)return r;if("#"===f){var g=getByKeyPath(o,r.slice(1));return void 0===g&&c.push([o,r.slice(1),s,l]),g}return [].concat(f).reduce((function reducer(t,r){return hasConstructorOf(t,e)?t.then((function(e){return reducer(e,r)})):executeReviver(r,t)}),r)}}("",t,null),y.length&&(f=e.resolve(f).then((function(t){return e.all([t].concat(y))})).then((function(e){return _slicedToArray(e,1)[0]})))),isThenable(f)?o&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(f,e)?f.p.then(checkUndefined):f:!o&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():o?checkUndefined(f):Promise.resolve(checkUndefined(f))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!1}))}},{key:"register",value:function register(e,t){var r=this;t=t||{};var n=function R(e){i$1(e)?e.forEach((function(e){return R(e)})):e&&a(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(l.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var o=e[n],a=o&&o.testPlainObjects?r.plainObjectReplacers:r.nonplainObjectReplacers,c=a.filter((function(e){return e.type===n}));if(c.length&&(a.splice(a.indexOf(c[0]),1),delete r.revivers[n],delete r.types[n]),"function"==typeof o){var s=o;o={test:function test(e){return e&&e.constructor===s},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(s.prototype),e)}};}else if(i$1(o)){var u=_slicedToArray(o,3);o={test:u[0],replace:u[1],revive:u[2]};}if(o&&o.test){var p={type:n,test:o.test.bind(o)};o.replace&&(p.replace=o.replace.bind(o)),o.replaceAsync&&(p.replaceAsync=o.replaceAsync.bind(o));var y="number"==typeof t.fallback?t.fallback:t.fallback?0:Number.POSITIVE_INFINITY;if(o.testPlainObjects?r.plainObjectReplacers.splice(y,0,p):r.nonplainObjectReplacers.splice(y,0,p),o.revive||o.reviveAsync){var f={};o.revive&&(f.revive=o.revive.bind(o)),o.reviveAsync&&(f.reviveAsync=o.reviveAsync.bind(o)),r.revivers[n]=[f,{plain:o.testPlainObjects}];}r.types[n]=o;}}));};return [].concat(e).forEach((function(e){return n(e)})),this}}]),Typeson}(),p=_createClass((function Undefined(){_classCallCheck(this,Undefined);}));p.__typeson__type__="TypesonUndefined";var l=["null","boolean","number","string","array","object"];
|
|
1
|
+
function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n);}return r}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t]);})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t));}));}return e}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n);}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,r){return (t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],s=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1;}else for(;!(s=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);s=!0);}catch(e){u=!0,o=e;}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return c}}(e,t)||_unsupportedIterableToArray(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}(e)||function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||_unsupportedIterableToArray(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);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}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(e,"string");return "symbol"==typeof t?t:String(t)}var e=_createClass((function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e);}));e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function get(){return "TypesonPromise"}}),e.prototype.then=function(t,r){var n=this;return new e((function(e,o){n.p.then((function(r){e(t?t(r):r);})).catch((function(e){return r?r(e):Promise.reject(e)})).then(e,o);}))},e.prototype.catch=function(e){return this.then((function(){}),e)},e.resolve=function(t){return new e((function(e){e(t);}))},e.reject=function(t){return new e((function(e,r){r(t);}))},e.all=function(t){return new e((function(e,r){Promise.all(t.map((function(e){return null!=e&&e.constructor&&"__typeson__type__"in e.constructor&&"TypesonPromise"===e.constructor.__typeson__type__?e.p:e}))).then(e,r);}))},e.race=function(t){return new e((function(e,r){Promise.race(t.map((function(e){return null!=e&&e.constructor&&"__typeson__type__"in e.constructor&&"TypesonPromise"===e.constructor.__typeson__type__?e.p:e}))).then(e,r);}))},e.allSettled=function(t){return new e((function(e,r){Promise.allSettled(t.map((function(e){return null!=e&&e.constructor&&"__typeson__type__"in e.constructor&&"TypesonPromise"===e.constructor.__typeson__type__?e.p:e}))).then(e,r);}))};var t=Object.hasOwn,r=Object.getPrototypeOf;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return Object.prototype.toString.call(e).slice(8,-1)}function hasConstructorOf(e,n){if(!e||"object"!==_typeof(e))return !1;var o=r(e);if(!o)return null===n;var i=t(o,"constructor")&&o.constructor;return "function"!=typeof i?null===n:n===i||(null!==n&&Function.prototype.toString.call(i)===Function.prototype.toString.call(n)||"function"==typeof n&&"string"==typeof i.__typeson__type__&&i.__typeson__type__===n.__typeson__type__)}function isPlainObject(e){return !(!e||"Object"!==toStringTag(e))&&(!r(e)||hasConstructorOf(e,Object))}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return !1;var t=r(e);return !t||(hasConstructorOf(e,Object)||isUserObject(t))}function isObject(e){return null!==e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/''/g,"''''").replace(/^$/,"''").replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~").replace(/^''$/,"").replace(/''''/g,"''")}function getByKeyPath(e,t){if(""===t)return e;if(null===e||"object"!==_typeof(e))throw new TypeError("Unexpected non-object type");var r=t.indexOf(".");if(r>-1){var n=e[unescapeKeyPathComponent(t.slice(0,r))];return void 0===n?void 0:getByKeyPath(n,t.slice(r+1))}return e[unescapeKeyPathComponent(t)]}function setAtKeyPath(e,t,r){if(""===t)return r;if(!e||"object"!==_typeof(e))throw new TypeError("Unexpected non-object type");var n=t.indexOf(".");return n>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,n))],t.slice(n+1),r):(e[unescapeKeyPathComponent(t)]=r,e)}function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)}function _await(e,t,r){return r?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}var n=Object.keys,o=Object.hasOwn,i$1=Array.isArray,a=["type","replaced","iterateIn","iterateUnsetNumeric","addLength"];function _async(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];try{return Promise.resolve(e.apply(this,t))}catch(e){return Promise.reject(e)}}}function nestedPathsFirst(e,t){var r,n;if(""===e.keypath)return -1;var o=null!==(r=e.keypath.match(/\./g))&&void 0!==r?r:0,i=null!==(n=t.keypath.match(/\./g))&&void 0!==n?n:0;return o&&(o=o.length),i&&(i=i.length),o>i?-1:o<i?1:e.keypath<t.keypath?-1:e.keypath>t.keypath?1:0}var c=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={};}return _createClass(Typeson,[{key:"stringify",value:function stringify(e,t,r,n){n=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),n),{},{stringification:!0});var o=this.encapsulate(e,null,n);return i$1(o)?JSON.stringify(o[0],t,r):o.then((function(e){return JSON.stringify(e,t,r)}))}},{key:"stringifySync",value:function stringifySync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!1}))}},{key:"parse",value:function parse(e,t,r){return r=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),r),{},{parse:!0}),this.revive(JSON.parse(e,t),r)}},{key:"parseSync",value:function parseSync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.returnTypeNames=!0,this.encapsulate(e,t,r)}},{key:"rootTypeName",value:function rootTypeName(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.iterateNone=!0,this.encapsulate(e,t,r)}},{key:"encapsulate",value:function encapsulate(t,r,c){var s=this,u=_objectSpread2(_objectSpread2({sync:!0},this.options),c),y=u.sync,p={},l=[],f=[],v=[],h=!("cyclic"in u)||u.cyclic,d=u.encapsulateObserver,b=function finish(e){var t=Object.values(p);if(u.iterateNone)return t.length?t[0]:getJSONType(e);if(t.length){if(u.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!o(e,"$types")?e.$types=p:e={$:e,$types:{$:p}};}else isObject(e)&&o(e,"$types")&&(e={$:e,$types:!0});return !u.returnTypeNames&&e},_=_async((function(t,r){return _await(Promise.all(r.map((function(e){return e[1].p}))),(function(n){return _await(Promise.all(n.map(_async((function(n){var o=!1,i=[],a=_slicedToArray(r.splice(0,1),1),c=_slicedToArray(a[0],7),s=c[0],u=c[2],y=c[3],p=c[4],l=c[5],f=c[6],v=m(s,n,u,y,i,!0,f),h=hasConstructorOf(v,e);return function _invoke(e,t){var r=e();return r&&r.then?r.then(t):t(r)}((function(){if(s&&h)return _await(v.p,(function(e){p[l]=e;var r=_(t,i);return o=!0,r}))}),(function(e){return o?e:(s?p[l]=v:t=h?v.p:v,_(t,i))}))})))),(function(){return t}))}))})),O=function _adaptBuiltinStateObjectProperties(e,t,r){Object.assign(e,t);var n=a.map((function(t){var r=e[t];return delete e[t],r}));r(),a.forEach((function(t,r){e[t]=n[r];}));},m=function _encapsulate(t,r,a,c,y,v,h){var b,_={},m=_typeof(r),g=d?function(n){var o,i=null!==(o=null!=h?h:c.type)&&void 0!==o?o:getJSONType(r);d(Object.assign(null!=n?n:_,{keypath:t,value:r,cyclic:a,stateObj:c,promisesData:y,resolvingTypesonPromise:v,awaitingTypesonPromise:hasConstructorOf(r,e)},{type:i}));}:null;if(["string","boolean","number","undefined"].includes(m))return void 0===r||Number.isNaN(r)||r===Number.NEGATIVE_INFINITY||r===Number.POSITIVE_INFINITY||0===r?(b=c.replaced?r:j(t,r,c,y,!1,v,g))!==r&&(_={replaced:b}):b=r,g&&g(),b;if(null===r)return g&&g(),r;if(a&&!c.iterateIn&&!c.iterateUnsetNumeric&&r&&"object"===_typeof(r)){var S=l.indexOf(r);if(!(S<0))return p[t]="#",g&&g({cyclicKeypath:f[S]}),"#"+f[S];!0===a&&(l.push(r),f.push(t));}var P,T,w=isPlainObject(r),A=i$1(r),C=(w||A)&&(!s.plainObjectReplacers.length||c.replaced)||c.iterateIn?r:j(t,r,c,y,w||A,null,g);if(C!==r?(b=C,_={replaced:C}):""===t&&hasConstructorOf(r,e)?(y.push([t,r,a,c,void 0,void 0,c.type]),b=r):A&&"object"!==c.iterateIn||"array"===c.iterateIn?(P=new Array(r.length),_={clone:P}):(["function","symbol"].includes(_typeof(r))||"toJSON"in r||hasConstructorOf(r,e)||hasConstructorOf(r,Promise)||hasConstructorOf(r,ArrayBuffer))&&!w&&"object"!==c.iterateIn?b=r:(P={},c.addLength&&(P.length=r.length),_={clone:P}),g&&g(),u.iterateNone)return null!==(T=P)&&void 0!==T?T:b;if(!P)return b;if(c.iterateIn){var k=function _loop(n){var i={ownKeys:o(r,n)};O(c,i,(function(){var o=t+(t?".":"")+escapeKeyPathComponent(n),i=_encapsulate(o,r[n],Boolean(a),c,y,v);hasConstructorOf(i,e)?y.push([o,i,Boolean(a),c,P,n,c.type]):void 0!==i&&(P[n]=i);}));};for(var N in r)k(N);g&&g({endIterateIn:!0,end:!0});}else n(r).forEach((function(n){var o=t+(t?".":"")+escapeKeyPathComponent(n);O(c,{ownKeys:!0},(function(){var t=_encapsulate(o,r[n],Boolean(a),c,y,v);hasConstructorOf(t,e)?y.push([o,t,Boolean(a),c,P,n,c.type]):void 0!==t&&(P[n]=t);}));})),g&&g({endIterateOwn:!0,end:!0});if(c.iterateUnsetNumeric){for(var I=r.length,E=function _loop2(n){if(!(n in r)){var o="".concat(t).concat(t?".":"").concat(n);O(c,{ownKeys:!1},(function(){var t=_encapsulate(o,void 0,Boolean(a),c,y,v);hasConstructorOf(t,e)?y.push([o,t,Boolean(a),c,P,n,c.type]):void 0!==t&&(P[n]=t);}));}},K=0;K<I;K++)E(K);g&&g({endIterateUnsetNumeric:!0,end:!0});}return P},j=function replace(e,t,r,n,o,i,a){for(var c=o?s.plainObjectReplacers:s.nonplainObjectReplacers,u=c.length;u--;){var l=c[u];if(l.test(t,r)){var f=l.type;if(s.revivers[f]){var v=p[e];p[e]=v?[f].concat(v):f;}if(Object.assign(r,{type:f,replaced:!0}),(y||!l.replaceAsync)&&!l.replace)return a&&a({typeDetected:!0}),m(e,t,h&&"readonly",r,n,i,f);a&&a({replacing:!0});var d=void 0;if(y||!l.replaceAsync){if(void 0===l.replace)throw new TypeError("Missing replacer");d=l.replace(t,r);}else d=l.replaceAsync(t,r);return m(e,d,h&&"readonly",r,n,i,f)}}return t},g=m("",t,h,null!=r?r:{},v);if(v.length)return y&&u.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(_(g,v)).then(b);if(!y&&u.throwOnBadSyncType)throw new TypeError("Async method requested but sync result obtained");return u.stringification&&y?[b(g)]:y?b(g):Promise.resolve(b(g))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"revive",value:function revive(t,r){var o=this,a=_objectSpread2(_objectSpread2({sync:!0},this.options),r),c=a.sync;function finishRevival(e){if(c)return e;if(a.throwOnBadSyncType)throw new TypeError("Async method requested but sync result obtained");return Promise.resolve(e)}if(!t||"object"!==_typeof(t)||Array.isArray(t))return finishRevival(t);var u=t.$types;if(!0===u)return finishRevival(t.$);if(!u||"object"!==_typeof(u)||Array.isArray(u))return finishRevival(t);var y=[],p={},l=!0;u.$&&isPlainObject(u.$)&&(t=t.$,u=u.$,l=!1);var f=function executeReviver(e,t){var r,n=_slicedToArray(null!==(r=o.revivers[e])&&void 0!==r?r:[],1)[0];if(!n)throw new Error("Unregistered type: "+e);if(c&&!("revive"in n))return t;if(!c&&n.reviveAsync)return n.reviveAsync(t,p);if(n.revive)return n.revive(t,p);throw new Error("Missing reviver")},v=[];function checkUndefined(e){return hasConstructorOf(e,s)?void 0:e}var h,d=function revivePlainObjects(){var r=[];if(!u)throw new Error("Found bad `types`");if(Object.entries(u).forEach((function(e){var t=_slicedToArray(e,2),n=t[0],i=t[1];"#"!==i&&[].concat(i).forEach((function(e){var t;_slicedToArray(null!==(t=o.revivers[e])&&void 0!==t?t:[null,{}],2)[1].plain&&(r.push({keypath:n,type:e}),delete u[n]);}));})),r.length)return r.sort(nestedPathsFirst).reduce((function reducer(r,n){var o=n.keypath,i=n.type;if(isThenable(r))return r.then((function(e){return reducer(e,{keypath:o,type:i})}));var a=getByKeyPath(t,o);if(hasConstructorOf(a=f(i,a),e))return a.then((function(e){var r=setAtKeyPath(t,o,e);r===e&&(t=r);}));var c=setAtKeyPath(t,o,a);c===a&&(t=c);}),void 0)}();return hasConstructorOf(d,e)?h=d.then((function(){return t})):(h=function _revive(t,r,o,a,c){if(!l||"$types"!==t){var p=u[t],h=i$1(r);if(h||isPlainObject(r)){var d=h?new Array(r.length):{};for(n(r).forEach((function(n){var i=_revive(t+(t?".":"")+escapeKeyPathComponent(n),r[n],null!=o?o:d,d,n),a=function set(e){return hasConstructorOf(e,s)?d[n]=void 0:void 0!==e&&(d[n]=e),e};hasConstructorOf(i,e)?v.push(i.then((function(e){return a(e)}))):a(i);})),r=d;y.length;){var b=_slicedToArray(y[0],4),_=b[0],O=b[1],m=b[2],j=b[3],g=getByKeyPath(_,O);if(void 0===g)break;m[j]=g,y.splice(0,1);}}if(!p)return r;if("#"===p){var S=getByKeyPath(o,r.slice(1));return void 0===S&&y.push([o,r.slice(1),a,c]),S}return [].concat(p).reduce((function reducer(t,r){if(hasConstructorOf(t,e))return t.then((function(e){return reducer(e,r)}));if("string"!=typeof r)throw new TypeError("Bad type JSON");return f(r,t)}),r)}}("",t,null),v.length&&(h=e.resolve(h).then((function(t){return e.all([t].concat(v))})).then((function(e){return _slicedToArray(e,1)[0]})))),isThenable(h)?c&&a.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(h,e)?h.p.then(checkUndefined):h:!c&&a.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():c?checkUndefined(h):Promise.resolve(checkUndefined(h))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!1}))}},{key:"register",value:function register(e,t){var r=this,o=null!=t?t:{},a=function R(e){i$1(e)?e.forEach((function(e){return R(e)})):n(e).forEach((function(t){var n;if("#"===t)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(u.includes(t))throw new TypeError("Plain JSON object types are reserved as type names");var a=e[t],c=a&&"function"!=typeof a&&!Array.isArray(a)&&a.testPlainObjects?r.plainObjectReplacers:r.nonplainObjectReplacers,s=c.filter((function(e){return e.type===t}));if(s.length&&(c.splice(c.indexOf(s[0]),1),delete r.revivers[t],delete r.types[t]),"function"==typeof a){var y=a;a={test:function test(e){return e&&e.constructor===y},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(y.prototype),e)}};}else if(i$1(a)){var p=_slicedToArray(a,3);a={test:p[0],replace:p[1],revive:p[2]};}if(null!==(n=a)&&void 0!==n&&n.test){var l={type:t,test:a.test.bind(a)};a.replace&&(l.replace=a.replace.bind(a)),a.replaceAsync&&(l.replaceAsync=a.replaceAsync.bind(a));var f="number"==typeof o.fallback?o.fallback:o.fallback?0:Number.POSITIVE_INFINITY;if(a.testPlainObjects?r.plainObjectReplacers.splice(f,0,l):r.nonplainObjectReplacers.splice(f,0,l),a.revive||a.reviveAsync){var v={};a.revive&&(v.revive=a.revive.bind(a)),a.reviveAsync&&(v.reviveAsync=a.reviveAsync.bind(a)),r.revivers[t]=[v,{plain:a.testPlainObjects}];}r.types[t]=a;}}));};return [].concat(e).forEach((function(e){return a(e)})),this}}]),Typeson}(),s=_createClass((function Undefined(){_classCallCheck(this,Undefined);}));s.__typeson__type__="TypesonUndefined";var u=["null","boolean","number","string","array","object"];
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* base64-arraybuffer
|
|
5
5
|
* https://github.com/niklasvh/base64-arraybuffer
|
|
6
6
|
*
|
|
7
|
-
* Copyright (c) 2017 Brett Zamir, 2012 Niklas von Hertzen
|
|
7
|
+
* Copyright (c) 2017-2023 Brett Zamir, 2012 Niklas von Hertzen
|
|
8
8
|
* Licensed under the MIT license.
|
|
9
9
|
*/
|
|
10
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {number} Integer
|
|
13
|
+
*/
|
|
13
14
|
|
|
15
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
16
|
+
|
|
17
|
+
// Use a lookup table to find the index.
|
|
18
|
+
var lookup = new Uint8Array(256);
|
|
14
19
|
for (var i = 0; i < chars.length; i++) {
|
|
15
|
-
lookup[chars.codePointAt(i)] = i;
|
|
20
|
+
lookup[/** @type {number} */chars.codePointAt(i)] = i;
|
|
16
21
|
}
|
|
22
|
+
|
|
17
23
|
/**
|
|
18
24
|
* @param {ArrayBuffer} arraybuffer
|
|
19
|
-
* @param {Integer} byteOffset
|
|
20
|
-
* @param {Integer} lngth
|
|
25
|
+
* @param {Integer} [byteOffset]
|
|
26
|
+
* @param {Integer} [lngth]
|
|
21
27
|
* @returns {string}
|
|
22
28
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
29
|
var encode = function encode(arraybuffer, byteOffset, lngth) {
|
|
26
30
|
if (lngth === null || lngth === undefined) {
|
|
27
31
|
lngth = arraybuffer.byteLength; // Needed for Safari
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
var bytes = new Uint8Array(arraybuffer, byteOffset || 0,
|
|
34
|
+
var bytes = new Uint8Array(arraybuffer, byteOffset || 0,
|
|
35
|
+
// Default needed for Safari
|
|
31
36
|
lngth);
|
|
32
37
|
var len = bytes.length;
|
|
33
38
|
var base64 = '';
|
|
34
|
-
|
|
35
39
|
for (var _i = 0; _i < len; _i += 3) {
|
|
36
40
|
base64 += chars[bytes[_i] >> 2];
|
|
37
41
|
base64 += chars[(bytes[_i] & 3) << 4 | bytes[_i + 1] >> 4];
|
|
38
42
|
base64 += chars[(bytes[_i + 1] & 15) << 2 | bytes[_i + 2] >> 6];
|
|
39
43
|
base64 += chars[bytes[_i + 2] & 63];
|
|
40
44
|
}
|
|
41
|
-
|
|
42
45
|
if (len % 3 === 2) {
|
|
43
46
|
base64 = base64.slice(0, -1) + '=';
|
|
44
47
|
} else if (len % 3 === 1) {
|
|
45
48
|
base64 = base64.slice(0, -2) + '==';
|
|
46
49
|
}
|
|
47
|
-
|
|
48
50
|
return base64;
|
|
49
51
|
};
|
|
52
|
+
|
|
50
53
|
/**
|
|
51
54
|
* @param {string} base64
|
|
52
55
|
* @returns {ArrayBuffer}
|
|
53
56
|
*/
|
|
54
|
-
|
|
55
57
|
var decode = function decode(base64) {
|
|
56
58
|
var len = base64.length;
|
|
59
|
+
if (len % 4) {
|
|
60
|
+
throw new Error('Bad base64 length: not divisible by four');
|
|
61
|
+
}
|
|
57
62
|
var bufferLength = base64.length * 0.75;
|
|
58
63
|
var p = 0;
|
|
59
64
|
var encoded1, encoded2, encoded3, encoded4;
|
|
60
|
-
|
|
61
65
|
if (base64[base64.length - 1] === '=') {
|
|
62
66
|
bufferLength--;
|
|
63
|
-
|
|
64
67
|
if (base64[base64.length - 2] === '=') {
|
|
65
68
|
bufferLength--;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
|
-
|
|
69
71
|
var arraybuffer = new ArrayBuffer(bufferLength),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
bytes = new Uint8Array(arraybuffer);
|
|
72
73
|
for (var _i2 = 0; _i2 < len; _i2 += 4) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
// We know the result will not be undefined, as we have a text
|
|
75
|
+
// length divisible by four
|
|
76
|
+
encoded1 = lookup[/** @type {number} */base64.codePointAt(_i2)];
|
|
77
|
+
encoded2 = lookup[/** @type {number} */base64.codePointAt(_i2 + 1)];
|
|
78
|
+
encoded3 = lookup[/** @type {number} */base64.codePointAt(_i2 + 2)];
|
|
79
|
+
encoded4 = lookup[/** @type {number} */base64.codePointAt(_i2 + 3)];
|
|
77
80
|
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
|
|
78
81
|
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
|
|
79
82
|
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
|
|
80
83
|
}
|
|
81
|
-
|
|
82
84
|
return arraybuffer;
|
|
83
85
|
};
|
|
84
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @type {import('typeson').TypeSpecSet}
|
|
89
|
+
*/
|
|
85
90
|
const arraybuffer = {
|
|
86
91
|
arraybuffer: {
|
|
87
92
|
test (x) { return toStringTag(x) === 'ArrayBuffer'; },
|
|
88
|
-
replace (
|
|
93
|
+
replace (
|
|
94
|
+
b,
|
|
95
|
+
/**
|
|
96
|
+
* @type {import('typeson').StateObject &
|
|
97
|
+
* {buffers?: ArrayBuffer[]}}
|
|
98
|
+
*/
|
|
99
|
+
stateObj
|
|
100
|
+
) {
|
|
89
101
|
if (!stateObj.buffers) {
|
|
90
102
|
stateObj.buffers = [];
|
|
91
103
|
}
|
|
@@ -96,14 +108,26 @@ const arraybuffer = {
|
|
|
96
108
|
stateObj.buffers.push(b);
|
|
97
109
|
return encode(b);
|
|
98
110
|
},
|
|
99
|
-
revive (
|
|
111
|
+
revive (
|
|
112
|
+
b64,
|
|
113
|
+
/**
|
|
114
|
+
* @type {import('typeson').StateObject &
|
|
115
|
+
* {buffers?: ArrayBuffer[]}}
|
|
116
|
+
*/
|
|
117
|
+
stateObj
|
|
118
|
+
) {
|
|
100
119
|
if (!stateObj.buffers) {
|
|
101
120
|
stateObj.buffers = [];
|
|
102
121
|
}
|
|
103
122
|
if (typeof b64 === 'object') {
|
|
104
|
-
return stateObj.buffers[
|
|
123
|
+
return stateObj.buffers[
|
|
124
|
+
/**
|
|
125
|
+
* @type {{index: import('typeson').Integer}}
|
|
126
|
+
*/
|
|
127
|
+
(b64).index
|
|
128
|
+
];
|
|
105
129
|
}
|
|
106
|
-
const buffer = decode(b64);
|
|
130
|
+
const buffer = decode(/** @type {string} */ (b64));
|
|
107
131
|
stateObj.buffers.push(buffer);
|
|
108
132
|
return buffer;
|
|
109
133
|
}
|
|
@@ -114,6 +138,9 @@ const arraybuffer = {
|
|
|
114
138
|
|
|
115
139
|
/* globals BigInt */
|
|
116
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @type {import('typeson').TypeSpecSet}
|
|
143
|
+
*/
|
|
117
144
|
const bigintObject = {
|
|
118
145
|
bigintObject: {
|
|
119
146
|
test (x) {
|
|
@@ -123,27 +150,33 @@ const bigintObject = {
|
|
|
123
150
|
revive (s) {
|
|
124
151
|
// Filed this to avoid error: https://github.com/eslint/eslint/issues/11810
|
|
125
152
|
// eslint-disable-next-line no-new-object
|
|
126
|
-
return new Object(BigInt(s));
|
|
153
|
+
return new Object(BigInt(/** @type {string} */ (s)));
|
|
127
154
|
}
|
|
128
155
|
}
|
|
129
156
|
};
|
|
130
157
|
|
|
131
158
|
/* globals BigInt */
|
|
132
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @type {import('typeson').TypeSpecSet}
|
|
162
|
+
*/
|
|
133
163
|
const bigint = {
|
|
134
164
|
bigint: {
|
|
135
165
|
test (x) {
|
|
136
166
|
return typeof x === 'bigint';
|
|
137
167
|
},
|
|
138
168
|
replace: String,
|
|
139
|
-
|
|
169
|
+
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
170
|
+
revive (s) {
|
|
171
|
+
return BigInt(/** @type {string} */ (s));
|
|
172
|
+
}
|
|
140
173
|
}
|
|
141
174
|
};
|
|
142
175
|
|
|
143
176
|
/**
|
|
144
177
|
* Not currently in use internally, but provided for parity.
|
|
145
178
|
* @param {ArrayBuffer} buf
|
|
146
|
-
* @returns {
|
|
179
|
+
* @returns {string}
|
|
147
180
|
*/
|
|
148
181
|
|
|
149
182
|
/**
|
|
@@ -209,6 +242,9 @@ function string2arraybuffer (str) {
|
|
|
209
242
|
|
|
210
243
|
/* globals XMLHttpRequest, Blob, FileReader */
|
|
211
244
|
|
|
245
|
+
/**
|
|
246
|
+
* @type {import('typeson').TypeSpecSet}
|
|
247
|
+
*/
|
|
212
248
|
const blob = {
|
|
213
249
|
blob: {
|
|
214
250
|
test (x) { return toStringTag(x) === 'Blob'; },
|
|
@@ -228,7 +264,10 @@ const blob = {
|
|
|
228
264
|
stringContents: req.responseText
|
|
229
265
|
};
|
|
230
266
|
},
|
|
231
|
-
revive (
|
|
267
|
+
revive (obj) {
|
|
268
|
+
const {
|
|
269
|
+
type, stringContents
|
|
270
|
+
} = /** @type {{type: string, stringContents: string}} */ (obj);
|
|
232
271
|
return new Blob([string2arraybuffer(stringContents)], {type});
|
|
233
272
|
},
|
|
234
273
|
replaceAsync (b) {
|
|
@@ -287,8 +326,14 @@ function generateUUID () { // Adapted from original: public domain/MIT: http://
|
|
|
287
326
|
});
|
|
288
327
|
}
|
|
289
328
|
|
|
329
|
+
/**
|
|
330
|
+
* @type {{[key: (symbol|string)]: any}}
|
|
331
|
+
*/
|
|
290
332
|
const cloneableObjectsByUUID = {};
|
|
291
333
|
|
|
334
|
+
/**
|
|
335
|
+
* @type {import('typeson').TypeSpecSet}
|
|
336
|
+
*/
|
|
292
337
|
const cloneable = {
|
|
293
338
|
cloneable: {
|
|
294
339
|
test (x) {
|
|
@@ -301,7 +346,11 @@ const cloneable = {
|
|
|
301
346
|
cloneableObjectsByUUID[uuid] = clonable;
|
|
302
347
|
return {uuid, encapsulated};
|
|
303
348
|
},
|
|
304
|
-
revive (
|
|
349
|
+
revive (obj) {
|
|
350
|
+
const {
|
|
351
|
+
uuid, encapsulated
|
|
352
|
+
} = /** @type {{uuid: string, encapsulated: any}} */ (obj);
|
|
353
|
+
|
|
305
354
|
return cloneableObjectsByUUID[uuid][Symbol.for('cloneRevive')](
|
|
306
355
|
encapsulated
|
|
307
356
|
);
|
|
@@ -311,13 +360,20 @@ const cloneable = {
|
|
|
311
360
|
|
|
312
361
|
/* globals crypto */
|
|
313
362
|
|
|
363
|
+
/**
|
|
364
|
+
* @type {import('typeson').TypeSpecSet}
|
|
365
|
+
*/
|
|
314
366
|
const cryptokey = {
|
|
315
367
|
cryptokey: {
|
|
316
368
|
test (x) {
|
|
317
369
|
return toStringTag(x) === 'CryptoKey' && x.extractable;
|
|
318
370
|
},
|
|
319
|
-
replaceAsync (
|
|
371
|
+
replaceAsync (
|
|
372
|
+
/** @type {CryptoKey} */
|
|
373
|
+
key
|
|
374
|
+
) {
|
|
320
375
|
return new e(async (resolve, reject) => {
|
|
376
|
+
/** @type {JsonWebKey} */
|
|
321
377
|
let jwk;
|
|
322
378
|
try {
|
|
323
379
|
jwk = await crypto.subtle.exportKey('jwk', key);
|
|
@@ -334,16 +390,39 @@ const cryptokey = {
|
|
|
334
390
|
});
|
|
335
391
|
});
|
|
336
392
|
},
|
|
337
|
-
revive (
|
|
338
|
-
|
|
393
|
+
revive (obj) {
|
|
394
|
+
const {
|
|
395
|
+
jwk, algorithm, usages
|
|
396
|
+
} = /**
|
|
397
|
+
* @type {{
|
|
398
|
+
* jwk: JsonWebKey,
|
|
399
|
+
* algorithm: KeyAlgorithm,
|
|
400
|
+
* usages: KeyUsage[]
|
|
401
|
+
* }}
|
|
402
|
+
*/ (obj);
|
|
403
|
+
|
|
404
|
+
return crypto.subtle.importKey(
|
|
405
|
+
'jwk', jwk, algorithm, true, usages
|
|
406
|
+
);
|
|
339
407
|
}
|
|
340
408
|
}
|
|
341
409
|
};
|
|
342
410
|
|
|
411
|
+
/**
|
|
412
|
+
* @type {import('typeson').TypeSpecSet}
|
|
413
|
+
*/
|
|
343
414
|
const dataview = {
|
|
344
415
|
dataview: {
|
|
345
416
|
test (x) { return toStringTag(x) === 'DataView'; },
|
|
346
|
-
replace (
|
|
417
|
+
replace (
|
|
418
|
+
{buffer, byteOffset, byteLength},
|
|
419
|
+
/**
|
|
420
|
+
* @type {import('typeson').StateObject & {
|
|
421
|
+
* buffers?: ArrayBuffer[]
|
|
422
|
+
* }}
|
|
423
|
+
*/
|
|
424
|
+
stateObj
|
|
425
|
+
) {
|
|
347
426
|
if (!stateObj.buffers) {
|
|
348
427
|
stateObj.buffers = [];
|
|
349
428
|
}
|
|
@@ -358,7 +437,15 @@ const dataview = {
|
|
|
358
437
|
byteLength
|
|
359
438
|
};
|
|
360
439
|
},
|
|
361
|
-
revive (
|
|
440
|
+
revive (
|
|
441
|
+
b64Obj,
|
|
442
|
+
/**
|
|
443
|
+
* @type {import('typeson').StateObject & {
|
|
444
|
+
* buffers?: ArrayBuffer[]
|
|
445
|
+
* }}
|
|
446
|
+
*/
|
|
447
|
+
stateObj
|
|
448
|
+
) {
|
|
362
449
|
if (!stateObj.buffers) {
|
|
363
450
|
stateObj.buffers = [];
|
|
364
451
|
}
|
|
@@ -375,6 +462,9 @@ const dataview = {
|
|
|
375
462
|
}
|
|
376
463
|
};
|
|
377
464
|
|
|
465
|
+
/**
|
|
466
|
+
* @type {import('typeson').TypeSpecSet}
|
|
467
|
+
*/
|
|
378
468
|
const date = {
|
|
379
469
|
date: {
|
|
380
470
|
test (x) { return toStringTag(x) === 'Date'; },
|
|
@@ -394,6 +484,9 @@ const date = {
|
|
|
394
484
|
}
|
|
395
485
|
};
|
|
396
486
|
|
|
487
|
+
/**
|
|
488
|
+
* @type {import('typeson').TypeSpecSet}
|
|
489
|
+
*/
|
|
397
490
|
const error = {
|
|
398
491
|
error: {
|
|
399
492
|
test (x) { return toStringTag(x) === 'Error'; },
|
|
@@ -405,13 +498,23 @@ const error = {
|
|
|
405
498
|
};
|
|
406
499
|
},
|
|
407
500
|
revive (obj) {
|
|
408
|
-
const e =
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
501
|
+
const e = /**
|
|
502
|
+
* @type {{
|
|
503
|
+
* name: string,
|
|
504
|
+
* cause: Error,
|
|
505
|
+
* stack: string,
|
|
506
|
+
* fileName?: string,
|
|
507
|
+
* lineNumber?: import('typeson').Integer,
|
|
508
|
+
* columnNumber?: import('typeson').Integer
|
|
509
|
+
* }}
|
|
510
|
+
*/ (new Error(obj.message));
|
|
511
|
+
e.name = obj.name;
|
|
512
|
+
e.cause = obj.cause;
|
|
513
|
+
e.stack = obj.stack;
|
|
514
|
+
e.fileName = obj.fileName;
|
|
515
|
+
e.lineNumber = obj.lineNumber;
|
|
516
|
+
e.columnNumber = obj.columnNumber;
|
|
517
|
+
|
|
415
518
|
return e;
|
|
416
519
|
}
|
|
417
520
|
}
|
|
@@ -419,11 +522,15 @@ const error = {
|
|
|
419
522
|
|
|
420
523
|
/* globals InternalError */
|
|
421
524
|
|
|
525
|
+
/**
|
|
526
|
+
* @type {import('typeson').TypeSpecSet}
|
|
527
|
+
*/
|
|
422
528
|
const errors = {};
|
|
423
529
|
|
|
424
530
|
// JS standard
|
|
425
531
|
[
|
|
426
|
-
TypeError, RangeError, SyntaxError, ReferenceError,
|
|
532
|
+
TypeError, RangeError, SyntaxError, ReferenceError,
|
|
533
|
+
EvalError, URIError
|
|
427
534
|
].forEach((error) => create$2(error));
|
|
428
535
|
|
|
429
536
|
/* c8 ignore next 3 */
|
|
@@ -435,11 +542,22 @@ if (typeof AggregateError !== 'undefined') {
|
|
|
435
542
|
// @ts-ignore Non-standard
|
|
436
543
|
typeof InternalError === 'function' && create$2(InternalError);
|
|
437
544
|
|
|
545
|
+
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131 */
|
|
546
|
+
/**
|
|
547
|
+
* Non-standard.
|
|
548
|
+
* @typedef {{
|
|
549
|
+
* new (message?: string, options?: ErrorOptions): EvalError;
|
|
550
|
+
* (message?: string, options?: ErrorOptions): EvalError;
|
|
551
|
+
* }} InternalErrorConstructor
|
|
552
|
+
*/
|
|
553
|
+
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131 */
|
|
554
|
+
|
|
438
555
|
/**
|
|
439
556
|
* Comprises all built-in errors.
|
|
440
|
-
* @param {
|
|
441
|
-
*
|
|
442
|
-
*
|
|
557
|
+
* @param {TypeErrorConstructor|RangeErrorConstructor|
|
|
558
|
+
* SyntaxErrorConstructor|ReferenceErrorConstructor|
|
|
559
|
+
* EvalErrorConstructor|URIErrorConstructor|
|
|
560
|
+
* AggregateErrorConstructor|InternalErrorConstructor
|
|
443
561
|
* } Ctor
|
|
444
562
|
* @returns {void}
|
|
445
563
|
*/
|
|
@@ -458,18 +576,38 @@ function create$2 (Ctor) {
|
|
|
458
576
|
revive (obj) {
|
|
459
577
|
const isAggregateError = typeof AggregateError !== 'undefined' &&
|
|
460
578
|
Ctor === AggregateError;
|
|
461
|
-
const e =
|
|
462
|
-
|
|
463
|
-
:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
579
|
+
const e = /**
|
|
580
|
+
* @type {{
|
|
581
|
+
* name: string,
|
|
582
|
+
* cause: Error,
|
|
583
|
+
* stack: string,
|
|
584
|
+
* fileName?: string,
|
|
585
|
+
* lineNumber?: import('typeson').Integer,
|
|
586
|
+
* columnNumber?: import('typeson').Integer
|
|
587
|
+
* }}
|
|
588
|
+
*/ (isAggregateError
|
|
589
|
+
? new /** @type {AggregateErrorConstructor} */ (
|
|
590
|
+
Ctor
|
|
591
|
+
)(obj.errors, obj.message)
|
|
592
|
+
: new /**
|
|
593
|
+
* @type {TypeErrorConstructor|RangeErrorConstructor|
|
|
594
|
+
* SyntaxErrorConstructor|ReferenceErrorConstructor|
|
|
595
|
+
* EvalErrorConstructor|URIErrorConstructor|
|
|
596
|
+
* InternalErrorConstructor}
|
|
597
|
+
*/ (Ctor)(obj.message));
|
|
598
|
+
|
|
599
|
+
e.name = obj.name;
|
|
600
|
+
e.cause = obj.cause;
|
|
601
|
+
e.stack = obj.stack;
|
|
602
|
+
e.fileName = obj.fileName;
|
|
603
|
+
e.lineNumber = obj.lineNumber;
|
|
604
|
+
e.columnNumber = obj.columnNumber;
|
|
605
|
+
|
|
470
606
|
/* c8 ignore next 6 */
|
|
471
607
|
if (isAggregateError) {
|
|
472
|
-
|
|
608
|
+
/** @type {AggregateError} */ (
|
|
609
|
+
e
|
|
610
|
+
).errors = obj.errors;
|
|
473
611
|
}
|
|
474
612
|
return e;
|
|
475
613
|
}
|
|
@@ -478,6 +616,9 @@ function create$2 (Ctor) {
|
|
|
478
616
|
|
|
479
617
|
/* globals XMLHttpRequest, File, FileReader */
|
|
480
618
|
|
|
619
|
+
/**
|
|
620
|
+
* @type {import('typeson').TypeSpecSet}
|
|
621
|
+
*/
|
|
481
622
|
const file = {
|
|
482
623
|
file: {
|
|
483
624
|
test (x) { return toStringTag(x) === 'File'; },
|
|
@@ -533,6 +674,9 @@ const file = {
|
|
|
533
674
|
}
|
|
534
675
|
};
|
|
535
676
|
|
|
677
|
+
/**
|
|
678
|
+
* @type {import('typeson').TypeSpecSet}
|
|
679
|
+
*/
|
|
536
680
|
const filelist = {
|
|
537
681
|
file: file.file,
|
|
538
682
|
filelist: {
|
|
@@ -558,7 +702,7 @@ const filelist = {
|
|
|
558
702
|
this.length = this._files.length;
|
|
559
703
|
}
|
|
560
704
|
/**
|
|
561
|
-
* @param {Integer} index
|
|
705
|
+
* @param {import('typeson').Integer} index
|
|
562
706
|
* @returns {File}
|
|
563
707
|
*/
|
|
564
708
|
item (index) {
|
|
@@ -580,6 +724,9 @@ const filelist = {
|
|
|
580
724
|
|
|
581
725
|
/* globals createImageBitmap */
|
|
582
726
|
|
|
727
|
+
/**
|
|
728
|
+
* @type {import('typeson').TypeSpecSet}
|
|
729
|
+
*/
|
|
583
730
|
const imagebitmap = {
|
|
584
731
|
imagebitmap: {
|
|
585
732
|
test (x) {
|
|
@@ -590,7 +737,9 @@ const imagebitmap = {
|
|
|
590
737
|
},
|
|
591
738
|
replace (bm) {
|
|
592
739
|
const canvas = document.createElement('canvas');
|
|
593
|
-
const ctx =
|
|
740
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (
|
|
741
|
+
canvas.getContext('2d')
|
|
742
|
+
);
|
|
594
743
|
ctx.drawImage(bm, 0, 0);
|
|
595
744
|
// Although `width` and `height` are part of `ImageBitMap`,
|
|
596
745
|
// these will be auto-created for us when reviving with the
|
|
@@ -611,7 +760,9 @@ const imagebitmap = {
|
|
|
611
760
|
return req.responseText;
|
|
612
761
|
*/
|
|
613
762
|
const canvas = document.createElement('canvas');
|
|
614
|
-
const ctx =
|
|
763
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (
|
|
764
|
+
canvas.getContext('2d')
|
|
765
|
+
);
|
|
615
766
|
const img = document.createElement('img');
|
|
616
767
|
// The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
|
|
617
768
|
img.addEventListener('load', function () {
|
|
@@ -624,20 +775,34 @@ const imagebitmap = {
|
|
|
624
775
|
},
|
|
625
776
|
reviveAsync (o) {
|
|
626
777
|
const canvas = document.createElement('canvas');
|
|
627
|
-
const ctx =
|
|
778
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (
|
|
779
|
+
canvas.getContext('2d')
|
|
780
|
+
);
|
|
628
781
|
const img = document.createElement('img');
|
|
629
782
|
// The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
|
|
630
783
|
img.addEventListener('load', function () {
|
|
631
784
|
ctx.drawImage(img, 0, 0);
|
|
632
785
|
});
|
|
633
786
|
img.src = o; // o.dataURL;
|
|
634
|
-
|
|
787
|
+
|
|
788
|
+
return new e(async (resolve, reject) => {
|
|
789
|
+
try {
|
|
790
|
+
const resp = await createImageBitmap(canvas);
|
|
791
|
+
resolve(resp);
|
|
792
|
+
/* c8 ignore next 3 */
|
|
793
|
+
} catch (err) {
|
|
794
|
+
reject(err);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
635
797
|
}
|
|
636
798
|
}
|
|
637
799
|
};
|
|
638
800
|
|
|
639
801
|
/* globals ImageData */
|
|
640
802
|
|
|
803
|
+
/**
|
|
804
|
+
* @type {import('typeson').TypeSpecSet}
|
|
805
|
+
*/
|
|
641
806
|
const imagedata = {
|
|
642
807
|
imagedata: {
|
|
643
808
|
test (x) { return toStringTag(x) === 'ImageData'; },
|
|
@@ -657,6 +822,9 @@ const imagedata = {
|
|
|
657
822
|
}
|
|
658
823
|
};
|
|
659
824
|
|
|
825
|
+
/**
|
|
826
|
+
* @type {import('typeson').TypeSpecSet}
|
|
827
|
+
*/
|
|
660
828
|
const infinity = {
|
|
661
829
|
infinity: {
|
|
662
830
|
test (x) { return x === Number.POSITIVE_INFINITY; },
|
|
@@ -665,12 +833,18 @@ const infinity = {
|
|
|
665
833
|
}
|
|
666
834
|
};
|
|
667
835
|
|
|
836
|
+
/**
|
|
837
|
+
* @type {import('typeson').Spec}
|
|
838
|
+
*/
|
|
668
839
|
const IntlCollator = {
|
|
669
840
|
test (x) { return hasConstructorOf(x, Intl.Collator); },
|
|
670
841
|
replace (c) { return c.resolvedOptions(); },
|
|
671
842
|
revive (options) { return new Intl.Collator(options.locale, options); }
|
|
672
843
|
};
|
|
673
844
|
|
|
845
|
+
/**
|
|
846
|
+
* @type {import('typeson').Spec}
|
|
847
|
+
*/
|
|
674
848
|
const IntlDateTimeFormat = {
|
|
675
849
|
test (x) { return hasConstructorOf(x, Intl.DateTimeFormat); },
|
|
676
850
|
replace (dtf) { return dtf.resolvedOptions(); },
|
|
@@ -679,6 +853,9 @@ const IntlDateTimeFormat = {
|
|
|
679
853
|
}
|
|
680
854
|
};
|
|
681
855
|
|
|
856
|
+
/**
|
|
857
|
+
* @type {import('typeson').Spec}
|
|
858
|
+
*/
|
|
682
859
|
const IntlNumberFormat = {
|
|
683
860
|
test (x) { return hasConstructorOf(x, Intl.NumberFormat); },
|
|
684
861
|
replace (nf) { return nf.resolvedOptions(); },
|
|
@@ -691,6 +868,9 @@ const intlTypes = {
|
|
|
691
868
|
IntlNumberFormat
|
|
692
869
|
};
|
|
693
870
|
|
|
871
|
+
/**
|
|
872
|
+
* @type {import('typeson').TypeSpecSet}
|
|
873
|
+
*/
|
|
694
874
|
const map = {
|
|
695
875
|
map: {
|
|
696
876
|
test (x) { return toStringTag(x) === 'Map'; },
|
|
@@ -699,6 +879,9 @@ const map = {
|
|
|
699
879
|
}
|
|
700
880
|
};
|
|
701
881
|
|
|
882
|
+
/**
|
|
883
|
+
* @type {import('typeson').TypeSpecSet}
|
|
884
|
+
*/
|
|
702
885
|
const nan = {
|
|
703
886
|
nan: {
|
|
704
887
|
test (x) { return Number.isNaN(x); },
|
|
@@ -707,6 +890,9 @@ const nan = {
|
|
|
707
890
|
}
|
|
708
891
|
};
|
|
709
892
|
|
|
893
|
+
/**
|
|
894
|
+
* @type {import('typeson').TypeSpecSet}
|
|
895
|
+
*/
|
|
710
896
|
const negativeInfinity = {
|
|
711
897
|
negativeInfinity: {
|
|
712
898
|
test (x) { return x === Number.NEGATIVE_INFINITY; },
|
|
@@ -715,6 +901,9 @@ const negativeInfinity = {
|
|
|
715
901
|
}
|
|
716
902
|
};
|
|
717
903
|
|
|
904
|
+
/**
|
|
905
|
+
* @type {import('typeson').TypeSpecSet}
|
|
906
|
+
*/
|
|
718
907
|
const negativeZero = {
|
|
719
908
|
negativeZero: {
|
|
720
909
|
test (x) {
|
|
@@ -730,6 +919,9 @@ const negativeZero = {
|
|
|
730
919
|
}
|
|
731
920
|
};
|
|
732
921
|
|
|
922
|
+
/**
|
|
923
|
+
* @type {import('typeson').TypeSpecSet}
|
|
924
|
+
*/
|
|
733
925
|
const nonbuiltinIgnore = {
|
|
734
926
|
nonbuiltinIgnore: {
|
|
735
927
|
test (x) {
|
|
@@ -761,6 +953,9 @@ const nonbuiltinIgnore = {
|
|
|
761
953
|
|
|
762
954
|
// This module is for objectified primitives (such as `new Number(3)` or
|
|
763
955
|
|
|
956
|
+
/**
|
|
957
|
+
* @type {import('typeson').TypeSpecSet}
|
|
958
|
+
*/
|
|
764
959
|
const primitiveObjects = {
|
|
765
960
|
// String Object (not primitive string which need no type spec)
|
|
766
961
|
StringObject: {
|
|
@@ -792,6 +987,9 @@ const primitiveObjects = {
|
|
|
792
987
|
}
|
|
793
988
|
};
|
|
794
989
|
|
|
990
|
+
/**
|
|
991
|
+
* @type {import('typeson').TypeSpecSet}
|
|
992
|
+
*/
|
|
795
993
|
const regexp = {
|
|
796
994
|
regexp: {
|
|
797
995
|
test (x) { return toStringTag(x) === 'RegExp'; },
|
|
@@ -811,8 +1009,14 @@ const regexp = {
|
|
|
811
1009
|
|
|
812
1010
|
// Here we allow the exact same non-plain object, function, and symbol
|
|
813
1011
|
|
|
1012
|
+
/**
|
|
1013
|
+
* @type {{[key: string]: any}}
|
|
1014
|
+
*/
|
|
814
1015
|
const resurrectableObjectsByUUID = {};
|
|
815
1016
|
|
|
1017
|
+
/**
|
|
1018
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1019
|
+
*/
|
|
816
1020
|
const resurrectable = {
|
|
817
1021
|
resurrectable: {
|
|
818
1022
|
test (x) {
|
|
@@ -831,25 +1035,36 @@ const resurrectable = {
|
|
|
831
1035
|
}
|
|
832
1036
|
};
|
|
833
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1040
|
+
*/
|
|
834
1041
|
const set = {
|
|
835
1042
|
set: {
|
|
836
1043
|
test (x) { return toStringTag(x) === 'Set'; },
|
|
837
1044
|
replace (st) {
|
|
838
1045
|
return [...st.values()];
|
|
839
1046
|
},
|
|
840
|
-
revive (values) {
|
|
1047
|
+
revive (values) {
|
|
1048
|
+
return new Set(values);
|
|
1049
|
+
}
|
|
841
1050
|
}
|
|
842
1051
|
};
|
|
843
1052
|
|
|
844
1053
|
/* eslint-env browser, node */
|
|
845
1054
|
|
|
846
1055
|
// Support all kinds of typed arrays (views of ArrayBuffers)
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1059
|
+
*/
|
|
847
1060
|
const typedArraysSocketIO = {};
|
|
848
1061
|
|
|
849
1062
|
/**
|
|
850
|
-
* @param {
|
|
851
|
-
*
|
|
852
|
-
*
|
|
1063
|
+
* @param {Int8ArrayConstructor|Uint8ArrayConstructor|
|
|
1064
|
+
* Uint8ClampedArrayConstructor|Int16ArrayConstructor|
|
|
1065
|
+
* Uint16ArrayConstructor|Int32ArrayConstructor|
|
|
1066
|
+
* Uint32ArrayConstructor|Float32ArrayConstructor|
|
|
1067
|
+
* Float64ArrayConstructor
|
|
853
1068
|
* } TypedArray
|
|
854
1069
|
* @returns {void}
|
|
855
1070
|
*/
|
|
@@ -900,20 +1115,42 @@ if (typeof Int8Array === 'function') {
|
|
|
900
1115
|
|
|
901
1116
|
/* eslint-env browser, node */
|
|
902
1117
|
|
|
1118
|
+
/**
|
|
1119
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1120
|
+
*/
|
|
903
1121
|
const typedArrays = {};
|
|
904
1122
|
|
|
905
1123
|
/**
|
|
906
|
-
* @
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
*
|
|
1124
|
+
* @typedef {Int8ArrayConstructor|Uint8ArrayConstructor|
|
|
1125
|
+
* Uint8ClampedArrayConstructor|
|
|
1126
|
+
* Int16ArrayConstructor|Uint16ArrayConstructor|
|
|
1127
|
+
* Int32ArrayConstructor|Uint32ArrayConstructor|
|
|
1128
|
+
* Float32ArrayConstructor|
|
|
1129
|
+
* Float64ArrayConstructor} TypedArrayConstructor
|
|
1130
|
+
*/
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* @param {TypedArrayConstructor} TypedArray
|
|
910
1134
|
* @returns {void}
|
|
911
1135
|
*/
|
|
912
1136
|
function create (TypedArray) {
|
|
913
|
-
const typeName =
|
|
1137
|
+
const typeName =
|
|
1138
|
+
/**
|
|
1139
|
+
* @type {TypedArrayConstructor & {name: string}}
|
|
1140
|
+
*/
|
|
1141
|
+
(TypedArray).name;
|
|
1142
|
+
|
|
914
1143
|
typedArrays[typeName.toLowerCase()] = {
|
|
915
1144
|
test (x) { return toStringTag(x) === typeName; },
|
|
916
|
-
replace (
|
|
1145
|
+
replace (
|
|
1146
|
+
{buffer, byteOffset, length: l},
|
|
1147
|
+
/**
|
|
1148
|
+
* @type {import('typeson').StateObject & {
|
|
1149
|
+
* buffers?: ArrayBuffer[]
|
|
1150
|
+
* }}
|
|
1151
|
+
*/
|
|
1152
|
+
stateObj
|
|
1153
|
+
) {
|
|
917
1154
|
if (!stateObj.buffers) {
|
|
918
1155
|
stateObj.buffers = [];
|
|
919
1156
|
}
|
|
@@ -928,7 +1165,15 @@ function create (TypedArray) {
|
|
|
928
1165
|
length: l
|
|
929
1166
|
};
|
|
930
1167
|
},
|
|
931
|
-
revive (
|
|
1168
|
+
revive (
|
|
1169
|
+
b64Obj,
|
|
1170
|
+
/**
|
|
1171
|
+
* @type {import('typeson').StateObject & {
|
|
1172
|
+
* buffers?: ArrayBuffer[]
|
|
1173
|
+
* }}
|
|
1174
|
+
*/
|
|
1175
|
+
stateObj
|
|
1176
|
+
) {
|
|
932
1177
|
if (!stateObj.buffers) {
|
|
933
1178
|
stateObj.buffers = [];
|
|
934
1179
|
}
|
|
@@ -963,6 +1208,9 @@ if (typeof Int8Array === 'function') {
|
|
|
963
1208
|
|
|
964
1209
|
// This does not preserve `undefined` in sparse arrays; see the `undef`
|
|
965
1210
|
|
|
1211
|
+
/**
|
|
1212
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1213
|
+
*/
|
|
966
1214
|
const undef$1 = {
|
|
967
1215
|
undef: {
|
|
968
1216
|
test (x, stateObj) {
|
|
@@ -970,14 +1218,17 @@ const undef$1 = {
|
|
|
970
1218
|
(stateObj.ownKeys || !('ownKeys' in stateObj));
|
|
971
1219
|
},
|
|
972
1220
|
replace (n) { return 0; },
|
|
973
|
-
revive (s) {
|
|
1221
|
+
revive (s$1) {
|
|
974
1222
|
// Will add `undefined` (returning `undefined` would instead
|
|
975
1223
|
// avoid explicitly setting)
|
|
976
|
-
return new
|
|
1224
|
+
return new s();
|
|
977
1225
|
}
|
|
978
1226
|
}
|
|
979
1227
|
};
|
|
980
1228
|
|
|
1229
|
+
/**
|
|
1230
|
+
* @type {import('typeson').TypeSpecSet}
|
|
1231
|
+
*/
|
|
981
1232
|
const userObject = {
|
|
982
1233
|
userObject: {
|
|
983
1234
|
test (x, stateObj) { return isUserObject(x); },
|
|
@@ -986,6 +1237,9 @@ const userObject = {
|
|
|
986
1237
|
}
|
|
987
1238
|
};
|
|
988
1239
|
|
|
1240
|
+
/**
|
|
1241
|
+
* @type {import('typeson').Preset}
|
|
1242
|
+
*/
|
|
989
1243
|
const arrayNonindexKeys = [
|
|
990
1244
|
{
|
|
991
1245
|
arrayNonindexKeys: {
|
|
@@ -1024,13 +1278,14 @@ const arrayNonindexKeys = [
|
|
|
1024
1278
|
if (Array.isArray(o)) {
|
|
1025
1279
|
return o;
|
|
1026
1280
|
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* @type {{[key: string]: any}}
|
|
1284
|
+
*/
|
|
1027
1285
|
const arr = [];
|
|
1028
1286
|
// No map here as may be a sparse array (including
|
|
1029
1287
|
// with `length` set)
|
|
1030
|
-
|
|
1031
|
-
// Object.entries(o).forEach(([key, val]) => {
|
|
1032
|
-
Object.keys(o).forEach((key) => {
|
|
1033
|
-
const val = o[key];
|
|
1288
|
+
Object.entries(o).forEach(([key, val]) => {
|
|
1034
1289
|
arr[key] = val;
|
|
1035
1290
|
});
|
|
1036
1291
|
return arr;
|
|
@@ -1048,6 +1303,9 @@ const arrayNonindexKeys = [
|
|
|
1048
1303
|
}
|
|
1049
1304
|
];
|
|
1050
1305
|
|
|
1306
|
+
/**
|
|
1307
|
+
* @type {import('typeson').Preset}
|
|
1308
|
+
*/
|
|
1051
1309
|
const specialNumbers = [
|
|
1052
1310
|
nan,
|
|
1053
1311
|
infinity,
|
|
@@ -1071,6 +1329,9 @@ const specialNumbers = [
|
|
|
1071
1329
|
Symbols are similarly not included.
|
|
1072
1330
|
*/
|
|
1073
1331
|
|
|
1332
|
+
/**
|
|
1333
|
+
* @type {import('typeson').Preset}
|
|
1334
|
+
*/
|
|
1074
1335
|
const expObj$1 = [
|
|
1075
1336
|
undef$1,
|
|
1076
1337
|
// ES5
|
|
@@ -1111,11 +1372,17 @@ This preset will only include the Error types and you can register your
|
|
|
1111
1372
|
custom types after having registered these.
|
|
1112
1373
|
*/
|
|
1113
1374
|
|
|
1375
|
+
/**
|
|
1376
|
+
* @type {import('typeson').Preset}
|
|
1377
|
+
*/
|
|
1114
1378
|
const postmessage = [
|
|
1115
1379
|
error,
|
|
1116
1380
|
errors
|
|
1117
1381
|
];
|
|
1118
1382
|
|
|
1383
|
+
/**
|
|
1384
|
+
* @type {import('typeson').Preset}
|
|
1385
|
+
*/
|
|
1119
1386
|
const socketio = [
|
|
1120
1387
|
expObj$1,
|
|
1121
1388
|
// Leave ArrayBuffer as is, and let socket.io stream it instead.
|
|
@@ -1124,6 +1391,9 @@ const socketio = [
|
|
|
1124
1391
|
typedArraysSocketIO
|
|
1125
1392
|
];
|
|
1126
1393
|
|
|
1394
|
+
/**
|
|
1395
|
+
* @type {import('typeson').Preset}
|
|
1396
|
+
*/
|
|
1127
1397
|
const sparseUndefined = [
|
|
1128
1398
|
{
|
|
1129
1399
|
sparseArrays: {
|
|
@@ -1148,6 +1418,9 @@ const sparseUndefined = [
|
|
|
1148
1418
|
|
|
1149
1419
|
/* This preset includes types for the Structured Cloning Algorithm. */
|
|
1150
1420
|
|
|
1421
|
+
/**
|
|
1422
|
+
* @type {import('typeson').Preset}
|
|
1423
|
+
*/
|
|
1151
1424
|
const expObj = [
|
|
1152
1425
|
// Todo: Might also register synchronous `ImageBitmap` and
|
|
1153
1426
|
// `Blob`/`File`/`FileList`?
|
|
@@ -1188,7 +1461,10 @@ const expObj = [
|
|
|
1188
1461
|
|
|
1189
1462
|
/* globals DOMException */
|
|
1190
1463
|
|
|
1191
|
-
|
|
1464
|
+
/**
|
|
1465
|
+
* @type {import('typeson').Preset}
|
|
1466
|
+
*/
|
|
1467
|
+
const structuredCloningThrowing = expObj.concat({
|
|
1192
1468
|
checkDataCloneException: {
|
|
1193
1469
|
test (val) {
|
|
1194
1470
|
// Should also throw with:
|
|
@@ -1263,16 +1539,22 @@ var structuredCloningThrowing = expObj.concat({
|
|
|
1263
1539
|
}
|
|
1264
1540
|
});
|
|
1265
1541
|
|
|
1542
|
+
/**
|
|
1543
|
+
* @type {import('typeson').Preset}
|
|
1544
|
+
*/
|
|
1266
1545
|
const undef = [
|
|
1267
1546
|
sparseUndefined,
|
|
1268
1547
|
undef$1
|
|
1269
1548
|
];
|
|
1270
1549
|
|
|
1550
|
+
/**
|
|
1551
|
+
* @type {import('typeson').Preset}
|
|
1552
|
+
*/
|
|
1271
1553
|
const universal = [
|
|
1272
1554
|
expObj$1
|
|
1273
1555
|
// TODO: Add types that are de-facto universal even though not
|
|
1274
1556
|
// built-in into ecmasript standard.
|
|
1275
1557
|
];
|
|
1276
1558
|
|
|
1277
|
-
export {
|
|
1559
|
+
export { u as JSON_TYPES, c as Typeson, e as TypesonPromise, s as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, negativeZero, nonbuiltinIgnore, postmessage, primitiveObjects, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
|
|
1278
1560
|
//# sourceMappingURL=index.js.map
|