@prisma-next/cli 0.3.0-dev.15 → 0.3.0-dev.17
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 +11 -11
- 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
|
@@ -25,12 +25,49 @@ export interface ControlClientOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
readonly connection?: unknown;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Action names for control-api operations that can emit progress events.
|
|
30
|
+
*/
|
|
31
|
+
export type ControlActionName = 'dbInit' | 'verify' | 'schemaVerify' | 'sign' | 'introspect';
|
|
32
|
+
/**
|
|
33
|
+
* Progress event emitted during control-api operation execution.
|
|
34
|
+
*
|
|
35
|
+
* Events model operation progress using a span-based model:
|
|
36
|
+
* - `spanStart`: Begin a timed segment (supports nesting via parentSpanId)
|
|
37
|
+
* - `spanEnd`: Complete a timed segment
|
|
38
|
+
*
|
|
39
|
+
* All operation-specific progress (e.g., per-migration-operation) is modeled
|
|
40
|
+
* as nested spans rather than special event types.
|
|
41
|
+
*
|
|
42
|
+
* Events are delivered via an optional `onProgress` callback to avoid polluting
|
|
43
|
+
* return types. If the callback is absent, operations emit no events (zero overhead).
|
|
44
|
+
*/
|
|
45
|
+
export type ControlProgressEvent = {
|
|
46
|
+
readonly action: ControlActionName;
|
|
47
|
+
readonly kind: 'spanStart';
|
|
48
|
+
readonly spanId: string;
|
|
49
|
+
readonly parentSpanId?: string;
|
|
50
|
+
readonly label: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly action: ControlActionName;
|
|
53
|
+
readonly kind: 'spanEnd';
|
|
54
|
+
readonly spanId: string;
|
|
55
|
+
readonly outcome: 'ok' | 'skipped' | 'error';
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Callback function for receiving progress events during control-api operations.
|
|
59
|
+
*
|
|
60
|
+
* @param event - The progress event emitted by the operation
|
|
61
|
+
*/
|
|
62
|
+
export type OnControlProgress = (event: ControlProgressEvent) => void;
|
|
28
63
|
/**
|
|
29
64
|
* Options for the verify operation.
|
|
30
65
|
*/
|
|
31
66
|
export interface VerifyOptions {
|
|
32
67
|
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
33
68
|
readonly contractIR: unknown;
|
|
69
|
+
/** Optional progress callback for observing operation progress */
|
|
70
|
+
readonly onProgress?: OnControlProgress;
|
|
34
71
|
}
|
|
35
72
|
/**
|
|
36
73
|
* Options for the schemaVerify operation.
|
|
@@ -44,6 +81,8 @@ export interface SchemaVerifyOptions {
|
|
|
44
81
|
* Default: false (tolerant mode - allows superset)
|
|
45
82
|
*/
|
|
46
83
|
readonly strict?: boolean;
|
|
84
|
+
/** Optional progress callback for observing operation progress */
|
|
85
|
+
readonly onProgress?: OnControlProgress;
|
|
47
86
|
}
|
|
48
87
|
/**
|
|
49
88
|
* Options for the sign operation.
|
|
@@ -51,6 +90,8 @@ export interface SchemaVerifyOptions {
|
|
|
51
90
|
export interface SignOptions {
|
|
52
91
|
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
53
92
|
readonly contractIR: unknown;
|
|
93
|
+
/** Optional progress callback for observing operation progress */
|
|
94
|
+
readonly onProgress?: OnControlProgress;
|
|
54
95
|
}
|
|
55
96
|
/**
|
|
56
97
|
* Options for the dbInit operation.
|
|
@@ -64,6 +105,14 @@ export interface DbInitOptions {
|
|
|
64
105
|
* - 'apply': Applies operations and writes marker
|
|
65
106
|
*/
|
|
66
107
|
readonly mode: 'plan' | 'apply';
|
|
108
|
+
/**
|
|
109
|
+
* Database connection. If provided, dbInit will connect before executing.
|
|
110
|
+
* If omitted, the client must already be connected.
|
|
111
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
112
|
+
*/
|
|
113
|
+
readonly connection?: unknown;
|
|
114
|
+
/** Optional progress callback for observing operation progress */
|
|
115
|
+
readonly onProgress?: OnControlProgress;
|
|
67
116
|
}
|
|
68
117
|
/**
|
|
69
118
|
* Options for the introspect operation.
|
|
@@ -73,6 +122,8 @@ export interface IntrospectOptions {
|
|
|
73
122
|
* Optional schema name to introspect.
|
|
74
123
|
*/
|
|
75
124
|
readonly schema?: string;
|
|
125
|
+
/** Optional progress callback for observing operation progress */
|
|
126
|
+
readonly onProgress?: OnControlProgress;
|
|
76
127
|
}
|
|
77
128
|
/**
|
|
78
129
|
* Successful dbInit result.
|
|
@@ -106,7 +157,9 @@ export type DbInitFailureCode = 'PLANNING_FAILED' | 'MARKER_ORIGIN_MISMATCH' | '
|
|
|
106
157
|
export interface DbInitFailure {
|
|
107
158
|
readonly code: DbInitFailureCode;
|
|
108
159
|
readonly summary: string;
|
|
109
|
-
readonly
|
|
160
|
+
readonly why: string | undefined;
|
|
161
|
+
readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
|
|
162
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
110
163
|
readonly marker?: {
|
|
111
164
|
readonly coreHash?: string;
|
|
112
165
|
readonly profileHash?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/control-api/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAMxD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IAEnC,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEnD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAE7D,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC,GAAG,EAAE,GAAG,EAAE,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C,CAAC;IAE9D;;;;;;OAMG;IACH,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAEhF;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAExD;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D"}
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type { ControlPlaneStack, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult, } from '@prisma-next/core-control-plane/types';
|
|
11
11
|
export { createControlClient } from '../control-api/client';
|
|
12
|
-
export type { ControlClient, ControlClientOptions, DbInitFailure, DbInitFailureCode, DbInitOptions, DbInitResult, DbInitSuccess, IntrospectOptions, SchemaVerifyOptions, SignOptions, VerifyOptions, } from '../control-api/types';
|
|
12
|
+
export type { ControlActionName, ControlClient, ControlClientOptions, ControlProgressEvent, DbInitFailure, DbInitFailureCode, DbInitOptions, DbInitResult, DbInitSuccess, IntrospectOptions, OnControlProgress, SchemaVerifyOptions, SignOptions, VerifyOptions, } from '../control-api/types';
|
|
13
13
|
//# sourceMappingURL=control-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-api.d.ts","sourceRoot":"","sources":["../../src/exports/control-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"control-api.d.ts","sourceRoot":"","sources":["../../src/exports/control-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,239 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
createControlClient
|
|
3
|
+
} from "../chunk-74IELXRA.js";
|
|
4
|
+
import "../chunk-6EPKRATC.js";
|
|
4
5
|
import "../chunk-VI2YETW7.js";
|
|
5
|
-
|
|
6
|
-
// src/control-api/client.ts
|
|
7
|
-
import { createControlPlaneStack } from "@prisma-next/core-control-plane/stack";
|
|
8
|
-
|
|
9
|
-
// src/control-api/operations/db-init.ts
|
|
10
|
-
import { notOk, ok } from "@prisma-next/utils/result";
|
|
11
|
-
async function executeDbInit(options) {
|
|
12
|
-
const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents } = options;
|
|
13
|
-
const planner = migrations.createPlanner(familyInstance);
|
|
14
|
-
const runner = migrations.createRunner(familyInstance);
|
|
15
|
-
const schemaIR = await familyInstance.introspect({ driver });
|
|
16
|
-
const policy = { allowedOperationClasses: ["additive"] };
|
|
17
|
-
const plannerResult = await planner.plan({
|
|
18
|
-
contract: contractIR,
|
|
19
|
-
schema: schemaIR,
|
|
20
|
-
policy,
|
|
21
|
-
frameworkComponents
|
|
22
|
-
});
|
|
23
|
-
if (plannerResult.kind === "failure") {
|
|
24
|
-
return notOk({
|
|
25
|
-
code: "PLANNING_FAILED",
|
|
26
|
-
summary: "Migration planning failed due to conflicts",
|
|
27
|
-
conflicts: plannerResult.conflicts
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const migrationPlan = plannerResult.plan;
|
|
31
|
-
const existingMarker = await familyInstance.readMarker({ driver });
|
|
32
|
-
if (existingMarker) {
|
|
33
|
-
const markerMatchesDestination = existingMarker.coreHash === migrationPlan.destination.coreHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash);
|
|
34
|
-
if (markerMatchesDestination) {
|
|
35
|
-
const result2 = {
|
|
36
|
-
mode,
|
|
37
|
-
plan: { operations: [] },
|
|
38
|
-
...mode === "apply" ? {
|
|
39
|
-
execution: { operationsPlanned: 0, operationsExecuted: 0 },
|
|
40
|
-
marker: {
|
|
41
|
-
coreHash: existingMarker.coreHash,
|
|
42
|
-
profileHash: existingMarker.profileHash
|
|
43
|
-
}
|
|
44
|
-
} : {},
|
|
45
|
-
summary: "Database already at target contract state"
|
|
46
|
-
};
|
|
47
|
-
return ok(result2);
|
|
48
|
-
}
|
|
49
|
-
return notOk({
|
|
50
|
-
code: "MARKER_ORIGIN_MISMATCH",
|
|
51
|
-
summary: "Existing contract marker does not match plan destination",
|
|
52
|
-
marker: {
|
|
53
|
-
coreHash: existingMarker.coreHash,
|
|
54
|
-
profileHash: existingMarker.profileHash
|
|
55
|
-
},
|
|
56
|
-
destination: {
|
|
57
|
-
coreHash: migrationPlan.destination.coreHash,
|
|
58
|
-
profileHash: migrationPlan.destination.profileHash
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (mode === "plan") {
|
|
63
|
-
const result2 = {
|
|
64
|
-
mode: "plan",
|
|
65
|
-
plan: { operations: migrationPlan.operations },
|
|
66
|
-
summary: `Planned ${migrationPlan.operations.length} operation(s)`
|
|
67
|
-
};
|
|
68
|
-
return ok(result2);
|
|
69
|
-
}
|
|
70
|
-
const runnerResult = await runner.execute({
|
|
71
|
-
plan: migrationPlan,
|
|
72
|
-
driver,
|
|
73
|
-
destinationContract: contractIR,
|
|
74
|
-
policy,
|
|
75
|
-
// db init plans and applies back-to-back from a fresh introspection, so per-operation
|
|
76
|
-
// pre/postchecks and the idempotency probe are usually redundant overhead. We still
|
|
77
|
-
// enforce marker/origin compatibility and a full schema verification after apply.
|
|
78
|
-
executionChecks: {
|
|
79
|
-
prechecks: false,
|
|
80
|
-
postchecks: false,
|
|
81
|
-
idempotencyChecks: false
|
|
82
|
-
},
|
|
83
|
-
frameworkComponents
|
|
84
|
-
});
|
|
85
|
-
if (!runnerResult.ok) {
|
|
86
|
-
return notOk({
|
|
87
|
-
code: "RUNNER_FAILED",
|
|
88
|
-
summary: runnerResult.failure.summary
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
const execution = runnerResult.value;
|
|
92
|
-
const result = {
|
|
93
|
-
mode: "apply",
|
|
94
|
-
plan: { operations: migrationPlan.operations },
|
|
95
|
-
execution: {
|
|
96
|
-
operationsPlanned: execution.operationsPlanned,
|
|
97
|
-
operationsExecuted: execution.operationsExecuted
|
|
98
|
-
},
|
|
99
|
-
marker: migrationPlan.destination.profileHash ? {
|
|
100
|
-
coreHash: migrationPlan.destination.coreHash,
|
|
101
|
-
profileHash: migrationPlan.destination.profileHash
|
|
102
|
-
} : { coreHash: migrationPlan.destination.coreHash },
|
|
103
|
-
summary: `Applied ${execution.operationsExecuted} operation(s), marker written`
|
|
104
|
-
};
|
|
105
|
-
return ok(result);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/control-api/client.ts
|
|
109
|
-
function createControlClient(options) {
|
|
110
|
-
return new ControlClientImpl(options);
|
|
111
|
-
}
|
|
112
|
-
var ControlClientImpl = class {
|
|
113
|
-
options;
|
|
114
|
-
stack = null;
|
|
115
|
-
driver = null;
|
|
116
|
-
familyInstance = null;
|
|
117
|
-
frameworkComponents = null;
|
|
118
|
-
initialized = false;
|
|
119
|
-
defaultConnection;
|
|
120
|
-
constructor(options) {
|
|
121
|
-
this.options = options;
|
|
122
|
-
this.defaultConnection = options.connection;
|
|
123
|
-
}
|
|
124
|
-
init() {
|
|
125
|
-
if (this.initialized) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this.stack = createControlPlaneStack({
|
|
129
|
-
target: this.options.target,
|
|
130
|
-
adapter: this.options.adapter,
|
|
131
|
-
driver: this.options.driver,
|
|
132
|
-
extensionPacks: this.options.extensionPacks
|
|
133
|
-
});
|
|
134
|
-
this.familyInstance = this.options.family.create(this.stack);
|
|
135
|
-
const rawComponents = [
|
|
136
|
-
this.options.target,
|
|
137
|
-
this.options.adapter,
|
|
138
|
-
...this.options.extensionPacks ?? []
|
|
139
|
-
];
|
|
140
|
-
this.frameworkComponents = assertFrameworkComponentsCompatible(
|
|
141
|
-
this.options.family.familyId,
|
|
142
|
-
this.options.target.targetId,
|
|
143
|
-
rawComponents
|
|
144
|
-
);
|
|
145
|
-
this.initialized = true;
|
|
146
|
-
}
|
|
147
|
-
async connect(connection) {
|
|
148
|
-
this.init();
|
|
149
|
-
if (this.driver) {
|
|
150
|
-
throw new Error("Already connected. Call close() before reconnecting.");
|
|
151
|
-
}
|
|
152
|
-
const resolvedConnection = connection ?? this.defaultConnection;
|
|
153
|
-
if (resolvedConnection === void 0) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
"No connection provided. Pass a connection to connect() or provide a default connection when creating the client."
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (!this.stack?.driver) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
"Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations."
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
this.driver = await this.stack?.driver.create(resolvedConnection);
|
|
164
|
-
}
|
|
165
|
-
async close() {
|
|
166
|
-
if (this.driver) {
|
|
167
|
-
await this.driver.close();
|
|
168
|
-
this.driver = null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async ensureConnected() {
|
|
172
|
-
this.init();
|
|
173
|
-
if (!this.driver && this.defaultConnection !== void 0) {
|
|
174
|
-
await this.connect(this.defaultConnection);
|
|
175
|
-
}
|
|
176
|
-
if (!this.driver || !this.familyInstance || !this.frameworkComponents) {
|
|
177
|
-
throw new Error("Not connected. Call connect(connection) first.");
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
driver: this.driver,
|
|
181
|
-
familyInstance: this.familyInstance,
|
|
182
|
-
frameworkComponents: this.frameworkComponents
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async verify(options) {
|
|
186
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
187
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
188
|
-
return familyInstance.verify({
|
|
189
|
-
driver,
|
|
190
|
-
contractIR,
|
|
191
|
-
expectedTargetId: this.options.target.targetId,
|
|
192
|
-
contractPath: ""
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
async schemaVerify(options) {
|
|
196
|
-
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
197
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
198
|
-
return familyInstance.schemaVerify({
|
|
199
|
-
driver,
|
|
200
|
-
contractIR,
|
|
201
|
-
strict: options.strict ?? false,
|
|
202
|
-
contractPath: "",
|
|
203
|
-
frameworkComponents
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
async sign(options) {
|
|
207
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
208
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
209
|
-
return familyInstance.sign({
|
|
210
|
-
driver,
|
|
211
|
-
contractIR,
|
|
212
|
-
contractPath: ""
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async dbInit(options) {
|
|
216
|
-
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
217
|
-
if (!this.options.target.migrations) {
|
|
218
|
-
throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
|
|
219
|
-
}
|
|
220
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
221
|
-
return executeDbInit({
|
|
222
|
-
driver,
|
|
223
|
-
familyInstance,
|
|
224
|
-
contractIR,
|
|
225
|
-
mode: options.mode,
|
|
226
|
-
migrations: this.options.target.migrations,
|
|
227
|
-
frameworkComponents
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
async introspect(options) {
|
|
231
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
232
|
-
const _schema = options?.schema;
|
|
233
|
-
void _schema;
|
|
234
|
-
return familyInstance.introspect({ driver });
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
6
|
export {
|
|
238
7
|
createControlClient
|
|
239
8
|
};
|
|
@@ -1 +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 { 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 });\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 MigrationRunnerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/core-control-plane/types';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type { DbInitResult, DbInitSuccess } 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}\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 } = 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 schemaIR = await familyInstance.introspect({ driver });\n\n // Policy for init mode (additive only)\n const policy = { allowedOperationClasses: ['additive'] as const };\n\n // Plan migration\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 return notOk({\n code: 'PLANNING_FAILED' as const,\n summary: 'Migration planning failed due to conflicts',\n conflicts: plannerResult.conflicts,\n });\n }\n\n const migrationPlan: MigrationPlan = plannerResult.plan;\n\n // Check for existing marker - handle idempotency and mismatch errors\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 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 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 });\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 runnerResult: MigrationRunnerResult = await runner.execute({\n plan: migrationPlan,\n driver,\n destinationContract: contractIR,\n policy,\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 return notOk({\n code: 'RUNNER_FAILED' as const,\n summary: runnerResult.failure.summary,\n });\n }\n\n const execution = runnerResult.value;\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;;;ACSxC,SAAS,OAAO,UAAU;AA6B1B,eAAsB,cACpB,SACuB;AACvB,QAAM,EAAE,QAAQ,gBAAgB,YAAY,MAAM,YAAY,oBAAoB,IAAI;AAGtF,QAAM,UAAU,WAAW,cAAc,cAAc;AACvD,QAAM,SAAS,WAAW,aAAa,cAAc;AAGrD,QAAM,WAAW,MAAM,eAAe,WAAW,EAAE,OAAO,CAAC;AAG3D,QAAM,SAAS,EAAE,yBAAyB,CAAC,UAAU,EAAW;AAGhE,QAAM,gBAAwC,MAAM,QAAQ,KAAK;AAAA,IAC/D,UAAU;AAAA,IACV,QAAQ;AAAA,IACR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,MAAM,KAAK,gBAAgB;AAG9D,UAAM,UAAU,SAAS;AACzB,SAAK;AAEL,WAAO,eAAe,WAAW,EAAE,OAAO,CAAC;AAAA,EAC7C;AACF;","names":["result"]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/exports/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createContractEmitCommand
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-U6QI3AZ3.js";
|
|
4
|
+
import "../chunk-5MPKZYVI.js";
|
|
5
|
+
import "../chunk-ZG5T6OB5.js";
|
|
5
6
|
import "../chunk-HWYQOCAJ.js";
|
|
6
7
|
import "../chunk-VI2YETW7.js";
|
|
7
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/load-ts-contract.ts"],"sourcesContent":["import { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type { Plugin } from 'esbuild';\nimport { build } from 'esbuild';\n\nexport interface LoadTsContractOptions {\n readonly allowlist?: ReadonlyArray<string>;\n}\n\nconst DEFAULT_ALLOWLIST = ['@prisma-next/*'];\n\nfunction isAllowedImport(importPath: string, allowlist: ReadonlyArray<string>): boolean {\n for (const pattern of allowlist) {\n if (pattern.endsWith('/*')) {\n const prefix = pattern.slice(0, -2);\n if (importPath === prefix || importPath.startsWith(`${prefix}/`)) {\n return true;\n }\n } else if (importPath === pattern) {\n return true;\n }\n }\n return false;\n}\n\nfunction validatePurity(value: unknown): void {\n if (typeof value !== 'object' || value === null) {\n return;\n }\n\n const seen = new WeakSet();\n function check(value: unknown): void {\n if (value === null || typeof value !== 'object') {\n return;\n }\n\n if (seen.has(value)) {\n throw new Error('Contract export contains circular references');\n }\n seen.add(value);\n\n for (const key in value) {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor && (descriptor.get || descriptor.set)) {\n throw new Error(`Contract export contains getter/setter at key \"${key}\"`);\n }\n if (descriptor && typeof descriptor.value === 'function') {\n throw new Error(`Contract export contains function at key \"${key}\"`);\n }\n check((value as Record<string, unknown>)[key]);\n }\n }\n\n try {\n check(value);\n JSON.stringify(value);\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('getter') || error.message.includes('circular')) {\n throw error;\n }\n throw new Error(`Contract export is not JSON-serializable: ${error.message}`);\n }\n throw new Error('Contract export is not JSON-serializable');\n }\n}\n\nfunction createImportAllowlistPlugin(allowlist: ReadonlyArray<string>, entryPath: string): Plugin {\n return {\n name: 'import-allowlist',\n setup(build) {\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind === 'entry-point') {\n return undefined;\n }\n if (args.path.startsWith('.') || args.path.startsWith('/')) {\n return undefined;\n }\n const isFromEntryPoint = args.importer === entryPath || args.importer === '<stdin>';\n if (isFromEntryPoint && !isAllowedImport(args.path, allowlist)) {\n return {\n path: args.path,\n external: true,\n };\n }\n return undefined;\n });\n },\n };\n}\n\n/**\n * Loads a contract from a TypeScript file and returns it as ContractIR.\n *\n * **Responsibility: Parsing Only**\n * This function loads and parses a TypeScript contract file. It does NOT normalize the contract.\n * The contract should already be normalized if it was built using the contract builder.\n *\n * Normalization must happen in the contract builder when the contract is created.\n * This function only validates that the contract is JSON-serializable and returns it as-is.\n *\n * @param entryPath - Path to the TypeScript contract file\n * @param options - Optional configuration (import allowlist)\n * @returns The contract as ContractIR (should already be normalized)\n * @throws Error if the contract cannot be loaded or is not JSON-serializable\n */\nexport async function loadContractFromTs(\n entryPath: string,\n options?: LoadTsContractOptions,\n): Promise<ContractIR> {\n const allowlist = options?.allowlist ?? DEFAULT_ALLOWLIST;\n\n if (!existsSync(entryPath)) {\n throw new Error(`Contract file not found: ${entryPath}`);\n }\n\n const tempFile = join(\n tmpdir(),\n `prisma-next-contract-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`,\n );\n\n try {\n const result = await build({\n entryPoints: [entryPath],\n bundle: true,\n format: 'esm',\n platform: 'node',\n target: 'es2022',\n outfile: tempFile,\n write: false,\n metafile: true,\n plugins: [createImportAllowlistPlugin(allowlist, entryPath)],\n logLevel: 'error',\n });\n\n if (result.errors.length > 0) {\n const errorMessages = result.errors.map((e: { text: string }) => e.text).join('\\n');\n throw new Error(`Failed to bundle contract file: ${errorMessages}`);\n }\n\n if (!result.outputFiles || result.outputFiles.length === 0) {\n throw new Error('No output files generated from bundling');\n }\n\n const disallowedImports: string[] = [];\n if (result.metafile) {\n const inputs = result.metafile.inputs;\n for (const [, inputData] of Object.entries(inputs)) {\n const imports =\n (inputData as { imports?: Array<{ path: string; external?: boolean }> }).imports || [];\n for (const imp of imports) {\n if (\n imp.external &&\n !imp.path.startsWith('.') &&\n !imp.path.startsWith('/') &&\n !isAllowedImport(imp.path, allowlist)\n ) {\n disallowedImports.push(imp.path);\n }\n }\n }\n }\n\n if (disallowedImports.length > 0) {\n throw new Error(\n `Disallowed imports detected. Only imports matching the allowlist are permitted:\\n Allowlist: ${allowlist.join(', ')}\\n Disallowed imports: ${disallowedImports.join(', ')}\\n\\nOnly @prisma-next/* packages are allowed in contract files.`,\n );\n }\n\n const bundleContent = result.outputFiles[0]?.text;\n if (bundleContent === undefined) {\n throw new Error('Bundle content is undefined');\n }\n writeFileSync(tempFile, bundleContent, 'utf-8');\n\n const module = (await import(`file://${tempFile}`)) as {\n default?: unknown;\n contract?: unknown;\n };\n unlinkSync(tempFile);\n\n let contract: unknown;\n\n if (module.default !== undefined) {\n contract = module.default;\n } else if (module.contract !== undefined) {\n contract = module.contract;\n } else {\n throw new Error(\n `Contract file must export a contract as default export or named export 'contract'. Found exports: ${Object.keys(module as Record<string, unknown>).join(', ') || 'none'}`,\n );\n }\n\n if (typeof contract !== 'object' || contract === null) {\n throw new Error(`Contract export must be an object, got ${typeof contract}`);\n }\n\n validatePurity(contract);\n\n return contract as ContractIR;\n } catch (error) {\n try {\n if (tempFile) {\n unlinkSync(tempFile);\n }\n } catch {\n // Ignore cleanup errors\n }\n\n if (error instanceof Error) {\n throw error;\n }\n throw new Error(`Failed to load contract from ${entryPath}: ${String(error)}`);\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,YAAY,YAAY,qBAAqB;AACtD,SAAS,cAAc;AACvB,SAAS,YAAY;AAGrB,SAAS,aAAa;AAMtB,IAAM,oBAAoB,CAAC,gBAAgB;AAE3C,SAAS,gBAAgB,YAAoB,WAA2C;AACtF,aAAW,WAAW,WAAW;AAC/B,QAAI,QAAQ,SAAS,IAAI,GAAG;AAC1B,YAAM,SAAS,QAAQ,MAAM,GAAG,EAAE;AAClC,UAAI,eAAe,UAAU,WAAW,WAAW,GAAG,MAAM,GAAG,GAAG;AAChE,eAAO;AAAA,MACT;AAAA,IACF,WAAW,eAAe,SAAS;AACjC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,eAAe,OAAsB;AAC5C,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C;AAAA,EACF;AAEA,QAAM,OAAO,oBAAI,QAAQ;AACzB,WAAS,MAAMA,QAAsB;AACnC,QAAIA,WAAU,QAAQ,OAAOA,WAAU,UAAU;AAC/C;AAAA,IACF;AAEA,QAAI,KAAK,IAAIA,MAAK,GAAG;AACnB,YAAM,IAAI,MAAM,8CAA8C;AAAA,IAChE;AACA,SAAK,IAAIA,MAAK;AAEd,eAAW,OAAOA,QAAO;AACvB,YAAM,aAAa,OAAO,yBAAyBA,QAAO,GAAG;AAC7D,UAAI,eAAe,WAAW,OAAO,WAAW,MAAM;AACpD,cAAM,IAAI,MAAM,kDAAkD,GAAG,GAAG;AAAA,MAC1E;AACA,UAAI,cAAc,OAAO,WAAW,UAAU,YAAY;AACxD,cAAM,IAAI,MAAM,6CAA6C,GAAG,GAAG;AAAA,MACrE;AACA,YAAOA,OAAkC,GAAG,CAAC;AAAA,IA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OAAO;AAE9C,UAAM,SAAU,MAAM,OAAO,UAAU,QAAQ;AAI/C,eAAW,QAAQ;AAEnB,QAAI;AAEJ,QAAI,OAAO,YAAY,QAAW;AAChC,iBAAW,OAAO;AAAA,IACpB,WAAW,OAAO,aAAa,QAAW;AACxC,iBAAW,OAAO;AAAA,IACpB,OAAO;AACL,YAAM,IAAI;AAAA,QACR,qGAAqG,OAAO,KAAK,MAAiC,EAAE,KAAK,IAAI,KAAK,MAAM;AAAA,MAC1K;AAAA,IACF;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,IAAI,MAAM,0CAA0C,OAAO,QAAQ,EAAE;AAAA,IAC7E;AAEA,mBAAe,QAAQ;AAEvB,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI;AACF,UAAI,UAAU;AACZ,mBAAW,QAAQ;AAAA,MACrB;AAAA,IACF,QAAQ;AAAA,IAER;AAEA,QAAI,iBAAiB,OAAO;AAC1B,YAAM;AAAA,IACR;AACA,UAAM,IAAI,MAAM,gCAAgC,SAAS,KAAK,OAAO,KAAK,CAAC,EAAE;AAAA,EAC/E;AACF;","names":["value","build"]}
|
|
1
|
+
{"version":3,"sources":["../../src/load-ts-contract.ts"],"sourcesContent":["import { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type { Plugin } from 'esbuild';\nimport { build } from 'esbuild';\n\nexport interface LoadTsContractOptions {\n readonly allowlist?: ReadonlyArray<string>;\n}\n\nconst DEFAULT_ALLOWLIST = ['@prisma-next/*'];\n\nfunction isAllowedImport(importPath: string, allowlist: ReadonlyArray<string>): boolean {\n for (const pattern of allowlist) {\n if (pattern.endsWith('/*')) {\n const prefix = pattern.slice(0, -2);\n if (importPath === prefix || importPath.startsWith(`${prefix}/`)) {\n return true;\n }\n } else if (importPath === pattern) {\n return true;\n }\n }\n return false;\n}\n\nfunction validatePurity(value: unknown): void {\n if (typeof value !== 'object' || value === null) {\n return;\n }\n\n const seen = new WeakSet();\n function check(value: unknown): void {\n if (value === null || typeof value !== 'object') {\n return;\n }\n\n if (seen.has(value)) {\n throw new Error('Contract export contains circular references');\n }\n seen.add(value);\n\n for (const key in value) {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor && (descriptor.get || descriptor.set)) {\n throw new Error(`Contract export contains getter/setter at key \"${key}\"`);\n }\n if (descriptor && typeof descriptor.value === 'function') {\n throw new Error(`Contract export contains function at key \"${key}\"`);\n }\n check((value as Record<string, unknown>)[key]);\n }\n }\n\n try {\n check(value);\n JSON.stringify(value);\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('getter') || error.message.includes('circular')) {\n throw error;\n }\n throw new Error(`Contract export is not JSON-serializable: ${error.message}`);\n }\n throw new Error('Contract export is not JSON-serializable');\n }\n}\n\nfunction createImportAllowlistPlugin(allowlist: ReadonlyArray<string>, entryPath: string): Plugin {\n return {\n name: 'import-allowlist',\n setup(build) {\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind === 'entry-point') {\n return undefined;\n }\n if (args.path.startsWith('.') || args.path.startsWith('/')) {\n return undefined;\n }\n const isFromEntryPoint = args.importer === entryPath || args.importer === '<stdin>';\n if (isFromEntryPoint && !isAllowedImport(args.path, allowlist)) {\n return {\n path: args.path,\n external: true,\n };\n }\n return undefined;\n });\n },\n };\n}\n\n/**\n * Loads a contract from a TypeScript file and returns it as ContractIR.\n *\n * **Responsibility: Parsing Only**\n * This function loads and parses a TypeScript contract file. It does NOT normalize the contract.\n * The contract should already be normalized if it was built using the contract builder.\n *\n * Normalization must happen in the contract builder when the contract is created.\n * This function only validates that the contract is JSON-serializable and returns it as-is.\n *\n * @param entryPath - Path to the TypeScript contract file\n * @param options - Optional configuration (import allowlist)\n * @returns The contract as ContractIR (should already be normalized)\n * @throws Error if the contract cannot be loaded or is not JSON-serializable\n */\nexport async function loadContractFromTs(\n entryPath: string,\n options?: LoadTsContractOptions,\n): Promise<ContractIR> {\n const allowlist = options?.allowlist ?? DEFAULT_ALLOWLIST;\n\n if (!existsSync(entryPath)) {\n throw new Error(`Contract file not found: ${entryPath}`);\n }\n\n const tempFile = join(\n tmpdir(),\n `prisma-next-contract-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`,\n );\n\n try {\n const result = await build({\n entryPoints: [entryPath],\n bundle: true,\n format: 'esm',\n platform: 'node',\n target: 'es2022',\n outfile: tempFile,\n write: false,\n metafile: true,\n plugins: [createImportAllowlistPlugin(allowlist, entryPath)],\n logLevel: 'error',\n });\n\n if (result.errors.length > 0) {\n const errorMessages = result.errors.map((e: { text: string }) => e.text).join('\\n');\n throw new Error(`Failed to bundle contract file: ${errorMessages}`);\n }\n\n if (!result.outputFiles || result.outputFiles.length === 0) {\n throw new Error('No output files generated from bundling');\n }\n\n const disallowedImports: string[] = [];\n if (result.metafile) {\n const inputs = result.metafile.inputs;\n for (const [, inputData] of Object.entries(inputs)) {\n const imports =\n (inputData as { imports?: Array<{ path: string; external?: boolean }> }).imports || [];\n for (const imp of imports) {\n if (\n imp.external &&\n !imp.path.startsWith('.') &&\n !imp.path.startsWith('/') &&\n !isAllowedImport(imp.path, allowlist)\n ) {\n disallowedImports.push(imp.path);\n }\n }\n }\n }\n\n if (disallowedImports.length > 0) {\n throw new Error(\n `Disallowed imports detected. Only imports matching the allowlist are permitted:\\n Allowlist: ${allowlist.join(', ')}\\n Disallowed imports: ${disallowedImports.join(', ')}\\n\\nOnly @prisma-next/* packages are allowed in contract files.`,\n );\n }\n\n const bundleContent = result.outputFiles[0]?.text;\n if (bundleContent === undefined) {\n throw new Error('Bundle content is undefined');\n }\n writeFileSync(tempFile, bundleContent, 'utf-8');\n\n const module = (await import(`file://${tempFile}`)) as {\n default?: unknown;\n contract?: unknown;\n };\n unlinkSync(tempFile);\n\n let contract: unknown;\n\n if (module.default !== undefined) {\n contract = module.default;\n } else if (module.contract !== undefined) {\n contract = module.contract;\n } else {\n throw new Error(\n `Contract file must export a contract as default export or named export 'contract'. Found exports: ${Object.keys(module as Record<string, unknown>).join(', ') || 'none'}`,\n );\n }\n\n if (typeof contract !== 'object' || contract === null) {\n throw new Error(`Contract export must be an object, got ${typeof contract}`);\n }\n\n validatePurity(contract);\n\n return contract as ContractIR;\n } catch (error) {\n try {\n if (tempFile) {\n unlinkSync(tempFile);\n }\n } catch {\n // Ignore cleanup errors\n }\n\n if (error instanceof Error) {\n throw error;\n }\n throw new Error(`Failed to load contract from ${entryPath}: ${String(error)}`);\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,YAAY,YAAY,qBAAqB;AACtD,SAAS,cAAc;AACvB,SAAS,YAAY;AAGrB,SAAS,aAAa;AAMtB,IAAM,oBAAoB,CAAC,gBAAgB;AAE3C,SAAS,gBAAgB,YAAoB,WAA2C;AACtF,aAAW,WAAW,WAAW;AAC/B,QAAI,QAAQ,SAAS,IAAI,GAAG;AAC1B,YAAM,SAAS,QAAQ,MAAM,GAAG,EAAE;AAClC,UAAI,eAAe,UAAU,WAAW,WAAW,GAAG,MAAM,GAAG,GAAG;AAChE,eAAO;AAAA,MACT;AAAA,IACF,WAAW,eAAe,SAAS;AACjC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,eAAe,OAAsB;AAC5C,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C;AAAA,EACF;AAEA,QAAM,OAAO,oBAAI,QAAQ;AACzB,WAAS,MAAMA,QAAsB;AACnC,QAAIA,WAAU,QAAQ,OAAOA,WAAU,UAAU;AAC/C;AAAA,IACF;AAEA,QAAI,KAAK,IAAIA,MAAK,GAAG;AACnB,YAAM,IAAI,MAAM,8CAA8C;AAAA,IAChE;AACA,SAAK,IAAIA,MAAK;AAEd,eAAW,OAAOA,QAAO;AACvB,YAAM,aAAa,OAAO,yBAAyBA,QAAO,GAAG;AAC7D,UAAI,eAAe,WAAW,OAAO,WAAW,MAAM;AAC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,IAAI,CAAC;AAAA;AAAA;AAAA,MAC9K;AAAA,IACF;AAEA,UAAM,gBAAgB,OAAO,YAAY,CAAC,GAAG;AAC7C,QAAI,kBAAkB,QAAW;AAC/B,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,kBAAc,UAAU,eAAe,OAAO;AAE9C,UAAM,SAAU,MAAM,OAAO,UAAU,QAAQ;AAI/C,eAAW,QAAQ;AAEnB,QAAI;AAEJ,QAAI,OAAO,YAAY,QAAW;AAChC,iBAAW,OAAO;AAAA,IACpB,WAAW,OAAO,aAAa,QAAW;AACxC,iBAAW,OAAO;AAAA,IACpB,OAAO;AACL,YAAM,IAAI;AAAA,QACR,qGAAqG,OAAO,KAAK,MAAiC,EAAE,KAAK,IAAI,KAAK,MAAM;AAAA,MAC1K;AAAA,IACF;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,IAAI,MAAM,0CAA0C,OAAO,QAAQ,EAAE;AAAA,IAC7E;AAEA,mBAAe,QAAQ;AAEvB,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI;AACF,UAAI,UAAU;AACZ,mBAAW,QAAQ;AAAA,MACrB;AAAA,IACF,QAAQ;AAAA,IAER;AAEA,QAAI,iBAAiB,OAAO;AAC1B,YAAM;AAAA,IACR;AACA,UAAM,IAAI,MAAM,gCAAgC,SAAS,KAAK,OAAO,KAAK,CAAC,EAAE;AAAA,EAC/E;AACF;","names":["value","build"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OnControlProgress } from '../control-api/types';
|
|
2
|
+
import type { GlobalFlags } from './global-flags';
|
|
3
|
+
/**
|
|
4
|
+
* Options for creating a progress adapter.
|
|
5
|
+
*/
|
|
6
|
+
interface ProgressAdapterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Global flags that control progress output behavior (quiet, json, color).
|
|
9
|
+
*/
|
|
10
|
+
readonly flags: GlobalFlags;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a progress adapter that converts control-api progress events
|
|
14
|
+
* into CLI spinner/progress output.
|
|
15
|
+
*
|
|
16
|
+
* The adapter:
|
|
17
|
+
* - Starts/succeeds spinners for top-level span boundaries
|
|
18
|
+
* - Prints per-operation lines for nested spans (e.g., migration operations under 'apply')
|
|
19
|
+
* - Respects quiet/json/non-TTY flags (no-op in those cases)
|
|
20
|
+
*
|
|
21
|
+
* @param options - Progress adapter configuration
|
|
22
|
+
* @returns An onProgress callback compatible with control-api operations
|
|
23
|
+
*/
|
|
24
|
+
export declare function createProgressAdapter(options: ProgressAdapterOptions): OnControlProgress;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=progress-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-adapter.d.ts","sourceRoot":"","sources":["../../src/utils/progress-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,UAAU,sBAAsB;IAC9B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAUD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,iBAAiB,CAmDxF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/cli",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"string-width": "^7.2.0",
|
|
21
21
|
"strip-ansi": "^7.1.2",
|
|
22
22
|
"wrap-ansi": "^9.0.2",
|
|
23
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
24
|
-
"@prisma-next/core-control-plane": "0.3.0-dev.
|
|
25
|
-
"@prisma-next/emitter": "0.3.0-dev.
|
|
26
|
-
"@prisma-next/utils": "0.3.0-dev.
|
|
23
|
+
"@prisma-next/contract": "0.3.0-dev.17",
|
|
24
|
+
"@prisma-next/core-control-plane": "0.3.0-dev.17",
|
|
25
|
+
"@prisma-next/emitter": "0.3.0-dev.17",
|
|
26
|
+
"@prisma-next/utils": "0.3.0-dev.17"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "24.10.4",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"tsup": "8.5.1",
|
|
32
32
|
"typescript": "5.9.3",
|
|
33
33
|
"vitest": "4.0.16",
|
|
34
|
-
"@prisma-next/sql-contract
|
|
35
|
-
"@prisma-next/sql-contract": "0.3.0-dev.
|
|
36
|
-
"@prisma-next/sql-
|
|
37
|
-
"@prisma-next/sql-
|
|
38
|
-
"@prisma-next/
|
|
39
|
-
"@prisma-next/
|
|
34
|
+
"@prisma-next/sql-contract": "0.3.0-dev.17",
|
|
35
|
+
"@prisma-next/sql-contract-emitter": "0.3.0-dev.17",
|
|
36
|
+
"@prisma-next/sql-contract-ts": "0.3.0-dev.17",
|
|
37
|
+
"@prisma-next/sql-operations": "0.3.0-dev.17",
|
|
38
|
+
"@prisma-next/sql-runtime": "0.3.0-dev.17",
|
|
39
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|