@prisma-next/cli 0.3.0-dev.11 → 0.3.0-dev.114

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 (215) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +470 -134
  3. package/dist/cli-errors-ByGuoqNj.mjs +3 -0
  4. package/dist/cli-errors-D6HxRn3A.d.mts +2 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.js +1 -2350
  7. package/dist/cli.mjs +235 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/client-612RJJD_.mjs +1069 -0
  10. package/dist/client-612RJJD_.mjs.map +1 -0
  11. package/dist/commands/contract-emit.d.mts +7 -0
  12. package/dist/commands/contract-emit.d.mts.map +1 -0
  13. package/dist/commands/contract-emit.mjs +4 -0
  14. package/dist/commands/contract-infer.d.mts +7 -0
  15. package/dist/commands/contract-infer.d.mts.map +1 -0
  16. package/dist/commands/contract-infer.mjs +4 -0
  17. package/dist/commands/db-init.d.mts +7 -0
  18. package/dist/commands/db-init.d.mts.map +1 -0
  19. package/dist/commands/db-init.mjs +124 -0
  20. package/dist/commands/db-init.mjs.map +1 -0
  21. package/dist/commands/db-schema.d.mts +7 -0
  22. package/dist/commands/db-schema.d.mts.map +1 -0
  23. package/dist/commands/db-schema.mjs +52 -0
  24. package/dist/commands/db-schema.mjs.map +1 -0
  25. package/dist/commands/db-sign.d.mts +7 -0
  26. package/dist/commands/db-sign.d.mts.map +1 -0
  27. package/dist/commands/db-sign.mjs +135 -0
  28. package/dist/commands/db-sign.mjs.map +1 -0
  29. package/dist/commands/db-update.d.mts +7 -0
  30. package/dist/commands/db-update.d.mts.map +1 -0
  31. package/dist/commands/db-update.mjs +121 -0
  32. package/dist/commands/db-update.mjs.map +1 -0
  33. package/dist/commands/db-verify.d.mts +7 -0
  34. package/dist/commands/db-verify.d.mts.map +1 -0
  35. package/dist/commands/db-verify.mjs +310 -0
  36. package/dist/commands/db-verify.mjs.map +1 -0
  37. package/dist/commands/migration-apply.d.mts +36 -0
  38. package/dist/commands/migration-apply.d.mts.map +1 -0
  39. package/dist/commands/migration-apply.mjs +240 -0
  40. package/dist/commands/migration-apply.mjs.map +1 -0
  41. package/dist/commands/migration-plan.d.mts +47 -0
  42. package/dist/commands/migration-plan.d.mts.map +1 -0
  43. package/dist/commands/migration-plan.mjs +288 -0
  44. package/dist/commands/migration-plan.mjs.map +1 -0
  45. package/dist/commands/migration-ref.d.mts +43 -0
  46. package/dist/commands/migration-ref.d.mts.map +1 -0
  47. package/dist/commands/migration-ref.mjs +194 -0
  48. package/dist/commands/migration-ref.mjs.map +1 -0
  49. package/dist/commands/migration-show.d.mts +28 -0
  50. package/dist/commands/migration-show.d.mts.map +1 -0
  51. package/dist/commands/migration-show.mjs +139 -0
  52. package/dist/commands/migration-show.mjs.map +1 -0
  53. package/dist/commands/migration-status.d.mts +85 -0
  54. package/dist/commands/migration-status.d.mts.map +1 -0
  55. package/dist/commands/migration-status.mjs +4 -0
  56. package/dist/commands/migration-verify.d.mts +16 -0
  57. package/dist/commands/migration-verify.d.mts.map +1 -0
  58. package/dist/commands/migration-verify.mjs +87 -0
  59. package/dist/commands/migration-verify.mjs.map +1 -0
  60. package/dist/config-loader-d_KF19Tw.mjs +43 -0
  61. package/dist/config-loader-d_KF19Tw.mjs.map +1 -0
  62. package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
  63. package/dist/config-loader.d.mts.map +1 -0
  64. package/dist/config-loader.mjs +3 -0
  65. package/dist/contract-emit-CVv7dbQ9.mjs +187 -0
  66. package/dist/contract-emit-CVv7dbQ9.mjs.map +1 -0
  67. package/dist/contract-infer-Bvw8u8Eu.mjs +83 -0
  68. package/dist/contract-infer-Bvw8u8Eu.mjs.map +1 -0
  69. package/dist/exports/config-types.d.mts +2 -0
  70. package/dist/exports/config-types.mjs +3 -0
  71. package/dist/exports/control-api.d.mts +626 -0
  72. package/dist/exports/control-api.d.mts.map +1 -0
  73. package/dist/exports/control-api.mjs +107 -0
  74. package/dist/exports/control-api.mjs.map +1 -0
  75. package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +10 -5
  76. package/dist/exports/index.d.mts.map +1 -0
  77. package/dist/exports/index.mjs +130 -0
  78. package/dist/exports/index.mjs.map +1 -0
  79. package/dist/extract-sql-ddl-Jf5blEO0.mjs +26 -0
  80. package/dist/extract-sql-ddl-Jf5blEO0.mjs.map +1 -0
  81. package/dist/framework-components-M2j-qPfr.mjs +59 -0
  82. package/dist/framework-components-M2j-qPfr.mjs.map +1 -0
  83. package/dist/inspect-live-schema-BQe5i4YE.mjs +90 -0
  84. package/dist/inspect-live-schema-BQe5i4YE.mjs.map +1 -0
  85. package/dist/migration-command-scaffold-SLrjcKXS.mjs +104 -0
  86. package/dist/migration-command-scaffold-SLrjcKXS.mjs.map +1 -0
  87. package/dist/migration-status-B7OVZ-Ka.mjs +1576 -0
  88. package/dist/migration-status-B7OVZ-Ka.mjs.map +1 -0
  89. package/dist/migrations-Db_ea9eE.mjs +173 -0
  90. package/dist/migrations-Db_ea9eE.mjs.map +1 -0
  91. package/dist/progress-adapter-DRNe2idZ.mjs +43 -0
  92. package/dist/progress-adapter-DRNe2idZ.mjs.map +1 -0
  93. package/dist/terminal-ui-DAcMBRKf.mjs +980 -0
  94. package/dist/terminal-ui-DAcMBRKf.mjs.map +1 -0
  95. package/dist/verify-DXKxBFvU.mjs +385 -0
  96. package/dist/verify-DXKxBFvU.mjs.map +1 -0
  97. package/package.json +88 -43
  98. package/src/cli.ts +109 -58
  99. package/src/commands/contract-emit.ts +236 -143
  100. package/src/commands/contract-infer-paths.ts +32 -0
  101. package/src/commands/contract-infer.ts +131 -0
  102. package/src/commands/db-init.ts +211 -425
  103. package/src/commands/db-schema.ts +77 -0
  104. package/src/commands/db-sign.ts +207 -228
  105. package/src/commands/db-update.ts +236 -0
  106. package/src/commands/db-verify.ts +484 -186
  107. package/src/commands/inspect-live-schema.ts +171 -0
  108. package/src/commands/migration-apply.ts +416 -0
  109. package/src/commands/migration-plan.ts +451 -0
  110. package/src/commands/migration-ref.ts +305 -0
  111. package/src/commands/migration-show.ts +246 -0
  112. package/src/commands/migration-status.ts +838 -0
  113. package/src/commands/migration-verify.ts +134 -0
  114. package/src/config-loader.ts +13 -3
  115. package/src/control-api/client.ts +614 -0
  116. package/src/control-api/contract-enrichment.ts +135 -0
  117. package/src/control-api/errors.ts +9 -0
  118. package/src/control-api/operations/contract-emit.ts +173 -0
  119. package/src/control-api/operations/db-init.ts +286 -0
  120. package/src/control-api/operations/db-update.ts +221 -0
  121. package/src/control-api/operations/extract-sql-ddl.ts +47 -0
  122. package/src/control-api/operations/migration-apply.ts +194 -0
  123. package/src/control-api/operations/migration-helpers.ts +49 -0
  124. package/src/control-api/types.ts +683 -0
  125. package/src/exports/config-types.ts +4 -3
  126. package/src/exports/control-api.ts +56 -0
  127. package/src/load-ts-contract.ts +16 -11
  128. package/src/utils/cli-errors.ts +5 -2
  129. package/src/utils/command-helpers.ts +293 -3
  130. package/src/utils/formatters/emit.ts +67 -0
  131. package/src/utils/formatters/errors.ts +82 -0
  132. package/src/utils/formatters/graph-migration-mapper.ts +220 -0
  133. package/src/utils/formatters/graph-render.ts +1317 -0
  134. package/src/utils/formatters/graph-types.ts +114 -0
  135. package/src/utils/formatters/help.ts +380 -0
  136. package/src/utils/formatters/helpers.ts +28 -0
  137. package/src/utils/formatters/migrations.ts +346 -0
  138. package/src/utils/formatters/styled.ts +212 -0
  139. package/src/utils/formatters/verify.ts +620 -0
  140. package/src/utils/global-flags.ts +41 -23
  141. package/src/utils/migration-command-scaffold.ts +187 -0
  142. package/src/utils/migration-types.ts +12 -0
  143. package/src/utils/progress-adapter.ts +75 -0
  144. package/src/utils/result-handler.ts +12 -13
  145. package/src/utils/shutdown.ts +92 -0
  146. package/src/utils/suggest-command.ts +31 -0
  147. package/src/utils/terminal-ui.ts +276 -0
  148. package/dist/chunk-BZMBKEEQ.js +0 -997
  149. package/dist/chunk-BZMBKEEQ.js.map +0 -1
  150. package/dist/chunk-CVNWLFXO.js +0 -91
  151. package/dist/chunk-CVNWLFXO.js.map +0 -1
  152. package/dist/chunk-HWYQOCAJ.js +0 -47
  153. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  154. package/dist/chunk-QUPBU4KV.js +0 -131
  155. package/dist/chunk-QUPBU4KV.js.map +0 -1
  156. package/dist/cli.d.ts +0 -2
  157. package/dist/cli.d.ts.map +0 -1
  158. package/dist/cli.js.map +0 -1
  159. package/dist/commands/contract-emit.d.ts +0 -3
  160. package/dist/commands/contract-emit.d.ts.map +0 -1
  161. package/dist/commands/contract-emit.js +0 -9
  162. package/dist/commands/contract-emit.js.map +0 -1
  163. package/dist/commands/db-init.d.ts +0 -3
  164. package/dist/commands/db-init.d.ts.map +0 -1
  165. package/dist/commands/db-init.js +0 -337
  166. package/dist/commands/db-init.js.map +0 -1
  167. package/dist/commands/db-introspect.d.ts +0 -3
  168. package/dist/commands/db-introspect.d.ts.map +0 -1
  169. package/dist/commands/db-introspect.js +0 -186
  170. package/dist/commands/db-introspect.js.map +0 -1
  171. package/dist/commands/db-schema-verify.d.ts +0 -3
  172. package/dist/commands/db-schema-verify.d.ts.map +0 -1
  173. package/dist/commands/db-schema-verify.js +0 -160
  174. package/dist/commands/db-schema-verify.js.map +0 -1
  175. package/dist/commands/db-sign.d.ts +0 -3
  176. package/dist/commands/db-sign.d.ts.map +0 -1
  177. package/dist/commands/db-sign.js +0 -195
  178. package/dist/commands/db-sign.js.map +0 -1
  179. package/dist/commands/db-verify.d.ts +0 -3
  180. package/dist/commands/db-verify.d.ts.map +0 -1
  181. package/dist/commands/db-verify.js +0 -169
  182. package/dist/commands/db-verify.js.map +0 -1
  183. package/dist/config-loader.d.ts.map +0 -1
  184. package/dist/config-loader.js +0 -7
  185. package/dist/config-loader.js.map +0 -1
  186. package/dist/exports/config-types.d.ts +0 -3
  187. package/dist/exports/config-types.d.ts.map +0 -1
  188. package/dist/exports/config-types.js +0 -6
  189. package/dist/exports/config-types.js.map +0 -1
  190. package/dist/exports/index.d.ts +0 -4
  191. package/dist/exports/index.d.ts.map +0 -1
  192. package/dist/exports/index.js +0 -175
  193. package/dist/exports/index.js.map +0 -1
  194. package/dist/load-ts-contract.d.ts.map +0 -1
  195. package/dist/utils/action.d.ts +0 -16
  196. package/dist/utils/action.d.ts.map +0 -1
  197. package/dist/utils/cli-errors.d.ts +0 -7
  198. package/dist/utils/cli-errors.d.ts.map +0 -1
  199. package/dist/utils/command-helpers.d.ts +0 -12
  200. package/dist/utils/command-helpers.d.ts.map +0 -1
  201. package/dist/utils/framework-components.d.ts +0 -70
  202. package/dist/utils/framework-components.d.ts.map +0 -1
  203. package/dist/utils/global-flags.d.ts +0 -25
  204. package/dist/utils/global-flags.d.ts.map +0 -1
  205. package/dist/utils/output.d.ts +0 -142
  206. package/dist/utils/output.d.ts.map +0 -1
  207. package/dist/utils/result-handler.d.ts +0 -15
  208. package/dist/utils/result-handler.d.ts.map +0 -1
  209. package/dist/utils/spinner.d.ts +0 -29
  210. package/dist/utils/spinner.d.ts.map +0 -1
  211. package/src/commands/db-introspect.ts +0 -256
  212. package/src/commands/db-schema-verify.ts +0 -232
  213. package/src/utils/action.ts +0 -43
  214. package/src/utils/output.ts +0 -1471
  215. package/src/utils/spinner.ts +0 -67
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Maps MigrationGraph + status info to the generic graph renderer types.
3
+ */
4
+ import { EMPTY_CONTRACT_HASH } from '@prisma-next/core-control-plane/constants';
5
+ import { findPath } from '@prisma-next/migration-tools/dag';
6
+ import type { MigrationGraph } from '@prisma-next/migration-tools/types';
7
+ import { ifDefined } from '@prisma-next/utils/defined';
8
+
9
+ import type { StatusRef } from '../migration-types';
10
+ import {
11
+ type GraphEdge,
12
+ type GraphNode,
13
+ type GraphRenderOptions,
14
+ type NodeMarker,
15
+ RenderGraph,
16
+ } from './graph-types';
17
+
18
+ export type EdgeStatusKind = 'applied' | 'pending' | 'unreachable';
19
+
20
+ const STATUS_ICON: Record<EdgeStatusKind, string> = {
21
+ applied: ' ✓',
22
+ pending: ' ⧗',
23
+ unreachable: ' ✗',
24
+ };
25
+
26
+ /** Shorten a contract hash for display: strip sha256: prefix, take 7 chars. */
27
+ function shortHash(hash: string): string {
28
+ const stripped = hash.startsWith('sha256:') ? hash.slice(7) : hash;
29
+ return stripped.slice(0, 7);
30
+ }
31
+
32
+ function toShortId(hash: string): string {
33
+ return hash === EMPTY_CONTRACT_HASH ? '∅' : shortHash(hash);
34
+ }
35
+
36
+ /** Minimal per-edge status from the CLI's status result. */
37
+ export interface EdgeStatus {
38
+ readonly dirName: string;
39
+ readonly status: EdgeStatusKind;
40
+ }
41
+
42
+ export interface MigrationGraphInput {
43
+ readonly graph: MigrationGraph;
44
+ readonly mode: 'online' | 'offline';
45
+ readonly markerHash?: string | undefined;
46
+ readonly contractHash: string;
47
+ readonly refs?: readonly StatusRef[] | undefined;
48
+ readonly activeRefHash?: string | undefined;
49
+ readonly activeRefName?: string | undefined;
50
+ /**
51
+ * Per-edge applied/pending status from the ledger. When provided, status
52
+ * icons (✓/⧗) are baked into edge labels. Undefined in offline mode.
53
+ */
54
+ readonly edgeStatuses?: readonly EdgeStatus[] | undefined;
55
+ }
56
+
57
+ export interface MigrationRenderInput {
58
+ readonly graph: RenderGraph;
59
+ readonly options: GraphRenderOptions;
60
+ /** All relevant paths (root→contract, root→marker, root→ref). */
61
+ readonly relevantPaths: readonly (readonly string[])[];
62
+ }
63
+
64
+ /**
65
+ * Convert a MigrationGraph + status info into the generic graph renderer types.
66
+ */
67
+ export function migrationGraphToRenderInput(input: MigrationGraphInput): MigrationRenderInput {
68
+ const { graph, mode, markerHash, contractHash, refs, activeRefHash, edgeStatuses } = input;
69
+
70
+ const statusByDirName = new Map(edgeStatuses?.map((e) => [e.dirName, e.status]));
71
+
72
+ // Build nodes
73
+ const nodeList: GraphNode[] = [];
74
+ for (const nodeId of graph.nodes) {
75
+ const markers: NodeMarker[] = [];
76
+
77
+ // DB marker
78
+ if (mode === 'online' && markerHash === nodeId) {
79
+ markers.push({ kind: 'db' });
80
+ }
81
+
82
+ // Ref markers
83
+ if (refs) {
84
+ for (const ref of refs) {
85
+ if (ref.hash === nodeId) {
86
+ markers.push({ kind: 'ref', name: ref.name, active: ref.active });
87
+ }
88
+ }
89
+ }
90
+
91
+ // Contract marker
92
+ if (contractHash === nodeId && contractHash !== EMPTY_CONTRACT_HASH) {
93
+ markers.push({ kind: 'contract', planned: true });
94
+ }
95
+
96
+ nodeList.push({
97
+ id: toShortId(nodeId),
98
+ markers: markers.length > 0 ? markers : undefined,
99
+ });
100
+ }
101
+
102
+ // Detached contract node (not in graph)
103
+ if (contractHash !== EMPTY_CONTRACT_HASH && !graph.nodes.has(contractHash)) {
104
+ const detachedMarkers: NodeMarker[] = [];
105
+ if (mode === 'online' && markerHash === contractHash) {
106
+ detachedMarkers.push({ kind: 'db' });
107
+ }
108
+ detachedMarkers.push({ kind: 'contract', planned: false });
109
+ nodeList.push({
110
+ id: shortHash(contractHash),
111
+ markers: detachedMarkers,
112
+ style: 'detached',
113
+ });
114
+ }
115
+
116
+ // Build edges
117
+ const edgeList: GraphEdge[] = [];
118
+ for (const [, entries] of graph.forwardChain) {
119
+ for (const entry of entries) {
120
+ const status = statusByDirName.get(entry.dirName);
121
+ const icon = status ? STATUS_ICON[status] : '';
122
+ const label = `${entry.dirName}${icon}`;
123
+
124
+ edgeList.push({
125
+ from: toShortId(entry.from),
126
+ to: toShortId(entry.to),
127
+ label,
128
+ ...ifDefined('colorHint', status),
129
+ });
130
+ }
131
+ }
132
+
133
+ // Compute paths to all interesting targets so the default view shows the
134
+ // minimal subgraph that covers everything relevant: contract, DB marker, ref.
135
+ const relevantPaths: string[][] = [];
136
+ const rootId = EMPTY_CONTRACT_HASH;
137
+
138
+ function addPathFromRoot(targetHash: string): void {
139
+ if (!graph.nodes.has(targetHash)) return;
140
+ const raw = findPath(graph, rootId, targetHash);
141
+ if (raw && raw.length > 0) {
142
+ relevantPaths.push([toShortId(rootId), ...raw.map((e) => toShortId(e.to))]);
143
+ }
144
+ }
145
+
146
+ function addPathBetween(fromHash: string, toHash: string): void {
147
+ if (!graph.nodes.has(fromHash) || !graph.nodes.has(toHash)) return;
148
+ const raw = findPath(graph, fromHash, toHash);
149
+ if (raw && raw.length > 0) {
150
+ relevantPaths.push([toShortId(fromHash), ...raw.map((e) => toShortId(e.to))]);
151
+ }
152
+ }
153
+
154
+ // 1. Path to the DB marker
155
+ if (mode === 'online' && markerHash) {
156
+ addPathFromRoot(markerHash);
157
+ }
158
+
159
+ // 2. Path to the ref
160
+ if (activeRefHash && activeRefHash !== markerHash) {
161
+ addPathFromRoot(activeRefHash);
162
+ }
163
+
164
+ // 3. Path(s) to the contract — prefer continuing from marker and/or ref
165
+ // rather than an independent root→contract (which BFS may route through
166
+ // an unrelated branch). When both marker and ref exist, try both paths
167
+ // so that the diamond (two branches converging at the contract) is visible.
168
+ if (contractHash !== EMPTY_CONTRACT_HASH) {
169
+ let contractReached = false;
170
+
171
+ if (markerHash && markerHash !== contractHash) {
172
+ const markerReaches = findPath(graph, markerHash, contractHash);
173
+ if (markerReaches) {
174
+ addPathBetween(markerHash, contractHash);
175
+ contractReached = true;
176
+ }
177
+ }
178
+
179
+ if (activeRefHash && activeRefHash !== markerHash && activeRefHash !== contractHash) {
180
+ const refReaches = findPath(graph, activeRefHash, contractHash);
181
+ if (refReaches) {
182
+ addPathBetween(activeRefHash, contractHash);
183
+ contractReached = true;
184
+ }
185
+ }
186
+
187
+ if (!contractReached && contractHash !== (markerHash ?? activeRefHash)) {
188
+ addPathFromRoot(contractHash);
189
+ }
190
+ }
191
+
192
+ // Fall back: if no paths were found, try the tip of the forward chain.
193
+ if (relevantPaths.length === 0) {
194
+ const lastEdge = [...graph.forwardChain.values()].flat().pop();
195
+ const fallbackHash = lastEdge?.to ?? EMPTY_CONTRACT_HASH;
196
+ addPathFromRoot(fallbackHash);
197
+ }
198
+
199
+ // Spine target for rendering (edge coloring, detached node alignment).
200
+ let spineTargetHash: string;
201
+
202
+ if (activeRefHash && graph.nodes.has(activeRefHash)) {
203
+ spineTargetHash = activeRefHash;
204
+ } else if (contractHash !== EMPTY_CONTRACT_HASH && graph.nodes.has(contractHash)) {
205
+ spineTargetHash = contractHash;
206
+ } else {
207
+ const lastEdge = [...graph.forwardChain.values()].flat().pop();
208
+ spineTargetHash = lastEdge?.to ?? EMPTY_CONTRACT_HASH;
209
+ }
210
+
211
+ return {
212
+ graph: new RenderGraph(nodeList, edgeList),
213
+ options: {
214
+ spineTarget: toShortId(spineTargetHash),
215
+ rootId: '∅',
216
+ colorize: true,
217
+ },
218
+ relevantPaths,
219
+ };
220
+ }