@stryke/prisma-trpc-generator
Version:
A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.
1 lines • 3.85 kB
Source Map (JSON)
{"version":3,"file":"modelArgs-helpers.mjs","names":[],"sources":["../../src/zod/modelArgs-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { DMMF } from \"@prisma/generator-helper\";\nimport { checkModelHasModelRelation } from \"./model-helpers\";\n\nexport function addMissingInputObjectTypesForModelArgs(\n inputObjectTypes: DMMF.InputType[],\n models: DMMF.Model[],\n isGenerateSelect: boolean,\n isGenerateInclude: boolean\n) {\n const modelArgsInputObjectTypes = generateModelArgsInputObjectTypes(\n models,\n isGenerateSelect,\n isGenerateInclude\n );\n\n for (const modelArgsInputObjectType of modelArgsInputObjectTypes) {\n inputObjectTypes.push(modelArgsInputObjectType);\n }\n}\nfunction generateModelArgsInputObjectTypes(\n models: DMMF.Model[],\n isGenerateSelect: boolean,\n isGenerateInclude: boolean\n) {\n const modelArgsInputObjectTypes: DMMF.InputType[] = [];\n for (const model of models) {\n const { name: modelName } = model;\n const fields: DMMF.SchemaArg[] = [];\n\n if (isGenerateSelect) {\n const selectField: DMMF.SchemaArg = {\n name: \"select\",\n isRequired: false,\n isNullable: false,\n inputTypes: [\n {\n isList: false,\n type: `${modelName}Select`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n }\n ]\n };\n fields.push(selectField);\n }\n\n const hasRelationToAnotherModel = checkModelHasModelRelation(model);\n\n if (isGenerateInclude && hasRelationToAnotherModel) {\n const includeField: DMMF.SchemaArg = {\n name: \"include\",\n isRequired: false,\n isNullable: false,\n inputTypes: [\n {\n isList: false,\n type: `${modelName}Include`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n }\n ]\n };\n fields.push(includeField);\n }\n\n const modelArgsInputObjectType: DMMF.InputType = {\n name: `${modelName}DefaultArgs`,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields\n };\n modelArgsInputObjectTypes.push(modelArgsInputObjectType);\n }\n\n return modelArgsInputObjectTypes;\n}\n"],"mappings":";;;AAqBA,SAAgB,uCACd,kBACA,QACA,kBACA,mBACA;CACA,MAAM,4BAA4B,kCAChC,QACA,kBACA,kBACD;AAED,MAAK,MAAM,4BAA4B,0BACrC,kBAAiB,KAAK,yBAAyB;;AAGnD,SAAS,kCACP,QACA,kBACA,mBACA;CACA,MAAM,4BAA8C,EAAE;AACtD,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,EAAE,MAAM,cAAc;EAC5B,MAAM,SAA2B,EAAE;AAEnC,MAAI,kBAAkB;GACpB,MAAM,cAA8B;IAClC,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,YAAY,CACV;KACE,QAAQ;KACR,MAAM,GAAG,UAAU;KACnB,UAAU;KACV,WAAW;KACZ,CACF;IACF;AACD,UAAO,KAAK,YAAY;;EAG1B,MAAM,4BAA4B,2BAA2B,MAAM;AAEnE,MAAI,qBAAqB,2BAA2B;GAClD,MAAM,eAA+B;IACnC,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,YAAY,CACV;KACE,QAAQ;KACR,MAAM,GAAG,UAAU;KACnB,UAAU;KACV,WAAW;KACZ,CACF;IACF;AACD,UAAO,KAAK,aAAa;;EAG3B,MAAM,2BAA2C;GAC/C,MAAM,GAAG,UAAU;GACnB,aAAa;IACX,cAAc;IACd,cAAc;IACf;GACD;GACD;AACD,4BAA0B,KAAK,yBAAyB;;AAG1D,QAAO"}