@basmilius/http-client 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/HttpAdapter.d.ts +6 -6
- package/dist/adapter/index.d.ts +1 -1
- package/dist/decorator/adapter.d.ts +2 -2
- package/dist/decorator/bound.d.ts +1 -1
- package/dist/decorator/debounce.d.ts +1 -1
- package/dist/decorator/dto/arrayProxy.d.ts +15 -15
- package/dist/decorator/dto/classProxy.d.ts +8 -8
- package/dist/decorator/dto/clone.d.ts +4 -4
- package/dist/decorator/dto/constant.d.ts +7 -7
- package/dist/decorator/dto/fill.d.ts +4 -4
- package/dist/decorator/dto/helper/areEqual.d.ts +4 -4
- package/dist/decorator/dto/helper/assertDto.d.ts +4 -4
- package/dist/decorator/dto/helper/circularProtect.d.ts +1 -1
- package/dist/decorator/dto/helper/cloneDto.d.ts +3 -3
- package/dist/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.d.ts +7 -4
- package/dist/decorator/dto/helper/index.d.ts +17 -17
- package/dist/decorator/dto/helper/instance.d.ts +2 -2
- package/dist/decorator/dto/helper/isDto.d.ts +4 -4
- package/dist/decorator/dto/helper/isDtoClean.d.ts +3 -3
- package/dist/decorator/dto/helper/isDtoDirty.d.ts +3 -3
- package/dist/decorator/dto/helper/markDtoClean.d.ts +2 -2
- package/dist/decorator/dto/helper/markDtoDirty.d.ts +2 -2
- package/dist/decorator/dto/helper/relateDtoTo.d.ts +4 -4
- package/dist/decorator/dto/helper/relateValueTo.d.ts +4 -4
- package/dist/decorator/dto/helper/trackDto.d.ts +3 -3
- package/dist/decorator/dto/helper/triggerDto.d.ts +3 -3
- package/dist/decorator/dto/helper/unrelateDtoFrom.d.ts +4 -4
- package/dist/decorator/dto/helper/unrelateValueFrom.d.ts +4 -4
- package/dist/decorator/dto/index.d.ts +6 -6
- package/dist/decorator/dto/instanceProxy.d.ts +21 -21
- package/dist/decorator/dto/map.d.ts +2 -2
- package/dist/decorator/dto/refProxy.d.ts +30 -30
- package/dist/decorator/dto/serialize/deserialize.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeArray.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeDateTime.d.ts +3 -3
- package/dist/decorator/dto/serialize/deserializeDto.d.ts +3 -3
- package/dist/decorator/dto/serialize/deserializeObject.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeUnknown.d.ts +1 -1
- package/dist/decorator/dto/serialize/index.d.ts +2 -2
- package/dist/decorator/dto/serialize/isSerializedDateTime.d.ts +2 -2
- package/dist/decorator/dto/serialize/isSerializedDto.d.ts +2 -2
- package/dist/decorator/dto/serialize/serialize.d.ts +1 -1
- package/dist/decorator/dto/serialize/serializeArray.d.ts +2 -2
- package/dist/decorator/dto/serialize/serializeDateTime.d.ts +3 -3
- package/dist/decorator/dto/serialize/serializeDto.d.ts +3 -3
- package/dist/decorator/dto/serialize/serializeObject.d.ts +1 -1
- package/dist/decorator/dto/serialize/serializeUnknown.d.ts +2 -2
- package/dist/decorator/dto/serialize/uuid.d.ts +1 -1
- package/dist/decorator/dto/toJSON.d.ts +4 -4
- package/dist/decorator/index.d.ts +7 -7
- package/dist/dto/BlobResponse.d.ts +4 -4
- package/dist/dto/Paginated.d.ts +7 -7
- package/dist/dto/RequestError.d.ts +7 -7
- package/dist/dto/ValidationError.d.ts +7 -7
- package/dist/dto/index.d.ts +4 -4
- package/dist/http/BaseResponse.d.ts +8 -8
- package/dist/http/BaseService.d.ts +3 -3
- package/dist/http/HttpClient.d.ts +8 -8
- package/dist/http/QueryString.d.ts +11 -12
- package/dist/http/RequestBuilder.d.ts +32 -29
- package/dist/http/helpers.d.ts +1 -1
- package/dist/http/index.d.ts +6 -6
- package/dist/http-client.js +12 -35
- package/dist/http-client.js.map +17 -18
- package/dist/index.d.ts +5 -5
- package/package.json +7 -8
- package/dist/decorator/dto/instance.d.ts +0 -29
- package/dist/decorator/dto/serialize/types.d.ts +0 -3
- package/dist/type/index.d.ts +0 -2
package/dist/dto/Paginated.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default class Paginated<T> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
#private;
|
|
3
|
+
get items(): T[];
|
|
4
|
+
get page(): number;
|
|
5
|
+
get pageSize(): number;
|
|
6
|
+
get pages(): number;
|
|
7
|
+
get totalItems(): number;
|
|
8
|
+
constructor(items: T[], page: number, pageSize: number, pages: number, totalItems: number);
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { HttpStatusCode } from
|
|
1
|
+
import type { HttpStatusCode } from "../type";
|
|
2
2
|
export default class RequestError {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
#private;
|
|
4
|
+
get code(): number;
|
|
5
|
+
get error(): string;
|
|
6
|
+
get errorDescription(): string;
|
|
7
|
+
get statusCode(): HttpStatusCode;
|
|
8
|
+
constructor(code: number, error: string, errorDescription: string, statusCode: HttpStatusCode);
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default class ValidationError {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
#private;
|
|
3
|
+
get code(): number;
|
|
4
|
+
get error(): string;
|
|
5
|
+
get errorDescription(): string;
|
|
6
|
+
get errors(): Record<string, ValidationError>;
|
|
7
|
+
get params(): Record<string, string | number | boolean>;
|
|
8
|
+
constructor(code: number, error: string, errorDescription: string, errors?: Record<string, ValidationError>, params?: Record<string, string | number | boolean>);
|
|
9
9
|
}
|
package/dist/dto/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as BlobResponse } from
|
|
2
|
-
export { default as Paginated } from
|
|
3
|
-
export { default as RequestError } from
|
|
4
|
-
export { default as ValidationError } from
|
|
1
|
+
export { default as BlobResponse } from "./BlobResponse";
|
|
2
|
+
export { default as Paginated } from "./Paginated";
|
|
3
|
+
export { default as RequestError } from "./RequestError";
|
|
4
|
+
export { default as ValidationError } from "./ValidationError";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { HttpStatusCode } from
|
|
1
|
+
import type { HttpStatusCode } from "../type";
|
|
2
2
|
export default class BaseResponse<T> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
#private;
|
|
4
|
+
get data(): T;
|
|
5
|
+
get headers(): Headers;
|
|
6
|
+
get ok(): boolean;
|
|
7
|
+
get response(): Response;
|
|
8
|
+
get statusCode(): HttpStatusCode;
|
|
9
|
+
constructor(data: T, response: Response);
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import HttpClient from
|
|
2
|
-
import RequestBuilder from
|
|
1
|
+
import HttpClient from "./HttpClient";
|
|
2
|
+
import RequestBuilder from "./RequestBuilder";
|
|
3
3
|
export default class BaseService {
|
|
4
|
-
|
|
4
|
+
protected request(path: string, client?: HttpClient): RequestBuilder;
|
|
5
5
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export default class HttpClient {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
#private;
|
|
3
|
+
get authToken(): string | null;
|
|
4
|
+
set authToken(value: string | null);
|
|
5
|
+
get baseUrl(): string;
|
|
6
|
+
get dataField(): boolean;
|
|
7
|
+
constructor(authToken: string | null, baseUrl: string, dataField?: boolean);
|
|
8
|
+
static get instance(): HttpClient;
|
|
9
|
+
static register(client: HttpClient): void;
|
|
10
10
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export default class QueryString {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
#private;
|
|
3
|
+
constructor();
|
|
4
|
+
build(): string;
|
|
5
|
+
append(name: string, value: QueryStringValue): QueryString;
|
|
6
|
+
appendArray(name: string, values: QueryStringValue[] | null): QueryString;
|
|
7
|
+
delete(name: string): QueryString;
|
|
8
|
+
get(name: string): string | null;
|
|
9
|
+
getAll(name: string): string[];
|
|
10
|
+
has(name: string): boolean;
|
|
11
|
+
set(name: string, value: QueryStringValue): QueryString;
|
|
12
|
+
static builder(): QueryString;
|
|
13
13
|
}
|
|
14
14
|
type QueryStringValue = boolean | number | string | null;
|
|
15
|
-
export {};
|
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import { BlobResponse, Paginated } from
|
|
2
|
-
import type { HttpMethod, HttpStatusCode } from
|
|
3
|
-
import BaseResponse from
|
|
4
|
-
import HttpClient from
|
|
5
|
-
import type QueryString from
|
|
1
|
+
import { BlobResponse, Paginated } from "../dto";
|
|
2
|
+
import type { HttpMethod, HttpStatusCode } from "../type";
|
|
3
|
+
import BaseResponse from "./BaseResponse";
|
|
4
|
+
import HttpClient from "./HttpClient";
|
|
5
|
+
import type QueryString from "./QueryString";
|
|
6
6
|
export default class RequestBuilder {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
#private;
|
|
8
|
+
get client(): HttpClient;
|
|
9
|
+
get options(): RequestInit;
|
|
10
|
+
get path(): string;
|
|
11
|
+
set path(value: string);
|
|
12
|
+
get query(): QueryString | null;
|
|
13
|
+
set query(value: QueryString | null);
|
|
14
|
+
constructor(path: string, client?: HttpClient);
|
|
15
|
+
bearerToken(token?: string): RequestBuilder;
|
|
16
|
+
body(body: BodyInit | FormData | object | null, contentType?: string | null): RequestBuilder;
|
|
17
|
+
header(name: string, value: string): RequestBuilder;
|
|
18
|
+
method(method: HttpMethod): RequestBuilder;
|
|
19
|
+
queryString(queryString: QueryString): RequestBuilder;
|
|
20
|
+
signal(signal?: AbortSignal | null): RequestBuilder;
|
|
21
|
+
fetch<TResult>(): Promise<TResult>;
|
|
22
|
+
fetchBlob(): Promise<BlobResponse>;
|
|
23
|
+
run<TResult extends {}>(): Promise<BaseResponse<TResult>>;
|
|
24
|
+
runAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult>>;
|
|
25
|
+
runArrayAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult[]>>;
|
|
26
|
+
runEmpty(): Promise<BaseResponse<never>>;
|
|
27
|
+
runPaginatedAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<Paginated<TResult>>>;
|
|
28
|
+
runData<TResult>(): Promise<BaseResponse<TResult>>;
|
|
29
|
+
runDataKey<
|
|
30
|
+
TResult extends object,
|
|
31
|
+
TKey extends keyof TResult = keyof TResult
|
|
32
|
+
>(key: TKey): Promise<BaseResponse<TResult[TKey]>>;
|
|
33
|
+
runStatusCode(): Promise<HttpStatusCode>;
|
|
31
34
|
}
|
package/dist/http/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestError, ValidationError } from
|
|
1
|
+
import { RequestError, ValidationError } from "../dto";
|
|
2
2
|
export declare function isRequestError(obj: unknown): obj is RequestError;
|
|
3
3
|
export declare function isUnsanctionedRequest(statusCode: unknown): boolean;
|
|
4
4
|
export declare function isValidationError(obj: unknown): obj is ValidationError;
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BaseResponse from
|
|
2
|
-
import BaseService from
|
|
3
|
-
import HttpClient from
|
|
4
|
-
import QueryString from
|
|
5
|
-
import RequestBuilder from
|
|
1
|
+
import BaseResponse from "./BaseResponse";
|
|
2
|
+
import BaseService from "./BaseService";
|
|
3
|
+
import HttpClient from "./HttpClient";
|
|
4
|
+
import QueryString from "./QueryString";
|
|
5
|
+
import RequestBuilder from "./RequestBuilder";
|
|
6
6
|
export { BaseResponse, BaseService, HttpClient, QueryString, RequestBuilder };
|
|
7
|
-
export { isRequestError, isUnsanctionedRequest, isValidationError } from
|
|
7
|
+
export { isRequestError, isUnsanctionedRequest, isValidationError } from "./helpers";
|
package/dist/http-client.js
CHANGED
|
@@ -55,31 +55,8 @@ function debounce(fn, interval, $this) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
const entries = {};
|
|
61
|
-
do {
|
|
62
|
-
if (obj.name === "") {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(obj.prototype))) {
|
|
66
|
-
if (["constructor", "clone", "toJSON"].includes(key)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (!descriptor.get && !descriptor.set) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
entries[key] = descriptor;
|
|
73
|
-
}
|
|
74
|
-
} while (obj = Object.getPrototypeOf(obj));
|
|
75
|
-
return entries;
|
|
76
|
-
}
|
|
77
|
-
function setObjectMethod_default(obj, key, fn) {
|
|
78
|
-
obj.prototype[key] = fn;
|
|
79
|
-
}
|
|
80
|
-
function setObjectValue_default(obj, key, value) {
|
|
81
|
-
Object.defineProperty(obj, key, { value });
|
|
82
|
-
}
|
|
58
|
+
// src/decorator/dto/index.ts
|
|
59
|
+
import { getPrototypeChain, setObjectMethod, setObjectValue } from "@basmilius/utils";
|
|
83
60
|
|
|
84
61
|
// src/decorator/dto/constant.ts
|
|
85
62
|
var ENABLE_CIRCULAR_LOGGING = false;
|
|
@@ -457,15 +434,15 @@ function toJSON_default() {
|
|
|
457
434
|
// src/decorator/dto/index.ts
|
|
458
435
|
function dto_default(clazz) {
|
|
459
436
|
validate(clazz);
|
|
460
|
-
const descriptors = Object.freeze(
|
|
437
|
+
const descriptors = Object.freeze(getPrototypeChain(clazz));
|
|
461
438
|
const properties = Object.keys(descriptors);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
439
|
+
setObjectValue(clazz.prototype, DESCRIPTORS, descriptors);
|
|
440
|
+
setObjectValue(clazz.prototype, NAME, clazz.name);
|
|
441
|
+
setObjectValue(clazz.prototype, PROPERTIES, properties);
|
|
442
|
+
setObjectValue(clazz, Symbol.hasInstance, (instance) => typeof instance === "object" && instance?.[NAME] === clazz.name);
|
|
443
|
+
setObjectMethod(clazz, "clone", clone_default);
|
|
444
|
+
setObjectMethod(clazz, "fill", fill_default);
|
|
445
|
+
setObjectMethod(clazz, "toJSON", toJSON_default);
|
|
469
446
|
return proxy(clazz);
|
|
470
447
|
}
|
|
471
448
|
function proxy(clazz) {
|
|
@@ -520,7 +497,7 @@ function deserializeObject_default(obj) {
|
|
|
520
497
|
var CACHE = {};
|
|
521
498
|
function deserializeDto_default([, id, name, state, args]) {
|
|
522
499
|
if (!(name in DTO_CLASS_MAP)) {
|
|
523
|
-
throw new Error(`
|
|
500
|
+
throw new Error(`Cannot restore @dto. Dto ${name} was not found.`);
|
|
524
501
|
}
|
|
525
502
|
if (id in CACHE) {
|
|
526
503
|
return CACHE[id];
|
|
@@ -1114,5 +1091,5 @@ export {
|
|
|
1114
1091
|
BaseResponse
|
|
1115
1092
|
};
|
|
1116
1093
|
|
|
1117
|
-
//# debugId=
|
|
1094
|
+
//# debugId=AD0CA21D25D97D8A64756E2164756E21
|
|
1118
1095
|
//# sourceMappingURL=http-client.js.map
|