@basmilius/http-client 3.7.0 → 3.8.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.
Files changed (72) hide show
  1. package/dist/index.d.mts +248 -0
  2. package/dist/index.mjs +1 -0
  3. package/package.json +10 -10
  4. package/src/decorator/debounce.ts +1 -1
  5. package/dist/adapter/HttpAdapter.d.ts +0 -8
  6. package/dist/adapter/index.d.ts +0 -1
  7. package/dist/decorator/adapter.d.ts +0 -2
  8. package/dist/decorator/bound.d.ts +0 -1
  9. package/dist/decorator/debounce.d.ts +0 -1
  10. package/dist/decorator/dto/arrayProxy.d.ts +0 -18
  11. package/dist/decorator/dto/classProxy.d.ts +0 -11
  12. package/dist/decorator/dto/clone.d.ts +0 -5
  13. package/dist/decorator/dto/constant.d.ts +0 -7
  14. package/dist/decorator/dto/fill.d.ts +0 -5
  15. package/dist/decorator/dto/helper/areEqual.d.ts +0 -5
  16. package/dist/decorator/dto/helper/assertDto.d.ts +0 -5
  17. package/dist/decorator/dto/helper/circularProtect.d.ts +0 -1
  18. package/dist/decorator/dto/helper/cloneDto.d.ts +0 -4
  19. package/dist/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.d.ts +0 -8
  20. package/dist/decorator/dto/helper/index.d.ts +0 -18
  21. package/dist/decorator/dto/helper/instance.d.ts +0 -2
  22. package/dist/decorator/dto/helper/isDto.d.ts +0 -5
  23. package/dist/decorator/dto/helper/isDtoClean.d.ts +0 -4
  24. package/dist/decorator/dto/helper/isDtoDirty.d.ts +0 -4
  25. package/dist/decorator/dto/helper/markDtoClean.d.ts +0 -5
  26. package/dist/decorator/dto/helper/markDtoDirty.d.ts +0 -5
  27. package/dist/decorator/dto/helper/relateDtoTo.d.ts +0 -5
  28. package/dist/decorator/dto/helper/relateValueTo.d.ts +0 -5
  29. package/dist/decorator/dto/helper/trackDto.d.ts +0 -5
  30. package/dist/decorator/dto/helper/triggerDto.d.ts +0 -6
  31. package/dist/decorator/dto/helper/unrelateDtoFrom.d.ts +0 -5
  32. package/dist/decorator/dto/helper/unrelateValueFrom.d.ts +0 -5
  33. package/dist/decorator/dto/index.d.ts +0 -7
  34. package/dist/decorator/dto/instanceProxy.d.ts +0 -24
  35. package/dist/decorator/dto/map.d.ts +0 -3
  36. package/dist/decorator/dto/refProxy.d.ts +0 -33
  37. package/dist/decorator/dto/serialize/deserialize.d.ts +0 -1
  38. package/dist/decorator/dto/serialize/deserializeArray.d.ts +0 -1
  39. package/dist/decorator/dto/serialize/deserializeDateTime.d.ts +0 -3
  40. package/dist/decorator/dto/serialize/deserializeDto.d.ts +0 -3
  41. package/dist/decorator/dto/serialize/deserializeObject.d.ts +0 -1
  42. package/dist/decorator/dto/serialize/deserializeUnknown.d.ts +0 -1
  43. package/dist/decorator/dto/serialize/index.d.ts +0 -3
  44. package/dist/decorator/dto/serialize/isSerializedDateTime.d.ts +0 -2
  45. package/dist/decorator/dto/serialize/isSerializedDto.d.ts +0 -2
  46. package/dist/decorator/dto/serialize/serialize.d.ts +0 -1
  47. package/dist/decorator/dto/serialize/serializeArray.d.ts +0 -2
  48. package/dist/decorator/dto/serialize/serializeDateTime.d.ts +0 -3
  49. package/dist/decorator/dto/serialize/serializeDto.d.ts +0 -3
  50. package/dist/decorator/dto/serialize/serializeObject.d.ts +0 -1
  51. package/dist/decorator/dto/serialize/serializeUnknown.d.ts +0 -2
  52. package/dist/decorator/dto/serialize/uuid.d.ts +0 -1
  53. package/dist/decorator/dto/symbols.d.ts +0 -11
  54. package/dist/decorator/dto/toJSON.d.ts +0 -5
  55. package/dist/decorator/index.d.ts +0 -8
  56. package/dist/dto/BlobResponse.d.ts +0 -6
  57. package/dist/dto/Paginated.d.ts +0 -9
  58. package/dist/dto/RequestError.d.ts +0 -9
  59. package/dist/dto/ValidationError.d.ts +0 -9
  60. package/dist/dto/index.d.ts +0 -4
  61. package/dist/http/BaseResponse.d.ts +0 -10
  62. package/dist/http/BaseService.d.ts +0 -5
  63. package/dist/http/HttpClient.d.ts +0 -10
  64. package/dist/http/QueryString.d.ts +0 -14
  65. package/dist/http/RequestAbortedError.d.ts +0 -1
  66. package/dist/http/RequestBuilder.d.ts +0 -35
  67. package/dist/http/helpers.d.ts +0 -6
  68. package/dist/http/index.d.ts +0 -8
  69. package/dist/index.d.ts +0 -5
  70. package/dist/index.js +0 -4
  71. package/dist/index.js.map +0 -67
  72. package/dist/type.d.ts +0 -76
@@ -0,0 +1,248 @@
1
+ import { Constructor, Descriptors } from "@basmilius/utils";
2
+
3
+ //#region src/dto/BlobResponse.d.ts
4
+ declare class BlobResponse {
5
+ #private;
6
+ get blob(): Blob;
7
+ get name(): string;
8
+ constructor(blob: Blob, name: string);
9
+ }
10
+ //#endregion
11
+ //#region src/dto/Paginated.d.ts
12
+ declare class Paginated<T> {
13
+ #private;
14
+ get items(): T[];
15
+ get page(): number;
16
+ get pageSize(): number;
17
+ get pages(): number;
18
+ get total(): number;
19
+ constructor(items: T[], page: number, pageSize: number, pages: number, total: number);
20
+ }
21
+ //#endregion
22
+ //#region src/type/index.d.ts
23
+ type HttpMethod = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
24
+ type HttpStatusCode = 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
25
+ type ForeignData = Record<string, any>;
26
+ //#endregion
27
+ //#region src/dto/RequestError.d.ts
28
+ declare class RequestError {
29
+ #private;
30
+ get code(): number;
31
+ get error(): string;
32
+ get errorDescription(): string;
33
+ get statusCode(): HttpStatusCode;
34
+ constructor(code: number, error: string, errorDescription: string, statusCode: HttpStatusCode);
35
+ }
36
+ //#endregion
37
+ //#region src/dto/ValidationError.d.ts
38
+ declare class ValidationError {
39
+ #private;
40
+ get code(): number;
41
+ get error(): string;
42
+ get errorDescription(): string;
43
+ get errors(): Record<string, ValidationError>;
44
+ get params(): Record<string, string | number | boolean>;
45
+ constructor(code: number, error: string, errorDescription: string, errors?: Record<string, ValidationError>, params?: Record<string, string | number | boolean>);
46
+ }
47
+ //#endregion
48
+ //#region src/adapter/HttpAdapter.d.ts
49
+ declare class HttpAdapter {
50
+ static parsePaginatedAdapter<T>(response: ForeignData, adapterMethod: (item: object) => T): Paginated<T>;
51
+ static parseFileNameFromContentDispositionHeader(header: string): string;
52
+ static parseRequestError(response: ForeignData, statusCode: HttpStatusCode): RequestError;
53
+ static parseValidationError(response: ForeignData): ValidationError;
54
+ }
55
+ //#endregion
56
+ //#region src/decorator/adapter.d.ts
57
+ declare function export_default$1<T extends Constructor>(Parent: T): T;
58
+ //#endregion
59
+ //#region src/decorator/bound.d.ts
60
+ declare function export_default$3(): (target: object, method: string) => void;
61
+ //#endregion
62
+ //#region src/decorator/debounce.d.ts
63
+ declare function export_default$5(interval: number): Function;
64
+ //#endregion
65
+ //#region src/decorator/dto/symbols.d.ts
66
+ declare const ARGS: unique symbol;
67
+ declare const CHILDREN: unique symbol;
68
+ declare const DESCRIPTORS: unique symbol;
69
+ declare const DIRTY: unique symbol;
70
+ declare const NAME: unique symbol;
71
+ declare const PARENT: unique symbol;
72
+ declare const PARENT_KEY: unique symbol;
73
+ declare const PROPERTIES: unique symbol;
74
+ declare const TRACK: unique symbol;
75
+ declare const TRIGGER: unique symbol;
76
+ //#endregion
77
+ //#region src/decorator/dto/instance.d.ts
78
+ interface DtoInstance<T> extends Function {
79
+ [ARGS]: any[];
80
+ [CHILDREN]?: DtoInstance<unknown>[];
81
+ [DESCRIPTORS]: Descriptors;
82
+ [DIRTY]: boolean;
83
+ [NAME]: string;
84
+ [PARENT]?: DtoInstance<unknown>;
85
+ [PARENT_KEY]?: string;
86
+ [PROPERTIES]: string[];
87
+ [TRACK]: (instance: DtoInstance<unknown>, key: string) => void;
88
+ [TRIGGER]: (instance: DtoInstance<unknown>, key: string | symbol, value: unknown, oldValue?: unknown) => void;
89
+ /**
90
+ * Clones the DTO starting with the original arguments
91
+ * and replaces them with the current values.
92
+ */
93
+ clone(): DtoInstance<T>;
94
+ /**
95
+ * Fills the DTO with the given data.
96
+ */
97
+ fill(data: Record<string, unknown>): void;
98
+ /**
99
+ * Gets all getters of the DTO and returns them as
100
+ * an object, so {@see JSON.stringify} knows what
101
+ * to do with our DTO.
102
+ */
103
+ toJSON(): Record<string, unknown>;
104
+ }
105
+ //#endregion
106
+ //#region src/decorator/dto/index.d.ts
107
+ /**
108
+ * Provides reactivity to the decorated class.
109
+ */
110
+ declare function export_default$7<T extends Constructor>(clazz: T): T;
111
+ //#endregion
112
+ //#region src/decorator/dto/helper/assertDto.d.ts
113
+ /**
114
+ * Asserts that the given object is a dto.
115
+ */
116
+ declare function export_default$2(obj: unknown): asserts obj is DtoInstance<never>;
117
+ //#endregion
118
+ //#region src/decorator/dto/helper/cloneDto.d.ts
119
+ /**
120
+ * Clones the given dto.
121
+ */
122
+ declare function export_default$4<T>(obj: T): T;
123
+ //#endregion
124
+ //#region src/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.d.ts
125
+ /**
126
+ * Executes the given function if the given dto is marked dirty.
127
+ */
128
+ declare function export_default$8<T, R = void>(obj: T, fn: (dto: T & DtoInstance<T>) => Promise<R>): Promise<void>;
129
+ //#endregion
130
+ //#region src/decorator/dto/helper/isDto.d.ts
131
+ /**
132
+ * Checks if the given object is a dto.
133
+ */
134
+ declare function export_default$9(obj: unknown): obj is DtoInstance<unknown>;
135
+ //#endregion
136
+ //#region src/decorator/dto/helper/isDtoClean.d.ts
137
+ /**
138
+ * Checks if the given dto is clean.
139
+ */
140
+ declare function export_default$10(obj: unknown): boolean;
141
+ //#endregion
142
+ //#region src/decorator/dto/helper/isDtoDirty.d.ts
143
+ /**
144
+ * Checks if the given dto is dirty.
145
+ */
146
+ declare function export_default$11(obj: unknown): boolean;
147
+ //#endregion
148
+ //#region src/decorator/dto/helper/markDtoClean.d.ts
149
+ /**
150
+ * Marks the given dto clean.
151
+ */
152
+ declare const markDtoClean: (obj: unknown) => void;
153
+ //#endregion
154
+ //#region src/decorator/dto/helper/markDtoDirty.d.ts
155
+ /**
156
+ * Marks the given dto dirty.
157
+ */
158
+ declare const markDtoDirty: (obj: unknown, key?: string | number) => void;
159
+ //#endregion
160
+ //#region src/decorator/dto/serialize/deserialize.d.ts
161
+ declare function export_default$6(serialized: string): unknown;
162
+ //#endregion
163
+ //#region src/decorator/dto/serialize/serialize.d.ts
164
+ declare function export_default$12(obj: unknown): string;
165
+ //#endregion
166
+ //#region src/http/BaseResponse.d.ts
167
+ declare class BaseResponse<T> {
168
+ #private;
169
+ get data(): T;
170
+ get headers(): Headers;
171
+ get ok(): boolean;
172
+ get response(): Response;
173
+ get statusCode(): HttpStatusCode;
174
+ constructor(data: T, response: Response);
175
+ }
176
+ //#endregion
177
+ //#region src/http/HttpClient.d.ts
178
+ declare class HttpClient {
179
+ #private;
180
+ get authToken(): string | null;
181
+ set authToken(value: string | null);
182
+ get baseUrl(): string;
183
+ get dataField(): boolean;
184
+ constructor(authToken: string | null, baseUrl: string, dataField?: boolean);
185
+ static get instance(): HttpClient;
186
+ static register(client: HttpClient): void;
187
+ }
188
+ //#endregion
189
+ //#region src/http/QueryString.d.ts
190
+ declare class QueryString {
191
+ #private;
192
+ constructor();
193
+ build(): string;
194
+ append(name: string, value: QueryStringValue): QueryString;
195
+ appendArray(name: string, values: QueryStringValue[] | null): QueryString;
196
+ delete(name: string): QueryString;
197
+ get(name: string): string | null;
198
+ getAll(name: string): string[];
199
+ has(name: string): boolean;
200
+ set(name: string, value: QueryStringValue): QueryString;
201
+ static builder(): QueryString;
202
+ }
203
+ type QueryStringValue = boolean | number | string | null;
204
+ //#endregion
205
+ //#region src/http/RequestBuilder.d.ts
206
+ declare class RequestBuilder {
207
+ #private;
208
+ get client(): HttpClient;
209
+ get options(): RequestInit;
210
+ get path(): string;
211
+ set path(value: string);
212
+ get query(): QueryString | null;
213
+ set query(value: QueryString | null);
214
+ constructor(path: string, client?: HttpClient);
215
+ autoCancel(identifier: symbol): RequestBuilder;
216
+ bearerToken(token?: string): RequestBuilder;
217
+ body(body: BodyInit | FormData | object | null, contentType?: string | null): RequestBuilder;
218
+ header(name: string, value: string): RequestBuilder;
219
+ method(method: HttpMethod): RequestBuilder;
220
+ queryString(queryString: QueryString): RequestBuilder;
221
+ signal(signal?: AbortSignal | null): RequestBuilder;
222
+ fetch<TResult>(): Promise<TResult>;
223
+ fetchBlob(): Promise<BlobResponse>;
224
+ run<TResult extends {}>(): Promise<BaseResponse<TResult>>;
225
+ runAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult>>;
226
+ runArrayAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult[]>>;
227
+ runEmpty(): Promise<BaseResponse<never>>;
228
+ runPaginatedAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<Paginated<TResult>>>;
229
+ runData<TResult>(): Promise<BaseResponse<TResult>>;
230
+ runDataKey<TResult extends object, TKey extends keyof TResult = keyof TResult>(key: TKey): Promise<BaseResponse<TResult[TKey]>>;
231
+ runStatusCode(): Promise<HttpStatusCode>;
232
+ }
233
+ //#endregion
234
+ //#region src/http/BaseService.d.ts
235
+ declare class BaseService {
236
+ protected request(path: string, client?: HttpClient): RequestBuilder;
237
+ }
238
+ //#endregion
239
+ //#region src/http/RequestAbortedError.d.ts
240
+ declare class export_default extends Error {}
241
+ //#endregion
242
+ //#region src/http/helpers.d.ts
243
+ declare function isRequestAborted(obj: unknown): obj is export_default;
244
+ declare function isRequestError(obj: unknown): obj is RequestError;
245
+ declare function isUnsanctionedRequest(statusCode: unknown): boolean;
246
+ declare function isValidationError(obj: unknown): obj is ValidationError;
247
+ //#endregion
248
+ export { BaseResponse, BaseService, BlobResponse, type DtoInstance, ForeignData, HttpAdapter, HttpClient, HttpMethod, HttpStatusCode, Paginated, QueryString, export_default as RequestAbortedError, RequestBuilder, RequestError, ValidationError, export_default$1 as adapter, export_default$2 as assertDto, export_default$3 as bound, export_default$4 as cloneDto, export_default$5 as debounce, export_default$6 as deserialize, export_default$7 as dto, export_default$8 as executeIfDtoDirtyAndMarkClean, export_default$9 as isDto, export_default$10 as isDtoClean, export_default$11 as isDtoDirty, isRequestAborted, isRequestError, isUnsanctionedRequest, isValidationError, markDtoClean, markDtoDirty, export_default$12 as serialize };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{DateTime as e}from"luxon";import{debounce as t,getPrototypeChain as n,setObjectMethod as r,setObjectValue as i}from"@basmilius/utils";import{customRef as a,markRaw as o,toRaw as s}from"vue";function c(e){return class extends e{constructor(...e){throw Error(`@adapter: cannot create instance of class.`)}}}function ee(){return(e,t)=>{e[t]=e[t].bind(e)}}function te(e){return(n,r,i)=>{i.value=t(i.value,e,n)}}const l=Symbol(),u=Symbol(),d=Symbol(),f=Symbol(),p=Symbol(),m=Symbol(),h=Symbol(),g=Symbol(),_=Symbol(),v=Symbol(),y=Symbol();function b(e){return e&&typeof e==`object`&&!!e[p]}function ne(e,t){return!b(e)||!b(t)?e===t:JSON.stringify(e)===JSON.stringify(t)}function x(e){if(!b(e))throw Error(`@dto assert given object is not a class decorated with @Dto.`)}const S=Symbol();function C(e,t=0,n){return function(...r){let i=S in e,a=e[S]??=new WeakMap,o=r[t],s=n===void 0?`self`:r[n];if(typeof o!=`object`)return e.call(this,...r);if(a.has(o)||a.set(o,[]),a.get(o).includes(s))return;a.get(o).push(s);let c=e.call(this,...r);return!i&&delete e[S],c}}function re(e){return x(e),e.clone()}function w(e){return x(e),e[f]}const T=C(function(e,t,n,r){let i=e[y];i(e,t,n,r),e[m]&&T(e[m],e[h],e[m][e[h]])},0,1),E=C(function(e){x(e),e[f]&&(e[f]=!1,T(e,f,!1,!0)),!(!e[u]||e[u].length===0)&&e[u].filter(w).forEach(E)});async function ie(e,t){!b(e)||!w(e)||(await t(e),E(e))}function ae(e){return x(e),!e[f]}const D=C(function(e,t){x(e),e[f]||(e[f]=!0,T(e,f,!0,!1)),e[m]&&D(e[m],e[h])});function O(e,t,n){t[u]??=[],!t[u].includes(e)&&t[u].push(e),e[m]!==t&&(e[m]=t),e[h]!==n&&(e[h]=n)}function oe(e,t,n){b(n)?O(n,e,t):Array.isArray(n)&&(n.some(b)&&n.filter(b).forEach(n=>O(n,e,t)),n[m]=e,n[h]=t)}function se(e,t){let n=e[v];n(e,t)}function ce(e,t){if(u in t){let n=t[u].indexOf(e);t[u].splice(n,1)}e[m]=void 0,e[h]=void 0}function le(e,t){b(t)?ce(t,e):Array.isArray(t)&&(t.some(b)&&t.filter(b).forEach(t=>ce(t,e)),t[m]=void 0,t[h]=void 0)}const k={};var ue={deleteProperty(e,t){if(Reflect.deleteProperty(e,t),A(e,t))return!0;let n=e[m];return n&&T(n,e[h],n[e[h]]),n&&D(n,e[h]),!0},get(e,t,n){if(t===_)return!0;if(A(e,t))return Reflect.get(e,t,n);let r=e[m];return r&&se(r,e[h]),Reflect.get(e,t)},set(e,t,n,r){if(A(e,t))return Reflect.set(e,t,n,r);let i=e[m];return i&&T(i,e[h],i[e[h]]),i&&D(i,e[h]),Reflect.set(e,t,n)}};function A(e,t){return typeof t==`symbol`||typeof e[t]==`function`||t===`length`}var de={get(e,t,n){if(t===_)return!0;if(typeof t==`symbol`)return Reflect.get(e,t,n);let r=e[d][t];if(!r||!r.get)return Reflect.get(e,t,n);let i=r.get.call(e);return se(e,t),oe(e,t,i),i},getOwnPropertyDescriptor(e,t){return e[d][t]},ownKeys(e){return e[g]},set(e,t,n,r){if(typeof t==`symbol`)return Reflect.set(e,t,n,r);let i=e[d][t];if(!i||!i.set)return Reflect.set(e,t,n,r);let a=i.get?.call(e)??void 0;return ne(n,a)?!0:(le(e,a),Array.isArray(n)&&!n[_]&&(n=new Proxy(n,ue)),i.set.call(e,n),oe(e,t,n),D(e,t),T(e,t,n,a),!0)}},fe={get(e,t,n){return t===`__v_isRef`?!1:t===_?!0:t in e?Reflect.get(e,t,n):Reflect.get(e.value,t)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e.value,t)},ownKeys(e){return Reflect.ownKeys(e.value)},set(e,t,n,r){return t in e?Reflect.set(e,t,n,r):Reflect.set(e.value,t,n)}},pe={construct(e,t,n){t=t.map(e=>Array.isArray(e)?new Proxy(e,ue):e);let r=a((r,i)=>{let a=o(Reflect.construct(e,t,n));a[l]=t,a[f]=!1,a[v]=r,a[y]=i;let s=new Proxy(a,de);return{get:()=>(r(),s),set:()=>void 0}});return new Proxy(r,fe)}};function me(){let e=this;x(e);let t=k[e[p]],n=new t(...e[l]);return Object.entries(this[d]).filter(([,e])=>!!e.set).map(([e])=>e).forEach(e=>n[e]=b(this[e])?this[e].clone():this[e]),n}function he(e){for(let t in e){let n=this[d][t];b(this[t])&&typeof e[t]==`object`?this[t].fill(e[t]):n&&n.set&&(this[t]=e[t])}}function ge(){return Object.fromEntries(this[g].map(e=>{let t=Reflect.get.call(this,this,e,this);return b(t)&&(t=t.toJSON()),[e,t]}))}function j(e){ve(e);let t=Object.freeze(n(e)),a=Object.keys(t);return i(e.prototype,d,t),i(e.prototype,p,e.name),i(e.prototype,g,a),i(e,Symbol.hasInstance,t=>typeof t==`object`&&t?.[p]===e.name),r(e,`clone`,me),r(e,`fill`,he),r(e,`toJSON`,ge),_e(e)}function _e(e){let t=new Proxy(e,pe);return k[e.name]=t,t}function ve(e){let t=Object.getPrototypeOf(e.prototype);if(p in t)throw Error(`⛔️ @dto ${e.name} cannot extend parent class which is also decorated with @dto ${t[p]}.`)}function M(e){return e.map(F)}function ye([,t]){return e.fromISO(t)}function N(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,F(t)]).filter(([,e])=>e!==void 0))}const P={};function be([,e,t,n,r]){if(!(t in k))throw Error(`Cannot restore @dto. Dto ${t} was not found.`);if(e in P)return P[e];let i=k[t],a=new i(...M(r));return a.fill(N(n)),P[e]=a,a}function xe(e){return Array.isArray(e)&&e[0]===3058}function Se(e){return Array.isArray(e)&&e[0]===3057}function F(e){switch(!0){case e===null:return null;case Array.isArray(e):switch(!0){case xe(e):return ye(e);case Se(e):return be(e);default:return M(e)}case typeof e==`object`:return N(e);default:return e}}function Ce(e){return F(JSON.parse(e))}function I(e){return[3058,e.toISO({extendedZone:!0,includeOffset:!0})]}function L(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,B(t)]).filter(([,e])=>e!==void 0))}function we(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}function R(e){e=s(e);let t=e.toJSON();return[3057,we(),e[p],L(t),z(e[l])]}function z(t){switch(!0){case t.every(b):return t.map(R);case t.every(e.isDateTime):return t.map(I);default:return t.map(B)}}function B(t){switch(!0){case t===null:return null;case Array.isArray(t):return z(t);case b(t):return R(t);case e.isDateTime(t):return I(t);case typeof t==`object`:return L(t);case typeof t==`boolean`:case typeof t==`number`:case typeof t==`string`:return t;default:return}}function Te(e){return JSON.stringify(B(e))}function V(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let H=class{get blob(){return this.#e}get name(){return this.#t}#e;#t;constructor(e,t){this.#e=e,this.#t=t}};H=V([j],H);var Ee=H;let U=class{get items(){return this.#e}get page(){return this.#t}get pageSize(){return this.#n}get pages(){return this.#r}get total(){return this.#i}#e;#t;#n;#r;#i;constructor(e,t,n,r,i){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}};U=V([j],U);var De=U;let W=class{get code(){return this.#e}get error(){return this.#t}get errorDescription(){return this.#n}get statusCode(){return this.#r}#e;#t;#n;#r;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r}};W=V([j],W);var G=W;let K=class{get code(){return this.#e}get error(){return this.#t}get errorDescription(){return this.#n}get errors(){return this.#r}get params(){return this.#i}#e;#t;#n;#r;#i;constructor(e,t,n,r,i){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}};K=V([j],K);var q=K,J;let Y=J=class{static parsePaginatedAdapter(e,t){return new De(e.items.map(t),e.page,e.page_size,e.pages,e.total)}static parseFileNameFromContentDispositionHeader(t){let n=`download-${e.now().toFormat(`yyyy-MM-dd HH-mm-ss`)}`;if(!t.startsWith(`attachment`))return n;let r=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(t);return(r?.length||0)<2?n:r[1].replaceAll(`'`,``).replaceAll(`"`,``).replaceAll(`/`,`-`).replaceAll(`:`,`-`)}static parseRequestError(e,t){return new G(e.code,e.error,e.error_description,t)}static parseValidationError(e){let t;return e.errors&&(t={},Object.entries(e.errors).forEach(([e,n])=>{t[e]=J.parseValidationError(n)})),new q(e.code,e.error,e.error_description,t,e.params)}};Y=J=V([c],Y);var X=class{get data(){return this.#e}get headers(){return this.#t.headers}get ok(){return this.statusCode>=200&&this.statusCode<300}get response(){return this.#t}get statusCode(){return this.#t.status}#e;#t;constructor(e,t){this.#e=e,this.#t=t}},Oe=class e{get authToken(){return this.#e}set authToken(e){this.#e=e}get baseUrl(){return this.#t}get dataField(){return this.#n}#e;#t;#n;constructor(e,t,n=!1){this.#e=e,this.#t=t,this.#n=n}static get instance(){if(e.#r===null)throw Error(`There is currently no HttpClient instance registered. Register one using the HttpClient.register() function.`);return e.#r}static#r=null;static register(t){e.#r=t}},Z=class extends Error{};const Q={};var $=class t{get client(){return this.#e}get options(){return this.#r}get path(){return this.#n}set path(e){this.#n=e}get query(){return this.#i}set query(e){this.#i=e}#e;#t=null;#n;#r={};#i=null;constructor(e,t){this.#e=t??Oe.instance,this.#r.cache=`no-cache`,this.#r.method=`GET`,this.#n=e}autoCancel(e){return this.#t=e,this}bearerToken(e){return e??=this.#e.authToken,e?this.header(`Authorization`,`Bearer ${e}`):(this.#r.headers&&`Authorization`in this.#r.headers&&delete this.#r.headers.Authorization,this)}body(e,t=`application/octet-stream`){return e instanceof FormData?t=null:(Array.isArray(e)||typeof e==`object`)&&(e=JSON.stringify(e),t=`application/json`),this.#r.body=e,t===null?this:this.header(`Content-Type`,t)}header(e,t){return this.#r.headers=this.#r.headers||{},this.#r.headers[e]=t,this}method(e){return this.#r.method=e.toUpperCase(),this}queryString(e){return this.#i=e,this}signal(e=null){return this.#r.signal=e,this}async fetch(){return this.#a().then(e=>e.json())}async fetchBlob(){let t=await this.#a();if(t.status!==200){let e=await t.json();throw`code`in e&&`error`in e&&`error_description`in e?new G(e.code,e.error,e.error_description,t.status):new G(-1,`failed_without_info`,`Request failed without any information from the backend.`,t.status)}let n=t.headers.has(`content-disposition`)?Y.parseFileNameFromContentDispositionHeader(t.headers.get(`content-disposition`)):`download-${e.now().toFormat(`yyyy-MM-dd HH-mm-ss`)}`;return new Ee(await t.blob(),n)}async run(){let{data:e,response:t}=await this.#o();return new X(e,t)}async runAdapter(e){let{data:t,response:n}=await this.#o();return new X(e(t),n)}async runArrayAdapter(e){return this.runAdapter(t=>t.map(e))}async runEmpty(){return await this.#o()}async runPaginatedAdapter(e){return this.runAdapter(t=>Y.parsePaginatedAdapter(t,e))}async runData(){return await this.#o()}async runDataKey(e){let{data:t,response:n}=await this.#o();return new X(t[e],n)}async runStatusCode(){return(await this.#o()).statusCode}async#a(){if(this.#t!==null){this.#t in Q&&Q[this.#t].abort(new Z);let e=new AbortController;Q[this.#t]=e,this.signal(e.signal)}let e=this.path;return this.query!==null&&(e+=`?${this.query.build()}`),await fetch(this.client.baseUrl+e,this.options)}async#o(){return await this.#a().then(e=>t.#s(e,this.client.dataField))}static async#s(e,t){if(e.status===204)return new X(null,e);if(e.headers.has(`content-type`)&&e.headers.get(`content-type`).startsWith(`application/json`)){let n=await e.json();if(`code`in n&&`error`in n&&`error_description`in n)throw`errors`in n?Y.parseValidationError(n):Y.parseRequestError(n,e.status);return t&&`data`in n?new X(n.data,e):new X(n,e)}if(e.status===401||e.status===403||(await e.text()).length===0&&e.status>=200&&e.status<300)return new X(null,e);throw new G(-1,`not_a_json_response`,`The response was not a JSON response.`,e.status)}},ke=class{request(e,t){return new $(e,t)}},Ae=class e{#e;constructor(){this.#e=new URLSearchParams}build(){return this.#e.toString()}append(e,t){return this.#t(this.#e.append.bind(this.#e),e,t)}appendArray(e,t){return t?.forEach(t=>this.append(e,t)),this}delete(e){return this.#e.delete(e),this}get(e){return this.#e.get(e)}getAll(e){return this.#e.getAll(e)}has(e){return this.#e.has(e)}set(e,t){return this.#t(this.#e.set.bind(this.#e),e,t)}#t(e,t,n){if(!n&&n!==!1)return this;switch(typeof n){case`boolean`:e(t,n?`true`:`false`);break;case`number`:e(t,n.toString(10));break;case`string`:e(t,n);break}return this}static builder(){return new e}};function je(e){return e instanceof Z}function Me(e){return e instanceof G}function Ne(e){return e instanceof G&&(e=e.statusCode),e===403||e===401}function Pe(e){return e instanceof q}export{X as BaseResponse,ke as BaseService,Ee as BlobResponse,Y as HttpAdapter,Oe as HttpClient,De as Paginated,Ae as QueryString,Z as RequestAbortedError,$ as RequestBuilder,G as RequestError,q as ValidationError,c as adapter,x as assertDto,ee as bound,re as cloneDto,te as debounce,Ce as deserialize,j as dto,ie as executeIfDtoDirtyAndMarkClean,b as isDto,ae as isDtoClean,w as isDtoDirty,je as isRequestAborted,Me as isRequestError,Ne as isUnsanctionedRequest,Pe as isValidationError,E as markDtoClean,D as markDtoDirty,Te as serialize};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/http-client",
3
3
  "description": "Http client for Vue projects.",
4
- "version": "3.7.0",
4
+ "version": "3.8.0",
5
5
  "license": "MIT",
6
6
  "funding": "https://github.com/sponsors/basmilius",
7
7
  "homepage": "https://github.com/basmilius/packages",
@@ -19,7 +19,7 @@
19
19
  "vue 3"
20
20
  ],
21
21
  "scripts": {
22
- "build": "tsgo --noEmit && bun -b build.ts"
22
+ "build": "tsgo --noEmit && tsdown"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=23"
@@ -31,13 +31,13 @@
31
31
  "LICENSE"
32
32
  ],
33
33
  "type": "module",
34
- "main": "./dist/index.js",
35
- "module": "./dist/index.js",
36
- "types": "./dist/index.d.ts",
34
+ "main": "./dist/index.mjs",
35
+ "module": "./dist/index.mjs",
36
+ "types": "./dist/index.d.mts",
37
37
  "exports": {
38
38
  ".": {
39
- "types": "./dist/index.d.ts",
40
- "default": "./dist/index.js"
39
+ "types": "./dist/index.d.mts",
40
+ "default": "./dist/index.mjs"
41
41
  }
42
42
  },
43
43
  "publishConfig": {
@@ -45,12 +45,12 @@
45
45
  "provenance": true
46
46
  },
47
47
  "dependencies": {
48
- "@basmilius/utils": "3.7.0",
48
+ "@basmilius/utils": "3.8.0",
49
49
  "luxon": "^3.7.2",
50
50
  "vue": "^3.6.0-beta.6"
51
51
  },
52
52
  "devDependencies": {
53
- "@basmilius/tools": "3.7.0",
54
- "@types/luxon": "^3.7.1"
53
+ "@types/luxon": "^3.7.1",
54
+ "tsdown": "^0.21.0-beta.2"
55
55
  }
56
56
  }
@@ -1,6 +1,6 @@
1
1
  import { debounce } from '@basmilius/utils';
2
2
 
3
- export default function (interval: number) {
3
+ export default function (interval: number): Function {
4
4
  return (target: object, _: string, descriptor: PropertyDescriptor) => {
5
5
  descriptor.value = debounce(descriptor.value, interval, target);
6
6
  };
@@ -1,8 +0,0 @@
1
- import { Paginated, RequestError, ValidationError } from "../dto";
2
- import type { ForeignData, HttpStatusCode } from "../type";
3
- export declare class HttpAdapter {
4
- static parsePaginatedAdapter<T>(response: ForeignData, adapterMethod: (item: object) => T): Paginated<T>;
5
- static parseFileNameFromContentDispositionHeader(header: string): string;
6
- static parseRequestError(response: ForeignData, statusCode: HttpStatusCode): RequestError;
7
- static parseValidationError(response: ForeignData): ValidationError;
8
- }
@@ -1 +0,0 @@
1
- export { HttpAdapter } from "./HttpAdapter";
@@ -1,2 +0,0 @@
1
- import type { Constructor } from "@basmilius/utils";
2
- export default function<T extends Constructor>(Parent: T): T;
@@ -1 +0,0 @@
1
- export default function(): (target: object, method: string) => void;
@@ -1 +0,0 @@
1
- export default function(interval: number): unknown;
@@ -1,18 +0,0 @@
1
- declare const _default: {
2
- /**
3
- * Trap for when a property is deleted from the target. This
4
- * will mark the parent dto as dirty and trigger an update.
5
- */
6
- deleteProperty(target: unknown[], key: string | symbol): boolean;
7
- /**
8
- * Trap for when a property of the target is being accessed. The
9
- * property access is being tracked for further updates.
10
- */
11
- get(target: unknown[], key: string | symbol, receiver: any): unknown;
12
- /**
13
- * Trap for when a property of the target is being updated. This
14
- * will mark the parent dto as dirty and trigger an update.
15
- */
16
- set(target: unknown[], key: string | symbol, value: unknown, receiver: any);
17
- };
18
- export default _default;
@@ -1,11 +0,0 @@
1
- import type { Constructor } from "@basmilius/utils";
2
- import type DtoInstance from "./instance";
3
- declare const _default: {
4
- /**
5
- * Trap for when a dto is being constructed. Reactivity is provided
6
- * to all arguments and a proxied custom ref is returned that references
7
- * the actual dto instance.
8
- */
9
- construct(target: Constructor, argsArray: any[], newTarget: Function): DtoInstance<unknown>;
10
- };
11
- export default _default;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "./instance";
2
- /**
3
- * Returns a clone of the dto.
4
- */
5
- export default function<T>(this: DtoInstance<T>): DtoInstance<T>;
@@ -1,7 +0,0 @@
1
- export declare const ENABLE_CIRCULAR_LOGGING: boolean;
2
- export declare const ENABLE_DIRTY_LOGGING: boolean;
3
- export declare const ENABLE_REACTIVE_LOGGING: boolean;
4
- export declare const ENABLE_GET_LOGGING: boolean;
5
- export declare const ENABLE_SET_LOGGING: boolean;
6
- export declare const ENABLE_SERIALIZATION_LOGGING: boolean;
7
- export declare const OVERRIDE_CONSOLE_LOG: boolean;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "./instance";
2
- /**
3
- * Fills the dto with the given data.
4
- */
5
- export default function(this: DtoInstance<unknown>, data: Record<string, unknown>): void;
@@ -1,5 +0,0 @@
1
- /**
2
- * Checks if the two given values are equal. When both values are a
3
- * dto, the check is done by firstly converthing them to JSON.
4
- */
5
- export default function(a: unknown, b: unknown): boolean;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Asserts that the given object is a dto.
4
- */
5
- export default function(obj: unknown): asserts obj is DtoInstance<never>;
@@ -1 +0,0 @@
1
- export default function<T extends (...args: any[]) => unknown>(fn: T, arg1?: number, arg2?: number): T;
@@ -1,4 +0,0 @@
1
- /**
2
- * Clones the given dto.
3
- */
4
- export default function<T>(obj: T): T;
@@ -1,8 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Executes the given function if the given dto is marked dirty.
4
- */
5
- export default function<
6
- T,
7
- R = void
8
- >(obj: T, fn: (dto: T & DtoInstance<T>) => Promise<R>): Promise<void>;
@@ -1,18 +0,0 @@
1
- import areEqual from "./areEqual";
2
- import assertDto from "./assertDto";
3
- import circularProtect from "./circularProtect";
4
- import cloneDto from "./cloneDto";
5
- import executeIfDtoDirtyAndMarkClean from "./executeIfDtoDirtyAndMarkClean";
6
- import instance from "./instance";
7
- import isDto from "./isDto";
8
- import isDtoClean from "./isDtoClean";
9
- import isDtoDirty from "./isDtoDirty";
10
- import markDtoClean from "./markDtoClean";
11
- import markDtoDirty from "./markDtoDirty";
12
- import relateDtoTo from "./relateDtoTo";
13
- import relateValueTo from "./relateValueTo";
14
- import trackDto from "./trackDto";
15
- import triggerDto from "./triggerDto";
16
- import unrelateDtoFrom from "./unrelateDtoFrom";
17
- import unrelateValueFrom from "./unrelateValueFrom";
18
- export { areEqual, assertDto, circularProtect, cloneDto, executeIfDtoDirtyAndMarkClean, instance, isDto, isDtoClean, isDtoDirty, markDtoClean, markDtoDirty, relateDtoTo, relateValueTo, trackDto, triggerDto, unrelateDtoFrom, unrelateValueFrom };
@@ -1,2 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- export default function<T>(dto: DtoInstance<T>): DtoInstance<T>;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Checks if the given object is a dto.
4
- */
5
- export default function(obj: unknown): obj is DtoInstance<unknown>;
@@ -1,4 +0,0 @@
1
- /**
2
- * Checks if the given dto is clean.
3
- */
4
- export default function(obj: unknown): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * Checks if the given dto is dirty.
3
- */
4
- export default function(obj: unknown): boolean;
@@ -1,5 +0,0 @@
1
- /**
2
- * Marks the given dto clean.
3
- */
4
- declare const markDtoClean: (obj: unknown) => void;
5
- export default markDtoClean;
@@ -1,5 +0,0 @@
1
- /**
2
- * Marks the given dto dirty.
3
- */
4
- declare const markDtoDirty: (obj: unknown, key?: string | number) => void;
5
- export default markDtoDirty;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Creates a parent-child relationship between the given two dtos.
4
- */
5
- export default function(dto: DtoInstance<unknown>, parent: DtoInstance<unknown>, key: string): void;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Creates relationships between the given value and dto.
4
- */
5
- export default function(dto: DtoInstance<unknown>, key: string, value: unknown): void;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Tracking for when a dto property is being accessed.
4
- */
5
- export default function trackDto(dto: DtoInstance<unknown>, key: string): void;
@@ -1,6 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Trigger for when a dto property is being updated.
4
- */
5
- declare const triggerDto: (dto: DtoInstance<unknown>, key: string | symbol, value: unknown, oldValue?: unknown) => void;
6
- export default triggerDto;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Removes a parent-child relationship between the given two dtos.
4
- */
5
- export default function(dto: DtoInstance<unknown>, parent: DtoInstance<unknown>): void;
@@ -1,5 +0,0 @@
1
- import type DtoInstance from "../instance";
2
- /**
3
- * Removes relationships between the given value and dto.
4
- */
5
- export default function(dto: DtoInstance<unknown>, value: unknown): void;
@@ -1,7 +0,0 @@
1
- import { type Constructor } from "@basmilius/utils";
2
- import type DtoInstance from "./instance";
3
- /**
4
- * Provides reactivity to the decorated class.
5
- */
6
- export default function<T extends Constructor>(clazz: T): T;
7
- export type { DtoInstance };
@@ -1,24 +0,0 @@
1
- import type DtoInstance from "./instance";
2
- declare const _default: {
3
- /**
4
- * Trap for when a dto property is being accessed. The property
5
- * access is being tracked for further updates. If the dto has
6
- * any child dtos, a relationship will be added between them.
7
- */
8
- get(target: DtoInstance<unknown>, key: string | symbol, receiver: any): unknown;
9
- /**
10
- * Trap for when a descriptor of a dto property is requested.
11
- */
12
- getOwnPropertyDescriptor(target: DtoInstance<unknown>, key: string | symbol): PropertyDescriptor | undefined;
13
- /**
14
- * Trap for when the keys of a dto are requested.
15
- */
16
- ownKeys(target: DtoInstance<unknown>);
17
- /**
18
- * Trap for when a dto property is being updated. This will
19
- * mark the dto dirty and trigger an update. If an array is
20
- * passed, that array will be made reactive as well.
21
- */
22
- set(target: DtoInstance<unknown>, key: string | symbol, value: unknown, receiver: any): boolean;
23
- };
24
- export default _default;
@@ -1,3 +0,0 @@
1
- import type { Constructor } from "@basmilius/utils";
2
- import type DtoInstance from "./instance";
3
- export declare const DTO_CLASS_MAP: Record<string, Constructor<DtoInstance<unknown>>>;
@@ -1,33 +0,0 @@
1
- import type { Ref } from "vue";
2
- import type DtoInstance from "./instance";
3
- declare const _default: {
4
- /**
5
- * Trap for when a ref property is being accessed. The property
6
- * access is being tracked for further updates. If the requested
7
- * property is not a part of {Ref}, the get is proxied to the
8
- * underlying dto instance.
9
- *
10
- * A little trick with __v_isRef is done here, all the features
11
- * of refs are used by our dto, but we don't want Vue to treat
12
- * it as a ref. We return false here to trick Vue.
13
- */
14
- get(target: Ref<DtoInstance<unknown>>, key: string | symbol, receiver: any): unknown;
15
- /**
16
- * Trap for when a descriptor of a property is requested, that
17
- * request is proxied to the underlying dto.
18
- */
19
- getOwnPropertyDescriptor(target: Ref<DtoInstance<unknown>>, key: string | symbol): PropertyDescriptor | undefined;
20
- /**
21
- * Trap for when the keys of the ref are requested, that request
22
- * is proxied to the underlying dto.
23
- */
24
- ownKeys(target: Ref<DtoInstance<unknown>>);
25
- /**
26
- * Trap for when a ref property is being updated. If the property
27
- * is not part of {Ref}, the set is proxied to the underlying dto
28
- * instance. In that proxy, the dto will be marked dirty and an
29
- * update is triggered.
30
- */
31
- set(target: Ref<DtoInstance<unknown>>, key: string | symbol, value: unknown, receiver: any): boolean;
32
- };
33
- export default _default;
@@ -1 +0,0 @@
1
- export default function(serialized: string): unknown;
@@ -1 +0,0 @@
1
- export default function(obj: unknown[]): unknown[];
@@ -1,3 +0,0 @@
1
- import { DateTime } from "luxon";
2
- import type { SerializedDateTime } from "./types";
3
- export default function([, iso]: SerializedDateTime): DateTime;
@@ -1,3 +0,0 @@
1
- import type { SerializedDto } from "./types";
2
- import type DtoInstance from "../instance";
3
- export default function([, id, name, state, args]: SerializedDto): DtoInstance<unknown>;