MCPcopy
hub / github.com/prisma/prisma / toTS

Method toTS

packages/client-generator-js/src/TSClient/TSClient.ts:108–276  ·  packages/client-generator-js/src/TSClient/TSClient.ts::TSClient.toTS
()

Source from the content-addressed store, hash-verified

106 }
107
108 public toTS(): string {
109 const { reusedTs } = this.options
110
111 class="cm">// in some cases, we just re-export the existing types
112 if (reusedTs) {
113 const topExports = ts.moduleExportFrom(`./${reusedTs}`)
114
115 return ts.stringify(topExports)
116 }
117
118 const context = new GenerateContext({
119 dmmf: this.dmmf,
120 genericArgsInfo: this.genericsInfo,
121 generator: this.options.generator,
122 provider: this.options.activeProvider,
123 })
124
125 const prismaClientClass = new PrismaClientClass(
126 context,
127 this.options.datasources,
128 this.options.outputDir,
129 this.options.runtimeName,
130 this.options.browser,
131 )
132
133 const commonCode = commonCodeTS(this.options)
134 const modelAndTypes = Object.values(this.dmmf.typeAndModelMap).reduce((acc, modelOrType) => {
135 if (this.dmmf.outputTypeMap.model[modelOrType.name]) {
136 acc.push(new Model(modelOrType, context))
137 }
138 return acc
139 }, [] as Model[])
140
141 class="cm">// TODO: Make this code more efficient and directly return 2 arrays
142
143 const prismaEnums = this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toTS())
144
145 const modelEnums: string[] = []
146 const modelEnumsAliases: string[] = []
147 for (const datamodelEnum of this.dmmf.datamodel.enums) {
148 modelEnums.push(new Enum(datamodelEnumToSchemaEnum(datamodelEnum), false).toTS())
149 modelEnumsAliases.push(
150 ts.stringify(
151 ts.moduleExport(ts.typeDeclaration(datamodelEnum.name, ts.namedType(`$Enums.${datamodelEnum.name}`))),
152 ),
153 ts.stringify(
154 ts.moduleExport(ts.constDeclaration(datamodelEnum.name, ts.namedType(`typeof $Enums.${datamodelEnum.name}`))),
155 ),
156 )
157 }
158
159 const fieldRefs = this.dmmf.schema.fieldRefTypes.prisma?.map((type) => new FieldRefInput(type).toTS()) ?? []
160
161 const countTypes: Count[] = this.dmmf.schema.outputObjectTypes.prisma
162 ?.filter((t) => t.name.endsWith(class="st">'CountOutputType'))
163 .map((t) => new Count(t, context))
164
165 const code = `

Callers

nothing calls this directly

Calls 11

toTSWithoutNamespaceMethod · 0.95
toTSMethod · 0.95
commonCodeTSFunction · 0.90
valuesMethod · 0.80
includesMethod · 0.80
overrideNameMethod · 0.80
toTSMethod · 0.65
toTSWithoutNamespaceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected