import type { Context } from "./context.ts"; export type FeatureValue = boolean | string | number; export type FeatureRule = FeatureValue | ((ctx: Context) => FeatureValue | Promise); export interface FeatureFlags { get(name: string, ctx: Context): Promise; enabled(name: string, ctx: Context): Promise; } export function defineFeatureFlags(rules: Record): 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; }, }; }