Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xyo-network/serialization

Package Overview
Dependencies
Maintainers
6
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xyo-network/serialization - npm Package Compare versions

Comparing version 0.34.0 to 0.35.0

2

dist/@types/index.d.ts

@@ -54,2 +54,3 @@ /// <reference types="node" />

export interface IXyoSerializableObject {
origin: Buffer | undefined;
schemaObjectId: number;

@@ -63,2 +64,3 @@ srcBuffer: Buffer | null;

isEqual(other: IXyoSerializableObject): boolean;
realSchema(): IXyoObjectPartialSchema;
}

@@ -65,0 +67,0 @@ export interface IXyoDeserializer<T extends IXyoSerializableObject> {

8

dist/helpers/base-serializable.d.ts
/// <reference types="node" />
import { IXyoSerializableObject, IXyoObjectSchema } from "../@types";
import { IXyoSerializableObject, IXyoObjectSchema, IXyoObjectPartialSchema } from "../@types";
import { XyoBase } from "@xyo-network/base";

@@ -8,3 +8,4 @@ export declare abstract class XyoBaseSerializable extends XyoBase implements IXyoSerializableObject {

srcBuffer: Buffer | null;
constructor(schema: IXyoObjectSchema);
origin: Buffer | undefined;
constructor(schema: IXyoObjectSchema, origin?: Buffer);
getReadableName(): string;

@@ -16,4 +17,7 @@ abstract getReadableValue(): any;

isEqual(other: IXyoSerializableObject): boolean;
readSelfSchema(): IXyoObjectPartialSchema | undefined;
realSchema(): IXyoObjectPartialSchema;
protected serializablesToBuffer(serializables: IXyoSerializableObject[]): Buffer;
private findSchemaById;
}
//# sourceMappingURL=base-serializable.d.ts.map

@@ -17,7 +17,9 @@ "use strict";

const findSchemaById_1 = require("./findSchemaById");
const readHeader_1 = require("./readHeader");
class XyoBaseSerializable extends base_1.XyoBase {
constructor(schema) {
constructor(schema, origin) {
super();
this.schema = schema;
this.srcBuffer = null;
this.origin = origin;
}

@@ -34,9 +36,9 @@ getReadableName() {

if (result instanceof Buffer) {
return serialize_1.serialize(result, findSchemaById_1.findSchemaById(this.schemaObjectId, this.schema));
return serialize_1.serialize(result, this.findSchemaById(this.schemaObjectId, this.schema));
}
if (Array.isArray(result)) {
const serializationResult = this.serializablesToBuffer(result);
return serialize_1.serialize(serializationResult, findSchemaById_1.findSchemaById(this.schemaObjectId, this.schema));
return serialize_1.serialize(serializationResult, this.findSchemaById(this.schemaObjectId, this.schema));
}
return serialize_1.serialize(result.serialize(), findSchemaById_1.findSchemaById(this.schemaObjectId, this.schema));
return serialize_1.serialize(result.serialize(), this.findSchemaById(this.schemaObjectId, this.schema));
})();

@@ -52,7 +54,26 @@ this.srcBuffer = serialized;

}
readSelfSchema() {
if (this.origin) {
return readHeader_1.readHeader(this.origin);
}
return undefined;
}
realSchema() {
return this.findSchemaById(this.schemaObjectId, this.schema);
}
serializablesToBuffer(serializables) {
return resolveSerializablesToBuffer_1.resolveSerializablesToBuffer(this.schemaObjectId, this.schema, serializables);
if (this.origin) {
return this.origin;
}
return resolveSerializablesToBuffer_1.resolveSerializablesToBuffer(this.findSchemaById(this.schemaObjectId, this.schema), this.schema, serializables);
}
findSchemaById(id, schema) {
const selfSchema = this.readSelfSchema();
if (selfSchema) {
return selfSchema;
}
return findSchemaById_1.findSchemaById(id, schema);
}
}
exports.XyoBaseSerializable = XyoBaseSerializable;
//# sourceMappingURL=base-serializable.js.map
/// <reference types="node" />
import { IXyoObjectSchema, IXyoSerializableObject } from "../@types";
export declare function resolveSerializablesToBuffer(schemaId: number, objectSchema: IXyoObjectSchema, serializables: IXyoSerializableObject[]): Buffer;
import { IXyoObjectSchema, IXyoSerializableObject, IXyoObjectPartialSchema } from "../@types";
export declare function resolveSerializablesToBuffer(schema: IXyoObjectPartialSchema, objectSchema: IXyoObjectSchema, serializables: IXyoSerializableObject[]): Buffer;
//# sourceMappingURL=resolveSerializablesToBuffer.d.ts.map

@@ -13,3 +13,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const findSchemaById_1 = require("./findSchemaById");
const errors_1 = require("@xyo-network/errors");

@@ -19,9 +18,8 @@ const getHeader_1 = require("./getHeader");

const getSizeHeader_1 = require("./getSizeHeader");
function resolveSerializablesToBuffer(schemaId, objectSchema, serializables) {
function resolveSerializablesToBuffer(schema, objectSchema, serializables) {
if (serializables.length === 0) {
return Buffer.alloc(0);
}
const partialSchema = findSchemaById_1.findSchemaById(schemaId, objectSchema);
if (partialSchema.iterableType === 'not-iterable') {
throw new errors_1.XyoError(`Incorrect schema iterable type for ${schemaId}`);
if (schema.iterableType === 'not-iterable') {
throw new errors_1.XyoError(`Incorrect schema iterable type for ${schema.id}`, errors_1.XyoErrors.CRITICAL);
}

@@ -41,4 +39,4 @@ const serializablesById = {};

if (numberOfSerializerTypes > 1) {
if (partialSchema.iterableType === 'iterable-typed') {
throw new errors_1.XyoError(`Incorrect schema iterable type for ${schemaId}`);
if (schema.iterableType === 'iterable-typed') {
throw new errors_1.XyoError(`Incorrect schema iterable type for ${schema.id}`, errors_1.XyoErrors.CRITICAL);
}

@@ -48,3 +46,3 @@ arraySerializationType = 'iterable-untyped';

else { // numberOfSerializerTypes === 1
arraySerializationType = partialSchema.iterableType || 'iterable-typed';
arraySerializationType = schema.iterableType || 'iterable-typed';
}

@@ -57,3 +55,3 @@ let highestByteAmount = 0;

bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: result

@@ -67,3 +65,3 @@ });

bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: resultBuffer

@@ -73,6 +71,7 @@ });

}
const resolveBuffer = resolveSerializablesToBuffer(serializable.schemaObjectId, objectSchema, result);
const schemaOfSub = serializable.realSchema();
const resolveBuffer = resolveSerializablesToBuffer(schemaOfSub, objectSchema, result);
highestByteAmount = Math.max(resolveBuffer.length, highestByteAmount);
bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: resolveBuffer

@@ -90,3 +89,3 @@ });

}, []);
const innerSchema = findSchemaById_1.findSchemaById(components[0].id, objectSchema);
const innerSchema = components[0].schema;
return Buffer.concat([

@@ -103,3 +102,3 @@ getHeader_1.getHeader(highestByteAmount, {

const componentsWithHeaders = components.reduce((collection, component) => {
const innerSchema = findSchemaById_1.findSchemaById(component.id, objectSchema);
const innerSchema = component.schema;
const componentHeader = getHeader_1.getHeader(component.buffer.length, {

@@ -106,0 +105,0 @@ id: innerSchema.id,

@@ -17,3 +17,2 @@ "use strict";

const serialize_1 = require("./helpers/serialize");
const findSchemaById_1 = require("./helpers/findSchemaById");
const readHeader_1 = require("./helpers/readHeader");

@@ -33,4 +32,4 @@ const parse_1 = require("./helpers/parse");

result :
resolveSerializablesToBuffer_1.resolveSerializablesToBuffer(serializable.schemaObjectId, this.schema, result);
const b = serialize_1.serialize(buf, findSchemaById_1.findSchemaById(serializable.schemaObjectId, this.schema));
resolveSerializablesToBuffer_1.resolveSerializablesToBuffer(serializable.realSchema(), this.schema, result);
const b = serialize_1.serialize(buf, serializable.realSchema());
if (serializationType === 'hex') {

@@ -37,0 +36,0 @@ return b.toString('hex');

{
"name": "@xyo-network/serialization",
"version": "0.34.0",
"version": "0.35.0",
"description": "Serialization services in the xyo network",

@@ -10,4 +10,4 @@ "main": "dist/index.js",

"dependencies": {
"@xyo-network/base": "^0.34.0",
"@xyo-network/errors": "^0.34.0",
"@xyo-network/base": "^0.35.0",
"@xyo-network/errors": "^0.35.0",
"bn.js": "^4.11.8"

@@ -25,3 +25,3 @@ },

},
"gitHead": "b29cd20d3043a5788a0249191221a8916bc61d1f"
"gitHead": "1419347e15c9672dbc53e4f48e81d41ddf0cf468"
}

@@ -83,2 +83,3 @@ /*

export interface IXyoSerializableObject {
origin: Buffer | undefined
schemaObjectId: number

@@ -92,2 +93,3 @@ srcBuffer: Buffer | null

isEqual(other: IXyoSerializableObject): boolean
realSchema (): IXyoObjectPartialSchema
}

@@ -94,0 +96,0 @@

@@ -12,3 +12,3 @@ /*

import { IXyoSerializableObject, IXyoObjectSchema } from "../@types"
import { IXyoSerializableObject, IXyoObjectSchema, IXyoObjectPartialSchema, IParseResult } from "../@types"
import { XyoBase } from "@xyo-network/base"

@@ -18,2 +18,3 @@ import { resolveSerializablesToBuffer } from "./resolveSerializablesToBuffer"

import { findSchemaById } from "./findSchemaById"
import { readHeader } from './readHeader'

@@ -24,5 +25,8 @@ export abstract class XyoBaseSerializable extends XyoBase implements IXyoSerializableObject {

public srcBuffer: Buffer | null = null
public origin: Buffer | undefined
constructor(private readonly schema: IXyoObjectSchema) {
constructor(private readonly schema: IXyoObjectSchema, origin?: Buffer) {
super()
this.origin = origin
}

@@ -50,3 +54,3 @@

result,
findSchemaById(this.schemaObjectId, this.schema)
this.findSchemaById(this.schemaObjectId, this.schema)
)

@@ -57,3 +61,3 @@ }

const serializationResult = this.serializablesToBuffer(result)
return serialize(serializationResult, findSchemaById(this.schemaObjectId, this.schema))
return serialize(serializationResult, this.findSchemaById(this.schemaObjectId, this.schema))
}

@@ -63,3 +67,3 @@

result.serialize(),
findSchemaById(this.schemaObjectId, this.schema)
this.findSchemaById(this.schemaObjectId, this.schema)
)

@@ -80,5 +84,21 @@ })()

public readSelfSchema (): IXyoObjectPartialSchema | undefined {
if (this.origin) {
return readHeader(this.origin)
}
return undefined
}
public realSchema (): IXyoObjectPartialSchema {
return this.findSchemaById(this.schemaObjectId, this.schema)
}
protected serializablesToBuffer(serializables: IXyoSerializableObject[]) {
if (this.origin) {
return this.origin
}
return resolveSerializablesToBuffer(
this.schemaObjectId,
this.findSchemaById(this.schemaObjectId, this.schema),
this.schema,

@@ -88,2 +108,12 @@ serializables

}
private findSchemaById (id: number, schema: IXyoObjectSchema): IXyoObjectPartialSchema {
const selfSchema = this.readSelfSchema()
if (selfSchema) {
return selfSchema
}
return findSchemaById(id, schema)
}
}

@@ -16,3 +16,2 @@ /*

export class XyoOnTheFlySerializable extends XyoBaseSerializable {
constructor (

@@ -19,0 +18,0 @@ schema: IXyoObjectSchema,

@@ -12,4 +12,3 @@ /*

import { IXyoObjectSchema, IXyoSerializableObject, IIterableType } from "../@types"
import { findSchemaById } from "./findSchemaById"
import { IXyoObjectSchema, IXyoSerializableObject, IIterableType, IXyoObjectPartialSchema } from "../@types"
import { XyoError, XyoErrors } from "@xyo-network/errors"

@@ -19,5 +18,6 @@ import { getHeader } from "./getHeader"

import { getSizeHeader } from "./getSizeHeader"
import { readHeader } from "./readHeader"
export function resolveSerializablesToBuffer(
schemaId: number,
schema: IXyoObjectPartialSchema,
objectSchema: IXyoObjectSchema,

@@ -30,5 +30,4 @@ serializables: IXyoSerializableObject[]): Buffer {

const partialSchema = findSchemaById(schemaId, objectSchema)
if (partialSchema.iterableType === 'not-iterable') {
throw new XyoError(`Incorrect schema iterable type for ${schemaId}`)
if (schema.iterableType === 'not-iterable') {
throw new XyoError(`Incorrect schema iterable type for ${schema.id}`, XyoErrors.CRITICAL)
}

@@ -53,8 +52,9 @@

if (numberOfSerializerTypes > 1) {
if (partialSchema.iterableType === 'iterable-typed') {
throw new XyoError(`Incorrect schema iterable type for ${schemaId}`)
if (schema.iterableType === 'iterable-typed') {
throw new XyoError(`Incorrect schema iterable type for ${schema.id}`, XyoErrors.CRITICAL)
}
arraySerializationType = 'iterable-untyped'
} else { // numberOfSerializerTypes === 1
arraySerializationType = partialSchema.iterableType || 'iterable-typed'
arraySerializationType = schema.iterableType || 'iterable-typed'
}

@@ -65,6 +65,8 @@

const result = serializable.getData()
if (result instanceof Buffer) {
highestByteAmount = Math.max(result.length, highestByteAmount)
bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: result

@@ -79,3 +81,3 @@ })

bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: resultBuffer

@@ -86,6 +88,8 @@ })

const resolveBuffer = resolveSerializablesToBuffer(serializable.schemaObjectId, objectSchema, result)
const schemaOfSub = serializable.realSchema()
const resolveBuffer = resolveSerializablesToBuffer(schemaOfSub, objectSchema, result)
highestByteAmount = Math.max(resolveBuffer.length, highestByteAmount)
bufferCollection.push({
id: serializable.schemaObjectId,
schema: serializable.realSchema(),
buffer: resolveBuffer

@@ -105,3 +109,3 @@ })

}, [] as Buffer[])
const innerSchema = findSchemaById(components[0].id, objectSchema)
const innerSchema = components[0].schema
return Buffer.concat([

@@ -123,3 +127,3 @@ getHeader(

const componentsWithHeaders = components.reduce((collection, component) => {
const innerSchema = findSchemaById(component.id, objectSchema)
const innerSchema = component.schema
const componentHeader = getHeader(

@@ -142,4 +146,4 @@ component.buffer.length,

interface IBufferIdPair {
id: number
schema: IXyoObjectPartialSchema
buffer: Buffer
}

@@ -13,3 +13,3 @@ /*

import { XyoBaseSerializable } from './base-serializable'
import { IXyoSerializableObject, IParseResult, IXyoSerializationService, IXyoObjectSchema } from '../@types'
import { IXyoSerializableObject, IParseResult, IXyoSerializationService, IXyoObjectSchema, IXyoObjectPartialSchema } from '../@types'
import { ParseQuery } from './parse-query'

@@ -25,2 +25,3 @@

super(serializationService.schema)
}

@@ -27,0 +28,0 @@

@@ -15,2 +15,3 @@ /*

import { XyoBaseSerializable } from '../helpers/base-serializable'
import { findSchemaById } from '../helpers/findSchemaById'

@@ -33,3 +34,3 @@ describe(`Serialization`, () => {

const xCollection = new XCollection(schema, [new X(schema, 1)])
const result = resolveSerializablesToBuffer(2, schema, xCollection.getData())
const result = resolveSerializablesToBuffer(findSchemaById(2, schema), schema, xCollection.getData())

@@ -58,3 +59,3 @@ expect(Buffer.from([

const xCollection = new XCollection(schema, [new X(schema, 1), new X(schema, 256), new X(schema, 65536)])
const result = resolveSerializablesToBuffer(2, schema, xCollection.getData())
const result = resolveSerializablesToBuffer(findSchemaById(2, schema), schema, xCollection.getData())

@@ -94,3 +95,3 @@ expect(Buffer.from([

const xCollection = new XCollection(schema, [new X(schema, 1)])
const result = resolveSerializablesToBuffer(2, schema, xCollection.getData())
const result = resolveSerializablesToBuffer(findSchemaById(2, schema), schema, xCollection.getData())

@@ -119,3 +120,3 @@ expect(Buffer.from([

const xCollection = new XCollection(schema, [new X(schema, 1), new X(schema, 2)])
const result = resolveSerializablesToBuffer(2, schema, xCollection.getData())
const result = resolveSerializablesToBuffer(findSchemaById(2, schema), schema, xCollection.getData())

@@ -146,3 +147,3 @@ expect(Buffer.from([

const xCollection = new XCollection(schema, [new X(schema, 1), new X(schema, 2)])
const result = resolveSerializablesToBuffer(2, schema, xCollection.getData())
const result = resolveSerializablesToBuffer(findSchemaById(2, schema), schema, xCollection.getData())

@@ -180,3 +181,3 @@ expect(Buffer.from([

const xCollectionSet = new XCollectionSet(schema, [])
const result = resolveSerializablesToBuffer(3, schema, xCollectionSet.getData())
const result = resolveSerializablesToBuffer(findSchemaById(3, schema), schema, xCollectionSet.getData())

@@ -206,3 +207,3 @@ expect(Buffer.from([]).equals(result)).toBe(true)

const xCollectionSet = new XCollectionSet(schema, [xCollection])
const result = resolveSerializablesToBuffer(3, schema, xCollectionSet.getData())
const result = resolveSerializablesToBuffer(findSchemaById(3, schema), schema, xCollectionSet.getData())

@@ -244,3 +245,3 @@ expect(Buffer.from([

const xCollectionSet = new XCollectionSet(schema, [xCollection])
const result = resolveSerializablesToBuffer(3, schema, xCollectionSet.getData())
const result = resolveSerializablesToBuffer(findSchemaById(3, schema), schema, xCollectionSet.getData())

@@ -247,0 +248,0 @@ expect(Buffer.from([

@@ -40,5 +40,5 @@ /*

result :
resolveSerializablesToBuffer(serializable.schemaObjectId, this.schema, result)
resolveSerializablesToBuffer(serializable.realSchema(), this.schema, result)
const b = serialize(buf, findSchemaById(serializable.schemaObjectId, this.schema))
const b = serialize(buf, serializable.realSchema())
if (serializationType === 'hex') {

@@ -45,0 +45,0 @@ return b.toString('hex')

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

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