// @ts-nocheck import { AxiosRequestConfig, AxiosResponse } from 'axios'; import express from 'express'; import { Circ } from 'json10/browser'; import { Observable } from 'rxjs'; import { CoreModels } from 'tnp-core/browser'; type DeepPartial = { [K in keyof T]?: T[K] extends object ? DeepPartial : T[K]; }; type ModelValue = DeepPartial | Partial, any>>; type Constructor = new (...args: any[]) => T; type DecrementDepth = [never, 0, 1, 2, 3, 4, 5]; type MappingFrom = [Depth] extends [never] ? never : { [K in keyof T & string]: T[K] extends Primitive ? K : T[K] extends Array ? K | `${K}.${MappingFrom}` : K | `${K}.${MappingFrom}`; }[keyof T & string]; /** * Mapping schema that can be set from decorator * * @DefaultMapping(() => ({ * '': User, * 'book': Book, * 'book.author': Author, * })) * class User { } * */ type EncodeSchema = { ''?: Constructor; } & { [K in MappingFrom]?: Constructor | [Constructor]; }; /** * Mapping schema returned or sended inside http headers */ type EncodeSchemaString = { ''?: string; '[]'?: string[]; } & { [K in MappingFrom]?: string | string[]; }; type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | Function; declare function DefaultMapping(mapping?: () => EncodeSchema): (target: Constructor) => void; declare function DefaultModel(defaults?: () => ModelValue): (target: Constructor) => void; declare function getDefaultModel(instanceOrClass: T | Constructor): ModelValue | undefined; declare function getDefaultMappingSingleObjOrClass(instanceOrClass: T | Constructor): EncodeSchema | undefined; /** * This will be send in request header to later restore class mapping */ declare function getMappingHeaderString(instanceOrClass: T | Constructor | (T | Constructor)[]): string; /** * * @param instanceOrClass class instance or class object * OR array of class instancess or class objects * @returns Mapping object ready to be JSON.stringify */ declare function decodeMappingForHeaderJson(instanceOrClass: T | Constructor | (T | Constructor)[], options?: { useFirstArrayItemClassNameForAllElements?: boolean; }): EncodeSchemaString; declare const encodeMapping: (input: any, schema: EncodeSchema | EncodeSchemaString, circular?: Circ[]) => T; 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} */ declare function getParamsUrl(params: UrlParams[], doNotSerialize?: boolean): string; declare const regexisPath: RegExp; /** * let pattern = '/books/:bookid'; * let url = `/books/34`; */ declare function interpolateParamsToUrl(params: Object, url: string): string; interface AxiosTaonHttpHandler { handle(req: AxiosRequestConfig): Observable>; } interface TaonClientMiddlewareInterceptOptions { req: AxiosRequestConfig; next: AxiosTaonHttpHandler; } interface TaonServerMiddlewareInterceptOptions { req: express.Request; res: express.Response; next: express.NextFunction; } interface TaonAxiosClientInterceptor { intercept(client: TaonClientMiddlewareInterceptOptions): Observable>; } declare class AxiosBackendHandler implements AxiosTaonHttpHandler { handle(req: AxiosRequestConfig): Observable>; } declare const buildInterceptorChain: (globalInterceptors: Array>, backend: AxiosTaonHttpHandler) => AxiosTaonHttpHandler; type ResponseTypeAxios = 'blob' | 'text' | 'json'; type RestHeadersOptions = RestHeaders | { [name: string]: string | string[]; }; 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; } declare class RestResponseWrapper extends RestCommonHttpResponseWrapper { data?: any; } 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; } declare abstract class BaseBody { protected toJSON(data: any, opt: { isJSONArray?: boolean; parsingError?: boolean; }): object | undefined; } 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; } declare class ErrorBody extends BaseBody { private readonly url; private readonly data; constructor(url: string, data: any); get json(): T; get text(): string; } 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); } 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); } 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); } 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; }; declare const HeaderKeyContentType = "Content-Type"; declare const HeaderKeyAccept = "Accept"; 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; }; 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; } interface UrlParams { [urlModelName: string]: string | number | boolean | RegExp | Object; regex?: RegExp; } type Ng2RestAxiosRequestConfig = { doNotSerializeParams?: boolean; } & AxiosRequestConfig; 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; }) => { get: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; delete: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; head: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; post: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; put: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; patch: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; jsonp: (item?: MODEL, urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; array: { get: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; delete: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; head: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; post: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; put: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; patch: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; jsonp: (item?: MODEL[], urlParams?: UrlParams[], axiosOptions?: Ng2RestAxiosRequestConfig) => ResourceResponse; }; }; }; } export { AxiosBackendHandler, BaseBody, BaseResponse, Cookie, DEFAULT_HEADERS, DefaultMapping, DefaultModel, ErrorBody, HeaderKeyAccept, HeaderKeyContentType, HttpBody, HttpResponse, HttpResponseError, Resource, ResourceResponse, RestErrorResponseWrapper, RestHeaders, RestResponseWrapper, buildInterceptorChain, decodeMappingForHeaderJson, encodeMapping, getDefaultMappingSingleObjOrClass, getDefaultModel, getMappingHeaderString, getParamsUrl, interpolateParamsToUrl, regexisPath }; export type { AxiosTaonHttpHandler, EncodeSchema, EncodeSchemaString, ModelValue, Ng2RestAxiosRequestConfig, ResourceStrategy, ResponseTypeAxios, RestHeadersOptions, TaonAxiosClientInterceptor, TaonClientMiddlewareInterceptOptions, TaonServerMiddlewareInterceptOptions, UrlParams };