mock-config-server 3.0.0 → 3.1.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/LICENSE +21 -21
- package/README.md +614 -502
- package/dist/bin/bin.d.ts +2 -0
- package/dist/bin/bin.js +13 -0
- package/dist/bin/build.d.ts +2 -0
- package/dist/bin/build.js +55 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +41 -0
- package/dist/bin/helpers/index.d.ts +3 -0
- package/dist/bin/helpers/index.js +38 -0
- package/dist/bin/helpers/resolveConfigFile.d.ts +2 -0
- package/dist/bin/helpers/resolveConfigFile.js +23 -0
- package/dist/bin/helpers/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/helpers/resolveConfigFilePath.js +16 -0
- package/dist/bin/helpers/resolveExportsFromSourceCode.d.ts +1 -0
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +14 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +16 -0
- package/dist/bin/run.d.ts +6 -0
- package/dist/bin/run.js +22 -0
- package/dist/bin/validateMockServerConfig/helpers/index.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/helpers/index.js +27 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.js +16 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +12 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +16 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +20 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +15 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +84 -0
- 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.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +52 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +104 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +27 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +32 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +12 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +57 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +108 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +53 -0
- package/dist/index.d.ts +1 -0
- 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.d.ts +3 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +102 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.d.ts +1 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +16 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +41 -0
- package/dist/src/core/graphql/index.d.ts +1 -0
- package/dist/src/core/graphql/index.js +16 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +18 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.d.ts +1 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +16 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.d.ts +3 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +19 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +52 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.d.ts +2 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +16 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.d.ts +1 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +16 -0
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.d.ts +7 -0
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +26 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +21 -0
- package/dist/src/core/middlewares/index.d.ts +8 -0
- package/dist/src/core/middlewares/index.js +93 -0
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +24 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +11 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +27 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +84 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +11 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +39 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +8 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +8 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.d.ts +2 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +27 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.d.ts +3 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +38 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +68 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +17 -0
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +31 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +3 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +75 -0
- package/dist/src/core/rest/createRestRoutes/helpers/index.d.ts +1 -0
- package/dist/src/core/rest/createRestRoutes/helpers/index.js +16 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +43 -0
- package/dist/src/core/rest/index.d.ts +1 -0
- package/dist/src/core/rest/index.js +16 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +38 -0
- package/dist/src/server/createMockServer/createMockServer.d.ts +3 -0
- package/dist/src/server/createMockServer/createMockServer.js +79 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.js +27 -0
- package/dist/src/server/startMockServer/startMockServer.d.ts +5 -0
- package/dist/src/server/startMockServer/startMockServer.js +23 -0
- package/dist/src/static/views/assets/icons/scheme-dark.svg +3 -0
- package/dist/src/static/views/assets/icons/scheme-light.svg +3 -0
- 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 -0
- package/dist/src/static/views/components/header/index.css +55 -0
- package/dist/src/static/views/components/header/index.ejs +40 -0
- package/dist/src/static/views/components/header/index.js +1 -0
- package/dist/src/static/views/features/scheme/dark.css +12 -0
- package/dist/src/static/views/features/scheme/index.ejs +3 -0
- package/dist/src/static/views/features/scheme/index.js +31 -0
- package/dist/src/static/views/features/scheme/light.css +12 -0
- package/dist/src/static/views/features/tab/index.css +30 -0
- package/dist/src/static/views/features/tab/index.ejs +2 -0
- package/dist/src/static/views/features/tab/index.js +12 -0
- package/dist/src/static/views/pages/404/index.css +10 -0
- package/dist/src/static/views/pages/404/index.ejs +85 -0
- package/dist/src/utils/constants/appPath.d.ts +1 -0
- package/dist/src/utils/constants/appPath.js +8 -0
- package/dist/src/utils/constants/checkModes.d.ts +9 -0
- package/dist/src/utils/constants/checkModes.js +22 -0
- package/dist/src/utils/constants/default.d.ts +11 -0
- package/dist/src/utils/constants/default.js +18 -0
- package/dist/src/utils/constants/index.d.ts +3 -0
- package/dist/src/utils/constants/index.js +38 -0
- package/dist/src/utils/helpers/asyncHandler.d.ts +2 -0
- package/dist/src/utils/helpers/asyncHandler.js +8 -0
- package/dist/src/utils/helpers/config/index.d.ts +1 -0
- package/dist/src/utils/helpers/config/index.js +16 -0
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.d.ts +2 -0
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +118 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.d.ts +2 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +12 -0
- package/dist/src/utils/helpers/entities/index.d.ts +2 -0
- package/dist/src/utils/helpers/entities/index.js +27 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +1 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +9 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +31 -0
- package/dist/src/utils/helpers/graphql/index.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/index.js +38 -0
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +14 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +7 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +24 -0
- package/dist/src/utils/helpers/index.d.ts +10 -0
- package/dist/src/utils/helpers/index.js +115 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts +8 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +25 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts +15 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +60 -0
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.d.ts +1 -0
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +11 -0
- package/dist/src/utils/helpers/interceptors/index.d.ts +2 -0
- package/dist/src/utils/helpers/interceptors/index.js +27 -0
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.d.ts +1 -0
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +8 -0
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.d.ts +2 -0
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +8 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.d.ts +1 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +8 -0
- package/dist/src/utils/helpers/sleep.d.ts +1 -0
- package/dist/src/utils/helpers/sleep.js +10 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.d.ts +1 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +1 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +9 -0
- package/dist/src/utils/helpers/url/index.d.ts +4 -0
- package/dist/src/utils/helpers/url/index.js +49 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +8 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.d.ts +1 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +15 -0
- package/dist/src/utils/types/checkModes.d.ts +12 -0
- package/dist/src/utils/types/checkModes.js +1 -0
- 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.d.ts +74 -0
- package/dist/src/utils/types/graphql.js +1 -0
- package/dist/src/utils/types/index.d.ts +7 -0
- package/dist/src/utils/types/index.js +82 -0
- package/dist/src/utils/types/interceptors.d.ts +31 -0
- package/dist/src/utils/types/interceptors.js +1 -0
- package/dist/src/utils/types/rest.d.ts +77 -0
- package/dist/src/utils/types/rest.js +1 -0
- package/dist/src/utils/types/server.d.ts +53 -0
- package/dist/src/utils/types/server.js +1 -0
- package/dist/src/utils/types/values.d.ts +4 -0
- package/dist/src/utils/types/values.js +1 -0
- package/package.json +130 -113
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRewrittenDatabaseRoutes = void 0;
|
|
7
|
+
var _expressUrlrewrite = _interopRequireDefault(require("express-urlrewrite"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
const createRewrittenDatabaseRoutes = (router, rewrittenRoutes) => Object.entries(rewrittenRoutes).forEach(([key, value]) => {
|
|
10
|
+
router.use((0, _expressUrlrewrite.default)(key, value));
|
|
11
|
+
});
|
|
12
|
+
exports.createRewrittenDatabaseRoutes = createRewrittenDatabaseRoutes;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IRouter } from 'express';
|
|
2
|
+
import type { ShallowDatabase } from '../../../../../utils/types';
|
|
3
|
+
import type { MemoryStorage } from '../../storages';
|
|
4
|
+
export declare const createShallowDatabaseRoutes: (router: IRouter, database: ShallowDatabase, storage: MemoryStorage<ShallowDatabase>) => IRouter;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createShallowDatabaseRoutes = void 0;
|
|
7
|
+
const createShallowDatabaseRoutes = (router, database, storage) => {
|
|
8
|
+
Object.keys(database).forEach(key => {
|
|
9
|
+
const path = `/${key}`;
|
|
10
|
+
router.route(path).get((_request, response) => {
|
|
11
|
+
// ✅ important:
|
|
12
|
+
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
13
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
14
|
+
response.set('Cache-control', 'max-age=0, must-revalidate');
|
|
15
|
+
response.json(storage.read(key));
|
|
16
|
+
});
|
|
17
|
+
router.route(path).post((request, response) => {
|
|
18
|
+
storage.write(key, request.body);
|
|
19
|
+
response.set('Location', request.url);
|
|
20
|
+
response.status(201).json(request.body);
|
|
21
|
+
});
|
|
22
|
+
router.route(path).put((request, response) => {
|
|
23
|
+
storage.write(key, request.body);
|
|
24
|
+
response.json(request.body);
|
|
25
|
+
});
|
|
26
|
+
router.route(path).patch((request, response) => {
|
|
27
|
+
const currentResource = storage.read(key);
|
|
28
|
+
const updatedResource = {
|
|
29
|
+
...currentResource,
|
|
30
|
+
...request.body
|
|
31
|
+
};
|
|
32
|
+
storage.write(key, updatedResource);
|
|
33
|
+
response.json(updatedResource);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return router;
|
|
37
|
+
};
|
|
38
|
+
exports.createShallowDatabaseRoutes = createShallowDatabaseRoutes;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './array';
|
|
2
|
+
export * from './createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes';
|
|
3
|
+
export * from './createNestedDatabaseRoutes/createNestedDatabaseRoutes';
|
|
4
|
+
export * from './createShallowDatabaseRoutes/createShallowDatabaseRoutes';
|
|
5
|
+
export * from './splitDatabaseByNesting/splitDatabaseByNesting';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _array = require("./array");
|
|
7
|
+
Object.keys(_array).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _array[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _array[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _createRewrittenDatabaseRoutes = require("./createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes");
|
|
18
|
+
Object.keys(_createRewrittenDatabaseRoutes).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _createRewrittenDatabaseRoutes[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _createRewrittenDatabaseRoutes[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _createNestedDatabaseRoutes = require("./createNestedDatabaseRoutes/createNestedDatabaseRoutes");
|
|
29
|
+
Object.keys(_createNestedDatabaseRoutes).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _createNestedDatabaseRoutes[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _createNestedDatabaseRoutes[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _createShallowDatabaseRoutes = require("./createShallowDatabaseRoutes/createShallowDatabaseRoutes");
|
|
40
|
+
Object.keys(_createShallowDatabaseRoutes).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _createShallowDatabaseRoutes[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _createShallowDatabaseRoutes[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _splitDatabaseByNesting = require("./splitDatabaseByNesting/splitDatabaseByNesting");
|
|
51
|
+
Object.keys(_splitDatabaseByNesting).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _splitDatabaseByNesting[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _splitDatabaseByNesting[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.splitDatabaseByNesting = void 0;
|
|
7
|
+
var _helpers = require("../../../../../utils/helpers");
|
|
8
|
+
const isAllArrayElementsHaveValidTypeId = array => array.every(element => (0, _helpers.isPlainObject)(element) && (typeof element.id === 'number' || typeof element.id === 'string'));
|
|
9
|
+
const isAllArrayElementsHaveUniqueId = array => {
|
|
10
|
+
const uniqueIdsCount = new Set(array.map(({
|
|
11
|
+
id
|
|
12
|
+
}) => id)).size;
|
|
13
|
+
return array.length === uniqueIdsCount;
|
|
14
|
+
};
|
|
15
|
+
const splitDatabaseByNesting = data => {
|
|
16
|
+
const shallowDatabase = {};
|
|
17
|
+
const nestedDatabase = {};
|
|
18
|
+
Object.entries(data).forEach(([databaseEntityKey, databaseEntityValue]) => {
|
|
19
|
+
if (Array.isArray(databaseEntityValue) && isAllArrayElementsHaveValidTypeId(databaseEntityValue) && isAllArrayElementsHaveUniqueId(databaseEntityValue)) {
|
|
20
|
+
nestedDatabase[databaseEntityKey] = databaseEntityValue;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
shallowDatabase[databaseEntityKey] = databaseEntityValue;
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
shallowDatabase,
|
|
27
|
+
nestedDatabase
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.splitDatabaseByNesting = splitDatabaseByNesting;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Index = string | number;
|
|
2
|
+
type Object = Record<Index, any>;
|
|
3
|
+
export declare class FileStorage<T extends Object = Object> {
|
|
4
|
+
private readonly fileWriter;
|
|
5
|
+
private readonly data;
|
|
6
|
+
constructor(fileName: string);
|
|
7
|
+
read(key?: Index | Index[]): any;
|
|
8
|
+
write(key: Index | Index[], value: unknown): void;
|
|
9
|
+
delete(key: Index | Index[]): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FileStorage = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _constants = require("../../../../../utils/constants");
|
|
10
|
+
var _helpers = require("../../helpers");
|
|
11
|
+
var _FileWriter = require("./FileWriter");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
+
class FileStorage {
|
|
17
|
+
constructor(fileName) {
|
|
18
|
+
_defineProperty(this, "fileWriter", void 0);
|
|
19
|
+
_defineProperty(this, "data", void 0);
|
|
20
|
+
const filePath = _path.default.resolve(_constants.APP_PATH, fileName);
|
|
21
|
+
this.fileWriter = new _FileWriter.FileWriter(filePath);
|
|
22
|
+
this.data = JSON.parse(_fs.default.readFileSync(filePath, 'utf-8'));
|
|
23
|
+
}
|
|
24
|
+
read(key) {
|
|
25
|
+
if (!key) return this.data;
|
|
26
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
27
|
+
let readable = this.data;
|
|
28
|
+
for (const currentKey of keys) {
|
|
29
|
+
readable = readable[currentKey];
|
|
30
|
+
}
|
|
31
|
+
return readable;
|
|
32
|
+
}
|
|
33
|
+
write(key, value) {
|
|
34
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
35
|
+
let writable = this.data;
|
|
36
|
+
let index = 0;
|
|
37
|
+
// ✅ important:
|
|
38
|
+
// stop iterate one element before end of keys for get access to writable object property
|
|
39
|
+
while (index < keys.length - 1) {
|
|
40
|
+
writable = writable[keys[index]];
|
|
41
|
+
index += 1;
|
|
42
|
+
}
|
|
43
|
+
writable[keys[index]] = value;
|
|
44
|
+
this.fileWriter.write(JSON.stringify(this.data));
|
|
45
|
+
}
|
|
46
|
+
delete(key) {
|
|
47
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
48
|
+
let deletable = this.data;
|
|
49
|
+
let index = 0;
|
|
50
|
+
// ✅ important:
|
|
51
|
+
// stop iterate one element before end of key for get access to deletable object property
|
|
52
|
+
while (index < keys.length - 1) {
|
|
53
|
+
deletable = deletable[keys[index]];
|
|
54
|
+
index += 1;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(deletable) && (0, _helpers.isIndex)(keys[index])) {
|
|
57
|
+
deletable.splice(keys[index], 1);
|
|
58
|
+
} else {
|
|
59
|
+
delete deletable[keys[index]];
|
|
60
|
+
}
|
|
61
|
+
this.fileWriter.write(JSON.stringify(this.data));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.FileStorage = FileStorage;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class FileWriter {
|
|
2
|
+
private readonly filePath;
|
|
3
|
+
private nextData;
|
|
4
|
+
private nextDataPromise;
|
|
5
|
+
private nextDataResolve;
|
|
6
|
+
private writeIsLocked;
|
|
7
|
+
constructor(filePath: string);
|
|
8
|
+
private lockedWrite;
|
|
9
|
+
private unlockedWrite;
|
|
10
|
+
write(data: string): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FileWriter = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
class FileWriter {
|
|
13
|
+
constructor(filePath) {
|
|
14
|
+
_defineProperty(this, "filePath", void 0);
|
|
15
|
+
_defineProperty(this, "nextData", null);
|
|
16
|
+
_defineProperty(this, "nextDataPromise", null);
|
|
17
|
+
_defineProperty(this, "nextDataResolve", null);
|
|
18
|
+
_defineProperty(this, "writeIsLocked", false);
|
|
19
|
+
this.filePath = filePath;
|
|
20
|
+
}
|
|
21
|
+
lockedWrite(data) {
|
|
22
|
+
var _this$nextDataPromise;
|
|
23
|
+
this.nextData = data;
|
|
24
|
+
this.nextDataPromise = (_this$nextDataPromise = this.nextDataPromise) !== null && _this$nextDataPromise !== void 0 ? _this$nextDataPromise : new Promise(resolve => {
|
|
25
|
+
this.nextDataResolve = resolve;
|
|
26
|
+
});
|
|
27
|
+
return new Promise(resolve => {
|
|
28
|
+
var _this$nextDataPromise2;
|
|
29
|
+
(_this$nextDataPromise2 = this.nextDataPromise) === null || _this$nextDataPromise2 === void 0 ? void 0 : _this$nextDataPromise2.then(() => {
|
|
30
|
+
resolve();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async unlockedWrite(data, recursionLevel = 0) {
|
|
35
|
+
this.writeIsLocked = true;
|
|
36
|
+
await _fs.default.promises.writeFile(this.filePath, data, 'utf-8');
|
|
37
|
+
this.writeIsLocked = false;
|
|
38
|
+
|
|
39
|
+
// ✅ important:
|
|
40
|
+
// copy content of this.nextData into new variable
|
|
41
|
+
// for avoid infinite recursion of 'unlockedWrite'
|
|
42
|
+
const passedData = this.nextData;
|
|
43
|
+
this.nextData = null;
|
|
44
|
+
if (passedData) {
|
|
45
|
+
await this.unlockedWrite(passedData, recursionLevel + 1);
|
|
46
|
+
if (recursionLevel === 0) {
|
|
47
|
+
var _this$nextDataResolve;
|
|
48
|
+
(_this$nextDataResolve = this.nextDataResolve) === null || _this$nextDataResolve === void 0 ? void 0 : _this$nextDataResolve.call(this);
|
|
49
|
+
this.nextDataPromise = null;
|
|
50
|
+
this.nextDataResolve = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
write(data) {
|
|
55
|
+
return this.writeIsLocked ? this.lockedWrite(data) : this.unlockedWrite(data);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.FileWriter = FileWriter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Index = string | number;
|
|
2
|
+
type Object = Record<Index, any>;
|
|
3
|
+
export declare class MemoryStorage<T extends Object = Object> {
|
|
4
|
+
private readonly data;
|
|
5
|
+
constructor(initialData: T);
|
|
6
|
+
read(key?: Index | Index[]): any;
|
|
7
|
+
write(key: Index | Index[], value: unknown): void;
|
|
8
|
+
delete(key: Index | Index[]): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MemoryStorage = void 0;
|
|
7
|
+
var _helpers = require("../../helpers");
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
class MemoryStorage {
|
|
12
|
+
constructor(initialData) {
|
|
13
|
+
_defineProperty(this, "data", void 0);
|
|
14
|
+
this.data = initialData;
|
|
15
|
+
}
|
|
16
|
+
read(key) {
|
|
17
|
+
if (!key) return this.data;
|
|
18
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
19
|
+
let readable = this.data;
|
|
20
|
+
for (const currentKey of keys) {
|
|
21
|
+
readable = readable[currentKey];
|
|
22
|
+
}
|
|
23
|
+
return readable;
|
|
24
|
+
}
|
|
25
|
+
write(key, value) {
|
|
26
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
27
|
+
let writable = this.data;
|
|
28
|
+
let index = 0;
|
|
29
|
+
// ✅ important:
|
|
30
|
+
// stop iterate one element before end of keys for get access to writable object property
|
|
31
|
+
while (index < keys.length - 1) {
|
|
32
|
+
writable = writable[keys[index]];
|
|
33
|
+
index += 1;
|
|
34
|
+
}
|
|
35
|
+
writable[keys[index]] = value;
|
|
36
|
+
}
|
|
37
|
+
delete(key) {
|
|
38
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
39
|
+
let deletable = this.data;
|
|
40
|
+
let index = 0;
|
|
41
|
+
// ✅ important:
|
|
42
|
+
// stop iterate one element before end of key for get access to deletable object property
|
|
43
|
+
while (index < keys.length - 1) {
|
|
44
|
+
deletable = deletable[keys[index]];
|
|
45
|
+
index += 1;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(deletable) && (0, _helpers.isIndex)(keys[index])) {
|
|
48
|
+
deletable.splice(keys[index], 1);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
delete deletable[keys[index]];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.MemoryStorage = MemoryStorage;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _FileStorage = require("./File/FileStorage");
|
|
7
|
+
Object.keys(_FileStorage).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _FileStorage[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _FileStorage[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _MemoryStorage = require("./Memory/MemoryStorage");
|
|
18
|
+
Object.keys(_MemoryStorage).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _MemoryStorage[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _MemoryStorage[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createDatabaseRoutes/createDatabaseRoutes';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _createDatabaseRoutes = require("./createDatabaseRoutes/createDatabaseRoutes");
|
|
7
|
+
Object.keys(_createDatabaseRoutes).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _createDatabaseRoutes[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _createDatabaseRoutes[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGraphQLRoutes = void 0;
|
|
7
|
+
var _flat = require("flat");
|
|
8
|
+
var _helpers = require("../../../utils/helpers");
|
|
9
|
+
var _helpers2 = require("./helpers");
|
|
10
|
+
const createGraphQLRoutes = (router, graphqlConfig, serverResponseInterceptors) => {
|
|
11
|
+
const preparedGraphQLRequestConfig = (0, _helpers2.prepareGraphQLRequestConfigs)(graphqlConfig.configs);
|
|
12
|
+
const graphqlMiddleware = async (request, response, next) => {
|
|
13
|
+
var _matchedRequestConfig, _matchedRouteConfig$e, _matchedRouteConfig$i, _matchedRequestConfig2, _graphqlConfig$interc;
|
|
14
|
+
const graphQLInput = (0, _helpers.getGraphQLInput)(request);
|
|
15
|
+
if (!graphQLInput || !graphQLInput.query) {
|
|
16
|
+
return response.status(400).json({
|
|
17
|
+
message: 'Query is missing, you must pass a valid GraphQL query'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const query = (0, _helpers.parseQuery)(graphQLInput.query);
|
|
21
|
+
if (!query) {
|
|
22
|
+
return response.status(400).json({
|
|
23
|
+
message: 'Query is invalid, you must use a valid GraphQL query'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (!query.operationName || !query.operationType) {
|
|
27
|
+
return response.status(400).json({
|
|
28
|
+
message: `You should to specify operationName and operationType for ${request.method}:${request.baseUrl}${request.path}`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const matchedRequestConfig = preparedGraphQLRequestConfig.find(requestConfig => {
|
|
32
|
+
if (requestConfig.operationName instanceof RegExp) {
|
|
33
|
+
return new RegExp(requestConfig.operationName).test(query.operationName) && requestConfig.operationType === query.operationType;
|
|
34
|
+
}
|
|
35
|
+
return requestConfig.operationName === query.operationName && requestConfig.operationType === query.operationType;
|
|
36
|
+
});
|
|
37
|
+
if (!matchedRequestConfig) {
|
|
38
|
+
return next();
|
|
39
|
+
}
|
|
40
|
+
const requestInterceptor = (_matchedRequestConfig = matchedRequestConfig.interceptors) === null || _matchedRequestConfig === void 0 ? void 0 : _matchedRequestConfig.request;
|
|
41
|
+
if (requestInterceptor) {
|
|
42
|
+
await (0, _helpers.callRequestInterceptor)({
|
|
43
|
+
request,
|
|
44
|
+
interceptor: requestInterceptor
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const matchedRouteConfig = matchedRequestConfig.routes.find(({
|
|
48
|
+
entities
|
|
49
|
+
}) => {
|
|
50
|
+
if (!entities) return true;
|
|
51
|
+
const entries = Object.entries(entities);
|
|
52
|
+
return entries.every(([entityName, valueOrDescriptor]) => {
|
|
53
|
+
const {
|
|
54
|
+
checkMode,
|
|
55
|
+
value: descriptorValue
|
|
56
|
+
} = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
|
|
57
|
+
|
|
58
|
+
// ✅ important: check whole variables as plain value strictly if descriptor used for variables
|
|
59
|
+
const isVariablesPlain = entityName === 'variables' && (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
|
|
60
|
+
if (isVariablesPlain) {
|
|
61
|
+
// ✅ important: getGraphQLInput returns empty object if variables not sent or invalid, so count {} as undefined
|
|
62
|
+
return (0, _helpers.resolveEntityValues)(checkMode, Object.keys(graphQLInput.variables).length ? graphQLInput.variables : undefined, descriptorValue);
|
|
63
|
+
}
|
|
64
|
+
const mappedEntityDescriptors = Object.entries(valueOrDescriptor);
|
|
65
|
+
return mappedEntityDescriptors.every(([entityKey, mappedEntityDescriptor]) => {
|
|
66
|
+
const {
|
|
67
|
+
checkMode,
|
|
68
|
+
value: descriptorValue
|
|
69
|
+
} = (0, _helpers.convertToEntityDescriptor)(mappedEntityDescriptor);
|
|
70
|
+
const flattenEntity = (0, _flat.flatten)(entityName === 'variables' ? graphQLInput.variables : request[entityName]);
|
|
71
|
+
// ✅ important: transform header keys to lower case because browsers send headers in lowercase
|
|
72
|
+
return (0, _helpers.resolveEntityValues)(checkMode, flattenEntity[entityName === 'headers' ? entityKey.toLowerCase() : entityKey], descriptorValue);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
if (!matchedRouteConfig) {
|
|
77
|
+
return next();
|
|
78
|
+
}
|
|
79
|
+
const matchedRouteConfigData = typeof matchedRouteConfig.data === 'function' ? await matchedRouteConfig.data(request, (_matchedRouteConfig$e = matchedRouteConfig.entities) !== null && _matchedRouteConfig$e !== void 0 ? _matchedRouteConfig$e : {}) : matchedRouteConfig.data;
|
|
80
|
+
const data = await (0, _helpers.callResponseInterceptors)({
|
|
81
|
+
data: matchedRouteConfigData,
|
|
82
|
+
request,
|
|
83
|
+
response,
|
|
84
|
+
interceptors: {
|
|
85
|
+
routeInterceptor: (_matchedRouteConfig$i = matchedRouteConfig.interceptors) === null || _matchedRouteConfig$i === void 0 ? void 0 : _matchedRouteConfig$i.response,
|
|
86
|
+
requestInterceptor: (_matchedRequestConfig2 = matchedRequestConfig.interceptors) === null || _matchedRequestConfig2 === void 0 ? void 0 : _matchedRequestConfig2.response,
|
|
87
|
+
apiInterceptor: (_graphqlConfig$interc = graphqlConfig.interceptors) === null || _graphqlConfig$interc === void 0 ? void 0 : _graphqlConfig$interc.response,
|
|
88
|
+
serverInterceptor: serverResponseInterceptors
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ✅ important:
|
|
93
|
+
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
94
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
95
|
+
response.set('Cache-control', 'max-age=0, must-revalidate');
|
|
96
|
+
return response.status(response.statusCode).json(data);
|
|
97
|
+
};
|
|
98
|
+
router.route('/').get((0, _helpers.asyncHandler)(graphqlMiddleware));
|
|
99
|
+
router.route('/').post((0, _helpers.asyncHandler)(graphqlMiddleware));
|
|
100
|
+
return router;
|
|
101
|
+
};
|
|
102
|
+
exports.createGraphQLRoutes = createGraphQLRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _prepareGraphQLRequestConfigs = require("./prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs");
|
|
7
|
+
Object.keys(_prepareGraphQLRequestConfigs).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _prepareGraphQLRequestConfigs[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _prepareGraphQLRequestConfigs[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prepareGraphQLRequestConfigs = void 0;
|
|
7
|
+
var _helpers = require("../../../../../utils/helpers");
|
|
8
|
+
const calculateRouteConfigWeight = graphQLRouteConfig => {
|
|
9
|
+
const {
|
|
10
|
+
entities
|
|
11
|
+
} = graphQLRouteConfig;
|
|
12
|
+
if (!entities) return 0;
|
|
13
|
+
let routeConfigWeight = 0;
|
|
14
|
+
const {
|
|
15
|
+
headers,
|
|
16
|
+
cookies,
|
|
17
|
+
query,
|
|
18
|
+
variables
|
|
19
|
+
} = entities;
|
|
20
|
+
if (headers) routeConfigWeight += Object.keys(headers).length;
|
|
21
|
+
if (cookies) routeConfigWeight += Object.keys(cookies).length;
|
|
22
|
+
if (query) routeConfigWeight += Object.keys(query).length;
|
|
23
|
+
if (variables) {
|
|
24
|
+
if ((0, _helpers.isPlainObject)(variables) && variables.checkMode) {
|
|
25
|
+
routeConfigWeight += (0, _helpers.isPlainObject)(variables.value) ? Object.keys(variables.value).length : 1;
|
|
26
|
+
return routeConfigWeight;
|
|
27
|
+
}
|
|
28
|
+
routeConfigWeight += Object.keys(variables).length;
|
|
29
|
+
}
|
|
30
|
+
return routeConfigWeight;
|
|
31
|
+
};
|
|
32
|
+
const prepareGraphQLRequestConfigs = requestConfigs => {
|
|
33
|
+
requestConfigs.forEach(requestConfig => {
|
|
34
|
+
requestConfig.routes.sort((first, second) =>
|
|
35
|
+
// ✅ important:
|
|
36
|
+
// Lift more specific configs for correct working of routes
|
|
37
|
+
calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
|
|
38
|
+
});
|
|
39
|
+
return requestConfigs;
|
|
40
|
+
};
|
|
41
|
+
exports.prepareGraphQLRequestConfigs = prepareGraphQLRequestConfigs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createGraphQLRoutes/createGraphQLRoutes';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _createGraphQLRoutes = require("./createGraphQLRoutes/createGraphQLRoutes");
|
|
7
|
+
Object.keys(_createGraphQLRoutes).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _createGraphQLRoutes[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _createGraphQLRoutes[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cookieParseMiddleware = void 0;
|
|
7
|
+
var _helpers = require("./helpers");
|
|
8
|
+
const cookieParseMiddleware = server => {
|
|
9
|
+
server.use((request, _response, next) => {
|
|
10
|
+
if (request.headers.cookie) {
|
|
11
|
+
request.cookies = (0, _helpers.parseCookie)(request.headers.cookie);
|
|
12
|
+
} else {
|
|
13
|
+
request.cookies = {};
|
|
14
|
+
}
|
|
15
|
+
return next();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.cookieParseMiddleware = cookieParseMiddleware;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './parseCookie/parseCookie';
|