From e985f99f623744eeb333ba080b5f3c6f34abd013 Mon Sep 17 00:00:00 2001 From: Jan Lewandowski Date: Mon, 23 Dec 2024 13:00:58 +0100 Subject: [PATCH 1/2] fix: deep cloning state and original drp --- packages/object/package.json | 3 ++- packages/object/src/index.ts | 13 ++++--------- pnpm-lock.yaml | 8 ++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/object/package.json b/packages/object/package.json index 5ca5dc4e..a9463769 100644 --- a/packages/object/package.json +++ b/packages/object/package.json @@ -27,7 +27,8 @@ "devDependencies": { "@bufbuild/protobuf": "^2.0.0", "benchmark": "^2.1.4", - "tsx": "4.19.1" + "tsx": "4.19.1", + "es-toolkit": "1.30.1" }, "dependencies": { "@ts-drp/logger": "^0.4.4" diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index 44a231d5..342d6cb9 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -13,6 +13,7 @@ import { ObjectSet } from "./utils/objectSet.js"; export * as ObjectPb from "./proto/drp/object/v1/object_pb.js"; export * from "./hashgraph/index.js"; +import { clone, cloneDeep } from "es-toolkit"; export interface IACL { isWriter: (peerId: string) => boolean; @@ -96,10 +97,7 @@ export class DRPObject implements IDRPObject { ); this.subscriptions = []; this.states = new Map([[HashGraph.rootHash, { state: new Map() }]]); - this.originalDRP = Object.create( - Object.getPrototypeOf(drp), - Object.getOwnPropertyDescriptors(structuredClone(drp)), - ); + this.originalDRP = cloneDeep(drp); this.vertices = this.hashGraph.getAllVertices(); } @@ -202,17 +200,14 @@ export class DRPObject implements IDRPObject { ? [] : this.hashGraph.linearizeOperations(lca, subgraph); - const drp = Object.create( - Object.getPrototypeOf(this.originalDRP), - Object.getOwnPropertyDescriptors(structuredClone(this.originalDRP)), - ) as DRP; + const drp = cloneDeep(this.originalDRP); const fetchedState = this.states.get(lca); if (!fetchedState) { throw new Error("State is undefined"); } - const state = structuredClone(fetchedState); + const state = cloneDeep(fetchedState); for (const [key, value] of state.state) { drp[key] = value; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f9bd1f4a..5290bb09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -289,6 +289,9 @@ importers: benchmark: specifier: ^2.1.4 version: 2.1.4 + es-toolkit: + specifier: 1.30.1 + version: 1.30.1 tsx: specifier: 4.19.1 version: 4.19.1 @@ -2783,6 +2786,9 @@ packages: resolution: {integrity: sha512-MZ4iQ6JwHOBQjahnjwaC1ZtIBH+2ohjamzAO3oaHcXYup7qxjF2fixyH+Q71voWHeOkI2q/TnJao/KfXYIZWbw==} engines: {node: '>= 0.4'} + es-toolkit@1.30.1: + resolution: {integrity: sha512-ZXflqanzH8BpHkDhFa10bBf6ONDCe84EPUm7SSICGzuuROSluT2ynTPtwn9PcRelMtorCRozSknI/U0MNYp0Uw==} + esbuild@0.21.5: resolution: {integrity: sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==} engines: {node: '>=12'} @@ -8047,6 +8053,8 @@ snapshots: dependencies: es-errors: 1.3.0 + es-toolkit@1.30.1: {} + esbuild@0.21.5: optionalDependencies: '@esbuild/aix-ppc64': 0.21.5 From c9a32305e5663318db01f388c31ddb36d5e6e26a Mon Sep 17 00:00:00 2001 From: Jan Lewandowski <62848215+JanLewDev@users.noreply.github.com> Date: Tue, 24 Dec 2024 00:08:09 +0100 Subject: [PATCH 2/2] Update packages/object/src/index.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Phạm Xuân Trung <66519569+trungnotchung@users.noreply.github.com> --- packages/object/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index 342d6cb9..152b1abd 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -13,7 +13,7 @@ import { ObjectSet } from "./utils/objectSet.js"; export * as ObjectPb from "./proto/drp/object/v1/object_pb.js"; export * from "./hashgraph/index.js"; -import { clone, cloneDeep } from "es-toolkit"; +import { cloneDeep } from "es-toolkit"; export interface IACL { isWriter: (peerId: string) => boolean;