@prisma-next/cli 0.5.0-dev.3 → 0.5.0-dev.5

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 (107) hide show
  1. package/dist/agent-skill-mongo.md +63 -31
  2. package/dist/agent-skill-postgres.md +1 -1
  3. package/dist/cli.mjs +119 -13
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/{client-TG7rbCWT.mjs → client-CrsnY58k.mjs} +4 -4
  6. package/dist/{client-TG7rbCWT.mjs.map → client-CrsnY58k.mjs.map} +1 -1
  7. package/dist/commands/contract-emit.mjs +2 -2
  8. package/dist/commands/contract-infer.mjs +2 -2
  9. package/dist/commands/db-init.mjs +7 -7
  10. package/dist/commands/db-schema.mjs +5 -5
  11. package/dist/commands/db-sign.mjs +7 -7
  12. package/dist/commands/db-update.mjs +7 -7
  13. package/dist/commands/db-verify.mjs +7 -7
  14. package/dist/commands/migration-apply.mjs +8 -8
  15. package/dist/commands/migration-apply.mjs.map +1 -1
  16. package/dist/commands/migration-new.mjs +5 -5
  17. package/dist/commands/migration-plan.mjs +6 -6
  18. package/dist/commands/migration-ref.d.mts +6 -4
  19. package/dist/commands/migration-ref.d.mts.map +1 -1
  20. package/dist/commands/migration-ref.mjs +29 -34
  21. package/dist/commands/migration-ref.mjs.map +1 -1
  22. package/dist/commands/migration-show.d.mts +1 -1
  23. package/dist/commands/migration-show.mjs +6 -6
  24. package/dist/commands/migration-status.d.mts.map +1 -1
  25. package/dist/commands/migration-status.mjs +2 -2
  26. package/dist/{config-loader-_W4T21X1.mjs → config-loader-C25b63rJ.mjs} +1 -1
  27. package/dist/{config-loader-_W4T21X1.mjs.map → config-loader-C25b63rJ.mjs.map} +1 -1
  28. package/dist/config-loader.mjs +1 -1
  29. package/dist/contract-emit--feXyNd7.mjs +4 -0
  30. package/dist/{contract-emit-CNYyzJwF.mjs → contract-emit-NJ01hiiv.mjs} +8 -8
  31. package/dist/{contract-emit-CNYyzJwF.mjs.map → contract-emit-NJ01hiiv.mjs.map} +1 -1
  32. package/dist/{contract-emit-CQfj7xJn.mjs → contract-emit-V5SSitUT.mjs} +6 -6
  33. package/dist/{contract-emit-CQfj7xJn.mjs.map → contract-emit-V5SSitUT.mjs.map} +1 -1
  34. package/dist/{contract-enrichment-CGW6mm-E.mjs → contract-enrichment-CAOELa-H.mjs} +1 -1
  35. package/dist/{contract-enrichment-CGW6mm-E.mjs.map → contract-enrichment-CAOELa-H.mjs.map} +1 -1
  36. package/dist/{contract-infer-BP3DrGgz.mjs → contract-infer-D9cC3rJm.mjs} +4 -4
  37. package/dist/{contract-infer-BP3DrGgz.mjs.map → contract-infer-D9cC3rJm.mjs.map} +1 -1
  38. package/dist/exports/control-api.mjs +4 -4
  39. package/dist/exports/index.mjs +2 -2
  40. package/dist/exports/init-output.d.mts +39 -0
  41. package/dist/exports/init-output.d.mts.map +1 -0
  42. package/dist/exports/init-output.mjs +3 -0
  43. package/dist/{extract-operation-statements-DZUJNmL3.mjs → extract-operation-statements-DsFfxXVZ.mjs} +2 -2
  44. package/dist/{extract-operation-statements-DZUJNmL3.mjs.map → extract-operation-statements-DsFfxXVZ.mjs.map} +1 -1
  45. package/dist/{extract-sql-ddl-DDMX-9mz.mjs → extract-sql-ddl-D9UbZDyz.mjs} +1 -1
  46. package/dist/{extract-sql-ddl-DDMX-9mz.mjs.map → extract-sql-ddl-D9UbZDyz.mjs.map} +1 -1
  47. package/dist/{framework-components-DfZKQBQ2.mjs → framework-components-Cr--XBKy.mjs} +2 -2
  48. package/dist/{framework-components-DfZKQBQ2.mjs.map → framework-components-Cr--XBKy.mjs.map} +1 -1
  49. package/dist/init-C5220SY9.mjs +2062 -0
  50. package/dist/init-C5220SY9.mjs.map +1 -0
  51. package/dist/{inspect-live-schema-DWzf4Q_m.mjs → inspect-live-schema-yrHAvG71.mjs} +6 -6
  52. package/dist/{inspect-live-schema-DWzf4Q_m.mjs.map → inspect-live-schema-yrHAvG71.mjs.map} +1 -1
  53. package/dist/migration-cli.mjs +1 -1
  54. package/dist/{migration-command-scaffold-CLMD302g.mjs → migration-command-scaffold-B3B09et6.mjs} +6 -6
  55. package/dist/{migration-command-scaffold-CLMD302g.mjs.map → migration-command-scaffold-B3B09et6.mjs.map} +1 -1
  56. package/dist/{migration-status-B0HLF7So.mjs → migration-status-DUMiH8_G.mjs} +12 -14
  57. package/dist/{migration-status-B0HLF7So.mjs.map → migration-status-DUMiH8_G.mjs.map} +1 -1
  58. package/dist/{migrations-B0dOQlk0.mjs → migrations-Bo5WtTla.mjs} +2 -2
  59. package/dist/{migrations-B0dOQlk0.mjs.map → migrations-Bo5WtTla.mjs.map} +1 -1
  60. package/dist/output-BpcQrnnq.mjs +103 -0
  61. package/dist/output-BpcQrnnq.mjs.map +1 -0
  62. package/dist/{progress-adapter-B-YvmcDu.mjs → progress-adapter-DvQWB1nK.mjs} +1 -1
  63. package/dist/{progress-adapter-B-YvmcDu.mjs.map → progress-adapter-DvQWB1nK.mjs.map} +1 -1
  64. package/dist/quick-reference-mongo.md +34 -13
  65. package/dist/quick-reference-postgres.md +11 -9
  66. package/dist/{result-handler-CIyu0Pdt.mjs → result-handler-Ba3zWQsI.mjs} +5 -78
  67. package/dist/result-handler-Ba3zWQsI.mjs.map +1 -0
  68. package/dist/{terminal-ui-C5k88MmW.mjs → terminal-ui-C3ZLwQxK.mjs} +76 -2
  69. package/dist/terminal-ui-C3ZLwQxK.mjs.map +1 -0
  70. package/dist/{validate-contract-deps-esa-VQ0h.mjs → validate-contract-deps-B_Cs29TL.mjs} +1 -1
  71. package/dist/{validate-contract-deps-esa-VQ0h.mjs.map → validate-contract-deps-B_Cs29TL.mjs.map} +1 -1
  72. package/dist/{verify-BxiVp50b.mjs → verify-Bkycc-Tf.mjs} +2 -2
  73. package/dist/{verify-BxiVp50b.mjs.map → verify-Bkycc-Tf.mjs.map} +1 -1
  74. package/package.json +21 -16
  75. package/src/commands/init/detect-pnpm-catalog.ts +141 -0
  76. package/src/commands/init/errors.ts +254 -0
  77. package/src/commands/init/exit-codes.ts +62 -0
  78. package/src/commands/init/hygiene-gitattributes.ts +97 -0
  79. package/src/commands/init/hygiene-gitignore.ts +48 -0
  80. package/src/commands/init/hygiene-package-scripts.ts +91 -0
  81. package/src/commands/init/index.ts +112 -7
  82. package/src/commands/init/init.ts +766 -144
  83. package/src/commands/init/inputs.ts +421 -0
  84. package/src/commands/init/output.ts +147 -0
  85. package/src/commands/init/probe-db.ts +308 -0
  86. package/src/commands/init/reinit-cleanup.ts +83 -0
  87. package/src/commands/init/templates/agent-skill-mongo.md +63 -31
  88. package/src/commands/init/templates/agent-skill-postgres.md +1 -1
  89. package/src/commands/init/templates/agent-skill.ts +25 -3
  90. package/src/commands/init/templates/code-templates.ts +125 -32
  91. package/src/commands/init/templates/env.ts +80 -0
  92. package/src/commands/init/templates/quick-reference-mongo.md +34 -13
  93. package/src/commands/init/templates/quick-reference-postgres.md +11 -9
  94. package/src/commands/init/templates/quick-reference.ts +42 -3
  95. package/src/commands/init/templates/tsconfig.ts +167 -5
  96. package/src/commands/migration-apply.ts +3 -3
  97. package/src/commands/migration-ref.ts +32 -47
  98. package/src/commands/migration-status.ts +16 -21
  99. package/src/exports/init-output.ts +10 -0
  100. package/src/utils/command-helpers.ts +3 -3
  101. package/dist/contract-emit-fhNwwhkQ.mjs +0 -4
  102. package/dist/init-CQfo_4Ro.mjs +0 -430
  103. package/dist/init-CQfo_4Ro.mjs.map +0 -1
  104. package/dist/result-handler-CIyu0Pdt.mjs.map +0 -1
  105. package/dist/terminal-ui-C5k88MmW.mjs.map +0 -1
  106. /package/dist/{cli-errors-C0JhVj0c.d.mts → cli-errors-BFYgBH3L.d.mts} +0 -0
  107. /package/dist/{cli-errors-DHq6GQGu.mjs → cli-errors-Cd79vmTH.mjs} +0 -0
@@ -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):
package/dist/cli.mjs CHANGED
@@ -1,10 +1,10 @@
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 { n as installShutdownHandlers } from "./terminal-ui-C3ZLwQxK.mjs";
5
+ import { d as setCommandExamples, g as formatRootHelp, h as formatCommandHelp, m as parseGlobalFlags, n as addGlobalOptions, u as setCommandDescriptions } from "./result-handler-Ba3zWQsI.mjs";
6
+ import { t as createContractEmitCommand } from "./contract-emit-NJ01hiiv.mjs";
7
+ import { t as createContractInferCommand } from "./contract-infer-D9cC3rJm.mjs";
8
8
  import { createDbInitCommand } from "./commands/db-init.mjs";
9
9
  import { createDbSchemaCommand } from "./commands/db-schema.mjs";
10
10
  import { createDbSignCommand } from "./commands/db-sign.mjs";
@@ -15,20 +15,126 @@ import { createMigrationNewCommand } from "./commands/migration-new.mjs";
15
15
  import { createMigrationPlanCommand } from "./commands/migration-plan.mjs";
16
16
  import { createMigrationRefCommand } from "./commands/migration-ref.mjs";
17
17
  import { createMigrationShowCommand } from "./commands/migration-show.mjs";
18
- import { t as createMigrationStatusCommand } from "./migration-status-B0HLF7So.mjs";
18
+ import { t as createMigrationStatusCommand } from "./migration-status-DUMiH8_G.mjs";
19
19
  import { Command } from "commander";
20
20
  import { distance } from "closest-match";
21
21
 
22
+ //#region src/commands/init/exit-codes.ts
23
+ /**
24
+ * Stable exit codes for the `init` command.
25
+ *
26
+ * These are part of the command's public contract. AI agents and CI scripts
27
+ * branch on them (FR1.6), so the values must remain stable across versions.
28
+ *
29
+ * Codes 0–3 are the CLI-wide reserved values per the [CLI Style Guide
30
+ * Exit Codes section](../../../../../../../docs/CLI%20Style%20Guide.md#exit-codes):
31
+ * `OK = 0`, `INTERNAL_ERROR = 1`, `PRECONDITION = 2`, `USER_ABORTED = 3`.
32
+ * Codes 4 and 5 are command-specific outcomes for `init`'s two fallible
33
+ * side effects (install + emit). Documented in `--help` via
34
+ * `setCommandDescriptions` in `./index.ts`.
35
+ */
36
+ const INIT_EXIT_OK = 0;
37
+ /**
38
+ * Anything we did not anticipate — a bug in prisma-next, not something
39
+ * the caller did wrong. Includes the structured error code `5009`
40
+ * (invalid output document) and any unrecognised internal error code,
41
+ * so callers can distinguish "tool is broken" from "your invocation
42
+ * was wrong" (`PRECONDITION = 2`). Maps to the generic "RUN" error
43
+ * domain.
44
+ */
45
+ const INIT_EXIT_INTERNAL_ERROR = 1;
46
+ /**
47
+ * Preconditions not met. The caller asked for something we cannot do
48
+ * without more input or a different environment. Examples:
49
+ * - missing `package.json` / `deno.json`
50
+ * - non-interactive mode without enough flags to proceed
51
+ * - re-init without `--force` in non-interactive mode
52
+ */
53
+ const INIT_EXIT_PRECONDITION = 2;
54
+ /**
55
+ * The user actively aborted an interactive prompt (Ctrl-C, declined the
56
+ * re-init confirmation, etc.). Distinct from PRECONDITION because the user
57
+ * was given the choice and made it; no diagnostic is needed.
58
+ */
59
+ const INIT_EXIT_USER_ABORTED = 3;
60
+ /**
61
+ * Dependency installation step failed without a recoverable fallback.
62
+ * `init` automatically falls back from `pnpm` to `npm` on a recognised
63
+ * workspace/catalog leak (FR7.2); this code is returned only when the
64
+ * fallback also fails, or when the package manager is not pnpm and the
65
+ * single attempt failed. Files written before the install step (config,
66
+ * schema, db client, etc.) remain on disk so the user can fix the
67
+ * environment and re-run; the error envelope's `meta.filesWritten` lists
68
+ * them.
69
+ */
70
+ const INIT_EXIT_INSTALL_FAILED = 4;
71
+ /**
72
+ * Contract emit step failed after a successful install. Files written
73
+ * before emit (including any installed dependencies) are still on disk;
74
+ * the user can fix the underlying issue (typically a contract syntax
75
+ * error or a missing extension pack) and re-run `prisma-next contract
76
+ * emit` manually.
77
+ */
78
+ const INIT_EXIT_EMIT_FAILED = 5;
79
+
80
+ //#endregion
22
81
  //#region src/commands/init/index.ts
23
82
  function createInitCommand() {
24
83
  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 });
84
+ setCommandDescriptions(command, "Initialize a new Prisma Next project", `Scaffolds config, schema, and runtime files, installs dependencies,
85
+ and emits the contract. Gets you from zero to typed queries in one step.
86
+
87
+ Run interactively for a guided experience, or supply --target / --authoring
88
+ and --yes for a fully scriptable run (CI, AI coding agents, automation).
89
+
90
+ Exit codes (see CLI Style Guide § Exit Codes):
91
+ ${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).`);
92
+ setCommandExamples(command, [
93
+ "prisma-next init",
94
+ "prisma-next init --yes --target postgres --authoring psl",
95
+ "prisma-next init --yes --target mongodb --authoring typescript --json",
96
+ "prisma-next init --yes --force --target postgres --authoring psl # overwrite an existing scaffold",
97
+ "prisma-next init --no-install # skip pnpm/npm install + emit"
98
+ ]);
99
+ 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) => {
100
+ const { runInit } = await import("./init-C5220SY9.mjs");
101
+ const flags = parseGlobalFlags(options);
102
+ const canPrompt = deriveCanPrompt({
103
+ flagsInteractive: flags.interactive,
104
+ optionInteractive: options.interactive,
105
+ stdinIsTTY: Boolean(process.stdin.isTTY)
106
+ });
107
+ const exitCode = await runInit(process.cwd(), {
108
+ options,
109
+ flags,
110
+ canPrompt
111
+ });
112
+ process.exit(exitCode);
30
113
  });
31
- return command;
114
+ }
115
+ /**
116
+ * Bridges the action handler's two TTY checks (stdout via `flags`, stdin
117
+ * via `process.stdin.isTTY`) into the `canPrompt` boolean `runInit`
118
+ * consumes.
119
+ *
120
+ * Per the [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity):
121
+ *
122
+ * - `flags.interactive` governs *decoration* (TerminalUI, intro/outro,
123
+ * spinners) and is derived from stdout-TTY by `parseGlobalFlags`,
124
+ * honouring `--interactive` / `--no-interactive`.
125
+ * - Prompting additionally requires a stdin TTY — closing stdin is a
126
+ * common signal in CI / agent environments even when stdout stays
127
+ * attached.
128
+ * - `--interactive` is the explicit override: when the user passes it,
129
+ * we honour it (e.g. testing flows where stdin is stubbed).
130
+ *
131
+ * Exported so callers and tests can derive the same value without
132
+ * touching `process` globals — F14 of the M1/M2 review.
133
+ */
134
+ function deriveCanPrompt(opts) {
135
+ if (opts.optionInteractive === true) return true;
136
+ if (opts.flagsInteractive === false) return false;
137
+ return opts.stdinIsTTY;
32
138
  }
33
139
 
34
140
  //#endregion
@@ -247,5 +353,5 @@ if (args.length > 0) {
247
353
  program.parse();
248
354
 
249
355
  //#endregion
250
- export { };
356
+ 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
357
  //# 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,CAAC;CAE9D,MAAM,SAAS,WACZ,KAAK,UAAU;EAAE;EAAM,MAA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,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;;;;;;AAOtC,MAAa,yBAAyB;;;;;;;;;;;AAYtC,MAAa,2BAA2B;;;;;;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AK,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,6 +1,6 @@
1
- import { t as assertFrameworkComponentsCompatible } from "./framework-components-DfZKQBQ2.mjs";
2
- import { t as enrichContract } from "./contract-enrichment-CGW6mm-E.mjs";
3
- import { t as extractOperationStatements } from "./extract-operation-statements-DZUJNmL3.mjs";
1
+ import { t as assertFrameworkComponentsCompatible } from "./framework-components-Cr--XBKy.mjs";
2
+ import { t as enrichContract } from "./contract-enrichment-CAOELa-H.mjs";
3
+ import { t as extractOperationStatements } from "./extract-operation-statements-DsFfxXVZ.mjs";
4
4
  import { emit } from "@prisma-next/emitter";
5
5
  import { notOk, ok } from "@prisma-next/utils/result";
6
6
  import { ifDefined } from "@prisma-next/utils/defined";
@@ -994,4 +994,4 @@ var ControlClientImpl = class {
994
994
 
995
995
  //#endregion
996
996
  export { ContractValidationError as n, createControlClient as t };
997
- //# sourceMappingURL=client-TG7rbCWT.mjs.map
997
+ //# sourceMappingURL=client-CrsnY58k.mjs.map