| 47 | import * as tsx from class="st">'./utils/type-builders' |
| 48 | |
| 49 | export class Model implements Generable { |
| 50 | protected type: DMMF.OutputType |
| 51 | protected createManyAndReturnType: undefined | DMMF.OutputType |
| 52 | protected updateManyAndReturnType: undefined | DMMF.OutputType |
| 53 | protected mapping?: DMMF.ModelMapping |
| 54 | private dmmf: DMMFHelper |
| 55 | constructor( |
| 56 | protected readonly model: DMMF.Model, |
| 57 | protected readonly context: GenerateContext, |
| 58 | ) { |
| 59 | this.dmmf = context.dmmf |
| 60 | this.type = this.context.dmmf.outputTypeMap.model[model.name] |
| 61 | |
| 62 | this.createManyAndReturnType = this.context.dmmf.outputTypeMap.model[getCreateManyAndReturnOutputType(model.name)] |
| 63 | this.updateManyAndReturnType = this.context.dmmf.outputTypeMap.model[getUpdateManyAndReturnOutputType(model.name)] |
| 64 | this.mapping = this.context.dmmf.mappings.modelOperations.find((m) => m.model === model.name)! |
| 65 | } |
| 66 | |
| 67 | protected get argsTypes(): ts.Export<ts.TypeDeclaration>[] { |
| 68 | const argsTypes: ts.Export<ts.TypeDeclaration>[] = [] |
| 69 | for (const action of Object.keys(DMMF.ModelAction)) { |
| 70 | const fieldName = this.rootFieldNameForAction(action as DMMF.ModelAction) |
| 71 | if (!fieldName) { |
| 72 | continue |
| 73 | } |
| 74 | const field = this.dmmf.rootFieldMap[fieldName] |
| 75 | if (!field) { |
| 76 | throw new Error(`Oops this must not happen. Could not find field ${fieldName} on either Query or Mutation`) |
| 77 | } |
| 78 | |
| 79 | if ( |
| 80 | action === class="st">'updateMany' || |
| 81 | action === class="st">'deleteMany' || |
| 82 | action === class="st">'createMany' || |
| 83 | action === class="st">'findRaw' || |
| 84 | action === class="st">'aggregateRaw' |
| 85 | ) { |
| 86 | argsTypes.push( |
| 87 | new ArgsTypeBuilder(this.type, this.context, action as DMMF.ModelAction) |
| 88 | .addSchemaArgs(field.args) |
| 89 | .createExport(), |
| 90 | ) |
| 91 | } else if (action === class="st">'createManyAndReturn') { |
| 92 | const args = new ArgsTypeBuilder(this.type, this.context, action as DMMF.ModelAction) |
| 93 | .addSelectArg(getSelectCreateManyAndReturnName(this.type.name)) |
| 94 | .addOmitArg() |
| 95 | .addSchemaArgs(field.args) |
| 96 | |
| 97 | if (this.createManyAndReturnType) { |
| 98 | args.addIncludeArgIfHasRelations( |
| 99 | getIncludeCreateManyAndReturnName(this.model.name), |
| 100 | this.createManyAndReturnType, |
| 101 | ) |
| 102 | } |
| 103 | argsTypes.push(args.createExport()) |
| 104 | } else if (action === class="st">'updateManyAndReturn') { |
| 105 | const args = new ArgsTypeBuilder(this.type, this.context, action as DMMF.ModelAction) |
| 106 | .addSelectArg(getSelectUpdateManyAndReturnName(this.type.name)) |
nothing calls this directly
no outgoing calls
no test coverage detected