planning-center-monorepo v1.0.0
planning-center-monorepo / planning-center-base-ts/src / FlattenedResource
Type Alias: FlattenedResource<TType, TAttrs, TRelMap, TRelResourceMap>
FlattenedResource<
TType,TAttrs,TRelMap,TRelResourceMap> =object&TAttrs& { [K in keyof TRelMap]?: TRelMap[K] extends Relationship ? TRelMap[K][“data”] extends ResourceIdentifier[] ? K extends keyof TRelResourceMap ? TRelResourceMap[K] extends ResourceObject<string, any, any>[] ? FlattenedResource<(…)[(…)][“type”], (…)[(…)] extends ResourceObject<(…), (…), (…)> ? TAttrs : never, (…)[(…)] extends ResourceObject<(…), (…), (…)> ? (…) : never>[] | ResourceIdentifier[] : FlattenedResource<string, any, any>[] | ResourceIdentifier[] : FlattenedResource<string, any, any>[] | ResourceIdentifier[] : TRelMap[K][“data”] extends ResourceIdentifier ? K extends keyof TRelResourceMap ? TRelResourceMap[K] extends ResourceObject<string, any, any> ? FlattenedResource<(…)[(…)][“type”], (…)[(…)] extends ResourceObject<(…), (…), (…)> ? TAttrs : never, (…)[(…)] extends ResourceObject<(…), (…), (…)> ? (…) : never> | ResourceIdentifier | null : FlattenedResource<string, any, any> | ResourceIdentifier | null : FlattenedResource<string, any, any> | ResourceIdentifier | null : never : TRelMap[K] } &object
Defined in: packages/planning-center-base-ts/src/types/flattened-resource.ts:46
Flatten a single resource object type
Transforms ResourceObject<TType, TAttrs, TRelMap> into a flat structure where:
- Attributes are at the top level
- Relationships are at the top level (as arrays or single objects)
- Relationships are typed as the actual resource types, not Relationship wrappers
- type, id, links, meta are preserved
Type Declaration
type
type:
TType
id
id:
string
Type Declaration
links?
optionallinks:Record<string,any>
meta?
optionalmeta:Record<string,any>
Type Parameters
TType
TType extends string = string
TAttrs
TAttrs extends Record<string, any> = Record<string, any>
TRelMap
TRelMap extends Record<string, any> = Record<string, any>
TRelResourceMap
TRelResourceMap extends Record<string, ResourceObject<string, any, any> | ResourceObject<string, any, any>[]> = Record<string, never>
Optional mapping of relationship keys to their resource types
If provided, relationships will be typed as the specific resource types.
If not provided, relationships will be typed as FlattenedResource
Example
// With mapping:
type PersonWithRelationships = FlattenedResource<
'Person',
PersonAttributes,
PersonRelationships,
{ emails: EmailResource; phone_numbers: PhoneNumberResource[]; household: HouseholdResource }
>;
// Result: { emails?: EmailResource[]; phone_numbers?: PhoneNumberResource[]; household?: HouseholdResource }