@digitalasset/daml-ledger
Version:
DAML Ledger API Node.js bindings
74 lines (73 loc) • 2.61 kB
TypeScript
export declare type ValidationError = TypeError | MissingKey | UnexpectedKey | MissingTypeTag | UnexpectedTypeTag | InvalidIntegerString;
export interface TypeError {
errorType: 'type-error';
expectedType: string;
actualType: string;
}
export interface MissingKey {
errorType: 'missing-key';
expectedKey: string;
expectedType: string;
}
export interface UnexpectedKey {
errorType: 'unexpected-key';
key: string;
}
export interface MissingTypeTag {
errorType: 'missing-type-tag';
expectedTypeTags: string[];
}
export interface UnexpectedTypeTag {
errorType: 'unexpected-type-tag';
expectedTypeTags: string[];
actualTypeTag: string;
}
export interface InvalidIntegerString {
errorType: 'invalid-integer-string';
actualValue: string;
}
export interface ValidationTree {
errors: ValidationError[];
children: Record<string, ValidationTree>;
}
export declare function isValid(tree: ValidationTree): boolean;
export interface Validation {
type: string;
validate(value: any): ValidationTree;
validate(value: any, key: string, validation: ValidationTree): ValidationTree;
}
export interface UnionValidation<Tag extends string, A extends {
[_ in Tag]: string;
}> extends Validation {
tag: Tag;
values(): {
[_ in A[Tag]]: Validation;
};
}
export interface ObjectValidation<A extends object> extends Validation {
required(): RequiredFieldsValidators<A>;
optional(): OptionalFieldsValidators<A>;
}
export declare const noFields: () => {};
export declare function init(key?: string, validation?: ValidationTree): ValidationTree;
export declare function typeOf(value: any): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'null' | 'object' | 'function' | 'array';
/**
* Extracts required keys as a string type union
*/
export declare type RequiredKeys<T> = {
[K in keyof T]: {} extends Pick<T, K> ? never : K;
} extends {
[_ in keyof T]: infer U;
} ? {} extends U ? never : U : never;
/**
* Extracts optional keys as a string type union
*/
export declare type OptionalKeys<T> = {
[K in keyof T]: T extends Record<K, T[K]> ? never : K;
} extends {
[_ in keyof T]: infer U;
} ? {} extends U ? never : U : never;
export declare type RequiredFields<K extends object, V> = Record<RequiredKeys<K>, V>;
export declare type RequiredFieldsValidators<K extends object> = RequiredFields<K, Validation>;
export declare type OptionalFields<K extends object, V> = Record<OptionalKeys<K>, V>;
export declare type OptionalFieldsValidators<K extends object> = OptionalFields<K, Validation>;