import { MetaData } from '../templates/IndexPage/types/meta'; import { ResourcePaths, StandardUIPageType } from '../types'; export type BaseResource = Record & { id?: number | string | null; }; export type ApiFnOrObject = T | ((params?: { urlParams?: ApiUrlParams; }) => T); export type StandardUIApi = { /** * APIエンドポイント * :で始まる文字列はリクエスト時に同名のパラメータで置換される */ url: string; /** * HTTPメソッド * default: 'GET' */ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * 返り値から型を推論させるための関数 * 実際に呼ばれることはない */ typeSignature?: () => { /** * APIリクエストパラメータ */ params: ApiParams; /** * APIレスポンス */ response: ApiResponse; /** * APIで扱うレコードの型 * 基本的にはresponseに含まれる想定 */ record: ApiRecord; }; /** * APIレスポンスのシリアライザ * 標準UI内で必要なオブジェクトをレスポンスから取り出す * * 204などでbodyが空の場合は呼び出されない */ serializer?: { record: (response: ApiResponse) => ApiRecord; meta?: (response: ApiResponse) => MetaData; }; /** * APIリクエスト時に付与するヘッダーをカスタムしたい場合は設定 */ requestHeaders?: Record; /** * APIリクエスト前にparameterを加工したい場合は指定 */ encodeParams?: (params: ApiParams) => Promise> | Record; /** * APIレスポンスを加工したい場合は指定 */ decodeResponse?: (response: unknown) => Promise | ApiResponse; }; export type PagePreprocessor = (params: { resource?: R; }) => Promise | unknown; export type PathsConfig = { /** * リソースについて一部のページのみを扱う場合は allowlist形式で記述 * * ex: 一覧のみが存在し、新規作成や詳細については扱わない場合 * { only: ['index'] } */ only?: StandardUIPageType[]; /** * パスの命名規則がデフォルトと異なる場合は指定 * * default: * { * index: indexPath, * new: `${indexPath}/new`, * detail: `${indexPath}/:id`, * edit: `${indexPath}/:id/edit`, * } */ override?: ResourcePaths; };