@powerlines/plugin-prisma 0.4.111 → 0.4.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client-generator-B7ixcoYG.mjs +2 -0
- package/dist/client-generator-CXGC6qf4.cjs +2 -0
- package/dist/client-generator-CxSJThTu.mjs +2 -0
- package/dist/client-generator-DP-c-kAJ.cjs +2 -0
- package/dist/get-schema-BUxb6ANl.cjs +1 -0
- package/dist/helpers/client-generator.cjs +1 -4
- package/dist/helpers/client-generator.mjs +1 -3
- package/dist/helpers/get-schema.cjs +1 -4
- package/dist/helpers/get-schema.mjs +1 -98
- package/dist/helpers/index.cjs +1 -10
- package/dist/helpers/index.mjs +1 -6
- package/dist/helpers/schema-creator.cjs +12 -60
- package/dist/helpers/schema-creator.mjs +12 -58
- package/dist/helpers/typed-sql.cjs +3 -38
- package/dist/helpers/typed-sql.mjs +3 -36
- package/dist/index.cjs +1 -149
- package/dist/index.mjs +1 -144
- package/dist/types/index.cjs +1 -2
- package/dist/types/index.mjs +1 -4
- package/dist/types/plugin.mjs +1 -1
- package/dist/types/prisma.mjs +1 -1
- package/package.json +5 -5
- package/dist/client-generator-CKfvwlAl.mjs +0 -146
- package/dist/client-generator-DGm0RhWT.cjs +0 -152
- package/dist/client-generator-DxSrveMa.mjs +0 -146
- package/dist/client-generator-VnXV260K.cjs +0 -152
- package/dist/get-schema-OhMkdmwI.cjs +0 -138
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{findFileExtension as e}from"@stryke/path/find";import{buildClient as t}from"@prisma/client-generator-ts";import{enginesVersion as n}from"@prisma/engines-version";import{bufferToString as r}from"@stryke/convert/buffer-to-string";import{replaceExtension as i}from"@stryke/path/replace";import{isBuffer as a}from"@stryke/type-checks/is-buffer";import{isString as o}from"@stryke/type-checks/is-string";var s=`0.4.112`,c=class{#e;name=`powerlines-client`;constructor(e){this.context=e,this.#e={name:this.name,output:null,config:{},provider:{fromEnvVar:`POWERLINES_CLIENT_PROVIDER`,value:this.name},binaryTargets:[],previewFeatures:this.context.prisma.previewFeatures,sourceFilePath:this.context.prisma.schema.schemaRootDir}}async getManifest(e){return Promise.resolve({defaultOutput:`./generated`,prettyName:`Powerlines Client`,version:s,requiresEngines:[],requiresEngineVersion:n})}async generate(){let{prismaClientDmmf:e,fileMap:r}=t({datamodel:this.context.prisma.schema.schemas.map(e=>e.content).join(`
|
|
2
|
+
`),schemaPath:this.context.prisma.schema.schemaPath,binaryPaths:{},datasources:this.context.prisma.schema.datasources,outputDir:this.context.config.prisma.outputPath,runtimeBase:`@prisma/client/runtime`,dmmf:this.context.prisma.dmmf,generator:this.#e,engineVersion:n,clientVersion:s,activeProvider:this.context.prisma.schema.primaryDatasource?.activeProvider,typedSql:this.context.prisma.typedSql,target:this.context.config.prisma.runtime,generatedFileExtension:`ts`,importFileExtension:`ts`,moduleFormat:`esm`,tsNoCheckPreamble:!0,compilerBuild:`fast`}),i=[],a={models:`PrismaClient.Prisma.async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.super.switch.this.throw.true.try.using.typeof.var.void.while.with.yield`.split(`.`),fields:[`AND`,`OR`,`NOT`],dynamic:[]};if(e.datamodel.enums)for(let t of e.datamodel.enums)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"enum ${t.name}"`));if(e.datamodel.models)for(let t of e.datamodel.models)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"model ${t.name}"`));if(i.length>0){let e=`Error: The schema at "${this.context.prisma.schema.schemaPath}" contains reserved keywords.\n Rename the following items:`;for(let t of i)e+=`\n - ${t.message}`;throw Error(`${e}\nTo learn more about how to rename models, check out https://pris.ly/d/naming-models`)}await this.writeFileMap(r)}stop(){}async writeFileMap(t){return Promise.all(Object.entries(t).map(async([t,n])=>{o(n)?this.context.emitBuiltinSync(n,`prisma/${i(t)}`,{extension:e(t)||`ts`}):a(n)?this.context.emitBuiltinSync(r(n),`prisma/${i(t)}`,{extension:e(t)||`ts`}):await this.writeFileMap(n)}))}};export{c as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`./get-schema-BUxb6ANl.cjs`);let e=require(`@stryke/path/find`),t=require(`@prisma/client-generator-ts`),n=require(`@prisma/engines-version`),r=require(`@stryke/convert/buffer-to-string`),i=require(`@stryke/path/replace`),a=require(`@stryke/type-checks/is-buffer`),o=require(`@stryke/type-checks/is-string`);var s=`0.4.113`,c=class{#e;name=`powerlines-client`;constructor(e){this.context=e,this.#e={name:this.name,output:null,config:{},provider:{fromEnvVar:`POWERLINES_CLIENT_PROVIDER`,value:this.name},binaryTargets:[],previewFeatures:this.context.prisma.previewFeatures,sourceFilePath:this.context.prisma.schema.schemaRootDir}}async getManifest(e){return Promise.resolve({defaultOutput:`./generated`,prettyName:`Powerlines Client`,version:s,requiresEngines:[],requiresEngineVersion:n.enginesVersion})}async generate(){let{prismaClientDmmf:e,fileMap:r}=(0,t.buildClient)({datamodel:this.context.prisma.schema.schemas.map(e=>e.content).join(`
|
|
2
|
+
`),schemaPath:this.context.prisma.schema.schemaPath,binaryPaths:{},datasources:this.context.prisma.schema.datasources,outputDir:this.context.config.prisma.outputPath,runtimeBase:`@prisma/client/runtime`,dmmf:this.context.prisma.dmmf,generator:this.#e,engineVersion:n.enginesVersion,clientVersion:s,activeProvider:this.context.prisma.schema.primaryDatasource?.activeProvider,typedSql:this.context.prisma.typedSql,target:this.context.config.prisma.runtime,generatedFileExtension:`ts`,importFileExtension:`ts`,moduleFormat:`esm`,tsNoCheckPreamble:!0,compilerBuild:`fast`}),i=[],a={models:`PrismaClient.Prisma.async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.super.switch.this.throw.true.try.using.typeof.var.void.while.with.yield`.split(`.`),fields:[`AND`,`OR`,`NOT`],dynamic:[]};if(e.datamodel.enums)for(let t of e.datamodel.enums)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"enum ${t.name}"`));if(e.datamodel.models)for(let t of e.datamodel.models)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"model ${t.name}"`));if(i.length>0){let e=`Error: The schema at "${this.context.prisma.schema.schemaPath}" contains reserved keywords.\n Rename the following items:`;for(let t of i)e+=`\n - ${t.message}`;throw Error(`${e}\nTo learn more about how to rename models, check out https://pris.ly/d/naming-models`)}await this.writeFileMap(r)}stop(){}async writeFileMap(t){return Promise.all(Object.entries(t).map(async([t,n])=>{(0,o.isString)(n)?this.context.emitBuiltinSync(n,`prisma/${(0,i.replaceExtension)(t)}`,{extension:(0,e.findFileExtension)(t)||`ts`}):(0,a.isBuffer)(n)?this.context.emitBuiltinSync((0,r.bufferToString)(n),`prisma/${(0,i.replaceExtension)(t)}`,{extension:(0,e.findFileExtension)(t)||`ts`}):await this.writeFileMap(n)}))}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{findFileExtension as e}from"@stryke/path/find";import{buildClient as t}from"@prisma/client-generator-ts";import{enginesVersion as n}from"@prisma/engines-version";import{bufferToString as r}from"@stryke/convert/buffer-to-string";import{replaceExtension as i}from"@stryke/path/replace";import{isBuffer as a}from"@stryke/type-checks/is-buffer";import{isString as o}from"@stryke/type-checks/is-string";var s=`0.4.113`,c=class{#e;name=`powerlines-client`;constructor(e){this.context=e,this.#e={name:this.name,output:null,config:{},provider:{fromEnvVar:`POWERLINES_CLIENT_PROVIDER`,value:this.name},binaryTargets:[],previewFeatures:this.context.prisma.previewFeatures,sourceFilePath:this.context.prisma.schema.schemaRootDir}}async getManifest(e){return Promise.resolve({defaultOutput:`./generated`,prettyName:`Powerlines Client`,version:s,requiresEngines:[],requiresEngineVersion:n})}async generate(){let{prismaClientDmmf:e,fileMap:r}=t({datamodel:this.context.prisma.schema.schemas.map(e=>e.content).join(`
|
|
2
|
+
`),schemaPath:this.context.prisma.schema.schemaPath,binaryPaths:{},datasources:this.context.prisma.schema.datasources,outputDir:this.context.config.prisma.outputPath,runtimeBase:`@prisma/client/runtime`,dmmf:this.context.prisma.dmmf,generator:this.#e,engineVersion:n,clientVersion:s,activeProvider:this.context.prisma.schema.primaryDatasource?.activeProvider,typedSql:this.context.prisma.typedSql,target:this.context.config.prisma.runtime,generatedFileExtension:`ts`,importFileExtension:`ts`,moduleFormat:`esm`,tsNoCheckPreamble:!0,compilerBuild:`fast`}),i=[],a={models:`PrismaClient.Prisma.async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.super.switch.this.throw.true.try.using.typeof.var.void.while.with.yield`.split(`.`),fields:[`AND`,`OR`,`NOT`],dynamic:[]};if(e.datamodel.enums)for(let t of e.datamodel.enums)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"enum ${t.name}"`));if(e.datamodel.models)for(let t of e.datamodel.models)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"model ${t.name}"`));if(i.length>0){let e=`Error: The schema at "${this.context.prisma.schema.schemaPath}" contains reserved keywords.\n Rename the following items:`;for(let t of i)e+=`\n - ${t.message}`;throw Error(`${e}\nTo learn more about how to rename models, check out https://pris.ly/d/naming-models`)}await this.writeFileMap(r)}stop(){}async writeFileMap(t){return Promise.all(Object.entries(t).map(async([t,n])=>{o(n)?this.context.emitBuiltinSync(n,`prisma/${i(t)}`,{extension:e(t)||`ts`}):a(n)?this.context.emitBuiltinSync(r(n),`prisma/${i(t)}`,{extension:e(t)||`ts`}):await this.writeFileMap(n)}))}};export{c as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`./get-schema-BUxb6ANl.cjs`);let e=require(`@stryke/path/find`),t=require(`@prisma/client-generator-ts`),n=require(`@prisma/engines-version`),r=require(`@stryke/convert/buffer-to-string`),i=require(`@stryke/path/replace`),a=require(`@stryke/type-checks/is-buffer`),o=require(`@stryke/type-checks/is-string`);var s=`0.4.112`,c=class{#e;name=`powerlines-client`;constructor(e){this.context=e,this.#e={name:this.name,output:null,config:{},provider:{fromEnvVar:`POWERLINES_CLIENT_PROVIDER`,value:this.name},binaryTargets:[],previewFeatures:this.context.prisma.previewFeatures,sourceFilePath:this.context.prisma.schema.schemaRootDir}}async getManifest(e){return Promise.resolve({defaultOutput:`./generated`,prettyName:`Powerlines Client`,version:s,requiresEngines:[],requiresEngineVersion:n.enginesVersion})}async generate(){let{prismaClientDmmf:e,fileMap:r}=(0,t.buildClient)({datamodel:this.context.prisma.schema.schemas.map(e=>e.content).join(`
|
|
2
|
+
`),schemaPath:this.context.prisma.schema.schemaPath,binaryPaths:{},datasources:this.context.prisma.schema.datasources,outputDir:this.context.config.prisma.outputPath,runtimeBase:`@prisma/client/runtime`,dmmf:this.context.prisma.dmmf,generator:this.#e,engineVersion:n.enginesVersion,clientVersion:s,activeProvider:this.context.prisma.schema.primaryDatasource?.activeProvider,typedSql:this.context.prisma.typedSql,target:this.context.config.prisma.runtime,generatedFileExtension:`ts`,importFileExtension:`ts`,moduleFormat:`esm`,tsNoCheckPreamble:!0,compilerBuild:`fast`}),i=[],a={models:`PrismaClient.Prisma.async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.super.switch.this.throw.true.try.using.typeof.var.void.while.with.yield`.split(`.`),fields:[`AND`,`OR`,`NOT`],dynamic:[]};if(e.datamodel.enums)for(let t of e.datamodel.enums)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"enum ${t.name}"`));if(e.datamodel.models)for(let t of e.datamodel.models)(a.models.includes(t.name)||a.fields.includes(t.name))&&i.push(Error(`"model ${t.name}"`));if(i.length>0){let e=`Error: The schema at "${this.context.prisma.schema.schemaPath}" contains reserved keywords.\n Rename the following items:`;for(let t of i)e+=`\n - ${t.message}`;throw Error(`${e}\nTo learn more about how to rename models, check out https://pris.ly/d/naming-models`)}await this.writeFileMap(r)}stop(){}async writeFileMap(t){return Promise.all(Object.entries(t).map(async([t,n])=>{(0,o.isString)(n)?this.context.emitBuiltinSync(n,`prisma/${(0,i.replaceExtension)(t)}`,{extension:(0,e.findFileExtension)(t)||`ts`}):(0,a.isBuffer)(n)?this.context.emitBuiltinSync((0,r.bufferToString)(n),`prisma/${(0,i.replaceExtension)(t)}`,{extension:(0,e.findFileExtension)(t)||`ts`}):await this.writeFileMap(n)}))}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@prisma/get-platform`),l=require(`@prisma/prisma-schema-wasm`);l=s(l,1);let u=require(`fp-ts/Either`);u=s(u,1);let d=require(`fp-ts/lib/function`),f=require(`ts-pattern`);async function p(e){for(let t of e.binaryTargets){if(t.fromEnvVar&&process.env[t.fromEnvVar]){let n=JSON.parse(process.env[t.fromEnvVar]);Array.isArray(n)?(e.binaryTargets=n.map(e=>({fromEnvVar:null,value:e})),await p(e)):t.value=n}t.value===`native`&&(t.value=await(0,c.getBinaryTargetForCurrentPlatform)(),t.native=!0)}e.binaryTargets.length===0&&(e.binaryTargets=[{fromEnvVar:null,value:await(0,c.getBinaryTargetForCurrentPlatform)(),native:!0}])}async function m(e){let t=(0,d.pipe)(u.tryCatch(()=>{process.env.FORCE_PANIC_QUERY_ENGINE_GET_CONFIG&&l.default.debug_panic();let t=JSON.stringify({prismaSchema:e,datasourceOverrides:{},ignoreEnvVarErrors:!0,env:process.env});return l.default.get_config(t)},e=>({type:`wasm-error`,reason:`(get-config wasm)`,error:e})),u.map(e=>({result:e})),u.chainW(({result:e})=>u.tryCatch(()=>JSON.parse(e),e=>({type:`parse-json`,reason:`Unable to parse JSON`,error:e}))),u.chainW(e=>e.errors.length>0?u.left({type:`validation-error`,reason:`(get-config wasm)`,error:e.errors}):u.right(e.config)));if(u.isRight(t)){let{right:e}=t;for(let t of e.generators)await p(t);return Promise.resolve(e)}throw(0,f.match)(t.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 h(e){let t={path:e,content:``,generators:[],datasources:[],warnings:[]},n=await m(e);return{...t,...n}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return h}});
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_client_generator = require('../client-generator-VnXV260K.cjs');
|
|
3
|
-
|
|
4
|
-
exports.PowerlinesClientGenerator = require_client_generator.PowerlinesClientGenerator;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../client-generator-CXGC6qf4.cjs`);exports.PowerlinesClientGenerator=e.t;
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
-
|
|
4
|
-
exports.getSchema = require_get_schema.getSchema;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../get-schema-BUxb6ANl.cjs`);exports.getSchema=e.t;
|
|
@@ -1,98 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
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};
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_get_schema = require('../get-schema-OhMkdmwI.cjs');
|
|
3
|
-
const require_client_generator = require('../client-generator-VnXV260K.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
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../get-schema-BUxb6ANl.cjs`),t=require(`../client-generator-CXGC6qf4.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;
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{t as e}from"../client-generator-CxSJThTu.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,62 +1,14 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}` : ""}
|
|
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
|
+
}`:``}
|
|
51
12
|
}
|
|
52
13
|
|
|
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;
|
|
14
|
+
${e}`;return e}async write(){await this.#e.fs.write(this.#e.config.prisma.schema,this.build())}};exports.PrismaSchemaCreator=t;
|
|
@@ -1,60 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}` : ""}
|
|
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
|
+
}`:``}
|
|
49
12
|
}
|
|
50
13
|
|
|
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 };
|
|
14
|
+
${e}`;return e}async write(){await this.#e.fs.write(this.#e.config.prisma.schema,this.build())}};export{t as PrismaSchemaCreator};
|
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
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,36 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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 };
|
|
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};
|
package/dist/index.cjs
CHANGED
|
@@ -1,149 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
const require_get_schema = require('./get-schema-OhMkdmwI.cjs');
|
|
3
|
-
const require_client_generator = require('./client-generator-VnXV260K.cjs');
|
|
4
|
-
const require_helpers_schema_creator = require('./helpers/schema-creator.cjs');
|
|
5
|
-
const require_helpers_typed_sql = require('./helpers/typed-sql.cjs');
|
|
6
|
-
let _powerlines_plugin_pulumi = require("@powerlines/plugin-pulumi");
|
|
7
|
-
_powerlines_plugin_pulumi = require_get_schema.__toESM(_powerlines_plugin_pulumi, 1);
|
|
8
|
-
let _prisma_client_generator_registry = require("@prisma/client-generator-registry");
|
|
9
|
-
let _prisma_engines = require("@prisma/engines");
|
|
10
|
-
let _prisma_internals = require("@prisma/internals");
|
|
11
|
-
let _pulumi_prisma_postgres = require("@pulumi/prisma-postgres");
|
|
12
|
-
_pulumi_prisma_postgres = require_get_schema.__toESM(_pulumi_prisma_postgres, 1);
|
|
13
|
-
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
14
|
-
let _stryke_path_append = require("@stryke/path/append");
|
|
15
|
-
let _stryke_path_common = require("@stryke/path/common");
|
|
16
|
-
let _stryke_path_find = require("@stryke/path/find");
|
|
17
|
-
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
18
|
-
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
19
|
-
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
20
|
-
let defu = require("defu");
|
|
21
|
-
defu = require_get_schema.__toESM(defu, 1);
|
|
22
|
-
let powerlines_plugin_utils = require("powerlines/plugin-utils");
|
|
23
|
-
|
|
24
|
-
//#region src/index.ts
|
|
25
|
-
/**
|
|
26
|
-
* A Powerlines plugin to integrate Prisma for code generation.
|
|
27
|
-
*
|
|
28
|
-
* @param options - The plugin options.
|
|
29
|
-
* @returns A Powerlines plugin instance.
|
|
30
|
-
*/
|
|
31
|
-
const plugin = (options = {}) => {
|
|
32
|
-
return [...(0, _powerlines_plugin_pulumi.default)(options.pulumi), {
|
|
33
|
-
name: "prisma",
|
|
34
|
-
config() {
|
|
35
|
-
return { prisma: (0, defu.default)(options, {
|
|
36
|
-
schema: (0, _stryke_path_join_paths.joinPaths)(this.config.root, "prisma", "*.prisma"),
|
|
37
|
-
configFile: options.configFile || (0, powerlines_plugin_utils.getConfigPath)(this, "prisma.config"),
|
|
38
|
-
runtime: options.runtime || "nodejs",
|
|
39
|
-
outputPath: (0, _stryke_path_join_paths.joinPaths)("{builtinPath}", "prisma"),
|
|
40
|
-
prismaPostgres: options.prismaPostgres ? {
|
|
41
|
-
projectId: this.config.name,
|
|
42
|
-
region: "us-east-1"
|
|
43
|
-
} : void 0
|
|
44
|
-
}) };
|
|
45
|
-
},
|
|
46
|
-
async configResolved() {
|
|
47
|
-
this.dependencies["@prisma/ppg"] = "latest";
|
|
48
|
-
this.config.prisma.configFile = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.configFile);
|
|
49
|
-
if (!this.config.prisma.schema) throw new Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
50
|
-
this.config.prisma.schema = (0, _stryke_convert_to_array.toArray)(this.config.prisma.schema).map((schemaPath) => (0, powerlines_plugin_utils.replacePathTokens)(this, schemaPath));
|
|
51
|
-
if (!this.config.prisma.outputPath) throw new Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);
|
|
52
|
-
this.config.prisma.outputPath = (0, powerlines_plugin_utils.replacePathTokens)(this, this.config.prisma.outputPath);
|
|
53
|
-
this.prisma ??= {};
|
|
54
|
-
this.prisma.config = (0, _prisma_internals.validatePrismaConfigWithDatasource)({
|
|
55
|
-
config: this.config.prisma,
|
|
56
|
-
cmd: "generate --sql"
|
|
57
|
-
});
|
|
58
|
-
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);
|
|
59
|
-
this.prisma.schema ??= {
|
|
60
|
-
schemaRootDir,
|
|
61
|
-
loadedFromPathForLogMessages: (0, _stryke_path_find.relativePath)(this.config.root, schemaRootDir),
|
|
62
|
-
schemaPath: schemaRootDir,
|
|
63
|
-
schemas: [],
|
|
64
|
-
schemaFiles: [],
|
|
65
|
-
generators: [],
|
|
66
|
-
datasources: [],
|
|
67
|
-
warnings: [],
|
|
68
|
-
primaryDatasource: void 0
|
|
69
|
-
};
|
|
70
|
-
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)));
|
|
71
|
-
this.prisma.schema = this.prisma.schema.schemas.reduce((ret, schema) => {
|
|
72
|
-
ret.datasources.push(...schema.datasources);
|
|
73
|
-
ret.generators.push(...schema.generators);
|
|
74
|
-
ret.warnings.push(...schema.warnings);
|
|
75
|
-
ret.schemaFiles.push([schema.path, schema.content]);
|
|
76
|
-
return ret;
|
|
77
|
-
}, this.prisma.schema);
|
|
78
|
-
this.prisma.schema.primaryDatasource = this.prisma.schema.datasources.at(0);
|
|
79
|
-
this.prisma.schema.schemaPath = this.prisma.schema.schemas.at(0).path;
|
|
80
|
-
this.prisma.builder = new require_helpers_schema_creator.PrismaSchemaCreator(this);
|
|
81
|
-
},
|
|
82
|
-
async prepare() {
|
|
83
|
-
await this.prisma.builder.write();
|
|
84
|
-
this.prisma.previewFeatures = (0, _prisma_internals.extractPreviewFeatures)(this.prisma.schema.generators);
|
|
85
|
-
this.prisma.dmmf = await (0, _prisma_internals.getDMMF)({
|
|
86
|
-
datamodel: this.prisma.schema.schemaFiles,
|
|
87
|
-
previewFeatures: this.prisma.previewFeatures
|
|
88
|
-
});
|
|
89
|
-
const typedSql = await require_helpers_typed_sql.introspectSql(this);
|
|
90
|
-
let generators = await (0, _prisma_internals.getGenerators)({
|
|
91
|
-
schemaContext: this.prisma.schema,
|
|
92
|
-
printDownloadProgress: true,
|
|
93
|
-
version: _prisma_engines.enginesVersion,
|
|
94
|
-
typedSql,
|
|
95
|
-
allowNoModels: true,
|
|
96
|
-
registry: _prisma_client_generator_registry.defaultRegistry.toInternal()
|
|
97
|
-
});
|
|
98
|
-
if (!generators || !generators.some((gen) => [
|
|
99
|
-
"prisma-client",
|
|
100
|
-
"prisma-client-js",
|
|
101
|
-
"prisma-client-ts"
|
|
102
|
-
].includes(gen.name || gen.getProvider()))) {
|
|
103
|
-
generators ??= [];
|
|
104
|
-
generators.push(new require_client_generator.PowerlinesClientGenerator(this));
|
|
105
|
-
} else generators = generators.map((generator) => [
|
|
106
|
-
"prisma-client",
|
|
107
|
-
"prisma-client-js",
|
|
108
|
-
"prisma-client-ts"
|
|
109
|
-
].includes(generator.name || generator.getProvider()) ? new require_client_generator.PowerlinesClientGenerator(this) : generator);
|
|
110
|
-
for (const generator of generators) try {
|
|
111
|
-
await generator.generate();
|
|
112
|
-
generator.stop();
|
|
113
|
-
} catch (err) {
|
|
114
|
-
generator.stop();
|
|
115
|
-
this.error(`Error while generating with ${generator.name || generator.getProvider()}: ${err instanceof Error ? err.message : String(err)}`);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
pulumi: { async deploy() {
|
|
119
|
-
if (this.config.prisma.prismaPostgres) {
|
|
120
|
-
let serviceToken = process.env.PRISMA_SERVICE_TOKEN;
|
|
121
|
-
if (!serviceToken) {
|
|
122
|
-
serviceToken = options.serviceToken;
|
|
123
|
-
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.");
|
|
124
|
-
else throw new Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");
|
|
125
|
-
}
|
|
126
|
-
await this.pulumi.workspace.installPlugin("registry.terraform.io/prisma/prisma-postgres", "v0.2.0");
|
|
127
|
-
const project = new _pulumi_prisma_postgres.Project("project", { name: `${this.config.prisma.prismaPostgres?.projectId || this.config.name}` });
|
|
128
|
-
const database = new _pulumi_prisma_postgres.Database("database", {
|
|
129
|
-
projectId: project.id,
|
|
130
|
-
name: `${this.config.prisma.prismaPostgres?.databaseName || `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,
|
|
131
|
-
region: `${this.config.prisma.prismaPostgres?.region}`
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
project,
|
|
135
|
-
database,
|
|
136
|
-
connection: new _pulumi_prisma_postgres.Connection("connection", {
|
|
137
|
-
databaseId: database.id,
|
|
138
|
-
name: `${(0, _stryke_string_format_constant_case.constantCase)(this.config.name)}_API_KEY`
|
|
139
|
-
})
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
} }
|
|
144
|
-
}];
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
exports.default = plugin;
|
|
149
|
-
exports.plugin = plugin;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./get-schema-BUxb6ANl.cjs`),t=require(`./client-generator-CXGC6qf4.cjs`),n=require(`./helpers/schema-creator.cjs`),r=require(`./helpers/typed-sql.cjs`);let i=require(`@powerlines/plugin-pulumi`);i=e.n(i,1);let a=require(`@prisma/client-generator-registry`),o=require(`@prisma/engines`),s=require(`@prisma/internals`),c=require(`@pulumi/prisma-postgres`);c=e.n(c,1);let l=require(`@stryke/convert/to-array`),u=require(`@stryke/path/append`),d=require(`@stryke/path/common`),f=require(`@stryke/path/find`),p=require(`@stryke/path/join-paths`),m=require(`@stryke/string-format/constant-case`),h=require(`@stryke/string-format/kebab-case`),g=require(`defu`);g=e.n(g,1);let _=require(`powerlines/plugin-utils`);const v=(v={})=>[...(0,i.default)(v.pulumi),{name:`prisma`,config(){return{prisma:(0,g.default)(v,{schema:(0,p.joinPaths)(this.config.root,`prisma`,`*.prisma`),configFile:v.configFile||(0,_.getConfigPath)(this,`prisma.config`),runtime:v.runtime||`nodejs`,outputPath:(0,p.joinPaths)(`{builtinPath}`,`prisma`),prismaPostgres:v.prismaPostgres?{projectId:this.config.name,region:`us-east-1`}:void 0})}},async configResolved(){if(this.dependencies[`@prisma/ppg`]=`latest`,this.config.prisma.configFile=(0,_.replacePathTokens)(this,this.config.prisma.configFile),!this.config.prisma.schema)throw Error(`Prisma schema path is not defined. Please specify a valid path in the plugin configuration.`);if(this.config.prisma.schema=(0,l.toArray)(this.config.prisma.schema).map(e=>(0,_.replacePathTokens)(this,e)),!this.config.prisma.outputPath)throw Error(`Prisma generated path is not defined. Please specify a valid path in the plugin configuration.`);this.config.prisma.outputPath=(0,_.replacePathTokens)(this,this.config.prisma.outputPath),this.prisma??={},this.prisma.config=(0,s.validatePrismaConfigWithDatasource)({config:this.config.prisma,cmd:`generate --sql`});let t=(0,u.appendPath)((0,u.appendPath)((0,d.findBasePath)(this.config.prisma.schema),this.config.root),this.config.cwd);this.prisma.schema??={schemaRootDir:t,loadedFromPathForLogMessages:(0,f.relativePath)(this.config.root,t),schemaPath:t,schemas:[],schemaFiles:[],generators:[],datasources:[],warnings:[],primaryDatasource:void 0},this.prisma.schema.schemas=await Promise.all((await this.fs.glob(this.config.prisma.schema.map(e=>e.includes(`*`)||this.fs.isFileSync(e)?e:(0,p.joinPaths)(e,`**/*.prisma`)))).map(async t=>e.t(t))),this.prisma.schema=this.prisma.schema.schemas.reduce((e,t)=>(e.datasources.push(...t.datasources),e.generators.push(...t.generators),e.warnings.push(...t.warnings),e.schemaFiles.push([t.path,t.content]),e),this.prisma.schema),this.prisma.schema.primaryDatasource=this.prisma.schema.datasources.at(0),this.prisma.schema.schemaPath=this.prisma.schema.schemas.at(0).path,this.prisma.builder=new n.PrismaSchemaCreator(this)},async prepare(){await this.prisma.builder.write(),this.prisma.previewFeatures=(0,s.extractPreviewFeatures)(this.prisma.schema.generators),this.prisma.dmmf=await(0,s.getDMMF)({datamodel:this.prisma.schema.schemaFiles,previewFeatures:this.prisma.previewFeatures});let e=await r.introspectSql(this),n=await(0,s.getGenerators)({schemaContext:this.prisma.schema,printDownloadProgress:!0,version:o.enginesVersion,typedSql:e,allowNoModels:!0,registry:a.defaultRegistry.toInternal()});!n||!n.some(e=>[`prisma-client`,`prisma-client-js`,`prisma-client-ts`].includes(e.name||e.getProvider()))?(n??=[],n.push(new t.t(this))):n=n.map(e=>[`prisma-client`,`prisma-client-js`,`prisma-client-ts`].includes(e.name||e.getProvider())?new t.t(this):e);for(let e of n)try{await e.generate(),e.stop()}catch(t){e.stop(),this.error(`Error while generating with ${e.name||e.getProvider()}: ${t instanceof Error?t.message:String(t)}`)}},pulumi:{async deploy(){if(this.config.prisma.prismaPostgres){let e=process.env.PRISMA_SERVICE_TOKEN;if(!e)if(e=v.serviceToken,e)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.");else throw Error("Unable to determine the Prisma service token. Please set the `PRISMA_SERVICE_TOKEN` environment variable.");await this.pulumi.workspace.installPlugin(`registry.terraform.io/prisma/prisma-postgres`,`v0.2.0`);let t=new c.Project(`project`,{name:`${this.config.prisma.prismaPostgres?.projectId||this.config.name}`}),n=new c.Database(`database`,{projectId:t.id,name:`${this.config.prisma.prismaPostgres?.databaseName||`${(0,h.kebabCase)(this.config.name)}.${this.config.mode}.${this.config.prisma.prismaPostgres?.region}`}`,region:`${this.config.prisma.prismaPostgres?.region}`});return{project:t,database:n,connection:new c.Connection(`connection`,{databaseId:n.id,name:`${(0,m.constantCase)(this.config.name)}_API_KEY`})}}return null}}}];exports.default=v,exports.plugin=v;
|