mock-config-server 3.4.0 → 3.5.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/dist/bin/bin.js +5 -8
- package/dist/bin/build.js +52 -50
- package/dist/bin/cli.js +50 -43
- package/dist/bin/helpers/createTemplate.js +29 -21
- package/dist/bin/helpers/getMostSpecificPathFromError.js +34 -30
- package/dist/bin/helpers/getValidationMessageFromPath.js +11 -8
- package/dist/bin/helpers/index.js +21 -79
- package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +13 -6
- package/dist/bin/helpers/resolveConfigFile.js +22 -19
- package/dist/bin/helpers/resolveConfigFilePath.js +19 -12
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +13 -10
- package/dist/bin/init.js +114 -97
- package/dist/bin/run.js +42 -37
- package/dist/bin/templates/js/full/mock-server.config.js +16 -16
- package/dist/bin/templates/js/graphql/mock-server.config.js +9 -9
- package/dist/bin/templates/js/rest/mock-server.config.js +9 -9
- package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -2
- package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -37
- package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -14
- package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -2
- package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -37
- package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -14
- package/dist/bin/templates/ts/full/mock-server.config.ts +18 -18
- package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -2
- package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -37
- package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -14
- package/dist/bin/templates/ts/graphql/mock-server.config.ts +11 -11
- package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -2
- package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -37
- package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -14
- package/dist/bin/templates/ts/rest/mock-server.config.ts +11 -11
- package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +32 -14
- package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +38 -22
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +38 -28
- package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +12 -8
- package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +18 -9
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +33 -19
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +62 -48
- package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +13 -9
- package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +27 -9
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +117 -60
- package/dist/bin/validateMockServerConfig/utils/index.js +20 -68
- package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +30 -10
- package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +9 -8
- package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -7
- package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +18 -6
- package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +43 -40
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +38 -35
- package/dist/index.js +15 -13
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +25 -28
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +14 -11
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.js +17 -35
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +157 -143
- package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.js +15 -8
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +88 -94
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +44 -47
- package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +19 -57
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +32 -31
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +34 -24
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +38 -34
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +26 -25
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +65 -50
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +55 -48
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +51 -41
- package/dist/src/core/database/createDatabaseRoutes/storages/index.js +16 -24
- package/dist/src/core/database/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +126 -140
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +36 -41
- package/dist/src/core/graphql/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +18 -15
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +50 -47
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +17 -12
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -20
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +23 -17
- package/dist/src/core/middlewares/index.js +23 -91
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +22 -19
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +21 -23
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +80 -80
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -34
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +16 -24
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +17 -35
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +58 -60
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +16 -17
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +32 -25
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +120 -130
- package/dist/src/core/rest/createRestRoutes/helpers/index.js +15 -13
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +37 -43
- package/dist/src/core/rest/index.js +15 -13
- package/dist/src/index.js +16 -24
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +56 -53
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +64 -62
- package/dist/src/server/createMockServer/createMockServer.js +94 -91
- package/dist/src/server/createRestMockServer/createRestMockServer.js +64 -62
- package/dist/src/server/index.js +23 -91
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +25 -19
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +25 -19
- package/dist/src/server/startMockServer/startMockServer.js +25 -19
- package/dist/src/server/startRestMockServer/startRestMockServer.js +25 -19
- package/dist/src/utils/constants/appPath.js +8 -4
- package/dist/src/utils/constants/checkModes.js +74 -11
- package/dist/src/utils/constants/default.js +18 -14
- package/dist/src/utils/constants/index.js +17 -35
- package/dist/src/utils/helpers/asyncHandler.js +8 -5
- package/dist/src/utils/helpers/config/index.js +15 -13
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +103 -110
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +12 -9
- package/dist/src/utils/helpers/entities/index.js +16 -24
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +9 -6
- package/dist/src/utils/helpers/files/index.js +15 -13
- package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +22 -15
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +25 -29
- package/dist/src/utils/helpers/graphql/index.js +17 -35
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +13 -10
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +23 -19
- package/dist/src/utils/helpers/index.js +26 -124
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +21 -21
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +62 -64
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +10 -7
- package/dist/src/utils/helpers/interceptors/index.js +16 -24
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +8 -5
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +8 -5
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +8 -5
- package/dist/src/utils/helpers/sleep.js +9 -6
- package/dist/src/utils/helpers/tests/createTmpDir.js +16 -9
- package/dist/src/utils/helpers/tests/index.js +15 -13
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -5
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +9 -6
- package/dist/src/utils/helpers/url/index.js +18 -46
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +8 -5
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +18 -11
- package/dist/src/utils/types/checkModes.js +4 -1
- package/dist/src/utils/types/database.js +4 -1
- package/dist/src/utils/types/entities.js +4 -1
- package/dist/src/utils/types/graphql.js +4 -1
- package/dist/src/utils/types/index.js +24 -102
- package/dist/src/utils/types/interceptors.js +4 -1
- package/dist/src/utils/types/rest.js +4 -1
- package/dist/src/utils/types/server.js +4 -1
- package/dist/src/utils/types/utils.js +4 -1
- package/dist/src/utils/types/values.js +4 -1
- package/package.json +8 -9
- package/dist/bin/templates/.eslintrc.js +0 -14
- package/dist/bin/templates/tsconfig.json +0 -11
package/dist/bin/bin.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
4
|
+
value: true
|
|
6
5
|
});
|
|
7
|
-
const pleaseUpgradeNode = require(
|
|
8
|
-
const packageJson = require(
|
|
6
|
+
const pleaseUpgradeNode = require("please-upgrade-node");
|
|
7
|
+
const packageJson = require("../../package.json");
|
|
9
8
|
pleaseUpgradeNode(packageJson);
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
} = require('./cli');
|
|
13
|
-
cli();
|
|
9
|
+
const { cli } = require("./cli");
|
|
10
|
+
cli();
|
package/dist/bin/build.js
CHANGED
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _instance;
|
|
34
|
-
(_instance = instance) === null || _instance === void 0 || _instance.destroy();
|
|
35
|
-
});
|
|
36
|
-
build.onEnd(result => {
|
|
37
|
-
if (!result.errors.length) {
|
|
38
|
-
const mockConfig = (0, _helpers.resolveConfigFile)(result.outputFiles[0].text);
|
|
39
|
-
instance = (0, _run.run)(mockConfig, argv);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
5
|
+
Object.defineProperty(exports, "build", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return build;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _esbuild = require("esbuild");
|
|
12
|
+
const _helpers = require("./helpers");
|
|
13
|
+
const _run = require("./run");
|
|
14
|
+
const build = async (argv)=>{
|
|
15
|
+
const configFilePath = (0, _helpers.resolveConfigFilePath)(argv.config);
|
|
16
|
+
if (!configFilePath) {
|
|
17
|
+
throw new Error("Cannot find config file mock-server.config.(ts|mts|cts|js|mjs|cjs)");
|
|
18
|
+
}
|
|
19
|
+
const buildOptions = {
|
|
20
|
+
entryPoints: [
|
|
21
|
+
configFilePath
|
|
22
|
+
],
|
|
23
|
+
bundle: true,
|
|
24
|
+
platform: "node",
|
|
25
|
+
target: "esnext",
|
|
26
|
+
minifySyntax: true,
|
|
27
|
+
minify: true,
|
|
28
|
+
write: false,
|
|
29
|
+
metafile: false,
|
|
30
|
+
logLevel: "info",
|
|
31
|
+
plugins: []
|
|
43
32
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
if (argv.watch) {
|
|
34
|
+
const watchPlugin = {
|
|
35
|
+
name: "watch",
|
|
36
|
+
setup: (build)=>{
|
|
37
|
+
let instance;
|
|
38
|
+
build.onStart(()=>{
|
|
39
|
+
instance === null || instance === void 0 ? void 0 : instance.destroy();
|
|
40
|
+
});
|
|
41
|
+
build.onEnd((result)=>{
|
|
42
|
+
if (!result.errors.length) {
|
|
43
|
+
const mockConfig = (0, _helpers.resolveConfigFile)(result.outputFiles[0].text);
|
|
44
|
+
instance = (0, _run.run)(mockConfig, argv);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
buildOptions.plugins.push(watchPlugin);
|
|
50
|
+
const ctx = await (0, _esbuild.context)(buildOptions);
|
|
51
|
+
ctx.watch();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const { outputFiles } = await (0, _esbuild.build)(buildOptions);
|
|
55
|
+
const mockConfig = (0, _helpers.resolveConfigFile)(outputFiles[0].text);
|
|
56
|
+
(0, _run.run)(mockConfig, argv);
|
|
54
57
|
};
|
|
55
|
-
exports.build = build;
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,50 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Object.defineProperty(exports, "cli", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cli;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _yargs = /*#__PURE__*/ _interop_require_default(require("yargs"));
|
|
12
|
+
const _helpers = require("yargs/helpers");
|
|
13
|
+
const _build = require("./build");
|
|
14
|
+
const _init = require("./init");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
const initOptions = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
port: {
|
|
19
|
-
alias: 'p',
|
|
20
|
-
description: 'Set port for server',
|
|
21
|
-
type: 'number'
|
|
22
|
-
},
|
|
23
|
-
staticPath: {
|
|
24
|
-
alias: 's',
|
|
25
|
-
description: 'Set static path for mock server',
|
|
26
|
-
type: 'string'
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const cli = () => {
|
|
30
|
-
const processArgv = (0, _helpers.hideBin)(process.argv);
|
|
31
|
-
if (processArgv.includes('init')) {
|
|
32
|
-
const argv = (0, _yargs.default)(processArgv).options(initOptions).parse();
|
|
33
|
-
return (0, _init.init)(argv);
|
|
34
|
-
}
|
|
35
|
-
const argv = (0, _yargs.default)(processArgv).usage('mcs [options]').epilogue('More info: https://github.com/siberiacancode/mock-config-server#readme').options({
|
|
36
|
-
...initOptions,
|
|
37
|
-
config: {
|
|
38
|
-
alias: 'c',
|
|
39
|
-
description: 'Set path to config file',
|
|
40
|
-
type: 'string'
|
|
21
|
+
baseUrl: {
|
|
22
|
+
alias: "b",
|
|
23
|
+
description: "Set base url for mock server",
|
|
24
|
+
type: "string"
|
|
41
25
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
port: {
|
|
27
|
+
alias: "p",
|
|
28
|
+
description: "Set port for server",
|
|
29
|
+
type: "number"
|
|
30
|
+
},
|
|
31
|
+
staticPath: {
|
|
32
|
+
alias: "s",
|
|
33
|
+
description: "Set static path for mock server",
|
|
34
|
+
type: "string"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const cli = ()=>{
|
|
38
|
+
const processArgv = (0, _helpers.hideBin)(process.argv);
|
|
39
|
+
if (processArgv.includes("init")) {
|
|
40
|
+
const argv = (0, _yargs.default)(processArgv).options(initOptions).parse();
|
|
41
|
+
return (0, _init.init)(argv);
|
|
46
42
|
}
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const argv = (0, _yargs.default)(processArgv).usage("mcs [options]").epilogue("More info: https://github.com/siberiacancode/mock-config-server#readme").options({
|
|
44
|
+
...initOptions,
|
|
45
|
+
config: {
|
|
46
|
+
alias: "c",
|
|
47
|
+
description: "Set path to config file",
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
watch: {
|
|
51
|
+
alias: "w",
|
|
52
|
+
description: "Enables server restart after config file changes",
|
|
53
|
+
type: "boolean"
|
|
54
|
+
}
|
|
55
|
+
}).version().alias("version", "v").help().alias("help", "h").parse();
|
|
56
|
+
(0, _build.build)(argv);
|
|
49
57
|
};
|
|
50
|
-
exports.cli = cli;
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
Object.defineProperty(exports, "createTemplate", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createTemplate;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
|
|
12
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
13
|
+
const _constants = require("../../src/utils/constants");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const createTemplate = (options)=>{
|
|
20
|
+
const language = options.withTypescript ? "ts" : "js";
|
|
21
|
+
const templatePath = _nodepath.default.join(__dirname, "..", `templates/${language}/${options.apiType}`);
|
|
22
|
+
_nodefs.default.cpSync(`${templatePath}/mock-requests`, `${_constants.APP_PATH}/mock-requests`, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
force: true
|
|
25
|
+
});
|
|
26
|
+
let mockServerConfig = _nodefs.default.readFileSync(`${templatePath}/mock-server.config.${language}`, "utf8");
|
|
27
|
+
if (options.staticPath !== "/") {
|
|
28
|
+
mockServerConfig = mockServerConfig.replace(`port: ${_constants.DEFAULT.PORT}`, `port: ${_constants.DEFAULT.PORT},\n staticPath: '${options.staticPath}'`);
|
|
29
|
+
}
|
|
30
|
+
mockServerConfig = mockServerConfig.replace(`port: ${_constants.DEFAULT.PORT}`, `port: ${options.port.toString()}`);
|
|
31
|
+
mockServerConfig = mockServerConfig.replace("baseUrl: '/'", `baseUrl: '${options.baseUrl}'`);
|
|
32
|
+
_nodefs.default.writeFileSync(`${_constants.APP_PATH}/mock-server.config.${language}`, mockServerConfig);
|
|
24
33
|
};
|
|
25
|
-
exports.createTemplate = createTemplate;
|
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (const issue of error.issues) {
|
|
11
|
-
if (issue.code === _zod.z.ZodIssueCode.invalid_union) {
|
|
12
|
-
for (const unionError of issue.unionErrors) {
|
|
13
|
-
const unionErrorMostSpecificPath = getMostSpecificPathFromError(unionError);
|
|
14
|
-
if (unionErrorMostSpecificPath.length > currentMostSpecificPath.length) {
|
|
15
|
-
currentMostSpecificPath = unionErrorMostSpecificPath;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
// eslint-disable-next-line no-continue
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
if (issue.code === _zod.z.ZodIssueCode.unrecognized_keys) {
|
|
22
|
-
const [unrecognizedKey] = issue.keys;
|
|
23
|
-
const issuePath = [...issue.path, unrecognizedKey];
|
|
24
|
-
if (issuePath.length > currentMostSpecificPath.length) {
|
|
25
|
-
currentMostSpecificPath = issuePath;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line no-continue
|
|
28
|
-
continue;
|
|
5
|
+
Object.defineProperty(exports, "getMostSpecificPathFromError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getMostSpecificPathFromError;
|
|
29
9
|
}
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
});
|
|
11
|
+
const _zod = require("zod");
|
|
12
|
+
const getMostSpecificPathFromError = (error)=>{
|
|
13
|
+
let currentMostSpecificPath = [];
|
|
14
|
+
for (const issue of error.issues){
|
|
15
|
+
if (issue.code === _zod.z.ZodIssueCode.invalid_union) {
|
|
16
|
+
for (const unionError of issue.unionErrors){
|
|
17
|
+
const unionErrorMostSpecificPath = getMostSpecificPathFromError(unionError);
|
|
18
|
+
if (unionErrorMostSpecificPath.length > currentMostSpecificPath.length) {
|
|
19
|
+
currentMostSpecificPath = unionErrorMostSpecificPath;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (issue.code === _zod.z.ZodIssueCode.unrecognized_keys) {
|
|
25
|
+
const [unrecognizedKey] = issue.keys;
|
|
26
|
+
const issuePath = [
|
|
27
|
+
...issue.path,
|
|
28
|
+
unrecognizedKey
|
|
29
|
+
];
|
|
30
|
+
if (issuePath.length > currentMostSpecificPath.length) {
|
|
31
|
+
currentMostSpecificPath = issuePath;
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (issue.path.length > currentMostSpecificPath.length) {
|
|
36
|
+
currentMostSpecificPath = issue.path;
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
|
-
|
|
34
|
-
return currentMostSpecificPath;
|
|
39
|
+
return currentMostSpecificPath;
|
|
35
40
|
};
|
|
36
|
-
exports.getMostSpecificPathFromError = getMostSpecificPathFromError;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
5
|
+
Object.defineProperty(exports, "getValidationMessageFromPath", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getValidationMessageFromPath;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const getValidationMessageFromPath = (path)=>path.reduce((validationMessageAcc, pathElement)=>{
|
|
12
|
+
if (typeof pathElement === "number") return `${validationMessageAcc}[${pathElement}]`;
|
|
13
|
+
return `${validationMessageAcc}.${pathElement}`;
|
|
14
|
+
}, "");
|
|
@@ -1,82 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _getValidationMessageFromPath = require("./getValidationMessageFromPath");
|
|
29
|
-
Object.keys(_getValidationMessageFromPath).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _getValidationMessageFromPath[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _getValidationMessageFromPath[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _isOnlyRequestedDataResolvingPropertyExists = require("./isOnlyRequestedDataResolvingPropertyExists");
|
|
40
|
-
Object.keys(_isOnlyRequestedDataResolvingPropertyExists).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _isOnlyRequestedDataResolvingPropertyExists[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _isOnlyRequestedDataResolvingPropertyExists[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _resolveConfigFile = require("./resolveConfigFile");
|
|
51
|
-
Object.keys(_resolveConfigFile).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _resolveConfigFile[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _resolveConfigFile[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _resolveConfigFilePath = require("./resolveConfigFilePath");
|
|
62
|
-
Object.keys(_resolveConfigFilePath).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _resolveConfigFilePath[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _resolveConfigFilePath[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
var _resolveExportsFromSourceCode = require("./resolveExportsFromSourceCode");
|
|
73
|
-
Object.keys(_resolveExportsFromSourceCode).forEach(function (key) {
|
|
74
|
-
if (key === "default" || key === "__esModule") return;
|
|
75
|
-
if (key in exports && exports[key] === _resolveExportsFromSourceCode[key]) return;
|
|
76
|
-
Object.defineProperty(exports, key, {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _resolveExportsFromSourceCode[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
5
|
+
_export_star(require("./createTemplate"), exports);
|
|
6
|
+
_export_star(require("./getMostSpecificPathFromError"), exports);
|
|
7
|
+
_export_star(require("./getValidationMessageFromPath"), exports);
|
|
8
|
+
_export_star(require("./isOnlyRequestedDataResolvingPropertyExists"), exports);
|
|
9
|
+
_export_star(require("./resolveConfigFile"), exports);
|
|
10
|
+
_export_star(require("./resolveConfigFilePath"), exports);
|
|
11
|
+
_export_star(require("./resolveExportsFromSourceCode"), exports);
|
|
12
|
+
function _export_star(from, to) {
|
|
13
|
+
Object.keys(from).forEach(function(k) {
|
|
14
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
15
|
+
Object.defineProperty(to, k, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return from[k];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return from;
|
|
24
|
+
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Object.defineProperty(exports, "isOnlyRequestedDataResolvingPropertyExists", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return isOnlyRequestedDataResolvingPropertyExists;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const DATA_RESOLVING_PROPERTIES = [
|
|
12
|
+
"data",
|
|
13
|
+
"file",
|
|
14
|
+
"queue"
|
|
15
|
+
];
|
|
16
|
+
const isOnlyRequestedDataResolvingPropertyExists = (object, requestedDataResolvingProperty)=>DATA_RESOLVING_PROPERTIES.every((dataResolvingProperty)=>dataResolvingProperty === requestedDataResolvingProperty ? dataResolvingProperty in object : !(dataResolvingProperty in object));
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
Object.defineProperty(exports, "resolveConfigFile", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return resolveConfigFile;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _helpers = require("../../src/utils/helpers");
|
|
12
|
+
const _resolveExportsFromSourceCode = require("./resolveExportsFromSourceCode");
|
|
13
|
+
const resolveConfigFile = (configSourceCode)=>{
|
|
14
|
+
if (!configSourceCode) {
|
|
15
|
+
throw new Error("Cannot handle source code of mock-server.config.(ts|js)");
|
|
16
|
+
}
|
|
17
|
+
const mockServerConfigExports = (0, _resolveExportsFromSourceCode.resolveExportsFromSourceCode)(configSourceCode);
|
|
18
|
+
const mockServerConfig = mockServerConfigExports.default;
|
|
19
|
+
if (!mockServerConfig) {
|
|
20
|
+
throw new Error("Cannot handle exports of mock-server.config.(ts|js)");
|
|
21
|
+
}
|
|
22
|
+
if (!(0, _helpers.isPlainObject)(mockServerConfig)) {
|
|
23
|
+
throw new Error("configuration should be plain object; see our doc (https://www.npmjs.com/package/mock-config-server) for more information");
|
|
24
|
+
}
|
|
25
|
+
return mockServerConfig;
|
|
22
26
|
};
|
|
23
|
-
exports.resolveConfigFile = resolveConfigFile;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
Object.defineProperty(exports, "resolveConfigFilePath", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return resolveConfigFilePath;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const resolveConfigFilePath = (cliConfigFilePath)=>{
|
|
19
|
+
const appPath = process.cwd();
|
|
20
|
+
if (cliConfigFilePath) return _path.default.resolve(appPath, cliConfigFilePath);
|
|
21
|
+
const configFileNameRegex = /mock-server.config.(?:ts|mts|cts|js|mjs|cjs)/;
|
|
22
|
+
return _fs.default.readdirSync(appPath).find((fileName)=>configFileNameRegex.test(fileName));
|
|
15
23
|
};
|
|
16
|
-
exports.resolveConfigFilePath = resolveConfigFilePath;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Object.defineProperty(exports, "resolveExportsFromSourceCode", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return resolveExportsFromSourceCode;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const resolveExportsFromSourceCode = (sourceCode)=>{
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const moduleInstance = new module.constructor();
|
|
14
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
15
|
+
moduleInstance._compile(sourceCode, "");
|
|
16
|
+
return moduleInstance.exports;
|
|
13
17
|
};
|
|
14
|
-
exports.resolveExportsFromSourceCode = resolveExportsFromSourceCode;
|