mock-config-server 2.0.1 → 2.1.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 (141) hide show
  1. package/README.md +33 -1
  2. package/dist/bin/{mock-config-server.d.ts → bin.d.ts} +2 -2
  3. package/dist/bin/bin.js +8 -0
  4. package/dist/bin/cli.d.ts +1 -0
  5. package/dist/bin/cli.js +36 -0
  6. package/dist/bin/{resolveExportsFromSourceCode.d.ts → resolveExportsFromSourceCode/resolveExportsFromSourceCode.d.ts} +1 -1
  7. package/dist/bin/{resolveExportsFromSourceCode.js → resolveExportsFromSourceCode/resolveExportsFromSourceCode.js} +11 -11
  8. package/dist/bin/start.d.ts +3 -0
  9. package/dist/bin/{mock-config-server.js → start.js} +73 -67
  10. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -1
  11. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -12
  12. package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -1
  13. package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +82 -82
  14. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +1 -1
  15. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +48 -48
  16. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -2
  17. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +71 -71
  18. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -1
  19. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +21 -21
  20. package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +2 -1
  21. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +30 -34
  22. package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -1
  23. package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -9
  24. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -1
  25. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -52
  26. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -2
  27. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +105 -104
  28. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -1
  29. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +44 -44
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +17 -17
  32. package/dist/src/{graphql → core/graphql}/createGraphQLRoutes/createGraphQLRoutes.d.ts +3 -3
  33. package/dist/src/{graphql → core/graphql}/createGraphQLRoutes/createGraphQLRoutes.js +76 -73
  34. package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.d.ts +1 -0
  35. package/dist/src/{notFound/urlSuggestions → core/graphql/createGraphQLRoutes/helpers}/index.js +17 -18
  36. package/dist/src/{graphql → core/graphql/createGraphQLRoutes/helpers}/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -2
  37. package/dist/src/{graphql → core/graphql/createGraphQLRoutes/helpers}/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +28 -28
  38. package/dist/src/core/graphql/index.d.ts +1 -0
  39. package/dist/src/{notFound/urlSuggestions/getGraphqlUrlSuggestions → core/graphql}/index.js +17 -17
  40. package/dist/src/{cors → core/middlewares}/corsMiddleware/corsMiddleware.d.ts +3 -3
  41. package/dist/src/{cors → core/middlewares}/corsMiddleware/corsMiddleware.js +44 -44
  42. package/dist/src/{cors/getOrigins → core/middlewares/corsMiddleware/helpers/getAllowedOrigins}/getAllowedOrigins.d.ts +2 -2
  43. package/dist/src/{cors/getOrigins → core/middlewares/corsMiddleware/helpers/getAllowedOrigins}/getAllowedOrigins.js +13 -13
  44. package/dist/src/core/middlewares/corsMiddleware/helpers/index.d.ts +1 -0
  45. package/dist/src/{notFound/urlSuggestions/getRestUrlSuggestions → core/middlewares/corsMiddleware/helpers}/index.js +17 -17
  46. package/dist/src/core/middlewares/index.d.ts +4 -0
  47. package/dist/src/core/middlewares/index.js +20 -0
  48. package/dist/src/{cors → core/middlewares}/noCorsMiddleware/noCorsMiddleware.d.ts +2 -2
  49. package/dist/src/{cors → core/middlewares}/noCorsMiddleware/noCorsMiddleware.js +24 -20
  50. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +6 -6
  51. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +18 -18
  52. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -1
  53. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getLevenshteinDistance/getLevenshteinDistance.js +80 -80
  54. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +6 -6
  55. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -34
  56. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +1 -1
  57. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +7 -7
  58. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +1 -1
  59. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +5 -5
  60. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/index.d.ts +2 -2
  61. package/dist/src/{notFound/urlSuggestions → core/middlewares/notFoundMiddleware/helpers}/getRestUrlSuggestions/helpers/index.js +18 -18
  62. package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.d.ts +3 -0
  63. package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +19 -0
  64. package/dist/src/{notFound → core/middlewares/notFoundMiddleware}/notFoundMiddleware.d.ts +8 -8
  65. package/dist/src/{notFound → core/middlewares/notFoundMiddleware}/notFoundMiddleware.js +47 -47
  66. package/dist/src/{static → core/middlewares}/staticMiddleware/staticMiddleware.d.ts +3 -3
  67. package/dist/src/{static → core/middlewares}/staticMiddleware/staticMiddleware.js +30 -30
  68. package/dist/src/{rest → core/rest}/createRestRoutes/createRestRoutes.d.ts +3 -3
  69. package/dist/src/{rest → core/rest}/createRestRoutes/createRestRoutes.js +46 -41
  70. package/dist/src/core/rest/createRestRoutes/helpers/index.d.ts +1 -0
  71. package/dist/src/core/rest/createRestRoutes/helpers/index.js +17 -0
  72. package/dist/src/{rest → core/rest/createRestRoutes/helpers}/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -2
  73. package/dist/src/{rest → core/rest/createRestRoutes/helpers}/prepareRestRequestConfigs/prepareRestRequestConfigs.js +30 -30
  74. package/dist/src/core/rest/index.d.ts +1 -0
  75. package/dist/src/core/rest/index.js +17 -0
  76. package/dist/src/index.d.ts +3 -3
  77. package/dist/src/index.js +19 -19
  78. package/dist/src/server/createMockServer/createMockServer.d.ts +3 -3
  79. package/dist/src/server/createMockServer/createMockServer.js +46 -49
  80. package/dist/src/server/index.d.ts +2 -0
  81. package/dist/src/server/index.js +18 -0
  82. package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
  83. package/dist/src/server/startMockServer/startMockServer.js +17 -17
  84. package/dist/src/static/views/notFound.ejs +1 -1
  85. package/dist/src/utils/constants/appPath.d.ts +1 -1
  86. package/dist/src/utils/constants/appPath.js +4 -4
  87. package/dist/src/utils/constants/default.d.ts +11 -11
  88. package/dist/src/utils/constants/default.js +14 -14
  89. package/dist/src/utils/constants/index.d.ts +2 -2
  90. package/dist/src/utils/constants/index.js +18 -18
  91. package/dist/src/utils/helpers/config/index.d.ts +1 -0
  92. package/dist/src/utils/helpers/config/index.js +17 -0
  93. package/dist/src/{configs → utils/helpers/config}/isEntitiesEqual/isEntityValuesEqual.d.ts +1 -1
  94. package/dist/src/{configs → utils/helpers/config}/isEntitiesEqual/isEntityValuesEqual.js +29 -29
  95. package/dist/src/{graphql → utils/helpers/graphql}/getGraphQLInput/getGraphQLInput.d.ts +3 -3
  96. package/dist/src/{graphql → utils/helpers/graphql}/getGraphQLInput/getGraphQLInput.js +21 -21
  97. package/dist/src/utils/helpers/graphql/index.d.ts +3 -0
  98. package/dist/src/utils/helpers/graphql/index.js +19 -0
  99. package/dist/src/{graphql → utils/helpers/graphql}/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -3
  100. package/dist/src/{graphql → utils/helpers/graphql}/parseGraphQLRequest/parseGraphQLRequest.js +12 -12
  101. package/dist/src/{graphql → utils/helpers/graphql}/parseQuery/parseQuery.d.ts +7 -7
  102. package/dist/src/{graphql → utils/helpers/graphql}/parseQuery/parseQuery.js +21 -21
  103. package/dist/src/utils/helpers/index.d.ts +6 -3
  104. package/dist/src/utils/helpers/index.js +22 -19
  105. package/dist/src/{routes → utils/helpers/interceptors}/callRequestInterceptors/callRequestInterceptors.d.ts +12 -12
  106. package/dist/src/{routes → utils/helpers/interceptors}/callRequestInterceptors/callRequestInterceptors.js +13 -13
  107. package/dist/src/{routes → utils/helpers/interceptors}/callResponseInterceptors/callResponseInterceptors.d.ts +14 -14
  108. package/dist/src/{routes → utils/helpers/interceptors}/callResponseInterceptors/callResponseInterceptors.js +55 -31
  109. package/dist/src/utils/helpers/interceptors/index.d.ts +2 -0
  110. package/dist/src/utils/helpers/interceptors/index.js +18 -0
  111. package/dist/src/utils/helpers/{isPlainObject.d.ts → isPlainObject/isPlainObject.d.ts} +1 -1
  112. package/dist/src/utils/helpers/{isPlainObject.js → isPlainObject/isPlainObject.js} +5 -5
  113. package/dist/src/utils/helpers/sleep.d.ts +1 -1
  114. package/dist/src/utils/helpers/sleep.js +7 -7
  115. package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.d.ts +1 -1
  116. package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -8
  117. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +1 -1
  118. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +6 -6
  119. package/dist/src/utils/helpers/url/index.d.ts +4 -4
  120. package/dist/src/utils/helpers/url/index.js +20 -20
  121. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -1
  122. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +5 -5
  123. package/dist/src/utils/helpers/url/urlJoin/urlJoin.d.ts +1 -1
  124. package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +14 -14
  125. package/dist/src/utils/types/graphql.d.ts +34 -5
  126. package/dist/src/utils/types/graphql.js +2 -2
  127. package/dist/src/utils/types/index.d.ts +5 -4
  128. package/dist/src/utils/types/index.js +21 -20
  129. package/dist/src/utils/types/interceptors.d.ts +21 -15
  130. package/dist/src/utils/types/interceptors.js +2 -2
  131. package/dist/src/utils/types/rest.d.ts +38 -0
  132. package/dist/src/utils/types/{configs.js → rest.js} +2 -2
  133. package/dist/src/utils/types/server.d.ts +37 -32
  134. package/dist/src/utils/types/server.js +2 -2
  135. package/dist/src/utils/types/values.d.ts +9 -0
  136. package/dist/src/utils/types/values.js +2 -0
  137. package/package.json +19 -17
  138. package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.d.ts +0 -1
  139. package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.d.ts +0 -1
  140. package/dist/src/notFound/urlSuggestions/index.d.ts +0 -2
  141. package/dist/src/utils/types/configs.d.ts +0 -63
@@ -1,71 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRoutes = void 0;
4
- const helpers_1 = require("../../../../src/utils/helpers");
5
- const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
6
- const ALLOWED_ENTITIES_BY_OPERATION_TYPE = {
7
- query: ['headers', 'query', 'variables'],
8
- mutation: ['headers', 'query', 'variables']
9
- };
10
- const validateHeadersOrQuery = (headersOrQuery, entity) => {
11
- const isHeadersOrQueryObject = (0, helpers_1.isPlainObject)(headersOrQuery);
12
- if (isHeadersOrQueryObject) {
13
- Object.entries(headersOrQuery).forEach(([headerOrQueryKey, headerOrQueryValue]) => {
14
- if (typeof headerOrQueryValue !== 'string') {
15
- throw new Error(`${entity}.${headerOrQueryKey}`);
16
- }
17
- });
18
- return;
19
- }
20
- throw new Error(entity);
21
- };
22
- const validateEntities = (entities, operationType) => {
23
- const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
24
- if (isEntitiesObject) {
25
- Object.keys(entities).forEach((entity) => {
26
- const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entity);
27
- if (!isEntityAllowed) {
28
- throw new Error(`entities.${entity}`);
29
- }
30
- if (entity === 'headers' || entity === 'query') {
31
- try {
32
- const headersOrQuery = entities[entity];
33
- return validateHeadersOrQuery(headersOrQuery, entity);
34
- }
35
- catch (error) {
36
- throw new Error(`entities.${error.message}`);
37
- }
38
- }
39
- });
40
- return;
41
- }
42
- if (typeof entities !== 'undefined') {
43
- throw new Error('entities');
44
- }
45
- };
46
- const validateRoutes = (routes, operationType) => {
47
- const isRoutesArray = Array.isArray(routes);
48
- if (isRoutesArray) {
49
- routes.forEach((route, index) => {
50
- const isRouteObject = (0, helpers_1.isPlainObject)(route);
51
- if (isRouteObject) {
52
- const isRouteHasDataProperty = 'data' in route;
53
- if (!isRouteHasDataProperty) {
54
- throw new Error(`routes[${index}]`);
55
- }
56
- try {
57
- validateEntities(route.entities, operationType);
58
- (0, validateInterceptors_1.validateInterceptors)(route.interceptors);
59
- }
60
- catch (error) {
61
- throw new Error(`routes[${index}].${error.message}`);
62
- }
63
- return;
64
- }
65
- throw new Error(`routes[${index}]`);
66
- });
67
- return;
68
- }
69
- throw new Error('routes');
70
- };
71
- exports.validateRoutes = validateRoutes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRoutes = void 0;
4
+ const helpers_1 = require("../../../../src/utils/helpers");
5
+ const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
6
+ const ALLOWED_ENTITIES_BY_OPERATION_TYPE = {
7
+ query: ['headers', 'query', 'variables'],
8
+ mutation: ['headers', 'query', 'variables']
9
+ };
10
+ const validateHeadersOrQuery = (headersOrQuery, entity) => {
11
+ const isHeadersOrQueryObject = (0, helpers_1.isPlainObject)(headersOrQuery);
12
+ if (isHeadersOrQueryObject) {
13
+ Object.entries(headersOrQuery).forEach(([headerOrQueryKey, headerOrQueryValue]) => {
14
+ if (typeof headerOrQueryValue !== 'string') {
15
+ throw new Error(`${entity}.${headerOrQueryKey}`);
16
+ }
17
+ });
18
+ return;
19
+ }
20
+ throw new Error(entity);
21
+ };
22
+ const validateEntities = (entities, operationType) => {
23
+ const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
24
+ if (isEntitiesObject) {
25
+ Object.keys(entities).forEach((entity) => {
26
+ const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entity);
27
+ if (!isEntityAllowed) {
28
+ throw new Error(`entities.${entity}`);
29
+ }
30
+ if (entity === 'headers' || entity === 'query') {
31
+ try {
32
+ const headersOrQuery = entities[entity];
33
+ validateHeadersOrQuery(headersOrQuery, entity);
34
+ }
35
+ catch (error) {
36
+ throw new Error(`entities.${error.message}`);
37
+ }
38
+ }
39
+ });
40
+ return;
41
+ }
42
+ if (typeof entities !== 'undefined') {
43
+ throw new Error('entities');
44
+ }
45
+ };
46
+ const validateRoutes = (routes, operationType) => {
47
+ const isRoutesArray = Array.isArray(routes);
48
+ if (isRoutesArray) {
49
+ routes.forEach((route, index) => {
50
+ const isRouteObject = (0, helpers_1.isPlainObject)(route);
51
+ if (isRouteObject) {
52
+ const isRouteHasDataProperty = 'data' in route;
53
+ if (!isRouteHasDataProperty) {
54
+ throw new Error(`routes[${index}]`);
55
+ }
56
+ try {
57
+ validateEntities(route.entities, operationType);
58
+ (0, validateInterceptors_1.validateInterceptors)(route.interceptors);
59
+ }
60
+ catch (error) {
61
+ throw new Error(`routes[${index}].${error.message}`);
62
+ }
63
+ return;
64
+ }
65
+ throw new Error(`routes[${index}]`);
66
+ });
67
+ return;
68
+ }
69
+ throw new Error('routes');
70
+ };
71
+ exports.validateRoutes = validateRoutes;
@@ -1 +1 @@
1
- export declare const validateInterceptors: (interceptors: unknown) => void;
1
+ export declare const validateInterceptors: (interceptors: unknown) => void;
@@ -1,21 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateInterceptors = void 0;
4
- const helpers_1 = require("../../../src/utils/helpers");
5
- const validateInterceptors = (interceptors) => {
6
- const isInterceptorsObject = (0, helpers_1.isPlainObject)(interceptors);
7
- if (isInterceptorsObject) {
8
- const { request, response } = interceptors;
9
- if (typeof request !== 'function' && typeof request !== 'undefined') {
10
- throw new Error('interceptors.request');
11
- }
12
- if (typeof response !== 'function' && typeof response !== 'undefined') {
13
- throw new Error('interceptors.response');
14
- }
15
- return;
16
- }
17
- if (typeof interceptors !== 'undefined') {
18
- throw new Error('interceptors');
19
- }
20
- };
21
- exports.validateInterceptors = validateInterceptors;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateInterceptors = void 0;
4
+ const helpers_1 = require("../../../src/utils/helpers");
5
+ const validateInterceptors = (interceptors) => {
6
+ const isInterceptorsObject = (0, helpers_1.isPlainObject)(interceptors);
7
+ if (isInterceptorsObject) {
8
+ const { request, response } = interceptors;
9
+ if (typeof request !== 'function' && typeof request !== 'undefined') {
10
+ throw new Error('interceptors.request');
11
+ }
12
+ if (typeof response !== 'function' && typeof response !== 'undefined') {
13
+ throw new Error('interceptors.response');
14
+ }
15
+ return;
16
+ }
17
+ if (typeof interceptors !== 'undefined') {
18
+ throw new Error('interceptors');
19
+ }
20
+ };
21
+ exports.validateInterceptors = validateInterceptors;
@@ -1 +1,2 @@
1
- export declare const validateMockServerConfig: (mockServerConfig: unknown) => void;
1
+ import type { PlainObject } from '../../src';
2
+ export declare const validateMockServerConfig: (mockServerConfig: PlainObject) => void;
@@ -1,34 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateMockServerConfig = void 0;
4
- const helpers_1 = require("../../src/utils/helpers");
5
- const validateBaseUrl_1 = require("./validateBaseUrl/validateBaseUrl");
6
- const validateCors_1 = require("./validateCors/validateCors");
7
- const validateGraphqlConfig_1 = require("./validateGraphqlConfig/validateGraphqlConfig");
8
- const validateInterceptors_1 = require("./validateInterceptors/validateInterceptors");
9
- const validatePort_1 = require("./validatePort/validatePort");
10
- const validateRestConfig_1 = require("./validateRestConfig/validateRestConfig");
11
- const validateStaticPath_1 = require("./validateStaticPath/validateStaticPath");
12
- const validateMockServerConfig = (mockServerConfig) => {
13
- if (!(0, helpers_1.isPlainObject)(mockServerConfig)) {
14
- throw new Error('configuration should be plain object; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
15
- }
16
- if (!mockServerConfig.rest && !mockServerConfig.graphql) {
17
- throw new Error('configuration should contain at least one of these configs: rest | graphql; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
18
- }
19
- try {
20
- if (mockServerConfig.rest)
21
- (0, validateRestConfig_1.validateRestConfig)(mockServerConfig.rest);
22
- if (mockServerConfig.graphql)
23
- (0, validateGraphqlConfig_1.validateGraphqlConfig)(mockServerConfig.graphql);
24
- (0, validateBaseUrl_1.validateBaseUrl)(mockServerConfig.baseUrl);
25
- (0, validatePort_1.validatePort)(mockServerConfig.port);
26
- (0, validateStaticPath_1.validateStaticPath)(mockServerConfig.staticPath);
27
- (0, validateInterceptors_1.validateInterceptors)(mockServerConfig.interceptors);
28
- (0, validateCors_1.validateCors)(mockServerConfig.cors);
29
- }
30
- catch (error) {
31
- throw new Error(`Validation Error: configuration.${error.message} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
32
- }
33
- };
34
- exports.validateMockServerConfig = validateMockServerConfig;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMockServerConfig = void 0;
4
+ const validateBaseUrl_1 = require("./validateBaseUrl/validateBaseUrl");
5
+ const validateCors_1 = require("./validateCors/validateCors");
6
+ const validateGraphqlConfig_1 = require("./validateGraphqlConfig/validateGraphqlConfig");
7
+ const validateInterceptors_1 = require("./validateInterceptors/validateInterceptors");
8
+ const validatePort_1 = require("./validatePort/validatePort");
9
+ const validateRestConfig_1 = require("./validateRestConfig/validateRestConfig");
10
+ const validateStaticPath_1 = require("./validateStaticPath/validateStaticPath");
11
+ const validateMockServerConfig = (mockServerConfig) => {
12
+ if (!mockServerConfig.rest && !mockServerConfig.graphql) {
13
+ throw new Error('configuration should contain at least one of these configs: rest | graphql; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
14
+ }
15
+ try {
16
+ if (mockServerConfig.rest)
17
+ (0, validateRestConfig_1.validateRestConfig)(mockServerConfig.rest);
18
+ if (mockServerConfig.graphql)
19
+ (0, validateGraphqlConfig_1.validateGraphqlConfig)(mockServerConfig.graphql);
20
+ (0, validateBaseUrl_1.validateBaseUrl)(mockServerConfig.baseUrl);
21
+ (0, validatePort_1.validatePort)(mockServerConfig.port);
22
+ (0, validateStaticPath_1.validateStaticPath)(mockServerConfig.staticPath);
23
+ (0, validateInterceptors_1.validateInterceptors)(mockServerConfig.interceptors);
24
+ (0, validateCors_1.validateCors)(mockServerConfig.cors);
25
+ }
26
+ catch (error) {
27
+ throw new Error(`Validation Error: configuration.${error.message} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
28
+ }
29
+ };
30
+ exports.validateMockServerConfig = validateMockServerConfig;
@@ -1 +1 @@
1
- export declare const validatePort: (port: unknown) => void;
1
+ export declare const validatePort: (port: unknown) => void;
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validatePort = void 0;
4
- const validatePort = (port) => {
5
- if (typeof port !== 'number' && typeof port !== 'undefined') {
6
- throw new Error('port');
7
- }
8
- };
9
- exports.validatePort = validatePort;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validatePort = void 0;
4
+ const validatePort = (port) => {
5
+ if (typeof port !== 'number' && typeof port !== 'undefined') {
6
+ throw new Error('port');
7
+ }
8
+ };
9
+ exports.validatePort = validatePort;
@@ -1 +1 @@
1
- export declare const validateRestConfig: (restConfig: unknown) => void;
1
+ export declare const validateRestConfig: (restConfig: unknown) => void;
@@ -1,52 +1,52 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRestConfig = void 0;
4
- const helpers_1 = require("../../../src/utils/helpers");
5
- const validateBaseUrl_1 = require("../validateBaseUrl/validateBaseUrl");
6
- const validateInterceptors_1 = require("../validateInterceptors/validateInterceptors");
7
- const validateRoutes_1 = require("./validateRoutes/validateRoutes");
8
- const validateConfigs = (configs) => {
9
- const isConfigsArray = Array.isArray(configs);
10
- if (isConfigsArray) {
11
- configs.forEach((config, index) => {
12
- const { path, method } = config;
13
- const isPathStringWithLeadingSlash = typeof path === 'string' && path.startsWith('/');
14
- if (!isPathStringWithLeadingSlash && !(path instanceof RegExp)) {
15
- throw new Error(`configs[${index}].path`);
16
- }
17
- // ✅ important:
18
- // compare without 'toLowerCase' because Express methods names is case-sensitive
19
- const allowedMethods = ['get', 'post', 'delete', 'put', 'patch'];
20
- const isMethodAllowed = typeof method === 'string' && allowedMethods.includes(method);
21
- if (!isMethodAllowed) {
22
- throw new Error(`configs[${index}].method`);
23
- }
24
- try {
25
- (0, validateRoutes_1.validateRoutes)(config.routes, method);
26
- (0, validateInterceptors_1.validateInterceptors)(config.interceptors);
27
- }
28
- catch (error) {
29
- throw new Error(`configs[${index}].${error.message}`);
30
- }
31
- });
32
- return;
33
- }
34
- throw new Error('configs');
35
- };
36
- const validateRestConfig = (restConfig) => {
37
- const isRestConfigObject = (0, helpers_1.isPlainObject)(restConfig);
38
- if (isRestConfigObject) {
39
- try {
40
- (0, validateBaseUrl_1.validateBaseUrl)(restConfig.baseUrl);
41
- validateConfigs(restConfig.configs);
42
- }
43
- catch (error) {
44
- throw new Error(`rest.${error.message}`);
45
- }
46
- return;
47
- }
48
- if (typeof restConfig !== 'undefined') {
49
- throw new Error('rest');
50
- }
51
- };
52
- exports.validateRestConfig = validateRestConfig;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRestConfig = void 0;
4
+ const helpers_1 = require("../../../src/utils/helpers");
5
+ const validateBaseUrl_1 = require("../validateBaseUrl/validateBaseUrl");
6
+ const validateInterceptors_1 = require("../validateInterceptors/validateInterceptors");
7
+ const validateRoutes_1 = require("./validateRoutes/validateRoutes");
8
+ const validateConfigs = (configs) => {
9
+ const isConfigsArray = Array.isArray(configs);
10
+ if (isConfigsArray) {
11
+ configs.forEach((config, index) => {
12
+ const { path, method } = config;
13
+ const isPathStringWithLeadingSlash = typeof path === 'string' && path.startsWith('/');
14
+ if (!isPathStringWithLeadingSlash && !(path instanceof RegExp)) {
15
+ throw new Error(`configs[${index}].path`);
16
+ }
17
+ // ✅ important:
18
+ // compare without 'toLowerCase' because Express methods names is case-sensitive
19
+ const allowedMethods = ['get', 'post', 'delete', 'put', 'patch', 'options'];
20
+ const isMethodAllowed = typeof method === 'string' && allowedMethods.includes(method);
21
+ if (!isMethodAllowed) {
22
+ throw new Error(`configs[${index}].method`);
23
+ }
24
+ try {
25
+ (0, validateRoutes_1.validateRoutes)(config.routes, method);
26
+ (0, validateInterceptors_1.validateInterceptors)(config.interceptors);
27
+ }
28
+ catch (error) {
29
+ throw new Error(`configs[${index}].${error.message}`);
30
+ }
31
+ });
32
+ return;
33
+ }
34
+ throw new Error('configs');
35
+ };
36
+ const validateRestConfig = (restConfig) => {
37
+ const isRestConfigObject = (0, helpers_1.isPlainObject)(restConfig);
38
+ if (isRestConfigObject) {
39
+ try {
40
+ (0, validateBaseUrl_1.validateBaseUrl)(restConfig.baseUrl);
41
+ validateConfigs(restConfig.configs);
42
+ }
43
+ catch (error) {
44
+ throw new Error(`rest.${error.message}`);
45
+ }
46
+ return;
47
+ }
48
+ if (typeof restConfig !== 'undefined') {
49
+ throw new Error('rest');
50
+ }
51
+ };
52
+ exports.validateRestConfig = validateRestConfig;
@@ -1,2 +1,2 @@
1
- import type { RestMethod } from '../../../../src';
2
- export declare const validateRoutes: (routes: unknown, method: RestMethod) => void;
1
+ import type { RestMethod } from '../../../../src/utils/types';
2
+ export declare const validateRoutes: (routes: unknown, method: RestMethod) => void;
@@ -1,104 +1,105 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRoutes = void 0;
4
- const helpers_1 = require("../../../../src/utils/helpers");
5
- const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
6
- const ALLOWED_ENTITIES_BY_METHOD = {
7
- get: ['headers', 'query', 'params'],
8
- delete: ['headers', 'query', 'params'],
9
- post: ['headers', 'query', 'params', 'body'],
10
- put: ['headers', 'query', 'params', 'body'],
11
- patch: ['headers', 'query', 'params', 'body']
12
- };
13
- const validateHeadersOrParams = (headersOrParams, entity) => {
14
- const isHeadersOrParamsObject = (0, helpers_1.isPlainObject)(headersOrParams);
15
- if (isHeadersOrParamsObject) {
16
- Object.entries(headersOrParams).forEach(([headerOrParamKey, headerOrParamValue]) => {
17
- if (typeof headerOrParamValue !== 'string') {
18
- throw new Error(`${entity}.${headerOrParamKey}`);
19
- }
20
- });
21
- return;
22
- }
23
- throw new Error(entity);
24
- };
25
- const validateQuery = (query, entity) => {
26
- const isQueryObject = (0, helpers_1.isPlainObject)(query);
27
- if (isQueryObject) {
28
- Object.entries(query).forEach(([queryKey, queryValue]) => {
29
- const isQueryValueArray = Array.isArray(queryValue);
30
- if (isQueryValueArray) {
31
- queryValue.forEach((queryValueElement, index) => {
32
- if (typeof queryValueElement !== 'string') {
33
- throw new Error(`${entity}.${queryKey}[${index}]`);
34
- }
35
- });
36
- return;
37
- }
38
- if (typeof queryValue !== 'string') {
39
- throw new Error(`${entity}.${queryKey}`);
40
- }
41
- });
42
- return;
43
- }
44
- throw new Error(entity);
45
- };
46
- const validateEntities = (entities, method) => {
47
- const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
48
- if (isEntitiesObject) {
49
- Object.keys(entities).forEach((entity) => {
50
- const isEntityAllowed = ALLOWED_ENTITIES_BY_METHOD[method].includes(entity);
51
- if (!isEntityAllowed) {
52
- throw new Error(`entities.${entity}`);
53
- }
54
- if (entity === 'headers' || entity === 'params') {
55
- try {
56
- const headersOrParams = entities[entity];
57
- return validateHeadersOrParams(headersOrParams, entity);
58
- }
59
- catch (error) {
60
- throw new Error(`entities.${error.message}`);
61
- }
62
- }
63
- if (entity === 'query') {
64
- try {
65
- const query = entities[entity];
66
- return validateQuery(query, entity);
67
- }
68
- catch (error) {
69
- throw new Error(`entities.${error.message}`);
70
- }
71
- }
72
- });
73
- return;
74
- }
75
- if (typeof entities !== 'undefined') {
76
- throw new Error('entities');
77
- }
78
- };
79
- const validateRoutes = (routes, method) => {
80
- const isRoutesArray = Array.isArray(routes);
81
- if (isRoutesArray) {
82
- routes.forEach((route, index) => {
83
- const isRouteObject = (0, helpers_1.isPlainObject)(route);
84
- if (isRouteObject) {
85
- const isRouteHasDataProperty = 'data' in route;
86
- if (!isRouteHasDataProperty) {
87
- throw new Error(`routes[${index}]`);
88
- }
89
- try {
90
- validateEntities(route.entities, method);
91
- (0, validateInterceptors_1.validateInterceptors)(route.interceptors);
92
- }
93
- catch (error) {
94
- throw new Error(`routes[${index}].${error.message}`);
95
- }
96
- return;
97
- }
98
- throw new Error(`routes[${index}]`);
99
- });
100
- return;
101
- }
102
- throw new Error('routes');
103
- };
104
- exports.validateRoutes = validateRoutes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRoutes = void 0;
4
+ const helpers_1 = require("../../../../src/utils/helpers");
5
+ const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
6
+ const ALLOWED_ENTITIES_BY_METHOD = {
7
+ get: ['headers', 'query', 'params'],
8
+ delete: ['headers', 'query', 'params'],
9
+ post: ['headers', 'query', 'params', 'body'],
10
+ put: ['headers', 'query', 'params', 'body'],
11
+ patch: ['headers', 'query', 'params', 'body'],
12
+ options: ['headers', 'query', 'params']
13
+ };
14
+ const validateHeadersOrParams = (headersOrParams, entity) => {
15
+ const isHeadersOrParamsObject = (0, helpers_1.isPlainObject)(headersOrParams);
16
+ if (isHeadersOrParamsObject) {
17
+ Object.entries(headersOrParams).forEach(([headerOrParamKey, headerOrParamValue]) => {
18
+ if (typeof headerOrParamValue !== 'string') {
19
+ throw new Error(`${entity}.${headerOrParamKey}`);
20
+ }
21
+ });
22
+ return;
23
+ }
24
+ throw new Error(entity);
25
+ };
26
+ const validateQuery = (query, entity) => {
27
+ const isQueryObject = (0, helpers_1.isPlainObject)(query);
28
+ if (isQueryObject) {
29
+ Object.entries(query).forEach(([queryKey, queryValue]) => {
30
+ const isQueryValueArray = Array.isArray(queryValue);
31
+ if (isQueryValueArray) {
32
+ queryValue.forEach((queryValueElement, index) => {
33
+ if (typeof queryValueElement !== 'string') {
34
+ throw new Error(`${entity}.${queryKey}[${index}]`);
35
+ }
36
+ });
37
+ return;
38
+ }
39
+ if (typeof queryValue !== 'string') {
40
+ throw new Error(`${entity}.${queryKey}`);
41
+ }
42
+ });
43
+ return;
44
+ }
45
+ throw new Error(entity);
46
+ };
47
+ const validateEntities = (entities, method) => {
48
+ const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
49
+ if (isEntitiesObject) {
50
+ Object.keys(entities).forEach((entity) => {
51
+ const isEntityAllowed = ALLOWED_ENTITIES_BY_METHOD[method].includes(entity);
52
+ if (!isEntityAllowed) {
53
+ throw new Error(`entities.${entity}`);
54
+ }
55
+ if (entity === 'headers' || entity === 'params') {
56
+ try {
57
+ const headersOrParams = entities[entity];
58
+ validateHeadersOrParams(headersOrParams, entity);
59
+ }
60
+ catch (error) {
61
+ throw new Error(`entities.${error.message}`);
62
+ }
63
+ }
64
+ if (entity === 'query') {
65
+ try {
66
+ const query = entities[entity];
67
+ validateQuery(query, entity);
68
+ }
69
+ catch (error) {
70
+ throw new Error(`entities.${error.message}`);
71
+ }
72
+ }
73
+ });
74
+ return;
75
+ }
76
+ if (typeof entities !== 'undefined') {
77
+ throw new Error('entities');
78
+ }
79
+ };
80
+ const validateRoutes = (routes, method) => {
81
+ const isRoutesArray = Array.isArray(routes);
82
+ if (isRoutesArray) {
83
+ routes.forEach((route, index) => {
84
+ const isRouteObject = (0, helpers_1.isPlainObject)(route);
85
+ if (isRouteObject) {
86
+ const isRouteHasDataProperty = 'data' in route;
87
+ if (!isRouteHasDataProperty) {
88
+ throw new Error(`routes[${index}]`);
89
+ }
90
+ try {
91
+ validateEntities(route.entities, method);
92
+ (0, validateInterceptors_1.validateInterceptors)(route.interceptors);
93
+ }
94
+ catch (error) {
95
+ throw new Error(`routes[${index}].${error.message}`);
96
+ }
97
+ return;
98
+ }
99
+ throw new Error(`routes[${index}]`);
100
+ });
101
+ return;
102
+ }
103
+ throw new Error('routes');
104
+ };
105
+ exports.validateRoutes = validateRoutes;
@@ -1 +1 @@
1
- export declare const validateStaticPath: (staticPath: unknown) => void;
1
+ export declare const validateStaticPath: (staticPath: unknown) => void;