// relaxed constraints on call,apply,bind *this* /* eslint-disable @typescript-eslint/ban-types */ import type { EndpointInterface, Schema } from './interface.js'; import type { EndpointExtraOptions, FetchFunction, PartialParameters, } from './types.js'; export interface EndpointOptions< F extends FetchFunction = FetchFunction, S extends Schema | undefined = undefined, M extends boolean | undefined = false, > extends EndpointExtraOptions { key?: (...args: Parameters) => string; sideEffect?: M; schema?: S; [k: string]: any; } export interface EndpointExtendOptions< F extends FetchFunction = FetchFunction, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, > extends EndpointOptions { fetch?: FetchFunction; } export type ParamFromFetch = F extends (params: infer P, body?: any) => Promise ? P : never; export type KeyofEndpointInstance = keyof EndpointInstance; export type ExtendedEndpoint< O extends EndpointExtendOptions, E extends EndpointInstance< FetchFunction, Schema | undefined, boolean | undefined >, F extends FetchFunction, > = EndpointInstance< 'fetch' extends keyof O ? Exclude : E['fetch'], 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? O['sideEffect'] : E['sideEffect'] > & Omit & Omit; /** * Defines an async data source. * @see https://dataclient.io/docs/api/Endpoint */ export interface EndpointInstance< F extends (...args: any) => Promise = FetchFunction, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, > extends EndpointInstanceInterface { extend< E extends EndpointInstance< (...args: any) => Promise, Schema | undefined, boolean | undefined >, O extends EndpointExtendOptions & Partial>> & Record, >( this: E, options: Readonly, ): ExtendedEndpoint; } /** * Defines an async data source. * @see https://dataclient.io/docs/api/Endpoint */ export interface EndpointInstanceInterface< F extends FetchFunction = FetchFunction, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, > extends EndpointInterface { constructor: EndpointConstructor; /** * Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function. * @param thisArg The object to be used as the this object. * @param argArray A set of arguments to be passed to the function. */ apply( this: E, thisArg: any, argArray?: Parameters, ): ReturnType; /** * Calls a method of an object, substituting another object for the current object. * @param thisArg The object to be used as the current object. * @param argArray A list of arguments to be passed to the method. */ call( this: E, thisArg: any, ...argArray: Parameters ): ReturnType; /** * For a given function, creates a bound function that has the same body as the original function. * The this object of the bound function is associated with the specified object, and has the specified initial parameters. * @param thisArg An object to which the this keyword can refer inside the new function. * @param argArray A list of arguments to be passed to the new function. */ bind>( this: E, thisArg: any, ...args: readonly [...P] ): EndpointInstance< (...args: readonly [...RemoveArray, P>]) => ReturnType, S, M > & Omit>; /** Returns a string representation of a function. */ toString(): string; prototype: any; readonly length: number; arguments: any; caller: F; key(...args: Parameters): string; readonly sideEffect: M; readonly schema: S; fetch: F; /** @see https://dataclient.io/rest/api/Endpoint#testKey */ testKey(key: string): boolean; } export interface EndpointConstructor { new < F extends ( this: EndpointInstance & E, params?: any, body?: any, ) => Promise, S extends Schema | undefined = undefined, M extends boolean | undefined = false, E extends Record = {}, >( fetchFunction: F, options?: EndpointOptions & E, ): EndpointInstance & E; readonly prototype: Function; } export interface ExtendableEndpointConstructor { new < F extends ( this: EndpointInstanceInterface & E, params?: any, body?: any, ) => Promise, S extends Schema | undefined = undefined, M extends boolean | undefined = false, E extends Record = {}, >( RestFetch: F, options?: Readonly> & E, ): EndpointInstanceInterface & E; readonly prototype: Function; } type RemoveArray = Rem extends [any, ...infer RestRem] ? Orig extends [any, ...infer RestOrig] ? RemoveArray : never : Orig; export {}; //# sourceMappingURL=endpointTypes.d.ts.map