@ahoo-wang/fetcher-decorator 1.5.0 → 1.5.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.
@@ -1,4 +1,4 @@
1
- import { Fetcher, RequestHeaders, RequestHeadersCapable, TimeoutCapable } from '@ahoo-wang/fetcher';
1
+ import { AttributesCapable, Fetcher, RequestHeaders, RequestHeadersCapable, TimeoutCapable } from '@ahoo-wang/fetcher';
2
2
  import { ResultExtractorCapable } from './resultExtractor';
3
3
  import { FetcherCapable } from './fetcherCapable';
4
4
  /**
@@ -8,7 +8,7 @@ import { FetcherCapable } from './fetcherCapable';
8
8
  * These settings will be used as defaults for all endpoints within the class unless overridden
9
9
  * at the method level.
10
10
  */
11
- export interface ApiMetadata extends TimeoutCapable, RequestHeadersCapable, ResultExtractorCapable, FetcherCapable {
11
+ export interface ApiMetadata extends TimeoutCapable, RequestHeadersCapable, ResultExtractorCapable, FetcherCapable, AttributesCapable {
12
12
  /**
13
13
  * Base path for all endpoints in the class.
14
14
  *
@@ -1 +1 @@
1
- {"version":3,"file":"apiDecorator.d.ts","sourceRoot":"","sources":["../src/apiDecorator.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,WACf,SAAQ,cAAc,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,cAAc;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IAEzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE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,EAAE,aAAa,CAAC,KAAG,CAAC,CAgB3E"}
@@ -0,0 +1,151 @@
1
+ import { Fetcher, FetchExchangeInit, NamedCapable, ResultExtractor } from '@ahoo-wang/fetcher';
2
+ import { ApiMetadata } from './apiDecorator';
3
+ import { EndpointMetadata } from './endpointDecorator';
4
+ import { ParameterMetadata } from './parameterDecorator';
5
+ /**
6
+ * Metadata container for a function with HTTP endpoint decorators.
7
+ *
8
+ * Encapsulates all the metadata needed to execute an HTTP request
9
+ * for a decorated method, including API-level defaults, endpoint-specific
10
+ * configuration, and parameter metadata.
11
+ */
12
+ export declare class FunctionMetadata implements NamedCapable {
13
+ /**
14
+ * Name of the function.
15
+ */
16
+ name: string;
17
+ /**
18
+ * API-level metadata (class-level configuration).
19
+ */
20
+ api: ApiMetadata;
21
+ /**
22
+ * Endpoint-level metadata (method-level configuration).
23
+ */
24
+ endpoint: EndpointMetadata;
25
+ /**
26
+ * Metadata for method parameters.
27
+ *
28
+ * Defines the metadata stored for each parameter decorated with @path, @query,
29
+ * @header, or @body decorators. Stored as a Map keyed by parameter index.
30
+ *
31
+ * @remarks
32
+ * The metadata is stored as a Map<number, ParameterMetadata> where the key is
33
+ * the parameter index and the value is the parameter metadata. This ensures
34
+ * correct parameter ordering regardless of decorator application order.
35
+ */
36
+ parameters: Map<number, ParameterMetadata>;
37
+ /**
38
+ * Creates a new FunctionMetadata instance.
39
+ *
40
+ * @param name - The name of the function
41
+ * @param api - API-level metadata
42
+ * @param endpoint - Endpoint-level metadata
43
+ * @param parameters - Parameter metadata array
44
+ */
45
+ constructor(name: string, api: ApiMetadata, endpoint: EndpointMetadata, parameters: Map<number, ParameterMetadata>);
46
+ /**
47
+ * Gets the fetcher instance to use for this function.
48
+ *
49
+ * Returns the fetcher specified in the endpoint metadata, or the API metadata,
50
+ * or falls back to the default fetcher if none is specified.
51
+ *
52
+ * @returns The fetcher instance
53
+ */
54
+ get fetcher(): Fetcher;
55
+ /**
56
+ * Resolves the complete path by combining base path and endpoint path
57
+ *
58
+ * @param parameterPath - Optional path parameter to use instead of endpoint path
59
+ * @returns The combined URL path
60
+ */
61
+ resolvePath(parameterPath?: string): string;
62
+ /**
63
+ * Resolves the timeout for the request.
64
+ *
65
+ * Returns the timeout specified in the endpoint metadata, or the API metadata,
66
+ * or undefined if no timeout is specified.
67
+ *
68
+ * @returns The timeout value in milliseconds, or undefined
69
+ */
70
+ resolveTimeout(): number | undefined;
71
+ resolveResultExtractor(): ResultExtractor<any>;
72
+ resolveAttributes(): Record<string, any>;
73
+ /**
74
+ * Resolves the request configuration from the method arguments.
75
+ *
76
+ * This method processes the runtime arguments according to the parameter metadata
77
+ * and constructs a FetcherRequest object with path parameters, query parameters,
78
+ * headers, body, and timeout. It handles various parameter types including:
79
+ * - Path parameters (@path decorator)
80
+ * - Query parameters (@query decorator)
81
+ * - Header parameters (@header decorator)
82
+ * - Body parameter (@body decorator)
83
+ * - Complete request object (@request decorator)
84
+ * - AbortSignal for request cancellation
85
+ *
86
+ * The method uses mergeRequest to combine the endpoint-specific configuration
87
+ * with the parameter-provided request object, where the parameter request
88
+ * takes precedence over endpoint configuration.
89
+ *
90
+ * @param args - The runtime arguments passed to the method
91
+ * @returns A FetcherRequest object with all request configuration
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // For a method decorated like:
96
+ * @get('/users/{id}')
97
+ * getUser(
98
+ * @path('id') id: number,
99
+ * @query('include') include: string,
100
+ * @header('Authorization') auth: string
101
+ * ): Promise<Response>
102
+ *
103
+ * // Calling with: getUser(123, 'profile', 'Bearer token')
104
+ * // Would produce a request with:
105
+ * // {
106
+ * // method: 'GET',
107
+ * // urlParams: {
108
+ * // path: { id: 123 },
109
+ * // query: { include: 'profile' }
110
+ * // },
111
+ * // headers: {
112
+ * // 'Authorization': 'Bearer token',
113
+ * // ...apiHeaders,
114
+ * // ...endpointHeaders
115
+ * // }
116
+ * // }
117
+ * ```
118
+ */
119
+ resolveExchangeInit(args: any[]): Required<Pick<FetchExchangeInit, 'request' | 'attributes'>>;
120
+ private processPathParam;
121
+ private processQueryParam;
122
+ private processHeaderParam;
123
+ /**
124
+ * Processes a request parameter value.
125
+ *
126
+ * This method handles the @request() decorator parameter by casting
127
+ * the provided value to a FetcherRequest. The @request() decorator
128
+ * allows users to pass a complete FetcherRequest object to customize
129
+ * the request configuration.
130
+ *
131
+ * @param value - The value provided for the @request() parameter
132
+ * @returns The value cast to FetcherRequest type
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * @post('/users')
137
+ * createUsers(@request() request: FetcherRequest): Promise<Response>
138
+ *
139
+ * // Usage:
140
+ * const customRequest: FetcherRequest = {
141
+ * headers: { 'X-Custom': 'value' },
142
+ * timeout: 5000
143
+ * };
144
+ * await service.createUsers(customRequest);
145
+ * ```
146
+ */
147
+ private processRequestParam;
148
+ private processAttributeParam;
149
+ private processAttributesParam;
150
+ }
151
+ //# sourceMappingURL=functionMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functionMetadata.d.ts","sourceRoot":"","sources":["../src/functionMetadata.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,OAAO,EACP,KAAK,iBAAiB,EAGtB,YAAY,EAEZ,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAmC,MAAM,sBAAsB,CAAC;AAI1F;;;;;;GAMG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,EAAE,WAAW,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAE3B;;;;;;;;;;OAUG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAE3C;;;;;;;OAOG;gBAED,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAQ5C;;;;;;;OAOG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;OAKG;IACH,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM;IAW3C;;;;;;;OAOG;IACH,cAAc,IAAI,MAAM,GAAG,SAAS;IAIpC,sBAAsB,IAAI,eAAe,CAAC,GAAG,CAAC;IAQ9C,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC;IA2E7F,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,kBAAkB;IAU1B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,sBAAsB;CAY/B"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './apiDecorator';
2
2
  export * from './endpointDecorator';
3
3
  export * from './fetcherCapable';
4
+ export * from './functionMetadata';
4
5
  export * from './parameterDecorator';
5
6
  export * from './reflection';
6
7
  export * from './requestExecutor';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}