(model: DMMF.Model, context: GenerateContext)
| 7 | import { buildModelOutputProperty } from './Output' |
| 8 | |
| 9 | export function buildModelPayload(model: DMMF.Model, context: GenerateContext) { |
| 10 | const isComposite = context.dmmf.isComposite(model.name) |
| 11 | |
| 12 | const objects = ts.objectType() |
| 13 | const scalars = ts.objectType() |
| 14 | const composites = ts.objectType() |
| 15 | |
| 16 | for (const field of model.fields) { |
| 17 | if (field.kind === 'object') { |
| 18 | if (context.dmmf.isComposite(field.type)) { |
| 19 | composites.add(buildModelOutputProperty(field, context.dmmf)) |
| 20 | } else { |
| 21 | objects.add(buildModelOutputProperty(field, context.dmmf)) |
| 22 | } |
| 23 | } else if (field.kind === 'enum' || field.kind === 'scalar') { |
| 24 | scalars.add(buildModelOutputProperty(field, context.dmmf)) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | const scalarsType = isComposite |
| 29 | ? scalars |
| 30 | : ts |
| 31 | .namedType('$Extensions.GetPayloadResult') |
| 32 | .addGenericArgument(scalars) |
| 33 | .addGenericArgument(ts.namedType('ExtArgs').subKey('result').subKey(uncapitalize(model.name))) |
| 34 | |
| 35 | const payloadTypeDeclaration = ts.typeDeclaration( |
| 36 | getPayloadName(model.name, false), |
| 37 | ts |
| 38 | .objectType() |
| 39 | .add(ts.property('name', ts.stringLiteral(model.name))) |
| 40 | .add(ts.property('objects', objects)) |
| 41 | .add(ts.property('scalars', scalarsType)) |
| 42 | .add(ts.property('composites', composites)), |
| 43 | ) |
| 44 | |
| 45 | if (!isComposite) { |
| 46 | payloadTypeDeclaration.addGenericParameter(extArgsParam) |
| 47 | } |
| 48 | |
| 49 | return ts.moduleExport(payloadTypeDeclaration) |
| 50 | } |
no test coverage detected