@prisma/internals 6.7.0-dev.2 → 6.7.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-OXXF7LCX.js → chunk-36HEJ53U.js} +5 -5
- package/dist/{chunk-JGJGCIF6.js → chunk-3AHGJNVW.js} +5 -5
- package/dist/{chunk-4ZNHLZTQ.js → chunk-AXODXULX.js} +5 -5
- package/dist/{chunk-HSCJEEWW.js → chunk-BATBMQL6.js} +5 -5
- package/dist/{chunk-WMIPCYQH.js → chunk-BQR56ITE.js} +8 -8
- package/dist/{chunk-WKDVLS4Z.js → chunk-C3DSIEII.js} +8 -8
- package/dist/chunk-CHOXBASF.js +44 -0
- package/dist/{chunk-LWRNGWQ7.js → chunk-GDAVBSHI.js} +5 -5
- package/dist/{chunk-7VLCG6RO.js → chunk-GVG3JQDU.js} +8 -8
- package/dist/{chunk-L5MJMR3W.js → chunk-JLKVIFZ6.js} +38 -432
- package/dist/{chunk-XCXK2WBL.js → chunk-JMXX2GKM.js} +7 -7
- package/dist/{chunk-4RTSZRIG.js → chunk-KR4RJJRT.js} +38 -432
- package/dist/{chunk-SXHAFH2E.js → chunk-L3WYRPHA.js} +5 -5
- package/dist/{chunk-67I7CEQJ.js → chunk-MY5KA4VU.js} +12 -329
- package/dist/{chunk-ZQB3OZHH.js → chunk-NKR3L4GD.js} +8 -8
- package/dist/chunk-PSFQKG2Q.js +6291 -0
- package/dist/chunk-Q6ZVYPDB.js +41 -0
- package/dist/chunk-QS3WUGE3.js +341 -0
- package/dist/{chunk-DVK2KU3X.js → chunk-RJ5C46HN.js} +7 -7
- package/dist/{chunk-SIR4CCL5.js → chunk-RPEQCKAF.js} +8 -8
- package/dist/{chunk-46TQ3PMY.js → chunk-TQZRKRJL.js} +5 -5
- package/dist/{chunk-TI7UC2UE.js → chunk-U5GS7TZV.js} +6 -6
- package/dist/{chunk-WFM4E4NF.js → chunk-VJDRTF62.js} +5 -5
- package/dist/chunk-WCPUXXL2.js +183 -0
- package/dist/{chunk-UUMPQSS5.js → chunk-WWIZHZEN.js} +5 -5
- package/dist/{chunk-XIFVVTBW.js → chunk-YJCAAD5D.js} +8 -8
- package/dist/chunk-ZCBEMBHR.js +242 -0
- package/dist/chunk-ZIFBTC6Y.js +6440 -0
- package/dist/cli/checkUnsupportedDataProxy.js +22 -16
- package/dist/cli/checkUnsupportedSchemaEngineWasm.js +22 -16
- package/dist/cli/getSchema.js +8 -112
- package/dist/cli/hashes.js +6 -109
- package/dist/cli/schemaContext.js +22 -16
- package/dist/engine-commands/errorHelpers.js +4 -4
- package/dist/engine-commands/formatSchema.js +21 -15
- package/dist/engine-commands/getConfig.js +10 -10
- package/dist/engine-commands/getDmmf.js +7 -7
- package/dist/engine-commands/index.js +30 -24
- package/dist/engine-commands/lintSchema.js +8 -8
- package/dist/engine-commands/mergeSchemas.js +7 -7
- package/dist/engine-commands/validate.js +7 -7
- package/dist/get-generators/getGenerators.js +24 -18
- package/dist/getPackedPackage.js +6 -4
- package/dist/index.js +51 -45
- package/dist/resolvePkg.js +3 -2
- package/dist/utils/getEnvPaths.js +5 -106
- package/dist/utils/getVersionFromPackageJson.js +3 -3
- package/dist/utils/loadEnvFile.js +6 -106
- package/dist/wasm.js +5 -5
- package/package.json +13 -13
- package/dist/chunk-MJIP3FY5.js +0 -12695
@@ -0,0 +1,183 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var chunk_WCPUXXL2_exports = {};
|
30
|
+
__export(chunk_WCPUXXL2_exports, {
|
31
|
+
getEnvPaths: () => getEnvPaths
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(chunk_WCPUXXL2_exports);
|
34
|
+
var import_chunk_2IP7H3BQ = require("./chunk-2IP7H3BQ.js");
|
35
|
+
var import_chunk_ZCBEMBHR = require("./chunk-ZCBEMBHR.js");
|
36
|
+
var import_chunk_PSFQKG2Q = require("./chunk-PSFQKG2Q.js");
|
37
|
+
var import_debug = __toESM(require("@prisma/debug"));
|
38
|
+
var import_node_path = __toESM(require("node:path"));
|
39
|
+
var import_node_process = __toESM(require("node:process"));
|
40
|
+
var import_node_path2 = __toESM(require("node:path"));
|
41
|
+
var import_node_fs = __toESM(require("node:fs"));
|
42
|
+
var import_node_url = require("node:url");
|
43
|
+
var import_node_fs2 = __toESM(require("node:fs"));
|
44
|
+
var import_fs = __toESM(require("fs"));
|
45
|
+
var import_path = __toESM(require("path"));
|
46
|
+
var typeMappings = {
|
47
|
+
directory: "isDirectory",
|
48
|
+
file: "isFile"
|
49
|
+
};
|
50
|
+
function checkType(type) {
|
51
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
throw new Error(`Invalid type specified: ${type}`);
|
55
|
+
}
|
56
|
+
var matchType = (type, stat) => stat[typeMappings[type]]();
|
57
|
+
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
58
|
+
function locatePathSync(paths, {
|
59
|
+
cwd = import_node_process.default.cwd(),
|
60
|
+
type = "file",
|
61
|
+
allowSymlinks = true
|
62
|
+
} = {}) {
|
63
|
+
checkType(type);
|
64
|
+
cwd = toPath2(cwd);
|
65
|
+
const statFunction = allowSymlinks ? import_node_fs.default.statSync : import_node_fs.default.lstatSync;
|
66
|
+
for (const path_ of paths) {
|
67
|
+
try {
|
68
|
+
const stat = statFunction(import_node_path2.default.resolve(cwd, path_), {
|
69
|
+
throwIfNoEntry: false
|
70
|
+
});
|
71
|
+
if (!stat) {
|
72
|
+
continue;
|
73
|
+
}
|
74
|
+
if (matchType(type, stat)) {
|
75
|
+
return path_;
|
76
|
+
}
|
77
|
+
} catch {
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
function pathExistsSync(path4) {
|
82
|
+
try {
|
83
|
+
import_node_fs2.default.accessSync(path4);
|
84
|
+
return true;
|
85
|
+
} catch {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
var findUpStop = Symbol("findUpStop");
|
90
|
+
function findUpMultipleSync(name, options = {}) {
|
91
|
+
let directory = import_node_path.default.resolve((0, import_chunk_PSFQKG2Q.toPath)(options.cwd) ?? "");
|
92
|
+
const { root } = import_node_path.default.parse(directory);
|
93
|
+
const stopAt = import_node_path.default.resolve(directory, (0, import_chunk_PSFQKG2Q.toPath)(options.stopAt) ?? root);
|
94
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
95
|
+
const paths = [name].flat();
|
96
|
+
const runMatcher = (locateOptions) => {
|
97
|
+
if (typeof name !== "function") {
|
98
|
+
return locatePathSync(paths, locateOptions);
|
99
|
+
}
|
100
|
+
const foundPath = name(locateOptions.cwd);
|
101
|
+
if (typeof foundPath === "string") {
|
102
|
+
return locatePathSync([foundPath], locateOptions);
|
103
|
+
}
|
104
|
+
return foundPath;
|
105
|
+
};
|
106
|
+
const matches = [];
|
107
|
+
while (true) {
|
108
|
+
const foundPath = runMatcher({ ...options, cwd: directory });
|
109
|
+
if (foundPath === findUpStop) {
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
if (foundPath) {
|
113
|
+
matches.push(import_node_path.default.resolve(directory, foundPath));
|
114
|
+
}
|
115
|
+
if (directory === stopAt || matches.length >= limit) {
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
directory = import_node_path.default.dirname(directory);
|
119
|
+
}
|
120
|
+
return matches;
|
121
|
+
}
|
122
|
+
function findUpSync(name, options = {}) {
|
123
|
+
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
124
|
+
return matches[0];
|
125
|
+
}
|
126
|
+
var debug = (0, import_debug.default)("prisma:loadEnv");
|
127
|
+
async function getEnvPaths(schemaPath, opts = { cwd: process.cwd() }) {
|
128
|
+
const rootEnvPath = getProjectRootEnvPath({ cwd: opts.cwd }) ?? null;
|
129
|
+
const schemaEnvPathFromArgs = schemaPathToEnvPath(schemaPath);
|
130
|
+
const schemaEnvPathFromPkgJson = schemaPathToEnvPath(await readSchemaPathFromPkgJson());
|
131
|
+
const schemaEnvPaths = [
|
132
|
+
schemaEnvPathFromArgs,
|
133
|
+
// 1 - Check --schema directory for .env
|
134
|
+
schemaEnvPathFromPkgJson,
|
135
|
+
// 2 - Check package.json schema directory for .env
|
136
|
+
"./prisma/.env",
|
137
|
+
// 3 - Check ./prisma directory for .env
|
138
|
+
"./.env"
|
139
|
+
// 4 - Check cwd for .env
|
140
|
+
];
|
141
|
+
const schemaEnvPath = schemaEnvPaths.find(import_chunk_2IP7H3BQ.exists);
|
142
|
+
return { rootEnvPath, schemaEnvPath };
|
143
|
+
}
|
144
|
+
async function readSchemaPathFromPkgJson() {
|
145
|
+
try {
|
146
|
+
const pkgJsonSchema = await (0, import_chunk_ZCBEMBHR.getSchemaFromPackageJson)(process.cwd());
|
147
|
+
if (pkgJsonSchema.ok) {
|
148
|
+
pkgJsonSchema.schema.schemaPath;
|
149
|
+
}
|
150
|
+
return null;
|
151
|
+
} catch {
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
function getProjectRootEnvPath(opts) {
|
156
|
+
const pkgJsonPath = findUpSync((dir) => {
|
157
|
+
const pkgPath = import_path.default.join(dir, "package.json");
|
158
|
+
if (pathExistsSync(pkgPath)) {
|
159
|
+
try {
|
160
|
+
const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
|
161
|
+
if (pkg["name"] !== ".prisma/client") {
|
162
|
+
debug(`project root found at ${pkgPath}`);
|
163
|
+
return pkgPath;
|
164
|
+
}
|
165
|
+
} catch (e) {
|
166
|
+
debug(`skipping package.json at ${pkgPath}`);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return void 0;
|
170
|
+
}, opts);
|
171
|
+
if (!pkgJsonPath) {
|
172
|
+
return null;
|
173
|
+
}
|
174
|
+
const candidate = import_path.default.join(import_path.default.dirname(pkgJsonPath), ".env");
|
175
|
+
if (!import_fs.default.existsSync(candidate)) {
|
176
|
+
return null;
|
177
|
+
}
|
178
|
+
return candidate;
|
179
|
+
}
|
180
|
+
function schemaPathToEnvPath(schemaPath) {
|
181
|
+
if (!schemaPath) return null;
|
182
|
+
return import_path.default.join(import_path.default.dirname(schemaPath), ".env");
|
183
|
+
}
|
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
return to;
|
17
17
|
};
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var
|
20
|
-
__export(
|
19
|
+
var chunk_WWIZHZEN_exports = {};
|
20
|
+
__export(chunk_WWIZHZEN_exports, {
|
21
21
|
version: () => version
|
22
22
|
});
|
23
|
-
module.exports = __toCommonJS(
|
24
|
-
var
|
25
|
-
var packageJson = (0,
|
23
|
+
module.exports = __toCommonJS(chunk_WWIZHZEN_exports);
|
24
|
+
var import_chunk_BATBMQL6 = require("./chunk-BATBMQL6.js");
|
25
|
+
var packageJson = (0, import_chunk_BATBMQL6.require_package)();
|
26
26
|
var version = packageJson.version;
|
@@ -26,20 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
26
26
|
mod
|
27
27
|
));
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var
|
30
|
-
__export(
|
29
|
+
var chunk_YJCAAD5D_exports = {};
|
30
|
+
__export(chunk_YJCAAD5D_exports, {
|
31
31
|
GetConfigError: () => GetConfigError,
|
32
32
|
getConfig: () => getConfig,
|
33
33
|
getDirectUrl: () => getDirectUrl,
|
34
34
|
getEffectiveUrl: () => getEffectiveUrl,
|
35
35
|
resolveUrl: () => resolveUrl
|
36
36
|
});
|
37
|
-
module.exports = __toCommonJS(
|
37
|
+
module.exports = __toCommonJS(chunk_YJCAAD5D_exports);
|
38
38
|
var import_chunk_TZJROXB3 = require("./chunk-TZJROXB3.js");
|
39
39
|
var import_chunk_C47SCASR = require("./chunk-C47SCASR.js");
|
40
40
|
var import_chunk_R6QH57HZ = require("./chunk-R6QH57HZ.js");
|
41
|
-
var
|
42
|
-
var
|
41
|
+
var import_chunk_AXODXULX = require("./chunk-AXODXULX.js");
|
42
|
+
var import_chunk_36HEJ53U = require("./chunk-36HEJ53U.js");
|
43
43
|
var import_chunk_5DBOS77Y = require("./chunk-5DBOS77Y.js");
|
44
44
|
var import_chunk_XKZ6CBLA = require("./chunk-XKZ6CBLA.js");
|
45
45
|
var import_chunk_LMVSIVKQ = require("./chunk-LMVSIVKQ.js");
|
@@ -64,7 +64,7 @@ ${detailsHeader} ${message}`;
|
|
64
64
|
}).exhaustive();
|
65
65
|
const errorMessageWithContext = `${constructedErrorMessage}
|
66
66
|
[Context: getConfig]`;
|
67
|
-
super((0,
|
67
|
+
super((0, import_chunk_AXODXULX.addVersionDetailsToErrorMessage)(errorMessageWithContext));
|
68
68
|
this.name = "GetConfigError";
|
69
69
|
}
|
70
70
|
};
|
@@ -89,7 +89,7 @@ async function getConfig(options) {
|
|
89
89
|
() => {
|
90
90
|
if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) {
|
91
91
|
debug("Triggering a Rust panic...");
|
92
|
-
|
92
|
+
import_chunk_36HEJ53U.prismaSchemaWasm.debug_panic();
|
93
93
|
}
|
94
94
|
const params = JSON.stringify({
|
95
95
|
prismaSchema: options.datamodel,
|
@@ -97,7 +97,7 @@ async function getConfig(options) {
|
|
97
97
|
ignoreEnvVarErrors: options.ignoreEnvVarErrors ?? false,
|
98
98
|
env: process.env
|
99
99
|
});
|
100
|
-
const data =
|
100
|
+
const data = import_chunk_36HEJ53U.prismaSchemaWasm.get_config(params);
|
101
101
|
return data;
|
102
102
|
},
|
103
103
|
(e) => ({
|
@@ -0,0 +1,242 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var chunk_ZCBEMBHR_exports = {};
|
30
|
+
__export(chunk_ZCBEMBHR_exports, {
|
31
|
+
getPrismaConfigFromPackageJson: () => getPrismaConfigFromPackageJson,
|
32
|
+
getSchemaFromPackageJson: () => getSchemaFromPackageJson,
|
33
|
+
getSchemaWithPath: () => getSchemaWithPath,
|
34
|
+
getSchemaWithPathOptional: () => getSchemaWithPathOptional,
|
35
|
+
printSchemaLoadedMessage: () => printSchemaLoadedMessage
|
36
|
+
});
|
37
|
+
module.exports = __toCommonJS(chunk_ZCBEMBHR_exports);
|
38
|
+
var import_chunk_PG5FDKSF = require("./chunk-PG5FDKSF.js");
|
39
|
+
var import_chunk_PSFQKG2Q = require("./chunk-PSFQKG2Q.js");
|
40
|
+
var import_debug = require("@prisma/debug");
|
41
|
+
var import_schema_files_loader = require("@prisma/schema-files-loader");
|
42
|
+
var import_fs = __toESM(require("fs"));
|
43
|
+
var import_path = __toESM(require("path"));
|
44
|
+
var import_util = require("util");
|
45
|
+
var readFile = (0, import_util.promisify)(import_fs.default.readFile);
|
46
|
+
var stat = (0, import_util.promisify)(import_fs.default.stat);
|
47
|
+
var debug = (0, import_debug.Debug)("prisma:getSchema");
|
48
|
+
async function getSchemaWithPath(schemaPathFromArgs, schemaPathFromConfig, { cwd = process.cwd(), argumentName = "--schema" } = {}) {
|
49
|
+
const result = await getSchemaWithPathInternal(schemaPathFromArgs, schemaPathFromConfig, { cwd, argumentName });
|
50
|
+
if (result.ok) {
|
51
|
+
return result.schema;
|
52
|
+
}
|
53
|
+
throw new Error(renderDefaultLookupError(result.error, cwd));
|
54
|
+
}
|
55
|
+
async function getSchemaWithPathOptional(schemaPathFromArgs, schemaPathFromConfig, { cwd = process.cwd(), argumentName = "--schema" } = {}) {
|
56
|
+
const result = await getSchemaWithPathInternal(schemaPathFromArgs, schemaPathFromConfig, { cwd, argumentName });
|
57
|
+
if (result.ok) {
|
58
|
+
return result.schema;
|
59
|
+
}
|
60
|
+
return null;
|
61
|
+
}
|
62
|
+
function printSchemaLoadedMessage(schemaPath) {
|
63
|
+
process.stdout.write((0, import_chunk_PG5FDKSF.dim)(`Prisma schema loaded from ${import_path.default.relative(process.cwd(), schemaPath)}`) + "\n");
|
64
|
+
}
|
65
|
+
async function readSchemaFromSingleFile(schemaPath) {
|
66
|
+
debug("Reading schema from single file", schemaPath);
|
67
|
+
const typeError = await (0, import_schema_files_loader.ensureType)(schemaPath, "file");
|
68
|
+
if (typeError) {
|
69
|
+
return { ok: false, error: typeError };
|
70
|
+
}
|
71
|
+
const file = await readFile(schemaPath, { encoding: "utf-8" });
|
72
|
+
const schemaTuple = [schemaPath, file];
|
73
|
+
return {
|
74
|
+
ok: true,
|
75
|
+
schema: { schemaPath, schemaRootDir: import_path.default.dirname(schemaPath), schemas: [schemaTuple] }
|
76
|
+
};
|
77
|
+
}
|
78
|
+
async function readSchemaFromDirectory(schemaPath) {
|
79
|
+
debug("Reading schema from multiple files", schemaPath);
|
80
|
+
const typeError = await (0, import_schema_files_loader.ensureType)(schemaPath, "directory");
|
81
|
+
if (typeError) {
|
82
|
+
return { ok: false, error: typeError };
|
83
|
+
}
|
84
|
+
const files = await (0, import_schema_files_loader.loadSchemaFiles)(schemaPath);
|
85
|
+
return { ok: true, schema: { schemaPath, schemaRootDir: schemaPath, schemas: files } };
|
86
|
+
}
|
87
|
+
async function readSchemaFromFileOrDirectory(schemaPath) {
|
88
|
+
let stats;
|
89
|
+
try {
|
90
|
+
stats = await stat(schemaPath);
|
91
|
+
} catch (e) {
|
92
|
+
if (e.code === "ENOENT") {
|
93
|
+
return { ok: false, error: { kind: "NotFound", path: schemaPath } };
|
94
|
+
}
|
95
|
+
throw e;
|
96
|
+
}
|
97
|
+
if (stats.isFile()) {
|
98
|
+
return readSchemaFromSingleFile(schemaPath);
|
99
|
+
}
|
100
|
+
if (stats.isDirectory()) {
|
101
|
+
return readSchemaFromDirectory(schemaPath);
|
102
|
+
}
|
103
|
+
return { ok: false, error: { kind: "WrongType", path: schemaPath, expectedTypes: ["file", "directory"] } };
|
104
|
+
}
|
105
|
+
async function getSchemaWithPathInternal(schemaPathFromArgs, schemaPathFromConfig, { cwd, argumentName }) {
|
106
|
+
if (schemaPathFromArgs) {
|
107
|
+
const absPath = import_path.default.resolve(cwd, schemaPathFromArgs);
|
108
|
+
const customSchemaResult = await readSchemaFromFileOrDirectory(absPath);
|
109
|
+
if (!customSchemaResult.ok) {
|
110
|
+
const relPath = import_path.default.relative(cwd, absPath);
|
111
|
+
throw new Error(
|
112
|
+
`Could not load \`${argumentName}\` from provided path \`${relPath}\`: ${renderLookupError(
|
113
|
+
customSchemaResult.error
|
114
|
+
)}`
|
115
|
+
);
|
116
|
+
}
|
117
|
+
return customSchemaResult;
|
118
|
+
}
|
119
|
+
const prismaConfigResult = await readSchemaFromPrismaConfigBasedLocation(schemaPathFromConfig);
|
120
|
+
if (prismaConfigResult.ok) {
|
121
|
+
return prismaConfigResult;
|
122
|
+
}
|
123
|
+
const pkgJsonResult = await getSchemaFromPackageJson(cwd);
|
124
|
+
if (pkgJsonResult.ok) {
|
125
|
+
return pkgJsonResult;
|
126
|
+
}
|
127
|
+
const defaultResult = await getDefaultSchema(cwd);
|
128
|
+
if (defaultResult.ok) {
|
129
|
+
return defaultResult;
|
130
|
+
}
|
131
|
+
return {
|
132
|
+
ok: false,
|
133
|
+
error: defaultResult.error
|
134
|
+
};
|
135
|
+
}
|
136
|
+
function renderLookupError(error) {
|
137
|
+
switch (error.kind) {
|
138
|
+
case "NotFound": {
|
139
|
+
const expected = error.expectedType ?? "file or directory";
|
140
|
+
return `${expected} not found`;
|
141
|
+
}
|
142
|
+
case "WrongType":
|
143
|
+
return `expected ${error.expectedTypes.join(" or ")}`;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
function renderDefaultLookupError(error, cwd) {
|
147
|
+
const parts = [
|
148
|
+
`Could not find Prisma Schema that is required for this command.`,
|
149
|
+
`You can either provide it with ${(0, import_chunk_PG5FDKSF.green)("`--schema`")} argument,`,
|
150
|
+
`set it in your ${(0, import_chunk_PG5FDKSF.green)("`prisma.config.ts`")},`,
|
151
|
+
`set it as ${(0, import_chunk_PG5FDKSF.green)("`prisma.schema`")} in your ${(0, import_chunk_PG5FDKSF.green)("package.json")},`,
|
152
|
+
`or put it into the default location (${(0, import_chunk_PG5FDKSF.green)("`./prisma/schema.prisma`")}, or ${(0, import_chunk_PG5FDKSF.green)("`./schema.prisma`")}.`,
|
153
|
+
"Checked following paths:\n"
|
154
|
+
];
|
155
|
+
const printedPaths = /* @__PURE__ */ new Set();
|
156
|
+
for (const failure of error.failures) {
|
157
|
+
const filePath = failure.path;
|
158
|
+
if (!printedPaths.has(failure.path)) {
|
159
|
+
parts.push(`${import_path.default.relative(cwd, filePath)}: ${renderLookupError(failure.error)}`);
|
160
|
+
printedPaths.add(filePath);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
parts.push("\nSee also https://pris.ly/d/prisma-schema-location");
|
164
|
+
return parts.join("\n");
|
165
|
+
}
|
166
|
+
async function getPrismaConfigFromPackageJson(cwd) {
|
167
|
+
const pkgJson = await (0, import_chunk_PSFQKG2Q.readPackageUp)({ cwd, normalize: false });
|
168
|
+
const prismaPropertyFromPkgJson = pkgJson?.packageJson?.prisma;
|
169
|
+
if (!pkgJson) {
|
170
|
+
return null;
|
171
|
+
}
|
172
|
+
return {
|
173
|
+
data: prismaPropertyFromPkgJson,
|
174
|
+
packagePath: pkgJson.path
|
175
|
+
};
|
176
|
+
}
|
177
|
+
async function readSchemaFromPrismaConfigBasedLocation(schemaPathFromConfig) {
|
178
|
+
if (!schemaPathFromConfig) {
|
179
|
+
return {
|
180
|
+
ok: false,
|
181
|
+
error: { kind: "PrismaConfigNotConfigured" }
|
182
|
+
};
|
183
|
+
}
|
184
|
+
const schemaResult = await readSchemaFromFileOrDirectory(schemaPathFromConfig);
|
185
|
+
if (!schemaResult.ok) {
|
186
|
+
throw new Error(
|
187
|
+
`Could not load schema from \`${schemaPathFromConfig}\` provided by "prisma.config.ts"\`: ${renderLookupError(
|
188
|
+
schemaResult.error
|
189
|
+
)}`
|
190
|
+
);
|
191
|
+
}
|
192
|
+
return schemaResult;
|
193
|
+
}
|
194
|
+
async function getSchemaFromPackageJson(cwd) {
|
195
|
+
const prismaConfig = await getPrismaConfigFromPackageJson(cwd);
|
196
|
+
debug("prismaConfig", prismaConfig);
|
197
|
+
if (!prismaConfig || !prismaConfig.data?.schema) {
|
198
|
+
return { ok: false, error: { kind: "PackageJsonNotConfigured" } };
|
199
|
+
}
|
200
|
+
const schemaPathFromPkgJson = prismaConfig.data.schema;
|
201
|
+
if (typeof schemaPathFromPkgJson !== "string") {
|
202
|
+
throw new Error(
|
203
|
+
`Provided schema path \`${schemaPathFromPkgJson}\` from \`${import_path.default.relative(
|
204
|
+
cwd,
|
205
|
+
prismaConfig.packagePath
|
206
|
+
)}\` must be of type string`
|
207
|
+
);
|
208
|
+
}
|
209
|
+
const absoluteSchemaPath = import_path.default.isAbsolute(schemaPathFromPkgJson) ? schemaPathFromPkgJson : import_path.default.resolve(import_path.default.dirname(prismaConfig.packagePath), schemaPathFromPkgJson);
|
210
|
+
const lookupResult = await readSchemaFromFileOrDirectory(absoluteSchemaPath);
|
211
|
+
if (!lookupResult.ok) {
|
212
|
+
throw new Error(
|
213
|
+
`Could not load schema from \`${import_path.default.relative(
|
214
|
+
cwd,
|
215
|
+
absoluteSchemaPath
|
216
|
+
)}\` provided by "prisma.schema" config of \`${import_path.default.relative(
|
217
|
+
cwd,
|
218
|
+
prismaConfig.packagePath
|
219
|
+
)}\`: ${renderLookupError(lookupResult.error)}`
|
220
|
+
);
|
221
|
+
}
|
222
|
+
return lookupResult;
|
223
|
+
}
|
224
|
+
async function getDefaultSchema(cwd, failures = []) {
|
225
|
+
const lookupPaths = [import_path.default.join(cwd, "schema.prisma"), import_path.default.join(cwd, "prisma", "schema.prisma")];
|
226
|
+
for (const path2 of lookupPaths) {
|
227
|
+
debug(`Checking existence of ${path2}`);
|
228
|
+
const schema = await readSchemaFromSingleFile(path2);
|
229
|
+
if (!schema.ok) {
|
230
|
+
failures.push({ path: path2, error: schema.error });
|
231
|
+
continue;
|
232
|
+
}
|
233
|
+
return schema;
|
234
|
+
}
|
235
|
+
return {
|
236
|
+
ok: false,
|
237
|
+
error: {
|
238
|
+
kind: "NotFoundMultipleLocations",
|
239
|
+
failures
|
240
|
+
}
|
241
|
+
};
|
242
|
+
}
|