serde-ts/dist/option.d.ts

80 lines
3.1 KiB
TypeScript

import { IDeserializer } from './de';
import { ISerializer } from './ser';
import { CaseConvention } from './case';
import { Nullable } from './utils';
export interface RenameOptions {
serialize?: string;
deserialize?: string;
}
export interface RenameAllOptions {
serialize?: CaseConvention;
deserialize?: CaseConvention;
}
export interface ContainerOptions {
rename?: RenameOptions | string;
renameAll?: RenameAllOptions | CaseConvention;
default?: () => any;
denyUnknownFields?: boolean;
tag?: string;
untagged?: boolean;
}
interface Predicate {
<T>(value: T): boolean;
}
export interface SkipOptions {
serialize?: Predicate | boolean;
deserialize?: Predicate | boolean;
}
type CustomSerializer = <T, U, S extends ISerializer<T>>(value: U, serializer: S) => T;
type CustomDeserializer = <T, D extends IDeserializer>(deserializer: D) => T;
export interface CustomSerdeOptions {
serialize?: CustomSerializer;
deserialize?: CustomDeserializer;
}
export interface PropertyOptions {
alias?: string | string[];
default?: () => any;
flatten?: boolean;
rename?: RenameOptions | string;
skip?: SkipOptions | Predicate | boolean;
with?: CustomSerdeOptions;
}
export declare const Stage: Readonly<{
readonly Serialize: 0;
readonly Deserialize: 1;
}>;
export declare class PropertyMap extends Map<string, PropertyOptions> {
private readonly options;
private readonly aliases;
constructor(options: SerdeOptions, iterable?: Iterable<any>);
private setAliasesFromOptions;
set(key: string, value: PropertyOptions): this;
addAlias(alias: string | Iterable<string>, key: string): void;
getFieldFromAlias(alias: string): string | undefined;
private buildAliasMap;
}
export type Stage = typeof Stage[keyof typeof Stage];
export declare class SerdeOptions {
readonly target: Nullable<any>;
readonly container: ContainerOptions;
readonly properties: PropertyMap;
constructor(target: any, container?: ContainerOptions, properties?: PropertyMap);
private getClassName;
getSerializedClassName(defaultName?: string): string | undefined;
getDeserializedClassName(defaultName?: string): string | undefined;
getCaseConvention(stage: Stage): CaseConvention | undefined;
applyCaseConvention(stage: Stage, property: string): string;
getPropertyRename(stage: Stage, property: string): string | undefined;
getSerializationPropertyName(property: string): string;
getNameFromAlias(alias: string): string | undefined;
getDeserializationPropertyName(property: string): string;
shouldSkip(stage: Stage, property: string, value: any): boolean;
shouldSkipSerialization(property: string, value: any): boolean;
shouldSkipDeserialization(property: string, value: any): boolean;
defaultFor(property: string): any;
hasCustomSerializer(property: string): boolean;
hasCustomDeserializer(property: string): boolean;
useCustomSerializer<T, U, S extends ISerializer<U>>(serializer: S, property: string, value: T): Nullable<U>;
useCustomDeserializer<T, U, D extends IDeserializer>(deserializer: D, property: string): Nullable<U>;
}
export {};