Skip to Content
APIPlanning Center Base TSSrcFunctionsFunction: mapIncludedToRelationships()

planning-center-monorepo v1.0.0


planning-center-monorepo / planning-center-base-ts/src / mapIncludedToRelationships

Function: mapIncludedToRelationships()

mapIncludedToRelationships<T>(data, included): FlattenedResource<T["type"], T extends ResourceObject<string, TAttrs, any> ? TAttrs : never, T extends ResourceObject<any, any, TRelMap> ? TRelMap : never>[]

Defined in: packages/planning-center-base-ts/src/included-resolver.ts:114 

Automatically map included resources to their relationships and flatten the structure

This transforms JSON:API responses to a flatter, more convenient structure:

  • Relationships are moved to the top level (person.emails instead of personemails)
  • Attributes are moved to the top level (email.address instead of email.attributes.address)
  • Included resources are automatically resolved and flattened

Type Parameters

T

T extends ResourceObject<string, any, any>

Parameters

data

T[]

Array of resource objects with relationships

included

ResourceObject<string, any, any>[]

Array of included resources from JSON:API response

Returns

FlattenedResource<T["type"], T extends ResourceObject<string, TAttrs, any> ? TAttrs : never, T extends ResourceObject<any, any, TRelMap> ? TRelMap : never>[]

The data array with relationships resolved and structure flattened

Example

// Before: personemails.data[0].attributes.address // After: person.emails[0].address const mapped = mapIncludedToRelationships(response.data, response.included);