@chzky/reqwest 0.0.1 → 0.1.1

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.
Files changed (179) hide show
  1. package/README.md +314 -0
  2. package/esm/_dnt.polyfills.d.ts +11 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -10
  4. package/esm/_dnt.polyfills.js +24 -66
  5. package/esm/_dnt.shims.d.ts +1 -13
  6. package/esm/_dnt.shims.d.ts.map +1 -1
  7. package/esm/_dnt.shims.js +57 -1
  8. package/esm/lib/core/class.d.ts +122 -0
  9. package/esm/lib/core/class.d.ts.map +1 -0
  10. package/esm/lib/core/class.js +173 -0
  11. package/esm/lib/core/core.d.ts +11 -0
  12. package/esm/lib/core/core.d.ts.map +1 -0
  13. package/esm/lib/core/core.js +157 -0
  14. package/esm/lib/{reqwest → core}/factor.d.ts +57 -9
  15. package/esm/lib/core/factor.d.ts.map +1 -0
  16. package/esm/lib/core/factor.js +48 -0
  17. package/esm/lib/core/interface.d.ts +172 -0
  18. package/esm/lib/core/interface.d.ts.map +1 -0
  19. package/esm/lib/core/interface.js +1 -0
  20. package/esm/lib/core/mod.d.ts +5 -0
  21. package/esm/lib/core/mod.d.ts.map +1 -0
  22. package/esm/lib/core/mod.js +3 -0
  23. package/esm/lib/helper/mod.d.ts +2 -0
  24. package/esm/lib/helper/mod.d.ts.map +1 -1
  25. package/esm/lib/helper/mod.js +2 -0
  26. package/esm/lib/helper/other/mod.d.ts +2 -0
  27. package/esm/lib/helper/other/mod.d.ts.map +1 -0
  28. package/esm/lib/helper/other/mod.js +1 -0
  29. package/esm/lib/helper/other/sseParse.d.ts +34 -0
  30. package/esm/lib/helper/other/sseParse.d.ts.map +1 -0
  31. package/esm/lib/helper/other/sseParse.js +42 -0
  32. package/esm/lib/helper/request/RESTful.d.ts +43 -11
  33. package/esm/lib/helper/request/RESTful.d.ts.map +1 -1
  34. package/esm/lib/helper/request/RESTful.js +129 -1
  35. package/esm/lib/helper/request/baseConf.d.ts +11 -4
  36. package/esm/lib/helper/request/baseConf.d.ts.map +1 -1
  37. package/esm/lib/helper/request/baseConf.js +37 -1
  38. package/esm/lib/helper/request/factors.d.ts +31 -0
  39. package/esm/lib/helper/request/factors.d.ts.map +1 -0
  40. package/esm/lib/helper/request/factors.js +40 -0
  41. package/esm/lib/helper/request/input.d.ts +5 -4
  42. package/esm/lib/helper/request/input.d.ts.map +1 -1
  43. package/esm/lib/helper/request/input.js +24 -1
  44. package/esm/lib/helper/request/mod.d.ts +4 -1
  45. package/esm/lib/helper/request/mod.d.ts.map +1 -1
  46. package/esm/lib/helper/request/mod.js +6 -3
  47. package/esm/lib/helper/request/process.d.ts +16 -0
  48. package/esm/lib/helper/request/process.d.ts.map +1 -0
  49. package/esm/lib/helper/request/process.js +37 -0
  50. package/esm/lib/helper/request/wait.d.ts +9 -0
  51. package/esm/lib/helper/request/wait.d.ts.map +1 -0
  52. package/esm/lib/helper/request/wait.js +13 -0
  53. package/esm/lib/helper/response/blobToUrl.d.ts +11 -0
  54. package/esm/lib/helper/response/blobToUrl.d.ts.map +1 -0
  55. package/esm/lib/helper/response/blobToUrl.js +22 -0
  56. package/esm/lib/helper/response/mod.d.ts +3 -1
  57. package/esm/lib/helper/response/mod.d.ts.map +1 -1
  58. package/esm/lib/helper/response/mod.js +4 -2
  59. package/esm/lib/helper/response/openLink.d.ts +8 -0
  60. package/esm/lib/helper/response/openLink.d.ts.map +1 -0
  61. package/esm/lib/helper/response/openLink.js +21 -0
  62. package/esm/lib/helper/response/output.d.ts +14 -3
  63. package/esm/lib/helper/response/output.d.ts.map +1 -1
  64. package/esm/lib/helper/response/output.js +24 -1
  65. package/esm/lib/helper/response/pick.d.ts +19 -2
  66. package/esm/lib/helper/response/pick.d.ts.map +1 -1
  67. package/esm/lib/helper/response/pick.js +26 -1
  68. package/esm/lib/helper/use/mod.js +2 -2
  69. package/esm/lib/helper/use/useCancel.d.ts +32 -2
  70. package/esm/lib/helper/use/useCancel.d.ts.map +1 -1
  71. package/esm/lib/helper/use/useCancel.js +42 -1
  72. package/esm/lib/helper/use/useLoading.d.ts +27 -7
  73. package/esm/lib/helper/use/useLoading.d.ts.map +1 -1
  74. package/esm/lib/helper/use/useLoading.js +58 -1
  75. package/esm/lib/mod.d.ts +1 -1
  76. package/esm/lib/mod.d.ts.map +1 -1
  77. package/esm/lib/mod.js +1 -1
  78. package/package.json +4 -11
  79. package/script/_dnt.polyfills.d.ts +11 -0
  80. package/script/_dnt.polyfills.d.ts.map +1 -1
  81. package/script/_dnt.polyfills.js +15 -0
  82. package/script/_dnt.shims.d.ts +1 -13
  83. package/script/_dnt.shims.d.ts.map +1 -1
  84. package/script/_dnt.shims.js +2 -21
  85. package/script/lib/core/class.d.ts +122 -0
  86. package/script/lib/core/class.d.ts.map +1 -0
  87. package/script/lib/core/class.js +180 -0
  88. package/script/lib/core/core.d.ts +11 -0
  89. package/script/lib/core/core.d.ts.map +1 -0
  90. package/script/lib/core/core.js +165 -0
  91. package/script/lib/{reqwest → core}/factor.d.ts +57 -9
  92. package/script/lib/core/factor.d.ts.map +1 -0
  93. package/script/lib/{reqwest → core}/factor.js +24 -8
  94. package/script/lib/core/interface.d.ts +172 -0
  95. package/script/lib/core/interface.d.ts.map +1 -0
  96. package/script/lib/core/mod.d.ts +5 -0
  97. package/script/lib/core/mod.d.ts.map +1 -0
  98. package/script/lib/{reqwest → core}/mod.js +1 -0
  99. package/script/lib/helper/mod.d.ts +2 -0
  100. package/script/lib/helper/mod.d.ts.map +1 -1
  101. package/script/lib/helper/mod.js +2 -0
  102. package/script/lib/helper/other/mod.d.ts +2 -0
  103. package/script/lib/helper/other/mod.d.ts.map +1 -0
  104. package/script/lib/helper/other/mod.js +17 -0
  105. package/script/lib/helper/other/sseParse.d.ts +34 -0
  106. package/script/lib/helper/other/sseParse.d.ts.map +1 -0
  107. package/script/lib/helper/other/sseParse.js +45 -0
  108. package/script/lib/helper/request/RESTful.d.ts +43 -11
  109. package/script/lib/helper/request/RESTful.d.ts.map +1 -1
  110. package/script/lib/helper/request/RESTful.js +75 -21
  111. package/script/lib/helper/request/baseConf.d.ts +11 -4
  112. package/script/lib/helper/request/baseConf.d.ts.map +1 -1
  113. package/script/lib/helper/request/baseConf.js +25 -10
  114. package/script/lib/helper/request/factors.d.ts +31 -0
  115. package/script/lib/helper/request/factors.d.ts.map +1 -0
  116. package/script/lib/helper/request/factors.js +43 -0
  117. package/script/lib/helper/request/input.d.ts +5 -4
  118. package/script/lib/helper/request/input.d.ts.map +1 -1
  119. package/script/lib/helper/request/input.js +11 -11
  120. package/script/lib/helper/request/mod.d.ts +4 -1
  121. package/script/lib/helper/request/mod.d.ts.map +1 -1
  122. package/script/lib/helper/request/mod.js +6 -3
  123. package/script/lib/helper/request/process.d.ts +16 -0
  124. package/script/lib/helper/request/process.d.ts.map +1 -0
  125. package/script/lib/helper/request/process.js +41 -0
  126. package/script/lib/helper/request/wait.d.ts +9 -0
  127. package/script/lib/helper/request/wait.d.ts.map +1 -0
  128. package/script/lib/helper/request/wait.js +16 -0
  129. package/script/lib/helper/response/blobToUrl.d.ts +11 -0
  130. package/script/lib/helper/response/blobToUrl.d.ts.map +1 -0
  131. package/script/lib/helper/response/blobToUrl.js +25 -0
  132. package/script/lib/helper/response/mod.d.ts +3 -1
  133. package/script/lib/helper/response/mod.d.ts.map +1 -1
  134. package/script/lib/helper/response/mod.js +4 -2
  135. package/script/lib/helper/response/openLink.d.ts +8 -0
  136. package/script/lib/helper/response/openLink.d.ts.map +1 -0
  137. package/script/lib/helper/response/openLink.js +47 -0
  138. package/script/lib/helper/response/output.d.ts +14 -3
  139. package/script/lib/helper/response/output.d.ts.map +1 -1
  140. package/script/lib/helper/response/output.js +20 -7
  141. package/script/lib/helper/response/pick.d.ts +19 -2
  142. package/script/lib/helper/response/pick.d.ts.map +1 -1
  143. package/script/lib/helper/response/pick.js +22 -5
  144. package/script/lib/helper/use/mod.js +2 -2
  145. package/script/lib/helper/use/useCancel.d.ts +32 -2
  146. package/script/lib/helper/use/useCancel.d.ts.map +1 -1
  147. package/script/lib/helper/use/useCancel.js +37 -7
  148. package/script/lib/helper/use/useLoading.d.ts +27 -7
  149. package/script/lib/helper/use/useLoading.d.ts.map +1 -1
  150. package/script/lib/helper/use/useLoading.js +56 -46
  151. package/script/lib/mod.d.ts +1 -1
  152. package/script/lib/mod.d.ts.map +1 -1
  153. package/script/lib/mod.js +1 -1
  154. package/esm/lib/reqwest/class.d.ts +0 -84
  155. package/esm/lib/reqwest/class.d.ts.map +0 -1
  156. package/esm/lib/reqwest/class.js +0 -1
  157. package/esm/lib/reqwest/core.d.ts +0 -6
  158. package/esm/lib/reqwest/core.d.ts.map +0 -1
  159. package/esm/lib/reqwest/core.js +0 -250
  160. package/esm/lib/reqwest/factor.d.ts.map +0 -1
  161. package/esm/lib/reqwest/factor.js +0 -1
  162. package/esm/lib/reqwest/interface.d.ts +0 -48
  163. package/esm/lib/reqwest/interface.d.ts.map +0 -1
  164. package/esm/lib/reqwest/interface.js +0 -1
  165. package/esm/lib/reqwest/mod.d.ts +0 -4
  166. package/esm/lib/reqwest/mod.d.ts.map +0 -1
  167. package/esm/lib/reqwest/mod.js +0 -2
  168. package/script/lib/reqwest/class.d.ts +0 -84
  169. package/script/lib/reqwest/class.d.ts.map +0 -1
  170. package/script/lib/reqwest/class.js +0 -72
  171. package/script/lib/reqwest/core.d.ts +0 -6
  172. package/script/lib/reqwest/core.d.ts.map +0 -1
  173. package/script/lib/reqwest/core.js +0 -72
  174. package/script/lib/reqwest/factor.d.ts.map +0 -1
  175. package/script/lib/reqwest/interface.d.ts +0 -23
  176. package/script/lib/reqwest/interface.d.ts.map +0 -1
  177. package/script/lib/reqwest/mod.d.ts +0 -4
  178. package/script/lib/reqwest/mod.d.ts.map +0 -1
  179. /package/script/lib/{reqwest → core}/interface.js +0 -0
package/README.md ADDED
@@ -0,0 +1,314 @@
1
+ # `@chzky/reqwest`: HTTP Request Library for chzky
2
+ [![JSR](https://jsr.io/badges/@chzky/reqwest)](https://jsr.io/@chzky/reqwest)
3
+
4
+ @chzky/reqwest 是一个基于 Axios 的 HTTP 请求库。它采用函数式编程风格,通过不可变(immutable)的构建器模式和基于 Result 类型(来自 @chzky/core)的错误处理机制来构建和发送请求。
5
+
6
+ ## Features
7
+
8
+ - **基于 Axios**: 底层使用 `axios` 发送请求,继承其稳定性。
9
+ - **`Result` 驱动**: 所有请求的最终结果都被包装在 `Result<T, E>` 对象中,强制进行显式的错误处理,避免了 `try...catch` 块的泛滥。
10
+ - **不可变 API**: 所有配置方法(如 `.request()`, `.response()`, `.conf()`)都会返回一个新的 `Reqwest` 实例,而不是修改当前实例。这使得创建可复用的基础客户端变得容易。
11
+ - **链式调用**: 通过链式调用组合拦截器来构建请求。
12
+ - **内置工具函数**: 提供了一系列用于 RESTful 请求、数据验证、取消请求和加载状态管理的辅助函数。
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pnpm install @chzky/reqwest
18
+ ```
19
+ or deno
20
+ ```bash
21
+ deno add jsr:@chzky/reqwest
22
+ ```
23
+
24
+ ## 核心概念
25
+
26
+ ### 1. Result 结果类型
27
+
28
+ 本库不通过抛出异常来处理网络或逻辑错误。`dispatch()` 方法返回一个 `Promise<Result<SuccessType, ErrorType>>`。你需要通过 `@chzky/core` 提供的 `Result` 类型来处理请求结果。
29
+
30
+ ### 2. 不可变构建器
31
+
32
+ `Reqwest` 实例是不可变的。每次调用配置方法时,都会基于当前配置克隆出一个新的实例。
33
+
34
+ ```typescript
35
+ // baseClient 不会改变
36
+ const baseClient = Reqwest.new().conf({ baseURL: '/api' });
37
+
38
+ // userClient 是一个带有特定拦截器的新实例
39
+ const userClient = baseClient.request(get('/user'));
40
+
41
+ // postClient 也是一个独立的新实例
42
+ const postClient = baseClient.request(get('/post'));
43
+ ```
44
+
45
+ ### 3. 拦截器 (Interceptors)
46
+
47
+ 库的核心功能由拦截器驱动。拦截器是普通的函数,分为两类:
48
+
49
+ - **请求拦截器 (`RequestInterceptor`)**: 接收 `AxiosRequestConfig` 对象,用于在请求发送前修改配置。它必须返回 `Ok<void>` 或 `Err<E>`。
50
+ - **响应拦截器 (`ResponseInterceptor`)**: 接收上一个拦截器或原始请求的响应数据,用于转换数据。它必须返回 `Ok<NewData>` 或 `Err<E>`。
51
+
52
+ ## 基本用法
53
+
54
+ 下面是一个获取用户数据并提取 `data` 字段的基础示例。
55
+
56
+ ```typescript
57
+ import { Reqwest, get, pick } from '@chzky/reqwest';
58
+ import { is_ok } from '@chzky/core';
59
+
60
+ interface User {
61
+ id: number;
62
+ name: string;
63
+ }
64
+
65
+ async function fetchUser(id: number) {
66
+ // 1. 创建一个新的 Reqwest 实例
67
+ const result = await Reqwest.new()
68
+ .conf({ baseURL: 'https://jsonplaceholder.typicode.com/todos/' })
69
+ // 2. 添加一个请求拦截器来设置请求方法和 URL
70
+ .request(get(`/api/users/${id}`))
71
+ // 3. 添加一个响应拦截器来提取响应体中的 `data` 字段
72
+ .response(pick('data'))
73
+ // 4. 发送请求并等待 Result
74
+ .dispatch<User>();
75
+
76
+ if (is_ok(result)) {
77
+ const user = result.unwrap();
78
+ console.log('User data:', user);
79
+ // -> { id: 1, name: 'John Doe' }
80
+ } else {
81
+ const error = result.unwrap_err();
82
+ console.error('Failed to fetch user:', error.message);
83
+ }
84
+ }
85
+
86
+ fetchUser(1);
87
+ ```
88
+
89
+ ## [API 参考](https://jsr.io/@chzky/reqwest)
90
+
91
+ ### 添加请求头
92
+ ```typescript
93
+ import { header } from '@chzky/reqwest';
94
+
95
+ const client = Reqwest.default()
96
+ .request(header({
97
+ 'Authorization': 'Bearer token',
98
+ 'X-Custom-Header': 'value'
99
+ }));
100
+ ```
101
+
102
+ ### 设置超时
103
+ ```typescript
104
+ import { timeout } from '@chzky/reqwest';
105
+
106
+ const client = Reqwest.default()
107
+ .request(timeout(5000));
108
+ ```
109
+
110
+ ### 输入验证
111
+ ```typescript
112
+ import { input_validate } from '@chzky/reqwest';
113
+ import { z } from 'zod';
114
+
115
+ const schema = z.object({
116
+ name: z.string().min(1),
117
+ age: z.number().min(0)
118
+ });
119
+
120
+ const client = Reqwest.default()
121
+ .request(input_validate(schema, 'data'));
122
+ ```
123
+
124
+ ### GET 请求
125
+ ```typescript
126
+ import { get, pick } from '@chzky/reqwest';
127
+
128
+ const client = Reqwest.default()
129
+ .request(get('/api/users', { page: 1, limit: 10 }))
130
+ .response(pick('data'));
131
+
132
+ const result = await client.dispatch();
133
+ ```
134
+
135
+ ### POST 请求
136
+ ```typescript
137
+ import { post } from '@chzky/reqwest';
138
+
139
+ const client = Reqwest.default()
140
+ .request(post('/api/users', { name: 'John', age: 25 }));
141
+
142
+ const result = await client.dispatch();
143
+ ```
144
+
145
+ ### PUT 请求
146
+ ```typescript
147
+ import { put } from '@chzky/reqwest';
148
+
149
+ const client = Reqwest.default()
150
+ .request(put('/api/users/1', { name: 'John Updated' }));
151
+
152
+ const result = await client.dispatch();
153
+ ```
154
+
155
+ ### DELETE 请求
156
+ ```typescript
157
+ import { del } from '@chzky/reqwest';
158
+
159
+ const client = Reqwest.default()
160
+ .request(del('/api/users/1'));
161
+
162
+ const result = await client.dispatch();
163
+ ```
164
+
165
+ ### 表单提交
166
+ ```typescript
167
+ import { form } from '@chzky/reqwest';
168
+
169
+ const client = Reqwest.default()
170
+ .request(form('/api/upload', {
171
+ file: fileObject,
172
+ name: 'document'
173
+ }));
174
+
175
+ const result = await client.dispatch();
176
+ ```
177
+
178
+ ### 输出验证
179
+ ```typescript
180
+ import { output_validate } from '@chzky/reqwest';
181
+ import { z } from 'zod';
182
+
183
+ const responseSchema = z.object({
184
+ id: z.number(),
185
+ name: z.string()
186
+ });
187
+
188
+ const client = Reqwest.default()
189
+ .response(output_validate(responseSchema));
190
+
191
+ const result = await client.dispatch();
192
+ ```
193
+
194
+ ### 数据映射
195
+ ```typescript
196
+ import { response_map } from '@chzky/reqwest';
197
+
198
+ const client = Reqwest.default()
199
+ .response(response_map(data => ({
200
+ ...data,
201
+ processed: true
202
+ })));
203
+
204
+ const result = await client.dispatch();
205
+ ```
206
+
207
+ ### 数据提取
208
+ ```typescript
209
+ import { pick } from '@chzky/reqwest';
210
+
211
+ const client = Reqwest.default()
212
+ .response(pick('data'));
213
+
214
+ const result = await client.dispatch();
215
+ ```
216
+
217
+ ### Server-Sent Events (SSE)
218
+ ```typescript
219
+ import { Reqwest, parse_sse_data } from '@chzky/reqwest';
220
+
221
+ const abort = new AbortController();
222
+ const gen = Reqwest.sse({
223
+ abort: abort.signal,
224
+ url: 'https://stream.example.com/events'
225
+ });
226
+
227
+ // 使用 for await 循环
228
+ for await (const item of gen) {
229
+ if (/* 条件 */) abort.abort();
230
+ const message = parse_sse_data(item);
231
+ console.log(message.data);
232
+ }
233
+ ```
234
+
235
+ ### WebSocket
236
+ ```typescript
237
+ import { Reqwest } from '@chzky/reqwest';
238
+
239
+ const abort = new AbortController();
240
+ const ws = Reqwest.ws({
241
+ url: 'wss://echo.websocket.org',
242
+ abort: abort.signal,
243
+ deserialize: data => JSON.parse(data.data),
244
+ serialize: data => JSON.stringify(data)
245
+ });
246
+
247
+ ws.subscribe({
248
+ next: data => console.log('Received:', data),
249
+ complete: () => console.log('Connection closed')
250
+ });
251
+
252
+ ws.next({ type: 'message', data: 'Hello' });
253
+ ```
254
+
255
+ ### 下载进度
256
+ ```typescript
257
+ import { download_process } from '@chzky/reqwest';
258
+
259
+ const client = Reqwest.default()
260
+ .request(download_process(progress => {
261
+ console.log(`Download progress: ${progress}%`);
262
+ }));
263
+ ```
264
+
265
+ ### 文件下载
266
+ ```typescript
267
+ import { open_link, blob2url } from '@chzky/reqwest';
268
+
269
+ const [cleanup, createUrl] = blob2url();
270
+
271
+ const client = Reqwest.default()
272
+ .response(open_link('file.pdf'))
273
+ .response(createUrl);
274
+
275
+ const result = await client.dispatch();
276
+
277
+ // 使用后清理
278
+ cleanup();
279
+ ```
280
+
281
+ ### 请求取消
282
+ ```typescript
283
+ import { cancel } from '@chzky/reqwest';
284
+
285
+ const [abortController, interceptor] = cancel();
286
+
287
+ const client = Reqwest.default()
288
+ .use(interceptor);
289
+
290
+ // 取消请求
291
+ abortController.abort();
292
+ ```
293
+
294
+ ### 加载状态
295
+ ```typescript
296
+ import { loading_control } from '@chzky/reqwest';
297
+
298
+ const loading = ref(false);
299
+ const [controller, interceptor] = loading_control(loading, {
300
+ maximum: 10000,
301
+ maximun_handler: () => console.log('Request timeout')
302
+ });
303
+
304
+ const client = Reqwest.default()
305
+ .use(interceptor);
306
+ ```
307
+
308
+ ### 延迟请求
309
+ ```typescript
310
+ import { wait } from '@chzky/reqwest';
311
+
312
+ const client = Reqwest.default()
313
+ .request(wait(1000)); // 延迟 1 秒
314
+ ```
@@ -1,3 +1,14 @@
1
+ declare global {
2
+ interface Object {
3
+ /**
4
+ * Determines whether an object has a property with the specified name.
5
+ * @param o An object.
6
+ * @param v A property name.
7
+ */
8
+ hasOwn(o: object, v: PropertyKey): boolean;
9
+ }
10
+ }
11
+ export {};
1
12
  declare global {
2
13
  interface PromiseConstructor {
3
14
  /**
@@ -1,10 +1 @@
1
- {
2
- "version": 3,
3
- "file": "_dnt.polyfills.d.ts",
4
- "sourceRoot": "",
5
- "sources": [
6
- "../src/_dnt.polyfills.ts"
7
- ],
8
- "names": [],
9
- "mappings": "AAAA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,kBAAkB;QAC1B;;;WAGG;QACH,aAAa,CAAC,CAAC,KAAK;YAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;SAAE,CAAC;KAC3H;CACF"
10
- }
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,kBAAkB;QAC1B;;;WAGG;QACH,aAAa,CAAC,CAAC,KAAK;YAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;SAAE,CAAC;KAC3H;CACF"}
@@ -1,68 +1,26 @@
1
- 'use strict'
2
- const _0x31d5ea = _0xac34
3
- ;(function (_0x218eb6, _0x197562) {
4
- const _0xace3fc = _0xac34,
5
- _0x162a79 = _0x218eb6()
6
- while (!![]) {
7
- try {
8
- const _0x33bcea =
9
- (-parseInt(_0xace3fc(0x1ac)) / 0x1) * (-parseInt(_0xace3fc(0x1b3)) / 0x2) +
10
- -parseInt(_0xace3fc(0x1af)) / 0x3 +
11
- (-parseInt(_0xace3fc(0x1ad)) / 0x4) * (parseInt(_0xace3fc(0x1b4)) / 0x5) +
12
- -parseInt(_0xace3fc(0x1b8)) / 0x6 +
13
- (-parseInt(_0xace3fc(0x1b1)) / 0x7) * (-parseInt(_0xace3fc(0x1b6)) / 0x8) +
14
- (-parseInt(_0xace3fc(0x1b7)) / 0x9) * (-parseInt(_0xace3fc(0x1b0)) / 0xa) +
15
- (parseInt(_0xace3fc(0x1ae)) / 0xb) * (-parseInt(_0xace3fc(0x1b9)) / 0xc)
16
- if (_0x33bcea === _0x197562) break
17
- else _0x162a79['push'](_0x162a79['shift']())
18
- } catch (_0x79caa0) {
19
- _0x162a79['push'](_0x162a79['shift']())
20
- }
21
- }
22
- })(_0x1840, 0x90753)
23
- function _0xac34(_0x42e44f, _0x1ce41b) {
24
- const _0x184000 = _0x1840()
25
- return (
26
- (_0xac34 = function (_0xac34be, _0x449ecd) {
27
- _0xac34be = _0xac34be - 0x1ab
28
- let _0x32ec58 = _0x184000[_0xac34be]
29
- return _0x32ec58
30
- }),
31
- _0xac34(_0x42e44f, _0x1ce41b)
32
- )
1
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
2
+ if (!Object.hasOwn) {
3
+ Object.defineProperty(Object, "hasOwn", {
4
+ value: function (object, property) {
5
+ if (object == null) {
6
+ throw new TypeError("Cannot convert undefined or null to object");
7
+ }
8
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
9
+ },
10
+ configurable: true,
11
+ enumerable: false,
12
+ writable: true,
13
+ });
33
14
  }
34
- Promise[_0x31d5ea(0x1ab)] === undefined &&
35
- (Promise[_0x31d5ea(0x1ab)] = () => {
36
- const _0x3518a6 = _0x31d5ea,
37
- _0x5a4145 = {}
38
- return (
39
- (_0x5a4145[_0x3518a6(0x1b2)] = new Promise((_0x449ccb, _0x2f4282) => {
40
- const _0x2589c7 = _0x3518a6
41
- ;(_0x5a4145['resolve'] = _0x449ccb), (_0x5a4145[_0x2589c7(0x1b5)] = _0x2f4282)
42
- })),
43
- _0x5a4145
44
- )
45
- })
46
- function _0x1840() {
47
- const _0x20b7b6 = [
48
- '185fhOclK',
49
- 'reject',
50
- '24KaZOkY',
51
- '8375013pOGIFB',
52
- '1183158wBXZLS',
53
- '684YPnMsq',
54
- 'withResolvers',
55
- '495067IzAadC',
56
- '90276LHDCpv',
57
- '60401QhgZeF',
58
- '1303824UqgQha',
59
- '10hgNBTH',
60
- '1051981DvvVBk',
61
- 'promise',
62
- '4GxaeKo',
63
- ]
64
- _0x1840 = function () {
65
- return _0x20b7b6
66
- }
67
- return _0x1840()
15
+ // https://github.com/tc39/proposal-promise-with-resolvers/blob/3a78801e073e99217dbeb2c43ba7212f3bdc8b83/polyfills.js#L1C1-L9C2
16
+ if (Promise.withResolvers === undefined) {
17
+ Promise.withResolvers = () => {
18
+ const out = {};
19
+ out.promise = new Promise((resolve_, reject_) => {
20
+ out.resolve = resolve_;
21
+ out.reject = reject_;
22
+ });
23
+ return out;
24
+ };
68
25
  }
26
+ export {};
@@ -1,14 +1,2 @@
1
- import { Deno } from "@deno/shim-deno";
2
- export { Deno } from "@deno/shim-deno";
3
- export { alert, confirm, prompt } from "@deno/shim-prompts";
4
- import { setInterval, setTimeout } from "@deno/shim-timers";
5
- export { setInterval, setTimeout } from "@deno/shim-timers";
6
- export declare const dntGlobalThis: Omit<typeof globalThis, "alert" | "confirm" | "prompt" | "setInterval" | "setTimeout" | "Deno"> & {
7
- Deno: typeof Deno;
8
- alert: typeof globalThis.alert;
9
- confirm: typeof globalThis.confirm;
10
- prompt: typeof globalThis.prompt;
11
- setInterval: typeof setInterval;
12
- setTimeout: typeof setTimeout;
13
- };
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
14
2
  //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU5D,eAAO,MAAM,aAAa;;;;;;;CAA2C,CAAC"}
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
package/esm/_dnt.shims.js CHANGED
@@ -1 +1,57 @@
1
- (function(_0x1bfd95,_0x39097d){const _0x411f69=_0x4032,_0x31b370=_0x1bfd95();while(!![]){try{const _0x18787d=-parseInt(_0x411f69(0xed))/0x1*(parseInt(_0x411f69(0xef))/0x2)+parseInt(_0x411f69(0xee))/0x3+-parseInt(_0x411f69(0xe7))/0x4*(parseInt(_0x411f69(0xe9))/0x5)+parseInt(_0x411f69(0xe4))/0x6*(-parseInt(_0x411f69(0xec))/0x7)+-parseInt(_0x411f69(0xe3))/0x8*(-parseInt(_0x411f69(0xeb))/0x9)+-parseInt(_0x411f69(0xea))/0xa+parseInt(_0x411f69(0xe1))/0xb;if(_0x18787d===_0x39097d)break;else _0x31b370['push'](_0x31b370['shift']());}catch(_0x4781b0){_0x31b370['push'](_0x31b370['shift']());}}}(_0x5be7,0x7e7c7));import{Deno}from'@deno/shim-deno';export{Deno}from'@deno/shim-deno';function _0x4032(_0x5acdd8,_0x7ad30f){const _0x5be73c=_0x5be7();return _0x4032=function(_0x403274,_0x21cadc){_0x403274=_0x403274-0xe1;let _0x51f016=_0x5be73c[_0x403274];return _0x51f016;},_0x4032(_0x5acdd8,_0x7ad30f);}import{alert,confirm,prompt}from'@deno/shim-prompts';export{alert,confirm,prompt}from'@deno/shim-prompts';import{setInterval,setTimeout}from'@deno/shim-timers';function _0x5be7(){const _0x5c70ab=['7280170wXGpqC','212526EPPdXw','7qtoZFC','1BAnbyJ','483219avhdbg','1032328CiCAdz','7816149AlTGro','has','328YzAgoX','241482mMMCTj','filter','getOwnPropertyDescriptor','4COLHAT','ownKeys','186455dwBDyQ'];_0x5be7=function(){return _0x5c70ab;};return _0x5be7();}export{setInterval,setTimeout}from'@deno/shim-timers';const dntGlobals={'Deno':Deno,'alert':alert,'confirm':confirm,'prompt':prompt,'setInterval':setInterval,'setTimeout':setTimeout};export const dntGlobalThis=createMergeProxy(globalThis,dntGlobals);function createMergeProxy(_0x494ef5,_0xad92f9){return new Proxy(_0x494ef5,{'get'(_0x43c33c,_0xa03f44,_0x25c92e){return _0xa03f44 in _0xad92f9?_0xad92f9[_0xa03f44]:_0x494ef5[_0xa03f44];},'set'(_0x2b9dba,_0x11a134,_0x10c824){return _0x11a134 in _0xad92f9&&delete _0xad92f9[_0x11a134],_0x494ef5[_0x11a134]=_0x10c824,!![];},'deleteProperty'(_0x4ecc5d,_0xa9b848){let _0x310d92=![];return _0xa9b848 in _0xad92f9&&(delete _0xad92f9[_0xa9b848],_0x310d92=!![]),_0xa9b848 in _0x494ef5&&(delete _0x494ef5[_0xa9b848],_0x310d92=!![]),_0x310d92;},'ownKeys'(_0x67fb0b){const _0xa5e994=_0x4032,_0x34de2e=Reflect[_0xa5e994(0xe8)](_0x494ef5),_0x3218ca=Reflect[_0xa5e994(0xe8)](_0xad92f9),_0xfb95e9=new Set(_0x3218ca);return[..._0x34de2e[_0xa5e994(0xe5)](_0x5578e1=>!_0xfb95e9[_0xa5e994(0xe2)](_0x5578e1)),..._0x3218ca];},'defineProperty'(_0x5a3aa1,_0x1c6455,_0xb67c49){return _0x1c6455 in _0xad92f9&&delete _0xad92f9[_0x1c6455],Reflect['defineProperty'](_0x494ef5,_0x1c6455,_0xb67c49),!![];},'getOwnPropertyDescriptor'(_0xee0720,_0x34eb20){const _0x4f72bf=_0x4032;return _0x34eb20 in _0xad92f9?Reflect[_0x4f72bf(0xe6)](_0xad92f9,_0x34eb20):Reflect[_0x4f72bf(0xe6)](_0x494ef5,_0x34eb20);},'has'(_0x11bdb5,_0x46c9d6){return _0x46c9d6 in _0xad92f9||_0x46c9d6 in _0x494ef5;}});}
1
+ const dntGlobals = {};
2
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
3
+ function createMergeProxy(baseObj, extObj) {
4
+ return new Proxy(baseObj, {
5
+ get(_target, prop, _receiver) {
6
+ if (prop in extObj) {
7
+ return extObj[prop];
8
+ }
9
+ else {
10
+ return baseObj[prop];
11
+ }
12
+ },
13
+ set(_target, prop, value) {
14
+ if (prop in extObj) {
15
+ delete extObj[prop];
16
+ }
17
+ baseObj[prop] = value;
18
+ return true;
19
+ },
20
+ deleteProperty(_target, prop) {
21
+ let success = false;
22
+ if (prop in extObj) {
23
+ delete extObj[prop];
24
+ success = true;
25
+ }
26
+ if (prop in baseObj) {
27
+ delete baseObj[prop];
28
+ success = true;
29
+ }
30
+ return success;
31
+ },
32
+ ownKeys(_target) {
33
+ const baseKeys = Reflect.ownKeys(baseObj);
34
+ const extKeys = Reflect.ownKeys(extObj);
35
+ const extKeysSet = new Set(extKeys);
36
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
37
+ },
38
+ defineProperty(_target, prop, desc) {
39
+ if (prop in extObj) {
40
+ delete extObj[prop];
41
+ }
42
+ Reflect.defineProperty(baseObj, prop, desc);
43
+ return true;
44
+ },
45
+ getOwnPropertyDescriptor(_target, prop) {
46
+ if (prop in extObj) {
47
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
48
+ }
49
+ else {
50
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
51
+ }
52
+ },
53
+ has(_target, prop) {
54
+ return prop in extObj || prop in baseObj;
55
+ },
56
+ });
57
+ }
@@ -0,0 +1,122 @@
1
+ import type { AsyncResult, UnexpectedError } from '@chzky/core';
2
+ import type { AxiosResponse, CreateAxiosDefaults } from 'axios';
3
+ import type { ExtendWebSocketSubject, MergeErrors, RequestInterceptor, ReqwestInterceptor, ReqwestInterface, ReqwestSSEConfig, ReqwestWsConfig, ResponseInterceptor, ResponseResult } from './interface.js';
4
+ /** ## `Reqwest` : 基于`Axios`二次封装的请求库 */
5
+ export declare class Reqwest<O = AxiosResponse<unknown, unknown>, E = never, ER = UnexpectedError> implements ReqwestInterface<O, E, ER> {
6
+ private readonly interceptors_req;
7
+ private readonly interceptors_res;
8
+ private cof;
9
+ private readonly internal_axios;
10
+ constructor(interceptors_req?: any[], interceptors_res?: any[], cof?: CreateAxiosDefaults);
11
+ /** ### `conf` : 更新配置 */
12
+ conf(conf: CreateAxiosDefaults): ReqwestInterface<O, E, ER>;
13
+ request<I extends RequestInterceptor<unknown>[]>(...interceptors: I): ReqwestInterface<O, MergeErrors<I> | E, ER>;
14
+ response<T extends ResponseInterceptor<unknown, unknown, unknown>[]>(...interceptor: T): ResponseResult<O, E, ER, T>;
15
+ use<OO, EC, EE>(interceptor: ReqwestInterceptor<O, EC, OO, EE>): ReqwestInterface<OO, EC | E, EE | ER>;
16
+ dispatch(): AsyncResult<O, E | ER>;
17
+ clone(): ReqwestInterface<O, E, ER>;
18
+ /** ### `new`
19
+ 实现{@link NewAble}接口 */
20
+ static new(): ReqwestInterface;
21
+ /** ### `default`
22
+ 实现{@link Default}接口 : 以默认配置生成一个`Reqwest`
23
+ #### 默认配置
24
+ + `timeout` : `6000`ms
25
+ */
26
+ static default(): ReqwestInterface;
27
+ /** ## `sse` : 进行[SSE](https://developer.mozilla.org/zh-CN/docs/Web/API/Server-sent_events/Using_server-sent_events)请求
28
+ api使用见[rxjs-webSocket](https://rxjs.dev/api/webSocket/webSocket)
29
+ + 实际请求只有在第一次`gen.next()`时才会发出请求
30
+ + 由于请求带来的错误不会抛出,而是返回`{done:true,value:underfine}`
31
+ @example for await to take
32
+ ```ts
33
+ const sse_url = 'https://stream.wikimedia.org/v2/stream/recentchange'
34
+
35
+ const abort = new AbortController()
36
+
37
+ const gen = Reqwest.sse({
38
+ abort,
39
+ url: sse_url,
40
+ })
41
+
42
+ let index = 0
43
+ // 开始循环时才会调用接口获取数据
44
+ for await (const item of gen) {
45
+ if (index === 10) abort.abort() //主动终止数据获取
46
+ index++
47
+ const message = parse_sse_data(item)
48
+ assert(typeof message.data === 'string')
49
+ }
50
+
51
+ const { done, value } = await gen.next()
52
+ assert(done)
53
+ assert.equal(value, undefined)
54
+ ```
55
+ @example AsyncVector to take
56
+ ```ts
57
+ const sse_url = 'https://stream.wikimedia.org/v2/stream/recentchange'
58
+
59
+ const abort = new AbortController()
60
+
61
+ const gen = Reqwest.sse({
62
+ abort,
63
+ url: sse_url,
64
+ })
65
+
66
+ const vec = AsyncVec(gen, false)
67
+
68
+ const result = await vec
69
+ .map(item => parse_sse_data(item))
70
+ .filter(i => Boolean(i.data))
71
+ .take(10)
72
+ .collect()
73
+
74
+ const { done, value } = await gen.next()
75
+
76
+ assert(done)
77
+ assert.equal(value, undefined)
78
+ assert.equal(result.length, 10)
79
+ assert(result.every(i => i.data.length > 1))
80
+ ```
81
+ */
82
+ static sse(conf: ReqwestSSEConfig): AsyncGenerator<Uint8Array, undefined, void>;
83
+ /** ## `sse` : 进行[WebSocket](https://developer.mozilla.org/zh-CN/docs/Web/API/WebSocket)请求
84
+ @example Usage
85
+ ```ts
86
+ const MOCK_URL = 'wss://echo.websocket.org'
87
+
88
+ const { promise, resolve } = Promise.withResolvers<void>()
89
+
90
+ const abort = new AbortController()
91
+
92
+ type TansShape = { type: 'event' | 'message'; data: JsonX }
93
+
94
+ const wss = Reqwest.ws({
95
+ url: MOCK_URL,
96
+ abort: abort.signal,
97
+ deserialize: data => result(() => JSON.parse(data.data) as TansShape).unwrap_or(data.data),
98
+ serialize: (data: TansShape) => JSON.stringify(data),
99
+ })
100
+
101
+ wss.subscribe({
102
+ complete: resolve,
103
+ next: data => {
104
+ if (typeof data === 'string') return
105
+ const rdata = data as TansShape
106
+ if (!rdata.data) return
107
+
108
+ abort.abort() // 触发complete函数,执行complete回调
109
+ assert(rdata.data)
110
+ assert.equal(rdata.type, 'message')
111
+ },
112
+ })
113
+
114
+ wss.next({ type: 'event', data: false })
115
+ wss.next({ type: 'message', data: true })
116
+
117
+ await promise
118
+ ```
119
+ */
120
+ static ws<A, B>(conf: ReqwestWsConfig<A, B>): ExtendWebSocketSubject<A, B>;
121
+ }
122
+ //# sourceMappingURL=class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../../../src/lib/core/class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,KAAK,EACX,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,MAAM,gBAAgB,CAAA;AAKvB,uCAAuC;AACvC,qBAAa,OAAO,CACnB,CAAC,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EACnC,CAAC,GAAG,KAAK,EACT,EAAE,GAAG,eAAe,CACnB,YAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAMrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,GAAG;IAPZ,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;gBAIhC,gBAAgB,GAAE,GAAG,EAAO,EAE5B,gBAAgB,GAAE,GAAG,EAAO,EACrC,GAAG,GAAE,mBAAwB;IAKtC,wBAAwB;IACxB,IAAI,CAAC,IAAI,EAAE,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAW3D,OAAO,CAAC,CAAC,SAAS,kBAAkB,CAAC,OAAO,CAAC,EAAE,EAC9C,GAAG,YAAY,EAAE,CAAC,GAChB,gBAAgB,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;IAQ9C,QAAQ,CAAC,CAAC,SAAS,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAClE,GAAG,WAAW,EAAE,CAAC,GACf,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAQ9B,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EACb,WAAW,EAAE,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAC5C,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC;IAQxC,QAAQ,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IAIlC,KAAK,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAQnC;0BACsB;IACtB,MAAM,CAAC,GAAG,IAAI,gBAAgB;IAI9B;;;;OAIG;IACH,MAAM,CAAC,OAAO,IAAI,gBAAgB;IAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsDG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC;IAI/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC;CAG1E"}