@whook/gcp-functions 8.3.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/LICENSE +20 -0
- package/README.md +187 -0
- package/dist/commands/testHTTPFunction.d.ts +12 -0
- package/dist/commands/testHTTPFunction.js +156 -0
- package/dist/commands/testHTTPFunction.js.map +1 -0
- package/dist/commands/testHTTPFunction.mjs +136 -0
- package/dist/commands/testHTTPFunction.mjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +265 -0
- package/dist/index.mjs.map +1 -0
- package/dist/libs/utils.d.ts +5 -0
- package/dist/libs/utils.js +39 -0
- package/dist/libs/utils.js.map +1 -0
- package/dist/libs/utils.mjs +27 -0
- package/dist/libs/utils.mjs.map +1 -0
- package/dist/services/_autoload.d.ts +17 -0
- package/dist/services/_autoload.js +121 -0
- package/dist/services/_autoload.js.map +1 -0
- package/dist/services/_autoload.mjs +107 -0
- package/dist/services/_autoload.mjs.map +1 -0
- package/dist/services/log.d.ts +2 -0
- package/dist/services/log.js +14 -0
- package/dist/services/log.js.map +1 -0
- package/dist/services/log.mjs +4 -0
- package/dist/services/log.mjs.map +1 -0
- package/dist/services/log.test.d.ts +1 -0
- package/dist/services/log.test.js +12 -0
- package/dist/services/log.test.js.map +1 -0
- package/dist/services/log.test.mjs +7 -0
- package/dist/services/log.test.mjs.map +1 -0
- package/dist/wrappers/googleHTTPFunction.d.ts +22 -0
- package/dist/wrappers/googleHTTPFunction.js +310 -0
- package/dist/wrappers/googleHTTPFunction.js.map +1 -0
- package/dist/wrappers/googleHTTPFunction.mjs +289 -0
- package/dist/wrappers/googleHTTPFunction.mjs.map +1 -0
- package/package.json +215 -0
- package/src/commands/testHTTPFunction.ts +181 -0
- package/src/index.ts +443 -0
- package/src/libs/utils.ts +43 -0
- package/src/services/_autoload.ts +161 -0
- package/src/services/log.test.ts +7 -0
- package/src/services/log.ts +4 -0
- package/src/wrappers/googleHTTPFunction.ts +468 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadLambda = loadLambda;
|
|
7
|
+
|
|
8
|
+
var _yerror = _interopRequireDefault(require("yerror"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
async function loadLambda({
|
|
15
|
+
PROJECT_DIR,
|
|
16
|
+
log
|
|
17
|
+
}, target, operationId, type) {
|
|
18
|
+
const modulePath = _path.default.join(PROJECT_DIR, 'builds', target, operationId, type);
|
|
19
|
+
|
|
20
|
+
log('debug', `⛏️ - Loading lambda module at path "${modulePath}".`);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// eslint-disable-next-line
|
|
24
|
+
const module = require(modulePath);
|
|
25
|
+
|
|
26
|
+
if (!module) {
|
|
27
|
+
throw new _yerror.default('E_MODULE_NOT_FOUND', module);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!module.default) {
|
|
31
|
+
throw new _yerror.default('E_LAMBDA_NOT_FOUND', module, Object.keys(module));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return module.default;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
throw _yerror.default.wrap(err, 'E_LAMBDA_LOAD');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/libs/utils.ts"],"names":["loadLambda","PROJECT_DIR","log","target","operationId","type","modulePath","path","join","module","require","YError","default","Object","keys","err","wrap"],"mappings":";;;;;;;AAAA;;AACA;;;;AAGO,eAAeA,UAAf,CACL;AACEC,EAAAA,WADF;AAEEC,EAAAA;AAFF,CADK,EAQLC,MARK,EASLC,WATK,EAULC,IAVK,EAWS;AACd,QAAMC,UAAU,GAAGC,cAAKC,IAAL,CACjBP,WADiB,EAEjB,QAFiB,EAGjBE,MAHiB,EAIjBC,WAJiB,EAKjBC,IALiB,CAAnB;;AAQAH,EAAAA,GAAG,CAAC,OAAD,EAAW,uCAAsCI,UAAW,IAA5D,CAAH;;AAEA,MAAI;AACF;AACA,UAAMG,MAAM,GAAGC,OAAO,CAACJ,UAAD,CAAtB;;AAEA,QAAI,CAACG,MAAL,EAAa;AACX,YAAM,IAAIE,eAAJ,CAAW,oBAAX,EAAiCF,MAAjC,CAAN;AACD;;AAED,QAAI,CAACA,MAAM,CAACG,OAAZ,EAAqB;AACnB,YAAM,IAAID,eAAJ,CAAW,oBAAX,EAAiCF,MAAjC,EAAyCI,MAAM,CAACC,IAAP,CAAYL,MAAZ,CAAzC,CAAN;AACD;;AAED,WAAOA,MAAM,CAACG,OAAd;AACD,GAbD,CAaE,OAAOG,GAAP,EAAY;AACZ,UAAMJ,gBAAOK,IAAP,CAAYD,GAAZ,EAAiB,eAAjB,CAAN;AACD;AACF","sourcesContent":["import YError from 'yerror';\nimport path from 'path';\nimport type { LogService } from 'common-services';\n\nexport async function loadLambda(\n {\n PROJECT_DIR,\n log,\n }: {\n PROJECT_DIR: string;\n log: LogService;\n },\n target: string,\n operationId: string,\n type: string,\n): Promise<any> {\n const modulePath = path.join(\n PROJECT_DIR,\n 'builds',\n target,\n operationId,\n type,\n );\n\n log('debug', `⛏️ - Loading lambda module at path \"${modulePath}\".`);\n\n try {\n // eslint-disable-next-line\n const module = require(modulePath);\n\n if (!module) {\n throw new YError('E_MODULE_NOT_FOUND', module);\n }\n\n if (!module.default) {\n throw new YError('E_LAMBDA_NOT_FOUND', module, Object.keys(module));\n }\n\n return module.default;\n } catch (err) {\n throw YError.wrap(err, 'E_LAMBDA_LOAD');\n }\n}\n"],"file":"utils.js"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import YError from 'yerror';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export async function loadLambda({
|
|
4
|
+
PROJECT_DIR,
|
|
5
|
+
log
|
|
6
|
+
}, target, operationId, type) {
|
|
7
|
+
const modulePath = path.join(PROJECT_DIR, 'builds', target, operationId, type);
|
|
8
|
+
log('debug', `⛏️ - Loading lambda module at path "${modulePath}".`);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
const module = require(modulePath);
|
|
13
|
+
|
|
14
|
+
if (!module) {
|
|
15
|
+
throw new YError('E_MODULE_NOT_FOUND', module);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!module.default) {
|
|
19
|
+
throw new YError('E_LAMBDA_NOT_FOUND', module, Object.keys(module));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return module.default;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
throw YError.wrap(err, 'E_LAMBDA_LOAD');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/libs/utils.ts"],"names":["YError","path","loadLambda","PROJECT_DIR","log","target","operationId","type","modulePath","join","module","require","default","Object","keys","err","wrap"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,QAAnB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AAGA,OAAO,eAAeC,UAAf,CACL;AACEC,EAAAA,WADF;AAEEC,EAAAA;AAFF,CADK,EAQLC,MARK,EASLC,WATK,EAULC,IAVK,EAWS;AACd,QAAMC,UAAU,GAAGP,IAAI,CAACQ,IAAL,CACjBN,WADiB,EAEjB,QAFiB,EAGjBE,MAHiB,EAIjBC,WAJiB,EAKjBC,IALiB,CAAnB;AAQAH,EAAAA,GAAG,CAAC,OAAD,EAAW,uCAAsCI,UAAW,IAA5D,CAAH;;AAEA,MAAI;AACF;AACA,UAAME,MAAM,GAAGC,OAAO,CAACH,UAAD,CAAtB;;AAEA,QAAI,CAACE,MAAL,EAAa;AACX,YAAM,IAAIV,MAAJ,CAAW,oBAAX,EAAiCU,MAAjC,CAAN;AACD;;AAED,QAAI,CAACA,MAAM,CAACE,OAAZ,EAAqB;AACnB,YAAM,IAAIZ,MAAJ,CAAW,oBAAX,EAAiCU,MAAjC,EAAyCG,MAAM,CAACC,IAAP,CAAYJ,MAAZ,CAAzC,CAAN;AACD;;AAED,WAAOA,MAAM,CAACE,OAAd;AACD,GAbD,CAaE,OAAOG,GAAP,EAAY;AACZ,UAAMf,MAAM,CAACgB,IAAP,CAAYD,GAAZ,EAAiB,eAAjB,CAAN;AACD;AACF","sourcesContent":["import YError from 'yerror';\nimport path from 'path';\nimport type { LogService } from 'common-services';\n\nexport async function loadLambda(\n {\n PROJECT_DIR,\n log,\n }: {\n PROJECT_DIR: string;\n log: LogService;\n },\n target: string,\n operationId: string,\n type: string,\n): Promise<any> {\n const modulePath = path.join(\n PROJECT_DIR,\n 'builds',\n target,\n operationId,\n type,\n );\n\n log('debug', `⛏️ - Loading lambda module at path \"${modulePath}\".`);\n\n try {\n // eslint-disable-next-line\n const module = require(modulePath);\n\n if (!module) {\n throw new YError('E_MODULE_NOT_FOUND', module);\n }\n\n if (!module.default) {\n throw new YError('E_LAMBDA_NOT_FOUND', module, Object.keys(module));\n }\n\n return module.default;\n } catch (err) {\n throw YError.wrap(err, 'E_LAMBDA_LOAD');\n }\n}\n"],"file":"utils.mjs"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Autoloader } from 'knifecycle';
|
|
2
|
+
declare const _default: import("knifecycle").ServiceInitializer<unknown, Autoloader<any>>;
|
|
3
|
+
/**
|
|
4
|
+
* Wrap the _autoload service in order to build AWS
|
|
5
|
+
* Lambda compatible code.
|
|
6
|
+
* @param {Object} services
|
|
7
|
+
* The services ENV depends on
|
|
8
|
+
* @param {Object} services.NODE_ENV
|
|
9
|
+
* The injected NODE_ENV value to add it to the build env
|
|
10
|
+
* @param {Object} [services.PROXYED_ENV_VARS={}]
|
|
11
|
+
* A list of environment variable names to proxy
|
|
12
|
+
* @param {Object} [services.log=noop]
|
|
13
|
+
* An optional logging service
|
|
14
|
+
* @return {Promise<Object>}
|
|
15
|
+
* A promise of an object containing the reshaped env vars.
|
|
16
|
+
*/
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _whook = require("@whook/whook");
|
|
9
|
+
|
|
10
|
+
var _knifecycle = require("knifecycle");
|
|
11
|
+
|
|
12
|
+
var _yerror = _interopRequireDefault(require("yerror"));
|
|
13
|
+
|
|
14
|
+
var _httpRouter = require("@whook/http-router");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wrap the _autoload service in order to build AWS
|
|
26
|
+
* Lambda compatible code.
|
|
27
|
+
* @param {Object} services
|
|
28
|
+
* The services ENV depends on
|
|
29
|
+
* @param {Object} services.NODE_ENV
|
|
30
|
+
* The injected NODE_ENV value to add it to the build env
|
|
31
|
+
* @param {Object} [services.PROXYED_ENV_VARS={}]
|
|
32
|
+
* A list of environment variable names to proxy
|
|
33
|
+
* @param {Object} [services.log=noop]
|
|
34
|
+
* An optional logging service
|
|
35
|
+
* @return {Promise<Object>}
|
|
36
|
+
* A promise of an object containing the reshaped env vars.
|
|
37
|
+
*/
|
|
38
|
+
var _default = (0, _knifecycle.alsoInject)(['?BUILD_CONSTANTS', '$instance', '$injector', '?log'], (0, _knifecycle.wrapInitializer)(async ({
|
|
39
|
+
BUILD_CONSTANTS = {},
|
|
40
|
+
$injector,
|
|
41
|
+
$instance,
|
|
42
|
+
log = _whook.noop
|
|
43
|
+
}, $autoload) => {
|
|
44
|
+
let API;
|
|
45
|
+
let OPERATION_APIS;
|
|
46
|
+
|
|
47
|
+
const getAPIOperation = (() => {
|
|
48
|
+
return async serviceName => {
|
|
49
|
+
// eslint-disable-next-line
|
|
50
|
+
API = API || (await $injector(['API'])).API; // eslint-disable-next-line
|
|
51
|
+
|
|
52
|
+
OPERATION_APIS = OPERATION_APIS || (0, _httpRouter.getOpenAPIOperations)(API);
|
|
53
|
+
const OPERATION = OPERATION_APIS.find(operation => serviceName === ((operation['x-whook'] || {}).sourceOperationId && 'OPERATION_API_' + (operation['x-whook'] || {}).sourceOperationId || 'OPERATION_API_' + operation.operationId) + ((operation['x-whook'] || {}).suffix || ''));
|
|
54
|
+
|
|
55
|
+
if (!OPERATION) {
|
|
56
|
+
log('error', '💥 - Unable to find a lambda operation definition!');
|
|
57
|
+
throw new _yerror.default('E_OPERATION_NOT_FOUND', serviceName);
|
|
58
|
+
} // eslint-disable-next-line
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const OPERATION_API = (0, _whook.cleanupOpenAPI)(_objectSpread(_objectSpread({}, API), {}, {
|
|
62
|
+
paths: {
|
|
63
|
+
[OPERATION.path]: {
|
|
64
|
+
[OPERATION.method]: API.paths[OPERATION.path][OPERATION.method]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
return _objectSpread(_objectSpread({}, OPERATION_API), {}, {
|
|
69
|
+
paths: {
|
|
70
|
+
[OPERATION.path]: {
|
|
71
|
+
[OPERATION.method]: (await (0, _httpRouter.dereferenceOpenAPIOperations)(OPERATION_API, [_objectSpread(_objectSpread({
|
|
72
|
+
path: OPERATION.path,
|
|
73
|
+
method: OPERATION.method
|
|
74
|
+
}, OPERATION_API.paths[OPERATION.path][OPERATION.method]), {}, {
|
|
75
|
+
parameters: OPERATION.parameters
|
|
76
|
+
})]))[0]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
})();
|
|
82
|
+
|
|
83
|
+
log('debug', '🤖 - Initializing the `$autoload` build wrapper.');
|
|
84
|
+
return async serviceName => {
|
|
85
|
+
try {
|
|
86
|
+
// TODO: add initializer map to knifecycle public API
|
|
87
|
+
const initializer = $instance._initializers.get(serviceName);
|
|
88
|
+
|
|
89
|
+
if (initializer && initializer[_knifecycle.SPECIAL_PROPS.TYPE] === 'constant') {
|
|
90
|
+
log('debug', `🤖 - Reusing a constant initializer directly from the Knifecycle instance: "${serviceName}".`);
|
|
91
|
+
return {
|
|
92
|
+
initializer,
|
|
93
|
+
path: `instance://${serviceName}`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (serviceName.startsWith('OPERATION_API_')) {
|
|
98
|
+
const OPERATION_API = await getAPIOperation(serviceName);
|
|
99
|
+
return {
|
|
100
|
+
initializer: (0, _knifecycle.constant)(serviceName, OPERATION_API),
|
|
101
|
+
path: `api://${serviceName}`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (BUILD_CONSTANTS[serviceName]) {
|
|
106
|
+
return {
|
|
107
|
+
initializer: (0, _knifecycle.constant)(serviceName, BUILD_CONSTANTS[serviceName]),
|
|
108
|
+
path: `constant://${serviceName}`
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return $autoload(serviceName);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
log('error', `Build error while loading "${serviceName}".`);
|
|
115
|
+
log('stack', err.stack);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}, _whook.initAutoload));
|
|
119
|
+
|
|
120
|
+
exports.default = _default;
|
|
121
|
+
//# sourceMappingURL=_autoload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/_autoload.ts"],"names":["BUILD_CONSTANTS","$injector","$instance","log","noop","$autoload","API","OPERATION_APIS","getAPIOperation","serviceName","OPERATION","find","operation","sourceOperationId","operationId","suffix","YError","OPERATION_API","paths","path","method","parameters","initializer","_initializers","get","SPECIAL_PROPS","TYPE","startsWith","err","stack","initAutoload"],"mappings":";;;;;;;AAAA;;AACA;;AAMA;;AACA;;;;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,4BACb,CAAC,kBAAD,EAAqB,WAArB,EAAkC,WAAlC,EAA+C,MAA/C,CADa,EAEb,iCACE,OACE;AACEA,EAAAA,eAAe,GAAG,EADpB;AAEEC,EAAAA,SAFF;AAGEC,EAAAA,SAHF;AAIEC,EAAAA,GAAG,GAAGC;AAJR,CADF,EAYEC,SAZF,KAkBK;AACH,MAAIC,GAAJ;AACA,MAAIC,cAAJ;;AACA,QAAMC,eAAe,GAAG,CAAC,MAAM;AAC7B,WAAO,MAAOC,WAAP,IAAuB;AAC5B;AACAH,MAAAA,GAAG,GAAGA,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EAqHEC,mBArHF,CAFa,C","sourcesContent":["import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';\nimport Knifecycle, {\n SPECIAL_PROPS,\n wrapInitializer,\n constant,\n alsoInject,\n} from 'knifecycle';\nimport YError from 'yerror';\nimport {\n dereferenceOpenAPIOperations,\n getOpenAPIOperations,\n} from '@whook/http-router';\nimport type {\n Injector,\n Autoloader,\n Initializer,\n Dependencies,\n Service,\n} from 'knifecycle';\nimport type { WhookBuildConstantsService } from '@whook/whook';\nimport type { WhookRawOperation } from '@whook/http-router';\nimport type { LogService } from 'common-services';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { WhookAPIOperationGCPFunctionConfig } from '..';\n\n/**\n * Wrap the _autoload service in order to build AWS\n * Lambda compatible code.\n * @param {Object} services\n * The services ENV depends on\n * @param {Object} services.NODE_ENV\n * The injected NODE_ENV value to add it to the build env\n * @param {Object} [services.PROXYED_ENV_VARS={}]\n * A list of environment variable names to proxy\n * @param {Object} [services.log=noop]\n * An optional logging service\n * @return {Promise<Object>}\n * A promise of an object containing the reshaped env vars.\n */\nexport default alsoInject(\n ['?BUILD_CONSTANTS', '$instance', '$injector', '?log'],\n wrapInitializer(\n async (\n {\n BUILD_CONSTANTS = {},\n $injector,\n $instance,\n log = noop,\n }: {\n BUILD_CONSTANTS?: WhookBuildConstantsService;\n $injector: Injector<Service>;\n $instance: Knifecycle<Dependencies>;\n log: LogService;\n },\n $autoload: Autoloader,\n ): Promise<\n (serviceName: string) => Promise<{\n initializer: Initializer<Dependencies, Service>;\n path: string;\n }>\n > => {\n let API: OpenAPIV3.Document;\n let OPERATION_APIS: WhookRawOperation<WhookAPIOperationGCPFunctionConfig>[];\n const getAPIOperation = (() => {\n return async (serviceName) => {\n // eslint-disable-next-line\n API = API || (await $injector(['API'])).API;\n // eslint-disable-next-line\n OPERATION_APIS =\n OPERATION_APIS ||\n getOpenAPIOperations<WhookAPIOperationGCPFunctionConfig>(API);\n\n const OPERATION = OPERATION_APIS.find(\n (operation) =>\n serviceName ===\n (((operation['x-whook'] || {}).sourceOperationId &&\n 'OPERATION_API_' +\n (operation['x-whook'] || {}).sourceOperationId) ||\n 'OPERATION_API_' + operation.operationId) +\n ((operation['x-whook'] || {}).suffix || ''),\n );\n\n if (!OPERATION) {\n log('error', '💥 - Unable to find a lambda operation definition!');\n throw new YError('E_OPERATION_NOT_FOUND', serviceName);\n }\n\n // eslint-disable-next-line\n const OPERATION_API = cleanupOpenAPI({\n ...API,\n paths: {\n [OPERATION.path]: {\n [OPERATION.method]: API.paths[OPERATION.path][OPERATION.method],\n },\n },\n });\n\n return {\n ...OPERATION_API,\n paths: {\n [OPERATION.path]: {\n [OPERATION.method]: (\n await dereferenceOpenAPIOperations(OPERATION_API, [\n {\n path: OPERATION.path,\n method: OPERATION.method,\n ...OPERATION_API.paths[OPERATION.path][OPERATION.method],\n parameters: OPERATION.parameters,\n },\n ])\n )[0],\n },\n },\n };\n };\n })();\n\n log('debug', '🤖 - Initializing the `$autoload` build wrapper.');\n\n return async (serviceName) => {\n try {\n // TODO: add initializer map to knifecycle public API\n const initializer = ($instance as any)._initializers.get(serviceName);\n\n if (initializer && initializer[SPECIAL_PROPS.TYPE] === 'constant') {\n log(\n 'debug',\n `🤖 - Reusing a constant initializer directly from the Knifecycle instance: \"${serviceName}\".`,\n );\n return {\n initializer,\n path: `instance://${serviceName}`,\n };\n }\n\n if (serviceName.startsWith('OPERATION_API_')) {\n const OPERATION_API = await getAPIOperation(serviceName);\n\n return {\n initializer: constant(serviceName, OPERATION_API),\n path: `api://${serviceName}`,\n };\n }\n\n if (BUILD_CONSTANTS[serviceName]) {\n return {\n initializer: constant(serviceName, BUILD_CONSTANTS[serviceName]),\n path: `constant://${serviceName}`,\n };\n }\n\n return $autoload(serviceName);\n } catch (err) {\n log('error', `Build error while loading \"${serviceName}\".`);\n log('stack', err.stack);\n }\n };\n },\n initAutoload,\n ),\n);\n"],"file":"_autoload.js"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';
|
|
8
|
+
import { SPECIAL_PROPS, wrapInitializer, constant, alsoInject } from 'knifecycle';
|
|
9
|
+
import YError from 'yerror';
|
|
10
|
+
import { dereferenceOpenAPIOperations, getOpenAPIOperations } from '@whook/http-router';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wrap the _autoload service in order to build AWS
|
|
14
|
+
* Lambda compatible code.
|
|
15
|
+
* @param {Object} services
|
|
16
|
+
* The services ENV depends on
|
|
17
|
+
* @param {Object} services.NODE_ENV
|
|
18
|
+
* The injected NODE_ENV value to add it to the build env
|
|
19
|
+
* @param {Object} [services.PROXYED_ENV_VARS={}]
|
|
20
|
+
* A list of environment variable names to proxy
|
|
21
|
+
* @param {Object} [services.log=noop]
|
|
22
|
+
* An optional logging service
|
|
23
|
+
* @return {Promise<Object>}
|
|
24
|
+
* A promise of an object containing the reshaped env vars.
|
|
25
|
+
*/
|
|
26
|
+
export default alsoInject(['?BUILD_CONSTANTS', '$instance', '$injector', '?log'], wrapInitializer(async ({
|
|
27
|
+
BUILD_CONSTANTS = {},
|
|
28
|
+
$injector,
|
|
29
|
+
$instance,
|
|
30
|
+
log = noop
|
|
31
|
+
}, $autoload) => {
|
|
32
|
+
let API;
|
|
33
|
+
let OPERATION_APIS;
|
|
34
|
+
|
|
35
|
+
const getAPIOperation = (() => {
|
|
36
|
+
return async serviceName => {
|
|
37
|
+
// eslint-disable-next-line
|
|
38
|
+
API = API || (await $injector(['API'])).API; // eslint-disable-next-line
|
|
39
|
+
|
|
40
|
+
OPERATION_APIS = OPERATION_APIS || getOpenAPIOperations(API);
|
|
41
|
+
const OPERATION = OPERATION_APIS.find(operation => serviceName === ((operation['x-whook'] || {}).sourceOperationId && 'OPERATION_API_' + (operation['x-whook'] || {}).sourceOperationId || 'OPERATION_API_' + operation.operationId) + ((operation['x-whook'] || {}).suffix || ''));
|
|
42
|
+
|
|
43
|
+
if (!OPERATION) {
|
|
44
|
+
log('error', '💥 - Unable to find a lambda operation definition!');
|
|
45
|
+
throw new YError('E_OPERATION_NOT_FOUND', serviceName);
|
|
46
|
+
} // eslint-disable-next-line
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const OPERATION_API = cleanupOpenAPI(_objectSpread(_objectSpread({}, API), {}, {
|
|
50
|
+
paths: {
|
|
51
|
+
[OPERATION.path]: {
|
|
52
|
+
[OPERATION.method]: API.paths[OPERATION.path][OPERATION.method]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
return _objectSpread(_objectSpread({}, OPERATION_API), {}, {
|
|
57
|
+
paths: {
|
|
58
|
+
[OPERATION.path]: {
|
|
59
|
+
[OPERATION.method]: (await dereferenceOpenAPIOperations(OPERATION_API, [_objectSpread(_objectSpread({
|
|
60
|
+
path: OPERATION.path,
|
|
61
|
+
method: OPERATION.method
|
|
62
|
+
}, OPERATION_API.paths[OPERATION.path][OPERATION.method]), {}, {
|
|
63
|
+
parameters: OPERATION.parameters
|
|
64
|
+
})]))[0]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
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[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: constant(serviceName, OPERATION_API),
|
|
89
|
+
path: `api://${serviceName}`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (BUILD_CONSTANTS[serviceName]) {
|
|
94
|
+
return {
|
|
95
|
+
initializer: 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('stack', err.stack);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}, initAutoload));
|
|
107
|
+
//# sourceMappingURL=_autoload.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/_autoload.ts"],"names":["initAutoload","noop","cleanupOpenAPI","SPECIAL_PROPS","wrapInitializer","constant","alsoInject","YError","dereferenceOpenAPIOperations","getOpenAPIOperations","BUILD_CONSTANTS","$injector","$instance","log","$autoload","API","OPERATION_APIS","getAPIOperation","serviceName","OPERATION","find","operation","sourceOperationId","operationId","suffix","OPERATION_API","paths","path","method","parameters","initializer","_initializers","get","TYPE","startsWith","err","stack"],"mappings":";;;;;;AAAA,SAASA,YAAT,EAAuBC,IAAvB,EAA6BC,cAA7B,QAAmD,cAAnD;AACA,SACEC,aADF,EAEEC,eAFF,EAGEC,QAHF,EAIEC,UAJF,QAKO,YALP;AAMA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SACEC,4BADF,EAEEC,oBAFF,QAGO,oBAHP;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeH,UAAU,CACvB,CAAC,kBAAD,EAAqB,WAArB,EAAkC,WAAlC,EAA+C,MAA/C,CADuB,EAEvBF,eAAe,CACb,OACE;AACEM,EAAAA,eAAe,GAAG,EADpB;AAEEC,EAAAA,SAFF;AAGEC,EAAAA,SAHF;AAIEC,EAAAA,GAAG,GAAGZ;AAJR,CADF,EAYEa,SAZF,KAkBK;AACH,MAAIC,GAAJ;AACA,MAAIC,cAAJ;;AACA,QAAMC,eAAe,GAAG,CAAC,MAAM;AAC7B,WAAO,MAAOC,WAAP,IAAuB;AAC5B;AACAH,MAAAA,GAAG,GAAGA,GAAG,IAAI,CAAC,MAAMJ,SAAS,CAAC,CAAC,KAAD,CAAD,CAAhB,EAA2BI,GAAxC,CAF4B,CAG5B;;AACAC,MAAAA,cAAc,GACZA,cAAc,IACdP,oBAAoB,CAAqCM,GAArC,CAFtB;AAIA,YAAMI,SAAS,GAAGH,cAAc,CAACI,IAAf,CACfC,SAAD,IACEH,WAAW,KACX,CAAE,CAACG,SAAS,CAAC,SAAD,CAAT,IAAwB,EAAzB,EAA6BC,iBAA7B,IACA,mBACE,CAACD,SAAS,CAAC,SAAD,CAAT,IAAwB,EAAzB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,UAAIY,WAAW,IAAIA,WAAW,CAAC3B,aAAa,CAAC8B,IAAf,CAAX,KAAoC,UAAvD,EAAmE;AACjEpB,QAAAA,GAAG,CACD,OADC,EAEA,+EAA8EK,WAAY,IAF1F,CAAH;AAIA,eAAO;AACLY,UAAAA,WADK;AAELH,UAAAA,IAAI,EAAG,cAAaT,WAAY;AAF3B,SAAP;AAID;;AAED,UAAIA,WAAW,CAACgB,UAAZ,CAAuB,gBAAvB,CAAJ,EAA8C;AAC5C,cAAMT,aAAa,GAAG,MAAMR,eAAe,CAACC,WAAD,CAA3C;AAEA,eAAO;AACLY,UAAAA,WAAW,EAAEzB,QAAQ,CAACa,WAAD,EAAcO,aAAd,CADhB;AAELE,UAAAA,IAAI,EAAG,SAAQT,WAAY;AAFtB,SAAP;AAID;;AAED,UAAIR,eAAe,CAACQ,WAAD,CAAnB,EAAkC;AAChC,eAAO;AACLY,UAAAA,WAAW,EAAEzB,QAAQ,CAACa,WAAD,EAAcR,eAAe,CAACQ,WAAD,CAA7B,CADhB;AAELS,UAAAA,IAAI,EAAG,cAAaT,WAAY;AAF3B,SAAP;AAID;;AAED,aAAOJ,SAAS,CAACI,WAAD,CAAhB;AACD,KAhCD,CAgCE,OAAOiB,GAAP,EAAY;AACZtB,MAAAA,GAAG,CAAC,OAAD,EAAW,8BAA6BK,WAAY,IAApD,CAAH;AACAL,MAAAA,GAAG,CAAC,OAAD,EAAUsB,GAAG,CAACC,KAAd,CAAH;AACD;AACF,GArCD;AAsCD,CApHY,EAqHbpC,YArHa,CAFQ,CAAzB","sourcesContent":["import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';\nimport Knifecycle, {\n SPECIAL_PROPS,\n wrapInitializer,\n constant,\n alsoInject,\n} from 'knifecycle';\nimport YError from 'yerror';\nimport {\n dereferenceOpenAPIOperations,\n getOpenAPIOperations,\n} from '@whook/http-router';\nimport type {\n Injector,\n Autoloader,\n Initializer,\n Dependencies,\n Service,\n} from 'knifecycle';\nimport type { WhookBuildConstantsService } from '@whook/whook';\nimport type { WhookRawOperation } from '@whook/http-router';\nimport type { LogService } from 'common-services';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { WhookAPIOperationGCPFunctionConfig } from '..';\n\n/**\n * Wrap the _autoload service in order to build AWS\n * Lambda compatible code.\n * @param {Object} services\n * The services ENV depends on\n * @param {Object} services.NODE_ENV\n * The injected NODE_ENV value to add it to the build env\n * @param {Object} [services.PROXYED_ENV_VARS={}]\n * A list of environment variable names to proxy\n * @param {Object} [services.log=noop]\n * An optional logging service\n * @return {Promise<Object>}\n * A promise of an object containing the reshaped env vars.\n */\nexport default alsoInject(\n ['?BUILD_CONSTANTS', '$instance', '$injector', '?log'],\n wrapInitializer(\n async (\n {\n BUILD_CONSTANTS = {},\n $injector,\n $instance,\n log = noop,\n }: {\n BUILD_CONSTANTS?: WhookBuildConstantsService;\n $injector: Injector<Service>;\n $instance: Knifecycle<Dependencies>;\n log: LogService;\n },\n $autoload: Autoloader,\n ): Promise<\n (serviceName: string) => Promise<{\n initializer: Initializer<Dependencies, Service>;\n path: string;\n }>\n > => {\n let API: OpenAPIV3.Document;\n let OPERATION_APIS: WhookRawOperation<WhookAPIOperationGCPFunctionConfig>[];\n const getAPIOperation = (() => {\n return async (serviceName) => {\n // eslint-disable-next-line\n API = API || (await $injector(['API'])).API;\n // eslint-disable-next-line\n OPERATION_APIS =\n OPERATION_APIS ||\n getOpenAPIOperations<WhookAPIOperationGCPFunctionConfig>(API);\n\n const OPERATION = OPERATION_APIS.find(\n (operation) =>\n serviceName ===\n (((operation['x-whook'] || {}).sourceOperationId &&\n 'OPERATION_API_' +\n (operation['x-whook'] || {}).sourceOperationId) ||\n 'OPERATION_API_' + operation.operationId) +\n ((operation['x-whook'] || {}).suffix || ''),\n );\n\n if (!OPERATION) {\n log('error', '💥 - Unable to find a lambda operation definition!');\n throw new YError('E_OPERATION_NOT_FOUND', serviceName);\n }\n\n // eslint-disable-next-line\n const OPERATION_API = cleanupOpenAPI({\n ...API,\n paths: {\n [OPERATION.path]: {\n [OPERATION.method]: API.paths[OPERATION.path][OPERATION.method],\n },\n },\n });\n\n return {\n ...OPERATION_API,\n paths: {\n [OPERATION.path]: {\n [OPERATION.method]: (\n await dereferenceOpenAPIOperations(OPERATION_API, [\n {\n path: OPERATION.path,\n method: OPERATION.method,\n ...OPERATION_API.paths[OPERATION.path][OPERATION.method],\n parameters: OPERATION.parameters,\n },\n ])\n )[0],\n },\n },\n };\n };\n })();\n\n log('debug', '🤖 - Initializing the `$autoload` build wrapper.');\n\n return async (serviceName) => {\n try {\n // TODO: add initializer map to knifecycle public API\n const initializer = ($instance as any)._initializers.get(serviceName);\n\n if (initializer && initializer[SPECIAL_PROPS.TYPE] === 'constant') {\n log(\n 'debug',\n `🤖 - Reusing a constant initializer directly from the Knifecycle instance: \"${serviceName}\".`,\n );\n return {\n initializer,\n path: `instance://${serviceName}`,\n };\n }\n\n if (serviceName.startsWith('OPERATION_API_')) {\n const OPERATION_API = await getAPIOperation(serviceName);\n\n return {\n initializer: constant(serviceName, OPERATION_API),\n path: `api://${serviceName}`,\n };\n }\n\n if (BUILD_CONSTANTS[serviceName]) {\n return {\n initializer: constant(serviceName, BUILD_CONSTANTS[serviceName]),\n path: `constant://${serviceName}`,\n };\n }\n\n return $autoload(serviceName);\n } catch (err) {\n log('error', `Build error while loading \"${serviceName}\".`);\n log('stack', err.stack);\n }\n };\n },\n initAutoload,\n ),\n);\n"],"file":"_autoload.mjs"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
var _default = (0, _knifecycle.service)(async () => console.log.bind(console), 'log');
|
|
12
|
+
|
|
13
|
+
exports.default = _default;
|
|
14
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/log.ts"],"names":["console","log","bind"],"mappings":";;;;;;;AAAA;;AAEA;eACe,yBAAQ,YAAYA,OAAO,CAACC,GAAR,CAAYC,IAAZ,CAAiBF,OAAjB,CAApB,EAA+C,KAA/C,C","sourcesContent":["import { service } from 'knifecycle';\n\n// eslint-disable-next-line\nexport default service(async () => console.log.bind(console), 'log');\n"],"file":"log.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/log.ts"],"names":["service","console","log","bind"],"mappings":"AAAA,SAASA,OAAT,QAAwB,YAAxB,C,CAEA;;AACA,eAAeA,OAAO,CAAC,YAAYC,OAAO,CAACC,GAAR,CAAYC,IAAZ,CAAiBF,OAAjB,CAAb,EAAwC,KAAxC,CAAtB","sourcesContent":["import { service } from 'knifecycle';\n\n// eslint-disable-next-line\nexport default service(async () => console.log.bind(console), 'log');\n"],"file":"log.mjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _log = _interopRequireDefault(require("./log"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('initLogService', () => {
|
|
8
|
+
it('should work', async () => {
|
|
9
|
+
await (0, _log.default)();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=log.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/log.test.ts"],"names":["describe","it"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,EAAE,CAAC,aAAD,EAAgB,YAAY;AAC5B,UAAM,mBAAN;AACD,GAFC,CAAF;AAGD,CAJO,CAAR","sourcesContent":["import initLogService from './log';\n\ndescribe('initLogService', () => {\n it('should work', async () => {\n await initLogService();\n });\n});\n"],"file":"log.test.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/log.test.ts"],"names":["initLogService","describe","it"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,OAA3B;AAEAC,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,EAAE,CAAC,aAAD,EAAgB,YAAY;AAC5B,UAAMF,cAAc,EAApB;AACD,GAFC,CAAF;AAGD,CAJO,CAAR","sourcesContent":["import initLogService from './log';\n\ndescribe('initLogService', () => {\n it('should work', async () => {\n await initLogService();\n });\n});\n"],"file":"log.test.mjs"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DEFAULT_PARSERS, DEFAULT_STRINGIFYERS, DEFAULT_DECODERS, DEFAULT_ENCODERS } from '@whook/http-router';
|
|
2
|
+
import type { WhookQueryStringParser } from '@whook/http-router';
|
|
3
|
+
import type { ServiceInitializer, Dependencies, Service } from 'knifecycle';
|
|
4
|
+
import type { WhookHandler, ObfuscatorService, WhookOperation, WhookWrapper } from '@whook/whook';
|
|
5
|
+
import type { TimeService, LogService } from 'common-services';
|
|
6
|
+
declare type HTTPWrapperDependencies = {
|
|
7
|
+
NODE_ENV: string;
|
|
8
|
+
DEBUG_NODE_ENVS?: string[];
|
|
9
|
+
OPERATION: WhookOperation;
|
|
10
|
+
DECODERS?: typeof DEFAULT_DECODERS;
|
|
11
|
+
ENCODERS?: typeof DEFAULT_ENCODERS;
|
|
12
|
+
PARSERS?: typeof DEFAULT_PARSERS;
|
|
13
|
+
STRINGIFYERS?: typeof DEFAULT_STRINGIFYERS;
|
|
14
|
+
QUERY_PARSER: WhookQueryStringParser;
|
|
15
|
+
BUFFER_LIMIT?: string;
|
|
16
|
+
obfuscator: ObfuscatorService;
|
|
17
|
+
time?: TimeService;
|
|
18
|
+
log?: LogService;
|
|
19
|
+
WRAPPERS: WhookWrapper<Dependencies, Service>[];
|
|
20
|
+
};
|
|
21
|
+
export default function wrapHandlerForAWSHTTPFunction<D, S extends WhookHandler>(initHandler: ServiceInitializer<D, S>): ServiceInitializer<D & HTTPWrapperDependencies, S>;
|
|
22
|
+
export {};
|