mock-config-server 4.0.2 → 5.0.0-beta.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 (173) hide show
  1. package/README.md +229 -237
  2. package/dist/bin/build.d.ts +3 -3
  3. package/dist/bin/build.js +1 -11
  4. package/dist/bin/helpers/createTemplate.js +6 -6
  5. package/dist/bin/helpers/resolveConfigFile.d.ts +2 -2
  6. package/dist/bin/helpers/resolveConfigFile.js +2 -3
  7. package/dist/bin/helpers/resolveConfigFilePath.js +4 -4
  8. package/dist/bin/init.d.ts +2 -2
  9. package/dist/bin/init.js +7 -7
  10. package/dist/bin/run.d.ts +3 -3
  11. package/dist/bin/run.js +17 -24
  12. package/dist/bin/templates/js/full/mock-requests/graphql/index.js +2 -2
  13. package/dist/bin/templates/js/full/mock-requests/graphql/user.js +35 -35
  14. package/dist/bin/templates/js/full/mock-requests/graphql/users.js +12 -12
  15. package/dist/bin/templates/js/full/mock-requests/rest/index.js +2 -2
  16. package/dist/bin/templates/js/full/mock-requests/rest/user.js +35 -35
  17. package/dist/bin/templates/js/full/mock-requests/rest/users.js +12 -12
  18. package/dist/bin/templates/js/full/mock-server.config.js +19 -19
  19. package/dist/bin/templates/js/graphql/mock-requests/index.js +2 -2
  20. package/dist/bin/templates/js/graphql/mock-requests/user.js +35 -35
  21. package/dist/bin/templates/js/graphql/mock-requests/users.js +12 -12
  22. package/dist/bin/templates/js/graphql/mock-server.config.js +14 -14
  23. package/dist/bin/templates/js/rest/mock-requests/index.js +2 -2
  24. package/dist/bin/templates/js/rest/mock-requests/user.js +35 -35
  25. package/dist/bin/templates/js/rest/mock-requests/users.js +12 -12
  26. package/dist/bin/templates/js/rest/mock-server.config.js +14 -14
  27. package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -2
  28. package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -37
  29. package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -14
  30. package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -2
  31. package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -37
  32. package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -14
  33. package/dist/bin/templates/ts/full/mock-server.config.ts +21 -21
  34. package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -2
  35. package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -37
  36. package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -14
  37. package/dist/bin/templates/ts/graphql/mock-server.config.ts +16 -16
  38. package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -2
  39. package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -37
  40. package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -14
  41. package/dist/bin/templates/ts/rest/mock-server.config.ts +16 -16
  42. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +3 -3
  43. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +4 -4
  44. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +2 -2
  45. package/dist/src/core/functions/graphql/graphql.d.ts +54 -0
  46. package/dist/src/core/functions/graphql/graphql.js +126 -0
  47. package/dist/src/core/functions/graphql/helpers/createQueueHandler/createQueueHandler.d.ts +5 -0
  48. package/dist/src/core/functions/graphql/helpers/createQueueHandler/createQueueHandler.js +35 -0
  49. package/dist/src/core/functions/graphql/helpers/index.d.ts +1 -0
  50. package/dist/src/core/{rest/createRestRoutes → functions/graphql}/helpers/index.js +1 -1
  51. package/dist/src/core/functions/index.d.ts +3 -0
  52. package/dist/src/core/functions/index.js +20 -0
  53. package/dist/src/core/functions/mock.d.ts +2 -0
  54. package/dist/src/core/functions/mock.js +11 -0
  55. package/dist/src/core/functions/rest/helpers/createFileHandler/createFileHandler.d.ts +2 -0
  56. package/dist/src/core/functions/rest/helpers/createFileHandler/createFileHandler.js +29 -0
  57. package/dist/src/core/functions/rest/helpers/createQueueHandler/createQueueHandler.d.ts +5 -0
  58. package/dist/src/core/functions/rest/helpers/createQueueHandler/createQueueHandler.js +35 -0
  59. package/dist/src/core/functions/rest/helpers/formatSsePayload/formatSsePayload.d.ts +5 -0
  60. package/dist/src/core/functions/rest/helpers/formatSsePayload/formatSsePayload.js +50 -0
  61. package/dist/src/core/functions/rest/helpers/index.d.ts +3 -0
  62. package/dist/src/core/functions/rest/helpers/index.js +20 -0
  63. package/dist/src/core/functions/rest/index.d.ts +1 -0
  64. package/dist/src/core/{graphql/createGraphQLRoutes/helpers → functions/rest}/index.js +1 -1
  65. package/dist/src/core/functions/rest/rest.d.ts +102 -0
  66. package/dist/src/core/functions/rest/rest.js +165 -0
  67. package/dist/src/core/graphql/createGraphQLRoute/createGraphQLRoute.d.ts +8 -0
  68. package/dist/src/core/graphql/createGraphQLRoute/createGraphQLRoute.js +158 -0
  69. package/dist/src/core/graphql/createGraphQLRoute/helpers/calculateGraphQLRouteConfigWeight/calculateGraphQLRouteConfigWeight.d.ts +2 -0
  70. package/dist/src/core/graphql/{createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js → createGraphQLRoute/helpers/calculateGraphQLRouteConfigWeight/calculateGraphQLRouteConfigWeight.js} +3 -11
  71. package/dist/src/core/graphql/createGraphQLRoute/helpers/index.d.ts +3 -0
  72. package/dist/src/core/graphql/createGraphQLRoute/helpers/index.js +20 -0
  73. package/dist/src/core/graphql/createGraphQLRoute/helpers/matchGraphQLRequestArtifacts/matchGraphQLRequestArtifacts.d.ts +12 -0
  74. package/dist/src/core/graphql/createGraphQLRoute/helpers/matchGraphQLRequestArtifacts/matchGraphQLRequestArtifacts.js +28 -0
  75. package/dist/src/core/graphql/createGraphQLRoute/helpers/prepareGraphQLRequestArtifacts/prepareGraphQLRequestArtifacts.d.ts +2 -0
  76. package/dist/src/core/graphql/createGraphQLRoute/helpers/prepareGraphQLRequestArtifacts/prepareGraphQLRequestArtifacts.js +11 -0
  77. package/dist/src/core/graphql/index.d.ts +2 -1
  78. package/dist/src/core/graphql/index.js +2 -1
  79. package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.d.ts +6 -4
  80. package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.js +1 -2
  81. package/dist/src/core/rest/createRestRoute/createRestRoute.d.ts +8 -0
  82. package/dist/src/core/rest/createRestRoute/createRestRoute.js +190 -0
  83. package/dist/src/core/rest/createRestRoute/helpers/calculateRestRouteConfigWeight/calculateRestRouteConfigWeight.d.ts +2 -0
  84. package/dist/src/core/rest/createRestRoute/helpers/calculateRestRouteConfigWeight/calculateRestRouteConfigWeight.js +35 -0
  85. package/dist/src/core/rest/createRestRoute/helpers/index.d.ts +3 -0
  86. package/dist/src/core/rest/createRestRoute/helpers/index.js +20 -0
  87. package/dist/src/core/rest/createRestRoute/helpers/matchRestRequestArtifacts/matchRestRequestArtifacts.d.ts +11 -0
  88. package/dist/src/core/rest/createRestRoute/helpers/matchRestRequestArtifacts/matchRestRequestArtifacts.js +31 -0
  89. package/dist/src/core/rest/createRestRoute/helpers/prepareRestRequestArtifacts/prepareRestRequestArtifacts.d.ts +2 -0
  90. package/dist/src/core/rest/createRestRoute/helpers/prepareRestRequestArtifacts/prepareRestRequestArtifacts.js +37 -0
  91. package/dist/src/core/rest/index.d.ts +2 -1
  92. package/dist/src/core/rest/index.js +2 -1
  93. package/dist/src/index.d.ts +1 -0
  94. package/dist/src/index.js +1 -0
  95. package/dist/src/server/createMockServer/createMockServer.d.ts +1 -1
  96. package/dist/src/server/createMockServer/createMockServer.js +76 -45
  97. package/dist/src/server/index.d.ts +0 -8
  98. package/dist/src/server/index.js +0 -8
  99. package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
  100. package/dist/src/server/startMockServer/startMockServer.js +4 -3
  101. package/dist/src/utils/constants/checkModes.js +7 -7
  102. package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +1 -1
  103. package/dist/src/utils/helpers/files/isFileDescriptor/isFileDescriptor.js +2 -2
  104. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +3 -3
  105. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts +3 -3
  106. package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +2 -2
  107. package/dist/src/utils/helpers/tests/createTmpDir.js +4 -4
  108. package/dist/src/utils/helpers/url/index.d.ts +1 -2
  109. package/dist/src/utils/helpers/url/index.js +1 -2
  110. package/dist/src/utils/helpers/url/normalizeUrl/normalizeUrl.d.ts +1 -0
  111. package/dist/src/utils/helpers/url/normalizeUrl/normalizeUrl.js +15 -0
  112. package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +4 -4
  113. package/dist/src/utils/types/graphql.d.ts +44 -18
  114. package/dist/src/utils/types/rest.d.ts +44 -27
  115. package/dist/src/utils/types/server.d.ts +7 -24
  116. package/dist/src/utils/types/values.d.ts +6 -1
  117. package/dist/src/utils/validate/graphqlConfigSchema/graphqlConfigSchema.d.ts +41 -383
  118. package/dist/src/utils/validate/graphqlConfigSchema/graphqlConfigSchema.js +3 -3
  119. package/dist/src/utils/validate/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +3 -66
  120. package/dist/src/utils/validate/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +7 -22
  121. package/dist/src/utils/validate/index.d.ts +0 -2
  122. package/dist/src/utils/validate/index.js +0 -2
  123. package/dist/src/utils/validate/queueSchema/queueSchema.d.ts +2 -11
  124. package/dist/src/utils/validate/queueSchema/queueSchema.js +7 -13
  125. package/dist/src/utils/validate/restConfigSchema/restConfigSchema.d.ts +101 -1309
  126. package/dist/src/utils/validate/restConfigSchema/restConfigSchema.js +3 -3
  127. package/dist/src/utils/validate/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +3 -82
  128. package/dist/src/utils/validate/restConfigSchema/routeConfigSchema/routeConfigSchema.js +6 -28
  129. package/dist/src/utils/validate/settingsSchema/settingsSchema.d.ts +0 -3
  130. package/dist/src/utils/validate/settingsSchema/settingsSchema.js +0 -1
  131. package/dist/src/utils/validate/utils/checkModeSchema/checkModeSchema.js +6 -6
  132. package/dist/src/utils/validate/utils/entitiesSchema/entitiesSchema.js +4 -4
  133. package/dist/src/utils/validate/utils/jsonSchema/jsonSchema.js +3 -3
  134. package/dist/src/utils/validate/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +1 -1
  135. package/dist/src/utils/validate/utils/sharedSchema/sharedSchema.js +3 -3
  136. package/dist/src/utils/validate/validateMockServerConfig.js +18 -8
  137. package/package.json +17 -40
  138. package/LICENSE +0 -21
  139. package/dist/bin/runFlatConfig.d.ts +0 -5
  140. package/dist/bin/runFlatConfig.js +0 -36
  141. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +0 -9
  142. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +0 -160
  143. package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.d.ts +0 -1
  144. package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +0 -2
  145. package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +0 -9
  146. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +0 -184
  147. package/dist/src/core/rest/createRestRoutes/helpers/index.d.ts +0 -1
  148. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +0 -2
  149. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +0 -67
  150. package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.d.ts +0 -3
  151. package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +0 -62
  152. package/dist/src/server/createFlatMockServer/createFlatMockServer.d.ts +0 -3
  153. package/dist/src/server/createFlatMockServer/createFlatMockServer.js +0 -128
  154. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.d.ts +0 -3
  155. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +0 -67
  156. package/dist/src/server/createRestMockServer/createRestMockServer.d.ts +0 -3
  157. package/dist/src/server/createRestMockServer/createRestMockServer.js +0 -67
  158. package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.d.ts +0 -4
  159. package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +0 -29
  160. package/dist/src/server/startFlatMockServer/startFlatMockServer.d.ts +0 -4
  161. package/dist/src/server/startFlatMockServer/startFlatMockServer.js +0 -32
  162. package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.d.ts +0 -4
  163. package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +0 -29
  164. package/dist/src/server/startRestMockServer/startRestMockServer.d.ts +0 -4
  165. package/dist/src/server/startRestMockServer/startRestMockServer.js +0 -29
  166. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +0 -1
  167. package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +0 -12
  168. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +0 -1
  169. package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +0 -11
  170. package/dist/src/utils/validate/isOnlyRequestedDataResolvingPropertyExists.d.ts +0 -4
  171. package/dist/src/utils/validate/isOnlyRequestedDataResolvingPropertyExists.js +0 -16
  172. package/dist/src/utils/validate/validateApiMockServerConfig.d.ts +0 -2
  173. package/dist/src/utils/validate/validateApiMockServerConfig.js +0 -48
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- restConfigSchema: function() {
12
+ get restConfigSchema () {
13
13
  return restConfigSchema;
14
14
  },
15
- restRequestConfigSchema: function() {
15
+ get restRequestConfigSchema () {
16
16
  return restRequestConfigSchema;
17
17
  }
18
18
  });
@@ -1,12 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import type { RestMethod } from '../../../types';
3
- export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
3
+ export declare const routeConfigSchema: (method: RestMethod) => z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<{
4
4
  settings: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
5
5
  data: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodAny]>;
6
- }, {
7
6
  entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
8
7
  interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
9
- }>, "strict", z.ZodTypeAny, {
8
+ }, "strict", z.ZodTypeAny, {
10
9
  data?: any;
11
10
  interceptors?: any;
12
11
  entities?: any;
@@ -16,82 +15,4 @@ export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.Zo
16
15
  interceptors?: unknown;
17
16
  entities?: unknown;
18
17
  settings?: unknown;
19
- }>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
20
- settings: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
21
- file: z.ZodString;
22
- }, {
23
- entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
24
- interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
25
- }>, "strict", z.ZodTypeAny, {
26
- file: string;
27
- interceptors?: any;
28
- entities?: any;
29
- settings?: any;
30
- }, {
31
- file: string;
32
- interceptors?: unknown;
33
- entities?: unknown;
34
- settings?: unknown;
35
- }>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
36
- settings: z.ZodObject<z.objectUtil.extendShape<{
37
- polling: z.ZodOptional<z.ZodBoolean>;
38
- status: z.ZodOptional<z.ZodNumber>;
39
- delay: z.ZodOptional<z.ZodNumber>;
40
- }, {
41
- polling: z.ZodLiteral<true>;
42
- }>, "strict", z.ZodTypeAny, {
43
- polling: true;
44
- status?: number | undefined;
45
- delay?: number | undefined;
46
- }, {
47
- polling: true;
48
- status?: number | undefined;
49
- delay?: number | undefined;
50
- }>;
51
- queue: z.ZodArray<z.ZodUnion<[z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<{
52
- time: z.ZodOptional<z.ZodNumber>;
53
- data: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodAny]>;
54
- }, "strict", z.ZodTypeAny, {
55
- data?: any;
56
- time?: number | undefined;
57
- }, {
58
- data?: any;
59
- time?: number | undefined;
60
- }>>, z.ZodObject<{
61
- time: z.ZodOptional<z.ZodNumber>;
62
- file: z.ZodString;
63
- }, "strict", z.ZodTypeAny, {
64
- file: string;
65
- time?: number | undefined;
66
- }, {
67
- file: string;
68
- time?: number | undefined;
69
- }>]>, "many">;
70
- }, {
71
- entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
72
- interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
73
- }>, "strict", z.ZodTypeAny, {
74
- queue: ({
75
- data?: any;
76
- time?: number | undefined;
77
- } | {
78
- file: string;
79
- time?: number | undefined;
80
- })[];
81
- settings: {
82
- polling: true;
83
- status?: number | undefined;
84
- delay?: number | undefined;
85
- };
86
- interceptors?: any;
87
- entities?: any;
88
- }, {
89
- queue: unknown[];
90
- settings: {
91
- polling: true;
92
- status?: number | undefined;
93
- delay?: number | undefined;
94
- };
95
- interceptors?: unknown;
96
- entities?: unknown;
97
- }>>]>;
18
+ }>>;
@@ -11,8 +11,6 @@ Object.defineProperty(exports, "routeConfigSchema", {
11
11
  const _zod = require("zod");
12
12
  const _helpers = require("../../../helpers");
13
13
  const _interceptorsSchema = require("../../interceptorsSchema/interceptorsSchema");
14
- const _isOnlyRequestedDataResolvingPropertyExists = require("../../isOnlyRequestedDataResolvingPropertyExists");
15
- const _queueSchema = require("../../queueSchema/queueSchema");
16
14
  const _settingsSchema = require("../../settingsSchema/settingsSchema");
17
15
  const _utils = require("../../utils");
18
16
  const METHODS_WITH_BODY = [
@@ -32,33 +30,13 @@ const entitiesByEntityNameSchema = (method)=>{
32
30
  }
33
31
  }));
34
32
  };
35
- const baseRouteConfigSchema = (method)=>_zod.z.strictObject({
36
- entities: entitiesByEntityNameSchema(method).optional(),
37
- interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional()
38
- });
39
33
  const dataRouteConfigSchema = (method)=>_zod.z.strictObject({
40
- settings: (0, _utils.plainObjectSchema)(_settingsSchema.settingsSchema.extend({
41
- polling: _zod.z.literal(false).optional()
42
- })).optional(),
34
+ settings: (0, _utils.plainObjectSchema)(_settingsSchema.settingsSchema).optional(),
43
35
  data: _zod.z.union([
44
36
  _zod.z.function(),
45
37
  _zod.z.any()
46
- ])
47
- }).merge(baseRouteConfigSchema(method));
48
- const fileRouteConfigSchema = (method)=>_zod.z.strictObject({
49
- settings: (0, _utils.plainObjectSchema)(_settingsSchema.settingsSchema.extend({
50
- polling: _zod.z.literal(false).optional()
51
- })).optional(),
52
- file: _zod.z.string()
53
- }).merge(baseRouteConfigSchema(method));
54
- const queueRouteConfigSchema = (method)=>_zod.z.strictObject({
55
- settings: _settingsSchema.settingsSchema.extend({
56
- polling: _zod.z.literal(true)
57
- }),
58
- queue: _queueSchema.queueSchema
59
- }).merge(baseRouteConfigSchema(method));
60
- const routeConfigSchema = (method)=>_zod.z.union([
61
- _zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _isOnlyRequestedDataResolvingPropertyExists.isOnlyRequestedDataResolvingPropertyExists)(value, 'data')).pipe(dataRouteConfigSchema(method)),
62
- _zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _isOnlyRequestedDataResolvingPropertyExists.isOnlyRequestedDataResolvingPropertyExists)(value, 'file')).pipe(fileRouteConfigSchema(method)),
63
- _zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _isOnlyRequestedDataResolvingPropertyExists.isOnlyRequestedDataResolvingPropertyExists)(value, 'queue')).pipe(queueRouteConfigSchema(method))
64
- ]);
38
+ ]),
39
+ entities: entitiesByEntityNameSchema(method).optional(),
40
+ interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional()
41
+ });
42
+ const routeConfigSchema = (method)=>_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && 'data' in value).pipe(dataRouteConfigSchema(method));
@@ -1,14 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  export declare const settingsSchema: z.ZodObject<{
3
- polling: z.ZodOptional<z.ZodBoolean>;
4
3
  status: z.ZodOptional<z.ZodNumber>;
5
4
  delay: z.ZodOptional<z.ZodNumber>;
6
5
  }, "strict", z.ZodTypeAny, {
7
6
  status?: number | undefined;
8
- polling?: boolean | undefined;
9
7
  delay?: number | undefined;
10
8
  }, {
11
9
  status?: number | undefined;
12
- polling?: boolean | undefined;
13
10
  delay?: number | undefined;
14
11
  }>;
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "settingsSchema", {
10
10
  });
11
11
  const _zod = require("zod");
12
12
  const settingsSchema = _zod.z.strictObject({
13
- polling: _zod.z.boolean().optional(),
14
13
  status: _zod.z.number().min(200).max(599).optional(),
15
14
  delay: _zod.z.number().nonnegative().optional()
16
15
  });
@@ -5,23 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- checkActualValueCheckModeSchema: function() {
12
+ get checkActualValueCheckModeSchema () {
13
13
  return checkActualValueCheckModeSchema;
14
14
  },
15
- compareWithDescriptorAnyValueCheckModeSchema: function() {
15
+ get compareWithDescriptorAnyValueCheckModeSchema () {
16
16
  return compareWithDescriptorAnyValueCheckModeSchema;
17
17
  },
18
- compareWithDescriptorStringValueCheckModeSchema: function() {
18
+ get compareWithDescriptorStringValueCheckModeSchema () {
19
19
  return compareWithDescriptorStringValueCheckModeSchema;
20
20
  },
21
- compareWithDescriptorValueCheckModeSchema: function() {
21
+ get compareWithDescriptorValueCheckModeSchema () {
22
22
  return compareWithDescriptorValueCheckModeSchema;
23
23
  },
24
- entityDescriptorSchema: function() {
24
+ get entityDescriptorSchema () {
25
25
  return entityDescriptorSchema;
26
26
  }
27
27
  });
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- bodyPlainEntitySchema: function() {
12
+ get bodyPlainEntitySchema () {
13
13
  return bodyPlainEntitySchema;
14
14
  },
15
- mappedEntitySchema: function() {
15
+ get mappedEntitySchema () {
16
16
  return mappedEntitySchema;
17
17
  },
18
- variablesPlainEntitySchema: function() {
18
+ get variablesPlainEntitySchema () {
19
19
  return variablesPlainEntitySchema;
20
20
  }
21
21
  });
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- jsonLiteralSchema: function() {
12
+ get jsonLiteralSchema () {
13
13
  return jsonLiteralSchema;
14
14
  },
15
- jsonSchema: function() {
15
+ get jsonSchema () {
16
16
  return jsonSchema;
17
17
  }
18
18
  });
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "requiredPropertiesSchema", {
10
10
  });
11
11
  const _zod = require("zod");
12
12
  const _helpers = require("../../../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);
13
+ const requiredPropertiesSchema = (schema, requiredProperties)=>_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && requiredProperties.every((property)=>Object.hasOwn(value, property))).pipe(schema);
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- stringForwardSlashSchema: function() {
12
+ get stringForwardSlashSchema () {
13
13
  return stringForwardSlashSchema;
14
14
  },
15
- stringJsonFilenameSchema: function() {
15
+ get stringJsonFilenameSchema () {
16
16
  return stringJsonFilenameSchema;
17
17
  }
18
18
  });
@@ -21,22 +21,32 @@ const _restConfigSchema = require("./restConfigSchema/restConfigSchema");
21
21
  const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
22
22
  const _utils = require("./utils");
23
23
  const validateMockServerConfig = (mockServerConfig)=>{
24
- if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database && !mockServerConfig.staticPath) {
25
- 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');
24
+ if (!mockServerConfig.length) {
25
+ throw new Error('Config should contain at least one element; see our doc (https://github.com/siberiacancode/mock-config-server) for more information');
26
26
  }
27
- const mockServerConfigSchema = _zod.z.strictObject({
27
+ const mockServerSettingsSchema = _zod.z.strictObject({
28
28
  baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
29
29
  port: _portSchema.portSchema.optional(),
30
30
  staticPath: _staticPathSchema.staticPathSchema.optional(),
31
31
  interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
32
32
  cors: _corsSchema.corsSchema.optional(),
33
- rest: _restConfigSchema.restConfigSchema.optional(),
34
- graphql: _graphqlConfigSchema.graphqlConfigSchema.optional(),
35
33
  database: _databaseConfigSchema.databaseConfigSchema.optional()
36
34
  });
37
- const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
38
- if (!validationResult.success) {
39
- const path = (0, _getMostSpecificPathFromError.getMostSpecificPathFromError)(validationResult.error);
35
+ const mockServerComponentSchema = _zod.z.strictObject({
36
+ name: _zod.z.string().optional(),
37
+ baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
38
+ interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
39
+ configs: _zod.z.array(_zod.z.union([
40
+ _restConfigSchema.restRequestConfigSchema,
41
+ _graphqlConfigSchema.graphqlRequestConfigSchema
42
+ ]))
43
+ });
44
+ const mockServerConfigSchema = _zod.z.tuple([
45
+ (0, _utils.plainObjectSchema)(mockServerSettingsSchema).or(mockServerComponentSchema)
46
+ ]).rest(mockServerComponentSchema);
47
+ const validationMockServerConfigSchemaResult = mockServerConfigSchema.safeParse(mockServerConfig);
48
+ if (!validationMockServerConfigSchemaResult.success) {
49
+ const path = (0, _getMostSpecificPathFromError.getMostSpecificPathFromError)(validationMockServerConfigSchemaResult.error);
40
50
  const validationMessage = (0, _getValidationMessageFromPath.getValidationMessageFromPath)(path);
41
51
  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
52
  }
package/package.json CHANGED
@@ -1,38 +1,19 @@
1
1
  {
2
2
  "name": "mock-config-server",
3
- "version": "4.0.2",
3
+ "version": "5.0.0-beta.0",
4
4
  "description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
7
7
  "url": "https://github.com/siberiacancode"
8
8
  },
9
- "contributors": [
10
- {
11
- "name": "Dmitry Babin",
12
- "url": "https://github.com/debabin"
13
- },
14
- {
15
- "name": "Nursultan Zianurov",
16
- "url": "https://github.com/MiaInturi"
17
- },
18
- {
19
- "name": "Sergey Kryavkin",
20
- "url": "https://github.com/RiceWithMeat"
21
- },
22
- {
23
- "name": "Alexander Vasilchuk",
24
- "url": "https://github.com/anv296"
25
- },
26
- {
27
- "name": "Daria Bortsova",
28
- "url": "https://github.com/kvelian"
29
- }
30
- ],
31
9
  "license": "MIT",
32
- "homepage": "https://github.com/siberiacancode/mock-config-server",
10
+ "homepage": "https://github.com/siberiacancode/mock-config",
33
11
  "repository": {
34
12
  "type": "git",
35
- "url": "https://github.com/siberiacancode/mock-config-server.git"
13
+ "url": "git+https://github.com/siberiacancode/mock-config-server.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/siberiacancode/mock-config/issues"
36
17
  },
37
18
  "keywords": [
38
19
  "server",
@@ -56,28 +37,29 @@
56
37
  "dist"
57
38
  ],
58
39
  "engines": {
59
- "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
40
+ "node": "^16.0.0 || >=17.0.0"
60
41
  },
61
42
  "scripts": {
62
43
  "prepublishOnly": "git diff --exit-code",
63
- "prepare": "husky && yarn build",
44
+ "lint-staged": "lint-staged",
45
+ "prepare": "husky && pnpm build",
64
46
  "build:types": "tsc -p tsconfig.production.json && tsc-alias -p tsconfig.production.json",
65
47
  "build:swc": "swc bin src index.ts -d dist --extensions .ts --copy-files --ignore **/*.test.ts --ignore bin/templates",
66
48
  "build:copy-templates": "shx mkdir -p dist/bin/templates/ts && shx cp -r bin/templates/ts dist/bin/templates && shx mkdir -p dist/bin/templates/js && shx cp -r bin/templates/js dist/bin/templates",
67
- "build": "shx rm -rf dist && yarn build:types && yarn build:swc && yarn build:copy-templates",
68
- "start": "yarn build && node ./dist/bin/bin.js",
69
- "dev": "nodemon --watch src --watch bin --watch mock-server.config.* -e js,ts --exec \"yarn start\"",
49
+ "build": "shx rm -rf dist && pnpm build:types && pnpm build:swc && pnpm build:copy-templates",
50
+ "start": "pnpm build && node ./dist/bin/bin.js",
51
+ "dev": "nodemon --watch src --watch bin --watch mock-server.config.* -e js,ts --exec \"pnpm start\"",
70
52
  "type": "tsc --noEmit",
71
53
  "unit-test": "vitest",
72
54
  "lint": "eslint . --fix",
73
55
  "lint-inspector": "npx @eslint/config-inspector",
74
- "stylelint": "stylelint \"src/static/**/*.css\" --fix",
75
56
  "format": "prettier --write \"**/*.(ts|js)\"",
76
- "pretty": "yarn format && yarn lint"
57
+ "pretty": "pnpm lint && pnpm format"
77
58
  },
78
59
  "dependencies": {
79
60
  "@types/body-parser": "^1.19.5",
80
61
  "@types/express": "^4.17.21",
62
+ "@types/express-serve-static-core": "^5.0.7",
81
63
  "@types/flat": "^5.0.5",
82
64
  "@types/prompts": "^2.4.9",
83
65
  "@types/yargs": "^17.0.33",
@@ -94,8 +76,6 @@
94
76
  "zod": "^3.24.1"
95
77
  },
96
78
  "devDependencies": {
97
- "@siberiacancode/eslint": "^2.6.0",
98
- "@siberiacancode/prettier": "^1.1.1",
99
79
  "@siberiacancode/vitest": "^1.2.4",
100
80
  "@swc/cli": "^0.6.0",
101
81
  "@swc/core": "^1.10.7",
@@ -106,18 +86,15 @@
106
86
  "shx": "^0.3.4",
107
87
  "supertest": "^7.0.0",
108
88
  "tsc-alias": "^1.8.10",
109
- "typescript": "^5.7.3"
89
+ "vitest": "^3.2.4"
110
90
  },
111
91
  "lint-staged": {
112
- "*.css": [
113
- "stylelint --fix"
114
- ],
115
92
  "*.js": [
116
93
  "prettier --write"
117
94
  ],
118
95
  "*.ts": [
119
- "prettier --write",
120
- "eslint --no-error-on-unmatched-pattern --fix"
96
+ "eslint --no-error-on-unmatched-pattern --fix",
97
+ "prettier --write"
121
98
  ]
122
99
  }
123
100
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 siberiacancode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- import type { FlatMockServerConfig, MockServerConfigArgv } from '../src';
3
- export declare const runFlatConfig: (flatMockServerConfig: FlatMockServerConfig, { baseUrl, port, staticPath }: MockServerConfigArgv) => (import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> & {
4
- destroy: import("http").Server["close"];
5
- }) | undefined;
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "runFlatConfig", {
7
- enumerable: true,
8
- get: function() {
9
- return runFlatConfig;
10
- }
11
- });
12
- const _server = require("../src/server");
13
- const runFlatConfig = (flatMockServerConfig, { baseUrl, port, staticPath })=>{
14
- try {
15
- const [option, ...flatMockServerComponents] = flatMockServerConfig;
16
- const flatMockServerSettings = !('configs' in option) ? option : undefined;
17
- const mergedFlatMockServerConfig = [
18
- {
19
- ...flatMockServerSettings,
20
- ...baseUrl && {
21
- baseUrl
22
- },
23
- ...port && {
24
- port
25
- },
26
- ...staticPath && {
27
- staticPath
28
- }
29
- },
30
- ...flatMockServerSettings ? flatMockServerComponents : flatMockServerConfig
31
- ];
32
- return (0, _server.startFlatMockServer)(mergedFlatMockServerConfig);
33
- } catch (error) {
34
- console.error(error.message);
35
- }
36
- };
@@ -1,9 +0,0 @@
1
- import type { IRouter } from 'express';
2
- import type { GraphqlConfig, Interceptors } from '../../../utils/types';
3
- interface CreateGraphQLRoutesParams {
4
- graphqlConfig: GraphqlConfig;
5
- router: IRouter;
6
- serverResponseInterceptor?: Interceptors<'graphql'>['response'];
7
- }
8
- export declare const createGraphQLRoutes: ({ router, graphqlConfig, serverResponseInterceptor }: CreateGraphQLRoutesParams) => IRouter;
9
- export {};