@eggjs/router 4.0.0-beta.34 → 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.
package/dist/Layer.d.ts CHANGED
@@ -1,114 +1,118 @@
1
- import { type Key } from 'path-to-regexp';
2
- import type { MiddlewareFunc, MiddlewareFuncWithParamProperty, ParamMiddlewareFunc } from './types.ts';
3
- export interface LayerOptions {
4
- prefix?: string;
5
- /** route name */
6
- name?: string;
7
- /** case sensitive (default: false) */
8
- sensitive?: boolean;
9
- /** require the trailing slash (default: false) */
10
- strict?: boolean;
11
- ignoreCaptures?: boolean;
12
- end?: boolean;
1
+ import { MiddlewareFunc, MiddlewareFuncWithParamProperty, ParamMiddlewareFunc } from "./types.js";
2
+ import { Key } from "path-to-regexp";
3
+
4
+ //#region src/Layer.d.ts
5
+ interface LayerOptions {
6
+ prefix?: string;
7
+ /** route name */
8
+ name?: string;
9
+ /** case sensitive (default: false) */
10
+ sensitive?: boolean;
11
+ /** require the trailing slash (default: false) */
12
+ strict?: boolean;
13
+ ignoreCaptures?: boolean;
14
+ end?: boolean;
13
15
  }
14
- export interface LayerURLOptions {
15
- query?: string | object;
16
+ interface LayerURLOptions {
17
+ query?: string | object;
16
18
  }
17
- export declare class Layer {
18
- readonly opts: LayerOptions;
19
- readonly name?: string;
20
- readonly methods: string[];
21
- readonly stack: MiddlewareFuncWithParamProperty[];
22
- path: string | RegExp;
23
- regexp: RegExp;
24
- paramNames: Key[];
25
- /**
26
- * Initialize a new routing Layer with given `method`, `path`, and `middleware`.
27
- *
28
- * @param {String|RegExp} path Path string or regular expression.
29
- * @param {Array} methods Array of HTTP verbs.
30
- * @param {Array|Function} middlewares Layer callback/middleware or series of.
31
- * @param {Object=} opts optional params
32
- * @param {String=} opts.name route name
33
- * @param {String=} opts.sensitive case sensitive (default: false)
34
- * @param {String=} opts.strict require the trailing slash (default: false)
35
- * @private
36
- */
37
- constructor(path: string | RegExp, methods: string[], middlewares: MiddlewareFunc | MiddlewareFunc[], opts?: LayerOptions | string);
38
- /**
39
- * Returns whether request `path` matches route.
40
- *
41
- * @param {String} path path string
42
- * @return {Boolean} matched or not
43
- * @private
44
- */
45
- match(path: string): boolean;
46
- /**
47
- * Returns map of URL parameters for given `path` and `paramNames`.
48
- *
49
- * @param {String} _path path string
50
- * @param {Array.<String>} captures captures strings
51
- * @param {Object=} [existingParams] existing params
52
- * @return {Object} params object
53
- * @private
54
- */
55
- params(_path: string, captures: Array<string>, existingParams?: Record<string, string>): Record<string, string>;
56
- /**
57
- * Returns array of regexp url path captures.
58
- *
59
- * @param {String} path path string
60
- * @return {Array.<String>} captures strings
61
- * @private
62
- */
63
- captures(path: string): Array<string>;
64
- /**
65
- * Generate URL for route using given `params`.
66
- *
67
- * @example
68
- *
69
- * ```javascript
70
- * var route = new Layer(['GET'], '/users/:id', fn);
71
- *
72
- * route.url(123); // => "/users/123"
73
- * route.url('123'); // => "/users/123"
74
- * route.url({ id: 123 }); // => "/users/123"
75
- * ```
76
- *
77
- * @param {Object} params url parameters
78
- * @param {Object} paramsOrOptions optional parameters
79
- * @return {String} url string
80
- * @private
81
- */
82
- url(params?: string | number | object, ...paramsOrOptions: (string | number | object | LayerURLOptions)[]): string;
83
- /**
84
- * Run validations on route named parameters.
85
- *
86
- * @example
87
- *
88
- * ```javascript
89
- * router
90
- * .param('user', function (id, ctx, next) {
91
- * ctx.user = users[id];
92
- * if (!user) return ctx.status = 404;
93
- * next();
94
- * })
95
- * .get('/users/:user', function (ctx, next) {
96
- * ctx.body = ctx.user;
97
- * });
98
- * ```
99
- *
100
- * @param {String} param param string
101
- * @param {Function} fn middleware function
102
- * @return {Layer} layer instance
103
- * @private
104
- */
105
- param(param: string, fn: ParamMiddlewareFunc): Layer;
106
- /**
107
- * Prefix route path.
108
- *
109
- * @param {String} prefix prefix string
110
- * @return {Layer} layer instance
111
- * @private
112
- */
113
- setPrefix(prefix: string): Layer;
19
+ declare class Layer {
20
+ readonly opts: LayerOptions;
21
+ readonly name?: string;
22
+ readonly methods: string[];
23
+ readonly stack: MiddlewareFuncWithParamProperty[];
24
+ path: string | RegExp;
25
+ regexp: RegExp;
26
+ paramNames: Key[];
27
+ /**
28
+ * Initialize a new routing Layer with given `method`, `path`, and `middleware`.
29
+ *
30
+ * @param {String|RegExp} path Path string or regular expression.
31
+ * @param {Array} methods Array of HTTP verbs.
32
+ * @param {Array|Function} middlewares Layer callback/middleware or series of.
33
+ * @param {Object=} opts optional params
34
+ * @param {String=} opts.name route name
35
+ * @param {String=} opts.sensitive case sensitive (default: false)
36
+ * @param {String=} opts.strict require the trailing slash (default: false)
37
+ * @private
38
+ */
39
+ constructor(path: string | RegExp, methods: string[], middlewares: MiddlewareFunc | MiddlewareFunc[], opts?: LayerOptions | string);
40
+ /**
41
+ * Returns whether request `path` matches route.
42
+ *
43
+ * @param {String} path path string
44
+ * @return {Boolean} matched or not
45
+ * @private
46
+ */
47
+ match(path: string): boolean;
48
+ /**
49
+ * Returns map of URL parameters for given `path` and `paramNames`.
50
+ *
51
+ * @param {String} _path path string
52
+ * @param {Array.<String>} captures captures strings
53
+ * @param {Object=} [existingParams] existing params
54
+ * @return {Object} params object
55
+ * @private
56
+ */
57
+ params(_path: string, captures: Array<string>, existingParams?: Record<string, string>): Record<string, string>;
58
+ /**
59
+ * Returns array of regexp url path captures.
60
+ *
61
+ * @param {String} path path string
62
+ * @return {Array.<String>} captures strings
63
+ * @private
64
+ */
65
+ captures(path: string): Array<string>;
66
+ /**
67
+ * Generate URL for route using given `params`.
68
+ *
69
+ * @example
70
+ *
71
+ * ```javascript
72
+ * var route = new Layer(['GET'], '/users/:id', fn);
73
+ *
74
+ * route.url(123); // => "/users/123"
75
+ * route.url('123'); // => "/users/123"
76
+ * route.url({ id: 123 }); // => "/users/123"
77
+ * ```
78
+ *
79
+ * @param {Object} params url parameters
80
+ * @param {Object} paramsOrOptions optional parameters
81
+ * @return {String} url string
82
+ * @private
83
+ */
84
+ url(params?: string | number | object, ...paramsOrOptions: (string | number | object | LayerURLOptions)[]): string;
85
+ /**
86
+ * Run validations on route named parameters.
87
+ *
88
+ * @example
89
+ *
90
+ * ```javascript
91
+ * router
92
+ * .param('user', function (id, ctx, next) {
93
+ * ctx.user = users[id];
94
+ * if (!user) return ctx.status = 404;
95
+ * next();
96
+ * })
97
+ * .get('/users/:user', function (ctx, next) {
98
+ * ctx.body = ctx.user;
99
+ * });
100
+ * ```
101
+ *
102
+ * @param {String} param param string
103
+ * @param {Function} fn middleware function
104
+ * @return {Layer} layer instance
105
+ * @private
106
+ */
107
+ param(param: string, fn: ParamMiddlewareFunc): Layer;
108
+ /**
109
+ * Prefix route path.
110
+ *
111
+ * @param {String} prefix prefix string
112
+ * @return {Layer} layer instance
113
+ * @private
114
+ */
115
+ setPrefix(prefix: string): Layer;
114
116
  }
117
+ //#endregion
118
+ export { Layer, LayerOptions, LayerURLOptions };