@prisma-next/cli 0.4.0-dev.6 → 0.4.0-dev.7

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 (47) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.mjs +3 -3
  3. package/dist/{client-DUs1DH-1.mjs → client-CJxHfhze.mjs} +3 -1
  4. package/dist/client-CJxHfhze.mjs.map +1 -0
  5. package/dist/commands/contract-emit.mjs +1 -1
  6. package/dist/commands/contract-infer.mjs +1 -1
  7. package/dist/commands/db-init.mjs +2 -2
  8. package/dist/commands/db-schema.mjs +1 -1
  9. package/dist/commands/db-sign.mjs +1 -1
  10. package/dist/commands/db-update.mjs +2 -2
  11. package/dist/commands/db-verify.mjs +1 -1
  12. package/dist/commands/migration-apply.mjs +1 -1
  13. package/dist/commands/migration-emit.mjs +2 -2
  14. package/dist/commands/migration-emit.mjs.map +1 -1
  15. package/dist/commands/migration-new.d.mts.map +1 -1
  16. package/dist/commands/migration-new.mjs +31 -8
  17. package/dist/commands/migration-new.mjs.map +1 -1
  18. package/dist/commands/migration-plan.d.mts.map +1 -1
  19. package/dist/commands/migration-plan.mjs +91 -60
  20. package/dist/commands/migration-plan.mjs.map +1 -1
  21. package/dist/commands/migration-status.mjs +1 -1
  22. package/dist/{contract-emit-7jqH6dq9.mjs → contract-emit-gpJNLGs7.mjs} +2 -2
  23. package/dist/{contract-emit-7jqH6dq9.mjs.map → contract-emit-gpJNLGs7.mjs.map} +1 -1
  24. package/dist/{contract-infer-BFlIbyl9.mjs → contract-infer-BDJgg7Xb.mjs} +2 -2
  25. package/dist/{contract-infer-BFlIbyl9.mjs.map → contract-infer-BDJgg7Xb.mjs.map} +1 -1
  26. package/dist/exports/control-api.mjs +1 -1
  27. package/dist/exports/index.mjs +1 -1
  28. package/dist/{inspect-live-schema-gjmUZ8xm.mjs → inspect-live-schema-ChqrALmw.mjs} +2 -2
  29. package/dist/{inspect-live-schema-gjmUZ8xm.mjs.map → inspect-live-schema-ChqrALmw.mjs.map} +1 -1
  30. package/dist/{migration-command-scaffold-CfllKppa.mjs → migration-command-scaffold-B0oH_hyB.mjs} +2 -2
  31. package/dist/{migration-command-scaffold-CfllKppa.mjs.map → migration-command-scaffold-B0oH_hyB.mjs.map} +1 -1
  32. package/dist/migration-emit-Du4DBMqz.mjs +125 -0
  33. package/dist/migration-emit-Du4DBMqz.mjs.map +1 -0
  34. package/dist/{migration-status-BwKCQB_a.mjs → migration-status-CPamfEPj.mjs} +2 -2
  35. package/dist/{migration-status-BwKCQB_a.mjs.map → migration-status-CPamfEPj.mjs.map} +1 -1
  36. package/package.json +16 -16
  37. package/src/commands/migration-emit.ts +3 -1
  38. package/src/commands/migration-new.ts +48 -13
  39. package/src/commands/migration-plan.ts +140 -90
  40. package/src/control-api/operations/db-init.ts +3 -0
  41. package/src/control-api/operations/db-update.ts +3 -0
  42. package/src/lib/migration-emit.ts +36 -24
  43. package/src/lib/migration-strategy.ts +49 -0
  44. package/src/utils/cli-errors.ts +2 -0
  45. package/dist/client-DUs1DH-1.mjs.map +0 -1
  46. package/dist/migration-emit-dRXV6QSz.mjs +0 -72
  47. package/dist/migration-emit-dRXV6QSz.mjs.map +0 -1
@@ -0,0 +1,125 @@
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
@@ -0,0 +1 @@
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"}
@@ -1,6 +1,6 @@
1
1
  import { t as loadConfig } from "./config-loader-C4VXKl8f.mjs";
2
2
  import { h as errorRuntime, v as errorUnexpected } from "./cli-errors-BUuJr6py.mjs";
3
- import { t as createControlClient } from "./client-DUs1DH-1.mjs";
3
+ import { t as createControlClient } from "./client-CJxHfhze.mjs";
4
4
  import { _ as formatStyledHeader, a as maskConnectionUrl, c as resolveMigrationPaths, d as setCommandExamples, i as loadAllBundles, m as parseGlobalFlags, n as addGlobalOptions, o as readContractEnvelope, p as toPathDecisionResult, t as handleResult, u as setCommandDescriptions } from "./result-handler-AFK4hxyX.mjs";
5
5
  import { t as TerminalUI } from "./terminal-ui-C5k88MmW.mjs";
6
6
  import { Command } from "commander";
@@ -1580,4 +1580,4 @@ function summarizeRefDistance(graph, markerHash, refHash, refName) {
1580
1580
 
1581
1581
  //#endregion
1582
1582
  export { deriveEdgeStatuses as n, createMigrationStatusCommand as t };
1583
- //# sourceMappingURL=migration-status-BwKCQB_a.mjs.map
1583
+ //# sourceMappingURL=migration-status-CPamfEPj.mjs.map