@fastcar/koa 0.1.22 → 0.1.23

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
@@ -114,6 +114,14 @@ export default class UserController {
114
114
  const userId = ctx.params.id;
115
115
  return { code: 200, data: { id: userId } };
116
116
  }
117
+
118
+ @HEAD("/users/:id")
119
+ async checkUserExists(data: { id: string }, ctx: Context) {
120
+ // HEAD 请求通常用于检查资源是否存在,不返回响应体
121
+ const userId = ctx.params.id;
122
+ const exists = await checkUser(userId); // 假设的检查方法
123
+ ctx.status = exists ? 200 : 404;
124
+ }
117
125
  }
118
126
  ```
119
127
 
@@ -183,6 +191,7 @@ type KoaConfig = {
183
191
  | `@PutMapping(path)` | PUT | `@PUT` | `string` - 路由路径 |
184
192
  | `@DeleteMapping(path)` | DELETE | `@DELETE` | `string` - 路由路径 |
185
193
  | `@PatchMapping(path)` | PATCH | `@PATCH` | `string` - 路由路径 |
194
+ | `@HeadMapping(path)` | HEAD | `@HEAD` | `string` - 路由路径 |
186
195
  | `@AllMapping(path)` | ALL | `@ALL` | `string` - 路由路径 |
187
196
  | `@RequestMapping(path)` | - | `@REQUEST` | `string` - 基础路径前缀 |
188
197
 
@@ -392,7 +401,7 @@ export default class UploadController {
392
401
  import { KoaApplication, KoaConfig } from "@fastcar/koa";
393
402
 
394
403
  // 装饰器
395
- import { EnableKoa, KoaMiddleware, GET, POST, ... } from "@fastcar/koa/annotation";
404
+ import { EnableKoa, KoaMiddleware, GET, POST, HEAD, ... } from "@fastcar/koa/annotation";
396
405
  ```
397
406
 
398
407
  ### KoaApplication 类
package/annotation.d.ts CHANGED
@@ -25,6 +25,8 @@ export function PatchMapping(url?: string): MRet;
25
25
 
26
26
  export function PutMapping(url?: string): MRet;
27
27
 
28
+ export function HeadMapping(url?: string): MRet;
29
+
28
30
  export function RequestMapping(url: string): Ret;
29
31
 
30
32
  export function ALL(url?: string): MRet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/koa",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "description": "fastcar框架下对koa的包装",
6
6
  "main": "target/index.js",
@@ -0,0 +1,12 @@
1
+ import { RouteMethods } from "../../type/RouteMethods";
2
+ import AddMapping from "./AddMapping";
3
+
4
+ export default function HeadMapping(url?: string) {
5
+ return function (target: any, name: string, descriptor: PropertyDescriptor) {
6
+ AddMapping(target, {
7
+ url,
8
+ method: name,
9
+ request: [RouteMethods.HeadMapping],
10
+ });
11
+ };
12
+ }
package/src/annotation.ts CHANGED
@@ -5,6 +5,7 @@ import AddMapping from "./annotation/router/AddMapping";
5
5
  import AllMapping from "./annotation/router/AllMapping";
6
6
  import DeleteMapping from "./annotation/router/DeleteMapping";
7
7
  import GetMapping from "./annotation/router/GetMapping";
8
+ import HeadMapping from "./annotation/router/HeadMapping";
8
9
  import PatchMapping from "./annotation/router/PatchMapping";
9
10
  import PostMapping from "./annotation/router/PostMapping";
10
11
  import PutMapping from "./annotation/router/PutMapping";
@@ -18,6 +19,7 @@ const PUT = PutMapping;
18
19
  const PATCH = PatchMapping;
19
20
  const ALL = AllMapping;
20
21
  const REQUEST = RequestMapping;
22
+ const HEAD = HeadMapping;
21
23
 
22
24
  export {
23
25
  //关于请求方式注解
@@ -29,6 +31,7 @@ export {
29
31
  PostMapping,
30
32
  PutMapping,
31
33
  RequestMapping,
34
+ HeadMapping,
32
35
  //开启koa应用
33
36
  EnableKoa,
34
37
  //追加koa中间件
@@ -42,4 +45,5 @@ export {
42
45
  ALL,
43
46
  REQUEST,
44
47
  KoaApp,
48
+ HEAD,
45
49
  };
@@ -5,4 +5,5 @@ export enum RouteMethods {
5
5
  DeleteMapping = "delete",
6
6
  PatchMapping = "patch",
7
7
  AllMapping = "all",
8
+ HeadMapping = "head",
8
9
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = HeadMapping;
4
+ const RouteMethods_1 = require("../../type/RouteMethods");
5
+ const AddMapping_1 = require("./AddMapping");
6
+ function HeadMapping(url) {
7
+ return function (target, name, descriptor) {
8
+ (0, AddMapping_1.default)(target, {
9
+ url,
10
+ method: name,
11
+ request: [RouteMethods_1.RouteMethods.HeadMapping],
12
+ });
13
+ };
14
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KoaApp = exports.REQUEST = exports.ALL = exports.PATCH = exports.PUT = exports.DELETE = exports.POST = exports.GET = exports.KoaMiddleware = exports.EnableKoa = exports.RequestMapping = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.GetMapping = exports.DeleteMapping = exports.AllMapping = exports.AddMapping = void 0;
3
+ exports.HEAD = exports.KoaApp = exports.REQUEST = exports.ALL = exports.PATCH = exports.PUT = exports.DELETE = exports.POST = exports.GET = exports.KoaMiddleware = exports.EnableKoa = exports.HeadMapping = exports.RequestMapping = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.GetMapping = exports.DeleteMapping = exports.AllMapping = exports.AddMapping = void 0;
4
4
  const EnableKoa_1 = require("./annotation/EnableKoa");
5
5
  exports.EnableKoa = EnableKoa_1.default;
6
6
  const KoaApp_1 = require("./annotation/KoaApp");
@@ -15,6 +15,8 @@ const DeleteMapping_1 = require("./annotation/router/DeleteMapping");
15
15
  exports.DeleteMapping = DeleteMapping_1.default;
16
16
  const GetMapping_1 = require("./annotation/router/GetMapping");
17
17
  exports.GetMapping = GetMapping_1.default;
18
+ const HeadMapping_1 = require("./annotation/router/HeadMapping");
19
+ exports.HeadMapping = HeadMapping_1.default;
18
20
  const PatchMapping_1 = require("./annotation/router/PatchMapping");
19
21
  exports.PatchMapping = PatchMapping_1.default;
20
22
  const PostMapping_1 = require("./annotation/router/PostMapping");
@@ -38,3 +40,5 @@ const ALL = AllMapping_1.default;
38
40
  exports.ALL = ALL;
39
41
  const REQUEST = RequestMapping_1.default;
40
42
  exports.REQUEST = REQUEST;
43
+ const HEAD = HeadMapping_1.default;
44
+ exports.HEAD = HEAD;
@@ -9,4 +9,5 @@ var RouteMethods;
9
9
  RouteMethods["DeleteMapping"] = "delete";
10
10
  RouteMethods["PatchMapping"] = "patch";
11
11
  RouteMethods["AllMapping"] = "all";
12
+ RouteMethods["HeadMapping"] = "head";
12
13
  })(RouteMethods || (exports.RouteMethods = RouteMethods = {}));