seroval
Version:
Stringify JS values
18 lines (12 loc) • 48.7 kB
JavaScript
var F=(i=>(i[i.AggregateError=1]="AggregateError",i[i.ArrowFunction=2]="ArrowFunction",i[i.ErrorPrototypeStack=4]="ErrorPrototypeStack",i[i.ObjectAssign=8]="ObjectAssign",i[i.BigIntTypedArray=16]="BigIntTypedArray",i[i.AbortSignal=32]="AbortSignal",i))(F||{});function yr(o){switch(o){case'"':return'\\"';case"\\":return"\\\\";case`
`:return"\\n";case"\r":return"\\r";case"\b":return"\\b";case" ":return"\\t";case"\f":return"\\f";case"<":return"\\x3C";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";default:return}}function p(o){let e="",r=0,s;for(let n=0,a=o.length;n<a;n++)s=yr(o[n]),s&&(e+=o.slice(r,n)+s,r=n+1);return r===0?e=o:e+=o.slice(r),e}function vr(o){switch(o){case"\\\\":return"\\";case'\\"':return'"';case"\\n":return`
`;case"\\r":return"\r";case"\\b":return"\b";case"\\t":return" ";case"\\f":return"\f";case"\\x3C":return"<";case"\\u2028":return"\u2028";case"\\u2029":return"\u2029";default:return o}}function N(o){return o.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g,vr)}var E="__SEROVAL_REFS__",Z="$R",oe=`self.${Z}`;function br(o){return o==null?`${oe}=${oe}||[]`:`(${oe}=${oe}||{})["${p(o)}"]=[]`}function m(o,e){if(!o)throw e}var De=new Map,R=new Map;function Nr(o,e){return De.set(e,o),R.set(o,e),e}function Be(o){return De.has(o)}function Ar(o){return R.has(o)}function Le(o){return m(Be(o),new ne(o)),De.get(o)}function We(o){return m(Ar(o),new ae(o)),R.get(o)}typeof globalThis!="undefined"?Object.defineProperty(globalThis,E,{value:R,configurable:!0,writable:!1,enumerable:!1}):typeof window!="undefined"?Object.defineProperty(window,E,{value:R,configurable:!0,writable:!1,enumerable:!1}):typeof self!="undefined"?Object.defineProperty(self,E,{value:R,configurable:!0,writable:!1,enumerable:!1}):typeof global!="undefined"&&Object.defineProperty(global,E,{value:R,configurable:!0,writable:!1,enumerable:!1});function Yr(o){return o}function Ke(o,e){for(let r=0,s=e.length;r<s;r++){let n=e[r];o.has(n)||(o.add(n),n.extends&&Ke(o,n.extends))}}function f(o){if(o){let e=new Set;return Ke(e,o),[...e]}}function xr(o){o(this.reason)}function Ir(o){this.addEventListener("abort",xr.bind(this,o),{once:!0})}function Je(o){return new Promise(Ir.bind(o))}var Ye={0:"Symbol.asyncIterator",1:"Symbol.hasInstance",2:"Symbol.isConcatSpreadable",3:"Symbol.iterator",4:"Symbol.match",5:"Symbol.matchAll",6:"Symbol.replace",7:"Symbol.search",8:"Symbol.species",9:"Symbol.split",10:"Symbol.toPrimitive",11:"Symbol.toStringTag",12:"Symbol.unscopables"},ie={[Symbol.asyncIterator]:0,[Symbol.hasInstance]:1,[Symbol.isConcatSpreadable]:2,[Symbol.iterator]:3,[Symbol.match]:4,[Symbol.matchAll]:5,[Symbol.replace]:6,[Symbol.search]:7,[Symbol.species]:8,[Symbol.split]:9,[Symbol.toPrimitive]:10,[Symbol.toStringTag]:11,[Symbol.unscopables]:12},$e={0:Symbol.asyncIterator,1:Symbol.hasInstance,2:Symbol.isConcatSpreadable,3:Symbol.iterator,4:Symbol.match,5:Symbol.matchAll,6:Symbol.replace,7:Symbol.search,8:Symbol.species,9:Symbol.split,10:Symbol.toPrimitive,11:Symbol.toStringTag,12:Symbol.unscopables},Ge={2:"!0",3:"!1",1:"void 0",0:"null",4:"-0",5:"1/0",6:"-1/0",7:"0/0"},qe={2:!0,3:!1,1:void 0,0:null,4:-0,5:Number.POSITIVE_INFINITY,6:Number.NEGATIVE_INFINITY,7:Number.NaN};var le={0:"Error",1:"EvalError",2:"RangeError",3:"ReferenceError",4:"SyntaxError",5:"TypeError",6:"URIError"},He={0:Error,1:EvalError,2:RangeError,3:ReferenceError,4:SyntaxError,5:TypeError,6:URIError},t=void 0;function u(o,e,r,s,n,a,i,l,c,d,h,H){return{t:o,i:e,s:r,l:s,c:n,m:a,p:i,e:l,a:c,f:d,b:h,o:H}}function A(o){return u(2,t,o,t,t,t,t,t,t,t,t,t)}var x=A(2),I=A(3),ce=A(1),ue=A(0),Ze=A(4),Xe=A(5),Qe=A(6),er=A(7);function de(o){return o instanceof EvalError?1:o instanceof RangeError?2:o instanceof ReferenceError?3:o instanceof SyntaxError?4:o instanceof TypeError?5:o instanceof URIError?6:0}function wr(o){let e=le[de(o)];return o.name!==e?{name:o.name}:o.constructor.name!==e?{name:o.constructor.name}:{}}function V(o,e){let r=wr(o),s=Object.getOwnPropertyNames(o);for(let n=0,a=s.length,i;n<a;n++)i=s[n],i!=="name"&&i!=="message"&&(i==="stack"?e&4&&(r=r||{},r[i]=o[i]):(r=r||{},r[i]=o[i]));return r}function pe(o){return Object.isFrozen(o)?3:Object.isSealed(o)?2:Object.isExtensible(o)?0:1}function fe(o){switch(o){case Number.POSITIVE_INFINITY:return Xe;case Number.NEGATIVE_INFINITY:return Qe}return o!==o?er:Object.is(o,-0)?Ze:u(0,t,o,t,t,t,t,t,t,t,t,t)}function w(o){return u(1,t,p(o),t,t,t,t,t,t,t,t,t)}function me(o){return u(3,t,""+o,t,t,t,t,t,t,t,t,t)}function tr(o){return u(4,o,t,t,t,t,t,t,t,t,t,t)}function Se(o,e){return u(5,o,e.toISOString(),t,t,t,t,t,t,t,t,t)}function ge(o,e){return u(6,o,t,t,p(e.source),e.flags,t,t,t,t,t,t)}function he(o,e){let r=new Uint8Array(e),s=r.length,n=new Array(s);for(let a=0;a<s;a++)n[a]=r[a];return u(19,o,n,t,t,t,t,t,t,t,t,t)}function sr(o,e){return u(17,o,ie[e],t,t,t,t,t,t,t,t,t)}function or(o,e){return u(18,o,p(Le(e)),t,t,t,t,t,t,t,t,t)}function D(o,e,r){return u(25,o,r,t,p(e),t,t,t,t,t,t,t)}function ye(o,e,r){return u(9,o,t,e.length,t,t,t,t,r,t,t,pe(e))}function ve(o,e){return u(21,o,t,t,t,t,t,t,t,e,t,t)}function be(o,e,r){return u(15,o,t,e.length,e.constructor.name,t,t,t,t,r,e.byteOffset,t)}function Ne(o,e,r){return u(16,o,t,e.length,e.constructor.name,t,t,t,t,r,e.byteOffset,t)}function Ae(o,e,r){return u(20,o,t,e.byteLength,t,t,t,t,t,r,e.byteOffset,t)}function xe(o,e,r){return u(13,o,de(e),t,t,p(e.message),r,t,t,t,t,t)}function Ie(o,e,r){return u(14,o,de(e),t,t,p(e.message),r,t,t,t,t,t)}function we(o,e,r){return u(7,o,t,e,t,t,t,t,r,t,t,t)}function B(o,e){return u(28,t,t,t,t,t,t,t,[o,e],t,t,t)}function j(o,e){return u(30,t,t,t,t,t,t,t,[o,e],t,t,t)}function _(o,e,r){return u(31,o,t,t,t,t,t,t,r,e,t,t)}function Ee(o,e){return u(32,o,t,t,t,t,t,t,t,e,t,t)}function Re(o,e){return u(33,o,t,t,t,t,t,t,t,e,t,t)}function Pe(o,e){return u(34,o,t,t,t,t,t,t,t,e,t,t)}var{toString:je}=Object.prototype;function Er(o,e){return e instanceof Error?`Seroval caught an error during the ${o} process.
${e.name}
${e.message}
- For more information, please check the "cause" property of this error.
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new`:`Seroval caught an error during the ${o} process.
"${je.call(e)}"
For more information, please check the "cause" property of this error.`}var X=class extends Error{constructor(r,s){super(Er(r,s));this.cause=s}},M=class extends X{constructor(e){super("parsing",e)}},Ce=class extends X{constructor(e){super("serialization",e)}},ze=class extends X{constructor(e){super("deserialization",e)}},S=class extends Error{constructor(r){super(`The value ${je.call(r)} of type "${typeof r}" cannot be parsed/serialized.
There are few workarounds for this problem:
- Transform the value in a way that it can be serialized.
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.`);this.value=r}},g=class extends Error{constructor(e){super('Unsupported node type "'+e.t+'".')}},U=class extends Error{constructor(e){super('Missing plugin for tag "'+e+'".')}},v=class extends Error{constructor(e){super('Missing "'+e+'" instance.')}},ne=class extends Error{constructor(r){super('Missing reference for the value "'+je.call(r)+'" of type "'+typeof r+'"');this.value=r}},ae=class extends Error{constructor(e){super('Missing reference for id "'+p(e)+'"')}},Oe=class extends Error{constructor(e){super('Unknown TypedArray "'+e+'"')}};var P=class{constructor(e,r){this.value=e;this.replacement=r}};var nr={},ar={};var ir={0:{},1:{},2:{},3:{},4:{},5:{},6:{}};function Q(){let o,e;return{promise:new Promise((r,s)=>{o=r,e=s}),resolve(r){o(r)},reject(r){e(r)}}}function Te(o){return"__SEROVAL_STREAM__"in o}function L(){let o=new Set,e=[],r=!0,s=!0;function n(l){for(let c of o.keys())c.next(l)}function a(l){for(let c of o.keys())c.throw(l)}function i(l){for(let c of o.keys())c.return(l)}return{__SEROVAL_STREAM__:!0,on(l){r&&o.add(l);for(let c=0,d=e.length;c<d;c++){let h=e[c];c===d-1&&!r?s?l.return(h):l.throw(h):l.next(h)}return()=>{r&&o.delete(l)}},next(l){r&&(e.push(l),n(l))},throw(l){r&&(e.push(l),a(l),r=!1,s=!1,o.clear())},return(l){r&&(e.push(l),i(l),r=!1,s=!0,o.clear())}}}function ke(o){let e=L(),r=o[Symbol.asyncIterator]();async function s(){try{let n=await r.next();n.done?e.return(n.value):(e.next(n.value),await s())}catch(n){e.throw(n)}}return s().catch(()=>{}),e}function lr(o){return()=>{let e=[],r=[],s=0,n=-1,a=!1;function i(){for(let c=0,d=r.length;c<d;c++)r[c].resolve({done:!0,value:void 0})}o.on({next(c){let d=r.shift();d&&d.resolve({done:!1,value:c}),e.push(c)},throw(c){let d=r.shift();d&&d.reject(c),i(),n=e.length,e.push(c),a=!0},return(c){let d=r.shift();d&&d.resolve({done:!0,value:c}),i(),n=e.length,e.push(c)}});function l(){let c=s++,d=e[c];if(c!==n)return{done:!1,value:d};if(a)throw d;return{done:!0,value:d}}return{[Symbol.asyncIterator](){return this},async next(){if(n===-1){let c=s++;if(c>=e.length){let d=Q();return r.push(d),await d.promise}return{done:!1,value:e[c]}}return s>n?{done:!0,value:void 0}:l()}}}}function W(o){let e=[],r=-1,s=-1,n=o[Symbol.iterator]();for(;;)try{let a=n.next();if(e.push(a.value),a.done){s=e.length-1;break}}catch(a){r=e.length,e.push(a)}return{v:e,t:r,d:s}}function cr(o){return()=>{let e=0;return{[Symbol.iterator](){return this},next(){if(e>o.d)return{done:!0,value:t};let r=e++,s=o.v[r];if(r===o.t)throw s;return{done:r===o.d,value:s}}}}}async function _e(o){try{return[1,await o]}catch(e){return[0,e]}}var K=class{constructor(e){this.marked=new Set;this.plugins=e.plugins,this.features=47^(e.disabledFeatures||0),this.refs=e.refs||new Map}markRef(e){this.marked.add(e)}isMarked(e){return this.marked.has(e)}getIndexedValue(e){let r=this.refs.get(e);if(r!=null)return this.markRef(r),{type:1,value:tr(r)};let s=this.refs.size;return this.refs.set(e,s),{type:0,value:s}}getReference(e){let r=this.getIndexedValue(e);return r.type===1?r:Be(e)?{type:2,value:or(r.value,e)}:r}parseWellKnownSymbol(e){let r=this.getReference(e);return r.type!==0?r.value:(m(e in ie,new S(e)),sr(r.value,e))}parseSpecialReference(e){let r=this.getIndexedValue(ir[e]);return r.type===1?r.value:u(26,r.value,e,t,t,t,t,t,t,t,t,t)}parseIteratorFactory(){let e=this.getIndexedValue(nr);return e.type===1?e.value:u(27,e.value,t,t,t,t,t,t,t,this.parseWellKnownSymbol(Symbol.iterator),t,t)}parseAsyncIteratorFactory(){let e=this.getIndexedValue(ar);return e.type===1?e.value:u(29,e.value,t,t,t,t,t,t,[this.parseSpecialReference(1),this.parseWellKnownSymbol(Symbol.asyncIterator)],t,t,t)}createObjectNode(e,r,s,n){return u(s?11:10,e,t,t,t,t,n,t,t,t,t,pe(r))}createMapNode(e,r,s,n){return u(8,e,t,t,t,t,t,{k:r,v:s,s:n},t,this.parseSpecialReference(0),t,t)}createPromiseConstructorNode(e){return u(22,e,t,t,t,t,t,t,t,this.parseSpecialReference(1),t,t)}createAbortSignalConstructorNode(e){return u(35,e,t,t,t,t,t,t,t,this.parseSpecialReference(5),t,t)}};var C=class extends K{async parseItems(e){let r=[];for(let s=0,n=e.length;s<n;s++)s in e&&(r[s]=await this.parse(e[s]));return r}async parseArray(e,r){return ye(e,r,await this.parseItems(r))}async parseProperties(e){let r=Object.entries(e),s=[],n=[];for(let i=0,l=r.length;i<l;i++)s.push(p(r[i][0])),n.push(await this.parse(r[i][1]));let a=Symbol.iterator;return a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(B(this.parseIteratorFactory(),await this.parse(W(e))))),a=Symbol.asyncIterator,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(j(this.parseAsyncIteratorFactory(),await this.parse(ke(e))))),a=Symbol.toStringTag,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(w(e[a]))),a=Symbol.isConcatSpreadable,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(e[a]?x:I)),{k:s,v:n,s:s.length}}async parsePlainObject(e,r,s){return this.createObjectNode(e,r,s,await this.parseProperties(r))}async parseBoxed(e,r){return ve(e,await this.parse(r.valueOf()))}async parseTypedArray(e,r){return be(e,r,await this.parse(r.buffer))}async parseBigIntTypedArray(e,r){return Ne(e,r,await this.parse(r.buffer))}async parseDataView(e,r){return Ae(e,r,await this.parse(r.buffer))}async parseError(e,r){let s=V(r,this.features);return xe(e,r,s?await this.parseProperties(s):t)}async parseAggregateError(e,r){let s=V(r,this.features);return Ie(e,r,s?await this.parseProperties(s):t)}async parseMap(e,r){let s=[],n=[];for(let[a,i]of r.entries())s.push(await this.parse(a)),n.push(await this.parse(i));return this.createMapNode(e,s,n,r.size)}async parseSet(e,r){let s=[];for(let n of r.keys())s.push(await this.parse(n));return we(e,r.size,s)}async parsePromise(e,r){let[s,n]=await _e(r);return u(12,e,s,t,t,t,t,t,t,await this.parse(n),t,t)}async parsePlugin(e,r){let s=this.plugins;if(s)for(let n=0,a=s.length;n<a;n++){let i=s[n];if(i.parse.async&&i.test(r))return D(e,i.tag,await i.parse.async(r,this,{id:e}))}return t}async parseStream(e,r){return _(e,this.parseSpecialReference(4),await new Promise((s,n)=>{let a=[],i=r.on({next:l=>{this.markRef(e),this.parse(l).then(c=>{a.push(Ee(e,c))},c=>{n(c),i()})},throw:l=>{this.markRef(e),this.parse(l).then(c=>{a.push(Re(e,c)),s(a),i()},c=>{n(c),i()})},return:l=>{this.markRef(e),this.parse(l).then(c=>{a.push(Pe(e,c)),s(a),i()},c=>{n(c),i()})}})}))}async parseAbortSignalSync(e,r){return u(37,e,t,t,t,t,t,t,t,await this.parse(r.reason),t,t)}async parseAbortSignal(e,r){return r.aborted||await Je(r),this.parseAbortSignalSync(e,r)}async parseObject(e,r){if(Array.isArray(r))return this.parseArray(e,r);if(Te(r))return this.parseStream(e,r);let s=r.constructor;if(s===P)return this.parse(r.replacement);let n=await this.parsePlugin(e,r);if(n)return n;switch(s){case Object:return this.parsePlainObject(e,r,!1);case t:return this.parsePlainObject(e,r,!0);case Date:return Se(e,r);case RegExp:return ge(e,r);case Error:case EvalError:case RangeError:case ReferenceError:case SyntaxError:case TypeError:case URIError:return this.parseError(e,r);case Number:case Boolean:case String:case BigInt:return this.parseBoxed(e,r);case ArrayBuffer:return he(e,r);case Int8Array:case Int16Array:case Int32Array:case Uint8Array:case Uint16Array:case Uint32Array:case Uint8ClampedArray:case Float32Array:case Float64Array:return this.parseTypedArray(e,r);case DataView:return this.parseDataView(e,r);case Map:return this.parseMap(e,r);case Set:return this.parseSet(e,r);default:break}if(s===Promise||r instanceof Promise)return this.parsePromise(e,r);let a=this.features;if(a&32&&typeof AbortSignal!="undefined"&&s===AbortSignal)return this.parseAbortSignal(e,r);if(a&16)switch(s){case BigInt64Array:case BigUint64Array:return this.parseBigIntTypedArray(e,r);default:break}if(a&1&&typeof AggregateError!="undefined"&&(s===AggregateError||r instanceof AggregateError))return this.parseAggregateError(e,r);if(r instanceof Error)return this.parseError(e,r);if(Symbol.iterator in r||Symbol.asyncIterator in r)return this.parsePlainObject(e,r,!!s);throw new S(r)}async parseFunction(e){let r=this.getReference(e);if(r.type!==0)return r.value;let s=await this.parsePlugin(r.value,e);if(s)return s;throw new S(e)}async parse(e){try{switch(typeof e){case"boolean":return e?x:I;case"undefined":return ce;case"string":return w(e);case"number":return fe(e);case"bigint":return me(e);case"object":{if(e){let r=this.getReference(e);return r.type===0?await this.parseObject(r.value,e):r.value}return ue}case"symbol":return this.parseWellKnownSymbol(e);case"function":return this.parseFunction(e);default:throw new S(e)}}catch(r){throw new M(r)}}};var J=class extends C{constructor(){super(...arguments);this.mode="cross"}};function ur(o){switch(o){case"Int8Array":return Int8Array;case"Int16Array":return Int16Array;case"Int32Array":return Int32Array;case"Uint8Array":return Uint8Array;case"Uint16Array":return Uint16Array;case"Uint32Array":return Uint32Array;case"Uint8ClampedArray":return Uint8ClampedArray;case"Float32Array":return Float32Array;case"Float64Array":return Float64Array;case"BigInt64Array":return BigInt64Array;case"BigUint64Array":return BigUint64Array;default:throw new Oe(o)}}function dr(o,e){switch(e){case 3:return Object.freeze(o);case 1:return Object.preventExtensions(o);case 2:return Object.seal(o);default:return o}}var z=class{constructor(e){this.plugins=e.plugins,this.refs=e.refs||new Map}deserializeReference(e){return this.assignIndexedValue(e.i,We(N(e.s)))}deserializeArray(e){let r=e.l,s=this.assignIndexedValue(e.i,new Array(r)),n;for(let a=0;a<r;a++)n=e.a[a],n&&(s[a]=this.deserialize(n));return dr(s,e.o),s}deserializeProperties(e,r){let s=e.s;if(s){let n=e.k,a=e.v;for(let i=0,l;i<s;i++)l=n[i],typeof l=="string"?r[N(l)]=this.deserialize(a[i]):r[this.deserialize(l)]=this.deserialize(a[i])}return r}deserializeObject(e){let r=this.assignIndexedValue(e.i,e.t===10?{}:Object.create(null));return this.deserializeProperties(e.p,r),dr(r,e.o),r}deserializeDate(e){return this.assignIndexedValue(e.i,new Date(e.s))}deserializeRegExp(e){return this.assignIndexedValue(e.i,new RegExp(N(e.c),e.m))}deserializeSet(e){let r=this.assignIndexedValue(e.i,new Set),s=e.a;for(let n=0,a=e.l;n<a;n++)r.add(this.deserialize(s[n]));return r}deserializeMap(e){let r=this.assignIndexedValue(e.i,new Map),s=e.e.k,n=e.e.v;for(let a=0,i=e.e.s;a<i;a++)r.set(this.deserialize(s[a]),this.deserialize(n[a]));return r}deserializeArrayBuffer(e){let r=new Uint8Array(e.s);return this.assignIndexedValue(e.i,r.buffer)}deserializeTypedArray(e){let r=ur(e.c),s=this.deserialize(e.f);return this.assignIndexedValue(e.i,new r(s,e.b,e.l))}deserializeDataView(e){let r=this.deserialize(e.f);return this.assignIndexedValue(e.i,new DataView(r,e.b,e.l))}deserializeDictionary(e,r){if(e.p){let s=this.deserializeProperties(e.p,{});Object.assign(r,s)}return r}deserializeAggregateError(e){let r=this.assignIndexedValue(e.i,new AggregateError([],N(e.m)));return this.deserializeDictionary(e,r)}deserializeError(e){let r=He[e.s],s=this.assignIndexedValue(e.i,new r(N(e.m)));return this.deserializeDictionary(e,s)}deserializePromise(e){let r=Q(),s=this.assignIndexedValue(e.i,r),n=this.deserialize(e.f);return e.s?r.resolve(n):r.reject(n),s.promise}deserializeBoxed(e){return this.assignIndexedValue(e.i,Object(this.deserialize(e.f)))}deserializePlugin(e){let r=this.plugins;if(r){let s=N(e.c);for(let n=0,a=r.length;n<a;n++){let i=r[n];if(i.tag===s)return this.assignIndexedValue(e.i,i.deserialize(e.s,this,{id:e.i}))}}throw new U(e.c)}deserializePromiseConstructor(e){return this.assignIndexedValue(e.i,Q()).promise}deserializePromiseResolve(e){let r=this.refs.get(e.i);m(r,new v("Promise")),r.resolve(this.deserialize(e.a[1]))}deserializePromiseReject(e){let r=this.refs.get(e.i);m(r,new v("Promise")),r.reject(this.deserialize(e.a[1]))}deserializeIteratorFactoryInstance(e){this.deserialize(e.a[0]);let r=this.deserialize(e.a[1]);return cr(r)}deserializeAsyncIteratorFactoryInstance(e){this.deserialize(e.a[0]);let r=this.deserialize(e.a[1]);return lr(r)}deserializeStreamConstructor(e){let r=this.assignIndexedValue(e.i,L()),s=e.a.length;if(s)for(let n=0;n<s;n++)this.deserialize(e.a[n]);return r}deserializeStreamNext(e){let r=this.refs.get(e.i);m(r,new v("Stream")),r.next(this.deserialize(e.f))}deserializeStreamThrow(e){let r=this.refs.get(e.i);m(r,new v("Stream")),r.throw(this.deserialize(e.f))}deserializeStreamReturn(e){let r=this.refs.get(e.i);m(r,new v("Stream")),r.return(this.deserialize(e.f))}deserializeIteratorFactory(e){this.deserialize(e.f)}deserializeAsyncIteratorFactory(e){this.deserialize(e.a[1])}deserializeAbortSignalConstructor(e){return this.assignIndexedValue(e.i,new AbortController).signal}deserializeAbortSignalAbort(e){let r=this.refs.get(e.i);m(r,new v("AbortSignal")),r.abort(this.deserialize(e.a[1]))}deserializeAbortSignalSync(e){return this.assignIndexedValue(e.i,AbortSignal.abort(this.deserialize(e.f)))}deserialize(e){try{switch(e.t){case 2:return qe[e.s];case 0:return e.s;case 1:return N(e.s);case 3:return BigInt(e.s);case 4:return this.refs.get(e.i);case 18:return this.deserializeReference(e);case 9:return this.deserializeArray(e);case 10:case 11:return this.deserializeObject(e);case 5:return this.deserializeDate(e);case 6:return this.deserializeRegExp(e);case 7:return this.deserializeSet(e);case 8:return this.deserializeMap(e);case 19:return this.deserializeArrayBuffer(e);case 16:case 15:return this.deserializeTypedArray(e);case 20:return this.deserializeDataView(e);case 14:return this.deserializeAggregateError(e);case 13:return this.deserializeError(e);case 12:return this.deserializePromise(e);case 17:return $e[e.s];case 21:return this.deserializeBoxed(e);case 25:return this.deserializePlugin(e);case 22:return this.deserializePromiseConstructor(e);case 23:return this.deserializePromiseResolve(e);case 24:return this.deserializePromiseReject(e);case 28:return this.deserializeIteratorFactoryInstance(e);case 30:return this.deserializeAsyncIteratorFactoryInstance(e);case 31:return this.deserializeStreamConstructor(e);case 32:return this.deserializeStreamNext(e);case 33:return this.deserializeStreamThrow(e);case 34:return this.deserializeStreamReturn(e);case 27:return this.deserializeIteratorFactory(e);case 29:return this.deserializeAsyncIteratorFactory(e);case 36:return this.deserializeAbortSignalAbort(e);case 35:return this.deserializeAbortSignalConstructor(e);case 37:return this.deserializeAbortSignalSync(e);default:throw new g(e)}}catch(r){throw new ze(r)}}};var ee=class extends z{constructor(){super(...arguments);this.mode="cross"}assignIndexedValue(r,s){return this.refs.has(r)||this.refs.set(r,s),s}};var Cr=/^[$A-Z_][0-9A-Z_$]*$/i;function Me(o){let e=o[0];return(e==="$"||e==="_"||e>="A"&&e<="Z"||e>="a"&&e<="z")&&Cr.test(o)}function re(o){switch(o.t){case 0:return o.s+"="+o.v;case 2:return o.s+".set("+o.k+","+o.v+")";case 1:return o.s+".add("+o.v+")";case 3:return o.s+".delete("+o.k+")"}}function zr(o){let e=[],r=o[0];for(let s=1,n=o.length,a,i=r;s<n;s++)a=o[s],a.t===0&&a.v===i.v?r={t:0,s:a.s,k:t,v:re(r)}:a.t===2&&a.s===i.s?r={t:2,s:re(r),k:a.k,v:a.v}:a.t===1&&a.s===i.s?r={t:1,s:re(r),k:t,v:a.v}:a.t===3&&a.s===i.s?r={t:3,s:re(r),k:a.k,v:t}:(e.push(r),r=a),i=a;return e.push(r),e}function pr(o){if(o.length){let e="",r=zr(o);for(let s=0,n=r.length;s<n;s++)e+=re(r[s])+",";return e}return t}var Or="Object.create(null)",Tr="new Set",kr="new Map",Fr="Promise.resolve",Vr="Promise.reject",Dr={3:"Object.freeze",2:"Object.seal",1:"Object.preventExtensions",0:t},O=class{constructor(e){this.stack=[];this.flags=[];this.assignments=[];this.plugins=e.plugins,this.features=e.features,this.marked=new Set(e.markedRefs)}createFunction(e,r){return this.features&2?(e.length===1?e[0]:"("+e.join(",")+")")+"=>"+(r.startsWith("{")?"("+r+")":r):"function("+e.join(",")+"){return "+r+"}"}createEffectfulFunction(e,r){return this.features&2?(e.length===1?e[0]:"("+e.join(",")+")")+"=>{"+r+"}":"function("+e.join(",")+"){"+r+"}"}markRef(e){this.marked.add(e)}isMarked(e){return this.marked.has(e)}pushObjectFlag(e,r){e!==0&&(this.markRef(r),this.flags.push({type:e,value:this.getRefParam(r)}))}resolveFlags(){let e="";for(let r=0,s=this.flags,n=s.length;r<n;r++){let a=s[r];e+=Dr[a.type]+"("+a.value+"),"}return e}resolvePatches(){let e=pr(this.assignments),r=this.resolveFlags();return e?r?e+r:e:r}createAssignment(e,r){this.assignments.push({t:0,s:e,k:t,v:r})}createAddAssignment(e,r){this.assignments.push({t:1,s:this.getRefParam(e),k:t,v:r})}createSetAssignment(e,r,s){this.assignments.push({t:2,s:this.getRefParam(e),k:r,v:s})}createDeleteAssignment(e,r){this.assignments.push({t:3,s:this.getRefParam(e),k:r,v:t})}createArrayAssign(e,r,s){this.createAssignment(this.getRefParam(e)+"["+r+"]",s)}createObjectAssign(e,r,s){this.createAssignment(this.getRefParam(e)+"."+r,s)}isIndexedValueInStack(e){return e.t===4&&this.stack.includes(e.i)}serializeReference(e){return this.assignIndexedValue(e.i,E+'.get("'+e.s+'")')}serializeArrayItem(e,r,s){return r?this.isIndexedValueInStack(r)?(this.markRef(e),this.createArrayAssign(e,s,this.getRefParam(r.i)),""):this.serialize(r):""}serializeArray(e){let r=e.i;if(e.l){this.stack.push(r);let s=e.a,n=this.serializeArrayItem(r,s[0],0),a=n==="";for(let i=1,l=e.l,c;i<l;i++)c=this.serializeArrayItem(r,s[i],i),n+=","+c,a=c==="";return this.stack.pop(),this.pushObjectFlag(e.o,e.i),this.assignIndexedValue(r,"["+n+(a?",]":"]"))}return this.assignIndexedValue(r,"[]")}serializeProperty(e,r,s){if(typeof r=="string"){let n=Number(r),a=n>=0&&n.toString()===r||Me(r);if(this.isIndexedValueInStack(s)){let i=this.getRefParam(s.i);return this.markRef(e.i),a&&n!==n?this.createObjectAssign(e.i,r,i):this.createArrayAssign(e.i,a?r:'"'+r+'"',i),""}return(a?r:'"'+r+'"')+":"+this.serialize(s)}return"["+this.serialize(r)+"]:"+this.serialize(s)}serializeProperties(e,r){let s=r.s;if(s){let n=r.k,a=r.v;this.stack.push(e.i);let i=this.serializeProperty(e,n[0],a[0]);for(let l=1,c=i;l<s;l++)c=this.serializeProperty(e,n[l],a[l]),i+=(c&&i&&",")+c;return this.stack.pop(),"{"+i+"}"}return"{}"}serializeObject(e){return this.pushObjectFlag(e.o,e.i),this.assignIndexedValue(e.i,this.serializeProperties(e,e.p))}serializeWithObjectAssign(e,r,s){let n=this.serializeProperties(e,r);return n!=="{}"?"Object.assign("+s+","+n+")":s}serializeStringKeyAssignment(e,r,s,n){let a=this.serialize(n),i=Number(s),l=i>=0&&i.toString()===s||Me(s);if(this.isIndexedValueInStack(n))l&&i!==i?this.createObjectAssign(e.i,s,a):this.createArrayAssign(e.i,l?s:'"'+s+'"',a);else{let c=this.assignments;this.assignments=r,l&&i!==i?this.createObjectAssign(e.i,s,a):this.createArrayAssign(e.i,l?s:'"'+s+'"',a),this.assignments=c}}serializeAssignment(e,r,s,n){if(typeof s=="string")this.serializeStringKeyAssignment(e,r,s,n);else{let a=this.stack;this.stack=[];let i=this.serialize(n);this.stack=a;let l=this.assignments;this.assignments=r,this.createArrayAssign(e.i,this.serialize(s),i),this.assignments=l}}serializeAssignments(e,r){let s=r.s;if(s){let n=[],a=r.k,i=r.v;this.stack.push(e.i);for(let l=0;l<s;l++)this.serializeAssignment(e,n,a[l],i[l]);return this.stack.pop(),pr(n)}return t}serializeDictionary(e,r){if(e.p)if(this.features&8)r=this.serializeWithObjectAssign(e,e.p,r);else{this.markRef(e.i);let s=this.serializeAssignments(e,e.p);if(s)return"("+this.assignIndexedValue(e.i,r)+","+s+this.getRefParam(e.i)+")"}return this.assignIndexedValue(e.i,r)}serializeNullConstructor(e){return this.pushObjectFlag(e.o,e.i),this.serializeDictionary(e,Or)}serializeDate(e){return this.assignIndexedValue(e.i,'new Date("'+e.s+'")')}serializeRegExp(e){return this.assignIndexedValue(e.i,"/"+e.c+"/"+e.m)}serializeSetItem(e,r){return this.isIndexedValueInStack(r)?(this.markRef(e),this.createAddAssignment(e,this.getRefParam(r.i)),""):this.serialize(r)}serializeSet(e){let r=Tr,s=e.l,n=e.i;if(s){let a=e.a;this.stack.push(n);let i=this.serializeSetItem(n,a[0]);for(let l=1,c=i;l<s;l++)c=this.serializeSetItem(n,a[l]),i+=(c&&i&&",")+c;this.stack.pop(),i&&(r+="(["+i+"])")}return this.assignIndexedValue(n,r)}serializeMapEntry(e,r,s,n){if(this.isIndexedValueInStack(r)){let a=this.getRefParam(r.i);if(this.markRef(e),this.isIndexedValueInStack(s)){let l=this.getRefParam(s.i);return this.createSetAssignment(e,a,l),""}if(s.t!==4&&s.i!=null&&this.isMarked(s.i)){let l="("+this.serialize(s)+",["+n+","+n+"])";return this.createSetAssignment(e,a,this.getRefParam(s.i)),this.createDeleteAssignment(e,n),l}let i=this.stack;return this.stack=[],this.createSetAssignment(e,a,this.serialize(s)),this.stack=i,""}if(this.isIndexedValueInStack(s)){let a=this.getRefParam(s.i);if(this.markRef(e),r.t!==4&&r.i!=null&&this.isMarked(r.i)){let l="("+this.serialize(r)+",["+n+","+n+"])";return this.createSetAssignment(e,this.getRefParam(r.i),a),this.createDeleteAssignment(e,n),l}let i=this.stack;return this.stack=[],this.createSetAssignment(e,this.serialize(r),a),this.stack=i,""}return"["+this.serialize(r)+","+this.serialize(s)+"]"}serializeMap(e){let r=kr,s=e.e.s,n=e.i,a=e.f,i=this.getRefParam(a.i);if(s){let l=e.e.k,c=e.e.v;this.stack.push(n);let d=this.serializeMapEntry(n,l[0],c[0],i);for(let h=1,H=d;h<s;h++)H=this.serializeMapEntry(n,l[h],c[h],i),d+=(H&&d&&",")+H;this.stack.pop(),d&&(r+="(["+d+"])")}return a.t===26&&(this.markRef(a.i),r="("+this.serialize(a)+","+r+")"),this.assignIndexedValue(n,r)}serializeArrayBuffer(e){let r="new Uint8Array(",s=e.s,n=s.length;if(n){r+="["+s[0];for(let a=1;a<n;a++)r+=","+s[a];r+="]"}return this.assignIndexedValue(e.i,r+").buffer")}serializeTypedArray(e){return this.assignIndexedValue(e.i,"new "+e.c+"("+this.serialize(e.f)+","+e.b+","+e.l+")")}serializeDataView(e){return this.assignIndexedValue(e.i,"new DataView("+this.serialize(e.f)+","+e.b+","+e.l+")")}serializeAggregateError(e){let r=e.i;this.stack.push(r);let s=this.serializeDictionary(e,'new AggregateError([],"'+e.m+'")');return this.stack.pop(),s}serializeError(e){return this.serializeDictionary(e,"new "+le[e.s]+'("'+e.m+'")')}serializePromise(e){let r,s=e.f,n=e.i,a=e.s?Fr:Vr;if(this.isIndexedValueInStack(s)){let i=this.getRefParam(s.i);r=a+(e.s?"().then("+this.createFunction([],i)+")":"().catch("+this.createEffectfulFunction([],"throw "+i)+")")}else{this.stack.push(n);let i=this.serialize(s);this.stack.pop(),r=a+"("+i+")"}return this.assignIndexedValue(n,r)}serializeWellKnownSymbol(e){return this.assignIndexedValue(e.i,Ye[e.s])}serializeBoxed(e){return this.assignIndexedValue(e.i,"Object("+this.serialize(e.f)+")")}serializePlugin(e){let r=this.plugins;if(r)for(let s=0,n=r.length;s<n;s++){let a=r[s];if(a.tag===e.c)return this.assignIndexedValue(e.i,a.serialize(e.s,this,{id:e.i}))}throw new U(e.c)}getConstructor(e){let r=this.serialize(e);return r===this.getRefParam(e.i)?r:"("+r+")"}serializePromiseConstructor(e){return this.assignIndexedValue(e.i,this.getConstructor(e.f)+"()")}serializePromiseResolve(e){return this.getConstructor(e.a[0])+"("+this.getRefParam(e.i)+","+this.serialize(e.a[1])+")"}serializePromiseReject(e){return this.getConstructor(e.a[0])+"("+this.getRefParam(e.i)+","+this.serialize(e.a[1])+")"}serializeSpecialReferenceValue(e){switch(e){case 0:return"[]";case 1:return this.createFunction(["s","f","p"],"((p=new Promise("+this.createEffectfulFunction(["a","b"],"s=a,f=b")+")).s=s,p.f=f,p)");case 2:return this.createEffectfulFunction(["p","d"],'p.s(d),p.status="success",p.value=d;delete p.s;delete p.f');case 3:return this.createEffectfulFunction(["p","d"],'p.f(d),p.status="failure",p.value=d;delete p.s;delete p.f');case 4:return this.createFunction(["b","a","s","l","p","f","e","n"],"(b=[],a=!0,s=!1,l=[],p=0,f="+this.createEffectfulFunction(["v","m","x"],"for(x=0;x<p;x++)l[x]&&l[x][m](v)")+",n="+this.createEffectfulFunction(["o","x","z","c"],'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))')+",e="+this.createFunction(["o","t"],"(a&&(l[t=p++]=o),n(o),"+this.createEffectfulFunction([],"a&&(l[t]=void 0)")+")")+",{__SEROVAL_STREAM__:!0,on:"+this.createFunction(["o"],"e(o)")+",next:"+this.createEffectfulFunction(["v"],'a&&(b.push(v),f(v,"next"))')+",throw:"+this.createEffectfulFunction(["v"],'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)')+",return:"+this.createEffectfulFunction(["v"],'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)')+"})");case 5:return this.createFunction(["a","s"],"((s=(a=new AbortController).signal).a=a,s)");case 6:return this.createEffectfulFunction(["s","r"],"s.a.abort(r);delete s.a");default:return""}}serializeSpecialReference(e){return this.assignIndexedValue(e.i,this.serializeSpecialReferenceValue(e.s))}serializeIteratorFactory(e){let r="",s=!1;return e.f.t!==4&&(this.markRef(e.f.i),r="("+this.serialize(e.f)+",",s=!0),r+=this.assignIndexedValue(e.i,this.createFunction(["s"],this.createFunction(["i","c","d","t"],"(i=0,t={["+this.getRefParam(e.f.i)+"]:"+this.createFunction([],"t")+",next:"+this.createEffectfulFunction([],"if(i>s.d)return{done:!0,value:void 0};if(d=s.v[c=i++],c===s.t)throw d;return{done:c===s.d,value:d}")+"})"))),s&&(r+=")"),r}serializeIteratorFactoryInstance(e){return this.getConstructor(e.a[0])+"("+this.serialize(e.a[1])+")"}serializeAsyncIteratorFactory(e){let r=e.a[0],s=e.a[1],n="";r.t!==4&&(this.markRef(r.i),n+="("+this.serialize(r)),s.t!==4&&(this.markRef(s.i),n+=(n?",":"(")+this.serialize(s)),n&&(n+=",");let a=this.assignIndexedValue(e.i,this.createFunction(["s"],this.createFunction(["b","c","p","d","e","t","f"],"(b=[],c=0,p=[],d=-1,e=!1,f="+this.createEffectfulFunction(["i","l"],"for(i=0,l=p.length;i<l;i++)p[i].s({done:!0,value:void 0})")+",s.on({next:"+this.createEffectfulFunction(["v","t"],"if(t=p.shift())t.s({done:!1,value:v});b.push(v)")+",throw:"+this.createEffectfulFunction(["v","t"],"if(t=p.shift())t.f(v);f(),d=b.length,e=!0,b.push(v)")+",return:"+this.createEffectfulFunction(["v","t"],"if(t=p.shift())t.s({done:!0,value:v});f(),d=b.length,b.push(v)")+"}),t={["+this.getRefParam(s.i)+"]:"+this.createFunction([],"t")+",next:"+this.createEffectfulFunction(["i","t","v"],"if(d===-1){return((i=c++)>=b.length)?(p.push(t="+this.getRefParam(r.i)+"()),t):{done:!1,value:b[i]}}if(c>d)return{done:!0,value:void 0};if(v=b[i=c++],i!==d)return{done:!1,value:v};if(e)throw v;return{done:!0,value:v}")+"})")));return n?n+a+")":a}serializeAsyncIteratorFactoryInstance(e){return this.getConstructor(e.a[0])+"("+this.serialize(e.a[1])+")"}serializeStreamConstructor(e){let r=this.assignIndexedValue(e.i,this.getConstructor(e.f)+"()"),s=e.a.length;if(s){let n=this.serialize(e.a[0]);for(let a=1;a<s;a++)n+=","+this.serialize(e.a[a]);return"("+r+","+n+","+this.getRefParam(e.i)+")"}return r}serializeStreamNext(e){return this.getRefParam(e.i)+".next("+this.serialize(e.f)+")"}serializeStreamThrow(e){return this.getRefParam(e.i)+".throw("+this.serialize(e.f)+")"}serializeStreamReturn(e){return this.getRefParam(e.i)+".return("+this.serialize(e.f)+")"}serializeAbortSignalSync(e){return this.assignIndexedValue(e.i,"AbortSignal.abort("+this.serialize(e.f)+")")}serializeAbortSignalConstructor(e){return this.assignIndexedValue(e.i,this.getConstructor(e.f)+"()")}serializeAbortSignalAbort(e){return this.getConstructor(e.a[0])+"("+this.getRefParam(e.i)+","+this.serialize(e.a[1])+")"}serialize(e){try{switch(e.t){case 2:return Ge[e.s];case 0:return""+e.s;case 1:return'"'+e.s+'"';case 3:return e.s+"n";case 4:return this.getRefParam(e.i);case 18:return this.serializeReference(e);case 9:return this.serializeArray(e);case 10:return this.serializeObject(e);case 11:return this.serializeNullConstructor(e);case 5:return this.serializeDate(e);case 6:return this.serializeRegExp(e);case 7:return this.serializeSet(e);case 8:return this.serializeMap(e);case 19:return this.serializeArrayBuffer(e);case 16:case 15:return this.serializeTypedArray(e);case 20:return this.serializeDataView(e);case 14:return this.serializeAggregateError(e);case 13:return this.serializeError(e);case 12:return this.serializePromise(e);case 17:return this.serializeWellKnownSymbol(e);case 21:return this.serializeBoxed(e);case 22:return this.serializePromiseConstructor(e);case 23:return this.serializePromiseResolve(e);case 24:return this.serializePromiseReject(e);case 25:return this.serializePlugin(e);case 26:return this.serializeSpecialReference(e);case 27:return this.serializeIteratorFactory(e);case 28:return this.serializeIteratorFactoryInstance(e);case 29:return this.serializeAsyncIteratorFactory(e);case 30:return this.serializeAsyncIteratorFactoryInstance(e);case 31:return this.serializeStreamConstructor(e);case 32:return this.serializeStreamNext(e);case 33:return this.serializeStreamThrow(e);case 34:return this.serializeStreamReturn(e);case 36:return this.serializeAbortSignalAbort(e);case 35:return this.serializeAbortSignalConstructor(e);case 37:return this.serializeAbortSignalSync(e);default:throw new g(e)}}catch(r){throw new Ce(r)}}};var T=class extends O{constructor(r){super(r);this.mode="cross";this.scopeId=r.scopeId}getRefParam(r){return Z+"["+r+"]"}assignIndexedValue(r,s){return this.getRefParam(r)+"="+s}serializeTop(r){let s=this.serialize(r),n=r.i;if(n==null)return s;let a=this.resolvePatches(),i=this.getRefParam(n),l=this.scopeId==null?"":Z,c=a?"("+s+","+a+i+")":s;if(l==="")return r.t===10&&!a?"("+c+")":c;let d=this.scopeId==null?"()":"("+Z+'["'+p(this.scopeId)+'"])';return"("+this.createFunction([l],c)+")"+d}};var b=class extends K{parseItems(e){let r=[];for(let s=0,n=e.length;s<n;s++)s in e&&(r[s]=this.parse(e[s]));return r}parseArray(e,r){return ye(e,r,this.parseItems(r))}parseProperties(e){let r=Object.entries(e),s=[],n=[];for(let i=0,l=r.length;i<l;i++)s.push(p(r[i][0])),n.push(this.parse(r[i][1]));let a=Symbol.iterator;return a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(B(this.parseIteratorFactory(),this.parse(W(e))))),a=Symbol.asyncIterator,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(j(this.parseAsyncIteratorFactory(),this.parse(L())))),a=Symbol.toStringTag,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(w(e[a]))),a=Symbol.isConcatSpreadable,a in e&&(s.push(this.parseWellKnownSymbol(a)),n.push(e[a]?x:I)),{k:s,v:n,s:s.length}}parsePlainObject(e,r,s){return this.createObjectNode(e,r,s,this.parseProperties(r))}parseBoxed(e,r){return ve(e,this.parse(r.valueOf()))}parseTypedArray(e,r){return be(e,r,this.parse(r.buffer))}parseBigIntTypedArray(e,r){return Ne(e,r,this.parse(r.buffer))}parseDataView(e,r){return Ae(e,r,this.parse(r.buffer))}parseError(e,r){let s=V(r,this.features);return xe(e,r,s?this.parseProperties(s):t)}parseAggregateError(e,r){let s=V(r,this.features);return Ie(e,r,s?this.parseProperties(s):t)}parseMap(e,r){let s=[],n=[];for(let[a,i]of r.entries())s.push(this.parse(a)),n.push(this.parse(i));return this.createMapNode(e,s,n,r.size)}parseSet(e,r){let s=[];for(let n of r.keys())s.push(this.parse(n));return we(e,r.size,s)}parsePlugin(e,r){let s=this.plugins;if(s)for(let n=0,a=s.length;n<a;n++){let i=s[n];if(i.parse.sync&&i.test(r))return D(e,i.tag,i.parse.sync(r,this,{id:e}))}}parseStream(e,r){return _(e,this.parseSpecialReference(4),[])}parsePromise(e,r){return this.createPromiseConstructorNode(e)}parseAbortSignalSync(e,r){return u(37,e,t,t,t,t,t,t,t,this.parse(r.reason),t,t)}parseAbortSignal(e,r){return r.aborted?this.parseAbortSignalSync(e,r):this.createAbortSignalConstructorNode(e)}parseObject(e,r){if(Array.isArray(r))return this.parseArray(e,r);if(Te(r))return this.parseStream(e,r);let s=r.constructor;if(s===P)return this.parse(r.replacement);let n=this.parsePlugin(e,r);if(n)return n;switch(s){case Object:return this.parsePlainObject(e,r,!1);case void 0:return this.parsePlainObject(e,r,!0);case Date:return Se(e,r);case RegExp:return ge(e,r);case Error:case EvalError:case RangeError:case ReferenceError:case SyntaxError:case TypeError:case URIError:return this.parseError(e,r);case Number:case Boolean:case String:case BigInt:return this.parseBoxed(e,r);case ArrayBuffer:return he(e,r);case Int8Array:case Int16Array:case Int32Array:case Uint8Array:case Uint16Array:case Uint32Array:case Uint8ClampedArray:case Float32Array:case Float64Array:return this.parseTypedArray(e,r);case DataView:return this.parseDataView(e,r);case Map:return this.parseMap(e,r);case Set:return this.parseSet(e,r);default:break}if(s===Promise||r instanceof Promise)return this.parsePromise(e,r);let a=this.features;if(a&32&&typeof AbortSignal!="undefined"&&s===AbortSignal)return this.parseAbortSignal(e,r);if(a&16)switch(s){case BigInt64Array:case BigUint64Array:return this.parseBigIntTypedArray(e,r);default:break}if(a&1&&typeof AggregateError!="undefined"&&(s===AggregateError||r instanceof AggregateError))return this.parseAggregateError(e,r);if(r instanceof Error)return this.parseError(e,r);if(Symbol.iterator in r||Symbol.asyncIterator in r)return this.parsePlainObject(e,r,!!s);throw new S(r)}parseFunction(e){let r=this.getReference(e);if(r.type!==0)return r.value;let s=this.parsePlugin(r.value,e);if(s)return s;throw new S(e)}parse(e){try{switch(typeof e){case"boolean":return e?x:I;case"undefined":return ce;case"string":return w(e);case"number":return fe(e);case"bigint":return me(e);case"object":{if(e){let r=this.getReference(e);return r.type===0?this.parseObject(r.value,e):r.value}return ue}case"symbol":return this.parseWellKnownSymbol(e);case"function":return this.parseFunction(e);default:throw new S(e)}}catch(r){throw new M(r)}}};var te=class extends b{constructor(r){super(r);this.alive=!0;this.pending=0;this.initial=!0;this.buffer=[];this.onParseCallback=r.onParse,this.onErrorCallback=r.onError,this.onDoneCallback=r.onDone}onParseInternal(r,s){try{this.onParseCallback(r,s)}catch(n){this.onError(n)}}flush(){for(let r=0,s=this.buffer.length;r<s;r++)this.onParseInternal(this.buffer[r],!1)}onParse(r){this.initial?this.buffer.push(r):this.onParseInternal(r,!1)}onError(r){if(this.onErrorCallback)this.onErrorCallback(r);else throw r}onDone(){this.onDoneCallback&&this.onDoneCallback()}pushPendingState(){this.pending++}popPendingState(){--this.pending<=0&&this.onDone()}parseProperties(r){let s=Object.entries(r),n=[],a=[];for(let l=0,c=s.length;l<c;l++)n.push(p(s[l][0])),a.push(this.parse(s[l][1]));let i=Symbol.iterator;return i in r&&(n.push(this.parseWellKnownSymbol(i)),a.push(B(this.parseIteratorFactory(),this.parse(W(r))))),i=Symbol.asyncIterator,i in r&&(n.push(this.parseWellKnownSymbol(i)),a.push(j(this.parseAsyncIteratorFactory(),this.parse(ke(r))))),i=Symbol.toStringTag,i in r&&(n.push(this.parseWellKnownSymbol(i)),a.push(w(r[i]))),i=Symbol.isConcatSpreadable,i in r&&(n.push(this.parseWellKnownSymbol(i)),a.push(r[i]?x:I)),{k:n,v:a,s:n.length}}parsePromise(r,s){return s.then(n=>{let a=this.parseWithError(n);a&&this.onParse(u(23,r,t,t,t,t,t,t,[this.parseSpecialReference(2),a],t,t,t)),this.popPendingState()},n=>{if(this.alive){let a=this.parseWithError(n);a&&this.onParse(u(24,r,t,t,t,t,t,t,[this.parseSpecialReference(3),a],t,t,t))}this.popPendingState()}),this.pushPendingState(),this.createPromiseConstructorNode(r)}parsePlugin(r,s){let n=this.plugins;if(n)for(let a=0,i=n.length;a<i;a++){let l=n[a];if(l.parse.stream&&l.test(s))return D(r,l.tag,l.parse.stream(s,this,{id:r}))}return t}parseStream(r,s){let n=_(r,this.parseSpecialReference(4),[]);return this.pushPendingState(),s.on({next:a=>{if(this.alive){let i=this.parseWithError(a);i&&this.onParse(Ee(r,i))}},throw:a=>{if(this.alive){let i=this.parseWithError(a);i&&this.onParse(Re(r,i))}this.popPendingState()},return:a=>{if(this.alive){let i=this.parseWithError(a);i&&this.onParse(Pe(r,i))}this.popPendingState()}}),n}handleAbortSignal(r,s){if(this.alive){let n=this.parseWithError(s.reason);n&&this.onParse(u(36,r,t,t,t,t,t,t,[this.parseSpecialReference(6),n],t,t,t))}this.popPendingState()}parseAbortSignal(r,s){return s.aborted?this.parseAbortSignalSync(r,s):(this.pushPendingState(),s.addEventListener("abort",this.handleAbortSignal.bind(this,r,s),{once:!0}),this.createAbortSignalConstructorNode(r))}parseWithError(r){try{return this.parse(r)}catch(s){return this.onError(s),t}}start(r){let s=this.parseWithError(r);s&&(this.onParseInternal(s,!0),this.initial=!1,this.flush(),this.pending<=0&&this.destroy())}destroy(){this.alive&&(this.onDone(),this.alive=!1)}isAlive(){return this.alive}};var Y=class extends te{constructor(){super(...arguments);this.mode="cross"}};var $=class extends b{constructor(){super(...arguments);this.mode="cross"}};function ao(o,e={}){let r=f(e.plugins),s=new $({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}),n=s.parse(o);return new T({plugins:r,features:s.features,scopeId:e.scopeId,markedRefs:s.marked}).serializeTop(n)}async function io(o,e={}){let r=f(e.plugins),s=new J({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}),n=await s.parse(o);return new T({plugins:r,features:s.features,scopeId:e.scopeId,markedRefs:s.marked}).serializeTop(n)}function lo(o,e={}){let r=f(e.plugins);return new $({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}).parse(o)}async function co(o,e={}){let r=f(e.plugins);return await new J({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}).parse(o)}function fr(o,e){let r=f(e.plugins),s=new Y({plugins:r,refs:e.refs,disabledFeatures:e.disabledFeatures,onParse(n,a){let i=new T({plugins:r,features:s.features,scopeId:e.scopeId,markedRefs:s.marked}),l;try{l=i.serializeTop(n)}catch(c){e.onError&&e.onError(c);return}e.onSerialize(l,a)},onError:e.onError,onDone:e.onDone});return s.start(o),s.destroy.bind(s)}function uo(o,e){let r=f(e.plugins),s=new Y({plugins:r,refs:e.refs,disabledFeatures:e.disabledFeatures,onParse:e.onParse,onError:e.onError,onDone:e.onDone});return s.start(o),s.destroy.bind(s)}function po(o,e){let r=f(e.plugins);return new ee({plugins:r,refs:e.refs}).deserialize(o)}var G=class extends C{constructor(){super(...arguments);this.mode="vanilla"}};var se=class extends z{constructor(r){super(r);this.mode="vanilla";this.marked=new Set(r.markedRefs)}assignIndexedValue(r,s){return this.marked.has(r)&&this.refs.set(r,s),s}};var gr="hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_",mr=gr.length,hr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_",Sr=hr.length;function Ue(o){let e=o%mr,r=gr[e];for(o=(o-e)/mr;o>0;)e=o%Sr,r+=hr[e],o=(o-e)/Sr;return r}var k=class extends O{constructor(){super(...arguments);this.mode="vanilla";this.valid=new Map;this.vars=[]}getRefParam(r){let s=this.valid.get(r);s==null&&(s=this.valid.size,this.valid.set(r,s));let n=this.vars[s];return n==null&&(n=Ue(s),this.vars[s]=n),n}assignIndexedValue(r,s){return this.isMarked(r)?this.getRefParam(r)+"="+s:s}serializePromiseConstructor(r){throw new g(r)}serializePromiseResolve(r){throw new g(r)}serializePromiseReject(r){throw new g(r)}serializeAbortSignalAbort(r){throw new g(r)}serializeTop(r){let s=this.serialize(r);if(r.i!=null&&this.vars.length){let n=this.resolvePatches(),a=s;if(n){let i=this.getRefParam(r.i);a=s+","+n+i,s.startsWith(i+"=")||(a=i+"="+a),a="("+a+")"}return"("+this.createFunction(this.vars,a)+")()"}return r.t===10?"("+s+")":s}};var q=class extends b{constructor(){super(...arguments);this.mode="vanilla"}};function Oo(o,e={}){let r=f(e.plugins),s=new q({plugins:r,disabledFeatures:e.disabledFeatures}),n=s.parse(o);return new k({plugins:r,features:s.features,markedRefs:s.marked}).serializeTop(n)}async function To(o,e={}){let r=f(e.plugins),s=new G({plugins:r,disabledFeatures:e.disabledFeatures}),n=await s.parse(o);return new k({plugins:r,features:s.features,markedRefs:s.marked}).serializeTop(n)}function ko(o){return(0,eval)(o)}function Fo(o,e={}){let r=f(e.plugins),s=new q({plugins:r,disabledFeatures:e.disabledFeatures});return{t:s.parse(o),f:s.features,m:Array.from(s.marked)}}async function Vo(o,e={}){let r=f(e.plugins),s=new G({plugins:r,disabledFeatures:e.disabledFeatures});return{t:await s.parse(o),f:s.features,m:Array.from(s.marked)}}function Do(o,e={}){let r=f(e.plugins);return new k({plugins:r,features:o.f,markedRefs:o.m}).serializeTop(o.t)}function Bo(o,e={}){let r=f(e.plugins);return new se({plugins:r,markedRefs:o.m}).deserialize(o.t)}var Ve=class{constructor(e){this.options=e;this.alive=!0;this.flushed=!1;this.done=!1;this.pending=0;this.cleanups=[];this.refs=new Map;this.keys=new Set;this.ids=0;this.plugins=f(e.plugins)}write(e,r){this.alive&&!this.flushed&&(this.pending++,this.keys.add(e),this.cleanups.push(fr(r,{plugins:this.plugins,scopeId:this.options.scopeId,refs:this.refs,disabledFeatures:this.options.disabledFeatures,onError:this.options.onError,onSerialize:(s,n)=>{this.alive&&this.options.onData(n?this.options.globalIdentifier+'["'+p(e)+'"]='+s:s)},onDone:()=>{this.alive&&(this.pending--,this.pending<=0&&this.flushed&&!this.done&&this.options.onDone&&(this.options.onDone(),this.done=!0))}})))}getNextID(){for(;this.keys.has(""+this.ids);)this.ids++;return""+this.ids}push(e){let r=this.getNextID();return this.write(r,e),r}flush(){this.alive&&(this.flushed=!0,this.pending<=0&&!this.done&&this.options.onDone&&(this.options.onDone(),this.done=!0))}close(){if(this.alive){for(let e=0,r=this.cleanups.length;e<r;e++)this.cleanups[e]();!this.done&&this.options.onDone&&(this.options.onDone(),this.done=!0),this.alive=!1}}};export{F as Feature,P as OpaqueReference,Ve as Serializer,ze as SerovalDeserializationError,X as SerovalError,v as SerovalMissingInstanceError,U as SerovalMissingPluginError,ne as SerovalMissingReferenceError,ae as SerovalMissingReferenceForIdError,M as SerovalParserError,Ce as SerovalSerializationError,Oe as SerovalUnknownTypedArrayError,g as SerovalUnsupportedNodeError,S as SerovalUnsupportedTypeError,Do as compileJSON,Yr as createPlugin,Nr as createReference,L as createStream,ao as crossSerialize,io as crossSerializeAsync,fr as crossSerializeStream,ko as deserialize,po as fromCrossJSON,Bo as fromJSON,br as getCrossReferenceHeader,f as resolvePlugins,Oo as serialize,To as serializeAsync,lo as toCrossJSON,co as toCrossJSONAsync,uo as toCrossJSONStream,Fo as toJSON,Vo as toJSONAsync};