import { ODataQueryParam } from './params'; import { ODataVersion } from './types_v4'; export type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; export type ODataVariant = 'default' | 'c4c' | 'byd' | 'cap' | 'cpi' | '@odata/server' export const SAPNetweaverOData = ['c4c', 'byd']; export type FetchProxy = (url: string, init: RequestInit) => Promise<{ /** * parsed body content */ content: any; /** * original response object */ response: Response; }>; export interface ODataNewOptions { /** * metadata url */ metadataUri: string; /** * basic credential pair */ credential?: Credential; /** * fetch proxy of all request */ fetchProxy?: FetchProxy; /** * auto process csrf token of c4c */ processCsrfToken?: boolean; /** * for SAP OData * @deprecated */ forSAP?: boolean; /** * service variant */ variant?: ODataVariant; /** * odata version, default v2 */ version?: ODataVersion; } export interface BatchRequestOptions { /** * Collection Name */ collection: string; /** * OData Entity ObjectID */ id?: any; /** * OData Param */ params?: ODataQueryParam; method?: HTTPMethod; /** * OData Entity Object */ entity?: Partial; /** * SAP OData need Content-Length but standard reject it */ withContentLength?: boolean; } export interface ODataRequest { collection: string, /** collection name */ /** * GET for QUERY/READ; for QUERY, you can use params to control response data * PATCH for UPDATE * POST for CREATE * DELETE for delete */ method?: HTTPMethod, } export interface ODataReadIDRequest extends ODataRequest { id: any, /** object key in READ/UPDATE/DELETE */ params?: ODataQueryParam, } export interface ODataQueryRequest extends ODataRequest { params?: ODataQueryParam, /** params in QUERY */ } export interface ODataWriteRequest extends ODataRequest { entity?: Partial /** data object in CREATE/UPDATE */ id?: any; method: HTTPMethod } export interface PlainODataResponse { error?: { /** if error occured, node error will have value */ code: string; message: { lang: string, value: string /** server error message */ } } } export type BatchPlainODataResponse = PlainODataResponse & { d?: { __count?: string; /** $inlinecount values */ results?: Array; } & E; } export type PlainODataSingleResponse = { /** * @version 2.0.0 */ d?: { __count?: string; /** $inlinecount values */ } & E; } & PlainODataResponse export interface PlainODataMultiResponse extends PlainODataResponse { d?: { __count?: string; /** $inlinecount values */ results: Array; /** result list/object */ }; } export interface Credential { username: string, password: string }