temba 0.12.20 → 0.12.21

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
@@ -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
- ### Manually adding to an existing app
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
- By passing a config object to the `create` function you can customize Temba's behavior. Refer to the [config settings](#config-settings-overview) below for the various possibilities.
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
 
@@ -244,9 +248,9 @@ const config = {
244
248
  const server = temba.create(config)
245
249
  ```
246
250
 
247
- ## Response body interception
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 = {
@@ -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
- ## Custom router
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 resource routes can be overruled by a custom router. To add your own routes, create an Express router, and configure it as a `customRouter`:
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
- ### Config settings overview
364
+ ## Config settings overview
361
365
 
362
366
  Configuring Temba is optional, it already works out of the box.
363
367
 
@@ -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 | Description |
395
- | :--------------------- | :----------------------------------------------------------------------------------------- |
396
- | `resourceNames` | See [Allowing specific resources only](#allowing-specific-resources-only) |
397
- | `connectionString` | See [MongoDB](#mongodb) |
398
- | `staticFolder` | See [Static assets](#static-assets) |
399
- | `apiPrefix` | See [API prefix](#api-prefix) |
400
- | `customRouter` | See [Custom router](#custom-router) |
401
- | `cacheControl` | The `Cache-control` response header value for each GET request. |
402
- | `delay` | After processing the request, the delay in milliseconds before the request should be sent. |
403
- | `requestBodyValidator` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
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
+ | `requestBodyValidator` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
408
+ | `responseBodyInterceptor` | See [Response body interception](#response-body-interception) |
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/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,4CAA8C;AAC9C,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,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,C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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": {
@@ -1,4 +1,4 @@
1
1
  declare function createDeleteRoutes(queries: any): {
2
- handleDelete: (req: any, res: any, next: any) => Promise<any>;
2
+ handleDelete: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createDeleteRoutes };
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, next) {
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 next(error);
29
+ return res.status(500).json({ message: error.message });
30
30
  }
31
31
  return res.status(204).send();
32
32
  });
@@ -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,EAAE,IAAI;;YACxC,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,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;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"}
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
@@ -1,4 +1,4 @@
1
1
  declare function createGetRoutes(queries: any, cacheControl: any, responseBodyInterceptor: any): {
2
- handleGetResource: (req: any, res: any, next: any) => Promise<any>;
2
+ handleGetResource: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createGetRoutes };
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, next) {
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;
@@ -30,9 +30,7 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
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
  }
@@ -50,9 +48,7 @@ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
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 next(error);
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":";;;;;;;;;;;;AAEA,SAAS,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,uBAAuB;IACrE,SAAe,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;;YAC7C,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,EAA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AAA;yBACH;qBACF;oBAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBACf,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;oBACjB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;iBAClB;gBAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;gBAEhD,IAAI,QAAQ,GAAG,KAAK,CAAA;gBACpB,IAAI,uBAAuB,EAAE;oBAC3B,IAAI;wBACF,QAAQ,GAAG,uBAAuB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;wBACvD,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"}
package/routes/patch.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  declare function createPatchRoutes(queries: any, requestBodyValidator: any): {
2
- handlePatch: (req: any, res: any, next: any) => Promise<any>;
2
+ handlePatch: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createPatchRoutes };
package/routes/patch.js CHANGED
@@ -10,10 +10,9 @@ 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 errors_1 = require("../errors/errors");
14
13
  const validator_1 = require("./validator");
15
14
  function createPatchRoutes(queries, requestBodyValidator) {
16
- function handlePatch(req, res, next) {
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;
@@ -23,15 +22,16 @@ function createPatchRoutes(queries, requestBodyValidator) {
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 next((0, errors_1.new404NotFoundError)(`ID '${id}' not found`));
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 next(error);
34
+ return res.status(500).json({ message: error.message });
35
35
  }
36
36
  });
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/routes/patch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAsD;AACtD,2CAAiD;AAEjD,SAAS,iBAAiB,CAAC,OAAO,EAAE,oBAAoB;IACtD,SAAe,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;;YACvC,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,OA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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
1
  declare function createPostRoutes(queries: any, requestBodyValidator: any): {
2
- handlePost: (req: any, res: any, next: any) => Promise<any>;
2
+ handlePost: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createPostRoutes };
package/routes/post.js CHANGED
@@ -13,7 +13,7 @@ exports.createPostRoutes = void 0;
13
13
  const url_1 = require("url");
14
14
  const validator_1 = require("./validator");
15
15
  function createPostRoutes(queries, requestBodyValidator) {
16
- function handlePost(req, res, next) {
16
+ function handlePost(req, res) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  try {
19
19
  const { resourceName } = req.requestInfo;
@@ -34,7 +34,7 @@ function createPostRoutes(queries, requestBodyValidator) {
34
34
  .send();
35
35
  }
36
36
  catch (error) {
37
- return next(error);
37
+ return res.status(500).json({ message: error.message });
38
38
  }
39
39
  });
40
40
  }
@@ -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,EAAE,IAAI;;YACtC,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,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;IAED,OAAO;QACL,UAAU;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}
package/routes/put.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  declare function createPutRoutes(queries: any, requestBodyValidator: any): {
2
- handlePut: (req: any, res: any, next: any) => Promise<any>;
2
+ handlePut: (req: any, res: any) => Promise<any>;
3
3
  };
4
4
  export { createPutRoutes };
package/routes/put.js CHANGED
@@ -10,10 +10,9 @@ 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 errors_1 = require("../errors/errors");
14
13
  const validator_1 = require("./validator");
15
14
  function createPutRoutes(queries, requestBodyValidator) {
16
- function handlePut(req, res, next) {
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;
@@ -23,15 +22,16 @@ function createPutRoutes(queries, requestBodyValidator) {
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 next((0, errors_1.new404NotFoundError)(`ID '${id}' not found`));
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 next(error);
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,6CAAsD;AACtD,2CAAiD;AAEjD,SAAS,eAAe,CAAC,OAAO,EAAE,oBAAoB;IACpD,SAAe,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;;YACrC,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,C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AAA,+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,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"}
@@ -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, _: any, next: any) => any;
2
+ declare function createValidateResourceMiddleware(validateResources: any, resourceNames: any): (req: any, res: any, next: any) => any;
3
3
  export { createResourceAndIdParser, createValidateResourceMiddleware };
@@ -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, _, next) {
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
- // TODO return a response instead of calling next
24
- const error = (0, errors_1.new404NotFoundError)(`'${resourceName}' is an unknown resource`);
25
- return next(error);
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,6CAAsD;AACtD,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;AAsBQ,8DAAyB;AApBlC,SAAS,gCAA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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"}
@@ -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
@@ -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"}