@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/index.es.js CHANGED
@@ -1,590 +1,332 @@
1
- import { HttpMethod as p, getFetcher as O, combineURLs as w, JsonResultExtractor as D, mergeRecordToMap as l, mergeRequest as H } from "@ahoo-wang/fetcher";
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
- const T = /* @__PURE__ */ Symbol("endpoint:metadata");
4
- function h(t, e, r = {}) {
5
- return function(n, a) {
6
- const s = {
7
- method: t,
8
- path: e,
9
- ...r
10
- };
11
- Reflect.defineMetadata(
12
- T,
13
- s,
14
- n,
15
- a
16
- );
17
- };
18
- }
19
- function Z(t = "", e = {}) {
20
- return h(p.GET, t, e);
21
- }
22
- function F(t = "", e = {}) {
23
- return h(p.POST, t, e);
24
- }
25
- function tt(t = "", e = {}) {
26
- return h(p.PUT, t, e);
27
- }
28
- function et(t = "", e = {}) {
29
- return h(p.DELETE, t, e);
30
- }
31
- function rt(t = "", e = {}) {
32
- return h(p.PATCH, t, e);
33
- }
34
- function nt(t = "", e = {}) {
35
- return h(p.HEAD, t, e);
36
- }
37
- function at(t = "", e = {}) {
38
- return h(p.OPTIONS, t, e);
39
- }
40
- var b = /* @__PURE__ */ ((t) => (t.EXCHANGE = "Exchange", t.RESULT = "Result", t))(b || {});
41
- const I = "__decorator_target__", U = "__decorator_metadata__";
42
- class C {
43
- /**
44
- * Creates a new RequestExecutor instance.
45
- * @param target - The target object that the method is called on.
46
- * This can contain a custom fetcher instance in its 'fetcher' property.
47
- * @param metadata - The function metadata containing all request information
48
- */
49
- constructor(e, r) {
50
- this.target = e, this.metadata = r;
51
- }
52
- /**
53
- * Executes the HTTP request based on the decorated method metadata.
54
- *
55
- * This method orchestrates the complete HTTP request lifecycle:
56
- * 1. Resolves request configuration from metadata and runtime arguments
57
- * 2. Sets up request attributes for interceptor access
58
- * 3. Creates the FetchExchange object
59
- * 4. Executes lifecycle hooks (beforeExecute)
60
- * 5. Processes the request through the interceptor chain
61
- * 6. Executes lifecycle hooks (afterExecute)
62
- * 7. Extracts and returns the result based on endpoint return type
63
- *
64
- * @param args - The runtime arguments passed to the decorated method.
65
- * These are mapped to request components (path variables, query params, body, etc.)
66
- * based on parameter decorators applied to the method.
67
- * @returns A Promise that resolves to the extracted result. The return type depends on:
68
- * - EndpointReturnType.EXCHANGE: Returns the FetchExchange object directly
69
- * - Otherwise: Returns the result of exchange.extractResult() (e.g., Response, parsed JSON)
70
- * @throws Error if the request fails during execution or if lifecycle hooks/interceptors throw
71
- *
72
- * @example
73
- * ```typescript
74
- * // Given a decorated service method:
75
- * class UserService {
76
- * @get('/users/{id}')
77
- * getUser(@path('id') id: number): Promise<User> {
78
- * // This method body is replaced by the executor at runtime
79
- * }
80
- * }
81
- *
82
- * // When calling:
83
- * const userService = new UserService();
84
- * const user = await userService.getUser(123);
85
- *
86
- * // The execute method will:
87
- * // 1. Resolve the path to '/users/123'
88
- * // 2. Create a GET request
89
- * // 3. Execute the request using the configured fetcher
90
- * // 4. Extract and return the parsed User object
91
- * ```
92
- */
93
- async execute(e) {
94
- const r = this.metadata.fetcher, n = this.metadata.resolveExchangeInit(e);
95
- n.attributes.set(I, this.target), n.attributes.set(
96
- U,
97
- this.metadata
98
- );
99
- const a = this.metadata.resolveResultExtractor(), s = this.metadata.resolveEndpointReturnType(), o = r.resolveExchange(n.request, {
100
- resultExtractor: a,
101
- attributes: n.attributes
102
- }), i = this.target;
103
- return i.beforeExecute && await i.beforeExecute(o), await r.interceptors.exchange(o), i.afterExecute && await i.afterExecute(o), s === b.EXCHANGE ? o : await o.extractResult();
104
- }
105
- }
106
- const m = /* @__PURE__ */ new WeakMap();
107
- function N(t) {
108
- if (typeof t != "function")
109
- throw new TypeError("Expected a function");
110
- if (m.has(t))
111
- return m.get(t);
112
- try {
113
- const e = t.toString().trim(), r = j(e);
114
- if (!S(r)) {
115
- const a = [];
116
- return m.set(t, a), a;
117
- }
118
- const n = k(r);
119
- return m.set(t, n), n;
120
- } catch {
121
- const e = [];
122
- return m.set(t, e), e;
123
- }
124
- }
125
- function Y(t, e, r, n) {
126
- if (n)
127
- return n;
128
- try {
129
- const a = t[e];
130
- if (a && typeof a == "function") {
131
- const s = N(a);
132
- if (r < s.length)
133
- return s[r];
134
- }
135
- } catch {
136
- }
137
- }
138
- function S(t) {
139
- return t != null && t.trim() !== "";
140
- }
141
- function j(t) {
142
- if (t.startsWith("(")) {
143
- const n = A(t, 0);
144
- return n === -1 ? "" : t.substring(1, n);
145
- }
146
- const e = t.indexOf("(");
147
- if (e === -1) return "";
148
- const r = A(t, e);
149
- return r === -1 ? "" : t.substring(e + 1, r);
150
- }
151
- function A(t, e) {
152
- let r = 1;
153
- for (let n = e + 1; n < t.length; n++) {
154
- const a = t[n];
155
- if (a === "(")
156
- r++;
157
- else if (a === ")" && (r--, r === 0))
158
- return n;
159
- }
160
- return -1;
161
- }
162
- function k(t) {
163
- return t.split(",").map(G).filter(v).map(B);
164
- }
165
- function G(t) {
166
- return t.trim();
167
- }
168
- function v(t) {
169
- return t.length > 0;
170
- }
171
- function B(t) {
172
- let e = Q(t);
173
- return e = L(e), e.trim();
174
- }
175
- function Q(t) {
176
- const e = t.indexOf("=");
177
- return e !== -1 ? t.substring(0, e) : t;
178
- }
179
- function L(t) {
180
- const e = t.indexOf(":");
181
- return e !== -1 ? t.substring(0, e) : t;
182
- }
183
- var u = /* @__PURE__ */ ((t) => (t.PATH = "path", t.QUERY = "query", t.HEADER = "header", t.BODY = "body", t.REQUEST = "request", t.ATTRIBUTE = "attribute", t))(u || {});
184
- const P = /* @__PURE__ */ Symbol("parameter:metadata");
185
- function f(t, e = "") {
186
- return function(r, n, a) {
187
- const s = Y(
188
- r,
189
- n,
190
- a,
191
- e
192
- ), o = Reflect.getMetadata(P, r, n) || /* @__PURE__ */ new Map(), i = {
193
- type: t,
194
- name: s,
195
- index: a
196
- };
197
- o.set(a, i), Reflect.defineMetadata(
198
- P,
199
- o,
200
- r,
201
- n
202
- );
203
- };
204
- }
205
- function st(t = "") {
206
- return f("path", t);
207
- }
208
- function ot(t = "") {
209
- return f("query", t);
210
- }
211
- function it(t = "") {
212
- return f("header", t);
213
- }
214
- function ct() {
215
- return f(
216
- "body"
217
- /* BODY */
218
- );
219
- }
220
- function ut() {
221
- return f(
222
- "request"
223
- /* REQUEST */
224
- );
225
- }
226
- function pt(t = "") {
227
- return f("attribute", t);
228
- }
229
- class g {
230
- /**
231
- * Creates a new FunctionMetadata instance.
232
- *
233
- * @param name - The name of the function
234
- * @param api - API-level metadata
235
- * @param endpoint - Endpoint-level metadata
236
- * @param parameters - Parameter metadata array
237
- */
238
- constructor(e, r, n, a) {
239
- this.name = e, this.api = r, this.endpoint = n, this.parameters = a;
240
- }
241
- /**
242
- * Gets the fetcher instance to use for this function.
243
- *
244
- * Returns the fetcher specified in the endpoint metadata, or the API metadata,
245
- * or falls back to the default fetcher if none is specified.
246
- *
247
- * @returns The fetcher instance
248
- */
249
- get fetcher() {
250
- return O(this.endpoint.fetcher ?? this.api.fetcher);
251
- }
252
- /**
253
- * Resolves the complete path by combining base path and endpoint path
254
- *
255
- * @param parameterPath - Optional path parameter to use instead of endpoint path
256
- * @returns The combined URL path
257
- */
258
- resolvePath(e) {
259
- const r = this.endpoint.basePath || this.api.basePath || "", n = e || this.endpoint.path || "";
260
- return w(r, n);
261
- }
262
- /**
263
- * Resolves the timeout for the request.
264
- *
265
- * Returns the timeout specified in the endpoint metadata, or the API metadata,
266
- * or undefined if no timeout is specified.
267
- *
268
- * @returns The timeout value in milliseconds, or undefined
269
- */
270
- resolveTimeout() {
271
- return this.endpoint.timeout || this.api.timeout;
272
- }
273
- /**
274
- * Resolves the result extractor for the request.
275
- *
276
- * Returns the result extractor specified in the endpoint metadata, or the API metadata,
277
- * or falls back to the default JsonResultExtractor if none is specified.
278
- *
279
- * @returns The result extractor function to use for processing responses
280
- */
281
- resolveResultExtractor() {
282
- return this.endpoint.resultExtractor || this.api.resultExtractor || D;
283
- }
284
- /**
285
- * Resolves the attributes for the request.
286
- *
287
- * Merges attributes from API-level and endpoint-level metadata into a single Map.
288
- * API-level attributes are applied first, then endpoint-level attributes can override them.
289
- *
290
- * @returns A Map containing all resolved attributes for the request
291
- */
292
- resolveAttributes() {
293
- const e = l(this.api.attributes);
294
- return l(this.endpoint.attributes, e);
295
- }
296
- /**
297
- * Resolves the endpoint return type for the request.
298
- *
299
- * Returns the return type specified in the endpoint metadata, or the API metadata,
300
- * or falls back to EndpointReturnType.RESULT if none is specified.
301
- *
302
- * @returns The endpoint return type determining what the method should return
303
- */
304
- resolveEndpointReturnType() {
305
- return this.endpoint.returnType || this.api.returnType || b.RESULT;
306
- }
307
- /**
308
- * Resolves the request configuration from the method arguments.
309
- *
310
- * This method processes the runtime arguments according to the parameter metadata
311
- * and constructs a FetcherRequest object with path parameters, query parameters,
312
- * headers, body, and timeout. It handles various parameter types including:
313
- * - Path parameters (@path decorator)
314
- * - Query parameters (@query decorator)
315
- * - Header parameters (@header decorator)
316
- * - Body parameter (@body decorator)
317
- * - Complete request object (@request decorator)
318
- * - AbortSignal for request cancellation
319
- *
320
- * The method uses mergeRequest to combine the endpoint-specific configuration
321
- * with the parameter-provided request object, where the parameter request
322
- * takes precedence over endpoint configuration.
323
- *
324
- * @param args - The runtime arguments passed to the method
325
- * @returns A FetcherRequest object with all request configuration
326
- *
327
- * @example
328
- * ```typescript
329
- * // For a method decorated like:
330
- * @get('/users/{id}')
331
- * getUser(
332
- * @path('id') id: number,
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