mock-config-server 3.1.1 → 3.3.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/README.md +174 -14
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +2 -1
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +30 -7
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +9 -3
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +67 -18
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +2 -2
- package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.js +29 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +67 -18
- package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.js +34 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +51 -2
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +2 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +17 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/index.d.ts +1 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +8 -8
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +13 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +36 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +2 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +42 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.d.ts +1 -2
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.d.ts +1 -2
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +7 -1
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +65 -24
- package/dist/src/core/middlewares/index.d.ts +4 -4
- package/dist/src/core/middlewares/index.js +28 -28
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +1 -3
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +7 -1
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +6 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +7 -1
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +55 -12
- package/dist/src/index.d.ts +1 -2
- package/dist/src/index.js +4 -15
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.d.ts +3 -0
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +58 -0
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.d.ts +3 -0
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +67 -0
- package/dist/src/server/createMockServer/createMockServer.d.ts +1 -1
- package/dist/src/server/createMockServer/createMockServer.js +29 -11
- package/dist/src/server/createRestMockServer/createRestMockServer.d.ts +3 -0
- package/dist/src/server/createRestMockServer/createRestMockServer.js +67 -0
- package/dist/src/server/index.d.ts +6 -0
- package/dist/src/server/index.js +66 -0
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.d.ts +5 -0
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +23 -0
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.d.ts +5 -0
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +23 -0
- package/dist/src/server/startRestMockServer/startRestMockServer.d.ts +5 -0
- package/dist/src/server/startRestMockServer/startRestMockServer.js +23 -0
- package/dist/src/static/views/assets/styles/global.css +2 -2
- package/dist/src/static/views/components/header/index.css +4 -4
- package/dist/src/static/views/components/header/index.ejs +6 -6
- package/dist/src/static/views/components/header/index.js +1 -1
- package/dist/src/static/views/features/scheme/dark.css +1 -0
- package/dist/src/static/views/features/scheme/index.js +1 -1
- package/dist/src/static/views/features/scheme/light.css +1 -0
- package/dist/src/static/views/features/tab/index.css +4 -4
- package/dist/src/static/views/features/tab/index.js +12 -12
- package/dist/src/static/views/pages/404/index.css +4 -4
- package/dist/src/static/views/pages/404/index.ejs +8 -8
- package/dist/src/utils/constants/checkModes.d.ts +1 -1
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +2 -1
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.d.ts +7 -2
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +6 -4
- package/dist/src/utils/helpers/graphql/index.d.ts +1 -1
- package/dist/src/utils/helpers/graphql/index.js +11 -11
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +1 -1
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +1 -1
- package/dist/src/utils/helpers/index.d.ts +5 -5
- package/dist/src/utils/helpers/index.js +40 -40
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +19 -10
- package/dist/src/utils/types/graphql.d.ts +60 -51
- package/dist/src/utils/types/index.d.ts +1 -0
- package/dist/src/utils/types/index.js +11 -0
- package/dist/src/utils/types/interceptors.d.ts +1 -1
- package/dist/src/utils/types/rest.d.ts +47 -40
- package/dist/src/utils/types/server.d.ts +18 -4
- package/dist/src/utils/types/utils.d.ts +8 -0
- package/dist/src/utils/types/utils.js +1 -0
- package/dist/src/utils/types/values.d.ts +0 -1
- package/package.json +9 -19
|
@@ -7,10 +7,14 @@ exports.createRestRoutes = void 0;
|
|
|
7
7
|
var _flat = require("flat");
|
|
8
8
|
var _helpers = require("../../../utils/helpers");
|
|
9
9
|
var _helpers2 = require("./helpers");
|
|
10
|
-
const createRestRoutes = (
|
|
10
|
+
const createRestRoutes = ({
|
|
11
|
+
router,
|
|
12
|
+
restConfig,
|
|
13
|
+
serverResponseInterceptor
|
|
14
|
+
}) => {
|
|
11
15
|
(0, _helpers2.prepareRestRequestConfigs)(restConfig.configs).forEach(requestConfig => {
|
|
12
16
|
router.route(requestConfig.path)[requestConfig.method]((0, _helpers.asyncHandler)(async (request, response, next) => {
|
|
13
|
-
var _requestConfig$interc, _matchedRouteConfig$e, _matchedRouteConfig$i, _requestConfig$interc2, _restConfig$intercept;
|
|
17
|
+
var _requestConfig$interc, _matchedRouteConfig$s, _matchedRouteConfig$e, _matchedRouteConfig$i, _requestConfig$interc2, _restConfig$intercept;
|
|
14
18
|
const requestInterceptor = (_requestConfig$interc = requestConfig.interceptors) === null || _requestConfig$interc === void 0 ? void 0 : _requestConfig$interc.request;
|
|
15
19
|
if (requestInterceptor) {
|
|
16
20
|
await (0, _helpers.callRequestInterceptor)({
|
|
@@ -23,20 +27,26 @@ const createRestRoutes = (router, restConfig, serverResponseInterceptors) => {
|
|
|
23
27
|
}) => {
|
|
24
28
|
if (!entities) return true;
|
|
25
29
|
const entries = Object.entries(entities);
|
|
26
|
-
return entries.every(([entityName,
|
|
30
|
+
return entries.every(([entityName, entityDescriptorOrValue]) => {
|
|
27
31
|
const {
|
|
28
32
|
checkMode,
|
|
29
33
|
value: descriptorValue
|
|
30
|
-
} = (0, _helpers.convertToEntityDescriptor)(
|
|
34
|
+
} = (0, _helpers.convertToEntityDescriptor)(entityDescriptorOrValue);
|
|
31
35
|
|
|
32
36
|
// ✅ important: check whole body as plain value strictly if descriptor used for body
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
// ✅ important: bodyParser sets body to empty object if body not sent or invalid, so
|
|
37
|
+
const isEntityBodyByTopLevelDescriptor = entityName === 'body' && (0, _helpers.isEntityDescriptor)(entityDescriptorOrValue);
|
|
38
|
+
if (isEntityBodyByTopLevelDescriptor) {
|
|
39
|
+
// ✅ important: bodyParser sets body to empty object if body not sent or invalid, so assume {} as undefined
|
|
36
40
|
return (0, _helpers.resolveEntityValues)(checkMode, Object.keys(request.body).length ? request.body : undefined, descriptorValue);
|
|
37
41
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
42
|
+
const isEntityBodyByTopLevelArray = entityName === 'body' && Array.isArray(entityDescriptorOrValue);
|
|
43
|
+
if (isEntityBodyByTopLevelArray) {
|
|
44
|
+
return entityDescriptorOrValue.some(entityDescriptorOrValueElement =>
|
|
45
|
+
// ✅ important: bodyParser sets body to empty object if body not sent or invalid, so assume {} as undefined
|
|
46
|
+
(0, _helpers.resolveEntityValues)(checkMode, Object.keys(request.body).length ? request.body : undefined, entityDescriptorOrValueElement));
|
|
47
|
+
}
|
|
48
|
+
const recordOrArrayEntries = Object.entries(entityDescriptorOrValue);
|
|
49
|
+
return recordOrArrayEntries.every(([entityKey, mappedEntityDescriptor]) => {
|
|
40
50
|
const {
|
|
41
51
|
checkMode,
|
|
42
52
|
value: descriptorValue
|
|
@@ -50,16 +60,49 @@ const createRestRoutes = (router, restConfig, serverResponseInterceptors) => {
|
|
|
50
60
|
if (!matchedRouteConfig) {
|
|
51
61
|
return next();
|
|
52
62
|
}
|
|
53
|
-
|
|
63
|
+
let matchedRouteConfigData = null;
|
|
64
|
+
if ((_matchedRouteConfig$s = matchedRouteConfig.settings) !== null && _matchedRouteConfig$s !== void 0 && _matchedRouteConfig$s.polling && 'queue' in matchedRouteConfig) {
|
|
65
|
+
var _shallowMatchedRouteC;
|
|
66
|
+
if (!matchedRouteConfig.queue.length) return next();
|
|
67
|
+
const shallowMatchedRouteConfig = matchedRouteConfig;
|
|
68
|
+
let index = (_shallowMatchedRouteC = shallowMatchedRouteConfig.__pollingIndex) !== null && _shallowMatchedRouteC !== void 0 ? _shallowMatchedRouteC : 0;
|
|
69
|
+
const {
|
|
70
|
+
time,
|
|
71
|
+
data
|
|
72
|
+
} = matchedRouteConfig.queue[index];
|
|
73
|
+
const updateIndex = () => {
|
|
74
|
+
if (matchedRouteConfig.queue.length - 1 === index) {
|
|
75
|
+
index = 0;
|
|
76
|
+
} else {
|
|
77
|
+
index += 1;
|
|
78
|
+
}
|
|
79
|
+
shallowMatchedRouteConfig.__pollingIndex = index;
|
|
80
|
+
};
|
|
81
|
+
if (time && !shallowMatchedRouteConfig.__timeoutInProgress) {
|
|
82
|
+
shallowMatchedRouteConfig.__timeoutInProgress = true;
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
shallowMatchedRouteConfig.__timeoutInProgress = false;
|
|
85
|
+
updateIndex();
|
|
86
|
+
}, time);
|
|
87
|
+
}
|
|
88
|
+
if (!time && !shallowMatchedRouteConfig.__timeoutInProgress) {
|
|
89
|
+
updateIndex();
|
|
90
|
+
}
|
|
91
|
+
matchedRouteConfigData = data;
|
|
92
|
+
}
|
|
93
|
+
if ('data' in matchedRouteConfig) {
|
|
94
|
+
matchedRouteConfigData = matchedRouteConfig.data;
|
|
95
|
+
}
|
|
96
|
+
const resolvedData = typeof matchedRouteConfigData === 'function' ? await matchedRouteConfigData(request, (_matchedRouteConfig$e = matchedRouteConfig.entities) !== null && _matchedRouteConfig$e !== void 0 ? _matchedRouteConfig$e : {}) : matchedRouteConfigData;
|
|
54
97
|
const data = await (0, _helpers.callResponseInterceptors)({
|
|
55
|
-
data:
|
|
98
|
+
data: resolvedData,
|
|
56
99
|
request,
|
|
57
100
|
response,
|
|
58
101
|
interceptors: {
|
|
59
102
|
routeInterceptor: (_matchedRouteConfig$i = matchedRouteConfig.interceptors) === null || _matchedRouteConfig$i === void 0 ? void 0 : _matchedRouteConfig$i.response,
|
|
60
103
|
requestInterceptor: (_requestConfig$interc2 = requestConfig.interceptors) === null || _requestConfig$interc2 === void 0 ? void 0 : _requestConfig$interc2.response,
|
|
61
104
|
apiInterceptor: (_restConfig$intercept = restConfig.interceptors) === null || _restConfig$intercept === void 0 ? void 0 : _restConfig$intercept.response,
|
|
62
|
-
serverInterceptor:
|
|
105
|
+
serverInterceptor: serverResponseInterceptor
|
|
63
106
|
}
|
|
64
107
|
});
|
|
65
108
|
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -3,25 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
Object.keys(
|
|
6
|
+
var _server = require("./server");
|
|
7
|
+
Object.keys(_server).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] ===
|
|
9
|
+
if (key in exports && exports[key] === _server[key]) return;
|
|
10
10
|
Object.defineProperty(exports, key, {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function () {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _startMockServer = require("./server/startMockServer/startMockServer");
|
|
18
|
-
Object.keys(_startMockServer).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _startMockServer[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _startMockServer[key];
|
|
13
|
+
return _server[key];
|
|
25
14
|
}
|
|
26
15
|
});
|
|
27
16
|
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDatabaseMockServer = void 0;
|
|
7
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _database = require("../../core/database");
|
|
10
|
+
var _middlewares = require("../../core/middlewares");
|
|
11
|
+
var _helpers = require("../../utils/helpers");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
const createDatabaseMockServer = (databaseMockServerConfig, server = (0, _express.default)()) => {
|
|
14
|
+
var _databaseMockServerCo, _databaseMockServerCo2;
|
|
15
|
+
const {
|
|
16
|
+
cors,
|
|
17
|
+
staticPath,
|
|
18
|
+
data,
|
|
19
|
+
routes
|
|
20
|
+
} = databaseMockServerConfig;
|
|
21
|
+
server.set('view engine', 'ejs');
|
|
22
|
+
server.set('views', (0, _helpers.urlJoin)(__dirname, '../../static/views'));
|
|
23
|
+
server.use(_express.default.static((0, _helpers.urlJoin)(__dirname, '../../static/views')));
|
|
24
|
+
server.use(_bodyParser.default.urlencoded({
|
|
25
|
+
extended: false
|
|
26
|
+
}));
|
|
27
|
+
server.use(_bodyParser.default.json({
|
|
28
|
+
limit: '10mb'
|
|
29
|
+
}));
|
|
30
|
+
server.set('json spaces', 2);
|
|
31
|
+
server.use(_bodyParser.default.text());
|
|
32
|
+
(0, _middlewares.cookieParseMiddleware)(server);
|
|
33
|
+
const serverRequestInterceptor = (_databaseMockServerCo = databaseMockServerConfig.interceptors) === null || _databaseMockServerCo === void 0 ? void 0 : _databaseMockServerCo.request;
|
|
34
|
+
if (serverRequestInterceptor) {
|
|
35
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
36
|
+
server,
|
|
37
|
+
interceptor: serverRequestInterceptor
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const baseUrl = (_databaseMockServerCo2 = databaseMockServerConfig.baseUrl) !== null && _databaseMockServerCo2 !== void 0 ? _databaseMockServerCo2 : '/';
|
|
41
|
+
if (cors) {
|
|
42
|
+
(0, _middlewares.corsMiddleware)(server, cors);
|
|
43
|
+
} else {
|
|
44
|
+
(0, _middlewares.noCorsMiddleware)(server);
|
|
45
|
+
}
|
|
46
|
+
if (staticPath) {
|
|
47
|
+
(0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
|
|
48
|
+
}
|
|
49
|
+
const routerWithDatabaseRoutes = (0, _database.createDatabaseRoutes)(_express.default.Router(), {
|
|
50
|
+
data,
|
|
51
|
+
routes
|
|
52
|
+
});
|
|
53
|
+
server.use(baseUrl, routerWithDatabaseRoutes);
|
|
54
|
+
(0, _middlewares.notFoundMiddleware)(server, databaseMockServerConfig);
|
|
55
|
+
(0, _middlewares.errorMiddleware)(server);
|
|
56
|
+
return server;
|
|
57
|
+
};
|
|
58
|
+
exports.createDatabaseMockServer = createDatabaseMockServer;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGraphQLMockServer = void 0;
|
|
7
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _database = require("../../core/database");
|
|
10
|
+
var _graphql = require("../../core/graphql");
|
|
11
|
+
var _middlewares = require("../../core/middlewares");
|
|
12
|
+
var _helpers = require("../../utils/helpers");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
const createGraphQLMockServer = (graphqlMockServerConfig, server = (0, _express.default)()) => {
|
|
15
|
+
var _graphqlMockServerCon, _graphqlMockServerCon2;
|
|
16
|
+
const {
|
|
17
|
+
cors,
|
|
18
|
+
staticPath,
|
|
19
|
+
configs,
|
|
20
|
+
database,
|
|
21
|
+
interceptors
|
|
22
|
+
} = graphqlMockServerConfig;
|
|
23
|
+
server.set('view engine', 'ejs');
|
|
24
|
+
server.set('views', (0, _helpers.urlJoin)(__dirname, '../../static/views'));
|
|
25
|
+
server.use(_express.default.static((0, _helpers.urlJoin)(__dirname, '../../static/views')));
|
|
26
|
+
server.use(_bodyParser.default.urlencoded({
|
|
27
|
+
extended: false
|
|
28
|
+
}));
|
|
29
|
+
server.use(_bodyParser.default.json({
|
|
30
|
+
limit: '10mb'
|
|
31
|
+
}));
|
|
32
|
+
server.set('json spaces', 2);
|
|
33
|
+
server.use(_bodyParser.default.text());
|
|
34
|
+
(0, _middlewares.cookieParseMiddleware)(server);
|
|
35
|
+
const serverRequestInterceptor = (_graphqlMockServerCon = graphqlMockServerConfig.interceptors) === null || _graphqlMockServerCon === void 0 ? void 0 : _graphqlMockServerCon.request;
|
|
36
|
+
if (serverRequestInterceptor) {
|
|
37
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
38
|
+
server,
|
|
39
|
+
interceptor: serverRequestInterceptor
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const baseUrl = (_graphqlMockServerCon2 = graphqlMockServerConfig.baseUrl) !== null && _graphqlMockServerCon2 !== void 0 ? _graphqlMockServerCon2 : '/';
|
|
43
|
+
if (cors) {
|
|
44
|
+
(0, _middlewares.corsMiddleware)(server, cors);
|
|
45
|
+
} else {
|
|
46
|
+
(0, _middlewares.noCorsMiddleware)(server);
|
|
47
|
+
}
|
|
48
|
+
if (staticPath) {
|
|
49
|
+
(0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
|
|
50
|
+
}
|
|
51
|
+
const routerWithGraphqlRoutes = (0, _graphql.createGraphQLRoutes)({
|
|
52
|
+
router: _express.default.Router(),
|
|
53
|
+
graphqlConfig: {
|
|
54
|
+
configs
|
|
55
|
+
},
|
|
56
|
+
serverResponseInterceptor: interceptors === null || interceptors === void 0 ? void 0 : interceptors.response
|
|
57
|
+
});
|
|
58
|
+
server.use(baseUrl, routerWithGraphqlRoutes);
|
|
59
|
+
if (database) {
|
|
60
|
+
const routerWithDatabaseRoutes = (0, _database.createDatabaseRoutes)(_express.default.Router(), database);
|
|
61
|
+
server.use(baseUrl, routerWithDatabaseRoutes);
|
|
62
|
+
}
|
|
63
|
+
(0, _middlewares.notFoundMiddleware)(server, graphqlMockServerConfig);
|
|
64
|
+
(0, _middlewares.errorMiddleware)(server);
|
|
65
|
+
return server;
|
|
66
|
+
};
|
|
67
|
+
exports.createGraphQLMockServer = createGraphQLMockServer;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Express } from 'express';
|
|
2
2
|
import type { MockServerConfig } from '../../utils/types';
|
|
3
|
-
export declare const createMockServer: (mockServerConfig: Omit<MockServerConfig, 'port'
|
|
3
|
+
export declare const createMockServer: (mockServerConfig: Omit<MockServerConfig, 'port'>, server?: Express) => Express;
|
|
@@ -12,7 +12,7 @@ var _middlewares = require("../../core/middlewares");
|
|
|
12
12
|
var _rest = require("../../core/rest");
|
|
13
13
|
var _helpers = require("../../utils/helpers");
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
const createMockServer = mockServerConfig => {
|
|
15
|
+
const createMockServer = (mockServerConfig, server = (0, _express.default)()) => {
|
|
16
16
|
var _mockServerConfig$int, _mockServerConfig$bas;
|
|
17
17
|
const {
|
|
18
18
|
cors,
|
|
@@ -22,7 +22,6 @@ const createMockServer = mockServerConfig => {
|
|
|
22
22
|
database,
|
|
23
23
|
interceptors
|
|
24
24
|
} = mockServerConfig;
|
|
25
|
-
const server = (0, _express.default)();
|
|
26
25
|
server.set('view engine', 'ejs');
|
|
27
26
|
server.set('views', (0, _helpers.urlJoin)(__dirname, '../../static/views'));
|
|
28
27
|
server.use(_express.default.static((0, _helpers.urlJoin)(__dirname, '../../static/views')));
|
|
@@ -37,7 +36,10 @@ const createMockServer = mockServerConfig => {
|
|
|
37
36
|
(0, _middlewares.cookieParseMiddleware)(server);
|
|
38
37
|
const serverRequestInterceptor = (_mockServerConfig$int = mockServerConfig.interceptors) === null || _mockServerConfig$int === void 0 ? void 0 : _mockServerConfig$int.request;
|
|
39
38
|
if (serverRequestInterceptor) {
|
|
40
|
-
(0, _middlewares.requestInterceptorMiddleware)(
|
|
39
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
40
|
+
server,
|
|
41
|
+
interceptor: serverRequestInterceptor
|
|
42
|
+
});
|
|
41
43
|
}
|
|
42
44
|
const baseUrl = (_mockServerConfig$bas = mockServerConfig.baseUrl) !== null && _mockServerConfig$bas !== void 0 ? _mockServerConfig$bas : '/';
|
|
43
45
|
if (cors) {
|
|
@@ -49,23 +51,39 @@ const createMockServer = mockServerConfig => {
|
|
|
49
51
|
(0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
|
|
50
52
|
}
|
|
51
53
|
if (rest) {
|
|
52
|
-
var _rest$
|
|
53
|
-
const routerWithRestRoutes = (0, _rest.createRestRoutes)(
|
|
54
|
+
var _rest$baseUrl, _rest$interceptors;
|
|
55
|
+
const routerWithRestRoutes = (0, _rest.createRestRoutes)({
|
|
56
|
+
router: _express.default.Router(),
|
|
57
|
+
restConfig: rest,
|
|
58
|
+
serverResponseInterceptor: interceptors === null || interceptors === void 0 ? void 0 : interceptors.response
|
|
59
|
+
});
|
|
60
|
+
const restBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_rest$baseUrl = rest.baseUrl) !== null && _rest$baseUrl !== void 0 ? _rest$baseUrl : '/');
|
|
54
61
|
const apiRequestInterceptor = (_rest$interceptors = rest.interceptors) === null || _rest$interceptors === void 0 ? void 0 : _rest$interceptors.request;
|
|
55
62
|
if (apiRequestInterceptor) {
|
|
56
|
-
(0, _middlewares.requestInterceptorMiddleware)(
|
|
63
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
64
|
+
server,
|
|
65
|
+
path: restBaseUrl,
|
|
66
|
+
interceptor: apiRequestInterceptor
|
|
67
|
+
});
|
|
57
68
|
}
|
|
58
|
-
const restBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_rest$baseUrl = rest.baseUrl) !== null && _rest$baseUrl !== void 0 ? _rest$baseUrl : '/');
|
|
59
69
|
server.use(restBaseUrl, routerWithRestRoutes);
|
|
60
70
|
}
|
|
61
71
|
if (graphql) {
|
|
62
|
-
var _graphql$
|
|
63
|
-
const routerWithGraphQLRoutes = (0, _graphql.createGraphQLRoutes)(
|
|
72
|
+
var _graphql$baseUrl, _graphql$interceptors;
|
|
73
|
+
const routerWithGraphQLRoutes = (0, _graphql.createGraphQLRoutes)({
|
|
74
|
+
router: _express.default.Router(),
|
|
75
|
+
graphqlConfig: graphql,
|
|
76
|
+
serverResponseInterceptor: interceptors === null || interceptors === void 0 ? void 0 : interceptors.response
|
|
77
|
+
});
|
|
78
|
+
const graphqlBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_graphql$baseUrl = graphql.baseUrl) !== null && _graphql$baseUrl !== void 0 ? _graphql$baseUrl : '/');
|
|
64
79
|
const apiRequestInterceptor = (_graphql$interceptors = graphql.interceptors) === null || _graphql$interceptors === void 0 ? void 0 : _graphql$interceptors.request;
|
|
65
80
|
if (apiRequestInterceptor) {
|
|
66
|
-
(0, _middlewares.requestInterceptorMiddleware)(
|
|
81
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
82
|
+
server,
|
|
83
|
+
path: graphqlBaseUrl,
|
|
84
|
+
interceptor: apiRequestInterceptor
|
|
85
|
+
});
|
|
67
86
|
}
|
|
68
|
-
const graphqlBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_graphql$baseUrl = graphql.baseUrl) !== null && _graphql$baseUrl !== void 0 ? _graphql$baseUrl : '/');
|
|
69
87
|
server.use(graphqlBaseUrl, routerWithGraphQLRoutes);
|
|
70
88
|
}
|
|
71
89
|
if (database) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRestMockServer = void 0;
|
|
7
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _database = require("../../core/database");
|
|
10
|
+
var _middlewares = require("../../core/middlewares");
|
|
11
|
+
var _rest = require("../../core/rest");
|
|
12
|
+
var _helpers = require("../../utils/helpers");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
const createRestMockServer = (restMockServerConfig, server = (0, _express.default)()) => {
|
|
15
|
+
var _restMockServerConfig, _restMockServerConfig2;
|
|
16
|
+
const {
|
|
17
|
+
cors,
|
|
18
|
+
staticPath,
|
|
19
|
+
configs,
|
|
20
|
+
database,
|
|
21
|
+
interceptors
|
|
22
|
+
} = restMockServerConfig;
|
|
23
|
+
server.set('view engine', 'ejs');
|
|
24
|
+
server.set('views', (0, _helpers.urlJoin)(__dirname, '../../static/views'));
|
|
25
|
+
server.use(_express.default.static((0, _helpers.urlJoin)(__dirname, '../../static/views')));
|
|
26
|
+
server.use(_bodyParser.default.urlencoded({
|
|
27
|
+
extended: false
|
|
28
|
+
}));
|
|
29
|
+
server.use(_bodyParser.default.json({
|
|
30
|
+
limit: '10mb'
|
|
31
|
+
}));
|
|
32
|
+
server.set('json spaces', 2);
|
|
33
|
+
server.use(_bodyParser.default.text());
|
|
34
|
+
(0, _middlewares.cookieParseMiddleware)(server);
|
|
35
|
+
const serverRequestInterceptor = (_restMockServerConfig = restMockServerConfig.interceptors) === null || _restMockServerConfig === void 0 ? void 0 : _restMockServerConfig.request;
|
|
36
|
+
if (serverRequestInterceptor) {
|
|
37
|
+
(0, _middlewares.requestInterceptorMiddleware)({
|
|
38
|
+
server,
|
|
39
|
+
interceptor: serverRequestInterceptor
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const baseUrl = (_restMockServerConfig2 = restMockServerConfig.baseUrl) !== null && _restMockServerConfig2 !== void 0 ? _restMockServerConfig2 : '/';
|
|
43
|
+
if (cors) {
|
|
44
|
+
(0, _middlewares.corsMiddleware)(server, cors);
|
|
45
|
+
} else {
|
|
46
|
+
(0, _middlewares.noCorsMiddleware)(server);
|
|
47
|
+
}
|
|
48
|
+
if (staticPath) {
|
|
49
|
+
(0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
|
|
50
|
+
}
|
|
51
|
+
const routerWithRestRoutes = (0, _rest.createRestRoutes)({
|
|
52
|
+
router: _express.default.Router(),
|
|
53
|
+
restConfig: {
|
|
54
|
+
configs
|
|
55
|
+
},
|
|
56
|
+
serverResponseInterceptor: interceptors === null || interceptors === void 0 ? void 0 : interceptors.response
|
|
57
|
+
});
|
|
58
|
+
server.use(baseUrl, routerWithRestRoutes);
|
|
59
|
+
if (database) {
|
|
60
|
+
const routerWithDatabaseRoutes = (0, _database.createDatabaseRoutes)(_express.default.Router(), database);
|
|
61
|
+
server.use(baseUrl, routerWithDatabaseRoutes);
|
|
62
|
+
}
|
|
63
|
+
(0, _middlewares.notFoundMiddleware)(server, restMockServerConfig);
|
|
64
|
+
(0, _middlewares.errorMiddleware)(server);
|
|
65
|
+
return server;
|
|
66
|
+
};
|
|
67
|
+
exports.createRestMockServer = createRestMockServer;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
export * from './createDatabaseMockServer/createDatabaseMockServer';
|
|
2
|
+
export * from './createGraphQLMockServer/createGraphQLMockServer';
|
|
1
3
|
export * from './createMockServer/createMockServer';
|
|
4
|
+
export * from './createRestMockServer/createRestMockServer';
|
|
5
|
+
export * from './startDatabaseMockServer/startDatabaseMockServer';
|
|
6
|
+
export * from './startGraphQLMockServer/startGraphQLMockServer';
|
|
2
7
|
export * from './startMockServer/startMockServer';
|
|
8
|
+
export * from './startRestMockServer/startRestMockServer';
|
package/dist/src/server/index.js
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _createDatabaseMockServer = require("./createDatabaseMockServer/createDatabaseMockServer");
|
|
7
|
+
Object.keys(_createDatabaseMockServer).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _createDatabaseMockServer[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _createDatabaseMockServer[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _createGraphQLMockServer = require("./createGraphQLMockServer/createGraphQLMockServer");
|
|
18
|
+
Object.keys(_createGraphQLMockServer).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _createGraphQLMockServer[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _createGraphQLMockServer[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
6
28
|
var _createMockServer = require("./createMockServer/createMockServer");
|
|
7
29
|
Object.keys(_createMockServer).forEach(function (key) {
|
|
8
30
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -14,6 +36,39 @@ Object.keys(_createMockServer).forEach(function (key) {
|
|
|
14
36
|
}
|
|
15
37
|
});
|
|
16
38
|
});
|
|
39
|
+
var _createRestMockServer = require("./createRestMockServer/createRestMockServer");
|
|
40
|
+
Object.keys(_createRestMockServer).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _createRestMockServer[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _createRestMockServer[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _startDatabaseMockServer = require("./startDatabaseMockServer/startDatabaseMockServer");
|
|
51
|
+
Object.keys(_startDatabaseMockServer).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _startDatabaseMockServer[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _startDatabaseMockServer[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _startGraphQLMockServer = require("./startGraphQLMockServer/startGraphQLMockServer");
|
|
62
|
+
Object.keys(_startGraphQLMockServer).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _startGraphQLMockServer[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _startGraphQLMockServer[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
17
72
|
var _startMockServer = require("./startMockServer/startMockServer");
|
|
18
73
|
Object.keys(_startMockServer).forEach(function (key) {
|
|
19
74
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -24,4 +79,15 @@ Object.keys(_startMockServer).forEach(function (key) {
|
|
|
24
79
|
return _startMockServer[key];
|
|
25
80
|
}
|
|
26
81
|
});
|
|
82
|
+
});
|
|
83
|
+
var _startRestMockServer = require("./startRestMockServer/startRestMockServer");
|
|
84
|
+
Object.keys(_startRestMockServer).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _startRestMockServer[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _startRestMockServer[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
27
93
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { DatabaseMockServerConfig } from '../../utils/types';
|
|
3
|
+
export declare const startDatabaseMockServer: (databaseMockServerConfig: DatabaseMockServerConfig) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> & {
|
|
4
|
+
destroy: (callback?: ((err?: Error | undefined) => void) | undefined) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startDatabaseMockServer = void 0;
|
|
7
|
+
var _ansiColors = _interopRequireDefault(require("ansi-colors"));
|
|
8
|
+
var _middlewares = require("../../core/middlewares");
|
|
9
|
+
var _constants = require("../../utils/constants");
|
|
10
|
+
var _createDatabaseMockServer = require("../createDatabaseMockServer/createDatabaseMockServer");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const startDatabaseMockServer = databaseMockServerConfig => {
|
|
13
|
+
var _databaseMockServerCo;
|
|
14
|
+
const mockServer = (0, _createDatabaseMockServer.createDatabaseMockServer)(databaseMockServerConfig);
|
|
15
|
+
const port = (_databaseMockServerCo = databaseMockServerConfig.port) !== null && _databaseMockServerCo !== void 0 ? _databaseMockServerCo : _constants.DEFAULT.PORT;
|
|
16
|
+
const server = mockServer.listen(port, () => {
|
|
17
|
+
console.log(_ansiColors.default.green(`🎉 Database Mock Server is running at http://localhost:${port}`));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ✅ important: add destroy method for closing keep-alive connections after server shutdown
|
|
21
|
+
return (0, _middlewares.destroyerMiddleware)(server);
|
|
22
|
+
};
|
|
23
|
+
exports.startDatabaseMockServer = startDatabaseMockServer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { GraphQLMockServerConfig } from '../../utils/types';
|
|
3
|
+
export declare const startGraphQLMockServer: (graphQLMockServerConfig: GraphQLMockServerConfig) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> & {
|
|
4
|
+
destroy: (callback?: ((err?: Error | undefined) => void) | undefined) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startGraphQLMockServer = void 0;
|
|
7
|
+
var _ansiColors = _interopRequireDefault(require("ansi-colors"));
|
|
8
|
+
var _middlewares = require("../../core/middlewares");
|
|
9
|
+
var _constants = require("../../utils/constants");
|
|
10
|
+
var _createGraphQLMockServer = require("../createGraphQLMockServer/createGraphQLMockServer");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const startGraphQLMockServer = graphQLMockServerConfig => {
|
|
13
|
+
var _graphQLMockServerCon;
|
|
14
|
+
const mockServer = (0, _createGraphQLMockServer.createGraphQLMockServer)(graphQLMockServerConfig);
|
|
15
|
+
const port = (_graphQLMockServerCon = graphQLMockServerConfig.port) !== null && _graphQLMockServerCon !== void 0 ? _graphQLMockServerCon : _constants.DEFAULT.PORT;
|
|
16
|
+
const server = mockServer.listen(port, () => {
|
|
17
|
+
console.log(_ansiColors.default.green(`🎉 GraphQL Mock Server is running at http://localhost:${port}`));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ✅ important: add destroy method for closing keep-alive connections after server shutdown
|
|
21
|
+
return (0, _middlewares.destroyerMiddleware)(server);
|
|
22
|
+
};
|
|
23
|
+
exports.startGraphQLMockServer = startGraphQLMockServer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { RestMockServerConfig } from '../../utils/types';
|
|
3
|
+
export declare const startRestMockServer: (restMockServerConfig: RestMockServerConfig) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> & {
|
|
4
|
+
destroy: (callback?: ((err?: Error | undefined) => void) | undefined) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startRestMockServer = void 0;
|
|
7
|
+
var _ansiColors = _interopRequireDefault(require("ansi-colors"));
|
|
8
|
+
var _middlewares = require("../../core/middlewares");
|
|
9
|
+
var _constants = require("../../utils/constants");
|
|
10
|
+
var _createRestMockServer = require("../createRestMockServer/createRestMockServer");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const startRestMockServer = restMockServerConfig => {
|
|
13
|
+
var _restMockServerConfig;
|
|
14
|
+
const mockServer = (0, _createRestMockServer.createRestMockServer)(restMockServerConfig);
|
|
15
|
+
const port = (_restMockServerConfig = restMockServerConfig.port) !== null && _restMockServerConfig !== void 0 ? _restMockServerConfig : _constants.DEFAULT.PORT;
|
|
16
|
+
const server = mockServer.listen(port, () => {
|
|
17
|
+
console.log(_ansiColors.default.green(`🎉 Rest Mock Server is running at http://localhost:${port}`));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ✅ important: add destroy method for closing keep-alive connections after server shutdown
|
|
21
|
+
return (0, _middlewares.destroyerMiddleware)(server);
|
|
22
|
+
};
|
|
23
|
+
exports.startRestMockServer = startRestMockServer;
|
|
@@ -56,7 +56,7 @@ a {
|
|
|
56
56
|
line-height: 17px;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
.
|
|
59
|
+
.margin_container {
|
|
60
60
|
display: flex;
|
|
61
61
|
width: 100%;
|
|
62
62
|
justify-content: center;
|
|
@@ -80,7 +80,7 @@ a {
|
|
|
80
80
|
padding-inline: 75px;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
.
|
|
83
|
+
.content_head {
|
|
84
84
|
display: flex;
|
|
85
85
|
flex-direction: column;
|
|
86
86
|
align-items: center;
|