Skip to content

Commit

Permalink
chore(release): v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcachips authored and Marcachips committed Jun 10, 2023
1 parent 59d7f22 commit 65cd973
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 43 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# [1.3.0](https://github.com/klientjs/core/compare/1.2.1...1.3.0) (2023-06-10)


### Features

* make request resolve and reject method protected ([59d7f22](https://github.com/klientjs/core/commit/59d7f226af812560bdc613abaa13e0c126dca7db))

# [1.2.0](https://github.com/klientjs/core/compare/1.1.0...1.2.0) (2023-06-09)


Expand Down
16 changes: 10 additions & 6 deletions dist/cjs/services/request/request.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { AxiosResponse, AxiosError, AxiosRequestConfig, AxiosPromise } from 'axios';
import RequestEvent from '../../events/request/request';
import RequestSuccessEvent from '../../events/request/success';
import RequestErrorEvent from '../../events/request/error';
import RequestCancelEvent from '../../events/request/cancel';
import type Klient from '../..';
export declare type ResolveRequest = (response: AxiosResponse) => void;
export declare type RejectRequest = (error: AxiosError) => void;
Expand All @@ -8,6 +11,7 @@ declare type PromiseCallbacks = {
resolve: ResolveRequest;
reject: RejectRequest;
};
declare type RequestEventTypes = typeof RequestSuccessEvent | typeof RequestErrorEvent | typeof RequestCancelEvent;
declare type RequestContext = Record<string, any>;
export interface KlientRequestConfig extends AxiosRequestConfig {
context?: RequestContext;
Expand All @@ -23,13 +27,13 @@ export default class Request<T = unknown> extends Promise<AxiosResponse<T>> {
protected readonly abortController: AbortController;
protected constructor(callback: RequestCallback);
static new<T>({ context, ...axiosConfig }: KlientRequestConfig, klient: Klient): Request<T>;
resolve(response: AxiosResponse<T>): Promise<void>;
reject(error: AxiosError): Promise<void>;
static isCancel(e: Error): boolean;
cancel(): this;
execute(): this;
private doRequest;
private dispatchResultEvent;
private get dispatcher();
static isCancel(e: Error): boolean;
protected doRequest(): this;
protected resolve(response: AxiosResponse<T>): Promise<void>;
protected reject(error: AxiosError): Promise<void>;
protected dispatchResultEvent(EventClass: RequestEventTypes): Promise<void>;
protected get dispatcher(): import("../..").Dispatcher;
}
export {};
28 changes: 14 additions & 14 deletions dist/cjs/services/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,8 @@ class Request extends Promise {
request.context = Object.assign(Object.assign({}, request.context), context);
return request;
}
resolve(response) {
this.result = response;
return this.dispatchResultEvent(success_1.default).then(() => {
this.callbacks.resolve(this.result);
});
}
reject(error) {
this.result = error;
return this.dispatchResultEvent(Request.isCancel(error) ? cancel_1.default : error_1.default).then(() => {
this.callbacks.reject(this.result);
});
static isCancel(e) {
return axios_1.default.isCancel(e);
}
cancel() {
this.abortController.abort();
Expand Down Expand Up @@ -79,6 +70,18 @@ class Request extends Promise {
}
return this;
}
resolve(response) {
this.result = response;
return this.dispatchResultEvent(success_1.default).then(() => {
this.callbacks.resolve(this.result);
});
}
reject(error) {
this.result = error;
return this.dispatchResultEvent(Request.isCancel(error) ? cancel_1.default : error_1.default).then(() => {
this.callbacks.reject(this.result);
});
}
dispatchResultEvent(EventClass) {
const event = new EventClass(this.primaryEvent);
return new Promise((resolve) => {
Expand All @@ -93,8 +96,5 @@ class Request extends Promise {
get dispatcher() {
return this.klient.dispatcher;
}
static isCancel(e) {
return axios_1.default.isCancel(e);
}
}
exports.default = Request;
16 changes: 10 additions & 6 deletions dist/esm/services/request/request.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { AxiosResponse, AxiosError, AxiosRequestConfig, AxiosPromise } from 'axios';
import RequestEvent from '../../events/request/request';
import RequestSuccessEvent from '../../events/request/success';
import RequestErrorEvent from '../../events/request/error';
import RequestCancelEvent from '../../events/request/cancel';
import type Klient from '../..';
export declare type ResolveRequest = (response: AxiosResponse) => void;
export declare type RejectRequest = (error: AxiosError) => void;
Expand All @@ -8,6 +11,7 @@ declare type PromiseCallbacks = {
resolve: ResolveRequest;
reject: RejectRequest;
};
declare type RequestEventTypes = typeof RequestSuccessEvent | typeof RequestErrorEvent | typeof RequestCancelEvent;
declare type RequestContext = Record<string, any>;
export interface KlientRequestConfig extends AxiosRequestConfig {
context?: RequestContext;
Expand All @@ -23,13 +27,13 @@ export default class Request<T = unknown> extends Promise<AxiosResponse<T>> {
protected readonly abortController: AbortController;
protected constructor(callback: RequestCallback);
static new<T>({ context, ...axiosConfig }: KlientRequestConfig, klient: Klient): Request<T>;
resolve(response: AxiosResponse<T>): Promise<void>;
reject(error: AxiosError): Promise<void>;
static isCancel(e: Error): boolean;
cancel(): this;
execute(): this;
private doRequest;
private dispatchResultEvent;
private get dispatcher();
static isCancel(e: Error): boolean;
protected doRequest(): this;
protected resolve(response: AxiosResponse<T>): Promise<void>;
protected reject(error: AxiosError): Promise<void>;
protected dispatchResultEvent(EventClass: RequestEventTypes): Promise<void>;
protected get dispatcher(): import("../..").Dispatcher;
}
export {};
28 changes: 14 additions & 14 deletions dist/esm/services/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,8 @@ export default class Request extends Promise {
request.context = Object.assign(Object.assign({}, request.context), context);
return request;
}
resolve(response) {
this.result = response;
return this.dispatchResultEvent(RequestSuccessEvent).then(() => {
this.callbacks.resolve(this.result);
});
}
reject(error) {
this.result = error;
return this.dispatchResultEvent(Request.isCancel(error) ? RequestCancelEvent : RequestErrorEvent).then(() => {
this.callbacks.reject(this.result);
});
static isCancel(e) {
return axios.isCancel(e);
}
cancel() {
this.abortController.abort();
Expand Down Expand Up @@ -77,6 +68,18 @@ export default class Request extends Promise {
}
return this;
}
resolve(response) {
this.result = response;
return this.dispatchResultEvent(RequestSuccessEvent).then(() => {
this.callbacks.resolve(this.result);
});
}
reject(error) {
this.result = error;
return this.dispatchResultEvent(Request.isCancel(error) ? RequestCancelEvent : RequestErrorEvent).then(() => {
this.callbacks.reject(this.result);
});
}
dispatchResultEvent(EventClass) {
const event = new EventClass(this.primaryEvent);
return new Promise((resolve) => {
Expand All @@ -91,7 +94,4 @@ export default class Request extends Promise {
get dispatcher() {
return this.klient.dispatcher;
}
static isCancel(e) {
return axios.isCancel(e);
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"axios",
"sdk"
],
"version": "1.2.1",
"version": "1.3.0",
"license": "MIT",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
Expand Down

0 comments on commit 65cd973

Please sign in to comment.