Path: blob/1.0-develop/resources/scripts/api/definitions/index.d.ts
7461 views
import { MarkRequired } from 'ts-essentials';1import { FractalResponseData, FractalResponseList } from '../http';23export type UUID = string;45// eslint-disable-next-line @typescript-eslint/no-empty-interface6export interface Model {}78interface ModelWithRelationships extends Model {9relationships: Record<string, FractalResponseData | FractalResponseList | undefined>;10}1112/**13* Allows a model to have optional relationships that are marked as being14* present in a given pathway. This allows different API calls to specify the15* "completeness" of a response object without having to make every API return16* the same information, or every piece of logic do explicit null checking.17*18* Example:19* >> const user: WithLoaded<User, 'servers'> = {};20* >> // "user.servers" is no longer potentially undefined.21*/22type WithLoaded<M extends ModelWithRelationships, R extends keyof M['relationships']> = M & {23relationships: MarkRequired<M['relationships'], R>;24};2526/**27* Helper type that allows you to infer the type of an object by giving28* it the specific API request function with a return type. For example:29*30* type Egg = InferModel<typeof getEgg>;31*/32export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends Promise<infer U> ? U : T;333435