@npora/request 1.6.0 → 1.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.
- package/README.md +21 -0
- package/dist/index.cjs +2653 -3236
- package/dist/index.d.cts +697 -597
- package/dist/index.d.ts +697 -597
- package/dist/index.js +2637 -3195
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -116,6 +116,7 @@ import {
|
|
|
116
116
|
authPlugin,
|
|
117
117
|
cachePlugin,
|
|
118
118
|
circuitBreakerPlugin,
|
|
119
|
+
concurrencyPlugin,
|
|
119
120
|
createClient,
|
|
120
121
|
retryPlugin
|
|
121
122
|
} from '@npora/request'
|
|
@@ -129,6 +130,7 @@ const request = createClient()
|
|
|
129
130
|
maxElapsedTime: 10000
|
|
130
131
|
}))
|
|
131
132
|
.use(circuitBreakerPlugin())
|
|
133
|
+
.use(concurrencyPlugin({ maxConcurrent: 20 }))
|
|
132
134
|
.use(cache)
|
|
133
135
|
.use(authPlugin({
|
|
134
136
|
token: () => accessToken,
|
|
@@ -167,6 +169,7 @@ Built-in plugins:
|
|
|
167
169
|
- `retryPlugin()`
|
|
168
170
|
- `cachePlugin()`
|
|
169
171
|
- `circuitBreakerPlugin()`
|
|
172
|
+
- `concurrencyPlugin()`
|
|
170
173
|
- `authPlugin()`
|
|
171
174
|
- `loggerPlugin()`
|
|
172
175
|
- `uploadPlugin()`
|
|
@@ -194,6 +197,22 @@ the stable `CIRCUIT_OPEN` error code and permit a bounded half-open probe after
|
|
|
194
197
|
the recovery window. Inactive circuit state is retained with LRU eviction;
|
|
195
198
|
active requests are never evicted and can temporarily exceed `maxCircuits`.
|
|
196
199
|
|
|
200
|
+
Bound concurrent logical requests and queue short bursts before adapter I/O:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const concurrency = concurrencyPlugin({
|
|
204
|
+
maxConcurrent: 20,
|
|
205
|
+
maxQueue: 200,
|
|
206
|
+
queueTimeout: 5000
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
const request = createClient().use(concurrency)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Limits are isolated by resolved request origin. Queued requests are admitted
|
|
213
|
+
in FIFO order and remain abortable through their request signal. Full queues
|
|
214
|
+
and expired queue waits reject with the stable `CONCURRENCY_LIMIT` error code.
|
|
215
|
+
|
|
197
216
|
Inject a structured logger when request correlation and timing are needed:
|
|
198
217
|
|
|
199
218
|
```ts
|
|
@@ -268,7 +287,9 @@ Stable request error codes:
|
|
|
268
287
|
- `TIMEOUT_ERROR`
|
|
269
288
|
- `ABORT_ERROR`
|
|
270
289
|
- `PARSER_ERROR`
|
|
290
|
+
- `RESPONSE_TOO_LARGE`
|
|
271
291
|
- `CIRCUIT_OPEN`
|
|
292
|
+
- `CONCURRENCY_LIMIT`
|
|
272
293
|
|
|
273
294
|
## Documentation
|
|
274
295
|
|