UNPKG

1.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const awsHooks = require("./hook-aws");
4const gcpHooks = require("./hook-gcp");
5const hooksDic = new Map();
6//#region ---------- Initialize the Hook Registry ----------
7const hookObjByType = {
8 'aws': awsHooks,
9 'gcp': gcpHooks
10};
11for (const k of Object.keys(hookObjByType)) {
12 const type = k; // Note: might have a better way to get types from hookObjByType
13 const fnByName = hookObjByType[type];
14 for (const key in fnByName) {
15 // TODO: need some validations
16 const name = key;
17 const fn = fnByName[name];
18 registerHook(type, name, fn);
19 }
20}
21//#endregion ---------- /Initialize the Hook Registry ----------
22async function callHook(realm, name, ...args) {
23 const fn = getHook(realm.type, name);
24 if (fn) {
25 return fn(realm, ...args);
26 }
27}
28exports.callHook = callHook;
29function getHook(type, name) {
30 const fnDic = hooksDic.get(type);
31 return (fnDic) ? fnDic.get(name) : undefined;
32}
33function 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}