mock-config-server 2.4.0 → 3.0.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 +502 -326
- package/dist/bin/validateMockServerConfig/helpers/index.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/helpers/index.js +18 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.js +17 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +10 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +17 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +23 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +44 -18
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +38 -42
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +17 -6
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +7 -2
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +6 -5
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +18 -0
- package/dist/src/core/middlewares/index.d.ts +1 -0
- package/dist/src/core/middlewares/index.js +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.d.ts +1 -6
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +1 -1
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +2 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +19 -3
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +6 -1
- package/dist/src/server/createMockServer/createMockServer.js +2 -4
- 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/images/404.png +0 -0
- package/dist/src/static/views/assets/images/logo.png +0 -0
- 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/features/scheme/dark.css +12 -12
- package/dist/src/static/views/features/scheme/index.ejs +3 -3
- 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/pages/404/index.css +10 -10
- package/dist/src/static/views/pages/404/index.ejs +84 -84
- package/dist/src/utils/constants/checkModes.d.ts +9 -0
- package/dist/src/utils/constants/checkModes.js +31 -0
- package/dist/src/utils/constants/default.js +1 -1
- package/dist/src/utils/constants/index.d.ts +1 -0
- package/dist/src/utils/constants/index.js +1 -0
- package/dist/src/utils/helpers/asyncHandler.d.ts +2 -0
- package/dist/src/utils/helpers/asyncHandler.js +5 -0
- package/dist/src/utils/helpers/config/index.d.ts +1 -1
- package/dist/src/utils/helpers/config/index.js +1 -1
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.d.ts +2 -0
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +131 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.d.ts +2 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +8 -0
- package/dist/src/utils/helpers/entities/index.d.ts +2 -0
- package/dist/src/utils/helpers/entities/index.js +18 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +1 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +6 -0
- package/dist/src/utils/helpers/index.d.ts +4 -0
- package/dist/src/utils/helpers/index.js +4 -0
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +4 -1
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.d.ts +2 -0
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +5 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.d.ts +1 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +5 -0
- package/dist/src/utils/types/checkModes.d.ts +12 -0
- package/dist/src/utils/types/checkModes.js +2 -0
- package/dist/src/utils/types/graphql.d.ts +58 -18
- package/dist/src/utils/types/index.d.ts +1 -0
- package/dist/src/utils/types/index.js +1 -0
- package/dist/src/utils/types/interceptors.d.ts +4 -3
- package/dist/src/utils/types/rest.d.ts +61 -23
- package/dist/src/utils/types/server.d.ts +4 -3
- package/dist/src/utils/types/values.d.ts +1 -7
- package/package.json +113 -113
- package/dist/src/static/views/assets/images/success.png +0 -0
- package/dist/src/utils/helpers/config/isEntitiesEqual/isEntityValuesEqual.d.ts +0 -1
- package/dist/src/utils/helpers/config/isEntitiesEqual/isEntityValuesEqual.js +0 -29
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
|
|
8
|
-
<title>404 - 🎉 Mock Config Server</title>
|
|
9
|
-
|
|
10
|
-
<link rel="stylesheet" href="/assets/styles/global.css" />
|
|
11
|
-
<link rel="stylesheet" href="/pages/404/index.css" />
|
|
12
|
-
|
|
13
|
-
<% const api = { rest: "REST", graphql: "GraphQL" } %>
|
|
14
|
-
|
|
15
|
-
<% const rootPath = (path) => `../../${path}` %>
|
|
16
|
-
<%- include(rootPath('features/scheme/index')) -%>
|
|
17
|
-
<%- include(rootPath('features/tab/index')) -%>
|
|
18
|
-
</head>
|
|
19
|
-
|
|
20
|
-
<body class="tab-item-<%= graphqlRequestSuggestions.length ? api.graphql : api.rest %>">
|
|
21
|
-
<%- include(rootPath('components/header/index')) -%>
|
|
22
|
-
<div class="margin-container">
|
|
23
|
-
<div class="hero">
|
|
24
|
-
<div class="title">
|
|
25
|
-
<img src="/assets/images/404.png" />
|
|
26
|
-
404
|
|
27
|
-
</div>
|
|
28
|
-
<div class="description">
|
|
29
|
-
Such request or page not found ☹️
|
|
30
|
-
<a class="link" href="/">
|
|
31
|
-
Return on main page
|
|
32
|
-
</a>
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
<div class="margin-container">
|
|
37
|
-
<div class="content">
|
|
38
|
-
<div class="content-head">
|
|
39
|
-
<div class="tab-items">
|
|
40
|
-
<% Object.values(api).forEach((variant)=> { %>
|
|
41
|
-
<div id="tab-item-<%=variant%>" class="tab-item">
|
|
42
|
-
<%=variant%>
|
|
43
|
-
</div>
|
|
44
|
-
<% }) %>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
<div id="tab-content-<%=api.rest%>" class="tab-content">
|
|
48
|
-
<div class="description">
|
|
49
|
-
<% if (restRequestSuggestions.length) { %>
|
|
50
|
-
<span>We searched a bit, maybe this will help you:</span>
|
|
51
|
-
<% restRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
52
|
-
<span><%= requestSuggestion.method.toUpperCase() %> <%=
|
|
53
|
-
requestSuggestion.path %></span>
|
|
54
|
-
<% })} else { %>
|
|
55
|
-
<span>We searched, but found nothing.</span>
|
|
56
|
-
<span>Maybe you don't have <%=api.rest%> configs? 👀</span>
|
|
57
|
-
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
58
|
-
Read documentation 📘 for more information
|
|
59
|
-
</a>
|
|
60
|
-
<% } %>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<div id="tab-content-<%=api.graphql%>" class="tab-content">
|
|
65
|
-
<div class="description">
|
|
66
|
-
<% if (graphqlRequestSuggestions.length) { %>
|
|
67
|
-
<span>We searched a bit, maybe this will help you:</span>
|
|
68
|
-
<% graphqlRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
69
|
-
<span><%= requestSuggestion.operationType %> <%=
|
|
70
|
-
requestSuggestion.operationName %></span>
|
|
71
|
-
<% })} else { %>
|
|
72
|
-
<span>We searched, but found nothing.</span>
|
|
73
|
-
<span>Maybe you don't have <%=api.graphql%> configs? 👀</span>
|
|
74
|
-
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
75
|
-
Read documentation 📘 for more information
|
|
76
|
-
</a>
|
|
77
|
-
<% } %>
|
|
78
|
-
</div>
|
|
79
|
-
</div>
|
|
80
|
-
</div>
|
|
81
|
-
</div>
|
|
82
|
-
</div>
|
|
83
|
-
</body>
|
|
84
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
|
|
8
|
+
<title>404 - 🎉 Mock Config Server</title>
|
|
9
|
+
|
|
10
|
+
<link rel="stylesheet" href="/assets/styles/global.css" />
|
|
11
|
+
<link rel="stylesheet" href="/pages/404/index.css" />
|
|
12
|
+
|
|
13
|
+
<% const api = { rest: "REST", graphql: "GraphQL" } %>
|
|
14
|
+
|
|
15
|
+
<% const rootPath = (path) => `../../${path}` %>
|
|
16
|
+
<%- include(rootPath('features/scheme/index')) -%>
|
|
17
|
+
<%- include(rootPath('features/tab/index')) -%>
|
|
18
|
+
</head>
|
|
19
|
+
|
|
20
|
+
<body class="tab-item-<%= graphqlRequestSuggestions.length ? api.graphql : api.rest %>">
|
|
21
|
+
<%- include(rootPath('components/header/index')) -%>
|
|
22
|
+
<div class="margin-container">
|
|
23
|
+
<div class="hero">
|
|
24
|
+
<div class="title">
|
|
25
|
+
<img src="/assets/images/404.png" />
|
|
26
|
+
404
|
|
27
|
+
</div>
|
|
28
|
+
<div class="description">
|
|
29
|
+
Such request or page not found ☹️
|
|
30
|
+
<a class="link" href="/">
|
|
31
|
+
Return on main page
|
|
32
|
+
</a>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="margin-container">
|
|
37
|
+
<div class="content">
|
|
38
|
+
<div class="content-head">
|
|
39
|
+
<div class="tab-items">
|
|
40
|
+
<% Object.values(api).forEach((variant)=> { %>
|
|
41
|
+
<div id="tab-item-<%=variant%>" class="tab-item">
|
|
42
|
+
<%=variant%>
|
|
43
|
+
</div>
|
|
44
|
+
<% }) %>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<div id="tab-content-<%=api.rest%>" class="tab-content">
|
|
48
|
+
<div class="description">
|
|
49
|
+
<% if (restRequestSuggestions.length) { %>
|
|
50
|
+
<span>We searched a bit, maybe this will help you:</span>
|
|
51
|
+
<% restRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
52
|
+
<span><%= requestSuggestion.method.toUpperCase() %> <%=
|
|
53
|
+
requestSuggestion.path %></span>
|
|
54
|
+
<% })} else { %>
|
|
55
|
+
<span>We searched, but found nothing.</span>
|
|
56
|
+
<span>Maybe you don't have <%=api.rest%> configs? 👀</span>
|
|
57
|
+
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
58
|
+
Read documentation 📘 for more information
|
|
59
|
+
</a>
|
|
60
|
+
<% } %>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div id="tab-content-<%=api.graphql%>" class="tab-content">
|
|
65
|
+
<div class="description">
|
|
66
|
+
<% if (graphqlRequestSuggestions.length) { %>
|
|
67
|
+
<span>We searched a bit, maybe this will help you:</span>
|
|
68
|
+
<% graphqlRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
69
|
+
<span><%= requestSuggestion.operationType %> <%=
|
|
70
|
+
requestSuggestion.operationName %></span>
|
|
71
|
+
<% })} else { %>
|
|
72
|
+
<span>We searched, but found nothing.</span>
|
|
73
|
+
<span>Maybe you don't have <%=api.graphql%> configs? 👀</span>
|
|
74
|
+
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
75
|
+
Read documentation 📘 for more information
|
|
76
|
+
</a>
|
|
77
|
+
<% } %>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</body>
|
|
84
|
+
|
|
85
85
|
</html>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CalculateByDescriptorValueCheckMode, CheckMode, CompareWithDescriptorValueCheckMode, CheckActualValueCheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorStringValueCheckMode } from '../types';
|
|
2
|
+
export declare const CHECK_ACTUAL_VALUE_CHECK_MODES: CheckActualValueCheckMode[];
|
|
3
|
+
export declare const COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES: CompareWithDescriptorAnyValueCheckMode[];
|
|
4
|
+
export declare const COMPARE_WITH_DESCRIPTOR_STRING_VALUE_CHECK_MODES: CompareWithDescriptorStringValueCheckMode[];
|
|
5
|
+
export declare const COMPARE_WITH_DESCRIPTOR_VALUE_CHECK_MODES: CompareWithDescriptorValueCheckMode[];
|
|
6
|
+
export declare const CALCULATE_BY_DESCRIPTOR_VALUE_CHECK_MODES: CalculateByDescriptorValueCheckMode[];
|
|
7
|
+
export declare const CHECK_MODES: CheckMode[];
|
|
8
|
+
export declare const PLAIN_ENTITY_CHECK_MODES: CheckMode[];
|
|
9
|
+
export declare const NEGATION_CHECK_MODES: CheckMode[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NEGATION_CHECK_MODES = exports.PLAIN_ENTITY_CHECK_MODES = exports.CHECK_MODES = exports.CALCULATE_BY_DESCRIPTOR_VALUE_CHECK_MODES = exports.COMPARE_WITH_DESCRIPTOR_VALUE_CHECK_MODES = exports.COMPARE_WITH_DESCRIPTOR_STRING_VALUE_CHECK_MODES = exports.COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES = exports.CHECK_ACTUAL_VALUE_CHECK_MODES = void 0;
|
|
4
|
+
exports.CHECK_ACTUAL_VALUE_CHECK_MODES = ['exists', 'notExists'];
|
|
5
|
+
exports.COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES = ['equals', 'notEquals'];
|
|
6
|
+
exports.COMPARE_WITH_DESCRIPTOR_STRING_VALUE_CHECK_MODES = ['includes', 'notIncludes', 'startsWith', 'notStartsWith', 'endsWith', 'notEndsWith'];
|
|
7
|
+
exports.COMPARE_WITH_DESCRIPTOR_VALUE_CHECK_MODES = [
|
|
8
|
+
...exports.COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES,
|
|
9
|
+
...exports.COMPARE_WITH_DESCRIPTOR_STRING_VALUE_CHECK_MODES
|
|
10
|
+
];
|
|
11
|
+
exports.CALCULATE_BY_DESCRIPTOR_VALUE_CHECK_MODES = [
|
|
12
|
+
'regExp',
|
|
13
|
+
'function'
|
|
14
|
+
];
|
|
15
|
+
exports.CHECK_MODES = [
|
|
16
|
+
...exports.CHECK_ACTUAL_VALUE_CHECK_MODES,
|
|
17
|
+
...exports.COMPARE_WITH_DESCRIPTOR_VALUE_CHECK_MODES,
|
|
18
|
+
...exports.CALCULATE_BY_DESCRIPTOR_VALUE_CHECK_MODES
|
|
19
|
+
];
|
|
20
|
+
exports.PLAIN_ENTITY_CHECK_MODES = [
|
|
21
|
+
...exports.CHECK_ACTUAL_VALUE_CHECK_MODES,
|
|
22
|
+
...exports.COMPARE_WITH_DESCRIPTOR_ANY_VALUE_CHECK_MODES,
|
|
23
|
+
'function'
|
|
24
|
+
];
|
|
25
|
+
exports.NEGATION_CHECK_MODES = [
|
|
26
|
+
'notExists',
|
|
27
|
+
'notEquals',
|
|
28
|
+
'notIncludes',
|
|
29
|
+
'notStartsWith',
|
|
30
|
+
'notEndsWith'
|
|
31
|
+
];
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./appPath"), exports);
|
|
18
|
+
__exportStar(require("./checkModes"), exports);
|
|
18
19
|
__exportStar(require("./default"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './resolveEntityValues/resolveEntityValues';
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./resolveEntityValues/resolveEntityValues"), exports);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEntityValues = void 0;
|
|
4
|
+
const flat_1 = require("flat");
|
|
5
|
+
const constants_1 = require("../../../constants");
|
|
6
|
+
const isPlainObject_1 = require("../../isPlainObject/isPlainObject");
|
|
7
|
+
const isPrimitive_1 = require("../../isPrimitive/isPrimitive");
|
|
8
|
+
const isRegExp_1 = require("../../isRegExp/isRegExp");
|
|
9
|
+
const checkFunction = (checkMode, actualValue, descriptorValue) => {
|
|
10
|
+
if (checkMode === 'function' && typeof descriptorValue === 'function')
|
|
11
|
+
return descriptorValue(actualValue, checkFunction);
|
|
12
|
+
const actualValueString = String(actualValue);
|
|
13
|
+
if (checkMode === 'regExp' && (0, isRegExp_1.isRegExp)(descriptorValue))
|
|
14
|
+
return descriptorValue.test(actualValueString);
|
|
15
|
+
const isActualValueUndefined = typeof actualValue === 'undefined';
|
|
16
|
+
if (checkMode === 'exists')
|
|
17
|
+
return !isActualValueUndefined;
|
|
18
|
+
if (checkMode === 'notExists')
|
|
19
|
+
return isActualValueUndefined;
|
|
20
|
+
// ✅ important:
|
|
21
|
+
// cast values to string for ignore types of values
|
|
22
|
+
const descriptorValueString = String(descriptorValue);
|
|
23
|
+
if (checkMode === 'equals')
|
|
24
|
+
return actualValueString === descriptorValueString;
|
|
25
|
+
if (checkMode === 'notEquals')
|
|
26
|
+
return actualValueString !== descriptorValueString;
|
|
27
|
+
if (checkMode === 'includes')
|
|
28
|
+
return actualValueString.includes(descriptorValueString);
|
|
29
|
+
if (checkMode === 'notIncludes')
|
|
30
|
+
return !actualValueString.includes(descriptorValueString);
|
|
31
|
+
if (checkMode === 'startsWith')
|
|
32
|
+
return actualValueString.startsWith(descriptorValueString);
|
|
33
|
+
if (checkMode === 'notStartsWith')
|
|
34
|
+
return !actualValueString.startsWith(descriptorValueString);
|
|
35
|
+
if (checkMode === 'endsWith')
|
|
36
|
+
return actualValueString.endsWith(descriptorValueString);
|
|
37
|
+
if (checkMode === 'notEndsWith')
|
|
38
|
+
return !actualValueString.endsWith(descriptorValueString);
|
|
39
|
+
throw new Error('Wrong checkMode');
|
|
40
|
+
};
|
|
41
|
+
const resolveEntityValues = (checkMode, actualValue, descriptorValue) => {
|
|
42
|
+
if (checkMode === 'function')
|
|
43
|
+
return descriptorValue(actualValue, checkFunction);
|
|
44
|
+
if (checkMode === 'exists' || checkMode === 'notExists')
|
|
45
|
+
return checkFunction(checkMode, actualValue, descriptorValue);
|
|
46
|
+
// ✅ actual: primitive, descriptor: primitive
|
|
47
|
+
const isActualValuePrimitive = (0, isPrimitive_1.isPrimitive)(actualValue);
|
|
48
|
+
const isDescriptorValuePrimitive = (0, isPrimitive_1.isPrimitive)(descriptorValue);
|
|
49
|
+
if (isActualValuePrimitive && isDescriptorValuePrimitive)
|
|
50
|
+
return checkFunction(checkMode, actualValue, descriptorValue);
|
|
51
|
+
// ✅ actual: primitive, descriptor: array
|
|
52
|
+
const isDescriptorValueArray = Array.isArray(descriptorValue);
|
|
53
|
+
const isNegativeCheckMode = constants_1.NEGATION_CHECK_MODES.includes(checkMode);
|
|
54
|
+
if (isActualValuePrimitive && isDescriptorValueArray) {
|
|
55
|
+
if (isNegativeCheckMode) {
|
|
56
|
+
return descriptorValue.every((descriptorValueElement) => checkFunction(checkMode, actualValue, descriptorValueElement));
|
|
57
|
+
}
|
|
58
|
+
return descriptorValue.some((descriptorValueElement) => checkFunction(checkMode, actualValue, descriptorValueElement));
|
|
59
|
+
}
|
|
60
|
+
// ✅ actual: primitive, descriptor: object => skip
|
|
61
|
+
const isDescriptorValueObject = (0, isPlainObject_1.isPlainObject)(descriptorValue) || (0, isRegExp_1.isRegExp)(descriptorValue);
|
|
62
|
+
if (isActualValuePrimitive && isDescriptorValueObject) {
|
|
63
|
+
if (checkMode === 'regExp')
|
|
64
|
+
return checkFunction(checkMode, actualValue, descriptorValue);
|
|
65
|
+
// ✅ important: resolving primitive with object make no sense
|
|
66
|
+
return isNegativeCheckMode;
|
|
67
|
+
}
|
|
68
|
+
// ✅ actual: array, descriptor: primitive => skip
|
|
69
|
+
const isActualValueArray = Array.isArray(actualValue);
|
|
70
|
+
// ✅ important: resolving array with primitive make no sense
|
|
71
|
+
if (isActualValueArray && isDescriptorValuePrimitive)
|
|
72
|
+
return isNegativeCheckMode;
|
|
73
|
+
// ✅ actual: array, descriptor: array
|
|
74
|
+
if (isActualValueArray && isDescriptorValueArray) {
|
|
75
|
+
if (actualValue.length !== descriptorValue.length)
|
|
76
|
+
return isNegativeCheckMode;
|
|
77
|
+
const flattenActualValue = (0, flat_1.flatten)(actualValue);
|
|
78
|
+
const flattenDescriptorValue = (0, flat_1.flatten)(descriptorValue);
|
|
79
|
+
if (Object.keys(flattenActualValue).length === Object.keys(flattenDescriptorValue).length)
|
|
80
|
+
return Object.keys(flattenDescriptorValue).every((flattenDescriptorValueKey) => checkFunction(checkMode, flattenActualValue[flattenDescriptorValueKey], flattenDescriptorValue[flattenDescriptorValueKey]));
|
|
81
|
+
return isNegativeCheckMode;
|
|
82
|
+
}
|
|
83
|
+
// ✅ actual: array, descriptor: object => skip
|
|
84
|
+
if (isActualValueArray && isDescriptorValueObject) {
|
|
85
|
+
if (checkMode === 'regExp')
|
|
86
|
+
return actualValue.some((actualValueElement) => checkFunction(checkMode, actualValueElement, descriptorValue));
|
|
87
|
+
// ✅ important: resolving array with object make no sense
|
|
88
|
+
return isNegativeCheckMode;
|
|
89
|
+
}
|
|
90
|
+
// ✅ actual: object, descriptor: primitive => skip
|
|
91
|
+
const isActualValueObject = (0, isPlainObject_1.isPlainObject)(actualValue);
|
|
92
|
+
// ✅ important: resolving object with primitive make no sense
|
|
93
|
+
if (isActualValueObject && isDescriptorValuePrimitive)
|
|
94
|
+
return isNegativeCheckMode;
|
|
95
|
+
// ✅ actual: object, descriptor: array
|
|
96
|
+
if (isActualValueObject && isDescriptorValueArray) {
|
|
97
|
+
// ✅ important: any object can not pass RegExp check
|
|
98
|
+
if (checkMode === 'regExp')
|
|
99
|
+
return false;
|
|
100
|
+
const flattenActualValue = (0, flat_1.flatten)(actualValue);
|
|
101
|
+
if (isNegativeCheckMode) {
|
|
102
|
+
return descriptorValue.every((descriptorValueElement) => {
|
|
103
|
+
const flattenDescriptorValue = (0, flat_1.flatten)(descriptorValueElement);
|
|
104
|
+
if (Object.keys(flattenActualValue).length !== Object.keys(flattenDescriptorValue).length)
|
|
105
|
+
return isNegativeCheckMode;
|
|
106
|
+
return Object.keys(flattenActualValue).every((flattenActualValueKey) => checkFunction(checkMode, flattenActualValue[flattenActualValueKey], flattenDescriptorValue[flattenActualValueKey]));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return descriptorValue.some((descriptorValueElement) => {
|
|
110
|
+
const flattenDescriptorValue = (0, flat_1.flatten)(descriptorValueElement);
|
|
111
|
+
if (Object.keys(flattenActualValue).length !== Object.keys(flattenDescriptorValue).length)
|
|
112
|
+
return isNegativeCheckMode;
|
|
113
|
+
return Object.keys(flattenActualValue).every((flattenActualValueKey) => checkFunction(checkMode, flattenActualValue[flattenActualValueKey], flattenDescriptorValue[flattenActualValueKey]));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// ✅ actual: object, descriptor: object
|
|
117
|
+
if (isActualValueObject && isDescriptorValueObject) {
|
|
118
|
+
// ✅ important: any object can not pass RegExp check
|
|
119
|
+
if (checkMode === 'regExp')
|
|
120
|
+
return false;
|
|
121
|
+
const flattenActualValue = (0, flat_1.flatten)(actualValue);
|
|
122
|
+
const flattenDescriptorValue = (0, flat_1.flatten)(descriptorValue);
|
|
123
|
+
if (Object.keys(flattenActualValue).length !== Object.keys(flattenDescriptorValue).length)
|
|
124
|
+
return isNegativeCheckMode;
|
|
125
|
+
if (isNegativeCheckMode) {
|
|
126
|
+
return Object.keys(flattenDescriptorValue).some((flattenDescriptorValueKey) => checkFunction(checkMode, flattenActualValue[flattenDescriptorValueKey], flattenDescriptorValue[flattenDescriptorValueKey]));
|
|
127
|
+
}
|
|
128
|
+
return Object.keys(flattenDescriptorValue).every((flattenDescriptorValueKey) => checkFunction(checkMode, flattenActualValue[flattenDescriptorValueKey], flattenDescriptorValue[flattenDescriptorValueKey]));
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
exports.resolveEntityValues = resolveEntityValues;
|
package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToEntityDescriptor = void 0;
|
|
4
|
+
const isEntityDescriptor_1 = require("../isEntityDescriptor/isEntityDescriptor");
|
|
5
|
+
const convertToEntityDescriptor = (valueOrDescriptor) => (0, isEntityDescriptor_1.isEntityDescriptor)(valueOrDescriptor)
|
|
6
|
+
? valueOrDescriptor
|
|
7
|
+
: { checkMode: 'equals', value: valueOrDescriptor };
|
|
8
|
+
exports.convertToEntityDescriptor = convertToEntityDescriptor;
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./convertToEntityDescriptor/convertToEntityDescriptor"), exports);
|
|
18
|
+
__exportStar(require("./isEntityDescriptor/isEntityDescriptor"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEntityDescriptor: (value: any) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntityDescriptor = void 0;
|
|
4
|
+
const isPlainObject_1 = require("../../isPlainObject/isPlainObject");
|
|
5
|
+
const isEntityDescriptor = (value) => (0, isPlainObject_1.isPlainObject)(value) && 'checkMode' in value;
|
|
6
|
+
exports.isEntityDescriptor = isEntityDescriptor;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export * from './isPlainObject/isPlainObject';
|
|
2
|
+
export * from './isPrimitive/isPrimitive';
|
|
3
|
+
export * from './isRegExp/isRegExp';
|
|
2
4
|
export * from './sleep';
|
|
3
5
|
export * from './url';
|
|
4
6
|
export * from './config';
|
|
7
|
+
export * from './entities';
|
|
5
8
|
export * from './interceptors';
|
|
6
9
|
export * from './graphql';
|
|
10
|
+
export * from './asyncHandler';
|
|
@@ -15,8 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./isPlainObject/isPlainObject"), exports);
|
|
18
|
+
__exportStar(require("./isPrimitive/isPrimitive"), exports);
|
|
19
|
+
__exportStar(require("./isRegExp/isRegExp"), exports);
|
|
18
20
|
__exportStar(require("./sleep"), exports);
|
|
19
21
|
__exportStar(require("./url"), exports);
|
|
20
22
|
__exportStar(require("./config"), exports);
|
|
23
|
+
__exportStar(require("./entities"), exports);
|
|
21
24
|
__exportStar(require("./interceptors"), exports);
|
|
22
25
|
__exportStar(require("./graphql"), exports);
|
|
26
|
+
__exportStar(require("./asyncHandler"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPlainObject = void 0;
|
|
4
|
-
const isPlainObject = (value) => typeof value === 'object' &&
|
|
4
|
+
const isPlainObject = (value) => typeof value === 'object' &&
|
|
5
|
+
!Array.isArray(value) &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
!(value instanceof RegExp);
|
|
5
8
|
exports.isPlainObject = isPlainObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isRegExp: (value: any) => value is RegExp;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CheckActualValueCheckMode = 'exists' | 'notExists';
|
|
2
|
+
export type CompareWithDescriptorAnyValueCheckMode = 'equals' | 'notEquals';
|
|
3
|
+
export type CompareWithDescriptorStringValueCheckMode = 'includes' | 'notIncludes' | 'startsWith' | 'notStartsWith' | 'endsWith' | 'notEndsWith';
|
|
4
|
+
export type CompareWithDescriptorValueCheckMode = CompareWithDescriptorAnyValueCheckMode | CompareWithDescriptorStringValueCheckMode;
|
|
5
|
+
export type CalculateByDescriptorValueCheckMode = 'regExp' | 'function';
|
|
6
|
+
export type CheckMode = CheckActualValueCheckMode | CompareWithDescriptorValueCheckMode | CalculateByDescriptorValueCheckMode;
|
|
7
|
+
export type PlainEntityCheckMode = Exclude<CheckMode, CompareWithDescriptorStringValueCheckMode | Extract<CalculateByDescriptorValueCheckMode, 'regExp'>>;
|
|
8
|
+
export interface EntityDescriptor {
|
|
9
|
+
checkMode: CheckMode;
|
|
10
|
+
value?: any;
|
|
11
|
+
}
|
|
12
|
+
export type CheckFunction = <ActualValue = any, DescriptorValue = any>(checkMode: CheckMode, actualValue: ActualValue, descriptorValue?: DescriptorValue) => boolean;
|
|
@@ -1,34 +1,74 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
|
+
import type { CalculateByDescriptorValueCheckMode, CheckActualValueCheckMode, CheckFunction, CheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorValueCheckMode } from './checkModes';
|
|
2
3
|
import type { Interceptors } from './interceptors';
|
|
3
|
-
import type { Data,
|
|
4
|
-
export type
|
|
4
|
+
import type { Data, Primitive } from './values';
|
|
5
|
+
export type GraphQLEntityName = 'headers' | 'cookies' | 'query' | 'variables';
|
|
6
|
+
export type GraphQLMappedEntityName = string;
|
|
7
|
+
type GraphQLMappedEntityValue = string | number | boolean;
|
|
8
|
+
type GraphQLPlainEntityInnerValue = {
|
|
9
|
+
checkMode?: undefined;
|
|
10
|
+
call?: undefined;
|
|
11
|
+
dotAll?: undefined;
|
|
12
|
+
[key: string]: Primitive | GraphQLPlainEntityInnerValue;
|
|
13
|
+
};
|
|
14
|
+
type GraphQLPlainEntityValue = {
|
|
15
|
+
checkMode?: undefined;
|
|
16
|
+
call?: undefined;
|
|
17
|
+
forEach?: undefined;
|
|
18
|
+
dotAll?: undefined;
|
|
19
|
+
[key: string]: GraphQLPlainEntityInnerValue | Primitive | GraphQLEntityDescriptor;
|
|
20
|
+
};
|
|
21
|
+
export type GraphQLOperationType = 'query' | 'mutation';
|
|
22
|
+
type GraphQLOperationName = string | RegExp;
|
|
23
|
+
interface GraphQLQuery {
|
|
24
|
+
operationType: GraphQLOperationType;
|
|
25
|
+
operationName: GraphQLOperationName;
|
|
26
|
+
}
|
|
27
|
+
type GraphQLVariables = Record<string, any>;
|
|
5
28
|
export interface GraphQLInput {
|
|
6
29
|
query?: string;
|
|
7
30
|
variables: GraphQLVariables;
|
|
8
31
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
32
|
+
type GraphQLEntityValue<EntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLPlainEntityValue : GraphQLMappedEntityValue;
|
|
33
|
+
type GraphQLEntityValueOrValues<EntityName = GraphQLEntityName> = GraphQLEntityValue<EntityName> | GraphQLEntityValue<EntityName>[];
|
|
34
|
+
type GraphQLEntityDescriptor<EntityName extends GraphQLEntityName = GraphQLEntityName, Check extends CheckMode = CheckMode> = EntityName extends 'variables' ? Check extends Extract<CalculateByDescriptorValueCheckMode, 'function'> ? {
|
|
35
|
+
checkMode: Check;
|
|
36
|
+
value: (actualValue: any, checkFunction: CheckFunction) => boolean;
|
|
37
|
+
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
38
|
+
checkMode: Check;
|
|
39
|
+
value: GraphQLEntityValueOrValues<EntityName>;
|
|
40
|
+
} : Check extends CheckActualValueCheckMode ? {
|
|
41
|
+
checkMode: Check;
|
|
42
|
+
value?: undefined;
|
|
43
|
+
} : never : Check extends Extract<CalculateByDescriptorValueCheckMode, 'function'> ? {
|
|
44
|
+
checkMode: Check;
|
|
45
|
+
value: (actualValue: any, checkFunction: CheckFunction) => boolean;
|
|
46
|
+
} : Check extends Extract<CalculateByDescriptorValueCheckMode, 'regExp'> ? {
|
|
47
|
+
checkMode: Check;
|
|
48
|
+
value: RegExp | RegExp[];
|
|
49
|
+
} : Check extends CompareWithDescriptorValueCheckMode ? {
|
|
50
|
+
checkMode: Check;
|
|
51
|
+
value: GraphQLEntityValueOrValues<EntityName>;
|
|
52
|
+
} : Check extends CheckActualValueCheckMode ? {
|
|
53
|
+
checkMode: Check;
|
|
54
|
+
value?: undefined;
|
|
55
|
+
} : never;
|
|
56
|
+
export type GraphQLEntityDescriptorOrValue<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLEntityDescriptor<EntityName> | GraphQLEntityValue<EntityName> : Record<GraphQLMappedEntityName, GraphQLEntityDescriptor<EntityName> | GraphQLEntityValueOrValues<EntityName>>;
|
|
57
|
+
export type GraphQLEntityDescriptorOnly<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLEntityDescriptor<EntityName> : Record<GraphQLMappedEntityName, GraphQLEntityDescriptor<EntityName>>;
|
|
58
|
+
export interface GraphQLEntityNamesByOperationType {
|
|
59
|
+
query: GraphQLEntityName;
|
|
60
|
+
mutation: GraphQLEntityName;
|
|
16
61
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export type GraphQLRouteConfigEntities = {
|
|
20
|
-
[Key in GraphQLOperationsEntities[GraphQLOperationType]]?: GraphQLEntitiesValues[Key];
|
|
62
|
+
type GraphQLEntityByEntityName<OperationType extends GraphQLOperationType> = {
|
|
63
|
+
[EntityName in GraphQLEntityNamesByOperationType[OperationType]]?: GraphQLEntityDescriptorOrValue<EntityName>;
|
|
21
64
|
};
|
|
22
|
-
export interface GraphQLRouteConfig<
|
|
65
|
+
export interface GraphQLRouteConfig<OperationType extends GraphQLOperationType = GraphQLOperationType, Entities extends GraphQLEntityByEntityName<OperationType> = GraphQLEntityByEntityName<OperationType>> {
|
|
23
66
|
entities?: Entities;
|
|
24
67
|
data: ((request: Request, entities: Entities) => Data | Promise<Data>) | Data;
|
|
25
68
|
interceptors?: Pick<Interceptors, 'response'>;
|
|
26
69
|
}
|
|
27
|
-
export interface GraphQLQuery {
|
|
28
|
-
operationType: GraphQLOperationType;
|
|
29
|
-
operationName: GraphQLOperationName;
|
|
30
|
-
}
|
|
31
70
|
export interface GraphQLRequestConfig extends GraphQLQuery {
|
|
32
71
|
routes: GraphQLRouteConfig[];
|
|
33
72
|
interceptors?: Interceptors;
|
|
34
73
|
}
|
|
74
|
+
export {};
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./checkModes"), exports);
|
|
17
18
|
__exportStar(require("./graphql"), exports);
|
|
18
19
|
__exportStar(require("./interceptors"), exports);
|
|
19
20
|
__exportStar(require("./rest"), exports);
|