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.
- package/README.md +2 -0
- package/dist/bin/bin.js +3 -6
- package/dist/bin/build.js +52 -50
- package/dist/bin/cli.js +50 -43
- package/dist/bin/helpers/createTemplate.js +29 -21
- package/dist/bin/helpers/getMostSpecificPathFromError.js +34 -30
- package/dist/bin/helpers/getValidationMessageFromPath.js +11 -8
- package/dist/bin/helpers/index.js +21 -79
- package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +13 -6
- package/dist/bin/helpers/resolveConfigFile.js +22 -19
- package/dist/bin/helpers/resolveConfigFilePath.js +19 -12
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +13 -10
- package/dist/bin/init.js +114 -97
- package/dist/bin/run.js +42 -43
- package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.d.ts +2 -2
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +32 -14
- package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +82 -72
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +38 -22
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +25 -21
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +36 -28
- package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +12 -8
- package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +2 -2
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +18 -9
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +270 -240
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +33 -19
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +33 -28
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +60 -48
- package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +13 -9
- package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +27 -9
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +4 -8
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +117 -60
- package/dist/bin/validateMockServerConfig/utils/index.js +20 -68
- package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +30 -10
- package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +9 -8
- package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +1 -1
- package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -7
- package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +18 -6
- package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +43 -40
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +38 -35
- package/dist/index.js +15 -13
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +25 -28
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +14 -11
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.js +17 -35
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +159 -143
- package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.js +15 -8
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +90 -94
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +49 -46
- package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +19 -57
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +32 -31
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +34 -24
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +37 -33
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +26 -25
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +65 -50
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +55 -48
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +51 -41
- package/dist/src/core/database/createDatabaseRoutes/storages/index.js +16 -24
- package/dist/src/core/database/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +131 -140
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +36 -41
- package/dist/src/core/graphql/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +18 -15
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +50 -47
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +17 -12
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -20
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +23 -17
- package/dist/src/core/middlewares/index.js +23 -91
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +22 -19
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +21 -23
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +80 -80
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -34
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +16 -24
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +17 -35
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +58 -60
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +16 -17
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +32 -25
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +125 -130
- package/dist/src/core/rest/createRestRoutes/helpers/index.js +15 -13
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +37 -43
- package/dist/src/core/rest/index.js +15 -13
- package/dist/src/index.js +16 -24
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +56 -53
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +64 -62
- package/dist/src/server/createMockServer/createMockServer.js +94 -91
- package/dist/src/server/createRestMockServer/createRestMockServer.js +64 -62
- package/dist/src/server/index.js +23 -91
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +25 -19
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +25 -19
- package/dist/src/server/startMockServer/startMockServer.js +25 -19
- package/dist/src/server/startRestMockServer/startRestMockServer.js +25 -19
- package/dist/src/utils/constants/appPath.js +8 -4
- package/dist/src/utils/constants/checkModes.js +74 -11
- package/dist/src/utils/constants/default.js +18 -14
- package/dist/src/utils/constants/index.js +17 -35
- package/dist/src/utils/helpers/asyncHandler.js +8 -5
- package/dist/src/utils/helpers/config/index.js +15 -13
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +103 -110
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +12 -9
- package/dist/src/utils/helpers/entities/index.js +16 -24
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +9 -6
- package/dist/src/utils/helpers/files/index.js +15 -13
- package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +22 -15
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +25 -29
- package/dist/src/utils/helpers/graphql/index.js +17 -35
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +13 -10
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +23 -19
- package/dist/src/utils/helpers/index.js +26 -124
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +21 -21
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +62 -64
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +10 -7
- package/dist/src/utils/helpers/interceptors/index.js +16 -24
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +8 -5
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +8 -5
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +8 -5
- package/dist/src/utils/helpers/sleep.js +9 -6
- package/dist/src/utils/helpers/tests/createTmpDir.js +16 -9
- package/dist/src/utils/helpers/tests/index.js +15 -13
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -5
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +9 -6
- package/dist/src/utils/helpers/url/index.js +18 -46
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +8 -5
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +18 -11
- package/dist/src/utils/types/checkModes.js +4 -1
- package/dist/src/utils/types/database.js +4 -1
- package/dist/src/utils/types/entities.js +4 -1
- package/dist/src/utils/types/graphql.d.ts +1 -1
- package/dist/src/utils/types/graphql.js +4 -1
- package/dist/src/utils/types/index.js +24 -102
- package/dist/src/utils/types/interceptors.js +4 -1
- package/dist/src/utils/types/rest.d.ts +1 -1
- package/dist/src/utils/types/rest.js +4 -1
- package/dist/src/utils/types/server.js +4 -1
- package/dist/src/utils/types/utils.js +4 -1
- package/dist/src/utils/types/values.js +4 -1
- package/package.json +26 -29
- package/dist/bin/templates/.eslintrc.js +0 -14
- package/dist/bin/templates/tsconfig.json +0 -11
|
@@ -1,71 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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>>;
|
package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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;
|
package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
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;
|