aziosxjs 0.4.0 → 1.0.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/LICENSE +21 -0
- package/README.md +92 -267
- package/dist/cache/memoryCache.d.ts +4 -0
- package/dist/cache/memoryCache.js +32 -0
- package/dist/cache/memoryCache.js.map +1 -0
- package/dist/core/Azios.d.ts +33 -3
- package/dist/core/Azios.js +119 -2
- package/dist/core/Azios.js.map +1 -1
- package/dist/core/createInstance.js +3 -0
- package/dist/core/createInstance.js.map +1 -1
- package/dist/core/dispatchRequest.d.ts +1 -2
- package/dist/core/dispatchRequest.js +68 -42
- package/dist/core/dispatchRequest.js.map +1 -1
- package/dist/core/requestStore.d.ts +3 -0
- package/dist/core/requestStore.js +16 -0
- package/dist/core/requestStore.js.map +1 -0
- package/dist/errors/AziosError.d.ts +2 -2
- package/dist/errors/AziosError.js +6 -3
- package/dist/errors/AziosError.js.map +1 -1
- package/dist/helpers/buildURL.d.ts +1 -0
- package/dist/helpers/buildURL.js +27 -0
- package/dist/helpers/buildURL.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/dist/middleware/MiddlewarePipeline.d.ts +54 -0
- package/dist/middleware/MiddlewarePipeline.js +122 -0
- package/dist/middleware/MiddlewarePipeline.js.map +1 -0
- package/dist/middleware/compose.d.ts +1 -0
- package/dist/middleware/compose.js +25 -0
- package/dist/middleware/compose.js.map +1 -0
- package/dist/middleware/middlewareManager.d.ts +4 -0
- package/dist/middleware/middlewareManager.js +12 -0
- package/dist/middleware/middlewareManager.js.map +1 -0
- package/dist/plugins/pluginManager.d.ts +44 -0
- package/dist/plugins/pluginManager.js +120 -0
- package/dist/plugins/pluginManager.js.map +1 -0
- package/dist/rateLimiter/rateLimiter.d.ts +1 -0
- package/dist/rateLimiter/rateLimiter.js +31 -0
- package/dist/rateLimiter/rateLimiter.js.map +1 -0
- package/dist/runtimes/AdapterFactory.d.ts +22 -0
- package/dist/runtimes/AdapterFactory.js +43 -0
- package/dist/runtimes/AdapterFactory.js.map +1 -0
- package/dist/runtimes/HttpAdapter.d.ts +23 -0
- package/dist/runtimes/HttpAdapter.js +10 -0
- package/dist/runtimes/HttpAdapter.js.map +1 -0
- package/dist/runtimes/UniversalHttpAdapter.d.ts +19 -0
- package/dist/runtimes/UniversalHttpAdapter.js +114 -0
- package/dist/runtimes/UniversalHttpAdapter.js.map +1 -0
- package/dist/runtimes/detectRuntime.d.ts +34 -0
- package/dist/runtimes/detectRuntime.js +77 -0
- package/dist/runtimes/detectRuntime.js.map +1 -0
- package/dist/types/config.d.ts +8 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/middleware.d.ts +16 -0
- package/dist/types/middleware.js +3 -0
- package/dist/types/middleware.js.map +1 -0
- package/dist/types/plugin.d.ts +43 -0
- package/dist/types/plugin.js +3 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/request.d.ts +15 -0
- package/dist/types/response.d.ts +23 -1
- package/package.json +24 -5
- package/src/adapters/httpAdapter.ts +0 -0
- package/src/adapters/index.ts +0 -0
- package/src/adapters/xhrAdapter.ts +0 -0
- package/src/cache/memoryCache.ts +45 -0
- package/src/config/mergeConfig.ts +0 -0
- package/src/core/Azios.ts +184 -0
- package/src/core/createInstance.ts +23 -0
- package/src/core/dispatchRequest.ts +111 -0
- package/src/core/requestMethods.ts +0 -0
- package/src/core/requestStore.ts +13 -0
- package/src/errors/AziosError.ts +26 -0
- package/src/helpers/buildURL.ts +44 -0
- package/src/helpers/normalizeHeaders.ts +0 -0
- package/src/helpers/parseHeaders.ts +0 -0
- package/src/index.ts +64 -0
- package/src/interceptors/InterceptorManager.ts +30 -0
- package/src/middleware/MiddlewarePipeline.ts +155 -0
- package/src/middleware/compose.ts +33 -0
- package/src/middleware/middlewareManager.ts +9 -0
- package/src/plugins/pluginManager.ts +143 -0
- package/src/rateLimiter/rateLimiter.ts +36 -0
- package/src/runtimes/AdapterFactory.ts +46 -0
- package/src/runtimes/HttpAdapter.ts +26 -0
- package/src/runtimes/UniversalHttpAdapter.ts +136 -0
- package/src/runtimes/detectRuntime.ts +85 -0
- package/src/types/config.ts +30 -0
- package/src/types/index.ts +5 -0
- package/src/types/middleware.ts +21 -0
- package/src/types/plugin.ts +50 -0
- package/src/types/request.ts +39 -0
- package/src/types/response.ts +37 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface AziosRequestConfig {
|
|
2
|
+
|
|
3
|
+
url?: string
|
|
4
|
+
method?: string
|
|
5
|
+
|
|
6
|
+
baseURL?: string
|
|
7
|
+
|
|
8
|
+
headers?: Record<string, any>
|
|
9
|
+
|
|
10
|
+
params?: Record<string, any>
|
|
11
|
+
|
|
12
|
+
data?: any
|
|
13
|
+
|
|
14
|
+
timeout?: number
|
|
15
|
+
|
|
16
|
+
responseType?: string
|
|
17
|
+
|
|
18
|
+
signal?: AbortSignal
|
|
19
|
+
|
|
20
|
+
// Sprint 3
|
|
21
|
+
retry?: number
|
|
22
|
+
retryDelay?: number
|
|
23
|
+
|
|
24
|
+
// Sprint 4
|
|
25
|
+
cache?: boolean
|
|
26
|
+
cacheTTL?: number
|
|
27
|
+
|
|
28
|
+
rateLimit?: number
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AziosRequestConfig } from './config'
|
|
2
|
+
import { AziosResponse } from './response'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Middleware function type for request/response processing
|
|
6
|
+
* Koa-style middleware pattern that receives context and next function
|
|
7
|
+
*/
|
|
8
|
+
export type AziosMiddleware = (
|
|
9
|
+
config: AziosRequestConfig,
|
|
10
|
+
next: (cfg?: AziosRequestConfig) => Promise<AziosResponse>
|
|
11
|
+
) => Promise<AziosResponse>
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Middleware context for tracking state across pipeline
|
|
15
|
+
*/
|
|
16
|
+
export interface MiddlewareContext {
|
|
17
|
+
startTime?: number
|
|
18
|
+
endTime?: number
|
|
19
|
+
config: AziosRequestConfig
|
|
20
|
+
metadata?: Record<string, any>
|
|
21
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AziosRequestConfig } from './config'
|
|
2
|
+
import { AziosResponse } from './response'
|
|
3
|
+
import type { AziosInstance } from './request'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Plugin lifecycle hooks
|
|
7
|
+
* Allows plugins to inject behavior at various stages of the request/response pipeline
|
|
8
|
+
*/
|
|
9
|
+
export interface PluginHooks {
|
|
10
|
+
/**
|
|
11
|
+
* Called when plugin is installed
|
|
12
|
+
*/
|
|
13
|
+
onInstall?(instance: AziosInstance): void | Promise<void>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Called before request is sent
|
|
17
|
+
*/
|
|
18
|
+
beforeRequest?(config: AziosRequestConfig): AziosRequestConfig | Promise<AziosRequestConfig>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Called after response is received
|
|
22
|
+
*/
|
|
23
|
+
afterResponse?(response: AziosResponse): AziosResponse | Promise<AziosResponse>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Called when an error occurs
|
|
27
|
+
*/
|
|
28
|
+
onError?(error: Error): Error | Promise<Error>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Called when plugin is uninstalled
|
|
32
|
+
*/
|
|
33
|
+
onUninstall?(instance: AziosInstance): void | Promise<void>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Plugin definition with metadata
|
|
38
|
+
*/
|
|
39
|
+
export interface AziosPlugin {
|
|
40
|
+
name: string
|
|
41
|
+
version?: string
|
|
42
|
+
hooks: PluginHooks
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Plugin registry to track installed plugins
|
|
47
|
+
*/
|
|
48
|
+
export interface PluginRegistry {
|
|
49
|
+
[key: string]: AziosPlugin
|
|
50
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AziosRequestConfig } from "./config"
|
|
2
|
+
import { AziosResponse } from "./response"
|
|
3
|
+
import InterceptorManager from "../interceptors/InterceptorManager"
|
|
4
|
+
import type { AziosPlugin } from "./plugin"
|
|
5
|
+
import type { AziosMiddleware } from "./middleware"
|
|
6
|
+
|
|
7
|
+
export interface AziosInstance {
|
|
8
|
+
|
|
9
|
+
(config: AziosRequestConfig): Promise<AziosResponse>
|
|
10
|
+
|
|
11
|
+
request(config: AziosRequestConfig): Promise<AziosResponse>
|
|
12
|
+
|
|
13
|
+
get(url: string, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
14
|
+
|
|
15
|
+
post(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
16
|
+
|
|
17
|
+
put(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
18
|
+
|
|
19
|
+
patch(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
20
|
+
|
|
21
|
+
delete(url: string, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
22
|
+
|
|
23
|
+
head(url: string, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
24
|
+
|
|
25
|
+
options(url: string, config?: AziosRequestConfig): Promise<AziosResponse>
|
|
26
|
+
|
|
27
|
+
interceptors: {
|
|
28
|
+
request: InterceptorManager<AziosRequestConfig>
|
|
29
|
+
response: InterceptorManager<AziosResponse>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Plugin system
|
|
33
|
+
installPlugin(plugin: AziosPlugin): Promise<void>
|
|
34
|
+
uninstallPlugin(name: string): Promise<void>
|
|
35
|
+
|
|
36
|
+
// Middleware system
|
|
37
|
+
use(middleware: AziosMiddleware): void
|
|
38
|
+
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AziosRequestConfig } from "./config"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Azios HTTP response object
|
|
5
|
+
* Returned by all request methods
|
|
6
|
+
*/
|
|
7
|
+
export interface AziosResponse<T = any> {
|
|
8
|
+
/**
|
|
9
|
+
* Response data (parsed if JSON)
|
|
10
|
+
*/
|
|
11
|
+
data: T
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* HTTP status code
|
|
15
|
+
*/
|
|
16
|
+
status: number
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* HTTP status text
|
|
20
|
+
*/
|
|
21
|
+
statusText: string
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Response headers
|
|
25
|
+
*/
|
|
26
|
+
headers: Record<string, any>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Original request config
|
|
30
|
+
*/
|
|
31
|
+
config: AziosRequestConfig
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Native request object (if available)
|
|
35
|
+
*/
|
|
36
|
+
request?: any
|
|
37
|
+
}
|