Skip to content

Commit 0b272d5

Browse files
author
Justin Abrahms
authored
Merge pull request #119 from open-feature/provider-hooks
Remove context transformers. Add provider hooks
2 parents 607e74b + 9bc54eb commit 0b272d5

File tree

3 files changed

+18
-67
lines changed

3 files changed

+18
-67
lines changed

specification.json

Lines changed: 4 additions & 19 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.",
270-
"RFC 2119 keyword": "MAY",
269+
"content": "The provider interface MUST define a `provider hook` mechanism which can be optionally implemented in order to add `hook` instances to the evaluation life-cycle.",
270+
"RFC 2119 keyword": "MUST",
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",
@@ -458,14 +443,14 @@
458443
{
459444
"id": "Requirement 4.4.1",
460445
"machine_id": "requirement_4_4_1",
461-
"content": "The API, Client and invocation MUST have a method for registering hooks which accepts `flag evaluation options`",
446+
"content": "The API, Client, Provider, and invocation MUST have a method for registering hooks.",
462447
"RFC 2119 keyword": "MUST",
463448
"children": []
464449
},
465450
{
466451
"id": "Requirement 4.4.2",
467452
"machine_id": "requirement_4_4_2",
468-
"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",
453+
"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",
469454
"RFC 2119 keyword": "MUST",
470455
"children": []
471456
},

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+
A `provider hook` exposes a mechanism for `providers` to register [`hooks`](./04-hooks.md) to tap into various stages of the flag evaluation lifecycle. As one example, feature flag management systems often need to transform the context structures the user provides.
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 **MUST** define a `provider hook` mechanism which can be optionally implemented in order to add `hook` instances to the evaluation life-cycle.
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ EvaluationContext | void before(HookContext, HookHints);
113113

114114
#### Requirement 4.4.1
115115

116-
> The API, Client and invocation **MUST** have a method for registering hooks which accepts `flag evaluation options`
116+
> The API, Client, Provider, and invocation **MUST** have a method for registering hooks.
117117
118118
```js
119119
OpenFeature.addHooks(new Hook1());
@@ -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)