mock-config-server 3.0.1 → 3.1.1

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 (146) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +614 -502
  3. package/dist/bin/bin.js +8 -3
  4. package/dist/bin/build.js +51 -45
  5. package/dist/bin/cli.js +37 -44
  6. package/dist/bin/helpers/index.js +36 -17
  7. package/dist/bin/helpers/resolveConfigFile.js +20 -17
  8. package/dist/bin/helpers/resolveConfigFilePath.js +12 -35
  9. package/dist/bin/helpers/resolveExportsFromSourceCode.js +11 -8
  10. package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +12 -35
  11. package/dist/bin/run.js +17 -12
  12. package/dist/bin/validateMockServerConfig/helpers/index.js +25 -16
  13. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.js +14 -15
  14. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +8 -6
  15. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +14 -15
  16. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +15 -18
  17. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -9
  18. package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +75 -73
  19. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.d.ts +1 -0
  20. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.js +45 -0
  21. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +47 -43
  22. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +90 -83
  23. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +22 -16
  24. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +29 -27
  25. package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -6
  26. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -47
  27. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +94 -87
  28. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +43 -34
  29. package/dist/index.js +14 -15
  30. package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.d.ts +3 -0
  31. package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +33 -0
  32. package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.d.ts +4 -0
  33. package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +16 -0
  34. package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.d.ts +4 -0
  35. package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js +8 -0
  36. package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.d.ts +3 -0
  37. package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.js +38 -0
  38. package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.d.ts +1 -0
  39. package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.js +8 -0
  40. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.d.ts +4 -0
  41. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +88 -0
  42. package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.d.ts +2 -0
  43. package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.js +12 -0
  44. package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.d.ts +4 -0
  45. package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +38 -0
  46. package/dist/src/core/database/createDatabaseRoutes/helpers/index.d.ts +5 -0
  47. package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +60 -0
  48. package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.d.ts +5 -0
  49. package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +30 -0
  50. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.d.ts +11 -0
  51. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +64 -0
  52. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.d.ts +11 -0
  53. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +58 -0
  54. package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.d.ts +10 -0
  55. package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +54 -0
  56. package/dist/src/core/database/createDatabaseRoutes/storages/index.d.ts +2 -0
  57. package/dist/src/core/database/createDatabaseRoutes/storages/index.js +27 -0
  58. package/dist/src/core/database/index.d.ts +1 -0
  59. package/dist/src/core/database/index.js +16 -0
  60. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +96 -83
  61. package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +14 -15
  62. package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +36 -30
  63. package/dist/src/core/graphql/index.js +14 -15
  64. package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +15 -13
  65. package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +14 -15
  66. package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +16 -14
  67. package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +48 -41
  68. package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +13 -10
  69. package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +14 -15
  70. package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +21 -18
  71. package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +18 -15
  72. package/dist/src/core/middlewares/index.js +92 -23
  73. package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +21 -21
  74. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +24 -16
  75. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +78 -74
  76. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +36 -31
  77. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +6 -5
  78. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +6 -3
  79. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +25 -16
  80. package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +36 -17
  81. package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +63 -48
  82. package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +13 -7
  83. package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +26 -25
  84. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +71 -56
  85. package/dist/src/core/rest/createRestRoutes/helpers/index.js +14 -15
  86. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +38 -32
  87. package/dist/src/core/rest/index.js +14 -15
  88. package/dist/src/index.js +36 -17
  89. package/dist/src/server/createMockServer/createMockServer.js +74 -53
  90. package/dist/src/server/index.js +25 -16
  91. package/dist/src/server/startMockServer/startMockServer.js +20 -17
  92. package/dist/src/static/views/assets/icons/scheme-dark.svg +3 -3
  93. package/dist/src/static/views/assets/icons/scheme-light.svg +3 -3
  94. package/dist/src/static/views/assets/styles/global.css +88 -88
  95. package/dist/src/static/views/components/header/index.css +55 -55
  96. package/dist/src/static/views/components/header/index.ejs +39 -39
  97. package/dist/src/static/views/components/header/index.js +1 -1
  98. package/dist/src/static/views/features/scheme/dark.css +12 -12
  99. package/dist/src/static/views/features/scheme/index.ejs +3 -3
  100. package/dist/src/static/views/features/scheme/index.js +31 -31
  101. package/dist/src/static/views/features/scheme/light.css +12 -12
  102. package/dist/src/static/views/features/tab/index.css +30 -30
  103. package/dist/src/static/views/features/tab/index.ejs +1 -1
  104. package/dist/src/static/views/features/tab/index.js +12 -12
  105. package/dist/src/static/views/pages/404/index.css +10 -10
  106. package/dist/src/static/views/pages/404/index.ejs +84 -84
  107. package/dist/src/utils/constants/appPath.js +6 -2
  108. package/dist/src/utils/constants/checkModes.js +21 -30
  109. package/dist/src/utils/constants/default.js +15 -11
  110. package/dist/src/utils/constants/index.js +36 -17
  111. package/dist/src/utils/helpers/asyncHandler.js +6 -3
  112. package/dist/src/utils/helpers/config/index.js +14 -15
  113. package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +109 -122
  114. package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +10 -6
  115. package/dist/src/utils/helpers/entities/index.js +25 -16
  116. package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +7 -4
  117. package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +28 -18
  118. package/dist/src/utils/helpers/graphql/index.js +36 -17
  119. package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +11 -9
  120. package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +20 -17
  121. package/dist/src/utils/helpers/index.js +114 -25
  122. package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +22 -16
  123. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +56 -48
  124. package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +8 -5
  125. package/dist/src/utils/helpers/interceptors/index.js +25 -16
  126. package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +6 -6
  127. package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +6 -3
  128. package/dist/src/utils/helpers/isRegExp/isRegExp.js +6 -3
  129. package/dist/src/utils/helpers/sleep.js +7 -4
  130. package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +6 -6
  131. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +7 -4
  132. package/dist/src/utils/helpers/url/index.js +47 -18
  133. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +6 -3
  134. package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +11 -10
  135. package/dist/src/utils/types/checkModes.js +1 -2
  136. package/dist/src/utils/types/database.d.ts +6 -0
  137. package/dist/src/utils/types/database.js +1 -0
  138. package/dist/src/utils/types/graphql.js +1 -2
  139. package/dist/src/utils/types/index.d.ts +1 -0
  140. package/dist/src/utils/types/index.js +80 -20
  141. package/dist/src/utils/types/interceptors.js +1 -2
  142. package/dist/src/utils/types/rest.js +1 -2
  143. package/dist/src/utils/types/server.d.ts +5 -0
  144. package/dist/src/utils/types/server.js +1 -2
  145. package/dist/src/utils/types/values.js +1 -2
  146. package/package.json +130 -113
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.validateBaseUrl = void 0;
4
- const validateBaseUrl = (baseUrl) => {
5
- if (typeof baseUrl !== 'string' && typeof baseUrl !== 'undefined') {
6
- throw new Error('baseUrl');
7
- }
8
- if (typeof baseUrl === 'string' && !baseUrl.startsWith('/')) {
9
- throw new Error('baseUrl');
10
- }
7
+ const validateBaseUrl = baseUrl => {
8
+ if (typeof baseUrl !== 'string' && typeof baseUrl !== 'undefined') {
9
+ throw new Error('baseUrl');
10
+ }
11
+ if (typeof baseUrl === 'string' && !baseUrl.startsWith('/')) {
12
+ throw new Error('baseUrl');
13
+ }
11
14
  };
12
- exports.validateBaseUrl = validateBaseUrl;
15
+ exports.validateBaseUrl = validateBaseUrl;
@@ -1,82 +1,84 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.validateCors = void 0;
4
- const helpers_1 = require("../../../src/utils/helpers");
5
- const validateOrigin = (origin) => {
6
- const isOriginArray = Array.isArray(origin);
7
- if (isOriginArray) {
8
- origin.forEach((originElement, index) => {
9
- const isOriginElementStringOrRegExp = typeof originElement === 'string' || originElement instanceof RegExp;
10
- if (!isOriginElementStringOrRegExp) {
11
- throw new Error(`origin[${index}]`);
12
- }
13
- });
14
- return;
15
- }
16
- const isOriginStringOrRegexp = typeof origin === 'string' || origin instanceof RegExp;
17
- const isOriginFunction = typeof origin === 'function';
18
- if (!isOriginStringOrRegexp && !isOriginFunction) {
19
- throw new Error('origin');
20
- }
7
+ var _helpers = require("../../../src/utils/helpers");
8
+ const validateOrigin = origin => {
9
+ const isOriginArray = Array.isArray(origin);
10
+ if (isOriginArray) {
11
+ origin.forEach((originElement, index) => {
12
+ const isOriginElementStringOrRegExp = typeof originElement === 'string' || originElement instanceof RegExp;
13
+ if (!isOriginElementStringOrRegExp) {
14
+ throw new Error(`origin[${index}]`);
15
+ }
16
+ });
17
+ return;
18
+ }
19
+ const isOriginStringOrRegexp = typeof origin === 'string' || origin instanceof RegExp;
20
+ const isOriginFunction = typeof origin === 'function';
21
+ if (!isOriginStringOrRegexp && !isOriginFunction) {
22
+ throw new Error('origin');
23
+ }
21
24
  };
22
- const validateMethods = (methods) => {
23
- const isMethodsArray = Array.isArray(methods);
24
- if (isMethodsArray) {
25
- const allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
26
- methods.forEach((method, index) => {
27
- // ✅ important:
28
- // compare without 'toUpperCase' because 'Access-Control-Allow-Methods' value is case-sensitive
29
- if (!allowedMethods.includes(method)) {
30
- throw new Error(`methods[${index}]`);
31
- }
32
- });
33
- return;
34
- }
35
- if (typeof methods !== 'undefined') {
36
- throw new Error('methods');
37
- }
25
+ const validateMethods = methods => {
26
+ const isMethodsArray = Array.isArray(methods);
27
+ if (isMethodsArray) {
28
+ const allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
29
+ methods.forEach((method, index) => {
30
+ // ✅ important:
31
+ // compare without 'toUpperCase' because 'Access-Control-Allow-Methods' value is case-sensitive
32
+ if (!allowedMethods.includes(method)) {
33
+ throw new Error(`methods[${index}]`);
34
+ }
35
+ });
36
+ return;
37
+ }
38
+ if (typeof methods !== 'undefined') {
39
+ throw new Error('methods');
40
+ }
38
41
  };
39
- const validateHeaders = (headers) => {
40
- const isHeadersArray = Array.isArray(headers);
41
- if (isHeadersArray) {
42
- headers.forEach((header, index) => {
43
- if (typeof header !== 'string') {
44
- throw new Error(`headers[${index}]`);
45
- }
46
- });
47
- return;
48
- }
49
- if (typeof headers !== 'undefined') {
50
- throw new Error('headers');
51
- }
42
+ const validateHeaders = headers => {
43
+ const isHeadersArray = Array.isArray(headers);
44
+ if (isHeadersArray) {
45
+ headers.forEach((header, index) => {
46
+ if (typeof header !== 'string') {
47
+ throw new Error(`headers[${index}]`);
48
+ }
49
+ });
50
+ return;
51
+ }
52
+ if (typeof headers !== 'undefined') {
53
+ throw new Error('headers');
54
+ }
52
55
  };
53
- const validateCredentials = (credentials) => {
54
- if (typeof credentials !== 'boolean' && typeof credentials !== 'undefined') {
55
- throw new Error('credentials');
56
- }
56
+ const validateCredentials = credentials => {
57
+ if (typeof credentials !== 'boolean' && typeof credentials !== 'undefined') {
58
+ throw new Error('credentials');
59
+ }
57
60
  };
58
- const validateMaxAge = (maxAge) => {
59
- if (typeof maxAge !== 'number' && typeof maxAge !== 'undefined') {
60
- throw new Error('maxAge');
61
- }
61
+ const validateMaxAge = maxAge => {
62
+ if (typeof maxAge !== 'number' && typeof maxAge !== 'undefined') {
63
+ throw new Error('maxAge');
64
+ }
62
65
  };
63
- const validateCors = (cors) => {
64
- const isCorsObject = (0, helpers_1.isPlainObject)(cors);
65
- if (isCorsObject) {
66
- try {
67
- validateOrigin(cors.origin);
68
- validateMethods(cors.methods);
69
- validateHeaders(cors.headers);
70
- validateCredentials(cors.credentials);
71
- validateMaxAge(cors.maxAge);
72
- }
73
- catch (error) {
74
- throw new Error(`cors.${error.message}`);
75
- }
76
- return;
77
- }
78
- if (typeof cors !== 'undefined') {
79
- throw new Error('cors');
66
+ const validateCors = cors => {
67
+ const isCorsObject = (0, _helpers.isPlainObject)(cors);
68
+ if (isCorsObject) {
69
+ try {
70
+ validateOrigin(cors.origin);
71
+ validateMethods(cors.methods);
72
+ validateHeaders(cors.headers);
73
+ validateCredentials(cors.credentials);
74
+ validateMaxAge(cors.maxAge);
75
+ } catch (error) {
76
+ throw new Error(`cors.${error.message}`);
80
77
  }
78
+ return;
79
+ }
80
+ if (typeof cors !== 'undefined') {
81
+ throw new Error('cors');
82
+ }
81
83
  };
82
- exports.validateCors = validateCors;
84
+ exports.validateCors = validateCors;
@@ -0,0 +1 @@
1
+ export declare const validateDatabaseConfig: (databaseConfig: unknown) => void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateDatabaseConfig = void 0;
7
+ var _helpers = require("../../../src/utils/helpers");
8
+ const validateData = data => {
9
+ const isDataObject = (0, _helpers.isPlainObject)(data);
10
+ const isDataJsonFilePath = typeof data === 'string' && data.endsWith('.json');
11
+ if (!isDataObject && !isDataJsonFilePath) throw new Error('data');
12
+ };
13
+ const validateRoutes = routes => {
14
+ const isRoutesObject = (0, _helpers.isPlainObject)(routes);
15
+ if (isRoutesObject) {
16
+ Object.entries(routes).forEach(([routeKey, routeValue]) => {
17
+ const isKeyRoutePath = routeKey.startsWith('/');
18
+ const isValueRoutePath = typeof routeValue === 'string' && routeValue.startsWith('/');
19
+ if (!isKeyRoutePath || !isValueRoutePath) {
20
+ throw new Error(`routes.${routeKey}`);
21
+ }
22
+ });
23
+ return;
24
+ }
25
+ const isRoutesJsonFilePath = typeof routes === 'string' && routes.endsWith('.json');
26
+ if (!isRoutesJsonFilePath && typeof routes !== 'undefined') {
27
+ throw new Error('routes');
28
+ }
29
+ };
30
+ const validateDatabaseConfig = databaseConfig => {
31
+ const isDatabaseConfigObject = (0, _helpers.isPlainObject)(databaseConfig);
32
+ if (isDatabaseConfigObject) {
33
+ try {
34
+ validateData(databaseConfig.data);
35
+ validateRoutes(databaseConfig.routes);
36
+ } catch (error) {
37
+ throw new Error(`database.${error.message}`);
38
+ }
39
+ return;
40
+ }
41
+ if (typeof databaseConfig !== 'undefined') {
42
+ throw new Error('database');
43
+ }
44
+ };
45
+ exports.validateDatabaseConfig = validateDatabaseConfig;
@@ -1,48 +1,52 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.validateGraphqlConfig = 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 { operationType, operationName } = config;
13
- if (operationType !== 'query' && operationType !== 'mutation') {
14
- throw new Error(`configs[${index}].operationType`);
15
- }
16
- const isOperationNameStringOrRegExp = typeof operationName === 'string' || operationName instanceof RegExp;
17
- if (!isOperationNameStringOrRegExp) {
18
- throw new Error(`configs[${index}].operationName`);
19
- }
20
- try {
21
- (0, validateRoutes_1.validateRoutes)(config.routes, operationType);
22
- (0, validateInterceptors_1.validateInterceptors)(config.interceptors);
23
- }
24
- catch (error) {
25
- throw new Error(`configs[${index}].${error.message}`);
26
- }
27
- });
28
- return;
29
- }
30
- throw new Error('configs');
7
+ var _helpers = require("../../../src/utils/helpers");
8
+ var _validateBaseUrl = require("../validateBaseUrl/validateBaseUrl");
9
+ var _validateInterceptors = require("../validateInterceptors/validateInterceptors");
10
+ var _validateRoutes = require("./validateRoutes/validateRoutes");
11
+ const validateConfigs = configs => {
12
+ const isConfigsArray = Array.isArray(configs);
13
+ if (isConfigsArray) {
14
+ configs.forEach((config, index) => {
15
+ const {
16
+ operationType,
17
+ operationName
18
+ } = config;
19
+ if (operationType !== 'query' && operationType !== 'mutation') {
20
+ throw new Error(`configs[${index}].operationType`);
21
+ }
22
+ const isOperationNameStringOrRegExp = typeof operationName === 'string' || operationName instanceof RegExp;
23
+ if (!isOperationNameStringOrRegExp) {
24
+ throw new Error(`configs[${index}].operationName`);
25
+ }
26
+ try {
27
+ (0, _validateRoutes.validateRoutes)(config.routes, operationType);
28
+ (0, _validateInterceptors.validateInterceptors)(config.interceptors);
29
+ } catch (error) {
30
+ throw new Error(`configs[${index}].${error.message}`);
31
+ }
32
+ });
33
+ return;
34
+ }
35
+ throw new Error('configs');
31
36
  };
32
- const validateGraphqlConfig = (graphqlConfig) => {
33
- const isGraphqlConfigObject = (0, helpers_1.isPlainObject)(graphqlConfig);
34
- if (isGraphqlConfigObject) {
35
- try {
36
- (0, validateBaseUrl_1.validateBaseUrl)(graphqlConfig.baseUrl);
37
- validateConfigs(graphqlConfig.configs);
38
- }
39
- catch (error) {
40
- throw new Error(`graphql.${error.message}`);
41
- }
42
- return;
43
- }
44
- if (typeof graphqlConfig !== 'undefined') {
45
- throw new Error('graphql');
37
+ const validateGraphqlConfig = graphqlConfig => {
38
+ const isGraphqlConfigObject = (0, _helpers.isPlainObject)(graphqlConfig);
39
+ if (isGraphqlConfigObject) {
40
+ try {
41
+ (0, _validateBaseUrl.validateBaseUrl)(graphqlConfig.baseUrl);
42
+ validateConfigs(graphqlConfig.configs);
43
+ } catch (error) {
44
+ throw new Error(`graphql.${error.message}`);
46
45
  }
46
+ return;
47
+ }
48
+ if (typeof graphqlConfig !== 'undefined') {
49
+ throw new Error('graphql');
50
+ }
47
51
  };
48
- exports.validateGraphqlConfig = validateGraphqlConfig;
52
+ exports.validateGraphqlConfig = validateGraphqlConfig;
@@ -1,97 +1,104 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.validateRoutes = void 0;
4
- const helpers_1 = require("../../../../src/utils/helpers");
5
- const helpers_2 = require("../../helpers");
6
- const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
7
+ var _helpers = require("../../../../src/utils/helpers");
8
+ var _helpers2 = require("../../helpers");
9
+ var _validateInterceptors = require("../../validateInterceptors/validateInterceptors");
7
10
  const ALLOWED_ENTITIES_BY_OPERATION_TYPE = {
8
- query: ['headers', 'cookies', 'query', 'variables'],
9
- mutation: ['headers', 'cookies', 'query', 'variables']
11
+ query: ['headers', 'cookies', 'query', 'variables'],
12
+ mutation: ['headers', 'cookies', 'query', 'variables']
10
13
  };
11
14
  const validateEntity = (entity, entityName) => {
12
- const { checkMode: topLevelCheckMode, value: topLevelValue } = (0, helpers_1.convertToEntityDescriptor)(entity);
13
- const isVariables = entityName === 'variables';
14
- const isTopLevelDescriptor = (0, helpers_1.isEntityDescriptor)(entity);
15
- if (isTopLevelDescriptor && isVariables) {
16
- if (!(0, helpers_2.isCheckModeValid)(topLevelCheckMode, 'variables')) {
17
- throw new Error('variables.checkMode');
18
- }
19
- if (!(0, helpers_2.isDescriptorValueValid)(topLevelCheckMode, topLevelValue, 'variables')) {
20
- const errorMessage = 'variables.value';
21
- throw new Error(errorMessage);
22
- }
15
+ const {
16
+ checkMode: topLevelCheckMode,
17
+ value: topLevelValue
18
+ } = (0, _helpers.convertToEntityDescriptor)(entity);
19
+ const isVariables = entityName === 'variables';
20
+ const isTopLevelDescriptor = (0, _helpers.isEntityDescriptor)(entity);
21
+ if (isTopLevelDescriptor && isVariables) {
22
+ if (!(0, _helpers2.isCheckModeValid)(topLevelCheckMode, 'variables')) {
23
+ throw new Error('variables.checkMode');
24
+ }
25
+ if (!(0, _helpers2.isDescriptorValueValid)(topLevelCheckMode, topLevelValue, 'variables')) {
26
+ const errorMessage = 'variables.value';
27
+ throw new Error(errorMessage);
23
28
  }
24
- const isEntityObject = (0, helpers_1.isPlainObject)(entity) && !(entity instanceof RegExp);
25
- const isEntityArray = Array.isArray(entity) && isVariables;
26
- if (isEntityObject || isEntityArray) {
27
- Object.entries(topLevelValue).forEach(([key, valueOrDescriptor]) => {
28
- const { checkMode, value } = (0, helpers_1.convertToEntityDescriptor)(valueOrDescriptor);
29
- if (!(0, helpers_2.isCheckModeValid)(checkMode)) {
30
- throw new Error(`${entityName}.${key}.checkMode`);
31
- }
32
- const isDescriptor = (0, helpers_1.isEntityDescriptor)(valueOrDescriptor);
33
- const errorMessage = `${entityName}.${key}${isDescriptor ? '.value' : ''}`;
34
- const isValueArray = Array.isArray(value);
35
- if (isValueArray && !isVariables) {
36
- value.forEach((element, index) => {
37
- if (!(0, helpers_2.isDescriptorValueValid)(checkMode, element)) {
38
- throw new Error(`${errorMessage}[${index}]`);
39
- }
40
- });
41
- return;
42
- }
43
- if (!(0, helpers_2.isDescriptorValueValid)(checkMode, value)) {
44
- throw new Error(errorMessage);
45
- }
29
+ }
30
+ const isEntityObject = (0, _helpers.isPlainObject)(entity) && !(entity instanceof RegExp);
31
+ const isEntityArray = Array.isArray(entity) && isVariables;
32
+ if (isEntityObject || isEntityArray) {
33
+ Object.entries(topLevelValue).forEach(([key, valueOrDescriptor]) => {
34
+ const {
35
+ checkMode,
36
+ value
37
+ } = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
38
+ if (!(0, _helpers2.isCheckModeValid)(checkMode)) {
39
+ throw new Error(`${entityName}.${key}.checkMode`);
40
+ }
41
+ const isDescriptor = (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
42
+ const errorMessage = `${entityName}.${key}${isDescriptor ? '.value' : ''}`;
43
+ const isValueArray = Array.isArray(value);
44
+ if (isValueArray && !isVariables) {
45
+ value.forEach((element, index) => {
46
+ if (!(0, _helpers2.isDescriptorValueValid)(checkMode, element)) {
47
+ throw new Error(`${errorMessage}[${index}]`);
48
+ }
46
49
  });
47
50
  return;
48
- }
49
- throw new Error(entityName);
51
+ }
52
+ if (!(0, _helpers2.isDescriptorValueValid)(checkMode, value)) {
53
+ throw new Error(errorMessage);
54
+ }
55
+ });
56
+ return;
57
+ }
58
+ throw new Error(entityName);
50
59
  };
51
60
  const validateEntities = (entities, operationType) => {
52
- const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
53
- if (isEntitiesObject) {
54
- Object.keys(entities).forEach((entityName) => {
55
- const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entityName);
56
- if (!isEntityAllowed) {
57
- throw new Error(`entities.${entityName}`);
58
- }
59
- try {
60
- validateEntity(entities[entityName], entityName);
61
- }
62
- catch (error) {
63
- throw new Error(`entities.${error.message}`);
64
- }
65
- });
66
- return;
67
- }
68
- if (typeof entities !== 'undefined') {
69
- throw new Error('entities');
70
- }
61
+ const isEntitiesObject = (0, _helpers.isPlainObject)(entities);
62
+ if (isEntitiesObject) {
63
+ Object.keys(entities).forEach(entityName => {
64
+ const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entityName);
65
+ if (!isEntityAllowed) {
66
+ throw new Error(`entities.${entityName}`);
67
+ }
68
+ try {
69
+ validateEntity(entities[entityName], entityName);
70
+ } catch (error) {
71
+ throw new Error(`entities.${error.message}`);
72
+ }
73
+ });
74
+ return;
75
+ }
76
+ if (typeof entities !== 'undefined') {
77
+ throw new Error('entities');
78
+ }
71
79
  };
72
80
  const validateRoutes = (routes, operationType) => {
73
- const isRoutesArray = Array.isArray(routes);
74
- if (isRoutesArray) {
75
- routes.forEach((route, index) => {
76
- const isRouteObject = (0, helpers_1.isPlainObject)(route);
77
- if (isRouteObject) {
78
- const isRouteHasDataProperty = 'data' in route;
79
- if (!isRouteHasDataProperty) {
80
- throw new Error(`routes[${index}]`);
81
- }
82
- try {
83
- validateEntities(route.entities, operationType);
84
- (0, validateInterceptors_1.validateInterceptors)(route.interceptors);
85
- }
86
- catch (error) {
87
- throw new Error(`routes[${index}].${error.message}`);
88
- }
89
- return;
90
- }
91
- throw new Error(`routes[${index}]`);
92
- });
81
+ const isRoutesArray = Array.isArray(routes);
82
+ if (isRoutesArray) {
83
+ routes.forEach((route, index) => {
84
+ const isRouteObject = (0, _helpers.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, operationType);
92
+ (0, _validateInterceptors.validateInterceptors)(route.interceptors);
93
+ } catch (error) {
94
+ throw new Error(`routes[${index}].${error.message}`);
95
+ }
93
96
  return;
94
- }
95
- throw new Error('routes');
97
+ }
98
+ throw new Error(`routes[${index}]`);
99
+ });
100
+ return;
101
+ }
102
+ throw new Error('routes');
96
103
  };
97
- exports.validateRoutes = validateRoutes;
104
+ exports.validateRoutes = validateRoutes;
@@ -1,21 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  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;
7
+ var _helpers = require("../../../src/utils/helpers");
8
+ const validateInterceptors = interceptors => {
9
+ const isInterceptorsObject = (0, _helpers.isPlainObject)(interceptors);
10
+ if (isInterceptorsObject) {
11
+ const {
12
+ request,
13
+ response
14
+ } = interceptors;
15
+ if (typeof request !== 'function' && typeof request !== 'undefined') {
16
+ throw new Error('interceptors.request');
16
17
  }
17
- if (typeof interceptors !== 'undefined') {
18
- throw new Error('interceptors');
18
+ if (typeof response !== 'function' && typeof response !== 'undefined') {
19
+ throw new Error('interceptors.response');
19
20
  }
21
+ return;
22
+ }
23
+ if (typeof interceptors !== 'undefined') {
24
+ throw new Error('interceptors');
25
+ }
20
26
  };
21
- exports.validateInterceptors = validateInterceptors;
27
+ exports.validateInterceptors = validateInterceptors;
@@ -1,30 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  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
- }
7
+ var _validateBaseUrl = require("./validateBaseUrl/validateBaseUrl");
8
+ var _validateCors = require("./validateCors/validateCors");
9
+ var _validateDatabaseConfig = require("./validateDatabaseConfig/validateDatabaseConfig");
10
+ var _validateGraphqlConfig = require("./validateGraphqlConfig/validateGraphqlConfig");
11
+ var _validateInterceptors = require("./validateInterceptors/validateInterceptors");
12
+ var _validatePort = require("./validatePort/validatePort");
13
+ var _validateRestConfig = require("./validateRestConfig/validateRestConfig");
14
+ var _validateStaticPath = require("./validateStaticPath/validateStaticPath");
15
+ const validateMockServerConfig = mockServerConfig => {
16
+ if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database) {
17
+ throw new Error('configuration should contain at least one of these configs: rest | graphql | database; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
18
+ }
19
+ try {
20
+ if (mockServerConfig.rest) (0, _validateRestConfig.validateRestConfig)(mockServerConfig.rest);
21
+ if (mockServerConfig.graphql) (0, _validateGraphqlConfig.validateGraphqlConfig)(mockServerConfig.graphql);
22
+ if (mockServerConfig.database) (0, _validateDatabaseConfig.validateDatabaseConfig)(mockServerConfig.database);
23
+ (0, _validateBaseUrl.validateBaseUrl)(mockServerConfig.baseUrl);
24
+ (0, _validatePort.validatePort)(mockServerConfig.port);
25
+ (0, _validateStaticPath.validateStaticPath)(mockServerConfig.staticPath);
26
+ (0, _validateInterceptors.validateInterceptors)(mockServerConfig.interceptors);
27
+ (0, _validateCors.validateCors)(mockServerConfig.cors);
28
+ } catch (error) {
29
+ 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`);
30
+ }
29
31
  };
30
- exports.validateMockServerConfig = validateMockServerConfig;
32
+ exports.validateMockServerConfig = validateMockServerConfig;