@prisma/orm-toolchain 8.0.0-rc.24-dev.28 → 8.0.0-rc.24-dev.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/{aggregate-CRIdmKmq.mjs → aggregate-7sB4u_aJ.mjs} +11 -5
- package/dist/aggregate-7sB4u_aJ.mjs.map +1 -0
- package/dist/{aggregate-C6PGBKyb.d.mts → aggregate-DgWdbWNs.d.mts} +12 -6
- package/dist/{aggregate-C6PGBKyb.d.mts.map → aggregate-DgWdbWNs.d.mts.map} +1 -1
- package/dist/{caught-errors-I1l50iPc-D_-F2M3t.mjs → caught-errors-D_pbHqmS-B-4jRN6g.mjs} +52 -11
- package/dist/caught-errors-D_pbHqmS-B-4jRN6g.mjs.map +1 -0
- package/dist/cli-telemetry.mjs +1 -1
- package/dist/cli.d.mts +2 -2
- package/dist/cli.mjs +1094 -1012
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +16 -14
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +2 -2
- package/dist/cli__control-api__testing.d.mts +1 -1
- package/dist/cli__init-contribution.d.mts +101 -0
- package/dist/cli__init-contribution.d.mts.map +1 -0
- package/dist/cli__init-contribution.mjs +1 -0
- package/dist/cli__init-output.d.mts +3 -3
- package/dist/cli__init-output.mjs +1 -1
- package/dist/cli__migration-cli.mjs +3 -3
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.d.mts +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{db-sign-Bv-FZMAD-uQhMNCC7.d.mts → db-sign-DLIR5swa-DQ0aN1nU.d.mts} +25 -21
- package/dist/db-sign-DLIR5swa-DQ0aN1nU.d.mts.map +1 -0
- package/dist/{domain-type-generation-BlYB8GiS-k0HNTf4f.mjs → domain-type-generation-BGcbGgHJ-Cdw5RNaZ.mjs} +11 -12
- package/dist/domain-type-generation-BGcbGgHJ-Cdw5RNaZ.mjs.map +1 -0
- package/dist/{domain-type-generation-D5cG6TGd-DKLpO6ZA.d.mts → domain-type-generation-BP8J5hy8-CxSjSRCh.d.mts} +6 -5
- package/dist/domain-type-generation-BP8J5hy8-CxSjSRCh.d.mts.map +1 -0
- package/dist/emitter.d.mts +3 -3
- package/dist/emitter.mjs +3 -3
- package/dist/emitter__domain-type-generation.d.mts +2 -2
- package/dist/emitter__domain-type-generation.mjs +2 -2
- package/dist/{exports-RTLU0w9r.mjs → exports-BiXPktAF.mjs} +4 -4
- package/dist/{exports-RTLU0w9r.mjs.map → exports-BiXPktAF.mjs.map} +1 -1
- package/dist/{exports-CVgs3YWV-BF4rqnxF.mjs → exports-CCuYD8dO-yw1GizAT.mjs} +28 -18
- package/dist/exports-CCuYD8dO-yw1GizAT.mjs.map +1 -0
- package/dist/{exports-CSVHjfwG.mjs → exports-CZ6dPu-O.mjs} +35 -10
- package/dist/exports-CZ6dPu-O.mjs.map +1 -0
- package/dist/{index-BHYAWGxJ.d.mts → index-C09OeJjf.d.mts} +7 -12
- package/dist/index-C09OeJjf.d.mts.map +1 -0
- package/dist/{index-BhNbc269.d.mts → index-C3KtOcBP.d.mts} +3 -1
- package/dist/index-C3KtOcBP.d.mts.map +1 -0
- package/dist/migration-tools.d.mts +1 -1
- package/dist/migration-tools.mjs +3 -3
- package/dist/migration-tools__aggregate.d.mts +1 -1
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/{output-BcC8eB0h-C5bRd-aC.mjs → output-E6F4-EMc-CqlzGlv-.mjs} +50 -9
- package/dist/output-E6F4-EMc-CqlzGlv-.mjs.map +1 -0
- package/dist/{ref-DfuqRCA7-CPPoVHY9.mjs → ref-PQOM_LTC-lyfzb0MO.mjs} +535 -270
- package/dist/ref-PQOM_LTC-lyfzb0MO.mjs.map +1 -0
- package/dist/{ref-resolution-C9j2SSb6.mjs → ref-resolution-C0xsiRig.mjs} +2 -2
- package/dist/{ref-resolution-C9j2SSb6.mjs.map → ref-resolution-C0xsiRig.mjs.map} +1 -1
- package/dist/{refs-t_JbIjGo-CRpBRRkq.mjs → refs-t_JbIjGo-BVCqKpXd.mjs} +2 -2
- package/dist/{refs-t_JbIjGo-CRpBRRkq.mjs.map → refs-t_JbIjGo-BVCqKpXd.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +4 -5
- package/dist/vite-plugin-contract-emit.mjs.map +1 -1
- package/package.json +12 -15
- package/dist/aggregate-CRIdmKmq.mjs.map +0 -1
- package/dist/caught-errors-I1l50iPc-D_-F2M3t.mjs.map +0 -1
- package/dist/db-sign-Bv-FZMAD-uQhMNCC7.d.mts.map +0 -1
- package/dist/domain-type-generation-BlYB8GiS-k0HNTf4f.mjs.map +0 -1
- package/dist/domain-type-generation-D5cG6TGd-DKLpO6ZA.d.mts.map +0 -1
- package/dist/exports-CSVHjfwG.mjs.map +0 -1
- package/dist/exports-CVgs3YWV-BF4rqnxF.mjs.map +0 -1
- package/dist/import-roots-DlSoi7oS.d.mts +0 -119
- package/dist/import-roots-DlSoi7oS.d.mts.map +0 -1
- package/dist/import-roots-Dqs1_cn4.mjs +0 -224
- package/dist/import-roots-Dqs1_cn4.mjs.map +0 -1
- package/dist/index-BHYAWGxJ.d.mts.map +0 -1
- package/dist/index-BhNbc269.d.mts.map +0 -1
- package/dist/output-BcC8eB0h-C5bRd-aC.mjs.map +0 -1
- package/dist/publish-surface.d.mts +0 -3
- package/dist/publish-surface.mjs +0 -3
- package/dist/publish-surface__import-roots.d.mts +0 -2
- package/dist/publish-surface__import-roots.mjs +0 -2
- package/dist/publish-surface__shells.d.mts +0 -2
- package/dist/publish-surface__shells.mjs +0 -2
- package/dist/quick-reference-mongo.md +0 -116
- package/dist/quick-reference-postgres.md +0 -95
- package/dist/quick-reference-prisma7.md +0 -80
- package/dist/readme-mongo.md +0 -35
- package/dist/readme-postgres.md +0 -34
- package/dist/ref-DfuqRCA7-CPPoVHY9.mjs.map +0 -1
- package/dist/shells-BA7YJyPT.mjs +0 -777
- package/dist/shells-BA7YJyPT.mjs.map +0 -1
- package/dist/shells-D7NNxMLT.d.mts +0 -129
- package/dist/shells-D7NNxMLT.d.mts.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { a as expandContractInputs, c as globContractInputMatching, d as loadConfigFiles, g as requireConfigSections, h as ormConfigSection, i as evaluateConfigModule, r as buildLoadedConfig } from "./exports-
|
|
1
|
+
import { a as expandContractInputs, c as globContractInputMatching, d as loadConfigFiles, g as requireConfigSections, h as ormConfigSection, i as evaluateConfigModule, r as buildLoadedConfig } from "./exports-CZ6dPu-O.mjs";
|
|
2
2
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
3
3
|
import { t as MigrationToolsError } from "./errors-BMq40nYH-Cg8PBect.mjs";
|
|
4
4
|
import { t as contractSnapshotDir } from "./contract-snapshot-store-B0fRbVHB-BN2g8BKh.mjs";
|
|
5
5
|
import { s as readMigrationsDir } from "./io-B39zsxMm-D5Wcf6cf.mjs";
|
|
6
6
|
import { l as spaceMigrationDirectory, u as spaceRefsDirectory } from "./verify-contract-spaces-BOnqhfQs-BBq5YOKo.mjs";
|
|
7
|
-
import { A as
|
|
8
|
-
import { r as getEmittedArtifactPaths } from "./exports-
|
|
7
|
+
import { A as errorFileNotFound, C as errorContractArgConflict, Ct as statementFlag, D as errorConvertAndDelete, E as errorContractValidationFailed, F as errorMarkerMissing, J as errorSignRefsNotWritten, L as errorMigrationPackageNotFound, M as errorHashMismatch, O as errorDatabaseConnectionRequired, P as errorLegendHumanOnly, S as errorConsentUnused, St as shellQuoted, _ as displayPath, _t as rerunFlags, a as appRefsDirFor, bt as runCommandAction, c as cliCommand, ct as maskConnectionUrl, d as closeQuietly, et as errorStatementNeedsMigrationFile, g as dbUpdateRerun, gt as requireLiveDatabase, ht as redactUrlCredentials, i as appMigrationsDirFor, it as errorTargetMismatch, j as errorFromCaught, k as errorDriverRequired, mt as readContractEnvelope, n as CliStructuredError$1$1, o as baseDirFor, p as contractPathFor, pt as printedPlanCommand, q as errorRuntime, rt as errorTargetMigrationNotSupported, s as chooseAction, u as cliInvocation, ut as migrationsDirFor, w as errorContractConfigMissing, wt as targetSupportsMigrations, x as errorConfigValidation$1, xt as selfEmitCommand, y as errorAdvanceRefArgConflict, z as errorNoMigrations } from "./caught-errors-D_pbHqmS-B-4jRN6g.mjs";
|
|
8
|
+
import { r as getEmittedArtifactPaths } from "./exports-CCuYD8dO-yw1GizAT.mjs";
|
|
9
9
|
import { r as isInSpaceHistory } from "./graph-membership-D7m41lWA-B68g1CRS.mjs";
|
|
10
|
-
import { i as readRef, n as advanceRef } from "./refs-t_JbIjGo-
|
|
11
|
-
import { a as contractHashAtMarker } from "./aggregate-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
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
|
+
import { i as readRef, n as advanceRef } from "./refs-t_JbIjGo-BVCqKpXd.mjs";
|
|
11
|
+
import { a as contractHashAtMarker } from "./aggregate-7sB4u_aJ.mjs";
|
|
12
|
+
import { o as isLiveMarkerRef } from "./ref-resolution-C0xsiRig.mjs";
|
|
13
|
+
import { $ as planEverySpace, A as executeMigrationNewCommand, B as labelsText, C as errorPermitPolicyChangeNeedsRef, Ct as statusForMigrationHash, Et as withWarningFindings, F as executeRefSetCommand, G as loadContractSource, H as liveMarkerUse, I as findPackageByDirPath, J as looksLikePath, K as loadContractSourceWithStack, L as formatSourceDiagnostic, N as executeRefDeleteCommand, P as executeRefListCommand, Q as migrationSpaceListEntriesFromAggregate, R as hasMigrationPath, S as enumerateCheckSpaces, St as sourceWarningDiagnostic, Tt as validateLoadedContract, U as loadAggregateIntegrityViolations, V as listRefsByContractHash, W as loadContractRawSafely, Y as mapContractAtError, Z as matchConsents, _ as databasePoliciesInForce, a as advanceRefSafely, at as refusePackageCorruptionOnAggregate, bt as skippedOperationsText, ct as requireDatabaseForLiveMarkerUse, d as buildRefAdvancementFields, dt as resolveContractRefToSnapshot, et as preflightRefAdvancement, f as checkSingleTarget, g as createControlClient, gt as retryCommandFor, h as convertAndDelete, i as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, it as refuseMissingInvariantPath, j as executeMigrationPlanCommand, k as executeMigrateShowPlan, l as buildMigrationSpaceGraphEntries, lt as resolveAppTargetPath, m as contractValidationMeta, n as NO_REF_ADVANCEMENT, nt as refuseContractSpaceIntegrity, ot as refuseUnknownInvariants, p as computeRefAdvancementName, pt as resolveMigrationRef, q as loadContractSpaceAggregateForCli, r as RECORDED_CONTRACT_REF_FORMS, s as appliedHashesFromLedger, st as renamedAndDeleted, t as ALL_CONTRACT_REF_FORMS, tt as readMigrationRefs, u as buildReadAggregate, ut as resolveContractRef$1, v as declaredSettingsText, vt as runMigrationCheck, w as executeContractEmit, wt as toDeclaredExtensionsFromRaw, xt as snapshotVerifierFor, y as deriveStatusEdgeAnnotations, yt as runMigrationList, z as isStatementVerb } from "./ref-PQOM_LTC-lyfzb0MO.mjs";
|
|
14
|
+
import { a as PRISMA7_LOOP_STEP, c as buildNextSteps, d as findTargetByProvider, i as NEXT_STEPS_BEFORE_SCAFFOLD, l as findPrisma6OnlyTarget, n as InitOutputSchema, o as PRISMA7_QUICK_REFERENCE_STEP, r as KNOWN_TARGET_PACKAGES, s as TARGET_SHORT_NAMES, t as DB_SIGN_STEP, u as findTargetByName } from "./output-E6F4-EMc-CqlzGlv-.mjs";
|
|
16
15
|
import { a as resolveGating, i as readUserConfig, r as ensureInstallationId, s as runTelemetry, u as userConfigPath } from "./exports-DwuO4y2c.mjs";
|
|
17
16
|
import { createRequire } from "node:module";
|
|
18
17
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
19
18
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
20
19
|
import { APP_SPACE_ID, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, createControlStack, databasePoliciesOf, databasePolicyDifferences, databasePolicyValueText, hasPslContractBuild, issueLabel, migrationSubjectJson, sameMarkerHashes, schemaIssuesWhy } from "@prisma/orm-framework/components/control";
|
|
21
20
|
import { InternalError, isInternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
21
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
22
22
|
import { DOCS_BASE, docsUrlFor, isStructuredError, isStructuredErrorCode } from "@prisma/orm-framework/utils/structured-error";
|
|
23
23
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
24
24
|
import { errorMarkerPoliciesCorrupt } from "@prisma/orm-framework/errors/execution";
|
|
@@ -26,8 +26,6 @@ import { mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from
|
|
|
26
26
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
27
27
|
import { type } from "arktype";
|
|
28
28
|
import { existsSync, fstatSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
29
|
-
import { keepInternalSpecifiers } from "@prisma/orm-framework/components/emission";
|
|
30
|
-
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
31
29
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
32
30
|
import { createCli, defineCommand, defineCommandFamily, defineServerCommand, flag, noDataLines, positional, telemetryCommandGroup } from "@prisma/cli-engine";
|
|
33
31
|
import process$1 from "node:process";
|
|
@@ -36,16 +34,15 @@ import { printPsl } from "@prisma/orm-framework/psl-printer";
|
|
|
36
34
|
import { DEFAULT_CONTRACT_SOURCE_DIR, defaultContractOutputPath } from "@prisma/orm-framework/config/config-types";
|
|
37
35
|
import { EOL, tmpdir } from "node:os";
|
|
38
36
|
import { format } from "@prisma/orm-framework/psl-parser/format";
|
|
39
|
-
import {
|
|
40
|
-
import { spawn } from "node:child_process";
|
|
37
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
41
38
|
import { detect } from "package-manager-detector/detect";
|
|
42
39
|
import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
43
40
|
import stringWidth from "string-width";
|
|
44
41
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
45
42
|
import { isCI } from "ci-info";
|
|
46
43
|
import { build } from "esbuild";
|
|
47
|
-
//#region ../../../1-framework/3-tooling/cli/dist/cli-
|
|
48
|
-
var version = "8.0.0-rc.24-dev.
|
|
44
|
+
//#region ../../../1-framework/3-tooling/cli/dist/cli-Cpe_rAAv.mjs
|
|
45
|
+
var version = "8.0.0-rc.24-dev.29";
|
|
49
46
|
const ESCAPES = {
|
|
50
47
|
"\\": "\\\\",
|
|
51
48
|
" ": "\\t",
|
|
@@ -1015,10 +1012,11 @@ function answerGroups(entries) {
|
|
|
1015
1012
|
* answered by `--delete` or `--rename`, and each that would change access, answered by `--allow`.
|
|
1016
1013
|
*/
|
|
1017
1014
|
function questionBlocks(result) {
|
|
1018
|
-
const
|
|
1015
|
+
const asks = (setting) => result.permitted?.includes(setting) !== true;
|
|
1016
|
+
const entries = [...(asks("dataLoss") ? result.dataLoss ?? [] : []).map((entry) => ({
|
|
1019
1017
|
entry,
|
|
1020
1018
|
verb: "delete"
|
|
1021
|
-
})), ...(result.accessChanges ?? []).map((entry) => ({
|
|
1019
|
+
})), ...(asks("accessWidening") ? result.accessChanges ?? [] : []).map((entry) => ({
|
|
1022
1020
|
entry,
|
|
1023
1021
|
verb: "allow"
|
|
1024
1022
|
}))];
|
|
@@ -1098,6 +1096,28 @@ function fallbackMarkerBlocks(result) {
|
|
|
1098
1096
|
}]]
|
|
1099
1097
|
}];
|
|
1100
1098
|
}
|
|
1099
|
+
const PERMITTED_STATEMENTS = {
|
|
1100
|
+
dataLoss: {
|
|
1101
|
+
verb: "delete",
|
|
1102
|
+
text: "permits losing data, so these deletes"
|
|
1103
|
+
},
|
|
1104
|
+
accessWidening: {
|
|
1105
|
+
verb: "allow",
|
|
1106
|
+
text: "permits changing who can read or write data, so these access changes"
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
/** Says which applied statements the database's data protection policy answered, without asking. */
|
|
1110
|
+
function permittedStatementBlocks(result) {
|
|
1111
|
+
const verbs = new Set((result.appliedStatements ?? []).map(({ verb }) => verb));
|
|
1112
|
+
return (result.permitted ?? []).flatMap((setting) => {
|
|
1113
|
+
const { verb, text } = PERMITTED_STATEMENTS[setting];
|
|
1114
|
+
return verbs.has(verb) ? [{
|
|
1115
|
+
kind: "summary",
|
|
1116
|
+
status: "info",
|
|
1117
|
+
text: `This database's data protection policy ${text} were applied without asking.`
|
|
1118
|
+
}] : [];
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1101
1121
|
function applyBlocks(result, invocation, databaseStorageHash) {
|
|
1102
1122
|
const advanced = result.advancedRef;
|
|
1103
1123
|
return [
|
|
@@ -1110,6 +1130,7 @@ function applyBlocks(result, invocation, databaseStorageHash) {
|
|
|
1110
1130
|
...operationBlocks$2(result),
|
|
1111
1131
|
...temporaryValueBlocks$1(result, invocation, databaseStorageHash),
|
|
1112
1132
|
...appliedStatementBlocks(result.appliedStatements ?? []),
|
|
1133
|
+
...permittedStatementBlocks(result),
|
|
1113
1134
|
...fallbackMarkerBlocks(result),
|
|
1114
1135
|
...advanced === null || advanced === void 0 ? [] : [{
|
|
1115
1136
|
kind: "summary",
|
|
@@ -1307,7 +1328,7 @@ function createDbInitCommand(createClient) {
|
|
|
1307
1328
|
name: refName,
|
|
1308
1329
|
contractJson,
|
|
1309
1330
|
contractJsonPath: contractPath,
|
|
1310
|
-
|
|
1331
|
+
config: ctx.config,
|
|
1311
1332
|
client
|
|
1312
1333
|
});
|
|
1313
1334
|
if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
|
|
@@ -1996,7 +2017,7 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1996
2017
|
name: refName,
|
|
1997
2018
|
contractJson: signedSource.json,
|
|
1998
2019
|
contractJsonPath: signedSource.jsonPath,
|
|
1999
|
-
|
|
2020
|
+
config: ctx.config,
|
|
2000
2021
|
client
|
|
2001
2022
|
});
|
|
2002
2023
|
if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
|
|
@@ -2249,9 +2270,28 @@ function ledByKeepDataWays(error, questions) {
|
|
|
2249
2270
|
*/
|
|
2250
2271
|
function promptPlanQuestions(prompt, statements) {
|
|
2251
2272
|
const answer = answering(prompt, statements);
|
|
2252
|
-
return (questions
|
|
2253
|
-
|
|
2254
|
-
|
|
2273
|
+
return async (questions, answeredWithoutAsking = []) => {
|
|
2274
|
+
takeConsentsAnsweredWithoutAsking(questions, answeredWithoutAsking, statements);
|
|
2275
|
+
return answer(questions).catch((error) => {
|
|
2276
|
+
throw ledByKeepDataWays(error, questions);
|
|
2277
|
+
});
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* Takes the `--delete` and `--allow` values of each verb no question asks about but the run
|
|
2282
|
+
* answered without asking, as a database whose data protection policy permits it does: a value
|
|
2283
|
+
* that names such a subject is used, and one that names nothing the run touched is unused.
|
|
2284
|
+
*/
|
|
2285
|
+
function takeConsentsAnsweredWithoutAsking(questions, answeredWithoutAsking, statements) {
|
|
2286
|
+
for (const verb of ["delete", "allow"]) {
|
|
2287
|
+
const answered = answeredWithoutAsking.filter((entry) => entry.verb === verb);
|
|
2288
|
+
if (answered.length === 0 || questions.some(({ verbs }) => verbs.includes(verb))) continue;
|
|
2289
|
+
const matched = matchConsents(verb, answered.map(({ subject, removedNamespace }) => ({
|
|
2290
|
+
text: subject,
|
|
2291
|
+
removedNamespace
|
|
2292
|
+
})), statements.take(verb).map(({ text }) => text));
|
|
2293
|
+
if (matched.unused.length > 0) throw errorConsentUnused(matched.unused, questions.map(({ subject }) => subject));
|
|
2294
|
+
}
|
|
2255
2295
|
}
|
|
2256
2296
|
function answering(prompt, statements) {
|
|
2257
2297
|
return async (questions) => {
|
|
@@ -2369,12 +2409,13 @@ function answeredByFlags(entries, verb, given) {
|
|
|
2369
2409
|
};
|
|
2370
2410
|
});
|
|
2371
2411
|
}
|
|
2372
|
-
|
|
2412
|
+
/** An entry a dry run lists: answered by a flag, or by a data protection setting that permits it. */
|
|
2413
|
+
function subjectEntryJson(entry, answeredBy, permitted) {
|
|
2373
2414
|
return {
|
|
2374
2415
|
operationIndex: entry.operationIndex,
|
|
2375
2416
|
subject: migrationSubjectJson(entry.subject),
|
|
2376
2417
|
text: entry.text,
|
|
2377
|
-
answered: answeredBy !== void 0,
|
|
2418
|
+
answered: permitted || answeredBy !== void 0,
|
|
2378
2419
|
...ifDefined("answeredBy", answeredBy),
|
|
2379
2420
|
...ifDefined("removedNamespace", entry.removedNamespace)
|
|
2380
2421
|
};
|
|
@@ -2391,17 +2432,17 @@ function removedNamespacesJson(value, given) {
|
|
|
2391
2432
|
}));
|
|
2392
2433
|
}
|
|
2393
2434
|
/** The data-loss entries a dry run lists, each with how it loses data and whether a flag answers it. */
|
|
2394
|
-
function dataLossEntriesJson(entries, given) {
|
|
2435
|
+
function dataLossEntriesJson(entries, given, permitted) {
|
|
2395
2436
|
const answered = answeredByFlags(entries, "delete", given);
|
|
2396
2437
|
return entries.map((entry, index) => ({
|
|
2397
|
-
...subjectEntryJson(entry, answered[index]),
|
|
2438
|
+
...subjectEntryJson(entry, answered[index], permitted),
|
|
2398
2439
|
...ifDefined("loss", entry.loss)
|
|
2399
2440
|
}));
|
|
2400
2441
|
}
|
|
2401
2442
|
/** The access entries a dry run lists, each marked answered when an `--allow` it was given answers it. */
|
|
2402
|
-
function accessEntriesJson(entries, given) {
|
|
2443
|
+
function accessEntriesJson(entries, given, permitted) {
|
|
2403
2444
|
const answered = answeredByFlags(entries, "allow", given);
|
|
2404
|
-
return entries.map((entry, index) => subjectEntryJson(entry, answered[index]));
|
|
2445
|
+
return entries.map((entry, index) => subjectEntryJson(entry, answered[index], permitted));
|
|
2405
2446
|
}
|
|
2406
2447
|
function updateDocument(inputs) {
|
|
2407
2448
|
const { value } = inputs;
|
|
@@ -2432,11 +2473,12 @@ function updateDocument(inputs) {
|
|
|
2432
2473
|
...ifDefined("perSpace", value.perSpace),
|
|
2433
2474
|
...ifDefined("changedStorageEntities", value.changedStorageEntities),
|
|
2434
2475
|
...ifDefined("databasePoliciesUpdated", value.databasePoliciesUpdated),
|
|
2476
|
+
...ifDefined("permitted", value.permitted),
|
|
2435
2477
|
appliedStatements: value.appliedStatements,
|
|
2436
2478
|
temporaryValues: value.temporaryValues,
|
|
2437
2479
|
...value.mode === "plan" ? {
|
|
2438
|
-
dataLoss: dataLossEntriesJson(value.dataLoss, inputs.statements),
|
|
2439
|
-
accessChanges: accessEntriesJson(value.accessChanges, inputs.statements),
|
|
2480
|
+
dataLoss: dataLossEntriesJson(value.dataLoss, inputs.statements, value.permitted?.includes("dataLoss") === true),
|
|
2481
|
+
accessChanges: accessEntriesJson(value.accessChanges, inputs.statements, value.permitted?.includes("accessWidening") === true),
|
|
2440
2482
|
removedNamespaces: removedNamespacesJson(value, inputs.statements),
|
|
2441
2483
|
addedNamespaces: value.namespaces?.added ?? []
|
|
2442
2484
|
} : {},
|
|
@@ -2562,7 +2604,7 @@ function createDbUpdateCommand(createClient) {
|
|
|
2562
2604
|
name: refName,
|
|
2563
2605
|
contractJson,
|
|
2564
2606
|
contractJsonPath: snapshotContractPath,
|
|
2565
|
-
|
|
2607
|
+
config: ctx.config,
|
|
2566
2608
|
client
|
|
2567
2609
|
});
|
|
2568
2610
|
if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
|
|
@@ -3433,7 +3475,7 @@ function errorInitMissingFlags(options) {
|
|
|
3433
3475
|
const flagList = options.missing.map((flag) => `--${flag}`).join(", ");
|
|
3434
3476
|
const fixList = options.missing.map((flag) => {
|
|
3435
3477
|
switch (flag) {
|
|
3436
|
-
case "target": return
|
|
3478
|
+
case "target": return `--target ${TARGET_SHORT_NAMES.join("|")}`;
|
|
3437
3479
|
case "authoring": return "--authoring psl|typescript";
|
|
3438
3480
|
case "schema-path": return "--schema-path <path>";
|
|
3439
3481
|
default: return `--${flag} <value>`;
|
|
@@ -3622,7 +3664,7 @@ function errorInitFlagConflict(options) {
|
|
|
3622
3664
|
meta: { flags: [first, second] }
|
|
3623
3665
|
});
|
|
3624
3666
|
}
|
|
3625
|
-
const PRISMA7_SUPPORTED_PROVIDERS =
|
|
3667
|
+
const PRISMA7_SUPPORTED_PROVIDERS = KNOWN_TARGET_PACKAGES.map((entry) => entry.provider.name);
|
|
3626
3668
|
/**
|
|
3627
3669
|
* The Prisma 7 schema's provider is one Prisma 8 has no target for, or is not
|
|
3628
3670
|
* a string literal and no `--target` names the database instead.
|
|
@@ -3702,13 +3744,75 @@ function errorInitPrisma7ConfigUnreadable(options) {
|
|
|
3702
3744
|
}
|
|
3703
3745
|
});
|
|
3704
3746
|
}
|
|
3705
|
-
/**
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3747
|
+
/**
|
|
3748
|
+
* The project does not have the target package: `--skip-install` forbade installing it, or init's
|
|
3749
|
+
* install command succeeded and the package still cannot be found from the project. Init takes
|
|
3750
|
+
* every file it writes from that package, so it stops before writing any scaffold file.
|
|
3751
|
+
*/
|
|
3752
|
+
function errorInitTargetPackageNotInstalled(options) {
|
|
3753
|
+
const { packageName, ranCommand } = options;
|
|
3754
|
+
return new CliStructuredError$1$1("CLI.INIT_TARGET_PACKAGE_NOT_INSTALLED", ranCommand !== void 0 ? `${packageName} cannot be found from the project` : `${packageName} is not installed`, {
|
|
3755
|
+
why: ranCommand !== void 0 ? `\`${ranCommand}\` succeeded, but ${packageName} cannot be found from the project, so init cannot read its init contribution. No scaffold file was written.` : `init writes the project from ${packageName}, and \`--skip-install\` forbids installing it. Nothing was changed.`,
|
|
3756
|
+
fix: ranCommand !== void 0 ? `Check that \`${options.installCommand}\` makes ${packageName} resolvable from this directory (Yarn Plug'n'Play hides packages from Node), then run \`prisma orm init\` again.` : `Install it with \`${options.installCommand}\`, then run \`prisma orm init\` again, or run it without \`--skip-install\`.`,
|
|
3757
|
+
docsUrl: docsUrlFor("CLI.INIT_TARGET_PACKAGE_NOT_INSTALLED"),
|
|
3758
|
+
meta: {
|
|
3759
|
+
packageName: options.packageName,
|
|
3760
|
+
installCommand: options.installCommand
|
|
3761
|
+
}
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
/**
|
|
3765
|
+
* The target package has no `init` entrypoint, its init module cannot be loaded, or its default
|
|
3766
|
+
* export is not an init contribution. The package is installed and no scaffold file was written.
|
|
3767
|
+
*/
|
|
3768
|
+
function errorInitContributionUnavailable(options) {
|
|
3769
|
+
const module = `${options.packageName}/init`;
|
|
3770
|
+
const detail = options.detail ?? "its shape is wrong";
|
|
3771
|
+
const why = {
|
|
3772
|
+
"no-entrypoint": `${options.packageName} has no \`${module}\` entrypoint, so it does not support \`prisma orm init\`.`,
|
|
3773
|
+
unloadable: `\`${module}\` could not be loaded: ${detail}.`,
|
|
3774
|
+
"invalid-shape": `The default export of \`${module}\` is not an init contribution: ${detail}.`
|
|
3775
|
+
}[options.reason];
|
|
3776
|
+
const byHand = `Write prisma.config.ts by hand, with the defineConfig import the README of ${options.packageName} shows.`;
|
|
3777
|
+
return new CliStructuredError$1$1("CLI.INIT_CONTRIBUTION_UNAVAILABLE", options.reason === "unloadable" ? `Could not load ${module}` : `${options.packageName} does not support init`, {
|
|
3778
|
+
why: `${why} ${options.packageName} is installed; no scaffold file was written.`,
|
|
3779
|
+
fix: options.reason === "unloadable" ? `Reinstall ${options.packageName} with your package manager and run \`prisma orm init\` again, or ${byHand.charAt(0).toLowerCase()}${byHand.slice(1)}` : byHand,
|
|
3780
|
+
docsUrl: docsUrlFor("CLI.INIT_CONTRIBUTION_UNAVAILABLE"),
|
|
3781
|
+
meta: {
|
|
3782
|
+
packageName: options.packageName,
|
|
3783
|
+
module,
|
|
3784
|
+
reason: options.reason
|
|
3785
|
+
}
|
|
3786
|
+
});
|
|
3787
|
+
}
|
|
3788
|
+
/** `--authoring` names a way to write the contract the target package does not offer. */
|
|
3789
|
+
function errorInitAuthoringUnsupported(options) {
|
|
3790
|
+
return new CliStructuredError$1$1("CLI.INIT_AUTHORING_UNSUPPORTED", `${options.packageName} does not offer --authoring ${options.authoring}`, {
|
|
3791
|
+
why: `${options.packageName} offers: ${options.offered.join(", ")}. No scaffold file was written.`,
|
|
3792
|
+
fix: `Use one of: ${options.offered.map((mode) => `--authoring ${mode}`).join(", ")}.`,
|
|
3793
|
+
docsUrl: docsUrlFor("CLI.INIT_AUTHORING_UNSUPPORTED"),
|
|
3794
|
+
meta: {
|
|
3795
|
+
packageName: options.packageName,
|
|
3796
|
+
authoring: options.authoring,
|
|
3797
|
+
offered: options.offered
|
|
3798
|
+
}
|
|
3799
|
+
});
|
|
3800
|
+
}
|
|
3801
|
+
function listed(items) {
|
|
3802
|
+
const last = items.at(-1) ?? "";
|
|
3803
|
+
return items.length <= 1 ? last : `${items.slice(0, -1).join(", ")} and ${last}`;
|
|
3709
3804
|
}
|
|
3710
|
-
|
|
3711
|
-
|
|
3805
|
+
const PRISMA7_CHECK = { kind: "prisma7-check" };
|
|
3806
|
+
/** The next action that tells the user how to undo what init installed. */
|
|
3807
|
+
function packagesAddedAction(added, reason) {
|
|
3808
|
+
const rewritten = listed(added.rewritten.map(({ name, before }) => `${name}, which was \`${before}\``));
|
|
3809
|
+
const rangeNote = added.rewritten.length === 0 ? "" : `changed the declared range of ${rewritten}; set it back in package.json.`;
|
|
3810
|
+
if (added.packages.length === 0) return `init ${rangeNote}`;
|
|
3811
|
+
const pronoun = added.packages.length === 1 ? "it" : "them";
|
|
3812
|
+
const packages = listed(added.packages);
|
|
3813
|
+
const remove = `remove ${pronoun} with \`${added.removeCommand}\`.`;
|
|
3814
|
+
const sentence = reason.kind === "prisma7-check" ? `init added ${packages} to package.json before checking; ${remove}` : `init installed ${packages} to read the init contribution of ${reason.packageName}; ${remove}`;
|
|
3815
|
+
return rangeNote === "" ? sentence : `${sentence} It also ${rangeNote}`;
|
|
3712
3816
|
}
|
|
3713
3817
|
/**
|
|
3714
3818
|
* The target package init loads to read the Prisma 7 schema cannot be loaded
|
|
@@ -3717,10 +3821,14 @@ function packagesAddedNote(added) {
|
|
|
3717
3821
|
*/
|
|
3718
3822
|
function errorInitPrisma7SourceUnavailable(options) {
|
|
3719
3823
|
const { packageName, schemaPath } = options;
|
|
3720
|
-
const wording = options.reason === "
|
|
3721
|
-
summary: `Could not load ${
|
|
3722
|
-
why:
|
|
3723
|
-
fix: `
|
|
3824
|
+
const wording = options.reason === "unloadable" ? {
|
|
3825
|
+
summary: `Could not load ${options.module}`,
|
|
3826
|
+
why: `\`${options.module}\` could not be loaded: ${options.cause}. init cannot check that Prisma 8 reads ${schemaPath}.`,
|
|
3827
|
+
fix: `Reinstall ${packageName} with your package manager, then run \`prisma orm init\` again.`
|
|
3828
|
+
} : options.reason === "not-resolvable" ? {
|
|
3829
|
+
summary: `Could not load ${options.module} from the project`,
|
|
3830
|
+
why: `${packageName} was installed, but the project cannot find \`${options.module}\`, the config module its init contribution names, so init cannot check that Prisma 8 reads ${schemaPath}.`,
|
|
3831
|
+
fix: `Check that ${packageName} is installed and exports ${options.module}, resolvable from this directory (Yarn Plug'n'Play hides packages from Node), then run \`prisma orm init\` again.`
|
|
3724
3832
|
} : {
|
|
3725
3833
|
summary: "No Prisma 7 contract source for this database",
|
|
3726
3834
|
why: `${packageName} does not provide a Prisma 7 contract source, so it cannot read ${schemaPath}.`,
|
|
@@ -3728,13 +3836,13 @@ function errorInitPrisma7SourceUnavailable(options) {
|
|
|
3728
3836
|
};
|
|
3729
3837
|
return new CliStructuredError$1$1("CLI.INIT_PRISMA7_SOURCE_UNAVAILABLE", wording.summary, {
|
|
3730
3838
|
why: wording.why,
|
|
3731
|
-
fix:
|
|
3839
|
+
fix: wording.fix,
|
|
3732
3840
|
docsUrl: docsUrlFor("CLI.INIT_PRISMA7_SOURCE_UNAVAILABLE"),
|
|
3733
3841
|
meta: {
|
|
3734
3842
|
schemaPath: options.schemaPath,
|
|
3735
3843
|
packageName: options.packageName,
|
|
3736
3844
|
reason: options.reason,
|
|
3737
|
-
|
|
3845
|
+
...options.reason === "no-prisma7-source" ? {} : { module: options.module }
|
|
3738
3846
|
}
|
|
3739
3847
|
});
|
|
3740
3848
|
}
|
|
@@ -3746,18 +3854,17 @@ function errorInitPrisma7SchemaRefused(options) {
|
|
|
3746
3854
|
const findings = options.diagnostics.map((diagnostic) => `\n ${formatSourceDiagnostic(diagnostic)}`);
|
|
3747
3855
|
return new CliStructuredError$1$1("CLI.INIT_PRISMA7_SCHEMA_REFUSED", `Prisma 8 cannot read ${options.schemaPath}`, {
|
|
3748
3856
|
why: `${options.summary}${findings.join("")}`,
|
|
3749
|
-
fix: `Edit ${options.schemaPath} as each finding says (see the Prisma 7 contract source section of the ${options.packageName} README), or run \`prisma orm init\` without \`--from-prisma7-schema
|
|
3857
|
+
fix: `Edit ${options.schemaPath} as each finding says (see the Prisma 7 contract source section of the ${options.packageName} README), or run \`prisma orm init\` without \`--from-prisma7-schema\`.`,
|
|
3750
3858
|
docsUrl: docsUrlFor("CLI.INIT_PRISMA7_SCHEMA_REFUSED"),
|
|
3751
3859
|
meta: {
|
|
3752
3860
|
schemaPath: options.schemaPath,
|
|
3753
3861
|
summary: options.summary,
|
|
3754
|
-
diagnostics: options.diagnostics
|
|
3755
|
-
packagesAdded: options.added?.packages ?? []
|
|
3862
|
+
diagnostics: options.diagnostics
|
|
3756
3863
|
}
|
|
3757
3864
|
});
|
|
3758
3865
|
}
|
|
3759
3866
|
/**
|
|
3760
|
-
* The project's schema is a Prisma 6
|
|
3867
|
+
* The project's schema names a provider only Prisma 6 wrote, so it is a Prisma 6 schema. Init stops before changing anything and gives
|
|
3761
3868
|
* the side-by-side setup as its next actions: set up by init, Prisma 8 would take the `prisma`
|
|
3762
3869
|
* package name and `prisma.config.ts` from the Prisma 6 CLI the app still runs.
|
|
3763
3870
|
*/
|
|
@@ -3783,7 +3890,7 @@ const CONFIG_EXTENSIONS = [
|
|
|
3783
3890
|
"cjs"
|
|
3784
3891
|
];
|
|
3785
3892
|
const PRISMA7_CLI_PACKAGE = "@prisma/prisma7";
|
|
3786
|
-
function isRecord$
|
|
3893
|
+
function isRecord$4(value) {
|
|
3787
3894
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3788
3895
|
}
|
|
3789
3896
|
function findConfigFile(cwd, stem) {
|
|
@@ -3796,7 +3903,7 @@ async function evaluateConfig(cwd, path) {
|
|
|
3796
3903
|
why: evaluated.failure.why ?? evaluated.failure.message
|
|
3797
3904
|
};
|
|
3798
3905
|
const exported = evaluated.value;
|
|
3799
|
-
if (!isRecord$
|
|
3906
|
+
if (!isRecord$4(exported) || Object.hasOwn(exported, "__esModule")) return {
|
|
3800
3907
|
kind: "unreadable",
|
|
3801
3908
|
why: `${path} has no object default export`
|
|
3802
3909
|
};
|
|
@@ -3901,7 +4008,7 @@ const CONVENTIONAL_SCHEMA_PATHS = [
|
|
|
3901
4008
|
*/
|
|
3902
4009
|
function conventionalSchemaPath(cwd) {
|
|
3903
4010
|
const declared = readJsonRecord(join(cwd, "package.json"))?.["prisma"];
|
|
3904
|
-
const schema = isRecord$
|
|
4011
|
+
const schema = isRecord$4(declared) ? declared["schema"] : void 0;
|
|
3905
4012
|
if (typeof schema === "string") return {
|
|
3906
4013
|
path: schema,
|
|
3907
4014
|
source: "package-json"
|
|
@@ -3915,7 +4022,7 @@ function readJsonRecord(path) {
|
|
|
3915
4022
|
if (!existsSync(path)) return;
|
|
3916
4023
|
try {
|
|
3917
4024
|
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
3918
|
-
return isRecord$
|
|
4025
|
+
return isRecord$4(parsed) ? parsed : void 0;
|
|
3919
4026
|
} catch {
|
|
3920
4027
|
return;
|
|
3921
4028
|
}
|
|
@@ -3923,7 +4030,7 @@ function readJsonRecord(path) {
|
|
|
3923
4030
|
function declaredRange(manifest, name) {
|
|
3924
4031
|
for (const field of ["devDependencies", "dependencies"]) {
|
|
3925
4032
|
const section = manifest[field];
|
|
3926
|
-
const range = isRecord$
|
|
4033
|
+
const range = isRecord$4(section) ? section[name] : void 0;
|
|
3927
4034
|
if (typeof range === "string") return range;
|
|
3928
4035
|
}
|
|
3929
4036
|
}
|
|
@@ -3984,9 +4091,49 @@ async function detectPrisma7Project(ctx) {
|
|
|
3984
4091
|
};
|
|
3985
4092
|
}
|
|
3986
4093
|
/**
|
|
3987
|
-
*
|
|
3988
|
-
*
|
|
3989
|
-
|
|
4094
|
+
* How long the CLI waits for a target package's probe. Prisma's own probes give the driver 20
|
|
4095
|
+
* seconds to connect and 20 more to answer, so they settle inside it.
|
|
4096
|
+
*/
|
|
4097
|
+
const PROBE_DEADLINE_MILLIS = 6e4;
|
|
4098
|
+
const TIMED_OUT = Symbol("timed-out");
|
|
4099
|
+
/**
|
|
4100
|
+
* The probe's answer, or `TIMED_OUT` when it has not settled by the deadline, at which point the
|
|
4101
|
+
* probe's signal is aborted so it can close its client.
|
|
4102
|
+
*/
|
|
4103
|
+
async function withinDeadline(probe) {
|
|
4104
|
+
const controller = new AbortController();
|
|
4105
|
+
let timer;
|
|
4106
|
+
const deadline = new Promise((resolve) => {
|
|
4107
|
+
timer = setTimeout(() => {
|
|
4108
|
+
controller.abort();
|
|
4109
|
+
resolve(TIMED_OUT);
|
|
4110
|
+
}, PROBE_DEADLINE_MILLIS);
|
|
4111
|
+
});
|
|
4112
|
+
try {
|
|
4113
|
+
return await Promise.race([probe(controller.signal), deadline]);
|
|
4114
|
+
} finally {
|
|
4115
|
+
clearTimeout(timer);
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
const ProbeResultSchema = type({
|
|
4119
|
+
kind: "'server-version'",
|
|
4120
|
+
serverVersion: "string"
|
|
4121
|
+
}).or({
|
|
4122
|
+
kind: "'version-unreadable'",
|
|
4123
|
+
detail: "string"
|
|
4124
|
+
}).or({
|
|
4125
|
+
kind: "'driver-missing'",
|
|
4126
|
+
driver: "string",
|
|
4127
|
+
cause: "string"
|
|
4128
|
+
}).or({
|
|
4129
|
+
kind: "'driver-failed'",
|
|
4130
|
+
driver: "string",
|
|
4131
|
+
cause: "string"
|
|
4132
|
+
});
|
|
4133
|
+
/**
|
|
4134
|
+
* Connects (when configured) to the user's database through the target
|
|
4135
|
+
* package's probe and returns a structured outcome describing whether the
|
|
4136
|
+
* server meets the minimum the package states (FR8.1). No I/O happens
|
|
3990
4137
|
* unless `databaseUrl` is set.
|
|
3991
4138
|
*
|
|
3992
4139
|
* The outcome is shaped so that `--strict-probe` can branch on the
|
|
@@ -3997,51 +4144,114 @@ async function detectPrisma7Project(ctx) {
|
|
|
3997
4144
|
* `--strict-probe` (the spec scopes strict-probe to "probe
|
|
3998
4145
|
* *failures*", and a successful probe that finds an old server is
|
|
3999
4146
|
* not a failure).
|
|
4000
|
-
* - `no-database-url` / `connection-failed` / `driver-missing`
|
|
4001
|
-
*
|
|
4147
|
+
* - `no-database-url` / `connection-failed` / `timed-out` / `driver-missing` /
|
|
4148
|
+
* `version-unreadable` / `invalid-result` / `unsupported` — warning by
|
|
4149
|
+
* default, fatal under `--strict-probe`.
|
|
4002
4150
|
*/
|
|
4003
|
-
async function probeServerVersion(ctx
|
|
4004
|
-
const { databaseUrl,
|
|
4151
|
+
async function probeServerVersion(ctx) {
|
|
4152
|
+
const { databaseUrl, contribution } = ctx;
|
|
4153
|
+
const minVersion = contribution.serverRequirement?.minVersion;
|
|
4005
4154
|
if (databaseUrl === void 0 || databaseUrl.trim().length === 0) return {
|
|
4006
4155
|
kind: "no-database-url",
|
|
4007
4156
|
minVersion,
|
|
4008
4157
|
meetsMinimum: null,
|
|
4009
4158
|
message: "Skipped --probe-db: DATABASE_URL is not set in the current shell environment. (init does not read .env for the probe; export the variable or drop --probe-db.)"
|
|
4010
4159
|
};
|
|
4011
|
-
|
|
4160
|
+
if (contribution.probe === void 0) return {
|
|
4161
|
+
kind: "unsupported",
|
|
4162
|
+
minVersion,
|
|
4163
|
+
meetsMinimum: null,
|
|
4164
|
+
message: `Skipped --probe-db: ${ctx.packageName} cannot check the server.`
|
|
4165
|
+
};
|
|
4166
|
+
let answer;
|
|
4012
4167
|
try {
|
|
4013
|
-
|
|
4014
|
-
|
|
4168
|
+
const { probe } = contribution;
|
|
4169
|
+
answer = await withinDeadline((signal) => probe(databaseUrl, signal));
|
|
4015
4170
|
} catch (err) {
|
|
4016
|
-
|
|
4171
|
+
const cause = redactUrlCredentials(causeMessage$3(err));
|
|
4172
|
+
return {
|
|
4173
|
+
kind: "connection-failed",
|
|
4174
|
+
minVersion,
|
|
4175
|
+
meetsMinimum: null,
|
|
4176
|
+
cause,
|
|
4177
|
+
message: `--probe-db could not connect: ${cause}.`
|
|
4178
|
+
};
|
|
4179
|
+
}
|
|
4180
|
+
if (answer === TIMED_OUT) return {
|
|
4181
|
+
kind: "timed-out",
|
|
4182
|
+
minVersion,
|
|
4183
|
+
meetsMinimum: null,
|
|
4184
|
+
message: `--probe-db gave up: the probe of ${ctx.packageName} did not finish within ${PROBE_DEADLINE_MILLIS / 1e3} seconds.`
|
|
4185
|
+
};
|
|
4186
|
+
const result = ProbeResultSchema(answer);
|
|
4187
|
+
if (result instanceof type.errors) {
|
|
4188
|
+
const cause = redactUrlCredentials(`the probe of ${ctx.packageName} gave a malformed answer: ${result.summary}`);
|
|
4189
|
+
return {
|
|
4190
|
+
kind: "invalid-result",
|
|
4191
|
+
minVersion,
|
|
4192
|
+
meetsMinimum: null,
|
|
4193
|
+
cause,
|
|
4194
|
+
message: `Skipped --probe-db: ${cause}.`
|
|
4195
|
+
};
|
|
4196
|
+
}
|
|
4197
|
+
if (result.kind === "driver-missing") {
|
|
4198
|
+
const cause = redactUrlCredentials(`\`${result.driver}\` could not be loaded by ${ctx.packageName} (cause: ${result.cause})`);
|
|
4199
|
+
return {
|
|
4017
4200
|
kind: "driver-missing",
|
|
4018
4201
|
minVersion,
|
|
4019
4202
|
meetsMinimum: null,
|
|
4020
|
-
cause
|
|
4021
|
-
message: `Skipped --probe-db: ${
|
|
4203
|
+
cause,
|
|
4204
|
+
message: `Skipped --probe-db: ${cause}. (Run with install enabled, or install the driver yourself, then re-run \`prisma orm init --probe-db\`.)`
|
|
4022
4205
|
};
|
|
4023
|
-
|
|
4206
|
+
}
|
|
4207
|
+
if (result.kind === "driver-failed") {
|
|
4208
|
+
const cause = redactUrlCredentials(`\`${result.driver}\` is installed but could not be loaded by ${ctx.packageName} (cause: ${result.cause})`);
|
|
4024
4209
|
return {
|
|
4025
|
-
kind: "
|
|
4210
|
+
kind: "driver-failed",
|
|
4026
4211
|
minVersion,
|
|
4027
4212
|
meetsMinimum: null,
|
|
4028
4213
|
cause,
|
|
4029
|
-
message:
|
|
4214
|
+
message: `Skipped --probe-db: ${cause}.`
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
if (result.kind === "version-unreadable") {
|
|
4218
|
+
const cause = redactUrlCredentials(result.detail);
|
|
4219
|
+
return {
|
|
4220
|
+
kind: "version-unreadable",
|
|
4221
|
+
minVersion,
|
|
4222
|
+
meetsMinimum: null,
|
|
4223
|
+
cause,
|
|
4224
|
+
message: `--probe-db connected to the server, but could not read its version: ${cause}.`
|
|
4030
4225
|
};
|
|
4031
4226
|
}
|
|
4032
|
-
|
|
4227
|
+
const { serverVersion } = result;
|
|
4228
|
+
if (!/\d/.test(serverVersion)) return {
|
|
4229
|
+
kind: "version-unreadable",
|
|
4230
|
+
minVersion,
|
|
4231
|
+
meetsMinimum: null,
|
|
4232
|
+
cause: `the probe of ${ctx.packageName} reported the version ${JSON.stringify(serverVersion)}`,
|
|
4233
|
+
message: `--probe-db connected to the server, but could not read its version: the probe of ${ctx.packageName} reported the version ${JSON.stringify(serverVersion)}.`
|
|
4234
|
+
};
|
|
4235
|
+
if (minVersion === void 0) return {
|
|
4236
|
+
kind: "ok",
|
|
4237
|
+
serverVersion,
|
|
4238
|
+
minVersion,
|
|
4239
|
+
meetsMinimum: true,
|
|
4240
|
+
message: `--probe-db: server reports version ${serverVersion}.`
|
|
4241
|
+
};
|
|
4242
|
+
if (compareVersionPrefix(serverVersion, minVersion) < 0) return {
|
|
4033
4243
|
kind: "below-minimum",
|
|
4034
|
-
serverVersion
|
|
4244
|
+
serverVersion,
|
|
4035
4245
|
minVersion,
|
|
4036
4246
|
meetsMinimum: false,
|
|
4037
|
-
message: `--probe-db: server reports version ${
|
|
4247
|
+
message: `--probe-db: server reports version ${serverVersion}, below the declared minimum (${minVersion}). Some queries may fail until the server is upgraded.`
|
|
4038
4248
|
};
|
|
4039
4249
|
return {
|
|
4040
4250
|
kind: "ok",
|
|
4041
|
-
serverVersion
|
|
4251
|
+
serverVersion,
|
|
4042
4252
|
minVersion,
|
|
4043
4253
|
meetsMinimum: true,
|
|
4044
|
-
message: `--probe-db: server reports version ${
|
|
4254
|
+
message: `--probe-db: server reports version ${serverVersion} (>= ${minVersion}).`
|
|
4045
4255
|
};
|
|
4046
4256
|
}
|
|
4047
4257
|
/**
|
|
@@ -4074,455 +4284,10 @@ function parseNumericParts(version) {
|
|
|
4074
4284
|
if (match === null) return [];
|
|
4075
4285
|
return (match[1] ?? "").split(".").map((part) => Number.parseInt(part, 10));
|
|
4076
4286
|
}
|
|
4077
|
-
|
|
4078
|
-
function causeMessage$2(err) {
|
|
4287
|
+
function causeMessage$3(err) {
|
|
4079
4288
|
if (err instanceof Error) return err.message;
|
|
4080
4289
|
return String(err);
|
|
4081
4290
|
}
|
|
4082
|
-
async function defaultProbePostgres(databaseUrl, baseDir, overrides) {
|
|
4083
|
-
const client = suppressIdleConnectionErrors(new (requirePeer("pg", baseDir, overrides)).Client({ connectionString: databaseUrl }));
|
|
4084
|
-
try {
|
|
4085
|
-
await client.connect();
|
|
4086
|
-
const result = await client.query("SELECT version() as version");
|
|
4087
|
-
return { serverVersion: parsePostgresVersion(String(result?.rows?.[0]?.version ?? "")) };
|
|
4088
|
-
} finally {
|
|
4089
|
-
await client.end().catch(() => void 0);
|
|
4090
|
-
}
|
|
4091
|
-
}
|
|
4092
|
-
/**
|
|
4093
|
-
* Extracts the numeric prefix from a Postgres `version()` row, e.g.
|
|
4094
|
-
*
|
|
4095
|
-
* `PostgreSQL 14.10 on x86_64-pc-linux-gnu, ...` → `"14.10"`
|
|
4096
|
-
* `PostgreSQL 16beta1 on …` → `"16"` (we
|
|
4097
|
-
* conservatively drop the suffix; minimum-version comparisons
|
|
4098
|
-
* treat 16beta1 as 16, which is what every reasonable user
|
|
4099
|
-
* expects).
|
|
4100
|
-
*
|
|
4101
|
-
* Exported for unit tests.
|
|
4102
|
-
*/
|
|
4103
|
-
function parsePostgresVersion(versionString) {
|
|
4104
|
-
const match = versionString.match(/PostgreSQL\s+(\d+(?:\.\d+)?)/i);
|
|
4105
|
-
if (match === null || match[1] === void 0) throw new CliStructuredError("CLI.INIT_PROBE_FAILED", `Could not parse PostgreSQL version from \`${versionString}\``);
|
|
4106
|
-
return match[1];
|
|
4107
|
-
}
|
|
4108
|
-
async function defaultProbeMongo(databaseUrl, baseDir, overrides) {
|
|
4109
|
-
const client = new (requirePeer("mongodb", baseDir, overrides)).MongoClient(databaseUrl);
|
|
4110
|
-
await client.connect();
|
|
4111
|
-
try {
|
|
4112
|
-
const buildInfo = await client.db().admin().command({ buildInfo: 1 });
|
|
4113
|
-
const versionString = String(buildInfo.version ?? "");
|
|
4114
|
-
if (versionString.length === 0) throw new CliStructuredError("CLI.INIT_PROBE_FAILED", "buildInfo did not include a `version` field");
|
|
4115
|
-
return { serverVersion: versionString };
|
|
4116
|
-
} finally {
|
|
4117
|
-
await client.close().catch(() => void 0);
|
|
4118
|
-
}
|
|
4119
|
-
}
|
|
4120
|
-
/**
|
|
4121
|
-
* Loads a peer driver (`pg` / `mongodb`) from the user's project
|
|
4122
|
-
* `node_modules`. We deliberately resolve from `baseDir` rather than
|
|
4123
|
-
* from the CLI bundle — the CLI does not depend on `pg` or `mongodb`
|
|
4124
|
-
* directly, but the user's `init`-generated `package.json` does (via
|
|
4125
|
-
* the target facade). Failure to resolve is folded into a typed
|
|
4126
|
-
* `DriverMissingError` so `probeServerVersion` can map it to a
|
|
4127
|
-
* `driver-missing` outcome rather than letting a `MODULE_NOT_FOUND`
|
|
4128
|
-
* leak as a generic connection failure.
|
|
4129
|
-
*/
|
|
4130
|
-
function requirePeer(moduleId, baseDir, overrides) {
|
|
4131
|
-
try {
|
|
4132
|
-
if (overrides.requireFromBaseDir !== void 0) return overrides.requireFromBaseDir(baseDir, moduleId);
|
|
4133
|
-
return createRequire(join(baseDir, "package.json"))(moduleId);
|
|
4134
|
-
} catch (err) {
|
|
4135
|
-
throw new DriverMissingError(`\`${moduleId}\` is not installed in this project (resolved from ${baseDir}; cause: ${causeMessage$2(err)})`);
|
|
4136
|
-
}
|
|
4137
|
-
}
|
|
4138
|
-
/**
|
|
4139
|
-
* The resolver a scaffold for `target` is written against.
|
|
4140
|
-
*
|
|
4141
|
-
* A scaffold is always on the facade root: `init` writes an application around
|
|
4142
|
-
* one database package, and the workspace names are not published, so a project
|
|
4143
|
-
* scaffolded against them could not install (ADR 242). Both the files `init`
|
|
4144
|
-
* writes and the dependency it adds go through this, so they cannot disagree.
|
|
4145
|
-
*/
|
|
4146
|
-
function scaffoldSpecifierResolverFor(target) {
|
|
4147
|
-
return createScaffoldSpecifierResolver({
|
|
4148
|
-
mode: "facade",
|
|
4149
|
-
facade: target === "postgres" ? "@prisma/orm-postgres" : "@prisma/orm-mongo"
|
|
4150
|
-
});
|
|
4151
|
-
}
|
|
4152
|
-
/**
|
|
4153
|
-
* The package name a scaffolded project depends on and imports from, for the
|
|
4154
|
-
* import root it is being scaffolded against.
|
|
4155
|
-
*
|
|
4156
|
-
* Every specifier the scaffold writes derives from this one, and `init` builds
|
|
4157
|
-
* a single resolver and hands it to both the file templates and the dependency
|
|
4158
|
-
* it installs — so the two cannot disagree. The one caller that deliberately
|
|
4159
|
-
* does not thread a resolver is the re-init cleanup in `inputs.ts`, which
|
|
4160
|
-
* inspects a manifest an earlier run wrote rather than writing one.
|
|
4161
|
-
*
|
|
4162
|
-
* Resolvers for scaffolding should come from `createScaffoldSpecifierResolver`
|
|
4163
|
-
* in the publish-surface package, which rejects the roots a facade-shaped
|
|
4164
|
-
* scaffold cannot express. (Named without its scope on purpose: JSDoc survives
|
|
4165
|
-
* into the published bundle, where an internal package name would trip the
|
|
4166
|
-
* shell tarball checks.)
|
|
4167
|
-
*/
|
|
4168
|
-
function targetPackageName(target, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4169
|
-
return resolveImportSpecifier(target === "postgres" ? "@internal/postgres" : "@internal/mongo");
|
|
4170
|
-
}
|
|
4171
|
-
const DRIVER_PEERS = /* @__PURE__ */ new Map([["mongo", "mongodb"]]);
|
|
4172
|
-
/** Packages the target package declares as required peer dependencies; init installs them with it. */
|
|
4173
|
-
function targetPeerPackages(target) {
|
|
4174
|
-
const driver = DRIVER_PEERS.get(target);
|
|
4175
|
-
return driver === void 0 ? [] : [driver];
|
|
4176
|
-
}
|
|
4177
|
-
/** One entrypoint of the scaffolded project's target package. */
|
|
4178
|
-
function targetEntrypoint(target, subpath, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4179
|
-
return resolveImportSpecifier(`${target === "postgres" ? "@internal/postgres" : "@internal/mongo"}/${subpath}`);
|
|
4180
|
-
}
|
|
4181
|
-
function targetLabel(target) {
|
|
4182
|
-
return target === "postgres" ? "PostgreSQL" : "MongoDB";
|
|
4183
|
-
}
|
|
4184
|
-
function defaultSchemaPath(authoring) {
|
|
4185
|
-
if (authoring === "typescript") return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.ts`;
|
|
4186
|
-
return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.prisma`;
|
|
4187
|
-
}
|
|
4188
|
-
function starterSchema(target, authoring, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4189
|
-
if (authoring === "typescript") {
|
|
4190
|
-
const builder = targetEntrypoint(target, "contract-builder", resolveImportSpecifier);
|
|
4191
|
-
return target === "mongo" ? starterSchemaTsMongo(builder) : starterSchemaTsPostgres(builder);
|
|
4192
|
-
}
|
|
4193
|
-
return target === "mongo" ? starterSchemaPslMongo() : starterSchemaPslPostgres();
|
|
4194
|
-
}
|
|
4195
|
-
/**
|
|
4196
|
-
* Renders a short authoring-appropriate schema sample for embedding in
|
|
4197
|
-
* `prisma-8.md`. Returns a complete fenced markdown code block.
|
|
4198
|
-
*
|
|
4199
|
-
* The sample intentionally shows just one model: it's illustrative, not
|
|
4200
|
-
* a substitute for the full scaffolded contract file. The TS samples use
|
|
4201
|
-
* the same outer shape as `starterSchemaTs*` so a user reading the doc and
|
|
4202
|
-
* the file side-by-side sees the same structure.
|
|
4203
|
-
*/
|
|
4204
|
-
function schemaSample(target, authoring, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4205
|
-
if (authoring === "typescript") {
|
|
4206
|
-
const builder = targetEntrypoint(target, "contract-builder", resolveImportSpecifier);
|
|
4207
|
-
return target === "mongo" ? schemaSampleTsMongo(builder) : schemaSampleTsPostgres(builder);
|
|
4208
|
-
}
|
|
4209
|
-
return target === "mongo" ? schemaSamplePslMongo() : schemaSamplePslPostgres();
|
|
4210
|
-
}
|
|
4211
|
-
function schemaSamplePslPostgres() {
|
|
4212
|
-
return `\`\`\`prisma
|
|
4213
|
-
model User {
|
|
4214
|
-
id Int @id @default(autoincrement())
|
|
4215
|
-
email String @unique
|
|
4216
|
-
username String?
|
|
4217
|
-
name String?
|
|
4218
|
-
}
|
|
4219
|
-
\`\`\``;
|
|
4220
|
-
}
|
|
4221
|
-
function schemaSamplePslMongo() {
|
|
4222
|
-
return `\`\`\`prisma
|
|
4223
|
-
model User {
|
|
4224
|
-
id ObjectId @id @map("_id")
|
|
4225
|
-
email String @unique
|
|
4226
|
-
username String?
|
|
4227
|
-
name String?
|
|
4228
|
-
@@map("users")
|
|
4229
|
-
}
|
|
4230
|
-
\`\`\``;
|
|
4231
|
-
}
|
|
4232
|
-
function schemaSampleTsPostgres(builder) {
|
|
4233
|
-
return `\`\`\`typescript
|
|
4234
|
-
import { defineContract } from '${builder}';
|
|
4235
|
-
|
|
4236
|
-
export const contract = defineContract(
|
|
4237
|
-
{},
|
|
4238
|
-
({ field, model, gen, type }) => ({
|
|
4239
|
-
models: {
|
|
4240
|
-
User: model('User', {
|
|
4241
|
-
fields: {
|
|
4242
|
-
id: field.column(type.Uuid()).id().onCreate(gen.uuid(7)),
|
|
4243
|
-
email: field.column(type.String()).unique(),
|
|
4244
|
-
username: field.column(type.String()).optional(),
|
|
4245
|
-
name: field.column(type.String()).optional(),
|
|
4246
|
-
},
|
|
4247
|
-
}),
|
|
4248
|
-
},
|
|
4249
|
-
}),
|
|
4250
|
-
);
|
|
4251
|
-
\`\`\``;
|
|
4252
|
-
}
|
|
4253
|
-
function schemaSampleTsMongo(builder) {
|
|
4254
|
-
return `\`\`\`typescript
|
|
4255
|
-
import { defineContract } from '${builder}';
|
|
4256
|
-
|
|
4257
|
-
export const contract = defineContract(
|
|
4258
|
-
{},
|
|
4259
|
-
({ field, model, type }) => ({
|
|
4260
|
-
models: {
|
|
4261
|
-
User: model('User', {
|
|
4262
|
-
collection: 'users',
|
|
4263
|
-
fields: {
|
|
4264
|
-
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
4265
|
-
email: field.scalar(type.String()),
|
|
4266
|
-
username: field.scalar(type.String()).optional(),
|
|
4267
|
-
name: field.scalar(type.String()).optional(),
|
|
4268
|
-
},
|
|
4269
|
-
}),
|
|
4270
|
-
},
|
|
4271
|
-
}),
|
|
4272
|
-
);
|
|
4273
|
-
\`\`\``;
|
|
4274
|
-
}
|
|
4275
|
-
function starterSchemaPslPostgres() {
|
|
4276
|
-
return `// use prisma-8
|
|
4277
|
-
|
|
4278
|
-
model User {
|
|
4279
|
-
id Int @id @default(autoincrement())
|
|
4280
|
-
email String @unique
|
|
4281
|
-
username String?
|
|
4282
|
-
name String?
|
|
4283
|
-
posts Post[]
|
|
4284
|
-
createdAt DateTime @default(now()) @onCreate(now())
|
|
4285
|
-
updatedAt temporal.UpdatedAt
|
|
4286
|
-
}
|
|
4287
|
-
|
|
4288
|
-
model Post {
|
|
4289
|
-
id Int @id @default(autoincrement())
|
|
4290
|
-
title String
|
|
4291
|
-
content String?
|
|
4292
|
-
author User @relation(fields: [authorId], references: [id])
|
|
4293
|
-
authorId Int
|
|
4294
|
-
createdAt DateTime @default(now()) @onCreate(now())
|
|
4295
|
-
updatedAt temporal.UpdatedAt
|
|
4296
|
-
}
|
|
4297
|
-
`;
|
|
4298
|
-
}
|
|
4299
|
-
function starterSchemaPslMongo() {
|
|
4300
|
-
return `// use prisma-8
|
|
4301
|
-
|
|
4302
|
-
model User {
|
|
4303
|
-
id ObjectId @id @map("_id")
|
|
4304
|
-
email String @unique
|
|
4305
|
-
username String?
|
|
4306
|
-
name String?
|
|
4307
|
-
posts Post[]
|
|
4308
|
-
@@map("users")
|
|
4309
|
-
}
|
|
4310
|
-
|
|
4311
|
-
model Post {
|
|
4312
|
-
id ObjectId @id @map("_id")
|
|
4313
|
-
title String
|
|
4314
|
-
content String?
|
|
4315
|
-
author User @relation(fields: [authorId], references: [id])
|
|
4316
|
-
authorId ObjectId
|
|
4317
|
-
@@map("posts")
|
|
4318
|
-
}
|
|
4319
|
-
`;
|
|
4320
|
-
}
|
|
4321
|
-
function starterSchemaTsPostgres(builder) {
|
|
4322
|
-
return `import { defineContract, now } from '${builder}';
|
|
4323
|
-
|
|
4324
|
-
export const contract = defineContract({}, ({ field, model, rel, gen, type }) => {
|
|
4325
|
-
const User = model('User', {
|
|
4326
|
-
fields: {
|
|
4327
|
-
id: field.column(type.Uuid()).id().onCreate(gen.uuid(7)),
|
|
4328
|
-
email: field.column(type.String()).unique(),
|
|
4329
|
-
username: field.column(type.String()).optional(),
|
|
4330
|
-
name: field.column(type.String()).optional(),
|
|
4331
|
-
createdAt: field.column(type.DateTime()).default(now()).onCreate(gen.now()),
|
|
4332
|
-
updatedAt: field.column(type.temporal.UpdatedAt()),
|
|
4333
|
-
},
|
|
4334
|
-
});
|
|
4335
|
-
|
|
4336
|
-
const Post = model('Post', {
|
|
4337
|
-
fields: {
|
|
4338
|
-
id: field.column(type.Uuid()).id().onCreate(gen.uuid(7)),
|
|
4339
|
-
title: field.column(type.String()),
|
|
4340
|
-
content: field.column(type.String()).optional(),
|
|
4341
|
-
authorId: field.column(type.Uuid()),
|
|
4342
|
-
createdAt: field.column(type.DateTime()).default(now()).onCreate(gen.now()),
|
|
4343
|
-
updatedAt: field.column(type.temporal.UpdatedAt()),
|
|
4344
|
-
},
|
|
4345
|
-
});
|
|
4346
|
-
|
|
4347
|
-
return {
|
|
4348
|
-
models: {
|
|
4349
|
-
User: User.relations({
|
|
4350
|
-
posts: rel.hasMany(Post, { by: 'authorId' }),
|
|
4351
|
-
}),
|
|
4352
|
-
Post: Post.relations({
|
|
4353
|
-
author: rel.belongsTo(User, { from: 'authorId', to: 'id' }),
|
|
4354
|
-
}),
|
|
4355
|
-
},
|
|
4356
|
-
};
|
|
4357
|
-
});
|
|
4358
|
-
`;
|
|
4359
|
-
}
|
|
4360
|
-
function starterSchemaTsMongo(builder) {
|
|
4361
|
-
return `import { defineContract } from '${builder}';
|
|
4362
|
-
|
|
4363
|
-
export const contract = defineContract(
|
|
4364
|
-
{},
|
|
4365
|
-
({ field, model, rel, type }) => ({
|
|
4366
|
-
models: {
|
|
4367
|
-
User: model('User', {
|
|
4368
|
-
collection: 'users',
|
|
4369
|
-
fields: {
|
|
4370
|
-
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
4371
|
-
email: field.scalar(type.String()),
|
|
4372
|
-
username: field.scalar(type.String()).optional(),
|
|
4373
|
-
name: field.scalar(type.String()).optional(),
|
|
4374
|
-
},
|
|
4375
|
-
relations: {
|
|
4376
|
-
posts: rel.hasMany('Post', { from: 'id', to: 'authorId' }),
|
|
4377
|
-
},
|
|
4378
|
-
}),
|
|
4379
|
-
|
|
4380
|
-
Post: model('Post', {
|
|
4381
|
-
collection: 'posts',
|
|
4382
|
-
fields: {
|
|
4383
|
-
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
4384
|
-
title: field.scalar(type.String()),
|
|
4385
|
-
content: field.scalar(type.String()).optional(),
|
|
4386
|
-
authorId: field.scalar(type.ObjectId()),
|
|
4387
|
-
},
|
|
4388
|
-
relations: {
|
|
4389
|
-
author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),
|
|
4390
|
-
},
|
|
4391
|
-
}),
|
|
4392
|
-
},
|
|
4393
|
-
}),
|
|
4394
|
-
);
|
|
4395
|
-
`;
|
|
4396
|
-
}
|
|
4397
|
-
function configFile(target, contractPath, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4398
|
-
return `import 'dotenv/config';
|
|
4399
|
-
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
4400
|
-
import { defineConfig as ormConfig } from '${targetEntrypoint(target, "config", resolveImportSpecifier)}';
|
|
4401
|
-
|
|
4402
|
-
export default definePrismaConfig({
|
|
4403
|
-
orm: ormConfig({
|
|
4404
|
-
contract: ${JSON.stringify(contractPath)},
|
|
4405
|
-
db: {
|
|
4406
|
-
connection: process.env['DATABASE_URL']!,
|
|
4407
|
-
},
|
|
4408
|
-
}),
|
|
4409
|
-
});
|
|
4410
|
-
`;
|
|
4411
|
-
}
|
|
4412
|
-
/**
|
|
4413
|
-
* The config for a project whose contract source is its Prisma 7 schema:
|
|
4414
|
-
* `prisma7Schema` beside `defineConfig`, from the same entrypoint, with the
|
|
4415
|
-
* schema path as the user gave it and the emitted artifacts under Prisma 8's
|
|
4416
|
-
* own directory (`output` is the directory; the facade names `contract.json`).
|
|
4417
|
-
*/
|
|
4418
|
-
function prisma7ConfigFile(target, schemaPath, outputDir, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4419
|
-
return `import 'dotenv/config';
|
|
4420
|
-
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
4421
|
-
import { defineConfig as ormConfig, prisma7Schema } from '${targetEntrypoint(target, "config", resolveImportSpecifier)}';
|
|
4422
|
-
|
|
4423
|
-
export default definePrismaConfig({
|
|
4424
|
-
orm: ormConfig({
|
|
4425
|
-
contract: prisma7Schema(${JSON.stringify(schemaPath)}),
|
|
4426
|
-
output: ${JSON.stringify(outputDir)},
|
|
4427
|
-
db: {
|
|
4428
|
-
connection: process.env['DATABASE_URL']!,
|
|
4429
|
-
},
|
|
4430
|
-
}),
|
|
4431
|
-
});
|
|
4432
|
-
`;
|
|
4433
|
-
}
|
|
4434
|
-
function dbFile(target, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
4435
|
-
const runtime = targetEntrypoint(target, "runtime", resolveImportSpecifier);
|
|
4436
|
-
const staticEntry = targetEntrypoint(target, "static", resolveImportSpecifier);
|
|
4437
|
-
const factory = target === "postgres" ? "postgres" : "mongo";
|
|
4438
|
-
return `import 'dotenv/config';
|
|
4439
|
-
import ${factory} from '${runtime}';
|
|
4440
|
-
import { contractFromJson } from '${staticEntry}';
|
|
4441
|
-
import type { Contract } from './contract.d.js';
|
|
4442
|
-
import contractJson from './contract.json' with { type: 'json' };
|
|
4443
|
-
|
|
4444
|
-
export const contract = contractFromJson<Contract>(contractJson);
|
|
4445
|
-
|
|
4446
|
-
export const db = ${factory}({
|
|
4447
|
-
contract,
|
|
4448
|
-
url: process.env['DATABASE_URL']!,
|
|
4449
|
-
});
|
|
4450
|
-
`;
|
|
4451
|
-
}
|
|
4452
|
-
/**
|
|
4453
|
-
* The minimum supported server version for each target. The
|
|
4454
|
-
* authoritative source of truth is the constant each target package
|
|
4455
|
-
* exports from its `server-version` entry point (for example
|
|
4456
|
-
* `POSTGRES_MIN_SERVER_VERSION`) —
|
|
4457
|
-
* this module mirrors those values and an integration test asserts the
|
|
4458
|
-
* two never drift (`test/integration/test/cli.init-min-server-version.test.ts`).
|
|
4459
|
-
*
|
|
4460
|
-
* Bumping a value here in isolation is **not** safe: edit the
|
|
4461
|
-
* corresponding target package's constant first, then mirror here.
|
|
4462
|
-
* The scaffold's `.env.example` and the "Requirements" section of
|
|
4463
|
-
* `prisma-8.md` both read from this constant, so a stale value lies to
|
|
4464
|
-
* every freshly initialised user.
|
|
4465
|
-
*/
|
|
4466
|
-
const MIN_SERVER_VERSION = {
|
|
4467
|
-
postgres: "15",
|
|
4468
|
-
mongo: "8.0"
|
|
4469
|
-
};
|
|
4470
|
-
const TARGET_LABEL = {
|
|
4471
|
-
postgres: "PostgreSQL",
|
|
4472
|
-
mongo: "MongoDB"
|
|
4473
|
-
};
|
|
4474
|
-
/**
|
|
4475
|
-
* Renders the placeholder body shared by `.env` and `.env.example`:
|
|
4476
|
-
* the target-specific connection-string requirement comments and the
|
|
4477
|
-
* commented-shape `DATABASE_URL` line. The output is identical for both
|
|
4478
|
-
* authoring styles — the env file is orthogonal to PSL vs TS schema
|
|
4479
|
-
* authoring.
|
|
4480
|
-
*/
|
|
4481
|
-
function envPlaceholderBody(target) {
|
|
4482
|
-
const label = TARGET_LABEL[target];
|
|
4483
|
-
const minVersion = MIN_SERVER_VERSION[target];
|
|
4484
|
-
const lines = [];
|
|
4485
|
-
lines.push(`# Connection string for ${label}.`);
|
|
4486
|
-
lines.push(`# Requires ${label} >= ${minVersion}.`);
|
|
4487
|
-
lines.push("");
|
|
4488
|
-
if (target === "postgres") lines.push("DATABASE_URL=\"postgresql://user:password@localhost:5432/mydb\"");
|
|
4489
|
-
else {
|
|
4490
|
-
lines.push("# Standalone local mongod / `docker run mongo:8` — no replica set required for first-run queries.");
|
|
4491
|
-
lines.push("# Transactions and change streams need a replica set; add ?replicaSet=... only after initiating one.");
|
|
4492
|
-
lines.push("");
|
|
4493
|
-
lines.push("DATABASE_URL=\"mongodb://user:password@localhost:27017/mydb\"");
|
|
4494
|
-
}
|
|
4495
|
-
lines.push("");
|
|
4496
|
-
return lines.join("\n");
|
|
4497
|
-
}
|
|
4498
|
-
/**
|
|
4499
|
-
* Renders the `.env.example` content for a given target:
|
|
4500
|
-
*
|
|
4501
|
-
* - Carries a "Copy this file to `.env`…" intro that only makes sense
|
|
4502
|
-
* for the example file (the real `.env` is the destination of that
|
|
4503
|
-
* copy and so does not get the same intro).
|
|
4504
|
-
* - Documents the `DATABASE_URL` placeholder in the target's native URL
|
|
4505
|
-
* shape (Postgres: standard `postgresql://`, Mongo: `mongodb://` plus
|
|
4506
|
-
* a `mydb` database segment so the lazy facade has a `dbName`).
|
|
4507
|
-
* - Carries a `# Requires <db> >= <version>` comment so a fresh user
|
|
4508
|
-
* knows the minimum supported server before they first try to connect.
|
|
4509
|
-
*/
|
|
4510
|
-
function envExampleContent(target) {
|
|
4511
|
-
const lines = [];
|
|
4512
|
-
lines.push("# Copy this file to `.env` and replace the placeholder with your real connection string.");
|
|
4513
|
-
lines.push(envPlaceholderBody(target));
|
|
4514
|
-
return lines.join("\n");
|
|
4515
|
-
}
|
|
4516
|
-
/**
|
|
4517
|
-
* Renders the initial `.env` content for `--write-env` / interactive
|
|
4518
|
-
* opt-in. Same placeholder body as `.env.example`, **without** the
|
|
4519
|
-
* example file's "Copy this file to `.env`…" intro: the real `.env` is
|
|
4520
|
-
* the destination of that copy, so the line would lie. Writing this
|
|
4521
|
-
* file is gitignored (`.env` lands in `.gitignore` during init).
|
|
4522
|
-
*/
|
|
4523
|
-
function envFileContent(target) {
|
|
4524
|
-
return envPlaceholderBody(target);
|
|
4525
|
-
}
|
|
4526
4291
|
/** The invocation that finishes what a failed `init` phase started. */
|
|
4527
4292
|
const EMIT_COMMAND = "prisma contract emit";
|
|
4528
4293
|
const DB_SIGN_COMMAND = "prisma db sign";
|
|
@@ -4650,6 +4415,7 @@ function buildInitNextActions(inputs) {
|
|
|
4650
4415
|
}
|
|
4651
4416
|
const DONE_TEXT = "Done. Open prisma-8.md to get started.";
|
|
4652
4417
|
const INCOMPLETE_TEXT = "Scaffold written. Finish the steps above to complete setup.";
|
|
4418
|
+
const NOTHING_WRITTEN_TEXT = "Nothing was written. Finish the steps above, then run `prisma orm init` again.";
|
|
4653
4419
|
function initPresentations(inputs) {
|
|
4654
4420
|
const { document } = inputs;
|
|
4655
4421
|
return {
|
|
@@ -4681,7 +4447,7 @@ function initPresentations(inputs) {
|
|
|
4681
4447
|
} : {
|
|
4682
4448
|
kind: "summary",
|
|
4683
4449
|
status: "warn",
|
|
4684
|
-
text: INCOMPLETE_TEXT
|
|
4450
|
+
text: document.filesWritten.length === 0 ? NOTHING_WRITTEN_TEXT : INCOMPLETE_TEXT
|
|
4685
4451
|
}
|
|
4686
4452
|
],
|
|
4687
4453
|
json: () => document,
|
|
@@ -4730,7 +4496,7 @@ async function emitScaffoldedContract(ctx, overrides = {}) {
|
|
|
4730
4496
|
function firstNonEmpty(preferred, fallback) {
|
|
4731
4497
|
return preferred.trim().length > 0 ? preferred : fallback;
|
|
4732
4498
|
}
|
|
4733
|
-
function isRecord$
|
|
4499
|
+
function isRecord$3(value) {
|
|
4734
4500
|
return typeof value === "object" && value !== null;
|
|
4735
4501
|
}
|
|
4736
4502
|
/**
|
|
@@ -4747,9 +4513,9 @@ function errorFromEnvelope(stdout) {
|
|
|
4747
4513
|
} catch {
|
|
4748
4514
|
continue;
|
|
4749
4515
|
}
|
|
4750
|
-
if (!isRecord$
|
|
4516
|
+
if (!isRecord$3(event) || event["kind"] !== "result" || !isRecord$3(event["envelope"])) continue;
|
|
4751
4517
|
const error = event["envelope"]["error"];
|
|
4752
|
-
if (!isRecord$
|
|
4518
|
+
if (!isRecord$3(error)) continue;
|
|
4753
4519
|
const code = typeof error["code"] === "string" ? error["code"] : void 0;
|
|
4754
4520
|
const summary = typeof error["summary"] === "string" ? error["summary"] : void 0;
|
|
4755
4521
|
const why = typeof error["why"] === "string" ? ` — ${error["why"]}` : "";
|
|
@@ -4763,13 +4529,13 @@ function resolveProjectBin(cwd, overrides) {
|
|
|
4763
4529
|
try {
|
|
4764
4530
|
manifestPath = resolveFromBaseDir(cwd, "prisma/package.json");
|
|
4765
4531
|
} catch (error) {
|
|
4766
|
-
throw new Error(`\`prisma\` is not installed in this project (resolved from ${cwd}; cause: ${causeMessage$
|
|
4532
|
+
throw new Error(`\`prisma\` is not installed in this project (resolved from ${cwd}; cause: ${causeMessage$2(error)})`);
|
|
4767
4533
|
}
|
|
4768
4534
|
let manifest;
|
|
4769
4535
|
try {
|
|
4770
4536
|
manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
4771
4537
|
} catch (error) {
|
|
4772
|
-
throw new Error(`the installed prisma manifest at ${manifestPath} is not valid JSON: ${causeMessage$
|
|
4538
|
+
throw new Error(`the installed prisma manifest at ${manifestPath} is not valid JSON: ${causeMessage$2(error)}`);
|
|
4773
4539
|
}
|
|
4774
4540
|
const bin = manifest !== null && typeof manifest === "object" ? Reflect.get(manifest, "bin") : void 0;
|
|
4775
4541
|
const binEntry = typeof bin === "string" ? bin : bin !== null && typeof bin === "object" ? Reflect.get(bin, "prisma") : void 0;
|
|
@@ -4810,15 +4576,9 @@ function runCaptured(file, args, cwd) {
|
|
|
4810
4576
|
function tail(text) {
|
|
4811
4577
|
return text.trim().split("\n").slice(-20).join("\n");
|
|
4812
4578
|
}
|
|
4813
|
-
function causeMessage$
|
|
4579
|
+
function causeMessage$2(error) {
|
|
4814
4580
|
return error instanceof Error ? error.message : String(error);
|
|
4815
4581
|
}
|
|
4816
|
-
const TARGET_ALIASES = /* @__PURE__ */ new Map([
|
|
4817
|
-
["postgres", "postgres"],
|
|
4818
|
-
["postgresql", "postgres"],
|
|
4819
|
-
["mongo", "mongo"],
|
|
4820
|
-
["mongodb", "mongo"]
|
|
4821
|
-
]);
|
|
4822
4582
|
const AUTHORING_VALUES = /* @__PURE__ */ new Map([
|
|
4823
4583
|
["psl", "psl"],
|
|
4824
4584
|
["typescript", "typescript"],
|
|
@@ -4826,18 +4586,14 @@ const AUTHORING_VALUES = /* @__PURE__ */ new Map([
|
|
|
4826
4586
|
]);
|
|
4827
4587
|
function resolveTarget(value) {
|
|
4828
4588
|
if (value === void 0) return void 0;
|
|
4829
|
-
const mapped =
|
|
4589
|
+
const mapped = findTargetByName(value);
|
|
4830
4590
|
if (mapped === void 0) throw errorInitInvalidFlagValue({
|
|
4831
4591
|
flag: "target",
|
|
4832
4592
|
value,
|
|
4833
|
-
allowed:
|
|
4593
|
+
allowed: TARGET_SHORT_NAMES
|
|
4834
4594
|
});
|
|
4835
4595
|
return mapped;
|
|
4836
4596
|
}
|
|
4837
|
-
/** The target a Prisma 7 `datasource` provider names; `undefined` when Prisma 8 has none for it. */
|
|
4838
|
-
function targetFromProviderName(provider) {
|
|
4839
|
-
return TARGET_ALIASES.get(provider);
|
|
4840
|
-
}
|
|
4841
4597
|
function resolveAuthoring(value) {
|
|
4842
4598
|
if (value === void 0) return void 0;
|
|
4843
4599
|
const mapped = AUTHORING_VALUES.get(value.toLowerCase());
|
|
@@ -4849,6 +4605,17 @@ function resolveAuthoring(value) {
|
|
|
4849
4605
|
return mapped;
|
|
4850
4606
|
}
|
|
4851
4607
|
/**
|
|
4608
|
+
* Refuses a `--schema-path` that no authoring style takes, before `--authoring` is known.
|
|
4609
|
+
*/
|
|
4610
|
+
function rejectSchemaPathNoModeTakes(value) {
|
|
4611
|
+
const ext = extname(value.trim()).toLowerCase();
|
|
4612
|
+
if (ext !== ".prisma" && ext !== ".ts") throw errorInitInvalidFlagValue({
|
|
4613
|
+
flag: "schema-path",
|
|
4614
|
+
value,
|
|
4615
|
+
allowed: ["<file path with .prisma or .ts extension>"]
|
|
4616
|
+
});
|
|
4617
|
+
}
|
|
4618
|
+
/**
|
|
4852
4619
|
* Validates `--schema-path` against the chosen `--authoring` style: PSL
|
|
4853
4620
|
* authoring requires a `.prisma` file and TypeScript authoring requires a
|
|
4854
4621
|
* `.ts` file. Mismatched combinations would silently scaffold PSL content
|
|
@@ -4914,13 +4681,6 @@ function formatAddDevArgs(pm, packages) {
|
|
|
4914
4681
|
...packages
|
|
4915
4682
|
];
|
|
4916
4683
|
}
|
|
4917
|
-
const PRISMA6_ONLY_PROVIDERS = /* @__PURE__ */ new Map([["mongodb", "mongo"]]);
|
|
4918
|
-
/**
|
|
4919
|
-
* The target of a `datasource` provider that exists only up to Prisma 6, which makes its schema a Prisma 6 schema; `undefined` for any other provider.
|
|
4920
|
-
*/
|
|
4921
|
-
function prisma6OnlyTarget(provider) {
|
|
4922
|
-
return provider === void 0 ? void 0 : PRISMA6_ONLY_PROVIDERS.get(provider);
|
|
4923
|
-
}
|
|
4924
4684
|
function runPrisma6(packageManager, args) {
|
|
4925
4685
|
switch (packageManager) {
|
|
4926
4686
|
case "npm": return `npm run prisma6 -- ${args}`;
|
|
@@ -4999,203 +4759,50 @@ function prisma6SideBySideSetup(inputs) {
|
|
|
4999
4759
|
]
|
|
5000
4760
|
};
|
|
5001
4761
|
}
|
|
4762
|
+
function defaultSchemaPath(authoring) {
|
|
4763
|
+
if (authoring === "typescript") return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.ts`;
|
|
4764
|
+
return `${DEFAULT_CONTRACT_SOURCE_DIR}/contract.prisma`;
|
|
4765
|
+
}
|
|
4766
|
+
/** A module name as a single-quoted TypeScript string literal, the quoting the configs use. */
|
|
4767
|
+
function singleQuoted(moduleName) {
|
|
4768
|
+
return `'${moduleName.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
4769
|
+
}
|
|
4770
|
+
function configFile(contractPath, configModule) {
|
|
4771
|
+
return `import 'dotenv/config';
|
|
4772
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
4773
|
+
import { defineConfig as ormConfig } from ${singleQuoted(configModule)};
|
|
4774
|
+
|
|
4775
|
+
export default definePrismaConfig({
|
|
4776
|
+
orm: ormConfig({
|
|
4777
|
+
contract: ${JSON.stringify(contractPath)},
|
|
4778
|
+
db: {
|
|
4779
|
+
connection: process.env['DATABASE_URL']!,
|
|
4780
|
+
},
|
|
4781
|
+
}),
|
|
4782
|
+
});
|
|
4783
|
+
`;
|
|
4784
|
+
}
|
|
5002
4785
|
/**
|
|
5003
|
-
* The
|
|
5004
|
-
* `
|
|
5005
|
-
*
|
|
5006
|
-
*
|
|
5007
|
-
* from a dist-tag (whose `latest` has lagged that version before and broken
|
|
5008
|
-
* the very next command). A CLI without a readable engine entry falls back to
|
|
5009
|
-
* the `next` tag, the release train the CLI itself publishes under.
|
|
5010
|
-
*/
|
|
5011
|
-
function engineDevDependencySpec(cwd) {
|
|
5012
|
-
try {
|
|
5013
|
-
const manifest = JSON.parse(readFileSync(join(cwd, "node_modules", "prisma", "package.json"), "utf-8"));
|
|
5014
|
-
if (typeof manifest === "object" && manifest !== null) for (const field of ["dependencies", "peerDependencies"]) {
|
|
5015
|
-
const block = Reflect.get(manifest, field);
|
|
5016
|
-
if (typeof block === "object" && block !== null) {
|
|
5017
|
-
const engine = Reflect.get(block, "@prisma/cli-engine");
|
|
5018
|
-
if (typeof engine === "string" && engine.length > 0) return `@prisma/cli-engine@${engine}`;
|
|
5019
|
-
}
|
|
5020
|
-
}
|
|
5021
|
-
} catch {}
|
|
5022
|
-
return "@prisma/cli-engine@latest";
|
|
5023
|
-
}
|
|
5024
|
-
/**
|
|
5025
|
-
* Adds the runtime and development dependencies through the engine's package manager. Returns the
|
|
5026
|
-
* first failure it reports, or `undefined` when both installs succeed.
|
|
5027
|
-
*/
|
|
5028
|
-
async function installProjectDependencies(ctx) {
|
|
5029
|
-
for (const [packages, dev] of [[ctx.deps, false], [ctx.devDeps, true]]) {
|
|
5030
|
-
if (packages.length === 0) continue;
|
|
5031
|
-
const installed = await ctx.packages.install({
|
|
5032
|
-
packages,
|
|
5033
|
-
cwd: ctx.cwd,
|
|
5034
|
-
...dev ? { dev } : {}
|
|
5035
|
-
});
|
|
5036
|
-
if (!installed.ok) return installed.failure;
|
|
5037
|
-
}
|
|
5038
|
-
}
|
|
5039
|
-
const importFromProject = async (cwd, specifier) => {
|
|
5040
|
-
let resolved;
|
|
5041
|
-
try {
|
|
5042
|
-
resolved = createRequire(join(cwd, "package.json")).resolve(specifier);
|
|
5043
|
-
} catch {
|
|
5044
|
-
return;
|
|
5045
|
-
}
|
|
5046
|
-
return await import(pathToFileURL(resolved).href);
|
|
5047
|
-
};
|
|
5048
|
-
/** The install before the check failed; nothing else has happened yet. */
|
|
5049
|
-
var Prisma7CheckInstallFailed = class extends Error {
|
|
5050
|
-
failure;
|
|
5051
|
-
target;
|
|
5052
|
-
schemaPath;
|
|
5053
|
-
constructor(failure, target, schemaPath) {
|
|
5054
|
-
super(failure.message);
|
|
5055
|
-
this.failure = failure;
|
|
5056
|
-
this.target = target;
|
|
5057
|
-
this.schemaPath = schemaPath;
|
|
5058
|
-
this.name = "Prisma7CheckInstallFailed";
|
|
5059
|
-
}
|
|
5060
|
-
};
|
|
5061
|
-
/**
|
|
5062
|
-
* Adds the check's undo instruction to an error raised after the check installed packages, such
|
|
5063
|
-
* as the engine's own consent or cancellation errors, which init cannot word itself. An error with
|
|
5064
|
-
* no structured code becomes `CLI.UNEXPECTED`, as it would at the handler boundary.
|
|
5065
|
-
*/
|
|
5066
|
-
function withPackagesAddedAction(error, added) {
|
|
5067
|
-
const engineError = normalizeError(error);
|
|
5068
|
-
return new CliStructuredError$1(engineError.code, engineError.message, {
|
|
5069
|
-
severity: engineError.severity,
|
|
5070
|
-
nextActions: [...engineError.nextActions, chooseAction(packagesAddedAction(added))],
|
|
5071
|
-
diagnostics: engineError.diagnostics,
|
|
5072
|
-
meta: {
|
|
5073
|
-
...engineError.meta,
|
|
5074
|
-
packagesAdded: added.packages
|
|
5075
|
-
},
|
|
5076
|
-
...ifDefined("why", engineError.why),
|
|
5077
|
-
...ifDefined("where", engineError.where),
|
|
5078
|
-
...ifDefined("docsUrl", engineError.docsUrl),
|
|
5079
|
-
cause: error
|
|
5080
|
-
});
|
|
5081
|
-
}
|
|
5082
|
-
/**
|
|
5083
|
-
* Finds out whether the chosen target package can read the Prisma 7 schema before init changes the
|
|
5084
|
-
* project: installs the package and `dotenv` (the packages every init installs), loads the
|
|
5085
|
-
* package's config entrypoint as the project resolves it, and runs its `prisma7Schema` source
|
|
5086
|
-
* without writing. The CLI carries no target code, so the installed package is the only one that
|
|
5087
|
-
* can answer.
|
|
4786
|
+
* The config for a project whose contract source is its Prisma 7 schema:
|
|
4787
|
+
* `prisma7Schema` beside `defineConfig`, from the same module, with the
|
|
4788
|
+
* schema path as the user gave it and the emitted artifacts under Prisma 8's
|
|
4789
|
+
* own directory (`output` is the directory; the target package names `contract.json`).
|
|
5088
4790
|
*/
|
|
5089
|
-
function
|
|
5090
|
-
return
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
});
|
|
5105
|
-
if (installFailure !== void 0) throw new Prisma7CheckInstallFailed(installFailure, target, schemaPath);
|
|
5106
|
-
if (ctx.packageManager === "pnpm") warnings.push(...buildCatalogWarnings(ctx.cwd, deps));
|
|
5107
|
-
installed = deps;
|
|
5108
|
-
const newlyDeclared = deps.filter((dep) => !declaredBefore.has(dep));
|
|
5109
|
-
added = newlyDeclared.length === 0 ? void 0 : {
|
|
5110
|
-
packages: newlyDeclared,
|
|
5111
|
-
removeCommand: formatRemoveCommand(ctx.packageManager, newlyDeclared)
|
|
5112
|
-
};
|
|
5113
|
-
}
|
|
5114
|
-
const undoable = async (step) => {
|
|
5115
|
-
try {
|
|
5116
|
-
return await step();
|
|
5117
|
-
} catch (error) {
|
|
5118
|
-
throw added === void 0 ? error : withPackagesAddedAction(error, added);
|
|
5119
|
-
}
|
|
5120
|
-
};
|
|
5121
|
-
const module = await undoable(() => ctx.importFromProject(ctx.cwd, targetEntrypoint(target, "config", resolveImportSpecifier)));
|
|
5122
|
-
if (module === void 0) {
|
|
5123
|
-
if (!ctx.install) {
|
|
5124
|
-
warnings.push(`Could not check that Prisma 8 can read ${schemaPath}: ${packageName} is not installed. Install the dependencies and run \`prisma contract emit\` to check it.`);
|
|
5125
|
-
return {
|
|
5126
|
-
outcome: "unchecked",
|
|
5127
|
-
packageName,
|
|
5128
|
-
installed,
|
|
5129
|
-
added,
|
|
5130
|
-
warnings
|
|
5131
|
-
};
|
|
5132
|
-
}
|
|
5133
|
-
throw errorInitPrisma7SourceUnavailable({
|
|
5134
|
-
schemaPath,
|
|
5135
|
-
packageName,
|
|
5136
|
-
reason: "not-resolvable",
|
|
5137
|
-
added
|
|
5138
|
-
});
|
|
5139
|
-
}
|
|
5140
|
-
const { defineConfig, prisma7Schema } = module;
|
|
5141
|
-
if (typeof defineConfig !== "function" || typeof prisma7Schema !== "function") return {
|
|
5142
|
-
outcome: "no-source",
|
|
5143
|
-
packageName,
|
|
5144
|
-
installed,
|
|
5145
|
-
added,
|
|
5146
|
-
warnings
|
|
5147
|
-
};
|
|
5148
|
-
const config = await undoable(() => {
|
|
5149
|
-
const section = defineConfig({
|
|
5150
|
-
contract: prisma7Schema(schemaPath),
|
|
5151
|
-
output: DEFAULT_CONTRACT_SOURCE_DIR
|
|
5152
|
-
});
|
|
5153
|
-
const required = requireConfigSections(buildLoadedConfig(isRecord(section) ? section : {}, ctx.cwd), [
|
|
5154
|
-
"family",
|
|
5155
|
-
"target",
|
|
5156
|
-
"adapter",
|
|
5157
|
-
"contract"
|
|
5158
|
-
]);
|
|
5159
|
-
if (!required.ok) throw required.failure;
|
|
5160
|
-
return required.value;
|
|
5161
|
-
});
|
|
5162
|
-
const result = await undoable(() => loadContractSource(config));
|
|
5163
|
-
if (!result.ok) throw errorInitPrisma7SchemaRefused({
|
|
5164
|
-
schemaPath,
|
|
5165
|
-
packageName,
|
|
5166
|
-
summary: result.failure.summary,
|
|
5167
|
-
diagnostics: result.failure.diagnostics,
|
|
5168
|
-
added
|
|
5169
|
-
});
|
|
5170
|
-
return {
|
|
5171
|
-
outcome: "readable",
|
|
5172
|
-
packageName,
|
|
5173
|
-
installed,
|
|
5174
|
-
added,
|
|
5175
|
-
warnings
|
|
5176
|
-
};
|
|
5177
|
-
};
|
|
5178
|
-
}
|
|
5179
|
-
function declaredPackages(cwd) {
|
|
5180
|
-
let manifest;
|
|
5181
|
-
try {
|
|
5182
|
-
manifest = JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
|
|
5183
|
-
} catch {
|
|
5184
|
-
return /* @__PURE__ */ new Set();
|
|
5185
|
-
}
|
|
5186
|
-
if (!isRecord(manifest)) return /* @__PURE__ */ new Set();
|
|
5187
|
-
const names = [
|
|
5188
|
-
"dependencies",
|
|
5189
|
-
"devDependencies",
|
|
5190
|
-
"optionalDependencies"
|
|
5191
|
-
].flatMap((field) => {
|
|
5192
|
-
const section = manifest[field];
|
|
5193
|
-
return isRecord(section) ? Object.keys(section) : [];
|
|
5194
|
-
});
|
|
5195
|
-
return new Set(names);
|
|
5196
|
-
}
|
|
5197
|
-
function isRecord(value) {
|
|
5198
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4791
|
+
function prisma7ConfigFile(schemaPath, outputDir, configModule) {
|
|
4792
|
+
return `import 'dotenv/config';
|
|
4793
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
4794
|
+
import { defineConfig as ormConfig, prisma7Schema } from ${singleQuoted(configModule)};
|
|
4795
|
+
|
|
4796
|
+
export default definePrismaConfig({
|
|
4797
|
+
orm: ormConfig({
|
|
4798
|
+
contract: prisma7Schema(${JSON.stringify(schemaPath)}),
|
|
4799
|
+
output: ${JSON.stringify(outputDir)},
|
|
4800
|
+
db: {
|
|
4801
|
+
connection: process.env['DATABASE_URL']!,
|
|
4802
|
+
},
|
|
4803
|
+
}),
|
|
4804
|
+
});
|
|
4805
|
+
`;
|
|
5199
4806
|
}
|
|
5200
4807
|
/**
|
|
5201
4808
|
* The `.gitattributes` entries written for a freshly initialised project
|
|
@@ -5242,12 +4849,9 @@ const ATTRIBUTE = "linguist-generated";
|
|
|
5242
4849
|
const STORE_GITATTRIBUTES_LINES = [`migrations/snapshots/**/contract.json ${ATTRIBUTE}`, `migrations/snapshots/**/contract.d.ts ${ATTRIBUTE}`];
|
|
5243
4850
|
/**
|
|
5244
4851
|
* Computes the `.gitattributes` lines this scaffold expects to own. Each
|
|
5245
|
-
* line has the shape `<path> linguist-generated`.
|
|
5246
|
-
* is currently unused but accepted for symmetry with the other hygiene
|
|
5247
|
-
* helpers and to leave room for target-specific entries (e.g. a future
|
|
5248
|
-
* family-specific artifact) without a signature break.
|
|
4852
|
+
* line has the shape `<path> linguist-generated`.
|
|
5249
4853
|
*/
|
|
5250
|
-
function requiredGitattributesLines(schemaDir
|
|
4854
|
+
function requiredGitattributesLines(schemaDir) {
|
|
5251
4855
|
const dir = schemaDir === "." ? "" : schemaDir.replace(/\/+$/, "");
|
|
5252
4856
|
const prefix = dir === "" ? "" : `${dir}/`;
|
|
5253
4857
|
return [...ARTIFACT_FILENAMES$1.map((file) => `${prefix}${file} ${ATTRIBUTE}`), ...STORE_GITATTRIBUTES_LINES];
|
|
@@ -5628,9 +5232,9 @@ function findStaleArtifacts(baseDir, schemaDir) {
|
|
|
5628
5232
|
* the caller can skip the write to keep re-init idempotent (FR9.3).
|
|
5629
5233
|
*
|
|
5630
5234
|
* Used by `runInit` for the FR9.2 target-switch path: when the user
|
|
5631
|
-
* re-inits a project
|
|
5632
|
-
*
|
|
5633
|
-
*
|
|
5235
|
+
* re-inits a project with a different `--target`, the previous facade is
|
|
5236
|
+
* removed from `dependencies` so the resulting project depends only on the
|
|
5237
|
+
* chosen target's facade.
|
|
5634
5238
|
*
|
|
5635
5239
|
* Devs/peers/optional dep groups are intentionally *not* touched — the
|
|
5636
5240
|
* facades are only ever in `dependencies` (FR4 / FR7), and broadening
|
|
@@ -5697,135 +5301,27 @@ const AGENT_SKILL_ROOTS = [
|
|
|
5697
5301
|
function legacySkillDirs() {
|
|
5698
5302
|
return AGENT_SKILL_ROOTS.flatMap((root) => RETIRED_SKILL_NAMES.map((name) => `${root}/${name}`));
|
|
5699
5303
|
}
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
}
|
|
5707
|
-
return result;
|
|
5304
|
+
const EXAMPLE_INTRO = "# Copy this file to `.env` and replace the placeholder with your real connection string.";
|
|
5305
|
+
/**
|
|
5306
|
+
* `.env.example`: the target package's placeholder body under an intro that only makes sense for
|
|
5307
|
+
* the example file. The real `.env` is the destination of that copy, so it gets the body alone.
|
|
5308
|
+
*/
|
|
5309
|
+
function envExampleContent(body) {
|
|
5310
|
+
return `${EXAMPLE_INTRO}\n${body}`;
|
|
5708
5311
|
}
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
"dbImportPath",
|
|
5713
|
-
"pkgRun",
|
|
5714
|
-
"pkg",
|
|
5715
|
-
"configEntrypoint",
|
|
5716
|
-
"schemaSample",
|
|
5717
|
-
"requirements"
|
|
5718
|
-
];
|
|
5719
|
-
function quickReferenceMd(target, authoring, schemaPath, pkgRun, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
5720
|
-
const schemaDir = dirname(schemaPath);
|
|
5721
|
-
const pkg = targetPackageName(target, resolveImportSpecifier);
|
|
5722
|
-
const vars = {
|
|
5723
|
-
schemaPath,
|
|
5724
|
-
schemaDir,
|
|
5725
|
-
dbImportPath: `./${schemaDir}/db`,
|
|
5726
|
-
pkgRun,
|
|
5727
|
-
pkg,
|
|
5728
|
-
configEntrypoint: targetEntrypoint(target, "config", resolveImportSpecifier),
|
|
5729
|
-
schemaSample: schemaSample(target, authoring, resolveImportSpecifier),
|
|
5730
|
-
requirements: requirementsBlock(target, pkgRun)
|
|
5731
|
-
};
|
|
5732
|
-
return renderTemplate(`quick-reference-${target}.md`, variables, vars);
|
|
5733
|
-
}
|
|
5734
|
-
/**
|
|
5735
|
-
* Renders the FR8.2 "Requirements" block injected into `prisma-8.md`
|
|
5736
|
-
* (the user-facing quick reference). Sources the minimum server
|
|
5737
|
-
* version from `MIN_SERVER_VERSION` — itself mirrored from each
|
|
5738
|
-
* target package's `server-version` export
|
|
5739
|
-
* (FR8.1).
|
|
5740
|
-
*
|
|
5741
|
-
* The verification command is target-specific — Postgres scaffolds
|
|
5742
|
-
* shouldn't ship Mongo's `db.runCommand` (and vice versa) just because
|
|
5743
|
-
* we couldn't be bothered to branch.
|
|
5312
|
+
/**
|
|
5313
|
+
* The FR8.2 "Requirements" section of `prisma-8.md`: the minimum server the target package
|
|
5314
|
+
* states, and how to check it. Empty when the package states none.
|
|
5744
5315
|
*/
|
|
5745
|
-
function requirementsBlock(
|
|
5316
|
+
function requirementsBlock(label, requirement, pkgRun, canProbe) {
|
|
5317
|
+
if (requirement === void 0) return "";
|
|
5746
5318
|
return [
|
|
5747
5319
|
"## Requirements",
|
|
5748
5320
|
"",
|
|
5749
|
-
`- **${
|
|
5750
|
-
`- The CLI never connects to your database without explicit consent. Pass \`--probe-db\` to \`${pkgRun} orm init\` if you want \`init\` to verify the server version itself.`
|
|
5321
|
+
`- **${label} ${requirement.minVersion} or newer.** Older servers are not supported. Run \`${requirement.checkCommand}\` against your server to verify.`,
|
|
5322
|
+
...canProbe ? [`- The CLI never connects to your database without explicit consent. Pass \`--probe-db\` to \`${pkgRun} orm init\` if you want \`init\` to verify the server version itself.`] : []
|
|
5751
5323
|
].join("\n");
|
|
5752
5324
|
}
|
|
5753
|
-
const prisma7Variables = [
|
|
5754
|
-
"schemaPath",
|
|
5755
|
-
"outputDir",
|
|
5756
|
-
"dbImportPath",
|
|
5757
|
-
"pkgRun",
|
|
5758
|
-
"pkg",
|
|
5759
|
-
"configEntrypoint",
|
|
5760
|
-
"requirements",
|
|
5761
|
-
"prisma7ConfigSentence",
|
|
5762
|
-
"prisma7ConfigRow"
|
|
5763
|
-
];
|
|
5764
|
-
/** The quick reference for a project whose contract source is its Prisma 7 schema. */
|
|
5765
|
-
function prisma7QuickReferenceMd(target, schemaPath, outputDir, pkgRun, prisma7Config, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
5766
|
-
const vars = {
|
|
5767
|
-
schemaPath,
|
|
5768
|
-
outputDir,
|
|
5769
|
-
dbImportPath: `./${outputDir}/db`,
|
|
5770
|
-
pkgRun,
|
|
5771
|
-
pkg: targetPackageName(target, resolveImportSpecifier),
|
|
5772
|
-
configEntrypoint: targetEntrypoint(target, "config", resolveImportSpecifier),
|
|
5773
|
-
requirements: requirementsBlock(target, pkgRun),
|
|
5774
|
-
prisma7ConfigSentence: prisma7Config === void 0 ? "" : ` Prisma 7 reads its own config from \`${prisma7Config}\`.`,
|
|
5775
|
-
prisma7ConfigRow: prisma7Config === void 0 ? "" : `\n| [\`${prisma7Config}\`](${prisma7Config}) | Prisma 7 CLI configuration |`
|
|
5776
|
-
};
|
|
5777
|
-
return renderTemplate("quick-reference-prisma7.md", prisma7Variables, vars);
|
|
5778
|
-
}
|
|
5779
|
-
const sharedVariables = [
|
|
5780
|
-
"projectName",
|
|
5781
|
-
"contractPath",
|
|
5782
|
-
"runDev",
|
|
5783
|
-
"runContractEmit"
|
|
5784
|
-
];
|
|
5785
|
-
const postgresVariables = [
|
|
5786
|
-
...sharedVariables,
|
|
5787
|
-
"runDbInit",
|
|
5788
|
-
"runDbUpdate",
|
|
5789
|
-
"runMigrationPlan",
|
|
5790
|
-
"runMigrate",
|
|
5791
|
-
"runDbSeed"
|
|
5792
|
-
];
|
|
5793
|
-
const mongoVariables = [
|
|
5794
|
-
...sharedVariables,
|
|
5795
|
-
"runDbUp",
|
|
5796
|
-
"runDbDown",
|
|
5797
|
-
"runDbReset",
|
|
5798
|
-
"runMigrationPlan",
|
|
5799
|
-
"runMigrate",
|
|
5800
|
-
"runDbSeed"
|
|
5801
|
-
];
|
|
5802
|
-
function minimalProjectReadmeMd(target, schemaPath, projectName, pm) {
|
|
5803
|
-
const run = (script) => formatRunScriptCommand(pm, script);
|
|
5804
|
-
const shared = {
|
|
5805
|
-
projectName,
|
|
5806
|
-
contractPath: schemaPath,
|
|
5807
|
-
runDev: run("dev"),
|
|
5808
|
-
runContractEmit: run("contract:emit"),
|
|
5809
|
-
runMigrationPlan: run("migration:plan"),
|
|
5810
|
-
runMigrate: run("migrate"),
|
|
5811
|
-
runDbSeed: run("db:seed")
|
|
5812
|
-
};
|
|
5813
|
-
if (target === "mongo") {
|
|
5814
|
-
const vars = {
|
|
5815
|
-
...shared,
|
|
5816
|
-
runDbUp: run("db:up"),
|
|
5817
|
-
runDbDown: run("db:down"),
|
|
5818
|
-
runDbReset: run("db:reset")
|
|
5819
|
-
};
|
|
5820
|
-
return renderTemplate("readme-mongo.md", mongoVariables, vars);
|
|
5821
|
-
}
|
|
5822
|
-
const vars = {
|
|
5823
|
-
...shared,
|
|
5824
|
-
runDbInit: run("db:init"),
|
|
5825
|
-
runDbUpdate: run("db:update")
|
|
5826
|
-
};
|
|
5827
|
-
return renderTemplate("readme-postgres.md", postgresVariables, vars);
|
|
5828
|
-
}
|
|
5829
5325
|
/**
|
|
5830
5326
|
* Compiler options the scaffolded `prisma.config.ts` and `db.ts` need
|
|
5831
5327
|
* to typecheck:
|
|
@@ -6122,47 +5618,53 @@ function hasProjectManifest(cwd) {
|
|
|
6122
5618
|
* user's project byte-identical to how it started.
|
|
6123
5619
|
*/
|
|
6124
5620
|
function planScaffold(ctx) {
|
|
6125
|
-
const { cwd, inputs, packageManager
|
|
5621
|
+
const { cwd, inputs, packageManager } = ctx;
|
|
5622
|
+
const { contribution } = inputs;
|
|
6126
5623
|
const warnings = [];
|
|
6127
5624
|
const source = inputs.contractSource;
|
|
6128
5625
|
const outputDir = source.kind === "prisma7-schema" ? DEFAULT_CONTRACT_SOURCE_DIR : dirname(inputs.schemaPath);
|
|
6129
5626
|
const configContractPath = isAbsolute(inputs.schemaPath) ? inputs.schemaPath : `./${inputs.schemaPath}`;
|
|
6130
5627
|
const runPrefix = formatRunCommand(packageManager, "prisma", "").trimEnd();
|
|
5628
|
+
const requirements = requirementsBlock(contribution.label, contribution.serverRequirement, runPrefix, contribution.probe !== void 0);
|
|
6131
5629
|
const renames = planConfigRename(cwd, inputs, warnings);
|
|
6132
|
-
const files =
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
5630
|
+
const files = [];
|
|
5631
|
+
if (source.kind === "starter") files.push({
|
|
5632
|
+
path: inputs.schemaPath,
|
|
5633
|
+
content: contribution.starterContract(source.authoring)
|
|
5634
|
+
}, {
|
|
5635
|
+
path: CONFIG_FILE,
|
|
5636
|
+
content: configFile(configContractPath, contribution.configModule)
|
|
5637
|
+
}, {
|
|
5638
|
+
path: join(outputDir, "db.ts"),
|
|
5639
|
+
content: contribution.databaseFile()
|
|
5640
|
+
}, {
|
|
5641
|
+
path: QUICK_REFERENCE_FILE,
|
|
5642
|
+
content: contribution.quickReference({
|
|
5643
|
+
mode: source.authoring,
|
|
5644
|
+
schemaPath: inputs.schemaPath,
|
|
5645
|
+
cliCommand: runPrefix,
|
|
5646
|
+
requirements
|
|
5647
|
+
})
|
|
5648
|
+
});
|
|
5649
|
+
else files.push({
|
|
5650
|
+
path: CONFIG_FILE,
|
|
5651
|
+
content: prisma7ConfigFile(source.schemaPath, outputDir, contribution.configModule)
|
|
5652
|
+
}, {
|
|
5653
|
+
path: join(outputDir, "db.ts"),
|
|
5654
|
+
content: contribution.databaseFile()
|
|
5655
|
+
}, {
|
|
5656
|
+
path: QUICK_REFERENCE_FILE,
|
|
5657
|
+
content: source.quickReference({
|
|
5658
|
+
schemaPath: source.schemaPath,
|
|
5659
|
+
outputDir,
|
|
5660
|
+
cliCommand: runPrefix,
|
|
5661
|
+
requirements,
|
|
5662
|
+
prisma7Config: source.prisma7Config
|
|
5663
|
+
})
|
|
5664
|
+
});
|
|
6163
5665
|
files.push({
|
|
6164
5666
|
path: ENV_EXAMPLE_FILE,
|
|
6165
|
-
content: envExampleContent(
|
|
5667
|
+
content: envExampleContent(contribution.envExample())
|
|
6166
5668
|
});
|
|
6167
5669
|
if (existsSync(join(cwd, ENV_EXAMPLE_FILE))) warnings.push(`${ENV_EXAMPLE_FILE} already existed and was replaced with the Prisma ORM template.`);
|
|
6168
5670
|
const filesToDelete = inputs.reinit ? [...findStaleArtifacts(cwd, outputDir)] : [];
|
|
@@ -6170,7 +5672,7 @@ function planScaffold(ctx) {
|
|
|
6170
5672
|
if (inputs.writeEnv) if (existsSync(join(cwd, ".env"))) warnings.push(".env already exists; leaving it untouched. Compare with .env.example for any new keys.");
|
|
6171
5673
|
else files.push({
|
|
6172
5674
|
path: ".env",
|
|
6173
|
-
content:
|
|
5675
|
+
content: contribution.envExample()
|
|
6174
5676
|
});
|
|
6175
5677
|
const manifestPath = join(cwd, "package.json");
|
|
6176
5678
|
const manifestExisted = existsSync(manifestPath);
|
|
@@ -6252,7 +5754,7 @@ function planScaffold(ctx) {
|
|
|
6252
5754
|
content: nextGitignore
|
|
6253
5755
|
});
|
|
6254
5756
|
const gitattributesPath = join(cwd, ".gitattributes");
|
|
6255
|
-
const nextGitattributes = mergeGitattributes(existsSync(gitattributesPath) ? readFileSync(gitattributesPath, "utf-8") : void 0, requiredGitattributesLines(outputDir
|
|
5757
|
+
const nextGitattributes = mergeGitattributes(existsSync(gitattributesPath) ? readFileSync(gitattributesPath, "utf-8") : void 0, requiredGitattributesLines(outputDir));
|
|
6256
5758
|
if (nextGitattributes !== null) files.push({
|
|
6257
5759
|
path: ".gitattributes",
|
|
6258
5760
|
content: nextGitattributes
|
|
@@ -6261,12 +5763,17 @@ function planScaffold(ctx) {
|
|
|
6261
5763
|
path: "package.json",
|
|
6262
5764
|
content: manifestContent
|
|
6263
5765
|
});
|
|
6264
|
-
|
|
5766
|
+
const { readme } = contribution;
|
|
5767
|
+
if (source.kind === "starter" && readme !== void 0 && existsSync(join(cwd, "src/index.ts"))) if (existsSync(join(cwd, "README.md"))) warnings.push("README.md already exists; leaving it untouched.");
|
|
6265
5768
|
else {
|
|
6266
5769
|
const declaredName = parsedManifest !== null && typeof parsedManifest["name"] === "string" ? parsedManifest["name"] : basename(cwd);
|
|
6267
5770
|
files.push({
|
|
6268
5771
|
path: "README.md",
|
|
6269
|
-
content:
|
|
5772
|
+
content: readme({
|
|
5773
|
+
projectName: sanitisePackageName(declaredName),
|
|
5774
|
+
contractPath: inputs.schemaPath,
|
|
5775
|
+
runScript: (script) => formatRunScriptCommand(packageManager, script)
|
|
5776
|
+
})
|
|
6270
5777
|
});
|
|
6271
5778
|
}
|
|
6272
5779
|
return {
|
|
@@ -6308,11 +5815,7 @@ function planConfigRename(cwd, inputs, warnings) {
|
|
|
6308
5815
|
* write that fails partway names the files that already landed.
|
|
6309
5816
|
*/
|
|
6310
5817
|
function scaffoldProject(ctx) {
|
|
6311
|
-
const
|
|
6312
|
-
const plan = planScaffold({
|
|
6313
|
-
...ctx,
|
|
6314
|
-
resolveImportSpecifier
|
|
6315
|
-
});
|
|
5818
|
+
const plan = planScaffold(ctx);
|
|
6316
5819
|
const filesWritten = [];
|
|
6317
5820
|
const filesDeleted = [];
|
|
6318
5821
|
const filesRenamed = [];
|
|
@@ -6374,11 +5877,443 @@ function scaffoldProject(ctx) {
|
|
|
6374
5877
|
scriptsRewritten: plan.scriptsRewritten,
|
|
6375
5878
|
warnings: plan.warnings,
|
|
6376
5879
|
notes,
|
|
6377
|
-
hasTypesNode: plan.hasTypesNode
|
|
6378
|
-
|
|
5880
|
+
hasTypesNode: plan.hasTypesNode
|
|
5881
|
+
};
|
|
5882
|
+
}
|
|
5883
|
+
/**
|
|
5884
|
+
* The engine dependency spec a fresh scaffold installs. The scaffolded
|
|
5885
|
+
* `prisma.config.ts` imports `definePrismaConfig` from `@prisma/cli-engine`, and the
|
|
5886
|
+
* installed `prisma` names the exact engine version it runs against — so
|
|
5887
|
+
* the spec is read from the manifest the install just placed, never guessed
|
|
5888
|
+
* from a dist-tag (whose `latest` has lagged that version before and broken
|
|
5889
|
+
* the very next command). A CLI without a readable engine entry falls back to
|
|
5890
|
+
* the `next` tag, the release train the CLI itself publishes under.
|
|
5891
|
+
*/
|
|
5892
|
+
function engineDevDependencySpec(cwd) {
|
|
5893
|
+
try {
|
|
5894
|
+
const manifest = JSON.parse(readFileSync(join(cwd, "node_modules", "prisma", "package.json"), "utf-8"));
|
|
5895
|
+
if (typeof manifest === "object" && manifest !== null) for (const field of ["dependencies", "peerDependencies"]) {
|
|
5896
|
+
const block = Reflect.get(manifest, field);
|
|
5897
|
+
if (typeof block === "object" && block !== null) {
|
|
5898
|
+
const engine = Reflect.get(block, "@prisma/cli-engine");
|
|
5899
|
+
if (typeof engine === "string" && engine.length > 0) return `@prisma/cli-engine@${engine}`;
|
|
5900
|
+
}
|
|
5901
|
+
}
|
|
5902
|
+
} catch {}
|
|
5903
|
+
return "@prisma/cli-engine@latest";
|
|
5904
|
+
}
|
|
5905
|
+
/**
|
|
5906
|
+
* Adds the runtime and development dependencies through the engine's package manager. Returns the
|
|
5907
|
+
* first failure it reports, or `undefined` when both installs succeed.
|
|
5908
|
+
*/
|
|
5909
|
+
async function installProjectDependencies(ctx) {
|
|
5910
|
+
for (const [packages, dev] of [[ctx.deps, false], [ctx.devDeps, true]]) {
|
|
5911
|
+
if (packages.length === 0) continue;
|
|
5912
|
+
const installed = await ctx.packages.install({
|
|
5913
|
+
packages,
|
|
5914
|
+
cwd: ctx.cwd,
|
|
5915
|
+
...dev ? { dev } : {}
|
|
5916
|
+
});
|
|
5917
|
+
if (!installed.ok) return installed.failure;
|
|
5918
|
+
}
|
|
5919
|
+
}
|
|
5920
|
+
/** The command that evaluates `script` as an ES module with `argument` last in `process.argv`. */
|
|
5921
|
+
function resolverChildCommand(versions, execPath, script, argument) {
|
|
5922
|
+
if (versions["deno"] !== void 0) return {
|
|
5923
|
+
command: execPath,
|
|
5924
|
+
args: [
|
|
5925
|
+
"eval",
|
|
5926
|
+
script,
|
|
5927
|
+
"--",
|
|
5928
|
+
argument
|
|
5929
|
+
]
|
|
5930
|
+
};
|
|
5931
|
+
return {
|
|
5932
|
+
command: execPath,
|
|
5933
|
+
args: [
|
|
5934
|
+
"--input-type=module",
|
|
5935
|
+
"-e",
|
|
5936
|
+
script,
|
|
5937
|
+
"--",
|
|
5938
|
+
argument
|
|
5939
|
+
]
|
|
5940
|
+
};
|
|
5941
|
+
}
|
|
5942
|
+
const ANSWER_START = "\0prisma-resolution-start\0";
|
|
5943
|
+
const ANSWER_END = "\0prisma-resolution-end\0";
|
|
5944
|
+
/**
|
|
5945
|
+
* Asks a child, started in the project folder, to resolve the specifier with
|
|
5946
|
+
* `import.meta.resolve`, so the project's own resolution, conditions and all, decides. The answer
|
|
5947
|
+
* sits between fixed markers, so output from a `NODE_OPTIONS` preload cannot be mistaken for it.
|
|
5948
|
+
*/
|
|
5949
|
+
const RESOLVE_IN_PROJECT = `
|
|
5950
|
+
const answer = (value) => process.stdout.write(${JSON.stringify(ANSWER_START)} + JSON.stringify(value) + ${JSON.stringify(ANSWER_END)});
|
|
5951
|
+
try {
|
|
5952
|
+
answer({ url: import.meta.resolve(process.argv.at(-1)) });
|
|
5953
|
+
} catch (error) {
|
|
5954
|
+
answer({ code: error?.code, message: String(error?.message ?? error) });
|
|
5955
|
+
}`;
|
|
5956
|
+
const nodeResolution = type({ url: "string" }).or({
|
|
5957
|
+
"code?": "string",
|
|
5958
|
+
message: "string"
|
|
5959
|
+
});
|
|
5960
|
+
function answerIn(stdout) {
|
|
5961
|
+
const start = stdout.lastIndexOf(ANSWER_START);
|
|
5962
|
+
const end = stdout.lastIndexOf(ANSWER_END);
|
|
5963
|
+
return start === -1 || end < start ? void 0 : stdout.slice(start + 25, end);
|
|
5964
|
+
}
|
|
5965
|
+
/**
|
|
5966
|
+
* The child runs on the runtime running the CLI. Node, Bun and Deno each load an exported module
|
|
5967
|
+
* and report a missing package the same way, but report a subpath the package does not export
|
|
5968
|
+
* differently: Node sets `ERR_PACKAGE_PATH_NOT_EXPORTED`, Bun sets `ERR_MODULE_NOT_FOUND` and Deno
|
|
5969
|
+
* sets no code. Under Bun and Deno that case is therefore `unloadable`, not `not-exported`.
|
|
5970
|
+
*/
|
|
5971
|
+
function resolveWithNode(cwd, specifier) {
|
|
5972
|
+
const { command: runtime, args } = resolverChildCommand(process.versions, process.execPath, RESOLVE_IN_PROJECT, specifier);
|
|
5973
|
+
const child = spawnSync(runtime, args, {
|
|
5974
|
+
cwd,
|
|
5975
|
+
encoding: "utf-8"
|
|
5976
|
+
});
|
|
5977
|
+
const command = `${process.execPath} resolving ${specifier} in ${cwd}`;
|
|
5978
|
+
if (child.error !== void 0) return { failed: new Error(`${command} could not start`, { cause: child.error }) };
|
|
5979
|
+
if (child.status !== 0) return { failed: /* @__PURE__ */ new Error(`${command} exited with ${child.status ?? child.signal}: ${child.stderr}`) };
|
|
5980
|
+
const answer = answerIn(child.stdout);
|
|
5981
|
+
let parsed;
|
|
5982
|
+
try {
|
|
5983
|
+
parsed = answer === void 0 ? void 0 : JSON.parse(answer);
|
|
5984
|
+
} catch {
|
|
5985
|
+
parsed = void 0;
|
|
5986
|
+
}
|
|
5987
|
+
const resolution = nodeResolution(parsed);
|
|
5988
|
+
if (resolution instanceof type.errors) return { failed: /* @__PURE__ */ new Error(`${command} gave no answer it could read: ${child.stdout}`) };
|
|
5989
|
+
return resolution;
|
|
5990
|
+
}
|
|
5991
|
+
function errorCode(error) {
|
|
5992
|
+
return error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
5993
|
+
}
|
|
5994
|
+
/** The package a bare specifier names: `@scope/name` or `name`. */
|
|
5995
|
+
function packageOf(specifier) {
|
|
5996
|
+
return specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
5997
|
+
}
|
|
5998
|
+
function isRecord$2(value) {
|
|
5999
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6000
|
+
}
|
|
6001
|
+
/**
|
|
6002
|
+
* The `package.json` of `name` in the nearest `node_modules` from `cwd` upwards, where Node looks
|
|
6003
|
+
* for a bare specifier. `module.findPackageJSON` does this too, but Bun and Deno do not have it.
|
|
6004
|
+
*/
|
|
6005
|
+
function installedManifest(cwd, name) {
|
|
6006
|
+
for (let dir = cwd;; dir = dirname(dir)) {
|
|
6007
|
+
const candidate = join(dir, "node_modules", name, "package.json");
|
|
6008
|
+
if (existsSync(candidate)) return candidate;
|
|
6009
|
+
if (dirname(dir) === dir) return;
|
|
6010
|
+
}
|
|
6011
|
+
}
|
|
6012
|
+
function resolveFromProject(cwd, specifier) {
|
|
6013
|
+
const manifestPath = installedManifest(cwd, packageOf(specifier));
|
|
6014
|
+
if (manifestPath === void 0) return { kind: "not-installed" };
|
|
6015
|
+
let manifest;
|
|
6016
|
+
try {
|
|
6017
|
+
manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
6018
|
+
} catch (cause) {
|
|
6019
|
+
return {
|
|
6020
|
+
kind: "unreadable",
|
|
6021
|
+
cause: new Error(`${manifestPath} cannot be read as JSON`, { cause })
|
|
6022
|
+
};
|
|
6023
|
+
}
|
|
6024
|
+
if (!isRecord$2(manifest) || manifest["exports"] === void 0) try {
|
|
6025
|
+
return {
|
|
6026
|
+
kind: "resolved",
|
|
6027
|
+
path: createRequire(manifestPath).resolve(specifier)
|
|
6028
|
+
};
|
|
6029
|
+
} catch (error) {
|
|
6030
|
+
if (errorCode(error) === "MODULE_NOT_FOUND") return { kind: "not-exported" };
|
|
6031
|
+
throw error;
|
|
6032
|
+
}
|
|
6033
|
+
const resolved = resolveWithNode(cwd, specifier);
|
|
6034
|
+
if ("failed" in resolved) return {
|
|
6035
|
+
kind: "unreadable",
|
|
6036
|
+
cause: resolved.failed
|
|
6037
|
+
};
|
|
6038
|
+
if ("url" in resolved) return {
|
|
6039
|
+
kind: "resolved",
|
|
6040
|
+
path: fileURLToPath(resolved.url)
|
|
6379
6041
|
};
|
|
6042
|
+
if (resolved.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return { kind: "not-exported" };
|
|
6043
|
+
return {
|
|
6044
|
+
kind: "unreadable",
|
|
6045
|
+
cause: Object.assign(new Error(resolved.message), { code: resolved.code })
|
|
6046
|
+
};
|
|
6047
|
+
}
|
|
6048
|
+
/** Whether the project at `cwd` has the package `name` where Node would find it. */
|
|
6049
|
+
function isInstalledInProject(cwd, name) {
|
|
6050
|
+
return installedManifest(cwd, name) !== void 0;
|
|
6051
|
+
}
|
|
6052
|
+
/**
|
|
6053
|
+
* Resolves with the import conditions, so a package that exports a module only under `import`
|
|
6054
|
+
* loads. A package the project does not have is `not-installed`; one that does not export the
|
|
6055
|
+
* subpath is `not-exported`; an export whose file is missing, or a module that throws while it
|
|
6056
|
+
* loads, is `unloadable` with the cause.
|
|
6057
|
+
*/
|
|
6058
|
+
const importFromProject = async (cwd, specifier) => {
|
|
6059
|
+
const resolution = resolveFromProject(cwd, specifier);
|
|
6060
|
+
if (resolution.kind === "unreadable") return {
|
|
6061
|
+
kind: "unloadable",
|
|
6062
|
+
cause: resolution.cause
|
|
6063
|
+
};
|
|
6064
|
+
if (resolution.kind !== "resolved") return resolution;
|
|
6065
|
+
if (!existsSync(resolution.path)) return {
|
|
6066
|
+
kind: "unloadable",
|
|
6067
|
+
cause: /* @__PURE__ */ new Error(`${specifier} resolves to ${resolution.path}, which does not exist`)
|
|
6068
|
+
};
|
|
6069
|
+
try {
|
|
6070
|
+
return {
|
|
6071
|
+
kind: "loaded",
|
|
6072
|
+
module: await import(pathToFileURL(resolution.path).href)
|
|
6073
|
+
};
|
|
6074
|
+
} catch (cause) {
|
|
6075
|
+
return {
|
|
6076
|
+
kind: "unloadable",
|
|
6077
|
+
cause
|
|
6078
|
+
};
|
|
6079
|
+
}
|
|
6080
|
+
};
|
|
6081
|
+
const InitContributionSchema = type({
|
|
6082
|
+
label: "string",
|
|
6083
|
+
configModule: /\S/,
|
|
6084
|
+
peerPackages: "string[]",
|
|
6085
|
+
authoringModes: type("'psl'|'typescript'").array().atLeastLength(1),
|
|
6086
|
+
starterContract: "Function",
|
|
6087
|
+
contractSample: "Function",
|
|
6088
|
+
databaseFile: "Function",
|
|
6089
|
+
envExample: "Function",
|
|
6090
|
+
quickReference: "Function",
|
|
6091
|
+
"readme?": "Function",
|
|
6092
|
+
"serverRequirement?": {
|
|
6093
|
+
minVersion: "string",
|
|
6094
|
+
checkCommand: "string"
|
|
6095
|
+
},
|
|
6096
|
+
"probe?": "Function",
|
|
6097
|
+
"prisma7QuickReference?": "Function"
|
|
6098
|
+
});
|
|
6099
|
+
/**
|
|
6100
|
+
* Checks the members' presence and the data members' shapes. The functions' signatures cannot be
|
|
6101
|
+
* checked at run time; the package's own `satisfies InitContribution` checks them when it builds.
|
|
6102
|
+
*/
|
|
6103
|
+
function isInitContribution(value) {
|
|
6104
|
+
return !(InitContributionSchema(value) instanceof type.errors);
|
|
6105
|
+
}
|
|
6106
|
+
function contributionProblems(value) {
|
|
6107
|
+
const checked = InitContributionSchema(value);
|
|
6108
|
+
return checked instanceof type.errors ? checked.summary : "its shape is wrong";
|
|
6109
|
+
}
|
|
6110
|
+
function causeMessage$1(cause) {
|
|
6111
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
6112
|
+
}
|
|
6113
|
+
/**
|
|
6114
|
+
* Adds the instruction to undo what init installed to an error raised after the install, such as
|
|
6115
|
+
* the engine's own consent or cancellation errors, which init cannot word itself. An error with
|
|
6116
|
+
* no structured code becomes `CLI.UNEXPECTED`, as it would at the handler boundary.
|
|
6117
|
+
*/
|
|
6118
|
+
function withPackagesAddedAction(error, added, reason) {
|
|
6119
|
+
const engineError = normalizeError(error);
|
|
6120
|
+
return new CliStructuredError$1(engineError.code, engineError.message, {
|
|
6121
|
+
severity: engineError.severity,
|
|
6122
|
+
nextActions: [...engineError.nextActions, chooseAction(packagesAddedAction(added, reason))],
|
|
6123
|
+
diagnostics: engineError.diagnostics,
|
|
6124
|
+
meta: {
|
|
6125
|
+
...engineError.meta,
|
|
6126
|
+
packagesAdded: added.packages
|
|
6127
|
+
},
|
|
6128
|
+
...ifDefined("why", engineError.why),
|
|
6129
|
+
...ifDefined("where", engineError.where),
|
|
6130
|
+
...ifDefined("docsUrl", engineError.docsUrl),
|
|
6131
|
+
cause: error
|
|
6132
|
+
});
|
|
6133
|
+
}
|
|
6134
|
+
function installCommand(packageManager, packages) {
|
|
6135
|
+
return [packageManager, ...formatAddArgs(packageManager, [...packages])].join(" ");
|
|
6136
|
+
}
|
|
6137
|
+
/**
|
|
6138
|
+
* The target package was installed, then could not be used. The caller adds the instruction to
|
|
6139
|
+
* undo the install, because only it knows why it installed the package.
|
|
6140
|
+
*/
|
|
6141
|
+
var TargetPackageRefusedAfterInstall = class extends Error {
|
|
6142
|
+
cause;
|
|
6143
|
+
added;
|
|
6144
|
+
constructor(cause, added) {
|
|
6145
|
+
super(cause instanceof Error ? cause.message : String(cause));
|
|
6146
|
+
this.cause = cause;
|
|
6147
|
+
this.added = added;
|
|
6148
|
+
this.name = "TargetPackageRefusedAfterInstall";
|
|
6149
|
+
}
|
|
6150
|
+
};
|
|
6151
|
+
/** The install of the target package failed; nothing else has happened yet. */
|
|
6152
|
+
var TargetPackageInstallFailed = class extends Error {
|
|
6153
|
+
failure;
|
|
6154
|
+
constructor(failure) {
|
|
6155
|
+
super(failure.message);
|
|
6156
|
+
this.failure = failure;
|
|
6157
|
+
this.name = "TargetPackageInstallFailed";
|
|
6158
|
+
}
|
|
6159
|
+
};
|
|
6160
|
+
/**
|
|
6161
|
+
* Installs the target package with `dotenv`, the package every init installs, and the driver
|
|
6162
|
+
* packages the caller names, leaving out those the project already declares, then loads the
|
|
6163
|
+
* package's init contribution from the project. Under `--skip-install` the package must already be
|
|
6164
|
+
* installed. Each refusal happens before any file is written.
|
|
6165
|
+
*/
|
|
6166
|
+
function createTargetPackagePreparation(ctx) {
|
|
6167
|
+
return async (packageName, peerPackages) => {
|
|
6168
|
+
rejectUnparseableManifest(ctx.cwd);
|
|
6169
|
+
const warnings = [];
|
|
6170
|
+
let installed = [];
|
|
6171
|
+
let added;
|
|
6172
|
+
let ranCommand;
|
|
6173
|
+
if (ctx.install) {
|
|
6174
|
+
const declaredBefore = declaredPackages(ctx.cwd);
|
|
6175
|
+
const targetInPlace = declaredBefore.has(packageName) && isInstalledInProject(ctx.cwd, packageName);
|
|
6176
|
+
const deps = [...targetInPlace ? [] : [packageName], ...["dotenv", ...peerPackages].filter((dep) => !declaredBefore.has(dep))];
|
|
6177
|
+
const installFailure = await installProjectDependencies({
|
|
6178
|
+
packages: ctx.packages,
|
|
6179
|
+
cwd: ctx.cwd,
|
|
6180
|
+
deps,
|
|
6181
|
+
devDeps: []
|
|
6182
|
+
});
|
|
6183
|
+
if (installFailure !== void 0) throw new TargetPackageInstallFailed(installFailure);
|
|
6184
|
+
if (ctx.packageManager === "pnpm") warnings.push(...buildCatalogWarnings(ctx.cwd, deps));
|
|
6185
|
+
installed = targetInPlace ? [packageName, ...deps] : deps;
|
|
6186
|
+
ranCommand = deps.length === 0 ? void 0 : installCommand(ctx.packageManager, deps);
|
|
6187
|
+
added = manifestChanges(ctx.packageManager, declaredBefore, declaredPackages(ctx.cwd));
|
|
6188
|
+
}
|
|
6189
|
+
try {
|
|
6190
|
+
return {
|
|
6191
|
+
contribution: await loadContribution(ctx, packageName, peerPackages, ranCommand),
|
|
6192
|
+
installed,
|
|
6193
|
+
added,
|
|
6194
|
+
warnings
|
|
6195
|
+
};
|
|
6196
|
+
} catch (error) {
|
|
6197
|
+
throw added === void 0 ? error : new TargetPackageRefusedAfterInstall(error, added);
|
|
6198
|
+
}
|
|
6199
|
+
};
|
|
6200
|
+
}
|
|
6201
|
+
async function loadContribution(ctx, packageName, peerPackages, ranCommand) {
|
|
6202
|
+
const entrypoint = await ctx.importFromProject(ctx.cwd, `${packageName}/init`);
|
|
6203
|
+
switch (entrypoint.kind) {
|
|
6204
|
+
case "not-installed": throw errorInitTargetPackageNotInstalled({
|
|
6205
|
+
packageName,
|
|
6206
|
+
installCommand: installCommand(ctx.packageManager, [packageName, ...peerPackages]),
|
|
6207
|
+
ranCommand
|
|
6208
|
+
});
|
|
6209
|
+
case "not-exported": throw errorInitContributionUnavailable({
|
|
6210
|
+
packageName,
|
|
6211
|
+
reason: "no-entrypoint",
|
|
6212
|
+
detail: void 0
|
|
6213
|
+
});
|
|
6214
|
+
case "unloadable": throw errorInitContributionUnavailable({
|
|
6215
|
+
packageName,
|
|
6216
|
+
reason: "unloadable",
|
|
6217
|
+
detail: causeMessage$1(entrypoint.cause)
|
|
6218
|
+
});
|
|
6219
|
+
case "loaded": break;
|
|
6220
|
+
}
|
|
6221
|
+
const contribution = entrypoint.module["default"];
|
|
6222
|
+
if (!isInitContribution(contribution)) throw errorInitContributionUnavailable({
|
|
6223
|
+
packageName,
|
|
6224
|
+
reason: "invalid-shape",
|
|
6225
|
+
detail: contributionProblems(contribution)
|
|
6226
|
+
});
|
|
6227
|
+
return contribution;
|
|
6228
|
+
}
|
|
6229
|
+
/**
|
|
6230
|
+
* The package manager and the module resolver both read `package.json`, so a malformed one is
|
|
6231
|
+
* reported as what it is before either runs.
|
|
6232
|
+
*/
|
|
6233
|
+
function rejectUnparseableManifest(cwd) {
|
|
6234
|
+
const manifestPath = join(cwd, "package.json");
|
|
6235
|
+
if (!existsSync(manifestPath)) return;
|
|
6236
|
+
try {
|
|
6237
|
+
JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
6238
|
+
} catch (error) {
|
|
6239
|
+
if (error instanceof SyntaxError) throw errorInitInvalidManifest({
|
|
6240
|
+
path: "package.json",
|
|
6241
|
+
cause: error.message
|
|
6242
|
+
});
|
|
6243
|
+
throw error;
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
/**
|
|
6247
|
+
* What the install changed in `package.json`, read from the file, since a package manager can
|
|
6248
|
+
* exit successfully and declare nothing; `undefined` when it changed nothing.
|
|
6249
|
+
*/
|
|
6250
|
+
function manifestChanges(packageManager, before, after) {
|
|
6251
|
+
const packages = [...after.keys()].filter((name) => !before.has(name));
|
|
6252
|
+
const rewritten = [...before].flatMap(([name, range]) => {
|
|
6253
|
+
const now = after.get(name);
|
|
6254
|
+
return now !== void 0 && now !== range ? [{
|
|
6255
|
+
name,
|
|
6256
|
+
before: range
|
|
6257
|
+
}] : [];
|
|
6258
|
+
});
|
|
6259
|
+
if (packages.length === 0 && rewritten.length === 0) return;
|
|
6260
|
+
return {
|
|
6261
|
+
packages,
|
|
6262
|
+
removeCommand: formatRemoveCommand(packageManager, packages),
|
|
6263
|
+
rewritten
|
|
6264
|
+
};
|
|
6265
|
+
}
|
|
6266
|
+
/** Every package the project's `package.json` declares, in any dependency field, with its range. */
|
|
6267
|
+
function declaredPackages(cwd) {
|
|
6268
|
+
let manifest;
|
|
6269
|
+
try {
|
|
6270
|
+
manifest = JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
|
|
6271
|
+
} catch {
|
|
6272
|
+
return /* @__PURE__ */ new Map();
|
|
6273
|
+
}
|
|
6274
|
+
if (!isRecord$1(manifest)) return /* @__PURE__ */ new Map();
|
|
6275
|
+
const entries = [
|
|
6276
|
+
"dependencies",
|
|
6277
|
+
"devDependencies",
|
|
6278
|
+
"optionalDependencies",
|
|
6279
|
+
"peerDependencies"
|
|
6280
|
+
].flatMap((field) => {
|
|
6281
|
+
const section = manifest[field];
|
|
6282
|
+
return isRecord$1(section) ? Object.entries(section).map(([name, range]) => [name, String(range)]) : [];
|
|
6283
|
+
});
|
|
6284
|
+
return new Map(entries);
|
|
6285
|
+
}
|
|
6286
|
+
function isRecord$1(value) {
|
|
6287
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6288
|
+
}
|
|
6289
|
+
/**
|
|
6290
|
+
* The install of the target package failed before anything was written. Carries what the output
|
|
6291
|
+
* document reports: on the starter path the authoring and schema path come from the flags, since
|
|
6292
|
+
* the questions that settle them come after the install.
|
|
6293
|
+
*/
|
|
6294
|
+
var InitInstallFailedBeforeWriting = class extends Error {
|
|
6295
|
+
failure;
|
|
6296
|
+
target;
|
|
6297
|
+
authoring;
|
|
6298
|
+
schemaPath;
|
|
6299
|
+
constructor(failure, target, authoring, schemaPath) {
|
|
6300
|
+
super(failure.message);
|
|
6301
|
+
this.failure = failure;
|
|
6302
|
+
this.target = target;
|
|
6303
|
+
this.authoring = authoring;
|
|
6304
|
+
this.schemaPath = schemaPath;
|
|
6305
|
+
this.name = "InitInstallFailedBeforeWriting";
|
|
6306
|
+
}
|
|
6307
|
+
};
|
|
6308
|
+
async function prepareTarget(prepareTargetPackage, target, report, installReason) {
|
|
6309
|
+
try {
|
|
6310
|
+
return await prepareTargetPackage(target.packageName, target.peerPackages);
|
|
6311
|
+
} catch (error) {
|
|
6312
|
+
if (error instanceof TargetPackageRefusedAfterInstall) throw withPackagesAddedAction(error.cause, error.added, installReason);
|
|
6313
|
+
if (error instanceof TargetPackageInstallFailed) throw new InitInstallFailedBeforeWriting(error.failure, target, report.authoring, report.schemaPath);
|
|
6314
|
+
throw error;
|
|
6315
|
+
}
|
|
6380
6316
|
}
|
|
6381
|
-
const REQUIRED_FLAG_PROMPTS = /* @__PURE__ */ new Set(["target", "authoring"]);
|
|
6382
6317
|
function formatFileList(files) {
|
|
6383
6318
|
const last = files.at(-1) ?? "";
|
|
6384
6319
|
return files.length <= 1 ? last : `${files.slice(0, -1).join(", ")} and ${last}`;
|
|
@@ -6412,22 +6347,27 @@ function consentToken(cwd) {
|
|
|
6412
6347
|
return name.length > 0 ? name : cwd.trim();
|
|
6413
6348
|
}
|
|
6414
6349
|
async function askTarget(prompt) {
|
|
6415
|
-
|
|
6416
|
-
value:
|
|
6417
|
-
label:
|
|
6418
|
-
}
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
}
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6350
|
+
const shortName = await prompt.select("What database are you using?", KNOWN_TARGET_PACKAGES.map((entry) => ({
|
|
6351
|
+
value: entry.shortName,
|
|
6352
|
+
label: entry.label
|
|
6353
|
+
})));
|
|
6354
|
+
const chosen = KNOWN_TARGET_PACKAGES.find((entry) => entry.shortName === shortName);
|
|
6355
|
+
if (chosen === void 0) throw errorInitUserAborted();
|
|
6356
|
+
return chosen;
|
|
6357
|
+
}
|
|
6358
|
+
const AUTHORING_CHOICES = [{
|
|
6359
|
+
value: "psl",
|
|
6360
|
+
label: "Prisma Schema Language (.prisma)"
|
|
6361
|
+
}, {
|
|
6362
|
+
value: "typescript",
|
|
6363
|
+
label: "TypeScript (.ts)"
|
|
6364
|
+
}];
|
|
6365
|
+
/** Asks only between the ways the target package offers; one way is taken without asking. */
|
|
6366
|
+
async function askAuthoring(prompt, offered) {
|
|
6367
|
+
const choices = AUTHORING_CHOICES.filter((choice) => offered.includes(choice.value));
|
|
6368
|
+
const [only] = choices;
|
|
6369
|
+
if (choices.length === 1 && only !== void 0) return only.value;
|
|
6370
|
+
return prompt.select("How do you want to write your schema?", choices);
|
|
6431
6371
|
}
|
|
6432
6372
|
/**
|
|
6433
6373
|
* The schema path the user typed goes through the same validator the flag
|
|
@@ -6442,15 +6382,17 @@ async function askSchemaPath(prompt, authoring) {
|
|
|
6442
6382
|
}), authoring);
|
|
6443
6383
|
}
|
|
6444
6384
|
/**
|
|
6445
|
-
* The
|
|
6446
|
-
* switches targets and one is still declared. Reads every name a previous
|
|
6447
|
-
* could have written, because older versions scaffolded
|
|
6385
|
+
* The target package a previous `init` installed for another target, when this
|
|
6386
|
+
* run switches targets and one is still declared. Reads every name a previous
|
|
6387
|
+
* run could have written, because older versions scaffolded other names.
|
|
6448
6388
|
*/
|
|
6449
6389
|
function previousFacade(cwd, target) {
|
|
6450
6390
|
const manifestPath = join(cwd, "package.json");
|
|
6451
6391
|
if (!existsSync(manifestPath)) return;
|
|
6452
|
-
const
|
|
6453
|
-
|
|
6392
|
+
const candidates = KNOWN_TARGET_PACKAGES.filter((entry) => entry.shortName !== target.shortName).flatMap((entry) => [entry.packageName, entry.workspacePackageName].map((packageName) => ({
|
|
6393
|
+
target: entry,
|
|
6394
|
+
packageName
|
|
6395
|
+
})));
|
|
6454
6396
|
let parsed;
|
|
6455
6397
|
try {
|
|
6456
6398
|
parsed = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
@@ -6460,14 +6402,13 @@ function previousFacade(cwd, target) {
|
|
|
6460
6402
|
const deps = parsed["dependencies"];
|
|
6461
6403
|
if (deps === null || typeof deps !== "object" || Array.isArray(deps)) return;
|
|
6462
6404
|
const declared = deps;
|
|
6463
|
-
return candidates.find((
|
|
6405
|
+
return candidates.find((candidate) => Object.hasOwn(declared, candidate.packageName));
|
|
6464
6406
|
}
|
|
6465
6407
|
async function resolveRemovePreviousFacade(ctx) {
|
|
6466
6408
|
if (!ctx.reinit || ctx.keepPreviousFacade) return null;
|
|
6467
6409
|
const facade = previousFacade(ctx.cwd, ctx.target);
|
|
6468
6410
|
if (facade === void 0) return null;
|
|
6469
|
-
|
|
6470
|
-
return await ctx.prompt.confirm(`Switching from ${targetLabel(otherTarget)} to ${targetLabel(ctx.target)} — remove ${facade} from package.json dependencies?`, { default: true }) ? facade : null;
|
|
6411
|
+
return await ctx.prompt.confirm(`Switching from ${facade.target.label} to ${ctx.target.label} — remove ${facade.packageName} from package.json dependencies?`, { default: true }) ? facade.packageName : null;
|
|
6471
6412
|
}
|
|
6472
6413
|
const PRISMA7_SCHEMA_FLAG = "from-prisma7-schema";
|
|
6473
6414
|
const PRISMA7_CONFIG_STEM = "prisma.config.";
|
|
@@ -6519,15 +6460,15 @@ async function choosePrisma7Path(ctx) {
|
|
|
6519
6460
|
* or name the database when the provider is not a string literal.
|
|
6520
6461
|
*/
|
|
6521
6462
|
function prisma7Target(schema, flagTarget, rawFlagTarget) {
|
|
6522
|
-
const providerTarget = schema.provider === void 0 ? void 0 :
|
|
6463
|
+
const providerTarget = schema.provider === void 0 ? void 0 : findTargetByProvider(schema.provider);
|
|
6523
6464
|
if (schema.provider !== void 0 && providerTarget === void 0) return notOk(errorInitPrisma7ProviderUnsupported({
|
|
6524
6465
|
schemaPath: schema.path,
|
|
6525
6466
|
provider: schema.provider
|
|
6526
6467
|
}));
|
|
6527
|
-
if (schema.provider !== void 0 && flagTarget !== void 0 && flagTarget !== providerTarget) return notOk(errorInitPrisma7TargetMismatch({
|
|
6468
|
+
if (schema.provider !== void 0 && flagTarget !== void 0 && flagTarget.shortName !== providerTarget?.shortName) return notOk(errorInitPrisma7TargetMismatch({
|
|
6528
6469
|
schemaPath: schema.path,
|
|
6529
6470
|
provider: schema.provider,
|
|
6530
|
-
target: rawFlagTarget ?? flagTarget
|
|
6471
|
+
target: rawFlagTarget ?? flagTarget.shortName
|
|
6531
6472
|
}));
|
|
6532
6473
|
const target = flagTarget ?? providerTarget;
|
|
6533
6474
|
return target === void 0 ? notOk(errorInitPrisma7ProviderUnsupported({
|
|
@@ -6597,19 +6538,23 @@ async function resolvePrisma7Inputs(ctx) {
|
|
|
6597
6538
|
const targetResult = prisma7Target(schema, flagTarget, flags.target);
|
|
6598
6539
|
if (!targetResult.ok) throw targetResult.failure;
|
|
6599
6540
|
const target = targetResult.value;
|
|
6600
|
-
const
|
|
6601
|
-
|
|
6541
|
+
const prepared = await prepareTarget(ctx.prepareTargetPackage, target, {
|
|
6542
|
+
authoring: "prisma7",
|
|
6602
6543
|
schemaPath: schema.path
|
|
6603
|
-
});
|
|
6604
|
-
if (check.outcome === "no-source" && flags.fromPrisma7Schema !== void 0) throw errorInitPrisma7SourceUnavailable({
|
|
6605
|
-
schemaPath: schema.path,
|
|
6606
|
-
packageName: check.packageName,
|
|
6607
|
-
reason: "no-prisma7-source",
|
|
6608
|
-
added: check.added
|
|
6609
|
-
});
|
|
6544
|
+
}, PRISMA7_CHECK);
|
|
6610
6545
|
try {
|
|
6546
|
+
const check = await ctx.checkPrisma7Source({
|
|
6547
|
+
packageName: target.packageName,
|
|
6548
|
+
contribution: prepared.contribution,
|
|
6549
|
+
schemaPath: schema.path
|
|
6550
|
+
});
|
|
6551
|
+
if (check.outcome === "no-source" && flags.fromPrisma7Schema !== void 0) throw errorInitPrisma7SourceUnavailable({
|
|
6552
|
+
schemaPath: schema.path,
|
|
6553
|
+
packageName: target.packageName,
|
|
6554
|
+
reason: "no-prisma7-source"
|
|
6555
|
+
});
|
|
6611
6556
|
if (check.outcome === "no-source") {
|
|
6612
|
-
ctx.warn(freshInitWarning(
|
|
6557
|
+
ctx.warn(freshInitWarning(target.packageName, detection));
|
|
6613
6558
|
return await resolveStarterInputs({
|
|
6614
6559
|
cwd,
|
|
6615
6560
|
flags,
|
|
@@ -6617,8 +6562,9 @@ async function resolvePrisma7Inputs(ctx) {
|
|
|
6617
6562
|
target,
|
|
6618
6563
|
flagAuthoring: void 0,
|
|
6619
6564
|
prisma7SchemaPath: void 0,
|
|
6620
|
-
warnings:
|
|
6621
|
-
|
|
6565
|
+
warnings: detection.warnings,
|
|
6566
|
+
prepared,
|
|
6567
|
+
prepareTargetPackage: ctx.prepareTargetPackage
|
|
6622
6568
|
});
|
|
6623
6569
|
}
|
|
6624
6570
|
return await confirmPrisma7Inputs({
|
|
@@ -6628,10 +6574,11 @@ async function resolvePrisma7Inputs(ctx) {
|
|
|
6628
6574
|
detection,
|
|
6629
6575
|
schema,
|
|
6630
6576
|
target,
|
|
6631
|
-
|
|
6577
|
+
prepared,
|
|
6578
|
+
quickReference: check.quickReference
|
|
6632
6579
|
});
|
|
6633
6580
|
} catch (error) {
|
|
6634
|
-
throw
|
|
6581
|
+
throw prepared.added === void 0 ? error : withPackagesAddedAction(error, prepared.added, PRISMA7_CHECK);
|
|
6635
6582
|
}
|
|
6636
6583
|
}
|
|
6637
6584
|
function prisma7ConfigAfterInit(detection, sideBySide) {
|
|
@@ -6642,7 +6589,7 @@ function prisma7ConfigAfterInit(detection, sideBySide) {
|
|
|
6642
6589
|
}
|
|
6643
6590
|
/** The consents and questions of the Prisma 7 path, once the check has read the schema. */
|
|
6644
6591
|
async function confirmPrisma7Inputs(ctx) {
|
|
6645
|
-
const { cwd, flags, prompt, detection, schema, target,
|
|
6592
|
+
const { cwd, flags, prompt, detection, schema, target, prepared } = ctx;
|
|
6646
6593
|
const { config } = detection;
|
|
6647
6594
|
const prisma7ConfigOccupiesConfigFile = config.kind === "prisma7" && config.path === "prisma.config.ts";
|
|
6648
6595
|
const reinit = await requireReinitConsent({
|
|
@@ -6664,18 +6611,20 @@ async function confirmPrisma7Inputs(ctx) {
|
|
|
6664
6611
|
});
|
|
6665
6612
|
return {
|
|
6666
6613
|
target,
|
|
6614
|
+
contribution: prepared.contribution,
|
|
6667
6615
|
authoring: "psl",
|
|
6668
6616
|
schemaPath: schema.path,
|
|
6669
6617
|
contractSource: {
|
|
6670
6618
|
kind: "prisma7-schema",
|
|
6671
6619
|
schemaPath: schema.path,
|
|
6672
6620
|
provider: schema.provider,
|
|
6673
|
-
prisma7Config: prisma7ConfigAfterInit(detection, sideBySide)
|
|
6621
|
+
prisma7Config: prisma7ConfigAfterInit(detection, sideBySide),
|
|
6622
|
+
quickReference: ctx.quickReference
|
|
6674
6623
|
},
|
|
6675
6624
|
sideBySide,
|
|
6676
|
-
warnings: [...detection.warnings, ...
|
|
6625
|
+
warnings: [...detection.warnings, ...prepared.warnings],
|
|
6677
6626
|
install: !flags.skipInstall,
|
|
6678
|
-
preinstalled:
|
|
6627
|
+
preinstalled: prepared.installed,
|
|
6679
6628
|
writeEnv,
|
|
6680
6629
|
probeDb: flags.probeDb,
|
|
6681
6630
|
strictProbe: flags.strictProbe,
|
|
@@ -6683,21 +6632,65 @@ async function confirmPrisma7Inputs(ctx) {
|
|
|
6683
6632
|
removePreviousFacade
|
|
6684
6633
|
};
|
|
6685
6634
|
}
|
|
6686
|
-
|
|
6635
|
+
function missingFlags(missing, prisma7SchemaPath) {
|
|
6636
|
+
return errorInitMissingFlags({
|
|
6637
|
+
missing,
|
|
6638
|
+
why: "This session cannot prompt, so the answers have to arrive as flags.",
|
|
6639
|
+
prisma7SchemaPath
|
|
6640
|
+
});
|
|
6641
|
+
}
|
|
6642
|
+
/**
|
|
6643
|
+
* A fresh init: the target package is installed and its contribution loaded first, since the
|
|
6644
|
+
* questions after the target, such as the ways to write the contract, come from it.
|
|
6645
|
+
*/
|
|
6687
6646
|
async function resolveStarterInputs(ctx) {
|
|
6688
|
-
const {
|
|
6647
|
+
const { flags, prompt, flagAuthoring } = ctx;
|
|
6689
6648
|
let target;
|
|
6690
|
-
let authoring;
|
|
6691
6649
|
try {
|
|
6692
6650
|
target = ctx.target ?? await askTarget(prompt);
|
|
6693
|
-
authoring = flagAuthoring ?? await askAuthoring(prompt);
|
|
6694
6651
|
} catch (error) {
|
|
6695
6652
|
if (!isPromptRequired(error)) throw error;
|
|
6696
|
-
throw
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6653
|
+
throw missingFlags(["target", ...flagAuthoring === void 0 ? ["authoring"] : []], ctx.prisma7SchemaPath);
|
|
6654
|
+
}
|
|
6655
|
+
if (flags.schemaPath !== void 0) if (flagAuthoring !== void 0) validateSchemaPath(flags.schemaPath, flagAuthoring);
|
|
6656
|
+
else rejectSchemaPathNoModeTakes(flags.schemaPath);
|
|
6657
|
+
const installReason = {
|
|
6658
|
+
kind: "init-contribution",
|
|
6659
|
+
packageName: target.packageName
|
|
6660
|
+
};
|
|
6661
|
+
const reportedAuthoring = flagAuthoring ?? "psl";
|
|
6662
|
+
const prepared = ctx.prepared ?? await prepareTarget(ctx.prepareTargetPackage, target, {
|
|
6663
|
+
authoring: reportedAuthoring,
|
|
6664
|
+
schemaPath: flags.schemaPath ?? defaultSchemaPath(reportedAuthoring)
|
|
6665
|
+
}, installReason);
|
|
6666
|
+
const added = ctx.prepared === void 0 ? prepared.added : void 0;
|
|
6667
|
+
try {
|
|
6668
|
+
return await confirmStarterInputs({
|
|
6669
|
+
...ctx,
|
|
6670
|
+
target,
|
|
6671
|
+
prepared
|
|
6700
6672
|
});
|
|
6673
|
+
} catch (error) {
|
|
6674
|
+
throw added === void 0 ? error : withPackagesAddedAction(error, added, installReason);
|
|
6675
|
+
}
|
|
6676
|
+
}
|
|
6677
|
+
/** The questions of a fresh init, once the target package's contribution is loaded. */
|
|
6678
|
+
async function confirmStarterInputs(ctx) {
|
|
6679
|
+
const { cwd, flags, prompt, flagAuthoring, target, prepared } = ctx;
|
|
6680
|
+
const { contribution } = prepared;
|
|
6681
|
+
let authoring;
|
|
6682
|
+
if (flagAuthoring !== void 0) {
|
|
6683
|
+
if (!contribution.authoringModes.includes(flagAuthoring)) throw errorInitAuthoringUnsupported({
|
|
6684
|
+
packageName: target.packageName,
|
|
6685
|
+
authoring: flagAuthoring,
|
|
6686
|
+
offered: contribution.authoringModes
|
|
6687
|
+
});
|
|
6688
|
+
authoring = flagAuthoring;
|
|
6689
|
+
} else try {
|
|
6690
|
+
authoring = await askAuthoring(prompt, contribution.authoringModes);
|
|
6691
|
+
} catch (error) {
|
|
6692
|
+
if (!isPromptRequired(error)) throw error;
|
|
6693
|
+
throw missingFlags(["authoring"], ctx.prisma7SchemaPath);
|
|
6701
6694
|
}
|
|
6702
6695
|
const schemaPath = flags.schemaPath !== void 0 ? validateSchemaPath(flags.schemaPath, authoring) : await askSchemaPath(prompt, authoring);
|
|
6703
6696
|
const reinit = await requireReinitConsent({
|
|
@@ -6715,6 +6708,7 @@ async function resolveStarterInputs(ctx) {
|
|
|
6715
6708
|
});
|
|
6716
6709
|
return {
|
|
6717
6710
|
target,
|
|
6711
|
+
contribution,
|
|
6718
6712
|
authoring,
|
|
6719
6713
|
schemaPath,
|
|
6720
6714
|
contractSource: {
|
|
@@ -6723,9 +6717,9 @@ async function resolveStarterInputs(ctx) {
|
|
|
6723
6717
|
schemaPath
|
|
6724
6718
|
},
|
|
6725
6719
|
sideBySide: null,
|
|
6726
|
-
warnings: ctx.warnings,
|
|
6720
|
+
warnings: [...ctx.warnings, ...prepared.warnings],
|
|
6727
6721
|
install: !flags.skipInstall,
|
|
6728
|
-
preinstalled:
|
|
6722
|
+
preinstalled: prepared.installed,
|
|
6729
6723
|
writeEnv,
|
|
6730
6724
|
probeDb: flags.probeDb,
|
|
6731
6725
|
strictProbe: flags.strictProbe,
|
|
@@ -6735,7 +6729,7 @@ async function resolveStarterInputs(ctx) {
|
|
|
6735
6729
|
}
|
|
6736
6730
|
function prisma6Schema(schema) {
|
|
6737
6731
|
if (schema.kind !== "datasource") return void 0;
|
|
6738
|
-
const target =
|
|
6732
|
+
const target = findPrisma6OnlyTarget(schema.provider);
|
|
6739
6733
|
return target === void 0 ? void 0 : {
|
|
6740
6734
|
schema,
|
|
6741
6735
|
target
|
|
@@ -6747,21 +6741,20 @@ function prisma6Schema(schema) {
|
|
|
6747
6741
|
* for the Prisma 6 CLI instead of a new one written.
|
|
6748
6742
|
*/
|
|
6749
6743
|
function prisma6SchemaFound(detection, { schema, target }, packageManager) {
|
|
6750
|
-
const resolveImportSpecifier = scaffoldSpecifierResolverFor(target);
|
|
6751
6744
|
const { config, cli } = detection;
|
|
6752
6745
|
const ownConfigPath = (config.kind === "prisma7" || config.kind === "unreadable") && config.path.startsWith(PRISMA7_CONFIG_STEM) ? config.path : void 0;
|
|
6753
6746
|
return errorInitPrisma6SchemaFound({
|
|
6754
6747
|
schemaPath: schema.path,
|
|
6755
|
-
database:
|
|
6748
|
+
database: target.label,
|
|
6756
6749
|
setup: prisma6SideBySideSetup({
|
|
6757
6750
|
schemaPath: schema.path,
|
|
6758
6751
|
urlEnv: schema.urlEnv,
|
|
6759
6752
|
packageManager,
|
|
6760
6753
|
cliVersion: cli.kind === "earlier" ? cli.version : void 0,
|
|
6761
6754
|
ownConfigPath,
|
|
6762
|
-
targetPackage:
|
|
6763
|
-
peerPackages:
|
|
6764
|
-
targetConfigEntrypoint:
|
|
6755
|
+
targetPackage: target.packageName,
|
|
6756
|
+
peerPackages: target.peerPackages,
|
|
6757
|
+
targetConfigEntrypoint: `${target.packageName}/config`
|
|
6765
6758
|
})
|
|
6766
6759
|
});
|
|
6767
6760
|
}
|
|
@@ -6769,15 +6762,18 @@ function prisma6SchemaFound(detection, { schema, target }, packageManager) {
|
|
|
6769
6762
|
function starterBesidePrisma6Warnings(cwd) {
|
|
6770
6763
|
const found = prisma6Schema(detectSchema(cwd, conventionalSchemaPath(cwd).path));
|
|
6771
6764
|
if (found === void 0) return [];
|
|
6772
|
-
return [`${found.schema.path} is a Prisma 6 ${
|
|
6765
|
+
return [`${found.schema.path} is a Prisma 6 ${found.target.label} schema, which this run leaves alone, but this run breaks the Prisma 6 CLI: it writes prisma.config.ts, which the Prisma 6 CLI reads too, so every Prisma 6 command fails until Prisma 6 gets its own config file, and its install step replaces the Prisma 6 CLI with prisma@latest. Run \`prisma orm init\` without --target and --authoring to see how to keep Prisma 6 working and read this schema instead.`];
|
|
6773
6766
|
}
|
|
6774
6767
|
/**
|
|
6775
6768
|
* Resolves every input from the flags and, where a flag is absent, from the
|
|
6776
6769
|
* engine's prompt surface.
|
|
6777
6770
|
*
|
|
6778
|
-
* Order matters
|
|
6779
|
-
* so a typo costs a typo rather than a typed consent token.
|
|
6780
|
-
*
|
|
6771
|
+
* Order matters three times. Every flag value is validated before anything is
|
|
6772
|
+
* asked, so a typo costs a typo rather than a typed consent token. The target
|
|
6773
|
+
* package is installed and its contribution loaded as soon as the target is
|
|
6774
|
+
* known, because the questions after it come from that package; nothing is
|
|
6775
|
+
* asked between naming the target and installing it. And consent comes as
|
|
6776
|
+
* soon as the schema path is known, because that is the point at which the
|
|
6781
6777
|
* question can name the files it is about — and before any question whose
|
|
6782
6778
|
* answer only matters if the run proceeds.
|
|
6783
6779
|
*/
|
|
@@ -6807,6 +6803,7 @@ async function resolveInitInputs(ctx) {
|
|
|
6807
6803
|
prompt,
|
|
6808
6804
|
detection,
|
|
6809
6805
|
flagTarget,
|
|
6806
|
+
prepareTargetPackage: ctx.prepareTargetPackage,
|
|
6810
6807
|
checkPrisma7Source: ctx.checkPrisma7Source,
|
|
6811
6808
|
warn: ctx.warn
|
|
6812
6809
|
});
|
|
@@ -6820,9 +6817,73 @@ async function resolveInitInputs(ctx) {
|
|
|
6820
6817
|
flagAuthoring,
|
|
6821
6818
|
prisma7SchemaPath,
|
|
6822
6819
|
warnings: mayAdoptPrisma7 ? [] : starterBesidePrisma6Warnings(cwd),
|
|
6823
|
-
|
|
6820
|
+
prepared: void 0,
|
|
6821
|
+
prepareTargetPackage: ctx.prepareTargetPackage
|
|
6824
6822
|
});
|
|
6825
6823
|
}
|
|
6824
|
+
/**
|
|
6825
|
+
* Finds out whether the installed target package can read the Prisma 7 schema before init changes
|
|
6826
|
+
* the project: loads the package's config module as the project resolves it and runs its
|
|
6827
|
+
* `prisma7Schema` source without writing. The CLI carries no target code, so the installed
|
|
6828
|
+
* package is the only one that can answer. A `prisma7Schema` export is the only sign that a
|
|
6829
|
+
* package takes a Prisma 7 schema, and such a package must give `prisma7QuickReference`.
|
|
6830
|
+
*/
|
|
6831
|
+
function createPrisma7SourceCheck(ctx) {
|
|
6832
|
+
return async ({ packageName, contribution, schemaPath }) => {
|
|
6833
|
+
const imported = await ctx.importFromProject(ctx.cwd, contribution.configModule);
|
|
6834
|
+
if (imported.kind === "unloadable") throw errorInitPrisma7SourceUnavailable({
|
|
6835
|
+
schemaPath,
|
|
6836
|
+
packageName,
|
|
6837
|
+
reason: "unloadable",
|
|
6838
|
+
module: contribution.configModule,
|
|
6839
|
+
cause: imported.cause instanceof Error ? imported.cause.message : String(imported.cause)
|
|
6840
|
+
});
|
|
6841
|
+
if (imported.kind !== "loaded") throw errorInitPrisma7SourceUnavailable({
|
|
6842
|
+
schemaPath,
|
|
6843
|
+
packageName,
|
|
6844
|
+
reason: "not-resolvable",
|
|
6845
|
+
module: contribution.configModule
|
|
6846
|
+
});
|
|
6847
|
+
const { defineConfig, prisma7Schema } = imported.module;
|
|
6848
|
+
if (typeof prisma7Schema !== "function") return { outcome: "no-source" };
|
|
6849
|
+
if (typeof defineConfig !== "function") throw errorInitContributionUnavailable({
|
|
6850
|
+
packageName,
|
|
6851
|
+
reason: "invalid-shape",
|
|
6852
|
+
detail: `${contribution.configModule} exports prisma7Schema, but not a defineConfig function`
|
|
6853
|
+
});
|
|
6854
|
+
const quickReference = contribution.prisma7QuickReference;
|
|
6855
|
+
if (quickReference === void 0) throw errorInitContributionUnavailable({
|
|
6856
|
+
packageName,
|
|
6857
|
+
reason: "invalid-shape",
|
|
6858
|
+
detail: `${contribution.configModule} exports prisma7Schema, but the contribution has no prisma7QuickReference`
|
|
6859
|
+
});
|
|
6860
|
+
const section = defineConfig({
|
|
6861
|
+
contract: prisma7Schema(schemaPath),
|
|
6862
|
+
output: DEFAULT_CONTRACT_SOURCE_DIR
|
|
6863
|
+
});
|
|
6864
|
+
const required = requireConfigSections(buildLoadedConfig(isRecord(section) ? section : {}, ctx.cwd), [
|
|
6865
|
+
"family",
|
|
6866
|
+
"target",
|
|
6867
|
+
"adapter",
|
|
6868
|
+
"contract"
|
|
6869
|
+
]);
|
|
6870
|
+
if (!required.ok) throw required.failure;
|
|
6871
|
+
const result = await loadContractSource(required.value);
|
|
6872
|
+
if (!result.ok) throw errorInitPrisma7SchemaRefused({
|
|
6873
|
+
schemaPath,
|
|
6874
|
+
packageName,
|
|
6875
|
+
summary: result.failure.summary,
|
|
6876
|
+
diagnostics: result.failure.diagnostics
|
|
6877
|
+
});
|
|
6878
|
+
return {
|
|
6879
|
+
outcome: "readable",
|
|
6880
|
+
quickReference
|
|
6881
|
+
};
|
|
6882
|
+
};
|
|
6883
|
+
}
|
|
6884
|
+
function isRecord(value) {
|
|
6885
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6886
|
+
}
|
|
6826
6887
|
/** Each of these is a finding on a completed run, not an error. */
|
|
6827
6888
|
const INIT_EXIT_CODES = {
|
|
6828
6889
|
4: "dependency install failed",
|
|
@@ -6839,8 +6900,13 @@ function probeWarning(outcome, strictProbe) {
|
|
|
6839
6900
|
fatal: void 0
|
|
6840
6901
|
};
|
|
6841
6902
|
case "no-database-url":
|
|
6903
|
+
case "invalid-result":
|
|
6842
6904
|
case "connection-failed":
|
|
6843
|
-
case "
|
|
6905
|
+
case "timed-out":
|
|
6906
|
+
case "driver-missing":
|
|
6907
|
+
case "driver-failed":
|
|
6908
|
+
case "version-unreadable":
|
|
6909
|
+
case "unsupported": return strictProbe ? {
|
|
6844
6910
|
warning: void 0,
|
|
6845
6911
|
fatal: outcome.message
|
|
6846
6912
|
} : {
|
|
@@ -6849,28 +6915,39 @@ function probeWarning(outcome, strictProbe) {
|
|
|
6849
6915
|
};
|
|
6850
6916
|
}
|
|
6851
6917
|
}
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
}
|
|
6918
|
+
const [FIRST_TARGET, SECOND_TARGET] = KNOWN_TARGET_PACKAGES;
|
|
6919
|
+
const PRISMA6_ONLY_LABELS = KNOWN_TARGET_PACKAGES.filter((entry) => entry.provider.writtenBy === 6).map((entry) => entry.label);
|
|
6855
6920
|
function causeMessage(error) {
|
|
6856
6921
|
return error instanceof Error ? error.message : String(error);
|
|
6857
6922
|
}
|
|
6858
6923
|
const createInitCommand = (injected) => defineOrmCommand({
|
|
6859
6924
|
help: {
|
|
6860
6925
|
summary: "Initialize a new Prisma ORM project",
|
|
6861
|
-
description:
|
|
6926
|
+
description: `Scaffolds config, schema, and runtime files, installs dependencies,
|
|
6927
|
+
and emits the contract. Gets you from zero to typed queries in one step.
|
|
6928
|
+
|
|
6929
|
+
Run it interactively for a guided setup, or supply --target and --authoring
|
|
6930
|
+
for a fully scriptable run (CI, AI coding agents, automation).
|
|
6931
|
+
|
|
6932
|
+
In a Prisma 7 project, pass --from-prisma7-schema (or answer yes when asked)
|
|
6933
|
+
to use the existing schema.prisma as the contract source.
|
|
6934
|
+
|
|
6935
|
+
In a Prisma 6 ${PRISMA6_ONLY_LABELS.join(" or ")} project, init changes nothing: it prints how to install\nPrisma 8 beside Prisma 6 and read schema.prisma through prisma6Schema in
|
|
6936
|
+
prisma.config.ts, keeping the Prisma 6 CLI as an alias with its own config.
|
|
6937
|
+
Passing --target and --authoring sets up a starter in the same project instead,
|
|
6938
|
+
which breaks the Prisma 6 CLI.`,
|
|
6862
6939
|
examples: [
|
|
6863
6940
|
"orm init",
|
|
6864
|
-
|
|
6865
|
-
|
|
6941
|
+
`orm init --target ${FIRST_TARGET.shortName} --authoring psl`,
|
|
6942
|
+
`orm init --target ${SECOND_TARGET.shortName} --authoring typescript --json`,
|
|
6866
6943
|
"orm init --skip-install",
|
|
6867
|
-
|
|
6944
|
+
`orm init --target ${FIRST_TARGET.shortName} --keep-previous-facade`,
|
|
6868
6945
|
"orm init --from-prisma7-schema prisma/schema.prisma --confirm my-app"
|
|
6869
6946
|
]
|
|
6870
6947
|
},
|
|
6871
6948
|
args: { flags: {
|
|
6872
6949
|
target: flag.string({
|
|
6873
|
-
brief:
|
|
6950
|
+
brief: `Database target: ${TARGET_SHORT_NAMES.join(" or ")}`,
|
|
6874
6951
|
placeholder: "db"
|
|
6875
6952
|
}),
|
|
6876
6953
|
authoring: flag.string({
|
|
@@ -6884,7 +6961,7 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6884
6961
|
writeEnv: flag.boolean({ brief: "Write a .env file from .env.example (gitignored)" }),
|
|
6885
6962
|
probeDb: flag.boolean({ brief: "Connect to DATABASE_URL once and check the server version" }),
|
|
6886
6963
|
strictProbe: flag.boolean({ brief: "Treat a failed --probe-db as fatal" }),
|
|
6887
|
-
skipInstall: flag.boolean({ brief: "Skip dependency installation and contract emission" }),
|
|
6964
|
+
skipInstall: flag.boolean({ brief: "Skip dependency installation and contract emission; the target package must already be installed" }),
|
|
6888
6965
|
keepPreviousFacade: flag.boolean({ brief: "Keep the previous target package in package.json when switching targets" }),
|
|
6889
6966
|
fromPrisma7Schema: flag.string({
|
|
6890
6967
|
brief: "Use an existing Prisma 7 schema.prisma as the contract source",
|
|
@@ -6913,22 +6990,26 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6913
6990
|
cwd: ctx.cwd,
|
|
6914
6991
|
flags: args.flags,
|
|
6915
6992
|
prompt: ctx.prompt,
|
|
6916
|
-
|
|
6993
|
+
prepareTargetPackage: createTargetPackagePreparation({
|
|
6917
6994
|
cwd: ctx.cwd,
|
|
6918
6995
|
packages: ctx.packages,
|
|
6919
6996
|
packageManager,
|
|
6920
6997
|
install: !args.flags.skipInstall,
|
|
6921
6998
|
importFromProject: injected.importFromProject
|
|
6922
6999
|
}),
|
|
7000
|
+
checkPrisma7Source: createPrisma7SourceCheck({
|
|
7001
|
+
cwd: ctx.cwd,
|
|
7002
|
+
importFromProject: injected.importFromProject
|
|
7003
|
+
}),
|
|
6923
7004
|
warn,
|
|
6924
7005
|
packageManager
|
|
6925
7006
|
});
|
|
6926
7007
|
} catch (error) {
|
|
6927
|
-
if (!(error instanceof
|
|
7008
|
+
if (!(error instanceof InitInstallFailedBeforeWriting)) throw error;
|
|
6928
7009
|
const document = {
|
|
6929
7010
|
ok: true,
|
|
6930
|
-
target:
|
|
6931
|
-
authoring:
|
|
7011
|
+
target: error.target.shortName,
|
|
7012
|
+
authoring: error.authoring,
|
|
6932
7013
|
schemaPath: error.schemaPath,
|
|
6933
7014
|
filesWritten: [],
|
|
6934
7015
|
filesDeleted: [],
|
|
@@ -6939,12 +7020,12 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6939
7020
|
devDeps: []
|
|
6940
7021
|
},
|
|
6941
7022
|
contractEmitted: false,
|
|
6942
|
-
prisma7: {
|
|
7023
|
+
prisma7: error.authoring === "prisma7" ? {
|
|
6943
7024
|
schemaPath: error.schemaPath,
|
|
6944
7025
|
configRenamedTo: null,
|
|
6945
7026
|
scriptsRewritten: [],
|
|
6946
7027
|
packagesMoved: []
|
|
6947
|
-
},
|
|
7028
|
+
} : null,
|
|
6948
7029
|
nextSteps: [...NEXT_STEPS_BEFORE_SCAFFOLD],
|
|
6949
7030
|
warnings
|
|
6950
7031
|
};
|
|
@@ -6974,9 +7055,9 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6974
7055
|
const clientMajor = movePackages?.clientVersion === void 0 ? void 0 : versionMajor(movePackages.clientVersion);
|
|
6975
7056
|
const moveClient = movePackages !== null && clientMajor !== void 0 && clientMajor < 7;
|
|
6976
7057
|
const deps = [
|
|
6977
|
-
|
|
7058
|
+
inputs.target.packageName,
|
|
6978
7059
|
"dotenv",
|
|
6979
|
-
...
|
|
7060
|
+
...inputs.contribution.peerPackages,
|
|
6980
7061
|
...moveClient ? ["@prisma/client@7"] : []
|
|
6981
7062
|
];
|
|
6982
7063
|
const depsToInstall = deps.filter((dep) => !inputs.preinstalled.includes(dep));
|
|
@@ -6996,7 +7077,7 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
6996
7077
|
const installed = packagesInstalled === "installed";
|
|
6997
7078
|
const document = {
|
|
6998
7079
|
ok: true,
|
|
6999
|
-
target:
|
|
7080
|
+
target: inputs.target.shortName,
|
|
7000
7081
|
authoring: adoptsPrisma7 ? "prisma7" : inputs.authoring,
|
|
7001
7082
|
schemaPath: inputs.schemaPath,
|
|
7002
7083
|
filesWritten: scaffold.filesWritten,
|
|
@@ -7015,7 +7096,7 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
7015
7096
|
packagesMoved
|
|
7016
7097
|
} : null,
|
|
7017
7098
|
nextSteps: buildNextSteps({
|
|
7018
|
-
target:
|
|
7099
|
+
target: inputs.target.shortName,
|
|
7019
7100
|
packagesInstalled,
|
|
7020
7101
|
contractEmitted,
|
|
7021
7102
|
emitCommand: EMIT_COMMAND,
|
|
@@ -7095,11 +7176,10 @@ const createInitCommand = (injected) => defineOrmCommand({
|
|
|
7095
7176
|
} else extraActions.push(chooseAction(`Install the project dependencies with your package manager: ${deps.join(", ")} (and ${devDeps.join(", ")} plus @prisma/cli-engine at the version prisma declares as its dependency, as development dependencies)`));
|
|
7096
7177
|
if (inputs.probeDb) {
|
|
7097
7178
|
const probe = probeWarning(await probeServerVersion({
|
|
7098
|
-
baseDir: ctx.cwd,
|
|
7099
|
-
target: inputs.target,
|
|
7100
7179
|
databaseUrl: ctx.env["DATABASE_URL"],
|
|
7101
|
-
|
|
7102
|
-
|
|
7180
|
+
packageName: inputs.target.packageName,
|
|
7181
|
+
contribution: inputs.contribution
|
|
7182
|
+
}), inputs.strictProbe);
|
|
7103
7183
|
if (probe.warning !== void 0) warn(probe.warning);
|
|
7104
7184
|
if (probe.fatal !== void 0) return notOk$1(normalizeError(errorInitProbeFailed({
|
|
7105
7185
|
cause: probe.fatal,
|
|
@@ -7140,7 +7220,7 @@ const lspCommand = defineServerCommand({
|
|
|
7140
7220
|
} },
|
|
7141
7221
|
handler: async (args, io) => {
|
|
7142
7222
|
const exitCode = await withoutClientProcessIdInArgv(async () => {
|
|
7143
|
-
const { startServer } = await import("./exports-
|
|
7223
|
+
const { startServer } = await import("./exports-BiXPktAF.mjs");
|
|
7144
7224
|
return startServer({
|
|
7145
7225
|
stdin: io.stdin,
|
|
7146
7226
|
stdout: io.stdout,
|
|
@@ -9574,7 +9654,10 @@ function createMigrateCommand(createClient) {
|
|
|
9574
9654
|
const planned = await executeMigrateShowPlan({
|
|
9575
9655
|
config: ctx.config,
|
|
9576
9656
|
cwd: ctx.cwd,
|
|
9577
|
-
invocation:
|
|
9657
|
+
invocation: {
|
|
9658
|
+
...cliInvocation(ctx, args.flags.db),
|
|
9659
|
+
rerunArgs: rerunFlags(args.flags)
|
|
9660
|
+
},
|
|
9578
9661
|
createClient,
|
|
9579
9662
|
...ifDefined("db", args.flags.db),
|
|
9580
9663
|
...ifDefined("to", args.flags.to),
|
|
@@ -9676,6 +9759,7 @@ function createMigrateCommand(createClient) {
|
|
|
9676
9759
|
refName: target.refName
|
|
9677
9760
|
},
|
|
9678
9761
|
storageNameOf: (operation) => familyInstance.storageNameOf(operation),
|
|
9762
|
+
accessChangesOf: (operations) => familyInstance.accessChangesOf(operations),
|
|
9679
9763
|
migrationsDir,
|
|
9680
9764
|
invocation: cliInvocation(ctx, args.flags.db),
|
|
9681
9765
|
readLedger: (spaceId) => client.readLedger(spaceId),
|
|
@@ -9712,7 +9796,7 @@ function createMigrateCommand(createClient) {
|
|
|
9712
9796
|
name: args.flags.advanceRef,
|
|
9713
9797
|
contractJson: snapshotContractJson,
|
|
9714
9798
|
contractJsonPath: snapshotContractPath,
|
|
9715
|
-
|
|
9799
|
+
config: ctx.config,
|
|
9716
9800
|
client
|
|
9717
9801
|
});
|
|
9718
9802
|
if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
|
|
@@ -10551,7 +10635,6 @@ function createMigrationNewCommand(createClient) {
|
|
|
10551
10635
|
const scaffolded = await executeMigrationNewCommand({
|
|
10552
10636
|
config: ctx.config,
|
|
10553
10637
|
cwd: ctx.cwd,
|
|
10554
|
-
projectDir: baseDirFor(ctx.config),
|
|
10555
10638
|
...ifDefined("name", args.flags.name),
|
|
10556
10639
|
...ifDefined("from", args.flags.from),
|
|
10557
10640
|
client: createClient({
|
|
@@ -10847,7 +10930,6 @@ function createMigrationPlanCommand(createClient) {
|
|
|
10847
10930
|
const planned = await executeMigrationPlanCommand({
|
|
10848
10931
|
config: ctx.config,
|
|
10849
10932
|
cwd: ctx.cwd,
|
|
10850
|
-
projectDir: baseDirFor(ctx.config),
|
|
10851
10933
|
...ifDefined("configPath", ctx.configPath),
|
|
10852
10934
|
...ifDefined("name", args.flags.name),
|
|
10853
10935
|
...ifDefined("from", args.flags.from),
|