prisma-next 0.5.0-dev.7 → 0.5.0-dev.71
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/cli-errors-D3_sMh2K.mjs +33 -0
- package/dist/cli-errors-D3_sMh2K.mjs.map +1 -0
- package/dist/cli-errors-QH8kf-C2.d.mts +3 -0
- package/dist/cli.mjs +16 -78
- package/dist/cli.mjs.map +1 -1
- package/dist/client-0ZX24FXF.mjs +1398 -0
- package/dist/client-0ZX24FXF.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +2 -4
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +2 -4
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +14 -13
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.d.mts.map +1 -1
- package/dist/commands/db-schema.mjs +5 -7
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +8 -9
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +13 -13
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.d.mts.map +1 -1
- package/dist/commands/db-verify.mjs +1 -321
- package/dist/commands/migration-apply.d.mts +5 -2
- package/dist/commands/migration-apply.d.mts.map +1 -1
- package/dist/commands/migration-apply.mjs +64 -66
- package/dist/commands/migration-apply.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts +0 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +33 -40
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +14 -5
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -347
- package/dist/commands/migration-ref.d.mts +1 -1
- package/dist/commands/migration-ref.d.mts.map +1 -1
- package/dist/commands/migration-ref.mjs +7 -12
- package/dist/commands/migration-ref.mjs.map +1 -1
- package/dist/commands/migration-show.d.mts +13 -7
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +34 -36
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +23 -5
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +2 -4
- package/dist/{config-loader-C25b63rJ.mjs → config-loader-B6sJjXTv.mjs} +3 -5
- package/dist/config-loader-B6sJjXTv.mjs.map +1 -0
- package/dist/config-loader.d.mts +0 -1
- package/dist/config-loader.d.mts.map +1 -1
- package/dist/config-loader.mjs +2 -3
- package/dist/contract-emit-B3ChISB_.mjs +338 -0
- package/dist/contract-emit-B3ChISB_.mjs.map +1 -0
- package/dist/contract-emit-DkMqO7f2.mjs +148 -0
- package/dist/contract-emit-DkMqO7f2.mjs.map +1 -0
- package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-CF6ogEJ_.mjs} +4 -6
- package/dist/contract-enrichment-CF6ogEJ_.mjs.map +1 -0
- package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-BDKAE0B0.mjs} +12 -22
- package/dist/contract-infer-BDKAE0B0.mjs.map +1 -0
- package/dist/db-verify-B4TdDKOI.mjs +403 -0
- package/dist/db-verify-B4TdDKOI.mjs.map +1 -0
- package/dist/exports/config-types.mjs +1 -2
- package/dist/exports/control-api.d.mts +287 -29
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +4 -6
- package/dist/exports/index.d.mts.map +1 -1
- package/dist/exports/index.mjs +28 -30
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts +2 -4
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +2 -3
- package/dist/{framework-components-Cr--XBKy.mjs → framework-components-gwAHl7ml.mjs} +3 -4
- package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-gwAHl7ml.mjs.map} +1 -1
- package/dist/{init-C5220SY9.mjs → init-Deo7U8_U.mjs} +26 -35
- package/dist/init-Deo7U8_U.mjs.map +1 -0
- package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-BAgQMYpD.mjs} +10 -11
- package/dist/inspect-live-schema-BAgQMYpD.mjs.map +1 -0
- package/dist/migration-cli.d.mts +41 -12
- package/dist/migration-cli.d.mts.map +1 -1
- package/dist/migration-cli.mjs +309 -86
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-B8J702Uh.mjs} +8 -9
- package/dist/migration-command-scaffold-B8J702Uh.mjs.map +1 -0
- package/dist/migration-plan-BcKNnTM7.mjs +530 -0
- package/dist/migration-plan-BcKNnTM7.mjs.map +1 -0
- package/dist/{migration-status-DUMiH8_G.mjs → migration-status-CjwB2of-.mjs} +117 -64
- package/dist/migration-status-CjwB2of-.mjs.map +1 -0
- package/dist/{migrations-Bo5WtTla.mjs → migrations-CIK94AJf.mjs} +43 -23
- package/dist/migrations-CIK94AJf.mjs.map +1 -0
- package/dist/{output-BpcQrnnq.mjs → output-DnjfCC_u.mjs} +9 -3
- package/dist/output-DnjfCC_u.mjs.map +1 -0
- package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-xASh41wr.mjs} +2 -2
- package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-xASh41wr.mjs.map} +1 -1
- package/dist/{result-handler-Ba3zWQsI.mjs → result-handler-DWb1rFS-.mjs} +52 -27
- package/dist/result-handler-DWb1rFS-.mjs.map +1 -0
- package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-zaRDhJnP.mjs} +2 -6
- package/dist/{terminal-ui-C3ZLwQxK.mjs.map → terminal-ui-zaRDhJnP.mjs.map} +1 -1
- package/dist/{verify-Bkycc-Tf.mjs → verify-BEIa9638.mjs} +3 -4
- package/dist/verify-BEIa9638.mjs.map +1 -0
- package/package.json +19 -17
- package/dist/cli-errors-BFYgBH3L.d.mts +0 -4
- package/dist/cli-errors-Cd79vmTH.mjs +0 -5
- package/dist/client-CrsnY58k.mjs +0 -997
- package/dist/client-CrsnY58k.mjs.map +0 -1
- package/dist/commands/db-verify.mjs.map +0 -1
- package/dist/commands/migration-plan.mjs.map +0 -1
- package/dist/config-loader-C25b63rJ.mjs.map +0 -1
- package/dist/contract-emit--feXyNd7.mjs +0 -4
- package/dist/contract-emit-NJ01hiiv.mjs +0 -195
- package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
- package/dist/contract-emit-V5SSitUT.mjs +0 -122
- package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
- package/dist/contract-enrichment-CAOELa-H.mjs.map +0 -1
- package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
- package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
- package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
- package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
- package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
- package/dist/init-C5220SY9.mjs.map +0 -1
- package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
- package/dist/migration-command-scaffold-B3B09et6.mjs.map +0 -1
- package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
- package/dist/migrations-Bo5WtTla.mjs.map +0 -1
- package/dist/output-BpcQrnnq.mjs.map +0 -1
- package/dist/result-handler-Ba3zWQsI.mjs.map +0 -1
- package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
- package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
- package/dist/verify-Bkycc-Tf.mjs.map +0 -1
|
@@ -1,11 +1,71 @@
|
|
|
1
|
+
import { t as CliStructuredError } from "../cli-errors-QH8kf-C2.mjs";
|
|
1
2
|
import { Result } from "@prisma-next/utils/result";
|
|
2
3
|
import { ContractSourceDiagnostics, ContractSourceProvider } from "@prisma-next/config/config-types";
|
|
3
|
-
import { ControlAdapterDescriptor, ControlDriverDescriptor, ControlExtensionDescriptor, ControlFamilyDescriptor, ControlStack, ControlTargetDescriptor, CoreSchemaView, MigrationPlanOperation, MigrationPlannerConflict, SignDatabaseResult, SignDatabaseResult as SignDatabaseResult$1, VerifyDatabaseResult, VerifyDatabaseResult as VerifyDatabaseResult$1, VerifyDatabaseSchemaResult, VerifyDatabaseSchemaResult as VerifyDatabaseSchemaResult$1 } from "@prisma-next/framework-components/control";
|
|
4
|
+
import { ControlAdapterDescriptor, ControlDriverDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyDescriptor, ControlFamilyInstance, ControlStack, ControlTargetDescriptor, CoreSchemaView, MigrationPlanOperation, MigrationPlannerConflict, OperationPreview, SignDatabaseResult, SignDatabaseResult as SignDatabaseResult$1, TargetMigrationsCapability, VerifyDatabaseResult, VerifyDatabaseResult as VerifyDatabaseResult$1, VerifyDatabaseSchemaResult, VerifyDatabaseSchemaResult as VerifyDatabaseSchemaResult$1 } from "@prisma-next/framework-components/control";
|
|
4
5
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
5
6
|
import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
7
|
+
import { PslDocumentAst } from "@prisma-next/framework-components/psl-ast";
|
|
6
8
|
|
|
9
|
+
//#region src/control-api/operations/db-verify.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Inputs for the aggregate `db verify` operation.
|
|
12
|
+
*
|
|
13
|
+
* Loader → verifier pipeline. The loader (sole descriptor-import
|
|
14
|
+
* boundary) builds a {@link import('@prisma-next/migration-tools/aggregate').ContractSpaceAggregate};
|
|
15
|
+
* the aggregate verifier bundles `markerCheck` + per-space pre-projected
|
|
16
|
+
* `schemaCheck`. `mode: 'strict' | 'lenient'` maps directly to the user
|
|
17
|
+
* facing `--strict` flag.
|
|
18
|
+
*/
|
|
19
|
+
interface ExecuteDbVerifyOptions<TFamilyId extends string, TTargetId extends string> {
|
|
20
|
+
readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
|
|
21
|
+
readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;
|
|
22
|
+
readonly contract: Contract;
|
|
23
|
+
readonly migrationsDir: string;
|
|
24
|
+
readonly targetId: TTargetId;
|
|
25
|
+
readonly extensionPacks: ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>;
|
|
26
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
27
|
+
readonly mode: 'strict' | 'lenient';
|
|
28
|
+
readonly skipSchema: boolean;
|
|
29
|
+
readonly skipMarker: boolean;
|
|
30
|
+
readonly onProgress?: OnControlProgress;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of the aggregate verify operation.
|
|
34
|
+
*
|
|
35
|
+
* Marker-check failures are surfaced as a {@link CliStructuredError}
|
|
36
|
+
* (same envelope code `5002` the legacy `runContractSpaceVerifierMarkerCheck`
|
|
37
|
+
* emitted, so downstream tooling and integration tests assert on the
|
|
38
|
+
* same shape).
|
|
39
|
+
*
|
|
40
|
+
* On success, the per-space schema results are returned for the CLI to
|
|
41
|
+
* render. When `skipSchema` is true (`--marker-only`), the schema map
|
|
42
|
+
* is empty.
|
|
43
|
+
*/
|
|
44
|
+
interface ExecuteDbVerifySuccess {
|
|
45
|
+
readonly schemaResults: ReadonlyMap<string, VerifyDatabaseSchemaResult$1>;
|
|
46
|
+
readonly memberOrder: readonly string[];
|
|
47
|
+
readonly appSpaceId: string;
|
|
48
|
+
}
|
|
49
|
+
type ExecuteDbVerifyResult = Result<ExecuteDbVerifySuccess, CliStructuredError>;
|
|
50
|
+
/**
|
|
51
|
+
* Loader → verifier pipeline shared by `db verify` modes (`full`,
|
|
52
|
+
* `marker-only`, `schema-only`).
|
|
53
|
+
*
|
|
54
|
+
* 1. **Load**: build a {@link import('@prisma-next/migration-tools/aggregate').ContractSpaceAggregate}
|
|
55
|
+
* from descriptors + on-disk on-disk artefacts. Layout / drift /
|
|
56
|
+
* integrity / disjointness violations short-circuit with a
|
|
57
|
+
* structured CLI error.
|
|
58
|
+
* 2. **Read DB state**: marker rows + (when `skipSchema` is `false`)
|
|
59
|
+
* schema introspection.
|
|
60
|
+
* 3. **Verify**: {@link verifyAggregate} returns per-space
|
|
61
|
+
* `markerCheck` + per-space pre-projected `schemaCheck` (closes F23).
|
|
62
|
+
* Marker mismatches map to `CliStructuredError` (code `5002`) so
|
|
63
|
+
* callers (CLI command) can render and exit. Schema results are
|
|
64
|
+
* returned to the caller verbatim.
|
|
65
|
+
*/
|
|
66
|
+
declare function executeDbVerify<TFamilyId extends string, TTargetId extends string>(options: ExecuteDbVerifyOptions<TFamilyId, TTargetId>): Promise<ExecuteDbVerifyResult>;
|
|
67
|
+
//#endregion
|
|
7
68
|
//#region src/control-api/types.d.ts
|
|
8
|
-
|
|
9
69
|
/**
|
|
10
70
|
* Options for creating a control client.
|
|
11
71
|
*
|
|
@@ -34,7 +94,7 @@ interface ControlClientOptions {
|
|
|
34
94
|
/**
|
|
35
95
|
* Action names for control-api operations that can emit progress events.
|
|
36
96
|
*/
|
|
37
|
-
type ControlActionName = 'dbInit' | 'dbUpdate' | 'migrationApply' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
|
|
97
|
+
type ControlActionName = 'dbInit' | 'dbUpdate' | 'dbVerify' | 'migrationApply' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
|
|
38
98
|
/**
|
|
39
99
|
* Progress event emitted during control-api operation execution.
|
|
40
100
|
*
|
|
@@ -143,6 +203,13 @@ interface DbInitOptions {
|
|
|
143
203
|
* The type is driver-specific (e.g., string URL for Postgres).
|
|
144
204
|
*/
|
|
145
205
|
readonly connection?: unknown;
|
|
206
|
+
/**
|
|
207
|
+
* On-disk migrations directory. Always required — every `db init`
|
|
208
|
+
* routes through the per-space flow, which reads on-disk
|
|
209
|
+
* `refs/head.json` and extension destination contracts from this
|
|
210
|
+
* root.
|
|
211
|
+
*/
|
|
212
|
+
readonly migrationsDir: string;
|
|
146
213
|
/** Optional progress callback for observing operation progress */
|
|
147
214
|
readonly onProgress?: OnControlProgress;
|
|
148
215
|
}
|
|
@@ -172,9 +239,33 @@ interface DbUpdateOptions {
|
|
|
172
239
|
* or re-run with -y/--yes.
|
|
173
240
|
*/
|
|
174
241
|
readonly acceptDataLoss?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* On-disk migrations directory. Always required — every `db update`
|
|
244
|
+
* routes through the per-space flow, which reads on-disk
|
|
245
|
+
* `refs/head.json` and extension destination contracts from this
|
|
246
|
+
* root.
|
|
247
|
+
*/
|
|
248
|
+
readonly migrationsDir: string;
|
|
175
249
|
/** Optional progress callback for observing operation progress */
|
|
176
250
|
readonly onProgress?: OnControlProgress;
|
|
177
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Options for the dbVerify operation.
|
|
254
|
+
*
|
|
255
|
+
* Drives the loader → aggregate-verifier pipeline. `strict` maps to
|
|
256
|
+
* `verifyAggregate({ mode: 'strict' | 'lenient' })`; `skipSchema`
|
|
257
|
+
* mirrors the `--marker-only` CLI flag and short-circuits the schema
|
|
258
|
+
* portion of the verifier.
|
|
259
|
+
*/
|
|
260
|
+
interface DbVerifyOptions {
|
|
261
|
+
readonly contract: unknown;
|
|
262
|
+
readonly migrationsDir: string;
|
|
263
|
+
readonly strict: boolean;
|
|
264
|
+
readonly skipSchema: boolean;
|
|
265
|
+
readonly skipMarker: boolean;
|
|
266
|
+
readonly connection?: unknown;
|
|
267
|
+
readonly onProgress?: OnControlProgress;
|
|
268
|
+
}
|
|
178
269
|
/**
|
|
179
270
|
* Options for the introspect operation.
|
|
180
271
|
*/
|
|
@@ -228,7 +319,14 @@ interface DbInitSuccess {
|
|
|
228
319
|
readonly label: string;
|
|
229
320
|
readonly operationClass: string;
|
|
230
321
|
}>;
|
|
231
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Family-agnostic textual preview of the planned operations, e.g.
|
|
324
|
+
* `language: 'sql'` for SQL families and `language: 'mongodb-shell'`
|
|
325
|
+
* for the Mongo family. Replaces the previous `sql?: readonly string[]`
|
|
326
|
+
* field; consumers that previously read `plan.sql` should read
|
|
327
|
+
* `plan.preview?.statements.map((s) => s.text)`.
|
|
328
|
+
*/
|
|
329
|
+
readonly preview?: OperationPreview;
|
|
232
330
|
};
|
|
233
331
|
readonly destination: {
|
|
234
332
|
readonly storageHash: string;
|
|
@@ -282,7 +380,14 @@ interface DbUpdateSuccess {
|
|
|
282
380
|
readonly label: string;
|
|
283
381
|
readonly operationClass: string;
|
|
284
382
|
}>;
|
|
285
|
-
|
|
383
|
+
/**
|
|
384
|
+
* Family-agnostic textual preview of the planned operations, e.g.
|
|
385
|
+
* `language: 'sql'` for SQL families and `language: 'mongodb-shell'`
|
|
386
|
+
* for the Mongo family. Replaces the previous `sql?: readonly string[]`
|
|
387
|
+
* field; consumers that previously read `plan.sql` should read
|
|
388
|
+
* `plan.preview?.statements.map((s) => s.text)`.
|
|
389
|
+
*/
|
|
390
|
+
readonly preview?: OperationPreview;
|
|
286
391
|
};
|
|
287
392
|
readonly destination: {
|
|
288
393
|
readonly storageHash: string;
|
|
@@ -358,10 +463,18 @@ type EmitResult = Result<EmitSuccess, EmitFailure>;
|
|
|
358
463
|
*/
|
|
359
464
|
interface MigrationApplyStep {
|
|
360
465
|
readonly dirName: string;
|
|
361
|
-
readonly from: string;
|
|
466
|
+
readonly from: string | null;
|
|
362
467
|
readonly to: string;
|
|
363
468
|
readonly toContract: Contract;
|
|
364
469
|
readonly operations: readonly MigrationPlanOperation[];
|
|
470
|
+
/**
|
|
471
|
+
* Sorted, deduplicated invariant ids from `migration.json.providedInvariants`.
|
|
472
|
+
* Verified at load time by `readMigrationPackage` (manifest copy must equal
|
|
473
|
+
* the value derived from `ops.json`). The control-api passes this through
|
|
474
|
+
* to the runner via `MigrationPlan.providedInvariants` so target runners
|
|
475
|
+
* read the canonical set instead of re-deriving from `operations`.
|
|
476
|
+
*/
|
|
477
|
+
readonly providedInvariants: readonly string[];
|
|
365
478
|
}
|
|
366
479
|
/**
|
|
367
480
|
* Options for the migrationApply operation.
|
|
@@ -395,7 +508,7 @@ interface MigrationApplyOptions {
|
|
|
395
508
|
*/
|
|
396
509
|
interface MigrationApplyAppliedEntry {
|
|
397
510
|
readonly dirName: string;
|
|
398
|
-
readonly from: string;
|
|
511
|
+
readonly from: string | null;
|
|
399
512
|
readonly to: string;
|
|
400
513
|
readonly operationsExecuted: number;
|
|
401
514
|
}
|
|
@@ -427,17 +540,30 @@ interface MigrationApplyFailure {
|
|
|
427
540
|
type MigrationApplyResult = Result<MigrationApplySuccess, MigrationApplyFailure>;
|
|
428
541
|
/**
|
|
429
542
|
* Options for the standalone executeContractEmit function.
|
|
430
|
-
*
|
|
431
|
-
*
|
|
543
|
+
*
|
|
544
|
+
* `executeContractEmit` is the canonical publication path for both the
|
|
545
|
+
* `prisma-next contract emit` CLI command and the `@prisma-next/vite-plugin-contract-emit`
|
|
546
|
+
* Vite plugin. Do not duplicate the load → emit → publish dance elsewhere; if a
|
|
547
|
+
* caller needs additional behavior, extend this options shape and update the
|
|
548
|
+
* single implementation rather than building a parallel publication path.
|
|
549
|
+
*
|
|
550
|
+
* Concurrent calls for the same output JSON path are serialized per-output via
|
|
551
|
+
* a FIFO queue; concurrent calls for distinct outputs run in parallel.
|
|
432
552
|
*/
|
|
433
553
|
interface ContractEmitOptions {
|
|
434
554
|
/** Path to the prisma-next.config.ts file */
|
|
435
555
|
readonly configPath: string;
|
|
436
|
-
/** Optional AbortSignal for
|
|
556
|
+
/** Optional AbortSignal for cancelling the in-flight emit */
|
|
437
557
|
readonly signal?: AbortSignal;
|
|
558
|
+
/** Optional progress callback for observing source-resolution and emit spans */
|
|
559
|
+
readonly onProgress?: OnControlProgress;
|
|
438
560
|
}
|
|
439
561
|
/**
|
|
440
562
|
* Result from the standalone executeContractEmit function.
|
|
563
|
+
*
|
|
564
|
+
* Always describes the bytes that were just published to disk. Failures throw
|
|
565
|
+
* (config / source-resolution / emit / publish) — callers do not need to
|
|
566
|
+
* branch on a result discriminator.
|
|
441
567
|
*/
|
|
442
568
|
interface ContractEmitResult {
|
|
443
569
|
/** Hash of the storage contract (schema-level) */
|
|
@@ -448,11 +574,15 @@ interface ContractEmitResult {
|
|
|
448
574
|
readonly profileHash: string;
|
|
449
575
|
/** Paths to the emitted files */
|
|
450
576
|
readonly files: {
|
|
451
|
-
/** Path to the emitted contract.json file */
|
|
452
|
-
readonly json: string;
|
|
453
|
-
/** Path to the emitted contract.d.ts file */
|
|
577
|
+
/** Path to the emitted contract.json file */readonly json: string; /** Path to the emitted contract.d.ts file */
|
|
454
578
|
readonly dts: string;
|
|
455
579
|
};
|
|
580
|
+
/**
|
|
581
|
+
* Warning surfaced by `validateContractDeps` after a successful publication.
|
|
582
|
+
* Callers (CLI, Vite plugin) decide how to render this; the operation does
|
|
583
|
+
* not write to stderr itself. Undefined when no warning was raised.
|
|
584
|
+
*/
|
|
585
|
+
readonly validationWarning?: string;
|
|
456
586
|
}
|
|
457
587
|
/**
|
|
458
588
|
* Programmatic control client for Prisma Next operations.
|
|
@@ -535,6 +665,20 @@ interface ControlClient {
|
|
|
535
665
|
* @throws If not connected, target doesn't support migrations, or infrastructure failure
|
|
536
666
|
*/
|
|
537
667
|
dbUpdate(options: DbUpdateOptions): Promise<DbUpdateResult>;
|
|
668
|
+
/**
|
|
669
|
+
* Verifies the database against every contract space (app + extensions).
|
|
670
|
+
*
|
|
671
|
+
* Loader → aggregate-verifier pipeline:
|
|
672
|
+
* - The loader catches layout / drift / disjointness violations.
|
|
673
|
+
* - The aggregate verifier surfaces marker-vs-on-disk drift and orphan
|
|
674
|
+
* markers, and (unless `skipSchema` is true) per-space schema
|
|
675
|
+
* verification with pre-projection (closes F23).
|
|
676
|
+
*
|
|
677
|
+
* @returns Result pattern: per-space schema results on success;
|
|
678
|
+
* structured CLI error on marker / loader failure.
|
|
679
|
+
* @throws If not connected or infrastructure failure
|
|
680
|
+
*/
|
|
681
|
+
dbVerify(options: DbVerifyOptions): Promise<ExecuteDbVerifyResult>;
|
|
538
682
|
/**
|
|
539
683
|
* Reads the contract marker from the database.
|
|
540
684
|
* Returns null if no marker exists (fresh database).
|
|
@@ -542,6 +686,12 @@ interface ControlClient {
|
|
|
542
686
|
* @throws If not connected or infrastructure failure
|
|
543
687
|
*/
|
|
544
688
|
readMarker(): Promise<ContractMarkerRecord | null>;
|
|
689
|
+
/**
|
|
690
|
+
* Reads every marker row (one per contract space). Used by the
|
|
691
|
+
* per-space verifier to detect orphan marker rows and marker-vs-on-disk
|
|
692
|
+
* drift after a database connection has been established.
|
|
693
|
+
*/
|
|
694
|
+
readAllMarkers(): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
545
695
|
/**
|
|
546
696
|
* Applies pre-planned on-disk migrations to the database.
|
|
547
697
|
* Each migration runs in its own transaction with full execution checks.
|
|
@@ -569,6 +719,23 @@ interface ControlClient {
|
|
|
569
719
|
* @returns CoreSchemaView if the family supports it, undefined otherwise
|
|
570
720
|
*/
|
|
571
721
|
toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
|
|
722
|
+
/**
|
|
723
|
+
* Infers a PSL contract AST from an introspected schema IR.
|
|
724
|
+
* Delegates to the family instance's inferPslContract method.
|
|
725
|
+
*
|
|
726
|
+
* @param schemaIR - The schema IR from introspect()
|
|
727
|
+
* @returns PslDocumentAst if the family supports the capability, undefined otherwise
|
|
728
|
+
*/
|
|
729
|
+
inferPslContract(schemaIR: unknown): PslDocumentAst | undefined;
|
|
730
|
+
/**
|
|
731
|
+
* Renders a textual preview of a migration plan's operations for the CLI's
|
|
732
|
+
* "DDL preview" output. Delegates to the family instance's
|
|
733
|
+
* `toOperationPreview` method.
|
|
734
|
+
*
|
|
735
|
+
* @param operations - The migration plan operations to render
|
|
736
|
+
* @returns OperationPreview if the family supports the capability, undefined otherwise
|
|
737
|
+
*/
|
|
738
|
+
toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview | undefined;
|
|
572
739
|
/**
|
|
573
740
|
* Emits the contract to JSON and TypeScript declarations.
|
|
574
741
|
* This is an offline operation that does NOT require a database connection.
|
|
@@ -594,31 +761,122 @@ declare function createControlClient(options: ControlClientOptions): ControlClie
|
|
|
594
761
|
//#endregion
|
|
595
762
|
//#region src/control-api/contract-enrichment.d.ts
|
|
596
763
|
/**
|
|
597
|
-
* Enriches a raw contract with framework-derived metadata:
|
|
598
|
-
* capabilities from all component descriptors and extension pack metadata
|
|
599
|
-
* from extension descriptors. Produces deterministically sorted output.
|
|
764
|
+
* Enriches a raw contract with framework-derived metadata: capabilities from all component descriptors and extension pack metadata from extension descriptors. Produces deterministically sorted output.
|
|
600
765
|
*/
|
|
601
766
|
declare function enrichContract(ir: Contract, components: ReadonlyArray<TargetBoundComponentDescriptor<string, string>>): Contract;
|
|
602
767
|
//#endregion
|
|
603
768
|
//#region src/control-api/operations/contract-emit.d.ts
|
|
604
769
|
/**
|
|
605
|
-
*
|
|
770
|
+
* Canonical contract emit operation.
|
|
606
771
|
*
|
|
607
|
-
* This is
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* 4. Emits contract artifacts (JSON and DTS)
|
|
612
|
-
* 5. Writes files to the paths specified in config
|
|
772
|
+
* This is the SINGLE publication path used by both the CLI command
|
|
773
|
+
* (`prisma-next contract emit`) and the Vite plugin
|
|
774
|
+
* (`@prisma-next/vite-plugin-contract-emit`). New callers must go through this
|
|
775
|
+
* function rather than re-implementing load → emit → publish.
|
|
613
776
|
*
|
|
614
|
-
*
|
|
777
|
+
* The whole flow (load config → resolve source → emit bytes → atomic publish)
|
|
778
|
+
* is serialized per output JSON path via `queueEmitByOutput`. Concurrent calls
|
|
779
|
+
* for the same output line up FIFO; the user-visible outcome is "last
|
|
780
|
+
* submission wins on disk" without any supersession bookkeeping. Within a
|
|
781
|
+
* single emit, `publishContractArtifactPair` stages temp files, renames
|
|
782
|
+
* `contract.d.ts` before `contract.json`, and attempts to restore the previous
|
|
783
|
+
* pair if either rename fails — so type-only consumers never observe a
|
|
784
|
+
* mismatched pair.
|
|
615
785
|
*
|
|
616
|
-
* @
|
|
617
|
-
* @
|
|
618
|
-
* @throws If config loading fails, contract is invalid, or file I/O fails
|
|
619
|
-
* @throws signal.reason if cancelled via AbortSignal (typically DOMException with name 'AbortError')
|
|
786
|
+
* @throws {CliStructuredError} on config/source/validation problems
|
|
787
|
+
* @throws {DOMException} `AbortError` if cancelled via `signal`
|
|
620
788
|
*/
|
|
621
789
|
declare function executeContractEmit(options: ContractEmitOptions): Promise<ContractEmitResult>;
|
|
622
790
|
//#endregion
|
|
623
|
-
|
|
791
|
+
//#region src/control-api/operations/db-init.d.ts
|
|
792
|
+
/**
|
|
793
|
+
* Options for executing the `db init` operation.
|
|
794
|
+
*
|
|
795
|
+
* `db init` runs the loader → planner → runner pipeline:
|
|
796
|
+
*
|
|
797
|
+
* 1. {@link executeAggregateApply} loads a `ContractSpaceAggregate` via
|
|
798
|
+
* {@link import('@prisma-next/migration-tools/aggregate').loadContractSpaceAggregate}
|
|
799
|
+
* from the supplied descriptor set + on-disk on-disk artefacts.
|
|
800
|
+
* 2. The aggregate planner runs with `callerPolicy.ignoreGraphFor`
|
|
801
|
+
* locked to the app member — synth strategy for the app, graph-walk
|
|
802
|
+
* for every extension.
|
|
803
|
+
* 3. The runner's `executeAcrossSpaces` applies the per-space plans
|
|
804
|
+
* inside one outer transaction.
|
|
805
|
+
*
|
|
806
|
+
* `extensionPacks` mirrors `Config.extensionPacks` (descriptor list).
|
|
807
|
+
* The loader (sub-spec § Loader) is the sole descriptor-import boundary.
|
|
808
|
+
*/
|
|
809
|
+
interface ExecuteDbInitOptions<TFamilyId extends string, TTargetId extends string> {
|
|
810
|
+
readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
|
|
811
|
+
readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;
|
|
812
|
+
readonly contract: Contract;
|
|
813
|
+
readonly mode: 'plan' | 'apply';
|
|
814
|
+
readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, ControlFamilyInstance<TFamilyId, unknown>>;
|
|
815
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
816
|
+
/**
|
|
817
|
+
* On-disk migrations directory the aggregate loader reads on-disk
|
|
818
|
+
* artefacts from. Required.
|
|
819
|
+
*/
|
|
820
|
+
readonly migrationsDir: string;
|
|
821
|
+
/**
|
|
822
|
+
* Resolved adapter target id. Threaded through to the loader for
|
|
823
|
+
* target-consistency checks across descriptors and the app contract.
|
|
824
|
+
*/
|
|
825
|
+
readonly targetId: TTargetId;
|
|
826
|
+
/**
|
|
827
|
+
* Declared extension descriptors. Defaults to an empty list, which
|
|
828
|
+
* routes through the same loader → planner → runner pipeline with no
|
|
829
|
+
* extension members in the aggregate.
|
|
830
|
+
*/
|
|
831
|
+
readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>;
|
|
832
|
+
/** Optional progress callback for observing operation progress */
|
|
833
|
+
readonly onProgress?: OnControlProgress;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Execute `db init` against the configured contract.
|
|
837
|
+
*
|
|
838
|
+
* Routes through the loader → planner → runner pipeline (sub-spec
|
|
839
|
+
* "Commit-by-commit § Commit 4"). Always additive-only; destructive
|
|
840
|
+
* changes belong to `db update`.
|
|
841
|
+
*/
|
|
842
|
+
declare function executeDbInit<TFamilyId extends string, TTargetId extends string>(options: ExecuteDbInitOptions<TFamilyId, TTargetId>): Promise<DbInitResult>;
|
|
843
|
+
//#endregion
|
|
844
|
+
//#region src/control-api/operations/db-update.d.ts
|
|
845
|
+
/**
|
|
846
|
+
* Options for the `db update` operation.
|
|
847
|
+
*
|
|
848
|
+
* Same loader → planner → runner pipeline as `db init`, but with the
|
|
849
|
+
* widened operation policy (additive + widening + destructive). The
|
|
850
|
+
* destructive-change confirmation gate runs at this layer: when
|
|
851
|
+
* `mode === 'apply'` and `acceptDataLoss` is `false`, the operation
|
|
852
|
+
* pre-plans, surfaces destructive ops to the caller, and aborts.
|
|
853
|
+
*/
|
|
854
|
+
interface ExecuteDbUpdateOptions<TFamilyId extends string, TTargetId extends string> {
|
|
855
|
+
readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
|
|
856
|
+
readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;
|
|
857
|
+
readonly contract: Contract;
|
|
858
|
+
readonly mode: 'plan' | 'apply';
|
|
859
|
+
readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, ControlFamilyInstance<TFamilyId, unknown>>;
|
|
860
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
861
|
+
readonly acceptDataLoss?: boolean;
|
|
862
|
+
readonly migrationsDir: string;
|
|
863
|
+
readonly targetId: TTargetId;
|
|
864
|
+
readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<TFamilyId, TTargetId>>;
|
|
865
|
+
readonly onProgress?: OnControlProgress;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Execute `db update` against the configured contract.
|
|
869
|
+
*
|
|
870
|
+
* Routes through the loader → planner → runner pipeline. Destructive
|
|
871
|
+
* operations require either `acceptDataLoss: true` or a prior
|
|
872
|
+
* `mode: 'plan'` invocation that surfaces the destructive ops; the
|
|
873
|
+
* confirmation gate is implemented here so the lower-level applier
|
|
874
|
+
* remains policy-agnostic.
|
|
875
|
+
*/
|
|
876
|
+
declare function executeDbUpdate<TFamilyId extends string, TTargetId extends string>(options: ExecuteDbUpdateOptions<TFamilyId, TTargetId>): Promise<DbUpdateResult>;
|
|
877
|
+
//#endregion
|
|
878
|
+
//#region src/utils/emit-queue.d.ts
|
|
879
|
+
declare function disposeEmitQueue(outputJsonPath: string): void;
|
|
880
|
+
//#endregion
|
|
881
|
+
export { type ContractEmitOptions, type ContractEmitResult, type ControlActionName, type ControlClient, type ControlClientOptions, type ControlProgressEvent, type ControlStack, type DbInitFailure, type DbInitFailureCode, type DbInitOptions, type DbInitResult, type DbInitSuccess, type DbUpdateFailure, type DbUpdateFailureCode, type DbUpdateOptions, type DbUpdateResult, type DbUpdateSuccess, type EmitContractConfig, type EmitFailure, type EmitFailureCode, type EmitOptions, type EmitResult, type EmitSuccess, type ExecuteDbInitOptions, type ExecuteDbUpdateOptions, type ExecuteDbVerifyOptions, type ExecuteDbVerifyResult, type IntrospectOptions, type OnControlProgress, type SchemaVerifyOptions, type SignDatabaseResult, type SignOptions, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, type VerifyOptions, createControlClient, disposeEmitQueue, enrichContract, executeContractEmit, executeDbInit, executeDbUpdate, executeDbVerify };
|
|
624
882
|
//# sourceMappingURL=control-api.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-api.d.mts","names":[],"sources":["../../src/control-api/types.ts","../../src/control-api/client.ts","../../src/control-api/contract-enrichment.ts","../../src/control-api/operations/contract-emit.ts"
|
|
1
|
+
{"version":3,"file":"control-api.d.mts","names":[],"sources":["../../src/control-api/operations/db-verify.ts","../../src/control-api/types.ts","../../src/control-api/client.ts","../../src/control-api/contract-enrichment.ts","../../src/control-api/operations/contract-emit.ts","../../src/control-api/operations/db-init.ts","../../src/control-api/operations/db-update.ts","../../src/utils/emit-queue.ts"],"mappings":";;;;;;;;;;;;AAwCA;;;;;;UAAiB,sBAAA;EAAA,SACN,MAAA,EAAQ,qBAAA,CAAsB,SAAA,EAAW,SAAA;EAAA,SACzC,cAAA,EAAgB,qBAAA,CAAsB,SAAA;EAAA,SACtC,QAAA,EAAU,QAAA;EAAA,SACV,aAAA;EAAA,SACA,QAAA,EAAU,SAAA;EAAA,SACV,cAAA,EAAgB,aAAA,CAAc,0BAAA,CAA2B,SAAA,EAAW,SAAA;E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,SAAA,EAAW,SAAA,IACxC,OAAA,CAAQ,YAAA;;;;;;;;AL7BX;;;;UMdiB,sBAAA;EAAA,SACN,MAAA,EAAQ,qBAAA,CAAsB,SAAA,EAAW,SAAA;EAAA,SACzC,cAAA,EAAgB,qBAAA,CAAsB,SAAA;EAAA,SACtC,QAAA,EAAU,QAAA;EAAA,SACV,IAAA;EAAA,SACA,UAAA,EAAY,0BAAA,CACnB,SAAA,EACA,SAAA,EACA,qBAAA,CAAsB,SAAA;EAAA,SAEf,mBAAA,EAAqB,aAAA,CAAc,8BAAA,CAA+B,SAAA,EAAW,SAAA;EAAA,SAC7E,cAAA;EAAA,SACA,aAAA;EAAA,SACA,QAAA,EAAU,SAAA;EAAA,SACV,cAAA,GAAiB,aAAA,CAAc,0BAAA,CAA2B,SAAA,EAAW,SAAA;EAAA,SACrE,UAAA,GAAa,iBAAA;AAAA;;;;;;;;;;iBAYF,eAAA,oDAAA,CACpB,OAAA,EAAS,sBAAA,CAAuB,SAAA,EAAW,SAAA,IAC1C,OAAA,CAAQ,cAAA;;;iBChCK,gBAAA,CAAiB,cAAA"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { t as enrichContract } from "../contract-enrichment-
|
|
3
|
-
import { t as createControlClient } from "../client-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { createControlClient, enrichContract, executeContractEmit };
|
|
1
|
+
import { n as executeContractEmit, r as disposeEmitQueue } from "../contract-emit-B3ChISB_.mjs";
|
|
2
|
+
import { t as enrichContract } from "../contract-enrichment-CF6ogEJ_.mjs";
|
|
3
|
+
import { i as executeDbInit, n as executeDbVerify, r as executeDbUpdate, t as createControlClient } from "../client-0ZX24FXF.mjs";
|
|
4
|
+
export { createControlClient, disposeEmitQueue, enrichContract, executeContractEmit, executeDbInit, executeDbUpdate, executeDbVerify };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/load-ts-contract.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/load-ts-contract.ts"],"mappings":";;;;UAQiB,qBAAA;EAAA,SACN,SAAA,GAAY,aAAA;AAAA;AADvB;;;;;AA6HA;;;;;;;;;;AA7HA,iBA6HsB,kBAAA,CACpB,SAAA,UACA,OAAA,GAAU,qBAAA,GACT,OAAA,CAAQ,QAAA"}
|
package/dist/exports/index.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import {
|
|
1
|
+
import { t as createContractEmitCommand } from "../contract-emit-DkMqO7f2.mjs";
|
|
2
|
+
import { join, resolve } from "pathe";
|
|
3
3
|
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { join } from "pathe";
|
|
5
4
|
import { tmpdir } from "node:os";
|
|
6
5
|
import { pathToFileURL } from "node:url";
|
|
7
6
|
import { build } from "esbuild";
|
|
8
|
-
|
|
9
7
|
//#region src/load-ts-contract.ts
|
|
10
8
|
const DEFAULT_ALLOWLIST = ["@prisma-next/*", "node:crypto"];
|
|
11
9
|
function isAllowedImport(importPath, allowlist) {
|
|
@@ -21,19 +19,19 @@ function isAllowedImport(importPath, allowlist) {
|
|
|
21
19
|
function validatePurity(value) {
|
|
22
20
|
if (typeof value !== "object" || value === null) return;
|
|
23
21
|
const path = /* @__PURE__ */ new WeakSet();
|
|
24
|
-
function check(value
|
|
25
|
-
if (value
|
|
26
|
-
if (path.has(value
|
|
27
|
-
path.add(value
|
|
22
|
+
function check(value) {
|
|
23
|
+
if (value === null || typeof value !== "object") return;
|
|
24
|
+
if (path.has(value)) throw new Error("Contract export contains circular references");
|
|
25
|
+
path.add(value);
|
|
28
26
|
try {
|
|
29
|
-
for (const key in value
|
|
30
|
-
const descriptor = Object.getOwnPropertyDescriptor(value
|
|
27
|
+
for (const key in value) {
|
|
28
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
31
29
|
if (descriptor && (descriptor.get || descriptor.set)) throw new Error(`Contract export contains getter/setter at key "${key}"`);
|
|
32
30
|
if (descriptor && typeof descriptor.value === "function") throw new Error(`Contract export contains function at key "${key}"`);
|
|
33
|
-
check(value
|
|
31
|
+
check(value[key]);
|
|
34
32
|
}
|
|
35
33
|
} finally {
|
|
36
|
-
path.delete(value
|
|
34
|
+
path.delete(value);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
try {
|
|
@@ -47,17 +45,24 @@ function validatePurity(value) {
|
|
|
47
45
|
throw new Error("Contract export is not JSON-serializable");
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
function createImportAllowlistPlugin(allowlist, entryPath) {
|
|
48
|
+
function createImportAllowlistPlugin(allowlist, entryPath, collected) {
|
|
49
|
+
const entryAbs = resolve(entryPath);
|
|
50
|
+
function isFromEntry(importer) {
|
|
51
|
+
return importer === entryAbs || importer === entryPath || importer === "<stdin>";
|
|
52
|
+
}
|
|
51
53
|
return {
|
|
52
54
|
name: "import-allowlist",
|
|
53
|
-
setup(build
|
|
54
|
-
build
|
|
55
|
+
setup(build) {
|
|
56
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
55
57
|
if (args.kind === "entry-point") return;
|
|
56
58
|
if (args.path.startsWith(".") || args.path.startsWith("/")) return;
|
|
57
|
-
if ((args.importer
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
if (isFromEntry(args.importer) && !isAllowedImport(args.path, allowlist)) {
|
|
60
|
+
collected.add(args.path);
|
|
61
|
+
return {
|
|
62
|
+
path: args.path,
|
|
63
|
+
external: true
|
|
64
|
+
};
|
|
65
|
+
}
|
|
61
66
|
});
|
|
62
67
|
}
|
|
63
68
|
};
|
|
@@ -81,6 +86,7 @@ async function loadContractFromTs(entryPath, options) {
|
|
|
81
86
|
const allowlist = options?.allowlist ?? DEFAULT_ALLOWLIST;
|
|
82
87
|
if (!existsSync(entryPath)) throw new Error(`Contract file not found: ${entryPath}`);
|
|
83
88
|
const tempFile = join(tmpdir(), `prisma-next-contract-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`);
|
|
89
|
+
const disallowedFromEntry = /* @__PURE__ */ new Set();
|
|
84
90
|
try {
|
|
85
91
|
const result = await build({
|
|
86
92
|
entryPoints: [entryPath],
|
|
@@ -91,7 +97,7 @@ async function loadContractFromTs(entryPath, options) {
|
|
|
91
97
|
outfile: tempFile,
|
|
92
98
|
write: false,
|
|
93
99
|
metafile: true,
|
|
94
|
-
plugins: [createImportAllowlistPlugin(allowlist, entryPath)],
|
|
100
|
+
plugins: [createImportAllowlistPlugin(allowlist, entryPath, disallowedFromEntry)],
|
|
95
101
|
logLevel: "error"
|
|
96
102
|
});
|
|
97
103
|
if (result.errors.length > 0) {
|
|
@@ -99,15 +105,7 @@ async function loadContractFromTs(entryPath, options) {
|
|
|
99
105
|
throw new Error(`Failed to bundle contract file: ${errorMessages}`);
|
|
100
106
|
}
|
|
101
107
|
if (!result.outputFiles || result.outputFiles.length === 0) throw new Error("No output files generated from bundling");
|
|
102
|
-
|
|
103
|
-
if (result.metafile) {
|
|
104
|
-
const inputs = result.metafile.inputs;
|
|
105
|
-
for (const [, inputData] of Object.entries(inputs)) {
|
|
106
|
-
const imports = inputData.imports || [];
|
|
107
|
-
for (const imp of imports) if (imp.external && !imp.path.startsWith(".") && !imp.path.startsWith("/") && !isAllowedImport(imp.path, allowlist)) disallowedImports.push(imp.path);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (disallowedImports.length > 0) throw new Error(`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.`);
|
|
108
|
+
if (disallowedFromEntry.size > 0) throw new Error(`Disallowed imports detected. Only imports matching the allowlist are permitted:\n Allowlist: ${allowlist.join(", ")}\n Disallowed imports: ${[...disallowedFromEntry].join(", ")}`);
|
|
111
109
|
const bundleContent = result.outputFiles[0]?.text;
|
|
112
110
|
if (bundleContent === void 0) throw new Error("Bundle content is undefined");
|
|
113
111
|
writeFileSync(tempFile, bundleContent, "utf-8");
|
|
@@ -131,7 +129,7 @@ async function loadContractFromTs(entryPath, options) {
|
|
|
131
129
|
throw new Error(`Failed to load contract from ${entryPath}: ${String(error)}`);
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
|
-
|
|
135
132
|
//#endregion
|
|
136
133
|
export { createContractEmitCommand, loadContractFromTs };
|
|
134
|
+
|
|
137
135
|
//# sourceMappingURL=index.mjs.map
|