diff --git a/packages/api-redundancy/package.json b/packages/api-redundancy/package.json index abccce2..a1843ec 100644 --- a/packages/api-redundancy/package.json +++ b/packages/api-redundancy/package.json @@ -1,7 +1,7 @@ { "name": "@iconify/api-redundancy", "description": "Reusable redundancy library for API queries", - "version": "1.1.0", + "version": "1.1.1", "author": "Vjacheslav Trushkin", "license": "MIT", "main": "dist/index.js", diff --git a/packages/api-redundancy/src/index.ts b/packages/api-redundancy/src/index.ts index 3b6eb1b..572c533 100644 --- a/packages/api-redundancy/src/index.ts +++ b/packages/api-redundancy/src/index.ts @@ -54,38 +54,15 @@ export interface Redundancy { cleanup: () => void; } -/** - * Set configuration - */ -function setConfig(config: Partial): RedundancyConfig { - if ( - typeof config !== 'object' || - typeof (config as RedundancyConfig).resources !== 'object' || - !((config as RedundancyConfig).resources instanceof Array) || - !(config as RedundancyConfig).resources.length - ) { - throw new Error('Invalid Reduncancy configuration'); - } - - const newConfig = Object.create(null); - let key: keyof RedundancyConfig; - for (key in defaultConfig) { - if (config[key] !== void 0) { - newConfig[key] = config[key]; - } else { - newConfig[key] = defaultConfig[key]; - } - } - - return newConfig; -} - /** * Redundancy instance */ export function initRedundancy(cfg: Partial): Redundancy { // Configuration - const config: RedundancyConfig = setConfig(cfg); + const config: RedundancyConfig = { + ...defaultConfig, + ...cfg, + }; // List of queries let queries: GetQueryStatus[] = []; @@ -127,10 +104,11 @@ export function initRedundancy(cfg: Partial): Redundancy { * Find instance */ function find(callback: FilterCallback): GetQueryStatus | null { - const result = queries.find((value) => { - return callback(value); - }); - return result !== void 0 ? result : null; + return ( + queries.find((value) => { + return callback(value); + }) || null + ); } // Create and return functions