temba 0.12.20 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -43
- package/config/index.d.ts +4 -4
- package/config/index.js +13 -14
- package/config/index.js.map +1 -1
- package/index.js +0 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/routes/delete.d.ts +1 -1
- package/routes/delete.js +2 -2
- package/routes/delete.js.map +1 -1
- package/routes/get.d.ts +1 -1
- package/routes/get.js +6 -10
- package/routes/get.js.map +1 -1
- package/routes/interceptors.d.ts +3 -0
- package/routes/{validator.js → interceptors.js} +5 -5
- package/routes/interceptors.js.map +1 -0
- package/routes/patch.d.ts +2 -2
- package/routes/patch.js +8 -8
- package/routes/patch.js.map +1 -1
- package/routes/post.d.ts +2 -2
- package/routes/post.js +5 -5
- package/routes/post.js.map +1 -1
- package/routes/put.d.ts +2 -2
- package/routes/put.js +8 -8
- package/routes/put.js.map +1 -1
- package/routes/routes.d.ts +1 -1
- package/routes/routes.js +4 -4
- package/routes/routes.js.map +1 -1
- package/routes/types.d.ts +16 -6
- package/urls/urlMiddleware.d.ts +1 -1
- package/urls/urlMiddleware.js +4 -5
- package/urls/urlMiddleware.js.map +1 -1
- package/errors/errors.d.ts +0 -10
- package/errors/errors.js +0 -34
- package/errors/errors.js.map +0 -1
- package/routes/validator.d.ts +0 -3
- package/routes/validator.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ Powered by NodeJS, Express and MongoDB.
|
|
|
16
16
|
|
|
17
17
|
This project is inspired by the fantastic [json-server](https://github.com/typicode/json-server) project, but instead of a JSON file Temba uses a real database. The goal, however, is the same: Get you started with a REST API very quickly.
|
|
18
18
|
|
|
19
|
+
No need for any coding, unless you want to opt-out of the defaults, or want to do more customization.
|
|
20
|
+
|
|
19
21
|
## Table of contents
|
|
20
22
|
|
|
21
23
|
[Temba?](#temba-1)
|
|
@@ -26,6 +28,8 @@ This project is inspired by the fantastic [json-server](https://github.com/typic
|
|
|
26
28
|
|
|
27
29
|
[Usage](#usage)
|
|
28
30
|
|
|
31
|
+
[Config settings overview](#config-settings-overview)
|
|
32
|
+
|
|
29
33
|
## Temba?
|
|
30
34
|
|
|
31
35
|
> _"Temba, at REST"_
|
|
@@ -57,7 +61,7 @@ This command clones the [Temba-starter](https://github.com/bouwe77/temba-starter
|
|
|
57
61
|
|
|
58
62
|
Once the server is running, you can issue any HTTP request, and it probably will just work, but [learn more here](#what-temba-does).
|
|
59
63
|
|
|
60
|
-
###
|
|
64
|
+
### Adding to an existing app
|
|
61
65
|
|
|
62
66
|
Alternatively, add Temba to your app manually:
|
|
63
67
|
|
|
@@ -77,7 +81,7 @@ server.listen(port, () => {
|
|
|
77
81
|
|
|
78
82
|
### Configuration
|
|
79
83
|
|
|
80
|
-
|
|
84
|
+
To opt-out or customize Temba's workings, pass a `config` object to the `create` function. Learn more in the [Usage](#usage) section, or check out the [config settings](#config-settings-overview).
|
|
81
85
|
|
|
82
86
|
## What Temba does
|
|
83
87
|
|
|
@@ -109,7 +113,7 @@ Temba supports JSON only.
|
|
|
109
113
|
|
|
110
114
|
Request bodies sent with a `POST`, `PATCH`, and `PUT` requests are valid when the request body is either empty, or when it's valid formatted JSON. Adding a `Content-Type: application/json` header is required. If you send a request with invalid formatted JSON, a `400 Bad Request` response is returned.
|
|
111
115
|
|
|
112
|
-
Any valid formatted JSON is accepted and stored. If you want to validate or even change the JSON in the request bodies, check out the [`
|
|
116
|
+
Any valid formatted JSON is accepted and stored. If you want to validate or even change the JSON in the request bodies, check out the [`requestBodyInterceptor`](#request-body-validation-or-mutation) callbacks.
|
|
113
117
|
|
|
114
118
|
IDs are auto generated when creating resources. IDs in the JSON request body are ignored for any request.
|
|
115
119
|
|
|
@@ -193,18 +197,18 @@ POST /movies
|
|
|
193
197
|
}
|
|
194
198
|
```
|
|
195
199
|
|
|
196
|
-
You can even omit a request body when doing a `POST`, `PATCH`, or `PUT`. If you don't want that, and want to have proper validation, use the `
|
|
200
|
+
You can even omit a request body when doing a `POST`, `PATCH`, or `PUT`. If you don't want that, and want to have proper validation, use the `requestBodyInterceptor` config setting:
|
|
197
201
|
|
|
198
202
|
```js
|
|
199
203
|
const config = {
|
|
200
|
-
|
|
201
|
-
post: (resourceName, requestBody) => {
|
|
204
|
+
requestBodyInterceptor: {
|
|
205
|
+
post: ({ resourceName, requestBody }) => {
|
|
202
206
|
// Validate, or even change the requestBody
|
|
203
207
|
},
|
|
204
|
-
put: (resourceName, requestBody) => {
|
|
208
|
+
put: ({ resourceName, requestBody }) => {
|
|
205
209
|
// Validate, or even change the requestBody
|
|
206
210
|
},
|
|
207
|
-
patch: (resourceName, requestBody) => {
|
|
211
|
+
patch: ({ resourceName, requestBody }) => {
|
|
208
212
|
// Validate, or even change the requestBody
|
|
209
213
|
},
|
|
210
214
|
},
|
|
@@ -213,9 +217,9 @@ const config = {
|
|
|
213
217
|
const server = temba.create(config)
|
|
214
218
|
```
|
|
215
219
|
|
|
216
|
-
The `
|
|
220
|
+
The `requestBodyInterceptor` is an object with a `post`, and/or `patch`, and/or `put` field, which contains the callback function you want Temba to call before the JSON is saved to the database.
|
|
217
221
|
|
|
218
|
-
The callback function receives
|
|
222
|
+
The callback function receives an object containing the `resourceName`, which for example is `movies` if you request `POST /movies`, and the `requestBody`, which is the JSON object of the request body.
|
|
219
223
|
|
|
220
224
|
Your callback function can return the following things:
|
|
221
225
|
|
|
@@ -227,8 +231,8 @@ Example:
|
|
|
227
231
|
|
|
228
232
|
```js
|
|
229
233
|
const config = {
|
|
230
|
-
|
|
231
|
-
post: (resourceName, requestBody) => {
|
|
234
|
+
requestBodyInterceptor: {
|
|
235
|
+
post: ({ resourceName, requestBody }) => {
|
|
232
236
|
// Do not allow Pokemons to be created: 400 Bad Request
|
|
233
237
|
if (resourceName === 'pokemons') return 'You are not allowed to create new Pokemons'
|
|
234
238
|
|
|
@@ -244,13 +248,13 @@ const config = {
|
|
|
244
248
|
const server = temba.create(config)
|
|
245
249
|
```
|
|
246
250
|
|
|
247
|
-
|
|
251
|
+
### Response body interception
|
|
248
252
|
|
|
249
|
-
To change the response body of a `GET` request, configure a `responseBodyInterceptor`, and return the updated response body:
|
|
253
|
+
To change the response body of a `GET` request, before it's being sent to the client, configure a `responseBodyInterceptor`, and return the updated response body:
|
|
250
254
|
|
|
251
255
|
```js
|
|
252
256
|
const config = {
|
|
253
|
-
responseBodyInterceptor: (resourceName, responseBody, id) => {
|
|
257
|
+
responseBodyInterceptor: ({ resourceName, responseBody, id }) => {
|
|
254
258
|
if (resourceName === 'movies') {
|
|
255
259
|
if (id) {
|
|
256
260
|
// responseBody is an object
|
|
@@ -274,7 +278,7 @@ const config = {
|
|
|
274
278
|
const server = temba.create(config)
|
|
275
279
|
```
|
|
276
280
|
|
|
277
|
-
`responseBodyInterceptor` is a callback function that provides the `resourceName`, `responseBody`, and the `id`. Depending on whether it's a collection or item request, the `responseBody` is either an array or object, and the `id' can be `undefined`.
|
|
281
|
+
`responseBodyInterceptor` is a callback function that provides an object containing the `resourceName`, `responseBody`, and the `id`. Depending on whether it's a collection or item request, the `responseBody` is either an array or object, and the `id' can be `undefined`.
|
|
278
282
|
|
|
279
283
|
In the example above we check for the `id` being defined, but a runtime check to determine the type of `responseBody` would also suffice.
|
|
280
284
|
|
|
@@ -284,7 +288,7 @@ If you don't return anything, the response body will be sent as-is.
|
|
|
284
288
|
|
|
285
289
|
The `responseBodyInterceptor` will only be called when the response was successful, i.e. a `200 OK` status code.
|
|
286
290
|
|
|
287
|
-
|
|
291
|
+
### Custom router
|
|
288
292
|
|
|
289
293
|
Although `temba.create()` returns an Express instance, adding your own routes, as you would normally do with Express, is not possible:
|
|
290
294
|
|
|
@@ -297,7 +301,7 @@ server.get('/hello', (req, res) => {
|
|
|
297
301
|
})
|
|
298
302
|
```
|
|
299
303
|
|
|
300
|
-
The reason is that Temba is in charge of all Express routes, to make sure only
|
|
304
|
+
The reason is that Temba is in charge of all Express routes, to make sure only _resource routes_ can be overruled by a custom router. To add your own routes, create an Express router, and configure it as a `customRouter`:
|
|
301
305
|
|
|
302
306
|
```js
|
|
303
307
|
// Example code of how to create an Express router, from the official Express docs at https://expressjs.com/en/guide/routing.html:
|
|
@@ -357,7 +361,7 @@ const server = temba.create(config)
|
|
|
357
361
|
- `/movies` will return a `404 Not Found`, because of `apiPrefix`
|
|
358
362
|
- `/api/movies` will return movies, handled by Temba
|
|
359
363
|
|
|
360
|
-
|
|
364
|
+
## Config settings overview
|
|
361
365
|
|
|
362
366
|
Configuring Temba is optional, it already works out of the box.
|
|
363
367
|
|
|
@@ -372,14 +376,14 @@ const config = {
|
|
|
372
376
|
customRouter: router,
|
|
373
377
|
cacheControl: 'public, max-age=300',
|
|
374
378
|
delay: 500,
|
|
375
|
-
|
|
376
|
-
post: (resourceName, requestBody) => {
|
|
379
|
+
requestBodyInterceptor: {
|
|
380
|
+
post: ({ resourceName, requestBody }) => {
|
|
377
381
|
// Validate, or even change the requestBody
|
|
378
382
|
},
|
|
379
|
-
patch: (resourceName, requestBody) => {
|
|
383
|
+
patch: ({ resourceName, requestBody }) => {
|
|
380
384
|
// Validate, or even change the requestBody
|
|
381
385
|
},
|
|
382
|
-
put: (resourceName, requestBody) => {
|
|
386
|
+
put: ({ resourceName, requestBody }) => {
|
|
383
387
|
// Validate, or even change the requestBody
|
|
384
388
|
},
|
|
385
389
|
},
|
|
@@ -391,16 +395,17 @@ None of the settings are required, and only the settings you define are used.
|
|
|
391
395
|
|
|
392
396
|
These are all the possible settings:
|
|
393
397
|
|
|
394
|
-
| Config setting
|
|
395
|
-
|
|
|
396
|
-
| `resourceNames`
|
|
397
|
-
| `connectionString`
|
|
398
|
-
| `staticFolder`
|
|
399
|
-
| `apiPrefix`
|
|
400
|
-
| `customRouter`
|
|
401
|
-
| `cacheControl`
|
|
402
|
-
| `delay`
|
|
403
|
-
| `
|
|
398
|
+
| Config setting | Description |
|
|
399
|
+
| :------------------------ | :----------------------------------------------------------------------------------------- |
|
|
400
|
+
| `resourceNames` | See [Allowing specific resources only](#allowing-specific-resources-only) |
|
|
401
|
+
| `connectionString` | See [MongoDB](#mongodb) |
|
|
402
|
+
| `staticFolder` | See [Static assets](#static-assets) |
|
|
403
|
+
| `apiPrefix` | See [API prefix](#api-prefix) |
|
|
404
|
+
| `customRouter` | See [Custom router](#custom-router) |
|
|
405
|
+
| `cacheControl` | The `Cache-control` response header value for each GET request. |
|
|
406
|
+
| `delay` | After processing the request, the delay in milliseconds before the request should be sent. |
|
|
407
|
+
| `requestBodyInterceptor` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
|
|
408
|
+
| `responseBodyInterceptor` | See [Response body interception](#request-body-validation-or-mutation) |
|
|
404
409
|
|
|
405
410
|
## Not supported (yet?)
|
|
406
411
|
|
|
@@ -422,16 +427,6 @@ And there is no filtering, sorting, searching, etc. (yet?).
|
|
|
422
427
|
|
|
423
428
|
Temba is built with JavaScript, [Node](https://nodejs.org), [Express](https://expressjs.com/), [Jest](https://jestjs.io/), [Supertest](https://www.npmjs.com/package/supertest), and [@rakered/mongo](https://www.npmjs.com/package/@rakered/mongo).
|
|
424
429
|
|
|
425
|
-
## Which problem does Temba solve?
|
|
426
|
-
|
|
427
|
-
The problem with JSON file solutions like json-server is the limitations you have when hosting your app, because your data is stored in a file.
|
|
428
|
-
|
|
429
|
-
For example, hosting json-server on GitHub Pages means your API is essentially readonly, because, although mutations are supported, your data is not really persisted.
|
|
430
|
-
|
|
431
|
-
And hosting json-server on Heroku does give you persistence, but is not reliable because of its [ephemeral filesystem](https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem).
|
|
432
|
-
|
|
433
|
-
These limitations are of course the whole idea behind json-server, it's for simple mocking and prototyping. But if you want more (persistence wise) and don't mind having a database, you might want to try Temba.
|
|
434
|
-
|
|
435
430
|
## Contributors ✨
|
|
436
431
|
|
|
437
432
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
package/config/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { RequestBodyInterceptor, ResponseBodyInterceptor } from '../routes/types';
|
|
3
3
|
export type Config = {
|
|
4
4
|
validateResources: boolean;
|
|
5
5
|
resourceNames: string[];
|
|
6
6
|
apiPrefix: string;
|
|
7
7
|
cacheControl: string;
|
|
8
|
-
|
|
8
|
+
requestBodyInterceptor: RequestBodyInterceptor;
|
|
9
9
|
responseBodyInterceptor: ResponseBodyInterceptor;
|
|
10
10
|
staticFolder: string;
|
|
11
11
|
connectionString: string;
|
|
12
12
|
delay: number;
|
|
13
13
|
customRouter: Router;
|
|
14
14
|
};
|
|
15
|
-
export type RouterConfig = Pick<Config, 'validateResources' | 'resourceNames' | 'apiPrefix' | 'cacheControl' | '
|
|
15
|
+
export type RouterConfig = Pick<Config, 'validateResources' | 'resourceNames' | 'apiPrefix' | 'cacheControl' | 'requestBodyInterceptor' | 'responseBodyInterceptor'>;
|
|
16
16
|
export type UserConfig = {
|
|
17
17
|
resourceNames?: string[];
|
|
18
18
|
validateResources?: boolean;
|
|
@@ -21,7 +21,7 @@ export type UserConfig = {
|
|
|
21
21
|
connectionString?: string;
|
|
22
22
|
cacheControl?: string;
|
|
23
23
|
delay?: number;
|
|
24
|
-
|
|
24
|
+
requestBodyInterceptor?: RequestBodyInterceptor;
|
|
25
25
|
responseBodyInterceptor?: ResponseBodyInterceptor;
|
|
26
26
|
customRouter?: Router;
|
|
27
27
|
};
|
package/config/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const defaultConfig = {
|
|
|
9
9
|
connectionString: null,
|
|
10
10
|
cacheControl: 'no-store',
|
|
11
11
|
delay: 0,
|
|
12
|
-
|
|
12
|
+
requestBodyInterceptor: {
|
|
13
13
|
post: () => {
|
|
14
14
|
// do nothing
|
|
15
15
|
},
|
|
@@ -20,7 +20,7 @@ const defaultConfig = {
|
|
|
20
20
|
// do nothing
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
|
-
responseBodyInterceptor: (
|
|
23
|
+
responseBodyInterceptor: ({ responseBody }) => {
|
|
24
24
|
return responseBody;
|
|
25
25
|
},
|
|
26
26
|
customRouter: null,
|
|
@@ -37,8 +37,7 @@ function initConfig(userConfig) {
|
|
|
37
37
|
config.staticFolder = userConfig.staticFolder.replace(/[^a-zA-Z0-9]/g, '');
|
|
38
38
|
}
|
|
39
39
|
if (userConfig.apiPrefix) {
|
|
40
|
-
config.apiPrefix =
|
|
41
|
-
'/' + userConfig.apiPrefix.replace(/[^a-zA-Z0-9]/g, '') + '/';
|
|
40
|
+
config.apiPrefix = '/' + userConfig.apiPrefix.replace(/[^a-zA-Z0-9]/g, '') + '/';
|
|
42
41
|
}
|
|
43
42
|
if (userConfig.connectionString && userConfig.connectionString.length > 0) {
|
|
44
43
|
config.connectionString = userConfig.connectionString;
|
|
@@ -53,18 +52,18 @@ function initConfig(userConfig) {
|
|
|
53
52
|
Number(userConfig.delay) < 10000) {
|
|
54
53
|
config.delay = Number(userConfig.delay);
|
|
55
54
|
}
|
|
56
|
-
if (userConfig.
|
|
57
|
-
if (userConfig.
|
|
58
|
-
typeof userConfig.
|
|
59
|
-
config.
|
|
55
|
+
if (userConfig.requestBodyInterceptor) {
|
|
56
|
+
if (userConfig.requestBodyInterceptor.post &&
|
|
57
|
+
typeof userConfig.requestBodyInterceptor.post === 'function') {
|
|
58
|
+
config.requestBodyInterceptor.post = userConfig.requestBodyInterceptor.post;
|
|
60
59
|
}
|
|
61
|
-
if (userConfig.
|
|
62
|
-
typeof userConfig.
|
|
63
|
-
config.
|
|
60
|
+
if (userConfig.requestBodyInterceptor.patch &&
|
|
61
|
+
typeof userConfig.requestBodyInterceptor.patch === 'function') {
|
|
62
|
+
config.requestBodyInterceptor.patch = userConfig.requestBodyInterceptor.patch;
|
|
64
63
|
}
|
|
65
|
-
if (userConfig.
|
|
66
|
-
typeof userConfig.
|
|
67
|
-
config.
|
|
64
|
+
if (userConfig.requestBodyInterceptor.put &&
|
|
65
|
+
typeof userConfig.requestBodyInterceptor.put === 'function') {
|
|
66
|
+
config.requestBodyInterceptor.put = userConfig.requestBodyInterceptor.put;
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
if (userConfig.responseBodyInterceptor) {
|
package/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAuCA,MAAM,aAAa,GAAW;IAC5B,aAAa,EAAE,EAAE;IACjB,iBAAiB,EAAE,KAAK;IACxB,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,EAAE;IACb,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,UAAU;IACxB,KAAK,EAAE,CAAC;IACR,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAuCA,MAAM,aAAa,GAAW;IAC5B,aAAa,EAAE,EAAE;IACjB,iBAAiB,EAAE,KAAK;IACxB,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,EAAE;IACb,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,UAAU;IACxB,KAAK,EAAE,CAAC;IACR,sBAAsB,EAAE;QACtB,IAAI,EAAE,GAAG,EAAE;YACT,aAAa;QACf,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,aAAa;QACf,CAAC;QACD,GAAG,EAAE,GAAG,EAAE;YACR,aAAa;QACf,CAAC;KACF;IACD,uBAAuB,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE;QAC5C,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,YAAY,EAAE,IAAI;CACnB,CAAA;AAED,SAAgB,UAAU,CAAC,UAAsB;IAC/C,IAAI,CAAC,UAAU;QAAE,OAAO,aAAa,CAAA;IAErC,MAAM,MAAM,GAAG,kBAAK,aAAa,CAAY,CAAA;IAE7C,IAAI,UAAU,CAAC,aAA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M,CAAC,sBAAsB,CAAC,IAAI,GAAG,UAAU,CAAC,sBAAsB,CAAC,IAAI,CAAA;SAC5E;QACD,IACE,UAAU,CAAC,sBAAsB,CAAC,KAAK;YACvC,OAAO,UAAU,CAAC,sBAAsB,CAAC,KAAK,KAAK,UAAU,EAC7D;YACA,MAAM,CAAC,sBAAsB,CAAC,KAAK,GAAG,UAAU,CAAC,sBAAsB,CAAC,KAAK,CAAA;SAC9E;QACD,IACE,UAAU,CAAC,sBAAsB,CAAC,GAAG;YACrC,OAAO,UAAU,CAAC,sBAAsB,CAAC,GAAG,KAAK,UAAU,EAC3D;YACA,MAAM,CAAC,sBAAsB,CAAC,GAAG,GAAG,UAAU,CAAC,sBAAsB,CAAC,GAAG,CAAA;SAC1E;KACF;IAED,IAAI,UAAU,CAAC,uBAAuB,EAAE;QACtC,MAAM,CAAC,uBAAuB,GAAG,UAAU,CAAC,uBAAuB,CAAA;KACpE;IAED,IAAI,UAAU,CAAC,YAAY,EAAE;QAC3B,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;KAC9C;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAlED,gCAkEC"}
|
package/index.js
CHANGED
|
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.create = void 0;
|
|
30
30
|
const express_1 = __importStar(require("express"));
|
|
31
31
|
const morgan_1 = __importDefault(require("morgan"));
|
|
32
|
-
const errors_1 = require("./errors/errors");
|
|
33
32
|
const routes_1 = require("./routes/routes");
|
|
34
33
|
const queries_1 = require("./queries/queries");
|
|
35
34
|
const config_1 = require("./config");
|
|
@@ -76,8 +75,6 @@ function createServer(userConfig) {
|
|
|
76
75
|
app.all('*', routes_1.handleMethodNotAllowed);
|
|
77
76
|
if (config.apiPrefix)
|
|
78
77
|
app.all(`${config.apiPrefix}*`, routes_1.handleMethodNotAllowed);
|
|
79
|
-
// Error middleware.
|
|
80
|
-
app.use(errors_1.errorHandler);
|
|
81
78
|
return app;
|
|
82
79
|
}
|
|
83
80
|
function create(userConfig) {
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,oDAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,oDAA2B;AAC3B,4CAKwB;AACxB,+CAAiD;AACjD,qCAAyD;AACzD,gDAAuB;AACvB,6DAA+D;AAE/D,SAAS,YAAY,CAAC,UAAuB;IAC3C,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,UAAU,CAAC,CAAA;IAErC,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAEtD,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;IACrB,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAA;IAEf,4BAA4B;IAC5B,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAM,EAAC,MAAM,CAAC,CAAC,CAAA;IAEvB,gCAAgC;IAChC,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAElD,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE;QACpB,MAAM,eAAe,GAAG,IAAA,uCAAqB,EAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3D,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;KACzB;IAED,oBAAoB;IACpB,iDAAiD;IAEjD,wCAAwC;IACxC,IAAI,MAAM,CAAC,YAAY,EAAE;QACvB,GAAG,CAAC,GAAG,CAAC,i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O,YAAY,CAAC,UAAU,CAAC,CAAA;AACjC,CAAC;AAFD,wBAEC"}
|
package/package.json
CHANGED
package/routes/delete.d.ts
CHANGED
package/routes/delete.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createDeleteRoutes = void 0;
|
|
13
13
|
function createDeleteRoutes(queries) {
|
|
14
|
-
function handleDelete(req, res
|
|
14
|
+
function handleDelete(req, res) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
17
|
const { resourceName, id } = req.requestInfo;
|
|
@@ -26,7 +26,7 @@ function createDeleteRoutes(queries) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
return
|
|
29
|
+
return res.status(500).json({ message: error.message });
|
|
30
30
|
}
|
|
31
31
|
return res.status(204).send();
|
|
32
32
|
});
|
package/routes/delete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/routes/delete.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,kBAAkB,CAAC,OAAO;IACjC,SAAe,YAAY,CAAC,GAAG,EAAE,GAAG
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/routes/delete.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,kBAAkB,CAAC,OAAO;IACjC,SAAe,YAAY,CAAC,GAAG,EAAE,GAAG;;YAClC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAE5C,IAAI,EAAE,EAAE;oBACN,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;oBACpD,IAAI,IAAI,EAAE;wBACR,MAAM,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;qBAC3C;iBACF;qBAAM;oBACL,MAAM,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;iBACtC;aACF;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;aACnE;YAED,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;QAC/B,CAAC;KAAA;IAED,OAAO;QACL,YAAY;KACb,CAAA;AACH,CAAC;AAEQ,gDAAkB"}
|
package/routes/get.d.ts
CHANGED
package/routes/get.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createGetRoutes = void 0;
|
|
13
13
|
function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
|
|
14
|
-
function handleGetResource(req, res
|
|
14
|
+
function handleGetResource(req, res) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
17
|
const { resourceName, id } = req.requestInfo;
|
|
@@ -25,14 +25,12 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
|
|
|
25
25
|
let theItem = item;
|
|
26
26
|
if (responseBodyInterceptor) {
|
|
27
27
|
try {
|
|
28
|
-
theItem = responseBodyInterceptor(resourceName, item, id);
|
|
28
|
+
theItem = responseBodyInterceptor({ resourceName, responseBody: item, id });
|
|
29
29
|
if (!theItem)
|
|
30
30
|
theItem = item;
|
|
31
31
|
}
|
|
32
32
|
catch (error) {
|
|
33
|
-
return res
|
|
34
|
-
.status(500)
|
|
35
|
-
.json({
|
|
33
|
+
return res.status(500).json({
|
|
36
34
|
message: 'Error in responseBodyInterceptor: ' + error.message,
|
|
37
35
|
});
|
|
38
36
|
}
|
|
@@ -45,14 +43,12 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
|
|
|
45
43
|
let theItems = items;
|
|
46
44
|
if (responseBodyInterceptor) {
|
|
47
45
|
try {
|
|
48
|
-
theItems = responseBodyInterceptor(resourceName, items);
|
|
46
|
+
theItems = responseBodyInterceptor({ resourceName, responseBody: items });
|
|
49
47
|
if (!theItems)
|
|
50
48
|
theItems = items;
|
|
51
49
|
}
|
|
52
50
|
catch (error) {
|
|
53
|
-
return res
|
|
54
|
-
.status(500)
|
|
55
|
-
.json({
|
|
51
|
+
return res.status(500).json({
|
|
56
52
|
message: 'Error in responseBodyInterceptor: ' + error.message,
|
|
57
53
|
});
|
|
58
54
|
}
|
|
@@ -62,7 +58,7 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
|
|
|
62
58
|
return res.send();
|
|
63
59
|
}
|
|
64
60
|
catch (error) {
|
|
65
|
-
return
|
|
61
|
+
return res.status(500).json({ message: error.message });
|
|
66
62
|
}
|
|
67
63
|
});
|
|
68
64
|
}
|
package/routes/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/routes/get.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/routes/get.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,uBAAuB;IACrE,SAAe,iBAAiB,CAAC,GAAG,EAAE,GAAG;;YACvC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAE5C,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA;gBAEtC,IAAI,EAAE,EAAE;oBACN,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAA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MAAM,CAAC,GAAG,CAAC,CAAA;gBACf,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAClB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;aAClB;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;aACnE;QACH,CAAC;KAAA;IAED,OAAO;QACL,iBAAiB;KAClB,CAAA;AACH,CAAC;AAEQ,0CAAe"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
3
|
+
exports.interceptRequestBody = void 0;
|
|
4
|
+
function interceptRequestBody(intercept, req) {
|
|
5
5
|
const { resourceName } = req.requestInfo;
|
|
6
6
|
let requestBody = req.body;
|
|
7
|
-
const validationResult =
|
|
7
|
+
const validationResult = intercept({ resourceName, requestBody });
|
|
8
8
|
if (!validationResult && typeof requestBody === 'object')
|
|
9
9
|
return requestBody;
|
|
10
10
|
if (typeof validationResult === 'string')
|
|
@@ -18,5 +18,5 @@ function validateRequestBody(validator, req) {
|
|
|
18
18
|
else
|
|
19
19
|
return req.body;
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
22
|
-
//# sourceMappingURL=
|
|
21
|
+
exports.interceptRequestBody = interceptRequestBody;
|
|
22
|
+
//# sourceMappingURL=interceptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../src/routes/interceptors.ts"],"names":[],"mappings":";;;AAEA,SAAS,oBAAoB,CAAC,SAAyC,EAAE,GAAG;IAC1E,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;IACxC,IAAI,WAAW,GAAG,GAAG,CAAC,IAAI,CAAA;IAE1B,MAAM,gBAAgB,GAAG,SAAS,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAA;IAEjE,IAAI,CAAC,gBAAgB,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAA;IAE5E,IAAI,OAAO,gBAAgB,KAAK,QAAQ;QAAE,OAAO,gBAAgB,CAAA;IAEjE,kDAAkD;IAClD,IAAI,gBAAgB;QAAE,WAAW,GAAG,gBAAgB,CAAA;IAEpD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,OAAO,WAAW,CAAA;KACnB;;QAAM,OAAO,GAAG,CAAC,IAAI,CAAA;AACxB,CAAC;AAEQ,oDAAoB"}
|
package/routes/patch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function createPatchRoutes(queries: any,
|
|
2
|
-
handlePatch: (req: any, res: any
|
|
1
|
+
declare function createPatchRoutes(queries: any, requestBodyInterceptor: any): {
|
|
2
|
+
handlePatch: (req: any, res: any) => Promise<any>;
|
|
3
3
|
};
|
|
4
4
|
export { createPatchRoutes };
|
package/routes/patch.js
CHANGED
|
@@ -10,28 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createPatchRoutes = void 0;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
function handlePatch(req, res, next) {
|
|
13
|
+
const interceptors_1 = require("./interceptors");
|
|
14
|
+
function createPatchRoutes(queries, requestBodyInterceptor) {
|
|
15
|
+
function handlePatch(req, res) {
|
|
17
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
17
|
try {
|
|
19
18
|
const { resourceName, id } = req.requestInfo;
|
|
20
|
-
const requestBody = (0,
|
|
19
|
+
const requestBody = (0, interceptors_1.interceptRequestBody)(requestBodyInterceptor.patch, req);
|
|
21
20
|
if (typeof requestBody === 'string')
|
|
22
21
|
return res.status(400).json({ message: requestBody }).send();
|
|
23
22
|
let item = null;
|
|
24
23
|
if (id)
|
|
25
24
|
item = yield queries.getById(resourceName, id);
|
|
26
|
-
// TODO return a response instead of calling next
|
|
27
25
|
if (!item)
|
|
28
|
-
return
|
|
26
|
+
return res.status(404).json({
|
|
27
|
+
message: `ID '${id}' not found`,
|
|
28
|
+
});
|
|
29
29
|
item = Object.assign(Object.assign(Object.assign({}, item), requestBody), { id });
|
|
30
30
|
const updatedItem = yield queries.update(resourceName, item);
|
|
31
31
|
return res.status(200).json(updatedItem).send();
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
return
|
|
34
|
+
return res.status(500).json({ message: error.message });
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
package/routes/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/routes/patch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/routes/patch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAqD;AAErD,SAAS,iBAAiB,CAAC,OAAO,EAAE,sBAAsB;IACxD,SAAe,WAAW,CAAC,GAAG,EAAE,GAAG;;YACjC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAE5C,MAAM,WAAW,GAAG,IAAA,mCAAoB,EAAC,sBAAsB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBAE3E,IAAI,OAAO,WAAW,KAAK,QAAQ;oBACjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;gBAE9D,IAAI,IAAI,GAAG,IAAI,CAAA;gBACf,IAAI,EAAE;oBAAE,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;gBAEtD,IAAI,CAAC,IAAI;oBACP,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBAC1B,OAAO,EAAE,OAAO,EAAE,aAAa;qBAChC,CAAC,CAAA;gBAEJ,IAAI,iDAAQ,IAAI,GAAK,WAAW,KAAE,EAAE,GAAE,CAAA;gBAEtC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;gBAE5D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAA;aAChD;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;aACnE;QACH,CAAC;KAAA;IAED,OAAO;QACL,WAAW;KACZ,CAAA;AACH,CAAC;AAEQ,8CAAiB"}
|
package/routes/post.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function createPostRoutes(queries: any,
|
|
2
|
-
handlePost: (req: any, res: any
|
|
1
|
+
declare function createPostRoutes(queries: any, requestBodyInterceptor: any): {
|
|
2
|
+
handlePost: (req: any, res: any) => Promise<any>;
|
|
3
3
|
};
|
|
4
4
|
export { createPostRoutes };
|
package/routes/post.js
CHANGED
|
@@ -11,13 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createPostRoutes = void 0;
|
|
13
13
|
const url_1 = require("url");
|
|
14
|
-
const
|
|
15
|
-
function createPostRoutes(queries,
|
|
16
|
-
function handlePost(req, res
|
|
14
|
+
const interceptors_1 = require("./interceptors");
|
|
15
|
+
function createPostRoutes(queries, requestBodyInterceptor) {
|
|
16
|
+
function handlePost(req, res) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
try {
|
|
19
19
|
const { resourceName } = req.requestInfo;
|
|
20
|
-
const requestBody = (0,
|
|
20
|
+
const requestBody = (0, interceptors_1.interceptRequestBody)(requestBodyInterceptor.post, req);
|
|
21
21
|
if (typeof requestBody === 'string')
|
|
22
22
|
return res.status(400).json({ message: requestBody }).send();
|
|
23
23
|
const newItem = yield queries.create(resourceName, requestBody);
|
|
@@ -34,7 +34,7 @@ function createPostRoutes(queries, requestBodyValidator) {
|
|
|
34
34
|
.send();
|
|
35
35
|
}
|
|
36
36
|
catch (error) {
|
|
37
|
-
return
|
|
37
|
+
return res.status(500).json({ message: error.message });
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}
|
package/routes/post.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/routes/post.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/routes/post.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAC5B,iDAAqD;AAErD,SAAS,gBAAgB,CAAC,OAAO,EAAE,sBAAsB;IACvD,SAAe,UAAU,CAAC,GAAG,EAAE,GAAG;;YAChC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAExC,MAAM,WAAW,GAAG,IAAA,mCAAoB,EAAC,sBAAsB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;gBAE1E,IAAI,OAAO,WAAW,KAAK,QAAQ;oBACjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;gBAE9D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;gBAE/D,OAAO,GAAG;qBACP,GAAG,CAAC;oBACH,QAAQ,EAAE,IAAA,YAAM,EAAC;wBACf,QAAQ,EAAE,GAAG,CAAC,QAAQ;wBACtB,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;wBACrB,QAAQ,EAAE,GAAG,YAAY,IAAI,OAAO,CAAC,EAAE,EAAE;qBAC1C,CAAC;iBACH,CAAC;qBACD,MAAM,CAAC,GAAG,CAAC;qBACX,IAAI,CAAC,OAAO,CAAC;qBACb,IAAI,EAAE,CAAA;aACV;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;aACnE;QACH,CAAC;KAAA;IAED,OAAO;QACL,UAAU;KACX,CAAA;AACH,CAAC;AAEQ,4CAAgB"}
|
package/routes/put.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function createPutRoutes(queries: any,
|
|
2
|
-
handlePut: (req: any, res: any
|
|
1
|
+
declare function createPutRoutes(queries: any, requestBodyInterceptor: any): {
|
|
2
|
+
handlePut: (req: any, res: any) => Promise<any>;
|
|
3
3
|
};
|
|
4
4
|
export { createPutRoutes };
|
package/routes/put.js
CHANGED
|
@@ -10,28 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createPutRoutes = void 0;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
function handlePut(req, res, next) {
|
|
13
|
+
const interceptors_1 = require("./interceptors");
|
|
14
|
+
function createPutRoutes(queries, requestBodyInterceptor) {
|
|
15
|
+
function handlePut(req, res) {
|
|
17
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
17
|
try {
|
|
19
18
|
const { resourceName, id } = req.requestInfo;
|
|
20
|
-
const requestBody = (0,
|
|
19
|
+
const requestBody = (0, interceptors_1.interceptRequestBody)(requestBodyInterceptor.put, req);
|
|
21
20
|
if (typeof requestBody === 'string')
|
|
22
21
|
return res.status(400).json({ message: requestBody }).send();
|
|
23
22
|
let item = null;
|
|
24
23
|
if (id)
|
|
25
24
|
item = yield queries.getById(resourceName, id);
|
|
26
|
-
// TODO return a response instead of calling next
|
|
27
25
|
if (!item)
|
|
28
|
-
return
|
|
26
|
+
return res.status(404).json({
|
|
27
|
+
message: `ID '${id}' not found`,
|
|
28
|
+
});
|
|
29
29
|
item = Object.assign(Object.assign({}, requestBody), { id });
|
|
30
30
|
const replacedItem = yield queries.update(resourceName, item);
|
|
31
31
|
return res.status(200).json(replacedItem).send();
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
return
|
|
34
|
+
return res.status(500).json({ message: error.message });
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
package/routes/put.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"put.js","sourceRoot":"","sources":["../../src/routes/put.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"put.js","sourceRoot":"","sources":["../../src/routes/put.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAqD;AAErD,SAAS,eAAe,CAAC,OAAO,EAAE,sBAAsB;IACtD,SAAe,SAAS,CAAC,GAAG,EAAE,GAAG;;YAC/B,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAE5C,MAAM,WAAW,GAAG,IAAA,mCAAoB,EAAC,sBAAsB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;gBAEzE,IAAI,OAAO,WAAW,KAAK,QAAQ;oBACjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;gBAE9D,IAAI,IAAI,GAAG,IAAI,CAAA;gBACf,IAAI,EAAE;oBAAE,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;gBAEtD,IAAI,CAAC,IAAI;oBACP,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBAC1B,OAAO,EAAE,OAAO,EAAE,aAAa;qBAChC,CAAC,CAAA;gBAEJ,IAAI,mCAAQ,WAAW,KAAE,EAAE,GAAE,CAAA;gBAE7B,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;gBAE7D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAA;aACjD;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;aACnE;QACH,CAAC;KAAA;IAED,OAAO;QACL,SAAS;KACV,CAAA;AACH,CAAC;AAEQ,0CAAe"}
|
package/routes/routes.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ declare function createResourceRouter(queries: any, routerConfig: RouterConfig):
|
|
|
3
3
|
declare const rootRouter: import("express-serve-static-core").Router;
|
|
4
4
|
declare function handleMethodNotAllowed(_: any, res: any): void;
|
|
5
5
|
declare function handleNotFound(_: any, res: any): void;
|
|
6
|
-
export { createResourceRouter, rootRouter, handleMethodNotAllowed, handleNotFound
|
|
6
|
+
export { createResourceRouter, rootRouter, handleMethodNotAllowed, handleNotFound };
|
package/routes/routes.js
CHANGED
|
@@ -21,11 +21,11 @@ const delete_1 = require("./delete");
|
|
|
21
21
|
const urlMiddleware_1 = require("../urls/urlMiddleware");
|
|
22
22
|
const express_1 = __importDefault(require("express"));
|
|
23
23
|
function createResourceRouter(queries, routerConfig) {
|
|
24
|
-
const { validateResources, resourceNames, apiPrefix, cacheControl,
|
|
24
|
+
const { validateResources, resourceNames, apiPrefix, cacheControl, requestBodyInterceptor, responseBodyInterceptor, } = routerConfig;
|
|
25
25
|
const { handleGetResource } = (0, get_1.createGetRoutes)(queries, cacheControl, responseBodyInterceptor);
|
|
26
|
-
const { handlePost } = (0, post_1.createPostRoutes)(queries,
|
|
27
|
-
const { handlePut } = (0, put_1.createPutRoutes)(queries,
|
|
28
|
-
const { handlePatch } = (0, patch_1.createPatchRoutes)(queries,
|
|
26
|
+
const { handlePost } = (0, post_1.createPostRoutes)(queries, requestBodyInterceptor);
|
|
27
|
+
const { handlePut } = (0, put_1.createPutRoutes)(queries, requestBodyInterceptor);
|
|
28
|
+
const { handlePatch } = (0, patch_1.createPatchRoutes)(queries, requestBodyInterceptor);
|
|
29
29
|
const { handleDelete } = (0, delete_1.createDeleteRoutes)(queries);
|
|
30
30
|
const validateResource = (0, urlMiddleware_1.createValidateResourceMiddleware)(validateResources, resourceNames);
|
|
31
31
|
const getResourceAndId = (0, urlMiddleware_1.createResourceAndIdParser)(apiPrefix);
|
package/routes/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,mCAA2C;AAC3C,qCAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,m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gB,EAAE,YAAY,CAAC,CAAA;IAEhE,OAAO,cAAc,CAAA;AACvB,CAAC;AAqBQ,oDAAoB;AAnB7B,iDAAiD;AACjD,MAAM,UAAU,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAA;AAkBJ,gCAAU;AAjBzC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAO,CAAC,EAAE,GAAG,EAAE,EAAE;IACnC,OAAO,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;AAChC,CAAC,CAAA,CAAC,CAAA;AAEF,sDAAsD;AACtD,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAA;AAE3C,0CAA0C;AAC1C,SAAS,sBAAsB,CAAC,CAAC,EAAE,GAAG;IACpC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAA;AACzD,CAAC;AAO0C,wDAAsB;AALjE,gCAAgC;AAChC,SAAS,cAAc,CAAC,CAAC,EAAE,GAAG;IAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;AAChD,CAAC;AAEkE,wCAAc"}
|
package/routes/types.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
patch?: ValidatorCallback;
|
|
5
|
-
put?: ValidatorCallback;
|
|
1
|
+
type RequestInfo = {
|
|
2
|
+
resourceName: string;
|
|
3
|
+
requestBody: unknown;
|
|
6
4
|
};
|
|
7
|
-
export type
|
|
5
|
+
export type RequestBodyInterceptorCallback = (info: RequestInfo) => void | string | object;
|
|
6
|
+
export type RequestBodyInterceptor = {
|
|
7
|
+
post?: RequestBodyInterceptorCallback;
|
|
8
|
+
patch?: RequestBodyInterceptorCallback;
|
|
9
|
+
put?: RequestBodyInterceptorCallback;
|
|
10
|
+
};
|
|
11
|
+
type ResponseInfo = {
|
|
12
|
+
resourceName: string;
|
|
13
|
+
responseBody: unknown;
|
|
14
|
+
id?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ResponseBodyInterceptor = (info: ResponseInfo) => unknown;
|
|
17
|
+
export {};
|
package/urls/urlMiddleware.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
declare function createResourceAndIdParser(apiPrefix: any): (req: any, _: any, next: any) => any;
|
|
2
|
-
declare function createValidateResourceMiddleware(validateResources: any, resourceNames: any): (req: any,
|
|
2
|
+
declare function createValidateResourceMiddleware(validateResources: any, resourceNames: any): (req: any, res: any, next: any) => any;
|
|
3
3
|
export { createResourceAndIdParser, createValidateResourceMiddleware };
|
package/urls/urlMiddleware.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createValidateResourceMiddleware = exports.createResourceAndIdParser = void 0;
|
|
4
|
-
const errors_1 = require("../errors/errors");
|
|
5
4
|
const urlParser_1 = require("./urlParser");
|
|
6
5
|
function createResourceAndIdParser(apiPrefix) {
|
|
7
6
|
return function getResourceAndId(req, _, next) {
|
|
@@ -13,16 +12,16 @@ function createResourceAndIdParser(apiPrefix) {
|
|
|
13
12
|
}
|
|
14
13
|
exports.createResourceAndIdParser = createResourceAndIdParser;
|
|
15
14
|
function createValidateResourceMiddleware(validateResources, resourceNames) {
|
|
16
|
-
return function validateResource(req,
|
|
15
|
+
return function validateResource(req, res, next) {
|
|
17
16
|
if (!validateResources)
|
|
18
17
|
return next();
|
|
19
18
|
const { resourceName } = req.requestInfo;
|
|
20
19
|
if (!resourceName)
|
|
21
20
|
return next();
|
|
22
21
|
if (!resourceNames.includes(resourceName.toLowerCase())) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
return res.status(404).json({
|
|
23
|
+
message: `'${resourceName}' is an unknown resource`,
|
|
24
|
+
});
|
|
26
25
|
}
|
|
27
26
|
return next();
|
|
28
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlMiddleware.js","sourceRoot":"","sources":["../../src/urls/urlMiddleware.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"urlMiddleware.js","sourceRoot":"","sources":["../../src/urls/urlMiddleware.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAEtC,SAAS,yBAAyB,CAAC,SAAS;IAC1C,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI;QAC3C,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QAC9C,MAAM,OAAO,GAAG,IAAA,oBAAQ,EAAC,GAAG,CAAC,CAAA;QAE7B,GAAG,CAAC,WAAW,mCAAQ,GAAG,CAAC,WAAW,GAAK,OAAO,CAAE,CAAA;QAEpD,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAoBQ,8DAAyB;AAlBlC,SAAS,gCAAgC,CAAC,iBAAiB,EAAE,aAAa;IACxE,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;QAC7C,IAAI,CAAC,iBAAiB;YAAE,OAAO,IAAI,EAAE,CAAA;QAErC,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;QAExC,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,EAAE,CAAA;QAEhC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE;YACvD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,OAAO,EAAE,IAAI,YAAY,0BAA0B;aACpD,CAAC,CAAA;SACH;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAEmC,4EAAgC"}
|
package/errors/errors.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class HttpError extends Error {
|
|
2
|
-
status: number;
|
|
3
|
-
message: string;
|
|
4
|
-
constructor(status: number, message: string);
|
|
5
|
-
}
|
|
6
|
-
declare function errorHandler(e: unknown, _: any, res: any): any;
|
|
7
|
-
declare function new404NotFoundError(message?: string): HttpError;
|
|
8
|
-
declare function new400BadRequestError(message?: string): HttpError;
|
|
9
|
-
declare function new500InternalServerError(message?: string): HttpError;
|
|
10
|
-
export { errorHandler, new404NotFoundError, new400BadRequestError, new500InternalServerError, };
|
package/errors/errors.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.new500InternalServerError = exports.new400BadRequestError = exports.new404NotFoundError = exports.errorHandler = exports.HttpError = void 0;
|
|
4
|
-
class HttpError extends Error {
|
|
5
|
-
constructor(status, message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.message = message;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.HttpError = HttpError;
|
|
12
|
-
// This is the error middleware that will be used by the server.
|
|
13
|
-
function errorHandler(e, _, res) {
|
|
14
|
-
const status = 500;
|
|
15
|
-
let message = 'Unknown error';
|
|
16
|
-
if (e instanceof Error) {
|
|
17
|
-
message = e.message;
|
|
18
|
-
}
|
|
19
|
-
return res.status(status).json({ message });
|
|
20
|
-
}
|
|
21
|
-
exports.errorHandler = errorHandler;
|
|
22
|
-
function new404NotFoundError(message = 'Not Found') {
|
|
23
|
-
return new HttpError(404, message);
|
|
24
|
-
}
|
|
25
|
-
exports.new404NotFoundError = new404NotFoundError;
|
|
26
|
-
function new400BadRequestError(message = 'Bad Request') {
|
|
27
|
-
return new HttpError(400, message);
|
|
28
|
-
}
|
|
29
|
-
exports.new400BadRequestError = new400BadRequestError;
|
|
30
|
-
function new500InternalServerError(message = 'Internal Server Error') {
|
|
31
|
-
return new HttpError(500, message);
|
|
32
|
-
}
|
|
33
|
-
exports.new500InternalServerError = new500InternalServerError;
|
|
34
|
-
//# sourceMappingURL=errors.js.map
|
package/errors/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAAY,MAAc,EAAE,OAAe;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAVD,8BAUC;AAED,gEAAgE;AAChE,SAAS,YAAY,CAAC,CAAU,EAAE,CAAC,EAAE,GAAG;IACtC,MAAM,MAAM,GAAG,GAAG,CAAA;IAClB,IAAI,OAAO,GAAG,eAAe,CAAA;IAE7B,IAAI,CAAC,YAAY,KAAK,EAAE;QACtB,OAAO,GAAG,CAAC,CAAC,OAAO,CAAA;KACpB;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;AAC7C,CAAC;AAeC,oCAAY;AAbd,SAAS,mBAAmB,CAAC,OAAO,GAAG,WAAW;IAChD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAYC,kDAAmB;AAVrB,SAAS,qBAAqB,CAAC,OAAO,GAAG,aAAa;IACpD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AASC,sDAAqB;AAPvB,SAAS,yBAAyB,CAAC,OAAO,GAAG,uBAAuB;IAClE,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAMC,8DAAyB"}
|
package/routes/validator.d.ts
DELETED
package/routes/validator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/routes/validator.ts"],"names":[],"mappings":";;;AAEA,SAAS,mBAAmB,CAC1B,SAA4B,EAC5B,GAAG;IAEH,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;IACxC,IAAI,WAAW,GAAG,GAAG,CAAC,IAAI,CAAA;IAE1B,MAAM,gBAAgB,GAAG,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IAE7D,IAAI,CAAC,gBAAgB,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAA;IAE5E,IAAI,OAAO,gBAAgB,KAAK,QAAQ;QAAE,OAAO,gBAAgB,CAAA;IAEjE,kDAAkD;IAClD,IAAI,gBAAgB;QAAE,WAAW,GAAG,gBAAgB,CAAA;IAEpD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,OAAO,WAAW,CAAA;KACnB;;QAAM,OAAO,GAAG,CAAC,IAAI,CAAA;AACxB,CAAC;AAEQ,kDAAmB"}
|