Type Alias RelationshipPaths<MapT, DocumentT, Depth, Prefix>

RelationshipPaths: GreaterThan<Depth, 0> extends true
    ? DocumentT["data"] extends (infer Data)[]
    | infer Data
        ? Data extends { relationships?: infer Relation }
            ? Relation extends Record<string, Relationship>
                ? {
                    [K in keyof Relation]: K extends string
                        ? Relation[K]["data"] extends | { type?: infer RelationT }
                        | { type?: ... }[]
                            ? RelationT extends keyof MapT
                                ? | `${(...)}${(...)}`
                                | RelationshipPaths<(...), (...), (...), (...)>
                                : never
                            : never
                        : never
                }[keyof Relation]
                : never
            : never
        : never
    : never

Recursively traverse the JSON:API document to build a list of all possible relationship paths up to the specified depth, which prevents stack overflow for circular relationships. Use the result in include queries

Type Parameters

  • MapT extends Record<string, z.ZodTypeAny>

    A map of ApiType to Zod schemas.

  • DocumentT extends JsonApiDocument

    The JSON:API document.

  • Depth extends number = 5

    The maximum depth for recursive relationship traversal.

  • Prefix extends string = ""

    The prefix for nested relationship paths.