@whook/gcp-functions 9.0.0 → 10.0.1
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 +14 -11
- package/dist/commands/testHTTPFunction.d.ts +1 -1
- package/dist/commands/testHTTPFunction.js +119 -150
- package/dist/commands/testHTTPFunction.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +182 -269
- package/dist/index.js.map +1 -1
- package/dist/libs/utils.js +16 -35
- package/dist/libs/utils.js.map +1 -1
- package/dist/services/_autoload.d.ts +3 -3
- package/dist/services/_autoload.js +83 -109
- package/dist/services/_autoload.js.map +1 -1
- package/dist/services/log.js +2 -12
- package/dist/services/log.js.map +1 -1
- package/dist/services/log.test.js +4 -9
- package/dist/services/log.test.js.map +1 -1
- package/dist/wrappers/googleHTTPFunction.js +246 -294
- package/dist/wrappers/googleHTTPFunction.js.map +1 -1
- package/package.json +49 -90
- package/src/commands/testHTTPFunction.ts +6 -13
- package/src/index.ts +28 -48
- package/src/libs/utils.ts +3 -4
- package/src/services/_autoload.ts +4 -3
- package/src/services/log.test.ts +1 -1
- package/src/wrappers/googleHTTPFunction.ts +6 -6
- package/dist/commands/testHTTPFunction.mjs +0 -136
- package/dist/commands/testHTTPFunction.mjs.map +0 -1
- package/dist/index.mjs +0 -265
- package/dist/index.mjs.map +0 -1
- package/dist/libs/utils.mjs +0 -27
- package/dist/libs/utils.mjs.map +0 -1
- package/dist/services/_autoload.mjs +0 -113
- package/dist/services/_autoload.mjs.map +0 -1
- package/dist/services/log.mjs +0 -4
- package/dist/services/log.mjs.map +0 -1
- package/dist/services/log.test.mjs +0 -7
- package/dist/services/log.test.mjs.map +0 -1
- package/dist/wrappers/googleHTTPFunction.mjs +0 -290
- package/dist/wrappers/googleHTTPFunction.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { Injector, Autoloader, Initializer, Dependencies } from 'knifecycle';
|
|
3
3
|
import type { LogService } from 'common-services';
|
|
4
4
|
/**
|
|
@@ -15,7 +15,7 @@ import type { LogService } from 'common-services';
|
|
|
15
15
|
* @return {Promise<Object>}
|
|
16
16
|
* A promise of an object containing the reshaped env vars.
|
|
17
17
|
*/
|
|
18
|
-
declare const _default: import("knifecycle").ServiceInitializer<import("@whook/whook/dist/services/_autoload").AutoloadConfig & {
|
|
18
|
+
declare const _default: import("knifecycle").ServiceInitializer<import("@whook/whook/dist/services/_autoload.js").AutoloadConfig & {
|
|
19
19
|
PROJECT_SRC: string;
|
|
20
20
|
CONFIGS?: import("@whook/whook").CONFIGSService | undefined;
|
|
21
21
|
WRAPPERS?: import("@whook/whook").WhookWrapper<unknown, import("@whook/http-transaction").WhookHandler<import("knifecycle").Parameters<any>, import("@whook/http-transaction").WhookResponse<number, void | import("@whook/http-transaction").WhookHeaders, void | import("type-fest").JsonValue | import("stream").Readable>, import("@whook/http-transaction").WhookOperation<Record<string, unknown>>>>[] | undefined;
|
|
@@ -23,7 +23,7 @@ declare const _default: import("knifecycle").ServiceInitializer<import("@whook/w
|
|
|
23
23
|
importer: import("@whook/whook").ImporterService<{
|
|
24
24
|
default: Initializer<any, Dependencies<any>>;
|
|
25
25
|
}>;
|
|
26
|
-
resolve: import("@whook/whook
|
|
26
|
+
resolve: import("@whook/whook").ResolveService;
|
|
27
27
|
log?: LogService | undefined;
|
|
28
28
|
}, Autoloader<Initializer<unknown, Dependencies<any>>>>;
|
|
29
29
|
export default _default;
|
|
@@ -1,110 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';
|
|
2
|
+
import { SPECIAL_PROPS, wrapInitializer, constant, alsoInject, } from 'knifecycle';
|
|
3
|
+
import { YError } from 'yerror';
|
|
4
|
+
import { dereferenceOpenAPIOperations, getOpenAPIOperations, } from '@whook/http-router';
|
|
5
|
+
const initializerWrapper = (async ({ BUILD_CONSTANTS = {}, $injector, $instance, log = noop, }, $autoload) => {
|
|
6
|
+
let API;
|
|
7
|
+
let OPERATION_APIS;
|
|
8
|
+
const getAPIOperation = (() => {
|
|
9
|
+
return async (serviceName) => {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
API = API || (await $injector(['API'])).API;
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
OPERATION_APIS =
|
|
14
|
+
OPERATION_APIS ||
|
|
15
|
+
getOpenAPIOperations(API);
|
|
16
|
+
const OPERATION = OPERATION_APIS.find((operation) => serviceName ===
|
|
17
|
+
(((operation['x-whook'] || {}).sourceOperationId &&
|
|
18
|
+
'OPERATION_API_' +
|
|
19
|
+
(operation['x-whook'] || {}).sourceOperationId) ||
|
|
20
|
+
'OPERATION_API_' + operation.operationId) +
|
|
21
|
+
((operation['x-whook'] || {}).suffix || ''));
|
|
22
|
+
if (!OPERATION) {
|
|
23
|
+
log('error', '💥 - Unable to find a lambda operation definition!');
|
|
24
|
+
throw new YError('E_OPERATION_NOT_FOUND', serviceName);
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
const OPERATION_API = cleanupOpenAPI({
|
|
28
|
+
...API,
|
|
29
|
+
paths: {
|
|
30
|
+
[OPERATION.path]: {
|
|
31
|
+
[OPERATION.method]: API.paths[OPERATION.path]?.[OPERATION.method],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
...OPERATION_API,
|
|
37
|
+
paths: {
|
|
38
|
+
[OPERATION.path]: {
|
|
39
|
+
[OPERATION.method]: (await dereferenceOpenAPIOperations(OPERATION_API, [
|
|
40
|
+
{
|
|
41
|
+
path: OPERATION.path,
|
|
42
|
+
method: OPERATION.method,
|
|
43
|
+
...OPERATION_API.paths[OPERATION.path]?.[OPERATION.method],
|
|
44
|
+
parameters: OPERATION.parameters,
|
|
45
|
+
},
|
|
46
|
+
]))[0],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
log('debug', '🤖 - Initializing the `$autoload` build wrapper.');
|
|
53
|
+
return async (serviceName) => {
|
|
54
|
+
try {
|
|
55
|
+
// TODO: add initializer map to knifecycle public API
|
|
56
|
+
const initializer = $instance._initializers.get(serviceName);
|
|
57
|
+
if (initializer && initializer[SPECIAL_PROPS.TYPE] === 'constant') {
|
|
58
|
+
log('debug', `🤖 - Reusing a constant initializer directly from the Knifecycle instance: "${serviceName}".`);
|
|
59
|
+
return {
|
|
60
|
+
initializer,
|
|
61
|
+
path: `instance://${serviceName}`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (serviceName.startsWith('OPERATION_API_')) {
|
|
65
|
+
const OPERATION_API = await getAPIOperation(serviceName);
|
|
66
|
+
return {
|
|
67
|
+
initializer: constant(serviceName, OPERATION_API),
|
|
68
|
+
path: `api://${serviceName}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (BUILD_CONSTANTS[serviceName]) {
|
|
72
|
+
return {
|
|
73
|
+
initializer: constant(serviceName, BUILD_CONSTANTS[serviceName]),
|
|
74
|
+
path: `constant://${serviceName}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return $autoload(serviceName);
|
|
54
78
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
[OPERATION.method]: (await (0, _httpRouter.dereferenceOpenAPIOperations)(OPERATION_API, [_objectSpread(_objectSpread({
|
|
60
|
-
path: OPERATION.path,
|
|
61
|
-
method: OPERATION.method
|
|
62
|
-
}, (_OPERATION_API$paths$ = OPERATION_API.paths[OPERATION.path]) === null || _OPERATION_API$paths$ === void 0 ? void 0 : _OPERATION_API$paths$[OPERATION.method]), {}, {
|
|
63
|
-
parameters: OPERATION.parameters
|
|
64
|
-
})]))[0]
|
|
65
|
-
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
log('error', `Build error while loading "${serviceName}".`);
|
|
81
|
+
log('error-stack', err.stack || 'no_stack_trace');
|
|
82
|
+
throw err;
|
|
66
83
|
}
|
|
67
|
-
});
|
|
68
84
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
log('debug', '🤖 - Initializing the `$autoload` build wrapper.');
|
|
72
|
-
return async serviceName => {
|
|
73
|
-
try {
|
|
74
|
-
// TODO: add initializer map to knifecycle public API
|
|
75
|
-
const initializer = $instance._initializers.get(serviceName);
|
|
76
|
-
|
|
77
|
-
if (initializer && initializer[_knifecycle.SPECIAL_PROPS.TYPE] === 'constant') {
|
|
78
|
-
log('debug', `🤖 - Reusing a constant initializer directly from the Knifecycle instance: "${serviceName}".`);
|
|
79
|
-
return {
|
|
80
|
-
initializer,
|
|
81
|
-
path: `instance://${serviceName}`
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (serviceName.startsWith('OPERATION_API_')) {
|
|
86
|
-
const OPERATION_API = await getAPIOperation(serviceName);
|
|
87
|
-
return {
|
|
88
|
-
initializer: (0, _knifecycle.constant)(serviceName, OPERATION_API),
|
|
89
|
-
path: `api://${serviceName}`
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (BUILD_CONSTANTS[serviceName]) {
|
|
94
|
-
return {
|
|
95
|
-
initializer: (0, _knifecycle.constant)(serviceName, BUILD_CONSTANTS[serviceName]),
|
|
96
|
-
path: `constant://${serviceName}`
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return $autoload(serviceName);
|
|
101
|
-
} catch (err) {
|
|
102
|
-
log('error', `Build error while loading "${serviceName}".`);
|
|
103
|
-
log('error-stack', err.stack || 'no_stack_trace');
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
85
|
+
});
|
|
108
86
|
/**
|
|
109
87
|
* Wrap the _autoload service in order to build AWS
|
|
110
88
|
* Lambda compatible code.
|
|
@@ -119,9 +97,5 @@ const initializerWrapper = async ({
|
|
|
119
97
|
* @return {Promise<Object>}
|
|
120
98
|
* A promise of an object containing the reshaped env vars.
|
|
121
99
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var _default = (0, _knifecycle.alsoInject)(['?BUILD_CONSTANTS', '$instance', '$injector', '?log'], (0, _knifecycle.wrapInitializer)(initializerWrapper, _whook.initAutoload));
|
|
125
|
-
|
|
126
|
-
exports.default = _default;
|
|
100
|
+
export default alsoInject(['?BUILD_CONSTANTS', '$instance', '$injector', '?log'], wrapInitializer(initializerWrapper, initAutoload));
|
|
127
101
|
//# sourceMappingURL=_autoload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_autoload.js","
|
|
1
|
+
{"version":3,"file":"_autoload.js","sourceRoot":"","sources":["../../src/services/_autoload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EA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iBAClC,CAAC;aACH;YAED,IAAI,WAAW,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE;gBAC5C,MAAM,aAAa,GAAG,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC;gBAEzD,OAAO;oBACL,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;oBACjD,IAAI,EAAE,SAAS,WAAW,EAAE;iBAC7B,CAAC;aACH;YAED,IAAI,eAAe,CAAC,WAAW,CAAC,EAAE;gBAChC,OAAO;oBACL,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;oBAChE,IAAI,EAAE,cAAc,WAAW,EAAE;iBAClC,CAAC;aACH;YAED,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC;SAC/B;QAAC,OAAO,GAAG,EAAE;YACZ,GAAG,CAAC,OAAO,EAAE,8BAA8B,WAAW,IAAI,CAAC,CAAC;YAC5D,GAAG,CAAC,aAAa,EAAG,GAAa,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;YAC7D,MAAM,GAAG,CAAC;SACX;IACH,CAAC,CAAC;AACJ,CAAC,CAAQ,CAAC;AAEV;;;;;;;;;;;;;GAaG;AACH,eAAe,UAAU,CACvB,CAAC,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,EACtD,eAAe,CAAC,kBAAyB,EAAE,YAAY,CAAC,CACzD,CAAC"}
|
package/dist/services/log.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _knifecycle = require("knifecycle");
|
|
9
|
-
|
|
1
|
+
import { service } from 'knifecycle';
|
|
10
2
|
// eslint-disable-next-line
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.default = _default;
|
|
3
|
+
export default service(async () => console.log.bind(console), 'log');
|
|
14
4
|
//# sourceMappingURL=log.js.map
|
package/dist/services/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/services/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,2BAA2B;AAC3B,eAAe,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _log = _interopRequireDefault(require("./log"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
1
|
+
import initLogService from './log.js';
|
|
7
2
|
describe('initLogService', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
it('should work', async () => {
|
|
4
|
+
await initLogService({});
|
|
5
|
+
});
|
|
11
6
|
});
|
|
12
7
|
//# sourceMappingURL=log.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.test.js","
|
|
1
|
+
{"version":3,"file":"log.test.js","sourceRoot":"","sources":["../../src/services/log.test.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,UAAU,CAAC;AAEtC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|