@prisma-next/cli 0.5.0-dev.1 → 0.5.0-dev.11

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 (138) hide show
  1. package/README.md +17 -18
  2. package/dist/agent-skill-mongo.md +63 -31
  3. package/dist/agent-skill-postgres.md +1 -1
  4. package/dist/cli-errors-By1iVE3z.mjs +34 -0
  5. package/dist/cli-errors-By1iVE3z.mjs.map +1 -0
  6. package/dist/{cli-errors-C0JhVj0c.d.mts → cli-errors-D2NPMaxW.d.mts} +1 -0
  7. package/dist/cli.mjs +126 -13
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/{client-TG7rbCWT.mjs → client-faKQqcix.mjs} +19 -4
  10. package/dist/client-faKQqcix.mjs.map +1 -0
  11. package/dist/commands/contract-emit.mjs +7 -2
  12. package/dist/commands/contract-infer.mjs +8 -2
  13. package/dist/commands/db-init.mjs +8 -7
  14. package/dist/commands/db-init.mjs.map +1 -1
  15. package/dist/commands/db-schema.mjs +8 -5
  16. package/dist/commands/db-schema.mjs.map +1 -1
  17. package/dist/commands/db-sign.mjs +8 -7
  18. package/dist/commands/db-sign.mjs.map +1 -1
  19. package/dist/commands/db-update.mjs +8 -7
  20. package/dist/commands/db-update.mjs.map +1 -1
  21. package/dist/commands/db-verify.mjs +8 -7
  22. package/dist/commands/db-verify.mjs.map +1 -1
  23. package/dist/commands/migration-apply.d.mts +1 -1
  24. package/dist/commands/migration-apply.d.mts.map +1 -1
  25. package/dist/commands/migration-apply.mjs +15 -38
  26. package/dist/commands/migration-apply.mjs.map +1 -1
  27. package/dist/commands/migration-new.d.mts.map +1 -1
  28. package/dist/commands/migration-new.mjs +21 -26
  29. package/dist/commands/migration-new.mjs.map +1 -1
  30. package/dist/commands/migration-plan.d.mts +6 -3
  31. package/dist/commands/migration-plan.d.mts.map +1 -1
  32. package/dist/commands/migration-plan.mjs +31 -36
  33. package/dist/commands/migration-plan.mjs.map +1 -1
  34. package/dist/commands/migration-ref.d.mts +6 -4
  35. package/dist/commands/migration-ref.d.mts.map +1 -1
  36. package/dist/commands/migration-ref.mjs +31 -40
  37. package/dist/commands/migration-ref.mjs.map +1 -1
  38. package/dist/commands/migration-show.d.mts +4 -4
  39. package/dist/commands/migration-show.d.mts.map +1 -1
  40. package/dist/commands/migration-show.mjs +19 -26
  41. package/dist/commands/migration-show.mjs.map +1 -1
  42. package/dist/commands/migration-status.d.mts +5 -4
  43. package/dist/commands/migration-status.d.mts.map +1 -1
  44. package/dist/commands/migration-status.mjs +7 -2
  45. package/dist/{config-loader-_W4T21X1.mjs → config-loader-C25b63rJ.mjs} +1 -1
  46. package/dist/{config-loader-_W4T21X1.mjs.map → config-loader-C25b63rJ.mjs.map} +1 -1
  47. package/dist/config-loader.mjs +1 -1
  48. package/dist/contract-emit-B9wkchud.mjs +6 -0
  49. package/dist/{contract-emit-CNYyzJwF.mjs → contract-emit-Cf3fjDL6.mjs} +8 -8
  50. package/dist/{contract-emit-CNYyzJwF.mjs.map → contract-emit-Cf3fjDL6.mjs.map} +1 -1
  51. package/dist/{contract-emit-CQfj7xJn.mjs → contract-emit-PeB96eHy.mjs} +6 -6
  52. package/dist/{contract-emit-CQfj7xJn.mjs.map → contract-emit-PeB96eHy.mjs.map} +1 -1
  53. package/dist/{contract-enrichment-CGW6mm-E.mjs → contract-enrichment-CAOELa-H.mjs} +1 -1
  54. package/dist/{contract-enrichment-CGW6mm-E.mjs.map → contract-enrichment-CAOELa-H.mjs.map} +1 -1
  55. package/dist/{contract-infer-BP3DrGgz.mjs → contract-infer-BgnsSkGp.mjs} +4 -4
  56. package/dist/{contract-infer-BP3DrGgz.mjs.map → contract-infer-BgnsSkGp.mjs.map} +1 -1
  57. package/dist/exports/control-api.mjs +6 -4
  58. package/dist/exports/index.mjs +7 -2
  59. package/dist/exports/index.mjs.map +1 -1
  60. package/dist/exports/init-output.d.mts +39 -0
  61. package/dist/exports/init-output.d.mts.map +1 -0
  62. package/dist/exports/init-output.mjs +3 -0
  63. package/dist/{extract-operation-statements-DZUJNmL3.mjs → extract-operation-statements-DsFfxXVZ.mjs} +2 -2
  64. package/dist/{extract-operation-statements-DZUJNmL3.mjs.map → extract-operation-statements-DsFfxXVZ.mjs.map} +1 -1
  65. package/dist/{extract-sql-ddl-DDMX-9mz.mjs → extract-sql-ddl-D9UbZDyz.mjs} +1 -1
  66. package/dist/{extract-sql-ddl-DDMX-9mz.mjs.map → extract-sql-ddl-D9UbZDyz.mjs.map} +1 -1
  67. package/dist/{framework-components-DfZKQBQ2.mjs → framework-components-C6el-5x_.mjs} +2 -2
  68. package/dist/{framework-components-DfZKQBQ2.mjs.map → framework-components-C6el-5x_.mjs.map} +1 -1
  69. package/dist/init-jf33mNQ6.mjs +2062 -0
  70. package/dist/init-jf33mNQ6.mjs.map +1 -0
  71. package/dist/{inspect-live-schema-DWzf4Q_m.mjs → inspect-live-schema-yCu0JT0I.mjs} +6 -6
  72. package/dist/{inspect-live-schema-DWzf4Q_m.mjs.map → inspect-live-schema-yCu0JT0I.mjs.map} +1 -1
  73. package/dist/migration-cli.mjs +14 -7
  74. package/dist/migration-cli.mjs.map +1 -1
  75. package/dist/{migration-command-scaffold-CLMD302g.mjs → migration-command-scaffold-B8HAEGhQ.mjs} +6 -6
  76. package/dist/{migration-command-scaffold-CLMD302g.mjs.map → migration-command-scaffold-B8HAEGhQ.mjs.map} +1 -1
  77. package/dist/{migration-status-B0HLF7So.mjs → migration-status-8QUxCJHE.mjs} +19 -33
  78. package/dist/migration-status-8QUxCJHE.mjs.map +1 -0
  79. package/dist/{migrations-B0dOQlk0.mjs → migrations-CKRMAKka.mjs} +3 -3
  80. package/dist/migrations-CKRMAKka.mjs.map +1 -0
  81. package/dist/output-BpcQrnnq.mjs +103 -0
  82. package/dist/output-BpcQrnnq.mjs.map +1 -0
  83. package/dist/{progress-adapter-B-YvmcDu.mjs → progress-adapter-DvQWB1nK.mjs} +1 -1
  84. package/dist/{progress-adapter-B-YvmcDu.mjs.map → progress-adapter-DvQWB1nK.mjs.map} +1 -1
  85. package/dist/quick-reference-mongo.md +34 -13
  86. package/dist/quick-reference-postgres.md +11 -9
  87. package/dist/{result-handler-CIyu0Pdt.mjs → result-handler-CuhZ3kNu.mjs} +10 -91
  88. package/dist/result-handler-CuhZ3kNu.mjs.map +1 -0
  89. package/dist/{terminal-ui-C5k88MmW.mjs → terminal-ui-C3ZLwQxK.mjs} +76 -2
  90. package/dist/terminal-ui-C3ZLwQxK.mjs.map +1 -0
  91. package/dist/{validate-contract-deps-esa-VQ0h.mjs → validate-contract-deps-B_Cs29TL.mjs} +1 -1
  92. package/dist/{validate-contract-deps-esa-VQ0h.mjs.map → validate-contract-deps-B_Cs29TL.mjs.map} +1 -1
  93. package/dist/{verify-BxiVp50b.mjs → verify-Bkycc-Tf.mjs} +2 -2
  94. package/dist/{verify-BxiVp50b.mjs.map → verify-Bkycc-Tf.mjs.map} +1 -1
  95. package/package.json +20 -15
  96. package/src/commands/init/detect-pnpm-catalog.ts +141 -0
  97. package/src/commands/init/errors.ts +254 -0
  98. package/src/commands/init/exit-codes.ts +62 -0
  99. package/src/commands/init/hygiene-gitattributes.ts +97 -0
  100. package/src/commands/init/hygiene-gitignore.ts +48 -0
  101. package/src/commands/init/hygiene-package-scripts.ts +91 -0
  102. package/src/commands/init/index.ts +112 -7
  103. package/src/commands/init/init.ts +766 -144
  104. package/src/commands/init/inputs.ts +421 -0
  105. package/src/commands/init/output.ts +147 -0
  106. package/src/commands/init/probe-db.ts +308 -0
  107. package/src/commands/init/reinit-cleanup.ts +83 -0
  108. package/src/commands/init/templates/agent-skill-mongo.md +63 -31
  109. package/src/commands/init/templates/agent-skill-postgres.md +1 -1
  110. package/src/commands/init/templates/agent-skill.ts +25 -3
  111. package/src/commands/init/templates/code-templates.ts +125 -32
  112. package/src/commands/init/templates/env.ts +80 -0
  113. package/src/commands/init/templates/quick-reference-mongo.md +34 -13
  114. package/src/commands/init/templates/quick-reference-postgres.md +11 -9
  115. package/src/commands/init/templates/quick-reference.ts +42 -3
  116. package/src/commands/init/templates/tsconfig.ts +167 -5
  117. package/src/commands/migration-apply.ts +15 -50
  118. package/src/commands/migration-new.ts +23 -28
  119. package/src/commands/migration-plan.ts +53 -42
  120. package/src/commands/migration-ref.ts +40 -54
  121. package/src/commands/migration-show.ts +27 -28
  122. package/src/commands/migration-status.ts +33 -50
  123. package/src/control-api/operations/migration-apply.ts +15 -0
  124. package/src/exports/init-output.ts +10 -0
  125. package/src/migration-cli.ts +16 -9
  126. package/src/utils/cli-errors.ts +45 -1
  127. package/src/utils/command-helpers.ts +13 -26
  128. package/src/utils/formatters/graph-migration-mapper.ts +2 -2
  129. package/src/utils/formatters/migrations.ts +2 -2
  130. package/dist/cli-errors-DHq6GQGu.mjs +0 -5
  131. package/dist/client-TG7rbCWT.mjs.map +0 -1
  132. package/dist/contract-emit-fhNwwhkQ.mjs +0 -4
  133. package/dist/init-CQfo_4Ro.mjs +0 -430
  134. package/dist/init-CQfo_4Ro.mjs.map +0 -1
  135. package/dist/migration-status-B0HLF7So.mjs.map +0 -1
  136. package/dist/migrations-B0dOQlk0.mjs.map +0 -1
  137. package/dist/result-handler-CIyu0Pdt.mjs.map +0 -1
  138. package/dist/terminal-ui-C5k88MmW.mjs.map +0 -1
package/README.md CHANGED
@@ -951,12 +951,12 @@ prisma-next migration plan [--config <path>] [--name <slug>] [--from <hash>] [--
951
951
  2. Reads existing migrations from `config.migrations.dir` (default: `migrations/`)
952
952
  3. Determines the starting point: `--from <hash>` if provided, otherwise the latest migration target
953
953
  4. Diffs the starting contract against the new contract using the target's migration planner
954
- 5. Scaffolds a new migration package: `migration.ts` (containing `placeholder(...)` lambdas for any data transforms), `migration.json` (with a content-addressed `migrationId` over the planned ops, or over `[]` when the planner could not lower any calls because of placeholders), `ops.json` (the planned ops, or `[]` in the placeholder-blocked case), and contract bookends. The package is **always** fully attested — there is no draft state on disk.
955
- 6. If the plan has unfilled `placeholder(...)` slots, the command returns a successful `pendingPlaceholders` envelope (a warning, not a failure) asking the developer to fill in the slots before re-emitting. The on-disk `ops.json` is `[]` and `migrationId` is the hash of `(manifest, [])`, so applying the migration as-written will not advance the storage hash to the intended destination — the runner's destination-hash post-check surfaces this as a state mismatch. After filling in the placeholders, run `node migrations/<dir>/migration.ts` to re-emit `ops.json` and the corresponding `migrationId`. `PN-MIG-2001` is raised only at self-emit time when a slot is still unfilled.
954
+ 5. Scaffolds a new migration package: `migration.ts` (containing `placeholder(...)` lambdas for any data transforms), `migration.json` (with a content-addressed `migrationHash` over the planned ops, or over `[]` when the planner could not lower any calls because of placeholders), `ops.json` (the planned ops, or `[]` in the placeholder-blocked case), and contract bookends. The package is **always** fully attested — there is no draft state on disk.
955
+ 6. If the plan has unfilled `placeholder(...)` slots, the command returns a successful `pendingPlaceholders` envelope (a warning, not a failure) asking the developer to fill in the slots before re-emitting. The on-disk `ops.json` is `[]` and `migrationHash` is the hash of `(metadata, [])`, so applying the migration as-written will not advance the storage hash to the intended destination — the runner's destination-hash post-check surfaces this as a state mismatch. After filling in the placeholders, run `node migrations/<dir>/migration.ts` to re-emit `ops.json` and the corresponding `migrationHash`. `PN-MIG-2001` is raised only at self-emit time when a slot is still unfilled.
956
956
 
957
957
  **Outputs:**
958
958
  - `migrations/<dir>/migration.ts` — editable migration source (with `placeholder(...)` slots when the planner inserted them)
959
- - `migrations/<dir>/migration.json` — fully attested manifest (`migrationId: string`, never null)
959
+ - `migrations/<dir>/migration.json` — fully attested metadata (`migrationHash: string`, never null)
960
960
  - `migrations/<dir>/ops.json` — planned operations (empty list `[]` if placeholders blocked the planner)
961
961
  - `migrations/<dir>/start-contract.{json,d.ts}` — bookend from the "from" side (when applicable)
962
962
  - `migrations/<dir>/end-contract.{json,d.ts}` — bookend from the "to" side
@@ -965,14 +965,14 @@ prisma-next migration plan [--config <path>] [--name <slug>] [--from <hash>] [--
965
965
 
966
966
  ### `prisma-next migration show`
967
967
 
968
- Display a migration package's operations, DDL preview, and metadata. Accepts a directory path, a hash prefix (git-style matching against `migrationId`), or defaults to the latest migration.
968
+ Display a migration package's operations, DDL preview, and metadata. Accepts a directory path, a hash prefix (git-style matching against `migrationHash`), or defaults to the latest migration.
969
969
 
970
970
  ```bash
971
971
  prisma-next migration show [target] [--config <path>] [--json] [-v] [-q] [--color/--no-color]
972
972
  ```
973
973
 
974
974
  **Options:**
975
- - `[target]`: Migration directory path or migrationId hash prefix (defaults to latest)
975
+ - `[target]`: Migration directory path or `migrationHash` prefix (defaults to latest)
976
976
  - `--config <path>`: Path to `prisma-next.config.ts`
977
977
  - `--json`: Output as JSON object
978
978
  - `-q, --quiet`: Quiet mode (errors only)
@@ -980,7 +980,7 @@ prisma-next migration show [target] [--config <path>] [--json] [-v] [-q] [--colo
980
980
 
981
981
  **What it does:**
982
982
  1. If `target` is a path (contains `/` or `\`), reads that directory directly
983
- 2. If `target` is a hash prefix, scans all attested migrations and matches against `migrationId`
983
+ 2. If `target` is a hash prefix, scans all attested migrations and matches against `migrationHash`
984
984
  3. If no target, defaults to the latest migration
985
985
  4. Displays operations with operation class badges, destructive warnings, and DDL preview
986
986
 
@@ -1034,15 +1034,14 @@ prisma-next migration apply [--db <url>] [--ref <name>] [--config <path>] [--jso
1034
1034
  - `-v, --verbose`: Verbose output (debug info, timings)
1035
1035
 
1036
1036
  **What it does:**
1037
- 1. Reads migration packages from `config.migrations.dir` (every package is attested — there is no on-disk draft state)
1038
- 2. **Defense in depth:** rehashes `(manifest, ops)` for each loaded bundle and confirms it matches the stored `migrationId`. If a bundle has been hand-edited or partially written since emit, apply aborts with a structured runtime error pointing at the offending directory and asks the developer to re-run `node migrations/<dir>/migration.ts` (or restore from version control).
1039
- 3. Reconstructs the migration graph from all loaded bundles
1040
- 4. Determines the destination hash: from `--ref` (via `refs.json`) or from `contract.json`
1041
- 5. Connects to the database and reads the current marker hash
1042
- 6. Finds the shortest path from the marker hash to the destination using graph pathfinding
1043
- 7. Executes each pending migration in order using the target's `MigrationRunner`
1044
- 8. Each migration runs in its own transaction with prechecks, postchecks, and idempotency checks enabled
1045
- 9. After each migration, the runner verifies the schema and updates the marker/ledger
1037
+ 1. Reads migration packages from `config.migrations.dir`. Every package is attested — there is no on-disk draft state. The loader (`readMigrationPackage` in `@prisma-next/migration-tools/io`) rehashes `(metadata, ops)` for each `MigrationPackage` it returns and confirms the result matches the stored `migrationHash`. If a package has been hand-edited or partially written since emit, the load fails with `MIGRATION.HASH_MISMATCH` pointing at the offending directory and asks the developer to re-run `node migrations/<dir>/migration.ts` (or restore from version control).
1038
+ 2. Reconstructs the migration graph from all loaded packages
1039
+ 3. Determines the destination hash: from `--ref` (via `refs.json`) or from `contract.json`
1040
+ 4. Connects to the database and reads the current marker hash
1041
+ 5. Finds the shortest path from the marker hash to the destination using graph pathfinding
1042
+ 6. Executes each pending migration in order using the target's `MigrationRunner`
1043
+ 7. Each migration runs in its own transaction with prechecks, postchecks, and idempotency checks enabled
1044
+ 8. After each migration, the runner verifies the schema and updates the marker/ledger
1046
1045
 
1047
1046
  **Config requirements:** Requires `driver` and `db.connection` (or `--db`). `migrations.dir` is optional and defaults to `migrations/`.
1048
1047
 
@@ -1050,7 +1049,7 @@ prisma-next migration apply [--db <url>] [--ref <name>] [--config <path>] [--jso
1050
1049
 
1051
1050
  **Ref-based routing:** With `--ref`, apply targets the ref's hash instead of the contract hash. This enables multi-environment workflows where staging and production track different points in the migration graph.
1052
1051
 
1053
- ### Emitting `ops.json` and computing `migrationId`
1052
+ ### Emitting `ops.json` and computing `migrationHash`
1054
1053
 
1055
1054
  There is no dedicated CLI command for emitting a migration — migrations
1056
1055
  self-emit. After scaffolding (via `migration plan` or `migration new`),
@@ -1061,7 +1060,7 @@ run `migration.ts` directly with Node to produce `ops.json` and attest
1061
1060
  node migrations/<dir>/migration.ts
1062
1061
  ```
1063
1062
 
1064
- The scaffolded `migration.ts` calls `MigrationCLI.run(import.meta.url, ...)` from `@prisma-next/cli/migration-cli` when invoked as the entrypoint. (Postgres scaffolds re-export `MigrationCLI` through `@prisma-next/target-postgres/migration` so a Postgres `migration.ts` only needs the single facade import; Mongo scaffolds still pull from `@prisma-next/cli/migration-cli` directly.) The CLI entrypoint loads `prisma-next.config.ts`, assembles a `ControlStack`, instantiates the migration with that stack (so `dataTransform` and other adapter-aware helpers can materialize a real adapter), and serializes operations to `ops.json` while writing the content-addressed `migrationId` into `migration.json`. If `migration.ts` contains unfilled `placeholder()` slots, the script exits with `PN-MIG-2001` and reports the slot to fill in.
1063
+ The scaffolded `migration.ts` calls `MigrationCLI.run(import.meta.url, ...)` from `@prisma-next/cli/migration-cli` when invoked as the entrypoint. (Postgres scaffolds re-export `MigrationCLI` through `@prisma-next/target-postgres/migration` so a Postgres `migration.ts` only needs the single facade import; Mongo scaffolds still pull from `@prisma-next/cli/migration-cli` directly.) The CLI entrypoint loads `prisma-next.config.ts`, assembles a `ControlStack`, instantiates the migration with that stack (so `dataTransform` and other adapter-aware helpers can materialize a real adapter), and serializes operations to `ops.json` while writing the content-addressed `migrationHash` into `migration.json`. If `migration.ts` contains unfilled `placeholder()` slots, the script exits with `PN-MIG-2001` and reports the slot to fill in.
1065
1064
 
1066
1065
  ### `prisma-next migration ref`
1067
1066
 
@@ -1266,7 +1265,7 @@ export default defineConfig({
1266
1265
  - **`commander`**: CLI argument parsing and command routing
1267
1266
  - **`esbuild`**: Bundling TypeScript contract files with import allowlisting
1268
1267
  - **`@prisma-next/emitter`**: Contract emission engine (returns strings)
1269
- - **`@prisma-next/migration-tools`**: On-disk migration I/O, attestation, and history reconstruction
1268
+ - **`@prisma-next/migration-tools`**: On-disk migration I/O, hash verification, and history reconstruction
1270
1269
  - **`@prisma-next/framework-components`**: Control plane types, migration operation types, control stack (via `./control`)
1271
1270
  - **`@prisma-next/errors`**: Error types and factories (via `./control`)
1272
1271
 
@@ -4,7 +4,7 @@ This project uses **Prisma Next** with **MongoDB** via `@prisma-next/mongo`. Pri
4
4
 
5
5
  ## Files
6
6
 
7
- - **Contract**: `{{schemaPath}}` — the user's data models. Edit this to add or change models.
7
+ - **Contract**: `{{schemaPath}}` ({{authoringLabel}} authoring) — the user's data models. Edit this to add or change models.
8
8
  - **Config**: `prisma-next.config.ts` — tells the CLI where the contract is and how to connect to the database. Loads `.env` via `dotenv/config`.
9
9
  - **Database client**: `{{schemaDir}}/db.ts` — `import { db } from '{{dbImportPath}}'`. This is the entry point for all queries.
10
10
  - **Generated files** (do not edit by hand):
@@ -23,71 +23,103 @@ This project uses **Prisma Next** with **MongoDB** via `@prisma-next/mongo`. Pri
23
23
 
24
24
  ## How to write queries
25
25
 
26
- Always use the ORM (`db.orm`). Only fall back to `db.sql` if the user explicitly asks for raw queries or the ORM doesn't support the operation.
26
+ Use the ORM (`db.orm`). Each root accessor is the lowercased plural form emitted by `prisma-next contract emit` (typically the `@@map`-ped collection name) for `model User { @@map("users") }` use `db.orm.users`, for `model Post { @@map("posts") }` use `db.orm.posts`. The Mongo facade has no raw-SQL surface. Two escape hatches exist for cases the ORM can't express; both are covered under "Escape hatches" below.
27
27
 
28
28
  ```typescript
29
29
  import { db } from '{{dbImportPath}}';
30
30
 
31
31
  // Find one record
32
- const user = await db.orm.User
33
- .where(user => user.email.eq('alice@example.com'))
32
+ const user = await db.orm.users
33
+ .where({ email: 'alice@example.com' })
34
34
  .first();
35
- // Returns { id: ObjectId; email: string; ... } | null
35
+ // Returns { _id: ObjectId; email: string; ... } | null
36
36
 
37
- // Find multiple records
38
- const users = await db.orm.User
39
- .select('id', 'email')
37
+ // Find multiple records — `.all()` returns an AsyncIterableResult, consume
38
+ // either as an async iterable (below) or by `await`ing it to materialise an Array.
39
+ for await (const user of db.orm.users
40
+ .select('_id', 'email')
40
41
  .take(10)
41
- .all();
42
- // Returns Array<{ id: ObjectId; email: string }>
42
+ .all()) {
43
+ // Each `user` is { _id: ObjectId; email: string }
44
+ }
45
+ // Returns AsyncIterableResult<{ _id: ObjectId; email: string }>
43
46
 
44
47
  // Filter, order, limit
45
- const recentPosts = await db.orm.Post
46
- .where(post => post.authorId.eq(userId))
47
- .orderBy(post => post.createdAt.desc())
48
- .select('id', 'title', 'createdAt')
48
+ const recentPosts = await db.orm.posts
49
+ .where({ authorId: userId })
50
+ .orderBy({ createdAt: -1 })
51
+ .select('_id', 'title', 'createdAt')
49
52
  .take(50)
50
53
  .all();
51
54
 
52
- // Include relations
53
- const usersWithPosts = await db.orm.User
54
- .select('id', 'email')
55
- .include('posts', post =>
56
- post.select('id', 'title').orderBy(p => p.createdAt.desc()).take(5)
57
- )
55
+ // Include relations (reference relations only — embedded relations come back automatically)
56
+ const usersWithPosts = await db.orm.users
57
+ .select('_id', 'email')
58
+ .include('posts')
58
59
  .take(10)
59
60
  .all();
60
61
  ```
61
62
 
62
63
  ### Key ORM methods
63
64
 
64
- - `.where(predicate)` — filter records. Predicate receives a model accessor with `.eq()`, `.neq()`, `.ilike()`, `.lt()`, `.gt()`, etc.
65
+ - `.where({ field: value, ... })` — filter records by an equality object. Pass a raw filter expression for `$gt`/`$in`/`$regex` etc.
65
66
  - `.select('field1', 'field2', ...)` — pick which fields to return
66
- - `.orderBy(accessor => accessor.field.asc()` or `.desc())` — sort results
67
- - `.take(n)` — limit number of results
68
- - `.all()` — execute and return all matching records as an array
69
- - `.first()` — execute and return the first matching record, or `null`
70
- - `.first({ id: value })` — find a single record by primary key, or `null`
71
- - `.include('relation', builder => ...)` — eager-load a relation
67
+ - `.orderBy({ field: 1 | -1 })` — sort results (1 = ascending, -1 = descending)
68
+ - `.take(n)` / `.skip(n)` — limit and offset
69
+ - `.all()` — execute and return all matching records as an `AsyncIterableResult`
70
+ - `.first()` — execute with limit 1 and return the first matching row, or `null`
71
+ - `.include('relationName')` — eager-load a reference relation (`$lookup`); embedded relations are already part of the row
72
+ - `.variant('VariantName')` — narrow a polymorphic collection to a discriminator value
73
+
74
+ ## Escape hatches
75
+
76
+ The ORM covers the common cases. When you genuinely need something it can't express, prefer these — in order — over reaching for `db.runtime()` (which is an internal executor surface, not a `mongodb`-driver handle):
77
+
78
+ 1. **Typed raw aggregations — `db.query`.** The facade exposes a `db.query` builder that runs aggregation pipelines through the same runtime + middleware + codec stack as `db.orm`, so results stay typed against the contract. Use this for `$lookup`/`$facet`/`$graphLookup`/window-function pipelines that the ORM doesn't surface.
79
+
80
+ 2. **Direct `mongodb` driver control — `mongoClient` binding.** If you need a raw `MongoClient` (e.g. for transactions, change streams, sessions, or a driver feature Prisma Next doesn't expose), construct one yourself and pass it to `mongo({ mongoClient, dbName, contractJson })`. Your code keeps the `MongoClient` reference and uses it directly, while the same `db` object still gives you the typed ORM surface:
81
+
82
+ ```typescript
83
+ import { MongoClient } from 'mongodb';
84
+ import mongo from '@prisma-next/mongo/runtime';
85
+ import type { Contract } from './contract.d';
86
+ import contractJson from './contract.json' with { type: 'json' };
87
+
88
+ const client = new MongoClient(process.env['DATABASE_URL']!);
89
+ await client.connect();
90
+
91
+ export const db = mongo<Contract>({ contractJson, mongoClient: client, dbName: 'mydb' });
92
+
93
+ const session = client.startSession();
94
+ try {
95
+ await session.withTransaction(async () => {
96
+ await db.orm.users.createAll([{ /* ... */ }]);
97
+ });
98
+ } finally {
99
+ await session.endSession();
100
+ }
101
+ ```
72
102
 
73
103
  ## Rules
74
104
 
75
105
  - **Never hand-edit** `contract.json` or `contract.d.ts`. Always regenerate them with `contract emit`.
76
106
  - **Always emit after contract changes.** When you modify `{{schemaPath}}`, run `{{pkgRun}} contract emit` before writing any code that depends on the new or changed models.
77
- - **Don't restructure `db.ts`.** It's scaffolded by init and works as-is.
78
- - **Use `db.orm` for queries**, not `db.sql`. The ORM is the primary query surface.
107
+ - **Don't restructure `db.ts`.** It's scaffolded by init and works as-is. `db` connects lazily on the first query — there is no `db.connect(...)` step.
108
+ - **Root accessors are emitter-driven.** Use the lowercased plural collection name (e.g. `db.orm.users`, `db.orm.posts`) not the PascalCase model name. Re-run `{{pkgRun}} contract emit` if a new model's accessor isn't appearing on `db.orm`.
79
109
  - **Connection string** is `DATABASE_URL` in `.env`. If the user reports connection errors, check this value and the `.env` file.
110
+ - **Transactions and change streams** require a MongoDB **replica set**. The Mongo facade does not yet expose `db.transaction(...)` — for now, use the `mongoClient` escape hatch above to drive transactions/sessions directly. See the quick reference for dev-environment options; the typed transaction API is tracked under [TML-2313](https://linear.app/prisma-company/issue/TML-2313/mongo-dev-replica-set-story-is-missing-transactions-change-streams).
111
+ - **Don't reach for `db.runtime()`** as an escape hatch. It returns the internal executor (`MongoRuntime`), not a `mongodb` `MongoClient` or `Db`. Use `db.query` for raw aggregations and the `mongoClient` binding for direct driver control.
80
112
 
81
113
  ## Workflow for common tasks
82
114
 
83
115
  **User wants to add a new model or field:**
84
116
  1. Edit `{{schemaPath}}`
85
117
  2. Run `{{pkgRun}} contract emit`
86
- 3. Write query code using `db.orm.ModelName`
118
+ 3. Write query code using `db.orm.<collection>` (lowercased plural, see Rules above)
87
119
 
88
120
  **User wants to query data:**
89
121
  1. Import `db` from `{{dbImportPath}}`
90
- 2. Use `db.orm.ModelName` with `.where()`, `.select()`, `.all()`, `.first()`, etc.
122
+ 2. Use `db.orm.<collection>` with `.where()`, `.select()`, `.all()`, `.first()`, etc.
91
123
 
92
124
  **User wants to set up or change the database connection:**
93
125
  1. Edit `DATABASE_URL` in `.env`
@@ -4,7 +4,7 @@ This project uses **Prisma Next** with **PostgreSQL** via `@prisma-next/postgres
4
4
 
5
5
  ## Files
6
6
 
7
- - **Contract**: `{{schemaPath}}` — the user's data models. Edit this to add or change models.
7
+ - **Contract**: `{{schemaPath}}` ({{authoringLabel}} authoring) — the user's data models. Edit this to add or change models.
8
8
  - **Config**: `prisma-next.config.ts` — tells the CLI where the contract is and how to connect to the database. Loads `.env` via `dotenv/config`.
9
9
  - **Database client**: `{{schemaDir}}/db.ts` — `import { db } from '{{dbImportPath}}'`. This is the entry point for all queries.
10
10
  - **Generated files** (do not edit by hand):
@@ -0,0 +1,34 @@
1
+ import { CliStructuredError as CliStructuredError$1, 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, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
3
+ import "@prisma-next/errors/migration";
4
+
5
+ //#region src/utils/cli-errors.ts
6
+ /**
7
+ * Maps a `MigrationToolsError` raised by the migration-tools loader/graph
8
+ * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,
9
+ * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.
10
+ *
11
+ * The full `error.details` payload is forwarded into `meta` so machine
12
+ * consumers (`--json`) see structural fields like `dir`, `storedHash`,
13
+ * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable
14
+ * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.
15
+ *
16
+ * Callers are expected to gate on `MigrationToolsError.is(error)` first
17
+ * (mirroring the original inline pattern); non-`MigrationToolsError`
18
+ * values are caller-classified (rethrow, wrap with command-specific
19
+ * `errorUnexpected`, etc.).
20
+ */
21
+ function mapMigrationToolsError(error) {
22
+ return errorRuntime(error.message, {
23
+ why: error.why,
24
+ fix: error.fix,
25
+ meta: {
26
+ code: error.code,
27
+ ...error.details ?? {}
28
+ }
29
+ });
30
+ }
31
+
32
+ //#endregion
33
+ export { errorUnexpected$1 as _, errorContractValidationFailed as a, errorDriverRequired as c, errorMarkerMissing as d, errorMigrationPlanningFailed as f, errorTargetMismatch as g, errorTargetMigrationNotSupported as h, errorContractConfigMissing$1 as i, errorFileNotFound as l, errorRuntime$1 as m, ERROR_CODE_DESTRUCTIVE_CHANGES as n, errorDatabaseConnectionRequired as o, errorRunnerFailed as p, errorConfigValidation$1 as r, errorDestructiveChanges as s, CliStructuredError$1 as t, errorHashMismatch as u, mapMigrationToolsError as v };
34
+ //# sourceMappingURL=cli-errors-By1iVE3z.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-errors-By1iVE3z.mjs","names":[],"sources":["../src/utils/cli-errors.ts"],"sourcesContent":["/**\n * Re-export all domain error factories from @prisma-next/errors for convenience.\n * CLI-specific errors (e.g., Commander.js argument validation) can be added here if needed.\n */\nexport type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/errors/control';\n\nimport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorMigrationCliInvalidConfigArg,\n errorMigrationPlanningFailed,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { errorRuntime } from '@prisma-next/errors/execution';\nimport type { MigrationToolsError } from '@prisma-next/migration-tools/errors';\n\nexport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorMigrationCliInvalidConfigArg,\n errorMigrationPlanningFailed,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n};\nexport {\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorDestructiveChanges,\n errorHashMismatch,\n errorMarkerMissing,\n errorMarkerRequired,\n errorRunnerFailed,\n errorRuntime,\n errorSchemaVerificationFailed,\n errorTargetMismatch,\n} from '@prisma-next/errors/execution';\nexport {\n errorMigrationFileMissing,\n errorMigrationInvalidDefaultExport,\n errorMigrationPlanNotArray,\n errorUnfilledPlaceholder,\n placeholder,\n} from '@prisma-next/errors/migration';\n\n/**\n * Maps a `MigrationToolsError` raised by the migration-tools loader/graph\n * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,\n * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.\n *\n * The full `error.details` payload is forwarded into `meta` so machine\n * consumers (`--json`) see structural fields like `dir`, `storedHash`,\n * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable\n * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.\n *\n * Callers are expected to gate on `MigrationToolsError.is(error)` first\n * (mirroring the original inline pattern); non-`MigrationToolsError`\n * values are caller-classified (rethrow, wrap with command-specific\n * `errorUnexpected`, etc.).\n */\nexport function mapMigrationToolsError(error: MigrationToolsError): CliStructuredError {\n return errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code, ...(error.details ?? {}) },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB,uBAAuB,OAAgD;AACrF,QAAO,aAAa,MAAM,SAAS;EACjC,KAAK,MAAM;EACX,KAAK,MAAM;EACX,MAAM;GAAE,MAAM,MAAM;GAAM,GAAI,MAAM,WAAW,EAAE;GAAG;EACrD,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { CliStructuredError as CliStructuredError$1 } from "@prisma-next/errors/control";
2
2
  import "@prisma-next/errors/execution";
3
3
  import "@prisma-next/errors/migration";
4
+ import { MigrationToolsError } from "@prisma-next/migration-tools/errors";
4
5
  export { CliStructuredError$1 as t };
package/dist/cli.mjs CHANGED
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import "./config-loader-_W4T21X1.mjs";
4
- import { d as setCommandExamples, g as formatRootHelp, h as formatCommandHelp, m as parseGlobalFlags, u as setCommandDescriptions } from "./result-handler-CIyu0Pdt.mjs";
5
- import { t as createContractEmitCommand } from "./contract-emit-CNYyzJwF.mjs";
6
- import { n as installShutdownHandlers } from "./terminal-ui-C5k88MmW.mjs";
7
- import { t as createContractInferCommand } from "./contract-infer-BP3DrGgz.mjs";
3
+ import "./config-loader-C25b63rJ.mjs";
4
+ import "./cli-errors-By1iVE3z.mjs";
5
+ import "./framework-components-C6el-5x_.mjs";
6
+ import "./client-faKQqcix.mjs";
7
+ import { n as installShutdownHandlers } from "./terminal-ui-C3ZLwQxK.mjs";
8
+ import { d as setCommandExamples, g as formatRootHelp, h as formatCommandHelp, m as parseGlobalFlags, n as addGlobalOptions, u as setCommandDescriptions } from "./result-handler-CuhZ3kNu.mjs";
9
+ import { t as createContractEmitCommand } from "./contract-emit-Cf3fjDL6.mjs";
10
+ import { t as createContractInferCommand } from "./contract-infer-BgnsSkGp.mjs";
11
+ import "./inspect-live-schema-yCu0JT0I.mjs";
12
+ import "./migrations-CKRMAKka.mjs";
13
+ import "./migration-command-scaffold-B8HAEGhQ.mjs";
8
14
  import { createDbInitCommand } from "./commands/db-init.mjs";
15
+ import "./verify-Bkycc-Tf.mjs";
9
16
  import { createDbSchemaCommand } from "./commands/db-schema.mjs";
10
17
  import { createDbSignCommand } from "./commands/db-sign.mjs";
11
18
  import { createDbUpdateCommand } from "./commands/db-update.mjs";
@@ -15,20 +22,126 @@ import { createMigrationNewCommand } from "./commands/migration-new.mjs";
15
22
  import { createMigrationPlanCommand } from "./commands/migration-plan.mjs";
16
23
  import { createMigrationRefCommand } from "./commands/migration-ref.mjs";
17
24
  import { createMigrationShowCommand } from "./commands/migration-show.mjs";
18
- import { t as createMigrationStatusCommand } from "./migration-status-B0HLF7So.mjs";
25
+ import { t as createMigrationStatusCommand } from "./migration-status-8QUxCJHE.mjs";
19
26
  import { Command } from "commander";
20
27
  import { distance } from "closest-match";
21
28
 
29
+ //#region src/commands/init/exit-codes.ts
30
+ /**
31
+ * Stable exit codes for the `init` command.
32
+ *
33
+ * These are part of the command's public contract. AI agents and CI scripts
34
+ * branch on them (FR1.6), so the values must remain stable across versions.
35
+ *
36
+ * Codes 0–3 are the CLI-wide reserved values per the [CLI Style Guide
37
+ * Exit Codes section](../../../../../../../docs/CLI%20Style%20Guide.md#exit-codes):
38
+ * `OK = 0`, `INTERNAL_ERROR = 1`, `PRECONDITION = 2`, `USER_ABORTED = 3`.
39
+ * Codes 4 and 5 are command-specific outcomes for `init`'s two fallible
40
+ * side effects (install + emit). Documented in `--help` via
41
+ * `setCommandDescriptions` in `./index.ts`.
42
+ */
43
+ const INIT_EXIT_OK = 0;
44
+ /**
45
+ * Anything we did not anticipate — a bug in prisma-next, not something
46
+ * the caller did wrong. Includes the structured error code `5009`
47
+ * (invalid output document) and any unrecognised internal error code,
48
+ * so callers can distinguish "tool is broken" from "your invocation
49
+ * was wrong" (`PRECONDITION = 2`). Maps to the generic "RUN" error
50
+ * domain.
51
+ */
52
+ const INIT_EXIT_INTERNAL_ERROR = 1;
53
+ /**
54
+ * Preconditions not met. The caller asked for something we cannot do
55
+ * without more input or a different environment. Examples:
56
+ * - missing `package.json` / `deno.json`
57
+ * - non-interactive mode without enough flags to proceed
58
+ * - re-init without `--force` in non-interactive mode
59
+ */
60
+ const INIT_EXIT_PRECONDITION = 2;
61
+ /**
62
+ * The user actively aborted an interactive prompt (Ctrl-C, declined the
63
+ * re-init confirmation, etc.). Distinct from PRECONDITION because the user
64
+ * was given the choice and made it; no diagnostic is needed.
65
+ */
66
+ const INIT_EXIT_USER_ABORTED = 3;
67
+ /**
68
+ * Dependency installation step failed without a recoverable fallback.
69
+ * `init` automatically falls back from `pnpm` to `npm` on a recognised
70
+ * workspace/catalog leak (FR7.2); this code is returned only when the
71
+ * fallback also fails, or when the package manager is not pnpm and the
72
+ * single attempt failed. Files written before the install step (config,
73
+ * schema, db client, etc.) remain on disk so the user can fix the
74
+ * environment and re-run; the error envelope's `meta.filesWritten` lists
75
+ * them.
76
+ */
77
+ const INIT_EXIT_INSTALL_FAILED = 4;
78
+ /**
79
+ * Contract emit step failed after a successful install. Files written
80
+ * before emit (including any installed dependencies) are still on disk;
81
+ * the user can fix the underlying issue (typically a contract syntax
82
+ * error or a missing extension pack) and re-run `prisma-next contract
83
+ * emit` manually.
84
+ */
85
+ const INIT_EXIT_EMIT_FAILED = 5;
86
+
87
+ //#endregion
22
88
  //#region src/commands/init/index.ts
23
89
  function createInitCommand() {
24
90
  const command = new Command("init");
25
- setCommandDescriptions(command, "Initialize a new Prisma Next project", "Scaffolds config, schema, and runtime files, installs dependencies,\nand emits the contract. Gets you from zero to typed queries in one step.");
26
- setCommandExamples(command, ["prisma-next init", "prisma-next init --no-install"]);
27
- command.option("--no-install", "Skip dependency installation and contract emission").action(async (options) => {
28
- const { runInit } = await import("./init-CQfo_4Ro.mjs");
29
- await runInit(process.cwd(), { noInstall: !options.install });
91
+ setCommandDescriptions(command, "Initialize a new Prisma Next project", `Scaffolds config, schema, and runtime files, installs dependencies,
92
+ and emits the contract. Gets you from zero to typed queries in one step.
93
+
94
+ Run interactively for a guided experience, or supply --target / --authoring
95
+ and --yes for a fully scriptable run (CI, AI coding agents, automation).
96
+
97
+ Exit codes (see CLI Style Guide § Exit Codes):
98
+ ${INIT_EXIT_OK} OK Init succeeded.\n ${INIT_EXIT_INTERNAL_ERROR} INTERNAL_ERROR Unexpected bug in prisma-next (please report).\n ${INIT_EXIT_PRECONDITION} PRECONDITION Bad flags / missing prerequisite (e.g. no package.json).\n ${INIT_EXIT_USER_ABORTED} USER_ABORTED User cancelled an interactive prompt.\n ${INIT_EXIT_INSTALL_FAILED} INSTALL_FAILED Dependency installation failed (init-specific).\n ${INIT_EXIT_EMIT_FAILED} EMIT_FAILED \`contract emit\` failed after install (init-specific).`);
99
+ setCommandExamples(command, [
100
+ "prisma-next init",
101
+ "prisma-next init --yes --target postgres --authoring psl",
102
+ "prisma-next init --yes --target mongodb --authoring typescript --json",
103
+ "prisma-next init --yes --force --target postgres --authoring psl # overwrite an existing scaffold",
104
+ "prisma-next init --no-install # skip pnpm/npm install + emit"
105
+ ]);
106
+ return addGlobalOptions(command).option("--target <db>", "Database target: postgres or mongodb").option("--authoring <style>", "Schema authoring style: psl or typescript").option("--schema-path <path>", "Where to write the starter schema (default: prisma/contract.prisma)").option("--force", "Overwrite an existing scaffold without prompting").option("--write-env", "Write a .env file from .env.example (gitignored; default: only .env.example)").option("--probe-db", "Connect to DATABASE_URL once and check the server version against the target minimum (opt-in; off by default)").option("--strict-probe", "Treat a failed --probe-db as fatal (no-op without --probe-db; init is offline-by-default)").option("--no-install", "Skip dependency installation and contract emission").action(async (options) => {
107
+ const { runInit } = await import("./init-jf33mNQ6.mjs");
108
+ const flags = parseGlobalFlags(options);
109
+ const canPrompt = deriveCanPrompt({
110
+ flagsInteractive: flags.interactive,
111
+ optionInteractive: options.interactive,
112
+ stdinIsTTY: Boolean(process.stdin.isTTY)
113
+ });
114
+ const exitCode = await runInit(process.cwd(), {
115
+ options,
116
+ flags,
117
+ canPrompt
118
+ });
119
+ process.exit(exitCode);
30
120
  });
31
- return command;
121
+ }
122
+ /**
123
+ * Bridges the action handler's two TTY checks (stdout via `flags`, stdin
124
+ * via `process.stdin.isTTY`) into the `canPrompt` boolean `runInit`
125
+ * consumes.
126
+ *
127
+ * Per the [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity):
128
+ *
129
+ * - `flags.interactive` governs *decoration* (TerminalUI, intro/outro,
130
+ * spinners) and is derived from stdout-TTY by `parseGlobalFlags`,
131
+ * honouring `--interactive` / `--no-interactive`.
132
+ * - Prompting additionally requires a stdin TTY — closing stdin is a
133
+ * common signal in CI / agent environments even when stdout stays
134
+ * attached.
135
+ * - `--interactive` is the explicit override: when the user passes it,
136
+ * we honour it (e.g. testing flows where stdin is stubbed).
137
+ *
138
+ * Exported so callers and tests can derive the same value without
139
+ * touching `process` globals — F14 of the M1/M2 review.
140
+ */
141
+ function deriveCanPrompt(opts) {
142
+ if (opts.optionInteractive === true) return true;
143
+ if (opts.flagsInteractive === false) return false;
144
+ return opts.stdinIsTTY;
32
145
  }
33
146
 
34
147
  //#endregion
@@ -247,5 +360,5 @@ if (args.length > 0) {
247
360
  program.parse();
248
361
 
249
362
  //#endregion
250
- export { };
363
+ export { INIT_EXIT_PRECONDITION as a, INIT_EXIT_OK as i, INIT_EXIT_INSTALL_FAILED as n, INIT_EXIT_USER_ABORTED as o, INIT_EXIT_INTERNAL_ERROR as r, INIT_EXIT_EMIT_FAILED as t };
251
364
  //# sourceMappingURL=cli.mjs.map
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":[],"sources":["../src/commands/init/index.ts","../src/utils/suggest-command.ts","../src/cli.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { setCommandDescriptions, setCommandExamples } from '../../utils/command-helpers';\n\nexport function createInitCommand(): Command {\n const command = new Command('init');\n setCommandDescriptions(\n command,\n 'Initialize a new Prisma Next project',\n 'Scaffolds config, schema, and runtime files, installs dependencies,\\n' +\n 'and emits the contract. Gets you from zero to typed queries in one step.',\n );\n setCommandExamples(command, ['prisma-next init', 'prisma-next init --no-install']);\n command\n .option('--no-install', 'Skip dependency installation and contract emission')\n .action(async (options: { readonly install?: boolean }) => {\n const { runInit } = await import('./init');\n await runInit(process.cwd(), { noInstall: !options.install });\n });\n\n return command;\n}\n","import { distance } from 'closest-match';\n\n/**\n * Suggests similar command names for a mistyped input.\n *\n * Uses Levenshtein distance to find close matches. Only suggests commands\n * within a reasonable distance threshold (40% of the input length, minimum 2).\n * Returns up to 3 suggestions in case of ties.\n *\n * @returns Array of suggested command names (empty if nothing is close enough).\n */\nexport function suggestCommands(input: string, candidates: readonly string[]): string[] {\n if (candidates.length === 0) return [];\n\n // Threshold: at most 40% of the input length (min 2) to avoid absurd suggestions\n const maxDistance = Math.max(2, Math.ceil(input.length * 0.4));\n\n const scored = candidates\n .map((name) => ({ name, dist: distance(input, name) }))\n .filter((entry) => entry.dist <= maxDistance)\n .sort((a, b) => a.dist - b.dist);\n\n if (scored.length === 0) return [];\n\n // Take the best distance, then include ties (up to 3)\n const bestDist = scored[0]!.dist;\n return scored\n .filter((entry) => entry.dist === bestDist)\n .slice(0, 3)\n .map((entry) => entry.name);\n}\n","import { Command } from 'commander';\nimport { createContractEmitCommand } from './commands/contract-emit';\nimport { createContractInferCommand } from './commands/contract-infer';\nimport { createInitCommand } from './commands/init';\nimport { installShutdownHandlers } from './utils/shutdown';\n\n// Install SIGINT/SIGTERM handlers before anything else\ninstallShutdownHandlers();\n\nimport { createDbInitCommand } from './commands/db-init';\nimport { createDbSchemaCommand } from './commands/db-schema';\nimport { createDbSignCommand } from './commands/db-sign';\nimport { createDbUpdateCommand } from './commands/db-update';\nimport { createDbVerifyCommand } from './commands/db-verify';\nimport { createMigrationApplyCommand } from './commands/migration-apply';\nimport { createMigrationNewCommand } from './commands/migration-new';\nimport { createMigrationPlanCommand } from './commands/migration-plan';\nimport { createMigrationRefCommand } from './commands/migration-ref';\nimport { createMigrationShowCommand } from './commands/migration-show';\nimport { createMigrationStatusCommand } from './commands/migration-status';\nimport { setCommandDescriptions } from './utils/command-helpers';\nimport { formatCommandHelp, formatRootHelp } from './utils/formatters/help';\nimport { parseGlobalFlags } from './utils/global-flags';\nimport { suggestCommands } from './utils/suggest-command';\n\n/**\n * Formats the \"Did you mean ...?\" hint for an unknown command.\n */\nfunction formatSuggestion(input: string, candidates: readonly string[]): string {\n const suggestions = suggestCommands(\n input,\n candidates.map((c) => c),\n );\n if (suggestions.length === 0) return '';\n if (suggestions.length === 1) return `\\nDid you mean ${suggestions[0]}?\\n`;\n return `\\nDid you mean one of these?\\n${suggestions.map((s) => ` ${s}`).join('\\n')}\\n`;\n}\n\nconst program = new Command();\n\nprogram.name('prisma-next').description('Prisma Next CLI').version('0.0.1');\n\n// Override version option description to match capitalization style\nconst versionOption = program.options.find((opt) => opt.flags.includes('--version'));\nif (versionOption) {\n versionOption.description = 'Output the version number';\n}\n\nprogram.configureOutput({\n writeErr: () => {\n // Suppress all default error output - we handle errors in exitOverride\n },\n writeOut: () => {\n // Suppress all default output - our custom formatters handle everything\n },\n});\n\n// Customize root help output to use our styled format\nconst rootHelpFormatter = (cmd: Command) => {\n const flags = parseGlobalFlags({});\n return formatRootHelp({ program: cmd, flags });\n};\n\nprogram.configureHelp({\n formatHelp: rootHelpFormatter,\n subcommandDescription: () => '',\n});\n\n// Override exit to handle unhandled errors (fail fast cases)\n// Commands handle structured errors themselves via process.exit()\nprogram.exitOverride((err) => {\n if (err) {\n const errorCode = (err as { code?: string }).code;\n const errorMessage = String(err.message ?? '');\n const errorName = err.name ?? '';\n\n // Unknown command/argument → exit 2 (CLI usage error)\n const isUnknownCommandError =\n errorCode === 'commander.unknownCommand' ||\n errorCode === 'commander.unknownArgument' ||\n (errorName === 'CommanderError' &&\n (errorMessage.includes('unknown command') || errorMessage.includes('unknown argument')));\n if (isUnknownCommandError) {\n const flags = parseGlobalFlags({});\n const match = errorMessage.match(/unknown command ['\"]([^'\"]+)['\"]/);\n const commandName = match ? match[1] : process.argv[3] || process.argv[2] || 'unknown';\n\n const firstArg = process.argv[2];\n const parentCommand = firstArg\n ? program.commands.find((cmd) => cmd.name() === firstArg)\n : undefined;\n\n if (parentCommand && commandName !== firstArg) {\n const subNames = parentCommand.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, subNames)}\\n`,\n );\n const helpText = formatCommandHelp({ command: parentCommand, flags });\n process.stderr.write(`${helpText}\\n`);\n } else {\n const topNames = program.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\\n`,\n );\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n }\n process.exit(2);\n return;\n }\n\n // Help requests → exit 0\n const isHelpError =\n errorCode === 'commander.help' ||\n errorCode === 'commander.helpDisplayed' ||\n errorCode === 'outputHelp' ||\n errorMessage === '(outputHelp)' ||\n errorMessage.includes('outputHelp') ||\n (errorName === 'CommanderError' && errorMessage.includes('outputHelp'));\n if (isHelpError) {\n process.exit(0);\n return;\n }\n\n // Missing required arguments → exit 2 (CLI usage error)\n const isMissingArgumentError =\n errorCode === 'commander.missingArgument' ||\n errorCode === 'commander.missingMandatoryOptionValue' ||\n (errorName === 'CommanderError' &&\n (errorMessage.includes('missing') || errorMessage.includes('required')));\n if (isMissingArgumentError) {\n process.exit(2);\n return;\n }\n\n // Unhandled error → exit 1\n process.stderr.write(`Unhandled error: ${err.message}\\n`);\n if (err.stack) {\n process.stderr.write(`${err.stack}\\n`);\n }\n process.exit(1);\n }\n process.exit(0);\n});\n\n// Register contract subcommand\nconst contractCommand = new Command('contract');\nsetCommandDescriptions(\n contractCommand,\n 'Contract management commands',\n 'Define and emit your application data contract. The contract describes your schema as a\\n' +\n 'declarative data structure that can be signed and verified against your database.',\n);\ncontractCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\n// Add emit subcommand to contract\nconst contractEmitCommand = createContractEmitCommand();\ncontractCommand.addCommand(contractEmitCommand);\n\n// Add infer subcommand to contract\nconst contractInferCommand = createContractInferCommand();\ncontractCommand.addCommand(contractInferCommand);\n\n// Register contract command\nprogram.addCommand(contractCommand);\n\n// Register db subcommand\nconst dbCommand = new Command('db');\nsetCommandDescriptions(\n dbCommand,\n 'Database management commands',\n 'Verify and sign your database with your contract. Ensure your database schema matches\\n' +\n 'your contract, and sign it to record the contract hash for future verification.',\n);\ndbCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\n// Add verify subcommand to db\nconst dbVerifyCommand = createDbVerifyCommand();\ndbCommand.addCommand(dbVerifyCommand);\n\n// Add init subcommand to db\nconst dbInitCommand = createDbInitCommand();\ndbCommand.addCommand(dbInitCommand);\n\n// Add update subcommand to db\nconst dbUpdateCommand = createDbUpdateCommand();\ndbCommand.addCommand(dbUpdateCommand);\n\n// Add schema subcommand to db\nconst dbSchemaCommand = createDbSchemaCommand();\ndbCommand.addCommand(dbSchemaCommand);\n\n// Add sign subcommand to db\nconst dbSignCommand = createDbSignCommand();\ndbCommand.addCommand(dbSignCommand);\n\n// Register db command\nprogram.addCommand(dbCommand);\n\n// Register migration subcommand\nconst migrationCommand = new Command('migration');\nsetCommandDescriptions(\n migrationCommand,\n 'On-disk migration management commands',\n 'Plan, apply, and scaffold on-disk migration packages. Migrations are\\n' +\n 'contract-to-contract edges stored as versioned directories under migrations/.',\n);\nmigrationCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\nconst migrationPlanCommand = createMigrationPlanCommand();\nmigrationCommand.addCommand(migrationPlanCommand);\n\nconst migrationNewCommand = createMigrationNewCommand();\nmigrationCommand.addCommand(migrationNewCommand);\n\nconst migrationShowCommand = createMigrationShowCommand();\nmigrationCommand.addCommand(migrationShowCommand);\n\nconst migrationStatusCommand = createMigrationStatusCommand();\nmigrationCommand.addCommand(migrationStatusCommand);\n\nconst migrationApplyCommand = createMigrationApplyCommand();\nmigrationCommand.addCommand(migrationApplyCommand);\n\nconst migrationRefCommand = createMigrationRefCommand();\nmigrationCommand.addCommand(migrationRefCommand);\n\nprogram.addCommand(migrationCommand);\n\n// Register init command (top-level, not nested)\nconst initCommand = createInitCommand();\nprogram.addCommand(initCommand);\n\n// Create help command\nconst helpCommand = new Command('help')\n .description('Show usage instructions')\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .action(() => {\n const flags = parseGlobalFlags({});\n const helpText = formatRootHelp({ program, flags });\n // Help is decoration → stderr\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n });\n\nprogram.addCommand(helpCommand);\n\n// Set help as the default action when no command is provided\nprogram.action(() => {\n const flags = parseGlobalFlags({});\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n});\n\n// Check if a command was invoked with no arguments (just the command name)\n// or if an unrecognized command was provided\nconst args = process.argv.slice(2);\nif (args.length > 0) {\n const commandName = args[0];\n // Handle version option explicitly since we suppress default output\n if (commandName === '--version' || commandName === '-V') {\n // Version is data → stdout\n process.stdout.write(`${program.version()}\\n`);\n process.exit(0);\n }\n // Skip command check for global options like --help, -h\n const isGlobalOption = commandName === '--help' || commandName === '-h';\n if (!isGlobalOption) {\n // Check if this is a recognized command\n const command = program.commands.find((cmd) => cmd.name() === commandName);\n\n if (!command) {\n // Unrecognized command → exit 2 (CLI usage error)\n const flags = parseGlobalFlags({});\n const topNames = program.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\\n`,\n );\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(2);\n } else if (command.commands.length > 0 && args.length === 1) {\n // Parent command called with no subcommand - show help and exit with 0\n const flags = parseGlobalFlags({});\n const helpText = formatCommandHelp({ command, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n }\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,oBAA6B;CAC3C,MAAM,UAAU,IAAI,QAAQ,OAAO;AACnC,wBACE,SACA,wCACA,gJAED;AACD,oBAAmB,SAAS,CAAC,oBAAoB,gCAAgC,CAAC;AAClF,SACG,OAAO,gBAAgB,qDAAqD,CAC5E,OAAO,OAAO,YAA4C;EACzD,MAAM,EAAE,YAAY,MAAM,OAAO;AACjC,QAAM,QAAQ,QAAQ,KAAK,EAAE,EAAE,WAAW,CAAC,QAAQ,SAAS,CAAC;GAC7D;AAEJ,QAAO;;;;;;;;;;;;;;ACRT,SAAgB,gBAAgB,OAAe,YAAyC;AACtF,KAAI,WAAW,WAAW,EAAG,QAAO,EAAE;CAGtC,MAAM,cAAc,KAAK,IAAI,GAAG,KAAK,KAAK,MAAM,SAAS,GAAI,CA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gB,YAAY,gBAAgB,OAC9C;EAEnB,MAAM,UAAU,QAAQ,SAAS,MAAM,QAAQ,IAAI,MAAM,KAAK,YAAY;AAE1E,MAAI,CAAC,SAAS;GAEZ,MAAM,QAAQ,iBAAiB,EAAE,CAAC;GAClC,MAAM,WAAW,QAAQ,SAAS,KAAK,MAAM,EAAE,MAAM,CAAC;AACtD,WAAQ,OAAO,MACb,oBAAoB,cAAc,iBAAiB,aAAc,SAAS,CAAC,IAC5E;GACD,MAAM,WAAW,eAAe;IAAE;IAAS;IAAO,CAAC;AACnD,WAAQ,OAAO,MAAM,GAAG,SAAS,IAAI;AACrC,WAAQ,KAAK,EAAE;aACN,QAAQ,SAAS,SAAS,KAAK,KAAK,WAAW,GAAG;GAG3D,MAAM,WAAW,kBAAkB;IAAE;IAAS,OADhC,iBAAiB,EAAE,CAAC;IACmB,CAAC;AACtD,WAAQ,OAAO,MAAM,GAAG,SAAS,IAAI;AACrC,WAAQ,KAAK,EAAE;;;;AAKrB,QAAQ,OAAO"}
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/commands/init/exit-codes.ts","../src/commands/init/index.ts","../src/utils/suggest-command.ts","../src/cli.ts"],"sourcesContent":["/**\n * Stable exit codes for the `init` command.\n *\n * These are part of the command's public contract. AI agents and CI scripts\n * branch on them (FR1.6), so the values must remain stable across versions.\n *\n * Codes 0–3 are the CLI-wide reserved values per the [CLI Style Guide\n * Exit Codes section](../../../../../../../docs/CLI%20Style%20Guide.md#exit-codes):\n * `OK = 0`, `INTERNAL_ERROR = 1`, `PRECONDITION = 2`, `USER_ABORTED = 3`.\n * Codes 4 and 5 are command-specific outcomes for `init`'s two fallible\n * side effects (install + emit). Documented in `--help` via\n * `setCommandDescriptions` in `./index.ts`.\n */\n\nexport const INIT_EXIT_OK = 0;\n\n/**\n * Anything we did not anticipate — a bug in prisma-next, not something\n * the caller did wrong. Includes the structured error code `5009`\n * (invalid output document) and any unrecognised internal error code,\n * so callers can distinguish \"tool is broken\" from \"your invocation\n * was wrong\" (`PRECONDITION = 2`). Maps to the generic \"RUN\" error\n * domain.\n */\nexport const INIT_EXIT_INTERNAL_ERROR = 1;\n\n/**\n * Preconditions not met. The caller asked for something we cannot do\n * without more input or a different environment. Examples:\n * - missing `package.json` / `deno.json`\n * - non-interactive mode without enough flags to proceed\n * - re-init without `--force` in non-interactive mode\n */\nexport const INIT_EXIT_PRECONDITION = 2;\n\n/**\n * The user actively aborted an interactive prompt (Ctrl-C, declined the\n * re-init confirmation, etc.). Distinct from PRECONDITION because the user\n * was given the choice and made it; no diagnostic is needed.\n */\nexport const INIT_EXIT_USER_ABORTED = 3;\n\n/**\n * Dependency installation step failed without a recoverable fallback.\n * `init` automatically falls back from `pnpm` to `npm` on a recognised\n * workspace/catalog leak (FR7.2); this code is returned only when the\n * fallback also fails, or when the package manager is not pnpm and the\n * single attempt failed. Files written before the install step (config,\n * schema, db client, etc.) remain on disk so the user can fix the\n * environment and re-run; the error envelope's `meta.filesWritten` lists\n * them.\n */\nexport const INIT_EXIT_INSTALL_FAILED = 4;\n\n/**\n * Contract emit step failed after a successful install. Files written\n * before emit (including any installed dependencies) are still on disk;\n * the user can fix the underlying issue (typically a contract syntax\n * error or a missing extension pack) and re-run `prisma-next contract\n * emit` manually.\n */\nexport const INIT_EXIT_EMIT_FAILED = 5;\n","import { Command } from 'commander';\nimport {\n addGlobalOptions,\n setCommandDescriptions,\n setCommandExamples,\n} from '../../utils/command-helpers';\nimport { type CommonCommandOptions, parseGlobalFlags } from '../../utils/global-flags';\nimport {\n INIT_EXIT_EMIT_FAILED,\n INIT_EXIT_INSTALL_FAILED,\n INIT_EXIT_INTERNAL_ERROR,\n INIT_EXIT_OK,\n INIT_EXIT_PRECONDITION,\n INIT_EXIT_USER_ABORTED,\n} from './exit-codes';\n\n/**\n * Commander.js parsed options for `init`. The init-specific options live\n * alongside the inherited `CommonCommandOptions` global flags.\n *\n * `target` and `authoring` are typed as plain `string` here because\n * Commander.js does not enforce enums at parse time — the validation /\n * normalisation happens in `inputs.ts::resolveInitInputs`, which can\n * raise a structured `errorInitInvalidFlagValue` with the full set of\n * allowed values.\n */\ninterface InitCommandOptions extends CommonCommandOptions {\n readonly target?: string;\n readonly authoring?: string;\n readonly schemaPath?: string;\n readonly force?: boolean;\n readonly writeEnv?: boolean;\n readonly probeDb?: boolean;\n readonly strictProbe?: boolean;\n readonly install?: boolean;\n}\n\nexport function createInitCommand(): Command {\n const command = new Command('init');\n setCommandDescriptions(\n command,\n 'Initialize a new Prisma Next project',\n 'Scaffolds config, schema, and runtime files, installs dependencies,\\n' +\n 'and emits the contract. Gets you from zero to typed queries in one step.\\n' +\n '\\n' +\n 'Run interactively for a guided experience, or supply --target / --authoring\\n' +\n 'and --yes for a fully scriptable run (CI, AI coding agents, automation).\\n' +\n '\\n' +\n 'Exit codes (see CLI Style Guide § Exit Codes):\\n' +\n ` ${INIT_EXIT_OK} OK Init succeeded.\\n` +\n ` ${INIT_EXIT_INTERNAL_ERROR} INTERNAL_ERROR Unexpected bug in prisma-next (please report).\\n` +\n ` ${INIT_EXIT_PRECONDITION} PRECONDITION Bad flags / missing prerequisite (e.g. no package.json).\\n` +\n ` ${INIT_EXIT_USER_ABORTED} USER_ABORTED User cancelled an interactive prompt.\\n` +\n ` ${INIT_EXIT_INSTALL_FAILED} INSTALL_FAILED Dependency installation failed (init-specific).\\n` +\n ` ${INIT_EXIT_EMIT_FAILED} EMIT_FAILED \\`contract emit\\` failed after install (init-specific).`,\n );\n setCommandExamples(command, [\n 'prisma-next init',\n 'prisma-next init --yes --target postgres --authoring psl',\n 'prisma-next init --yes --target mongodb --authoring typescript --json',\n 'prisma-next init --yes --force --target postgres --authoring psl # overwrite an existing scaffold',\n 'prisma-next init --no-install # skip pnpm/npm install + emit',\n ]);\n\n return addGlobalOptions(command)\n .option('--target <db>', 'Database target: postgres or mongodb')\n .option('--authoring <style>', 'Schema authoring style: psl or typescript')\n .option(\n '--schema-path <path>',\n 'Where to write the starter schema (default: prisma/contract.prisma)',\n )\n .option('--force', 'Overwrite an existing scaffold without prompting')\n .option(\n '--write-env',\n 'Write a .env file from .env.example (gitignored; default: only .env.example)',\n )\n .option(\n '--probe-db',\n 'Connect to DATABASE_URL once and check the server version against the target minimum (opt-in; off by default)',\n )\n .option(\n '--strict-probe',\n 'Treat a failed --probe-db as fatal (no-op without --probe-db; init is offline-by-default)',\n )\n .option('--no-install', 'Skip dependency installation and contract emission')\n .action(async (options: InitCommandOptions) => {\n const { runInit } = await import('./init');\n const flags = parseGlobalFlags(options);\n const canPrompt = deriveCanPrompt({\n flagsInteractive: flags.interactive,\n optionInteractive: options.interactive,\n stdinIsTTY: Boolean(process.stdin.isTTY),\n });\n const exitCode = await runInit(process.cwd(), { options, flags, canPrompt });\n process.exit(exitCode);\n });\n}\n\n/**\n * Bridges the action handler's two TTY checks (stdout via `flags`, stdin\n * via `process.stdin.isTTY`) into the `canPrompt` boolean `runInit`\n * consumes.\n *\n * Per the [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity):\n *\n * - `flags.interactive` governs *decoration* (TerminalUI, intro/outro,\n * spinners) and is derived from stdout-TTY by `parseGlobalFlags`,\n * honouring `--interactive` / `--no-interactive`.\n * - Prompting additionally requires a stdin TTY — closing stdin is a\n * common signal in CI / agent environments even when stdout stays\n * attached.\n * - `--interactive` is the explicit override: when the user passes it,\n * we honour it (e.g. testing flows where stdin is stubbed).\n *\n * Exported so callers and tests can derive the same value without\n * touching `process` globals — F14 of the M1/M2 review.\n */\nexport function deriveCanPrompt(opts: {\n readonly flagsInteractive: boolean | undefined;\n readonly optionInteractive: boolean | undefined;\n readonly stdinIsTTY: boolean;\n}): boolean {\n if (opts.optionInteractive === true) return true;\n if (opts.flagsInteractive === false) return false;\n return opts.stdinIsTTY;\n}\n","import { distance } from 'closest-match';\n\n/**\n * Suggests similar command names for a mistyped input.\n *\n * Uses Levenshtein distance to find close matches. Only suggests commands\n * within a reasonable distance threshold (40% of the input length, minimum 2).\n * Returns up to 3 suggestions in case of ties.\n *\n * @returns Array of suggested command names (empty if nothing is close enough).\n */\nexport function suggestCommands(input: string, candidates: readonly string[]): string[] {\n if (candidates.length === 0) return [];\n\n // Threshold: at most 40% of the input length (min 2) to avoid absurd suggestions\n const maxDistance = Math.max(2, Math.ceil(input.length * 0.4));\n\n const scored = candidates\n .map((name) => ({ name, dist: distance(input, name) }))\n .filter((entry) => entry.dist <= maxDistance)\n .sort((a, b) => a.dist - b.dist);\n\n if (scored.length === 0) return [];\n\n // Take the best distance, then include ties (up to 3)\n const bestDist = scored[0]!.dist;\n return scored\n .filter((entry) => entry.dist === bestDist)\n .slice(0, 3)\n .map((entry) => entry.name);\n}\n","import { Command } from 'commander';\nimport { createContractEmitCommand } from './commands/contract-emit';\nimport { createContractInferCommand } from './commands/contract-infer';\nimport { createInitCommand } from './commands/init';\nimport { installShutdownHandlers } from './utils/shutdown';\n\n// Install SIGINT/SIGTERM handlers before anything else\ninstallShutdownHandlers();\n\nimport { createDbInitCommand } from './commands/db-init';\nimport { createDbSchemaCommand } from './commands/db-schema';\nimport { createDbSignCommand } from './commands/db-sign';\nimport { createDbUpdateCommand } from './commands/db-update';\nimport { createDbVerifyCommand } from './commands/db-verify';\nimport { createMigrationApplyCommand } from './commands/migration-apply';\nimport { createMigrationNewCommand } from './commands/migration-new';\nimport { createMigrationPlanCommand } from './commands/migration-plan';\nimport { createMigrationRefCommand } from './commands/migration-ref';\nimport { createMigrationShowCommand } from './commands/migration-show';\nimport { createMigrationStatusCommand } from './commands/migration-status';\nimport { setCommandDescriptions } from './utils/command-helpers';\nimport { formatCommandHelp, formatRootHelp } from './utils/formatters/help';\nimport { parseGlobalFlags } from './utils/global-flags';\nimport { suggestCommands } from './utils/suggest-command';\n\n/**\n * Formats the \"Did you mean ...?\" hint for an unknown command.\n */\nfunction formatSuggestion(input: string, candidates: readonly string[]): string {\n const suggestions = suggestCommands(\n input,\n candidates.map((c) => c),\n );\n if (suggestions.length === 0) return '';\n if (suggestions.length === 1) return `\\nDid you mean ${suggestions[0]}?\\n`;\n return `\\nDid you mean one of these?\\n${suggestions.map((s) => ` ${s}`).join('\\n')}\\n`;\n}\n\nconst program = new Command();\n\nprogram.name('prisma-next').description('Prisma Next CLI').version('0.0.1');\n\n// Override version option description to match capitalization style\nconst versionOption = program.options.find((opt) => opt.flags.includes('--version'));\nif (versionOption) {\n versionOption.description = 'Output the version number';\n}\n\nprogram.configureOutput({\n writeErr: () => {\n // Suppress all default error output - we handle errors in exitOverride\n },\n writeOut: () => {\n // Suppress all default output - our custom formatters handle everything\n },\n});\n\n// Customize root help output to use our styled format\nconst rootHelpFormatter = (cmd: Command) => {\n const flags = parseGlobalFlags({});\n return formatRootHelp({ program: cmd, flags });\n};\n\nprogram.configureHelp({\n formatHelp: rootHelpFormatter,\n subcommandDescription: () => '',\n});\n\n// Override exit to handle unhandled errors (fail fast cases)\n// Commands handle structured errors themselves via process.exit()\nprogram.exitOverride((err) => {\n if (err) {\n const errorCode = (err as { code?: string }).code;\n const errorMessage = String(err.message ?? '');\n const errorName = err.name ?? '';\n\n // Unknown command/argument → exit 2 (CLI usage error)\n const isUnknownCommandError =\n errorCode === 'commander.unknownCommand' ||\n errorCode === 'commander.unknownArgument' ||\n (errorName === 'CommanderError' &&\n (errorMessage.includes('unknown command') || errorMessage.includes('unknown argument')));\n if (isUnknownCommandError) {\n const flags = parseGlobalFlags({});\n const match = errorMessage.match(/unknown command ['\"]([^'\"]+)['\"]/);\n const commandName = match ? match[1] : process.argv[3] || process.argv[2] || 'unknown';\n\n const firstArg = process.argv[2];\n const parentCommand = firstArg\n ? program.commands.find((cmd) => cmd.name() === firstArg)\n : undefined;\n\n if (parentCommand && commandName !== firstArg) {\n const subNames = parentCommand.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, subNames)}\\n`,\n );\n const helpText = formatCommandHelp({ command: parentCommand, flags });\n process.stderr.write(`${helpText}\\n`);\n } else {\n const topNames = program.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\\n`,\n );\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n }\n process.exit(2);\n return;\n }\n\n // Help requests → exit 0\n const isHelpError =\n errorCode === 'commander.help' ||\n errorCode === 'commander.helpDisplayed' ||\n errorCode === 'outputHelp' ||\n errorMessage === '(outputHelp)' ||\n errorMessage.includes('outputHelp') ||\n (errorName === 'CommanderError' && errorMessage.includes('outputHelp'));\n if (isHelpError) {\n process.exit(0);\n return;\n }\n\n // Missing required arguments → exit 2 (CLI usage error)\n const isMissingArgumentError =\n errorCode === 'commander.missingArgument' ||\n errorCode === 'commander.missingMandatoryOptionValue' ||\n (errorName === 'CommanderError' &&\n (errorMessage.includes('missing') || errorMessage.includes('required')));\n if (isMissingArgumentError) {\n process.exit(2);\n return;\n }\n\n // Unhandled error → exit 1\n process.stderr.write(`Unhandled error: ${err.message}\\n`);\n if (err.stack) {\n process.stderr.write(`${err.stack}\\n`);\n }\n process.exit(1);\n }\n process.exit(0);\n});\n\n// Register contract subcommand\nconst contractCommand = new Command('contract');\nsetCommandDescriptions(\n contractCommand,\n 'Contract management commands',\n 'Define and emit your application data contract. The contract describes your schema as a\\n' +\n 'declarative data structure that can be signed and verified against your database.',\n);\ncontractCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\n// Add emit subcommand to contract\nconst contractEmitCommand = createContractEmitCommand();\ncontractCommand.addCommand(contractEmitCommand);\n\n// Add infer subcommand to contract\nconst contractInferCommand = createContractInferCommand();\ncontractCommand.addCommand(contractInferCommand);\n\n// Register contract command\nprogram.addCommand(contractCommand);\n\n// Register db subcommand\nconst dbCommand = new Command('db');\nsetCommandDescriptions(\n dbCommand,\n 'Database management commands',\n 'Verify and sign your database with your contract. Ensure your database schema matches\\n' +\n 'your contract, and sign it to record the contract hash for future verification.',\n);\ndbCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\n// Add verify subcommand to db\nconst dbVerifyCommand = createDbVerifyCommand();\ndbCommand.addCommand(dbVerifyCommand);\n\n// Add init subcommand to db\nconst dbInitCommand = createDbInitCommand();\ndbCommand.addCommand(dbInitCommand);\n\n// Add update subcommand to db\nconst dbUpdateCommand = createDbUpdateCommand();\ndbCommand.addCommand(dbUpdateCommand);\n\n// Add schema subcommand to db\nconst dbSchemaCommand = createDbSchemaCommand();\ndbCommand.addCommand(dbSchemaCommand);\n\n// Add sign subcommand to db\nconst dbSignCommand = createDbSignCommand();\ndbCommand.addCommand(dbSignCommand);\n\n// Register db command\nprogram.addCommand(dbCommand);\n\n// Register migration subcommand\nconst migrationCommand = new Command('migration');\nsetCommandDescriptions(\n migrationCommand,\n 'On-disk migration management commands',\n 'Plan, apply, and scaffold on-disk migration packages. Migrations are\\n' +\n 'contract-to-contract edges stored as versioned directories under migrations/.',\n);\nmigrationCommand.configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n subcommandDescription: () => '',\n});\n\nconst migrationPlanCommand = createMigrationPlanCommand();\nmigrationCommand.addCommand(migrationPlanCommand);\n\nconst migrationNewCommand = createMigrationNewCommand();\nmigrationCommand.addCommand(migrationNewCommand);\n\nconst migrationShowCommand = createMigrationShowCommand();\nmigrationCommand.addCommand(migrationShowCommand);\n\nconst migrationStatusCommand = createMigrationStatusCommand();\nmigrationCommand.addCommand(migrationStatusCommand);\n\nconst migrationApplyCommand = createMigrationApplyCommand();\nmigrationCommand.addCommand(migrationApplyCommand);\n\nconst migrationRefCommand = createMigrationRefCommand();\nmigrationCommand.addCommand(migrationRefCommand);\n\nprogram.addCommand(migrationCommand);\n\n// Register init command (top-level, not nested)\nconst initCommand = createInitCommand();\nprogram.addCommand(initCommand);\n\n// Create help command\nconst helpCommand = new Command('help')\n .description('Show usage instructions')\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .action(() => {\n const flags = parseGlobalFlags({});\n const helpText = formatRootHelp({ program, flags });\n // Help is decoration → stderr\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n });\n\nprogram.addCommand(helpCommand);\n\n// Set help as the default action when no command is provided\nprogram.action(() => {\n const flags = parseGlobalFlags({});\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n});\n\n// Check if a command was invoked with no arguments (just the command name)\n// or if an unrecognized command was provided\nconst args = process.argv.slice(2);\nif (args.length > 0) {\n const commandName = args[0];\n // Handle version option explicitly since we suppress default output\n if (commandName === '--version' || commandName === '-V') {\n // Version is data → stdout\n process.stdout.write(`${program.version()}\\n`);\n process.exit(0);\n }\n // Skip command check for global options like --help, -h\n const isGlobalOption = commandName === '--help' || commandName === '-h';\n if (!isGlobalOption) {\n // Check if this is a recognized command\n const command = program.commands.find((cmd) => cmd.name() === commandName);\n\n if (!command) {\n // Unrecognized command → exit 2 (CLI usage error)\n const flags = parseGlobalFlags({});\n const topNames = program.commands.map((c) => c.name());\n process.stderr.write(\n `Unknown command: ${commandName}${formatSuggestion(commandName!, topNames)}\\n`,\n );\n const helpText = formatRootHelp({ program, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(2);\n } else if (command.commands.length > 0 && args.length === 1) {\n // Parent command called with no subcommand - show help and exit with 0\n const flags = parseGlobalFlags({});\n const helpText = formatCommandHelp({ command, flags });\n process.stderr.write(`${helpText}\\n`);\n process.exit(0);\n }\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAa,eAAe;;;;;;;;;AAU5B,MAAa,2BAA2B;;;;;;;;AASxC,MAAa,yBAAyB;;;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