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

@bnaya/objectbuffer

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bnaya/objectbuffer - npm Package Compare versions

Comparing version 0.0.0-547d018 to 0.0.0-68033db

2

dist/internal/api.js

@@ -36,3 +36,3 @@ import { initializeArrayBuffer } from "./store";

};
const start = objectSaver(externalArgsApiToExternalArgsApi(externalArgs), carrier, [], initialValue);
const start = objectSaver(externalArgsApiToExternalArgsApi(externalArgs), carrier, [], new Map(), initialValue);
carrier.uint32[INITIAL_ENTRY_POINTER_TO_POINTER / Uint32Array.BYTES_PER_ELEMENT] = start;

@@ -39,0 +39,0 @@ return createObjectWrapper(externalArgsApiToExternalArgsApi(externalArgs), carrier, start);

@@ -15,3 +15,3 @@ import { appendEntry } from "./store";

for (const item of arrayToSave) {
const rOfValue = saveValue(externalArgs, carrier, referencedPointers, item);
const rOfValue = saveValue(externalArgs, carrier, referencedPointers, new Map(), item);
carrier.uint32[memoryForPointersCursor / Uint32Array.BYTES_PER_ELEMENT] = rOfValue;

@@ -18,0 +18,0 @@ memoryForPointersCursor += Uint32Array.BYTES_PER_ELEMENT;

@@ -15,4 +15,2 @@ import { ExternalArgs, GlobalCarrier, InternalAPI, DateEntry, ArrayEntry, ObjectEntry, MapEntry, SetEntry } from "./interfaces";

arrayAdditionalAllocation: number;
textDecoder: import("./textEncoderDecoderTypes").TextDecoder;
textEncoder: import("./textEncoderDecoderTypes").TextEncoder;
}>;

@@ -19,0 +17,0 @@ protected get entryPointer(): number;

@@ -16,3 +16,3 @@ import { WeakValueMap } from "./WeakValueMap";

function supportWeakRef() {
return typeof WeakRef !== "undefined";
return typeof WeakRef !== "undefined" && (typeof FinalizationGroup !== "undefined" || typeof "FinalizationRegistry" !== "undefined");
}
import { ENTRY_TYPE } from "./entry-types";
import { TextDecoder, TextEncoder } from "./textEncoderDecoderTypes";
export declare type primitive = string | number | bigint | boolean | undefined | null;

@@ -72,5 +71,7 @@ export declare type Entry = StringEntry | NumberEntry | BigIntPositiveEntry | BigIntNegativeEntry | ObjectEntry | ArrayEntry | DateEntry | MapEntry | SetEntry;

hashMapMinInitialCapacity: number;
/**
* Allocate additional memory for array pointers,
* will prevent the reallocation and copy when array is getting bigger
*/
arrayAdditionalAllocation: number;
textDecoder: TextDecoder;
textEncoder: TextEncoder;
}>;

@@ -81,4 +82,2 @@ export declare type ExternalArgsApi = Readonly<{

arrayAdditionalAllocation?: number;
textDecoder: TextDecoder;
textEncoder: TextEncoder;
}>;

@@ -85,0 +84,0 @@ export interface InternalAPI {

import { ExternalArgs, GlobalCarrier } from "./interfaces";
export declare function objectSaver(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], objectToSave: any): number;
export declare function mapSaver(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], mapToSave: Map<string | number, any>): number;
export declare function objectSaver(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], visitedValues: Map<object, number>, objectToSave: any): number;
export declare function mapSaver(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], visitedValues: Map<object, number>, mapToSave: Map<string | number, any>): number;
export declare function setSaver(externalArgs: ExternalArgs, carrier: GlobalCarrier, setToSave: Set<string | number>): number;
//# sourceMappingURL=objectSaver.d.ts.map

@@ -5,3 +5,3 @@ import { appendEntry } from "./store";

import { createHashMap, hashMapInsertUpdate } from "./hashmap/hashmap";
export function objectSaver(externalArgs, carrier, referencedPointers, objectToSave) {
export function objectSaver(externalArgs, carrier, referencedPointers, visitedValues, objectToSave) {
const objectEntries = Object.entries(objectToSave);

@@ -12,3 +12,3 @@ const hashMapPointer = createHashMap(carrier, Math.max(externalArgs.hashMapMinInitialCapacity, Math.ceil(objectEntries.length * 1.3)));

const ptrToPtr = hashMapInsertUpdate(externalArgs, carrier, hashMapPointer, key);
const pointerToValue = saveValue(externalArgs, carrier, referencedPointers, value);
const pointerToValue = saveValue(externalArgs, carrier, referencedPointers, visitedValues, value);
carrier.uint32[ptrToPtr / Uint32Array.BYTES_PER_ELEMENT] = pointerToValue;

@@ -24,3 +24,3 @@ }

}
export function mapSaver(externalArgs, carrier, referencedPointers, mapToSave) {
export function mapSaver(externalArgs, carrier, referencedPointers, visitedValues, mapToSave) {
const hashMapPointer = createHashMap(carrier, Math.max(externalArgs.hashMapMinInitialCapacity, Math.ceil(mapToSave.size * 1.3)));

@@ -30,3 +30,3 @@

const ptrToPtr = hashMapInsertUpdate(externalArgs, carrier, hashMapPointer, key);
const pointerToValue = saveValue(externalArgs, carrier, referencedPointers, value);
const pointerToValue = saveValue(externalArgs, carrier, referencedPointers, visitedValues, value);
carrier.uint32[ptrToPtr / Uint32Array.BYTES_PER_ELEMENT] = pointerToValue;

@@ -33,0 +33,0 @@ }

@@ -5,3 +5,3 @@ import { ExternalArgs, GlobalCarrier } from "./interfaces";

*/
export declare function saveValue(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], value: any): number;
export declare function saveValue(externalArgs: ExternalArgs, carrier: GlobalCarrier, referencedPointers: number[], visitedValuesOnCurrentSaveOperation: Map<object, number>, value: any): number;
//# sourceMappingURL=saveValue.d.ts.map

@@ -11,3 +11,4 @@ import { primitiveValueToEntry, isPrimitive, getOurPointerIfApplicable } from "./utils";

export function saveValue(externalArgs, carrier, referencedPointers, value) {
export function saveValue(externalArgs, carrier, referencedPointers, // Not really working yet. we need iterative saving for it
visitedValuesOnCurrentSaveOperation, value) {
let valuePointer = 0;

@@ -38,2 +39,5 @@ let maybeOurPointer;

referencedPointers.push(valuePointer);
} else if (maybeOurPointer = visitedValuesOnCurrentSaveOperation.get(value)) {
valuePointer = maybeOurPointer;
referencedPointers.push(valuePointer);
} else if (Array.isArray(value)) {

@@ -48,7 +52,10 @@ valuePointer = arraySaver(externalArgs, carrier, referencedPointers, value);

} else if (value instanceof Map) {
valuePointer = mapSaver(externalArgs, carrier, referencedPointers, value);
valuePointer = mapSaver(externalArgs, carrier, referencedPointers, visitedValuesOnCurrentSaveOperation, value);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else if (value instanceof Set) {
valuePointer = setSaver(externalArgs, carrier, value);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else if (typeof value === "object") {
valuePointer = objectSaver(externalArgs, carrier, referencedPointers, value);
valuePointer = objectSaver(externalArgs, carrier, referencedPointers, visitedValuesOnCurrentSaveOperation, value);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else {

@@ -55,0 +62,0 @@ throw new Error("unsupported yet");

@@ -280,3 +280,3 @@ import { ENTRY_TYPE, isPrimitiveEntryType } from "./entry-types";

const referencedPointers = [];
const newEntryPointer = saveValue(externalArgs, carrier, referencedPointers, value);
const newEntryPointer = saveValue(externalArgs, carrier, referencedPointers, new Map(), value);
carrier.uint32[ptrToPtr / Uint32Array.BYTES_PER_ELEMENT] = newEntryPointer;

@@ -283,0 +283,0 @@ return {

@@ -15,3 +15,4 @@ const KEYS = 1;

this.map = new Map();
this.group = new FinalizationGroup(iterator => {
const FinalizationSomething = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : FinalizationGroup;
this.group = new FinalizationSomething(iterator => {
for (const key of iterator) {

@@ -18,0 +19,0 @@ this.map.delete(key);

{
"name": "@bnaya/objectbuffer",
"description": "Object-like api, backed by an array buffer",
"version": "0.0.0-547d018",
"version": "0.0.0-68033db",
"main": "dist/objectbuffer.cjs.js",

@@ -36,3 +36,3 @@ "module": "dist/index.js",

"webpack-playground": "webpack-dev-server --mode=development --config playground/webpack.config.js --open",
"generate-docs": "rimraf -f docs/generated/ && typedoc --out docs/generated/ --includes . --name objectbuffer --readme none --entryPoint \"\\\"index\\\"\" --excludeNotExported --ignoreCompilerErrors --mode modules src/index.ts"
"generate-docs": "rimraf -f docs/generated/ && typedoc --mode library --readme none --out docs/generated/ --excludeNotExported --ignoreCompilerErrors src/index.ts"
},

@@ -67,3 +67,3 @@ "devDependencies": {

"rollup-plugin-node-resolve": "^5.2.0",
"typedoc": "^0.17.4",
"typedoc": "^0.17.0-3",
"typedoc-plugin-markdown": "^2.2.17",

@@ -70,0 +70,0 @@ "typescript": "^3.8.3",

@@ -1,2 +0,2 @@

# ObjectBuffer: object-like API, backed by a [shared]arraybuffer
# ObjectBuffer: object-like API, backed by a [shared]arraybuffer 👀

@@ -6,14 +6,17 @@ [![npm version](https://badge.fury.io/js/%40bnaya%2Fobjectbuffer.svg)](https://badge.fury.io/js/%40bnaya%2Fobjectbuffer)

## The readme is for latest release `v0.10.0`.big refactor ongoing (allocator, hashmap)
For Modern browsers and node.
For Modern browsers and node. Zero direct dependencies.
Save, read and update plain javascript objects into `ArrayBuffer` (And not only TypedArrays), using regular javascript object api, without serialization/deserialization, or pre-defined schema.
In other words, It's an implementation of javascript objects in user-land.
Save, read and update plain javascript objects into `ArrayBuffer` (And not only TypedArrays), using regular javascript object api, without serialization/deserialization.
Look at it as a simple implementation of javascript objects in user-land.
That's enables us to `transfer` or share objects in-memory with `WebWorker` without additional memory or serialization
While the library is not `1.0`, it is usable.
The library is still not `1.0`, but already usable, and will never offer full compatibility with plain js (`Symbol` and such)
A core part of the library is an allocator, that allocates & free memory on the `ArrayBuffer` for us!
The allocator in use is [@thi.ng/malloc](https://www.npmjs.com/package/@thi.ng/malloc), part of the amazing [thi.ng/umbrella](https://github.com/thi-ng/umbrella) project
For in-depth overview of how things are implemented, see [implementation details document](docs/implementationDetails.md)
## 🐉🐉🐉 Adventurers Beware 🐉🐉🐉
Using this library, and workers in general, will not necessarily make you code faster.
First be sure where are your bottlenecks and if you don't have a better and more simple workaround.
I personally also really like what's going on around the [main thread scheduling proposal](https://github.com/WICG/main-thread-scheduling) and [react userland scheduler](https://www.npmjs.com/package/scheduler) that powers concurrent react

@@ -30,7 +33,3 @@ ## Quick example

const myObject = createObjectBuffer(
{
// available globally in the browser, or inside `util` in node
textEncoder: new TextEncoder(),
textDecoder: new TextDecoder()
},
{},
// size in bytes

@@ -84,15 +83,18 @@ 1024,

* Date
* Internal references (`foo.bar2 = foo.bar` will not create a copy)
* BigInt
* Internal references (`foo.bar2 = foo.bar` will not create a copy, but a reference)
* Automatic reference counting, to dispose a value you need to use the `disposeWrapperObject` or to have WeakRef support
* Internal equality between objects (`foo.bar === foo.bar` will be true)
* global lock for shared memory using [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) (i hope its really working)
* global lock for shared memory using [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) (I hope its really working)
## Caveats & Limitations
* Need to specify size for the `ArrayBuffer`. When exceed that size, exception will be thrown. (Can be extended with a utility function, but not automatically)
* Not memory re-use. memory allocation is append based, or overwrite when possible [#21](https://github.com/Bnaya/objectbuffer/issues/21)
* Object are implemented using simple linked list [#26](https://github.com/Bnaya/objectbuffer/issues/26)
* Maps & Sets are not supported yet [#15](https://github.com/Bnaya/objectbuffer/issues/15) & [#24](https://github.com/Bnaya/objectbuffer/issues/24)
* No prototype chain. objects props will simply be copied
* Additional props on Array, Date, primitives will not be saved.
* getters, setters, will not work/break the library
* Need to specify size for the `ArrayBuffer`. When exceed that size, exception will be thrown. (Can be extended later with a utility function, but not automatically)
* Size must be multiplication of 8
* Set, Map, Object keys can be only string or numbers. no symbols or other things
* You can't save objects with circularities (But you can create them on objectbuffer)
* No prototype chain. no methods on the objects
* Adding getters, setters, will not work/break the library
* deleting/removing the current key of Map/Set while iteration will make you skip the next key [#60](https://github.com/Bnaya/objectbuffer/issues/60)
* unreliable_sizeOf is unreliable due to hashmap array side depends on actual keys, Also It's an expensive operation

@@ -103,3 +105,3 @@ ### What's not working yet, but can be

### What's probably never going to work (convince me otherwise )
### What's probably never going to work

@@ -112,2 +114,10 @@ * Anything that cannot go into `JSON.stringify`

There's a huge place for optimizations, code hygiene, and features!
Feel free to open issues and maybe implementing missing parts
Feel free to open issues and maybe implementing missing parts.
The code is Written in TypeScript 🦾, but the semantics are more like `C` 🥵
Have a look on the [issues](https://github.com/Bnaya/objectbuffer/issues) and see if you find something interesting
## If you came this far, you better also look at:
* [GoogleChromeLabs/buffer-backed-object](https://github.com/GoogleChromeLabs/buffer-backed-object#readme)
* [FlatBuffers](https://google.github.io/flatbuffers/flatbuffers_guide_use_javascript.html)
/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -12,4 +10,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -16,0 +12,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -11,4 +9,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -15,0 +11,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -11,4 +9,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -15,0 +11,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -10,6 +8,3 @@ import { memoryStats } from "../internal/api";

describe("Map", () => {
const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
});
const externalArgs = externalArgsApiToExternalArgsApi({});

@@ -16,0 +11,0 @@ test("creation", () => {

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -11,4 +9,2 @@ import { resizeObjectBuffer, memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -15,0 +11,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -10,6 +8,3 @@ import { memoryStats } from "../internal/api";

describe("object tests", () => {
const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
});
const externalArgs = externalArgsApiToExternalArgsApi({});

@@ -59,2 +54,28 @@ test("delete object prop", () => {

});
// Not working. will make infinite loop
test.skip("With circular", () => {
const input: any = {
a: 1,
b: true,
c: false,
d: null,
e: undefined,
foo: { a: 1, b: true, c: false, d: null, e: undefined },
};
// Create circularity
input.foo.circular = input.foo;
const objectBuffer = createObjectBuffer<any>(externalArgs, 2048, input);
expect(memoryStats(objectBuffer).available).toMatchInlineSnapshot(`1016`);
expect(input).toEqual(objectBuffer);
expect(objectBuffer.foo.circular).toEqual(objectBuffer.foo);
expect(objectBuffer.foo.circular.d).toMatchInlineSnapshot();
objectBuffer.foo.circular = "severe the circularity";
expect(objectBuffer).toMatchInlineSnapshot();
});
});
/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer, resizeObjectBuffer } from "../";

@@ -18,4 +16,2 @@ import {

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -22,0 +18,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -12,4 +10,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -16,0 +12,0 @@ });

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -10,6 +8,3 @@ import { memoryStats } from "../internal/api";

describe("Set tests", () => {
const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
});
const externalArgs = externalArgsApiToExternalArgsApi({});

@@ -16,0 +11,0 @@ test("creation", () => {

/* eslint-env jest */
import * as util from "util";
import { createObjectBuffer } from "../";

@@ -12,4 +10,2 @@ import { memoryStats, disposeWrapperObject } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -16,0 +12,0 @@ });

/* eslint-disable */
import { ExternalArgs } from "../internal/interfaces";
import * as util from "util";
import { createObjectBuffer } from "..";

@@ -27,6 +27,6 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,
});

@@ -33,0 +33,0 @@

@@ -1,2 +0,1 @@

import * as util from "util";
import { createObjectBuffer } from "..";

@@ -10,4 +9,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -14,0 +11,0 @@ });

@@ -1,2 +0,1 @@

import * as util from "util";
import { createObjectBuffer } from "..";

@@ -10,4 +9,2 @@ import { memoryStats } from "../internal/api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -14,0 +11,0 @@ });

/* eslint-env jest */
import * as util from "util";

@@ -14,4 +13,2 @@ import {

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -41,4 +38,2 @@ });

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -63,4 +58,2 @@ });

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -67,0 +60,0 @@ });

@@ -72,2 +72,3 @@ import { initializeArrayBuffer } from "./store";

[],
new Map(),
initialValue

@@ -74,0 +75,0 @@ );

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { arraySaver } from "./arraySaver";

@@ -18,4 +18,2 @@ import {

const externalArgs: ExternalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 0,

@@ -22,0 +20,0 @@ });

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { arrayBuffer2HexArray, makeCarrier } from "./testUtils";

@@ -11,4 +11,2 @@ import { arraySaver } from "./arraySaver";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -15,0 +13,0 @@ });

@@ -27,3 +27,9 @@ import { appendEntry } from "./store";

for (const item of arrayToSave) {
const rOfValue = saveValue(externalArgs, carrier, referencedPointers, item);
const rOfValue = saveValue(
externalArgs,
carrier,
referencedPointers,
new Map(),
item
);

@@ -30,0 +36,0 @@ carrier.uint32[

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { createArrayWrapper } from "./arrayWrapper";

@@ -14,4 +14,2 @@ import { arraySaver } from "./arraySaver";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -18,0 +16,0 @@ });

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { createArrayWrapper } from "./arrayWrapper";

@@ -14,4 +14,2 @@ import { arraySaver } from "./arraySaver";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -18,0 +16,0 @@ });

@@ -1,2 +0,1 @@

import * as util from "util";
import { createObjectBuffer } from "..";

@@ -9,4 +8,2 @@ import { externalArgsApiToExternalArgsApi } from "./utils";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -13,0 +10,0 @@ });

@@ -26,3 +26,7 @@ import { WeakValueMap } from "./WeakValueMap";

function supportWeakRef() {
return typeof WeakRef !== "undefined";
return (
typeof WeakRef !== "undefined" &&
(typeof FinalizationGroup !== "undefined" ||
typeof "FinalizationRegistry" !== "undefined")
);
}
/* eslint-env jest */
import * as util from "util";
import { MemPool } from "@thi.ng/malloc";

@@ -11,4 +10,2 @@ import { createObjectBuffer, memoryStats } from "./api";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -15,0 +12,0 @@ });

/* eslint-env jest */
import * as util from "util";
import {

@@ -24,4 +24,2 @@ arrayBuffer2HexArray,

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -28,0 +26,0 @@ });

import { ENTRY_TYPE } from "./entry-types";
import { TextDecoder, TextEncoder } from "./textEncoderDecoderTypes";

@@ -97,5 +96,7 @@ export type primitive = string | number | bigint | boolean | undefined | null;

hashMapMinInitialCapacity: number;
/**
* Allocate additional memory for array pointers,
* will prevent the reallocation and copy when array is getting bigger
*/
arrayAdditionalAllocation: number;
textDecoder: TextDecoder;
textEncoder: TextEncoder;
}>;

@@ -107,4 +108,2 @@

arrayAdditionalAllocation?: number;
textDecoder: TextDecoder;
textEncoder: TextEncoder;
}>;

@@ -111,0 +110,0 @@

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { createArrayWrapper } from "./arrayWrapper";

@@ -12,4 +12,2 @@ import { arraySaver } from "./arraySaver";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -16,0 +14,0 @@ });

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { arrayBuffer2HexArray, makeCarrier } from "./testUtils";

@@ -10,6 +10,3 @@ import { objectSaver } from "./objectSaver";

describe("objectSaver tests", () => {
const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
});
const externalArgs = externalArgsApiToExternalArgsApi({});

@@ -35,3 +32,9 @@ describe("objectSaver - general", () => {

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -38,0 +41,0 @@ expect(saverOutput).toMatchInlineSnapshot(`976`);

@@ -17,2 +17,3 @@ import { appendEntry } from "./store";

referencedPointers: number[],
visitedValues: Map<object, number>,
objectToSave: any

@@ -42,2 +43,3 @@ ) {

referencedPointers,
visitedValues,
value

@@ -62,2 +64,3 @@ );

referencedPointers: number[],
visitedValues: Map<object, number>,
mapToSave: Map<string | number, any>

@@ -85,2 +88,3 @@ ) {

referencedPointers,
visitedValues,
value

@@ -87,0 +91,0 @@ );

/* eslint-env jest */
import { initializeArrayBuffer } from "./store";
import * as util from "util";
import { objectSaver } from "./objectSaver";

@@ -11,6 +11,3 @@ import { createObjectWrapper } from "./objectWrapper";

describe("objectWrapper tests", () => {
const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
});
const externalArgs = externalArgsApiToExternalArgsApi({});

@@ -33,3 +30,9 @@ describe("objectWrapper - general", () => {

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -77,3 +80,9 @@ const objectWrapper: any = createObjectWrapper(

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -108,3 +117,9 @@ const objectWrapper: any = createObjectWrapper(

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -150,3 +165,9 @@ const objectWrapper = createObjectWrapper(

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -193,3 +214,9 @@ const objectWrapper = createObjectWrapper(

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -196,0 +223,0 @@ const objectWrapper = createObjectWrapper(

/* eslint-env jest */
import { initializeArrayBuffer, readEntry } from "./store";
import * as util from "util";
import { objectSaver } from "./objectSaver";

@@ -16,4 +16,2 @@ import {

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -37,3 +35,9 @@ });

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -83,3 +87,9 @@ const hashmapPointer = (readEntry(carrier, saverOutput) as ObjectEntry)

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -133,3 +143,9 @@ expect(carrier.allocator.stats().available).toMatchInlineSnapshot(`40`);

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);

@@ -182,3 +198,9 @@ expect(carrier.allocator.stats().available).toMatchInlineSnapshot(`40`);

const saverOutput = objectSaver(externalArgs, carrier, [], objectToSave);
const saverOutput = objectSaver(
externalArgs,
carrier,
[],
new Map(),
objectToSave
);
// expect(carrier.allocator.stats().available).toMatchInlineSnapshot(`8`);

@@ -185,0 +207,0 @@

@@ -25,2 +25,4 @@ import {

referencedPointers: number[],
// Not really working yet. we need iterative saving for it
visitedValuesOnCurrentSaveOperation: Map<object, number>,
value: any

@@ -55,2 +57,7 @@ ) {

referencedPointers.push(valuePointer);
} else if (
(maybeOurPointer = visitedValuesOnCurrentSaveOperation.get(value))
) {
valuePointer = maybeOurPointer;
referencedPointers.push(valuePointer);
} else if (Array.isArray(value)) {

@@ -65,5 +72,13 @@ valuePointer = arraySaver(externalArgs, carrier, referencedPointers, value);

} else if (value instanceof Map) {
valuePointer = mapSaver(externalArgs, carrier, referencedPointers, value);
valuePointer = mapSaver(
externalArgs,
carrier,
referencedPointers,
visitedValuesOnCurrentSaveOperation,
value
);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else if (value instanceof Set) {
valuePointer = setSaver(externalArgs, carrier, value);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else if (typeof value === "object") {

@@ -74,4 +89,6 @@ valuePointer = objectSaver(

referencedPointers,
visitedValuesOnCurrentSaveOperation,
value
);
visitedValuesOnCurrentSaveOperation.set(value, valuePointer);
} else {

@@ -78,0 +95,0 @@ throw new Error("unsupported yet");

/* eslint-env jest */
import * as util from "util";
import { sizeOf } from "./sizeOf";

@@ -10,4 +9,2 @@ import { externalArgsApiToExternalArgsApi } from "./utils";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -14,0 +11,0 @@ });

@@ -10,3 +10,3 @@ /* eslint-env jest */

import { ENTRY_TYPE } from "./entry-types";
import * as util from "util";
import { arrayBuffer2HexArray, makeCarrier } from "./testUtils";

@@ -154,4 +154,2 @@ import { ObjectEntry } from "./interfaces";

const externalArgs = externalArgsApiToExternalArgsApi({
textEncoder: new util.TextEncoder(),
textDecoder: new util.TextDecoder(),
arrayAdditionalAllocation: 20,

@@ -158,0 +156,0 @@ });

@@ -365,2 +365,3 @@ import { ENTRY_TYPE, isPrimitiveEntryType } from "./entry-types";

referencedPointers,
new Map(),
value

@@ -367,0 +368,0 @@ );

@@ -6,2 +6,3 @@ const KEYS = 1;

declare const FinalizationGroup: any;
declare const FinalizationRegistry: any;
declare const WeakRef: any;

@@ -25,3 +26,8 @@

this.group = new FinalizationGroup((iterator: Iterable<any>) => {
const FinalizationSomething =
typeof FinalizationRegistry !== "undefined"
? FinalizationRegistry
: FinalizationGroup;
this.group = new FinalizationSomething((iterator: Iterable<any>) => {
for (const key of iterator) {

@@ -28,0 +34,0 @@ this.map.delete(key);

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 too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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