@opensaas/stack-cli 0.42.3 → 0.44.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +116 -135
  2. package/dist/.build-hash +1 -0
  3. package/dist/commands/db.d.ts +23 -0
  4. package/dist/commands/db.d.ts.map +1 -0
  5. package/dist/commands/db.js +43 -0
  6. package/dist/commands/db.js.map +1 -0
  7. package/dist/commands/dev.d.ts +12 -1
  8. package/dist/commands/dev.d.ts.map +1 -1
  9. package/dist/commands/dev.js +519 -22
  10. package/dist/commands/dev.js.map +1 -1
  11. package/dist/commands/fk-renames.d.ts +14 -0
  12. package/dist/commands/fk-renames.d.ts.map +1 -0
  13. package/dist/commands/fk-renames.js +90 -0
  14. package/dist/commands/fk-renames.js.map +1 -0
  15. package/dist/commands/generate.d.ts +61 -4
  16. package/dist/commands/generate.d.ts.map +1 -1
  17. package/dist/commands/generate.js +225 -138
  18. package/dist/commands/generate.js.map +1 -1
  19. package/dist/commands/init.d.ts +6 -0
  20. package/dist/commands/init.d.ts.map +1 -1
  21. package/dist/commands/init.js +13 -2
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/junction-ids.d.ts +11 -0
  24. package/dist/commands/junction-ids.d.ts.map +1 -0
  25. package/dist/commands/junction-ids.js +81 -0
  26. package/dist/commands/junction-ids.js.map +1 -0
  27. package/dist/commands/migrate.d.ts +2 -0
  28. package/dist/commands/migrate.d.ts.map +1 -1
  29. package/dist/commands/migrate.js +47 -25
  30. package/dist/commands/migrate.js.map +1 -1
  31. package/dist/dev/app-runner.d.ts +70 -0
  32. package/dist/dev/app-runner.d.ts.map +1 -0
  33. package/dist/dev/app-runner.js +116 -0
  34. package/dist/dev/app-runner.js.map +1 -0
  35. package/dist/dev/control.d.ts +73 -0
  36. package/dist/dev/control.d.ts.map +1 -0
  37. package/dist/dev/control.js +251 -0
  38. package/dist/dev/control.js.map +1 -0
  39. package/dist/dev/staged-reconcile.d.ts +126 -0
  40. package/dist/dev/staged-reconcile.d.ts.map +1 -0
  41. package/dist/dev/staged-reconcile.js +289 -0
  42. package/dist/dev/staged-reconcile.js.map +1 -0
  43. package/dist/generator/config-load.d.ts +34 -0
  44. package/dist/generator/config-load.d.ts.map +1 -0
  45. package/dist/generator/config-load.js +64 -0
  46. package/dist/generator/config-load.js.map +1 -0
  47. package/dist/generator/context.d.ts +39 -3
  48. package/dist/generator/context.d.ts.map +1 -1
  49. package/dist/generator/context.js +245 -107
  50. package/dist/generator/context.js.map +1 -1
  51. package/dist/generator/contract-emit.d.ts +24 -0
  52. package/dist/generator/contract-emit.d.ts.map +1 -0
  53. package/dist/generator/contract-emit.js +34 -0
  54. package/dist/generator/contract-emit.js.map +1 -0
  55. package/dist/generator/contract-module.d.ts +39 -0
  56. package/dist/generator/contract-module.d.ts.map +1 -0
  57. package/dist/generator/contract-module.js +440 -0
  58. package/dist/generator/contract-module.js.map +1 -0
  59. package/dist/generator/extension-spaces.d.ts +142 -0
  60. package/dist/generator/extension-spaces.d.ts.map +1 -0
  61. package/dist/generator/extension-spaces.js +358 -0
  62. package/dist/generator/extension-spaces.js.map +1 -0
  63. package/dist/generator/index.d.ts +12 -4
  64. package/dist/generator/index.d.ts.map +1 -1
  65. package/dist/generator/index.js +7 -3
  66. package/dist/generator/index.js.map +1 -1
  67. package/dist/generator/lists.d.ts +6 -7
  68. package/dist/generator/lists.d.ts.map +1 -1
  69. package/dist/generator/lists.js +33 -13
  70. package/dist/generator/lists.js.map +1 -1
  71. package/dist/generator/output-paths.d.ts +62 -19
  72. package/dist/generator/output-paths.d.ts.map +1 -1
  73. package/dist/generator/output-paths.js +68 -30
  74. package/dist/generator/output-paths.js.map +1 -1
  75. package/dist/generator/prisma-cli.d.ts +61 -0
  76. package/dist/generator/prisma-cli.d.ts.map +1 -0
  77. package/dist/generator/prisma-cli.js +92 -0
  78. package/dist/generator/prisma-cli.js.map +1 -0
  79. package/dist/generator/prisma-config.d.ts +50 -31
  80. package/dist/generator/prisma-config.d.ts.map +1 -1
  81. package/dist/generator/prisma-config.js +72 -65
  82. package/dist/generator/prisma-config.js.map +1 -1
  83. package/dist/generator/source-text.d.ts +16 -0
  84. package/dist/generator/source-text.d.ts.map +1 -0
  85. package/dist/generator/source-text.js +35 -0
  86. package/dist/generator/source-text.js.map +1 -0
  87. package/dist/generator/tables.d.ts +5 -0
  88. package/dist/generator/tables.d.ts.map +1 -0
  89. package/dist/generator/tables.js +84 -0
  90. package/dist/generator/tables.js.map +1 -0
  91. package/dist/generator/types.d.ts +23 -3
  92. package/dist/generator/types.d.ts.map +1 -1
  93. package/dist/generator/types.js +291 -1171
  94. package/dist/generator/types.js.map +1 -1
  95. package/dist/index.js +20 -7
  96. package/dist/index.js.map +1 -1
  97. package/dist/mcp/lib/documentation-provider.d.ts.map +1 -1
  98. package/dist/mcp/lib/documentation-provider.js +44 -42
  99. package/dist/mcp/lib/documentation-provider.js.map +1 -1
  100. package/dist/mcp/lib/generators/feature-generator.d.ts.map +1 -1
  101. package/dist/mcp/lib/generators/feature-generator.js +124 -73
  102. package/dist/mcp/lib/generators/feature-generator.js.map +1 -1
  103. package/dist/mcp/lib/wizards/migration-wizard.js +6 -6
  104. package/dist/mcp/lib/wizards/migration-wizard.js.map +1 -1
  105. package/dist/mcp/lib/wizards/wizard-engine.d.ts.map +1 -1
  106. package/dist/mcp/lib/wizards/wizard-engine.js +3 -2
  107. package/dist/mcp/lib/wizards/wizard-engine.js.map +1 -1
  108. package/dist/mcp/server/stack-mcp-server.js +1 -1
  109. package/dist/migration/fk-renames.d.ts +39 -0
  110. package/dist/migration/fk-renames.d.ts.map +1 -0
  111. package/dist/migration/fk-renames.js +79 -0
  112. package/dist/migration/fk-renames.js.map +1 -0
  113. package/dist/migration/generators/migration-generator.d.ts +11 -0
  114. package/dist/migration/generators/migration-generator.d.ts.map +1 -1
  115. package/dist/migration/generators/migration-generator.js +83 -150
  116. package/dist/migration/generators/migration-generator.js.map +1 -1
  117. package/dist/migration/introspectors/prisma-introspector.d.ts.map +1 -1
  118. package/dist/migration/introspectors/prisma-introspector.js +1 -0
  119. package/dist/migration/introspectors/prisma-introspector.js.map +1 -1
  120. package/dist/migration/junction-ids.d.ts +15 -0
  121. package/dist/migration/junction-ids.d.ts.map +1 -0
  122. package/dist/migration/junction-ids.js +58 -0
  123. package/dist/migration/junction-ids.js.map +1 -0
  124. package/dist/migration/types.d.ts +2 -0
  125. package/dist/migration/types.d.ts.map +1 -1
  126. package/package.json +27 -15
  127. package/dist/generator/node-build.d.ts +0 -53
  128. package/dist/generator/node-build.d.ts.map +0 -1
  129. package/dist/generator/node-build.js +0 -280
  130. package/dist/generator/node-build.js.map +0 -1
  131. package/dist/generator/prisma.d.ts +0 -30
  132. package/dist/generator/prisma.d.ts.map +0 -1
  133. package/dist/generator/prisma.js +0 -422
  134. package/dist/generator/prisma.js.map +0 -1
package/README.md CHANGED
@@ -10,9 +10,14 @@ pnpm add -D @opensaas/stack-cli
10
10
 
11
11
  ## Commands
12
12
 
13
+ The CLI carries `generate`, `init`, `dev` and `migrate`, plus the command groups
14
+ `db` and `mcp`. `migrate` is a single command with options, not a group — it has
15
+ no subcommands.
16
+
13
17
  ### `opensaas generate`
14
18
 
15
- Generate Prisma schema and TypeScript types from your `opensaas.config.ts`.
19
+ Generate the schema contract and TypeScript types from your
20
+ `opensaas.config.ts`.
16
21
 
17
22
  ```bash
18
23
  opensaas generate
@@ -20,26 +25,15 @@ opensaas generate
20
25
 
21
26
  **What it does:**
22
27
 
23
- 1. Reads `opensaas.config.ts` from current directory
24
- 2. Generates `prisma/schema.prisma` - Prisma schema
25
- 3. Generates `.opensaas/types.ts` - TypeScript types
26
- 4. Outputs success message with next steps
27
-
28
- **Output:**
29
-
30
- ```
31
- 🚀 OpenSaas Generator
32
- - Loading configuration...
33
- ✔ Generation complete
34
- ✅ Prisma schema generated
35
- ✅ TypeScript types generated
36
- ✨ Generation complete!
37
-
38
- Next steps:
39
- 1. Run: npx prisma generate
40
- 2. Run: npx prisma db push
41
- 3. Start using your generated types!
42
- ```
28
+ 1. Reads `opensaas.config.ts` from the current directory
29
+ 2. Writes `prisma/contract.ts`, the contract module
30
+ 3. Shells to `prisma contract emit`, which writes `prisma/contract.json` and
31
+ `prisma/contract.d.ts` — the artifacts the runtime executes
32
+ 4. Writes the generated bundle: `.opensaas/types.ts`, `.opensaas/context.ts`,
33
+ `.opensaas/lists.ts`, `.opensaas/tables.ts`, `.opensaas/plugin-types.ts`
34
+ 5. Writes `prisma.config.ts` at the project root
35
+ 6. Seeds an Extension contract space under `migrations/` for every extension
36
+ pack the config declares
43
37
 
44
38
  **Example package.json script:**
45
39
 
@@ -53,47 +47,63 @@ Next steps:
53
47
 
54
48
  ### `opensaas dev`
55
49
 
56
- Watch `opensaas.config.ts` and automatically regenerate on changes.
50
+ Start the Dev database, generate, reconcile the schema, and run the app. This is
51
+ the whole local loop in one process.
57
52
 
58
53
  ```bash
59
54
  opensaas dev
60
55
  ```
61
56
 
62
- **What it does:**
57
+ Pass your own app command after `--` to run something other than `next dev`:
63
58
 
64
- 1. Runs initial generation
65
- 2. Watches `opensaas.config.ts` for changes
66
- 3. Automatically regenerates when file changes
67
- 4. Runs until you press Ctrl+C
59
+ ```bash
60
+ opensaas dev -- vite dev
61
+ ```
68
62
 
69
- **Output:**
63
+ The loop owns the Dev database's data directory, the staged generation and the
64
+ app child, so it is the only thing holding a connection. Leave it running while
65
+ you work.
70
66
 
71
- ```
72
- 🚀 OpenSaas Generator
73
- - Loading configuration...
74
- ✔ Generation complete
75
- ✅ Prisma schema generated
76
- ✅ TypeScript types generated
67
+ ### `opensaas db update`
77
68
 
78
- 👀 Watching opensaas.config.ts for changes...
79
- Press Ctrl+C to stop
69
+ Apply the staged schema change through the running `opensaas dev` loop — what
70
+ `pnpm db:update` points at.
71
+
72
+ ```bash
73
+ opensaas db update
80
74
  ```
81
75
 
82
- When changes detected:
76
+ The command opens **no connection of its own**: it hands the request to the
77
+ running loop and exits non-zero when none is listening. A destructive change
78
+ needs consent: the loop prints the plan with a plan id, and `--plan` names it.
79
+ The loop applies it only if the plan it computes now still has that id, and
80
+ supplies Prisma's own consent for the database it is connected to:
83
81
 
82
+ ```bash
83
+ opensaas db update --plan <id>
84
84
  ```
85
- Config changed, regenerating...
86
85
 
87
- 🚀 OpenSaas Generator
88
- ...
89
- ```
86
+ `update` is the only subcommand under `db`. There is no `opensaas db migrate` —
87
+ production applies committed migrations with the Prisma CLI (`prisma db
88
+ migrate`).
90
89
 
91
- **Example package.json script:**
90
+ **What it does:**
91
+
92
+ 1. Sends one reconcile request to the `opensaas dev` loop already running
93
+ 2. Exits — non-zero if no loop is listening, or if the change needs a
94
+ `--plan <id>` it was not given, or one that no longer matches
95
+
96
+ It is not a watcher and it does not stay resident: the watching, regenerating
97
+ and Ctrl+C-until-stopped behaviour all belong to [`opensaas dev`](#opensaas-dev),
98
+ which must already be running for this command to have anything to talk to.
99
+
100
+ **Example package.json scripts:**
92
101
 
93
102
  ```json
94
103
  {
95
104
  "scripts": {
96
- "dev": "opensaas dev"
105
+ "dev": "opensaas dev",
106
+ "db:update": "opensaas db update"
97
107
  }
98
108
  }
99
109
  ```
@@ -138,11 +148,12 @@ This command runs `npx create-opensaas-app@latest` with the provided arguments.
138
148
  ```bash
139
149
  cd my-project
140
150
  pnpm install
141
- pnpm generate # Generate Prisma schema and types
142
- pnpm db:push # Create database
143
- pnpm dev # Start dev server
151
+ pnpm dev
144
152
  ```
145
153
 
154
+ `pnpm dev` starts the Dev database, generates, reconciles the schema and runs
155
+ the app. Nothing needs creating first.
156
+
146
157
  ### `opensaas migrate`
147
158
 
148
159
  Migrate an existing Prisma, KeystoneJS, or Next.js project to OpenSaas Stack.
@@ -229,8 +240,6 @@ Without `--with-ai`, the command provides project analysis and you create the co
229
240
  npm create opensaas-app@latest my-project
230
241
  cd my-project
231
242
  pnpm install
232
- pnpm generate
233
- pnpm db:push
234
243
  pnpm dev
235
244
  ```
236
245
 
@@ -240,8 +249,6 @@ pnpm dev
240
249
  npx @opensaas/stack-cli init my-project
241
250
  cd my-project
242
251
  pnpm install
243
- pnpm generate
244
- pnpm db:push
245
252
  pnpm dev
246
253
  ```
247
254
 
@@ -255,30 +262,37 @@ pnpm add -D @opensaas/stack-cli
255
262
  {
256
263
  "scripts": {
257
264
  "generate": "opensaas generate",
258
- "dev": "opensaas dev"
265
+ "dev": "opensaas dev",
266
+ "db:update": "opensaas db update"
259
267
  }
260
268
  }
261
269
 
262
270
  # Generate code
263
271
  pnpm generate
264
272
 
265
- # Or watch for changes
273
+ # Or run the whole dev loop
266
274
  pnpm dev
267
275
  ```
268
276
 
269
277
  ### Development Workflow
270
278
 
279
+ `opensaas dev` runs the Dev database, the generator and the app together, so one
280
+ terminal is the normal case:
281
+
271
282
  ```bash
272
- # Terminal 1: Watch config and regenerate
273
283
  pnpm dev
284
+ ```
274
285
 
275
- # Terminal 2: Run Next.js dev server
276
- pnpm next dev
286
+ When you change the config, the loop stages the new generation and tells you what
287
+ applying it would do. Accept it from a second terminal:
277
288
 
278
- # Terminal 3: Watch Prisma Studio (optional)
279
- pnpm db:studio
289
+ ```bash
290
+ pnpm db:update
280
291
  ```
281
292
 
293
+ That command talks to the running loop, so `pnpm dev` has to be up for it to do
294
+ anything.
295
+
282
296
  ### CI/CD Integration
283
297
 
284
298
  ```yaml
@@ -293,7 +307,6 @@ jobs:
293
307
  - uses: pnpm/action-setup@v2
294
308
  - run: pnpm install
295
309
  - run: pnpm generate
296
- - run: npx prisma generate
297
310
  - run: pnpm test
298
311
  ```
299
312
 
@@ -309,10 +322,7 @@ import { config, list } from '@opensaas/stack-core'
309
322
  import { text } from '@opensaas/stack-core/fields'
310
323
 
311
324
  export default config({
312
- db: {
313
- provider: 'postgresql',
314
- url: process.env.DATABASE_URL,
315
- },
325
+ db: { provider: 'postgresql' },
316
326
  lists: {
317
327
  Post: list({
318
328
  fields: {
@@ -323,64 +333,47 @@ export default config({
323
333
  })
324
334
  ```
325
335
 
336
+ `postgresql` is the only provider. The connection is resolved at run time from
337
+ `DIRECT_DATABASE_URL`, then `DATABASE_URL`, then the Dev database `opensaas dev`
338
+ starts — there is no `db.url` key and no `prismaClientConstructor`. See the
339
+ [config API reference](https://stack.opensaas.au/docs/reference/config-api) for
340
+ the complete `db` key list.
341
+
326
342
  ## Output Files
327
343
 
328
- ### Prisma Schema (`prisma/schema.prisma`)
344
+ ### Contract module (`prisma/contract.ts`)
329
345
 
330
- Generated Prisma schema with:
346
+ The schema, as a TypeScript module: one table per list, the columns each field
347
+ declares, the relations between them and the indexes. `prisma contract emit`
348
+ reads it and writes `prisma/contract.json` and `prisma/contract.d.ts` beside it —
349
+ those two are what the runtime executes.
331
350
 
332
- - Database provider configuration
333
- - Models for each list
334
- - Field types and modifiers
335
- - Indexes
336
- - Relationships
351
+ ### Generated bundle (`.opensaas/`)
337
352
 
338
- **Example output:**
353
+ - `types.ts` — row, create-input and update-input interfaces per list
354
+ - `context.ts` — `getContext`, `rawOpensaasContext` and `config`
355
+ - `lists.ts`, `tables.ts`, `plugin-types.ts`
339
356
 
340
- ```prisma
341
- datasource db {
342
- provider = "postgresql"
343
- url = env("DATABASE_URL")
344
- }
357
+ **Example `types.ts` output:**
345
358
 
346
- generator client {
347
- provider = "prisma-client-js"
348
- }
349
-
350
- model Post {
351
- id String @id @default(cuid())
352
- title String
353
- createdAt DateTime @default(now())
354
- updatedAt DateTime @updatedAt
355
- }
359
+ ```typescript
360
+ export interface Post extends Stack$Row<Stack$Contract, Remainder, 'Post'> {}
361
+ export interface PostCreateInput extends Stack$CreateInput<Stack$Contract, Remainder, 'Post'> {}
362
+ export interface PostUpdateInput extends Stack$UpdateInput<Stack$Contract, Remainder, 'Post'> {}
356
363
  ```
357
364
 
358
- ### TypeScript Types (`.opensaas/types.ts`)
359
-
360
- Generated TypeScript types for:
365
+ Each interface is its own named symbol resolved lazily from the emitted
366
+ contract, so a list's shape follows the contract without being restated here.
361
367
 
362
- - List items
363
- - Create/update input types
364
- - Context types
368
+ ### Migrations (`migrations/`)
365
369
 
366
- **Example output:**
370
+ `generate` seeds one Extension contract space per declared extension pack. These
371
+ files are committed — they are derived from `db.extensions` and the installed
372
+ pack version, and a stale copy is a wrong-version migration.
367
373
 
368
- ```typescript
369
- export type Post = {
370
- id: string
371
- title: string
372
- createdAt: Date
373
- updatedAt: Date
374
- }
374
+ ### `prisma.config.ts`
375
375
 
376
- export type PostCreateInput = {
377
- title: string
378
- }
379
-
380
- export type PostUpdateInput = {
381
- title?: string
382
- }
383
- ```
376
+ Written at the project root, for the Prisma CLI.
384
377
 
385
378
  ## Troubleshooting
386
379
 
@@ -410,47 +403,35 @@ Error: EACCES: permission denied
410
403
 
411
404
  ## Examples
412
405
 
413
- ### Generate after config changes
414
-
415
- ```bash
416
- # Edit opensaas.config.ts
417
- vim opensaas.config.ts
406
+ ### Changing the schema during development
418
407
 
419
- # Regenerate
420
- pnpm generate
408
+ With `pnpm dev` running, edit `opensaas.config.ts`. The loop regenerates,
409
+ stages the change and reports what applying it would do. Accept it from a second
410
+ terminal:
421
411
 
422
- # Update database
423
- pnpm db:push
412
+ ```bash
413
+ pnpm db:update
424
414
  ```
425
415
 
426
- ### Watch mode during development
416
+ If the change would destroy data, pass the plan id the loop printed:
427
417
 
428
418
  ```bash
429
- # Start watch mode
430
- pnpm dev
431
-
432
- # In another terminal, edit config
433
- vim opensaas.config.ts
434
-
435
- # Generator automatically reruns!
419
+ pnpm db:update --plan <id>
436
420
  ```
437
421
 
438
- ## Integration with Prisma
422
+ ### Preparing a production migration
439
423
 
440
- After running `opensaas generate`:
424
+ Planning a migration needs a database to plan against, and a direct
425
+ (non-pooled) connection, which `DIRECT_DATABASE_URL` supplies:
441
426
 
442
427
  ```bash
443
- # Generate Prisma Client
444
- npx prisma generate
445
-
446
- # Push schema to database
447
- npx prisma db push
428
+ DIRECT_DATABASE_URL=... npx prisma migration plan
429
+ ```
448
430
 
449
- # Create migration
450
- npx prisma migrate dev --name init
431
+ Commit the resulting `migrations/` directory. The release step applies it:
451
432
 
452
- # Open Prisma Studio
453
- npx prisma studio
433
+ ```bash
434
+ npx prisma db migrate
454
435
  ```
455
436
 
456
437
  ## Learn More
@@ -0,0 +1 @@
1
+ 6233c3fc7a4763851b23906d997c8761084a8ce24df8876bf3c74e1c50769f16
@@ -0,0 +1,23 @@
1
+ import { Command } from 'commander';
2
+ /** Options for {@link dbUpdateCommand}. */
3
+ export interface DbUpdateCommandOptions {
4
+ /** The id of the destructive plan the loop printed; it is the consent to apply it. */
5
+ plan?: string;
6
+ }
7
+ /**
8
+ * `opensaas db update` — what `pnpm db:update` points at.
9
+ *
10
+ * The reconcile itself runs inside the `opensaas dev` loop: it holds the Dev
11
+ * database's data directory, the staged generation and the app child, so this
12
+ * command opens no connection of its own. It hands the loop the plan id and
13
+ * prints what the loop reports (ADR-0063).
14
+ *
15
+ * @example
16
+ * ```bash
17
+ * opensaas db update --plan <id>
18
+ * ```
19
+ */
20
+ export declare function dbUpdateCommand(options?: DbUpdateCommandOptions): Promise<void>;
21
+ /** The `db` command group. */
22
+ export declare function createDbCommand(): Command;
23
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/commands/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAYzF;AAED,8BAA8B;AAC9B,wBAAgB,eAAe,IAAI,OAAO,CAWzC"}
@@ -0,0 +1,43 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { DevLoopUnreachableError, NoDevLoopError, requestDatabaseUpdate } from '../dev/control.js';
4
+ /**
5
+ * `opensaas db update` — what `pnpm db:update` points at.
6
+ *
7
+ * The reconcile itself runs inside the `opensaas dev` loop: it holds the Dev
8
+ * database's data directory, the staged generation and the app child, so this
9
+ * command opens no connection of its own. It hands the loop the plan id and
10
+ * prints what the loop reports (ADR-0063).
11
+ *
12
+ * @example
13
+ * ```bash
14
+ * opensaas db update --plan <id>
15
+ * ```
16
+ */
17
+ export async function dbUpdateCommand(options = {}) {
18
+ try {
19
+ const ok = await requestDatabaseUpdate(process.cwd(), options.plan, (message) => {
20
+ console.log(message);
21
+ });
22
+ if (!ok)
23
+ process.exitCode = 1;
24
+ }
25
+ catch (error) {
26
+ if (!(error instanceof NoDevLoopError) && !(error instanceof DevLoopUnreachableError))
27
+ throw error;
28
+ console.error(chalk.red(error.message));
29
+ process.exitCode = 1;
30
+ }
31
+ }
32
+ /** The `db` command group. */
33
+ export function createDbCommand() {
34
+ const db = new Command('db').description('Database commands for the running dev loop');
35
+ db.command('update')
36
+ .description('Apply the staged schema change through the running `opensaas dev` loop')
37
+ .option('--plan <id>', 'The id of the destructive plan the loop printed, to apply it')
38
+ .action(async (options) => {
39
+ await dbUpdateCommand({ plan: options.plan });
40
+ });
41
+ return db;
42
+ }
43
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/commands/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAQlG;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAO,GAA2B,EAAE;IACxE,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,MAAM,qBAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAC9E,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACtB,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,uBAAuB,CAAC;YACnF,MAAM,KAAK,CAAA;QACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;QACvC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACtB,CAAC;AACH,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,4CAA4C,CAAC,CAAA;IAEtF,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,wEAAwE,CAAC;SACrF,MAAM,CAAC,aAAa,EAAE,8DAA8D,CAAC;SACrF,MAAM,CAAC,KAAK,EAAE,OAA0B,EAAE,EAAE;QAC3C,MAAM,eAAe,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEJ,OAAO,EAAE,CAAA;AACX,CAAC"}
@@ -1,2 +1,13 @@
1
- export declare function devCommand(): Promise<void>;
1
+ /** Options for {@link devCommand}. */
2
+ export interface DevCommandOptions {
3
+ /**
4
+ * The app command to run in place of `next dev` — what a caller wrote after
5
+ * `opensaas dev --`.
6
+ */
7
+ appCommand?: readonly string[];
8
+ /** Consent, for the whole session, to schema changes applied to a database named by the environment. */
9
+ yes?: boolean;
10
+ }
11
+ /** The dev loop: Dev database, generate, reconcile, app child, config watch (ADR-0063). */
12
+ export declare function devCommand(options?: DevCommandOptions): Promise<void>;
2
13
  //# sourceMappingURL=dev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAMA,wBAAsB,UAAU,kBAoC/B"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAiEA,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC9B,wGAAwG;IACxG,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAuED,2FAA2F;AAC3F,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsgB/E"}