export type ActionName = 'index' | 'create' | 'read' | 'update' | 'delete' | 'bulk-create' | 'bulk-update' | 'bulk-delete'; export type ID = string | number; export type HasId = { id: ID; }; export type ServerSettings = { enable?: boolean; /** Sets the mock server delay in ms */ delay?: number; }; export type SimpleModelSettings = { /** An array of actions to enable for this model */ only?: ActionName[]; /** The plural name of the model, defaults to [name]s */ plural?: string; /** Base path for the model in the API */ path?: string; /** Whether or not to wrap the API return in a data prop. Defaults to true. */ envelope?: boolean; pagination?: { type: 'page' | 'cursor'; defaultLimit: number; }; inverse?: { [local: string]: string | null; }; }; export type ModelSettings = { /** An array of actions to enable for this model */ only?: ActionName[]; /** The plural name of the model, defaults to [name]s */ plural?: string; /** Base path for the model in the API */ path?: string; /** Whether or not to wrap the API return in a data prop. Defaults to true. */ envelope?: boolean; singleton?: true; pagination?: { type: 'page' | 'cursor'; defaultLimit: number; }; inverse?: { [local: string]: string | null; }; listMeta?: { [key: string]: { type: Function; }; }; }; export type ApiNames = { data: string; dataSingle: string; meta: string; included: string; }; export type FetchRequestOptions = { mode?: 'no-cors' | 'cors' | 'same-origin'; credentials?: 'include' | 'same-origin' | 'omit'; cache?: 'default' | 'no-cache' | 'reload' | 'force-cache' | 'only-if-cached'; redirect?: 'manual' | 'follow' | 'error'; referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'; }; export type Settings = { baseURL?: string; server?: ServerSettings; idsAreNumbers?: boolean; idFactory?: (i: number) => string; naming?: { [key in keyof ApiNames]?: string; }; identityModel?: any; useSnakeCase?: boolean; }; type WithBelongsToPostFix = SnakeCase extends true ? { [K in `${keyof Obj}_id`]: Id; } : { [K in `${keyof Obj}Id`]: Id; }; type WithHasManyPostFix = SnakeCase extends true ? { [K in `${keyof Obj}_ids`]?: Id[]; } : { [K in `${keyof Obj}Ids`]?: Id[]; }; type RelId = One extends { [key: string]: () => string; } ? WithBelongsToPostFix : {}; type RelIds = Many extends { [key: string]: () => string; } ? WithHasManyPostFix : {}; export type Rels = Many extends { [key: string]: () => string; } ? { [K in keyof Many]?: (Id & Models[ReturnType]['types'] & RelId]['belongsTo'], Id['id'], SnakeCase>)[]; } : {}; export type Rel = One extends { [key: string]: () => string; } ? { [K in keyof One]?: Id & Models[ReturnType]['types'] & RelId]['belongsTo'], Id['id'], SnakeCase>; } : {}; export type FieldTypes = { [K in keyof Models]: Models[K]['types'] & Id & Rels & Rel & RelId & RelIds; }; export type IdType = IdSettings extends { idsAreNumbers: true; } ? { id: number; } : { id: string; }; export type SnakeCase = CaseSettings extends { useSnakeCase: true; } ? true : false; export {};