mock-config-server 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/bin.d.ts +2 -0
- package/dist/bin/bin.js +8 -0
- package/dist/bin/build.d.ts +2 -0
- package/dist/bin/build.js +49 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +48 -0
- package/dist/bin/helpers/index.d.ts +3 -0
- package/dist/bin/helpers/index.js +19 -0
- package/dist/bin/helpers/resolveConfigFile.d.ts +2 -0
- package/dist/bin/helpers/resolveConfigFile.js +20 -0
- package/dist/bin/helpers/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/helpers/resolveConfigFilePath.js +39 -0
- package/dist/bin/helpers/resolveExportsFromSourceCode.d.ts +1 -0
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +11 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +39 -0
- package/dist/bin/run.d.ts +6 -0
- package/dist/bin/run.js +17 -0
- package/dist/bin/validateMockServerConfig/helpers/index.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/helpers/index.js +18 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.js +17 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +10 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +17 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +23 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +82 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +48 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +97 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +21 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +30 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +101 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +44 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +3 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +89 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.d.ts +1 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +17 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +35 -0
- package/dist/src/core/graphql/index.d.ts +1 -0
- package/dist/src/core/graphql/index.js +17 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.d.ts +1 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +17 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.d.ts +3 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +17 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +45 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.d.ts +2 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +13 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.d.ts +1 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +17 -0
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.d.ts +7 -0
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +18 -0
- package/dist/src/core/middlewares/index.d.ts +8 -0
- package/dist/src/core/middlewares/index.js +24 -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 +19 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +80 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +11 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -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 +7 -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 +5 -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 +18 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.d.ts +3 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +19 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +53 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +11 -0
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +30 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +3 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +60 -0
- package/dist/src/core/rest/createRestRoutes/helpers/index.d.ts +1 -0
- package/dist/src/core/rest/createRestRoutes/helpers/index.js +17 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +37 -0
- package/dist/src/core/rest/index.d.ts +1 -0
- package/dist/src/core/rest/index.js +17 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +19 -0
- package/dist/src/server/createMockServer/createMockServer.d.ts +3 -0
- package/dist/src/server/createMockServer/createMockServer.js +58 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.js +18 -0
- package/dist/src/server/startMockServer/startMockServer.d.ts +5 -0
- package/dist/src/server/startMockServer/startMockServer.js +20 -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 +4 -0
- package/dist/src/utils/constants/checkModes.d.ts +9 -0
- package/dist/src/utils/constants/checkModes.js +31 -0
- package/dist/src/utils/constants/default.d.ts +11 -0
- package/dist/src/utils/constants/default.js +14 -0
- package/dist/src/utils/constants/index.d.ts +3 -0
- package/dist/src/utils/constants/index.js +19 -0
- package/dist/src/utils/helpers/asyncHandler.d.ts +2 -0
- package/dist/src/utils/helpers/asyncHandler.js +5 -0
- package/dist/src/utils/helpers/config/index.d.ts +1 -0
- package/dist/src/utils/helpers/config/index.js +17 -0
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.d.ts +2 -0
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +131 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.d.ts +2 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +8 -0
- package/dist/src/utils/helpers/entities/index.d.ts +2 -0
- package/dist/src/utils/helpers/entities/index.js +18 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +1 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +6 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +21 -0
- package/dist/src/utils/helpers/graphql/index.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/index.js +19 -0
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -0
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +12 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +7 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +21 -0
- package/dist/src/utils/helpers/index.d.ts +10 -0
- package/dist/src/utils/helpers/index.js +26 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts +8 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +19 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts +15 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +52 -0
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.d.ts +1 -0
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +8 -0
- package/dist/src/utils/helpers/interceptors/index.d.ts +2 -0
- package/dist/src/utils/helpers/interceptors/index.js +18 -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 +5 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.d.ts +1 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +5 -0
- package/dist/src/utils/helpers/sleep.d.ts +1 -0
- package/dist/src/utils/helpers/sleep.js +7 -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 +6 -0
- package/dist/src/utils/helpers/url/index.d.ts +4 -0
- package/dist/src/utils/helpers/url/index.js +20 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +5 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.d.ts +1 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +14 -0
- package/dist/src/utils/types/checkModes.d.ts +12 -0
- package/dist/src/utils/types/checkModes.js +2 -0
- package/dist/src/utils/types/graphql.d.ts +74 -0
- package/dist/src/utils/types/graphql.js +2 -0
- package/dist/src/utils/types/index.d.ts +6 -0
- package/dist/src/utils/types/index.js +22 -0
- package/dist/src/utils/types/interceptors.d.ts +31 -0
- package/dist/src/utils/types/interceptors.js +2 -0
- package/dist/src/utils/types/rest.d.ts +77 -0
- package/dist/src/utils/types/rest.js +2 -0
- package/dist/src/utils/types/server.d.ts +48 -0
- package/dist/src/utils/types/server.js +2 -0
- package/dist/src/utils/types/values.d.ts +4 -0
- package/dist/src/utils/types/values.js +2 -0
- package/package.json +2 -2
package/dist/bin/bin.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const pleaseUpgradeNode = require('please-upgrade-node');
|
|
5
|
+
const packageJson = require('../../package.json');
|
|
6
|
+
pleaseUpgradeNode(packageJson);
|
|
7
|
+
const { cli } = require('./cli');
|
|
8
|
+
cli();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = void 0;
|
|
4
|
+
const esbuild_1 = require("esbuild");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const run_1 = require("./run");
|
|
7
|
+
const build = async (argv) => {
|
|
8
|
+
const configFilePath = (0, helpers_1.resolveConfigFilePath)(argv.config);
|
|
9
|
+
if (!configFilePath) {
|
|
10
|
+
throw new Error('Cannot find config file mock-server.config.(ts|mts|cts|js|mjs|cjs)');
|
|
11
|
+
}
|
|
12
|
+
const buildOptions = {
|
|
13
|
+
entryPoints: [configFilePath],
|
|
14
|
+
bundle: true,
|
|
15
|
+
platform: 'node',
|
|
16
|
+
target: 'esnext',
|
|
17
|
+
minifySyntax: true,
|
|
18
|
+
minify: true,
|
|
19
|
+
write: false,
|
|
20
|
+
metafile: false,
|
|
21
|
+
logLevel: 'info',
|
|
22
|
+
plugins: []
|
|
23
|
+
};
|
|
24
|
+
if (argv.watch) {
|
|
25
|
+
const watchPlugin = {
|
|
26
|
+
name: 'watch',
|
|
27
|
+
setup: (build) => {
|
|
28
|
+
let instance;
|
|
29
|
+
build.onStart(() => {
|
|
30
|
+
instance?.destroy();
|
|
31
|
+
});
|
|
32
|
+
build.onEnd((result) => {
|
|
33
|
+
if (!result.errors.length) {
|
|
34
|
+
const mockConfig = (0, helpers_1.resolveConfigFile)(result.outputFiles[0].text);
|
|
35
|
+
instance = (0, run_1.run)(mockConfig, argv);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
buildOptions.plugins.push(watchPlugin);
|
|
41
|
+
const ctx = await (0, esbuild_1.context)(buildOptions);
|
|
42
|
+
ctx.watch();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { outputFiles } = await (0, esbuild_1.build)(buildOptions);
|
|
46
|
+
const mockConfig = (0, helpers_1.resolveConfigFile)(outputFiles[0].text);
|
|
47
|
+
(0, run_1.run)(mockConfig, argv);
|
|
48
|
+
};
|
|
49
|
+
exports.build = build;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cli: () => void;
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cli = void 0;
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const helpers_1 = require("yargs/helpers");
|
|
9
|
+
const build_1 = require("./build");
|
|
10
|
+
const cli = () => {
|
|
11
|
+
const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
12
|
+
.usage('mcs [options]')
|
|
13
|
+
.epilogue('More info: https://github.com/siberiacancode/mock-config-server#readme')
|
|
14
|
+
.options({
|
|
15
|
+
baseUrl: {
|
|
16
|
+
alias: 'b',
|
|
17
|
+
description: 'Set base url for mock server',
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
port: {
|
|
21
|
+
alias: 'p',
|
|
22
|
+
description: 'Set port for server',
|
|
23
|
+
type: 'number'
|
|
24
|
+
},
|
|
25
|
+
staticPath: {
|
|
26
|
+
alias: 's',
|
|
27
|
+
description: 'Set static path for mock server',
|
|
28
|
+
type: 'string'
|
|
29
|
+
},
|
|
30
|
+
config: {
|
|
31
|
+
alias: 'c',
|
|
32
|
+
description: 'Set path to config file',
|
|
33
|
+
type: 'string'
|
|
34
|
+
},
|
|
35
|
+
watch: {
|
|
36
|
+
alias: 'w',
|
|
37
|
+
description: 'Enables server restart after config file changes',
|
|
38
|
+
type: 'boolean'
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
.version()
|
|
42
|
+
.alias('version', 'v')
|
|
43
|
+
.help()
|
|
44
|
+
.alias('help', 'h')
|
|
45
|
+
.parse();
|
|
46
|
+
(0, build_1.build)(argv);
|
|
47
|
+
};
|
|
48
|
+
exports.cli = cli;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolveConfigFile"), exports);
|
|
18
|
+
__exportStar(require("./resolveConfigFilePath"), exports);
|
|
19
|
+
__exportStar(require("./resolveExportsFromSourceCode"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveConfigFile = void 0;
|
|
4
|
+
const helpers_1 = require("../../src/utils/helpers");
|
|
5
|
+
const resolveExportsFromSourceCode_1 = require("./resolveExportsFromSourceCode");
|
|
6
|
+
const resolveConfigFile = (configSourceCode) => {
|
|
7
|
+
if (!configSourceCode) {
|
|
8
|
+
throw new Error('Cannot handle source code of mock-server.config.(ts|js)');
|
|
9
|
+
}
|
|
10
|
+
const mockServerConfigExports = (0, resolveExportsFromSourceCode_1.resolveExportsFromSourceCode)(configSourceCode);
|
|
11
|
+
const mockServerConfig = mockServerConfigExports.default;
|
|
12
|
+
if (!mockServerConfig) {
|
|
13
|
+
throw new Error('Cannot handle exports of mock-server.config.(ts|js)');
|
|
14
|
+
}
|
|
15
|
+
if (!(0, helpers_1.isPlainObject)(mockServerConfig)) {
|
|
16
|
+
throw new Error('configuration should be plain object; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
|
|
17
|
+
}
|
|
18
|
+
return mockServerConfig;
|
|
19
|
+
};
|
|
20
|
+
exports.resolveConfigFile = resolveConfigFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveConfigFilePath: (cliConfigFilePath?: string) => string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.resolveConfigFilePath = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const resolveConfigFilePath = (cliConfigFilePath) => {
|
|
33
|
+
const appPath = process.cwd();
|
|
34
|
+
if (cliConfigFilePath)
|
|
35
|
+
return path_1.default.resolve(appPath, cliConfigFilePath);
|
|
36
|
+
const configFileNameRegex = /mock-server.config.(?:ts|mts|cts|js|mjs|cjs)/;
|
|
37
|
+
return fs.readdirSync(appPath).find((fileName) => configFileNameRegex.test(fileName));
|
|
38
|
+
};
|
|
39
|
+
exports.resolveConfigFilePath = resolveConfigFilePath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveExportsFromSourceCode: (sourceCode: string) => any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveExportsFromSourceCode = void 0;
|
|
4
|
+
const resolveExportsFromSourceCode = (sourceCode) => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const moduleInstance = new module.constructor();
|
|
7
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
8
|
+
moduleInstance._compile(sourceCode, '');
|
|
9
|
+
return moduleInstance.exports;
|
|
10
|
+
};
|
|
11
|
+
exports.resolveExportsFromSourceCode = resolveExportsFromSourceCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveConfigFilePath: (cliConfigFilePath?: string) => string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.resolveConfigFilePath = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const resolveConfigFilePath = (cliConfigFilePath) => {
|
|
33
|
+
const appPath = process.cwd();
|
|
34
|
+
if (cliConfigFilePath)
|
|
35
|
+
return path_1.default.resolve(appPath, cliConfigFilePath);
|
|
36
|
+
const configFileNameRegex = /mock-server.config.(?:ts|mts|cts|js|mjs|cjs)/;
|
|
37
|
+
return fs.readdirSync(appPath).find((fileName) => configFileNameRegex.test(fileName));
|
|
38
|
+
};
|
|
39
|
+
exports.resolveConfigFilePath = resolveConfigFilePath;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { MockServerConfig, MockServerConfigArgv } from '../src';
|
|
4
|
+
export declare const run: (mockConfig: MockServerConfig, argv: MockServerConfigArgv) => (import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> & {
|
|
5
|
+
destroy: (callback?: ((err?: Error | undefined) => void) | undefined) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
6
|
+
}) | undefined;
|
package/dist/bin/run.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.run = void 0;
|
|
5
|
+
const server_1 = require("../src/server");
|
|
6
|
+
const validateMockServerConfig_1 = require("./validateMockServerConfig/validateMockServerConfig");
|
|
7
|
+
const run = (mockConfig, argv) => {
|
|
8
|
+
try {
|
|
9
|
+
const mergedMockServerConfig = { ...mockConfig, ...argv };
|
|
10
|
+
(0, validateMockServerConfig_1.validateMockServerConfig)(mergedMockServerConfig);
|
|
11
|
+
return (0, server_1.startMockServer)(mergedMockServerConfig);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error(error.message);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.run = run;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./isCheckModeValid"), exports);
|
|
18
|
+
__exportStar(require("./isDescriptorValueValid"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isCheckModeValid';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./isCheckModeValid"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isCheckModeValid: (checkMode: unknown, entityName?: unknown) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCheckModeValid = void 0;
|
|
4
|
+
const constants_1 = require("../../../../src/utils/constants");
|
|
5
|
+
const isCheckModeValid = (checkMode, entityName) => {
|
|
6
|
+
if (entityName === 'body' || entityName === 'variables')
|
|
7
|
+
return constants_1.PLAIN_ENTITY_CHECK_MODES.includes(checkMode);
|
|
8
|
+
return constants_1.CHECK_MODES.includes(checkMode);
|
|
9
|
+
};
|
|
10
|
+
exports.isCheckModeValid = isCheckModeValid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isDescriptorValueValid';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./isDescriptorValueValid"), exports);
|
package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDescriptorValueValid: (checkMode: unknown, value: unknown, entityName?: unknown) => boolean;
|
package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDescriptorValueValid = void 0;
|
|
4
|
+
const constants_1 = require("../../../../src/utils/constants");
|
|
5
|
+
const isDescriptorValueValid = (checkMode, value, entityName) => {
|
|
6
|
+
if (constants_1.CHECK_ACTUAL_VALUE_CHECK_MODES.includes(checkMode))
|
|
7
|
+
return typeof value === 'undefined';
|
|
8
|
+
if (constants_1.COMPARE_WITH_DESCRIPTOR_VALUE_CHECK_MODES.includes(checkMode)) {
|
|
9
|
+
if (entityName === 'body' || entityName === 'variables') {
|
|
10
|
+
return (typeof value === 'object' &&
|
|
11
|
+
value !== null &&
|
|
12
|
+
typeof value !== 'function' &&
|
|
13
|
+
!(value instanceof RegExp));
|
|
14
|
+
}
|
|
15
|
+
return typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string';
|
|
16
|
+
}
|
|
17
|
+
if (checkMode === 'function')
|
|
18
|
+
return typeof value === 'function';
|
|
19
|
+
if (checkMode === 'regExp')
|
|
20
|
+
return value instanceof RegExp;
|
|
21
|
+
throw new Error('Invalid checkMode');
|
|
22
|
+
};
|
|
23
|
+
exports.isDescriptorValueValid = isDescriptorValueValid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateBaseUrl: (baseUrl: unknown) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBaseUrl = void 0;
|
|
4
|
+
const validateBaseUrl = (baseUrl) => {
|
|
5
|
+
if (typeof baseUrl !== 'string' && typeof baseUrl !== 'undefined') {
|
|
6
|
+
throw new Error('baseUrl');
|
|
7
|
+
}
|
|
8
|
+
if (typeof baseUrl === 'string' && !baseUrl.startsWith('/')) {
|
|
9
|
+
throw new Error('baseUrl');
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.validateBaseUrl = validateBaseUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateCors: (cors: unknown) => void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCors = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateOrigin = (origin) => {
|
|
6
|
+
const isOriginArray = Array.isArray(origin);
|
|
7
|
+
if (isOriginArray) {
|
|
8
|
+
origin.forEach((originElement, index) => {
|
|
9
|
+
const isOriginElementStringOrRegExp = typeof originElement === 'string' || originElement instanceof RegExp;
|
|
10
|
+
if (!isOriginElementStringOrRegExp) {
|
|
11
|
+
throw new Error(`origin[${index}]`);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const isOriginStringOrRegexp = typeof origin === 'string' || origin instanceof RegExp;
|
|
17
|
+
const isOriginFunction = typeof origin === 'function';
|
|
18
|
+
if (!isOriginStringOrRegexp && !isOriginFunction) {
|
|
19
|
+
throw new Error('origin');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const validateMethods = (methods) => {
|
|
23
|
+
const isMethodsArray = Array.isArray(methods);
|
|
24
|
+
if (isMethodsArray) {
|
|
25
|
+
const allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
|
26
|
+
methods.forEach((method, index) => {
|
|
27
|
+
// ✅ important:
|
|
28
|
+
// compare without 'toUpperCase' because 'Access-Control-Allow-Methods' value is case-sensitive
|
|
29
|
+
if (!allowedMethods.includes(method)) {
|
|
30
|
+
throw new Error(`methods[${index}]`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof methods !== 'undefined') {
|
|
36
|
+
throw new Error('methods');
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const validateHeaders = (headers) => {
|
|
40
|
+
const isHeadersArray = Array.isArray(headers);
|
|
41
|
+
if (isHeadersArray) {
|
|
42
|
+
headers.forEach((header, index) => {
|
|
43
|
+
if (typeof header !== 'string') {
|
|
44
|
+
throw new Error(`headers[${index}]`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (typeof headers !== 'undefined') {
|
|
50
|
+
throw new Error('headers');
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const validateCredentials = (credentials) => {
|
|
54
|
+
if (typeof credentials !== 'boolean' && typeof credentials !== 'undefined') {
|
|
55
|
+
throw new Error('credentials');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const validateMaxAge = (maxAge) => {
|
|
59
|
+
if (typeof maxAge !== 'number' && typeof maxAge !== 'undefined') {
|
|
60
|
+
throw new Error('maxAge');
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const validateCors = (cors) => {
|
|
64
|
+
const isCorsObject = (0, helpers_1.isPlainObject)(cors);
|
|
65
|
+
if (isCorsObject) {
|
|
66
|
+
try {
|
|
67
|
+
validateOrigin(cors.origin);
|
|
68
|
+
validateMethods(cors.methods);
|
|
69
|
+
validateHeaders(cors.headers);
|
|
70
|
+
validateCredentials(cors.credentials);
|
|
71
|
+
validateMaxAge(cors.maxAge);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`cors.${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (typeof cors !== 'undefined') {
|
|
79
|
+
throw new Error('cors');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.validateCors = validateCors;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateGraphqlConfig: (graphqlConfig: unknown) => void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateGraphqlConfig = void 0;
|
|
4
|
+
const helpers_1 = require("../../../src/utils/helpers");
|
|
5
|
+
const validateBaseUrl_1 = require("../validateBaseUrl/validateBaseUrl");
|
|
6
|
+
const validateInterceptors_1 = require("../validateInterceptors/validateInterceptors");
|
|
7
|
+
const validateRoutes_1 = require("./validateRoutes/validateRoutes");
|
|
8
|
+
const validateConfigs = (configs) => {
|
|
9
|
+
const isConfigsArray = Array.isArray(configs);
|
|
10
|
+
if (isConfigsArray) {
|
|
11
|
+
configs.forEach((config, index) => {
|
|
12
|
+
const { operationType, operationName } = config;
|
|
13
|
+
if (operationType !== 'query' && operationType !== 'mutation') {
|
|
14
|
+
throw new Error(`configs[${index}].operationType`);
|
|
15
|
+
}
|
|
16
|
+
const isOperationNameStringOrRegExp = typeof operationName === 'string' || operationName instanceof RegExp;
|
|
17
|
+
if (!isOperationNameStringOrRegExp) {
|
|
18
|
+
throw new Error(`configs[${index}].operationName`);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
(0, validateRoutes_1.validateRoutes)(config.routes, operationType);
|
|
22
|
+
(0, validateInterceptors_1.validateInterceptors)(config.interceptors);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`configs[${index}].${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
throw new Error('configs');
|
|
31
|
+
};
|
|
32
|
+
const validateGraphqlConfig = (graphqlConfig) => {
|
|
33
|
+
const isGraphqlConfigObject = (0, helpers_1.isPlainObject)(graphqlConfig);
|
|
34
|
+
if (isGraphqlConfigObject) {
|
|
35
|
+
try {
|
|
36
|
+
(0, validateBaseUrl_1.validateBaseUrl)(graphqlConfig.baseUrl);
|
|
37
|
+
validateConfigs(graphqlConfig.configs);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`graphql.${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (typeof graphqlConfig !== 'undefined') {
|
|
45
|
+
throw new Error('graphql');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.validateGraphqlConfig = validateGraphqlConfig;
|