UNPKG

@stryke/prisma-trpc-generator

Version:

A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.

1 lines 5.07 kB
{"version":3,"file":"aggregate-helpers.mjs","names":[],"sources":["../../src/zod/aggregate-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 type { AggregateOperationSupport } from \"../types\";\n\nconst isAggregateOutputType = (name: string) =>\n /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name);\n\nexport const isAggregateInputType = (name: string) =>\n name.endsWith(\"CountAggregateInput\") ||\n name.endsWith(\"SumAggregateInput\") ||\n name.endsWith(\"AvgAggregateInput\") ||\n name.endsWith(\"MinAggregateInput\") ||\n name.endsWith(\"MaxAggregateInput\");\n\nexport function addMissingInputObjectTypesForAggregate(\n inputObjectTypes: DMMF.InputType[],\n outputObjectTypes: DMMF.OutputType[]\n) {\n const aggregateOutputTypes = outputObjectTypes.filter(({ name }) =>\n isAggregateOutputType(name)\n );\n for (const aggregateOutputType of aggregateOutputTypes) {\n const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, \"\");\n inputObjectTypes.push({\n constraints: { maxNumFields: null, minNumFields: null },\n name: `${name}Input`,\n fields: aggregateOutputType.fields.map(field => ({\n name: field.name,\n isNullable: false,\n isRequired: false,\n inputTypes: [\n {\n isList: false,\n type: \"True\",\n location: \"scalar\"\n }\n ]\n }))\n });\n }\n}\n\nexport function resolveZodAggregateOperationSupport(\n inputObjectTypes: DMMF.InputType[]\n) {\n const aggregateOperationSupport: AggregateOperationSupport = {};\n for (const inputType of inputObjectTypes) {\n if (isAggregateInputType(inputType.name)) {\n const name = inputType.name.replace(\"AggregateInput\", \"\");\n if (name.endsWith(\"Count\")) {\n const model = name.replace(\"Count\", \"\");\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n count: true\n };\n } else if (name.endsWith(\"Min\")) {\n const model = name.replace(\"Min\", \"\");\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n min: true\n };\n } else if (name.endsWith(\"Max\")) {\n const model = name.replace(\"Max\", \"\");\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n max: true\n };\n } else if (name.endsWith(\"Sum\")) {\n const model = name.replace(\"Sum\", \"\");\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n sum: true\n };\n } else if (name.endsWith(\"Avg\")) {\n const model = name.replace(\"Avg\", \"\");\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n avg: true\n };\n }\n }\n }\n return aggregateOperationSupport;\n}\n"],"mappings":";AAqBA,MAAM,yBAAyB,SAC7B,gDAAgD,KAAK,KAAK;AAE5D,MAAa,wBAAwB,SACnC,KAAK,SAAS,sBAAsB,IACpC,KAAK,SAAS,oBAAoB,IAClC,KAAK,SAAS,oBAAoB,IAClC,KAAK,SAAS,oBAAoB,IAClC,KAAK,SAAS,oBAAoB;AAEpC,SAAgB,uCACd,kBACA,mBACA;CACA,MAAM,uBAAuB,kBAAkB,QAAQ,EAAE,WACvD,sBAAsB,KAAK,CAC5B;AACD,MAAK,MAAM,uBAAuB,sBAAsB;EACtD,MAAM,OAAO,oBAAoB,KAAK,QAAQ,0BAA0B,GAAG;AAC3E,mBAAiB,KAAK;GACpB,aAAa;IAAE,cAAc;IAAM,cAAc;IAAM;GACvD,MAAM,GAAG,KAAK;GACd,QAAQ,oBAAoB,OAAO,KAAI,WAAU;IAC/C,MAAM,MAAM;IACZ,YAAY;IACZ,YAAY;IACZ,Y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