@powerlines/plugin-prisma 0.4.44 → 0.4.45
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/package.json +5 -5
- package/dist/client-generator-BMVqvIaz.cjs +0 -152
- package/dist/client-generator-BlAmVcxP.cjs +0 -152
- package/dist/client-generator-DZuV_FU-.mjs +0 -146
- package/dist/client-generator-a3gfBXbv.mjs +0 -146
- package/dist/get-schema-Dq1-Jwvo.cjs +0 -138
- package/dist/helpers/client-generator.cjs +0 -4
- package/dist/helpers/client-generator.mjs +0 -3
- package/dist/helpers/get-schema.cjs +0 -4
- package/dist/helpers/get-schema.mjs +0 -98
- package/dist/helpers/index.cjs +0 -10
- package/dist/helpers/index.mjs +0 -6
- package/dist/helpers/schema-creator.cjs +0 -62
- package/dist/helpers/schema-creator.mjs +0 -60
- package/dist/helpers/typed-sql.cjs +0 -38
- package/dist/helpers/typed-sql.mjs +0 -36
- package/dist/index.cjs +0 -147
- package/dist/index.mjs +0 -143
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.mjs +0 -4
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.mjs +0 -1
- package/dist/types/prisma.cjs +0 -0
- package/dist/types/prisma.mjs +0 -1
|
@@ -1,138 +0,0 @@
|
|
|
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);
|
|
31
|
-
let fp_ts_Either = require("fp-ts/Either");
|
|
32
|
-
fp_ts_Either = __toESM(fp_ts_Either);
|
|
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 path - 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,98 +0,0 @@
|
|
|
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 path - 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
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_get_schema = require('../get-schema-Dq1-Jwvo.cjs');
|
|
3
|
-
const require_client_generator = require('../client-generator-BMVqvIaz.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
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { t as PowerlinesClientGenerator } from "../client-generator-a3gfBXbv.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,62 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_get_schema = require('../get-schema-Dq1-Jwvo.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
|
-
}` : ""}
|
|
51
|
-
}
|
|
52
|
-
|
|
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,60 +0,0 @@
|
|
|
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
|
-
}` : ""}
|
|
49
|
-
}
|
|
50
|
-
|
|
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,38 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_get_schema = require('../get-schema-Dq1-Jwvo.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,36 +0,0 @@
|
|
|
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 };
|
package/dist/index.cjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
const require_get_schema = require('./get-schema-Dq1-Jwvo.cjs');
|
|
3
|
-
const require_client_generator = require('./client-generator-BMVqvIaz.cjs');
|
|
4
|
-
const require_helpers_schema_creator = require('./helpers/schema-creator.cjs');
|
|
5
|
-
const require_helpers_typed_sql = require('./helpers/typed-sql.cjs');
|
|
6
|
-
let _prisma_client_generator_registry = require("@prisma/client-generator-registry");
|
|
7
|
-
let _prisma_engines = require("@prisma/engines");
|
|
8
|
-
let _prisma_internals = require("@prisma/internals");
|
|
9
|
-
let _pulumi_prisma_postgres = require("@pulumi/prisma-postgres");
|
|
10
|
-
_pulumi_prisma_postgres = require_get_schema.__toESM(_pulumi_prisma_postgres);
|
|
11
|
-
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
12
|
-
let _stryke_path_append = require("@stryke/path/append");
|
|
13
|
-
let _stryke_path_common = require("@stryke/path/common");
|
|
14
|
-
let _stryke_path_find = require("@stryke/path/find");
|
|
15
|
-
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
16
|
-
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
17
|
-
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
18
|
-
let defu = require("defu");
|
|
19
|
-
defu = require_get_schema.__toESM(defu);
|
|
20
|
-
let powerlines_plugin_utils = require("powerlines/plugin-utils");
|
|
21
|
-
|
|
22
|
-
//#region src/index.ts
|
|
23
|
-
/**
|
|
24
|
-
* A Powerlines plugin to integrate Prisma for code generation.
|
|
25
|
-
*
|
|
26
|
-
* @param options - The plugin options.
|
|
27
|
-
* @returns A Powerlines plugin instance.
|
|
28
|
-
*/
|
|
29
|
-
const plugin = (options = {}) => {
|
|
30
|
-
return {
|
|
31
|
-
name: "prisma",
|
|
32
|
-
config() {
|
|
33
|
-
return { prisma: (0, defu.default)(options, {
|
|
34
|
-
schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma", "*.prisma"),
|
|
35
|
-
configFile: options.configFile || (0, powerlines_plugin_utils.getConfigPath)(this, "prisma.config"),
|
|
36
|
-
runtime: options.runtime || "nodejs",
|
|
37
|
-
outputPath: (0, _stryke_path_join_paths.joinPaths)("{builtinPath}", "prisma"),
|
|
38
|
-
prismaPostgres: options.prismaPostgres ? {
|
|
39
|
-
projectId: this.config.name,
|
|
40
|
-
region: "us-east-1"
|
|
41
|
-
} : void 0
|
|
42
|
-
}) };
|
|
43
|
-
},
|
|
44
|
-
async configResolved() {
|
|
45
|
-
this.dependencies["@prisma/ppg"] = "latest";
|
|
46
|
-
this.config.prisma.configFile = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.configFile);
|
|
47
|
-
if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
48
|
-
this.config.prisma.schema = (0, _stryke_convert_to_array.toArray)(this.config.prisma.schema).map((schemaPath) => (0, powerlines_plugin_utils.replacePathTokens)(this, schemaPath));
|
|
49
|
-
if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
50
|
-
this.config.prisma.outputPath = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.outputPath);
|
|
51
|
-
this.prisma ??= {};
|
|
52
|
-
this.prisma.config = (0, _prisma_internals.validatePrismaConfigWithDatasource)({
|
|
53
|
-
config: this.config.prisma,
|
|
54
|
-
cmd: "generate --sql"
|
|
55
|
-
});
|
|
56
|
-
const schemaRootDir = (0, _stryke_path_append.appendPath)((0, _stryke_path_append.appendPath)((0, _stryke_path_common.findBasePath)(this.config.prisma.schema), this.config.root), this.workspaceConfig.workspaceRoot);
|
|
57
|
-
this.prisma.schema ??= {
|
|
58
|
-
schemaRootDir,
|
|
59
|
-
loadedFromPathForLogMessages: (0, _stryke_path_find.relativePath)(this.config.root, schemaRootDir),
|
|
60
|
-
schemaPath: schemaRootDir,
|
|
61
|
-
schemas: [],
|
|
62
|
-
schemaFiles: [],
|
|
63
|
-
generators: [],
|
|
64
|
-
datasources: [],
|
|
65
|
-
warnings: [],
|
|
66
|
-
primaryDatasource: void 0
|
|
67
|
-
};
|
|
68
|
-
this.prisma.schema.schemas = await Promise.all((await this.fs.glob(this.config.prisma.schema.map((schema) => schema.includes("*") || this.fs.isFileSync(schema) ? schema : (0, _stryke_path_join_paths.joinPaths)(schema, "**/*.prisma")))).map(async (schema) => require_get_schema.getSchema(schema)));
|
|
69
|
-
this.prisma.schema = this.prisma.schema.schemas.reduce((ret, schema) => {
|
|
70
|
-
ret.datasources.push(...schema.datasources);
|
|
71
|
-
ret.generators.push(...schema.generators);
|
|
72
|
-
ret.warnings.push(...schema.warnings);
|
|
73
|
-
ret.schemaFiles.push([schema.path, schema.content]);
|
|
74
|
-
return ret;
|
|
75
|
-
}, this.prisma.schema);
|
|
76
|
-
this.prisma.schema.primaryDatasource = this.prisma.schema.datasources.at(0);
|
|
77
|
-
this.prisma.schema.schemaPath = this.prisma.schema.schemas.at(0).path;
|
|
78
|
-
this.prisma.builder = new require_helpers_schema_creator.PrismaSchemaCreator(this);
|
|
79
|
-
},
|
|
80
|
-
async prepare() {
|
|
81
|
-
await this.prisma.builder.write();
|
|
82
|
-
this.prisma.previewFeatures = (0, _prisma_internals.extractPreviewFeatures)(this.prisma.schema.generators);
|
|
83
|
-
this.prisma.dmmf = await (0, _prisma_internals.getDMMF)({
|
|
84
|
-
datamodel: this.prisma.schema.schemaFiles,
|
|
85
|
-
previewFeatures: this.prisma.previewFeatures
|
|
86
|
-
});
|
|
87
|
-
const typedSql = await require_helpers_typed_sql.introspectSql(this);
|
|
88
|
-
let generators = await (0, _prisma_internals.getGenerators)({
|
|
89
|
-
schemaContext: this.prisma.schema,
|
|
90
|
-
printDownloadProgress: true,
|
|
91
|
-
version: _prisma_engines.enginesVersion,
|
|
92
|
-
typedSql,
|
|
93
|
-
allowNoModels: true,
|
|
94
|
-
registry: _prisma_client_generator_registry.defaultRegistry.toInternal()
|
|
95
|
-
});
|
|
96
|
-
if (!generators || !generators.some((gen) => [
|
|
97
|
-
"prisma-client",
|
|
98
|
-
"prisma-client-js",
|
|
99
|
-
"prisma-client-ts"
|
|
100
|
-
].includes(gen.name || gen.getProvider()))) {
|
|
101
|
-
generators ??= [];
|
|
102
|
-
generators.push(new require_client_generator.PowerlinesClientGenerator(this));
|
|
103
|
-
} else generators = generators.map((generator) => [
|
|
104
|
-
"prisma-client",
|
|
105
|
-
"prisma-client-js",
|
|
106
|
-
"prisma-client-ts"
|
|
107
|
-
].includes(generator.name || generator.getProvider()) ? new require_client_generator.PowerlinesClientGenerator(this) : generator);
|
|
108
|
-
for (const generator of generators) try {
|
|
109
|
-
await generator.generate();
|
|
110
|
-
generator.stop();
|
|
111
|
-
} catch (err) {
|
|
112
|
-
generator.stop();
|
|
113
|
-
this.error(`Error while generating with ${generator.name || generator.getProvider()}: ${err instanceof Error ? err.message : String(err)}`);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
async deployPulumi() {
|
|
117
|
-
if (this.config.prisma.prismaPostgres) {
|
|
118
|
-
let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
|
|
119
|
-
if (!serviceToken) {
|
|
120
|
-
serviceToken = options.serviceToken;
|
|
121
|
-
if (serviceToken) this.warn("If possible, please use the `PRISMA_SERVICE_TOKEN` environment variable instead of using the `serviceToken` option directly. The `serviceToken` option will work; however, this is a less secure method of configuration.");
|
|
122
|
-
else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
|
|
123
|
-
}
|
|
124
|
-
await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
|
|
125
|
-
const project = new _pulumi_prisma_postgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
|
|
126
|
-
const database = new _pulumi_prisma_postgres.Database("database", {
|
|
127
|
-
projectId: project.id,
|
|
128
|
-
name: `${this.config.prisma.prismaPostgres?.databaseName || `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
|
|
129
|
-
region: `${this.config.prisma.prismaPostgres?.region}`
|
|
130
|
-
});
|
|
131
|
-
return {
|
|
132
|
-
project,
|
|
133
|
-
database,
|
|
134
|
-
connection: new _pulumi_prisma_postgres.Connection("connection", {
|
|
135
|
-
databaseId: database.id,
|
|
136
|
-
name: `${(0, _stryke_string_format_constant_case.constantCase)(this.config.name)}_API_KEY`
|
|
137
|
-
})
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
//#endregion
|
|
146
|
-
exports.default = plugin;
|
|
147
|
-
exports.plugin = plugin;
|