mock-config-server 3.7.1 → 4.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 +272 -224
- package/dist/bin/bin.js +1 -1
- package/dist/bin/build.d.ts +3 -1
- package/dist/bin/build.js +10 -0
- package/dist/bin/helpers/createTemplate.d.ts +3 -3
- package/dist/bin/helpers/createTemplate.js +1 -1
- package/dist/bin/helpers/index.d.ts +0 -3
- package/dist/bin/helpers/index.js +0 -3
- package/dist/bin/helpers/resolveConfigFile.d.ts +2 -2
- package/dist/bin/helpers/resolveConfigFile.js +2 -2
- package/dist/bin/helpers/resolveConfigFilePath.js +4 -4
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +1 -2
- package/dist/bin/init.js +5 -8
- package/dist/bin/run.d.ts +1 -2
- package/dist/bin/run.js +1 -6
- package/dist/bin/runFlatConfig.d.ts +5 -0
- package/dist/bin/runFlatConfig.js +36 -0
- package/dist/bin/templates/js/full/mock-server.config.js +10 -7
- package/dist/bin/templates/js/graphql/mock-server.config.js +11 -6
- package/dist/bin/templates/js/rest/mock-server.config.js +11 -6
- package/dist/bin/templates/ts/full/mock-server.config.ts +11 -8
- package/dist/bin/templates/ts/graphql/mock-server.config.ts +12 -7
- package/dist/bin/templates/ts/rest/mock-server.config.ts +12 -7
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +2 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +8 -12
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +0 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +0 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +0 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +0 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.d.ts +1 -1
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.d.ts +5 -6
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +4 -4
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +2 -2
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.d.ts +6 -7
- package/dist/src/core/database/createOrm/createOrm.d.ts +2 -0
- package/dist/src/core/database/createOrm/createOrm.js +119 -0
- package/dist/src/core/database/createStorage/createStorage.d.ts +2 -0
- package/dist/src/core/database/createStorage/createStorage.js +13 -0
- package/dist/src/core/database/index.d.ts +2 -0
- package/dist/src/core/database/index.js +2 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +1 -1
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +39 -17
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +2 -2
- package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.d.ts +2 -2
- package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.js +11 -1
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.d.ts +1 -2
- package/dist/src/core/middlewares/index.d.ts +0 -1
- package/dist/src/core/middlewares/index.js +0 -1
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +2 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +1 -1
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +80 -24
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.d.ts +1 -1
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +6 -6
- package/dist/src/server/createFlatMockServer/createFlatMockServer.d.ts +3 -0
- package/dist/src/server/createFlatMockServer/createFlatMockServer.js +127 -0
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.d.ts +1 -1
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +3 -6
- package/dist/src/server/createMockServer/createMockServer.d.ts +1 -1
- package/dist/src/server/createMockServer/createMockServer.js +3 -5
- package/dist/src/server/createRestMockServer/createRestMockServer.d.ts +1 -1
- package/dist/src/server/createRestMockServer/createRestMockServer.js +3 -6
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.js +2 -0
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.d.ts +1 -2
- package/dist/src/server/startFlatMockServer/startFlatMockServer.d.ts +4 -0
- package/dist/src/server/startFlatMockServer/startFlatMockServer.js +28 -0
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.d.ts +1 -2
- package/dist/src/server/startMockServer/startMockServer.d.ts +1 -2
- package/dist/src/server/startRestMockServer/startRestMockServer.d.ts +1 -2
- package/dist/src/utils/constants/checkModes.d.ts +1 -3
- package/dist/src/utils/constants/checkModes.js +3 -19
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.d.ts +20 -2
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +37 -71
- package/dist/src/utils/helpers/files/index.d.ts +1 -0
- package/dist/src/utils/helpers/files/index.js +1 -0
- package/dist/src/utils/helpers/files/isFileDescriptor/isFileDescriptor.d.ts +2 -0
- package/dist/src/utils/helpers/files/isFileDescriptor/isFileDescriptor.js +16 -0
- package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +3 -3
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +1 -1
- package/dist/src/utils/helpers/index.d.ts +0 -1
- package/dist/src/utils/helpers/index.js +0 -1
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts +1 -1
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +2 -1
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +10 -5
- package/dist/src/utils/helpers/logger/callResponseLogger/callResponseLogger.d.ts +1 -1
- package/dist/src/utils/helpers/tests/createTmpDir.js +4 -4
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +1 -1
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +4 -4
- package/dist/src/utils/types/checkModes.d.ts +14 -7
- package/dist/src/utils/types/database.d.ts +30 -0
- package/dist/src/utils/types/entities.d.ts +13 -43
- package/dist/src/utils/types/files.d.ts +5 -0
- package/dist/src/utils/types/files.js +4 -0
- package/dist/src/utils/types/graphql.d.ts +9 -8
- 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 +21 -16
- package/dist/src/utils/types/logger.d.ts +11 -11
- package/dist/src/utils/types/rest.d.ts +17 -12
- package/dist/src/utils/types/server.d.ts +48 -20
- package/dist/src/utils/types/shared.d.ts +1 -1
- package/dist/src/utils/types/utils.d.ts +4 -4
- package/dist/src/utils/types/values.d.ts +3 -4
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/corsSchema/corsSchema.d.ts +2 -2
- package/dist/{bin/helpers → src/utils/validate}/getMostSpecificPathFromError.d.ts +1 -1
- package/dist/src/utils/validate/getValidationMessageFromPath.d.ts +1 -0
- package/dist/src/utils/validate/graphqlConfigSchema/graphqlConfigSchema.d.ts +535 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/graphqlConfigSchema/graphqlConfigSchema.js +14 -6
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +20 -5
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +5 -5
- package/dist/src/utils/validate/index.d.ts +14 -0
- package/dist/src/utils/validate/index.js +31 -0
- package/dist/{bin/helpers → src/utils/validate}/isOnlyRequestedDataResolvingPropertyExists.d.ts +1 -1
- package/dist/src/utils/validate/queueSchema/queueSchema.d.ts +20 -0
- package/dist/src/utils/validate/queueSchema/queueSchema.js +24 -0
- package/dist/src/utils/validate/restConfigSchema/restConfigSchema.d.ts +1659 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/restConfigSchema/restConfigSchema.js +13 -5
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +21 -6
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/restConfigSchema/routeConfigSchema/routeConfigSchema.js +6 -6
- package/dist/src/utils/validate/utils/checkModeSchema/checkModeSchema.d.ts +23 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/checkModeSchema/checkModeSchema.js +24 -1
- package/dist/src/utils/validate/utils/entitiesSchema/entitiesSchema.d.ts +4 -0
- package/dist/src/utils/validate/utils/entitiesSchema/entitiesSchema.js +94 -0
- package/dist/src/utils/validate/utils/extendedDiscriminatedUnion/extendedDiscriminatedUnion.d.ts +8 -0
- package/dist/src/utils/validate/utils/extendedDiscriminatedUnion/extendedDiscriminatedUnion.js +46 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/index.d.ts +2 -2
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/index.js +2 -2
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/jsonSchema/jsonSchema.d.ts +2 -2
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/jsonSchema/jsonSchema.js +1 -1
- package/dist/src/utils/validate/utils/nestedObjectOrArraySchema/nestedObjectOrArraySchema.d.ts +3 -0
- package/dist/src/utils/validate/utils/nestedObjectOrArraySchema/nestedObjectOrArraySchema.js +22 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +1 -1
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +1 -1
- package/dist/src/utils/validate/validateApiMockServerConfig.d.ts +2 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/validateApiMockServerConfig.js +4 -3
- package/dist/src/utils/validate/validateFlatMockServerConfig.d.ts +2 -0
- package/dist/src/utils/validate/validateFlatMockServerConfig.js +53 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/validateMockServerConfig.d.ts +1 -1
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/validateMockServerConfig.js +4 -3
- package/package.json +51 -52
- package/dist/bin/helpers/getValidationMessageFromPath.d.ts +0 -1
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +0 -258
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +0 -8
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +0 -21
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +0 -743
- package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.d.ts +0 -5
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +0 -71
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +0 -124
- package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.d.ts +0 -2
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +0 -11
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +0 -25
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.d.ts +0 -1
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +0 -85
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +0 -11
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +0 -39
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +0 -1
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +0 -11
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +0 -1
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +0 -11
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.d.ts +0 -2
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +0 -19
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.d.ts +0 -3
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +0 -20
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.d.ts +0 -3
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +0 -65
- package/dist/src/static/views/assets/icons/scheme-dark.svg +0 -3
- package/dist/src/static/views/assets/icons/scheme-light.svg +0 -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 +0 -88
- package/dist/src/static/views/components/header/index.css +0 -55
- package/dist/src/static/views/components/header/index.ejs +0 -40
- package/dist/src/static/views/components/header/index.js +0 -1
- package/dist/src/static/views/features/scheme/dark.css +0 -13
- package/dist/src/static/views/features/scheme/index.ejs +0 -3
- package/dist/src/static/views/features/scheme/index.js +0 -31
- package/dist/src/static/views/features/scheme/light.css +0 -13
- package/dist/src/static/views/features/tab/index.css +0 -30
- package/dist/src/static/views/features/tab/index.ejs +0 -2
- package/dist/src/static/views/features/tab/index.js +0 -12
- package/dist/src/static/views/pages/404/index.css +0 -10
- package/dist/src/static/views/pages/404/index.ejs +0 -82
- package/dist/src/utils/helpers/isRegExp/isRegExp.d.ts +0 -1
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +0 -11
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/baseUrlSchema/baseUrlSchema.d.ts +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/baseUrlSchema/baseUrlSchema.js +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/corsSchema/corsSchema.js +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/databaseConfigSchema/databaseConfigSchema.d.ts +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/databaseConfigSchema/databaseConfigSchema.js +0 -0
- package/dist/{bin/helpers → src/utils/validate}/getMostSpecificPathFromError.js +0 -0
- package/dist/{bin/helpers → src/utils/validate}/getValidationMessageFromPath.js +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/interceptorsSchema/interceptorsSchema.d.ts +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/interceptorsSchema/interceptorsSchema.js +0 -0
- package/dist/{bin/helpers → src/utils/validate}/isOnlyRequestedDataResolvingPropertyExists.js +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/portSchema/portSchema.d.ts +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/portSchema/portSchema.js +0 -0
- package/dist/{bin/validateMockServerConfig → src/utils/validate}/settingsSchema/settingsSchema.d.ts +2 -2
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/settingsSchema/settingsSchema.js +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/staticPathSchema/staticPathSchema.d.ts +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/staticPathSchema/staticPathSchema.js +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/plainObjectSchema/plainObjectSchema.d.ts +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/plainObjectSchema/plainObjectSchema.js +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/sharedSchema/sharedSchema.d.ts +0 -0
- /package/dist/{bin/validateMockServerConfig → src/utils/validate}/utils/sharedSchema/sharedSchema.js +0 -0
|
@@ -7,7 +7,6 @@ export * from './graphql';
|
|
|
7
7
|
export * from './interceptors';
|
|
8
8
|
export * from './isPlainObject/isPlainObject';
|
|
9
9
|
export * from './isPrimitive/isPrimitive';
|
|
10
|
-
export * from './isRegExp/isRegExp';
|
|
11
10
|
export * from './logger';
|
|
12
11
|
export * from './sleep';
|
|
13
12
|
export * from './url';
|
|
@@ -11,7 +11,6 @@ _export_star(require("./graphql"), exports);
|
|
|
11
11
|
_export_star(require("./interceptors"), exports);
|
|
12
12
|
_export_star(require("./isPlainObject/isPlainObject"), exports);
|
|
13
13
|
_export_star(require("./isPrimitive/isPrimitive"), exports);
|
|
14
|
-
_export_star(require("./isRegExp/isRegExp"), exports);
|
|
15
14
|
_export_star(require("./logger"), exports);
|
|
16
15
|
_export_star(require("./sleep"), exports);
|
|
17
16
|
_export_star(require("./url"), exports);
|
package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
2
|
import type { RequestInterceptor } from '../../../types';
|
|
3
3
|
interface CallRequestInterceptorParams {
|
|
4
|
-
request: Request;
|
|
5
4
|
interceptor: RequestInterceptor;
|
|
5
|
+
request: Request;
|
|
6
6
|
}
|
|
7
7
|
export declare const callRequestInterceptor: (params: CallRequestInterceptorParams) => Promise<void>;
|
|
8
8
|
export {};
|
package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js
CHANGED
|
@@ -12,8 +12,10 @@ const _logger = require("../../logger");
|
|
|
12
12
|
const _setDelay = require("../helpers/setDelay");
|
|
13
13
|
const callResponseInterceptors = async (params)=>{
|
|
14
14
|
const { data, request, response, interceptors } = params;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const getRequestHeader = (field)=>request.headers[field];
|
|
16
|
+
const getRequestHeaders = ()=>request.headers;
|
|
17
|
+
const getResponseHeader = (field)=>response.getHeader(field);
|
|
18
|
+
const getResponseHeaders = ()=>response.getHeaders();
|
|
17
19
|
const setHeader = (field, value)=>{
|
|
18
20
|
response.set(field, value);
|
|
19
21
|
};
|
|
@@ -50,13 +52,16 @@ const callResponseInterceptors = async (params)=>{
|
|
|
50
52
|
setStatusCode,
|
|
51
53
|
setHeader,
|
|
52
54
|
appendHeader,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
getRequestHeader,
|
|
56
|
+
getRequestHeaders,
|
|
57
|
+
getResponseHeader,
|
|
58
|
+
getResponseHeaders,
|
|
55
59
|
setCookie,
|
|
56
60
|
getCookie,
|
|
57
61
|
clearCookie,
|
|
58
62
|
attachment,
|
|
59
|
-
log
|
|
63
|
+
log,
|
|
64
|
+
orm: request.context.orm
|
|
60
65
|
};
|
|
61
66
|
let updatedData = data;
|
|
62
67
|
if (interceptors === null || interceptors === void 0 ? void 0 : interceptors.routeInterceptor) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Request, Response } from 'express';
|
|
2
2
|
import type { Data, Logger } from '../../../types';
|
|
3
3
|
interface CallResponseLoggerParams {
|
|
4
|
-
logger?: Logger<'response'>;
|
|
5
4
|
data: Data;
|
|
5
|
+
logger?: Logger<'response'>;
|
|
6
6
|
request: Request;
|
|
7
7
|
response: Response;
|
|
8
8
|
}
|
|
@@ -8,12 +8,12 @@ Object.defineProperty(exports, "createTmpDir", {
|
|
|
8
8
|
return createTmpDir;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
|
|
12
|
+
const _nodeos = /*#__PURE__*/ _interop_require_default(require("node:os"));
|
|
13
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
16
16
|
default: obj
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
const createTmpDir = ()=>
|
|
19
|
+
const createTmpDir = ()=>_nodefs.default.mkdtempSync(`${_nodeos.default.tmpdir()}${_nodepath.default.sep}`);
|
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "convertWin32PathToUnix", {
|
|
|
8
8
|
return convertWin32PathToUnix;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const convertWin32PathToUnix = (win32Path)=>win32Path.replace(/^\\\\\?\\/, '').replace(/\\/g, '/').replace(
|
|
11
|
+
const convertWin32PathToUnix = (win32Path)=>win32Path.replace(/^\\\\\?\\/, '').replace(/\\/g, '/').replace(/\/{2,}/g, '/');
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "urlJoin", {
|
|
|
8
8
|
return urlJoin;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _nodeos = /*#__PURE__*/ _interop_require_default(require("node:os"));
|
|
12
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
13
13
|
const _convertWin32PathToUnix = require("../convertWin32PathToUnix/convertWin32PathToUnix");
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
@@ -17,6 +17,6 @@ function _interop_require_default(obj) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const urlJoin = (...paths)=>{
|
|
20
|
-
const pathsToJoin =
|
|
21
|
-
return
|
|
20
|
+
const pathsToJoin = _nodeos.default.platform() === 'win32' ? paths.map((path)=>(0, _convertWin32PathToUnix.convertWin32PathToUnix)(path)) : paths;
|
|
21
|
+
return _nodepath.default.posix.join(...pathsToJoin);
|
|
22
22
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
export type CheckActualValueCheckMode = 'exists' | 'notExists';
|
|
2
2
|
export type CompareWithDescriptorAnyValueCheckMode = 'equals' | 'notEquals';
|
|
3
|
-
export type CompareWithDescriptorStringValueCheckMode = '
|
|
3
|
+
export type CompareWithDescriptorStringValueCheckMode = 'endsWith' | 'includes' | 'notEndsWith' | 'notIncludes' | 'notStartsWith' | 'startsWith';
|
|
4
4
|
export type CompareWithDescriptorValueCheckMode = CompareWithDescriptorAnyValueCheckMode | CompareWithDescriptorStringValueCheckMode;
|
|
5
|
-
export type CalculateByDescriptorValueCheckMode = '
|
|
6
|
-
export type CheckMode =
|
|
7
|
-
export
|
|
8
|
-
checkMode:
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export type CalculateByDescriptorValueCheckMode = 'function' | 'regExp';
|
|
6
|
+
export type CheckMode = CalculateByDescriptorValueCheckMode | CheckActualValueCheckMode | CompareWithDescriptorValueCheckMode;
|
|
7
|
+
export type EntityDescriptor<Check extends CheckMode = CheckMode, Value = any> = Check extends CheckActualValueCheckMode ? {
|
|
8
|
+
checkMode: Check;
|
|
9
|
+
} : {
|
|
10
|
+
checkMode: Check;
|
|
11
|
+
value: Value;
|
|
12
|
+
oneOf?: false;
|
|
13
|
+
} | {
|
|
14
|
+
checkMode: Check;
|
|
15
|
+
value: Value[];
|
|
16
|
+
oneOf: true;
|
|
17
|
+
};
|
|
11
18
|
export type CheckFunction = <ActualValue = any, DescriptorValue = any>(checkMode: CheckMode, actualValue: ActualValue, descriptorValue?: DescriptorValue) => boolean;
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
+
export interface Database extends Record<string, unknown> {
|
|
2
|
+
}
|
|
1
3
|
export type ShallowDatabase = Record<string, unknown>;
|
|
2
4
|
export type NestedDatabaseId = number | string;
|
|
3
5
|
export type NestedDatabase = Record<string, {
|
|
4
6
|
id: NestedDatabaseId;
|
|
5
7
|
[key: string]: unknown;
|
|
6
8
|
}[]>;
|
|
9
|
+
export type StorageIndex = number | string;
|
|
10
|
+
export interface Storage {
|
|
11
|
+
delete: (key: StorageIndex | StorageIndex[]) => void;
|
|
12
|
+
read: (key?: StorageIndex | StorageIndex[]) => any;
|
|
13
|
+
write: (key: StorageIndex | StorageIndex[], value: unknown) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface ShallowOrm<Item = unknown> {
|
|
16
|
+
get: () => Item;
|
|
17
|
+
update: (data: Item) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface NestedOrm<Item = Record<string, unknown>> {
|
|
20
|
+
count: () => number;
|
|
21
|
+
create: (item: Omit<Item, 'id'>) => Item;
|
|
22
|
+
createMany: (items: Omit<Item, 'id'>[]) => void;
|
|
23
|
+
delete: (id: StorageIndex) => void;
|
|
24
|
+
deleteMany: (ids: StorageIndex[]) => void;
|
|
25
|
+
exists: (filters: Partial<Item>) => boolean;
|
|
26
|
+
findById: (id: StorageIndex) => Item | undefined;
|
|
27
|
+
findFirst: (filters?: Partial<Item>) => Item | undefined;
|
|
28
|
+
findMany: (filters?: Partial<Item>) => Item[];
|
|
29
|
+
update: (id: StorageIndex, item: Partial<Omit<Item, 'id'>>) => void;
|
|
30
|
+
updateMany: (ids: StorageIndex[], item: Partial<Omit<Item, 'id'>>) => number;
|
|
31
|
+
}
|
|
32
|
+
export type Orm<Database extends Record<string, unknown>> = {
|
|
33
|
+
[Key in keyof Database]: Database[Key] extends Array<infer Item> ? Item extends {
|
|
34
|
+
id: StorageIndex;
|
|
35
|
+
} ? NestedOrm<Item> : ShallowOrm<Database[Key]> : ShallowOrm<Database[Key]>;
|
|
36
|
+
};
|
|
@@ -1,48 +1,18 @@
|
|
|
1
|
-
import type { CheckActualValueCheckMode, CheckFunction, CheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorStringValueCheckMode, CompareWithDescriptorValueCheckMode } from './checkModes';
|
|
1
|
+
import type { CheckActualValueCheckMode, CheckFunction, CheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorStringValueCheckMode, CompareWithDescriptorValueCheckMode, EntityDescriptor } from './checkModes';
|
|
2
2
|
import type { NestedObjectOrArray } from './utils';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
checkMode: Check;
|
|
9
|
-
value: NestedObjectOrArray<PlainEntityValue>;
|
|
10
|
-
} : Check extends CheckActualValueCheckMode ? {
|
|
11
|
-
checkMode: Check;
|
|
12
|
-
} : never;
|
|
13
|
-
type PropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
14
|
-
checkMode: Check;
|
|
15
|
-
value: (actualValue: PlainEntityValue | NestedObjectOrArray<PlainEntityValue>, checkFunction: CheckFunction) => boolean;
|
|
16
|
-
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
17
|
-
checkMode: Check;
|
|
18
|
-
value: PlainEntityValue | NestedObjectOrArray<PlainEntityValue>;
|
|
19
|
-
} : Check extends 'regExp' ? {
|
|
20
|
-
checkMode: Check;
|
|
21
|
-
value: RegExp | RegExp[];
|
|
22
|
-
} : Check extends CompareWithDescriptorStringValueCheckMode ? {
|
|
23
|
-
checkMode: Check;
|
|
24
|
-
value: PlainEntityValue | PlainEntityValue[];
|
|
25
|
-
} : Check extends CheckActualValueCheckMode ? {
|
|
26
|
-
checkMode: Check;
|
|
27
|
-
} : never;
|
|
3
|
+
type PlainEntityPrimitiveValue = boolean | number | string | null;
|
|
4
|
+
type PlainEntityObjectiveValue = NestedObjectOrArray<PlainEntityPrimitiveValue>;
|
|
5
|
+
export type EntityFunctionDescriptorValue<ActualValue> = (actualValue: ActualValue, checkFunction: CheckFunction) => boolean;
|
|
6
|
+
export type TopLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? EntityDescriptor<Check, EntityFunctionDescriptorValue<PlainEntityObjectiveValue>> : Check extends CompareWithDescriptorAnyValueCheckMode ? EntityDescriptor<Check, PlainEntityObjectiveValue> : Check extends CheckActualValueCheckMode ? EntityDescriptor<Check> : never;
|
|
7
|
+
type PropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? EntityDescriptor<Check, EntityFunctionDescriptorValue<PlainEntityObjectiveValue | PlainEntityPrimitiveValue>> : Check extends 'regExp' ? EntityDescriptor<Check, RegExp> : Check extends CompareWithDescriptorAnyValueCheckMode ? EntityDescriptor<Check, PlainEntityObjectiveValue | PlainEntityPrimitiveValue> : Check extends CompareWithDescriptorStringValueCheckMode ? EntityDescriptor<Check, PlainEntityPrimitiveValue> : Check extends CheckActualValueCheckMode ? EntityDescriptor<Check> : never;
|
|
28
8
|
type NonCheckMode<T extends object> = T & {
|
|
29
9
|
checkMode?: never;
|
|
30
10
|
};
|
|
31
|
-
type TopLevelPlainEntityRecord = NonCheckMode<Record<string,
|
|
32
|
-
export type TopLevelPlainEntityArray = Array<
|
|
33
|
-
export type
|
|
34
|
-
type
|
|
35
|
-
type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} : Check extends 'regExp' ? {
|
|
39
|
-
checkMode: Check;
|
|
40
|
-
value: RegExp | RegExp[];
|
|
41
|
-
} : Check extends CompareWithDescriptorValueCheckMode ? {
|
|
42
|
-
checkMode: Check;
|
|
43
|
-
value: MappedEntityValue | MappedEntityValue[];
|
|
44
|
-
} : Check extends CheckActualValueCheckMode ? {
|
|
45
|
-
checkMode: Check;
|
|
46
|
-
} : never;
|
|
47
|
-
export type MappedEntity = Record<string, MappedEntityDescriptor | MappedEntityValue | MappedEntityValue[]>;
|
|
11
|
+
type TopLevelPlainEntityRecord = NonCheckMode<Record<string, NonCheckMode<PlainEntityObjectiveValue> | PlainEntityPrimitiveValue | PropertyLevelPlainEntityDescriptor>>;
|
|
12
|
+
export type TopLevelPlainEntityArray = Array<PlainEntityObjectiveValue | PlainEntityPrimitiveValue>;
|
|
13
|
+
export type BodyPlainEntity = TopLevelPlainEntityArray | TopLevelPlainEntityDescriptor | TopLevelPlainEntityRecord;
|
|
14
|
+
export type VariablesPlainEntity = TopLevelPlainEntityDescriptor | TopLevelPlainEntityRecord;
|
|
15
|
+
type MappedEntityValue = boolean | number | string;
|
|
16
|
+
type MappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? EntityDescriptor<Check, EntityFunctionDescriptorValue<MappedEntityValue>> : Check extends 'regExp' ? EntityDescriptor<Check, RegExp> : Check extends CompareWithDescriptorValueCheckMode ? EntityDescriptor<Check, MappedEntityValue> : Check extends CheckActualValueCheckMode ? EntityDescriptor<Check> : never;
|
|
17
|
+
export type MappedEntity = Record<string, MappedEntityDescriptor | MappedEntityValue>;
|
|
48
18
|
export {};
|
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
|
-
import type { MappedEntity,
|
|
2
|
+
import type { MappedEntity, VariablesPlainEntity } from './entities';
|
|
3
3
|
import type { Interceptors } from './interceptors';
|
|
4
4
|
import type { Data } from './values';
|
|
5
|
-
export type GraphQLEntityName = '
|
|
6
|
-
export type GraphQLEntity<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ?
|
|
7
|
-
export type GraphQLOperationType = '
|
|
5
|
+
export type GraphQLEntityName = 'cookies' | 'headers' | 'query' | 'variables';
|
|
6
|
+
export type GraphQLEntity<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ? VariablesPlainEntity : MappedEntity;
|
|
7
|
+
export type GraphQLOperationType = 'mutation' | 'query';
|
|
8
8
|
export type GraphQLOperationName = string | RegExp;
|
|
9
9
|
export type GraphQLEntitiesByEntityName = {
|
|
10
10
|
[EntityName in GraphQLEntityName]?: GraphQLEntity<EntityName>;
|
|
11
11
|
};
|
|
12
12
|
interface GraphQLSettings {
|
|
13
|
+
readonly delay?: number;
|
|
13
14
|
readonly polling?: boolean;
|
|
14
15
|
readonly status?: number;
|
|
15
|
-
readonly delay?: number;
|
|
16
16
|
}
|
|
17
|
+
export type GraphqlDataResponse = ((request: Request, entities: GraphQLEntitiesByEntityName) => Data | Promise<Data>) | Data;
|
|
17
18
|
export type GraphQLRouteConfig = ({
|
|
18
19
|
settings: GraphQLSettings & {
|
|
19
20
|
polling: true;
|
|
20
21
|
};
|
|
21
22
|
queue: Array<{
|
|
22
23
|
time?: number;
|
|
23
|
-
data:
|
|
24
|
+
data: GraphqlDataResponse;
|
|
24
25
|
}>;
|
|
25
26
|
} | {
|
|
26
27
|
settings?: GraphQLSettings & {
|
|
27
28
|
polling?: false;
|
|
28
29
|
};
|
|
29
|
-
data:
|
|
30
|
+
data: GraphqlDataResponse;
|
|
30
31
|
}) & {
|
|
31
32
|
entities?: GraphQLEntitiesByEntityName;
|
|
32
33
|
interceptors?: Interceptors<'graphql'>;
|
|
33
34
|
};
|
|
34
35
|
interface BaseGraphQLRequestConfig {
|
|
36
|
+
interceptors?: Interceptors<'graphql'>;
|
|
35
37
|
operationType: GraphQLOperationType;
|
|
36
38
|
routes: GraphQLRouteConfig[];
|
|
37
|
-
interceptors?: Interceptors<'graphql'>;
|
|
38
39
|
}
|
|
39
40
|
export interface OperationNameGraphQLRequestConfig extends BaseGraphQLRequestConfig {
|
|
40
41
|
operationName: GraphQLOperationName;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
_export_star(require("./checkModes"), exports);
|
|
6
6
|
_export_star(require("./database"), exports);
|
|
7
7
|
_export_star(require("./entities"), exports);
|
|
8
|
+
_export_star(require("./files"), exports);
|
|
8
9
|
_export_star(require("./graphql"), exports);
|
|
9
10
|
_export_star(require("./interceptors"), exports);
|
|
10
11
|
_export_star(require("./logger"), exports);
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import type { CookieOptions, Request, Response } from 'express';
|
|
2
|
+
import type { Database, Orm } from './database';
|
|
2
3
|
import type { Logger, LoggerTokens } from './logger';
|
|
3
4
|
import type { ApiType } from './shared';
|
|
4
|
-
type
|
|
5
|
-
type
|
|
5
|
+
type InterceptorCookieValue = string | undefined;
|
|
6
|
+
type InterceptorHeaderValue = number | string | string[] | undefined;
|
|
6
7
|
export interface RequestInterceptorParams<Api extends ApiType = ApiType> {
|
|
8
|
+
orm: Orm<Database>;
|
|
7
9
|
request: Request;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
getHeaders: () => Record<string, RequestInterceptorHeaderValue>;
|
|
10
|
+
getCookie: (name: string) => InterceptorCookieValue;
|
|
11
|
+
getHeader: (field: string) => InterceptorHeaderValue;
|
|
12
|
+
getHeaders: () => Record<string, InterceptorHeaderValue>;
|
|
12
13
|
log: (logger?: Logger<'request', Api>) => Partial<LoggerTokens>;
|
|
14
|
+
setDelay: (delay: number) => Promise<void>;
|
|
13
15
|
}
|
|
14
|
-
export type RequestInterceptor<Api extends ApiType = ApiType> = (params: RequestInterceptorParams<Api>) => void |
|
|
16
|
+
export type RequestInterceptor<Api extends ApiType = ApiType> = (params: RequestInterceptorParams<Api>) => Promise<void> | void;
|
|
15
17
|
export interface ResponseInterceptorParams<Api extends ApiType = ApiType> {
|
|
18
|
+
orm: Orm<Database>;
|
|
16
19
|
request: Request;
|
|
17
20
|
response: Response;
|
|
18
|
-
|
|
19
|
-
setStatusCode: (statusCode: number) => void;
|
|
20
|
-
setHeader: (field: string, value?: string | string[]) => void;
|
|
21
|
-
appendHeader: (field: string, value?: string[] | string) => void;
|
|
22
|
-
getHeader: (field: string) => RequestInterceptorHeaderValue;
|
|
23
|
-
getHeaders: () => Record<string, RequestInterceptorHeaderValue>;
|
|
24
|
-
setCookie: (name: string, value: string, options?: CookieOptions) => void;
|
|
25
|
-
getCookie: (name: string) => RequestInterceptorCookieValue;
|
|
26
|
-
clearCookie: (name: string, options?: CookieOptions) => void;
|
|
21
|
+
appendHeader: (field: string, value?: string | string[]) => void;
|
|
27
22
|
attachment: (filename: string) => void;
|
|
23
|
+
clearCookie: (name: string, options?: CookieOptions) => void;
|
|
24
|
+
getCookie: (name: string) => InterceptorCookieValue;
|
|
25
|
+
getRequestHeader: (field: string) => InterceptorHeaderValue;
|
|
26
|
+
getRequestHeaders: () => Record<string, InterceptorHeaderValue>;
|
|
27
|
+
getResponseHeader: (field: string) => InterceptorHeaderValue;
|
|
28
|
+
getResponseHeaders: () => Record<string, InterceptorHeaderValue>;
|
|
28
29
|
log: (logger?: Logger<'response', Api>) => Partial<LoggerTokens>;
|
|
30
|
+
setCookie: (name: string, value: string, options?: CookieOptions) => void;
|
|
31
|
+
setDelay: (delay: number) => Promise<void>;
|
|
32
|
+
setHeader: (field: string, value?: string | string[]) => void;
|
|
33
|
+
setStatusCode: (statusCode: number) => void;
|
|
29
34
|
}
|
|
30
35
|
export type ResponseInterceptor<Data = any, Api extends ApiType = ApiType> = (data: Data, params: ResponseInterceptorParams<Api>) => any;
|
|
31
36
|
export interface Interceptors<Api extends ApiType = ApiType> {
|
|
@@ -3,37 +3,37 @@ import type { RestMethod } from './rest';
|
|
|
3
3
|
import type { ApiType } from './shared';
|
|
4
4
|
import type { Cookies, Headers, Params, PlainObject, Query } from './values';
|
|
5
5
|
export interface LoggerBaseTokens {
|
|
6
|
-
|
|
6
|
+
body: any;
|
|
7
|
+
cookies: Cookies;
|
|
8
|
+
headers: Headers;
|
|
7
9
|
id: number;
|
|
8
|
-
timestamp: number;
|
|
9
10
|
method: RestMethod;
|
|
10
|
-
url: string;
|
|
11
|
-
headers: Headers;
|
|
12
|
-
cookies: Cookies;
|
|
13
|
-
query: Query;
|
|
14
11
|
params: Params;
|
|
15
|
-
|
|
12
|
+
query: Query;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
type: string;
|
|
15
|
+
url: string;
|
|
16
16
|
}
|
|
17
17
|
interface LoggerRestRequestTokens extends LoggerBaseTokens {
|
|
18
18
|
}
|
|
19
19
|
interface LoggerRestResponseTokens extends LoggerRestRequestTokens {
|
|
20
|
-
statusCode: number;
|
|
21
20
|
data: any;
|
|
21
|
+
statusCode: number;
|
|
22
22
|
}
|
|
23
23
|
interface LoggerGraphQLRequestTokens extends LoggerBaseTokens {
|
|
24
|
-
graphQLOperationType: GraphQLOperationType | null;
|
|
25
24
|
graphQLOperationName: GraphQLOperationName | null;
|
|
25
|
+
graphQLOperationType: GraphQLOperationType | null;
|
|
26
26
|
graphQLQuery: string | null;
|
|
27
27
|
variables: PlainObject | null;
|
|
28
28
|
}
|
|
29
29
|
interface LoggerGraphQLResponseTokens extends LoggerGraphQLRequestTokens {
|
|
30
|
-
statusCode: number;
|
|
31
30
|
data: any;
|
|
31
|
+
statusCode: number;
|
|
32
32
|
}
|
|
33
33
|
export type LoggerType = 'request' | 'response';
|
|
34
34
|
export type LoggerTokens<Type extends LoggerType = LoggerType, Api extends ApiType = ApiType> = Type extends 'request' ? Api extends 'rest' ? LoggerRestRequestTokens : Api extends 'graphql' ? LoggerGraphQLRequestTokens : never : Type extends 'response' ? Api extends 'rest' ? LoggerRestResponseTokens : Api extends 'graphql' ? LoggerGraphQLResponseTokens : never : never;
|
|
35
35
|
type LoggerTokensToLoggerOptions<Type> = {
|
|
36
|
-
[Key in keyof Type]?: Type[Key] extends PlainObject ? Record<string, boolean>
|
|
36
|
+
[Key in keyof Type]?: Type[Key] extends PlainObject ? boolean | Record<string, boolean> : boolean;
|
|
37
37
|
};
|
|
38
38
|
export type LoggerOptions<Type extends LoggerType = LoggerType, Api extends ApiType = ApiType> = LoggerTokensToLoggerOptions<LoggerTokens<Type, Api>>;
|
|
39
39
|
export interface Logger<Type extends LoggerType = LoggerType, Api extends ApiType = ApiType> {
|
|
@@ -1,49 +1,54 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BodyPlainEntity, MappedEntity } from './entities';
|
|
3
3
|
import type { Interceptors } from './interceptors';
|
|
4
4
|
import type { Data } from './values';
|
|
5
|
-
export type RestMethod = '
|
|
6
|
-
export type RestEntityName = '
|
|
7
|
-
export type RestEntity<EntityName extends RestEntityName = RestEntityName> = EntityName extends 'body' ?
|
|
5
|
+
export type RestMethod = 'delete' | 'get' | 'options' | 'patch' | 'post' | 'put';
|
|
6
|
+
export type RestEntityName = 'body' | 'cookies' | 'headers' | 'params' | 'query';
|
|
7
|
+
export type RestEntity<EntityName extends RestEntityName = RestEntityName> = EntityName extends 'body' ? BodyPlainEntity : MappedEntity;
|
|
8
8
|
export type RestEntityNamesByMethod = {
|
|
9
|
-
[key in RestMethod]: key extends '
|
|
9
|
+
[key in RestMethod]: key extends 'delete' | 'get' | 'options' ? Exclude<RestEntityName, 'body'> : RestEntityName;
|
|
10
10
|
};
|
|
11
11
|
export type RestEntitiesByEntityName<Method extends RestMethod = RestMethod> = {
|
|
12
12
|
[EntityName in RestEntityNamesByMethod[Method]]?: RestEntity<EntityName>;
|
|
13
13
|
};
|
|
14
14
|
interface RestSettings {
|
|
15
|
+
readonly delay?: number;
|
|
15
16
|
readonly polling?: boolean;
|
|
16
17
|
readonly status?: number;
|
|
17
|
-
readonly delay?: number;
|
|
18
18
|
}
|
|
19
|
+
export type RestDataResponse<Method extends RestMethod = RestMethod> = ((request: Request, entities: RestEntitiesByEntityName<Method>) => Data | Promise<Data>) | Data;
|
|
20
|
+
export type RestFileResponse = string;
|
|
19
21
|
export type RestRouteConfig<Method extends RestMethod> = ({
|
|
20
22
|
settings: RestSettings & {
|
|
21
23
|
polling: true;
|
|
22
24
|
};
|
|
23
25
|
queue: Array<{
|
|
24
26
|
time?: number;
|
|
25
|
-
data:
|
|
27
|
+
data: RestDataResponse<Method>;
|
|
28
|
+
} | {
|
|
29
|
+
time?: number;
|
|
30
|
+
file: RestFileResponse;
|
|
26
31
|
}>;
|
|
27
32
|
} | {
|
|
28
33
|
settings?: RestSettings & {
|
|
29
34
|
polling?: false;
|
|
30
35
|
};
|
|
31
|
-
data:
|
|
36
|
+
data: RestDataResponse<Method>;
|
|
32
37
|
} | {
|
|
33
38
|
settings?: RestSettings & {
|
|
34
39
|
polling?: false;
|
|
35
40
|
};
|
|
36
|
-
file:
|
|
41
|
+
file: RestFileResponse;
|
|
37
42
|
}) & {
|
|
38
43
|
entities?: RestEntitiesByEntityName<Method>;
|
|
39
44
|
interceptors?: Interceptors<'rest'>;
|
|
40
45
|
};
|
|
41
46
|
export type RestPathString = `/${string}`;
|
|
42
47
|
interface BaseRestRequestConfig<Method extends RestMethod> {
|
|
43
|
-
|
|
48
|
+
interceptors?: Interceptors<'rest'>;
|
|
44
49
|
method: Method;
|
|
50
|
+
path: RegExp | RestPathString;
|
|
45
51
|
routes: RestRouteConfig<Method>[];
|
|
46
|
-
interceptors?: Interceptors<'rest'>;
|
|
47
52
|
}
|
|
48
53
|
type RestGetRequestConfig = BaseRestRequestConfig<'get'>;
|
|
49
54
|
type RestPostRequestConfig = BaseRestRequestConfig<'post'>;
|
|
@@ -51,5 +56,5 @@ type RestPutRequestConfig = BaseRestRequestConfig<'put'>;
|
|
|
51
56
|
type RestDeleteRequestConfig = BaseRestRequestConfig<'delete'>;
|
|
52
57
|
type RestPatchRequestConfig = BaseRestRequestConfig<'patch'>;
|
|
53
58
|
type RestOptionsRequestConfig = BaseRestRequestConfig<'options'>;
|
|
54
|
-
export type RestRequestConfig =
|
|
59
|
+
export type RestRequestConfig = RestDeleteRequestConfig | RestGetRequestConfig | RestOptionsRequestConfig | RestPatchRequestConfig | RestPostRequestConfig | RestPutRequestConfig;
|
|
55
60
|
export {};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
2
|
import type { Arguments } from 'yargs';
|
|
3
|
+
import type { Database, Orm } from './database';
|
|
3
4
|
import type { GraphQLRequestConfig } from './graphql';
|
|
4
5
|
import type { Interceptors } from './interceptors';
|
|
5
6
|
import type { RestMethod, RestRequestConfig } from './rest';
|
|
6
|
-
|
|
7
|
-
prefix: `/${string}`;
|
|
7
|
+
interface StaticPathObject {
|
|
8
8
|
path: `/${string}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
9
|
+
prefix: `/${string}`;
|
|
10
|
+
}
|
|
11
|
+
export type StaticPath = `/${string}` | (`/${string}` | StaticPathObject)[] | StaticPathObject;
|
|
11
12
|
type CorsHeader = string;
|
|
12
|
-
export type CorsOrigin = string |
|
|
13
|
-
export
|
|
14
|
-
origin: CorsOrigin | ((request: Request) => Promise<CorsOrigin> | CorsOrigin);
|
|
15
|
-
methods?: Uppercase<RestMethod>[];
|
|
13
|
+
export type CorsOrigin = string | (string | RegExp)[] | RegExp;
|
|
14
|
+
export interface Cors {
|
|
16
15
|
allowedHeaders?: CorsHeader[];
|
|
17
|
-
exposedHeaders?: CorsHeader[];
|
|
18
16
|
credentials?: boolean;
|
|
17
|
+
exposedHeaders?: CorsHeader[];
|
|
19
18
|
maxAge?: number;
|
|
20
|
-
|
|
19
|
+
methods?: Uppercase<RestMethod>[];
|
|
20
|
+
origin: ((request: Request) => CorsOrigin | Promise<CorsOrigin>) | CorsOrigin;
|
|
21
|
+
}
|
|
21
22
|
type Port = number;
|
|
22
23
|
export type BaseUrl = `/${string}`;
|
|
23
24
|
export interface RestConfig {
|
|
@@ -30,21 +31,21 @@ export interface GraphqlConfig {
|
|
|
30
31
|
configs: GraphQLRequestConfig[];
|
|
31
32
|
interceptors?: Interceptors<'graphql'>;
|
|
32
33
|
}
|
|
33
|
-
export
|
|
34
|
-
data: Record<string, unknown
|
|
35
|
-
routes?: Record<`/${string}`, `/${string}
|
|
36
|
-
}
|
|
34
|
+
export interface DatabaseConfig {
|
|
35
|
+
data: `${string}.json` | Record<string, unknown>;
|
|
36
|
+
routes?: `${string}.json` | Record<`/${string}`, `/${string}`>;
|
|
37
|
+
}
|
|
37
38
|
export interface BaseMockServerConfig {
|
|
38
39
|
baseUrl?: BaseUrl;
|
|
40
|
+
cors?: Cors;
|
|
41
|
+
interceptors?: Interceptors;
|
|
39
42
|
port?: Port;
|
|
40
43
|
staticPath?: StaticPath;
|
|
41
|
-
interceptors?: Interceptors;
|
|
42
|
-
cors?: Cors;
|
|
43
44
|
}
|
|
44
45
|
export interface MockServerConfig extends BaseMockServerConfig {
|
|
45
|
-
rest?: RestConfig;
|
|
46
|
-
graphql?: GraphqlConfig;
|
|
47
46
|
database?: DatabaseConfig;
|
|
47
|
+
graphql?: GraphqlConfig;
|
|
48
|
+
rest?: RestConfig;
|
|
48
49
|
}
|
|
49
50
|
export interface RestMockServerConfig extends BaseMockServerConfig {
|
|
50
51
|
configs?: RestRequestConfig[];
|
|
@@ -55,8 +56,8 @@ export interface GraphQLMockServerConfig extends BaseMockServerConfig {
|
|
|
55
56
|
database?: DatabaseConfig;
|
|
56
57
|
}
|
|
57
58
|
export interface DatabaseMockServerConfig extends BaseMockServerConfig {
|
|
58
|
-
data: Record<string, unknown
|
|
59
|
-
routes?: Record<`/${string}`, `/${string}
|
|
59
|
+
data: `${string}.json` | Record<string, unknown>;
|
|
60
|
+
routes?: `${string}.json` | Record<`/${string}`, `/${string}`>;
|
|
60
61
|
}
|
|
61
62
|
export type MockServerConfigArgv = Arguments<{
|
|
62
63
|
baseUrl?: string;
|
|
@@ -65,4 +66,31 @@ export type MockServerConfigArgv = Arguments<{
|
|
|
65
66
|
config?: string;
|
|
66
67
|
watch?: boolean;
|
|
67
68
|
}>;
|
|
69
|
+
declare global {
|
|
70
|
+
namespace Express {
|
|
71
|
+
interface Request {
|
|
72
|
+
context: {
|
|
73
|
+
orm: Orm<Database>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export interface FlatMockServerComponent {
|
|
79
|
+
baseUrl?: BaseUrl;
|
|
80
|
+
configs: Array<GraphQLRequestConfig | RestRequestConfig>;
|
|
81
|
+
interceptors?: Interceptors;
|
|
82
|
+
name?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface FlatMockServerSettings {
|
|
85
|
+
baseUrl?: BaseUrl;
|
|
86
|
+
cors?: Cors;
|
|
87
|
+
database?: DatabaseConfig;
|
|
88
|
+
interceptors?: Interceptors;
|
|
89
|
+
port?: Port;
|
|
90
|
+
staticPath?: StaticPath;
|
|
91
|
+
}
|
|
92
|
+
export type FlatMockServerConfig = [
|
|
93
|
+
option: FlatMockServerComponent | FlatMockServerSettings,
|
|
94
|
+
...flatMockServerComponents: FlatMockServerComponent[]
|
|
95
|
+
];
|
|
68
96
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type ApiType = '
|
|
1
|
+
export type ApiType = 'graphql' | 'rest';
|