@stryke/prisma-trpc-generator 0.1.0 → 0.2.1

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 (41) hide show
  1. package/README.md +232 -1
  2. package/dist/chunk-6UJ53OQ6.js +19 -0
  3. package/dist/chunk-GQ7ABBSV.js +160 -0
  4. package/dist/chunk-LVOPI6NH.js +18 -0
  5. package/dist/chunk-RYVIOFDO.js +333 -0
  6. package/dist/chunk-SHUYVCID.js +6 -0
  7. package/dist/chunk-V6DNCMCB.js +31 -0
  8. package/dist/config.cjs +52 -18
  9. package/dist/config.js +7 -0
  10. package/dist/generator.cjs +1 -3
  11. package/dist/generator.js +7 -0
  12. package/dist/helpers.cjs +360 -206
  13. package/dist/helpers.js +29 -0
  14. package/dist/index.cjs +520 -8
  15. package/dist/index.js +6 -0
  16. package/dist/prisma-generator.cjs +502 -77
  17. package/dist/prisma-generator.js +10 -0
  18. package/dist/project.cjs +36 -13
  19. package/dist/project.js +7 -0
  20. package/package.json +59 -146
  21. package/dist/config.d.ts +0 -28
  22. package/dist/config.mjs +0 -1
  23. package/dist/generator.d.ts +0 -2
  24. package/dist/generator.mjs +0 -2
  25. package/dist/helpers.d.ts +0 -18
  26. package/dist/helpers.mjs +0 -26
  27. package/dist/index.d.ts +0 -1
  28. package/dist/index.mjs +0 -1
  29. package/dist/prisma-generator.d.ts +0 -2
  30. package/dist/prisma-generator.mjs +0 -6
  31. package/dist/project.d.ts +0 -2
  32. package/dist/project.mjs +0 -1
  33. package/dist/utils/getRelativePath.cjs +0 -18
  34. package/dist/utils/getRelativePath.d.ts +0 -1
  35. package/dist/utils/getRelativePath.mjs +0 -1
  36. package/dist/utils/removeDir.cjs +0 -18
  37. package/dist/utils/removeDir.d.ts +0 -1
  38. package/dist/utils/removeDir.mjs +0 -1
  39. package/dist/utils/uncapitalizeFirstLetter.cjs +0 -8
  40. package/dist/utils/uncapitalizeFirstLetter.d.ts +0 -1
  41. package/dist/utils/uncapitalizeFirstLetter.mjs +0 -1
package/README.md CHANGED
@@ -1,11 +1,73 @@
1
1
  <!-- START header -->
2
+ <!-- prettier-ignore-start -->
3
+ <!-- markdownlint-disable -->
4
+
5
+
6
+ <div align="center"><img src="https://public.storm-cdn.com/storm-banner.gif" width="100%" alt="Storm Software" /></div>
7
+ <br />
8
+
9
+ <div align="center">
10
+ <b>
11
+ <a href="https://stormsoftware.com" target="_blank">Website</a> •
12
+ <a href="https://github.com/storm-software/stryke" target="_blank">GitHub</a> •
13
+ <a href="https://discord.gg/MQ6YVzakM5">Discord</a> • <a href="https://stormsoftware.com/projects/stryke/docs" target="_blank">Docs</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> •
14
+ <a href="https://github.com/storm-software/stryke/issues/new?assignees=&labels=bug&template=bug-report.yml&title=Bug Report%3A+">Report a Bug</a>
15
+ </b>
16
+ </div>
17
+
18
+ <br />
19
+ This package is part of Storm Software's **🌩️ Stryke** monorepo. Stryke packages TypeScript utility packages with shared functionality common to many Storm Software applications.
20
+
21
+ <br />
22
+
23
+ <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
+
25
+ [![Version](https://img.shields.io/badge/version-0.0.1-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
+
27
+ > [!IMPORTANT] This repository, and the apps, libraries, and tools contained
28
+ > within, is still in it's initial development phase. As a result, bugs and
29
+ > issues are expected with it's usage. When the main development phase
30
+ > completes, a proper release will be performed, the packages will be availible
31
+ > through NPM (and other distributions), and this message will be removed.
32
+ > However, in the meantime, please feel free to report any issues you may come
33
+ > across.
34
+
35
+ <div align="center">
36
+ <b>Be sure to ⭐ this repository on <a href="https://github.com/storm-software/stryke" target="_blank">GitHub</a> so you can keep up to date on any daily progress!</b>
37
+ </div>
38
+
39
+ <br />
40
+
41
+
42
+ <!-- markdownlint-restore -->
43
+ <!-- prettier-ignore-end -->
44
+
2
45
  <!-- END header -->
3
46
 
4
47
  # prisma-trpc-generator
5
48
 
6
- A fork of the prisma-trpc-generator code to work in ESM. Huge thanks to [prisma-trpc-generator](https://github.com/omar-dulaimi/prisma-trpc-generator) for the great work.
49
+ A fork of the prisma-trpc-generator code to work in ESM. Huge thanks to
50
+ [prisma-trpc-generator](https://github.com/omar-dulaimi/prisma-trpc-generator)
51
+ for the great work.
7
52
 
8
53
  <!-- START doctoc -->
54
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55
+ ## Table of Contents
56
+
57
+ - [Installing](#installing)
58
+ - [Reduced Package Size](#reduced-package-size)
59
+ - [Development](#development)
60
+ - [Building](#building)
61
+ - [Running unit tests](#running-unit-tests)
62
+ - [Linting](#linting)
63
+ - [Storm Workspaces](#storm-workspaces)
64
+ - [Roadmap](#roadmap)
65
+ - [Support](#support)
66
+ - [License](#license)
67
+ - [Changelog](#changelog)
68
+ - [Contributing](#contributing)
69
+ - [Contributors](#contributors)
70
+
9
71
  <!-- END doctoc -->
10
72
 
11
73
  ## Installing
@@ -61,4 +123,173 @@ Run `nx lint prisma-trpc-generator` to run [ESLint](https://eslint.org/) on the
61
123
  package.
62
124
 
63
125
  <!-- START footer -->
126
+ <!-- prettier-ignore-start -->
127
+ <!-- markdownlint-disable -->
128
+
129
+
130
+ ## Storm Workspaces
131
+
132
+ Storm workspaces are built using
133
+ <a href="https://nx.dev/" target="_blank">Nx</a>, a set of extensible dev tools
134
+ for monorepos, which helps you develop like Google, Facebook, and Microsoft.
135
+ Building on top of Nx, the Open System provides a set of tools and patterns that
136
+ help you scale your monorepo to many teams while keeping the codebase
137
+ maintainable.
138
+
139
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
140
+ <br />
141
+
142
+ ## Roadmap
143
+
144
+ See the [open issues](https://github.com/storm-software/stryke/issues) for a
145
+ list of proposed features (and known issues).
146
+
147
+ - [Top Feature Requests](https://github.com/storm-software/stryke/issues?q=label%3Aenhancement+is%3Aopen+sort%3Areactions-%2B1-desc)
148
+ (Add your votes using the 👍 reaction)
149
+ - [Top Bugs](https://github.com/storm-software/stryke/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc)
150
+ (Add your votes using the 👍 reaction)
151
+ - [Newest Bugs](https://github.com/storm-software/stryke/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
152
+
153
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
154
+ <br />
155
+
156
+ ## Support
157
+
158
+ Reach out to the maintainer at one of the following places:
159
+
160
+ - [Contact](https://stormsoftware.com/contact)
161
+ - [GitHub discussions](https://github.com/storm-software/stryke/discussions)
162
+ - <support@stormsoftware.com>
163
+
164
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
165
+ <br />
166
+
167
+ ## License
168
+
169
+ This project is licensed under the **Apache License 2.0**. Feel free to edit and
170
+ distribute this template as you like.
171
+
172
+ See [LICENSE](LICENSE) for more information.
173
+
174
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
175
+ <br />
176
+
177
+ ## Changelog
178
+
179
+ This project adheres to
180
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Every release, along
181
+ with the migration instructions, is documented in the [CHANGELOG](CHANGELOG.md)
182
+ file
183
+
184
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
185
+ <br />
186
+
187
+ ## Contributing
188
+
189
+ First off, thanks for taking the time to contribute! Contributions are what
190
+ makes the open-source community such an amazing place to learn, inspire, and
191
+ create. Any contributions you make will benefit everybody else and are **greatly
192
+ appreciated**.
193
+
194
+ Please try to create bug reports that are:
195
+
196
+ - _Reproducible._ Include steps to reproduce the problem.
197
+ - _Specific._ Include as much detail as possible: which version, what
198
+ environment, etc.
199
+ - _Unique._ Do not duplicate existing opened issues.
200
+ - _Scoped to a Single Bug._ One bug per report.
201
+
202
+ Please adhere to this project's [code of conduct](.github/CODE_OF_CONDUCT.md).
203
+
204
+ You can use
205
+ [markdownlint-cli](https://github.com/storm-software/stryke/markdownlint-cli) to
206
+ check for common markdown style inconsistency.
207
+
208
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
209
+ <br />
210
+
211
+ ## Contributors
212
+
213
+ Thanks goes to these wonderful people
214
+ ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
215
+
216
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
217
+
218
+ <table>
219
+ <tbody>
220
+ <tr>
221
+ <td align="center" valign="top" width="14.28%"><a href="http://www.sullypat.com/"><img src="https://avatars.githubusercontent.com/u/99053093?v=4?s=100" width="100px;" alt="Patrick Sullivan"/><br /><sub><b>Patrick Sullivan</b></sub></a><br /><a href="#design-sullivanpj" title="Design">🎨</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Code">💻</a> <a href="#tool-sullivanpj" title="Tools">🔧</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Documentation">📖</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Tests">⚠️</a></td>
222
+ <td align="center" valign="top" width="14.28%"><a href="https://tylerbenning.com/"><img src="https://avatars.githubusercontent.com/u/7265547?v=4?s=100" width="100px;" alt="Tyler Benning"/><br /><sub><b>Tyler Benning</b></sub></a><br /><a href="#design-tbenning" title="Design">🎨</a></td>
223
+ <td align="center" valign="top" width="14.28%"><a href="http://stormsoftware.com"><img src="https://avatars.githubusercontent.com/u/149802440?v=4?s=100" width="100px;" alt="Stormie"/><br /><sub><b>Stormie</b></sub></a><br /><a href="#maintenance-stormie-bot" title="Maintenance">🚧</a></td>
224
+ </tr>
225
+ </tbody>
226
+ <tfoot>
227
+ <tr>
228
+ <td align="center" size="13px" colspan="7">
229
+ <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg" alt="All Contributors">
230
+ <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
231
+ </img>
232
+ </td>
233
+ </tr>
234
+ </tfoot>
235
+ </table>
236
+
237
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
238
+
239
+ This project follows the
240
+ [all-contributors](https://github.com/all-contributors/all-contributors)
241
+ specification. Contributions of any kind welcome!
242
+
243
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
244
+ <br />
245
+
246
+ <hr />
247
+ <br />
248
+
249
+ <div align="center">
250
+ <img src="https://public.storm-cdn.com/logo-banner.png" width="100%" alt="Storm Software" />
251
+ </div>
252
+ <br />
253
+
254
+ <div align="center">
255
+ <a href="https://stormsoftware.com" target="_blank">Website</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> • <a href="https://linkedin.com/in/patrick-sullivan-865526b0" target="_blank">LinkedIn</a> • <a href="https://medium.com/@pat.joseph.sullivan" target="_blank">Medium</a> • <a href="https://github.com/storm-software" target="_blank">GitHub</a> • <a href="https://keybase.io/sullivanp" target="_blank">OpenPGP Key</a>
256
+ </div>
257
+
258
+ <div align="center">
259
+ <b>Fingerprint:</b> 1BD2 7192 7770 2549 F4C9 F238 E6AD C420 DA5C 4C2D
260
+ </div>
261
+ <br />
262
+
263
+ Storm Software is an open source software development organization and creator
264
+ of Acidic, StormStack and StormCloud.
265
+
266
+ Our mission is to make software development more accessible. Our ideal future is
267
+ one where anyone can create software without years of prior development
268
+ experience serving as a barrier to entry. We hope to achieve this via LLMs,
269
+ Generative AI, and intuitive, high-level data modeling/programming languages.
270
+
271
+ Join us on [Discord](https://discord.gg/MQ6YVzakM5) to chat with the team,
272
+ receive release notifications, ask questions, and get involved.
273
+
274
+ If this sounds interesting, and you would like to help us in creating the next
275
+ generation of development tools, please reach out on our
276
+ [website](https://stormsoftware.com/contact) or join our
277
+ [Slack channel](https://join.slack.com/t/storm-software/shared_invite/zt-2gsmk04hs-i6yhK_r6urq0dkZYAwq2pA)!
278
+
279
+ <br />
280
+
281
+ <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/icon-fill.png" alt="Storm Software" width="200px"/></a></div>
282
+ <br />
283
+ <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/visit-us-text.svg" alt="Visit us at stormsoftware.com" height="90px"/></a></div>
284
+
285
+ <br />
286
+
287
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
288
+ <br />
289
+ <br />
290
+
291
+
292
+ <!-- markdownlint-restore -->
293
+ <!-- prettier-ignore-end -->
294
+
64
295
  <!-- END footer -->
@@ -0,0 +1,19 @@
1
+ import {
2
+ generate
3
+ } from "./chunk-GQ7ABBSV.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-SHUYVCID.js";
7
+
8
+ // src/index.ts
9
+ import { generatorHandler } from "@prisma/generator-helper";
10
+ generatorHandler({
11
+ onManifest: /* @__PURE__ */ __name(() => ({
12
+ defaultOutput: "./generated",
13
+ prettyName: "Prisma tRPC Generator",
14
+ requiresGenerators: [
15
+ "prisma-client-js"
16
+ ]
17
+ }), "onManifest"),
18
+ onGenerate: generate
19
+ });
@@ -0,0 +1,160 @@
1
+ import {
2
+ configSchema
3
+ } from "./chunk-V6DNCMCB.js";
4
+ import {
5
+ generateBaseRouter,
6
+ generateCreateRouterImport,
7
+ generateProcedure,
8
+ generateRPCImport,
9
+ generateRouterImport,
10
+ generateRouterSchemaImports,
11
+ generateShieldImport,
12
+ getInputTypeByOpName,
13
+ resolveModelsComments
14
+ } from "./chunk-RYVIOFDO.js";
15
+ import {
16
+ project
17
+ } from "./chunk-LVOPI6NH.js";
18
+ import {
19
+ __name
20
+ } from "./chunk-SHUYVCID.js";
21
+
22
+ // src/prisma-generator.ts
23
+ import { getDMMF, parseEnvValue } from "@prisma/internals";
24
+ import { promises as fs2 } from "node:fs";
25
+ import path2 from "node:path";
26
+ import pluralize from "pluralize";
27
+ import { generate as PrismaTrpcShieldGenerator } from "prisma-trpc-shield-generator/lib/prisma-generator";
28
+ import { generate as PrismaZodGenerator } from "prisma-zod-generator/lib/prisma-generator";
29
+
30
+ // src/utils/removeDir.ts
31
+ import { promises as fs } from "node:fs";
32
+ import path from "node:path";
33
+ async function removeDir(dirPath, onlyContent) {
34
+ const dirEntries = await fs.readdir(dirPath, {
35
+ withFileTypes: true
36
+ });
37
+ await Promise.all(dirEntries.map(async (dirEntry) => {
38
+ const fullPath = path.join(dirPath, dirEntry.name);
39
+ return dirEntry.isDirectory() ? removeDir(fullPath, false) : fs.unlink(fullPath);
40
+ }));
41
+ if (!onlyContent) {
42
+ await fs.rmdir(dirPath);
43
+ }
44
+ }
45
+ __name(removeDir, "removeDir");
46
+
47
+ // src/prisma-generator.ts
48
+ async function generate(options) {
49
+ const outputDir = parseEnvValue(options.generator.output);
50
+ const results = configSchema.safeParse(options.generator.config);
51
+ if (!results.success) throw new Error("Invalid options passed");
52
+ const config = results.data;
53
+ await fs2.mkdir(outputDir, {
54
+ recursive: true
55
+ });
56
+ await removeDir(outputDir, true);
57
+ if (config.withZod) {
58
+ await PrismaZodGenerator(options);
59
+ }
60
+ if (config.withShield === true) {
61
+ const shieldOutputPath = path2.join(outputDir, "./shield");
62
+ await PrismaTrpcShieldGenerator({
63
+ ...options,
64
+ generator: {
65
+ ...options.generator,
66
+ output: {
67
+ ...options.generator.output,
68
+ value: shieldOutputPath
69
+ },
70
+ config: {
71
+ ...options.generator.config,
72
+ contextPath: config.contextPath
73
+ }
74
+ }
75
+ });
76
+ }
77
+ const prismaClientProvider = options.otherGenerators.find((it) => parseEnvValue(it.provider) === "prisma-client-js");
78
+ const prismaClientDmmf = await getDMMF({
79
+ datamodel: options.datamodel,
80
+ previewFeatures: prismaClientProvider.previewFeatures
81
+ });
82
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
83
+ const models = prismaClientDmmf.datamodel.models;
84
+ const hiddenModels = [];
85
+ resolveModelsComments(models, hiddenModels);
86
+ const createRouter = project.createSourceFile(path2.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
87
+ overwrite: true
88
+ });
89
+ generateRPCImport(createRouter);
90
+ if (config.withShield) {
91
+ generateShieldImport(createRouter, options, config.withShield);
92
+ }
93
+ generateBaseRouter(createRouter, config, options);
94
+ createRouter.formatText({
95
+ indentSize: 2
96
+ });
97
+ const appRouter = project.createSourceFile(path2.resolve(outputDir, "routers", `index.ts`), void 0, {
98
+ overwrite: true
99
+ });
100
+ generateCreateRouterImport({
101
+ sourceFile: appRouter
102
+ });
103
+ const routerStatements = [];
104
+ for (const modelOperation of modelOperations) {
105
+ const { model, ...operations } = modelOperation;
106
+ if (hiddenModels.includes(model)) continue;
107
+ const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
108
+ if (!modelActions.length) continue;
109
+ const plural = pluralize(model.toLowerCase());
110
+ generateRouterImport(appRouter, plural, model);
111
+ const modelRouter = project.createSourceFile(path2.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
112
+ overwrite: true
113
+ });
114
+ generateCreateRouterImport({
115
+ sourceFile: modelRouter,
116
+ config
117
+ });
118
+ if (config.withZod) {
119
+ generateRouterSchemaImports(modelRouter, model, modelActions);
120
+ }
121
+ modelRouter.addStatements(
122
+ /* ts */
123
+ `
124
+ export const ${plural}Router = t.router({`
125
+ );
126
+ for (const opType of modelActions) {
127
+ const opNameWithModel = operations[opType];
128
+ const baseOpType = opType.replace("OrThrow", "");
129
+ generateProcedure(modelRouter, opNameWithModel, getInputTypeByOpName(baseOpType, model), model, opType, baseOpType, config);
130
+ }
131
+ modelRouter.addStatements(
132
+ /* ts */
133
+ `
134
+ })`
135
+ );
136
+ modelRouter.formatText({
137
+ indentSize: 2
138
+ });
139
+ routerStatements.push(
140
+ /* ts */
141
+ `
142
+ ${model.toLowerCase()}: ${plural}Router`
143
+ );
144
+ }
145
+ appRouter.addStatements(
146
+ /* ts */
147
+ `
148
+ export const appRouter = t.router({${routerStatements}})
149
+ `
150
+ );
151
+ appRouter.formatText({
152
+ indentSize: 2
153
+ });
154
+ await project.save();
155
+ }
156
+ __name(generate, "generate");
157
+
158
+ export {
159
+ generate
160
+ };
@@ -0,0 +1,18 @@
1
+ // src/project.ts
2
+ import { ModuleKind, Project, ScriptTarget } from "ts-morph";
3
+ var compilerOptions = {
4
+ target: ScriptTarget.ES2019,
5
+ module: ModuleKind.CommonJS,
6
+ emitDecoratorMetadata: true,
7
+ experimentalDecorators: true,
8
+ esModuleInterop: true
9
+ };
10
+ var project = new Project({
11
+ compilerOptions: {
12
+ ...compilerOptions
13
+ }
14
+ });
15
+
16
+ export {
17
+ project
18
+ };