export type Timestamp = string; /** 正常値と異常値を格納する型 */ export type Result = { ok: true; value: T } | { ok: false; value: E }; /** networkからdataをとってくる処理 * * interfaceは`fetch()`と同じ */ export type Fetch = ( input: string | Request, init?: RequestInit, ) => Promise; /** 全てのREST APIに共通するopitons */ export interface BaseOptions { /** データの取得に使う処理 * * @default fetch */ fetch?: Fetch; } /** OAuth API用options */ export interface OAuthOptions extends BaseOptions { /** user accountに紐付いたaccess token */ accessToken: string; } /** BaseOptionsの既定値を埋める */ export const setDefaults = ( options: T, ): Omit & Required> => { const { fetch = globalThis.fetch, ...rest } = options; return { fetch, ...rest }; }; export const isObject = (value: unknown): value is Record => typeof value === "object" && value !== null;