@powerlines/plugin-prisma 0.4.287 → 0.4.288

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.
@@ -26,9 +26,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
 
27
27
  //#endregion
28
28
 
29
- Object.defineProperty(exports, '__toESM', {
30
- enumerable: true,
31
- get: function () {
32
- return __toESM;
33
- }
34
- });
29
+ exports.__toESM = __toESM;
package/dist/index.cjs CHANGED
@@ -1,148 +1,99 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
3
- const require_client_generator = require('./client-generator-DzDgrDsT.cjs');
4
- const require_helpers_get_schema = require('./helpers/get-schema.cjs');
5
- const require_helpers_schema_creator = require('./helpers/schema-creator.cjs');
6
- const require_helpers_typed_sql = require('./helpers/typed-sql.cjs');
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _powerlines_plugin_power_plant = require("@powerlines/plugin-power-plant");
4
+ _powerlines_plugin_power_plant = require_runtime.__toESM(_powerlines_plugin_power_plant, 1);
7
5
  let _powerlines_plugin_pulumi = require("@powerlines/plugin-pulumi");
8
- _powerlines_plugin_pulumi = require_rolldown_runtime.__toESM(_powerlines_plugin_pulumi, 1);
9
- let _prisma_client_generator_registry = require("@prisma/client-generator-registry");
10
- let _prisma_engines = require("@prisma/engines");
11
- let _prisma_internals = require("@prisma/internals");
12
- let _pulumi_prisma_postgres = require("@pulumi/prisma-postgres");
13
- _pulumi_prisma_postgres = require_rolldown_runtime.__toESM(_pulumi_prisma_postgres, 1);
14
- let _stryke_convert_to_array = require("@stryke/convert/to-array");
15
- let _stryke_path_append = require("@stryke/path/append");
16
- let _stryke_path_common = require("@stryke/path/common");
17
- let _stryke_path_find = require("@stryke/path/find");
6
+ _powerlines_plugin_pulumi = require_runtime.__toESM(_powerlines_plugin_pulumi, 1);
18
7
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
19
8
  let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
20
9
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
21
10
  let defu = require("defu");
22
- defu = require_rolldown_runtime.__toESM(defu, 1);
11
+ defu = require_runtime.__toESM(defu, 1);
12
+ let node_module = require("node:module");
23
13
  let powerlines_plugin_utils = require("powerlines/plugin-utils");
24
14
 
25
15
  //#region src/index.ts
26
16
  /**
27
- * A Powerlines plugin to integrate Prisma for code generation.
17
+ * Load packages via CJS where published ESM is unreliable.
18
+ *
19
+ * @remarks
20
+ * Prisma's published ESM builds use extensionless relative imports that fail
21
+ * under Node's native ESM resolver. The CJS entry works. `@pulumi/prisma-postgres`
22
+ * is also resolved at deploy time only (Terraform provider stub).
23
+ */
24
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
25
+ const prismaGenerator = require$1("@power-plant/prisma");
26
+ /**
27
+ * A Powerlines plugin to integrate Prisma for code generation via Power Plant.
28
+ *
29
+ * @see https://www.prisma.io/docs/orm/prisma-schema/overview/generators
30
+ * @see https://github.com/storm-software/power-plant/tree/main/packages/generators/prisma
28
31
  *
29
32
  * @param options - The plugin options.
30
- * @returns A Powerlines plugin instance.
33
+ * @returns Powerlines plugin instances.
31
34
  */
32
35
  const plugin = (options = {}) => {
33
- return [...(0, _powerlines_plugin_pulumi.default)(options.pulumi), {
34
- name: "prisma",
35
- config() {
36
- return { prisma: (0, defu.default)(options, {
37
- schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma", "*.prisma"),
38
- configFile: options.configFile || (0, powerlines_plugin_utils.getConfigPath)(this, "prisma.config"),
39
- runtime: options.runtime || "nodejs",
40
- outputPath: (0, _stryke_path_join_paths.joinPaths)("{builtinPath}", "prisma"),
41
- prismaPostgres: options.prismaPostgres ? {
42
- projectId: this.config.name,
43
- region: "us-east-1"
44
- } : void 0
45
- }) };
46
- },
47
- async configResolved() {
48
- this.dependencies["@prisma/ppg"] = "latest";
49
- this.config.prisma.configFile = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.configFile);
50
- if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
51
- this.config.prisma.schema = (0, _stryke_convert_to_array.toArray)(this.config.prisma.schema).map((schemaPath) => (0, powerlines_plugin_utils.replacePathTokens)(this, schemaPath));
52
- if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
53
- this.config.prisma.outputPath = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.outputPath);
54
- this.prisma ??= {};
55
- this.prisma.config = (0, _prisma_internals.validatePrismaConfigWithDatasource)({
56
- config: this.config.prisma,
57
- cmd: "generate --sql"
58
- });
59
- 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.config.cwd);
60
- this.prisma.schema ??= {
61
- schemaRootDir,
62
- loadedFromPathForLogMessages: (0, _stryke_path_find.relativePath)(this.config.root, schemaRootDir),
63
- schemaPath: schemaRootDir,
64
- schemas: [],
65
- schemaFiles: [],
66
- generators: [],
67
- datasources: [],
68
- warnings: [],
69
- primaryDatasource: void 0
70
- };
71
- 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_helpers_get_schema.getSchema(schema)));
72
- this.prisma.schema = this.prisma.schema.schemas.reduce((ret, schema) => {
73
- ret.datasources.push(...schema.datasources);
74
- ret.generators.push(...schema.generators);
75
- ret.warnings.push(...schema.warnings);
76
- ret.schemaFiles.push([schema.path, schema.content]);
77
- return ret;
78
- }, this.prisma.schema);
79
- this.prisma.schema.primaryDatasource = this.prisma.schema.datasources.at(0);
80
- this.prisma.schema.schemaPath = this.prisma.schema.schemas.at(0).path;
81
- this.prisma.builder = new require_helpers_schema_creator.PrismaSchemaCreator(this);
82
- },
83
- async prepare() {
84
- await this.prisma.builder.write();
85
- this.prisma.previewFeatures = (0, _prisma_internals.extractPreviewFeatures)(this.prisma.schema.generators);
86
- this.prisma.dmmf = await (0, _prisma_internals.getDMMF)({
87
- datamodel: this.prisma.schema.schemaFiles,
88
- previewFeatures: this.prisma.previewFeatures
89
- });
90
- const typedSql = await require_helpers_typed_sql.introspectSql(this);
91
- let generators = await (0, _prisma_internals.getGenerators)({
92
- schemaContext: this.prisma.schema,
93
- printDownloadProgress: true,
94
- version: _prisma_engines.enginesVersion,
95
- typedSql,
96
- allowNoModels: true,
97
- registry: _prisma_client_generator_registry.defaultRegistry.toInternal()
98
- });
99
- if (!generators || !generators.some((gen) => [
100
- "prisma-client",
101
- "prisma-client-js",
102
- "prisma-client-ts"
103
- ].includes(gen.name || gen.getProvider()))) {
104
- generators ??= [];
105
- generators.push(new require_client_generator.PowerlinesClientGenerator(this));
106
- } else generators = generators.map((generator) => [
107
- "prisma-client",
108
- "prisma-client-js",
109
- "prisma-client-ts"
110
- ].includes(generator.name || generator.getProvider()) ? new require_client_generator.PowerlinesClientGenerator(this) : generator);
111
- for (const generator of generators) try {
112
- await generator.generate();
113
- generator.stop();
114
- } catch (err) {
115
- generator.stop();
116
- this.error(`Error while generating with ${generator.name || generator.getProvider()}: ${err instanceof Error ? err.message : String(err)}`);
117
- }
118
- },
119
- pulumi: { async deploy() {
120
- if (this.config.prisma.prismaPostgres) {
121
- let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
122
- if (!serviceToken) {
123
- serviceToken = options.serviceToken;
124
- 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.");
125
- else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
126
- }
127
- await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
128
- const project = new _pulumi_prisma_postgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
129
- const database = new _pulumi_prisma_postgres.Database("database", {
130
- projectId: project.id,
131
- name: `${this.config.prisma.prismaPostgres?.databaseName || `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
132
- region: `${this.config.prisma.prismaPostgres?.region}`
133
- });
134
- return {
135
- project,
136
- database,
137
- connection: new _pulumi_prisma_postgres.Connection("connection", {
138
- databaseId: database.id,
139
- name: `${(0, _stryke_string_format_constant_case.constantCase)(this.config.name)}_API_KEY`
140
- })
36
+ const generatorConfig = { ...prismaGenerator };
37
+ return [
38
+ (0, _powerlines_plugin_power_plant.default)(generatorConfig),
39
+ ...(0, _powerlines_plugin_pulumi.default)(options.pulumi),
40
+ {
41
+ name: "prisma",
42
+ config() {
43
+ return { prisma: (0, defu.default)(options, {
44
+ schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma"),
45
+ printDownloadProgress: true,
46
+ allowNoModels: true,
47
+ prismaPostgres: options.prismaPostgres ? {
48
+ projectId: this.config.name,
49
+ region: "us-east-1"
50
+ } : void 0
51
+ }) };
52
+ },
53
+ async configResolved() {
54
+ this.dependencies["@prisma/ppg"] = "latest";
55
+ if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
56
+ this.config.prisma.schema = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.schema);
57
+ const { schema, printDownloadProgress, allowNoModels, generatorNames, skipDownload, serviceToken: _serviceToken, prismaPostgres: _prismaPostgres, pulumi: _pulumi, ...rest } = this.config.prisma;
58
+ this.config.powerplant = { ...generatorConfig };
59
+ this.powerplant.options = {
60
+ ...rest,
61
+ schemaPath: schema,
62
+ printDownloadProgress,
63
+ allowNoModels,
64
+ generatorNames,
65
+ skipDownload
141
66
  };
142
- }
143
- return null;
144
- } }
145
- }];
67
+ },
68
+ pulumi: { async deploy() {
69
+ if (this.config.prisma.prismaPostgres) {
70
+ let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
71
+ if (!serviceToken) {
72
+ serviceToken = options.serviceToken;
73
+ 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.");
74
+ else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
75
+ }
76
+ await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
77
+ const prismaPostgres = require$1("@pulumi/prisma-postgres");
78
+ const project = new prismaPostgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
79
+ const database = new prismaPostgres.Database("database", {
80
+ projectId: project.id,
81
+ name: `${this.config.prisma.prismaPostgres?.databaseName || `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
82
+ region: `${this.config.prisma.prismaPostgres?.region}`
83
+ });
84
+ return {
85
+ project,
86
+ database,
87
+ connection: new prismaPostgres.Connection("connection", {
88
+ databaseId: database.id,
89
+ name: `${(0, _stryke_string_format_constant_case.constantCase)(this.config.name)}_API_KEY`
90
+ })
91
+ };
92
+ }
93
+ return null;
94
+ } }
95
+ }
96
+ ];
146
97
  };
147
98
 
148
99
  //#endregion
@@ -0,0 +1,22 @@
1
+ import { PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, PrismaSchema } from "./types/plugin.cjs";
2
+ import "./types/index.cjs";
3
+ import { Plugin } from "powerlines";
4
+ //#region src/index.d.ts
5
+ declare module "powerlines" {
6
+ interface Config {
7
+ prisma?: PrismaPluginOptions;
8
+ }
9
+ }
10
+ /**
11
+ * A Powerlines plugin to integrate Prisma for code generation via Power Plant.
12
+ *
13
+ * @see https://www.prisma.io/docs/orm/prisma-schema/overview/generators
14
+ * @see https://github.com/storm-software/power-plant/tree/main/packages/generators/prisma
15
+ *
16
+ * @param options - The plugin options.
17
+ * @returns Powerlines plugin instances.
18
+ */
19
+ declare const plugin: <TContext extends PrismaPluginContext = PrismaPluginContext>(options?: PrismaPluginOptions) => Plugin<TContext>[];
20
+ //#endregion
21
+ export { type PowerPlantPrismaOptions, type PrismaPluginContext, type PrismaPluginOptions, type PrismaPluginResolvedConfig, type PrismaPluginUserConfig, type PrismaPostgresPrismaPluginOptions, type PrismaSchema, plugin as default, plugin };
22
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;YAsCY;IACR,SAAS;;;;;;;;;;;;cA2BA,SACX,iBAAiB,sBAAsB,qBAEvC,UAAS,wBACR,OAAO"}
@@ -0,0 +1,22 @@
1
+ import { PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, PrismaSchema } from "./types/plugin.mjs";
2
+ import "./types/index.mjs";
3
+ import { Plugin } from "powerlines";
4
+ //#region src/index.d.ts
5
+ declare module "powerlines" {
6
+ interface Config {
7
+ prisma?: PrismaPluginOptions;
8
+ }
9
+ }
10
+ /**
11
+ * A Powerlines plugin to integrate Prisma for code generation via Power Plant.
12
+ *
13
+ * @see https://www.prisma.io/docs/orm/prisma-schema/overview/generators
14
+ * @see https://github.com/storm-software/power-plant/tree/main/packages/generators/prisma
15
+ *
16
+ * @param options - The plugin options.
17
+ * @returns Powerlines plugin instances.
18
+ */
19
+ declare const plugin: <TContext extends PrismaPluginContext = PrismaPluginContext>(options?: PrismaPluginOptions) => Plugin<TContext>[];
20
+ //#endregion
21
+ export { type PowerPlantPrismaOptions, type PrismaPluginContext, type PrismaPluginOptions, type PrismaPluginResolvedConfig, type PrismaPluginUserConfig, type PrismaPostgresPrismaPluginOptions, type PrismaSchema, plugin as default, plugin };
22
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":""}
package/dist/index.mjs CHANGED
@@ -1,144 +1,96 @@
1
- import { t as PowerlinesClientGenerator } from "./client-generator-BXFg7x5g.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";
1
+ import { createRequire } from "node:module";
2
+ import powerPlant from "@powerlines/plugin-power-plant";
5
3
  import pulumi from "@powerlines/plugin-pulumi";
6
- import { defaultRegistry } from "@prisma/client-generator-registry";
7
- import { enginesVersion } from "@prisma/engines";
8
- import { extractPreviewFeatures, getDMMF, getGenerators, validatePrismaConfigWithDatasource } from "@prisma/internals";
9
- import * as prismaPostgres from "@pulumi/prisma-postgres";
10
- import { toArray } from "@stryke/convert/to-array";
11
- import { appendPath } from "@stryke/path/append";
12
- import { findBasePath } from "@stryke/path/common";
13
- import { relativePath } from "@stryke/path/find";
14
4
  import { joinPaths } from "@stryke/path/join-paths";
15
5
  import { constantCase } from "@stryke/string-format/constant-case";
16
6
  import { kebabCase } from "@stryke/string-format/kebab-case";
17
7
  import defu from "defu";
18
- import { getConfigPath, replacePathTokens } from "powerlines/plugin-utils";
8
+ import { replacePathTokens } from "powerlines/plugin-utils";
19
9
 
20
10
  //#region src/index.ts
21
11
  /**
22
- * A Powerlines plugin to integrate Prisma for code generation.
12
+ * Load packages via CJS where published ESM is unreliable.
13
+ *
14
+ * @remarks
15
+ * Prisma's published ESM builds use extensionless relative imports that fail
16
+ * under Node's native ESM resolver. The CJS entry works. `@pulumi/prisma-postgres`
17
+ * is also resolved at deploy time only (Terraform provider stub).
18
+ */
19
+ const require = createRequire(import.meta.url);
20
+ const prismaGenerator = require("@power-plant/prisma");
21
+ /**
22
+ * A Powerlines plugin to integrate Prisma for code generation via Power Plant.
23
+ *
24
+ * @see https://www.prisma.io/docs/orm/prisma-schema/overview/generators
25
+ * @see https://github.com/storm-software/power-plant/tree/main/packages/generators/prisma
23
26
  *
24
27
  * @param options - The plugin options.
25
- * @returns A Powerlines plugin instance.
28
+ * @returns Powerlines plugin instances.
26
29
  */
27
30
  const plugin = (options = {}) => {
28
- return [...pulumi(options.pulumi), {
29
- name: "prisma",
30
- config() {
31
- return { prisma: defu(options, {
32
- schema: joinPaths(this.config.root, "prisma", "*.prisma"),
33
- configFile: options.configFile || getConfigPath(this, "prisma.config"),
34
- runtime: options.runtime || "nodejs",
35
- outputPath: joinPaths("{builtinPath}", "prisma"),
36
- prismaPostgres: options.prismaPostgres ? {
37
- projectId: this.config.name,
38
- region: "us-east-1"
39
- } : void 0
40
- }) };
41
- },
42
- async configResolved() {
43
- this.dependencies["@prisma/ppg"] = "latest";
44
- this.config.prisma.configFile = replacePathTokens(this, this.config.prisma.configFile);
45
- if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
46
- this.config.prisma.schema = toArray(this.config.prisma.schema).map((schemaPath) => replacePathTokens(this, schemaPath));
47
- if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
48
- this.config.prisma.outputPath = replacePathTokens(this, this.config.prisma.outputPath);
49
- this.prisma ??= {};
50
- this.prisma.config = validatePrismaConfigWithDatasource({
51
- config: this.config.prisma,
52
- cmd: "generate --sql"
53
- });
54
- const schemaRootDir = appendPath(appendPath(findBasePath(this.config.prisma.schema), this.config.root), this.config.cwd);
55
- this.prisma.schema ??= {
56
- schemaRootDir,
57
- loadedFromPathForLogMessages: relativePath(this.config.root, schemaRootDir),
58
- schemaPath: schemaRootDir,
59
- schemas: [],
60
- schemaFiles: [],
61
- generators: [],
62
- datasources: [],
63
- warnings: [],
64
- primaryDatasource: void 0
65
- };
66
- 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)));
67
- this.prisma.schema = this.prisma.schema.schemas.reduce((ret, schema) => {
68
- ret.datasources.push(...schema.datasources);
69
- ret.generators.push(...schema.generators);
70
- ret.warnings.push(...schema.warnings);
71
- ret.schemaFiles.push([schema.path, schema.content]);
72
- return ret;
73
- }, this.prisma.schema);
74
- this.prisma.schema.primaryDatasource = this.prisma.schema.datasources.at(0);
75
- this.prisma.schema.schemaPath = this.prisma.schema.schemas.at(0).path;
76
- this.prisma.builder = new PrismaSchemaCreator(this);
77
- },
78
- async prepare() {
79
- await this.prisma.builder.write();
80
- this.prisma.previewFeatures = extractPreviewFeatures(this.prisma.schema.generators);
81
- this.prisma.dmmf = await getDMMF({
82
- datamodel: this.prisma.schema.schemaFiles,
83
- previewFeatures: this.prisma.previewFeatures
84
- });
85
- const typedSql = await introspectSql(this);
86
- let generators = await getGenerators({
87
- schemaContext: this.prisma.schema,
88
- printDownloadProgress: true,
89
- version: enginesVersion,
90
- typedSql,
91
- allowNoModels: true,
92
- registry: defaultRegistry.toInternal()
93
- });
94
- if (!generators || !generators.some((gen) => [
95
- "prisma-client",
96
- "prisma-client-js",
97
- "prisma-client-ts"
98
- ].includes(gen.name || gen.getProvider()))) {
99
- generators ??= [];
100
- generators.push(new PowerlinesClientGenerator(this));
101
- } else generators = generators.map((generator) => [
102
- "prisma-client",
103
- "prisma-client-js",
104
- "prisma-client-ts"
105
- ].includes(generator.name || generator.getProvider()) ? new PowerlinesClientGenerator(this) : generator);
106
- for (const generator of generators) try {
107
- await generator.generate();
108
- generator.stop();
109
- } catch (err) {
110
- generator.stop();
111
- this.error(`Error while generating with ${generator.name || generator.getProvider()}: ${err instanceof Error ? err.message : String(err)}`);
112
- }
113
- },
114
- pulumi: { async deploy() {
115
- if (this.config.prisma.prismaPostgres) {
116
- let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
117
- if (!serviceToken) {
118
- serviceToken = options.serviceToken;
119
- 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.");
120
- else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
121
- }
122
- await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
123
- const project = new prismaPostgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
124
- const database = new prismaPostgres.Database("database", {
125
- projectId: project.id,
126
- name: `${this.config.prisma.prismaPostgres?.databaseName || `${kebabCase(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
127
- region: `${this.config.prisma.prismaPostgres?.region}`
128
- });
129
- return {
130
- project,
131
- database,
132
- connection: new prismaPostgres.Connection("connection", {
133
- databaseId: database.id,
134
- name: `${constantCase(this.config.name)}_API_KEY`
135
- })
31
+ const generatorConfig = { ...prismaGenerator };
32
+ return [
33
+ powerPlant(generatorConfig),
34
+ ...pulumi(options.pulumi),
35
+ {
36
+ name: "prisma",
37
+ config() {
38
+ return { prisma: defu(options, {
39
+ schema: joinPaths(this.config.root, "prisma"),
40
+ printDownloadProgress: true,
41
+ allowNoModels: true,
42
+ prismaPostgres: options.prismaPostgres ? {
43
+ projectId: this.config.name,
44
+ region: "us-east-1"
45
+ } : void 0
46
+ }) };
47
+ },
48
+ async configResolved() {
49
+ this.dependencies["@prisma/ppg"] = "latest";
50
+ if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
51
+ this.config.prisma.schema = replacePathTokens(this, this.config.prisma.schema);
52
+ const { schema, printDownloadProgress, allowNoModels, generatorNames, skipDownload, serviceToken: _serviceToken, prismaPostgres: _prismaPostgres, pulumi: _pulumi, ...rest } = this.config.prisma;
53
+ this.config.powerplant = { ...generatorConfig };
54
+ this.powerplant.options = {
55
+ ...rest,
56
+ schemaPath: schema,
57
+ printDownloadProgress,
58
+ allowNoModels,
59
+ generatorNames,
60
+ skipDownload
136
61
  };
137
- }
138
- return null;
139
- } }
140
- }];
62
+ },
63
+ pulumi: { async deploy() {
64
+ if (this.config.prisma.prismaPostgres) {
65
+ let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
66
+ if (!serviceToken) {
67
+ serviceToken = options.serviceToken;
68
+ 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.");
69
+ else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
70
+ }
71
+ await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
72
+ const prismaPostgres = require("@pulumi/prisma-postgres");
73
+ const project = new prismaPostgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
74
+ const database = new prismaPostgres.Database("database", {
75
+ projectId: project.id,
76
+ name: `${this.config.prisma.prismaPostgres?.databaseName || `${kebabCase(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
77
+ region: `${this.config.prisma.prismaPostgres?.region}`
78
+ });
79
+ return {
80
+ project,
81
+ database,
82
+ connection: new prismaPostgres.Connection("connection", {
83
+ databaseId: database.id,
84
+ name: `${constantCase(this.config.name)}_API_KEY`
85
+ })
86
+ };
87
+ }
88
+ return null;
89
+ } }
90
+ }
91
+ ];
141
92
  };
142
93
 
143
94
  //#endregion
144
- export { plugin as default, plugin };
95
+ export { plugin as default, plugin };
96
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- require('./prisma.cjs');
2
- require('./plugin.cjs');
@@ -0,0 +1,2 @@
1
+ import { PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, PrismaSchema } from "./plugin.cjs";
2
+ export { type PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, type PrismaSchema };
@@ -0,0 +1,2 @@
1
+ import { PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, PrismaSchema } from "./plugin.mjs";
2
+ export { type PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, type PrismaSchema };
@@ -1,4 +1 @@
1
- import "./prisma.mjs";
2
- import "./plugin.mjs";
3
-
4
1
  export { };
@@ -0,0 +1,74 @@
1
+ import { ResolvedConfig, UserConfig } from "powerlines";
2
+ import { Options, Options as PowerPlantPrismaOptions } from "@power-plant/prisma";
3
+ import { PrismaSchema, PrismaSchema as PrismaSchema$1 } from "@power-plant/prisma-schema";
4
+ import { PowerPlantPluginContext, PowerPlantPluginResolvedConfig } from "@powerlines/plugin-power-plant/types/plugin";
5
+ import { PulumiPluginContext, PulumiPluginOptions, PulumiPluginResolvedConfig, PulumiPluginUserConfig } from "@powerlines/plugin-pulumi";
6
+ //#region src/types/plugin.d.ts
7
+ interface PrismaPostgresPrismaPluginOptions {
8
+ /**
9
+ * The Prisma project name
10
+ *
11
+ * @defaultValue "\{name\}"
12
+ */
13
+ projectId?: string;
14
+ /**
15
+ * The region to deploy the database to
16
+ *
17
+ * @defaultValue "us-east-1"
18
+ */
19
+ region?: "us-east-1" | "us-east-2" | "us-west-1" | "us-west-2" | "af-south-1" | "ap-east-1" | "ap-south-1" | "ap-south-2" | "ap-southeast-1" | "ap-southeast-2" | "ap-southeast-3" | "ap-southeast-4" | "ap-northeast-1" | "ap-northeast-2" | "ap-northeast-3" | "ca-central-1" | "ca-west-1" | "eu-central-1" | "eu-central-2" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-north-1" | "eu-south-1" | "eu-south-2" | "il-central-1" | "me-south-1" | "me-central-1" | "sa-east-1";
20
+ /**
21
+ * The database name
22
+ *
23
+ * @defaultValue "\{region\}.\{mode\}.\{name\}"
24
+ */
25
+ databaseName?: string;
26
+ }
27
+ /**
28
+ * Options for the Prisma Powerlines plugin.
29
+ */
30
+ type PrismaPluginOptions = Partial<Omit<Options, "schemaPath">> & {
31
+ /**
32
+ * Path to the Prisma schema file (or directory) used by `@power-plant/prisma`.
33
+ *
34
+ * @remarks
35
+ * Maps to the Power Plant generator `schemaPath` option. This field allows
36
+ * the use of the "\{projectRoot\}" token to refer to the project's root
37
+ * directory - the value will be replaced with the correct file path by the
38
+ * plugin.
39
+ *
40
+ * @defaultValue "\{projectRoot\}/prisma"
41
+ */
42
+ schema?: string;
43
+ /**
44
+ * The service token to use for the Prisma API
45
+ */
46
+ serviceToken?: string;
47
+ /**
48
+ * Configuration parameters to manage a Prisma Postgres database
49
+ */
50
+ prismaPostgres?: PrismaPostgresPrismaPluginOptions | true;
51
+ /**
52
+ * The configuration options for Pulumi.
53
+ */
54
+ pulumi?: PulumiPluginOptions;
55
+ };
56
+ type PrismaPluginUserConfig = UserConfig & PulumiPluginUserConfig & {
57
+ prisma?: PrismaPluginOptions;
58
+ };
59
+ type PrismaPluginResolvedConfig = ResolvedConfig & PulumiPluginResolvedConfig & PowerPlantPluginResolvedConfig<PrismaSchema$1, Options> & {
60
+ prisma: Omit<PrismaPluginOptions, "schema" | "prismaPostgres"> & {
61
+ /**
62
+ * Path to the Prisma schema file (or directory).
63
+ */
64
+ schema: string;
65
+ /**
66
+ * Configuration parameters to manage a Prisma Postgres database
67
+ */
68
+ prismaPostgres?: Required<PrismaPostgresPrismaPluginOptions>;
69
+ };
70
+ };
71
+ type PrismaPluginContext<TResolvedConfig extends PrismaPluginResolvedConfig = PrismaPluginResolvedConfig> = PowerPlantPluginContext<PrismaSchema$1, Options, TResolvedConfig> & PulumiPluginContext;
72
+ //#endregion
73
+ export { type PowerPlantPrismaOptions, PrismaPluginContext, PrismaPluginOptions, PrismaPluginResolvedConfig, PrismaPluginUserConfig, PrismaPostgresPrismaPluginOptions, type PrismaSchema };
74
+ //# sourceMappingURL=plugin.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/types/plugin.ts"],"mappings":";;;;;;UAmCiB;;;;;;EAMf;;;;;;EAOA;;;;;;EAoCA;;;;;KAMU,sBAAsB,QAChC,KAAK;;;;;;;;;;;;EAaL;;;;EAKA;;;;EAKA,iBAAiB;;;;EAKjB,SAAS;;KAGC,yBAAyB,aACnC;EACE,SAAS;;KAGD,6BAA6B,iBACvC,6BACA,+BAA+B,gBAAc;EAC3C,QAAQ,KACN;;;;IAMA;;;;IAKA,iBAAiB,SAAS;;;KAIpB,oBACV,wBAAwB,6BACtB,8BACA,wBACF,gBACA,SACA,mBAEA"}