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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { BaseRestRequestConfig, Data, RestEntitiesByEntityName, RestFileResponse, RestMethod, RestParams, RestRequestConfig, RestSettings } from '../../../utils/types';
|
|
2
|
+
interface RestRequestInput {
|
|
3
|
+
body?: unknown;
|
|
4
|
+
params?: unknown;
|
|
5
|
+
query?: unknown;
|
|
6
|
+
response?: Data;
|
|
7
|
+
}
|
|
8
|
+
type ReservedRestConfigKeys = {
|
|
9
|
+
[K in 'file' | 'handler' | 'match' | 'queue' | 'response']?: never;
|
|
10
|
+
};
|
|
11
|
+
type RestInlineResponse<Response> = Response extends Record<string, unknown> ? Response & ReservedRestConfigKeys : Response;
|
|
12
|
+
type RestFunction<Method extends RestMethod, Options extends RestRequestInput, AdditionalParams = {}> = (params: RestParams<Method, Options['query'], Options['body'], Options['params'], Options['response']> & AdditionalParams) => Options['response'] | Promise<Options['response']>;
|
|
13
|
+
interface RestResponseObject<Method extends RestMethod, Response> {
|
|
14
|
+
match?: RestEntitiesByEntityName<Method>;
|
|
15
|
+
response: Response;
|
|
16
|
+
}
|
|
17
|
+
interface RestHandlerObject<Method extends RestMethod, Options extends RestRequestInput> {
|
|
18
|
+
handler: RestFunction<Method, Options>;
|
|
19
|
+
match?: RestEntitiesByEntityName<Method>;
|
|
20
|
+
}
|
|
21
|
+
interface RestFileObject<Method extends RestMethod> {
|
|
22
|
+
file: RestFileResponse;
|
|
23
|
+
match?: RestEntitiesByEntityName<Method>;
|
|
24
|
+
}
|
|
25
|
+
interface RestQueueObject<Method extends RestMethod, Options extends RestRequestInput> {
|
|
26
|
+
match?: RestEntitiesByEntityName<Method>;
|
|
27
|
+
queue: Array<{
|
|
28
|
+
file: RestFileResponse;
|
|
29
|
+
time?: number;
|
|
30
|
+
} | {
|
|
31
|
+
handler: RestFunction<Method, Options>;
|
|
32
|
+
time?: number;
|
|
33
|
+
} | {
|
|
34
|
+
response: Options['response'];
|
|
35
|
+
time?: number;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
interface RestSseClient<Response extends string> {
|
|
39
|
+
close: () => void;
|
|
40
|
+
send: (data: Response, meta?: {
|
|
41
|
+
event?: string;
|
|
42
|
+
id?: string;
|
|
43
|
+
retry?: number;
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
export declare const rest: {
|
|
47
|
+
delete: {
|
|
48
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"delete", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
49
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"delete">, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
50
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"delete", Options>, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
51
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"delete", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
52
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"delete", Options>, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
53
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"delete">;
|
|
54
|
+
};
|
|
55
|
+
get: {
|
|
56
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"get", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
57
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"get">, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
58
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"get", Options>, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
59
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"get", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
60
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"get", Options>, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
61
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"get">;
|
|
62
|
+
};
|
|
63
|
+
options: {
|
|
64
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"options", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
65
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"options">, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
66
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"options", Options>, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
67
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"options", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
68
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"options", Options>, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
69
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"options">;
|
|
70
|
+
};
|
|
71
|
+
patch: {
|
|
72
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"patch", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
73
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"patch">, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
74
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"patch", Options>, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
75
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"patch", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
76
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"patch", Options>, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
77
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"patch">;
|
|
78
|
+
};
|
|
79
|
+
post: {
|
|
80
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"post", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
81
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"post">, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
82
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"post", Options>, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
83
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"post", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
84
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"post", Options>, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
85
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"post">;
|
|
86
|
+
};
|
|
87
|
+
put: {
|
|
88
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestResponseObject<"put", Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
89
|
+
(path: RestRequestConfig["path"], config: RestFileObject<"put">, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
90
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestHandlerObject<"put", Options>, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
91
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestFunction<"put", Options, {}>, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
92
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestQueueObject<"put", Options>, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
93
|
+
<Options extends RestRequestInput = Partial<RestRequestInput>>(path: RestRequestConfig["path"], config: RestInlineResponse<Options["response"]>, settings?: RestSettings): BaseRestRequestConfig<"put">;
|
|
94
|
+
};
|
|
95
|
+
sse: <Options extends RestRequestInput = Partial<RestRequestInput>, Response extends string = string>(path: RestRequestConfig["path"], config: RestFunction<"get", Options, {
|
|
96
|
+
client: RestSseClient<Response>;
|
|
97
|
+
}>, settings?: RestSettings) => BaseRestRequestConfig<"get">;
|
|
98
|
+
stream: <Options extends RestRequestInput = Partial<RestRequestInput>, Response extends string = string>(path: RestRequestConfig["path"], config: RestFunction<"post", Options, {
|
|
99
|
+
client: RestSseClient<Response>;
|
|
100
|
+
}>, settings?: RestSettings) => BaseRestRequestConfig<"post">;
|
|
101
|
+
};
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "rest", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return rest;
|
|
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 ('file' in config) return {
|
|
26
|
+
type: 'file',
|
|
27
|
+
config
|
|
28
|
+
};
|
|
29
|
+
if ('response' in config) return {
|
|
30
|
+
type: 'data',
|
|
31
|
+
config
|
|
32
|
+
};
|
|
33
|
+
if ('handler' in config) return {
|
|
34
|
+
type: 'handler',
|
|
35
|
+
config
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
type: 'inlineResponse',
|
|
39
|
+
config
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const createConfigResolver = (config, settings = {})=>{
|
|
43
|
+
const resolvedConfig = resolveConfigType(config);
|
|
44
|
+
switch(resolvedConfig.type){
|
|
45
|
+
case 'inlineResponse':
|
|
46
|
+
return {
|
|
47
|
+
data: resolvedConfig.config,
|
|
48
|
+
settings
|
|
49
|
+
};
|
|
50
|
+
case 'data':
|
|
51
|
+
{
|
|
52
|
+
return {
|
|
53
|
+
data: resolvedConfig.config.response,
|
|
54
|
+
entities: resolvedConfig.config.match,
|
|
55
|
+
settings
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
case 'file':
|
|
59
|
+
{
|
|
60
|
+
return {
|
|
61
|
+
data: (0, _helpers.createFileHandler)(resolvedConfig.config.file),
|
|
62
|
+
entities: resolvedConfig.config.match,
|
|
63
|
+
settings
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
case 'queue':
|
|
67
|
+
{
|
|
68
|
+
const normalizedQueue = resolvedConfig.config.queue.map((item)=>{
|
|
69
|
+
if ('handler' in item) {
|
|
70
|
+
return {
|
|
71
|
+
data: item.handler,
|
|
72
|
+
time: item.time
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if ('response' in item) {
|
|
76
|
+
return {
|
|
77
|
+
data: item.response,
|
|
78
|
+
time: item.time
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if ('file' in item) {
|
|
82
|
+
return {
|
|
83
|
+
data: (0, _helpers.createFileHandler)(item.file),
|
|
84
|
+
time: item.time
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Unexpected queue item kind: ${JSON.stringify(item, null, 2)}`);
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
data: (0, _helpers.createQueueHandler)(normalizedQueue),
|
|
91
|
+
entities: resolvedConfig.config.match,
|
|
92
|
+
settings
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
case 'inlineHandler':
|
|
96
|
+
return {
|
|
97
|
+
data: resolvedConfig.config,
|
|
98
|
+
settings
|
|
99
|
+
};
|
|
100
|
+
case 'handler':
|
|
101
|
+
{
|
|
102
|
+
return {
|
|
103
|
+
data: resolvedConfig.config.handler,
|
|
104
|
+
entities: resolvedConfig.config.match,
|
|
105
|
+
settings
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
{
|
|
110
|
+
throw new Error(`Unexpected route config kind: ${JSON.stringify(config, null, 2)}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const createRestFactory = (method)=>{
|
|
115
|
+
function createRequestConfig(path, config, settings) {
|
|
116
|
+
return {
|
|
117
|
+
method,
|
|
118
|
+
path,
|
|
119
|
+
routes: [
|
|
120
|
+
createConfigResolver(config, settings)
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return createRequestConfig;
|
|
125
|
+
};
|
|
126
|
+
const createSseRestFactory = (method)=>{
|
|
127
|
+
function createSseRequestConfig(path, config, settings) {
|
|
128
|
+
const wrapperHandler = (params)=>{
|
|
129
|
+
params.setHeader('connection', 'keep-alive');
|
|
130
|
+
params.setHeader('content-type', 'text/event-stream');
|
|
131
|
+
params.setHeader('cache-control', 'no-cache');
|
|
132
|
+
const client = {
|
|
133
|
+
send (message, meta) {
|
|
134
|
+
const payload = (0, _helpers.formatSsePayload)(message, meta);
|
|
135
|
+
params.response.write(payload);
|
|
136
|
+
},
|
|
137
|
+
close () {
|
|
138
|
+
params.response.end();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return config({
|
|
142
|
+
...params,
|
|
143
|
+
client
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
method,
|
|
148
|
+
path,
|
|
149
|
+
routes: [
|
|
150
|
+
createConfigResolver(wrapperHandler, settings)
|
|
151
|
+
]
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return createSseRequestConfig;
|
|
155
|
+
};
|
|
156
|
+
const rest = {
|
|
157
|
+
delete: createRestFactory('delete'),
|
|
158
|
+
get: createRestFactory('get'),
|
|
159
|
+
options: createRestFactory('options'),
|
|
160
|
+
patch: createRestFactory('patch'),
|
|
161
|
+
post: createRestFactory('post'),
|
|
162
|
+
put: createRestFactory('put'),
|
|
163
|
+
sse: createSseRestFactory('get'),
|
|
164
|
+
stream: createSseRestFactory('post')
|
|
165
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
import type { GraphQLRequestArtifact } from '../../../utils/types';
|
|
3
|
+
interface CreateGraphQLRouteParams {
|
|
4
|
+
graphQLRequestArtifacts: GraphQLRequestArtifact[];
|
|
5
|
+
server: Express;
|
|
6
|
+
}
|
|
7
|
+
export declare const createGraphQLRoute: ({ server, graphQLRequestArtifacts }: CreateGraphQLRouteParams) => Express;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createGraphQLRoute", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createGraphQLRoute;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _flat = require("flat");
|
|
12
|
+
const _helpers = require("../../../utils/helpers");
|
|
13
|
+
const _helpers1 = require("./helpers");
|
|
14
|
+
const createGraphQLRoute = ({ server, graphQLRequestArtifacts })=>server.use((0, _helpers.asyncHandler)(async (request, response, next)=>{
|
|
15
|
+
var _matchedRouteConfig_config_settings, _matchedRouteConfig_config_settings1;
|
|
16
|
+
if (request.method !== 'GET' && request.method !== 'POST') return next();
|
|
17
|
+
const graphQLInput = (0, _helpers.getGraphQLInput)(request);
|
|
18
|
+
if (!graphQLInput.query) return next();
|
|
19
|
+
const query = (0, _helpers.parseQuery)(graphQLInput.query);
|
|
20
|
+
if (!query) return next();
|
|
21
|
+
const matchedRequestArtifacts = (0, _helpers1.matchGraphQLRequestArtifacts)({
|
|
22
|
+
artifacts: graphQLRequestArtifacts,
|
|
23
|
+
meta: {
|
|
24
|
+
path: (0, _helpers.normalizeUrl)(request.path),
|
|
25
|
+
query: graphQLInput.query,
|
|
26
|
+
operationType: query.operationType,
|
|
27
|
+
operationName: query.operationName
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
if (!matchedRequestArtifacts.length) return next();
|
|
31
|
+
const matchedRouteConfig = matchedRequestArtifacts.find(({ config })=>{
|
|
32
|
+
if (!config.entities) return true;
|
|
33
|
+
const entityEntries = Object.entries(config.entities);
|
|
34
|
+
return entityEntries.every(([entityName, entityDescriptorOrValue])=>{
|
|
35
|
+
const isEntityVariablesByTopLevelDescriptor = entityName === 'variables' && (0, _helpers.isEntityDescriptor)(entityDescriptorOrValue);
|
|
36
|
+
if (isEntityVariablesByTopLevelDescriptor) {
|
|
37
|
+
const variablesDescriptor = entityDescriptorOrValue;
|
|
38
|
+
if (variablesDescriptor.checkMode === 'exists' || variablesDescriptor.checkMode === 'notExists') {
|
|
39
|
+
return (0, _helpers.resolveEntityValues)({
|
|
40
|
+
actualValue: graphQLInput.variables,
|
|
41
|
+
checkMode: variablesDescriptor.checkMode
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var _variablesDescriptor_oneOf;
|
|
45
|
+
return (0, _helpers.resolveEntityValues)({
|
|
46
|
+
actualValue: graphQLInput.variables,
|
|
47
|
+
descriptorValue: variablesDescriptor.value,
|
|
48
|
+
checkMode: variablesDescriptor.checkMode,
|
|
49
|
+
oneOf: (_variablesDescriptor_oneOf = variablesDescriptor.oneOf) !== null && _variablesDescriptor_oneOf !== void 0 ? _variablesDescriptor_oneOf : false
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const actualEntity = (0, _flat.flatten)(entityName === 'variables' ? graphQLInput.variables : request[entityName]);
|
|
53
|
+
const entityValueEntries = Object.entries(entityDescriptorOrValue);
|
|
54
|
+
return entityValueEntries.every(([entityPropertyKey, entityPropertyDescriptorOrValue])=>{
|
|
55
|
+
const entityPropertyDescriptor = (0, _helpers.convertToEntityDescriptor)(entityPropertyDescriptorOrValue);
|
|
56
|
+
const actualPropertyKey = entityName === 'headers' ? entityPropertyKey.toLowerCase() : entityPropertyKey;
|
|
57
|
+
const actualPropertyValue = actualEntity[actualPropertyKey];
|
|
58
|
+
if (entityPropertyDescriptor.checkMode === 'exists' || entityPropertyDescriptor.checkMode === 'notExists') {
|
|
59
|
+
return (0, _helpers.resolveEntityValues)({
|
|
60
|
+
actualValue: actualPropertyValue,
|
|
61
|
+
checkMode: entityPropertyDescriptor.checkMode
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var _entityPropertyDescriptor_oneOf;
|
|
65
|
+
return (0, _helpers.resolveEntityValues)({
|
|
66
|
+
actualValue: actualPropertyValue,
|
|
67
|
+
descriptorValue: entityPropertyDescriptor.value,
|
|
68
|
+
checkMode: entityPropertyDescriptor.checkMode,
|
|
69
|
+
oneOf: (_entityPropertyDescriptor_oneOf = entityPropertyDescriptor.oneOf) !== null && _entityPropertyDescriptor_oneOf !== void 0 ? _entityPropertyDescriptor_oneOf : false
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
if (!matchedRouteConfig) return next();
|
|
75
|
+
if (matchedRouteConfig.componentRequestInterceptor) {
|
|
76
|
+
await (0, _helpers.callRequestInterceptor)({
|
|
77
|
+
request,
|
|
78
|
+
interceptor: matchedRouteConfig.componentRequestInterceptor
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (matchedRouteConfig.requestRequestInterceptor) {
|
|
82
|
+
await (0, _helpers.callRequestInterceptor)({
|
|
83
|
+
request,
|
|
84
|
+
interceptor: matchedRouteConfig.requestRequestInterceptor
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (matchedRouteConfig.routeRequestInterceptor) {
|
|
88
|
+
await (0, _helpers.callRequestInterceptor)({
|
|
89
|
+
request,
|
|
90
|
+
interceptor: matchedRouteConfig.routeRequestInterceptor
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
var _matchedRouteConfig_config_entities;
|
|
94
|
+
const params = {
|
|
95
|
+
request,
|
|
96
|
+
response,
|
|
97
|
+
next,
|
|
98
|
+
entities: (_matchedRouteConfig_config_entities = matchedRouteConfig.config.entities) !== null && _matchedRouteConfig_config_entities !== void 0 ? _matchedRouteConfig_config_entities : {},
|
|
99
|
+
appendHeader: (field, value)=>{
|
|
100
|
+
response.append(field, value);
|
|
101
|
+
},
|
|
102
|
+
attachment: (filename)=>{
|
|
103
|
+
response.attachment(filename);
|
|
104
|
+
},
|
|
105
|
+
clearCookie: (name, options)=>{
|
|
106
|
+
response.clearCookie(name, options);
|
|
107
|
+
},
|
|
108
|
+
getCookie: (name)=>request.cookies[name],
|
|
109
|
+
getRequestHeader: (field)=>request.headers[field],
|
|
110
|
+
getRequestHeaders: ()=>request.headers,
|
|
111
|
+
getResponseHeader: (field)=>response.getHeader(field),
|
|
112
|
+
getResponseHeaders: ()=>response.getHeaders(),
|
|
113
|
+
setCookie: (name, value, options)=>{
|
|
114
|
+
if (options) {
|
|
115
|
+
response.cookie(name, value, options);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
response.cookie(name, value);
|
|
119
|
+
},
|
|
120
|
+
setDelay: async (delay)=>{
|
|
121
|
+
await (0, _helpers.sleep)(delay === Infinity ? 99999999 : delay);
|
|
122
|
+
},
|
|
123
|
+
setHeader: (field, value)=>{
|
|
124
|
+
response.set(field, value);
|
|
125
|
+
},
|
|
126
|
+
setStatusCode: (statusCode)=>{
|
|
127
|
+
response.statusCode = statusCode;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const resolvedData = typeof matchedRouteConfig.config.data === 'function' ? await matchedRouteConfig.config.data(params) : matchedRouteConfig.config.data;
|
|
131
|
+
if (response.headersSent) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if ((_matchedRouteConfig_config_settings = matchedRouteConfig.config.settings) === null || _matchedRouteConfig_config_settings === void 0 ? void 0 : _matchedRouteConfig_config_settings.status) {
|
|
135
|
+
response.statusCode = matchedRouteConfig.config.settings.status;
|
|
136
|
+
}
|
|
137
|
+
if (matchedRouteConfig.operationType === 'query') {
|
|
138
|
+
response.set('Cache-control', 'no-cache');
|
|
139
|
+
}
|
|
140
|
+
const data = await (0, _helpers.callResponseInterceptors)({
|
|
141
|
+
data: resolvedData,
|
|
142
|
+
request,
|
|
143
|
+
response,
|
|
144
|
+
interceptors: {
|
|
145
|
+
routeInterceptor: matchedRouteConfig.routeResponseInterceptor,
|
|
146
|
+
componentInterceptor: matchedRouteConfig.componentResponseInterceptor,
|
|
147
|
+
requestInterceptor: matchedRouteConfig.requestResponseInterceptor,
|
|
148
|
+
serverInterceptor: matchedRouteConfig.serverResponseInterceptor
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
if ((_matchedRouteConfig_config_settings1 = matchedRouteConfig.config.settings) === null || _matchedRouteConfig_config_settings1 === void 0 ? void 0 : _matchedRouteConfig_config_settings1.delay) {
|
|
152
|
+
await (0, _helpers.sleep)(matchedRouteConfig.config.settings.delay);
|
|
153
|
+
}
|
|
154
|
+
if (response.headersSent) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
return response.json(data);
|
|
158
|
+
}));
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "calculateGraphQLRouteConfigWeight", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return calculateGraphQLRouteConfigWeight;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _helpers = require("../../../../../utils/helpers");
|
|
12
|
-
const
|
|
12
|
+
const calculateGraphQLRouteConfigWeight = (graphQLRouteConfig)=>{
|
|
13
13
|
const { entities } = graphQLRouteConfig;
|
|
14
14
|
if (!entities) return 0;
|
|
15
15
|
let routeConfigWeight = 0;
|
|
@@ -32,11 +32,3 @@ const calculateRouteConfigWeight = (graphQLRouteConfig)=>{
|
|
|
32
32
|
}
|
|
33
33
|
return routeConfigWeight;
|
|
34
34
|
};
|
|
35
|
-
const prepareGraphQLRequestConfigs = (requestConfigs)=>{
|
|
36
|
-
requestConfigs.forEach((requestConfig)=>{
|
|
37
|
-
requestConfig.routes.sort((first, second)=>// ✅ important:
|
|
38
|
-
// Lift more specific configs for correct working of routes
|
|
39
|
-
calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
|
|
40
|
-
});
|
|
41
|
-
return requestConfigs;
|
|
42
|
-
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./calculateGraphQLRouteConfigWeight/calculateGraphQLRouteConfigWeight"), exports);
|
|
6
|
+
_export_star(require("./matchGraphQLRequestArtifacts/matchGraphQLRequestArtifacts"), exports);
|
|
7
|
+
_export_star(require("./prepareGraphQLRequestArtifacts/prepareGraphQLRequestArtifacts"), 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,12 @@
|
|
|
1
|
+
import type { GraphQLRequestArtifact } from '../../../../../utils/types';
|
|
2
|
+
interface MatchGraphQLRequestArtifactsParams {
|
|
3
|
+
artifacts: GraphQLRequestArtifact[];
|
|
4
|
+
meta: {
|
|
5
|
+
path: string;
|
|
6
|
+
operationType: string;
|
|
7
|
+
query?: string;
|
|
8
|
+
operationName?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const matchGraphQLRequestArtifacts: ({ artifacts, meta }: MatchGraphQLRequestArtifactsParams) => GraphQLRequestArtifact[];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "matchGraphQLRequestArtifacts", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return matchGraphQLRequestArtifacts;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _graphql = require("graphql");
|
|
12
|
+
const _helpers = require("../../../../../utils/helpers");
|
|
13
|
+
const matchGraphQLRequestArtifacts = ({ artifacts, meta })=>artifacts.filter((artifact)=>{
|
|
14
|
+
if ((0, _helpers.normalizeUrl)(meta.path) !== (0, _helpers.normalizeUrl)(artifact.baseUrl)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (artifact.operationType !== meta.operationType) return false;
|
|
18
|
+
if (artifact.query) {
|
|
19
|
+
if (!meta.query) return false;
|
|
20
|
+
return (0, _graphql.stripIgnoredCharacters)((0, _graphql.print)((0, _graphql.parse)(artifact.query))) === (0, _graphql.stripIgnoredCharacters)((0, _graphql.print)((0, _graphql.parse)(meta.query)));
|
|
21
|
+
}
|
|
22
|
+
if (artifact.operationName) {
|
|
23
|
+
if (!meta.operationName) return false;
|
|
24
|
+
return artifact.operationName instanceof RegExp ? new RegExp(artifact.operationName).test(meta.operationName) : artifact.operationName === meta.operationName;
|
|
25
|
+
}
|
|
26
|
+
console.warn(`[mock-config] GraphQL artifact with no query or operationName was skipped: ${JSON.stringify(artifact)}`);
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "prepareGraphQLRequestArtifacts", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return prepareGraphQLRequestArtifacts;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const prepareGraphQLRequestArtifacts = (requestArtifacts)=>requestArtifacts.toSorted((first, second)=>second.weight - first.weight);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './createGraphQLRoute/createGraphQLRoute';
|
|
2
|
+
export * from './createGraphQLRoute/helpers';
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
_export_star(require("./
|
|
5
|
+
_export_star(require("./createGraphQLRoute/createGraphQLRoute"), exports);
|
|
6
|
+
_export_star(require("./createGraphQLRoute/helpers"), exports);
|
|
6
7
|
function _export_star(from, to) {
|
|
7
8
|
Object.keys(from).forEach(function(k) {
|
|
8
9
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { Express } from 'express';
|
|
2
|
-
import type { GraphQLEntity, GraphQLOperationName, GraphQLOperationType
|
|
2
|
+
import type { DatabaseConfig, GraphQLEntity, GraphQLOperationName, GraphQLOperationType } from '../../../utils/types';
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Express {
|
|
5
5
|
interface Request {
|
|
6
|
-
id: number;
|
|
7
|
-
timestamp: number;
|
|
8
6
|
graphQL: {
|
|
9
7
|
operationType: GraphQLOperationType;
|
|
10
8
|
operationName?: GraphQLOperationName;
|
|
11
9
|
query: string;
|
|
12
10
|
variables?: GraphQLEntity<'variables'>;
|
|
13
11
|
} | null;
|
|
12
|
+
id: number;
|
|
13
|
+
timestamp: number;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export declare const contextMiddleware: (server: Express, { database }:
|
|
17
|
+
export declare const contextMiddleware: (server: Express, { database }: {
|
|
18
|
+
database?: DatabaseConfig;
|
|
19
|
+
}) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
import type { RestRequestArtifact } from '../../../utils/types';
|
|
3
|
+
interface CreateRestRoutesParams {
|
|
4
|
+
restRequestArtifacts: RestRequestArtifact[];
|
|
5
|
+
server: Express;
|
|
6
|
+
}
|
|
7
|
+
export declare const createRestRoute: ({ server, restRequestArtifacts }: CreateRestRoutesParams) => Express;
|
|
8
|
+
export {};
|