@powerlines/plugin-prisma 0.4.81 → 0.4.83

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 (61) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/helpers/client-generator.cjs +143 -2
  3. package/dist/helpers/client-generator.d.cts +17 -0
  4. package/dist/helpers/client-generator.d.cts.map +1 -0
  5. package/dist/helpers/client-generator.d.mts +17 -0
  6. package/dist/helpers/client-generator.d.mts.map +1 -0
  7. package/dist/helpers/client-generator.mjs +143 -2
  8. package/dist/helpers/client-generator.mjs.map +1 -0
  9. package/dist/helpers/get-schema.cjs +100 -2
  10. package/dist/helpers/get-schema.d.cts +13 -0
  11. package/dist/helpers/get-schema.d.cts.map +1 -0
  12. package/dist/helpers/get-schema.d.mts +13 -0
  13. package/dist/helpers/get-schema.d.mts.map +1 -0
  14. package/dist/helpers/get-schema.mjs +2 -1
  15. package/dist/helpers/get-schema.mjs.map +1 -0
  16. package/dist/helpers/index.cjs +4 -4
  17. package/dist/helpers/index.d.cts +5 -0
  18. package/dist/helpers/index.d.mts +5 -0
  19. package/dist/helpers/index.mjs +1 -1
  20. package/dist/helpers/schema-creator.cjs +1 -1
  21. package/dist/helpers/schema-creator.d.cts +20 -0
  22. package/dist/helpers/schema-creator.d.cts.map +1 -0
  23. package/dist/helpers/schema-creator.d.mts +20 -0
  24. package/dist/helpers/schema-creator.d.mts.map +1 -0
  25. package/dist/helpers/schema-creator.mjs +2 -1
  26. package/dist/helpers/schema-creator.mjs.map +1 -0
  27. package/dist/helpers/typed-sql.cjs +1 -1
  28. package/dist/helpers/typed-sql.d.cts +7 -0
  29. package/dist/helpers/typed-sql.d.cts.map +1 -0
  30. package/dist/helpers/typed-sql.d.mts +7 -0
  31. package/dist/helpers/typed-sql.d.mts.map +1 -0
  32. package/dist/helpers/typed-sql.mjs +2 -1
  33. package/dist/helpers/typed-sql.mjs.map +1 -0
  34. package/dist/index.cjs +10 -9
  35. package/dist/index.d.cts +20 -0
  36. package/dist/index.d.cts.map +1 -0
  37. package/dist/index.d.mts +20 -0
  38. package/dist/index.d.mts.map +1 -0
  39. package/dist/index.mjs +4 -3
  40. package/dist/index.mjs.map +1 -0
  41. package/dist/package.cjs +11 -0
  42. package/dist/package.mjs +6 -0
  43. package/dist/package.mjs.map +1 -0
  44. package/dist/types/index.cjs +0 -2
  45. package/dist/types/index.d.cts +3 -0
  46. package/dist/types/index.d.mts +3 -0
  47. package/dist/types/index.mjs +0 -3
  48. package/dist/types/plugin.d.cts +111 -0
  49. package/dist/types/plugin.d.cts.map +1 -0
  50. package/dist/types/plugin.d.mts +111 -0
  51. package/dist/types/plugin.d.mts.map +1 -0
  52. package/dist/types/prisma.d.cts +94 -0
  53. package/dist/types/prisma.d.cts.map +1 -0
  54. package/dist/types/prisma.d.mts +94 -0
  55. package/dist/types/prisma.d.mts.map +1 -0
  56. package/package.json +6 -6
  57. package/dist/client-generator-BoWegnfS.mjs +0 -146
  58. package/dist/client-generator-CMCbRxho.cjs +0 -152
  59. package/dist/client-generator-CQiim7Qj.cjs +0 -152
  60. package/dist/client-generator-CxKIlqpl.mjs +0 -146
  61. package/dist/get-schema-OhMkdmwI.cjs +0 -138
@@ -1,146 +0,0 @@
1
- import { findFileExtension } from "@stryke/path/find";
2
- import { buildClient } from "@prisma/client-generator-ts";
3
- import { enginesVersion } from "@prisma/engines-version";
4
- import { bufferToString } from "@stryke/convert/buffer-to-string";
5
- import { replaceExtension } from "@stryke/path/replace";
6
- import { isBuffer } from "@stryke/type-checks/is-buffer";
7
- import { isString } from "@stryke/type-checks/is-string";
8
-
9
- //#region package.json
10
- var version = "0.4.81";
11
-
12
- //#endregion
13
- //#region src/helpers/client-generator.ts
14
- var PowerlinesClientGenerator = class {
15
- #options;
16
- name = "powerlines-client";
17
- constructor(context) {
18
- this.context = context;
19
- this.#options = {
20
- name: this.name,
21
- output: null,
22
- config: {},
23
- provider: {
24
- fromEnvVar: "POWERLINES_CLIENT_PROVIDER",
25
- value: this.name
26
- },
27
- binaryTargets: [],
28
- previewFeatures: this.context.prisma.previewFeatures,
29
- sourceFilePath: this.context.prisma.schema.schemaRootDir
30
- };
31
- }
32
- async getManifest(_config) {
33
- return Promise.resolve({
34
- defaultOutput: "./generated",
35
- prettyName: "Powerlines Client",
36
- version,
37
- requiresEngines: [],
38
- requiresEngineVersion: enginesVersion
39
- });
40
- }
41
- async generate() {
42
- const { prismaClientDmmf, fileMap } = buildClient({
43
- datamodel: this.context.prisma.schema.schemas.map((s) => s.content).join("\n"),
44
- schemaPath: this.context.prisma.schema.schemaPath,
45
- binaryPaths: {},
46
- datasources: this.context.prisma.schema.datasources,
47
- outputDir: this.context.config.prisma.outputPath,
48
- runtimeBase: "@prisma/client/runtime",
49
- dmmf: this.context.prisma.dmmf,
50
- generator: this.#options,
51
- engineVersion: enginesVersion,
52
- clientVersion: version,
53
- activeProvider: this.context.prisma.schema.primaryDatasource?.activeProvider,
54
- typedSql: this.context.prisma.typedSql,
55
- target: this.context.config.prisma.runtime,
56
- generatedFileExtension: "ts",
57
- importFileExtension: "ts",
58
- moduleFormat: "esm",
59
- tsNoCheckPreamble: true,
60
- compilerBuild: "fast"
61
- });
62
- const errorArray = [];
63
- const denylists = {
64
- models: [
65
- "PrismaClient",
66
- "Prisma",
67
- "async",
68
- "await",
69
- "break",
70
- "case",
71
- "catch",
72
- "class",
73
- "const",
74
- "continue",
75
- "debugger",
76
- "default",
77
- "delete",
78
- "do",
79
- "else",
80
- "enum",
81
- "export",
82
- "extends",
83
- "false",
84
- "finally",
85
- "for",
86
- "function",
87
- "if",
88
- "implements",
89
- "import",
90
- "in",
91
- "instanceof",
92
- "interface",
93
- "let",
94
- "new",
95
- "null",
96
- "package",
97
- "private",
98
- "protected",
99
- "public",
100
- "return",
101
- "super",
102
- "switch",
103
- "this",
104
- "throw",
105
- "true",
106
- "try",
107
- "using",
108
- "typeof",
109
- "var",
110
- "void",
111
- "while",
112
- "with",
113
- "yield"
114
- ],
115
- fields: [
116
- "AND",
117
- "OR",
118
- "NOT"
119
- ],
120
- dynamic: []
121
- };
122
- if (prismaClientDmmf.datamodel.enums) {
123
- for (const it of prismaClientDmmf.datamodel.enums) if (denylists.models.includes(it.name) || denylists.fields.includes(it.name)) errorArray.push(/* @__PURE__ */ new Error(`"enum ${it.name}"`));
124
- }
125
- if (prismaClientDmmf.datamodel.models) {
126
- for (const it of prismaClientDmmf.datamodel.models) if (denylists.models.includes(it.name) || denylists.fields.includes(it.name)) errorArray.push(/* @__PURE__ */ new Error(`"model ${it.name}"`));
127
- }
128
- if (errorArray.length > 0) {
129
- let message = `Error: The schema at "${this.context.prisma.schema.schemaPath}" contains reserved keywords.\n Rename the following items:`;
130
- for (const error of errorArray) message += `\n - ${error.message}`;
131
- throw new Error(`${message}\nTo learn more about how to rename models, check out https://pris.ly/d/naming-models`);
132
- }
133
- await this.writeFileMap(fileMap);
134
- }
135
- stop() {}
136
- async writeFileMap(fileMap) {
137
- return Promise.all(Object.entries(fileMap).map(async ([fileName, content]) => {
138
- if (isString(content)) this.context.emitBuiltinSync(content, `prisma/${replaceExtension(fileName)}`, { extension: findFileExtension(fileName) || "ts" });
139
- else if (isBuffer(content)) this.context.emitBuiltinSync(bufferToString(content), `prisma/${replaceExtension(fileName)}`, { extension: findFileExtension(fileName) || "ts" });
140
- else await this.writeFileMap(content);
141
- }));
142
- }
143
- };
144
-
145
- //#endregion
146
- export { PowerlinesClientGenerator as t };
@@ -1,138 +0,0 @@
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, 1);
31
- let fp_ts_Either = require("fp-ts/Either");
32
- fp_ts_Either = __toESM(fp_ts_Either, 1);
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 schemaPath - 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
- });