diff --git a/packages/@ackee/antonio-core/docs/api/Class: Antonio.md b/packages/@ackee/antonio-core/docs/api/Class: Antonio.md new file mode 100644 index 0000000..63a408f --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Class: Antonio.md @@ -0,0 +1,291 @@ +## Type parameters + +| Name | Type | +| :-------------------- | :---------------------------- | +| `TSuccessDataDefault` | `TSuccessDataDefault` = `any` | +| `TErrorDataDefault` | `TErrorDataDefault` = `any` | + +## Table of contents + +### Constructors + +- [constructor](../wiki/Class:%20Antonio#constructor) + +### Properties + +- [defaults](../wiki/Class:%20Antonio#defaults) +- [generalConfig](../wiki/Class:%20Antonio#generalconfig) +- [interceptors](../wiki/Class:%20Antonio#interceptors) + +### Methods + +- [delete](../wiki/Class:%20Antonio#delete) +- [get](../wiki/Class:%20Antonio#get) +- [head](../wiki/Class:%20Antonio#head) +- [options](../wiki/Class:%20Antonio#options) +- [patch](../wiki/Class:%20Antonio#patch) +- [post](../wiki/Class:%20Antonio#post) +- [put](../wiki/Class:%20Antonio#put) + +## Constructors + +### constructor + +• **new Antonio**(`requestConfig?`, `generalConfig?`) + +**`example`** + +```ts +import { Antonio } from `@ackee/antonio-core`; + +const api = new Antonio({ + baseURL: 'https://some-domain.com/api/', +}); +``` + +#### Type parameters + +| Name | Type | +| :-------------------- | :---------------------------- | +| `TSuccessDataDefault` | `TSuccessDataDefault` = `any` | +| `TErrorDataDefault` | `TErrorDataDefault` = `any` | + +#### Parameters + +| Name | Type | +| :--------------- | :--------------------------------------------------------- | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | +| `generalConfig?` | `Partial`<[GeneralConfig](../wiki/Exports#generalconfig)\> | + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:16](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L16) + +## Properties + +### defaults + +• `Readonly` **defaults**: `DefaultRequestConfig` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:14](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L14) + +--- + +### generalConfig + +• `Readonly` **generalConfig**: [GeneralConfig](../wiki/Exports#generalconfig) + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:16](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L16) + +--- + +### interceptors + +• `Readonly` **interceptors**: `InterceptorManagers` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:15](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L15) + +## Methods + +### delete + +▸ **delete**(`url`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:73](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L73) + +--- + +### get + +▸ **get**(`url`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:66](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L66) + +--- + +### head + +▸ **head**(`url`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:80](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L80) + +--- + +### options + +▸ **options**(`url`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:87](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L87) + +--- + +### patch + +▸ **patch**(`url`, `body`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `body` | [RequestBodyData](../wiki/Exports#requestbodydata) | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:58](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L58) + +--- + +### post + +▸ **post**(`url`, `body`, `requestConfig?`): `any` + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `body` | [RequestBodyData](../wiki/Exports#requestbodydata) | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`any` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:42](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L42) + +--- + +### put + +▸ **put**(`url`, `body`, `requestConfig?`): `Generator`, IteratorResult\>\> + +#### Type parameters + +| Name | Type | +| :------------- | :------------------------------------- | +| `TSuccessData` | `TSuccessData` = `TSuccessDataDefault` | +| `TErrorData` | `TErrorData` = `TErrorDataDefault` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------------------------------------------------- | +| `url` | `string` | +| `body` | [RequestBodyData](../wiki/Exports#requestbodydata) | +| `requestConfig?` | [RequestConfig](../wiki/Interface:%20RequestConfig) | + +#### Returns + +`Generator`, IteratorResult\>\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts:50](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/models/Antonio.ts#L50) diff --git a/packages/@ackee/antonio-core/docs/api/Class: AntonioError.md b/packages/@ackee/antonio-core/docs/api/Class: AntonioError.md new file mode 100644 index 0000000..a6a554a --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Class: AntonioError.md @@ -0,0 +1,215 @@ +## Type parameters + +| Name | Type | +| :--- | :-------------- | +| `D` | `D` = `unknown` | + +## Hierarchy + +- `Error` + + ↳ **AntonioError** + +## Table of contents + +### Constructors + +- [constructor](../wiki/Class:%20AntonioError#constructor) + +### Properties + +- [data](../wiki/Class:%20AntonioError#data) +- [isAntonioError](../wiki/Class:%20AntonioError#isantonioerror) +- [message](../wiki/Class:%20AntonioError#message) +- [name](../wiki/Class:%20AntonioError#name) +- [request](../wiki/Class:%20AntonioError#request) +- [response](../wiki/Class:%20AntonioError#response) +- [stack](../wiki/Class:%20AntonioError#stack) +- [prepareStackTrace](../wiki/Class:%20AntonioError#preparestacktrace) +- [stackTraceLimit](../wiki/Class:%20AntonioError#stacktracelimit) + +### Methods + +- [captureStackTrace](../wiki/Class:%20AntonioError#capturestacktrace) + +## Constructors + +### constructor + +• **new AntonioError**(`request`, `response`, `data`) + +#### Type parameters + +| Name | Type | +| :--- | :-------------- | +| `D` | `D` = `unknown` | + +#### Parameters + +| Name | Type | +| :--------- | :--------- | +| `request` | `Request` | +| `response` | `Response` | +| `data` | `D` | + +#### Overrides + +Error.constructor + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:8](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L8) + +## Properties + +### data + +• **data**: `D` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:7](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L7) + +--- + +### isAntonioError + +• **isAntonioError**: `true` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:8](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L8) + +--- + +### message + +• **message**: `string` + +#### Inherited from + +Error.message + +#### Defined in + +node_modules/typescript/lib/lib.es5.d.ts:974 + +--- + +### name + +• **name**: `"AntonioError"` + +#### Overrides + +Error.name + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:4](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L4) + +--- + +### request + +• **request**: `Request` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:5](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L5) + +--- + +### response + +• **response**: `Response` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:6](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L6) + +--- + +### stack + +• `Optional` **stack**: `string` + +#### Inherited from + +Error.stack + +#### Defined in + +node_modules/typescript/lib/lib.es5.d.ts:975 + +--- + +### prepareStackTrace + +▪ `Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` + +#### Type declaration + +▸ (`err`, `stackTraces`): `any` + +Optional override for formatting stack traces + +##### Parameters + +| Name | Type | +| :------------ | :----------- | +| `err` | `Error` | +| `stackTraces` | `CallSite`[] | + +##### Returns + +`any` + +#### Inherited from + +Error.prepareStackTrace + +#### Defined in + +node_modules/@types/node/globals.d.ts:11 + +--- + +### stackTraceLimit + +▪ `Static` **stackTraceLimit**: `number` + +#### Inherited from + +Error.stackTraceLimit + +#### Defined in + +node_modules/@types/node/globals.d.ts:13 + +## Methods + +### captureStackTrace + +▸ `Static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` + +Create .stack property on a target object + +#### Parameters + +| Name | Type | +| :---------------- | :--------- | +| `targetObject` | `object` | +| `constructorOpt?` | `Function` | + +#### Returns + +`void` + +#### Inherited from + +Error.captureStackTrace + +#### Defined in + +node_modules/@types/node/globals.d.ts:4 diff --git a/packages/@ackee/antonio-core/docs/api/Exports.md b/packages/@ackee/antonio-core/docs/api/Exports.md new file mode 100644 index 0000000..9c9066e --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Exports.md @@ -0,0 +1,335 @@ +## Table of contents + +### Classes + +- [Antonio](../wiki/Class:%20Antonio) +- [AntonioError](../wiki/Class:%20AntonioError) + +### Interfaces + +- [RequestConfig](../wiki/Interface:%20RequestConfig) +- [RequestParams](../wiki/Interface:%20RequestParams) +- [RequestResult](../wiki/Interface:%20RequestResult) + +### Type aliases + +- [GeneralConfig](../wiki/Exports#generalconfig) +- [RequestBodyData](../wiki/Exports#requestbodydata) +- [RequestHeaders](../wiki/Exports#requestheaders) +- [RequestSearchParams](../wiki/Exports#requestsearchparams) +- [RequestUriParams](../wiki/Exports#requesturiparams) +- [ResolverType](../wiki/Exports#resolvertype) +- [ResponseData](../wiki/Exports#responsedata) +- [ResponseDataType](../wiki/Exports#responsedatatype) + +### Variables + +- [resolverTypes](../wiki/Exports#resolvertypes) + +### Functions + +- [generatorToPromise](../wiki/Exports#generatortopromise) +- [isAntonioError](../wiki/Exports#isantonioerror) +- [runIterableStream](../wiki/Exports#runiterablestream) + +## Type aliases + +### GeneralConfig + +Ƭ **GeneralConfig**: `Object` + +#### Type declaration + +| Name | Type | +| :------- | :----------- | +| `logger` | `RootLogger` | + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/general-config/index.ts:4](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/general-config/index.ts#L4) + +--- + +### RequestBodyData + +Ƭ **RequestBodyData**: `BodyInit` \| `Primitive` \| `object` \| `any`[] + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:7](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L7) + +--- + +### RequestHeaders + +Ƭ **RequestHeaders**: `Headers` \| `HeadersInit` \| { [key: string]: `string`; } + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:85](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L85) + +--- + +### RequestSearchParams + +Ƭ **RequestSearchParams**: `URLSearchParams` \| { [key: string]: `string` \| `number` \| `boolean` \| (`string` \| `number` \| `boolean`)[]; } + +An instace of `URLSearchParams` or a plain object. + +**`example`** + +```ts +api.get('/posts', { + params: new URLSearchParams({ + page: 1, + limit: 20, + }), +}); +``` + +**`example`** + +```ts +api.get('/posts', { + params: { + page: 1, + limit: 20, + userIds: [1, 2, 3], + }, +}); +``` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:128](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L128) + +--- + +### RequestUriParams + +Ƭ **RequestUriParams**: `Object` + +**`example`** + +```ts +const { data } = + yield * + api.get('/user/:id', { + uriParams: { id: '1' }, + }); + +console.assert(data.id === '1'); +``` + +#### Index signature + +▪ [key: `string`]: `string` \| `number` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:102](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L102) + +--- + +### ResolverType + +Ƭ **ResolverType**: typeof [resolverTypes](../wiki/Exports#resolvertypes)[`ResolverTypesKeys`] + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/constants/index.ts:7](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/constants/index.ts#L7) + +--- + +### ResponseData + +Ƭ **ResponseData**: `ArrayBuffer` \| `FormData` \| `ReadableStream` \| `ArrayBufferView` \| `Blob` \| `Primitive` \| `object` \| `any`[] \| `IterableStream` \| `null` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:73](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L73) + +--- + +### ResponseDataType + +Ƭ **ResponseDataType**: `"json"` \| `"blob"` \| `"formData"` \| `"text"` \| `"arrayBuffer"` \| `"iterableStream"` \| `"stream"` + +It defines the format of the returned `data` property in the request result object (`RequestResult`): + +- `json` -> `data === await response.json()` +- `text` -> `data === await response.text()` +- ... + +#### Default behavior based on `Content-Type` header + +Antonio selects the `responseDataType` by default based on the response `Content-Type` header (its mime type). +Based on that it chooses method for formatting the body: + +- `Content-Type: application/json` refers to `response.json()` method. +- `text/*` -> `response.text()` method. +- `image/*`, `audio/*`, `video/*`, `application/octet-stream` -> `response.arrayBuffer()`. +- `multipart/form-data` -> `response.formData()` + +Without `Content-Type` or without explicitly defined `responseDataType`, it returns `data` as `null`. + +#### Exception with `Content-Length` header + +Note that if the `Content-Length` header is `'0'`, then formatting body is skip completely and `data` are `null`. + +#### Streaming the response + +Selecting `iterableStream` response data type fetches data with `ReadableStream`. +The `data` is going to be async generator that yields out slices of data. +If the `Content-Type` response header has `application/json` mime type, +then the received chunk of string from the stream is going to be parsed as json +and the `slice` and once a valid json is created, it's yielded out as the `slice`. + +**Note that both examples are functionally identical.** + +_#1 Using async generators:_ + +**`example`** + +```ts +async function* fetchPosts() { + const { data } = yield* api.get('/posts', { + responseDataType: 'iterableStream', + }); + + for await (const slice of data) { + console.log(slice); // -> [{ title: '1' }, { title: '2' }, ...] + } +} +``` + +_#2 Using sync generators:_ + +**`example`** + +```ts +import { runIterableStream } from `@ackee/antonio-core`; + +function* fetchPosts() { + const { data } = yield* api.get('/posts', { + responseDataType: 'iterableStream', + }); + + yield runIterableStream(data, function* (slice) { + console.log(slice); // -> [{ title: '1' }, { title: '2' }, ...] + }); +} +``` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:71](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L71) + +## Variables + +### resolverTypes + +• `Const` **resolverTypes**: `Object` + +#### Type declaration + +| Name | Type | +| :---------- | :------------ | +| `GENERATOR` | `"generator"` | +| `PROMISE` | `"promise"` | + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/constants/index.ts:1](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/constants/index.ts#L1) + +## Functions + +### generatorToPromise + +▸ **generatorToPromise**(`it`): `Promise` + +#### Type parameters + +| Name | +| :--- | +| `T` | + +#### Parameters + +| Name | Type | +| :--- | :------------------------------------------------ | +| `it` | `AsyncGenerator` \| `Generator` | + +#### Returns + +`Promise` + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/core/makeRequest.ts:8](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/core/makeRequest.ts#L8) + +--- + +### isAntonioError + +▸ `Const` **isAntonioError**(`error`): error is AntonioError + +#### Parameters + +| Name | Type | +| :------ | :---- | +| `error` | `any` | + +#### Returns + +error is AntonioError + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/errors/index.ts:21](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/errors/index.ts#L21) + +--- + +### runIterableStream + +▸ **runIterableStream**(`it`, `onProgress`): `Generator`\>, void, any\> + +Converts async generator to sync generator. +Use it to handle `iterableStream` response data type. + +**`example`** + +```ts +import { runIterableStream } from `@ackee/antonio-core`; + +function* fetchPosts() { + const { data } = yield* api.get('/posts', { + responseDataType: 'iterableStream', + }); + + yield runIterableStream(data, function* (slice) { + console.log(slice); // -> [{ title: '1' }, { title: '2' }, ...] + }); +} +``` + +#### Type parameters + +| Name | Type | +| :--- | :------------------------ | +| `T` | `T` = `string` \| `any`[] | + +#### Parameters + +| Name | Type | +| :----------- | :---------------------------------- | +| `it` | `AsyncGenerator` | +| `onProgress` | `OnProgress` | + +#### Returns + +`Generator`\>, void, any\> + +#### Defined in + +[packages/@ackee/antonio-core/src/modules/response/utils/runIterableStream.ts:24](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/modules/response/utils/runIterableStream.ts#L24) diff --git a/packages/@ackee/antonio-core/docs/api/Home.md b/packages/@ackee/antonio-core/docs/api/Home.md new file mode 100644 index 0000000..28ae916 --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Home.md @@ -0,0 +1,88 @@ +![ackee|Antonio](/assets/ackee_git_frontend_antonio.png) + +# [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/AckeeCZ/antonio/blob/master/LICENSE) [![CI Status](https://img.shields.io/travis/com/AckeeCZ/antonio.svg?style=flat)](https://travis-ci.com/AckeeCZ/antonio) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request) [![Dependency Status](https://img.shields.io/david/AckeeCZ/antonio.svg?style=flat-square)](https://david-dm.org/AckeeCZ/antonio) [![bundlephobia](https://flat.badgen.net/bundlephobia/min/@ackee/antonio-core)](https://bundlephobia.com/result?p=@ackee/antonio-core) [![bundlephobia](https://flat.badgen.net/bundlephobia/minzip/@ackee/antonio-core)](https://bundlephobia.com/result?p=@ackee/antonio-core) ![node version](https://img.shields.io/node/v/@ackee/antonio-core) + +# `@ackee/antonio-core` + +HTTP client built on Fetch API. + +## Table of contents + +- [Install](#install) +- [Usage](#usage) +- [API](./docs-api/modules.md) + +--- + +## Install + +```bash +yarn add @ackee/antonio-core -S +``` + +--- + +## Usage + +```js +import { Antonio } from '@ackee/antonio-core'; + +const api = new Antonio({ + baseURL: 'https://jsonplaceholder.typicode.com/', +}); + +function* fetchTodos() { + // Since api.get returns generator function, `yield*` is required. + const { data, request, response } = yield* api.get('/todos', { + params: { + page: 1, + limit: 20, + }, + }); +} +``` + +--- + +## API + +### `new Antonio(requestConfig?: RequestConfig, generalConfig?: GeneralConfig)` + +Creates a new instance of `Antonio` with custom request config and general config: + +```ts +import { Antonio } from '@ackee/antonio-core'; + +const api = new Antonio({ + baseURL: 'https://some-domain.com/api/', +}); +``` + +#### Instance methods + +```ts +api.get(url: string, requestConfig?: RequestConfig): Generator + +api.delete(url: string, requestConfig?: RequestConfig): Generator + +api.head(url: string, requestConfig?: RequestConfig): Generator + +api.options(url: string, requestConfig?: RequestConfig): Generator + +api.post(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator + +api.put(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator + +api.patch(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator +``` + +## `generalConfig: GeneralConfig` + +Optional `@ackee/antonio-core` configuration: + +```ts +{ + // Default is [`loglevel`](https://www.npmjs.com/package/loglevel) + logger: loglevel, +} +``` diff --git a/packages/@ackee/antonio-core/docs/api/Interface: RequestConfig.md b/packages/@ackee/antonio-core/docs/api/Interface: RequestConfig.md new file mode 100644 index 0000000..f01a6c0 --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Interface: RequestConfig.md @@ -0,0 +1,251 @@ +## Hierarchy + +- `Omit` + + ↳ **RequestConfig** + +## Table of contents + +### Properties + +- [baseURL](../wiki/Interface:%20RequestConfig#baseurl) +- [cache](../wiki/Interface:%20RequestConfig#cache) +- [cancelToken](../wiki/Interface:%20RequestConfig#canceltoken) +- [credentials](../wiki/Interface:%20RequestConfig#credentials) +- [headers](../wiki/Interface:%20RequestConfig#headers) +- [integrity](../wiki/Interface:%20RequestConfig#integrity) +- [keepalive](../wiki/Interface:%20RequestConfig#keepalive) +- [mode](../wiki/Interface:%20RequestConfig#mode) +- [params](../wiki/Interface:%20RequestConfig#params) +- [redirect](../wiki/Interface:%20RequestConfig#redirect) +- [referrer](../wiki/Interface:%20RequestConfig#referrer) +- [referrerPolicy](../wiki/Interface:%20RequestConfig#referrerpolicy) +- [responseDataType](../wiki/Interface:%20RequestConfig#responsedatatype) +- [signal](../wiki/Interface:%20RequestConfig#signal) +- [uriParams](../wiki/Interface:%20RequestConfig#uriparams) +- [window](../wiki/Interface:%20RequestConfig#window) + +## Properties + +### baseURL + +• `Optional` **baseURL**: `string` + +`baseURL` will be prepended to `url` unless `url` is absolute. +It can be convenient to set `baseURL` for an instance of antonio to pass relative URLs. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:139](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L139) + +--- + +### cache + +• `Optional` **cache**: `RequestCache` + +A string indicating how the request will interact with the browser's cache to set request's cache. + +#### Inherited from + +Omit.cache + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1610 + +--- + +### cancelToken + +• `Optional` **cancelToken**: `AbortSignal` + +**`deprecated`** This prop is going to be removed in next major relase. Use `signal` prop instead. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:152](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L152) + +--- + +### credentials + +• `Optional` **credentials**: `RequestCredentials` + +A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. + +#### Inherited from + +Omit.credentials + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1614 + +--- + +### headers + +• `Optional` **headers**: [RequestHeaders](../wiki/Exports#requestheaders) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:145](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L145) + +--- + +### integrity + +• `Optional` **integrity**: `string` + +A cryptographic hash of the resource to be fetched by request. Sets request's integrity. + +#### Inherited from + +Omit.integrity + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1622 + +--- + +### keepalive + +• `Optional` **keepalive**: `boolean` + +A boolean to set request's keepalive. + +#### Inherited from + +Omit.keepalive + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1626 + +--- + +### mode + +• `Optional` **mode**: `RequestMode` + +A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. + +#### Inherited from + +Omit.mode + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1634 + +--- + +### params + +• `Optional` **params**: [RequestSearchParams](../wiki/Exports#requestsearchparams) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:147](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L147) + +--- + +### redirect + +• `Optional` **redirect**: `RequestRedirect` + +A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. + +#### Inherited from + +Omit.redirect + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1638 + +--- + +### referrer + +• `Optional` **referrer**: `string` + +A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. + +#### Inherited from + +Omit.referrer + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1642 + +--- + +### referrerPolicy + +• `Optional` **referrerPolicy**: `ReferrerPolicy` + +A referrer policy to set request's referrerPolicy. + +#### Inherited from + +Omit.referrerPolicy + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1646 + +--- + +### responseDataType + +• `Optional` **responseDataType**: [ResponseDataType](../wiki/Exports#responsedatatype) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:141](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L141) + +--- + +### signal + +• `Optional` **signal**: `null` \| `AbortSignal` + +An AbortSignal to set request's signal. + +#### Inherited from + +Omit.signal + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1650 + +--- + +### uriParams + +• `Optional` **uriParams**: [RequestUriParams](../wiki/Exports#requesturiparams) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:143](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L143) + +--- + +### window + +• `Optional` **window**: `any` + +Can only be null. Used to disassociate request from any Window. + +#### Inherited from + +Omit.window + +#### Defined in + +node_modules/typescript/lib/lib.dom.d.ts:1654 diff --git a/packages/@ackee/antonio-core/docs/api/Interface: RequestParams.md b/packages/@ackee/antonio-core/docs/api/Interface: RequestParams.md new file mode 100644 index 0000000..39c4b1f --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Interface: RequestParams.md @@ -0,0 +1,37 @@ +## Table of contents + +### Properties + +- [bodyData](../wiki/Interface:%20RequestParams#bodydata) +- [config](../wiki/Interface:%20RequestParams#config) +- [url](../wiki/Interface:%20RequestParams#url) + +## Properties + +### bodyData + +• **bodyData**: [RequestBodyData](../wiki/Exports#requestbodydata) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:184](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L184) + +--- + +### config + +• **config**: [RequestConfig](../wiki/Interface:%20RequestConfig) + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:183](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L183) + +--- + +### url + +• **url**: `string` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:182](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L182) diff --git a/packages/@ackee/antonio-core/docs/api/Interface: RequestResult.md b/packages/@ackee/antonio-core/docs/api/Interface: RequestResult.md new file mode 100644 index 0000000..07825fe --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/Interface: RequestResult.md @@ -0,0 +1,95 @@ +## Type parameters + +| Name | Type | +| :--- | :---------- | +| `D` | `D` = `any` | + +## Table of contents + +### Properties + +- [config](../wiki/Interface:%20RequestResult#config) +- [data](../wiki/Interface:%20RequestResult#data) +- [headers](../wiki/Interface:%20RequestResult#headers) +- [request](../wiki/Interface:%20RequestResult#request) +- [response](../wiki/Interface:%20RequestResult#response) +- [status](../wiki/Interface:%20RequestResult#status) +- [statusText](../wiki/Interface:%20RequestResult#statustext) + +## Properties + +### config + +• **config**: `Object` + +**`deprecated`** This prop is going to be removed in next major relase. Depend on properties in the `request`. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:178](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L178) + +--- + +### data + +• **data**: `D` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:158](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L158) + +--- + +### headers + +• **headers**: `Object` + +**`deprecated`** This prop is going to be removed in next major relase. Use `response.headers` instead. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:173](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L173) + +--- + +### request + +• **request**: `Request` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:156](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L156) + +--- + +### response + +• **response**: `Response` + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:157](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L157) + +--- + +### status + +• **status**: `number` + +**`deprecated`** This prop is going to be removed in next major relase. Use `response.status` instead. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:163](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L163) + +--- + +### statusText + +• **statusText**: `string` + +**`deprecated`** This prop is going to be removed in next major relase. Use `response.statusText` instead. + +#### Defined in + +[packages/@ackee/antonio-core/src/types.ts:168](https://github.com/AckeeCZ/antonio/blob/d2bc82d/packages/@ackee/antonio-core/src/types.ts#L168) diff --git a/packages/@ackee/antonio-core/docs/api/_Sidebar.md b/packages/@ackee/antonio-core/docs/api/_Sidebar.md new file mode 100644 index 0000000..3f796b2 --- /dev/null +++ b/packages/@ackee/antonio-core/docs/api/_Sidebar.md @@ -0,0 +1,15 @@ +## @ackee/antonio-core - v4.0.0-beta.27 + +- [Home](../wiki/Home) +- [Exports](../wiki/Exports) + +### Classes + +- [Antonio](../wiki/Class:%20Antonio) +- [AntonioError](../wiki/Class:%20AntonioError) + +### Interfaces + +- [RequestConfig](../wiki/Interface:%20RequestConfig) +- [RequestParams](../wiki/Interface:%20RequestParams) +- [RequestResult](../wiki/Interface:%20RequestResult)