import * as jtv from "@mojotech/json-type-validation"; /** * Interface for companion objects of serializable types. Its main purpose is * to serialize and deserialize values between raw JSON and typed values. * * @typeparam T The template type. */ export interface Serializable { /** * @internal */ decoder: jtv.Decoder; /** * @internal Encodes T in expected shape for JSON API. */ encode: (t: T) => unknown; } /** * Companion objects for templates and interfaces, containing their choices. * * @typeparam T The template payload format or interface view. * @typeparam K The contract key type. * @typeparam I The template or interface id. */ export interface ContractTypeCompanion { templateId: I; templateIdWithPackageId: string; /** * @internal */ sdkVersion: "3.5.0"; /** * @internal */ decoder: jtv.Decoder; /** * @internal */ keyDecoder: jtv.Decoder; } /** * Interface for objects representing Daml templates. It is similar to the * `Template` type class in Daml. * * @typeparam T The template type. * @typeparam K The contract key type. * @typeparam I The template id type. * */ export interface Template extends ContractTypeCompanion, Serializable { /** * @internal */ keyEncode: (k: K) => unknown; Archive: Choice & ChoiceFrom>; } /** * A mixin for [[Template]] that provides the `toInterface` and * `unsafeFromInterface` contract ID conversion functions. * * Even templates that directly implement no interfaces implement this, because * this also permits conversion with interfaces that supply retroactive * implementations to this template. * * @typeparam T The template type. * @typeparam IfU The union of implemented interfaces, or `never` for templates * that directly implement no interface. */ export interface ToInterface { toInterface(ic: FromTemplate, cid: ContractId): ContractId; toInterface(ic: FromTemplate, cid: ContractId): ContractId; unsafeFromInterface(ic: FromTemplate, cid: ContractId): ContractId; unsafeFromInterface(ic: FromTemplate, cid: ContractId): ContractId; } declare const InterfaceBrand: unique symbol; /** * An interface type, for use with contract IDs. * * @typeparam IfId The interface ID as a constant string. */ export type Interface = { readonly [InterfaceBrand]: IfId; }; /** * Interface for objects representing Daml interfaces. */ export type InterfaceCompanion = ContractTypeCompanion; export type TemplateOrInterface = Template | InterfaceCompanion; declare const FromTemplateBrand: unique symbol; /** * A mixin for [[InterfaceCompanion]]. This supplies the basis * for the methods of [[ToInterface]]. * * Even interfaces that retroactively implement for no templates implement this, * because forward implementations still require this marker to work. * * @typeparam If The interface type. * @typeparam TX The intersection of template types this interface retroactively * implements, or `unknown` if there are none. */ export interface FromTemplate { readonly [FromTemplateBrand]: [If, TX]; } /** * Interface for objects representing Daml choices. * * @typeparam T The template type. * @typeparam K The contract key type. * @typeparam C The choice type. * @typeparam R The choice return type. * */ export interface Choice extends ChoiceFrom> { /** * @internal Returns a decoder to decode the choice arguments. * * Note: we never need to decode the choice arguments, as they are sent over * the API but not received. */ argumentDecoder: jtv.Decoder; /** * @internal */ argumentEncode: (c: C) => unknown; /** * @internal Returns a deocoder to decode the return value. */ resultDecoder: jtv.Decoder; /** * The choice name. */ choiceName: string; } /** * The origin companion that contained a [[Choice]]. * * @typeparam O The type of the template or interface of which * this [[Choice]] is a member. */ export interface ChoiceFrom { /** * Returns the template to which this choice belongs. */ readonly template: () => O; } /** * @internal */ export declare function assembleTemplate, IfU>(template: TC, ..._interfaces: FromTemplate[]): TC & ToInterface; /** * @internal */ export declare function assembleInterface(templateId: I, templatIdWithPackageId: string, decoderSource: () => Serializable, choices: C): InterfaceCompanion & T, unknown, I> & C; /** * @internal */ export declare const registerTemplate: (template: Template, packageSpecifiers?: string[]) => void; /** * @internal */ export declare const templateIdWithPackageId: (t: Template) => (pkgId: string) => string; /** * @internal */ export declare const lookupTemplate: (templateId: string) => Template; /** * @internal Turn a thunk into a memoized version of itself. The memoized thunk * invokes the original thunk only on its first invocation and caches the result * for later uses. We use this to implement a version of `jtv.lazy` with * memoization. */ export declare function memo(thunk: () => A): () => A; /** * @internal Variation of `jtv.lazy` which memoizes the computed decoder on its * first invocation. */ export declare function lazyMemo(mkDecoder: () => jtv.Decoder): jtv.Decoder; /** * The counterpart of Daml's `()` type. */ export interface Unit { } /** * Companion object of the [[Unit]] type. */ export declare const Unit: Serializable; /** * The counterpart of Daml's `Bool` type. */ export type Bool = boolean; /** * Companion object of the [[Bool]] type. */ export declare const Bool: Serializable; /** * The counterpart of Daml's `Int` type. * * We represent `Int`s as string in order to avoid a loss of precision. */ export type Int = string; /** * Companion object of the [[Int]] type. */ export declare const Int: Serializable; /** * The counterpart of Daml's `Numeric` type. * * We represent `Numeric`s as string in order to avoid a loss of precision. The string must match * the regular expression `-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?`. */ export type Numeric = string; /** * The counterpart of Daml's `Decimal` type. * * In Daml, Decimal's are the same as Numeric with precision 10. * */ export type Decimal = Numeric; /** * Companion function of the [[Numeric]] type. */ export declare const Numeric: (_: number) => Serializable; /** * Companion object of the [[Decimal]] type. */ export declare const Decimal: Serializable; /** * The counterpart of Daml's `Text` type. */ export type Text = string; /** * Companion object of the [[Text]] type. */ export declare const Text: Serializable; /** * The counterpart of Daml's `Time` type. * * We represent `Times`s as strings with format `YYYY-MM-DDThh:mm:ss[.ssssss]Z`. */ export type Time = string; /** * Companion object of the [[Time]] type. */ export declare const Time: Serializable