@mojojs/core 1.26.18 → 2.0.0
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/README.md +1 -1
- package/lib/app.d.ts +31 -16
- package/lib/app.js +181 -126
- package/lib/body/params.js +0 -1
- package/lib/body.d.ts +13 -5
- package/lib/body.js +47 -17
- package/lib/cache.d.ts +1 -2
- package/lib/cache.js +12 -21
- package/lib/cgi.d.ts +3 -3
- package/lib/cgi.js +16 -8
- package/lib/cli/cgi.d.ts +1 -1
- package/lib/cli/cgi.js +1 -2
- package/lib/cli/create-full-app.d.ts +1 -1
- package/lib/cli/create-full-app.js +27 -27
- package/lib/cli/create-lite-app.d.ts +1 -1
- package/lib/cli/create-lite-app.js +2 -3
- package/lib/cli/create-plugin.d.ts +1 -1
- package/lib/cli/create-plugin.js +25 -23
- package/lib/cli/eval.d.ts +1 -1
- package/lib/cli/eval.js +12 -5
- package/lib/cli/get.d.ts +1 -1
- package/lib/cli/get.js +30 -26
- package/lib/cli/repl.d.ts +1 -1
- package/lib/cli/repl.js +0 -1
- package/lib/cli/routes.d.ts +1 -1
- package/lib/cli/routes.js +10 -7
- package/lib/cli/server.d.ts +1 -1
- package/lib/cli/server.js +41 -24
- package/lib/cli/version.js +1 -2
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +25 -19
- package/lib/context.d.ts +33 -10
- package/lib/context.js +137 -32
- package/lib/core.d.ts +14 -13
- package/lib/core.js +12 -12
- package/lib/headers.js +5 -4
- package/lib/hooks.d.ts +1 -1
- package/lib/hooks.js +1 -5
- package/lib/logger.d.ts +2 -2
- package/lib/logger.js +28 -16
- package/lib/mime.js +10 -13
- package/lib/plugins/default-conditions.d.ts +1 -1
- package/lib/plugins/default-conditions.js +0 -1
- package/lib/plugins/default-helpers.d.ts +1 -1
- package/lib/plugins/default-helpers.js +28 -11
- package/lib/plugins/json-config.d.ts +1 -1
- package/lib/plugins/json-config.js +0 -1
- package/lib/plugins/mount.d.ts +1 -1
- package/lib/plugins/mount.js +0 -1
- package/lib/plugins/tmpl-engine.d.ts +1 -1
- package/lib/plugins/tmpl-engine.js +2 -5
- package/lib/plugins/yaml-config.d.ts +1 -1
- package/lib/plugins/yaml-config.js +1 -2
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +27 -30
- package/lib/router/pattern.d.ts +1 -1
- package/lib/router/pattern.js +25 -14
- package/lib/router/plan.d.ts +1 -1
- package/lib/router/plan.js +12 -15
- package/lib/router/route.d.ts +10 -3
- package/lib/router/route.js +44 -38
- package/lib/router.d.ts +4 -4
- package/lib/router.js +25 -26
- package/lib/server/cookie.d.ts +1 -1
- package/lib/server/cookie.js +3 -2
- package/lib/server/request.d.ts +3 -3
- package/lib/server/request.js +44 -17
- package/lib/server/response.d.ts +3 -3
- package/lib/server/response.js +20 -20
- package/lib/server.d.ts +7 -2
- package/lib/server.js +70 -20
- package/lib/session.d.ts +8 -3
- package/lib/session.js +47 -29
- package/lib/sse.d.ts +10 -0
- package/lib/sse.js +62 -0
- package/lib/static.d.ts +1 -1
- package/lib/static.js +27 -22
- package/lib/types.d.ts +13 -5
- package/lib/types.js +0 -1
- package/lib/user-agent/cookie-jar.d.ts +2 -2
- package/lib/user-agent/cookie-jar.js +6 -9
- package/lib/user-agent/mock.d.ts +4 -4
- package/lib/user-agent/mock.js +6 -7
- package/lib/user-agent/response.d.ts +12 -1
- package/lib/user-agent/response.js +36 -2
- package/lib/user-agent/test.d.ts +75 -5
- package/lib/user-agent/test.js +147 -13
- package/lib/user-agent/transport/http.d.ts +2 -2
- package/lib/user-agent/transport/http.js +7 -10
- package/lib/user-agent/transport/https.d.ts +2 -2
- package/lib/user-agent/transport/https.js +2 -6
- package/lib/user-agent/transport/ws.d.ts +2 -2
- package/lib/user-agent/transport/ws.js +2 -3
- package/lib/user-agent.d.ts +21 -18
- package/lib/user-agent.js +70 -49
- package/lib/util.d.ts +13 -0
- package/lib/util.js +35 -11
- package/lib/validator/result.d.ts +1 -1
- package/lib/validator/result.js +8 -1
- package/lib/validator.d.ts +2 -2
- package/lib/validator.js +3 -6
- package/lib/websocket.d.ts +2 -2
- package/lib/websocket.js +9 -1
- package/package.json +22 -29
- package/lib/app.js.map +0 -1
- package/lib/body/params.js.map +0 -1
- package/lib/body.js.map +0 -1
- package/lib/cache.js.map +0 -1
- package/lib/cgi.js.map +0 -1
- package/lib/cli/cgi.js.map +0 -1
- package/lib/cli/create-full-app.js.map +0 -1
- package/lib/cli/create-lite-app.js.map +0 -1
- package/lib/cli/create-plugin.js.map +0 -1
- package/lib/cli/eval.js.map +0 -1
- package/lib/cli/get.js.map +0 -1
- package/lib/cli/repl.js.map +0 -1
- package/lib/cli/routes.js.map +0 -1
- package/lib/cli/server.js.map +0 -1
- package/lib/cli/version.js.map +0 -1
- package/lib/cli.js.map +0 -1
- package/lib/context.js.map +0 -1
- package/lib/core.js.map +0 -1
- package/lib/headers.js.map +0 -1
- package/lib/hooks.js.map +0 -1
- package/lib/logger.js.map +0 -1
- package/lib/mime.js.map +0 -1
- package/lib/plugins/default-conditions.js.map +0 -1
- package/lib/plugins/default-helpers.js.map +0 -1
- package/lib/plugins/json-config.js.map +0 -1
- package/lib/plugins/mount.js.map +0 -1
- package/lib/plugins/tmpl-engine.js.map +0 -1
- package/lib/plugins/yaml-config.js.map +0 -1
- package/lib/renderer.js.map +0 -1
- package/lib/router/pattern.js.map +0 -1
- package/lib/router/plan.js.map +0 -1
- package/lib/router/route.js.map +0 -1
- package/lib/router.js.map +0 -1
- package/lib/server/cookie.js.map +0 -1
- package/lib/server/request.js.map +0 -1
- package/lib/server/response.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/lib/session.js.map +0 -1
- package/lib/static.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/user-agent/cookie-jar.js.map +0 -1
- package/lib/user-agent/mock.js.map +0 -1
- package/lib/user-agent/response.js.map +0 -1
- package/lib/user-agent/test.js.map +0 -1
- package/lib/user-agent/transport/http.js.map +0 -1
- package/lib/user-agent/transport/https.js.map +0 -1
- package/lib/user-agent/transport/ws.js.map +0 -1
- package/lib/user-agent.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib/validator/result.js.map +0 -1
- package/lib/validator.js.map +0 -1
- package/lib/websocket.js.map +0 -1
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import { Body } from
|
|
1
|
+
import { Body } from "../body.js";
|
|
2
|
+
import { parseEvent } from "../sse.js";
|
|
2
3
|
/**
|
|
3
4
|
* User-agent response class.
|
|
4
5
|
*/
|
|
5
6
|
export class UserAgentResponse extends Body {
|
|
7
|
+
/**
|
|
8
|
+
* HTTP version.
|
|
9
|
+
*/
|
|
10
|
+
httpVersion;
|
|
11
|
+
/**
|
|
12
|
+
* Response status code.
|
|
13
|
+
*/
|
|
14
|
+
statusCode;
|
|
15
|
+
/**
|
|
16
|
+
* Response status message.
|
|
17
|
+
*/
|
|
18
|
+
statusMessage;
|
|
6
19
|
constructor(options) {
|
|
7
20
|
super(options.headers, options.body);
|
|
8
21
|
this.httpVersion = options.httpVersion;
|
|
@@ -43,6 +56,28 @@ export class UserAgentResponse extends Body {
|
|
|
43
56
|
const { statusCode } = this;
|
|
44
57
|
return statusCode >= 200 && statusCode <= 299;
|
|
45
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Get async iterator for Server-Sent Events from response body. Note that this method is EXPERIMENTAL and might
|
|
61
|
+
* change without warning!
|
|
62
|
+
* @example
|
|
63
|
+
* // Iterate over events
|
|
64
|
+
* for await (const {id, type, text} of res.sse()) {
|
|
65
|
+
* console.log(`${type}: ${text}`);
|
|
66
|
+
* }
|
|
67
|
+
*/
|
|
68
|
+
async *sse() {
|
|
69
|
+
const decoder = new TextDecoder();
|
|
70
|
+
let buffer = '';
|
|
71
|
+
for await (const chunk of this.createReadStream()) {
|
|
72
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
73
|
+
let [event, rest] = parseEvent(buffer);
|
|
74
|
+
while (event !== null) {
|
|
75
|
+
yield event;
|
|
76
|
+
[event, rest] = parseEvent(rest);
|
|
77
|
+
}
|
|
78
|
+
buffer = rest;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
46
81
|
/**
|
|
47
82
|
* Get `Content-Type` header value.
|
|
48
83
|
*/
|
|
@@ -50,4 +85,3 @@ export class UserAgentResponse extends Body {
|
|
|
50
85
|
return this.get('Content-Type');
|
|
51
86
|
}
|
|
52
87
|
}
|
|
53
|
-
//# sourceMappingURL=response.js.map
|
package/lib/user-agent/test.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { UserAgentResponse } from './response.
|
|
2
|
-
import type { App } from '../app.
|
|
3
|
-
import type { JSONValue, ServerOptions, TestContext, TestUserAgentOptions, UserAgentRequestOptions, UserAgentWebSocketOptions } from '../types.
|
|
4
|
-
import type { WebSocket } from '../websocket.
|
|
1
|
+
import type { UserAgentResponse } from './response.ts';
|
|
2
|
+
import type { App } from '../app.ts';
|
|
3
|
+
import type { JSONValue, SSEEvent, ServerOptions, TestContext, TestUserAgentOptions, UserAgentRequestOptions, UserAgentWebSocketOptions } from '../types.ts';
|
|
4
|
+
import type { WebSocket } from '../websocket.ts';
|
|
5
5
|
import type { URL } from 'node:url';
|
|
6
6
|
import assert from 'node:assert/strict';
|
|
7
|
-
import { MockUserAgent } from './mock.
|
|
7
|
+
import { MockUserAgent } from './mock.ts';
|
|
8
8
|
import DOM from '@mojojs/dom';
|
|
9
9
|
import StackUtils from 'stack-utils';
|
|
10
10
|
type SkipFunction = (...args: any[]) => any;
|
|
@@ -21,6 +21,8 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
21
21
|
_finished: [number, string] | null | undefined;
|
|
22
22
|
_messages: AsyncIterableIterator<JSONValue> | undefined;
|
|
23
23
|
_res: UserAgentResponse | undefined;
|
|
24
|
+
_sse: SSEEvent | undefined;
|
|
25
|
+
_sseEvents: AsyncIterator<SSEEvent> | undefined;
|
|
24
26
|
_stack: StackUtils;
|
|
25
27
|
_ws: WebSocket | undefined;
|
|
26
28
|
constructor(options?: TestUserAgentOptions);
|
|
@@ -68,6 +70,11 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
68
70
|
* Perform a `GET` request and check for transport errors.
|
|
69
71
|
*/
|
|
70
72
|
getOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
73
|
+
/**
|
|
74
|
+
* Perform a `GET` request and check for transport errors, but leave the response body for Server-Sent Events. Note
|
|
75
|
+
* that this method is EXPERIMENTAL and might change without warning!
|
|
76
|
+
*/
|
|
77
|
+
getSSEOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
71
78
|
/**
|
|
72
79
|
* Perform a `HEAD` request and check for transport errors.
|
|
73
80
|
*/
|
|
@@ -121,10 +128,19 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
121
128
|
* Perform a `POST` request and check for transport errors.
|
|
122
129
|
*/
|
|
123
130
|
postOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
131
|
+
/**
|
|
132
|
+
* Perform a `POST` request and check for transport errors, but leave the response body for Server-Sent Events. Note
|
|
133
|
+
* that this method is EXPERIMENTAL and might change without warning!
|
|
134
|
+
*/
|
|
135
|
+
postSSEOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
124
136
|
/**
|
|
125
137
|
* Perform a `PUT` request and check for transport errors.
|
|
126
138
|
*/
|
|
127
139
|
putOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
140
|
+
/**
|
|
141
|
+
* Perform a `QUERY` request and check for transport errors.
|
|
142
|
+
*/
|
|
143
|
+
queryOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
128
144
|
/**
|
|
129
145
|
* Current HTTP response.
|
|
130
146
|
*/
|
|
@@ -133,6 +149,58 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
133
149
|
* Send message or frame via WebSocket.
|
|
134
150
|
*/
|
|
135
151
|
sendOk(message: any): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Current Server-Sent Event. Note that this property is EXPERIMENTAL and might change without warning!
|
|
154
|
+
*/
|
|
155
|
+
get sse(): SSEEvent;
|
|
156
|
+
/**
|
|
157
|
+
* Close Server-Sent Events connection. Note that this method is EXPERIMENTAL and might change without warning!
|
|
158
|
+
*/
|
|
159
|
+
sseFinishOk(): Promise<this>;
|
|
160
|
+
/**
|
|
161
|
+
* Wait for Server-Sent Events connection to be closed by the server. Note that this method is EXPERIMENTAL and might
|
|
162
|
+
* change without warning!
|
|
163
|
+
*/
|
|
164
|
+
sseFinishedOk(): Promise<this>;
|
|
165
|
+
/**
|
|
166
|
+
* Check Server-Sent Event id for exact match. Note that this method is EXPERIMENTAL and might change without warning!
|
|
167
|
+
*/
|
|
168
|
+
sseIdIs(id: string | null): this;
|
|
169
|
+
/**
|
|
170
|
+
* Opposite of `sseIdIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
171
|
+
*/
|
|
172
|
+
sseIdIsnt(id: string | null): this;
|
|
173
|
+
/**
|
|
174
|
+
* Wait for next Server-Sent Event to arrive. Note that this method is EXPERIMENTAL and might change without warning!
|
|
175
|
+
*/
|
|
176
|
+
sseOk(): Promise<this>;
|
|
177
|
+
/**
|
|
178
|
+
* Check Server-Sent Event text for exact match. Note that this method is EXPERIMENTAL and might change without
|
|
179
|
+
* warning!
|
|
180
|
+
*/
|
|
181
|
+
sseTextIs(text: string): this;
|
|
182
|
+
/**
|
|
183
|
+
* Opposite of `sseTextIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
184
|
+
*/
|
|
185
|
+
sseTextIsnt(text: string): this;
|
|
186
|
+
/**
|
|
187
|
+
* Check Server-Sent Event text for similar match. Note that this method is EXPERIMENTAL and might change without
|
|
188
|
+
* warning!
|
|
189
|
+
*/
|
|
190
|
+
sseTextLike(regex: RegExp): this;
|
|
191
|
+
/**
|
|
192
|
+
* Opposite of `sseTextLike`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
193
|
+
*/
|
|
194
|
+
sseTextUnlike(regex: RegExp): this;
|
|
195
|
+
/**
|
|
196
|
+
* Check Server-Sent Event type for exact match. Note that this method is EXPERIMENTAL and might change without
|
|
197
|
+
* warning!
|
|
198
|
+
*/
|
|
199
|
+
sseTypeIs(type: string): this;
|
|
200
|
+
/**
|
|
201
|
+
* Opposite of `sseTypeIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
202
|
+
*/
|
|
203
|
+
sseTypeIsnt(type: string): this;
|
|
136
204
|
/**
|
|
137
205
|
* Check response status for exact match.
|
|
138
206
|
*/
|
|
@@ -173,6 +241,8 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
173
241
|
get _html(): DOM;
|
|
174
242
|
_prepareTap(tap: TestContext): void;
|
|
175
243
|
_requestOk(skip: SkipFunction, method: string, url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
244
|
+
get _sseIterator(): AsyncIterator<SSEEvent>;
|
|
245
|
+
_sseOk(skip: SkipFunction, method: string, url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
176
246
|
_waitFinished(): Promise<void>;
|
|
177
247
|
}
|
|
178
248
|
export {};
|
package/lib/user-agent/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { on } from 'node:events';
|
|
3
|
-
import { MockUserAgent } from
|
|
3
|
+
import { MockUserAgent } from "./mock.js";
|
|
4
4
|
import DOM from '@mojojs/dom';
|
|
5
5
|
import { jsonPointer } from '@mojojs/util';
|
|
6
6
|
import * as yaml from 'js-yaml';
|
|
@@ -18,19 +18,21 @@ function addNodeAssertMethods(tapInstance) {
|
|
|
18
18
|
* Test user-agent class.
|
|
19
19
|
*/
|
|
20
20
|
export class TestUserAgent extends MockUserAgent {
|
|
21
|
+
/**
|
|
22
|
+
* Current HTTP response content.
|
|
23
|
+
*/
|
|
24
|
+
body = Buffer.from('');
|
|
25
|
+
_assert = undefined;
|
|
26
|
+
_dom = undefined;
|
|
27
|
+
_finished = undefined;
|
|
28
|
+
_messages = undefined;
|
|
29
|
+
_res = undefined;
|
|
30
|
+
_sse = undefined;
|
|
31
|
+
_sseEvents = undefined;
|
|
32
|
+
_stack = new StackUtils();
|
|
33
|
+
_ws = undefined;
|
|
21
34
|
constructor(options = {}) {
|
|
22
35
|
super(options);
|
|
23
|
-
/**
|
|
24
|
-
* Current HTTP response content.
|
|
25
|
-
*/
|
|
26
|
-
this.body = Buffer.from('');
|
|
27
|
-
this._assert = undefined;
|
|
28
|
-
this._dom = undefined;
|
|
29
|
-
this._finished = undefined;
|
|
30
|
-
this._messages = undefined;
|
|
31
|
-
this._res = undefined;
|
|
32
|
-
this._stack = new StackUtils();
|
|
33
|
-
this._ws = undefined;
|
|
34
36
|
if (options.tap !== undefined)
|
|
35
37
|
this._prepareTap(options.tap);
|
|
36
38
|
}
|
|
@@ -113,6 +115,13 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
113
115
|
async getOk(url, options) {
|
|
114
116
|
return await this._requestOk(this.getOk, 'GET', url, options);
|
|
115
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Perform a `GET` request and check for transport errors, but leave the response body for Server-Sent Events. Note
|
|
120
|
+
* that this method is EXPERIMENTAL and might change without warning!
|
|
121
|
+
*/
|
|
122
|
+
async getSSEOk(url, options) {
|
|
123
|
+
return await this._sseOk(this.getSSEOk, 'GET', url, options);
|
|
124
|
+
}
|
|
116
125
|
/**
|
|
117
126
|
* Perform a `HEAD` request and check for transport errors.
|
|
118
127
|
*/
|
|
@@ -206,12 +215,25 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
206
215
|
async postOk(url, options) {
|
|
207
216
|
return await this._requestOk(this.postOk, 'POST', url, options);
|
|
208
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Perform a `POST` request and check for transport errors, but leave the response body for Server-Sent Events. Note
|
|
220
|
+
* that this method is EXPERIMENTAL and might change without warning!
|
|
221
|
+
*/
|
|
222
|
+
async postSSEOk(url, options) {
|
|
223
|
+
return await this._sseOk(this.postSSEOk, 'POST', url, options);
|
|
224
|
+
}
|
|
209
225
|
/**
|
|
210
226
|
* Perform a `PUT` request and check for transport errors.
|
|
211
227
|
*/
|
|
212
228
|
async putOk(url, options) {
|
|
213
229
|
return await this._requestOk(this.putOk, 'PUT', url, options);
|
|
214
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Perform a `QUERY` request and check for transport errors.
|
|
233
|
+
*/
|
|
234
|
+
async queryOk(url, options) {
|
|
235
|
+
return await this._requestOk(this.queryOk, 'QUERY', url, options);
|
|
236
|
+
}
|
|
215
237
|
/**
|
|
216
238
|
* Current HTTP response.
|
|
217
239
|
*/
|
|
@@ -228,6 +250,105 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
228
250
|
await this.ws.send(message);
|
|
229
251
|
this.assert('ok', [true], 'send message', this.sendOk);
|
|
230
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Current Server-Sent Event. Note that this property is EXPERIMENTAL and might change without warning!
|
|
255
|
+
*/
|
|
256
|
+
get sse() {
|
|
257
|
+
const sse = this._sse;
|
|
258
|
+
if (sse === undefined)
|
|
259
|
+
throw new Error('No Server-Sent Event received');
|
|
260
|
+
return sse;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Close Server-Sent Events connection. Note that this method is EXPERIMENTAL and might change without warning!
|
|
264
|
+
*/
|
|
265
|
+
async sseFinishOk() {
|
|
266
|
+
await this._sseIterator.return?.();
|
|
267
|
+
this._sseEvents = undefined;
|
|
268
|
+
this.assert('ok', [true], 'closed SSE connection', this.sseFinishOk);
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Wait for Server-Sent Events connection to be closed by the server. Note that this method is EXPERIMENTAL and might
|
|
273
|
+
* change without warning!
|
|
274
|
+
*/
|
|
275
|
+
async sseFinishedOk() {
|
|
276
|
+
const events = this._sseIterator;
|
|
277
|
+
while ((await events.next()).done !== true)
|
|
278
|
+
;
|
|
279
|
+
this._sseEvents = undefined;
|
|
280
|
+
this.assert('ok', [true], 'SSE connection has been closed', this.sseFinishedOk);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Check Server-Sent Event id for exact match. Note that this method is EXPERIMENTAL and might change without warning!
|
|
285
|
+
*/
|
|
286
|
+
sseIdIs(id) {
|
|
287
|
+
this.assert('strictEqual', [this.sse.id, id], 'exact match for SSE event id', this.sseIdIs);
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Opposite of `sseIdIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
292
|
+
*/
|
|
293
|
+
sseIdIsnt(id) {
|
|
294
|
+
this.assert('notStrictEqual', [this.sse.id, id], 'no match for SSE event id', this.sseIdIsnt);
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Wait for next Server-Sent Event to arrive. Note that this method is EXPERIMENTAL and might change without warning!
|
|
299
|
+
*/
|
|
300
|
+
async sseOk() {
|
|
301
|
+
const { done, value } = await this._sseIterator.next();
|
|
302
|
+
if (done !== true)
|
|
303
|
+
this._sse = value;
|
|
304
|
+
this.assert('ok', [done !== true], 'event received', this.sseOk);
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Check Server-Sent Event text for exact match. Note that this method is EXPERIMENTAL and might change without
|
|
309
|
+
* warning!
|
|
310
|
+
*/
|
|
311
|
+
sseTextIs(text) {
|
|
312
|
+
this.assert('strictEqual', [this.sse.text, text], 'exact match for SSE event text', this.sseTextIs);
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Opposite of `sseTextIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
317
|
+
*/
|
|
318
|
+
sseTextIsnt(text) {
|
|
319
|
+
this.assert('notStrictEqual', [this.sse.text, text], 'no match for SSE event text', this.sseTextIsnt);
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Check Server-Sent Event text for similar match. Note that this method is EXPERIMENTAL and might change without
|
|
324
|
+
* warning!
|
|
325
|
+
*/
|
|
326
|
+
sseTextLike(regex) {
|
|
327
|
+
this.assert('match', [this.sse.text, regex], 'similar match for SSE event text', this.sseTextLike);
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Opposite of `sseTextLike`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
332
|
+
*/
|
|
333
|
+
sseTextUnlike(regex) {
|
|
334
|
+
this.assert('doesNotMatch', [this.sse.text, regex], 'no similar match for SSE event text', this.sseTextUnlike);
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Check Server-Sent Event type for exact match. Note that this method is EXPERIMENTAL and might change without
|
|
339
|
+
* warning!
|
|
340
|
+
*/
|
|
341
|
+
sseTypeIs(type) {
|
|
342
|
+
this.assert('strictEqual', [this.sse.type, type], 'exact match for SSE event type', this.sseTypeIs);
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Opposite of `sseTypeIs`. Note that this method is EXPERIMENTAL and might change without warning!
|
|
347
|
+
*/
|
|
348
|
+
sseTypeIsnt(type) {
|
|
349
|
+
this.assert('notStrictEqual', [this.sse.type, type], 'no match for SSE event type', this.sseTypeIsnt);
|
|
350
|
+
return this;
|
|
351
|
+
}
|
|
231
352
|
/**
|
|
232
353
|
* Check response status for exact match.
|
|
233
354
|
*/
|
|
@@ -327,6 +448,20 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
327
448
|
this.assert('ok', [true], `${method.toUpperCase()} request for ${url.toString()}`, skip);
|
|
328
449
|
return this;
|
|
329
450
|
}
|
|
451
|
+
get _sseIterator() {
|
|
452
|
+
const events = this._sseEvents;
|
|
453
|
+
if (events === undefined)
|
|
454
|
+
throw new Error('No active SSE connection');
|
|
455
|
+
return events;
|
|
456
|
+
}
|
|
457
|
+
async _sseOk(skip, method, url, options) {
|
|
458
|
+
this._res = await this.request({ method, url, ...options });
|
|
459
|
+
this._dom = undefined;
|
|
460
|
+
this._sse = undefined;
|
|
461
|
+
this._sseEvents = this.res.sse();
|
|
462
|
+
this.assert('ok', [true], `${method.toUpperCase()} request for ${url.toString()}`, skip);
|
|
463
|
+
return this;
|
|
464
|
+
}
|
|
330
465
|
async _waitFinished() {
|
|
331
466
|
if (this._finished != null)
|
|
332
467
|
return;
|
|
@@ -337,4 +472,3 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
337
472
|
});
|
|
338
473
|
}
|
|
339
474
|
}
|
|
340
|
-
//# sourceMappingURL=test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { UserAgentRequestOptions } from '../../types.
|
|
1
|
+
import type { UserAgentRequestOptions } from '../../types.ts';
|
|
2
2
|
import type { URL } from 'node:url';
|
|
3
3
|
import http from 'node:http';
|
|
4
|
-
import { UserAgentResponse } from '../response.
|
|
4
|
+
import { UserAgentResponse } from '../response.ts';
|
|
5
5
|
/**
|
|
6
6
|
* HTTP transport class.
|
|
7
7
|
*/
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
import Stream from 'node:stream';
|
|
3
|
-
import { UserAgentResponse } from
|
|
3
|
+
import { UserAgentResponse } from "../response.js";
|
|
4
4
|
import { termEscape } from '@mojojs/util';
|
|
5
5
|
/**
|
|
6
6
|
* HTTP transport class.
|
|
7
7
|
*/
|
|
8
8
|
export class HTTPTransport {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.agent = new http.Agent();
|
|
14
|
-
}
|
|
9
|
+
/**
|
|
10
|
+
* HTTP agent.
|
|
11
|
+
*/
|
|
12
|
+
agent = new http.Agent();
|
|
15
13
|
/**
|
|
16
14
|
* Destroy active keep-alive connections.
|
|
17
15
|
*/
|
|
@@ -40,9 +38,9 @@ export class HTTPTransport {
|
|
|
40
38
|
const stderr = process.stderr;
|
|
41
39
|
socket.on('data', (chunk) => stderr.write(termEscape(`-- Client <<< Server\n${chunk}`)));
|
|
42
40
|
const write = socket.write;
|
|
43
|
-
socket.write = (chunk,
|
|
41
|
+
socket.write = (chunk, ...args) => {
|
|
44
42
|
stderr.write(termEscape(`-- Client >>> Server\n${chunk}`));
|
|
45
|
-
return write.apply(socket, [chunk,
|
|
43
|
+
return write.apply(socket, [chunk, ...args]);
|
|
46
44
|
};
|
|
47
45
|
});
|
|
48
46
|
}
|
|
@@ -75,4 +73,3 @@ export class HTTPTransport {
|
|
|
75
73
|
return http.request(url, options, cb);
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
|
-
//# sourceMappingURL=http.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { UserAgentRequestOptions } from '../../types.
|
|
1
|
+
import type { UserAgentRequestOptions } from '../../types.ts';
|
|
2
2
|
import type http from 'node:http';
|
|
3
3
|
import type { URL } from 'node:url';
|
|
4
4
|
import https from 'node:https';
|
|
5
|
-
import { HTTPTransport } from './http.
|
|
5
|
+
import { HTTPTransport } from './http.ts';
|
|
6
6
|
/**
|
|
7
7
|
* HTTPS transport class.
|
|
8
8
|
*/
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import https from 'node:https';
|
|
2
|
-
import { HTTPTransport } from
|
|
2
|
+
import { HTTPTransport } from "./http.js";
|
|
3
3
|
/**
|
|
4
4
|
* HTTPS transport class.
|
|
5
5
|
*/
|
|
6
6
|
export class HTTPSTransport extends HTTPTransport {
|
|
7
|
-
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.agent = new https.Agent();
|
|
10
|
-
}
|
|
7
|
+
agent = new https.Agent();
|
|
11
8
|
_prepareOptions(config) {
|
|
12
9
|
const options = super._prepareOptions(config);
|
|
13
10
|
if (config.ca !== undefined)
|
|
@@ -22,4 +19,3 @@ export class HTTPSTransport extends HTTPTransport {
|
|
|
22
19
|
return https.request(url, options, cb);
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
//# sourceMappingURL=https.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { UserAgentWebSocketOptions } from '../../types.
|
|
2
|
-
import { WebSocket } from '../../websocket.
|
|
1
|
+
import type { UserAgentWebSocketOptions } from '../../types.ts';
|
|
2
|
+
import { WebSocket } from '../../websocket.ts';
|
|
3
3
|
/**
|
|
4
4
|
* WebSocket transport class.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebSocket } from
|
|
2
|
-
import { UserAgentResponse } from
|
|
1
|
+
import { WebSocket } from "../../websocket.js";
|
|
2
|
+
import { UserAgentResponse } from "../response.js";
|
|
3
3
|
import WS from 'ws';
|
|
4
4
|
/**
|
|
5
5
|
* WebSocket transport class.
|
|
@@ -37,4 +37,3 @@ export class WSTransport {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
//# sourceMappingURL=ws.js.map
|
package/lib/user-agent.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { UserAgentOptions, UserAgentRequestOptions, UserAgentWebSocketOptions } from './types.
|
|
2
|
-
import type { UserAgentResponse } from './user-agent/response.
|
|
3
|
-
import type { WebSocket } from './websocket.
|
|
1
|
+
import type { UserAgentOptions, UserAgentRequestOptions, UserAgentWebSocketOptions } from './types.ts';
|
|
2
|
+
import type { UserAgentResponse } from './user-agent/response.ts';
|
|
3
|
+
import type { WebSocket } from './websocket.ts';
|
|
4
4
|
import { URL } from 'node:url';
|
|
5
|
-
import { CookieJar } from './user-agent/cookie-jar.
|
|
6
|
-
import { HTTPTransport } from './user-agent/transport/http.
|
|
7
|
-
import { HTTPSTransport } from './user-agent/transport/https.
|
|
8
|
-
import { WSTransport } from './user-agent/transport/ws.
|
|
5
|
+
import { CookieJar } from './user-agent/cookie-jar.ts';
|
|
6
|
+
import { HTTPTransport } from './user-agent/transport/http.ts';
|
|
7
|
+
import { HTTPSTransport } from './user-agent/transport/https.ts';
|
|
8
|
+
import { WSTransport } from './user-agent/transport/ws.ts';
|
|
9
9
|
import { AsyncHooks } from '@mojojs/util';
|
|
10
|
-
import FormData from 'form-data';
|
|
11
10
|
interface Upload {
|
|
12
11
|
content: string;
|
|
13
12
|
filename: string;
|
|
14
|
-
type
|
|
13
|
+
type?: string;
|
|
15
14
|
}
|
|
16
15
|
type UserAgentHook = (ua: UserAgent, ...args: any[]) => any;
|
|
17
16
|
/**
|
|
@@ -63,31 +62,35 @@ declare class UserAgent {
|
|
|
63
62
|
/**
|
|
64
63
|
* Perform `DELETE` request.
|
|
65
64
|
*/
|
|
66
|
-
delete(url: string | URL, options
|
|
65
|
+
delete(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
67
66
|
/**
|
|
68
67
|
* Perform `GET` request.
|
|
69
68
|
*/
|
|
70
|
-
get(url: string | URL, options
|
|
69
|
+
get(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
71
70
|
/**
|
|
72
71
|
* Perform `HEAD` request.
|
|
73
72
|
*/
|
|
74
|
-
head(url: string | URL, options
|
|
73
|
+
head(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
75
74
|
/**
|
|
76
75
|
* Perform `OPTIONS` request.
|
|
77
76
|
*/
|
|
78
|
-
options(url: string | URL, options
|
|
77
|
+
options(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
79
78
|
/**
|
|
80
79
|
* Perform `PATCH` request.
|
|
81
80
|
*/
|
|
82
|
-
patch(url: string | URL, options
|
|
81
|
+
patch(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
83
82
|
/**
|
|
84
83
|
* Perform `POST` request.
|
|
85
84
|
*/
|
|
86
|
-
post(url: string | URL, options
|
|
85
|
+
post(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
87
86
|
/**
|
|
88
87
|
* Perform `PUT` request.
|
|
89
88
|
*/
|
|
90
|
-
put(url: string | URL, options
|
|
89
|
+
put(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Perform `QUERY` request.
|
|
92
|
+
*/
|
|
93
|
+
query(url: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
91
94
|
/**
|
|
92
95
|
* Perform HTTP request.
|
|
93
96
|
*/
|
|
@@ -97,9 +100,9 @@ declare class UserAgent {
|
|
|
97
100
|
*/
|
|
98
101
|
websocket(url: string | URL, options?: UserAgentWebSocketOptions): Promise<WebSocket>;
|
|
99
102
|
_filterConfig(config: UserAgentRequestOptions): Promise<Record<string, any>>;
|
|
100
|
-
_filterSharedConfig(
|
|
103
|
+
_filterSharedConfig(options: UserAgentRequestOptions | UserAgentWebSocketOptions): Promise<Record<string, any>>;
|
|
101
104
|
_formData(values?: Record<string, string | Upload>): FormData;
|
|
102
|
-
_handleRedirect(config: Record<string, any>, res: UserAgentResponse): Promise<UserAgentResponse>;
|
|
105
|
+
_handleRedirect(config: Record<string, any>, base: URL, res: UserAgentResponse): Promise<UserAgentResponse>;
|
|
103
106
|
_requestConfig(method: string, url?: string | URL, options?: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
104
107
|
}
|
|
105
108
|
export { UserAgent };
|