typescript-mock-server 0.0.12 → 0.0.13

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
@@ -58,6 +58,13 @@ export const data: User[] = [{
58
58
  lastName: 'Development',
59
59
  creationDate: newDate()
60
60
  }];
61
+
62
+ export const config: Config = {
63
+ server: {
64
+ delay: 2000,
65
+ statusCode: 418
66
+ }
67
+ }
61
68
  ```
62
69
 
63
70
  ## Dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-mock-server",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Simple mock server that can be used in front end development. Instead of creating json files you can just publish TypeScript objects as json",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -32,12 +32,12 @@
32
32
  "prettier": "^2.6.2"
33
33
  },
34
34
  "dependencies": {
35
- "@types/express": "^4.17.9",
36
- "@types/node": "^14.18.12",
37
- "express": "^4.17.3",
38
- "ts-node-dev": "^1.1.8",
35
+ "@types/express": "^4.17.13",
36
+ "@types/node": "^18.0.5",
37
+ "express": "^4.18.1",
38
+ "ts-node-dev": "2.0.0",
39
39
  "tslog": "^3.3.3",
40
- "typescript": "^4.0.5"
40
+ "typescript": "^4.7.4"
41
41
  },
42
42
  "prettier": {
43
43
  "arrowParens": "avoid",
@@ -1,6 +1,5 @@
1
1
  export interface CommandLine {
2
2
  getCommands(): Map<Command, string>;
3
-
4
3
  getCommand(command: Command): string | undefined;
5
4
  }
6
5
 
@@ -53,7 +53,16 @@ export class TypescriptMockServerImpl implements TypescriptMockServer{
53
53
  }
54
54
 
55
55
  private addEndpoint(endpoint: string, httpVerb: HttpVerb, model: any) {
56
- this.app[httpVerb](endpoint, (req, res) => res.send(model.data));
56
+ this.app[httpVerb](endpoint, (req, res) => {
57
+ if (model?.config?.server?.statusCode) {
58
+ res.statusCode = model?.config?.server?.statusCode;
59
+ }
60
+ if (model?.config?.server?.delay) {
61
+ setTimeout(() => res.send(model.data), model?.config?.server?.delay);
62
+ } else {
63
+ return res.send(model.data);
64
+ }
65
+ });
57
66
  }
58
67
 
59
68
  private handleRequest(path: string, dirent: Dirent, httpVerb: HttpVerb) {
@@ -0,0 +1,8 @@
1
+ export interface Config {
2
+ server?: Server;
3
+ }
4
+
5
+ export interface Server {
6
+ delay?: number; // Delay response (in ms)
7
+ statusCode?: number; // Status code of response
8
+ }
@@ -1,3 +1,5 @@
1
+ import { Config } from '../../src/models/config';
2
+
1
3
  export interface User {
2
4
  id: number;
3
5
  firstName: string;
@@ -18,3 +20,10 @@ export const data: User[] = [{
18
20
  lastName: 'Development',
19
21
  creationDate: newDate()
20
22
  }];
23
+
24
+ export const config: Config = {
25
+ server: {
26
+ delay: 2000,
27
+ statusCode: 418
28
+ }
29
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
3
+ "target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
4
 
5
5
  "module": "commonjs", /* Specify what module code is generated. */
6
6