diff --git a/packages/seroval/src/core/abort-signal.ts b/packages/seroval/src/core/abort-signal.ts new file mode 100644 index 0000000..a95ebb2 --- /dev/null +++ b/packages/seroval/src/core/abort-signal.ts @@ -0,0 +1,13 @@ +export function abortSignalToPromise(signal: AbortSignal): Promise { + return new Promise(resolve => { + signal.addEventListener( + 'abort', + () => { + resolve(signal.reason); + }, + { + once: true, + }, + ); + }); +} diff --git a/packages/seroval/src/core/base-primitives.ts b/packages/seroval/src/core/base-primitives.ts index 8500a84..d37fbc9 100644 --- a/packages/seroval/src/core/base-primitives.ts +++ b/packages/seroval/src/core/base-primitives.ts @@ -1,14 +1,16 @@ import type { WellKnownSymbols } from './constants'; -import { INV_SYMBOL_REF, SerovalNodeType } from './constants'; +import { INV_SYMBOL_REF, NIL, SerovalNodeType } from './constants'; import { INFINITY_NODE, NAN_NODE, NEG_INFINITY_NODE, NEG_ZERO_NODE, } from './literals'; +import { createSerovalNode } from './node'; import { getReferenceID } from './reference'; import { serializeString } from './string'; import type { + SerovalAbortSignalSyncNode, SerovalAggregateErrorNode, SerovalArrayBufferNode, SerovalArrayNode, @@ -60,108 +62,108 @@ export function createNumberNode( if (Object.is(value, -0)) { return NEG_ZERO_NODE; } - return { - t: SerovalNodeType.Number, - i: undefined, - s: value, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Number, + NIL, + value, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createStringNode(value: string): SerovalStringNode { - return { - t: SerovalNodeType.String, - i: undefined, - s: serializeString(value), - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.String, + NIL, + serializeString(value), + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createBigIntNode(current: bigint): SerovalBigIntNode { - return { - t: SerovalNodeType.BigInt, - i: undefined, - s: '' + current, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.BigInt, + NIL, + '' + current, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createIndexedValueNode(id: number): SerovalIndexedValueNode { - return { - t: SerovalNodeType.IndexedValue, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.IndexedValue, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createDateNode(id: number, current: Date): SerovalDateNode { - return { - t: SerovalNodeType.Date, - i: id, - s: current.toISOString(), - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - f: undefined, - a: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Date, + id, + current.toISOString(), + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createRegExpNode( id: number, current: RegExp, ): SerovalRegExpNode { - return { - t: SerovalNodeType.RegExp, - i: id, - s: undefined, - l: undefined, - c: serializeString(current.source), - m: current.flags, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.RegExp, + id, + NIL, + NIL, + serializeString(current.source), + current.flags, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createArrayBufferNode( @@ -174,60 +176,60 @@ export function createArrayBufferNode( for (let i = 0; i < len; i++) { values[i] = bytes[i]; } - return { - t: SerovalNodeType.ArrayBuffer, - i: id, - s: values, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.ArrayBuffer, + id, + values, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createWKSymbolNode( id: number, current: WellKnownSymbols, ): SerovalWKSymbolNode { - return { - t: SerovalNodeType.WKSymbol, - i: id, - s: INV_SYMBOL_REF[current], - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.WKSymbol, + id, + INV_SYMBOL_REF[current], + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createReferenceNode( id: number, ref: T, ): SerovalReferenceNode { - return { - t: SerovalNodeType.Reference, - i: id, - s: serializeString(getReferenceID(ref)), - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Reference, + id, + serializeString(getReferenceID(ref)), + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createPluginNode( @@ -235,20 +237,20 @@ export function createPluginNode( tag: string, value: unknown, ): SerovalPluginNode { - return { - t: SerovalNodeType.Plugin, - i: id, - s: value, - l: undefined, - c: serializeString(tag), - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Plugin, + id, + value, + NIL, + serializeString(tag), + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createArrayNode( @@ -256,40 +258,40 @@ export function createArrayNode( current: unknown[], parsedItems: SerovalNode[], ): SerovalArrayNode { - return { - t: SerovalNodeType.Array, - i: id, - s: undefined, - l: current.length, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: parsedItems, - f: undefined, - b: undefined, - o: getObjectFlag(current), - }; + return createSerovalNode( + SerovalNodeType.Array, + id, + NIL, + current.length, + NIL, + NIL, + NIL, + NIL, + parsedItems, + NIL, + NIL, + getObjectFlag(current), + ); } export function createBoxedNode( id: number, boxed: SerovalNode, ): SerovalBoxedNode { - return { - t: SerovalNodeType.Boxed, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: boxed, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Boxed, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + boxed, + NIL, + NIL, + ); } export function createTypedArrayNode( @@ -297,20 +299,20 @@ export function createTypedArrayNode( current: TypedArrayValue, buffer: SerovalNode, ): SerovalTypedArrayNode { - return { - t: SerovalNodeType.TypedArray, - i: id, - s: undefined, - l: current.length, - c: current.constructor.name, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: buffer, - b: current.byteOffset, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.TypedArray, + id, + NIL, + current.length, + current.constructor.name, + NIL, + NIL, + NIL, + NIL, + buffer, + current.byteOffset, + NIL, + ); } export function createBigIntTypedArrayNode( @@ -318,20 +320,20 @@ export function createBigIntTypedArrayNode( current: BigIntTypedArrayValue, buffer: SerovalNode, ): SerovalBigIntTypedArrayNode { - return { - t: SerovalNodeType.BigIntTypedArray, - i: id, - s: undefined, - l: current.length, - c: current.constructor.name, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: buffer, - b: current.byteOffset, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.BigIntTypedArray, + id, + NIL, + current.length, + current.constructor.name, + NIL, + NIL, + NIL, + NIL, + buffer, + current.byteOffset, + NIL, + ); } export function createDataViewNode( @@ -339,20 +341,20 @@ export function createDataViewNode( current: DataView, buffer: SerovalNode, ): SerovalDataViewNode { - return { - t: SerovalNodeType.DataView, - i: id, - s: undefined, - l: current.byteLength, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: buffer, - b: current.byteOffset, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.DataView, + id, + NIL, + current.byteLength, + NIL, + NIL, + NIL, + NIL, + NIL, + buffer, + current.byteOffset, + NIL, + ); } export function createErrorNode( @@ -360,20 +362,20 @@ export function createErrorNode( current: Error, options: SerovalObjectRecordNode | undefined, ): SerovalErrorNode { - return { - t: SerovalNodeType.Error, - i: id, - s: getErrorConstructor(current), - l: undefined, - c: undefined, - m: serializeString(current.message), - p: options, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Error, + id, + getErrorConstructor(current), + NIL, + NIL, + serializeString(current.message), + options, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createAggregateErrorNode( @@ -381,20 +383,20 @@ export function createAggregateErrorNode( current: AggregateError, options: SerovalObjectRecordNode | undefined, ): SerovalAggregateErrorNode { - return { - t: SerovalNodeType.AggregateError, - i: id, - s: getErrorConstructor(current), - l: undefined, - c: undefined, - m: serializeString(current.message), - p: options, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.AggregateError, + id, + getErrorConstructor(current), + NIL, + NIL, + serializeString(current.message), + options, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export function createSetNode( @@ -402,60 +404,60 @@ export function createSetNode( size: number, items: SerovalNode[], ): SerovalSetNode { - return { - t: SerovalNodeType.Set, - i: id, - s: undefined, - l: size, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: items, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Set, + id, + NIL, + size, + NIL, + NIL, + NIL, + NIL, + items, + NIL, + NIL, + NIL, + ); } export function createIteratorFactoryInstanceNode( factory: SerovalNodeWithID, items: SerovalNode, ): SerovalIteratorFactoryInstanceNode { - return { - t: SerovalNodeType.IteratorFactoryInstance, - i: undefined, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: [factory, items], - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.IteratorFactoryInstance, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [factory, items], + NIL, + NIL, + NIL, + ); } export function createAsyncIteratorFactoryInstanceNode( factory: SerovalNodeWithID, items: SerovalNode, ): SerovalAsyncIteratorFactoryInstanceNode { - return { - t: SerovalNodeType.AsyncIteratorFactoryInstance, - i: undefined, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: [factory, items], - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.AsyncIteratorFactoryInstance, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [factory, items], + NIL, + NIL, + NIL, + ); } export function createStreamConstructorNode( @@ -463,78 +465,98 @@ export function createStreamConstructorNode( factory: SerovalNodeWithID, sequence: SerovalNode[], ): SerovalStreamConstructorNode { - return { - t: SerovalNodeType.StreamConstructor, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: sequence, - f: factory, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.StreamConstructor, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + sequence, + factory, + NIL, + NIL, + ); } export function createStreamNextNode( id: number, parsed: SerovalNode, ): SerovalStreamNextNode { - return { - t: SerovalNodeType.StreamNext, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: parsed, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.StreamNext, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + parsed, + NIL, + NIL, + ); } export function createStreamThrowNode( id: number, parsed: SerovalNode, ): SerovalStreamThrowNode { - return { - t: SerovalNodeType.StreamThrow, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: parsed, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.StreamThrow, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + parsed, + NIL, + NIL, + ); } export function createStreamReturnNode( id: number, parsed: SerovalNode, ): SerovalStreamReturnNode { - return { - t: SerovalNodeType.StreamReturn, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: parsed, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.StreamReturn, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + parsed, + NIL, + NIL, + ); +} + +export function createAbortSignalSyncNode( + id: number, + parsed: SerovalNode, +): SerovalAbortSignalSyncNode { + return createSerovalNode( + SerovalNodeType.AbortSignalSync, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + parsed, + NIL, + NIL, + ); } diff --git a/packages/seroval/src/core/compat.ts b/packages/seroval/src/core/compat.ts index 50b907b..fb075b9 100644 --- a/packages/seroval/src/core/compat.ts +++ b/packages/seroval/src/core/compat.ts @@ -10,6 +10,7 @@ export const enum Feature { ErrorPrototypeStack = 0x04, ObjectAssign = 0x08, BigIntTypedArray = 0x10, + AbortSignal = 0x20, } -export const ALL_ENABLED = 0x1f; +export const ALL_ENABLED = 0x2f; diff --git a/packages/seroval/src/core/constants.ts b/packages/seroval/src/core/constants.ts index 636ed3b..bd131f4 100644 --- a/packages/seroval/src/core/constants.ts +++ b/packages/seroval/src/core/constants.ts @@ -45,6 +45,9 @@ export const enum SerovalNodeType { StreamNext = 32, StreamThrow = 33, StreamReturn = 34, + AbortSignalConstructor = 35, + AbortSignalAbort = 36, + AbortSignalSync = 37, } export const enum SerovalObjectFlags { @@ -181,3 +184,5 @@ export const ERROR_CONSTRUCTOR: Record = [ErrorConstructorTag.TypeError]: TypeError, [ErrorConstructorTag.URIError]: URIError, }; + +export const NIL = undefined; diff --git a/packages/seroval/src/core/context/deserializer.ts b/packages/seroval/src/core/context/deserializer.ts index 28fa4f2..b41e584 100644 --- a/packages/seroval/src/core/context/deserializer.ts +++ b/packages/seroval/src/core/context/deserializer.ts @@ -17,6 +17,9 @@ import type { Stream } from '../stream'; import { createStream, streamToAsyncIterable } from '../stream'; import { deserializeString } from '../string'; import type { + SerovalAbortSignalAbortNode, + SerovalAbortSignalConstructorNode, + SerovalAbortSignalSyncNode, SerovalAggregateErrorNode, SerovalArrayBufferNode, SerovalArrayNode, @@ -369,6 +372,30 @@ export default abstract class BaseDeserializerContext return undefined; } + private deserializeAbortSignalConstructor( + node: SerovalAbortSignalConstructorNode, + ): unknown { + return this.assignIndexedValue(node.i, new AbortController()).signal; + } + + private deserializeAbortSignalAbort( + node: SerovalAbortSignalAbortNode, + ): unknown { + const controller = this.refs.get(node.i) as AbortController | undefined; + assert(controller, new SerovalMissingInstanceError('AbortSignal')); + controller.abort(this.deserialize(node.a[1])); + return undefined; + } + + private deserializeAbortSignalSync( + node: SerovalAbortSignalSyncNode, + ): unknown { + return this.assignIndexedValue( + node.i, + AbortSignal.abort(this.deserialize(node.f)), + ); + } + deserialize(node: SerovalNode): unknown { try { switch (node.t) { @@ -438,6 +465,12 @@ export default abstract class BaseDeserializerContext return this.deserializeIteratorFactory(node); case SerovalNodeType.AsyncIteratorFactory: return this.deserializeAsyncIteratorFactory(node); + case SerovalNodeType.AbortSignalAbort: + return this.deserializeAbortSignalAbort(node); + case SerovalNodeType.AbortSignalConstructor: + return this.deserializeAbortSignalConstructor(node); + case SerovalNodeType.AbortSignalSync: + return this.deserializeAbortSignalSync(node); // case SerovalNodeType.SpecialReference: default: throw new SerovalUnsupportedNodeError(node); diff --git a/packages/seroval/src/core/context/parser.ts b/packages/seroval/src/core/context/parser.ts index 262d00a..752faf6 100644 --- a/packages/seroval/src/core/context/parser.ts +++ b/packages/seroval/src/core/context/parser.ts @@ -5,8 +5,9 @@ import { } from '../base-primitives'; import { ALL_ENABLED } from '../compat'; import type { WellKnownSymbols } from '../constants'; -import { INV_SYMBOL_REF, SerovalNodeType } from '../constants'; +import { INV_SYMBOL_REF, NIL, SerovalNodeType } from '../constants'; import { SerovalUnsupportedTypeError } from '../errors'; +import { createSerovalNode } from '../node'; import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin'; import { hasReferenceID } from '../reference'; import { @@ -16,6 +17,7 @@ import { SpecialReference, } from '../special-reference'; import type { + SerovalAbortSignalConstructorNode, SerovalAsyncIteratorFactoryNode, SerovalIndexedValueNode, SerovalIteratorFactoryNode, @@ -151,20 +153,20 @@ export abstract class BaseParserContext implements PluginAccessOptions { if (result.type === NodeType.Indexed) { return result.value; } - return { - t: SerovalNodeType.SpecialReference, - i: result.value, - s: ref, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.SpecialReference, + result.value, + ref, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } protected parseIteratorFactory(): @@ -174,20 +176,20 @@ export abstract class BaseParserContext implements PluginAccessOptions { if (result.type === NodeType.Indexed) { return result.value; } - return { - t: SerovalNodeType.IteratorFactory, - i: result.value, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: this.parseWellKnownSymbol(Symbol.iterator), - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.IteratorFactory, + result.value, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + this.parseWellKnownSymbol(Symbol.iterator), + NIL, + NIL, + ); } protected parseAsyncIteratorFactory(): @@ -197,23 +199,23 @@ export abstract class BaseParserContext implements PluginAccessOptions { if (result.type === NodeType.Indexed) { return result.value; } - return { - t: SerovalNodeType.AsyncIteratorFactory, - i: result.value, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: [ + return createSerovalNode( + SerovalNodeType.AsyncIteratorFactory, + result.value, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [ this.parseSpecialReference(SpecialReference.PromiseConstructor), this.parseWellKnownSymbol(Symbol.asyncIterator), ], - f: undefined, - b: undefined, - o: undefined, - }; + NIL, + NIL, + NIL, + ); } protected createObjectNode( @@ -222,20 +224,20 @@ export abstract class BaseParserContext implements PluginAccessOptions { empty: boolean, record: SerovalObjectRecordNode, ): SerovalObjectNode | SerovalNullConstructorNode { - return { - t: empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: record, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: getObjectFlag(current), - }; + return createSerovalNode( + empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object, + id, + NIL, + NIL, + NIL, + NIL, + record, + NIL, + NIL, + NIL, + NIL, + getObjectFlag(current), + ); } protected createMapNode( @@ -244,38 +246,57 @@ export abstract class BaseParserContext implements PluginAccessOptions { v: SerovalNode[], s: number, ): SerovalMapNode { - return { - t: SerovalNodeType.Map, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: { k, v, s }, - a: undefined, - f: this.parseSpecialReference(SpecialReference.MapSentinel), - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Map, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + { k, v, s }, + NIL, + this.parseSpecialReference(SpecialReference.MapSentinel), + NIL, + NIL, + ); } protected createPromiseConstructorNode( id: number, ): SerovalPromiseConstructorNode { - return { - t: SerovalNodeType.PromiseConstructor, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: this.parseSpecialReference(SpecialReference.PromiseConstructor), - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.PromiseConstructor, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + this.parseSpecialReference(SpecialReference.PromiseConstructor), + NIL, + NIL, + ); + } + + protected createAbortSignalConstructorNode( + id: number, + ): SerovalAbortSignalConstructorNode { + return createSerovalNode( + SerovalNodeType.AbortSignalConstructor, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + this.parseSpecialReference(SpecialReference.AbortSignalConstructor), + NIL, + NIL, + ); } } diff --git a/packages/seroval/src/core/context/parser/async.ts b/packages/seroval/src/core/context/parser/async.ts index 132b3c6..c78b15c 100644 --- a/packages/seroval/src/core/context/parser/async.ts +++ b/packages/seroval/src/core/context/parser/async.ts @@ -1,3 +1,4 @@ +import { abortSignalToPromise } from '../../abort-signal'; import { createAggregateErrorNode, createArrayBufferNode, @@ -22,7 +23,7 @@ import { createTypedArrayNode, } from '../../base-primitives'; import { Feature } from '../../compat'; -import { SerovalNodeType } from '../../constants'; +import { NIL, SerovalNodeType } from '../../constants'; import { SerovalParserError, SerovalUnsupportedTypeError } from '../../errors'; import { FALSE_NODE, @@ -30,12 +31,14 @@ import { TRUE_NODE, UNDEFINED_NODE, } from '../../literals'; +import { createSerovalNode } from '../../node'; import { OpaqueReference } from '../../opaque-reference'; import { SpecialReference } from '../../special-reference'; import type { Stream } from '../../stream'; import { createStreamFromAsyncIterable, isStream } from '../../stream'; import { serializeString } from '../../string'; import type { + SerovalAbortSignalSyncNode, SerovalAggregateErrorNode, SerovalArrayNode, SerovalBigIntTypedArrayNode, @@ -194,7 +197,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { return createErrorNode( id, current, - options ? await this.parseProperties(options) : undefined, + options ? await this.parseProperties(options) : NIL, ); } @@ -206,7 +209,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { return createAggregateErrorNode( id, current, - options ? await this.parseProperties(options) : undefined, + options ? await this.parseProperties(options) : NIL, ); } @@ -239,20 +242,21 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { current: Promise, ): Promise { const [status, result] = await promiseToResult(current); - return { - t: SerovalNodeType.Promise, - i: id, - s: status, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: await this.parse(result), - b: undefined, - o: undefined, - }; + + return createSerovalNode( + SerovalNodeType.Promise, + id, + status, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + await this.parse(result), + NIL, + NIL, + ); } private async parsePlugin( @@ -274,7 +278,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { } } } - return undefined; + return NIL; } private async parseStream( @@ -332,7 +336,37 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { ); } - // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: + private async parseAbortSignalSync( + id: number, + current: AbortSignal, + ): Promise { + return createSerovalNode( + SerovalNodeType.AbortSignalSync, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + await this.parse(current.reason), + NIL, + NIL, + ); + } + + private async parseAbortSignal( + id: number, + current: AbortSignal, + ): Promise { + if (!current.aborted) { + await abortSignalToPromise(current); + } + return this.parseAbortSignalSync(id, current); + } + + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh private async parseObject(id: number, current: object): Promise { if (Array.isArray(current)) { return this.parseArray(id, current); @@ -357,7 +391,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { current as Record, false, ); - case undefined: + case NIL: return this.parsePlainObject( id, current as Record, @@ -406,6 +440,13 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext { return this.parsePromise(id, current as unknown as Promise); } const currentFeatures = this.features; + if ( + currentFeatures & Feature.AbortSignal && + typeof AbortSignal !== 'undefined' && + currentClass === AbortSignal + ) { + return this.parseAbortSignal(id, current as unknown as AbortSignal); + } // BigInt Typed Arrays if (currentFeatures & Feature.BigIntTypedArray) { switch (currentClass) { diff --git a/packages/seroval/src/core/context/parser/stream.ts b/packages/seroval/src/core/context/parser/stream.ts index 1832cc9..17450e0 100644 --- a/packages/seroval/src/core/context/parser/stream.ts +++ b/packages/seroval/src/core/context/parser/stream.ts @@ -8,13 +8,16 @@ import { createStreamThrowNode, createStringNode, } from '../../base-primitives'; -import { SerovalNodeType } from '../../constants'; +import { NIL, SerovalNodeType } from '../../constants'; import { FALSE_NODE, TRUE_NODE } from '../../literals'; +import { createSerovalNode } from '../../node'; import { SpecialReference } from '../../special-reference'; import type { Stream } from '../../stream'; import { createStreamFromAsyncIterable } from '../../stream'; import { serializeString } from '../../string'; import type { + SerovalAbortSignalConstructorNode, + SerovalAbortSignalSyncNode, SerovalNode, SerovalObjectRecordKey, SerovalObjectRecordNode, @@ -164,23 +167,25 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont data => { const parsed = this.parseWithError(data); if (parsed) { - this.onParse({ - t: SerovalNodeType.PromiseResolve, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: [ - this.parseSpecialReference(SpecialReference.PromiseResolve), - parsed, - ], - f: undefined, - b: undefined, - o: undefined, - }); + this.onParse( + createSerovalNode( + SerovalNodeType.PromiseResolve, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [ + this.parseSpecialReference(SpecialReference.PromiseResolve), + parsed, + ], + NIL, + NIL, + NIL, + ), + ); } this.popPendingState(); }, @@ -188,23 +193,25 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont if (this.alive) { const parsed = this.parseWithError(data); if (parsed) { - this.onParse({ - t: SerovalNodeType.PromiseReject, - i: id, - s: undefined, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: [ - this.parseSpecialReference(SpecialReference.PromiseReject), - parsed, - ], - f: undefined, - b: undefined, - o: undefined, - }); + this.onParse( + createSerovalNode( + SerovalNodeType.PromiseReject, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [ + this.parseSpecialReference(SpecialReference.PromiseReject), + parsed, + ], + NIL, + NIL, + NIL, + ), + ); } } this.popPendingState(); @@ -233,7 +240,7 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont } } } - return undefined; + return NIL; } protected parseStream(id: number, current: Stream): SerovalNode { @@ -274,12 +281,57 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont return result; } + protected parseAbortSignal( + id: number, + current: AbortSignal, + ): SerovalAbortSignalConstructorNode | SerovalAbortSignalSyncNode { + if (current.aborted) { + return this.parseAbortSignalSync(id, current); + } + + this.pushPendingState(); + + current.addEventListener( + 'abort', + () => { + if (this.alive) { + const parsed = this.parseWithError(current.reason); + if (parsed) { + this.onParse( + createSerovalNode( + SerovalNodeType.AbortSignalAbort, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + [ + this.parseSpecialReference(SpecialReference.AbortSignalAbort), + parsed, + ], + NIL, + NIL, + NIL, + ), + ); + } + } + this.popPendingState(); + }, + { once: true }, + ); + + return this.createAbortSignalConstructorNode(id); + } + private parseWithError(current: T): SerovalNode | undefined { try { return this.parse(current); } catch (err) { this.onError(err); - return undefined; + return NIL; } } diff --git a/packages/seroval/src/core/context/parser/sync.ts b/packages/seroval/src/core/context/parser/sync.ts index 031321d..722c125 100644 --- a/packages/seroval/src/core/context/parser/sync.ts +++ b/packages/seroval/src/core/context/parser/sync.ts @@ -19,6 +19,7 @@ import { createTypedArrayNode, } from '../../base-primitives'; import { Feature } from '../../compat'; +import { NIL, SerovalNodeType } from '../../constants'; import { SerovalParserError, SerovalUnsupportedTypeError } from '../../errors'; import { FALSE_NODE, @@ -26,12 +27,15 @@ import { TRUE_NODE, UNDEFINED_NODE, } from '../../literals'; +import { createSerovalNode } from '../../node'; import { OpaqueReference } from '../../opaque-reference'; import { SpecialReference } from '../../special-reference'; import type { Stream } from '../../stream'; import { createStream, isStream } from '../../stream'; import { serializeString } from '../../string'; import type { + SerovalAbortSignalConstructorNode, + SerovalAbortSignalSyncNode, SerovalAggregateErrorNode, SerovalArrayNode, SerovalBigIntTypedArrayNode, @@ -167,7 +171,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext { return createErrorNode( id, current, - options ? this.parseProperties(options) : undefined, + options ? this.parseProperties(options) : NIL, ); } @@ -179,7 +183,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext { return createAggregateErrorNode( id, current, - options ? this.parseProperties(options) : undefined, + options ? this.parseProperties(options) : NIL, ); } @@ -241,7 +245,37 @@ export default abstract class BaseSyncParserContext extends BaseParserContext { return this.createPromiseConstructorNode(id); } - // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: + protected parseAbortSignalSync( + id: number, + current: AbortSignal, + ): SerovalAbortSignalSyncNode { + return createSerovalNode( + SerovalNodeType.AbortSignalSync, + id, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + this.parse(current.reason), + NIL, + NIL, + ); + } + + protected parseAbortSignal( + id: number, + current: AbortSignal, + ): SerovalAbortSignalConstructorNode | SerovalAbortSignalSyncNode { + if (current.aborted) { + return this.parseAbortSignalSync(id, current); + } + return this.createAbortSignalConstructorNode(id); + } + + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh protected parseObject(id: number, current: object): SerovalNode { if (Array.isArray(current)) { return this.parseArray(id, current); @@ -315,6 +349,13 @@ export default abstract class BaseSyncParserContext extends BaseParserContext { return this.parsePromise(id, current as unknown as Promise); } const currentFeatures = this.features; + if ( + currentFeatures & Feature.AbortSignal && + typeof AbortSignal !== 'undefined' && + currentClass === AbortSignal + ) { + return this.parseAbortSignal(id, current as unknown as AbortSignal); + } // BigInt Typed Arrays if (currentFeatures & Feature.BigIntTypedArray) { switch (currentClass) { diff --git a/packages/seroval/src/core/context/serializer.ts b/packages/seroval/src/core/context/serializer.ts index 1c3f677..8d82137 100644 --- a/packages/seroval/src/core/context/serializer.ts +++ b/packages/seroval/src/core/context/serializer.ts @@ -2,6 +2,7 @@ import { Feature } from '../compat'; import { CONSTANT_STRING, ERROR_CONSTRUCTOR_STRING, + NIL, SYMBOL_STRING, SerovalNodeType, SerovalObjectFlags, @@ -15,6 +16,9 @@ import { REFERENCES_KEY } from '../keys'; import type { Plugin, PluginAccessOptions, SerovalMode } from '../plugin'; import { SpecialReference } from '../special-reference'; import type { + SerovalAbortSignalAbortNode, + SerovalAbortSignalConstructorNode, + SerovalAbortSignalSyncNode, SerovalAggregateErrorNode, SerovalArrayBufferNode, SerovalArrayNode, @@ -128,7 +132,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] { current = { t: AssignmentType.Index, s: item.s, - k: undefined, + k: NIL, v: getAssignmentExpression(current), } as IndexAssignment; } else if (item.t === AssignmentType.Set && item.s === prev.s) { @@ -144,7 +148,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] { current = { t: AssignmentType.Add, s: getAssignmentExpression(current), - k: undefined, + k: NIL, v: item.v, } as AddAssignment; } else if (item.t === AssignmentType.Delete && item.s === prev.s) { @@ -153,7 +157,7 @@ function mergeAssignments(assignments: Assignment[]): Assignment[] { t: AssignmentType.Delete, s: getAssignmentExpression(current), k: item.k, - v: undefined, + v: NIL, } as DeleteAssignment; } else { // Different assignment, push current @@ -177,7 +181,7 @@ function resolveAssignments(assignments: Assignment[]): string | undefined { } return result; } - return undefined; + return NIL; } const NULL_CONSTRUCTOR = 'Object.create(null)'; @@ -192,7 +196,7 @@ const OBJECT_FLAG_CONSTRUCTOR: Record = [SerovalObjectFlags.Frozen]: 'Object.freeze', [SerovalObjectFlags.Sealed]: 'Object.seal', [SerovalObjectFlags.NonExtensible]: 'Object.preventExtensions', - [SerovalObjectFlags.None]: undefined, + [SerovalObjectFlags.None]: NIL, }; type SerovalNodeWithProperties = @@ -331,7 +335,7 @@ export default abstract class BaseSerializerContext this.assignments.push({ t: AssignmentType.Index, s: source, - k: undefined, + k: NIL, v: value, }); } @@ -340,7 +344,7 @@ export default abstract class BaseSerializerContext this.assignments.push({ t: AssignmentType.Add, s: this.getRefParam(ref), - k: undefined, + k: NIL, v: value, }); } @@ -359,7 +363,7 @@ export default abstract class BaseSerializerContext t: AssignmentType.Delete, s: this.getRefParam(ref), k: key, - v: undefined, + v: NIL, }); } @@ -610,7 +614,7 @@ export default abstract class BaseSerializerContext this.stack.pop(); return resolveAssignments(mainAssignments); } - return undefined; + return NIL; } protected serializeDictionary( @@ -997,6 +1001,16 @@ export default abstract class BaseSerializerContext ) + '})', ); + case SpecialReference.AbortSignalConstructor: + return this.createFunction( + ['a', 's'], + '((s=(a=new AbortController).signal).a=a,s)', + ); + case SpecialReference.AbortSignalAbort: + return this.createEffectfulFunction( + ['s', 'r'], + 's.a.abort(r);delete s.a', + ); default: return ''; } @@ -1159,6 +1173,32 @@ export default abstract class BaseSerializerContext return this.getRefParam(node.i) + '.return(' + this.serialize(node.f) + ')'; } + protected serializeAbortSignalSync(node: SerovalAbortSignalSyncNode): string { + return this.assignIndexedValue( + node.i, + 'AbortSignal.abort(' + this.serialize(node.f) + ')', + ); + } + + protected serializeAbortSignalConstructor( + node: SerovalAbortSignalConstructorNode, + ): string { + return this.assignIndexedValue(node.i, this.getConstructor(node.f) + '()'); + } + + protected serializeAbortSignalAbort( + node: SerovalAbortSignalAbortNode, + ): string { + return ( + this.getConstructor(node.a[0]) + + '(' + + this.getRefParam(node.i) + + ',' + + this.serialize(node.a[1]) + + ')' + ); + } + serialize(node: SerovalNode): string { try { switch (node.t) { @@ -1231,6 +1271,12 @@ export default abstract class BaseSerializerContext return this.serializeStreamThrow(node); case SerovalNodeType.StreamReturn: return this.serializeStreamReturn(node); + case SerovalNodeType.AbortSignalAbort: + return this.serializeAbortSignalAbort(node); + case SerovalNodeType.AbortSignalConstructor: + return this.serializeAbortSignalConstructor(node); + case SerovalNodeType.AbortSignalSync: + return this.serializeAbortSignalSync(node); default: throw new SerovalUnsupportedNodeError(node); } diff --git a/packages/seroval/src/core/literals.ts b/packages/seroval/src/core/literals.ts index fd3a75f..0ec2e66 100644 --- a/packages/seroval/src/core/literals.ts +++ b/packages/seroval/src/core/literals.ts @@ -1,21 +1,22 @@ -import { SerovalConstant, SerovalNodeType } from './constants'; +import { NIL, SerovalConstant, SerovalNodeType } from './constants'; +import { createSerovalNode } from './node'; import type { SerovalConstantNode } from './types'; function createConstantNode(value: SerovalConstant): SerovalConstantNode { - return { - t: SerovalNodeType.Constant, - i: undefined, - s: value, - l: undefined, - c: undefined, - m: undefined, - p: undefined, - e: undefined, - a: undefined, - f: undefined, - b: undefined, - o: undefined, - }; + return createSerovalNode( + SerovalNodeType.Constant, + NIL, + value, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + NIL, + ); } export const TRUE_NODE = /* @__PURE__ */ createConstantNode( diff --git a/packages/seroval/src/core/node.ts b/packages/seroval/src/core/node.ts new file mode 100644 index 0000000..4ffb6ed --- /dev/null +++ b/packages/seroval/src/core/node.ts @@ -0,0 +1,40 @@ +import type { SerovalNodeType } from './constants'; +import type { SerovalNode } from './types'; + +type ExtractedNodeType = Extract< + SerovalNode, + { t: T } +>; + +export function createSerovalNode< + T extends SerovalNodeType, + N extends ExtractedNodeType, +>( + t: T, + i: N['i'], + s: N['s'], + l: N['l'], + c: N['c'], + m: N['m'], + p: N['p'], + e: N['e'], + a: N['a'], + f: N['f'], + b: N['b'], + o: N['o'], +): N { + return { + t, + i, + s, + l, + c, + m, + p, + e, + a, + f, + b, + o, + } as N; +} diff --git a/packages/seroval/src/core/special-reference.ts b/packages/seroval/src/core/special-reference.ts index 7a37e00..f59e6b5 100644 --- a/packages/seroval/src/core/special-reference.ts +++ b/packages/seroval/src/core/special-reference.ts @@ -8,12 +8,19 @@ export const enum SpecialReference { PromiseResolve = 2, PromiseReject = 3, StreamConstructor = 4, + AbortSignalConstructor = 5, + AbortSignalAbort = 6, } +/** + * Placeholder references + */ export const SPECIAL_REFS: Record = { [SpecialReference.MapSentinel]: {}, [SpecialReference.PromiseConstructor]: {}, [SpecialReference.PromiseResolve]: {}, [SpecialReference.PromiseReject]: {}, [SpecialReference.StreamConstructor]: {}, + [SpecialReference.AbortSignalConstructor]: {}, + [SpecialReference.AbortSignalAbort]: {}, }; diff --git a/packages/seroval/src/core/tree/serializer.ts b/packages/seroval/src/core/tree/serializer.ts index 9cd996b..d27189f 100644 --- a/packages/seroval/src/core/tree/serializer.ts +++ b/packages/seroval/src/core/tree/serializer.ts @@ -4,6 +4,7 @@ import BaseSerializerContext from '../context/serializer'; import { SerovalUnsupportedNodeError } from '../errors'; import type { SerovalMode } from '../plugin'; import type { + SerovalAbortSignalAbortNode, SerovalNode, SerovalPromiseConstructorNode, SerovalPromiseRejectNode, @@ -73,6 +74,12 @@ export default class VanillaSerializerContext extends BaseSerializerContext { throw new SerovalUnsupportedNodeError(node); } + protected serializeAbortSignalAbort( + node: SerovalAbortSignalAbortNode, + ): string { + throw new SerovalUnsupportedNodeError(node); + } + serializeTop(tree: SerovalNode): string { const result = this.serialize(tree); // Shared references detected diff --git a/packages/seroval/src/core/types.ts b/packages/seroval/src/core/types.ts index 1d8891e..15e8580 100644 --- a/packages/seroval/src/core/types.ts +++ b/packages/seroval/src/core/types.ts @@ -269,6 +269,9 @@ export interface SerovalPluginNode extends SerovalBaseNode { c: string; } +/** + * Represents special values as placeholders + */ export interface SerovalSpecialReferenceNode extends SerovalBaseNode { t: SerovalNodeType.SpecialReference; i: number; @@ -302,24 +305,48 @@ export interface SerovalStreamConstructorNode extends SerovalBaseNode { t: SerovalNodeType.StreamConstructor; i: number; a: SerovalNode[]; + // special reference to the constructor f: SerovalNodeWithID; } export interface SerovalStreamNextNode extends SerovalBaseNode { t: SerovalNodeType.StreamNext; i: number; + // Next value f: SerovalNode; } export interface SerovalStreamThrowNode extends SerovalBaseNode { t: SerovalNodeType.StreamThrow; i: number; + // Throw value f: SerovalNode; } export interface SerovalStreamReturnNode extends SerovalBaseNode { t: SerovalNodeType.StreamReturn; i: number; + // Return value + f: SerovalNode; +} + +export interface SerovalAbortSignalConstructorNode extends SerovalBaseNode { + t: SerovalNodeType.AbortSignalConstructor; + i: number; + // special reference to the constructor + f: SerovalNodeWithID; +} + +export interface SerovalAbortSignalAbortNode extends SerovalBaseNode { + t: SerovalNodeType.AbortSignalAbort; + i: number; + a: [resolver: SerovalNodeWithID, resolved: SerovalNode]; +} + +export interface SerovalAbortSignalSyncNode extends SerovalBaseNode { + t: SerovalNodeType.AbortSignalSync; + i: number; + // Abort reason f: SerovalNode; } @@ -345,7 +372,8 @@ export type SerovalSyncNode = | SerovalIteratorFactoryNode | SerovalIteratorFactoryInstanceNode | SerovalAsyncIteratorFactoryNode - | SerovalAsyncIteratorFactoryInstanceNode; + | SerovalAsyncIteratorFactoryInstanceNode + | SerovalAbortSignalSyncNode; export type SerovalAsyncNode = | SerovalPromiseNode @@ -355,7 +383,9 @@ export type SerovalAsyncNode = | SerovalStreamConstructorNode | SerovalStreamNextNode | SerovalStreamThrowNode - | SerovalStreamReturnNode; + | SerovalStreamReturnNode + | SerovalAbortSignalConstructorNode + | SerovalAbortSignalAbortNode; export type SerovalNode = SerovalSyncNode | SerovalAsyncNode; diff --git a/packages/seroval/src/core/utils/iterator-to-sequence.ts b/packages/seroval/src/core/utils/iterator-to-sequence.ts index 231663f..00702c5 100644 --- a/packages/seroval/src/core/utils/iterator-to-sequence.ts +++ b/packages/seroval/src/core/utils/iterator-to-sequence.ts @@ -1,3 +1,5 @@ +import { NIL } from "../constants"; + export interface Sequence { v: unknown[]; t: number; @@ -46,7 +48,7 @@ export function sequenceToIterator( if (index > sequence.d) { return { done: true, - value: undefined, + value: NIL, }; } const currentIndex = index++; diff --git a/packages/seroval/test/__snapshots__/abort-signal.test.ts.snap b/packages/seroval/test/__snapshots__/abort-signal.test.ts.snap new file mode 100644 index 0000000..79f0559 --- /dev/null +++ b/packages/seroval/test/__snapshots__/abort-signal.test.ts.snap @@ -0,0 +1,65 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AbortSignal > crossSerialize > scoped > supports aborted AbortSignal 1`] = `"($R=>$R[0]=AbortSignal.abort("aborted!"))($R["example"])"`; + +exports[`AbortSignal > crossSerialize > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))())($R["example"])"`; + +exports[`AbortSignal > crossSerialize > supports aborted AbortSignal 1`] = `"$R[0]=AbortSignal.abort("aborted!")"`; + +exports[`AbortSignal > crossSerialize > supports future AbortSignal 1`] = `"$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))()"`; + +exports[`AbortSignal > crossSerializeAsync > scoped > supports aborted AbortSignal 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=AbortSignal.abort("aborted!")))($R["example"])"`; + +exports[`AbortSignal > crossSerializeAsync > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=AbortSignal.abort($R[1]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"})))($R["example"])"`; + +exports[`AbortSignal > crossSerializeAsync > supports aborted AbortSignal 1`] = `"$R[0]=Promise.resolve($R[1]=AbortSignal.abort("aborted!"))"`; + +exports[`AbortSignal > crossSerializeAsync > supports future AbortSignal 1`] = `"$R[0]=AbortSignal.abort($R[1]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`; + +exports[`AbortSignal > crossSerializeStream > scoped > supports aborted AbortSignal 1`] = `"($R=>$R[0]=($R[1]=(s,f,p)=>((p=new Promise((a,b)=>{s=a,f=b})).s=s,p.f=f,p))())($R["example"])"`; + +exports[`AbortSignal > crossSerializeStream > scoped > supports aborted AbortSignal 2`] = `"($R=>($R[3]=(p,d)=>{p.s(d),p.status="success",p.value=d;delete p.s;delete p.f})($R[0],$R[2]=AbortSignal.abort("aborted!")))($R["example"])"`; + +exports[`AbortSignal > crossSerializeStream > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))())($R["example"])"`; + +exports[`AbortSignal > crossSerializeStream > scoped > supports future AbortSignal 2`] = `"($R=>($R[3]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],$R[2]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"})))($R["example"])"`; + +exports[`AbortSignal > crossSerializeStream > supports aborted AbortSignal 1`] = `"$R[0]=($R[1]=(s,f,p)=>((p=new Promise((a,b)=>{s=a,f=b})).s=s,p.f=f,p))()"`; + +exports[`AbortSignal > crossSerializeStream > supports aborted AbortSignal 2`] = `"($R[3]=(p,d)=>{p.s(d),p.status="success",p.value=d;delete p.s;delete p.f})($R[0],$R[2]=AbortSignal.abort("aborted!"))"`; + +exports[`AbortSignal > crossSerializeStream > supports future AbortSignal 1`] = `"$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))()"`; + +exports[`AbortSignal > crossSerializeStream > supports future AbortSignal 2`] = `"($R[3]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],$R[2]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`; + +exports[`AbortSignal > serialize > supports aborted AbortSignal 1`] = `"AbortSignal.abort("aborted!")"`; + +exports[`AbortSignal > serialize > supports future AbortSignal 1`] = `"(h=>((a,s)=>((s=(a=new AbortController).signal).a=a,s))())()"`; + +exports[`AbortSignal > serializeAsync > supports aborted AbortSignal 1`] = `"Promise.resolve(AbortSignal.abort("aborted!"))"`; + +exports[`AbortSignal > serializeAsync > supports future AbortSignal 1`] = `"AbortSignal.abort(Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`; + +exports[`AbortSignal > toCrossJSON > supports aborted AbortSignal 1`] = `"{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}}"`; + +exports[`AbortSignal > toCrossJSON > supports future AbortSignal 1`] = `"{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}}"`; + +exports[`AbortSignal > toCrossJSONAsync > supports aborted AbortSignal 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":37,"i":1,"f":{"t":1,"s":"aborted!"}}}"`; + +exports[`AbortSignal > toCrossJSONAsync > supports future AbortSignal 1`] = `"{"t":37,"i":0,"f":{"t":13,"i":1,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}}"`; + +exports[`AbortSignal > toCrossJSONStream > supports aborted AbortSignal 1`] = `"{"t":22,"i":0,"f":{"t":26,"i":1,"s":1}}"`; + +exports[`AbortSignal > toCrossJSONStream > supports aborted AbortSignal 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":37,"i":2,"f":{"t":1,"s":"aborted!"}}]}"`; + +exports[`AbortSignal > toCrossJSONStream > supports future AbortSignal 1`] = `"{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}}"`; + +exports[`AbortSignal > toCrossJSONStream > supports future AbortSignal 2`] = `"{"t":36,"i":0,"a":[{"t":26,"i":3,"s":6},{"t":13,"i":2,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}]}"`; + +exports[`AbortSignal > toJSON > supports aborted AbortSignal 1`] = `"{"t":{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}},"f":47,"m":[]}"`; + +exports[`AbortSignal > toJSON > supports future AbortSignal 1`] = `"{"t":{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}},"f":47,"m":[]}"`; + +exports[`AbortSignal > toJSONAsync > supports aborted AbortSignal 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":37,"i":1,"f":{"t":1,"s":"aborted!"}}},"f":47,"m":[]}"`; + +exports[`AbortSignal > toJSONAsync > supports future AbortSignal 1`] = `"{"t":{"t":37,"i":0,"f":{"t":13,"i":1,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/array.test.ts.snap b/packages/seroval/test/__snapshots__/array.test.ts.snap index e873caf..4311fe8 100644 --- a/packages/seroval/test/__snapshots__/array.test.ts.snap +++ b/packages/seroval/test/__snapshots__/array.test.ts.snap @@ -62,10 +62,10 @@ exports[`arrays > toCrossJSONStream > supports self recursion 2`] = `"{"t":23,"i exports[`arrays > toCrossJSONStream > supports self recursion 3`] = `"{"t":23,"i":3,"a":[{"t":4,"i":4},{"t":4,"i":0}]}"`; -exports[`arrays > toJSON > supports Arrays 1`] = `"{"t":{"t":9,"i":0,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}],"o":0},"f":31,"m":[]}"`; +exports[`arrays > toJSON > supports Arrays 1`] = `"{"t":{"t":9,"i":0,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}],"o":0},"f":47,"m":[]}"`; -exports[`arrays > toJSON > supports self recursion 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":4,"i":0},{"t":4,"i":0}],"o":0},"f":31,"m":[0]}"`; +exports[`arrays > toJSON > supports self recursion 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":4,"i":0},{"t":4,"i":0}],"o":0},"f":47,"m":[0]}"`; -exports[`arrays > toJSONAsync > supports Arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":9,"i":1,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}],"o":0}},"f":31,"m":[]}"`; +exports[`arrays > toJSONAsync > supports Arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":9,"i":1,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}],"o":0}},"f":47,"m":[]}"`; -exports[`arrays > toJSONAsync > supports self recursion 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"o":0},"f":31,"m":[0]}"`; +exports[`arrays > toJSONAsync > supports self recursion 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"o":0},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/async-iterable.test.ts.snap b/packages/seroval/test/__snapshots__/async-iterable.test.ts.snap index 49047ca..846330d 100644 --- a/packages/seroval/test/__snapshots__/async-iterable.test.ts.snap +++ b/packages/seroval/test/__snapshots__/async-iterable.test.ts.snap @@ -2,7 +2,7 @@ exports[`AsyncIterable > compat > should use function expressions instead of arrow functions. 1`] = `"(function(h,j,k,m,o){return {title:"Hello World",[h=Symbol.asyncIterator]:((j=function(s,f,p){return ((p=new Promise(function(a,b){s=a,f=b})).s=s,p.f=f,p)},function(s){return function(b,c,p,d,e,t,f){return (b=[],c=0,p=[],d=-1,e=!1,f=function(i,l){for(i=0,l=p.length;i=b.length)?(p.push(t=j()),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}}})}}))((o=(function(b,a,s,l,p,f,e,n){return (b=[],a=!0,s=!1,l=[],p=0,f=function(v,m,x){for(x=0;x compat#toJSONAsync > should use function expression instead of arrow functions. 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":0}],"v":[{"t":1,"s":"Hello World"},{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":2},"o":0},"f":29,"m":[1,4]}"`; +exports[`AsyncIterable > compat#toJSONAsync > should use function expression instead of arrow functions. 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":0}],"v":[{"t":1,"s":"Hello World"},{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":2},"o":0},"f":45,"m":[1,4]}"`; exports[`AsyncIterable > compat#toJSONAsync > should use function expression instead of arrow functions. 2`] = `"(function(h,j,k,m,o){return {title:"Hello World",[h=Symbol.asyncIterator]:((j=function(s,f,p){return ((p=new Promise(function(a,b){s=a,f=b})).s=s,p.f=f,p)},function(s){return function(b,c,p,d,e,t,f){return (b=[],c=0,p=[],d=-1,e=!1,f=function(i,l){for(i=0,l=p.length;i=b.length)?(p.push(t=j()),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}}})}}))((o=(function(b,a,s,l,p,f,e,n){return (b=[],a=!0,s=!1,l=[],p=0,f=function(v,m,x){for(x=0;x toCrossJSONStream > supports AsyncIterables 4`] = `"{"t exports[`AsyncIterable > toCrossJSONStream > supports AsyncIterables 5`] = `"{"t":34,"i":4,"f":{"t":2,"s":1}}"`; -exports[`AsyncIterable > toJSONAsync > supports AsyncIterables 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":0}],"v":[{"t":1,"s":"Hello World"},{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":2},"o":0},"f":31,"m":[1,4]}"`; +exports[`AsyncIterable > toJSONAsync > supports AsyncIterables 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":0}],"v":[{"t":1,"s":"Hello World"},{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":2},"o":0},"f":47,"m":[1,4]}"`; diff --git a/packages/seroval/test/__snapshots__/bigint.test.ts.snap b/packages/seroval/test/__snapshots__/bigint.test.ts.snap index 6eecdf7..e1e00c1 100644 --- a/packages/seroval/test/__snapshots__/bigint.test.ts.snap +++ b/packages/seroval/test/__snapshots__/bigint.test.ts.snap @@ -20,6 +20,6 @@ exports[`bigint > toCrossJSONStream > supports bigint 1`] = `"{"t":22,"i":0,"f": exports[`bigint > toCrossJSONStream > supports bigint 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":2,"s":2},{"t":3,"s":"9007199254740991"}]}"`; -exports[`bigint > toJSON > supports bigint 1`] = `"{"t":{"t":3,"s":"9007199254740991"},"f":31,"m":[]}"`; +exports[`bigint > toJSON > supports bigint 1`] = `"{"t":{"t":3,"s":"9007199254740991"},"f":47,"m":[]}"`; -exports[`bigint > toJSONAsync > supports bigint 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":3,"s":"9007199254740991"}},"f":31,"m":[]}"`; +exports[`bigint > toJSONAsync > supports bigint 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":3,"s":"9007199254740991"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/boolean.test.ts.snap b/packages/seroval/test/__snapshots__/boolean.test.ts.snap index f7cf596..d945637 100644 --- a/packages/seroval/test/__snapshots__/boolean.test.ts.snap +++ b/packages/seroval/test/__snapshots__/boolean.test.ts.snap @@ -32,10 +32,10 @@ exports[`boolean > toCrossJSONStream > supports true value 1`] = `"{"t":22,"i":0 exports[`boolean > toCrossJSONStream > supports true value 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":2,"s":2},{"t":2,"s":2}]}"`; -exports[`boolean > toJSON > supports boolean 1`] = `"{"t":{"t":2,"s":2},"f":31,"m":[]}"`; +exports[`boolean > toJSON > supports boolean 1`] = `"{"t":{"t":2,"s":2},"f":47,"m":[]}"`; -exports[`boolean > toJSON > supports boolean 2`] = `"{"t":{"t":2,"s":3},"f":31,"m":[]}"`; +exports[`boolean > toJSON > supports boolean 2`] = `"{"t":{"t":2,"s":3},"f":47,"m":[]}"`; -exports[`boolean > toJSONAsync > supports boolean 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":2}},"f":31,"m":[]}"`; +exports[`boolean > toJSONAsync > supports boolean 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":2}},"f":47,"m":[]}"`; -exports[`boolean > toJSONAsync > supports boolean 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":3}},"f":31,"m":[]}"`; +exports[`boolean > toJSONAsync > supports boolean 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":3}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/boxed-bigint.test.ts.snap b/packages/seroval/test/__snapshots__/boxed-bigint.test.ts.snap index 16ea7c1..5b5c6ac 100644 --- a/packages/seroval/test/__snapshots__/boxed-bigint.test.ts.snap +++ b/packages/seroval/test/__snapshots__/boxed-bigint.test.ts.snap @@ -28,6 +28,6 @@ exports[`boxed bigint > toCrossJSONStream > supports boxed bigint 1`] = `"{"t":2 exports[`boxed bigint > toCrossJSONStream > supports boxed bigint 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":21,"i":2,"f":{"t":3,"s":"9007199254740991"}}]}"`; -exports[`boxed bigint > toJSON > supports boxed bigint 1`] = `"{"t":{"t":21,"i":0,"f":{"t":3,"s":"9007199254740991"}},"f":31,"m":[]}"`; +exports[`boxed bigint > toJSON > supports boxed bigint 1`] = `"{"t":{"t":21,"i":0,"f":{"t":3,"s":"9007199254740991"}},"f":47,"m":[]}"`; -exports[`boxed bigint > toJSONAsync > supports boxed bigint 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":3,"s":"9007199254740991"}}},"f":31,"m":[]}"`; +exports[`boxed bigint > toJSONAsync > supports boxed bigint 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":3,"s":"9007199254740991"}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/boxed-boolean.test.ts.snap b/packages/seroval/test/__snapshots__/boxed-boolean.test.ts.snap index 2c378ef..ffa2763 100644 --- a/packages/seroval/test/__snapshots__/boxed-boolean.test.ts.snap +++ b/packages/seroval/test/__snapshots__/boxed-boolean.test.ts.snap @@ -48,10 +48,10 @@ exports[`boxed boolean > toCrossJSONStream > supports boxed true 1`] = `"{"t":22 exports[`boxed boolean > toCrossJSONStream > supports boxed true 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":21,"i":2,"f":{"t":2,"s":2}}]}"`; -exports[`boxed boolean > toJSON > supports boolean 1`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":2}},"f":31,"m":[]}"`; +exports[`boxed boolean > toJSON > supports boolean 1`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":2}},"f":47,"m":[]}"`; -exports[`boxed boolean > toJSON > supports boolean 2`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":3}},"f":31,"m":[]}"`; +exports[`boxed boolean > toJSON > supports boolean 2`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":3}},"f":47,"m":[]}"`; -exports[`boxed boolean > toJSONAsync > supports boolean 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":2}}},"f":31,"m":[]}"`; +exports[`boxed boolean > toJSONAsync > supports boolean 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":2}}},"f":47,"m":[]}"`; -exports[`boxed boolean > toJSONAsync > supports boolean 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":3}}},"f":31,"m":[]}"`; +exports[`boxed boolean > toJSONAsync > supports boolean 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":3}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/boxed-number.test.ts.snap b/packages/seroval/test/__snapshots__/boxed-number.test.ts.snap index a14dd08..4752a24 100644 --- a/packages/seroval/test/__snapshots__/boxed-number.test.ts.snap +++ b/packages/seroval/test/__snapshots__/boxed-number.test.ts.snap @@ -120,22 +120,22 @@ exports[`boxed number > toCrossJSONStream > supports boxed numbers 1`] = `"{"t": exports[`boxed number > toCrossJSONStream > supports boxed numbers 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":21,"i":2,"f":{"t":0,"s":3735928559}}]}"`; -exports[`boxed number > toJSON > supports boxed numbers 1`] = `"{"t":{"t":21,"i":0,"f":{"t":0,"s":3735928559}},"f":31,"m":[]}"`; +exports[`boxed number > toJSON > supports boxed numbers 1`] = `"{"t":{"t":21,"i":0,"f":{"t":0,"s":3735928559}},"f":47,"m":[]}"`; -exports[`boxed number > toJSON > supports boxed numbers 2`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":7}},"f":31,"m":[]}"`; +exports[`boxed number > toJSON > supports boxed numbers 2`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":7}},"f":47,"m":[]}"`; -exports[`boxed number > toJSON > supports boxed numbers 3`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":5}},"f":31,"m":[]}"`; +exports[`boxed number > toJSON > supports boxed numbers 3`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":5}},"f":47,"m":[]}"`; -exports[`boxed number > toJSON > supports boxed numbers 4`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":6}},"f":31,"m":[]}"`; +exports[`boxed number > toJSON > supports boxed numbers 4`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":6}},"f":47,"m":[]}"`; -exports[`boxed number > toJSON > supports boxed numbers 5`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":4}},"f":31,"m":[]}"`; +exports[`boxed number > toJSON > supports boxed numbers 5`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":4}},"f":47,"m":[]}"`; -exports[`boxed number > toJSONAsync > supports boxed numbers 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":0,"s":3735928559}}},"f":31,"m":[]}"`; +exports[`boxed number > toJSONAsync > supports boxed numbers 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":0,"s":3735928559}}},"f":47,"m":[]}"`; -exports[`boxed number > toJSONAsync > supports boxed numbers 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":7}}},"f":31,"m":[]}"`; +exports[`boxed number > toJSONAsync > supports boxed numbers 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":7}}},"f":47,"m":[]}"`; -exports[`boxed number > toJSONAsync > supports boxed numbers 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":5}}},"f":31,"m":[]}"`; +exports[`boxed number > toJSONAsync > supports boxed numbers 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":5}}},"f":47,"m":[]}"`; -exports[`boxed number > toJSONAsync > supports boxed numbers 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":6}}},"f":31,"m":[]}"`; +exports[`boxed number > toJSONAsync > supports boxed numbers 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":6}}},"f":47,"m":[]}"`; -exports[`boxed number > toJSONAsync > supports boxed numbers 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":4}}},"f":31,"m":[]}"`; +exports[`boxed number > toJSONAsync > supports boxed numbers 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":4}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/boxed-string.test.ts.snap b/packages/seroval/test/__snapshots__/boxed-string.test.ts.snap index b4d49d2..e03b9c5 100644 --- a/packages/seroval/test/__snapshots__/boxed-string.test.ts.snap +++ b/packages/seroval/test/__snapshots__/boxed-string.test.ts.snap @@ -56,10 +56,10 @@ exports[`boxed string > toCrossJSONStream > supports boxed strings 1`] = `"{"t": exports[`boxed string > toCrossJSONStream > supports boxed strings 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":21,"i":2,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}}]}"`; -exports[`boxed string > toJSON > supports boxed strings 1`] = `"{"t":{"t":21,"i":0,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}},"f":31,"m":[]}"`; +exports[`boxed string > toJSON > supports boxed strings 1`] = `"{"t":{"t":21,"i":0,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}},"f":47,"m":[]}"`; -exports[`boxed string > toJSON > supports boxed strings 2`] = `"{"t":{"t":21,"i":0,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}},"f":31,"m":[]}"`; +exports[`boxed string > toJSON > supports boxed strings 2`] = `"{"t":{"t":21,"i":0,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}},"f":47,"m":[]}"`; -exports[`boxed string > toJSONAsync > supports boxed strings 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}}},"f":31,"m":[]}"`; +exports[`boxed string > toJSONAsync > supports boxed strings 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}}},"f":47,"m":[]}"`; -exports[`boxed string > toJSONAsync > supports boxed strings 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}}},"f":31,"m":[]}"`; +exports[`boxed string > toJSONAsync > supports boxed strings 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/data-view.test.ts.snap b/packages/seroval/test/__snapshots__/data-view.test.ts.snap index 347365c..e689c75 100644 --- a/packages/seroval/test/__snapshots__/data-view.test.ts.snap +++ b/packages/seroval/test/__snapshots__/data-view.test.ts.snap @@ -28,6 +28,6 @@ exports[`DataView > toCrossJSONStream > supports DataView 1`] = `"{"t":22,"i":0, exports[`DataView > toCrossJSONStream > supports DataView 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":4,"s":2},{"t":20,"i":2,"l":16,"f":{"t":19,"i":3,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0}]}"`; -exports[`DataView > toJSON > supports DataView 1`] = `"{"t":{"t":20,"i":0,"l":16,"f":{"t":19,"i":1,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0},"f":31,"m":[]}"`; +exports[`DataView > toJSON > supports DataView 1`] = `"{"t":{"t":20,"i":0,"l":16,"f":{"t":19,"i":1,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0},"f":47,"m":[]}"`; -exports[`DataView > toJSONAsync > supports DataView 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":20,"i":1,"l":16,"f":{"t":19,"i":2,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0}},"f":31,"m":[]}"`; +exports[`DataView > toJSONAsync > supports DataView 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":20,"i":1,"l":16,"f":{"t":19,"i":2,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/date.test.ts.snap b/packages/seroval/test/__snapshots__/date.test.ts.snap index 30a9cd6..05a7222 100644 --- a/packages/seroval/test/__snapshots__/date.test.ts.snap +++ b/packages/seroval/test/__snapshots__/date.test.ts.snap @@ -28,6 +28,6 @@ exports[`Date > toCrossJSONStream > supports Date 1`] = `"{"t":22,"i":0,"f":{"t" exports[`Date > toCrossJSONStream > supports Date 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":5,"i":2,"s":"2023-03-14T11:16:24.879Z"}]}"`; -exports[`Date > toJSON > supports Date 1`] = `"{"t":{"t":5,"i":0,"s":"2023-03-14T11:16:24.879Z"},"f":31,"m":[]}"`; +exports[`Date > toJSON > supports Date 1`] = `"{"t":{"t":5,"i":0,"s":"2023-03-14T11:16:24.879Z"},"f":47,"m":[]}"`; -exports[`Date > toJSONAsync > supports Date 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":5,"i":1,"s":"2023-03-14T11:16:24.879Z"}},"f":31,"m":[]}"`; +exports[`Date > toJSONAsync > supports Date 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":5,"i":1,"s":"2023-03-14T11:16:24.879Z"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/error.test.ts.snap b/packages/seroval/test/__snapshots__/error.test.ts.snap index 0ddb1a6..b16502c 100644 --- a/packages/seroval/test/__snapshots__/error.test.ts.snap +++ b/packages/seroval/test/__snapshots__/error.test.ts.snap @@ -90,14 +90,14 @@ exports[`Error > toCrossJSONStream > supports other Error classes 1`] = `"{"t":2 exports[`Error > toCrossJSONStream > supports other Error classes 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":13,"i":2,"s":3,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}]}"`; -exports[`Error > toJSON > supports Error.prototype.cause 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"B","p":{"k":["stack","cause"],"v":[{"t":1,"s":""},{"t":13,"i":1,"s":0,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}],"s":2}},"f":31,"m":[]}"`; +exports[`Error > toJSON > supports Error.prototype.cause 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"B","p":{"k":["stack","cause"],"v":[{"t":1,"s":""},{"t":13,"i":1,"s":0,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}],"s":2}},"f":47,"m":[]}"`; -exports[`Error > toJSON > supports Error.prototype.name 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"A","p":{"k":["name","stack"],"v":[{"t":1,"s":"ExampleError"},{"t":1,"s":""}],"s":2}},"f":31,"m":[]}"`; +exports[`Error > toJSON > supports Error.prototype.name 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"A","p":{"k":["name","stack"],"v":[{"t":1,"s":"ExampleError"},{"t":1,"s":""}],"s":2}},"f":47,"m":[]}"`; -exports[`Error > toJSON > supports other Error classes 1`] = `"{"t":{"t":13,"i":0,"s":3,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}},"f":31,"m":[]}"`; +exports[`Error > toJSON > supports other Error classes 1`] = `"{"t":{"t":13,"i":0,"s":3,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}},"f":47,"m":[]}"`; -exports[`Error > toJSONAsync > supports Error.prototype.cause 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"B","p":{"k":["stack","cause"],"v":[{"t":1,"s":""},{"t":12,"i":1,"s":1,"f":{"t":13,"i":2,"s":0,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}}],"s":2}},"f":31,"m":[]}"`; +exports[`Error > toJSONAsync > supports Error.prototype.cause 1`] = `"{"t":{"t":13,"i":0,"s":0,"m":"B","p":{"k":["stack","cause"],"v":[{"t":1,"s":""},{"t":12,"i":1,"s":1,"f":{"t":13,"i":2,"s":0,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}}],"s":2}},"f":47,"m":[]}"`; -exports[`Error > toJSONAsync > supports Error.prototype.name 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":13,"i":1,"s":0,"m":"A","p":{"k":["name","stack"],"v":[{"t":1,"s":"ExampleError"},{"t":1,"s":""}],"s":2}}},"f":31,"m":[]}"`; +exports[`Error > toJSONAsync > supports Error.prototype.name 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":13,"i":1,"s":0,"m":"A","p":{"k":["name","stack"],"v":[{"t":1,"s":"ExampleError"},{"t":1,"s":""}],"s":2}}},"f":47,"m":[]}"`; -exports[`Error > toJSONAsync > supports other Error classes 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":13,"i":1,"s":3,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}},"f":31,"m":[]}"`; +exports[`Error > toJSONAsync > supports other Error classes 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":13,"i":1,"s":3,"m":"A","p":{"k":["stack"],"v":[{"t":1,"s":""}],"s":1}}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/frozen-object.test.ts.snap b/packages/seroval/test/__snapshots__/frozen-object.test.ts.snap index 837f071..b857e38 100644 --- a/packages/seroval/test/__snapshots__/frozen-object.test.ts.snap +++ b/packages/seroval/test/__snapshots__/frozen-object.test.ts.snap @@ -128,16 +128,16 @@ exports[`frozen object > toCrossJSONStream > supports self-recursion 2`] = `"{"t exports[`frozen object > toCrossJSONStream > supports self-recursion 3`] = `"{"t":23,"i":3,"a":[{"t":4,"i":4},{"t":4,"i":0}]}"`; -exports[`frozen object > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":3},"f":31,"m":[]}"`; +exports[`frozen object > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":3},"f":47,"m":[]}"`; -exports[`frozen object > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":3},"f":31,"m":[1]}"`; +exports[`frozen object > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":3},"f":47,"m":[1]}"`; -exports[`frozen object > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":3},"f":31,"m":[0]}"`; +exports[`frozen object > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":3},"f":47,"m":[0]}"`; -exports[`frozen object > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":3}},"f":31,"m":[]}"`; +exports[`frozen object > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":3}},"f":47,"m":[]}"`; -exports[`frozen object > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":3},"f":31,"m":[1,4]}"`; +exports[`frozen object > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":3},"f":47,"m":[1,4]}"`; -exports[`frozen object > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":3}},"f":31,"m":[2]}"`; +exports[`frozen object > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":3}},"f":47,"m":[2]}"`; -exports[`frozen object > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":3},"f":31,"m":[0]}"`; +exports[`frozen object > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":3},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/iterable.test.ts.snap b/packages/seroval/test/__snapshots__/iterable.test.ts.snap index ec4fba3..f5c1fd1 100644 --- a/packages/seroval/test/__snapshots__/iterable.test.ts.snap +++ b/packages/seroval/test/__snapshots__/iterable.test.ts.snap @@ -2,7 +2,7 @@ exports[`Iterable > compat > should use function expression instead of arrow functions. 1`] = `"(function(h,j){return {title:"Hello World",[h=Symbol.iterator]:(function(s){return function(i,c,d,t){return (i=0,t={[h]:function(){return t},next:function(){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}}})}})({v:[1,2,3,void 0],t:-1,d:3})}})()"`; -exports[`Iterable > compat#toJSON > should use function expression instead of arrow functions. 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0},"f":29,"m":[1]}"`; +exports[`Iterable > compat#toJSON > should use function expression instead of arrow functions. 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0},"f":45,"m":[1]}"`; exports[`Iterable > compat#toJSON > should use function expression instead of arrow functions. 2`] = `"(function(h,j){return {title:"Hello World",[h=Symbol.iterator]:(function(s){return function(i,c,d,t){return (i=0,t={[h]:function(){return t},next:function(){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}}})}})({v:[1,2,3,void 0],t:-1,d:3})}})()"`; @@ -34,6 +34,6 @@ exports[`Iterable > toCrossJSONStream > supports Iterables 1`] = `"{"t":22,"i":0 exports[`Iterable > toCrossJSONStream > supports Iterables 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":7,"s":2},{"t":10,"i":2,"p":{"k":["title",{"t":17,"i":3,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":4,"f":{"t":4,"i":3}},{"t":10,"i":5,"p":{"k":["v","t","d"],"v":[{"t":9,"i":6,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0}]}"`; -exports[`Iterable > toJSON > supports Iterables 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0},"f":31,"m":[1]}"`; +exports[`Iterable > toJSON > supports Iterables 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["title",{"t":17,"i":1,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0},"f":47,"m":[1]}"`; -exports[`Iterable > toJSONAsync > supports Iterables 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["title",{"t":17,"i":2,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0}},"f":31,"m":[2]}"`; +exports[`Iterable > toJSONAsync > supports Iterables 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["title",{"t":17,"i":2,"s":3}],"v":[{"t":1,"s":"Hello World"},{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":2},"o":0}},"f":47,"m":[2]}"`; diff --git a/packages/seroval/test/__snapshots__/map.test.ts.snap b/packages/seroval/test/__snapshots__/map.test.ts.snap index 64e602e..0365158 100644 --- a/packages/seroval/test/__snapshots__/map.test.ts.snap +++ b/packages/seroval/test/__snapshots__/map.test.ts.snap @@ -62,10 +62,10 @@ exports[`Map > toCrossJSONAsync > supports Map 1`] = `"{"t":12,"i":0,"s":1,"f":{ exports[`Map > toCrossJSONAsync > supports self-recursion 1`] = `"{"t":8,"i":0,"e":{"k":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}],"v":[{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":1},"f":{"t":26,"i":3,"s":0}}"`; -exports[`Map > toJSON > supports Map 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":0,"s":1},{"t":0,"s":3}],"v":[{"t":0,"s":2},{"t":0,"s":4}],"s":2},"f":{"t":26,"i":1,"s":0}},"f":31,"m":[]}"`; +exports[`Map > toJSON > supports Map 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":0,"s":1},{"t":0,"s":3}],"v":[{"t":0,"s":2},{"t":0,"s":4}],"s":2},"f":{"t":26,"i":1,"s":0}},"f":47,"m":[]}"`; -exports[`Map > toJSON > supports self-recursion 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":4,"i":0}],"v":[{"t":4,"i":0}],"s":1},"f":{"t":26,"i":1,"s":0}},"f":31,"m":[0]}"`; +exports[`Map > toJSON > supports self-recursion 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":4,"i":0}],"v":[{"t":4,"i":0}],"s":1},"f":{"t":26,"i":1,"s":0}},"f":47,"m":[0]}"`; -exports[`Map > toJSONAsync > supports Map 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":8,"i":1,"e":{"k":[{"t":0,"s":1},{"t":0,"s":3}],"v":[{"t":0,"s":2},{"t":0,"s":4}],"s":2},"f":{"t":26,"i":2,"s":0}}},"f":31,"m":[]}"`; +exports[`Map > toJSONAsync > supports Map 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":8,"i":1,"e":{"k":[{"t":0,"s":1},{"t":0,"s":3}],"v":[{"t":0,"s":2},{"t":0,"s":4}],"s":2},"f":{"t":26,"i":2,"s":0}}},"f":47,"m":[]}"`; -exports[`Map > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}],"v":[{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":1},"f":{"t":26,"i":3,"s":0}},"f":31,"m":[0]}"`; +exports[`Map > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":8,"i":0,"e":{"k":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}],"v":[{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":1},"f":{"t":26,"i":3,"s":0}},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/mutual-cycle.test.ts.snap b/packages/seroval/test/__snapshots__/mutual-cycle.test.ts.snap index 351f6a5..7563ce4 100644 --- a/packages/seroval/test/__snapshots__/mutual-cycle.test.ts.snap +++ b/packages/seroval/test/__snapshots__/mutual-cycle.test.ts.snap @@ -102,14 +102,14 @@ exports[`mutual cyclic references > toCrossJSONStream > supports Objects and Obj exports[`mutual cyclic references > toCrossJSONStream > supports Objects and Objects 3`] = `"{"t":23,"i":5,"a":[{"t":4,"i":6},{"t":4,"i":1}]}"`; -exports[`mutual cyclic references > toJSON > supports Arrays and Arrays 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":9,"i":2,"l":1,"a":[{"t":4,"i":1}],"o":0}],"o":0},{"t":4,"i":2}],"o":0},"f":31,"m":[1,2]}"`; +exports[`mutual cyclic references > toJSON > supports Arrays and Arrays 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":9,"i":2,"l":1,"a":[{"t":4,"i":1}],"o":0}],"o":0},{"t":4,"i":2}],"o":0},"f":47,"m":[1,2]}"`; -exports[`mutual cyclic references > toJSON > supports Arrays and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":10,"i":2,"p":{"k":["0"],"v":[{"t":4,"i":1}],"s":1},"o":0}],"o":0},{"t":4,"i":2}],"o":0},"f":31,"m":[1,2]}"`; +exports[`mutual cyclic references > toJSON > supports Arrays and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":10,"i":2,"p":{"k":["0"],"v":[{"t":4,"i":1}],"s":1},"o":0}],"o":0},{"t":4,"i":2}],"o":0},"f":47,"m":[1,2]}"`; -exports[`mutual cyclic references > toJSON > supports Objects and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":10,"i":1,"p":{"k":["0"],"v":[{"t":10,"i":2,"p":{"k":["0"],"v":[{"t":4,"i":1}],"s":1},"o":0}],"s":1},"o":0},{"t":4,"i":2}],"o":0},"f":31,"m":[1,2]}"`; +exports[`mutual cyclic references > toJSON > supports Objects and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":10,"i":1,"p":{"k":["0"],"v":[{"t":10,"i":2,"p":{"k":["0"],"v":[{"t":4,"i":1}],"s":1},"o":0}],"s":1},"o":0},{"t":4,"i":2}],"o":0},"f":47,"m":[1,2]}"`; -exports[`mutual cyclic references > toJSONAsync > supports Arrays and Arrays 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":12,"i":2,"s":1,"f":{"t":9,"i":3,"l":1,"a":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"o":0}}],"o":0},{"t":4,"i":3}],"o":0},"f":31,"m":[1,3]}"`; +exports[`mutual cyclic references > toJSONAsync > supports Arrays and Arrays 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":12,"i":2,"s":1,"f":{"t":9,"i":3,"l":1,"a":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"o":0}}],"o":0},{"t":4,"i":3}],"o":0},"f":47,"m":[1,3]}"`; -exports[`mutual cyclic references > toJSONAsync > supports Arrays and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":12,"i":2,"s":1,"f":{"t":10,"i":3,"p":{"k":["0"],"v":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"s":1},"o":0}}],"o":0},{"t":4,"i":3}],"o":0},"f":31,"m":[1,3]}"`; +exports[`mutual cyclic references > toJSONAsync > supports Arrays and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":9,"i":1,"l":1,"a":[{"t":12,"i":2,"s":1,"f":{"t":10,"i":3,"p":{"k":["0"],"v":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"s":1},"o":0}}],"o":0},{"t":4,"i":3}],"o":0},"f":47,"m":[1,3]}"`; -exports[`mutual cyclic references > toJSONAsync > supports Objects and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":10,"i":1,"p":{"k":["0"],"v":[{"t":12,"i":2,"s":1,"f":{"t":10,"i":3,"p":{"k":["0"],"v":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"s":1},"o":0}}],"s":1},"o":0},{"t":4,"i":3}],"o":0},"f":31,"m":[1,3]}"`; +exports[`mutual cyclic references > toJSONAsync > supports Objects and Objects 1`] = `"{"t":{"t":9,"i":0,"l":2,"a":[{"t":10,"i":1,"p":{"k":["0"],"v":[{"t":12,"i":2,"s":1,"f":{"t":10,"i":3,"p":{"k":["0"],"v":[{"t":12,"i":4,"s":1,"f":{"t":4,"i":1}}],"s":1},"o":0}}],"s":1},"o":0},{"t":4,"i":3}],"o":0},"f":47,"m":[1,3]}"`; diff --git a/packages/seroval/test/__snapshots__/null-constructor.test.ts.snap b/packages/seroval/test/__snapshots__/null-constructor.test.ts.snap index 52da7f1..44c4f1f 100644 --- a/packages/seroval/test/__snapshots__/null-constructor.test.ts.snap +++ b/packages/seroval/test/__snapshots__/null-constructor.test.ts.snap @@ -2,7 +2,7 @@ exports[`null-constructor > compat > should use manual assignment instead of Object.assign 1`] = `"(h=>(h=Object.create(null),h.example="valid identifier",h["%example"]="invalid identifier",h["0x1"]="hexadecimal",h["0b1"]="binary",h["0o1"]="octal",h["1_000"]="numeric separator",h[1.7976931348623157e+308]="exponentiation",h))()"`; -exports[`null-constructor > compat#toJSON > should use manual assignment instead of Object.assign 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":23,"m":[]}"`; +exports[`null-constructor > compat#toJSON > should use manual assignment instead of Object.assign 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":39,"m":[]}"`; exports[`null-constructor > compat#toJSON > should use manual assignment instead of Object.assign 2`] = `"(h=>(h=Object.create(null),h.example="valid identifier",h["%example"]="invalid identifier",h["0x1"]="hexadecimal",h["0b1"]="binary",h["0o1"]="octal",h["1_000"]="numeric separator",h[1.7976931348623157e+308]="exponentiation",h))()"`; @@ -134,16 +134,16 @@ exports[`null-constructor > toCrossJSONStream > supports self-recursion 2`] = `" exports[`null-constructor > toCrossJSONStream > supports self-recursion 3`] = `"{"t":23,"i":3,"a":[{"t":4,"i":4},{"t":4,"i":0}]}"`; -exports[`null-constructor > toJSON > supports Object.create(null) 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":31,"m":[]}"`; +exports[`null-constructor > toJSON > supports Object.create(null) 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":47,"m":[]}"`; -exports[`null-constructor > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":11,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0},"f":31,"m":[1]}"`; +exports[`null-constructor > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":11,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0},"f":47,"m":[1]}"`; -exports[`null-constructor > toJSON > supports self-recursion 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":0},"f":31,"m":[0]}"`; +exports[`null-constructor > toJSON > supports self-recursion 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":0},"f":47,"m":[0]}"`; -exports[`null-constructor > toJSONAsync > supports Object.create(null) 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":11,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0}},"f":31,"m":[]}"`; +exports[`null-constructor > toJSONAsync > supports Object.create(null) 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":11,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0}},"f":47,"m":[]}"`; -exports[`null-constructor > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":11,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":0},"f":31,"m":[1,4]}"`; +exports[`null-constructor > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":11,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":0},"f":47,"m":[1,4]}"`; -exports[`null-constructor > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":11,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0}},"f":31,"m":[2]}"`; +exports[`null-constructor > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":11,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0}},"f":47,"m":[2]}"`; -exports[`null-constructor > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":0},"f":31,"m":[0]}"`; +exports[`null-constructor > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":11,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":0},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/number.test.ts.snap b/packages/seroval/test/__snapshots__/number.test.ts.snap index a574fb2..07f03cb 100644 --- a/packages/seroval/test/__snapshots__/number.test.ts.snap +++ b/packages/seroval/test/__snapshots__/number.test.ts.snap @@ -80,22 +80,22 @@ exports[`number > toCrossJSONStream > supports numbers 1`] = `"{"t":22,"i":0,"f" exports[`number > toCrossJSONStream > supports numbers 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":2,"s":2},{"t":0,"s":3735928559}]}"`; -exports[`number > toJSON > supports numbers 1`] = `"{"t":{"t":0,"s":3735928559},"f":31,"m":[]}"`; +exports[`number > toJSON > supports numbers 1`] = `"{"t":{"t":0,"s":3735928559},"f":47,"m":[]}"`; -exports[`number > toJSON > supports numbers 2`] = `"{"t":{"t":2,"s":7},"f":31,"m":[]}"`; +exports[`number > toJSON > supports numbers 2`] = `"{"t":{"t":2,"s":7},"f":47,"m":[]}"`; -exports[`number > toJSON > supports numbers 3`] = `"{"t":{"t":2,"s":5},"f":31,"m":[]}"`; +exports[`number > toJSON > supports numbers 3`] = `"{"t":{"t":2,"s":5},"f":47,"m":[]}"`; -exports[`number > toJSON > supports numbers 4`] = `"{"t":{"t":2,"s":6},"f":31,"m":[]}"`; +exports[`number > toJSON > supports numbers 4`] = `"{"t":{"t":2,"s":6},"f":47,"m":[]}"`; -exports[`number > toJSON > supports numbers 5`] = `"{"t":{"t":2,"s":4},"f":31,"m":[]}"`; +exports[`number > toJSON > supports numbers 5`] = `"{"t":{"t":2,"s":4},"f":47,"m":[]}"`; -exports[`number > toJSONAsync > supports numbers 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":0,"s":3735928559}},"f":31,"m":[]}"`; +exports[`number > toJSONAsync > supports numbers 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":0,"s":3735928559}},"f":47,"m":[]}"`; -exports[`number > toJSONAsync > supports numbers 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":7}},"f":31,"m":[]}"`; +exports[`number > toJSONAsync > supports numbers 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":7}},"f":47,"m":[]}"`; -exports[`number > toJSONAsync > supports numbers 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":5}},"f":31,"m":[]}"`; +exports[`number > toJSONAsync > supports numbers 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":5}},"f":47,"m":[]}"`; -exports[`number > toJSONAsync > supports numbers 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":6}},"f":31,"m":[]}"`; +exports[`number > toJSONAsync > supports numbers 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":6}},"f":47,"m":[]}"`; -exports[`number > toJSONAsync > supports numbers 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":4}},"f":31,"m":[]}"`; +exports[`number > toJSONAsync > supports numbers 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":4}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/object.test.ts.snap b/packages/seroval/test/__snapshots__/object.test.ts.snap index 6cd74fd..4b43e4a 100644 --- a/packages/seroval/test/__snapshots__/object.test.ts.snap +++ b/packages/seroval/test/__snapshots__/object.test.ts.snap @@ -2,7 +2,7 @@ exports[`objects > compat > should use manual assignment instead of Object.assign 1`] = `"({example:"valid identifier","%example":"invalid identifier","0x1":"hexadecimal","0b1":"binary","0o1":"octal","1_000":"numeric separator",1.7976931348623157e+308:"exponentiation"})"`; -exports[`objects > compat#toJSON > should use manual assignment instead of Object.assign 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":23,"m":[]}"`; +exports[`objects > compat#toJSON > should use manual assignment instead of Object.assign 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":39,"m":[]}"`; exports[`objects > compat#toJSON > should use manual assignment instead of Object.assign 2`] = `"({example:"valid identifier","%example":"invalid identifier","0x1":"hexadecimal","0b1":"binary","0o1":"octal","1_000":"numeric separator",1.7976931348623157e+308:"exponentiation"})"`; @@ -134,16 +134,16 @@ exports[`objects > toCrossJSONStream > supports self-recursion 2`] = `"{"t":23," exports[`objects > toCrossJSONStream > supports self-recursion 3`] = `"{"t":23,"i":3,"a":[{"t":4,"i":4},{"t":4,"i":0}]}"`; -exports[`objects > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":31,"m":[]}"`; +exports[`objects > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0},"f":47,"m":[]}"`; -exports[`objects > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0},"f":31,"m":[1]}"`; +exports[`objects > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0},"f":47,"m":[1]}"`; -exports[`objects > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":0},"f":31,"m":[0]}"`; +exports[`objects > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":0},"f":47,"m":[0]}"`; -exports[`objects > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0}},"f":31,"m":[]}"`; +exports[`objects > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":0}},"f":47,"m":[]}"`; -exports[`objects > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":0},"f":31,"m":[1,4]}"`; +exports[`objects > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":0},"f":47,"m":[1,4]}"`; -exports[`objects > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0}},"f":31,"m":[2]}"`; +exports[`objects > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":0}},"f":47,"m":[2]}"`; -exports[`objects > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":0},"f":31,"m":[0]}"`; +exports[`objects > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":0},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/opaque-reference.test.ts.snap b/packages/seroval/test/__snapshots__/opaque-reference.test.ts.snap index 76cf70e..0759a52 100644 --- a/packages/seroval/test/__snapshots__/opaque-reference.test.ts.snap +++ b/packages/seroval/test/__snapshots__/opaque-reference.test.ts.snap @@ -44,10 +44,10 @@ exports[`OpaqueReference > toCrossJSONStream > supports OpaqueReference 1`] = `" exports[`OpaqueReference > toCrossJSONStream > supports OpaqueReference with replacement 1`] = `"{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":1,"s":"This is a dummy value."}],"s":2},"o":0}"`; -exports[`OpaqueReference > toJSON > supports OpaqueReference 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":2,"s":1}],"s":2},"o":0},"f":31,"m":[]}"`; +exports[`OpaqueReference > toJSON > supports OpaqueReference 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":2,"s":1}],"s":2},"o":0},"f":47,"m":[]}"`; -exports[`OpaqueReference > toJSON > supports OpaqueReference with replacement 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":1,"s":"This is a dummy value."}],"s":2},"o":0},"f":31,"m":[]}"`; +exports[`OpaqueReference > toJSON > supports OpaqueReference with replacement 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":1,"s":"This is a dummy value."}],"s":2},"o":0},"f":47,"m":[]}"`; -exports[`OpaqueReference > toJSONAsync > supports OpaqueReference 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":2,"s":1}],"s":2},"o":0},"f":31,"m":[]}"`; +exports[`OpaqueReference > toJSONAsync > supports OpaqueReference 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":2,"s":1}],"s":2},"o":0},"f":47,"m":[]}"`; -exports[`OpaqueReference > toJSONAsync > supports OpaqueReference with replacement 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":1,"s":"This is a dummy value."}],"s":2},"o":0},"f":31,"m":[]}"`; +exports[`OpaqueReference > toJSONAsync > supports OpaqueReference with replacement 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["transparent","opaque"],"v":[{"t":1,"s":"This is transparent"},{"t":1,"s":"This is a dummy value."}],"s":2},"o":0},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/plugin.test.ts.snap b/packages/seroval/test/__snapshots__/plugin.test.ts.snap index b76561c..a3aff2f 100644 --- a/packages/seroval/test/__snapshots__/plugin.test.ts.snap +++ b/packages/seroval/test/__snapshots__/plugin.test.ts.snap @@ -22,6 +22,6 @@ exports[`Plugin > toCrossJSONAsync > supports Plugin 1`] = `"{"t":12,"i":0,"s":1 exports[`Plugin > toCrossJSONStream > supports Plugin 1`] = `"{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}"`; -exports[`Plugin > toJSON > supports Plugin 1`] = `"{"t":{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"},"f":31,"m":[]}"`; +exports[`Plugin > toJSON > supports Plugin 1`] = `"{"t":{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"},"f":47,"m":[]}"`; -exports[`Plugin > toJSONAsync > supports Plugin 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":25,"i":1,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}},"f":31,"m":[]}"`; +exports[`Plugin > toJSONAsync > supports Plugin 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":25,"i":1,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/reference.test.ts.snap b/packages/seroval/test/__snapshots__/reference.test.ts.snap index 62e8233..e3a53bc 100644 --- a/packages/seroval/test/__snapshots__/reference.test.ts.snap +++ b/packages/seroval/test/__snapshots__/reference.test.ts.snap @@ -28,6 +28,6 @@ exports[`Reference > toCrossJSONStream > supports Reference 1`] = `"{"t":22,"i": exports[`Reference > toCrossJSONStream > supports Reference 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":18,"i":2,"s":"example"}]}"`; -exports[`Reference > toJSON > supports Reference 1`] = `"{"t":{"t":18,"i":0,"s":"example"},"f":31,"m":[]}"`; +exports[`Reference > toJSON > supports Reference 1`] = `"{"t":{"t":18,"i":0,"s":"example"},"f":47,"m":[]}"`; -exports[`Reference > toJSONAsync > supports Reference 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":18,"i":1,"s":"example"}},"f":31,"m":[]}"`; +exports[`Reference > toJSONAsync > supports Reference 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":18,"i":1,"s":"example"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/regexp.test.ts.snap b/packages/seroval/test/__snapshots__/regexp.test.ts.snap index 3f83cb3..03ed58f 100644 --- a/packages/seroval/test/__snapshots__/regexp.test.ts.snap +++ b/packages/seroval/test/__snapshots__/regexp.test.ts.snap @@ -28,6 +28,6 @@ exports[`RegExp > toCrossJSONStream > supports RegExp 1`] = `"{"t":22,"i":0,"f": exports[`RegExp > toCrossJSONStream > supports RegExp 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":6,"i":2,"c":"[a-z0-9]+","m":"i"}]}"`; -exports[`RegExp > toJSON > supports RegExp 1`] = `"{"t":{"t":6,"i":0,"c":"[a-z0-9]+","m":"i"},"f":31,"m":[]}"`; +exports[`RegExp > toJSON > supports RegExp 1`] = `"{"t":{"t":6,"i":0,"c":"[a-z0-9]+","m":"i"},"f":47,"m":[]}"`; -exports[`RegExp > toJSONAsync > supports RegExp 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":6,"i":1,"c":"[a-z0-9]+","m":"i"}},"f":31,"m":[]}"`; +exports[`RegExp > toJSONAsync > supports RegExp 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":6,"i":1,"c":"[a-z0-9]+","m":"i"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/sealed-object.test.ts.snap b/packages/seroval/test/__snapshots__/sealed-object.test.ts.snap index bf48ec1..4e86bae 100644 --- a/packages/seroval/test/__snapshots__/sealed-object.test.ts.snap +++ b/packages/seroval/test/__snapshots__/sealed-object.test.ts.snap @@ -128,16 +128,16 @@ exports[`sealed object > toCrossJSONStream > supports self-recursion 2`] = `"{"t exports[`sealed object > toCrossJSONStream > supports self-recursion 3`] = `"{"t":23,"i":3,"a":[{"t":4,"i":4},{"t":4,"i":0}]}"`; -exports[`sealed object > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":2},"f":31,"m":[]}"`; +exports[`sealed object > toJSON > supports Objects 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":2},"f":47,"m":[]}"`; -exports[`sealed object > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":2},"f":31,"m":[1]}"`; +exports[`sealed object > toJSON > supports Symbol.iterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":2,"f":{"t":4,"i":1}},{"t":10,"i":3,"p":{"k":["v","t","d"],"v":[{"t":9,"i":4,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":2},"f":47,"m":[1]}"`; -exports[`sealed object > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":2},"f":31,"m":[0]}"`; +exports[`sealed object > toJSON > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":4,"i":0},{"t":4,"i":0}],"s":2},"o":2},"f":47,"m":[0]}"`; -exports[`sealed object > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":2}},"f":31,"m":[]}"`; +exports[`sealed object > toJSONAsync > supports Objects 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":["example","%example","0x1","0b1","0o1","1_000","1.7976931348623157e+308"],"v":[{"t":1,"s":"valid identifier"},{"t":1,"s":"invalid identifier"},{"t":1,"s":"hexadecimal"},{"t":1,"s":"binary"},{"t":1,"s":"octal"},{"t":1,"s":"numeric separator"},{"t":1,"s":"exponentiation"}],"s":7},"o":2}},"f":47,"m":[]}"`; -exports[`sealed object > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":2},"f":31,"m":[1,4]}"`; +exports[`sealed object > toJSONAsync > supports Symbol.asyncIterator 1`] = `"{"t":{"t":10,"i":0,"p":{"k":[{"t":17,"i":1,"s":0}],"v":[{"t":30,"a":[{"t":29,"i":2,"a":[{"t":26,"i":3,"s":1},{"t":4,"i":1}]},{"t":31,"i":4,"a":[{"t":32,"i":4,"f":{"t":0,"s":1}},{"t":32,"i":4,"f":{"t":0,"s":2}},{"t":32,"i":4,"f":{"t":0,"s":3}},{"t":34,"i":4,"f":{"t":2,"s":1}}],"f":{"t":26,"i":5,"s":4}}]}],"s":1},"o":2},"f":47,"m":[1,4]}"`; -exports[`sealed object > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":2}},"f":31,"m":[2]}"`; +exports[`sealed object > toJSONAsync > supports Symbol.iterator 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":10,"i":1,"p":{"k":[{"t":17,"i":2,"s":3}],"v":[{"t":28,"a":[{"t":27,"i":3,"f":{"t":4,"i":2}},{"t":10,"i":4,"p":{"k":["v","t","d"],"v":[{"t":9,"i":5,"l":4,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3},{"t":2,"s":1}],"o":0},{"t":0,"s":-1},{"t":0,"s":3}],"s":3},"o":0}]}],"s":1},"o":2}},"f":47,"m":[2]}"`; -exports[`sealed object > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":2},"f":31,"m":[0]}"`; +exports[`sealed object > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":10,"i":0,"p":{"k":["a","b"],"v":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}},{"t":12,"i":2,"s":1,"f":{"t":4,"i":0}}],"s":2},"o":2},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/set.test.ts.snap b/packages/seroval/test/__snapshots__/set.test.ts.snap index 30fb4bb..257b0c1 100644 --- a/packages/seroval/test/__snapshots__/set.test.ts.snap +++ b/packages/seroval/test/__snapshots__/set.test.ts.snap @@ -48,10 +48,10 @@ exports[`Set > toCrossJSONAsync > supports Set 1`] = `"{"t":12,"i":0,"s":1,"f":{ exports[`Set > toCrossJSONAsync > supports self-recursion 1`] = `"{"t":7,"i":0,"l":1,"a":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}]}"`; -exports[`Set > toJSON > supports Set 1`] = `"{"t":{"t":7,"i":0,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}]},"f":31,"m":[]}"`; +exports[`Set > toJSON > supports Set 1`] = `"{"t":{"t":7,"i":0,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}]},"f":47,"m":[]}"`; -exports[`Set > toJSON > supports self-recursion 1`] = `"{"t":{"t":7,"i":0,"l":1,"a":[{"t":4,"i":0}]},"f":31,"m":[0]}"`; +exports[`Set > toJSON > supports self-recursion 1`] = `"{"t":{"t":7,"i":0,"l":1,"a":[{"t":4,"i":0}]},"f":47,"m":[0]}"`; -exports[`Set > toJSONAsync > supports Set 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":7,"i":1,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}]}},"f":31,"m":[]}"`; +exports[`Set > toJSONAsync > supports Set 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":7,"i":1,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}]}},"f":47,"m":[]}"`; -exports[`Set > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":7,"i":0,"l":1,"a":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}]},"f":31,"m":[0]}"`; +exports[`Set > toJSONAsync > supports self-recursion 1`] = `"{"t":{"t":7,"i":0,"l":1,"a":[{"t":12,"i":1,"s":1,"f":{"t":4,"i":0}}]},"f":47,"m":[0]}"`; diff --git a/packages/seroval/test/__snapshots__/sparse-array.test.ts.snap b/packages/seroval/test/__snapshots__/sparse-array.test.ts.snap index 9b52f65..aa7ce3c 100644 --- a/packages/seroval/test/__snapshots__/sparse-array.test.ts.snap +++ b/packages/seroval/test/__snapshots__/sparse-array.test.ts.snap @@ -28,6 +28,6 @@ exports[`sparse arrays > toCrossJSONStream > supports sparse arrays 1`] = `"{"t" exports[`sparse arrays > toCrossJSONStream > supports sparse arrays 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":9,"i":2,"l":10,"a":[],"o":0}]}"`; -exports[`sparse arrays > toJSON > supports sparse arrays 1`] = `"{"t":{"t":9,"i":0,"l":10,"a":[],"o":0},"f":31,"m":[]}"`; +exports[`sparse arrays > toJSON > supports sparse arrays 1`] = `"{"t":{"t":9,"i":0,"l":10,"a":[],"o":0},"f":47,"m":[]}"`; -exports[`sparse arrays > toJSONAsync > supports sparse arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":9,"i":1,"l":10,"a":[],"o":0}},"f":31,"m":[]}"`; +exports[`sparse arrays > toJSONAsync > supports sparse arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":9,"i":1,"l":10,"a":[],"o":0}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/string.test.ts.snap b/packages/seroval/test/__snapshots__/string.test.ts.snap index 0ea9493..fa1b827 100644 --- a/packages/seroval/test/__snapshots__/string.test.ts.snap +++ b/packages/seroval/test/__snapshots__/string.test.ts.snap @@ -40,10 +40,10 @@ exports[`string > toCrossJSONStream > supports strings 1`] = `"{"t":22,"i":0,"f" exports[`string > toCrossJSONStream > supports strings 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":2,"s":2},{"t":1,"s":"\\\\\\"hello\\\\\\""}]}"`; -exports[`string > toJSON > supports strings 1`] = `"{"t":{"t":1,"s":"\\\\\\"hello\\\\\\""},"f":31,"m":[]}"`; +exports[`string > toJSON > supports strings 1`] = `"{"t":{"t":1,"s":"\\\\\\"hello\\\\\\""},"f":47,"m":[]}"`; -exports[`string > toJSON > supports strings 2`] = `"{"t":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"},"f":31,"m":[]}"`; +exports[`string > toJSON > supports strings 2`] = `"{"t":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"},"f":47,"m":[]}"`; -exports[`string > toJSONAsync > supports strings 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}},"f":31,"m":[]}"`; +exports[`string > toJSONAsync > supports strings 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}},"f":47,"m":[]}"`; -exports[`string > toJSONAsync > supports strings 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}},"f":31,"m":[]}"`; +exports[`string > toJSONAsync > supports strings 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/typed-array.test.ts.snap b/packages/seroval/test/__snapshots__/typed-array.test.ts.snap index 3cac186..36e9d7d 100644 --- a/packages/seroval/test/__snapshots__/typed-array.test.ts.snap +++ b/packages/seroval/test/__snapshots__/typed-array.test.ts.snap @@ -28,6 +28,6 @@ exports[`typed arrays > toCrossJSONStream > supports typed arrays 1`] = `"{"t":2 exports[`typed arrays > toCrossJSONStream > supports typed arrays 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":4,"s":2},{"t":15,"i":2,"l":4,"c":"Uint32Array","f":{"t":19,"i":3,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0}]}"`; -exports[`typed arrays > toJSON > supports typed arrays 1`] = `"{"t":{"t":15,"i":0,"l":4,"c":"Uint32Array","f":{"t":19,"i":1,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0},"f":31,"m":[]}"`; +exports[`typed arrays > toJSON > supports typed arrays 1`] = `"{"t":{"t":15,"i":0,"l":4,"c":"Uint32Array","f":{"t":19,"i":1,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0},"f":47,"m":[]}"`; -exports[`typed arrays > toJSONAsync > supports typed arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":15,"i":1,"l":4,"c":"Uint32Array","f":{"t":19,"i":2,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0}},"f":31,"m":[]}"`; +exports[`typed arrays > toJSONAsync > supports typed arrays 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":15,"i":1,"l":4,"c":"Uint32Array","f":{"t":19,"i":2,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/__snapshots__/wk-symbols.test.ts.snap b/packages/seroval/test/__snapshots__/wk-symbols.test.ts.snap index f8a1b37..6d3b14e 100644 --- a/packages/seroval/test/__snapshots__/wk-symbols.test.ts.snap +++ b/packages/seroval/test/__snapshots__/wk-symbols.test.ts.snap @@ -364,54 +364,54 @@ exports[`well-known symbols > toCrossJSONStream > supports Symbol.unscopables 1` exports[`well-known symbols > toCrossJSONStream > supports Symbol.unscopables 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":17,"i":2,"s":12}]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 1`] = `"{"t":{"t":17,"i":0,"s":0},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 1`] = `"{"t":{"t":17,"i":0,"s":0},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 2`] = `"{"t":{"t":17,"i":0,"s":1},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 2`] = `"{"t":{"t":17,"i":0,"s":1},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 3`] = `"{"t":{"t":17,"i":0,"s":2},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 3`] = `"{"t":{"t":17,"i":0,"s":2},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 4`] = `"{"t":{"t":17,"i":0,"s":3},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 4`] = `"{"t":{"t":17,"i":0,"s":3},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 5`] = `"{"t":{"t":17,"i":0,"s":4},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 5`] = `"{"t":{"t":17,"i":0,"s":4},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 6`] = `"{"t":{"t":17,"i":0,"s":5},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 6`] = `"{"t":{"t":17,"i":0,"s":5},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 7`] = `"{"t":{"t":17,"i":0,"s":6},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 7`] = `"{"t":{"t":17,"i":0,"s":6},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 8`] = `"{"t":{"t":17,"i":0,"s":7},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 8`] = `"{"t":{"t":17,"i":0,"s":7},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 9`] = `"{"t":{"t":17,"i":0,"s":8},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 9`] = `"{"t":{"t":17,"i":0,"s":8},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 10`] = `"{"t":{"t":17,"i":0,"s":9},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 10`] = `"{"t":{"t":17,"i":0,"s":9},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 11`] = `"{"t":{"t":17,"i":0,"s":10},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 11`] = `"{"t":{"t":17,"i":0,"s":10},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 12`] = `"{"t":{"t":17,"i":0,"s":11},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 12`] = `"{"t":{"t":17,"i":0,"s":11},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSON > supports well-known symbols 13`] = `"{"t":{"t":17,"i":0,"s":12},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSON > supports well-known symbols 13`] = `"{"t":{"t":17,"i":0,"s":12},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":0}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":0}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":1}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":1}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":2}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 3`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":2}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":3}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 4`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":3}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":4}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 5`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":4}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 6`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":5}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 6`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":5}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 7`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":6}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 7`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":6}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 8`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":7}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 8`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":7}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 9`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":8}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 9`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":8}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 10`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":9}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 10`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":9}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 11`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":10}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 11`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":10}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 12`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":11}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 12`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":11}},"f":47,"m":[]}"`; -exports[`well-known symbols > toJSONAsync > supports well-known symbols 13`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":12}},"f":31,"m":[]}"`; +exports[`well-known symbols > toJSONAsync > supports well-known symbols 13`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":17,"i":1,"s":12}},"f":47,"m":[]}"`; diff --git a/packages/seroval/test/abort-signal.test.ts b/packages/seroval/test/abort-signal.test.ts new file mode 100644 index 0000000..9b8860c --- /dev/null +++ b/packages/seroval/test/abort-signal.test.ts @@ -0,0 +1,272 @@ +import { describe, expect, it } from 'vitest'; +import { + crossSerialize, + crossSerializeAsync, + crossSerializeStream, + deserialize, + fromCrossJSON, + fromJSON, + serialize, + serializeAsync, + toCrossJSON, + toCrossJSONAsync, + toCrossJSONStream, + toJSON, + toJSONAsync, +} from '../src'; + +const SYNC_EXAMPLE = AbortSignal.abort('aborted!'); + +describe('AbortSignal', () => { + describe('serialize', () => { + it('supports aborted AbortSignal', () => { + const result = serialize(SYNC_EXAMPLE); + expect(result).toMatchSnapshot(); + const back = deserialize(result); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', () => { + const instance = AbortSignal.timeout(100); + const result = serialize(instance); + expect(result).toMatchSnapshot(); + const back = deserialize(result); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + describe('serializeAsync', () => { + it('supports aborted AbortSignal', async () => { + const result = await serializeAsync(Promise.resolve(SYNC_EXAMPLE)); + expect(result).toMatchSnapshot(); + const back = await deserialize>(result); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', async () => { + const instance = AbortSignal.timeout(100); + const result = await serializeAsync(instance); + expect(result).toMatchSnapshot(); + const back = await deserialize>(result); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + describe('toJSON', () => { + it('supports aborted AbortSignal', () => { + const result = toJSON(SYNC_EXAMPLE); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromJSON(result); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', () => { + const instance = AbortSignal.timeout(100); + const result = toJSON(instance); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromJSON(result); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + describe('toJSONAsync', () => { + it('supports aborted AbortSignal', async () => { + const result = await toJSONAsync(Promise.resolve(SYNC_EXAMPLE)); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = await fromJSON>(result); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', async () => { + const instance = AbortSignal.timeout(100); + const result = await toJSONAsync(instance); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromJSON(result); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + + describe('crossSerialize', () => { + it('supports aborted AbortSignal', () => { + const result = crossSerialize(SYNC_EXAMPLE); + expect(result).toMatchSnapshot(); + }); + it('supports future AbortSignal', () => { + const instance = AbortSignal.timeout(100); + const result = crossSerialize(instance); + expect(result).toMatchSnapshot(); + }); + describe('scoped', () => { + it('supports aborted AbortSignal', () => { + const result = crossSerialize(SYNC_EXAMPLE, { scopeId: 'example' }); + expect(result).toMatchSnapshot(); + }); + it('supports future AbortSignal', () => { + const instance = AbortSignal.timeout(100); + const result = crossSerialize(instance, { scopeId: 'example' }); + expect(result).toMatchSnapshot(); + }); + }); + }); + describe('crossSerializeAsync', () => { + it('supports aborted AbortSignal', async () => { + const result = await crossSerializeAsync(Promise.resolve(SYNC_EXAMPLE)); + expect(result).toMatchSnapshot(); + }); + it('supports future AbortSignal', async () => { + const instance = AbortSignal.timeout(100); + const result = await crossSerializeAsync(instance); + expect(result).toMatchSnapshot(); + }); + describe('scoped', () => { + it('supports aborted AbortSignal', async () => { + const result = await crossSerializeAsync( + Promise.resolve(SYNC_EXAMPLE), + { + scopeId: 'example', + }, + ); + expect(result).toMatchSnapshot(); + }); + it('supports future AbortSignal', async () => { + const instance = AbortSignal.timeout(100); + const result = await crossSerializeAsync(instance, { + scopeId: 'example', + }); + expect(result).toMatchSnapshot(); + }); + }); + }); + describe('crossSerializeStream', () => { + it('supports aborted AbortSignal', async () => + new Promise((resolve, reject) => { + crossSerializeStream(Promise.resolve(SYNC_EXAMPLE), { + onSerialize(data) { + expect(data).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + it('supports future AbortSignal', async () => + new Promise((resolve, reject) => { + const instance = AbortSignal.timeout(100); + crossSerializeStream(instance, { + onSerialize(data) { + expect(data).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + describe('scoped', () => { + it('supports aborted AbortSignal', async () => + new Promise((resolve, reject) => { + crossSerializeStream(Promise.resolve(SYNC_EXAMPLE), { + scopeId: 'example', + onSerialize(data) { + expect(data).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + it('supports future AbortSignal', async () => + new Promise((resolve, reject) => { + const instance = AbortSignal.timeout(100); + crossSerializeStream(instance, { + scopeId: 'example', + onSerialize(data) { + expect(data).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + }); + }); + describe('toCrossJSON', () => { + it('supports aborted AbortSignal', () => { + const result = toCrossJSON(SYNC_EXAMPLE); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromCrossJSON(result, { + refs: new Map(), + }); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', () => { + const instance = AbortSignal.timeout(100); + const result = toCrossJSON(instance); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromCrossJSON(result, { + refs: new Map(), + }); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + describe('toCrossJSONAsync', () => { + it('supports aborted AbortSignal', async () => { + const result = await toCrossJSONAsync(Promise.resolve(SYNC_EXAMPLE)); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = await fromCrossJSON>(result, { + refs: new Map(), + }); + expect(back).toBeInstanceOf(AbortSignal); + expect(back.reason).toBe(SYNC_EXAMPLE.reason); + }); + it('supports future AbortSignal', async () => { + const instance = AbortSignal.timeout(100); + const result = await toCrossJSONAsync(instance); + expect(JSON.stringify(result)).toMatchSnapshot(); + const back = fromCrossJSON(result, { + refs: new Map(), + }); + expect(back).toBeInstanceOf(AbortSignal); + }); + }); + describe('toCrossJSONStream', () => { + it('supports aborted AbortSignal', async () => + new Promise((resolve, reject) => { + toCrossJSONStream(Promise.resolve(SYNC_EXAMPLE), { + onParse(data) { + expect(JSON.stringify(data)).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + it('supports future AbortSignal', async () => + new Promise((resolve, reject) => { + const instance = AbortSignal.timeout(100); + toCrossJSONStream(instance, { + onParse(data) { + expect(JSON.stringify(data)).toMatchSnapshot(); + }, + onDone() { + resolve(); + }, + onError(error) { + reject(error); + }, + }); + })); + }); +});