@whook/gcp-functions 13.0.0 → 13.1.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.
Files changed (38) hide show
  1. package/README.md +43 -28
  2. package/dist/commands/testHTTPFunction.d.ts +1 -1
  3. package/dist/commands/testHTTPFunction.js +2 -2
  4. package/dist/commands/testHTTPFunction.js.map +1 -1
  5. package/dist/index.d.ts +27 -0
  6. package/dist/index.js +33 -65
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.test.js +10 -0
  9. package/dist/index.test.js.map +1 -0
  10. package/dist/libs/utils.d.ts +3 -2
  11. package/dist/libs/utils.js +2 -2
  12. package/dist/libs/utils.js.map +1 -1
  13. package/dist/services/HANDLER.d.ts +12 -0
  14. package/dist/services/HANDLER.js +21 -0
  15. package/dist/services/HANDLER.js.map +1 -0
  16. package/dist/services/_autoload.d.ts +27 -13
  17. package/dist/services/_autoload.js +74 -26
  18. package/dist/services/_autoload.js.map +1 -1
  19. package/dist/services/log.js +2 -2
  20. package/dist/services/log.js.map +1 -1
  21. package/dist/wrappers/wrapHandlerForGoogleHTTPFunction.d.ts +26 -0
  22. package/dist/wrappers/{googleHTTPFunction.js → wrapHandlerForGoogleHTTPFunction.js} +70 -62
  23. package/dist/wrappers/wrapHandlerForGoogleHTTPFunction.js.map +1 -0
  24. package/package.json +10 -9
  25. package/src/commands/testHTTPFunction.ts +3 -4
  26. package/src/index.test.ts +11 -0
  27. package/src/index.ts +43 -97
  28. package/src/libs/utils.ts +3 -2
  29. package/src/services/HANDLER.ts +41 -0
  30. package/src/services/_autoload.ts +131 -36
  31. package/src/services/log.ts +2 -2
  32. package/src/wrappers/{googleHTTPFunction.ts → wrapHandlerForGoogleHTTPFunction.ts} +134 -122
  33. package/dist/services/log.test.js +0 -8
  34. package/dist/services/log.test.js.map +0 -1
  35. package/dist/wrappers/googleHTTPFunction.d.ts +0 -22
  36. package/dist/wrappers/googleHTTPFunction.js.map +0 -1
  37. package/src/services/log.test.ts +0 -8
  38. /package/dist/{services/log.test.d.ts → index.test.d.ts} +0 -0
package/src/index.ts CHANGED
@@ -1,18 +1,15 @@
1
- /* eslint global-require:0 */
2
1
  import fs from 'fs';
3
2
  import util from 'util';
4
3
  import path from 'path';
5
4
  import { mkdirp } from 'mkdirp';
5
+ import { argv, exit, stderr } from 'node:process';
6
6
  import cpr from 'cpr';
7
7
  import { printStackTrace, YError } from 'yerror';
8
- import { createRequire } from 'module';
8
+ import { Knifecycle, constant, initInitializerBuilder } from 'knifecycle';
9
9
  import {
10
- Knifecycle,
11
- SPECIAL_PROPS,
12
- constant,
13
- initInitializerBuilder,
14
- } from 'knifecycle';
15
- import { initCompiler } from '@whook/whook';
10
+ DEFAULT_BUILD_INITIALIZER_PATH_MAP as BASE_DEFAULT_BUILD_INITIALIZER_PATH_MAP,
11
+ initCompiler,
12
+ } from '@whook/whook';
16
13
  import initBuildAutoloader from './services/_autoload.js';
17
14
  import {
18
15
  dereferenceOpenAPIOperations,
@@ -35,6 +32,10 @@ import type { LogService } from 'common-services';
35
32
  import type { CprOptions } from 'cpr';
36
33
 
37
34
  export const DEFAULT_BUILD_PARALLELISM = 10;
35
+ export const DEFAULT_BUILD_INITIALIZER_PATH_MAP = {
36
+ ...BASE_DEFAULT_BUILD_INITIALIZER_PATH_MAP,
37
+ log: '@whook/gcp-functions/dist/services/log',
38
+ };
38
39
 
39
40
  export type WhookGCPBuildConfig = {
40
41
  BUILD_PARALLELISM?: number;
@@ -62,40 +63,11 @@ const cprAsync = util.promisify(cpr) as (
62
63
  options: CprOptions,
63
64
  ) => Promise<string[]>;
64
65
 
65
- // TODO: Use import.meta when Jest will support it
66
- const require = createRequire(path.join(process.cwd(), 'src', 'index.ts'));
67
-
68
- const BUILD_DEFINITIONS: Record<
69
- NonNullable<WhookAPIOperationGCPFunctionConfig['type']>,
70
- {
71
- type: string;
72
- wrapper: { name: string; path: string };
73
- suffix?: string;
74
- }
75
- > = {
76
- http: {
77
- type: 'HTTP',
78
- wrapper: {
79
- name: 'wrapHandlerForGoogleHTTPFunction',
80
- path: path.join(
81
- path.dirname(require.resolve('@whook/gcp-functions')),
82
- 'wrappers/googleHTTPFunction.js',
83
- ),
84
- },
85
- suffix: 'Wrapped',
86
- },
87
- };
88
-
89
66
  export async function prepareBuildEnvironment<T extends Knifecycle>(
90
67
  $: T = new Knifecycle() as T,
91
68
  ): Promise<T> {
92
69
  $.register(
93
- constant('INITIALIZER_PATH_MAP', {
94
- ENV: '@whook/whook/dist/services/ProxyedENV',
95
- log: '@whook/gcp-functions/dist/services/log',
96
- time: 'common-services/dist/time',
97
- delay: 'common-services/dist/delay',
98
- }),
70
+ constant('INITIALIZER_PATH_MAP', DEFAULT_BUILD_INITIALIZER_PATH_MAP),
99
71
  );
100
72
  $.register(initInitializerBuilder);
101
73
  $.register(initBuildAutoloader);
@@ -110,10 +82,10 @@ export async function runBuild(
110
82
  aPrepareBuildEnvironment: typeof prepareBuildEnvironment,
111
83
  ): Promise<void> {
112
84
  try {
113
- const handlerName = process.argv[2];
85
+ const handlerName = argv[2];
114
86
  const $ = await aPrepareBuildEnvironment();
115
87
  const {
116
- NODE_ENV,
88
+ APP_ENV,
117
89
  BUILD_PARALLELISM,
118
90
  PROJECT_DIR,
119
91
  compiler,
@@ -122,7 +94,7 @@ export async function runBuild(
122
94
  API,
123
95
  buildInitializer,
124
96
  }: WhookGCPBuildConfig & {
125
- NODE_ENV: string;
97
+ APP_ENV: string;
126
98
  PROJECT_DIR: string;
127
99
  compiler: WhookCompilerService;
128
100
  log: LogService;
@@ -130,7 +102,7 @@ export async function runBuild(
130
102
  API: OpenAPIV3.Document;
131
103
  buildInitializer: BuildInitializer;
132
104
  } = await $.run([
133
- 'NODE_ENV',
105
+ 'APP_ENV',
134
106
  '?BUILD_PARALLELISM',
135
107
  'PROJECT_DIR',
136
108
  'process',
@@ -161,10 +133,11 @@ export async function runBuild(
161
133
  return true;
162
134
  });
163
135
 
164
- log('warning', `${operations.length} operations to process.`);
136
+ log('warning', `📃 - ${operations.length} operations to process.`);
137
+
165
138
  await processOperations(
166
139
  {
167
- NODE_ENV,
140
+ APP_ENV,
168
141
  BUILD_PARALLELISM: BUILD_PARALLELISM || DEFAULT_BUILD_PARALLELISM,
169
142
  PROJECT_DIR,
170
143
  compiler,
@@ -176,19 +149,16 @@ export async function runBuild(
176
149
  );
177
150
  await $.destroy();
178
151
  } catch (err) {
179
- // eslint-disable-next-line
180
- console.error(
181
- '💀 - Cannot launch the build:',
182
- printStackTrace(err as Error),
183
- JSON.stringify((err as YError)?.params, null, 2),
152
+ stderr.write(
153
+ `💀 - Cannot launch the build:' ${printStackTrace(err as Error)}`,
184
154
  );
185
- process.exit(1);
155
+ exit(1);
186
156
  }
187
157
  }
188
158
 
189
159
  async function processOperations(
190
160
  {
191
- NODE_ENV,
161
+ APP_ENV,
192
162
  BUILD_PARALLELISM,
193
163
  PROJECT_DIR,
194
164
  compiler,
@@ -196,7 +166,7 @@ async function processOperations(
196
166
  $autoload,
197
167
  buildInitializer,
198
168
  }: WhookGCPBuildConfig & {
199
- NODE_ENV: string;
169
+ APP_ENV: string;
200
170
  PROJECT_DIR: string;
201
171
  compiler: WhookCompilerService;
202
172
  log: LogService;
@@ -211,11 +181,10 @@ async function processOperations(
211
181
  operations.slice(0, BUILD_PARALLELISM).map((operation) =>
212
182
  buildAnyLambda(
213
183
  {
214
- NODE_ENV,
184
+ APP_ENV,
215
185
  PROJECT_DIR,
216
186
  compiler,
217
187
  log,
218
- $autoload,
219
188
  buildInitializer,
220
189
  },
221
190
  operation,
@@ -224,10 +193,10 @@ async function processOperations(
224
193
  );
225
194
 
226
195
  if (operationsLeft.length) {
227
- log('info', operationsLeft.length, ' operations left.');
196
+ log('info', `📃 - ${operationsLeft.length} operations left.`);
228
197
  return processOperations(
229
198
  {
230
- NODE_ENV,
199
+ APP_ENV,
231
200
  BUILD_PARALLELISM,
232
201
  PROJECT_DIR,
233
202
  compiler,
@@ -238,23 +207,21 @@ async function processOperations(
238
207
  operationsLeft,
239
208
  );
240
209
  }
241
- log('info', 'No more operations.');
210
+ log('info', '🤷 - No more operations.');
242
211
  }
243
212
 
244
213
  async function buildAnyLambda(
245
214
  {
246
- NODE_ENV,
215
+ APP_ENV,
247
216
  PROJECT_DIR,
248
217
  compiler,
249
218
  log,
250
- $autoload,
251
219
  buildInitializer,
252
220
  }: {
253
- NODE_ENV: string;
221
+ APP_ENV: string;
254
222
  PROJECT_DIR: string;
255
223
  compiler: WhookCompilerService;
256
224
  log: LogService;
257
- $autoload: Autoloader<Initializer<Dependencies, Service>>;
258
225
  buildInitializer: BuildInitializer;
259
226
  },
260
227
  operation: WhookOperation<WhookAPIOperationGCPFunctionConfig>,
@@ -267,36 +234,25 @@ async function buildAnyLambda(
267
234
  ] || { type: 'http' };
268
235
  const operationType = whookConfig.type || 'http';
269
236
  const sourceOperationId = whookConfig.sourceOperationId;
270
- const entryPoint = operationId;
271
237
  const finalEntryPoint =
272
238
  (sourceOperationId ? sourceOperationId : operationId) +
273
239
  ((operation['x-whook'] || {}).suffix || '');
274
- log('warning', `Building ${operationType} "${finalEntryPoint}"...`);
275
- const buildDefinition = BUILD_DEFINITIONS[operationType];
276
- // eslint-disable-next-line
277
- const applyWrapper = (await import(buildDefinition.wrapper.path)).default;
278
- const rootNode = await $autoload(
279
- entryPoint + (buildDefinition.suffix || ''),
280
- );
240
+
241
+ log('warning', `🏗 - Building ${operationType} "${finalEntryPoint}"...`);
242
+
281
243
  const lambdaPath = path.join(
282
244
  PROJECT_DIR,
283
245
  'builds',
284
- NODE_ENV,
246
+ APP_ENV,
285
247
  finalEntryPoint,
286
248
  );
287
- const finalHandlerInitializer = applyWrapper(rootNode.initializer);
288
249
 
289
- const initializerContent = await buildInitializer(
290
- finalHandlerInitializer[SPECIAL_PROPS.INJECT].map((name) =>
291
- name === 'OPERATION_API'
292
- ? `OPERATION_API>OPERATION_API_${finalEntryPoint}`
293
- : name,
294
- ),
250
+ const initializerContent = await buildInitializer([
251
+ `OPERATION_HANDLER_${finalEntryPoint}`,
252
+ ]);
253
+ const indexContent = await buildLambdaIndex(
254
+ `OPERATION_HANDLER_${finalEntryPoint}`,
295
255
  );
296
- const indexContent = await buildLambdaIndex(rootNode, {
297
- name: buildDefinition.wrapper.name,
298
- path: buildDefinition.wrapper.path,
299
- });
300
256
 
301
257
  await mkdirp(lambdaPath);
302
258
  await Promise.all([
@@ -316,29 +272,19 @@ async function buildAnyLambda(
316
272
  } catch (err) {
317
273
  log('error', `Error building "${operationId}"...`);
318
274
  log('error-stack', printStackTrace(err as Error));
319
- log('debug', JSON.stringify((err as YError).params, null, 2));
320
275
  throw YError.wrap(err as Error, 'E_LAMBDA_BUILD', operationId);
321
276
  }
322
277
  }
323
278
 
324
- async function buildLambdaIndex(
325
- rootNode: { path: string },
326
- buildWrapper: { name: string; path: string },
327
- ): Promise<string> {
328
- return `import initHandler from '${rootNode.path}';
329
- import ${buildWrapper.name} from '${buildWrapper.path}';
279
+ async function buildLambdaIndex(name: string): Promise<string> {
280
+ return `// Automatically generated by \`@whook/gcp-functions\`
330
281
  import { initialize } from './initialize.js';
331
282
 
332
- const handlerInitializer = ${buildWrapper.name}(
333
- initHandler
334
- );
335
-
336
- const handlerPromise = initialize()
337
- .then(handlerInitializer);
283
+ const initializationPromise = initialize();
338
284
 
339
- export default function handler (req, res) {
340
- return handlerPromise
341
- .then(handler => handler(req, res));
285
+ export default function handler (req, res) {
286
+ return initializationPromise
287
+ .then(services => services['${name}'](req, res));
342
288
  };
343
289
  `;
344
290
  }
package/src/libs/utils.ts CHANGED
@@ -5,12 +5,13 @@ import type { LogService } from 'common-services';
5
5
  export async function loadFunction(
6
6
  {
7
7
  PROJECT_DIR,
8
+ APP_ENV,
8
9
  log,
9
10
  }: {
10
11
  PROJECT_DIR: string;
12
+ APP_ENV: string;
11
13
  log: LogService;
12
14
  },
13
- target: string,
14
15
  operationId: string,
15
16
  type: string,
16
17
  extension = '.mjs',
@@ -19,7 +20,7 @@ export async function loadFunction(
19
20
  const modulePath = path.join(
20
21
  PROJECT_DIR,
21
22
  'builds',
22
- target,
23
+ APP_ENV,
23
24
  operationId,
24
25
  type + extension,
25
26
  );
@@ -0,0 +1,41 @@
1
+ import { autoService, name } from 'knifecycle';
2
+ import { noop, applyWrappers } from '@whook/whook';
3
+ import type { WhookWrapper } from '@whook/whook';
4
+ import type { WhookHandler } from '@whook/http-transaction';
5
+ import type { LogService } from 'common-services';
6
+
7
+ export type WhookHandlerDependencies<T extends WhookHandler> = {
8
+ WRAPPERS: WhookWrapper<T>[];
9
+ mainWrapper: WhookWrapper<T>;
10
+ baseHandler: T;
11
+ log?: LogService;
12
+ };
13
+
14
+ export default name('HANDLER', autoService(initHandler));
15
+
16
+ /**
17
+ * Initialize one Whook handler
18
+ * @param {Object} services
19
+ * The services `$autoload` depends on
20
+ * @param {Array} services.WRAPPERS
21
+ * An optional list of wrappers to inject
22
+ * @param {Object} [services.log=noop]
23
+ * An optional logging service
24
+ * @param {Object} services.HANDLERS
25
+ * The rest is a hash of handlers mapped by their operation id
26
+ * @return {Promise<Function>}
27
+ * A promise of the `HANDLERS` hash.
28
+ */
29
+ async function initHandler<T extends WhookHandler>({
30
+ WRAPPERS,
31
+ mainWrapper,
32
+ baseHandler,
33
+ log = noop,
34
+ }: WhookHandlerDependencies<T>): Promise<WhookHandler<T>> {
35
+ log(
36
+ 'warning',
37
+ `🏭 - Initializing the HANDLER service with wrapped by ${WRAPPERS.length} wrappers.`,
38
+ );
39
+
40
+ return await applyWrappers<T>([...WRAPPERS, mainWrapper], baseHandler);
41
+ }
@@ -1,7 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';
2
3
  import {
3
- Knifecycle,
4
4
  SPECIAL_PROPS,
5
+ UNBUILDABLE_SERVICES,
6
+ Knifecycle,
5
7
  wrapInitializer,
6
8
  constant,
7
9
  alsoInject,
@@ -11,6 +13,8 @@ import {
11
13
  dereferenceOpenAPIOperations,
12
14
  getOpenAPIOperations,
13
15
  } from '@whook/http-router';
16
+ import initHandler from './HANDLER.js';
17
+ import initWrapHandlerForGoogleHTTPFunction from '../wrappers/wrapHandlerForGoogleHTTPFunction.js';
14
18
  import type {
15
19
  Injector,
16
20
  Autoloader,
@@ -21,10 +25,31 @@ import type {
21
25
  } from 'knifecycle';
22
26
  import type { WhookBuildConstantsService } from '@whook/whook';
23
27
  import type { WhookRawOperation } from '@whook/http-router';
24
- import type { LogService } from 'common-services';
28
+ import type { LogService, ResolveService } from 'common-services';
25
29
  import type { OpenAPIV3 } from 'openapi-types';
26
30
  import type { WhookAPIOperationGCPFunctionConfig } from '../index.js';
27
31
 
32
+ export type WhookGoogleFunctionsAutoloadDependencies = {
33
+ BUILD_CONSTANTS?: WhookBuildConstantsService;
34
+ $injector: Injector<Service>;
35
+ $instance: Knifecycle;
36
+ resolve: ResolveService;
37
+ log?: LogService;
38
+ };
39
+
40
+ export const GCP_WRAPPERS: Record<
41
+ Required<WhookAPIOperationGCPFunctionConfig>['type'],
42
+ {
43
+ name: string;
44
+ initializer: Initializer<Service, Dependencies>;
45
+ }
46
+ > = {
47
+ http: {
48
+ name: 'wrapHandlerForGoogleHTTPFunction',
49
+ initializer: initWrapHandlerForGoogleHTTPFunction as any,
50
+ },
51
+ };
52
+
28
53
  const initializerWrapper: ServiceInitializerWrapper<
29
54
  Autoloader<Initializer<Dependencies, Service>>,
30
55
  Dependencies
@@ -33,13 +58,9 @@ const initializerWrapper: ServiceInitializerWrapper<
33
58
  BUILD_CONSTANTS = {},
34
59
  $injector,
35
60
  $instance,
61
+ resolve,
36
62
  log = noop,
37
- }: {
38
- BUILD_CONSTANTS?: WhookBuildConstantsService;
39
- $injector: Injector<Service>;
40
- $instance: Knifecycle;
41
- log: LogService;
42
- },
63
+ }: WhookGoogleFunctionsAutoloadDependencies,
43
64
  $autoload: Autoloader<Initializer<Dependencies, Service>>,
44
65
  ): Promise<
45
66
  (serviceName: string) => Promise<{
@@ -49,7 +70,15 @@ const initializerWrapper: ServiceInitializerWrapper<
49
70
  > => {
50
71
  let API: OpenAPIV3.Document;
51
72
  let OPERATION_APIS: WhookRawOperation<WhookAPIOperationGCPFunctionConfig>[];
52
- const getAPIOperation = (() => {
73
+ const getAPIOperation: (
74
+ serviceName: string,
75
+ ) => Promise<
76
+ [
77
+ Required<WhookAPIOperationGCPFunctionConfig>['type'],
78
+ string,
79
+ OpenAPIV3.Document,
80
+ ]
81
+ > = (() => {
53
82
  return async (serviceName) => {
54
83
  // eslint-disable-next-line
55
84
  API = API || (await $injector(['API'])).API;
@@ -74,7 +103,7 @@ const initializerWrapper: ServiceInitializerWrapper<
74
103
  }
75
104
 
76
105
  // eslint-disable-next-line
77
- const OPERATION_API = cleanupOpenAPI({
106
+ const OPERATION_API: OpenAPIV3.Document = cleanupOpenAPI({
78
107
  ...API,
79
108
  paths: {
80
109
  [OPERATION.path]: {
@@ -83,33 +112,58 @@ const initializerWrapper: ServiceInitializerWrapper<
83
112
  },
84
113
  });
85
114
 
86
- return {
87
- ...OPERATION_API,
88
- paths: {
89
- [OPERATION.path]: {
90
- [OPERATION.method]: (
91
- await dereferenceOpenAPIOperations(OPERATION_API, [
92
- {
93
- path: OPERATION.path,
94
- method: OPERATION.method,
95
- ...OPERATION_API.paths[OPERATION.path]?.[OPERATION.method],
96
- parameters: OPERATION.parameters,
97
- },
98
- ])
99
- )[0],
115
+ return [
116
+ OPERATION['x-whook']?.type || 'http',
117
+ OPERATION.operationId as string,
118
+ {
119
+ ...OPERATION_API,
120
+ paths: {
121
+ [OPERATION.path]: {
122
+ [OPERATION.method]: (
123
+ await dereferenceOpenAPIOperations(OPERATION_API, [
124
+ {
125
+ path: OPERATION.path,
126
+ method: OPERATION.method,
127
+ ...OPERATION_API.paths[OPERATION.path]?.[OPERATION.method],
128
+ parameters: OPERATION.parameters,
129
+ },
130
+ ])
131
+ )[0],
132
+ },
100
133
  },
101
134
  },
102
- };
135
+ ];
103
136
  };
104
137
  })();
105
138
 
106
139
  log('debug', '🤖 - Initializing the `$autoload` build wrapper.');
107
140
 
108
141
  return async (serviceName) => {
142
+ if (UNBUILDABLE_SERVICES.includes(serviceName)) {
143
+ log(
144
+ 'warning',
145
+ `🤷 - Building a project with the "${serviceName}" unbuildable service (ie Knifecycle ones: ${UNBUILDABLE_SERVICES.join(
146
+ ', ',
147
+ )}) can give unpredictable results!`,
148
+ );
149
+ return {
150
+ initializer: constant(serviceName, undefined),
151
+ path: `constant://${serviceName}`,
152
+ };
153
+ }
154
+
109
155
  try {
110
- // TODO: add initializer map to knifecycle public API
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- const initializer = ($instance as any)._initializers.get(serviceName);
156
+ let initializer;
157
+
158
+ try {
159
+ initializer = $instance._getInitializer(serviceName);
160
+ } catch (err) {
161
+ log(
162
+ 'debug',
163
+ `🤖 - Direct initializer access failure from the Knifecycle instance: "${serviceName}".`,
164
+ );
165
+ log('debug-stack', printStackTrace(err as Error));
166
+ }
113
167
 
114
168
  if (initializer && initializer[SPECIAL_PROPS.TYPE] === 'constant') {
115
169
  log(
@@ -123,7 +177,7 @@ const initializerWrapper: ServiceInitializerWrapper<
123
177
  }
124
178
 
125
179
  if (serviceName.startsWith('OPERATION_API_')) {
126
- const OPERATION_API = await getAPIOperation(serviceName);
180
+ const [, , OPERATION_API] = await getAPIOperation(serviceName);
127
181
 
128
182
  return {
129
183
  initializer: constant(serviceName, OPERATION_API),
@@ -131,6 +185,45 @@ const initializerWrapper: ServiceInitializerWrapper<
131
185
  };
132
186
  }
133
187
 
188
+ if (serviceName.startsWith('OPERATION_WRAPPER_')) {
189
+ const [type] = await getAPIOperation(serviceName);
190
+
191
+ return {
192
+ initializer: alsoInject(
193
+ [
194
+ `OPERATION_API>${serviceName.replace(
195
+ 'OPERATION_WRAPPER_',
196
+ 'OPERATION_API_',
197
+ )}`,
198
+ ],
199
+ GCP_WRAPPERS[type].initializer as any,
200
+ ) as any,
201
+ path: resolve(
202
+ `@whook/gcp-functions/dist/wrappers/${GCP_WRAPPERS[type].name}`,
203
+ ),
204
+ };
205
+ }
206
+
207
+ if (serviceName.startsWith('OPERATION_HANDLER_')) {
208
+ const [, operationId] = await getAPIOperation(serviceName);
209
+
210
+ return {
211
+ name: serviceName,
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ initializer: alsoInject(
214
+ [
215
+ `mainWrapper>OPERATION_WRAPPER_${serviceName.replace(
216
+ 'OPERATION_HANDLER_',
217
+ '',
218
+ )}`,
219
+ `baseHandler>${operationId}`,
220
+ ],
221
+ initHandler,
222
+ ) as any,
223
+ path: resolve('@whook/gcp-functions/dist/services/HANDLER'),
224
+ };
225
+ }
226
+
134
227
  if (BUILD_CONSTANTS[serviceName]) {
135
228
  return {
136
229
  initializer: constant(serviceName, BUILD_CONSTANTS[serviceName]),
@@ -140,7 +233,7 @@ const initializerWrapper: ServiceInitializerWrapper<
140
233
 
141
234
  return $autoload(serviceName);
142
235
  } catch (err) {
143
- log('error', `Build error while loading "${serviceName}".`);
236
+ log('error', `💥 - Build error while loading "${serviceName}".`);
144
237
  log('error-stack', printStackTrace(err as Error));
145
238
  throw err;
146
239
  }
@@ -149,14 +242,16 @@ const initializerWrapper: ServiceInitializerWrapper<
149
242
  }) as any;
150
243
 
151
244
  /**
152
- * Wrap the _autoload service in order to build AWS
153
- * Lambda compatible code.
245
+ * Wrap the _autoload service in order to build for GCP
246
+ * Functions compatible code.
154
247
  * @param {Object} services
155
248
  * The services ENV depends on
156
- * @param {Object} services.NODE_ENV
157
- * The injected NODE_ENV value to add it to the build env
158
- * @param {Object} [services.PROXYED_ENV_VARS={}]
159
- * A list of environment variable names to proxy
249
+ * @param {Object} [services.BUILD_CONSTANTS]
250
+ * Service whose contents should be considered as constants
251
+ * @param {Object} $instance
252
+ * A Knifecycle instance
253
+ * @param {Object} $injector
254
+ * The Knifecycle injector
160
255
  * @param {Object} [services.log=noop]
161
256
  * An optional logging service
162
257
  * @return {Promise<Object>}
@@ -1,4 +1,4 @@
1
1
  import { service } from 'knifecycle';
2
+ import { log } from 'node:console';
2
3
 
3
- // eslint-disable-next-line
4
- export default service(async () => console.log.bind(console), 'log');
4
+ export default service(async () => log, 'log');