@basmilius/http-client 1.13.0 → 2.2.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/README.md +12 -34
- package/dist/decorator/dto/clone.d.ts +0 -3
- package/dist/decorator/dto/fill.d.ts +0 -3
- package/dist/decorator/dto/helper/areEqual.d.ts +0 -4
- package/dist/decorator/dto/helper/assertDto.d.ts +0 -3
- package/dist/decorator/dto/helper/cloneDto.d.ts +0 -3
- package/dist/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.d.ts +0 -3
- package/dist/decorator/dto/helper/isDto.d.ts +0 -3
- package/dist/decorator/dto/helper/isDtoClean.d.ts +0 -3
- package/dist/decorator/dto/helper/isDtoDirty.d.ts +0 -3
- package/dist/decorator/dto/helper/relateDtoTo.d.ts +0 -3
- package/dist/decorator/dto/helper/relateValueTo.d.ts +0 -3
- package/dist/decorator/dto/helper/trackDto.d.ts +0 -3
- package/dist/decorator/dto/helper/unrelateDtoFrom.d.ts +0 -3
- package/dist/decorator/dto/helper/unrelateValueFrom.d.ts +0 -3
- package/dist/decorator/dto/index.d.ts +1 -4
- package/dist/decorator/dto/toJSON.d.ts +0 -3
- package/dist/decorator/index.d.ts +1 -1
- package/dist/dto/Paginated.d.ts +2 -2
- package/dist/index.js +4 -0
- package/dist/{http-client.js.map → index.js.map} +4 -4
- package/package.json +14 -13
- package/src/adapter/HttpAdapter.ts +67 -0
- package/src/adapter/index.ts +1 -0
- package/src/decorator/adapter.ts +10 -0
- package/src/decorator/bound.ts +5 -0
- package/src/decorator/debounce.ts +30 -0
- package/src/decorator/dto/arrayProxy.ts +65 -0
- package/src/decorator/dto/classProxy.ts +49 -0
- package/src/decorator/dto/clone.ts +24 -0
- package/src/decorator/dto/constant.ts +7 -0
- package/src/decorator/dto/fill.ts +18 -0
- package/src/decorator/dto/helper/areEqual.ts +13 -0
- package/src/decorator/dto/helper/assertDto.ts +11 -0
- package/src/decorator/dto/helper/circularProtect.ts +35 -0
- package/src/decorator/dto/helper/cloneDto.ts +9 -0
- package/src/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.ts +16 -0
- package/src/decorator/dto/helper/index.ts +37 -0
- package/src/decorator/dto/helper/instance.ts +5 -0
- package/src/decorator/dto/helper/isDto.ts +9 -0
- package/src/decorator/dto/helper/isDtoClean.ts +10 -0
- package/src/decorator/dto/helper/isDtoDirty.ts +10 -0
- package/src/decorator/dto/helper/markDtoClean.ts +29 -0
- package/src/decorator/dto/helper/markDtoDirty.ts +26 -0
- package/src/decorator/dto/helper/relateDtoTo.ts +13 -0
- package/src/decorator/dto/helper/relateValueTo.ts +22 -0
- package/src/decorator/dto/helper/trackDto.ts +13 -0
- package/src/decorator/dto/helper/triggerDto.ts +18 -0
- package/src/decorator/dto/helper/unrelateDtoFrom.ts +15 -0
- package/src/decorator/dto/helper/unrelateValueFrom.ts +22 -0
- package/src/decorator/dto/index.ts +78 -0
- package/src/decorator/dto/instance.ts +33 -0
- package/src/decorator/dto/instanceProxy.ts +89 -0
- package/src/decorator/dto/map.ts +4 -0
- package/src/decorator/dto/refProxy.ts +61 -0
- package/src/decorator/dto/serialize/deserialize.ts +5 -0
- package/src/decorator/dto/serialize/deserializeArray.ts +5 -0
- package/src/decorator/dto/serialize/deserializeDateTime.ts +6 -0
- package/src/decorator/dto/serialize/deserializeDto.ts +28 -0
- package/src/decorator/dto/serialize/deserializeObject.ts +9 -0
- package/src/decorator/dto/serialize/deserializeUnknown.ts +31 -0
- package/src/decorator/dto/serialize/index.ts +7 -0
- package/src/decorator/dto/serialize/isSerializedDateTime.ts +5 -0
- package/src/decorator/dto/serialize/isSerializedDto.ts +5 -0
- package/src/decorator/dto/serialize/serialize.ts +5 -0
- package/src/decorator/dto/serialize/serializeArray.ts +19 -0
- package/src/decorator/dto/serialize/serializeDateTime.ts +9 -0
- package/src/decorator/dto/serialize/serializeDto.ts +21 -0
- package/src/decorator/dto/serialize/serializeObject.ts +9 -0
- package/src/decorator/dto/serialize/serializeUnknown.ts +34 -0
- package/src/decorator/dto/serialize/types.ts +3 -0
- package/src/decorator/dto/serialize/uuid.ts +3 -0
- package/src/decorator/dto/symbols.ts +11 -0
- package/src/decorator/dto/toJSON.ts +20 -0
- package/src/decorator/index.ts +31 -0
- package/src/dto/BlobResponse.ts +20 -0
- package/src/dto/Paginated.ts +38 -0
- package/src/dto/RequestError.ts +33 -0
- package/src/dto/ValidationError.ts +38 -0
- package/src/dto/index.ts +4 -0
- package/src/http/BaseResponse.ts +31 -0
- package/src/http/BaseService.ts +8 -0
- package/src/http/HttpClient.ts +41 -0
- package/src/http/QueryString.ts +75 -0
- package/src/http/RequestBuilder.ts +222 -0
- package/src/http/helpers.ts +17 -0
- package/src/http/index.ts +19 -0
- package/src/index.ts +5 -0
- package/src/type/index.ts +74 -0
- package/LICENSE +0 -21
- package/dist/http-client.js +0 -1095
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ENABLE_GET_LOGGING, ENABLE_SET_LOGGING } from './constant';
|
|
2
|
+
import { areEqual, markDtoDirty, relateValueTo, trackDto, triggerDto, unrelateValueFrom } from './helper';
|
|
3
|
+
import { DESCRIPTORS, NAME, PROPERTIES, PROXY } from './symbols';
|
|
4
|
+
import arrayProxy from './arrayProxy';
|
|
5
|
+
import type DtoInstance from './instance';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
/**
|
|
9
|
+
* Trap for when a dto property is being accessed. The property
|
|
10
|
+
* access is being tracked for further updates. If the dto has
|
|
11
|
+
* any child dtos, a relationship will be added between them.
|
|
12
|
+
*/
|
|
13
|
+
get(target: DtoInstance<unknown>, key: string | symbol, receiver: any): unknown {
|
|
14
|
+
if (key === PROXY) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof key === 'symbol') {
|
|
19
|
+
return Reflect.get(target, key, receiver);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const descriptor = target[DESCRIPTORS][key];
|
|
23
|
+
|
|
24
|
+
if (!descriptor || !descriptor.get) {
|
|
25
|
+
return Reflect.get(target, key, receiver);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const value = descriptor.get.call(target);
|
|
29
|
+
|
|
30
|
+
ENABLE_GET_LOGGING && console.log(`%c@dto %c${target[NAME]} %cget`, 'color: #0891b2', 'color: #059669', 'color: #1d4ed8', key);
|
|
31
|
+
trackDto(target, key);
|
|
32
|
+
|
|
33
|
+
relateValueTo(target, key, value);
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Trap for when a descriptor of a dto property is requested.
|
|
40
|
+
*/
|
|
41
|
+
getOwnPropertyDescriptor(target: DtoInstance<unknown>, key: string | symbol): PropertyDescriptor | undefined {
|
|
42
|
+
return target[DESCRIPTORS][key];
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Trap for when the keys of a dto are requested.
|
|
47
|
+
*/
|
|
48
|
+
ownKeys(target: DtoInstance<unknown>) {
|
|
49
|
+
return target[PROPERTIES];
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Trap for when a dto property is being updated. This will
|
|
54
|
+
* mark the dto dirty and trigger an update. If an array is
|
|
55
|
+
* passed, that array will be made reactive as well.
|
|
56
|
+
*/
|
|
57
|
+
set(target: DtoInstance<unknown>, key: string | symbol, value: unknown, receiver: any): boolean {
|
|
58
|
+
if (typeof key === 'symbol') {
|
|
59
|
+
return Reflect.set(target, key, value, receiver);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const descriptor = target[DESCRIPTORS][key];
|
|
63
|
+
|
|
64
|
+
if (!descriptor || !descriptor.set) {
|
|
65
|
+
return Reflect.set(target, key, value, receiver);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const oldValue = descriptor.get?.call(target) ?? undefined;
|
|
69
|
+
|
|
70
|
+
if (areEqual(value, oldValue)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
unrelateValueFrom(target, oldValue);
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(value) && !value[PROXY]) {
|
|
77
|
+
value = new Proxy(value, arrayProxy);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ENABLE_SET_LOGGING && console.log(`%c@dto %c${target[NAME]} %cset`, 'color: #0891b2', 'color: #059669', 'color: #1d4ed8', key, {value});
|
|
81
|
+
descriptor.set.call(target, value);
|
|
82
|
+
|
|
83
|
+
relateValueTo(target, key, value);
|
|
84
|
+
markDtoDirty(target, key);
|
|
85
|
+
triggerDto(target, key, value, oldValue);
|
|
86
|
+
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
} satisfies ProxyHandler<DtoInstance<unknown>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import { PROXY } from './symbols';
|
|
3
|
+
import type DtoInstance from './instance';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
/**
|
|
7
|
+
* Trap for when a ref property is being accessed. The property
|
|
8
|
+
* access is being tracked for further updates. If the requested
|
|
9
|
+
* property is not a part of {Ref}, the get is proxied to the
|
|
10
|
+
* underlying dto instance.
|
|
11
|
+
*
|
|
12
|
+
* A little trick with __v_isRef is done here, all the features
|
|
13
|
+
* of refs are used by our dto, but we don't want Vue to treat
|
|
14
|
+
* it as a ref. We return false here to trick Vue.
|
|
15
|
+
*/
|
|
16
|
+
get(target: Ref<DtoInstance<unknown>>, key: string | symbol, receiver: any): unknown {
|
|
17
|
+
if (key === '__v_isRef') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (key === PROXY) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (key in target) {
|
|
26
|
+
return Reflect.get(target, key, receiver);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Reflect.get(target.value, key);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Trap for when a descriptor of a property is requested, that
|
|
34
|
+
* request is proxied to the underlying dto.
|
|
35
|
+
*/
|
|
36
|
+
getOwnPropertyDescriptor(target: Ref<DtoInstance<unknown>>, key: string | symbol): PropertyDescriptor | undefined {
|
|
37
|
+
return Reflect.getOwnPropertyDescriptor(target.value, key);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Trap for when the keys of the ref are requested, that request
|
|
42
|
+
* is proxied to the underlying dto.
|
|
43
|
+
*/
|
|
44
|
+
ownKeys(target: Ref<DtoInstance<unknown>>) {
|
|
45
|
+
return Reflect.ownKeys(target.value);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Trap for when a ref property is being updated. If the property
|
|
50
|
+
* is not part of {Ref}, the set is proxied to the underlying dto
|
|
51
|
+
* instance. In that proxy, the dto will be marked dirty and an
|
|
52
|
+
* update is triggered.
|
|
53
|
+
*/
|
|
54
|
+
set(target: Ref<DtoInstance<unknown>>, key: string | symbol, value: unknown, receiver: any): boolean {
|
|
55
|
+
if (key in target) {
|
|
56
|
+
return Reflect.set(target, key, value, receiver);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Reflect.set(target.value, key, value);
|
|
60
|
+
}
|
|
61
|
+
} satisfies ProxyHandler<Ref<DtoInstance<unknown>>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ENABLE_SERIALIZATION_LOGGING } from '../constant';
|
|
2
|
+
import { DTO_CLASS_MAP } from '../map';
|
|
3
|
+
import type { SerializedDto } from './types';
|
|
4
|
+
import type DtoInstance from '../instance';
|
|
5
|
+
import deserializeArray from './deserializeArray';
|
|
6
|
+
import deserializeObject from './deserializeObject';
|
|
7
|
+
|
|
8
|
+
const CACHE: Record<string, unknown> = {};
|
|
9
|
+
|
|
10
|
+
export default function ([, id, name, state, args]: SerializedDto): DtoInstance<unknown> {
|
|
11
|
+
if (!(name in DTO_CLASS_MAP)) {
|
|
12
|
+
throw new Error(`Cannot restore @dto. Dto ${name} was not found.`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (id in CACHE) {
|
|
16
|
+
return CACHE[id] as DtoInstance<unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ENABLE_SERIALIZATION_LOGGING && console.group('⭐️', name, id);
|
|
20
|
+
const Dto = DTO_CLASS_MAP[name];
|
|
21
|
+
const instance = new Dto(...deserializeArray(args));
|
|
22
|
+
instance.fill(deserializeObject(state));
|
|
23
|
+
ENABLE_SERIALIZATION_LOGGING && console.groupEnd();
|
|
24
|
+
|
|
25
|
+
CACHE[id] = instance;
|
|
26
|
+
|
|
27
|
+
return instance;
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import deserializeUnknown from './deserializeUnknown';
|
|
2
|
+
|
|
3
|
+
export default function (obj: object): Record<string, unknown> {
|
|
4
|
+
return Object.fromEntries(
|
|
5
|
+
Object.entries(obj)
|
|
6
|
+
.map(([key, value]) => [key, deserializeUnknown(value)])
|
|
7
|
+
.filter(([, value]) => value !== undefined)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import deserializeArray from './deserializeArray';
|
|
2
|
+
import deserializeDateTime from './deserializeDateTime';
|
|
3
|
+
import deserializeDto from './deserializeDto';
|
|
4
|
+
import deserializeObject from './deserializeObject';
|
|
5
|
+
import isSerializedDateTime from './isSerializedDateTime';
|
|
6
|
+
import isSerializedDto from './isSerializedDto';
|
|
7
|
+
|
|
8
|
+
export default function (obj: unknown): unknown {
|
|
9
|
+
switch (true) {
|
|
10
|
+
case obj === null:
|
|
11
|
+
return null;
|
|
12
|
+
|
|
13
|
+
case Array.isArray(obj):
|
|
14
|
+
switch (true) {
|
|
15
|
+
case isSerializedDateTime(obj):
|
|
16
|
+
return deserializeDateTime(obj);
|
|
17
|
+
|
|
18
|
+
case isSerializedDto(obj):
|
|
19
|
+
return deserializeDto(obj);
|
|
20
|
+
|
|
21
|
+
default:
|
|
22
|
+
return deserializeArray(obj);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
case typeof obj === 'object':
|
|
26
|
+
return deserializeObject(obj);
|
|
27
|
+
|
|
28
|
+
default:
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import type { Serialized } from './types';
|
|
3
|
+
import isDto from '../helper/isDto';
|
|
4
|
+
import serializeDateTime from './serializeDateTime';
|
|
5
|
+
import serializeDto from './serializeDto';
|
|
6
|
+
import serializeUnknown from './serializeUnknown';
|
|
7
|
+
|
|
8
|
+
export default function (obj: unknown[]): Serialized[] {
|
|
9
|
+
switch (true) {
|
|
10
|
+
case obj.every(isDto):
|
|
11
|
+
return obj.map(serializeDto);
|
|
12
|
+
|
|
13
|
+
case obj.every(DateTime.isDateTime):
|
|
14
|
+
return obj.map(serializeDateTime);
|
|
15
|
+
|
|
16
|
+
default:
|
|
17
|
+
return obj.map(serializeUnknown);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { toRaw } from 'vue';
|
|
2
|
+
import { ARGS, NAME } from '../symbols';
|
|
3
|
+
import type { SerializedDto } from './types';
|
|
4
|
+
import type DtoInstance from '../instance';
|
|
5
|
+
import serializeArray from './serializeArray';
|
|
6
|
+
import serializeObject from './serializeObject';
|
|
7
|
+
import uuid from './uuid';
|
|
8
|
+
|
|
9
|
+
export default function (obj: DtoInstance<unknown>): SerializedDto {
|
|
10
|
+
obj = toRaw(obj);
|
|
11
|
+
|
|
12
|
+
const json = obj.toJSON();
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
0xBF1,
|
|
16
|
+
uuid(),
|
|
17
|
+
obj[NAME],
|
|
18
|
+
serializeObject(json),
|
|
19
|
+
serializeArray(obj[ARGS])
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import serializeUnknown from './serializeUnknown';
|
|
2
|
+
|
|
3
|
+
export default function (obj: object): Record<string, unknown> {
|
|
4
|
+
return Object.fromEntries(
|
|
5
|
+
Object.entries(obj)
|
|
6
|
+
.map(([key, value]) => [key, serializeUnknown(value)])
|
|
7
|
+
.filter(([, value]) => value !== undefined)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import type { Serialized } from './types';
|
|
3
|
+
import isDto from '../helper/isDto';
|
|
4
|
+
import serializeArray from './serializeArray';
|
|
5
|
+
import serializeDateTime from './serializeDateTime';
|
|
6
|
+
import serializeDto from './serializeDto';
|
|
7
|
+
import serializeObject from './serializeObject';
|
|
8
|
+
|
|
9
|
+
export default function (obj: unknown): Serialized | undefined {
|
|
10
|
+
switch (true) {
|
|
11
|
+
case obj === null:
|
|
12
|
+
return null;
|
|
13
|
+
|
|
14
|
+
case Array.isArray(obj):
|
|
15
|
+
return serializeArray(obj);
|
|
16
|
+
|
|
17
|
+
case isDto(obj):
|
|
18
|
+
return serializeDto(obj);
|
|
19
|
+
|
|
20
|
+
case DateTime.isDateTime(obj):
|
|
21
|
+
return serializeDateTime(obj);
|
|
22
|
+
|
|
23
|
+
case typeof obj === 'object':
|
|
24
|
+
return serializeObject(obj);
|
|
25
|
+
|
|
26
|
+
case typeof obj === 'boolean':
|
|
27
|
+
case typeof obj === 'number':
|
|
28
|
+
case typeof obj === 'string':
|
|
29
|
+
return obj;
|
|
30
|
+
|
|
31
|
+
default:
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ARGS: unique symbol = Symbol();
|
|
2
|
+
export const CHILDREN: unique symbol = Symbol();
|
|
3
|
+
export const DESCRIPTORS: unique symbol = Symbol();
|
|
4
|
+
export const DIRTY: unique symbol = Symbol();
|
|
5
|
+
export const NAME: unique symbol = Symbol();
|
|
6
|
+
export const PARENT: unique symbol = Symbol();
|
|
7
|
+
export const PARENT_KEY: unique symbol = Symbol();
|
|
8
|
+
export const PROPERTIES: unique symbol = Symbol();
|
|
9
|
+
export const PROXY: unique symbol = Symbol();
|
|
10
|
+
export const TRACK: unique symbol = Symbol();
|
|
11
|
+
export const TRIGGER: unique symbol = Symbol();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isDto } from './helper';
|
|
2
|
+
import { PROPERTIES } from './symbols';
|
|
3
|
+
import type DtoInstance from './instance';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the json object representation of the dto.
|
|
7
|
+
*/
|
|
8
|
+
export default function (this: DtoInstance<unknown>): Record<string, unknown> {
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
this[PROPERTIES].map(property => {
|
|
11
|
+
let value: unknown = Reflect.get.call(this, this, property, this);
|
|
12
|
+
|
|
13
|
+
if (isDto(value)) {
|
|
14
|
+
value = value.toJSON();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return [property, value];
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import adapter from './adapter';
|
|
2
|
+
import bound from './bound';
|
|
3
|
+
import debounce from './debounce';
|
|
4
|
+
import dto from './dto';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
adapter,
|
|
8
|
+
bound,
|
|
9
|
+
debounce,
|
|
10
|
+
dto
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
assertDto,
|
|
15
|
+
cloneDto,
|
|
16
|
+
executeIfDtoDirtyAndMarkClean,
|
|
17
|
+
isDto,
|
|
18
|
+
isDtoClean,
|
|
19
|
+
isDtoDirty,
|
|
20
|
+
markDtoClean,
|
|
21
|
+
markDtoDirty
|
|
22
|
+
} from './dto/helper';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
deserialize,
|
|
26
|
+
serialize
|
|
27
|
+
} from './dto/serialize';
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
DtoInstance
|
|
31
|
+
} from './dto';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { dto } from '../decorator';
|
|
2
|
+
|
|
3
|
+
@dto
|
|
4
|
+
export default class BlobResponse {
|
|
5
|
+
get blob(): Blob {
|
|
6
|
+
return this.#blob;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get name(): string {
|
|
10
|
+
return this.#name;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
readonly #blob: Blob;
|
|
14
|
+
readonly #name: string;
|
|
15
|
+
|
|
16
|
+
constructor(blob: Blob, name: string) {
|
|
17
|
+
this.#blob = blob;
|
|
18
|
+
this.#name = name;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { dto } from '../decorator';
|
|
2
|
+
|
|
3
|
+
@dto
|
|
4
|
+
export default class Paginated<T> {
|
|
5
|
+
get items(): T[] {
|
|
6
|
+
return this.#items;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get page(): number {
|
|
10
|
+
return this.#page;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get pageSize(): number {
|
|
14
|
+
return this.#pageSize;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get pages(): number {
|
|
18
|
+
return this.#pages;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get total(): number {
|
|
22
|
+
return this.#total;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
readonly #items: T[];
|
|
26
|
+
readonly #page: number;
|
|
27
|
+
readonly #pageSize: number;
|
|
28
|
+
readonly #pages: number;
|
|
29
|
+
readonly #total: number;
|
|
30
|
+
|
|
31
|
+
constructor(items: T[], page: number, pageSize: number, pages: number, total: number) {
|
|
32
|
+
this.#items = items;
|
|
33
|
+
this.#page = page;
|
|
34
|
+
this.#pageSize = pageSize;
|
|
35
|
+
this.#pages = pages;
|
|
36
|
+
this.#total = total;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { dto } from '../decorator';
|
|
2
|
+
import type { HttpStatusCode } from '../type';
|
|
3
|
+
|
|
4
|
+
@dto
|
|
5
|
+
export default class RequestError {
|
|
6
|
+
get code(): number {
|
|
7
|
+
return this.#code;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get error(): string {
|
|
11
|
+
return this.#error;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get errorDescription(): string {
|
|
15
|
+
return this.#errorDescription;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get statusCode(): HttpStatusCode {
|
|
19
|
+
return this.#statusCode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readonly #code: number;
|
|
23
|
+
readonly #error: string;
|
|
24
|
+
readonly #errorDescription: string;
|
|
25
|
+
readonly #statusCode: HttpStatusCode;
|
|
26
|
+
|
|
27
|
+
constructor(code: number, error: string, errorDescription: string, statusCode: HttpStatusCode) {
|
|
28
|
+
this.#code = code;
|
|
29
|
+
this.#error = error;
|
|
30
|
+
this.#errorDescription = errorDescription;
|
|
31
|
+
this.#statusCode = statusCode;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { dto } from '../decorator';
|
|
2
|
+
|
|
3
|
+
@dto
|
|
4
|
+
export default class ValidationError {
|
|
5
|
+
get code(): number {
|
|
6
|
+
return this.#code;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get error(): string {
|
|
10
|
+
return this.#error;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get errorDescription(): string {
|
|
14
|
+
return this.#errorDescription;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get errors(): Record<string, ValidationError> {
|
|
18
|
+
return this.#errors;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get params(): Record<string, string | number | boolean> {
|
|
22
|
+
return this.#params;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
readonly #code: number;
|
|
26
|
+
readonly #error: string;
|
|
27
|
+
readonly #errorDescription: string;
|
|
28
|
+
readonly #errors: Record<string, ValidationError>;
|
|
29
|
+
readonly #params: Record<string, string | number | boolean>;
|
|
30
|
+
|
|
31
|
+
constructor(code: number, error: string, errorDescription: string, errors?: Record<string, ValidationError>, params?: Record<string, string | number | boolean>) {
|
|
32
|
+
this.#code = code;
|
|
33
|
+
this.#error = error;
|
|
34
|
+
this.#errorDescription = errorDescription;
|
|
35
|
+
this.#errors = errors;
|
|
36
|
+
this.#params = params;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/dto/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HttpStatusCode } from '../type';
|
|
2
|
+
|
|
3
|
+
export default class BaseResponse<T> {
|
|
4
|
+
get data(): T {
|
|
5
|
+
return this.#data;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get headers(): Headers {
|
|
9
|
+
return this.#response.headers;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get ok(): boolean {
|
|
13
|
+
return this.statusCode >= 200 && this.statusCode < 300;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get response(): Response {
|
|
17
|
+
return this.#response;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get statusCode(): HttpStatusCode {
|
|
21
|
+
return this.#response.status as HttpStatusCode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
readonly #data: T;
|
|
25
|
+
readonly #response: Response;
|
|
26
|
+
|
|
27
|
+
constructor(data: T, response: Response) {
|
|
28
|
+
this.#data = data;
|
|
29
|
+
this.#response = response;
|
|
30
|
+
}
|
|
31
|
+
}
|