(base: any, key: string, type: 'object' | 'function')
| 357 | // decorates the base entity by calling plugin[key] |
| 358 | // for all the available plugins |
| 359 | function decorateEntity(base: any, key: string, type: 'object' | 'function') { |
| 360 | let decorated = base; |
| 361 | modules.forEach((plugin) => { |
| 362 | if (plugin[key]) { |
| 363 | let res; |
| 364 | try { |
| 365 | res = plugin[key](decorated); |
| 366 | } catch (e) { |
| 367 | notify('Plugin error!', `"${plugin._name}" when decorating ${key}`, {error: e}); |
| 368 | return; |
| 369 | } |
| 370 | if (res && (!type || typeof res === type)) { |
| 371 | decorated = res; |
| 372 | } else { |
| 373 | notify('Plugin error!', `"${plugin._name}": invalid return type for \`${key}\``); |
| 374 | } |
| 375 | } |
| 376 | }); |
| 377 | |
| 378 | return decorated; |
| 379 | } |
| 380 | |
| 381 | function decorateObject<T>(base: T, key: string): T { |
| 382 | return decorateEntity(base, key, 'object'); |
no test coverage detected