UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

17 lines (16 loc) 2.98 kB
import type { PType } from "../PType/index.js"; import type { PLam, PInt, PBool, PByteString, PString, PUnit, PPair, PList, PAlias } from "../PTypes/index.js"; import { UtilityTermOf } from "./std/UtilityTerms/addUtilityForType.js"; import { Term } from "../Term/index.js"; import { TermType, ToPType, GenericTermType, Methods } from "../type_system/index.js"; import { ByteString } from "@harmoniclabs/bytestring"; import { Pair } from "@harmoniclabs/pair"; type _TsFunctionSatisfying<KnownArgs extends Term<PType>[], POut extends PType> = POut extends PLam<infer POutIn extends PType, infer POutOut extends PType> ? (_TsFunctionSatisfying<[...KnownArgs, UtilityTermOf<POutIn | PAlias<POutIn, Methods>>], POutOut>) : (...args: KnownArgs) => Term<POut>; export type TsFunctionSatisfying<PIn extends PType, POut extends PType> = _TsFunctionSatisfying<[UtilityTermOf<PIn>], POut>; export type PAliasPermutations<PT extends PType> = (PT extends PAlias<infer PReal extends PType, any> ? PAliasPermutations<PReal> : PT extends PPair<infer PFst extends PType, infer PSnd extends PType> ? (PAliasPermutations<PFst> extends infer PermFst extends PType ? (PAliasPermutations<PSnd> extends infer PermSnd extends PType ? (PPair<PFst, PSnd> | PPair<PermFst, PSnd> | PPair<PFst, PermSnd> | PPair<PermFst, PermSnd> | PAlias<PPair<PFst, PSnd>, Methods> | PAlias<PPair<PermFst, PSnd>, Methods> | PAlias<PPair<PFst, PermSnd>, Methods> | PAlias<PPair<PermFst, PermSnd>, Methods>) : never) : never) : PT extends PList<infer PElems extends PType> ? (PAliasPermutations<PElems> extends infer PermElems extends PType ? (PList<PermElems> | PAlias<PermElems, Methods>) : never) : PT extends PLam<infer PFst extends PType, infer PSnd extends PType> ? (PAliasPermutations<PFst> extends infer PermFst extends PType ? (PAliasPermutations<PSnd> extends infer PermSnd extends PType ? (PLam<PFst, PSnd> | PLam<PermFst, PSnd> | PLam<PFst, PermSnd> | PLam<PermFst, PermSnd> | PAlias<PLam<PFst, PSnd>, Methods> | PAlias<PLam<PermFst, PSnd>, Methods> | PAlias<PLam<PFst, PermSnd>, Methods> | PAlias<PLam<PermFst, PermSnd>, Methods>) : never) : never) : (PAlias<PT, Methods> | PT)); export type PappArg<PIn extends PType> = (PIn extends PAlias<infer PAliased extends PType, infer _> ? PappArg<PAliased> : PIn extends PInt ? bigint | number : PIn extends PBool ? boolean : PIn extends PByteString ? ByteString | Uint8Array | string : PIn extends PString ? string : PIn extends PUnit ? undefined | null : PIn extends PPair<infer PFst extends PType, infer PSnd extends PType> ? Pair<PappArg<PFst>, PappArg<PSnd>> | { fst: PappArg<PFst>; snd: PappArg<PSnd>; } | [PappArg<PFst>, PappArg<PSnd>] : PIn extends PLam<infer PIn extends PType, infer POut extends PType> ? TsFunctionSatisfying<PIn, POut> : Term<PIn>) | Term<PIn> | Term<PAliasPermutations<PIn>>; export declare function pappArgToTerm<ArgT extends TermType>(arg: PappArg<ToPType<ArgT>>, mustExtend?: GenericTermType): UtilityTermOf<ToPType<ArgT>>; export {};