prisma-generator-express 1.14.1 → 1.14.2

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 (2) hide show
  1. package/README.md +15 -15
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -10,7 +10,7 @@ This tool helps you quickly create API endpoints in your Express app using your
10
10
 
11
11
  When you run `npx prisma generate`, it automatically creates two things:
12
12
 
13
- - Service functions that you can import into your Express routes. By default these functions handle CRUD operations and output validation. This behavior can be controlled.
13
+ - Service functions that you can import into your Express routes. By default, these functions handle CRUD operations and output validation. This behavior can be controlled.
14
14
  - Router generator function that lets you select which routes to add to the application and which middlewares to apply.
15
15
 
16
16
  ## Table of Contents
@@ -19,7 +19,7 @@ When you run `npx prisma generate`, it automatically creates two things:
19
19
  - [Basic Usage](#basic-usage)
20
20
  - [Router Generator Usage](#router-generator-usage)
21
21
  - [Request Object Properties](#request-object-properties)
22
- - [Roadmap](#roadmap)
22
+ - [Router Schema](#router-schema)
23
23
 
24
24
  # Installation
25
25
 
@@ -72,7 +72,7 @@ app.use((req, res, next) => {
72
72
  - Here’s how you can use a generated function in your Express app:
73
73
 
74
74
  ```ts
75
- import { UserFindUnique } from './generated/UserFindUnique' // Adjust the path as necessary
75
+ import { UserFindUnique } from './generated/api/UserFindUnique' // Adjust the path as necessary
76
76
  import { FindUniqueUserSchema } from './prisma-zod-generator/schemas/FindUniqueUser.schema' // Adjust the path as necessary
77
77
  import { FindUniqueUserSchemaOutput } from './prisma-zod-generator/schemas/FindUniqueUserOutput.schema' // Adjust the path as necessary
78
78
 
@@ -133,7 +133,7 @@ const addPrisma: RequestHandler = (
133
133
  next: NextFunction,
134
134
  ) => {
135
135
  req.prisma = prisma
136
- // req.omitOutputValidation = true (not required if you use `select` instead of `include`)
136
+ // req.omitOutputValidation = true (output validation is not required if you use `select` instead of `include`)
137
137
  next()
138
138
  }
139
139
 
@@ -166,12 +166,12 @@ const afterFindFirst: RequestHandler = (
166
166
  * For generated route the middleware order will be as follows:
167
167
  * 1. Query parser (kicks in for GET requests)
168
168
  * 2. Custom middlewares: config.{method}.before[]
169
- * 3. Input validator middleware (Optional): config.{method}.input
169
+ * 3. Input validator middleware (Optional): config.{method}.input. For GET request validates `req.query`, for others - `req.body`
170
170
  * 4. Generated middleware
171
171
  * 5. Output validator middleware: config.{method}.input
172
172
  * 6. Custom middlewares: config.{method}.after[] (not available if req.passToNext is falsy)
173
173
  */
174
- const someRouterConfig: RouteConfig<RequestHandler> = {
174
+ const userAccounRouterConfig: RouteConfig<RequestHandler> = {
175
175
  FindFirst: {
176
176
  before: [beforeFindFirst],
177
177
  after: [afterFindFirst],
@@ -194,7 +194,7 @@ const someRouterConfig: RouteConfig<RequestHandler> = {
194
194
  }
195
195
 
196
196
  app.use(addPrisma)
197
- app.use(UserAccountRouter(someRouterConfig))
197
+ app.use(UserAccountRouter(userAccounRouterConfig))
198
198
 
199
199
  app.listen(3000, () => {
200
200
  console.log('Server is running on http://localhost:3000')
@@ -208,9 +208,8 @@ The following properties can be attached to the `req` object to control the beha
208
208
  | Property | Type | Description |
209
209
  | ---------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
210
210
  | `prisma` | PrismaClient | An instance of PrismaClient that allows the middleware to interact with your database. |
211
- | `passToNext` | boolean | Optional, if `true` - the result of a Prisma request will be passed to a next middleware as `if (req.locals) req.locals.data` |
212
- | `query` | Object | A structured object that conforms to Prisma's API for the selected method. |
213
- | `outputValidation` | ZodTypeAny | (Optional) A Zod schema used to validate the data returned from the Prisma query before sending it to the client. This helps ensure the response adheres to expected data formats. |
211
+ | `passToNext` | boolean | Optional, if `true` - the result of a Prisma request will be passed to the next middleware as `if (req.locals) req.locals.data` |
212
+ | `outputValidation` | ZodTypeAny | (Optional) A Zod schema used to validate the data returned from the Prisma query before sending it to the client. |
214
213
  | `omitOutputValidation` | Boolean | (Optional) A flag that, if set to `true`, disables output validation even if a Zod schema is provided. |
215
214
 
216
215
  ## Router Schema
@@ -219,7 +218,10 @@ The following properties can be attached to the `req` object to control the beha
219
218
  | ------------ | -------- | ------------ |
220
219
  | `findUnique` | `GET` | `/:id` |
221
220
  | `findFirst` | `GET` | `/first` |
222
- | `FindFirst` | `GET` | `/` |
221
+ | `findMany` | `GET` | `/` |
222
+ | `aggregate` | `GET` | `/aggregate` |
223
+ | `count` | `GET` | `/count` |
224
+ | `groupBy` | `GET` | `/groupby` |
223
225
  | `create` | `POST` | `/` |
224
226
  | `createMany` | `POST` | `/many` |
225
227
  | `update` | `PUT` | `/` |
@@ -227,9 +229,7 @@ The following properties can be attached to the `req` object to control the beha
227
229
  | `upsert` | `PATCH` | `/` |
228
230
  | `delete` | `DELETE` | `/` |
229
231
  | `deleteMany` | `DELETE` | `/many` |
230
- | `aggregate` | `GET` | `/aggregate` |
231
- | `count` | `GET` | `/count` |
232
- | `groupBy` | `GET` | `/groupby` |
232
+
233
233
 
234
234
  ## Helper functions
235
235
 
@@ -248,7 +248,7 @@ interface ValidatorOptions {
248
248
 
249
249
  ### encodeQueryParams(params: Params)
250
250
 
251
- Can be used on frontend to encode Prisma compatible queries. Alternatively `qs` can be used, but it probably won't work with `OR: [{ blah: false }, { blah: null }]` or some other edge cases.
251
+ It can be used on the frontend to encode Prisma-compatible queries. Alternatively `qs` can be used, but it probably won't work with `OR: [{ blah: false }, { blah: null }]` or some other edge cases.
252
252
 
253
253
  ```ts
254
254
  type RecursiveUrlParams = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-generator-express",
3
3
  "description": "Prisma generator of Express CRUD API",
4
- "version": "1.14.1",
4
+ "version": "1.14.2",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -35,12 +35,12 @@
35
35
  "@types/express": "^4.17.21",
36
36
  "@types/jest": "29.5.12",
37
37
  "@types/lodash": "^4.17.4",
38
- "@types/node": "20.12.12",
38
+ "@types/node": "20.12.13",
39
39
  "@types/prettier": "3.0.0",
40
40
  "jest": "29.7.0",
41
41
  "prisma": "5.14.0",
42
42
  "semantic-release": "^23.1.1",
43
- "ts-jest": "29.1.3",
43
+ "ts-jest": "29.1.4",
44
44
  "typescript": "5.4.5"
45
45
  },
46
46
  "homepage": "https://github.com/multipliedtwice/prisma-generator-express/blob/master/README.md",