Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

TypeScript · 27 lines · 766 B · at 2e2b18f

export type Rule = { attribute: string; op: "eq" | "in" | "gte"; value: unknown };export type Flag = {  key: string;  enabled: boolean;  rules: Rule[];  rolloutPercent: number;  defaultValue: boolean;};export type User = { id: string; attributes: Record<string, unknown> };export type FlagErrorInfo = { kind: "invalid_rollout" } | { kind: "invalid_rule"; index: number };export class FlagError extends Error {  declare readonly kind: FlagErrorInfo["kind"];  declare readonly index?: number;  constructor(info: FlagErrorInfo) {    super(info.kind);    Object.assign(this, info);  }}/** Throws FlagError when the flag config is invalid. */export function evaluateFlag(flag: Flag, user: User, hash: (s: string) => number): boolean {  // TODO}