@powerlines/plugin-prisma 0.4.139 → 0.4.140
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/client-generator-BJPB8ZEI.mjs +146 -0
- package/dist/client-generator-BsfhD3cL.cjs +152 -0
- package/dist/client-generator-CFdQVkOA.mjs +146 -0
- package/dist/client-generator-DUxEfw1f.cjs +152 -0
- package/dist/get-schema-OhMkdmwI.cjs +138 -0
- package/dist/helpers/client-generator.cjs +4 -1
- package/dist/helpers/client-generator.mjs +3 -1
- package/dist/helpers/get-schema.cjs +4 -1
- package/dist/helpers/get-schema.mjs +98 -1
- package/dist/helpers/index.cjs +10 -1
- package/dist/helpers/index.mjs +6 -1
- package/dist/helpers/schema-creator.cjs +60 -12
- package/dist/helpers/schema-creator.mjs +58 -12
- package/dist/helpers/typed-sql.cjs +38 -3
- package/dist/helpers/typed-sql.mjs +36 -3
- package/dist/index.cjs +149 -1
- package/dist/index.mjs +144 -1
- package/dist/types/index.cjs +2 -1
- package/dist/types/index.mjs +4 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/types/prisma.mjs +1 -1
- package/package.json +5 -5
- package/dist/client-generator-B56cunrE.cjs +0 -2
- package/dist/client-generator-BD6A890_.cjs +0 -2
- package/dist/client-generator-BQvSCNNA.mjs +0 -2
- package/dist/client-generator-D6g8INQg.mjs +0 -2
- package/dist/get-schema-BUxb6ANl.cjs +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let _prisma_get_platform = require("@prisma/get-platform");
|
|
29
|
+
let _prisma_prisma_schema_wasm = require("@prisma/prisma-schema-wasm");
|
|
30
|
+
_prisma_prisma_schema_wasm = __toESM(_prisma_prisma_schema_wasm, 1);
|
|
31
|
+
let fp_ts_Either = require("fp-ts/Either");
|
|
32
|
+
fp_ts_Either = __toESM(fp_ts_Either, 1);
|
|
33
|
+
let fp_ts_lib_function = require("fp-ts/lib/function");
|
|
34
|
+
let ts_pattern = require("ts-pattern");
|
|
35
|
+
|
|
36
|
+
//#region src/helpers/get-schema.ts
|
|
37
|
+
async function resolveBinaryTargets(generator) {
|
|
38
|
+
for (const binaryTarget of generator.binaryTargets) {
|
|
39
|
+
if (binaryTarget.fromEnvVar && process.env[binaryTarget.fromEnvVar]) {
|
|
40
|
+
const value = JSON.parse(process.env[binaryTarget.fromEnvVar]);
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
generator.binaryTargets = value.map((v) => ({
|
|
43
|
+
fromEnvVar: null,
|
|
44
|
+
value: v
|
|
45
|
+
}));
|
|
46
|
+
await resolveBinaryTargets(generator);
|
|
47
|
+
} else binaryTarget.value = value;
|
|
48
|
+
}
|
|
49
|
+
if (binaryTarget.value === "native") {
|
|
50
|
+
binaryTarget.value = await (0, _prisma_get_platform.getBinaryTargetForCurrentPlatform)();
|
|
51
|
+
binaryTarget.native = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (generator.binaryTargets.length === 0) generator.binaryTargets = [{
|
|
55
|
+
fromEnvVar: null,
|
|
56
|
+
value: await (0, _prisma_get_platform.getBinaryTargetForCurrentPlatform)(),
|
|
57
|
+
native: true
|
|
58
|
+
}];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the Prisma schema using the provided options.
|
|
62
|
+
*
|
|
63
|
+
* @param schemaPath - The path to the Prisma schema file.
|
|
64
|
+
* @returns The Prisma schema.
|
|
65
|
+
*/
|
|
66
|
+
async function resolveDataModel(schemaPath) {
|
|
67
|
+
const configEither = (0, fp_ts_lib_function.pipe)(fp_ts_Either.tryCatch(() => {
|
|
68
|
+
if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) _prisma_prisma_schema_wasm.default.debug_panic();
|
|
69
|
+
const params = JSON.stringify({
|
|
70
|
+
prismaSchema: schemaPath,
|
|
71
|
+
datasourceOverrides: {},
|
|
72
|
+
ignoreEnvVarErrors: true,
|
|
73
|
+
env: process.env
|
|
74
|
+
});
|
|
75
|
+
return _prisma_prisma_schema_wasm.default.get_config(params);
|
|
76
|
+
}, (e) => ({
|
|
77
|
+
type: "wasm-error",
|
|
78
|
+
reason: "(get-config wasm)",
|
|
79
|
+
error: e
|
|
80
|
+
})), fp_ts_Either.map((result) => ({ result })), fp_ts_Either.chainW(({ result }) => fp_ts_Either.tryCatch(() => JSON.parse(result), (e) => ({
|
|
81
|
+
type: "parse-json",
|
|
82
|
+
reason: "Unable to parse JSON",
|
|
83
|
+
error: e
|
|
84
|
+
}))), fp_ts_Either.chainW((response) => {
|
|
85
|
+
if (response.errors.length > 0) return fp_ts_Either.left({
|
|
86
|
+
type: "validation-error",
|
|
87
|
+
reason: "(get-config wasm)",
|
|
88
|
+
error: response.errors
|
|
89
|
+
});
|
|
90
|
+
return fp_ts_Either.right(response.config);
|
|
91
|
+
}));
|
|
92
|
+
if (fp_ts_Either.isRight(configEither)) {
|
|
93
|
+
const { right: data } = configEither;
|
|
94
|
+
for (const generator of data.generators) await resolveBinaryTargets(generator);
|
|
95
|
+
return Promise.resolve(data);
|
|
96
|
+
}
|
|
97
|
+
throw (0, ts_pattern.match)(configEither.left).with({ type: "wasm-error" }, (e) => {
|
|
98
|
+
return /* @__PURE__ */ new Error(`Prisma get-config Wasm runtime error: ${e.error.message}`);
|
|
99
|
+
}).with({ type: "validation-error" }, (e) => {
|
|
100
|
+
return /* @__PURE__ */ new Error(`Prisma get-config validation error: ${e.error.map((err) => err.message).join(", ")}`);
|
|
101
|
+
}).otherwise((e) => {
|
|
102
|
+
return /* @__PURE__ */ new Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the Prisma schema using the provided path.
|
|
107
|
+
*
|
|
108
|
+
* @param path - The path to the Prisma schema file.
|
|
109
|
+
* @returns The Prisma schema.
|
|
110
|
+
*/
|
|
111
|
+
async function getSchema(path) {
|
|
112
|
+
const schema = {
|
|
113
|
+
path,
|
|
114
|
+
content: "",
|
|
115
|
+
generators: [],
|
|
116
|
+
datasources: [],
|
|
117
|
+
warnings: []
|
|
118
|
+
};
|
|
119
|
+
const dataModel = await resolveDataModel(path);
|
|
120
|
+
return {
|
|
121
|
+
...schema,
|
|
122
|
+
...dataModel
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
Object.defineProperty(exports, '__toESM', {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return __toESM;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, 'getSchema', {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return getSchema;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_client_generator = require('../client-generator-DUxEfw1f.cjs');
|
|
3
|
+
|
|
4
|
+
exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
+
|
|
4
|
+
exports.getSchema = require_get_schema.getSchema;
|
|
@@ -1 +1,98 @@
|
|
|
1
|
-
import{getBinaryTargetForCurrentPlatform
|
|
1
|
+
import { getBinaryTargetForCurrentPlatform } from "@prisma/get-platform";
|
|
2
|
+
import prismaSchemaWasm from "@prisma/prisma-schema-wasm";
|
|
3
|
+
import * as E from "fp-ts/Either";
|
|
4
|
+
import { pipe } from "fp-ts/lib/function";
|
|
5
|
+
import { match } from "ts-pattern";
|
|
6
|
+
|
|
7
|
+
//#region src/helpers/get-schema.ts
|
|
8
|
+
async function resolveBinaryTargets(generator) {
|
|
9
|
+
for (const binaryTarget of generator.binaryTargets) {
|
|
10
|
+
if (binaryTarget.fromEnvVar && process.env[binaryTarget.fromEnvVar]) {
|
|
11
|
+
const value = JSON.parse(process.env[binaryTarget.fromEnvVar]);
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
generator.binaryTargets = value.map((v) => ({
|
|
14
|
+
fromEnvVar: null,
|
|
15
|
+
value: v
|
|
16
|
+
}));
|
|
17
|
+
await resolveBinaryTargets(generator);
|
|
18
|
+
} else binaryTarget.value = value;
|
|
19
|
+
}
|
|
20
|
+
if (binaryTarget.value === "native") {
|
|
21
|
+
binaryTarget.value = await getBinaryTargetForCurrentPlatform();
|
|
22
|
+
binaryTarget.native = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (generator.binaryTargets.length === 0) generator.binaryTargets = [{
|
|
26
|
+
fromEnvVar: null,
|
|
27
|
+
value: await getBinaryTargetForCurrentPlatform(),
|
|
28
|
+
native: true
|
|
29
|
+
}];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the Prisma schema using the provided options.
|
|
33
|
+
*
|
|
34
|
+
* @param schemaPath - The path to the Prisma schema file.
|
|
35
|
+
* @returns The Prisma schema.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveDataModel(schemaPath) {
|
|
38
|
+
const configEither = pipe(E.tryCatch(() => {
|
|
39
|
+
if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) prismaSchemaWasm.debug_panic();
|
|
40
|
+
const params = JSON.stringify({
|
|
41
|
+
prismaSchema: schemaPath,
|
|
42
|
+
datasourceOverrides: {},
|
|
43
|
+
ignoreEnvVarErrors: true,
|
|
44
|
+
env: process.env
|
|
45
|
+
});
|
|
46
|
+
return prismaSchemaWasm.get_config(params);
|
|
47
|
+
}, (e) => ({
|
|
48
|
+
type: "wasm-error",
|
|
49
|
+
reason: "(get-config wasm)",
|
|
50
|
+
error: e
|
|
51
|
+
})), E.map((result) => ({ result })), E.chainW(({ result }) => E.tryCatch(() => JSON.parse(result), (e) => ({
|
|
52
|
+
type: "parse-json",
|
|
53
|
+
reason: "Unable to parse JSON",
|
|
54
|
+
error: e
|
|
55
|
+
}))), E.chainW((response) => {
|
|
56
|
+
if (response.errors.length > 0) return E.left({
|
|
57
|
+
type: "validation-error",
|
|
58
|
+
reason: "(get-config wasm)",
|
|
59
|
+
error: response.errors
|
|
60
|
+
});
|
|
61
|
+
return E.right(response.config);
|
|
62
|
+
}));
|
|
63
|
+
if (E.isRight(configEither)) {
|
|
64
|
+
const { right: data } = configEither;
|
|
65
|
+
for (const generator of data.generators) await resolveBinaryTargets(generator);
|
|
66
|
+
return Promise.resolve(data);
|
|
67
|
+
}
|
|
68
|
+
throw match(configEither.left).with({ type: "wasm-error" }, (e) => {
|
|
69
|
+
return /* @__PURE__ */ new Error(`Prisma get-config Wasm runtime error: ${e.error.message}`);
|
|
70
|
+
}).with({ type: "validation-error" }, (e) => {
|
|
71
|
+
return /* @__PURE__ */ new Error(`Prisma get-config validation error: ${e.error.map((err) => err.message).join(", ")}`);
|
|
72
|
+
}).otherwise((e) => {
|
|
73
|
+
return /* @__PURE__ */ new Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves the Prisma schema using the provided path.
|
|
78
|
+
*
|
|
79
|
+
* @param path - The path to the Prisma schema file.
|
|
80
|
+
* @returns The Prisma schema.
|
|
81
|
+
*/
|
|
82
|
+
async function getSchema(path) {
|
|
83
|
+
const schema = {
|
|
84
|
+
path,
|
|
85
|
+
content: "",
|
|
86
|
+
generators: [],
|
|
87
|
+
datasources: [],
|
|
88
|
+
warnings: []
|
|
89
|
+
};
|
|
90
|
+
const dataModel = await resolveDataModel(path);
|
|
91
|
+
return {
|
|
92
|
+
...schema,
|
|
93
|
+
...dataModel
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { getSchema };
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
+
const require_client_generator = require('../client-generator-DUxEfw1f.cjs');
|
|
4
|
+
const require_helpers_schema_creator = require('./schema-creator.cjs');
|
|
5
|
+
const require_helpers_typed_sql = require('./typed-sql.cjs');
|
|
6
|
+
|
|
7
|
+
exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
|
|
8
|
+
exports.PrismaSchemaCreator = require_helpers_schema_creator.PrismaSchemaCreator;
|
|
9
|
+
exports.getSchema = require_get_schema.getSchema;
|
|
10
|
+
exports.introspectSql = require_helpers_typed_sql.introspectSql;
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import { t as PowerlinesClientGenerator } from "../client-generator-CFdQVkOA.mjs";
|
|
2
|
+
import { getSchema } from "./get-schema.mjs";
|
|
3
|
+
import { PrismaSchemaCreator } from "./schema-creator.mjs";
|
|
4
|
+
import { introspectSql } from "./typed-sql.mjs";
|
|
5
|
+
|
|
6
|
+
export { PowerlinesClientGenerator, PrismaSchemaCreator, getSchema, introspectSql };
|
|
@@ -1,14 +1,62 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
+
let prisma_util_schema_creator = require("prisma-util/schema-creator");
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/schema-creator.ts
|
|
6
|
+
/**
|
|
7
|
+
* Prisma schema creator that allows building a schema via code.
|
|
8
|
+
*/
|
|
9
|
+
var PrismaSchemaCreator = class extends prisma_util_schema_creator.SchemaCreator {
|
|
10
|
+
/** Prisma plugin context */
|
|
11
|
+
#context;
|
|
12
|
+
get generators() {
|
|
13
|
+
return this.#context.prisma.schema.generators;
|
|
14
|
+
}
|
|
15
|
+
set generators(value) {
|
|
16
|
+
this.#context.prisma.schema.generators = value;
|
|
17
|
+
}
|
|
18
|
+
constructor(context) {
|
|
19
|
+
super();
|
|
20
|
+
this.#context = context;
|
|
21
|
+
this.#context.prisma ??= {};
|
|
22
|
+
this.#context.prisma.schema ??= {
|
|
23
|
+
generators: [],
|
|
24
|
+
datasources: [],
|
|
25
|
+
warnings: []
|
|
26
|
+
};
|
|
27
|
+
this.#context.prisma.schema.generators.forEach((generator) => {
|
|
28
|
+
this.pushGenerator(generator);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
pushGenerator(generator) {
|
|
32
|
+
if (this.generators.some((gen) => gen.name === generator.name)) this.generators = [...this.generators.filter((gen) => gen.name !== generator.name), generator];
|
|
33
|
+
else this.generators.push(generator);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
build() {
|
|
37
|
+
let schema = super.build();
|
|
38
|
+
for (const generator of this.generators) schema = `
|
|
39
|
+
generator ${generator.name} {
|
|
40
|
+
provider = "${generator.provider.value}"
|
|
41
|
+
output = "${generator.output?.value}"${generator.previewFeatures && generator.previewFeatures.length > 0 ? `
|
|
42
|
+
previewFeatures = [${generator.previewFeatures.map((feature) => `"${feature}"`).join(", ")}]` : ""}${generator.config && Object.keys(generator.config).length > 0 ? Object.entries(generator.config).map(([key, value]) => {
|
|
43
|
+
if (Array.isArray(value)) return `${key} = [${value.map((v) => `"${v}"`).join(", ")}]`;
|
|
44
|
+
else return `${key} = "${value}"`;
|
|
45
|
+
}).join("\n ") : ""}${generator.binaryTargets && generator.binaryTargets.length > 0 ? `
|
|
46
|
+
binaryTargets = [${generator.binaryTargets.map((bt) => `"${bt.value}"`).join(", ")}]` : ""}${generator.envPaths?.rootEnvPath || generator.envPaths?.schemaEnvPath ? `
|
|
47
|
+
env = {${generator.envPaths?.rootEnvPath ? `
|
|
48
|
+
root = "${generator.envPaths.rootEnvPath}"` : ""}${generator.envPaths?.schemaEnvPath ? `
|
|
49
|
+
schema = "${generator.envPaths.schemaEnvPath}"` : ""}
|
|
50
|
+
}` : ""}
|
|
12
51
|
}
|
|
13
52
|
|
|
14
|
-
${
|
|
53
|
+
${schema}`;
|
|
54
|
+
return schema;
|
|
55
|
+
}
|
|
56
|
+
async write() {
|
|
57
|
+
await this.#context.fs.write(this.#context.config.prisma.schema, this.build());
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.PrismaSchemaCreator = PrismaSchemaCreator;
|
|
@@ -1,14 +1,60 @@
|
|
|
1
|
-
import{SchemaCreator
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { SchemaCreator } from "prisma-util/schema-creator";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/schema-creator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Prisma schema creator that allows building a schema via code.
|
|
6
|
+
*/
|
|
7
|
+
var PrismaSchemaCreator = class extends SchemaCreator {
|
|
8
|
+
/** Prisma plugin context */
|
|
9
|
+
#context;
|
|
10
|
+
get generators() {
|
|
11
|
+
return this.#context.prisma.schema.generators;
|
|
12
|
+
}
|
|
13
|
+
set generators(value) {
|
|
14
|
+
this.#context.prisma.schema.generators = value;
|
|
15
|
+
}
|
|
16
|
+
constructor(context) {
|
|
17
|
+
super();
|
|
18
|
+
this.#context = context;
|
|
19
|
+
this.#context.prisma ??= {};
|
|
20
|
+
this.#context.prisma.schema ??= {
|
|
21
|
+
generators: [],
|
|
22
|
+
datasources: [],
|
|
23
|
+
warnings: []
|
|
24
|
+
};
|
|
25
|
+
this.#context.prisma.schema.generators.forEach((generator) => {
|
|
26
|
+
this.pushGenerator(generator);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
pushGenerator(generator) {
|
|
30
|
+
if (this.generators.some((gen) => gen.name === generator.name)) this.generators = [...this.generators.filter((gen) => gen.name !== generator.name), generator];
|
|
31
|
+
else this.generators.push(generator);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
build() {
|
|
35
|
+
let schema = super.build();
|
|
36
|
+
for (const generator of this.generators) schema = `
|
|
37
|
+
generator ${generator.name} {
|
|
38
|
+
provider = "${generator.provider.value}"
|
|
39
|
+
output = "${generator.output?.value}"${generator.previewFeatures && generator.previewFeatures.length > 0 ? `
|
|
40
|
+
previewFeatures = [${generator.previewFeatures.map((feature) => `"${feature}"`).join(", ")}]` : ""}${generator.config && Object.keys(generator.config).length > 0 ? Object.entries(generator.config).map(([key, value]) => {
|
|
41
|
+
if (Array.isArray(value)) return `${key} = [${value.map((v) => `"${v}"`).join(", ")}]`;
|
|
42
|
+
else return `${key} = "${value}"`;
|
|
43
|
+
}).join("\n ") : ""}${generator.binaryTargets && generator.binaryTargets.length > 0 ? `
|
|
44
|
+
binaryTargets = [${generator.binaryTargets.map((bt) => `"${bt.value}"`).join(", ")}]` : ""}${generator.envPaths?.rootEnvPath || generator.envPaths?.schemaEnvPath ? `
|
|
45
|
+
env = {${generator.envPaths?.rootEnvPath ? `
|
|
46
|
+
root = "${generator.envPaths.rootEnvPath}"` : ""}${generator.envPaths?.schemaEnvPath ? `
|
|
47
|
+
schema = "${generator.envPaths.schemaEnvPath}"` : ""}
|
|
48
|
+
}` : ""}
|
|
12
49
|
}
|
|
13
50
|
|
|
14
|
-
${
|
|
51
|
+
${schema}`;
|
|
52
|
+
return schema;
|
|
53
|
+
}
|
|
54
|
+
async write() {
|
|
55
|
+
await this.#context.fs.write(this.#context.config.prisma.schema, this.build());
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { PrismaSchemaCreator };
|
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
+
let _prisma_internals = require("@prisma/internals");
|
|
4
|
+
let _prisma_migrate = require("@prisma/migrate");
|
|
5
|
+
let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
6
|
+
let _stryke_path_join = require("@stryke/path/join");
|
|
7
|
+
|
|
8
|
+
//#region src/helpers/typed-sql.ts
|
|
9
|
+
async function readTypedSqlFiles(context, typedSqlDirPath) {
|
|
10
|
+
const files = await context.fs.list(typedSqlDirPath);
|
|
11
|
+
const results = [];
|
|
12
|
+
for (const fileName of files) {
|
|
13
|
+
if ((0, _stryke_path_file_path_fns.findFileExtension)(fileName) !== ".sql") continue;
|
|
14
|
+
if (!(0, _prisma_internals.isValidJsIdentifier)((0, _stryke_path_file_path_fns.findFileName)(fileName, { withExtension: false }))) throw new Error(`${(0, _stryke_path_join.joinPaths)(typedSqlDirPath, fileName)} can not be used as a typed sql query: name must be a valid JS identifier`);
|
|
15
|
+
if ((0, _stryke_path_file_path_fns.findFileName)(fileName).startsWith("$")) throw new Error(`${(0, _stryke_path_join.joinPaths)(typedSqlDirPath, fileName)} can not be used as a typed sql query: name must not start with $`);
|
|
16
|
+
results.push({
|
|
17
|
+
name: (0, _stryke_path_file_path_fns.findFileName)(fileName, { withExtension: false }),
|
|
18
|
+
source: await context.fs.read((0, _stryke_path_join.joinPaths)(typedSqlDirPath, fileName)),
|
|
19
|
+
fileName: (0, _stryke_path_join.joinPaths)(typedSqlDirPath, fileName)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
async function introspectSql(context) {
|
|
25
|
+
const sqlFiles = await readTypedSqlFiles(context, (0, _prisma_internals.inferDirectoryConfig)(context.prisma.schema, context.prisma.config).typedSqlDirPath);
|
|
26
|
+
const introspectionResult = await (0, _prisma_migrate.introspectSql)(context.prisma.schema, context.prisma.config, context.config.root, sqlFiles);
|
|
27
|
+
if (introspectionResult.ok) return introspectionResult.queries;
|
|
28
|
+
const lines = [`Errors while reading sql files:\n`];
|
|
29
|
+
for (const { fileName, message } of introspectionResult.errors) {
|
|
30
|
+
lines.push(`In ${(0, _stryke_path_file_path_fns.relativePath)(process.cwd(), fileName)}:`);
|
|
31
|
+
lines.push(message);
|
|
32
|
+
lines.push("");
|
|
33
|
+
}
|
|
34
|
+
throw new Error(lines.join("\n"));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.introspectSql = introspectSql;
|
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
import{inferDirectoryConfig
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { inferDirectoryConfig, isValidJsIdentifier } from "@prisma/internals";
|
|
2
|
+
import { introspectSql as introspectSql$1 } from "@prisma/migrate";
|
|
3
|
+
import { findFileExtension, findFileName, relativePath } from "@stryke/path/file-path-fns";
|
|
4
|
+
import { joinPaths } from "@stryke/path/join";
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/typed-sql.ts
|
|
7
|
+
async function readTypedSqlFiles(context, typedSqlDirPath) {
|
|
8
|
+
const files = await context.fs.list(typedSqlDirPath);
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const fileName of files) {
|
|
11
|
+
if (findFileExtension(fileName) !== ".sql") continue;
|
|
12
|
+
if (!isValidJsIdentifier(findFileName(fileName, { withExtension: false }))) throw new Error(`${joinPaths(typedSqlDirPath, fileName)} can not be used as a typed sql query: name must be a valid JS identifier`);
|
|
13
|
+
if (findFileName(fileName).startsWith("$")) throw new Error(`${joinPaths(typedSqlDirPath, fileName)} can not be used as a typed sql query: name must not start with $`);
|
|
14
|
+
results.push({
|
|
15
|
+
name: findFileName(fileName, { withExtension: false }),
|
|
16
|
+
source: await context.fs.read(joinPaths(typedSqlDirPath, fileName)),
|
|
17
|
+
fileName: joinPaths(typedSqlDirPath, fileName)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
async function introspectSql(context) {
|
|
23
|
+
const sqlFiles = await readTypedSqlFiles(context, inferDirectoryConfig(context.prisma.schema, context.prisma.config).typedSqlDirPath);
|
|
24
|
+
const introspectionResult = await introspectSql$1(context.prisma.schema, context.prisma.config, context.config.root, sqlFiles);
|
|
25
|
+
if (introspectionResult.ok) return introspectionResult.queries;
|
|
26
|
+
const lines = [`Errors while reading sql files:\n`];
|
|
27
|
+
for (const { fileName, message } of introspectionResult.errors) {
|
|
28
|
+
lines.push(`In ${relativePath(process.cwd(), fileName)}:`);
|
|
29
|
+
lines.push(message);
|
|
30
|
+
lines.push("");
|
|
31
|
+
}
|
|
32
|
+
throw new Error(lines.join("\n"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { introspectSql };
|