Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.0 #13

Merged
merged 21 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add length support for Typed Arrays
  • Loading branch information
lxsmnsyc committed Apr 8, 2023
commit 2c3dc6768f3594d59448f709e88e41efb524f75c
8 changes: 8 additions & 0 deletions packages/seroval/src/tree/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async function generateArrayNode(
d: undefined,
a: await generateNodeList(ctx, current),
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -147,6 +148,7 @@ async function generateMapNode(
d: { k: keyNodes, v: valueNodes, s: len },
a: undefined,
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -183,6 +185,7 @@ async function generateSetNode(
d: undefined,
a: nodes,
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -243,6 +246,7 @@ async function generateIterableNode(
: undefined,
a: await generateNodeList(ctx, array),
f: undefined,
b: undefined,
};
}

Expand All @@ -263,6 +267,7 @@ async function generatePromiseNode(
d: undefined,
a: undefined,
f: await parse(ctx, value),
b: undefined,
}));
}

Expand All @@ -288,6 +293,7 @@ async function generateObjectNode(
d: await generateProperties(ctx, current as Record<string, unknown>),
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -310,6 +316,7 @@ async function generateAggregateErrorNode(
d: optionsNode,
a: await generateNodeList(ctx, current.errors as unknown[]),
f: undefined,
b: undefined,
};
}

Expand All @@ -332,6 +339,7 @@ async function generateErrorNode(
d: optionsNode,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/seroval/src/tree/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function deserializeTypedArray(
const source = deserializeTree(ctx, node.f) as ArrayBuffer;
const result = assignIndexedValue(ctx, node.i, new TypedArray(
source,
node.b,
node.l,
));
return result;
Expand Down
19 changes: 19 additions & 0 deletions packages/seroval/src/tree/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const TRUE_NODE: SerovalBooleanNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const FALSE_NODE: SerovalBooleanNode = {
t: SerovalNodeType.Boolean,
Expand All @@ -48,6 +49,7 @@ export const FALSE_NODE: SerovalBooleanNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const UNDEFINED_NODE: SerovalUndefinedNode = {
t: SerovalNodeType.Undefined,
Expand All @@ -59,6 +61,7 @@ export const UNDEFINED_NODE: SerovalUndefinedNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const NULL_NODE: SerovalNullNode = {
t: SerovalNodeType.Null,
Expand All @@ -70,6 +73,7 @@ export const NULL_NODE: SerovalNullNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const NEG_ZERO_NODE: SerovalNegativeZeroNode = {
t: SerovalNodeType.NegativeZero,
Expand All @@ -81,6 +85,7 @@ export const NEG_ZERO_NODE: SerovalNegativeZeroNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const INFINITY_NODE: SerovalInfinityNode = {
t: SerovalNodeType.Infinity,
Expand All @@ -92,6 +97,7 @@ export const INFINITY_NODE: SerovalInfinityNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const NEG_INFINITY_NODE: SerovalNegativeInfinityNode = {
t: SerovalNodeType.NegativeInfinity,
Expand All @@ -103,6 +109,7 @@ export const NEG_INFINITY_NODE: SerovalNegativeInfinityNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
export const NAN_NODE: SerovalNaNNode = {
t: SerovalNodeType.NaN,
Expand All @@ -114,6 +121,7 @@ export const NAN_NODE: SerovalNaNNode = {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};

export function createNumberNode(value: number): SerovalNumberNode {
Expand All @@ -127,6 +135,7 @@ export function createNumberNode(value: number): SerovalNumberNode {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -141,6 +150,7 @@ export function createStringNode(value: string): SerovalStringNode {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -159,6 +169,7 @@ export function createBigIntNode(
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -173,6 +184,7 @@ export function createIndexedValueNode(id: number): SerovalIndexedValueNode {
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -187,6 +199,7 @@ export function createDateNode(id: number, current: Date): SerovalDateNode {
d: undefined,
f: undefined,
a: undefined,
b: undefined,
};
}

Expand All @@ -201,6 +214,7 @@ export function createRegExpNode(id: number, current: RegExp): SerovalRegExpNode
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -224,6 +238,7 @@ export function createArrayBufferNode(
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -255,6 +270,7 @@ export function createTypedArrayNode(
d: undefined,
a: undefined,
f: serializeArrayBuffer(ctx, current.buffer),
b: current.byteLength,
};
}

Expand All @@ -281,6 +297,7 @@ export function createBigIntTypedArrayNode(
d: undefined,
a: undefined,
f: serializeArrayBuffer(ctx, current.buffer),
b: current.byteLength,
};
}

Expand All @@ -300,6 +317,7 @@ export function createWKSymbolNode(
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -317,5 +335,6 @@ export function createReferenceNode<T>(
d: undefined,
a: undefined,
f: undefined,
b: undefined,
};
}
2 changes: 1 addition & 1 deletion packages/seroval/src/tree/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ function serializeTypedArray(
ctx: SerializationContext,
node: SerovalTypedArrayNode | SerovalBigIntTypedArrayNode,
) {
const args = serializeTree(ctx, node.f) + (node.l !== 0 ? (',' + node.l) : '');
const args = serializeTree(ctx, node.f) + ',' + node.b + ',' + node.l;
return assignIndexedValue(ctx, node.i, 'new ' + node.c + '(' + args + ')');
}

Expand Down
7 changes: 7 additions & 0 deletions packages/seroval/src/tree/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function generateArrayNode(
d: undefined,
a: generateNodeList(ctx, current),
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -132,6 +133,7 @@ function generateMapNode(
d: { k: keyNodes, v: valueNodes, s: len },
a: undefined,
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -168,6 +170,7 @@ function generateSetNode(
d: undefined,
a: nodes,
f: undefined,
b: undefined,
};
}

Expand Down Expand Up @@ -228,6 +231,7 @@ function generateIterableNode(
: undefined,
a: generateNodeList(ctx, array),
f: undefined,
b: undefined,
};
}

Expand All @@ -250,6 +254,7 @@ function generateObjectNode(
d: generateProperties(ctx, current),
a: undefined,
f: undefined,
b: undefined,
};
}

Expand All @@ -272,6 +277,7 @@ function generateAggregateErrorNode(
d: optionsNode,
a: generateNodeList(ctx, current.errors as unknown[]),
f: undefined,
b: undefined,
};
}

Expand All @@ -294,6 +300,7 @@ function generateErrorNode(
d: optionsNode,
a: undefined,
f: undefined,
b: undefined,
};
}

Expand Down
8 changes: 6 additions & 2 deletions packages/seroval/src/tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ export interface SerovalBaseNode {
i: number | undefined;
// Serialized value
s: any;
// Size/Byte offset
// size/length
l: number | undefined;
// Constructor name / RegExp source
c: string | undefined;
// message /flags
// message/flags
m: string | undefined;
// dictionary
d: SerovalDictionaryNode | undefined;
// array of nodes
a: SerovalNode[] | undefined;
// fulfilled node
f: SerovalNode | undefined;
// byte offset
b: number | undefined;
}

export interface SerovalObjectRecordNode {
Expand Down Expand Up @@ -156,6 +158,7 @@ export interface SerovalTypedArrayNode extends SerovalBaseNode {
l: number;
c: string;
f: SerovalNode;
b: number;
}

export interface SerovalBigIntTypedArrayNode extends SerovalBaseNode {
Expand All @@ -164,6 +167,7 @@ export interface SerovalBigIntTypedArrayNode extends SerovalBaseNode {
l: number;
c: string;
f: SerovalNode;
b: number;
}

export type SerovalSemiPrimitiveNode =
Expand Down
2 changes: 2 additions & 0 deletions packages/seroval/src/tree/web-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function createURLNode(
d: undefined,
f: undefined,
a: undefined,
b: undefined,
};
}

Expand All @@ -38,5 +39,6 @@ export function createURLSearchParamsNode(
d: undefined,
f: undefined,
a: undefined,
b: undefined,
};
}