@prisma-next/cli 0.3.0-dev.14 → 0.3.0-dev.16
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/dist/chunk-5MPKZYVI.js +47 -0
- package/dist/chunk-5MPKZYVI.js.map +1 -0
- package/dist/chunk-74IELXRA.js +371 -0
- package/dist/chunk-74IELXRA.js.map +1 -0
- package/dist/{chunk-MG7PBERL.js → chunk-U6QI3AZ3.js} +7 -5
- package/dist/{chunk-MG7PBERL.js.map → chunk-U6QI3AZ3.js.map} +1 -1
- package/dist/{chunk-DIJPT5TZ.js → chunk-ZG5T6OB5.js} +2 -46
- package/dist/chunk-ZG5T6OB5.js.map +1 -0
- package/dist/cli.js +593 -268
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.js +3 -2
- package/dist/commands/db-init.d.ts.map +1 -1
- package/dist/commands/db-init.js +238 -275
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-introspect.js +6 -4
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-schema-verify.js +6 -4
- package/dist/commands/db-schema-verify.js.map +1 -1
- package/dist/commands/db-sign.js +6 -4
- package/dist/commands/db-sign.js.map +1 -1
- package/dist/commands/db-verify.js +6 -4
- package/dist/commands/db-verify.js.map +1 -1
- package/dist/control-api/operations/db-init.d.ts +3 -1
- package/dist/control-api/operations/db-init.d.ts.map +1 -1
- package/dist/control-api/types.d.ts +54 -1
- package/dist/control-api/types.d.ts.map +1 -1
- package/dist/exports/control-api.d.ts +1 -1
- package/dist/exports/control-api.d.ts.map +1 -1
- package/dist/exports/control-api.js +3 -234
- package/dist/exports/control-api.js.map +1 -1
- package/dist/exports/index.js +3 -2
- package/dist/exports/index.js.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 +10 -10
- package/src/commands/db-init.ts +262 -355
- package/src/control-api/client.ts +30 -0
- package/src/control-api/operations/db-init.ts +116 -2
- package/src/control-api/types.ts +63 -1
- package/src/exports/control-api.ts +3 -0
- package/src/utils/progress-adapter.ts +86 -0
- package/dist/chunk-DIJPT5TZ.js.map +0 -1
|
@@ -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":[]}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertFrameworkComponentsCompatible
|
|
3
|
+
} from "./chunk-6EPKRATC.js";
|
|
4
|
+
|
|
5
|
+
// src/control-api/client.ts
|
|
6
|
+
import { createControlPlaneStack } from "@prisma-next/core-control-plane/stack";
|
|
7
|
+
|
|
8
|
+
// src/control-api/operations/db-init.ts
|
|
9
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
10
|
+
async function executeDbInit(options) {
|
|
11
|
+
const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents, onProgress } = options;
|
|
12
|
+
const planner = migrations.createPlanner(familyInstance);
|
|
13
|
+
const runner = migrations.createRunner(familyInstance);
|
|
14
|
+
const introspectSpanId = "introspect";
|
|
15
|
+
onProgress?.({
|
|
16
|
+
action: "dbInit",
|
|
17
|
+
kind: "spanStart",
|
|
18
|
+
spanId: introspectSpanId,
|
|
19
|
+
label: "Introspecting database schema"
|
|
20
|
+
});
|
|
21
|
+
const schemaIR = await familyInstance.introspect({ driver });
|
|
22
|
+
onProgress?.({
|
|
23
|
+
action: "dbInit",
|
|
24
|
+
kind: "spanEnd",
|
|
25
|
+
spanId: introspectSpanId,
|
|
26
|
+
outcome: "ok"
|
|
27
|
+
});
|
|
28
|
+
const policy = { allowedOperationClasses: ["additive"] };
|
|
29
|
+
const planSpanId = "plan";
|
|
30
|
+
onProgress?.({
|
|
31
|
+
action: "dbInit",
|
|
32
|
+
kind: "spanStart",
|
|
33
|
+
spanId: planSpanId,
|
|
34
|
+
label: "Planning migration"
|
|
35
|
+
});
|
|
36
|
+
const plannerResult = await planner.plan({
|
|
37
|
+
contract: contractIR,
|
|
38
|
+
schema: schemaIR,
|
|
39
|
+
policy,
|
|
40
|
+
frameworkComponents
|
|
41
|
+
});
|
|
42
|
+
if (plannerResult.kind === "failure") {
|
|
43
|
+
onProgress?.({
|
|
44
|
+
action: "dbInit",
|
|
45
|
+
kind: "spanEnd",
|
|
46
|
+
spanId: planSpanId,
|
|
47
|
+
outcome: "error"
|
|
48
|
+
});
|
|
49
|
+
return notOk({
|
|
50
|
+
code: "PLANNING_FAILED",
|
|
51
|
+
summary: "Migration planning failed due to conflicts",
|
|
52
|
+
conflicts: plannerResult.conflicts,
|
|
53
|
+
why: void 0,
|
|
54
|
+
meta: void 0
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const migrationPlan = plannerResult.plan;
|
|
58
|
+
onProgress?.({
|
|
59
|
+
action: "dbInit",
|
|
60
|
+
kind: "spanEnd",
|
|
61
|
+
spanId: planSpanId,
|
|
62
|
+
outcome: "ok"
|
|
63
|
+
});
|
|
64
|
+
const checkMarkerSpanId = "checkMarker";
|
|
65
|
+
onProgress?.({
|
|
66
|
+
action: "dbInit",
|
|
67
|
+
kind: "spanStart",
|
|
68
|
+
spanId: checkMarkerSpanId,
|
|
69
|
+
label: "Checking contract marker"
|
|
70
|
+
});
|
|
71
|
+
const existingMarker = await familyInstance.readMarker({ driver });
|
|
72
|
+
if (existingMarker) {
|
|
73
|
+
const markerMatchesDestination = existingMarker.coreHash === migrationPlan.destination.coreHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash);
|
|
74
|
+
if (markerMatchesDestination) {
|
|
75
|
+
onProgress?.({
|
|
76
|
+
action: "dbInit",
|
|
77
|
+
kind: "spanEnd",
|
|
78
|
+
spanId: checkMarkerSpanId,
|
|
79
|
+
outcome: "skipped"
|
|
80
|
+
});
|
|
81
|
+
const result2 = {
|
|
82
|
+
mode,
|
|
83
|
+
plan: { operations: [] },
|
|
84
|
+
...mode === "apply" ? {
|
|
85
|
+
execution: { operationsPlanned: 0, operationsExecuted: 0 },
|
|
86
|
+
marker: {
|
|
87
|
+
coreHash: existingMarker.coreHash,
|
|
88
|
+
profileHash: existingMarker.profileHash
|
|
89
|
+
}
|
|
90
|
+
} : {},
|
|
91
|
+
summary: "Database already at target contract state"
|
|
92
|
+
};
|
|
93
|
+
return ok(result2);
|
|
94
|
+
}
|
|
95
|
+
onProgress?.({
|
|
96
|
+
action: "dbInit",
|
|
97
|
+
kind: "spanEnd",
|
|
98
|
+
spanId: checkMarkerSpanId,
|
|
99
|
+
outcome: "error"
|
|
100
|
+
});
|
|
101
|
+
return notOk({
|
|
102
|
+
code: "MARKER_ORIGIN_MISMATCH",
|
|
103
|
+
summary: "Existing contract marker does not match plan destination",
|
|
104
|
+
marker: {
|
|
105
|
+
coreHash: existingMarker.coreHash,
|
|
106
|
+
profileHash: existingMarker.profileHash
|
|
107
|
+
},
|
|
108
|
+
destination: {
|
|
109
|
+
coreHash: migrationPlan.destination.coreHash,
|
|
110
|
+
profileHash: migrationPlan.destination.profileHash
|
|
111
|
+
},
|
|
112
|
+
why: void 0,
|
|
113
|
+
conflicts: void 0,
|
|
114
|
+
meta: void 0
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
onProgress?.({
|
|
118
|
+
action: "dbInit",
|
|
119
|
+
kind: "spanEnd",
|
|
120
|
+
spanId: checkMarkerSpanId,
|
|
121
|
+
outcome: "ok"
|
|
122
|
+
});
|
|
123
|
+
if (mode === "plan") {
|
|
124
|
+
const result2 = {
|
|
125
|
+
mode: "plan",
|
|
126
|
+
plan: { operations: migrationPlan.operations },
|
|
127
|
+
summary: `Planned ${migrationPlan.operations.length} operation(s)`
|
|
128
|
+
};
|
|
129
|
+
return ok(result2);
|
|
130
|
+
}
|
|
131
|
+
const applySpanId = "apply";
|
|
132
|
+
onProgress?.({
|
|
133
|
+
action: "dbInit",
|
|
134
|
+
kind: "spanStart",
|
|
135
|
+
spanId: applySpanId,
|
|
136
|
+
label: "Applying migration plan"
|
|
137
|
+
});
|
|
138
|
+
const callbacks = onProgress ? {
|
|
139
|
+
onOperationStart: (op) => {
|
|
140
|
+
onProgress({
|
|
141
|
+
action: "dbInit",
|
|
142
|
+
kind: "spanStart",
|
|
143
|
+
spanId: `operation:${op.id}`,
|
|
144
|
+
parentSpanId: applySpanId,
|
|
145
|
+
label: op.label
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
onOperationComplete: (op) => {
|
|
149
|
+
onProgress({
|
|
150
|
+
action: "dbInit",
|
|
151
|
+
kind: "spanEnd",
|
|
152
|
+
spanId: `operation:${op.id}`,
|
|
153
|
+
outcome: "ok"
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
} : void 0;
|
|
157
|
+
const runnerResult = await runner.execute({
|
|
158
|
+
plan: migrationPlan,
|
|
159
|
+
driver,
|
|
160
|
+
destinationContract: contractIR,
|
|
161
|
+
policy,
|
|
162
|
+
...callbacks ? { callbacks } : {},
|
|
163
|
+
// db init plans and applies back-to-back from a fresh introspection, so per-operation
|
|
164
|
+
// pre/postchecks and the idempotency probe are usually redundant overhead. We still
|
|
165
|
+
// enforce marker/origin compatibility and a full schema verification after apply.
|
|
166
|
+
executionChecks: {
|
|
167
|
+
prechecks: false,
|
|
168
|
+
postchecks: false,
|
|
169
|
+
idempotencyChecks: false
|
|
170
|
+
},
|
|
171
|
+
frameworkComponents
|
|
172
|
+
});
|
|
173
|
+
if (!runnerResult.ok) {
|
|
174
|
+
onProgress?.({
|
|
175
|
+
action: "dbInit",
|
|
176
|
+
kind: "spanEnd",
|
|
177
|
+
spanId: applySpanId,
|
|
178
|
+
outcome: "error"
|
|
179
|
+
});
|
|
180
|
+
return notOk({
|
|
181
|
+
code: "RUNNER_FAILED",
|
|
182
|
+
summary: runnerResult.failure.summary,
|
|
183
|
+
why: runnerResult.failure.why,
|
|
184
|
+
meta: runnerResult.failure.meta,
|
|
185
|
+
conflicts: void 0
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const execution = runnerResult.value;
|
|
189
|
+
onProgress?.({
|
|
190
|
+
action: "dbInit",
|
|
191
|
+
kind: "spanEnd",
|
|
192
|
+
spanId: applySpanId,
|
|
193
|
+
outcome: "ok"
|
|
194
|
+
});
|
|
195
|
+
const result = {
|
|
196
|
+
mode: "apply",
|
|
197
|
+
plan: { operations: migrationPlan.operations },
|
|
198
|
+
execution: {
|
|
199
|
+
operationsPlanned: execution.operationsPlanned,
|
|
200
|
+
operationsExecuted: execution.operationsExecuted
|
|
201
|
+
},
|
|
202
|
+
marker: migrationPlan.destination.profileHash ? {
|
|
203
|
+
coreHash: migrationPlan.destination.coreHash,
|
|
204
|
+
profileHash: migrationPlan.destination.profileHash
|
|
205
|
+
} : { coreHash: migrationPlan.destination.coreHash },
|
|
206
|
+
summary: `Applied ${execution.operationsExecuted} operation(s), marker written`
|
|
207
|
+
};
|
|
208
|
+
return ok(result);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/control-api/client.ts
|
|
212
|
+
function createControlClient(options) {
|
|
213
|
+
return new ControlClientImpl(options);
|
|
214
|
+
}
|
|
215
|
+
var ControlClientImpl = class {
|
|
216
|
+
options;
|
|
217
|
+
stack = null;
|
|
218
|
+
driver = null;
|
|
219
|
+
familyInstance = null;
|
|
220
|
+
frameworkComponents = null;
|
|
221
|
+
initialized = false;
|
|
222
|
+
defaultConnection;
|
|
223
|
+
constructor(options) {
|
|
224
|
+
this.options = options;
|
|
225
|
+
this.defaultConnection = options.connection;
|
|
226
|
+
}
|
|
227
|
+
init() {
|
|
228
|
+
if (this.initialized) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
this.stack = createControlPlaneStack({
|
|
232
|
+
target: this.options.target,
|
|
233
|
+
adapter: this.options.adapter,
|
|
234
|
+
driver: this.options.driver,
|
|
235
|
+
extensionPacks: this.options.extensionPacks
|
|
236
|
+
});
|
|
237
|
+
this.familyInstance = this.options.family.create(this.stack);
|
|
238
|
+
const rawComponents = [
|
|
239
|
+
this.options.target,
|
|
240
|
+
this.options.adapter,
|
|
241
|
+
...this.options.extensionPacks ?? []
|
|
242
|
+
];
|
|
243
|
+
this.frameworkComponents = assertFrameworkComponentsCompatible(
|
|
244
|
+
this.options.family.familyId,
|
|
245
|
+
this.options.target.targetId,
|
|
246
|
+
rawComponents
|
|
247
|
+
);
|
|
248
|
+
this.initialized = true;
|
|
249
|
+
}
|
|
250
|
+
async connect(connection) {
|
|
251
|
+
this.init();
|
|
252
|
+
if (this.driver) {
|
|
253
|
+
throw new Error("Already connected. Call close() before reconnecting.");
|
|
254
|
+
}
|
|
255
|
+
const resolvedConnection = connection ?? this.defaultConnection;
|
|
256
|
+
if (resolvedConnection === void 0) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
"No connection provided. Pass a connection to connect() or provide a default connection when creating the client."
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (!this.stack?.driver) {
|
|
262
|
+
throw new Error(
|
|
263
|
+
"Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations."
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
this.driver = await this.stack?.driver.create(resolvedConnection);
|
|
267
|
+
}
|
|
268
|
+
async close() {
|
|
269
|
+
if (this.driver) {
|
|
270
|
+
await this.driver.close();
|
|
271
|
+
this.driver = null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async ensureConnected() {
|
|
275
|
+
this.init();
|
|
276
|
+
if (!this.driver && this.defaultConnection !== void 0) {
|
|
277
|
+
await this.connect(this.defaultConnection);
|
|
278
|
+
}
|
|
279
|
+
if (!this.driver || !this.familyInstance || !this.frameworkComponents) {
|
|
280
|
+
throw new Error("Not connected. Call connect(connection) first.");
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
driver: this.driver,
|
|
284
|
+
familyInstance: this.familyInstance,
|
|
285
|
+
frameworkComponents: this.frameworkComponents
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
async verify(options) {
|
|
289
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
290
|
+
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
291
|
+
return familyInstance.verify({
|
|
292
|
+
driver,
|
|
293
|
+
contractIR,
|
|
294
|
+
expectedTargetId: this.options.target.targetId,
|
|
295
|
+
contractPath: ""
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async schemaVerify(options) {
|
|
299
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
300
|
+
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
301
|
+
return familyInstance.schemaVerify({
|
|
302
|
+
driver,
|
|
303
|
+
contractIR,
|
|
304
|
+
strict: options.strict ?? false,
|
|
305
|
+
contractPath: "",
|
|
306
|
+
frameworkComponents
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async sign(options) {
|
|
310
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
311
|
+
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
312
|
+
return familyInstance.sign({
|
|
313
|
+
driver,
|
|
314
|
+
contractIR,
|
|
315
|
+
contractPath: ""
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
async dbInit(options) {
|
|
319
|
+
const { onProgress } = options;
|
|
320
|
+
if (options.connection !== void 0) {
|
|
321
|
+
onProgress?.({
|
|
322
|
+
action: "dbInit",
|
|
323
|
+
kind: "spanStart",
|
|
324
|
+
spanId: "connect",
|
|
325
|
+
label: "Connecting to database..."
|
|
326
|
+
});
|
|
327
|
+
try {
|
|
328
|
+
await this.connect(options.connection);
|
|
329
|
+
onProgress?.({
|
|
330
|
+
action: "dbInit",
|
|
331
|
+
kind: "spanEnd",
|
|
332
|
+
spanId: "connect",
|
|
333
|
+
outcome: "ok"
|
|
334
|
+
});
|
|
335
|
+
} catch (error) {
|
|
336
|
+
onProgress?.({
|
|
337
|
+
action: "dbInit",
|
|
338
|
+
kind: "spanEnd",
|
|
339
|
+
spanId: "connect",
|
|
340
|
+
outcome: "error"
|
|
341
|
+
});
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
346
|
+
if (!this.options.target.migrations) {
|
|
347
|
+
throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
|
|
348
|
+
}
|
|
349
|
+
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
350
|
+
return executeDbInit({
|
|
351
|
+
driver,
|
|
352
|
+
familyInstance,
|
|
353
|
+
contractIR,
|
|
354
|
+
mode: options.mode,
|
|
355
|
+
migrations: this.options.target.migrations,
|
|
356
|
+
frameworkComponents,
|
|
357
|
+
...onProgress ? { onProgress } : {}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
async introspect(options) {
|
|
361
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
362
|
+
const _schema = options?.schema;
|
|
363
|
+
void _schema;
|
|
364
|
+
return familyInstance.introspect({ driver });
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
export {
|
|
369
|
+
createControlClient
|
|
370
|
+
};
|
|
371
|
+
//# sourceMappingURL=chunk-74IELXRA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/control-api/client.ts","../src/control-api/operations/db-init.ts"],"sourcesContent":["import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';\nimport { createControlPlaneStack } from '@prisma-next/core-control-plane/stack';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n ControlPlaneStack,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/core-control-plane/types';\nimport { assertFrameworkComponentsCompatible } from '../utils/framework-components';\nimport { executeDbInit } from './operations/db-init';\nimport type {\n ControlClient,\n ControlClientOptions,\n DbInitOptions,\n DbInitResult,\n IntrospectOptions,\n SchemaVerifyOptions,\n SignOptions,\n VerifyOptions,\n} from './types';\n\n/**\n * Creates a programmatic control client for Prisma Next operations.\n *\n * The client accepts framework component descriptors at creation time,\n * manages driver lifecycle via connect()/close(), and exposes domain\n * operations that delegate to the existing family instance methods.\n *\n * @see {@link ControlClient} for the client interface\n * @see README.md \"Programmatic Control API\" section for usage examples\n */\nexport function createControlClient(options: ControlClientOptions): ControlClient {\n return new ControlClientImpl(options);\n}\n\n/**\n * Implementation of ControlClient.\n * Manages initialization and connection state, delegates operations to family instance.\n */\nclass ControlClientImpl implements ControlClient {\n private readonly options: ControlClientOptions;\n private stack: ControlPlaneStack<string, string> | null = null;\n private driver: ControlDriverInstance<string, string> | null = null;\n private familyInstance: ControlFamilyInstance<string> | null = null;\n private frameworkComponents: ReadonlyArray<\n TargetBoundComponentDescriptor<string, string>\n > | null = null;\n private initialized = false;\n private readonly defaultConnection: unknown;\n\n constructor(options: ControlClientOptions) {\n this.options = options;\n this.defaultConnection = options.connection;\n }\n\n init(): void {\n if (this.initialized) {\n return; // Idempotent\n }\n\n // Create the control plane stack\n this.stack = createControlPlaneStack({\n target: this.options.target,\n adapter: this.options.adapter,\n driver: this.options.driver,\n extensionPacks: this.options.extensionPacks,\n });\n\n // Create family instance using the stack\n this.familyInstance = this.options.family.create(this.stack);\n\n // Validate and type-narrow framework components\n const rawComponents = [\n this.options.target,\n this.options.adapter,\n ...(this.options.extensionPacks ?? []),\n ];\n this.frameworkComponents = assertFrameworkComponentsCompatible(\n this.options.family.familyId,\n this.options.target.targetId,\n rawComponents,\n );\n\n this.initialized = true;\n }\n\n async connect(connection?: unknown): Promise<void> {\n // Auto-init if needed\n this.init();\n\n if (this.driver) {\n throw new Error('Already connected. Call close() before reconnecting.');\n }\n\n // Resolve connection: argument > default from options\n const resolvedConnection = connection ?? this.defaultConnection;\n if (resolvedConnection === undefined) {\n throw new Error(\n 'No connection provided. Pass a connection to connect() or provide a default connection when creating the client.',\n );\n }\n\n // Check for driver descriptor\n if (!this.stack?.driver) {\n throw new Error(\n 'Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations.',\n );\n }\n\n // Create driver instance\n // Cast through any since connection type is driver-specific at runtime.\n // The driver descriptor is typed with any for TConnection in ControlClientOptions,\n // but createControlPlaneStack defaults it to string. We bridge this at runtime.\n // biome-ignore lint/suspicious/noExplicitAny: required for runtime connection type flexibility\n this.driver = await this.stack?.driver.create(resolvedConnection as any);\n }\n\n async close(): Promise<void> {\n if (this.driver) {\n await this.driver.close();\n this.driver = null;\n }\n }\n\n private async ensureConnected(): Promise<{\n driver: ControlDriverInstance<string, string>;\n familyInstance: ControlFamilyInstance<string>;\n frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<string, string>>;\n }> {\n // Auto-init if needed\n this.init();\n\n // Auto-connect if not connected and default connection is available\n if (!this.driver && this.defaultConnection !== undefined) {\n await this.connect(this.defaultConnection);\n }\n\n if (!this.driver || !this.familyInstance || !this.frameworkComponents) {\n throw new Error('Not connected. Call connect(connection) first.');\n }\n return {\n driver: this.driver,\n familyInstance: this.familyInstance,\n frameworkComponents: this.frameworkComponents,\n };\n }\n\n async verify(options: VerifyOptions): Promise<VerifyDatabaseResult> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance verify method\n // Note: We pass empty strings for contractPath/configPath since the programmatic\n // API doesn't deal with file paths. The family instance accepts these as optional\n // metadata for error reporting.\n return familyInstance.verify({\n driver,\n contractIR,\n expectedTargetId: this.options.target.targetId,\n contractPath: '',\n });\n }\n\n async schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult> {\n const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance schemaVerify method\n return familyInstance.schemaVerify({\n driver,\n contractIR,\n strict: options.strict ?? false,\n contractPath: '',\n frameworkComponents,\n });\n }\n\n async sign(options: SignOptions): Promise<SignDatabaseResult> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance sign method\n return familyInstance.sign({\n driver,\n contractIR,\n contractPath: '',\n });\n }\n\n async dbInit(options: DbInitOptions): Promise<DbInitResult> {\n const { onProgress } = options;\n\n // Connect with progress span if connection provided\n if (options.connection !== undefined) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: 'connect',\n label: 'Connecting to database...',\n });\n try {\n await this.connect(options.connection);\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: 'connect',\n outcome: 'ok',\n });\n } catch (error) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: 'connect',\n outcome: 'error',\n });\n throw error;\n }\n }\n\n const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();\n\n // Check target supports migrations\n if (!this.options.target.migrations) {\n throw new Error(`Target \"${this.options.target.targetId}\" does not support migrations`);\n }\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to extracted dbInit operation\n return executeDbInit({\n driver,\n familyInstance,\n contractIR,\n mode: options.mode,\n migrations: this.options.target.migrations,\n frameworkComponents,\n ...(onProgress ? { onProgress } : {}),\n });\n }\n\n async introspect(options?: IntrospectOptions): Promise<unknown> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // TODO: Pass schema option to familyInstance.introspect when schema filtering is implemented\n const _schema = options?.schema;\n void _schema;\n\n return familyInstance.introspect({ driver });\n }\n}\n","import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n MigrationPlan,\n MigrationPlannerResult,\n MigrationPlanOperation,\n MigrationRunnerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/core-control-plane/types';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type { DbInitResult, DbInitSuccess, OnControlProgress } from '../types';\n\n/**\n * Options for executing dbInit operation.\n */\nexport interface ExecuteDbInitOptions<TFamilyId extends string, TTargetId extends string> {\n readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;\n readonly familyInstance: ControlFamilyInstance<TFamilyId>;\n readonly contractIR: ContractIR;\n readonly mode: 'plan' | 'apply';\n readonly migrations: TargetMigrationsCapability<\n TFamilyId,\n TTargetId,\n ControlFamilyInstance<TFamilyId>\n >;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;\n /** Optional progress callback for observing operation progress */\n readonly onProgress?: OnControlProgress;\n}\n\n/**\n * Executes the dbInit operation.\n *\n * This is the core logic extracted from the CLI command, without any file I/O,\n * process.exit(), or console output. It uses the Result pattern to return\n * success or failure details.\n *\n * @param options - The options for executing dbInit\n * @returns Result with DbInitSuccess on success, DbInitFailure on failure\n */\nexport async function executeDbInit<TFamilyId extends string, TTargetId extends string>(\n options: ExecuteDbInitOptions<TFamilyId, TTargetId>,\n): Promise<DbInitResult> {\n const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents, onProgress } =\n options;\n\n // Create planner and runner from target migrations capability\n const planner = migrations.createPlanner(familyInstance);\n const runner = migrations.createRunner(familyInstance);\n\n // Introspect live schema\n const introspectSpanId = 'introspect';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: introspectSpanId,\n label: 'Introspecting database schema',\n });\n const schemaIR = await familyInstance.introspect({ driver });\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: introspectSpanId,\n outcome: 'ok',\n });\n\n // Policy for init mode (additive only)\n const policy = { allowedOperationClasses: ['additive'] as const };\n\n // Plan migration\n const planSpanId = 'plan';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: planSpanId,\n label: 'Planning migration',\n });\n const plannerResult: MigrationPlannerResult = await planner.plan({\n contract: contractIR,\n schema: schemaIR,\n policy,\n frameworkComponents,\n });\n\n if (plannerResult.kind === 'failure') {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: planSpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'PLANNING_FAILED' as const,\n summary: 'Migration planning failed due to conflicts',\n conflicts: plannerResult.conflicts,\n why: undefined,\n meta: undefined,\n });\n }\n\n const migrationPlan: MigrationPlan = plannerResult.plan;\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: planSpanId,\n outcome: 'ok',\n });\n\n // Check for existing marker - handle idempotency and mismatch errors\n const checkMarkerSpanId = 'checkMarker';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: checkMarkerSpanId,\n label: 'Checking contract marker',\n });\n const existingMarker = await familyInstance.readMarker({ driver });\n if (existingMarker) {\n const markerMatchesDestination =\n existingMarker.coreHash === migrationPlan.destination.coreHash &&\n (!migrationPlan.destination.profileHash ||\n existingMarker.profileHash === migrationPlan.destination.profileHash);\n\n if (markerMatchesDestination) {\n // Already at destination - return success with no operations\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'skipped',\n });\n const result: DbInitSuccess = {\n mode,\n plan: { operations: [] },\n ...(mode === 'apply'\n ? {\n execution: { operationsPlanned: 0, operationsExecuted: 0 },\n marker: {\n coreHash: existingMarker.coreHash,\n profileHash: existingMarker.profileHash,\n },\n }\n : {}),\n summary: 'Database already at target contract state',\n };\n return ok(result);\n }\n\n // Marker exists but doesn't match destination - fail\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'MARKER_ORIGIN_MISMATCH' as const,\n summary: 'Existing contract marker does not match plan destination',\n marker: {\n coreHash: existingMarker.coreHash,\n profileHash: existingMarker.profileHash,\n },\n destination: {\n coreHash: migrationPlan.destination.coreHash,\n profileHash: migrationPlan.destination.profileHash,\n },\n why: undefined,\n conflicts: undefined,\n meta: undefined,\n });\n }\n\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'ok',\n });\n\n // Plan mode - don't execute\n if (mode === 'plan') {\n const result: DbInitSuccess = {\n mode: 'plan',\n plan: { operations: migrationPlan.operations },\n summary: `Planned ${migrationPlan.operations.length} operation(s)`,\n };\n return ok(result);\n }\n\n // Apply mode - execute runner\n const applySpanId = 'apply';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: applySpanId,\n label: 'Applying migration plan',\n });\n\n const callbacks = onProgress\n ? {\n onOperationStart: (op: MigrationPlanOperation) => {\n onProgress({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: `operation:${op.id}`,\n parentSpanId: applySpanId,\n label: op.label,\n });\n },\n onOperationComplete: (op: MigrationPlanOperation) => {\n onProgress({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: `operation:${op.id}`,\n outcome: 'ok',\n });\n },\n }\n : undefined;\n\n const runnerResult: MigrationRunnerResult = await runner.execute({\n plan: migrationPlan,\n driver,\n destinationContract: contractIR,\n policy,\n ...(callbacks ? { callbacks } : {}),\n // db init plans and applies back-to-back from a fresh introspection, so per-operation\n // pre/postchecks and the idempotency probe are usually redundant overhead. We still\n // enforce marker/origin compatibility and a full schema verification after apply.\n executionChecks: {\n prechecks: false,\n postchecks: false,\n idempotencyChecks: false,\n },\n frameworkComponents,\n });\n\n if (!runnerResult.ok) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: applySpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'RUNNER_FAILED' as const,\n summary: runnerResult.failure.summary,\n why: runnerResult.failure.why,\n meta: runnerResult.failure.meta,\n conflicts: undefined,\n });\n }\n\n const execution = runnerResult.value;\n\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: applySpanId,\n outcome: 'ok',\n });\n\n const result: DbInitSuccess = {\n mode: 'apply',\n plan: { operations: migrationPlan.operations },\n execution: {\n operationsPlanned: execution.operationsPlanned,\n operationsExecuted: execution.operationsExecuted,\n },\n marker: migrationPlan.destination.profileHash\n ? {\n coreHash: migrationPlan.destination.coreHash,\n profileHash: migrationPlan.destination.profileHash,\n }\n : { coreHash: migrationPlan.destination.coreHash },\n summary: `Applied ${execution.operationsExecuted} operation(s), marker written`,\n };\n return ok(result);\n}\n"],"mappings":";;;;;AACA,SAAS,+BAA+B;;;ACUxC,SAAS,OAAO,UAAU;AA+B1B,eAAsB,cACpB,SACuB;AACvB,QAAM,EAAE,QAAQ,gBAAgB,YAAY,MAAM,YAAY,qBAAqB,WAAW,IAC5F;AAGF,QAAM,UAAU,WAAW,cAAc,cAAc;AACvD,QAAM,SAAS,WAAW,aAAa,cAAc;AAGrD,QAAM,mBAAmB;AACzB,eAAa;AAAA,IACX,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,EACT,CAAC;AACD,QAAM,WAAW,MAAM,eAAe,WAAW,EAAE,OAAO,CAAC;AAC3D,eAAa;AAAA,IACX,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AAGD,QAAM,SAAS,EAAE,yBAAyB,CAAC,UAAU,EAAW;AAGhE,QAAM,aAAa;AACnB,eAAa;AAAA,IACX,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,EACT,CAAC;AACD,QAAM,gBAAwC,MAAM,QAAQ,KAAK;AAAA,IAC/D,UAAU;AAAA,IACV,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,cAAc,SAAS,WAAW;AACpC,iBAAa;AAAA,MACX,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,SAAS;AAAA,IACX,CAAC;AACD,WAAO,MAAM;AAAA,MACX,MAAM;AAAA,MACN,SAAS;AAAA,MACT,WAAW,cAAc;AAAA,MACzB,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC;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AAA,MACR;AAAA,IACF;AAEA,UAAM,EAAE,QAAQ,gBAAgB,oBAAoB,IAAI,MAAM,KAAK,gBAAgB;AAGnF,QAAI,CAAC,KAAK,QAAQ,OAAO,YAAY;AACnC,YAAM,IAAI,MAAM,WAAW,KAAK,QAAQ,OAAO,QAAQ,+BAA+B;AAAA,IACxF;AAGA,UAAM,aAAa,eAAe,mBAAmB,QAAQ,UAAU;AAGvE,WAAO,cAAc;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,YAAY,KAAK,QAAQ,OAAO;AAAA,MAChC;AAAA,MACA,GAAI,aAAa,EAAE,WAAW,IAAI,CAAC;AAAA,IACrC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,WAAW,SAA+C;AAC9D,UAAM,EAAE,QAAQ,eAAe,IAAI,MAAM,KAAK,gBAAgB;AAG9D,UAAM,UAAU,SAAS;AACzB,SAAK;AAEL,WAAO,eAAe,WAAW,EAAE,OAAO,CAAC;AAAA,EAC7C;AACF;","names":["result"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
performAction,
|
|
3
|
+
withSpinner
|
|
4
|
+
} from "./chunk-5MPKZYVI.js";
|
|
1
5
|
import {
|
|
2
6
|
formatCommandHelp,
|
|
3
7
|
formatEmitJson,
|
|
@@ -6,10 +10,8 @@ import {
|
|
|
6
10
|
formatSuccessMessage,
|
|
7
11
|
handleResult,
|
|
8
12
|
parseGlobalFlags,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
withSpinner
|
|
12
|
-
} from "./chunk-DIJPT5TZ.js";
|
|
13
|
+
setCommandDescriptions
|
|
14
|
+
} from "./chunk-ZG5T6OB5.js";
|
|
13
15
|
import {
|
|
14
16
|
loadConfig
|
|
15
17
|
} from "./chunk-HWYQOCAJ.js";
|
|
@@ -128,4 +130,4 @@ function createContractEmitCommand() {
|
|
|
128
130
|
export {
|
|
129
131
|
createContractEmitCommand
|
|
130
132
|
};
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
133
|
+
//# sourceMappingURL=chunk-U6QI3AZ3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/contract-emit.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\nimport { errorContractConfigMissing } from '@prisma-next/core-control-plane/errors';\nimport { createControlPlaneStack } from '@prisma-next/core-control-plane/types';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { performAction } from '../utils/action';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatEmitJson,\n formatEmitOutput,\n formatStyledHeader,\n formatSuccessMessage,\n} from '../utils/output';\nimport { handleResult } from '../utils/result-handler';\nimport { withSpinner } from '../utils/spinner';\n\ninterface ContractEmitOptions {\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\nexport function createContractEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Write your contract to JSON and sign it',\n 'Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\\n' +\n 'contract.d.ts. The contract.json contains the canonical contract structure, and\\n' +\n 'contract.d.ts provides TypeScript types for type-safe query building.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object or ndjson)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: ContractEmitOptions) => {\n const flags = parseGlobalFlags(options);\n\n const result = await performAction(async () => {\n // Load config\n const config = await loadConfig(options.config);\n\n // Resolve contract from config\n if (!config.contract) {\n throw errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',\n });\n }\n\n // Contract config is already normalized by defineConfig() with defaults applied\n const contractConfig = config.contract;\n\n // Resolve artifact paths from config (already normalized by defineConfig() with defaults)\n if (!contractConfig.output || !contractConfig.types) {\n throw errorContractConfigMissing({\n why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',\n });\n }\n const outputJsonPath = resolve(contractConfig.output);\n const outputDtsPath = resolve(contractConfig.types);\n\n // Output header (only for human-readable output)\n if (flags.json !== 'object' && !flags.quiet) {\n // Normalize config path for display (match contract path format - no ./ prefix)\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n // Convert absolute paths to relative paths for display\n const contractPath = relative(process.cwd(), outputJsonPath);\n const typesPath = relative(process.cwd(), outputDtsPath);\n const header = formatStyledHeader({\n command: 'contract emit',\n description: 'Write your contract to JSON and sign it',\n url: 'https://pris.ly/contract-emit',\n details: [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'types', value: typesPath },\n ],\n flags,\n });\n console.log(header);\n }\n\n const stack = createControlPlaneStack({\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks,\n });\n const familyInstance = config.family.create(stack);\n\n // Resolve contract source from config (user's config handles loading)\n let contractRaw: unknown;\n if (typeof contractConfig.source === 'function') {\n contractRaw = await contractConfig.source();\n } else {\n contractRaw = contractConfig.source;\n }\n\n // Call emitContract on family instance (handles stripping mappings and validation internally)\n const emitResult = await withSpinner(\n () => familyInstance.emitContract({ contractIR: contractRaw }),\n {\n message: 'Emitting contract...',\n flags,\n },\n );\n\n // Create directories if needed\n mkdirSync(dirname(outputJsonPath), { recursive: true });\n mkdirSync(dirname(outputDtsPath), { recursive: true });\n\n // Write the results to files\n writeFileSync(outputJsonPath, emitResult.contractJson, 'utf-8');\n writeFileSync(outputDtsPath, emitResult.contractDts, 'utf-8');\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n // Return result with file paths for output formatting\n return {\n coreHash: emitResult.coreHash,\n profileHash: emitResult.profileHash,\n outDir: dirname(outputJsonPath),\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n timings: {\n total: 0, // Timing is handled by emitContract internally if needed\n },\n };\n });\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, (emitResult) => {\n // Output based on flags\n if (flags.json === 'object') {\n // JSON output to stdout\n console.log(formatEmitJson(emitResult));\n } else {\n // Human-readable output to stdout\n const output = formatEmitOutput(emitResult, flags);\n if (output) {\n console.log(output);\n }\n // Output success message\n if (!flags.quiet) {\n console.log(formatSuccessMessage(flags));\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/commands/contract-emit.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\nimport { errorContractConfigMissing } from '@prisma-next/core-control-plane/errors';\nimport { createControlPlaneStack } from '@prisma-next/core-control-plane/types';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { performAction } from '../utils/action';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatEmitJson,\n formatEmitOutput,\n formatStyledHeader,\n formatSuccessMessage,\n} from '../utils/output';\nimport { handleResult } from '../utils/result-handler';\nimport { withSpinner } from '../utils/spinner';\n\ninterface ContractEmitOptions {\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\nexport function createContractEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Write your contract to JSON and sign it',\n 'Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\\n' +\n 'contract.d.ts. The contract.json contains the canonical contract structure, and\\n' +\n 'contract.d.ts provides TypeScript types for type-safe query building.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object or ndjson)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: ContractEmitOptions) => {\n const flags = parseGlobalFlags(options);\n\n const result = await performAction(async () => {\n // Load config\n const config = await loadConfig(options.config);\n\n // Resolve contract from config\n if (!config.contract) {\n throw errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',\n });\n }\n\n // Contract config is already normalized by defineConfig() with defaults applied\n const contractConfig = config.contract;\n\n // Resolve artifact paths from config (already normalized by defineConfig() with defaults)\n if (!contractConfig.output || !contractConfig.types) {\n throw errorContractConfigMissing({\n why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',\n });\n }\n const outputJsonPath = resolve(contractConfig.output);\n const outputDtsPath = resolve(contractConfig.types);\n\n // Output header (only for human-readable output)\n if (flags.json !== 'object' && !flags.quiet) {\n // Normalize config path for display (match contract path format - no ./ prefix)\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n // Convert absolute paths to relative paths for display\n const contractPath = relative(process.cwd(), outputJsonPath);\n const typesPath = relative(process.cwd(), outputDtsPath);\n const header = formatStyledHeader({\n command: 'contract emit',\n description: 'Write your contract to JSON and sign it',\n url: 'https://pris.ly/contract-emit',\n details: [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'types', value: typesPath },\n ],\n flags,\n });\n console.log(header);\n }\n\n const stack = createControlPlaneStack({\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks,\n });\n const familyInstance = config.family.create(stack);\n\n // Resolve contract source from config (user's config handles loading)\n let contractRaw: unknown;\n if (typeof contractConfig.source === 'function') {\n contractRaw = await contractConfig.source();\n } else {\n contractRaw = contractConfig.source;\n }\n\n // Call emitContract on family instance (handles stripping mappings and validation internally)\n const emitResult = await withSpinner(\n () => familyInstance.emitContract({ contractIR: contractRaw }),\n {\n message: 'Emitting contract...',\n flags,\n },\n );\n\n // Create directories if needed\n mkdirSync(dirname(outputJsonPath), { recursive: true });\n mkdirSync(dirname(outputDtsPath), { recursive: true });\n\n // Write the results to files\n writeFileSync(outputJsonPath, emitResult.contractJson, 'utf-8');\n writeFileSync(outputDtsPath, emitResult.contractDts, 'utf-8');\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n // Return result with file paths for output formatting\n return {\n coreHash: emitResult.coreHash,\n profileHash: emitResult.profileHash,\n outDir: dirname(outputJsonPath),\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n timings: {\n total: 0, // Timing is handled by emitContract internally if needed\n },\n };\n });\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, (emitResult) => {\n // Output based on flags\n if (flags.json === 'object') {\n // JSON output to stdout\n console.log(formatEmitJson(emitResult));\n } else {\n // Human-readable output to stdout\n const output = formatEmitOutput(emitResult, flags);\n if (output) {\n console.log(output);\n }\n // Output success message\n if (!flags.quiet) {\n console.log(formatSuccessMessage(flags));\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,qBAAqB;AACzC,SAAS,SAAS,UAAU,eAAe;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,eAAe;AA6BjB,SAAS,4BAAqC;AACnD,QAAM,UAAU,IAAI,QAAQ,MAAM;AAClC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EAGF;AACA,UACG,cAAc;AAAA,IACb,YAAY,CAAC,QAAQ;AACnB,YAAM,QAAQ,iBAAiB,CAAC,CAAC;AACjC,aAAO,kBAAkB,EAAE,SAAS,KAAK,MAAM,CAAC;AAAA,IAClD;AAAA,EACF,CAAC,EACA,OAAO,mBAAmB,+BAA+B,EACzD,OAAO,mBAAmB,qCAAqC,KAAK,EACpE,OAAO,eAAe,yBAAyB,EAC/C,OAAO,iBAAiB,qCAAqC,EAC7D,OAAO,gBAAgB,4CAA4C,EACnE,OAAO,gBAAgB,0BAA0B,EACjD,OAAO,WAAW,oBAAoB,EACtC,OAAO,cAAc,sBAAsB,EAC3C,OAAO,OAAO,YAAiC;AAC9C,UAAM,QAAQ,iBAAiB,OAAO;AAEtC,UAAM,SAAS,MAAM,cAAc,YAAY;AAE7C,YAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;AAG9C,UAAI,CAAC,OAAO,UAAU;AACpB,cAAM,2BAA2B;AAAA,UAC/B,KAAK;AAAA,QACP,CAAC;AAAA,MACH;AAGA,YAAM,iBAAiB,OAAO;AAG9B,UAAI,CAAC,eAAe,UAAU,CAAC,eAAe,OAAO;AACnD,cAAM,2BAA2B;AAAA,UAC/B,KAAK;AAAA,QACP,CAAC;AAAA,MACH;AACA,YAAM,iBAAiB,QAAQ,eAAe,MAAM;AACpD,YAAM,gBAAgB,QAAQ,eAAe,KAAK;AAGlD,UAAI,MAAM,SAAS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AAO;AACnE,gBAAQ,IAAI,EAAE;AAAA,MAChB;AAGA,aAAO;AAAA,QACL,UAAU,WAAW;AAAA,QACrB,aAAa,WAAW;AAAA,QACxB,QAAQ,QAAQ,cAAc;AAAA,QAC9B,OAAO;AAAA,UACL,MAAM;AAAA,UACN,KAAK;AAAA,QACP;AAAA,QACA,SAAS;AAAA,UACP,OAAO;AAAA;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,WAAW,aAAa,QAAQ,OAAO,CAAC,eAAe;AAE3D,UAAI,MAAM,SAAS,UAAU;AAE3B,gBAAQ,IAAI,eAAe,UAAU,CAAC;AAAA,MACxC,OAAO;AAEL,cAAM,SAAS,iBAAiB,YAAY,KAAK;AACjD,YAAI,QAAQ;AACV,kBAAQ,IAAI,MAAM;AAAA,QACpB;AAEA,YAAI,CAAC,MAAM,OAAO;AAChB,kBAAQ,IAAI,qBAAqB,KAAK,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AACD,YAAQ,KAAK,QAAQ;AAAA,EACvB,CAAC;AAEH,SAAO;AACT;","names":[]}
|
|
@@ -1,21 +1,3 @@
|
|
|
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
1
|
// src/utils/command-helpers.ts
|
|
20
2
|
function setCommandDescriptions(command, shortDescription, longDescription) {
|
|
21
3
|
command.description(shortDescription);
|
|
@@ -917,32 +899,7 @@ function handleResult(result, flags, onSuccess) {
|
|
|
917
899
|
return exitCode;
|
|
918
900
|
}
|
|
919
901
|
|
|
920
|
-
// src/utils/spinner.ts
|
|
921
|
-
import ora from "ora";
|
|
922
|
-
async function withSpinner(operation, options) {
|
|
923
|
-
const { message, flags } = options;
|
|
924
|
-
const shouldShowSpinner = !flags.quiet && flags.json !== "object" && process.stdout.isTTY;
|
|
925
|
-
if (!shouldShowSpinner) {
|
|
926
|
-
return operation();
|
|
927
|
-
}
|
|
928
|
-
const startTime = Date.now();
|
|
929
|
-
const spinner = ora({
|
|
930
|
-
text: message,
|
|
931
|
-
color: flags.color !== false ? "cyan" : false
|
|
932
|
-
}).start();
|
|
933
|
-
try {
|
|
934
|
-
const result = await operation();
|
|
935
|
-
const elapsed = Date.now() - startTime;
|
|
936
|
-
spinner.succeed(`${message} (${elapsed}ms)`);
|
|
937
|
-
return result;
|
|
938
|
-
} catch (error) {
|
|
939
|
-
spinner.fail(`${message} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
940
|
-
throw error;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
|
|
944
902
|
export {
|
|
945
|
-
performAction,
|
|
946
903
|
setCommandDescriptions,
|
|
947
904
|
parseGlobalFlags,
|
|
948
905
|
formatEmitOutput,
|
|
@@ -961,7 +918,6 @@ export {
|
|
|
961
918
|
formatStyledHeader,
|
|
962
919
|
formatSuccessMessage,
|
|
963
920
|
formatCommandHelp,
|
|
964
|
-
handleResult
|
|
965
|
-
withSpinner
|
|
921
|
+
handleResult
|
|
966
922
|
};
|
|
967
|
-
//# sourceMappingURL=chunk-
|
|
923
|
+
//# sourceMappingURL=chunk-ZG5T6OB5.js.map
|