New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

seroval

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seroval - npm Package Compare versions

Comparing version 0.4.0-alpha.9 to 0.4.0-alpha.10

3

dist/types/checks.d.ts
import { AsyncServerValue, PrimitiveValue } from './types';
export declare function isPrimitive(current: unknown): current is PrimitiveValue;
export declare function isPromise<T>(obj: unknown): obj is PromiseLike<T>;
export declare function constructorCheck<T extends NonNullable<AsyncServerValue>>(value: unknown, constructor: unknown): value is T;
export declare function isIterable<T>(obj: unknown): obj is Iterable<T>;
export declare function isIterable(obj: AsyncServerValue): obj is Iterable<AsyncServerValue>;

@@ -53,3 +53,3 @@ interface IndexAssignment {

*/
export declare function createRef(ctx: ParserContext, index: unknown): number;
export declare function createRef(ctx: ParserContext, current: unknown, mark: boolean): number;
export {};
import { SerializationContext, ParserContext } from '../context';
import { ErrorValue, PrimitiveValue } from '../types';
import { AsyncServerValue, ErrorValue, NonPrimitiveServerValue, PrimitiveValue } from '../types';
import { SerovalNode, SerovalReferenceNode } from './types';

@@ -8,4 +8,3 @@ export declare function getErrorConstructor(error: ErrorValue): "EvalError" | "RangeError" | "ReferenceError" | "SyntaxError" | "TypeError" | "URIError" | "Error";

export declare function isReferenceInStack(ctx: SerializationContext, node: SerovalNode): node is SerovalReferenceNode;
export declare function generateRef(ctx: ParserContext, current: unknown): number | SerovalReferenceNode;
export declare function generateSemiPrimitiveValue(ctx: ParserContext, current: unknown, id: number): SerovalNode | undefined;
export declare function generateSemiPrimitiveValue(ctx: ParserContext, current: NonPrimitiveServerValue<AsyncServerValue>, id: number): SerovalNode | undefined;
export declare function serializePrimitive(value: PrimitiveValue): string | number | null;
{
"name": "seroval",
"type": "module",
"version": "0.4.0-alpha.9",
"version": "0.4.0-alpha.10",
"files": [

@@ -67,3 +67,3 @@ "dist",

},
"gitHead": "27ff8d23e589e5968ebe968b14d050cd468ca49f"
"gitHead": "8b6be3d5d8a6860e0e5d0717b973fee5c94e07fb"
}

@@ -19,18 +19,15 @@ import { AsyncServerValue, PrimitiveValue } from './types';

export function constructorCheck<T extends NonNullable<AsyncServerValue>>(
value: unknown,
constructor: unknown,
): value is T {
return (value as { constructor: unknown }).constructor === constructor;
function isIterableBuiltin(obj: AsyncServerValue) {
if (!!obj && typeof obj === 'object') {
const cons = obj.constructor;
return (
Array.isArray(obj)
|| cons === Set
|| cons === Map
);
}
return false;
}
function isIterableBuiltin(obj: unknown) {
return (
Array.isArray(obj)
|| constructorCheck<Set<any>>(obj, Set)
|| constructorCheck<Map<any, any>>(obj, Map)
);
}
export function isIterable<T>(obj: unknown): obj is Iterable<T> {
export function isIterable(obj: AsyncServerValue): obj is Iterable<AsyncServerValue> {
return !!obj

@@ -37,0 +34,0 @@ && typeof obj === 'object'

@@ -8,5 +8,2 @@ /* eslint-disable guard-for-in */

*/
import assert from './assert';
export type Version = [major: number, minor: number, patch: number];

@@ -221,12 +218,32 @@

const TARGET_REGEX = /^(es|chrome|edge|safari|firefox|opera|ios|samsung|deno|node)([0-9]+(\.[0-9]+(\.[0-9]+)?)?)$/i;
const platforms: Platform[] = [
'chrome',
'deno',
'edge',
'es',
'firefox',
'ios',
'node',
'opera',
'safari',
'samsung',
];
export type Target = [platform: Platform, version: Version];
function getPlatform(target: string): Platform {
for (let i = 0, len = platforms.length; i < len; i++) {
const platform = target.substring(0, platforms[i].length);
if (platform === platforms[i]) {
return platform;
}
}
throw new Error(`Invalid target "${target}"`);
}
function parseTarget(target: string): Target {
const result = TARGET_REGEX.exec(target);
assert(result, `Invalid target "${target}"`);
const [, platform, version] = result;
const platform = getPlatform(target);
const version = target.substring(platform.length);
const [major, minor = '0', patch = '0'] = version.split('.');
return [platform as Platform, [Number(major), Number(minor), Number(patch)]];
return [platform, [Number(major), Number(minor), Number(patch)]];
}

@@ -237,4 +254,4 @@

const versions: Target[] = [];
for (const target of targets) {
versions.push(parseTarget(target));
for (let i = 0, len = targets.length; i < len; i++) {
versions.push(parseTarget(targets[i]));
}

@@ -250,3 +267,3 @@ return versions;

for (const key in VERSION_TABLE) {
for (const key of Object.keys(VERSION_TABLE)) {
const base = VERSION_TABLE[key as unknown as Feature];

@@ -253,0 +270,0 @@ let flag = true;

@@ -130,11 +130,20 @@ import { parseTargets } from './compat';

ctx: ParserContext,
index: unknown,
) {
const current = ctx.refs.get(index);
if (current != null) {
return current;
current: unknown,
mark: boolean,
): number {
// Check if reference number already exists
const ref = ctx.refs.get(current);
if (ref != null) {
// Exists, means this value is currently
// being referenced
// Mark reference
if (mark) {
markRef(ctx, ref);
}
return ref;
}
// Create a new reference ID
const id = ctx.refs.size;
ctx.refs.set(index, id);
ctx.refs.set(current, id);
return id;
}

@@ -7,3 +7,2 @@ /* eslint-disable no-await-in-loop */

isPrimitive,
constructorCheck,
isPromise,

@@ -15,3 +14,2 @@ } from '../checks';

import {
generateRef,
generateSemiPrimitiveValue,

@@ -37,3 +35,3 @@ getErrorConstructor,

ctx: ParserContext,
properties: Record<string, unknown>,
properties: Record<string, AsyncServerValue>,
): Promise<SerovalObjectRecordNode> {

@@ -51,7 +49,7 @@ const keys = Object.keys(properties);

deferredKeys[deferredSize] = key;
deferredValues[deferredSize] = properties[key] as AsyncServerValue;
deferredValues[deferredSize] = properties[key];
deferredSize++;
} else {
keyNodes[nodesSize] = key;
valueNodes[nodesSize] = await generateTreeAsync(ctx, properties[key] as AsyncServerValue);
valueNodes[nodesSize] = await generateTreeAsync(ctx, properties[key]);
nodesSize++;

@@ -250,3 +248,5 @@ }

// Parse options first before the items
d: options ? await serializePropertiesAsync(ctx, options) : undefined,
d: options
? await serializePropertiesAsync(ctx, options as Record<string, AsyncServerValue>)
: undefined,
a: await generateNodeList(ctx, Array.from(current)),

@@ -275,8 +275,60 @@ n: undefined,

}
if (typeof current === 'bigint') {
assert(ctx.features & Feature.BigInt, 'Unsupported type "BigInt"');
return {
t: SerovalNodeType.BigInt,
i: undefined,
a: undefined,
s: `${current}n`,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
// Non-primitive values needs a reference ID
// mostly because the values themselves are stateful
const id = generateRef(ctx, current);
if (typeof id !== 'number') {
return id;
const id = createRef(ctx, current, true);
if (ctx.markedRefs[id]) {
return {
t: SerovalNodeType.Reference,
i: id,
a: undefined,
s: undefined,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
if (Array.isArray(current)) {
return generateArrayNode(ctx, current, id);
}
const cs = current.constructor;
const empty = cs == null;
if (cs === Object || empty) {
if (Symbol.iterator in current) {
return generateIterableNode(ctx, current, id);
}
return {
t: empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,
i: id,
s: undefined,
l: undefined,
m: undefined,
c: undefined,
// Parse options first before the items
d: await serializePropertiesAsync(ctx, current as Record<string, AsyncServerValue>),
a: undefined,
n: undefined,
};
}
if (cs === Set) {
return generateSetNode(ctx, current as unknown as Set<AsyncServerValue>, id);
}
if (cs === Map) {
return generateMapNode(ctx, current as unknown as Map<AsyncServerValue, AsyncServerValue>, id);
}
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);

@@ -286,2 +338,5 @@ if (semiPrimitive) {

}
if (Symbol.iterator in current) {
return generateIterableNode(ctx, current, id);
}
if (isPromise(current)) {

@@ -302,11 +357,2 @@ assert(ctx.features & Feature.Promise, 'Unsupported type "Promise"');

}
if (constructorCheck<Set<AsyncServerValue>>(current, Set)) {
return generateSetNode(ctx, current, id);
}
if (constructorCheck<Map<AsyncServerValue, AsyncServerValue>>(current, Map)) {
return generateMapNode(ctx, current, id);
}
if (Array.isArray(current)) {
return generateArrayNode(ctx, current, id);
}
if (current instanceof AggregateError && ctx.features & Feature.AggregateError) {

@@ -318,20 +364,2 @@ return generateAggregateErrorNode(ctx, current, id);

}
if (isIterable(current)) {
return generateIterableNode(ctx, current, id);
}
const empty = current.constructor == null;
if (current.constructor === Object || empty) {
return {
t: empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,
i: id,
s: undefined,
l: undefined,
m: undefined,
c: undefined,
// Parse options first before the items
d: await serializePropertiesAsync(ctx, current as Record<string, unknown>),
a: undefined,
n: undefined,
};
}
throw new Error('Unsupported value');

@@ -345,3 +373,3 @@ }

const result = await generateTreeAsync(ctx, current);
return [result, createRef(ctx, current), result.t === SerovalNodeType.Object] as const;
return [result, createRef(ctx, current, false), result.t === SerovalNodeType.Object] as const;
}
import assert from '../assert';
import { constructorCheck } from '../checks';
import { Feature } from '../compat';
import { SerializationContext, ParserContext, markRef } from '../context';
import { SerializationContext, ParserContext } from '../context';
import quote from '../quote';
import { ErrorValue, PrimitiveValue } from '../types';
import {
AsyncServerValue,
ErrorValue,
NonPrimitiveServerValue,
PrimitiveValue,
} from '../types';
import { SerovalNode, SerovalReferenceNode, SerovalNodeType } from './types';

@@ -73,130 +77,84 @@

export function generateRef(
ctx: ParserContext,
current: unknown,
): number | SerovalReferenceNode {
// Check if reference number already exists
const ref = ctx.refs.has(current);
if (ref) {
// Exists, means this value is currently
// being referenced
const refID = ctx.refs.get(current) || 0;
// Mark reference
markRef(ctx, refID);
return {
t: SerovalNodeType.Reference,
i: refID,
a: undefined,
s: undefined,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
// Create a new reference ID
const id = ctx.refs.size;
ctx.refs.set(current, id);
return id;
}
export function generateSemiPrimitiveValue(
ctx: ParserContext,
current: unknown,
current: NonPrimitiveServerValue<AsyncServerValue>,
id: number,
): SerovalNode | undefined {
if (typeof current === 'bigint') {
assert(ctx.features & Feature.BigInt, 'Unsupported type "BigInt"');
return {
t: SerovalNodeType.BigInt,
i: undefined,
a: undefined,
s: `${current}n`,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
if (constructorCheck<Date>(current, Date)) {
return {
t: SerovalNodeType.Date,
i: id,
a: undefined,
s: current.toISOString(),
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
if (constructorCheck<RegExp>(current, RegExp)) {
return {
t: SerovalNodeType.RegExp,
i: id,
a: undefined,
s: String(current),
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
if (
constructorCheck<Int8Array>(current, Int8Array)
|| constructorCheck<Int16Array>(current, Int16Array)
|| constructorCheck<Int32Array>(current, Int32Array)
|| constructorCheck<Uint8Array>(current, Uint8Array)
|| constructorCheck<Uint16Array>(current, Uint16Array)
|| constructorCheck<Uint32Array>(current, Uint32Array)
|| constructorCheck<Uint8ClampedArray>(current, Uint8ClampedArray)
|| constructorCheck<Float32Array>(current, Float32Array)
|| constructorCheck<Float64Array>(current, Float64Array)
) {
const constructor = current.constructor.name;
assert(ctx.features & Feature.TypedArray, `Unsupported value type "${constructor}"`);
return {
t: SerovalNodeType.TypedArray,
i: id,
a: undefined,
s: current.toString(),
l: current.byteOffset,
m: undefined,
c: constructor,
d: undefined,
n: undefined,
};
}
if (
constructorCheck<BigInt64Array>(current, BigInt64Array)
|| constructorCheck<BigUint64Array>(current, BigUint64Array)
) {
const constructor = current.constructor.name;
assert(
ctx.features & (Feature.BigIntTypedArray),
`Unsupported value type "${constructor}"`,
);
let result = '';
const cap = current.length - 1;
for (let i = 0; i < cap; i++) {
result += `${current[i]}n,`;
const cs = current.constructor;
switch (cs) {
case Date:
return {
t: SerovalNodeType.Date,
i: id,
a: undefined,
s: (current as Date).toISOString(),
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
case RegExp:
return {
t: SerovalNodeType.RegExp,
i: id,
a: undefined,
s: String(current),
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
case Int8Array:
case Int16Array:
case Int32Array:
case Uint8Array:
case Uint16Array:
case Uint32Array:
case Uint8ClampedArray:
case Float32Array:
case Float64Array: {
const constructor = cs.name;
assert(ctx.features & Feature.TypedArray, `Unsupported value type "${constructor}"`);
return {
t: SerovalNodeType.TypedArray,
i: id,
a: undefined,
s: current.toString(),
l: (current as Int8Array).byteOffset,
m: undefined,
c: constructor,
d: undefined,
n: undefined,
};
}
result += `"${current[cap]}"`;
return {
t: SerovalNodeType.TypedArray,
i: id,
a: undefined,
s: result,
l: current.byteOffset,
m: undefined,
c: constructor,
d: undefined,
n: undefined,
};
case BigInt64Array:
case BigUint64Array: {
const constructor = cs.name;
assert(
ctx.features & (Feature.BigIntTypedArray),
`Unsupported value type "${constructor}"`,
);
let result = '';
const cap = (current as BigInt64Array).length - 1;
for (let i = 0; i < cap; i++) {
result += `${(current as BigInt64Array)[i]}n,`;
}
result += `"${(current as BigInt64Array)[cap]}"`;
return {
t: SerovalNodeType.TypedArray,
i: id,
a: undefined,
s: result,
l: (current as BigInt64Array).byteOffset,
m: undefined,
c: constructor,
d: undefined,
n: undefined,
};
}
default:
return undefined;
}
return undefined;
}

@@ -203,0 +161,0 @@

/* eslint-disable @typescript-eslint/no-use-before-define */
import assert from '../assert';
import { isIterable, isPrimitive, constructorCheck } from '../checks';
import { isIterable, isPrimitive } from '../checks';
import { Feature } from '../compat';

@@ -8,3 +8,2 @@ import { createRef, ParserContext } from '../context';

import {
generateRef,
generateSemiPrimitiveValue,

@@ -30,3 +29,3 @@ getErrorConstructor,

ctx: ParserContext,
properties: Record<string, unknown>,
properties: Record<string, ServerValue>,
): SerovalObjectRecordNode {

@@ -44,7 +43,7 @@ const keys = Object.keys(properties);

deferredKeys[deferredSize] = key;
deferredValues[deferredSize] = properties[key] as ServerValue;
deferredValues[deferredSize] = properties[key];
deferredSize++;
} else {
keyNodes[nodesSize] = key;
valueNodes[nodesSize] = generateTreeSync(ctx, properties[key] as ServerValue);
valueNodes[nodesSize] = generateTreeSync(ctx, properties[key]);
nodesSize++;

@@ -243,3 +242,5 @@ }

// Parse options first before the items
d: options ? serializePropertiesSync(ctx, options) : undefined,
d: options
? serializePropertiesSync(ctx, options as Record<string, ServerValue>)
: undefined,
a: generateNodeList(ctx, Array.from(current)),

@@ -268,32 +269,41 @@ n: undefined,

}
if (typeof current === 'bigint') {
assert(ctx.features & Feature.BigInt, 'Unsupported type "BigInt"');
return {
t: SerovalNodeType.BigInt,
i: undefined,
a: undefined,
s: `${current}n`,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
// Non-primitive values needs a reference ID
// mostly because the values themselves are stateful
const id = generateRef(ctx, current);
if (typeof id !== 'number') {
return id;
const id = createRef(ctx, current, true);
if (ctx.markedRefs[id]) {
return {
t: SerovalNodeType.Reference,
i: id,
a: undefined,
s: undefined,
l: undefined,
m: undefined,
c: undefined,
d: undefined,
n: undefined,
};
}
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
if (semiPrimitive) {
return semiPrimitive;
}
if (constructorCheck<Set<ServerValue>>(current, Set)) {
return generateSetNode(ctx, current, id);
}
if (constructorCheck<Map<ServerValue, ServerValue>>(current, Map)) {
return generateMapNode(ctx, current, id);
}
if (Array.isArray(current)) {
return generateArrayNode(ctx, current, id);
}
if (current instanceof AggregateError && ctx.features & Feature.AggregateError) {
return generateAggregateErrorNode(ctx, current, id);
}
if (current instanceof Error) {
return generateErrorNode(ctx, current, id);
}
if (isIterable(current)) {
return generateIterableNode(ctx, current, id);
}
const empty = current.constructor == null;
if (current.constructor === Object || empty) {
const cs = current.constructor;
const empty = cs == null;
if (cs === Object || empty) {
if (Symbol.iterator in current) {
return generateIterableNode(ctx, current, id);
}
return {

@@ -307,3 +317,3 @@ t: empty ? SerovalNodeType.NullConstructor : SerovalNodeType.Object,

// Parse options first before the items
d: serializePropertiesSync(ctx, current as Record<string, unknown>),
d: serializePropertiesSync(ctx, current as Record<string, ServerValue>),
a: undefined,

@@ -313,2 +323,21 @@ n: undefined,

}
if (cs === Set) {
return generateSetNode(ctx, current as Set<ServerValue>, id);
}
if (cs === Map) {
return generateMapNode(ctx, current as Map<ServerValue, ServerValue>, id);
}
const semiPrimitive = generateSemiPrimitiveValue(ctx, current, id);
if (semiPrimitive) {
return semiPrimitive;
}
if (Symbol.iterator in current) {
return generateIterableNode(ctx, current, id);
}
if (current instanceof AggregateError && ctx.features & Feature.AggregateError) {
return generateAggregateErrorNode(ctx, current, id);
}
if (current instanceof Error) {
return generateErrorNode(ctx, current, id);
}
throw new Error('Unsupported value');

@@ -322,3 +351,3 @@ }

const result = generateTreeSync(ctx, current);
return [result, createRef(ctx, current), result.t === SerovalNodeType.Object] as const;
return [result, createRef(ctx, current, false), result.t === SerovalNodeType.Object] as const;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc