@whook/gcp-functions 18.1.0 → 19.0.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 +16 -54
- package/dist/commands/testGCPFunctionRoute.d.ts +50 -0
- package/dist/commands/{testHTTPFunction.js → testGCPFunctionRoute.js} +43 -44
- package/dist/commands/testGCPFunctionRoute.js.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +49 -52
- package/dist/index.js.map +1 -1
- package/dist/services/_autoload.d.ts +14 -9
- package/dist/services/_autoload.js +49 -62
- package/dist/services/_autoload.js.map +1 -1
- package/dist/wrappers/wrapRouteHandlerForGoogleHTTPFunction.d.ts +19 -0
- package/dist/wrappers/wrapRouteHandlerForGoogleHTTPFunction.js +307 -0
- package/dist/wrappers/wrapRouteHandlerForGoogleHTTPFunction.js.map +1 -0
- package/package.json +10 -8
- package/src/commands/{testHTTPFunction.ts → testGCPFunctionRoute.ts} +68 -69
- package/src/index.ts +85 -87
- package/src/services/_autoload.ts +79 -106
- package/src/types.d.ts +8 -0
- package/src/wrappers/wrapRouteHandlerForGoogleHTTPFunction.ts +571 -0
- package/dist/commands/testHTTPFunction.d.ts +0 -13
- package/dist/commands/testHTTPFunction.js.map +0 -1
- package/dist/services/HANDLER.d.ts +0 -10
- package/dist/services/HANDLER.js +0 -21
- package/dist/services/HANDLER.js.map +0 -1
- package/dist/services/log.d.ts +0 -5
- package/dist/services/log.js +0 -4
- package/dist/services/log.js.map +0 -1
- package/dist/wrappers/wrapHandlerForGoogleHTTPFunction.d.ts +0 -21
- package/dist/wrappers/wrapHandlerForGoogleHTTPFunction.js +0 -270
- package/dist/wrappers/wrapHandlerForGoogleHTTPFunction.js.map +0 -1
- package/src/services/HANDLER.ts +0 -47
- package/src/services/log.ts +0 -7
- package/src/wrappers/wrapHandlerForGoogleHTTPFunction.ts +0 -480
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import {
|
|
3
|
-
UNBUILDABLE_SERVICES,
|
|
4
3
|
Knifecycle,
|
|
5
4
|
wrapInitializer,
|
|
6
5
|
constant,
|
|
@@ -16,18 +15,24 @@ import {
|
|
|
16
15
|
import { YError } from 'yerror';
|
|
17
16
|
import {
|
|
18
17
|
initBuildAutoload,
|
|
18
|
+
initMainHandler,
|
|
19
19
|
noop,
|
|
20
|
-
|
|
21
|
-
dereferenceOpenAPIOperations,
|
|
22
|
-
getOpenAPIOperations,
|
|
20
|
+
type WhookOpenAPI,
|
|
23
21
|
type WhookBuildConstantsService,
|
|
24
|
-
type
|
|
22
|
+
type WhookDefinitions,
|
|
23
|
+
type WhookRouteDefinition,
|
|
24
|
+
type WhookRoutesDefinitionsService,
|
|
25
25
|
} from '@whook/whook';
|
|
26
26
|
import { type LogService } from 'common-services';
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
import { cleanupOpenAPI } from 'ya-open-api-types';
|
|
28
|
+
import initWrapRouteHandlerForGoogleHTTPFunction from '../wrappers/wrapRouteHandlerForGoogleHTTPFunction.js';
|
|
29
|
+
|
|
30
|
+
export type GCPFunctionDefinition = {
|
|
31
|
+
name: string;
|
|
32
|
+
type: 'route';
|
|
33
|
+
definition: WhookRouteDefinition;
|
|
34
|
+
openAPI: WhookOpenAPI;
|
|
35
|
+
};
|
|
31
36
|
|
|
32
37
|
export type WhookGoogleFunctionsAutoloadDependencies = {
|
|
33
38
|
BUILD_CONSTANTS?: WhookBuildConstantsService;
|
|
@@ -36,19 +41,6 @@ export type WhookGoogleFunctionsAutoloadDependencies = {
|
|
|
36
41
|
log?: LogService;
|
|
37
42
|
};
|
|
38
43
|
|
|
39
|
-
export const GCP_WRAPPERS: Record<
|
|
40
|
-
Required<WhookAPIOperationGCPFunctionConfig>['type'],
|
|
41
|
-
{
|
|
42
|
-
name: string;
|
|
43
|
-
initializer: Initializer<Service, Dependencies>;
|
|
44
|
-
}
|
|
45
|
-
> = {
|
|
46
|
-
http: {
|
|
47
|
-
name: 'wrapHandlerForGoogleHTTPFunction',
|
|
48
|
-
initializer: initWrapHandlerForGoogleHTTPFunction as any,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
44
|
const initializerWrapper: ServiceInitializerWrapper<
|
|
53
45
|
Autoloader<Initializer<Dependencies, Service>>,
|
|
54
46
|
Dependencies
|
|
@@ -58,125 +50,106 @@ const initializerWrapper: ServiceInitializerWrapper<
|
|
|
58
50
|
): Promise<
|
|
59
51
|
(serviceName: string) => Promise<Initializer<Dependencies, Service>>
|
|
60
52
|
> => {
|
|
61
|
-
let API:
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Required<WhookAPIOperationGCPFunctionConfig>['type'],
|
|
68
|
-
string,
|
|
69
|
-
OpenAPIV3_1.Document,
|
|
70
|
-
]
|
|
71
|
-
> = (() => {
|
|
72
|
-
return async (serviceName) => {
|
|
73
|
-
const cleanedName = serviceName.split('_').pop();
|
|
53
|
+
let API: WhookOpenAPI;
|
|
54
|
+
let DEFINITIONS: WhookDefinitions;
|
|
55
|
+
let ROUTES_DEFINITIONS: WhookRoutesDefinitionsService;
|
|
56
|
+
const getDefinition = (() => {
|
|
57
|
+
return async (serviceName: string): Promise<GCPFunctionDefinition> => {
|
|
58
|
+
const cleanedName = serviceName.split('_').pop() as string;
|
|
74
59
|
|
|
75
60
|
API = API || (await $injector(['API'])).API;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(((operation['x-whook'] || {}).sourceOperationId &&
|
|
84
|
-
(operation['x-whook'] || {}).sourceOperationId) ||
|
|
85
|
-
operation.operationId) +
|
|
86
|
-
((operation['x-whook'] || {}).suffix || ''),
|
|
87
|
-
);
|
|
61
|
+
DEFINITIONS =
|
|
62
|
+
DEFINITIONS || (await $injector(['DEFINITIONS'])).DEFINITIONS;
|
|
63
|
+
ROUTES_DEFINITIONS =
|
|
64
|
+
ROUTES_DEFINITIONS ||
|
|
65
|
+
(await $injector(['ROUTES_DEFINITIONS'])).ROUTES_DEFINITIONS;
|
|
66
|
+
|
|
67
|
+
const config = DEFINITIONS.configs[cleanedName as string];
|
|
88
68
|
|
|
89
|
-
if (!
|
|
90
|
-
log('error', '💥 - Unable to find a
|
|
91
|
-
throw new YError('
|
|
69
|
+
if (!config) {
|
|
70
|
+
log('error', '💥 - Unable to find a GCP Function definition!');
|
|
71
|
+
throw new YError('E_DEFINITION_NOT_FOUND', serviceName, cleanedName);
|
|
92
72
|
}
|
|
93
73
|
|
|
94
|
-
|
|
74
|
+
if (!config || config.type !== 'route') {
|
|
75
|
+
log('error', '💥 - GCP Function only supports routes!');
|
|
76
|
+
throw new YError('E_UNSUPPORTED_DEFINITION', serviceName, cleanedName);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const openAPI = (await cleanupOpenAPI({
|
|
95
80
|
...API,
|
|
96
81
|
paths: {
|
|
97
|
-
[
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return [
|
|
104
|
-
OPERATION['x-whook']?.type || 'http',
|
|
105
|
-
OPERATION.operationId as string,
|
|
106
|
-
{
|
|
107
|
-
...OPERATION_API,
|
|
108
|
-
paths: {
|
|
109
|
-
[OPERATION.path]: {
|
|
110
|
-
[OPERATION.method]: (
|
|
111
|
-
await dereferenceOpenAPIOperations(OPERATION_API, [
|
|
112
|
-
{
|
|
113
|
-
path: OPERATION.path,
|
|
114
|
-
method: OPERATION.method,
|
|
115
|
-
...OPERATION_API.paths?.[OPERATION.path]?.[
|
|
116
|
-
OPERATION.method
|
|
117
|
-
],
|
|
118
|
-
parameters: OPERATION.parameters,
|
|
119
|
-
},
|
|
120
|
-
])
|
|
121
|
-
)[0],
|
|
122
|
-
},
|
|
82
|
+
[config.path]: {
|
|
83
|
+
parameters: API?.paths?.[config.path]?.parameters || [],
|
|
84
|
+
[config.method]: API.paths?.[config.path]?.[config.method],
|
|
123
85
|
},
|
|
124
86
|
},
|
|
125
|
-
|
|
87
|
+
})) as WhookOpenAPI;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
name: cleanedName,
|
|
91
|
+
type: 'route',
|
|
92
|
+
openAPI,
|
|
93
|
+
definition:
|
|
94
|
+
ROUTES_DEFINITIONS[cleanedName]?.module?.definition || config,
|
|
95
|
+
};
|
|
126
96
|
};
|
|
127
97
|
})();
|
|
128
98
|
|
|
129
|
-
log(
|
|
99
|
+
log(
|
|
100
|
+
'debug',
|
|
101
|
+
'🤖 - Initializing the GCP Functions `$autoload` build wrapper.',
|
|
102
|
+
);
|
|
130
103
|
|
|
131
104
|
return async (serviceName) => {
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
105
|
+
if (serviceName.startsWith('MAIN_API_')) {
|
|
106
|
+
const definition = await getDefinition(serviceName);
|
|
107
|
+
|
|
108
|
+
return constant(
|
|
109
|
+
serviceName,
|
|
110
|
+
definition.type === 'route' ? definition.openAPI : {},
|
|
138
111
|
);
|
|
139
|
-
return constant(serviceName, undefined);
|
|
140
112
|
}
|
|
141
113
|
|
|
142
|
-
if (serviceName.startsWith('
|
|
143
|
-
const
|
|
114
|
+
if (serviceName.startsWith('MAIN_DEFINITION_')) {
|
|
115
|
+
const { definition } = await getDefinition(serviceName);
|
|
144
116
|
|
|
145
|
-
return constant(serviceName,
|
|
117
|
+
return constant(serviceName, definition);
|
|
146
118
|
}
|
|
147
119
|
|
|
148
|
-
if (serviceName.startsWith('
|
|
149
|
-
const [type] = await getAPIOperation(serviceName);
|
|
150
|
-
|
|
120
|
+
if (serviceName.startsWith('MAIN_WRAPPER_')) {
|
|
151
121
|
return location(
|
|
152
122
|
alsoInject(
|
|
153
123
|
[
|
|
154
|
-
`
|
|
155
|
-
'
|
|
156
|
-
'
|
|
124
|
+
`MAIN_DEFINITION>${serviceName.replace(
|
|
125
|
+
'MAIN_WRAPPER_',
|
|
126
|
+
'MAIN_DEFINITION_',
|
|
157
127
|
)}`,
|
|
128
|
+
`MAIN_API>${serviceName.replace('MAIN_WRAPPER_', 'MAIN_API_')}`,
|
|
158
129
|
],
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
`@whook/gcp-functions/dist/wrappers
|
|
130
|
+
initWrapRouteHandlerForGoogleHTTPFunction as any,
|
|
131
|
+
) as any,
|
|
132
|
+
`@whook/gcp-functions/dist/wrappers/wrapRouteHandlerForGoogleHTTPFunction.js`,
|
|
162
133
|
) as any;
|
|
163
134
|
}
|
|
164
135
|
|
|
165
|
-
if (serviceName.startsWith('
|
|
166
|
-
const
|
|
136
|
+
if (serviceName.startsWith('MAIN_HANDLER_')) {
|
|
137
|
+
const { type, name, definition } = await getDefinition(serviceName);
|
|
138
|
+
const targetHandler = definition.config?.targetHandler || name;
|
|
167
139
|
|
|
168
140
|
return location(
|
|
169
141
|
alsoInject(
|
|
170
142
|
[
|
|
171
|
-
`
|
|
172
|
-
'
|
|
143
|
+
`MAIN_WRAPPER>MAIN_WRAPPER_${serviceName.replace(
|
|
144
|
+
'MAIN_HANDLER_',
|
|
173
145
|
'',
|
|
174
146
|
)}`,
|
|
175
|
-
|
|
147
|
+
`?WRAPPERS>${type.toUpperCase()}S_WRAPPERS`,
|
|
148
|
+
`BASE_HANDLER>${targetHandler}`,
|
|
176
149
|
],
|
|
177
|
-
|
|
178
|
-
),
|
|
179
|
-
'@whook/
|
|
150
|
+
initMainHandler,
|
|
151
|
+
) as any,
|
|
152
|
+
'@whook/whook/dist/services/MAIN_HANDLER.js',
|
|
180
153
|
);
|
|
181
154
|
}
|
|
182
155
|
|
package/src/types.d.ts
ADDED