@ahoo-wang/fetcher-decorator 3.13.14 → 3.15.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/dist/apiDecorator.d.ts +1 -1
- package/dist/apiDecorator.d.ts.map +1 -1
- package/dist/executeLifeCycle.d.ts.map +1 -1
- package/dist/functionMetadata.d.ts +1 -1
- package/dist/functionMetadata.d.ts.map +1 -1
- package/dist/index.es.js +331 -589
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/parameterDecorator.d.ts +1 -1
- package/dist/parameterDecorator.d.ts.map +1 -1
- package/dist/requestExecutor.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.es.js
CHANGED
|
@@ -1,590 +1,332 @@
|
|
|
1
|
-
import { HttpMethod as
|
|
1
|
+
import { HttpMethod as e, JsonResultExtractor as t, combineURLs as n, getFetcher as r, mergeRecordToMap as i, mergeRequest as a } from "@ahoo-wang/fetcher";
|
|
2
2
|
import "reflect-metadata";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
* @query('include') include: string,
|
|
334
|
-
* @header('Authorization') auth: string
|
|
335
|
-
* ): Promise<Response>
|
|
336
|
-
*
|
|
337
|
-
* // Calling with: getUser(123, 'profile', 'Bearer token')
|
|
338
|
-
* // Would produce a request with:
|
|
339
|
-
* // {
|
|
340
|
-
* // method: 'GET',
|
|
341
|
-
* // urlParams: {
|
|
342
|
-
* // path: { id: 123 },
|
|
343
|
-
* // query: { include: 'profile' }
|
|
344
|
-
* // },
|
|
345
|
-
* // headers: {
|
|
346
|
-
* // 'Authorization': 'Bearer token',
|
|
347
|
-
* // ...apiHeaders,
|
|
348
|
-
* // ...endpointHeaders
|
|
349
|
-
* // }
|
|
350
|
-
* // }
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
resolveExchangeInit(e) {
|
|
354
|
-
const r = {
|
|
355
|
-
...this.api.urlParams?.path,
|
|
356
|
-
...this.endpoint.urlParams?.path
|
|
357
|
-
}, n = {
|
|
358
|
-
...this.api.urlParams?.query,
|
|
359
|
-
...this.endpoint.urlParams?.query
|
|
360
|
-
}, a = {
|
|
361
|
-
...this.api.headers,
|
|
362
|
-
...this.endpoint.headers
|
|
363
|
-
};
|
|
364
|
-
let s, o, i, E = {};
|
|
365
|
-
const x = this.resolveAttributes();
|
|
366
|
-
e.forEach((c, _) => {
|
|
367
|
-
if (c instanceof AbortSignal) {
|
|
368
|
-
o = c;
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
if (c instanceof AbortController) {
|
|
372
|
-
i = c;
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const d = this.parameters.get(_);
|
|
376
|
-
if (d)
|
|
377
|
-
switch (d.type) {
|
|
378
|
-
case u.PATH:
|
|
379
|
-
this.processPathParam(d, c, r);
|
|
380
|
-
break;
|
|
381
|
-
case u.QUERY:
|
|
382
|
-
this.processQueryParam(d, c, n);
|
|
383
|
-
break;
|
|
384
|
-
case u.HEADER:
|
|
385
|
-
this.processHeaderParam(d, c, a);
|
|
386
|
-
break;
|
|
387
|
-
case u.BODY:
|
|
388
|
-
s = c;
|
|
389
|
-
break;
|
|
390
|
-
case u.REQUEST:
|
|
391
|
-
E = this.processRequestParam(c);
|
|
392
|
-
break;
|
|
393
|
-
case u.ATTRIBUTE:
|
|
394
|
-
this.processAttributeParam(d, c, x);
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
const y = {
|
|
399
|
-
path: r,
|
|
400
|
-
query: n
|
|
401
|
-
}, q = {
|
|
402
|
-
method: this.endpoint.method,
|
|
403
|
-
urlParams: y,
|
|
404
|
-
headers: a,
|
|
405
|
-
body: s,
|
|
406
|
-
timeout: this.resolveTimeout(),
|
|
407
|
-
signal: o,
|
|
408
|
-
abortController: i
|
|
409
|
-
}, R = H(
|
|
410
|
-
q,
|
|
411
|
-
E
|
|
412
|
-
), M = E.path;
|
|
413
|
-
return R.url = this.resolvePath(M), {
|
|
414
|
-
request: R,
|
|
415
|
-
attributes: x
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
processHttpParam(e, r, n) {
|
|
419
|
-
if (r == null)
|
|
420
|
-
return;
|
|
421
|
-
if (typeof r == "object") {
|
|
422
|
-
Object.entries(r).forEach(([s, o]) => {
|
|
423
|
-
n[s] = o;
|
|
424
|
-
});
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const a = e.name || `param${e.index}`;
|
|
428
|
-
n[a] = r;
|
|
429
|
-
}
|
|
430
|
-
processPathParam(e, r, n) {
|
|
431
|
-
this.processHttpParam(e, r, n);
|
|
432
|
-
}
|
|
433
|
-
processQueryParam(e, r, n) {
|
|
434
|
-
this.processHttpParam(e, r, n);
|
|
435
|
-
}
|
|
436
|
-
processHeaderParam(e, r, n) {
|
|
437
|
-
this.processHttpParam(e, r, n);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Processes a request parameter value.
|
|
441
|
-
*
|
|
442
|
-
* This method handles the @request() decorator parameter by casting
|
|
443
|
-
* the provided value to a FetcherRequest. The @request() decorator
|
|
444
|
-
* allows users to pass a complete FetcherRequest object to customize
|
|
445
|
-
* the request configuration.
|
|
446
|
-
*
|
|
447
|
-
* @param value - The value provided for the @request() parameter
|
|
448
|
-
* @returns The value cast to FetcherRequest type
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* ```typescript
|
|
452
|
-
* @post('/users')
|
|
453
|
-
* createUsers(@request() request: FetcherRequest): Promise<Response>
|
|
454
|
-
*
|
|
455
|
-
* // Usage:
|
|
456
|
-
* const customRequest: FetcherRequest = {
|
|
457
|
-
* headers: { 'X-Custom': 'value' },
|
|
458
|
-
* timeout: 5000
|
|
459
|
-
* };
|
|
460
|
-
* await service.createUsers(customRequest);
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
|
-
processRequestParam(e) {
|
|
464
|
-
if (!e)
|
|
465
|
-
return {};
|
|
466
|
-
const r = e;
|
|
467
|
-
return {
|
|
468
|
-
...r,
|
|
469
|
-
headers: r.headers || {},
|
|
470
|
-
urlParams: r.urlParams || { path: {}, query: {} }
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
processAttributeParam(e, r, n) {
|
|
474
|
-
if (typeof r == "object" || r instanceof Map) {
|
|
475
|
-
l(r, n);
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
e.name && r !== void 0 && n.set(e.name, r);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
const K = /* @__PURE__ */ Symbol("api:metadata");
|
|
482
|
-
function W(t, e, r) {
|
|
483
|
-
const n = t.prototype[e];
|
|
484
|
-
if (e === "constructor" || typeof n != "function")
|
|
485
|
-
return;
|
|
486
|
-
const a = Reflect.getMetadata(
|
|
487
|
-
T,
|
|
488
|
-
t.prototype,
|
|
489
|
-
e
|
|
490
|
-
);
|
|
491
|
-
if (!a)
|
|
492
|
-
return;
|
|
493
|
-
const s = Reflect.getMetadata(
|
|
494
|
-
P,
|
|
495
|
-
t.prototype,
|
|
496
|
-
e
|
|
497
|
-
) || /* @__PURE__ */ new Map(), o = new g(
|
|
498
|
-
e,
|
|
499
|
-
r,
|
|
500
|
-
a,
|
|
501
|
-
s
|
|
502
|
-
);
|
|
503
|
-
t.prototype[e] = async function(...i) {
|
|
504
|
-
return await X(
|
|
505
|
-
this,
|
|
506
|
-
o
|
|
507
|
-
).execute(i);
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
function X(t, e) {
|
|
511
|
-
let r = t.requestExecutors;
|
|
512
|
-
r || (r = /* @__PURE__ */ new Map(), t.requestExecutors = r);
|
|
513
|
-
let n = r.get(e.name);
|
|
514
|
-
if (n)
|
|
515
|
-
return n;
|
|
516
|
-
const a = t.apiMetadata, s = {
|
|
517
|
-
...e.api,
|
|
518
|
-
...a
|
|
519
|
-
};
|
|
520
|
-
return n = new C(
|
|
521
|
-
t,
|
|
522
|
-
new g(
|
|
523
|
-
e.name,
|
|
524
|
-
s,
|
|
525
|
-
e.endpoint,
|
|
526
|
-
e.parameters
|
|
527
|
-
)
|
|
528
|
-
), r.set(e.name, n), n;
|
|
529
|
-
}
|
|
530
|
-
function ht(t = "", e = {}) {
|
|
531
|
-
return function(r) {
|
|
532
|
-
const n = {
|
|
533
|
-
basePath: t,
|
|
534
|
-
...e
|
|
535
|
-
};
|
|
536
|
-
return Reflect.defineMetadata(K, n, r), J(r, n), r;
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
function J(t, e) {
|
|
540
|
-
const r = /* @__PURE__ */ new Set();
|
|
541
|
-
let n = t.prototype;
|
|
542
|
-
for (; n && n !== Object.prototype; ) {
|
|
543
|
-
if (r.has(n)) {
|
|
544
|
-
n = Object.getPrototypeOf(n);
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
r.add(n), Object.getOwnPropertyNames(n).forEach((a) => {
|
|
548
|
-
W(t, a, e);
|
|
549
|
-
}), n = Object.getPrototypeOf(n);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
class V extends Error {
|
|
553
|
-
constructor() {
|
|
554
|
-
super("Implementation will be generated automatically."), this.name = "AutoGenerated";
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
const dt = (...t) => new V();
|
|
558
|
-
export {
|
|
559
|
-
K as API_METADATA_KEY,
|
|
560
|
-
V as AutoGenerated,
|
|
561
|
-
U as DECORATOR_METADATA_ATTRIBUTE_KEY,
|
|
562
|
-
I as DECORATOR_TARGET_ATTRIBUTE_KEY,
|
|
563
|
-
T as ENDPOINT_METADATA_KEY,
|
|
564
|
-
b as EndpointReturnType,
|
|
565
|
-
g as FunctionMetadata,
|
|
566
|
-
P as PARAMETER_METADATA_KEY,
|
|
567
|
-
u as ParameterType,
|
|
568
|
-
C as RequestExecutor,
|
|
569
|
-
ht as api,
|
|
570
|
-
pt as attribute,
|
|
571
|
-
dt as autoGeneratedError,
|
|
572
|
-
ct as body,
|
|
573
|
-
X as buildRequestExecutor,
|
|
574
|
-
et as del,
|
|
575
|
-
h as endpoint,
|
|
576
|
-
Z as get,
|
|
577
|
-
Y as getParameterName,
|
|
578
|
-
N as getParameterNames,
|
|
579
|
-
nt as head,
|
|
580
|
-
it as header,
|
|
581
|
-
at as options,
|
|
582
|
-
f as parameter,
|
|
583
|
-
rt as patch,
|
|
584
|
-
st as path,
|
|
585
|
-
F as post,
|
|
586
|
-
tt as put,
|
|
587
|
-
ot as query,
|
|
588
|
-
ut as request
|
|
589
|
-
};
|
|
590
|
-
//# sourceMappingURL=index.es.js.map
|
|
3
|
+
//#region src/endpointDecorator.ts
|
|
4
|
+
var o = Symbol("endpoint:metadata");
|
|
5
|
+
function s(e, t, n = {}) {
|
|
6
|
+
return function(r, i) {
|
|
7
|
+
let a = {
|
|
8
|
+
method: e,
|
|
9
|
+
path: t,
|
|
10
|
+
...n
|
|
11
|
+
};
|
|
12
|
+
Reflect.defineMetadata(o, a, r, i);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function c(t = "", n = {}) {
|
|
16
|
+
return s(e.GET, t, n);
|
|
17
|
+
}
|
|
18
|
+
function l(t = "", n = {}) {
|
|
19
|
+
return s(e.POST, t, n);
|
|
20
|
+
}
|
|
21
|
+
function u(t = "", n = {}) {
|
|
22
|
+
return s(e.PUT, t, n);
|
|
23
|
+
}
|
|
24
|
+
function d(t = "", n = {}) {
|
|
25
|
+
return s(e.DELETE, t, n);
|
|
26
|
+
}
|
|
27
|
+
function f(t = "", n = {}) {
|
|
28
|
+
return s(e.PATCH, t, n);
|
|
29
|
+
}
|
|
30
|
+
function p(t = "", n = {}) {
|
|
31
|
+
return s(e.HEAD, t, n);
|
|
32
|
+
}
|
|
33
|
+
function m(t = "", n = {}) {
|
|
34
|
+
return s(e.OPTIONS, t, n);
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/endpointReturnTypeCapable.ts
|
|
38
|
+
var h = /* @__PURE__ */ function(e) {
|
|
39
|
+
return e.EXCHANGE = "Exchange", e.RESULT = "Result", e;
|
|
40
|
+
}({}), g = "__decorator_target__", _ = "__decorator_metadata__", v = class {
|
|
41
|
+
constructor(e, t) {
|
|
42
|
+
this.target = e, this.metadata = t;
|
|
43
|
+
}
|
|
44
|
+
async execute(e) {
|
|
45
|
+
let t = this.metadata.fetcher, n = this.metadata.resolveExchangeInit(e);
|
|
46
|
+
n.attributes.set(g, this.target), n.attributes.set(_, this.metadata);
|
|
47
|
+
let r = this.metadata.resolveResultExtractor(), i = this.metadata.resolveEndpointReturnType(), a = t.resolveExchange(n.request, {
|
|
48
|
+
resultExtractor: r,
|
|
49
|
+
attributes: n.attributes
|
|
50
|
+
}), o = this.target;
|
|
51
|
+
return o.beforeExecute && await o.beforeExecute(a), await t.interceptors.exchange(a), o.afterExecute && await o.afterExecute(a), i === h.EXCHANGE ? a : await a.extractResult();
|
|
52
|
+
}
|
|
53
|
+
}, y = /* @__PURE__ */ new WeakMap();
|
|
54
|
+
function b(e) {
|
|
55
|
+
if (typeof e != "function") throw TypeError("Expected a function");
|
|
56
|
+
if (y.has(e)) return y.get(e);
|
|
57
|
+
try {
|
|
58
|
+
let t = C(e.toString().trim());
|
|
59
|
+
if (!S(t)) {
|
|
60
|
+
let t = [];
|
|
61
|
+
return y.set(e, t), t;
|
|
62
|
+
}
|
|
63
|
+
let n = T(t);
|
|
64
|
+
return y.set(e, n), n;
|
|
65
|
+
} catch {
|
|
66
|
+
let t = [];
|
|
67
|
+
return y.set(e, t), t;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function x(e, t, n, r) {
|
|
71
|
+
if (r) return r;
|
|
72
|
+
try {
|
|
73
|
+
let r = e[t];
|
|
74
|
+
if (r && typeof r == "function") {
|
|
75
|
+
let e = b(r);
|
|
76
|
+
if (n < e.length) return e[n];
|
|
77
|
+
}
|
|
78
|
+
} catch {}
|
|
79
|
+
}
|
|
80
|
+
function S(e) {
|
|
81
|
+
return e != null && e.trim() !== "";
|
|
82
|
+
}
|
|
83
|
+
function C(e) {
|
|
84
|
+
if (e.startsWith("(")) {
|
|
85
|
+
let t = w(e, 0);
|
|
86
|
+
return t === -1 ? "" : e.substring(1, t);
|
|
87
|
+
}
|
|
88
|
+
let t = e.indexOf("(");
|
|
89
|
+
if (t === -1) return "";
|
|
90
|
+
let n = w(e, t);
|
|
91
|
+
return n === -1 ? "" : e.substring(t + 1, n);
|
|
92
|
+
}
|
|
93
|
+
function w(e, t) {
|
|
94
|
+
let n = 1;
|
|
95
|
+
for (let r = t + 1; r < e.length; r++) {
|
|
96
|
+
let t = e[r];
|
|
97
|
+
if (t === "(") n++;
|
|
98
|
+
else if (t === ")" && (n--, n === 0)) return r;
|
|
99
|
+
}
|
|
100
|
+
return -1;
|
|
101
|
+
}
|
|
102
|
+
function T(e) {
|
|
103
|
+
return e.split(",").map(E).filter(D).map(O);
|
|
104
|
+
}
|
|
105
|
+
function E(e) {
|
|
106
|
+
return e.trim();
|
|
107
|
+
}
|
|
108
|
+
function D(e) {
|
|
109
|
+
return e.length > 0;
|
|
110
|
+
}
|
|
111
|
+
function O(e) {
|
|
112
|
+
let t = k(e);
|
|
113
|
+
return t = A(t), t.trim();
|
|
114
|
+
}
|
|
115
|
+
function k(e) {
|
|
116
|
+
let t = e.indexOf("=");
|
|
117
|
+
return t === -1 ? e : e.substring(0, t);
|
|
118
|
+
}
|
|
119
|
+
function A(e) {
|
|
120
|
+
let t = e.indexOf(":");
|
|
121
|
+
return t === -1 ? e : e.substring(0, t);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/parameterDecorator.ts
|
|
125
|
+
var j = /* @__PURE__ */ function(e) {
|
|
126
|
+
return e.PATH = "path", e.QUERY = "query", e.HEADER = "header", e.BODY = "body", e.REQUEST = "request", e.ATTRIBUTE = "attribute", e;
|
|
127
|
+
}({}), M = Symbol("parameter:metadata");
|
|
128
|
+
function N(e, t = "") {
|
|
129
|
+
return function(n, r, i) {
|
|
130
|
+
let a = x(n, r, i, t), o = Reflect.getMetadata(M, n, r) || /* @__PURE__ */ new Map(), s = {
|
|
131
|
+
type: e,
|
|
132
|
+
name: a,
|
|
133
|
+
index: i
|
|
134
|
+
};
|
|
135
|
+
o.set(i, s), Reflect.defineMetadata(M, o, n, r);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function P(e = "") {
|
|
139
|
+
return N(j.PATH, e);
|
|
140
|
+
}
|
|
141
|
+
function F(e = "") {
|
|
142
|
+
return N(j.QUERY, e);
|
|
143
|
+
}
|
|
144
|
+
function I(e = "") {
|
|
145
|
+
return N(j.HEADER, e);
|
|
146
|
+
}
|
|
147
|
+
function L() {
|
|
148
|
+
return N(j.BODY);
|
|
149
|
+
}
|
|
150
|
+
function R() {
|
|
151
|
+
return N(j.REQUEST);
|
|
152
|
+
}
|
|
153
|
+
function z(e = "") {
|
|
154
|
+
return N(j.ATTRIBUTE, e);
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/functionMetadata.ts
|
|
158
|
+
var B = class {
|
|
159
|
+
constructor(e, t, n, r) {
|
|
160
|
+
this.name = e, this.api = t, this.endpoint = n, this.parameters = r;
|
|
161
|
+
}
|
|
162
|
+
get fetcher() {
|
|
163
|
+
return r(this.endpoint.fetcher ?? this.api.fetcher);
|
|
164
|
+
}
|
|
165
|
+
resolvePath(e) {
|
|
166
|
+
return n(this.endpoint.basePath || this.api.basePath || "", e || this.endpoint.path || "");
|
|
167
|
+
}
|
|
168
|
+
resolveTimeout() {
|
|
169
|
+
return this.endpoint.timeout || this.api.timeout;
|
|
170
|
+
}
|
|
171
|
+
resolveResultExtractor() {
|
|
172
|
+
return this.endpoint.resultExtractor || this.api.resultExtractor || t;
|
|
173
|
+
}
|
|
174
|
+
resolveAttributes() {
|
|
175
|
+
let e = i(this.api.attributes);
|
|
176
|
+
return i(this.endpoint.attributes, e);
|
|
177
|
+
}
|
|
178
|
+
resolveEndpointReturnType() {
|
|
179
|
+
return this.endpoint.returnType || this.api.returnType || h.RESULT;
|
|
180
|
+
}
|
|
181
|
+
resolveExchangeInit(e) {
|
|
182
|
+
let t = {
|
|
183
|
+
...this.api.urlParams?.path,
|
|
184
|
+
...this.endpoint.urlParams?.path
|
|
185
|
+
}, n = {
|
|
186
|
+
...this.api.urlParams?.query,
|
|
187
|
+
...this.endpoint.urlParams?.query
|
|
188
|
+
}, r = {
|
|
189
|
+
...this.api.headers,
|
|
190
|
+
...this.endpoint.headers
|
|
191
|
+
}, i, o, s, c = {}, l = this.resolveAttributes();
|
|
192
|
+
e.forEach((e, a) => {
|
|
193
|
+
if (e instanceof AbortSignal) {
|
|
194
|
+
o = e;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (e instanceof AbortController) {
|
|
198
|
+
s = e;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
let u = this.parameters.get(a);
|
|
202
|
+
if (u) switch (u.type) {
|
|
203
|
+
case j.PATH:
|
|
204
|
+
this.processPathParam(u, e, t);
|
|
205
|
+
break;
|
|
206
|
+
case j.QUERY:
|
|
207
|
+
this.processQueryParam(u, e, n);
|
|
208
|
+
break;
|
|
209
|
+
case j.HEADER:
|
|
210
|
+
this.processHeaderParam(u, e, r);
|
|
211
|
+
break;
|
|
212
|
+
case j.BODY:
|
|
213
|
+
i = e;
|
|
214
|
+
break;
|
|
215
|
+
case j.REQUEST:
|
|
216
|
+
c = this.processRequestParam(e);
|
|
217
|
+
break;
|
|
218
|
+
case j.ATTRIBUTE:
|
|
219
|
+
this.processAttributeParam(u, e, l);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
let u = {
|
|
224
|
+
path: t,
|
|
225
|
+
query: n
|
|
226
|
+
}, d = a({
|
|
227
|
+
method: this.endpoint.method,
|
|
228
|
+
urlParams: u,
|
|
229
|
+
headers: r,
|
|
230
|
+
body: i,
|
|
231
|
+
timeout: this.resolveTimeout(),
|
|
232
|
+
signal: o,
|
|
233
|
+
abortController: s
|
|
234
|
+
}, c), f = c.path;
|
|
235
|
+
return d.url = this.resolvePath(f), {
|
|
236
|
+
request: d,
|
|
237
|
+
attributes: l
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
processHttpParam(e, t, n) {
|
|
241
|
+
if (t == null) return;
|
|
242
|
+
if (typeof t == "object") {
|
|
243
|
+
Object.entries(t).forEach(([e, t]) => {
|
|
244
|
+
n[e] = t;
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
let r = e.name || `param${e.index}`;
|
|
249
|
+
n[r] = t;
|
|
250
|
+
}
|
|
251
|
+
processPathParam(e, t, n) {
|
|
252
|
+
this.processHttpParam(e, t, n);
|
|
253
|
+
}
|
|
254
|
+
processQueryParam(e, t, n) {
|
|
255
|
+
this.processHttpParam(e, t, n);
|
|
256
|
+
}
|
|
257
|
+
processHeaderParam(e, t, n) {
|
|
258
|
+
this.processHttpParam(e, t, n);
|
|
259
|
+
}
|
|
260
|
+
processRequestParam(e) {
|
|
261
|
+
if (!e) return {};
|
|
262
|
+
let t = e;
|
|
263
|
+
return {
|
|
264
|
+
...t,
|
|
265
|
+
headers: t.headers || {},
|
|
266
|
+
urlParams: t.urlParams || {
|
|
267
|
+
path: {},
|
|
268
|
+
query: {}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
processAttributeParam(e, t, n) {
|
|
273
|
+
if (typeof t == "object" || t instanceof Map) {
|
|
274
|
+
i(t, n);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
e.name && t !== void 0 && n.set(e.name, t);
|
|
278
|
+
}
|
|
279
|
+
}, V = Symbol("api:metadata");
|
|
280
|
+
function H(e, t, n) {
|
|
281
|
+
let r = e.prototype[t];
|
|
282
|
+
if (t === "constructor" || typeof r != "function") return;
|
|
283
|
+
let i = Reflect.getMetadata(o, e.prototype, t);
|
|
284
|
+
if (!i) return;
|
|
285
|
+
let a = new B(t, n, i, Reflect.getMetadata(M, e.prototype, t) || /* @__PURE__ */ new Map());
|
|
286
|
+
e.prototype[t] = async function(...e) {
|
|
287
|
+
return await U(this, a).execute(e);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function U(e, t) {
|
|
291
|
+
let n = e.requestExecutors;
|
|
292
|
+
n || (n = /* @__PURE__ */ new Map(), e.requestExecutors = n);
|
|
293
|
+
let r = n.get(t.name);
|
|
294
|
+
if (r) return r;
|
|
295
|
+
let i = e.apiMetadata, a = {
|
|
296
|
+
...t.api,
|
|
297
|
+
...i
|
|
298
|
+
};
|
|
299
|
+
return r = new v(e, new B(t.name, a, t.endpoint, t.parameters)), n.set(t.name, r), r;
|
|
300
|
+
}
|
|
301
|
+
function W(e = "", t = {}) {
|
|
302
|
+
return function(n) {
|
|
303
|
+
let r = {
|
|
304
|
+
basePath: e,
|
|
305
|
+
...t
|
|
306
|
+
};
|
|
307
|
+
return Reflect.defineMetadata(V, r, n), G(n, r), n;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function G(e, t) {
|
|
311
|
+
let n = /* @__PURE__ */ new Set(), r = e.prototype;
|
|
312
|
+
for (; r && r !== Object.prototype;) {
|
|
313
|
+
if (n.has(r)) {
|
|
314
|
+
r = Object.getPrototypeOf(r);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
n.add(r), Object.getOwnPropertyNames(r).forEach((n) => {
|
|
318
|
+
H(e, n, t);
|
|
319
|
+
}), r = Object.getPrototypeOf(r);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/generated.ts
|
|
324
|
+
var K = class extends Error {
|
|
325
|
+
constructor() {
|
|
326
|
+
super("Implementation will be generated automatically."), this.name = "AutoGenerated";
|
|
327
|
+
}
|
|
328
|
+
}, q = (...e) => new K();
|
|
329
|
+
//#endregion
|
|
330
|
+
export { V as API_METADATA_KEY, K as AutoGenerated, _ as DECORATOR_METADATA_ATTRIBUTE_KEY, g as DECORATOR_TARGET_ATTRIBUTE_KEY, o as ENDPOINT_METADATA_KEY, h as EndpointReturnType, B as FunctionMetadata, M as PARAMETER_METADATA_KEY, j as ParameterType, v as RequestExecutor, W as api, z as attribute, q as autoGeneratedError, L as body, U as buildRequestExecutor, d as del, s as endpoint, c as get, x as getParameterName, b as getParameterNames, p as head, I as header, m as options, N as parameter, f as patch, P as path, l as post, u as put, F as query, R as request };
|
|
331
|
+
|
|
332
|
+
//# sourceMappingURL=index.es.js.map
|