= {
19 | [SpecialReference.MapSentinel]: {},
20 | [SpecialReference.PromiseConstructor]: {},
21 | [SpecialReference.PromiseSuccess]: {},
22 | [SpecialReference.PromiseFailure]: {},
23 | [SpecialReference.StreamConstructor]: {},
24 | };
25 |
26 | function serializePromiseConstructor(features: number): string {
27 | return createFunction(
28 | features,
29 | ['r'],
30 | '(r.p=new Promise(' +
31 | createEffectfulFunction(features, ['s', 'f'], 'r.s=s,r.f=f') +
32 | '))',
33 | );
34 | }
35 |
36 | function serializePromiseSuccess(features: number): string {
37 | return createEffectfulFunction(
38 | features,
39 | ['r', 'd'],
40 | 'r.s(d),r.p.s=1,r.p.v=d',
41 | );
42 | }
43 |
44 | function serializePromiseFailure(features: number): string {
45 | return createEffectfulFunction(
46 | features,
47 | ['r', 'd'],
48 | 'r.f(d),r.p.s=2,r.p.v=d',
49 | );
50 | }
51 |
52 | function serializeStreamConstructor(features: number): string {
53 | return createFunction(
54 | features,
55 | ['b', 'a', 's', 'l', 'p', 'f', 'e', 'n'],
56 | '(b=[],a=!0,s=!1,l=[],p=0,f=' +
57 | createEffectfulFunction(
58 | features,
59 | ['v', 'm', 'x'],
60 | 'for(x=0;x" and "\" to avoid invalid escapes in the output.
32 | // http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
33 | export function serializeString(str: string): string {
34 | let result = '';
35 | let lastPos = 0;
36 | let replacement: string | undefined;
37 | for (let i = 0, len = str.length; i < len; i++) {
38 | replacement = serializeChar(str[i]);
39 | if (replacement) {
40 | result += str.slice(lastPos, i) + replacement;
41 | lastPos = i + 1;
42 | }
43 | }
44 | if (lastPos === 0) {
45 | result = str;
46 | } else {
47 | result += str.slice(lastPos);
48 | }
49 | return result;
50 | }
51 |
52 | function deserializeReplacer(str: string): string {
53 | switch (str) {
54 | case '\\\\':
55 | return '\\';
56 | case '\\"':
57 | return '"';
58 | case '\\n':
59 | return '\n';
60 | case '\\r':
61 | return '\r';
62 | case '\\b':
63 | return '\b';
64 | case '\\t':
65 | return '\t';
66 | case '\\f':
67 | return '\f';
68 | case '\\x3C':
69 | return '\x3C';
70 | case '\\u2028':
71 | return '\u2028';
72 | case '\\u2029':
73 | return '\u2029';
74 | default:
75 | return str;
76 | }
77 | }
78 |
79 | export function deserializeString(str: string): string {
80 | return str.replace(
81 | /(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g,
82 | deserializeReplacer,
83 | );
84 | }
85 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/tree/async.ts:
--------------------------------------------------------------------------------
1 | import type { BaseParserContextOptions } from '../context/parser';
2 | import BaseAsyncParserContext from '../context/parser/async';
3 | import type { SerovalMode } from '../plugin';
4 |
5 | export type AsyncParserContextOptions = Omit;
6 |
7 | export default class AsyncParserContext extends BaseAsyncParserContext {
8 | readonly mode: SerovalMode = 'vanilla';
9 | }
10 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/tree/deserializer.ts:
--------------------------------------------------------------------------------
1 | import type { BaseDeserializerOptions } from '../context/deserializer';
2 | import BaseDeserializerContext from '../context/deserializer';
3 | import type { SerovalMode } from '../plugin';
4 |
5 | export interface VanillaDeserializerContextOptions
6 | extends Omit {
7 | markedRefs: number[] | Set;
8 | }
9 |
10 | export default class VanillaDeserializerContext extends BaseDeserializerContext {
11 | readonly mode: SerovalMode = 'vanilla';
12 |
13 | marked: Set;
14 |
15 | constructor(options: VanillaDeserializerContextOptions) {
16 | super(options);
17 | this.marked = new Set(options.markedRefs);
18 | }
19 |
20 | assignIndexedValue(index: number, value: T): T {
21 | if (this.marked.has(index)) {
22 | this.refs.set(index, value);
23 | }
24 | return value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/tree/index.ts:
--------------------------------------------------------------------------------
1 | import { type PluginAccessOptions, resolvePlugins } from '../plugin';
2 | import type { SerovalNode } from '../types';
3 | import type { AsyncParserContextOptions } from './async';
4 | import AsyncParserContext from './async';
5 | import VanillaDeserializerContext from './deserializer';
6 | import VanillaSerializerContext from './serializer';
7 | import type { SyncParserContextOptions } from './sync';
8 | import SyncParserContext from './sync';
9 |
10 | export function serialize(
11 | source: T,
12 | options: SyncParserContextOptions = {},
13 | ): string {
14 | const plugins = resolvePlugins(options.plugins);
15 | const ctx = new SyncParserContext({
16 | plugins,
17 | disabledFeatures: options.disabledFeatures,
18 | });
19 | const tree = ctx.parseTop(source);
20 | const serial = new VanillaSerializerContext({
21 | plugins,
22 | features: ctx.features,
23 | markedRefs: ctx.marked,
24 | });
25 | return serial.serializeTop(tree);
26 | }
27 |
28 | export async function serializeAsync(
29 | source: T,
30 | options: AsyncParserContextOptions = {},
31 | ): Promise {
32 | const plugins = resolvePlugins(options.plugins);
33 | const ctx = new AsyncParserContext({
34 | plugins,
35 | disabledFeatures: options.disabledFeatures,
36 | });
37 | const tree = await ctx.parseTop(source);
38 | const serial = new VanillaSerializerContext({
39 | plugins,
40 | features: ctx.features,
41 | markedRefs: ctx.marked,
42 | });
43 | return serial.serializeTop(tree);
44 | }
45 |
46 | export function deserialize(source: string): T {
47 | return (0, eval)(source) as T;
48 | }
49 |
50 | export interface SerovalJSON {
51 | t: SerovalNode;
52 | f: number;
53 | m: number[];
54 | }
55 |
56 | export function toJSON(
57 | source: T,
58 | options: SyncParserContextOptions = {},
59 | ): SerovalJSON {
60 | const plugins = resolvePlugins(options.plugins);
61 | const ctx = new SyncParserContext({
62 | plugins,
63 | disabledFeatures: options.disabledFeatures,
64 | });
65 | return {
66 | t: ctx.parseTop(source),
67 | f: ctx.features,
68 | m: Array.from(ctx.marked),
69 | };
70 | }
71 |
72 | export async function toJSONAsync(
73 | source: T,
74 | options: AsyncParserContextOptions = {},
75 | ): Promise {
76 | const plugins = resolvePlugins(options.plugins);
77 | const ctx = new AsyncParserContext({
78 | plugins,
79 | disabledFeatures: options.disabledFeatures,
80 | });
81 | return {
82 | t: await ctx.parseTop(source),
83 | f: ctx.features,
84 | m: Array.from(ctx.marked),
85 | };
86 | }
87 |
88 | export function compileJSON(
89 | source: SerovalJSON,
90 | options: PluginAccessOptions = {},
91 | ): string {
92 | const plugins = resolvePlugins(options.plugins);
93 | const ctx = new VanillaSerializerContext({
94 | plugins,
95 | features: source.f,
96 | markedRefs: source.m,
97 | });
98 | return ctx.serializeTop(source.t);
99 | }
100 |
101 | export function fromJSON(
102 | source: SerovalJSON,
103 | options: PluginAccessOptions = {},
104 | ): T {
105 | const plugins = resolvePlugins(options.plugins);
106 | const ctx = new VanillaDeserializerContext({
107 | plugins,
108 | markedRefs: source.m,
109 | });
110 | return ctx.deserializeTop(source.t) as T;
111 | }
112 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/tree/serializer.ts:
--------------------------------------------------------------------------------
1 | import { SerovalNodeType } from '../constants';
2 | import type { BaseSerializerContextOptions } from '../context/serializer';
3 | import BaseSerializerContext from '../context/serializer';
4 | import { SerovalUnsupportedNodeError } from '../errors';
5 | import type { SerovalMode } from '../plugin';
6 | import type {
7 | SerovalNode,
8 | SerovalPromiseConstructorNode,
9 | SerovalPromiseRejectNode,
10 | SerovalPromiseResolveNode,
11 | } from '../types';
12 | import getIdentifier from '../utils/get-identifier';
13 |
14 | export type VanillaSerializerContextOptions = BaseSerializerContextOptions;
15 |
16 | export default class VanillaSerializerContext extends BaseSerializerContext {
17 | readonly mode: SerovalMode = 'vanilla';
18 |
19 | /**
20 | * Map tree refs to actual refs
21 | * @private
22 | */
23 | valid = new Map();
24 |
25 | /**
26 | * Variables
27 | * @private
28 | */
29 | vars: string[] = [];
30 |
31 | /**
32 | * Creates the reference param (identifier) from the given reference ID
33 | * Calling this function means the value has been referenced somewhere
34 | */
35 | getRefParam(index: number): string {
36 | /**
37 | * Creates a new reference ID from a given reference ID
38 | * This new reference ID means that the reference itself
39 | * has been referenced at least once, and is used to generate
40 | * the variables
41 | */
42 | let actualIndex = this.valid.get(index);
43 | if (actualIndex == null) {
44 | actualIndex = this.valid.size;
45 | this.valid.set(index, actualIndex);
46 | }
47 | let identifier = this.vars[actualIndex];
48 | if (identifier == null) {
49 | identifier = getIdentifier(actualIndex);
50 | this.vars[actualIndex] = identifier;
51 | }
52 | return identifier;
53 | }
54 |
55 | protected assignIndexedValue(index: number, value: string): string {
56 | if (this.isMarked(index)) {
57 | return this.getRefParam(index) + '=' + value;
58 | }
59 | return value;
60 | }
61 |
62 | protected serializePromiseConstructor(
63 | node: SerovalPromiseConstructorNode,
64 | ): string {
65 | throw new SerovalUnsupportedNodeError(node);
66 | }
67 |
68 | protected serializePromiseResolve(node: SerovalPromiseResolveNode): string {
69 | throw new SerovalUnsupportedNodeError(node);
70 | }
71 |
72 | protected serializePromiseReject(node: SerovalPromiseRejectNode): string {
73 | throw new SerovalUnsupportedNodeError(node);
74 | }
75 |
76 | serializeTop(tree: SerovalNode): string {
77 | const result = this.serialize(tree);
78 | // Shared references detected
79 | if (tree.i != null && this.vars.length) {
80 | const patches = this.resolvePatches();
81 | let body = result;
82 | if (patches) {
83 | // Get (or create) a ref from the source
84 | const index = this.getRefParam(tree.i);
85 | body = result + ',' + patches + index;
86 | if (!result.startsWith(index + '=')) {
87 | body = index + '=' + body;
88 | }
89 | body = '(' + body + ')';
90 | }
91 | return '(' + this.createFunction(this.vars, body) + ')()';
92 | }
93 | if (tree.t === SerovalNodeType.Object) {
94 | return '(' + result + ')';
95 | }
96 | return result;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/tree/sync.ts:
--------------------------------------------------------------------------------
1 | import BaseSyncParserContext from '../context/parser/sync';
2 | import type { BaseParserContextOptions } from '../context/parser';
3 | import type { SerovalMode } from '../plugin';
4 |
5 | export type SyncParserContextOptions = Omit;
6 |
7 | export default class SyncParserContext extends BaseSyncParserContext {
8 | readonly mode: SerovalMode = 'vanilla';
9 | }
10 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/assert.ts:
--------------------------------------------------------------------------------
1 | export default function assert(cond: unknown, error: Error): asserts cond {
2 | if (!cond) {
3 | throw error;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/deferred.ts:
--------------------------------------------------------------------------------
1 | export interface Deferred {
2 | promise: Promise;
3 | resolve(value: unknown): void;
4 | reject(value: unknown): void;
5 | }
6 |
7 | export function createDeferred(): Deferred {
8 | let resolve: Deferred['resolve'];
9 | let reject: Deferred['reject'];
10 | return {
11 | promise: new Promise((res, rej) => {
12 | resolve = res;
13 | reject = rej;
14 | }),
15 | resolve(value): void {
16 | resolve(value);
17 | },
18 | reject(value): void {
19 | reject(value);
20 | },
21 | };
22 | }
23 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/error.ts:
--------------------------------------------------------------------------------
1 | import { Feature } from '../compat';
2 | import { ERROR_CONSTRUCTOR_STRING, ErrorConstructorTag } from '../constants';
3 |
4 | type ErrorValue =
5 | | Error
6 | | AggregateError
7 | | EvalError
8 | | RangeError
9 | | ReferenceError
10 | | TypeError
11 | | SyntaxError
12 | | URIError;
13 |
14 | export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
15 | if (error instanceof EvalError) {
16 | return ErrorConstructorTag.EvalError;
17 | }
18 | if (error instanceof RangeError) {
19 | return ErrorConstructorTag.RangeError;
20 | }
21 | if (error instanceof ReferenceError) {
22 | return ErrorConstructorTag.ReferenceError;
23 | }
24 | if (error instanceof SyntaxError) {
25 | return ErrorConstructorTag.SyntaxError;
26 | }
27 | if (error instanceof TypeError) {
28 | return ErrorConstructorTag.TypeError;
29 | }
30 | if (error instanceof URIError) {
31 | return ErrorConstructorTag.URIError;
32 | }
33 | return ErrorConstructorTag.Error;
34 | }
35 |
36 | function getInitialErrorOptions(
37 | error: Error,
38 | ): Record | undefined {
39 | const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
40 | // Name has been modified
41 | if (error.name !== construct) {
42 | return { name: error.name };
43 | }
44 | if (error.constructor.name !== construct) {
45 | // Otherwise, name is overriden because
46 | // the Error class is extended
47 | return { name: error.constructor.name };
48 | }
49 | return {};
50 | }
51 |
52 | export function getErrorOptions(
53 | error: Error,
54 | features: number,
55 | ): Record | undefined {
56 | let options = getInitialErrorOptions(error);
57 | const names = Object.getOwnPropertyNames(error);
58 | for (let i = 0, len = names.length, name: string; i < len; i++) {
59 | name = names[i];
60 | if (name !== 'name' && name !== 'message') {
61 | if (name === 'stack') {
62 | if (features & Feature.ErrorPrototypeStack) {
63 | options = options || {};
64 | options[name] = error[name as keyof Error];
65 | }
66 | } else {
67 | options = options || {};
68 | options[name] = error[name as keyof Error];
69 | }
70 | }
71 | }
72 | return options;
73 | }
74 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/get-identifier.ts:
--------------------------------------------------------------------------------
1 | // Written by https://github.com/DylanPiercey and is distributed under the MIT license.
2 | const REF_START_CHARS = /* @__PURE__ */ 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
3 | const REF_START_CHARS_LEN = /* @__PURE__ */ REF_START_CHARS.length;
4 | const REF_CHARS =
5 | /* @__PURE__ */ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_';
6 | const REF_CHARS_LEN = /* @__PURE__ */ REF_CHARS.length;
7 |
8 | export default function getIdentifier(index: number): string {
9 | let mod = index % REF_START_CHARS_LEN;
10 | let ref = REF_START_CHARS[mod];
11 | index = (index - mod) / REF_START_CHARS_LEN;
12 | while (index > 0) {
13 | mod = index % REF_CHARS_LEN;
14 | ref += REF_CHARS[mod];
15 | index = (index - mod) / REF_CHARS_LEN;
16 | }
17 | return ref;
18 | }
19 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/get-object-flag.ts:
--------------------------------------------------------------------------------
1 | import { SerovalObjectFlags } from '../constants';
2 |
3 | export function getObjectFlag(obj: unknown): SerovalObjectFlags {
4 | if (Object.isFrozen(obj)) {
5 | return SerovalObjectFlags.Frozen;
6 | }
7 | if (Object.isSealed(obj)) {
8 | return SerovalObjectFlags.Sealed;
9 | }
10 | if (Object.isExtensible(obj)) {
11 | return SerovalObjectFlags.None;
12 | }
13 | return SerovalObjectFlags.NonExtensible;
14 | }
15 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/is-valid-identifier.ts:
--------------------------------------------------------------------------------
1 | const IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
2 |
3 | export function isValidIdentifier(name: string): boolean {
4 | const char = name[0];
5 | return (
6 | (char === '$' ||
7 | char === '_' ||
8 | (char >= 'A' && char <= 'Z') ||
9 | (char >= 'a' && char <= 'z')) &&
10 | IDENTIFIER_CHECK.test(name)
11 | );
12 | }
13 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/iterator-to-sequence.ts:
--------------------------------------------------------------------------------
1 | import { NIL } from "../constants";
2 |
3 | export interface Sequence {
4 | v: unknown[];
5 | t: number;
6 | d: number;
7 | }
8 |
9 | export function iteratorToSequence(source: Iterable): Sequence {
10 | const values: unknown[] = [];
11 | let throwsAt = -1;
12 | let doneAt = -1;
13 |
14 | const iterator = source[Symbol.iterator]();
15 |
16 | while (true) {
17 | try {
18 | const value = iterator.next();
19 | values.push(value.value);
20 | if (value.done) {
21 | doneAt = values.length - 1;
22 | break;
23 | }
24 | } catch (error) {
25 | throwsAt = values.length;
26 | values.push(error);
27 | }
28 | }
29 |
30 | return {
31 | v: values,
32 | t: throwsAt,
33 | d: doneAt,
34 | };
35 | }
36 |
37 | export function sequenceToIterator(
38 | sequence: Sequence,
39 | ): () => IterableIterator {
40 | return (): IterableIterator => {
41 | let index = 0;
42 |
43 | return {
44 | [Symbol.iterator](): IterableIterator {
45 | return this;
46 | },
47 | next(): IteratorResult {
48 | if (index > sequence.d) {
49 | return {
50 | done: true,
51 | value: NIL,
52 | };
53 | }
54 | const currentIndex = index++;
55 | const currentItem = sequence.v[currentIndex];
56 | if (currentIndex === sequence.t) {
57 | throw currentItem;
58 | }
59 | return {
60 | done: currentIndex === sequence.d,
61 | value: currentItem as T,
62 | };
63 | },
64 | };
65 | };
66 | }
67 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/promise-to-result.ts:
--------------------------------------------------------------------------------
1 | export default async function promiseToResult(
2 | current: Promise,
3 | ): Promise<[0 | 1, unknown]> {
4 | try {
5 | return [1, await current];
6 | } catch (e) {
7 | return [0, e];
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/seroval/src/core/utils/typed-array.ts:
--------------------------------------------------------------------------------
1 | import { SerovalUnknownTypedArrayError } from '../errors';
2 |
3 | type TypedArrayConstructor =
4 | | Int8ArrayConstructor
5 | | Int16ArrayConstructor
6 | | Int32ArrayConstructor
7 | | Uint8ArrayConstructor
8 | | Uint16ArrayConstructor
9 | | Uint32ArrayConstructor
10 | | Uint8ClampedArrayConstructor
11 | | Float32ArrayConstructor
12 | | Float64ArrayConstructor
13 | | BigInt64ArrayConstructor
14 | | BigUint64ArrayConstructor;
15 |
16 | export type TypedArrayValue =
17 | | Int8Array
18 | | Int16Array
19 | | Int32Array
20 | | Uint8Array
21 | | Uint16Array
22 | | Uint32Array
23 | | Uint8ClampedArray
24 | | Float32Array
25 | | Float64Array;
26 |
27 | export type BigIntTypedArrayValue = BigInt64Array | BigUint64Array;
28 |
29 | export function getTypedArrayConstructor(name: string): TypedArrayConstructor {
30 | switch (name) {
31 | case 'Int8Array':
32 | return Int8Array;
33 | case 'Int16Array':
34 | return Int16Array;
35 | case 'Int32Array':
36 | return Int32Array;
37 | case 'Uint8Array':
38 | return Uint8Array;
39 | case 'Uint16Array':
40 | return Uint16Array;
41 | case 'Uint32Array':
42 | return Uint32Array;
43 | case 'Uint8ClampedArray':
44 | return Uint8ClampedArray;
45 | case 'Float32Array':
46 | return Float32Array;
47 | case 'Float64Array':
48 | return Float64Array;
49 | case 'BigInt64Array':
50 | return BigInt64Array;
51 | case 'BigUint64Array':
52 | return BigUint64Array;
53 | default:
54 | throw new SerovalUnknownTypedArrayError(name);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/packages/seroval/src/index.ts:
--------------------------------------------------------------------------------
1 | export { Feature } from './core/compat';
2 | export { createReference } from './core/reference';
3 |
4 | export * from './core/cross';
5 | export * from './core/tree';
6 |
7 | export { getCrossReferenceHeader } from './core/keys';
8 |
9 | export * from './core/plugin';
10 | export { default as Serializer } from './core/Serializer';
11 |
12 | export { createStream } from './core/stream';
13 | export type { Stream } from './core/stream';
14 |
15 | export * from './core/errors';
16 | export type { SerovalNode } from './core/types';
17 |
18 | export { OpaqueReference } from './core/opaque-reference';
19 |
--------------------------------------------------------------------------------
/packages/seroval/test.js:
--------------------------------------------------------------------------------
1 | import { serialize } from './dist/esm/development/index.mjs';
2 |
3 | function example() {
4 | return new Set([
5 | {
6 | id: 1,
7 | first_name: 'Jimmy',
8 | last_name: 'Hansen',
9 | email: 'jhansen0@skyrock.com',
10 | gender: 'Male',
11 | ip_address: '166.6.70.130',
12 | },
13 | {
14 | id: 1,
15 | first_name: 'Judy',
16 | last_name: 'Cook',
17 | email: 'jcook0@themeforest.net',
18 | gender: 'Female',
19 | ip_address: '171.246.40.83',
20 | },
21 | {
22 | id: 2,
23 | first_name: 'Anne',
24 | last_name: 'Thomas',
25 | email: 'athomas1@usda.gov',
26 | gender: 'Female',
27 | ip_address: '158.159.200.150',
28 | },
29 | ]);
30 | }
31 |
32 | for (let i = 0; i < 10000; i++) {
33 | serialize(example());
34 | }
35 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/bigint.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`bigint > crossSerialize > supports bigint 1`] = `"9007199254740991n"`;
4 |
5 | exports[`bigint > crossSerializeAsync > supports bigint 1`] = `"$R[0]=Promise.resolve(9007199254740991n)"`;
6 |
7 | exports[`bigint > crossSerializeStream > supports bigint 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
8 |
9 | exports[`bigint > crossSerializeStream > supports bigint 2`] = `"($R[3]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],9007199254740991n)"`;
10 |
11 | exports[`bigint > serialize > supports bigint 1`] = `"9007199254740991n"`;
12 |
13 | exports[`bigint > serializeAsync > supports bigint 1`] = `"Promise.resolve(9007199254740991n)"`;
14 |
15 | exports[`bigint > toCrossJSON > supports bigint 1`] = `"{"t":3,"s":"9007199254740991"}"`;
16 |
17 | exports[`bigint > toCrossJSONAsync > supports bigint 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":3,"s":"9007199254740991"}}"`;
18 |
19 | exports[`bigint > toCrossJSONStream > supports bigint 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
20 |
21 | exports[`bigint > toCrossJSONStream > supports bigint 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":3,"s":2},{"t":3,"s":"9007199254740991"}]}"`;
22 |
23 | exports[`bigint > toJSON > supports bigint 1`] = `"{"t":{"t":3,"s":"9007199254740991"},"f":31,"m":[]}"`;
24 |
25 | exports[`bigint > toJSONAsync > supports bigint 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":3,"s":"9007199254740991"}},"f":31,"m":[]}"`;
26 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/boolean.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`boolean > crossSerialize > supports boolean 1`] = `"!0"`;
4 |
5 | exports[`boolean > crossSerialize > supports boolean 2`] = `"!1"`;
6 |
7 | exports[`boolean > crossSerializeAsync > supports boolean 1`] = `"$R[0]=Promise.resolve(!0)"`;
8 |
9 | exports[`boolean > crossSerializeAsync > supports boolean 2`] = `"$R[0]=Promise.resolve(!1)"`;
10 |
11 | exports[`boolean > crossSerializeStream > supports false value 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
12 |
13 | exports[`boolean > crossSerializeStream > supports false value 2`] = `"($R[3]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],!1)"`;
14 |
15 | exports[`boolean > crossSerializeStream > supports true value 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`boolean > crossSerializeStream > supports true value 2`] = `"($R[3]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],!0)"`;
18 |
19 | exports[`boolean > toCrossJSON > supports boolean 1`] = `"{"t":2,"s":2}"`;
20 |
21 | exports[`boolean > toCrossJSON > supports boolean 2`] = `"{"t":2,"s":3}"`;
22 |
23 | exports[`boolean > toCrossJSONAsync > supports boolean 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":2,"s":2}}"`;
24 |
25 | exports[`boolean > toCrossJSONAsync > supports boolean 2`] = `"{"t":12,"i":0,"s":1,"f":{"t":2,"s":3}}"`;
26 |
27 | exports[`boolean > toCrossJSONStream > supports false value 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`boolean > toCrossJSONStream > supports false value 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":3,"s":2},{"t":2,"s":3}]}"`;
30 |
31 | exports[`boolean > toCrossJSONStream > supports true value 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
32 |
33 | exports[`boolean > toCrossJSONStream > supports true value 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":3,"s":2},{"t":2,"s":2}]}"`;
34 |
35 | exports[`boolean > toJSON > supports boolean 1`] = `"{"t":{"t":2,"s":2},"f":31,"m":[]}"`;
36 |
37 | exports[`boolean > toJSON > supports boolean 2`] = `"{"t":{"t":2,"s":3},"f":31,"m":[]}"`;
38 |
39 | exports[`boolean > toJSONAsync > supports boolean 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":2}},"f":31,"m":[]}"`;
40 |
41 | exports[`boolean > toJSONAsync > supports boolean 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":2,"s":3}},"f":31,"m":[]}"`;
42 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/boxed-bigint.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`boxed bigint > crossSerialize > scoped > supports boxed bigint 1`] = `"($R=>$R[0]=Object(9007199254740991n))($R["example"])"`;
4 |
5 | exports[`boxed bigint > crossSerialize > supports boxed bigint 1`] = `"$R[0]=Object(9007199254740991n)"`;
6 |
7 | exports[`boxed bigint > crossSerializeAsync > scoped > supports boxed bigint 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=Object(9007199254740991n)))($R["example"])"`;
8 |
9 | exports[`boxed bigint > crossSerializeAsync > supports boxed bigint 1`] = `"$R[0]=Promise.resolve($R[1]=Object(9007199254740991n))"`;
10 |
11 | exports[`boxed bigint > crossSerializeStream > scoped > supports boxed bigint 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`boxed bigint > crossSerializeStream > scoped > supports boxed bigint 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(9007199254740991n)))($R["example"])"`;
14 |
15 | exports[`boxed bigint > crossSerializeStream > supports boxed bigint 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`boxed bigint > crossSerializeStream > supports boxed bigint 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(9007199254740991n))"`;
18 |
19 | exports[`boxed bigint > serialize > supports boxed bigint 1`] = `"Object(9007199254740991n)"`;
20 |
21 | exports[`boxed bigint > serializeAsync > supports boxed bigint 1`] = `"Promise.resolve(Object(9007199254740991n))"`;
22 |
23 | exports[`boxed bigint > toCrossJSON > supports boxed bigint 1`] = `"{"t":21,"i":0,"f":{"t":3,"s":"9007199254740991"}}"`;
24 |
25 | exports[`boxed bigint > toCrossJSONAsync > supports boxed bigint 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":3,"s":"9007199254740991"}}}"`;
26 |
27 | exports[`boxed bigint > toCrossJSONStream > supports boxed bigint 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`boxed bigint > toCrossJSONStream > supports boxed bigint 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":21,"i":3,"f":{"t":3,"s":"9007199254740991"}}]}"`;
30 |
31 | exports[`boxed bigint > toJSON > supports boxed bigint 1`] = `"{"t":{"t":21,"i":0,"f":{"t":3,"s":"9007199254740991"}},"f":31,"m":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/boxed-boolean.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`boxed boolean > crossSerialize > scoped > supports boolean 1`] = `"($R=>$R[0]=Object(!0))($R["example"])"`;
4 |
5 | exports[`boxed boolean > crossSerialize > scoped > supports boolean 2`] = `"($R=>$R[0]=Object(!1))($R["example"])"`;
6 |
7 | exports[`boxed boolean > crossSerialize > supports boolean 1`] = `"$R[0]=Object(!0)"`;
8 |
9 | exports[`boxed boolean > crossSerialize > supports boolean 2`] = `"$R[0]=Object(!1)"`;
10 |
11 | exports[`boxed boolean > crossSerializeAsync > scoped > supports boolean 1`] = `"($R=>$R[0]=Object(!0))($R["example"])"`;
12 |
13 | exports[`boxed boolean > crossSerializeAsync > scoped > supports boolean 2`] = `"($R=>$R[0]=Object(!1))($R["example"])"`;
14 |
15 | exports[`boxed boolean > crossSerializeAsync > supports boolean 1`] = `"$R[0]=Object(!0)"`;
16 |
17 | exports[`boxed boolean > crossSerializeAsync > supports boolean 2`] = `"$R[0]=Object(!1)"`;
18 |
19 | exports[`boxed boolean > crossSerializeStream > scoped > supports boxed false 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
20 |
21 | exports[`boxed boolean > crossSerializeStream > scoped > supports boxed false 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(!1)))($R["example"])"`;
22 |
23 | exports[`boxed boolean > crossSerializeStream > scoped > supports boxed true 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
24 |
25 | exports[`boxed boolean > crossSerializeStream > scoped > supports boxed true 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(!0)))($R["example"])"`;
26 |
27 | exports[`boxed boolean > crossSerializeStream > supports boxed false 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
28 |
29 | exports[`boxed boolean > crossSerializeStream > supports boxed false 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(!1))"`;
30 |
31 | exports[`boxed boolean > crossSerializeStream > supports boxed true 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
32 |
33 | exports[`boxed boolean > crossSerializeStream > supports boxed true 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=Object(!0))"`;
34 |
35 | exports[`boxed boolean > toCrossJSON > supports boolean 1`] = `"{"t":21,"i":0,"f":{"t":2,"s":2}}"`;
36 |
37 | exports[`boxed boolean > toCrossJSON > supports boolean 2`] = `"{"t":21,"i":0,"f":{"t":2,"s":3}}"`;
38 |
39 | exports[`boxed boolean > toCrossJSONAsync > supports boolean 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":2}}}"`;
40 |
41 | exports[`boxed boolean > toCrossJSONAsync > supports boolean 2`] = `"{"t":12,"i":0,"s":1,"f":{"t":21,"i":1,"f":{"t":2,"s":3}}}"`;
42 |
43 | exports[`boxed boolean > toCrossJSONStream > supports boxed false 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
44 |
45 | exports[`boxed boolean > toCrossJSONStream > supports boxed false 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":21,"i":3,"f":{"t":2,"s":3}}]}"`;
46 |
47 | exports[`boxed boolean > toCrossJSONStream > supports boxed true 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
48 |
49 | exports[`boxed boolean > toCrossJSONStream > supports boxed true 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":21,"i":3,"f":{"t":2,"s":2}}]}"`;
50 |
51 | exports[`boxed boolean > toJSON > supports boolean 1`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":2}},"f":31,"m":[]}"`;
52 |
53 | exports[`boxed boolean > toJSON > supports boolean 2`] = `"{"t":{"t":21,"i":0,"f":{"t":2,"s":3}},"f":31,"m":[]}"`;
54 |
55 | 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":[]}"`;
56 |
57 | 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":[]}"`;
58 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/data-view.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`DataView > crossSerialize > scoped > supports DataView 1`] = `"($R=>$R[0]=new DataView($R[1]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16))($R["example"])"`;
4 |
5 | exports[`DataView > crossSerialize > supports DataView 1`] = `"$R[0]=new DataView($R[1]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16)"`;
6 |
7 | exports[`DataView > crossSerializeAsync > scoped > supports DataView 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=new DataView($R[2]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16)))($R["example"])"`;
8 |
9 | exports[`DataView > crossSerializeAsync > supports DataView 1`] = `"$R[0]=Promise.resolve($R[1]=new DataView($R[2]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16))"`;
10 |
11 | exports[`DataView > crossSerializeStream > scoped > supports DataView 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`DataView > crossSerializeStream > scoped > supports DataView 2`] = `"($R=>($R[5]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new DataView($R[4]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16)))($R["example"])"`;
14 |
15 | exports[`DataView > crossSerializeStream > supports DataView 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`DataView > crossSerializeStream > supports DataView 2`] = `"($R[5]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new DataView($R[4]=new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16))"`;
18 |
19 | exports[`DataView > serialize > supports DataView 1`] = `"new DataView(new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16)"`;
20 |
21 | exports[`DataView > serializeAsync > supports DataView 1`] = `"Promise.resolve(new DataView(new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16))"`;
22 |
23 | exports[`DataView > toCrossJSON > supports DataView 1`] = `"{"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}"`;
24 |
25 | exports[`DataView > toCrossJSONAsync > supports DataView 1`] = `"{"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}}"`;
26 |
27 | exports[`DataView > toCrossJSONStream > supports DataView 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`DataView > toCrossJSONStream > supports DataView 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":5,"s":2},{"t":20,"i":3,"l":16,"f":{"t":19,"i":4,"s":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},"b":0}]}"`;
30 |
31 | 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":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/date.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`Date > crossSerialize > scoped > supports Date 1`] = `"($R=>$R[0]=new Date("2023-03-14T11:16:24.879Z"))($R["example"])"`;
4 |
5 | exports[`Date > crossSerialize > supports Date 1`] = `"$R[0]=new Date("2023-03-14T11:16:24.879Z")"`;
6 |
7 | exports[`Date > crossSerializeAsync > scoped > supports Date 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=new Date("2023-03-14T11:16:24.879Z")))($R["example"])"`;
8 |
9 | exports[`Date > crossSerializeAsync > supports Date 1`] = `"$R[0]=Promise.resolve($R[1]=new Date("2023-03-14T11:16:24.879Z"))"`;
10 |
11 | exports[`Date > crossSerializeStream > scoped > supports Date 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`Date > crossSerializeStream > scoped > supports Date 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Date("2023-03-14T11:16:24.879Z")))($R["example"])"`;
14 |
15 | exports[`Date > crossSerializeStream > supports Date 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`Date > crossSerializeStream > supports Date 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Date("2023-03-14T11:16:24.879Z"))"`;
18 |
19 | exports[`Date > serialize > supports Date 1`] = `"new Date("2023-03-14T11:16:24.879Z")"`;
20 |
21 | exports[`Date > serializeAsync > supports Date 1`] = `"Promise.resolve(new Date("2023-03-14T11:16:24.879Z"))"`;
22 |
23 | exports[`Date > toCrossJSON > supports Date 1`] = `"{"t":5,"i":0,"s":"2023-03-14T11:16:24.879Z"}"`;
24 |
25 | exports[`Date > toCrossJSONAsync > supports Date 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":5,"i":1,"s":"2023-03-14T11:16:24.879Z"}}"`;
26 |
27 | exports[`Date > toCrossJSONStream > supports Date 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`Date > toCrossJSONStream > supports Date 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":5,"i":3,"s":"2023-03-14T11:16:24.879Z"}]}"`;
30 |
31 | exports[`Date > toJSON > supports Date 1`] = `"{"t":{"t":5,"i":0,"s":"2023-03-14T11:16:24.879Z"},"f":31,"m":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/plugin.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`Plugin > crossSerialize > scoped > supports Plugin 1`] = `"($R=>$R[0]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64"))($R["example"])"`;
4 |
5 | exports[`Plugin > crossSerialize > supports Plugin 1`] = `"$R[0]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64")"`;
6 |
7 | exports[`Plugin > crossSerializeAsync > scoped > supports Plugin 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64")))($R["example"])"`;
8 |
9 | exports[`Plugin > crossSerializeAsync > supports Plugin 1`] = `"$R[0]=Promise.resolve($R[1]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64"))"`;
10 |
11 | exports[`Plugin > crossSerializeStream > scoped > supports Plugin 1`] = `"($R=>$R[0]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64"))($R["example"])"`;
12 |
13 | exports[`Plugin > crossSerializeStream > supports Plugin 1`] = `"$R[0]=Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64")"`;
14 |
15 | exports[`Plugin > serialize > supports Plugin 1`] = `"Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64")"`;
16 |
17 | exports[`Plugin > serializeAsync > supports Plugin 1`] = `"Promise.resolve(Buffer.from("SGVsbG8sIFdvcmxkIQ==", "base64"))"`;
18 |
19 | exports[`Plugin > toCrossJSON > supports Plugin 1`] = `"{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}"`;
20 |
21 | exports[`Plugin > toCrossJSONAsync > supports Plugin 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":25,"i":1,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}}"`;
22 |
23 | exports[`Plugin > toCrossJSONStream > supports Plugin 1`] = `"{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"}"`;
24 |
25 | exports[`Plugin > toJSON > supports Plugin 1`] = `"{"t":{"t":25,"i":0,"s":{"t":1,"s":"SGVsbG8sIFdvcmxkIQ=="},"c":"Buffer"},"f":31,"m":[]}"`;
26 |
27 | 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":[]}"`;
28 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/promise.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`Promise > compat > should use function expression instead of arrow functions 1`] = `"(function(h){return h={self:Promise.resolve().then(function(){return h})}})()"`;
4 |
5 | exports[`Promise > compat > should use function expression instead of arrow functions 2`] = `"(function(h){return h={self:Promise.reject().catch(function(){throw h})}})()"`;
6 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/reference.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`Reference > crossSerialize > crossSerialize > supports Reference 1`] = `"($R=>$R[0]=__SEROVAL_REFS__.get("example"))($R["example"])"`;
4 |
5 | exports[`Reference > crossSerialize > supports Reference 1`] = `"$R[0]=__SEROVAL_REFS__.get("example")"`;
6 |
7 | exports[`Reference > crossSerializeAsync > scoped > supports Reference 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=__SEROVAL_REFS__.get("example")))($R["example"])"`;
8 |
9 | exports[`Reference > crossSerializeAsync > supports Reference 1`] = `"$R[0]=Promise.resolve($R[1]=__SEROVAL_REFS__.get("example"))"`;
10 |
11 | exports[`Reference > crossSerializeStream > scoped > supports Reference 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`Reference > crossSerializeStream > scoped > supports Reference 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=__SEROVAL_REFS__.get("example")))($R["example"])"`;
14 |
15 | exports[`Reference > crossSerializeStream > supports Reference 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`Reference > crossSerializeStream > supports Reference 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=__SEROVAL_REFS__.get("example"))"`;
18 |
19 | exports[`Reference > serialize > supports Reference 1`] = `"__SEROVAL_REFS__.get("example")"`;
20 |
21 | exports[`Reference > serializeAsync > supports Reference 1`] = `"Promise.resolve(__SEROVAL_REFS__.get("example"))"`;
22 |
23 | exports[`Reference > toCrossJSON > supports Reference 1`] = `"{"t":18,"i":0,"s":"example"}"`;
24 |
25 | exports[`Reference > toCrossJSONAsync > supports Reference 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":18,"i":1,"s":"example"}}"`;
26 |
27 | exports[`Reference > toCrossJSONStream > supports Reference 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`Reference > toCrossJSONStream > supports Reference 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":18,"i":3,"s":"example"}]}"`;
30 |
31 | exports[`Reference > toJSON > supports Reference 1`] = `"{"t":{"t":18,"i":0,"s":"example"},"f":31,"m":[]}"`;
32 |
33 | exports[`Reference > toJSONAsync > supports Reference 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":18,"i":1,"s":"example"}},"f":31,"m":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/regexp.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`RegExp > crossSerialize > scoped > supports RegExp 1`] = `"($R=>$R[0]=/[a-z0-9]+/i)($R["example"])"`;
4 |
5 | exports[`RegExp > crossSerialize > supports RegExp 1`] = `"$R[0]=/[a-z0-9]+/i"`;
6 |
7 | exports[`RegExp > crossSerializeAsync > scoped > supports RegExp 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=/[a-z0-9]+/i))($R["example"])"`;
8 |
9 | exports[`RegExp > crossSerializeAsync > supports RegExp 1`] = `"$R[0]=Promise.resolve($R[1]=/[a-z0-9]+/i)"`;
10 |
11 | exports[`RegExp > crossSerializeStream > scoped > supports RegExp 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`RegExp > crossSerializeStream > scoped > supports RegExp 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=/[a-z0-9]+/i))($R["example"])"`;
14 |
15 | exports[`RegExp > crossSerializeStream > supports RegExp 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`RegExp > crossSerializeStream > supports RegExp 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=/[a-z0-9]+/i)"`;
18 |
19 | exports[`RegExp > serialize > supports RegExp 1`] = `"/[a-z0-9]+/i"`;
20 |
21 | exports[`RegExp > serializeAsync > supports RegExp 1`] = `"Promise.resolve(/[a-z0-9]+/i)"`;
22 |
23 | exports[`RegExp > toCrossJSON > supports RegExp 1`] = `"{"t":6,"i":0,"c":"[a-z0-9]+","m":"i"}"`;
24 |
25 | exports[`RegExp > toCrossJSONAsync > supports RegExp 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":6,"i":1,"c":"[a-z0-9]+","m":"i"}}"`;
26 |
27 | exports[`RegExp > toCrossJSONStream > supports RegExp 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`RegExp > toCrossJSONStream > supports RegExp 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":6,"i":3,"c":"[a-z0-9]+","m":"i"}]}"`;
30 |
31 | exports[`RegExp > toJSON > supports RegExp 1`] = `"{"t":{"t":6,"i":0,"c":"[a-z0-9]+","m":"i"},"f":31,"m":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/set.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`Set > crossSerialize > scoped > supports Set 1`] = `"($R=>$R[0]=new Set([1,2,3]))($R["example"])"`;
4 |
5 | exports[`Set > crossSerialize > scoped > supports self-recursion 1`] = `"($R=>($R[0]=new Set,$R[0].add($R[0]),$R[0]))($R["example"])"`;
6 |
7 | exports[`Set > crossSerialize > supports Set 1`] = `"$R[0]=new Set([1,2,3])"`;
8 |
9 | exports[`Set > crossSerialize > supports self-recursion 1`] = `"($R[0]=new Set,$R[0].add($R[0]),$R[0])"`;
10 |
11 | exports[`Set > crossSerializeAsync > scoped > supports Set 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=new Set([1,2,3])))($R["example"])"`;
12 |
13 | exports[`Set > crossSerializeAsync > scoped > supports self-recursion 1`] = `"($R=>$R[0]=new Set([$R[1]=Promise.resolve().then(()=>$R[0])]))($R["example"])"`;
14 |
15 | exports[`Set > crossSerializeAsync > supports Set 1`] = `"$R[0]=Promise.resolve($R[1]=new Set([1,2,3]))"`;
16 |
17 | exports[`Set > crossSerializeAsync > supports self-recursion 1`] = `"$R[0]=new Set([$R[1]=Promise.resolve().then(()=>$R[0])])"`;
18 |
19 | exports[`Set > crossSerializeStream > scoped > supports Set 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
20 |
21 | exports[`Set > crossSerializeStream > scoped > supports Set 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Set([1,2,3])))($R["example"])"`;
22 |
23 | exports[`Set > crossSerializeStream > scoped > supports self-recursion 1`] = `"($R=>$R[0]=new Set([$R[1]=($R[3]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[2]={p:0,s:0,f:0})]))($R["example"])"`;
24 |
25 | exports[`Set > crossSerializeStream > scoped > supports self-recursion 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[2],$R[0]))($R["example"])"`;
26 |
27 | exports[`Set > crossSerializeStream > supports Set 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
28 |
29 | exports[`Set > crossSerializeStream > supports Set 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Set([1,2,3]))"`;
30 |
31 | exports[`Set > crossSerializeStream > supports self-recursion 1`] = `"$R[0]=new Set([$R[1]=($R[3]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[2]={p:0,s:0,f:0})])"`;
32 |
33 | exports[`Set > crossSerializeStream > supports self-recursion 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[2],$R[0])"`;
34 |
35 | exports[`Set > serialize > supports Set 1`] = `"new Set([1,2,3])"`;
36 |
37 | exports[`Set > serialize > supports self-recursion 1`] = `"(h=>(h=new Set,h.add(h),h))()"`;
38 |
39 | exports[`Set > serializeAsync > supports Set 1`] = `"Promise.resolve(new Set([1,2,3]))"`;
40 |
41 | exports[`Set > serializeAsync > supports self-recursion 1`] = `"(h=>h=new Set([Promise.resolve().then(()=>h)]))()"`;
42 |
43 | exports[`Set > toCrossJSON > supports Set 1`] = `"{"t":7,"i":0,"l":3,"a":[{"t":0,"s":1},{"t":0,"s":2},{"t":0,"s":3}]}"`;
44 |
45 | exports[`Set > toCrossJSON > supports self-recursion 1`] = `"{"t":7,"i":0,"l":1,"a":[{"t":4,"i":0}]}"`;
46 |
47 | exports[`Set > toCrossJSONAsync > supports Set 1`] = `"{"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}]}}"`;
48 |
49 | 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}}]}"`;
50 |
51 | 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":[]}"`;
52 |
53 | exports[`Set > toJSON > supports self-recursion 1`] = `"{"t":{"t":7,"i":0,"l":1,"a":[{"t":4,"i":0}]},"f":31,"m":[0]}"`;
54 |
55 | 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":[]}"`;
56 |
57 | 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]}"`;
58 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/sparse-array.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`sparse arrays > crossSerialize > scoped > supports sparse arrays 1`] = `"($R=>$R[0]=[,,,,,,,,,,])($R["example"])"`;
4 |
5 | exports[`sparse arrays > crossSerialize > supports sparse arrays 1`] = `"$R[0]=[,,,,,,,,,,]"`;
6 |
7 | exports[`sparse arrays > crossSerializeAsync > scoped > supports sparse arrays 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=[,,,,,,,,,,]))($R["example"])"`;
8 |
9 | exports[`sparse arrays > crossSerializeAsync > supports sparse arrays 1`] = `"$R[0]=Promise.resolve($R[1]=[,,,,,,,,,,])"`;
10 |
11 | exports[`sparse arrays > crossSerializeStream > scoped > supports sparse arrays 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`sparse arrays > crossSerializeStream > scoped > supports sparse arrays 2`] = `"($R=>($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=[,,,,,,,,,,]))($R["example"])"`;
14 |
15 | exports[`sparse arrays > crossSerializeStream > supports sparse arrays 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`sparse arrays > crossSerializeStream > supports sparse arrays 2`] = `"($R[4]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=[,,,,,,,,,,])"`;
18 |
19 | exports[`sparse arrays > serialize > supports sparse arrays 1`] = `"[,,,,,,,,,,]"`;
20 |
21 | exports[`sparse arrays > serializeAsync > supports sparse arrays 1`] = `"Promise.resolve([,,,,,,,,,,])"`;
22 |
23 | exports[`sparse arrays > toCrossJSON > supports sparse arrays 1`] = `"{"t":9,"i":0,"l":10,"a":[],"o":0}"`;
24 |
25 | exports[`sparse arrays > toCrossJSONAsync > supports sparse arrays 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":9,"i":1,"l":10,"a":[],"o":0}}"`;
26 |
27 | exports[`sparse arrays > toCrossJSONStream > supports sparse arrays 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`sparse arrays > toCrossJSONStream > supports sparse arrays 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":4,"s":2},{"t":9,"i":3,"l":10,"a":[],"o":0}]}"`;
30 |
31 | exports[`sparse arrays > toJSON > supports sparse arrays 1`] = `"{"t":{"t":9,"i":0,"l":10,"a":[],"o":0},"f":31,"m":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/string.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`string > crossSerialize > supports strings 1`] = `""\\"hello\\"""`;
4 |
5 | exports[`string > crossSerialize > supports strings 2`] = `""\\x3Cscript>\\x3C/script>""`;
6 |
7 | exports[`string > crossSerializeAsync > supports strings 1`] = `"$R[0]=Promise.resolve("\\"hello\\"")"`;
8 |
9 | exports[`string > crossSerializeAsync > supports strings 2`] = `"$R[0]=Promise.resolve("\\x3Cscript>\\x3C/script>")"`;
10 |
11 | exports[`string > crossSerializeStream > supports sanitized strings 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
12 |
13 | exports[`string > crossSerializeStream > supports sanitized strings 2`] = `"($R[3]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],"\\x3Cscript>\\x3C/script>")"`;
14 |
15 | exports[`string > crossSerializeStream > supports strings 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`string > crossSerializeStream > supports strings 2`] = `"($R[3]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],"\\"hello\\"")"`;
18 |
19 | exports[`string > serialize > supports strings 1`] = `""\\"hello\\"""`;
20 |
21 | exports[`string > serialize > supports strings 2`] = `""\\x3Cscript>\\x3C/script>""`;
22 |
23 | exports[`string > serializeAsync > supports strings 1`] = `"Promise.resolve("\\"hello\\"")"`;
24 |
25 | exports[`string > serializeAsync > supports strings 2`] = `"Promise.resolve("\\x3Cscript>\\x3C/script>")"`;
26 |
27 | exports[`string > toCrossJSON > supports strings 1`] = `"{"t":1,"s":"\\\\\\"hello\\\\\\""}"`;
28 |
29 | exports[`string > toCrossJSON > supports strings 2`] = `"{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}"`;
30 |
31 | exports[`string > toCrossJSONAsync > supports strings 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}}"`;
32 |
33 | exports[`string > toCrossJSONAsync > supports strings 2`] = `"{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}}"`;
34 |
35 | exports[`string > toCrossJSONStream > supports sanitized strings 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
36 |
37 | exports[`string > toCrossJSONStream > supports sanitized strings 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":3,"s":2},{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}]}"`;
38 |
39 | exports[`string > toCrossJSONStream > supports strings 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
40 |
41 | exports[`string > toCrossJSONStream > supports strings 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":3,"s":2},{"t":1,"s":"\\\\\\"hello\\\\\\""}]}"`;
42 |
43 | exports[`string > toJSON > supports strings 1`] = `"{"t":{"t":1,"s":"\\\\\\"hello\\\\\\""},"f":31,"m":[]}"`;
44 |
45 | exports[`string > toJSON > supports strings 2`] = `"{"t":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"},"f":31,"m":[]}"`;
46 |
47 | exports[`string > toJSONAsync > supports strings 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\\\"hello\\\\\\""}},"f":31,"m":[]}"`;
48 |
49 | exports[`string > toJSONAsync > supports strings 2`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":1,"s":"\\\\x3Cscript>\\\\x3C/script>"}},"f":31,"m":[]}"`;
50 |
--------------------------------------------------------------------------------
/packages/seroval/test/__snapshots__/typed-array.test.ts.snap:
--------------------------------------------------------------------------------
1 | // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2 |
3 | exports[`typed arrays > crossSerialize > scoped > supports typed arrays 1`] = `"($R=>$R[0]=new Uint32Array($R[1]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4))($R["example"])"`;
4 |
5 | exports[`typed arrays > crossSerialize > supports typed arrays 1`] = `"$R[0]=new Uint32Array($R[1]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4)"`;
6 |
7 | exports[`typed arrays > crossSerializeAsync > scoped > supports typed arrays 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=new Uint32Array($R[2]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4)))($R["example"])"`;
8 |
9 | exports[`typed arrays > crossSerializeAsync > supports typed arrays 1`] = `"$R[0]=Promise.resolve($R[1]=new Uint32Array($R[2]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4))"`;
10 |
11 | exports[`typed arrays > crossSerializeStream > scoped > supports typed arrays 1`] = `"($R=>$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0}))($R["example"])"`;
12 |
13 | exports[`typed arrays > crossSerializeStream > scoped > supports typed arrays 2`] = `"($R=>($R[5]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Uint32Array($R[4]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4)))($R["example"])"`;
14 |
15 | exports[`typed arrays > crossSerializeStream > supports typed arrays 1`] = `"$R[0]=($R[2]=r=>(r.p=new Promise((s,f)=>{r.s=s,r.f=f})))($R[1]={p:0,s:0,f:0})"`;
16 |
17 | exports[`typed arrays > crossSerializeStream > supports typed arrays 2`] = `"($R[5]=(r,d)=>{r.s(d),r.p.s=1,r.p.v=d})($R[1],$R[3]=new Uint32Array($R[4]=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4))"`;
18 |
19 | exports[`typed arrays > serialize > supports typed arrays 1`] = `"new Uint32Array(new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4)"`;
20 |
21 | exports[`typed arrays > serializeAsync > supports typed arrays 1`] = `"Promise.resolve(new Uint32Array(new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]).buffer,0,4))"`;
22 |
23 | exports[`typed arrays > toCrossJSON > supports typed arrays 1`] = `"{"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}"`;
24 |
25 | exports[`typed arrays > toCrossJSONAsync > supports typed arrays 1`] = `"{"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}}"`;
26 |
27 | exports[`typed arrays > toCrossJSONStream > supports typed arrays 1`] = `"{"t":22,"i":0,"s":1,"f":{"t":26,"i":2,"s":1}}"`;
28 |
29 | exports[`typed arrays > toCrossJSONStream > supports typed arrays 2`] = `"{"t":23,"i":1,"a":[{"t":26,"i":5,"s":2},{"t":15,"i":3,"l":4,"c":"Uint32Array","f":{"t":19,"i":4,"s":[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},"b":0}]}"`;
30 |
31 | 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":[]}"`;
32 |
33 | 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":[]}"`;
34 |
--------------------------------------------------------------------------------
/packages/seroval/test/bigint.test.ts:
--------------------------------------------------------------------------------
1 | import { describe, expect, it } from 'vitest';
2 | import {
3 | crossSerialize,
4 | crossSerializeAsync,
5 | crossSerializeStream,
6 | deserialize,
7 | fromCrossJSON,
8 | fromJSON,
9 | serialize,
10 | serializeAsync,
11 | toCrossJSON,
12 | toCrossJSONAsync,
13 | toCrossJSONStream,
14 | toJSON,
15 | toJSONAsync,
16 | } from '../src';
17 |
18 | const EXAMPLE = 9007199254740991n;
19 |
20 | describe('bigint', () => {
21 | describe('serialize', () => {
22 | it('supports bigint', () => {
23 | expect(serialize(EXAMPLE)).toMatchSnapshot();
24 | expect(deserialize(serialize(EXAMPLE))).toBe(EXAMPLE);
25 | });
26 | });
27 | describe('serializeAsync', () => {
28 | it('supports bigint', async () => {
29 | expect(await serializeAsync(Promise.resolve(EXAMPLE))).toMatchSnapshot();
30 | });
31 | });
32 | describe('toJSON', () => {
33 | it('supports bigint', () => {
34 | expect(JSON.stringify(toJSON(EXAMPLE))).toMatchSnapshot();
35 | expect(fromJSON(toJSON(EXAMPLE))).toBe(EXAMPLE);
36 | });
37 | });
38 | describe('toJSONAsync', () => {
39 | it('supports bigint', async () => {
40 | expect(
41 | JSON.stringify(await toJSONAsync(Promise.resolve(EXAMPLE))),
42 | ).toMatchSnapshot();
43 | });
44 | });
45 | describe('crossSerialize', () => {
46 | it('supports bigint', () => {
47 | expect(crossSerialize(EXAMPLE)).toMatchSnapshot();
48 | });
49 | });
50 | describe('crossSerializeAsync', () => {
51 | it('supports bigint', async () => {
52 | expect(
53 | await crossSerializeAsync(Promise.resolve(EXAMPLE)),
54 | ).toMatchSnapshot();
55 | });
56 | });
57 | describe('crossSerializeStream', () => {
58 | it('supports bigint', async () =>
59 | new Promise((resolve, reject) => {
60 | crossSerializeStream(Promise.resolve(EXAMPLE), {
61 | onSerialize(data) {
62 | expect(data).toMatchSnapshot();
63 | },
64 | onDone() {
65 | resolve();
66 | },
67 | onError(error) {
68 | reject(error);
69 | },
70 | });
71 | }));
72 | });
73 | describe('toCrossJSON', () => {
74 | it('supports bigint', () => {
75 | expect(JSON.stringify(toCrossJSON(EXAMPLE))).toMatchSnapshot();
76 | expect(fromCrossJSON(toCrossJSON(EXAMPLE), { refs: new Map() })).toBe(
77 | EXAMPLE,
78 | );
79 | });
80 | });
81 | describe('toCrossJSONAsync', () => {
82 | it('supports bigint', async () => {
83 | expect(
84 | JSON.stringify(await toCrossJSONAsync(Promise.resolve(EXAMPLE))),
85 | ).toMatchSnapshot();
86 | });
87 | });
88 | describe('toCrossJSONStream', () => {
89 | it('supports bigint', async () =>
90 | new Promise((resolve, reject) => {
91 | toCrossJSONStream(Promise.resolve(EXAMPLE), {
92 | onParse(data) {
93 | expect(JSON.stringify(data)).toMatchSnapshot();
94 | },
95 | onDone() {
96 | resolve();
97 | },
98 | onError(error) {
99 | reject(error);
100 | },
101 | });
102 | }));
103 | });
104 | });
105 |
--------------------------------------------------------------------------------
/packages/seroval/test/promise.test.ts:
--------------------------------------------------------------------------------
1 | import { describe, expect, it } from 'vitest';
2 | import { Feature, serializeAsync } from '../src';
3 |
4 | describe('Promise', () => {
5 | describe('compat', () => {
6 | it('should use function expression instead of arrow functions', async () => {
7 | const example: Record> = {};
8 | example.self = Promise.resolve(example);
9 | expect(
10 | await serializeAsync(example, {
11 | disabledFeatures: Feature.ArrowFunction,
12 | }),
13 | ).toMatchSnapshot();
14 | });
15 | it('should use function expression instead of arrow functions', async () => {
16 | const example: Record> = {};
17 | example.self = Promise.reject(example);
18 | expect(
19 | await serializeAsync(example, {
20 | disabledFeatures: Feature.ArrowFunction,
21 | }),
22 | ).toMatchSnapshot();
23 | });
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/packages/seroval/theory.js:
--------------------------------------------------------------------------------
1 | import { toCrossJSONStream, fromCrossJSON, crossSerializeStream } from "./dist/esm/development/index.mjs";
2 |
3 | const delay = (delay, value) => new Promise((resolve) => {
4 | setTimeout(() => resolve(value), delay)
5 | })
6 |
7 | const bla = {
8 | a: 'Hello',
9 | b: delay(1000, "World"),
10 | c: delay(2000, "Bla"),
11 | d: delay(3000, {
12 | e: 2500
13 | })
14 | }
15 |
16 | const refs = new Map();
17 |
18 | toCrossJSONStream(bla, {
19 | onParse(node, initial) {
20 | console.log(fromCrossJSON(node, { refs }))
21 | }
22 | });
23 |
24 | // crossSerializeStream(bla, {
25 | // onSerialize(node) {
26 | // console.log(node);
27 | // }
28 | // })
--------------------------------------------------------------------------------
/packages/seroval/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "exclude": ["node_modules"],
3 | "include": ["src", "types", "test"],
4 | "compilerOptions": {
5 | "module": "ESNext",
6 | "lib": ["ESNext", "DOM"],
7 | "importHelpers": true,
8 | "declaration": true,
9 | "sourceMap": true,
10 | "rootDir": "./src",
11 | "strict": true,
12 | "noUnusedLocals": true,
13 | "noUnusedParameters": true,
14 | "noImplicitReturns": true,
15 | "noFallthroughCasesInSwitch": true,
16 | "moduleResolution": "bundler",
17 | "jsx": "react",
18 | "esModuleInterop": true,
19 | "target": "ESNext",
20 | "useDefineForClassFields": false,
21 | "declarationMap": true
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pnpm-workspace.yaml:
--------------------------------------------------------------------------------
1 | packages:
2 | - packages/**/*
3 | - benchmark
4 | onlyBuiltDependencies:
5 | - esbuild
6 |
--------------------------------------------------------------------------------