mock-config-server 1.0.3 → 2.0.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 +277 -213
- package/dist/bin/mock-config-server.d.ts +2 -2
- package/dist/bin/mock-config-server.js +67 -65
- package/dist/bin/resolveExportsFromSourceCode.d.ts +1 -1
- package/dist/bin/resolveExportsFromSourceCode.js +11 -11
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +82 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +48 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +71 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +21 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +34 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +104 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +44 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.d.ts +1 -2
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.js +29 -29
- package/dist/src/cors/corsMiddleware/corsMiddleware.d.ts +3 -3
- package/dist/src/cors/corsMiddleware/corsMiddleware.js +44 -32
- package/dist/src/cors/getOrigins/getAllowedOrigins.d.ts +2 -2
- package/dist/src/cors/getOrigins/getAllowedOrigins.js +13 -16
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.d.ts +2 -2
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.js +20 -15
- package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +3 -0
- package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.js +73 -0
- package/dist/src/graphql/getGraphQLInput/getGraphQLInput.d.ts +3 -0
- package/dist/src/graphql/getGraphQLInput/getGraphQLInput.js +21 -0
- package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -0
- package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.js +12 -0
- package/dist/src/graphql/parseQuery/parseQuery.d.ts +7 -0
- package/dist/src/graphql/parseQuery/parseQuery.js +21 -0
- package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -0
- package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +28 -0
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +19 -19
- package/dist/src/notFound/notFoundMiddleware.d.ts +8 -0
- package/dist/src/notFound/notFoundMiddleware.js +47 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +6 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +18 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.js +17 -0
- package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.js +80 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +6 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +7 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +5 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.d.ts +2 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.js +18 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.js +17 -0
- package/dist/src/notFound/urlSuggestions/index.d.ts +2 -0
- package/dist/src/notFound/urlSuggestions/index.js +18 -0
- package/dist/src/rest/createRestRoutes/createRestRoutes.d.ts +3 -0
- package/dist/src/{routes/createRoutes/createRoutes.js → rest/createRestRoutes/createRestRoutes.js} +41 -43
- package/dist/src/rest/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -0
- package/dist/src/{configs/prepareRequestConfigs/prepareRequestConfigs.js → rest/prepareRestRequestConfigs/prepareRestRequestConfigs.js} +30 -30
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.d.ts +12 -12
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.js +13 -13
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.d.ts +14 -14
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.js +31 -31
- package/dist/src/server/createMockServer/createMockServer.d.ts +3 -3
- package/dist/src/server/createMockServer/createMockServer.js +48 -35
- package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
- package/dist/src/server/startMockServer/startMockServer.js +17 -13
- package/dist/src/static/staticMiddleware/staticMiddleware.d.ts +3 -3
- package/dist/src/static/staticMiddleware/staticMiddleware.js +30 -29
- package/dist/src/utils/constants/appPath.d.ts +1 -1
- package/dist/src/utils/constants/appPath.js +4 -4
- package/dist/src/utils/constants/default.d.ts +11 -10
- package/dist/src/utils/constants/default.js +14 -13
- package/dist/src/utils/constants/index.d.ts +2 -2
- package/dist/src/utils/constants/index.js +18 -18
- package/dist/src/utils/helpers/index.d.ts +3 -2
- package/dist/src/utils/helpers/index.js +19 -18
- package/dist/src/utils/helpers/isPlainObject.d.ts +1 -1
- package/dist/src/utils/helpers/isPlainObject.js +5 -5
- package/dist/src/utils/helpers/sleep.d.ts +1 -1
- package/dist/src/utils/helpers/sleep.js +7 -7
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +1 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +6 -0
- package/dist/src/utils/helpers/url/index.d.ts +2 -0
- package/dist/src/utils/helpers/url/index.js +18 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +5 -0
- package/dist/src/utils/types/configs.d.ts +63 -34
- package/dist/src/utils/types/configs.js +2 -2
- package/dist/src/utils/types/graphql.d.ts +5 -0
- package/dist/src/utils/types/graphql.js +2 -0
- package/dist/src/utils/types/index.d.ts +4 -3
- package/dist/src/utils/types/index.js +20 -19
- package/dist/src/utils/types/interceptors.d.ts +15 -15
- package/dist/src/utils/types/interceptors.js +2 -2
- package/dist/src/utils/types/server.d.ts +32 -24
- package/dist/src/utils/types/server.js +2 -2
- package/package.json +102 -99
- package/dist/jest.config.d.ts +0 -3
- package/dist/jest.config.js +0 -7
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.test.d.ts +0 -1
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.test.js +0 -25
- package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.d.ts +0 -2
- package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.test.d.ts +0 -1
- package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.test.js +0 -151
- package/dist/src/cors/corsMiddleware/corsMiddleware.test.d.ts +0 -1
- package/dist/src/cors/corsMiddleware/corsMiddleware.test.js +0 -86
- package/dist/src/cors/getOrigins/getAllowedOrigins.test.d.ts +0 -1
- package/dist/src/cors/getOrigins/getAllowedOrigins.test.js +0 -24
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.test.d.ts +0 -1
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.test.js +0 -22
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.test.d.ts +0 -1
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.test.js +0 -28
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.test.d.ts +0 -1
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.test.js +0 -36
- package/dist/src/routes/createRoutes/createRoutes.d.ts +0 -3
- package/dist/src/routes/createRoutes/createRoutes.test.d.ts +0 -1
- package/dist/src/routes/createRoutes/createRoutes.test.js +0 -276
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveExportsFromSourceCode = void 0;
|
|
4
|
-
const resolveExportsFromSourceCode = (sourceCode) => {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
const moduleInstance = new module.constructor();
|
|
7
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
8
|
-
moduleInstance._compile(sourceCode, '');
|
|
9
|
-
return moduleInstance.exports;
|
|
10
|
-
};
|
|
11
|
-
exports.resolveExportsFromSourceCode = resolveExportsFromSourceCode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveExportsFromSourceCode = void 0;
|
|
4
|
+
const resolveExportsFromSourceCode = (sourceCode) => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const moduleInstance = new module.constructor();
|
|
7
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
8
|
+
moduleInstance._compile(sourceCode, '');
|
|
9
|
+
return moduleInstance.exports;
|
|
10
|
+
};
|
|
11
|
+
exports.resolveExportsFromSourceCode = resolveExportsFromSourceCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateBaseUrl: (baseUrl: unknown) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBaseUrl = void 0;
|
|
4
|
+
const validateBaseUrl = (baseUrl) => {
|
|
5
|
+
if (typeof baseUrl !== 'string' && typeof baseUrl !== 'undefined') {
|
|
6
|
+
throw new Error('baseUrl');
|
|
7
|
+
}
|
|
8
|
+
if (typeof baseUrl === 'string' && !baseUrl.startsWith('/')) {
|
|
9
|
+
throw new Error('baseUrl');
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.validateBaseUrl = validateBaseUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateCors: (cors: unknown) => void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCors = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateOrigin = (origin) => {
|
|
6
|
+
const isOriginArray = Array.isArray(origin);
|
|
7
|
+
if (isOriginArray) {
|
|
8
|
+
origin.forEach((originElement, index) => {
|
|
9
|
+
const isOriginElementStringOrRegExp = typeof originElement === 'string' || originElement instanceof RegExp;
|
|
10
|
+
if (!isOriginElementStringOrRegExp) {
|
|
11
|
+
throw new Error(`origin[${index}]`);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const isOriginStringOrRegexp = typeof origin === 'string' || origin instanceof RegExp;
|
|
17
|
+
const isOriginFunction = typeof origin === 'function';
|
|
18
|
+
if (!isOriginStringOrRegexp && !isOriginFunction) {
|
|
19
|
+
throw new Error('origin');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const validateMethods = (methods) => {
|
|
23
|
+
const isMethodsArray = Array.isArray(methods);
|
|
24
|
+
if (isMethodsArray) {
|
|
25
|
+
const allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
|
|
26
|
+
methods.forEach((method, index) => {
|
|
27
|
+
// ✅ important:
|
|
28
|
+
// compare without 'toUpperCase' because 'Access-Control-Allow-Methods' value is case-sensitive
|
|
29
|
+
if (!allowedMethods.includes(method)) {
|
|
30
|
+
throw new Error(`methods[${index}]`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof methods !== 'undefined') {
|
|
36
|
+
throw new Error('methods');
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const validateHeaders = (headers) => {
|
|
40
|
+
const isHeadersArray = Array.isArray(headers);
|
|
41
|
+
if (isHeadersArray) {
|
|
42
|
+
headers.forEach((header, index) => {
|
|
43
|
+
if (typeof header !== 'string') {
|
|
44
|
+
throw new Error(`headers[${index}]`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (typeof headers !== 'undefined') {
|
|
50
|
+
throw new Error('headers');
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const validateCredentials = (credentials) => {
|
|
54
|
+
if (typeof credentials !== 'boolean' && typeof credentials !== 'undefined') {
|
|
55
|
+
throw new Error('credentials');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const validateMaxAge = (maxAge) => {
|
|
59
|
+
if (typeof maxAge !== 'number' && typeof maxAge !== 'undefined') {
|
|
60
|
+
throw new Error('maxAge');
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const validateCors = (cors) => {
|
|
64
|
+
const isCorsObject = (0, helpers_1.isPlainObject)(cors);
|
|
65
|
+
if (isCorsObject) {
|
|
66
|
+
try {
|
|
67
|
+
validateOrigin(cors.origin);
|
|
68
|
+
validateMethods(cors.methods);
|
|
69
|
+
validateHeaders(cors.headers);
|
|
70
|
+
validateCredentials(cors.credentials);
|
|
71
|
+
validateMaxAge(cors.maxAge);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`cors.${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (typeof cors !== 'undefined') {
|
|
79
|
+
throw new Error('cors');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.validateCors = validateCors;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateGraphqlConfig: (graphqlConfig: unknown) => void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateGraphqlConfig = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateBaseUrl_1 = require("../validateBaseUrl/validateBaseUrl");
|
|
6
|
+
const validateInterceptors_1 = require("../validateInterceptors/validateInterceptors");
|
|
7
|
+
const validateRoutes_1 = require("./validateRoutes/validateRoutes");
|
|
8
|
+
const validateConfigs = (configs) => {
|
|
9
|
+
const isConfigsArray = Array.isArray(configs);
|
|
10
|
+
if (isConfigsArray) {
|
|
11
|
+
configs.forEach((config, index) => {
|
|
12
|
+
const { operationType, operationName } = config;
|
|
13
|
+
if (operationType !== 'query' && operationType !== 'mutation') {
|
|
14
|
+
throw new Error(`configs[${index}].operationType`);
|
|
15
|
+
}
|
|
16
|
+
const isOperationNameStringOrRegExp = typeof operationName === 'string' || operationName instanceof RegExp;
|
|
17
|
+
if (!isOperationNameStringOrRegExp) {
|
|
18
|
+
throw new Error(`configs[${index}].operationName`);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
(0, validateRoutes_1.validateRoutes)(config.routes, operationType);
|
|
22
|
+
(0, validateInterceptors_1.validateInterceptors)(config.interceptors);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`configs[${index}].${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
throw new Error('configs');
|
|
31
|
+
};
|
|
32
|
+
const validateGraphqlConfig = (graphqlConfig) => {
|
|
33
|
+
const isGraphqlConfigObject = (0, helpers_1.isPlainObject)(graphqlConfig);
|
|
34
|
+
if (isGraphqlConfigObject) {
|
|
35
|
+
try {
|
|
36
|
+
(0, validateBaseUrl_1.validateBaseUrl)(graphqlConfig.baseUrl);
|
|
37
|
+
validateConfigs(graphqlConfig.configs);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`graphql.${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (typeof graphqlConfig !== 'undefined') {
|
|
45
|
+
throw new Error('graphql');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.validateGraphqlConfig = validateGraphqlConfig;
|
package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRoutes = void 0;
|
|
4
|
+
const helpers_1 = require("../../../../src/utils/helpers");
|
|
5
|
+
const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
|
|
6
|
+
const ALLOWED_ENTITIES_BY_OPERATION_TYPE = {
|
|
7
|
+
query: ['headers', 'query', 'variables'],
|
|
8
|
+
mutation: ['headers', 'query', 'variables']
|
|
9
|
+
};
|
|
10
|
+
const validateHeadersOrQuery = (headersOrQuery, entity) => {
|
|
11
|
+
const isHeadersOrQueryObject = (0, helpers_1.isPlainObject)(headersOrQuery);
|
|
12
|
+
if (isHeadersOrQueryObject) {
|
|
13
|
+
Object.entries(headersOrQuery).forEach(([headerOrQueryKey, headerOrQueryValue]) => {
|
|
14
|
+
if (typeof headerOrQueryValue !== 'string') {
|
|
15
|
+
throw new Error(`${entity}.${headerOrQueryKey}`);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
throw new Error(entity);
|
|
21
|
+
};
|
|
22
|
+
const validateEntities = (entities, operationType) => {
|
|
23
|
+
const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
|
|
24
|
+
if (isEntitiesObject) {
|
|
25
|
+
Object.keys(entities).forEach((entity) => {
|
|
26
|
+
const isEntityAllowed = ALLOWED_ENTITIES_BY_OPERATION_TYPE[operationType].includes(entity);
|
|
27
|
+
if (!isEntityAllowed) {
|
|
28
|
+
throw new Error(`entities.${entity}`);
|
|
29
|
+
}
|
|
30
|
+
if (entity === 'headers' || entity === 'query') {
|
|
31
|
+
try {
|
|
32
|
+
const headersOrQuery = entities[entity];
|
|
33
|
+
return validateHeadersOrQuery(headersOrQuery, entity);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new Error(`entities.${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (typeof entities !== 'undefined') {
|
|
43
|
+
throw new Error('entities');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const validateRoutes = (routes, operationType) => {
|
|
47
|
+
const isRoutesArray = Array.isArray(routes);
|
|
48
|
+
if (isRoutesArray) {
|
|
49
|
+
routes.forEach((route, index) => {
|
|
50
|
+
const isRouteObject = (0, helpers_1.isPlainObject)(route);
|
|
51
|
+
if (isRouteObject) {
|
|
52
|
+
const isRouteHasDataProperty = 'data' in route;
|
|
53
|
+
if (!isRouteHasDataProperty) {
|
|
54
|
+
throw new Error(`routes[${index}]`);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
validateEntities(route.entities, operationType);
|
|
58
|
+
(0, validateInterceptors_1.validateInterceptors)(route.interceptors);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`routes[${index}].${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`routes[${index}]`);
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
throw new Error('routes');
|
|
70
|
+
};
|
|
71
|
+
exports.validateRoutes = validateRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateInterceptors: (interceptors: unknown) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInterceptors = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateInterceptors = (interceptors) => {
|
|
6
|
+
const isInterceptorsObject = (0, helpers_1.isPlainObject)(interceptors);
|
|
7
|
+
if (isInterceptorsObject) {
|
|
8
|
+
const { request, response } = interceptors;
|
|
9
|
+
if (typeof request !== 'function' && typeof request !== 'undefined') {
|
|
10
|
+
throw new Error('interceptors.request');
|
|
11
|
+
}
|
|
12
|
+
if (typeof response !== 'function' && typeof response !== 'undefined') {
|
|
13
|
+
throw new Error('interceptors.response');
|
|
14
|
+
}
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (typeof interceptors !== 'undefined') {
|
|
18
|
+
throw new Error('interceptors');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.validateInterceptors = validateInterceptors;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateMockServerConfig: (mockServerConfig: unknown) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMockServerConfig = void 0;
|
|
4
|
+
const helpers_1 = require("../../src/utils/helpers");
|
|
5
|
+
const validateBaseUrl_1 = require("./validateBaseUrl/validateBaseUrl");
|
|
6
|
+
const validateCors_1 = require("./validateCors/validateCors");
|
|
7
|
+
const validateGraphqlConfig_1 = require("./validateGraphqlConfig/validateGraphqlConfig");
|
|
8
|
+
const validateInterceptors_1 = require("./validateInterceptors/validateInterceptors");
|
|
9
|
+
const validatePort_1 = require("./validatePort/validatePort");
|
|
10
|
+
const validateRestConfig_1 = require("./validateRestConfig/validateRestConfig");
|
|
11
|
+
const validateStaticPath_1 = require("./validateStaticPath/validateStaticPath");
|
|
12
|
+
const validateMockServerConfig = (mockServerConfig) => {
|
|
13
|
+
if (!(0, helpers_1.isPlainObject)(mockServerConfig)) {
|
|
14
|
+
throw new Error('configuration should be plain object; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
|
|
15
|
+
}
|
|
16
|
+
if (!mockServerConfig.rest && !mockServerConfig.graphql) {
|
|
17
|
+
throw new Error('configuration should contain at least one of these configs: rest | graphql; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
if (mockServerConfig.rest)
|
|
21
|
+
(0, validateRestConfig_1.validateRestConfig)(mockServerConfig.rest);
|
|
22
|
+
if (mockServerConfig.graphql)
|
|
23
|
+
(0, validateGraphqlConfig_1.validateGraphqlConfig)(mockServerConfig.graphql);
|
|
24
|
+
(0, validateBaseUrl_1.validateBaseUrl)(mockServerConfig.baseUrl);
|
|
25
|
+
(0, validatePort_1.validatePort)(mockServerConfig.port);
|
|
26
|
+
(0, validateStaticPath_1.validateStaticPath)(mockServerConfig.staticPath);
|
|
27
|
+
(0, validateInterceptors_1.validateInterceptors)(mockServerConfig.interceptors);
|
|
28
|
+
(0, validateCors_1.validateCors)(mockServerConfig.cors);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
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`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.validateMockServerConfig = validateMockServerConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validatePort: (port: unknown) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePort = void 0;
|
|
4
|
+
const validatePort = (port) => {
|
|
5
|
+
if (typeof port !== 'number' && typeof port !== 'undefined') {
|
|
6
|
+
throw new Error('port');
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.validatePort = validatePort;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateRestConfig: (restConfig: unknown) => void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRestConfig = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateBaseUrl_1 = require("../validateBaseUrl/validateBaseUrl");
|
|
6
|
+
const validateInterceptors_1 = require("../validateInterceptors/validateInterceptors");
|
|
7
|
+
const validateRoutes_1 = require("./validateRoutes/validateRoutes");
|
|
8
|
+
const validateConfigs = (configs) => {
|
|
9
|
+
const isConfigsArray = Array.isArray(configs);
|
|
10
|
+
if (isConfigsArray) {
|
|
11
|
+
configs.forEach((config, index) => {
|
|
12
|
+
const { path, method } = config;
|
|
13
|
+
const isPathStringWithLeadingSlash = typeof path === 'string' && path.startsWith('/');
|
|
14
|
+
if (!isPathStringWithLeadingSlash && !(path instanceof RegExp)) {
|
|
15
|
+
throw new Error(`configs[${index}].path`);
|
|
16
|
+
}
|
|
17
|
+
// ✅ important:
|
|
18
|
+
// compare without 'toLowerCase' because Express methods names is case-sensitive
|
|
19
|
+
const allowedMethods = ['get', 'post', 'delete', 'put', 'patch'];
|
|
20
|
+
const isMethodAllowed = typeof method === 'string' && allowedMethods.includes(method);
|
|
21
|
+
if (!isMethodAllowed) {
|
|
22
|
+
throw new Error(`configs[${index}].method`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
(0, validateRoutes_1.validateRoutes)(config.routes, method);
|
|
26
|
+
(0, validateInterceptors_1.validateInterceptors)(config.interceptors);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`configs[${index}].${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
throw new Error('configs');
|
|
35
|
+
};
|
|
36
|
+
const validateRestConfig = (restConfig) => {
|
|
37
|
+
const isRestConfigObject = (0, helpers_1.isPlainObject)(restConfig);
|
|
38
|
+
if (isRestConfigObject) {
|
|
39
|
+
try {
|
|
40
|
+
(0, validateBaseUrl_1.validateBaseUrl)(restConfig.baseUrl);
|
|
41
|
+
validateConfigs(restConfig.configs);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new Error(`rest.${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (typeof restConfig !== 'undefined') {
|
|
49
|
+
throw new Error('rest');
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.validateRestConfig = validateRestConfig;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRoutes = void 0;
|
|
4
|
+
const helpers_1 = require("../../../../src/utils/helpers");
|
|
5
|
+
const validateInterceptors_1 = require("../../validateInterceptors/validateInterceptors");
|
|
6
|
+
const ALLOWED_ENTITIES_BY_METHOD = {
|
|
7
|
+
get: ['headers', 'query', 'params'],
|
|
8
|
+
delete: ['headers', 'query', 'params'],
|
|
9
|
+
post: ['headers', 'query', 'params', 'body'],
|
|
10
|
+
put: ['headers', 'query', 'params', 'body'],
|
|
11
|
+
patch: ['headers', 'query', 'params', 'body']
|
|
12
|
+
};
|
|
13
|
+
const validateHeadersOrParams = (headersOrParams, entity) => {
|
|
14
|
+
const isHeadersOrParamsObject = (0, helpers_1.isPlainObject)(headersOrParams);
|
|
15
|
+
if (isHeadersOrParamsObject) {
|
|
16
|
+
Object.entries(headersOrParams).forEach(([headerOrParamKey, headerOrParamValue]) => {
|
|
17
|
+
if (typeof headerOrParamValue !== 'string') {
|
|
18
|
+
throw new Error(`${entity}.${headerOrParamKey}`);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(entity);
|
|
24
|
+
};
|
|
25
|
+
const validateQuery = (query, entity) => {
|
|
26
|
+
const isQueryObject = (0, helpers_1.isPlainObject)(query);
|
|
27
|
+
if (isQueryObject) {
|
|
28
|
+
Object.entries(query).forEach(([queryKey, queryValue]) => {
|
|
29
|
+
const isQueryValueArray = Array.isArray(queryValue);
|
|
30
|
+
if (isQueryValueArray) {
|
|
31
|
+
queryValue.forEach((queryValueElement, index) => {
|
|
32
|
+
if (typeof queryValueElement !== 'string') {
|
|
33
|
+
throw new Error(`${entity}.${queryKey}[${index}]`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (typeof queryValue !== 'string') {
|
|
39
|
+
throw new Error(`${entity}.${queryKey}`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(entity);
|
|
45
|
+
};
|
|
46
|
+
const validateEntities = (entities, method) => {
|
|
47
|
+
const isEntitiesObject = (0, helpers_1.isPlainObject)(entities);
|
|
48
|
+
if (isEntitiesObject) {
|
|
49
|
+
Object.keys(entities).forEach((entity) => {
|
|
50
|
+
const isEntityAllowed = ALLOWED_ENTITIES_BY_METHOD[method].includes(entity);
|
|
51
|
+
if (!isEntityAllowed) {
|
|
52
|
+
throw new Error(`entities.${entity}`);
|
|
53
|
+
}
|
|
54
|
+
if (entity === 'headers' || entity === 'params') {
|
|
55
|
+
try {
|
|
56
|
+
const headersOrParams = entities[entity];
|
|
57
|
+
return validateHeadersOrParams(headersOrParams, entity);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new Error(`entities.${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (entity === 'query') {
|
|
64
|
+
try {
|
|
65
|
+
const query = entities[entity];
|
|
66
|
+
return validateQuery(query, entity);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(`entities.${error.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (typeof entities !== 'undefined') {
|
|
76
|
+
throw new Error('entities');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const validateRoutes = (routes, method) => {
|
|
80
|
+
const isRoutesArray = Array.isArray(routes);
|
|
81
|
+
if (isRoutesArray) {
|
|
82
|
+
routes.forEach((route, index) => {
|
|
83
|
+
const isRouteObject = (0, helpers_1.isPlainObject)(route);
|
|
84
|
+
if (isRouteObject) {
|
|
85
|
+
const isRouteHasDataProperty = 'data' in route;
|
|
86
|
+
if (!isRouteHasDataProperty) {
|
|
87
|
+
throw new Error(`routes[${index}]`);
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
validateEntities(route.entities, method);
|
|
91
|
+
(0, validateInterceptors_1.validateInterceptors)(route.interceptors);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`routes[${index}].${error.message}`);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`routes[${index}]`);
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
throw new Error('routes');
|
|
103
|
+
};
|
|
104
|
+
exports.validateRoutes = validateRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateStaticPath: (staticPath: unknown) => void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateStaticPath = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateStaticPath = (staticPath) => {
|
|
6
|
+
const isStaticPathArray = Array.isArray(staticPath);
|
|
7
|
+
if (isStaticPathArray) {
|
|
8
|
+
staticPath.forEach((staticPathElement, index) => {
|
|
9
|
+
const isStaticPathElementObject = (0, helpers_1.isPlainObject)(staticPathElement);
|
|
10
|
+
if (isStaticPathElementObject) {
|
|
11
|
+
const { prefix, path } = staticPathElement;
|
|
12
|
+
if (typeof prefix !== 'string' || !prefix.startsWith('/')) {
|
|
13
|
+
throw new Error(`staticPath[${index}].prefix`);
|
|
14
|
+
}
|
|
15
|
+
if (typeof path !== 'string' || !path.startsWith('/')) {
|
|
16
|
+
throw new Error(`staticPath[${index}].path`);
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (typeof staticPathElement !== 'string' || !staticPathElement.startsWith('/')) {
|
|
21
|
+
throw new Error(`staticPath[${index}]`);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const isStaticPathObject = (0, helpers_1.isPlainObject)(staticPath);
|
|
27
|
+
if (isStaticPathObject) {
|
|
28
|
+
const { prefix, path } = staticPath;
|
|
29
|
+
if (typeof prefix !== 'string' || !prefix.startsWith('/')) {
|
|
30
|
+
throw new Error('staticPath.prefix');
|
|
31
|
+
}
|
|
32
|
+
if (typeof path !== 'string' || !path.startsWith('/')) {
|
|
33
|
+
throw new Error('staticPath.path');
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (typeof staticPath !== 'string' && typeof staticPath !== 'undefined') {
|
|
38
|
+
throw new Error('staticPath');
|
|
39
|
+
}
|
|
40
|
+
if (typeof staticPath === 'string' && !staticPath.startsWith('/')) {
|
|
41
|
+
throw new Error('staticPath');
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.validateStaticPath = validateStaticPath;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src';
|
|
1
|
+
export * from './src';
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./src"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src"), exports);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const isEntityValuesEqual: <Entity extends Entities>(firstEntityValue: EntitiesValues[Entity], secondEntityValue: EntitiesValues[Entity]) => boolean;
|
|
1
|
+
export declare const isEntityValuesEqual: (firstEntityValue: any, secondEntityValue: any) => boolean;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEntityValuesEqual = void 0;
|
|
4
|
-
const flat_1 = require("flat");
|
|
5
|
-
const helpers_1 = require("../../utils/helpers");
|
|
6
|
-
const isEntityValuesEqual = (firstEntityValue, secondEntityValue) => {
|
|
7
|
-
const isValuesArePlainObjects = (0, helpers_1.isPlainObject)(firstEntityValue) && (0, helpers_1.isPlainObject)(secondEntityValue);
|
|
8
|
-
if (isValuesArePlainObjects) {
|
|
9
|
-
const flattenFirstEntityValue = (0, flat_1.flatten)(firstEntityValue);
|
|
10
|
-
const flattenSecondEntityValue = (0, flat_1.flatten)(secondEntityValue);
|
|
11
|
-
return Object.keys(flattenFirstEntityValue).every((key) =>
|
|
12
|
-
// ✅ important:
|
|
13
|
-
// call 'toString' for ignore types of values
|
|
14
|
-
flattenFirstEntityValue[key].toString() === flattenSecondEntityValue[key]?.toString());
|
|
15
|
-
}
|
|
16
|
-
const isValuesAreArrays = Array.isArray(firstEntityValue) && Array.isArray(secondEntityValue);
|
|
17
|
-
if (isValuesAreArrays) {
|
|
18
|
-
const flattenFirstEntityValue = (0, flat_1.flatten)(firstEntityValue);
|
|
19
|
-
const flattenSecondEntityValue = (0, flat_1.flatten)(secondEntityValue);
|
|
20
|
-
return (Object.keys(flattenFirstEntityValue).length ===
|
|
21
|
-
Object.keys(flattenSecondEntityValue).length &&
|
|
22
|
-
Object.keys(flattenFirstEntityValue).every((key) =>
|
|
23
|
-
// ✅ important:
|
|
24
|
-
// call 'toString' for ignore types of values
|
|
25
|
-
flattenFirstEntityValue[key].toString() === flattenSecondEntityValue[key].toString()));
|
|
26
|
-
}
|
|
27
|
-
return firstEntityValue
|
|
28
|
-
};
|
|
29
|
-
exports.isEntityValuesEqual = isEntityValuesEqual;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntityValuesEqual = void 0;
|
|
4
|
+
const flat_1 = require("flat");
|
|
5
|
+
const helpers_1 = require("../../utils/helpers");
|
|
6
|
+
const isEntityValuesEqual = (firstEntityValue, secondEntityValue) => {
|
|
7
|
+
const isValuesArePlainObjects = (0, helpers_1.isPlainObject)(firstEntityValue) && (0, helpers_1.isPlainObject)(secondEntityValue);
|
|
8
|
+
if (isValuesArePlainObjects) {
|
|
9
|
+
const flattenFirstEntityValue = (0, flat_1.flatten)(firstEntityValue);
|
|
10
|
+
const flattenSecondEntityValue = (0, flat_1.flatten)(secondEntityValue);
|
|
11
|
+
return Object.keys(flattenFirstEntityValue).every((key) =>
|
|
12
|
+
// ✅ important:
|
|
13
|
+
// call 'toString' for ignore types of values
|
|
14
|
+
flattenFirstEntityValue[key].toString() === flattenSecondEntityValue[key]?.toString());
|
|
15
|
+
}
|
|
16
|
+
const isValuesAreArrays = Array.isArray(firstEntityValue) && Array.isArray(secondEntityValue);
|
|
17
|
+
if (isValuesAreArrays) {
|
|
18
|
+
const flattenFirstEntityValue = (0, flat_1.flatten)(firstEntityValue);
|
|
19
|
+
const flattenSecondEntityValue = (0, flat_1.flatten)(secondEntityValue);
|
|
20
|
+
return (Object.keys(flattenFirstEntityValue).length ===
|
|
21
|
+
Object.keys(flattenSecondEntityValue).length &&
|
|
22
|
+
Object.keys(flattenFirstEntityValue).every((key) =>
|
|
23
|
+
// ✅ important:
|
|
24
|
+
// call 'toString' for ignore types of values
|
|
25
|
+
flattenFirstEntityValue[key].toString() === flattenSecondEntityValue[key].toString()));
|
|
26
|
+
}
|
|
27
|
+
return `${firstEntityValue}` === `${secondEntityValue}`;
|
|
28
|
+
};
|
|
29
|
+
exports.isEntityValuesEqual = isEntityValuesEqual;
|