Skip to content

Commit aebcd5f

Browse files
author
Justin Abrahms
committed
Remove context transformers. Add provider hooks
Signed-off-by: Justin Abrahms <[email protected]>
1 parent 8c24a8d commit aebcd5f

File tree

3 files changed

+15
-64
lines changed

3 files changed

+15
-64
lines changed

specification.json

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,25 +266,10 @@
266266
{
267267
"id": "Requirement 2.10",
268268
"machine_id": "requirement_2_10",
269-
"content": "The provider interface MAY define a `context transformer` method or function, which can be optionally implemented in order to transform the `evaluation context` prior to flag value resolution.",
269+
"content": "The provider interface MAY define a `provider hook` mechanism which can be optionally implemented in order to add `hook` instances to the client.",
270270
"RFC 2119 keyword": "MAY",
271271
"children": []
272272
},
273-
{
274-
"id": "Condition 2.11",
275-
"machine_id": "condition_2_11",
276-
"content": "The implementation language supports generics (or an equivalent feature).",
277-
"RFC 2119 keyword": null,
278-
"children": [
279-
{
280-
"id": "Conditional Requirement 2.11.1",
281-
"machine_id": "conditional_requirement_2_11_1",
282-
"content": "If the implementation includes a `context transformer`, the provider SHOULD accept a generic argument (or use an equivalent language feature) indicating the type of the transformed context. If such type information is supplied, more accurate type information can be supplied in the flag resolution methods.",
283-
"RFC 2119 keyword": "SHOULD",
284-
"children": []
285-
}
286-
]
287-
},
288273
{
289274
"id": "Requirement 3.1.1",
290275
"machine_id": "requirement_3_1_1",
@@ -451,7 +436,7 @@
451436
{
452437
"id": "Requirement 4.4.2",
453438
"machine_id": "requirement_4_4_2",
454-
"content": "Hooks MUST be evaluated in the following order: - before: API, Client, Invocation - after: Invocation, Client, API - error (if applicable): Invocation, Client, API - finally: Invocation, Client, API",
439+
"content": "Hooks MUST be evaluated in the following order: - before: API, Client, Invocation, Provider - after: Provider, Invocation, Client, API - error (if applicable): Provider, Invocation, Client, API - finally: Provider, Invocation, Client, API",
455440
"RFC 2119 keyword": "MUST",
456441
"children": []
457442
},

specification/sections/02-providers.md

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -111,59 +111,25 @@ ResolutionDetails<number> resolveNumberValue(string flagKey, number defaultValue
111111
ResolutionDetails<MyStruct> resolveStructureValue(string flagKey, MyStruct defaultValue, context: EvaluationContext, options: FlagEvaluationOptions);
112112
```
113113

114-
#### Context Transformation
114+
#### Provider hooks
115115

116-
Feature flag management systems often define structures representing arbitrary contextual data pertaining to the runtime, user, or application. The context transformer defines a simple interface to transform the OpenFeature `evaluation context` to such a structure, mapping values appropriately.
117-
118-
See [evaluation context](./03-evaluation-context.md).
116+
Feature flag management systems often need to transform the context structures the user provides or generally address lifecycle concerns. A `provider hook` exposes a mechanism for providers to register [`Hooks`](./04-hooks.md) to tap into various stages of the flag evaluation lifecycle.
119117

120118
##### Requirement 2.10
121119

122-
> The provider interface **MAY** define a `context transformer` method or function, which can be optionally implemented in order to transform the `evaluation context` prior to flag value resolution.
123-
124-
The OpenFeature `client` might apply the transformer function before passing the returned value (the `transformed context`) to the provider resolution methods, thus allowing the provider implementation to avoid implementing and calling such transformation logic repeatedly in flag value resolution methods.
125-
126-
```typescript
127-
class MyProvider implements Provider {
128-
//...
129-
130-
// implementation of context transformer
131-
MyProviderContext transformContext(EvaluationContext context) {
132-
return new MyProviderContext(context.email, context.ip, context.httpMethod);
133-
}
120+
> The provider interface **MAY** define a `provider hook` mechanism which can be optionally implemented in order to add `hook` instances to the client.
134121
135-
//...
136-
}
137122
```
138-
139-
See [evaluation context](./03-evaluation-context.md), [flag evaluation](./01-flag-evaluation.md#flag-evaluation).
140-
141-
##### Condition 2.11
142-
143-
> The implementation language supports generics (or an equivalent feature).
144-
145-
###### Conditional Requirement 2.11.1
146-
147-
> If the implementation includes a `context transformer`, the provider **SHOULD** accept a generic argument (or use an equivalent language feature) indicating the type of the transformed context.
148-
>
149-
> If such type information is supplied, more accurate type information can be supplied in the flag resolution methods.
150-
151-
```typescript
152-
// an example implementation in a language supporting interfaces, classes, and generics
153-
// T represents a generic argument for the type of the transformed context
154-
interface Provider<T> {
155-
123+
class MyProvider implements Provider {
156124
//...
157125
158-
// context transformer signature
159-
T transformContext(EvaluationContext context);
160-
161-
//...
126+
private readonly hooks: Hook[] = [new MyProviderHook()];
162127
163-
// flag resolution methods context parameter type corresponds to class-generic
164-
boolean resolveBooleanValue (string flagKey, boolean defaultValue, T transformedContext, EvaluationOptions options);
128+
// ..or alternatively..
129+
getProviderHooks(): Hook[] {
130+
return [new MyProviderHook()];
131+
}
165132
166133
//...
167-
168134
}
169135
```

specification/sections/04-hooks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ client.getValue('my-flag', 'defaultValue', new Hook3());
132132

133133
> Hooks **MUST** be evaluated in the following order:
134134
>
135-
> - before: API, Client, Invocation
136-
> - after: Invocation, Client, API
137-
> - error (if applicable): Invocation, Client, API
138-
> - finally: Invocation, Client, API
135+
> - before: API, Client, Invocation, Provider
136+
> - after: Provider, Invocation, Client, API
137+
> - error (if applicable): Provider, Invocation, Client, API
138+
> - finally: Provider, Invocation, Client, API
139139

140140
#### Requirement 4.4.3
141141

0 commit comments

Comments
 (0)