@eggjs/koa 3.1.0-beta.35 → 3.1.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/context.d.ts CHANGED
@@ -1,160 +1,164 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http';
2
- import type { ParsedUrlQuery } from 'node:querystring';
3
- import type { Accepts } from 'accepts';
4
- import Cookies from 'cookies';
5
- import type { Application } from './application.ts';
6
- import type { Request, RequestSocket } from './request.ts';
7
- import type { Response } from './response.ts';
8
- import type { CustomError, AnyProto } from './types.ts';
9
- export declare class Context {
10
- #private;
11
- [key: symbol | string]: unknown;
12
- app: Application;
13
- req: IncomingMessage;
14
- res: ServerResponse;
15
- request: Request & AnyProto;
16
- response: Response & AnyProto;
17
- originalUrl: string;
18
- respond?: boolean;
19
- constructor(app: Application, req: IncomingMessage, res: ServerResponse);
20
- /**
21
- * util.inspect() implementation, which
22
- * just returns the JSON output.
23
- */
24
- inspect(): object;
25
- /**
26
- * Return JSON representation.
27
- *
28
- * Here we explicitly invoke .toJSON() on each
29
- * object, as iteration will otherwise fail due
30
- * to the getters and cause utilities such as
31
- * clone() to fail.
32
- */
33
- toJSON(): object;
34
- /**
35
- * Similar to .throw(), adds assertion.
36
- *
37
- * ```ts
38
- * this.assert(this.user, 401, 'Please login!');
39
- * ```
40
- */
41
- assert(value: unknown, status?: number, errorProps?: Record<string, unknown>): void;
42
- assert(value: unknown, status?: number, errorMessage?: string, errorProps?: Record<string, unknown>): void;
43
- /**
44
- * Throw an error with `status` (default 500) and
45
- * `msg`. Note that these are user-level
46
- * errors, and the message may be exposed to the client.
47
- *
48
- * this.throw(403)
49
- * this.throw(400, 'name required')
50
- * this.throw('something exploded')
51
- * this.throw(new Error('invalid'))
52
- * this.throw(400, new Error('invalid'))
53
- * this.throw(400, new Error('invalid'), { foo: 'bar' })
54
- * this.throw(new Error('invalid'), { foo: 'bar' })
55
- *
56
- * See: https://github.com/jshttp/http-errors
57
- *
58
- * Note: `status` should only be passed as the first parameter.
59
- *
60
- * @param {String|Number|Error} status error, msg or status
61
- * @param {String|Number|Error|Object} [error] error, msg, status or errorProps
62
- * @param {Object} [errorProps] error object properties
63
- */
64
- throw(status: number): void;
65
- throw(status: number, errorProps: object): void;
66
- throw(status: number, errorMessage: string): void;
67
- throw(status: number, errorMessage: string, errorProps: object): void;
68
- throw(status: number, error: Error): void;
69
- throw(status: number, error: Error, errorProps: object): void;
70
- throw(errorMessage: string): void;
71
- throw(errorMessage: string, errorProps: object): void;
72
- throw(errorMessage: string, status: number): void;
73
- throw(errorMessage: string, status: number, errorProps: object): void;
74
- throw(error: Error): void;
75
- throw(error: Error, errorProps: object): void;
76
- throw(error: Error, status: number): void;
77
- throw(error: Error, status: number, errorProps: object): void;
78
- /**
79
- * Default error handling.
80
- * @private
81
- */
82
- onerror(err: CustomError): void;
83
- protected _cookies: Cookies | undefined;
84
- get cookies(): Cookies;
85
- set cookies(cookies: Cookies);
86
- get state(): Record<string, any>;
87
- /**
88
- * Request delegation.
89
- */
90
- acceptsLanguages(): string[];
91
- acceptsLanguages(languages: string[]): string | false;
92
- acceptsLanguages(...languages: string[]): string | false;
93
- acceptsEncodings(): string[];
94
- acceptsEncodings(encodings: string[]): string | false;
95
- acceptsEncodings(...encodings: string[]): string | false;
96
- acceptsCharsets(): string[];
97
- acceptsCharsets(charsets: string[]): string | false;
98
- acceptsCharsets(...charsets: string[]): string | false;
99
- accepts(args: string[]): string | string[] | false;
100
- accepts(...args: string[]): string | string[] | false;
101
- get<T = string | string[]>(field: string): T;
102
- is(type?: string | string[], ...types: string[]): string | false | null;
103
- get querystring(): string;
104
- set querystring(str: string);
105
- get idempotent(): boolean;
106
- get socket(): RequestSocket;
107
- get search(): string;
108
- set search(str: string);
109
- get method(): string;
110
- set method(method: string);
111
- get query(): ParsedUrlQuery;
112
- set query(obj: ParsedUrlQuery);
113
- get path(): string;
114
- set path(path: string);
115
- get url(): string;
116
- set url(url: string);
117
- get accept(): Accepts;
118
- set accept(accept: Accepts);
119
- get origin(): string;
120
- get href(): string;
121
- get subdomains(): string[];
122
- get protocol(): string;
123
- get host(): string;
124
- get hostname(): string;
125
- get URL(): URL;
126
- get header(): IncomingMessage['headers'];
127
- get headers(): IncomingMessage['headers'];
128
- get secure(): boolean;
129
- get stale(): boolean;
130
- get fresh(): boolean;
131
- get ips(): string[];
132
- get ip(): string;
133
- /**
134
- * Response delegation.
135
- */
136
- attachment(...args: Parameters<Response['attachment']>): void;
137
- redirect(...args: Parameters<Response['redirect']>): void;
138
- remove(...args: Parameters<Response['remove']>): void;
139
- vary(...args: Parameters<Response['vary']>): void;
140
- has(...args: Parameters<Response['has']>): boolean;
141
- set(...args: Parameters<Response['set']>): void;
142
- append(...args: Parameters<Response['append']>): void;
143
- flushHeaders(...args: Parameters<Response['flushHeaders']>): void;
144
- get status(): number;
145
- set status(status: number);
146
- get message(): string;
147
- set message(msg: string);
148
- get body(): any;
149
- set body(val: any);
150
- get length(): number | undefined;
151
- set length(n: number | string | undefined);
152
- get type(): string;
153
- set type(type: string | null | undefined);
154
- get lastModified(): string | Date | undefined;
155
- set lastModified(val: string | Date | undefined);
156
- get etag(): string;
157
- set etag(val: string);
158
- get headerSent(): boolean;
159
- get writable(): boolean;
1
+ import { Response } from "./response.js";
2
+ import { Request, RequestSocket } from "./request.js";
3
+ import { AnyProto, CustomError } from "./types.js";
4
+ import { Application } from "./application.js";
5
+ import { IncomingMessage, ServerResponse } from "node:http";
6
+ import { Cookies } from "@eggjs/cookies";
7
+ import { ParsedUrlQuery } from "node:querystring";
8
+ import { Accepts } from "accepts";
9
+
10
+ //#region src/context.d.ts
11
+ declare class Context {
12
+ #private;
13
+ [key: symbol | string]: unknown;
14
+ app: Application;
15
+ req: IncomingMessage;
16
+ res: ServerResponse;
17
+ request: Request & AnyProto;
18
+ response: Response & AnyProto;
19
+ originalUrl: string;
20
+ respond?: boolean;
21
+ constructor(app: Application, req: IncomingMessage, res: ServerResponse);
22
+ /**
23
+ * util.inspect() implementation, which
24
+ * just returns the JSON output.
25
+ */
26
+ inspect(): object;
27
+ /**
28
+ * Return JSON representation.
29
+ *
30
+ * Here we explicitly invoke .toJSON() on each
31
+ * object, as iteration will otherwise fail due
32
+ * to the getters and cause utilities such as
33
+ * clone() to fail.
34
+ */
35
+ toJSON(): object;
36
+ /**
37
+ * Similar to .throw(), adds assertion.
38
+ *
39
+ * ```ts
40
+ * this.assert(this.user, 401, 'Please login!');
41
+ * ```
42
+ */
43
+ assert(value: unknown, status?: number, errorProps?: Record<string, unknown>): void;
44
+ assert(value: unknown, status?: number, errorMessage?: string, errorProps?: Record<string, unknown>): void;
45
+ /**
46
+ * Throw an error with `status` (default 500) and
47
+ * `msg`. Note that these are user-level
48
+ * errors, and the message may be exposed to the client.
49
+ *
50
+ * this.throw(403)
51
+ * this.throw(400, 'name required')
52
+ * this.throw('something exploded')
53
+ * this.throw(new Error('invalid'))
54
+ * this.throw(400, new Error('invalid'))
55
+ * this.throw(400, new Error('invalid'), { foo: 'bar' })
56
+ * this.throw(new Error('invalid'), { foo: 'bar' })
57
+ *
58
+ * See: https://github.com/jshttp/http-errors
59
+ *
60
+ * Note: `status` should only be passed as the first parameter.
61
+ *
62
+ * @param {String|Number|Error} status error, msg or status
63
+ * @param {String|Number|Error|Object} [error] error, msg, status or errorProps
64
+ * @param {Object} [errorProps] error object properties
65
+ */
66
+ throw(status: number): void;
67
+ throw(status: number, errorProps: object): void;
68
+ throw(status: number, errorMessage: string): void;
69
+ throw(status: number, errorMessage: string, errorProps: object): void;
70
+ throw(status: number, error: Error): void;
71
+ throw(status: number, error: Error, errorProps: object): void;
72
+ throw(errorMessage: string): void;
73
+ throw(errorMessage: string, errorProps: object): void;
74
+ throw(errorMessage: string, status: number): void;
75
+ throw(errorMessage: string, status: number, errorProps: object): void;
76
+ throw(error: Error): void;
77
+ throw(error: Error, errorProps: object): void;
78
+ throw(error: Error, status: number): void;
79
+ throw(error: Error, status: number, errorProps: object): void;
80
+ /**
81
+ * Default error handling.
82
+ * @private
83
+ */
84
+ onerror(err: CustomError): void;
85
+ protected _cookies: Cookies | undefined;
86
+ get cookies(): Cookies;
87
+ set cookies(cookies: Cookies);
88
+ get state(): Record<string, any>;
89
+ /**
90
+ * Request delegation.
91
+ */
92
+ acceptsLanguages(): string[];
93
+ acceptsLanguages(languages: string[]): string | false;
94
+ acceptsLanguages(...languages: string[]): string | false;
95
+ acceptsEncodings(): string[];
96
+ acceptsEncodings(encodings: string[]): string | false;
97
+ acceptsEncodings(...encodings: string[]): string | false;
98
+ acceptsCharsets(): string[];
99
+ acceptsCharsets(charsets: string[]): string | false;
100
+ acceptsCharsets(...charsets: string[]): string | false;
101
+ accepts(args: string[]): string | string[] | false;
102
+ accepts(...args: string[]): string | string[] | false;
103
+ get<T = string | string[]>(field: string): T;
104
+ is(type?: string | string[], ...types: string[]): string | false | null;
105
+ get querystring(): string;
106
+ set querystring(str: string);
107
+ get idempotent(): boolean;
108
+ get socket(): RequestSocket;
109
+ get search(): string;
110
+ set search(str: string);
111
+ get method(): string;
112
+ set method(method: string);
113
+ get query(): ParsedUrlQuery;
114
+ set query(obj: ParsedUrlQuery);
115
+ get path(): string;
116
+ set path(path: string);
117
+ get url(): string;
118
+ set url(url: string);
119
+ get accept(): Accepts;
120
+ set accept(accept: Accepts);
121
+ get origin(): string;
122
+ get href(): string;
123
+ get subdomains(): string[];
124
+ get protocol(): string;
125
+ get host(): string;
126
+ get hostname(): string;
127
+ get URL(): URL;
128
+ get header(): IncomingMessage["headers"];
129
+ get headers(): IncomingMessage["headers"];
130
+ get secure(): boolean;
131
+ get stale(): boolean;
132
+ get fresh(): boolean;
133
+ get ips(): string[];
134
+ get ip(): string;
135
+ /**
136
+ * Response delegation.
137
+ */
138
+ attachment(...args: Parameters<Response["attachment"]>): void;
139
+ redirect(...args: Parameters<Response["redirect"]>): void;
140
+ remove(...args: Parameters<Response["remove"]>): void;
141
+ vary(...args: Parameters<Response["vary"]>): void;
142
+ has(...args: Parameters<Response["has"]>): boolean;
143
+ set(...args: Parameters<Response["set"]>): void;
144
+ append(...args: Parameters<Response["append"]>): void;
145
+ flushHeaders(...args: Parameters<Response["flushHeaders"]>): void;
146
+ get status(): number;
147
+ set status(status: number);
148
+ get message(): string;
149
+ set message(msg: string);
150
+ get body(): any;
151
+ set body(val: any);
152
+ get length(): number | undefined;
153
+ set length(n: number | string | undefined);
154
+ get type(): string;
155
+ set type(type: string | null | undefined);
156
+ get lastModified(): string | Date | undefined;
157
+ set lastModified(val: string | Date | undefined);
158
+ get etag(): string;
159
+ set etag(val: string);
160
+ get headerSent(): boolean;
161
+ get writable(): boolean;
160
162
  }
163
+ //#endregion
164
+ export { Context };