Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use superjson for local serialization #454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@eventual/core-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@opensearch-project/opensearch": "^2.2.1",
"heap-js": "2.2.0",
"itty-router": "^2.6.6",
"superjson": "^1.13.1",
"ulidx": "^0.3.0",
"zod": "^3.21.4"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/@eventual/core-runtime/src/local/serialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import superjson from "superjson";

export function toJSON(data: any) {
return JSON.stringify(superjson.serialize(data));
}

export function fromJSON<T = any>(data: string): T {
return superjson.deserialize(JSON.parse(data));
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import { LocalEnvConnector } from "../local-container.js";
import { LocalSerializable } from "../local-persistance-store.js";
import { paginateItems } from "./pagination.js";
import { fromJSON, toJSON } from "../serialize.js";

type PK = KeyValue;
type SK = KeyValue;
Expand Down Expand Up @@ -622,11 +623,11 @@ function serializeTableMap(tableMap: TableMap): Buffer {
] as const;
})
);
return Buffer.from(JSON.stringify(record));
return Buffer.from(toJSON(record));
}

function deserializeTableMap(data: Buffer): TableMap {
const record: SerializedData = JSON.parse(data.toString("utf-8"));
const record: SerializedData = fromJSON(data.toString("utf-8"));
return new Map(
Object.entries(record).map(([pk, partition]) => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
UpdateHistoryRequest,
} from "../../stores/execution-history-state-store.js";
import type { LocalSerializable } from "../local-persistance-store.js";
import { fromJSON, toJSON } from "../serialize.js";

export class LocalExecutionHistoryStateStore
implements ExecutionHistoryStateStore, LocalSerializable
Expand All @@ -16,7 +17,7 @@ export class LocalExecutionHistoryStateStore
return Object.fromEntries(
Object.entries(this.executionHistory).map(([e, history]) => [
e,
Buffer.from(JSON.stringify(history)),
Buffer.from(toJSON(history)),
])
);
}
Expand All @@ -29,7 +30,7 @@ export class LocalExecutionHistoryStateStore
Object.fromEntries(
Object.entries(data).map(([key, value]) => [
key,
JSON.parse(value.toString("utf-8")),
fromJSON(value.toString("utf-8")),
])
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { WorkflowEvent } from "@eventual/core/internal";
import { ExecutionHistoryStore } from "../../stores/execution-history-store.js";
import type { LocalSerializable } from "../local-persistance-store.js";
import { paginateItems } from "./pagination.js";
import { fromJSON, toJSON } from "../serialize.js";

export class LocalExecutionHistoryStore
extends ExecutionHistoryStore
Expand All @@ -20,7 +21,7 @@ export class LocalExecutionHistoryStore
return Object.fromEntries(
Object.entries(this.eventStore).map(([key, value]) => [
key,
Buffer.from(JSON.stringify(value)),
Buffer.from(toJSON(value)),
])
);
}
Expand All @@ -31,7 +32,7 @@ export class LocalExecutionHistoryStore
? Object.fromEntries(
Object.entries(data).map(([key, value]) => [
key,
JSON.parse(value.toString("utf-8")),
fromJSON(value.toString("utf-8")),
])
)
: {}
Expand Down
64 changes: 48 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading