UNPKG

@mos-connection/helper

Version:

Helper functions for the MOS-connection library

35 lines 1.77 kB
import { MosTypes, MosType, AnyXMLObject } from '@mos-connection/model'; import { AnyXMLValue } from './lib'; export declare function getParseMosTypes(strict: boolean): MosParseTypes; export type MosParseTypes = { [key in keyof MosTypes]: MosTypes[key] extends MosType<infer Serialized, infer Value, infer CreateValue> ? MosTypeParse<Serialized, Value, CreateValue | AnyXMLValue> : MosTypes[key]; } & { string: MosTypeParse<string, string, AnyXMLValue>; stringEnum: MosTypeParse<any, string, { enum: { [key: string]: string; }; value: AnyXMLValue; }>; number: MosTypeParse<number, number, AnyXMLValue>; }; interface MosTypeParse<Serialized, Value, CreateValue> extends Omit<MosType<Serialized, Value, CreateValue>, 'create'> { /** * Used to parse data that is optional. * If the data is missing, undefined is returned. */ createOptional: (anyValue: CreateValue, path: string) => Serialized | undefined; /** * Used to parse data that is required. * If in strict mode, the data must be present and parsable, otherwise an error is thrown. * If not in strict mode, a fallback value will be used. */ createRequired: (anyValue: CreateValue, path: string) => Serialized; } export declare function parseOptional<V, R>(parser: (value: V) => R, valueIsSingular: boolean, strict: boolean): (value: V | AnyXMLValue, path: string) => R | undefined; export declare function parseRequired<V, R>(parser: (value: V) => R, fallback: () => R, valueIsSingular: boolean, strict: boolean): (value: V | AnyXMLValue, path: string) => R; export declare function getXMLAttributes(obj: AnyXMLObject): { [key: string]: string; }; export {}; //# sourceMappingURL=parseMosTypes.d.ts.map