bytekit 2.2.0 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/ddd-boilerplate.d.ts.map +1 -1
- package/dist/cli/ddd-boilerplate.js +4 -1
- package/dist/cli/ddd-boilerplate.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +11 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/swagger-generator.d.ts.map +1 -1
- package/dist/cli/swagger-generator.js +9 -0
- package/dist/cli/swagger-generator.js.map +1 -1
- package/dist/cli/type-generator.d.ts.map +1 -1
- package/dist/cli/type-generator.js +5 -0
- package/dist/cli/type-generator.js.map +1 -1
- package/dist/utils/async/index.d.ts +8 -0
- package/dist/utils/async/index.d.ts.map +1 -1
- package/dist/utils/async/index.js +4 -0
- package/dist/utils/async/index.js.map +1 -1
- package/dist/utils/async/pipeline.d.ts +164 -0
- package/dist/utils/async/pipeline.d.ts.map +1 -0
- package/dist/utils/async/pipeline.js +154 -0
- package/dist/utils/async/pipeline.js.map +1 -0
- package/dist/utils/async/promise-pool.d.ts +59 -0
- package/dist/utils/async/promise-pool.d.ts.map +1 -0
- package/dist/utils/async/promise-pool.js +130 -0
- package/dist/utils/async/promise-pool.js.map +1 -0
- package/dist/utils/async/request-batcher.d.ts +82 -0
- package/dist/utils/async/request-batcher.d.ts.map +1 -0
- package/dist/utils/async/request-batcher.js +179 -0
- package/dist/utils/async/request-batcher.js.map +1 -0
- package/dist/utils/async/request-queue.d.ts +115 -0
- package/dist/utils/async/request-queue.d.ts.map +1 -0
- package/dist/utils/async/request-queue.js +236 -0
- package/dist/utils/async/request-queue.js.map +1 -0
- package/dist/utils/async/throttle.d.ts.map +1 -1
- package/dist/utils/async/throttle.js +1 -0
- package/dist/utils/async/throttle.js.map +1 -1
- package/dist/utils/core/ApiClient.d.ts +22 -1
- package/dist/utils/core/ApiClient.d.ts.map +1 -1
- package/dist/utils/core/ApiClient.js +64 -4
- package/dist/utils/core/ApiClient.js.map +1 -1
- package/dist/utils/core/ErrorBoundary.d.ts.map +1 -1
- package/dist/utils/core/ErrorBoundary.js +18 -5
- package/dist/utils/core/ErrorBoundary.js.map +1 -1
- package/dist/utils/core/Logger.d.ts +191 -0
- package/dist/utils/core/Logger.d.ts.map +1 -1
- package/dist/utils/core/Logger.js +155 -0
- package/dist/utils/core/Logger.js.map +1 -1
- package/dist/utils/core/Profiler.d.ts +41 -0
- package/dist/utils/core/Profiler.d.ts.map +1 -1
- package/dist/utils/core/Profiler.js +59 -0
- package/dist/utils/core/Profiler.js.map +1 -1
- package/dist/utils/core/RateLimiter.d.ts.map +1 -1
- package/dist/utils/core/RateLimiter.js +2 -0
- package/dist/utils/core/RateLimiter.js.map +1 -1
- package/dist/utils/core/ResponseValidator.d.ts +56 -0
- package/dist/utils/core/ResponseValidator.d.ts.map +1 -1
- package/dist/utils/core/ResponseValidator.js +28 -0
- package/dist/utils/core/ResponseValidator.js.map +1 -1
- package/dist/utils/core/RetryPolicy.d.ts +144 -0
- package/dist/utils/core/RetryPolicy.d.ts.map +1 -1
- package/dist/utils/core/RetryPolicy.js +108 -0
- package/dist/utils/core/RetryPolicy.js.map +1 -1
- package/dist/utils/helpers/CacheManager.d.ts.map +1 -1
- package/dist/utils/helpers/CacheManager.js +5 -0
- package/dist/utils/helpers/CacheManager.js.map +1 -1
- package/dist/utils/helpers/CompressionUtils.d.ts.map +1 -1
- package/dist/utils/helpers/CompressionUtils.js +21 -4
- package/dist/utils/helpers/CompressionUtils.js.map +1 -1
- package/dist/utils/helpers/CryptoUtils.d.ts.map +1 -1
- package/dist/utils/helpers/CryptoUtils.js +15 -3
- package/dist/utils/helpers/CryptoUtils.js.map +1 -1
- package/dist/utils/helpers/EnvManager.d.ts +46 -0
- package/dist/utils/helpers/EnvManager.d.ts.map +1 -1
- package/dist/utils/helpers/EnvManager.js +46 -0
- package/dist/utils/helpers/EnvManager.js.map +1 -1
- package/dist/utils/helpers/EventEmitter.d.ts.map +1 -1
- package/dist/utils/helpers/EventEmitter.js +0 -3
- package/dist/utils/helpers/EventEmitter.js.map +1 -1
- package/dist/utils/helpers/FileUploadHelper.d.ts +68 -1
- package/dist/utils/helpers/FileUploadHelper.d.ts.map +1 -1
- package/dist/utils/helpers/FileUploadHelper.js +72 -19
- package/dist/utils/helpers/FileUploadHelper.js.map +1 -1
- package/dist/utils/helpers/StorageUtils.d.ts +62 -0
- package/dist/utils/helpers/StorageUtils.d.ts.map +1 -1
- package/dist/utils/helpers/StorageUtils.js +62 -0
- package/dist/utils/helpers/StorageUtils.js.map +1 -1
- package/dist/utils/helpers/StreamingHelper.d.ts.map +1 -1
- package/dist/utils/helpers/StreamingHelper.js +16 -6
- package/dist/utils/helpers/StreamingHelper.js.map +1 -1
- package/dist/utils/helpers/UrlHelper.d.ts +30 -0
- package/dist/utils/helpers/UrlHelper.d.ts.map +1 -1
- package/dist/utils/helpers/UrlHelper.js +23 -1
- package/dist/utils/helpers/UrlHelper.js.map +1 -1
- package/dist/utils/helpers/WebSocketHelper.d.ts +30 -0
- package/dist/utils/helpers/WebSocketHelper.d.ts.map +1 -1
- package/dist/utils/helpers/WebSocketHelper.js +117 -5
- package/dist/utils/helpers/WebSocketHelper.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestQueue — Priority-aware, concurrency-limited task queue with AbortSignal cancellation.
|
|
3
|
+
* Feature: 004-batching-system
|
|
4
|
+
* Zero external dependencies: AbortController, Map (built-in).
|
|
5
|
+
*/
|
|
6
|
+
/** The three fixed priority lanes for task execution ordering. */
|
|
7
|
+
export type QueuePriority = "high" | "normal" | "low";
|
|
8
|
+
/** Constructor options for {@link RequestQueue}. */
|
|
9
|
+
export interface RequestQueueOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Max tasks running simultaneously. Minimum: 1.
|
|
12
|
+
*/
|
|
13
|
+
concurrency: number;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a task rejects. Queue continues executing remaining tasks.
|
|
16
|
+
* @param error The rejection reason (cast to Error).
|
|
17
|
+
* @param id The task's unique identifier.
|
|
18
|
+
*/
|
|
19
|
+
onError?: (error: Error, id: string) => void;
|
|
20
|
+
}
|
|
21
|
+
/** Per-task options for {@link RequestQueue.add}. */
|
|
22
|
+
export interface AddOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Lane priority. Defaults to `"normal"`.
|
|
25
|
+
* Tasks in `high` always dequeue before `normal`; `normal` before `low`.
|
|
26
|
+
*/
|
|
27
|
+
priority?: QueuePriority;
|
|
28
|
+
/**
|
|
29
|
+
* External AbortSignal. If it fires before the task starts,
|
|
30
|
+
* the task is cancelled immediately with {@link QueueAbortError}.
|
|
31
|
+
* This is the **public consumer cancellation path**.
|
|
32
|
+
*/
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when a queued task is cancelled — either via an external AbortSignal
|
|
37
|
+
* or via the internal `cancel(id)` mechanism.
|
|
38
|
+
*/
|
|
39
|
+
export declare class QueueAbortError extends Error {
|
|
40
|
+
constructor(message?: string);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A priority-aware, concurrency-limited task queue with AbortSignal-based cancellation.
|
|
44
|
+
*
|
|
45
|
+
* Tasks are organised into three lanes (`high`, `normal`, `low`). At any moment,
|
|
46
|
+
* at most `concurrency` tasks execute simultaneously. When a slot opens, the
|
|
47
|
+
* highest-priority queued task is dequeued and started.
|
|
48
|
+
*
|
|
49
|
+
* **Consumer cancellation** is done via `AddOptions.signal`.
|
|
50
|
+
* The `cancel(id)` method is an internal queue-management mechanism.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const queue = new RequestQueue({ concurrency: 3 });
|
|
55
|
+
*
|
|
56
|
+
* const result = await queue.add(
|
|
57
|
+
* (signal) => fetch("/api/data", { signal }),
|
|
58
|
+
* { priority: "high" }
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class RequestQueue {
|
|
63
|
+
private readonly _concurrency;
|
|
64
|
+
private readonly _onError?;
|
|
65
|
+
private readonly _high;
|
|
66
|
+
private readonly _normal;
|
|
67
|
+
private readonly _low;
|
|
68
|
+
private _running;
|
|
69
|
+
private readonly _active;
|
|
70
|
+
private _counter;
|
|
71
|
+
private _flushWaiters;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new RequestQueue.
|
|
74
|
+
* @throws {TypeError} if `concurrency` is less than 1.
|
|
75
|
+
*/
|
|
76
|
+
constructor(options: RequestQueueOptions);
|
|
77
|
+
/**
|
|
78
|
+
* Enqueues a task. The task factory receives an internal AbortSignal
|
|
79
|
+
* that fires when the task is cancelled via `cancel(id)`.
|
|
80
|
+
*
|
|
81
|
+
* @returns `Promise<T>` resolving to the task's return value.
|
|
82
|
+
* @throws {@link QueueAbortError} if cancelled before or during execution.
|
|
83
|
+
* @throws Whatever the task itself throws.
|
|
84
|
+
*/
|
|
85
|
+
add<T>(task: (signal: AbortSignal) => Promise<T>, options?: AddOptions): Promise<T>;
|
|
86
|
+
private _drain;
|
|
87
|
+
private _notifyFlushWaiters;
|
|
88
|
+
/**
|
|
89
|
+
* Cancels a task by ID.
|
|
90
|
+
* - **Queued task**: removed from its lane; promise rejects with {@link QueueAbortError}.
|
|
91
|
+
* Task factory is never called.
|
|
92
|
+
* - **In-flight task**: internal AbortSignal is fired. The task is responsible
|
|
93
|
+
* for reacting to signal abortion and rejecting its promise.
|
|
94
|
+
*
|
|
95
|
+
* @returns `true` if the ID was found; `false` otherwise.
|
|
96
|
+
* @internal Public consumers should use `AddOptions.signal` for cancellation.
|
|
97
|
+
*/
|
|
98
|
+
cancel(id: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Resolves when all currently queued and running tasks have settled.
|
|
101
|
+
* Tasks added after `flush()` is called are included in the wait.
|
|
102
|
+
*/
|
|
103
|
+
flush(): Promise<void>;
|
|
104
|
+
/** @internal Returns IDs of all queued (not yet running) items across all lanes. */
|
|
105
|
+
_queuedIds(): string[];
|
|
106
|
+
/** @internal Returns IDs of all currently running items. */
|
|
107
|
+
_runningIds(): string[];
|
|
108
|
+
/** Number of tasks waiting to start (across all priority lanes). */
|
|
109
|
+
get size(): number;
|
|
110
|
+
/** Number of tasks currently executing. */
|
|
111
|
+
get running(): number;
|
|
112
|
+
/** Total active work: `size + running`. */
|
|
113
|
+
get pending(): number;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=request-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-queue.d.ts","sourceRoot":"","sources":["../../../src/utils/async/request-queue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEtD,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,qDAAqD;AACrD,MAAM,WAAW,UAAU;IACvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM;CAI/B;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAqC;IAC/D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmB;IACxC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,aAAa,CAAyB;IAE9C;;;OAGG;gBACS,OAAO,EAAE,mBAAmB;IAQxC;;;;;;;OAOG;IACH,GAAG,CAAC,CAAC,EACD,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC,CAAC,CAAC;IA2Cb,OAAO,CAAC,MAAM;IAmCd,OAAO,CAAC,mBAAmB;IAO3B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAoB3B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,oFAAoF;IACpF,UAAU,IAAI,MAAM,EAAE;IAQtB,4DAA4D;IAC5D,WAAW,IAAI,MAAM,EAAE;IAIvB,oEAAoE;IACpE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,2CAA2C;IAC3C,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,2CAA2C;IAC3C,IAAI,OAAO,IAAI,MAAM,CAEpB;CACJ"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestQueue — Priority-aware, concurrency-limited task queue with AbortSignal cancellation.
|
|
3
|
+
* Feature: 004-batching-system
|
|
4
|
+
* Zero external dependencies: AbortController, Map (built-in).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a queued task is cancelled — either via an external AbortSignal
|
|
8
|
+
* or via the internal `cancel(id)` mechanism.
|
|
9
|
+
*/
|
|
10
|
+
export class QueueAbortError extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message ?? "Request cancelled");
|
|
13
|
+
this.name = "QueueAbortError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A priority-aware, concurrency-limited task queue with AbortSignal-based cancellation.
|
|
18
|
+
*
|
|
19
|
+
* Tasks are organised into three lanes (`high`, `normal`, `low`). At any moment,
|
|
20
|
+
* at most `concurrency` tasks execute simultaneously. When a slot opens, the
|
|
21
|
+
* highest-priority queued task is dequeued and started.
|
|
22
|
+
*
|
|
23
|
+
* **Consumer cancellation** is done via `AddOptions.signal`.
|
|
24
|
+
* The `cancel(id)` method is an internal queue-management mechanism.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const queue = new RequestQueue({ concurrency: 3 });
|
|
29
|
+
*
|
|
30
|
+
* const result = await queue.add(
|
|
31
|
+
* (signal) => fetch("/api/data", { signal }),
|
|
32
|
+
* { priority: "high" }
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class RequestQueue {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new RequestQueue.
|
|
39
|
+
* @throws {TypeError} if `concurrency` is less than 1.
|
|
40
|
+
*/
|
|
41
|
+
constructor(options) {
|
|
42
|
+
Object.defineProperty(this, "_concurrency", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(this, "_onError", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(this, "_high", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: []
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(this, "_normal", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: []
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(this, "_low", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: []
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "_running", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "_active", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: new Map()
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "_counter", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: 0
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(this, "_flushWaiters", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: []
|
|
95
|
+
});
|
|
96
|
+
if (options.concurrency < 1) {
|
|
97
|
+
throw new TypeError("concurrency must be >= 1");
|
|
98
|
+
}
|
|
99
|
+
this._concurrency = options.concurrency;
|
|
100
|
+
this._onError = options.onError;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Enqueues a task. The task factory receives an internal AbortSignal
|
|
104
|
+
* that fires when the task is cancelled via `cancel(id)`.
|
|
105
|
+
*
|
|
106
|
+
* @returns `Promise<T>` resolving to the task's return value.
|
|
107
|
+
* @throws {@link QueueAbortError} if cancelled before or during execution.
|
|
108
|
+
* @throws Whatever the task itself throws.
|
|
109
|
+
*/
|
|
110
|
+
add(task, options) {
|
|
111
|
+
const priority = options?.priority ?? "normal";
|
|
112
|
+
const externalSignal = options?.signal;
|
|
113
|
+
if (externalSignal?.aborted) {
|
|
114
|
+
return Promise.reject(new QueueAbortError());
|
|
115
|
+
}
|
|
116
|
+
const controller = new AbortController();
|
|
117
|
+
const id = String(++this._counter);
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const item = {
|
|
120
|
+
task,
|
|
121
|
+
priority,
|
|
122
|
+
resolve,
|
|
123
|
+
reject,
|
|
124
|
+
controller,
|
|
125
|
+
id,
|
|
126
|
+
};
|
|
127
|
+
const lane = priority === "high"
|
|
128
|
+
? this._high
|
|
129
|
+
: priority === "low"
|
|
130
|
+
? this._low
|
|
131
|
+
: this._normal;
|
|
132
|
+
lane.push(item);
|
|
133
|
+
if (externalSignal) {
|
|
134
|
+
externalSignal.addEventListener("abort", () => {
|
|
135
|
+
this.cancel(id);
|
|
136
|
+
}, { once: true });
|
|
137
|
+
}
|
|
138
|
+
this._drain();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
_drain() {
|
|
142
|
+
while (this._running < this._concurrency) {
|
|
143
|
+
const item = this._high.shift() ?? this._normal.shift() ?? this._low.shift();
|
|
144
|
+
if (!item)
|
|
145
|
+
break;
|
|
146
|
+
this._running++;
|
|
147
|
+
this._active.set(item.id, item);
|
|
148
|
+
const p = item
|
|
149
|
+
.task(item.controller.signal)
|
|
150
|
+
.then((value) => {
|
|
151
|
+
item.resolve(value);
|
|
152
|
+
}, (err) => {
|
|
153
|
+
this._onError?.(err instanceof Error ? err : new Error(String(err)), item.id);
|
|
154
|
+
item.reject(err);
|
|
155
|
+
})
|
|
156
|
+
.finally(() => {
|
|
157
|
+
this._running--;
|
|
158
|
+
this._active.delete(item.id);
|
|
159
|
+
this._drain();
|
|
160
|
+
});
|
|
161
|
+
void p;
|
|
162
|
+
}
|
|
163
|
+
this._notifyFlushWaiters();
|
|
164
|
+
}
|
|
165
|
+
_notifyFlushWaiters() {
|
|
166
|
+
if (this._running === 0 && this.size === 0) {
|
|
167
|
+
const waiters = this._flushWaiters.splice(0);
|
|
168
|
+
for (const w of waiters)
|
|
169
|
+
w();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Cancels a task by ID.
|
|
174
|
+
* - **Queued task**: removed from its lane; promise rejects with {@link QueueAbortError}.
|
|
175
|
+
* Task factory is never called.
|
|
176
|
+
* - **In-flight task**: internal AbortSignal is fired. The task is responsible
|
|
177
|
+
* for reacting to signal abortion and rejecting its promise.
|
|
178
|
+
*
|
|
179
|
+
* @returns `true` if the ID was found; `false` otherwise.
|
|
180
|
+
* @internal Public consumers should use `AddOptions.signal` for cancellation.
|
|
181
|
+
*/
|
|
182
|
+
cancel(id) {
|
|
183
|
+
for (const lane of [this._high, this._normal, this._low]) {
|
|
184
|
+
const idx = lane.findIndex((i) => i.id === id);
|
|
185
|
+
if (idx !== -1) {
|
|
186
|
+
const [item] = lane.splice(idx, 1);
|
|
187
|
+
item.reject(new QueueAbortError());
|
|
188
|
+
this._notifyFlushWaiters();
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const active = this._active.get(id);
|
|
193
|
+
if (active) {
|
|
194
|
+
active.controller.abort();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Resolves when all currently queued and running tasks have settled.
|
|
201
|
+
* Tasks added after `flush()` is called are included in the wait.
|
|
202
|
+
*/
|
|
203
|
+
flush() {
|
|
204
|
+
if (this._running === 0 && this.size === 0) {
|
|
205
|
+
return Promise.resolve();
|
|
206
|
+
}
|
|
207
|
+
return new Promise((resolve) => {
|
|
208
|
+
this._flushWaiters.push(resolve);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/** @internal Returns IDs of all queued (not yet running) items across all lanes. */
|
|
212
|
+
_queuedIds() {
|
|
213
|
+
return [
|
|
214
|
+
...this._high.map((i) => i.id),
|
|
215
|
+
...this._normal.map((i) => i.id),
|
|
216
|
+
...this._low.map((i) => i.id),
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
/** @internal Returns IDs of all currently running items. */
|
|
220
|
+
_runningIds() {
|
|
221
|
+
return [...this._active.keys()];
|
|
222
|
+
}
|
|
223
|
+
/** Number of tasks waiting to start (across all priority lanes). */
|
|
224
|
+
get size() {
|
|
225
|
+
return this._high.length + this._normal.length + this._low.length;
|
|
226
|
+
}
|
|
227
|
+
/** Number of tasks currently executing. */
|
|
228
|
+
get running() {
|
|
229
|
+
return this._running;
|
|
230
|
+
}
|
|
231
|
+
/** Total active work: `size + running`. */
|
|
232
|
+
get pending() {
|
|
233
|
+
return this.size + this._running;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=request-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-queue.js","sourceRoot":"","sources":["../../../src/utils/async/request-queue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkCH;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACtC,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,IAAI,mBAAmB,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IAWrB;;;OAGG;IACH,YAAY,OAA4B;QAdvB;;;;;WAAqB;QACrB;;;;;WAA8C;QAC9C;;;;mBAAqB,EAAE;WAAC;QACxB;;;;mBAAuB,EAAE;WAAC;QAC1B;;;;mBAAoB,EAAE;WAAC;QAChC;;;;mBAAW,CAAC;WAAC;QACJ;;;;mBAAU,IAAI,GAAG,EAAqB;WAAC;QAChD;;;;mBAAW,CAAC;WAAC;QACb;;;;mBAAmC,EAAE;WAAC;QAO1C,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,OAAO,CA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AE,eAAoB,GAC9B,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/utils/async/throttle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,aAAa,EACb,eAAe,EACf,iBAAiB,EACpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,OAAO,EACtD,EAAE,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,EACjC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,eAAoB,GAC9B,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAmHnC"}
|
|
@@ -44,6 +44,7 @@ export function throttleAsync(fn, interval, options = {}) {
|
|
|
44
44
|
* Executes the pending call if one exists
|
|
45
45
|
*/
|
|
46
46
|
const executePending = async () => {
|
|
47
|
+
/* v8 ignore next 2 — defensive guard against double-dispatch (unreachable via public API) */
|
|
47
48
|
if (pendingArgs === null)
|
|
48
49
|
return;
|
|
49
50
|
const args = pendingArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../../src/utils/async/throttle.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CACzB,EAAiC,EACjC,QAAgB,EAChB,UAA2B,EAAE;IAE7B,kBAAkB;IAClB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;QAC3B,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,EAAE,QAAQ,GAAG,IAAI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QAC9B,MAAM,aAAa,GAAG,QAAQ,GAAG,sBAAsB,CAAC;QACxD,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,cAAc,EAAE,CAAC;QACrB,CAAC,EAAE,aAAa,CAAC,CAAC;QAElB,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,MAAM,GAAG,GAAS,EAAE;QAC1B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACrB,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,SAAS,GAAG,IAAI,CAAC;QACrB,CAAC;QAED,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YACzB,aAAa,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;YACrD,cAAc,GAAG,IAAI,CAAC;YACtB,aAAa,GAAG,IAAI,CAAC;QACzB,CAAC;QAED,WAAW,GAAG,IAAI,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -2,6 +2,9 @@ import { Logger } from "#core/Logger.js";
|
|
|
2
2
|
import { RetryConfig, CircuitBreakerConfig } from "#core/RetryPolicy.js";
|
|
3
3
|
import { ValidationSchema } from "#core/ResponseValidator.js";
|
|
4
4
|
import { SchemaAdapter } from "./SchemaAdapter.js";
|
|
5
|
+
import { PromisePoolOptions } from "../async/promise-pool.js";
|
|
6
|
+
import { RequestQueueOptions } from "../async/request-queue.js";
|
|
7
|
+
import { BatchOptions } from "../async/request-batcher.js";
|
|
5
8
|
export type QueryParamValue = string | number | boolean | null | undefined;
|
|
6
9
|
export type QueryParam = QueryParamValue | QueryParamValue[] | Record<string, unknown>;
|
|
7
10
|
export type Locale = "en" | "es";
|
|
@@ -24,6 +27,12 @@ export interface ApiClientConfig {
|
|
|
24
27
|
logger?: Logger;
|
|
25
28
|
retryPolicy?: RetryConfig;
|
|
26
29
|
circuitBreaker?: CircuitBreakerConfig;
|
|
30
|
+
/** Optional pool for limiting concurrent requests. */
|
|
31
|
+
pool?: PromisePoolOptions;
|
|
32
|
+
/** Optional request queue for concurrency-limited, priority-aware request execution. */
|
|
33
|
+
queue?: RequestQueueOptions;
|
|
34
|
+
/** Optional request batcher for time-window deduplication of identical requests. */
|
|
35
|
+
batch?: BatchOptions;
|
|
27
36
|
}
|
|
28
37
|
export type RequestBody = Record<string, unknown> | unknown[] | string | FormData | Blob | BufferSource;
|
|
29
38
|
export interface RequestOptions<TResponse = unknown> extends Omit<RequestInit, "body"> {
|
|
@@ -32,6 +41,14 @@ export interface RequestOptions<TResponse = unknown> extends Omit<RequestInit, "
|
|
|
32
41
|
errorLocale?: Locale;
|
|
33
42
|
timeoutMs?: number;
|
|
34
43
|
validateResponse?: ValidationSchema | SchemaAdapter<TResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional post-processing pipeline applied to the response body after parsing
|
|
46
|
+
* and validation. Applied after `validateResponse` (if present) has already run.
|
|
47
|
+
* If `pipeline.process()` throws, the error propagates as a request error.
|
|
48
|
+
*/
|
|
49
|
+
pipeline?: {
|
|
50
|
+
process(data: TResponse): Promise<unknown>;
|
|
51
|
+
};
|
|
35
52
|
skipRetry?: boolean;
|
|
36
53
|
skipInterceptors?: boolean;
|
|
37
54
|
logHeaders?: boolean;
|
|
@@ -109,6 +126,9 @@ export declare class ApiClient {
|
|
|
109
126
|
private readonly errorMessages;
|
|
110
127
|
private readonly retryPolicy;
|
|
111
128
|
private readonly circuitBreaker;
|
|
129
|
+
private readonly pool?;
|
|
130
|
+
private readonly _queue?;
|
|
131
|
+
private readonly _batcher?;
|
|
112
132
|
/**
|
|
113
133
|
* Creates a new ApiClient instance.
|
|
114
134
|
*
|
|
@@ -123,7 +143,7 @@ export declare class ApiClient {
|
|
|
123
143
|
*
|
|
124
144
|
* @param config Client configuration including baseUrl, headers, and policies.
|
|
125
145
|
*/
|
|
126
|
-
constructor({ baseUrl, baseURL, defaultHeaders, fetchImpl, locale, errorMessages, timeoutMs, interceptors, disableInterceptors, logHeaders, redactHeaderKeys, logger, retryPolicy, circuitBreaker, }: ApiClientConfig);
|
|
146
|
+
constructor({ baseUrl, baseURL, defaultHeaders, fetchImpl, locale, errorMessages, timeoutMs, interceptors, disableInterceptors, logHeaders, redactHeaderKeys, logger, retryPolicy, circuitBreaker, pool, queue, batch, }: ApiClientConfig);
|
|
127
147
|
get<T>(path: string | URL, options?: RequestOptions<T>): Promise<T>;
|
|
128
148
|
/**
|
|
129
149
|
* POST request - Acepta body directamente o RequestOptions
|
|
@@ -177,6 +197,7 @@ export declare class ApiClient {
|
|
|
177
197
|
*/
|
|
178
198
|
private handleRequestError;
|
|
179
199
|
request<T>(path: string | URL, options?: RequestOptions<T>): Promise<T>;
|
|
200
|
+
private executeRequest;
|
|
180
201
|
/**
|
|
181
202
|
* Normaliza el segundo parámetro de post/put/patch para soportar:
|
|
182
203
|
* 1. Body directo: post("/path", { name: "John" })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../../src/utils/core/ApiClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../../src/utils/core/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAGH,WAAW,EACX,oBAAoB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEH,gBAAgB,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAe,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAgB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAkB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI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AAI,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IAI/D;;;;;;;;;;;;;;;OAeG;IACG,OAAO,CAAC,CAAC,EAAE,OAAO,SAAS,YAAY,GAAG,YAAY,EACxD,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACrD,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IA8ChC;;OAEG;YACW,oBAAoB;IA8DlC;;OAEG;YACW,eAAe;IAyC7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoCpB,OAAO,CAAC,CAAC,EACX,IAAI,EAAE,MAAM,GAAG,GAAG,EAClB,OAAO,GAAE,cAAc,CAAC,CAAC,CAAM,GAChC,OAAO,CAAC,CAAC,CAAC;YA4BC,cAAc;IA8G5B;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAgB9B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAkDxB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,WAAW;YAYL,WAAW;IAwBzB,OAAO,CAAC,QAAQ;YAsBF,UAAU;IAwBxB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,mBAAmB;CAK9B;AAKD,eAAO,MAAM,eAAe,GAAI,QAAQ,eAAe,cAC9B,CAAC"}
|
|
@@ -3,6 +3,9 @@ import { retry as retryFn } from "../async/retry.js";
|
|
|
3
3
|
import { RetryPolicy, CircuitBreaker, } from "#core/RetryPolicy.js";
|
|
4
4
|
import { ResponseValidator, } from "#core/ResponseValidator.js";
|
|
5
5
|
import { isSchemaAdapter } from "./SchemaAdapter.js";
|
|
6
|
+
import { PromisePool } from "../async/promise-pool.js";
|
|
7
|
+
import { RequestQueue } from "../async/request-queue.js";
|
|
8
|
+
import { RequestBatcher } from "../async/request-batcher.js";
|
|
6
9
|
export class ApiError extends Error {
|
|
7
10
|
constructor(status, statusText, message, body, isTimeout = false) {
|
|
8
11
|
super(message);
|
|
@@ -64,6 +67,7 @@ export class ApiError extends Error {
|
|
|
64
67
|
parts.push(`Body: ${bodyStr}`);
|
|
65
68
|
}
|
|
66
69
|
catch {
|
|
70
|
+
/* v8 ignore next */
|
|
67
71
|
parts.push(`Body: ${this.body}`);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
@@ -127,7 +131,7 @@ export class ApiClient {
|
|
|
127
131
|
*
|
|
128
132
|
* @param config Client configuration including baseUrl, headers, and policies.
|
|
129
133
|
*/
|
|
130
|
-
constructor({ baseUrl, baseURL, defaultHeaders, fetchImpl, locale = "es", errorMessages, timeoutMs = 15000, interceptors, disableInterceptors = false, logHeaders = false, redactHeaderKeys, logger, retryPolicy, circuitBreaker, }) {
|
|
134
|
+
constructor({ baseUrl, baseURL, defaultHeaders, fetchImpl, locale = "es", errorMessages, timeoutMs = 15000, interceptors, disableInterceptors = false, logHeaders = false, redactHeaderKeys, logger, retryPolicy, circuitBreaker, pool, queue, batch, }) {
|
|
131
135
|
Object.defineProperty(this, "baseUrl", {
|
|
132
136
|
enumerable: true,
|
|
133
137
|
configurable: true,
|
|
@@ -206,6 +210,24 @@ export class ApiClient {
|
|
|
206
210
|
writable: true,
|
|
207
211
|
value: void 0
|
|
208
212
|
});
|
|
213
|
+
Object.defineProperty(this, "pool", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
configurable: true,
|
|
216
|
+
writable: true,
|
|
217
|
+
value: void 0
|
|
218
|
+
});
|
|
219
|
+
Object.defineProperty(this, "_queue", {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
configurable: true,
|
|
222
|
+
writable: true,
|
|
223
|
+
value: void 0
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(this, "_batcher", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
configurable: true,
|
|
228
|
+
writable: true,
|
|
229
|
+
value: void 0
|
|
230
|
+
});
|
|
209
231
|
// Support both baseUrl and baseURL (common convention)
|
|
210
232
|
const url = baseUrl ?? baseURL;
|
|
211
233
|
if (!url) {
|
|
@@ -231,6 +253,9 @@ export class ApiClient {
|
|
|
231
253
|
this.logger = logger;
|
|
232
254
|
this.retryPolicy = new RetryPolicy(retryPolicy);
|
|
233
255
|
this.circuitBreaker = new CircuitBreaker(circuitBreaker);
|
|
256
|
+
this.pool = pool ? new PromisePool(pool) : undefined;
|
|
257
|
+
this._queue = queue ? new RequestQueue(queue) : undefined;
|
|
258
|
+
this._batcher = batch ? new RequestBatcher(batch) : undefined;
|
|
234
259
|
}
|
|
235
260
|
// -------------------------
|
|
236
261
|
// Core request shortcuts
|
|
@@ -400,9 +425,11 @@ export class ApiClient {
|
|
|
400
425
|
*/
|
|
401
426
|
handleRequestError(err, path, method) {
|
|
402
427
|
const pathStr = String(path);
|
|
428
|
+
/* v8 ignore start */
|
|
403
429
|
if (err instanceof Error && err.name === "AbortError") {
|
|
404
430
|
throw new ApiError(408, "Timeout", "Request timeout", null, true);
|
|
405
431
|
}
|
|
432
|
+
/* v8 ignore end */
|
|
406
433
|
// Enhanced logging for ApiError
|
|
407
434
|
if (err instanceof ApiError) {
|
|
408
435
|
this.logger?.error("API Request failed", {
|
|
@@ -414,12 +441,34 @@ export class ApiClient {
|
|
|
414
441
|
}, err);
|
|
415
442
|
}
|
|
416
443
|
else {
|
|
444
|
+
/* v8 ignore next 6 */
|
|
417
445
|
this.logger?.error("Request failed", { path: pathStr, method }, err instanceof Error ? err : new Error(String(err)));
|
|
418
446
|
}
|
|
419
447
|
throw err;
|
|
420
448
|
}
|
|
421
449
|
async request(path, options = {}) {
|
|
422
|
-
|
|
450
|
+
// US4: RequestQueue — concurrency-limited, priority-aware queue
|
|
451
|
+
if (this._queue) {
|
|
452
|
+
return this._queue.add((_signal) => this.executeRequest(path, options));
|
|
453
|
+
}
|
|
454
|
+
// US4: RequestBatcher — time-window deduplication
|
|
455
|
+
if (this._batcher) {
|
|
456
|
+
const pathStr = String(path);
|
|
457
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
458
|
+
const proxyInit = { method };
|
|
459
|
+
return this._batcher.add(pathStr, proxyInit, (_url, _init) => this.executeRequest(path, options));
|
|
460
|
+
}
|
|
461
|
+
// T026: legacy pool support (003) — if a pool is configured, route through it
|
|
462
|
+
if (this.pool) {
|
|
463
|
+
const results = await this.pool.run([
|
|
464
|
+
() => this.executeRequest(path, options),
|
|
465
|
+
]);
|
|
466
|
+
return results[0];
|
|
467
|
+
}
|
|
468
|
+
return this.executeRequest(path, options);
|
|
469
|
+
}
|
|
470
|
+
async executeRequest(path, options = {}) {
|
|
471
|
+
const { validateResponse, pipeline, skipRetry, skipInterceptors, logHeaders, ...requestOptions } = options;
|
|
423
472
|
const executeRequest = async () => {
|
|
424
473
|
return this.circuitBreaker.execute(async () => {
|
|
425
474
|
const { errorLocale, ...rest } = requestOptions;
|
|
@@ -430,12 +479,14 @@ export class ApiClient {
|
|
|
430
479
|
const headersForLog = shouldLogHeaders
|
|
431
480
|
? this.redactHeaders(this.normalizeHeaders(init.headers))
|
|
432
481
|
: undefined;
|
|
482
|
+
/* v8 ignore start */
|
|
433
483
|
this.logger?.debug("HTTP Request", {
|
|
434
484
|
method: rest.method,
|
|
435
485
|
url,
|
|
436
486
|
...(shouldLogHeaders ? { headers: headersForLog } : {}),
|
|
437
487
|
body: rest.body,
|
|
438
488
|
});
|
|
489
|
+
/* v8 ignore end */
|
|
439
490
|
try {
|
|
440
491
|
const response = await this.withTimeout(this.fetchImpl(url, init), timeout, controller);
|
|
441
492
|
// Response interceptor
|
|
@@ -449,7 +500,11 @@ export class ApiClient {
|
|
|
449
500
|
throw await this.toApiError(finalResponse, errorLocale);
|
|
450
501
|
}
|
|
451
502
|
// Process response
|
|
452
|
-
|
|
503
|
+
let data = await this.processResponse(finalResponse, validateResponse);
|
|
504
|
+
// Apply optional pipeline post-processing
|
|
505
|
+
if (pipeline) {
|
|
506
|
+
data = await pipeline.process(data);
|
|
507
|
+
}
|
|
453
508
|
this.logger?.debug("HTTP Response", {
|
|
454
509
|
status: finalResponse.status,
|
|
455
510
|
url,
|
|
@@ -472,7 +527,11 @@ export class ApiClient {
|
|
|
472
527
|
baseDelay: config.initialDelayMs,
|
|
473
528
|
maxDelay: config.maxDelayMs,
|
|
474
529
|
backoff: "exponential",
|
|
475
|
-
shouldRetry: (err) =>
|
|
530
|
+
shouldRetry: (err) =>
|
|
531
|
+
/* v8 ignore next */
|
|
532
|
+
config.shouldRetry?.(err instanceof Error ? err : new Error(String(err)), 0
|
|
533
|
+
/* v8 ignore next */
|
|
534
|
+
) ?? false,
|
|
476
535
|
});
|
|
477
536
|
}
|
|
478
537
|
// -------------------------
|
|
@@ -626,6 +685,7 @@ export class ApiClient {
|
|
|
626
685
|
if (dict[status])
|
|
627
686
|
return dict[status];
|
|
628
687
|
}
|
|
688
|
+
/* v8 ignore next */
|
|
629
689
|
return (GENERIC_ERROR_MESSAGE[this.locale] ?? GENERIC_ERROR_MESSAGE.es)(status, statusText);
|
|
630
690
|
}
|
|
631
691
|
getLocalePreference(override) {
|