1 | import type { Serializer } from "./serializer";
|
2 | import type { ModelToObject } from "./schema";
|
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 | *
|
9 | * Additionally, each {@link Serializer} plugin must define a predicate that instructs the group
|
10 | * it belongs to.
|
11 | */
|
12 | export interface SerializerComponent<T extends object> {
|
13 | /**
|
14 | * The priority this serializer should be executed with.
|
15 | * A higher priority means the {@link Serializer} will be applied earlier.
|
16 | */
|
17 | readonly priority: number;
|
18 | /**
|
19 | * Technically this should return `item is T`, but that doesn't play nicely
|
20 | * with inference, so allow the looser `boolean` return type.
|
21 | * @param item
|
22 | */
|
23 | supports(item: unknown): boolean;
|
24 | toObject(item: T, obj: Partial<ModelToObject<T>>, serializer: Serializer): Partial<ModelToObject<T>>;
|
25 | }
|