@prisma/orm-toolchain 8.0.0-rc.12-dev.14 → 8.0.0-rc.12-dev.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{aggregate-CZyUi3Gt.mjs → aggregate-BsI5y36e.mjs} +9 -9
- package/dist/{aggregate-CZyUi3Gt.mjs.map → aggregate-BsI5y36e.mjs.map} +1 -1
- package/dist/{aggregate-DwZNs0oH.d.mts → aggregate-C_e9y2vI.d.mts} +2 -2
- package/dist/{aggregate-DwZNs0oH.d.mts.map → aggregate-C_e9y2vI.d.mts.map} +1 -1
- package/dist/cli-telemetry.mjs +3 -3
- package/dist/cli.d.mts +2 -2
- package/dist/cli.mjs +377 -48
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +25 -21
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +1 -1
- package/dist/cli__control-api__testing.d.mts +2 -2
- package/dist/cli__control-api__testing.mjs +1 -1
- package/dist/cli__migration-cli.mjs +5 -5
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.d.mts +2 -2
- package/dist/config-loader.mjs +2 -2
- package/dist/{contract-snapshot-store-1S_6vaGt-mzFobPtq.mjs → contract-snapshot-store-1S_6vaGt-FrXDiBEd.mjs} +4 -4
- package/dist/{contract-snapshot-store-1S_6vaGt-mzFobPtq.mjs.map → contract-snapshot-store-1S_6vaGt-FrXDiBEd.mjs.map} +1 -1
- package/dist/{db-verify-D4Y9yGyX-Df6oIwYg.d.mts → db-verify-DoVihHM8-QNzdRseL.d.mts} +4 -4
- package/dist/{db-verify-D4Y9yGyX-Df6oIwYg.d.mts.map → db-verify-DoVihHM8-QNzdRseL.d.mts.map} +1 -1
- package/dist/emitter.mjs +1 -1
- package/dist/{errors-DD6iLGXk-B4Q4tIha.mjs → errors-DD6iLGXk-6I9PqjpZ.mjs} +2 -2
- package/dist/{errors-DD6iLGXk-B4Q4tIha.mjs.map → errors-DD6iLGXk-6I9PqjpZ.mjs.map} +1 -1
- package/dist/{exports-4SvYVqSf.mjs → exports-BB9aU4zk.mjs} +4 -4
- package/dist/{exports-4SvYVqSf.mjs.map → exports-BB9aU4zk.mjs.map} +1 -1
- package/dist/{exports-DI1kMms6--e9LdT9A.mjs → exports-Bx-2JeW0-BHlN6Av7.mjs} +4 -3
- package/dist/exports-Bx-2JeW0-BHlN6Av7.mjs.map +1 -0
- package/dist/{exports-BOv2LgXz.mjs → exports-C2kyulLb.mjs} +19 -10
- package/dist/exports-C2kyulLb.mjs.map +1 -0
- package/dist/{graph-membership-BQ43lP4A-B8rZC7rC.mjs → graph-membership-BQ43lP4A-i4Ov419-.mjs} +2 -2
- package/dist/{graph-membership-BQ43lP4A-B8rZC7rC.mjs.map → graph-membership-BQ43lP4A-i4Ov419-.mjs.map} +1 -1
- package/dist/{import-roots-CR-pnC1n.mjs → import-roots-BB3GzIi-.mjs} +2 -2
- package/dist/{import-roots-CR-pnC1n.mjs.map → import-roots-BB3GzIi-.mjs.map} +1 -1
- package/dist/{index-D_KaEMoL.d.mts → index-CQm4jQjG.d.mts} +8 -3
- package/dist/index-CQm4jQjG.d.mts.map +1 -0
- package/dist/{invariants-C0lpc60l-MH7CqDAw.mjs → invariants-C0lpc60l-CMUCvk4O.mjs} +2 -2
- package/dist/{invariants-C0lpc60l-MH7CqDAw.mjs.map → invariants-C0lpc60l-CMUCvk4O.mjs.map} +1 -1
- package/dist/{io-xKnQrxIC-D_C_lwGm.mjs → io-xKnQrxIC-BZHUkAeY.mjs} +4 -4
- package/dist/{io-xKnQrxIC-D_C_lwGm.mjs.map → io-xKnQrxIC-BZHUkAeY.mjs.map} +1 -1
- package/dist/{migration-CkACVhgz.mjs → migration-CTBcGs-o.mjs} +4 -4
- package/dist/{migration-CkACVhgz.mjs.map → migration-CTBcGs-o.mjs.map} +1 -1
- package/dist/migration-tools.d.mts +1 -1
- package/dist/migration-tools.mjs +12 -12
- package/dist/migration-tools__aggregate.d.mts +1 -1
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +1 -1
- package/dist/migration-tools__errors.mjs +1 -1
- package/dist/migration-tools__invariants.mjs +1 -1
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.mjs +1 -1
- package/dist/migration-tools__migration-ts.mjs +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{migration-ts-FyF55c4M.mjs → migration-ts-DdVm0rws.mjs} +2 -2
- package/dist/{migration-ts-FyF55c4M.mjs.map → migration-ts-DdVm0rws.mjs.map} +1 -1
- package/dist/publish-surface.mjs +2 -2
- package/dist/publish-surface__import-roots.mjs +1 -1
- package/dist/publish-surface__shells.mjs +1 -1
- package/dist/{ref-jhp3BGZM-CI91tliC.mjs → ref-DZuzAvuD-BYpisYJp.mjs} +269 -270
- package/dist/ref-DZuzAvuD-BYpisYJp.mjs.map +1 -0
- package/dist/{ref-resolution-be3JMf5X.mjs → ref-resolution-CyyiVwzz.mjs} +2 -2
- package/dist/{ref-resolution-be3JMf5X.mjs.map → ref-resolution-CyyiVwzz.mjs.map} +1 -1
- package/dist/{refs-qwvw4_dV-Bk9tl756.mjs → refs-qwvw4_dV-DNg_7WTD.mjs} +2 -2
- package/dist/{refs-qwvw4_dV-Bk9tl756.mjs.map → refs-qwvw4_dV-DNg_7WTD.mjs.map} +1 -1
- package/dist/{shells-B05MST_L.mjs → shells-nviMkCdc.mjs} +2 -1
- package/dist/shells-nviMkCdc.mjs.map +1 -0
- package/dist/{spaces-D1-7OKid.mjs → spaces-CcU9rbeZ.mjs} +7 -7
- package/dist/{spaces-D1-7OKid.mjs.map → spaces-CcU9rbeZ.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-CYjc343k-9_2GpPRg.mjs → verify-contract-spaces-CYjc343k-DHy5xtKR.mjs} +4 -4
- package/dist/{verify-contract-spaces-CYjc343k-9_2GpPRg.mjs.map → verify-contract-spaces-CYjc343k-DHy5xtKR.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +3 -3
- package/package.json +12 -12
- package/dist/exports-BOv2LgXz.mjs.map +0 -1
- package/dist/exports-DI1kMms6--e9LdT9A.mjs.map +0 -1
- package/dist/index-D_KaEMoL.d.mts.map +0 -1
- package/dist/ref-jhp3BGZM-CI91tliC.mjs.map +0 -1
- package/dist/shells-B05MST_L.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { h as requireConfigSections, i as expandContractInputs, m as ormConfigSection, n as buildLoadedConfig, r as evaluateConfigModule, s as globContractInputMatching, u as loadConfigFiles } from "./exports-C2kyulLb.mjs";
|
|
2
|
+
import { r as getEmittedArtifactPaths } from "./exports-Bx-2JeW0-BHlN6Av7.mjs";
|
|
3
|
+
import { t as MigrationToolsError } from "./errors-DD6iLGXk-6I9PqjpZ.mjs";
|
|
4
|
+
import { t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-FrXDiBEd.mjs";
|
|
4
5
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
5
|
-
import { r as readRef } from "./refs-qwvw4_dV-
|
|
6
|
-
import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CYjc343k-
|
|
7
|
-
import { i as createScaffoldSpecifierResolver } from "./import-roots-
|
|
8
|
-
import { $ as
|
|
6
|
+
import { r as readRef } from "./refs-qwvw4_dV-DNg_7WTD.mjs";
|
|
7
|
+
import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CYjc343k-DHy5xtKR.mjs";
|
|
8
|
+
import { i as createScaffoldSpecifierResolver } from "./import-roots-BB3GzIi-.mjs";
|
|
9
|
+
import { $ as findPackageByDirPath, A as errorHashMismatch, At as resolveMigrationRef, B as errorTargetMismatch, Bt as toDeclaredExtensionsFromRaw, C as errorContractArgConflict, Ct as refusePackageCorruptionOnAggregate, D as errorDestructiveChanges, Dt as resolveContractRef$1, E as errorDatabaseConnectionRequired, Et as resolveAppTargetPath, F as errorNoMigrations, Ft as runMigrationList, H as executeContractEmit, I as errorPathUnreachable, It as sanitizeErrorMessage, J as executeMigrationPlanCommand, K as executeMigrateShowPlan, L as errorRunnerFailed, Lt as snapshotVerifierFor, M as errorMarkerMissing, Mt as runCommandAction, N as errorMigrationPackageNotFound, O as errorDriverRequired, Ot as resolveContractRefToSnapshot, P as errorMigrationPlanningFailed, Pt as runMigrationCheck, Q as executeRefSetCommand, R as errorRuntime, Rt as statusForMigrationHash, S as errorConsentPlanMismatch, St as refuseMissingInvariantPath, T as errorContractValidationFailed, Tt as requireLiveDatabase, V as errorUnexpected, Vt as validateLoadedContract, X as executeRefDeleteCommand, Z as executeRefListCommand, _t as readMigrationRefs, at as loadContractSource, b as errorAdvanceRefArgConflict, c as buildMigrationSpaceGraphEntries, ct as looksLikePath, d as checkSingleTarget, et as formatSourceDiagnostic, f as chooseAction, ft as maskConnectionUrl, g as deriveStatusEdgeAnnotations, gt as readContractEnvelope, h as createControlClient, ht as preflightRefAdvancement, i as advanceRefSafely, it as loadContractRawSafely, j as errorLegendHumanOnly, k as errorFileNotFound, l as buildReadAggregate, lt as mapCaughtMigrationError, m as computeRefAdvancementName, mt as originHashForStatus, n as ERROR_CODE_DESTRUCTIVE_CHANGES, nt as listRefsByContractHash, o as appliedHashesFromLedger, ot as loadContractSourceWithStack, p as closeQuietly, pt as migrationSpaceListEntriesFromAggregate, q as executeMigrationNewCommand, r as NO_REF_ADVANCEMENT, rt as loadAggregateIntegrityViolations, st as loadContractSpaceAggregateForCli, t as CliStructuredError$1$1, tt as hasMigrationPath, u as buildRefAdvancementFields, ut as mapContractAtError, vt as redactUrlCredentials, w as errorContractConfigMissing, wt as refuseUnknownInvariants, x as errorConfigValidation$1, xt as refuseMarkerOutsideGraph, y as enumerateCheckSpaces, yt as refuseContractSpaceIntegrity, z as errorTargetMigrationNotSupported, zt as targetSupportsMigrations } from "./ref-DZuzAvuD-BYpisYJp.mjs";
|
|
9
10
|
import { a as PRISMA7_QUICK_REFERENCE_STEP, i as PRISMA7_LOOP_STEP, n as InitOutputSchema, o as buildNextSteps, r as NEXT_STEPS_BEFORE_SCAFFOLD, t as DB_SIGN_STEP } from "./output-BcC8eB0h-C5bRd-aC.mjs";
|
|
10
11
|
import { createRequire } from "node:module";
|
|
11
12
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
12
13
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
13
|
-
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
14
|
-
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
15
|
-
import { pathToFileURL } from "node:url";
|
|
16
14
|
import { DOCS_BASE, docsUrlFor, isStructuredError, isStructuredErrorCode } from "@prisma/orm-framework/utils/structured-error";
|
|
17
15
|
import { keepInternalSpecifiers } from "@prisma/orm-framework/components/emission";
|
|
18
16
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
19
17
|
import { InternalError, assertNever, isInternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
20
18
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
19
|
+
import { APP_SPACE_ID, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, createControlStack, hasPslContractBuild, issueOutcome } from "@prisma/orm-framework/components/control";
|
|
21
20
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
21
|
+
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
22
|
+
import { mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
24
23
|
import { type } from "arktype";
|
|
24
|
+
import { pathToFileURL } from "node:url";
|
|
25
|
+
import { defineCommand, defineCommandFamily, defineServerCommand, flag, positional } from "@prisma/cli-engine";
|
|
25
26
|
import { CliStructuredError as CliStructuredError$1, notOk as notOk$1, ok as ok$1 } from "@prisma/cli-engine/protocol";
|
|
26
27
|
import { printPsl } from "@prisma/orm-framework/psl-printer";
|
|
28
|
+
import { DEFAULT_CONTRACT_SOURCE_DIR, defaultContractOutputPath } from "@prisma/orm-framework/config/config-types";
|
|
27
29
|
import { EOL, tmpdir } from "node:os";
|
|
28
30
|
import { format } from "@prisma/orm-framework/psl-parser/format";
|
|
29
31
|
import { suppressIdleConnectionErrors } from "@prisma/orm-framework/utils/suppress-idle-connection-errors";
|
|
30
|
-
import { DEFAULT_CONTRACT_SOURCE_DIR } from "@prisma/orm-framework/config/config-types";
|
|
31
32
|
import { spawn } from "node:child_process";
|
|
32
33
|
import { detect } from "package-manager-detector/detect";
|
|
33
34
|
import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
34
35
|
import stringWidth from "string-width";
|
|
35
36
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
36
37
|
import { build } from "esbuild";
|
|
37
|
-
//#region ../../../1-framework/3-tooling/cli/dist/load-config-
|
|
38
|
+
//#region ../../../1-framework/3-tooling/cli/dist/load-config-BlkxAzxF.mjs
|
|
38
39
|
/**
|
|
39
40
|
* `isStructuredError` is the repo's own check, and it is the one that matters here: it holds the
|
|
40
41
|
* regular expression for a dotted `NAMESPACE.SUBCODE`, so only a code the protocol accepts
|
|
@@ -326,6 +327,55 @@ function inferredContractPathFor(inputs) {
|
|
|
326
327
|
if (contractOutput !== void 0) return join(dirname(resolve(inputs.cwd, contractOutput)), INFERRED_CONTRACT_FILENAME);
|
|
327
328
|
return join(inputs.cwd, INFERRED_CONTRACT_FILENAME);
|
|
328
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* The nearest part of `path` that exists, with symbolic links resolved, and
|
|
332
|
+
* the names below it that do not exist yet.
|
|
333
|
+
*/
|
|
334
|
+
async function existingPart(path) {
|
|
335
|
+
const missing = [];
|
|
336
|
+
let candidate = path;
|
|
337
|
+
for (;;) try {
|
|
338
|
+
return {
|
|
339
|
+
existing: normalize(await realpath(candidate)),
|
|
340
|
+
missing
|
|
341
|
+
};
|
|
342
|
+
} catch {
|
|
343
|
+
const parent = dirname(candidate);
|
|
344
|
+
if (parent === candidate) return {
|
|
345
|
+
existing: candidate,
|
|
346
|
+
missing
|
|
347
|
+
};
|
|
348
|
+
missing.unshift(basename(candidate));
|
|
349
|
+
candidate = parent;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function withCaseSwapped(path) {
|
|
353
|
+
return [...path].map((character) => {
|
|
354
|
+
const upper = character.toUpperCase();
|
|
355
|
+
return character === upper ? character.toLowerCase() : upper;
|
|
356
|
+
}).join("");
|
|
357
|
+
}
|
|
358
|
+
/** Whether `existingPath` names the same file with the case of its letters swapped. */
|
|
359
|
+
async function volumeIgnoresCase(existingPath) {
|
|
360
|
+
const swapped = withCaseSwapped(existingPath);
|
|
361
|
+
if (swapped === existingPath) return false;
|
|
362
|
+
try {
|
|
363
|
+
const [original, variant] = await Promise.all([stat(existingPath), stat(swapped)]);
|
|
364
|
+
return original.dev === variant.dev && original.ino === variant.ino;
|
|
365
|
+
} catch {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* A key that is the same for two paths naming the same file. Symbolic links
|
|
371
|
+
* are resolved, in the path itself or in its nearest existing parent, and the
|
|
372
|
+
* key is lower case when that parent is on a volume that ignores case.
|
|
373
|
+
*/
|
|
374
|
+
async function filePathKey(path) {
|
|
375
|
+
const { existing, missing } = await existingPart(path);
|
|
376
|
+
const resolved = join(existing, ...missing);
|
|
377
|
+
return await volumeIgnoresCase(existing) ? resolved.toLowerCase() : resolved;
|
|
378
|
+
}
|
|
329
379
|
function inferPresentations(inputs) {
|
|
330
380
|
const { document, database } = inputs;
|
|
331
381
|
return {
|
|
@@ -395,7 +445,10 @@ function createContractInferCommand({ createControlClient, printPsl }) {
|
|
|
395
445
|
why: "The configured family does not implement the PslContractInferCapable capability, so an inferred PSL contract cannot be produced from the live database schema.",
|
|
396
446
|
fix: "Use a family that supports contract inference (e.g. SQL/Postgres)."
|
|
397
447
|
})));
|
|
398
|
-
pslContent = printPsl(pslContractAst, {
|
|
448
|
+
pslContent = printPsl(pslContractAst, {
|
|
449
|
+
pslBlockDescriptors: client.getPslBlockDescriptors(),
|
|
450
|
+
description: "Contract inferred from the live database schema. Edit as needed, then run `prisma contract emit`."
|
|
451
|
+
});
|
|
399
452
|
} catch (error) {
|
|
400
453
|
if (CliStructuredError$1$1.is(error)) return notOk$1(normalizeError(error));
|
|
401
454
|
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
@@ -442,41 +495,51 @@ const contractInferCommand = createContractInferCommand({
|
|
|
442
495
|
createControlClient,
|
|
443
496
|
printPsl
|
|
444
497
|
});
|
|
445
|
-
|
|
446
|
-
const parts = [];
|
|
447
|
-
if (failure.marker?.storageHash !== failure.destination?.storageHash && failure.marker?.storageHash && failure.destination?.storageHash) parts.push(`storageHash (marker: ${failure.marker.storageHash}, destination: ${failure.destination.storageHash})`);
|
|
448
|
-
if (failure.marker?.profileHash !== failure.destination?.profileHash && failure.marker?.profileHash && failure.destination?.profileHash) parts.push(`profileHash (marker: ${failure.marker.profileHash}, destination: ${failure.destination.profileHash})`);
|
|
449
|
-
return parts.length > 0 ? ` Mismatch in ${parts.join(" and ")}.` : "";
|
|
450
|
-
}
|
|
498
|
+
const defaultContractPrintDependencies = { printPsl };
|
|
451
499
|
/**
|
|
452
|
-
*
|
|
500
|
+
* Loads the configured contract, validates it as `contract emit` does, and prints it as Prisma 8
|
|
501
|
+
* PSL. One control stack serves the whole operation: the source is loaded against it, the family
|
|
502
|
+
* instance is created from it, and its block descriptors and codec lookup render the text.
|
|
453
503
|
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
504
|
+
* @throws {CliStructuredError} `CONTRACT.SOURCE_LOAD_FAILED` when the source cannot produce a
|
|
505
|
+
* contract, and `CONTRACT.PRINT_UNSUPPORTED` when the family or target cannot print it
|
|
506
|
+
* @throws the family instance's error for a contract whose structure it rejects, as `contract emit`
|
|
507
|
+
* reports it
|
|
508
|
+
* @throws {DOMException} `AbortError` if cancelled via `signal`
|
|
509
|
+
*/
|
|
510
|
+
async function executeContractPrint(options, dependencies = defaultContractPrintDependencies) {
|
|
511
|
+
const { config, contractConfig, description, signal } = options;
|
|
512
|
+
const stack = createControlStack(config);
|
|
513
|
+
const sourceWarnings = [];
|
|
514
|
+
const loaded = await loadContractSourceWithStack({
|
|
515
|
+
stack,
|
|
516
|
+
source: contractConfig.source,
|
|
517
|
+
...ifDefined("signal", signal),
|
|
518
|
+
reportWarning: (diagnostic) => {
|
|
519
|
+
sourceWarnings.push(diagnostic);
|
|
467
520
|
}
|
|
468
521
|
});
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
522
|
+
if (!loaded.ok) throw loaded.failure.error;
|
|
523
|
+
const familyInstance = config.family.create(stack);
|
|
524
|
+
const contract = validateLoadedContract({
|
|
525
|
+
config,
|
|
526
|
+
familyInstance,
|
|
527
|
+
contract: loaded.value
|
|
528
|
+
});
|
|
529
|
+
if (!hasPslContractBuild(familyInstance)) throw errorRuntime("CONTRACT.PRINT_UNSUPPORTED", "contract print is not supported for this family", {
|
|
530
|
+
why: "The configured family cannot print a contract as PSL, so nothing was written.",
|
|
531
|
+
fix: "Use a family and target that can print a contract as PSL."
|
|
532
|
+
});
|
|
533
|
+
const { document, sourceSettings } = familyInstance.buildPslContract(contract);
|
|
534
|
+
return {
|
|
535
|
+
psl: dependencies.printPsl(document, {
|
|
536
|
+
pslBlockDescriptors: stack.authoringContributions.pslBlockDescriptors,
|
|
537
|
+
codecLookup: stack.codecLookup,
|
|
538
|
+
description
|
|
539
|
+
}),
|
|
540
|
+
sourceSettings,
|
|
541
|
+
sourceWarnings
|
|
542
|
+
};
|
|
480
543
|
}
|
|
481
544
|
/**
|
|
482
545
|
* The directory of the config file that wrote the section, recorded when the
|
|
@@ -513,6 +576,265 @@ function contractPathFor(config) {
|
|
|
513
576
|
function displayPath(path, cwd) {
|
|
514
577
|
return relative(cwd, path);
|
|
515
578
|
}
|
|
579
|
+
function sourceSettingsClause(policy) {
|
|
580
|
+
return policy === void 0 ? "" : `, through a PSL source that sets defaultControlPolicy: '${policy}'`;
|
|
581
|
+
}
|
|
582
|
+
function switchToPrintedActions(document, configSwitch) {
|
|
583
|
+
const policyClause = sourceSettingsClause(document.sourceSettings.defaultControlPolicy);
|
|
584
|
+
const emit = runCommandAction("Emit the printed contract", "{bin} contract emit");
|
|
585
|
+
if (configSwitch === void 0) return [chooseAction(`Write the PSL to a file with --output <path>, then point contract in prisma.config.ts at that file${policyClause}`), emit];
|
|
586
|
+
const { contractPath: path, emittedFilesMove } = configSwitch;
|
|
587
|
+
return [
|
|
588
|
+
chooseAction(`Point contract in prisma.config.ts at ${path}${policyClause}`),
|
|
589
|
+
...emittedFilesMove === void 0 ? [] : [chooseAction(`With contract: './${path}' and no output in prisma.config.ts, contract emit writes ${emittedFilesMove.after.json} and ${emittedFilesMove.after.dts}, not ${emittedFilesMove.before.json} and ${emittedFilesMove.before.dts}`)],
|
|
590
|
+
emit
|
|
591
|
+
];
|
|
592
|
+
}
|
|
593
|
+
function defaultControlPolicyWarning(policy) {
|
|
594
|
+
return `The contract's default control policy is '${policy}', and a PSL file cannot carry it. Set defaultControlPolicy: '${policy}' on the PSL source in prisma.config.ts. Without it, the emitted contract has no default control policy, and everything that sets no control policy of its own is treated as managed.`;
|
|
595
|
+
}
|
|
596
|
+
/** The lines of `text`, without the empty line after its final newline. */
|
|
597
|
+
function linesOf(text) {
|
|
598
|
+
return text.replace(/\n$/, "").split("\n");
|
|
599
|
+
}
|
|
600
|
+
function printPresentations(document, configSwitch) {
|
|
601
|
+
return {
|
|
602
|
+
stdout: () => "text" in document.psl ? linesOf(document.psl.text) : [],
|
|
603
|
+
next: () => switchToPrintedActions(document, configSwitch),
|
|
604
|
+
human: () => "path" in document.psl ? [{
|
|
605
|
+
kind: "summary",
|
|
606
|
+
status: "ok",
|
|
607
|
+
text: [{ text: "Contract written to " }, {
|
|
608
|
+
text: document.psl.path,
|
|
609
|
+
tone: "identifier"
|
|
610
|
+
}]
|
|
611
|
+
}] : [{
|
|
612
|
+
kind: "summary",
|
|
613
|
+
status: "ok",
|
|
614
|
+
text: [{ text: "Contract printed as Prisma 8 PSL" }]
|
|
615
|
+
}, {
|
|
616
|
+
kind: "drawing",
|
|
617
|
+
lines: linesOf(document.psl.text)
|
|
618
|
+
}],
|
|
619
|
+
json: () => document
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function printDescription(sourcePaths) {
|
|
623
|
+
return `Printed${sourcePaths.length === 0 ? "" : ` from ${sourcePaths.join(", ")}`} by \`prisma contract print\`.`;
|
|
624
|
+
}
|
|
625
|
+
async function isSameFile(outputKey, path) {
|
|
626
|
+
return outputKey === await filePathKey(path);
|
|
627
|
+
}
|
|
628
|
+
async function isSameFileOrInside(outputKey, path) {
|
|
629
|
+
const key = await filePathKey(path);
|
|
630
|
+
return outputKey === key || outputKey.startsWith(`${key.replace(/\/$/, "")}/`);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The refusal for an output path that would write over a file the project
|
|
634
|
+
* needs: a contract source input, or a file inside a directory of inputs; the
|
|
635
|
+
* config file; or a file `contract emit` writes. `undefined` when the path
|
|
636
|
+
* touches none of them.
|
|
637
|
+
*/
|
|
638
|
+
async function outputPathRefusal(inputs) {
|
|
639
|
+
const { cwd } = inputs;
|
|
640
|
+
const output = relative(cwd, inputs.outputPath);
|
|
641
|
+
const outputKey = await filePathKey(inputs.outputPath);
|
|
642
|
+
for (const input of await expandContractInputs(inputs.sourceInputs)) if (await isSameFileOrInside(outputKey, resolve(cwd, input))) {
|
|
643
|
+
const source = relative(cwd, resolve(cwd, input));
|
|
644
|
+
return errorRuntime("CONTRACT.PRINT_OUTPUT_IS_SOURCE", "contract print would write over its own contract source", {
|
|
645
|
+
why: `The output path ${output} is the contract source ${source}, or sits inside it, so printing would destroy the source it reads.`,
|
|
646
|
+
fix: "Pick another --output path, outside the source files the config names.",
|
|
647
|
+
meta: {
|
|
648
|
+
output,
|
|
649
|
+
source
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
const matchingGlob = globContractInputMatching(inputs.sourceInputs, inputs.outputPath) ?? globContractInputMatching(inputs.sourceInputs, outputKey);
|
|
654
|
+
if (matchingGlob !== void 0) {
|
|
655
|
+
const source = relative(cwd, matchingGlob);
|
|
656
|
+
return errorRuntime("CONTRACT.PRINT_OUTPUT_IS_SOURCE", "contract print would write a file its own contract source reads", {
|
|
657
|
+
why: `The contract source reads every file that matches ${source}. Once written, ${output} would match, so contract emit would read the printed file together with the source files.`,
|
|
658
|
+
fix: "Pick another --output path, one the source inputs in the config do not match.",
|
|
659
|
+
meta: {
|
|
660
|
+
output,
|
|
661
|
+
source
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
const { configPath } = inputs;
|
|
666
|
+
if (await isSameFile(outputKey, configPath)) {
|
|
667
|
+
const file = relative(cwd, configPath);
|
|
668
|
+
return errorRuntime("CONTRACT.PRINT_OUTPUT_IS_PROJECT_FILE", "contract print would write over the config file", {
|
|
669
|
+
why: `The output path ${output} is ${file}, the file the CLI reads its config from unless --config names another.`,
|
|
670
|
+
fix: "Pick another --output path.",
|
|
671
|
+
meta: {
|
|
672
|
+
output,
|
|
673
|
+
file
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (inputs.emittedJsonPath === void 0) return;
|
|
678
|
+
const emitted = getEmittedArtifactPaths(inputs.emittedJsonPath);
|
|
679
|
+
for (const emittedPath of [emitted.jsonPath, emitted.dtsPath]) if (await isSameFile(outputKey, emittedPath)) {
|
|
680
|
+
const file = relative(cwd, emittedPath);
|
|
681
|
+
return errorRuntime("CONTRACT.PRINT_OUTPUT_IS_PROJECT_FILE", "contract print would write over an emitted contract file", {
|
|
682
|
+
why: `The output path ${output} is ${file}, a file contract emit writes, so the next contract emit would write over the printed PSL.`,
|
|
683
|
+
fix: "Pick another --output path.",
|
|
684
|
+
meta: {
|
|
685
|
+
output,
|
|
686
|
+
file
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function emittedFilesMoveFor(inputs) {
|
|
692
|
+
if (inputs.emittedJsonPath === void 0) return;
|
|
693
|
+
const before = getEmittedArtifactPaths(inputs.emittedJsonPath);
|
|
694
|
+
const after = getEmittedArtifactPaths(defaultContractOutputPath(inputs.outputPath));
|
|
695
|
+
if (after.jsonPath === before.jsonPath) return;
|
|
696
|
+
return {
|
|
697
|
+
before: {
|
|
698
|
+
json: relative(inputs.configDir, before.jsonPath),
|
|
699
|
+
dts: relative(inputs.configDir, before.dtsPath)
|
|
700
|
+
},
|
|
701
|
+
after: {
|
|
702
|
+
json: relative(inputs.configDir, after.jsonPath),
|
|
703
|
+
dts: relative(inputs.configDir, after.dtsPath)
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function createContractPrintCommand({ printPsl }) {
|
|
708
|
+
return defineOrmCommand({
|
|
709
|
+
help: {
|
|
710
|
+
summary: "Print the configured contract as Prisma 8 PSL",
|
|
711
|
+
description: "Loads the contract from contract.source in your config, whatever kind\nof source that is, and prints it as Prisma 8 PSL, or writes it to the\nfile --output names. Emitting that PSL produces the same contract: same\nhashes, same domain. If the contract holds something PSL cannot\nexpress, the command refuses, names it, and prints nothing. A pipe\nreceives the JSON result unless you pass --format human. The command\ndoes not change your config: point it at the written file, then run\n`contract emit`. An existing file at the --output path is overwritten,\nwith a warning.",
|
|
712
|
+
examples: [
|
|
713
|
+
"contract print",
|
|
714
|
+
"contract print --format human > printed.prisma",
|
|
715
|
+
"contract print --output ./src/prisma/contract.prisma",
|
|
716
|
+
"contract print --json"
|
|
717
|
+
]
|
|
718
|
+
},
|
|
719
|
+
args: { flags: { output: flag.string({
|
|
720
|
+
brief: "Write the PSL to this file instead of standard output",
|
|
721
|
+
placeholder: "path"
|
|
722
|
+
}) } },
|
|
723
|
+
needs: { config: ormConfigSection },
|
|
724
|
+
handler: async (args, ctx) => {
|
|
725
|
+
const startedAt = Date.now();
|
|
726
|
+
const contractConfig = ctx.config.contract;
|
|
727
|
+
if (contractConfig?.source === void 0) return notOk$1(normalizeError(errorContractConfigMissing({ why: "Config.contract.source is required for contract print. Define contract in your config so the command has a source to print." })));
|
|
728
|
+
const sourceInputs = contractConfig.source.inputs ?? [];
|
|
729
|
+
const sourcePaths = sourceInputs.map((input) => relative(ctx.cwd, input));
|
|
730
|
+
const emittedJsonPath = contractConfig.output === void 0 ? void 0 : resolve(ctx.cwd, contractConfig.output);
|
|
731
|
+
const configDir = baseDirFor(ctx.config);
|
|
732
|
+
const outputPath = args.flags.output === void 0 ? void 0 : resolve(ctx.cwd, args.flags.output);
|
|
733
|
+
if (outputPath !== void 0) {
|
|
734
|
+
const refusal = await outputPathRefusal({
|
|
735
|
+
cwd: ctx.cwd,
|
|
736
|
+
outputPath,
|
|
737
|
+
sourceInputs,
|
|
738
|
+
configPath: resolve(configDir, "prisma.config.ts"),
|
|
739
|
+
emittedJsonPath
|
|
740
|
+
});
|
|
741
|
+
if (refusal !== void 0) return notOk$1(normalizeError(refusal));
|
|
742
|
+
}
|
|
743
|
+
let printed;
|
|
744
|
+
try {
|
|
745
|
+
printed = await executeContractPrint({
|
|
746
|
+
config: ctx.config,
|
|
747
|
+
contractConfig,
|
|
748
|
+
description: printDescription(sourcePaths),
|
|
749
|
+
signal: ctx.signal
|
|
750
|
+
}, { printPsl });
|
|
751
|
+
} catch (error) {
|
|
752
|
+
return notOk$1(normalizeError(error));
|
|
753
|
+
}
|
|
754
|
+
ctx.signal.throwIfAborted();
|
|
755
|
+
for (const warning of printed.sourceWarnings) ctx.report({
|
|
756
|
+
kind: "message",
|
|
757
|
+
severity: "warn",
|
|
758
|
+
text: `warning ${formatSourceDiagnostic(warning)}`
|
|
759
|
+
});
|
|
760
|
+
if (outputPath !== void 0) {
|
|
761
|
+
if (existsSync(outputPath)) ctx.report({
|
|
762
|
+
kind: "message",
|
|
763
|
+
severity: "warn",
|
|
764
|
+
text: `Overwriting existing file: ${relative(ctx.cwd, outputPath)}`
|
|
765
|
+
});
|
|
766
|
+
await publishTextArtifact({
|
|
767
|
+
path: outputPath,
|
|
768
|
+
content: printed.psl,
|
|
769
|
+
publicationToken: String(process.hrtime.bigint())
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
const { defaultControlPolicy } = printed.sourceSettings;
|
|
773
|
+
if (defaultControlPolicy !== void 0) ctx.report({
|
|
774
|
+
kind: "message",
|
|
775
|
+
severity: "warn",
|
|
776
|
+
text: defaultControlPolicyWarning(defaultControlPolicy)
|
|
777
|
+
});
|
|
778
|
+
const document = {
|
|
779
|
+
ok: true,
|
|
780
|
+
summary: "Contract printed successfully",
|
|
781
|
+
target: {
|
|
782
|
+
familyId: ctx.config.family.familyId,
|
|
783
|
+
id: ctx.config.target.targetId
|
|
784
|
+
},
|
|
785
|
+
psl: outputPath === void 0 ? { text: printed.psl } : { path: relative(ctx.cwd, outputPath) },
|
|
786
|
+
source: sourcePaths,
|
|
787
|
+
sourceSettings: printed.sourceSettings,
|
|
788
|
+
timings: { total: Date.now() - startedAt }
|
|
789
|
+
};
|
|
790
|
+
return ok$1(ctx.present({ data: document }, printPresentations(document, outputPath === void 0 ? void 0 : {
|
|
791
|
+
contractPath: relative(configDir, outputPath),
|
|
792
|
+
emittedFilesMove: emittedFilesMoveFor({
|
|
793
|
+
configDir,
|
|
794
|
+
outputPath,
|
|
795
|
+
emittedJsonPath
|
|
796
|
+
})
|
|
797
|
+
})));
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
const contractPrintCommand = createContractPrintCommand({ printPsl });
|
|
802
|
+
function markerMismatchDetail(failure) {
|
|
803
|
+
const parts = [];
|
|
804
|
+
if (failure.marker?.storageHash !== failure.destination?.storageHash && failure.marker?.storageHash && failure.destination?.storageHash) parts.push(`storageHash (marker: ${failure.marker.storageHash}, destination: ${failure.destination.storageHash})`);
|
|
805
|
+
if (failure.marker?.profileHash !== failure.destination?.profileHash && failure.marker?.profileHash && failure.destination?.profileHash) parts.push(`profileHash (marker: ${failure.marker.profileHash}, destination: ${failure.destination.profileHash})`);
|
|
806
|
+
return parts.length > 0 ? ` Mismatch in ${parts.join(" and ")}.` : "";
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* A `db init` failure as the CLI's structured error.
|
|
810
|
+
*
|
|
811
|
+
* The `assertNever` is deliberate: a control-API failure code this does not
|
|
812
|
+
* handle must stop the command rather than degrade into a generic message.
|
|
813
|
+
*/
|
|
814
|
+
function mapDbInitFailure(failure) {
|
|
815
|
+
if (failure.code === "PLANNING_FAILED") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });
|
|
816
|
+
if (failure.code === "MIGRATION.MARKER_ORIGIN_MISMATCH") return errorRuntime("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing database signature does not match plan destination.${markerMismatchDetail(failure)}`, {
|
|
817
|
+
why: "Database has an existing signature (marker) that does not match the target contract",
|
|
818
|
+
fix: "If bootstrapping, drop/reset the database then re-run `{bin} db init`; otherwise reconcile schema/marker using your migration workflow",
|
|
819
|
+
meta: {
|
|
820
|
+
...ifDefined("markerStorageHash", failure.marker?.storageHash),
|
|
821
|
+
...ifDefined("destinationStorageHash", failure.destination?.storageHash),
|
|
822
|
+
...ifDefined("markerProfileHash", failure.marker?.profileHash),
|
|
823
|
+
...ifDefined("destinationProfileHash", failure.destination?.profileHash)
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
if (failure.code === "RUNNER_FAILED") {
|
|
827
|
+
const fix = (typeof failure.meta?.["runnerErrorCode"] === "string" ? failure.meta["runnerErrorCode"] : void 0) === "MIGRATION.LEGACY_MARKER_SHAPE" ? "Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `{bin} db init` to recreate it with the current per-space schema." : "Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run `{bin} db init`";
|
|
828
|
+
return errorRunnerFailed(failure.summary, {
|
|
829
|
+
why: failure.why ?? "Migration runner failed",
|
|
830
|
+
fix,
|
|
831
|
+
...ifDefined("meta", failure.meta),
|
|
832
|
+
...ifDefined("cause", failure.cause)
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
const exhaustive = failure.code;
|
|
836
|
+
return assertNever(exhaustive, `Unhandled DbInitFailure code: ${String(exhaustive)}`);
|
|
837
|
+
}
|
|
516
838
|
/**
|
|
517
839
|
* Render a single statement of an `OperationPreview` for the human-readable
|
|
518
840
|
* preview block. SQL statements get a trailing `;` if missing so the rendered
|
|
@@ -2468,6 +2790,11 @@ async function formatOneFile(inputPath, formatOptions) {
|
|
|
2468
2790
|
}
|
|
2469
2791
|
return ok(inputPath);
|
|
2470
2792
|
}
|
|
2793
|
+
/** The input itself, or every `.prisma` file under it when the input is a directory. */
|
|
2794
|
+
async function pslFilesOf(inputPath) {
|
|
2795
|
+
if (!await stat(inputPath).then((stats) => stats.isDirectory(), () => false)) return [inputPath];
|
|
2796
|
+
return (await readdir(inputPath, { recursive: true })).filter((entry) => entry.endsWith(".prisma")).sort().map((entry) => join(inputPath, entry));
|
|
2797
|
+
}
|
|
2471
2798
|
async function executeFormat(options) {
|
|
2472
2799
|
const eol = options.eol ?? EOL;
|
|
2473
2800
|
const config = options.config;
|
|
@@ -2487,7 +2814,8 @@ async function executeFormat(options) {
|
|
|
2487
2814
|
};
|
|
2488
2815
|
const paths = [];
|
|
2489
2816
|
const failures = [];
|
|
2490
|
-
|
|
2817
|
+
const files = (await Promise.all(resolvedInputs.map(pslFilesOf))).flat();
|
|
2818
|
+
for (const inputPath of files) {
|
|
2491
2819
|
const outcome = await formatOneFile(inputPath, formatOptions);
|
|
2492
2820
|
if (outcome.ok) paths.push(outcome.value);
|
|
2493
2821
|
else failures.push(outcome.failure);
|
|
@@ -6203,7 +6531,7 @@ const lspCommand = defineServerCommand({
|
|
|
6203
6531
|
} },
|
|
6204
6532
|
handler: async (args, io) => {
|
|
6205
6533
|
const exitCode = await withoutClientProcessIdInArgv(async () => {
|
|
6206
|
-
const { startServer } = await import("./exports-
|
|
6534
|
+
const { startServer } = await import("./exports-BB9aU4zk.mjs");
|
|
6207
6535
|
return startServer({
|
|
6208
6536
|
stdin: io.stdin,
|
|
6209
6537
|
stdout: io.stdout,
|
|
@@ -10671,6 +10999,7 @@ const DOCS_BASE_URL = `${DOCS_BASE}/`;
|
|
|
10671
10999
|
const ormCommandFamily = defineCommandFamily({
|
|
10672
11000
|
configSection: ormConfigSection,
|
|
10673
11001
|
commands: {
|
|
11002
|
+
"contract print": contractPrintCommand,
|
|
10674
11003
|
"contract emit": contractEmitCommand,
|
|
10675
11004
|
"contract format": formatCommand,
|
|
10676
11005
|
"contract infer": contractInferCommand,
|