UNPKG

928 BTypeScriptView Raw
1import type { Serializer } from "./serializer.js";
2import type { ModelToObject } from "./schema.js";
3/**
4 * Represents Serializer plugin component.
5 *
6 * Like {@link Converter} plugins each {@link Serializer} plugin defines a predicate that instructs if an
7 * object can be serialized by it. This is done dynamically at runtime via a `supports` method.
8 */
9export interface SerializerComponent<T extends object> {
10 /**
11 * The priority this serializer should be executed with.
12 * A higher priority means the {@link Serializer} will be applied earlier.
13 */
14 readonly priority: number;
15 /**
16 * Technically this should return `item is T`, but that doesn't play nicely
17 * with inference, so allow the looser `boolean` return type.
18 * @param item
19 */
20 supports(item: unknown): boolean;
21 toObject(item: T, obj: Partial<ModelToObject<T>>, serializer: Serializer): Partial<ModelToObject<T>>;
22}