Repository navigation
Expand file tree
/
Copy pathnodejs.tmpl
More file actions
95 lines (88 loc) · 5.32 KB
/
Copy pathnodejs.tmpl
File metadata and controls
95 lines (88 loc) · 5.32 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// AUTOMATICALLY GENERATED BY OPENFEATURE CLI, DO NOT EDIT.
import {
OpenFeature,
stringOrUndefined,
objectOrUndefined,
JsonValue,
} from "@openfeature/server-sdk";
import type {
EvaluationContext,
EvaluationDetails,
FlagEvaluationOptions,
} from "@openfeature/server-sdk";
// Flag key constants for programmatic access
export const FlagKeys = {
{{- range .Flagset.Flags }}
/** Flag key for {{ if .Description }}{{ .Description }}{{ else }}this flag{{ end }} */
{{ .Key | ToScreamingSnake }}: {{ .Key | Quote }},
{{- end }}
} as const;
export interface GeneratedClient {
{{- range .Flagset.Flags }}
/**
* {{ if .Description }}{{ .Description }}{{ else }}Feature flag{{ end }}
*
* **Details:**
* - flag key: `{{ .Key }}`
* - default value: `{{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue }}{{ end }}`
* - type: `{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}`
*
* Performs a flag evaluation that returns a {{ .Type | OpenFeatureType }}.
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
* @param {FlagEvaluationOptions} options Additional flag evaluation options
* @returns {Promise<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>} Flag evaluation response
*/
{{ .Key | ToCamel }}(context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>;
/**
* {{ if .Description }}{{ .Description }}{{ else }}Feature flag{{ end }}
*
* **Details:**
* - flag key: `{{ .Key }}`
* - default value: `{{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue }}{{ end }}`
* - type: `{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}`
*
* Performs a flag evaluation that a returns an evaluation details object.
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
* @param {FlagEvaluationOptions} options Additional flag evaluation options
* @returns {Promise<EvaluationDetails<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>>} Flag evaluation details response
*/
{{ .Key | ToCamel }}Details(context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>>;
{{ end -}}
}
/**
* A factory function that returns a generated client that not bound to a domain.
* It was generated using the OpenFeature CLI and is compatible with `@openfeature/server-sdk`.
*
* All domainless or unbound clients use the default provider set via {@link OpenFeature.setProvider}.
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations
* @returns {GeneratedClient} Generated OpenFeature Client
*/
export function getGeneratedClient(context?: EvaluationContext): GeneratedClient
/**
* A factory function that returns a domain-bound generated client that was
* created using the OpenFeature CLI and is compatible with the `@openfeature/server-sdk`.
*
* If there is already a provider bound to this domain via {@link OpenFeature.setProvider}, this provider will be used.
* Otherwise, the default provider is used until a provider is assigned to that domain.
* @param {string} domain An identifier which logically binds clients with providers
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations
* @returns {GeneratedClient} Generated OpenFeature Client
*/
export function getGeneratedClient(domain: string, context?: EvaluationContext): GeneratedClient
export function getGeneratedClient(domainOrContext?: string | EvaluationContext, contextOrUndefined?: EvaluationContext): GeneratedClient {
const domain = stringOrUndefined(domainOrContext);
const context =
objectOrUndefined<EvaluationContext>(domainOrContext) ??
objectOrUndefined<EvaluationContext>(contextOrUndefined);
const client = domain ? OpenFeature.getClient(domain, context) : OpenFeature.getClient(context)
return {
{{- range .Flagset.Flags }}
{{ .Key | ToCamel }}: (context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}> => {
return client.get{{ .Type | OpenFeatureType | ToPascal }}Value({{ .Key | Quote }}, {{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue | QuoteString }}{{ end }}, context, options);
},
{{ .Key | ToCamel }}Details: (context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<{{ if eq (.Type | OpenFeatureType) "object" }}JsonValue{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>> => {
return client.get{{ .Type | OpenFeatureType | ToPascal }}Details({{ .Key | Quote }}, {{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue | QuoteString }}{{ end }}, context, options);
},
{{ end -}}
{{ printf " " }}}
}