@powerlines/plugin-prisma 0.4.139 → 0.4.141

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.
@@ -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, 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
+ });
@@ -1 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../client-generator-B56cunrE.cjs`);exports.PowerlinesClientGenerator=e.t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_client_generator = require('../client-generator-u4jrBLcl.cjs');
3
+
4
+ exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
@@ -1 +1,3 @@
1
- import{t as e}from"../client-generator-D6g8INQg.mjs";export{e as PowerlinesClientGenerator};
1
+ import { t as PowerlinesClientGenerator } from "../client-generator-Bv8CO27S.mjs";
2
+
3
+ export { PowerlinesClientGenerator };
@@ -1 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../get-schema-BUxb6ANl.cjs`);exports.getSchema=e.t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
3
+
4
+ exports.getSchema = require_get_schema.getSchema;
@@ -1 +1,98 @@
1
- import{getBinaryTargetForCurrentPlatform as e}from"@prisma/get-platform";import t from"@prisma/prisma-schema-wasm";import*as n from"fp-ts/Either";import{pipe as r}from"fp-ts/lib/function";import{match as i}from"ts-pattern";async function a(t){for(let n of t.binaryTargets){if(n.fromEnvVar&&process.env[n.fromEnvVar]){let e=JSON.parse(process.env[n.fromEnvVar]);Array.isArray(e)?(t.binaryTargets=e.map(e=>({fromEnvVar:null,value:e})),await a(t)):n.value=e}n.value===`native`&&(n.value=await e(),n.native=!0)}t.binaryTargets.length===0&&(t.binaryTargets=[{fromEnvVar:null,value:await e(),native:!0}])}async function o(e){let o=r(n.tryCatch(()=>{process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG&&t.debug_panic();let n=JSON.stringify({prismaSchema:e,datasourceOverrides:{},ignoreEnvVarErrors:!0,env:process.env});return t.get_config(n)},e=>({type:`wasm-error`,reason:`(get-config wasm)`,error:e})),n.map(e=>({result:e})),n.chainW(({result:e})=>n.tryCatch(()=>JSON.parse(e),e=>({type:`parse-json`,reason:`Unable to parse JSON`,error:e}))),n.chainW(e=>e.errors.length>0?n.left({type:`validation-error`,reason:`(get-config wasm)`,error:e.errors}):n.right(e.config)));if(n.isRight(o)){let{right:e}=o;for(let t of e.generators)await a(t);return Promise.resolve(e)}throw i(o.left).with({type:`wasm-error`},e=>Error(`Prisma get-config Wasm runtime error: ${e.error.message}`)).with({type:`validation-error`},e=>Error(`Prisma get-config validation error: ${e.error.map(e=>e.message).join(`, `)}`)).otherwise(e=>Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`))}async function s(e){let t={path:e,content:``,generators:[],datasources:[],warnings:[]},n=await o(e);return{...t,...n}}export{s as getSchema};
1
+ import { getBinaryTargetForCurrentPlatform } from "@prisma/get-platform";
2
+ import prismaSchemaWasm from "@prisma/prisma-schema-wasm";
3
+ import * as E from "fp-ts/Either";
4
+ import { pipe } from "fp-ts/lib/function";
5
+ import { match } from "ts-pattern";
6
+
7
+ //#region src/helpers/get-schema.ts
8
+ async function resolveBinaryTargets(generator) {
9
+ for (const binaryTarget of generator.binaryTargets) {
10
+ if (binaryTarget.fromEnvVar && process.env[binaryTarget.fromEnvVar]) {
11
+ const value = JSON.parse(process.env[binaryTarget.fromEnvVar]);
12
+ if (Array.isArray(value)) {
13
+ generator.binaryTargets = value.map((v) => ({
14
+ fromEnvVar: null,
15
+ value: v
16
+ }));
17
+ await resolveBinaryTargets(generator);
18
+ } else binaryTarget.value = value;
19
+ }
20
+ if (binaryTarget.value === "native") {
21
+ binaryTarget.value = await getBinaryTargetForCurrentPlatform();
22
+ binaryTarget.native = true;
23
+ }
24
+ }
25
+ if (generator.binaryTargets.length === 0) generator.binaryTargets = [{
26
+ fromEnvVar: null,
27
+ value: await getBinaryTargetForCurrentPlatform(),
28
+ native: true
29
+ }];
30
+ }
31
+ /**
32
+ * Retrieves the Prisma schema using the provided options.
33
+ *
34
+ * @param schemaPath - The path to the Prisma schema file.
35
+ * @returns The Prisma schema.
36
+ */
37
+ async function resolveDataModel(schemaPath) {
38
+ const configEither = pipe(E.tryCatch(() => {
39
+ if (process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG) prismaSchemaWasm.debug_panic();
40
+ const params = JSON.stringify({
41
+ prismaSchema: schemaPath,
42
+ datasourceOverrides: {},
43
+ ignoreEnvVarErrors: true,
44
+ env: process.env
45
+ });
46
+ return prismaSchemaWasm.get_config(params);
47
+ }, (e) => ({
48
+ type: "wasm-error",
49
+ reason: "(get-config wasm)",
50
+ error: e
51
+ })), E.map((result) => ({ result })), E.chainW(({ result }) => E.tryCatch(() => JSON.parse(result), (e) => ({
52
+ type: "parse-json",
53
+ reason: "Unable to parse JSON",
54
+ error: e
55
+ }))), E.chainW((response) => {
56
+ if (response.errors.length > 0) return E.left({
57
+ type: "validation-error",
58
+ reason: "(get-config wasm)",
59
+ error: response.errors
60
+ });
61
+ return E.right(response.config);
62
+ }));
63
+ if (E.isRight(configEither)) {
64
+ const { right: data } = configEither;
65
+ for (const generator of data.generators) await resolveBinaryTargets(generator);
66
+ return Promise.resolve(data);
67
+ }
68
+ throw match(configEither.left).with({ type: "wasm-error" }, (e) => {
69
+ return /* @__PURE__ */ new Error(`Prisma get-config Wasm runtime error: ${e.error.message}`);
70
+ }).with({ type: "validation-error" }, (e) => {
71
+ return /* @__PURE__ */ new Error(`Prisma get-config validation error: ${e.error.map((err) => err.message).join(", ")}`);
72
+ }).otherwise((e) => {
73
+ return /* @__PURE__ */ new Error(`Prisma get-config unknown error: ${e.reason} - ${e.error.message}`);
74
+ });
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
+ }
96
+
97
+ //#endregion
98
+ export { getSchema };
@@ -1 +1,10 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../get-schema-BUxb6ANl.cjs`),t=require(`../client-generator-B56cunrE.cjs`),n=require(`./schema-creator.cjs`),r=require(`./typed-sql.cjs`);exports.PowerlinesClientGenerator=t.t,exports.PrismaSchemaCreator=n.PrismaSchemaCreator,exports.getSchema=e.t,exports.introspectSql=r.introspectSql;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
3
+ const require_client_generator = require('../client-generator-u4jrBLcl.cjs');
4
+ const require_helpers_schema_creator = require('./schema-creator.cjs');
5
+ const require_helpers_typed_sql = require('./typed-sql.cjs');
6
+
7
+ exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
8
+ exports.PrismaSchemaCreator = require_helpers_schema_creator.PrismaSchemaCreator;
9
+ exports.getSchema = require_get_schema.getSchema;
10
+ exports.introspectSql = require_helpers_typed_sql.introspectSql;
@@ -1 +1,6 @@
1
- import{t as e}from"../client-generator-D6g8INQg.mjs";import{getSchema as t}from"./get-schema.mjs";import{PrismaSchemaCreator as n}from"./schema-creator.mjs";import{introspectSql as r}from"./typed-sql.mjs";export{e as PowerlinesClientGenerator,n as PrismaSchemaCreator,t as getSchema,r as introspectSql};
1
+ import { t as PowerlinesClientGenerator } from "../client-generator-Bv8CO27S.mjs";
2
+ import { getSchema } from "./get-schema.mjs";
3
+ import { PrismaSchemaCreator } from "./schema-creator.mjs";
4
+ import { introspectSql } from "./typed-sql.mjs";
5
+
6
+ export { PowerlinesClientGenerator, PrismaSchemaCreator, getSchema, introspectSql };
@@ -1,14 +1,62 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../get-schema-BUxb6ANl.cjs`);let e=require(`prisma-util/schema-creator`);var t=class extends e.SchemaCreator{#e;get generators(){return this.#e.prisma.schema.generators}set generators(e){this.#e.prisma.schema.generators=e}constructor(e){super(),this.#e=e,this.#e.prisma??={},this.#e.prisma.schema??={generators:[],datasources:[],warnings:[]},this.#e.prisma.schema.generators.forEach(e=>{this.pushGenerator(e)})}pushGenerator(e){return this.generators.some(t=>t.name===e.name)?this.generators=[...this.generators.filter(t=>t.name!==e.name),e]:this.generators.push(e),this}build(){let e=super.build();for(let t of this.generators)e=`
2
- generator ${t.name} {
3
- provider = "${t.provider.value}"
4
- output = "${t.output?.value}"${t.previewFeatures&&t.previewFeatures.length>0?`
5
- previewFeatures = [${t.previewFeatures.map(e=>`"${e}"`).join(`, `)}]`:``}${t.config&&Object.keys(t.config).length>0?Object.entries(t.config).map(([e,t])=>Array.isArray(t)?`${e} = [${t.map(e=>`"${e}"`).join(`, `)}]`:`${e} = "${t}"`).join(`
6
- `):``}${t.binaryTargets&&t.binaryTargets.length>0?`
7
- binaryTargets = [${t.binaryTargets.map(e=>`"${e.value}"`).join(`, `)}]`:``}${t.envPaths?.rootEnvPath||t.envPaths?.schemaEnvPath?`
8
- env = {${t.envPaths?.rootEnvPath?`
9
- root = "${t.envPaths.rootEnvPath}"`:``}${t.envPaths?.schemaEnvPath?`
10
- schema = "${t.envPaths.schemaEnvPath}"`:``}
11
- }`:``}
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
3
+ let prisma_util_schema_creator = require("prisma-util/schema-creator");
4
+
5
+ //#region src/helpers/schema-creator.ts
6
+ /**
7
+ * Prisma schema creator that allows building a schema via code.
8
+ */
9
+ var PrismaSchemaCreator = class extends prisma_util_schema_creator.SchemaCreator {
10
+ /** Prisma plugin context */
11
+ #context;
12
+ get generators() {
13
+ return this.#context.prisma.schema.generators;
14
+ }
15
+ set generators(value) {
16
+ this.#context.prisma.schema.generators = value;
17
+ }
18
+ constructor(context) {
19
+ super();
20
+ this.#context = context;
21
+ this.#context.prisma ??= {};
22
+ this.#context.prisma.schema ??= {
23
+ generators: [],
24
+ datasources: [],
25
+ warnings: []
26
+ };
27
+ this.#context.prisma.schema.generators.forEach((generator) => {
28
+ this.pushGenerator(generator);
29
+ });
30
+ }
31
+ pushGenerator(generator) {
32
+ if (this.generators.some((gen) => gen.name === generator.name)) this.generators = [...this.generators.filter((gen) => gen.name !== generator.name), generator];
33
+ else this.generators.push(generator);
34
+ return this;
35
+ }
36
+ build() {
37
+ let schema = super.build();
38
+ for (const generator of this.generators) schema = `
39
+ generator ${generator.name} {
40
+ provider = "${generator.provider.value}"
41
+ output = "${generator.output?.value}"${generator.previewFeatures && generator.previewFeatures.length > 0 ? `
42
+ previewFeatures = [${generator.previewFeatures.map((feature) => `"${feature}"`).join(", ")}]` : ""}${generator.config && Object.keys(generator.config).length > 0 ? Object.entries(generator.config).map(([key, value]) => {
43
+ if (Array.isArray(value)) return `${key} = [${value.map((v) => `"${v}"`).join(", ")}]`;
44
+ else return `${key} = "${value}"`;
45
+ }).join("\n ") : ""}${generator.binaryTargets && generator.binaryTargets.length > 0 ? `
46
+ binaryTargets = [${generator.binaryTargets.map((bt) => `"${bt.value}"`).join(", ")}]` : ""}${generator.envPaths?.rootEnvPath || generator.envPaths?.schemaEnvPath ? `
47
+ env = {${generator.envPaths?.rootEnvPath ? `
48
+ root = "${generator.envPaths.rootEnvPath}"` : ""}${generator.envPaths?.schemaEnvPath ? `
49
+ schema = "${generator.envPaths.schemaEnvPath}"` : ""}
50
+ }` : ""}
12
51
  }
13
52
 
14
- ${e}`;return e}async write(){await this.#e.fs.write(this.#e.config.prisma.schema,this.build())}};exports.PrismaSchemaCreator=t;
53
+ ${schema}`;
54
+ return schema;
55
+ }
56
+ async write() {
57
+ await this.#context.fs.write(this.#context.config.prisma.schema, this.build());
58
+ }
59
+ };
60
+
61
+ //#endregion
62
+ exports.PrismaSchemaCreator = PrismaSchemaCreator;
@@ -1,14 +1,60 @@
1
- import{SchemaCreator as e}from"prisma-util/schema-creator";var t=class extends e{#e;get generators(){return this.#e.prisma.schema.generators}set generators(e){this.#e.prisma.schema.generators=e}constructor(e){super(),this.#e=e,this.#e.prisma??={},this.#e.prisma.schema??={generators:[],datasources:[],warnings:[]},this.#e.prisma.schema.generators.forEach(e=>{this.pushGenerator(e)})}pushGenerator(e){return this.generators.some(t=>t.name===e.name)?this.generators=[...this.generators.filter(t=>t.name!==e.name),e]:this.generators.push(e),this}build(){let e=super.build();for(let t of this.generators)e=`
2
- generator ${t.name} {
3
- provider = "${t.provider.value}"
4
- output = "${t.output?.value}"${t.previewFeatures&&t.previewFeatures.length>0?`
5
- previewFeatures = [${t.previewFeatures.map(e=>`"${e}"`).join(`, `)}]`:``}${t.config&&Object.keys(t.config).length>0?Object.entries(t.config).map(([e,t])=>Array.isArray(t)?`${e} = [${t.map(e=>`"${e}"`).join(`, `)}]`:`${e} = "${t}"`).join(`
6
- `):``}${t.binaryTargets&&t.binaryTargets.length>0?`
7
- binaryTargets = [${t.binaryTargets.map(e=>`"${e.value}"`).join(`, `)}]`:``}${t.envPaths?.rootEnvPath||t.envPaths?.schemaEnvPath?`
8
- env = {${t.envPaths?.rootEnvPath?`
9
- root = "${t.envPaths.rootEnvPath}"`:``}${t.envPaths?.schemaEnvPath?`
10
- schema = "${t.envPaths.schemaEnvPath}"`:``}
11
- }`:``}
1
+ import { SchemaCreator } from "prisma-util/schema-creator";
2
+
3
+ //#region src/helpers/schema-creator.ts
4
+ /**
5
+ * Prisma schema creator that allows building a schema via code.
6
+ */
7
+ var PrismaSchemaCreator = class extends SchemaCreator {
8
+ /** Prisma plugin context */
9
+ #context;
10
+ get generators() {
11
+ return this.#context.prisma.schema.generators;
12
+ }
13
+ set generators(value) {
14
+ this.#context.prisma.schema.generators = value;
15
+ }
16
+ constructor(context) {
17
+ super();
18
+ this.#context = context;
19
+ this.#context.prisma ??= {};
20
+ this.#context.prisma.schema ??= {
21
+ generators: [],
22
+ datasources: [],
23
+ warnings: []
24
+ };
25
+ this.#context.prisma.schema.generators.forEach((generator) => {
26
+ this.pushGenerator(generator);
27
+ });
28
+ }
29
+ pushGenerator(generator) {
30
+ if (this.generators.some((gen) => gen.name === generator.name)) this.generators = [...this.generators.filter((gen) => gen.name !== generator.name), generator];
31
+ else this.generators.push(generator);
32
+ return this;
33
+ }
34
+ build() {
35
+ let schema = super.build();
36
+ for (const generator of this.generators) schema = `
37
+ generator ${generator.name} {
38
+ provider = "${generator.provider.value}"
39
+ output = "${generator.output?.value}"${generator.previewFeatures && generator.previewFeatures.length > 0 ? `
40
+ previewFeatures = [${generator.previewFeatures.map((feature) => `"${feature}"`).join(", ")}]` : ""}${generator.config && Object.keys(generator.config).length > 0 ? Object.entries(generator.config).map(([key, value]) => {
41
+ if (Array.isArray(value)) return `${key} = [${value.map((v) => `"${v}"`).join(", ")}]`;
42
+ else return `${key} = "${value}"`;
43
+ }).join("\n ") : ""}${generator.binaryTargets && generator.binaryTargets.length > 0 ? `
44
+ binaryTargets = [${generator.binaryTargets.map((bt) => `"${bt.value}"`).join(", ")}]` : ""}${generator.envPaths?.rootEnvPath || generator.envPaths?.schemaEnvPath ? `
45
+ env = {${generator.envPaths?.rootEnvPath ? `
46
+ root = "${generator.envPaths.rootEnvPath}"` : ""}${generator.envPaths?.schemaEnvPath ? `
47
+ schema = "${generator.envPaths.schemaEnvPath}"` : ""}
48
+ }` : ""}
12
49
  }
13
50
 
14
- ${e}`;return e}async write(){await this.#e.fs.write(this.#e.config.prisma.schema,this.build())}};export{t as PrismaSchemaCreator};
51
+ ${schema}`;
52
+ return schema;
53
+ }
54
+ async write() {
55
+ await this.#context.fs.write(this.#context.config.prisma.schema, this.build());
56
+ }
57
+ };
58
+
59
+ //#endregion
60
+ export { PrismaSchemaCreator };
@@ -1,3 +1,38 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../get-schema-BUxb6ANl.cjs`);let e=require(`@prisma/internals`),t=require(`@prisma/migrate`),n=require(`@stryke/path/file-path-fns`),r=require(`@stryke/path/join`);async function i(t,i){let a=await t.fs.list(i),o=[];for(let s of a)if((0,n.findFileExtension)(s)===`.sql`){if(!(0,e.isValidJsIdentifier)((0,n.findFileName)(s,{withExtension:!1})))throw Error(`${(0,r.joinPaths)(i,s)} can not be used as a typed sql query: name must be a valid JS identifier`);if((0,n.findFileName)(s).startsWith(`$`))throw Error(`${(0,r.joinPaths)(i,s)} can not be used as a typed sql query: name must not start with $`);o.push({name:(0,n.findFileName)(s,{withExtension:!1}),source:await t.fs.read((0,r.joinPaths)(i,s)),fileName:(0,r.joinPaths)(i,s)})}return o}async function a(r){let a=await i(r,(0,e.inferDirectoryConfig)(r.prisma.schema,r.prisma.config).typedSqlDirPath),o=await(0,t.introspectSql)(r.prisma.schema,r.prisma.config,r.config.root,a);if(o.ok)return o.queries;let s=[`Errors while reading sql files:
2
- `];for(let{fileName:e,message:t}of o.errors)s.push(`In ${(0,n.relativePath)(process.cwd(),e)}:`),s.push(t),s.push(``);throw Error(s.join(`
3
- `))}exports.introspectSql=a;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_get_schema = require('../get-schema-OhMkdmwI.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;
@@ -1,3 +1,36 @@
1
- import{inferDirectoryConfig as e,isValidJsIdentifier as t}from"@prisma/internals";import{introspectSql as n}from"@prisma/migrate";import{findFileExtension as r,findFileName as i,relativePath as a}from"@stryke/path/file-path-fns";import{joinPaths as o}from"@stryke/path/join";async function s(e,n){let a=await e.fs.list(n),s=[];for(let c of a)if(r(c)===`.sql`){if(!t(i(c,{withExtension:!1})))throw Error(`${o(n,c)} can not be used as a typed sql query: name must be a valid JS identifier`);if(i(c).startsWith(`$`))throw Error(`${o(n,c)} can not be used as a typed sql query: name must not start with $`);s.push({name:i(c,{withExtension:!1}),source:await e.fs.read(o(n,c)),fileName:o(n,c)})}return s}async function c(t){let r=await s(t,e(t.prisma.schema,t.prisma.config).typedSqlDirPath),i=await n(t.prisma.schema,t.prisma.config,t.config.root,r);if(i.ok)return i.queries;let o=[`Errors while reading sql files:
2
- `];for(let{fileName:e,message:t}of i.errors)o.push(`In ${a(process.cwd(),e)}:`),o.push(t),o.push(``);throw Error(o.join(`
3
- `))}export{c as introspectSql};
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 };