66 EventHandler ,
77 FlagValue ,
88 FlagValueType ,
9- Hook ,
109 HookContext ,
1110 JsonValue ,
1211 Logger ,
@@ -22,6 +21,7 @@ import { OpenFeature } from '../open-feature';
2221import { Provider } from '../provider' ;
2322import { InternalEventEmitter } from '../events/internal/internal-event-emitter' ;
2423import { Client } from './client' ;
24+ import { Hook } from '../hooks' ;
2525
2626type OpenFeatureClientOptions = {
2727 name ?: string ;
@@ -38,7 +38,7 @@ export class OpenFeatureClient implements Client {
3838 private readonly providerAccessor : ( ) => Provider ,
3939 private readonly emitterAccessor : ( ) => InternalEventEmitter ,
4040 private readonly globalLogger : ( ) => Logger ,
41- private readonly options : OpenFeatureClientOptions
41+ private readonly options : OpenFeatureClientOptions ,
4242 ) { }
4343
4444 get metadata ( ) : ClientMetadata {
@@ -76,12 +76,12 @@ export class OpenFeatureClient implements Client {
7676 return this ;
7777 }
7878
79- addHooks ( ...hooks : Hook < FlagValue > [ ] ) : this {
79+ addHooks ( ...hooks : Hook [ ] ) : this {
8080 this . _hooks = [ ...this . _hooks , ...hooks ] ;
8181 return this ;
8282 }
8383
84- getHooks ( ) : Hook < FlagValue > [ ] {
84+ getHooks ( ) : Hook [ ] {
8585 return this . _hooks ;
8686 }
8787
@@ -97,7 +97,7 @@ export class OpenFeatureClient implements Client {
9797 getBooleanDetails (
9898 flagKey : string ,
9999 defaultValue : boolean ,
100- options ?: FlagEvaluationOptions
100+ options ?: FlagEvaluationOptions ,
101101 ) : EvaluationDetails < boolean > {
102102 return this . evaluate < boolean > ( flagKey , this . _provider . resolveBooleanEvaluation , defaultValue , 'boolean' , options ) ;
103103 }
@@ -109,15 +109,15 @@ export class OpenFeatureClient implements Client {
109109 getStringDetails < T extends string = string > (
110110 flagKey : string ,
111111 defaultValue : T ,
112- options ?: FlagEvaluationOptions
112+ options ?: FlagEvaluationOptions ,
113113 ) : EvaluationDetails < T > {
114114 return this . evaluate < T > (
115115 flagKey ,
116116 // this isolates providers from our restricted string generic argument.
117117 this . _provider . resolveStringEvaluation as ( ) => EvaluationDetails < T > ,
118118 defaultValue ,
119119 'string' ,
120- options
120+ options ,
121121 ) ;
122122 }
123123
@@ -128,30 +128,30 @@ export class OpenFeatureClient implements Client {
128128 getNumberDetails < T extends number = number > (
129129 flagKey : string ,
130130 defaultValue : T ,
131- options ?: FlagEvaluationOptions
131+ options ?: FlagEvaluationOptions ,
132132 ) : EvaluationDetails < T > {
133133 return this . evaluate < T > (
134134 flagKey ,
135135 // this isolates providers from our restricted number generic argument.
136136 this . _provider . resolveNumberEvaluation as ( ) => EvaluationDetails < T > ,
137137 defaultValue ,
138138 'number' ,
139- options
139+ options ,
140140 ) ;
141141 }
142142
143143 getObjectValue < T extends JsonValue = JsonValue > (
144144 flagKey : string ,
145145 defaultValue : T ,
146- options ?: FlagEvaluationOptions
146+ options ?: FlagEvaluationOptions ,
147147 ) : T {
148148 return this . getObjectDetails ( flagKey , defaultValue , options ) . value ;
149149 }
150150
151151 getObjectDetails < T extends JsonValue = JsonValue > (
152152 flagKey : string ,
153153 defaultValue : T ,
154- options ?: FlagEvaluationOptions
154+ options ?: FlagEvaluationOptions ,
155155 ) : EvaluationDetails < T > {
156156 return this . evaluate < T > ( flagKey , this . _provider . resolveObjectEvaluation , defaultValue , 'object' , options ) ;
157157 }
@@ -161,7 +161,7 @@ export class OpenFeatureClient implements Client {
161161 resolver : ( flagKey : string , defaultValue : T , context : EvaluationContext , logger : Logger ) => ResolutionDetails < T > ,
162162 defaultValue : T ,
163163 flagType : FlagValueType ,
164- options : FlagEvaluationOptions = { }
164+ options : FlagEvaluationOptions = { } ,
165165 ) : EvaluationDetails < T > {
166166 // merge global, client, and evaluation context
167167
@@ -224,26 +224,19 @@ export class OpenFeatureClient implements Client {
224224 }
225225
226226 private beforeHooks ( hooks : Hook [ ] , hookContext : HookContext , options : FlagEvaluationOptions ) {
227+ Object . freeze ( hookContext ) ;
228+ Object . freeze ( hookContext . context ) ;
229+
227230 for ( const hook of hooks ) {
228- // freeze the hookContext
229- Object . freeze ( hookContext ) ;
230-
231- // use Object.assign to avoid modification of frozen hookContext
232- Object . assign ( hookContext . context , {
233- ...hookContext . context ,
234- ...hook ?. before ?.( hookContext , Object . freeze ( options . hookHints ) ) ,
235- } ) ;
231+ hook ?. before ?.( hookContext , Object . freeze ( options . hookHints ) ) ;
236232 }
237-
238- // after before hooks, freeze the EvaluationContext.
239- return Object . freeze ( hookContext . context ) ;
240233 }
241234
242235 private afterHooks (
243236 hooks : Hook [ ] ,
244237 hookContext : HookContext ,
245238 evaluationDetails : EvaluationDetails < FlagValue > ,
246- options : FlagEvaluationOptions
239+ options : FlagEvaluationOptions ,
247240 ) {
248241 // run "after" hooks sequentially
249242 for ( const hook of hooks ) {
0 commit comments