| 1 | import type { SchemaOptions } from "./Schema.ts"; |
| 2 | |
| 3 | /** Optional outputs alongside Prisma's canonical contract artifacts. */ |
| 4 | export interface EffectGeneratorOptions extends SchemaOptions { |
| 5 | /** Emit the contract-bound Effect client factory. Defaults to true. */ |
| 6 | readonly client?: boolean; |
| 7 | /** Emit standalone Effect row schemas. Defaults to true. */ |
| 8 | readonly schemas?: boolean; |
| 9 | } |
| 10 | |
| 11 | export const effectGeneratorKey = Symbol.for("alchemy/Prisma/ORM/generator"); |
| 12 | |
| 13 | /** |
| 14 | * Attach Effect generation to the ORM section of a Prisma configuration. |
| 15 | * Run `alchemy prisma generate --config ./prisma.config.ts` to emit outputs. |
| 16 | * Native Prisma commands continue to work and do not run this generator. |
| 17 | * |
| 18 | * ```typescript |
| 19 | * export default definePrismaConfig({ |
| 20 | * orm: withEffect(ormConfig({ contract: "./contract.psl", output: "./generated" }), { |
| 21 | * client: true, |
| 22 | * schemas: true, |
| 23 | * }), |
| 24 | * }); |
| 25 | * ``` |
| 26 | */ |
| 27 | export function withEffect<C extends object>( |
| 28 | config: C, |
| 29 | options: EffectGeneratorOptions = {}, |
| 30 | ): C & { |
| 31 | readonly [effectGeneratorKey]: EffectGeneratorOptions; |
| 32 | } { |
| 33 | return { ...config, [effectGeneratorKey]: options }; |
| 34 | } |