mock-config-server 3.3.4 → 3.4.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 (171) hide show
  1. package/README.md +107 -3
  2. package/dist/bin/build.js +1 -1
  3. package/dist/bin/cli.d.ts +1 -1
  4. package/dist/bin/cli.js +25 -16
  5. package/dist/bin/helpers/createTemplate.d.ts +9 -0
  6. package/dist/bin/helpers/createTemplate.js +25 -0
  7. package/dist/bin/helpers/getMostSpecificPathFromError.d.ts +2 -0
  8. package/dist/bin/helpers/getMostSpecificPathFromError.js +36 -0
  9. package/dist/bin/helpers/getValidationMessageFromPath.d.ts +1 -0
  10. package/dist/bin/helpers/getValidationMessageFromPath.js +11 -0
  11. package/dist/bin/helpers/index.d.ts +4 -0
  12. package/dist/bin/helpers/index.js +44 -0
  13. package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.d.ts +4 -0
  14. package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +9 -0
  15. package/dist/bin/init.d.ts +2 -0
  16. package/dist/bin/init.js +101 -0
  17. package/dist/bin/run.d.ts +1 -1
  18. package/dist/bin/run.js +23 -2
  19. package/dist/bin/templates/.eslintrc.js +14 -0
  20. package/dist/bin/templates/js/full/mock-requests/graphql/index.js +2 -0
  21. package/dist/bin/templates/js/full/mock-requests/graphql/user.js +35 -0
  22. package/dist/bin/templates/js/full/mock-requests/graphql/users.js +12 -0
  23. package/dist/bin/templates/js/full/mock-requests/rest/index.js +2 -0
  24. package/dist/bin/templates/js/full/mock-requests/rest/user.js +35 -0
  25. package/dist/bin/templates/js/full/mock-requests/rest/users.js +12 -0
  26. package/dist/bin/templates/js/full/mock-server.config.js +16 -0
  27. package/dist/bin/templates/js/graphql/mock-requests/index.js +2 -0
  28. package/dist/bin/templates/js/graphql/mock-requests/user.js +35 -0
  29. package/dist/bin/templates/js/graphql/mock-requests/users.js +12 -0
  30. package/dist/bin/templates/js/graphql/mock-server.config.js +9 -0
  31. package/dist/bin/templates/js/rest/mock-requests/index.js +2 -0
  32. package/dist/bin/templates/js/rest/mock-requests/user.js +35 -0
  33. package/dist/bin/templates/js/rest/mock-requests/users.js +12 -0
  34. package/dist/bin/templates/js/rest/mock-server.config.js +9 -0
  35. package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -0
  36. package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -0
  37. package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -0
  38. package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -0
  39. package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -0
  40. package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -0
  41. package/dist/bin/templates/ts/full/mock-server.config.ts +18 -0
  42. package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -0
  43. package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -0
  44. package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -0
  45. package/dist/bin/templates/ts/graphql/mock-server.config.ts +11 -0
  46. package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -0
  47. package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -0
  48. package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -0
  49. package/dist/bin/templates/ts/rest/mock-server.config.ts +11 -0
  50. package/dist/bin/templates/tsconfig.json +11 -0
  51. package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.d.ts +1 -0
  52. package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +8 -0
  53. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.d.ts +23 -0
  54. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +17 -0
  55. package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.d.ts +11 -0
  56. package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +12 -0
  57. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +248 -0
  58. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +31 -0
  59. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +61 -0
  60. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +37 -0
  61. package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.d.ts +11 -0
  62. package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +11 -0
  63. package/dist/bin/validateMockServerConfig/portSchema/portSchema.d.ts +2 -0
  64. package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -0
  65. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +8 -0
  66. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +12 -0
  67. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +713 -0
  68. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +23 -0
  69. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +77 -0
  70. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +52 -0
  71. package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.d.ts +14 -0
  72. package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +12 -0
  73. package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.d.ts +20 -0
  74. package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +14 -0
  75. package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.d.ts +5 -0
  76. package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +12 -0
  77. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +75 -0
  78. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +67 -0
  79. package/dist/bin/validateMockServerConfig/utils/index.d.ts +6 -0
  80. package/dist/bin/validateMockServerConfig/utils/index.js +71 -0
  81. package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.d.ts +8 -0
  82. package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +13 -0
  83. package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.d.ts +2 -0
  84. package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +11 -0
  85. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +3 -0
  86. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -0
  87. package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.d.ts +3 -0
  88. package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +9 -0
  89. package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.d.ts +2 -0
  90. package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +44 -0
  91. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +27 -20
  92. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +27 -16
  93. package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +64 -3
  94. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +1 -0
  95. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +46 -6
  96. package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +1 -0
  97. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +4 -0
  98. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +29 -0
  99. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +1 -0
  100. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +3 -4
  101. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +2 -2
  102. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +13 -7
  103. package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +7 -1
  104. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +27 -10
  105. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +6 -0
  106. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +1 -1
  107. package/dist/src/server/createRestMockServer/createRestMockServer.js +1 -1
  108. package/dist/src/static/views/components/header/index.js +1 -1
  109. package/dist/src/static/views/features/scheme/index.js +31 -31
  110. package/dist/src/static/views/features/tab/index.js +12 -12
  111. package/dist/src/utils/constants/appPath.js +1 -2
  112. package/dist/src/utils/constants/checkModes.d.ts +8 -9
  113. package/dist/src/utils/constants/checkModes.js +8 -16
  114. package/dist/src/utils/constants/default.js +2 -3
  115. package/dist/src/utils/helpers/files/index.d.ts +1 -0
  116. package/dist/src/utils/helpers/files/index.js +16 -0
  117. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.d.ts +1 -0
  118. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +19 -0
  119. package/dist/src/utils/helpers/index.d.ts +1 -0
  120. package/dist/src/utils/helpers/index.js +11 -0
  121. package/dist/src/utils/helpers/tests/createTmpDir.d.ts +1 -0
  122. package/dist/src/utils/helpers/tests/createTmpDir.js +12 -0
  123. package/dist/src/utils/helpers/tests/index.d.ts +1 -0
  124. package/dist/{bin/validateMockServerConfig/helpers/isCheckModeValid → src/utils/helpers/tests}/index.js +4 -4
  125. package/dist/src/utils/types/entities.d.ts +48 -0
  126. package/dist/src/utils/types/entities.js +1 -0
  127. package/dist/src/utils/types/graphql.d.ts +11 -45
  128. package/dist/src/utils/types/index.d.ts +1 -0
  129. package/dist/src/utils/types/index.js +11 -0
  130. package/dist/src/utils/types/rest.d.ts +17 -46
  131. package/dist/src/utils/types/server.d.ts +5 -4
  132. package/package.json +35 -27
  133. package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.d.ts +0 -1
  134. package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +0 -16
  135. package/dist/bin/validateMockServerConfig/helpers/index.d.ts +0 -2
  136. package/dist/bin/validateMockServerConfig/helpers/index.js +0 -27
  137. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.d.ts +0 -1
  138. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.d.ts +0 -1
  139. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +0 -12
  140. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.d.ts +0 -1
  141. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +0 -16
  142. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +0 -2
  143. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +0 -43
  144. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +0 -1
  145. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +0 -15
  146. package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +0 -1
  147. package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +0 -84
  148. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.d.ts +0 -1
  149. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.js +0 -45
  150. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +0 -1
  151. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +0 -58
  152. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +0 -2
  153. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +0 -153
  154. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +0 -1
  155. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +0 -27
  156. package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +0 -1
  157. package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +0 -12
  158. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.d.ts +0 -1
  159. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.js +0 -29
  160. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +0 -1
  161. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +0 -57
  162. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +0 -2
  163. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +0 -157
  164. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.d.ts +0 -1
  165. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.js +0 -34
  166. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +0 -1
  167. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +0 -53
  168. package/dist/src/core/database/createOrm/createOrm.d.ts +0 -4
  169. package/dist/src/core/database/createOrm/createOrm.js +0 -70
  170. package/dist/src/core/database/createStorage/createStorage.d.ts +0 -2
  171. package/dist/src/core/database/createStorage/createStorage.js +0 -10
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isCheckModeValid = void 0;
7
- var _constants = require("../../../../src/utils/constants");
8
- const isCheckModeValid = (checkMode, entityName) => {
9
- if (entityName === 'body' || entityName === 'variables') return _constants.PLAIN_ENTITY_CHECK_MODES.includes(checkMode);
10
- return _constants.CHECK_MODES.includes(checkMode);
11
- };
12
- exports.isCheckModeValid = isCheckModeValid;
@@ -1 +0,0 @@
1
- export * from './isDescriptorValueValid';
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _isDescriptorValueValid = require("./isDescriptorValueValid");
7
- Object.keys(_isDescriptorValueValid).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _isDescriptorValueValid[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _isDescriptorValueValid[key];
14
- }
15
- });
16
- });
@@ -1,2 +0,0 @@
1
- import type { CheckMode } from '../../../../src/utils/types';
2
- export declare const isDescriptorValueValid: (checkMode: CheckMode, value: unknown) => boolean | undefined;
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isDescriptorValueValid = void 0;
7
- var _constants = require("../../../../src/utils/constants");
8
- var _helpers = require("../../../../src/utils/helpers");
9
- // ✅ important:
10
- // should validate all properties over nesting
11
- const isObjectOrArrayValid = value => {
12
- if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' || value === null) {
13
- return true;
14
- }
15
- if (Array.isArray(value)) {
16
- return value.every(isObjectOrArrayValid);
17
- }
18
- if ((0, _helpers.isPlainObject)(value)) {
19
- for (const key in value) {
20
- if (!isObjectOrArrayValid(value[key])) {
21
- return false;
22
- }
23
- }
24
- return true;
25
- }
26
- return false;
27
- };
28
- const isDescriptorValueValid = (checkMode, value) => {
29
- if (_constants.CHECK_ACTUAL_VALUE_CHECK_MODES.includes(checkMode)) {
30
- return typeof value === 'undefined';
31
- }
32
- if (_constants.COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES.includes(checkMode)) {
33
- const isValueObjectOrArray = (0, _helpers.isPlainObject)(value) || Array.isArray(value);
34
- if (isValueObjectOrArray) return isObjectOrArrayValid(value);
35
- return typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' || value === null;
36
- }
37
- if (_constants.COMPARE_WITH_DESCRIPTOR_STRING_VALUE_CHECK_MODES.includes(checkMode)) {
38
- return typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string';
39
- }
40
- if (checkMode === 'function') return typeof value === 'function' && value.length <= 2;
41
- if (checkMode === 'regExp') return value instanceof RegExp;
42
- };
43
- exports.isDescriptorValueValid = isDescriptorValueValid;
@@ -1 +0,0 @@
1
- export declare const validateBaseUrl: (baseUrl: unknown) => void;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateBaseUrl = void 0;
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
- }
14
- };
15
- exports.validateBaseUrl = validateBaseUrl;
@@ -1 +0,0 @@
1
- export declare const validateCors: (cors: unknown) => void;
@@ -1,84 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateCors = void 0;
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
- }
24
- };
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
- }
41
- };
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
- }
55
- };
56
- const validateCredentials = credentials => {
57
- if (typeof credentials !== 'boolean' && typeof credentials !== 'undefined') {
58
- throw new Error('credentials');
59
- }
60
- };
61
- const validateMaxAge = maxAge => {
62
- if (typeof maxAge !== 'number' && typeof maxAge !== 'undefined') {
63
- throw new Error('maxAge');
64
- }
65
- };
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}`);
77
- }
78
- return;
79
- }
80
- if (typeof cors !== 'undefined') {
81
- throw new Error('cors');
82
- }
83
- };
84
- exports.validateCors = validateCors;
@@ -1 +0,0 @@
1
- export declare const validateDatabaseConfig: (databaseConfig: unknown) => void;
@@ -1,45 +0,0 @@
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 +0,0 @@
1
- export declare const validateGraphqlConfig: (graphqlConfig: unknown) => void;
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateGraphqlConfig = void 0;
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
- query
19
- } = config;
20
- if (typeof operationName === 'undefined' && typeof query === 'undefined') {
21
- throw new Error(`configs[${index}]`);
22
- }
23
- if (operationType !== 'query' && operationType !== 'mutation') {
24
- throw new Error(`configs[${index}].operationType`);
25
- }
26
- if (typeof operationName !== 'undefined' && typeof operationName !== 'string' && !(operationName instanceof RegExp)) {
27
- throw new Error(`configs[${index}].operationName`);
28
- }
29
- if (typeof query !== 'undefined' && typeof query !== 'string') {
30
- throw new Error(`configs[${index}].query`);
31
- }
32
- try {
33
- (0, _validateRoutes.validateRoutes)(config.routes, operationType);
34
- (0, _validateInterceptors.validateInterceptors)(config.interceptors);
35
- } catch (error) {
36
- throw new Error(`configs[${index}].${error.message}`);
37
- }
38
- });
39
- return;
40
- }
41
- throw new Error('configs');
42
- };
43
- const validateGraphqlConfig = graphqlConfig => {
44
- const isGraphqlConfigObject = (0, _helpers.isPlainObject)(graphqlConfig);
45
- if (isGraphqlConfigObject) {
46
- try {
47
- (0, _validateBaseUrl.validateBaseUrl)(graphqlConfig.baseUrl);
48
- validateConfigs(graphqlConfig.configs);
49
- } catch (error) {
50
- throw new Error(`graphql.${error.message}`);
51
- }
52
- return;
53
- }
54
- if (typeof graphqlConfig !== 'undefined') {
55
- throw new Error('graphql');
56
- }
57
- };
58
- exports.validateGraphqlConfig = validateGraphqlConfig;
@@ -1,2 +0,0 @@
1
- import type { GraphQLOperationType } from '../../../../src/utils/types';
2
- export declare const validateRoutes: (routes: unknown, operationType: GraphQLOperationType) => void;
@@ -1,153 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateRoutes = void 0;
7
- var _helpers = require("../../../../src/utils/helpers");
8
- var _helpers2 = require("../../helpers");
9
- var _validateInterceptors = require("../../validateInterceptors/validateInterceptors");
10
- var _validateQueue = require("../../validateQueue/validateQueue");
11
- var _validateSettings = require("../../validateSettings/validateSettings");
12
- const ALLOWED_ENTITIES_BY_OPERATION_TYPE = {
13
- query: ['headers', 'cookies', 'query', 'variables'],
14
- mutation: ['headers', 'cookies', 'query', 'variables']
15
- };
16
- const validateEntity = (entity, entityName) => {
17
- const isVariables = entityName === 'variables';
18
- const isEntityTopLevelDescriptor = (0, _helpers.isEntityDescriptor)(entity);
19
- if (isEntityTopLevelDescriptor) {
20
- if (!isVariables) {
21
- throw new Error(entityName);
22
- }
23
- if (!(0, _helpers2.isCheckModeValid)(entity.checkMode, 'variables')) {
24
- throw new Error('variables.checkMode');
25
- }
26
- const isDescriptorValueObjectOrArray = (0, _helpers.isPlainObject)(entity.value) || Array.isArray(entity.value);
27
- if (!isDescriptorValueObjectOrArray || !(0, _helpers2.isDescriptorValueValid)(entity.checkMode, entity.value)) {
28
- throw new Error('variables.value');
29
- }
30
- return;
31
- }
32
- const isEntityArray = Array.isArray(entity);
33
- if (isEntityArray) {
34
- if (!isVariables) {
35
- throw new Error(entityName);
36
- }
37
- entity.forEach((entityElement, index) => {
38
- const isEntityElementObjectOrArray = (0, _helpers.isPlainObject)(entityElement) || Array.isArray(entityElement);
39
- if (!isEntityElementObjectOrArray || !(0, _helpers2.isDescriptorValueValid)('equals', entityElement)) {
40
- throw new Error(`${entityName}[${index}]`);
41
- }
42
- });
43
- return;
44
- }
45
- const isEntityObject = (0, _helpers.isPlainObject)(entity);
46
- if (isEntityObject) {
47
- Object.entries(entity).forEach(([key, valueOrDescriptor]) => {
48
- const {
49
- checkMode,
50
- value
51
- } = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
52
- if (!(0, _helpers2.isCheckModeValid)(checkMode)) {
53
- throw new Error(`${entityName}.${key}.checkMode`);
54
- }
55
- const isDescriptor = (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
56
- const errorMessage = `${entityName}.${key}${isDescriptor ? '.value' : ''}`;
57
- const isValueArray = Array.isArray(value);
58
- if (isValueArray) {
59
- value.forEach((element, index) => {
60
- if (isVariables) {
61
- if ((0, _helpers2.isDescriptorValueValid)(checkMode, element)) return;
62
- throw new Error(`${errorMessage}[${index}]`);
63
- }
64
- const isElementObjectOrArray = (0, _helpers.isPlainObject)(element) || Array.isArray(element);
65
- if (isElementObjectOrArray || !(0, _helpers2.isDescriptorValueValid)(checkMode, element)) {
66
- throw new Error(`${errorMessage}[${index}]`);
67
- }
68
- });
69
- return;
70
- }
71
- if (isVariables) {
72
- if ((0, _helpers2.isDescriptorValueValid)(checkMode, value)) return;
73
- throw new Error(errorMessage);
74
- }
75
- const isValueObject = (0, _helpers.isPlainObject)(value);
76
- if (isValueObject || !(0, _helpers2.isDescriptorValueValid)(checkMode, value)) {
77
- throw new Error(errorMessage);
78
- }
79
- });
80
- return;
81
- }
82
- throw new Error(entityName);
83
- };
84
- const validateEntities = (entities, operationType) => {
85
- const isEntitiesObject = (0, _helpers.isPlainObject)(entities);
86
- if (isEntitiesObject) {
87
- Object.keys(entities).forEach(entityName => {
88
- const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entityName);
89
- if (!isEntityAllowed) {
90
- throw new Error(`entities.${entityName}`);
91
- }
92
- try {
93
- validateEntity(entities[entityName], entityName);
94
- } catch (error) {
95
- throw new Error(`entities.${error.message}`);
96
- }
97
- });
98
- return;
99
- }
100
- if (typeof entities !== 'undefined') {
101
- throw new Error('entities');
102
- }
103
- };
104
- const validateRoutes = (routes, operationType) => {
105
- const isRoutesArray = Array.isArray(routes);
106
- if (isRoutesArray) {
107
- routes.forEach((route, index) => {
108
- const isRouteObject = (0, _helpers.isPlainObject)(route);
109
- if (isRouteObject) {
110
- const isRouteHasDataProperty = ('data' in route);
111
- const isRouteHasQueueProperty = ('queue' in route);
112
- if (!isRouteHasDataProperty && !isRouteHasQueueProperty) {
113
- throw new Error(`routes[${index}]`);
114
- }
115
- if (isRouteHasDataProperty && isRouteHasQueueProperty) {
116
- throw new Error(`routes[${index}]`);
117
- }
118
- const {
119
- settings
120
- } = route;
121
- const isRouteSettingsObject = (0, _helpers.isPlainObject)(settings);
122
- if (isRouteHasQueueProperty) {
123
- try {
124
- (0, _validateQueue.validateQueue)(route.queue);
125
- if (!isRouteSettingsObject) {
126
- throw new Error('settings');
127
- }
128
- if (!(isRouteSettingsObject && settings !== null && settings !== void 0 && settings.polling)) {
129
- throw new Error('settings.polling');
130
- }
131
- } catch (error) {
132
- throw new Error(`routes[${index}].${error.message}`);
133
- }
134
- }
135
- if (isRouteHasDataProperty && isRouteSettingsObject && settings !== null && settings !== void 0 && settings.polling) {
136
- throw new Error(`routes[${index}].settings.polling`);
137
- }
138
- try {
139
- (0, _validateSettings.validateSettings)(route.settings);
140
- validateEntities(route.entities, operationType);
141
- (0, _validateInterceptors.validateInterceptors)(route.interceptors);
142
- } catch (error) {
143
- throw new Error(`routes[${index}].${error.message}`);
144
- }
145
- return;
146
- }
147
- throw new Error(`routes[${index}]`);
148
- });
149
- return;
150
- }
151
- throw new Error('routes');
152
- };
153
- exports.validateRoutes = validateRoutes;
@@ -1 +0,0 @@
1
- export declare const validateInterceptors: (interceptors: unknown) => void;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateInterceptors = void 0;
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');
17
- }
18
- if (typeof response !== 'function' && typeof response !== 'undefined') {
19
- throw new Error('interceptors.response');
20
- }
21
- return;
22
- }
23
- if (typeof interceptors !== 'undefined') {
24
- throw new Error('interceptors');
25
- }
26
- };
27
- exports.validateInterceptors = validateInterceptors;
@@ -1 +0,0 @@
1
- export declare const validatePort: (port: unknown) => void;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validatePort = void 0;
7
- const validatePort = port => {
8
- if (typeof port !== 'number' && typeof port !== 'undefined') {
9
- throw new Error('port');
10
- }
11
- };
12
- exports.validatePort = validatePort;
@@ -1 +0,0 @@
1
- export declare const validateQueue: (queue: unknown) => void;
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateQueue = void 0;
7
- var _helpers = require("../../../src/utils/helpers");
8
- const validateQueue = queue => {
9
- const isQueueArray = Array.isArray(queue);
10
- if (!isQueueArray) {
11
- throw new Error('queue');
12
- }
13
- queue.forEach((queueElement, index) => {
14
- const isQueueElementObject = (0, _helpers.isPlainObject)(queueElement);
15
- if (isQueueElementObject) {
16
- const isQueueElementDataProperty = ('data' in queueElement);
17
- if (!isQueueElementDataProperty) {
18
- throw new Error(`queue[${index}].data`);
19
- }
20
- const isQueueElementTimeProperty = ('time' in queueElement);
21
- if (isQueueElementTimeProperty && typeof queueElement.time !== 'number') {
22
- throw new Error(`queue[${index}].time`);
23
- }
24
- return;
25
- }
26
- throw new Error(`queue[${index}]`);
27
- });
28
- };
29
- exports.validateQueue = validateQueue;
@@ -1 +0,0 @@
1
- export declare const validateRestConfig: (restConfig: unknown) => void;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateRestConfig = void 0;
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
- path,
17
- method
18
- } = config;
19
- const isPathStringWithLeadingSlash = typeof path === 'string' && path.startsWith('/');
20
- if (!isPathStringWithLeadingSlash && !(path instanceof RegExp)) {
21
- throw new Error(`configs[${index}].path`);
22
- }
23
-
24
- // ✅ important:
25
- // compare without 'toLowerCase' because Express methods names is case-sensitive
26
- const allowedMethods = ['get', 'post', 'delete', 'put', 'patch', 'options'];
27
- const isMethodAllowed = typeof method === 'string' && allowedMethods.includes(method);
28
- if (!isMethodAllowed) {
29
- throw new Error(`configs[${index}].method`);
30
- }
31
- try {
32
- (0, _validateRoutes.validateRoutes)(config.routes, method);
33
- (0, _validateInterceptors.validateInterceptors)(config.interceptors);
34
- } catch (error) {
35
- throw new Error(`configs[${index}].${error.message}`);
36
- }
37
- });
38
- return;
39
- }
40
- throw new Error('configs');
41
- };
42
- const validateRestConfig = restConfig => {
43
- const isRestConfigObject = (0, _helpers.isPlainObject)(restConfig);
44
- if (isRestConfigObject) {
45
- try {
46
- (0, _validateBaseUrl.validateBaseUrl)(restConfig.baseUrl);
47
- validateConfigs(restConfig.configs);
48
- } catch (error) {
49
- throw new Error(`rest.${error.message}`);
50
- }
51
- return;
52
- }
53
- if (typeof restConfig !== 'undefined') {
54
- throw new Error('rest');
55
- }
56
- };
57
- exports.validateRestConfig = validateRestConfig;
@@ -1,2 +0,0 @@
1
- import type { RestMethod } from '../../../../src/utils/types';
2
- export declare const validateRoutes: (routes: unknown, method: RestMethod) => void;