mirror of https://github.com/open-feature/cli.git
86 lines
4.4 KiB
Cheetah
86 lines
4.4 KiB
Cheetah
// AUTOMATICALLY GENERATED BY OPENFEATURE CLI, DO NOT EDIT.
|
|
import {
|
|
OpenFeature,
|
|
stringOrUndefined,
|
|
objectOrUndefined,
|
|
} from "@openfeature/server-sdk";
|
|
import type {
|
|
EvaluationContext,
|
|
EvaluationDetails,
|
|
FlagEvaluationOptions,
|
|
} from "@openfeature/server-sdk";
|
|
|
|
export interface GeneratedClient {
|
|
{{- range .Flagset.Flags }}
|
|
/**
|
|
* {{ .Description }}
|
|
*
|
|
* **Details:**
|
|
* - flag key: `{{ .Key }}`
|
|
* - default value: `{{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue }}{{ end }}`
|
|
* - type: `{{ .Type | OpenFeatureType }}`
|
|
*
|
|
* 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<{{ .Type | OpenFeatureType }}>} Flag evaluation response
|
|
*/
|
|
{{ .Key | ToCamel }}(context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<{{ .Type | OpenFeatureType }}>;
|
|
|
|
/**
|
|
* {{ .Description }}
|
|
*
|
|
* **Details:**
|
|
* - flag key: `{{ .Key }}`
|
|
* - default value: `{{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue }}{{ end }}`
|
|
* - type: `{{ .Type | OpenFeatureType }}`
|
|
*
|
|
* 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<{{ .Type | OpenFeatureType }}>>} Flag evaluation details response
|
|
*/
|
|
{{ .Key | ToCamel }}Details(context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<{{ .Type | OpenFeatureType }}>>;
|
|
{{ 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<{{ .Type | OpenFeatureType }}> => {
|
|
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<{{ .Type | OpenFeatureType }}>> => {
|
|
return client.get{{ .Type | OpenFeatureType | ToPascal }}Details({{ .Key | Quote }}, {{ if eq (.Type | OpenFeatureType) "object"}}{{ .DefaultValue | ToJSONString }}{{ else }}{{ .DefaultValue | QuoteString }}{{ end }}, context, options);
|
|
},
|
|
{{ end -}}
|
|
{{ printf " " }}}
|
|
} |