@centeredgesoft/runtime-mock-routes 2.1.0 → 2.5.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/.devcontainer/Dockerfile +16 -0
- package/.devcontainer/devcontainer.json +32 -0
- package/LICENSE +20 -20
- package/README.md +100 -93
- package/build/index.d.ts +2 -2
- package/build/index.js +24 -24
- package/build/run.d.ts +2 -2
- package/build/run.js +32 -32
- package/build/src/app.d.ts +27 -27
- package/build/src/app.js +188 -180
- package/build/src/appV2.d.ts +30 -23
- package/build/src/appV2.js +196 -177
- package/index.ts +1 -1
- package/jest.config.js +3 -3
- package/package.json +53 -55
- package/run.ts +38 -38
- package/src/app.test.ts +212 -212
- package/src/app.ts +234 -234
- package/src/appV2.test.ts +320 -261
- package/src/appV2.ts +257 -227
- package/tsconfig.json +15 -15
- package/.env +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/typescript-node/.devcontainer/base.Dockerfile
|
|
2
|
+
|
|
3
|
+
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
|
|
4
|
+
ARG VARIANT="16-bullseye"
|
|
5
|
+
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
|
|
6
|
+
|
|
7
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
|
8
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
9
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
10
|
+
|
|
11
|
+
# [Optional] Uncomment if you want to install an additional version of node using nvm
|
|
12
|
+
# ARG EXTRA_NODE_VERSION=10
|
|
13
|
+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
|
|
14
|
+
|
|
15
|
+
# [Optional] Uncomment if you want to install more global node packages
|
|
16
|
+
# RUN su node -c "npm install -g <your-package-list -here>"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/typescript-node
|
|
3
|
+
{
|
|
4
|
+
"name": "Node.js & TypeScript",
|
|
5
|
+
"build": {
|
|
6
|
+
"dockerfile": "Dockerfile",
|
|
7
|
+
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
|
|
8
|
+
// Append -bullseye or -buster to pin to an OS version.
|
|
9
|
+
// Use -bullseye variants on local on arm64/Apple Silicon.
|
|
10
|
+
"args": {
|
|
11
|
+
"VARIANT": "16-bullseye"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
// Set *default* container specific settings.json values on container create.
|
|
16
|
+
"settings": {},
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// Add the IDs of extensions you want installed when the container is created.
|
|
20
|
+
"extensions": [
|
|
21
|
+
"dbaeumer.vscode-eslint"
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
25
|
+
// "forwardPorts": [],
|
|
26
|
+
|
|
27
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
|
28
|
+
// "postCreateCommand": "yarn install",
|
|
29
|
+
|
|
30
|
+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
|
31
|
+
"remoteUser": "node"
|
|
32
|
+
}
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 CenterEdge Software
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 CenterEdge Software
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,94 +1,101 @@
|
|
|
1
|
-
# Runtime-Mock-Routes
|
|
2
|
-
|
|
3
|
-
Runtime-Mock-Routes is a nodejs application for defining parameterized route and response bodies. This is ideal for mocking 3rd party services.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Use the package manager [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/) to install Runtime-Mock-Routes.
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install -g @centeredgesoft/runtime-mock-routes
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
runtime-mock-routes -p 8080 -s ./seed.json
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
All command line options are optional. If a seed file is supplied, it must be one of the following
|
|
20
|
-
* a json file that matches a `RuntimeRequestCollection`
|
|
21
|
-
* a js file with a default export of type `RuntimeRequestCollection`
|
|
22
|
-
* a js file with a default export of a function that returns a `RuntimeRequestCollection`
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
type SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
26
|
-
const SupportedMethodsColection: SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
27
|
-
type SupportedMethod = SupportedMethodsType[number];
|
|
28
|
-
|
|
29
|
-
export interface RuntimeRequestMethodBody {
|
|
30
|
-
body: any;
|
|
31
|
-
status?: number;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
# Runtime-Mock-Routes
|
|
2
|
+
|
|
3
|
+
Runtime-Mock-Routes is a nodejs application for defining parameterized route and response bodies. This is ideal for mocking 3rd party services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Use the package manager [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/) to install Runtime-Mock-Routes.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @centeredgesoft/runtime-mock-routes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
runtime-mock-routes -p 8080 -s ./seed.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
All command line options are optional. If a seed file is supplied, it must be one of the following
|
|
20
|
+
* a json file that matches a `RuntimeRequestCollection`
|
|
21
|
+
* a js file with a default export of type `RuntimeRequestCollection`
|
|
22
|
+
* a js file with a default export of a function that returns a `RuntimeRequestCollection`
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
type SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
26
|
+
const SupportedMethodsColection: SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
27
|
+
type SupportedMethod = SupportedMethodsType[number];
|
|
28
|
+
|
|
29
|
+
export interface RuntimeRequestMethodBody {
|
|
30
|
+
body: any;
|
|
31
|
+
status?: number | ((...args : any[])=>number);
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type RuntimeRequestMethodBodyCollection = Partial<Record<SupportedMethod, RuntimeRequestMethodBody>>;
|
|
36
|
+
|
|
37
|
+
export interface RuntimeRequestBody {
|
|
38
|
+
path: string;
|
|
39
|
+
methods: RuntimeRequestMethodBodyCollection;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface RuntimeRequestCollection {
|
|
43
|
+
[path: string]: RuntimeRequestBody;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For example:
|
|
48
|
+
```JSON
|
|
49
|
+
{
|
|
50
|
+
"/test":{
|
|
51
|
+
"path":"/test",
|
|
52
|
+
"methods":{
|
|
53
|
+
"GET": {
|
|
54
|
+
"body": {},
|
|
55
|
+
"status": 200,
|
|
56
|
+
"headers": {
|
|
57
|
+
"X-Custom-Header": "yes"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The following environment variables can also be used in place of command line options
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
RUNTIME_MOCK_ROUTES_PORT=8080
|
|
69
|
+
RUNTIME_MOCK_ROUTES_FILE_PATH=/seed.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Route parameters are specified in path via a colon followed by the parameter name.
|
|
73
|
+
`'/users/:id'`
|
|
74
|
+
|
|
75
|
+
Template strings that are compatible with [handlebars](https://handlebarsjs.com/) can be used for the `body` property of a `RuntimeRequestMethodBody`. The application will use path and query params as data for the tempalte. This application makes use of [faker](https://www.npmjs.com/package/faker) and [chance](https://www.npmjs.com/package/chance) as Handlebars Helpers.
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
{{params.<path-param-name>}} {{query.<query-param-name>}}
|
|
79
|
+
{{body.<post-body-property>}}
|
|
80
|
+
{{headers.<header-property-name>}}
|
|
81
|
+
{{ faker "lorem.words" 5}} {{ chance "guid"}}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If the rendered template is valid JSON, the response will be of type `application/json`.
|
|
85
|
+
|
|
86
|
+
Also, be aware that instead of a direct JSON response, the body can also be a function that takes in a `RequestParameters` and returns a body response. The response will still be processed through handlebars.
|
|
87
|
+
|
|
88
|
+
### Routes
|
|
89
|
+
* `GET /` returns all of the currently defined routes
|
|
90
|
+
* `POST /` Takes a `RuntimeRequestBody` and adds it to the collection or updates the existing entry if it exists.
|
|
91
|
+
* `PUT /` Takes a `RuntimeRequestCollection` and replaces the current collection.
|
|
92
|
+
* `[GET,POST,PUT,PATCH,DELETE] /*` The result of retrieving an entry in the collection, 404 otherwise
|
|
93
|
+
* `DELETE /?path=<path>` Deletes items from the collection
|
|
94
|
+
|
|
95
|
+
## Contributing
|
|
96
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
97
|
+
|
|
98
|
+
Please make sure to add/update tests as appropriate.
|
|
99
|
+
|
|
100
|
+
## License
|
|
94
101
|
[MIT](https://choosealicense.com/licenses/mit/)
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * as appV1 from './src/app';
|
|
2
|
-
export * as appV2 from './src/appV2';
|
|
1
|
+
export * as appV1 from './src/app';
|
|
2
|
+
export * as appV2 from './src/appV2';
|
package/build/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.appV2 = exports.appV1 = void 0;
|
|
23
|
-
exports.appV1 = __importStar(require("./src/app"));
|
|
24
|
-
exports.appV2 = __importStar(require("./src/appV2"));
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.appV2 = exports.appV1 = void 0;
|
|
23
|
+
exports.appV1 = __importStar(require("./src/app"));
|
|
24
|
+
exports.appV2 = __importStar(require("./src/appV2"));
|
package/build/run.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/build/run.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const app_1 = require("./src/app");
|
|
7
|
-
const appV2_1 = require("./src/appV2");
|
|
8
|
-
var AppVersion;
|
|
9
|
-
(function (AppVersion) {
|
|
10
|
-
AppVersion["v1"] = "v1";
|
|
11
|
-
AppVersion["v2"] = "v2";
|
|
12
|
-
})(AppVersion || (AppVersion = {}));
|
|
13
|
-
commander_1.program.version("2.1.0")
|
|
14
|
-
.option("-p, --port <port>", "Port to run the server one", process.env.RUNTIME_MOCK_ROUTES_PORT || "8080")
|
|
15
|
-
.option("-s, --seed <filePath>", "File path to seed the application", process.env.RUNTIME_MOCK_ROUTES_FILE_PATH)
|
|
16
|
-
.option("-a, --appVersion <appVersion>", "App Version to use", AppVersion.v2);
|
|
17
|
-
commander_1.program.parse(process.argv);
|
|
18
|
-
let initialRequests = {};
|
|
19
|
-
if (commander_1.program.seed) {
|
|
20
|
-
const filePath = path_1.resolve(commander_1.program.seed);
|
|
21
|
-
const funcOrJson = require(filePath);
|
|
22
|
-
initialRequests = typeof funcOrJson === 'function' ? funcOrJson() : funcOrJson;
|
|
23
|
-
}
|
|
24
|
-
const appVersions = {
|
|
25
|
-
v1: app_1.appFactory,
|
|
26
|
-
v2: appV2_1.appFactory
|
|
27
|
-
};
|
|
28
|
-
const appFactory = appVersions[commander_1.program.appVersion] || appV2_1.appFactory;
|
|
29
|
-
const app = appFactory(initialRequests);
|
|
30
|
-
app.listen(commander_1.program.port, () => {
|
|
31
|
-
console.log(`⚡️[server]: Server is running at http://localhost:${commander_1.program.port}`);
|
|
32
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const app_1 = require("./src/app");
|
|
7
|
+
const appV2_1 = require("./src/appV2");
|
|
8
|
+
var AppVersion;
|
|
9
|
+
(function (AppVersion) {
|
|
10
|
+
AppVersion["v1"] = "v1";
|
|
11
|
+
AppVersion["v2"] = "v2";
|
|
12
|
+
})(AppVersion || (AppVersion = {}));
|
|
13
|
+
commander_1.program.version("2.1.0")
|
|
14
|
+
.option("-p, --port <port>", "Port to run the server one", process.env.RUNTIME_MOCK_ROUTES_PORT || "8080")
|
|
15
|
+
.option("-s, --seed <filePath>", "File path to seed the application", process.env.RUNTIME_MOCK_ROUTES_FILE_PATH)
|
|
16
|
+
.option("-a, --appVersion <appVersion>", "App Version to use", AppVersion.v2);
|
|
17
|
+
commander_1.program.parse(process.argv);
|
|
18
|
+
let initialRequests = {};
|
|
19
|
+
if (commander_1.program.seed) {
|
|
20
|
+
const filePath = path_1.resolve(commander_1.program.seed);
|
|
21
|
+
const funcOrJson = require(filePath);
|
|
22
|
+
initialRequests = typeof funcOrJson === 'function' ? funcOrJson() : funcOrJson;
|
|
23
|
+
}
|
|
24
|
+
const appVersions = {
|
|
25
|
+
v1: app_1.appFactory,
|
|
26
|
+
v2: appV2_1.appFactory
|
|
27
|
+
};
|
|
28
|
+
const appFactory = appVersions[commander_1.program.appVersion] || appV2_1.appFactory;
|
|
29
|
+
const app = appFactory(initialRequests);
|
|
30
|
+
app.listen(commander_1.program.port, () => {
|
|
31
|
+
console.log(`⚡️[server]: Server is running at http://localhost:${commander_1.program.port}`);
|
|
32
|
+
});
|
package/build/src/app.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
declare type SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
2
|
-
export declare const SupportedMethodsColection: SupportedMethodsType;
|
|
3
|
-
export declare type SupportedMethod = SupportedMethodsType[number];
|
|
4
|
-
export declare const isSupportedMethod: (obj: any) => obj is "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
5
|
-
export interface RuntimeRequestBody {
|
|
6
|
-
path: string;
|
|
7
|
-
body: any;
|
|
8
|
-
method: SupportedMethod;
|
|
9
|
-
status?: number;
|
|
10
|
-
}
|
|
11
|
-
export declare const isRuntimeRequestBody: (obj: any) => obj is RuntimeRequestBody;
|
|
12
|
-
export interface RuntimeRequestCollection {
|
|
13
|
-
[path: string]: RuntimeRequestBody;
|
|
14
|
-
}
|
|
15
|
-
export declare const isRuntimeRequestCollection: (obj: any) => obj is RuntimeRequestCollection;
|
|
16
|
-
export declare type MethodBasedRuntimeRequestCollection = Partial<Record<SupportedMethod, RuntimeRequestCollection>>;
|
|
17
|
-
export declare const isMethodBasedRuntimeRequestCollection: (obj: any) => obj is Partial<Record<"GET" | "POST" | "PUT" | "PATCH" | "DELETE", RuntimeRequestCollection>>;
|
|
18
|
-
interface CleanRuntimeRequestCollectionParams {
|
|
19
|
-
collection: RuntimeRequestCollection;
|
|
20
|
-
method: SupportedMethod;
|
|
21
|
-
}
|
|
22
|
-
export declare const cleanRuntimeRequestCollection: (params: CleanRuntimeRequestCollectionParams) => RuntimeRequestCollection;
|
|
23
|
-
export declare const cleanMethodBasedRuntimeRequestCollection: (obj: MethodBasedRuntimeRequestCollection) => MethodBasedRuntimeRequestCollection;
|
|
24
|
-
export declare const singleQueryParam: (obj: any) => string;
|
|
25
|
-
export declare const appFactory: (runtimeCollection?: MethodBasedRuntimeRequestCollection) => import("express-serve-static-core").Express;
|
|
26
|
-
declare const app: import("express-serve-static-core").Express;
|
|
27
|
-
export default app;
|
|
1
|
+
declare type SupportedMethodsType = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
2
|
+
export declare const SupportedMethodsColection: SupportedMethodsType;
|
|
3
|
+
export declare type SupportedMethod = SupportedMethodsType[number];
|
|
4
|
+
export declare const isSupportedMethod: (obj: any) => obj is "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
5
|
+
export interface RuntimeRequestBody {
|
|
6
|
+
path: string;
|
|
7
|
+
body: any;
|
|
8
|
+
method: SupportedMethod;
|
|
9
|
+
status?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const isRuntimeRequestBody: (obj: any) => obj is RuntimeRequestBody;
|
|
12
|
+
export interface RuntimeRequestCollection {
|
|
13
|
+
[path: string]: RuntimeRequestBody;
|
|
14
|
+
}
|
|
15
|
+
export declare const isRuntimeRequestCollection: (obj: any) => obj is RuntimeRequestCollection;
|
|
16
|
+
export declare type MethodBasedRuntimeRequestCollection = Partial<Record<SupportedMethod, RuntimeRequestCollection>>;
|
|
17
|
+
export declare const isMethodBasedRuntimeRequestCollection: (obj: any) => obj is Partial<Record<"GET" | "POST" | "PUT" | "PATCH" | "DELETE", RuntimeRequestCollection>>;
|
|
18
|
+
interface CleanRuntimeRequestCollectionParams {
|
|
19
|
+
collection: RuntimeRequestCollection;
|
|
20
|
+
method: SupportedMethod;
|
|
21
|
+
}
|
|
22
|
+
export declare const cleanRuntimeRequestCollection: (params: CleanRuntimeRequestCollectionParams) => RuntimeRequestCollection;
|
|
23
|
+
export declare const cleanMethodBasedRuntimeRequestCollection: (obj: MethodBasedRuntimeRequestCollection) => MethodBasedRuntimeRequestCollection;
|
|
24
|
+
export declare const singleQueryParam: (obj: any) => string;
|
|
25
|
+
export declare const appFactory: (runtimeCollection?: MethodBasedRuntimeRequestCollection) => import("express-serve-static-core").Express;
|
|
26
|
+
declare const app: import("express-serve-static-core").Express;
|
|
27
|
+
export default app;
|