@powerlines/plugin-prisma 0.4.45 → 0.4.47
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-B-xjmX6K.mjs +146 -0
- package/dist/client-generator-BGpgi16l.mjs +146 -0
- package/dist/client-generator-CtfzFAPm.cjs +152 -0
- package/dist/client-generator-zg9dQfpm.cjs +152 -0
- package/dist/get-schema-Dq1-Jwvo.cjs +138 -0
- package/dist/helpers/client-generator.cjs +4 -0
- package/dist/helpers/client-generator.mjs +3 -0
- package/dist/helpers/get-schema.cjs +4 -0
- package/dist/helpers/get-schema.mjs +98 -0
- package/dist/helpers/index.cjs +10 -0
- package/dist/helpers/index.mjs +6 -0
- package/dist/helpers/schema-creator.cjs +62 -0
- package/dist/helpers/schema-creator.mjs +60 -0
- package/dist/helpers/typed-sql.cjs +38 -0
- package/dist/helpers/typed-sql.mjs +36 -0
- package/dist/index.cjs +147 -0
- package/dist/index.mjs +143 -0
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.mjs +4 -0
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.mjs +1 -0
- package/dist/types/prisma.cjs +0 -0
- package/dist/types/prisma.mjs +1 -0
- package/package.json +5 -5
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { t as PowerlinesClientGenerator } from "./client-generator-BGpgi16l.mjs";
|
|
2
|
+
import { getSchema } from "./helpers/get-schema.mjs";
|
|
3
|
+
import { PrismaSchemaCreator } from "./helpers/schema-creator.mjs";
|
|
4
|
+
import { introspectSql } from "./helpers/typed-sql.mjs";
|
|
5
|
+
import { defaultRegistry } from "@prisma/client-generator-registry";
|
|
6
|
+
import { enginesVersion } from "@prisma/engines";
|
|
7
|
+
import { extractPreviewFeatures, getDMMF, getGenerators, validatePrismaConfigWithDatasource } from "@prisma/internals";
|
|
8
|
+
import * as prismaPostgres from "@pulumi/prisma-postgres";
|
|
9
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
10
|
+
import { appendPath } from "@stryke/path/append";
|
|
11
|
+
import { findBasePath } from "@stryke/path/common";
|
|
12
|
+
import { relativePath } from "@stryke/path/find";
|
|
13
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
14
|
+
import { constantCase } from "@stryke/string-format/constant-case";
|
|
15
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
16
|
+
import defu from "defu";
|
|
17
|
+
import { getConfigPath, replacePathTokens } from "powerlines/plugin-utils";
|
|
18
|
+
|
|
19
|
+
//#region src/index.ts
|
|
20
|
+
/**
|
|
21
|
+
* A Powerlines plugin to integrate Prisma for code generation.
|
|
22
|
+
*
|
|
23
|
+
* @param options - The plugin options.
|
|
24
|
+
* @returns A Powerlines plugin instance.
|
|
25
|
+
*/
|
|
26
|
+
const plugin = (options = {}) => {
|
|
27
|
+
return {
|
|
28
|
+
name: "prisma",
|
|
29
|
+
config() {
|
|
30
|
+
return { prisma: defu(options, {
|
|
31
|
+
schema: joinPaths(this.config.root, "prisma", "*.prisma"),
|
|
32
|
+
configFile: options.configFile || getConfigPath(this, "prisma.config"),
|
|
33
|
+
runtime: options.runtime || "nodejs",
|
|
34
|
+
outputPath: joinPaths("{builtinPath}", "prisma"),
|
|
35
|
+
prismaPostgres: options.prismaPostgres ? {
|
|
36
|
+
projectId: this.config.name,
|
|
37
|
+
region: "us-east-1"
|
|
38
|
+
} : void 0
|
|
39
|
+
}) };
|
|
40
|
+
},
|
|
41
|
+
async configResolved() {
|
|
42
|
+
this.dependencies["@prisma/ppg"] = "latest";
|
|
43
|
+
this.config.prisma.configFile = replacePathTokens(this, this.config.prisma.configFile);
|
|
44
|
+
if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
45
|
+
this.config.prisma.schema = toArray(this.config.prisma.schema).map((schemaPath) => replacePathTokens(this, schemaPath));
|
|
46
|
+
if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
47
|
+
this.config.prisma.outputPath = replacePathTokens(this, this.config.prisma.outputPath);
|
|
48
|
+
this.prisma ??= {};
|
|
49
|
+
this.prisma.config = validatePrismaConfigWithDatasource({
|
|
50
|
+
config: this.config.prisma,
|
|
51
|
+
cmd: "generate --sql"
|
|
52
|
+
});
|
|
53
|
+
const schemaRootDir = appendPath(appendPath(findBasePath(this.config.prisma.schema), this.config.root), this.workspaceConfig.workspaceRoot);
|
|
54
|
+
this.prisma.schema ??= {
|
|
55
|
+
schemaRootDir,
|
|
56
|
+
loadedFromPathForLogMessages: relativePath(this.config.root, schemaRootDir),
|
|
57
|
+
schemaPath: schemaRootDir,
|
|
58
|
+
schemas: [],
|
|
59
|
+
schemaFiles: [],
|
|
60
|
+
generators: [],
|
|
61
|
+
datasources: [],
|
|
62
|
+
warnings: [],
|
|
63
|
+
primaryDatasource: void 0
|
|
64
|
+
};
|
|
65
|
+
this.prisma.schema.schemas = await Promise.all((await this.fs.glob(this.config.prisma.schema.map((schema) => schema.includes("*") || this.fs.isFileSync(schema) ? schema : joinPaths(schema, "**/*.prisma")))).map(async (schema) => getSchema(schema)));
|
|
66
|
+
this.prisma.schema = this.prisma.schema.schemas.reduce((ret, schema) => {
|
|
67
|
+
ret.datasources.push(...schema.datasources);
|
|
68
|
+
ret.generators.push(...schema.generators);
|
|
69
|
+
ret.warnings.push(...schema.warnings);
|
|
70
|
+
ret.schemaFiles.push([schema.path, schema.content]);
|
|
71
|
+
return ret;
|
|
72
|
+
}, this.prisma.schema);
|
|
73
|
+
this.prisma.schema.primaryDatasource = this.prisma.schema.datasources.at(0);
|
|
74
|
+
this.prisma.schema.schemaPath = this.prisma.schema.schemas.at(0).path;
|
|
75
|
+
this.prisma.builder = new PrismaSchemaCreator(this);
|
|
76
|
+
},
|
|
77
|
+
async prepare() {
|
|
78
|
+
await this.prisma.builder.write();
|
|
79
|
+
this.prisma.previewFeatures = extractPreviewFeatures(this.prisma.schema.generators);
|
|
80
|
+
this.prisma.dmmf = await getDMMF({
|
|
81
|
+
datamodel: this.prisma.schema.schemaFiles,
|
|
82
|
+
previewFeatures: this.prisma.previewFeatures
|
|
83
|
+
});
|
|
84
|
+
const typedSql = await introspectSql(this);
|
|
85
|
+
let generators = await getGenerators({
|
|
86
|
+
schemaContext: this.prisma.schema,
|
|
87
|
+
printDownloadProgress: true,
|
|
88
|
+
version: enginesVersion,
|
|
89
|
+
typedSql,
|
|
90
|
+
allowNoModels: true,
|
|
91
|
+
registry: defaultRegistry.toInternal()
|
|
92
|
+
});
|
|
93
|
+
if (!generators || !generators.some((gen) => [
|
|
94
|
+
"prisma-client",
|
|
95
|
+
"prisma-client-js",
|
|
96
|
+
"prisma-client-ts"
|
|
97
|
+
].includes(gen.name || gen.getProvider()))) {
|
|
98
|
+
generators ??= [];
|
|
99
|
+
generators.push(new PowerlinesClientGenerator(this));
|
|
100
|
+
} else generators = generators.map((generator) => [
|
|
101
|
+
"prisma-client",
|
|
102
|
+
"prisma-client-js",
|
|
103
|
+
"prisma-client-ts"
|
|
104
|
+
].includes(generator.name || generator.getProvider()) ? new PowerlinesClientGenerator(this) : generator);
|
|
105
|
+
for (const generator of generators) try {
|
|
106
|
+
await generator.generate();
|
|
107
|
+
generator.stop();
|
|
108
|
+
} catch (err) {
|
|
109
|
+
generator.stop();
|
|
110
|
+
this.error(`Error while generating with ${generator.name || generator.getProvider()}: ${err instanceof Error ? err.message : String(err)}`);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
async deployPulumi() {
|
|
114
|
+
if (this.config.prisma.prismaPostgres) {
|
|
115
|
+
let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
|
|
116
|
+
if (!serviceToken) {
|
|
117
|
+
serviceToken = options.serviceToken;
|
|
118
|
+
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.");
|
|
119
|
+
else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
|
|
120
|
+
}
|
|
121
|
+
await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
|
|
122
|
+
const project = new prismaPostgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
|
|
123
|
+
const database = new prismaPostgres.Database("database", {
|
|
124
|
+
projectId: project.id,
|
|
125
|
+
name: `${this.config.prisma.prismaPostgres?.databaseName || `${kebabCase(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
|
|
126
|
+
region: `${this.config.prisma.prismaPostgres?.region}`
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
project,
|
|
130
|
+
database,
|
|
131
|
+
connection: new prismaPostgres.Connection("connection", {
|
|
132
|
+
databaseId: database.id,
|
|
133
|
+
name: `${constantCase(this.config.name)}_API_KEY`
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
export { plugin as default, plugin };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-prisma",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.47",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Powerlines plugin to generate project code and a Prisma client from a Prisma schema (PSL).",
|
|
6
6
|
"keywords": ["prisma", "powerlines", "storm-software", "powerlines-plugin"],
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
"typings": "dist/index.d.mts",
|
|
175
175
|
"files": ["dist/**/*"],
|
|
176
176
|
"dependencies": {
|
|
177
|
-
"@powerlines/plugin-pulumi": "^0.6.
|
|
177
|
+
"@powerlines/plugin-pulumi": "^0.6.6",
|
|
178
178
|
"@prisma/client-generator-registry": "^7.5.0",
|
|
179
179
|
"@prisma/config": "^7.5.0",
|
|
180
180
|
"@prisma/dmmf": "^7.5.0",
|
|
@@ -192,16 +192,16 @@
|
|
|
192
192
|
"defu": "^6.1.4",
|
|
193
193
|
"fp-ts": "^2.16.11",
|
|
194
194
|
"jiti": "^2.6.1",
|
|
195
|
-
"powerlines": "^0.42.
|
|
195
|
+
"powerlines": "^0.42.6",
|
|
196
196
|
"prisma-util": "^2.1.1",
|
|
197
197
|
"ts-pattern": "^5.9.0"
|
|
198
198
|
},
|
|
199
199
|
"devDependencies": {
|
|
200
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
200
|
+
"@powerlines/plugin-plugin": "^0.12.316",
|
|
201
201
|
"@prisma/client-generator-ts": "^7.5.0",
|
|
202
202
|
"@pulumi/pulumi": "^3.226.0",
|
|
203
203
|
"@types/node": "^25.5.0"
|
|
204
204
|
},
|
|
205
205
|
"publishConfig": { "access": "public" },
|
|
206
|
-
"gitHead": "
|
|
206
|
+
"gitHead": "af94c1952c9f2d293dac72a2d0ed3627be8d807d"
|
|
207
207
|
}
|