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