-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathhook-flag-query.ts
57 lines (45 loc) · 1.14 KB
/
hook-flag-query.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type {
EvaluationDetails,
FlagValue} from '@openfeature/web-sdk';
import {
StandardResolutionReasons
} from '@openfeature/web-sdk';
import type { FlagQuery } from '../query';
// FlagQuery implementation, do not export
export class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {
constructor(private _details: EvaluationDetails<T>) {}
get details() {
return this._details;
}
get value() {
return this._details?.value;
}
get variant() {
return this._details.variant;
}
get flagMetadata() {
return this._details.flagMetadata;
}
get reason() {
return this._details.reason;
}
get isError() {
return !!this._details?.errorCode || this._details.reason == StandardResolutionReasons.ERROR;
}
get errorCode() {
return this._details?.errorCode;
}
get errorMessage() {
return this._details?.errorMessage;
}
get isAuthoritative() {
return (
!this.isError &&
this._details.reason != StandardResolutionReasons.STALE &&
this._details.reason != StandardResolutionReasons.DISABLED
);
}
get type() {
return typeof this._details.value;
}
}