@basmilius/http-client 1.1.0 → 1.2.1

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.
@@ -1,1096 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __typeError = (msg) => {
4
- throw TypeError(msg);
5
- };
6
- var __decorateClass = (decorators, target, key, kind) => {
7
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
9
- if (decorator = decorators[i])
10
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
- if (kind && result) __defProp(target, key, result);
12
- return result;
13
- };
14
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
15
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
16
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
17
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
18
-
19
- // src/decorator/adapter.ts
20
- var isStrict = true;
21
- function adapter_default(Parent) {
22
- return class extends Parent {
23
- constructor(...args) {
24
- if (isStrict) {
25
- throw new Error("Adapters cannot be instantiated.");
26
- }
27
- super(...args);
28
- }
29
- };
30
- }
31
-
32
- // src/decorator/debounce.ts
33
- function debounce_default(interval) {
34
- return (target, method, descriptor) => {
35
- descriptor.value = debounce(descriptor.value, interval, target);
36
- };
37
- }
38
- function debounce(fn, interval, $this) {
39
- let resolvers = [], rejecters = [], timeout = null;
40
- return (...args) => {
41
- clearTimeout(timeout);
42
- timeout = setTimeout(async () => {
43
- try {
44
- let result = await fn.apply($this, args);
45
- resolvers.forEach((resolve) => resolve(result));
46
- } catch (err) {
47
- rejecters.forEach((reject) => reject(err));
48
- }
49
- resolvers = [];
50
- rejecters = [];
51
- }, interval);
52
- return new Promise((resolve, reject) => {
53
- resolvers.push(resolve);
54
- rejecters.push(reject);
55
- });
56
- };
57
- }
58
-
59
- // src/util/datetime.ts
60
- import { DateTime } from "luxon";
61
- function formatFileDateTime(dateTime) {
62
- dateTime = dateTime || DateTime.now();
63
- return dateTime.toFormat("yyyy-MM-dd HH-mm-ss");
64
- }
65
-
66
- // src/util/reflection.ts
67
- function getPrototypeChain(obj) {
68
- const entries = {};
69
- do {
70
- if (obj.name === "") {
71
- break;
72
- }
73
- for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(obj.prototype))) {
74
- if (["constructor", "clone", "toJSON"].includes(key)) {
75
- continue;
76
- }
77
- if (!descriptor.get && !descriptor.set) {
78
- continue;
79
- }
80
- entries[key] = descriptor;
81
- }
82
- } while (obj = Object.getPrototypeOf(obj));
83
- return entries;
84
- }
85
- function setObjectMethod(obj, key, fn) {
86
- obj.prototype[key] = fn;
87
- }
88
- function setObjectValue(obj, key, value) {
89
- Object.defineProperty(obj, key, { value });
90
- }
91
-
92
- // src/decorator/dto/constant.ts
93
- var ENABLE_CIRCULAR_LOGGING = false;
94
- var ENABLE_DIRTY_LOGGING = false;
95
- var ENABLE_REACTIVE_LOGGING = false;
96
- var ENABLE_GET_LOGGING = false;
97
- var ENABLE_SET_LOGGING = false;
98
- var OVERRIDE_CONSOLE_LOG = true;
99
-
100
- // src/decorator/dto/symbols.ts
101
- var ARGS = Symbol();
102
- var CHILDREN = Symbol();
103
- var DESCRIPTORS = Symbol();
104
- var DIRTY = Symbol();
105
- var NAME = Symbol();
106
- var PARENT = Symbol();
107
- var PARENT_KEY = Symbol();
108
- var PROPERTIES = Symbol();
109
- var PROXY = Symbol();
110
- var TRACK = Symbol();
111
- var TRIGGER = Symbol();
112
-
113
- // src/decorator/dto/helper/isDto.ts
114
- function isDto_default(obj) {
115
- return obj && typeof obj === "object" && obj[NAME];
116
- }
117
-
118
- // src/decorator/dto/helper/areEqual.ts
119
- function areEqual_default(a, b) {
120
- if (!isDto_default(a) || !isDto_default(b)) {
121
- return a === b;
122
- }
123
- return JSON.stringify(a) === JSON.stringify(b);
124
- }
125
-
126
- // src/decorator/dto/helper/assertDto.ts
127
- function assertDto_default(obj) {
128
- if (!isDto_default(obj)) {
129
- throw new Error("@dto assert given object is not a class decorated with @Dto.");
130
- }
131
- }
132
-
133
- // src/decorator/dto/helper/circularProtect.ts
134
- var CIRCULAR_MAP = Symbol();
135
- function circularProtect_default(fn, arg1 = 0, arg2) {
136
- return function(...args) {
137
- const hasMap = CIRCULAR_MAP in fn;
138
- const map = fn[CIRCULAR_MAP] ??= /* @__PURE__ */ new WeakMap();
139
- const primary = args[arg1];
140
- const secondary = arg2 !== void 0 ? args[arg2] : "self";
141
- if (typeof primary !== "object") {
142
- return fn.call(this, ...args);
143
- }
144
- if (!map.has(primary)) {
145
- map.set(primary, []);
146
- }
147
- if (map.get(primary).includes(secondary)) {
148
- ENABLE_CIRCULAR_LOGGING && console.log(`%c@dto %ccircular protect %cdetected a circular reference`, "color: #0891b2", "color: #059669", "color: #1d4ed8", { fn, primary, secondary });
149
- return;
150
- }
151
- map.get(primary).push(secondary);
152
- const result = fn.call(this, ...args);
153
- !hasMap && delete fn[CIRCULAR_MAP];
154
- return result;
155
- };
156
- }
157
-
158
- // src/decorator/dto/helper/cloneDto.ts
159
- function cloneDto_default(obj) {
160
- assertDto_default(obj);
161
- return obj.clone();
162
- }
163
-
164
- // src/decorator/dto/helper/isDtoDirty.ts
165
- function isDtoDirty_default(obj) {
166
- assertDto_default(obj);
167
- return obj[DIRTY];
168
- }
169
-
170
- // src/decorator/dto/helper/triggerDto.ts
171
- var triggerDto = circularProtect_default(function(dto, key, value, oldValue) {
172
- const trigger = dto[TRIGGER];
173
- trigger(dto, key, value, oldValue);
174
- ENABLE_REACTIVE_LOGGING && console.log(`%c@dto %c${dto[NAME]} %ctrigger`, "color: #0891b2", "color: #059669", "color: #1d4ed8", key, { dto, value, oldValue });
175
- dto[PARENT] && triggerDto(dto[PARENT], dto[PARENT_KEY], dto[PARENT][dto[PARENT_KEY]]);
176
- }, 0, 1);
177
- var triggerDto_default = triggerDto;
178
-
179
- // src/decorator/dto/helper/markDtoClean.ts
180
- var markDtoClean = circularProtect_default(function(obj) {
181
- assertDto_default(obj);
182
- if (obj[DIRTY]) {
183
- obj[DIRTY] = false;
184
- ENABLE_DIRTY_LOGGING && console.log(`%c@dto %c${obj[NAME]} %cdirty`, "color: #0891b2", "color: #059669", "color: #1d4ed8", "marked clean", { obj });
185
- triggerDto_default(obj, DIRTY, false, true);
186
- }
187
- if (!obj[CHILDREN] || obj[CHILDREN].length === 0) {
188
- return;
189
- }
190
- obj[CHILDREN].filter(isDtoDirty_default).forEach(markDtoClean);
191
- });
192
- var markDtoClean_default = markDtoClean;
193
-
194
- // src/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.ts
195
- async function executeIfDtoDirtyAndMarkClean_default(obj, fn) {
196
- if (!isDto_default(obj) || !isDtoDirty_default(obj)) {
197
- return;
198
- }
199
- await fn(obj);
200
- markDtoClean_default(obj);
201
- }
202
-
203
- // src/decorator/dto/helper/instance.ts
204
- function instance_default(dto) {
205
- return dto?.value ?? dto;
206
- }
207
-
208
- // src/decorator/dto/helper/isDtoClean.ts
209
- function isDtoClean_default(obj) {
210
- assertDto_default(obj);
211
- return !obj[DIRTY];
212
- }
213
-
214
- // src/decorator/dto/helper/markDtoDirty.ts
215
- var markDtoDirty = circularProtect_default(function(obj, key) {
216
- assertDto_default(obj);
217
- if (!obj[DIRTY]) {
218
- obj[DIRTY] = true;
219
- ENABLE_DIRTY_LOGGING && console.log(`%c@dto %c${obj[NAME]} %cdirty`, "color: #0891b2", "color: #059669", "color: #1d4ed8", "marked dirty", { obj, key });
220
- triggerDto_default(obj, DIRTY, true, false);
221
- }
222
- if (!obj[PARENT]) {
223
- return;
224
- }
225
- markDtoDirty(obj[PARENT], obj[PARENT_KEY]);
226
- });
227
- var markDtoDirty_default = markDtoDirty;
228
-
229
- // src/decorator/dto/helper/relateDtoTo.ts
230
- function relateDtoTo_default(dto, parent, key) {
231
- parent[CHILDREN] ??= [];
232
- !parent[CHILDREN].includes(dto) && parent[CHILDREN].push(dto);
233
- dto[PARENT] !== parent && (dto[PARENT] = parent);
234
- dto[PARENT_KEY] !== key && (dto[PARENT_KEY] = key);
235
- }
236
-
237
- // src/decorator/dto/helper/relateValueTo.ts
238
- function relateValueTo_default(dto, key, value) {
239
- if (isDto_default(value)) {
240
- relateDtoTo_default(value, dto, key);
241
- } else if (Array.isArray(value)) {
242
- if (value.some(isDto_default)) {
243
- value.filter(isDto_default).forEach((val) => relateDtoTo_default(val, dto, key));
244
- }
245
- value[PARENT] = dto;
246
- value[PARENT_KEY] = key;
247
- }
248
- }
249
-
250
- // src/decorator/dto/helper/trackDto.ts
251
- function trackDto(dto, key) {
252
- const track = dto[TRACK];
253
- track(dto, key);
254
- ENABLE_REACTIVE_LOGGING && console.log(`%c@dto %c${dto[NAME]} %ctrack`, "color: #0891b2", "color: #059669", "color: #1d4ed8", key, { dto });
255
- }
256
-
257
- // src/decorator/dto/helper/unrelateDtoFrom.ts
258
- function unrelateDtoFrom_default(dto, parent) {
259
- if (CHILDREN in parent) {
260
- const index = parent[CHILDREN].indexOf(dto);
261
- parent[CHILDREN].splice(index, 1);
262
- }
263
- dto[PARENT] = void 0;
264
- dto[PARENT_KEY] = void 0;
265
- }
266
-
267
- // src/decorator/dto/helper/unrelateValueFrom.ts
268
- function unrelateValueFrom_default(dto, value) {
269
- if (isDto_default(value)) {
270
- unrelateDtoFrom_default(value, dto);
271
- } else if (Array.isArray(value)) {
272
- if (value.some(isDto_default)) {
273
- value.filter(isDto_default).forEach((val) => unrelateDtoFrom_default(val, dto));
274
- }
275
- value[PARENT] = void 0;
276
- value[PARENT_KEY] = void 0;
277
- }
278
- }
279
-
280
- // src/decorator/dto/classProxy.ts
281
- import { customRef, markRaw } from "vue";
282
-
283
- // src/decorator/dto/arrayProxy.ts
284
- var arrayProxy_default = {
285
- /**
286
- * Trap for when a property is deleted from the target. This
287
- * will mark the parent dto as dirty and trigger an update.
288
- */
289
- deleteProperty(target, key) {
290
- Reflect.deleteProperty(target, key);
291
- if (ignored(target, key)) {
292
- return true;
293
- }
294
- const dto = target[PARENT];
295
- dto && triggerDto_default(dto, target[PARENT_KEY], dto[target[PARENT_KEY]]);
296
- dto && markDtoDirty_default(dto, target[PARENT_KEY]);
297
- return true;
298
- },
299
- /**
300
- * Trap for when a property of the target is being accessed. The
301
- * property access is being tracked for further updates.
302
- */
303
- get(target, key, receiver) {
304
- if (key === PROXY) {
305
- return true;
306
- }
307
- if (ignored(target, key)) {
308
- return Reflect.get(target, key, receiver);
309
- }
310
- const dto = target[PARENT];
311
- dto && trackDto(dto, target[PARENT_KEY]);
312
- return Reflect.get(target, key);
313
- },
314
- /**
315
- * Trap for when a property of the target is being updated. This
316
- * will mark the parent dto as dirty and trigger an update.
317
- */
318
- set(target, key, value, receiver) {
319
- if (ignored(target, key)) {
320
- return Reflect.set(target, key, value, receiver);
321
- }
322
- const dto = target[PARENT];
323
- dto && triggerDto_default(dto, target[PARENT_KEY], dto[target[PARENT_KEY]]);
324
- dto && markDtoDirty_default(dto, target[PARENT_KEY]);
325
- return Reflect.set(target, key, value);
326
- }
327
- };
328
- function ignored(target, key) {
329
- return typeof key === "symbol" || typeof target[key] === "function" || key === "length";
330
- }
331
-
332
- // src/decorator/dto/instanceProxy.ts
333
- var instanceProxy_default = {
334
- /**
335
- * Trap for when a dto property is being accessed. The property
336
- * access is being tracked for further updates. If the dto has
337
- * any child dtos, a relationship will be added between them.
338
- */
339
- get(target, key, receiver) {
340
- if (key === PROXY) {
341
- return true;
342
- }
343
- if (typeof key === "symbol") {
344
- return Reflect.get(target, key, receiver);
345
- }
346
- const descriptor = target[DESCRIPTORS][key];
347
- if (!descriptor || !descriptor.get) {
348
- return Reflect.get(target, key, receiver);
349
- }
350
- const value = descriptor.get.call(target);
351
- ENABLE_GET_LOGGING && console.log(`%c@dto %c${target[NAME]} %cget`, "color: #0891b2", "color: #059669", "color: #1d4ed8", key);
352
- trackDto(target, key);
353
- relateValueTo_default(target, key, value);
354
- return value;
355
- },
356
- /**
357
- * Trap for when a descriptor of a dto property is requested.
358
- */
359
- getOwnPropertyDescriptor(target, key) {
360
- return target[DESCRIPTORS][key];
361
- },
362
- /**
363
- * Trap for when the keys of a dto are requested.
364
- */
365
- ownKeys(target) {
366
- return target[PROPERTIES];
367
- },
368
- /**
369
- * Trap for when a dto property is being updated. This will
370
- * mark the dto dirty and trigger an update. If an array is
371
- * passed, that array will be made reactive as well.
372
- */
373
- set(target, key, value, receiver) {
374
- if (typeof key === "symbol") {
375
- return Reflect.set(target, key, value, receiver);
376
- }
377
- const descriptor = target[DESCRIPTORS][key];
378
- if (!descriptor || !descriptor.set) {
379
- return Reflect.set(target, key, value, receiver);
380
- }
381
- const oldValue = descriptor.get?.call(target) ?? void 0;
382
- if (areEqual_default(value, oldValue)) {
383
- return true;
384
- }
385
- unrelateValueFrom_default(target, oldValue);
386
- if (Array.isArray(value) && !value[PROXY]) {
387
- value = new Proxy(value, arrayProxy_default);
388
- }
389
- ENABLE_SET_LOGGING && console.log(`%c@dto %c${target[NAME]} %cset`, "color: #0891b2", "color: #059669", "color: #1d4ed8", key, { value });
390
- descriptor.set.call(target, value);
391
- relateValueTo_default(target, key, value);
392
- markDtoDirty_default(target, key);
393
- triggerDto_default(target, key, value, oldValue);
394
- return true;
395
- }
396
- };
397
-
398
- // src/decorator/dto/refProxy.ts
399
- var refProxy_default = {
400
- /**
401
- * Trap for when a ref property is being accessed. The property
402
- * access is being tracked for further updates. If the requested
403
- * property is not a part of {Ref}, the get is proxied to the
404
- * underlying dto instance.
405
- *
406
- * A little trick with __v_isRef is done here, all the features
407
- * of refs are used by our dto, but we don't want Vue to treat
408
- * it as a ref. We return false here to trick Vue.
409
- */
410
- get(target, key, receiver) {
411
- if (key === "__v_isRef") {
412
- return false;
413
- }
414
- if (key === PROXY) {
415
- return true;
416
- }
417
- if (key in target) {
418
- return Reflect.get(target, key, receiver);
419
- }
420
- return Reflect.get(target.value, key);
421
- },
422
- /**
423
- * Trap for when a descriptor of a property is requested, that
424
- * request is proxied to the underlying dto.
425
- */
426
- getOwnPropertyDescriptor(target, key) {
427
- return Reflect.getOwnPropertyDescriptor(target.value, key);
428
- },
429
- /**
430
- * Trap for when the keys of the ref are requested, that request
431
- * is proxied to the underlying dto.
432
- */
433
- ownKeys(target) {
434
- return Reflect.ownKeys(target.value);
435
- },
436
- /**
437
- * Trap for when a ref property is being updated. If the property
438
- * is not part of {Ref}, the set is proxied to the underlying dto
439
- * instance. In that proxy, the dto will be marked dirty and an
440
- * update is triggered.
441
- */
442
- set(target, key, value, receiver) {
443
- if (key in target) {
444
- return Reflect.set(target, key, value, receiver);
445
- }
446
- return Reflect.set(target.value, key, value);
447
- }
448
- };
449
-
450
- // src/decorator/dto/classProxy.ts
451
- var classProxy_default = {
452
- /**
453
- * Trap for when a dto is being constructed. Reactivity is provided
454
- * to all arguments and a proxied custom ref is returned that references
455
- * the actual dto instance.
456
- */
457
- construct(target, argsArray, newTarget) {
458
- argsArray = argsArray.map((arg) => {
459
- if (!Array.isArray(arg)) {
460
- return arg;
461
- }
462
- return new Proxy(arg, arrayProxy_default);
463
- });
464
- const ref = customRef((track, trigger) => {
465
- const instance = markRaw(Reflect.construct(target, argsArray, newTarget));
466
- instance[ARGS] = argsArray;
467
- instance[DIRTY] = false;
468
- instance[TRACK] = track;
469
- instance[TRIGGER] = trigger;
470
- const proxied = new Proxy(instance, instanceProxy_default);
471
- return {
472
- // note(Bas): track that the dto itself is being accessed.
473
- get: () => {
474
- track();
475
- return proxied;
476
- },
477
- // note(Bas): setter is never used, but we don't want to
478
- // cause any errors.
479
- set: () => void 0
480
- };
481
- });
482
- return new Proxy(ref, refProxy_default);
483
- }
484
- };
485
-
486
- // src/decorator/dto/clone.ts
487
- function clone_default() {
488
- const instance = this;
489
- assertDto_default(instance);
490
- const clone = Reflect.construct(instance.prototype.constructor, instance[ARGS]);
491
- Object.entries(this[DESCRIPTORS]).filter(([, descriptor]) => !!descriptor.set).map(([name]) => name).forEach((key) => clone[key] = isDto_default(this[key]) ? this[key].clone() : this[key]);
492
- return clone;
493
- }
494
-
495
- // src/decorator/dto/fill.ts
496
- function fill_default(data) {
497
- for (let key in data) {
498
- const descriptor = this[DESCRIPTORS][key];
499
- if (isDto_default(this[key]) && typeof data[key] === "object") {
500
- this[key].fill(data[key]);
501
- } else if (descriptor && descriptor.set) {
502
- this[key] = data[key];
503
- }
504
- }
505
- }
506
-
507
- // src/decorator/dto/toJSON.ts
508
- function toJSON_default() {
509
- return Object.fromEntries(
510
- this[PROPERTIES].map((property) => {
511
- let value = Reflect.get.call(this, this, property, this);
512
- if (isDto_default(value)) {
513
- value = value.toJSON();
514
- }
515
- return [property, value];
516
- })
517
- );
518
- }
519
-
520
- // src/decorator/dto/index.ts
521
- function dto_default(clazz) {
522
- validate(clazz);
523
- const descriptors = Object.freeze(getPrototypeChain(clazz));
524
- const properties = Object.keys(descriptors);
525
- setObjectValue(clazz.prototype, DESCRIPTORS, descriptors);
526
- setObjectValue(clazz.prototype, NAME, clazz.name);
527
- setObjectValue(clazz.prototype, PROPERTIES, properties);
528
- setObjectValue(clazz, Symbol.hasInstance, (instance) => typeof instance === "object" && instance?.[NAME] === clazz.name);
529
- setObjectMethod(clazz, "clone", clone_default);
530
- setObjectMethod(clazz, "fill", fill_default);
531
- setObjectMethod(clazz, "toJSON", toJSON_default);
532
- return proxy(clazz);
533
- }
534
- var DTO_CLASS_MAP = {};
535
- function proxy(clazz) {
536
- const proxied = new Proxy(clazz, classProxy_default);
537
- DTO_CLASS_MAP[clazz.name] = proxied;
538
- return proxied;
539
- }
540
- function validate(clazz) {
541
- const parent = Object.getPrototypeOf(clazz.prototype);
542
- if (NAME in parent) {
543
- throw new Error(`\u26D4\uFE0F @dto ${clazz.name} cannot extend parent @dto ${parent[NAME]}. A non-dto base implementation should be created with separate implementations. TL;DR a class marked as @dto cannot extend another @dto class.`);
544
- }
545
- }
546
- if (OVERRIDE_CONSOLE_LOG) {
547
- const _error2 = console.error.bind(console);
548
- const _info = console.info.bind(console);
549
- const _log = console.log.bind(console);
550
- const _warn = console.warn.bind(console);
551
- const override = (fn) => (...args) => {
552
- for (let i = args.length - 1; i >= 0; --i) {
553
- const arg = args[i];
554
- if (!isDto_default(arg)) {
555
- continue;
556
- }
557
- const dto = instance_default(arg);
558
- args.splice(i, 1, `\u{1F4E6} ${dto[NAME]}`, dto.toJSON());
559
- }
560
- return fn(...args);
561
- };
562
- console.error = override(_error2);
563
- console.info = override(_info);
564
- console.log = override(_log);
565
- console.warn = override(_warn);
566
- }
567
-
568
- // src/dto/BlobResponse.ts
569
- var _blob, _name;
570
- var BlobResponse = class {
571
- constructor(blob, name) {
572
- __privateAdd(this, _blob);
573
- __privateAdd(this, _name);
574
- __privateSet(this, _blob, blob);
575
- __privateSet(this, _name, name);
576
- }
577
- get blob() {
578
- return __privateGet(this, _blob);
579
- }
580
- get name() {
581
- return __privateGet(this, _name);
582
- }
583
- };
584
- _blob = new WeakMap();
585
- _name = new WeakMap();
586
- BlobResponse = __decorateClass([
587
- dto_default
588
- ], BlobResponse);
589
-
590
- // src/dto/Paginated.ts
591
- var _items, _page, _pageSize, _pages, _totalItems;
592
- var Paginated = class {
593
- constructor(items, page, pageSize, pages, totalItems) {
594
- __privateAdd(this, _items);
595
- __privateAdd(this, _page);
596
- __privateAdd(this, _pageSize);
597
- __privateAdd(this, _pages);
598
- __privateAdd(this, _totalItems);
599
- __privateSet(this, _items, items);
600
- __privateSet(this, _page, page);
601
- __privateSet(this, _pageSize, pageSize);
602
- __privateSet(this, _pages, pages);
603
- __privateSet(this, _totalItems, totalItems);
604
- }
605
- get items() {
606
- return __privateGet(this, _items);
607
- }
608
- get page() {
609
- return __privateGet(this, _page);
610
- }
611
- get pageSize() {
612
- return __privateGet(this, _pageSize);
613
- }
614
- get pages() {
615
- return __privateGet(this, _pages);
616
- }
617
- get totalItems() {
618
- return __privateGet(this, _totalItems);
619
- }
620
- };
621
- _items = new WeakMap();
622
- _page = new WeakMap();
623
- _pageSize = new WeakMap();
624
- _pages = new WeakMap();
625
- _totalItems = new WeakMap();
626
- Paginated = __decorateClass([
627
- dto_default
628
- ], Paginated);
629
-
630
- // src/adapter/HttpAdapter.ts
631
- var HttpAdapter = class {
632
- static parsePaginatedAdapter(response, adapterMethod) {
633
- return new Paginated(
634
- response["items"].map(adapterMethod),
635
- response["page"],
636
- response["pageSize"],
637
- response["pages"],
638
- response["totalItems"]
639
- );
640
- }
641
- static parseFileNameFromContentDispositionHeader(header) {
642
- if (!header.startsWith("attachment")) {
643
- return `download-${formatFileDateTime()}`;
644
- }
645
- let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
646
- let matches = filenameRegex.exec(header);
647
- if ((matches?.length || 0) < 2) {
648
- return `download-${formatFileDateTime()}`;
649
- }
650
- return matches[1].replaceAll("'", "").replaceAll('"', "").replaceAll("/", "-").replaceAll(":", "-");
651
- }
652
- };
653
- HttpAdapter = __decorateClass([
654
- adapter_default
655
- ], HttpAdapter);
656
-
657
- // src/enum/HttpMethod.ts
658
- var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
659
- HttpMethod2["Delete"] = "DELETE";
660
- HttpMethod2["Get"] = "GET";
661
- HttpMethod2["Head"] = "HEAD";
662
- HttpMethod2["Options"] = "OPTIONS";
663
- HttpMethod2["Patch"] = "PATCH";
664
- HttpMethod2["Post"] = "POST";
665
- HttpMethod2["Put"] = "PUT";
666
- return HttpMethod2;
667
- })(HttpMethod || {});
668
-
669
- // src/enum/HttpStatusCode.ts
670
- var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
671
- HttpStatusCode2[HttpStatusCode2["Continue"] = 100] = "Continue";
672
- HttpStatusCode2[HttpStatusCode2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
673
- HttpStatusCode2[HttpStatusCode2["Processing"] = 102] = "Processing";
674
- HttpStatusCode2[HttpStatusCode2["Ok"] = 200] = "Ok";
675
- HttpStatusCode2[HttpStatusCode2["Created"] = 201] = "Created";
676
- HttpStatusCode2[HttpStatusCode2["Accepted"] = 202] = "Accepted";
677
- HttpStatusCode2[HttpStatusCode2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
678
- HttpStatusCode2[HttpStatusCode2["NoContent"] = 204] = "NoContent";
679
- HttpStatusCode2[HttpStatusCode2["ResetContent"] = 205] = "ResetContent";
680
- HttpStatusCode2[HttpStatusCode2["PartialContent"] = 206] = "PartialContent";
681
- HttpStatusCode2[HttpStatusCode2["MultiStatus"] = 207] = "MultiStatus";
682
- HttpStatusCode2[HttpStatusCode2["AlreadyReported"] = 208] = "AlreadyReported";
683
- HttpStatusCode2[HttpStatusCode2["ImUsed"] = 226] = "ImUsed";
684
- HttpStatusCode2[HttpStatusCode2["MultipleChoices"] = 300] = "MultipleChoices";
685
- HttpStatusCode2[HttpStatusCode2["MovedPermanently"] = 301] = "MovedPermanently";
686
- HttpStatusCode2[HttpStatusCode2["Found"] = 302] = "Found";
687
- HttpStatusCode2[HttpStatusCode2["SeeOther"] = 303] = "SeeOther";
688
- HttpStatusCode2[HttpStatusCode2["NotModified"] = 304] = "NotModified";
689
- HttpStatusCode2[HttpStatusCode2["UseProxy"] = 305] = "UseProxy";
690
- HttpStatusCode2[HttpStatusCode2["SwitchProxy"] = 306] = "SwitchProxy";
691
- HttpStatusCode2[HttpStatusCode2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
692
- HttpStatusCode2[HttpStatusCode2["PermanentRedirect"] = 308] = "PermanentRedirect";
693
- HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
694
- HttpStatusCode2[HttpStatusCode2["Unauthorized"] = 401] = "Unauthorized";
695
- HttpStatusCode2[HttpStatusCode2["PaymentRequired"] = 402] = "PaymentRequired";
696
- HttpStatusCode2[HttpStatusCode2["Forbidden"] = 403] = "Forbidden";
697
- HttpStatusCode2[HttpStatusCode2["NotFound"] = 404] = "NotFound";
698
- HttpStatusCode2[HttpStatusCode2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
699
- HttpStatusCode2[HttpStatusCode2["NotAcceptable"] = 406] = "NotAcceptable";
700
- HttpStatusCode2[HttpStatusCode2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
701
- HttpStatusCode2[HttpStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
702
- HttpStatusCode2[HttpStatusCode2["Conflict"] = 409] = "Conflict";
703
- HttpStatusCode2[HttpStatusCode2["Gone"] = 410] = "Gone";
704
- HttpStatusCode2[HttpStatusCode2["LengthRequired"] = 411] = "LengthRequired";
705
- HttpStatusCode2[HttpStatusCode2["PreconditionFailed"] = 412] = "PreconditionFailed";
706
- HttpStatusCode2[HttpStatusCode2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
707
- HttpStatusCode2[HttpStatusCode2["UriTooLong"] = 414] = "UriTooLong";
708
- HttpStatusCode2[HttpStatusCode2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
709
- HttpStatusCode2[HttpStatusCode2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
710
- HttpStatusCode2[HttpStatusCode2["ExpectationFailed"] = 417] = "ExpectationFailed";
711
- HttpStatusCode2[HttpStatusCode2["IAmATeapot"] = 418] = "IAmATeapot";
712
- HttpStatusCode2[HttpStatusCode2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
713
- HttpStatusCode2[HttpStatusCode2["UnprocessableEntity"] = 422] = "UnprocessableEntity";
714
- HttpStatusCode2[HttpStatusCode2["Locked"] = 423] = "Locked";
715
- HttpStatusCode2[HttpStatusCode2["FailedDependency"] = 424] = "FailedDependency";
716
- HttpStatusCode2[HttpStatusCode2["UpgradeRequired"] = 426] = "UpgradeRequired";
717
- HttpStatusCode2[HttpStatusCode2["PreconditionRequired"] = 428] = "PreconditionRequired";
718
- HttpStatusCode2[HttpStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
719
- HttpStatusCode2[HttpStatusCode2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
720
- HttpStatusCode2[HttpStatusCode2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
721
- HttpStatusCode2[HttpStatusCode2["InternalServerError"] = 500] = "InternalServerError";
722
- HttpStatusCode2[HttpStatusCode2["NotImplemented"] = 501] = "NotImplemented";
723
- HttpStatusCode2[HttpStatusCode2["BadGateway"] = 502] = "BadGateway";
724
- HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
725
- HttpStatusCode2[HttpStatusCode2["GatewayTimeout"] = 504] = "GatewayTimeout";
726
- HttpStatusCode2[HttpStatusCode2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
727
- HttpStatusCode2[HttpStatusCode2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
728
- HttpStatusCode2[HttpStatusCode2["InsufficientStorage"] = 507] = "InsufficientStorage";
729
- HttpStatusCode2[HttpStatusCode2["LoopDetected"] = 508] = "LoopDetected";
730
- HttpStatusCode2[HttpStatusCode2["NotExtended"] = 510] = "NotExtended";
731
- HttpStatusCode2[HttpStatusCode2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
732
- return HttpStatusCode2;
733
- })(HttpStatusCode || {});
734
-
735
- // src/http/BaseResponse.ts
736
- var BaseResponse = class {
737
- get data() {
738
- return this.#data;
739
- }
740
- get headers() {
741
- return this.#response.headers;
742
- }
743
- get ok() {
744
- return this.statusCode >= 200 && this.statusCode < 300;
745
- }
746
- get response() {
747
- return this.#response;
748
- }
749
- get statusCode() {
750
- return this.#response.status;
751
- }
752
- #data;
753
- #response;
754
- constructor(data, response) {
755
- this.#data = data;
756
- this.#response = response;
757
- }
758
- };
759
-
760
- // src/http/BaseService.ts
761
- var BaseService = class {
762
- request(path, client) {
763
- return new RequestBuilder(path, client);
764
- }
765
- };
766
-
767
- // src/http/HttpClient.ts
768
- var HttpClient2 = class _HttpClient {
769
- get authToken() {
770
- return this.#authToken;
771
- }
772
- set authToken(value) {
773
- this.#authToken = value;
774
- }
775
- get baseUrl() {
776
- return this.#baseUrl;
777
- }
778
- get timezone() {
779
- return this.#timezone;
780
- }
781
- set timezone(value) {
782
- this.#timezone = value;
783
- }
784
- #authToken;
785
- #timezone;
786
- #baseUrl;
787
- constructor(authToken, baseUrl) {
788
- this.#authToken = authToken;
789
- this.#baseUrl = baseUrl;
790
- this.#timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
791
- }
792
- onException(err, caller) {
793
- }
794
- onRequest(request) {
795
- return request;
796
- }
797
- onResponse(response) {
798
- }
799
- static get instance() {
800
- if (_HttpClient.#instance === null) {
801
- throw new Error("There is currently no HttpClient instance registered. Register one using the HttpClient.register() function.");
802
- }
803
- return _HttpClient.#instance;
804
- }
805
- static #instance = null;
806
- static register(client) {
807
- _HttpClient.#instance = client;
808
- }
809
- };
810
-
811
- // src/http/QueryString.ts
812
- var QueryString = class _QueryString {
813
- #builder;
814
- constructor() {
815
- this.#builder = new URLSearchParams();
816
- }
817
- build() {
818
- return this.#builder.toString();
819
- }
820
- append(name, value) {
821
- return this.#add(this.#builder.append.bind(this.#builder), name, value);
822
- }
823
- appendArray(name, values) {
824
- if (values === void 0 || values === null) {
825
- return this;
826
- }
827
- values.forEach((value) => this.append(name, value));
828
- return this;
829
- }
830
- delete(name) {
831
- this.#builder.delete(name);
832
- return this;
833
- }
834
- get(name) {
835
- return this.#builder.get(name);
836
- }
837
- getAll(name) {
838
- return this.#builder.getAll(name);
839
- }
840
- has(name) {
841
- return this.#builder.has(name);
842
- }
843
- set(name, value) {
844
- return this.#add(this.#builder.set.bind(this.#builder), name, value);
845
- }
846
- #add(fn, name, value) {
847
- if (!value && value !== false) {
848
- return this;
849
- }
850
- switch (typeof value) {
851
- case "boolean":
852
- fn(name, value ? "true" : "false");
853
- break;
854
- case "number":
855
- fn(name, value.toString(10));
856
- break;
857
- case "string":
858
- fn(name, value);
859
- break;
860
- }
861
- return this;
862
- }
863
- static builder() {
864
- return new _QueryString();
865
- }
866
- };
867
-
868
- // src/http/RequestBuilder.ts
869
- var RequestBuilder = class _RequestBuilder {
870
- get client() {
871
- return this.#client;
872
- }
873
- get options() {
874
- return this.#options;
875
- }
876
- get path() {
877
- return this.#path;
878
- }
879
- set path(value) {
880
- this.#path = value;
881
- }
882
- get query() {
883
- return this.#query;
884
- }
885
- set query(value) {
886
- this.#query = value;
887
- }
888
- #client;
889
- #path;
890
- #options = {};
891
- #query = null;
892
- constructor(path, client) {
893
- this.#client = client ?? HttpClient2.instance;
894
- this.#options.cache = "no-cache";
895
- this.#options.method = "GET" /* Get */;
896
- this.#path = path;
897
- }
898
- bearerToken(token) {
899
- token = token ?? this.#client.authToken;
900
- if (token) {
901
- return this.header("Authorization", `Bearer ${token}`);
902
- }
903
- if (this.#options.headers && "Authorization" in this.#options.headers) {
904
- delete this.#options.headers["Authorization"];
905
- }
906
- return this;
907
- }
908
- body(body, contentType = "application/octet-stream") {
909
- if (body instanceof FormData) {
910
- contentType = null;
911
- } else if (Array.isArray(body) || typeof body === "object") {
912
- body = JSON.stringify(body);
913
- contentType = "application/json";
914
- }
915
- this.#options.body = body;
916
- if (contentType !== null) {
917
- return this.header("Content-Type", contentType);
918
- }
919
- return this;
920
- }
921
- asOrganization(value) {
922
- return this.header("X-Organization-Id", value);
923
- }
924
- header(name, value) {
925
- this.#options.headers = this.#options.headers || {};
926
- this.#options.headers[name] = value;
927
- return this;
928
- }
929
- method(method) {
930
- this.#options.method = method;
931
- return this;
932
- }
933
- queryString(queryString) {
934
- this.#query = queryString;
935
- return this;
936
- }
937
- async fetch() {
938
- return this.#execute().then((r) => r.json());
939
- }
940
- async fetchBlob() {
941
- let response = await this.#execute();
942
- if (response.status !== 200 /* Ok */) {
943
- const data = await response.json();
944
- if ("code" in data && "error" in data && "error_description" in data) {
945
- throw new RequestError(data.code, data.error, data.error_description, response.status);
946
- }
947
- throw new RequestError(-1, "failed_without_info", "Request failed without any information from the backend.", response.status);
948
- }
949
- let filename = response.headers.has("content-disposition") ? HttpAdapter.parseFileNameFromContentDispositionHeader(response.headers.get("content-disposition")) : `download-${formatFileDateTime()}`;
950
- return new BlobResponse(
951
- await response.blob(),
952
- filename
953
- );
954
- }
955
- async runAdapter(adapterMethod) {
956
- const { data, response } = await this.#executeSafe();
957
- return new BaseResponse(adapterMethod(data), response);
958
- }
959
- async runArrayAdapter(adapterMethod) {
960
- return this.runAdapter((data) => data.map(adapterMethod));
961
- }
962
- async runEmpty() {
963
- return await this.#executeSafe();
964
- }
965
- async runPaginatedAdapter(adapterMethod) {
966
- return this.runAdapter((response) => HttpAdapter.parsePaginatedAdapter(response, adapterMethod));
967
- }
968
- async runData() {
969
- return await this.#executeSafe();
970
- }
971
- async runDataKey(key) {
972
- const { data, response } = await this.#executeSafe();
973
- return new BaseResponse(data[key], response);
974
- }
975
- async runStatusCode() {
976
- const response = await this.#executeSafe();
977
- return response.statusCode;
978
- }
979
- async #execute() {
980
- const request = this.#client.onRequest(this);
981
- let path = request.path;
982
- if (request.query !== null) {
983
- path += `?${request.query.build()}`;
984
- }
985
- return await fetch(request.client.baseUrl + path, request.options).catch((err) => {
986
- this.#client.onException(err, request);
987
- throw err;
988
- });
989
- }
990
- async #executeSafe() {
991
- return await this.#execute().then(_RequestBuilder.#handleResponse).then((response) => {
992
- this.#client.onResponse(response);
993
- return response;
994
- });
995
- }
996
- static async #handleResponse(response) {
997
- if (response.status === 204 /* NoContent */) {
998
- return new BaseResponse(null, response);
999
- }
1000
- if (response.headers.has("content-type") && response.headers.get("content-type").startsWith("application/json")) {
1001
- const data2 = await response.json();
1002
- if ("code" in data2 && "error" in data2 && "error_description" in data2) {
1003
- throw new RequestError(data2.code, data2.error, data2.error_description, response.status);
1004
- }
1005
- return new BaseResponse(data2, response);
1006
- }
1007
- if (response.status === 401 /* Unauthorized */ || response.status === 403 /* Forbidden */) {
1008
- return new BaseResponse(null, response);
1009
- }
1010
- const data = await response.text();
1011
- if (data.length === 0 && response.status >= 200 /* Ok */ && response.status < 300 /* MultipleChoices */) {
1012
- return new BaseResponse(null, response);
1013
- }
1014
- throw new RequestError(-1, "not_a_json_response", "The response was not a JSON response.", response.status);
1015
- }
1016
- };
1017
-
1018
- // src/http/RequestError.ts
1019
- var _code, _error, _errorDescription, _statusCode;
1020
- var RequestError = class {
1021
- constructor(code, error, errorDescription, statusCode) {
1022
- __privateAdd(this, _code);
1023
- __privateAdd(this, _error);
1024
- __privateAdd(this, _errorDescription);
1025
- __privateAdd(this, _statusCode);
1026
- __privateSet(this, _code, code);
1027
- __privateSet(this, _error, error);
1028
- __privateSet(this, _errorDescription, errorDescription);
1029
- __privateSet(this, _statusCode, statusCode);
1030
- }
1031
- get code() {
1032
- return __privateGet(this, _code);
1033
- }
1034
- get error() {
1035
- return __privateGet(this, _error);
1036
- }
1037
- get errorDescription() {
1038
- return __privateGet(this, _errorDescription);
1039
- }
1040
- get statusCode() {
1041
- return __privateGet(this, _statusCode);
1042
- }
1043
- };
1044
- _code = new WeakMap();
1045
- _error = new WeakMap();
1046
- _errorDescription = new WeakMap();
1047
- _statusCode = new WeakMap();
1048
- RequestError = __decorateClass([
1049
- dto_default
1050
- ], RequestError);
1051
-
1052
- // src/http/helpers.ts
1053
- function isRequestError(obj) {
1054
- return obj instanceof RequestError;
1055
- }
1056
- function isUnsanctionedRequest(statusCode) {
1057
- if (statusCode instanceof RequestError) {
1058
- statusCode = statusCode.statusCode;
1059
- }
1060
- return statusCode === 403 /* Forbidden */ || statusCode === 401 /* Unauthorized */;
1061
- }
1062
- export {
1063
- ARGS,
1064
- BaseResponse,
1065
- BaseService,
1066
- BlobResponse,
1067
- DTO_CLASS_MAP,
1068
- HttpAdapter,
1069
- HttpClient2 as HttpClient,
1070
- HttpMethod,
1071
- HttpStatusCode,
1072
- NAME,
1073
- PROPERTIES,
1074
- Paginated,
1075
- QueryString,
1076
- RequestBuilder,
1077
- RequestError,
1078
- adapter_default as adapter,
1079
- assertDto_default as assertDto,
1080
- cloneDto_default as cloneDto,
1081
- debounce_default as debounce,
1082
- dto_default as dto,
1083
- executeIfDtoDirtyAndMarkClean_default as executeIfDtoDirtyAndMarkClean,
1084
- isDto_default as isDto,
1085
- isDtoClean_default as isDtoClean,
1086
- isDtoDirty_default as isDtoDirty,
1087
- isRequestError,
1088
- isUnsanctionedRequest,
1089
- markDtoClean_default as markDtoClean,
1090
- markDtoDirty_default as markDtoDirty,
1091
- relateDtoTo_default as relateDtoTo,
1092
- relateValueTo_default as relateValueTo,
1093
- trackDto,
1094
- triggerDto_default as triggerDto
1095
- };
1
+ var Ge=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Re=r=>{throw TypeError(r)};var P=(r,e,n,o)=>{for(var i=o>1?void 0:o?_e(e,n):e,u=r.length-1,l;u>=0;u--)(l=r[u])&&(i=(o?l(e,n,i):l(i))||i);return o&&i&&Ge(e,n,i),i};var De=(r,e,n)=>e.has(r)||Re("Cannot "+n);var h=(r,e,n)=>(De(r,e,"read from private field"),n?n.call(r):e.get(r)),y=(r,e,n)=>e.has(r)?Re("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,n),d=(r,e,n,o)=>(De(r,e,"write to private field"),o?o.call(r,n):e.set(r,n),n);function oe(r){return class extends r{constructor(...e){throw new Error("Adapters cannot be instantiated.")}}}function Be(){return(r,e)=>{r[e]=r[e].bind(r)}}function Le(r){return(e,n,o)=>{o.value=Fe(o.value,r,e)}}function Fe(r,e,n){let o=[],i=[],u=null;return(...l)=>(clearTimeout(u),u=setTimeout(async()=>{try{let c=await r.apply(n,l);o.forEach(b=>b(c))}catch(c){i.forEach(b=>b(c))}o=[],i=[]},e),new Promise((c,b)=>{o.push(c),i.push(b)}))}import{DateTime as Me}from"luxon";function U(r){return r=r||Me.now(),r.toFormat("yyyy-MM-dd HH-mm-ss")}function ge(r){let e={};do{if(r.name==="")break;for(let[n,o]of Object.entries(Object.getOwnPropertyDescriptors(r.prototype)))["constructor","clone","toJSON"].includes(n)||!o.get&&!o.set||(e[n]=o)}while(r=Object.getPrototypeOf(r));return e}function ee(r,e,n){r.prototype[e]=n}function Y(r,e,n){Object.defineProperty(r,e,{value:n})}var B=Symbol(),g=Symbol(),w=Symbol(),R=Symbol(),m=Symbol(),f=Symbol(),a=Symbol(),k=Symbol(),N=Symbol(),re=Symbol(),ne=Symbol();function s(r){return r&&typeof r=="object"&&r[m]}function ie(r,e){return!s(r)||!s(e)?r===e:JSON.stringify(r)===JSON.stringify(e)}function p(r){if(!s(r))throw new Error("@dto assert given object is not a class decorated with @Dto.")}var se=Symbol();function L(r,e=0,n){return function(...o){let i=se in r,u=r[se]??=new WeakMap,l=o[e],c=n!==void 0?o[n]:"self";if(typeof l!="object")return r.call(this,...o);if(u.has(l)||u.set(l,[]),u.get(l).includes(c)){!1;return}u.get(l).push(c);let b=r.call(this,...o);return!i&&delete r[se],b}}function ce(r){return p(r),r.clone()}function O(r){return p(r),r[R]}var Te=L(function(r,e,n,o){let i=r[ne];i(r,e,n,o),!1,r[f]&&Te(r[f],r[a],r[f][r[a]])},0,1),T=Te;var be=L(function(r){p(r),r[R]&&(r[R]=!1,!1,T(r,R,!1,!0)),!(!r[g]||r[g].length===0)&&r[g].filter(O).forEach(be)}),K=be;async function le(r,e){!s(r)||!O(r)||(await e(r),K(r))}function ae(r){return r?.value??r}function ue(r){return p(r),!r[R]}var we=L(function(r,e){p(r),r[R]||(r[R]=!0,!1,T(r,R,!0,!1)),r[f]&&we(r[f],r[a])}),I=we;function F(r,e,n){e[g]??=[],!e[g].includes(r)&&e[g].push(r),r[f]!==e&&(r[f]=e),r[a]!==n&&(r[a]=n)}function M(r,e,n){s(n)?F(n,r,e):Array.isArray(n)&&(n.some(s)&&n.filter(s).forEach(o=>F(o,r,e)),n[f]=r,n[a]=e)}function E(r,e){let n=r[re];n(r,e),!1}function me(r,e){if(g in e){let n=e[g].indexOf(r);e[g].splice(n,1)}r[f]=void 0,r[a]=void 0}function fe(r,e){s(e)?me(e,r):Array.isArray(e)&&(e.some(s)&&e.filter(s).forEach(n=>me(n,r)),e[f]=void 0,e[a]=void 0)}var xe={};import{customRef as Ke,markRaw as Ve}from"vue";var te={deleteProperty(r,e){if(Reflect.deleteProperty(r,e),pe(r,e))return!0;let n=r[f];return n&&T(n,r[a],n[r[a]]),n&&I(n,r[a]),!0},get(r,e,n){if(e===N)return!0;if(pe(r,e))return Reflect.get(r,e,n);let o=r[f];return o&&E(o,r[a]),Reflect.get(r,e)},set(r,e,n,o){if(pe(r,e))return Reflect.set(r,e,n,o);let i=r[f];return i&&T(i,r[a],i[r[a]]),i&&I(i,r[a]),Reflect.set(r,e,n)}};function pe(r,e){return typeof e=="symbol"||typeof r[e]=="function"||e==="length"}var Pe={get(r,e,n){if(e===N)return!0;if(typeof e=="symbol")return Reflect.get(r,e,n);let o=r[w][e];if(!o||!o.get)return Reflect.get(r,e,n);let i=o.get.call(r);return!1,E(r,e),M(r,e,i),i},getOwnPropertyDescriptor(r,e){return r[w][e]},ownKeys(r){return r[k]},set(r,e,n,o){if(typeof e=="symbol")return Reflect.set(r,e,n,o);let i=r[w][e];if(!i||!i.set)return Reflect.set(r,e,n,o);let u=i.get?.call(r)??void 0;return ie(n,u)||(fe(r,u),Array.isArray(n)&&!n[N]&&(n=new Proxy(n,te)),!1,i.set.call(r,n),M(r,e,n),I(r,e),T(r,e,n,u)),!0}};var Ie={get(r,e,n){return e==="__v_isRef"?!1:e===N?!0:e in r?Reflect.get(r,e,n):Reflect.get(r.value,e)},getOwnPropertyDescriptor(r,e){return Reflect.getOwnPropertyDescriptor(r.value,e)},ownKeys(r){return Reflect.ownKeys(r.value)},set(r,e,n,o){return e in r?Reflect.set(r,e,n,o):Reflect.set(r.value,e,n)}};var Ee={construct(r,e,n){e=e.map(i=>Array.isArray(i)?new Proxy(i,te):i);let o=Ke((i,u)=>{let l=Ve(Reflect.construct(r,e,n));l[B]=e,l[R]=!1,l[re]=i,l[ne]=u;let c=new Proxy(l,Pe);return{get:()=>(i(),c),set:()=>{}}});return new Proxy(o,Ie)}};function Ae(){let r=this;p(r);let e=Reflect.construct(r.prototype.constructor,r[B]);return Object.entries(this[w]).filter(([,n])=>!!n.set).map(([n])=>n).forEach(n=>e[n]=s(this[n])?this[n].clone():this[n]),e}function ke(r){for(let e in r){let n=this[w][e];s(this[e])&&typeof r[e]=="object"?this[e].fill(r[e]):n&&n.set&&(this[e]=r[e])}}function Ne(){return Object.fromEntries(this[k].map(r=>{let e=Reflect.get.call(this,this,r,this);return s(e)&&(e=e.toJSON()),[r,e]}))}function q(r){Qe(r);let e=Object.freeze(ge(r)),n=Object.keys(e);return Y(r.prototype,w,e),Y(r.prototype,m,r.name),Y(r.prototype,k,n),Y(r,Symbol.hasInstance,o=>typeof o=="object"&&o?.[m]===r.name),ee(r,"clone",Ae),ee(r,"fill",ke),ee(r,"toJSON",Ne),je(r)}function je(r){let e=new Proxy(r,Ee);return xe[r.name]=e,e}function Qe(r){let e=Object.getPrototypeOf(r.prototype);if(m in e)throw new Error(`\u26D4\uFE0F @dto ${r.name} cannot extend parent @dto ${e[m]}. A non-dto base implementation should be created with separate implementations. TL;DR a class marked as @dto cannot extend another @dto class.`)}if(!1){let r=console.error.bind(console),e=console.info.bind(console),n=console.log.bind(console),o=console.warn.bind(console),i=u=>(...l)=>{for(let c=l.length-1;c>=0;--c){let b=l[c];if(!s(b))continue;let de=ae(b);l.splice(c,1,`\u{1F4E6} ${de[m]}`,de.toJSON())}return u(...l)};console.error=i(r),console.info=i(e),console.log=i(n),console.warn=i(o)}var V,j,G=class{constructor(e,n){y(this,V);y(this,j);d(this,V,e),d(this,j,n)}get blob(){return h(this,V)}get name(){return h(this,j)}};V=new WeakMap,j=new WeakMap,G=P([q],G);var Q,v,$,J,X,_=class{constructor(e,n,o,i,u){y(this,Q);y(this,v);y(this,$);y(this,J);y(this,X);d(this,Q,e),d(this,v,n),d(this,$,o),d(this,J,i),d(this,X,u)}get items(){return h(this,Q)}get page(){return h(this,v)}get pageSize(){return h(this,$)}get pages(){return h(this,J)}get totalItems(){return h(this,X)}};Q=new WeakMap,v=new WeakMap,$=new WeakMap,J=new WeakMap,X=new WeakMap,_=P([q],_);var A=class{static parsePaginatedAdapter(e,n){return new _(e.items.map(n),e.page,e.pageSize,e.pages,e.totalItems)}static parseFileNameFromContentDispositionHeader(e){if(!e.startsWith("attachment"))return`download-${U()}`;let o=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(e);return(o?.length||0)<2?`download-${U()}`:o[1].replaceAll("'","").replaceAll('"',"").replaceAll("/","-").replaceAll(":","-")}};A=P([oe],A);var Oe=(c=>(c.Delete="DELETE",c.Get="GET",c.Head="HEAD",c.Options="OPTIONS",c.Patch="PATCH",c.Post="POST",c.Put="PUT",c))(Oe||{});var qe=(t=>(t[t.Continue=100]="Continue",t[t.SwitchingProtocols=101]="SwitchingProtocols",t[t.Processing=102]="Processing",t[t.Ok=200]="Ok",t[t.Created=201]="Created",t[t.Accepted=202]="Accepted",t[t.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",t[t.NoContent=204]="NoContent",t[t.ResetContent=205]="ResetContent",t[t.PartialContent=206]="PartialContent",t[t.MultiStatus=207]="MultiStatus",t[t.AlreadyReported=208]="AlreadyReported",t[t.ImUsed=226]="ImUsed",t[t.MultipleChoices=300]="MultipleChoices",t[t.MovedPermanently=301]="MovedPermanently",t[t.Found=302]="Found",t[t.SeeOther=303]="SeeOther",t[t.NotModified=304]="NotModified",t[t.UseProxy=305]="UseProxy",t[t.SwitchProxy=306]="SwitchProxy",t[t.TemporaryRedirect=307]="TemporaryRedirect",t[t.PermanentRedirect=308]="PermanentRedirect",t[t.BadRequest=400]="BadRequest",t[t.Unauthorized=401]="Unauthorized",t[t.PaymentRequired=402]="PaymentRequired",t[t.Forbidden=403]="Forbidden",t[t.NotFound=404]="NotFound",t[t.MethodNotAllowed=405]="MethodNotAllowed",t[t.NotAcceptable=406]="NotAcceptable",t[t.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",t[t.RequestTimeout=408]="RequestTimeout",t[t.Conflict=409]="Conflict",t[t.Gone=410]="Gone",t[t.LengthRequired=411]="LengthRequired",t[t.PreconditionFailed=412]="PreconditionFailed",t[t.PayloadTooLarge=413]="PayloadTooLarge",t[t.UriTooLong=414]="UriTooLong",t[t.UnsupportedMediaType=415]="UnsupportedMediaType",t[t.RangeNotSatisfiable=416]="RangeNotSatisfiable",t[t.ExpectationFailed=417]="ExpectationFailed",t[t.IAmATeapot=418]="IAmATeapot",t[t.MisdirectedRequest=421]="MisdirectedRequest",t[t.UnprocessableEntity=422]="UnprocessableEntity",t[t.Locked=423]="Locked",t[t.FailedDependency=424]="FailedDependency",t[t.UpgradeRequired=426]="UpgradeRequired",t[t.PreconditionRequired=428]="PreconditionRequired",t[t.TooManyRequests=429]="TooManyRequests",t[t.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",t[t.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",t[t.InternalServerError=500]="InternalServerError",t[t.NotImplemented=501]="NotImplemented",t[t.BadGateway=502]="BadGateway",t[t.ServiceUnavailable=503]="ServiceUnavailable",t[t.GatewayTimeout=504]="GatewayTimeout",t[t.HttpVersionNotSupported=505]="HttpVersionNotSupported",t[t.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",t[t.InsufficientStorage=507]="InsufficientStorage",t[t.LoopDetected=508]="LoopDetected",t[t.NotExtended=510]="NotExtended",t[t.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",t))(qe||{});var x=class{get data(){return this.#e}get headers(){return this.#r.headers}get ok(){return this.statusCode>=200&&this.statusCode<300}get response(){return this.#r}get statusCode(){return this.#r.status}#e;#r;constructor(e,n){this.#e=e,this.#r=n}};var he=class{request(e,n){return new W(e,n)}};var Z=class r{get authToken(){return this.#e}set authToken(e){this.#e=e}get baseUrl(){return this.#n}get timezone(){return this.#r}set timezone(e){this.#r=e}#e;#r;#n;constructor(e,n){this.#e=e,this.#n=n,this.#r=Intl.DateTimeFormat().resolvedOptions().timeZone}onException(e,n){}onRequest(e){return e}onResponse(e){}static get instance(){if(r.#t===null)throw new Error("There is currently no HttpClient instance registered. Register one using the HttpClient.register() function.");return r.#t}static#t=null;static register(e){r.#t=e}};var ye=class r{#e;constructor(){this.#e=new URLSearchParams}build(){return this.#e.toString()}append(e,n){return this.#r(this.#e.append.bind(this.#e),e,n)}appendArray(e,n){return n==null?this:(n.forEach(o=>this.append(e,o)),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,n){return this.#r(this.#e.set.bind(this.#e),e,n)}#r(e,n,o){if(!o&&o!==!1)return this;switch(typeof o){case"boolean":e(n,o?"true":"false");break;case"number":e(n,o.toString(10));break;case"string":e(n,o);break}return this}static builder(){return new r}};var W=class r{get client(){return this.#e}get options(){return this.#n}get path(){return this.#r}set path(e){this.#r=e}get query(){return this.#t}set query(e){this.#t=e}#e;#r;#n={};#t=null;constructor(e,n){this.#e=n??Z.instance,this.#n.cache="no-cache",this.#n.method="GET",this.#r=e}bearerToken(e){return e=e??this.#e.authToken,e?this.header("Authorization",`Bearer ${e}`):(this.#n.headers&&"Authorization"in this.#n.headers&&delete this.#n.headers.Authorization,this)}body(e,n="application/octet-stream"){return e instanceof FormData?n=null:(Array.isArray(e)||typeof e=="object")&&(e=JSON.stringify(e),n="application/json"),this.#n.body=e,n!==null?this.header("Content-Type",n):this}asOrganization(e){return this.header("X-Organization-Id",e)}header(e,n){return this.#n.headers=this.#n.headers||{},this.#n.headers[e]=n,this}method(e){return this.#n.method=e,this}queryString(e){return this.#t=e,this}async fetch(){return this.#i().then(e=>e.json())}async fetchBlob(){let e=await this.#i();if(e.status!==200){let o=await e.json();throw"code"in o&&"error"in o&&"error_description"in o?new D(o.code,o.error,o.error_description,e.status):new D(-1,"failed_without_info","Request failed without any information from the backend.",e.status)}let n=e.headers.has("content-disposition")?A.parseFileNameFromContentDispositionHeader(e.headers.get("content-disposition")):`download-${U()}`;return new G(await e.blob(),n)}async runAdapter(e){let{data:n,response:o}=await this.#o();return new x(e(n),o)}async runArrayAdapter(e){return this.runAdapter(n=>n.map(e))}async runEmpty(){return await this.#o()}async runPaginatedAdapter(e){return this.runAdapter(n=>A.parsePaginatedAdapter(n,e))}async runData(){return await this.#o()}async runDataKey(e){let{data:n,response:o}=await this.#o();return new x(n[e],o)}async runStatusCode(){return(await this.#o()).statusCode}async#i(){let e=this.#e.onRequest(this),n=e.path;return e.query!==null&&(n+=`?${e.query.build()}`),await fetch(e.client.baseUrl+n,e.options).catch(o=>{throw this.#e.onException(o,e),o})}async#o(){return await this.#i().then(r.#s).then(e=>(this.#e.onResponse(e),e))}static async#s(e){if(e.status===204)return new x(null,e);if(e.headers.has("content-type")&&e.headers.get("content-type").startsWith("application/json")){let o=await e.json();if("code"in o&&"error"in o&&"error_description"in o)throw new D(o.code,o.error,o.error_description,e.status);return new x(o,e)}if(e.status===401||e.status===403)return new x(null,e);if((await e.text()).length===0&&e.status>=200&&e.status<300)return new x(null,e);throw new D(-1,"not_a_json_response","The response was not a JSON response.",e.status)}};var z,S,C,H,D=class{constructor(e,n,o,i){y(this,z);y(this,S);y(this,C);y(this,H);d(this,z,e),d(this,S,n),d(this,C,o),d(this,H,i)}get code(){return h(this,z)}get error(){return h(this,S)}get errorDescription(){return h(this,C)}get statusCode(){return h(this,H)}};z=new WeakMap,S=new WeakMap,C=new WeakMap,H=new WeakMap,D=P([q],D);function ve(r){return r instanceof D}function $e(r){return r instanceof D&&(r=r.statusCode),r===403||r===401}export{B as ARGS,x as BaseResponse,he as BaseService,G as BlobResponse,A as HttpAdapter,Z as HttpClient,Oe as HttpMethod,qe as HttpStatusCode,m as NAME,k as PROPERTIES,_ as Paginated,ye as QueryString,W as RequestBuilder,D as RequestError,oe as adapter,p as assertDto,Be as bound,ce as cloneDto,Le as debounce,q as dto,le as executeIfDtoDirtyAndMarkClean,s as isDto,ue as isDtoClean,O as isDtoDirty,ve as isRequestError,$e as isUnsanctionedRequest,K as markDtoClean,I as markDtoDirty,F as relateDtoTo,M as relateValueTo,E as trackDto,T as triggerDto};
1096
2
  //# sourceMappingURL=basmilius.httpClient.js.map