1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const awsHooks = require("./hook-aws");
|
4 | const gcpHooks = require("./hook-gcp");
|
5 | const hooksDic = new Map();
|
6 |
|
7 | const hookObjByType = {
|
8 | 'aws': awsHooks,
|
9 | 'gcp': gcpHooks
|
10 | };
|
11 | for (const k of Object.keys(hookObjByType)) {
|
12 | const type = k;
|
13 | const fnByName = hookObjByType[type];
|
14 | for (const key in fnByName) {
|
15 |
|
16 | const name = key;
|
17 | const fn = fnByName[name];
|
18 | registerHook(type, name, fn);
|
19 | }
|
20 | }
|
21 |
|
22 | async function callHook(realm, name, ...args) {
|
23 | const fn = getHook(realm.type, name);
|
24 | if (fn) {
|
25 | return fn(realm, ...args);
|
26 | }
|
27 | }
|
28 | exports.callHook = callHook;
|
29 | function getHook(type, name) {
|
30 | const fnDic = hooksDic.get(type);
|
31 | return (fnDic) ? fnDic.get(name) : undefined;
|
32 | }
|
33 | function registerHook(type, name, fn) {
|
34 | let fnDic = hooksDic.get(type);
|
35 | if (fnDic == null) {
|
36 | fnDic = new Map();
|
37 | hooksDic.set(type, fnDic);
|
38 | }
|
39 | fnDic.set(name, fn);
|
40 | }
|