@mswjs/interceptors 0.19.4 → 0.19.5
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/XMLHttpRequestOverride.js +213 -338
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/index.js +16 -33
- 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/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/utils/AsyncEventEmitter.test.ts +6 -6
- package/src/utils/AsyncEventEmitter.ts +60 -50
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventMap, Listener } from 'strict-event-emitter';
|
|
2
2
|
import { ExtractEventNames, Interceptor } from './Interceptor';
|
|
3
|
-
export interface BatchInterceptorOptions<InterceptorList extends Interceptor<any
|
|
3
|
+
export interface BatchInterceptorOptions<InterceptorList extends Array<Interceptor<any>>> {
|
|
4
4
|
name: string;
|
|
5
5
|
interceptors: InterceptorList;
|
|
6
6
|
}
|
|
7
|
-
export declare type ExtractEventMapType<InterceptorList extends Interceptor<any
|
|
7
|
+
export declare type ExtractEventMapType<InterceptorList extends Array<Interceptor<any>>> = InterceptorList extends Array<infer InterceptorType> ? InterceptorType extends Interceptor<infer EventMap> ? EventMap : never : never;
|
|
8
8
|
/**
|
|
9
9
|
* A batch interceptor that exposes a single interface
|
|
10
10
|
* to apply and operate with multiple interceptors at once.
|
|
11
11
|
*/
|
|
12
|
-
export declare class BatchInterceptor<InterceptorList extends Interceptor<any
|
|
12
|
+
export declare class BatchInterceptor<InterceptorList extends Array<Interceptor<any>>, Events extends EventMap = ExtractEventMapType<InterceptorList>> extends Interceptor<Events> {
|
|
13
13
|
static symbol: Symbol;
|
|
14
14
|
private interceptors;
|
|
15
15
|
constructor(options: BatchInterceptorOptions<InterceptorList>);
|
|
16
16
|
protected setup(): void;
|
|
17
|
-
on<
|
|
17
|
+
on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): void;
|
|
18
18
|
}
|
package/lib/BatchInterceptor.js
CHANGED
|
@@ -1,79 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
exports.BatchInterceptor = void 0;
|
|
30
|
-
|
|
4
|
+
const Interceptor_1 = require("./Interceptor");
|
|
31
5
|
/**
|
|
32
6
|
* A batch interceptor that exposes a single interface
|
|
33
7
|
* to apply and operate with multiple interceptors at once.
|
|
34
8
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function BatchInterceptor(options) {
|
|
38
|
-
var _this = this;
|
|
9
|
+
class BatchInterceptor extends Interceptor_1.Interceptor {
|
|
10
|
+
constructor(options) {
|
|
39
11
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return _this;
|
|
12
|
+
super(BatchInterceptor.symbol);
|
|
13
|
+
this.interceptors = options.interceptors;
|
|
43
14
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var log = this.log.extend('setup');
|
|
15
|
+
setup() {
|
|
16
|
+
const log = this.log.extend('setup');
|
|
47
17
|
log('applying all %d interceptors...', this.interceptors.length);
|
|
48
|
-
|
|
18
|
+
for (const interceptor of this.interceptors) {
|
|
49
19
|
log('applying "%s" interceptor...', interceptor.constructor.name);
|
|
50
20
|
interceptor.apply();
|
|
51
21
|
log('adding interceptor dispose subscription');
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
var this_1 = this;
|
|
55
|
-
try {
|
|
56
|
-
for (var _b = __values(this.interceptors), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
57
|
-
var interceptor = _c.value;
|
|
58
|
-
_loop_1(interceptor);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
62
|
-
finally {
|
|
63
|
-
try {
|
|
64
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
65
|
-
}
|
|
66
|
-
finally { if (e_1) throw e_1.error; }
|
|
22
|
+
this.subscriptions.push(() => interceptor.dispose());
|
|
67
23
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
24
|
+
}
|
|
25
|
+
on(event, listener) {
|
|
70
26
|
// Instead of adding a listener to the batch interceptor,
|
|
71
27
|
// propagate the listener to each of the individual interceptors.
|
|
72
|
-
this.interceptors.forEach(
|
|
28
|
+
this.interceptors.forEach((interceptor) => {
|
|
73
29
|
interceptor.on(event, listener);
|
|
74
30
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
}(Interceptor_1.Interceptor));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
78
33
|
exports.BatchInterceptor = BatchInterceptor;
|
|
79
34
|
//# sourceMappingURL=BatchInterceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BatchInterceptor.js","sourceRoot":"","sources":["../src/BatchInterceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BatchInterceptor.js","sourceRoot":"","sources":["../src/BatchInterceptor.ts"],"names":[],"mappings":";;;AACA,+CAA8D;AAiB9D;;;GAGG;AACH,MAAa,gBAGX,SAAQ,yBAAmB;IAK3B,YAAY,OAAiD;QAC3D,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9C,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;IAC1C,CAAC;IAES,KAAK;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAEpC,GAAG,CAAC,iCAAiC,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAEhE,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE;YAC3C,GAAG,CAAC,8BAA8B,EAAE,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YACjE,WAAW,CAAC,KAAK,EAAE,CAAA;YAEnB,GAAG,CAAC,yCAAyC,CAAC,CAAA;YAC9C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;SACrD;IACH,CAAC;IAEM,EAAE,CACP,KAAgB,EAChB,QAAqC;QAErC,yDAAyD;QACzD,iEAAiE;QACjE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;YACxC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAtCD,4CAsCC"}
|
package/lib/Interceptor.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Debugger } from 'debug';
|
|
2
|
+
import { Listener } from 'strict-event-emitter';
|
|
2
3
|
import { AsyncEventEmitter } from './utils/AsyncEventEmitter';
|
|
3
|
-
export declare type InterceptorEventMap = Record<string,
|
|
4
|
+
export declare type InterceptorEventMap = Record<string, any>;
|
|
4
5
|
export declare type InterceptorSubscription = () => void;
|
|
5
6
|
export declare function getGlobalSymbol<V>(symbol: Symbol): V | undefined;
|
|
6
7
|
export declare function deleteGlobalSymbol(symbol: Symbol): void;
|
|
@@ -11,11 +12,11 @@ export declare enum InterceptorReadyState {
|
|
|
11
12
|
DISPOSING = "DISPOSING",
|
|
12
13
|
DISPOSED = "DISPOSED"
|
|
13
14
|
}
|
|
14
|
-
export declare type ExtractEventNames<
|
|
15
|
-
export declare class Interceptor<
|
|
15
|
+
export declare type ExtractEventNames<Events extends Record<string, any>> = Events extends Record<infer EventName, any> ? EventName : never;
|
|
16
|
+
export declare class Interceptor<Events extends InterceptorEventMap> {
|
|
16
17
|
private readonly symbol;
|
|
17
|
-
protected emitter: AsyncEventEmitter<
|
|
18
|
-
protected subscriptions: InterceptorSubscription
|
|
18
|
+
protected emitter: AsyncEventEmitter<Events>;
|
|
19
|
+
protected subscriptions: Array<InterceptorSubscription>;
|
|
19
20
|
protected log: Debugger;
|
|
20
21
|
readyState: InterceptorReadyState;
|
|
21
22
|
constructor(symbol: Symbol);
|
|
@@ -38,7 +39,7 @@ export declare class Interceptor<EventMap extends InterceptorEventMap> {
|
|
|
38
39
|
/**
|
|
39
40
|
* Listen to the interceptor's public events.
|
|
40
41
|
*/
|
|
41
|
-
on<
|
|
42
|
+
on<EventName extends ExtractEventNames<Events>>(eventName: EventName, listener: Listener<Events[EventName]>): void;
|
|
42
43
|
/**
|
|
43
44
|
* Disposes of any side-effects this interceptor has introduced.
|
|
44
45
|
*/
|
package/lib/Interceptor.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.Interceptor = exports.InterceptorReadyState = exports.deleteGlobalSymbol = exports.getGlobalSymbol = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const debug_1 = require("debug");
|
|
5
|
+
const AsyncEventEmitter_1 = require("./utils/AsyncEventEmitter");
|
|
6
|
+
const nextTick_1 = require("./utils/nextTick");
|
|
18
7
|
function getGlobalSymbol(symbol) {
|
|
19
8
|
return (
|
|
20
9
|
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
@@ -38,8 +27,8 @@ var InterceptorReadyState;
|
|
|
38
27
|
InterceptorReadyState["DISPOSING"] = "DISPOSING";
|
|
39
28
|
InterceptorReadyState["DISPOSED"] = "DISPOSED";
|
|
40
29
|
})(InterceptorReadyState = exports.InterceptorReadyState || (exports.InterceptorReadyState = {}));
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
class Interceptor {
|
|
31
|
+
constructor(symbol) {
|
|
43
32
|
this.symbol = symbol;
|
|
44
33
|
this.readyState = InterceptorReadyState.INACTIVE;
|
|
45
34
|
this.emitter = new AsyncEventEmitter_1.AsyncEventEmitter();
|
|
@@ -54,22 +43,21 @@ var Interceptor = /** @class */ (function () {
|
|
|
54
43
|
* Determine if this interceptor can be applied
|
|
55
44
|
* in the current environment.
|
|
56
45
|
*/
|
|
57
|
-
|
|
46
|
+
checkEnvironment() {
|
|
58
47
|
return true;
|
|
59
|
-
}
|
|
48
|
+
}
|
|
60
49
|
/**
|
|
61
50
|
* Apply this interceptor to the current process.
|
|
62
51
|
* Returns an already running interceptor instance if it's present.
|
|
63
52
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var log = this.log.extend('apply');
|
|
53
|
+
apply() {
|
|
54
|
+
const log = this.log.extend('apply');
|
|
67
55
|
log('applying the interceptor...');
|
|
68
56
|
if (this.readyState === InterceptorReadyState.APPLIED) {
|
|
69
57
|
log('intercepted already applied!');
|
|
70
58
|
return;
|
|
71
59
|
}
|
|
72
|
-
|
|
60
|
+
const shouldApply = this.checkEnvironment();
|
|
73
61
|
if (!shouldApply) {
|
|
74
62
|
log('the interceptor cannot be applied in this environment!');
|
|
75
63
|
return;
|
|
@@ -83,24 +71,24 @@ var Interceptor = /** @class */ (function () {
|
|
|
83
71
|
// Whenever applying a new interceptor, check if it hasn't been applied already.
|
|
84
72
|
// This enables to apply the same interceptor multiple times, for example from a different
|
|
85
73
|
// interceptor, only proxying events but keeping the stubs in a single place.
|
|
86
|
-
|
|
74
|
+
const runningInstance = this.getInstance();
|
|
87
75
|
if (runningInstance) {
|
|
88
76
|
log('found a running instance, reusing...');
|
|
89
77
|
// Proxy any listeners you set on this instance to the running instance.
|
|
90
|
-
this.on =
|
|
78
|
+
this.on = (event, listener) => {
|
|
91
79
|
log('proxying the "%s" listener', event);
|
|
92
80
|
// Add listeners to the running instance so they appear
|
|
93
81
|
// at the top of the event listeners list and are executed first.
|
|
94
82
|
runningInstance.emitter.addListener(event, listener);
|
|
95
83
|
// Ensure that once this interceptor instance is disposed,
|
|
96
84
|
// it removes all listeners it has appended to the running interceptor instance.
|
|
97
|
-
|
|
85
|
+
this.subscriptions.push(() => {
|
|
98
86
|
runningInstance.emitter.removeListener(event, listener);
|
|
99
87
|
log('removed proxied "%s" listener!', event);
|
|
100
88
|
});
|
|
101
89
|
};
|
|
102
|
-
(0, nextTick_1.nextTick)(
|
|
103
|
-
|
|
90
|
+
(0, nextTick_1.nextTick)(() => {
|
|
91
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
104
92
|
});
|
|
105
93
|
return;
|
|
106
94
|
}
|
|
@@ -109,36 +97,34 @@ var Interceptor = /** @class */ (function () {
|
|
|
109
97
|
this.setup();
|
|
110
98
|
// Store the newly applied interceptor instance globally.
|
|
111
99
|
this.setInstance();
|
|
112
|
-
(0, nextTick_1.nextTick)(
|
|
113
|
-
|
|
100
|
+
(0, nextTick_1.nextTick)(() => {
|
|
101
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
114
102
|
});
|
|
115
|
-
}
|
|
103
|
+
}
|
|
116
104
|
/**
|
|
117
105
|
* Setup the module augments and stubs necessary for this interceptor.
|
|
118
106
|
* This method is not run if there's a running interceptor instance
|
|
119
107
|
* to prevent instantiating an interceptor multiple times.
|
|
120
108
|
*/
|
|
121
|
-
|
|
109
|
+
setup() { }
|
|
122
110
|
/**
|
|
123
111
|
* Listen to the interceptor's public events.
|
|
124
112
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
113
|
+
on(eventName, listener) {
|
|
114
|
+
const log = this.log.extend('on');
|
|
127
115
|
if (this.readyState === InterceptorReadyState.DISPOSING ||
|
|
128
116
|
this.readyState === InterceptorReadyState.DISPOSED) {
|
|
129
117
|
log('cannot listen to events, already disposed!');
|
|
130
118
|
return;
|
|
131
119
|
}
|
|
132
|
-
log('adding "%s" event listener:',
|
|
133
|
-
this.emitter.on(
|
|
134
|
-
}
|
|
120
|
+
log('adding "%s" event listener:', eventName, listener.name);
|
|
121
|
+
this.emitter.on(eventName, listener);
|
|
122
|
+
}
|
|
135
123
|
/**
|
|
136
124
|
* Disposes of any side-effects this interceptor has introduced.
|
|
137
125
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
var _this = this;
|
|
141
|
-
var log = this.log.extend('dispose');
|
|
126
|
+
dispose() {
|
|
127
|
+
const log = this.log.extend('dispose');
|
|
142
128
|
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
143
129
|
log('cannot dispose, already disposed!');
|
|
144
130
|
return;
|
|
@@ -155,43 +141,32 @@ var Interceptor = /** @class */ (function () {
|
|
|
155
141
|
log('global symbol deleted:', getGlobalSymbol(this.symbol));
|
|
156
142
|
if (this.subscriptions.length > 0) {
|
|
157
143
|
log('disposing of %d subscriptions...', this.subscriptions.length);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var dispose = _c.value;
|
|
161
|
-
dispose();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
165
|
-
finally {
|
|
166
|
-
try {
|
|
167
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
168
|
-
}
|
|
169
|
-
finally { if (e_1) throw e_1.error; }
|
|
144
|
+
for (const dispose of this.subscriptions) {
|
|
145
|
+
dispose();
|
|
170
146
|
}
|
|
171
147
|
this.subscriptions = [];
|
|
172
148
|
log('disposed of all subscriptions!', this.subscriptions.length);
|
|
173
149
|
}
|
|
174
150
|
this.emitter.deactivate();
|
|
175
151
|
log('destroyed the listener!');
|
|
176
|
-
(0, nextTick_1.nextTick)(
|
|
177
|
-
|
|
152
|
+
(0, nextTick_1.nextTick)(() => {
|
|
153
|
+
this.readyState = InterceptorReadyState.DISPOSED;
|
|
178
154
|
});
|
|
179
|
-
}
|
|
180
|
-
|
|
155
|
+
}
|
|
156
|
+
getInstance() {
|
|
181
157
|
var _a;
|
|
182
|
-
|
|
158
|
+
const instance = getGlobalSymbol(this.symbol);
|
|
183
159
|
this.log('retrieved global instance:', (_a = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _a === void 0 ? void 0 : _a.name);
|
|
184
160
|
return instance;
|
|
185
|
-
}
|
|
186
|
-
|
|
161
|
+
}
|
|
162
|
+
setInstance() {
|
|
187
163
|
setGlobalSymbol(this.symbol, this);
|
|
188
164
|
this.log('set global instance!', this.symbol.description);
|
|
189
|
-
}
|
|
190
|
-
|
|
165
|
+
}
|
|
166
|
+
clearInstance() {
|
|
191
167
|
deleteGlobalSymbol(this.symbol);
|
|
192
168
|
this.log('cleared global instance!', this.symbol.description);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
}());
|
|
169
|
+
}
|
|
170
|
+
}
|
|
196
171
|
exports.Interceptor = Interceptor;
|
|
197
172
|
//# sourceMappingURL=Interceptor.js.map
|
package/lib/Interceptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interceptor.js","sourceRoot":"","sources":["../src/Interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Interceptor.js","sourceRoot":"","sources":["../src/Interceptor.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAEvC,iEAA6D;AAC7D,+CAA2C;AAK3C,SAAgB,eAAe,CAAI,MAAc;IAC/C,OAAO;IACL,kEAAkE;IAClE,UAAU,CAAC,MAAM,CAAC,IAAI,SAAS,CAChC,CAAA;AACH,CAAC;AALD,0CAKC;AAED,SAAS,eAAe,CAAC,MAAc,EAAE,KAAU;IACjD,aAAa;IACb,UAAU,CAAC,MAAM,CAAC,GAAG,KAA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