@stryke/prisma-trpc-generator 0.13.49 → 0.13.51

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.
Files changed (104) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +31 -1
  2. package/dist/_virtual/rolldown_runtime.mjs +32 -1
  3. package/dist/config.cjs +50 -1
  4. package/dist/config.mjs +49 -1
  5. package/dist/config.mjs.map +1 -1
  6. package/dist/generator.cjs +1 -1
  7. package/dist/generator.mjs +3 -1
  8. package/dist/helpers.cjs +281 -32
  9. package/dist/helpers.mjs +271 -32
  10. package/dist/helpers.mjs.map +1 -1
  11. package/dist/index.cjs +26 -1
  12. package/dist/index.mjs +27 -1
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/packages/env/src/get-env-paths.cjs +87 -1
  15. package/dist/packages/env/src/get-env-paths.mjs +84 -1
  16. package/dist/packages/env/src/get-env-paths.mjs.map +1 -1
  17. package/dist/packages/string-format/src/acronyms.cjs +408 -1
  18. package/dist/packages/string-format/src/acronyms.mjs +407 -1
  19. package/dist/packages/string-format/src/acronyms.mjs.map +1 -1
  20. package/dist/packages/string-format/src/articles.cjs +10 -1
  21. package/dist/packages/string-format/src/articles.mjs +9 -1
  22. package/dist/packages/string-format/src/articles.mjs.map +1 -1
  23. package/dist/packages/string-format/src/combine.cjs +15 -1
  24. package/dist/packages/string-format/src/combine.mjs +14 -1
  25. package/dist/packages/string-format/src/combine.mjs.map +1 -1
  26. package/dist/packages/string-format/src/conjunctions.cjs +32 -1
  27. package/dist/packages/string-format/src/conjunctions.mjs +31 -1
  28. package/dist/packages/string-format/src/conjunctions.mjs.map +1 -1
  29. package/dist/packages/string-format/src/decamelize.cjs +14 -1
  30. package/dist/packages/string-format/src/decamelize.mjs +13 -1
  31. package/dist/packages/string-format/src/decamelize.mjs.map +1 -1
  32. package/dist/packages/string-format/src/format-special-cases.cjs +33 -1
  33. package/dist/packages/string-format/src/format-special-cases.mjs +33 -1
  34. package/dist/packages/string-format/src/format-special-cases.mjs.map +1 -1
  35. package/dist/packages/string-format/src/lower-case-first.cjs +17 -1
  36. package/dist/packages/string-format/src/lower-case-first.mjs +16 -1
  37. package/dist/packages/string-format/src/lower-case-first.mjs.map +1 -1
  38. package/dist/packages/string-format/src/prepositions.cjs +68 -1
  39. package/dist/packages/string-format/src/prepositions.mjs +67 -1
  40. package/dist/packages/string-format/src/prepositions.mjs.map +1 -1
  41. package/dist/packages/string-format/src/special-cases.cjs +53 -1
  42. package/dist/packages/string-format/src/special-cases.mjs +52 -1
  43. package/dist/packages/string-format/src/special-cases.mjs.map +1 -1
  44. package/dist/packages/string-format/src/title-case.cjs +19 -1
  45. package/dist/packages/string-format/src/title-case.mjs +19 -1
  46. package/dist/packages/string-format/src/title-case.mjs.map +1 -1
  47. package/dist/packages/string-format/src/upper-case-first.cjs +17 -1
  48. package/dist/packages/string-format/src/upper-case-first.mjs +16 -1
  49. package/dist/packages/string-format/src/upper-case-first.mjs.map +1 -1
  50. package/dist/prisma-generator.cjs +185 -8
  51. package/dist/prisma-generator.mjs +184 -8
  52. package/dist/prisma-generator.mjs.map +1 -1
  53. package/dist/project.cjs +15 -1
  54. package/dist/project.mjs +14 -1
  55. package/dist/project.mjs.map +1 -1
  56. package/dist/utils/format-file.cjs +25 -1
  57. package/dist/utils/format-file.mjs +23 -1
  58. package/dist/utils/format-file.mjs.map +1 -1
  59. package/dist/utils/get-jiti.cjs +21 -1
  60. package/dist/utils/get-jiti.mjs +20 -1
  61. package/dist/utils/get-jiti.mjs.map +1 -1
  62. package/dist/utils/get-prisma-internals.cjs +13 -1
  63. package/dist/utils/get-prisma-internals.mjs +12 -1
  64. package/dist/utils/get-prisma-internals.mjs.map +1 -1
  65. package/dist/utils/write-file-safely.cjs +32 -2
  66. package/dist/utils/write-file-safely.mjs +29 -2
  67. package/dist/utils/write-file-safely.mjs.map +1 -1
  68. package/dist/zod/aggregate-helpers.cjs +70 -1
  69. package/dist/zod/aggregate-helpers.mjs +67 -1
  70. package/dist/zod/aggregate-helpers.mjs.map +1 -1
  71. package/dist/zod/comments-helpers.cjs +77 -1
  72. package/dist/zod/comments-helpers.mjs +75 -1
  73. package/dist/zod/comments-helpers.mjs.map +1 -1
  74. package/dist/zod/docs-helpers.cjs +23 -3
  75. package/dist/zod/docs-helpers.mjs +20 -3
  76. package/dist/zod/docs-helpers.mjs.map +1 -1
  77. package/dist/zod/generator-helpers.cjs +34 -1
  78. package/dist/zod/generator-helpers.mjs +31 -1
  79. package/dist/zod/generator-helpers.mjs.map +1 -1
  80. package/dist/zod/helpers.cjs +26 -1
  81. package/dist/zod/helpers.mjs +26 -1
  82. package/dist/zod/helpers.mjs.map +1 -1
  83. package/dist/zod/include-helpers.cjs +69 -1
  84. package/dist/zod/include-helpers.mjs +69 -1
  85. package/dist/zod/include-helpers.mjs.map +1 -1
  86. package/dist/zod/model-helpers.cjs +244 -1
  87. package/dist/zod/model-helpers.mjs +236 -1
  88. package/dist/zod/model-helpers.mjs.map +1 -1
  89. package/dist/zod/modelArgs-helpers.cjs +56 -1
  90. package/dist/zod/modelArgs-helpers.mjs +56 -1
  91. package/dist/zod/modelArgs-helpers.mjs.map +1 -1
  92. package/dist/zod/mongodb-helpers.cjs +49 -1
  93. package/dist/zod/mongodb-helpers.mjs +48 -1
  94. package/dist/zod/mongodb-helpers.mjs.map +1 -1
  95. package/dist/zod/select-helpers.cjs +128 -1
  96. package/dist/zod/select-helpers.mjs +128 -1
  97. package/dist/zod/select-helpers.mjs.map +1 -1
  98. package/dist/zod/transformer.cjs +434 -19
  99. package/dist/zod/transformer.mjs +432 -19
  100. package/dist/zod/transformer.mjs.map +1 -1
  101. package/dist/zod/whereUniqueInput-helpers.cjs +17 -1
  102. package/dist/zod/whereUniqueInput-helpers.mjs +16 -1
  103. package/dist/zod/whereUniqueInput-helpers.mjs.map +1 -1
  104. package/package.json +4 -4
@@ -1 +1 @@
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 { 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\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?: FormatSpecialCasesOptions\n): T {\n return input\n ?.split(/\\s+-\\s+/)\n .map(segment =>\n decamelize(segment)\n .split(/[\\s\\-_]/)\n .map(upperCaseFirst)\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":"8MA+BA,SAAgB,EACd,EACA,EACG,CACH,OAAO,GACH,MAAM,UAAU,CACjB,IAAI,GACH,EAAW,EAAQ,CAChB,MAAM,UAAU,CAChB,IAAI,EAAe,CACnB,KAAK,EAAe,EAAe,IAClC,EAAmB,EAAO,EAAO,EAAO,EAAQ,CACjD,CACA,OAAO,EAAQ,CACnB,CACA,KAAK,MAAM"}
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 { 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\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?: FormatSpecialCasesOptions\n): T {\n return input\n ?.split(/\\s+-\\s+/)\n .map(segment =>\n decamelize(segment)\n .split(/[\\s\\-_]/)\n .map(upperCaseFirst)\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":";;;;;;;;;;;;;AA+BA,SAAgB,UACd,OACA,SACG;AACH,QAAO,OACH,MAAM,UAAU,CACjB,KAAI,YACH,WAAW,QAAQ,CAChB,MAAM,UAAU,CAChB,IAAI,eAAe,CACnB,KAAK,OAAe,OAAe,UAClC,mBAAmB,OAAO,OAAO,OAAO,QAAQ,CACjD,CACA,OAAO,QAAQ,CACnB,CACA,KAAK,MAAM"}
@@ -1 +1,17 @@
1
- function e(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}exports.upperCaseFirst=e;
1
+
2
+ //#region ../string-format/src/upper-case-first.ts
3
+ /**
4
+ * Upper case the first character of an input string.
5
+ *
6
+ * @remarks
7
+ * "Thisisanexample"
8
+ *
9
+ * @param input - The input string.
10
+ * @returns The capitalized string.
11
+ */
12
+ function upperCaseFirst(input) {
13
+ return input ? input.charAt(0).toUpperCase() + input.slice(1) : input;
14
+ }
15
+
16
+ //#endregion
17
+ exports.upperCaseFirst = upperCaseFirst;
@@ -1,2 +1,17 @@
1
- function e(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}export{e as upperCaseFirst};
1
+ //#region ../string-format/src/upper-case-first.ts
2
+ /**
3
+ * Upper case the first character of an input string.
4
+ *
5
+ * @remarks
6
+ * "Thisisanexample"
7
+ *
8
+ * @param input - The input string.
9
+ * @returns The capitalized string.
10
+ */
11
+ function upperCaseFirst(input) {
12
+ return input ? input.charAt(0).toUpperCase() + input.slice(1) : input;
13
+ }
14
+
15
+ //#endregion
16
+ export { upperCaseFirst };
2
17
  //# sourceMappingURL=upper-case-first.mjs.map
@@ -1 +1 @@
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,EAAc,CACzE,OAAQ,GAAQ,EAAM,OAAO,EAAE,CAAC,aAAa,CAAG,EAAM,MAAM,EAAE"}
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,9 +1,186 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./packages/string-format/src/lower-case-first.cjs`),n=require(`./node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.cjs`),r=require(`./config.cjs`),i=require(`./project.cjs`),a=require(`./utils/get-prisma-internals.cjs`),o=require(`./helpers.cjs`),s=require(`./utils/write-file-safely.cjs`),c=require(`./zod/aggregate-helpers.cjs`),l=require(`./zod/comments-helpers.cjs`),u=require(`./zod/transformer.cjs`),d=require(`./zod/generator-helpers.cjs`),f=require(`./zod/helpers.cjs`);let p=require(`@stryke/fs/exists`),m=require(`@stryke/fs/helpers`),h=require(`@stryke/path/join-paths`),g=require(`node:path`);g=e.__toESM(g);var _=e.__toESM(n.default,1);async function v(e){console.log(`[STORM]: Running the Storm Software - Prisma tRPC generator
2
- `);let n=await a.getPrismaInternals();console.log(`[STORM]: Validating configuration options
3
- `);let v=n.parseEnvValue(e.generator.output),y=await r.configSchema.safeParseAsync(e.generator.config);if(!y.success)throw Error(`Invalid options passed`);let b=y.data,x=e=>{b.debug&&console.log(`[STORM]: ${e} \n`)};x(`Using configuration parameters: \n${JSON.stringify(b)}`),x(`Preparing output directory: ${v}`),await(0,m.removeDirectory)(v),await(0,m.createDirectory)(v),x(`Finding Prisma Client generator`);let S=e.otherGenerators.find(e=>n.parseEnvValue(e.provider)===`prisma-client-js`);if(!S)throw Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");x(`Generating Prisma Client DMMF`);let C=await n.getDMMF({datamodel:e.datamodel,previewFeatures:S?.previewFeatures}),w=C.mappings.modelOperations,T=C.schema.inputObjectTypes.prisma,E=C.schema.outputObjectTypes.prisma,D=C.schema.enumTypes,O=C.datamodel.models,k=[],A=[];if(b.withZod!==!1){x(`Generating Zod schemas`);let t=n.parseEnvValue(e.generator.output);await(0,m.createDirectory)(t),u.default.setOutputPath(t),S?.isCustomOutput&&u.default.setPrismaClientOutputPath(S.output?.value),await o.constructZodModels(O,(0,h.joinPaths)(t,`schemas`,`models`),b,e),l.resolveZodModelsComments(O,w,D,k,A),await d.generateZodEnumSchemas(D.prisma,D.model);let r=e.datasources?.[0];if(!r)throw Error(`No datasource found`);let i=S?.previewFeatures;u.default.provider=r.provider,u.default.previewFeatures=i,f.addMissingZodInputObjectTypes(T,E,O,w,r.provider,{isGenerateSelect:!0,isGenerateInclude:!0});let a=c.resolveZodAggregateOperationSupport(T);l.hideZodInputObjectTypesAndRelatedFields(T,k,A),await d.generateZodObjectSchemas(T),await d.generateZodModelSchemas(O,w,a),await d.generateZodIndex()}else x(`Skipping Zod schemas generation`);let j=[],M=[],N=[];C.mappings.modelOperations.forEach(e=>{let{model:t,plural:n,...r}=e;for(let[e,t]of Object.entries(r))[`findUnique`,`findUniqueOrThrow`,`findFirst`,`findFirstOrThrow`,`findRaw`,`findMany`,`aggregateRaw`,`count`,`aggregate`,`groupBy`].includes(e)&&j.push(t),[`createOne`,`createMany`,`createManyAndReturn`,`deleteOne`,`deleteMany`,`updateOne`,`updateMany`,`updateManyAndReturn`,`upsertOne`].includes(e)&&M.push(t)}),j.sort(),M.sort(),N.sort(),b.withShield&&!(typeof b.withShield==`string`&&((0,p.existsSync)((0,h.joinPaths)(v,b.withShield))||(0,p.existsSync)((0,h.joinPaths)(v,`./${b.withShield}.ts`))||(0,p.existsSync)((0,h.joinPaths)(v,b.withShield,`./shield.ts`))))?(x(`Generating tRPC Shield source file to ${v}`),await s.writeFileSafely((0,h.joinPaths)(v,`./shield.ts`),await o.constructShield({queries:j,mutations:M,subscriptions:N},b,e,v))):x(`Skipping tRPC Shield generation`),x(`Generating tRPC source code for ${O.length} models`),b.trpcOptions&&typeof b.trpcOptions==`boolean`&&(x(`Generating tRPC options source file to ${v}`),await s.writeFileSafely((0,h.joinPaths)(v,`./options.ts`),o.constructDefaultOptions(b,e,v))),o.resolveModelsComments(O,k),x(`Generating tRPC export file`),await o.generateTRPCExports(i.project.createSourceFile(g.default.resolve(v,`trpc.ts`),void 0,{overwrite:!0}),b,e,v),x(`Generating tRPC app router`);let P=i.project.createSourceFile(g.default.resolve(v,`routers`,`index.ts`),void 0,{overwrite:!0});x(`Generating tRPC router imports`),o.generateCreateRouterImport({sourceFile:P});let F=[];for(let e of w){let{model:n,...r}=e;if(k.includes(n)){x(`Skipping model ${n} as it is hidden`);continue}if(!n){x(`Skipping model ${n} as it is not defined`);continue}let a=Object.keys(r).filter(e=>b.generateModelActions.some(t=>t===e.replace(`One`,``)));if(!a.length){x(`Skipping model ${n} as it has no actions to generate`);continue}let s=(0,_.default)(t.lowerCaseFirst(n));x(`Generating tRPC router for model ${n}`),o.generateRouterImport(P,s,n);let c=i.project.createSourceFile(g.default.resolve(v,`routers`,`${t.lowerCaseFirst(n)}.router.ts`),void 0,{overwrite:!0});o.generateCreateRouterImport({sourceFile:c,config:b}),b.withZod&&(x(`Generating Zod schemas imports`),o.generateRouterSchemaImports(c,n,a)),c.addStatements(`
4
- export const ${s}Router = t.router({`);for(let e of a){let t=r[e];if(t){let r=e.replace(`OrThrow`,``);o.generateProcedure(c,t,o.getInputTypeByOpName(r,n),n,e,r,b)}}c.addStatements(`
5
- })`),c.formatText({indentSize:2}),F.push(`
6
- ${t.lowerCaseFirst(n)}: ${s}Router`),x(`Generated tRPC router for model ${n} with ${a.length} actions`)}x(`Generating tRPC app router`),P.addStatements(`
7
- export const appRouter = t.router({${F.join()}});
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_lower_case_first = require('./packages/string-format/src/lower-case-first.cjs');
3
+ const require_pluralize$1 = require('./node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.cjs');
4
+ const require_config = require('./config.cjs');
5
+ const require_project = require('./project.cjs');
6
+ const require_get_prisma_internals = require('./utils/get-prisma-internals.cjs');
7
+ const require_helpers = require('./helpers.cjs');
8
+ const require_write_file_safely = require('./utils/write-file-safely.cjs');
9
+ const require_aggregate_helpers = require('./zod/aggregate-helpers.cjs');
10
+ const require_comments_helpers = require('./zod/comments-helpers.cjs');
11
+ const require_transformer = require('./zod/transformer.cjs');
12
+ const require_generator_helpers = require('./zod/generator-helpers.cjs');
13
+ const require_helpers$1 = require('./zod/helpers.cjs');
14
+ let __stryke_fs_exists = require("@stryke/fs/exists");
15
+ let __stryke_fs_helpers = require("@stryke/fs/helpers");
16
+ let __stryke_path_join_paths = require("@stryke/path/join-paths");
17
+ let node_path = require("node:path");
18
+ node_path = require_rolldown_runtime.__toESM(node_path);
8
19
 
9
- export type AppRouter = typeof appRouter;`),P.formatText({indentSize:2}),x(`Saving tRPC router source files to disk`),await i.project.save(),x(`Storm Software - Prisma tRPC generator completed successfully`)}exports.generate=v;
20
+ //#region src/prisma-generator.ts
21
+ var import_pluralize = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_pluralize$1.default, 1);
22
+ async function generate(options) {
23
+ console.log("[STORM]: Running the Storm Software - Prisma tRPC generator \n");
24
+ const internals = await require_get_prisma_internals.getPrismaInternals();
25
+ console.log(`[STORM]: Validating configuration options \n`);
26
+ const outputDir = internals.parseEnvValue(options.generator.output);
27
+ const results = await require_config.configSchema.safeParseAsync(options.generator.config);
28
+ if (!results.success) throw new Error("Invalid options passed");
29
+ const config = results.data;
30
+ const consoleLog = (message) => {
31
+ if (config.debug) console.log(`[STORM]: ${message} \n`);
32
+ };
33
+ consoleLog(`Using configuration parameters: \n${JSON.stringify(config)}`);
34
+ consoleLog(`Preparing output directory: ${outputDir}`);
35
+ await (0, __stryke_fs_helpers.removeDirectory)(outputDir);
36
+ await (0, __stryke_fs_helpers.createDirectory)(outputDir);
37
+ consoleLog("Finding Prisma Client generator");
38
+ const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
39
+ if (!prismaClientProvider) throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
40
+ consoleLog("Generating Prisma Client DMMF");
41
+ const prismaClientDmmf = await internals.getDMMF({
42
+ datamodel: options.datamodel,
43
+ previewFeatures: prismaClientProvider?.previewFeatures
44
+ });
45
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
46
+ const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;
47
+ const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;
48
+ const enumTypes = prismaClientDmmf.schema.enumTypes;
49
+ const models = prismaClientDmmf.datamodel.models;
50
+ const hiddenModels = [];
51
+ const hiddenFields = [];
52
+ if (config.withZod !== false) {
53
+ consoleLog("Generating Zod schemas");
54
+ const zodOutputPath = internals.parseEnvValue(options.generator.output);
55
+ await (0, __stryke_fs_helpers.createDirectory)(zodOutputPath);
56
+ require_transformer.default.setOutputPath(zodOutputPath);
57
+ if (prismaClientProvider?.isCustomOutput) require_transformer.default.setPrismaClientOutputPath(prismaClientProvider.output?.value);
58
+ await require_helpers.constructZodModels(models, (0, __stryke_path_join_paths.joinPaths)(zodOutputPath, "schemas", "models"), config, options);
59
+ require_comments_helpers.resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
60
+ await require_generator_helpers.generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
61
+ const dataSource = options.datasources?.[0];
62
+ if (!dataSource) throw new Error("No datasource found");
63
+ const previewFeatures = prismaClientProvider?.previewFeatures;
64
+ require_transformer.default.provider = dataSource.provider;
65
+ require_transformer.default.previewFeatures = previewFeatures;
66
+ require_helpers$1.addMissingZodInputObjectTypes(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSource.provider, {
67
+ isGenerateSelect: true,
68
+ isGenerateInclude: true
69
+ });
70
+ const aggregateOperationSupport = require_aggregate_helpers.resolveZodAggregateOperationSupport(inputObjectTypes);
71
+ require_comments_helpers.hideZodInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields);
72
+ await require_generator_helpers.generateZodObjectSchemas(inputObjectTypes);
73
+ await require_generator_helpers.generateZodModelSchemas(models, modelOperations, aggregateOperationSupport);
74
+ await require_generator_helpers.generateZodIndex();
75
+ } else consoleLog("Skipping Zod schemas generation");
76
+ const queries = [];
77
+ const mutations = [];
78
+ const subscriptions = [];
79
+ prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
80
+ const { model: _model, plural: _plural, ...operations } = modelOperation;
81
+ for (const [opType, opNameWithModel] of Object.entries(operations)) {
82
+ if ([
83
+ "findUnique",
84
+ "findUniqueOrThrow",
85
+ "findFirst",
86
+ "findFirstOrThrow",
87
+ "findRaw",
88
+ "findMany",
89
+ "aggregateRaw",
90
+ "count",
91
+ "aggregate",
92
+ "groupBy"
93
+ ].includes(opType)) queries.push(opNameWithModel);
94
+ if ([
95
+ "createOne",
96
+ "createMany",
97
+ "createManyAndReturn",
98
+ "deleteOne",
99
+ "deleteMany",
100
+ "updateOne",
101
+ "updateMany",
102
+ "updateManyAndReturn",
103
+ "upsertOne"
104
+ ].includes(opType)) mutations.push(opNameWithModel);
105
+ }
106
+ });
107
+ queries.sort();
108
+ mutations.sort();
109
+ subscriptions.sort();
110
+ if (config.withShield && !(typeof config.withShield === "string" && ((0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(outputDir, config.withShield)) || (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(outputDir, `./${config.withShield}.ts`)) || (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(outputDir, config.withShield, "./shield.ts"))))) {
111
+ consoleLog(`Generating tRPC Shield source file to ${outputDir}`);
112
+ await require_write_file_safely.writeFileSafely((0, __stryke_path_join_paths.joinPaths)(outputDir, "./shield.ts"), await require_helpers.constructShield({
113
+ queries,
114
+ mutations,
115
+ subscriptions
116
+ }, config, options, outputDir));
117
+ } else consoleLog("Skipping tRPC Shield generation");
118
+ consoleLog(`Generating tRPC source code for ${models.length} models`);
119
+ if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
120
+ consoleLog(`Generating tRPC options source file to ${outputDir}`);
121
+ await require_write_file_safely.writeFileSafely((0, __stryke_path_join_paths.joinPaths)(outputDir, "./options.ts"), require_helpers.constructDefaultOptions(config, options, outputDir));
122
+ }
123
+ require_helpers.resolveModelsComments(models, hiddenModels);
124
+ consoleLog("Generating tRPC export file");
125
+ await require_helpers.generateTRPCExports(require_project.project.createSourceFile(node_path.default.resolve(outputDir, "trpc.ts"), void 0, { overwrite: true }), config, options, outputDir);
126
+ consoleLog("Generating tRPC app router");
127
+ const appRouter = require_project.project.createSourceFile(node_path.default.resolve(outputDir, "routers", `index.ts`), void 0, { overwrite: true });
128
+ consoleLog("Generating tRPC router imports");
129
+ require_helpers.generateCreateRouterImport({ sourceFile: appRouter });
130
+ const routerStatements = [];
131
+ for (const modelOperation of modelOperations) {
132
+ const { model, ...operations } = modelOperation;
133
+ if (hiddenModels.includes(model)) {
134
+ consoleLog(`Skipping model ${model} as it is hidden`);
135
+ continue;
136
+ }
137
+ if (!model) {
138
+ consoleLog(`Skipping model ${model} as it is not defined`);
139
+ continue;
140
+ }
141
+ const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.some((generateModelAction) => generateModelAction === opType.replace("One", "")));
142
+ if (!modelActions.length) {
143
+ consoleLog(`Skipping model ${model} as it has no actions to generate`);
144
+ continue;
145
+ }
146
+ const plural = (0, import_pluralize.default)(require_lower_case_first.lowerCaseFirst(model));
147
+ consoleLog(`Generating tRPC router for model ${model}`);
148
+ require_helpers.generateRouterImport(appRouter, plural, model);
149
+ const modelRouter = require_project.project.createSourceFile(node_path.default.resolve(outputDir, "routers", `${require_lower_case_first.lowerCaseFirst(model)}.router.ts`), void 0, { overwrite: true });
150
+ require_helpers.generateCreateRouterImport({
151
+ sourceFile: modelRouter,
152
+ config
153
+ });
154
+ if (config.withZod) {
155
+ consoleLog("Generating Zod schemas imports");
156
+ require_helpers.generateRouterSchemaImports(modelRouter, model, modelActions);
157
+ }
158
+ modelRouter.addStatements(`
159
+ export const ${plural}Router = t.router({`);
160
+ for (const opType of modelActions) {
161
+ const opNameWithModel = operations[opType];
162
+ if (opNameWithModel) {
163
+ const baseOpType = opType.replace("OrThrow", "");
164
+ require_helpers.generateProcedure(modelRouter, opNameWithModel, require_helpers.getInputTypeByOpName(baseOpType, model), model, opType, baseOpType, config);
165
+ }
166
+ }
167
+ modelRouter.addStatements(`
168
+ })`);
169
+ modelRouter.formatText({ indentSize: 2 });
170
+ routerStatements.push(`
171
+ ${require_lower_case_first.lowerCaseFirst(model)}: ${plural}Router`);
172
+ consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
173
+ }
174
+ consoleLog("Generating tRPC app router");
175
+ appRouter.addStatements(`
176
+ export const appRouter = t.router({${routerStatements.join()}});
177
+
178
+ export type AppRouter = typeof appRouter;`);
179
+ appRouter.formatText({ indentSize: 2 });
180
+ consoleLog("Saving tRPC router source files to disk");
181
+ await require_project.project.save();
182
+ consoleLog("Storm Software - Prisma tRPC generator completed successfully");
183
+ }
184
+
185
+ //#endregion
186
+ exports.generate = generate;
@@ -1,10 +1,186 @@
1
- import{__toESM as e}from"./_virtual/rolldown_runtime.mjs";import{lowerCaseFirst as t}from"./packages/string-format/src/lower-case-first.mjs";import{require_pluralize as n}from"./node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.mjs";import{configSchema as r}from"./config.mjs";import{project as i}from"./project.mjs";import{getPrismaInternals as a}from"./utils/get-prisma-internals.mjs";import{constructDefaultOptions as o,constructShield as s,constructZodModels as c,generateCreateRouterImport as l,generateProcedure as u,generateRouterImport as d,generateRouterSchemaImports as f,generateTRPCExports as p,getInputTypeByOpName as m,resolveModelsComments as h}from"./helpers.mjs";import{writeFileSafely as g}from"./utils/write-file-safely.mjs";import{resolveZodAggregateOperationSupport as _}from"./zod/aggregate-helpers.mjs";import{hideZodInputObjectTypesAndRelatedFields as v,resolveZodModelsComments as y}from"./zod/comments-helpers.mjs";import b from"./zod/transformer.mjs";import{generateZodEnumSchemas as x,generateZodIndex as S,generateZodModelSchemas as C,generateZodObjectSchemas as w}from"./zod/generator-helpers.mjs";import{addMissingZodInputObjectTypes as T}from"./zod/helpers.mjs";import{existsSync as E}from"@stryke/fs/exists";import{createDirectory as D,removeDirectory as O}from"@stryke/fs/helpers";import{joinPaths as k}from"@stryke/path/join-paths";import A from"node:path";var j=e(n(),1);async function M(e){console.log(`[STORM]: Running the Storm Software - Prisma tRPC generator
2
- `);let n=await a();console.log(`[STORM]: Validating configuration options
3
- `);let M=n.parseEnvValue(e.generator.output),N=await r.safeParseAsync(e.generator.config);if(!N.success)throw Error(`Invalid options passed`);let P=N.data,F=e=>{P.debug&&console.log(`[STORM]: ${e} \n`)};F(`Using configuration parameters: \n${JSON.stringify(P)}`),F(`Preparing output directory: ${M}`),await O(M),await D(M),F(`Finding Prisma Client generator`);let I=e.otherGenerators.find(e=>n.parseEnvValue(e.provider)===`prisma-client-js`);if(!I)throw Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");F(`Generating Prisma Client DMMF`);let L=await n.getDMMF({datamodel:e.datamodel,previewFeatures:I?.previewFeatures}),R=L.mappings.modelOperations,z=L.schema.inputObjectTypes.prisma,B=L.schema.outputObjectTypes.prisma,V=L.schema.enumTypes,H=L.datamodel.models,U=[],W=[];if(P.withZod!==!1){F(`Generating Zod schemas`);let t=n.parseEnvValue(e.generator.output);await D(t),b.setOutputPath(t),I?.isCustomOutput&&b.setPrismaClientOutputPath(I.output?.value),await c(H,k(t,`schemas`,`models`),P,e),y(H,R,V,U,W),await x(V.prisma,V.model);let r=e.datasources?.[0];if(!r)throw Error(`No datasource found`);let i=I?.previewFeatures;b.provider=r.provider,b.previewFeatures=i,T(z,B,H,R,r.provider,{isGenerateSelect:!0,isGenerateInclude:!0});let a=_(z);v(z,U,W),await w(z),await C(H,R,a),await S()}else F(`Skipping Zod schemas generation`);let G=[],K=[],q=[];L.mappings.modelOperations.forEach(e=>{let{model:t,plural:n,...r}=e;for(let[e,t]of Object.entries(r))[`findUnique`,`findUniqueOrThrow`,`findFirst`,`findFirstOrThrow`,`findRaw`,`findMany`,`aggregateRaw`,`count`,`aggregate`,`groupBy`].includes(e)&&G.push(t),[`createOne`,`createMany`,`createManyAndReturn`,`deleteOne`,`deleteMany`,`updateOne`,`updateMany`,`updateManyAndReturn`,`upsertOne`].includes(e)&&K.push(t)}),G.sort(),K.sort(),q.sort(),P.withShield&&!(typeof P.withShield==`string`&&(E(k(M,P.withShield))||E(k(M,`./${P.withShield}.ts`))||E(k(M,P.withShield,`./shield.ts`))))?(F(`Generating tRPC Shield source file to ${M}`),await g(k(M,`./shield.ts`),await s({queries:G,mutations:K,subscriptions:q},P,e,M))):F(`Skipping tRPC Shield generation`),F(`Generating tRPC source code for ${H.length} models`),P.trpcOptions&&typeof P.trpcOptions==`boolean`&&(F(`Generating tRPC options source file to ${M}`),await g(k(M,`./options.ts`),o(P,e,M))),h(H,U),F(`Generating tRPC export file`),await p(i.createSourceFile(A.resolve(M,`trpc.ts`),void 0,{overwrite:!0}),P,e,M),F(`Generating tRPC app router`);let J=i.createSourceFile(A.resolve(M,`routers`,`index.ts`),void 0,{overwrite:!0});F(`Generating tRPC router imports`),l({sourceFile:J});let Y=[];for(let e of R){let{model:n,...r}=e;if(U.includes(n)){F(`Skipping model ${n} as it is hidden`);continue}if(!n){F(`Skipping model ${n} as it is not defined`);continue}let a=Object.keys(r).filter(e=>P.generateModelActions.some(t=>t===e.replace(`One`,``)));if(!a.length){F(`Skipping model ${n} as it has no actions to generate`);continue}let o=(0,j.default)(t(n));F(`Generating tRPC router for model ${n}`),d(J,o,n);let s=i.createSourceFile(A.resolve(M,`routers`,`${t(n)}.router.ts`),void 0,{overwrite:!0});l({sourceFile:s,config:P}),P.withZod&&(F(`Generating Zod schemas imports`),f(s,n,a)),s.addStatements(`
4
- export const ${o}Router = t.router({`);for(let e of a){let t=r[e];if(t){let r=e.replace(`OrThrow`,``);u(s,t,m(r,n),n,e,r,P)}}s.addStatements(`
5
- })`),s.formatText({indentSize:2}),Y.push(`
6
- ${t(n)}: ${o}Router`),F(`Generated tRPC router for model ${n} with ${a.length} actions`)}F(`Generating tRPC app router`),J.addStatements(`
7
- export const appRouter = t.router({${Y.join()}});
1
+ import { __toESM } from "./_virtual/rolldown_runtime.mjs";
2
+ import { lowerCaseFirst } from "./packages/string-format/src/lower-case-first.mjs";
3
+ import { require_pluralize } from "./node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.mjs";
4
+ import { configSchema } from "./config.mjs";
5
+ import { project } from "./project.mjs";
6
+ import { getPrismaInternals } from "./utils/get-prisma-internals.mjs";
7
+ import { constructDefaultOptions, constructShield, constructZodModels, generateCreateRouterImport, generateProcedure, generateRouterImport, generateRouterSchemaImports, generateTRPCExports, getInputTypeByOpName, resolveModelsComments } from "./helpers.mjs";
8
+ import { writeFileSafely } from "./utils/write-file-safely.mjs";
9
+ import { resolveZodAggregateOperationSupport } from "./zod/aggregate-helpers.mjs";
10
+ import { hideZodInputObjectTypesAndRelatedFields, resolveZodModelsComments } from "./zod/comments-helpers.mjs";
11
+ import Transformer from "./zod/transformer.mjs";
12
+ import { generateZodEnumSchemas, generateZodIndex, generateZodModelSchemas, generateZodObjectSchemas } from "./zod/generator-helpers.mjs";
13
+ import { addMissingZodInputObjectTypes } from "./zod/helpers.mjs";
14
+ import { existsSync } from "@stryke/fs/exists";
15
+ import { createDirectory, removeDirectory } from "@stryke/fs/helpers";
16
+ import { joinPaths } from "@stryke/path/join-paths";
17
+ import path from "node:path";
8
18
 
9
- export type AppRouter = typeof appRouter;`),J.formatText({indentSize:2}),F(`Saving tRPC router source files to disk`),await i.save(),F(`Storm Software - Prisma tRPC generator completed successfully`)}export{M as generate};
19
+ //#region src/prisma-generator.ts
20
+ var import_pluralize = /* @__PURE__ */ __toESM(require_pluralize(), 1);
21
+ async function generate(options) {
22
+ console.log("[STORM]: Running the Storm Software - Prisma tRPC generator \n");
23
+ const internals = await getPrismaInternals();
24
+ console.log(`[STORM]: Validating configuration options \n`);
25
+ const outputDir = internals.parseEnvValue(options.generator.output);
26
+ const results = await configSchema.safeParseAsync(options.generator.config);
27
+ if (!results.success) throw new Error("Invalid options passed");
28
+ const config = results.data;
29
+ const consoleLog = (message) => {
30
+ if (config.debug) console.log(`[STORM]: ${message} \n`);
31
+ };
32
+ consoleLog(`Using configuration parameters: \n${JSON.stringify(config)}`);
33
+ consoleLog(`Preparing output directory: ${outputDir}`);
34
+ await removeDirectory(outputDir);
35
+ await createDirectory(outputDir);
36
+ consoleLog("Finding Prisma Client generator");
37
+ const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
38
+ if (!prismaClientProvider) throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
39
+ consoleLog("Generating Prisma Client DMMF");
40
+ const prismaClientDmmf = await internals.getDMMF({
41
+ datamodel: options.datamodel,
42
+ previewFeatures: prismaClientProvider?.previewFeatures
43
+ });
44
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
45
+ const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;
46
+ const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;
47
+ const enumTypes = prismaClientDmmf.schema.enumTypes;
48
+ const models = prismaClientDmmf.datamodel.models;
49
+ const hiddenModels = [];
50
+ const hiddenFields = [];
51
+ if (config.withZod !== false) {
52
+ consoleLog("Generating Zod schemas");
53
+ const zodOutputPath = internals.parseEnvValue(options.generator.output);
54
+ await createDirectory(zodOutputPath);
55
+ Transformer.setOutputPath(zodOutputPath);
56
+ if (prismaClientProvider?.isCustomOutput) Transformer.setPrismaClientOutputPath(prismaClientProvider.output?.value);
57
+ await constructZodModels(models, joinPaths(zodOutputPath, "schemas", "models"), config, options);
58
+ resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
59
+ await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
60
+ const dataSource = options.datasources?.[0];
61
+ if (!dataSource) throw new Error("No datasource found");
62
+ const previewFeatures = prismaClientProvider?.previewFeatures;
63
+ Transformer.provider = dataSource.provider;
64
+ Transformer.previewFeatures = previewFeatures;
65
+ addMissingZodInputObjectTypes(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSource.provider, {
66
+ isGenerateSelect: true,
67
+ isGenerateInclude: true
68
+ });
69
+ const aggregateOperationSupport = resolveZodAggregateOperationSupport(inputObjectTypes);
70
+ hideZodInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields);
71
+ await generateZodObjectSchemas(inputObjectTypes);
72
+ await generateZodModelSchemas(models, modelOperations, aggregateOperationSupport);
73
+ await generateZodIndex();
74
+ } else consoleLog("Skipping Zod schemas generation");
75
+ const queries = [];
76
+ const mutations = [];
77
+ const subscriptions = [];
78
+ prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
79
+ const { model: _model, plural: _plural, ...operations } = modelOperation;
80
+ for (const [opType, opNameWithModel] of Object.entries(operations)) {
81
+ if ([
82
+ "findUnique",
83
+ "findUniqueOrThrow",
84
+ "findFirst",
85
+ "findFirstOrThrow",
86
+ "findRaw",
87
+ "findMany",
88
+ "aggregateRaw",
89
+ "count",
90
+ "aggregate",
91
+ "groupBy"
92
+ ].includes(opType)) queries.push(opNameWithModel);
93
+ if ([
94
+ "createOne",
95
+ "createMany",
96
+ "createManyAndReturn",
97
+ "deleteOne",
98
+ "deleteMany",
99
+ "updateOne",
100
+ "updateMany",
101
+ "updateManyAndReturn",
102
+ "upsertOne"
103
+ ].includes(opType)) mutations.push(opNameWithModel);
104
+ }
105
+ });
106
+ queries.sort();
107
+ mutations.sort();
108
+ subscriptions.sort();
109
+ if (config.withShield && !(typeof config.withShield === "string" && (existsSync(joinPaths(outputDir, config.withShield)) || existsSync(joinPaths(outputDir, `./${config.withShield}.ts`)) || existsSync(joinPaths(outputDir, config.withShield, "./shield.ts"))))) {
110
+ consoleLog(`Generating tRPC Shield source file to ${outputDir}`);
111
+ await writeFileSafely(joinPaths(outputDir, "./shield.ts"), await constructShield({
112
+ queries,
113
+ mutations,
114
+ subscriptions
115
+ }, config, options, outputDir));
116
+ } else consoleLog("Skipping tRPC Shield generation");
117
+ consoleLog(`Generating tRPC source code for ${models.length} models`);
118
+ if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
119
+ consoleLog(`Generating tRPC options source file to ${outputDir}`);
120
+ await writeFileSafely(joinPaths(outputDir, "./options.ts"), constructDefaultOptions(config, options, outputDir));
121
+ }
122
+ resolveModelsComments(models, hiddenModels);
123
+ consoleLog("Generating tRPC export file");
124
+ await generateTRPCExports(project.createSourceFile(path.resolve(outputDir, "trpc.ts"), void 0, { overwrite: true }), config, options, outputDir);
125
+ consoleLog("Generating tRPC app router");
126
+ const appRouter = project.createSourceFile(path.resolve(outputDir, "routers", `index.ts`), void 0, { overwrite: true });
127
+ consoleLog("Generating tRPC router imports");
128
+ generateCreateRouterImport({ sourceFile: appRouter });
129
+ const routerStatements = [];
130
+ for (const modelOperation of modelOperations) {
131
+ const { model, ...operations } = modelOperation;
132
+ if (hiddenModels.includes(model)) {
133
+ consoleLog(`Skipping model ${model} as it is hidden`);
134
+ continue;
135
+ }
136
+ if (!model) {
137
+ consoleLog(`Skipping model ${model} as it is not defined`);
138
+ continue;
139
+ }
140
+ const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.some((generateModelAction) => generateModelAction === opType.replace("One", "")));
141
+ if (!modelActions.length) {
142
+ consoleLog(`Skipping model ${model} as it has no actions to generate`);
143
+ continue;
144
+ }
145
+ const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
146
+ consoleLog(`Generating tRPC router for model ${model}`);
147
+ generateRouterImport(appRouter, plural, model);
148
+ const modelRouter = project.createSourceFile(path.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, { overwrite: true });
149
+ generateCreateRouterImport({
150
+ sourceFile: modelRouter,
151
+ config
152
+ });
153
+ if (config.withZod) {
154
+ consoleLog("Generating Zod schemas imports");
155
+ generateRouterSchemaImports(modelRouter, model, modelActions);
156
+ }
157
+ modelRouter.addStatements(`
158
+ export const ${plural}Router = t.router({`);
159
+ for (const opType of modelActions) {
160
+ const opNameWithModel = operations[opType];
161
+ if (opNameWithModel) {
162
+ const baseOpType = opType.replace("OrThrow", "");
163
+ generateProcedure(modelRouter, opNameWithModel, getInputTypeByOpName(baseOpType, model), model, opType, baseOpType, config);
164
+ }
165
+ }
166
+ modelRouter.addStatements(`
167
+ })`);
168
+ modelRouter.formatText({ indentSize: 2 });
169
+ routerStatements.push(`
170
+ ${lowerCaseFirst(model)}: ${plural}Router`);
171
+ consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
172
+ }
173
+ consoleLog("Generating tRPC app router");
174
+ appRouter.addStatements(`
175
+ export const appRouter = t.router({${routerStatements.join()}});
176
+
177
+ export type AppRouter = typeof appRouter;`);
178
+ appRouter.formatText({ indentSize: 2 });
179
+ consoleLog("Saving tRPC router source files to disk");
180
+ await project.save();
181
+ consoleLog("Storm Software - Prisma tRPC generator completed successfully");
182
+ }
183
+
184
+ //#endregion
185
+ export { generate };
10
186
  //# sourceMappingURL=prisma-generator.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-generator.mjs","names":["hiddenModels: string[]","hiddenFields: string[]","queries: RootType","mutations: RootType","subscriptions: RootType"],"sources":["../src/prisma-generator.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 { existsSync } from \"@stryke/fs/exists\";\nimport { createDirectory, removeDirectory } from \"@stryke/fs/helpers\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { lowerCaseFirst } from \"@stryke/string-format/lower-case-first\";\nimport path from \"node:path\";\nimport pluralize from \"pluralize\";\nimport { configSchema } from \"./config\";\nimport {\n constructDefaultOptions,\n constructShield,\n constructZodModels,\n generateCreateRouterImport,\n generateProcedure,\n generateRouterImport,\n generateRouterSchemaImports,\n generateTRPCExports,\n getInputTypeByOpName,\n resolveModelsComments\n} from \"./helpers\";\nimport { project } from \"./project\";\nimport type { RootType, Writeable } from \"./types\";\nimport { getPrismaInternals } from \"./utils/get-prisma-internals\";\nimport { writeFileSafely } from \"./utils/write-file-safely\";\nimport { resolveZodAggregateOperationSupport } from \"./zod/aggregate-helpers\";\nimport {\n hideZodInputObjectTypesAndRelatedFields,\n resolveZodModelsComments\n} from \"./zod/comments-helpers\";\nimport {\n generateZodEnumSchemas,\n generateZodIndex,\n generateZodModelSchemas,\n generateZodObjectSchemas\n} from \"./zod/generator-helpers\";\nimport { addMissingZodInputObjectTypes } from \"./zod/helpers\";\nimport Transformer from \"./zod/transformer\";\n\nexport async function generate(options: GeneratorOptions) {\n // eslint-disable-next-line no-console\n console.log(\"[STORM]: Running the Storm Software - Prisma tRPC generator \\n\");\n\n const internals = await getPrismaInternals();\n\n // eslint-disable-next-line no-console\n console.log(`[STORM]: Validating configuration options \\n`);\n\n const outputDir = internals.parseEnvValue(\n options.generator.output as EnvValue\n );\n const results = await configSchema.safeParseAsync(options.generator.config);\n if (!results.success) {\n throw new Error(\"Invalid options passed\");\n }\n\n const config = results.data;\n const consoleLog = (message: string) => {\n if (config.debug) {\n // eslint-disable-next-line no-console\n console.log(`[STORM]: ${message} \\n`);\n }\n };\n\n consoleLog(`Using configuration parameters: \\n${JSON.stringify(config)}`);\n\n consoleLog(`Preparing output directory: ${outputDir}`);\n\n await removeDirectory(outputDir);\n await createDirectory(outputDir);\n\n consoleLog(\"Finding Prisma Client generator\");\n\n const prismaClientProvider = options.otherGenerators.find(\n it => internals.parseEnvValue(it.provider) === \"prisma-client-js\"\n );\n if (!prismaClientProvider) {\n throw new Error(\n \"No Prisma Client generator found. Please add `prisma-client-js` to your generator list.\"\n );\n }\n\n consoleLog(\"Generating Prisma Client DMMF\");\n\n const prismaClientDmmf = (await internals.getDMMF({\n datamodel: options.datamodel,\n previewFeatures: prismaClientProvider?.previewFeatures\n })) as Writeable<DMMF.Document>;\n\n const modelOperations = prismaClientDmmf.mappings\n .modelOperations as DMMF.ModelMapping[];\n const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes\n .prisma as DMMF.InputType[];\n const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes\n .prisma as DMMF.OutputType[];\n const enumTypes = prismaClientDmmf.schema.enumTypes;\n const models = prismaClientDmmf.datamodel.models as Writeable<DMMF.Model[]>;\n const hiddenModels: string[] = [];\n const hiddenFields: string[] = [];\n\n if (config.withZod !== false) {\n consoleLog(\"Generating Zod schemas\");\n\n const zodOutputPath = internals.parseEnvValue(options.generator.output!);\n\n await createDirectory(zodOutputPath);\n Transformer.setOutputPath(zodOutputPath);\n\n if (prismaClientProvider?.isCustomOutput) {\n Transformer.setPrismaClientOutputPath(\n prismaClientProvider.output?.value as string\n );\n }\n\n await constructZodModels(\n models,\n joinPaths(zodOutputPath, \"schemas\", \"models\"),\n config,\n options\n );\n\n resolveZodModelsComments(\n models,\n modelOperations,\n enumTypes,\n hiddenModels,\n hiddenFields\n );\n\n await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model!);\n\n const dataSource = options.datasources?.[0];\n if (!dataSource) {\n throw new Error(\"No datasource found\");\n }\n\n const previewFeatures = prismaClientProvider?.previewFeatures;\n Transformer.provider = dataSource.provider;\n Transformer.previewFeatures = previewFeatures;\n\n addMissingZodInputObjectTypes(\n inputObjectTypes,\n outputObjectTypes,\n models,\n modelOperations,\n dataSource.provider,\n {\n isGenerateSelect: true,\n isGenerateInclude: true\n }\n );\n\n const aggregateOperationSupport =\n resolveZodAggregateOperationSupport(inputObjectTypes);\n\n hideZodInputObjectTypesAndRelatedFields(\n inputObjectTypes,\n hiddenModels,\n hiddenFields\n );\n\n await generateZodObjectSchemas(\n inputObjectTypes as Writeable<DMMF.InputType[]>\n );\n\n await generateZodModelSchemas(\n models,\n modelOperations,\n aggregateOperationSupport\n );\n await generateZodIndex();\n } else {\n consoleLog(\"Skipping Zod schemas generation\");\n }\n\n const queries: RootType = [];\n const mutations: RootType = [];\n const subscriptions: RootType = [];\n\n prismaClientDmmf.mappings.modelOperations.forEach(modelOperation => {\n const { model: _model, plural: _plural, ...operations } = modelOperation;\n for (const [opType, opNameWithModel] of Object.entries(operations)) {\n if (\n [\n \"findUnique\",\n \"findUniqueOrThrow\",\n \"findFirst\",\n \"findFirstOrThrow\",\n \"findRaw\",\n \"findMany\",\n \"aggregateRaw\",\n \"count\",\n \"aggregate\",\n \"groupBy\"\n ].includes(opType)\n ) {\n queries.push(opNameWithModel as string);\n }\n\n if (\n [\n \"createOne\",\n \"createMany\",\n \"createManyAndReturn\",\n \"deleteOne\",\n \"deleteMany\",\n \"updateOne\",\n \"updateMany\",\n \"updateManyAndReturn\",\n \"upsertOne\"\n ].includes(opType)\n ) {\n mutations.push(opNameWithModel as string);\n }\n }\n });\n\n queries.sort();\n mutations.sort();\n subscriptions.sort();\n\n if (\n config.withShield &&\n !(\n typeof config.withShield === \"string\" &&\n (existsSync(joinPaths(outputDir, config.withShield)) ||\n existsSync(joinPaths(outputDir, `./${config.withShield}.ts`)) ||\n existsSync(joinPaths(outputDir, config.withShield, \"./shield.ts\")))\n )\n ) {\n consoleLog(`Generating tRPC Shield source file to ${outputDir}`);\n await writeFileSafely(\n joinPaths(outputDir, \"./shield.ts\"),\n await constructShield(\n { queries, mutations, subscriptions },\n config,\n options,\n outputDir\n )\n );\n } else {\n consoleLog(\"Skipping tRPC Shield generation\");\n }\n\n consoleLog(`Generating tRPC source code for ${models.length} models`);\n\n if (config.trpcOptions && typeof config.trpcOptions === \"boolean\") {\n consoleLog(`Generating tRPC options source file to ${outputDir}`);\n\n await writeFileSafely(\n joinPaths(outputDir, \"./options.ts\"),\n constructDefaultOptions(config, options, outputDir)\n );\n }\n\n resolveModelsComments(models, hiddenModels);\n\n consoleLog(\"Generating tRPC export file\");\n const trpcExports = project.createSourceFile(\n path.resolve(outputDir, \"trpc.ts\"),\n undefined,\n { overwrite: true }\n );\n\n await generateTRPCExports(trpcExports, config, options, outputDir);\n\n consoleLog(\"Generating tRPC app router\");\n const appRouter = project.createSourceFile(\n path.resolve(outputDir, \"routers\", `index.ts`),\n undefined,\n { overwrite: true }\n );\n\n consoleLog(\"Generating tRPC router imports\");\n\n generateCreateRouterImport({\n sourceFile: appRouter\n });\n\n const routerStatements = [];\n\n for (const modelOperation of modelOperations) {\n const { model, ...operations } = modelOperation;\n if (hiddenModels.includes(model)) {\n consoleLog(`Skipping model ${model} as it is hidden`);\n continue;\n }\n if (!model) {\n consoleLog(`Skipping model ${model} as it is not defined`);\n continue;\n }\n\n const modelActions = Object.keys(operations).filter<DMMF.ModelAction>(\n (opType): opType is DMMF.ModelAction =>\n // eslint-disable-next-line unicorn/prefer-includes\n config.generateModelActions.some(\n generateModelAction =>\n generateModelAction === opType.replace(\"One\", \"\")\n )\n );\n if (!modelActions.length) {\n consoleLog(`Skipping model ${model} as it has no actions to generate`);\n continue;\n }\n\n const plural = pluralize(lowerCaseFirst(model));\n\n consoleLog(`Generating tRPC router for model ${model}`);\n\n generateRouterImport(appRouter, plural, model);\n const modelRouter = project.createSourceFile(\n path.resolve(outputDir, \"routers\", `${lowerCaseFirst(model)}.router.ts`),\n undefined,\n { overwrite: true }\n );\n\n generateCreateRouterImport({\n sourceFile: modelRouter,\n config\n });\n\n if (config.withZod) {\n consoleLog(\"Generating Zod schemas imports\");\n generateRouterSchemaImports(modelRouter, model, modelActions);\n }\n\n modelRouter.addStatements(/* ts */ `\n export const ${plural}Router = t.router({`);\n\n for (const opType of modelActions) {\n const opNameWithModel = operations[opType];\n if (opNameWithModel) {\n const baseOpType = opType.replace(\"OrThrow\", \"\");\n\n generateProcedure(\n modelRouter,\n opNameWithModel,\n getInputTypeByOpName(baseOpType, model)!,\n model,\n opType,\n baseOpType,\n config\n );\n }\n }\n\n modelRouter.addStatements(/* ts */ `\n })`);\n\n modelRouter.formatText({ indentSize: 2 });\n routerStatements.push(/* ts */ `\n ${lowerCaseFirst(model)}: ${plural}Router`);\n\n consoleLog(\n `Generated tRPC router for model ${model} with ${modelActions.length} actions`\n );\n }\n\n consoleLog(\"Generating tRPC app router\");\n\n appRouter.addStatements(/* ts */ `\nexport const appRouter = t.router({${routerStatements.join()}});\n\nexport type AppRouter = typeof appRouter;`);\n\n appRouter.formatText({ indentSize: 2 });\n\n consoleLog(\"Saving tRPC router source files to disk\");\n\n await project.save();\n\n consoleLog(\"Storm Software - Prisma tRPC generator completed successfully\");\n}\n"],"mappings":"i5CA4DA,eAAsB,EAAS,EAA2B,CAExD,QAAQ,IAAI;EAAiE,CAE7E,IAAM,EAAY,MAAM,GAAoB,CAG5C,QAAQ,IAAI;EAA+C,CAE3D,IAAM,EAAY,EAAU,cA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,cAAuB;qBAClB,EAAO,qBAAqB,CAE7C,IAAK,IAAM,KAAU,EAAc,CACjC,IAAM,EAAkB,EAAW,GACnC,GAAI,EAAiB,CACnB,IAAM,EAAa,EAAO,QAAQ,UAAW,GAAG,CAEhD,EACE,EACA,EACA,EAAqB,EAAY,EAAM,CACvC,EACA,EACA,EACA,EACD,EAIL,EAAY,cAAuB;QAC/B,CAEJ,EAAY,WAAW,CAAE,WAAY,EAAG,CAAC,CACzC,EAAiB,KAAc;QAC3B,EAAe,EAAM,CAAC,IAAI,EAAO,QAAQ,CAE7C,EACE,mCAAmC,EAAM,QAAQ,EAAa,OAAO,UACtE,CAGH,EAAW,6BAA6B,CAExC,EAAU,cAAuB;qCACE,EAAiB,MAAM,CAAC;;2CAElB,CAEzC,EAAU,WAAW,CAAE,WAAY,EAAG,CAAC,CAEvC,EAAW,0CAA0C,CAErD,MAAM,EAAQ,MAAM,CAEpB,EAAW,gEAAgE"}
1
+ {"version":3,"file":"prisma-generator.mjs","names":["hiddenModels: string[]","hiddenFields: string[]","queries: RootType","mutations: RootType","subscriptions: RootType"],"sources":["../src/prisma-generator.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 { existsSync } from \"@stryke/fs/exists\";\nimport { createDirectory, removeDirectory } from \"@stryke/fs/helpers\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { lowerCaseFirst } from \"@stryke/string-format/lower-case-first\";\nimport path from \"node:path\";\nimport pluralize from \"pluralize\";\nimport { configSchema } from \"./config\";\nimport {\n constructDefaultOptions,\n constructShield,\n constructZodModels,\n generateCreateRouterImport,\n generateProcedure,\n generateRouterImport,\n generateRouterSchemaImports,\n generateTRPCExports,\n getInputTypeByOpName,\n resolveModelsComments\n} from \"./helpers\";\nimport { project } from \"./project\";\nimport type { RootType, Writeable } from \"./types\";\nimport { getPrismaInternals } from \"./utils/get-prisma-internals\";\nimport { writeFileSafely } from \"./utils/write-file-safely\";\nimport { resolveZodAggregateOperationSupport } from \"./zod/aggregate-helpers\";\nimport {\n hideZodInputObjectTypesAndRelatedFields,\n resolveZodModelsComments\n} from \"./zod/comments-helpers\";\nimport {\n generateZodEnumSchemas,\n generateZodIndex,\n generateZodModelSchemas,\n generateZodObjectSchemas\n} from \"./zod/generator-helpers\";\nimport { addMissingZodInputObjectTypes } from \"./zod/helpers\";\nimport Transformer from \"./zod/transformer\";\n\nexport async function generate(options: GeneratorOptions) {\n // eslint-disable-next-line no-console\n console.log(\"[STORM]: Running the Storm Software - Prisma tRPC generator \\n\");\n\n const internals = await getPrismaInternals();\n\n // eslint-disable-next-line no-console\n console.log(`[STORM]: Validating configuration options \\n`);\n\n const outputDir = internals.parseEnvValue(\n options.generator.output as EnvValue\n );\n const results = await configSchema.safeParseAsync(options.generator.config);\n if (!results.success) {\n throw new Error(\"Invalid options passed\");\n }\n\n const config = results.data;\n const consoleLog = (message: string) => {\n if (config.debug) {\n // eslint-disable-next-line no-console\n console.log(`[STORM]: ${message} \\n`);\n }\n };\n\n consoleLog(`Using configuration parameters: \\n${JSON.stringify(config)}`);\n\n consoleLog(`Preparing output directory: ${outputDir}`);\n\n await removeDirectory(outputDir);\n await createDirectory(outputDir);\n\n consoleLog(\"Finding Prisma Client generator\");\n\n const prismaClientProvider = options.otherGenerators.find(\n it => internals.parseEnvValue(it.provider) === \"prisma-client-js\"\n );\n if (!prismaClientProvider) {\n throw new Error(\n \"No Prisma Client generator found. Please add `prisma-client-js` to your generator list.\"\n );\n }\n\n consoleLog(\"Generating Prisma Client DMMF\");\n\n const prismaClientDmmf = (await internals.getDMMF({\n datamodel: options.datamodel,\n previewFeatures: prismaClientProvider?.previewFeatures\n })) as Writeable<DMMF.Document>;\n\n const modelOperations = prismaClientDmmf.mappings\n .modelOperations as DMMF.ModelMapping[];\n const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes\n .prisma as DMMF.InputType[];\n const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes\n .prisma as DMMF.OutputType[];\n const enumTypes = prismaClientDmmf.schema.enumTypes;\n const models = prismaClientDmmf.datamodel.models as Writeable<DMMF.Model[]>;\n const hiddenModels: string[] = [];\n const hiddenFields: string[] = [];\n\n if (config.withZod !== false) {\n consoleLog(\"Generating Zod schemas\");\n\n const zodOutputPath = internals.parseEnvValue(options.generator.output!);\n\n await createDirectory(zodOutputPath);\n Transformer.setOutputPath(zodOutputPath);\n\n if (prismaClientProvider?.isCustomOutput) {\n Transformer.setPrismaClientOutputPath(\n prismaClientProvider.output?.value as string\n );\n }\n\n await constructZodModels(\n models,\n joinPaths(zodOutputPath, \"schemas\", \"models\"),\n config,\n options\n );\n\n resolveZodModelsComments(\n models,\n modelOperations,\n enumTypes,\n hiddenModels,\n hiddenFields\n );\n\n await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model!);\n\n const dataSource = options.datasources?.[0];\n if (!dataSource) {\n throw new Error(\"No datasource found\");\n }\n\n const previewFeatures = prismaClientProvider?.previewFeatures;\n Transformer.provider = dataSource.provider;\n Transformer.previewFeatures = previewFeatures;\n\n addMissingZodInputObjectTypes(\n inputObjectTypes,\n outputObjectTypes,\n models,\n modelOperations,\n dataSource.provider,\n {\n isGenerateSelect: true,\n isGenerateInclude: true\n }\n );\n\n const aggregateOperationSupport =\n resolveZodAggregateOperationSupport(inputObjectTypes);\n\n hideZodInputObjectTypesAndRelatedFields(\n inputObjectTypes,\n hiddenModels,\n hiddenFields\n );\n\n await generateZodObjectSchemas(\n inputObjectTypes as Writeable<DMMF.InputType[]>\n );\n\n await generateZodModelSchemas(\n models,\n modelOperations,\n aggregateOperationSupport\n );\n await generateZodIndex();\n } else {\n consoleLog(\"Skipping Zod schemas generation\");\n }\n\n const queries: RootType = [];\n const mutations: RootType = [];\n const subscriptions: RootType = [];\n\n prismaClientDmmf.mappings.modelOperations.forEach(modelOperation => {\n const { model: _model, plural: _plural, ...operations } = modelOperation;\n for (const [opType, opNameWithModel] of Object.entries(operations)) {\n if (\n [\n \"findUnique\",\n \"findUniqueOrThrow\",\n \"findFirst\",\n \"findFirstOrThrow\",\n \"findRaw\",\n \"findMany\",\n \"aggregateRaw\",\n \"count\",\n \"aggregate\",\n \"groupBy\"\n ].includes(opType)\n ) {\n queries.push(opNameWithModel as string);\n }\n\n if (\n [\n \"createOne\",\n \"createMany\",\n \"createManyAndReturn\",\n \"deleteOne\",\n \"deleteMany\",\n \"updateOne\",\n \"updateMany\",\n \"updateManyAndReturn\",\n \"upsertOne\"\n ].includes(opType)\n ) {\n mutations.push(opNameWithModel as string);\n }\n }\n });\n\n queries.sort();\n mutations.sort();\n subscriptions.sort();\n\n if (\n config.withShield &&\n !(\n typeof config.withShield === \"string\" &&\n (existsSync(joinPaths(outputDir, config.withShield)) ||\n existsSync(joinPaths(outputDir, `./${config.withShield}.ts`)) ||\n existsSync(joinPaths(outputDir, config.withShield, \"./shield.ts\")))\n )\n ) {\n consoleLog(`Generating tRPC Shield source file to ${outputDir}`);\n await writeFileSafely(\n joinPaths(outputDir, \"./shield.ts\"),\n await constructShield(\n { queries, mutations, subscriptions },\n config,\n options,\n outputDir\n )\n );\n } else {\n consoleLog(\"Skipping tRPC Shield generation\");\n }\n\n consoleLog(`Generating tRPC source code for ${models.length} models`);\n\n if (config.trpcOptions && typeof config.trpcOptions === \"boolean\") {\n consoleLog(`Generating tRPC options source file to ${outputDir}`);\n\n await writeFileSafely(\n joinPaths(outputDir, \"./options.ts\"),\n constructDefaultOptions(config, options, outputDir)\n );\n }\n\n resolveModelsComments(models, hiddenModels);\n\n consoleLog(\"Generating tRPC export file\");\n const trpcExports = project.createSourceFile(\n path.resolve(outputDir, \"trpc.ts\"),\n undefined,\n { overwrite: true }\n );\n\n await generateTRPCExports(trpcExports, config, options, outputDir);\n\n consoleLog(\"Generating tRPC app router\");\n const appRouter = project.createSourceFile(\n path.resolve(outputDir, \"routers\", `index.ts`),\n undefined,\n { overwrite: true }\n );\n\n consoleLog(\"Generating tRPC router imports\");\n\n generateCreateRouterImport({\n sourceFile: appRouter\n });\n\n const routerStatements = [];\n\n for (const modelOperation of modelOperations) {\n const { model, ...operations } = modelOperation;\n if (hiddenModels.includes(model)) {\n consoleLog(`Skipping model ${model} as it is hidden`);\n continue;\n }\n if (!model) {\n consoleLog(`Skipping model ${model} as it is not defined`);\n continue;\n }\n\n const modelActions = Object.keys(operations).filter<DMMF.ModelAction>(\n (opType): opType is DMMF.ModelAction =>\n // eslint-disable-next-line unicorn/prefer-includes\n config.generateModelActions.some(\n generateModelAction =>\n generateModelAction === opType.replace(\"One\", \"\")\n )\n );\n if (!modelActions.length) {\n consoleLog(`Skipping model ${model} as it has no actions to generate`);\n continue;\n }\n\n const plural = pluralize(lowerCaseFirst(model));\n\n consoleLog(`Generating tRPC router for model ${model}`);\n\n generateRouterImport(appRouter, plural, model);\n const modelRouter = project.createSourceFile(\n path.resolve(outputDir, \"routers\", `${lowerCaseFirst(model)}.router.ts`),\n undefined,\n { overwrite: true }\n );\n\n generateCreateRouterImport({\n sourceFile: modelRouter,\n config\n });\n\n if (config.withZod) {\n consoleLog(\"Generating Zod schemas imports\");\n generateRouterSchemaImports(modelRouter, model, modelActions);\n }\n\n modelRouter.addStatements(/* ts */ `\n export const ${plural}Router = t.router({`);\n\n for (const opType of modelActions) {\n const opNameWithModel = operations[opType];\n if (opNameWithModel) {\n const baseOpType = opType.replace(\"OrThrow\", \"\");\n\n generateProcedure(\n modelRouter,\n opNameWithModel,\n getInputTypeByOpName(baseOpType, model)!,\n model,\n opType,\n baseOpType,\n config\n );\n }\n }\n\n modelRouter.addStatements(/* ts */ `\n })`);\n\n modelRouter.formatText({ indentSize: 2 });\n routerStatements.push(/* ts */ `\n ${lowerCaseFirst(model)}: ${plural}Router`);\n\n consoleLog(\n `Generated tRPC router for model ${model} with ${modelActions.length} actions`\n );\n }\n\n consoleLog(\"Generating tRPC app router\");\n\n appRouter.addStatements(/* ts */ `\nexport const appRouter = t.router({${routerStatements.join()}});\n\nexport type AppRouter = typeof appRouter;`);\n\n appRouter.formatText({ indentSize: 2 });\n\n consoleLog(\"Saving tRPC router source files to disk\");\n\n await project.save();\n\n consoleLog(\"Storm Software - Prisma tRPC generator completed successfully\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4DA,eAAsB,SAAS,SAA2B;AAExD,SAAQ,IAAI,iEAAiE;CAE7E,MAAM,YAAY,MAAM,oBAAoB;AAG5C,SAAQ,IAAI,+CAA+C;CAE3D,MAAM,YAAY,UAAU,cAC1B,QAAQ,UAAU,OACnB;CACD,MAAM,UAAU,MAAM,aAAa,eAAe,QAAQ,UAAU,OAAO;AAC3E,KAAI,CAAC,QAAQ,QACX,OAAM,IAAI,MAAM,yBAAyB;CAG3C,MAAM,SAAS,QAAQ;CACvB,MAAM,cAAc,YAAoB;AACtC,MAAI,OAAO,MAET,SAAQ,IAAI,YAAY,QAAQ,KAAK;;AAIzC,YAAW,qCAAqC,KAAK,UAAU,OAAO,GAAG;AAEzE,YAAW,+BAA+B,YAAY;AAEtD,OAAM,gBAAgB,UAAU;AAChC,OAAM,gBAAgB,UAAU;AAEhC,YAAW,kCAAkC;CAE7C,MAAM,uBAAuB,QAAQ,gBAAgB,MACnD,OAAM,UAAU,cAAc,GAAG,SAAS,KAAK,mBAChD;AACD,KAAI,CAAC,qBACH,OAAM,IAAI,MACR,0FACD;AAGH,YAAW,gCAAgC;CAE3C,MAAM,mBAAoB,MAAM,UAAU,QAAQ;EAChD,WAAW,QAAQ;EACnB,iB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AAExC,WAAU,cAAuB;qCACE,iBAAiB,MAAM,CAAC;;2CAElB;AAEzC,WAAU,WAAW,EAAE,YAAY,GAAG,CAAC;AAEvC,YAAW,0CAA0C;AAErD,OAAM,QAAQ,MAAM;AAEpB,YAAW,gEAAgE"}
package/dist/project.cjs CHANGED
@@ -1 +1,15 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`ts-morph`);const n={target:t.ScriptTarget.ESNext,module:t.ModuleKind.ESNext,emitDecoratorMetadata:!0,experimentalDecorators:!0,esModuleInterop:!0},r=new t.Project({compilerOptions:{...n}});exports.project=r;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let ts_morph = require("ts-morph");
3
+
4
+ //#region src/project.ts
5
+ const compilerOptions = {
6
+ target: ts_morph.ScriptTarget.ESNext,
7
+ module: ts_morph.ModuleKind.ESNext,
8
+ emitDecoratorMetadata: true,
9
+ experimentalDecorators: true,
10
+ esModuleInterop: true
11
+ };
12
+ const project = new ts_morph.Project({ compilerOptions: { ...compilerOptions } });
13
+
14
+ //#endregion
15
+ exports.project = project;
package/dist/project.mjs CHANGED
@@ -1,2 +1,15 @@
1
- import{ModuleKind as e,Project as t,ScriptTarget as n}from"ts-morph";const r=new t({compilerOptions:{target:n.ESNext,module:e.ESNext,emitDecoratorMetadata:!0,experimentalDecorators:!0,esModuleInterop:!0}});export{r as project};
1
+ import { ModuleKind, Project, ScriptTarget } from "ts-morph";
2
+
3
+ //#region src/project.ts
4
+ const compilerOptions = {
5
+ target: ScriptTarget.ESNext,
6
+ module: ModuleKind.ESNext,
7
+ emitDecoratorMetadata: true,
8
+ experimentalDecorators: true,
9
+ esModuleInterop: true
10
+ };
11
+ const project = new Project({ compilerOptions: { ...compilerOptions } });
12
+
13
+ //#endregion
14
+ export { project };
2
15
  //# sourceMappingURL=project.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.mjs","names":["compilerOptions: CompilerOptions"],"sources":["../src/project.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.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\nimport type { CompilerOptions } from \"ts-morph\";\nimport { ModuleKind, Project, ScriptTarget } from \"ts-morph\";\n\nconst compilerOptions: CompilerOptions = {\n target: ScriptTarget.ESNext,\n module: ModuleKind.ESNext,\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n esModuleInterop: true\n};\n\nexport const project = new Project({\n compilerOptions: {\n ...compilerOptions\n }\n});\n"],"mappings":"qEA4BA,MAAa,EAAU,IAAI,EAAQ,CACjC,gBAAiB,CARjB,OAAQ,EAAa,OACrB,OAAQ,EAAW,OACnB,sBAAuB,GACvB,uBAAwB,GACxB,gBAAiB,GAMhB,CACF,CAAC"}
1
+ {"version":3,"file":"project.mjs","names":["compilerOptions: CompilerOptions"],"sources":["../src/project.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.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\nimport type { CompilerOptions } from \"ts-morph\";\nimport { ModuleKind, Project, ScriptTarget } from \"ts-morph\";\n\nconst compilerOptions: CompilerOptions = {\n target: ScriptTarget.ESNext,\n module: ModuleKind.ESNext,\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n esModuleInterop: true\n};\n\nexport const project = new Project({\n compilerOptions: {\n ...compilerOptions\n }\n});\n"],"mappings":";;;AAoBA,MAAMA,kBAAmC;CACvC,QAAQ,aAAa;CACrB,QAAQ,WAAW;CACnB,uBAAuB;CACvB,wBAAwB;CACxB,iBAAiB;CAClB;AAED,MAAa,UAAU,IAAI,QAAQ,EACjC,iBAAiB,EACf,GAAG,iBACJ,EACF,CAAC"}
@@ -1 +1,25 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`);let t=require(`prettier`);t=e.__toESM(t);async function n(e){let n=await t.default.resolveConfig(process.cwd()),r=n;return n||(r={trailingComma:`all`,tabWidth:2,printWidth:80,bracketSpacing:!0,semi:!0,singleQuote:!0,useTabs:!1}),await t.default.format(e,{...r,parser:`typescript`})}exports.formatFile=n;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let prettier = require("prettier");
3
+ prettier = require_rolldown_runtime.__toESM(prettier);
4
+
5
+ //#region src/utils/format-file.ts
6
+ async function formatFile(content) {
7
+ const options = await prettier.default.resolveConfig(process.cwd());
8
+ let formatOptions = options;
9
+ if (!options) formatOptions = {
10
+ trailingComma: "all",
11
+ tabWidth: 2,
12
+ printWidth: 80,
13
+ bracketSpacing: true,
14
+ semi: true,
15
+ singleQuote: true,
16
+ useTabs: false
17
+ };
18
+ return await prettier.default.format(content, {
19
+ ...formatOptions,
20
+ parser: "typescript"
21
+ });
22
+ }
23
+
24
+ //#endregion
25
+ exports.formatFile = formatFile;