@powerlines/plugin-prisma 0.4.30 → 0.4.31

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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/client-generator-AkVOcQPr.mjs +146 -0
  3. package/dist/client-generator-B8dwKgp9.mjs +146 -0
  4. package/dist/client-generator-BAc2oiYI.cjs +152 -0
  5. package/dist/client-generator-Wdm31y35.cjs +152 -0
  6. package/dist/get-schema-Dq1-Jwvo.cjs +138 -0
  7. package/dist/helpers/client-generator.cjs +4 -0
  8. package/dist/helpers/client-generator.mjs +3 -0
  9. package/dist/helpers/get-schema.cjs +2 -80
  10. package/dist/helpers/get-schema.mjs +24 -4
  11. package/dist/helpers/index.cjs +6 -4
  12. package/dist/helpers/index.mjs +3 -2
  13. package/dist/helpers/schema-creator.cjs +1 -1
  14. package/dist/helpers/typed-sql.cjs +38 -0
  15. package/dist/helpers/typed-sql.mjs +36 -0
  16. package/dist/index.cjs +71 -42
  17. package/dist/index.mjs +68 -38
  18. package/dist/types/index.cjs +2 -0
  19. package/dist/types/index.mjs +3 -0
  20. package/package.json +45 -249
  21. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  22. package/dist/_virtual/_rolldown/runtime.mjs +0 -3
  23. package/dist/api/client/client.gen.cjs +0 -176
  24. package/dist/api/client/client.gen.mjs +0 -175
  25. package/dist/api/client/index.cjs +0 -15
  26. package/dist/api/client/index.mjs +0 -7
  27. package/dist/api/client/types.gen.cjs +0 -0
  28. package/dist/api/client/types.gen.mjs +0 -1
  29. package/dist/api/client/utils.gen.cjs +0 -187
  30. package/dist/api/client/utils.gen.mjs +0 -179
  31. package/dist/api/client.gen.cjs +0 -10
  32. package/dist/api/client.gen.mjs +0 -9
  33. package/dist/api/core/auth.gen.cjs +0 -13
  34. package/dist/api/core/auth.gen.mjs +0 -11
  35. package/dist/api/core/bodySerializer.gen.cjs +0 -36
  36. package/dist/api/core/bodySerializer.gen.mjs +0 -32
  37. package/dist/api/core/params.gen.cjs +0 -66
  38. package/dist/api/core/params.gen.mjs +0 -64
  39. package/dist/api/core/pathSerializer.gen.cjs +0 -88
  40. package/dist/api/core/pathSerializer.gen.mjs +0 -81
  41. package/dist/api/core/queryKeySerializer.gen.cjs +0 -67
  42. package/dist/api/core/queryKeySerializer.gen.mjs +0 -63
  43. package/dist/api/core/serverSentEvents.gen.cjs +0 -96
  44. package/dist/api/core/serverSentEvents.gen.mjs +0 -94
  45. package/dist/api/core/types.gen.cjs +0 -0
  46. package/dist/api/core/types.gen.mjs +0 -1
  47. package/dist/api/core/utils.gen.cjs +0 -82
  48. package/dist/api/core/utils.gen.mjs +0 -78
  49. package/dist/api/sdk.gen.cjs +0 -405
  50. package/dist/api/sdk.gen.mjs +0 -404
  51. package/dist/api/types.gen.cjs +0 -0
  52. package/dist/api/types.gen.mjs +0 -1
  53. package/dist/generator.cjs +0 -15
  54. package/dist/generator.mjs +0 -15
  55. package/dist/helpers/prisma-postgres.cjs +0 -17
  56. package/dist/helpers/prisma-postgres.mjs +0 -15
@@ -0,0 +1,138 @@
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
+ });
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_client_generator = require('../client-generator-BAc2oiYI.cjs');
3
+
4
+ exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
@@ -0,0 +1,3 @@
1
+ import { t as PowerlinesClientGenerator } from "../client-generator-AkVOcQPr.mjs";
2
+
3
+ export { PowerlinesClientGenerator };
@@ -1,82 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _prisma_get_platform = require("@prisma/get-platform");
4
- let _prisma_prisma_schema_wasm = require("@prisma/prisma-schema-wasm");
5
- _prisma_prisma_schema_wasm = require_runtime.__toESM(_prisma_prisma_schema_wasm);
6
- let fp_ts_Either = require("fp-ts/Either");
7
- fp_ts_Either = require_runtime.__toESM(fp_ts_Either);
8
- let fp_ts_lib_function = require("fp-ts/lib/function");
9
- let ts_pattern = require("ts-pattern");
2
+ const require_get_schema = require('../get-schema-Dq1-Jwvo.cjs');
10
3
 
11
- //#region src/helpers/get-schema.ts
12
- async function resolveBinaryTargets(generator) {
13
- for (const binaryTarget of generator.binaryTargets) {
14
- if (binaryTarget.fromEnvVar && process.env[binaryTarget.fromEnvVar]) {
15
- const value = JSON.parse(process.env[binaryTarget.fromEnvVar]);
16
- if (Array.isArray(value)) {
17
- generator.binaryTargets = value.map((v) => ({
18
- fromEnvVar: null,
19
- value: v
20
- }));
21
- await resolveBinaryTargets(generator);
22
- } else binaryTarget.value = value;
23
- }
24
- if (binaryTarget.value === "native") {
25
- binaryTarget.value = await (0, _prisma_get_platform.getBinaryTargetForCurrentPlatform)();
26
- binaryTarget.native = true;
27
- }
28
- }
29
- if (generator.binaryTargets.length === 0) generator.binaryTargets = [{
30
- fromEnvVar: null,
31
- value: await (0, _prisma_get_platform.getBinaryTargetForCurrentPlatform)(),
32
- native: true
33
- }];
34
- }
35
- /**
36
- * Retrieves the Prisma schema using the provided options.
37
- *
38
- * @param options - The options to customize the schema retrieval.
39
- * @returns The Prisma schema.
40
- */
41
- async function getSchema(options) {
42
- const configEither = (0, fp_ts_lib_function.pipe)(fp_ts_Either.tryCatch(() => {
43
- if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) _prisma_prisma_schema_wasm.default.debug_panic();
44
- const params = JSON.stringify({
45
- prismaSchema: options.datamodel,
46
- datasourceOverrides: {},
47
- ignoreEnvVarErrors: options.ignoreEnvVarErrors ?? false,
48
- env: process.env
49
- });
50
- return _prisma_prisma_schema_wasm.default.get_config(params);
51
- }, (e) => ({
52
- type: "wasm-error",
53
- reason: "(get-config wasm)",
54
- error: e
55
- })), fp_ts_Either.map((result) => ({ result })), fp_ts_Either.chainW(({ result }) => fp_ts_Either.tryCatch(() => JSON.parse(result), (e) => ({
56
- type: "parse-json",
57
- reason: "Unable to parse JSON",
58
- error: e
59
- }))), fp_ts_Either.chainW((response) => {
60
- if (response.errors.length > 0) return fp_ts_Either.left({
61
- type: "validation-error",
62
- reason: "(get-config wasm)",
63
- error: response.errors
64
- });
65
- return fp_ts_Either.right(response.config);
66
- }));
67
- if (fp_ts_Either.isRight(configEither)) {
68
- const { right: data } = configEither;
69
- for (const generator of data.generators) await resolveBinaryTargets(generator);
70
- return Promise.resolve(data);
71
- }
72
- throw (0, ts_pattern.match)(configEither.left).with({ type: "wasm-error" }, (e) => {
73
- return /* @__PURE__ */ new Error(`Prisma get-config Wasm runtime error: ${e.error.message}`);
74
- }).with({ type: "validation-error" }, (e) => {
75
- return /* @__PURE__ */ new Error(`Prisma get-config validation error: ${e.error.map((err) => err.message).join(", ")}`);
76
- }).otherwise((e) => {
77
- return /* @__PURE__ */ new Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`);
78
- });
79
- }
80
-
81
- //#endregion
82
- exports.getSchema = getSchema;
4
+ exports.getSchema = require_get_schema.getSchema;
@@ -31,16 +31,16 @@ async function resolveBinaryTargets(generator) {
31
31
  /**
32
32
  * Retrieves the Prisma schema using the provided options.
33
33
  *
34
- * @param options - The options to customize the schema retrieval.
34
+ * @param path - The path to the Prisma schema file.
35
35
  * @returns The Prisma schema.
36
36
  */
37
- async function getSchema(options) {
37
+ async function resolveDataModel(schemaPath) {
38
38
  const configEither = pipe(E.tryCatch(() => {
39
39
  if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) prismaSchemaWasm.debug_panic();
40
40
  const params = JSON.stringify({
41
- prismaSchema: options.datamodel,
41
+ prismaSchema: schemaPath,
42
42
  datasourceOverrides: {},
43
- ignoreEnvVarErrors: options.ignoreEnvVarErrors ?? false,
43
+ ignoreEnvVarErrors: true,
44
44
  env: process.env
45
45
  });
46
46
  return prismaSchemaWasm.get_config(params);
@@ -73,6 +73,26 @@ async function getSchema(options) {
73
73
  return /* @__PURE__ */ new Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`);
74
74
  });
75
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
+ }
76
96
 
77
97
  //#endregion
78
98
  export { getSchema };
@@ -1,8 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_helpers_get_schema = require('./get-schema.cjs');
2
+ const require_get_schema = require('../get-schema-Dq1-Jwvo.cjs');
3
+ const require_client_generator = require('../client-generator-BAc2oiYI.cjs');
3
4
  const require_helpers_schema_creator = require('./schema-creator.cjs');
4
- const require_helpers_prisma_postgres = require('./prisma-postgres.cjs');
5
+ const require_helpers_typed_sql = require('./typed-sql.cjs');
5
6
 
7
+ exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
6
8
  exports.PrismaSchemaCreator = require_helpers_schema_creator.PrismaSchemaCreator;
7
- exports.findDatabaseByName = require_helpers_prisma_postgres.findDatabaseByName;
8
- exports.getSchema = require_helpers_get_schema.getSchema;
9
+ exports.getSchema = require_get_schema.getSchema;
10
+ exports.introspectSql = require_helpers_typed_sql.introspectSql;
@@ -1,5 +1,6 @@
1
+ import { t as PowerlinesClientGenerator } from "../client-generator-AkVOcQPr.mjs";
1
2
  import { getSchema } from "./get-schema.mjs";
2
3
  import { PrismaSchemaCreator } from "./schema-creator.mjs";
3
- import { findDatabaseByName } from "./prisma-postgres.mjs";
4
+ import { introspectSql } from "./typed-sql.mjs";
4
5
 
5
- export { PrismaSchemaCreator, findDatabaseByName, getSchema };
6
+ export { PowerlinesClientGenerator, PrismaSchemaCreator, getSchema, introspectSql };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_get_schema = require('../get-schema-Dq1-Jwvo.cjs');
3
3
  let prisma_util_schema_creator = require("prisma-util/schema-creator");
4
4
 
5
5
  //#region src/helpers/schema-creator.ts
@@ -0,0 +1,38 @@
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;
@@ -0,0 +1,36 @@
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 CHANGED
@@ -1,16 +1,22 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_helpers_get_schema = require('./helpers/get-schema.cjs');
2
+ const require_get_schema = require('./get-schema-Dq1-Jwvo.cjs');
3
+ const require_client_generator = require('./client-generator-BAc2oiYI.cjs');
4
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");
5
9
  let _pulumi_prisma_postgres = require("@pulumi/prisma-postgres");
6
- _pulumi_prisma_postgres = require_runtime.__toESM(_pulumi_prisma_postgres);
7
- let _stryke_cli_execute = require("@stryke/cli/execute");
8
- let _stryke_fs_exists = require("@stryke/fs/exists");
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");
9
15
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
10
16
  let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
11
17
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
12
18
  let defu = require("defu");
13
- defu = require_runtime.__toESM(defu);
19
+ defu = require_get_schema.__toESM(defu);
14
20
  let powerlines_plugin_utils = require("powerlines/plugin-utils");
15
21
 
16
22
  //#region src/index.ts
@@ -25,10 +31,11 @@ const plugin = (options = {}) => {
25
31
  name: "prisma",
26
32
  config() {
27
33
  return { prisma: (0, defu.default)(options, {
28
- schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma", "schema.prisma"),
34
+ schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma", "*.prisma"),
29
35
  configFile: options.configFile || (0, powerlines_plugin_utils.getConfigPath)(this, "prisma.config"),
36
+ runtime: options.runtime || "nodejs",
30
37
  outputPath: (0, _stryke_path_join_paths.joinPaths)("{builtinPath}", "prisma"),
31
- prismaPostgres: options?.prismaPostgres ? {
38
+ prismaPostgres: options.prismaPostgres ? {
32
39
  projectId: this.config.name,
33
40
  region: "us-east-1"
34
41
  } : void 0
@@ -38,50 +45,72 @@ const plugin = (options = {}) => {
38
45
  this.dependencies["@prisma/ppg"] = "latest";
39
46
  this.config.prisma.configFile = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.configFile);
40
47
  if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
41
- this.config.prisma.schema = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.schema);
48
+ this.config.prisma.schema = (0, _stryke_convert_to_array.toArray)(this.config.prisma.schema).map((schemaPath) => (0, powerlines_plugin_utils.replacePathTokens)(this, schemaPath));
42
49
  if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
43
50
  this.config.prisma.outputPath = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.outputPath);
44
51
  this.prisma ??= {};
45
- if (!(0, _stryke_fs_exists.existsSync)(this.config.prisma.schema)) this.prisma.schema ??= {
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: [],
46
63
  generators: [],
47
64
  datasources: [],
48
- warnings: []
49
- };
50
- else this.prisma.schema = await require_helpers_get_schema.getSchema({ datamodel: this.config.prisma.schema });
51
- const generator = this.prisma.schema.generators.find((gen) => gen.provider.value === "prisma-client");
52
- if (!generator) this.prisma.schema.generators.push({
53
- name: "prisma-client",
54
- provider: {
55
- value: "prisma-client",
56
- fromEnvVar: null
57
- },
58
- output: {
59
- value: this.config.prisma.outputPath,
60
- fromEnvVar: null
61
- },
62
- config: {},
63
- binaryTargets: [],
64
- previewFeatures: [],
65
- sourceFilePath: this.config.prisma.schema
66
- });
67
- else generator.output ??= {
68
- value: this.config.prisma.outputPath,
69
- fromEnvVar: null
65
+ warnings: [],
66
+ primaryDatasource: void 0
70
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;
71
78
  this.prisma.builder = new require_helpers_schema_creator.PrismaSchemaCreator(this);
72
79
  },
73
80
  async prepare() {
74
81
  await this.prisma.builder.write();
75
- if (this.config.prisma.prismaPath) {
76
- const result = await (0, _stryke_cli_execute.execute)(`${this.config.prisma.prismaPath} generate --schema ${this.config.prisma.schema}`, this.config.root);
77
- if (result.failed) throw new Error(`Prisma process exited with code ${result.exitCode}.`);
78
- } else {
79
- const result = await (0, _stryke_cli_execute.executePackage)("prisma", [
80
- "generate",
81
- "--schema",
82
- this.config.prisma.schema
83
- ], (0, _stryke_path_join_paths.joinPaths)(this.workspaceConfig.workspaceRoot, this.config.root));
84
- if (result.failed) throw new Error(`Prisma process exited with code ${result.exitCode}.`);
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)}`);
85
114
  }
86
115
  },
87
116
  async deployPulumi() {