Skip to content

Latest commit

 

History

History
436 lines (259 loc) · 11.1 KB

README.md

File metadata and controls

436 lines (259 loc) · 11.1 KB

jsonapi-fractal

jsonapi-fractal

Table of contents

Enumerations

Classes

JSON Type Aliases

Other Type Aliases

Functions

JSON Type Aliases

JsonObject

Ƭ JsonObject: { [Key in string]: JsonValue } & { [Key in string]?: JsonValue }

Matches a JSON object.

This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: jsonObject as unknown as CustomResponse. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: interface CustomResponse extends JsonObject { … }.

Defined in

node_modules/type-fest/source/basic.d.ts:22


Other Type Aliases

AttributesObject

Ƭ AttributesObject: JsonObject

Defined in

src/types.ts:17


Context

Ƭ Context<TEntity, TExtraProperties>: Object

Type parameters

Name Type
TEntity TEntity
TExtraProperties unknown

Type declaration

Name Type
included boolean
input TEntity | undefined
options Options<TExtraProperties>
transformer Transformer<TEntity, TExtraProperties>

Defined in

src/context.ts:5


DocumentObject

Ƭ DocumentObject: ExistingDocumentObject | NewDocumentObject

Defined in

src/types.ts:15


ExistingDocumentObject

Ƭ ExistingDocumentObject: BaseDocumentObject<ExistingResourceObject>

Defined in

src/types.ts:11


ExistingResourceObject

Ƭ ExistingResourceObject: ResourceIdentifierObject & { attributes: AttributesObject ; id: string ; links?: LinkObject ; relationships?: Record<string, RelationshipObject> }

Defined in

src/types.ts:28


LinkObject

Ƭ LinkObject: JsonObject

Defined in

src/types.ts:21


MetaObject

Ƭ MetaObject: JsonObject

Defined in

src/types.ts:19


NewDocumentObject

Ƭ NewDocumentObject: BaseDocumentObject<NewResourceObject>

Defined in

src/types.ts:13


NewResourceObject

Ƭ NewResourceObject: Omit<ExistingResourceObject, "id">

Defined in

src/types.ts:35


Options

Ƭ Options<TExtraOptions>: Object

Type parameters

Name Type
TExtraOptions void

Type declaration

Name Type Description
changeCase? CaseType change case of the attribute keys
changeCaseDeep? boolean if true, also apply the change for sub objects
extra? TExtraOptions custom properties, that are available in the transformer
fields? Record<string, string[]> map of EntityType => Fields Array, e.g. {"users": ["name", "age"], "images": ["width"]}
idKey? string key that should be used as the id

Defined in

src/types.ts:50


RelationshipObject

Ƭ RelationshipObject: Object

Type declaration

Name Type
data ResourceIdentifierObject | ResourceIdentifierObject[]
links? LinkObject

Defined in

src/types.ts:39


RelationshipTransformerInfo

Ƭ RelationshipTransformerInfo<TExtraOptions, T>: Object

Type parameters

Name Type
TExtraOptions TExtraOptions
T unknown

Type declaration

Name Type
included boolean
input T
transformer Transformer<T, TExtraOptions>

Defined in

src/transformer.ts:24


RelationshipTransformerInfoFunction

Ƭ RelationshipTransformerInfoFunction<TEntity, TExtraOptions>: (entity: TEntity, options: Options<TExtraOptions>) => RelationshipTransformerInfo<TExtraOptions>

Type parameters

Name
TEntity
TExtraOptions

Type declaration

▸ (entity, options): RelationshipTransformerInfo<TExtraOptions>

Parameters
Name Type
entity TEntity
options Options<TExtraOptions>
Returns

RelationshipTransformerInfo<TExtraOptions>

Defined in

src/transformer.ts:19


ResourceIdentifierObject

Ƭ ResourceIdentifierObject: Object

Type declaration

Name Type
id string
type string

Defined in

src/types.ts:23


ResourceObject

Ƭ ResourceObject: ExistingResourceObject | NewResourceObject

Defined in

src/types.ts:37


SerializeOptions

Ƭ SerializeOptions<TExtraOptions>: Options<TExtraOptions> & { included?: boolean ; relationships?: string[] | Record<string, string> }

Type parameters

Name Type
TExtraOptions void

Defined in

src/types.ts:63


TransformerRelationships

Ƭ TransformerRelationships<TEntity, TExtraOptions>: Record<string, RelationshipTransformerInfoFunction<TEntity, TExtraOptions>>

Type parameters

Name
TEntity
TExtraOptions

Defined in

src/transformer.ts:14

Functions

deserialize

deserialize<TEntity, TExtraOptions>(response, options?): TEntity | TEntity[] | undefined

Deserialize a JSON:API response

Type parameters

Name Type
TEntity TEntity
TExtraOptions unknown

Parameters

Name Type
response DocumentObject
options Options<TExtraOptions>

Returns

TEntity | TEntity[] | undefined

Defined in

src/deserializer.ts:12


serialize

serialize<TEntity, TExtraOptions>(data, type, options?): DocumentObject

Serialize the entity

Type parameters

Name Type
TEntity TEntity
TExtraOptions unknown

Parameters

Name Type Description
data TEntity entity to be serialized
type string type of the entity
options? SerializeOptions<TExtraOptions> options used in the serialization

Returns

DocumentObject

Defined in

src/serializer.ts:32


transform

transform<TEntity, TExtraOptions>(): ContextBuilder<TEntity, TExtraOptions>

Create a ContextBuilder, used to configure the transformation

Type parameters

Name Type
TEntity TEntity
TExtraOptions unknown

Returns

ContextBuilder<TEntity, TExtraOptions>

Defined in

src/serializer.ts:21


whitelist

whitelist(object, list): AttributesObject

Keep only a set of fields on a given object

Parameters

Name Type
object unknown
list string[]

Returns

AttributesObject

Defined in

src/utils.ts:54