TypeScript API / laikacms/json-api / fromJsonApi
Function: fromJsonApi()
ts
function fromJsonApi<T, I, O>(
data,
_type,
idField
): O;Transforms a JSON:API resource back to domain object format.
Injects type from the resource envelope (it was stripped from attributes by toJsonApi to comply with JSON:API §7.2.2) and merges the id back under the caller-supplied idField.
Type Parameters
| Type Parameter |
|---|
T extends string |
I extends string |
O extends Record<string, unknown> |
Parameters
| Parameter | Type | Description |
|---|---|---|
data | { attributes: Omit<O, I | "type" | "id">; id: string; type: T; } | The JSON:API resource |
data.attributes | Omit<O, I | "type" | "id"> | - |
data.id | string | - |
data.type | T | - |
_type | T | JSON:API resource type (for type checking, not used at runtime) |
idField | I | Name of the ID field in the domain object |
Returns
O