@powerlines/plugin-prisma 0.4.43 → 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-BlAmVcxP.cjs +0 -152
- package/dist/client-generator-D-m-hiFR.mjs +0 -146
- package/dist/client-generator-DZuV_FU-.mjs +0 -146
- package/dist/client-generator-L-39odzA.cjs +0 -152
- 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
package/dist/index.mjs
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { t as PowerlinesClientGenerator } from "./client-generator-DZuV_FU-.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 };
|
package/dist/types/index.cjs
DELETED
package/dist/types/index.mjs
DELETED
package/dist/types/plugin.cjs
DELETED
|
File without changes
|
package/dist/types/plugin.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/types/prisma.cjs
DELETED
|
File without changes
|
package/dist/types/prisma.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|