mock-config-server 3.2.0 → 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.
Files changed (47) hide show
  1. package/README.md +153 -3
  2. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +2 -1
  3. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +30 -7
  4. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +9 -3
  5. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +67 -18
  6. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.d.ts +1 -0
  7. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.js +29 -0
  8. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +67 -18
  9. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.d.ts +1 -0
  10. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.js +34 -0
  11. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +45 -2
  12. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +2 -1
  13. package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +13 -0
  14. package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +36 -0
  15. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +2 -0
  16. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +42 -0
  17. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +7 -1
  18. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +65 -24
  19. package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +1 -3
  20. package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +7 -1
  21. package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +6 -2
  22. package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +7 -1
  23. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +55 -12
  24. package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +4 -1
  25. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +11 -4
  26. package/dist/src/server/createMockServer/createMockServer.js +28 -9
  27. package/dist/src/server/createRestMockServer/createRestMockServer.js +11 -4
  28. package/dist/src/server/index.d.ts +3 -3
  29. package/dist/src/server/index.js +23 -23
  30. package/dist/src/static/views/components/header/index.js +1 -1
  31. package/dist/src/static/views/features/scheme/index.js +31 -31
  32. package/dist/src/static/views/features/tab/index.js +12 -12
  33. package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +2 -1
  34. package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.d.ts +7 -2
  35. package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +6 -4
  36. package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +1 -1
  37. package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +1 -1
  38. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +19 -10
  39. package/dist/src/utils/types/graphql.d.ts +60 -51
  40. package/dist/src/utils/types/index.d.ts +1 -0
  41. package/dist/src/utils/types/index.js +11 -0
  42. package/dist/src/utils/types/interceptors.d.ts +1 -1
  43. package/dist/src/utils/types/rest.d.ts +47 -40
  44. package/dist/src/utils/types/utils.d.ts +8 -0
  45. package/dist/src/utils/types/utils.js +1 -0
  46. package/dist/src/utils/types/values.d.ts +0 -1
  47. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ import type { ParsedUrlQuery } from 'node:querystring';
2
+ export declare const pagination: (array: any[], queries: ParsedUrlQuery) => any[] | {
3
+ _link: {
4
+ count: number;
5
+ pages: number;
6
+ first: number;
7
+ current: number;
8
+ next: number | null;
9
+ prev: number | null;
10
+ last: number | null;
11
+ };
12
+ results: any[];
13
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pagination = void 0;
7
+ const DEFAULT_LIMIT = 10;
8
+ const pagination = (array, queries) => {
9
+ const {
10
+ _page
11
+ } = queries;
12
+ if (!_page || +_page <= 0) return array;
13
+ const page = +_page;
14
+ const limit = queries._limit && +queries._limit > 0 ? +queries._limit : DEFAULT_LIMIT;
15
+ const pages = Math.ceil(array.length / limit);
16
+ if (page > pages) return array;
17
+ const start = page * limit - limit;
18
+ const end = page * limit;
19
+ const results = array.slice(start, end);
20
+ const next = page + 1 <= pages ? page + 1 : null;
21
+ const prev = page - 1 !== 0 ? page - 1 : null;
22
+ const last = pages > 0 ? pages : null;
23
+ return {
24
+ _link: {
25
+ count: array.length,
26
+ pages,
27
+ first: 1,
28
+ current: page,
29
+ next,
30
+ prev,
31
+ last
32
+ },
33
+ results
34
+ };
35
+ };
36
+ exports.pagination = pagination;
@@ -0,0 +1,2 @@
1
+ import type { ParsedUrlQuery } from 'node:querystring';
2
+ export declare const sort: (array: any[], queries: ParsedUrlQuery) => any[];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sort = void 0;
7
+ var _flat = _interopRequireDefault(require("flat"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ const DEFAULT_ORDER = 'asc';
10
+ const getOrder = order => {
11
+ if (order === 'asc' || order === 'desc') return order;
12
+ return DEFAULT_ORDER;
13
+ };
14
+ const sortArray = (array, key, order) => array.sort((a, b) => {
15
+ const flattenedA = (0, _flat.default)(a);
16
+ const flattenedB = (0, _flat.default)(b);
17
+ if (!flattenedA[key] || !flattenedB[key]) return 0;
18
+ if (typeof flattenedA[key] === 'string' && typeof flattenedB[key] === 'string') {
19
+ return order === 'asc' ? flattenedA[key].localeCompare(flattenedB[key]) : flattenedB[key].localeCompare(flattenedA[key]);
20
+ }
21
+ return order === 'asc' ? Number(flattenedA[key]) - Number(flattenedB[key]) : Number(flattenedB[key]) - Number(flattenedA[key]);
22
+ });
23
+ const sort = (array, queries) => {
24
+ const {
25
+ _sort,
26
+ _order = DEFAULT_ORDER
27
+ } = queries;
28
+ if (!_sort) return array;
29
+ const result = [...array];
30
+ if (Array.isArray(_sort)) {
31
+ const orders = Array.isArray(_order) ? _order : [_order];
32
+ _sort.forEach((key, index) => {
33
+ const order = getOrder(orders[index]);
34
+ sortArray(result, key, order);
35
+ });
36
+ return result;
37
+ }
38
+ const order = getOrder(Array.isArray(_order) ? _order[0] : _order);
39
+ sortArray(result, _sort, order);
40
+ return result;
41
+ };
42
+ exports.sort = sort;
@@ -1,3 +1,9 @@
1
1
  import type { IRouter } from 'express';
2
2
  import type { GraphqlConfig, Interceptors } from '../../../utils/types';
3
- export declare const createGraphQLRoutes: (router: IRouter, graphqlConfig: GraphqlConfig, serverResponseInterceptors?: Interceptors['response']) => IRouter;
3
+ interface CreateGraphQLRoutesParams {
4
+ router: IRouter;
5
+ graphqlConfig: GraphqlConfig;
6
+ serverResponseInterceptor?: Interceptors['response'];
7
+ }
8
+ export declare const createGraphQLRoutes: ({ router, graphqlConfig, serverResponseInterceptor }: CreateGraphQLRoutesParams) => IRouter;
9
+ export {};
@@ -7,12 +7,16 @@ exports.createGraphQLRoutes = void 0;
7
7
  var _flat = require("flat");
8
8
  var _helpers = require("../../../utils/helpers");
9
9
  var _helpers2 = require("./helpers");
10
- const createGraphQLRoutes = (router, graphqlConfig, serverResponseInterceptors) => {
10
+ const createGraphQLRoutes = ({
11
+ router,
12
+ graphqlConfig,
13
+ serverResponseInterceptor
14
+ }) => {
11
15
  const preparedGraphQLRequestConfig = (0, _helpers2.prepareGraphQLRequestConfigs)(graphqlConfig.configs);
12
16
  const graphqlMiddleware = async (request, response, next) => {
13
- var _matchedRequestConfig, _matchedRouteConfig$e, _matchedRouteConfig$i, _matchedRequestConfig2, _graphqlConfig$interc;
17
+ var _matchedRequestConfig, _matchedRouteConfig$s, _matchedRouteConfig$e, _matchedRouteConfig$i, _matchedRequestConfig2, _graphqlConfig$interc;
14
18
  const graphQLInput = (0, _helpers.getGraphQLInput)(request);
15
- if (!graphQLInput || !graphQLInput.query) {
19
+ if (!graphQLInput.query) {
16
20
  return response.status(400).json({
17
21
  message: 'Query is missing, you must pass a valid GraphQL query'
18
22
  });
@@ -23,16 +27,16 @@ const createGraphQLRoutes = (router, graphqlConfig, serverResponseInterceptors)
23
27
  message: 'Query is invalid, you must use a valid GraphQL query'
24
28
  });
25
29
  }
26
- if (!query.operationName || !query.operationType) {
27
- return response.status(400).json({
28
- message: `You should to specify operationName and operationType for ${request.method}:${request.baseUrl}${request.path}`
29
- });
30
- }
31
30
  const matchedRequestConfig = preparedGraphQLRequestConfig.find(requestConfig => {
32
- if (requestConfig.operationName instanceof RegExp) {
33
- return new RegExp(requestConfig.operationName).test(query.operationName) && requestConfig.operationType === query.operationType;
31
+ var _graphQLInput$query;
32
+ if (requestConfig.operationType !== query.operationType) return false;
33
+ if ('query' in requestConfig && requestConfig.query.replace(/\s+/gi, ' ') !== ((_graphQLInput$query = graphQLInput.query) === null || _graphQLInput$query === void 0 ? void 0 : _graphQLInput$query.replace(/\s+/gi, ' '))) return false;
34
+ if ('operationName' in requestConfig) {
35
+ if (!query.operationName) return false;
36
+ if (requestConfig.operationName instanceof RegExp) return new RegExp(requestConfig.operationName).test(query.operationName);
37
+ return requestConfig.operationName === query.operationName;
34
38
  }
35
- return requestConfig.operationName === query.operationName && requestConfig.operationType === query.operationType;
39
+ return true;
36
40
  });
37
41
  if (!matchedRequestConfig) {
38
42
  return next();
@@ -49,25 +53,29 @@ const createGraphQLRoutes = (router, graphqlConfig, serverResponseInterceptors)
49
53
  }) => {
50
54
  if (!entities) return true;
51
55
  const entries = Object.entries(entities);
52
- return entries.every(([entityName, valueOrDescriptor]) => {
56
+ return entries.every(([entityName, entityDescriptorOrValue]) => {
53
57
  const {
54
58
  checkMode,
55
- value: descriptorValue
56
- } = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
59
+ value: entityDescriptorValue
60
+ } = (0, _helpers.convertToEntityDescriptor)(entityDescriptorOrValue);
57
61
 
58
62
  // ✅ important: check whole variables as plain value strictly if descriptor used for variables
59
- const isVariablesPlain = entityName === 'variables' && (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
60
- if (isVariablesPlain) {
61
- // important: getGraphQLInput returns empty object if variables not sent or invalid, so count {} as undefined
62
- return (0, _helpers.resolveEntityValues)(checkMode, Object.keys(graphQLInput.variables).length ? graphQLInput.variables : undefined, descriptorValue);
63
+ const isEntityVariablesByTopLevelDescriptor = entityName === 'variables' && (0, _helpers.isEntityDescriptor)(entityDescriptorOrValue);
64
+ if (isEntityVariablesByTopLevelDescriptor) {
65
+ return (0, _helpers.resolveEntityValues)(checkMode, graphQLInput.variables, entityDescriptorValue);
63
66
  }
64
- const mappedEntityDescriptors = Object.entries(valueOrDescriptor);
65
- return mappedEntityDescriptors.every(([entityKey, mappedEntityDescriptor]) => {
67
+ const isEntityVariablesByTopLevelArray = entityName === 'variables' && Array.isArray(entityDescriptorOrValue);
68
+ if (isEntityVariablesByTopLevelArray) {
69
+ return entityDescriptorOrValue.some(entityDescriptorOrValueElement => (0, _helpers.resolveEntityValues)(checkMode, graphQLInput.variables, entityDescriptorOrValueElement));
70
+ }
71
+ const recordOrArrayEntries = Object.entries(entityDescriptorOrValue);
72
+ return recordOrArrayEntries.every(([entityKey, entityValue]) => {
66
73
  const {
67
74
  checkMode,
68
75
  value: descriptorValue
69
- } = (0, _helpers.convertToEntityDescriptor)(mappedEntityDescriptor);
76
+ } = (0, _helpers.convertToEntityDescriptor)(entityValue);
70
77
  const flattenEntity = (0, _flat.flatten)(entityName === 'variables' ? graphQLInput.variables : request[entityName]);
78
+
71
79
  // ✅ important: transform header keys to lower case because browsers send headers in lowercase
72
80
  return (0, _helpers.resolveEntityValues)(checkMode, flattenEntity[entityName === 'headers' ? entityKey.toLowerCase() : entityKey], descriptorValue);
73
81
  });
@@ -76,16 +84,49 @@ const createGraphQLRoutes = (router, graphqlConfig, serverResponseInterceptors)
76
84
  if (!matchedRouteConfig) {
77
85
  return next();
78
86
  }
79
- const matchedRouteConfigData = typeof matchedRouteConfig.data === 'function' ? await matchedRouteConfig.data(request, (_matchedRouteConfig$e = matchedRouteConfig.entities) !== null && _matchedRouteConfig$e !== void 0 ? _matchedRouteConfig$e : {}) : matchedRouteConfig.data;
87
+ let matchedRouteConfigData = null;
88
+ if ((_matchedRouteConfig$s = matchedRouteConfig.settings) !== null && _matchedRouteConfig$s !== void 0 && _matchedRouteConfig$s.polling && 'queue' in matchedRouteConfig) {
89
+ var _shallowMatchedRouteC;
90
+ if (!matchedRouteConfig.queue.length) return next();
91
+ const shallowMatchedRouteConfig = matchedRouteConfig;
92
+ let index = (_shallowMatchedRouteC = shallowMatchedRouteConfig.__pollingIndex) !== null && _shallowMatchedRouteC !== void 0 ? _shallowMatchedRouteC : 0;
93
+ const {
94
+ time,
95
+ data
96
+ } = matchedRouteConfig.queue[index];
97
+ const updateIndex = () => {
98
+ if (matchedRouteConfig.queue.length - 1 === index) {
99
+ index = 0;
100
+ } else {
101
+ index += 1;
102
+ }
103
+ shallowMatchedRouteConfig.__pollingIndex = index;
104
+ };
105
+ if (time && !shallowMatchedRouteConfig.__timeoutInProgress) {
106
+ shallowMatchedRouteConfig.__timeoutInProgress = true;
107
+ setTimeout(() => {
108
+ shallowMatchedRouteConfig.__timeoutInProgress = false;
109
+ updateIndex();
110
+ }, time);
111
+ }
112
+ if (!time && !shallowMatchedRouteConfig.__timeoutInProgress) {
113
+ updateIndex();
114
+ }
115
+ matchedRouteConfigData = data;
116
+ }
117
+ if ('data' in matchedRouteConfig) {
118
+ matchedRouteConfigData = matchedRouteConfig.data;
119
+ }
120
+ const resolvedData = typeof matchedRouteConfigData === 'function' ? await matchedRouteConfigData(request, (_matchedRouteConfig$e = matchedRouteConfig.entities) !== null && _matchedRouteConfig$e !== void 0 ? _matchedRouteConfig$e : {}) : matchedRouteConfigData;
80
121
  const data = await (0, _helpers.callResponseInterceptors)({
81
- data: matchedRouteConfigData,
122
+ data: resolvedData,
82
123
  request,
83
124
  response,
84
125
  interceptors: {
85
126
  routeInterceptor: (_matchedRouteConfig$i = matchedRouteConfig.interceptors) === null || _matchedRouteConfig$i === void 0 ? void 0 : _matchedRouteConfig$i.response,
86
127
  requestInterceptor: (_matchedRequestConfig2 = matchedRequestConfig.interceptors) === null || _matchedRequestConfig2 === void 0 ? void 0 : _matchedRequestConfig2.response,
87
128
  apiInterceptor: (_graphqlConfig$interc = graphqlConfig.interceptors) === null || _graphqlConfig$interc === void 0 ? void 0 : _graphqlConfig$interc.response,
88
- serverInterceptor: serverResponseInterceptors
129
+ serverInterceptor: serverResponseInterceptor
89
130
  }
90
131
  });
91
132
 
@@ -22,9 +22,7 @@ const notFoundMiddleware = (server, mockServerConfig) => {
22
22
  path: `${serverBaseUrl !== null && serverBaseUrl !== void 0 ? serverBaseUrl : ''}${(_rest$baseUrl = rest === null || rest === void 0 ? void 0 : rest.baseUrl) !== null && _rest$baseUrl !== void 0 ? _rest$baseUrl : ''}${request.path}`
23
23
  };
24
24
  })) !== null && _rest$configs$filter$ !== void 0 ? _rest$configs$filter$ : [];
25
- const graphqlRequestConfigs = (_graphql$configs$filt = graphql === null || graphql === void 0 ? void 0 : graphql.configs.filter(({
26
- operationName
27
- }) => !(operationName instanceof RegExp)).map(request => {
25
+ const graphqlRequestConfigs = (_graphql$configs$filt = graphql === null || graphql === void 0 ? void 0 : graphql.configs.filter(request => 'operationName' in request && !(request.operationName instanceof RegExp)).map(request => {
28
26
  var _graphql$baseUrl;
29
27
  return {
30
28
  operationType: request.operationType,
@@ -1,3 +1,9 @@
1
1
  import type { Express } from 'express';
2
2
  import type { RequestInterceptor } from '../../../utils/types';
3
- export declare const requestInterceptorMiddleware: (server: Express, interceptor: RequestInterceptor) => void;
3
+ interface RequestInterceptorMiddlewareParams {
4
+ server: Express;
5
+ path?: string;
6
+ interceptor: RequestInterceptor;
7
+ }
8
+ export declare const requestInterceptorMiddleware: ({ server, path, interceptor }: RequestInterceptorMiddlewareParams) => void;
9
+ export {};
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.requestInterceptorMiddleware = void 0;
7
7
  var _helpers = require("../../../utils/helpers");
8
- const requestInterceptorMiddleware = (server, interceptor) => {
9
- server.use((0, _helpers.asyncHandler)(async (request, _response, next) => {
8
+ const requestInterceptorMiddleware = ({
9
+ server,
10
+ path = '*',
11
+ interceptor
12
+ }) => {
13
+ server.use(path, (0, _helpers.asyncHandler)(async (request, _response, next) => {
10
14
  await (0, _helpers.callRequestInterceptor)({
11
15
  request,
12
16
  interceptor
@@ -1,3 +1,9 @@
1
1
  import type { IRouter } from 'express';
2
2
  import type { Interceptors, RestConfig } from '../../../utils/types';
3
- export declare const createRestRoutes: (router: IRouter, restConfig: RestConfig, serverResponseInterceptors?: Interceptors['response']) => IRouter;
3
+ interface CreateRestRoutesParams {
4
+ router: IRouter;
5
+ restConfig: RestConfig;
6
+ serverResponseInterceptor?: Interceptors['response'];
7
+ }
8
+ export declare const createRestRoutes: ({ router, restConfig, serverResponseInterceptor }: CreateRestRoutesParams) => IRouter;
9
+ export {};
@@ -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 = (router, restConfig, serverResponseInterceptors) => {
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, valueOrDescriptor]) => {
30
+ return entries.every(([entityName, entityDescriptorOrValue]) => {
27
31
  const {
28
32
  checkMode,
29
33
  value: descriptorValue
30
- } = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
34
+ } = (0, _helpers.convertToEntityDescriptor)(entityDescriptorOrValue);
31
35
 
32
36
  // ✅ important: check whole body as plain value strictly if descriptor used for body
33
- const isBodyPlain = entityName === 'body' && (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
34
- if (isBodyPlain) {
35
- // ✅ important: bodyParser sets body to empty object if body not sent or invalid, so count {} as undefined
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 mappedEntityDescriptors = Object.entries(valueOrDescriptor);
39
- return mappedEntityDescriptors.every(([entityKey, mappedEntityDescriptor]) => {
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
- const matchedRouteConfigData = typeof matchedRouteConfig.data === 'function' ? await matchedRouteConfig.data(request, (_matchedRouteConfig$e = matchedRouteConfig.entities) !== null && _matchedRouteConfig$e !== void 0 ? _matchedRouteConfig$e : {}) : matchedRouteConfig.data;
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: matchedRouteConfigData,
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: serverResponseInterceptors
105
+ serverInterceptor: serverResponseInterceptor
63
106
  }
64
107
  });
65
108
 
@@ -32,7 +32,10 @@ const createDatabaseMockServer = (databaseMockServerConfig, server = (0, _expres
32
32
  (0, _middlewares.cookieParseMiddleware)(server);
33
33
  const serverRequestInterceptor = (_databaseMockServerCo = databaseMockServerConfig.interceptors) === null || _databaseMockServerCo === void 0 ? void 0 : _databaseMockServerCo.request;
34
34
  if (serverRequestInterceptor) {
35
- (0, _middlewares.requestInterceptorMiddleware)(server, serverRequestInterceptor);
35
+ (0, _middlewares.requestInterceptorMiddleware)({
36
+ server,
37
+ interceptor: serverRequestInterceptor
38
+ });
36
39
  }
37
40
  const baseUrl = (_databaseMockServerCo2 = databaseMockServerConfig.baseUrl) !== null && _databaseMockServerCo2 !== void 0 ? _databaseMockServerCo2 : '/';
38
41
  if (cors) {
@@ -34,7 +34,10 @@ const createGraphQLMockServer = (graphqlMockServerConfig, server = (0, _express.
34
34
  (0, _middlewares.cookieParseMiddleware)(server);
35
35
  const serverRequestInterceptor = (_graphqlMockServerCon = graphqlMockServerConfig.interceptors) === null || _graphqlMockServerCon === void 0 ? void 0 : _graphqlMockServerCon.request;
36
36
  if (serverRequestInterceptor) {
37
- (0, _middlewares.requestInterceptorMiddleware)(server, serverRequestInterceptor);
37
+ (0, _middlewares.requestInterceptorMiddleware)({
38
+ server,
39
+ interceptor: serverRequestInterceptor
40
+ });
38
41
  }
39
42
  const baseUrl = (_graphqlMockServerCon2 = graphqlMockServerConfig.baseUrl) !== null && _graphqlMockServerCon2 !== void 0 ? _graphqlMockServerCon2 : '/';
40
43
  if (cors) {
@@ -45,9 +48,13 @@ const createGraphQLMockServer = (graphqlMockServerConfig, server = (0, _express.
45
48
  if (staticPath) {
46
49
  (0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
47
50
  }
48
- const routerWithGraphqlRoutes = (0, _graphql.createGraphQLRoutes)(_express.default.Router(), {
49
- configs
50
- }, interceptors === null || interceptors === void 0 ? void 0 : interceptors.response);
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
+ });
51
58
  server.use(baseUrl, routerWithGraphqlRoutes);
52
59
  if (database) {
53
60
  const routerWithDatabaseRoutes = (0, _database.createDatabaseRoutes)(_express.default.Router(), database);
@@ -36,7 +36,10 @@ const createMockServer = (mockServerConfig, server = (0, _express.default)()) =>
36
36
  (0, _middlewares.cookieParseMiddleware)(server);
37
37
  const serverRequestInterceptor = (_mockServerConfig$int = mockServerConfig.interceptors) === null || _mockServerConfig$int === void 0 ? void 0 : _mockServerConfig$int.request;
38
38
  if (serverRequestInterceptor) {
39
- (0, _middlewares.requestInterceptorMiddleware)(server, serverRequestInterceptor);
39
+ (0, _middlewares.requestInterceptorMiddleware)({
40
+ server,
41
+ interceptor: serverRequestInterceptor
42
+ });
40
43
  }
41
44
  const baseUrl = (_mockServerConfig$bas = mockServerConfig.baseUrl) !== null && _mockServerConfig$bas !== void 0 ? _mockServerConfig$bas : '/';
42
45
  if (cors) {
@@ -48,23 +51,39 @@ const createMockServer = (mockServerConfig, server = (0, _express.default)()) =>
48
51
  (0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
49
52
  }
50
53
  if (rest) {
51
- var _rest$interceptors, _rest$baseUrl;
52
- const routerWithRestRoutes = (0, _rest.createRestRoutes)(_express.default.Router(), rest, interceptors === null || interceptors === void 0 ? void 0 : interceptors.response);
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 : '/');
53
61
  const apiRequestInterceptor = (_rest$interceptors = rest.interceptors) === null || _rest$interceptors === void 0 ? void 0 : _rest$interceptors.request;
54
62
  if (apiRequestInterceptor) {
55
- (0, _middlewares.requestInterceptorMiddleware)(server, apiRequestInterceptor);
63
+ (0, _middlewares.requestInterceptorMiddleware)({
64
+ server,
65
+ path: restBaseUrl,
66
+ interceptor: apiRequestInterceptor
67
+ });
56
68
  }
57
- const restBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_rest$baseUrl = rest.baseUrl) !== null && _rest$baseUrl !== void 0 ? _rest$baseUrl : '/');
58
69
  server.use(restBaseUrl, routerWithRestRoutes);
59
70
  }
60
71
  if (graphql) {
61
- var _graphql$interceptors, _graphql$baseUrl;
62
- const routerWithGraphQLRoutes = (0, _graphql.createGraphQLRoutes)(_express.default.Router(), graphql, interceptors === null || interceptors === void 0 ? void 0 : interceptors.response);
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 : '/');
63
79
  const apiRequestInterceptor = (_graphql$interceptors = graphql.interceptors) === null || _graphql$interceptors === void 0 ? void 0 : _graphql$interceptors.request;
64
80
  if (apiRequestInterceptor) {
65
- (0, _middlewares.requestInterceptorMiddleware)(server, apiRequestInterceptor);
81
+ (0, _middlewares.requestInterceptorMiddleware)({
82
+ server,
83
+ path: graphqlBaseUrl,
84
+ interceptor: apiRequestInterceptor
85
+ });
66
86
  }
67
- const graphqlBaseUrl = (0, _helpers.urlJoin)(baseUrl, (_graphql$baseUrl = graphql.baseUrl) !== null && _graphql$baseUrl !== void 0 ? _graphql$baseUrl : '/');
68
87
  server.use(graphqlBaseUrl, routerWithGraphQLRoutes);
69
88
  }
70
89
  if (database) {
@@ -34,7 +34,10 @@ const createRestMockServer = (restMockServerConfig, server = (0, _express.defaul
34
34
  (0, _middlewares.cookieParseMiddleware)(server);
35
35
  const serverRequestInterceptor = (_restMockServerConfig = restMockServerConfig.interceptors) === null || _restMockServerConfig === void 0 ? void 0 : _restMockServerConfig.request;
36
36
  if (serverRequestInterceptor) {
37
- (0, _middlewares.requestInterceptorMiddleware)(server, serverRequestInterceptor);
37
+ (0, _middlewares.requestInterceptorMiddleware)({
38
+ server,
39
+ interceptor: serverRequestInterceptor
40
+ });
38
41
  }
39
42
  const baseUrl = (_restMockServerConfig2 = restMockServerConfig.baseUrl) !== null && _restMockServerConfig2 !== void 0 ? _restMockServerConfig2 : '/';
40
43
  if (cors) {
@@ -45,9 +48,13 @@ const createRestMockServer = (restMockServerConfig, server = (0, _express.defaul
45
48
  if (staticPath) {
46
49
  (0, _middlewares.staticMiddleware)(server, baseUrl, staticPath);
47
50
  }
48
- const routerWithRestRoutes = (0, _rest.createRestRoutes)(_express.default.Router(), {
49
- configs
50
- }, interceptors === null || interceptors === void 0 ? void 0 : interceptors.response);
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
+ });
51
58
  server.use(baseUrl, routerWithRestRoutes);
52
59
  if (database) {
53
60
  const routerWithDatabaseRoutes = (0, _database.createDatabaseRoutes)(_express.default.Router(), database);
@@ -1,8 +1,8 @@
1
+ export * from './createDatabaseMockServer/createDatabaseMockServer';
2
+ export * from './createGraphQLMockServer/createGraphQLMockServer';
1
3
  export * from './createMockServer/createMockServer';
2
4
  export * from './createRestMockServer/createRestMockServer';
3
- export * from './createGraphQLMockServer/createGraphQLMockServer';
4
- export * from './createDatabaseMockServer/createDatabaseMockServer';
5
- export * from './startRestMockServer/startRestMockServer';
6
5
  export * from './startDatabaseMockServer/startDatabaseMockServer';
7
6
  export * from './startGraphQLMockServer/startGraphQLMockServer';
8
7
  export * from './startMockServer/startMockServer';
8
+ export * from './startRestMockServer/startRestMockServer';
@@ -3,25 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _createMockServer = require("./createMockServer/createMockServer");
7
- Object.keys(_createMockServer).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _createMockServer[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _createMockServer[key];
14
- }
15
- });
16
- });
17
- var _createRestMockServer = require("./createRestMockServer/createRestMockServer");
18
- Object.keys(_createRestMockServer).forEach(function (key) {
6
+ var _createDatabaseMockServer = require("./createDatabaseMockServer/createDatabaseMockServer");
7
+ Object.keys(_createDatabaseMockServer).forEach(function (key) {
19
8
  if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _createRestMockServer[key]) return;
9
+ if (key in exports && exports[key] === _createDatabaseMockServer[key]) return;
21
10
  Object.defineProperty(exports, key, {
22
11
  enumerable: true,
23
12
  get: function () {
24
- return _createRestMockServer[key];
13
+ return _createDatabaseMockServer[key];
25
14
  }
26
15
  });
27
16
  });
@@ -36,25 +25,25 @@ Object.keys(_createGraphQLMockServer).forEach(function (key) {
36
25
  }
37
26
  });
38
27
  });
39
- var _createDatabaseMockServer = require("./createDatabaseMockServer/createDatabaseMockServer");
40
- Object.keys(_createDatabaseMockServer).forEach(function (key) {
28
+ var _createMockServer = require("./createMockServer/createMockServer");
29
+ Object.keys(_createMockServer).forEach(function (key) {
41
30
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _createDatabaseMockServer[key]) return;
31
+ if (key in exports && exports[key] === _createMockServer[key]) return;
43
32
  Object.defineProperty(exports, key, {
44
33
  enumerable: true,
45
34
  get: function () {
46
- return _createDatabaseMockServer[key];
35
+ return _createMockServer[key];
47
36
  }
48
37
  });
49
38
  });
50
- var _startRestMockServer = require("./startRestMockServer/startRestMockServer");
51
- Object.keys(_startRestMockServer).forEach(function (key) {
39
+ var _createRestMockServer = require("./createRestMockServer/createRestMockServer");
40
+ Object.keys(_createRestMockServer).forEach(function (key) {
52
41
  if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _startRestMockServer[key]) return;
42
+ if (key in exports && exports[key] === _createRestMockServer[key]) return;
54
43
  Object.defineProperty(exports, key, {
55
44
  enumerable: true,
56
45
  get: function () {
57
- return _startRestMockServer[key];
46
+ return _createRestMockServer[key];
58
47
  }
59
48
  });
60
49
  });
@@ -90,4 +79,15 @@ Object.keys(_startMockServer).forEach(function (key) {
90
79
  return _startMockServer[key];
91
80
  }
92
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
+ });
93
93
  });
@@ -1 +1 @@
1
- document.getElementById('scheme_switcher').addEventListener('click', () => window.switchScheme());
1
+ document.getElementById('scheme_switcher').addEventListener('click', () => window.switchScheme());