@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.
- package/dist/EggRouter.d.ts +98 -102
- package/dist/EggRouter.js +228 -198
- package/dist/Layer.d.ts +111 -115
- package/dist/Layer.js +238 -201
- package/dist/Router.d.ts +489 -491
- package/dist/Router.js +775 -675
- package/dist/index.d.ts +7 -9
- package/dist/index.js +6 -9
- package/dist/types.d.ts +15 -18
- package/dist/types.js +2 -1
- package/package.json +5 -5
package/dist/EggRouter.d.ts
CHANGED
|
@@ -1,108 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
108
|
-
export { EggRouter };
|
|
104
|
+
export {};
|