barejs 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/dist/types/context.d.ts +3 -1
- package/package.json +1 -1
- package/src/context.ts +6 -2
package/dist/types/context.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export type Next = () => Promise<any> | any;
|
|
|
5
5
|
* Supports Context-only (379ns path), Standard Middleware, and Legacy Style.
|
|
6
6
|
*/
|
|
7
7
|
export type Middleware = ((ctx: Context) => Promise<any> | any) | ((ctx: Context, next: Next) => Promise<any> | any) | ((req: Request, params: Params, next: Next) => Promise<any> | any);
|
|
8
|
-
export type
|
|
8
|
+
export type ContextHandler = (ctx: Context) => Promise<any> | any;
|
|
9
|
+
export type NativeHandler = (req: Request, params: Params) => Promise<any> | any;
|
|
10
|
+
export type Handler = ContextHandler | NativeHandler;
|
|
9
11
|
export declare class Context {
|
|
10
12
|
req: Request;
|
|
11
13
|
params: Params;
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -12,8 +12,12 @@ export type Middleware =
|
|
|
12
12
|
| ((ctx: Context, next: Next) => Promise<any> | any)
|
|
13
13
|
| ((req: Request, params: Params, next: Next) => Promise<any> | any);
|
|
14
14
|
|
|
15
|
-
export type Handler = (ctx: Context) => Promise<any> | any;
|
|
15
|
+
// export type Handler = (ctx: Context) => Promise<any> | any;
|
|
16
|
+
export type ContextHandler = (ctx: Context) => Promise<any> | any;
|
|
17
|
+
export type NativeHandler = (req: Request, params: Params) => Promise<any> | any;
|
|
16
18
|
|
|
19
|
+
// 2. The Final Handler: This allows either (ctx) OR (req, params)
|
|
20
|
+
export type Handler = ContextHandler | NativeHandler;
|
|
17
21
|
export class Context {
|
|
18
22
|
public req!: Request;
|
|
19
23
|
public params!: Params;
|
|
@@ -126,7 +130,7 @@ export class Context {
|
|
|
126
130
|
this._headers['content-type'] = 'application/json';
|
|
127
131
|
return data;
|
|
128
132
|
}
|
|
129
|
-
|
|
133
|
+
|
|
130
134
|
public text(data: string) {
|
|
131
135
|
this._headers['content-type'] = 'text/plain; charset=utf-8';
|
|
132
136
|
return data;
|