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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Azeem Ali
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,351 +1,176 @@
|
|
|
1
1
|
# Aziosxjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/aziosxjs) [](LICENSE) [](https://www.typescriptlang.org/) [](https://nodejs.org/)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
It is built directly on Node.js low-level `http` and `https` modules to demonstrate how production-grade HTTP clients work internally.
|
|
7
|
-
|
|
8
|
-
The goal of this project is to provide a simple but powerful HTTP client that supports advanced features such as retries, caching, request deduplication, and rate limiting.
|
|
5
|
+
A lightweight, modular HTTP client with a clean API and a composable request pipeline.
|
|
9
6
|
|
|
10
7
|
---
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### Core HTTP
|
|
15
|
-
|
|
16
|
-
* Promise-based HTTP requests
|
|
17
|
-
* Support for GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
|
|
18
|
-
* Automatic JSON parsing
|
|
19
|
-
* Automatic request body serialization
|
|
20
|
-
* Query parameter serialization
|
|
21
|
-
|
|
22
|
-
### Request Pipeline
|
|
23
|
-
|
|
24
|
-
* Request interceptors
|
|
25
|
-
* Response interceptors
|
|
26
|
-
* Structured error system
|
|
27
|
-
* AbortController cancellation support
|
|
28
|
-
|
|
29
|
-
### Performance Features
|
|
30
|
-
|
|
31
|
-
* Automatic retry system
|
|
32
|
-
* Exponential backoff strategy
|
|
33
|
-
* Request deduplication (prevents duplicate concurrent requests)
|
|
34
|
-
* Response caching
|
|
35
|
-
* Built-in rate limiting
|
|
36
|
-
|
|
37
|
-
### Developer Experience
|
|
9
|
+
## Table of Contents
|
|
38
10
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Quick Start](#quick-start)
|
|
13
|
+
- [Core Concepts](#core-concepts)
|
|
14
|
+
- [Plugins & Middleware](#plugins--middleware)
|
|
15
|
+
- [Performance Features](#performance-features)
|
|
16
|
+
- [Error Handling](#error-handling)
|
|
17
|
+
- [Running Tests](#running-tests)
|
|
18
|
+
- [Contributing](#contributing)
|
|
19
|
+
- [License](#license)
|
|
42
20
|
|
|
43
21
|
---
|
|
44
22
|
|
|
45
|
-
|
|
23
|
+
## Installation
|
|
46
24
|
|
|
47
|
-
```bash
|
|
25
|
+
```bash
|
|
48
26
|
npm install aziosxjs
|
|
49
27
|
```
|
|
50
28
|
|
|
51
29
|
---
|
|
52
30
|
|
|
53
|
-
|
|
31
|
+
## Quick Start
|
|
54
32
|
|
|
55
|
-
```
|
|
33
|
+
```js
|
|
56
34
|
import azios from "aziosxjs";
|
|
57
35
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"https://jsonplaceholder.typicode.com/users"
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
console.log(response.data);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getUsers();
|
|
36
|
+
const response = await azios.get("https://jsonplaceholder.typicode.com/users/1");
|
|
37
|
+
console.log(response.data);
|
|
67
38
|
```
|
|
68
39
|
|
|
69
40
|
---
|
|
70
41
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## GET Request
|
|
42
|
+
## Core Concepts
|
|
74
43
|
|
|
75
|
-
|
|
76
|
-
const res = await azios.get("https://api.example.com/users");
|
|
44
|
+
### HTTP Methods
|
|
77
45
|
|
|
78
|
-
|
|
46
|
+
```js
|
|
47
|
+
await azios.get("/users");
|
|
48
|
+
await azios.post("/users", { name: "Jane" });
|
|
49
|
+
await azios.put("/users/1", { name: "Jane" });
|
|
50
|
+
await azios.delete("/users/1");
|
|
79
51
|
```
|
|
80
52
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## POST Request
|
|
53
|
+
### Configuration
|
|
84
54
|
|
|
85
|
-
```
|
|
86
|
-
const
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
console.log(res.data);
|
|
55
|
+
```js
|
|
56
|
+
const response = await azios.request({
|
|
57
|
+
url: "/users",
|
|
58
|
+
method: "GET",
|
|
59
|
+
baseURL: "https://api.example.com",
|
|
60
|
+
params: { page: 1, limit: 10 },
|
|
61
|
+
headers: { Authorization: "Bearer TOKEN" },
|
|
62
|
+
timeout: 5000,
|
|
63
|
+
});
|
|
95
64
|
```
|
|
96
65
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
# Query Parameters
|
|
100
|
-
|
|
101
|
-
Aziosxjs automatically serializes query parameters.
|
|
102
|
-
|
|
103
|
-
```javascript id="6e6w1q"
|
|
104
|
-
const res = await azios.get(
|
|
105
|
-
"https://jsonplaceholder.typicode.com/posts",
|
|
106
|
-
{
|
|
107
|
-
params: { _limit: 2 }
|
|
108
|
-
}
|
|
109
|
-
);
|
|
66
|
+
### Instances
|
|
110
67
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Generated URL:
|
|
68
|
+
```js
|
|
69
|
+
import { createInstance } from "aziosxjs";
|
|
115
70
|
|
|
116
|
-
|
|
117
|
-
/
|
|
71
|
+
const api = createInstance({ baseURL: "https://api.example.com" });
|
|
72
|
+
await api.get("/users");
|
|
118
73
|
```
|
|
119
74
|
|
|
120
75
|
---
|
|
121
76
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
Interceptors allow you to modify requests or responses globally.
|
|
125
|
-
|
|
126
|
-
## Request Interceptor
|
|
77
|
+
## Plugins & Middleware
|
|
127
78
|
|
|
128
|
-
|
|
129
|
-
azios.interceptors.request.use(config => {
|
|
130
|
-
console.log("Request intercepted");
|
|
79
|
+
### Plugin System
|
|
131
80
|
|
|
132
|
-
|
|
133
|
-
config.headers["x-client"] = "aziosxjs";
|
|
81
|
+
Plugins provide a clean way to extend Aziosxjs behavior.
|
|
134
82
|
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
---
|
|
83
|
+
```js
|
|
84
|
+
import type { AziosPlugin } from "aziosxjs";
|
|
140
85
|
|
|
141
|
-
|
|
86
|
+
const authPlugin: AziosPlugin = {
|
|
87
|
+
name: "auth",
|
|
88
|
+
version: "1.0.0",
|
|
89
|
+
hooks: {
|
|
90
|
+
beforeRequest: (config) => ({
|
|
91
|
+
...config,
|
|
92
|
+
headers: { ...config.headers, Authorization: "Bearer TOKEN" },
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
142
96
|
|
|
143
|
-
|
|
144
|
-
azios.interceptors.response.use(response => {
|
|
145
|
-
console.log("Response intercepted");
|
|
146
|
-
return response;
|
|
147
|
-
});
|
|
97
|
+
await azios.installPlugin(authPlugin);
|
|
148
98
|
```
|
|
149
99
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
# Request Cancellation
|
|
100
|
+
### Middleware
|
|
153
101
|
|
|
154
|
-
|
|
102
|
+
Middleware runs in sequence and can modify the request/response pipeline.
|
|
155
103
|
|
|
156
|
-
```
|
|
157
|
-
|
|
104
|
+
```js
|
|
105
|
+
import type { AziosMiddleware } from "aziosxjs";
|
|
158
106
|
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
);
|
|
107
|
+
const logger: AziosMiddleware = async (config, next) => {
|
|
108
|
+
console.log("→", config.method, config.url);
|
|
109
|
+
const res = await next();
|
|
110
|
+
console.log("←", res.status);
|
|
111
|
+
return res;
|
|
112
|
+
};
|
|
163
113
|
|
|
164
|
-
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
If aborted, Aziosxjs throws an error with code:
|
|
168
|
-
|
|
169
|
-
```id="m5ktg3"
|
|
170
|
-
ABORTED
|
|
114
|
+
azios.use(logger);
|
|
171
115
|
```
|
|
172
116
|
|
|
173
117
|
---
|
|
174
118
|
|
|
175
|
-
|
|
119
|
+
## Performance Features
|
|
176
120
|
|
|
177
|
-
|
|
121
|
+
### Retry + Backoff
|
|
178
122
|
|
|
179
|
-
```
|
|
180
|
-
await azios.get("
|
|
181
|
-
retry: 3
|
|
182
|
-
});
|
|
123
|
+
```js
|
|
124
|
+
await azios.get("/unstable", { retry: 3, retryDelay: 500 });
|
|
183
125
|
```
|
|
184
126
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
---
|
|
127
|
+
### Deduplication
|
|
188
128
|
|
|
189
|
-
|
|
129
|
+
Identical concurrent requests share the same network call.
|
|
190
130
|
|
|
191
|
-
|
|
131
|
+
### Caching
|
|
192
132
|
|
|
193
|
-
```
|
|
194
|
-
await azios.get(
|
|
195
|
-
"https://api.example.com/users",
|
|
196
|
-
{ cache: true }
|
|
197
|
-
);
|
|
133
|
+
```js
|
|
134
|
+
await azios.get("/users", { cache: true, cacheTTL: 5000 });
|
|
198
135
|
```
|
|
199
136
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
# Rate Limiting
|
|
137
|
+
### Rate Limiting
|
|
205
138
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
```javascript id="m2l4x9"
|
|
209
|
-
await azios.get(
|
|
210
|
-
"https://api.example.com/users",
|
|
211
|
-
{ rateLimit: 3 }
|
|
212
|
-
);
|
|
139
|
+
```js
|
|
140
|
+
await azios.get("/users", { rateLimit: 5 });
|
|
213
141
|
```
|
|
214
142
|
|
|
215
|
-
Only 3 requests will execute simultaneously.
|
|
216
|
-
|
|
217
143
|
---
|
|
218
144
|
|
|
219
|
-
|
|
145
|
+
## Error Handling
|
|
220
146
|
|
|
221
|
-
Aziosxjs
|
|
147
|
+
Aziosxjs throws `AziosError` instances with structured metadata.
|
|
222
148
|
|
|
223
|
-
```
|
|
149
|
+
```js
|
|
224
150
|
try {
|
|
225
|
-
await azios.get("
|
|
226
|
-
} catch (
|
|
227
|
-
console.log(
|
|
228
|
-
console.log(error.code); // NETWORK_ERROR
|
|
151
|
+
await azios.get("/404");
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.log(err.code, err.message);
|
|
229
154
|
}
|
|
230
155
|
```
|
|
231
156
|
|
|
232
|
-
This makes debugging significantly easier.
|
|
233
|
-
|
|
234
157
|
---
|
|
235
158
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
Aziosxjs follows a modular pipeline design.
|
|
239
|
-
|
|
240
|
-
```id="m2b3ux"
|
|
241
|
-
User Code
|
|
242
|
-
↓
|
|
243
|
-
Azios Instance
|
|
244
|
-
↓
|
|
245
|
-
Request Interceptors
|
|
246
|
-
↓
|
|
247
|
-
Retry Engine
|
|
248
|
-
↓
|
|
249
|
-
Rate Limiter
|
|
250
|
-
↓
|
|
251
|
-
dispatchRequest (HTTP engine)
|
|
252
|
-
↓
|
|
253
|
-
Node.js http / https
|
|
254
|
-
↓
|
|
255
|
-
Response Interceptors
|
|
256
|
-
↓
|
|
257
|
-
Return Response
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
---
|
|
159
|
+
## Running Tests
|
|
261
160
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
```id="v2z3go"
|
|
265
|
-
src
|
|
266
|
-
├── core
|
|
267
|
-
│ ├── Azios.ts
|
|
268
|
-
│ ├── createInstance.ts
|
|
269
|
-
│ ├── dispatchRequest.ts
|
|
270
|
-
│ └── requestStore.ts
|
|
271
|
-
│
|
|
272
|
-
├── cache
|
|
273
|
-
│ └── memoryCache.ts
|
|
274
|
-
│
|
|
275
|
-
├── rateLimiter
|
|
276
|
-
│ └── rateLimiter.ts
|
|
277
|
-
│
|
|
278
|
-
├── interceptors
|
|
279
|
-
│ └── InterceptorManager.ts
|
|
280
|
-
│
|
|
281
|
-
├── errors
|
|
282
|
-
│ └── AziosError.ts
|
|
283
|
-
│
|
|
284
|
-
├── helpers
|
|
285
|
-
│ └── buildURL.ts
|
|
286
|
-
│
|
|
287
|
-
├── types
|
|
288
|
-
│ ├── config.ts
|
|
289
|
-
│ ├── request.ts
|
|
290
|
-
│ └── response.ts
|
|
291
|
-
│
|
|
292
|
-
└── index.ts
|
|
161
|
+
```bash
|
|
162
|
+
npm test
|
|
293
163
|
```
|
|
294
164
|
|
|
295
165
|
---
|
|
296
166
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
### v0.1
|
|
300
|
-
|
|
301
|
-
* Core HTTP client
|
|
302
|
-
* Instances
|
|
303
|
-
* JSON handling
|
|
304
|
-
* Request configuration
|
|
167
|
+
## Contributing
|
|
305
168
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
* Interceptor pipeline
|
|
309
|
-
* Structured error system
|
|
310
|
-
* Request cancellation
|
|
311
|
-
* Query parameter serialization
|
|
312
|
-
|
|
313
|
-
### v0.3
|
|
314
|
-
|
|
315
|
-
* Retry mechanism
|
|
316
|
-
* Exponential backoff
|
|
317
|
-
* Request deduplication
|
|
318
|
-
|
|
319
|
-
### v0.4
|
|
320
|
-
|
|
321
|
-
* Response caching
|
|
322
|
-
* Rate limiting
|
|
323
|
-
|
|
324
|
-
### Planned
|
|
325
|
-
|
|
326
|
-
* Plugin system
|
|
327
|
-
* Middleware pipeline
|
|
328
|
-
* Advanced TypeScript inference
|
|
329
|
-
* Universal runtime support (Node, Browser, Edge)
|
|
169
|
+
Contributions are welcome. Please open an issue or pull request.
|
|
330
170
|
|
|
331
171
|
---
|
|
332
172
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
Contributions are welcome.
|
|
336
|
-
|
|
337
|
-
1. Fork the repository
|
|
338
|
-
2. Create a feature branch
|
|
339
|
-
3. Submit a pull request
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
# Author
|
|
344
|
-
|
|
345
|
-
Azeem Ali
|
|
346
|
-
|
|
347
|
-
---
|
|
173
|
+
## License
|
|
348
174
|
|
|
349
|
-
|
|
175
|
+
MIT © 2026 Azeem Ali
|
|
350
176
|
|
|
351
|
-
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCache = getCache;
|
|
4
|
+
exports.setCache = setCache;
|
|
5
|
+
exports.clearCache = clearCache;
|
|
6
|
+
exports.clearAllCache = clearAllCache;
|
|
7
|
+
const cache = new Map();
|
|
8
|
+
function getCache(key) {
|
|
9
|
+
const entry = cache.get(key);
|
|
10
|
+
if (!entry)
|
|
11
|
+
return null;
|
|
12
|
+
// remove expired cache
|
|
13
|
+
if (Date.now() > entry.expiry) {
|
|
14
|
+
cache.delete(key);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return entry.data;
|
|
18
|
+
}
|
|
19
|
+
function setCache(key, value, ttl = 5000) {
|
|
20
|
+
const expiry = Date.now() + ttl;
|
|
21
|
+
cache.set(key, {
|
|
22
|
+
data: value,
|
|
23
|
+
expiry
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function clearCache(key) {
|
|
27
|
+
cache.delete(key);
|
|
28
|
+
}
|
|
29
|
+
function clearAllCache() {
|
|
30
|
+
cache.clear();
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=memoryCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryCache.js","sourceRoot":"","sources":["../../src/cache/memoryCache.ts"],"names":[],"mappings":";;AAOA,4BAcC;AAED,4BAaC;AAED,gCAEC;AAED,sCAEC;AAvCD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE3C,SAAgB,QAAQ,CAAC,GAAW;IAElC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAE5B,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IAEvB,uBAAuB;IACvB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAA;AAEnB,CAAC;AAED,SAAgB,QAAQ,CACtB,GAAW,EACX,KAAU,EACV,MAAc,IAAI;IAGlB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAA;IAE/B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;QACb,IAAI,EAAE,KAAK;QACX,MAAM;KACP,CAAC,CAAA;AAEJ,CAAC;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC;AAED,SAAgB,aAAa;IAC3B,KAAK,CAAC,KAAK,EAAE,CAAA;AACf,CAAC"}
|
package/dist/core/Azios.d.ts
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
1
|
import { AziosRequestConfig } from "../types/config";
|
|
2
|
+
import type { AziosPlugin } from "../types/plugin";
|
|
2
3
|
import InterceptorManager from "../interceptors/InterceptorManager";
|
|
4
|
+
import PluginManager from "../plugins/pluginManager";
|
|
5
|
+
import MiddlewareManager from "../middleware/middlewareManager";
|
|
6
|
+
/**
|
|
7
|
+
* Core Azios HTTP client class
|
|
8
|
+
* Production-grade implementation with plugin system, middleware, and interceptors
|
|
9
|
+
*/
|
|
3
10
|
export default class Azios {
|
|
4
11
|
defaults: AziosRequestConfig;
|
|
5
12
|
interceptors: {
|
|
6
13
|
request: InterceptorManager<AziosRequestConfig>;
|
|
7
14
|
response: InterceptorManager<any>;
|
|
8
15
|
};
|
|
16
|
+
middlewares: MiddlewareManager;
|
|
17
|
+
plugins: PluginManager;
|
|
9
18
|
constructor(config: AziosRequestConfig);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Register middleware using Koa-style middleware pattern
|
|
21
|
+
*/
|
|
22
|
+
use(fn: any): void;
|
|
23
|
+
/**
|
|
24
|
+
* Install a plugin into this instance
|
|
25
|
+
* @throws Error if plugin is already installed or installation fails
|
|
26
|
+
*/
|
|
27
|
+
installPlugin(plugin: AziosPlugin): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Uninstall a plugin by name
|
|
30
|
+
*/
|
|
31
|
+
uninstallPlugin(pluginName: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Core request method - central request pipeline
|
|
34
|
+
*/
|
|
35
|
+
request(config: AziosRequestConfig): Promise<any>;
|
|
36
|
+
get(url: string, config?: AziosRequestConfig): Promise<any>;
|
|
37
|
+
post(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
|
|
38
|
+
put(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
|
|
39
|
+
patch(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
|
|
40
|
+
delete(url: string, config?: AziosRequestConfig): Promise<any>;
|
|
41
|
+
head(url: string, config?: AziosRequestConfig): Promise<any>;
|
|
42
|
+
options(url: string, config?: AziosRequestConfig): Promise<any>;
|
|
13
43
|
}
|
package/dist/core/Azios.js
CHANGED
|
@@ -5,6 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const dispatchRequest_1 = __importDefault(require("./dispatchRequest"));
|
|
7
7
|
const InterceptorManager_1 = __importDefault(require("../interceptors/InterceptorManager"));
|
|
8
|
+
const pluginManager_1 = __importDefault(require("../plugins/pluginManager"));
|
|
9
|
+
const middlewareManager_1 = __importDefault(require("../middleware/middlewareManager"));
|
|
10
|
+
const compose_1 = require("../middleware/compose");
|
|
11
|
+
/**
|
|
12
|
+
* Core Azios HTTP client class
|
|
13
|
+
* Production-grade implementation with plugin system, middleware, and interceptors
|
|
14
|
+
*/
|
|
8
15
|
class Azios {
|
|
9
16
|
constructor(config) {
|
|
10
17
|
this.defaults = config;
|
|
@@ -12,11 +19,84 @@ class Azios {
|
|
|
12
19
|
request: new InterceptorManager_1.default(),
|
|
13
20
|
response: new InterceptorManager_1.default()
|
|
14
21
|
};
|
|
22
|
+
this.middlewares = new middlewareManager_1.default();
|
|
23
|
+
this.plugins = new pluginManager_1.default();
|
|
15
24
|
}
|
|
16
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Register middleware using Koa-style middleware pattern
|
|
27
|
+
*/
|
|
28
|
+
use(fn) {
|
|
29
|
+
this.middlewares.use(fn);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Install a plugin into this instance
|
|
33
|
+
* @throws Error if plugin is already installed or installation fails
|
|
34
|
+
*/
|
|
35
|
+
async installPlugin(plugin) {
|
|
36
|
+
await this.plugins.install(plugin, this);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Uninstall a plugin by name
|
|
40
|
+
*/
|
|
41
|
+
async uninstallPlugin(pluginName) {
|
|
42
|
+
await this.plugins.uninstall(pluginName, this);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Core request method - central request pipeline
|
|
46
|
+
*/
|
|
47
|
+
async request(config) {
|
|
17
48
|
config = { ...this.defaults, ...config };
|
|
18
|
-
|
|
49
|
+
// -------------------------
|
|
50
|
+
// PLUGIN: PRE-REQUEST HOOKS
|
|
51
|
+
// -------------------------
|
|
52
|
+
config = await this.plugins.executeBeforeRequestHooks(config);
|
|
53
|
+
// -------------------------
|
|
54
|
+
// MIDDLEWARE PIPELINE
|
|
55
|
+
// -------------------------
|
|
56
|
+
const context = { config };
|
|
57
|
+
const fn = (0, compose_1.compose)(this.middlewares.middlewares);
|
|
58
|
+
await fn(context);
|
|
59
|
+
config = context.config;
|
|
60
|
+
// -------------------------
|
|
61
|
+
// INTERCEPTOR PIPELINE
|
|
62
|
+
// -------------------------
|
|
63
|
+
const chain = [];
|
|
64
|
+
// Request interceptors (reverse order)
|
|
65
|
+
this.interceptors.request.forEach(interceptor => {
|
|
66
|
+
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
67
|
+
});
|
|
68
|
+
// Main dispatch
|
|
69
|
+
chain.push(dispatchRequest_1.default, undefined);
|
|
70
|
+
// Response interceptors (normal order)
|
|
71
|
+
this.interceptors.response.forEach(interceptor => {
|
|
72
|
+
chain.push(interceptor.fulfilled, interceptor.rejected);
|
|
73
|
+
});
|
|
74
|
+
let promise = Promise.resolve(config);
|
|
75
|
+
while (chain.length) {
|
|
76
|
+
const fulfilled = chain.shift();
|
|
77
|
+
const rejected = chain.shift();
|
|
78
|
+
promise = promise.then(fulfilled, rejected);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const response = await promise;
|
|
82
|
+
// -------------------------
|
|
83
|
+
// PLUGIN: POST-RESPONSE HOOKS
|
|
84
|
+
// -------------------------
|
|
85
|
+
return await this.plugins.executeAfterResponseHooks(response);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// -------------------------
|
|
89
|
+
// PLUGIN: ERROR HOOKS
|
|
90
|
+
// -------------------------
|
|
91
|
+
if (error instanceof Error) {
|
|
92
|
+
throw await this.plugins.executeOnErrorHooks(error);
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
19
96
|
}
|
|
97
|
+
// =========================================
|
|
98
|
+
// HTTP METHODS
|
|
99
|
+
// =========================================
|
|
20
100
|
get(url, config) {
|
|
21
101
|
return this.request({
|
|
22
102
|
...config,
|
|
@@ -32,6 +112,43 @@ class Azios {
|
|
|
32
112
|
data
|
|
33
113
|
});
|
|
34
114
|
}
|
|
115
|
+
put(url, data, config) {
|
|
116
|
+
return this.request({
|
|
117
|
+
...config,
|
|
118
|
+
method: "PUT",
|
|
119
|
+
url,
|
|
120
|
+
data
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
patch(url, data, config) {
|
|
124
|
+
return this.request({
|
|
125
|
+
...config,
|
|
126
|
+
method: "PATCH",
|
|
127
|
+
url,
|
|
128
|
+
data
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
delete(url, config) {
|
|
132
|
+
return this.request({
|
|
133
|
+
...config,
|
|
134
|
+
method: "DELETE",
|
|
135
|
+
url
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
head(url, config) {
|
|
139
|
+
return this.request({
|
|
140
|
+
...config,
|
|
141
|
+
method: "HEAD",
|
|
142
|
+
url
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
options(url, config) {
|
|
146
|
+
return this.request({
|
|
147
|
+
...config,
|
|
148
|
+
method: "OPTIONS",
|
|
149
|
+
url
|
|
150
|
+
});
|
|
151
|
+
}
|
|
35
152
|
}
|
|
36
153
|
exports.default = Azios;
|
|
37
154
|
//# sourceMappingURL=Azios.js.map
|