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

Method toTS

packages/client-generator-ts/src/TSClient/Model.ts:502–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

500 }
501
502 public toTS(): string {
503 const { name } = this.outputType
504 const { dmmf } = this.context
505
506 const mapping = dmmf.mappingsMap[name] ?? { model: name, plural: `${name}s` }
507 const modelOrType = dmmf.typeAndModelMap[name]
508
509 const availableActions = getModelActions(dmmf, name)
510 const nonAggregateActions = this.getNonAggregateActions(availableActions)
511 const groupByArgsName = getGroupByArgsName(name)
512 const countArgsName = getModelArgName(name, DMMF.ModelAction.count)
513
514 const genericDelegateParams = [extArgsParam, ts.genericParameter('GlobalOmitOptions').default(ts.objectType())]
515
516 const excludedArgsForCount = ['select', 'include', 'distinct', 'omit']
517 if (this.context.isPreviewFeatureOn('relationJoins')) {
518 excludedArgsForCount.push('relationLoadStrategy')
519 }
520
521 const excludedArgsForCountType = excludedArgsForCount.map((name) => `'${name}'`).join(' | ')
522
523 return `\
524${
525 availableActions.includes(DMMF.ModelAction.aggregate)
526 ? `export type ${countArgsName}<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> =
527 Omit<${getModelArgName(name, DMMF.ModelAction.findMany)}, ${excludedArgsForCountType}> & {
528 select?: ${getCountAggregateInputName(name)} | true
529 }
530`
531 : ''
532}
533export interface ${name}Delegate<${genericDelegateParams.map((param) => ts.stringify(param)).join(', ')}> {
534${indent(`[K: symbol]: { types: Prisma.TypeMap<ExtArgs>['model']['${name}'], meta: { name: '${name}' } }`, TAB_SIZE)}
535${nonAggregateActions
536 .map((action) => {
537 const method = buildModelDelegateMethod(name, action, this.context)
538 return ts.stringify(method, { indentLevel: 1, newLine: 'trailing' })
539 })
540 .join('\n')}
541
542${
543 availableActions.includes(DMMF.ModelAction.aggregate)
544 ? `${indent(getMethodJSDoc(DMMF.ModelAction.count, mapping, modelOrType), TAB_SIZE)}
545 count<T extends ${countArgsName}>(
546 args?: Prisma.Subset<T, ${countArgsName}>,
547 ): Prisma.PrismaPromise<
548 T extends runtime.Types.Utils.Record<'select', any>
549 ? T['select'] extends true
550 ? number
551 : Prisma.GetScalarType<T['select'], ${getCountAggregateOutputName(name)}>
552 : number
553 >
554`
555 : ''
556}
557${
558 availableActions.includes(DMMF.ModelAction.aggregate)
559 ? `${indent(getMethodJSDoc(DMMF.ModelAction.aggregate, mapping, modelOrType), TAB_SIZE)}

Callers

nothing calls this directly

Calls 15

getModelActionsFunction · 0.90
getGroupByArgsNameFunction · 0.90
getModelArgNameFunction · 0.90
getMethodJSDocFunction · 0.90
getAggregateArgsNameFunction · 0.90
getAggregateGetNameFunction · 0.90
getGroupByPayloadNameFunction · 0.90
getFieldRefsTypeNameFunction · 0.90
includesMethod · 0.80

Tested by

no test coverage detected