MCPcopy
hub / github.com/prisma/prisma / TSClient

Class TSClient

packages/client-generator-js/src/TSClient/TSClient.ts:42–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42export class TSClient implements Generable {
43 protected readonly dmmf: DMMFHelper
44 protected readonly genericsInfo: GenericArgsInfo
45
46 constructor(protected readonly options: TSClientOptions) {
47 this.dmmf = new DMMFHelper(options.dmmf)
48 this.genericsInfo = new GenericArgsInfo(this.dmmf)
49 }
50
51 private buildParamGraphConfig(): string {
52 const serialized = buildAndSerializeParamGraph(this.options.dmmf)
53 const stringsJson = JSON.stringify(JSON.stringify(serialized.strings))
54 return `config.parameterizationSchema = {
55 strings: JSON.parse(${stringsJson}),
56 graph: "${serialized.graph}"
57}`
58 }
59
60 public toJS(): string {
61 const { edge, wasm, generator, datamodel: inlineSchema, runtimeName, reusedJs, compilerBuild } = this.options
62
63 if (reusedJs) {
64 return `module.exports = { ...require('${reusedJs}') }`
65 }
66
67 const config: Omit<GetPrismaClientConfig, 'runtimeDataModel' | 'parameterizationSchema'> = {
68 previewFeatures: generator.previewFeatures,
69 clientVersion: this.options.clientVersion,
70 engineVersion: this.options.engineVersion,
71 activeProvider: this.options.activeProvider,
72 inlineSchema,
73 }
74
75 const code = `${commonCodeJS({ ...this.options, browser: false })}
76${buildRequirePath(edge)}
77
78/**
79 * Enums
80 */
81${this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toJS()).join('\n\n')}
82${this.dmmf.datamodel.enums
83 .map((datamodelEnum) => new Enum(datamodelEnumToSchemaEnum(datamodelEnum), false).toJS())
84 .join('\n\n')}
85
86${new Enum(
87 {
88 name: 'ModelName',
89 values: this.dmmf.mappings.modelOperations.map((m) => m.model),
90 },
91 true,
92).toJS()}
93/**
94 * Create the Client
95 */
96const config = ${JSON.stringify(config, null, 2)}
97${buildRuntimeDataModel(this.dmmf.datamodel, runtimeName)}
98${this.buildParamGraphConfig()}
99${buildQueryCompilerWasmModule(wasm, runtimeName, compilerBuild)}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected