@prisma/orm-toolchain 8.0.0-rc.2-dev.3 → 8.0.0-rc.20-dev.1
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 +1 -5
- package/dist/{aggregate-DLUJLq5Y.d.mts → aggregate-BpcQdygS.d.mts} +83 -36
- package/dist/aggregate-BpcQdygS.d.mts.map +1 -0
- package/dist/{aggregate-CPZB020V.mjs → aggregate-T_HG6gq6.mjs} +118 -57
- package/dist/aggregate-T_HG6gq6.mjs.map +1 -0
- package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs +1026 -0
- package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs.map +1 -0
- package/dist/cli-telemetry.d.mts +9 -8
- package/dist/cli-telemetry.d.mts.map +1 -1
- package/dist/cli-telemetry.mjs +30 -27
- package/dist/cli-telemetry.mjs.map +1 -1
- package/dist/cli.d.mts +7 -14
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +3769 -1506
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +233 -93
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +3 -2
- package/dist/cli__control-api__testing.d.mts +5 -4
- package/dist/cli__control-api__testing.d.mts.map +1 -1
- package/dist/cli__control-api__testing.mjs +21 -16
- package/dist/cli__control-api__testing.mjs.map +1 -1
- package/dist/cli__init-output.d.mts +11 -1
- package/dist/cli__init-output.d.mts.map +1 -1
- package/dist/cli__init-output.mjs +1 -1
- package/dist/cli__migration-cli.d.mts +1 -1
- package/dist/cli__migration-cli.mjs +65 -19
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.d.mts +2 -2
- package/dist/config-loader.mjs +2 -2
- package/dist/{contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs → contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs} +44 -16
- package/dist/contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs.map +1 -0
- package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts +59 -0
- package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts.map +1 -0
- package/dist/contract-snapshot-store-DrIwu5pn.d.mts +2 -0
- package/dist/{db-verify-BwgNK50T-DGvKgFCK.d.mts → db-sign-gvrl0kFE-D-nTGx88.d.mts} +330 -230
- package/dist/db-sign-gvrl0kFE-D-nTGx88.d.mts.map +1 -0
- package/dist/{domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs → domain-type-generation-B4m774CV-WAjyhZHw.mjs} +144 -154
- package/dist/domain-type-generation-B4m774CV-WAjyhZHw.mjs.map +1 -0
- package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts +78 -0
- package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts.map +1 -0
- package/dist/emitter.d.mts +3 -3
- package/dist/emitter.mjs +3 -3
- package/dist/emitter__domain-type-generation.d.mts +2 -2
- package/dist/emitter__domain-type-generation.mjs +2 -2
- package/dist/{errors-D59OCpoI.d.mts → errors-CLwhWJiz.d.mts} +14 -3
- package/dist/errors-CLwhWJiz.d.mts.map +1 -0
- package/dist/{errors-CXbGUWGu-CstQHPh6.mjs → errors-DXha_4l--relAaiI4.mjs} +37 -42
- package/dist/errors-DXha_4l--relAaiI4.mjs.map +1 -0
- package/dist/exports-BCIlMjIW-DkUBVDzl.mjs +421 -0
- package/dist/exports-BCIlMjIW-DkUBVDzl.mjs.map +1 -0
- package/dist/exports-BlYTE3-J.mjs +539 -0
- package/dist/exports-BlYTE3-J.mjs.map +1 -0
- package/dist/exports-CKgwcXbp.mjs +3973 -0
- package/dist/exports-CKgwcXbp.mjs.map +1 -0
- package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs +19 -0
- package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs.map +1 -0
- package/dist/{hash-DH8hl5Rq-BpM2t3Nu.mjs → hash-BAZVWU4a-BQovI7hF.mjs} +24 -3
- package/dist/hash-BAZVWU4a-BQovI7hF.mjs.map +1 -0
- package/dist/hash-CwWGlFWV.d.mts +1 -0
- package/dist/{hash-XZYYKJ-i.d.mts → hash-DclMqd7S-WBvXJ_4C.d.mts} +17 -4
- package/dist/hash-DclMqd7S-WBvXJ_4C.d.mts.map +1 -0
- package/dist/{import-roots-CfoYgejL.d.mts → import-roots-ARK1wjzc.d.mts} +3 -3
- package/dist/{import-roots-CfoYgejL.d.mts.map → import-roots-ARK1wjzc.d.mts.map} +1 -1
- package/dist/{import-roots-CNFBPAT1.mjs → import-roots-BPn2s_fq.mjs} +6 -6
- package/dist/import-roots-BPn2s_fq.mjs.map +1 -0
- package/dist/index-CWPFeYyi.d.mts +204 -0
- package/dist/index-CWPFeYyi.d.mts.map +1 -0
- package/dist/{index-Dgwl8Tzs.d.mts → index-tAySVPvZ.d.mts} +16 -4
- package/dist/index-tAySVPvZ.d.mts.map +1 -0
- package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs → invariants-DrF9p5Gd-BF70vGl1.mjs} +3 -3
- package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs.map → invariants-DrF9p5Gd-BF70vGl1.mjs.map} +1 -1
- package/dist/{io-635GlNx1-D3zrw2qu.mjs → io-BNxFm3eg-DYD82QeZ.mjs} +8 -8
- package/dist/io-BNxFm3eg-DYD82QeZ.mjs.map +1 -0
- package/dist/io-D8Epu7iY.d.mts +1 -0
- package/dist/{io-sr4CO9_t-C3eV_kn-.d.mts → io-DZfMV51z-BKlH5Dhb.d.mts} +9 -2
- package/dist/io-DZfMV51z-BKlH5Dhb.d.mts.map +1 -0
- package/dist/{migration-B2ljMJim.d.mts → migration-Bjz05034.d.mts} +12 -5
- package/dist/migration-Bjz05034.d.mts.map +1 -0
- package/dist/{migration-hspPIEeV.mjs → migration-CWyjX9vz.mjs} +18 -6
- package/dist/migration-CWyjX9vz.mjs.map +1 -0
- package/dist/{migration-graph-_SJImD5V-BURyY1KM.mjs → migration-graph-BoiiZAaU-DLht12k7.mjs} +6 -89
- package/dist/migration-graph-BoiiZAaU-DLht12k7.mjs.map +1 -0
- package/dist/{migration-graph-tarTxJ99-BrGBANeE.d.mts → migration-graph-D8IuOkZb-pSI7-k4_.d.mts} +7 -29
- package/dist/migration-graph-D8IuOkZb-pSI7-k4_.d.mts.map +1 -0
- package/dist/migration-graph-Dra4CcyN.d.mts +14 -0
- package/dist/migration-graph-Dra4CcyN.d.mts.map +1 -0
- package/dist/migration-tools.d.mts +17 -15
- package/dist/migration-tools.mjs +15 -15
- package/dist/migration-tools__aggregate.d.mts +2 -2
- package/dist/migration-tools__aggregate.mjs +2 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +4 -2
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -2
- package/dist/migration-tools__errors.d.mts +2 -2
- package/dist/migration-tools__errors.mjs +1 -1
- package/dist/migration-tools__hash.d.mts +2 -1
- package/dist/migration-tools__hash.mjs +1 -1
- package/dist/migration-tools__invariants.mjs +1 -1
- package/dist/migration-tools__io.d.mts +2 -2
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.d.mts +3 -3
- package/dist/migration-tools__migration-graph.mjs +3 -3
- package/dist/migration-tools__migration-ts.d.mts +2 -2
- package/dist/migration-tools__migration-ts.mjs +2 -2
- package/dist/migration-tools__migration.d.mts +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.d.mts +2 -2
- package/dist/migration-tools__ref-resolution.mjs +2 -2
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.d.mts +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{migration-ts-DdVm0rws.mjs → migration-ts-DDgjsR1O.mjs} +6 -5
- package/dist/migration-ts-DDgjsR1O.mjs.map +1 -0
- package/dist/{migration-ts-CNaAtK8C.d.mts → migration-ts-SGer0PXq.d.mts} +4 -2
- package/dist/migration-ts-SGer0PXq.d.mts.map +1 -0
- package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs +23 -0
- package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs.map +1 -0
- package/dist/output-BcC8eB0h-C5bRd-aC.mjs +129 -0
- package/dist/output-BcC8eB0h-C5bRd-aC.mjs.map +1 -0
- package/dist/publish-surface.d.mts +1 -1
- package/dist/publish-surface.mjs +2 -2
- package/dist/publish-surface__import-roots.d.mts +1 -1
- package/dist/publish-surface__import-roots.mjs +1 -1
- package/dist/publish-surface__shells.mjs +1 -1
- package/dist/quick-reference-mongo.md +12 -12
- package/dist/quick-reference-postgres.md +10 -10
- package/dist/quick-reference-prisma7.md +80 -0
- package/dist/readme-mongo.md +6 -6
- package/dist/readme-postgres.md +6 -6
- package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs +6663 -0
- package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs.map +1 -0
- package/dist/{ref-resolution-COGOSL57.d.mts → ref-resolution-BPhR-kta.d.mts} +29 -11
- package/dist/ref-resolution-BPhR-kta.d.mts.map +1 -0
- package/dist/{ref-resolution-HeNBXW53.mjs → ref-resolution-Eo0QHp4f.mjs} +30 -6
- package/dist/ref-resolution-Eo0QHp4f.mjs.map +1 -0
- package/dist/{refs-WK86uYYp-gM8tvWQP.mjs → refs-DM3q3IZC-BC6H6P0X.mjs} +9 -9
- package/dist/refs-DM3q3IZC-BC6H6P0X.mjs.map +1 -0
- package/dist/{shells-C4HbRAr5.mjs → shells-w_yEDhe8.mjs} +98 -31
- package/dist/shells-w_yEDhe8.mjs.map +1 -0
- package/dist/{spaces-Dj65JrwZ.d.mts → spaces-BWULKO54.d.mts} +3 -3
- package/dist/{spaces-Dj65JrwZ.d.mts.map → spaces-BWULKO54.d.mts.map} +1 -1
- package/dist/{spaces-4qMOAYE9.mjs → spaces-c9xdiXW8.mjs} +14 -13
- package/dist/spaces-c9xdiXW8.mjs.map +1 -0
- package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs} +7 -7
- package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs.map → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.d.mts +1 -1
- package/dist/vite-plugin-contract-emit.mjs +10 -10
- package/dist/vite-plugin-contract-emit.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/aggregate-CPZB020V.mjs.map +0 -1
- package/dist/aggregate-DLUJLq5Y.d.mts.map +0 -1
- package/dist/contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs.map +0 -1
- package/dist/contract-snapshot-store-CbqynbtE.d.mts +0 -28
- package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +0 -1
- package/dist/db-verify-BwgNK50T-DGvKgFCK.d.mts.map +0 -1
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +0 -63
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +0 -1
- package/dist/domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs.map +0 -1
- package/dist/errors-CXbGUWGu-CstQHPh6.mjs.map +0 -1
- package/dist/errors-D59OCpoI.d.mts.map +0 -1
- package/dist/exports-8ZUN43ve.mjs +0 -1734
- package/dist/exports-8ZUN43ve.mjs.map +0 -1
- package/dist/exports-BCLg4CiV-05kuwcb0.mjs +0 -160
- package/dist/exports-BCLg4CiV-05kuwcb0.mjs.map +0 -1
- package/dist/exports-BZaG8_w_.mjs +0 -243
- package/dist/exports-BZaG8_w_.mjs.map +0 -1
- package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs +0 -14
- package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs.map +0 -1
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +0 -1
- package/dist/hash-XZYYKJ-i.d.mts.map +0 -1
- package/dist/import-roots-CNFBPAT1.mjs.map +0 -1
- package/dist/index-DRs7L6N0.d.mts +0 -57
- package/dist/index-DRs7L6N0.d.mts.map +0 -1
- package/dist/index-Dgwl8Tzs.d.mts.map +0 -1
- package/dist/io-635GlNx1-D3zrw2qu.mjs.map +0 -1
- package/dist/io-DYfeLJxR.d.mts +0 -1
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +0 -1
- package/dist/migration-B2ljMJim.d.mts.map +0 -1
- package/dist/migration-graph-Dqndu0i5.d.mts +0 -9
- package/dist/migration-graph-Dqndu0i5.d.mts.map +0 -1
- package/dist/migration-graph-_SJImD5V-BURyY1KM.mjs.map +0 -1
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +0 -1
- package/dist/migration-hspPIEeV.mjs.map +0 -1
- package/dist/migration-ts-CNaAtK8C.d.mts.map +0 -1
- package/dist/migration-ts-DdVm0rws.mjs.map +0 -1
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +0 -13
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +0 -1
- package/dist/output-CovTDY14-CUoAqLML.mjs +0 -77
- package/dist/output-CovTDY14-CUoAqLML.mjs.map +0 -1
- package/dist/ref-h6InR6dO-rGfl18Jv.mjs +0 -4686
- package/dist/ref-h6InR6dO-rGfl18Jv.mjs.map +0 -1
- package/dist/ref-resolution-COGOSL57.d.mts.map +0 -1
- package/dist/ref-resolution-HeNBXW53.mjs.map +0 -1
- package/dist/refs-WK86uYYp-gM8tvWQP.mjs.map +0 -1
- package/dist/shells-C4HbRAr5.mjs.map +0 -1
- package/dist/spaces-4qMOAYE9.mjs.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a as errorContractSnapshotHashMismatch, g as errorInvalidJson, o as errorContractSnapshotMissing } from "./errors-
|
|
2
|
-
import {
|
|
1
|
+
import { a as errorContractSnapshotHashMismatch, g as errorInvalidJson, i as errorContractSnapshotContentMismatch, o as errorContractSnapshotMissing, t as MigrationToolsError } from "./errors-DXha_4l--relAaiI4.mjs";
|
|
2
|
+
import { n as recomputePublishedStorageHash } from "./hash-BAZVWU4a-BQovI7hF.mjs";
|
|
3
3
|
import { CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex } from "@prisma/orm-framework/components/control";
|
|
4
4
|
import { join, relative } from "pathe";
|
|
5
5
|
import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { randomBytes } from "node:crypto";
|
|
7
7
|
import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
|
|
8
|
-
|
|
8
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
9
|
+
//#region ../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-6gIBcUeb.mjs
|
|
9
10
|
const CONTRACT_JSON_FILE = "contract.json";
|
|
10
11
|
const CONTRACT_DTS_FILE = "contract.d.ts";
|
|
11
12
|
function hasErrnoCode(error, code) {
|
|
@@ -22,6 +23,22 @@ async function directoryExists(p) {
|
|
|
22
23
|
function contractSnapshotDir(migrationsDir, storageHash) {
|
|
23
24
|
return join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex(storageHash));
|
|
24
25
|
}
|
|
26
|
+
function createSnapshotContentVerifier(hooks) {
|
|
27
|
+
return { assertSnapshotContentMatches(contractJson, storageHash, jsonPath) {
|
|
28
|
+
const record = blindCast(contractJson ?? {});
|
|
29
|
+
const computedHash = recomputePublishedStorageHash({
|
|
30
|
+
target: record.target,
|
|
31
|
+
targetFamily: record.targetFamily,
|
|
32
|
+
storage: record.storage,
|
|
33
|
+
hooks
|
|
34
|
+
});
|
|
35
|
+
if (computedHash !== storageHash) throw errorContractSnapshotContentMismatch({
|
|
36
|
+
storageHash,
|
|
37
|
+
computedHash,
|
|
38
|
+
jsonPath
|
|
39
|
+
});
|
|
40
|
+
} };
|
|
41
|
+
}
|
|
25
42
|
async function writeContractSnapshot(migrationsDir, storageHash, input) {
|
|
26
43
|
const dir = contractSnapshotDir(migrationsDir, storageHash);
|
|
27
44
|
const actualStorageHash = blindCast(input.contractJson).storage?.storageHash;
|
|
@@ -54,7 +71,13 @@ async function writeContractSnapshot(migrationsDir, storageHash, input) {
|
|
|
54
71
|
dir
|
|
55
72
|
};
|
|
56
73
|
}
|
|
57
|
-
|
|
74
|
+
/**
|
|
75
|
+
* When `verifyContent` is supplied, the parsed snapshot's content is checked
|
|
76
|
+
* against the hash it was addressed by before being returned — the store is
|
|
77
|
+
* content-addressed, and a snapshot edited in place under an unchanged hash
|
|
78
|
+
* would otherwise flow into planning as if it were the recorded contract.
|
|
79
|
+
*/
|
|
80
|
+
async function readContractSnapshotJson(migrationsDir, storageHash, verifyContent) {
|
|
58
81
|
const jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);
|
|
59
82
|
let raw;
|
|
60
83
|
try {
|
|
@@ -63,11 +86,14 @@ async function readContractSnapshotJson(migrationsDir, storageHash) {
|
|
|
63
86
|
if (hasErrnoCode(error, "ENOENT")) throw errorContractSnapshotMissing(storageHash, jsonPath);
|
|
64
87
|
throw error;
|
|
65
88
|
}
|
|
89
|
+
let parsed;
|
|
66
90
|
try {
|
|
67
|
-
|
|
91
|
+
parsed = JSON.parse(raw);
|
|
68
92
|
} catch (e) {
|
|
69
93
|
throw errorInvalidJson(jsonPath, e instanceof Error ? e.message : String(e));
|
|
70
94
|
}
|
|
95
|
+
verifyContent?.assertSnapshotContentMatches(parsed, storageHash, jsonPath);
|
|
96
|
+
return parsed;
|
|
71
97
|
}
|
|
72
98
|
/**
|
|
73
99
|
* Tolerant read: a missing store entry (ENOENT), an unparseable
|
|
@@ -77,9 +103,12 @@ async function readContractSnapshotJson(migrationsDir, storageHash) {
|
|
|
77
103
|
* `readEndContractJson` (`io.ts`), which never validated the hash it was
|
|
78
104
|
* keyed by either. Any other fs error (e.g. `EACCES` on a present-but-
|
|
79
105
|
* unreadable file) propagates rather than silently loading a contract-less
|
|
80
|
-
* package.
|
|
106
|
+
* package. When `verifyContent` is supplied, an entry whose content does not
|
|
107
|
+
* recompute to its address also resolves to `undefined` — tampered content
|
|
108
|
+
* must not flow onward, and the strict store reads report the same file
|
|
109
|
+
* loudly as `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`.
|
|
81
110
|
*/
|
|
82
|
-
async function readContractSnapshotJsonTolerant(migrationsDir, storageHash) {
|
|
111
|
+
async function readContractSnapshotJsonTolerant(migrationsDir, storageHash, verifyContent) {
|
|
83
112
|
let jsonPath;
|
|
84
113
|
try {
|
|
85
114
|
jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);
|
|
@@ -93,26 +122,25 @@ async function readContractSnapshotJsonTolerant(migrationsDir, storageHash) {
|
|
|
93
122
|
if (hasErrnoCode(error, "ENOENT")) return;
|
|
94
123
|
throw error;
|
|
95
124
|
}
|
|
125
|
+
let parsed;
|
|
96
126
|
try {
|
|
97
|
-
|
|
98
|
-
return parsed === null ? void 0 : parsed;
|
|
127
|
+
parsed = JSON.parse(raw);
|
|
99
128
|
} catch {
|
|
100
129
|
return;
|
|
101
130
|
}
|
|
102
|
-
|
|
103
|
-
async function readContractSnapshotDts(migrationsDir, storageHash) {
|
|
104
|
-
const dtsPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_DTS_FILE);
|
|
131
|
+
if (parsed === null) return;
|
|
105
132
|
try {
|
|
106
|
-
|
|
133
|
+
verifyContent?.assertSnapshotContentMatches(parsed, storageHash, jsonPath);
|
|
107
134
|
} catch (error) {
|
|
108
|
-
if (
|
|
135
|
+
if (MigrationToolsError.is(error) && error.code === "MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH") return;
|
|
109
136
|
throw error;
|
|
110
137
|
}
|
|
138
|
+
return parsed;
|
|
111
139
|
}
|
|
112
140
|
function snapshotsImportPathFrom(packageDir, migrationsDir) {
|
|
113
141
|
return relative(packageDir, join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME)).split("\\").join("/");
|
|
114
142
|
}
|
|
115
143
|
//#endregion
|
|
116
|
-
export { snapshotsImportPathFrom as a, readContractSnapshotJsonTolerant as i,
|
|
144
|
+
export { snapshotsImportPathFrom as a, readContractSnapshotJsonTolerant as i, createSnapshotContentVerifier as n, writeContractSnapshot as o, readContractSnapshotJson as r, contractSnapshotDir as t };
|
|
117
145
|
|
|
118
|
-
//# sourceMappingURL=contract-snapshot-store-
|
|
146
|
+
//# sourceMappingURL=contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs","names":[],"sources":["../../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-6gIBcUeb.mjs"],"sourcesContent":["import { a as errorContractSnapshotHashMismatch, g as errorInvalidJson, i as errorContractSnapshotContentMismatch, o as errorContractSnapshotMissing, t as MigrationToolsError } from \"./errors-DXha_4l-.mjs\";\nimport { n as recomputePublishedStorageHash } from \"./hash-BAZVWU4a.mjs\";\nimport { join, relative } from \"pathe\";\nimport { mkdir, readFile, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { randomBytes } from \"node:crypto\";\nimport { CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex } from \"@internal/framework-components/control\";\nimport { canonicalizeJson } from \"@internal/framework-components/utils\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/contract-snapshot-store.ts\nconst CONTRACT_JSON_FILE = \"contract.json\";\nconst CONTRACT_DTS_FILE = \"contract.d.ts\";\nfunction hasErrnoCode(error, code) {\n\treturn error instanceof Error && blindCast(error).code === code;\n}\nasync function directoryExists(p) {\n\ttry {\n\t\treturn (await stat(p)).isDirectory();\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) return false;\n\t\tthrow error;\n\t}\n}\nfunction contractSnapshotDir(migrationsDir, storageHash) {\n\treturn join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex(storageHash));\n}\nfunction createSnapshotContentVerifier(hooks) {\n\treturn { assertSnapshotContentMatches(contractJson, storageHash, jsonPath) {\n\t\tconst record = blindCast(contractJson ?? {});\n\t\tconst computedHash = recomputePublishedStorageHash({\n\t\t\ttarget: record.target,\n\t\t\ttargetFamily: record.targetFamily,\n\t\t\tstorage: record.storage,\n\t\t\thooks\n\t\t});\n\t\tif (computedHash !== storageHash) throw errorContractSnapshotContentMismatch({\n\t\t\tstorageHash,\n\t\t\tcomputedHash,\n\t\t\tjsonPath\n\t\t});\n\t} };\n}\nasync function writeContractSnapshot(migrationsDir, storageHash, input) {\n\tconst dir = contractSnapshotDir(migrationsDir, storageHash);\n\tconst actualStorageHash = blindCast(input.contractJson).storage?.storageHash;\n\tif (actualStorageHash !== storageHash) throw errorContractSnapshotHashMismatch(storageHash, typeof actualStorageHash === \"string\" ? actualStorageHash : String(actualStorageHash), dir);\n\tif (await directoryExists(dir)) return {\n\t\twritten: false,\n\t\tdir\n\t};\n\tconst tmpDir = join(join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME), `.tmp-${storageHashHex(storageHash)}-${Date.now()}-${randomBytes(4).toString(\"hex\")}`);\n\tawait mkdir(tmpDir, { recursive: true });\n\tconst jsonContent = `${canonicalizeJson(input.contractJson)}\\n`;\n\tconst dtsContent = input.contractDts.endsWith(\"\\n\") ? input.contractDts : `${input.contractDts}\\n`;\n\ttry {\n\t\tawait writeFile(join(tmpDir, CONTRACT_JSON_FILE), jsonContent);\n\t\tawait writeFile(join(tmpDir, CONTRACT_DTS_FILE), dtsContent);\n\t\tawait rename(tmpDir, dir);\n\t} catch (error) {\n\t\tawait rm(tmpDir, {\n\t\t\trecursive: true,\n\t\t\tforce: true\n\t\t});\n\t\tif (hasErrnoCode(error, \"EEXIST\") || hasErrnoCode(error, \"ENOTEMPTY\")) return {\n\t\t\twritten: false,\n\t\t\tdir\n\t\t};\n\t\tthrow error;\n\t}\n\treturn {\n\t\twritten: true,\n\t\tdir\n\t};\n}\n/**\n* When `verifyContent` is supplied, the parsed snapshot's content is checked\n* against the hash it was addressed by before being returned — the store is\n* content-addressed, and a snapshot edited in place under an unchanged hash\n* would otherwise flow into planning as if it were the recorded contract.\n*/\nasync function readContractSnapshotJson(migrationsDir, storageHash, verifyContent) {\n\tconst jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);\n\tlet raw;\n\ttry {\n\t\traw = await readFile(jsonPath, \"utf-8\");\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) throw errorContractSnapshotMissing(storageHash, jsonPath);\n\t\tthrow error;\n\t}\n\tlet parsed;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (e) {\n\t\tthrow errorInvalidJson(jsonPath, e instanceof Error ? e.message : String(e));\n\t}\n\tverifyContent?.assertSnapshotContentMatches(parsed, storageHash, jsonPath);\n\treturn parsed;\n}\n/**\n* Tolerant read: a missing store entry (ENOENT), an unparseable\n* `contract.json`, the JSON literal `null`, or a `storageHash` that isn't a\n* well-formed 64-hex value all resolve to `undefined` rather than\n* throwing — parity with the catch-all tolerance of the pre-store\n* `readEndContractJson` (`io.ts`), which never validated the hash it was\n* keyed by either. Any other fs error (e.g. `EACCES` on a present-but-\n* unreadable file) propagates rather than silently loading a contract-less\n* package. When `verifyContent` is supplied, an entry whose content does not\n* recompute to its address also resolves to `undefined` — tampered content\n* must not flow onward, and the strict store reads report the same file\n* loudly as `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`.\n*/\nasync function readContractSnapshotJsonTolerant(migrationsDir, storageHash, verifyContent) {\n\tlet jsonPath;\n\ttry {\n\t\tjsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);\n\t} catch {\n\t\treturn;\n\t}\n\tlet raw;\n\ttry {\n\t\traw = await readFile(jsonPath, \"utf-8\");\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) return;\n\t\tthrow error;\n\t}\n\tlet parsed;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\treturn;\n\t}\n\tif (parsed === null) return;\n\ttry {\n\t\tverifyContent?.assertSnapshotContentMatches(parsed, storageHash, jsonPath);\n\t} catch (error) {\n\t\tif (MigrationToolsError.is(error) && error.code === \"MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH\") return;\n\t\tthrow error;\n\t}\n\treturn parsed;\n}\nfunction snapshotsImportPathFrom(packageDir, migrationsDir) {\n\treturn relative(packageDir, join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME)).split(\"\\\\\").join(\"/\");\n}\n//#endregion\nexport { snapshotsImportPathFrom as a, readContractSnapshotJsonTolerant as i, createSnapshotContentVerifier as n, writeContractSnapshot as o, readContractSnapshotJson as r, contractSnapshotDir as t };\n\n//# sourceMappingURL=contract-snapshot-store-6gIBcUeb.mjs.map"],"mappings":"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"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as SnapshotCanonicalizationHooks } from "./hash-DclMqd7S-WBvXJ_4C.mjs";
|
|
2
|
+
//#region ../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-Bok5nQYi.d.mts
|
|
3
|
+
//#region src/contract-snapshot-store.d.ts
|
|
4
|
+
declare function contractSnapshotDir(migrationsDir: string, storageHash: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Recompute-and-compare integrity check for loaded contract snapshots,
|
|
7
|
+
* mirroring `verifyMigrationHash` for migration packages and
|
|
8
|
+
* `assertDescriptorSelfConsistency` for extension descriptors: the store is
|
|
9
|
+
* content-addressed, so the JSON read back for a hash must reproduce that
|
|
10
|
+
* hash. Every assertion recomputes — nothing is cached, so mutated or
|
|
11
|
+
* re-read content is always re-verified; repeated resolutions of the same
|
|
12
|
+
* snapshot are already deduplicated by the aggregate's result memo, so each
|
|
13
|
+
* file read is hashed once in practice. The recompute is coupled to
|
|
14
|
+
* the emit-time canonicalization: a release that changes the family hooks
|
|
15
|
+
* or hash canonicalization rules must regenerate (or migrate) existing
|
|
16
|
+
* snapshot stores, or every pre-existing snapshot reads as tampered.
|
|
17
|
+
*/
|
|
18
|
+
interface SnapshotContentVerifier {
|
|
19
|
+
/**
|
|
20
|
+
* Throws `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH` when
|
|
21
|
+
* `contractJson`'s content does not recompute to `storageHash` — the hash
|
|
22
|
+
* the snapshot at `jsonPath` was addressed by.
|
|
23
|
+
*/
|
|
24
|
+
assertSnapshotContentMatches(contractJson: unknown, storageHash: string, jsonPath: string): void;
|
|
25
|
+
}
|
|
26
|
+
declare function createSnapshotContentVerifier(hooks?: SnapshotCanonicalizationHooks): SnapshotContentVerifier;
|
|
27
|
+
interface ContractSnapshotInput {
|
|
28
|
+
readonly contractJson: unknown;
|
|
29
|
+
readonly contractDts: string;
|
|
30
|
+
}
|
|
31
|
+
declare function writeContractSnapshot(migrationsDir: string, storageHash: string, input: ContractSnapshotInput): Promise<{
|
|
32
|
+
readonly written: boolean;
|
|
33
|
+
readonly dir: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* When `verifyContent` is supplied, the parsed snapshot's content is checked
|
|
37
|
+
* against the hash it was addressed by before being returned — the store is
|
|
38
|
+
* content-addressed, and a snapshot edited in place under an unchanged hash
|
|
39
|
+
* would otherwise flow into planning as if it were the recorded contract.
|
|
40
|
+
*/
|
|
41
|
+
declare function readContractSnapshotJson(migrationsDir: string, storageHash: string, verifyContent?: SnapshotContentVerifier): Promise<unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Tolerant read: a missing store entry (ENOENT), an unparseable
|
|
44
|
+
* `contract.json`, the JSON literal `null`, or a `storageHash` that isn't a
|
|
45
|
+
* well-formed 64-hex value all resolve to `undefined` rather than
|
|
46
|
+
* throwing — parity with the catch-all tolerance of the pre-store
|
|
47
|
+
* `readEndContractJson` (`io.ts`), which never validated the hash it was
|
|
48
|
+
* keyed by either. Any other fs error (e.g. `EACCES` on a present-but-
|
|
49
|
+
* unreadable file) propagates rather than silently loading a contract-less
|
|
50
|
+
* package. When `verifyContent` is supplied, an entry whose content does not
|
|
51
|
+
* recompute to its address also resolves to `undefined` — tampered content
|
|
52
|
+
* must not flow onward, and the strict store reads report the same file
|
|
53
|
+
* loudly as `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`.
|
|
54
|
+
*/
|
|
55
|
+
declare function readContractSnapshotJsonTolerant(migrationsDir: string, storageHash: string, verifyContent?: SnapshotContentVerifier): Promise<unknown | undefined>;
|
|
56
|
+
declare function snapshotsImportPathFrom(packageDir: string, migrationsDir: string): string;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { readContractSnapshotJson as a, writeContractSnapshot as c, createSnapshotContentVerifier as i, SnapshotContentVerifier as n, readContractSnapshotJsonTolerant as o, contractSnapshotDir as r, snapshotsImportPathFrom as s, ContractSnapshotInput as t };
|
|
59
|
+
//# sourceMappingURL=contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts","names":[],"sources":["../../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-Bok5nQYi.d.mts"],"mappings":";;;iBAEiB,oBAAoB,uBAAuB;;;;;;;;;;;;;;UAclD;;;;;;EAMR,6BAA6B,uBAAuB,qBAAqB;;iBAE1D,8BAA8B,QAAQ,gCAAgC;UAC7E;WACC;WACA;;iBAEM,sBAAsB,uBAAuB,qBAAqB,OAAO,wBAAwB;WACvG;WACA;;;;;;;;iBAQM,yBAAyB,uBAAuB,qBAAqB,gBAAgB,0BAA0B;;;;;;;;;;;;;;iBAc/G,iCAAiC,uBAAuB,qBAAqB,gBAAgB,0BAA0B;iBACvH,wBAAwB,oBAAoB"}
|