Socket
Socket
Sign inDemoInstall

@xyo-network/serialization

Package Overview
Dependencies
Maintainers
4
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.5.0 to 0.6.0

6

dist/helpers/base-serializable.d.ts
/// <reference types="node" />
import { IXyoSerializableObject, IXyoSerializationService, IXyoObjectSchema } from "../@types";
import { IXyoSerializableObject, IXyoObjectSchema } from "../@types";
import { XyoBase } from "@xyo-network/base";
export declare abstract class XyoBaseSerializable extends XyoBase implements IXyoSerializableObject {
readonly schema: IXyoObjectSchema;
static serializationService: IXyoSerializationService;
private readonly schema;
abstract schemaObjectId: number;
srcBuffer: Buffer | null;
constructor(schema: IXyoObjectSchema);
abstract getData(): Buffer | IXyoSerializableObject | IXyoSerializableObject[];

@@ -10,0 +10,0 @@ serialize(): Buffer;

@@ -8,3 +8,3 @@ "use strict";

* @Last modified by: ryanxyo
* @Last modified time: Monday, 10th December 2018 5:10:28 pm
* @Last modified time: Wednesday, 12th December 2018 10:58:12 am
* @License: All Rights Reserved

@@ -20,9 +20,7 @@ * @Copyright: Copyright XY | The Findables Company

class XyoBaseSerializable extends base_1.XyoBase {
constructor() {
super(...arguments);
constructor(schema) {
super();
this.schema = schema;
this.srcBuffer = null;
}
get schema() {
return (XyoBaseSerializable.serializationService && XyoBaseSerializable.serializationService.schema) || undefined;
}
serialize() {

@@ -29,0 +27,0 @@ if (this.srcBuffer) {

/// <reference types="node" />
import { XyoBaseSerializable } from "./base-serializable";
import { IXyoSerializableObject, IOnTheFlyGetDataOptions } from "../@types";
import { IXyoSerializableObject, IOnTheFlyGetDataOptions, IXyoObjectSchema } from "../@types";
export declare class XyoOnTheFlySerializable extends XyoBaseSerializable {
readonly schemaObjectId: number;
private readonly dataOptions;
constructor(schemaObjectId: number, dataOptions: IOnTheFlyGetDataOptions);
constructor(schema: IXyoObjectSchema, schemaObjectId: number, dataOptions: IOnTheFlyGetDataOptions);
getData(): Buffer | IXyoSerializableObject | IXyoSerializableObject[];
}
//# sourceMappingURL=on-the-fly-serializable.d.ts.map

@@ -9,3 +9,3 @@ "use strict";

* @Last modified by: ryanxyo
* @Last modified time: Thursday, 6th December 2018 11:32:59 am
* @Last modified time: Wednesday, 12th December 2018 10:59:24 am
* @License: All Rights Reserved

@@ -17,4 +17,4 @@ * @Copyright: Copyright XY | The Findables Company

class XyoOnTheFlySerializable extends base_serializable_1.XyoBaseSerializable {
constructor(schemaObjectId, dataOptions) {
super();
constructor(schema, schemaObjectId, dataOptions) {
super(schema);
this.schemaObjectId = schemaObjectId;

@@ -21,0 +21,0 @@ this.dataOptions = dataOptions;

/// <reference types="node" />
import { IParseResult } from "../@types";
export declare function parse(src: Buffer): IParseResult;
import { IParseResult, IXyoObjectSchema } from "../@types";
export declare function parse(src: Buffer, schema: IXyoObjectSchema): IParseResult;
//# sourceMappingURL=parse.d.ts.map

@@ -8,3 +8,3 @@ "use strict";

* @Last modified by: ryanxyo
* @Last modified time: Friday, 7th December 2018 11:51:32 am
* @Last modified time: Wednesday, 12th December 2018 11:00:53 am
* @License: All Rights Reserved

@@ -17,3 +17,3 @@ * @Copyright: Copyright XY | The Findables Company

const on_the_fly_serializable_1 = require("./on-the-fly-serializable");
function parse(src) {
function parse(src, schema) {
const partialSchema = readHeader_1.readHeader(src);

@@ -31,3 +31,3 @@ const data = sliceItem_1.sliceItem(src, 0, partialSchema, true);

toSerializable: () => {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(partialSchema.id, {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

@@ -47,3 +47,3 @@ });

toSerializable: () => {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(partialSchema.id, {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

@@ -74,3 +74,3 @@ });

if (innerHeader.iterableType !== 'not-iterable') {
items.push(parse(Buffer.concat([innerHeaderBytes, sizeBytes, bytes])));
items.push(parse(Buffer.concat([innerHeaderBytes, sizeBytes, bytes]), schema));
}

@@ -86,3 +86,3 @@ else {

toSerializable: () => {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(innerHeader.id, {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(schema, innerHeader.id, {
buffer: bytes

@@ -102,3 +102,3 @@ });

toSerializable: () => {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(partialSchema.id, {
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

@@ -105,0 +105,0 @@ });

/// <reference types="node" />
import { XyoBaseSerializable } from './base-serializable';
import { IXyoSerializableObject, IParseResult } from '../@types';
import { IXyoSerializableObject, IParseResult, IXyoSerializationService, IXyoObjectSchema } from '../@types';
import { ParseQuery } from './parse-query';
export declare class XyoTreeIterator extends XyoBaseSerializable implements IXyoSerializableObject {
private readonly parseResult;
constructor(parseResult: IParseResult);
constructor(schema: IXyoObjectSchema, parseResult: IParseResult);
readonly schemaObjectId: number;
getData(): Buffer;
query(): ParseQuery;
hydrate<T extends IXyoSerializableObject>(): T;
hydrate<T extends IXyoSerializableObject>(serializationService: IXyoSerializationService): T;
}
//# sourceMappingURL=tree-iterator.d.ts.map

@@ -8,3 +8,3 @@ "use strict";

* @Last modified by: ryanxyo
* @Last modified time: Thursday, 6th December 2018 6:04:18 pm
* @Last modified time: Wednesday, 12th December 2018 11:01:51 am
* @License: All Rights Reserved

@@ -17,4 +17,4 @@ * @Copyright: Copyright XY | The Findables Company

class XyoTreeIterator extends base_serializable_1.XyoBaseSerializable {
constructor(parseResult) {
super();
constructor(schema, parseResult) {
super(schema);
this.parseResult = parseResult;

@@ -31,4 +31,4 @@ }

}
hydrate() {
return base_serializable_1.XyoBaseSerializable.serializationService.hydrate(this.parseResult);
hydrate(serializationService) {
return serializationService.hydrate(this.parseResult);
}

@@ -35,0 +35,0 @@ }

@@ -8,3 +8,3 @@ "use strict";

* @Last modified by: ryanxyo
* @Last modified time: Monday, 10th December 2018 5:13:43 pm
* @Last modified time: Wednesday, 12th December 2018 11:03:10 am
* @License: All Rights Reserved

@@ -48,4 +48,4 @@ * @Copyright: Copyright XY | The Findables Company

const src = deserializable instanceof Buffer ? deserializable : Buffer.from(deserializable, 'hex');
const parseResult = parse_1.parse(src);
return new tree_iterator_1.XyoTreeIterator(parseResult);
const parseResult = parse_1.parse(src, this.schema);
return new tree_iterator_1.XyoTreeIterator(this.schema, parseResult);
}

@@ -85,3 +85,3 @@ hydrate(deserializable) {

}
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(this.schema.typedSet.id, options);
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(this.schema, this.schema.typedSet.id, options);
}

@@ -96,3 +96,3 @@ untypedArrayOf(tCollection) {

}
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(this.schema.untypedSet.id, options);
return new on_the_fly_serializable_1.XyoOnTheFlySerializable(this.schema, this.schema.untypedSet.id, options);
}

@@ -99,0 +99,0 @@ findFirstElement(collection, schemaObjectId) {

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

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

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

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

},
"gitHead": "599cd70f6ec81a60314d6f855a8735f5fdb08c99"
"gitHead": "cbb5c5c20b4f081ebbd619dbdbd2ddace174db34"
}

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Monday, 10th December 2018 5:10:28 pm
* @Last modified time: Wednesday, 12th December 2018 10:58:12 am
* @License: All Rights Reserved

@@ -13,3 +13,3 @@ * @Copyright: Copyright XY | The Findables Company

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

@@ -23,8 +23,2 @@ import { resolveSerializablesToBuffer } from "./resolveSerializablesToBuffer"

public get schema(): IXyoObjectSchema {
return (XyoBaseSerializable.serializationService && XyoBaseSerializable.serializationService.schema) || undefined
}
public static serializationService: IXyoSerializationService
public abstract schemaObjectId: number

@@ -34,2 +28,6 @@

constructor(private readonly schema: IXyoObjectSchema) {
super()
}
// tslint:disable-next-line:max-line-length

@@ -36,0 +34,0 @@ public abstract getData(): Buffer | IXyoSerializableObject | IXyoSerializableObject[]

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Thursday, 6th December 2018 11:32:59 am
* @Last modified time: Wednesday, 12th December 2018 10:59:24 am
* @License: All Rights Reserved

@@ -13,3 +13,3 @@ * @Copyright: Copyright XY | The Findables Company

import { XyoBaseSerializable } from "./base-serializable"
import { IXyoSerializableObject, IOnTheFlyGetDataOptions } from "../@types"
import { IXyoSerializableObject, IOnTheFlyGetDataOptions, IXyoObjectSchema } from "../@types"
import { XyoError, XyoErrors } from "@xyo-network/errors"

@@ -20,6 +20,7 @@

constructor (
schema: IXyoObjectSchema,
public readonly schemaObjectId: number,
private readonly dataOptions: IOnTheFlyGetDataOptions
) {
super()
super(schema)
}

@@ -26,0 +27,0 @@

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Friday, 7th December 2018 11:51:32 am
* @Last modified time: Wednesday, 12th December 2018 11:00:53 am
* @License: All Rights Reserved

@@ -15,6 +15,6 @@ * @Copyright: Copyright XY | The Findables Company

import { sliceItem } from "./sliceItem"
import { IParseResult } from "../@types"
import { IParseResult, IXyoObjectSchema } from "../@types"
import { XyoOnTheFlySerializable } from "./on-the-fly-serializable"
export function parse(src: Buffer): IParseResult {
export function parse(src: Buffer, schema: IXyoObjectSchema): IParseResult {
const partialSchema = readHeader(src)

@@ -32,3 +32,3 @@ const data = sliceItem(src, 0, partialSchema, true)

toSerializable: () => {
return new XyoOnTheFlySerializable(partialSchema.id, {
return new XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

@@ -49,3 +49,3 @@ })

toSerializable: () => {
return new XyoOnTheFlySerializable(partialSchema.id, {
return new XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

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

if (innerHeader.iterableType !== 'not-iterable') {
items.push(parse(Buffer.concat([innerHeaderBytes, sizeBytes, bytes])))
items.push(parse(Buffer.concat([innerHeaderBytes, sizeBytes, bytes]), schema))
} else {

@@ -92,3 +92,3 @@ items.push({

toSerializable: () => {
return new XyoOnTheFlySerializable(innerHeader.id, {
return new XyoOnTheFlySerializable(schema, innerHeader.id, {
buffer: bytes

@@ -110,3 +110,3 @@ })

toSerializable: () => {
return new XyoOnTheFlySerializable(partialSchema.id, {
return new XyoOnTheFlySerializable(schema, partialSchema.id, {
buffer: data

@@ -113,0 +113,0 @@ })

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Thursday, 6th December 2018 6:04:18 pm
* @Last modified time: Wednesday, 12th December 2018 11:01:51 am
* @License: All Rights Reserved

@@ -14,3 +14,3 @@ * @Copyright: Copyright XY | The Findables Company

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

@@ -20,4 +20,4 @@

constructor (private readonly parseResult: IParseResult) {
super()
constructor (schema: IXyoObjectSchema, private readonly parseResult: IParseResult) {
super(schema)
}

@@ -37,5 +37,5 @@

public hydrate<T extends IXyoSerializableObject>(): T {
return XyoBaseSerializable.serializationService.hydrate<T>(this.parseResult) as T
public hydrate<T extends IXyoSerializableObject>(serializationService: IXyoSerializationService): T {
return serializationService.hydrate<T>(this.parseResult) as T
}
}

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Friday, 7th December 2018 11:41:24 am
* @Last modified time: Wednesday, 12th December 2018 11:16:10 am
* @License: All Rights Reserved

@@ -26,3 +26,3 @@ * @Copyright: Copyright XY | The Findables Company

const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -49,3 +49,3 @@ throw new Error(`Result should be defined`)

const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -78,3 +78,3 @@ throw new Error(`Result should be defined`)

const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -111,3 +111,3 @@ throw new Error(`Result should be defined`)

const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -160,3 +160,3 @@ throw new Error(`Result should be defined`)

const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -211,3 +211,3 @@ throw new Error(`Result should be defined`)

])
const result = parse(src)
const result = parse(src, {})
if (!result) {

@@ -214,0 +214,0 @@ throw new Error(`Result should be defined`)

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Tuesday, 11th December 2018 9:03:54 am
* @Last modified time: Wednesday, 12th December 2018 11:14:43 am
* @License: All Rights Reserved

@@ -14,3 +14,3 @@ * @Copyright: Copyright XY | The Findables Company

import { resolveSerializablesToBuffer } from '../helpers/resolveSerializablesToBuffer'
import { IXyoSerializableObject } from '../@types'
import { IXyoSerializableObject, IXyoObjectSchema } from '../@types'
import { XyoBaseSerializable } from '../helpers/base-serializable'

@@ -21,4 +21,3 @@

it(`Should serialize typed simple collection`, () => {
const xCollection = new XCollection([new X(1)])
const result = resolveSerializablesToBuffer(2, {
const schema: IXyoObjectSchema = {
x: {

@@ -34,3 +33,5 @@ id: 1,

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

@@ -46,4 +47,3 @@ expect(Buffer.from([

it(`Should serialize typed simple collection using high watermark for size encoding`, () => {
const xCollection = new XCollection([new X(1), new X(256), new X(65536)])
const result = resolveSerializablesToBuffer(2, {
const schema: IXyoObjectSchema = {
x: {

@@ -59,3 +59,5 @@ id: 1,

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

@@ -82,4 +84,3 @@ expect(Buffer.from([

it(`Should serialize untyped simple collection`, () => {
const xCollection = new XCollection([new X(1)])
const result = resolveSerializablesToBuffer(2, {
const schema: IXyoObjectSchema = {
x: {

@@ -95,3 +96,5 @@ id: 1,

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

@@ -107,4 +110,3 @@ expect(Buffer.from([

it(`Should serialize typed simple collection with 2 objects`, () => {
const xCollection = new XCollection([new X(1), new X(2)])
const result = resolveSerializablesToBuffer(2, {
const schema: IXyoObjectSchema = {
x: {

@@ -120,3 +122,5 @@ id: 1,

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

@@ -134,4 +138,3 @@ expect(Buffer.from([

it(`Should serialize untyped simple collection with 2 objects`, () => {
const xCollection = new XCollection([new X(1), new X(2)])
const result = resolveSerializablesToBuffer(2, {
const schema: IXyoObjectSchema = {
x: {

@@ -147,3 +150,5 @@ id: 1,

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

@@ -163,4 +168,3 @@ expect(Buffer.from([

it(`Should serialize a collection of untyped collections with 0 objects`, () => {
const xCollectionSet = new XCollectionSet([])
const result = resolveSerializablesToBuffer(3, {
const schema: IXyoObjectSchema = {
x: {

@@ -181,3 +185,5 @@ id: 1,

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

@@ -188,5 +194,3 @@ expect(Buffer.from([]).equals(result)).toBe(true)

it(`Should serialize a collection of untyped collections 2 objects`, () => {
const xCollection = new XCollection([new X(1), new X(2)])
const xCollectionSet = new XCollectionSet([xCollection])
const result = resolveSerializablesToBuffer(3, {
const schema: IXyoObjectSchema = {
x: {

@@ -207,3 +211,6 @@ id: 1,

}
}, xCollectionSet.getData())
}
const xCollection = new XCollection(schema, [new X(schema, 1), new X(schema, 2)])
const xCollectionSet = new XCollectionSet(schema, [xCollection])
const result = resolveSerializablesToBuffer(3, schema, xCollectionSet.getData())

@@ -226,5 +233,3 @@ expect(Buffer.from([

it(`Should serialize a collection of typed collections 2 objects`, () => {
const xCollection = new XCollection([new X(1), new X(2)])
const xCollectionSet = new XCollectionSet([xCollection])
const result = resolveSerializablesToBuffer(3, {
const schema: IXyoObjectSchema = {
x: {

@@ -245,3 +250,6 @@ id: 1,

}
}, xCollectionSet.getData())
}
const xCollection = new XCollection(schema, [new X(schema, 1), new X(schema, 2)])
const xCollectionSet = new XCollectionSet(schema, [xCollection])
const result = resolveSerializablesToBuffer(3, schema, xCollectionSet.getData())

@@ -265,3 +273,3 @@ expect(Buffer.from([

constructor(private readonly value: number) { super() }
constructor(schema: IXyoObjectSchema, private readonly value: number) { super(schema) }

@@ -291,3 +299,3 @@ public getData(): Buffer {

constructor(private readonly value: number) { super() }
constructor(schema: IXyoObjectSchema, private readonly value: number) { super(schema) }

@@ -305,3 +313,3 @@ public getData(): Buffer | IXyoSerializableObject[] {

constructor(private readonly collection: X[]) { super() }
constructor(schema: IXyoObjectSchema, private readonly collection: X[]) { super(schema) }

@@ -317,3 +325,3 @@ public getData(): IXyoSerializableObject[] {

constructor(private readonly collection: XCollection[]) { super() }
constructor(schema: IXyoObjectSchema, private readonly collection: XCollection[]) { super(schema) }

@@ -320,0 +328,0 @@ public getData(): IXyoSerializableObject[] {

@@ -7,3 +7,3 @@ /*

* @Last modified by: ryanxyo
* @Last modified time: Monday, 10th December 2018 5:13:43 pm
* @Last modified time: Wednesday, 12th December 2018 11:03:10 am
* @License: All Rights Reserved

@@ -61,4 +61,4 @@ * @Copyright: Copyright XY | The Findables Company

const src = deserializable instanceof Buffer ? deserializable : Buffer.from(deserializable, 'hex')
const parseResult = parse(src)
return new XyoTreeIterator(parseResult)
const parseResult = parse(src, this.schema)
return new XyoTreeIterator(this.schema, parseResult)
}

@@ -104,3 +104,3 @@

}
return new XyoOnTheFlySerializable(this.schema.typedSet.id, options)
return new XyoOnTheFlySerializable(this.schema, this.schema.typedSet.id, options)
}

@@ -115,3 +115,3 @@

}
return new XyoOnTheFlySerializable(this.schema.untypedSet.id, options)
return new XyoOnTheFlySerializable(this.schema, this.schema.untypedSet.id, options)
}

@@ -118,0 +118,0 @@

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