diff --git a/lib/@types/prisma-generator.ts b/lib/@types/prisma-generator.ts index 4273421..d1557bc 100644 --- a/lib/@types/prisma-generator.ts +++ b/lib/@types/prisma-generator.ts @@ -1,7 +1,13 @@ export interface PrismaGeneratorOptions { provider: string; + name?: string; output?: string; previewFeatures?: string[]; engineType?: "library" | "binary"; binaryTargets?: string[]; + [key: string]: string | string[] | undefined; } + +export type PrismaMultiGeneratorOptions = Array< + Omit & { name: string } +>; diff --git a/lib/index.ts b/lib/index.ts index 6140ef1..e27d324 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,11 +1,14 @@ import { PrismaSchema } from "@/modules/PrismaSchema"; import { PrismaDataSourceOptions } from "@/@types/prisma-datasource"; -import { PrismaGeneratorOptions } from "@/@types/prisma-generator"; +import { + PrismaGeneratorOptions, + PrismaMultiGeneratorOptions, +} from "@/@types/prisma-generator"; interface CreateSchemaOptions { datasource: PrismaDataSourceOptions; - generator: PrismaGeneratorOptions; + generator: PrismaGeneratorOptions | PrismaMultiGeneratorOptions; } /** diff --git a/lib/modules/PrismaScalarField.ts b/lib/modules/PrismaScalarField.ts index a8de09e..30a0ff0 100644 --- a/lib/modules/PrismaScalarField.ts +++ b/lib/modules/PrismaScalarField.ts @@ -50,7 +50,7 @@ export class PrismaScalarField { switch (typeof defaultValue) { case "object": const [prismaFunc] = - Object.entries(defaultValue).find(([_key, value]) => value) || []; + Object.entries(defaultValue).find(([, value]) => value) || []; setDefaultValue(`${prismaFunc}()`); break; case "string": diff --git a/lib/modules/PrismaSchema.ts b/lib/modules/PrismaSchema.ts index 72283e8..d7c1687 100644 --- a/lib/modules/PrismaSchema.ts +++ b/lib/modules/PrismaSchema.ts @@ -5,7 +5,10 @@ import { exportSchema } from "@/util/export"; import { parseKeyValueBlock } from "@/util/blocks"; import { PrismaDataSourceOptions } from "@/@types/prisma-datasource"; -import { PrismaGeneratorOptions } from "@/@types/prisma-generator"; +import { + PrismaGeneratorOptions, + PrismaMultiGeneratorOptions, +} from "@/@types/prisma-generator"; export class PrismaSchema { private enums: Map = new Map(); @@ -13,7 +16,9 @@ export class PrismaSchema { constructor( private readonly datasource: PrismaDataSourceOptions, - private readonly generator: PrismaGeneratorOptions + private readonly generator: + | PrismaGeneratorOptions + | PrismaMultiGeneratorOptions ) {} /** @@ -35,11 +40,19 @@ export class PrismaSchema { * @returns A string representing the generator block. */ private parseGenerator() { - return parseKeyValueBlock( - "generator", - "client", - Object.entries(this.generator) - ); + const generators = Array.isArray(this.generator) + ? this.generator + : [this.generator]; + + return generators + .map(({ name = "client", ...generator }) => + parseKeyValueBlock( + "generator", + name, + Object.entries(generator) as [string, string | string[]][] + ) + ) + .join("\n\n"); } /** diff --git a/lib/util/blocks.ts b/lib/util/blocks.ts index b3bcb02..f1e6b2e 100644 --- a/lib/util/blocks.ts +++ b/lib/util/blocks.ts @@ -8,7 +8,7 @@ export const parseKeyValueBlock = ( keyword: string, name: string, - entries: [string, string | { env: string }][] + entries: [string, string | string[] | { env: string }][] ) => { const tokenPadding = Math.max(...entries.map(([key]) => key.length)); const body = entries