mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
refactor: use structured clone for local copies
This commit is contained in:
@@ -80,7 +80,7 @@ export function getLoadSessionStoreMock(): AnyMock {
|
||||
}
|
||||
|
||||
export function setSessionStoreEntriesForTest(entries: SessionStore) {
|
||||
sessionStoreEntries.value = JSON.parse(JSON.stringify(entries)) as SessionStore;
|
||||
sessionStoreEntries.value = structuredClone(entries);
|
||||
}
|
||||
|
||||
const { readChannelAllowFromStore, upsertChannelPairingRequest } = vi.hoisted(
|
||||
|
||||
@@ -240,11 +240,7 @@ export async function loadCompactHooksHarness(): Promise<{
|
||||
createAgentSession: vi.fn(async () => {
|
||||
const session = {
|
||||
sessionId: "session-1",
|
||||
messages: sessionMessages.map((message) =>
|
||||
typeof structuredClone === "function"
|
||||
? structuredClone(message)
|
||||
: JSON.parse(JSON.stringify(message)),
|
||||
),
|
||||
messages: sessionMessages.map((message) => structuredClone(message)),
|
||||
agent: {
|
||||
streamFn: vi.fn(),
|
||||
transport: "sse",
|
||||
@@ -253,7 +249,7 @@ export async function loadCompactHooksHarness(): Promise<{
|
||||
return session.messages;
|
||||
},
|
||||
set messages(messages: unknown[]) {
|
||||
session.messages = [...(messages as typeof session.messages)];
|
||||
session.messages = [...messages];
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ vi.mock("./models/shared.js", async () => {
|
||||
return {
|
||||
...actual,
|
||||
updateConfig: async (mutator: (cfg: Record<string, unknown>) => Record<string, unknown>) => {
|
||||
const next = mutator(JSON.parse(JSON.stringify(mocks.currentConfig)));
|
||||
const next = mutator(structuredClone(mocks.currentConfig));
|
||||
mocks.writtenConfig = next;
|
||||
return next;
|
||||
},
|
||||
|
||||
@@ -9,10 +9,7 @@ type JsonSchemaObject = {
|
||||
};
|
||||
|
||||
export function cloneSchema<T>(value: T): T {
|
||||
if (typeof structuredClone === "function") {
|
||||
return structuredClone(value);
|
||||
}
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
return structuredClone(value);
|
||||
}
|
||||
|
||||
export function asSchemaObject(value: unknown): object | null {
|
||||
|
||||
@@ -147,7 +147,7 @@ describe("runCronIsolatedAgentTurn — cron model override (#21057)", () => {
|
||||
| { model?: string; modelProvider?: string; systemSent?: boolean }
|
||||
| undefined;
|
||||
if (entry) {
|
||||
persistedSnapshots.push(JSON.parse(JSON.stringify(entry)));
|
||||
persistedSnapshots.push(structuredClone(entry));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -579,7 +579,7 @@ async function prepareManualRun(
|
||||
job,
|
||||
startedAt: preflight.now,
|
||||
});
|
||||
const executionJob = JSON.parse(JSON.stringify(job)) as CronJob;
|
||||
const executionJob = structuredClone(job);
|
||||
return {
|
||||
ok: true,
|
||||
ran: true,
|
||||
|
||||
@@ -100,7 +100,7 @@ function resolveClaudeCliUsage(raw: ClaudeCliUsage) {
|
||||
}
|
||||
|
||||
function cloneJsonValue<T>(value: T): T {
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
return structuredClone(value);
|
||||
}
|
||||
|
||||
function normalizeClaudeCliContent(
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
export function cloneConfigObject<T>(value: T): T {
|
||||
if (typeof structuredClone === "function") {
|
||||
return structuredClone(value);
|
||||
}
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
return structuredClone(value);
|
||||
}
|
||||
|
||||
export function serializeConfigForm(form: Record<string, unknown>): string {
|
||||
|
||||
Reference in New Issue
Block a user