@eggjs/router 4.0.0-beta.35 → 4.0.0-beta.36

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