Skip to content

Infrastructure API

Все импорты на этой странице:

ts
import { ... } from '@azure-net/kit/infra';

HttpService

TypeScript сигнатура

ts
new HttpService(opts: {
  baseUrl: string;
  instance?: IHttpServiceInstance;
  baseOptions?: Options;
  onRequest?: (options: Options) => void | Promise<void>;
  onError?: (err: IHttpServiceError) => HttpServiceError<unknown>;
  handleError?: (err: unknown) => Promise<HttpServiceError<unknown>>;
})

HTTP методы возвращают

ts
get<T>(url: string, options?: IHttpServiceOptions): Promise<IHttpServiceResponse<T>>
post<T>(url: string, options?: IHttpServiceOptions): Promise<IHttpServiceResponse<T>>
put<T>(url: string, options?: IHttpServiceOptions): Promise<IHttpServiceResponse<T>>
patch<T>(url: string, options?: IHttpServiceOptions): Promise<IHttpServiceResponse<T>>
delete<T>(url: string, options?: IHttpServiceOptions): Promise<IHttpServiceResponse<T>>

HttpServiceResponse и HttpServiceError

TypeScript сигнатура

ts
interface IHttpServiceResponse<T> {
  headers: Record<string, string>;
  status: number;
  success: boolean;
  data: T;
  message: string;
}

interface IHttpServiceError<T> extends IHttpServiceResponse<T> {
  original?: Error;
}

Оба типа нормализуют транспортные детали и используются в error parser/helper-ах.


QueryBuilder

TypeScript сигнатура

ts
new QueryBuilder(options?: {
  objectFormat?: 'default' | 'nested-brackets';
  arrayFormat?: 'repeat' | 'brackets' | 'comma' | 'json';
  separator?: string;
  encode?: boolean;
  includeUndefined?: boolean;
})

build(query: Record<string, unknown>, opts?: { includeQuestionMark?: boolean }): string
transform(object: Record<string, unknown>): Record<string, unknown>

Сериализует query-объекты в стабильную URL-строку.


ResponseBuilder

Импорт

ts
import { ResponseBuilder } from '@azure-net/kit/infra';

TypeScript сигнатура

ts
class ResponseBuilder<TData, TMeta = unknown, TWrapper = unknown> {
  mapUsing<TResource>(ResourceClass: new (data: unknown) => TResource): this;
  mapCollectionUsing<TResource>(ResourceClass: new (data: unknown) => TResource): this;
  extract<TPath>(path: TPath): this;
  addMeta<TNewMeta>(metaData: TNewMeta): ResponseBuilder<TData, TMeta & TNewMeta, TWrapper>;
  getData(): TData;
  get(): { data: TData; meta: TMeta };
  getFlatten(): TData & { meta: TMeta };
  getRaw(): TWrapper;
}

Pipeline для маппинга API-ответов и преобразования ресурсов.


DTOMapper

Импорт

ts
import { DTOMapper } from '@azure-net/kit/infra';

TypeScript сигнатура

ts
class DTOMapper<TOutput = unknown> {
  toPlainObject(): TOutput;
}

Базовый класс для маппинга DTO/ресурсов.


BaseHttpDatasource

Импорт

ts
import { BaseHttpDatasource } from '@azure-net/kit/infra';

TypeScript сигнатура

ts
class BaseHttpDatasource<TQueryBuilder = unknown> {
  protected createRawRequest<T>(callback: () => Promise<T>): Promise<T>;
}

Базовый helper для datasource-классов, оборачивающих raw-запросы.


HttpStatusCode

Импорт

ts
import { HttpStatusCode } from '@azure-net/kit/infra';

Enum со стандартными HTTP-статусами.