temba 0.12.21 → 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 CHANGED
@@ -113,7 +113,7 @@ Temba supports JSON only.
113
113
 
114
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.
115
115
 
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 [`requestBodyValidator`](#request-body-validation-or-mutation) callbacks.
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.
117
117
 
118
118
  IDs are auto generated when creating resources. IDs in the JSON request body are ignored for any request.
119
119
 
@@ -197,18 +197,18 @@ POST /movies
197
197
  }
198
198
  ```
199
199
 
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 `requestBodyValidator` config setting:
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:
201
201
 
202
202
  ```js
203
203
  const config = {
204
- requestBodyValidator: {
205
- post: (resourceName, requestBody) => {
204
+ requestBodyInterceptor: {
205
+ post: ({ resourceName, requestBody }) => {
206
206
  // Validate, or even change the requestBody
207
207
  },
208
- put: (resourceName, requestBody) => {
208
+ put: ({ resourceName, requestBody }) => {
209
209
  // Validate, or even change the requestBody
210
210
  },
211
- patch: (resourceName, requestBody) => {
211
+ patch: ({ resourceName, requestBody }) => {
212
212
  // Validate, or even change the requestBody
213
213
  },
214
214
  },
@@ -217,9 +217,9 @@ const config = {
217
217
  const server = temba.create(config)
218
218
  ```
219
219
 
220
- The `requestBodyValidator` 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.
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.
221
221
 
222
- The callback function receives two arguments: The `resourceName`, which for example is `movies` if you request `POST /movies`. The second argument is the `requestBody`, which is the JSON object in the request body.
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.
223
223
 
224
224
  Your callback function can return the following things:
225
225
 
@@ -231,8 +231,8 @@ Example:
231
231
 
232
232
  ```js
233
233
  const config = {
234
- requestBodyValidator: {
235
- post: (resourceName, requestBody) => {
234
+ requestBodyInterceptor: {
235
+ post: ({ resourceName, requestBody }) => {
236
236
  // Do not allow Pokemons to be created: 400 Bad Request
237
237
  if (resourceName === 'pokemons') return 'You are not allowed to create new Pokemons'
238
238
 
@@ -254,7 +254,7 @@ To change the response body of a `GET` request, before it's being sent to the cl
254
254
 
255
255
  ```js
256
256
  const config = {
257
- responseBodyInterceptor: (resourceName, responseBody, id) => {
257
+ responseBodyInterceptor: ({ resourceName, responseBody, id }) => {
258
258
  if (resourceName === 'movies') {
259
259
  if (id) {
260
260
  // responseBody is an object
@@ -278,7 +278,7 @@ const config = {
278
278
  const server = temba.create(config)
279
279
  ```
280
280
 
281
- `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`.
282
282
 
283
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.
284
284
 
@@ -376,14 +376,14 @@ const config = {
376
376
  customRouter: router,
377
377
  cacheControl: 'public, max-age=300',
378
378
  delay: 500,
379
- requestBodyValidator: {
380
- post: (resourceName, requestBody) => {
379
+ requestBodyInterceptor: {
380
+ post: ({ resourceName, requestBody }) => {
381
381
  // Validate, or even change the requestBody
382
382
  },
383
- patch: (resourceName, requestBody) => {
383
+ patch: ({ resourceName, requestBody }) => {
384
384
  // Validate, or even change the requestBody
385
385
  },
386
- put: (resourceName, requestBody) => {
386
+ put: ({ resourceName, requestBody }) => {
387
387
  // Validate, or even change the requestBody
388
388
  },
389
389
  },
@@ -404,8 +404,8 @@ These are all the possible settings:
404
404
  | `customRouter` | See [Custom router](#custom-router) |
405
405
  | `cacheControl` | The `Cache-control` response header value for each GET request. |
406
406
  | `delay` | After processing the request, the delay in milliseconds before the request should be sent. |
407
- | `requestBodyValidator` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
408
- | `responseBodyInterceptor` | See [Response body interception](#response-body-interception) |
407
+ | `requestBodyInterceptor` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
408
+ | `responseBodyInterceptor` | See [Response body interception](#request-body-validation-or-mutation) |
409
409
 
410
410
  ## Not supported (yet?)
411
411
 
package/config/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { Router } from 'express';
2
- import { RequestBodyValidator, ResponseBodyInterceptor } from '../routes/types';
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
- requestBodyValidator: RequestBodyValidator;
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' | 'requestBodyValidator' | 'responseBodyInterceptor'>;
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
- requestBodyValidator?: RequestBodyValidator;
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
- requestBodyValidator: {
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: (resourceName, responseBody, id) => {
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.requestBodyValidator) {
57
- if (userConfig.requestBodyValidator.post &&
58
- typeof userConfig.requestBodyValidator.post === 'function') {
59
- config.requestBodyValidator.post = userConfig.requestBodyValidator.post;
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.requestBodyValidator.patch &&
62
- typeof userConfig.requestBodyValidator.patch === 'function') {
63
- config.requestBodyValidator.patch = userConfig.requestBodyValidator.patch;
60
+ if (userConfig.requestBodyInterceptor.patch &&
61
+ typeof userConfig.requestBodyInterceptor.patch === 'function') {
62
+ config.requestBodyInterceptor.patch = userConfig.requestBodyInterceptor.patch;
64
63
  }
65
- if (userConfig.requestBodyValidator.put &&
66
- typeof userConfig.requestBodyValidator.put === 'function') {
67
- config.requestBodyValidator.put = userConfig.requestBodyValidator.put;
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) {
@@ -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,oBAAoB,EAAE;QACpB,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,YAAY,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE;QAC1D,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,MA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AM,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,EAChC;QACA,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;KACxC;IAED,IAAI,UAAU,CAAC,sBAAsB,EAAE;QACrC,IACE,UAAU,CAAC,sBAAsB,CAAC,IAAI;YACtC,OAAO,UAAU,CAAC,sBAAsB,CAAC,IAAI,KAAK,UAAU,EAC5D;YACA,MAAM,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temba",
3
- "version": "0.12.21",
3
+ "version": "0.13.0",
4
4
  "description": "Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/routes/get.js CHANGED
@@ -25,7 +25,7 @@ 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
  }
@@ -43,7 +43,7 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
43
43
  let theItems = items;
44
44
  if (responseBodyInterceptor) {
45
45
  try {
46
- theItems = responseBodyInterceptor(resourceName, items);
46
+ theItems = responseBodyInterceptor({ resourceName, responseBody: items });
47
47
  if (!theItems)
48
48
  theItems = items;
49
49
  }
package/routes/get.js.map CHANGED
@@ -1 +1 @@
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,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;oBAEpD,IAAI,CAAC,IAAI,EAAE;wBACT,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;wBACf,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;qBAClB;oBAED,IAAI,OAAO,GAAG,IAAI,CAAA;oBAClB,IAAI,uBAAuB,EAAE;wBAC3B,IAAI;4BACF,OAAO,GAAG,uBAAuB,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;4BACzD,IAAI,CAAC,OAAO;gCAAE,OAAO,GAAG,IAAI,CAAA;yBAC7B;wBAAC,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,uBAAuB,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAA;wBACzE,IAAI,CAAC,QAAQ;4BAAE,QAAQ,GAAG,KAAK,CAAA;qBAChC;oBAAC,OAAO,KAAK,EAAE;wBACd,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;4BAC1B,OAAO,EAAE,oCAAoC,GAAG,KAAK,CAAC,OAAO;yBAC9D,CAAC,CAAA;qBACH;iBACF;gBAED,GAAG,CAAC,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"}
@@ -0,0 +1,3 @@
1
+ import { RequestBodyInterceptorCallback } from './types';
2
+ declare function interceptRequestBody(intercept: RequestBodyInterceptorCallback, req: any): string | object;
3
+ export { interceptRequestBody };
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRequestBody = void 0;
4
- function validateRequestBody(validator, req) {
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 = validator(resourceName, requestBody);
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.validateRequestBody = validateRequestBody;
22
- //# sourceMappingURL=validator.js.map
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, requestBodyValidator: any): {
1
+ declare function createPatchRoutes(queries: any, requestBodyInterceptor: any): {
2
2
  handlePatch: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createPatchRoutes };
package/routes/patch.js CHANGED
@@ -10,13 +10,13 @@ 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 validator_1 = require("./validator");
14
- function createPatchRoutes(queries, requestBodyValidator) {
13
+ const interceptors_1 = require("./interceptors");
14
+ function createPatchRoutes(queries, requestBodyInterceptor) {
15
15
  function handlePatch(req, res) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  try {
18
18
  const { resourceName, id } = req.requestInfo;
19
- const requestBody = (0, validator_1.validateRequestBody)(requestBodyValidator.patch, req);
19
+ const requestBody = (0, interceptors_1.interceptRequestBody)(requestBodyInterceptor.patch, req);
20
20
  if (typeof requestBody === 'string')
21
21
  return res.status(400).json({ message: requestBody }).send();
22
22
  let item = null;
@@ -1 +1 @@
1
- {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/routes/patch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AAEjD,SAAS,iBAAiB,CAAC,OAAO,EAAE,oBAAoB;IACtD,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,+BAAmB,EAAC,oBAAoB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBAExE,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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AE,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, requestBodyValidator: any): {
1
+ declare function createPostRoutes(queries: any, requestBodyInterceptor: any): {
2
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 validator_1 = require("./validator");
15
- function createPostRoutes(queries, requestBodyValidator) {
14
+ const interceptors_1 = require("./interceptors");
15
+ function createPostRoutes(queries, requestBodyInterceptor) {
16
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, validator_1.validateRequestBody)(requestBodyValidator.post, req);
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);
@@ -1 +1 @@
1
- {"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/routes/post.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAC5B,2CAAiD;AAEjD,SAAS,gBAAgB,CAAC,OAAO,EAAE,oBAAoB;IACrD,SAAe,UAAU,CAAC,GAAG,EAAE,GAAG;;YAChC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAExC,MAAM,WAAW,GAAG,IAAA,+BAAmB,EAAC,oBAAoB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;gBAEvE,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"}
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, requestBodyValidator: any): {
1
+ declare function createPutRoutes(queries: any, requestBodyInterceptor: any): {
2
2
  handlePut: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createPutRoutes };
package/routes/put.js CHANGED
@@ -10,13 +10,13 @@ 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 validator_1 = require("./validator");
14
- function createPutRoutes(queries, requestBodyValidator) {
13
+ const interceptors_1 = require("./interceptors");
14
+ function createPutRoutes(queries, requestBodyInterceptor) {
15
15
  function handlePut(req, res) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  try {
18
18
  const { resourceName, id } = req.requestInfo;
19
- const requestBody = (0, validator_1.validateRequestBody)(requestBodyValidator.put, req);
19
+ const requestBody = (0, interceptors_1.interceptRequestBody)(requestBodyInterceptor.put, req);
20
20
  if (typeof requestBody === 'string')
21
21
  return res.status(400).json({ message: requestBody }).send();
22
22
  let item = null;
package/routes/put.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"put.js","sourceRoot":"","sources":["../../src/routes/put.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AAEjD,SAAS,eAAe,CAAC,OAAO,EAAE,oBAAoB;IACpD,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,+BAAmB,EAAC,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;gBAEtE,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,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AI,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"}
@@ -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, requestBodyValidator, responseBodyInterceptor, } = routerConfig;
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, requestBodyValidator);
27
- const { handlePut } = (0, put_1.createPutRoutes)(queries, requestBodyValidator);
28
- const { handlePatch } = (0, patch_1.createPatchRoutes)(queries, requestBodyValidator);
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);
@@ -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,yDAG8B;AAE9B,sDAA6B;AAG7B,SAAS,oBAAoB,CAAC,OAAO,EAAE,YAA0B;IAC/D,MAAM,EACJ,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,GACxB,GAAG,YAAY,CAAA;IAEhB,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,qBAAe,EAC3C,OAAO,EACP,YAAY,EACZ,uBAAuB,CACxB,CAAA;IACD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,uBAAgB,EAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;IACtE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,qBAAe,EAAC,OAAO,EAAE,oBAAoB,CAAC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.d.ts CHANGED
@@ -1,7 +1,17 @@
1
- export type ValidatorCallback = (resourceName: string, requestBody: unknown) => void | string | object;
2
- export type RequestBodyValidator = {
3
- post?: ValidatorCallback;
4
- patch?: ValidatorCallback;
5
- put?: ValidatorCallback;
1
+ type RequestInfo = {
2
+ resourceName: string;
3
+ requestBody: unknown;
6
4
  };
7
- export type ResponseBodyInterceptor = (resourceName: string, responseBody: unknown, id?: string) => unknown;
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 {};
@@ -1,3 +0,0 @@
1
- import { ValidatorCallback } from './types';
2
- declare function validateRequestBody(validator: ValidatorCallback, req: any): string | object;
3
- export { validateRequestBody };
@@ -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"}