temba 0.9.0 → 0.10.3
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 +20 -17
- package/package.json +6 -9
- package/dist/config/index.js +0 -69
- package/dist/config/index.js.map +0 -1
- package/dist/delay/middleware.js +0 -16
- package/dist/delay/middleware.js.map +0 -1
- package/dist/errors/index.js +0 -13
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/middleware.js +0 -11
- package/dist/errors/middleware.js.map +0 -1
- package/dist/errors/types.js +0 -13
- package/dist/errors/types.js.map +0 -1
- package/dist/logging/index.js +0 -39
- package/dist/logging/index.js.map +0 -1
- package/dist/queries/in-memory.js +0 -65
- package/dist/queries/in-memory.js.map +0 -1
- package/dist/queries/index.js +0 -17
- package/dist/queries/index.js.map +0 -1
- package/dist/queries/mongo.js +0 -87
- package/dist/queries/mongo.js.map +0 -1
- package/dist/routes/delete.js +0 -39
- package/dist/routes/delete.js.map +0 -1
- package/dist/routes/get.js +0 -44
- package/dist/routes/get.js.map +0 -1
- package/dist/routes/index.js +0 -56
- package/dist/routes/index.js.map +0 -1
- package/dist/routes/post.js +0 -44
- package/dist/routes/post.js.map +0 -1
- package/dist/routes/put.js +0 -40
- package/dist/routes/put.js.map +0 -1
- package/dist/routes/validator.js +0 -18
- package/dist/routes/validator.js.map +0 -1
- package/dist/server.js +0 -77
- package/dist/server.js.map +0 -1
- package/dist/urls/middleware.js +0 -30
- package/dist/urls/middleware.js.map +0 -1
- package/dist/urls/urlParser.js +0 -13
- package/dist/urls/urlParser.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# Temba
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/temba)
|
|
3
4
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
4
|
-
|
|
5
5
|
[](#contributors-)
|
|
6
|
-
|
|
7
6
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
8
7
|
|
|
9
8
|
**Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).**
|
|
@@ -20,6 +19,8 @@ This project is inspired by the fantastic [json-server](https://github.com/typic
|
|
|
20
19
|
|
|
21
20
|
[Getting Started](#getting-started)
|
|
22
21
|
|
|
22
|
+
[What Tema does](#what-temba-does)
|
|
23
|
+
|
|
23
24
|
[Usage](#usage)
|
|
24
25
|
|
|
25
26
|
## Temba?
|
|
@@ -39,7 +40,7 @@ Prerequisites you need to have:
|
|
|
39
40
|
|
|
40
41
|
> Wthout a database, Temba also works. However, then data is kept in memory and flushed every time the server restarts.
|
|
41
42
|
|
|
42
|
-
### Use `npx`
|
|
43
|
+
### Use the starter with `npx`
|
|
43
44
|
|
|
44
45
|
Create your own Temba server with the following command and you are up and running!
|
|
45
46
|
|
|
@@ -47,7 +48,7 @@ Create your own Temba server with the following command and you are up and runni
|
|
|
47
48
|
npx create-temba-server my-rest-api
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
This command clones the [Temba-starter](https://github.com/bouwe77/temba-starter) repository and installs all dependencies.
|
|
51
52
|
|
|
52
53
|
### Manually adding to an existing app
|
|
53
54
|
|
|
@@ -71,9 +72,7 @@ server.listen(port, () => {
|
|
|
71
72
|
|
|
72
73
|
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.
|
|
73
74
|
|
|
74
|
-
##
|
|
75
|
-
|
|
76
|
-
### Introduction
|
|
75
|
+
## What Temba does
|
|
77
76
|
|
|
78
77
|
Out of the box, Temba gives you a CRUD REST API to any resource name you can think of.
|
|
79
78
|
|
|
@@ -94,9 +93,21 @@ The HTTP methods that are supported are `GET`, `POST`, `PUT` and `DELETE`. For a
|
|
|
94
93
|
|
|
95
94
|
On the root URI (e.g. http://localhost:8080/) only a `GET` request is supported, which shows you a message indicating the API is working. All other HTTP methods on the root URI return a `405 Method Not Allowed` response.
|
|
96
95
|
|
|
97
|
-
###
|
|
96
|
+
### JSON
|
|
97
|
+
|
|
98
|
+
Temba supports JSON only.
|
|
99
|
+
|
|
100
|
+
Request bodies sent with a `POST` 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.
|
|
101
|
+
|
|
102
|
+
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.
|
|
98
103
|
|
|
99
|
-
|
|
104
|
+
IDs are auto generated when creating resources. IDs in the JSON request body are ignored for any request.
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
### In-memory or MongoDB
|
|
109
|
+
|
|
110
|
+
By default data is stored in memory. This means the data is flushed when the server restarts. To persist your data, provide the `connectionString` config setting for your MongoDB database:
|
|
100
111
|
|
|
101
112
|
```js
|
|
102
113
|
const config = {
|
|
@@ -118,14 +129,6 @@ const server = temba.create(config)
|
|
|
118
129
|
|
|
119
130
|
Requests on these resources only give a `404 Not Found` if the ID does not exist. Requests on any other resource will always return a `404 Not Found`.
|
|
120
131
|
|
|
121
|
-
### JSON
|
|
122
|
-
|
|
123
|
-
Temba only supports JSON. If you send a request with invalid formatted JSON, a `400 Bad Request` response is returned.
|
|
124
|
-
|
|
125
|
-
When sending JSON data (`POST` and `PUT` requests), adding a `Content-Type: application/json` header is required.
|
|
126
|
-
|
|
127
|
-
IDs are auto generated when creating resources. IDs in the JSON request body are ignored.
|
|
128
|
-
|
|
129
132
|
### Static assets
|
|
130
133
|
|
|
131
134
|
If you want to host static assets next to the REST API, configure the `staticFolder`:
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "temba",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).",
|
|
5
|
-
"main": "dist/server.
|
|
5
|
+
"main": "dist/server.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "tsc",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts .",
|
|
7
|
+
"build": "rm -rf dist && tsc && cp package.json README.md ./dist",
|
|
8
|
+
"test": "jest --watch",
|
|
9
|
+
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
|
|
11
10
|
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
|
|
12
11
|
},
|
|
13
12
|
"repository": {
|
|
@@ -18,9 +17,7 @@
|
|
|
18
17
|
"author": "Bouwe (https://bouwe.io)",
|
|
19
18
|
"license": "ISC",
|
|
20
19
|
"files": [
|
|
21
|
-
"dist/**"
|
|
22
|
-
"package.json",
|
|
23
|
-
"!__tests__"
|
|
20
|
+
"dist/**"
|
|
24
21
|
],
|
|
25
22
|
"devDependencies": {
|
|
26
23
|
"@types/cors": "^2.8.12",
|
package/dist/config/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initConfig = void 0;
|
|
4
|
-
const logging_1 = require("../logging");
|
|
5
|
-
const defaultConfig = {
|
|
6
|
-
resourceNames: [],
|
|
7
|
-
validateResources: false,
|
|
8
|
-
logLevel: logging_1.logLevels.DEBUG,
|
|
9
|
-
staticFolder: null,
|
|
10
|
-
apiPrefix: '',
|
|
11
|
-
connectionString: null,
|
|
12
|
-
cacheControl: 'no-store',
|
|
13
|
-
delay: 0,
|
|
14
|
-
requestBodyValidator: {
|
|
15
|
-
post: () => {
|
|
16
|
-
// do nothing
|
|
17
|
-
},
|
|
18
|
-
put: () => {
|
|
19
|
-
// do nothing
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
function initConfig(userConfig) {
|
|
24
|
-
if (!userConfig)
|
|
25
|
-
return defaultConfig;
|
|
26
|
-
const config = Object.assign({}, defaultConfig);
|
|
27
|
-
if (userConfig.resourceNames && userConfig.resourceNames.length > 0) {
|
|
28
|
-
config.resourceNames = userConfig.resourceNames;
|
|
29
|
-
config.validateResources = true;
|
|
30
|
-
}
|
|
31
|
-
if (userConfig.logLevel &&
|
|
32
|
-
userConfig.logLevel.length !== 0 &&
|
|
33
|
-
Object.keys(logging_1.logLevels).includes(userConfig.logLevel.toUpperCase())) {
|
|
34
|
-
config.logLevel = userConfig.logLevel.toUpperCase();
|
|
35
|
-
}
|
|
36
|
-
if (userConfig.staticFolder) {
|
|
37
|
-
config.staticFolder = userConfig.staticFolder.replace(/[^a-zA-Z0-9]/g, '');
|
|
38
|
-
}
|
|
39
|
-
if (userConfig.apiPrefix) {
|
|
40
|
-
config.apiPrefix =
|
|
41
|
-
'/' + userConfig.apiPrefix.replace(/[^a-zA-Z0-9]/g, '') + '/';
|
|
42
|
-
}
|
|
43
|
-
if (userConfig.connectionString && userConfig.connectionString.length > 0) {
|
|
44
|
-
config.connectionString = userConfig.connectionString;
|
|
45
|
-
}
|
|
46
|
-
if (userConfig.cacheControl && userConfig.cacheControl.length > 0) {
|
|
47
|
-
config.cacheControl = userConfig.cacheControl;
|
|
48
|
-
}
|
|
49
|
-
if (userConfig.delay &&
|
|
50
|
-
userConfig.delay.length !== 0 &&
|
|
51
|
-
typeof Number(userConfig.delay) === 'number' &&
|
|
52
|
-
Number(userConfig.delay) > 0 &&
|
|
53
|
-
Number(userConfig.delay) < 10000) {
|
|
54
|
-
config.delay = Number(userConfig.delay);
|
|
55
|
-
}
|
|
56
|
-
if (userConfig.requestBodyValidator) {
|
|
57
|
-
if (userConfig.requestBodyValidator.post &&
|
|
58
|
-
typeof userConfig.requestBodyValidator.post === 'function') {
|
|
59
|
-
config.requestBodyValidator.post = userConfig.requestBodyValidator.post;
|
|
60
|
-
}
|
|
61
|
-
if (userConfig.requestBodyValidator.put &&
|
|
62
|
-
typeof userConfig.requestBodyValidator.put === 'function') {
|
|
63
|
-
config.requestBodyValidator.put = userConfig.requestBodyValidator.put;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return config;
|
|
67
|
-
}
|
|
68
|
-
exports.initConfig = initConfig;
|
|
69
|
-
//# sourceMappingURL=index.js.map
|
package/dist/config/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAAA,wCAAsC;AAEtC,MAAM,aAAa,GAAG;IACpB,aAAa,EAAE,EAAE;IACjB,iBAAiB,EAAE,KAAK;IACxB,QAAQ,EAAE,mBAAS,CAAC,KAAK;IACzB,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,GAAG,EAAE,GAAG,EAAE;YACR,aAAa;QACf,CAAC;KACF;CACF,CAAA;AAED,SAAgB,UAAU,CAAC,UAAU;IACnC,IAAI,CAAC,UAAU;QAAE,OAAO,aAAa,CAAA;IAErC,MAAM,MAAM,qBAAQ,aAAa,CAAE,CAAA;IAEnC,IAAI,UAAU,CAAC,aAAa,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;QACnE,MAAM,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAA;QAC/C,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAA;KAChC;IAED,IACE,UAAU,CAAC,QAAQ;QACnB,UAAU,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,mBAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,EAClE;QACA,MAAM,CAAC,QAAQ,G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AAC,oBAAoB,CAAC,GAAG;YACnC,OAAO,UAAU,CAAC,oBAAoB,CAAC,GAAG,KAAK,UAAU,EACzD;YACA,MAAM,CAAC,oBAAoB,CAAC,GAAG,GAAG,UAAU,CAAC,oBAAoB,CAAC,GAAG,CAAA;SACtE;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA7DD,gCA6DC"}
|
package/dist/delay/middleware.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createDelayMiddleware = void 0;
|
|
7
|
-
const connect_pause_1 = __importDefault(require("connect-pause"));
|
|
8
|
-
function createDelayMiddleware(delay) {
|
|
9
|
-
return function (req, res, next) {
|
|
10
|
-
console.log('Start delay...');
|
|
11
|
-
(0, connect_pause_1.default)(delay)(req, res, next);
|
|
12
|
-
console.log('Delay finished!');
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
exports.createDelayMiddleware = createDelayMiddleware;
|
|
16
|
-
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/delay/middleware.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAiC;AAEjC,SAAS,qBAAqB,CAAC,KAAK;IAClC,OAAO,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC7B,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QAC7B,IAAA,uBAAK,EAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAChC,CAAC,CAAA;AACH,CAAC;AAEQ,sDAAqB"}
|
package/dist/errors/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.new400BadRequestError = exports.new404NotFoundError = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
function new404NotFoundError(message = 'Not Found') {
|
|
6
|
-
return new types_1.TembaError(message, 404);
|
|
7
|
-
}
|
|
8
|
-
exports.new404NotFoundError = new404NotFoundError;
|
|
9
|
-
function new400BadRequestError(message = 'Bad Request') {
|
|
10
|
-
return new types_1.TembaError(message, 400);
|
|
11
|
-
}
|
|
12
|
-
exports.new400BadRequestError = new400BadRequestError;
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
package/dist/errors/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,SAAS,mBAAmB,CAAC,OAAO,GAAG,WAAW;IAChD,OAAO,IAAI,kBAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC;AAMQ,kDAAmB;AAJ5B,SAAS,qBAAqB,CAAC,OAAO,GAAG,aAAa;IACpD,OAAO,IAAI,kBAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC;AAE6B,sDAAqB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorHandler = void 0;
|
|
4
|
-
function errorHandler(err, _, res) {
|
|
5
|
-
console.log('errorHandler: ' + err.message);
|
|
6
|
-
if (!err.status)
|
|
7
|
-
err.status = 500;
|
|
8
|
-
return res.status(err.status).json({ message: err.message });
|
|
9
|
-
}
|
|
10
|
-
exports.errorHandler = errorHandler;
|
|
11
|
-
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/errors/middleware.ts"],"names":[],"mappings":";;;AAAA,SAAS,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG;IAC/B,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;IAE3C,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAA;IAEjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;AAC9D,CAAC;AAEQ,oCAAY"}
|
package/dist/errors/types.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TembaError = void 0;
|
|
4
|
-
class TembaError extends Error {
|
|
5
|
-
constructor(msg, status) {
|
|
6
|
-
super(msg);
|
|
7
|
-
this.status = status;
|
|
8
|
-
Object.setPrototypeOf(this, TembaError.prototype);
|
|
9
|
-
this.status = status;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.TembaError = TembaError;
|
|
13
|
-
//# sourceMappingURL=types.js.map
|
package/dist/errors/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/errors/types.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,GAAW,EAAS,MAAc;QAC5C,KAAK,CAAC,GAAG,CAAC,CAAA;QADoB,WAAM,GAAN,MAAM,CAAQ;QAE5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QAEjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAPD,gCAOC"}
|
package/dist/logging/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLogger = exports.logLevels = void 0;
|
|
4
|
-
const DEBUG = 'DEBUG';
|
|
5
|
-
const INFO = 'INFO';
|
|
6
|
-
//TODO Add 'NONE'
|
|
7
|
-
exports.logLevels = { DEBUG, INFO };
|
|
8
|
-
function createLogger(logLevel) {
|
|
9
|
-
return {
|
|
10
|
-
debug: function (message) {
|
|
11
|
-
try {
|
|
12
|
-
if (logLevel === DEBUG)
|
|
13
|
-
console.log(new Date(), 'DEBUG -', message);
|
|
14
|
-
}
|
|
15
|
-
catch (_a) {
|
|
16
|
-
//swallow exceptions during logging
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
info: function (message) {
|
|
20
|
-
try {
|
|
21
|
-
if (logLevel === DEBUG || logLevel === INFO)
|
|
22
|
-
console.info(new Date(), 'INFO -', message);
|
|
23
|
-
}
|
|
24
|
-
catch (_a) {
|
|
25
|
-
//swallow exceptions during logging
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
error: function (message) {
|
|
29
|
-
try {
|
|
30
|
-
console.error(new Date(), 'ERROR -', message);
|
|
31
|
-
}
|
|
32
|
-
catch (_a) {
|
|
33
|
-
//swallow exceptions during logging
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.createLogger = createLogger;
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAA;AACrB,MAAM,IAAI,GAAG,MAAM,CAAA;AACnB,iBAAiB;AAEJ,QAAA,SAAS,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AAExC,SAAgB,YAAY,CAAC,QAAQ;IACnC,OAAO;QACL,KAAK,EAAE,UAAU,OAAO;YACtB,IAAI;gBACF,IAAI,QAAQ,KAAK,KAAK;oBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aACpE;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;QAED,IAAI,EAAE,UAAU,OAAO;YACrB,IAAI;gBACF,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI;oBACzC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aAC/C;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;QAED,KAAK,EAAE,UAAU,OAAO;YACtB,IAAI;gBACF,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aAC9C;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AA3BD,oCA2BC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const data = {};
|
|
4
|
-
function connectToDatabase() {
|
|
5
|
-
// do nothing
|
|
6
|
-
}
|
|
7
|
-
function getAll(resourceName) {
|
|
8
|
-
createResourceArrayIfNecessary(resourceName);
|
|
9
|
-
return new Promise((resolve) => {
|
|
10
|
-
resolve(data[resourceName]);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function getById(resourceName, id) {
|
|
14
|
-
createResourceArrayIfNecessary(resourceName);
|
|
15
|
-
return new Promise((resolve) => {
|
|
16
|
-
resolve(data[resourceName].find((item) => item.id === id));
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function create(resourceName, item) {
|
|
20
|
-
createResourceArrayIfNecessary(resourceName);
|
|
21
|
-
const newItem = Object.assign(Object.assign({}, item), { id: String(new Date().getTime()) });
|
|
22
|
-
data[resourceName] = [...data[resourceName], newItem];
|
|
23
|
-
return new Promise((resolve) => {
|
|
24
|
-
resolve(newItem);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function update(resourceName, item) {
|
|
28
|
-
createResourceArrayIfNecessary(resourceName);
|
|
29
|
-
const updatedItem = Object.assign({}, item);
|
|
30
|
-
data[resourceName] = [
|
|
31
|
-
...data[resourceName].filter((r) => r.id !== item.id),
|
|
32
|
-
updatedItem,
|
|
33
|
-
];
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
resolve(updatedItem);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function deleteById(resourceName, id) {
|
|
39
|
-
createResourceArrayIfNecessary(resourceName);
|
|
40
|
-
data[resourceName] = data[resourceName].filter((item) => item.id !== id);
|
|
41
|
-
return new Promise((resolve) => {
|
|
42
|
-
resolve();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function deleteAll(resourceName) {
|
|
46
|
-
createResourceArrayIfNecessary(resourceName);
|
|
47
|
-
data[resourceName] = [];
|
|
48
|
-
return new Promise((resolve) => {
|
|
49
|
-
resolve([]);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function createResourceArrayIfNecessary(resourceName) {
|
|
53
|
-
if (!data.hasOwnProperty(resourceName))
|
|
54
|
-
data[resourceName] = [];
|
|
55
|
-
}
|
|
56
|
-
exports.default = {
|
|
57
|
-
connectToDatabase,
|
|
58
|
-
getAll,
|
|
59
|
-
getById,
|
|
60
|
-
create,
|
|
61
|
-
update,
|
|
62
|
-
deleteById,
|
|
63
|
-
deleteAll,
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=in-memory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.js","sourceRoot":"","sources":["../../src/queries/in-memory.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,EAAE,CAAA;AA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,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,WAAW;KACZ,CAAA;IACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,OAAO,CAAC,WAAW,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,YAAY,EAAE,EAAE;IAClC,8BAA8B,CAAC,YAAY,CAAC,CAAA;IAE5C,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACxE,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,YAAY;IAC7B,8BAA8B,CAAC,YAAY,CAAC,CAAA;IAE5C,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,OAAO,CAAC,EAAE,CAAC,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,8BAA8B,CAAC,YAAY;IAClD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC;QAAE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;AACjE,CAAC;AAED,kBAAe;IACb,iBAAiB;IACjB,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,UAAU;IACV,SAAS;CACV,CAAA"}
|
package/dist/queries/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createQueries = void 0;
|
|
7
|
-
const in_memory_1 = __importDefault(require("./in-memory"));
|
|
8
|
-
const mongo_1 = __importDefault(require("./mongo"));
|
|
9
|
-
function createQueries(connectionString) {
|
|
10
|
-
if (!connectionString) {
|
|
11
|
-
return in_memory_1.default;
|
|
12
|
-
}
|
|
13
|
-
const mongoQueries = (0, mongo_1.default)(connectionString);
|
|
14
|
-
return mongoQueries;
|
|
15
|
-
}
|
|
16
|
-
exports.createQueries = createQueries;
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAyC;AACzC,oDAAwC;AAExC,SAAS,aAAa,CAAC,gBAAgB;IACrC,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,mBAAe,CAAA;KACvB;IAED,MAAM,YAAY,GAAG,IAAA,eAAkB,EAAC,gBAAgB,CAAC,CAAA;IACzD,OAAO,YAAY,CAAA;AACrB,CAAC;AAEQ,sCAAa"}
|
package/dist/queries/mongo.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const mongo_1 = require("@rakered/mongo");
|
|
13
|
-
let uri;
|
|
14
|
-
let db;
|
|
15
|
-
function createMongoQueries(connectionString) {
|
|
16
|
-
uri = connectionString;
|
|
17
|
-
return {
|
|
18
|
-
connectToDatabase,
|
|
19
|
-
getAll,
|
|
20
|
-
getById,
|
|
21
|
-
create,
|
|
22
|
-
update,
|
|
23
|
-
deleteById,
|
|
24
|
-
deleteAll,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.default = createMongoQueries;
|
|
28
|
-
function connectToDatabase() {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
if (!db) {
|
|
31
|
-
console.log('Connecting...');
|
|
32
|
-
db = yield (0, mongo_1.connect)(uri);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function getAll(resourceName) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
yield connectToDatabase();
|
|
39
|
-
const items = yield db[resourceName].find({});
|
|
40
|
-
if (!items)
|
|
41
|
-
return [];
|
|
42
|
-
return items.map((item) => removeUnderscoreFromId(item));
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function getById(resourceName, id) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
yield connectToDatabase();
|
|
48
|
-
const item = yield db[resourceName].findOne({ _id: id });
|
|
49
|
-
if (!item)
|
|
50
|
-
return null;
|
|
51
|
-
return removeUnderscoreFromId(item);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function create(resourceName, item) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
yield connectToDatabase();
|
|
57
|
-
const createdItem = yield db[resourceName].insertOne(item);
|
|
58
|
-
return removeUnderscoreFromId(createdItem.ops[0]);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function update(resourceName, item) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
yield connectToDatabase();
|
|
64
|
-
const id = item.id;
|
|
65
|
-
delete item.id;
|
|
66
|
-
const updatedItem = yield db[resourceName].findOneAndUpdate({ _id: id }, { $set: item }, { returnOriginal: false });
|
|
67
|
-
return removeUnderscoreFromId(updatedItem.value);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function deleteById(resourceName, id) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
yield connectToDatabase();
|
|
73
|
-
yield db[resourceName].deleteOne({ _id: id });
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function deleteAll(resourceName) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
yield connectToDatabase();
|
|
79
|
-
yield db[resourceName].deleteMany({});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function removeUnderscoreFromId(item) {
|
|
83
|
-
const updatedItem = Object.assign(Object.assign({}, item), { id: item._id });
|
|
84
|
-
delete updatedItem._id;
|
|
85
|
-
return updatedItem;
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=mongo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/queries/mongo.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,0CAAwC;AAExC,IAAI,GAAG,CAAA;AACP,IAAI,EAAE,CAAA;AAEN,SAAwB,kBAAkB,CAAC,gBAAgB;IACzD,GAAG,GAAG,gBAAgB,CAAA;IAEtB,OAAO;QACL,iBAAiB;QACjB,MAAM;QACN,OAAO;QACP,MAAM;QACN,MAAM;QACN,UAAU;QACV,SAAS;KACV,CAAA;AACH,CAAC;AAZD,qCAYC;AAED,SAAe,iBAAiB;;QAC9B,IAAI,CAAC,EAAE,EAAE;YACP,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;YAC5B,EAAE,GAAG,MAAM,IAAA,eAAO,EAAC,GAAG,CAAC,CAAA;SAC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KAAK,EAAE,CAC1B,CAAA;QAED,OAAO,sBAAsB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;CAAA;AAED,SAAe,UAAU,CAAC,YAAY,EAAE,EAAE;;QACxC,MAAM,iBAAiB,EAAE,CAAA;QAEzB,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/C,CAAC;CAAA;AAED,SAAe,SAAS,CAAC,YAAY;;QACnC,MAAM,iBAAiB,EAAE,CAAA;QAEzB,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACvC,CAAC;CAAA;AAED,SAAS,sBAAsB,CAAC,IAAI;IAClC,MAAM,WAAW,mCAAQ,IAAI,KAAE,EAAE,EAAE,IAAI,CAAC,GAAG,GAAE,CAAA;IAC7C,OAAO,WAAW,CAAC,GAAG,CAAA;IACtB,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/dist/routes/delete.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createDeleteRoutes = void 0;
|
|
13
|
-
function createDeleteRoutes(queries) {
|
|
14
|
-
function handleDelete(req, res, next) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
try {
|
|
17
|
-
const { resourceName, id } = req.requestInfo;
|
|
18
|
-
if (id) {
|
|
19
|
-
const item = yield queries.getById(resourceName, id);
|
|
20
|
-
if (item) {
|
|
21
|
-
yield queries.deleteById(resourceName, id);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
yield queries.deleteAll(resourceName);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
return next(error);
|
|
30
|
-
}
|
|
31
|
-
return res.status(204).send();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
handleDelete,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.createDeleteRoutes = createDeleteRoutes;
|
|
39
|
-
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,KAAK,EAAE;gBACd,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"}
|
package/dist/routes/get.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createGetRoutes = void 0;
|
|
13
|
-
function createGetRoutes(queries, cacheControl) {
|
|
14
|
-
function handleGetResource(req, res, next) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
try {
|
|
17
|
-
const { resourceName, id } = req.requestInfo;
|
|
18
|
-
res.set('Cache-control', cacheControl);
|
|
19
|
-
if (id) {
|
|
20
|
-
const item = yield queries.getById(resourceName, id);
|
|
21
|
-
if (!item) {
|
|
22
|
-
res.status(404);
|
|
23
|
-
return res.send();
|
|
24
|
-
}
|
|
25
|
-
res.status(200);
|
|
26
|
-
res.json(item);
|
|
27
|
-
return res.send();
|
|
28
|
-
}
|
|
29
|
-
const items = yield queries.getAll(resourceName);
|
|
30
|
-
res.status(200);
|
|
31
|
-
res.json(items);
|
|
32
|
-
return res.send();
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return next(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
handleGetResource,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createGetRoutes = createGetRoutes;
|
|
44
|
-
//# sourceMappingURL=get.js.map
|
package/dist/routes/get.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/routes/get.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,eAAe,CAAC,OAAO,EAAE,YAAY;IAC5C,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,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,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBACf,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACd,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;iBAClB;gBAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;gBAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBACf,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACf,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;aAClB;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;IAED,OAAO;QACL,iBAAiB;KAClB,CAAA;AACH,CAAC;AAEQ,0CAAe"}
|
package/dist/routes/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.handleNotFound = exports.handleMethodNotAllowed = exports.rootRouter = exports.createResourceRouter = void 0;
|
|
16
|
-
const get_1 = require("./get");
|
|
17
|
-
const post_1 = require("./post");
|
|
18
|
-
const put_1 = require("./put");
|
|
19
|
-
const delete_1 = require("./delete");
|
|
20
|
-
const middleware_1 = require("../urls/middleware");
|
|
21
|
-
const express_1 = __importDefault(require("express"));
|
|
22
|
-
function createResourceRouter(queries, { validateResources, resourceNames, apiPrefix, cacheControl, requestBodyValidator, }) {
|
|
23
|
-
const { handleGetResource } = (0, get_1.createGetRoutes)(queries, cacheControl);
|
|
24
|
-
const { handlePost } = (0, post_1.createPostRoutes)(queries, requestBodyValidator);
|
|
25
|
-
const { handlePut } = (0, put_1.createPutRoutes)(queries, requestBodyValidator);
|
|
26
|
-
const { handleDelete } = (0, delete_1.createDeleteRoutes)(queries);
|
|
27
|
-
const validateResource = (0, middleware_1.createValidateResourceMiddleware)(validateResources, resourceNames);
|
|
28
|
-
const getResourceAndId = (0, middleware_1.createResourceAndIdParser)(apiPrefix);
|
|
29
|
-
var resourceRouter = express_1.default.Router();
|
|
30
|
-
resourceRouter
|
|
31
|
-
.get('*', getResourceAndId, validateResource, handleGetResource)
|
|
32
|
-
.post('*', getResourceAndId, validateResource, handlePost)
|
|
33
|
-
.put('*', getResourceAndId, validateResource, handlePut)
|
|
34
|
-
.delete('*', getResourceAndId, validateResource, handleDelete);
|
|
35
|
-
return resourceRouter;
|
|
36
|
-
}
|
|
37
|
-
exports.createResourceRouter = createResourceRouter;
|
|
38
|
-
// A GET to the root URL shows a default message.
|
|
39
|
-
const rootRouter = express_1.default.Router();
|
|
40
|
-
exports.rootRouter = rootRouter;
|
|
41
|
-
rootRouter.get('/', (_, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
return res.send('It works! ツ');
|
|
43
|
-
}));
|
|
44
|
-
// All other requests to the root URL are not allowed.
|
|
45
|
-
rootRouter.all('/', handleMethodNotAllowed);
|
|
46
|
-
// Route for handling not allowed methods.
|
|
47
|
-
function handleMethodNotAllowed(_, res) {
|
|
48
|
-
res.status(405).json({ message: 'Method Not Allowed' });
|
|
49
|
-
}
|
|
50
|
-
exports.handleMethodNotAllowed = handleMethodNotAllowed;
|
|
51
|
-
// Route for handling not found.
|
|
52
|
-
function handleNotFound(_, res) {
|
|
53
|
-
res.status(404).json({ message: 'Not Found' });
|
|
54
|
-
}
|
|
55
|
-
exports.handleNotFound = handleNotFound;
|
|
56
|
-
//# sourceMappingURL=index.js.map
|
package/dist/routes/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,qCAA6C;AAC7C,mDAG2B;AAE3B,sDAA6B;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AC,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;AAUC,wDAAsB;AARxB,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;AAMC,wCAAc"}
|
package/dist/routes/post.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createPostRoutes = void 0;
|
|
13
|
-
const url_1 = require("url");
|
|
14
|
-
const validator_1 = require("./validator");
|
|
15
|
-
function createPostRoutes(queries, requestBodyValidator) {
|
|
16
|
-
function handlePost(req, res, next) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
try {
|
|
19
|
-
const { resourceName } = req.requestInfo;
|
|
20
|
-
const requestBody = (0, validator_1.validateRequestBody)(requestBodyValidator.post, resourceName, req.body);
|
|
21
|
-
const newItem = yield queries.create(resourceName, requestBody);
|
|
22
|
-
return res
|
|
23
|
-
.set({
|
|
24
|
-
Location: (0, url_1.format)({
|
|
25
|
-
protocol: req.protocol,
|
|
26
|
-
host: req.get('host'),
|
|
27
|
-
pathname: `${resourceName}/${newItem.id}`,
|
|
28
|
-
}),
|
|
29
|
-
})
|
|
30
|
-
.status(201)
|
|
31
|
-
.json(newItem)
|
|
32
|
-
.send();
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return next(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
handlePost,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createPostRoutes = createPostRoutes;
|
|
44
|
-
//# sourceMappingURL=post.js.map
|
package/dist/routes/post.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,EACrC,oBAAoB,CAAC,IAAI,EACzB,YAAY,EACZ,GAAG,CAAC,IAAI,CACT,CAAA;gBAED,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,KAAK,EAAE;gBACd,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;IAED,OAAO;QACL,UAAU;KACX,CAAA;AACH,CAAC;AAEQ,4CAAgB"}
|
package/dist/routes/put.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createPutRoutes = void 0;
|
|
13
|
-
const errors_1 = require("../errors");
|
|
14
|
-
const validator_1 = require("./validator");
|
|
15
|
-
function createPutRoutes(queries, requestBodyValidator) {
|
|
16
|
-
function handlePut(req, res, next) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
try {
|
|
19
|
-
const { resourceName, id } = req.requestInfo;
|
|
20
|
-
const requestBody = (0, validator_1.validateRequestBody)(requestBodyValidator.put, resourceName, req.body);
|
|
21
|
-
let item = null;
|
|
22
|
-
if (id)
|
|
23
|
-
item = yield queries.getById(resourceName, id);
|
|
24
|
-
if (!item)
|
|
25
|
-
return next((0, errors_1.new404NotFoundError)(`ID '${id}' not found`));
|
|
26
|
-
item = Object.assign(Object.assign({}, requestBody), { id });
|
|
27
|
-
const updatedItem = yield queries.update(resourceName, item);
|
|
28
|
-
return res.status(200).json(updatedItem).send();
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
return next(error);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
handlePut,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
exports.createPutRoutes = createPutRoutes;
|
|
40
|
-
//# sourceMappingURL=put.js.map
|
package/dist/routes/put.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"put.js","sourceRoot":"","sources":["../../src/routes/put.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA+C;AAC/C,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,CAAC,WAAW,CAAA;gBAE5C,MAAM,WAAW,GAAG,IAAA,+BAAmB,EACrC,oBAAoB,CAAC,GAAG,EACxB,YAAY,EACZ,GAAG,CAAC,IAAI,CACT,CAAA;gBAED,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;oBAAE,OAAO,IAAI,CAAC,IAAA,4BAAmB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAA;gBAEnE,IAAI,mCAAQ,WAAW,KAAE,EAAE,GAAE,CAAA;gBAE7B,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,KAAK,EAAE;gBACd,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;IAED,OAAO;QACL,SAAS;KACV,CAAA;AACH,CAAC;AAEQ,0CAAe"}
|
package/dist/routes/validator.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequestBody = void 0;
|
|
4
|
-
const errors_1 = require("../errors");
|
|
5
|
-
function validateRequestBody(validator, resourceName, requestBody) {
|
|
6
|
-
const validationResult = validator(resourceName, requestBody);
|
|
7
|
-
if (!validationResult)
|
|
8
|
-
return requestBody;
|
|
9
|
-
if (typeof validationResult === 'string') {
|
|
10
|
-
throw (0, errors_1.new400BadRequestError)(validationResult);
|
|
11
|
-
}
|
|
12
|
-
// The requestBody was replaced by something else.
|
|
13
|
-
if (validationResult)
|
|
14
|
-
requestBody = validationResult;
|
|
15
|
-
return requestBody;
|
|
16
|
-
}
|
|
17
|
-
exports.validateRequestBody = validateRequestBody;
|
|
18
|
-
//# sourceMappingURL=validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/routes/validator.ts"],"names":[],"mappings":";;;AAAA,sCAAiD;AAEjD,SAAS,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW;IAC/D,MAAM,gBAAgB,GAAG,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IAE7D,IAAI,CAAC,gBAAgB;QAAE,OAAO,WAAW,CAAA;IAEzC,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;QACxC,MAAM,IAAA,8BAAqB,EAAC,gBAAgB,CAAC,CAAA;KAC9C;IAED,kDAAkD;IAClD,IAAI,gBAAgB;QAAE,WAAW,GAAG,gBAAgB,CAAA;IAEpD,OAAO,WAAW,CAAA;AACpB,CAAC;AAEQ,kDAAmB"}
|
package/dist/server.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.create = void 0;
|
|
26
|
-
const express_1 = __importStar(require("express"));
|
|
27
|
-
const morgan_1 = __importDefault(require("morgan"));
|
|
28
|
-
const middleware_1 = require("./errors/middleware");
|
|
29
|
-
const routes_1 = require("./routes");
|
|
30
|
-
const queries_1 = require("./queries");
|
|
31
|
-
const config_1 = require("./config");
|
|
32
|
-
const cors_1 = __importDefault(require("cors"));
|
|
33
|
-
const middleware_2 = require("./delay/middleware");
|
|
34
|
-
function createServer(userConfig) {
|
|
35
|
-
const config = (0, config_1.initConfig)(userConfig);
|
|
36
|
-
const queries = (0, queries_1.createQueries)(config.connectionString);
|
|
37
|
-
const app = (0, express_1.default)();
|
|
38
|
-
app.use((0, express_1.json)());
|
|
39
|
-
// Add HTTP request logging.
|
|
40
|
-
app.use((0, morgan_1.default)('tiny'));
|
|
41
|
-
// Enable CORS for all requests.
|
|
42
|
-
app.use((0, cors_1.default)({ origin: true, credentials: true }));
|
|
43
|
-
if (config.delay > 0) {
|
|
44
|
-
const delayMiddleware = (0, middleware_2.createDelayMiddleware)(config.delay);
|
|
45
|
-
app.use(delayMiddleware);
|
|
46
|
-
}
|
|
47
|
-
// Serve a static folder, if configured.
|
|
48
|
-
if (config.staticFolder) {
|
|
49
|
-
app.use(express_1.default.static(config.staticFolder));
|
|
50
|
-
}
|
|
51
|
-
// On the root URL (with apiPrefix if applicable) only a GET is allowed.
|
|
52
|
-
const rootPath = config.apiPrefix ? `${config.apiPrefix}` : '/';
|
|
53
|
-
app.use(rootPath, routes_1.rootRouter);
|
|
54
|
-
// For all other URLs, only GET, POST, PUT and DELETE are allowed and handled.
|
|
55
|
-
const resourceRouter = (0, routes_1.createResourceRouter)(queries, config);
|
|
56
|
-
const resourcePath = config.apiPrefix ? `${config.apiPrefix}*` : '*';
|
|
57
|
-
app.use(resourcePath, resourceRouter);
|
|
58
|
-
// In case of an API prefix, GET, POST, PUT and DELETE requests to all other URLs return a 404 Not Found.
|
|
59
|
-
if (config.apiPrefix) {
|
|
60
|
-
app.get('*', routes_1.handleNotFound);
|
|
61
|
-
app.post('*', routes_1.handleNotFound);
|
|
62
|
-
app.put('*', routes_1.handleNotFound);
|
|
63
|
-
app.delete('*', routes_1.handleNotFound);
|
|
64
|
-
}
|
|
65
|
-
// All other methods to any URL are not allowed.
|
|
66
|
-
app.all('*', routes_1.handleMethodNotAllowed);
|
|
67
|
-
if (config.apiPrefix)
|
|
68
|
-
app.all(`${config.apiPrefix}*`, routes_1.handleMethodNotAllowed);
|
|
69
|
-
// Error middleware.
|
|
70
|
-
app.use(middleware_1.errorHandler);
|
|
71
|
-
return app;
|
|
72
|
-
}
|
|
73
|
-
function create(userConfig) {
|
|
74
|
-
return createServer(userConfig);
|
|
75
|
-
}
|
|
76
|
-
exports.create = create;
|
|
77
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,oDAA2B;AAC3B,oDAAkD;AAClD,qCAKiB;AACjB,uCAAyC;AACzC,qCAAqC;AACrC,gDAAuB;AACvB,mDAA0D;AAE1D,SAAS,YAAY,CAAC,UAAU;IAC9B,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,kCAAqB,EAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3D,GAAG,CAA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,GAAG,CAAA;AACZ,CAAC;AAED,SAAgB,MAAM,CAAC,UAAU;IAC/B,OAAO,YAAY,CAAC,UAAU,CAAC,CAAA;AACjC,CAAC;AAFD,wBAEC"}
|
package/dist/urls/middleware.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createValidateResourceMiddleware = exports.createResourceAndIdParser = void 0;
|
|
4
|
-
const errors_1 = require("../errors");
|
|
5
|
-
const urlParser_1 = require("./urlParser");
|
|
6
|
-
function createResourceAndIdParser(apiPrefix) {
|
|
7
|
-
return function getResourceAndId(req, _, next) {
|
|
8
|
-
const url = req.baseUrl.replace(apiPrefix, '');
|
|
9
|
-
let urlInfo = (0, urlParser_1.parseUrl)(url);
|
|
10
|
-
req.requestInfo = Object.assign(Object.assign({}, req.requestInfo), urlInfo);
|
|
11
|
-
return next();
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
exports.createResourceAndIdParser = createResourceAndIdParser;
|
|
15
|
-
function createValidateResourceMiddleware(validateResources, resourceNames) {
|
|
16
|
-
return function validateResource(req, _, next) {
|
|
17
|
-
if (!validateResources)
|
|
18
|
-
return next();
|
|
19
|
-
const { resourceName } = req.requestInfo;
|
|
20
|
-
if (!resourceName)
|
|
21
|
-
return next();
|
|
22
|
-
if (!resourceNames.includes(resourceName.toLowerCase())) {
|
|
23
|
-
const error = (0, errors_1.new404NotFoundError)(`'${resourceName}' is an unknown resource`);
|
|
24
|
-
return next(error);
|
|
25
|
-
}
|
|
26
|
-
return next();
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
exports.createValidateResourceMiddleware = createValidateResourceMiddleware;
|
|
30
|
-
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/urls/middleware.ts"],"names":[],"mappings":";;;AAAA,sCAA+C;AAC/C,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,IAAI,OAAO,GAAG,IAAA,oBAAQ,EAAC,GAAG,CAAC,CAAA;QAE3B,GAAG,CAAC,WAAW,mCAAQ,GAAG,CAAC,WAAW,GAAK,OAAO,CAAE,CAAA;QAEpD,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAqBQ,8DAAyB;AAnBlC,SAAS,gCAAgC,CAAC,iBAAiB,EAAE,aAAa;IACxE,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI;QAC3C,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,MAAM,KAAK,GAAG,IAAA,4BAAmB,EAC/B,IAAI,YAAY,0BAA0B,CAC3C,CAAA;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;SACnB;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAEmC,4EAAgC"}
|
package/dist/urls/urlParser.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseUrl = void 0;
|
|
4
|
-
function parseUrl(url) {
|
|
5
|
-
if (!url || (url && !url.trim()))
|
|
6
|
-
return { resourceName: null, id: null };
|
|
7
|
-
const urlSegments = url.split('/').filter((i) => i);
|
|
8
|
-
const resourceName = urlSegments.length > 0 ? urlSegments[0] : null;
|
|
9
|
-
const id = urlSegments.length > 1 ? urlSegments[1] : null;
|
|
10
|
-
return { resourceName, id };
|
|
11
|
-
}
|
|
12
|
-
exports.parseUrl = parseUrl;
|
|
13
|
-
//# sourceMappingURL=urlParser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urlParser.js","sourceRoot":"","sources":["../../src/urls/urlParser.ts"],"names":[],"mappings":";;;AAAA,SAAS,QAAQ,CAAC,GAAG;IACnB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;IAEzE,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAEnD,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACnE,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAEzD,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA;AAC7B,CAAC;AAEQ,4BAAQ"}
|