@prisma/orm-toolchain 8.0.0-rc.2-dev.3 → 8.0.0-rc.20

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.
Files changed (196) hide show
  1. package/README.md +1 -5
  2. package/dist/{aggregate-DLUJLq5Y.d.mts → aggregate-BpcQdygS.d.mts} +83 -36
  3. package/dist/aggregate-BpcQdygS.d.mts.map +1 -0
  4. package/dist/{aggregate-CPZB020V.mjs → aggregate-T_HG6gq6.mjs} +118 -57
  5. package/dist/aggregate-T_HG6gq6.mjs.map +1 -0
  6. package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs +1026 -0
  7. package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs.map +1 -0
  8. package/dist/cli-telemetry.d.mts +9 -8
  9. package/dist/cli-telemetry.d.mts.map +1 -1
  10. package/dist/cli-telemetry.mjs +30 -27
  11. package/dist/cli-telemetry.mjs.map +1 -1
  12. package/dist/cli.d.mts +7 -14
  13. package/dist/cli.d.mts.map +1 -1
  14. package/dist/cli.mjs +3769 -1506
  15. package/dist/cli.mjs.map +1 -1
  16. package/dist/cli__control-api.d.mts +233 -93
  17. package/dist/cli__control-api.d.mts.map +1 -1
  18. package/dist/cli__control-api.mjs +3 -2
  19. package/dist/cli__control-api__testing.d.mts +5 -4
  20. package/dist/cli__control-api__testing.d.mts.map +1 -1
  21. package/dist/cli__control-api__testing.mjs +21 -16
  22. package/dist/cli__control-api__testing.mjs.map +1 -1
  23. package/dist/cli__init-output.d.mts +11 -1
  24. package/dist/cli__init-output.d.mts.map +1 -1
  25. package/dist/cli__init-output.mjs +1 -1
  26. package/dist/cli__migration-cli.d.mts +1 -1
  27. package/dist/cli__migration-cli.mjs +65 -19
  28. package/dist/cli__migration-cli.mjs.map +1 -1
  29. package/dist/config-loader.d.mts +2 -2
  30. package/dist/config-loader.mjs +2 -2
  31. package/dist/{contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs → contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs} +44 -16
  32. package/dist/contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs.map +1 -0
  33. package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts +59 -0
  34. package/dist/contract-snapshot-store-Bok5nQYi-D3g_P7im.d.mts.map +1 -0
  35. package/dist/contract-snapshot-store-DrIwu5pn.d.mts +2 -0
  36. package/dist/{db-verify-BwgNK50T-DGvKgFCK.d.mts → db-sign-gvrl0kFE-D-nTGx88.d.mts} +330 -230
  37. package/dist/db-sign-gvrl0kFE-D-nTGx88.d.mts.map +1 -0
  38. package/dist/{domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs → domain-type-generation-B4m774CV-WAjyhZHw.mjs} +144 -154
  39. package/dist/domain-type-generation-B4m774CV-WAjyhZHw.mjs.map +1 -0
  40. package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts +78 -0
  41. package/dist/domain-type-generation-DZjtzrbE-BpOOD3YV.d.mts.map +1 -0
  42. package/dist/emitter.d.mts +3 -3
  43. package/dist/emitter.mjs +3 -3
  44. package/dist/emitter__domain-type-generation.d.mts +2 -2
  45. package/dist/emitter__domain-type-generation.mjs +2 -2
  46. package/dist/{errors-D59OCpoI.d.mts → errors-CLwhWJiz.d.mts} +14 -3
  47. package/dist/errors-CLwhWJiz.d.mts.map +1 -0
  48. package/dist/{errors-CXbGUWGu-CstQHPh6.mjs → errors-DXha_4l--relAaiI4.mjs} +37 -42
  49. package/dist/errors-DXha_4l--relAaiI4.mjs.map +1 -0
  50. package/dist/exports-BCIlMjIW-DkUBVDzl.mjs +421 -0
  51. package/dist/exports-BCIlMjIW-DkUBVDzl.mjs.map +1 -0
  52. package/dist/exports-BlYTE3-J.mjs +539 -0
  53. package/dist/exports-BlYTE3-J.mjs.map +1 -0
  54. package/dist/exports-CKgwcXbp.mjs +3973 -0
  55. package/dist/exports-CKgwcXbp.mjs.map +1 -0
  56. package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs +19 -0
  57. package/dist/graph-membership-DxpNgxfZ-BfqA-H7V.mjs.map +1 -0
  58. package/dist/{hash-DH8hl5Rq-BpM2t3Nu.mjs → hash-BAZVWU4a-BQovI7hF.mjs} +24 -3
  59. package/dist/hash-BAZVWU4a-BQovI7hF.mjs.map +1 -0
  60. package/dist/hash-CwWGlFWV.d.mts +1 -0
  61. package/dist/{hash-XZYYKJ-i.d.mts → hash-DclMqd7S-WBvXJ_4C.d.mts} +17 -4
  62. package/dist/hash-DclMqd7S-WBvXJ_4C.d.mts.map +1 -0
  63. package/dist/{import-roots-CfoYgejL.d.mts → import-roots-ARK1wjzc.d.mts} +3 -3
  64. package/dist/{import-roots-CfoYgejL.d.mts.map → import-roots-ARK1wjzc.d.mts.map} +1 -1
  65. package/dist/{import-roots-CNFBPAT1.mjs → import-roots-BPn2s_fq.mjs} +6 -6
  66. package/dist/import-roots-BPn2s_fq.mjs.map +1 -0
  67. package/dist/index-CWPFeYyi.d.mts +204 -0
  68. package/dist/index-CWPFeYyi.d.mts.map +1 -0
  69. package/dist/{index-Dgwl8Tzs.d.mts → index-tAySVPvZ.d.mts} +16 -4
  70. package/dist/index-tAySVPvZ.d.mts.map +1 -0
  71. package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs → invariants-DrF9p5Gd-BF70vGl1.mjs} +3 -3
  72. package/dist/{invariants-CTHy88OP-CYI2a8IO.mjs.map → invariants-DrF9p5Gd-BF70vGl1.mjs.map} +1 -1
  73. package/dist/{io-635GlNx1-D3zrw2qu.mjs → io-BNxFm3eg-DYD82QeZ.mjs} +8 -8
  74. package/dist/io-BNxFm3eg-DYD82QeZ.mjs.map +1 -0
  75. package/dist/io-D8Epu7iY.d.mts +1 -0
  76. package/dist/{io-sr4CO9_t-C3eV_kn-.d.mts → io-DZfMV51z-BKlH5Dhb.d.mts} +9 -2
  77. package/dist/io-DZfMV51z-BKlH5Dhb.d.mts.map +1 -0
  78. package/dist/{migration-B2ljMJim.d.mts → migration-Bjz05034.d.mts} +12 -5
  79. package/dist/migration-Bjz05034.d.mts.map +1 -0
  80. package/dist/{migration-hspPIEeV.mjs → migration-CWyjX9vz.mjs} +18 -6
  81. package/dist/migration-CWyjX9vz.mjs.map +1 -0
  82. package/dist/{migration-graph-_SJImD5V-BURyY1KM.mjs → migration-graph-BoiiZAaU-DLht12k7.mjs} +6 -89
  83. package/dist/migration-graph-BoiiZAaU-DLht12k7.mjs.map +1 -0
  84. package/dist/{migration-graph-tarTxJ99-BrGBANeE.d.mts → migration-graph-D8IuOkZb-pSI7-k4_.d.mts} +7 -29
  85. package/dist/migration-graph-D8IuOkZb-pSI7-k4_.d.mts.map +1 -0
  86. package/dist/migration-graph-Dra4CcyN.d.mts +14 -0
  87. package/dist/migration-graph-Dra4CcyN.d.mts.map +1 -0
  88. package/dist/migration-tools.d.mts +17 -15
  89. package/dist/migration-tools.mjs +15 -15
  90. package/dist/migration-tools__aggregate.d.mts +2 -2
  91. package/dist/migration-tools__aggregate.mjs +2 -2
  92. package/dist/migration-tools__contract-snapshot-store.d.mts +4 -2
  93. package/dist/migration-tools__contract-snapshot-store.mjs +2 -2
  94. package/dist/migration-tools__errors.d.mts +2 -2
  95. package/dist/migration-tools__errors.mjs +1 -1
  96. package/dist/migration-tools__hash.d.mts +2 -1
  97. package/dist/migration-tools__hash.mjs +1 -1
  98. package/dist/migration-tools__invariants.mjs +1 -1
  99. package/dist/migration-tools__io.d.mts +2 -2
  100. package/dist/migration-tools__io.mjs +1 -1
  101. package/dist/migration-tools__migration-graph.d.mts +3 -3
  102. package/dist/migration-tools__migration-graph.mjs +3 -3
  103. package/dist/migration-tools__migration-ts.d.mts +2 -2
  104. package/dist/migration-tools__migration-ts.mjs +2 -2
  105. package/dist/migration-tools__migration.d.mts +1 -1
  106. package/dist/migration-tools__migration.mjs +1 -1
  107. package/dist/migration-tools__ref-resolution.d.mts +2 -2
  108. package/dist/migration-tools__ref-resolution.mjs +2 -2
  109. package/dist/migration-tools__refs.mjs +1 -1
  110. package/dist/migration-tools__spaces.d.mts +1 -1
  111. package/dist/migration-tools__spaces.mjs +2 -2
  112. package/dist/{migration-ts-DdVm0rws.mjs → migration-ts-DDgjsR1O.mjs} +6 -5
  113. package/dist/migration-ts-DDgjsR1O.mjs.map +1 -0
  114. package/dist/{migration-ts-CNaAtK8C.d.mts → migration-ts-SGer0PXq.d.mts} +4 -2
  115. package/dist/migration-ts-SGer0PXq.d.mts.map +1 -0
  116. package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs +23 -0
  117. package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs.map +1 -0
  118. package/dist/output-BcC8eB0h-C5bRd-aC.mjs +129 -0
  119. package/dist/output-BcC8eB0h-C5bRd-aC.mjs.map +1 -0
  120. package/dist/publish-surface.d.mts +1 -1
  121. package/dist/publish-surface.mjs +2 -2
  122. package/dist/publish-surface__import-roots.d.mts +1 -1
  123. package/dist/publish-surface__import-roots.mjs +1 -1
  124. package/dist/publish-surface__shells.mjs +1 -1
  125. package/dist/quick-reference-mongo.md +12 -12
  126. package/dist/quick-reference-postgres.md +10 -10
  127. package/dist/quick-reference-prisma7.md +80 -0
  128. package/dist/readme-mongo.md +6 -6
  129. package/dist/readme-postgres.md +6 -6
  130. package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs +6663 -0
  131. package/dist/ref-DEiY2Cbd-1ZImpUEN.mjs.map +1 -0
  132. package/dist/{ref-resolution-COGOSL57.d.mts → ref-resolution-BPhR-kta.d.mts} +29 -11
  133. package/dist/ref-resolution-BPhR-kta.d.mts.map +1 -0
  134. package/dist/{ref-resolution-HeNBXW53.mjs → ref-resolution-Eo0QHp4f.mjs} +30 -6
  135. package/dist/ref-resolution-Eo0QHp4f.mjs.map +1 -0
  136. package/dist/{refs-WK86uYYp-gM8tvWQP.mjs → refs-DM3q3IZC-BC6H6P0X.mjs} +9 -9
  137. package/dist/refs-DM3q3IZC-BC6H6P0X.mjs.map +1 -0
  138. package/dist/{shells-C4HbRAr5.mjs → shells-w_yEDhe8.mjs} +98 -31
  139. package/dist/shells-w_yEDhe8.mjs.map +1 -0
  140. package/dist/{spaces-Dj65JrwZ.d.mts → spaces-BWULKO54.d.mts} +3 -3
  141. package/dist/{spaces-Dj65JrwZ.d.mts.map → spaces-BWULKO54.d.mts.map} +1 -1
  142. package/dist/{spaces-4qMOAYE9.mjs → spaces-c9xdiXW8.mjs} +14 -13
  143. package/dist/spaces-c9xdiXW8.mjs.map +1 -0
  144. package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs} +7 -7
  145. package/dist/{verify-contract-spaces-DhJTb0zM-B62maCfE.mjs.map → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs.map} +1 -1
  146. package/dist/vite-plugin-contract-emit.d.mts +1 -1
  147. package/dist/vite-plugin-contract-emit.mjs +10 -10
  148. package/dist/vite-plugin-contract-emit.mjs.map +1 -1
  149. package/package.json +16 -15
  150. package/dist/aggregate-CPZB020V.mjs.map +0 -1
  151. package/dist/aggregate-DLUJLq5Y.d.mts.map +0 -1
  152. package/dist/contract-snapshot-store-B0G1Fw_F-CHc4QfKb.mjs.map +0 -1
  153. package/dist/contract-snapshot-store-CbqynbtE.d.mts +0 -28
  154. package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +0 -1
  155. package/dist/db-verify-BwgNK50T-DGvKgFCK.d.mts.map +0 -1
  156. package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +0 -63
  157. package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +0 -1
  158. package/dist/domain-type-generation-bpSO3Y0L-jo2C7LlH.mjs.map +0 -1
  159. package/dist/errors-CXbGUWGu-CstQHPh6.mjs.map +0 -1
  160. package/dist/errors-D59OCpoI.d.mts.map +0 -1
  161. package/dist/exports-8ZUN43ve.mjs +0 -1734
  162. package/dist/exports-8ZUN43ve.mjs.map +0 -1
  163. package/dist/exports-BCLg4CiV-05kuwcb0.mjs +0 -160
  164. package/dist/exports-BCLg4CiV-05kuwcb0.mjs.map +0 -1
  165. package/dist/exports-BZaG8_w_.mjs +0 -243
  166. package/dist/exports-BZaG8_w_.mjs.map +0 -1
  167. package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs +0 -14
  168. package/dist/graph-membership-BViWUMpP-C4lYYJdU.mjs.map +0 -1
  169. package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +0 -1
  170. package/dist/hash-XZYYKJ-i.d.mts.map +0 -1
  171. package/dist/import-roots-CNFBPAT1.mjs.map +0 -1
  172. package/dist/index-DRs7L6N0.d.mts +0 -57
  173. package/dist/index-DRs7L6N0.d.mts.map +0 -1
  174. package/dist/index-Dgwl8Tzs.d.mts.map +0 -1
  175. package/dist/io-635GlNx1-D3zrw2qu.mjs.map +0 -1
  176. package/dist/io-DYfeLJxR.d.mts +0 -1
  177. package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +0 -1
  178. package/dist/migration-B2ljMJim.d.mts.map +0 -1
  179. package/dist/migration-graph-Dqndu0i5.d.mts +0 -9
  180. package/dist/migration-graph-Dqndu0i5.d.mts.map +0 -1
  181. package/dist/migration-graph-_SJImD5V-BURyY1KM.mjs.map +0 -1
  182. package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +0 -1
  183. package/dist/migration-hspPIEeV.mjs.map +0 -1
  184. package/dist/migration-ts-CNaAtK8C.d.mts.map +0 -1
  185. package/dist/migration-ts-DdVm0rws.mjs.map +0 -1
  186. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +0 -13
  187. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +0 -1
  188. package/dist/output-CovTDY14-CUoAqLML.mjs +0 -77
  189. package/dist/output-CovTDY14-CUoAqLML.mjs.map +0 -1
  190. package/dist/ref-h6InR6dO-rGfl18Jv.mjs +0 -4686
  191. package/dist/ref-h6InR6dO-rGfl18Jv.mjs.map +0 -1
  192. package/dist/ref-resolution-COGOSL57.d.mts.map +0 -1
  193. package/dist/ref-resolution-HeNBXW53.mjs.map +0 -1
  194. package/dist/refs-WK86uYYp-gM8tvWQP.mjs.map +0 -1
  195. package/dist/shells-C4HbRAr5.mjs.map +0 -1
  196. 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-CXbGUWGu-CstQHPh6.mjs";
2
- import { blindCast } from "@prisma/orm-framework/utils/casts";
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
- //#region ../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-B0G1Fw_F.mjs
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
- async function readContractSnapshotJson(migrationsDir, storageHash) {
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
- return JSON.parse(raw);
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
- const parsed = JSON.parse(raw);
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
- return await readFile(dtsPath, "utf-8");
133
+ verifyContent?.assertSnapshotContentMatches(parsed, storageHash, jsonPath);
107
134
  } catch (error) {
108
- if (hasErrnoCode(error, "ENOENT")) throw errorContractSnapshotMissing(storageHash, dtsPath);
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, readContractSnapshotDts as n, writeContractSnapshot as o, readContractSnapshotJson as r, contractSnapshotDir as t };
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-B0G1Fw_F-CHc4QfKb.mjs.map
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"}
@@ -0,0 +1,2 @@
1
+ import "./hash-DclMqd7S-WBvXJ_4C.mjs";
2
+ import "./contract-snapshot-store-Bok5nQYi-D3g_P7im.mjs";