release: WRNexusJS 0.3.0
This commit is contained in:
1 parent
13dfa31d19
commit
07d8fb59d6
145 files changed
+9664
-3881
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import type { Context } from "./context.ts";
|
||||
|
||||
export type FeatureValue = boolean | string | number;
|
||||
export type FeatureRule = FeatureValue | ((ctx: Context) => FeatureValue | Promise<FeatureValue>);
|
||||
|
||||
export interface FeatureFlags {
|
||||
get(name: string, ctx: Context): Promise<FeatureValue | undefined>;
|
||||
enabled(name: string, ctx: Context): Promise<boolean>;
|
||||
}
|
||||
|
||||
export function defineFeatureFlags(rules: Record<string, FeatureRule>): FeatureFlags {
|
||||
return {
|
||||
async get(name, ctx) {
|
||||
const rule = rules[name];
|
||||
return typeof rule === "function" ? rule(ctx) : rule;
|
||||
},
|
||||
async enabled(name, ctx) {
|
||||
return (await this.get(name, ctx)) === true;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user