@prisma-next/cli 0.4.2 → 0.4.4

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 (130) hide show
  1. package/README.md +56 -21
  2. package/dist/cli-errors-By1iVE3z.mjs +34 -0
  3. package/dist/cli-errors-By1iVE3z.mjs.map +1 -0
  4. package/dist/{cli-errors-BFYgBH3L.d.mts → cli-errors-DDeVsP2Y.d.mts} +1 -0
  5. package/dist/cli.mjs +19 -16
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/{client-CrsnY58k.mjs → client-1JqqkiC7.mjs} +45 -20
  8. package/dist/client-1JqqkiC7.mjs.map +1 -0
  9. package/dist/commands/contract-emit.d.mts.map +1 -1
  10. package/dist/commands/contract-emit.mjs +7 -7
  11. package/dist/commands/contract-infer.d.mts.map +1 -1
  12. package/dist/commands/contract-infer.mjs +8 -8
  13. package/dist/commands/db-init.d.mts.map +1 -1
  14. package/dist/commands/db-init.mjs +11 -10
  15. package/dist/commands/db-init.mjs.map +1 -1
  16. package/dist/commands/db-schema.mjs +8 -8
  17. package/dist/commands/db-sign.mjs +8 -8
  18. package/dist/commands/db-update.mjs +10 -10
  19. package/dist/commands/db-update.mjs.map +1 -1
  20. package/dist/commands/db-verify.mjs +10 -10
  21. package/dist/commands/migration-apply.d.mts +5 -2
  22. package/dist/commands/migration-apply.d.mts.map +1 -1
  23. package/dist/commands/migration-apply.mjs +56 -57
  24. package/dist/commands/migration-apply.mjs.map +1 -1
  25. package/dist/commands/migration-new.d.mts.map +1 -1
  26. package/dist/commands/migration-new.mjs +26 -32
  27. package/dist/commands/migration-new.mjs.map +1 -1
  28. package/dist/commands/migration-plan.d.mts +14 -5
  29. package/dist/commands/migration-plan.d.mts.map +1 -1
  30. package/dist/commands/migration-plan.mjs +45 -48
  31. package/dist/commands/migration-plan.mjs.map +1 -1
  32. package/dist/commands/migration-ref.d.mts +1 -1
  33. package/dist/commands/migration-ref.d.mts.map +1 -1
  34. package/dist/commands/migration-ref.mjs +6 -10
  35. package/dist/commands/migration-ref.mjs.map +1 -1
  36. package/dist/commands/migration-show.d.mts +13 -7
  37. package/dist/commands/migration-show.d.mts.map +1 -1
  38. package/dist/commands/migration-show.mjs +28 -29
  39. package/dist/commands/migration-show.mjs.map +1 -1
  40. package/dist/commands/migration-status.d.mts +23 -5
  41. package/dist/commands/migration-status.d.mts.map +1 -1
  42. package/dist/commands/migration-status.mjs +8 -8
  43. package/dist/{config-loader-C25b63rJ.mjs → config-loader-ih8ViDb_.mjs} +2 -2
  44. package/dist/config-loader-ih8ViDb_.mjs.map +1 -0
  45. package/dist/config-loader.mjs +1 -1
  46. package/dist/contract-emit-DS5NzZh2.mjs +6 -0
  47. package/dist/contract-emit-RZBWzkop.mjs +329 -0
  48. package/dist/contract-emit-RZBWzkop.mjs.map +1 -0
  49. package/dist/contract-emit-rt_Nmdwq.mjs +150 -0
  50. package/dist/contract-emit-rt_Nmdwq.mjs.map +1 -0
  51. package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-4Ptgw3Pe.mjs} +1 -1
  52. package/dist/{contract-enrichment-CAOELa-H.mjs.map → contract-enrichment-4Ptgw3Pe.mjs.map} +1 -1
  53. package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-Cf5J2wVg.mjs} +11 -19
  54. package/dist/contract-infer-Cf5J2wVg.mjs.map +1 -0
  55. package/dist/exports/control-api.d.mts +86 -21
  56. package/dist/exports/control-api.d.mts.map +1 -1
  57. package/dist/exports/control-api.mjs +7 -7
  58. package/dist/exports/index.mjs +8 -8
  59. package/dist/{framework-components-Cr--XBKy.mjs → framework-components-Bgcre3Z6.mjs} +2 -2
  60. package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-Bgcre3Z6.mjs.map} +1 -1
  61. package/dist/{init-m8x0UoPY.mjs → init-DAbQMxIR.mjs} +5 -5
  62. package/dist/{init-m8x0UoPY.mjs.map → init-DAbQMxIR.mjs.map} +1 -1
  63. package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-LWtXfxm_.mjs} +9 -9
  64. package/dist/inspect-live-schema-LWtXfxm_.mjs.map +1 -0
  65. package/dist/migration-cli.d.mts +41 -11
  66. package/dist/migration-cli.d.mts.map +1 -1
  67. package/dist/migration-cli.mjs +308 -84
  68. package/dist/migration-cli.mjs.map +1 -1
  69. package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-CU452v9h.mjs} +7 -7
  70. package/dist/{migration-command-scaffold-B3B09et6.mjs.map → migration-command-scaffold-CU452v9h.mjs.map} +1 -1
  71. package/dist/{migration-status-DUMiH8_G.mjs → migration-status-DoPrFIOQ.mjs} +114 -57
  72. package/dist/migration-status-DoPrFIOQ.mjs.map +1 -0
  73. package/dist/{migrations-Bo5WtTla.mjs → migrations-MEoKMiV5.mjs} +42 -21
  74. package/dist/migrations-MEoKMiV5.mjs.map +1 -0
  75. package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-DgRGldpT.mjs} +1 -1
  76. package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-DgRGldpT.mjs.map} +1 -1
  77. package/dist/{result-handler-Ba3zWQsI.mjs → result-handler-Ch6hVnOo.mjs} +34 -19
  78. package/dist/{result-handler-Ba3zWQsI.mjs.map → result-handler-Ch6hVnOo.mjs.map} +1 -1
  79. package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-u2YgKghu.mjs} +1 -1
  80. package/dist/{terminal-ui-C3ZLwQxK.mjs.map → terminal-ui-u2YgKghu.mjs.map} +1 -1
  81. package/dist/{verify-Bkycc-Tf.mjs → verify-BT9tgCOH.mjs} +2 -2
  82. package/dist/{verify-Bkycc-Tf.mjs.map → verify-BT9tgCOH.mjs.map} +1 -1
  83. package/package.json +18 -17
  84. package/src/cli.ts +32 -6
  85. package/src/commands/contract-emit.ts +67 -163
  86. package/src/commands/contract-infer.ts +7 -20
  87. package/src/commands/db-init.ts +1 -0
  88. package/src/commands/db-update.ts +1 -1
  89. package/src/commands/inspect-live-schema.ts +10 -5
  90. package/src/commands/migration-apply.ts +84 -63
  91. package/src/commands/migration-new.ts +28 -34
  92. package/src/commands/migration-plan.ts +80 -56
  93. package/src/commands/migration-ref.ts +8 -7
  94. package/src/commands/migration-show.ts +53 -36
  95. package/src/commands/migration-status.ts +194 -58
  96. package/src/config-path-validation.ts +0 -1
  97. package/src/control-api/client.ts +21 -0
  98. package/src/control-api/operations/contract-emit.ts +198 -115
  99. package/src/control-api/operations/db-init.ts +10 -6
  100. package/src/control-api/operations/db-update.ts +10 -6
  101. package/src/control-api/operations/migration-apply.ts +30 -9
  102. package/src/control-api/types.ts +69 -7
  103. package/src/exports/control-api.ts +2 -1
  104. package/src/migration-cli.ts +445 -122
  105. package/src/utils/cli-errors.ts +49 -2
  106. package/src/utils/command-helpers.ts +45 -23
  107. package/src/utils/emit-queue.ts +26 -0
  108. package/src/utils/formatters/graph-migration-mapper.ts +7 -3
  109. package/src/utils/formatters/migrations.ts +62 -26
  110. package/src/utils/publish-contract-artifact-pair.ts +134 -0
  111. package/dist/cli-errors-Cd79vmTH.mjs +0 -5
  112. package/dist/client-CrsnY58k.mjs.map +0 -1
  113. package/dist/config-loader-C25b63rJ.mjs.map +0 -1
  114. package/dist/contract-emit-DxgyXrqV.mjs +0 -6
  115. package/dist/contract-emit-NJ01hiiv.mjs +0 -195
  116. package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
  117. package/dist/contract-emit-V5SSitUT.mjs +0 -122
  118. package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
  119. package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
  120. package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
  121. package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
  122. package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
  123. package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
  124. package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
  125. package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
  126. package/dist/migrations-Bo5WtTla.mjs.map +0 -1
  127. package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
  128. package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
  129. package/src/control-api/operations/extract-operation-statements.ts +0 -14
  130. package/src/control-api/operations/extract-sql-ddl.ts +0 -47
@@ -1,11 +1,10 @@
1
- import { t as loadConfig } from "./config-loader-C25b63rJ.mjs";
2
- import { _ as errorUnexpected, c as errorDriverRequired, o as errorDatabaseConnectionRequired, t as CliStructuredError } from "./cli-errors-Cd79vmTH.mjs";
3
- import { t as createControlClient } from "./client-CrsnY58k.mjs";
4
- import { _ as formatStyledHeader, a as maskConnectionUrl, l as sanitizeErrorMessage } from "./result-handler-Ba3zWQsI.mjs";
5
- import { t as createProgressAdapter } from "./progress-adapter-DvQWB1nK.mjs";
1
+ import { t as loadConfig } from "./config-loader-ih8ViDb_.mjs";
2
+ import { _ as errorUnexpected, c as errorDriverRequired, o as errorDatabaseConnectionRequired, t as CliStructuredError } from "./cli-errors-By1iVE3z.mjs";
3
+ import { o as maskConnectionUrl, u as sanitizeErrorMessage, y as formatStyledHeader } from "./result-handler-Ch6hVnOo.mjs";
4
+ import { t as createProgressAdapter } from "./progress-adapter-DgRGldpT.mjs";
5
+ import { t as createControlClient } from "./client-1JqqkiC7.mjs";
6
6
  import { notOk, ok } from "@prisma-next/utils/result";
7
7
  import { relative, resolve } from "pathe";
8
- import { validatePrintableSqlSchemaIR } from "@prisma-next/psl-printer";
9
8
 
10
9
  //#region src/commands/inspect-live-schema.ts
11
10
  async function inspectLiveSchema(options, flags, ui, startTime, context) {
@@ -56,17 +55,18 @@ async function inspectLiveSchema(options, flags, ui, startTime, context) {
56
55
  flags
57
56
  });
58
57
  try {
59
- const schemaIR = await client.introspect({
58
+ const schema = await client.introspect({
60
59
  connection: dbConnection,
61
60
  onProgress
62
61
  });
63
- const schema = config.family.familyId === "sql" ? validatePrintableSqlSchemaIR(schemaIR) : schemaIR;
64
62
  const schemaView = client.toSchemaView(schema);
63
+ const pslContractAst = client.inferPslContract(schema);
65
64
  const dbUrl = typeof dbConnection === "string" ? maskConnectionUrl(dbConnection) : void 0;
66
65
  return ok({
67
66
  config,
68
67
  schema,
69
68
  schemaView,
69
+ pslContractAst,
70
70
  target: {
71
71
  familyId: config.family.familyId,
72
72
  id: config.target.targetId
@@ -88,4 +88,4 @@ async function inspectLiveSchema(options, flags, ui, startTime, context) {
88
88
 
89
89
  //#endregion
90
90
  export { inspectLiveSchema as t };
91
- //# sourceMappingURL=inspect-live-schema-yrHAvG71.mjs.map
91
+ //# sourceMappingURL=inspect-live-schema-LWtXfxm_.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect-live-schema-LWtXfxm_.mjs","names":["config: LoadedCliConfig","details: Array<{ label: string; value: string }>"],"sources":["../src/commands/inspect-live-schema.ts"],"sourcesContent":["import type { CoreSchemaView } from '@prisma-next/framework-components/control';\nimport type { PslDocumentAst } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { relative, resolve } from 'pathe';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport {\n CliStructuredError,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport { maskConnectionUrl, sanitizeErrorMessage } from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions, GlobalFlags } from '../utils/global-flags';\nimport { createProgressAdapter } from '../utils/progress-adapter';\nimport type { TerminalUI } from '../utils/terminal-ui';\n\nexport interface InspectLiveSchemaOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n}\n\ninterface InspectLiveSchemaContext {\n readonly commandName: string;\n readonly description: string;\n readonly url: string;\n}\n\ntype LoadedCliConfig = Awaited<ReturnType<typeof loadConfig>>;\n\nexport interface InspectLiveSchemaResult {\n readonly config: LoadedCliConfig;\n readonly schema: unknown;\n readonly schemaView: CoreSchemaView | undefined;\n /**\n * PSL AST inferred from the introspected schema, when the configured family\n * implements `PslContractInferCapable`. `undefined` for families that do not\n * support inference (e.g. Mongo today).\n */\n readonly pslContractAst: PslDocumentAst | undefined;\n readonly target: {\n readonly familyId: string;\n readonly id: string;\n };\n readonly meta: {\n readonly configPath?: string;\n readonly dbUrl?: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\nexport async function inspectLiveSchema(\n options: InspectLiveSchemaOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n context: InspectLiveSchemaContext,\n): Promise<Result<InspectLiveSchemaResult, CliStructuredError>> {\n let config: LoadedCliConfig;\n try {\n config = await loadConfig(options.config);\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: 'Failed to load config',\n }),\n );\n }\n\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n\n if (!flags.json && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n ];\n\n if (options.db) {\n details.push({ label: 'database', value: maskConnectionUrl(options.db) });\n } else if (config.db?.connection && typeof config.db.connection === 'string') {\n details.push({ label: 'database', value: maskConnectionUrl(config.db.connection) });\n }\n\n ui.stderr(\n formatStyledHeader({\n command: context.commandName,\n description: context.description,\n url: context.url,\n details,\n flags,\n }),\n );\n }\n\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for ${context.commandName} (set db.connection in ${configPath}, or pass --db <url>)`,\n commandName: context.commandName,\n }),\n );\n }\n\n if (!config.driver) {\n return notOk(\n errorDriverRequired({\n why: `Config.driver is required for ${context.commandName}`,\n }),\n );\n }\n\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n const onProgress = createProgressAdapter({ ui, flags });\n\n try {\n const schema = await client.introspect({\n connection: dbConnection,\n onProgress,\n });\n const schemaView = client.toSchemaView(schema);\n const pslContractAst = client.inferPslContract(schema);\n\n const dbUrl = typeof dbConnection === 'string' ? maskConnectionUrl(dbConnection) : undefined;\n\n return ok({\n config,\n schema,\n schemaView,\n pslContractAst,\n target: {\n familyId: config.family.familyId,\n id: config.target.targetId,\n },\n meta: {\n configPath,\n ...(dbUrl ? { dbUrl } : {}),\n },\n timings: {\n total: Date.now() - startTime,\n },\n });\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n const rawMessage = error instanceof Error ? error.message : String(error);\n const safeMessage = sanitizeErrorMessage(\n rawMessage,\n typeof dbConnection === 'string' ? dbConnection : undefined,\n );\n return notOk(\n errorUnexpected(safeMessage, {\n why: `Unexpected error during ${context.commandName}: ${safeMessage}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n"],"mappings":";;;;;;;;;AAsDA,eAAsB,kBACpB,SACA,OACA,IACA,WACA,SAC8D;CAC9D,IAAIA;AACJ,KAAI;AACF,WAAS,MAAM,WAAW,QAAQ,OAAO;UAClC,OAAO;AACd,MAAI,mBAAmB,GAAG,MAAM,CAC9B,QAAO,MAAM,MAAM;AAGrB,SAAO,MACL,gBAAgB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAAE,EACtE,KAAK,yBACN,CAAC,CACH;;CAGH,MAAM,aAAa,QAAQ,SACvB,SAAS,QAAQ,KAAK,EAAE,QAAQ,QAAQ,OAAO,CAAC,GAChD;AAEJ,KAAI,CAAC,MAAM,QAAQ,CAAC,MAAM,OAAO;EAC/B,MAAMC,UAAmD,CACvD;GAAE,OAAO;GAAU,OAAO;GAAY,CACvC;AAED,MAAI,QAAQ,GACV,SAAQ,KAAK;GAAE,OAAO;GAAY,OAAO,kBAAkB,QAAQ,GAAG;GAAE,CAAC;WAChE,OAAO,IAAI,cAAc,OAAO,OAAO,GAAG,eAAe,SAClE,SAAQ,KAAK;GAAE,OAAO;GAAY,OAAO,kBAAkB,OAAO,GAAG,WAAW;GAAE,CAAC;AAGrF,KAAG,OACD,mBAAmB;GACjB,SAAS,QAAQ;GACjB,aAAa,QAAQ;GACrB,KAAK,QAAQ;GACb;GACA;GACD,CAAC,CACH;;CAGH,MAAM,eAAe,QAAQ,MAAM,OAAO,IAAI;AAC9C,KAAI,CAAC,aACH,QAAO,MACL,gCAAgC;EAC9B,KAAK,uCAAuC,QAAQ,YAAY,yBAAyB,WAAW;EACpG,aAAa,QAAQ;EACtB,CAAC,CACH;AAGH,KAAI,CAAC,OAAO,OACV,QAAO,MACL,oBAAoB,EAClB,KAAK,iCAAiC,QAAQ,eAC/C,CAAC,CACH;CAGH,MAAM,SAAS,oBAAoB;EACjC,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,QAAQ,OAAO;EACf,gBAAgB,OAAO,kBAAkB,EAAE;EAC5C,CAAC;CACF,MAAM,aAAa,sBAAsB;EAAE;EAAI;EAAO,CAAC;AAEvD,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,WAAW;GACrC,YAAY;GACZ;GACD,CAAC;EACF,MAAM,aAAa,OAAO,aAAa,OAAO;EAC9C,MAAM,iBAAiB,OAAO,iBAAiB,OAAO;EAEtD,MAAM,QAAQ,OAAO,iBAAiB,WAAW,kBAAkB,aAAa,GAAG;AAEnF,SAAO,GAAG;GACR;GACA;GACA;GACA;GACA,QAAQ;IACN,UAAU,OAAO,OAAO;IACxB,IAAI,OAAO,OAAO;IACnB;GACD,MAAM;IACJ;IACA,GAAI,QAAQ,EAAE,OAAO,GAAG,EAAE;IAC3B;GACD,SAAS,EACP,OAAO,KAAK,KAAK,GAAG,WACrB;GACF,CAAC;UACK,OAAO;AACd,MAAI,mBAAmB,GAAG,MAAM,CAC9B,QAAO,MAAM,MAAM;EAIrB,MAAM,cAAc,qBADD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAGvE,OAAO,iBAAiB,WAAW,eAAe,OACnD;AACD,SAAO,MACL,gBAAgB,aAAa,EAC3B,KAAK,2BAA2B,QAAQ,YAAY,IAAI,eACzD,CAAC,CACH;WACO;AACR,QAAM,OAAO,OAAO"}
@@ -1,4 +1,5 @@
1
1
  import { Migration } from "@prisma-next/migration-tools/migration";
2
+ import { Writable } from "node:stream";
2
3
 
3
4
  //#region src/migration-cli.d.ts
4
5
 
@@ -18,6 +19,20 @@ import { Migration } from "@prisma-next/migration-tools/migration";
18
19
  * point for additional construction arguments.
19
20
  */
20
21
  type MigrationConstructor = new (...args: any[]) => Migration;
22
+ /**
23
+ * Stream surface accepted by `MigrationCLI.run`'s `options.stdout` /
24
+ * `options.stderr`. Aliases node's `Writable` because clipanion's
25
+ * `BaseContext.stdout`/`stderr` are typed as `Writable`, and the CLI
26
+ * forwards the injected streams into clipanion's context.
27
+ *
28
+ * `process.stdout` and `process.stderr` are `Writable`-shaped, so the
29
+ * default-fallback path remains a no-op for existing two-argument
30
+ * callers like `MigrationCLI.run(import.meta.url, MyMigration)`.
31
+ *
32
+ * Tests inject a `Writable` subclass that captures chunks for
33
+ * assertions.
34
+ */
35
+ type MigrationCliWritable = Writable;
21
36
  /**
22
37
  * The CLI surface invoked by an authored `migration.ts` file. Exposed as
23
38
  * a class with a static `run` method (rather than a free function) to
@@ -32,19 +47,34 @@ type MigrationConstructor = new (...args: any[]) => Migration;
32
47
  */
33
48
  declare class MigrationCLI {
34
49
  /**
35
- * Orchestrates a class-flow `migration.ts` script run. Awaitable:
36
- * callers may `await MigrationCLI.run(...)` to surface async failures
37
- * from config loading, but the typical usage pattern (top-level call
38
- * after the class definition) does not require awaiting because
39
- * node's module evaluation keeps the promise alive until completion.
50
+ * Orchestrates a class-flow `migration.ts` script run.
51
+ *
52
+ * The third argument is the in-process testability surface: callers
53
+ * (and tests) may inject `argv`, `stdout`, and `stderr` instead of
54
+ * relying on `process.argv` / `process.stdout` / `process.stderr`.
55
+ * Each option defaults to its `process` global when omitted, so
56
+ * existing two-argument call sites
57
+ * (`MigrationCLI.run(import.meta.url, MyMigration)`) continue to
58
+ * compile and behave identically.
59
+ *
60
+ * Returns the exit code so the caller can branch on it. Also writes
61
+ * the same code to `process.exitCode` so script-style callers that
62
+ * don't await the return value still surface a non-zero exit when
63
+ * something fails.
40
64
  *
41
- * Any throwable inside this function must surface through the internal
42
- * try/catchscript callers do not await, so an unhandled rejection
43
- * would silently exit 0. Treat the try/catch as load-bearing for the
44
- * no-await usage pattern.
65
+ * Exit codes:
66
+ * - 0 success, or `--help`, or imported-not-entrypoint no-op.
67
+ * - 1 runtime/orchestration error (config not found, target
68
+ * mismatch, etc.).
69
+ * - 2 — usage error (unknown flag, malformed `--config`). Aligns
70
+ * with `docs/CLI Style Guide.md` § Exit Codes.
45
71
  */
46
- static run(importMetaUrl: string, MigrationClass: MigrationConstructor): Promise<void>;
72
+ static run(importMetaUrl: string, MigrationClass: MigrationConstructor, options?: {
73
+ readonly argv?: readonly string[];
74
+ readonly stdout?: MigrationCliWritable;
75
+ readonly stderr?: MigrationCliWritable;
76
+ }): Promise<number>;
47
77
  }
48
78
  //#endregion
49
- export { MigrationCLI, MigrationConstructor };
79
+ export { MigrationCLI, MigrationCliWritable, MigrationConstructor };
50
80
  //# sourceMappingURL=migration-cli.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration-cli.d.mts","names":[],"sources":["../src/migration-cli.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;KAqEY,oBAAA,2BAA+C;;;;;;;;;;;;;cAiE9C,YAAA;;;;;;;;;;;;;oDAa6C,uBAAuB"}
1
+ {"version":3,"file":"migration-cli.d.mts","names":[],"sources":["../src/migration-cli.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;KA6EY,oBAAA,2BAA+C;;;;;;;;;;;;;;KAe/C,oBAAA,GAAuB;;;;;;;;;;;;;cAuEtB,YAAA;;;;;;;;;;;;;;;;;;;;;;;;oDA0BO;;sBAGI;sBACA;MAEnB"}
@@ -1,11 +1,13 @@
1
- import { t as loadConfig } from "./config-loader-C25b63rJ.mjs";
2
- import { readFileSync, writeFileSync } from "node:fs";
3
- import { CliStructuredError, errorMigrationCliInvalidConfigArg } from "@prisma-next/errors/control";
1
+ import { t as loadConfig } from "./config-loader-ih8ViDb_.mjs";
2
+ import { CliStructuredError, errorMigrationCliInvalidConfigArg, errorMigrationCliUnknownFlag } from "@prisma-next/errors/control";
4
3
  import { dirname, join } from "pathe";
5
4
  import { createControlStack } from "@prisma-next/framework-components/control";
6
5
  import { errorMigrationTargetMismatch } from "@prisma-next/errors/migration";
6
+ import { readFileSync, realpathSync, writeFileSync } from "node:fs";
7
+ import { MigrationToolsError, errorInvalidJson } from "@prisma-next/migration-tools/errors";
7
8
  import { fileURLToPath } from "node:url";
8
- import { buildMigrationArtifacts, isDirectEntrypoint, printMigrationHelp } from "@prisma-next/migration-tools/migration";
9
+ import { buildMigrationArtifacts } from "@prisma-next/migration-tools/migration";
10
+ import { Cli, Command, Option, UsageError } from "clipanion";
9
11
 
10
12
  //#region src/migration-cli.ts
11
13
  /**
@@ -25,7 +27,8 @@ import { buildMigrationArtifacts, isDirectEntrypoint, printMigrationHelp } from
25
27
  * entrypoint (`node migration.ts`), the CLI:
26
28
  *
27
29
  * 1. Detects whether the file is the direct entrypoint (no-op when imported).
28
- * 2. Parses CLI args (`--help`, `--dry-run`, `--config <path>`).
30
+ * 2. Parses CLI args (`--help`, `--dry-run`, `--config <path>`) via
31
+ * [clipanion](https://github.com/arcanis/clipanion).
29
32
  * 3. Loads the project's `prisma-next.config.ts` via the same `loadConfig`
30
33
  * the CLI commands use, walking up from the migration file's directory.
31
34
  * 4. Probe-instantiates the migration class without a stack so it can read
@@ -44,44 +47,62 @@ import { buildMigrationArtifacts, isDirectEntrypoint, printMigrationHelp } from
44
47
  * on-disk persistence. `@prisma-next/migration-tools` owns the pure
45
48
  * conversion from a `Migration` instance to artifact strings; `Migration`
46
49
  * stays a pure abstract class.
50
+ *
51
+ * Parser library: clipanion (chosen over Commander/citty/`node:util.parseArgs`
52
+ * for its in-process testability and runtime-agnostic execution surface; see
53
+ * `docs/architecture docs/research/commander-friction-points.md` for the
54
+ * evaluation rubric and the durable rationale that drove the choice).
47
55
  */
48
56
  /**
49
- * Parse the subset of `process.argv` that `MigrationCLI.run` cares about.
50
- * Recognised flags: `--help`, `--dry-run`, `--config <path>` /
51
- * `--config=<path>`. Unknown flags are ignored to keep the surface
52
- * forgiving for ad-hoc tooling that wraps a migration file.
53
- *
54
- * Throws `errorMigrationCliInvalidConfigArg` (`PN-CLI-4012`) when
55
- * `--config` is missing its path argument or is followed by another flag
56
- * (e.g. `--config --dry-run`); silently consuming the next flag would
57
- * either drop dry-run handling or serialize against the wrong project.
57
+ * Flags exposed by the migration-file CLI.
58
58
  *
59
- * NOTE: this hand-rolled parser is a known wart, tracked separately by
60
- * TML-2318 ("Migration CLI: replace handrolled arg parser with shared
61
- * CLI library"). Until that lands the surface is intentionally tiny.
59
+ * Must stay in sync with the `Option` declarations on
60
+ * `MigrationFileCommand` below. This list is rendered in the
61
+ * `errorMigrationCliUnknownFlag` envelope's `fix` text and `meta`,
62
+ * so order matters for user-visible output (declaration order is the
63
+ * order users see when they run `--help`).
64
+ */
65
+ const KNOWN_FLAGS = [
66
+ "--help",
67
+ "--dry-run",
68
+ "--config"
69
+ ];
70
+ /**
71
+ * The clipanion command that owns the migration-file CLI's option
72
+ * declarations. The class is internal — `MigrationCLI.run` is the
73
+ * stable public surface. Adding a flag here automatically updates
74
+ * `--help` rendering and the `KNOWN_FLAGS` list (the latter must be
75
+ * updated in tandem).
62
76
  */
63
- function parseArgs(argv) {
64
- let help = false;
65
- let dryRun = false;
66
- let configPath;
67
- for (let i = 0; i < argv.length; i++) {
68
- const arg = argv[i];
69
- if (arg === "--help" || arg === "-h") help = true;
70
- else if (arg === "--dry-run") dryRun = true;
71
- else if (arg === "--config") {
72
- const next = argv[i + 1];
73
- if (next === void 0) throw errorMigrationCliInvalidConfigArg();
74
- if (next.startsWith("-")) throw errorMigrationCliInvalidConfigArg({ nextToken: next });
75
- configPath = next;
76
- i++;
77
- } else if (arg.startsWith("--config=")) configPath = arg.slice(9);
77
+ var MigrationFileCommand = class extends Command {
78
+ static paths = [Command.Default];
79
+ static usage = Command.Usage({
80
+ description: "Self-emit ops.json and migration.json from a class-flow migration",
81
+ details: `
82
+ Loads the project's prisma-next.config.ts, assembles a ControlStack
83
+ from the configured target/adapter/extensions, and serializes the
84
+ migration's operations + metadata next to this file.
85
+ `,
86
+ examples: [
87
+ ["Self-emit ops.json + migration.json next to migration.ts", "$0"],
88
+ ["Preview without writing files", "$0 --dry-run"],
89
+ ["Use a non-default config path", "$0 --config ./custom.config.ts"]
90
+ ]
91
+ });
92
+ dryRun = Option.Boolean("--dry-run", false, { description: "Print operations to stdout without writing files" });
93
+ config = Option.String("--config", { description: "Path to prisma-next.config.ts" });
94
+ /**
95
+ * Unused: orchestration runs inside `MigrationCLI.run` so error
96
+ * routing stays under our control (clipanion's `cli.run` writes
97
+ * error output to `context.stdout`, but our contract requires
98
+ * structured errors on stderr). `cli.process` is used to parse
99
+ * argv into a populated `MigrationFileCommand` instance whose
100
+ * fields drive the orchestration directly.
101
+ */
102
+ async execute() {
103
+ return 0;
78
104
  }
79
- return {
80
- help,
81
- dryRun,
82
- configPath
83
- };
84
- }
105
+ };
85
106
  /**
86
107
  * The CLI surface invoked by an authored `migration.ts` file. Exposed as
87
108
  * a class with a static `run` method (rather than a free function) to
@@ -96,59 +117,243 @@ function parseArgs(argv) {
96
117
  */
97
118
  var MigrationCLI = class {
98
119
  /**
99
- * Orchestrates a class-flow `migration.ts` script run. Awaitable:
100
- * callers may `await MigrationCLI.run(...)` to surface async failures
101
- * from config loading, but the typical usage pattern (top-level call
102
- * after the class definition) does not require awaiting because
103
- * node's module evaluation keeps the promise alive until completion.
120
+ * Orchestrates a class-flow `migration.ts` script run.
104
121
  *
105
- * Any throwable inside this function must surface through the internal
106
- * try/catch script callers do not await, so an unhandled rejection
107
- * would silently exit 0. Treat the try/catch as load-bearing for the
108
- * no-await usage pattern.
122
+ * The third argument is the in-process testability surface: callers
123
+ * (and tests) may inject `argv`, `stdout`, and `stderr` instead of
124
+ * relying on `process.argv` / `process.stdout` / `process.stderr`.
125
+ * Each option defaults to its `process` global when omitted, so
126
+ * existing two-argument call sites
127
+ * (`MigrationCLI.run(import.meta.url, MyMigration)`) continue to
128
+ * compile and behave identically.
129
+ *
130
+ * Returns the exit code so the caller can branch on it. Also writes
131
+ * the same code to `process.exitCode` so script-style callers that
132
+ * don't await the return value still surface a non-zero exit when
133
+ * something fails.
134
+ *
135
+ * Exit codes:
136
+ * - 0 — success, or `--help`, or imported-not-entrypoint no-op.
137
+ * - 1 — runtime/orchestration error (config not found, target
138
+ * mismatch, etc.).
139
+ * - 2 — usage error (unknown flag, malformed `--config`). Aligns
140
+ * with `docs/CLI Style Guide.md` § Exit Codes.
109
141
  */
110
- static async run(importMetaUrl, MigrationClass) {
111
- if (!importMetaUrl) return;
112
- if (!isDirectEntrypoint(importMetaUrl)) return;
113
- try {
114
- const args = parseArgs(process.argv.slice(2));
115
- if (args.help) {
116
- printMigrationHelp();
117
- return;
142
+ static async run(importMetaUrl, MigrationClass, options = {}) {
143
+ if (!importMetaUrl) return 0;
144
+ const argv = options.argv ?? process.argv;
145
+ const stdout = options.stdout ?? process.stdout;
146
+ const stderr = options.stderr ?? process.stderr;
147
+ if (!isDirectEntrypoint(importMetaUrl, argv)) return 0;
148
+ const exitCode = await orchestrate(importMetaUrl, MigrationClass, {
149
+ argv,
150
+ stdout,
151
+ stderr
152
+ });
153
+ if (exitCode !== 0 || !process.exitCode) process.exitCode = exitCode;
154
+ return exitCode;
155
+ }
156
+ };
157
+ /**
158
+ * Argv-aware variant of the entrypoint guard. The shared
159
+ * `@prisma-next/migration-tools` helper of the same name reads
160
+ * `process.argv[1]` directly, which doesn't compose with the new
161
+ * in-process testability surface (tests inject `argv` without mutating
162
+ * the process global). Inlined here so the migration-file CLI's check
163
+ * follows the injected `argv[1]` consistently.
164
+ */
165
+ function isDirectEntrypoint(importMetaUrl, argv) {
166
+ const argv1 = argv[1];
167
+ if (!argv1) return false;
168
+ try {
169
+ return realpathSync(fileURLToPath(importMetaUrl)) === realpathSync(argv1);
170
+ } catch {
171
+ return false;
172
+ }
173
+ }
174
+ /**
175
+ * Argv-and-stream-driven orchestration body. Pulled out of the static
176
+ * method so the entrypoint guard / process-default plumbing stays
177
+ * separate from the parse + load + serialize steps.
178
+ */
179
+ async function orchestrate(importMetaUrl, MigrationClass, ctx) {
180
+ const cli = Cli.from([MigrationFileCommand], {
181
+ binaryName: "migration.ts",
182
+ binaryLabel: "Migration file CLI"
183
+ });
184
+ const input = ctx.argv.slice(2);
185
+ const configError = detectInvalidConfig(input);
186
+ if (configError) {
187
+ writeStructuredError(ctx.stderr, configError);
188
+ return 2;
189
+ }
190
+ let parsed;
191
+ try {
192
+ const command = cli.process({
193
+ input: [...input],
194
+ context: {
195
+ stdout: ctx.stdout,
196
+ stderr: ctx.stderr
118
197
  }
119
- const migrationDir = dirname(fileURLToPath(importMetaUrl));
120
- const config = await loadConfig(args.configPath);
121
- const probe = new MigrationClass();
122
- if (probe.targetId !== config.target.targetId) throw errorMigrationTargetMismatch({
123
- migrationTargetId: probe.targetId,
124
- configTargetId: config.target.targetId
125
- });
126
- serializeMigrationToDisk(new MigrationClass(createControlStack(config)), migrationDir, args.dryRun);
127
- } catch (err) {
128
- if (CliStructuredError.is(err)) process.stderr.write(`${err.message}: ${err.why}\n`);
129
- else process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
130
- process.exitCode = 1;
198
+ });
199
+ if (!(command instanceof MigrationFileCommand)) {
200
+ ctx.stdout.write(cli.usage(MigrationFileCommand, { detailed: true }));
201
+ return 0;
131
202
  }
203
+ parsed = command;
204
+ } catch (err) {
205
+ return renderParseError(err, input, ctx.stderr);
132
206
  }
133
- };
207
+ if (parsed.help) {
208
+ ctx.stdout.write(cli.usage(MigrationFileCommand, { detailed: true }));
209
+ return 0;
210
+ }
211
+ try {
212
+ await runMigration(importMetaUrl, MigrationClass, parsed, ctx);
213
+ return 0;
214
+ } catch (err) {
215
+ if (CliStructuredError.is(err)) writeStructuredError(ctx.stderr, err);
216
+ else if (MigrationToolsError.is(err)) {
217
+ const fix = err.fix ? `\n${err.fix}` : "";
218
+ ctx.stderr.write(`${err.code}: ${err.message}\n${err.why}${fix}\n`);
219
+ } else ctx.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
220
+ return 1;
221
+ }
222
+ }
223
+ /**
224
+ * Returns an `errorMigrationCliInvalidConfigArg` envelope when `input`
225
+ * contains a malformed `--config`:
226
+ *
227
+ * - `--config` as the last token (no value follows).
228
+ * - `--config <flag>` where `<flag>` starts with `-` (silently
229
+ * consuming the next flag would either drop the flag or serialize
230
+ * against the wrong project).
231
+ * - `--config <empty>` where the value is the empty string. Shells
232
+ * expand `--config ""` (or `--config "$UNSET_VAR"`) into a real
233
+ * empty argv token; treating that as a usage error here surfaces
234
+ * `PN-CLI-4012` instead of a less actionable loader error on an
235
+ * empty path.
236
+ * - `--config=` (the equals form with an empty value). Same shape as
237
+ * the empty-string case above; the user expressed intent to override
238
+ * the config path but the override is empty.
239
+ *
240
+ * `--config=<value>` and `--config <value>` with a non-empty value are
241
+ * both valid (and the equals form's value is allowed to start with
242
+ * `-` — the `=` makes the binding explicit).
243
+ */
244
+ function detectInvalidConfig(input) {
245
+ for (let i = 0; i < input.length; i++) {
246
+ const token = input[i];
247
+ if (token === "--config") {
248
+ const next = input[i + 1];
249
+ if (next === void 0 || next === "") return errorMigrationCliInvalidConfigArg();
250
+ if (next.startsWith("-")) return errorMigrationCliInvalidConfigArg({ nextToken: next });
251
+ continue;
252
+ }
253
+ if (token === "--config=") return errorMigrationCliInvalidConfigArg();
254
+ }
255
+ return null;
256
+ }
257
+ /**
258
+ * Translate clipanion's parse-time errors into the project's structured
259
+ * error envelopes.
260
+ *
261
+ * - `UnknownSyntaxError` covers both unknown flags (`--frobnicate`) and
262
+ * the bare-trailing `--config` case (where arity-1 needs a value but
263
+ * none was supplied). Distinguished by inspecting the input array.
264
+ * - `UsageError` covers schema/validator failures from typanion. None
265
+ * of the migration-file CLI's options have validators today, but we
266
+ * still translate it as a usage error (exit 2) for forward-compat.
267
+ * - Anything else re-throws — caller's outer catch will surface it as
268
+ * exit 1 (runtime error).
269
+ */
270
+ function renderParseError(err, input, stderr) {
271
+ if (isUnknownSyntaxError(err)) {
272
+ writeStructuredError(stderr, errorMigrationCliUnknownFlag({
273
+ flag: findOffendingFlag(input),
274
+ knownFlags: KNOWN_FLAGS
275
+ }));
276
+ return 2;
277
+ }
278
+ if (err instanceof UsageError) {
279
+ writeStructuredError(stderr, errorMigrationCliInvalidConfigArg({ nextToken: err.message }));
280
+ return 2;
281
+ }
282
+ throw err;
283
+ }
284
+ /**
285
+ * Duck-type check for clipanion's `UnknownSyntaxError`: the class is
286
+ * thrown by the parser but is not re-exported from the package's main
287
+ * entry (only `UsageError` is — see clipanion's `advanced/index.d.ts`).
288
+ * Identified by `name === 'UnknownSyntaxError'` and the
289
+ * `clipanion.type === 'none'` discriminator that clipanion's
290
+ * `ErrorWithMeta` interface guarantees.
291
+ */
292
+ function isUnknownSyntaxError(err) {
293
+ if (!(err instanceof Error) || err.name !== "UnknownSyntaxError") return false;
294
+ const meta = err.clipanion;
295
+ return typeof meta === "object" && meta !== null && meta.type === "none";
296
+ }
297
+ /**
298
+ * Best-effort: pull the first input token that doesn't match a known
299
+ * flag. Falls back to the first token when we can't pinpoint it. The
300
+ * returned name is rendered into the user-visible PN-CLI-4013 envelope
301
+ * (`Unknown flag \`<name>\``) and round-tripped via `meta.flag` so
302
+ * agent consumers can render their own "did you mean" suggestions.
303
+ */
304
+ function findOffendingFlag(input) {
305
+ for (const token of input) {
306
+ if (!token.startsWith("-")) continue;
307
+ const head = token.split("=", 1)[0] ?? token;
308
+ if (!KNOWN_FLAGS.includes(head) && head !== "-h") return head;
309
+ }
310
+ return input[0] ?? "";
311
+ }
312
+ /**
313
+ * Write a `CliStructuredError` envelope to the given stream. Format
314
+ * matches the legacy hand-rolled writer (`message: why`) so the rest of
315
+ * the project's error rendering stays consistent across surfaces. The
316
+ * full PN code (`PN-<domain>-<code>`) is included so consumers can
317
+ * grep for stable identifiers.
318
+ */
319
+ function writeStructuredError(stream, err) {
320
+ const envelope = err.toEnvelope();
321
+ const why = envelope.why ?? envelope.summary;
322
+ const fix = envelope.fix ? `\n${envelope.fix}` : "";
323
+ stream.write(`${envelope.code}: ${envelope.summary}\n${why}${fix}\n`);
324
+ }
134
325
  /**
135
326
  * Read a previously-scaffolded `migration.json` from disk, returning
136
- * `null` when the file is missing or unparseable. The CLI feeds this into
137
- * `buildMigrationArtifacts` so the pure builder can preserve fields owned
138
- * by `migration plan` (contract bookends, hints, labels, `createdAt`)
139
- * across re-emits.
327
+ * `null` when the file is missing and throwing `MIGRATION.INVALID_JSON`
328
+ * when the file is present but cannot be parsed as JSON. The CLI feeds
329
+ * this into `buildMigrationArtifacts` so the pure builder can preserve
330
+ * fields owned by `migration plan` (contract bookends, hints, labels,
331
+ * `createdAt`) across re-emits.
332
+ *
333
+ * Author-time path: this loader still does not verify the manifest hash
334
+ * or schema — that is the apply-time loader's job. Hash mismatch is the
335
+ * *expected* outcome of a re-author (the developer's source changes
336
+ * invalidate the prior hash by construction), and verification here
337
+ * would block legitimate regenerations. Syntactic JSON-parse failure,
338
+ * however, is now surfaced rather than swallowed: a malformed
339
+ * `migration.json` indicates either a hand-edit gone wrong or partial
340
+ * write, and silently rebuilding from `describe()` would discard the
341
+ * user's on-disk content (preserved bookends, hints, labels,
342
+ * `createdAt`) without any indication something was wrong on disk.
343
+ * Apply-time consumers always route through the verifying
344
+ * `readMigrationPackage` in `@prisma-next/migration-tools/io` instead.
140
345
  */
141
- function readExistingManifest(manifestPath) {
346
+ function readExistingMetadata(metadataPath) {
142
347
  let raw;
143
348
  try {
144
- raw = readFileSync(manifestPath, "utf-8");
349
+ raw = readFileSync(metadataPath, "utf-8");
145
350
  } catch {
146
351
  return null;
147
352
  }
148
353
  try {
149
354
  return JSON.parse(raw);
150
- } catch {
151
- return null;
355
+ } catch (e) {
356
+ throw errorInvalidJson(metadataPath, e instanceof Error ? e.message : String(e));
152
357
  }
153
358
  }
154
359
  /**
@@ -165,18 +370,37 @@ function readExistingManifest(manifestPath) {
165
370
  * legitimate site for combining config loading, stack assembly, and
166
371
  * filesystem persistence.
167
372
  */
168
- function serializeMigrationToDisk(instance, migrationDir, dryRun) {
169
- const manifestPath = join(migrationDir, "migration.json");
170
- const { opsJson, manifestJson } = buildMigrationArtifacts(instance, readExistingManifest(manifestPath));
373
+ function serializeMigrationToDisk(instance, migrationDir, dryRun, stdout) {
374
+ const metadataPath = join(migrationDir, "migration.json");
375
+ const { opsJson, metadataJson } = buildMigrationArtifacts(instance, readExistingMetadata(metadataPath));
171
376
  if (dryRun) {
172
- process.stdout.write(`--- migration.json ---\n${manifestJson}\n`);
173
- process.stdout.write("--- ops.json ---\n");
174
- process.stdout.write(`${opsJson}\n`);
377
+ stdout.write(`--- migration.json ---\n${metadataJson}\n`);
378
+ stdout.write("--- ops.json ---\n");
379
+ stdout.write(`${opsJson}\n`);
175
380
  return;
176
381
  }
177
382
  writeFileSync(join(migrationDir, "ops.json"), opsJson);
178
- writeFileSync(manifestPath, manifestJson);
179
- process.stdout.write(`Wrote ops.json + migration.json to ${migrationDir}\n`);
383
+ writeFileSync(metadataPath, metadataJson);
384
+ stdout.write(`Wrote ops.json + migration.json to ${migrationDir}\n`);
385
+ }
386
+ /**
387
+ * Inner orchestration: load config, probe-construct the migration,
388
+ * verify target, assemble the stack, construct with the stack, persist.
389
+ *
390
+ * Throws `CliStructuredError` for known failure modes (config not
391
+ * found, target mismatch); the outer `orchestrate` translates those to
392
+ * exit 1.
393
+ */
394
+ async function runMigration(importMetaUrl, MigrationClass, parsed, ctx) {
395
+ const migrationDir = dirname(fileURLToPath(importMetaUrl));
396
+ const config = await loadConfig(parsed.config);
397
+ const probe = new MigrationClass();
398
+ if (probe.targetId !== config.target.targetId) throw errorMigrationTargetMismatch({
399
+ migrationTargetId: probe.targetId,
400
+ configTargetId: config.target.targetId
401
+ });
402
+ serializeMigrationToDisk(new MigrationClass(createControlStack(config)), migrationDir, parsed.dryRun, ctx.stdout);
403
+ ctx.stderr;
180
404
  }
181
405
 
182
406
  //#endregion