UNPKG

@lifi/compose-spec

Version:

Public wire-format types and schemas for Compose flows

25 lines (21 loc) 761 B
import type { Precondition } from './flow.js'; export type MaterialiserMetadata = | { readonly kind: 'exact'; readonly amount: bigint } | { readonly kind: 'exact-native'; readonly amount: bigint } | { readonly kind: 'runtime' }; export interface MaterialiserResolution { readonly meta: MaterialiserMetadata; readonly preconditions: readonly Precondition[]; } export const foldMaterialiserMetadata = <R>( meta: MaterialiserMetadata, cases: { readonly exact: (amount: bigint) => R; readonly exactNative: (amount: bigint) => R; readonly runtime: () => R; } ): R => { if (meta.kind === 'exact') return cases.exact(meta.amount); if (meta.kind === 'exact-native') return cases.exactNative(meta.amount); return cases.runtime(); };