@stryke/prisma-trpc-generator 0.13.102 → 0.13.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/config.mjs.map +1 -1
- package/dist/env/src/get-env-paths.mjs.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/prisma-generator.mjs.map +1 -1
- package/dist/project.mjs.map +1 -1
- package/dist/string-format/src/acronyms.mjs.map +1 -1
- package/dist/string-format/src/articles.mjs.map +1 -1
- package/dist/string-format/src/combine.mjs.map +1 -1
- package/dist/string-format/src/conjunctions.mjs.map +1 -1
- package/dist/string-format/src/decamelize.mjs.map +1 -1
- package/dist/string-format/src/format-special-cases.mjs.map +1 -1
- package/dist/string-format/src/lower-case-first.mjs.map +1 -1
- package/dist/string-format/src/prepositions.mjs.map +1 -1
- package/dist/string-format/src/special-cases.mjs.map +1 -1
- package/dist/string-format/src/title-case.mjs.map +1 -1
- package/dist/string-format/src/upper-case-first.mjs.map +1 -1
- package/dist/utils/format-file.mjs.map +1 -1
- package/dist/utils/get-jiti.mjs.map +1 -1
- package/dist/utils/get-prisma-internals.mjs.map +1 -1
- package/dist/utils/write-file-safely.mjs.map +1 -1
- package/dist/zod/aggregate-helpers.mjs.map +1 -1
- package/dist/zod/comments-helpers.mjs.map +1 -1
- package/dist/zod/docs-helpers.mjs.map +1 -1
- package/dist/zod/generator-helpers.mjs.map +1 -1
- package/dist/zod/helpers.mjs.map +1 -1
- package/dist/zod/include-helpers.mjs.map +1 -1
- package/dist/zod/model-helpers.mjs.map +1 -1
- package/dist/zod/modelArgs-helpers.mjs.map +1 -1
- package/dist/zod/mongodb-helpers.mjs.map +1 -1
- package/dist/zod/select-helpers.mjs.map +1 -1
- package/dist/zod/transformer.mjs.map +1 -1
- package/dist/zod/whereUniqueInput-helpers.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepositions.mjs","names":[],"sources":["../../../../string-format/src/prepositions.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"prepositions.mjs","names":[],"sources":["../../../../string-format/src/prepositions.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\nexport const PREPOSITIONS = [\n \"about\",\n \"above\",\n \"across\",\n \"after\",\n \"against\",\n \"along\",\n \"among\",\n \"around\",\n \"at\",\n \"because of\",\n \"before\",\n \"behind\",\n \"below\",\n \"beneath\",\n \"beside\",\n \"besides\",\n \"between\",\n \"beyond\",\n \"but\",\n \"by\",\n \"concerning\",\n \"despite\",\n \"down\",\n \"during\",\n \"except\",\n \"excepting\",\n \"for\",\n \"from\",\n \"in\",\n \"in front of\",\n \"inside\",\n \"in spite of\",\n \"instead of\",\n \"into\",\n \"like\",\n \"near\",\n \"of\",\n \"off\",\n \"on\",\n \"onto\",\n \"out\",\n \"outside\",\n \"over\",\n \"past\",\n \"regarding\",\n \"since\",\n \"through\",\n \"throughout\",\n \"to\",\n \"toward\",\n \"under\",\n \"underneath\",\n \"until\",\n \"up\",\n \"upon\",\n \"up to\",\n \"with\",\n \"within\",\n \"without\",\n \"with regard to\",\n \"with respect to\"\n];\n"],"mappings":";AAkBA,MAAa,eAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"special-cases.mjs","names":[],"sources":["../../../../string-format/src/special-cases.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"special-cases.mjs","names":[],"sources":["../../../../string-format/src/special-cases.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\nexport const SPECIAL_CASES = [\n \"2FA\",\n \"4K\",\n \"5K\",\n \"8K\",\n \"AGI\",\n \"BI\",\n \"ChatGPT\",\n \"CTA\",\n \"DateTime\",\n \"FMS\",\n \"GitHub\",\n \"GPT\",\n \"HD\",\n \"IBMid\",\n \"IDs\",\n \"iMac\",\n \"IMAX\",\n \"iOS\",\n \"iPad\",\n \"iPhone\",\n \"iPod\",\n \"LDAP\",\n \"LinkedIn\",\n \"LLM\",\n \"macOS\",\n \"McDonalds\",\n \"MCP\",\n \"ML\",\n \"MySQL\",\n \"NLG\",\n \"NLP\",\n \"NLU\",\n \"OpenAI\",\n \"PDFs\",\n \"PIM\",\n \"PEFT\",\n \"pH\",\n \"PostgreSQL\",\n \"SEO\",\n \"TTS\",\n \"UHD\",\n \"UUID\",\n \"XSS\",\n \"YouTube\",\n \"CSpell\",\n \"ESLint\"\n];\n"],"mappings":";AAkBA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title-case.mjs","names":[],"sources":["../../../../string-format/src/title-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"title-case.mjs","names":[],"sources":["../../../../string-format/src/title-case.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 { ACRONYMS } from \"./acronyms\";\nimport { combine } from \"./combine\";\nimport { decamelize } from \"./decamelize\";\nimport type { FormatSpecialCasesOptions } from \"./format-special-cases\";\nimport { formatSpecialCases } from \"./format-special-cases\";\nimport { upperCaseFirst } from \"./upper-case-first\";\n\nexport interface TitleCaseOptions extends FormatSpecialCasesOptions {\n /**\n * Whether to expand acronyms in the input string.\n *\n * @remarks\n * If true, acronyms will be expanded to their full form before being converted to title case. For example, \"NASA\" would be expanded to \"National Aeronautics and Space Administration\".\n *\n * @defaultValue false\n */\n expandAcronyms?: boolean;\n}\n\n/**\n * Convert a string to title case.\n *\n * @param input - The input string to convert.\n * @param options - Options for formatting special cases.\n * @returns The title cased string.\n */\nexport function titleCase<T extends string | undefined>(\n input: T,\n options?: TitleCaseOptions\n): T {\n return input\n ?.replaceAll(\":\", \" - \")\n ?.replaceAll(\"+\", \" + \")\n ?.replaceAll(\"/\", \" / \")\n ?.split(/\\s+-\\s+/)\n .map(segment =>\n decamelize(segment)\n .split(/[\\s\\-_]/)\n .map(upperCaseFirst)\n .map(value =>\n options?.expandAcronyms\n ? ACRONYMS[value]?.description || value\n : value\n )\n .map((value: string, index: number, array: string[]) =>\n formatSpecialCases(value, index, array, options)\n )\n .reduce(combine)\n )\n .join(\" - \") as T;\n}\n"],"mappings":";;;;;;;;;;;;;;AA4CA,SAAgB,UACd,OACA,SACG;AACH,QAAO,OACH,WAAW,KAAK,MAAM,EACtB,WAAW,KAAK,MAAM,EACtB,WAAW,KAAK,MAAM,EACtB,MAAM,UAAU,CACjB,KAAI,YACH,WAAW,QAAQ,CAChB,MAAM,UAAU,CAChB,IAAI,eAAe,CACnB,KAAI,UACH,SAAS,iBACL,SAAS,QAAQ,eAAe,QAChC,MACL,CACA,KAAK,OAAe,OAAe,UAClC,mBAAmB,OAAO,OAAO,OAAO,QAAQ,CACjD,CACA,OAAO,QAAQ,CACnB,CACA,KAAK,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upper-case-first.mjs","names":[],"sources":["../../../../string-format/src/upper-case-first.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"upper-case-first.mjs","names":[],"sources":["../../../../string-format/src/upper-case-first.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\n/**\n * Upper case the first character of an input string.\n *\n * @remarks\n * \"Thisisanexample\"\n *\n * @param input - The input string.\n * @returns The capitalized string.\n */\nexport function upperCaseFirst<T extends string | undefined>(input?: T): T {\n return (input ? input.charAt(0).toUpperCase() + input.slice(1) : input) as T;\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,eAA6C,OAAc;AACzE,QAAQ,QAAQ,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-file.mjs","names":[],"sources":["../../src/utils/format-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"format-file.mjs","names":[],"sources":["../../src/utils/format-file.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 prettier from \"prettier\";\n\nexport async function formatFile(content: string): Promise<string> {\n const options = await prettier.resolveConfig(process.cwd());\n\n let formatOptions = options;\n if (!options) {\n formatOptions = {\n trailingComma: \"all\",\n tabWidth: 2,\n printWidth: 80,\n bracketSpacing: true,\n semi: true,\n singleQuote: true,\n useTabs: false\n };\n }\n\n const formatted = await prettier.format(content, {\n ...formatOptions,\n parser: \"typescript\"\n });\n\n return formatted;\n}\n"],"mappings":";;;AAoBA,eAAsB,WAAW,SAAkC;CACjE,MAAM,UAAU,MAAM,SAAS,cAAc,QAAQ,KAAK,CAAC;CAE3D,IAAI,gBAAgB;AACpB,KAAI,CAAC,QACH,iBAAgB;EACd,eAAe;EACf,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,MAAM;EACN,aAAa;EACb,SAAS;EACV;AAQH,QAAO,MALiB,SAAS,OAAO,SAAS;EAC/C,GAAG;EACH,QAAQ;EACT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-jiti.mjs","names":[],"sources":["../../src/utils/get-jiti.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"get-jiti.mjs","names":[],"sources":["../../src/utils/get-jiti.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 { getEnvPaths } from \"@stryke/env/get-env-paths\";\nimport { getWorkspaceRoot } from \"@stryke/fs/get-workspace-root\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { Jiti } from \"jiti\";\nimport { createJiti } from \"jiti\";\n\nlet jiti!: Jiti;\n\nexport function getJiti() {\n if (!jiti) {\n const envPaths = getEnvPaths();\n\n jiti = createJiti(getWorkspaceRoot(), {\n fsCache: joinPaths(envPaths.cache, \"jiti\"),\n interopDefault: true\n });\n }\n\n return jiti;\n}\n"],"mappings":";;;;;;AAwBA,IAAI;AAEJ,SAAgB,UAAU;AACxB,KAAI,CAAC,MAAM;EACT,MAAM,WAAW,aAAa;AAE9B,SAAO,WAAW,kBAAkB,EAAE;GACpC,SAAS,UAAU,SAAS,OAAO,OAAO;GAC1C,gBAAgB;GACjB,CAAC;;AAGJ,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-prisma-internals.mjs","names":[],"sources":["../../src/utils/get-prisma-internals.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"get-prisma-internals.mjs","names":[],"sources":["../../src/utils/get-prisma-internals.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, EnvValue } from \"@prisma/generator-helper\";\nimport type { Handler } from \"@prisma/generator-helper/dist/generatorHandler\";\nimport type { GetDMMFOptions } from \"@prisma/internals\";\nimport { getJiti } from \"./get-jiti\";\n\nexport async function getPrismaInternals() {\n return getJiti().import<{\n parseEnvValue: (p: EnvValue) => string;\n getDMMF: (options: GetDMMFOptions) => Promise<DMMF.Document>;\n }>(getJiti().esmResolve(\"@prisma/internals\"));\n}\n\nexport async function getPrismaGeneratorHelper() {\n return getJiti().import<{\n generatorHandler: (handler: Handler) => void;\n }>(getJiti().esmResolve(\"@prisma/generator-helper\"));\n}\n"],"mappings":";;;AAuBA,eAAsB,qBAAqB;AACzC,QAAO,SAAS,CAAC,OAGd,SAAS,CAAC,WAAW,oBAAoB,CAAC;;AAG/C,eAAsB,2BAA2B;AAC/C,QAAO,SAAS,CAAC,OAEd,SAAS,CAAC,WAAW,2BAA2B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-file-safely.mjs","names":[],"sources":["../../src/utils/write-file-safely.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"write-file-safely.mjs","names":[],"sources":["../../src/utils/write-file-safely.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 { createDirectory } from \"@stryke/fs/helpers\";\nimport { writeFile } from \"@stryke/fs/write-file\";\nimport { correctPath } from \"@stryke/path/correct-path\";\nimport { findFilePath } from \"@stryke/path/file-path-fns\";\nimport path from \"node:path\";\nimport { formatFile } from \"./format-file\";\n\nconst indexExports = new Set<string>();\n\nexport const addIndexExport = (filePath: string) => {\n indexExports.add(filePath);\n};\n\nexport const writeFileSafely = async (\n writeLocation: string,\n content: any,\n addToIndex = true\n) => {\n const [fileContent] = await Promise.all([\n formatFile(content),\n createDirectory(findFilePath(writeLocation))\n ]);\n\n await writeFile(writeLocation, fileContent);\n if (addToIndex) {\n addIndexExport(writeLocation);\n }\n};\n\nexport const writeIndexFile = async (indexPath: string) => {\n const rows = Array.from(indexExports).map(filePath => {\n let relativePath = path.relative(path.dirname(indexPath), filePath);\n if (relativePath.endsWith(\".ts\")) {\n relativePath = relativePath.slice(0, relativePath.lastIndexOf(\".ts\"));\n }\n const normalized = correctPath(relativePath);\n\n return `export * from './${normalized}';`;\n });\n\n rows.push(\"export * from './models';\");\n\n await writeFileSafely(indexPath, rows.join(\"\\n\"), false);\n};\n"],"mappings":";;;;;;;;AAyBA,MAAM,+BAAe,IAAI,KAAa;AAEtC,MAAa,kBAAkB,aAAqB;AAClD,cAAa,IAAI,SAAS;;AAG5B,MAAa,kBAAkB,OAC7B,eACA,SACA,aAAa,SACV;CACH,MAAM,CAAC,eAAe,MAAM,QAAQ,IAAI,CACtC,WAAW,QAAQ,EACnB,gBAAgB,aAAa,cAAc,CAAC,CAC7C,CAAC;AAEF,OAAM,UAAU,eAAe,YAAY;AAC3C,KAAI,WACF,gBAAe,cAAc;;AAIjC,MAAa,iBAAiB,OAAO,cAAsB;CACzD,MAAM,OAAO,MAAM,KAAK,aAAa,CAAC,KAAI,aAAY;EACpD,IAAI,eAAe,KAAK,SAAS,KAAK,QAAQ,UAAU,EAAE,SAAS;AACnE,MAAI,aAAa,SAAS,MAAM,CAC9B,gBAAe,aAAa,MAAM,GAAG,aAAa,YAAY,MAAM,CAAC;AAIvE,SAAO,oBAFY,YAAY,aAEM,CAAC;GACtC;AAEF,MAAK,KAAK,4BAA4B;AAEtC,OAAM,gBAAgB,WAAW,KAAK,KAAK,KAAK,EAAE,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-helpers.mjs","names":[],"sources":["../../src/zod/aggregate-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"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":";AA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AK,SAAS,MAAM,EAAE;GAC/B,MAAM,QAAQ,KAAK,QAAQ,OAAO,GAAG;AACrC,6BAA0B,SAAS;IACjC,GAAG,0BAA0B;IAC7B,KAAK;IACN;aACQ,KAAK,SAAS,MAAM,EAAE;GAC/B,MAAM,QAAQ,KAAK,QAAQ,OAAO,GAAG;AACrC,6BAA0B,SAAS;IACjC,GAAG,0BAA0B;IAC7B,KAAK;IACN;;;AAIP,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments-helpers.mjs","names":[],"sources":["../../src/zod/comments-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"comments-helpers.mjs","names":[],"sources":["../../src/zod/comments-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\";\n\n// eslint-disable-next-line regexp/no-obscure-range\nconst modelAttributeRegex = /(?:@@Gen\\.)+[A-z]+\\(.+\\)/;\nconst attributeNameRegex = /\\.+[A-Z]+\\(+/i;\nconst attributeArgsRegex = /\\(+[A-Z]+:.+\\)/i;\n\nexport function resolveZodModelsComments(\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[],\n enumTypes: { model?: DMMF.SchemaEnum[]; prisma: DMMF.SchemaEnum[] },\n hiddenModels: string[],\n hiddenFields: string[]\n) {\n models = collectHiddenModels(models, hiddenModels);\n collectHiddenFields(models, hiddenModels, hiddenFields);\n hideModelOperations(models, modelOperations);\n hideEnums(enumTypes, hiddenModels);\n}\n\nfunction collectHiddenModels(models: DMMF.Model[], hiddenModels: string[]) {\n return models\n .map(model => {\n if (model.documentation) {\n const attribute = model.documentation?.match(modelAttributeRegex)?.[0];\n const attributeName = attribute\n ?.match(attributeNameRegex)?.[0]\n ?.slice(1, -1);\n if (attributeName !== \"model\") {\n return model;\n }\n\n const rawAttributeArgs = attribute\n ?.match(attributeArgsRegex)?.[0]\n ?.slice(1, -1);\n\n const parsedAttributeArgs: Record<string, unknown> = {};\n if (rawAttributeArgs) {\n const rawAttributeArgsParts = rawAttributeArgs\n .split(\":\")\n .map(it => it.trim())\n .map(part => (part.startsWith(\"[\") ? part : part.split(\",\")))\n .flat()\n .map(it => it.trim());\n\n for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {\n const key = rawAttributeArgsParts[i];\n const value = rawAttributeArgsParts[i + 1];\n parsedAttributeArgs[key!] = JSON.parse(value!);\n }\n }\n if (parsedAttributeArgs.hide) {\n hiddenModels.push(model.name);\n return null as unknown as DMMF.Model;\n }\n }\n\n return model;\n })\n .filter(Boolean);\n}\n\nfunction collectHiddenFields(\n models: DMMF.Model[],\n hiddenModels: string[],\n hiddenFields: string[]\n) {\n models.forEach(model => {\n model.fields.forEach(field => {\n if (hiddenModels.includes(field.type)) {\n hiddenFields.push(field.name);\n if (field.relationFromFields) {\n field.relationFromFields.forEach(item => hiddenFields.push(item));\n }\n }\n });\n });\n}\nfunction hideEnums(\n enumTypes: { model?: DMMF.SchemaEnum[]; prisma: DMMF.SchemaEnum[] },\n hiddenModels: string[]\n) {\n enumTypes.prisma = enumTypes.prisma.filter(\n item => !hiddenModels.find(model => item.name.startsWith(model))\n );\n}\n\nfunction hideModelOperations(\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[]\n) {\n let i = modelOperations.length;\n while (i >= 0) {\n --i;\n const modelOperation = modelOperations[i];\n if (\n modelOperation &&\n !models.find(model => {\n return model.name === modelOperation.model;\n })\n ) {\n modelOperations.splice(i, 1);\n }\n }\n}\n\nexport function hideZodInputObjectTypesAndRelatedFields(\n inputObjectTypes: DMMF.InputType[],\n hiddenModels: string[],\n hiddenFields: string[]\n) {\n let j = inputObjectTypes.length;\n while (j >= 0) {\n --j;\n const inputType = inputObjectTypes[j];\n if (\n inputType &&\n (hiddenModels.includes(inputType?.meta?.source as string) ||\n hiddenModels.find(model => inputType.name.startsWith(model)))\n ) {\n inputObjectTypes.splice(j, 1);\n } else {\n let k = inputType?.fields?.length ?? 0;\n while (k >= 0) {\n --k;\n const field = inputType?.fields?.[k];\n if (field && hiddenFields.includes(field.name)) {\n inputObjectTypes[j]!.fields.slice(k, 1);\n }\n }\n }\n }\n}\n"],"mappings":";AAqBA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAE3B,SAAgB,yBACd,QACA,iBACA,WACA,cACA,cACA;AACA,UAAS,oBAAoB,QAAQ,aAAa;AAClD,qBAAoB,QAAQ,cAAc,aAAa;AACvD,qBAAoB,QAAQ,gBAAgB;AAC5C,WAAU,WAAW,aAAa;;AAGpC,SAAS,oBAAoB,QAAsB,cAAwB;AACzE,QAAO,OACJ,KAAI,UAAS;AACZ,MAAI,MAAM,eAAe;GACvB,MAAM,YAAY,MAAM,eAAe,MAAM,oBAAoB,GAAG;AAIpE,OAHsB,WAClB,MAAM,mBAAmB,GAAG,IAC5B,MAAM,GAAG,GAAG,KACM,QACpB,QAAO;GAGT,MAAM,mBAAmB,WACrB,MAAM,mBAAmB,GAAG,IAC5B,MAAM,GAAG,GAAG;GAEhB,MAAM,sBAA+C,EAAE;AACvD,OAAI,kBAAkB;IACpB,MAAM,wBAAwB,iBAC3B,MAAM,IAAI,CACV,KAAI,OAAM,GAAG,MAAM,CAAC,CACpB,KAAI,SAAS,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK,MAAM,IAAI,CAAE,CAC5D,MAAM,CACN,KAAI,OAAM,GAAG,MAAM,CAAC;AAEvB,SAAK,IAAI,IAAI,GAAG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C,QAAI,SAAS,aAAa,SAAS,MAAM,KAAK,CAC5C,kBAAiB,GAAI,OAAO,MAAM,GAAG,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs-helpers.mjs","names":[],"sources":["../../src/zod/docs-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"docs-helpers.mjs","names":[],"sources":["../../src/zod/docs-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 { ArrayTree } from \"parenthesis\";\nimport parenthesis from \"parenthesis\";\nimport { chunk } from \"./model-helpers\";\n\nexport const getJSDocs = (docString?: string) => {\n const lines: string[] = [];\n\n if (docString) {\n const docLines = docString\n .split(\"\\n\")\n .filter(dL => !dL.trimStart().startsWith(\"@zod\"));\n\n if (docLines.length) {\n lines.push(\"/**\");\n docLines.forEach(dL => lines.push(` * ${dL}`));\n lines.push(\" */\");\n }\n }\n\n return lines;\n};\n\nexport const getZodDocElements = (docString: string) =>\n docString\n .split(\"\\n\")\n .filter(line => line.trimStart().startsWith(\"@zod\"))\n .map(line => line.trimStart().slice(4))\n .flatMap(line =>\n // Array.from(line.matchAll(/\\.([^().]+\\(.*?\\))/g), (m) => m.slice(1)).flat()\n chunk(parenthesis.parse(line), 2)\n .slice(0, -1)\n .map(\n ([each, contents]) =>\n `${(each as string).replace(\n /\\)?\\./,\n \"\"\n )}${parenthesis.stringify(contents as ArrayTree)})`\n )\n );\n"],"mappings":";;;;AAsBA,MAAa,aAAa,cAAuB;CAC/C,MAAM,QAAkB,EAAE;AAE1B,KAAI,WAAW;EACb,MAAM,WAAW,UACd,MAAM,KAAK,CACX,QAAO,OAAM,CAAC,GAAG,WAAW,CAAC,WAAW,OAAO,CAAC;AAEnD,MAAI,SAAS,QAAQ;AACnB,SAAM,KAAK,MAAM;AACjB,YAAS,SAAQ,OAAM,MAAM,KAAK,MAAM,KAAK,CAAC;AAC9C,SAAM,KAAK,MAAM;;;AAIrB,QAAO;;AAGT,MAAa,qBAAqB,cAChC,UACG,MAAM,KAAK,CACX,QAAO,SAAQ,KAAK,WAAW,CAAC,WAAW,OAAO,CAAC,CACnD,KAAI,SAAQ,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC,CACtC,SAAQ,SAEP,MAAM,YAAY,MAAM,KAAK,EAAE,EAAE,CAC9B,MAAM,GAAG,GAAG,CACZ,KACE,CAAC,MAAM,cACN,GAAI,KAAgB,QAClB,SACA,GACD,GAAG,YAAY,UAAU,SAAsB,CAAC,GACpD,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator-helpers.mjs","names":[],"sources":["../../src/zod/generator-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"generator-helpers.mjs","names":[],"sources":["../../src/zod/generator-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, Writeable } from \"../types\";\nimport Transformer from \"./transformer\";\n\nexport async function generateZodEnumSchemas(\n prismaSchemaEnum: Writeable<DMMF.SchemaEnum[]>,\n modelSchemaEnum: Writeable<DMMF.SchemaEnum[]>\n) {\n const enumTypes = [...prismaSchemaEnum, ...modelSchemaEnum];\n const enumNames = enumTypes.map(enumItem => enumItem.name);\n Transformer.enumNames = enumNames ?? [];\n const transformer = new Transformer({\n enumTypes\n });\n await transformer.generateEnumSchemas();\n}\n\nexport async function generateZodObjectSchemas(\n inputObjectTypes: Writeable<DMMF.InputType[]>\n) {\n for (let i = 0; i < inputObjectTypes.length; i += 1) {\n const fields = inputObjectTypes[i]?.fields;\n const name = inputObjectTypes[i]?.name;\n const transformer = new Transformer({ name, fields });\n await transformer.generateObjectSchema();\n }\n}\n\nexport async function generateZodModelSchemas(\n models: Writeable<DMMF.Model[]>,\n modelOperations: Writeable<DMMF.ModelMapping[]>,\n aggregateOperationSupport: AggregateOperationSupport\n) {\n const transformer = new Transformer({\n models,\n modelOperations,\n aggregateOperationSupport\n });\n await transformer.generateModelSchemas();\n}\n\nexport async function generateZodIndex() {\n await Transformer.generateIndex();\n}\n"],"mappings":";;;AAsBA,eAAsB,uBACpB,kBACA,iBACA;CACA,MAAM,YAAY,CAAC,GAAG,kBAAkB,GAAG,gBAAgB;AAE3D,aAAY,YADM,UAAU,KAAI,aAAY,SAAS,KACpB,IAAI,EAAE;AAIvC,OAAM,IAHkB,YAAY,EAClC,WACD,CACgB,CAAC,qBAAqB;;AAGzC,eAAsB,yBACpB,kBACA;AACA,MAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK,GAAG;EACnD,MAAM,SAAS,iBAAiB,IAAI;EACpC,MAAM,OAAO,iBAAiB,IAAI;AAElC,QAAM,IADkB,YAAY;GAAE;GAAM;GAAQ,CACnC,CAAC,sBAAsB;;;AAI5C,eAAsB,wBACpB,QACA,iBACA,2BACA;AAMA,OAAM,IALkB,YAAY;EAClC;EACA;EACA;EACD,CACgB,CAAC,sBAAsB;;AAG1C,eAAsB,mBAAmB;AACvC,OAAM,YAAY,eAAe"}
|
package/dist/zod/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/zod/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/zod/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 { ConnectorType, DMMF } from \"@prisma/generator-helper\";\nimport type { Writeable } from \"../types\";\nimport { addMissingInputObjectTypesForAggregate } from \"./aggregate-helpers\";\nimport { addMissingInputObjectTypesForInclude } from \"./include-helpers\";\nimport { addMissingInputObjectTypesForModelArgs } from \"./modelArgs-helpers\";\nimport { addMissingInputObjectTypesForMongoDbRawOpsAndQueries } from \"./mongodb-helpers\";\nimport { addMissingInputObjectTypesForSelect } from \"./select-helpers\";\nimport Transformer from \"./transformer\";\nimport { changeOptionalToRequiredFields } from \"./whereUniqueInput-helpers\";\n\ninterface AddMissingInputObjectTypeOptions {\n isGenerateSelect: boolean;\n isGenerateInclude: boolean;\n}\n\nexport function addMissingZodInputObjectTypes(\n inputObjectTypes: DMMF.InputType[],\n outputObjectTypes: DMMF.OutputType[],\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[],\n dataSourceProvider: ConnectorType,\n options: AddMissingInputObjectTypeOptions\n) {\n // TODO: remove once Prisma fix this issue: https://github.com/prisma/prisma/issues/14900\n if (dataSourceProvider === \"mongodb\") {\n addMissingInputObjectTypesForMongoDbRawOpsAndQueries(\n modelOperations,\n outputObjectTypes,\n inputObjectTypes\n );\n }\n addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes);\n if (options.isGenerateSelect) {\n addMissingInputObjectTypesForSelect(\n inputObjectTypes,\n outputObjectTypes,\n models\n );\n Transformer.setIsGenerateSelect(true);\n }\n if (options.isGenerateSelect || options.isGenerateInclude) {\n addMissingInputObjectTypesForModelArgs(\n inputObjectTypes,\n models,\n options.isGenerateSelect,\n options.isGenerateInclude\n );\n }\n if (options.isGenerateInclude) {\n addMissingInputObjectTypesForInclude(\n inputObjectTypes,\n models,\n options.isGenerateSelect\n );\n Transformer.setIsGenerateInclude(true);\n }\n\n changeOptionalToRequiredFields(\n inputObjectTypes as Writeable<DMMF.InputType[]>\n );\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAgB,8BACd,kBACA,mBACA,QACA,iBACA,oBACA,SACA;AAEA,KAAI,uBAAuB,UACzB,sDACE,iBACA,mBACA,iBACD;AAEH,wCAAuC,kBAAkB,kBAAkB;AAC3E,KAAI,QAAQ,kBAAkB;AAC5B,sCACE,kBACA,mBACA,OACD;AACD,cAAY,oBAAoB,KAAK;;AAEvC,KAAI,QAAQ,oBAAoB,QAAQ,kBACtC,wCACE,kBACA,QACA,QAAQ,kBACR,QAAQ,kBACT;AAEH,KAAI,QAAQ,mBAAmB;AAC7B,uCACE,kBACA,QACA,QAAQ,iBACT;AACD,cAAY,qBAAqB,KAAK;;AAGxC,gCACE,iBACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"include-helpers.mjs","names":[],"sources":["../../src/zod/include-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"include-helpers.mjs","names":[],"sources":["../../src/zod/include-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 { SchemaArgInputTypes } from \"../types\";\nimport {\n checkIsModelRelationField,\n checkModelHasManyModelRelation,\n checkModelHasModelRelation\n} from \"./model-helpers\";\n\nexport function addMissingInputObjectTypesForInclude(\n inputObjectTypes: DMMF.InputType[],\n models: DMMF.Model[],\n isGenerateSelect: boolean\n) {\n // generate input object types necessary to support ModelInclude with relation support\n const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(\n models,\n isGenerateSelect\n );\n\n for (const includeInputObjectType of generatedIncludeInputObjectTypes) {\n inputObjectTypes.push(includeInputObjectType);\n }\n}\n\nfunction generateModelIncludeInputObjectTypes(\n models: DMMF.Model[],\n isGenerateSelect: boolean\n) {\n const modelIncludeInputObjectTypes: DMMF.InputType[] = [];\n for (const model of models) {\n const { name: modelName, fields: modelFields } = model;\n const fields: DMMF.SchemaArg[] = [];\n\n for (const modelField of modelFields) {\n const { name: modelFieldName, isList, type } = modelField;\n\n const isRelationField = checkIsModelRelationField(modelField);\n\n if (isRelationField) {\n const field: DMMF.SchemaArg = {\n name: modelFieldName,\n isRequired: false,\n isNullable: false,\n inputTypes: [\n { isList: false, type: \"Boolean\", location: \"scalar\" },\n {\n isList: false,\n type: isList ? `${type}FindManyArgs` : `${type}DefaultArgs`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n }\n ]\n };\n fields.push(field);\n }\n }\n\n /**\n * include is not generated for models that do not have a relation with any other models continue onto the next model\n */\n const hasRelationToAnotherModel = checkModelHasModelRelation(model);\n if (!hasRelationToAnotherModel) {\n continue;\n }\n\n const hasManyRelationToAnotherModel = checkModelHasManyModelRelation(model);\n\n const shouldAddCountField = hasManyRelationToAnotherModel;\n if (shouldAddCountField) {\n const inputTypes: SchemaArgInputTypes = [\n { isList: false, type: \"Boolean\", location: \"scalar\" }\n ];\n if (isGenerateSelect) {\n inputTypes.push({\n isList: false,\n type: `${modelName}CountOutputTypeDefaultArgs`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n });\n }\n const _countField: DMMF.SchemaArg = {\n name: \"_count\",\n isRequired: false,\n isNullable: false,\n inputTypes\n };\n fields.push(_countField);\n }\n\n const modelIncludeInputObjectType: DMMF.InputType = {\n name: `${modelName}Include`,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields\n };\n modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);\n }\n return modelIncludeInputObjectTypes;\n}\n"],"mappings":";;;AA0BA,SAAgB,qCACd,kBACA,QACA,kBACA;CAEA,MAAM,mCAAmC,qCACvC,QACA,iBACD;AAED,MAAK,MAAM,0BAA0B,iCACnC,kBAAiB,KAAK,uBAAuB;;AAIjD,SAAS,qCACP,QACA,kBACA;CACA,MAAM,+BAAiD,EAAE;AACzD,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,EAAE,MAAM,WAAW,QAAQ,gBAAgB;EACjD,MAAM,SAA2B,EAAE;AAEnC,OAAK,MAAM,cAAc,aAAa;GACpC,MAAM,EAAE,MAAM,gBAAgB,QAAQ,SAAS;AAI/C,OAFwB,0BAA0B,WAE/B,EAAE;IACnB,MAAM,QAAwB;KAC5B,MAAM;KACN,YAAY;KACZ,YAAY;KACZ,YAAY,CACV;MAAE,QAAQ;MAAO,MAAM;MAAW,UAAU;MAAU,EACtD;MACE,QAAQ;MACR,MAAM,SAAS,GAAG,KAAK,gBAAgB,GAAG,KAAK;MAC/C,UAAU;MACV,WAAW;MACZ,CACF;KACF;AACD,WAAO,KAAK,MAAM;;;AAQtB,MAAI,CAD8B,2BAA2B,MAC/B,CAC5B;AAMF,MAHsC,+BAA+B,MAG9C,EAAE;GACvB,MAAM,aAAkC,CACtC;IAAE,QAAQ;IAAO,MAAM;IAAW,UAAU;IAAU,CACvD;AACD,OAAI,iBACF,YAAW,KAAK;IACd,QAAQ;IACR,MAAM,GAAG,UAAU;IACnB,UAAU;IACV,WAAW;IACZ,CAAC;GAEJ,MAAM,cAA8B;IAClC,MAAM;IACN,YAAY;IACZ,YAAY;IACZ;IACD;AACD,UAAO,KAAK,YAAY;;EAG1B,MAAM,8BAA8C;GAClD,MAAM,GAAG,UAAU;GACnB,aAAa;IACX,cAAc;IACd,cAAc;IACf;GACD;GACD;AACD,+BAA6B,KAAK,4BAA4B;;AAEhE,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-helpers.mjs","names":[],"sources":["../../src/zod/model-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 {\n DMMF,\n EnvValue,\n GeneratorOptions\n} from \"@prisma/generator-helper\";\nimport { lowerCaseFirst } from \"@stryke/string-format/lower-case-first\";\nimport path from \"node:path\";\nimport type {\n CodeBlockWriter,\n ImportDeclarationStructure,\n SourceFile\n} from \"ts-morph\";\nimport { StructureKind, VariableDeclarationKind } from \"ts-morph\";\nimport type { Config } from \"../config\";\nimport { getPrismaInternals } from \"../utils/get-prisma-internals\";\nimport { getJSDocs, getZodDocElements } from \"./docs-helpers\";\n\nexport function checkModelHasModelRelation(model: DMMF.Model) {\n const { fields: modelFields } = model;\n for (const modelField of modelFields) {\n const isRelationField = checkIsModelRelationField(modelField);\n if (isRelationField) {\n return true;\n }\n }\n return false;\n}\n\nexport function checkModelHasManyModelRelation(model: DMMF.Model) {\n const { fields: modelFields } = model;\n for (const modelField of modelFields) {\n const isManyRelationField = checkIsManyModelRelationField(modelField);\n if (isManyRelationField) {\n return true;\n }\n }\n return false;\n}\n\nexport function checkIsModelRelationField(modelField: DMMF.Field) {\n const { kind, relationName } = modelField;\n\n return kind === \"object\" && !!relationName;\n}\n\nexport function checkIsManyModelRelationField(modelField: DMMF.Field) {\n return checkIsModelRelationField(modelField) && modelField.isList;\n}\n\nexport function findModelByName(models: DMMF.Model[], modelName: string) {\n return models.find(({ name }) => name === modelName);\n}\n\nexport const writeArray = (\n writer: CodeBlockWriter,\n array: string[],\n newLine = true\n) => array.forEach(line => writer.write(line).conditionalNewLine(newLine));\n\nexport const useModelNames = ({\n modelCase,\n modelSuffix,\n relationModel\n}: Config) => {\n const formatModelName = (name: string, prefix = \"\") => {\n if (modelCase === \"camelCase\") {\n name = name.slice(0, 1).toLowerCase() + name.slice(1);\n }\n return `${prefix}${name}${modelSuffix}`;\n };\n\n return {\n modelName: (name: string) =>\n formatModelName(name, relationModel === \"default\" ? \"_\" : \"\"),\n relatedModelName: (\n name: string | DMMF.SchemaEnum | DMMF.OutputType | DMMF.SchemaArg\n ) =>\n formatModelName(\n relationModel === \"default\"\n ? name.toString()\n : `Related${name.toString()}`\n )\n };\n};\n\nexport const dotSlash = (input: string) => {\n const converted = input\n .replace(/^\\\\\\\\\\?\\\\/, \"\")\n .replace(/\\\\/g, \"/\")\n .replace(/\\/{2,}/g, \"/\");\n\n if (converted.includes(`/node_modules/`))\n return converted.split(`/node_modules/`).slice(-1)[0];\n\n if (converted.startsWith(`../`)) return converted;\n\n return `./${converted}`;\n};\n\nexport const chunk = <T extends any[]>(input: T, size: number): T[] => {\n return input.reduce((arr, item, idx) => {\n return idx % size === 0\n ? [...arr, [item]]\n : [...(arr as T).slice(0, -1), [...(arr as T).slice(-1)[0], item]];\n }, []);\n};\n\nexport const needsRelatedModel = (model: DMMF.Model, config: Config) =>\n model.fields.some(field => field.kind === \"object\") &&\n config.relationModel !== false;\n\nexport const writeImportsForModel = async (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config,\n options: GeneratorOptions\n) => {\n const internals = await getPrismaInternals();\n\n const outputPath = internals.parseEnvValue(\n options.generator.output as EnvValue\n );\n\n const { relatedModelName } = useModelNames(config);\n const importList: ImportDeclarationStructure[] = [\n {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: \"z\",\n moduleSpecifier: \"zod\"\n }\n ];\n\n if (config.imports) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n namespaceImport: \"imports\",\n moduleSpecifier: dotSlash(\n path.relative(\n outputPath,\n path.resolve(path.dirname(options.schemaPath), config.imports)\n )\n )!\n });\n }\n\n if (config.useDecimalJs && model.fields.some(f => f.type === \"Decimal\")) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n namedImports: [\"Decimal\"],\n moduleSpecifier: \"decimal.js\"\n });\n }\n\n const enumFields = model.fields.filter(f => f.kind === \"enum\");\n const relationFields = model.fields.filter(f => f.kind === \"object\");\n\n const clientPath = options.otherGenerators.find(\n each => each.provider.value === \"prisma-client-js\"\n )!.output!.value!;\n\n const relativePath = path.relative(outputPath, clientPath);\n\n if (enumFields.length > 0) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n isTypeOnly: enumFields.length === 0,\n moduleSpecifier: dotSlash(relativePath)!,\n namedImports: enumFields.map(f => f.type)\n });\n }\n\n if (config.relationModel !== false && relationFields.length > 0) {\n const filteredFields = relationFields.filter(f => f.type !== model.name);\n\n if (filteredFields.length > 0) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n moduleSpecifier: \"./index\",\n namedImports: Array.from(\n new Set(\n filteredFields.flatMap(f => [`${f.type}`, relatedModelName(f.type)])\n )\n )\n });\n }\n }\n\n sourceFile.addImportDeclarations(importList);\n};\n\nexport const computeCustomSchema = (docString: string) => {\n return getZodDocElements(docString)\n .find(modifier => modifier.startsWith(\"custom(\"))\n ?.slice(7)\n .slice(0, -1);\n};\n\nexport const computeModifiers = (docString: string) => {\n return getZodDocElements(docString).filter(\n each => !each.startsWith(\"custom(\")\n );\n};\n\nexport const getZodConstructor = (\n field: DMMF.Field,\n getRelatedModelName = (\n name: string | DMMF.SchemaEnum | DMMF.OutputType | DMMF.SchemaArg\n ) => name.toString()\n) => {\n let zodType = \"z.unknown()\";\n const extraModifiers: string[] = [\"\"];\n if (field.kind === \"scalar\") {\n switch (field.type) {\n case \"String\":\n zodType = \"z.string()\";\n break;\n case \"Int\":\n zodType = \"z.number()\";\n extraModifiers.push(\"int()\");\n break;\n case \"BigInt\":\n zodType = \"z.bigint()\";\n break;\n case \"DateTime\":\n zodType = \"z.date()\";\n break;\n case \"Float\":\n zodType = \"z.number()\";\n break;\n case \"Decimal\":\n zodType = \"z.number()\";\n break;\n case \"Json\":\n zodType = \"jsonSchema\";\n break;\n case \"Boolean\":\n zodType = \"z.boolean()\";\n break;\n // TODO: Proper type for bytes fields\n case \"Bytes\":\n zodType = \"z.unknown()\";\n break;\n }\n } else if (field.kind === \"enum\") {\n zodType = `z.nativeEnum(${field.type})`;\n } else if (field.kind === \"object\") {\n zodType = getRelatedModelName(field.type);\n }\n\n if (field.isList) extraModifiers.push(\"array()\");\n if (field.documentation) {\n zodType = computeCustomSchema(field.documentation) ?? zodType;\n extraModifiers.push(...computeModifiers(field.documentation));\n }\n if (!field.isRequired && field.type !== \"Json\")\n extraModifiers.push(\"nullish()\");\n // if (field.hasDefaultValue) extraModifiers.push('optional()')\n\n return `${zodType}${extraModifiers.join(\".\")}`;\n};\n\nexport const writeTypeSpecificSchemas = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n if (model.fields.some(f => f.type === \"Json\")) {\n sourceFile.addStatements(writer => {\n writer.newLine();\n writeArray(writer, [\n \"// Helper schema for JSON fields\",\n `type Literal = boolean | number | string${\n config.prismaJsonNullability ? \"\" : \"| null\"\n }`,\n \"type Json = Literal | { [key: string]: Json } | Json[]\",\n `const literalSchema = z.union([z.string(), z.number(), z.boolean()${\n config.prismaJsonNullability ? \"\" : \", z.null()\"\n }])`,\n \"const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))\"\n ]);\n });\n }\n\n if (config.useDecimalJs && model.fields.some(f => f.type === \"Decimal\")) {\n sourceFile.addStatements(writer => {\n writer.newLine();\n writeArray(writer, [\n \"// Helper schema for Decimal fields\",\n \"z\",\n \".instanceof(Decimal)\",\n \".or(z.string())\",\n \".or(z.number())\",\n \".refine((value) => {\",\n \" try {\",\n \" return new Decimal(value);\",\n \" } catch (error) {\",\n \" return false;\",\n \" }\",\n \"})\",\n \".transform((value) => new Decimal(value));\"\n ]);\n });\n }\n};\n\nexport const generateSchemaForModel = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n const { modelName } = useModelNames(config);\n\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n leadingTrivia: writer => writer.blankLineIfLastNot(),\n declarations: [\n {\n name: modelName(model.name),\n initializer(writer) {\n writer\n .write(\"z.object(\")\n .inlineBlock(() => {\n model.fields\n .filter(f => f.kind !== \"object\")\n .forEach(field => {\n writeArray(writer, getJSDocs(field.documentation));\n writer\n .write(`${field.name}: ${getZodConstructor(field)}`)\n .write(\",\")\n .newLine();\n });\n })\n .write(\")\");\n }\n }\n ]\n });\n};\n\nexport const generateRelatedSchemaForModel = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n const { modelName, relatedModelName } = useModelNames(config);\n\n const relationFields = model.fields.filter(f => f.kind === \"object\");\n\n sourceFile.addInterface({\n name: `${model.name}`,\n isExported: true,\n extends: [`z.infer<typeof ${modelName(model.name)}>`],\n properties: relationFields.map(f => ({\n hasQuestionToken: !f.isRequired,\n name: f.name,\n type: `${f.type}${f.isList ? \"[]\" : \"\"}${!f.isRequired ? \" | null\" : \"\"}`\n }))\n });\n\n sourceFile.addStatements(writer =>\n writeArray(writer, [\n \"\",\n \"/**\",\n ` * ${relatedModelName(\n model.name\n )} contains all relations on your model in addition to the scalars`,\n \" *\",\n \" * NOTE: Lazy required in case of potential circular dependencies within schema\",\n \" */\"\n ])\n );\n\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: relatedModelName(model.name),\n type: `z.ZodSchema<${model.name}>`,\n initializer(writer) {\n writer\n .write(`z.lazy(() => ${modelName(model.name)}.extend(`)\n .inlineBlock(() => {\n relationFields.forEach(field => {\n writeArray(writer, getJSDocs(field.documentation));\n\n writer\n .write(\n `${field.name}: ${getZodConstructor(\n field,\n relatedModelName\n )}`\n )\n .write(\",\")\n .newLine();\n });\n })\n .write(\"))\");\n }\n }\n ]\n });\n};\n\nexport const populateModelFile = async (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config,\n options: GeneratorOptions\n) => {\n await writeImportsForModel(model, sourceFile, config, options);\n writeTypeSpecificSchemas(model, sourceFile, config);\n generateSchemaForModel(model, sourceFile, config);\n if (needsRelatedModel(model, config))\n generateRelatedSchemaForModel(model, sourceFile, config);\n};\n\nexport const generateBarrelFile = (\n models: DMMF.Model[],\n indexFile: SourceFile\n) => {\n models.forEach(model =>\n indexFile.addExportDeclaration({\n moduleSpecifier: `./${lowerCaseFirst(model.name)}.schema`\n })\n );\n};\n"],"mappings":";;;;;;;AAmCA,SAAgB,2BAA2B,OAAmB;CAC5D,MAAM,EAAE,QAAQ,gBAAgB;AAChC,MAAK,MAAM,cAAc,YAEvB,KADwB,0BAA0B,WAC/B,CACjB,QAAO;AAGX,QAAO;;AAGT,SAAgB,+BAA+B,OAAmB;CAChE,MAAM,EAAE,QAAQ,gBAAgB;AAChC,MAAK,MAAM,cAAc,YAEvB,KAD4B,8BAA8B,WACnC,CACrB,QAAO;AAGX,QAAO;;AAGT,S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AkB,UAAU,MAAM,KAAK,CAAC,GAAG;EACrD,YAAY,eAAe,KAAI,OAAM;GACnC,kBAAkB,CAAC,EAAE;GACrB,MAAM,EAAE;GACR,MAAM,GAAG,EAAE,OAAO,EAAE,SAAS,OAAO,KAAK,CAAC,EAAE,aAAa,YAAY;GACtE,EAAE;EACJ,CAAC;AAEF,YAAW,eAAc,WACvB,WAAW,QAAQ;EACjB;EACA;EACA,MAAM,iBACJ,MAAM,KACP,CAAC;EACF;EACA;EACA;EACD,CAAC,CACH;AAED,YAAW,qBAAqB;EAC9B,iBAAiB,wBAAwB;EACzC,YAAY;EACZ,cAAc,CACZ;GACE,MAAM,iBAAiB,MAAM,KAAK;GAClC,MAAM,eAAe,MAAM,KAAK;GAChC,YAAY,QAAQ;AAClB,WACG,MAAM,gBAAgB,UAAU,MAAM,KAAK,CAAC,UAAU,CACtD,kBAAkB;AACjB,oBAAe,SAAQ,UAAS;AAC9B,iBAAW,QAAQ,UAAU,MAAM,cAAc,CAAC;AAElD,aACG,MACC,GAAG,MAAM,KAAK,IAAI,kBAChB,OACA,iBACD,GACF,CACA,MAAM,IAAI,CACV,SAAS;OACZ;MACF,CACD,MAAM,KAAK;;GAEjB,CACF;EACF,CAAC;;AAGJ,MAAa,oBAAoB,OAC/B,OACA,YACA,QACA,YACG;AACH,OAAM,qBAAqB,OAAO,YAAY,QAAQ,QAAQ;AAC9D,0BAAyB,OAAO,YAAY,OAAO;AACnD,wBAAuB,OAAO,YAAY,OAAO;AACjD,KAAI,kBAAkB,OAAO,OAAO,CAClC,+BAA8B,OAAO,YAAY,OAAO;;AAG5D,MAAa,sBACX,QACA,cACG;AACH,QAAO,SAAQ,UACb,UAAU,qBAAqB,EAC7B,iBAAiB,KAAK,eAAe,MAAM,KAAK,CAAC,UAClD,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"model-helpers.mjs","names":[],"sources":["../../src/zod/model-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 {\n DMMF,\n EnvValue,\n GeneratorOptions\n} from \"@prisma/generator-helper\";\nimport { lowerCaseFirst } from \"@stryke/string-format/lower-case-first\";\nimport path from \"node:path\";\nimport type {\n CodeBlockWriter,\n ImportDeclarationStructure,\n SourceFile\n} from \"ts-morph\";\nimport { StructureKind, VariableDeclarationKind } from \"ts-morph\";\nimport type { Config } from \"../config\";\nimport { getPrismaInternals } from \"../utils/get-prisma-internals\";\nimport { getJSDocs, getZodDocElements } from \"./docs-helpers\";\n\nexport function checkModelHasModelRelation(model: DMMF.Model) {\n const { fields: modelFields } = model;\n for (const modelField of modelFields) {\n const isRelationField = checkIsModelRelationField(modelField);\n if (isRelationField) {\n return true;\n }\n }\n return false;\n}\n\nexport function checkModelHasManyModelRelation(model: DMMF.Model) {\n const { fields: modelFields } = model;\n for (const modelField of modelFields) {\n const isManyRelationField = checkIsManyModelRelationField(modelField);\n if (isManyRelationField) {\n return true;\n }\n }\n return false;\n}\n\nexport function checkIsModelRelationField(modelField: DMMF.Field) {\n const { kind, relationName } = modelField;\n\n return kind === \"object\" && !!relationName;\n}\n\nexport function checkIsManyModelRelationField(modelField: DMMF.Field) {\n return checkIsModelRelationField(modelField) && modelField.isList;\n}\n\nexport function findModelByName(models: DMMF.Model[], modelName: string) {\n return models.find(({ name }) => name === modelName);\n}\n\nexport const writeArray = (\n writer: CodeBlockWriter,\n array: string[],\n newLine = true\n) => array.forEach(line => writer.write(line).conditionalNewLine(newLine));\n\nexport const useModelNames = ({\n modelCase,\n modelSuffix,\n relationModel\n}: Config) => {\n const formatModelName = (name: string, prefix = \"\") => {\n if (modelCase === \"camelCase\") {\n name = name.slice(0, 1).toLowerCase() + name.slice(1);\n }\n return `${prefix}${name}${modelSuffix}`;\n };\n\n return {\n modelName: (name: string) =>\n formatModelName(name, relationModel === \"default\" ? \"_\" : \"\"),\n relatedModelName: (\n name: string | DMMF.SchemaEnum | DMMF.OutputType | DMMF.SchemaArg\n ) =>\n formatModelName(\n relationModel === \"default\"\n ? name.toString()\n : `Related${name.toString()}`\n )\n };\n};\n\nexport const dotSlash = (input: string) => {\n const converted = input\n .replace(/^\\\\\\\\\\?\\\\/, \"\")\n .replace(/\\\\/g, \"/\")\n .replace(/\\/{2,}/g, \"/\");\n\n if (converted.includes(`/node_modules/`))\n return converted.split(`/node_modules/`).slice(-1)[0];\n\n if (converted.startsWith(`../`)) return converted;\n\n return `./${converted}`;\n};\n\nexport const chunk = <T extends any[]>(input: T, size: number): T[] => {\n return input.reduce((arr, item, idx) => {\n return idx % size === 0\n ? [...arr, [item]]\n : [...(arr as T).slice(0, -1), [...(arr as T).slice(-1)[0], item]];\n }, []);\n};\n\nexport const needsRelatedModel = (model: DMMF.Model, config: Config) =>\n model.fields.some(field => field.kind === \"object\") &&\n config.relationModel !== false;\n\nexport const writeImportsForModel = async (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config,\n options: GeneratorOptions\n) => {\n const internals = await getPrismaInternals();\n\n const outputPath = internals.parseEnvValue(\n options.generator.output as EnvValue\n );\n\n const { relatedModelName } = useModelNames(config);\n const importList: ImportDeclarationStructure[] = [\n {\n kind: StructureKind.ImportDeclaration,\n namespaceImport: \"z\",\n moduleSpecifier: \"zod\"\n }\n ];\n\n if (config.imports) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n namespaceImport: \"imports\",\n moduleSpecifier: dotSlash(\n path.relative(\n outputPath,\n path.resolve(path.dirname(options.schemaPath), config.imports)\n )\n )!\n });\n }\n\n if (config.useDecimalJs && model.fields.some(f => f.type === \"Decimal\")) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n namedImports: [\"Decimal\"],\n moduleSpecifier: \"decimal.js\"\n });\n }\n\n const enumFields = model.fields.filter(f => f.kind === \"enum\");\n const relationFields = model.fields.filter(f => f.kind === \"object\");\n\n const clientPath = options.otherGenerators.find(\n each => each.provider.value === \"prisma-client-js\"\n )!.output!.value!;\n\n const relativePath = path.relative(outputPath, clientPath);\n\n if (enumFields.length > 0) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n isTypeOnly: enumFields.length === 0,\n moduleSpecifier: dotSlash(relativePath)!,\n namedImports: enumFields.map(f => f.type)\n });\n }\n\n if (config.relationModel !== false && relationFields.length > 0) {\n const filteredFields = relationFields.filter(f => f.type !== model.name);\n\n if (filteredFields.length > 0) {\n importList.push({\n kind: StructureKind.ImportDeclaration,\n moduleSpecifier: \"./index\",\n namedImports: Array.from(\n new Set(\n filteredFields.flatMap(f => [`${f.type}`, relatedModelName(f.type)])\n )\n )\n });\n }\n }\n\n sourceFile.addImportDeclarations(importList);\n};\n\nexport const computeCustomSchema = (docString: string) => {\n return getZodDocElements(docString)\n .find(modifier => modifier.startsWith(\"custom(\"))\n ?.slice(7)\n .slice(0, -1);\n};\n\nexport const computeModifiers = (docString: string) => {\n return getZodDocElements(docString).filter(\n each => !each.startsWith(\"custom(\")\n );\n};\n\nexport const getZodConstructor = (\n field: DMMF.Field,\n getRelatedModelName = (\n name: string | DMMF.SchemaEnum | DMMF.OutputType | DMMF.SchemaArg\n ) => name.toString()\n) => {\n let zodType = \"z.unknown()\";\n const extraModifiers: string[] = [\"\"];\n if (field.kind === \"scalar\") {\n switch (field.type) {\n case \"String\":\n zodType = \"z.string()\";\n break;\n case \"Int\":\n zodType = \"z.number()\";\n extraModifiers.push(\"int()\");\n break;\n case \"BigInt\":\n zodType = \"z.bigint()\";\n break;\n case \"DateTime\":\n zodType = \"z.date()\";\n break;\n case \"Float\":\n zodType = \"z.number()\";\n break;\n case \"Decimal\":\n zodType = \"z.number()\";\n break;\n case \"Json\":\n zodType = \"jsonSchema\";\n break;\n case \"Boolean\":\n zodType = \"z.boolean()\";\n break;\n // TODO: Proper type for bytes fields\n case \"Bytes\":\n zodType = \"z.unknown()\";\n break;\n }\n } else if (field.kind === \"enum\") {\n zodType = `z.nativeEnum(${field.type})`;\n } else if (field.kind === \"object\") {\n zodType = getRelatedModelName(field.type);\n }\n\n if (field.isList) extraModifiers.push(\"array()\");\n if (field.documentation) {\n zodType = computeCustomSchema(field.documentation) ?? zodType;\n extraModifiers.push(...computeModifiers(field.documentation));\n }\n if (!field.isRequired && field.type !== \"Json\")\n extraModifiers.push(\"nullish()\");\n // if (field.hasDefaultValue) extraModifiers.push('optional()')\n\n return `${zodType}${extraModifiers.join(\".\")}`;\n};\n\nexport const writeTypeSpecificSchemas = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n if (model.fields.some(f => f.type === \"Json\")) {\n sourceFile.addStatements(writer => {\n writer.newLine();\n writeArray(writer, [\n \"// Helper schema for JSON fields\",\n `type Literal = boolean | number | string${\n config.prismaJsonNullability ? \"\" : \"| null\"\n }`,\n \"type Json = Literal | { [key: string]: Json } | Json[]\",\n `const literalSchema = z.union([z.string(), z.number(), z.boolean()${\n config.prismaJsonNullability ? \"\" : \", z.null()\"\n }])`,\n \"const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))\"\n ]);\n });\n }\n\n if (config.useDecimalJs && model.fields.some(f => f.type === \"Decimal\")) {\n sourceFile.addStatements(writer => {\n writer.newLine();\n writeArray(writer, [\n \"// Helper schema for Decimal fields\",\n \"z\",\n \".instanceof(Decimal)\",\n \".or(z.string())\",\n \".or(z.number())\",\n \".refine((value) => {\",\n \" try {\",\n \" return new Decimal(value);\",\n \" } catch (error) {\",\n \" return false;\",\n \" }\",\n \"})\",\n \".transform((value) => new Decimal(value));\"\n ]);\n });\n }\n};\n\nexport const generateSchemaForModel = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n const { modelName } = useModelNames(config);\n\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n leadingTrivia: writer => writer.blankLineIfLastNot(),\n declarations: [\n {\n name: modelName(model.name),\n initializer(writer) {\n writer\n .write(\"z.object(\")\n .inlineBlock(() => {\n model.fields\n .filter(f => f.kind !== \"object\")\n .forEach(field => {\n writeArray(writer, getJSDocs(field.documentation));\n writer\n .write(`${field.name}: ${getZodConstructor(field)}`)\n .write(\",\")\n .newLine();\n });\n })\n .write(\")\");\n }\n }\n ]\n });\n};\n\nexport const generateRelatedSchemaForModel = (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config\n) => {\n const { modelName, relatedModelName } = useModelNames(config);\n\n const relationFields = model.fields.filter(f => f.kind === \"object\");\n\n sourceFile.addInterface({\n name: `${model.name}`,\n isExported: true,\n extends: [`z.infer<typeof ${modelName(model.name)}>`],\n properties: relationFields.map(f => ({\n hasQuestionToken: !f.isRequired,\n name: f.name,\n type: `${f.type}${f.isList ? \"[]\" : \"\"}${!f.isRequired ? \" | null\" : \"\"}`\n }))\n });\n\n sourceFile.addStatements(writer =>\n writeArray(writer, [\n \"\",\n \"/**\",\n ` * ${relatedModelName(\n model.name\n )} contains all relations on your model in addition to the scalars`,\n \" *\",\n \" * NOTE: Lazy required in case of potential circular dependencies within schema\",\n \" */\"\n ])\n );\n\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: relatedModelName(model.name),\n type: `z.ZodSchema<${model.name}>`,\n initializer(writer) {\n writer\n .write(`z.lazy(() => ${modelName(model.name)}.extend(`)\n .inlineBlock(() => {\n relationFields.forEach(field => {\n writeArray(writer, getJSDocs(field.documentation));\n\n writer\n .write(\n `${field.name}: ${getZodConstructor(\n field,\n relatedModelName\n )}`\n )\n .write(\",\")\n .newLine();\n });\n })\n .write(\"))\");\n }\n }\n ]\n });\n};\n\nexport const populateModelFile = async (\n model: DMMF.Model,\n sourceFile: SourceFile,\n config: Config,\n options: GeneratorOptions\n) => {\n await writeImportsForModel(model, sourceFile, config, options);\n writeTypeSpecificSchemas(model, sourceFile, config);\n generateSchemaForModel(model, sourceFile, config);\n if (needsRelatedModel(model, config))\n generateRelatedSchemaForModel(model, sourceFile, config);\n};\n\nexport const generateBarrelFile = (\n models: DMMF.Model[],\n indexFile: SourceFile\n) => {\n models.forEach(model =>\n indexFile.addExportDeclaration({\n moduleSpecifier: `./${lowerCaseFirst(model.name)}.schema`\n })\n );\n};\n"],"mappings":";;;;;;;AAmCA,SAAgB,2BAA2B,OAAmB;CAC5D,MAAM,EAAE,QAAQ,gBAAgB;AAChC,MAAK,MAAM,cAAc,YAEvB,KADwB,0BAA0B,WAC/B,CACjB,QAAO;AAGX,QAAO;;AAGT,SAAgB,+BAA+B,OAAmB;CAChE,MAAM,EAAE,QAAQ,gBAAgB;AAChC,MAAK,MAAM,cAAc,YAEvB,KAD4B,8BAA8B,WACnC,CACrB,QAAO;AAGX,QAAO;;AAGT,SAAgB,0BAA0B,YAAwB;CAChE,MAAM,EAAE,MAAM,iBAAiB;AAE/B,QAAO,SAAS,YAAY,CAAC,CAAC;;AAGhC,SAAgB,8BAA8B,YAAwB;AACpE,QAAO,0BAA0B,WAAW,IAAI,WAAW;;AAG7D,SAAgB,gBAAgB,QAAsB,WAAmB;AACvE,QAAO,OAAO,MAAM,EAAE,WAAW,SAAS,UAAU;;AAGtD,MAAa,cACX,QACA,OACA,UAAU,SACP,MAAM,SAAQ,SAAQ,OAAO,MAAM,KAAK,CAAC,mBAAmB,QAAQ,CAAC;AAE1E,MAAa,iBAAiB,EAC5B,WACA,aACA,oBACY;CACZ,MAAM,mBAAmB,MAAc,SAAS,OAAO;AACrD,MAAI,cAAc,YAChB,QAAO,KAAK,MAAM,GAAG,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAEvD,SAAO,GAAG,SAAS,O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oBAAe,SAAQ,UAAS;AAC9B,iBAAW,QAAQ,UAAU,MAAM,cAAc,CAAC;AAElD,aACG,MACC,GAAG,MAAM,KAAK,IAAI,kBAChB,OACA,iBACD,GACF,CACA,MAAM,IAAI,CACV,SAAS;OACZ;MACF,CACD,MAAM,KAAK;;GAEjB,CACF;EACF,CAAC;;AAGJ,MAAa,oBAAoB,OAC/B,OACA,YACA,QACA,YACG;AACH,OAAM,qBAAqB,OAAO,YAAY,QAAQ,QAAQ;AAC9D,0BAAyB,OAAO,YAAY,OAAO;AACnD,wBAAuB,OAAO,YAAY,OAAO;AACjD,KAAI,kBAAkB,OAAO,OAAO,CAClC,+BAA8B,OAAO,YAAY,OAAO;;AAG5D,MAAa,sBACX,QACA,cACG;AACH,QAAO,SAAQ,UACb,UAAU,qBAAqB,EAC7B,iBAAiB,KAAK,eAAe,MAAM,KAAK,CAAC,UAClD,CAAC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelArgs-helpers.mjs","names":[],"sources":["../../src/zod/modelArgs-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-helpers.mjs","names":[],"sources":["../../src/zod/mongodb-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"mongodb-helpers.mjs","names":[],"sources":["../../src/zod/mongodb-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 Transformer from \"./transformer\";\n\nexport function addMissingInputObjectTypesForMongoDbRawOpsAndQueries(\n modelOperations: DMMF.ModelMapping[],\n outputObjectTypes: DMMF.OutputType[],\n inputObjectTypes: DMMF.InputType[]\n) {\n const rawOpsMap = resolveMongoDbRawOperations(modelOperations);\n Transformer.rawOpsMap = rawOpsMap ?? {};\n\n const mongoDbRawQueryInputObjectTypes =\n resolveMongoDbRawQueryInputObjectTypes(outputObjectTypes);\n for (const mongoDbRawQueryInputType of mongoDbRawQueryInputObjectTypes) {\n inputObjectTypes.push(mongoDbRawQueryInputType);\n }\n}\n\nfunction resolveMongoDbRawOperations(modelOperations: DMMF.ModelMapping[]) {\n const rawOpsMap: { [name: string]: string } = {};\n const rawOpsNames = [\n ...new Set(\n modelOperations.reduce<string[]>((result, current) => {\n const keys = Object.keys(current);\n keys?.forEach(key => {\n if (key.includes(\"Raw\")) {\n result.push(key);\n }\n });\n return result;\n }, [])\n )\n ];\n\n const modelNames = modelOperations.map(item => item.model);\n\n rawOpsNames.forEach(opName => {\n modelNames.forEach(modelName => {\n const isFind = opName === \"findRaw\";\n const opWithModel = `${opName.replace(\"Raw\", \"\")}${modelName}Raw`;\n rawOpsMap[opWithModel] = isFind\n ? `${modelName}FindRawArgs`\n : `${modelName}AggregateRawArgs`;\n });\n });\n\n return rawOpsMap;\n}\n\nfunction resolveMongoDbRawQueryInputObjectTypes(\n outputObjectTypes: DMMF.OutputType[]\n) {\n const mongoDbRawQueries = getMongoDbRawQueries(outputObjectTypes);\n const mongoDbRawQueryInputObjectTypes = mongoDbRawQueries.map(item => ({\n name: item.name,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields: item.args.map(arg => ({\n name: arg.name,\n isRequired: arg.isRequired,\n isNullable: arg.isNullable,\n inputTypes: arg.inputTypes\n }))\n }));\n\n return mongoDbRawQueryInputObjectTypes;\n}\n\nfunction getMongoDbRawQueries(outputObjectTypes: DMMF.OutputType[]) {\n const queryOutputTypes = outputObjectTypes.filter(\n item => item.name === \"Query\"\n );\n\n const mongodbRawQueries =\n queryOutputTypes?.[0]!.fields.filter(field => field.name.includes(\"Raw\")) ??\n [];\n\n return mongodbRawQueries;\n}\n\nexport const isMongodbRawOp = (name: string) =>\n /find[\\s\\S]*?Raw/.test(name) || /aggregate[\\s\\S]*?Raw/.test(name);\n"],"mappings":";;;AAqBA,SAAgB,qDACd,iBACA,mBACA,kBACA;AAEA,aAAY,YADM,4BAA4B,gBACb,IAAI,EAAE;CAEvC,MAAM,kCACJ,uCAAuC,kBAAkB;AAC3D,MAAK,MAAM,4BAA4B,gCACrC,kBAAiB,KAAK,yBAAyB;;AAInD,SAAS,4BAA4B,iBAAsC;CACzE,MAAM,YAAwC,EAAE;CAChD,MAAM,cAAc,CAClB,GAAG,IAAI,IACL,gBAAgB,QAAkB,QAAQ,YAAY;AAEpD,EADa,OAAO,KAAK,QACrB,EAAE,SAAQ,QAAO;AACnB,OAAI,IAAI,SAAS,MAAM,CACrB,QAAO,KAAK,IAAI;IAElB;AACF,SAAO;IACN,EAAE,CAAC,CACP,CACF;CAED,MAAM,aAAa,gBAAgB,KAAI,SAAQ,KAAK,MAAM;AAE1D,aAAY,SAAQ,WAAU;AAC5B,aAAW,SAAQ,cAAa;GAC9B,MAAM,SAAS,WAAW;GAC1B,MAAM,cAAc,GAAG,OAAO,QAAQ,OAAO,GAAG,GAAG,UAAU;AAC7D,aAAU,eAAe,SACrB,GAAG,UAAU,eACb,GAAG,UAAU;IACjB;GACF;AAEF,QAAO;;AAGT,SAAS,uCACP,mBACA;AAgBA,QAf0B,qBAAqB,kBACU,CAAC,KAAI,UAAS;EACrE,MAAM,KAAK;EACX,aAAa;GACX,cAAc;GACd,cAAc;GACf;EACD,QAAQ,KAAK,KAAK,KAAI,SAAQ;GAC5B,MAAM,IAAI;GACV,YAAY,IAAI;GAChB,YAAY,IAAI;GAChB,YAAY,IAAI;GACjB,EAAE;EACJ,EAEqC;;AAGxC,SAAS,qBAAqB,mBAAsC;AASlE,QARyB,kBAAkB,QACzC,SAAQ,KAAK,SAAS,QAIN,GAAG,GAAI,OAAO,QAAO,UAAS,MAAM,KAAK,SAAS,MAAM,CAAC,IACzE,EAAE;;AAKN,MAAa,kBAAkB,SAC7B,kBAAkB,KAAK,KAAK,IAAI,uBAAuB,KAAK,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-helpers.mjs","names":[],"sources":["../../src/zod/select-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"select-helpers.mjs","names":[],"sources":["../../src/zod/select-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 { ArrayValues } from \"@stryke/types/array\";\nimport type { SchemaArgInputTypes, Writeable } from \"../types\";\nimport {\n checkIsModelRelationField,\n checkModelHasManyModelRelation\n} from \"./model-helpers\";\n\nexport function addMissingInputObjectTypesForSelect(\n inputObjectTypes: DMMF.InputType[],\n outputObjectTypes: DMMF.OutputType[],\n models: DMMF.Model[]\n) {\n // generate input object types necessary to support ModelSelect._count\n const modelCountOutputTypes = getModelCountOutputTypes(outputObjectTypes);\n const modelCountOutputTypeSelectInputObjectTypes =\n generateModelCountOutputTypeSelectInputObjectTypes(modelCountOutputTypes);\n const modelCountOutputTypeArgsInputObjectTypes =\n generateModelCountOutputTypeArgsInputObjectTypes(modelCountOutputTypes);\n\n const modelSelectInputObjectTypes =\n generateModelSelectInputObjectTypes(models);\n\n const generatedInputObjectTypes = [\n modelCountOutputTypeSelectInputObjectTypes,\n modelCountOutputTypeArgsInputObjectTypes,\n modelSelectInputObjectTypes\n ].flat();\n\n for (const inputObjectType of generatedInputObjectTypes) {\n inputObjectTypes.push(inputObjectType);\n }\n}\n\nfunction getModelCountOutputTypes(outputObjectTypes: DMMF.OutputType[]) {\n return outputObjectTypes.filter(({ name }) =>\n name.includes(\"CountOutputType\")\n );\n}\n\nfunction generateModelCountOutputTypeSelectInputObjectTypes(\n modelCountOutputTypes: DMMF.OutputType[]\n) {\n const modelCountOutputTypeSelectInputObjectTypes: DMMF.InputType[] = [];\n for (const modelCountOutputType of modelCountOutputTypes) {\n const {\n name: modelCountOutputTypeName,\n fields: modelCountOutputTypeFields\n } = modelCountOutputType;\n const modelCountOutputTypeSelectInputObjectType: DMMF.InputType = {\n name: `${modelCountOutputTypeName}Select`,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields: modelCountOutputTypeFields.map(({ name }) => ({\n name,\n isRequired: false,\n isNullable: false,\n inputTypes: [\n {\n isList: false,\n type: `Boolean`,\n location: \"scalar\"\n }\n ]\n }))\n };\n modelCountOutputTypeSelectInputObjectTypes.push(\n modelCountOutputTypeSelectInputObjectType\n );\n }\n\n return modelCountOutputTypeSelectInputObjectTypes;\n}\n\nfunction generateModelCountOutputTypeArgsInputObjectTypes(\n modelCountOutputTypes: DMMF.OutputType[]\n) {\n const modelCountOutputTypeArgsInputObjectTypes: DMMF.InputType[] = [];\n for (const modelCountOutputType of modelCountOutputTypes) {\n const { name: modelCountOutputTypeName } = modelCountOutputType;\n const modelCountOutputTypeArgsInputObjectType: DMMF.InputType = {\n name: `${modelCountOutputTypeName}DefaultArgs`,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields: [\n {\n name: \"select\",\n isRequired: false,\n isNullable: false,\n inputTypes: [\n {\n isList: false,\n type: `${modelCountOutputTypeName}Select`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n }\n ]\n }\n ]\n };\n modelCountOutputTypeArgsInputObjectTypes.push(\n modelCountOutputTypeArgsInputObjectType\n );\n }\n\n return modelCountOutputTypeArgsInputObjectTypes;\n}\n\nfunction generateModelSelectInputObjectTypes(models: DMMF.Model[]) {\n const modelSelectInputObjectTypes: DMMF.InputType[] = [];\n for (const model of models) {\n const { name: modelName, fields: modelFields } = model;\n const fields: DMMF.SchemaArg[] = [];\n\n for (const modelField of modelFields) {\n const { name: modelFieldName, isList, type } = modelField;\n\n const isRelationField = checkIsModelRelationField(modelField);\n\n const field: Writeable<DMMF.SchemaArg> = {\n name: modelFieldName,\n isRequired: false,\n isNullable: false,\n inputTypes: [\n { isList: false, type: \"Boolean\", location: \"scalar\" }\n ] as Writeable<DMMF.SchemaArg[\"inputTypes\"]>\n };\n\n if (isRelationField) {\n const schemaArgInputType: ArrayValues<SchemaArgInputTypes> = {\n isList: false,\n type: isList ? `${type}FindManyArgs` : `${type}DefaultArgs`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n };\n field.inputTypes.push(schemaArgInputType);\n }\n\n fields.push(field);\n }\n\n const hasManyRelationToAnotherModel = checkModelHasManyModelRelation(model);\n\n const shouldAddCountField = hasManyRelationToAnotherModel;\n if (shouldAddCountField) {\n const _countField: DMMF.SchemaArg = {\n name: \"_count\",\n isRequired: false,\n isNullable: false,\n inputTypes: [\n { isList: false, type: \"Boolean\", location: \"scalar\" },\n {\n isList: false,\n type: `${modelName}CountOutputTypeDefaultArgs`,\n location: \"inputObjectTypes\",\n namespace: \"prisma\"\n }\n ]\n };\n fields.push(_countField);\n }\n\n const modelSelectInputObjectType: DMMF.InputType = {\n name: `${modelName}Select`,\n constraints: {\n maxNumFields: null,\n minNumFields: null\n },\n fields\n };\n modelSelectInputObjectTypes.push(modelSelectInputObjectType);\n }\n\n return modelSelectInputObjectTypes;\n}\n"],"mappings":";;;AA0BA,SAAgB,oCACd,kBACA,mBACA,QACA;CAEA,MAAM,wBAAwB,yBAAyB,kBAAkB;CASzE,MAAM,4BAA4B;EAPhC,mDAAmD,sBAQT;EAN1C,iDAAiD,sBAOT;EAJxC,oCAAoC,OAKT;EAC5B,CA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