import { AxiosRequestConfig, AxiosResponse } from 'axios'; import type express from 'express'; import { Circ } from 'json10'; import { Observable } from 'rxjs'; import { CoreModels } from 'tnp-core'; import { EncodeSchema, EncodeSchemaString } from './new-mapping'; export declare class Cookie { static get Instance(): Cookie; private static __instance; private constructor(); read(name: string): string; write(name: string, value: string, days?: number): void; remove(name: string): void; } /** * Create query params string for url * * @export * @param {UrlParams[]} params * @returns {string} */ export declare function getParamsUrl(params: UrlParams[], doNotSerialize?: boolean): string; export declare const regexisPath: RegExp; /** * let pattern = '/books/:bookid'; * let url = `/books/34`; */ export declare function interpolateParamsToUrl(params: Object, url: string): string; export interface AxiosTaonHttpHandler { handle(req: AxiosRequestConfig): Observable>; } export interface TaonClientMiddlewareInterceptOptions { req: AxiosRequestConfig; next: AxiosTaonHttpHandler; } export interface TaonServerMiddlewareInterceptOptions { req: express.Request; res: express.Response; next: express.NextFunction; } export interface TaonAxiosClientInterceptor { intercept(client: TaonClientMiddlewareInterceptOptions): Observable>; } export declare class AxiosBackendHandler implements AxiosTaonHttpHandler { handle(req: AxiosRequestConfig): Observable>; } export declare const buildInterceptorChain: (globalInterceptors: Array>, backend: AxiosTaonHttpHandler) => AxiosTaonHttpHandler; export type ResponseTypeAxios = 'blob' | 'text' | 'json' | 'arraybuffer' | 'document' | 'stream' | 'formdata'; export type RestHeadersOptions = RestHeaders | { [name: string]: string | string[]; }; export declare class RestHeaders { /** @internal header names are lower case */ protected _headers: Map; /** @internal map lower case names to actual names */ protected _normalizedNames: Map; static from(headers?: RestHeadersOptions): RestHeaders; apply(headers?: RestHeadersOptions): RestHeaders; private constructor(); /** * Returns a new RestHeaders instance from the given DOMString of Response RestHeaders */ static fromResponseHeaderString(headersString: string): RestHeaders; /** * Appends a header to existing list of header values for a given header name. */ append(name: string, value: string): void; /** * Deletes all header values for the given name. */ delete(name: string): void; forEach(fn: (values: string[], name: string, headers: Map) => void): void; /** * Returns first header that matches given name. */ get(name: string): string; /** * Checks for existence of header by given name. */ has(name: string): boolean; /** * Returns the names of the headers */ keys(): string[]; /** * Sets or overrides header value for given name. */ set(name: string, value: string | string[]): void; /** * Returns values of all headers. */ values(): string[][]; /** * Returns string of all headers. */ toJSON(): { [name: string]: any; }; /** * Returns list of header values for a given name. */ getAll(name: string): string[]; private mayBeSetNormalizedName; } declare class RestCommonHttpResponseWrapper { success?: boolean; } export declare class RestResponseWrapper extends RestCommonHttpResponseWrapper { data?: any; } export declare class RestErrorResponseWrapper extends RestCommonHttpResponseWrapper { message: string; /** * stack trace / more details about error */ details?: string; /** * http status code */ status?: number; /** * custom error code from backend */ code?: string; } export declare abstract class BaseBody { protected toJSON(data: any, opt: { isJSONArray?: boolean; parsingError?: boolean; }): object | undefined; } export declare class HttpBody extends BaseBody { private readonly url; private readonly method; private readonly headers; private readonly responseText; private readonly options; private readonly isArray; constructor(url: string, method: string, headers: RestHeaders, responseText: string | Blob, options: ResourceOptions, isArray: boolean); private get entity(); private get circular(); get blob(): Blob; get booleanValue(): boolean | undefined; get numericValue(): number | undefined; get rawJson(): Partial; get json(): T; private displayWarningWhenNotUsingProperAPI; /** * undefined when blob */ get text(): string | undefined; } export declare class ErrorBody extends BaseBody { private readonly url; private readonly data; constructor(url: string, data: any); get json(): T; get text(): string; } export declare abstract class BaseResponse { readonly responseText: string | Blob; readonly options: ResourceOptions; readonly statusCode: number; readonly headers: RestHeaders; readonly isArray: boolean; constructor(responseText: string | Blob, options: ResourceOptions, statusCode: number, headers: RestHeaders, isArray: boolean); } export declare class HttpResponse extends BaseResponse { readonly url: string; readonly method: CoreModels.HttpMethod; readonly responseText: string | Blob; readonly headers: RestHeaders; readonly statusCode: number; readonly options: ResourceOptions; readonly isArray: boolean; body: HttpBody; constructor(url: string, method: CoreModels.HttpMethod, responseText: string | Blob, headers: RestHeaders, statusCode: number, options: ResourceOptions, isArray: boolean); } export declare class HttpResponseError extends BaseResponse { readonly url: string; readonly method: CoreModels.HttpMethod; readonly responseText: string; readonly options: ResourceOptions; readonly headers: RestHeaders; readonly statusCode: number; readonly isArray: boolean; readonly body: ErrorBody; constructor(url: string, method: CoreModels.HttpMethod, responseText: string, options: ResourceOptions, headers: RestHeaders, statusCode: number, isArray: boolean); } export type ResourceStrategy = 'http' | 'ipc-electron' | 'js-mock'; interface ResourceOptions { strategy?: ResourceStrategy; headers?: RestHeaders; useArrayApiWarning?: boolean; defaultHeadersProfile?: keyof typeof DEFAULT_HEADERS; responseMapping?: { /** * Use ()=> MyEntity to avoid js circural dependencies. * String only when as header key value. */ entity?: (EncodeSchema | EncodeSchemaString) | { (): EncodeSchema | EncodeSchemaString; } | string; /** * Metadata for remapping circular objects. * Generated from json10 packages. * String only when as header key value. */ circular?: Circ[] | string; }; } type BackendError = { msg?: string; stack?: string[]; data: any; }; export declare const HeaderKeyContentType = "Content-Type"; export declare const HeaderKeyAccept = "Accept"; export declare const DEFAULT_HEADERS: { readonly APPLICATION_JSON: RestHeaders; readonly APPLICATION_VND_API_JSON: RestHeaders; readonly APPLICATION_X_WWW_FORM_URLENCODED: RestHeaders; readonly MULTIPART_FORM_DATA: RestHeaders; readonly TEXT_PLAIN: RestHeaders; readonly ACCEPT_ANY: RestHeaders; readonly OCTET_STREAM: RestHeaders; }; export declare abstract class ResourceResponse implements Promise | HttpResponseError> { protected httpMethodName: CoreModels.HttpMethod; protected urlOrigin: string; protected urlPathname: string; protected options: ResourceOptions; protected body: DATA | DATA; protected urlParams: UrlParams[]; protected axiosOptions: Ng2RestAxiosRequestConfig; protected isArray: boolean; protected headers: RestHeaders; protected globalInterceptors: Map; protected methodsInterceptors: Map; [Symbol.toStringTag]: string; private _promise?; private _promiseAbort?; private _observable?; constructor(httpMethodName: CoreModels.HttpMethod, urlOrigin: string, urlPathname: string, options: ResourceOptions, body: DATA | DATA, urlParams: UrlParams[], axiosOptions: Ng2RestAxiosRequestConfig, isArray: boolean, headers: RestHeaders, globalInterceptors: Map, methodsInterceptors: Map); protected abstract makeRequest(abortSignal: AbortSignal): Promise>; /** * ✅ Explicit cancel (useful for "promise style") */ cancel(reason?: string): void; /** * Promise API (cannot be auto-cancelled by consumer, so we expose cancel()) */ get promise(): Promise | HttpResponseError>; then, TResult2 = never>(onfulfilled?: ((value: HttpResponse) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): Promise; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | null): Promise<(HttpResponse | HttpResponseError) | TResult>; finally(onfinally?: (() => void) | null): Promise | HttpResponseError>; /** * ✅ Observable owns AbortController: * - subscribe starts request * - unsubscribe aborts request * - shareReplay shares the same in-flight request among subscribers */ get observable(): Observable>; protected creatUrl(params: any, doNotSerializeParams?: boolean): string; } export interface UrlParams { [urlModelName: string]: string | number | boolean | RegExp | Object; regex?: RegExp; } export type Ng2RestAxiosRequestConfig = { doNotSerializeParams?: boolean; } & AxiosRequestConfig; export declare namespace Resource { const globalInterceptors: Map>; const methodsInterceptors: Map>; const listenErrors: Observable; const Cookies: Cookie; function create(originUrl: string, pathnameModel: string, resourceOptions?: ResourceOptions): { model: (interpolateParams?: INTERPOLATE_ARGS, overrideOptions?: ResourceOptions | { (options: ResourceOptions): ResourceOptions; }) => { patch: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; get: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; post: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; put: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; delete: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; head: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; jsonp: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; array: { patch: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; get: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; post: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; put: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; delete: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; head: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; jsonp: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; }; }; }; } export {};