{"version":3,"file":"pluginCache.mjs","sources":["../../../../src/services/dataSource/pluginCache.ts"],"sourcesContent":["import { type DataSourceApi } from '@grafana/data';\n\nconst cache = new Map<string, DataSourceApi>();\nconst runtimeCache = new Map<string, DataSourceApi>();\n\nexport function getCachedPlugin(uid: string): DataSourceApi | undefined {\n  return cache.get(uid);\n}\n\nexport function setCachedPlugin(uid: string, instance: DataSourceApi): void {\n  cache.set(uid, instance);\n}\n\n/** Write a runtime-registered plugin instance. Runtime entries survive {@link clearPluginCache}. */\nexport function setRuntimePlugin(uid: string, instance: DataSourceApi): void {\n  runtimeCache.set(uid, instance);\n  cache.set(uid, instance);\n}\n\n/**\n * Clear all non-runtime plugin instances. Runtime entries are preserved,\n * matching the behaviour of the legacy `DatasourceSrv.init()` which reset\n * `this.datasources` then re-added runtime sources.\n */\nexport function clearPluginCache(): void {\n  for (const uid of cache.keys()) {\n    if (!runtimeCache.has(uid)) {\n      cache.delete(uid);\n    }\n  }\n}\n\n/**\n * Test helper — resets all module state. Should only be called from tests.\n *\n * @internal\n */\nexport function _resetForTests(): void {\n  if (process.env.NODE_ENV !== 'test') {\n    throw new Error('_resetForTests must only be called from tests');\n  }\n  cache.clear();\n  runtimeCache.clear();\n}\n"],"names":[],"mappings":";AAEA,MAAM,KAAA,uBAAY,GAAA,EAA2B;AAC7C,MAAM,YAAA,uBAAmB,GAAA,EAA2B;AAE7C,SAAS,gBAAgB,GAAA,EAAwC;AACtE,EAAA,OAAO,KAAA,CAAM,IAAI,GAAG,CAAA;AACtB;AAEO,SAAS,eAAA,CAAgB,KAAa,QAAA,EAA+B;AAC1E,EAAA,KAAA,CAAM,GAAA,CAAI,KAAK,QAAQ,CAAA;AACzB;AAGO,SAAS,gBAAA,CAAiB,KAAa,QAAA,EAA+B;AAC3E,EAAA,YAAA,CAAa,GAAA,CAAI,KAAK,QAAQ,CAAA;AAC9B,EAAA,KAAA,CAAM,GAAA,CAAI,KAAK,QAAQ,CAAA;AACzB;AAOO,SAAS,gBAAA,GAAyB;AACvC,EAAA,KAAA,MAAW,GAAA,IAAO,KAAA,CAAM,IAAA,EAAK,EAAG;AAC9B,IAAA,IAAI,CAAC,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA,EAAG;AAC1B,MAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,IAClB;AAAA,EACF;AACF;AAOO,SAAS,cAAA,GAAuB;AACrC,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,MAAA,EAAQ;AACnC,IAAA,MAAM,IAAI,MAAM,+CAA+C,CAAA;AAAA,EACjE;AACA,EAAA,KAAA,CAAM,KAAA,EAAM;AACZ,EAAA,YAAA,CAAa,KAAA,EAAM;AACrB;;;;"}