@poe-platform/safe-js 0.1.729 → 0.1.731
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/safe-js/chunks/{chunk-SJZWSPWD.js → chunk-2GVBG23M.js} +1 -1
- package/dist/safe-js/chunks/{chunk-SJZWSPWD.js.map → chunk-2GVBG23M.js.map} +1 -1
- package/dist/safe-js/chunks/{chunk-VIMROAQA.js → chunk-E4XLBT7R.js} +2 -2
- package/dist/safe-js/chunks/chunk-F6CV74HU.js +114 -0
- package/dist/safe-js/chunks/chunk-F6CV74HU.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-OZLTLIHX.js → chunk-G6WTEIJJ.js} +2 -2
- package/dist/safe-js/chunks/{chunk-XX57YCGZ.js → chunk-GNEORAQI.js} +55 -50
- package/dist/safe-js/chunks/chunk-GNEORAQI.js.map +7 -0
- package/dist/safe-js/chunks/chunk-GVKXZW53.js +76 -0
- package/dist/safe-js/chunks/chunk-GVKXZW53.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-2S4YRXI6.js → chunk-IRDQDZ5R.js} +4 -4
- package/dist/safe-js/chunks/{chunk-MRULOD5J.js → chunk-K4T4EBED.js} +59 -38
- package/dist/safe-js/chunks/chunk-K4T4EBED.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-MFCEBCGV.js → chunk-KETIFEA7.js} +17 -8
- package/dist/safe-js/chunks/chunk-KETIFEA7.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-S5YDMMM3.js → chunk-MDIWQFYU.js} +95 -169
- package/dist/safe-js/chunks/{chunk-S5YDMMM3.js.map → chunk-MDIWQFYU.js.map} +4 -4
- package/dist/safe-js/chunks/{chunk-BRBOVGNC.js → chunk-MGHE7ZFI.js} +78 -67
- package/dist/safe-js/chunks/chunk-MGHE7ZFI.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-EN724VH3.js → chunk-O4IDRXW7.js} +4 -4
- package/dist/safe-js/chunks/{chunk-EA7AHM2X.js → chunk-PSVV3IG2.js} +3 -3
- package/dist/safe-js/chunks/{chunk-Y5EZYHU6.js → chunk-QKO4FATZ.js} +33 -5
- package/dist/safe-js/chunks/chunk-QKO4FATZ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-EG3QWREA.js → chunk-RULU2F5J.js} +2 -2
- package/dist/safe-js/chunks/chunk-UQPYTZOZ.js +72 -0
- package/dist/safe-js/chunks/chunk-UQPYTZOZ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-LRSWTDIV.js → chunk-W4SWUHCQ.js} +58 -23
- package/dist/safe-js/chunks/chunk-W4SWUHCQ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-W3IY6FKO.js → chunk-WS2FJBH6.js} +2 -2
- package/dist/safe-js/chunks/{chunk-MVLDRXWS.js → chunk-X3CKAZQ4.js} +3 -3
- package/dist/safe-js/chunks/chunk-YUQFFRUF.js +26 -0
- package/dist/safe-js/chunks/chunk-YUQFFRUF.js.map +7 -0
- package/dist/safe-js/chunks/{cli-runtime-6VVBO2SS.js → cli-runtime-NUEFUM64.js} +51 -30
- package/dist/safe-js/chunks/cli-runtime-NUEFUM64.js.map +7 -0
- package/dist/safe-js/chunks/{dump-UNYK24YS.js → dump-RGRC3CG3.js} +5 -4
- package/dist/safe-js/chunks/harness-UMOMFXDT.js +11 -0
- package/dist/safe-js/chunks/mcp-S672263Q.js +12 -0
- package/dist/safe-js/chunks/migration-file-KRXQYI3Q.js +15 -0
- package/dist/safe-js/chunks/restore-GEO7VN2R.js +14 -0
- package/dist/safe-js/chunks/run-ZSFX66RN.js +20 -0
- package/dist/safe-js/chunks/runtime-modules-A3U2DKFL.js +11 -0
- package/dist/safe-js/chunks/source-files-L3SGK63Z.js +10 -0
- package/dist/safe-js/cli-runtime.d.ts +2 -0
- package/dist/safe-js/cli.js +4 -4
- package/dist/safe-js/core.d.ts +1 -0
- package/dist/safe-js/core.js +15 -8
- package/dist/safe-js/error/shape.js +170 -0
- package/dist/safe-js/index.js +42 -33
- package/dist/safe-js/index.js.map +2 -2
- package/dist/safe-js/interp/budget.js +600 -0
- package/dist/safe-js/interp/internal-symbols.js +1 -0
- package/dist/safe-js/interp/promise-replay.d.ts +1 -1
- package/dist/safe-js/interp/template-cache.js +7 -0
- package/dist/safe-js/migration-file.d.ts +2 -0
- package/dist/safe-js/modules/fs-config.d.ts +3 -1
- package/dist/safe-js/modules/fs.d.ts +8 -4
- package/dist/safe-js/modules/fs.js +16 -0
- package/dist/safe-js/modules/source-files.d.ts +3 -2
- package/dist/safe-js/platform/context.js +58 -0
- package/dist/safe-js/platform/node.js +64 -0
- package/dist/safe-js/platform/types.js +63 -0
- package/dist/safe-js/platform/workerd.js +39 -0
- package/dist/safe-js/runner/run-harness.d.ts +2 -0
- package/dist/safe-js/snapshot/backend.d.ts +2 -0
- package/package.json +9 -2
- package/dist/safe-js/chunks/chunk-BRBOVGNC.js.map +0 -7
- package/dist/safe-js/chunks/chunk-FCCA27RC.js +0 -69
- package/dist/safe-js/chunks/chunk-FCCA27RC.js.map +0 -7
- package/dist/safe-js/chunks/chunk-LRSWTDIV.js.map +0 -7
- package/dist/safe-js/chunks/chunk-MFCEBCGV.js.map +0 -7
- package/dist/safe-js/chunks/chunk-MRULOD5J.js.map +0 -7
- package/dist/safe-js/chunks/chunk-XX57YCGZ.js.map +0 -7
- package/dist/safe-js/chunks/chunk-Y5EZYHU6.js.map +0 -7
- package/dist/safe-js/chunks/cli-runtime-6VVBO2SS.js.map +0 -7
- package/dist/safe-js/chunks/fs-AOV77RQC.js +0 -13
- package/dist/safe-js/chunks/harness-ZIEO7NAV.js +0 -10
- package/dist/safe-js/chunks/mcp-WBM7ZOAN.js +0 -11
- package/dist/safe-js/chunks/migration-file-3SWGNDS2.js +0 -12
- package/dist/safe-js/chunks/restore-FCTWPLU3.js +0 -13
- package/dist/safe-js/chunks/run-ESJHEXCE.js +0 -17
- package/dist/safe-js/chunks/runtime-modules-7V6BWCRK.js +0 -10
- package/dist/safe-js/chunks/source-files-73OHLNGH.js +0 -8
- /package/dist/safe-js/chunks/{chunk-VIMROAQA.js.map → chunk-E4XLBT7R.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-OZLTLIHX.js.map → chunk-G6WTEIJJ.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-2S4YRXI6.js.map → chunk-IRDQDZ5R.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EN724VH3.js.map → chunk-O4IDRXW7.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EA7AHM2X.js.map → chunk-PSVV3IG2.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EG3QWREA.js.map → chunk-RULU2F5J.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-W3IY6FKO.js.map → chunk-WS2FJBH6.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-MVLDRXWS.js.map → chunk-X3CKAZQ4.js.map} +0 -0
- /package/dist/safe-js/chunks/{dump-UNYK24YS.js.map → dump-RGRC3CG3.js.map} +0 -0
- /package/dist/safe-js/chunks/{fs-AOV77RQC.js.map → harness-UMOMFXDT.js.map} +0 -0
- /package/dist/safe-js/chunks/{harness-ZIEO7NAV.js.map → mcp-S672263Q.js.map} +0 -0
- /package/dist/safe-js/chunks/{mcp-WBM7ZOAN.js.map → migration-file-KRXQYI3Q.js.map} +0 -0
- /package/dist/safe-js/chunks/{migration-file-3SWGNDS2.js.map → restore-GEO7VN2R.js.map} +0 -0
- /package/dist/safe-js/chunks/{restore-FCTWPLU3.js.map → run-ZSFX66RN.js.map} +0 -0
- /package/dist/safe-js/chunks/{run-ESJHEXCE.js.map → runtime-modules-A3U2DKFL.js.map} +0 -0
- /package/dist/safe-js/chunks/{runtime-modules-7V6BWCRK.js.map → source-files-L3SGK63Z.js.map} +0 -0
- /package/dist/safe-js/{chunks/source-files-73OHLNGH.js.map → modules/fs.js.map} +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// packages/safe-js/src/modules/source-files.ts
|
|
2
|
-
import { open, realpath, stat } from "node:fs/promises";
|
|
3
|
-
import { constants } from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
async function createRootedSourceResolver(root) {
|
|
6
|
-
const directory = await realpath(root);
|
|
7
|
-
const granted = path.resolve(root);
|
|
8
|
-
if (!(await stat(directory)).isDirectory()) throw new TypeError("Source module root must be a directory.");
|
|
9
|
-
const contains = (filename) => {
|
|
10
|
-
const relative = path.relative(directory, filename);
|
|
11
|
-
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
12
|
-
};
|
|
13
|
-
const resolver = async (specifier, referrer, { signal }) => {
|
|
14
|
-
signal?.throwIfAborted();
|
|
15
|
-
if (!specifier.startsWith("./") && !specifier.startsWith("../") || !path.isAbsolute(referrer)) return void 0;
|
|
16
|
-
const relative = path.relative(granted, referrer);
|
|
17
|
-
const canonicalReferrer = relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) ? path.resolve(directory, relative) : referrer;
|
|
18
|
-
if (!contains(canonicalReferrer)) return void 0;
|
|
19
|
-
const candidate = path.resolve(path.dirname(canonicalReferrer), specifier);
|
|
20
|
-
if (!contains(candidate)) return void 0;
|
|
21
|
-
try {
|
|
22
|
-
const id = await realpath(candidate);
|
|
23
|
-
signal?.throwIfAborted();
|
|
24
|
-
if (!contains(id)) return void 0;
|
|
25
|
-
const expected = await stat(id);
|
|
26
|
-
signal?.throwIfAborted();
|
|
27
|
-
if (!expected.isFile()) return void 0;
|
|
28
|
-
const handle = await open(id, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
29
|
-
try {
|
|
30
|
-
signal?.throwIfAborted();
|
|
31
|
-
const actual = await handle.stat();
|
|
32
|
-
signal?.throwIfAborted();
|
|
33
|
-
if (!actual.isFile() || actual.dev !== expected.dev || actual.ino !== expected.ino) return void 0;
|
|
34
|
-
const currentId = await realpath(id);
|
|
35
|
-
signal?.throwIfAborted();
|
|
36
|
-
if (currentId !== id) return void 0;
|
|
37
|
-
const source = await handle.readFile({ encoding: "utf8", signal });
|
|
38
|
-
signal?.throwIfAborted();
|
|
39
|
-
return { id, source };
|
|
40
|
-
} finally {
|
|
41
|
-
await handle.close();
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
signal?.throwIfAborted();
|
|
45
|
-
if (error !== null && typeof error === "object" && "code" in error && ["ENOENT", "ENOTDIR", "ELOOP"].includes(String(error.code))) return void 0;
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
return Object.assign(resolver, { async entryId(filename) {
|
|
50
|
-
if (filename === void 0) return path.join(directory, "<entry>");
|
|
51
|
-
const supplied = path.resolve(granted, filename);
|
|
52
|
-
const relative = path.relative(granted, supplied);
|
|
53
|
-
const candidate = relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) ? path.resolve(directory, relative) : supplied;
|
|
54
|
-
if (!contains(candidate)) throw new TypeError("Source entry must be inside its granted root.");
|
|
55
|
-
try {
|
|
56
|
-
const id = await realpath(candidate);
|
|
57
|
-
if (!contains(id)) throw new TypeError("Source entry must be inside its granted root.");
|
|
58
|
-
return id;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT") return candidate;
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
} });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export {
|
|
67
|
-
createRootedSourceResolver
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=chunk-FCCA27RC.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/modules/source-files.ts"],
|
|
4
|
-
"sourcesContent": ["import {open,realpath,stat} from \"node:fs/promises\";\nimport {constants} from \"node:fs\";\nimport path from \"node:path\";\nimport type {SourceResolver} from \"./source-graph.js\";\n\n/** Explicit Node host grant. No package lookup, extension search, or URL loading. */\nexport async function createRootedSourceResolver(root: string): Promise<SourceResolver & {\n entryId(filename?: string): Promise<string>;\n}> {\n const directory = await realpath(root);\n const granted = path.resolve(root);\n if (!(await stat(directory)).isDirectory()) throw new TypeError(\"Source module root must be a directory.\");\n const contains = (filename: string) => {\n const relative = path.relative(directory,filename);\n return relative !== \"..\" && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);\n };\n const resolver: SourceResolver = async (specifier,referrer,{signal}) => {\n signal?.throwIfAborted();\n if ((!specifier.startsWith(\"./\") && !specifier.startsWith(\"../\")) || !path.isAbsolute(referrer)) return undefined;\n const relative = path.relative(granted,referrer);\n const canonicalReferrer = relative !== \"..\" && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)\n ? path.resolve(directory,relative) : referrer;\n if (!contains(canonicalReferrer)) return undefined;\n const candidate = path.resolve(path.dirname(canonicalReferrer),specifier);\n if (!contains(candidate)) return undefined;\n try {\n const id = await realpath(candidate);\n signal?.throwIfAborted();\n if (!contains(id)) return undefined;\n const expected = await stat(id);\n signal?.throwIfAborted();\n if (!expected.isFile()) return undefined;\n const handle = await open(id,constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);\n try {\n signal?.throwIfAborted();\n const actual = await handle.stat();\n signal?.throwIfAborted();\n // Read the checked inode, never reopen its pathname. These checks deny\n // observed replacements; Node's path APIs do not provide atomic ancestor\n // confinement against an adversary repeatedly swapping directories.\n if (!actual.isFile() || actual.dev !== expected.dev || actual.ino !== expected.ino) return undefined;\n const currentId = await realpath(id);\n signal?.throwIfAborted();\n if (currentId !== id) return undefined;\n const source = await handle.readFile({encoding:\"utf8\",signal});\n signal?.throwIfAborted();\n return {id,source};\n } finally {await handle.close();}\n } catch (error) {\n signal?.throwIfAborted();\n if (error !== null && typeof error === \"object\" && \"code\" in error &&\n [\"ENOENT\",\"ENOTDIR\",\"ELOOP\"].includes(String(error.code))) return undefined;\n throw error;\n }\n };\n return Object.assign(resolver, {async entryId(filename?: string): Promise<string> {\n if (filename === undefined) return path.join(directory,\"<entry>\");\n const supplied = path.resolve(granted,filename);\n const relative = path.relative(granted,supplied);\n const candidate = relative !== \"..\" && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)\n ? path.resolve(directory,relative) : supplied;\n if (!contains(candidate)) throw new TypeError(\"Source entry must be inside its granted root.\");\n try {\n const id = await realpath(candidate);\n if (!contains(id)) throw new TypeError(\"Source entry must be inside its granted root.\");\n return id;\n } catch (error) {\n if (error !== null && typeof error === \"object\" && \"code\" in error && error.code === \"ENOENT\") return candidate;\n throw error;\n }\n }});\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAQ,MAAK,UAAS,YAAW;AACjC,SAAQ,iBAAgB;AACxB,OAAO,UAAU;AAIjB,eAAsB,2BAA2B,MAE9C;AACD,QAAM,YAAY,MAAM,SAAS,IAAI;AACrC,QAAM,UAAU,KAAK,QAAQ,IAAI;AACjC,MAAI,EAAE,MAAM,KAAK,SAAS,GAAG,YAAY,EAAG,OAAM,IAAI,UAAU,yCAAyC;AACzG,QAAM,WAAW,CAAC,aAAqB;AACrC,UAAM,WAAW,KAAK,SAAS,WAAU,QAAQ;AACjD,WAAO,aAAa,QAAQ,CAAC,SAAS,WAAW,KAAK,KAAK,GAAG,EAAE,KAAK,CAAC,KAAK,WAAW,QAAQ;AAAA,EAChG;AACA,QAAM,WAA2B,OAAO,WAAU,UAAS,EAAC,OAAM,MAAM;AACtE,YAAQ,eAAe;AACvB,QAAK,CAAC,UAAU,WAAW,IAAI,KAAK,CAAC,UAAU,WAAW,KAAK,KAAM,CAAC,KAAK,WAAW,QAAQ,EAAG,QAAO;AACxG,UAAM,WAAW,KAAK,SAAS,SAAQ,QAAQ;AAC/C,UAAM,oBAAoB,aAAa,QAAQ,CAAC,SAAS,WAAW,KAAK,KAAK,GAAG,EAAE,KAAK,CAAC,KAAK,WAAW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SAAS;AAChE,UAAM,WAAW,KAAK,QAAQ,SAAQ,QAAQ;AAC9C,UAAM,WAAW,KAAK,SAAS,SAAQ,QAAQ;AAC/C,UAAM,YAAY,aAAa,QAAQ,CAAC,SAAS,WAAW,KAAK,KAAK,GAAG,EAAE,KAAK,CAAC,KAAK,WAAW,QAAQ,IACrG,KAAK,QAAQ,WAAU,QAAQ,IAAI;AACvC,QAAI,CAAC,SAAS,SAAS,EAAG,OAAM,IAAI,UAAU,+CAA+C;AAC7F,QAAI;AACF,YAAM,KAAK,MAAM,SAAS,SAAS;AACnC,UAAI,CAAC,SAAS,EAAE,EAAG,OAAM,IAAI,UAAU,+CAA+C;AACtF,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,UAAU,SAAS,MAAM,SAAS,SAAU,QAAO;AACtG,YAAM;AAAA,IACR;AAAA,EACF,EAAC,CAAC;AACJ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/migration-file.ts", "../../src/migrate.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport { link, open, readFile, unlink } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { hasOwnErrorCode } from \"./error-codes.js\";\n\nimport {\n inspectSnapshotMigration,\n migrateSnapshot,\n type SnapshotMigrationOptions\n} from \"./migrate.js\";\nimport type { SafeJSSnapshot } from \"./restore.js\";\nimport { serializeSafeJSSnapshot } from \"./snapshot/dump-format.js\";\n\nexport type SnapshotMigrationFileOptions = {\n snapshotPath: string;\n sourcePath: string;\n targetSourcePath?: string;\n planPath?: string;\n outputPath?: string;\n inspect?: boolean;\n dryRun?: boolean;\n cwd?: string;\n};\n\nexport async function migrateSnapshotFile(options: SnapshotMigrationFileOptions) {\n const cwd = options.cwd ?? process.cwd();\n const resolvePath = (value: string | undefined, label: string) => {\n if (typeof value !== \"string\" || value.trim().length === 0)\n throw new TypeError(`Migration requires ${label}.`);\n return path.resolve(cwd, value);\n };\n const snapshotPath = resolvePath(options.snapshotPath, \"a snapshot path\");\n const sourcePath = resolvePath(options.sourcePath, \"--from <original.ajs>\");\n if (\n options.inspect &&\n [options.targetSourcePath, options.planPath, options.outputPath].some(\n (value) => value !== undefined\n )\n )\n throw new TypeError(\"Migration --inspect cannot be combined with --to, --plan, or --output.\");\n const outputPath = options.inspect\n ? undefined\n : resolvePath(options.outputPath, \"--output <new-checkpoint.json>\");\n const targetSourcePath = options.inspect\n ? undefined\n : resolvePath(options.targetSourcePath, \"--to <continuation.ajs>\");\n const planPath = options.inspect\n ? undefined\n : resolvePath(options.planPath, \"--plan <migration.json>\");\n for (const filepath of [sourcePath, targetSourcePath]) {\n if (filepath !== undefined && ![\".ajs\", \".safejs\"].includes(path.extname(filepath)))\n throw new TypeError(\n \"Migration source paths must name executable .ajs or .safejs files, not harness Markdown.\"\n );\n }\n const snapshot: SafeJSSnapshot = JSON.parse(await readFile(snapshotPath, \"utf8\"));\n const source = await readFile(sourcePath, \"utf8\");\n const inspection = inspectSnapshotMigration(snapshot, { source });\n if (options.inspect) return { inspection };\n const plan: unknown = JSON.parse(await readFile(planPath!, \"utf8\"));\n if (\n plan === null ||\n typeof plan !== \"object\" ||\n !Object.hasOwn(plan, \"state\") ||\n !Object.hasOwn(plan, \"reconciliation\")\n )\n throw new TypeError(\"Migration plan requires explicit state and reconciliation fields.\");\n const targetSource = await readFile(targetSourcePath!, \"utf8\");\n const migrated = migrateSnapshot(snapshot, {\n source,\n targetSource,\n state: (plan as SnapshotMigrationOptions).state,\n reconciliation: (plan as SnapshotMigrationOptions).reconciliation\n });\n const contents = serializeSafeJSSnapshot(migrated);\n if (!options.dryRun) {\n const temporaryPath = path.join(\n path.dirname(outputPath!),\n `.safejs-migration-${randomUUID()}.tmp`\n );\n let created = false;\n try {\n const handle = await open(temporaryPath, \"wx\", 0o600);\n created = true;\n try {\n await handle.writeFile(contents, \"utf8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n try {\n await link(temporaryPath, outputPath!);\n } catch (error) {\n if (hasOwnErrorCode(error, \"EEXIST\"))\n throw Object.assign(\n new Error(\n `Migration output already exists: ${JSON.stringify(outputPath)}. Choose a new output path; existing files are never overwritten.`,\n { cause: error }\n ),\n { code: \"EEXIST\" }\n );\n throw error;\n }\n } finally {\n if (created) await unlink(temporaryPath);\n }\n }\n return { inspection, outputPath, dryRun: options.dryRun === true };\n}\n", "import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\n\nimport { assertSnapshotInactive } from \"./interp/running-state.js\";\nimport { deepCopyToSandbox } from \"./interp/values.js\";\nimport { hashSource } from \"./parse/hash.js\";\nimport { parseModule } from \"./parse/parser.js\";\nimport type { SafeJSSnapshot } from \"./restore.js\";\nimport { DUMP_FORMAT_VERSION, EXECUTION_SEMANTICS } from \"./snapshot/dump-format.js\";\nimport {\n validateMigrationJournal,\n validateMigrationReconciliation,\n validateMigrationSemantics,\n validateSnapshotMigration,\n type SnapshotMigration,\n type SnapshotMigrationReconciliation\n} from \"./snapshot/migration.js\";\nimport { encodeReplayData } from \"./snapshot/replay-data.js\";\nimport { validateDumpEnvelope, validateSnapshotData } from \"./snapshot/validation.js\";\n\nexport type {\n SnapshotMigration,\n SnapshotMigrationReconciliation,\n SnapshotMigrationResolution\n} from \"./snapshot/migration.js\";\n\nexport type SnapshotMigrationOptions = {\n source: string;\n targetSource: string;\n state: unknown;\n reconciliation: SnapshotMigrationReconciliation;\n};\n\nexport function inspectSnapshotMigration(snapshot: SafeJSSnapshot, options: { source: string }) {\n assertSnapshotInactive(snapshot);\n validateSnapshotData(snapshot);\n validateDumpEnvelope(snapshot);\n validateMigrationSemantics(snapshot.executionSemantics);\n const sourceHash = hashSource(\n options.source,\n undefined,\n snapshot.executionSemantics === \"jobs-v8\" || snapshot.executionSemantics === EXECUTION_SEMANTICS\n );\n if (snapshot.sourceHash !== sourceHash)\n throw new TypeError(\n `Migration requires the original executable source (checkpoint hash ${snapshot.sourceHash}, supplied ${sourceHash}). Preserve the checkpoint; do not replace its hash.`\n );\n validateSnapshotMigration(snapshot.migration, sourceHash);\n const replay = validateMigrationJournal(sourceHash, snapshot.replay, snapshot.hostCalls);\n return {\n checkpointDigest: bytesToHex(sha256(new TextEncoder().encode(canonicalData(snapshot)))),\n sourceHash,\n executionSemantics: snapshot.executionSemantics,\n calls: replay.calls,\n unresolvedCalls: replay.calls.filter(\n (call) => ![\"settled\", \"consumed\"].includes(call.lifecycle)\n )\n };\n}\n\nexport function migrateSnapshot(\n snapshot: SafeJSSnapshot,\n options: SnapshotMigrationOptions\n): SafeJSSnapshot & { migration: SnapshotMigration } {\n if (!Object.hasOwn(options, \"state\"))\n throw new TypeError(\"Migration requires explicit application state.\");\n const inspection = inspectSnapshotMigration(snapshot, { source: options.source });\n parseModule(options.targetSource);\n const targetSourceHash = hashSource(options.targetSource);\n validateMigrationReconciliation(\n options.reconciliation,\n inspection.checkpointDigest,\n inspection.calls\n );\n const state = encodeReplayData(deepCopyToSandbox(options.state));\n const previous = snapshot.migration as SnapshotMigration | undefined;\n const migration: SnapshotMigration = {\n version: 1,\n state,\n history: [\n ...structuredClone(previous?.history ?? []),\n {\n sourceHash: inspection.sourceHash,\n targetSourceHash,\n executionSemantics: inspection.executionSemantics,\n replay: { version: 1, calls: inspection.calls },\n reconciliation: structuredClone(options.reconciliation)\n }\n ]\n };\n validateSnapshotMigration(migration, targetSourceHash);\n return {\n version: DUMP_FORMAT_VERSION,\n executionSemantics: EXECUTION_SEMANTICS,\n sourceHash: targetSourceHash,\n bindings: {},\n replay: { version: 1, calls: [] },\n migration\n };\n}\n\nfunction canonicalData(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalData).join(\",\")}]`;\n if (value !== null && typeof value === \"object\")\n return `{${Object.keys(value)\n .sort()\n .map(\n (key) => `${JSON.st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