@interopio/gateway
Version:
[](https://www.npmjs.com/package/@interopio/gateway)
8 lines (7 loc) • 2.21 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/metrics/publisher/custom.ts"],
"sourcesContent": ["import {PublishCommand} from './types.js';\nimport {IOGateway} from '../../../gateway';\n\nexport const name = 'custom';\nexport async function create(config: IOGateway.CustomMetricsPublisherConfig, logger: IOGateway.Logging.Logger) {\n const {file, configuration} = config.publisher;\n let factory: (cfg: unknown, log: IOGateway.Logging.Logger) => IOGateway.Metrics.Publisher;\n try {\n factory = await import(file);\n if (typeof factory['default'] === 'function') {\n factory = factory['default'] as typeof factory;\n }\n } catch (e) {\n logger.error(`failed to load publisher from ${file}`, e);\n return;\n }\n const cfg = configuration;\n const log = (typeof logger['child'] === 'function') ? logger['child'](`[${file}]`) : logger;\n const publisher: IOGateway.Metrics.Publisher = factory(cfg, log);\n\n return async(m: PublishCommand) => {\n if (m === 'start') {\n if (publisher.startup) {\n return await publisher.startup(config.context);\n }\n } else if (m === 'stop') {\n if (publisher.cleanup) {\n return publisher.cleanup ?? (() => {});\n }\n } else {\n return await publisher.function(m);\n }\n };\n}\n"],
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,SAAAC,IAAA,eAAAC,EAAAJ,GAGO,IAAMG,EAAO,SACpB,eAAsBD,EAAOG,EAAgDC,EAAkC,CAC3G,GAAM,CAAC,KAAAC,EAAM,cAAAC,CAAa,EAAIH,EAAO,UACjCI,EACJ,GAAI,CACAA,EAAU,MAAM,OAAOF,GACnB,OAAOE,EAAQ,SAAe,aAC9BA,EAAUA,EAAQ,QAE1B,OAASC,EAAG,CACRJ,EAAO,MAAM,iCAAiCC,CAAI,GAAIG,CAAC,EACvD,MACJ,CACA,IAAMC,EAAMH,EACNI,EAAO,OAAON,EAAO,OAAa,WAAcA,EAAO,MAAS,IAAIC,CAAI,GAAG,EAAID,EAC/EO,EAAyCJ,EAAQE,EAAKC,CAAG,EAE/D,MAAO,OAAME,GAAsB,CAC/B,GAAIA,IAAM,SACN,GAAID,EAAU,QACV,OAAO,MAAMA,EAAU,QAAQR,EAAO,OAAO,UAE1CS,IAAM,QACb,GAAID,EAAU,QACV,OAAOA,EAAU,UAAY,IAAM,CAAC,OAGxC,QAAO,MAAMA,EAAU,SAASC,CAAC,CAEzC,CACJ",
"names": ["custom_exports", "__export", "create", "name", "__toCommonJS", "config", "logger", "file", "configuration", "factory", "e", "cfg", "log", "publisher", "m"]
}