@prisma-next/core-control-plane 0.3.0-dev.55 → 0.3.0-dev.57

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.
@@ -1,310 +0,0 @@
1
- //#region src/errors.ts
2
- /**
3
- * Structured CLI error that contains all information needed for error envelopes.
4
- * Call sites throw these errors with full context.
5
- */
6
- var CliStructuredError = class extends Error {
7
- code;
8
- domain;
9
- severity;
10
- why;
11
- fix;
12
- where;
13
- meta;
14
- docsUrl;
15
- constructor(code, summary, options) {
16
- super(summary);
17
- this.name = "CliStructuredError";
18
- this.code = code;
19
- this.domain = options?.domain ?? "CLI";
20
- this.severity = options?.severity ?? "error";
21
- this.why = options?.why;
22
- this.fix = options?.fix === options?.why ? void 0 : options?.fix;
23
- this.where = options?.where ? {
24
- path: options.where.path,
25
- line: options.where.line
26
- } : void 0;
27
- this.meta = options?.meta;
28
- this.docsUrl = options?.docsUrl;
29
- }
30
- /**
31
- * Converts this error to a CLI error envelope for output formatting.
32
- */
33
- toEnvelope() {
34
- return {
35
- ok: false,
36
- code: `${this.domain === "CLI" ? "PN-CLI-" : "PN-RTM-"}${this.code}`,
37
- domain: this.domain,
38
- severity: this.severity,
39
- summary: this.message,
40
- why: this.why,
41
- fix: this.fix,
42
- where: this.where,
43
- meta: this.meta,
44
- docsUrl: this.docsUrl
45
- };
46
- }
47
- /**
48
- * Type guard to check if an error is a CliStructuredError.
49
- * Uses duck-typing to work across module boundaries where instanceof may fail.
50
- */
51
- static is(error) {
52
- if (!(error instanceof Error)) return false;
53
- const candidate = error;
54
- return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && (candidate.domain === "CLI" || candidate.domain === "RTM") && typeof candidate.toEnvelope === "function";
55
- }
56
- };
57
- /**
58
- * Config file not found or missing.
59
- */
60
- function errorConfigFileNotFound(configPath, options) {
61
- return new CliStructuredError("4001", "Config file not found", {
62
- domain: "CLI",
63
- ...options?.why ? { why: options.why } : { why: "Config file not found" },
64
- fix: "Run 'prisma-next init' to create a config file",
65
- docsUrl: "https://prisma-next.dev/docs/cli/config",
66
- ...configPath ? { where: { path: configPath } } : {}
67
- });
68
- }
69
- /**
70
- * Contract configuration missing from config.
71
- */
72
- function errorContractConfigMissing(options) {
73
- return new CliStructuredError("4002", "Contract configuration missing", {
74
- domain: "CLI",
75
- why: options?.why ?? "The contract configuration is required for emit",
76
- fix: "Add contract configuration to your prisma-next.config.ts",
77
- docsUrl: "https://prisma-next.dev/docs/cli/contract-emit"
78
- });
79
- }
80
- /**
81
- * Contract validation failed.
82
- */
83
- function errorContractValidationFailed(reason, options) {
84
- return new CliStructuredError("4003", "Contract validation failed", {
85
- domain: "CLI",
86
- why: reason,
87
- fix: "Re-run `prisma-next contract emit`, or fix the contract file and try again",
88
- docsUrl: "https://prisma-next.dev/docs/contracts",
89
- ...options?.where ? { where: options.where } : {}
90
- });
91
- }
92
- /**
93
- * File not found.
94
- */
95
- function errorFileNotFound(filePath, options) {
96
- return new CliStructuredError("4004", "File not found", {
97
- domain: "CLI",
98
- why: options?.why ?? `File not found: ${filePath}`,
99
- fix: options?.fix ?? "Check that the file path is correct",
100
- where: { path: filePath },
101
- ...options?.docsUrl ? { docsUrl: options.docsUrl } : {}
102
- });
103
- }
104
- /**
105
- * Database connection is required but not provided.
106
- */
107
- function errorDatabaseConnectionRequired(options) {
108
- return new CliStructuredError("4005", "Database connection is required", {
109
- domain: "CLI",
110
- why: options?.why ?? "Database connection is required for this command",
111
- fix: "Provide `--db <url>` or set `db: { connection: \"postgres://…\" }` in prisma-next.config.ts"
112
- });
113
- }
114
- /**
115
- * Query runner factory is required but not provided in config.
116
- */
117
- function errorQueryRunnerFactoryRequired(options) {
118
- return new CliStructuredError("4006", "Query runner factory is required", {
119
- domain: "CLI",
120
- why: options?.why ?? "Config.db.queryRunnerFactory is required for db verify",
121
- fix: "Add db.queryRunnerFactory to prisma-next.config.ts",
122
- docsUrl: "https://prisma-next.dev/docs/cli/db-verify"
123
- });
124
- }
125
- /**
126
- * Family verify.readMarker is required but not provided.
127
- */
128
- function errorFamilyReadMarkerSqlRequired(options) {
129
- return new CliStructuredError("4007", "Family readMarker() is required", {
130
- domain: "CLI",
131
- why: options?.why ?? "Family verify.readMarker is required for db verify",
132
- fix: "Ensure family.verify.readMarker() is exported by your family package",
133
- docsUrl: "https://prisma-next.dev/docs/cli/db-verify"
134
- });
135
- }
136
- /**
137
- * JSON output format not supported.
138
- */
139
- function errorJsonFormatNotSupported(options) {
140
- return new CliStructuredError("4008", "Unsupported JSON format", {
141
- domain: "CLI",
142
- why: `The ${options.command} command does not support --json ${options.format}`,
143
- fix: `Use --json ${options.supportedFormats.join(" or ")}, or omit --json for human output`,
144
- meta: {
145
- command: options.command,
146
- format: options.format,
147
- supportedFormats: options.supportedFormats
148
- }
149
- });
150
- }
151
- /**
152
- * Driver is required for DB-connected commands but not provided.
153
- */
154
- function errorDriverRequired(options) {
155
- return new CliStructuredError("4010", "Driver is required for DB-connected commands", {
156
- domain: "CLI",
157
- why: options?.why ?? "Config.driver is required for DB-connected commands",
158
- fix: "Add a control-plane driver to prisma-next.config.ts (e.g. import a driver descriptor and set `driver: postgresDriver`)",
159
- docsUrl: "https://prisma-next.dev/docs/cli/config"
160
- });
161
- }
162
- /**
163
- * Contract requires extension packs that are not provided by config descriptors.
164
- */
165
- function errorContractMissingExtensionPacks(options) {
166
- const missing = [...options.missingExtensionPacks].sort();
167
- return new CliStructuredError("4011", "Missing extension packs in config", {
168
- domain: "CLI",
169
- why: missing.length === 1 ? `Contract requires extension pack '${missing[0]}', but CLI config does not provide a matching descriptor.` : `Contract requires extension packs ${missing.map((p) => `'${p}'`).join(", ")}, but CLI config does not provide matching descriptors.`,
170
- fix: "Add the missing extension descriptors to `extensions` in prisma-next.config.ts",
171
- docsUrl: "https://prisma-next.dev/docs/cli/config",
172
- meta: {
173
- missingExtensionPacks: missing,
174
- providedComponentIds: [...options.providedComponentIds].sort()
175
- }
176
- });
177
- }
178
- /**
179
- * Migration planning failed due to conflicts.
180
- */
181
- function errorMigrationPlanningFailed(options) {
182
- const conflictSummaries = options.conflicts.map((c) => c.summary);
183
- const computedWhy = options.why ?? conflictSummaries.join("\n");
184
- const conflictFixes = options.conflicts.map((c) => c.why).filter((why) => typeof why === "string");
185
- return new CliStructuredError("4020", "Migration planning failed", {
186
- domain: "CLI",
187
- why: computedWhy,
188
- fix: conflictFixes.length > 0 ? conflictFixes.join("\n") : "Use `db schema-verify` to inspect conflicts, or ensure the database is empty",
189
- meta: { conflicts: options.conflicts },
190
- docsUrl: "https://prisma-next.dev/docs/cli/db-init"
191
- });
192
- }
193
- /**
194
- * Target does not support migrations (missing createPlanner/createRunner).
195
- */
196
- function errorTargetMigrationNotSupported(options) {
197
- return new CliStructuredError("4021", "Target does not support migrations", {
198
- domain: "CLI",
199
- why: options?.why ?? "The configured target does not provide migration planner/runner",
200
- fix: "Select a target that provides migrations (it must export `target.migrations` for db init)",
201
- docsUrl: "https://prisma-next.dev/docs/cli/db-init"
202
- });
203
- }
204
- /**
205
- * Config validation error (missing required fields).
206
- */
207
- function errorConfigValidation(field, options) {
208
- return new CliStructuredError("4009", "Config validation error", {
209
- domain: "CLI",
210
- why: options?.why ?? `Config must have a "${field}" field`,
211
- fix: "Check your prisma-next.config.ts and ensure all required fields are provided",
212
- docsUrl: "https://prisma-next.dev/docs/cli/config"
213
- });
214
- }
215
- /**
216
- * Contract marker not found in database.
217
- */
218
- function errorMarkerMissing(options) {
219
- return new CliStructuredError("3001", "Database not signed", {
220
- domain: "RTM",
221
- why: options?.why ?? "No database signature (marker) found",
222
- fix: "Run `prisma-next db sign --db <url>` to sign the database"
223
- });
224
- }
225
- /**
226
- * Contract hash does not match database marker.
227
- */
228
- function errorHashMismatch(options) {
229
- return new CliStructuredError("3002", "Hash mismatch", {
230
- domain: "RTM",
231
- why: options?.why ?? "Contract hash does not match database marker",
232
- fix: "Migrate database or re-sign if intentional",
233
- ...options?.expected || options?.actual ? { meta: {
234
- ...options.expected ? { expected: options.expected } : {},
235
- ...options.actual ? { actual: options.actual } : {}
236
- } } : {}
237
- });
238
- }
239
- /**
240
- * Contract target does not match config target.
241
- */
242
- function errorTargetMismatch(expected, actual, options) {
243
- return new CliStructuredError("3003", "Target mismatch", {
244
- domain: "RTM",
245
- why: options?.why ?? `Contract target does not match config target (expected: ${expected}, actual: ${actual})`,
246
- fix: "Align contract target and config target",
247
- meta: {
248
- expected,
249
- actual
250
- }
251
- });
252
- }
253
- /**
254
- * Database marker is required but not found.
255
- * Used by commands that require a pre-existing marker as a precondition.
256
- */
257
- function errorMarkerRequired(options) {
258
- return new CliStructuredError("3010", "Database must be signed first", {
259
- domain: "RTM",
260
- why: options?.why ?? "No database signature (marker) found",
261
- fix: options?.fix ?? "Run `prisma-next db init` first to sign the database"
262
- });
263
- }
264
- /**
265
- * Migration runner failed during execution.
266
- */
267
- function errorRunnerFailed(summary, options) {
268
- return new CliStructuredError("3020", summary, {
269
- domain: "RTM",
270
- why: options?.why ?? "Migration runner failed",
271
- fix: options?.fix ?? "Inspect the reported conflict and reconcile schema drift",
272
- ...options?.meta ? { meta: options.meta } : {}
273
- });
274
- }
275
- /**
276
- * Destructive operations require explicit confirmation via --accept-data-loss.
277
- */
278
- function errorDestructiveChanges(summary, options) {
279
- return new CliStructuredError("3030", summary, {
280
- domain: "RTM",
281
- why: options?.why ?? "Planned operations include destructive changes that require confirmation",
282
- fix: options?.fix ?? "Use `--plan` to preview, then re-run with `--accept-data-loss`",
283
- ...options?.meta ? { meta: options.meta } : {}
284
- });
285
- }
286
- /**
287
- * Generic runtime error.
288
- */
289
- function errorRuntime(summary, options) {
290
- return new CliStructuredError("3000", summary, {
291
- domain: "RTM",
292
- ...options?.why ? { why: options.why } : { why: "Verification failed" },
293
- ...options?.fix ? { fix: options.fix } : { fix: "Check contract and database state" },
294
- ...options?.meta ? { meta: options.meta } : {}
295
- });
296
- }
297
- /**
298
- * Generic unexpected error.
299
- */
300
- function errorUnexpected(message, options) {
301
- return new CliStructuredError("4999", "Unexpected error", {
302
- domain: "CLI",
303
- why: options?.why ?? message,
304
- fix: options?.fix ?? "Check the error message and try again"
305
- });
306
- }
307
-
308
- //#endregion
309
- export { errorUnexpected as S, errorQueryRunnerFactoryRequired as _, errorContractMissingExtensionPacks as a, errorTargetMigrationNotSupported as b, errorDestructiveChanges as c, errorFileNotFound as d, errorHashMismatch as f, errorMigrationPlanningFailed as g, errorMarkerRequired as h, errorContractConfigMissing as i, errorDriverRequired as l, errorMarkerMissing as m, errorConfigFileNotFound as n, errorContractValidationFailed as o, errorJsonFormatNotSupported as p, errorConfigValidation as r, errorDatabaseConnectionRequired as s, CliStructuredError as t, errorFamilyReadMarkerSqlRequired as u, errorRunnerFailed as v, errorTargetMismatch as x, errorRuntime as y };
310
- //# sourceMappingURL=errors-CvuQhtGp.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-CvuQhtGp.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * CLI error envelope for output formatting.\n * This is the serialized form of a CliStructuredError.\n */\nexport interface CliErrorEnvelope {\n readonly ok: false;\n readonly code: string;\n readonly domain: string;\n readonly severity: 'error' | 'warn' | 'info';\n readonly summary: string;\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n}\n\n/**\n * Minimal conflict data structure expected by CLI output.\n */\nexport interface CliErrorConflict {\n readonly kind: string;\n readonly summary: string;\n readonly why?: string;\n}\n\n/**\n * Structured CLI error that contains all information needed for error envelopes.\n * Call sites throw these errors with full context.\n */\nexport class CliStructuredError extends Error {\n readonly code: string;\n readonly domain: 'CLI' | 'RTM';\n readonly severity: 'error' | 'warn' | 'info';\n readonly why: string | undefined;\n readonly fix: string | undefined;\n readonly where:\n | {\n readonly path: string | undefined;\n readonly line: number | undefined;\n }\n | undefined;\n readonly meta: Record<string, unknown> | undefined;\n readonly docsUrl: string | undefined;\n\n constructor(\n code: string,\n summary: string,\n options?: {\n readonly domain?: 'CLI' | 'RTM';\n readonly severity?: 'error' | 'warn' | 'info';\n readonly why?: string;\n readonly fix?: string;\n readonly where?: { readonly path?: string; readonly line?: number };\n readonly meta?: Record<string, unknown>;\n readonly docsUrl?: string;\n },\n ) {\n super(summary);\n this.name = 'CliStructuredError';\n this.code = code;\n this.domain = options?.domain ?? 'CLI';\n this.severity = options?.severity ?? 'error';\n this.why = options?.why;\n this.fix = options?.fix === options?.why ? undefined : options?.fix;\n this.where = options?.where\n ? {\n path: options.where.path,\n line: options.where.line,\n }\n : undefined;\n this.meta = options?.meta;\n this.docsUrl = options?.docsUrl;\n }\n\n /**\n * Converts this error to a CLI error envelope for output formatting.\n */\n toEnvelope(): CliErrorEnvelope {\n const codePrefix = this.domain === 'CLI' ? 'PN-CLI-' : 'PN-RTM-';\n return {\n ok: false as const,\n code: `${codePrefix}${this.code}`,\n domain: this.domain,\n severity: this.severity,\n summary: this.message,\n why: this.why,\n fix: this.fix,\n where: this.where,\n meta: this.meta,\n docsUrl: this.docsUrl,\n };\n }\n\n /**\n * Type guard to check if an error is a CliStructuredError.\n * Uses duck-typing to work across module boundaries where instanceof may fail.\n */\n static is(error: unknown): error is CliStructuredError {\n if (!(error instanceof Error)) {\n return false;\n }\n const candidate = error as CliStructuredError;\n return (\n candidate.name === 'CliStructuredError' &&\n typeof candidate.code === 'string' &&\n (candidate.domain === 'CLI' || candidate.domain === 'RTM') &&\n typeof candidate.toEnvelope === 'function'\n );\n }\n}\n\n// ============================================================================\n// Config Errors (PN-CLI-4001-4007)\n// ============================================================================\n\n/**\n * Config file not found or missing.\n */\nexport function errorConfigFileNotFound(\n configPath?: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4001', 'Config file not found', {\n domain: 'CLI',\n ...(options?.why ? { why: options.why } : { why: 'Config file not found' }),\n fix: \"Run 'prisma-next init' to create a config file\",\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n ...(configPath ? { where: { path: configPath } } : {}),\n });\n}\n\n/**\n * Contract configuration missing from config.\n */\nexport function errorContractConfigMissing(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4002', 'Contract configuration missing', {\n domain: 'CLI',\n why: options?.why ?? 'The contract configuration is required for emit',\n fix: 'Add contract configuration to your prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/contract-emit',\n });\n}\n\n/**\n * Contract validation failed.\n */\nexport function errorContractValidationFailed(\n reason: string,\n options?: {\n readonly where?: { readonly path?: string; readonly line?: number };\n },\n): CliStructuredError {\n return new CliStructuredError('4003', 'Contract validation failed', {\n domain: 'CLI',\n why: reason,\n fix: 'Re-run `prisma-next contract emit`, or fix the contract file and try again',\n docsUrl: 'https://prisma-next.dev/docs/contracts',\n ...(options?.where ? { where: options.where } : {}),\n });\n}\n\n/**\n * File not found.\n */\nexport function errorFileNotFound(\n filePath: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly docsUrl?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4004', 'File not found', {\n domain: 'CLI',\n why: options?.why ?? `File not found: ${filePath}`,\n fix: options?.fix ?? 'Check that the file path is correct',\n where: { path: filePath },\n ...(options?.docsUrl ? { docsUrl: options.docsUrl } : {}),\n });\n}\n\n/**\n * Database connection is required but not provided.\n */\nexport function errorDatabaseConnectionRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4005', 'Database connection is required', {\n domain: 'CLI',\n why: options?.why ?? 'Database connection is required for this command',\n fix: 'Provide `--db <url>` or set `db: { connection: \"postgres://…\" }` in prisma-next.config.ts',\n });\n}\n\n/**\n * Query runner factory is required but not provided in config.\n */\nexport function errorQueryRunnerFactoryRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4006', 'Query runner factory is required', {\n domain: 'CLI',\n why: options?.why ?? 'Config.db.queryRunnerFactory is required for db verify',\n fix: 'Add db.queryRunnerFactory to prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * Family verify.readMarker is required but not provided.\n */\nexport function errorFamilyReadMarkerSqlRequired(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4007', 'Family readMarker() is required', {\n domain: 'CLI',\n why: options?.why ?? 'Family verify.readMarker is required for db verify',\n fix: 'Ensure family.verify.readMarker() is exported by your family package',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-verify',\n });\n}\n\n/**\n * JSON output format not supported.\n */\nexport function errorJsonFormatNotSupported(options: {\n readonly command: string;\n readonly format: string;\n readonly supportedFormats: readonly string[];\n}): CliStructuredError {\n return new CliStructuredError('4008', 'Unsupported JSON format', {\n domain: 'CLI',\n why: `The ${options.command} command does not support --json ${options.format}`,\n fix: `Use --json ${options.supportedFormats.join(' or ')}, or omit --json for human output`,\n meta: {\n command: options.command,\n format: options.format,\n supportedFormats: options.supportedFormats,\n },\n });\n}\n\n/**\n * Driver is required for DB-connected commands but not provided.\n */\nexport function errorDriverRequired(options?: { readonly why?: string }): CliStructuredError {\n return new CliStructuredError('4010', 'Driver is required for DB-connected commands', {\n domain: 'CLI',\n why: options?.why ?? 'Config.driver is required for DB-connected commands',\n fix: 'Add a control-plane driver to prisma-next.config.ts (e.g. import a driver descriptor and set `driver: postgresDriver`)',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n/**\n * Contract requires extension packs that are not provided by config descriptors.\n */\nexport function errorContractMissingExtensionPacks(options: {\n readonly missingExtensionPacks: readonly string[];\n readonly providedComponentIds: readonly string[];\n}): CliStructuredError {\n const missing = [...options.missingExtensionPacks].sort();\n return new CliStructuredError('4011', 'Missing extension packs in config', {\n domain: 'CLI',\n why:\n missing.length === 1\n ? `Contract requires extension pack '${missing[0]}', but CLI config does not provide a matching descriptor.`\n : `Contract requires extension packs ${missing.map((p) => `'${p}'`).join(', ')}, but CLI config does not provide matching descriptors.`,\n fix: 'Add the missing extension descriptors to `extensions` in prisma-next.config.ts',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n meta: {\n missingExtensionPacks: missing,\n providedComponentIds: [...options.providedComponentIds].sort(),\n },\n });\n}\n\n/**\n * Migration planning failed due to conflicts.\n */\nexport function errorMigrationPlanningFailed(options: {\n readonly conflicts: readonly CliErrorConflict[];\n readonly why?: string;\n}): CliStructuredError {\n // Build \"why\" from conflict summaries - these contain the actual problem description\n const conflictSummaries = options.conflicts.map((c) => c.summary);\n const computedWhy = options.why ?? conflictSummaries.join('\\n');\n\n // Build \"fix\" from conflict \"why\" fields - these contain actionable advice\n const conflictFixes = options.conflicts\n .map((c) => c.why)\n .filter((why): why is string => typeof why === 'string');\n const computedFix =\n conflictFixes.length > 0\n ? conflictFixes.join('\\n')\n : 'Use `db schema-verify` to inspect conflicts, or ensure the database is empty';\n\n return new CliStructuredError('4020', 'Migration planning failed', {\n domain: 'CLI',\n why: computedWhy,\n fix: computedFix,\n meta: { conflicts: options.conflicts },\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Target does not support migrations (missing createPlanner/createRunner).\n */\nexport function errorTargetMigrationNotSupported(options?: {\n readonly why?: string;\n}): CliStructuredError {\n return new CliStructuredError('4021', 'Target does not support migrations', {\n domain: 'CLI',\n why: options?.why ?? 'The configured target does not provide migration planner/runner',\n fix: 'Select a target that provides migrations (it must export `target.migrations` for db init)',\n docsUrl: 'https://prisma-next.dev/docs/cli/db-init',\n });\n}\n\n/**\n * Config validation error (missing required fields).\n */\nexport function errorConfigValidation(\n field: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4009', 'Config validation error', {\n domain: 'CLI',\n why: options?.why ?? `Config must have a \"${field}\" field`,\n fix: 'Check your prisma-next.config.ts and ensure all required fields are provided',\n docsUrl: 'https://prisma-next.dev/docs/cli/config',\n });\n}\n\n// ============================================================================\n// Runtime Errors (PN-RTM-3000-3030)\n// ============================================================================\n\n/**\n * Contract marker not found in database.\n */\nexport function errorMarkerMissing(options?: {\n readonly why?: string;\n readonly dbUrl?: string;\n}): CliStructuredError {\n return new CliStructuredError('3001', 'Database not signed', {\n domain: 'RTM',\n why: options?.why ?? 'No database signature (marker) found',\n fix: 'Run `prisma-next db sign --db <url>` to sign the database',\n });\n}\n\n/**\n * Contract hash does not match database marker.\n */\nexport function errorHashMismatch(options?: {\n readonly why?: string;\n readonly expected?: string;\n readonly actual?: string;\n}): CliStructuredError {\n return new CliStructuredError('3002', 'Hash mismatch', {\n domain: 'RTM',\n why: options?.why ?? 'Contract hash does not match database marker',\n fix: 'Migrate database or re-sign if intentional',\n ...(options?.expected || options?.actual\n ? {\n meta: {\n ...(options.expected ? { expected: options.expected } : {}),\n ...(options.actual ? { actual: options.actual } : {}),\n },\n }\n : {}),\n });\n}\n\n/**\n * Contract target does not match config target.\n */\nexport function errorTargetMismatch(\n expected: string,\n actual: string,\n options?: {\n readonly why?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('3003', 'Target mismatch', {\n domain: 'RTM',\n why:\n options?.why ??\n `Contract target does not match config target (expected: ${expected}, actual: ${actual})`,\n fix: 'Align contract target and config target',\n meta: { expected, actual },\n });\n}\n\n/**\n * Database marker is required but not found.\n * Used by commands that require a pre-existing marker as a precondition.\n */\nexport function errorMarkerRequired(options?: {\n readonly why?: string;\n readonly fix?: string;\n}): CliStructuredError {\n return new CliStructuredError('3010', 'Database must be signed first', {\n domain: 'RTM',\n why: options?.why ?? 'No database signature (marker) found',\n fix: options?.fix ?? 'Run `prisma-next db init` first to sign the database',\n });\n}\n\n/**\n * Migration runner failed during execution.\n */\nexport function errorRunnerFailed(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3020', summary, {\n domain: 'RTM',\n why: options?.why ?? 'Migration runner failed',\n fix: options?.fix ?? 'Inspect the reported conflict and reconcile schema drift',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/**\n * Destructive operations require explicit confirmation via --accept-data-loss.\n */\nexport function errorDestructiveChanges(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3030', summary, {\n domain: 'RTM',\n why: options?.why ?? 'Planned operations include destructive changes that require confirmation',\n fix: options?.fix ?? 'Use `--plan` to preview, then re-run with `--accept-data-loss`',\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n/**\n * Generic runtime error.\n */\nexport function errorRuntime(\n summary: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n readonly meta?: Record<string, unknown>;\n },\n): CliStructuredError {\n return new CliStructuredError('3000', summary, {\n domain: 'RTM',\n ...(options?.why ? { why: options.why } : { why: 'Verification failed' }),\n ...(options?.fix ? { fix: options.fix } : { fix: 'Check contract and database state' }),\n ...(options?.meta ? { meta: options.meta } : {}),\n });\n}\n\n// ============================================================================\n// Generic Error\n// ============================================================================\n\n/**\n * Generic unexpected error.\n */\nexport function errorUnexpected(\n message: string,\n options?: {\n readonly why?: string;\n readonly fix?: string;\n },\n): CliStructuredError {\n return new CliStructuredError('4999', 'Unexpected error', {\n domain: 'CLI',\n why: options?.why ?? message,\n fix: options?.fix ?? 'Check the error message and try again',\n });\n}\n"],"mappings":";;;;;AAmCA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAMT,AAAS;CACT,AAAS;CAET,YACE,MACA,SACA,SASA;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,WAAW,SAAS,YAAY;AACrC,OAAK,MAAM,SAAS;AACpB,OAAK,MAAM,SAAS,QAAQ,SAAS,MAAM,SAAY,SAAS;AAChE,OAAK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,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EAChD,CAAC;;;;;AAUJ,SAAgB,gBACd,SACA,SAIoB;AACpB,QAAO,IAAI,mBAAmB,QAAQ,oBAAoB;EACxD,QAAQ;EACR,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACtB,CAAC"}
@@ -1,152 +0,0 @@
1
- import { type } from 'arktype';
2
- import type { ContractSourceProvider } from './contract-source-types';
3
- import type {
4
- ControlAdapterDescriptor,
5
- ControlDriverDescriptor,
6
- ControlDriverInstance,
7
- ControlExtensionDescriptor,
8
- ControlFamilyDescriptor,
9
- ControlTargetDescriptor,
10
- } from './types';
11
-
12
- /**
13
- * Type alias for CLI driver instances.
14
- * Uses string for both family and target IDs for maximum flexibility.
15
- */
16
- export type CliDriver = ControlDriverInstance<string, string>;
17
-
18
- /**
19
- * Contract configuration specifying source and artifact locations.
20
- */
21
- export interface ContractConfig {
22
- /**
23
- * Contract source provider. The provider is always async and must return
24
- * a Result containing either ContractIR or structured diagnostics.
25
- */
26
- readonly source: ContractSourceProvider;
27
- /**
28
- * Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.
29
- * The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
30
- */
31
- readonly output?: string;
32
- }
33
-
34
- /**
35
- * Configuration for Prisma Next CLI.
36
- * Uses Control*Descriptor types for type-safe wiring with compile-time compatibility checks.
37
- *
38
- * @template TFamilyId - The family ID (e.g., 'sql', 'document')
39
- * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
40
- * @template TConnection - The driver connection input type (defaults to `unknown` for config flexibility)
41
- */
42
- export interface PrismaNextConfig<
43
- TFamilyId extends string = string,
44
- TTargetId extends string = string,
45
- TConnection = unknown,
46
- > {
47
- readonly family: ControlFamilyDescriptor<TFamilyId>;
48
- readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;
49
- readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;
50
- readonly extensionPacks?: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];
51
- /**
52
- * Driver descriptor for DB-connected CLI commands.
53
- * Required for DB-connected commands (e.g., db verify).
54
- * Optional for commands that don't need database access (e.g., emit).
55
- * The driver's connection type matches the TConnection config parameter.
56
- */
57
- readonly driver?: ControlDriverDescriptor<
58
- TFamilyId,
59
- TTargetId,
60
- ControlDriverInstance<TFamilyId, TTargetId>,
61
- TConnection
62
- >;
63
- /**
64
- * Database connection configuration.
65
- * The connection type is driver-specific (e.g., URL string for Postgres).
66
- */
67
- readonly db?: {
68
- /**
69
- * Driver-specific connection input.
70
- * For Postgres: a connection string (URL).
71
- * For other drivers: may be a structured object.
72
- */
73
- readonly connection?: TConnection;
74
- };
75
- /**
76
- * Contract configuration. Specifies source and artifact locations.
77
- * Required for emit command; optional for other commands that only read artifacts.
78
- */
79
- readonly contract?: ContractConfig;
80
- }
81
-
82
- /**
83
- * Arktype schema for ContractConfig validation.
84
- * Validates presence/shape only.
85
- * contract.source is validated as a provider function at runtime in defineConfig().
86
- */
87
- const ContractConfigSchema = type({
88
- source: 'unknown', // Runtime check enforces provider function shape
89
- 'output?': 'string',
90
- });
91
-
92
- /**
93
- * Arktype schema for PrismaNextConfig validation.
94
- * Note: This validates structure only. Descriptor objects (family, target, adapter) are validated separately.
95
- */
96
- const PrismaNextConfigSchema = type({
97
- family: 'unknown', // ControlFamilyDescriptor - validated separately
98
- target: 'unknown', // ControlTargetDescriptor - validated separately
99
- adapter: 'unknown', // ControlAdapterDescriptor - validated separately
100
- 'extensionPacks?': 'unknown[]',
101
- 'driver?': 'unknown', // ControlDriverDescriptor - validated separately (optional)
102
- 'db?': 'unknown',
103
- 'contract?': ContractConfigSchema,
104
- });
105
-
106
- /**
107
- * Helper function to define a Prisma Next config.
108
- * Validates and normalizes the config using Arktype, then returns the normalized IR.
109
- *
110
- * Normalization:
111
- * - contract.output defaults to 'src/prisma/contract.json' if missing
112
- *
113
- * @param config - Raw config input from user
114
- * @returns Normalized config IR with defaults applied
115
- * @throws Error if config structure is invalid
116
- */
117
- export function defineConfig<TFamilyId extends string = string, TTargetId extends string = string>(
118
- config: PrismaNextConfig<TFamilyId, TTargetId>,
119
- ): PrismaNextConfig<TFamilyId, TTargetId> {
120
- // Validate structure using Arktype
121
- const validated = PrismaNextConfigSchema(config);
122
- if (validated instanceof type.errors) {
123
- const messages = validated.map((p: { message: string }) => p.message).join('; ');
124
- throw new Error(`Config validation failed: ${messages}`);
125
- }
126
-
127
- // Normalize contract config if present
128
- if (config.contract) {
129
- // Validate contract.source provider function shape at runtime.
130
- const source = config.contract.source;
131
- if (typeof source !== 'function') {
132
- throw new Error('Config.contract.source must be a provider function');
133
- }
134
-
135
- // Apply defaults
136
- const output = config.contract.output ?? 'src/prisma/contract.json';
137
-
138
- const normalizedContract: ContractConfig = {
139
- source: config.contract.source,
140
- output,
141
- };
142
-
143
- // Return normalized config
144
- return {
145
- ...config,
146
- contract: normalizedContract,
147
- };
148
- }
149
-
150
- // Return config as-is if no contract (preserve literal types)
151
- return config;
152
- }