@mswjs/interceptors 0.19.4 → 0.20.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/lib/BatchInterceptor.d.ts +5 -5
- package/lib/BatchInterceptor.js +14 -59
- package/lib/BatchInterceptor.js.map +1 -1
- package/lib/Interceptor.d.ts +7 -6
- package/lib/Interceptor.js +39 -64
- package/lib/Interceptor.js.map +1 -1
- package/lib/RemoteHttpInterceptor.js +115 -209
- package/lib/RemoteHttpInterceptor.js.map +1 -1
- package/lib/glossary.d.ts +2 -2
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +141 -278
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.get.js +5 -34
- package/lib/interceptors/ClientRequest/http.get.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.request.js +6 -35
- package/lib/interceptors/ClientRequest/http.request.js.map +1 -1
- package/lib/interceptors/ClientRequest/index.js +22 -82
- package/lib/interceptors/ClientRequest/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +18 -62
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/createRequest.js +10 -32
- package/lib/interceptors/ClientRequest/utils/createRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/createResponse.js +6 -6
- package/lib/interceptors/ClientRequest/utils/createResponse.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +12 -12
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +21 -52
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +5 -9
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +6 -6
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.d.ts +44 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js +413 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js.map +1 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.d.ts +20 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js +75 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js.map +1 -0
- package/lib/interceptors/XMLHttpRequest/index.js +23 -42
- package/lib/interceptors/XMLHttpRequest/index.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +11 -12
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +9 -27
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +7 -7
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +2 -2
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +2 -2
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +1 -1
- package/lib/interceptors/fetch/index.js +52 -125
- package/lib/interceptors/fetch/index.js.map +1 -1
- package/lib/presets/browser.js +2 -2
- package/lib/presets/browser.js.map +1 -1
- package/lib/presets/node.js +2 -2
- package/lib/presets/node.js.map +1 -1
- package/lib/utils/AsyncEventEmitter.d.ts +9 -8
- package/lib/utils/AsyncEventEmitter.js +84 -190
- package/lib/utils/AsyncEventEmitter.js.map +1 -1
- package/lib/utils/bufferUtils.js +3 -3
- package/lib/utils/bufferUtils.js.map +1 -1
- package/lib/utils/cloneObject.js +2 -19
- package/lib/utils/cloneObject.js.map +1 -1
- package/lib/utils/createLazyCallback.js +14 -49
- package/lib/utils/createLazyCallback.js.map +1 -1
- package/lib/utils/createProxy.d.ts +8 -0
- package/lib/utils/createProxy.js +45 -0
- package/lib/utils/createProxy.js.map +1 -0
- package/lib/utils/getCleanUrl.js +1 -2
- package/lib/utils/getCleanUrl.js.map +1 -1
- package/lib/utils/getRequestOptionsByUrl.js +3 -3
- package/lib/utils/getRequestOptionsByUrl.js.map +1 -1
- package/lib/utils/getUrlByRequestOptions.js +23 -39
- package/lib/utils/getUrlByRequestOptions.js.map +1 -1
- package/lib/utils/nextTick.js +2 -2
- package/lib/utils/nextTick.js.map +1 -1
- package/lib/utils/parseJson.js +1 -1
- package/lib/utils/parseJson.js.map +1 -1
- package/lib/utils/toInteractiveRequest.js +3 -3
- package/lib/utils/toInteractiveRequest.js.map +1 -1
- package/lib/utils/uuid.js +2 -2
- package/lib/utils/uuid.js.map +1 -1
- package/package.json +2 -2
- package/src/BatchInterceptor.test.ts +2 -2
- package/src/BatchInterceptor.ts +14 -13
- package/src/Interceptor.ts +12 -11
- package/src/glossary.ts +2 -6
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +578 -0
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +111 -0
- package/src/interceptors/XMLHttpRequest/index.ts +12 -13
- package/src/utils/AsyncEventEmitter.test.ts +6 -6
- package/src/utils/AsyncEventEmitter.ts +60 -50
- package/src/utils/createProxy.ts +78 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +0 -93
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +0 -567
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +0 -1
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +0 -684
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRequestOptionsByUrl.js","sourceRoot":"","sources":["../../src/utils/getRequestOptionsByUrl.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,GAAQ;IAC7C,
|
|
1
|
+
{"version":3,"file":"getRequestOptionsByUrl.js","sourceRoot":"","sources":["../../src/utils/getRequestOptionsByUrl.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,GAAQ;IAC7C,MAAM,OAAO,GAAmB;QAC9B,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,QAAQ,EACN,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;YAC9D,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC,CAAC,GAAG,CAAC,QAAQ;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE;KAC3C,CAAA;IAED,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE;QACd,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;KAChC;IAED,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE;QAChC,OAAO,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAA;KACjD;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AArBD,wDAqBC"}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.getUrlByRequestOptions = exports.DEFAULT_PATH = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
const http_1 = require("http");
|
|
5
|
+
const debug = require('debug')('utils getUrlByRequestOptions');
|
|
22
6
|
exports.DEFAULT_PATH = '/';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
const DEFAULT_PROTOCOL = 'http:';
|
|
8
|
+
const DEFAULT_HOST = 'localhost';
|
|
9
|
+
const DEFAULT_PORT = 80;
|
|
10
|
+
const SSL_PORT = 443;
|
|
27
11
|
function getAgent(options) {
|
|
28
12
|
return options.agent instanceof http_1.Agent ? options.agent : undefined;
|
|
29
13
|
}
|
|
@@ -32,23 +16,23 @@ function getProtocolByRequestOptions(options) {
|
|
|
32
16
|
if (options.protocol) {
|
|
33
17
|
return options.protocol;
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
const agent = getAgent(options);
|
|
20
|
+
const agentProtocol = (_a = agent) === null || _a === void 0 ? void 0 : _a.protocol;
|
|
37
21
|
if (agentProtocol) {
|
|
38
22
|
return agentProtocol;
|
|
39
23
|
}
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
const port = getPortByRequestOptions(options);
|
|
25
|
+
const isSecureRequest = options.cert || port === SSL_PORT;
|
|
42
26
|
return isSecureRequest ? 'https:' : ((_b = options.uri) === null || _b === void 0 ? void 0 : _b.protocol) || DEFAULT_PROTOCOL;
|
|
43
27
|
}
|
|
44
28
|
function getPortByRequestOptions(options) {
|
|
45
29
|
var _a, _b;
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
const agent = getAgent(options);
|
|
31
|
+
const agentPort = ((_a = agent) === null || _a === void 0 ? void 0 : _a.options.port) ||
|
|
48
32
|
((_b = agent) === null || _b === void 0 ? void 0 : _b.defaultPort);
|
|
49
|
-
|
|
33
|
+
const optionsPort = options.port;
|
|
50
34
|
if (optionsPort || agentPort) {
|
|
51
|
-
|
|
35
|
+
const explicitPort = optionsPort || agentPort || DEFAULT_PORT;
|
|
52
36
|
return Number(explicitPort);
|
|
53
37
|
}
|
|
54
38
|
}
|
|
@@ -57,8 +41,8 @@ function getHostByRequestOptions(options) {
|
|
|
57
41
|
}
|
|
58
42
|
function getAuthByRequestOptions(options) {
|
|
59
43
|
if (options.auth) {
|
|
60
|
-
|
|
61
|
-
return { username
|
|
44
|
+
const [username, password] = options.auth.split(':');
|
|
45
|
+
return { username, password };
|
|
62
46
|
}
|
|
63
47
|
}
|
|
64
48
|
/**
|
|
@@ -66,18 +50,18 @@ function getAuthByRequestOptions(options) {
|
|
|
66
50
|
*/
|
|
67
51
|
function getUrlByRequestOptions(options) {
|
|
68
52
|
debug('request options', options);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
const protocol = getProtocolByRequestOptions(options);
|
|
54
|
+
const host = getHostByRequestOptions(options);
|
|
55
|
+
const port = getPortByRequestOptions(options);
|
|
56
|
+
const path = options.path || exports.DEFAULT_PATH;
|
|
57
|
+
const auth = getAuthByRequestOptions(options);
|
|
74
58
|
debug('protocol', protocol);
|
|
75
59
|
debug('host', host);
|
|
76
60
|
debug('port', port);
|
|
77
61
|
debug('path', path);
|
|
78
|
-
|
|
62
|
+
const baseUrl = `${protocol}//${host}`;
|
|
79
63
|
debug('base URL:', baseUrl);
|
|
80
|
-
|
|
64
|
+
const url = options.uri ? new URL(options.uri.href) : new URL(path, baseUrl);
|
|
81
65
|
if (port) {
|
|
82
66
|
debug('detected explicit port', port);
|
|
83
67
|
url.port = port.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUrlByRequestOptions.js","sourceRoot":"","sources":["../../src/utils/getUrlByRequestOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getUrlByRequestOptions.js","sourceRoot":"","sources":["../../src/utils/getUrlByRequestOptions.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAG5B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,8BAA8B,CAAC,CAAA;AAWjD,QAAA,YAAY,GAAG,GAAG,CAAA;AAC/B,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAChC,MAAM,YAAY,GAAG,WAAW,CAAA;AAChC,MAAM,YAAY,GAAG,EAAE,CAAA;AACvB,MAAM,QAAQ,GAAG,GAAG,CAAA;AAEpB,SAAS,QAAQ,CACf,OAA+B;IAE/B,OAAO,OAAO,CAAC,KAAK,YAAY,YAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AACnE,CAAC;AAED,SAAS,2BAA2B,CAAC,OAA+B;;IAClE,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,OAAO,CAAC,QAAQ,CAAA;KACxB;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC/B,MAAM,aAAa,GAAG,MAAC,KAAwB,0CAAE,QAAQ,CAAA;IAEzD,IAAI,aAAa,EAAE;QACjB,OAAO,aAAa,CAAA;KACrB;IAED,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,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-
return new Promise(
|
|
10
|
-
setTimeout(
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
setTimeout(() => {
|
|
11
11
|
resolve(callback());
|
|
12
12
|
}, 0);
|
|
13
13
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextTick.js","sourceRoot":"","sources":["../../src/utils/nextTick.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,QAAoB;IAC3C,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AACzB,CAAC;AAFD,4BAEC;AAED,SAAgB,aAAa,CAAC,QAAoB;IAChD,OAAO,IAAI,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"nextTick.js","sourceRoot":"","sources":["../../src/utils/nextTick.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,QAAoB;IAC3C,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AACzB,CAAC;AAFD,4BAEC;AAED,SAAgB,aAAa,CAAC,QAAoB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACrB,CAAC,EAAE,CAAC,CAAC,CAAA;IACP,CAAC,CAAC,CAAA;AACJ,CAAC;AAND,sCAMC"}
|
package/lib/utils/parseJson.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseJson.js","sourceRoot":"","sources":["../../src/utils/parseJson.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAY;IACpC,IAAI;QACF,
|
|
1
|
+
{"version":3,"file":"parseJson.js","sourceRoot":"","sources":["../../src/utils/parseJson.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAY;IACpC,IAAI;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;KACZ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAPD,8BAOC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toInteractiveRequest = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const outvariant_1 = require("outvariant");
|
|
5
|
+
const createLazyCallback_1 = require("./createLazyCallback");
|
|
6
6
|
function toInteractiveRequest(request) {
|
|
7
7
|
Object.defineProperty(request, 'respondWith', {
|
|
8
8
|
writable: false,
|
|
9
9
|
enumerable: true,
|
|
10
10
|
value: (0, createLazyCallback_1.createLazyCallback)({
|
|
11
11
|
maxCalls: 1,
|
|
12
|
-
maxCallsCallback
|
|
12
|
+
maxCallsCallback() {
|
|
13
13
|
throw new Error((0, outvariant_1.format)('Failed to respond to "%s %s" request: the "request" event has already been responded to.', request.method, request.url));
|
|
14
14
|
},
|
|
15
15
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toInteractiveRequest.js","sourceRoot":"","sources":["../../src/utils/toInteractiveRequest.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"toInteractiveRequest.js","sourceRoot":"","sources":["../../src/utils/toInteractiveRequest.ts"],"names":[],"mappings":";;;AAAA,2CAAmC;AACnC,6DAAuE;AAQvE,SAAgB,oBAAoB,CAAC,OAAgB;IACnD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;QAC5C,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,IAAA,uCAAkB,EAAuB;YAC9C,QAAQ,EAAE,CAAC;YACX,gBAAgB;gBACd,MAAM,IAAI,KAAK,CACb,IAAA,mBAAM,EACJ,0FAA0F,EAC1F,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,GAAG,CACZ,CACF,CAAA;YACH,CAAC;SACF,CAAC;KACH,CAAC,CAAA;IAEF,OAAO,OAA6B,CAAA;AACtC,CAAC;AAnBD,oDAmBC"}
|
package/lib/utils/uuid.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.uuidv4 = void 0;
|
|
4
4
|
function uuidv4() {
|
|
5
5
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const r = (Math.random() * 16) | 0;
|
|
7
|
+
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
8
8
|
return v.toString(16);
|
|
9
9
|
});
|
|
10
10
|
}
|
package/lib/utils/uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM;IACpB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;QACxE,
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/utils/uuid.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM;IACpB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;QAClC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;QACxC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC;AAND,wBAMC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mswjs/interceptors",
|
|
3
3
|
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"author": "Artem Zakharchenko",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"debug": "^4.3.3",
|
|
72
72
|
"headers-polyfill": "^3.1.0",
|
|
73
73
|
"outvariant": "^1.2.1",
|
|
74
|
-
"strict-event-emitter": "^0.
|
|
74
|
+
"strict-event-emitter": "^0.4.6",
|
|
75
75
|
"web-encoding": "^1.1.5"
|
|
76
76
|
},
|
|
77
77
|
"keywords": [
|
|
@@ -38,14 +38,14 @@ it('applies child interceptors', () => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
it('proxies event listeners to the interceptors', () => {
|
|
41
|
-
class PrimaryInterceptor extends Interceptor<{ hello
|
|
41
|
+
class PrimaryInterceptor extends Interceptor<{ hello: [string] }> {
|
|
42
42
|
constructor() {
|
|
43
43
|
super(Symbol('primary'))
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
class SecondaryInterceptor extends Interceptor<{
|
|
48
|
-
goodbye
|
|
48
|
+
goodbye: [string]
|
|
49
49
|
}> {
|
|
50
50
|
constructor() {
|
|
51
51
|
super(Symbol('secondary'))
|
package/src/BatchInterceptor.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventMap, Listener } from 'strict-event-emitter'
|
|
2
2
|
import { ExtractEventNames, Interceptor } from './Interceptor'
|
|
3
3
|
|
|
4
4
|
export interface BatchInterceptorOptions<
|
|
5
|
-
InterceptorList extends Interceptor<any
|
|
5
|
+
InterceptorList extends Array<Interceptor<any>>
|
|
6
6
|
> {
|
|
7
7
|
name: string
|
|
8
8
|
interceptors: InterceptorList
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type ExtractEventMapType<
|
|
12
|
-
InterceptorList extends Array<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export type ExtractEventMapType<
|
|
12
|
+
InterceptorList extends Array<Interceptor<any>>
|
|
13
|
+
> = InterceptorList extends Array<infer InterceptorType>
|
|
14
|
+
? InterceptorType extends Interceptor<infer EventMap>
|
|
15
|
+
? EventMap
|
|
16
16
|
: never
|
|
17
|
+
: never
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* A batch interceptor that exposes a single interface
|
|
20
21
|
* to apply and operate with multiple interceptors at once.
|
|
21
22
|
*/
|
|
22
23
|
export class BatchInterceptor<
|
|
23
|
-
InterceptorList extends Interceptor<any
|
|
24
|
-
|
|
25
|
-
> extends Interceptor<
|
|
24
|
+
InterceptorList extends Array<Interceptor<any>>,
|
|
25
|
+
Events extends EventMap = ExtractEventMapType<InterceptorList>
|
|
26
|
+
> extends Interceptor<Events> {
|
|
26
27
|
static symbol: Symbol
|
|
27
28
|
|
|
28
29
|
private interceptors: InterceptorList
|
|
@@ -47,9 +48,9 @@ export class BatchInterceptor<
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
public on<
|
|
51
|
-
event:
|
|
52
|
-
listener:
|
|
51
|
+
public on<EventName extends ExtractEventNames<Events>>(
|
|
52
|
+
event: EventName,
|
|
53
|
+
listener: Listener<Events[EventName]>
|
|
53
54
|
) {
|
|
54
55
|
// Instead of adding a listener to the batch interceptor,
|
|
55
56
|
// propagate the listener to each of the individual interceptors.
|
package/src/Interceptor.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Debugger, debug } from 'debug'
|
|
2
|
+
import { Listener } from 'strict-event-emitter'
|
|
2
3
|
import { AsyncEventEmitter } from './utils/AsyncEventEmitter'
|
|
3
4
|
import { nextTick } from './utils/nextTick'
|
|
4
5
|
|
|
5
|
-
export type InterceptorEventMap = Record<string,
|
|
6
|
+
export type InterceptorEventMap = Record<string, any>
|
|
6
7
|
export type InterceptorSubscription = () => void
|
|
7
8
|
|
|
8
9
|
export function getGlobalSymbol<V>(symbol: Symbol): V | undefined {
|
|
@@ -30,12 +31,12 @@ export enum InterceptorReadyState {
|
|
|
30
31
|
DISPOSED = 'DISPOSED',
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export type ExtractEventNames<
|
|
34
|
-
|
|
34
|
+
export type ExtractEventNames<Events extends Record<string, any>> =
|
|
35
|
+
Events extends Record<infer EventName, any> ? EventName : never
|
|
35
36
|
|
|
36
|
-
export class Interceptor<
|
|
37
|
-
protected emitter: AsyncEventEmitter<
|
|
38
|
-
protected subscriptions: InterceptorSubscription
|
|
37
|
+
export class Interceptor<Events extends InterceptorEventMap> {
|
|
38
|
+
protected emitter: AsyncEventEmitter<Events>
|
|
39
|
+
protected subscriptions: Array<InterceptorSubscription>
|
|
39
40
|
protected log: Debugger
|
|
40
41
|
|
|
41
42
|
public readyState: InterceptorReadyState
|
|
@@ -144,9 +145,9 @@ export class Interceptor<EventMap extends InterceptorEventMap> {
|
|
|
144
145
|
/**
|
|
145
146
|
* Listen to the interceptor's public events.
|
|
146
147
|
*/
|
|
147
|
-
public on<
|
|
148
|
-
|
|
149
|
-
listener:
|
|
148
|
+
public on<EventName extends ExtractEventNames<Events>>(
|
|
149
|
+
eventName: EventName,
|
|
150
|
+
listener: Listener<Events[EventName]>
|
|
150
151
|
): void {
|
|
151
152
|
const log = this.log.extend('on')
|
|
152
153
|
|
|
@@ -158,9 +159,9 @@ export class Interceptor<EventMap extends InterceptorEventMap> {
|
|
|
158
159
|
return
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
log('adding "%s" event listener:',
|
|
162
|
+
log('adding "%s" event listener:', eventName, listener.name)
|
|
162
163
|
|
|
163
|
-
this.emitter.on(
|
|
164
|
+
this.emitter.on(eventName, listener)
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
/**
|
package/src/glossary.ts
CHANGED
|
@@ -5,10 +5,6 @@ export const IS_PATCHED_MODULE: unique symbol = Symbol('isPatchedModule')
|
|
|
5
5
|
export type RequestCredentials = 'omit' | 'include' | 'same-origin'
|
|
6
6
|
|
|
7
7
|
export type HttpRequestEventMap = {
|
|
8
|
-
request
|
|
9
|
-
response
|
|
10
|
-
response: Response,
|
|
11
|
-
request: Request,
|
|
12
|
-
requestId: string
|
|
13
|
-
): Promise<void> | void
|
|
8
|
+
request: [request: InteractiveRequest, requestId: string]
|
|
9
|
+
response: [response: Response, request: Request, requestId: string]
|
|
14
10
|
}
|