mock-config-server 3.4.1 → 3.6.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 (148) hide show
  1. package/README.md +2 -0
  2. package/dist/bin/bin.js +3 -6
  3. package/dist/bin/build.js +52 -50
  4. package/dist/bin/cli.js +50 -43
  5. package/dist/bin/helpers/createTemplate.js +29 -21
  6. package/dist/bin/helpers/getMostSpecificPathFromError.js +34 -30
  7. package/dist/bin/helpers/getValidationMessageFromPath.js +11 -8
  8. package/dist/bin/helpers/index.js +21 -79
  9. package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +13 -6
  10. package/dist/bin/helpers/resolveConfigFile.js +22 -19
  11. package/dist/bin/helpers/resolveConfigFilePath.js +19 -12
  12. package/dist/bin/helpers/resolveExportsFromSourceCode.js +13 -10
  13. package/dist/bin/init.js +114 -97
  14. package/dist/bin/run.js +42 -43
  15. package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +9 -5
  16. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.d.ts +2 -2
  17. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +32 -14
  18. package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +19 -9
  19. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +82 -72
  20. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +38 -22
  21. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +25 -21
  22. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +36 -28
  23. package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +12 -8
  24. package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -5
  25. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +2 -2
  26. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +18 -9
  27. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +270 -240
  28. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +33 -19
  29. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +33 -28
  30. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +60 -48
  31. package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +13 -9
  32. package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +19 -9
  33. package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +27 -9
  34. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +4 -8
  35. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +117 -60
  36. package/dist/bin/validateMockServerConfig/utils/index.js +20 -68
  37. package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +30 -10
  38. package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +9 -8
  39. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +1 -1
  40. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -7
  41. package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +18 -6
  42. package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +43 -40
  43. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +38 -35
  44. package/dist/index.js +15 -13
  45. package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +25 -28
  46. package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +14 -11
  47. package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js +8 -5
  48. package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.js +17 -35
  49. package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.js +8 -5
  50. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +159 -143
  51. package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.js +15 -8
  52. package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +90 -94
  53. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +49 -46
  54. package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +19 -57
  55. package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +32 -31
  56. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +34 -24
  57. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +37 -33
  58. package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +26 -25
  59. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +65 -50
  60. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +55 -48
  61. package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +51 -41
  62. package/dist/src/core/database/createDatabaseRoutes/storages/index.js +16 -24
  63. package/dist/src/core/database/index.js +15 -13
  64. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +131 -140
  65. package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +15 -13
  66. package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +36 -41
  67. package/dist/src/core/graphql/index.js +15 -13
  68. package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -13
  69. package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +15 -13
  70. package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +18 -15
  71. package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +50 -47
  72. package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +17 -12
  73. package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +15 -13
  74. package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -20
  75. package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +23 -17
  76. package/dist/src/core/middlewares/index.js +23 -91
  77. package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +22 -19
  78. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +21 -23
  79. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +80 -80
  80. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -34
  81. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +8 -5
  82. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +8 -5
  83. package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +16 -24
  84. package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +17 -35
  85. package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +58 -60
  86. package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +16 -17
  87. package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +32 -25
  88. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +125 -130
  89. package/dist/src/core/rest/createRestRoutes/helpers/index.js +15 -13
  90. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +37 -43
  91. package/dist/src/core/rest/index.js +15 -13
  92. package/dist/src/index.js +16 -24
  93. package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +56 -53
  94. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +64 -62
  95. package/dist/src/server/createMockServer/createMockServer.js +94 -91
  96. package/dist/src/server/createRestMockServer/createRestMockServer.js +64 -62
  97. package/dist/src/server/index.js +23 -91
  98. package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +25 -19
  99. package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +25 -19
  100. package/dist/src/server/startMockServer/startMockServer.js +25 -19
  101. package/dist/src/server/startRestMockServer/startRestMockServer.js +25 -19
  102. package/dist/src/utils/constants/appPath.js +8 -4
  103. package/dist/src/utils/constants/checkModes.js +74 -11
  104. package/dist/src/utils/constants/default.js +18 -14
  105. package/dist/src/utils/constants/index.js +17 -35
  106. package/dist/src/utils/helpers/asyncHandler.js +8 -5
  107. package/dist/src/utils/helpers/config/index.js +15 -13
  108. package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +103 -110
  109. package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +12 -9
  110. package/dist/src/utils/helpers/entities/index.js +16 -24
  111. package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +9 -6
  112. package/dist/src/utils/helpers/files/index.js +15 -13
  113. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +22 -15
  114. package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +25 -29
  115. package/dist/src/utils/helpers/graphql/index.js +17 -35
  116. package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +13 -10
  117. package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +23 -19
  118. package/dist/src/utils/helpers/index.js +26 -124
  119. package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +21 -21
  120. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +62 -64
  121. package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +10 -7
  122. package/dist/src/utils/helpers/interceptors/index.js +16 -24
  123. package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +8 -5
  124. package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +8 -5
  125. package/dist/src/utils/helpers/isRegExp/isRegExp.js +8 -5
  126. package/dist/src/utils/helpers/sleep.js +9 -6
  127. package/dist/src/utils/helpers/tests/createTmpDir.js +16 -9
  128. package/dist/src/utils/helpers/tests/index.js +15 -13
  129. package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -5
  130. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +9 -6
  131. package/dist/src/utils/helpers/url/index.js +18 -46
  132. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +8 -5
  133. package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +18 -11
  134. package/dist/src/utils/types/checkModes.js +4 -1
  135. package/dist/src/utils/types/database.js +4 -1
  136. package/dist/src/utils/types/entities.js +4 -1
  137. package/dist/src/utils/types/graphql.d.ts +1 -1
  138. package/dist/src/utils/types/graphql.js +4 -1
  139. package/dist/src/utils/types/index.js +24 -102
  140. package/dist/src/utils/types/interceptors.js +4 -1
  141. package/dist/src/utils/types/rest.d.ts +1 -1
  142. package/dist/src/utils/types/rest.js +4 -1
  143. package/dist/src/utils/types/server.js +4 -1
  144. package/dist/src/utils/types/utils.js +4 -1
  145. package/dist/src/utils/types/values.js +4 -1
  146. package/package.json +26 -29
  147. package/dist/bin/templates/.eslintrc.js +0 -14
  148. package/dist/bin/templates/tsconfig.json +0 -11
@@ -1,71 +1,23 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- var _checkModeSchema = require("./checkModeSchema/checkModeSchema");
7
- Object.keys(_checkModeSchema).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _checkModeSchema[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _checkModeSchema[key];
14
- }
15
- });
16
- });
17
- var _entitiesSchema = require("./entitiesSchema/entitiesSchema");
18
- Object.keys(_entitiesSchema).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _entitiesSchema[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _entitiesSchema[key];
25
- }
26
- });
27
- });
28
- var _jsonSchema = require("./jsonSchema/jsonSchema");
29
- Object.keys(_jsonSchema).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _jsonSchema[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _jsonSchema[key];
36
- }
37
- });
38
- });
39
- var _plainObjectSchema = require("./plainObjectSchema/plainObjectSchema");
40
- Object.keys(_plainObjectSchema).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _plainObjectSchema[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _plainObjectSchema[key];
47
- }
48
- });
49
- });
50
- var _requiredPropertiesSchema = require("./requiredPropertiesSchema/requiredPropertiesSchema");
51
- Object.keys(_requiredPropertiesSchema).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _requiredPropertiesSchema[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _requiredPropertiesSchema[key];
58
- }
59
- });
60
- });
61
- var _sharedSchema = require("./sharedSchema/sharedSchema");
62
- Object.keys(_sharedSchema).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _sharedSchema[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _sharedSchema[key];
69
- }
70
- });
71
- });
5
+ _export_star(require("./checkModeSchema/checkModeSchema"), exports);
6
+ _export_star(require("./entitiesSchema/entitiesSchema"), exports);
7
+ _export_star(require("./jsonSchema/jsonSchema"), exports);
8
+ _export_star(require("./plainObjectSchema/plainObjectSchema"), exports);
9
+ _export_star(require("./requiredPropertiesSchema/requiredPropertiesSchema"), exports);
10
+ _export_star(require("./sharedSchema/sharedSchema"), exports);
11
+ function _export_star(from, to) {
12
+ Object.keys(from).forEach(function(k) {
13
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
14
+ Object.defineProperty(to, k, {
15
+ enumerable: true,
16
+ get: function() {
17
+ return from[k];
18
+ }
19
+ });
20
+ }
21
+ });
22
+ return from;
23
+ }
@@ -1,13 +1,33 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.jsonSchema = exports.jsonLiteralSchema = void 0;
7
- var _zod = require("zod");
8
- var _helpers = require("../../../../src/utils/helpers");
9
- const jsonLiteralSchema = exports.jsonLiteralSchema = _zod.z.union([_zod.z.string(), _zod.z.number(), _zod.z.boolean(), _zod.z.null()]);
10
- const jsonSchema = exports.jsonSchema = _zod.z.lazy(() => _zod.z.union([jsonLiteralSchema, _zod.z.array(jsonSchema),
11
- // ✅ important:
12
- // using 'and' checking instead of 'plainObjectSchema' because of zod types peculiarities
13
- _zod.z.record(jsonSchema).and(_zod.z.custom(value => (0, _helpers.isPlainObject)(value)))]));
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ jsonLiteralSchema: function() {
13
+ return jsonLiteralSchema;
14
+ },
15
+ jsonSchema: function() {
16
+ return jsonSchema;
17
+ }
18
+ });
19
+ const _zod = require("zod");
20
+ const _helpers = require("../../../../src/utils/helpers");
21
+ const jsonLiteralSchema = _zod.z.union([
22
+ _zod.z.string(),
23
+ _zod.z.number(),
24
+ _zod.z.boolean(),
25
+ _zod.z.null()
26
+ ]);
27
+ const jsonSchema = _zod.z.lazy(()=>_zod.z.union([
28
+ jsonLiteralSchema,
29
+ _zod.z.array(jsonSchema),
30
+ // ✅ important:
31
+ // using 'and' checking instead of 'plainObjectSchema' because of zod types peculiarities
32
+ _zod.z.record(jsonSchema).and(_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value)))
33
+ ]));
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.plainObjectSchema = void 0;
7
- var _zod = require("zod");
8
- // important:
9
- // this schema is needed because zod handle RegExps as plain object
10
- const plainObjectSchema = schema => _zod.z.custom(value => !(value instanceof RegExp)).pipe(schema);
11
- exports.plainObjectSchema = plainObjectSchema;
5
+ Object.defineProperty(exports, "plainObjectSchema", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return plainObjectSchema;
9
+ }
10
+ });
11
+ const _zod = require("zod");
12
+ const plainObjectSchema = (schema)=>_zod.z.custom((value)=>!(value instanceof RegExp)).pipe(schema);
@@ -1,3 +1,3 @@
1
1
  import { z } from 'zod';
2
2
  import type { PlainObject } from '../../../../src/utils/types';
3
- export declare const requiredPropertiesSchema: <T extends PlainObject>(schema: z.ZodType<T, z.ZodTypeDef, T>, requiredProperties: (keyof T)[]) => z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodType<T, z.ZodTypeDef, T>>;
3
+ export declare const requiredPropertiesSchema: <T extends PlainObject>(schema: z.ZodType<T>, requiredProperties: (keyof T)[]) => z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodType<T, z.ZodTypeDef, T>>;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.requiredPropertiesSchema = void 0;
7
- var _zod = require("zod");
8
- var _helpers = require("../../../../src/utils/helpers");
9
- const requiredPropertiesSchema = (schema, requiredProperties) => _zod.z.custom(value => (0, _helpers.isPlainObject)(value) && requiredProperties.every(property => Object.prototype.hasOwnProperty.call(value, property))).pipe(schema);
10
- exports.requiredPropertiesSchema = requiredPropertiesSchema;
5
+ Object.defineProperty(exports, "requiredPropertiesSchema", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return requiredPropertiesSchema;
9
+ }
10
+ });
11
+ const _zod = require("zod");
12
+ const _helpers = require("../../../../src/utils/helpers");
13
+ const requiredPropertiesSchema = (schema, requiredProperties)=>_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && requiredProperties.every((property)=>Object.prototype.hasOwnProperty.call(value, property))).pipe(schema);
@@ -1,9 +1,21 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.stringJsonFilenameSchema = exports.stringForwardSlashSchema = void 0;
7
- var _zod = require("zod");
8
- const stringForwardSlashSchema = exports.stringForwardSlashSchema = _zod.z.string().startsWith('/');
9
- const stringJsonFilenameSchema = exports.stringJsonFilenameSchema = _zod.z.string().endsWith('.json');
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ stringForwardSlashSchema: function() {
13
+ return stringForwardSlashSchema;
14
+ },
15
+ stringJsonFilenameSchema: function() {
16
+ return stringJsonFilenameSchema;
17
+ }
18
+ });
19
+ const _zod = require("zod");
20
+ const stringForwardSlashSchema = _zod.z.string().startsWith('/');
21
+ const stringJsonFilenameSchema = _zod.z.string().endsWith('.json');
@@ -1,44 +1,47 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.validateApiMockServerConfig = void 0;
7
- var _zod = require("zod");
8
- var _helpers = require("../helpers");
9
- var _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
10
- var _corsSchema = require("./corsSchema/corsSchema");
11
- var _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
12
- var _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
13
- var _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
14
- var _portSchema = require("./portSchema/portSchema");
15
- var _restConfigSchema = require("./restConfigSchema/restConfigSchema");
16
- var _staticPathSchema = require("./staticPathSchema/staticPathSchema");
17
- var _utils = require("./utils");
18
- const validateApiMockServerConfig = (mockServerConfig, api) => {
19
- if (!mockServerConfig.configs && !mockServerConfig.database && !mockServerConfig.staticPath) {
20
- throw new Error('Configuration should contain at least one of these configs: configs | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information');
21
- }
22
- const isConfigsContainAtLeastOneElement = Array.isArray(mockServerConfig.configs) && !!mockServerConfig.configs.length;
23
- const mockServerConfigSchema = _zod.z.strictObject({
24
- baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
25
- port: _portSchema.portSchema.optional(),
26
- staticPath: _staticPathSchema.staticPathSchema.optional(),
27
- interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
28
- cors: _corsSchema.corsSchema.optional(),
29
- database: _databaseConfigSchema.databaseConfigSchema.optional(),
30
- ...(isConfigsContainAtLeastOneElement && api === 'graphql' && {
31
- configs: _graphqlConfigSchema.graphqlConfigSchema.shape.configs
32
- }),
33
- ...(isConfigsContainAtLeastOneElement && api === 'rest' && {
34
- configs: _restConfigSchema.restConfigSchema.shape.configs
35
- })
36
- });
37
- const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
38
- if (!validationResult.success) {
39
- const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
40
- const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
41
- throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
42
- }
5
+ Object.defineProperty(exports, "validateApiMockServerConfig", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return validateApiMockServerConfig;
9
+ }
10
+ });
11
+ const _zod = require("zod");
12
+ const _helpers = require("../helpers");
13
+ const _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
14
+ const _corsSchema = require("./corsSchema/corsSchema");
15
+ const _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
16
+ const _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
17
+ const _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
18
+ const _portSchema = require("./portSchema/portSchema");
19
+ const _restConfigSchema = require("./restConfigSchema/restConfigSchema");
20
+ const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
21
+ const _utils = require("./utils");
22
+ const validateApiMockServerConfig = (mockServerConfig, api)=>{
23
+ if (!mockServerConfig.configs && !mockServerConfig.database && !mockServerConfig.staticPath) {
24
+ throw new Error('Configuration should contain at least one of these configs: configs | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information');
25
+ }
26
+ const isConfigsContainAtLeastOneElement = Array.isArray(mockServerConfig.configs) && !!mockServerConfig.configs.length;
27
+ const mockServerConfigSchema = _zod.z.strictObject({
28
+ baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
29
+ port: _portSchema.portSchema.optional(),
30
+ staticPath: _staticPathSchema.staticPathSchema.optional(),
31
+ interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
32
+ cors: _corsSchema.corsSchema.optional(),
33
+ database: _databaseConfigSchema.databaseConfigSchema.optional(),
34
+ ...isConfigsContainAtLeastOneElement && api === 'graphql' && {
35
+ configs: _graphqlConfigSchema.graphqlConfigSchema.shape.configs
36
+ },
37
+ ...isConfigsContainAtLeastOneElement && api === 'rest' && {
38
+ configs: _restConfigSchema.restConfigSchema.shape.configs
39
+ }
40
+ });
41
+ const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
42
+ if (!validationResult.success) {
43
+ const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
44
+ const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
45
+ throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
46
+ }
43
47
  };
44
- exports.validateApiMockServerConfig = validateApiMockServerConfig;
@@ -1,39 +1,42 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.validateMockServerConfig = void 0;
7
- var _zod = require("zod");
8
- var _helpers = require("../helpers");
9
- var _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
10
- var _corsSchema = require("./corsSchema/corsSchema");
11
- var _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
12
- var _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
13
- var _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
14
- var _portSchema = require("./portSchema/portSchema");
15
- var _restConfigSchema = require("./restConfigSchema/restConfigSchema");
16
- var _staticPathSchema = require("./staticPathSchema/staticPathSchema");
17
- var _utils = require("./utils");
18
- const validateMockServerConfig = mockServerConfig => {
19
- if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database && !mockServerConfig.staticPath) {
20
- throw new Error('Configuration should contain at least one of these configs: rest | graphql | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information');
21
- }
22
- const mockServerConfigSchema = _zod.z.strictObject({
23
- baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
24
- port: _portSchema.portSchema.optional(),
25
- staticPath: _staticPathSchema.staticPathSchema.optional(),
26
- interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
27
- cors: _corsSchema.corsSchema.optional(),
28
- rest: _restConfigSchema.restConfigSchema.optional(),
29
- graphql: _graphqlConfigSchema.graphqlConfigSchema.optional(),
30
- database: _databaseConfigSchema.databaseConfigSchema.optional()
31
- });
32
- const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
33
- if (!validationResult.success) {
34
- const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
35
- const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
36
- throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
37
- }
5
+ Object.defineProperty(exports, "validateMockServerConfig", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return validateMockServerConfig;
9
+ }
10
+ });
11
+ const _zod = require("zod");
12
+ const _helpers = require("../helpers");
13
+ const _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
14
+ const _corsSchema = require("./corsSchema/corsSchema");
15
+ const _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
16
+ const _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
17
+ const _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
18
+ const _portSchema = require("./portSchema/portSchema");
19
+ const _restConfigSchema = require("./restConfigSchema/restConfigSchema");
20
+ const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
21
+ const _utils = require("./utils");
22
+ const validateMockServerConfig = (mockServerConfig)=>{
23
+ if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database && !mockServerConfig.staticPath) {
24
+ throw new Error('Configuration should contain at least one of these configs: rest | graphql | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information');
25
+ }
26
+ const mockServerConfigSchema = _zod.z.strictObject({
27
+ baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
28
+ port: _portSchema.portSchema.optional(),
29
+ staticPath: _staticPathSchema.staticPathSchema.optional(),
30
+ interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
31
+ cors: _corsSchema.corsSchema.optional(),
32
+ rest: _restConfigSchema.restConfigSchema.optional(),
33
+ graphql: _graphqlConfigSchema.graphqlConfigSchema.optional(),
34
+ database: _databaseConfigSchema.databaseConfigSchema.optional()
35
+ });
36
+ const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
37
+ if (!validationResult.success) {
38
+ const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
39
+ const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
40
+ throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
41
+ }
38
42
  };
39
- exports.validateMockServerConfig = validateMockServerConfig;
package/dist/index.js CHANGED
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- var _src = require("./src");
7
- Object.keys(_src).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _src[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _src[key];
14
- }
15
- });
16
- });
5
+ _export_star(require("./src"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -1,33 +1,30 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.createDatabaseRoutes = void 0;
7
- var _helpers = require("./helpers");
8
- var _storages = require("./storages");
9
- const isVariableJsonFile = variable => typeof variable === 'string' && variable.endsWith('.json');
10
- const createDatabaseRoutes = (router, {
11
- data,
12
- routes
13
- }) => {
14
- if (routes) {
15
- const storage = isVariableJsonFile(routes) ? new _storages.FileStorage(routes) : new _storages.MemoryStorage(routes);
16
- (0, _helpers.createRewrittenDatabaseRoutes)(router, storage.read());
17
- router.route('/__routes').get((_request, response) => {
18
- response.json(storage.read());
5
+ Object.defineProperty(exports, "createDatabaseRoutes", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createDatabaseRoutes;
9
+ }
10
+ });
11
+ const _helpers = require("./helpers");
12
+ const _storages = require("./storages");
13
+ const isVariableJsonFile = (variable)=>typeof variable === 'string' && variable.endsWith('.json');
14
+ const createDatabaseRoutes = (router, { data, routes })=>{
15
+ if (routes) {
16
+ const storage = isVariableJsonFile(routes) ? new _storages.FileStorage(routes) : new _storages.MemoryStorage(routes);
17
+ (0, _helpers.createRewrittenDatabaseRoutes)(router, storage.read());
18
+ router.route('/__routes').get((_request, response)=>{
19
+ response.json(storage.read());
20
+ });
21
+ }
22
+ const storage = isVariableJsonFile(data) ? new _storages.FileStorage(data) : new _storages.MemoryStorage(data);
23
+ const { shallowDatabase, nestedDatabase } = (0, _helpers.splitDatabaseByNesting)(storage.read());
24
+ (0, _helpers.createShallowDatabaseRoutes)(router, shallowDatabase, storage);
25
+ (0, _helpers.createNestedDatabaseRoutes)(router, nestedDatabase, storage);
26
+ router.route('/__db').get((_request, response)=>{
27
+ response.json(storage.read());
19
28
  });
20
- }
21
- const storage = isVariableJsonFile(data) ? new _storages.FileStorage(data) : new _storages.MemoryStorage(data);
22
- const {
23
- shallowDatabase,
24
- nestedDatabase
25
- } = (0, _helpers.splitDatabaseByNesting)(storage.read());
26
- (0, _helpers.createShallowDatabaseRoutes)(router, shallowDatabase, storage);
27
- (0, _helpers.createNestedDatabaseRoutes)(router, nestedDatabase, storage);
28
- router.route('/__db').get((_request, response) => {
29
- response.json(storage.read());
30
- });
31
- return router;
29
+ return router;
32
30
  };
33
- exports.createDatabaseRoutes = createDatabaseRoutes;
@@ -1,16 +1,19 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.createNewId = void 0;
7
- const createNewId = array => {
8
- let maxId = -1;
9
- for (let i = 0; i < array.length; i += 1) {
10
- if (typeof array[i].id === 'number' && array[i].id > maxId) {
11
- maxId = array[i].id;
5
+ Object.defineProperty(exports, "createNewId", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createNewId;
12
9
  }
13
- }
14
- return maxId + 1;
10
+ });
11
+ const createNewId = (array)=>{
12
+ let maxId = -1;
13
+ for(let i = 0; i < array.length; i += 1){
14
+ if (typeof array[i].id === 'number' && array[i].id > maxId) {
15
+ maxId = array[i].id;
16
+ }
17
+ }
18
+ return maxId + 1;
15
19
  };
16
- exports.createNewId = createNewId;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.findIndexById = void 0;
7
- const findIndexById = (array, id) => array.findIndex(item => item.id.toString() === id.toString());
8
- exports.findIndexById = findIndexById;
5
+ Object.defineProperty(exports, "findIndexById", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return findIndexById;
9
+ }
10
+ });
11
+ const findIndexById = (array, id)=>array.findIndex((item)=>item.id.toString() === id.toString());
@@ -1,38 +1,20 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- var _createNewId = require("./createNewId/createNewId");
7
- Object.keys(_createNewId).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _createNewId[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _createNewId[key];
14
- }
15
- });
16
- });
17
- var _findIndexById = require("./findIndexById/findIndexById");
18
- Object.keys(_findIndexById).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _findIndexById[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _findIndexById[key];
25
- }
26
- });
27
- });
28
- var _isIndex = require("./isIndex/isIndex");
29
- Object.keys(_isIndex).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _isIndex[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _isIndex[key];
36
- }
37
- });
38
- });
5
+ _export_star(require("./createNewId/createNewId"), exports);
6
+ _export_star(require("./findIndexById/findIndexById"), exports);
7
+ _export_star(require("./isIndex/isIndex"), exports);
8
+ function _export_star(from, to) {
9
+ Object.keys(from).forEach(function(k) {
10
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
+ Object.defineProperty(to, k, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return from[k];
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return from;
20
+ }
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.isIndex = void 0;
7
- const isIndex = value => Number.isInteger(value) && value >= 0;
8
- exports.isIndex = isIndex;
5
+ Object.defineProperty(exports, "isIndex", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return isIndex;
9
+ }
10
+ });
11
+ const isIndex = (value)=>Number.isInteger(value) && value >= 0;