mock-config-server 4.0.3 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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/js/full/mock-requests/graphql/index.js +2 -2
- package/dist/bin/templates/js/full/mock-requests/graphql/user.js +35 -35
- package/dist/bin/templates/js/full/mock-requests/graphql/users.js +12 -12
- package/dist/bin/templates/js/full/mock-requests/rest/index.js +2 -2
- package/dist/bin/templates/js/full/mock-requests/rest/user.js +35 -35
- package/dist/bin/templates/js/full/mock-requests/rest/users.js +12 -12
- package/dist/bin/templates/js/full/mock-server.config.js +19 -19
- package/dist/bin/templates/js/graphql/mock-requests/index.js +2 -2
- package/dist/bin/templates/js/graphql/mock-requests/user.js +35 -35
- package/dist/bin/templates/js/graphql/mock-requests/users.js +12 -12
- package/dist/bin/templates/js/graphql/mock-server.config.js +14 -14
- package/dist/bin/templates/js/rest/mock-requests/index.js +2 -2
- package/dist/bin/templates/js/rest/mock-requests/user.js +35 -35
- package/dist/bin/templates/js/rest/mock-requests/users.js +12 -12
- package/dist/bin/templates/js/rest/mock-server.config.js +14 -14
- 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 +21 -21
- 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 +16 -16
- 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 +16 -16
- 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 +102 -0
- package/dist/src/core/functions/rest/rest.js +165 -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 +6 -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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import { getUserRequest, getUsersRequest, postUserRequest } from './mock-requests';
|
|
4
|
-
|
|
5
|
-
const mockServerConfig:
|
|
6
|
-
{
|
|
7
|
-
port: 31299,
|
|
8
|
-
baseUrl: '/'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: 'rest',
|
|
12
|
-
configs: [getUserRequest, getUsersRequest, postUserRequest]
|
|
13
|
-
}
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
export default mockServerConfig;
|
|
1
|
+
import type { MockServerConfig } from 'mock-config-server';
|
|
2
|
+
|
|
3
|
+
import { getUserRequest, getUsersRequest, postUserRequest } from './mock-requests';
|
|
4
|
+
|
|
5
|
+
const mockServerConfig: MockServerConfig = [
|
|
6
|
+
{
|
|
7
|
+
port: 31299,
|
|
8
|
+
baseUrl: '/'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'rest',
|
|
12
|
+
configs: [getUserRequest, getUsersRequest, postUserRequest]
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default mockServerConfig;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createFileHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createFileHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _helpers = require("../../../../../utils/helpers");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const createFileHandler = (filePath)=>({ response, setHeader, next })=>{
|
|
20
|
+
if (!(0, _helpers.isFilePathValid)(filePath)) {
|
|
21
|
+
return next();
|
|
22
|
+
}
|
|
23
|
+
const buffer = _fs.default.readFileSync(_path.default.resolve(filePath));
|
|
24
|
+
const fileName = filePath.replaceAll('\\', '/').split('/').at(-1);
|
|
25
|
+
const fileExtension = fileName.split('.').at(-1);
|
|
26
|
+
response.type(fileExtension);
|
|
27
|
+
setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
|
|
28
|
+
return buffer;
|
|
29
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RestDataResponse, RestDataResponseFunction, RestMethod } from '../../../../../utils/types';
|
|
2
|
+
export declare const createQueueHandler: <Method extends RestMethod>(queue: {
|
|
3
|
+
data: RestDataResponse<Method>;
|
|
4
|
+
time?: number;
|
|
5
|
+
}[]) => RestDataResponseFunction<Method>;
|
|
@@ -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 = (queue)=>{
|
|
12
|
+
let queueIndex = 0;
|
|
13
|
+
let timeoutInProgress = false;
|
|
14
|
+
const updateQueueIndex = ()=>{
|
|
15
|
+
queueIndex = queue.length - 1 === queueIndex ? 0 : queueIndex + 1;
|
|
16
|
+
};
|
|
17
|
+
return async (params)=>{
|
|
18
|
+
if (!queue.length) {
|
|
19
|
+
return params.next();
|
|
20
|
+
}
|
|
21
|
+
const queueItem = queue[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,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "formatSsePayload", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return formatSsePayload;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _zod = /*#__PURE__*/ _interop_require_default(require("zod"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const sseMetaSchema = _zod.default.object({
|
|
18
|
+
event: _zod.default.string().optional(),
|
|
19
|
+
id: _zod.default.string().optional(),
|
|
20
|
+
retry: _zod.default.number().int().nonnegative().optional()
|
|
21
|
+
}).optional();
|
|
22
|
+
// ✅ important:
|
|
23
|
+
// SSE is a line-based protocol. `id` and `event` must be single-line values.
|
|
24
|
+
// Strip CR/LF so metadata cannot break frame structure.
|
|
25
|
+
const normalizeSseMetaValue = (value)=>value.replaceAll('\r', '').replaceAll('\n', '');
|
|
26
|
+
const formatSsePayload = (data, meta)=>{
|
|
27
|
+
const parseMetaResult = sseMetaSchema.safeParse(meta);
|
|
28
|
+
if (!parseMetaResult.success) {
|
|
29
|
+
var _parseMetaResult_error_issues_;
|
|
30
|
+
throw new Error(`Invalid SSE meta: ${(_parseMetaResult_error_issues_ = parseMetaResult.error.issues[0]) === null || _parseMetaResult_error_issues_ === void 0 ? void 0 : _parseMetaResult_error_issues_.message}`);
|
|
31
|
+
}
|
|
32
|
+
const parsedMeta = parseMetaResult.data;
|
|
33
|
+
const lines = [];
|
|
34
|
+
if (parsedMeta === null || parsedMeta === void 0 ? void 0 : parsedMeta.id) {
|
|
35
|
+
lines.push(`id: ${normalizeSseMetaValue(parsedMeta.id)}`);
|
|
36
|
+
}
|
|
37
|
+
if (parsedMeta === null || parsedMeta === void 0 ? void 0 : parsedMeta.event) {
|
|
38
|
+
lines.push(`event: ${normalizeSseMetaValue(parsedMeta.event)}`);
|
|
39
|
+
}
|
|
40
|
+
if ((parsedMeta === null || parsedMeta === void 0 ? void 0 : parsedMeta.retry) != null) {
|
|
41
|
+
lines.push(`retry: ${parsedMeta.retry}`);
|
|
42
|
+
}
|
|
43
|
+
// ✅ important:
|
|
44
|
+
// Multiline payloads are encoded as multiple `data:` lines.
|
|
45
|
+
// SSE clients concatenate consecutive `data:` lines with '\n' into one message.
|
|
46
|
+
data.split(/\r\n|\r|\n/).forEach((line)=>{
|
|
47
|
+
lines.push(`data: ${line}`);
|
|
48
|
+
});
|
|
49
|
+
return `${lines.join('\n')}\n\n`;
|
|
50
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./createFileHandler/createFileHandler"), exports);
|
|
6
|
+
_export_star(require("./createQueueHandler/createQueueHandler"), exports);
|
|
7
|
+
_export_star(require("./formatSsePayload/formatSsePayload"), 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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rest';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
_export_star(require("./
|
|
5
|
+
_export_star(require("./rest"), 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)) {
|