mock-config-server 3.6.0 → 3.7.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 (68) hide show
  1. package/README.md +291 -90
  2. package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -2
  3. package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -37
  4. package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -14
  5. package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -2
  6. package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -37
  7. package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -14
  8. package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -2
  9. package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -37
  10. package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -14
  11. package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -2
  12. package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -37
  13. package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -14
  14. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +6 -6
  15. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +14 -14
  16. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +1 -1
  17. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +1 -3
  18. package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.d.ts +17 -0
  19. package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.js +33 -0
  20. package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.d.ts +1 -2
  21. package/dist/src/core/middlewares/index.d.ts +1 -0
  22. package/dist/src/core/middlewares/index.js +1 -0
  23. package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +3 -2
  24. package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +1 -1
  25. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +1 -3
  26. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +25 -1
  27. package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +1 -0
  28. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +1 -0
  29. package/dist/src/server/createMockServer/createMockServer.js +1 -0
  30. package/dist/src/server/createRestMockServer/createRestMockServer.js +1 -0
  31. package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +1 -1
  32. package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +1 -1
  33. package/dist/src/server/startMockServer/startMockServer.js +1 -1
  34. package/dist/src/server/startRestMockServer/startRestMockServer.js +1 -1
  35. package/dist/src/static/views/pages/404/index.ejs +66 -69
  36. package/dist/src/utils/helpers/date/formatTimestamp/formatTimestamp.d.ts +1 -0
  37. package/dist/src/utils/helpers/date/formatTimestamp/formatTimestamp.js +18 -0
  38. package/dist/src/utils/helpers/date/index.d.ts +1 -0
  39. package/dist/src/utils/helpers/date/index.js +18 -0
  40. package/dist/src/utils/helpers/index.d.ts +2 -0
  41. package/dist/src/utils/helpers/index.js +2 -0
  42. package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +7 -1
  43. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +9 -1
  44. package/dist/src/utils/helpers/logger/callRequestLogger/callRequestLogger.d.ts +8 -0
  45. package/dist/src/utils/helpers/logger/callRequestLogger/callRequestLogger.js +50 -0
  46. package/dist/src/utils/helpers/logger/callResponseLogger/callResponseLogger.d.ts +10 -0
  47. package/dist/src/utils/helpers/logger/callResponseLogger/callResponseLogger.js +54 -0
  48. package/dist/src/utils/helpers/logger/helpers/filterTokens/filterTokens.d.ts +5 -0
  49. package/dist/src/utils/helpers/logger/helpers/filterTokens/filterTokens.js +44 -0
  50. package/dist/src/utils/helpers/logger/helpers/formatTokens/formatTokens.d.ts +2 -0
  51. package/dist/src/utils/helpers/logger/helpers/formatTokens/formatTokens.js +23 -0
  52. package/dist/src/utils/helpers/logger/helpers/index.d.ts +2 -0
  53. package/dist/src/utils/helpers/logger/helpers/index.js +19 -0
  54. package/dist/src/utils/helpers/logger/index.d.ts +2 -0
  55. package/dist/src/utils/helpers/logger/index.js +19 -0
  56. package/dist/src/utils/types/checkModes.d.ts +0 -1
  57. package/dist/src/utils/types/graphql.d.ts +2 -5
  58. package/dist/src/utils/types/index.d.ts +2 -0
  59. package/dist/src/utils/types/index.js +2 -0
  60. package/dist/src/utils/types/interceptors.d.ts +11 -7
  61. package/dist/src/utils/types/logger.d.ts +43 -0
  62. package/dist/src/utils/types/logger.js +4 -0
  63. package/dist/src/utils/types/rest.d.ts +2 -2
  64. package/dist/src/utils/types/server.d.ts +2 -2
  65. package/dist/src/utils/types/shared.d.ts +1 -0
  66. package/dist/src/utils/types/shared.js +4 -0
  67. package/dist/src/utils/types/values.d.ts +7 -0
  68. package/package.json +1 -1
@@ -1,14 +1,14 @@
1
- import type { RestRequestConfig } from 'mock-config-server';
2
-
3
- export const getUsersRequest: RestRequestConfig = {
4
- path: '/users',
5
- method: 'get',
6
- routes: [
7
- {
8
- data: [
9
- { id: 1, emoji: '🎉' },
10
- { id: 2, emoji: '🔥' }
11
- ]
12
- }
13
- ]
14
- };
1
+ import type { RestRequestConfig } from 'mock-config-server';
2
+
3
+ export const getUsersRequest: RestRequestConfig = {
4
+ path: '/users',
5
+ method: 'get',
6
+ routes: [
7
+ {
8
+ data: [
9
+ { id: 1, emoji: '🎉' },
10
+ { id: 2, emoji: '🔥' }
11
+ ]
12
+ }
13
+ ]
14
+ };
@@ -1,2 +1,2 @@
1
- export * from './user';
2
- export * from './users';
1
+ export * from './user';
2
+ export * from './users';
@@ -1,37 +1,37 @@
1
- import type { GraphQLRequestConfig } from 'mock-config-server';
2
-
3
- export const getUserQuery: GraphQLRequestConfig = {
4
- operationName: 'getUser',
5
- operationType: 'query',
6
- routes: [
7
- {
8
- data: { id: 1, emoji: '🎉' }
9
- },
10
- {
11
- data: { id: 2, emoji: '🔥' },
12
- entities: {
13
- variables: {
14
- id: 2
15
- }
16
- }
17
- }
18
- ]
19
- };
20
-
21
- export const createUserMutation: GraphQLRequestConfig = {
22
- operationName: 'createUser',
23
- operationType: 'mutation',
24
- routes: [
25
- {
26
- data: { id: 1, emoji: '🎉' }
27
- },
28
- {
29
- data: { id: 2, emoji: '🔥' },
30
- entities: {
31
- variables: {
32
- emoji: '🔥'
33
- }
34
- }
35
- }
36
- ]
37
- };
1
+ import type { GraphQLRequestConfig } from 'mock-config-server';
2
+
3
+ export const getUserQuery: GraphQLRequestConfig = {
4
+ operationName: 'getUser',
5
+ operationType: 'query',
6
+ routes: [
7
+ {
8
+ data: { id: 1, emoji: '🎉' }
9
+ },
10
+ {
11
+ data: { id: 2, emoji: '🔥' },
12
+ entities: {
13
+ variables: {
14
+ id: 2
15
+ }
16
+ }
17
+ }
18
+ ]
19
+ };
20
+
21
+ export const createUserMutation: GraphQLRequestConfig = {
22
+ operationName: 'createUser',
23
+ operationType: 'mutation',
24
+ routes: [
25
+ {
26
+ data: { id: 1, emoji: '🎉' }
27
+ },
28
+ {
29
+ data: { id: 2, emoji: '🔥' },
30
+ entities: {
31
+ variables: {
32
+ emoji: '🔥'
33
+ }
34
+ }
35
+ }
36
+ ]
37
+ };
@@ -1,14 +1,14 @@
1
- import type { GraphQLRequestConfig } from 'mock-config-server';
2
-
3
- export const getUsersQuery: GraphQLRequestConfig = {
4
- operationName: 'getUsers',
5
- operationType: 'query',
6
- routes: [
7
- {
8
- data: [
9
- { id: 1, emoji: '🎉' },
10
- { id: 2, emoji: '🔥' }
11
- ]
12
- }
13
- ]
14
- };
1
+ import type { GraphQLRequestConfig } from 'mock-config-server';
2
+
3
+ export const getUsersQuery: GraphQLRequestConfig = {
4
+ operationName: 'getUsers',
5
+ operationType: 'query',
6
+ routes: [
7
+ {
8
+ data: [
9
+ { id: 1, emoji: '🎉' },
10
+ { id: 2, emoji: '🔥' }
11
+ ]
12
+ }
13
+ ]
14
+ };
@@ -1,2 +1,2 @@
1
- export * from './user';
2
- export * from './users';
1
+ export * from './user';
2
+ export * from './users';
@@ -1,37 +1,37 @@
1
- import type { RestRequestConfig } from 'mock-config-server';
2
-
3
- export const getUserRequest: RestRequestConfig = {
4
- method: 'get',
5
- path: '/users/:id',
6
- routes: [
7
- {
8
- data: { id: 1, emoji: '🎉' }
9
- },
10
- {
11
- data: { id: 2, emoji: '🔥' },
12
- entities: {
13
- params: {
14
- id: 2
15
- }
16
- }
17
- }
18
- ]
19
- };
20
-
21
- export const postUserRequest: RestRequestConfig = {
22
- method: 'post',
23
- path: '/users',
24
- routes: [
25
- {
26
- data: { id: 1, emoji: '🎉' }
27
- },
28
- {
29
- data: { id: 2, emoji: '🔥' },
30
- entities: {
31
- body: {
32
- emoji: '🔥'
33
- }
34
- }
35
- }
36
- ]
37
- };
1
+ import type { RestRequestConfig } from 'mock-config-server';
2
+
3
+ export const getUserRequest: RestRequestConfig = {
4
+ method: 'get',
5
+ path: '/users/:id',
6
+ routes: [
7
+ {
8
+ data: { id: 1, emoji: '🎉' }
9
+ },
10
+ {
11
+ data: { id: 2, emoji: '🔥' },
12
+ entities: {
13
+ params: {
14
+ id: 2
15
+ }
16
+ }
17
+ }
18
+ ]
19
+ };
20
+
21
+ export const postUserRequest: RestRequestConfig = {
22
+ method: 'post',
23
+ path: '/users',
24
+ routes: [
25
+ {
26
+ data: { id: 1, emoji: '🎉' }
27
+ },
28
+ {
29
+ data: { id: 2, emoji: '🔥' },
30
+ entities: {
31
+ body: {
32
+ emoji: '🔥'
33
+ }
34
+ }
35
+ }
36
+ ]
37
+ };
@@ -1,14 +1,14 @@
1
- import type { RestRequestConfig } from 'mock-config-server';
2
-
3
- export const getUsersRequest: RestRequestConfig = {
4
- path: '/users',
5
- method: 'get',
6
- routes: [
7
- {
8
- data: [
9
- { id: 1, emoji: '🎉' },
10
- { id: 2, emoji: '🔥' }
11
- ]
12
- }
13
- ]
14
- };
1
+ import type { RestRequestConfig } from 'mock-config-server';
2
+
3
+ export const getUsersRequest: RestRequestConfig = {
4
+ path: '/users',
5
+ method: 'get',
6
+ routes: [
7
+ {
8
+ data: [
9
+ { id: 1, emoji: '🎉' },
10
+ { id: 2, emoji: '🔥' }
11
+ ]
12
+ }
13
+ ]
14
+ };
@@ -90,14 +90,14 @@ export declare const graphqlConfigSchema: z.ZodObject<{
90
90
  interceptors?: any;
91
91
  entities?: any;
92
92
  })[];
93
- operationName: string | RegExp;
94
93
  operationType: "query" | "mutation";
94
+ operationName: string | RegExp;
95
95
  query?: string | undefined;
96
96
  interceptors?: any;
97
97
  }, {
98
98
  routes: unknown[];
99
- operationName: string | RegExp;
100
99
  operationType: "query" | "mutation";
100
+ operationName: string | RegExp;
101
101
  query?: string | undefined;
102
102
  interceptors?: unknown;
103
103
  }>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
@@ -191,14 +191,14 @@ export declare const graphqlConfigSchema: z.ZodObject<{
191
191
  entities?: any;
192
192
  })[];
193
193
  operationType: "query" | "mutation";
194
- interceptors?: any;
195
194
  operationName?: string | RegExp | undefined;
195
+ interceptors?: any;
196
196
  }, {
197
197
  query: string;
198
198
  routes: unknown[];
199
199
  operationType: "query" | "mutation";
200
- interceptors?: unknown;
201
200
  operationName?: string | RegExp | undefined;
201
+ interceptors?: unknown;
202
202
  }>>]>, "many">;
203
203
  interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
204
204
  }, "strict", z.ZodTypeAny, {
@@ -221,8 +221,8 @@ export declare const graphqlConfigSchema: z.ZodObject<{
221
221
  interceptors?: any;
222
222
  entities?: any;
223
223
  })[];
224
- operationName: string | RegExp;
225
224
  operationType: "query" | "mutation";
225
+ operationName: string | RegExp;
226
226
  query?: string | undefined;
227
227
  interceptors?: any;
228
228
  } | {
@@ -246,8 +246,8 @@ export declare const graphqlConfigSchema: z.ZodObject<{
246
246
  entities?: any;
247
247
  })[];
248
248
  operationType: "query" | "mutation";
249
- interceptors?: any;
250
249
  operationName?: string | RegExp | undefined;
250
+ interceptors?: any;
251
251
  })[];
252
252
  interceptors?: any;
253
253
  baseUrl?: string | undefined;
@@ -110,13 +110,13 @@ export declare const restConfigSchema: z.ZodObject<{
110
110
  interceptors?: any;
111
111
  entities?: any;
112
112
  })[];
113
- path: string | RegExp;
114
113
  method: RestMethod;
114
+ path: string | RegExp;
115
115
  interceptors?: any;
116
116
  }, {
117
117
  routes: unknown[];
118
- path: string | RegExp;
119
118
  method: RestMethod;
119
+ path: string | RegExp;
120
120
  interceptors?: unknown;
121
121
  }>, z.ZodObject<{
122
122
  path: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>;
@@ -226,13 +226,13 @@ export declare const restConfigSchema: z.ZodObject<{
226
226
  interceptors?: any;
227
227
  entities?: any;
228
228
  })[];
229
- path: string | RegExp;
230
229
  method: RestMethod;
230
+ path: string | RegExp;
231
231
  interceptors?: any;
232
232
  }, {
233
233
  routes: unknown[];
234
- path: string | RegExp;
235
234
  method: RestMethod;
235
+ path: string | RegExp;
236
236
  interceptors?: unknown;
237
237
  }>, z.ZodObject<{
238
238
  path: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>;
@@ -342,13 +342,13 @@ export declare const restConfigSchema: z.ZodObject<{
342
342
  interceptors?: any;
343
343
  entities?: any;
344
344
  })[];
345
- path: string | RegExp;
346
345
  method: RestMethod;
346
+ path: string | RegExp;
347
347
  interceptors?: any;
348
348
  }, {
349
349
  routes: unknown[];
350
- path: string | RegExp;
351
350
  method: RestMethod;
351
+ path: string | RegExp;
352
352
  interceptors?: unknown;
353
353
  }>, z.ZodObject<{
354
354
  path: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>;
@@ -458,13 +458,13 @@ export declare const restConfigSchema: z.ZodObject<{
458
458
  interceptors?: any;
459
459
  entities?: any;
460
460
  })[];
461
- path: string | RegExp;
462
461
  method: RestMethod;
462
+ path: string | RegExp;
463
463
  interceptors?: any;
464
464
  }, {
465
465
  routes: unknown[];
466
- path: string | RegExp;
467
466
  method: RestMethod;
467
+ path: string | RegExp;
468
468
  interceptors?: unknown;
469
469
  }>, z.ZodObject<{
470
470
  path: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>;
@@ -574,13 +574,13 @@ export declare const restConfigSchema: z.ZodObject<{
574
574
  interceptors?: any;
575
575
  entities?: any;
576
576
  })[];
577
- path: string | RegExp;
578
577
  method: RestMethod;
578
+ path: string | RegExp;
579
579
  interceptors?: any;
580
580
  }, {
581
581
  routes: unknown[];
582
- path: string | RegExp;
583
582
  method: RestMethod;
583
+ path: string | RegExp;
584
584
  interceptors?: unknown;
585
585
  }>, z.ZodObject<{
586
586
  path: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>;
@@ -690,13 +690,13 @@ export declare const restConfigSchema: z.ZodObject<{
690
690
  interceptors?: any;
691
691
  entities?: any;
692
692
  })[];
693
- path: string | RegExp;
694
693
  method: RestMethod;
694
+ path: string | RegExp;
695
695
  interceptors?: any;
696
696
  }, {
697
697
  routes: unknown[];
698
- path: string | RegExp;
699
698
  method: RestMethod;
699
+ path: string | RegExp;
700
700
  interceptors?: unknown;
701
701
  }>]>, "many">;
702
702
  interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
@@ -725,8 +725,8 @@ export declare const restConfigSchema: z.ZodObject<{
725
725
  interceptors?: any;
726
726
  entities?: any;
727
727
  })[];
728
- path: string | RegExp;
729
728
  method: RestMethod;
729
+ path: string | RegExp;
730
730
  interceptors?: any;
731
731
  }[];
732
732
  interceptors?: any;
@@ -734,8 +734,8 @@ export declare const restConfigSchema: z.ZodObject<{
734
734
  }, {
735
735
  configs: {
736
736
  routes: unknown[];
737
- path: string | RegExp;
738
737
  method: RestMethod;
738
+ path: string | RegExp;
739
739
  interceptors?: unknown;
740
740
  }[];
741
741
  interceptors?: unknown;
@@ -3,7 +3,7 @@ import type { GraphqlConfig, Interceptors } from '../../../utils/types';
3
3
  interface CreateGraphQLRoutesParams {
4
4
  router: IRouter;
5
5
  graphqlConfig: GraphqlConfig;
6
- serverResponseInterceptor?: Interceptors['response'];
6
+ serverResponseInterceptor?: Interceptors<'graphql'>['response'];
7
7
  }
8
8
  export declare const createGraphQLRoutes: ({ router, graphqlConfig, serverResponseInterceptor }: CreateGraphQLRoutesParams) => IRouter;
9
9
  export {};
@@ -70,9 +70,7 @@ const createGraphQLRoutes = ({ router, graphqlConfig, serverResponseInterceptor
70
70
  });
71
71
  });
72
72
  });
73
- if (!matchedRouteConfig) {
74
- return next();
75
- }
73
+ if (!matchedRouteConfig) return next();
76
74
  if ((_matchedRouteConfig_interceptors = matchedRouteConfig.interceptors) === null || _matchedRouteConfig_interceptors === void 0 ? void 0 : _matchedRouteConfig_interceptors.request) {
77
75
  await (0, _helpers.callRequestInterceptor)({
78
76
  request,
@@ -0,0 +1,17 @@
1
+ import type { Express } from 'express';
2
+ import type { GraphQLEntity, GraphQLOperationName, GraphQLOperationType } from '../../../utils/types';
3
+ declare global {
4
+ namespace Express {
5
+ interface Request {
6
+ id: number;
7
+ timestamp: number;
8
+ graphQL: {
9
+ operationType: GraphQLOperationType;
10
+ operationName?: GraphQLOperationName;
11
+ query: string;
12
+ variables?: GraphQLEntity<'variables'>;
13
+ } | null;
14
+ }
15
+ }
16
+ }
17
+ export declare const contextMiddleware: (server: Express) => void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "contextMiddleware", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return contextMiddleware;
9
+ }
10
+ });
11
+ const _helpers = require("../../../utils/helpers");
12
+ const contextMiddleware = (server)=>{
13
+ let requestId = 0;
14
+ server.use((request, _response, next)=>{
15
+ requestId += 1;
16
+ request.id = requestId;
17
+ request.timestamp = Date.now();
18
+ const graphQLInput = (0, _helpers.getGraphQLInput)(request);
19
+ var _graphQLInput_query;
20
+ const graphQLQuery = (0, _helpers.parseQuery)((_graphQLInput_query = graphQLInput.query) !== null && _graphQLInput_query !== void 0 ? _graphQLInput_query : '');
21
+ if (graphQLInput.query && graphQLQuery) {
22
+ request.graphQL = {
23
+ operationType: graphQLQuery.operationType,
24
+ operationName: graphQLQuery.operationName,
25
+ query: graphQLInput.query,
26
+ variables: graphQLInput.variables
27
+ };
28
+ return next();
29
+ }
30
+ request.graphQL = null;
31
+ return next();
32
+ });
33
+ };
@@ -1,3 +1,2 @@
1
- type Cookies = Record<string, string>;
1
+ import type { Cookies } from '../../../../../utils/types';
2
2
  export declare const parseCookie: (cookieHeader: string) => Cookies;
3
- export {};
@@ -1,3 +1,4 @@
1
+ export * from './contextMiddleware/contextMiddleware';
1
2
  export * from './cookieParseMiddleware/cookieParseMiddleware';
2
3
  export * from './corsMiddleware/corsMiddleware';
3
4
  export * from './destroyerMiddleware/destroyerMiddleware';
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ _export_star(require("./contextMiddleware/contextMiddleware"), exports);
5
6
  _export_star(require("./cookieParseMiddleware/cookieParseMiddleware"), exports);
6
7
  _export_star(require("./corsMiddleware/corsMiddleware"), exports);
7
8
  _export_star(require("./destroyerMiddleware/destroyerMiddleware"), exports);
@@ -45,15 +45,16 @@ const notFoundMiddleware = (server, mockServerConfig)=>{
45
45
  requestConfigs: graphqlRequestConfigs
46
46
  });
47
47
  }
48
+ response.status(404);
48
49
  const isRequestSupportHtml = ((_request_headers_accept = request.headers.accept) === null || _request_headers_accept === void 0 ? void 0 : _request_headers_accept.includes('text/html')) || ((_request_headers_accept1 = request.headers.accept) === null || _request_headers_accept1 === void 0 ? void 0 : _request_headers_accept1.includes('*/*'));
49
50
  if (isRequestSupportHtml) {
50
- response.status(404).render('pages/404', {
51
+ response.render('pages/404', {
51
52
  restRequestSuggestions,
52
53
  graphqlRequestSuggestions
53
54
  });
54
55
  return;
55
56
  }
56
- response.status(404).json({
57
+ response.json({
57
58
  message: 'Request or page not found. Similar requests in data',
58
59
  data: {
59
60
  restRequestSuggestions,
@@ -3,7 +3,7 @@ import type { Interceptors, RestConfig } from '../../../utils/types';
3
3
  interface CreateRestRoutesParams {
4
4
  router: IRouter;
5
5
  restConfig: RestConfig;
6
- serverResponseInterceptor?: Interceptors['response'];
6
+ serverResponseInterceptor?: Interceptors<'rest'>['response'];
7
7
  }
8
8
  export declare const createRestRoutes: ({ router, restConfig, serverResponseInterceptor }: CreateRestRoutesParams) => IRouter;
9
9
  export {};
@@ -55,9 +55,7 @@ const createRestRoutes = ({ router, restConfig, serverResponseInterceptor })=>{
55
55
  });
56
56
  });
57
57
  });
58
- if (!matchedRouteConfig) {
59
- return next();
60
- }
58
+ if (!matchedRouteConfig) return next();
61
59
  if ((_matchedRouteConfig_interceptors = matchedRouteConfig.interceptors) === null || _matchedRouteConfig_interceptors === void 0 ? void 0 : _matchedRouteConfig_interceptors.request) {
62
60
  await (0, _helpers.callRequestInterceptor)({
63
61
  request,
@@ -34,7 +34,31 @@ const calculateRouteConfigWeight = (restRouteConfig)=>{
34
34
  return routeConfigWeight;
35
35
  };
36
36
  const prepareRestRequestConfigs = (requestConfigs)=>{
37
- requestConfigs.forEach((requestConfig)=>{
37
+ const sortedByPathRequestConfigs = requestConfigs.sort(({ path: firstPath }, { path: secondPath })=>{
38
+ // ✅ important:
39
+ // do not compare RegExp paths and non-parameterized paths
40
+ if (firstPath instanceof RegExp || secondPath instanceof RegExp) return 0;
41
+ if (!firstPath.includes('/:') && !secondPath.includes('/:')) return 0;
42
+ const firstPathParts = firstPath.split('/');
43
+ const secondPathParts = secondPath.split('/');
44
+ const minimalPathPartsLength = Math.min(firstPathParts.length, secondPathParts.length);
45
+ // ✅ important:
46
+ // need to find the leftmost parameter/non-parameter pair and give priority to non-parameter one
47
+ for(let i = 0; i < minimalPathPartsLength; i += 1){
48
+ const firstPathPart = firstPathParts[i];
49
+ const secondPathPart = secondPathParts[i];
50
+ const isFirstPathPartParameter = firstPathPart.startsWith(':');
51
+ const isSecondPathPartParameter = secondPathPart.startsWith(':');
52
+ if (!isFirstPathPartParameter && !isSecondPathPartParameter) {
53
+ if (firstPathPart === secondPathPart) continue;
54
+ return 0;
55
+ }
56
+ if (isFirstPathPartParameter && isSecondPathPartParameter) continue;
57
+ return +isFirstPathPartParameter - +isSecondPathPartParameter;
58
+ }
59
+ return 0;
60
+ });
61
+ sortedByPathRequestConfigs.forEach((requestConfig)=>{
38
62
  requestConfig.routes.sort((first, second)=>// ✅ important:
39
63
  // Lift more specific configs for correct working of routes
40
64
  calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
@@ -32,6 +32,7 @@ const createDatabaseMockServer = (databaseMockServerConfig, server = (0, _expres
32
32
  }));
33
33
  server.set('json spaces', 2);
34
34
  server.use(_bodyparser.default.text());
35
+ (0, _middlewares.contextMiddleware)(server);
35
36
  (0, _middlewares.cookieParseMiddleware)(server);
36
37
  const serverRequestInterceptor = (_databaseMockServerConfig_interceptors = databaseMockServerConfig.interceptors) === null || _databaseMockServerConfig_interceptors === void 0 ? void 0 : _databaseMockServerConfig_interceptors.request;
37
38
  if (serverRequestInterceptor) {
@@ -33,6 +33,7 @@ const createGraphQLMockServer = (graphqlMockServerConfig, server = (0, _express.
33
33
  }));
34
34
  server.set('json spaces', 2);
35
35
  server.use(_bodyparser.default.text());
36
+ (0, _middlewares.contextMiddleware)(server);
36
37
  (0, _middlewares.cookieParseMiddleware)(server);
37
38
  const serverRequestInterceptor = (_graphqlMockServerConfig_interceptors = graphqlMockServerConfig.interceptors) === null || _graphqlMockServerConfig_interceptors === void 0 ? void 0 : _graphqlMockServerConfig_interceptors.request;
38
39
  if (serverRequestInterceptor) {
@@ -34,6 +34,7 @@ const createMockServer = (mockServerConfig, server = (0, _express.default)())=>{
34
34
  }));
35
35
  server.set('json spaces', 2);
36
36
  server.use(_bodyparser.default.text());
37
+ (0, _middlewares.contextMiddleware)(server);
37
38
  (0, _middlewares.cookieParseMiddleware)(server);
38
39
  const serverRequestInterceptor = (_mockServerConfig_interceptors = mockServerConfig.interceptors) === null || _mockServerConfig_interceptors === void 0 ? void 0 : _mockServerConfig_interceptors.request;
39
40
  if (serverRequestInterceptor) {
@@ -33,6 +33,7 @@ const createRestMockServer = (restMockServerConfig, server = (0, _express.defaul
33
33
  }));
34
34
  server.set('json spaces', 2);
35
35
  server.use(_bodyparser.default.text());
36
+ (0, _middlewares.contextMiddleware)(server);
36
37
  (0, _middlewares.cookieParseMiddleware)(server);
37
38
  const serverRequestInterceptor = (_restMockServerConfig_interceptors = restMockServerConfig.interceptors) === null || _restMockServerConfig_interceptors === void 0 ? void 0 : _restMockServerConfig_interceptors.request;
38
39
  if (serverRequestInterceptor) {
@@ -22,7 +22,7 @@ const startDatabaseMockServer = (databaseMockServerConfig)=>{
22
22
  var _databaseMockServerConfig_port;
23
23
  const port = (_databaseMockServerConfig_port = databaseMockServerConfig.port) !== null && _databaseMockServerConfig_port !== void 0 ? _databaseMockServerConfig_port : _constants.DEFAULT.PORT;
24
24
  const server = mockServer.listen(port, ()=>{
25
- console.log(_ansicolors.default.green(`🎉 Database Mock Server is running at http://localhost:${port}`));
25
+ console.info(_ansicolors.default.green(`🎉 Database Mock Server is running at http://localhost:${port}`));
26
26
  });
27
27
  // ✅ important: add destroy method for closing keep-alive connections after server shutdown
28
28
  return (0, _middlewares.destroyerMiddleware)(server);
@@ -22,7 +22,7 @@ const startGraphQLMockServer = (graphQLMockServerConfig)=>{
22
22
  var _graphQLMockServerConfig_port;
23
23
  const port = (_graphQLMockServerConfig_port = graphQLMockServerConfig.port) !== null && _graphQLMockServerConfig_port !== void 0 ? _graphQLMockServerConfig_port : _constants.DEFAULT.PORT;
24
24
  const server = mockServer.listen(port, ()=>{
25
- console.log(_ansicolors.default.green(`🎉 GraphQL Mock Server is running at http://localhost:${port}`));
25
+ console.info(_ansicolors.default.green(`🎉 GraphQL Mock Server is running at http://localhost:${port}`));
26
26
  });
27
27
  // ✅ important: add destroy method for closing keep-alive connections after server shutdown
28
28
  return (0, _middlewares.destroyerMiddleware)(server);
@@ -22,7 +22,7 @@ const startMockServer = (mockServerConfig)=>{
22
22
  var _mockServerConfig_port;
23
23
  const port = (_mockServerConfig_port = mockServerConfig.port) !== null && _mockServerConfig_port !== void 0 ? _mockServerConfig_port : _constants.DEFAULT.PORT;
24
24
  const server = mockServer.listen(port, ()=>{
25
- console.log(_ansicolors.default.green(`🎉 Mock Server is running at http://localhost:${port}`));
25
+ console.info(_ansicolors.default.green(`🎉 Mock Server is running at http://localhost:${port}`));
26
26
  });
27
27
  // ✅ important: add destroy method for closing keep-alive connections after server shutdown
28
28
  return (0, _middlewares.destroyerMiddleware)(server);