Interface SerializerOptions<PrimaryType>

interface SerializerOptions<PrimaryType> {
    asIncluded: boolean;
    cache: boolean | Cache<PrimaryType>;
    depth: number;
    idKey: keyof PrimaryType;
    include: number | string[] | (PrimaryType extends object
        ? {
            [K in string | number | symbol]-?: K extends string | number
                ? `${K}` | Join<K, PrimaryType[K] extends object
                    ? {
                        [K in string | number | symbol]-?: K extends string | number
                            ? `${K}` | Join<K, never>
                            : never
                    }[keyof any[any]]
                    : "">
                : never
        }[keyof PrimaryType]
        : "")[];
    linkers: {
        document?: Linker<[nullish | SingleOrArray<PrimaryType>]>;
        paginator?: Paginator<PrimaryType>;
        resource?: Linker<[PrimaryType]>;
    };
    metaizers: {
        document?: Metaizer<[nullish | SingleOrArray<PrimaryType>]>;
        jsonapi?: Metaizer<[]>;
        resource?: Metaizer<[PrimaryType]>;
    };
    nullData: boolean;
    onlyIdentifier: boolean;
    onlyRelationship: string;
    projection: undefined | null | Partial<Record<keyof PrimaryType, 0 | 1>>;
    relators?: Relator<PrimaryType, any> | Relator<PrimaryType, any>[] | Record<string, Relator<PrimaryType, any>>;
    version: null | string;
}

Type Parameters

Properties

asIncluded: boolean

Whether to make primary data as an included resource and use resource identifier objects for top-level data.

Default Value

false

cache: boolean | Cache<PrimaryType>

Enables caching of documents. If a Cache is given, then the given Cache will be used.

Default Value

false

depth: number

Determines the depth of relators to use for included resources.

PLEASE TAKE CAUTION: If this property is Infinity, performance can degrade significantly. It is RECOMMENDED to use more requests rather than a single one if such depth is required since included resources can be inhomogenous thus difficult to traverse.

Must be a number in [0, Infinity].

Default Value

0

Deprecated

Replaced by include

idKey: keyof PrimaryType

The key name for the identifier in the resource.

Default Value

"id"

include: number | string[] | (PrimaryType extends object
    ? {
        [K in string | number | symbol]-?: K extends string | number
            ? `${K}` | Join<K, PrimaryType[K] extends object
                ? {
                    [K in string | number | symbol]-?: K extends string | number
                        ? `${K}` | Join<K, never>
                        : never
                }[keyof any[any]]
                : "">
            : never
    }[keyof PrimaryType]
    : "")[]

Which resources to include. See docs

If passed as a numeric value, all related resources will be included up to the given depth.

If provided this will superceed the use of depth If not provided, or explicitly nullish, then behaviour will default to using depth If provided as an empty array, then no relationships will be included.

linkers: {
    document?: Linker<[nullish | SingleOrArray<PrimaryType>]>;
    paginator?: Paginator<PrimaryType>;
    resource?: Linker<[PrimaryType]>;
}

A set of options for constructing top-level links.

Type declaration

metaizers: {
    document?: Metaizer<[nullish | SingleOrArray<PrimaryType>]>;
    jsonapi?: Metaizer<[]>;
    resource?: Metaizer<[PrimaryType]>;
}

A dictionary of Metaizers to use in different locations of the document.

Type declaration

nullData: boolean

Whether to use null value the data field.

This option will ignore options onlyIdentifier, linkers.resource, and metaizers.resource (and all options they ignores).

Default Value

false

onlyIdentifier: boolean

Whether to only serialize the identifier.

This option will ignore the options depth

Default Value

false

onlyRelationship: string

This is used to serialize the resource linkages only. The value must be the name of a collection for a relator in the relators option.

Only a single primary datum (as opposed to an array) MUST be serialized.

This option will ignore the options projection, linkers.resource, and metaizers.resource.

projection: undefined | null | Partial<Record<keyof PrimaryType, 0 | 1>>

An object of 0 OR 1 (NOT BOTH) to denote hide or show attributes respectively.

If set (directly) to undefined, then the attributes field will be left undefined. If set to null, then every attribute will show. If set to {}, then every attribute will hide.

Default Value

null

relators?: Relator<PrimaryType, any> | Relator<PrimaryType, any>[] | Record<string, Relator<PrimaryType, any>>

A Relator that generates relationships for a given primary resource.

Note: You can add more relators by using Serializer.setRelators. This is useful in case you have a cycle of relators among serializers.

See relationships objects for more information.

version: null | string

The highest JSON API version supported. Set to null to omit version.

Default Value

1.0

Generated using TypeDoc