@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
26 lines (25 loc) • 1.96 kB
TypeScript
import { ToUPLC, UPLCTerm } from "@harmoniclabs/uplc";
import { IRTerm } from "../../IR/IRTerm.js";
import { ToIR } from "../../IR/interfaces/ToIR.js";
import { PType } from "../PType/index.js";
import { FromPType, GenericTermType, TermType, ToPType } from "../type_system/index.js";
import { Cloneable } from "../../utils/Cloneable.js";
import { CompilerOptions } from "../../IR/toUPLC/CompilerOptions.js";
export type UnTerm<T extends Term<PType>> = T extends Term<infer PT extends PType> ? PT : never;
export declare class Term<PT extends PType> implements ToUPLC, ToIR, Cloneable<Term<PT>> {
/**
* in most cases it will never be used
*
* it's solely purpose is to allow typescript to rise errors (at type level)
* when the type arguments don't match
*/
_pInstance?: PT;
get pInstance(): PT | undefined;
readonly type: FromPType<PT> | TermType;
readonly toUPLC: (deBruijnLevel?: bigint | number, config?: CompilerOptions) => UPLCTerm;
readonly toIR: (config?: CompilerOptions, deBruijnLevel?: bigint | number) => IRTerm;
readonly clone: () => Term<PT>;
constructor(type: FromPType<PT> | TermType | GenericTermType, _toIR: (config: CompilerOptions, dbn: bigint) => IRTerm, isConstant?: boolean);
}
export type ToTermArr<Ts extends TermType[]> = Ts extends [] ? [] & Term<PType>[] : Ts extends [infer T extends TermType] ? [Term<ToPType<T>>] & [Term<PType>] : Ts extends [infer T extends TermType, ...infer RestTs extends [TermType, ...TermType[]]] ? [Term<ToPType<T>>, ...ToTermArr<RestTs>] & [Term<PType>, ...Term<PType>[]] : never;
export type ToTermArrNonEmpty<Ts extends [TermType, ...TermType[]]> = Ts extends [] ? never & Term<PType>[] : Ts extends [infer T extends TermType] ? [Term<ToPType<T>>] & [Term<PType>] : Ts extends [infer T extends TermType, ...infer RestTs extends [TermType, ...TermType[]]] ? [Term<ToPType<T>>, ...ToTermArr<RestTs>] & [Term<PType>, ...Term<PType>[]] : never;