Skip to content

Commit 8fcc213

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

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
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` method or function, 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: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,59 +111,22 @@ 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 general address lifecycle concerns. A `provider hook` provides a mechanism for providers to register [`Hook`s](./04-hooks.md) to tap into that 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.
120+
> The provider interface **MAY** define a `provider hook` method or function, which can be optionally implemented in order to add `hook` instances to the client.
125121
126122
```typescript
127123
class MyProvider implements Provider {
128124
//...
129125

130-
// implementation of context transformer
131-
MyProviderContext transformContext(EvaluationContext context) {
132-
return new MyProviderContext(context.email, context.ip, context.httpMethod);
126+
List<Hook> providerHooks() {
127+
return [new MyProviderHook()];
133128
}
134129

135130
//...
136131
}
137132
```
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-
156-
//...
157-
158-
// context transformer signature
159-
T transformContext(EvaluationContext context);
160-
161-
//...
162-
163-
// flag resolution methods context parameter type corresponds to class-generic
164-
boolean resolveBooleanValue (string flagKey, boolean defaultValue, T transformedContext, EvaluationOptions options);
165-
166-
//...
167-
168-
}
169-
```

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)