mock-config-server 4.0.3 → 5.0.0-beta.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/README.md +229 -237
- package/dist/bin/build.d.ts +3 -3
- package/dist/bin/build.js +1 -11
- package/dist/bin/helpers/createTemplate.js +6 -6
- package/dist/bin/helpers/resolveConfigFile.d.ts +2 -2
- package/dist/bin/helpers/resolveConfigFile.js +2 -3
- package/dist/bin/helpers/resolveConfigFilePath.js +4 -4
- package/dist/bin/init.d.ts +2 -2
- package/dist/bin/init.js +7 -7
- package/dist/bin/run.d.ts +3 -3
- package/dist/bin/run.js +17 -24
- package/dist/bin/templates/ts/full/mock-server.config.ts +2 -2
- package/dist/bin/templates/ts/graphql/mock-server.config.ts +2 -2
- package/dist/bin/templates/ts/rest/mock-server.config.ts +2 -2
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +3 -3
- 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/functions/graphql/graphql.d.ts +54 -0
- package/dist/src/core/functions/graphql/graphql.js +126 -0
- package/dist/src/core/functions/graphql/helpers/createQueueHandler/createQueueHandler.d.ts +5 -0
- package/dist/src/core/functions/graphql/helpers/createQueueHandler/createQueueHandler.js +35 -0
- package/dist/src/core/functions/graphql/helpers/index.d.ts +1 -0
- package/dist/src/core/{rest/createRestRoutes → functions/graphql}/helpers/index.js +1 -1
- package/dist/src/core/functions/index.d.ts +3 -0
- package/dist/src/core/functions/index.js +20 -0
- package/dist/src/core/functions/mock.d.ts +2 -0
- package/dist/src/core/functions/mock.js +11 -0
- package/dist/src/core/functions/rest/helpers/createFileHandler/createFileHandler.d.ts +2 -0
- package/dist/src/core/functions/rest/helpers/createFileHandler/createFileHandler.js +29 -0
- package/dist/src/core/functions/rest/helpers/createQueueHandler/createQueueHandler.d.ts +5 -0
- package/dist/src/core/functions/rest/helpers/createQueueHandler/createQueueHandler.js +35 -0
- package/dist/src/core/functions/rest/helpers/formatSsePayload/formatSsePayload.d.ts +5 -0
- package/dist/src/core/functions/rest/helpers/formatSsePayload/formatSsePayload.js +50 -0
- package/dist/src/core/functions/rest/helpers/index.d.ts +3 -0
- package/dist/src/core/functions/rest/helpers/index.js +20 -0
- package/dist/src/core/functions/rest/index.d.ts +1 -0
- package/dist/src/core/{graphql/createGraphQLRoutes/helpers → functions/rest}/index.js +1 -1
- package/dist/src/core/functions/rest/rest.d.ts +114 -0
- package/dist/src/core/functions/rest/rest.js +171 -0
- package/dist/src/core/graphql/createGraphQLRoute/createGraphQLRoute.d.ts +8 -0
- package/dist/src/core/graphql/createGraphQLRoute/createGraphQLRoute.js +158 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/calculateGraphQLRouteConfigWeight/calculateGraphQLRouteConfigWeight.d.ts +2 -0
- package/dist/src/core/graphql/{createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js → createGraphQLRoute/helpers/calculateGraphQLRouteConfigWeight/calculateGraphQLRouteConfigWeight.js} +3 -11
- package/dist/src/core/graphql/createGraphQLRoute/helpers/index.d.ts +3 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/index.js +20 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/matchGraphQLRequestArtifacts/matchGraphQLRequestArtifacts.d.ts +12 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/matchGraphQLRequestArtifacts/matchGraphQLRequestArtifacts.js +28 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/prepareGraphQLRequestArtifacts/prepareGraphQLRequestArtifacts.d.ts +2 -0
- package/dist/src/core/graphql/createGraphQLRoute/helpers/prepareGraphQLRequestArtifacts/prepareGraphQLRequestArtifacts.js +11 -0
- package/dist/src/core/graphql/index.d.ts +2 -1
- package/dist/src/core/graphql/index.js +2 -1
- package/dist/src/core/middlewares/contextMiddleware/contextMiddleware.d.ts +6 -4
- package/dist/src/core/rest/createRestRoute/createRestRoute.d.ts +8 -0
- package/dist/src/core/rest/createRestRoute/createRestRoute.js +190 -0
- package/dist/src/core/rest/createRestRoute/helpers/calculateRestRouteConfigWeight/calculateRestRouteConfigWeight.d.ts +2 -0
- package/dist/src/core/rest/createRestRoute/helpers/calculateRestRouteConfigWeight/calculateRestRouteConfigWeight.js +35 -0
- package/dist/src/core/rest/createRestRoute/helpers/index.d.ts +3 -0
- package/dist/src/core/rest/createRestRoute/helpers/index.js +20 -0
- package/dist/src/core/rest/createRestRoute/helpers/matchRestRequestArtifacts/matchRestRequestArtifacts.d.ts +11 -0
- package/dist/src/core/rest/createRestRoute/helpers/matchRestRequestArtifacts/matchRestRequestArtifacts.js +31 -0
- package/dist/src/core/rest/createRestRoute/helpers/prepareRestRequestArtifacts/prepareRestRequestArtifacts.d.ts +2 -0
- package/dist/src/core/rest/createRestRoute/helpers/prepareRestRequestArtifacts/prepareRestRequestArtifacts.js +37 -0
- package/dist/src/core/rest/index.d.ts +2 -1
- package/dist/src/core/rest/index.js +2 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/server/createMockServer/createMockServer.d.ts +1 -1
- package/dist/src/server/createMockServer/createMockServer.js +76 -45
- package/dist/src/server/index.d.ts +0 -8
- package/dist/src/server/index.js +0 -8
- package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
- package/dist/src/server/startMockServer/startMockServer.js +4 -3
- package/dist/src/utils/constants/checkModes.js +7 -7
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +1 -1
- package/dist/src/utils/helpers/files/isFileDescriptor/isFileDescriptor.js +2 -2
- package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +3 -3
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts +3 -3
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +2 -2
- package/dist/src/utils/helpers/tests/createTmpDir.js +4 -4
- package/dist/src/utils/helpers/url/index.d.ts +1 -2
- package/dist/src/utils/helpers/url/index.js +1 -2
- package/dist/src/utils/helpers/url/normalizeUrl/normalizeUrl.d.ts +1 -0
- package/dist/src/utils/helpers/url/normalizeUrl/normalizeUrl.js +15 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +4 -4
- package/dist/src/utils/types/graphql.d.ts +44 -18
- package/dist/src/utils/types/rest.d.ts +44 -27
- package/dist/src/utils/types/server.d.ts +7 -24
- package/dist/src/utils/types/values.d.ts +2 -1
- package/dist/src/utils/validate/graphqlConfigSchema/graphqlConfigSchema.d.ts +41 -383
- package/dist/src/utils/validate/graphqlConfigSchema/graphqlConfigSchema.js +3 -3
- package/dist/src/utils/validate/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +3 -66
- package/dist/src/utils/validate/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +7 -22
- package/dist/src/utils/validate/index.d.ts +0 -2
- package/dist/src/utils/validate/index.js +0 -2
- package/dist/src/utils/validate/queueSchema/queueSchema.d.ts +2 -11
- package/dist/src/utils/validate/queueSchema/queueSchema.js +7 -13
- package/dist/src/utils/validate/restConfigSchema/restConfigSchema.d.ts +101 -1309
- package/dist/src/utils/validate/restConfigSchema/restConfigSchema.js +3 -3
- package/dist/src/utils/validate/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +3 -82
- package/dist/src/utils/validate/restConfigSchema/routeConfigSchema/routeConfigSchema.js +6 -28
- package/dist/src/utils/validate/settingsSchema/settingsSchema.d.ts +0 -3
- package/dist/src/utils/validate/settingsSchema/settingsSchema.js +0 -1
- package/dist/src/utils/validate/utils/checkModeSchema/checkModeSchema.js +6 -6
- package/dist/src/utils/validate/utils/entitiesSchema/entitiesSchema.js +4 -4
- package/dist/src/utils/validate/utils/jsonSchema/jsonSchema.js +3 -3
- package/dist/src/utils/validate/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +1 -1
- package/dist/src/utils/validate/utils/sharedSchema/sharedSchema.js +3 -3
- package/dist/src/utils/validate/validateMockServerConfig.js +18 -8
- package/package.json +17 -40
- package/LICENSE +0 -21
- package/dist/bin/runFlatConfig.d.ts +0 -5
- package/dist/bin/runFlatConfig.js +0 -36
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +0 -9
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +0 -160
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.d.ts +0 -1
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +0 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +0 -9
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +0 -184
- package/dist/src/core/rest/createRestRoutes/helpers/index.d.ts +0 -1
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +0 -2
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +0 -67
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.d.ts +0 -3
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +0 -62
- package/dist/src/server/createFlatMockServer/createFlatMockServer.d.ts +0 -3
- package/dist/src/server/createFlatMockServer/createFlatMockServer.js +0 -128
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.d.ts +0 -3
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +0 -67
- package/dist/src/server/createRestMockServer/createRestMockServer.d.ts +0 -3
- package/dist/src/server/createRestMockServer/createRestMockServer.js +0 -67
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.d.ts +0 -4
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +0 -29
- package/dist/src/server/startFlatMockServer/startFlatMockServer.d.ts +0 -4
- package/dist/src/server/startFlatMockServer/startFlatMockServer.js +0 -30
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.d.ts +0 -4
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +0 -29
- package/dist/src/server/startRestMockServer/startRestMockServer.d.ts +0 -4
- package/dist/src/server/startRestMockServer/startRestMockServer.js +0 -29
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +0 -1
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +0 -12
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +0 -1
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +0 -11
- package/dist/src/utils/validate/isOnlyRequestedDataResolvingPropertyExists.d.ts +0 -4
- package/dist/src/utils/validate/isOnlyRequestedDataResolvingPropertyExists.js +0 -16
- package/dist/src/utils/validate/validateApiMockServerConfig.d.ts +0 -2
- package/dist/src/utils/validate/validateApiMockServerConfig.js +0 -48
package/dist/bin/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const build: (argv:
|
|
3
|
-
destroy: import("http").Server["close"];
|
|
1
|
+
import type { MockServerCliArgv } from '../src/utils/types';
|
|
2
|
+
export declare const build: (argv: MockServerCliArgv) => Promise<(import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse> & {
|
|
3
|
+
destroy: import("node:http").Server["close"];
|
|
4
4
|
}) | undefined>;
|
package/dist/bin/build.js
CHANGED
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "build", {
|
|
|
11
11
|
const _esbuild = require("esbuild");
|
|
12
12
|
const _helpers = require("./helpers");
|
|
13
13
|
const _run = require("./run");
|
|
14
|
-
const _runFlatConfig = require("./runFlatConfig");
|
|
15
14
|
const build = async (argv)=>{
|
|
16
15
|
const configFilePath = (0, _helpers.resolveConfigFilePath)(argv.config);
|
|
17
16
|
if (!configFilePath) {
|
|
@@ -42,11 +41,6 @@ const build = async (argv)=>{
|
|
|
42
41
|
build.onEnd((result)=>{
|
|
43
42
|
if (!result.errors.length) {
|
|
44
43
|
const mockConfig = (0, _helpers.resolveConfigFile)(result.outputFiles[0].text);
|
|
45
|
-
const isFlatConfig = Array.isArray(mockConfig);
|
|
46
|
-
if (isFlatConfig) {
|
|
47
|
-
instance = (0, _runFlatConfig.runFlatConfig)(mockConfig, argv);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
44
|
instance = (0, _run.run)(mockConfig, argv);
|
|
51
45
|
}
|
|
52
46
|
});
|
|
@@ -59,9 +53,5 @@ const build = async (argv)=>{
|
|
|
59
53
|
}
|
|
60
54
|
const { outputFiles } = await (0, _esbuild.build)(buildOptions);
|
|
61
55
|
const mockConfig = (0, _helpers.resolveConfigFile)(outputFiles[0].text);
|
|
62
|
-
|
|
63
|
-
if (isFlatConfig) {
|
|
64
|
-
return (0, _runFlatConfig.runFlatConfig)(mockConfig, argv);
|
|
65
|
-
}
|
|
66
|
-
(0, _run.run)(mockConfig, argv);
|
|
56
|
+
return (0, _run.run)(mockConfig, argv);
|
|
67
57
|
};
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "createTemplate", {
|
|
|
8
8
|
return createTemplate;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
13
|
const _constants = require("../../src/utils/constants");
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
@@ -18,16 +18,16 @@ function _interop_require_default(obj) {
|
|
|
18
18
|
}
|
|
19
19
|
const createTemplate = (options)=>{
|
|
20
20
|
const language = options.withTypescript ? 'ts' : 'js';
|
|
21
|
-
const templatePath =
|
|
22
|
-
|
|
21
|
+
const templatePath = _path.default.join(__dirname, '..', `templates/${language}/${options.apiType}`);
|
|
22
|
+
_fs.default.cpSync(`${templatePath}/mock-requests`, `${_constants.APP_PATH}/mock-requests`, {
|
|
23
23
|
recursive: true,
|
|
24
24
|
force: true
|
|
25
25
|
});
|
|
26
|
-
let mockServerConfig =
|
|
26
|
+
let mockServerConfig = _fs.default.readFileSync(`${templatePath}/mock-server.config.${language}`, 'utf8');
|
|
27
27
|
if (options.staticPath !== '/') {
|
|
28
28
|
mockServerConfig = mockServerConfig.replace(`port: ${_constants.DEFAULT.PORT}`, `port: ${_constants.DEFAULT.PORT},\n\u0020\u0020\u0020\u0020staticPath: '${options.staticPath}'`);
|
|
29
29
|
}
|
|
30
30
|
mockServerConfig = mockServerConfig.replace(`port: ${_constants.DEFAULT.PORT}`, `port: ${options.port.toString()}`);
|
|
31
31
|
mockServerConfig = mockServerConfig.replace("baseUrl: '/'", `baseUrl: '${options.baseUrl}'`);
|
|
32
|
-
|
|
32
|
+
_fs.default.writeFileSync(`${_constants.APP_PATH}/mock-server.config.${language}`, mockServerConfig);
|
|
33
33
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const resolveConfigFile: (configSourceCode: string) =>
|
|
1
|
+
import type { MockServerConfig } from '../../src/utils/types';
|
|
2
|
+
export declare const resolveConfigFile: (configSourceCode: string) => MockServerConfig;
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "resolveConfigFile", {
|
|
|
8
8
|
return resolveConfigFile;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _helpers = require("../../src/utils/helpers");
|
|
12
11
|
const _resolveExportsFromSourceCode = require("./resolveExportsFromSourceCode");
|
|
13
12
|
const resolveConfigFile = (configSourceCode)=>{
|
|
14
13
|
if (!configSourceCode) {
|
|
@@ -19,8 +18,8 @@ const resolveConfigFile = (configSourceCode)=>{
|
|
|
19
18
|
if (!mockServerConfig) {
|
|
20
19
|
throw new Error('Cannot handle exports of mock-server.config.(ts|js)');
|
|
21
20
|
}
|
|
22
|
-
if (!
|
|
23
|
-
throw new
|
|
21
|
+
if (!Array.isArray(mockServerConfig)) {
|
|
22
|
+
throw new TypeError('configuration should be array config; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
|
|
24
23
|
}
|
|
25
24
|
return mockServerConfig;
|
|
26
25
|
};
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "resolveConfigFilePath", {
|
|
|
8
8
|
return resolveConfigFilePath;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
13
|
function _interop_require_default(obj) {
|
|
14
14
|
return obj && obj.__esModule ? obj : {
|
|
15
15
|
default: obj
|
|
@@ -17,7 +17,7 @@ function _interop_require_default(obj) {
|
|
|
17
17
|
}
|
|
18
18
|
const resolveConfigFilePath = (cliConfigFilePath)=>{
|
|
19
19
|
const appPath = process.cwd();
|
|
20
|
-
if (cliConfigFilePath) return
|
|
20
|
+
if (cliConfigFilePath) return _path.default.resolve(appPath, cliConfigFilePath);
|
|
21
21
|
const configFileNameRegex = /mock-server.config.(?:ts|mts|cts|js|mjs|cjs)/;
|
|
22
|
-
return
|
|
22
|
+
return _fs.default.readdirSync(appPath).find((fileName)=>configFileNameRegex.test(fileName));
|
|
23
23
|
};
|
package/dist/bin/init.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const init: (argv:
|
|
1
|
+
import type { MockServerCliArgv } from '../src/utils/types';
|
|
2
|
+
export declare const init: (argv: MockServerCliArgv) => Promise<void>;
|
package/dist/bin/init.js
CHANGED
|
@@ -31,22 +31,22 @@ const init = async (argv)=>{
|
|
|
31
31
|
{
|
|
32
32
|
type: 'select',
|
|
33
33
|
name: 'apiType',
|
|
34
|
-
message: 'Choose
|
|
34
|
+
message: 'Choose API type',
|
|
35
35
|
initial: 0,
|
|
36
36
|
choices: [
|
|
37
37
|
{
|
|
38
|
-
title: '
|
|
39
|
-
description: '
|
|
38
|
+
title: 'REST',
|
|
39
|
+
description: 'REST API sample',
|
|
40
40
|
value: 'rest'
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
title: 'GraphQL',
|
|
44
|
-
description: 'GraphQL
|
|
44
|
+
description: 'GraphQL API sample',
|
|
45
45
|
value: 'graphql'
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
title: 'Both',
|
|
49
|
-
description: '
|
|
49
|
+
description: 'REST API and GraphQL API sample',
|
|
50
50
|
value: 'full'
|
|
51
51
|
}
|
|
52
52
|
]
|
|
@@ -54,14 +54,14 @@ const init = async (argv)=>{
|
|
|
54
54
|
{
|
|
55
55
|
name: 'baseUrl',
|
|
56
56
|
type: argv.baseUrl ? null : 'text',
|
|
57
|
-
message: 'Base
|
|
57
|
+
message: 'Base URL (must start with a forward slash):',
|
|
58
58
|
initial: '/',
|
|
59
59
|
validate: (baseUrl)=>{
|
|
60
60
|
try {
|
|
61
61
|
_validate.baseUrlSchema.parse(baseUrl);
|
|
62
62
|
return true;
|
|
63
63
|
} catch {
|
|
64
|
-
return 'Invalid base
|
|
64
|
+
return 'Invalid base URL value';
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
},
|
package/dist/bin/run.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type {
|
|
3
|
-
export declare const run: (
|
|
4
|
-
destroy: import("http").Server["close"];
|
|
2
|
+
import type { MockServerCliArgv, MockServerConfig } from '../src';
|
|
3
|
+
export declare const run: (mockServerConfig: MockServerConfig, { baseUrl, port, staticPath }: MockServerCliArgv) => (import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse> & {
|
|
4
|
+
destroy: import("node:http").Server["close"];
|
|
5
5
|
}) | undefined;
|
package/dist/bin/run.js
CHANGED
|
@@ -10,32 +10,25 @@ Object.defineProperty(exports, "run", {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
const _server = require("../src/server");
|
|
13
|
-
const
|
|
14
|
-
const run = (mockConfig, { baseUrl, port, staticPath })=>{
|
|
15
|
-
console.warn(`**DEPRECATION WARNING**\nThe old mock config format is deprecated and will be removed in the next major version. Please use new format of config (flat config); see our doc (https://github.com/siberiacancode/mock-config-server) for more information`);
|
|
13
|
+
const run = (mockServerConfig, { baseUrl, port, staticPath })=>{
|
|
16
14
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const [option, ...mockServerComponents] = mockServerConfig;
|
|
16
|
+
const mockServerSettings = !('configs' in option) ? option : undefined;
|
|
17
|
+
const mergedMockServerConfig = [
|
|
18
|
+
{
|
|
19
|
+
...mockServerSettings,
|
|
20
|
+
...baseUrl && {
|
|
21
|
+
baseUrl
|
|
22
|
+
},
|
|
23
|
+
...port && {
|
|
24
|
+
port
|
|
25
|
+
},
|
|
26
|
+
...staticPath && {
|
|
27
|
+
staticPath
|
|
28
|
+
}
|
|
21
29
|
},
|
|
22
|
-
...
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
...staticPath && {
|
|
26
|
-
staticPath
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
if (!mergedMockServerConfig.rest && !mergedMockServerConfig.graphql && 'configs' in mergedMockServerConfig) {
|
|
30
|
-
const mergedApiMockServerConfig = mergedMockServerConfig;
|
|
31
|
-
if (Array.isArray(mergedApiMockServerConfig.configs) && (0, _helpers.isPlainObject)(mergedApiMockServerConfig.configs[0]) && 'path' in mergedApiMockServerConfig.configs[0]) {
|
|
32
|
-
return (0, _server.startRestMockServer)(mergedApiMockServerConfig);
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(mergedApiMockServerConfig.configs) && (0, _helpers.isPlainObject)(mergedApiMockServerConfig.configs[0]) && ('query' in mergedApiMockServerConfig.configs[0] || 'operationName' in mergedApiMockServerConfig.configs[0])) {
|
|
35
|
-
return (0, _server.startGraphQLMockServer)(mergedApiMockServerConfig);
|
|
36
|
-
}
|
|
37
|
-
return (0, _server.startRestMockServer)(mergedApiMockServerConfig);
|
|
38
|
-
}
|
|
30
|
+
...mockServerSettings ? mockServerComponents : mockServerConfig
|
|
31
|
+
];
|
|
39
32
|
return (0, _server.startMockServer)(mergedMockServerConfig);
|
|
40
33
|
} catch (error) {
|
|
41
34
|
console.error(error.message);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MockServerConfig } from 'mock-config-server';
|
|
2
2
|
|
|
3
3
|
import { createUserMutation, getUserQuery, getUsersQuery } from './mock-requests/graphql';
|
|
4
4
|
import { getUserRequest, getUsersRequest, postUserRequest } from './mock-requests/rest';
|
|
5
5
|
|
|
6
|
-
const mockServerConfig:
|
|
6
|
+
const mockServerConfig: MockServerConfig = [
|
|
7
7
|
{
|
|
8
8
|
port: 31299,
|
|
9
9
|
baseUrl: '/'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MockServerConfig } from 'mock-config-server';
|
|
2
2
|
|
|
3
3
|
import { createUserMutation, getUserQuery, getUsersQuery } from './mock-requests';
|
|
4
4
|
|
|
5
|
-
const mockServerConfig:
|
|
5
|
+
const mockServerConfig: MockServerConfig = [
|
|
6
6
|
{
|
|
7
7
|
port: 31299,
|
|
8
8
|
baseUrl: '/graphql'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MockServerConfig } from 'mock-config-server';
|
|
2
2
|
|
|
3
3
|
import { getUserRequest, getUsersRequest, postUserRequest } from './mock-requests';
|
|
4
4
|
|
|
5
|
-
const mockServerConfig:
|
|
5
|
+
const mockServerConfig: MockServerConfig = [
|
|
6
6
|
{
|
|
7
7
|
port: 31299,
|
|
8
8
|
baseUrl: '/'
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
search
|
|
12
|
+
get search () {
|
|
13
13
|
return search;
|
|
14
14
|
},
|
|
15
|
-
searchInNestedObjects
|
|
15
|
+
get searchInNestedObjects () {
|
|
16
16
|
return searchInNestedObjects;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "FileStorage", {
|
|
|
8
8
|
return FileStorage;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
13
|
const _constants = require("../../../../../utils/constants");
|
|
14
14
|
const _helpers = require("../../helpers");
|
|
15
15
|
const _FileWriter = require("./FileWriter");
|
|
@@ -22,9 +22,9 @@ class FileStorage {
|
|
|
22
22
|
fileWriter;
|
|
23
23
|
data;
|
|
24
24
|
constructor(fileName){
|
|
25
|
-
const filePath =
|
|
25
|
+
const filePath = _path.default.resolve(_constants.APP_PATH, fileName);
|
|
26
26
|
this.fileWriter = new _FileWriter.FileWriter(filePath);
|
|
27
|
-
this.data = JSON.parse(
|
|
27
|
+
this.data = JSON.parse(_fs.default.readFileSync(filePath, 'utf-8'));
|
|
28
28
|
}
|
|
29
29
|
read(key) {
|
|
30
30
|
if (!key) return this.data;
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "FileWriter", {
|
|
|
8
8
|
return FileWriter;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
function _interop_require_default(obj) {
|
|
13
13
|
return obj && obj.__esModule ? obj : {
|
|
14
14
|
default: obj
|
|
@@ -38,7 +38,7 @@ class FileWriter {
|
|
|
38
38
|
}
|
|
39
39
|
async unlockedWrite(data, recursionLevel = 0) {
|
|
40
40
|
this.writeIsLocked = true;
|
|
41
|
-
await
|
|
41
|
+
await _fs.default.promises.writeFile(this.filePath, data, 'utf-8');
|
|
42
42
|
this.writeIsLocked = false;
|
|
43
43
|
// ✅ important:
|
|
44
44
|
// copy content of this.nextData into new variable
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Data, GraphQLEntitiesByEntityName, GraphQLOperationName, GraphQLOperationType, GraphQLParams, GraphQLRequestConfig, GraphQLSettings } from '../../../utils/types';
|
|
2
|
+
interface GraphQLRequestInput {
|
|
3
|
+
body?: unknown;
|
|
4
|
+
params?: unknown;
|
|
5
|
+
query?: unknown;
|
|
6
|
+
response?: Data;
|
|
7
|
+
}
|
|
8
|
+
type ReservedGraphQLConfigKeys = {
|
|
9
|
+
[K in 'handler' | 'match' | 'queue' | 'response']?: never;
|
|
10
|
+
};
|
|
11
|
+
type GraphQLInlineResponse<Response> = Response extends Record<string, unknown> ? Response & ReservedGraphQLConfigKeys : Response;
|
|
12
|
+
type GraphQLFunction<Options extends GraphQLRequestInput> = (params: GraphQLParams<Options['query'], Options['body'], Options['params'], Options['response']>) => Options['response'] | Promise<Options['response']>;
|
|
13
|
+
interface GraphQLResponseObject<Response> {
|
|
14
|
+
match?: GraphQLEntitiesByEntityName;
|
|
15
|
+
response: Response;
|
|
16
|
+
}
|
|
17
|
+
interface GraphQLHandlerObject<Options extends GraphQLRequestInput> {
|
|
18
|
+
handler: GraphQLFunction<Options>;
|
|
19
|
+
match?: GraphQLEntitiesByEntityName;
|
|
20
|
+
}
|
|
21
|
+
interface GraphQLQueueObject<Options extends GraphQLRequestInput> {
|
|
22
|
+
match?: GraphQLEntitiesByEntityName;
|
|
23
|
+
queue: Array<{
|
|
24
|
+
handler: GraphQLFunction<Options>;
|
|
25
|
+
time?: number;
|
|
26
|
+
} | {
|
|
27
|
+
response: Options['response'];
|
|
28
|
+
time?: number;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export declare const graphql: {
|
|
32
|
+
query: {
|
|
33
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLResponseObject<Options["response"]>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
34
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLHandlerObject<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
35
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLFunction<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
36
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLQueueObject<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
37
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLInlineResponse<Options["response"]>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
38
|
+
};
|
|
39
|
+
mutation: {
|
|
40
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLResponseObject<Options["response"]>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
41
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLHandlerObject<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
42
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLFunction<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
43
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLQueueObject<Options>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
44
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: GraphQLOperationName, config: GraphQLInlineResponse<Options["response"]>, settings?: GraphQLSettings, operationType?: undefined): GraphQLRequestConfig;
|
|
45
|
+
};
|
|
46
|
+
raw: {
|
|
47
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: string, config: GraphQLResponseObject<Options["response"]>, settings?: GraphQLSettings, operationType?: GraphQLOperationType | undefined): GraphQLRequestConfig;
|
|
48
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: string, config: GraphQLHandlerObject<Options>, settings?: GraphQLSettings, operationType?: GraphQLOperationType | undefined): GraphQLRequestConfig;
|
|
49
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: string, config: GraphQLFunction<Options>, settings?: GraphQLSettings, operationType?: GraphQLOperationType | undefined): GraphQLRequestConfig;
|
|
50
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: string, config: GraphQLQueueObject<Options>, settings?: GraphQLSettings, operationType?: GraphQLOperationType | undefined): GraphQLRequestConfig;
|
|
51
|
+
<Options extends GraphQLRequestInput = Partial<GraphQLRequestInput>>(identifier: string, config: GraphQLInlineResponse<Options["response"]>, settings?: GraphQLSettings, operationType?: GraphQLOperationType | undefined): GraphQLRequestConfig;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "graphql", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return graphql;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _helpers = require("./helpers");
|
|
12
|
+
const resolveConfigType = (config)=>{
|
|
13
|
+
if (typeof config === 'function') return {
|
|
14
|
+
type: 'inlineHandler',
|
|
15
|
+
config
|
|
16
|
+
};
|
|
17
|
+
if (typeof config !== 'object' || config === null) return {
|
|
18
|
+
type: 'inlineResponse',
|
|
19
|
+
config
|
|
20
|
+
};
|
|
21
|
+
if ('queue' in config) return {
|
|
22
|
+
type: 'queue',
|
|
23
|
+
config
|
|
24
|
+
};
|
|
25
|
+
if ('response' in config) return {
|
|
26
|
+
type: 'data',
|
|
27
|
+
config
|
|
28
|
+
};
|
|
29
|
+
if ('handler' in config) return {
|
|
30
|
+
type: 'handlerObj',
|
|
31
|
+
config
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
type: 'inlineResponse',
|
|
35
|
+
config
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const createConfigResolver = (config, settings = {})=>{
|
|
39
|
+
const resolvedConfig = resolveConfigType(config);
|
|
40
|
+
switch(resolvedConfig.type){
|
|
41
|
+
case 'inlineResponse':
|
|
42
|
+
return {
|
|
43
|
+
data: resolvedConfig.config,
|
|
44
|
+
entities: {},
|
|
45
|
+
settings
|
|
46
|
+
};
|
|
47
|
+
case 'data':
|
|
48
|
+
{
|
|
49
|
+
var _resolvedConfig_config_match;
|
|
50
|
+
return {
|
|
51
|
+
data: resolvedConfig.config.response,
|
|
52
|
+
entities: (_resolvedConfig_config_match = resolvedConfig.config.match) !== null && _resolvedConfig_config_match !== void 0 ? _resolvedConfig_config_match : {},
|
|
53
|
+
settings
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
case 'queue':
|
|
57
|
+
{
|
|
58
|
+
const normalizedQueue = resolvedConfig.config.queue.map((item)=>{
|
|
59
|
+
if ('handler' in item) {
|
|
60
|
+
return {
|
|
61
|
+
data: item.handler,
|
|
62
|
+
time: item.time
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if ('response' in item) {
|
|
66
|
+
return {
|
|
67
|
+
data: item.response,
|
|
68
|
+
time: item.time
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Unexpected queue item kind: ${JSON.stringify(item, null, 2)}`);
|
|
72
|
+
});
|
|
73
|
+
var _resolvedConfig_config_match1;
|
|
74
|
+
return {
|
|
75
|
+
data: (0, _helpers.createQueueHandler)(normalizedQueue),
|
|
76
|
+
entities: (_resolvedConfig_config_match1 = resolvedConfig.config.match) !== null && _resolvedConfig_config_match1 !== void 0 ? _resolvedConfig_config_match1 : {},
|
|
77
|
+
settings
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
case 'inlineHandler':
|
|
81
|
+
return {
|
|
82
|
+
data: resolvedConfig.config,
|
|
83
|
+
entities: {},
|
|
84
|
+
settings
|
|
85
|
+
};
|
|
86
|
+
case 'handlerObj':
|
|
87
|
+
{
|
|
88
|
+
var _resolvedConfig_config_match2;
|
|
89
|
+
return {
|
|
90
|
+
data: resolvedConfig.config.handler,
|
|
91
|
+
entities: (_resolvedConfig_config_match2 = resolvedConfig.config.match) !== null && _resolvedConfig_config_match2 !== void 0 ? _resolvedConfig_config_match2 : {},
|
|
92
|
+
settings
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
{
|
|
97
|
+
throw new Error(`Unexpected route config kind: ${JSON.stringify(config, null, 2)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const createGraphQLFactory = (mode)=>{
|
|
102
|
+
function createRequestConfig(identifier, config, settings, operationType) {
|
|
103
|
+
if (mode === 'raw') {
|
|
104
|
+
return {
|
|
105
|
+
query: identifier,
|
|
106
|
+
operationType: operationType !== null && operationType !== void 0 ? operationType : 'query',
|
|
107
|
+
routes: [
|
|
108
|
+
createConfigResolver(config, settings)
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
operationName: identifier,
|
|
114
|
+
operationType: mode,
|
|
115
|
+
routes: [
|
|
116
|
+
createConfigResolver(config, settings)
|
|
117
|
+
]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return createRequestConfig;
|
|
121
|
+
};
|
|
122
|
+
const graphql = {
|
|
123
|
+
query: createGraphQLFactory('query'),
|
|
124
|
+
mutation: createGraphQLFactory('mutation'),
|
|
125
|
+
raw: createGraphQLFactory('raw')
|
|
126
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createQueueHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createQueueHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const createQueueHandler = (normalizedQueue)=>{
|
|
12
|
+
let queueIndex = 0;
|
|
13
|
+
let timeoutInProgress = false;
|
|
14
|
+
const updateQueueIndex = ()=>{
|
|
15
|
+
queueIndex = normalizedQueue.length - 1 === queueIndex ? 0 : queueIndex + 1;
|
|
16
|
+
};
|
|
17
|
+
return async (params)=>{
|
|
18
|
+
if (!normalizedQueue.length) {
|
|
19
|
+
return params.next();
|
|
20
|
+
}
|
|
21
|
+
const queueItem = normalizedQueue[queueIndex];
|
|
22
|
+
const { time } = queueItem;
|
|
23
|
+
if (time && !timeoutInProgress) {
|
|
24
|
+
timeoutInProgress = true;
|
|
25
|
+
setTimeout(()=>{
|
|
26
|
+
timeoutInProgress = false;
|
|
27
|
+
updateQueueIndex();
|
|
28
|
+
}, time);
|
|
29
|
+
}
|
|
30
|
+
if (!time) {
|
|
31
|
+
updateQueueIndex();
|
|
32
|
+
}
|
|
33
|
+
return typeof queueItem.data === 'function' ? queueItem.data(params) : queueItem.data;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createQueueHandler/createQueueHandler';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
_export_star(require("./
|
|
5
|
+
_export_star(require("./createQueueHandler/createQueueHandler"), exports);
|
|
6
6
|
function _export_star(from, to) {
|
|
7
7
|
Object.keys(from).forEach(function(k) {
|
|
8
8
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./graphql/graphql"), exports);
|
|
6
|
+
_export_star(require("./mock"), exports);
|
|
7
|
+
_export_star(require("./rest/rest"), exports);
|
|
8
|
+
function _export_star(from, to) {
|
|
9
|
+
Object.keys(from).forEach(function(k) {
|
|
10
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
+
Object.defineProperty(to, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return from[k];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return from;
|
|
20
|
+
}
|