@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/dist/index.mjs DELETED
@@ -1,143 +0,0 @@
1
- import { t as PowerlinesClientGenerator } from "./client-generator-a3gfBXbv.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 };
@@ -1,2 +0,0 @@
1
- require('./prisma.cjs');
2
- require('./plugin.cjs');
@@ -1,4 +0,0 @@
1
- import "./prisma.mjs";
2
- import "./plugin.mjs";
3
-
4
- export { };
File without changes
@@ -1 +0,0 @@
1
- export { };
File without changes
@@ -1 +0,0 @@
1
- export { };