From 9b35ab94e1dfa5cfef82b6e8c7c3ea3a6e5a0a79 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 30 Jun 2026 12:59:35 +0100 Subject: [PATCH] Add initial `ActionState` type --- src/action-common.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/action-common.ts diff --git a/src/action-common.ts b/src/action-common.ts new file mode 100644 index 000000000..5af58f08b --- /dev/null +++ b/src/action-common.ts @@ -0,0 +1,37 @@ +import { Env } from "./environment"; +import { FeatureEnablement } from "./feature-flags"; +import { Logger } from "./logging"; + +/** Describes different state features that an Action may have. */ +export interface FeatureState { + Logger: { + /** The logger that is in use. */ + logger: Logger; + }; + Env: { + /** Information about environment variables. */ + env: Env; + }; + FeatureFlags: { + /** Information about enabled feature flags. */ + features: FeatureEnablement; + }; +} + +/** Identifies a type of state an Action may have. */ +export type StateFeature = keyof FeatureState; + +/** Constructs the union of all state types identifies by `Fs`. */ +export type FieldsOf = Fs extends [ + infer Head extends StateFeature, +] + ? FeatureState[Head] + : Fs extends [ + infer Head extends StateFeature, + ...infer Tail extends StateFeature[], + ] + ? FeatureState[Head] & FieldsOf + : never; + +/** Describes the state of an Action that has access to the state corresponding to `Fs`. */ +export type ActionState = FieldsOf;