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GAAI,KAAK,QAAQ,GAAK,CACpB,IAEE,KAAK,QAAQ,GAAI,gBAEV,KAAK,QAAQ,UACb,KAAK,IAAI,YAAY,EAC9B,CAAE,MAAO,GAEP,OADA,QAAQ,OAAO,MAAM,uCAAwC,EAAI,IAC1D,CACT,CACA,OAAO,CACT,CACA,OAAO,CACT,EAEF,QAAQ,OAAS,OACjB,QAAQ,OAAS,QAEjB,MAAM,mBACJ,WAAA,CAAY,GACV,IAAK,EACH,MAAM,aAAa,4BAA6B,eAElD,MAAM,EAAO,KACb,KAAK,IAAM,CACT,YAAa,CAAC,EAEd,IAAA,CAAK,KAAa,GAAO,EAGzB,WAAY,EAAK,WAAW,KAAK,GACjC,aAAc,EAAK,aAAa,KAAK,GACrC,YAAa,EAAK,YAAY,KAAK,IAGrC,KAAK,KAAO,IAAI,QAAQ,EAAY,KAAK,IAC3C,CAGA,UAAA,CAAW,EAAQ,GACjB,OAAO,KAAK,KAAK,KAAK,EAAQ,EAChC,CACA,YAAA,CAAa,GACX,OAAO,KAAK,KAAK,OAAO,EAC1B,CACA,WAAA,CAAY,GACV,OAAO,KAAK,KAAK,MAAM,EACzB,EAEF,mBAAmB,UAAY,IAC7B,IAAI,EAEG,MAAM,aAAa,uBAAwB,kBADhD,QAAQ,OAAS,CACgD,EAGrE,mBAAmB,UAAY,IAC7B,IAAI,EAEG,MAAM,aAAa,uBAAwB,mBADhD,QAAQ,OAAS,CACiD,EAGtE,OAAO,QAAU,QACjB,OAAO,QAAQ,QAAU,QACzB,OAAO,QAAQ,mBAAqB","file":"/npm/@jabuco/use-manager@1.5.0/manager.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@jabuco/use-manager@1.5.0/manager.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const use = require(\"use-plugin\");\nconst ManagerError = (message, name = \"ERROR\") => {\n  const err = new Error();\n  err.message = message;\n  err.name = name;\n  return err;\n};\n\nclass Manager {\n  constructor(pluginPath = \"\", api, autoInit = true) {\n    this.pluginPath = pluginPath;\n    this.loader = use({\n      module: Manager.module,\n      prefix: pluginPath\n    });\n    this.autoInit = autoInit;\n    this.plugins = {};\n    this.cache = {};\n    const that = this;\n    const _api = {\n      contributed: {},\n      call(endpoint, ...args) {\n        if (this[endpoint]) {\n          const pluginApi = {\n            get api() {\n              return that.api;\n            }\n          };\n          return this[endpoint].call(pluginApi, ...args);\n        } else {\n          throw ManagerError(\n            `application api does not expose enpoint ${endpoint}`,\n            \"ERRNOEXPOINT\"\n          );\n        }\n      }\n    };\n    // create api if undefined\n    this.api = api || _api;\n    // add api properties\n    this.api.contributed = _api.contributed;\n    this.api.call = _api.call;\n  }\n  check(id) {\n    return this.load(id, undefined, false, true);\n  }\n  load(id, args = {}, autoInit = this.autoInit, check = false) {\n    // check if plugin is cached and try to load it\n    if (!this.cache[id]) {\n      // plugin is not yet cached\n      if (!check) Manager.logger.debug(\"trying to load uncached plugin %s\", id);\n      let descriptor;\n      try {\n        try {\n          descriptor = this.loader(id, args, () => {});\n          if (check) return true;\n          const plugin = this._load(descriptor, autoInit);\n          this.plugins[descriptor.name] = plugin;\n          // add plugin to cache\n          this.cache[descriptor.name] = plugin;\n          this.api.contributed[descriptor.name] = {\n            api: plugin.api,\n            call: plugin.call\n          };\n        } catch (error) {\n          if (!check) {\n            Manager.logger.error(\n              \"plugin init failed! [%s]\",\n              (descriptor && descriptor.name) || id,\n              error\n            );\n          }\n          return false;\n        }\n      } catch (error) {\n        Manager.logger.error(\n          \"plugin init failed! [%s]\",\n          (descriptor && descriptor.name) || id,\n          error\n        );\n        return false;\n      }\n    } else {\n      // plugin is in cache load it from there\n      if (!check) Manager.logger.debug(\"trying to load cached plugin %s\", id);\n      try {\n        const descriptor = this.cache[id].descriptor;\n        // even if plugin is cached run initialization\n        // to avoid unitialized plugins caused by unload calls\n        const plugin = this._load(descriptor, true);\n        this.plugins[descriptor.name] = plugin;\n        this.api.contributed[descriptor.name] = {\n          api: plugin.api,\n          call: plugin.call\n        };\n      } catch (error) {\n        if (!check) {\n          Manager.logger.error(\n            \"plugin init failed! [%s]\",\n            (descriptor && descriptor.name) || id,\n            error\n          );\n        }\n        return false;\n      }\n    }\n\n    return true;\n  }\n  _load(descriptor, autoInit) {\n    const { load, unload, meta, api } = descriptor.init();\n    let loadSuccess = true;\n    const that = this;\n    if (autoInit) {\n      try {\n        const api = {\n          get api() {\n            return that.api;\n          },\n          get info() {\n            return descriptor;\n          }\n        };\n        load.call(api, descriptor.options || {});\n      } catch (error) {\n        Manager.logger.error(error);\n        loadSuccess = false;\n      }\n    }\n    return {\n      load: load || (() => {}),\n      unload: unload || (() => {}),\n      api,\n      descriptor,\n      loadSuccess,\n      autoInit: this.autoInit,\n      meta,\n      call(endpoint, ...args) {\n        if (\n          meta.contributes &&\n          [...meta.contributes].indexOf(endpoint) > -1 &&\n          api[endpoint]\n        ) {\n          const pluginApi = {\n            get api() {\n              return that.api;\n            },\n            get info() {\n              return this;\n            }\n          };\n          return api[endpoint].call(pluginApi, ...args);\n        } else {\n          throw ManagerError(\n            `plugin ${descriptor.name} does not expose enpoint ${endpoint}`,\n            \"ERRNOEXPOINT\"\n          );\n        }\n      }\n    };\n  }\n  unload(id) {\n    if (this.plugins[id]) {\n      try {\n        // call unload on plugin instance\n        this.plugins[id].unload();\n        // delete api references\n        delete this.plugins[id];\n        delete this.api.contributed[id];\n      } catch (error) {\n        Manager.logger.error(\"[manager] plugin unload failed! [%s]\", id, error);\n        return false;\n      }\n      return true;\n    }\n    return false;\n  }\n}\nManager.module = module;\nManager.logger = console;\n\nclass ManagerApplication {\n  constructor(pluginPath) {\n    if (!pluginPath) {\n      throw ManagerError(\"pluginPath is not defined\", \"ERRNOEXPATH\");\n    }\n    const that = this;\n    this.api = {\n      contributed: {},\n      // api stub (mostly for intellisense)\n      call(endpoint, ...args) {},\n\n      // application api\n      loadPlugin: that.loadPlugin.bind(that),\n      unloadPlugin: that.unloadPlugin.bind(that),\n      checkPlugin: that.checkPlugin.bind(that)\n    };\n    // init api with plugins\n    this.host = new Manager(pluginPath, this.api);\n  }\n\n  // api\n  loadPlugin(plugin, options) {\n    return this.host.load(plugin, options);\n  }\n  unloadPlugin(plugin) {\n    return this.host.unload(plugin);\n  }\n  checkPlugin(plugin) {\n    return this.host.check(plugin);\n  }\n}\nManagerApplication.setLogger = logger => {\n  if (logger) {\n    Manager.logger = logger;\n  } else throw ManagerError(\"logger is undefined!\", \"ERRNOLOGGERARG\");\n};\n\nManagerApplication.setModule = module => {\n  if (module) {\n    Manager.module = module;\n  } else throw ManagerError(\"module is undefined!\", \"ERRNOMODULERARG\");\n};\n\nmodule.exports = Manager;\nmodule.exports.Manager = Manager;\nmodule.exports.ManagerApplication = ManagerApplication;\n"]}