{"version":3,"sources":["../../../packages/core/data/resource-cache.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAChC;;;;;OAKG;IACH,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,aAAa;IACtB,OAAc,OAAO,SAAS;IAC9B,OAAc,aAAa,SAAe;IAC1C,OAAc,OAAO,SAAa;IAElC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAE3E;;;;;OAKG;IACI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAAG,IAAI;IAUrE;;;;;;OAMG;IACI,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC;IAc3C;;;;;;OAMG;IACI,UAAU,CAAC,CAAC,KAAK,CAAC;CAI5B","file":"resource-cache.d.ts","sourcesContent":["import { LogLevel } from '../diagnostics/log-level';\r\nimport { LogRecord } from '../diagnostics/log-record';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { Strings } from '../generated/strings';\r\n\r\n/**\r\n * The interface of resource query.\r\n */\r\nexport interface ResourceCacheFind<T> {\r\n    /**\r\n     * Find a resource by id.\r\n     *\r\n     * @param id the identification.\r\n     * @return T the found object if any.\r\n     */\r\n    find: (id: string) => T;\r\n}\r\n\r\n/**\r\n * Resource service to find a resource data by type and id.\r\n */\r\nexport class ResourceCache {\r\n    public static svgType = 'svg';\r\n    public static svgInlineType = 'svgInline';\r\n    public static strings = 'strings';\r\n\r\n    private static collection: { [type: string]: ResourceCacheFind<any> } = {};\r\n\r\n    /**\r\n     * Register resource service to a specific type.\r\n     *\r\n     * @param type the type name of resource.\r\n     * @param resource the resource data with find() interface.\r\n     */\r\n    public register(type: string, resource: ResourceCacheFind<any>): void {\r\n        const existingResource = ResourceCache.collection[type];\r\n        if (existingResource) {\r\n            const mergedResource = MsftSme.deepAssign(existingResource, resource);\r\n            ResourceCache.collection[type] = mergedResource;\r\n        } else {\r\n            ResourceCache.collection[type] = resource;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Find a resource for the type and id.\r\n     *\r\n     * @param type the type name of resource.\r\n     * @param id the identification.\r\n     * @return T the found object id any.\r\n     */\r\n    public find<T>(type: string, id: string): T {\r\n        const resource = ResourceCache.collection[type];\r\n        if (!resource) {\r\n            Logging.log(<LogRecord>{\r\n                source: 'ResourceCache',\r\n                level: LogLevel.Warning,\r\n                message: MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ResourceCacheUnableFind.message.format(type)\r\n            });\r\n            return null;\r\n        }\r\n\r\n        return <T>resource.find(id);\r\n    }\r\n\r\n    /**\r\n     * @deprecated - Use MsftSme.getStrings<T>() instead.\r\n     *\r\n     * Gets the localized strings initialized by localization manager. The LocalizationManager should have\r\n     * been used to get the localized strings. This can also be achieved by calling SmeEnvironment.initEnvironment().\r\n     * @returns an object containing all the localized strings, or null if noe localized strings have been fetched yet\r\n     */\r\n    public getStrings<T>(): T {\r\n        const global: MsftSme.SMEWindow = <any>window;\r\n        return global.MsftSme.Resources && <T>global.MsftSme.Resources.strings;\r\n    }\r\n}\r\n"]}