@prisma-next/cli 0.4.0-dev.9 → 0.4.1

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 (119) hide show
  1. package/README.md +31 -18
  2. package/dist/cli-errors-CznZA5-d.mjs +5 -0
  3. package/dist/cli.mjs +8 -19
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/{client-CJxHfhze.mjs → client-DGKrciLM.mjs} +9 -8
  6. package/dist/{client-CJxHfhze.mjs.map → client-DGKrciLM.mjs.map} +1 -1
  7. package/dist/commands/contract-emit.d.mts.map +1 -1
  8. package/dist/commands/contract-emit.mjs +2 -7
  9. package/dist/commands/contract-infer.mjs +2 -8
  10. package/dist/commands/db-init.mjs +7 -8
  11. package/dist/commands/db-init.mjs.map +1 -1
  12. package/dist/commands/db-schema.mjs +5 -8
  13. package/dist/commands/db-schema.mjs.map +1 -1
  14. package/dist/commands/db-sign.mjs +7 -8
  15. package/dist/commands/db-sign.mjs.map +1 -1
  16. package/dist/commands/db-update.mjs +7 -8
  17. package/dist/commands/db-update.mjs.map +1 -1
  18. package/dist/commands/db-verify.mjs +8 -9
  19. package/dist/commands/db-verify.mjs.map +1 -1
  20. package/dist/commands/migration-apply.d.mts +1 -1
  21. package/dist/commands/migration-apply.d.mts.map +1 -1
  22. package/dist/commands/migration-apply.mjs +34 -26
  23. package/dist/commands/migration-apply.mjs.map +1 -1
  24. package/dist/commands/migration-new.d.mts.map +1 -1
  25. package/dist/commands/migration-new.mjs +48 -23
  26. package/dist/commands/migration-new.mjs.map +1 -1
  27. package/dist/commands/migration-plan.d.mts +6 -1
  28. package/dist/commands/migration-plan.d.mts.map +1 -1
  29. package/dist/commands/migration-plan.mjs +94 -71
  30. package/dist/commands/migration-plan.mjs.map +1 -1
  31. package/dist/commands/migration-ref.d.mts +1 -1
  32. package/dist/commands/migration-ref.mjs +5 -5
  33. package/dist/commands/migration-show.d.mts +2 -2
  34. package/dist/commands/migration-show.d.mts.map +1 -1
  35. package/dist/commands/migration-show.mjs +11 -16
  36. package/dist/commands/migration-show.mjs.map +1 -1
  37. package/dist/commands/migration-status.d.mts +4 -5
  38. package/dist/commands/migration-status.d.mts.map +1 -1
  39. package/dist/commands/migration-status.mjs +2 -7
  40. package/dist/config-loader-_xQZsw0i.mjs +90 -0
  41. package/dist/config-loader-_xQZsw0i.mjs.map +1 -0
  42. package/dist/config-loader.d.mts.map +1 -1
  43. package/dist/config-loader.mjs +1 -1
  44. package/dist/contract-emit-304WZtZJ.mjs +4 -0
  45. package/dist/{contract-emit-CKig_Lra.mjs → contract-emit-DgeWdonT.mjs} +25 -21
  46. package/dist/contract-emit-DgeWdonT.mjs.map +1 -0
  47. package/dist/{contract-emit-gpJNLGs7.mjs → contract-emit-mU1_B_m9.mjs} +18 -14
  48. package/dist/contract-emit-mU1_B_m9.mjs.map +1 -0
  49. package/dist/{contract-enrichment-CGW6mm-E.mjs → contract-enrichment-BV4KpbNW.mjs} +1 -1
  50. package/dist/{contract-enrichment-CGW6mm-E.mjs.map → contract-enrichment-BV4KpbNW.mjs.map} +1 -1
  51. package/dist/{contract-infer-BDJgg7Xb.mjs → contract-infer-CUbiWGX0.mjs} +4 -4
  52. package/dist/{contract-infer-BDJgg7Xb.mjs.map → contract-infer-CUbiWGX0.mjs.map} +1 -1
  53. package/dist/exports/control-api.d.mts +2 -2
  54. package/dist/exports/control-api.d.mts.map +1 -1
  55. package/dist/exports/control-api.mjs +4 -6
  56. package/dist/exports/index.mjs +2 -7
  57. package/dist/exports/index.mjs.map +1 -1
  58. package/dist/{extract-operation-statements-DZUJNmL3.mjs → extract-operation-statements-DWWFz1PK.mjs} +2 -2
  59. package/dist/{extract-operation-statements-DZUJNmL3.mjs.map → extract-operation-statements-DWWFz1PK.mjs.map} +1 -1
  60. package/dist/{extract-sql-ddl-DDMX-9mz.mjs → extract-sql-ddl-7zn_AFS8.mjs} +1 -1
  61. package/dist/{extract-sql-ddl-DDMX-9mz.mjs.map → extract-sql-ddl-7zn_AFS8.mjs.map} +1 -1
  62. package/dist/{framework-components-Bsr1GaIj.mjs → framework-components-B__p--vT.mjs} +2 -2
  63. package/dist/{framework-components-Bsr1GaIj.mjs.map → framework-components-B__p--vT.mjs.map} +1 -1
  64. package/dist/{init-DZWvhEP0.mjs → init-DRquYpPa.mjs} +3 -3
  65. package/dist/{init-DZWvhEP0.mjs.map → init-DRquYpPa.mjs.map} +1 -1
  66. package/dist/{inspect-live-schema-ChqrALmw.mjs → inspect-live-schema-wIYBTdL3.mjs} +6 -6
  67. package/dist/{inspect-live-schema-ChqrALmw.mjs.map → inspect-live-schema-wIYBTdL3.mjs.map} +1 -1
  68. package/dist/{migration-command-scaffold-B0oH_hyB.mjs → migration-command-scaffold-BC73xQSo.mjs} +7 -7
  69. package/dist/{migration-command-scaffold-B0oH_hyB.mjs.map → migration-command-scaffold-BC73xQSo.mjs.map} +1 -1
  70. package/dist/{migration-status-CPamfEPj.mjs → migration-status-CXBbScH5.mjs} +19 -35
  71. package/dist/migration-status-CXBbScH5.mjs.map +1 -0
  72. package/dist/{migrations-BIsjFjSV.mjs → migrations-DYRAjiVh.mjs} +4 -15
  73. package/dist/migrations-DYRAjiVh.mjs.map +1 -0
  74. package/dist/{progress-adapter-B-YvmcDu.mjs → progress-adapter-Bwouy73-.mjs} +1 -1
  75. package/dist/{progress-adapter-B-YvmcDu.mjs.map → progress-adapter-Bwouy73-.mjs.map} +1 -1
  76. package/dist/{result-handler-AFK4hxyX.mjs → result-handler-CGohaH1o.mjs} +22 -11
  77. package/dist/result-handler-CGohaH1o.mjs.map +1 -0
  78. package/dist/{terminal-ui-C5k88MmW.mjs → terminal-ui-BuPXVRFY.mjs} +1 -1
  79. package/dist/{terminal-ui-C5k88MmW.mjs.map → terminal-ui-BuPXVRFY.mjs.map} +1 -1
  80. package/dist/{validate-contract-deps-DBH6iTAD.mjs → validate-contract-deps-DZqv9m7H.mjs} +1 -1
  81. package/dist/{validate-contract-deps-DBH6iTAD.mjs.map → validate-contract-deps-DZqv9m7H.mjs.map} +1 -1
  82. package/dist/{verify-C56CuQc7.mjs → verify-Cm2UFuZA.mjs} +2 -2
  83. package/dist/{verify-C56CuQc7.mjs.map → verify-Cm2UFuZA.mjs.map} +1 -1
  84. package/package.json +16 -20
  85. package/src/cli.ts +1 -5
  86. package/src/commands/contract-emit.ts +9 -10
  87. package/src/commands/migration-apply.ts +34 -23
  88. package/src/commands/migration-new.ts +39 -17
  89. package/src/commands/migration-plan.ts +119 -104
  90. package/src/commands/migration-show.ts +6 -16
  91. package/src/commands/migration-status.ts +14 -34
  92. package/src/config-loader.ts +35 -29
  93. package/src/config-path-validation.ts +75 -0
  94. package/src/control-api/client.ts +2 -1
  95. package/src/control-api/operations/contract-emit.ts +24 -23
  96. package/src/control-api/types.ts +1 -1
  97. package/src/utils/command-helpers.ts +15 -19
  98. package/src/utils/formatters/graph-migration-mapper.ts +5 -14
  99. package/src/utils/formatters/help.ts +0 -1
  100. package/src/utils/formatters/migrations.ts +2 -29
  101. package/dist/cli-errors-BUuJr6py.mjs +0 -5
  102. package/dist/commands/migration-emit.d.mts +0 -38
  103. package/dist/commands/migration-emit.d.mts.map +0 -1
  104. package/dist/commands/migration-emit.mjs +0 -81
  105. package/dist/commands/migration-emit.mjs.map +0 -1
  106. package/dist/config-loader-C4VXKl8f.mjs +0 -43
  107. package/dist/config-loader-C4VXKl8f.mjs.map +0 -1
  108. package/dist/contract-emit-CKig_Lra.mjs.map +0 -1
  109. package/dist/contract-emit-CU-SYNe4.mjs +0 -6
  110. package/dist/contract-emit-gpJNLGs7.mjs.map +0 -1
  111. package/dist/migration-emit-Du4DBMqz.mjs +0 -125
  112. package/dist/migration-emit-Du4DBMqz.mjs.map +0 -1
  113. package/dist/migration-status-CPamfEPj.mjs.map +0 -1
  114. package/dist/migrations-BIsjFjSV.mjs.map +0 -1
  115. package/dist/result-handler-AFK4hxyX.mjs.map +0 -1
  116. package/src/commands/migration-emit.ts +0 -134
  117. package/src/lib/migration-emit.ts +0 -125
  118. package/src/lib/migration-strategy.ts +0 -49
  119. /package/dist/{cli-errors-Dic2eADK.d.mts → cli-errors-z37sV3eR.d.mts} +0 -0
@@ -1,5 +0,0 @@
1
- import { CliStructuredError, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing as errorContractConfigMissing$1, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorMigrationPlanningFailed, errorTargetMigrationNotSupported, errorUnexpected as errorUnexpected$1 } from "@prisma-next/errors/control";
2
- import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
3
- import { errorMigrationFileMissing } from "@prisma-next/errors/migration";
4
-
5
- export { errorTargetMismatch as _, errorContractValidationFailed as a, errorDriverRequired as c, errorMarkerMissing as d, errorMigrationFileMissing as f, errorTargetMigrationNotSupported as g, errorRuntime$1 as h, errorContractConfigMissing$1 as i, errorFileNotFound as l, errorRunnerFailed as m, ERROR_CODE_DESTRUCTIVE_CHANGES as n, errorDatabaseConnectionRequired as o, errorMigrationPlanningFailed as p, errorConfigValidation$1 as r, errorDestructiveChanges as s, CliStructuredError as t, errorHashMismatch as u, errorUnexpected$1 as v };
@@ -1,38 +0,0 @@
1
- import { Command } from "commander";
2
-
3
- //#region src/utils/global-flags.d.ts
4
-
5
- /**
6
- * Common options parsed by Commander.js for every command.
7
- * Extend this for command-specific options instead of duplicating these fields.
8
- */
9
- interface CommonCommandOptions {
10
- readonly json?: string | boolean;
11
- readonly quiet?: boolean;
12
- readonly q?: boolean;
13
- readonly verbose?: boolean;
14
- readonly v?: boolean;
15
- readonly trace?: boolean;
16
- readonly color?: boolean;
17
- readonly 'no-color'?: boolean;
18
- readonly interactive?: boolean;
19
- readonly 'no-interactive'?: boolean;
20
- readonly yes?: boolean;
21
- readonly y?: boolean;
22
- }
23
- //#endregion
24
- //#region src/commands/migration-emit.d.ts
25
- interface MigrationEmitOptions extends CommonCommandOptions {
26
- readonly dir: string;
27
- readonly config?: string;
28
- }
29
- interface MigrationEmitResult {
30
- readonly ok: boolean;
31
- readonly dir: string;
32
- readonly migrationId: string;
33
- readonly summary: string;
34
- }
35
- declare function createMigrationEmitCommand(): Command;
36
- //#endregion
37
- export { MigrationEmitOptions, MigrationEmitResult, createMigrationEmitCommand };
38
- //# sourceMappingURL=migration-emit.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration-emit.d.mts","names":[],"sources":["../../src/utils/global-flags.ts","../../src/commands/migration-emit.ts"],"sourcesContent":[],"mappings":";;;;AC8BA;AAuEA;;;UDxFiB,oBAAA;;;;;;;;;;;;;;;;UCYA,oBAAA,SAA6B;EDZ7B,SAAA,GAAA,EAAA,MAAA;;;UCiBA,mBAAA;EALA,SAAA,EAAA,EAAA,OAAA;EAKA,SAAA,GAAA,EAAA,MAAA;EAuED,SAAA,WAAA,EAAA,MAAA;;;iBAAA,0BAAA,CAAA,GAA8B"}
@@ -1,81 +0,0 @@
1
- import { t as loadConfig } from "../config-loader-C4VXKl8f.mjs";
2
- import { g as errorTargetMigrationNotSupported, h as errorRuntime, t as CliStructuredError, v as errorUnexpected } from "../cli-errors-BUuJr6py.mjs";
3
- import { t as assertFrameworkComponentsCompatible } from "../framework-components-Bsr1GaIj.mjs";
4
- import { _ as formatStyledHeader, d as setCommandExamples, m as parseGlobalFlags, n as addGlobalOptions, r as getTargetMigrations, t as handleResult, u as setCommandDescriptions } from "../result-handler-AFK4hxyX.mjs";
5
- import { t as TerminalUI } from "../terminal-ui-C5k88MmW.mjs";
6
- import { r as formatMigrationEmitCommandOutput } from "../migrations-BIsjFjSV.mjs";
7
- import { t as emitMigration } from "../migration-emit-Du4DBMqz.mjs";
8
- import { Command } from "commander";
9
- import { notOk, ok } from "@prisma-next/utils/result";
10
- import { MigrationToolsError } from "@prisma-next/migration-tools/types";
11
-
12
- //#region src/commands/migration-emit.ts
13
- async function executeMigrationEmitCommand(options, flags, ui) {
14
- const dir = options.dir;
15
- if (!flags.json && !flags.quiet) {
16
- const header = formatStyledHeader({
17
- command: "migration emit",
18
- description: "Emit ops.json from migration.ts and compute migrationId",
19
- details: [{
20
- label: "dir",
21
- value: dir
22
- }],
23
- flags
24
- });
25
- ui.stderr(header);
26
- }
27
- try {
28
- const config = await loadConfig(options.config);
29
- const migrations = getTargetMigrations(config.target);
30
- if (!migrations) throw errorTargetMigrationNotSupported({ why: `Target "${config.target.id}" does not support migrations` });
31
- const frameworkComponents = assertFrameworkComponentsCompatible(config.family.familyId, config.target.targetId, [
32
- config.target,
33
- config.adapter,
34
- ...config.extensionPacks ?? []
35
- ]);
36
- const { migrationId } = await emitMigration(dir, {
37
- targetId: config.target.targetId,
38
- migrations,
39
- frameworkComponents
40
- });
41
- return ok({
42
- ok: true,
43
- dir,
44
- migrationId,
45
- summary: `Emitted ops.json and attested migrationId: ${migrationId}`
46
- });
47
- } catch (error) {
48
- if (CliStructuredError.is(error)) return notOk(error);
49
- if (MigrationToolsError.is(error)) return notOk(errorRuntime(error.message, {
50
- why: error.why,
51
- fix: error.fix,
52
- meta: {
53
- code: error.code,
54
- ...error.details ?? {}
55
- }
56
- }));
57
- return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to emit migration: ${error instanceof Error ? error.message : String(error)}` }));
58
- }
59
- }
60
- function createMigrationEmitCommand() {
61
- const command = new Command("emit");
62
- setCommandDescriptions(command, "Emit ops.json from migration.ts and compute migrationId", "Evaluates migration.ts in the package directory, resolves it to ops.json,\nthen computes and persists the content-addressed migrationId in migration.json.\nIf the file contains unfilled placeholder() slots, emit fails with PN-MIG-2001\nand reports the slot to fill in.");
63
- setCommandExamples(command, ["prisma-next migration emit --dir migrations/20250101-add-users"]);
64
- addGlobalOptions(command).requiredOption("--dir <path>", "Path to the migration package directory").option("--config <path>", "Path to prisma-next.config.ts").action(async (options) => {
65
- const flags = parseGlobalFlags(options);
66
- const ui = new TerminalUI({
67
- color: flags.color,
68
- interactive: flags.interactive
69
- });
70
- const exitCode = handleResult(await executeMigrationEmitCommand(options, flags, ui), flags, ui, (emitResult) => {
71
- if (flags.json) ui.output(JSON.stringify(emitResult, null, 2));
72
- else if (!flags.quiet) ui.log(formatMigrationEmitCommandOutput(emitResult, flags));
73
- });
74
- process.exit(exitCode);
75
- });
76
- return command;
77
- }
78
-
79
- //#endregion
80
- export { createMigrationEmitCommand };
81
- //# sourceMappingURL=migration-emit.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration-emit.mjs","names":[],"sources":["../../src/commands/migration-emit.ts"],"sourcesContent":["import { MigrationToolsError } from '@prisma-next/migration-tools/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { emitMigration } from '../lib/migration-emit';\nimport {\n CliStructuredError,\n errorRuntime,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n getTargetMigrations,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport { formatMigrationEmitCommandOutput } from '../utils/formatters/migrations';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport { assertFrameworkComponentsCompatible } from '../utils/framework-components';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\nexport interface MigrationEmitOptions extends CommonCommandOptions {\n readonly dir: string;\n readonly config?: string;\n}\n\nexport interface MigrationEmitResult {\n readonly ok: boolean;\n readonly dir: string;\n readonly migrationId: string;\n readonly summary: string;\n}\n\nasync function executeMigrationEmitCommand(\n options: MigrationEmitOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationEmitResult, CliStructuredError>> {\n const dir = options.dir;\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration emit',\n description: 'Emit ops.json from migration.ts and compute migrationId',\n details: [{ label: 'dir', value: dir }],\n flags,\n });\n ui.stderr(header);\n }\n\n try {\n const config = await loadConfig(options.config);\n const migrations = getTargetMigrations(config.target);\n if (!migrations) {\n throw errorTargetMigrationNotSupported({\n why: `Target \"${config.target.id}\" does not support migrations`,\n });\n }\n const frameworkComponents = assertFrameworkComponentsCompatible(\n config.family.familyId,\n config.target.targetId,\n [config.target, config.adapter, ...(config.extensionPacks ?? [])],\n );\n\n const { migrationId } = await emitMigration(dir, {\n targetId: config.target.targetId,\n migrations,\n frameworkComponents,\n });\n\n return ok({\n ok: true,\n dir,\n migrationId,\n summary: `Emitted ops.json and attested migrationId: ${migrationId}`,\n });\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n if (MigrationToolsError.is(error)) {\n return notOk(\n errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code, ...(error.details ?? {}) },\n }),\n );\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to emit migration: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n}\n\nexport function createMigrationEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Emit ops.json from migration.ts and compute migrationId',\n 'Evaluates migration.ts in the package directory, resolves it to ops.json,\\n' +\n 'then computes and persists the content-addressed migrationId in migration.json.\\n' +\n 'If the file contains unfilled placeholder() slots, emit fails with PN-MIG-2001\\n' +\n 'and reports the slot to fill in.',\n );\n setCommandExamples(command, ['prisma-next migration emit --dir migrations/20250101-add-users']);\n addGlobalOptions(command)\n .requiredOption('--dir <path>', 'Path to the migration package directory')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: MigrationEmitOptions) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n\n const result = await executeMigrationEmitCommand(options, flags, ui);\n\n const exitCode = handleResult(result, flags, ui, (emitResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(emitResult, null, 2));\n } else if (!flags.quiet) {\n ui.log(formatMigrationEmitCommandOutput(emitResult, flags));\n }\n });\n\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;AAqCA,eAAe,4BACb,SACA,OACA,IAC0D;CAC1D,MAAM,MAAM,QAAQ;AAEpB,KAAI,CAAC,MAAM,QAAQ,CAAC,MAAM,OAAO;EAC/B,MAAM,SAAS,mBAAmB;GAChC,SAAS;GACT,aAAa;GACb,SAAS,CAAC;IAAE,OAAO;IAAO,OAAO;IAAK,CAAC;GACvC;GACD,CAAC;AACF,KAAG,OAAO,OAAO;;AAGnB,KAAI;EACF,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO;EAC/C,MAAM,aAAa,oBAAoB,OAAO,OAAO;AACrD,MAAI,CAAC,WACH,OAAM,iCAAiC,EACrC,KAAK,WAAW,OAAO,OAAO,GAAG,gCAClC,CAAC;EAEJ,MAAM,sBAAsB,oCAC1B,OAAO,OAAO,UACd,OAAO,OAAO,UACd;GAAC,OAAO;GAAQ,OAAO;GAAS,GAAI,OAAO,kBAAkB,EAAE;GAAE,CAClE;EAED,MAAM,EAAE,gBAAgB,MAAM,cAAc,KAAK;GAC/C,UAAU,OAAO,OAAO;GACxB;GACA;GACD,CAAC;AAEF,SAAO,GAAG;GACR,IAAI;GACJ;GACA;GACA,SAAS,8CAA8C;GACxD,CAAC;UACK,OAAO;AACd,MAAI,mBAAmB,GAAG,MAAM,CAC9B,QAAO,MAAM,MAAM;AAErB,MAAI,oBAAoB,GAAG,MAAM,CAC/B,QAAO,MACL,aAAa,MAAM,SAAS;GAC1B,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAM;IAAE,MAAM,MAAM;IAAM,GAAI,MAAM,WAAW,EAAE;IAAG;GACrD,CAAC,CACH;AAEH,SAAO,MACL,gBAAgB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAAE,EACtE,KAAK,6BAA6B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,IACzF,CAAC,CACH;;;AAIL,SAAgB,6BAAsC;CACpD,MAAM,UAAU,IAAI,QAAQ,OAAO;AACnC,wBACE,SACA,2DACA,+QAID;AACD,oBAAmB,SAAS,CAAC,iEAAiE,CAAC;AAC/F,kBAAiB,QAAQ,CACtB,eAAe,gBAAgB,0CAA0C,CACzE,OAAO,mBAAmB,gCAAgC,CAC1D,OAAO,OAAO,YAAkC;EAC/C,MAAM,QAAQ,iBAAiB,QAAQ;EACvC,MAAM,KAAK,IAAI,WAAW;GAAE,OAAO,MAAM;GAAO,aAAa,MAAM;GAAa,CAAC;EAIjF,MAAM,WAAW,aAFF,MAAM,4BAA4B,SAAS,OAAO,GAAG,EAE9B,OAAO,KAAK,eAAe;AAC/D,OAAI,MAAM,KACR,IAAG,OAAO,KAAK,UAAU,YAAY,MAAM,EAAE,CAAC;YACrC,CAAC,MAAM,MAChB,IAAG,IAAI,iCAAiC,YAAY,MAAM,CAAC;IAE7D;AAEF,UAAQ,KAAK,SAAS;GACtB;AAEJ,QAAO"}
@@ -1,43 +0,0 @@
1
- import { errorConfigFileNotFound, errorConfigValidation, errorUnexpected } from "@prisma-next/errors/control";
2
- import { dirname, resolve } from "node:path";
3
- import { ConfigValidationError, validateConfig } from "@prisma-next/config/config-validation";
4
- import { loadConfig } from "c12";
5
-
6
- //#region src/config-loader.ts
7
- /**
8
- * Loads the Prisma Next config from a TypeScript file.
9
- * Supports both default export and named export.
10
- * Uses c12 to automatically handle TypeScript compilation and config file discovery.
11
- *
12
- * @param configPath - Optional path to config file. Defaults to `./prisma-next.config.ts` in current directory.
13
- * @returns The loaded config object.
14
- * @throws Error if config file doesn't exist or is invalid.
15
- */
16
- async function loadConfig$1(configPath) {
17
- try {
18
- const cwd = process.cwd();
19
- const resolvedConfigPath = configPath ? resolve(cwd, configPath) : void 0;
20
- const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;
21
- const result = await loadConfig({
22
- name: "prisma-next",
23
- ...resolvedConfigPath ? { configFile: resolvedConfigPath } : {},
24
- cwd: configCwd
25
- });
26
- if (resolvedConfigPath && result.configFile !== resolvedConfigPath) throw errorConfigFileNotFound(resolvedConfigPath);
27
- if (!result.config || Object.keys(result.config).length === 0) throw errorConfigFileNotFound(result.configFile || resolvedConfigPath || configPath);
28
- validateConfig(result.config);
29
- return result.config;
30
- } catch (error) {
31
- if (error instanceof ConfigValidationError) throw errorConfigValidation(error.field, { why: error.why });
32
- if (error instanceof Error && "code" in error && typeof error.code === "string") throw error;
33
- if (error instanceof Error) {
34
- if (error.message.includes("not found") || error.message.includes("Cannot find") || error.message.includes("ENOENT")) throw errorConfigFileNotFound(configPath ? resolve(process.cwd(), configPath) : void 0, { why: error.message });
35
- throw errorUnexpected(error.message, { why: `Failed to load config: ${error.message}` });
36
- }
37
- throw errorUnexpected(String(error));
38
- }
39
- }
40
-
41
- //#endregion
42
- export { loadConfig$1 as t };
43
- //# sourceMappingURL=config-loader-C4VXKl8f.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-loader-C4VXKl8f.mjs","names":["loadConfig","loadConfigC12"],"sources":["../src/config-loader.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { ConfigValidationError, validateConfig } from '@prisma-next/config/config-validation';\nimport {\n errorConfigFileNotFound,\n errorConfigValidation,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { loadConfig as loadConfigC12 } from 'c12';\n\n/**\n * Loads the Prisma Next config from a TypeScript file.\n * Supports both default export and named export.\n * Uses c12 to automatically handle TypeScript compilation and config file discovery.\n *\n * @param configPath - Optional path to config file. Defaults to `./prisma-next.config.ts` in current directory.\n * @returns The loaded config object.\n * @throws Error if config file doesn't exist or is invalid.\n */\nexport async function loadConfig(configPath?: string): Promise<PrismaNextConfig> {\n try {\n const cwd = process.cwd();\n // Resolve config path to absolute path and set cwd to config directory when path is provided\n const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined;\n const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;\n\n const result = await loadConfigC12<PrismaNextConfig>({\n name: 'prisma-next',\n ...(resolvedConfigPath ? { configFile: resolvedConfigPath } : {}),\n cwd: configCwd,\n });\n\n // When a specific config file was requested, verify it was actually loaded\n // (c12 falls back to searching by name if the specified file doesn't exist)\n if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {\n throw errorConfigFileNotFound(resolvedConfigPath);\n }\n\n // Check if config is missing or empty (c12 may return empty object when file doesn't exist)\n if (!result.config || Object.keys(result.config).length === 0) {\n // Use c12's configFile if available, otherwise use explicit configPath, otherwise omit path\n const displayPath = result.configFile || resolvedConfigPath || configPath;\n throw errorConfigFileNotFound(displayPath);\n }\n\n // Validate config structure\n validateConfig(result.config);\n\n return result.config;\n } catch (error) {\n if (error instanceof ConfigValidationError) {\n throw errorConfigValidation(error.field, {\n why: error.why,\n });\n }\n\n // Re-throw structured errors as-is\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code: string }).code === 'string'\n ) {\n throw error;\n }\n\n if (error instanceof Error) {\n // Check for file not found errors\n if (\n error.message.includes('not found') ||\n error.message.includes('Cannot find') ||\n error.message.includes('ENOENT')\n ) {\n // Use resolved path if available, otherwise use original configPath\n const displayPath = configPath ? resolve(process.cwd(), configPath) : undefined;\n throw errorConfigFileNotFound(displayPath, {\n why: error.message,\n });\n }\n // For other errors, wrap in unexpected error\n throw errorUnexpected(error.message, {\n why: `Failed to load config: ${error.message}`,\n });\n }\n throw errorUnexpected(String(error));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,eAAsBA,aAAW,YAAgD;AAC/E,KAAI;EACF,MAAM,MAAM,QAAQ,KAAK;EAEzB,MAAM,qBAAqB,aAAa,QAAQ,KAAK,WAAW,GAAG;EACnE,MAAM,YAAY,qBAAqB,QAAQ,mBAAmB,GAAG;EAErE,MAAM,SAAS,MAAMC,WAAgC;GACnD,MAAM;GACN,GAAI,qBAAqB,EAAE,YAAY,oBAAoB,GAAG,EAAE;GAChE,KAAK;GACN,CAAC;AAIF,MAAI,sBAAsB,OAAO,eAAe,mBAC9C,OAAM,wBAAwB,mBAAmB;AAInD,MAAI,CAAC,OAAO,UAAU,OAAO,KAAK,OAAO,OAAO,CAAC,WAAW,EAG1D,OAAM,wBADc,OAAO,cAAc,sBAAsB,WACrB;AAI5C,iBAAe,OAAO,OAAO;AAE7B,SAAO,OAAO;UACP,OAAO;AACd,MAAI,iBAAiB,sBACnB,OAAM,sBAAsB,MAAM,OAAO,EACvC,KAAK,MAAM,KACZ,CAAC;AAIJ,MACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA2B,SAAS,SAE5C,OAAM;AAGR,MAAI,iBAAiB,OAAO;AAE1B,OACE,MAAM,QAAQ,SAAS,YAAY,IACnC,MAAM,QAAQ,SAAS,cAAc,IACrC,MAAM,QAAQ,SAAS,SAAS,CAIhC,OAAM,wBADc,aAAa,QAAQ,QAAQ,KAAK,EAAE,WAAW,GAAG,QAC3B,EACzC,KAAK,MAAM,SACZ,CAAC;AAGJ,SAAM,gBAAgB,MAAM,SAAS,EACnC,KAAK,0BAA0B,MAAM,WACtC,CAAC;;AAEJ,QAAM,gBAAgB,OAAO,MAAM,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-emit-CKig_Lra.mjs","names":["providerResult: Awaited<ReturnType<typeof contractConfig.source>>"],"sources":["../src/control-api/operations/contract-emit.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { emit } from '@prisma-next/emitter';\nimport { createControlStack } from '@prisma-next/framework-components/control';\nimport { abortable } from '@prisma-next/utils/abortable';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { dirname, isAbsolute, join, resolve } from 'pathe';\nimport { loadConfig } from '../../config-loader';\nimport { errorContractConfigMissing, errorRuntime } from '../../utils/cli-errors';\nimport { assertFrameworkComponentsCompatible } from '../../utils/framework-components';\nimport { enrichContract } from '../contract-enrichment';\nimport type { ContractEmitOptions, ContractEmitResult } from '../types';\n\ninterface ProviderFailureLike {\n readonly summary: string;\n readonly diagnostics: readonly unknown[];\n readonly meta?: unknown;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction isAbortError(error: unknown): boolean {\n return isRecord(error) && typeof error['name'] === 'string' && error['name'] === 'AbortError';\n}\n\nfunction isProviderFailureLike(value: unknown): value is ProviderFailureLike {\n return (\n isRecord(value) && typeof value['summary'] === 'string' && Array.isArray(value['diagnostics'])\n );\n}\n\n/**\n * Executes the contract emit operation.\n *\n * This is an offline operation that:\n * 1. Loads the Prisma Next config from the specified path\n * 2. Resolves the contract source from config\n * 3. Creates a control plane stack and family instance\n * 4. Emits contract artifacts (JSON and DTS)\n * 5. Writes files to the paths specified in config\n *\n * Supports AbortSignal for cancellation, enabling \"last change wins\" behavior.\n *\n * @param options - Options including configPath and optional signal\n * @returns File paths and hashes of emitted artifacts\n * @throws If config loading fails, contract is invalid, or file I/O fails\n * @throws signal.reason if cancelled via AbortSignal (typically DOMException with name 'AbortError')\n */\nexport async function executeContractEmit(\n options: ContractEmitOptions,\n): Promise<ContractEmitResult> {\n const { configPath, signal = new AbortController().signal } = options;\n const unlessAborted = abortable(signal);\n\n // Load config using the existing config loader\n const config = await unlessAborted(loadConfig(configPath));\n\n // Validate contract config is present\n if (!config.contract) {\n throw errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ... }',\n });\n }\n\n const contractConfig = config.contract;\n\n // Validate output path is present and ends with .json\n if (!contractConfig.output) {\n throw errorContractConfigMissing({\n why: 'Contract config must have output path. This should not happen if defineConfig() was used.',\n });\n }\n if (!contractConfig.output.endsWith('.json')) {\n throw errorContractConfigMissing({\n why: 'Contract config output path must end with .json (e.g., \"src/prisma/contract.json\")',\n });\n }\n\n // Validate source exists and is callable\n if (typeof contractConfig.source !== 'function') {\n throw errorContractConfigMissing({\n why: 'Contract config must include a valid source provider function',\n });\n }\n\n // Normalize configPath and resolve artifact paths relative to config file directory\n const normalizedConfigPath = resolve(configPath);\n const configDir = dirname(normalizedConfigPath);\n const outputJsonPath = isAbsolute(contractConfig.output)\n ? contractConfig.output\n : join(configDir, contractConfig.output);\n // Colocate .d.ts with .json (contract.json → contract.d.ts)\n const outputDtsPath = `${outputJsonPath.slice(0, -5)}.d.ts`;\n\n const stack = createControlStack(config);\n\n const sourceContext = {\n composedExtensionPacks: stack.extensionPacks.map((p) => p.id),\n scalarTypeDescriptors: stack.scalarTypeDescriptors,\n authoringContributions: stack.authoringContributions,\n codecLookup: stack.codecLookup,\n controlMutationDefaults: stack.controlMutationDefaults,\n };\n\n let providerResult: Awaited<ReturnType<typeof contractConfig.source>>;\n try {\n providerResult = await unlessAborted(contractConfig.source(sourceContext));\n } catch (error) {\n if (signal.aborted || isAbortError(error)) {\n throw error;\n }\n throw errorRuntime('Failed to resolve contract source', {\n why: error instanceof Error ? error.message : String(error),\n fix: 'Ensure contract.source resolves to ok(Contract) or returns structured diagnostics.',\n });\n }\n\n if (!isRecord(providerResult) || typeof providerResult.ok !== 'boolean') {\n throw errorRuntime('Failed to resolve contract source', {\n why: 'Contract source provider returned malformed result shape.',\n fix: 'Ensure contract.source resolves to ok(Contract) or notOk({ summary, diagnostics }).',\n });\n }\n\n if (providerResult.ok && !('value' in providerResult)) {\n throw errorRuntime('Failed to resolve contract source', {\n why: 'Contract source provider returned malformed success result: missing value.',\n fix: 'Ensure contract.source success payload is ok(Contract).',\n });\n }\n\n if (!providerResult.ok && !isProviderFailureLike(providerResult.failure)) {\n throw errorRuntime('Failed to resolve contract source', {\n why: 'Contract source provider returned malformed failure result: expected summary and diagnostics.',\n fix: 'Ensure contract.source failure payload is notOk({ summary, diagnostics, meta? }).',\n });\n }\n\n if (!providerResult.ok) {\n throw errorRuntime('Failed to resolve contract source', {\n why: providerResult.failure.summary,\n fix: 'Fix contract source diagnostics and return ok(Contract).',\n meta: {\n diagnostics: providerResult.failure.diagnostics,\n ...ifDefined('providerMeta', providerResult.failure.meta),\n },\n });\n }\n\n const familyInstance = config.family.create(stack);\n\n const rawComponents = [config.target, config.adapter, ...(config.extensionPacks ?? [])];\n const frameworkComponents = assertFrameworkComponentsCompatible(\n config.family.familyId,\n config.target.targetId,\n rawComponents,\n );\n const enrichedIR = enrichContract(providerResult.value as Contract, frameworkComponents);\n\n familyInstance.validateContract(enrichedIR);\n const emitResult = await unlessAborted(emit(enrichedIR, stack, config.family.emission));\n\n // Create directory if needed and write files (both colocated)\n await unlessAborted(mkdir(dirname(outputJsonPath), { recursive: true }));\n await unlessAborted(writeFile(outputJsonPath, emitResult.contractJson, 'utf-8'));\n await unlessAborted(writeFile(outputDtsPath, emitResult.contractDts, 'utf-8'));\n\n // Validate that contract.d.ts type imports are resolvable\n const { validateContractDeps } = await import('../../utils/validate-contract-deps');\n const depsValidation = validateContractDeps(emitResult.contractDts, dirname(outputDtsPath));\n if (depsValidation.warning) {\n process.stderr.write(`\\n⚠ ${depsValidation.warning}\\n`);\n }\n\n return {\n storageHash: emitResult.storageHash,\n ...ifDefined('executionHash', emitResult.executionHash),\n profileHash: emitResult.profileHash,\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,aAAa,OAAyB;AAC7C,QAAO,SAAS,MAAM,IAAI,OAAO,MAAM,YAAY,YAAY,MAAM,YAAY;;AAGnF,SAAS,sBAAsB,OAA8C;AAC3E,QACE,SAAS,MAAM,IAAI,OAAO,MAAM,eAAe,YAAY,MAAM,QAAQ,MAAM,eAAe;;;;;;;;;;;;;;;;;;;AAqBlG,eAAsB,oBACpB,SAC6B;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1
- import "./config-loader-C4VXKl8f.mjs";
2
- import "./cli-errors-BUuJr6py.mjs";
3
- import "./framework-components-Bsr1GaIj.mjs";
4
- import { t as executeContractEmit } from "./contract-emit-CKig_Lra.mjs";
5
-
6
- export { executeContractEmit };
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-emit-gpJNLGs7.mjs","names":["lines: string[]","exhaustive: never","config: Awaited<ReturnType<typeof loadConfig>>","errorUnexpected"],"sources":["../src/utils/formatters/emit.ts","../src/commands/contract-emit.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { relative } from 'pathe';\n\nimport type { GlobalFlags } from '../global-flags';\nimport { isVerbose } from './helpers';\n\n// EmitContractResult type for CLI output formatting (includes file paths)\nexport interface EmitContractResult {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n readonly outDir: string;\n readonly files: {\n readonly json: string;\n readonly dts: string;\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\n/**\n * Formats human-readable output for contract emit.\n */\nexport function formatEmitOutput(result: EmitContractResult, flags: GlobalFlags): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n // Convert absolute paths to relative paths from cwd\n const jsonPath = relative(process.cwd(), result.files.json);\n const dtsPath = relative(process.cwd(), result.files.dts);\n\n lines.push(`✔ Emitted contract.json → ${jsonPath}`);\n lines.push(`✔ Emitted contract.d.ts → ${dtsPath}`);\n lines.push(` storageHash: ${result.storageHash}`);\n if (result.executionHash) {\n lines.push(` executionHash: ${result.executionHash}`);\n }\n if (result.profileHash) {\n lines.push(` profileHash: ${result.profileHash}`);\n }\n if (isVerbose(flags, 1)) {\n lines.push(` Total time: ${result.timings.total}ms`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for contract emit.\n */\nexport function formatEmitJson(result: EmitContractResult): string {\n const output = {\n ok: true,\n storageHash: result.storageHash,\n ...ifDefined('executionHash', result.executionHash),\n ...(result.profileHash ? { profileHash: result.profileHash } : {}),\n outDir: result.outDir,\n files: result.files,\n timings: result.timings,\n };\n\n return JSON.stringify(output, null, 2);\n}\n","import { mkdirSync, writeFileSync } from 'node:fs';\nimport { errorContractConfigMissing } from '@prisma-next/errors/control';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { dirname, isAbsolute, join, relative, resolve } from 'pathe';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport type { EmitFailure } from '../control-api/types';\nimport {\n CliStructuredError,\n errorContractValidationFailed,\n errorRuntime,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport {\n type EmitContractResult,\n formatEmitJson,\n formatEmitOutput,\n} from '../utils/formatters/emit';\nimport { formatStyledHeader, formatSuccessMessage } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport { createProgressAdapter } from '../utils/progress-adapter';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ninterface ContractEmitOptions extends CommonCommandOptions {\n readonly config?: string;\n}\n\nfunction mapDiagnosticsToIssues(\n failure: EmitFailure,\n): ReadonlyArray<{ kind: string; message: string }> {\n const diagnostics = failure.diagnostics?.diagnostics ?? [];\n return diagnostics.map((diagnostic) => {\n const location =\n diagnostic.sourceId && diagnostic.span\n ? ` (${diagnostic.sourceId}:${diagnostic.span.start.line}:${diagnostic.span.start.column})`\n : diagnostic.sourceId\n ? ` (${diagnostic.sourceId})`\n : '';\n return {\n kind: diagnostic.code,\n message: `${diagnostic.message}${location}`,\n };\n });\n}\n\n/**\n * Maps an EmitFailure to a CliStructuredError for consistent error handling.\n */\nfunction mapEmitFailure(\n failure: EmitFailure,\n context?: { readonly configPath?: string },\n): CliStructuredError {\n if (failure.code === 'CONTRACT_SOURCE_INVALID') {\n const issues = mapDiagnosticsToIssues(failure);\n return errorRuntime(failure.summary, {\n why: failure.why ?? 'Contract source provider failed',\n fix: 'Check your contract source provider in prisma-next.config.ts and ensure it returns Result<Contract, Diagnostics>',\n ...(issues.length > 0 ? { meta: { issues } } : {}),\n });\n }\n\n if (failure.code === 'CONTRACT_VALIDATION_FAILED') {\n return errorContractValidationFailed(\n failure.why ?? 'Contract validation failed while emitting',\n context?.configPath ? { where: { path: context.configPath } } : undefined,\n );\n }\n\n if (failure.code === 'EMIT_FAILED') {\n return errorRuntime(failure.summary, {\n why: failure.why ?? 'Failed to emit contract',\n fix: 'Check your contract configuration and ensure the source is valid',\n });\n }\n\n // Exhaustive check - TypeScript will error if a new code is added but not handled\n const exhaustive: never = failure.code;\n throw new Error(`Unhandled EmitFailure code: ${exhaustive}`);\n}\n\n/**\n * Executes the contract emit command and returns a structured Result.\n */\nasync function executeContractEmitCommand(\n options: ContractEmitOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<EmitContractResult, CliStructuredError>> {\n // Load config\n let config: Awaited<ReturnType<typeof loadConfig>>;\n try {\n config = await loadConfig(options.config);\n } catch (error) {\n // Convert thrown CliStructuredError to Result\n if (error instanceof CliStructuredError) {\n return notOk(error);\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 // Resolve contract from config\n if (!config.contract) {\n return notOk(\n errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ... }',\n }),\n );\n }\n\n // Contract config is already normalized by defineConfig() with defaults applied\n const contractConfig = config.contract;\n\n // Resolve artifact paths from config (already normalized by defineConfig() with defaults)\n if (!contractConfig.output) {\n return notOk(\n errorContractConfigMissing({\n why: 'Contract config must have output path. This should not happen if defineConfig() was used.',\n }),\n );\n }\n if (!contractConfig.output.endsWith('.json')) {\n return notOk(\n errorContractConfigMissing({\n why: 'Contract config output path must end with .json (e.g., \"src/prisma/contract.json\")',\n }),\n );\n }\n const configDir = options.config ? dirname(resolve(options.config)) : process.cwd();\n const outputJsonPath = isAbsolute(contractConfig.output)\n ? contractConfig.output\n : join(configDir, contractConfig.output);\n // Colocate .d.ts with .json (contract.json → contract.d.ts)\n const outputDtsPath = `${outputJsonPath.slice(0, -5)}.d.ts`;\n\n // Output header to stderr (decoration)\n if (!flags.json && !flags.quiet) {\n const contractPath = relative(process.cwd(), outputJsonPath);\n const typesPath = relative(process.cwd(), outputDtsPath);\n const header = formatStyledHeader({\n command: 'contract emit',\n description: 'Emit your contract artifacts',\n url: 'https://pris.ly/contract-emit',\n details: [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'types', value: typesPath },\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n // Create control client (no driver needed for emit)\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n // Create progress adapter\n const onProgress = createProgressAdapter({ ui, flags });\n\n try {\n // Call emit with progress callback\n const result = await client.emit({\n contractConfig: {\n sourceProvider: contractConfig.source,\n output: outputJsonPath,\n },\n onProgress,\n });\n\n // Handle failures by mapping to CLI structured error\n if (!result.ok) {\n return notOk(mapEmitFailure(result.failure, { configPath }));\n }\n\n // Create directories if needed\n mkdirSync(dirname(outputJsonPath), { recursive: true });\n mkdirSync(dirname(outputDtsPath), { recursive: true });\n\n // Write the results to files\n writeFileSync(outputJsonPath, result.value.contractJson, 'utf-8');\n writeFileSync(outputDtsPath, result.value.contractDts, 'utf-8');\n\n // Validate that contract.d.ts type imports are resolvable\n const { validateContractDeps } = await import('../utils/validate-contract-deps');\n const depsValidation = validateContractDeps(result.value.contractDts, dirname(outputDtsPath));\n if (depsValidation.warning) {\n ui.warn(depsValidation.warning);\n }\n\n // Convert success result to CLI output format\n const emitResult: EmitContractResult = {\n storageHash: result.value.storageHash,\n ...(result.value.executionHash ? { executionHash: result.value.executionHash } : {}),\n profileHash: result.value.profileHash,\n outDir: dirname(outputJsonPath),\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n timings: { total: Date.now() - startTime },\n };\n\n return ok(emitResult);\n } catch (error) {\n // Use static type guard to work across module boundaries\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n // Wrap unexpected errors\n return notOk(\n errorUnexpected('Unexpected error during contract emit', {\n why: error instanceof Error ? error.message : String(error),\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createContractEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Emit your contract artifacts',\n 'Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\\n' +\n 'contract.d.ts. The contract.json contains the canonical contract structure, and\\n' +\n 'contract.d.ts provides TypeScript types for type-safe query building.',\n );\n setCommandExamples(command, [\n 'prisma-next contract emit',\n 'prisma-next contract emit --config ./custom-config.ts',\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: ContractEmitOptions) => {\n const flags = parseGlobalFlags(options);\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n const startTime = Date.now();\n\n const result = await executeContractEmitCommand(options, flags, ui, startTime);\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, ui, (emitResult) => {\n if (flags.json) {\n ui.output(formatEmitJson(emitResult));\n } else {\n const output = formatEmitOutput(emitResult, flags);\n if (output) {\n ui.log(output);\n }\n if (!flags.quiet) {\n ui.success(formatSuccessMessage(flags));\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAiB,QAA4B,OAA4B;AACvF,KAAI,MAAM,MACR,QAAO;CAGT,MAAMA,QAAkB,EAAE;CAG1B,MAAM,WAAW,SAAS,QAAQ,KAAK,EAAE,OAAO,MAAM,KAAK;CAC3D,MAAM,UAAU,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AAO;IACL,MAAM;IACN,KAAK;IACN;GACD,SAAS,EAAE,OAAO,KAAK,KAAK,GAAG,WAAW;GAC3C,CAEoB;UACd,OAAO;AAEd,MAAI,mBAAmB,GAAG,MAAM,CAC9B,QAAO,MAAM,MAAM;AAIrB,SAAO,MACLA,kBAAgB,yCAAyC,EACvD,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAC5D,CAAC,CACH;WACO;AACR,QAAM,OAAO,OAAO;;;AAIxB,SAAgB,4BAAqC;CACnD,MAAM,UAAU,IAAI,QAAQ,OAAO;AACnC,wBACE,SACA,gCACA,+OAGD;AACD,oBAAmB,SAAS,CAC1B,6BACA,wDACD,CAAC;AACF,kBAAiB,QAAQ,CACtB,OAAO,mBAAmB,gCAAgC,CAC1D,OAAO,OAAO,YAAiC;EAC9C,MAAM,QAAQ,iBAAiB,QAAQ;EACvC,MAAM,KAAK,IAAI,WAAW;GAAE,OAAO,MAAM;GAAO,aAAa,MAAM;GAAa,CAAC;EAMjF,MAAM,WAAW,aAHF,MAAM,2BAA2B,SAAS,OAAO,IAF9C,KAAK,KAAK,CAEkD,EAGxC,OAAO,KAAK,eAAe;AAC/D,OAAI,MAAM,KACR,IAAG,OAAO,eAAe,WAAW,CAAC;QAChC;IACL,MAAM,SAAS,iBAAiB,YAAY,MAAM;AAClD,QAAI,OACF,IAAG,IAAI,OAAO;AAEhB,QAAI,CAAC,MAAM,MACT,IAAG,QAAQ,qBAAqB,MAAM,CAAC;;IAG3C;AACF,UAAQ,KAAK,SAAS;GACtB;AAEJ,QAAO"}
@@ -1,125 +0,0 @@
1
- import { f as errorMigrationFileMissing, g as errorTargetMigrationNotSupported } from "./cli-errors-BUuJr6py.mjs";
2
- import { errorTargetHasIncompleteMigrationCapabilities } from "@prisma-next/errors/migration";
3
- import { readMigrationPackage, writeMigrationOps } from "@prisma-next/migration-tools/io";
4
- import assert from "node:assert/strict";
5
- import { attestMigration } from "@prisma-next/migration-tools/attestation";
6
- import { evaluateMigrationTs, hasMigrationTs } from "@prisma-next/migration-tools/migration-ts";
7
-
8
- //#region src/lib/migration-strategy.ts
9
- /**
10
- * Migration authoring strategy selector.
11
- *
12
- * Targets currently use one of two strategies to author `migration.ts`:
13
- *
14
- * - **Descriptor flow** — the planner produces an `OperationDescriptor[]`
15
- * and `migration.ts` is a `export default () => [...]` file that the CLI
16
- * later replays through `resolveDescriptors` at emit time. Postgres uses
17
- * this today.
18
- * - **Class flow** — the planner produces a `MigrationPlanWithAuthoringSurface`
19
- * that renders itself as a `class M extends Migration { ... }` file. The
20
- * CLI dispatches to the target's `emit` capability at emit time. Mongo
21
- * uses this today.
22
- *
23
- * The two are mutually exclusive at the target level: a migrations capability
24
- * either implements the descriptor-flow trio (`planWithDescriptors`,
25
- * `resolveDescriptors`, `renderDescriptorTypeScript`) or the class-flow
26
- * `emit` hook. `migrationStrategy` discriminates between them by observing
27
- * which hooks are present, and is consumed by `migration new`, `migration
28
- * plan`, and `migration emit` to keep strategy-specific branching in one
29
- * place.
30
- */
31
- /**
32
- * Determine which authoring strategy a target uses, based on the shape of
33
- * its `TargetMigrationsCapability`. Callers that need strategy-specific
34
- * guarantees (e.g. that `resolveDescriptors` is present) should narrow on
35
- * the returned tag and trust the capability fields directly rather than
36
- * re-probing.
37
- *
38
- * Throws `errorTargetHasIncompleteMigrationCapabilities` (PN-MIG-2011) when
39
- * the capability registers neither flow. We diagnose this here rather than
40
- * deferring to the dispatch site so a misconfigured target gets an honest
41
- * "incomplete capability" error instead of being silently routed to one
42
- * flow and reported as missing the *other* flow's hook.
43
- */
44
- function migrationStrategy(migrations, targetId) {
45
- if (migrations.resolveDescriptors) return "descriptor";
46
- if (migrations.emit) return "class-based";
47
- throw errorTargetHasIncompleteMigrationCapabilities({ targetId });
48
- }
49
-
50
- //#endregion
51
- //#region src/lib/migration-emit.ts
52
- /**
53
- * Shared helper for emitting `ops.json` and attesting `migration.json` for a
54
- * migration package's `migration.ts`.
55
- *
56
- * Two flows are dispatched here:
57
- * - Descriptor flow (Postgres): the framework evaluates `migration.ts`
58
- * (which re-exports the planner's descriptor list), calls the target's
59
- * `resolveDescriptors` to produce display-oriented operations, writes
60
- * `ops.json`, and attests `migration.json`.
61
- * - Class flow (Mongo): the target's `emit` capability dynamic-imports
62
- * `migration.ts`, instantiates the default-exported `Migration` subclass
63
- * (or invokes the default-exported factory function), reads `operations`,
64
- * and writes `ops.json`. This helper then attests `migration.json` once
65
- * the capability returns.
66
- *
67
- * In both cases attestation is owned by this helper so the on-disk artifacts
68
- * are guaranteed to be fully attested when emit returns.
69
- *
70
- * Note that this helper is the CLI-driven emit path. Class-flow `migration.ts`
71
- * files are also self-emitting via `Migration.run(...)` when run directly;
72
- * that path attests inside `Migration.run` and produces byte-identical
73
- * artifacts. This helper exists primarily to bridge descriptor-flow targets
74
- * and to give `migration plan` a single in-process emit dispatch.
75
- *
76
- * Used by `migration emit` (always) and `migration plan` (always, after
77
- * scaffolding `migration.ts`). Both flows run in-process so that structured
78
- * errors thrown during evaluation (notably `errorUnfilledPlaceholder` with
79
- * code `PN-MIG-2001`) propagate as real exceptions and the CLI's error
80
- * envelope renders them with full structured metadata.
81
- */
82
- /**
83
- * Emit `ops.json` and attest `migrationId` for the migration package at `dir`.
84
- *
85
- * Dispatches to descriptor flow when the target implements `resolveDescriptors`,
86
- * otherwise to the target's `emit` capability. Throws a structured error if
87
- * `migration.ts` is missing or the target supports neither flow. Other
88
- * structured errors thrown during evaluation propagate unchanged.
89
- */
90
- async function emitMigration(dir, ctx) {
91
- if (!await hasMigrationTs(dir)) throw errorMigrationFileMissing(dir);
92
- if (migrationStrategy(ctx.migrations, ctx.targetId) === "descriptor") return emitDescriptorFlow(dir, ctx.migrations, ctx);
93
- if (!ctx.migrations.emit) throw errorTargetMigrationNotSupported({ why: `Target "${ctx.targetId}" does not implement the class-flow \`emit\` capability; cannot emit a migration package` });
94
- return {
95
- operations: await ctx.migrations.emit({
96
- dir,
97
- frameworkComponents: ctx.frameworkComponents
98
- }),
99
- migrationId: await attestMigration(dir)
100
- };
101
- }
102
- /**
103
- * Descriptor flow: evaluate `migration.ts` to obtain a list of operation
104
- * descriptors, hand them to the target's `resolveDescriptors` along with the
105
- * manifest's contract bookends, then persist `ops.json` and attest the package.
106
- */
107
- async function emitDescriptorFlow(dir, migrations, ctx) {
108
- assert(migrations.resolveDescriptors, "emitDescriptorFlow requires resolveDescriptors; gated by caller");
109
- const pkg = await readMigrationPackage(dir);
110
- const descriptors = await evaluateMigrationTs(dir);
111
- const operations = migrations.resolveDescriptors(descriptors, {
112
- fromContract: pkg.manifest.fromContract,
113
- toContract: pkg.manifest.toContract,
114
- frameworkComponents: ctx.frameworkComponents
115
- });
116
- await writeMigrationOps(dir, operations);
117
- return {
118
- operations,
119
- migrationId: await attestMigration(dir)
120
- };
121
- }
122
-
123
- //#endregion
124
- export { migrationStrategy as n, emitMigration as t };
125
- //# sourceMappingURL=migration-emit-Du4DBMqz.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration-emit-Du4DBMqz.mjs","names":[],"sources":["../src/lib/migration-strategy.ts","../src/lib/migration-emit.ts"],"sourcesContent":["/**\n * Migration authoring strategy selector.\n *\n * Targets currently use one of two strategies to author `migration.ts`:\n *\n * - **Descriptor flow** — the planner produces an `OperationDescriptor[]`\n * and `migration.ts` is a `export default () => [...]` file that the CLI\n * later replays through `resolveDescriptors` at emit time. Postgres uses\n * this today.\n * - **Class flow** — the planner produces a `MigrationPlanWithAuthoringSurface`\n * that renders itself as a `class M extends Migration { ... }` file. The\n * CLI dispatches to the target's `emit` capability at emit time. Mongo\n * uses this today.\n *\n * The two are mutually exclusive at the target level: a migrations capability\n * either implements the descriptor-flow trio (`planWithDescriptors`,\n * `resolveDescriptors`, `renderDescriptorTypeScript`) or the class-flow\n * `emit` hook. `migrationStrategy` discriminates between them by observing\n * which hooks are present, and is consumed by `migration new`, `migration\n * plan`, and `migration emit` to keep strategy-specific branching in one\n * place.\n */\n\nimport { errorTargetHasIncompleteMigrationCapabilities } from '@prisma-next/errors/migration';\nimport type { TargetMigrationsCapability } from '@prisma-next/framework-components/control';\n\nexport type MigrationStrategy = 'descriptor' | 'class-based';\n\n/**\n * Determine which authoring strategy a target uses, based on the shape of\n * its `TargetMigrationsCapability`. Callers that need strategy-specific\n * guarantees (e.g. that `resolveDescriptors` is present) should narrow on\n * the returned tag and trust the capability fields directly rather than\n * re-probing.\n *\n * Throws `errorTargetHasIncompleteMigrationCapabilities` (PN-MIG-2011) when\n * the capability registers neither flow. We diagnose this here rather than\n * deferring to the dispatch site so a misconfigured target gets an honest\n * \"incomplete capability\" error instead of being silently routed to one\n * flow and reported as missing the *other* flow's hook.\n */\nexport function migrationStrategy(\n migrations: TargetMigrationsCapability,\n targetId: string,\n): MigrationStrategy {\n if (migrations.resolveDescriptors) return 'descriptor';\n if (migrations.emit) return 'class-based';\n throw errorTargetHasIncompleteMigrationCapabilities({ targetId });\n}\n","/**\n * Shared helper for emitting `ops.json` and attesting `migration.json` for a\n * migration package's `migration.ts`.\n *\n * Two flows are dispatched here:\n * - Descriptor flow (Postgres): the framework evaluates `migration.ts`\n * (which re-exports the planner's descriptor list), calls the target's\n * `resolveDescriptors` to produce display-oriented operations, writes\n * `ops.json`, and attests `migration.json`.\n * - Class flow (Mongo): the target's `emit` capability dynamic-imports\n * `migration.ts`, instantiates the default-exported `Migration` subclass\n * (or invokes the default-exported factory function), reads `operations`,\n * and writes `ops.json`. This helper then attests `migration.json` once\n * the capability returns.\n *\n * In both cases attestation is owned by this helper so the on-disk artifacts\n * are guaranteed to be fully attested when emit returns.\n *\n * Note that this helper is the CLI-driven emit path. Class-flow `migration.ts`\n * files are also self-emitting via `Migration.run(...)` when run directly;\n * that path attests inside `Migration.run` and produces byte-identical\n * artifacts. This helper exists primarily to bridge descriptor-flow targets\n * and to give `migration plan` a single in-process emit dispatch.\n *\n * Used by `migration emit` (always) and `migration plan` (always, after\n * scaffolding `migration.ts`). Both flows run in-process so that structured\n * errors thrown during evaluation (notably `errorUnfilledPlaceholder` with\n * code `PN-MIG-2001`) propagate as real exceptions and the CLI's error\n * envelope renders them with full structured metadata.\n */\n\nimport assert from 'node:assert/strict';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanOperation,\n OperationDescriptor,\n TargetMigrationsCapability,\n} from '@prisma-next/framework-components/control';\nimport { attestMigration } from '@prisma-next/migration-tools/attestation';\nimport { readMigrationPackage, writeMigrationOps } from '@prisma-next/migration-tools/io';\nimport { evaluateMigrationTs, hasMigrationTs } from '@prisma-next/migration-tools/migration-ts';\nimport { errorMigrationFileMissing, errorTargetMigrationNotSupported } from '../utils/cli-errors';\nimport { migrationStrategy } from './migration-strategy';\n\n/**\n * Context passed to `emitMigration`. Captures everything the helper needs to\n * dispatch to the right flow without re-loading the config.\n */\nexport interface EmitMigrationContext {\n readonly targetId: string;\n readonly migrations: TargetMigrationsCapability;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<string, string>>;\n}\n\n/**\n * Result of a successful emit: the operations that were written to `ops.json`\n * (display-oriented shape) and the content-addressed migrationId persisted to\n * `migration.json`.\n */\nexport interface EmitMigrationResult {\n readonly operations: readonly MigrationPlanOperation[];\n readonly migrationId: string;\n}\n\n/**\n * Emit `ops.json` and attest `migrationId` for the migration package at `dir`.\n *\n * Dispatches to descriptor flow when the target implements `resolveDescriptors`,\n * otherwise to the target's `emit` capability. Throws a structured error if\n * `migration.ts` is missing or the target supports neither flow. Other\n * structured errors thrown during evaluation propagate unchanged.\n */\nexport async function emitMigration(\n dir: string,\n ctx: EmitMigrationContext,\n): Promise<EmitMigrationResult> {\n if (!(await hasMigrationTs(dir))) {\n throw errorMigrationFileMissing(dir);\n }\n\n const strategy = migrationStrategy(ctx.migrations, ctx.targetId);\n\n if (strategy === 'descriptor') {\n return emitDescriptorFlow(dir, ctx.migrations, ctx);\n }\n\n if (!ctx.migrations.emit) {\n throw errorTargetMigrationNotSupported({\n why: `Target \"${ctx.targetId}\" does not implement the class-flow \\`emit\\` capability; cannot emit a migration package`,\n });\n }\n\n const operations = await ctx.migrations.emit({\n dir,\n frameworkComponents: ctx.frameworkComponents,\n });\n const migrationId = await attestMigration(dir);\n return { operations, migrationId };\n}\n\n/**\n * Descriptor flow: evaluate `migration.ts` to obtain a list of operation\n * descriptors, hand them to the target's `resolveDescriptors` along with the\n * manifest's contract bookends, then persist `ops.json` and attest the package.\n */\nasync function emitDescriptorFlow(\n dir: string,\n migrations: TargetMigrationsCapability,\n ctx: EmitMigrationContext,\n): Promise<EmitMigrationResult> {\n assert(\n migrations.resolveDescriptors,\n 'emitDescriptorFlow requires resolveDescriptors; gated by caller',\n );\n const pkg = await readMigrationPackage(dir);\n const descriptors = await evaluateMigrationTs(dir);\n const operations = migrations.resolveDescriptors(descriptors as OperationDescriptor[], {\n fromContract: pkg.manifest.fromContract,\n toContract: pkg.manifest.toContract,\n frameworkComponents: ctx.frameworkComponents,\n });\n await writeMigrationOps(dir, operations);\n const migrationId = await attestMigration(dir);\n return { operations, migrationId };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,kBACd,YACA,UACmB;AACnB,KAAI,WAAW,mBAAoB,QAAO;AAC1C,KAAI,WAAW,KAAM,QAAO;AAC5B,OAAM,8CAA8C,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACyBnE,eAAsB,cACpB,KACA,KAC8B;AAC9B,KAAI,CAAE,MAAM,eAAe,IAAI,CAC7B,OAAM,0BAA0B,IAAI;AAKtC,KAFiB,kBAAkB,IAAI,YAAY,IAAI,SAAS,KAE/C,aACf,QAAO,mBAAmB,KAAK,IAAI,YAAY,IAAI;AAGrD,KAAI,CAAC,IAAI,WAAW,KAClB,OAAM,iCAAiC,EACrC,KAAK,WAAW,IAAI,SAAS,2FAC9B,CAAC;AAQJ,QAAO;EAAE,YALU,MAAM,IAAI,WAAW,KAAK;GAC3C;GACA,qBAAqB,IAAI;GAC1B,CAAC;EAEmB,aADD,MAAM,gBAAgB,IAAI;EACZ;;;;;;;AAQpC,eAAe,mBACb,KACA,YACA,KAC8B;AAC9B,QACE,WAAW,oBACX,kEACD;CACD,MAAM,MAAM,MAAM,qBAAqB,IAAI;CAC3C,MAAM,cAAc,MAAM,oBAAoB,IAAI;CAClD,MAAM,aAAa,WAAW,mBAAmB,aAAsC;EACrF,cAAc,IAAI,SAAS;EAC3B,YAAY,IAAI,SAAS;EACzB,qBAAqB,IAAI;EAC1B,CAAC;AACF,OAAM,kBAAkB,KAAK,WAAW;AAExC,QAAO;EAAE;EAAY,aADD,MAAM,gBAAgB,IAAI;EACZ"}