typescript-mock-server 1.11.0 → 1.11.2

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.
Files changed (37) hide show
  1. package/dist/command-line.js +9 -0
  2. package/dist/impl/command-line-impl.js +28 -0
  3. package/dist/impl/logger-impl.js +31 -0
  4. package/dist/impl/typescript-mock-server-impl.js +212 -0
  5. package/dist/index.js +6 -0
  6. package/dist/logger.js +2 -0
  7. package/dist/models/config.js +2 -0
  8. package/dist/models/registered-endpoint.js +2 -0
  9. package/dist/src/command-line.js +9 -0
  10. package/dist/src/impl/command-line-impl.js +28 -0
  11. package/dist/src/impl/logger-impl.js +31 -0
  12. package/dist/src/impl/typescript-mock-server-impl.js +208 -0
  13. package/dist/src/index.js +6 -0
  14. package/dist/src/logger.js +2 -0
  15. package/dist/src/models/config.js +2 -0
  16. package/dist/src/models/registered-endpoint.js +2 -0
  17. package/dist/src/types/http-verbs.js +2 -0
  18. package/dist/src/typescript-mock-server.js +2 -0
  19. package/dist/test/impl/command-line-impl.spec.js +40 -0
  20. package/dist/test/impl/typescript-mock-server-impl.spec.js +182 -0
  21. package/dist/tms-models/dash-example/get-dash-in-id.js +6 -0
  22. package/dist/tms-models/dash-example/get-test1.js +6 -0
  23. package/dist/tms-models/dash-example/get.js +20 -0
  24. package/dist/tms-models/users/delete-1.js +8 -0
  25. package/dist/tms-models/users/get-1.js +14 -0
  26. package/dist/tms-models/users/get-dynamic.js +15 -0
  27. package/dist/tms-models/users/get.js +20 -0
  28. package/dist/tms-models/users/head-1.js +4 -0
  29. package/dist/tms-models/users/options-1.js +4 -0
  30. package/dist/tms-models/users/patch-1.js +8 -0
  31. package/dist/tms-models/users/post-1.js +8 -0
  32. package/dist/tms-models/users/profile/get-1.js +12 -0
  33. package/dist/tms-models/users/put-1.js +8 -0
  34. package/dist/types/http-verbs.js +2 -0
  35. package/dist/typescript-mock-server.js +2 -0
  36. package/package.json +6 -2
  37. package/src/index.ts +1 -1
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = void 0;
4
+ var Command;
5
+ (function (Command) {
6
+ Command["PATH"] = "path";
7
+ Command["PORT"] = "port";
8
+ Command["CORS"] = "cors";
9
+ })(Command || (exports.Command = Command = {}));
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandLineImpl = void 0;
4
+ const logger_impl_1 = require("./logger-impl");
5
+ class CommandLineImpl {
6
+ constructor() {
7
+ this.arguments = new Map();
8
+ this.log = new logger_impl_1.LoggerImpl();
9
+ this.parseCommandLineArguments();
10
+ }
11
+ getCommands() {
12
+ return this.arguments;
13
+ }
14
+ getCommand(command) {
15
+ return this.arguments.get(command);
16
+ }
17
+ parseCommandLineArguments() {
18
+ process.argv.slice(2).map((element) => {
19
+ const matches = element.match('--([a-zA-Z0-9]+)=(.*)');
20
+ if (matches) {
21
+ const value = matches[2].replace(/^['"]/, '').replace(/['"]$/, '');
22
+ this.arguments.set(matches[1], value);
23
+ }
24
+ });
25
+ this.log.debug(`Passed arguments ${[...this.arguments.keys()].join(',')}`);
26
+ }
27
+ }
28
+ exports.CommandLineImpl = CommandLineImpl;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerImpl = void 0;
4
+ const tslog_1 = require("tslog");
5
+ class LoggerImpl {
6
+ constructor() {
7
+ this.log = new tslog_1.Logger({ ignoreStackLevels: 4, displayFunctionName: false });
8
+ }
9
+ static getArgumentsToPass(args) {
10
+ return LoggerImpl.getNumberOfArguments(args) === 1 ? args[0] : args;
11
+ }
12
+ static getNumberOfArguments(args) {
13
+ return args.length;
14
+ }
15
+ debug(...args) {
16
+ this.log.debug(LoggerImpl.getArgumentsToPass(args));
17
+ }
18
+ error(...args) {
19
+ this.log.error(LoggerImpl.getArgumentsToPass(args));
20
+ }
21
+ trace(...args) {
22
+ this.log.trace(LoggerImpl.getArgumentsToPass(args));
23
+ }
24
+ warn(...args) {
25
+ this.log.warn(LoggerImpl.getArgumentsToPass(args));
26
+ }
27
+ info(...args) {
28
+ this.log.info(LoggerImpl.getArgumentsToPass(args));
29
+ }
30
+ }
31
+ exports.LoggerImpl = LoggerImpl;
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
45
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
46
+ var m = o[Symbol.asyncIterator], i;
47
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
48
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
49
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
50
+ };
51
+ var __importDefault = (this && this.__importDefault) || function (mod) {
52
+ return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.TypescriptMockServerImpl = void 0;
56
+ const express_1 = __importDefault(require("express"));
57
+ const cors_1 = __importDefault(require("cors"));
58
+ const command_line_impl_1 = require("./command-line-impl");
59
+ const command_line_1 = require("../command-line");
60
+ const promises_1 = require("fs/promises");
61
+ const logger_impl_1 = require("./logger-impl");
62
+ const path_1 = __importDefault(require("path"));
63
+ class TypescriptMockServerImpl {
64
+ constructor(config) {
65
+ this.log = new logger_impl_1.LoggerImpl();
66
+ this.commandLine = new command_line_impl_1.CommandLineImpl();
67
+ this.registeredEndpoints = [];
68
+ if (config && 'use' in config) {
69
+ this.app = config;
70
+ this.basePath = this.getPath();
71
+ }
72
+ else {
73
+ const serverConfig = config;
74
+ this.app = (serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.app) || (0, express_1.default)();
75
+ this.basePath = this.getPath(serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.path);
76
+ }
77
+ }
78
+ static loadModule(moduleName) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ if (moduleName.endsWith('.ts')) {
81
+ require('ts-node').register({ transpileOnly: true });
82
+ }
83
+ return yield Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
84
+ });
85
+ }
86
+ start() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ this.log.info(`basePath: ${this.basePath}`);
89
+ const port = this.commandLine.getCommand(command_line_1.Command.PORT) || 3000;
90
+ const corsSetting = {
91
+ origin: this.commandLine.getCommand(command_line_1.Command.CORS) || '*'
92
+ };
93
+ this.app.use((0, cors_1.default)(corsSetting));
94
+ // add started endpoint
95
+ this.addEndpoint('state', 'get', { data: { status: 'started' } });
96
+ yield this.readRoutes(this.basePath).catch(error => this.log.error(error));
97
+ this.app.listen(port, () => {
98
+ this.log.info(`App is listening on port ${port}!`);
99
+ });
100
+ this.log.info(`Started mock server on port ${port}`);
101
+ });
102
+ }
103
+ readRoutes(dirPath) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ var _a, e_1, _b, _c;
106
+ const dir = yield (0, promises_1.opendir)(dirPath);
107
+ try {
108
+ for (var _d = true, dir_1 = __asyncValues(dir), dir_1_1; dir_1_1 = yield dir_1.next(), _a = dir_1_1.done, !_a; _d = true) {
109
+ _c = dir_1_1.value;
110
+ _d = false;
111
+ const dirent = _c;
112
+ if (dirent.isDirectory()) {
113
+ yield this.readRoutes(`${dirPath}/${dirent.name}`);
114
+ }
115
+ else {
116
+ yield this.handleFile(dirPath, dirent);
117
+ }
118
+ }
119
+ }
120
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
121
+ finally {
122
+ try {
123
+ if (!_d && !_a && (_b = dir_1.return)) yield _b.call(dir_1);
124
+ }
125
+ finally { if (e_1) throw e_1.error; }
126
+ }
127
+ const port = this.commandLine.getCommand(command_line_1.Command.PORT) || 3000;
128
+ this.registeredEndpoints.forEach(endpoint => this.log.info(`${endpoint.httpVerb.toUpperCase()} http://localhost:${port}${endpoint.endpoint}`));
129
+ this.registeredEndpoints = [];
130
+ });
131
+ }
132
+ handleFile(dirPath, dirent) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const httpVerb = (dirent.name.indexOf('-') > -1 ? dirent.name.split('-')[0] : dirent.name.split('.')[0]);
135
+ yield this.handleRequest(dirPath, dirent, httpVerb);
136
+ });
137
+ }
138
+ addEndpoint(endpoint, httpVerb, model) {
139
+ const route = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
140
+ this.app[httpVerb](route, (req, res) => {
141
+ var _a, _b;
142
+ let responseData = model.data;
143
+ let statusCode = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.statusCode;
144
+ let delay = (_b = model === null || model === void 0 ? void 0 : model.config) === null || _b === void 0 ? void 0 : _b.delay;
145
+ if (typeof model.data === 'function') {
146
+ responseData = model.data(req, res);
147
+ }
148
+ if (statusCode) {
149
+ res.statusCode = statusCode;
150
+ }
151
+ if (delay) {
152
+ setTimeout(() => res.send(responseData), this.getDelayValue(delay));
153
+ }
154
+ else {
155
+ return res.send(responseData);
156
+ }
157
+ });
158
+ }
159
+ getDelayValue(delay) {
160
+ if (typeof delay === 'number') {
161
+ return delay;
162
+ }
163
+ else if (delay.min && delay.max) {
164
+ return Math.floor(delay.min + Math.random() * delay.max);
165
+ }
166
+ return 0;
167
+ }
168
+ handleRequest(dirPath, dirent, httpVerb) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ const endpoint = this.convertFileNameToEndpoint(dirPath, dirent, httpVerb);
171
+ let modulePath = `${dirPath}/${dirent.name}`;
172
+ this.registeredEndpoints.push({ httpVerb, endpoint });
173
+ if (__filename.endsWith('.js') && modulePath.endsWith('.ts')) {
174
+ const distPath = path_1.default.join(process.cwd(), 'dist');
175
+ const potentialJsPath = modulePath
176
+ .replace(process.cwd(), distPath)
177
+ .replace(/\.ts$/, '.js');
178
+ const fs = require('fs');
179
+ if (fs.existsSync(potentialJsPath)) {
180
+ modulePath = potentialJsPath;
181
+ }
182
+ }
183
+ yield TypescriptMockServerImpl.loadModule(modulePath)
184
+ .then(model => this.addEndpoint(endpoint, httpVerb, model))
185
+ .catch(error => this.log.error(error));
186
+ });
187
+ }
188
+ convertFileNameToEndpoint(dirPath, dirent, httpVerb) {
189
+ const endpoint = `${dirPath.replace(this.basePath, '')}/${dirent.name}`
190
+ .replace('.ts', '')
191
+ .replace(`${httpVerb}-`, '')
192
+ .replace(httpVerb, '');
193
+ if (endpoint.endsWith('/')) {
194
+ return endpoint.substring(0, endpoint.length - 1);
195
+ }
196
+ return endpoint;
197
+ }
198
+ getPath(defaultPath = 'tms-models') {
199
+ let definedPath = defaultPath;
200
+ if (!this.commandLine.getCommands().has(command_line_1.Command.PATH)) {
201
+ this.log.warn(`Path parameter not set, fallback to default ${defaultPath}`);
202
+ }
203
+ else {
204
+ definedPath = this.commandLine.getCommand(command_line_1.Command.PATH);
205
+ }
206
+ if (path_1.default.isAbsolute(definedPath)) {
207
+ return definedPath;
208
+ }
209
+ return path_1.default.join(process.cwd(), definedPath);
210
+ }
211
+ }
212
+ exports.TypescriptMockServerImpl = TypescriptMockServerImpl;
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const typescript_mock_server_impl_1 = require("./impl/typescript-mock-server-impl");
5
+ const server = new typescript_mock_server_impl_1.TypescriptMockServerImpl();
6
+ server.start().then(() => console.log('Server started')).catch(console.error);
package/dist/logger.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = void 0;
4
+ var Command;
5
+ (function (Command) {
6
+ Command["PATH"] = "path";
7
+ Command["PORT"] = "port";
8
+ Command["CORS"] = "cors";
9
+ })(Command || (exports.Command = Command = {}));
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandLineImpl = void 0;
4
+ const logger_impl_1 = require("./logger-impl");
5
+ class CommandLineImpl {
6
+ constructor() {
7
+ this.arguments = new Map();
8
+ this.log = new logger_impl_1.LoggerImpl();
9
+ this.parseCommandLineArguments();
10
+ }
11
+ getCommands() {
12
+ return this.arguments;
13
+ }
14
+ getCommand(command) {
15
+ return this.arguments.get(command);
16
+ }
17
+ parseCommandLineArguments() {
18
+ process.argv.slice(2).map((element) => {
19
+ const matches = element.match('--([a-zA-Z0-9]+)=(.*)');
20
+ if (matches) {
21
+ const value = matches[2].replace(/^['"]/, '').replace(/['"]$/, '');
22
+ this.arguments.set(matches[1], value);
23
+ }
24
+ });
25
+ this.log.debug(`Passed arguments ${[...this.arguments.keys()].join(',')}`);
26
+ }
27
+ }
28
+ exports.CommandLineImpl = CommandLineImpl;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerImpl = void 0;
4
+ const tslog_1 = require("tslog");
5
+ class LoggerImpl {
6
+ constructor() {
7
+ this.log = new tslog_1.Logger({ ignoreStackLevels: 4, displayFunctionName: false });
8
+ }
9
+ static getArgumentsToPass(args) {
10
+ return LoggerImpl.getNumberOfArguments(args) === 1 ? args[0] : args;
11
+ }
12
+ static getNumberOfArguments(args) {
13
+ return args.length;
14
+ }
15
+ debug(...args) {
16
+ this.log.debug(LoggerImpl.getArgumentsToPass(args));
17
+ }
18
+ error(...args) {
19
+ this.log.error(LoggerImpl.getArgumentsToPass(args));
20
+ }
21
+ trace(...args) {
22
+ this.log.trace(LoggerImpl.getArgumentsToPass(args));
23
+ }
24
+ warn(...args) {
25
+ this.log.warn(LoggerImpl.getArgumentsToPass(args));
26
+ }
27
+ info(...args) {
28
+ this.log.info(LoggerImpl.getArgumentsToPass(args));
29
+ }
30
+ }
31
+ exports.LoggerImpl = LoggerImpl;
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
45
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
46
+ var m = o[Symbol.asyncIterator], i;
47
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
48
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
49
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
50
+ };
51
+ var __importDefault = (this && this.__importDefault) || function (mod) {
52
+ return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.TypescriptMockServerImpl = void 0;
56
+ const express_1 = __importDefault(require("express"));
57
+ const cors_1 = __importDefault(require("cors"));
58
+ const command_line_impl_1 = require("./command-line-impl");
59
+ const command_line_1 = require("../command-line");
60
+ const promises_1 = require("fs/promises");
61
+ const logger_impl_1 = require("./logger-impl");
62
+ const path_1 = __importDefault(require("path"));
63
+ class TypescriptMockServerImpl {
64
+ constructor(config) {
65
+ this.log = new logger_impl_1.LoggerImpl();
66
+ this.commandLine = new command_line_impl_1.CommandLineImpl();
67
+ this.registeredEndpoints = [];
68
+ if (config && 'use' in config) {
69
+ this.app = config;
70
+ this.basePath = this.getPath();
71
+ }
72
+ else {
73
+ const serverConfig = config;
74
+ this.app = (serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.app) || (0, express_1.default)();
75
+ this.basePath = this.getPath(serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.path);
76
+ }
77
+ }
78
+ static loadModule(moduleName) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ return yield Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
81
+ });
82
+ }
83
+ start() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ this.log.info(`basePath: ${this.basePath}`);
86
+ const port = this.commandLine.getCommand(command_line_1.Command.PORT) || 3000;
87
+ const corsSetting = {
88
+ origin: this.commandLine.getCommand(command_line_1.Command.CORS) || '*'
89
+ };
90
+ this.app.use((0, cors_1.default)(corsSetting));
91
+ // add started endpoint
92
+ this.addEndpoint('state', 'get', { data: { status: 'started' } });
93
+ yield this.readRoutes(this.basePath).catch(error => this.log.error(error));
94
+ this.app.listen(port, () => {
95
+ this.log.info(`App is listening on port ${port}!`);
96
+ });
97
+ this.log.info(`Started mock server on port ${port}`);
98
+ });
99
+ }
100
+ readRoutes(dirPath) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ var _a, e_1, _b, _c;
103
+ const dir = yield (0, promises_1.opendir)(dirPath);
104
+ try {
105
+ for (var _d = true, dir_1 = __asyncValues(dir), dir_1_1; dir_1_1 = yield dir_1.next(), _a = dir_1_1.done, !_a; _d = true) {
106
+ _c = dir_1_1.value;
107
+ _d = false;
108
+ const dirent = _c;
109
+ if (dirent.isDirectory()) {
110
+ yield this.readRoutes(`${dirPath}/${dirent.name}`);
111
+ }
112
+ else {
113
+ yield this.handleFile(dirPath, dirent);
114
+ }
115
+ }
116
+ }
117
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
118
+ finally {
119
+ try {
120
+ if (!_d && !_a && (_b = dir_1.return)) yield _b.call(dir_1);
121
+ }
122
+ finally { if (e_1) throw e_1.error; }
123
+ }
124
+ const port = this.commandLine.getCommand(command_line_1.Command.PORT) || 3000;
125
+ this.registeredEndpoints.forEach(endpoint => this.log.info(`${endpoint.httpVerb.toUpperCase()} http://localhost:${port}${endpoint.endpoint}`));
126
+ this.registeredEndpoints = [];
127
+ });
128
+ }
129
+ handleFile(dirPath, dirent) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ const httpVerb = (dirent.name.indexOf('-') > -1 ? dirent.name.split('-')[0] : dirent.name.split('.')[0]);
132
+ yield this.handleRequest(dirPath, dirent, httpVerb);
133
+ });
134
+ }
135
+ addEndpoint(endpoint, httpVerb, model) {
136
+ const route = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
137
+ this.app[httpVerb](route, (req, res) => {
138
+ var _a, _b;
139
+ let responseData = model.data;
140
+ let statusCode = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.statusCode;
141
+ let delay = (_b = model === null || model === void 0 ? void 0 : model.config) === null || _b === void 0 ? void 0 : _b.delay;
142
+ if (typeof model.data === 'function') {
143
+ responseData = model.data(req, res);
144
+ }
145
+ if (statusCode) {
146
+ res.statusCode = statusCode;
147
+ }
148
+ if (delay) {
149
+ setTimeout(() => res.send(responseData), this.getDelayValue(delay));
150
+ }
151
+ else {
152
+ return res.send(responseData);
153
+ }
154
+ });
155
+ }
156
+ getDelayValue(delay) {
157
+ if (typeof delay === 'number') {
158
+ return delay;
159
+ }
160
+ else if (delay.min && delay.max) {
161
+ return Math.floor(delay.min + Math.random() * delay.max);
162
+ }
163
+ return 0;
164
+ }
165
+ handleRequest(dirPath, dirent, httpVerb) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const endpoint = this.convertFileNameToEndpoint(dirPath, dirent, httpVerb);
168
+ let modulePath = `${dirPath}/${dirent.name}`;
169
+ this.registeredEndpoints.push({ httpVerb, endpoint });
170
+ if (__filename.endsWith('.js')) {
171
+ const distPath = path_1.default.join(process.cwd(), 'dist');
172
+ if (modulePath.startsWith(process.cwd()) && !modulePath.startsWith(distPath)) {
173
+ modulePath = modulePath.replace(process.cwd(), distPath);
174
+ }
175
+ if (modulePath.endsWith('.ts')) {
176
+ modulePath = modulePath.replace(/\.ts$/, '.js');
177
+ }
178
+ }
179
+ yield TypescriptMockServerImpl.loadModule(modulePath)
180
+ .then(model => this.addEndpoint(endpoint, httpVerb, model))
181
+ .catch(error => this.log.error(error));
182
+ });
183
+ }
184
+ convertFileNameToEndpoint(dirPath, dirent, httpVerb) {
185
+ const endpoint = `${dirPath.replace(this.basePath, '')}/${dirent.name}`
186
+ .replace('.ts', '')
187
+ .replace(`${httpVerb}-`, '')
188
+ .replace(httpVerb, '');
189
+ if (endpoint.endsWith('/')) {
190
+ return endpoint.substring(0, endpoint.length - 1);
191
+ }
192
+ return endpoint;
193
+ }
194
+ getPath(defaultPath = 'tms-models') {
195
+ let definedPath = defaultPath;
196
+ if (!this.commandLine.getCommands().has(command_line_1.Command.PATH)) {
197
+ this.log.warn(`Path parameter not set, fallback to default ${defaultPath}`);
198
+ }
199
+ else {
200
+ definedPath = this.commandLine.getCommand(command_line_1.Command.PATH);
201
+ }
202
+ if (path_1.default.isAbsolute(definedPath)) {
203
+ return definedPath;
204
+ }
205
+ return path_1.default.join(process.cwd(), definedPath);
206
+ }
207
+ }
208
+ exports.TypescriptMockServerImpl = TypescriptMockServerImpl;
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const typescript_mock_server_impl_1 = require("./impl/typescript-mock-server-impl");
5
+ const server = new typescript_mock_server_impl_1.TypescriptMockServerImpl();
6
+ server.start().then(() => console.log('Server started')).catch(console.error);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_line_impl_1 = require("../../src/impl/command-line-impl");
4
+ const command_line_1 = require("../../src/command-line");
5
+ describe('CommandLineImpl', () => {
6
+ const originalArgv = process.argv;
7
+ beforeEach(() => {
8
+ jest.resetModules();
9
+ });
10
+ afterEach(() => {
11
+ process.argv = originalArgv;
12
+ });
13
+ it('should parse command line arguments correctly', () => {
14
+ process.argv = ['node', 'index.js', '--port=4000', '--path=./test-models', '--cors=http://localhost:3000'];
15
+ const commandLine = new command_line_impl_1.CommandLineImpl();
16
+ expect(commandLine.getCommand(command_line_1.Command.PORT)).toBe('4000');
17
+ expect(commandLine.getCommand(command_line_1.Command.PATH)).toBe('./test-models');
18
+ expect(commandLine.getCommand(command_line_1.Command.CORS)).toBe('http://localhost:3000');
19
+ });
20
+ it('should handle arguments with quotes', () => {
21
+ process.argv = ['node', 'index.js', '--path="C:/Program Files/Models"', "--cors='*'", '--port=5000'];
22
+ const commandLine = new command_line_impl_1.CommandLineImpl();
23
+ expect(commandLine.getCommand(command_line_1.Command.PATH)).toBe('C:/Program Files/Models');
24
+ expect(commandLine.getCommand(command_line_1.Command.CORS)).toBe('*');
25
+ expect(commandLine.getCommand(command_line_1.Command.PORT)).toBe('5000');
26
+ });
27
+ it('should return undefined for missing commands', () => {
28
+ process.argv = ['node', 'index.js'];
29
+ const commandLine = new command_line_impl_1.CommandLineImpl();
30
+ expect(commandLine.getCommand(command_line_1.Command.PORT)).toBeUndefined();
31
+ });
32
+ it('should return all commands', () => {
33
+ process.argv = ['node', 'index.js', '--port=4000', '--path=./models'];
34
+ const commandLine = new command_line_impl_1.CommandLineImpl();
35
+ const commands = commandLine.getCommands();
36
+ expect(commands.size).toBe(2);
37
+ expect(commands.get(command_line_1.Command.PORT)).toBe('4000');
38
+ expect(commands.get(command_line_1.Command.PATH)).toBe('./models');
39
+ });
40
+ });
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
45
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
46
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
47
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
48
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
49
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
50
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
51
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
52
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
53
+ function fulfill(value) { resume("next", value); }
54
+ function reject(value) { resume("throw", value); }
55
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
56
+ };
57
+ var __importDefault = (this && this.__importDefault) || function (mod) {
58
+ return (mod && mod.__esModule) ? mod : { "default": mod };
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ const supertest_1 = __importDefault(require("supertest"));
62
+ const express_1 = __importDefault(require("express"));
63
+ const typescript_mock_server_impl_1 = require("../../src/impl/typescript-mock-server-impl");
64
+ const fsPromises = __importStar(require("fs/promises"));
65
+ const path_1 = __importDefault(require("path"));
66
+ jest.mock('fs/promises');
67
+ describe('TypescriptMockServerImpl', () => {
68
+ let server;
69
+ let app;
70
+ beforeEach(() => {
71
+ jest.clearAllMocks();
72
+ app = (0, express_1.default)();
73
+ // Spy on listen to prevent it from actually starting
74
+ jest.spyOn(app, 'listen').mockImplementation((port, callback) => {
75
+ if (callback)
76
+ callback();
77
+ return {};
78
+ });
79
+ });
80
+ it('should start and have the state endpoint', () => __awaiter(void 0, void 0, void 0, function* () {
81
+ fsPromises.opendir.mockResolvedValue(function () {
82
+ return __asyncGenerator(this, arguments, function* () {
83
+ // yield nothing
84
+ });
85
+ }());
86
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
87
+ yield server.start();
88
+ const response = yield (0, supertest_1.default)(app).get('/state');
89
+ expect(response.status).toBe(200);
90
+ expect(response.body).toEqual({ status: 'started' });
91
+ }));
92
+ it('should have the state endpoint even if other routes are loaded', () => __awaiter(void 0, void 0, void 0, function* () {
93
+ fsPromises.opendir.mockResolvedValue(function () {
94
+ return __asyncGenerator(this, arguments, function* () {
95
+ // yield nothing
96
+ });
97
+ }());
98
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
99
+ yield server.start();
100
+ const response = yield (0, supertest_1.default)(app).get('/state');
101
+ expect(response.status).toBe(200);
102
+ }));
103
+ it('should load routes from directory', () => __awaiter(void 0, void 0, void 0, function* () {
104
+ const mockFiles = [
105
+ { name: 'get-test.ts', isDirectory: () => false },
106
+ { name: 'post-data.ts', isDirectory: () => false }
107
+ ];
108
+ fsPromises.opendir.mockResolvedValue(function () {
109
+ return __asyncGenerator(this, arguments, function* () {
110
+ for (const file of mockFiles) {
111
+ yield yield __await(file);
112
+ }
113
+ });
114
+ }());
115
+ // Mock loadModule
116
+ const loadModuleSpy = jest.spyOn(typescript_mock_server_impl_1.TypescriptMockServerImpl, 'loadModule');
117
+ loadModuleSpy.mockImplementation((...args) => __awaiter(void 0, void 0, void 0, function* () {
118
+ const path = args[0];
119
+ if (path.includes('get-test')) {
120
+ return { data: { message: 'get success' } };
121
+ }
122
+ if (path.includes('post-data')) {
123
+ return { data: { message: 'post success' } };
124
+ }
125
+ return {};
126
+ }));
127
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
128
+ yield server.start();
129
+ const getResponse = yield (0, supertest_1.default)(app).get('/test');
130
+ expect(getResponse.status).toBe(200);
131
+ expect(getResponse.body).toEqual({ message: 'get success' });
132
+ const postResponse = yield (0, supertest_1.default)(app).post('/data');
133
+ expect(postResponse.status).toBe(200);
134
+ expect(postResponse.body).toEqual({ message: 'post success' });
135
+ }));
136
+ it('should handle status codes and delay from config', () => __awaiter(void 0, void 0, void 0, function* () {
137
+ const mockFiles = [
138
+ { name: 'get-config.ts', isDirectory: () => false }
139
+ ];
140
+ fsPromises.opendir.mockResolvedValue(function () {
141
+ return __asyncGenerator(this, arguments, function* () {
142
+ yield yield __await(mockFiles[0]);
143
+ });
144
+ }());
145
+ const loadModuleSpy = jest.spyOn(typescript_mock_server_impl_1.TypescriptMockServerImpl, 'loadModule');
146
+ loadModuleSpy.mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
147
+ return {
148
+ data: { message: 'custom' },
149
+ config: { statusCode: 201, delay: 10 }
150
+ };
151
+ }));
152
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
153
+ yield server.start();
154
+ const response = yield (0, supertest_1.default)(app).get('/config');
155
+ expect(response.status).toBe(201);
156
+ expect(response.body).toEqual({ message: 'custom' });
157
+ }));
158
+ it('should resolve absolute paths correctly', () => __awaiter(void 0, void 0, void 0, function* () {
159
+ fsPromises.opendir.mockResolvedValue(function () {
160
+ return __asyncGenerator(this, arguments, function* () {
161
+ // yield nothing
162
+ });
163
+ }());
164
+ const absolutePath = path_1.default.resolve('/absolute/path/to/models');
165
+ process.argv = ['node', 'index.js', `--path=${absolutePath}`];
166
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
167
+ // @ts-ignore
168
+ expect(server.basePath).toBe(absolutePath);
169
+ }));
170
+ it('should resolve relative paths from process.cwd()', () => __awaiter(void 0, void 0, void 0, function* () {
171
+ fsPromises.opendir.mockResolvedValue(function () {
172
+ return __asyncGenerator(this, arguments, function* () {
173
+ // yield nothing
174
+ });
175
+ }());
176
+ const relativePath = 'custom-models';
177
+ process.argv = ['node', 'index.js', `--path=${relativePath}`];
178
+ server = new typescript_mock_server_impl_1.TypescriptMockServerImpl(app);
179
+ // @ts-ignore
180
+ expect(server.basePath).toBe(path_1.default.join(process.cwd(), relativePath));
181
+ }));
182
+ });
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: 'test1'
6
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: 'test1'
6
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = exports.data = exports.newDate = void 0;
4
+ const newDate = () => new Date();
5
+ exports.newDate = newDate;
6
+ exports.data = [{
7
+ id: 1,
8
+ firstName: 'Guy',
9
+ lastName: 'Theuws',
10
+ creationDate: (0, exports.newDate)()
11
+ }, {
12
+ id: 2,
13
+ firstName: 'Generation Y',
14
+ lastName: 'Development',
15
+ creationDate: (0, exports.newDate)()
16
+ }];
17
+ exports.config = {
18
+ delay: 2000,
19
+ statusCode: 418
20
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: 1,
6
+ firstName: 'Guy deleted',
7
+ lastName: 'Theuws deleted'
8
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = exports.data = void 0;
4
+ exports.data = {
5
+ id: 1,
6
+ firstName: 'Guy',
7
+ lastName: 'Theuws',
8
+ };
9
+ exports.config = {
10
+ delay: {
11
+ min: 1000,
12
+ max: 5000,
13
+ },
14
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = exports.data = void 0;
4
+ const data = (req, res) => {
5
+ const userId = req.query.id ? parseInt(req.query.id) : 1;
6
+ return {
7
+ id: userId,
8
+ username: `user_${userId}`,
9
+ email: `user_${userId}@example.com`
10
+ };
11
+ };
12
+ exports.data = data;
13
+ exports.config = {
14
+ statusCode: 200
15
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = exports.data = exports.newDate = void 0;
4
+ const newDate = () => new Date();
5
+ exports.newDate = newDate;
6
+ exports.data = [{
7
+ id: 1,
8
+ firstName: 'Guy',
9
+ lastName: 'Theuws',
10
+ creationDate: (0, exports.newDate)()
11
+ }, {
12
+ id: 2,
13
+ firstName: 'Generation Y',
14
+ lastName: 'Development',
15
+ creationDate: (0, exports.newDate)()
16
+ }];
17
+ exports.config = {
18
+ delay: 2000,
19
+ statusCode: 418
20
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = null;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = null;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: 1,
6
+ firstName: 'Guy patch',
7
+ lastName: 'Theuws patch'
8
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: new Date().getMilliseconds(),
6
+ firstName: 'Guy created',
7
+ lastName: 'Theuws created'
8
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ const get_1 = require("../get");
5
+ exports.data = {
6
+ id: 1, title: 'Hello profile', user: {
7
+ id: 1,
8
+ firstName: 'Guy',
9
+ lastName: 'Theuws',
10
+ creationDate: (0, get_1.newDate)()
11
+ }
12
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.data = void 0;
4
+ exports.data = {
5
+ id: 1,
6
+ firstName: 'Guy updated',
7
+ lastName: 'Theuws updated'
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "typescript-mock-server",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
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
+ "main": "dist/src/index.js",
6
+ "bin": {
7
+ "typescript-mock-server": "dist/src/index.js"
8
+ },
5
9
  "scripts": {
6
10
  "test": "jest",
7
- "build": "tsc --outDir dist",
11
+ "build": "tsc --outDir dist && sed -i '' '1s|.*|#!/usr/bin/env node|' dist/src/index.js",
8
12
  "example": "npm run build && node dist/src/index.js --path=tms-models --port=5200 --cors=http://localhost:5200",
9
13
  "start": "npm run build && node dist/src/index.js",
10
14
  "update-deps": "npm update",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- #!./node_modules/.bin/ts-node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import { TypescriptMockServer } from './typescript-mock-server';
4
4
  import { TypescriptMockServerImpl } from './impl/typescript-mock-server-impl';