@@ -13,10 +13,10 @@ import type {
1313 ProviderMetadata ,
1414 ResolutionDetails ,
1515 TrackingEventDetails ,
16- BaseEvaluationStrategy ,
1716 ProviderResolutionResult ,
1817 ProviderEntryInput ,
1918 RegisteredProvider ,
19+ BaseEvaluationStrategy ,
2020} from '@openfeature/core' ;
2121import {
2222 DefaultLogger ,
@@ -29,8 +29,10 @@ import {
2929 StatusTracker ,
3030} from '@openfeature/core' ;
3131import type { Provider } from '../provider' ;
32+ import { ProviderStatus } from '../provider' ;
3233import type { Hook } from '../../hooks' ;
3334import { OpenFeatureEventEmitter } from '../../events/open-feature-event-emitter' ;
35+ import { ProviderEvents } from '../../events' ;
3436import { HookExecutor } from './hook-executor' ;
3537
3638export class MultiProvider implements Provider {
@@ -43,15 +45,21 @@ export class MultiProvider implements Provider {
4345
4446 metadata : ProviderMetadata ;
4547
46- providerEntries : RegisteredProvider [ ] = [ ] ;
47- private providerEntriesByName : Record < string , RegisteredProvider > = { } ;
48+ providerEntries : RegisteredProvider < Provider > [ ] = [ ] ;
49+ private providerEntriesByName : Record < string , RegisteredProvider < Provider > > = { } ;
4850
4951 private hookExecutor : HookExecutor ;
50- private statusTracker = new StatusTracker ( this . events ) ;
52+ private statusTracker = new StatusTracker <
53+ ( typeof ProviderEvents ) [ keyof typeof ProviderEvents ] ,
54+ ProviderStatus ,
55+ Provider
56+ > ( this . events , ProviderStatus , ProviderEvents ) ;
5157
5258 constructor (
53- readonly constructorProviders : ProviderEntryInput [ ] ,
54- private readonly evaluationStrategy : BaseEvaluationStrategy = new FirstMatchStrategy ( ) ,
59+ readonly constructorProviders : ProviderEntryInput < Provider > [ ] ,
60+ private readonly evaluationStrategy : BaseEvaluationStrategy < ProviderStatus , Provider > = new FirstMatchStrategy (
61+ ProviderStatus ,
62+ ) ,
5563 private readonly logger : Logger = new DefaultLogger ( ) ,
5664 ) {
5765 this . hookExecutor = new HookExecutor ( this . logger ) ;
@@ -68,7 +76,7 @@ export class MultiProvider implements Provider {
6876 } ;
6977 }
7078
71- private registerProviders ( constructorProviders : ProviderEntryInput [ ] ) {
79+ private registerProviders ( constructorProviders : ProviderEntryInput < Provider > [ ] ) {
7280 const providersByName : Record < string , Provider [ ] > = { } ;
7381
7482 for ( const constructorProvider of constructorProviders ) {
@@ -155,7 +163,7 @@ export class MultiProvider implements Provider {
155163 throw new GeneralError ( 'Hook context not available for evaluation' ) ;
156164 }
157165
158- const tasks : Promise < [ boolean , ProviderResolutionResult < T > | null ] > [ ] = [ ] ;
166+ const tasks : Promise < [ boolean , ProviderResolutionResult < T , ProviderStatus , Provider > | null ] > [ ] = [ ] ;
159167
160168 for ( const providerEntry of this . providerEntries ) {
161169 const task = this . evaluateProviderEntry (
@@ -181,7 +189,7 @@ export class MultiProvider implements Provider {
181189 const results = await Promise . all ( tasks ) ;
182190 const resolutions = results
183191 . map ( ( [ , resolution ] ) => resolution )
184- . filter ( ( r ) : r is ProviderResolutionResult < T > => Boolean ( r ) ) ;
192+ . filter ( ( r ) : r is ProviderResolutionResult < T , ProviderStatus , Provider > => Boolean ( r ) ) ;
185193
186194 const finalResult = this . evaluationStrategy . determineFinalResult ( { flagKey, flagType } , context , resolutions ) ;
187195
@@ -200,17 +208,17 @@ export class MultiProvider implements Provider {
200208 flagKey : string ,
201209 flagType : FlagValueType ,
202210 defaultValue : T ,
203- providerEntry : RegisteredProvider ,
211+ providerEntry : RegisteredProvider < Provider > ,
204212 hookContext : HookContext ,
205213 hookHints : HookHints ,
206214 context : EvaluationContext ,
207- ) : Promise < [ boolean , ProviderResolutionResult < T > | null ] > {
215+ ) : Promise < [ boolean , ProviderResolutionResult < T , ProviderStatus , Provider > | null ] > {
208216 let evaluationResult : ResolutionDetails < T > | undefined = undefined ;
209217 const provider = providerEntry . provider ;
210218 const strategyContext = {
211219 flagKey,
212220 flagType,
213- provider,
221+ provider : provider as Provider ,
214222 providerName : providerEntry . name ,
215223 providerStatus : this . statusTracker . providerStatus ( providerEntry . name ) ,
216224 } ;
@@ -219,19 +227,19 @@ export class MultiProvider implements Provider {
219227 return [ true , null ] ;
220228 }
221229
222- let resolution : ProviderResolutionResult < T > ;
230+ let resolution : ProviderResolutionResult < T , ProviderStatus , Provider > ;
223231
224232 try {
225233 evaluationResult = await this . evaluateProviderAndHooks ( flagKey , defaultValue , provider , hookContext , hookHints ) ;
226234 resolution = {
227235 details : evaluationResult ,
228- provider : provider ,
236+ provider : provider as Provider ,
229237 providerName : providerEntry . name ,
230238 } ;
231239 } catch ( error : unknown ) {
232240 resolution = {
233241 thrownError : error ,
234- provider : provider ,
242+ provider : provider as Provider ,
235243 providerName : providerEntry . name ,
236244 } ;
237245 }
@@ -322,7 +330,7 @@ export class MultiProvider implements Provider {
322330 }
323331
324332 const strategyContext = {
325- provider : providerEntry . provider ,
333+ provider : providerEntry . provider as Provider ,
326334 providerName : providerEntry . name ,
327335 providerStatus : this . statusTracker . providerStatus ( providerEntry . name ) ,
328336 } ;
0 commit comments