@npora/request 1.5.0 → 1.7.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 +28 -2
- package/dist/index.cjs +384 -48
- package/dist/index.d.cts +90 -2
- package/dist/index.d.ts +90 -2
- package/dist/index.js +383 -48
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -98,6 +98,24 @@ interface CacheOptions {
|
|
|
98
98
|
*/
|
|
99
99
|
dedupe?: boolean;
|
|
100
100
|
}
|
|
101
|
+
interface ConcurrencyOptions {
|
|
102
|
+
/**
|
|
103
|
+
* Enable concurrency limiting for this request.
|
|
104
|
+
*
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Override the isolation key for this request.
|
|
110
|
+
*/
|
|
111
|
+
key?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Maximum time in milliseconds this request may wait for a permit.
|
|
114
|
+
*
|
|
115
|
+
* @default the plugin-level queueTimeout
|
|
116
|
+
*/
|
|
117
|
+
queueTimeout?: number;
|
|
118
|
+
}
|
|
101
119
|
interface AuthOptions {
|
|
102
120
|
token?: string | (() => string | Promise<string>);
|
|
103
121
|
scheme?: string;
|
|
@@ -221,6 +239,7 @@ interface RequestExtensions {
|
|
|
221
239
|
auth?: AuthOptions;
|
|
222
240
|
cache?: CacheOptions;
|
|
223
241
|
circuitBreaker?: CircuitBreakerOptions;
|
|
242
|
+
concurrency?: ConcurrencyOptions;
|
|
224
243
|
download?: DownloadOptions;
|
|
225
244
|
logger?: LoggerOptions;
|
|
226
245
|
retry?: number | RetryOptions;
|
|
@@ -516,7 +535,7 @@ declare function createClient(options?: ClientOptions): Client;
|
|
|
516
535
|
/**
|
|
517
536
|
* Public request error codes.
|
|
518
537
|
*/
|
|
519
|
-
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'CIRCUIT_OPEN';
|
|
538
|
+
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
520
539
|
interface RequestErrorOptions<T = unknown> {
|
|
521
540
|
/**
|
|
522
541
|
* Stable machine-readable error code.
|
|
@@ -637,8 +656,19 @@ interface CacheStore {
|
|
|
637
656
|
delete(key: string): MaybePromise<void>;
|
|
638
657
|
clear(): MaybePromise<void>;
|
|
639
658
|
}
|
|
659
|
+
interface MemoryCacheStoreOptions {
|
|
660
|
+
/**
|
|
661
|
+
* Maximum entries retained by the in-memory LRU store.
|
|
662
|
+
* Use `Infinity` for no practical limit.
|
|
663
|
+
*
|
|
664
|
+
* @default 1000
|
|
665
|
+
*/
|
|
666
|
+
maxEntries?: number;
|
|
667
|
+
}
|
|
640
668
|
declare class MemoryCacheStore implements CacheStore {
|
|
641
669
|
private readonly entries;
|
|
670
|
+
private readonly maxEntries;
|
|
671
|
+
constructor(options?: MemoryCacheStoreOptions);
|
|
642
672
|
get(key: string): CacheEntry | undefined;
|
|
643
673
|
set(key: string, entry: CacheEntry): void;
|
|
644
674
|
delete(key: string): void;
|
|
@@ -663,6 +693,13 @@ interface CachePluginOptions {
|
|
|
663
693
|
* @default an isolated MemoryCacheStore
|
|
664
694
|
*/
|
|
665
695
|
store?: CacheStore;
|
|
696
|
+
/**
|
|
697
|
+
* Maximum entries retained by the default MemoryCacheStore.
|
|
698
|
+
* Ignored when `store` is provided.
|
|
699
|
+
*
|
|
700
|
+
* @default 1000
|
|
701
|
+
*/
|
|
702
|
+
maxEntries?: number;
|
|
666
703
|
/**
|
|
667
704
|
* Share one network operation between concurrent equivalent requests.
|
|
668
705
|
*
|
|
@@ -700,6 +737,13 @@ interface CircuitBreakerPluginOptions {
|
|
|
700
737
|
* @default 1
|
|
701
738
|
*/
|
|
702
739
|
halfOpenMaxRequests?: number;
|
|
740
|
+
/**
|
|
741
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
742
|
+
* Active requests are never evicted and may temporarily exceed the limit.
|
|
743
|
+
*
|
|
744
|
+
* @default 1000
|
|
745
|
+
*/
|
|
746
|
+
maxCircuits?: number;
|
|
703
747
|
/**
|
|
704
748
|
* Create the default isolation key for a request.
|
|
705
749
|
*
|
|
@@ -723,6 +767,50 @@ interface CircuitBreakerPlugin extends Plugin {
|
|
|
723
767
|
}
|
|
724
768
|
declare function circuitBreakerPlugin(options?: CircuitBreakerPluginOptions): CircuitBreakerPlugin;
|
|
725
769
|
|
|
770
|
+
interface ConcurrencyPluginOptions {
|
|
771
|
+
/**
|
|
772
|
+
* Maximum active logical requests for each isolation key.
|
|
773
|
+
*
|
|
774
|
+
* @default 10
|
|
775
|
+
*/
|
|
776
|
+
maxConcurrent?: number;
|
|
777
|
+
/**
|
|
778
|
+
* Maximum queued requests for each isolation key.
|
|
779
|
+
* Set to zero to reject instead of waiting.
|
|
780
|
+
*
|
|
781
|
+
* @default 1000
|
|
782
|
+
*/
|
|
783
|
+
maxQueue?: number;
|
|
784
|
+
/**
|
|
785
|
+
* Maximum time in milliseconds a request may wait for a permit.
|
|
786
|
+
*
|
|
787
|
+
* @default 30000
|
|
788
|
+
*/
|
|
789
|
+
queueTimeout?: number;
|
|
790
|
+
/**
|
|
791
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
792
|
+
* Active and queued states are never evicted and may temporarily exceed
|
|
793
|
+
* the limit.
|
|
794
|
+
*
|
|
795
|
+
* @default 1000
|
|
796
|
+
*/
|
|
797
|
+
maxKeys?: number;
|
|
798
|
+
/**
|
|
799
|
+
* Create the default isolation key for a request.
|
|
800
|
+
*
|
|
801
|
+
* @default the resolved request origin or "default"
|
|
802
|
+
*/
|
|
803
|
+
createKey?: (config: RequestConfig) => string;
|
|
804
|
+
}
|
|
805
|
+
interface ConcurrencyState {
|
|
806
|
+
active: number;
|
|
807
|
+
queued: number;
|
|
808
|
+
}
|
|
809
|
+
interface ConcurrencyPlugin extends Plugin {
|
|
810
|
+
getState(key: string): Readonly<ConcurrencyState>;
|
|
811
|
+
}
|
|
812
|
+
declare function concurrencyPlugin(options?: ConcurrencyPluginOptions): ConcurrencyPlugin;
|
|
813
|
+
|
|
726
814
|
type DownloadTransport = 'auto' | 'fetch' | 'xhr';
|
|
727
815
|
interface DownloadPluginOptions {
|
|
728
816
|
/**
|
|
@@ -743,4 +831,4 @@ declare function retryPlugin(defaultOptions?: RetryOptions): Plugin;
|
|
|
743
831
|
|
|
744
832
|
declare function uploadPlugin(): Plugin;
|
|
745
833
|
|
|
746
|
-
export { type Adapter, type AuthOptions, type AuthPluginOptions, type AuthTokenStorage, type CacheEntry, type CacheOptions, type CachePlugin, type CachePluginOptions, type CacheStore, type CircuitBreakerOptions, type CircuitBreakerPlugin, type CircuitBreakerPluginOptions, type CircuitBreakerStateChange, type CircuitState, Client, type ClientOptions, type DownloadOptions, type DownloadPluginOptions, type DownloadProgress, type DownloadTransport, type ErrorLogEntry, FetchAdapter, type FetchOptions, type HttpMethod, type Interceptor, InterceptorManager, type InterceptorOptions, type LoggerEntry, type LoggerOptions, MemoryCacheStore, MockAdapter, type MockAdapterOptions, type MockHandler, type MockReply, type MockReplyHandler, type MockRequestMatcher, type MockResponseOptions, type MockRoute, type MockURLMatcher, type NporaResponse, type Plugin, type PluginCleanup, type PluginContext, PluginError, type PluginErrorCode, type PluginErrorOptions, type PluginHookManager, type PluginInterceptorManager, type QueryParams, type QueryValue, type RequestConfig, RequestError, type RequestErrorCode, type RequestErrorOptions, type RequestExtensions, type RequestLogEntry, type RequestLogger, type ResponseLogEntry, type ResponseType, type RetryEvent, type RetryOptions, type UploadData, type UploadOptions, type UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|
|
834
|
+
export { type Adapter, type AuthOptions, type AuthPluginOptions, type AuthTokenStorage, type CacheEntry, type CacheOptions, type CachePlugin, type CachePluginOptions, type CacheStore, type CircuitBreakerOptions, type CircuitBreakerPlugin, type CircuitBreakerPluginOptions, type CircuitBreakerStateChange, type CircuitState, Client, type ClientOptions, type ConcurrencyOptions, type ConcurrencyPlugin, type ConcurrencyPluginOptions, type ConcurrencyState, type DownloadOptions, type DownloadPluginOptions, type DownloadProgress, type DownloadTransport, type ErrorLogEntry, FetchAdapter, type FetchOptions, type HttpMethod, type Interceptor, InterceptorManager, type InterceptorOptions, type LoggerEntry, type LoggerOptions, MemoryCacheStore, type MemoryCacheStoreOptions, MockAdapter, type MockAdapterOptions, type MockHandler, type MockReply, type MockReplyHandler, type MockRequestMatcher, type MockResponseOptions, type MockRoute, type MockURLMatcher, type NporaResponse, type Plugin, type PluginCleanup, type PluginContext, PluginError, type PluginErrorCode, type PluginErrorOptions, type PluginHookManager, type PluginInterceptorManager, type QueryParams, type QueryValue, type RequestConfig, RequestError, type RequestErrorCode, type RequestErrorOptions, type RequestExtensions, type RequestLogEntry, type RequestLogger, type ResponseLogEntry, type ResponseType, type RetryEvent, type RetryOptions, type UploadData, type UploadOptions, type UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, concurrencyPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,24 @@ interface CacheOptions {
|
|
|
98
98
|
*/
|
|
99
99
|
dedupe?: boolean;
|
|
100
100
|
}
|
|
101
|
+
interface ConcurrencyOptions {
|
|
102
|
+
/**
|
|
103
|
+
* Enable concurrency limiting for this request.
|
|
104
|
+
*
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Override the isolation key for this request.
|
|
110
|
+
*/
|
|
111
|
+
key?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Maximum time in milliseconds this request may wait for a permit.
|
|
114
|
+
*
|
|
115
|
+
* @default the plugin-level queueTimeout
|
|
116
|
+
*/
|
|
117
|
+
queueTimeout?: number;
|
|
118
|
+
}
|
|
101
119
|
interface AuthOptions {
|
|
102
120
|
token?: string | (() => string | Promise<string>);
|
|
103
121
|
scheme?: string;
|
|
@@ -221,6 +239,7 @@ interface RequestExtensions {
|
|
|
221
239
|
auth?: AuthOptions;
|
|
222
240
|
cache?: CacheOptions;
|
|
223
241
|
circuitBreaker?: CircuitBreakerOptions;
|
|
242
|
+
concurrency?: ConcurrencyOptions;
|
|
224
243
|
download?: DownloadOptions;
|
|
225
244
|
logger?: LoggerOptions;
|
|
226
245
|
retry?: number | RetryOptions;
|
|
@@ -516,7 +535,7 @@ declare function createClient(options?: ClientOptions): Client;
|
|
|
516
535
|
/**
|
|
517
536
|
* Public request error codes.
|
|
518
537
|
*/
|
|
519
|
-
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'CIRCUIT_OPEN';
|
|
538
|
+
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
520
539
|
interface RequestErrorOptions<T = unknown> {
|
|
521
540
|
/**
|
|
522
541
|
* Stable machine-readable error code.
|
|
@@ -637,8 +656,19 @@ interface CacheStore {
|
|
|
637
656
|
delete(key: string): MaybePromise<void>;
|
|
638
657
|
clear(): MaybePromise<void>;
|
|
639
658
|
}
|
|
659
|
+
interface MemoryCacheStoreOptions {
|
|
660
|
+
/**
|
|
661
|
+
* Maximum entries retained by the in-memory LRU store.
|
|
662
|
+
* Use `Infinity` for no practical limit.
|
|
663
|
+
*
|
|
664
|
+
* @default 1000
|
|
665
|
+
*/
|
|
666
|
+
maxEntries?: number;
|
|
667
|
+
}
|
|
640
668
|
declare class MemoryCacheStore implements CacheStore {
|
|
641
669
|
private readonly entries;
|
|
670
|
+
private readonly maxEntries;
|
|
671
|
+
constructor(options?: MemoryCacheStoreOptions);
|
|
642
672
|
get(key: string): CacheEntry | undefined;
|
|
643
673
|
set(key: string, entry: CacheEntry): void;
|
|
644
674
|
delete(key: string): void;
|
|
@@ -663,6 +693,13 @@ interface CachePluginOptions {
|
|
|
663
693
|
* @default an isolated MemoryCacheStore
|
|
664
694
|
*/
|
|
665
695
|
store?: CacheStore;
|
|
696
|
+
/**
|
|
697
|
+
* Maximum entries retained by the default MemoryCacheStore.
|
|
698
|
+
* Ignored when `store` is provided.
|
|
699
|
+
*
|
|
700
|
+
* @default 1000
|
|
701
|
+
*/
|
|
702
|
+
maxEntries?: number;
|
|
666
703
|
/**
|
|
667
704
|
* Share one network operation between concurrent equivalent requests.
|
|
668
705
|
*
|
|
@@ -700,6 +737,13 @@ interface CircuitBreakerPluginOptions {
|
|
|
700
737
|
* @default 1
|
|
701
738
|
*/
|
|
702
739
|
halfOpenMaxRequests?: number;
|
|
740
|
+
/**
|
|
741
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
742
|
+
* Active requests are never evicted and may temporarily exceed the limit.
|
|
743
|
+
*
|
|
744
|
+
* @default 1000
|
|
745
|
+
*/
|
|
746
|
+
maxCircuits?: number;
|
|
703
747
|
/**
|
|
704
748
|
* Create the default isolation key for a request.
|
|
705
749
|
*
|
|
@@ -723,6 +767,50 @@ interface CircuitBreakerPlugin extends Plugin {
|
|
|
723
767
|
}
|
|
724
768
|
declare function circuitBreakerPlugin(options?: CircuitBreakerPluginOptions): CircuitBreakerPlugin;
|
|
725
769
|
|
|
770
|
+
interface ConcurrencyPluginOptions {
|
|
771
|
+
/**
|
|
772
|
+
* Maximum active logical requests for each isolation key.
|
|
773
|
+
*
|
|
774
|
+
* @default 10
|
|
775
|
+
*/
|
|
776
|
+
maxConcurrent?: number;
|
|
777
|
+
/**
|
|
778
|
+
* Maximum queued requests for each isolation key.
|
|
779
|
+
* Set to zero to reject instead of waiting.
|
|
780
|
+
*
|
|
781
|
+
* @default 1000
|
|
782
|
+
*/
|
|
783
|
+
maxQueue?: number;
|
|
784
|
+
/**
|
|
785
|
+
* Maximum time in milliseconds a request may wait for a permit.
|
|
786
|
+
*
|
|
787
|
+
* @default 30000
|
|
788
|
+
*/
|
|
789
|
+
queueTimeout?: number;
|
|
790
|
+
/**
|
|
791
|
+
* Maximum inactive isolation states retained by this plugin instance.
|
|
792
|
+
* Active and queued states are never evicted and may temporarily exceed
|
|
793
|
+
* the limit.
|
|
794
|
+
*
|
|
795
|
+
* @default 1000
|
|
796
|
+
*/
|
|
797
|
+
maxKeys?: number;
|
|
798
|
+
/**
|
|
799
|
+
* Create the default isolation key for a request.
|
|
800
|
+
*
|
|
801
|
+
* @default the resolved request origin or "default"
|
|
802
|
+
*/
|
|
803
|
+
createKey?: (config: RequestConfig) => string;
|
|
804
|
+
}
|
|
805
|
+
interface ConcurrencyState {
|
|
806
|
+
active: number;
|
|
807
|
+
queued: number;
|
|
808
|
+
}
|
|
809
|
+
interface ConcurrencyPlugin extends Plugin {
|
|
810
|
+
getState(key: string): Readonly<ConcurrencyState>;
|
|
811
|
+
}
|
|
812
|
+
declare function concurrencyPlugin(options?: ConcurrencyPluginOptions): ConcurrencyPlugin;
|
|
813
|
+
|
|
726
814
|
type DownloadTransport = 'auto' | 'fetch' | 'xhr';
|
|
727
815
|
interface DownloadPluginOptions {
|
|
728
816
|
/**
|
|
@@ -743,4 +831,4 @@ declare function retryPlugin(defaultOptions?: RetryOptions): Plugin;
|
|
|
743
831
|
|
|
744
832
|
declare function uploadPlugin(): Plugin;
|
|
745
833
|
|
|
746
|
-
export { type Adapter, type AuthOptions, type AuthPluginOptions, type AuthTokenStorage, type CacheEntry, type CacheOptions, type CachePlugin, type CachePluginOptions, type CacheStore, type CircuitBreakerOptions, type CircuitBreakerPlugin, type CircuitBreakerPluginOptions, type CircuitBreakerStateChange, type CircuitState, Client, type ClientOptions, type DownloadOptions, type DownloadPluginOptions, type DownloadProgress, type DownloadTransport, type ErrorLogEntry, FetchAdapter, type FetchOptions, type HttpMethod, type Interceptor, InterceptorManager, type InterceptorOptions, type LoggerEntry, type LoggerOptions, MemoryCacheStore, MockAdapter, type MockAdapterOptions, type MockHandler, type MockReply, type MockReplyHandler, type MockRequestMatcher, type MockResponseOptions, type MockRoute, type MockURLMatcher, type NporaResponse, type Plugin, type PluginCleanup, type PluginContext, PluginError, type PluginErrorCode, type PluginErrorOptions, type PluginHookManager, type PluginInterceptorManager, type QueryParams, type QueryValue, type RequestConfig, RequestError, type RequestErrorCode, type RequestErrorOptions, type RequestExtensions, type RequestLogEntry, type RequestLogger, type ResponseLogEntry, type ResponseType, type RetryEvent, type RetryOptions, type UploadData, type UploadOptions, type UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|
|
834
|
+
export { type Adapter, type AuthOptions, type AuthPluginOptions, type AuthTokenStorage, type CacheEntry, type CacheOptions, type CachePlugin, type CachePluginOptions, type CacheStore, type CircuitBreakerOptions, type CircuitBreakerPlugin, type CircuitBreakerPluginOptions, type CircuitBreakerStateChange, type CircuitState, Client, type ClientOptions, type ConcurrencyOptions, type ConcurrencyPlugin, type ConcurrencyPluginOptions, type ConcurrencyState, type DownloadOptions, type DownloadPluginOptions, type DownloadProgress, type DownloadTransport, type ErrorLogEntry, FetchAdapter, type FetchOptions, type HttpMethod, type Interceptor, InterceptorManager, type InterceptorOptions, type LoggerEntry, type LoggerOptions, MemoryCacheStore, type MemoryCacheStoreOptions, MockAdapter, type MockAdapterOptions, type MockHandler, type MockReply, type MockReplyHandler, type MockRequestMatcher, type MockResponseOptions, type MockRoute, type MockURLMatcher, type NporaResponse, type Plugin, type PluginCleanup, type PluginContext, PluginError, type PluginErrorCode, type PluginErrorOptions, type PluginHookManager, type PluginInterceptorManager, type QueryParams, type QueryValue, type RequestConfig, RequestError, type RequestErrorCode, type RequestErrorOptions, type RequestExtensions, type RequestLogEntry, type RequestLogger, type ResponseLogEntry, type ResponseType, type RetryEvent, type RetryOptions, type UploadData, type UploadOptions, type UploadProgress, authPlugin, cachePlugin, circuitBreakerPlugin, concurrencyPlugin, createClient, downloadPlugin, loggerPlugin, retryPlugin, uploadPlugin };
|