@interopio/gateway
Version:
[](https://www.npmjs.com/package/@interopio/gateway)
8 lines (7 loc) • 2.31 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/metrics/publisher/custom.ts"],
"sourcesContent": ["import type { PublishCommand } from './types.ts';\nimport type { Logger } from '../../../types/logging/api';\nimport { Metrics } from '../../../types/metrics/api';\nimport type { CustomPublisherConfig } from '../../../types/metrics/publisher/custom';\n\nexport const name = 'custom';\n\nexport async function create(config: CustomPublisherConfig, logger: Logger) {\n const {file, configuration} = config.publisher;\n let factory: (cfg: unknown, log: Logger) => Metrics.Publisher;\n try {\n factory = await import(file);\n if (typeof factory['default'] === 'function') {\n factory = factory['default'] as typeof factory;\n }\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: 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,GAKO,IAAMG,EAAO,SAEpB,eAAsBD,EAAOG,EAA+BC,EAAgB,CACxE,GAAM,CAAC,KAAAC,EAAM,cAAAC,CAAa,EAAIH,EAAO,UACjCI,EACJ,GAAI,CACAA,EAAU,MAAM,OAAOF,GACnB,OAAOE,EAAQ,SAAe,aAC9BA,EAAUA,EAAQ,QAE1B,OACOC,EAAG,CACNJ,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,EAA+BJ,EAAQE,EAAKC,CAAG,EAErD,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"]
}