import { type Scope, type SubscriptionRef } from 'effect'; import type { Effect } from 'effect/Effect'; import type { Stream } from 'effect/Stream'; import { Poly } from '@midnightntwrk/wallet-sdk-utilities'; import type { ProtocolVersion } from '@midnightntwrk/wallet-sdk-abstractions'; import { type WalletRuntimeError } from './WalletRuntimeError.js'; import type * as StateChange from './StateChange.js'; export interface VariantContext { stateRef: SubscriptionRef.SubscriptionRef; } /** * Encapsulates a variant of a wallet implementation. * * @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 TDomain The variant-specific functionality */ export type Variant> = Poly.WithTag & { start(context: VariantContext): Effect; migrateState(previousState: TPreviousState): Effect; }; export type RunningVariant = Poly.WithTag & { state: Stream, WalletRuntimeError>; }; /** A utility type that represents any {@link Variant}. */ export type AnyVariant = Variant; export type AnyRunningVariant = RunningVariant; export type RunningVariantOf = T extends VersionedVariant ? RunningVariantOf : T extends Variant ? Running : never; export type StateOf = T extends Variant ? S : T extends VersionedVariant ? StateOf : never; export type PreviousStateOf = T extends VersionedVariant ? PreviousStateOf : T extends Variant ? S : never; /** An array of {@link Variant} instances. */ export type AnyVariantArray = AnyVariant[]; /** A type that associates a {@link Variant} with a given version of the Midnight protocol. */ export type VersionedVariant = Readonly<{ sinceVersion: ProtocolVersion.ProtocolVersion; variant: T; }>; export type AnyVersionedVariant = VersionedVariant; /** * An ordered array of types that associates a {@link Variant} with a given version of the Midnight protocol. * * @remarks * The expected order of the variants will be ascending on `sinceVersion`. */ export type AnyVersionedVariantArray = AnyVersionedVariant[]; export type VariantTag = T extends VersionedVariant ? VariantTag : T extends Poly.WithTag ? Tag : never; export type VariantRecord = Variants extends [infer THead, ...infer TRest] ? { readonly [K in VariantTag]: THead; } & VariantRecord : Variants extends [] ? object : never; export declare const getVersionedVariantTag: (v: VersionedVariant) => VariantTag; export declare const makeVersionedRecord: (variants: Variants) => VariantRecord;