@eggjs/koa 3.0.1 → 3.1.0-beta.11

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