@ahoo-wang/fetcher-decorator 0.5.6 → 0.6.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.
package/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  [![License](https://img.shields.io/npm/l/@ahoo-wang/fetcher-decorator.svg)](https://github.com/Ahoo-Wang/fetcher/blob/main/LICENSE)
7
7
  [![npm downloads](https://img.shields.io/npm/dm/@ahoo-wang/fetcher-decorator.svg)](https://www.npmjs.com/package/@ahoo-wang/fetcher-decorator)
8
8
  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40ahoo-wang%2Ffetcher-decorator)](https://www.npmjs.com/package/@ahoo-wang/fetcher-decorator)
9
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Ahoo-Wang/fetcher)
9
10
 
10
11
  Decorator support for Fetcher HTTP client. Enables clean, declarative API service definitions using TypeScript
11
12
  decorators.
@@ -63,8 +64,8 @@ class UserService {
63
64
 
64
65
  @get('/{id}')
65
66
  getUser(
66
- @path('id') id: number,
67
- @query('include') include: string,
67
+ @path() id: number,
68
+ @query() include: string,
68
69
  ): Promise<Response> {
69
70
  throw new Error('Implementation will be generated automatically.');
70
71
  }
@@ -147,7 +148,7 @@ Defines an OPTIONS endpoint.
147
148
  ```typescript
148
149
  class UserService {
149
150
  @get('/{id}', { timeout: 3000 })
150
- getUser(@path('id') id: number): Promise<Response> {
151
+ getUser(@path() id: number): Promise<Response> {
151
152
  throw new Error('Implementation will be generated automatically.');
152
153
  }
153
154
 
@@ -162,31 +163,34 @@ class UserService {
162
163
 
163
164
  #### `@path(name)`
164
165
 
165
- Defines a path parameter.
166
+ Defines a path parameter. The name is optional - if not provided, it will be automatically extracted from the method
167
+ parameter name.
166
168
 
167
169
  **Parameters:**
168
170
 
169
- - `name`: Name of the parameter (used in the path template)
171
+ - `name`: Name of the parameter (used in the path template, optional - auto-extracted if not provided)
170
172
 
171
173
  #### `@query(name)`
172
174
 
173
- Defines a query parameter.
175
+ Defines a query parameter. The name is optional - if not provided, it will be automatically extracted from the method
176
+ parameter name.
174
177
 
175
178
  **Parameters:**
176
179
 
177
- - `name`: Name of the parameter (used in the query string)
180
+ - `name`: Name of the parameter (used in the query string, optional - auto-extracted if not provided)
178
181
 
179
182
  #### `@body()`
180
183
 
181
- Defines a request body.
184
+ Defines a request body. Body parameters don't have names since there's only one body per request.
182
185
 
183
186
  #### `@header(name)`
184
187
 
185
- Defines a header parameter.
188
+ Defines a header parameter. The name is optional - if not provided, it will be automatically extracted from the method
189
+ parameter name.
186
190
 
187
191
  **Parameters:**
188
192
 
189
- - `name`: Name of the header
193
+ - `name`: Name of the header (optional - auto-extracted if not provided)
190
194
 
191
195
  **Example:**
192
196
 
@@ -195,14 +199,14 @@ class UserService {
195
199
  @get('/search')
196
200
  searchUsers(
197
201
  @query('q') query: string,
198
- @query('limit') limit: number,
202
+ @query() limit: number,
199
203
  @header('Authorization') auth: string,
200
204
  ): Promise<Response> {
201
205
  throw new Error('Implementation will be generated automatically.');
202
206
  }
203
207
 
204
208
  @put('/{id}')
205
- updateUser(@path('id') id: number, @body() user: User): Promise<Response> {
209
+ updateUser(@path() id: number, @body() user: User): Promise<Response> {
206
210
  throw new Error('Implementation will be generated automatically.');
207
211
  }
208
212
  }
@@ -224,7 +228,7 @@ class BaseService {
224
228
  @api('/users')
225
229
  class UserService extends BaseService {
226
230
  @get('/{id}')
227
- getUser(@path('id') id: number): Promise<Response> {
231
+ getUser(@path() id: number): Promise<Response> {
228
232
  throw new Error('Implementation will be generated automatically.');
229
233
  }
230
234
  }
@@ -239,7 +243,7 @@ class ComplexService {
239
243
  batchOperation(
240
244
  @body() items: Item[],
241
245
  @header('X-Request-ID') requestId: string,
242
- @query('dryRun') dryRun: boolean = false,
246
+ @query() dryRun: boolean = false,
243
247
  ): Promise<Response> {
244
248
  throw new Error('Implementation will be generated automatically.');
245
249
  }
package/README.zh-CN.md CHANGED
@@ -6,6 +6,7 @@
6
6
  [![License](https://img.shields.io/npm/l/@ahoo-wang/fetcher-decorator.svg)](https://github.com/Ahoo-Wang/fetcher/blob/main/LICENSE)
7
7
  [![npm downloads](https://img.shields.io/npm/dm/@ahoo-wang/fetcher-decorator.svg)](https://www.npmjs.com/package/@ahoo-wang/fetcher-decorator)
8
8
  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40ahoo-wang%2Ffetcher-decorator)](https://www.npmjs.com/package/@ahoo-wang/fetcher-decorator)
9
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Ahoo-Wang/fetcher)
9
10
 
10
11
  Fetcher HTTP 客户端的装饰器支持。使用 TypeScript 装饰器实现简洁、声明式的 API 服务定义。
11
12
 
@@ -62,8 +63,8 @@ class UserService {
62
63
 
63
64
  @get('/{id}')
64
65
  getUser(
65
- @path('id') id: number,
66
- @query('include') include: string,
66
+ @path() id: number,
67
+ @query() include: string,
67
68
  ): Promise<Response> {
68
69
  throw new Error('实现将自动生成');
69
70
  }
@@ -146,7 +147,7 @@ class ApiService {
146
147
  ```typescript
147
148
  class UserService {
148
149
  @get('/{id}', { timeout: 3000 })
149
- getUser(@path('id') id: number): Promise<Response> {
150
+ getUser(@path() id: number): Promise<Response> {
150
151
  throw new Error('实现将自动生成');
151
152
  }
152
153
 
@@ -161,31 +162,31 @@ class UserService {
161
162
 
162
163
  #### `@path(name)`
163
164
 
164
- 定义路径参数。
165
+ 定义路径参数。名称是可选的 - 如果未提供,将使用反射从方法参数名自动提取。
165
166
 
166
167
  **参数:**
167
168
 
168
- - `name`: 参数名称(在路径模板中使用)
169
+ - `name`: 参数名称(在路径模板中使用,可选 - 如果未提供则自动提取)
169
170
 
170
171
  #### `@query(name)`
171
172
 
172
- 定义查询参数。
173
+ 定义查询参数。名称是可选的 - 如果未提供,将使用反射从方法参数名自动提取。
173
174
 
174
175
  **参数:**
175
176
 
176
- - `name`: 参数名称(在查询字符串中使用)
177
+ - `name`: 参数名称(在查询字符串中使用,可选 - 如果未提供则自动提取)
177
178
 
178
179
  #### `@body()`
179
180
 
180
- 定义请求体。
181
+ 定义请求体。请求体参数没有名称,因为每个请求只有一个请求体。
181
182
 
182
183
  #### `@header(name)`
183
184
 
184
- 定义头部参数。
185
+ 定义头部参数。名称是可选的 - 如果未提供,将使用反射从方法参数名自动提取。
185
186
 
186
187
  **参数:**
187
188
 
188
- - `name`: 头部名称
189
+ - `name`: 头部名称(可选 - 如果未提供则自动提取)
189
190
 
190
191
  **示例:**
191
192
 
@@ -194,7 +195,7 @@ class UserService {
194
195
  @get('/search')
195
196
  searchUsers(
196
197
  @query('q') query: string,
197
- @query('limit') limit: number,
198
+ @query() limit: number,
198
199
  @header('Authorization') auth: string,
199
200
  ): Promise<Response> {
200
201
  throw new Error('实现将自动生成');
@@ -223,7 +224,7 @@ class BaseService {
223
224
  @api('/users')
224
225
  class UserService extends BaseService {
225
226
  @get('/{id}')
226
- getUser(@path('id') id: number): Promise<Response> {
227
+ getUser(@path() id: number): Promise<Response> {
227
228
  throw new Error('实现将自动生成');
228
229
  }
229
230
  }
@@ -238,7 +239,7 @@ class ComplexService {
238
239
  batchOperation(
239
240
  @body() items: Item[],
240
241
  @header('X-Request-ID') requestId: string,
241
- @query('dryRun') dryRun: boolean = false,
242
+ @query() dryRun: boolean = false,
242
243
  ): Promise<Response> {
243
244
  throw new Error('实现将自动生成');
244
245
  }
@@ -94,20 +94,104 @@ export declare const PARAMETER_METADATA_KEY: unique symbol;
94
94
  * This function creates a decorator that can be used to specify how a method parameter
95
95
  * should be handled in the HTTP request. It stores metadata about the parameter
96
96
  * that will be used during request execution.
97
+ * The name is optional - if not provided, it will be automatically extracted
98
+ * from the method parameter name using reflection.
97
99
  *
98
100
  * @param type - The type of parameter (PATH, QUERY, HEADER, or BODY)
99
- * @param name - The name of the parameter (used for path, query, and header parameters)
101
+ * @param name - The name of the parameter (used for path, query, and header parameters, optional - auto-extracted if not provided)
100
102
  * @returns A parameter decorator function
101
103
  *
102
104
  * @example
103
105
  * ```typescript
106
+ * // With explicit name
104
107
  * @get('/users/{id}')
105
108
  * getUser(@parameter(ParameterType.PATH, 'id') userId: string): Promise<Response>
109
+ *
110
+ * // With auto-extracted name
111
+ * @get('/users/{userId}')
112
+ * getUser(@parameter(ParameterType.PATH) userId: string): Promise<Response>
106
113
  * ```
107
114
  */
108
115
  export declare function parameter(type: ParameterType, name?: string): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
116
+ /**
117
+ * Path parameter decorator
118
+ *
119
+ * Defines a path parameter that will be inserted into the URL path.
120
+ * The name is optional - if not provided, it will be automatically extracted
121
+ * from the method parameter name using reflection.
122
+ *
123
+ * @param name - The name of the path parameter (optional, auto-extracted if not provided)
124
+ * @returns A parameter decorator function
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // With explicit name
129
+ * @get('/users/{id}')
130
+ * getUser(@path('id') userId: string): Promise<Response>
131
+ *
132
+ * // With auto-extracted name
133
+ * @get('/users/{userId}')
134
+ * getUser(@path() userId: string): Promise<Response>
135
+ * ```
136
+ */
109
137
  export declare function path(name?: string): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
138
+ /**
139
+ * Query parameter decorator
140
+ *
141
+ * Defines a query parameter that will be appended to the URL query string.
142
+ * The name is optional - if not provided, it will be automatically extracted
143
+ * from the method parameter name using reflection.
144
+ *
145
+ * @param name - The name of the query parameter (optional, auto-extracted if not provided)
146
+ * @returns A parameter decorator function
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // With explicit name
151
+ * @get('/users')
152
+ * getUsers(@query('limit') limit: number): Promise<Response>
153
+ *
154
+ * // With auto-extracted name
155
+ * @get('/users')
156
+ * getUsers(@query() limit: number): Promise<Response>
157
+ * ```
158
+ */
110
159
  export declare function query(name?: string): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
160
+ /**
161
+ * Header parameter decorator
162
+ *
163
+ * Defines a header parameter that will be added to the request headers.
164
+ * The name is optional - if not provided, it will be automatically extracted
165
+ * from the method parameter name using reflection.
166
+ *
167
+ * @param name - The name of the header parameter (optional, auto-extracted if not provided)
168
+ * @returns A parameter decorator function
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // With explicit name
173
+ * @get('/users')
174
+ * getUsers(@header('Authorization') token: string): Promise<Response>
175
+ *
176
+ * // With auto-extracted name
177
+ * @get('/users')
178
+ * getUsers(@header() authorization: string): Promise<Response>
179
+ * ```
180
+ */
111
181
  export declare function header(name?: string): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
182
+ /**
183
+ * Body parameter decorator
184
+ *
185
+ * Defines a body parameter that will be sent as the request body.
186
+ * Note that body parameters don't have names since there's only one body per request.
187
+ *
188
+ * @returns A parameter decorator function
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * @post('/users')
193
+ * createUser(@body() user: User): Promise<Response>
194
+ * ```
195
+ */
112
196
  export declare function body(): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
113
197
  //# sourceMappingURL=parameterDecorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parameterDecorator.d.ts","sourceRoot":"","sources":["../src/parameterDecorator.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAE1B;;;;;;GAMG;AACH,oBAAY,aAAa;IACvB;;;;;;;;;;;OAWG;IACH,IAAI,SAAS;IAEb;;;;;;;;;;;OAWG;IACH,KAAK,UAAU;IAEf;;;;;;;;;;;OAWG;IACH,MAAM,WAAW;IAEjB;;;;;;;;;;;OAWG;IACH,IAAI,SAAS;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,IAAI,EAAE,aAAa,CAAC;IAEpB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,sBAAsB,eAA+B,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAA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zB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,MAAW,YAlD1B,MAAM,eACD,MAAM,GAAG,MAAM,kBACZ,MAAM,UAkDzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,MAAW,YA3E3B,MAAM,eACD,MAAM,GAAG,MAAM,kBACZ,MAAM,UA2EzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,IAAI,GAAE,MAAW,YApG5B,MAAM,eACD,MAAM,GAAG,MAAM,kBACZ,MAAM,UAoGzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,aAtHR,MAAM,eACD,MAAM,GAAG,MAAM,kBACZ,MAAM,UAsHzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-decorator",
3
- "version": "0.5.6",
3
+ "version": "0.6.1",
4
4
  "description": "TypeScript decorators for clean API service definitions with Fetcher HTTP client",
5
5
  "keywords": [
6
6
  "fetch",
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "reflect-metadata": "^0.2.2",
39
- "@ahoo-wang/fetcher": "0.5.6"
39
+ "@ahoo-wang/fetcher": "0.6.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@vitest/coverage-v8": "^3.2.4",