serde-ts/dist/options.d.ts
2025-05-18 20:05:52 -05:00

63 lines
2.2 KiB
TypeScript

import { CaseConvention } from './case';
import { Deserializer } from './de';
import { Serializer } from './ser';
import { Registry } from './registry';
export interface RenameOptions {
serialize?: string;
deserialize?: string;
}
export interface RenameAllOptions {
serialize?: CaseConvention;
deserialize?: CaseConvention;
}
export interface ContainerOptions {
default?: () => any;
denyUnknownFields?: boolean;
expecting?: string;
rename?: RenameOptions | string;
renameAll?: RenameAllOptions | CaseConvention;
registry?: Registry;
tag?: string;
content?: string;
untagged?: boolean;
}
export interface ConditionalSkipOptions {
if: (value: any) => boolean;
}
export interface SkipOptions {
serializing?: ConditionalSkipOptions | boolean;
deserializing?: ConditionalSkipOptions | boolean;
}
export type CustomSerializer = <T, V, S extends Serializer<T>>(value: V, serializer: S) => T;
export type CustomDeserializer = <T, D extends Deserializer>(deserializer: D) => T;
export interface PropertyOptions {
alias?: string;
default?: () => any;
flatten?: boolean;
rename?: RenameOptions | string;
skip?: SkipOptions | ConditionalSkipOptions | boolean;
}
export declare const Stage: Readonly<{
readonly Serialize: 0;
readonly Deserialize: 1;
}>;
export type Stage = typeof Stage[keyof typeof Stage];
export declare class SerdeOptions {
private readonly target;
readonly options: ContainerOptions;
readonly properties: Map<string, PropertyOptions>;
get registry(): Registry;
constructor(target: any, options?: ContainerOptions, properties?: Map<string, PropertyOptions>);
static from(target: any): SerdeOptions;
getClassName(stage: Stage): any;
private getPropertyRename;
private getPropertyCase;
getPropertyName(property: string, stage: Stage): string;
getSerializationName(property: string): string;
getDeserializationName(property: string): string;
getDefault(property: string): any;
private isConditionalSkip;
shouldSkip(property: string, value: any, stage: Stage): boolean;
shouldSkipSerializing(property: string, value: any): boolean;
shouldSkipDeserializing(property: string, value: any): boolean;
}