@eggjs/router 4.0.0-beta.19 → 4.0.0-beta.21

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,108 +1,104 @@
1
- import { MiddlewareFunc, ResourcesController } from "./types.js";
2
- import { Layer } from "./Layer.js";
3
- import { RegisterOptions, Router, RouterMethod, RouterOptions } from "./Router.js";
4
-
5
- //#region src/EggRouter.d.ts
1
+ import { type RegisterOptions, Router, type RouterMethod, type RouterOptions } from './Router.ts';
2
+ import { type MiddlewareFunc, type ResourcesController } from './types.ts';
6
3
  interface Application {
7
- controller: Record<string, any>;
4
+ controller: Record<string, any>;
8
5
  }
9
6
  /**
10
7
  * FIXME: move these patch into @eggjs/router
11
8
  */
12
- declare class EggRouter extends Router {
13
- readonly app: Application;
14
- /**
15
- * @class
16
- * @param {Object} opts - Router options.
17
- * @param {Application} app - Application object.
18
- */
19
- constructor(opts: RouterOptions, app: Application);
20
- verb(method: RouterMethod | RouterMethod[], nameOrPath: string | RegExp | (string | RegExp)[], pathOrMiddleware: string | RegExp | (string | RegExp)[] | MiddlewareFunc, ...middleware: (MiddlewareFunc | string)[]): this;
21
- head(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
22
- head(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
23
- options(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
24
- options(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
25
- get(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
26
- get(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
27
- put(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
28
- put(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
29
- patch(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
30
- patch(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
31
- post(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
32
- post(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
33
- delete(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
34
- delete(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
35
- all(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
36
- all(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
37
- register(path: string | RegExp | (string | RegExp)[], methods: string[], middleware: MiddlewareFunc | string | (MiddlewareFunc | string | ResourcesController)[], opts?: RegisterOptions): Layer | Layer[];
38
- /**
39
- * restful router api
40
- * @param {String} name - Router name
41
- * @param {String} prefix - url prefix
42
- * @param {Function} middleware - middleware or controller
43
- * @example
44
- * ```js
45
- * app.resources('/posts', 'posts')
46
- * app.resources('posts', '/posts', 'posts')
47
- * app.resources('posts', '/posts', app.role.can('user'), app.controller.posts)
48
- * app.resources('posts', '/posts', middleware1, middleware2, app.controller.posts)
49
- * ```
50
- *
51
- * Examples:
52
- *
53
- * ```js
54
- * app.resources('/posts', 'posts')
55
- * ```
56
- *
57
- * yield router mapping
58
- *
59
- * Method | Path | Route Name | Controller.Action
60
- * -------|-----------------|----------------|-----------------------------
61
- * GET | /posts | posts | app.controller.posts.index
62
- * GET | /posts/new | new_post | app.controller.posts.new
63
- * GET | /posts/:id | post | app.controller.posts.show
64
- * GET | /posts/:id/edit | edit_post | app.controller.posts.edit
65
- * POST | /posts | posts | app.controller.posts.create
66
- * PATCH | /posts/:id | post | app.controller.posts.update
67
- * DELETE | /posts/:id | post | app.controller.posts.destroy
68
- *
69
- * app.router.url can generate url based on arguments
70
- * ```js
71
- * app.router.url('posts')
72
- * => /posts
73
- * app.router.url('post', { id: 1 })
74
- * => /posts/1
75
- * app.router.url('new_post')
76
- * => /posts/new
77
- * app.router.url('edit_post', { id: 1 })
78
- * => /posts/1/edit
79
- * ```
80
- * @return {Router} return route object.
81
- * @since 1.0.0
82
- */
83
- resources(prefix: string, controller: string | ResourcesController): Router;
84
- resources(prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): Router;
85
- resources(name: string, prefix: string, controller: string | ResourcesController): Router;
86
- resources(name: string, prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): Router;
87
- resources(nameOrPath: string | RegExp, ...middleware: (MiddlewareFunc | string | ResourcesController)[]): Router;
88
- /**
89
- * @param {String} name - Router name
90
- * @param {Object} params - more parameters
91
- * @example
92
- * ```js
93
- * router.url('edit_post', { id: 1, name: 'foo', page: 2 })
94
- * => /posts/1/edit?name=foo&page=2
95
- * router.url('posts', { name: 'foo&1', page: 2 })
96
- * => /posts?name=foo%261&page=2
97
- * ```
98
- * @return {String} url by path name and query params.
99
- * @since 1.0.0
100
- */
101
- url(name: string, params?: Record<string, string | number | (string | number)[]>): string;
102
- /**
103
- * @alias to url()
104
- */
105
- pathFor(name: string, params?: Record<string, string | number | (string | number)[]>): string;
9
+ export declare class EggRouter extends Router {
10
+ readonly app: Application;
11
+ /**
12
+ * @class
13
+ * @param {Object} opts - Router options.
14
+ * @param {Application} app - Application object.
15
+ */
16
+ constructor(opts: RouterOptions, app: Application);
17
+ verb(method: RouterMethod | RouterMethod[], nameOrPath: string | RegExp | (string | RegExp)[], pathOrMiddleware: string | RegExp | (string | RegExp)[] | MiddlewareFunc, ...middleware: (MiddlewareFunc | string)[]): this;
18
+ head(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
19
+ head(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
20
+ options(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
21
+ options(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
22
+ get(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
23
+ get(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
24
+ put(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
25
+ put(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
26
+ patch(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
27
+ patch(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
28
+ post(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
29
+ post(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
30
+ delete(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
31
+ delete(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
32
+ all(path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
33
+ all(name: string, path: string | RegExp | (string | RegExp)[], ...middlewares: (MiddlewareFunc | string)[]): Router;
34
+ register(path: string | RegExp | (string | RegExp)[], methods: string[], middleware: MiddlewareFunc | string | (MiddlewareFunc | string | ResourcesController)[], opts?: RegisterOptions): import("./Layer.ts").Layer | import("./Layer.ts").Layer[];
35
+ /**
36
+ * restful router api
37
+ * @param {String} name - Router name
38
+ * @param {String} prefix - url prefix
39
+ * @param {Function} middleware - middleware or controller
40
+ * @example
41
+ * ```js
42
+ * app.resources('/posts', 'posts')
43
+ * app.resources('posts', '/posts', 'posts')
44
+ * app.resources('posts', '/posts', app.role.can('user'), app.controller.posts)
45
+ * app.resources('posts', '/posts', middleware1, middleware2, app.controller.posts)
46
+ * ```
47
+ *
48
+ * Examples:
49
+ *
50
+ * ```js
51
+ * app.resources('/posts', 'posts')
52
+ * ```
53
+ *
54
+ * yield router mapping
55
+ *
56
+ * Method | Path | Route Name | Controller.Action
57
+ * -------|-----------------|----------------|-----------------------------
58
+ * GET | /posts | posts | app.controller.posts.index
59
+ * GET | /posts/new | new_post | app.controller.posts.new
60
+ * GET | /posts/:id | post | app.controller.posts.show
61
+ * GET | /posts/:id/edit | edit_post | app.controller.posts.edit
62
+ * POST | /posts | posts | app.controller.posts.create
63
+ * PATCH | /posts/:id | post | app.controller.posts.update
64
+ * DELETE | /posts/:id | post | app.controller.posts.destroy
65
+ *
66
+ * app.router.url can generate url based on arguments
67
+ * ```js
68
+ * app.router.url('posts')
69
+ * => /posts
70
+ * app.router.url('post', { id: 1 })
71
+ * => /posts/1
72
+ * app.router.url('new_post')
73
+ * => /posts/new
74
+ * app.router.url('edit_post', { id: 1 })
75
+ * => /posts/1/edit
76
+ * ```
77
+ * @return {Router} return route object.
78
+ * @since 1.0.0
79
+ */
80
+ resources(prefix: string, controller: string | ResourcesController): Router;
81
+ resources(prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): Router;
82
+ resources(name: string, prefix: string, controller: string | ResourcesController): Router;
83
+ resources(name: string, prefix: string, middleware: MiddlewareFunc, controller: string | ResourcesController): Router;
84
+ resources(nameOrPath: string | RegExp, ...middleware: (MiddlewareFunc | string | ResourcesController)[]): Router;
85
+ /**
86
+ * @param {String} name - Router name
87
+ * @param {Object} params - more parameters
88
+ * @example
89
+ * ```js
90
+ * router.url('edit_post', { id: 1, name: 'foo', page: 2 })
91
+ * => /posts/1/edit?name=foo&page=2
92
+ * router.url('posts', { name: 'foo&1', page: 2 })
93
+ * => /posts?name=foo%261&page=2
94
+ * ```
95
+ * @return {String} url by path name and query params.
96
+ * @since 1.0.0
97
+ */
98
+ url(name: string, params?: Record<string, string | number | (string | number)[]>): string;
99
+ /**
100
+ * @alias to url()
101
+ */
102
+ pathFor(name: string, params?: Record<string, string | number | (string | number)[]>): string;
106
103
  }
107
- //#endregion
108
- export { EggRouter };
104
+ export {};