@prisma-next/cli 0.3.0-dev.4 → 0.3.0-dev.40
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.
- package/README.md +125 -40
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2376
- package/dist/cli.mjs +169 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-Lm9Q6aQM.mjs +694 -0
- package/dist/client-Lm9Q6aQM.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +140 -0
- package/dist/commands/contract-emit.mjs.map +1 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +179 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-introspect.d.mts +7 -0
- package/dist/commands/db-introspect.d.mts.map +1 -0
- package/dist/commands/db-introspect.mjs +120 -0
- package/dist/commands/db-introspect.mjs.map +1 -0
- package/dist/commands/db-schema-verify.d.mts +7 -0
- package/dist/commands/db-schema-verify.d.mts.map +1 -0
- package/dist/commands/db-schema-verify.mjs +116 -0
- package/dist/commands/db-schema-verify.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +138 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +129 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/config-loader-CnnWuluc.mjs +42 -0
- package/dist/config-loader-CnnWuluc.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +5 -2
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +451 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +59 -0
- package/dist/exports/control-api.mjs.map +1 -0
- package/dist/{index.d.ts → exports/index.d.mts} +7 -6
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +132 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/result-handler-BZPY7HX4.mjs +1029 -0
- package/dist/result-handler-BZPY7HX4.mjs.map +1 -0
- package/package.json +50 -38
- package/src/cli.ts +260 -0
- package/src/commands/contract-emit.ts +267 -0
- package/src/commands/db-init.ts +355 -0
- package/src/commands/db-introspect.ts +227 -0
- package/src/commands/db-schema-verify.ts +238 -0
- package/src/commands/db-sign.ts +279 -0
- package/src/commands/db-verify.ts +259 -0
- package/src/config-loader.ts +76 -0
- package/src/control-api/client.ts +591 -0
- package/src/control-api/operations/contract-emit.ts +103 -0
- package/src/control-api/operations/db-init.ts +281 -0
- package/src/control-api/types.ts +493 -0
- package/src/exports/config-types.ts +6 -0
- package/src/exports/control-api.ts +51 -0
- package/src/exports/index.ts +4 -0
- package/src/load-ts-contract.ts +222 -0
- package/src/utils/cli-errors.ts +26 -0
- package/src/utils/command-helpers.ts +26 -0
- package/src/utils/framework-components.ts +177 -0
- package/src/utils/global-flags.ts +75 -0
- package/src/utils/output.ts +1477 -0
- package/src/utils/progress-adapter.ts +86 -0
- package/src/utils/result-handler.ts +44 -0
- package/dist/chunk-464LNZCE.js +0 -134
- package/dist/chunk-464LNZCE.js.map +0 -1
- package/dist/chunk-BZMBKEEQ.js +0 -997
- package/dist/chunk-BZMBKEEQ.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-ZKYEJROM.js +0 -94
- package/dist/chunk-ZKYEJROM.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -5
- package/dist/commands/contract-emit.js +0 -9
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -5
- package/dist/commands/db-init.js +0 -341
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -5
- package/dist/commands/db-introspect.js +0 -190
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -5
- package/dist/commands/db-schema-verify.js +0 -164
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -5
- package/dist/commands/db-sign.js +0 -199
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -5
- package/dist/commands/db-verify.js +0 -173
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/config-types.d.ts +0 -1
- package/dist/config-types.js +0 -6
- package/dist/config-types.js.map +0 -1
- package/dist/index.js +0 -175
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Provide a command-line interface that:
|
|
|
22
22
|
- **Extension Pack Descriptor Assembly**: Collect adapter and extension descriptors for emission
|
|
23
23
|
- **Help Output Formatting**: Custom styled help output with command trees and formatted descriptions
|
|
24
24
|
- **Config Management**: Load and validate `prisma-next.config.ts` files using Arktype validation
|
|
25
|
+
- **CLI Binary Compatibility**: Build emits `dist/cli.mjs` and also writes a compatibility shim at `dist/cli.js`
|
|
25
26
|
|
|
26
27
|
### Wiring validation
|
|
27
28
|
|
|
@@ -46,7 +47,7 @@ Commands use separate short and long descriptions via `setCommandDescriptions()`
|
|
|
46
47
|
- **Short description**: One-liner used in command trees and headers (e.g., "Emit signed contract artifacts")
|
|
47
48
|
- **Long description**: Multiline text shown at the bottom of help output with detailed context
|
|
48
49
|
|
|
49
|
-
See
|
|
50
|
+
See `src/utils/command-helpers.ts` for `setCommandDescriptions()` and `getLongDescription()`.
|
|
50
51
|
|
|
51
52
|
## Commands
|
|
52
53
|
|
|
@@ -61,12 +62,11 @@ prisma-next contract emit [--config <path>] [--json] [-v] [-q] [--timestamps] [-
|
|
|
61
62
|
|
|
62
63
|
**Config File Requirements:**
|
|
63
64
|
|
|
64
|
-
The `contract emit` command
|
|
65
|
+
The `contract emit` command does not require a `driver` in the config since it doesn't connect to a database:
|
|
65
66
|
|
|
66
67
|
```typescript
|
|
67
68
|
import { defineConfig } from '@prisma-next/cli/config-types';
|
|
68
69
|
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
69
|
-
import postgresDriver from '@prisma-next/driver-postgres/control';
|
|
70
70
|
import postgres from '@prisma-next/target-postgres/control';
|
|
71
71
|
import sql from '@prisma-next/family-sql/control';
|
|
72
72
|
import { contract } from './prisma/contract';
|
|
@@ -75,7 +75,6 @@ export default defineConfig({
|
|
|
75
75
|
family: sql,
|
|
76
76
|
target: postgres,
|
|
77
77
|
adapter: postgresAdapter,
|
|
78
|
-
driver: postgresDriver, // Required even though emit doesn't use it
|
|
79
78
|
extensionPacks: [],
|
|
80
79
|
contract: {
|
|
81
80
|
source: contract,
|
|
@@ -116,7 +115,7 @@ prisma-next db verify [--db <url>] [--config <path>] [--json] [-v] [-q] [--times
|
|
|
116
115
|
```
|
|
117
116
|
|
|
118
117
|
Options:
|
|
119
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
118
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
120
119
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
121
120
|
- `--json`: Output as JSON object
|
|
122
121
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -164,7 +163,7 @@ export default defineConfig({
|
|
|
164
163
|
types: 'src/prisma/contract.d.ts',
|
|
165
164
|
},
|
|
166
165
|
db: {
|
|
167
|
-
|
|
166
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
168
167
|
},
|
|
169
168
|
});
|
|
170
169
|
```
|
|
@@ -173,12 +172,12 @@ export default defineConfig({
|
|
|
173
172
|
|
|
174
173
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
175
174
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
176
|
-
3. **Create Family Instance**:
|
|
175
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
177
176
|
4. **Verify**: Calls `familyInstance.verify()` which:
|
|
178
177
|
- Reads the contract marker from the database
|
|
179
178
|
- Compares marker presence: Returns `PN-RTM-3001` if marker is missing
|
|
180
179
|
- Compares target compatibility: Returns `PN-RTM-3003` if contract target doesn't match config target
|
|
181
|
-
|
|
180
|
+
- Compares storage hash: Returns `PN-RTM-3002` if `storageHash` doesn't match
|
|
182
181
|
- Compares profile hash: Returns `PN-RTM-3002` if `profileHash` doesn't match (when present)
|
|
183
182
|
- Checks codec coverage (optional): Compares contract column types against supported codec types and reports missing codecs
|
|
184
183
|
|
|
@@ -187,7 +186,7 @@ export default defineConfig({
|
|
|
187
186
|
Success:
|
|
188
187
|
```
|
|
189
188
|
✔ Database matches contract
|
|
190
|
-
|
|
189
|
+
storageHash: sha256:abc123...
|
|
191
190
|
profileHash: sha256:def456...
|
|
192
191
|
```
|
|
193
192
|
|
|
@@ -205,11 +204,11 @@ Failure:
|
|
|
205
204
|
"ok": true,
|
|
206
205
|
"summary": "Database matches contract",
|
|
207
206
|
"contract": {
|
|
208
|
-
"
|
|
207
|
+
"storageHash": "sha256:abc123...",
|
|
209
208
|
"profileHash": "sha256:def456..."
|
|
210
209
|
},
|
|
211
210
|
"marker": {
|
|
212
|
-
"
|
|
211
|
+
"storageHash": "sha256:abc123...",
|
|
213
212
|
"profileHash": "sha256:def456..."
|
|
214
213
|
},
|
|
215
214
|
"target": {
|
|
@@ -235,16 +234,20 @@ Failure:
|
|
|
235
234
|
|
|
236
235
|
**Family Requirements:**
|
|
237
236
|
|
|
238
|
-
The family must provide a `create()` method in the family descriptor that returns a `ControlFamilyInstance` with a `verify()` method:
|
|
237
|
+
The family must provide a `create()` method in the family descriptor that accepts a `ControlPlaneStack` and returns a `ControlFamilyInstance` with a `verify()` method:
|
|
239
238
|
|
|
240
239
|
```typescript
|
|
241
|
-
interface ControlFamilyDescriptor {
|
|
242
|
-
create(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
interface ControlFamilyDescriptor<TFamilyId, TFamilyInstance> {
|
|
241
|
+
create<TTargetId extends string>(
|
|
242
|
+
stack: ControlPlaneStack<TFamilyId, TTargetId>,
|
|
243
|
+
): TFamilyInstance;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface ControlPlaneStack<TFamilyId, TTargetId> {
|
|
247
|
+
readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;
|
|
248
|
+
readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;
|
|
249
|
+
readonly driver: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;
|
|
250
|
+
readonly extensionPacks: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];
|
|
248
251
|
}
|
|
249
252
|
|
|
250
253
|
interface ControlFamilyInstance {
|
|
@@ -258,6 +261,8 @@ interface ControlFamilyInstance {
|
|
|
258
261
|
}
|
|
259
262
|
```
|
|
260
263
|
|
|
264
|
+
Use `createControlPlaneStack()` from `@prisma-next/core-control-plane/stack` to create the stack with sensible defaults (`driver` defaults to `undefined`, `extensionPacks` defaults to `[]`).
|
|
265
|
+
|
|
261
266
|
The SQL family provides this via `@prisma-next/family-sql/control`. The `verify()` method handles reading the marker, comparing hashes, and checking codec coverage internally.
|
|
262
267
|
|
|
263
268
|
### `prisma-next db introspect`
|
|
@@ -270,7 +275,7 @@ prisma-next db introspect [--db <url>] [--config <path>] [--json] [-v] [-q] [--t
|
|
|
270
275
|
```
|
|
271
276
|
|
|
272
277
|
Options:
|
|
273
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
278
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
274
279
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
275
280
|
- `--json`: Output as JSON object
|
|
276
281
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -312,7 +317,7 @@ export default defineConfig({
|
|
|
312
317
|
driver: postgresDriver,
|
|
313
318
|
extensionPacks: [],
|
|
314
319
|
db: {
|
|
315
|
-
|
|
320
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
316
321
|
},
|
|
317
322
|
});
|
|
318
323
|
```
|
|
@@ -320,7 +325,7 @@ export default defineConfig({
|
|
|
320
325
|
**Introspection Process:**
|
|
321
326
|
|
|
322
327
|
1. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
323
|
-
2. **Create Family Instance**:
|
|
328
|
+
2. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
324
329
|
3. **Introspect**: Calls `familyInstance.introspect()` which:
|
|
325
330
|
- Queries the database catalog to discover schema structure
|
|
326
331
|
- Returns a family-specific schema IR (e.g., `SqlSchemaIR` for SQL family)
|
|
@@ -387,7 +392,7 @@ sql schema (tables: 2)
|
|
|
387
392
|
|
|
388
393
|
**Error Codes:**
|
|
389
394
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
390
|
-
- `PN-CLI-4005`: Missing database
|
|
395
|
+
- `PN-CLI-4005`: Missing database connection — provide `--db <url>` or set `db.connection` in config
|
|
391
396
|
|
|
392
397
|
**Family Requirements:**
|
|
393
398
|
|
|
@@ -421,7 +426,7 @@ prisma-next db sign [--db <url>] [--config <path>] [--json] [-v] [-q] [--timesta
|
|
|
421
426
|
```
|
|
422
427
|
|
|
423
428
|
Options:
|
|
424
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
429
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
425
430
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
426
431
|
- `--json`: Output as JSON object
|
|
427
432
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -469,7 +474,7 @@ export default defineConfig({
|
|
|
469
474
|
types: 'src/prisma/contract.d.ts',
|
|
470
475
|
},
|
|
471
476
|
db: {
|
|
472
|
-
|
|
477
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
473
478
|
},
|
|
474
479
|
});
|
|
475
480
|
```
|
|
@@ -478,7 +483,7 @@ export default defineConfig({
|
|
|
478
483
|
|
|
479
484
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
480
485
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
481
|
-
3. **Create Family Instance**:
|
|
486
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
482
487
|
4. **Schema Verification (Precondition)**: Calls `familyInstance.schemaVerify()` to verify the database schema matches the contract:
|
|
483
488
|
- If verification fails: Prints schema verification output and exits with code 1 (marker is not written)
|
|
484
489
|
- If verification passes: Proceeds to marker signing
|
|
@@ -495,7 +500,7 @@ export default defineConfig({
|
|
|
495
500
|
Success (new marker):
|
|
496
501
|
```
|
|
497
502
|
✔ Database signed (marker created)
|
|
498
|
-
|
|
503
|
+
storageHash: sha256:abc123...
|
|
499
504
|
profileHash: sha256:def456...
|
|
500
505
|
Total time: 42ms
|
|
501
506
|
```
|
|
@@ -503,16 +508,16 @@ Success (new marker):
|
|
|
503
508
|
Success (updated marker):
|
|
504
509
|
```
|
|
505
510
|
✔ Database signed (marker updated from sha256:old-hash)
|
|
506
|
-
|
|
511
|
+
storageHash: sha256:abc123...
|
|
507
512
|
profileHash: sha256:def456...
|
|
508
|
-
previous
|
|
513
|
+
previous storageHash: sha256:old-hash
|
|
509
514
|
Total time: 42ms
|
|
510
515
|
```
|
|
511
516
|
|
|
512
517
|
Success (already up-to-date):
|
|
513
518
|
```
|
|
514
519
|
✔ Database already signed with this contract
|
|
515
|
-
|
|
520
|
+
storageHash: sha256:abc123...
|
|
516
521
|
profileHash: sha256:def456...
|
|
517
522
|
Total time: 42ms
|
|
518
523
|
```
|
|
@@ -530,7 +535,7 @@ Failure (schema mismatch):
|
|
|
530
535
|
"ok": true,
|
|
531
536
|
"summary": "Database signed (marker created)",
|
|
532
537
|
"contract": {
|
|
533
|
-
"
|
|
538
|
+
"storageHash": "sha256:abc123...",
|
|
534
539
|
"profileHash": "sha256:def456..."
|
|
535
540
|
},
|
|
536
541
|
"target": {
|
|
@@ -557,7 +562,7 @@ For updated markers:
|
|
|
557
562
|
"ok": true,
|
|
558
563
|
"summary": "Database signed (marker updated from sha256:old-hash)",
|
|
559
564
|
"contract": {
|
|
560
|
-
"
|
|
565
|
+
"storageHash": "sha256:abc123...",
|
|
561
566
|
"profileHash": "sha256:def456..."
|
|
562
567
|
},
|
|
563
568
|
"target": {
|
|
@@ -568,7 +573,7 @@ For updated markers:
|
|
|
568
573
|
"created": false,
|
|
569
574
|
"updated": true,
|
|
570
575
|
"previous": {
|
|
571
|
-
"
|
|
576
|
+
"storageHash": "sha256:old-hash",
|
|
572
577
|
"profileHash": "sha256:old-profile-hash"
|
|
573
578
|
}
|
|
574
579
|
},
|
|
@@ -584,7 +589,7 @@ For updated markers:
|
|
|
584
589
|
|
|
585
590
|
**Error Codes:**
|
|
586
591
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
587
|
-
- `PN-CLI-4005`: Missing database
|
|
592
|
+
- `PN-CLI-4005`: Missing database connection — provide `--db <url>` or set `db.connection` in config
|
|
588
593
|
- Exit code 1: Schema verification failed — database schema does not match contract (marker is not written)
|
|
589
594
|
|
|
590
595
|
**Relationship to Other Commands:**
|
|
@@ -631,7 +636,7 @@ prisma-next db init [--db <url>] [--config <path>] [--plan] [--json] [-v] [-q] [
|
|
|
631
636
|
```
|
|
632
637
|
|
|
633
638
|
Options:
|
|
634
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
639
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
635
640
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
636
641
|
- `--plan`: Only show the migration plan, do not apply it
|
|
637
642
|
- `--json [format]`: Output as JSON (`object` only; `ndjson` is not supported for this command)
|
|
@@ -680,7 +685,7 @@ export default defineConfig({
|
|
|
680
685
|
types: 'src/prisma/contract.d.ts',
|
|
681
686
|
},
|
|
682
687
|
db: {
|
|
683
|
-
|
|
688
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
684
689
|
},
|
|
685
690
|
});
|
|
686
691
|
```
|
|
@@ -689,7 +694,7 @@ export default defineConfig({
|
|
|
689
694
|
|
|
690
695
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
691
696
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
692
|
-
3. **Create Family Instance**:
|
|
697
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
693
698
|
4. **Introspect Schema**: Calls `familyInstance.introspect()` to get the current database schema IR
|
|
694
699
|
5. **Validate wiring**: Ensures the contract is compatible with the CLI config:
|
|
695
700
|
- `contract.targetFamily` matches `config.family.familyId`
|
|
@@ -750,7 +755,7 @@ Applying migration plan and verifying schema...
|
|
|
750
755
|
"plan": {
|
|
751
756
|
"targetId": "postgres",
|
|
752
757
|
"destination": {
|
|
753
|
-
"
|
|
758
|
+
"storageHash": "sha256:abc123..."
|
|
754
759
|
},
|
|
755
760
|
"operations": [
|
|
756
761
|
{
|
|
@@ -765,7 +770,7 @@ Applying migration plan and verifying schema...
|
|
|
765
770
|
"operationsExecuted": 4
|
|
766
771
|
},
|
|
767
772
|
"marker": {
|
|
768
|
-
"
|
|
773
|
+
"storageHash": "sha256:abc123..."
|
|
769
774
|
}
|
|
770
775
|
}
|
|
771
776
|
```
|
|
@@ -865,7 +870,7 @@ See `.cursor/rules/config-validation-and-normalization.mdc` for detailed pattern
|
|
|
865
870
|
- **Error Handling**: Uses `exitOverride()` to catch unhandled errors (non-structured errors that fail fast) and print stack traces. Commands handle structured errors themselves via `process.exit()`.
|
|
866
871
|
- **Command Taxonomy**: Groups commands by domain/plane (e.g., `contract emit`)
|
|
867
872
|
- **Help Formatting**: Uses `configureHelp()` to customize help output with styled format matching normal command output. Root help shows "prisma-next" title with command tree; command help shows "prisma-next <command> ➜ <description>" with options and docs URLs. See `utils/output.ts` for help formatters.
|
|
868
|
-
- **Command Descriptions**:
|
|
873
|
+
- **Command Descriptions**: See the “Command Descriptions” section above for `setCommandDescriptions()` usage.
|
|
869
874
|
|
|
870
875
|
### Contract Emit Command (`commands/contract-emit.ts`)
|
|
871
876
|
- Canonical command implementation using commander
|
|
@@ -1058,12 +1063,92 @@ pnpm test:integration # Run integration tests only
|
|
|
1058
1063
|
pnpm test:e2e # Run e2e tests only
|
|
1059
1064
|
```
|
|
1060
1065
|
|
|
1066
|
+
## Programmatic Control API
|
|
1067
|
+
|
|
1068
|
+
The CLI package provides a programmatic control client for running control-plane operations without using the command line. This is useful for:
|
|
1069
|
+
|
|
1070
|
+
- Integration with build tools and CI pipelines
|
|
1071
|
+
- Custom orchestration workflows
|
|
1072
|
+
- Test automation
|
|
1073
|
+
- Programmatic database management
|
|
1074
|
+
|
|
1075
|
+
### Basic Usage
|
|
1076
|
+
|
|
1077
|
+
```typescript
|
|
1078
|
+
import { createControlClient } from '@prisma-next/cli/control-api';
|
|
1079
|
+
import sql from '@prisma-next/family-sql/control';
|
|
1080
|
+
import postgres from '@prisma-next/target-postgres/control';
|
|
1081
|
+
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
1082
|
+
import postgresDriver from '@prisma-next/driver-postgres/control';
|
|
1083
|
+
|
|
1084
|
+
// Create a control client with framework component descriptors
|
|
1085
|
+
const client = createControlClient({
|
|
1086
|
+
family: sql,
|
|
1087
|
+
target: postgres,
|
|
1088
|
+
adapter: postgresAdapter,
|
|
1089
|
+
driver: postgresDriver,
|
|
1090
|
+
extensionPacks: [],
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
try {
|
|
1094
|
+
// Connect to database
|
|
1095
|
+
await client.connect(databaseUrl);
|
|
1096
|
+
|
|
1097
|
+
// Run operations
|
|
1098
|
+
const verifyResult = await client.verify({ contractIR });
|
|
1099
|
+
const initResult = await client.dbInit({ contractIR, mode: 'apply' });
|
|
1100
|
+
const introspectResult = await client.introspect();
|
|
1101
|
+
} finally {
|
|
1102
|
+
// Clean up
|
|
1103
|
+
await client.close();
|
|
1104
|
+
}
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
### Available Operations
|
|
1108
|
+
|
|
1109
|
+
| Method | Description |
|
|
1110
|
+
|--------|-------------|
|
|
1111
|
+
| `connect(url)` | Establishes database connection |
|
|
1112
|
+
| `close()` | Closes connection (idempotent) |
|
|
1113
|
+
| `verify(options)` | Verifies database marker matches contract |
|
|
1114
|
+
| `schemaVerify(options)` | Verifies database schema satisfies contract |
|
|
1115
|
+
| `sign(options)` | Writes contract marker to database |
|
|
1116
|
+
| `dbInit(options)` | Initializes database schema from contract |
|
|
1117
|
+
| `introspect(options)` | Introspects database schema |
|
|
1118
|
+
|
|
1119
|
+
### Result Types
|
|
1120
|
+
|
|
1121
|
+
Operations return structured result types:
|
|
1122
|
+
|
|
1123
|
+
- `verify()` → `VerifyDatabaseResult`
|
|
1124
|
+
- `schemaVerify()` → `VerifyDatabaseSchemaResult`
|
|
1125
|
+
- `sign()` → `SignDatabaseResult`
|
|
1126
|
+
- `dbInit()` → `Result<DbInitSuccess, DbInitFailure>` (uses Result pattern)
|
|
1127
|
+
- `introspect()` → Schema IR (family-specific)
|
|
1128
|
+
|
|
1129
|
+
### Error Handling
|
|
1130
|
+
|
|
1131
|
+
- **Connection errors**: Thrown as exceptions from `connect()`
|
|
1132
|
+
- **Not connected errors**: Thrown if operations called before `connect()`
|
|
1133
|
+
- **Driver not configured**: Thrown if driver is not provided in options
|
|
1134
|
+
- **Operation failures**: Returned as structured results (not thrown)
|
|
1135
|
+
|
|
1136
|
+
### Key Differences from CLI
|
|
1137
|
+
|
|
1138
|
+
| Aspect | CLI | Control API |
|
|
1139
|
+
|--------|-----|-------------|
|
|
1140
|
+
| Config | Reads `prisma-next.config.ts` | Accepts descriptors directly |
|
|
1141
|
+
| File I/O | Reads contract.json from disk | Accepts contract IR directly |
|
|
1142
|
+
| Output | Formats for console | Returns structured data |
|
|
1143
|
+
| Exit codes | Uses `process.exit()` | Returns results/throws |
|
|
1144
|
+
|
|
1061
1145
|
## Entrypoints
|
|
1062
1146
|
|
|
1063
1147
|
The CLI package exports several subpaths for different use cases:
|
|
1064
1148
|
|
|
1065
1149
|
- **`@prisma-next/cli`** (main export): Exports `loadContractFromTs` and `createContractEmitCommand`
|
|
1066
1150
|
- **`@prisma-next/cli/config-types`**: Exports `defineConfig` and config types
|
|
1151
|
+
- **`@prisma-next/cli/control-api`**: Exports `createControlClient` and control API types
|
|
1067
1152
|
- **`@prisma-next/cli/commands/db-init`**: Exports `createDbInitCommand`
|
|
1068
1153
|
- **`@prisma-next/cli/commands/db-introspect`**: Exports `createDbIntrospectCommand`
|
|
1069
1154
|
- **`@prisma-next/cli/commands/db-schema-verify`**: Exports `createDbSchemaVerifyCommand`
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|