@prisma-next/target-postgres 0.14.0-dev.9 → 0.14.0-dev.90

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 (266) hide show
  1. package/dist/authoring-BtsOWgI3.mjs +674 -0
  2. package/dist/authoring-BtsOWgI3.mjs.map +1 -0
  3. package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
  4. package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
  5. package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-B10ZZHzw.mjs} +4 -2
  6. package/dist/codec-ids-B10ZZHzw.mjs.map +1 -0
  7. package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-CI144z7g.d.mts} +4 -2
  8. package/dist/codec-ids-CI144z7g.d.mts.map +1 -0
  9. package/dist/codec-ids.d.mts +2 -2
  10. package/dist/codec-ids.mjs +2 -2
  11. package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-CTfT4U4O.d.mts} +4 -2
  12. package/dist/codec-types-CTfT4U4O.d.mts.map +1 -0
  13. package/dist/codec-types.d.mts +1 -1
  14. package/dist/{codecs--0A5_4Bq.d.mts → codecs-D7W9O0Xx.d.mts} +134 -4
  15. package/dist/codecs-D7W9O0Xx.d.mts.map +1 -0
  16. package/dist/codecs-DRbb26Or.mjs +955 -0
  17. package/dist/codecs-DRbb26Or.mjs.map +1 -0
  18. package/dist/codecs.d.mts +2 -2
  19. package/dist/codecs.mjs +3 -757
  20. package/dist/codecs.mjs.map +1 -1
  21. package/dist/contract-free.d.mts +33 -3
  22. package/dist/contract-free.d.mts.map +1 -1
  23. package/dist/contract-free.mjs +23 -7
  24. package/dist/contract-free.mjs.map +1 -1
  25. package/dist/control-policy-DtbkLLGv.mjs +1285 -0
  26. package/dist/control-policy-DtbkLLGv.mjs.map +1 -0
  27. package/dist/control.d.mts +2 -2
  28. package/dist/control.d.mts.map +1 -1
  29. package/dist/control.mjs +880 -36
  30. package/dist/control.mjs.map +1 -1
  31. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  32. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
  33. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
  34. package/dist/data-transform.d.mts +1 -1
  35. package/dist/{ddl-QDyOSeLc.mjs → ddl-GTTOvjx_.mjs} +128 -6
  36. package/dist/ddl-GTTOvjx_.mjs.map +1 -0
  37. package/dist/ddl.d.mts +3 -2
  38. package/dist/ddl.mjs +2 -2
  39. package/dist/default-normalizer.d.mts +1 -1
  40. package/dist/default-normalizer.d.mts.map +1 -1
  41. package/dist/default-normalizer.mjs +247 -1
  42. package/dist/default-normalizer.mjs.map +1 -0
  43. package/dist/descriptor-meta-CFQKLXl_.mjs +23 -0
  44. package/dist/descriptor-meta-CFQKLXl_.mjs.map +1 -0
  45. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  46. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  47. package/dist/diff-database-schema-GncqMuSI.mjs +305 -0
  48. package/dist/diff-database-schema-GncqMuSI.mjs.map +1 -0
  49. package/dist/diff-database-schema.d.mts +46 -0
  50. package/dist/diff-database-schema.d.mts.map +1 -0
  51. package/dist/diff-database-schema.mjs +2 -0
  52. package/dist/errors-DO-w0EUS.mjs +35 -0
  53. package/dist/errors-DO-w0EUS.mjs.map +1 -0
  54. package/dist/errors.d.mts +11 -9
  55. package/dist/errors.d.mts.map +1 -1
  56. package/dist/errors.mjs +1 -1
  57. package/dist/issue-planner.d.mts +35 -11
  58. package/dist/issue-planner.d.mts.map +1 -1
  59. package/dist/issue-planner.mjs +2 -2
  60. package/dist/migration.d.mts +5 -5
  61. package/dist/migration.d.mts.map +1 -1
  62. package/dist/migration.mjs +4 -4
  63. package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
  64. package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
  65. package/dist/native-type-normalizer.mjs +37 -1
  66. package/dist/native-type-normalizer.mjs.map +1 -0
  67. package/dist/nodes-DJC5B8Id.mjs +192 -0
  68. package/dist/nodes-DJC5B8Id.mjs.map +1 -0
  69. package/dist/nodes-Dv5eCSq9.d.mts +170 -0
  70. package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
  71. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Bn9zDx4_.d.mts} +114 -15
  72. package/dist/op-factory-call-Bn9zDx4_.d.mts.map +1 -0
  73. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-C38NzvQD.mjs} +469 -32
  74. package/dist/op-factory-call-C38NzvQD.mjs.map +1 -0
  75. package/dist/op-factory-call.d.mts +2 -2
  76. package/dist/op-factory-call.mjs +2 -2
  77. package/dist/pack.d.mts +321 -3
  78. package/dist/pack.d.mts.map +1 -1
  79. package/dist/pack.mjs +1 -1
  80. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
  81. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
  82. package/dist/planner-ddl-builders.d.mts +4 -6
  83. package/dist/planner-ddl-builders.d.mts.map +1 -1
  84. package/dist/planner-ddl-builders.mjs +2 -2
  85. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  86. package/dist/planner-identity-values.d.mts +8 -2
  87. package/dist/planner-identity-values.d.mts.map +1 -1
  88. package/dist/planner-identity-values.mjs +2 -2
  89. package/dist/planner-kql24i_F.mjs +390 -0
  90. package/dist/planner-kql24i_F.mjs.map +1 -0
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BEY1T0Xm.d.mts} +4 -4
  92. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BEY1T0Xm.d.mts.map} +1 -1
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-D7y-PEHK.mjs} +3 -3
  94. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-D7y-PEHK.mjs.map} +1 -1
  95. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  96. package/dist/planner-produced-postgres-migration.mjs +1 -1
  97. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-zqNfs2XZ.mjs} +5 -5
  98. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-zqNfs2XZ.mjs.map} +1 -1
  99. package/dist/planner-sql-checks.d.mts +2 -2
  100. package/dist/planner-sql-checks.d.mts.map +1 -1
  101. package/dist/planner-sql-checks.mjs +1 -1
  102. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  103. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  104. package/dist/planner-target-details.d.mts +1 -1
  105. package/dist/planner.d.mts +72 -17
  106. package/dist/planner.d.mts.map +1 -1
  107. package/dist/planner.mjs +3 -2
  108. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  109. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  110. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DM8sN1Ot.mjs} +45 -41
  111. package/dist/postgres-contract-view-DM8sN1Ot.mjs.map +1 -0
  112. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
  113. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
  114. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DbckK1su.d.mts} +58 -9
  115. package/dist/postgres-migration-DbckK1su.d.mts.map +1 -0
  116. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-arMSWU9b.mjs} +78 -45
  117. package/dist/postgres-migration-arMSWU9b.mjs.map +1 -0
  118. package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
  119. package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
  120. package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
  121. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
  122. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
  123. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
  124. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-Cm4DtiGA.mjs} +200 -11
  125. package/dist/postgres-schema-Cm4DtiGA.mjs.map +1 -0
  126. package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
  127. package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
  128. package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
  129. package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
  130. package/dist/render-ops.d.mts +1 -1
  131. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  132. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  133. package/dist/render-typescript.mjs +1 -1
  134. package/dist/resolve-ddl-schema-XyBaaenM.mjs +22 -0
  135. package/dist/resolve-ddl-schema-XyBaaenM.mjs.map +1 -0
  136. package/dist/rls-canonicalize.d.mts +27 -0
  137. package/dist/rls-canonicalize.d.mts.map +1 -0
  138. package/dist/rls-canonicalize.mjs +2 -0
  139. package/dist/runtime.d.mts +6 -8
  140. package/dist/runtime.d.mts.map +1 -1
  141. package/dist/runtime.mjs +3 -3
  142. package/dist/runtime.mjs.map +1 -1
  143. package/dist/schema-ir-annotations.d.mts +15 -0
  144. package/dist/schema-ir-annotations.d.mts.map +1 -0
  145. package/dist/schema-ir-annotations.mjs +2 -0
  146. package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
  147. package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
  148. package/dist/sql-utils.d.mts +8 -1
  149. package/dist/sql-utils.d.mts.map +1 -1
  150. package/dist/sql-utils.mjs +2 -2
  151. package/dist/types.d.mts +4 -140
  152. package/dist/types.mjs +5 -2
  153. package/dist/wire-name-DbQ9-2RC.mjs +104 -0
  154. package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
  155. package/package.json +26 -20
  156. package/src/contract-free/checks.ts +153 -0
  157. package/src/contract-free/control-bootstrap.ts +20 -3
  158. package/src/contract-free/ddl.ts +98 -1
  159. package/src/core/authoring.ts +726 -2
  160. package/src/core/codec-helpers.ts +33 -7
  161. package/src/core/codec-ids.ts +2 -0
  162. package/src/core/codec-type-map.ts +4 -0
  163. package/src/core/codecs.ts +236 -12
  164. package/src/core/ddl/nodes.ts +185 -2
  165. package/src/core/default-normalizer.ts +122 -2
  166. package/src/core/descriptor-meta.ts +12 -1
  167. package/src/core/entity-kinds.ts +41 -0
  168. package/src/core/errors.ts +14 -12
  169. package/src/core/migrations/bound-schema.ts +10 -0
  170. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  171. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
  172. package/src/core/migrations/control-policy.ts +217 -65
  173. package/src/core/migrations/diff-database-schema.ts +252 -0
  174. package/src/core/migrations/issue-planner.ts +817 -656
  175. package/src/core/migrations/op-factory-call.ts +383 -23
  176. package/src/core/migrations/operations/columns.ts +24 -12
  177. package/src/core/migrations/operations/constraints.ts +1 -1
  178. package/src/core/migrations/operations/data-transform.ts +6 -0
  179. package/src/core/migrations/operations/dependencies.ts +2 -1
  180. package/src/core/migrations/operations/native-enum-types.ts +62 -0
  181. package/src/core/migrations/operations/rls.ts +187 -0
  182. package/src/core/migrations/operations/shared.ts +0 -30
  183. package/src/core/migrations/planner-ddl-builders.ts +31 -59
  184. package/src/core/migrations/planner-identity-values.ts +1 -1
  185. package/src/core/migrations/planner-recipes.ts +31 -13
  186. package/src/core/migrations/planner-sql-checks.ts +1 -1
  187. package/src/core/migrations/planner-strategies.ts +248 -216
  188. package/src/core/migrations/planner-target-details.ts +3 -1
  189. package/src/core/migrations/planner.ts +357 -67
  190. package/src/core/migrations/postgres-migration.ts +118 -86
  191. package/src/core/migrations/render-typescript.ts +42 -15
  192. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  193. package/src/core/migrations/runner.ts +11 -16
  194. package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
  195. package/src/core/namespace-ids.ts +3 -0
  196. package/src/core/postgres-contract-serializer.ts +46 -71
  197. package/src/core/postgres-contract-view.ts +48 -0
  198. package/src/core/postgres-native-enum.ts +61 -0
  199. package/src/core/postgres-rls-enablement.ts +34 -0
  200. package/src/core/postgres-rls-policy.ts +64 -0
  201. package/src/core/postgres-role.ts +59 -0
  202. package/src/core/postgres-schema-verifier.ts +10 -7
  203. package/src/core/postgres-schema.ts +85 -15
  204. package/src/core/postgres-validators.ts +34 -0
  205. package/src/core/psl-infer/infer-psl-contract.ts +1290 -0
  206. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  207. package/src/core/psl-infer/postgres-type-map.ts +129 -0
  208. package/src/core/rls/canonicalize.ts +65 -0
  209. package/src/core/rls/wire-name.ts +33 -0
  210. package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
  211. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  212. package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
  213. package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
  214. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  215. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  216. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  217. package/src/core/schema-ir/schema-node-kinds.ts +122 -0
  218. package/src/core/sql-utils.ts +15 -2
  219. package/src/exports/codecs.ts +5 -0
  220. package/src/exports/contract-free.ts +11 -1
  221. package/src/exports/control.ts +27 -33
  222. package/src/exports/ddl.ts +8 -0
  223. package/src/exports/diff-database-schema.ts +7 -0
  224. package/src/exports/issue-planner.ts +1 -1
  225. package/src/exports/migration.ts +1 -0
  226. package/src/exports/op-factory-call.ts +4 -0
  227. package/src/exports/planner-ddl-builders.ts +0 -2
  228. package/src/exports/planner-identity-values.ts +4 -1
  229. package/src/exports/planner.ts +1 -0
  230. package/src/exports/rls-canonicalize.ts +12 -0
  231. package/src/exports/runtime.ts +1 -0
  232. package/src/exports/schema-ir-annotations.ts +1 -0
  233. package/src/exports/sql-utils.ts +1 -0
  234. package/src/exports/types.ts +37 -0
  235. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  236. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  237. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  238. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  239. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  240. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  241. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  242. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  243. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  244. package/dist/errors-CUk87ByX.mjs +0 -33
  245. package/dist/errors-CUk87ByX.mjs.map +0 -1
  246. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  247. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  248. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  249. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  250. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  251. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  252. package/dist/nodes-pLeLgdis.d.mts +0 -67
  253. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  254. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  255. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  256. package/dist/planner-Bs_baQax.mjs +0 -324
  257. package/dist/planner-Bs_baQax.mjs.map +0 -1
  258. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  259. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  260. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  261. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  262. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  263. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  264. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  265. package/dist/types.d.mts.map +0 -1
  266. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -0,0 +1,269 @@
1
+ import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
2
+ import { t as PostgresRlsPolicy } from "./postgres-rls-policy--CSddvMR.mjs";
3
+ import { SqlNamespaceBase, SqlNamespaceEntries, SqlNamespaceInput, SqlNode, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
4
+ import { CfExpr } from "@prisma-next/sql-relational-core/contract-free";
5
+ import { Contract, ControlPolicy } from "@prisma-next/contract/types";
6
+
7
+ //#region src/core/postgres-native-enum.d.ts
8
+ interface PostgresNativeEnumInput<Members extends readonly string[] = readonly string[]> {
9
+ /** The Postgres type name (`CREATE TYPE <typeName> AS ENUM (…)`). */
10
+ readonly typeName: string;
11
+ /** Member values in declaration order — this is the Postgres enum sort order. */
12
+ readonly members: Members;
13
+ readonly control?: ControlPolicy;
14
+ }
15
+ /**
16
+ * Postgres contract-IR class for a native enum type (`CREATE TYPE … AS ENUM (…)`).
17
+ *
18
+ * This is an authored, serialized Contract-IR entity — it is registered as an entity
19
+ * kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
20
+ * the schema-diff tree will use `PostgresNativeEnumSchemaNode` when the managed phase
21
+ * builds it.
22
+ *
23
+ * A member is a value, not a name→value pair — matching `CREATE TYPE … AS ENUM
24
+ * ('a', 'b')`, which has no separate member name.
25
+ *
26
+ * Target-only concept — no SQL-family abstract. Extends `SqlNode` directly,
27
+ * frozen at construction via `freezeNode(this)`. The `kind: 'postgres-enum'`
28
+ * discriminant is enumerable so it survives JSON. Lives at
29
+ * `storage.namespaces[ns].entries.native_enum[HandleName]`; the entries key
30
+ * (`native_enum`) is the entity-kind descriptor's `kind`, decoupled from this
31
+ * node's own `kind` literal — the same shape as `table`/`StorageTable` and
32
+ * `valueSet`/`StorageValueSet`.
33
+ */
34
+ declare class PostgresNativeEnum<Members extends readonly string[] = readonly string[]> extends SqlNode {
35
+ static is(node: unknown): node is PostgresNativeEnum;
36
+ readonly kind: "postgres-enum";
37
+ readonly typeName: string;
38
+ readonly members: Members;
39
+ readonly control?: ControlPolicy;
40
+ constructor(input: PostgresNativeEnumInput<Members>);
41
+ }
42
+ //#endregion
43
+ //#region src/core/postgres-rls-enablement.d.ts
44
+ interface PostgresRlsEnablementInput {
45
+ /** Name of the table this marker declares RLS-controlled. */
46
+ readonly tableName: string;
47
+ /** Namespace coordinate (schema name). Markers are schema-scoped like policies. */
48
+ readonly namespaceId: string;
49
+ }
50
+ /**
51
+ * Postgres contract-IR marker for `@@rls` on a model: the table named here is
52
+ * RLS-controlled (`ENABLE ROW LEVEL SECURITY` is driven by this marker, never
53
+ * by the policy set).
54
+ *
55
+ * This is an authored, serialized Contract-IR entity — it is registered as an
56
+ * entity kind, extends `SqlNode`, and is stored in `contract.json` under
57
+ * `entries.rls[tableName]`. Target-only concept — no SQL-family abstract.
58
+ * Frozen at construction via `freezeNode(this)`. The `kind: 'rls'`
59
+ * discriminant is enumerable so it survives JSON serialization; the literal
60
+ * matches the entries key (one-string rule).
61
+ */
62
+ declare class PostgresRlsEnablement extends SqlNode {
63
+ readonly kind: "rls";
64
+ readonly tableName: string;
65
+ readonly namespaceId: string;
66
+ constructor(input: PostgresRlsEnablementInput);
67
+ }
68
+ //#endregion
69
+ //#region src/core/postgres-role.d.ts
70
+ interface PostgresRoleInput {
71
+ readonly name: string;
72
+ /**
73
+ * Namespace coordinate. Roles are cluster-scoped; pass `UNBOUND_NAMESPACE_ID`
74
+ * from `@prisma-next/framework-components/ir`.
75
+ */
76
+ readonly namespaceId: string;
77
+ /**
78
+ * Defaults to {@link ROLE_DEFAULT_CONTROL_POLICY} when omitted. Roles are
79
+ * referenced but never owned, so `'external'` is the only allowed value.
80
+ */
81
+ readonly control?: 'external';
82
+ }
83
+ /**
84
+ * Postgres contract-IR class for a database role (`CREATE ROLE …`).
85
+ *
86
+ * This is an authored, serialized Contract-IR entity — it is registered as an entity
87
+ * kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
88
+ * the schema-diff tree uses `PostgresRoleSchemaNode` for that role.
89
+ *
90
+ * Roles are cluster-scoped, so their namespace coordinate is always
91
+ * `UNBOUND_NAMESPACE_ID`. Target-only concept — no SQL-family abstract.
92
+ * Extends `SqlNode` directly, frozen at construction via `freezeNode(this)`.
93
+ * The `kind: 'role'` discriminant is enumerable so it survives JSON.
94
+ * Matches the entries key (one-string rule).
95
+ *
96
+ * `control` always carries a value (never omitted): it defaults to
97
+ * {@link ROLE_DEFAULT_CONTROL_POLICY} in the constructor, so both a
98
+ * freshly-authored role and one hydrated from an older `contract.json`
99
+ * lacking the field resolve the same way — the control-policy resolver
100
+ * reads it directly off the entity instead of special-casing role issues.
101
+ */
102
+ declare class PostgresRole extends SqlNode {
103
+ readonly kind: "role";
104
+ readonly name: string;
105
+ readonly namespaceId: string;
106
+ readonly control: 'external';
107
+ constructor(input: PostgresRoleInput);
108
+ }
109
+ //#endregion
110
+ //#region src/core/postgres-schema.d.ts
111
+ type PostgresContract = Contract<SqlStorage> & {
112
+ readonly target: 'postgres';
113
+ };
114
+ type PostgresNamespaceEntries = SqlNamespaceEntries & {
115
+ readonly policy?: Readonly<Record<string, PostgresRlsPolicy>>;
116
+ readonly role?: Readonly<Record<string, PostgresRole>>;
117
+ readonly rls?: Readonly<Record<string, PostgresRlsEnablement>>;
118
+ readonly native_enum?: Readonly<Record<string, PostgresNativeEnum>>;
119
+ };
120
+ interface PostgresSchemaInput {
121
+ readonly id: string;
122
+ readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
123
+ }
124
+ /**
125
+ * Postgres target `Namespace` concretion — a Postgres schema (`CREATE
126
+ * SCHEMA …`). Each Postgres `SqlStorage` carries a
127
+ * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
128
+ * the Postgres PSL interpreter from `namespace { … }` AST buckets.
129
+ *
130
+ * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
131
+ * emission is the rendering seam: DDL / SQL emission asks the namespace
132
+ * for its qualifier (`"<schema>"`) or for a qualified table name
133
+ * (`"<schema>"."<table>"`) and consumes the result polymorphically.
134
+ * The unbound singleton below overrides these methods to elide the
135
+ * prefix entirely — call sites stay polymorphic and never branch on
136
+ * `id === UNBOUND_NAMESPACE_ID`.
137
+ */
138
+ declare class PostgresSchema extends SqlNamespaceBase {
139
+ /**
140
+ * Stable singleton reference for the late-bound slot. Materialised
141
+ * lazily below the singleton subclass declaration so the static
142
+ * initialiser sees the subclass before assigning. Consumers always
143
+ * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`
144
+ * — same identity).
145
+ */
146
+ static unbound: PostgresUnboundSchema;
147
+ readonly kind: 'schema';
148
+ readonly id: string;
149
+ readonly entries: PostgresNamespaceEntries;
150
+ constructor(input: PostgresSchemaInput);
151
+ get table(): Readonly<Record<string, StorageTable>>;
152
+ get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
153
+ get policy(): Readonly<Record<string, PostgresRlsPolicy>>;
154
+ get role(): Readonly<Record<string, PostgresRole>>;
155
+ get rls(): Readonly<Record<string, PostgresRlsEnablement>>;
156
+ /**
157
+ * The bare schema qualifier as it would appear in a rendered SQL
158
+ * fragment (already quoted). The unbound-schema singleton overrides
159
+ * this to return `''`.
160
+ */
161
+ qualifier(): string;
162
+ /**
163
+ * Qualify a table name with the schema prefix
164
+ * (`"<schema>"."<table>"`). The unbound-schema singleton overrides
165
+ * this to emit just `"<table>"` so the resolved DDL is unqualified
166
+ * and `search_path` decides where the object lands at runtime.
167
+ */
168
+ qualifyTable(tableName: string): string;
169
+ /**
170
+ * Render a SQL string-literal containing the qualified-name form
171
+ * suitable for `to_regclass(...)` arguments (e.g. `'"public"."user"'`).
172
+ * The unbound singleton overrides this to elide the schema prefix
173
+ * (`'"user"'`) so `search_path` resolves the object at runtime.
174
+ */
175
+ regclassLiteral(name: string): string;
176
+ /**
177
+ * Render a SQL expression that evaluates to this namespace's schema
178
+ * name at runtime, ready to drop into a `WHERE table_schema = …` /
179
+ * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL
180
+ * literal (`'public'`); the unbound singleton overrides this to emit
181
+ * `current_schema()` so catalog queries match whichever schema the
182
+ * connection's `search_path` resolved at runtime.
183
+ */
184
+ schemaSqlExpression(): string;
185
+ /**
186
+ * Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
187
+ * builder-built catalog check compares `n.nspname` / `table_schema`
188
+ * against. Named schemas bind the schema name as a text parameter; the
189
+ * unbound singleton overrides this to the opaque `current_schema()`
190
+ * expression so the live connection's `search_path` decides at runtime.
191
+ */
192
+ schemaFilterExpression(): CfExpr;
193
+ /**
194
+ * Typed-AST counterpart of {@link qualifyTable}: the FROM source a
195
+ * builder-built check uses to address a user table in this namespace.
196
+ * Named schemas qualify (`"schema"."table"`); the unbound singleton
197
+ * overrides this to leave the table unqualified so `search_path`
198
+ * resolves it at runtime.
199
+ */
200
+ tableSource(tableName: string, alias?: string): PostgresTableSource;
201
+ /**
202
+ * The bare schema name a DDL planner should target when emitting
203
+ * statements that need to identify this namespace in the live
204
+ * database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
205
+ * catalog filters, planner conflict lookups). Named schemas resolve
206
+ * to their own id. The `PostgresUnboundSchema` singleton inherits
207
+ * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
208
+ * through `qualifyTableName` route through the polymorphic
209
+ * `PostgresUnboundSchema` overrides and produce unqualified
210
+ * (search-path-resolved) output automatically.
211
+ */
212
+ ddlSchemaName(_storage: SqlStorage): string;
213
+ }
214
+ /**
215
+ * Singleton subclass for the reserved sentinel namespace id
216
+ * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding
217
+ * the connection's `search_path` resolves at runtime. Overrides
218
+ * qualifier emission to elide the schema prefix; call sites that consume
219
+ * `qualifier()` / `qualifyTable()` get unqualified output without
220
+ * branching on the namespace id.
221
+ *
222
+ * This is the target-side materialization of "the framework provides
223
+ * affordances; targets implement specifics": the framework names the
224
+ * sentinel; Postgres decides what late-bound means here (the table
225
+ * name, naked — the schema is supplied by the live connection's
226
+ * `search_path`).
227
+ *
228
+ * `ddlSchemaName` is inherited from `PostgresSchema` and returns
229
+ * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
230
+ * route through the polymorphic factory and produce unqualified output
231
+ * automatically.
232
+ */
233
+ declare class PostgresUnboundSchema extends PostgresSchema {
234
+ static readonly instance: PostgresUnboundSchema;
235
+ constructor(input?: PostgresSchemaInput);
236
+ qualifier(): string;
237
+ qualifyTable(tableName: string): string;
238
+ schemaSqlExpression(): string;
239
+ schemaFilterExpression(): CfExpr;
240
+ tableSource(tableName: string, alias?: string): PostgresTableSource;
241
+ }
242
+ /**
243
+ * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`
244
+ * so callers can dispatch to the polymorphic emission methods without
245
+ * branching at the call site. Uses the structural `kind` discriminator
246
+ * (`'schema'`) rather than `instanceof` so the check survives realm /
247
+ * bundle / hot-reload boundaries — matching the rest of the IR's
248
+ * narrowing convention. `PostgresUnboundSchema` passes through because
249
+ * it inherits the same `kind: 'schema'` from `PostgresSchema`.
250
+ */
251
+ declare function isPostgresSchema(ns: unknown): ns is PostgresSchema;
252
+ /**
253
+ * Target-supplied `Namespace` factory the Postgres target plumbs
254
+ * through `defineContract({ createNamespace })` and the SQL PSL
255
+ * interpreter. Returns the unbound singleton for the framework
256
+ * sentinel and a fresh `PostgresSchema` for any other coordinate.
257
+ *
258
+ * The factory has no per-call state — every named id deterministically
259
+ * maps to a distinct schema instance — so callers can pass it through
260
+ * by reference and trust the resulting `SqlStorage.namespaces` map to
261
+ * be value-stable for a given input set. Native-enum column type names are
262
+ * schema-qualified earlier, at column construction, via the target's
263
+ * `authoring.qualifyColumnType` hook (`postgresQualifyColumnType`), so this
264
+ * factory just materialises the namespace from already-qualified entries.
265
+ */
266
+ declare function postgresCreateNamespace(input: SqlNamespaceInput): PostgresSchema;
267
+ //#endregion
268
+ export { postgresCreateNamespace as a, PostgresRlsEnablement as c, PostgresNativeEnumInput as d, isPostgresSchema as i, PostgresRlsEnablementInput as l, PostgresSchema as n, PostgresRole as o, PostgresUnboundSchema as r, PostgresRoleInput as s, PostgresContract as t, PostgresNativeEnum as u };
269
+ //# sourceMappingURL=postgres-schema-DKq6s1P3.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-schema-DKq6s1P3.d.mts","names":[],"sources":["../src/core/postgres-native-enum.ts","../src/core/postgres-rls-enablement.ts","../src/core/postgres-role.ts","../src/core/postgres-schema.ts"],"mappings":";;;;;;;UAKiB,uBAAA;;WAEN,QAAA;;WAEA,OAAA,EAAS,OAAA;EAAA,SACT,OAAA,GAAU,aAAa;AAAA;;;;;;;;;;AAAA;AA6BlC;;;;;;;;;cAAa,kBAAA,gEAEH,OAAA;EAAA,OACD,EAAA,CAAG,IAAA,YAAgB,IAAA,IAAQ,kBAAA;EAAA,SAMhB,IAAA;EAAA,SACT,QAAA;EAAA,SACA,OAAA,EAAS,OAAA;EAAA,SACD,OAAA,GAAU,aAAA;cAEf,KAAA,EAAO,uBAAA,CAAwB,OAAA;AAAA;;;UClD5B,0BAAA;;WAEN,SAAA;;WAEA,WAAW;AAAA;ADFtB;;;;;;;;;;;AAKkC;AALlC,cCiBa,qBAAA,SAA8B,OAAO;EAAA,SAC9B,IAAA;EAAA,SACT,SAAA;EAAA,SACA,WAAA;cAEG,KAAA,EAAO,0BAAA;AAAA;;;UCfJ,iBAAA;EAA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;;EE2J7C,eAAA,CAAgB,IAAA;ED1KgB;;;;;;;AAWhB;EC2KhB,mBAAA;EDrJwB;;;;;;;ECgKxB,sBAAA,IAA0B,MAAA;;;;;AD1JU;;;ECqKpC,WAAA,CAAY,SAAA,UAAmB,KAAA,YAAiB,mBAAA;EAtLtC;;;;;;;;AAA2D;AAEvE;;EAuME,aAAA,CAAc,QAAA,EAAU,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;cAwBb,qBAAA,SAA8B,cAAA;EAAA,gBACzB,QAAA,EAAU,qBAAA;cAEd,KAAA,GAAQ,mBAAA;EAIX,SAAA;EAIA,YAAA,CAAa,SAAA;EAIb,mBAAA;EAIA,sBAAA,IAA0B,MAAA;EAI1B,WAAA,CAAY,SAAA,UAAmB,KAAA,YAAiB,mBAAA;AAAA;;;;;AAlPQ;AAGnE;;;;iBAkQgB,gBAAA,CAAiB,EAAA,YAAc,EAAA,IAAM,cAAc;;;;;;;;;;;;AAhQR;AAiB3D;;iBAiQgB,uBAAA,CAAwB,KAAA,EAAO,iBAAA,GAAoB,cAAc"}
@@ -0,0 +1,216 @@
1
+ import { freezeNode } from "@prisma-next/framework-components/ir";
2
+ import { blindCast } from "@prisma-next/utils/casts";
3
+ import { PrimaryKey, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIRNode, SqlUniqueIR, assertNode, relationalNodeEntityKind, relationalNodeGranularity } from "@prisma-next/sql-schema-ir/types";
4
+ //#region src/core/schema-ir/schema-node-kinds.ts
5
+ /**
6
+ * The `nodeKind` discriminant for each Postgres schema-diff node. Each node
7
+ * carries a unique value; the static `is`/`assert` guards compare against these
8
+ * identifiers rather than spelling the string inline or using `instanceof`. The
9
+ * field is an enumerable own property carried on every node instance.
10
+ */
11
+ const PostgresSchemaNodeKind = {
12
+ database: "postgres-database",
13
+ namespace: "postgres-namespace",
14
+ table: "postgres-table",
15
+ policy: "postgres-policy",
16
+ role: "postgres-role",
17
+ nativeEnum: "postgres-native-enum"
18
+ };
19
+ /**
20
+ * The one real map from a Postgres-specific `nodeKind` to the
21
+ * framework-neutral {@link DiffSubjectGranularity} its diff issues carry —
22
+ * resolution is by `nodeKind` equality against this map, never a
23
+ * `nodeKind`-suffix string match and never anything stamped on the node.
24
+ */
25
+ const POSTGRES_NODE_GRANULARITY = {
26
+ [PostgresSchemaNodeKind.database]: "structural",
27
+ [PostgresSchemaNodeKind.namespace]: "namespace",
28
+ [PostgresSchemaNodeKind.table]: "entity",
29
+ [PostgresSchemaNodeKind.policy]: "structural",
30
+ [PostgresSchemaNodeKind.role]: "structural",
31
+ [PostgresSchemaNodeKind.nativeEnum]: "entity"
32
+ };
33
+ function isPostgresSchemaNodeKind(nodeKind) {
34
+ return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);
35
+ }
36
+ /** Looks up the subject granularity for a Postgres-specific `nodeKind`. */
37
+ function postgresNodeGranularity(nodeKind) {
38
+ return POSTGRES_NODE_GRANULARITY[nodeKind];
39
+ }
40
+ /**
41
+ * The subject granularity for any node kind that appears in a Postgres diff
42
+ * tree — the tree mixes Postgres-specific kinds (database/namespace/table/
43
+ * policy/role) with the relational leaf kinds (columns, constraints, indexes,
44
+ * …), so this dispatches to whichever family/target map owns the kind. Called
45
+ * on demand by consumers (the family verdict, the framework aggregate's
46
+ * unclaimed-elements sweep, via the {@link
47
+ * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
48
+ * capability) — never stamped onto the issue or the node.
49
+ */
50
+ function postgresDiffSubjectGranularity(nodeKind) {
51
+ return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeGranularity(nodeKind) : relationalNodeGranularity(nodeKind);
52
+ }
53
+ /**
54
+ * The map from a Postgres-specific `nodeKind` to its storage `entityKind` — the
55
+ * same vocabulary the contract storage's `entries` dictionary keys use. The
56
+ * whole-table and native-enum kinds each have an entity of their own;
57
+ * database/namespace/policy/role nodes map to nothing here (a namespace is
58
+ * addressed by id, not by an `entries` kind; policies and roles are
59
+ * structural, never a sibling space's unclaimed entity).
60
+ *
61
+ * The native enum keys under its PHYSICAL type name in `entries.native_enum`
62
+ * (ADR 221), so its diff node's `typeName` addresses the entity on the generic
63
+ * coordinate directly — no by-type-name walk needed. This lets the framework's
64
+ * unclaimed-elements sweep classify enum ownership the same coordinate way it
65
+ * classifies tables.
66
+ */
67
+ const POSTGRES_NODE_ENTITY_KIND = {
68
+ [PostgresSchemaNodeKind.table]: "table",
69
+ [PostgresSchemaNodeKind.nativeEnum]: "native_enum"
70
+ };
71
+ /** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */
72
+ function postgresNodeEntityKind(nodeKind) {
73
+ return POSTGRES_NODE_ENTITY_KIND[nodeKind];
74
+ }
75
+ /**
76
+ * The storage `entityKind` for any node kind that appears in a Postgres diff
77
+ * tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the
78
+ * same way to whichever family/target map owns the kind. Called on demand by
79
+ * the framework aggregate's unclaimed-elements sweep via the {@link
80
+ * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
81
+ * capability — never stamped onto the issue or the node.
82
+ */
83
+ function postgresDiffSubjectEntityKind(nodeKind) {
84
+ return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeEntityKind(nodeKind) : relationalNodeEntityKind(nodeKind);
85
+ }
86
+ //#endregion
87
+ //#region src/core/schema-ir/postgres-native-enum-schema-node.ts
88
+ /**
89
+ * Schema-diff leaf node for a native Postgres enum type.
90
+ *
91
+ * This is a derived, transient node walked by the differ — it is NEVER
92
+ * serialized. Both sides derive it on the namespace node: the expected side
93
+ * from the contract's hydrated `entries.native_enum` entities, the actual
94
+ * side from the adapter's introspected `nativeEnums`.
95
+ *
96
+ * Enum types are schema-scoped, so identity is (namespace, type name): the
97
+ * namespace coordinate comes from tree position (the differ pairs enum nodes
98
+ * only inside an already-paired namespace) and `id` carries the type name,
99
+ * prefixed with the entries-kind vocabulary (`native_enum:<typeName>`) so it
100
+ * cannot collide with a sibling table of the same name — the same
101
+ * sibling-prefix convention relational column nodes use (`column:<name>`).
102
+ *
103
+ * `isEqualTo` compares members POSITIONALLY — `['a','b'] ≠ ['b','a']` —
104
+ * because Postgres enum sort order is semantic. `control` is contract
105
+ * metadata, not database state, and does not participate in equality.
106
+ */
107
+ var PostgresNativeEnumSchemaNode = class PostgresNativeEnumSchemaNode extends SqlSchemaIRNode {
108
+ nodeKind = PostgresSchemaNodeKind.nativeEnum;
109
+ typeName;
110
+ namespaceId;
111
+ members;
112
+ constructor(input) {
113
+ super();
114
+ this.typeName = input.typeName;
115
+ this.namespaceId = input.namespaceId;
116
+ this.members = Object.freeze([...input.members]);
117
+ if (input.control !== void 0) this.control = input.control;
118
+ freezeNode(this);
119
+ }
120
+ get id() {
121
+ return `native_enum:${this.typeName}`;
122
+ }
123
+ children() {
124
+ return [];
125
+ }
126
+ isEqualTo(other) {
127
+ const node = blindCast(other);
128
+ PostgresNativeEnumSchemaNode.assert(node);
129
+ return this.typeName === node.typeName && this.members.length === node.members.length && this.members.every((member, index) => member === node.members[index]);
130
+ }
131
+ static is(node) {
132
+ return node.nodeKind === PostgresSchemaNodeKind.nativeEnum;
133
+ }
134
+ static assert(node) {
135
+ assertNode(node, "PostgresNativeEnumSchemaNode", PostgresNativeEnumSchemaNode.is);
136
+ }
137
+ };
138
+ //#endregion
139
+ //#region src/core/schema-ir/postgres-table-schema-node.ts
140
+ /**
141
+ * Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields
142
+ * plus `policies`, and implements `DiffableNode` so the table instance is
143
+ * directly the diff-tree node — no separate wrapper needed.
144
+ *
145
+ * Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because
146
+ * `SqlTableIR` calls `freezeNode` in its own constructor, which prevents
147
+ * subclass field initialisation.
148
+ *
149
+ * `id` is the table name. `isEqualTo` compares id + `rlsEnabled` — the
150
+ * table's one own diffable attribute; all other structural drift is
151
+ * expressed by its children. `children()` returns every column, the primary
152
+ * key (when present), every foreign key, unique, index, and check constraint,
153
+ * plus the policy nodes — one flat list, so a drifted column and a drifted
154
+ * policy are both reported by the same walk. Order is deterministic (object
155
+ * key order for columns, array order for the rest) so two structurally equal
156
+ * tables always produce the same child list.
157
+ */
158
+ var PostgresTableSchemaNode = class PostgresTableSchemaNode extends SqlSchemaIRNode {
159
+ nodeKind = PostgresSchemaNodeKind.table;
160
+ name;
161
+ columns;
162
+ foreignKeys;
163
+ uniques;
164
+ indexes;
165
+ policies;
166
+ rlsEnabled;
167
+ constructor(input) {
168
+ super();
169
+ this.name = input.name;
170
+ this.rlsEnabled = input.rlsEnabled;
171
+ this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([key, col]) => [key, col instanceof SqlColumnIR ? col : new SqlColumnIR(col)])));
172
+ this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk)));
173
+ this.uniques = Object.freeze(input.uniques.map((u) => u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u)));
174
+ this.indexes = Object.freeze(input.indexes.map((i) => i instanceof SqlIndexIR ? i : new SqlIndexIR(i)));
175
+ if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey);
176
+ if (input.annotations !== void 0) this.annotations = input.annotations;
177
+ if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((c) => c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c)));
178
+ this.policies = Object.freeze([...input.policies ?? []]);
179
+ freezeNode(this);
180
+ }
181
+ get id() {
182
+ return this.name;
183
+ }
184
+ /**
185
+ * Equal iff the ids (names) match AND `rlsEnabled` matches — the table's
186
+ * one own attribute in the diff; all other structural drift is expressed
187
+ * by children. A paired `not-equal` therefore always means enablement
188
+ * drift, which the planner maps to ENABLE/DISABLE ROW LEVEL SECURITY.
189
+ */
190
+ isEqualTo(other) {
191
+ const node = blindCast(other);
192
+ PostgresTableSchemaNode.assert(node);
193
+ return this.id === node.id && this.rlsEnabled === node.rlsEnabled;
194
+ }
195
+ children() {
196
+ return [
197
+ ...Object.values(this.columns),
198
+ ...this.primaryKey ? [this.primaryKey] : [],
199
+ ...this.foreignKeys,
200
+ ...this.uniques,
201
+ ...this.indexes,
202
+ ...this.checks ?? [],
203
+ ...this.policies
204
+ ];
205
+ }
206
+ static is(node) {
207
+ return node.nodeKind === PostgresSchemaNodeKind.table;
208
+ }
209
+ static assert(node) {
210
+ assertNode(node, "PostgresTableSchemaNode", PostgresTableSchemaNode.is);
211
+ }
212
+ };
213
+ //#endregion
214
+ export { postgresDiffSubjectGranularity as a, postgresDiffSubjectEntityKind as i, PostgresNativeEnumSchemaNode as n, postgresNodeEntityKind as o, PostgresSchemaNodeKind as r, PostgresTableSchemaNode as t };
215
+
216
+ //# sourceMappingURL=postgres-table-schema-node-D6LvInCe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-table-schema-node-D6LvInCe.mjs","names":[],"sources":["../src/core/schema-ir/schema-node-kinds.ts","../src/core/schema-ir/postgres-native-enum-schema-node.ts","../src/core/schema-ir/postgres-table-schema-node.ts"],"sourcesContent":["import type {\n DiffableNode,\n DiffSubjectGranularity,\n} from '@prisma-next/framework-components/control';\nimport {\n relationalNodeEntityKind,\n relationalNodeGranularity,\n type SqlSchemaIRNode,\n} from '@prisma-next/sql-schema-ir/types';\n\n/**\n * A Postgres schema-diff-tree node: a `SqlSchemaIRNode` that also implements\n * `DiffableNode` (the five `Postgres*SchemaNode` classes). `SqlSchemaIRNode`\n * alone is not a `DiffableNode` — its relational subclasses (`SqlColumnIR`, …)\n * carry no `id`/`isEqualTo`/`children` — so this intersection is the honest node\n * type the differ produces and the planner consumes (`SchemaDiff<SqlSchemaDiffNode>`).\n */\nexport type SqlSchemaDiffNode = SqlSchemaIRNode & DiffableNode;\n\n/**\n * The `nodeKind` discriminant for each Postgres schema-diff node. Each node\n * carries a unique value; the static `is`/`assert` guards compare against these\n * identifiers rather than spelling the string inline or using `instanceof`. The\n * field is an enumerable own property carried on every node instance.\n */\nexport const PostgresSchemaNodeKind = {\n database: 'postgres-database',\n namespace: 'postgres-namespace',\n table: 'postgres-table',\n policy: 'postgres-policy',\n role: 'postgres-role',\n nativeEnum: 'postgres-native-enum',\n} as const;\n\nexport type PostgresSchemaNodeKind =\n (typeof PostgresSchemaNodeKind)[keyof typeof PostgresSchemaNodeKind];\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to the\n * framework-neutral {@link DiffSubjectGranularity} its diff issues carry —\n * resolution is by `nodeKind` equality against this map, never a\n * `nodeKind`-suffix string match and never anything stamped on the node.\n */\nconst POSTGRES_NODE_GRANULARITY: Readonly<Record<PostgresSchemaNodeKind, DiffSubjectGranularity>> =\n {\n [PostgresSchemaNodeKind.database]: 'structural',\n [PostgresSchemaNodeKind.namespace]: 'namespace',\n [PostgresSchemaNodeKind.table]: 'entity',\n // A policy set is owned by the managed table it attaches to; a role is\n // referenced by the contract but not owned (the framework names it in a\n // policy but never owns the cluster's role list). Both classify as\n // `structural`. The asymmetry for roles — a missing declared one fails, an\n // undeclared live one is tolerated unconditionally — comes from the\n // control policy the diff resolves a role issue against (`external`),\n // not from the granularity.\n [PostgresSchemaNodeKind.policy]: 'structural',\n [PostgresSchemaNodeKind.role]: 'structural',\n [PostgresSchemaNodeKind.nativeEnum]: 'entity',\n };\n\nfunction isPostgresSchemaNodeKind(nodeKind: string): nodeKind is PostgresSchemaNodeKind {\n return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);\n}\n\n/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */\nexport function postgresNodeGranularity(nodeKind: PostgresSchemaNodeKind): DiffSubjectGranularity {\n return POSTGRES_NODE_GRANULARITY[nodeKind];\n}\n\n/**\n * The subject granularity for any node kind that appears in a Postgres diff\n * tree — the tree mixes Postgres-specific kinds (database/namespace/table/\n * policy/role) with the relational leaf kinds (columns, constraints, indexes,\n * …), so this dispatches to whichever family/target map owns the kind. Called\n * on demand by consumers (the family verdict, the framework aggregate's\n * unclaimed-elements sweep, via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability) — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectGranularity(nodeKind: string): DiffSubjectGranularity {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeGranularity(nodeKind)\n : relationalNodeGranularity(nodeKind);\n}\n\n/**\n * The map from a Postgres-specific `nodeKind` to its storage `entityKind` — the\n * same vocabulary the contract storage's `entries` dictionary keys use. The\n * whole-table and native-enum kinds each have an entity of their own;\n * database/namespace/policy/role nodes map to nothing here (a namespace is\n * addressed by id, not by an `entries` kind; policies and roles are\n * structural, never a sibling space's unclaimed entity).\n *\n * The native enum keys under its PHYSICAL type name in `entries.native_enum`\n * (ADR 221), so its diff node's `typeName` addresses the entity on the generic\n * coordinate directly — no by-type-name walk needed. This lets the framework's\n * unclaimed-elements sweep classify enum ownership the same coordinate way it\n * classifies tables.\n */\nconst POSTGRES_NODE_ENTITY_KIND: Partial<Readonly<Record<PostgresSchemaNodeKind, string>>> = {\n [PostgresSchemaNodeKind.table]: 'table',\n [PostgresSchemaNodeKind.nativeEnum]: 'native_enum',\n};\n\n/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */\nexport function postgresNodeEntityKind(nodeKind: PostgresSchemaNodeKind): string | undefined {\n return POSTGRES_NODE_ENTITY_KIND[nodeKind];\n}\n\n/**\n * The storage `entityKind` for any node kind that appears in a Postgres diff\n * tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the\n * same way to whichever family/target map owns the kind. Called on demand by\n * the framework aggregate's unclaimed-elements sweep via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectEntityKind(nodeKind: string): string | undefined {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeEntityKind(nodeKind)\n : relationalNodeEntityKind(nodeKind);\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresNativeEnumSchemaNodeInput {\n /** The Postgres type name (`CREATE TYPE <typeName> AS ENUM (…)`). */\n readonly typeName: string;\n /** The owning DDL schema name — enum types are schema-scoped. */\n readonly namespaceId: string;\n /** Member values in declaration (`pg_enum.enumsortorder`) order. */\n readonly members: readonly string[];\n /** The contract entity's control grade — expected-side nodes only. */\n readonly control?: ControlPolicy;\n}\n\n/**\n * Schema-diff leaf node for a native Postgres enum type.\n *\n * This is a derived, transient node walked by the differ — it is NEVER\n * serialized. Both sides derive it on the namespace node: the expected side\n * from the contract's hydrated `entries.native_enum` entities, the actual\n * side from the adapter's introspected `nativeEnums`.\n *\n * Enum types are schema-scoped, so identity is (namespace, type name): the\n * namespace coordinate comes from tree position (the differ pairs enum nodes\n * only inside an already-paired namespace) and `id` carries the type name,\n * prefixed with the entries-kind vocabulary (`native_enum:<typeName>`) so it\n * cannot collide with a sibling table of the same name — the same\n * sibling-prefix convention relational column nodes use (`column:<name>`).\n *\n * `isEqualTo` compares members POSITIONALLY — `['a','b'] ≠ ['b','a']` —\n * because Postgres enum sort order is semantic. `control` is contract\n * metadata, not database state, and does not participate in equality.\n */\nexport class PostgresNativeEnumSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.nativeEnum;\n\n readonly typeName: string;\n readonly namespaceId: string;\n readonly members: readonly string[];\n declare readonly control?: ControlPolicy;\n\n constructor(input: PostgresNativeEnumSchemaNodeInput) {\n super();\n this.typeName = input.typeName;\n this.namespaceId = input.namespaceId;\n this.members = Object.freeze([...input.members]);\n if (input.control !== undefined) this.control = input.control;\n freezeNode(this);\n }\n\n get id(): string {\n return `native_enum:${this.typeName}`;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode; the guard rejects non-enum kinds'\n >(other);\n PostgresNativeEnumSchemaNode.assert(node);\n return (\n this.typeName === node.typeName &&\n this.members.length === node.members.length &&\n this.members.every((member, index) => member === node.members[index])\n );\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresNativeEnumSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.nativeEnum;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresNativeEnumSchemaNode {\n assertNode(node, 'PostgresNativeEnumSchemaNode', PostgresNativeEnumSchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport {\n assertNode,\n PrimaryKey,\n type SqlAnnotations,\n SqlCheckConstraintIR,\n SqlColumnIR,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlSchemaIRNode,\n type SqlTableIRInput,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { PostgresPolicySchemaNode } from './postgres-policy-schema-node';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresTableSchemaNodeInput extends SqlTableIRInput {\n readonly policies?: readonly PostgresPolicySchemaNode[];\n /**\n * Whether row-level security is enabled on this table. Expected side:\n * stamped from the contract's `entries.rls` marker (never from the\n * policy set). Actual side: stamped from `pg_class.relrowsecurity` at\n * introspection. Required with no default so every construction site\n * supplies a deliberate value.\n */\n readonly rlsEnabled: boolean;\n}\n\n/**\n * Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields\n * plus `policies`, and implements `DiffableNode` so the table instance is\n * directly the diff-tree node — no separate wrapper needed.\n *\n * Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because\n * `SqlTableIR` calls `freezeNode` in its own constructor, which prevents\n * subclass field initialisation.\n *\n * `id` is the table name. `isEqualTo` compares id + `rlsEnabled` — the\n * table's one own diffable attribute; all other structural drift is\n * expressed by its children. `children()` returns every column, the primary\n * key (when present), every foreign key, unique, index, and check constraint,\n * plus the policy nodes — one flat list, so a drifted column and a drifted\n * policy are both reported by the same walk. Order is deterministic (object\n * key order for columns, array order for the rest) so two structurally equal\n * tables always produce the same child list.\n */\nexport class PostgresTableSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.table;\n\n readonly name: string;\n readonly columns: Readonly<Record<string, SqlColumnIR>>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;\n readonly uniques: ReadonlyArray<SqlUniqueIR>;\n readonly indexes: ReadonlyArray<SqlIndexIR>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly annotations?: SqlAnnotations;\n declare readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;\n readonly policies: readonly PostgresPolicySchemaNode[];\n readonly rlsEnabled: boolean;\n\n constructor(input: PostgresTableSchemaNodeInput) {\n super();\n this.name = input.name;\n this.rlsEnabled = input.rlsEnabled;\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([key, col]) => [\n key,\n col instanceof SqlColumnIR ? col : new SqlColumnIR(col),\n ]),\n ),\n );\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),\n );\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),\n );\n this.indexes = Object.freeze(\n input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n if (input.annotations !== undefined) this.annotations = input.annotations;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(\n input.checks.map((c) =>\n c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c),\n ),\n );\n }\n this.policies = Object.freeze([...(input.policies ?? [])]);\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n /**\n * Equal iff the ids (names) match AND `rlsEnabled` matches — the table's\n * one own attribute in the diff; all other structural drift is expressed\n * by children. A paired `not-equal` therefore always means enablement\n * drift, which the planner maps to ENABLE/DISABLE ROW LEVEL SECURITY.\n */\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode'\n >(other);\n PostgresTableSchemaNode.assert(node);\n return this.id === node.id && this.rlsEnabled === node.rlsEnabled;\n }\n\n children(): readonly DiffableNode[] {\n return [\n ...Object.values(this.columns),\n ...(this.primaryKey ? [this.primaryKey] : []),\n ...this.foreignKeys,\n ...this.uniques,\n ...this.indexes,\n ...(this.checks ?? []),\n ...this.policies,\n ];\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresTableSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.table;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresTableSchemaNode {\n assertNode(node, 'PostgresTableSchemaNode', PostgresTableSchemaNode.is);\n }\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAa,yBAAyB;CACpC,UAAU;CACV,WAAW;CACX,OAAO;CACP,QAAQ;CACR,MAAM;CACN,YAAY;AACd;;;;;;;AAWA,MAAM,4BACJ;EACG,uBAAuB,WAAW;EAClC,uBAAuB,YAAY;EACnC,uBAAuB,QAAQ;EAQ/B,uBAAuB,SAAS;EAChC,uBAAuB,OAAO;EAC9B,uBAAuB,aAAa;AACvC;AAEF,SAAS,yBAAyB,UAAsD;CACtF,OAAO,OAAO,OAAO,2BAA2B,QAAQ;AAC1D;;AAGA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eAAe,KAAK;CACzD;CAEA,WAAoC;EAClC,OAAO;GACL,GAAG,OAAO,OAAO,KAAK,OAAO;GAC7B,GAAI,KAAK,aAAa,CAAC,KAAK,UAAU,IAAI,CAAC;GAC3C,GAAG,KAAK;GACR,GAAG,KAAK;GACR,GAAG,KAAK;GACR,GAAI,KAAK,UAAU,CAAC;GACpB,GAAG,KAAK;EACV;CACF;CAEA,OAAO,GAAG,MAAwD;EAChE,OAAO,KAAK,aAAa,uBAAuB;CAClD;CAEA,OAAO,OAAO,MAAgE;EAC5E,WAAW,MAAM,2BAA2B,wBAAwB,EAAE;CACxE;AACF"}
@@ -1,4 +1,4 @@
1
- import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
1
+ import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
2
2
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
3
3
  import { OpFactoryCall } from "@prisma-next/framework-components/control";
4
4
  import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
@@ -27,14 +27,18 @@ const BASE_IMPORTS = [{
27
27
  symbol: "MigrationCLI"
28
28
  }];
29
29
  function renderCallsToTypeScript(calls, meta) {
30
- const imports = buildImports(calls);
30
+ const imports = buildImports(calls, meta);
31
31
  const operationsBody = calls.map((c) => renderCall(c)).join(",\n");
32
+ const hasStart = meta.from !== null;
33
+ const startField = hasStart ? [" override readonly startContractJson = startContract;"] : [];
32
34
  return [
33
35
  shebangLineFor(detectScaffoldRuntime()),
34
36
  imports,
35
37
  "",
36
- "export default class M extends Migration {",
37
- buildDescribeMethod(meta),
38
+ `export default class M extends Migration<${hasStart ? "Start" : "never"}, End> {`,
39
+ ...startField,
40
+ " override readonly endContractJson = endContract;",
41
+ "",
38
42
  " override get operations() {",
39
43
  " return [",
40
44
  indent(operationsBody, 6),
@@ -49,21 +53,46 @@ function renderCallsToTypeScript(calls, meta) {
49
53
  function renderCall(call) {
50
54
  return call.renderTypeScript();
51
55
  }
52
- function buildImports(calls) {
53
- const requirements = [...BASE_IMPORTS];
56
+ function buildImports(calls, meta) {
57
+ const requirements = [...BASE_IMPORTS, ...contractImports(meta)];
54
58
  for (const call of calls) for (const req of call.importRequirements()) requirements.push(req);
55
59
  return renderImports(requirements);
56
60
  }
57
- function buildDescribeMethod(meta) {
58
- const lines = [];
59
- lines.push(" override describe() {");
60
- lines.push(" return {");
61
- lines.push(` from: ${JSON.stringify(meta.from)},`);
62
- lines.push(` to: ${JSON.stringify(meta.to)},`);
63
- lines.push(" };");
64
- lines.push(" }");
65
- lines.push("");
66
- return lines.join("\n");
61
+ /**
62
+ * The committed contract-JSON imports the scaffold reads its from/to identity
63
+ * from. `end-contract.json` is always present; `start-contract.json` is added
64
+ * only for a non-baseline migration (`meta.from !== null`). The matching
65
+ * `Contract` type imports (aliased `Start`/`End`) feed the
66
+ * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
67
+ * no start imports — `never` is the honest "no prior contract" Start.
68
+ */
69
+ function contractImports(meta) {
70
+ const reqs = [{
71
+ moduleSpecifier: "./end-contract.json",
72
+ symbol: "endContract",
73
+ kind: "default",
74
+ attributes: { type: "json" }
75
+ }, {
76
+ moduleSpecifier: "./end-contract",
77
+ symbol: "Contract",
78
+ alias: "End",
79
+ typeOnly: true
80
+ }];
81
+ if (meta.from !== null) {
82
+ reqs.push({
83
+ moduleSpecifier: "./start-contract.json",
84
+ symbol: "startContract",
85
+ kind: "default",
86
+ attributes: { type: "json" }
87
+ });
88
+ reqs.push({
89
+ moduleSpecifier: "./start-contract",
90
+ symbol: "Contract",
91
+ alias: "Start",
92
+ typeOnly: true
93
+ });
94
+ }
95
+ return reqs;
67
96
  }
68
97
  function indent(text, spaces) {
69
98
  const pad = " ".repeat(spaces);
@@ -72,4 +101,4 @@ function indent(text, spaces) {
72
101
  //#endregion
73
102
  export { renderCallsToTypeScript as t };
74
103
 
75
- //# sourceMappingURL=render-typescript-KMgosran.mjs.map
104
+ //# sourceMappingURL=render-typescript-7yqILcwr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-typescript-7yqILcwr.mjs","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `OpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the facade re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls, meta);\n const operationsBody = calls.map((c) => renderCall(c)).join(',\\n');\n const hasStart = meta.from !== null;\n const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n `export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,\n ...startField,\n ' override readonly endContractJson = endContract;',\n '',\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction renderCall(call: OpFactoryCall): string {\n return call.renderTypeScript();\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\n/**\n * The committed contract-JSON imports the scaffold reads its from/to identity\n * from. `end-contract.json` is always present; `start-contract.json` is added\n * only for a non-baseline migration (`meta.from !== null`). The matching\n * `Contract` type imports (aliased `Start`/`End`) feed the\n * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with\n * no start imports — `never` is the honest \"no prior contract\" Start.\n */\nfunction contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {\n const reqs: ImportRequirement[] = [\n {\n moduleSpecifier: './end-contract.json',\n symbol: 'endContract',\n kind: 'default',\n attributes: { type: 'json' },\n },\n { moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },\n ];\n if (meta.from !== null) {\n reqs.push({\n moduleSpecifier: './start-contract.json',\n symbol: 'startContract',\n kind: 'default',\n attributes: { type: 'json' },\n });\n reqs.push({\n moduleSpecifier: './start-contract',\n symbol: 'Contract',\n alias: 'Start',\n typeOnly: true,\n });\n }\n return reqs;\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${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AiB;GACjB,QAAQ;GACR,OAAO;GACP,UAAU;EACZ,CAAC;CACH;CACA,OAAO;AACT;AAEA,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,MAAM;CAC7B,OAAO,KACJ,MAAM,IAAI,CAAC,CACX,KAAK,SAAU,KAAK,KAAK,IAAI,GAAG,MAAM,SAAS,IAAK,CAAC,CACrD,KAAK,IAAI;AACd"}
@@ -1,2 +1,2 @@
1
- import { t as renderCallsToTypeScript } from "./render-typescript-KMgosran.mjs";
1
+ import { t as renderCallsToTypeScript } from "./render-typescript-7yqILcwr.mjs";
2
2
  export { renderCallsToTypeScript };