@prisma-next/cli 0.3.0-pr.83.4 → 0.3.0-pr.86.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.
- package/README.md +109 -25
- package/dist/chunk-5MPKZYVI.js +47 -0
- package/dist/chunk-5MPKZYVI.js.map +1 -0
- package/dist/{chunk-CVNWLFXO.js → chunk-6EPKRATC.js} +2 -2
- package/dist/chunk-G32TCKQI.js +363 -0
- package/dist/chunk-G32TCKQI.js.map +1 -0
- package/dist/{chunk-QUPBU4KV.js → chunk-U6QI3AZ3.js} +7 -5
- package/dist/{chunk-QUPBU4KV.js.map → chunk-U6QI3AZ3.js.map} +1 -1
- package/dist/chunk-VI2YETW7.js +38 -0
- package/dist/chunk-VI2YETW7.js.map +1 -0
- package/dist/{chunk-BZMBKEEQ.js → chunk-ZG5T6OB5.js} +2 -76
- package/dist/chunk-ZG5T6OB5.js.map +1 -0
- package/dist/cli.js +611 -298
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.js +4 -2
- package/dist/commands/db-init.d.ts.map +1 -1
- package/dist/commands/db-init.js +249 -284
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-introspect.d.ts.map +1 -1
- package/dist/commands/db-introspect.js +18 -19
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-schema-verify.d.ts.map +1 -1
- package/dist/commands/db-schema-verify.js +13 -10
- package/dist/commands/db-schema-verify.js.map +1 -1
- package/dist/commands/db-sign.js +13 -10
- package/dist/commands/db-sign.js.map +1 -1
- package/dist/commands/db-verify.d.ts.map +1 -1
- package/dist/commands/db-verify.js +13 -10
- package/dist/commands/db-verify.js.map +1 -1
- package/dist/control-api/client.d.ts +13 -0
- package/dist/control-api/client.d.ts.map +1 -0
- package/dist/control-api/operations/db-init.d.ts +29 -0
- package/dist/control-api/operations/db-init.d.ts.map +1 -0
- package/dist/control-api/types.d.ts +254 -0
- package/dist/control-api/types.d.ts.map +1 -0
- package/dist/exports/control-api.d.ts +13 -0
- package/dist/exports/control-api.d.ts.map +1 -0
- package/dist/exports/control-api.js +9 -0
- package/dist/exports/control-api.js.map +1 -0
- package/dist/exports/index.js +4 -2
- package/dist/exports/index.js.map +1 -1
- package/dist/utils/cli-errors.d.ts +1 -1
- package/dist/utils/cli-errors.d.ts.map +1 -1
- package/dist/utils/progress-adapter.d.ts +26 -0
- package/dist/utils/progress-adapter.d.ts.map +1 -0
- package/package.json +14 -10
- package/src/commands/db-init.ts +261 -355
- package/src/commands/db-introspect.ts +16 -18
- package/src/commands/db-schema-verify.ts +6 -7
- package/src/commands/db-sign.ts +6 -6
- package/src/commands/db-verify.ts +6 -7
- package/src/control-api/client.ts +259 -0
- package/src/control-api/operations/db-init.ts +273 -0
- package/src/control-api/types.ts +311 -0
- package/src/exports/control-api.ts +37 -0
- package/src/utils/cli-errors.ts +1 -1
- package/src/utils/progress-adapter.ts +86 -0
- package/dist/chunk-BZMBKEEQ.js.map +0 -1
- /package/dist/{chunk-CVNWLFXO.js.map → chunk-6EPKRATC.js.map} +0 -0
package/README.md
CHANGED
|
@@ -61,12 +61,11 @@ prisma-next contract emit [--config <path>] [--json] [-v] [-q] [--timestamps] [-
|
|
|
61
61
|
|
|
62
62
|
**Config File Requirements:**
|
|
63
63
|
|
|
64
|
-
The `contract emit` command
|
|
64
|
+
The `contract emit` command does not require a `driver` in the config since it doesn't connect to a database:
|
|
65
65
|
|
|
66
66
|
```typescript
|
|
67
67
|
import { defineConfig } from '@prisma-next/cli/config-types';
|
|
68
68
|
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
69
|
-
import postgresDriver from '@prisma-next/driver-postgres/control';
|
|
70
69
|
import postgres from '@prisma-next/target-postgres/control';
|
|
71
70
|
import sql from '@prisma-next/family-sql/control';
|
|
72
71
|
import { contract } from './prisma/contract';
|
|
@@ -75,7 +74,6 @@ export default defineConfig({
|
|
|
75
74
|
family: sql,
|
|
76
75
|
target: postgres,
|
|
77
76
|
adapter: postgresAdapter,
|
|
78
|
-
driver: postgresDriver, // Required even though emit doesn't use it
|
|
79
77
|
extensionPacks: [],
|
|
80
78
|
contract: {
|
|
81
79
|
source: contract,
|
|
@@ -116,7 +114,7 @@ prisma-next db verify [--db <url>] [--config <path>] [--json] [-v] [-q] [--times
|
|
|
116
114
|
```
|
|
117
115
|
|
|
118
116
|
Options:
|
|
119
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
117
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
120
118
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
121
119
|
- `--json`: Output as JSON object
|
|
122
120
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -164,7 +162,7 @@ export default defineConfig({
|
|
|
164
162
|
types: 'src/prisma/contract.d.ts',
|
|
165
163
|
},
|
|
166
164
|
db: {
|
|
167
|
-
|
|
165
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
168
166
|
},
|
|
169
167
|
});
|
|
170
168
|
```
|
|
@@ -173,7 +171,7 @@ export default defineConfig({
|
|
|
173
171
|
|
|
174
172
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
175
173
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
176
|
-
3. **Create Family Instance**:
|
|
174
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
177
175
|
4. **Verify**: Calls `familyInstance.verify()` which:
|
|
178
176
|
- Reads the contract marker from the database
|
|
179
177
|
- Compares marker presence: Returns `PN-RTM-3001` if marker is missing
|
|
@@ -235,16 +233,20 @@ Failure:
|
|
|
235
233
|
|
|
236
234
|
**Family Requirements:**
|
|
237
235
|
|
|
238
|
-
The family must provide a `create()` method in the family descriptor that returns a `ControlFamilyInstance` with a `verify()` method:
|
|
236
|
+
The family must provide a `create()` method in the family descriptor that accepts a `ControlPlaneStack` and returns a `ControlFamilyInstance` with a `verify()` method:
|
|
239
237
|
|
|
240
238
|
```typescript
|
|
241
|
-
interface ControlFamilyDescriptor {
|
|
242
|
-
create(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
239
|
+
interface ControlFamilyDescriptor<TFamilyId, TFamilyInstance> {
|
|
240
|
+
create<TTargetId extends string>(
|
|
241
|
+
stack: ControlPlaneStack<TFamilyId, TTargetId>,
|
|
242
|
+
): TFamilyInstance;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
interface ControlPlaneStack<TFamilyId, TTargetId> {
|
|
246
|
+
readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;
|
|
247
|
+
readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;
|
|
248
|
+
readonly driver: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;
|
|
249
|
+
readonly extensionPacks: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
interface ControlFamilyInstance {
|
|
@@ -258,6 +260,8 @@ interface ControlFamilyInstance {
|
|
|
258
260
|
}
|
|
259
261
|
```
|
|
260
262
|
|
|
263
|
+
Use `createControlPlaneStack()` from `@prisma-next/core-control-plane/stack` to create the stack with sensible defaults (`driver` defaults to `undefined`, `extensionPacks` defaults to `[]`).
|
|
264
|
+
|
|
261
265
|
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
266
|
|
|
263
267
|
### `prisma-next db introspect`
|
|
@@ -270,7 +274,7 @@ prisma-next db introspect [--db <url>] [--config <path>] [--json] [-v] [-q] [--t
|
|
|
270
274
|
```
|
|
271
275
|
|
|
272
276
|
Options:
|
|
273
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
277
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
274
278
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
275
279
|
- `--json`: Output as JSON object
|
|
276
280
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -312,7 +316,7 @@ export default defineConfig({
|
|
|
312
316
|
driver: postgresDriver,
|
|
313
317
|
extensionPacks: [],
|
|
314
318
|
db: {
|
|
315
|
-
|
|
319
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
316
320
|
},
|
|
317
321
|
});
|
|
318
322
|
```
|
|
@@ -320,7 +324,7 @@ export default defineConfig({
|
|
|
320
324
|
**Introspection Process:**
|
|
321
325
|
|
|
322
326
|
1. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
323
|
-
2. **Create Family Instance**:
|
|
327
|
+
2. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
324
328
|
3. **Introspect**: Calls `familyInstance.introspect()` which:
|
|
325
329
|
- Queries the database catalog to discover schema structure
|
|
326
330
|
- Returns a family-specific schema IR (e.g., `SqlSchemaIR` for SQL family)
|
|
@@ -387,7 +391,7 @@ sql schema (tables: 2)
|
|
|
387
391
|
|
|
388
392
|
**Error Codes:**
|
|
389
393
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
390
|
-
- `PN-CLI-4005`: Missing database
|
|
394
|
+
- `PN-CLI-4005`: Missing database connection — provide `--db <url>` or set `db.connection` in config
|
|
391
395
|
|
|
392
396
|
**Family Requirements:**
|
|
393
397
|
|
|
@@ -421,7 +425,7 @@ prisma-next db sign [--db <url>] [--config <path>] [--json] [-v] [-q] [--timesta
|
|
|
421
425
|
```
|
|
422
426
|
|
|
423
427
|
Options:
|
|
424
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
428
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
425
429
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
426
430
|
- `--json`: Output as JSON object
|
|
427
431
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -469,7 +473,7 @@ export default defineConfig({
|
|
|
469
473
|
types: 'src/prisma/contract.d.ts',
|
|
470
474
|
},
|
|
471
475
|
db: {
|
|
472
|
-
|
|
476
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
473
477
|
},
|
|
474
478
|
});
|
|
475
479
|
```
|
|
@@ -478,7 +482,7 @@ export default defineConfig({
|
|
|
478
482
|
|
|
479
483
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
480
484
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
481
|
-
3. **Create Family Instance**:
|
|
485
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
482
486
|
4. **Schema Verification (Precondition)**: Calls `familyInstance.schemaVerify()` to verify the database schema matches the contract:
|
|
483
487
|
- If verification fails: Prints schema verification output and exits with code 1 (marker is not written)
|
|
484
488
|
- If verification passes: Proceeds to marker signing
|
|
@@ -584,7 +588,7 @@ For updated markers:
|
|
|
584
588
|
|
|
585
589
|
**Error Codes:**
|
|
586
590
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
587
|
-
- `PN-CLI-4005`: Missing database
|
|
591
|
+
- `PN-CLI-4005`: Missing database connection — provide `--db <url>` or set `db.connection` in config
|
|
588
592
|
- Exit code 1: Schema verification failed — database schema does not match contract (marker is not written)
|
|
589
593
|
|
|
590
594
|
**Relationship to Other Commands:**
|
|
@@ -631,7 +635,7 @@ prisma-next db init [--db <url>] [--config <path>] [--plan] [--json] [-v] [-q] [
|
|
|
631
635
|
```
|
|
632
636
|
|
|
633
637
|
Options:
|
|
634
|
-
- `--db <url>`: Database connection string (optional; defaults to `config.db.
|
|
638
|
+
- `--db <url>`: Database connection string (optional; defaults to `config.db.connection` if set)
|
|
635
639
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
636
640
|
- `--plan`: Only show the migration plan, do not apply it
|
|
637
641
|
- `--json [format]`: Output as JSON (`object` only; `ndjson` is not supported for this command)
|
|
@@ -680,7 +684,7 @@ export default defineConfig({
|
|
|
680
684
|
types: 'src/prisma/contract.d.ts',
|
|
681
685
|
},
|
|
682
686
|
db: {
|
|
683
|
-
|
|
687
|
+
connection: process.env.DATABASE_URL, // Optional: can also use --db flag
|
|
684
688
|
},
|
|
685
689
|
});
|
|
686
690
|
```
|
|
@@ -689,7 +693,7 @@ export default defineConfig({
|
|
|
689
693
|
|
|
690
694
|
1. **Load Contract**: Reads the emitted `contract.json` from `config.contract.output`
|
|
691
695
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
692
|
-
3. **Create Family Instance**:
|
|
696
|
+
3. **Create Family Instance**: Creates a `ControlPlaneStack` via `createControlPlaneStack()` and passes it to `config.family.create(stack)` to create a family instance
|
|
693
697
|
4. **Introspect Schema**: Calls `familyInstance.introspect()` to get the current database schema IR
|
|
694
698
|
5. **Validate wiring**: Ensures the contract is compatible with the CLI config:
|
|
695
699
|
- `contract.targetFamily` matches `config.family.familyId`
|
|
@@ -1058,12 +1062,92 @@ pnpm test:integration # Run integration tests only
|
|
|
1058
1062
|
pnpm test:e2e # Run e2e tests only
|
|
1059
1063
|
```
|
|
1060
1064
|
|
|
1065
|
+
## Programmatic Control API
|
|
1066
|
+
|
|
1067
|
+
The CLI package provides a programmatic control client for running control-plane operations without using the command line. This is useful for:
|
|
1068
|
+
|
|
1069
|
+
- Integration with build tools and CI pipelines
|
|
1070
|
+
- Custom orchestration workflows
|
|
1071
|
+
- Test automation
|
|
1072
|
+
- Programmatic database management
|
|
1073
|
+
|
|
1074
|
+
### Basic Usage
|
|
1075
|
+
|
|
1076
|
+
```typescript
|
|
1077
|
+
import { createControlClient } from '@prisma-next/cli/control-api';
|
|
1078
|
+
import sql from '@prisma-next/family-sql/control';
|
|
1079
|
+
import postgres from '@prisma-next/target-postgres/control';
|
|
1080
|
+
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
1081
|
+
import postgresDriver from '@prisma-next/driver-postgres/control';
|
|
1082
|
+
|
|
1083
|
+
// Create a control client with framework component descriptors
|
|
1084
|
+
const client = createControlClient({
|
|
1085
|
+
family: sql,
|
|
1086
|
+
target: postgres,
|
|
1087
|
+
adapter: postgresAdapter,
|
|
1088
|
+
driver: postgresDriver,
|
|
1089
|
+
extensionPacks: [],
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
try {
|
|
1093
|
+
// Connect to database
|
|
1094
|
+
await client.connect(databaseUrl);
|
|
1095
|
+
|
|
1096
|
+
// Run operations
|
|
1097
|
+
const verifyResult = await client.verify({ contractIR });
|
|
1098
|
+
const initResult = await client.dbInit({ contractIR, mode: 'apply' });
|
|
1099
|
+
const introspectResult = await client.introspect();
|
|
1100
|
+
} finally {
|
|
1101
|
+
// Clean up
|
|
1102
|
+
await client.close();
|
|
1103
|
+
}
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
### Available Operations
|
|
1107
|
+
|
|
1108
|
+
| Method | Description |
|
|
1109
|
+
|--------|-------------|
|
|
1110
|
+
| `connect(url)` | Establishes database connection |
|
|
1111
|
+
| `close()` | Closes connection (idempotent) |
|
|
1112
|
+
| `verify(options)` | Verifies database marker matches contract |
|
|
1113
|
+
| `schemaVerify(options)` | Verifies database schema satisfies contract |
|
|
1114
|
+
| `sign(options)` | Writes contract marker to database |
|
|
1115
|
+
| `dbInit(options)` | Initializes database schema from contract |
|
|
1116
|
+
| `introspect(options)` | Introspects database schema |
|
|
1117
|
+
|
|
1118
|
+
### Result Types
|
|
1119
|
+
|
|
1120
|
+
Operations return structured result types:
|
|
1121
|
+
|
|
1122
|
+
- `verify()` → `VerifyDatabaseResult`
|
|
1123
|
+
- `schemaVerify()` → `VerifyDatabaseSchemaResult`
|
|
1124
|
+
- `sign()` → `SignDatabaseResult`
|
|
1125
|
+
- `dbInit()` → `Result<DbInitSuccess, DbInitFailure>` (uses Result pattern)
|
|
1126
|
+
- `introspect()` → Schema IR (family-specific)
|
|
1127
|
+
|
|
1128
|
+
### Error Handling
|
|
1129
|
+
|
|
1130
|
+
- **Connection errors**: Thrown as exceptions from `connect()`
|
|
1131
|
+
- **Not connected errors**: Thrown if operations called before `connect()`
|
|
1132
|
+
- **Driver not configured**: Thrown if driver is not provided in options
|
|
1133
|
+
- **Operation failures**: Returned as structured results (not thrown)
|
|
1134
|
+
|
|
1135
|
+
### Key Differences from CLI
|
|
1136
|
+
|
|
1137
|
+
| Aspect | CLI | Control API |
|
|
1138
|
+
|--------|-----|-------------|
|
|
1139
|
+
| Config | Reads `prisma-next.config.ts` | Accepts descriptors directly |
|
|
1140
|
+
| File I/O | Reads contract.json from disk | Accepts contract IR directly |
|
|
1141
|
+
| Output | Formats for console | Returns structured data |
|
|
1142
|
+
| Exit codes | Uses `process.exit()` | Returns results/throws |
|
|
1143
|
+
|
|
1061
1144
|
## Entrypoints
|
|
1062
1145
|
|
|
1063
1146
|
The CLI package exports several subpaths for different use cases:
|
|
1064
1147
|
|
|
1065
1148
|
- **`@prisma-next/cli`** (main export): Exports `loadContractFromTs` and `createContractEmitCommand`
|
|
1066
1149
|
- **`@prisma-next/cli/config-types`**: Exports `defineConfig` and config types
|
|
1150
|
+
- **`@prisma-next/cli/control-api`**: Exports `createControlClient` and control API types
|
|
1067
1151
|
- **`@prisma-next/cli/commands/db-init`**: Exports `createDbInitCommand`
|
|
1068
1152
|
- **`@prisma-next/cli/commands/db-introspect`**: Exports `createDbIntrospectCommand`
|
|
1069
1153
|
- **`@prisma-next/cli/commands/db-schema-verify`**: Exports `createDbSchemaVerifyCommand`
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CliStructuredError
|
|
3
|
+
} from "./chunk-VI2YETW7.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/action.ts
|
|
6
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
7
|
+
async function performAction(fn) {
|
|
8
|
+
try {
|
|
9
|
+
const value = await fn();
|
|
10
|
+
return ok(value);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error instanceof CliStructuredError) {
|
|
13
|
+
return notOk(error);
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/utils/spinner.ts
|
|
20
|
+
import ora from "ora";
|
|
21
|
+
async function withSpinner(operation, options) {
|
|
22
|
+
const { message, flags } = options;
|
|
23
|
+
const shouldShowSpinner = !flags.quiet && flags.json !== "object" && process.stdout.isTTY;
|
|
24
|
+
if (!shouldShowSpinner) {
|
|
25
|
+
return operation();
|
|
26
|
+
}
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
const spinner = ora({
|
|
29
|
+
text: message,
|
|
30
|
+
color: flags.color !== false ? "cyan" : false
|
|
31
|
+
}).start();
|
|
32
|
+
try {
|
|
33
|
+
const result = await operation();
|
|
34
|
+
const elapsed = Date.now() - startTime;
|
|
35
|
+
spinner.succeed(`${message} (${elapsed}ms)`);
|
|
36
|
+
return result;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
spinner.fail(`${message} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
performAction,
|
|
45
|
+
withSpinner
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=chunk-5MPKZYVI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/action.ts","../src/utils/spinner.ts"],"sourcesContent":["import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { CliStructuredError } from './cli-errors';\n\nexport type CliResult<T> = Result<T, CliStructuredError>;\n\n/**\n * Performs an async action and catches structured errors, returning a Result.\n * Only catches CliStructuredError instances - other errors are allowed to propagate (fail fast).\n * If the function throws a CliStructuredError, it's caught and converted to a NotOk result.\n */\nexport async function performAction<T>(fn: () => Promise<T>): Promise<CliResult<T>> {\n try {\n const value = await fn();\n return ok(value);\n } catch (error) {\n // Only catch structured errors - let other errors propagate (fail fast)\n if (error instanceof CliStructuredError) {\n return notOk(error);\n }\n // Re-throw non-structured errors to fail fast\n throw error;\n }\n}\n\n/**\n * Wraps a synchronous function to catch structured errors and return a Result.\n * Only catches CliStructuredError instances - other errors are allowed to propagate (fail fast).\n * If the function throws a CliStructuredError, it's caught and converted to a NotOk result.\n */\nexport function wrapSync<T>(fn: () => T): CliResult<T> {\n try {\n const value = fn();\n return ok(value);\n } catch (error) {\n // Only catch structured errors - let other errors propagate (fail fast)\n if (error instanceof CliStructuredError) {\n return notOk(error);\n }\n // Re-throw non-structured errors to fail fast\n throw error;\n }\n}\n","import ora from 'ora';\nimport type { GlobalFlags } from './global-flags';\n\n/**\n * Options for the withSpinner helper function.\n */\ninterface WithSpinnerOptions {\n /**\n * The message to display in the spinner.\n */\n readonly message: string;\n /**\n * Global flags that control spinner behavior (quiet, json, color).\n */\n readonly flags: GlobalFlags;\n}\n\n/**\n * Wraps an async operation with a spinner.\n *\n * The spinner respects:\n * - `flags.quiet`: No spinner if quiet mode is enabled\n * - `flags.json === 'object'`: No spinner if JSON output is enabled\n * - Non-TTY environments: No spinner if stdout is not a TTY\n *\n * @param operation - The async operation to execute\n * @param options - Spinner configuration options\n * @returns The result of the operation\n */\nexport async function withSpinner<T>(\n operation: () => Promise<T>,\n options: WithSpinnerOptions,\n): Promise<T> {\n const { message, flags } = options;\n\n // Skip spinner if quiet, JSON output, or non-TTY\n const shouldShowSpinner = !flags.quiet && flags.json !== 'object' && process.stdout.isTTY;\n\n if (!shouldShowSpinner) {\n // Just execute the operation without spinner\n return operation();\n }\n\n // Start spinner immediately\n const startTime = Date.now();\n const spinner = ora({\n text: message,\n color: flags.color !== false ? 'cyan' : false,\n }).start();\n\n try {\n // Execute the operation\n const result = await operation();\n\n // Mark spinner as succeeded\n const elapsed = Date.now() - startTime;\n spinner.succeed(`${message} (${elapsed}ms)`);\n\n return result;\n } catch (error) {\n // Mark spinner as failed\n spinner.fail(`${message} failed: ${error instanceof Error ? error.message : String(error)}`);\n\n // Re-throw the error\n throw error;\n }\n}\n"],"mappings":";;;;;AACA,SAAS,OAAO,UAAU;AAU1B,eAAsB,cAAiB,IAA6C;AAClF,MAAI;AACF,UAAM,QAAQ,MAAM,GAAG;AACvB,WAAO,GAAG,KAAK;AAAA,EACjB,SAAS,OAAO;AAEd,QAAI,iBAAiB,oBAAoB;AACvC,aAAO,MAAM,KAAK;AAAA,IACpB;AAEA,UAAM;AAAA,EACR;AACF;;;ACvBA,OAAO,SAAS;AA6BhB,eAAsB,YACpB,WACA,SACY;AACZ,QAAM,EAAE,SAAS,MAAM,IAAI;AAG3B,QAAM,oBAAoB,CAAC,MAAM,SAAS,MAAM,SAAS,YAAY,QAAQ,OAAO;AAEpF,MAAI,CAAC,mBAAmB;AAEtB,WAAO,UAAU;AAAA,EACnB;AAGA,QAAM,YAAY,KAAK,IAAI;AAC3B,QAAM,UAAU,IAAI;AAAA,IAClB,MAAM;AAAA,IACN,OAAO,MAAM,UAAU,QAAQ,SAAS;AAAA,EAC1C,CAAC,EAAE,MAAM;AAET,MAAI;AAEF,UAAM,SAAS,MAAM,UAAU;AAG/B,UAAM,UAAU,KAAK,IAAI,IAAI;AAC7B,YAAQ,QAAQ,GAAG,OAAO,KAAK,OAAO,KAAK;AAE3C,WAAO;AAAA,EACT,SAAS,OAAO;AAEd,YAAQ,KAAK,GAAG,OAAO,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAG3F,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
errorConfigValidation,
|
|
3
3
|
errorContractMissingExtensionPacks
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VI2YETW7.js";
|
|
5
5
|
|
|
6
6
|
// src/utils/framework-components.ts
|
|
7
7
|
import {
|
|
@@ -88,4 +88,4 @@ export {
|
|
|
88
88
|
assertFrameworkComponentsCompatible,
|
|
89
89
|
assertContractRequirementsSatisfied
|
|
90
90
|
};
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-6EPKRATC.js.map
|