import { type ProtocolVersion } from '@midnightntwrk/wallet-sdk-abstractions'; import { type AnyVariant, type VersionedVariant } from './Variant.js'; /** * Builds a target {@link Variant} object from internal build state. * * @typeParam TTState The type of state that the variant will operate over. * @typeParam TPreviousState The type of state that the variant can migrate from. * @typeParam TConfiguration A type representing the configuration required by the variant. */ export interface VariantBuilder { /** * Builds the target variant object from the internal build state. * * @param configuration The configuration to use when building the target variant. * @returns An instance of {@link Variant} that operates over `TState`. */ build(configuration: TConfiguration): TVariant; } /** Base type that represents variant configuration. */ export type AnyBuilderConfiguration = object; /** A utility type that represents any {@link VariantBuilder}. */ export type AnyVariantBuilder = VariantBuilder; export type VariantOf = T extends VersionedVariantBuilder ? VariantOf : T extends VariantBuilder ? TVariant : never; export type VersionedVariantBuilder = Readonly<{ sinceVersion: ProtocolVersion.ProtocolVersion; variantBuilder: TBuilder; }>; export type VariantsOf = T extends [infer THead, ...infer TRest] ? [VariantOf, ...VariantsOf] : T extends [] ? [] : never; export type VersionedVariantsOf = T extends [infer THead, ...infer Rest] ? [VersionedVariant>, ...VersionedVariantsOf] : T extends [] ? [] : never; export type ConfigurationOf = T extends VariantBuilder ? Config : T extends VersionedVariantBuilder ? ConfigurationOf : never; /** A type that associates a {@link VariantBuilder} with a given version of the Midnight protocol. */ export type AnyVersionedVariantBuilder = VersionedVariantBuilder;