@whook/gcp-functions 8.5.1 → 10.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.
Files changed (40) hide show
  1. package/README.md +51 -40
  2. package/dist/commands/testHTTPFunction.d.ts +1 -1
  3. package/dist/commands/testHTTPFunction.js +119 -150
  4. package/dist/commands/testHTTPFunction.js.map +1 -1
  5. package/dist/index.d.ts +3 -6
  6. package/dist/index.js +182 -269
  7. package/dist/index.js.map +1 -1
  8. package/dist/libs/utils.js +16 -35
  9. package/dist/libs/utils.js.map +1 -1
  10. package/dist/services/_autoload.d.ts +14 -2
  11. package/dist/services/_autoload.js +85 -105
  12. package/dist/services/_autoload.js.map +1 -1
  13. package/dist/services/log.d.ts +4 -1
  14. package/dist/services/log.js +2 -12
  15. package/dist/services/log.js.map +1 -1
  16. package/dist/services/log.test.js +4 -9
  17. package/dist/services/log.test.js.map +1 -1
  18. package/dist/wrappers/googleHTTPFunction.js +246 -292
  19. package/dist/wrappers/googleHTTPFunction.js.map +1 -1
  20. package/package.json +55 -98
  21. package/src/commands/testHTTPFunction.ts +12 -19
  22. package/src/index.ts +48 -62
  23. package/src/libs/utils.ts +4 -5
  24. package/src/services/_autoload.ts +127 -122
  25. package/src/services/log.test.ts +2 -2
  26. package/src/wrappers/googleHTTPFunction.ts +34 -32
  27. package/dist/commands/testHTTPFunction.mjs +0 -136
  28. package/dist/commands/testHTTPFunction.mjs.map +0 -1
  29. package/dist/index.mjs +0 -265
  30. package/dist/index.mjs.map +0 -1
  31. package/dist/libs/utils.mjs +0 -27
  32. package/dist/libs/utils.mjs.map +0 -1
  33. package/dist/services/_autoload.mjs +0 -107
  34. package/dist/services/_autoload.mjs.map +0 -1
  35. package/dist/services/log.mjs +0 -4
  36. package/dist/services/log.mjs.map +0 -1
  37. package/dist/services/log.test.mjs +0 -7
  38. package/dist/services/log.test.mjs.map +0 -1
  39. package/dist/wrappers/googleHTTPFunction.mjs +0 -288
  40. package/dist/wrappers/googleHTTPFunction.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,217 +1,153 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DEFAULT_BUILD_PARALLELISM = void 0;
7
- exports.prepareBuildEnvironment = prepareBuildEnvironment;
8
- exports.runBuild = runBuild;
9
-
10
- var _fs = _interopRequireDefault(require("fs"));
11
-
12
- var _util = _interopRequireDefault(require("util"));
13
-
14
- var _path = _interopRequireDefault(require("path"));
15
-
16
- var _mkdirp = _interopRequireDefault(require("mkdirp"));
17
-
18
- var _cpr = _interopRequireDefault(require("cpr"));
19
-
20
- var _yerror = _interopRequireDefault(require("yerror"));
21
-
22
- var _knifecycle = _interopRequireWildcard(require("knifecycle"));
23
-
24
- var _whook = require("@whook/whook");
25
-
26
- var _autoload = _interopRequireDefault(require("./services/_autoload"));
27
-
28
- var _httpRouter = require("@whook/http-router");
29
-
30
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
-
32
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
1
  /* eslint global-require:0 */
37
- const DEFAULT_BUILD_PARALLELISM = 10;
38
- exports.DEFAULT_BUILD_PARALLELISM = DEFAULT_BUILD_PARALLELISM;
39
-
40
- const readFileAsync = _util.default.promisify(_fs.default.readFile);
41
-
42
- const writeFileAsync = _util.default.promisify(_fs.default.writeFile);
43
-
44
- const cprAsync = _util.default.promisify(_cpr.default);
45
-
2
+ import fs from 'fs';
3
+ import util from 'util';
4
+ import path from 'path';
5
+ import mkdirp from 'mkdirp';
6
+ import cpr from 'cpr';
7
+ import { YError } from 'yerror';
8
+ import { createRequire } from 'module';
9
+ import { Knifecycle, SPECIAL_PROPS, constant, initInitializerBuilder, } from 'knifecycle';
10
+ import { initCompiler } from '@whook/whook';
11
+ import initBuildAutoloader from './services/_autoload.js';
12
+ import { dereferenceOpenAPIOperations, getOpenAPIOperations, } from '@whook/http-router';
13
+ export const DEFAULT_BUILD_PARALLELISM = 10;
14
+ const readFileAsync = util.promisify(fs.readFile);
15
+ const writeFileAsync = util.promisify(fs.writeFile);
16
+ const cprAsync = util.promisify(cpr);
17
+ // TODO: Use import.meta when Jest will support it
18
+ const require = createRequire(path.join(process.cwd(), 'src', 'index.ts'));
46
19
  const BUILD_DEFINITIONS = {
47
- http: {
48
- type: 'HTTP',
49
- wrapper: {
50
- name: 'wrapHandlerForGoogleHTTPFunction',
51
- path: _path.default.join(__dirname, 'wrappers', 'googleHTTPFunction')
20
+ http: {
21
+ type: 'HTTP',
22
+ wrapper: {
23
+ name: 'wrapHandlerForGoogleHTTPFunction',
24
+ path: path.join(path.dirname(require.resolve('@whook/gcp-function')), 'wrappers/googleHTTPFunction.js'),
25
+ },
26
+ suffix: 'Wrapped',
52
27
  },
53
- suffix: 'Wrapped'
54
- }
55
28
  };
56
-
57
- async function prepareBuildEnvironment($ = new _knifecycle.default()) {
58
- $.register((0, _knifecycle.constant)('INITIALIZER_PATH_MAP', {
59
- ENV: '@whook/whook/dist/services/ProxyedENV',
60
- log: __dirname + '/services/log',
61
- time: 'common-services/dist/time',
62
- delay: 'common-services/dist/delay'
63
- }));
64
- $.register(_knifecycle.initInitializerBuilder);
65
- $.register(_autoload.default);
66
- $.register(_whook.initCompiler);
67
- $.register((0, _knifecycle.constant)('PORT', 1337));
68
- $.register((0, _knifecycle.constant)('HOST', 'localhost'));
69
- return $;
29
+ export async function prepareBuildEnvironment($ = new Knifecycle()) {
30
+ $.register(constant('INITIALIZER_PATH_MAP', {
31
+ ENV: '@whook/whook/dist/services/ProxyedENV',
32
+ log: '@whook/gcp-functions/dist/services/log',
33
+ time: 'common-services/dist/time',
34
+ delay: 'common-services/dist/delay',
35
+ }));
36
+ $.register(initInitializerBuilder);
37
+ $.register(initBuildAutoloader);
38
+ $.register(initCompiler);
39
+ $.register(constant('PORT', 1337));
40
+ $.register(constant('HOST', 'localhost'));
41
+ return $;
70
42
  }
71
-
72
- async function runBuild(aPrepareBuildEnvironment) {
73
- try {
74
- const handlerName = process.argv[2];
75
- const $ = await aPrepareBuildEnvironment();
76
- const {
77
- NODE_ENV,
78
- BUILD_PARALLELISM,
79
- BUILD_OPTIONS,
80
- PROJECT_DIR,
81
- compiler,
82
- log,
83
- $autoload,
84
- API,
85
- buildInitializer
86
- } = await $.run(['NODE_ENV', '?BUILD_PARALLELISM', '?BUILD_OPTIONS', 'PROJECT_DIR', 'process', 'compiler', 'log', '$autoload', 'API', 'buildInitializer']);
87
- log('info', 'Environment initialized 🚀🌕');
88
- const operations = (await (0, _httpRouter.dereferenceOpenAPIOperations)(API, (0, _httpRouter.getOpenAPIOperations)(API))).filter(operation => {
89
- if (handlerName) {
90
- const sourceOperationId = operation['x-whook'] && operation['x-whook'].sourceOperationId;
91
- return handlerName === operation.operationId || handlerName === sourceOperationId;
92
- }
93
-
94
- return true;
95
- });
96
- log('warning', `${operations.length} operations to process.`);
97
- await processOperations({
98
- NODE_ENV,
99
- BUILD_OPTIONS: BUILD_OPTIONS || _whook.DEFAULT_BUILD_OPTIONS,
100
- BUILD_PARALLELISM: BUILD_PARALLELISM || DEFAULT_BUILD_PARALLELISM,
101
- PROJECT_DIR,
102
- compiler,
103
- log,
104
- $autoload,
105
- buildInitializer
106
- }, operations);
107
- await $.destroy();
108
- } catch (err) {
109
- // eslint-disable-next-line
110
- console.error('💀 - Cannot launch the build:', err.stack, JSON.stringify(err.params, null, 2));
111
- process.exit(1);
112
- }
43
+ export async function runBuild(aPrepareBuildEnvironment) {
44
+ try {
45
+ const handlerName = process.argv[2];
46
+ const $ = await aPrepareBuildEnvironment();
47
+ const { NODE_ENV, BUILD_PARALLELISM, PROJECT_DIR, compiler, log, $autoload, API, buildInitializer, } = await $.run([
48
+ 'NODE_ENV',
49
+ '?BUILD_PARALLELISM',
50
+ 'PROJECT_DIR',
51
+ 'process',
52
+ 'compiler',
53
+ 'log',
54
+ '$autoload',
55
+ 'API',
56
+ 'buildInitializer',
57
+ ]);
58
+ log('info', 'GCP Functions build Environment initialized 🚀🌕');
59
+ const operations = (await dereferenceOpenAPIOperations(API, getOpenAPIOperations(API))).filter((operation) => {
60
+ if (handlerName) {
61
+ const sourceOperationId = operation['x-whook'] && operation['x-whook'].sourceOperationId;
62
+ return (handlerName === operation.operationId ||
63
+ handlerName === sourceOperationId);
64
+ }
65
+ return true;
66
+ });
67
+ log('warning', `${operations.length} operations to process.`);
68
+ await processOperations({
69
+ NODE_ENV,
70
+ BUILD_PARALLELISM: BUILD_PARALLELISM || DEFAULT_BUILD_PARALLELISM,
71
+ PROJECT_DIR,
72
+ compiler,
73
+ log,
74
+ $autoload,
75
+ buildInitializer,
76
+ }, operations);
77
+ await $.destroy();
78
+ }
79
+ catch (err) {
80
+ // eslint-disable-next-line
81
+ console.error('💀 - Cannot launch the build:', err.stack, JSON.stringify(err.params, null, 2));
82
+ process.exit(1);
83
+ }
113
84
  }
114
-
115
- async function processOperations({
116
- NODE_ENV,
117
- BUILD_PARALLELISM,
118
- BUILD_OPTIONS,
119
- PROJECT_DIR,
120
- compiler,
121
- log,
122
- $autoload,
123
- buildInitializer
124
- }, operations) {
125
- const operationsLeft = operations.slice(BUILD_PARALLELISM);
126
- await Promise.all(operations.slice(0, BUILD_PARALLELISM).map(operation => buildAnyLambda({
127
- NODE_ENV,
128
- PROJECT_DIR,
129
- BUILD_OPTIONS,
130
- compiler,
131
- log,
132
- $autoload,
133
- buildInitializer
134
- }, operation)));
135
-
136
- if (operationsLeft.length) {
137
- log('info', operationsLeft.length, ' operations left.');
138
- return processOperations({
139
- NODE_ENV,
140
- BUILD_PARALLELISM,
141
- BUILD_OPTIONS,
142
- PROJECT_DIR,
143
- compiler,
144
- log,
145
- $autoload,
146
- buildInitializer
147
- }, operationsLeft);
148
- }
149
-
150
- log('info', 'No more operations.');
85
+ async function processOperations({ NODE_ENV, BUILD_PARALLELISM, PROJECT_DIR, compiler, log, $autoload, buildInitializer, }, operations) {
86
+ const operationsLeft = operations.slice(BUILD_PARALLELISM);
87
+ await Promise.all(operations.slice(0, BUILD_PARALLELISM).map((operation) => buildAnyLambda({
88
+ NODE_ENV,
89
+ PROJECT_DIR,
90
+ compiler,
91
+ log,
92
+ $autoload,
93
+ buildInitializer,
94
+ }, operation)));
95
+ if (operationsLeft.length) {
96
+ log('info', operationsLeft.length, ' operations left.');
97
+ return processOperations({
98
+ NODE_ENV,
99
+ BUILD_PARALLELISM,
100
+ PROJECT_DIR,
101
+ compiler,
102
+ log,
103
+ $autoload,
104
+ buildInitializer,
105
+ }, operationsLeft);
106
+ }
107
+ log('info', 'No more operations.');
151
108
  }
152
-
153
- async function buildAnyLambda({
154
- NODE_ENV,
155
- PROJECT_DIR,
156
- BUILD_OPTIONS,
157
- compiler,
158
- log,
159
- $autoload,
160
- buildInitializer
161
- }, operation) {
162
- const {
163
- operationId
164
- } = operation;
165
-
166
- try {
167
- const whookConfig = operation['x-whook'] || {};
168
- const operationType = whookConfig.type || 'http';
169
- const sourceOperationId = whookConfig.sourceOperationId;
170
- const entryPoint = operationId;
171
- const finalEntryPoint = (sourceOperationId ? sourceOperationId : operationId) + ((operation['x-whook'] || {}).suffix || '');
172
- log('warning', `Building ${operationType} "${finalEntryPoint}"...`);
173
- const buildDefinition = BUILD_DEFINITIONS[operationType]; // eslint-disable-next-line
174
-
175
- const applyWrapper = require(buildDefinition.wrapper.path).default;
176
-
177
- const rootNode = await $autoload(entryPoint + (buildDefinition.suffix || ''));
178
-
179
- const lambdaPath = _path.default.join(PROJECT_DIR, 'builds', NODE_ENV, finalEntryPoint);
180
-
181
- const finalHandlerInitializer = applyWrapper(rootNode.initializer);
182
- const initializerContent = await buildInitializer(finalHandlerInitializer[_knifecycle.SPECIAL_PROPS.INJECT].map(name => name === 'OPERATION_API' ? `OPERATION_API>OPERATION_API_${finalEntryPoint}` : name), BUILD_OPTIONS);
183
- const indexContent = await buildLambdaIndex(rootNode, {
184
- name: buildDefinition.wrapper.name,
185
- path: buildDefinition.wrapper.path
186
- }, BUILD_OPTIONS);
187
- await (0, _mkdirp.default)(lambdaPath);
188
- await Promise.all([copyStaticFiles({
189
- PROJECT_DIR,
190
- log
191
- }, lambdaPath, whookConfig.staticFiles || []), ensureFileAsync({
192
- log
193
- }, _path.default.join(lambdaPath, 'initialize.js'), initializerContent), ensureFileAsync({
194
- log
195
- }, _path.default.join(lambdaPath, 'main.js'), indexContent)]);
196
- await buildFinalLambda({
197
- compiler,
198
- log
199
- }, lambdaPath, whookConfig);
200
- } catch (err) {
201
- log('error', `Error building "${operationId}"...`);
202
- log('stack', err.stack);
203
- log('debug', JSON.stringify(err.params, null, 2));
204
- throw _yerror.default.wrap(err, 'E_LAMBDA_BUILD', operationId);
205
- }
109
+ async function buildAnyLambda({ NODE_ENV, PROJECT_DIR, compiler, log, $autoload, buildInitializer, }, operation) {
110
+ const { operationId } = operation;
111
+ try {
112
+ const whookConfig = operation['x-whook'] || { type: 'http' };
113
+ const operationType = whookConfig.type || 'http';
114
+ const sourceOperationId = whookConfig.sourceOperationId;
115
+ const entryPoint = operationId;
116
+ const finalEntryPoint = (sourceOperationId ? sourceOperationId : operationId) +
117
+ ((operation['x-whook'] || {}).suffix || '');
118
+ log('warning', `Building ${operationType} "${finalEntryPoint}"...`);
119
+ const buildDefinition = BUILD_DEFINITIONS[operationType];
120
+ // eslint-disable-next-line
121
+ const applyWrapper = (await import(buildDefinition.wrapper.path)).default;
122
+ const rootNode = await $autoload(entryPoint + (buildDefinition.suffix || ''));
123
+ const lambdaPath = path.join(PROJECT_DIR, 'builds', NODE_ENV, finalEntryPoint);
124
+ const finalHandlerInitializer = applyWrapper(rootNode.initializer);
125
+ const initializerContent = await buildInitializer(finalHandlerInitializer[SPECIAL_PROPS.INJECT].map((name) => name === 'OPERATION_API'
126
+ ? `OPERATION_API>OPERATION_API_${finalEntryPoint}`
127
+ : name));
128
+ const indexContent = await buildLambdaIndex(rootNode, {
129
+ name: buildDefinition.wrapper.name,
130
+ path: buildDefinition.wrapper.path,
131
+ });
132
+ await mkdirp(lambdaPath);
133
+ await Promise.all([
134
+ copyStaticFiles({ PROJECT_DIR, log }, lambdaPath, whookConfig.staticFiles || []),
135
+ ensureFileAsync({ log }, path.join(lambdaPath, 'initialize.js'), initializerContent),
136
+ ensureFileAsync({ log }, path.join(lambdaPath, 'main.js'), indexContent),
137
+ ]);
138
+ await buildFinalLambda({ compiler, log }, lambdaPath, whookConfig);
139
+ }
140
+ catch (err) {
141
+ log('error', `Error building "${operationId}"...`);
142
+ log('error-stack', err.stack || 'no_stack_trace');
143
+ log('debug', JSON.stringify(err.params, null, 2));
144
+ throw YError.wrap(err, 'E_LAMBDA_BUILD', operationId);
145
+ }
206
146
  }
207
-
208
- async function buildLambdaIndex(rootNode, buildWrapper, options) {
209
- return `${options.modules === 'commonjs' ? `const pickModule = (m) => { return m && m.default || m; }
210
- const initHandler = pickModule(require('${rootNode.path}'));
211
- const ${buildWrapper.name} = pickModule(require('${buildWrapper.path}'));
212
- const { initialize } = require('./initialize');` : `import initHandler from '${rootNode.path}';
147
+ async function buildLambdaIndex(rootNode, buildWrapper) {
148
+ return `import initHandler from '${rootNode.path}';
213
149
  import ${buildWrapper.name} from '${buildWrapper.path}';
214
- import { initialize } from './initialize';`}
150
+ import { initialize } from './initialize.js';
215
151
 
216
152
  const handlerInitializer = ${buildWrapper.name}(
217
153
  initHandler
@@ -220,80 +156,57 @@ const handlerInitializer = ${buildWrapper.name}(
220
156
  const handlerPromise = initialize()
221
157
  .then(handlerInitializer);
222
158
 
223
- ${options.modules === 'commonjs' ? 'module.exports = {}; module.exports.default = ' : 'export default '}function handler (req, res) {
159
+ export default function handler (req, res) {
224
160
  return handlerPromise
225
161
  .then(handler => handler(req, res));
226
162
  };
227
163
  `;
228
164
  }
229
-
230
- async function buildFinalLambda({
231
- compiler,
232
- log
233
- }, lambdaPath, whookConfig) {
234
- const entryPoint = `${lambdaPath}/main.js`;
235
- const {
236
- contents,
237
- mappings
238
- } = await compiler(entryPoint, whookConfig.compilerOptions);
239
- await Promise.all([ensureFileAsync({
240
- log
241
- }, `${lambdaPath}/index.js`, contents, 'utf-8'), mappings ? ensureFileAsync({
242
- log
243
- }, `${lambdaPath}/index.js.map`, mappings, 'utf-8') : Promise.resolve()]);
165
+ async function buildFinalLambda({ compiler, log }, lambdaPath, whookConfig) {
166
+ const entryPoint = `${lambdaPath}/main.js`;
167
+ const { contents, mappings } = await compiler(entryPoint, whookConfig.compilerOptions);
168
+ await Promise.all([
169
+ ensureFileAsync({ log }, `${lambdaPath}/index.js`, contents, 'utf-8'),
170
+ mappings
171
+ ? ensureFileAsync({ log }, `${lambdaPath}/index.js.map`, mappings, 'utf-8')
172
+ : Promise.resolve(),
173
+ ]);
244
174
  }
245
-
246
- async function copyStaticFiles({
247
- PROJECT_DIR,
248
- log
249
- }, lambdaPath, staticFiles = []) {
250
- await Promise.all(staticFiles.map(async staticFile => await copyFiles({
251
- log
252
- }, _path.default.join(PROJECT_DIR, 'node_modules', staticFile), _path.default.join(lambdaPath, 'node_modules', staticFile))));
175
+ async function copyStaticFiles({ PROJECT_DIR, log }, lambdaPath, staticFiles = []) {
176
+ await Promise.all(staticFiles.map(async (staticFile) => await copyFiles({ log }, path.join(PROJECT_DIR, 'node_modules', staticFile), path.join(lambdaPath, 'node_modules', staticFile))));
253
177
  }
254
-
255
- async function copyFiles({
256
- log
257
- }, source, destination) {
258
- let theError;
259
-
260
- try {
261
- await (0, _mkdirp.default)(destination);
262
- const data = await readFileAsync(source, 'utf-8');
263
- await ensureFileAsync({
264
- log
265
- }, destination, data, 'utf-8');
266
- } catch (err) {
267
- theError = err;
268
- }
269
-
270
- if (theError) {
271
- if ('EISDIR' !== theError.code) {
272
- throw theError;
178
+ async function copyFiles({ log }, source, destination) {
179
+ let theError;
180
+ try {
181
+ await mkdirp(destination);
182
+ const data = await readFileAsync(source, 'utf-8');
183
+ await ensureFileAsync({ log }, destination, data, 'utf-8');
184
+ }
185
+ catch (err) {
186
+ theError = err;
187
+ }
188
+ if (theError) {
189
+ if ('EISDIR' !== theError.code) {
190
+ throw theError;
191
+ }
192
+ await cprAsync(source, destination, {
193
+ overwrite: true,
194
+ });
273
195
  }
274
-
275
- await cprAsync(source, destination, {
276
- overwrite: true
277
- });
278
- }
279
196
  }
280
-
281
- async function ensureFileAsync({
282
- log
283
- }, path, content, encoding = 'utf-8') {
284
- try {
285
- const oldContent = await readFileAsync(path, encoding);
286
-
287
- if (oldContent === content) {
288
- log('debug', `Ignore unchanged file: "${path}".`);
289
- return;
197
+ async function ensureFileAsync({ log }, path, content, encoding = 'utf-8') {
198
+ try {
199
+ const oldContent = await readFileAsync(path, encoding);
200
+ if (oldContent === content) {
201
+ log('debug', `Ignore unchanged file: "${path}".`);
202
+ return;
203
+ }
204
+ }
205
+ catch (err) {
206
+ log('debug', `Write new file: "${path}".`);
207
+ return await writeFileAsync(path, content, encoding);
290
208
  }
291
- } catch (err) {
292
- log('debug', `Write new file: "${path}".`);
209
+ log('debug', `Write changed file: "${path}".`);
293
210
  return await writeFileAsync(path, content, encoding);
294
- }
295
-
296
- log('debug', `Write changed file: "${path}".`);
297
- return await writeFileAsync(path, content, encoding);
298
211
  }
299
212
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["DEFAULT_BUILD_PARALLELISM","readFileAsync","util","promisify","fs","readFile","writeFileAsync","writeFile","cprAsync","cpr","BUILD_DEFINITIONS","http","type","wrapper","name","path","join","__dirname","suffix","prepareBuildEnvironment","$","Knifecycle","register","ENV","log","time","delay","initInitializerBuilder","initBuildAutoloader","initCompiler","runBuild","aPrepareBuildEnvironment","handlerName","process","argv","NODE_ENV","BUILD_PARALLELISM","BUILD_OPTIONS","PROJECT_DIR","compiler","$autoload","API","buildInitializer","run","operations","filter","operation","sourceOperationId","operationId","length","processOperations","DEFAULT_BUILD_OPTIONS","destroy","err","console","error","stack","JSON","stringify","params","exit","operationsLeft","slice","Promise","all","map","buildAnyLambda","whookConfig","operationType","entryPoint","finalEntryPoint","buildDefinition","applyWrapper","require","default","rootNode","lambdaPath","finalHandlerInitializer","initializer","initializerContent","SPECIAL_PROPS","INJECT","indexContent","buildLambdaIndex","copyStaticFiles","staticFiles","ensureFileAsync","buildFinalLambda","YError","wrap","buildWrapper","options","modules","contents","mappings","compilerOptions","resolve","staticFile","copyFiles","source","destination","theError","data","code","overwrite","content","encoding","oldContent"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;;;;;;;AAdA;AA6BO,MAAMA,yBAAyB,GAAG,EAAlC;;;AAcP,MAAMC,aAAa,GAAGC,cAAKC,SAAL,CAAeC,YAAGC,QAAlB,CAAtB;;AAIA,MAAMC,cAAc,GAAGJ,cAAKC,SAAL,CAAeC,YAAGG,SAAlB,CAAvB;;AAKA,MAAMC,QAAQ,GAAGN,cAAKC,SAAL,CAAeM,YAAf,CAAjB;;AAMA,MAAMC,iBAOL,GAAG;AACFC,EAAAA,IAAI,EAAE;AACJC,IAAA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A3B;AACD;;AACDlF,EAAAA,GAAG,CAAC,OAAD,EAAW,wBAAuBT,IAAK,IAAvC,CAAH;AACA,SAAO,MAAMT,cAAc,CAACS,IAAD,EAAO0F,OAAP,EAAgBC,QAAhB,CAA3B;AACD","sourcesContent":["/* eslint global-require:0 */\nimport fs from 'fs';\nimport util from 'util';\nimport path from 'path';\nimport mkdirp from 'mkdirp';\nimport cpr from 'cpr';\nimport YError from 'yerror';\nimport Knifecycle, {\n SPECIAL_PROPS,\n constant,\n initInitializerBuilder,\n} from 'knifecycle';\nimport { DEFAULT_BUILD_OPTIONS, initCompiler } from '@whook/whook';\nimport initBuildAutoloader from './services/_autoload';\nimport {\n dereferenceOpenAPIOperations,\n getOpenAPIOperations,\n} from '@whook/http-router';\nimport type { Autoloader, Dependencies, BuildInitializer } from 'knifecycle';\nimport type {\n WhookOperation,\n WhookCompilerOptions,\n WhookCompilerService,\n} from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService } from 'common-services';\nimport type { CprOptions } from 'cpr';\nimport type { BuildOptions } from 'knifecycle/dist/build';\n\nexport const DEFAULT_BUILD_PARALLELISM = 10;\n\nexport type WhookBuildConfig = {\n BUILD_OPTIONS?: BuildOptions;\n BUILD_PARALLELISM?: number;\n};\nexport type WhookAPIOperationGCPFunctionConfig = {\n type?: 'http';\n sourceOperationId?: string;\n staticFiles?: string[];\n compilerOptions?: WhookCompilerOptions;\n suffix?: string;\n};\n\nconst readFileAsync = util.promisify(fs.readFile) as (\n path: string,\n encoding: string,\n) => Promise<string>;\nconst writeFileAsync = util.promisify(fs.writeFile) as (\n path: string,\n content: string,\n encoding: string,\n) => Promise<void>;\nconst cprAsync = util.promisify(cpr) as (\n source: string,\n destination: string,\n options: CprOptions,\n) => Promise<string[]>;\n\nconst BUILD_DEFINITIONS: Record<\n WhookAPIOperationGCPFunctionConfig['type'],\n {\n type: string;\n wrapper: { name: string; path: string };\n suffix?: string;\n }\n> = {\n http: {\n type: 'HTTP',\n wrapper: {\n name: 'wrapHandlerForGoogleHTTPFunction',\n path: path.join(__dirname, 'wrappers', 'googleHTTPFunction'),\n },\n suffix: 'Wrapped',\n },\n};\n\nexport async function prepareBuildEnvironment<\n T extends Knifecycle<Dependencies>,\n>($: T = new Knifecycle() as T): Promise<T> {\n $.register(\n constant('INITIALIZER_PATH_MAP', {\n ENV: '@whook/whook/dist/services/ProxyedENV',\n log: __dirname + '/services/log',\n time: 'common-services/dist/time',\n delay: 'common-services/dist/delay',\n }),\n );\n $.register(initInitializerBuilder);\n $.register(initBuildAutoloader);\n $.register(initCompiler);\n $.register(constant('PORT', 1337));\n $.register(constant('HOST', 'localhost'));\n\n return $;\n}\n\nexport async function runBuild(\n aPrepareBuildEnvironment: typeof prepareBuildEnvironment,\n): Promise<void> {\n try {\n const handlerName = process.argv[2];\n const $ = await aPrepareBuildEnvironment();\n const {\n NODE_ENV,\n BUILD_PARALLELISM,\n BUILD_OPTIONS,\n PROJECT_DIR,\n compiler,\n log,\n $autoload,\n API,\n buildInitializer,\n }: WhookBuildConfig & {\n NODE_ENV: string;\n PROJECT_DIR: string;\n compiler: WhookCompilerService;\n log: LogService;\n $autoload: Autoloader;\n API: OpenAPIV3.Document;\n buildInitializer: BuildInitializer;\n } = await $.run([\n 'NODE_ENV',\n '?BUILD_PARALLELISM',\n '?BUILD_OPTIONS',\n 'PROJECT_DIR',\n 'process',\n 'compiler',\n 'log',\n '$autoload',\n 'API',\n 'buildInitializer',\n ]);\n\n log('info', 'Environment initialized 🚀🌕');\n\n const operations = (\n await dereferenceOpenAPIOperations(\n API,\n getOpenAPIOperations<WhookAPIOperationGCPFunctionConfig>(API),\n )\n ).filter((operation) => {\n if (handlerName) {\n const sourceOperationId =\n operation['x-whook'] && operation['x-whook'].sourceOperationId;\n\n return (\n handlerName === operation.operationId ||\n handlerName === sourceOperationId\n );\n }\n return true;\n });\n\n log('warning', `${operations.length} operations to process.`);\n await processOperations(\n {\n NODE_ENV,\n BUILD_OPTIONS: BUILD_OPTIONS || DEFAULT_BUILD_OPTIONS,\n BUILD_PARALLELISM: BUILD_PARALLELISM || DEFAULT_BUILD_PARALLELISM,\n PROJECT_DIR,\n compiler,\n log,\n $autoload,\n buildInitializer,\n },\n operations,\n );\n await $.destroy();\n } catch (err) {\n // eslint-disable-next-line\n console.error(\n '💀 - Cannot launch the build:',\n err.stack,\n JSON.stringify(err.params, null, 2),\n );\n process.exit(1);\n }\n}\n\nasync function processOperations(\n {\n NODE_ENV,\n BUILD_PARALLELISM,\n BUILD_OPTIONS,\n PROJECT_DIR,\n compiler,\n log,\n $autoload,\n buildInitializer,\n }: {\n NODE_ENV: string;\n BUILD_PARALLELISM: number;\n BUILD_OPTIONS: BuildOptions;\n PROJECT_DIR: string;\n compiler: WhookCompilerService;\n log: LogService;\n $autoload: Autoloader;\n buildInitializer: BuildInitializer;\n },\n operations: WhookOperation<WhookAPIOperationGCPFunctionConfig>[],\n): Promise<void> {\n const operationsLeft = operations.slice(BUILD_PARALLELISM);\n\n await Promise.all(\n operations.slice(0, BUILD_PARALLELISM).map((operation) =>\n buildAnyLambda(\n {\n NODE_ENV,\n PROJECT_DIR,\n BUILD_OPTIONS,\n compiler,\n log,\n $autoload,\n buildInitializer,\n },\n operation,\n ),\n ),\n );\n\n if (operationsLeft.length) {\n log('info', operationsLeft.length, ' operations left.');\n return processOperations(\n {\n NODE_ENV,\n BUILD_PARALLELISM,\n BUILD_OPTIONS,\n PROJECT_DIR,\n compiler,\n log,\n $autoload,\n buildInitializer,\n },\n operationsLeft,\n );\n }\n log('info', 'No more operations.');\n}\n\nasync function buildAnyLambda(\n {\n NODE_ENV,\n PROJECT_DIR,\n BUILD_OPTIONS,\n compiler,\n log,\n $autoload,\n buildInitializer,\n }: {\n NODE_ENV: string;\n PROJECT_DIR: string;\n BUILD_OPTIONS: BuildOptions;\n compiler: WhookCompilerService;\n log: LogService;\n $autoload: Autoloader;\n buildInitializer: BuildInitializer;\n },\n operation: WhookOperation<WhookAPIOperationGCPFunctionConfig>,\n): Promise<void> {\n const { operationId } = operation;\n\n try {\n const whookConfig: WhookAPIOperationGCPFunctionConfig =\n operation['x-whook'] || {};\n const operationType = whookConfig.type || 'http';\n const sourceOperationId = whookConfig.sourceOperationId;\n const entryPoint = operationId;\n const finalEntryPoint =\n (sourceOperationId ? sourceOperationId : operationId) +\n ((operation['x-whook'] || {}).suffix || '');\n log('warning', `Building ${operationType} \"${finalEntryPoint}\"...`);\n const buildDefinition = BUILD_DEFINITIONS[operationType];\n // eslint-disable-next-line\n const applyWrapper = require(buildDefinition.wrapper.path).default;\n const rootNode = await $autoload(\n entryPoint + (buildDefinition.suffix || ''),\n );\n const lambdaPath = path.join(\n PROJECT_DIR,\n 'builds',\n NODE_ENV,\n finalEntryPoint,\n );\n const finalHandlerInitializer = applyWrapper(rootNode.initializer);\n\n const initializerContent = await buildInitializer(\n finalHandlerInitializer[SPECIAL_PROPS.INJECT].map((name) =>\n name === 'OPERATION_API'\n ? `OPERATION_API>OPERATION_API_${finalEntryPoint}`\n : name,\n ),\n BUILD_OPTIONS,\n );\n const indexContent = await buildLambdaIndex(\n rootNode,\n {\n name: buildDefinition.wrapper.name,\n path: buildDefinition.wrapper.path,\n },\n BUILD_OPTIONS,\n );\n\n await mkdirp(lambdaPath);\n await Promise.all([\n copyStaticFiles(\n { PROJECT_DIR, log },\n lambdaPath,\n whookConfig.staticFiles || [],\n ),\n ensureFileAsync(\n { log },\n path.join(lambdaPath, 'initialize.js'),\n initializerContent,\n ),\n ensureFileAsync({ log }, path.join(lambdaPath, 'main.js'), indexContent),\n ]);\n await buildFinalLambda({ compiler, log }, lambdaPath, whookConfig);\n } catch (err) {\n log('error', `Error building \"${operationId}\"...`);\n log('stack', err.stack);\n log('debug', JSON.stringify(err.params, null, 2));\n throw YError.wrap(err, 'E_LAMBDA_BUILD', operationId);\n }\n}\n\nasync function buildLambdaIndex(\n rootNode: { path: string },\n buildWrapper: { name: string; path: string },\n options: BuildOptions,\n): Promise<string> {\n return `${\n options.modules === 'commonjs'\n ? `const pickModule = (m) => { return m && m.default || m; }\nconst initHandler = pickModule(require('${rootNode.path}'));\nconst ${buildWrapper.name} = pickModule(require('${buildWrapper.path}'));\nconst { initialize } = require('./initialize');`\n : `import initHandler from '${rootNode.path}';\nimport ${buildWrapper.name} from '${buildWrapper.path}';\nimport { initialize } from './initialize';`\n }\n\nconst handlerInitializer = ${buildWrapper.name}(\n initHandler\n);\n\nconst handlerPromise = initialize()\n .then(handlerInitializer);\n\n${\n options.modules === 'commonjs'\n ? 'module.exports = {}; module.exports.default = '\n : 'export default '\n}function handler (req, res) {\n return handlerPromise\n .then(handler => handler(req, res));\n};\n`;\n}\n\nasync function buildFinalLambda(\n { compiler, log }: { compiler: WhookCompilerService; log: LogService },\n lambdaPath: string,\n whookConfig: WhookAPIOperationGCPFunctionConfig,\n): Promise<void> {\n const entryPoint = `${lambdaPath}/main.js`;\n const { contents, mappings } = await compiler(\n entryPoint,\n whookConfig.compilerOptions,\n );\n\n await Promise.all([\n ensureFileAsync({ log }, `${lambdaPath}/index.js`, contents, 'utf-8'),\n mappings\n ? ensureFileAsync(\n { log },\n `${lambdaPath}/index.js.map`,\n mappings,\n 'utf-8',\n )\n : Promise.resolve(),\n ]);\n}\n\nasync function copyStaticFiles(\n { PROJECT_DIR, log }: { PROJECT_DIR: string; log: LogService },\n lambdaPath: string,\n staticFiles: string[] = [],\n): Promise<void> {\n await Promise.all(\n staticFiles.map(\n async (staticFile) =>\n await copyFiles(\n { log },\n path.join(PROJECT_DIR, 'node_modules', staticFile),\n path.join(lambdaPath, 'node_modules', staticFile),\n ),\n ),\n );\n}\n\nasync function copyFiles(\n { log }: { log: LogService },\n source: string,\n destination: string,\n): Promise<void> {\n let theError;\n try {\n await mkdirp(destination);\n const data = await readFileAsync(source, 'utf-8');\n await ensureFileAsync({ log }, destination, data, 'utf-8');\n } catch (err) {\n theError = err;\n }\n if (theError) {\n if ('EISDIR' !== theError.code) {\n throw theError;\n }\n await cprAsync(source, destination, {\n overwrite: true,\n });\n }\n}\n\nasync function ensureFileAsync(\n { log }: { log: LogService },\n path: string,\n content: string,\n encoding = 'utf-8',\n): Promise<void> {\n try {\n const oldContent = await readFileAsync(path, encoding);\n\n if (oldContent === content) {\n log('debug', `Ignore unchanged file: \"${path}\".`);\n return;\n }\n } catch (err) {\n log('debug', `Write new file: \"${path}\".`);\n return await writeFileAsync(path, content, encoding);\n }\n log('debug', `Write changed file: \"${path}\".`);\n return await writeFileAsync(path, content, encoding);\n}\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EACL,UAAU,EACV,aAAa,EACb,QAAQ,EACR,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,mBAAmB,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAiB5B,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAa5C,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAG5B,CAAC;AACrB,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAIhC,CAAC;AACnB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAIb,CAAC;AAEvB,kDAAkD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EAAE;YAClC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;KACJ;AACH,CAAC;AAED,KAAK,UAAU,eAAe,CAC5B,EAAE,GAAG,EAAuB,EAC5B,IAAY,EACZ,OAAe,EACf,QAAQ,GAAG,OAAO;IAElB,IAAI;QACF,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEvD,IAAI,UAAU,KAAK,OAAO,EAAE;YAC1B,GAAG,CAAC,OAAO,EAAE,2BAA2B,IAAI,IAAI,CAAC,CAAC;YAClD,OAAO;SACR;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,GAAG,CAAC,OAAO,EAAE,oBAAoB,IAAI,IAAI,CAAC,CAAC;QAC3C,OAAO,MAAM,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;KACtD;IACD,GAAG,CAAC,OAAO,EAAE,wBAAwB,IAAI,IAAI,CAAC,CAAC;IAC/C,OAAO,MAAM,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC"}
@@ -1,39 +1,20 @@
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);
1
+ import { YError } from 'yerror';
2
+ import path from 'path';
3
+ export async function loadLambda({ PROJECT_DIR, log, }, target, operationId, type) {
4
+ const modulePath = path.join(PROJECT_DIR, 'builds', target, operationId, type + '.js');
5
+ log('debug', `⛏️ - Loading lambda module at path "${modulePath}".`);
6
+ try {
7
+ const module = await import(modulePath);
8
+ if (!module) {
9
+ throw new YError('E_MODULE_NOT_FOUND', module);
10
+ }
11
+ if (!module.default) {
12
+ throw new YError('E_LAMBDA_NOT_FOUND', module, Object.keys(module));
13
+ }
14
+ return module.default;
28
15
  }
29
-
30
- if (!module.default) {
31
- throw new _yerror.default('E_LAMBDA_NOT_FOUND', module, Object.keys(module));
16
+ catch (err) {
17
+ throw YError.wrap(err, 'E_LAMBDA_LOAD');
32
18
  }
33
-
34
- return module.default;
35
- } catch (err) {
36
- throw _yerror.default.wrap(err, 'E_LAMBDA_LOAD');
37
- }
38
19
  }
39
20
  //# sourceMappingURL=utils.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/libs/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,EACE,WAAW,EACX,GAAG,GAIJ,EACD,MAAc,EACd,WAAmB,EACnB,IAAY;IAEZ,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,WAAW,EACX,QAAQ,EACR,MAAM,EACN,WAAW,EACX,IAAI,GAAG,KAAK,CACb,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,uCAAuC,UAAU,IAAI,CAAC,CAAC;IAEpE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QAExC,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;SAChD;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YACnB,MAAM,IAAI,MAAM,CAAC,oBAAoB,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SACrE;QAED,OAAO,MAAM,CAAC,OAAO,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,CAAC,IAAI,CAAC,GAAY,EAAE,eAAe,CAAC,CAAC;KAClD;AACH,CAAC"}