@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
@@ -0,0 +1,172 @@
1
+ import type { AsyncResult, Copy, Fn, PromiseOr, Result, rjx_ws, UnexpectedError, zod } from '@chzky/core';
2
+ import type { AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from 'axios';
3
+ type WebSocketMessage = string | ArrayBuffer | Blob | ArrayBufferView;
4
+ /** ### `ReqwestWsConfig` : WebSocket连接配置 */
5
+ export type ReqwestWsConfig<A, B> = {
6
+ /** WebSocket连接地址 */
7
+ url: string;
8
+ /** 终止控制器 */
9
+ abort?: AbortController | AbortSignal;
10
+ /** 反序列化函数 , 将获取的数据反序列化为`B`类型
11
+ @default `(data)=>JSON.parse(data.data)` */
12
+ deserialize?: Fn<MessageEvent, B>;
13
+ /** 序列化函数 , 将发送的数据序列化为`WebSocketMessage`类型
14
+ @default `(data)=>JSON.stringify(data)` */
15
+ serialize?: Fn<A, WebSocketMessage>;
16
+ };
17
+ export type ExtendWebSocketSubject<A, B> = {
18
+ next: (data: A) => void;
19
+ subscribe: Fn<Fn<B, void>, void>;
20
+ } & {
21
+ complete?: Fn<void, void>;
22
+ error?: Fn<Fn<unknown, void>, void>;
23
+ next?: Fn<Fn<B, void>, void>;
24
+ } & rjx_ws.WebSocketSubject<unknown>;
25
+ /** ### `ReqwestSSEConfig` : SSE连接配置 */
26
+ export type ReqwestSSEConfig = {
27
+ /** SSE连接地址 */
28
+ url: string;
29
+ /** 终止控制器 */
30
+ abort?: AbortController | AbortSignal;
31
+ /** SSE连接方法 : 默认`get` */
32
+ method?: 'GET' | 'POST';
33
+ /** 解码器 : 默认不使用,直接返回`Uint8Array` */
34
+ decode?: {
35
+ decode: (input: Uint8Array<ArrayBuffer>) => string;
36
+ };
37
+ /** 数据校验器,用于校验解码后的数据 : 默认不使用,直接返回解码后的数据 */
38
+ validator?: zod.ZodSchema<unknown>;
39
+ };
40
+ /** ### `RequestInterceptor` : 请求拦截器 | 返回`Ok()` or `Err(E)`
41
+ + `Ok()`表示通过拦截器 , 会运行下一个拦截器
42
+ + `Err(E)`表示拦截器拦截 , 会直接短路返回`Err(E)`
43
+ */
44
+ export type RequestInterceptor<E = never> = (conf: InternalAxiosRequestConfig<unknown>) => PromiseOr<Result<void, E>>;
45
+ /** ### `ResponseInterceptor` : 响应拦截器 | 返回`Ok(O)` or `Err(E)`
46
+ + `Ok(O)` 表示通过拦截器 , 会自动解包并将值传递给下一个拦截器
47
+ + `Err(E)`表示拦截器拦截 , 会直接短路返回`Err(E)`
48
+ */
49
+ export type ResponseInterceptor<O = AxiosResponse<unknown, unknown>, OO = AxiosResponse<unknown, unknown>, EE = never> = (response: O) => PromiseOr<Result<OO, EE>>;
50
+ /** ### `ReqwestInterceptor` : `请求-响应拦截器` | 分成响应拦截和请求拦截 */
51
+ export interface ReqwestInterceptor<O, E, OO = O, EE = never> {
52
+ request: RequestInterceptor<E>;
53
+ response: ResponseInterceptor<O, OO, EE>;
54
+ }
55
+ export type MergeErrors<T extends unknown[]> = T extends [
56
+ RequestInterceptor<infer E>,
57
+ ...infer Rest
58
+ ] ? E | MergeErrors<Rest> : never;
59
+ type FinalResult<Interceptors extends ResponseInterceptor<unknown, unknown, unknown>[], CurrentOutput = AxiosResponse<unknown>, CurrentError = UnexpectedError> = Interceptors extends [
60
+ infer First,
61
+ ...infer Rest extends ResponseInterceptor<unknown, unknown, unknown>[]
62
+ ] ? First extends ResponseInterceptor<CurrentOutput, infer NextOutput, infer NextError> ? FinalResult<Rest, NextOutput, NextError | CurrentError> : never : Result<CurrentOutput, CurrentError>;
63
+ export type ResponseResult<O, E, ER, Interceptors extends ResponseInterceptor<unknown, unknown, unknown>[]> = ReqwestInterface<FinalResult<Interceptors, O, ER> extends Result<infer O, unknown> ? O : never, E, FinalResult<Interceptors, O, ER> extends Result<unknown, infer E> ? E : never>;
64
+ export interface ReqwestInterface<O = AxiosResponse<unknown, unknown>, E = never, ER = UnexpectedError> extends Copy {
65
+ /** ### `conf` : 更新配置
66
+ @example Usage
67
+ ```ts
68
+ const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
69
+ const mock_reqwest = Reqwest.new().conf(conf)
70
+ mock_reqwest.dispatch() // curl https://jsonplaceholder.typicode.com/todos/
71
+ ```
72
+ */
73
+ conf(conf: CreateAxiosDefaults): ReqwestInterface<O, E, ER>;
74
+ /** ### `dispatch` : 发送请求,获取请求结果
75
+ @example Usage
76
+ ```ts
77
+ const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
78
+ const mock_reqwest = Reqwest.new().conf(conf)
79
+ mock_reqwest.dispatch() // dispatch to get https://jsonplaceholder.typicode.com/todos/
80
+ ```
81
+ */
82
+ dispatch(): AsyncResult<O, E | ER>;
83
+ /** ### `request` : 增加请求拦截器,拦截器会按顺序执行
84
+ + 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立 */
85
+ request<I extends RequestInterceptor<unknown>[]>(...interceptors: I): ReqwestInterface<O, MergeErrors<I> | E, ER>;
86
+ /** ### `response` : 增加响应拦截器,拦截器会按顺序执行
87
+ + 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立 */
88
+ response<OO, EE>(interceptor: ResponseInterceptor<O, OO, EE>): ReqwestInterface<OO, E, EE | ER>;
89
+ response<OO, EE, O2, E2>(...interceptor: [ResponseInterceptor<O, OO, EE>, ResponseInterceptor<OO, O2, E2>]): ReqwestInterface<O2, E, E2 | EE | ER>;
90
+ response<OO, EE, O2, E2, O3, E3>(...interceptor: [
91
+ ResponseInterceptor<O, OO, EE>,
92
+ ResponseInterceptor<OO, O2, E2>,
93
+ ResponseInterceptor<O2, O3, E3>
94
+ ]): ReqwestInterface<O3, E, E3 | E2 | EE | ER>;
95
+ response<OO, EE, O2, E2, O3, E3, O4, E4>(...interceptor: [
96
+ ResponseInterceptor<O, OO, EE>,
97
+ ResponseInterceptor<OO, O2, E2>,
98
+ ResponseInterceptor<O2, O3, E3>,
99
+ ResponseInterceptor<O3, O4, E4>
100
+ ]): ReqwestInterface<O4, E, E4 | E3 | E2 | EE | ER>;
101
+ response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5>(...interceptor: [
102
+ ResponseInterceptor<O, OO, EE>,
103
+ ResponseInterceptor<OO, O2, E2>,
104
+ ResponseInterceptor<O2, O3, E3>,
105
+ ResponseInterceptor<O3, O4, E4>
106
+ ]): ReqwestInterface<O5, E, E5 | E4 | E3 | E2 | EE | ER>;
107
+ response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6>(...interceptor: [
108
+ ResponseInterceptor<O, OO, EE>,
109
+ ResponseInterceptor<OO, O2, E2>,
110
+ ResponseInterceptor<O2, O3, E3>,
111
+ ResponseInterceptor<O3, O4, E4>,
112
+ ResponseInterceptor<O4, O5, E5>,
113
+ ResponseInterceptor<O5, O6, E6>
114
+ ]): ReqwestInterface<O6, E, E6 | E5 | E4 | E3 | E2 | EE | ER>;
115
+ response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7>(...interceptor: [
116
+ ResponseInterceptor<O, OO, EE>,
117
+ ResponseInterceptor<OO, O2, E2>,
118
+ ResponseInterceptor<O2, O3, E3>,
119
+ ResponseInterceptor<O3, O4, E4>,
120
+ ResponseInterceptor<O4, O5, E5>,
121
+ ResponseInterceptor<O5, O6, E6>,
122
+ ResponseInterceptor<O6, O7, E7>
123
+ ]): ReqwestInterface<O7, E, E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
124
+ response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7, O8, E8>(...interceptor: [
125
+ ResponseInterceptor<O, OO, EE>,
126
+ ResponseInterceptor<OO, O2, E2>,
127
+ ResponseInterceptor<O2, O3, E3>,
128
+ ResponseInterceptor<O3, O4, E4>,
129
+ ResponseInterceptor<O4, O5, E5>,
130
+ ResponseInterceptor<O5, O6, E6>,
131
+ ResponseInterceptor<O6, O7, E7>,
132
+ ResponseInterceptor<O7, O8, E8>
133
+ ]): ReqwestInterface<O8, E, E8 | E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
134
+ response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7, O8, E8, O9, E9>(...interceptor: [
135
+ ResponseInterceptor<O, OO, EE>,
136
+ ResponseInterceptor<OO, O2, E2>,
137
+ ResponseInterceptor<O2, O3, E3>,
138
+ ResponseInterceptor<O3, O4, E4>,
139
+ ResponseInterceptor<O4, O5, E5>,
140
+ ResponseInterceptor<O5, O6, E6>,
141
+ ResponseInterceptor<O6, O7, E7>,
142
+ ResponseInterceptor<O7, O8, E8>,
143
+ ResponseInterceptor<O8, O9, E9>
144
+ ]): ReqwestInterface<O9, E, E9 | E8 | E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
145
+ /** ### `use` : 增加`请求-响应拦截器`,拦截器会按顺序执行
146
+ + 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立
147
+ @example Usage - cancel
148
+ ```ts
149
+ const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
150
+ const mock_reqwest = Reqwest.new().conf(conf)
151
+
152
+ const [abort_controler, interceptor] = cancel() // 可取消的请求
153
+
154
+ const reqwest = mock_reqwest.clone().request(wait(2000), get('/1')).use(interceptor)
155
+
156
+ const mock_cause = 'mock abort'
157
+ abort_controler.abort(mock_cause)
158
+
159
+ const result = await reqwest.dispatch()
160
+
161
+ const error = result.unwrap_err()
162
+ assert(error.instance_of(AbortedError))
163
+ assert.equal(error.cause, mock_cause)
164
+ ```
165
+ */
166
+ use<OO, EC, EE>(interceptor: ReqwestInterceptor<O, EC, OO, EE>): ReqwestInterface<OO, EC | E, EE | ER>;
167
+ /** ### `clone`
168
+ + 实现{@link Copy}接口 : 生成一个全新的`Reqwest` */
169
+ clone(): ReqwestInterface<O, E, ER>;
170
+ }
171
+ export {};
172
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/lib/core/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,IAAI,EACJ,EAAE,EACF,SAAS,EACT,MAAM,EACN,MAAM,E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,EAAE,EAAE,EAAE,CAAC;QAC/B,mBAAmB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;QAC/B,mBAAmB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;QAC/B,mBAAmB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;KAC/B,GACC,gBAAgB,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;IAE3E;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,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,CAAA;IAExC;4CACwC;IACxC,KAAK,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;CACnC"}
@@ -0,0 +1,5 @@
1
+ /** @module core */
2
+ export type { RequestInterceptor, ReqwestInterceptor, ResponseInterceptor, } from './interface.js';
3
+ export * from './class.js';
4
+ export * from './factor.js';
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/core/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB;AAEnB,YAAY,EACX,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,gBAAgB,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /** @module core */
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,3 +1,5 @@
1
+ /** @module helper */
2
+ export * from './other/mod.js';
1
3
  export * from './request/mod.js';
2
4
  export * from './response/mod.js';
3
5
  export * from './use/mod.js';
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/helper/mod.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/helper/mod.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA"}
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /** @module helper */
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -14,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
16
  };
16
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./other/mod.js"), exports);
17
19
  __exportStar(require("./request/mod.js"), exports);
18
20
  __exportStar(require("./response/mod.js"), exports);
19
21
  __exportStar(require("./use/mod.js"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './sseParse.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/lib/helper/other/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./sseParse.js"), exports);
@@ -0,0 +1,34 @@
1
+ /** `SSEMessageEvent` : 经典的SSE事件名
2
+ + `message` : 默认事件(不写 event: 时就是它)
3
+ + `open` : 连接建立后服务器推送的第一条欢迎消息
4
+ + `ping` : 服务端保活
5
+ + `update` : 数据增量更新
6
+ + `error` : 服务端主动通知前端“出错了”
7
+ + `close` : 服务端优雅关闭连接
8
+ */
9
+ export type SSEMessageEvent = 'message' | 'open' | 'ping' | 'update' | 'error' | 'close';
10
+ export interface SSEMessage {
11
+ /** 数据 */
12
+ data: string;
13
+ /** 事件类型 */
14
+ event?: SSEMessageEvent | string;
15
+ /** 消息ID */
16
+ id?: string;
17
+ /** 重连时间(毫秒) */
18
+ retry?: number;
19
+ }
20
+ /** ## `parse_sse_data` : 解析[标准SSE格式](https://developer.mozilla.org/zh-CN/docs/Web/API/Server-sent_events/Using_server-sent_events)的数据
21
+ @example Usage
22
+ ```ts
23
+ const generator = Reqwest.sse({
24
+ url: 'http://localhost:7788/api/ping/sse',
25
+ })
26
+
27
+ for await (const item of generator) {
28
+ const { data } = parse_sse_data(item)
29
+ assert(typeof data === 'string')
30
+ }
31
+ ```
32
+ */
33
+ export declare function parse_sse_data(data: string | Uint8Array): SSEMessage;
34
+ //# sourceMappingURL=sseParse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sseParse.d.ts","sourceRoot":"","sources":["../../../../src/lib/helper/other/sseParse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAA;AAExF,MAAM,WAAW,UAAU;IAC1B,SAAS;IACT,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW;IACX,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM,CAAA;IAChC,WAAW;IACX,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,eAAe;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAGpE"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse_sse_data = parse_sse_data;
4
+ /** ## `parse_sse_data` : 解析[标准SSE格式](https://developer.mozilla.org/zh-CN/docs/Web/API/Server-sent_events/Using_server-sent_events)的数据
5
+ @example Usage
6
+ ```ts
7
+ const generator = Reqwest.sse({
8
+ url: 'http://localhost:7788/api/ping/sse',
9
+ })
10
+
11
+ for await (const item of generator) {
12
+ const { data } = parse_sse_data(item)
13
+ assert(typeof data === 'string')
14
+ }
15
+ ```
16
+ */
17
+ function parse_sse_data(data) {
18
+ if (typeof data === 'string')
19
+ return parse_core(data);
20
+ return parse_core(new TextDecoder().decode(data));
21
+ }
22
+ const MSG_SPLIT = '\n';
23
+ const EVENT_LINE = 'event: ';
24
+ const ID_LINE = 'id: ';
25
+ const RETRY_LINE = 'retry: ';
26
+ const DATA_LINE = 'data: ';
27
+ function parse_core(str) {
28
+ const result = { data: '' };
29
+ const lines = str.split(MSG_SPLIT);
30
+ for (const line of lines) {
31
+ if (line.startsWith(DATA_LINE)) {
32
+ if (result.data.length === 0)
33
+ result.data += line.slice(DATA_LINE.length);
34
+ else
35
+ result.data += `\n${line.slice(DATA_LINE.length)}`;
36
+ }
37
+ if (line.startsWith(ID_LINE))
38
+ result.id = line.slice(ID_LINE.length);
39
+ if (line.startsWith(EVENT_LINE))
40
+ result.event = line.slice(EVENT_LINE.length);
41
+ if (line.startsWith(RETRY_LINE))
42
+ result.retry = Number(line.slice(RETRY_LINE.length));
43
+ }
44
+ return result;
45
+ }
@@ -1,40 +1,72 @@
1
- import { type JsonXObject } from '@chzky/fp';
1
+ import type { JsonXObject } from '@chzky/core';
2
2
  import type { RequestInterceptor } from '../../../mod.js';
3
3
  /** ### `post` : post请求
4
- @param url `string` - 请求地址
4
+ @param `string` - 请求地址
5
5
  @param [data={}] `unknown` - 请求数据
6
6
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
7
- @type `Interceptor` - `Request`
8
- @category `Request`
7
+ @category `RequestInterceptor`
9
8
  */
10
9
  export declare function post(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
11
10
  /** ### `get` : get请求
12
11
  @param url `string` - 请求地址
13
12
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
14
- @type `Interceptor` - `Request`
15
- @category `Request`
13
+ @category `RequestInterceptor`
16
14
  */
17
15
  export declare function get(url: string, query?: JsonXObject): RequestInterceptor<never>;
18
16
  /** ### `put` : put请求
19
17
  @param url `string` - 请求地址
20
18
  @param [data={}] `unknown` - 请求数据
21
19
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
22
- @type `Interceptor` - `Request`
23
- @category `Request`
20
+ @category `RequestInterceptor`
24
21
  */
25
22
  export declare function put(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
26
23
  /** ### `del` : delete请求
27
24
  @param url `string` - 请求地址
28
25
  @param [query={}] `Record<string, unknown>` - query形式的请求参数
29
- @type `Interceptor` - `Request`
30
- @category `Request`
26
+ @category `RequestInterceptor`
31
27
  */
32
28
  export declare function del(url: string, query?: JsonXObject): RequestInterceptor<never>;
33
29
  /** ### `form` : FormData形式请求
34
30
  @param url `string` - 请求地址
35
31
  @param data `Record<string, string | Blob>` - 请求数据
36
- @type `Interceptor` - `Request`
37
32
  @category `Request`
38
33
  */
39
34
  export declare function form(url: string, data: Record<string | number, string | Blob>): RequestInterceptor<never>;
35
+ /** ### `set_body` : 覆盖Body参数
36
+ 该方法会覆盖请求的Body参数
37
+ @example Usage
38
+ ```ts
39
+ const request = post('/api')
40
+ request.use(set_body({ foo: 'bar' })) // Will override request body
41
+ ```
42
+ @param data `unknown` - 请求数据
43
+ @category `RequestInterceptor`
44
+ */
45
+ export declare function set_body(data: unknown): RequestInterceptor<never>;
46
+ /** ### `set_params` : 覆盖URL参数
47
+ 该方法会覆盖请求的URL参数
48
+ @example Usage
49
+ ```ts
50
+ const request = get('/api')
51
+ request.use(set_params({ foo: 'bar' })) // Will override request params
52
+ ```
53
+ @param params `Record<string, unknown>` - URL形式的请求参数
54
+ @type `Interceptor` - `Request`
55
+ @category `RequestInterceptor`
56
+ */
57
+ export declare function set_params(params: JsonXObject): RequestInterceptor<never>;
58
+ /** ### `append_url` : URL
59
+ 该方法会将url添加到请求地址的后面;如果没有url,则直接添加
60
+ @param url `string` - 请求地址
61
+ @type `Interceptor` - `Request`
62
+ @category `RequestInterceptor`
63
+ */
64
+ export declare function append_url(url: string): RequestInterceptor<never>;
65
+ /** ## `RESTful` : `RESTful`请求 */
66
+ export declare const RESTful: {
67
+ readonly Get: typeof get;
68
+ readonly Post: typeof post;
69
+ readonly Put: typeof put;
70
+ readonly Del: typeof del;
71
+ };
40
72
  //# sourceMappingURL=RESTful.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RESTful.d.ts","sourceRoot":"","sources":["../../../../src/lib/helper/request/RESTful.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAM,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,kBA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AED;;;;;GAKG;AACH,wBAAgB,GAAG,CAClB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAY,EAClB,KAAK,GAAE,WAAgB,GACrB,kBAAkB,CAAC,KAAK,CAAC,CAQ3B;AAED;;;;EAIE;AACF,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAOnF;AAED;;;;EAIE;AACF,wBAAgB,IAAI,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAC1C,kBAAkB,CAAC,KAAK,CAAC,CAW3B;AAED;;;;;;;;;EASE;AACF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKjE;AAED;;;;;;;;;;EAUE;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKzE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAMjE;AAED,kCAAkC;AAClC,eAAO,MAAM,OAAO;;;;;CAKV,CAAA"}
@@ -1,79 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESTful = void 0;
3
4
  exports.post = post;
4
5
  exports.get = get;
5
6
  exports.put = put;
6
7
  exports.del = del;
7
8
  exports.form = form;
8
- const fp_1 = require("@chzky/fp");
9
+ exports.set_body = set_body;
10
+ exports.set_params = set_params;
11
+ exports.append_url = append_url;
12
+ const core_1 = require("@chzky/core");
9
13
  /** ### `post` : post请求
10
- @param url `string` - 请求地址
14
+ @param `string` - 请求地址
11
15
  @param [data={}] `unknown` - 请求数据
12
16
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
13
- @type `Interceptor` - `Request`
14
- @category `Request`
17
+ @category `RequestInterceptor`
15
18
  */
16
19
  function post(url, data = {}, query = {}) {
17
- return (conf) => {
20
+ return conf => {
18
21
  conf.method = 'post';
19
22
  conf.url = url;
20
23
  conf.data = data;
21
24
  conf.params = query;
22
- return (0, fp_1.Ok)();
25
+ return (0, core_1.Ok)();
23
26
  };
24
27
  }
25
28
  /** ### `get` : get请求
26
29
  @param url `string` - 请求地址
27
30
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
28
- @type `Interceptor` - `Request`
29
- @category `Request`
31
+ @category `RequestInterceptor`
30
32
  */
31
33
  function get(url, query = {}) {
32
- return (conf) => {
34
+ return conf => {
33
35
  conf.method = 'get';
34
36
  conf.url = url;
35
37
  conf.params = query;
36
- return (0, fp_1.Ok)();
38
+ return (0, core_1.Ok)();
37
39
  };
38
40
  }
39
41
  /** ### `put` : put请求
40
42
  @param url `string` - 请求地址
41
43
  @param [data={}] `unknown` - 请求数据
42
44
  @param [query={}] `Record<string, unknown>` - URL形式的请求参数
43
- @type `Interceptor` - `Request`
44
- @category `Request`
45
+ @category `RequestInterceptor`
45
46
  */
46
47
  function put(url, data = {}, query = {}) {
47
- return (conf) => {
48
+ return conf => {
48
49
  conf.method = 'put';
49
50
  conf.url = url;
50
51
  conf.data = data;
51
52
  conf.params = query;
52
- return (0, fp_1.Ok)();
53
+ return (0, core_1.Ok)();
53
54
  };
54
55
  }
55
56
  /** ### `del` : delete请求
56
57
  @param url `string` - 请求地址
57
58
  @param [query={}] `Record<string, unknown>` - query形式的请求参数
58
- @type `Interceptor` - `Request`
59
- @category `Request`
59
+ @category `RequestInterceptor`
60
60
  */
61
61
  function del(url, query = {}) {
62
- return (conf) => {
62
+ return conf => {
63
63
  conf.method = 'delete';
64
64
  conf.url = url;
65
65
  conf.params = query;
66
- return (0, fp_1.Ok)();
66
+ return (0, core_1.Ok)();
67
67
  };
68
68
  }
69
69
  /** ### `form` : FormData形式请求
70
70
  @param url `string` - 请求地址
71
71
  @param data `Record<string, string | Blob>` - 请求数据
72
- @type `Interceptor` - `Request`
73
72
  @category `Request`
74
73
  */
75
74
  function form(url, data) {
76
- return (conf) => {
75
+ return conf => {
77
76
  conf.method = 'post';
78
77
  conf.url = url;
79
78
  const fdata = new FormData();
@@ -81,6 +80,61 @@ function form(url, data) {
81
80
  fdata.append(key, value);
82
81
  });
83
82
  conf.data = fdata;
84
- return (0, fp_1.Ok)();
83
+ return (0, core_1.Ok)();
84
+ };
85
+ }
86
+ /** ### `set_body` : 覆盖Body参数
87
+ 该方法会覆盖请求的Body参数
88
+ @example Usage
89
+ ```ts
90
+ const request = post('/api')
91
+ request.use(set_body({ foo: 'bar' })) // Will override request body
92
+ ```
93
+ @param data `unknown` - 请求数据
94
+ @category `RequestInterceptor`
95
+ */
96
+ function set_body(data) {
97
+ return conf => {
98
+ conf.data = data;
99
+ return (0, core_1.Ok)();
100
+ };
101
+ }
102
+ /** ### `set_params` : 覆盖URL参数
103
+ 该方法会覆盖请求的URL参数
104
+ @example Usage
105
+ ```ts
106
+ const request = get('/api')
107
+ request.use(set_params({ foo: 'bar' })) // Will override request params
108
+ ```
109
+ @param params `Record<string, unknown>` - URL形式的请求参数
110
+ @type `Interceptor` - `Request`
111
+ @category `RequestInterceptor`
112
+ */
113
+ function set_params(params) {
114
+ return conf => {
115
+ conf.params = params;
116
+ return (0, core_1.Ok)();
117
+ };
118
+ }
119
+ /** ### `append_url` : URL
120
+ 该方法会将url添加到请求地址的后面;如果没有url,则直接添加
121
+ @param url `string` - 请求地址
122
+ @type `Interceptor` - `Request`
123
+ @category `RequestInterceptor`
124
+ */
125
+ function append_url(url) {
126
+ return conf => {
127
+ if (!conf.url)
128
+ conf.url = url;
129
+ else
130
+ conf.url = `${url}/${conf.url}`.replace(/\/{2,}/g, '/');
131
+ return (0, core_1.Ok)();
85
132
  };
86
133
  }
134
+ /** ## `RESTful` : `RESTful`请求 */
135
+ exports.RESTful = {
136
+ Get: get,
137
+ Post: post,
138
+ Put: put,
139
+ Del: del,
140
+ };
@@ -1,15 +1,22 @@
1
+ import type { PositiveInteger } from '@chzky/core';
1
2
  import type { RequestInterceptor } from '../../../mod.js';
2
3
  import type { AxiosRequestHeaders, ResponseType } from 'axios';
3
4
  /** ## `header` : 修改请求头数据
4
- @param header `AxiosRequestHeaders` - 请求头数据
5
+ @param head `AxiosRequestHeaders` - 请求头数据
5
6
  @type `Interceptor` - `Request`
6
- @category `Request`
7
+ @category Helper
7
8
  */
8
- export declare function header(header: AxiosRequestHeaders): RequestInterceptor<never>;
9
+ export declare function header(head: AxiosRequestHeaders): RequestInterceptor<never>;
9
10
  /** ## `response_type` : 修改响应数据类型
10
11
  @param type `ResponseType` - 响应数据类型
11
12
  @type `Interceptor` - `Request`
12
- @category `Request`
13
+ @category Helper
13
14
  */
14
15
  export declare function response_type(type: ResponseType): RequestInterceptor<never>;
16
+ /** ## `timeout` : 修改请求超时时间
17
+ @param time `PositiveInteger<N>` - 请求超时时间
18
+ @type `Interceptor` - `Request`
19
+ @category Helper
20
+ */
21
+ export declare function timeout<N extends number>(time: PositiveInteger<N>): RequestInterceptor<never>;
15
22
  //# sourceMappingURL=baseConf.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseConf.d.ts","sourceRoot":"","sources":["../../../../src/lib/helper/request/baseConf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAE9D;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK7E;AAED;;;;EAIE;AACF,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK3E"}
1
+ {"version":3,"file":"baseConf.d.ts","sourceRoot":"","sources":["../../../../src/lib/helper/request/baseConf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAI9D;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAO3E;AAED;;;;EAIE;AACF,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK3E;AAED;;;;EAIE;AACF,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK7F"}