msw 2.12.14 → 2.13.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/browser/index.d.mts +29 -19
- package/lib/browser/index.d.ts +29 -19
- package/lib/browser/index.js +1763 -1321
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1769 -1321
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-Dj6ibgFJ.d.ts → HttpResponse-CksOMVAa.d.ts} +5 -5
- package/lib/core/{HttpResponse-Be4eT3x6.d.mts → HttpResponse-DlRR1D-f.d.mts} +5 -5
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +17 -0
- package/lib/core/experimental/compat.d.ts +17 -0
- package/lib/core/experimental/compat.js +54 -0
- package/lib/core/experimental/compat.js.map +1 -0
- package/lib/core/experimental/compat.mjs +36 -0
- package/lib/core/experimental/compat.mjs.map +1 -0
- package/lib/core/experimental/define-network.d.mts +75 -0
- package/lib/core/experimental/define-network.d.ts +75 -0
- package/lib/core/experimental/define-network.js +124 -0
- package/lib/core/experimental/define-network.js.map +1 -0
- package/lib/core/experimental/define-network.mjs +107 -0
- package/lib/core/experimental/define-network.mjs.map +1 -0
- package/lib/core/experimental/frames/http-frame.d.mts +77 -0
- package/lib/core/experimental/frames/http-frame.d.ts +77 -0
- package/lib/core/experimental/frames/http-frame.js +194 -0
- package/lib/core/experimental/frames/http-frame.js.map +1 -0
- package/lib/core/experimental/frames/http-frame.mjs +176 -0
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/network-frame.d.mts +12 -0
- package/lib/core/experimental/frames/network-frame.d.ts +12 -0
- package/lib/core/{handlers/common.js → experimental/frames/network-frame.js} +19 -3
- package/lib/core/experimental/frames/network-frame.js.map +1 -0
- package/lib/core/experimental/frames/network-frame.mjs +13 -0
- package/lib/core/experimental/frames/network-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.d.mts +55 -0
- package/lib/core/experimental/frames/websocket-frame.d.ts +55 -0
- package/lib/core/experimental/frames/websocket-frame.js +129 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.mjs +116 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -0
- package/lib/core/experimental/handlers-controller.d.mts +35 -0
- package/lib/core/experimental/handlers-controller.d.ts +35 -0
- package/lib/core/experimental/handlers-controller.js +121 -0
- package/lib/core/experimental/handlers-controller.js.map +1 -0
- package/lib/core/experimental/handlers-controller.mjs +101 -0
- package/lib/core/experimental/handlers-controller.mjs.map +1 -0
- package/lib/core/experimental/index.d.mts +17 -0
- package/lib/core/experimental/index.d.ts +17 -0
- package/lib/core/experimental/index.js +36 -0
- package/lib/core/experimental/index.js.map +1 -0
- package/lib/core/experimental/index.mjs +20 -0
- package/lib/core/experimental/index.mjs.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.d.mts +12 -0
- package/lib/core/experimental/on-unhandled-frame.d.ts +12 -0
- package/lib/core/experimental/on-unhandled-frame.js +90 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs +70 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -0
- package/lib/core/experimental/request-utils.d.mts +12 -0
- package/lib/core/experimental/request-utils.d.ts +12 -0
- package/lib/core/experimental/request-utils.js +50 -0
- package/lib/core/experimental/request-utils.js.map +1 -0
- package/lib/core/experimental/request-utils.mjs +30 -0
- package/lib/core/experimental/request-utils.mjs.map +1 -0
- package/lib/core/experimental/setup-api.d.mts +33 -0
- package/lib/core/experimental/setup-api.d.ts +33 -0
- package/lib/core/experimental/setup-api.js +61 -0
- package/lib/core/experimental/setup-api.js.map +1 -0
- package/lib/core/experimental/setup-api.mjs +43 -0
- package/lib/core/experimental/setup-api.mjs.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.d.mts +28 -0
- package/lib/core/experimental/sources/interceptor-source.d.ts +28 -0
- package/lib/core/experimental/sources/interceptor-source.js +142 -0
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.mjs +124 -0
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -0
- package/lib/core/experimental/sources/network-source.d.mts +31 -0
- package/lib/core/experimental/sources/network-source.d.ts +31 -0
- package/lib/core/experimental/sources/network-source.js +50 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -0
- package/lib/core/experimental/sources/network-source.mjs +30 -0
- package/lib/core/experimental/sources/network-source.mjs.map +1 -0
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +5 -6
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +5 -6
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +8 -4
- package/lib/core/handlers/WebSocketHandler.d.ts +8 -4
- package/lib/core/handlers/WebSocketHandler.js +18 -5
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +18 -5
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +7 -12
- package/lib/core/index.d.ts +7 -12
- package/lib/core/index.js +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/network-frame-B7A0ggXE.d.mts +56 -0
- package/lib/core/network-frame-usYiHS0K.d.ts +56 -0
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sharedOptions.d.mts +6 -2
- package/lib/core/sharedOptions.d.ts +6 -2
- package/lib/core/sharedOptions.js.map +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.d.ts +1 -1
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -1
- package/lib/core/utils/handleRequest.d.ts +2 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +3 -3
- package/lib/core/utils/internal/isHandlerKind.d.ts +3 -3
- package/lib/core/utils/internal/isHandlerKind.js +2 -1
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -1
- package/lib/core/utils/internal/isHandlerKind.mjs +2 -1
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.d.ts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.js +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws.d.mts +3 -3
- package/lib/core/ws.d.ts +3 -3
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +2021 -1432
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +21 -29
- package/lib/native/index.d.ts +21 -29
- package/lib/native/index.js +48 -116
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +51 -118
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +55 -33
- package/lib/node/index.d.ts +55 -33
- package/lib/node/index.js +152 -154
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +156 -156
- package/lib/node/index.mjs.map +1 -1
- package/package.json +10 -2
- package/src/browser/{setupWorker/glossary.ts → glossary.ts} +16 -33
- package/src/browser/index.ts +2 -3
- package/src/browser/{setupWorker/setupWorker.node.test.ts → setup-worker.node.test.ts} +2 -4
- package/src/browser/setup-worker.ts +148 -0
- package/src/browser/sources/fallback-http-source.ts +56 -0
- package/src/browser/sources/service-worker-source.ts +455 -0
- package/src/browser/tsconfig.browser.json +7 -2
- package/src/browser/utils/deserializeRequest.ts +1 -1
- package/src/browser/{setupWorker/start/utils/getWorkerByRegistration.ts → utils/get-worker-by-registration.ts} +3 -1
- package/src/browser/{setupWorker/start/utils/getWorkerInstance.ts → utils/get-worker-instance.ts} +4 -4
- package/src/browser/utils/pruneGetRequestBody.test.ts +1 -3
- package/src/browser/utils/pruneGetRequestBody.ts +1 -1
- package/src/browser/utils/validate-worker-scope.ts +19 -0
- package/src/browser/utils/workerChannel.ts +2 -2
- package/src/core/experimental/compat.ts +50 -0
- package/src/core/experimental/define-network.test.ts +124 -0
- package/src/core/experimental/define-network.ts +215 -0
- package/src/core/experimental/frames/http-frame.test.ts +360 -0
- package/src/core/experimental/frames/http-frame.ts +271 -0
- package/src/core/experimental/frames/network-frame.ts +64 -0
- package/src/core/experimental/frames/websocket-frame.test.ts +280 -0
- package/src/core/experimental/frames/websocket-frame.ts +188 -0
- package/src/core/experimental/handlers-controller.test.ts +198 -0
- package/src/core/experimental/handlers-controller.ts +145 -0
- package/src/core/experimental/index.ts +16 -0
- package/src/core/experimental/on-unhandled-frame.test.ts +360 -0
- package/src/core/experimental/on-unhandled-frame.ts +110 -0
- package/src/core/experimental/request-utils.test.ts +70 -0
- package/src/core/experimental/request-utils.ts +39 -0
- package/src/core/experimental/setup-api.ts +59 -0
- package/src/core/experimental/sources/interceptor-source.ts +185 -0
- package/src/core/experimental/sources/network-source.test.ts +74 -0
- package/src/core/experimental/sources/network-source.ts +56 -0
- package/src/core/handlers/RequestHandler.ts +9 -10
- package/src/core/handlers/WebSocketHandler.ts +27 -11
- package/src/core/index.ts +3 -7
- package/src/core/sharedOptions.ts +9 -4
- package/src/core/sse.ts +1 -1
- package/src/core/utils/cookieStore.ts +2 -1
- package/src/core/utils/internal/isHandlerKind.test.ts +20 -22
- package/src/core/utils/internal/isHandlerKind.ts +5 -9
- package/src/core/utils/request/onUnhandledRequest.ts +2 -2
- package/src/core/ws/WebSocketClientManager.test.ts +2 -10
- package/src/core/ws/handleWebSocketEvent.ts +5 -1
- package/src/core/ws/utils/attachWebSocketLogger.ts +43 -11
- package/src/core/ws.test.ts +1 -3
- package/src/core/ws.ts +6 -6
- package/src/iife/index.ts +1 -1
- package/src/native/index.ts +34 -11
- package/src/node/async-handlers-controller.test.ts +50 -0
- package/src/node/async-handlers-controller.ts +69 -0
- package/src/node/glossary.ts +19 -18
- package/src/node/index.ts +6 -2
- package/src/node/setup-server-common.ts +100 -0
- package/src/node/setup-server.ts +91 -0
- package/src/tsconfig.core.json +8 -0
- package/src/tsconfig.node.json +8 -3
- package/src/tsconfig.src.json +0 -2
- package/src/tsconfig.worker.json +2 -1
- package/lib/core/SetupApi.d.mts +0 -44
- package/lib/core/SetupApi.d.ts +0 -44
- package/lib/core/SetupApi.js +0 -112
- package/lib/core/SetupApi.js.map +0 -1
- package/lib/core/SetupApi.mjs +0 -92
- package/lib/core/SetupApi.mjs.map +0 -1
- package/lib/core/handlers/common.d.mts +0 -3
- package/lib/core/handlers/common.d.ts +0 -3
- package/lib/core/handlers/common.js.map +0 -1
- package/lib/core/handlers/common.mjs +0 -1
- package/lib/core/handlers/common.mjs.map +0 -1
- package/src/browser/setupWorker/setupWorker.ts +0 -184
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +0 -71
- package/src/browser/setupWorker/start/createRequestListener.ts +0 -138
- package/src/browser/setupWorker/start/createResponseListener.ts +0 -57
- package/src/browser/setupWorker/start/createStartHandler.ts +0 -137
- package/src/browser/setupWorker/start/utils/enableMocking.ts +0 -30
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +0 -59
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +0 -44
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +0 -84
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +0 -51
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +0 -18
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +0 -26
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +0 -13
- package/src/browser/utils/checkWorkerIntegrity.ts +0 -42
- package/src/core/SetupApi.ts +0 -127
- package/src/core/handlers/common.ts +0 -1
- package/src/node/SetupServerApi.ts +0 -87
- package/src/node/SetupServerCommonApi.ts +0 -169
- package/src/node/setupServer.ts +0 -15
package/lib/iife/index.js
CHANGED
|
@@ -14212,191 +14212,381 @@ ${operationTypes.join("\n")}
|
|
|
14212
14212
|
);
|
|
14213
14213
|
}
|
|
14214
14214
|
|
|
14215
|
-
// node_modules/.pnpm/
|
|
14216
|
-
var
|
|
14217
|
-
|
|
14218
|
-
|
|
14219
|
-
`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
|
|
14220
|
-
);
|
|
14221
|
-
this.emitter = emitter;
|
|
14222
|
-
this.type = type;
|
|
14223
|
-
this.count = count;
|
|
14224
|
-
this.name = "MaxListenersExceededWarning";
|
|
14225
|
-
}
|
|
14226
|
-
};
|
|
14227
|
-
var _Emitter = class {
|
|
14228
|
-
static listenerCount(emitter, eventName) {
|
|
14229
|
-
return emitter.listenerCount(eventName);
|
|
14230
|
-
}
|
|
14215
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
|
|
14216
|
+
var LensList = class {
|
|
14217
|
+
#list;
|
|
14218
|
+
#lens;
|
|
14231
14219
|
constructor() {
|
|
14232
|
-
this
|
|
14233
|
-
this
|
|
14234
|
-
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
14220
|
+
this.#list = [];
|
|
14221
|
+
this.#lens = /* @__PURE__ */ new Map();
|
|
14235
14222
|
}
|
|
14236
|
-
|
|
14237
|
-
this.
|
|
14238
|
-
internalEventName,
|
|
14239
|
-
...[eventName, listener]
|
|
14240
|
-
);
|
|
14223
|
+
get [Symbol.iterator]() {
|
|
14224
|
+
return this.#list[Symbol.iterator].bind(this.#list);
|
|
14241
14225
|
}
|
|
14242
|
-
|
|
14243
|
-
return
|
|
14226
|
+
entries() {
|
|
14227
|
+
return this.#lens.entries();
|
|
14244
14228
|
}
|
|
14245
|
-
|
|
14246
|
-
|
|
14247
|
-
|
|
14248
|
-
|
|
14249
|
-
|
|
14250
|
-
return [];
|
|
14229
|
+
/**
|
|
14230
|
+
* Return an order-sensitive list of values by the given key.
|
|
14231
|
+
*/
|
|
14232
|
+
get(key) {
|
|
14233
|
+
return this.#lens.get(key) || [];
|
|
14251
14234
|
}
|
|
14252
|
-
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14256
|
-
|
|
14257
|
-
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
14258
|
-
return onceListener;
|
|
14235
|
+
/**
|
|
14236
|
+
* Return an order-sensitive list of all values.
|
|
14237
|
+
*/
|
|
14238
|
+
getAll() {
|
|
14239
|
+
return this.#list.map(([, value]) => value);
|
|
14259
14240
|
}
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14241
|
+
/**
|
|
14242
|
+
* Append a new value to the given key.
|
|
14243
|
+
*/
|
|
14244
|
+
append(key, value) {
|
|
14245
|
+
this.#list.push([key, value]);
|
|
14246
|
+
this.#openLens(key, (list) => list.push(value));
|
|
14263
14247
|
}
|
|
14264
14248
|
/**
|
|
14265
|
-
|
|
14266
|
-
|
|
14267
|
-
|
|
14268
|
-
|
|
14269
|
-
|
|
14270
|
-
return this.maxListeners;
|
|
14249
|
+
* Prepend a new value to the given key.
|
|
14250
|
+
*/
|
|
14251
|
+
prepend(key, value) {
|
|
14252
|
+
this.#list.unshift([key, value]);
|
|
14253
|
+
this.#openLens(key, (list) => list.unshift(value));
|
|
14271
14254
|
}
|
|
14272
14255
|
/**
|
|
14273
|
-
|
|
14274
|
-
|
|
14275
|
-
|
|
14276
|
-
|
|
14277
|
-
|
|
14256
|
+
* Delete the value belonging to the given key.
|
|
14257
|
+
*/
|
|
14258
|
+
delete(key, value) {
|
|
14259
|
+
if (this.size === 0) return;
|
|
14260
|
+
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
14261
|
+
for (const [existingKey, values] of this.#lens) if (existingKey === key && values.includes(value)) values.splice(values.indexOf(value), 1);
|
|
14278
14262
|
}
|
|
14279
14263
|
/**
|
|
14280
|
-
|
|
14281
|
-
|
|
14282
|
-
|
|
14283
|
-
|
|
14284
|
-
|
|
14285
|
-
|
|
14286
|
-
* emitter.emit('hello', 'John')
|
|
14287
|
-
*/
|
|
14288
|
-
emit(eventName, ...data) {
|
|
14289
|
-
const listeners = this._getListeners(eventName);
|
|
14290
|
-
listeners.forEach((listener) => {
|
|
14291
|
-
listener.apply(this, data);
|
|
14292
|
-
});
|
|
14293
|
-
return listeners.length > 0;
|
|
14264
|
+
* Delete all values belogning to the given key.
|
|
14265
|
+
*/
|
|
14266
|
+
deleteAll(key) {
|
|
14267
|
+
if (this.size === 0) return;
|
|
14268
|
+
this.#list = this.#list.filter((item) => item[0] !== key);
|
|
14269
|
+
this.#lens.delete(key);
|
|
14294
14270
|
}
|
|
14295
|
-
|
|
14296
|
-
this.
|
|
14297
|
-
const nextListeners = this._getListeners(eventName).concat(listener);
|
|
14298
|
-
this.events.set(eventName, nextListeners);
|
|
14299
|
-
if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
|
|
14300
|
-
this.hasWarnedAboutPotentialMemoryLeak = true;
|
|
14301
|
-
const memoryLeakWarning = new MemoryLeakError(
|
|
14302
|
-
this,
|
|
14303
|
-
eventName,
|
|
14304
|
-
this.listenerCount(eventName)
|
|
14305
|
-
);
|
|
14306
|
-
console.warn(memoryLeakWarning);
|
|
14307
|
-
}
|
|
14308
|
-
return this;
|
|
14271
|
+
get size() {
|
|
14272
|
+
return this.#list.length;
|
|
14309
14273
|
}
|
|
14310
|
-
|
|
14311
|
-
|
|
14274
|
+
clear() {
|
|
14275
|
+
if (this.size === 0) return;
|
|
14276
|
+
this.#list.length = 0;
|
|
14277
|
+
this.#lens.clear();
|
|
14312
14278
|
}
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
eventName,
|
|
14316
|
-
this._wrapOnceListener(eventName, listener)
|
|
14317
|
-
);
|
|
14279
|
+
#openLens(key, setter) {
|
|
14280
|
+
setter(this.#lens.get(key) || this.#lens.set(key, []).get(key));
|
|
14318
14281
|
}
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
14322
|
-
|
|
14323
|
-
|
|
14324
|
-
|
|
14325
|
-
|
|
14326
|
-
|
|
14327
|
-
|
|
14282
|
+
};
|
|
14283
|
+
|
|
14284
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/index.mjs
|
|
14285
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
14286
|
+
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
14287
|
+
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
14288
|
+
var TypedEvent = class extends MessageEvent {
|
|
14289
|
+
/**
|
|
14290
|
+
* @note Keep a placeholder property with the return type
|
|
14291
|
+
* because the type must be set somewhere in order to be
|
|
14292
|
+
* correctly associated and inferred from the event.
|
|
14293
|
+
*/
|
|
14294
|
+
#returnType;
|
|
14295
|
+
[kDefaultPrevented];
|
|
14296
|
+
[kPropagationStopped];
|
|
14297
|
+
[kImmediatePropagationStopped];
|
|
14298
|
+
constructor(...args) {
|
|
14299
|
+
super(args[0], args[1]);
|
|
14300
|
+
this[kDefaultPrevented] = false;
|
|
14328
14301
|
}
|
|
14329
|
-
|
|
14330
|
-
return this
|
|
14331
|
-
eventName,
|
|
14332
|
-
this._wrapOnceListener(eventName, listener)
|
|
14333
|
-
);
|
|
14302
|
+
get defaultPrevented() {
|
|
14303
|
+
return this[kDefaultPrevented];
|
|
14334
14304
|
}
|
|
14335
|
-
|
|
14336
|
-
|
|
14337
|
-
|
|
14338
|
-
|
|
14339
|
-
|
|
14340
|
-
|
|
14341
|
-
|
|
14305
|
+
preventDefault() {
|
|
14306
|
+
super.preventDefault();
|
|
14307
|
+
this[kDefaultPrevented] = true;
|
|
14308
|
+
}
|
|
14309
|
+
stopImmediatePropagation() {
|
|
14310
|
+
super.stopImmediatePropagation();
|
|
14311
|
+
this[kImmediatePropagationStopped] = true;
|
|
14312
|
+
}
|
|
14313
|
+
};
|
|
14314
|
+
var kListenerOptions = Symbol("kListenerOptions");
|
|
14315
|
+
var Emitter = class {
|
|
14316
|
+
#listeners;
|
|
14317
|
+
constructor() {
|
|
14318
|
+
this.#listeners = new LensList();
|
|
14319
|
+
}
|
|
14320
|
+
/**
|
|
14321
|
+
* Adds a listener for the given event type.
|
|
14322
|
+
*/
|
|
14323
|
+
on(type, listener, options) {
|
|
14324
|
+
this.#addListener(type, listener, options);
|
|
14342
14325
|
return this;
|
|
14343
14326
|
}
|
|
14344
14327
|
/**
|
|
14345
|
-
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
|
|
14328
|
+
* Adds a one-time listener for the given event type.
|
|
14329
|
+
*/
|
|
14330
|
+
once(type, listener, options) {
|
|
14331
|
+
return this.on(type, listener, {
|
|
14332
|
+
...options || {},
|
|
14333
|
+
once: true
|
|
14334
|
+
});
|
|
14352
14335
|
}
|
|
14353
|
-
|
|
14354
|
-
|
|
14355
|
-
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
}
|
|
14336
|
+
/**
|
|
14337
|
+
* Prepends a listener for the given event type.
|
|
14338
|
+
*/
|
|
14339
|
+
earlyOn(type, listener, options) {
|
|
14340
|
+
this.#addListener(type, listener, options, "prepend");
|
|
14359
14341
|
return this;
|
|
14360
14342
|
}
|
|
14361
14343
|
/**
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14365
|
-
return
|
|
14344
|
+
* Prepends a one-time listener for the given event type.
|
|
14345
|
+
*/
|
|
14346
|
+
earlyOnce(type, listener, options) {
|
|
14347
|
+
return this.earlyOn(type, listener, {
|
|
14348
|
+
...options || {},
|
|
14349
|
+
once: true
|
|
14350
|
+
});
|
|
14366
14351
|
}
|
|
14367
14352
|
/**
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
-
|
|
14371
|
-
|
|
14353
|
+
* Emits the given typed event.
|
|
14354
|
+
*
|
|
14355
|
+
* @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
|
|
14356
|
+
*/
|
|
14357
|
+
emit(event) {
|
|
14358
|
+
if (this.#listeners.size === 0) return false;
|
|
14359
|
+
const hasListeners = this.listenerCount(event.type) > 0;
|
|
14360
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
14361
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
14362
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
14363
|
+
proxiedEvent.revoke();
|
|
14364
|
+
return false;
|
|
14365
|
+
}
|
|
14366
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
14367
|
+
this.#callListener(proxiedEvent.event, listener);
|
|
14368
|
+
}
|
|
14369
|
+
proxiedEvent.revoke();
|
|
14370
|
+
return hasListeners;
|
|
14372
14371
|
}
|
|
14373
|
-
|
|
14374
|
-
|
|
14372
|
+
/**
|
|
14373
|
+
* Emits the given typed event and returns a promise that resolves
|
|
14374
|
+
* when all the listeners for that event have settled.
|
|
14375
|
+
*
|
|
14376
|
+
* @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
|
|
14377
|
+
* with the return values of all listeners.
|
|
14378
|
+
*/
|
|
14379
|
+
async emitAsPromise(event) {
|
|
14380
|
+
if (this.#listeners.size === 0) return [];
|
|
14381
|
+
const pendingListeners = [];
|
|
14382
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
14383
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
14384
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
14385
|
+
proxiedEvent.revoke();
|
|
14386
|
+
return [];
|
|
14387
|
+
}
|
|
14388
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
14389
|
+
const returnValue = await Promise.resolve(this.#callListener(proxiedEvent.event, listener));
|
|
14390
|
+
if (!this.#isTypelessListener(listener)) pendingListeners.push(returnValue);
|
|
14391
|
+
}
|
|
14392
|
+
proxiedEvent.revoke();
|
|
14393
|
+
return Promise.allSettled(pendingListeners).then((results) => {
|
|
14394
|
+
return results.map((result) => result.status === "fulfilled" ? result.value : result.reason);
|
|
14395
|
+
});
|
|
14396
|
+
}
|
|
14397
|
+
/**
|
|
14398
|
+
* Emits the given event and returns a generator that yields
|
|
14399
|
+
* the result of each listener in the order of their registration.
|
|
14400
|
+
* This way, you stop exhausting the listeners once you get the expected value.
|
|
14401
|
+
*/
|
|
14402
|
+
*emitAsGenerator(event) {
|
|
14403
|
+
if (this.#listeners.size === 0) return;
|
|
14404
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
14405
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
14406
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
14407
|
+
proxiedEvent.revoke();
|
|
14408
|
+
return;
|
|
14409
|
+
}
|
|
14410
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
14411
|
+
const returnValue = this.#callListener(proxiedEvent.event, listener);
|
|
14412
|
+
if (!this.#isTypelessListener(listener)) yield returnValue;
|
|
14413
|
+
}
|
|
14414
|
+
proxiedEvent.revoke();
|
|
14415
|
+
}
|
|
14416
|
+
/**
|
|
14417
|
+
* Removes a listener for the given event type.
|
|
14418
|
+
*/
|
|
14419
|
+
removeListener(type, listener) {
|
|
14420
|
+
this.#listeners.delete(type, listener);
|
|
14421
|
+
}
|
|
14422
|
+
/**
|
|
14423
|
+
* Removes all listeners for the given event type.
|
|
14424
|
+
* If no event type is provided, removes all existing listeners.
|
|
14425
|
+
*/
|
|
14426
|
+
removeAllListeners(type) {
|
|
14427
|
+
if (type == null) {
|
|
14428
|
+
this.#listeners.clear();
|
|
14429
|
+
return;
|
|
14430
|
+
}
|
|
14431
|
+
this.#listeners.deleteAll(type);
|
|
14432
|
+
}
|
|
14433
|
+
/**
|
|
14434
|
+
* Returns the list of listeners for the given event type.
|
|
14435
|
+
* If no even type is provided, returns all listeners.
|
|
14436
|
+
*/
|
|
14437
|
+
listeners(type) {
|
|
14438
|
+
if (type == null) return this.#listeners.getAll();
|
|
14439
|
+
return this.#listeners.get(type);
|
|
14440
|
+
}
|
|
14441
|
+
/**
|
|
14442
|
+
* Returns the number of listeners for the given event type.
|
|
14443
|
+
* If no even type is provided, returns the total number of listeners.
|
|
14444
|
+
*/
|
|
14445
|
+
listenerCount(type) {
|
|
14446
|
+
if (type == null) return this.#listeners.size;
|
|
14447
|
+
return this.listeners(type).length;
|
|
14448
|
+
}
|
|
14449
|
+
#addListener(type, listener, options, insertMode = "append") {
|
|
14450
|
+
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
14451
|
+
else this.#listeners.append(type, listener);
|
|
14452
|
+
if (options) {
|
|
14453
|
+
Object.defineProperty(listener, kListenerOptions, {
|
|
14454
|
+
value: options,
|
|
14455
|
+
enumerable: false,
|
|
14456
|
+
writable: false
|
|
14457
|
+
});
|
|
14458
|
+
if (options.signal) options.signal.addEventListener("abort", () => {
|
|
14459
|
+
this.removeListener(type, listener);
|
|
14460
|
+
}, { once: true });
|
|
14461
|
+
}
|
|
14462
|
+
}
|
|
14463
|
+
#proxyEvent(event) {
|
|
14464
|
+
const { stopPropagation } = event;
|
|
14465
|
+
event.stopPropagation = new Proxy(event.stopPropagation, { apply: (target, thisArg, argArray) => {
|
|
14466
|
+
event[kPropagationStopped] = this;
|
|
14467
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
14468
|
+
} });
|
|
14469
|
+
return {
|
|
14470
|
+
event,
|
|
14471
|
+
revoke() {
|
|
14472
|
+
event.stopPropagation = stopPropagation;
|
|
14473
|
+
}
|
|
14474
|
+
};
|
|
14475
|
+
}
|
|
14476
|
+
#callListener(event, listener) {
|
|
14477
|
+
const returnValue = listener.call(this, event);
|
|
14478
|
+
if (listener[kListenerOptions]?.once) {
|
|
14479
|
+
const key = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
14480
|
+
this.#listeners.delete(key, listener);
|
|
14481
|
+
}
|
|
14482
|
+
return returnValue;
|
|
14483
|
+
}
|
|
14484
|
+
/**
|
|
14485
|
+
* Return a list of all event listeners relevant for the given event type.
|
|
14486
|
+
* This includes the explicit event listeners and also typeless event listeners.
|
|
14487
|
+
*/
|
|
14488
|
+
*#matchListeners(type) {
|
|
14489
|
+
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
|
|
14490
|
+
}
|
|
14491
|
+
#isTypelessListener(listener) {
|
|
14492
|
+
return this.#listeners.get("*").includes(listener);
|
|
14375
14493
|
}
|
|
14376
14494
|
};
|
|
14377
|
-
var Emitter = _Emitter;
|
|
14378
|
-
Emitter.defaultMaxListeners = 10;
|
|
14379
14495
|
|
|
14380
|
-
// src/core/
|
|
14381
|
-
function
|
|
14382
|
-
const
|
|
14383
|
-
|
|
14384
|
-
|
|
14496
|
+
// src/core/experimental/handlers-controller.ts
|
|
14497
|
+
function groupHandlersByKind(handlers) {
|
|
14498
|
+
const groups = {};
|
|
14499
|
+
for (const handler of handlers) {
|
|
14500
|
+
;
|
|
14501
|
+
(groups[handler.kind] ||= []).push(handler);
|
|
14385
14502
|
}
|
|
14386
|
-
|
|
14387
|
-
destination.emit(event, ...data);
|
|
14388
|
-
return rawEmit.call(this, event, ...data);
|
|
14389
|
-
};
|
|
14390
|
-
sourceEmit._isPiped = true;
|
|
14391
|
-
source.emit = sourceEmit;
|
|
14392
|
-
}
|
|
14393
|
-
|
|
14394
|
-
// src/core/utils/internal/toReadonlyArray.ts
|
|
14395
|
-
function toReadonlyArray(source) {
|
|
14396
|
-
const clone = [...source];
|
|
14397
|
-
Object.freeze(clone);
|
|
14398
|
-
return clone;
|
|
14503
|
+
return groups;
|
|
14399
14504
|
}
|
|
14505
|
+
var HandlersController = class {
|
|
14506
|
+
getInitialState(initialHandlers) {
|
|
14507
|
+
invariant(
|
|
14508
|
+
this.#validateHandlers(initialHandlers),
|
|
14509
|
+
devUtils.formatMessage(
|
|
14510
|
+
"[MSW] Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?"
|
|
14511
|
+
)
|
|
14512
|
+
);
|
|
14513
|
+
const normalizedInitialHandlers = groupHandlersByKind(initialHandlers);
|
|
14514
|
+
return {
|
|
14515
|
+
initialHandlers: normalizedInitialHandlers,
|
|
14516
|
+
handlers: { ...normalizedInitialHandlers }
|
|
14517
|
+
};
|
|
14518
|
+
}
|
|
14519
|
+
currentHandlers() {
|
|
14520
|
+
return Object.values(this.getState().handlers).flat().filter((handler) => handler != null);
|
|
14521
|
+
}
|
|
14522
|
+
getHandlersByKind(kind) {
|
|
14523
|
+
return this.getState().handlers[kind] || [];
|
|
14524
|
+
}
|
|
14525
|
+
use(nextHandlers) {
|
|
14526
|
+
invariant(
|
|
14527
|
+
this.#validateHandlers(nextHandlers),
|
|
14528
|
+
devUtils.formatMessage(
|
|
14529
|
+
'[MSW] Failed to call "use()" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?'
|
|
14530
|
+
)
|
|
14531
|
+
);
|
|
14532
|
+
if (nextHandlers.length === 0) {
|
|
14533
|
+
return;
|
|
14534
|
+
}
|
|
14535
|
+
const { handlers } = this.getState();
|
|
14536
|
+
for (let i = nextHandlers.length - 1; i >= 0; i--) {
|
|
14537
|
+
const handler = nextHandlers[i];
|
|
14538
|
+
handlers[handler.kind] = handlers[handler.kind] ? [handler, ...handlers[handler.kind]] : [handler];
|
|
14539
|
+
}
|
|
14540
|
+
this.setState({ handlers });
|
|
14541
|
+
}
|
|
14542
|
+
reset(nextHandlers) {
|
|
14543
|
+
invariant(
|
|
14544
|
+
nextHandlers.length > 0 ? this.#validateHandlers(nextHandlers) : true,
|
|
14545
|
+
devUtils.formatMessage(
|
|
14546
|
+
"Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?"
|
|
14547
|
+
)
|
|
14548
|
+
);
|
|
14549
|
+
const { initialHandlers } = this.getState();
|
|
14550
|
+
if (nextHandlers.length === 0) {
|
|
14551
|
+
this.setState({
|
|
14552
|
+
handlers: { ...initialHandlers }
|
|
14553
|
+
});
|
|
14554
|
+
return;
|
|
14555
|
+
}
|
|
14556
|
+
const normalizedNextHandlers = groupHandlersByKind(nextHandlers);
|
|
14557
|
+
this.setState({
|
|
14558
|
+
initialHandlers: normalizedNextHandlers,
|
|
14559
|
+
handlers: { ...normalizedNextHandlers }
|
|
14560
|
+
});
|
|
14561
|
+
}
|
|
14562
|
+
#validateHandlers(handlers) {
|
|
14563
|
+
return handlers.every((handler) => !Array.isArray(handler));
|
|
14564
|
+
}
|
|
14565
|
+
};
|
|
14566
|
+
var InMemoryHandlersController = class extends HandlersController {
|
|
14567
|
+
#handlers;
|
|
14568
|
+
#initialHandlers;
|
|
14569
|
+
constructor(initialHandlers) {
|
|
14570
|
+
super();
|
|
14571
|
+
const initialState = this.getInitialState(initialHandlers);
|
|
14572
|
+
this.#initialHandlers = initialState.initialHandlers;
|
|
14573
|
+
this.#handlers = initialState.handlers;
|
|
14574
|
+
}
|
|
14575
|
+
getState() {
|
|
14576
|
+
return {
|
|
14577
|
+
initialHandlers: this.#initialHandlers,
|
|
14578
|
+
handlers: this.#handlers
|
|
14579
|
+
};
|
|
14580
|
+
}
|
|
14581
|
+
setState(nextState) {
|
|
14582
|
+
if (nextState.initialHandlers) {
|
|
14583
|
+
this.#initialHandlers = nextState.initialHandlers;
|
|
14584
|
+
}
|
|
14585
|
+
if (nextState.handlers) {
|
|
14586
|
+
this.#handlers = nextState.handlers;
|
|
14587
|
+
}
|
|
14588
|
+
}
|
|
14589
|
+
};
|
|
14400
14590
|
|
|
14401
14591
|
// src/core/utils/internal/Disposable.ts
|
|
14402
14592
|
var Disposable = class {
|
|
@@ -14409,23 +14599,14 @@ ${operationTypes.join("\n")}
|
|
|
14409
14599
|
}
|
|
14410
14600
|
};
|
|
14411
14601
|
|
|
14412
|
-
// src/core/
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
this.handlers.unshift(...runtimeHandles);
|
|
14421
|
-
}
|
|
14422
|
-
reset(nextHandlers) {
|
|
14423
|
-
this.handlers = nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers];
|
|
14424
|
-
}
|
|
14425
|
-
currentHandlers() {
|
|
14426
|
-
return this.handlers;
|
|
14427
|
-
}
|
|
14428
|
-
};
|
|
14602
|
+
// src/core/utils/internal/toReadonlyArray.ts
|
|
14603
|
+
function toReadonlyArray(source) {
|
|
14604
|
+
const clone = [...source];
|
|
14605
|
+
Object.freeze(clone);
|
|
14606
|
+
return clone;
|
|
14607
|
+
}
|
|
14608
|
+
|
|
14609
|
+
// src/core/experimental/setup-api.ts
|
|
14429
14610
|
var SetupApi = class extends Disposable {
|
|
14430
14611
|
handlersController;
|
|
14431
14612
|
emitter;
|
|
@@ -14433,33 +14614,17 @@ ${operationTypes.join("\n")}
|
|
|
14433
14614
|
events;
|
|
14434
14615
|
constructor(...initialHandlers) {
|
|
14435
14616
|
super();
|
|
14436
|
-
invariant(
|
|
14437
|
-
this.validateHandlers(initialHandlers),
|
|
14438
|
-
devUtils.formatMessage(
|
|
14439
|
-
`Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?`
|
|
14440
|
-
)
|
|
14441
|
-
);
|
|
14442
14617
|
this.handlersController = new InMemoryHandlersController(initialHandlers);
|
|
14443
14618
|
this.emitter = new Emitter();
|
|
14444
14619
|
this.publicEmitter = new Emitter();
|
|
14445
|
-
|
|
14446
|
-
this.events = this.createLifeCycleEvents();
|
|
14620
|
+
this.events = this.emitter;
|
|
14447
14621
|
this.subscriptions.push(() => {
|
|
14448
14622
|
this.emitter.removeAllListeners();
|
|
14449
14623
|
this.publicEmitter.removeAllListeners();
|
|
14450
14624
|
});
|
|
14451
14625
|
}
|
|
14452
|
-
validateHandlers(handlers) {
|
|
14453
|
-
return handlers.every((handler) => !Array.isArray(handler));
|
|
14454
|
-
}
|
|
14455
14626
|
use(...runtimeHandlers) {
|
|
14456
|
-
|
|
14457
|
-
this.validateHandlers(runtimeHandlers),
|
|
14458
|
-
devUtils.formatMessage(
|
|
14459
|
-
`Failed to call "use()" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?`
|
|
14460
|
-
)
|
|
14461
|
-
);
|
|
14462
|
-
this.handlersController.prepend(runtimeHandlers);
|
|
14627
|
+
this.handlersController.use(runtimeHandlers);
|
|
14463
14628
|
}
|
|
14464
14629
|
restoreHandlers() {
|
|
14465
14630
|
this.handlersController.currentHandlers().forEach((handler) => {
|
|
@@ -14474,19 +14639,6 @@ ${operationTypes.join("\n")}
|
|
|
14474
14639
|
listHandlers() {
|
|
14475
14640
|
return toReadonlyArray(this.handlersController.currentHandlers());
|
|
14476
14641
|
}
|
|
14477
|
-
createLifeCycleEvents() {
|
|
14478
|
-
return {
|
|
14479
|
-
on: (...args) => {
|
|
14480
|
-
return this.publicEmitter.on(...args);
|
|
14481
|
-
},
|
|
14482
|
-
removeListener: (...args) => {
|
|
14483
|
-
return this.publicEmitter.removeListener(...args);
|
|
14484
|
-
},
|
|
14485
|
-
removeAllListeners: (...args) => {
|
|
14486
|
-
return this.publicEmitter.removeAllListeners(...args);
|
|
14487
|
-
}
|
|
14488
|
-
};
|
|
14489
|
-
}
|
|
14490
14642
|
};
|
|
14491
14643
|
|
|
14492
14644
|
// src/core/utils/internal/getCallFrame.ts
|
|
@@ -14519,17 +14671,17 @@ ${operationTypes.join("\n")}
|
|
|
14519
14671
|
// src/core/handlers/RequestHandler.ts
|
|
14520
14672
|
var RequestHandler = class _RequestHandler {
|
|
14521
14673
|
static cache = /* @__PURE__ */ new WeakMap();
|
|
14522
|
-
|
|
14674
|
+
kind = "request";
|
|
14675
|
+
resolver;
|
|
14676
|
+
resolverIterator;
|
|
14677
|
+
resolverIteratorResult;
|
|
14678
|
+
options;
|
|
14523
14679
|
info;
|
|
14524
14680
|
/**
|
|
14525
14681
|
* Indicates whether this request handler has been used
|
|
14526
14682
|
* (its resolver has successfully executed).
|
|
14527
14683
|
*/
|
|
14528
14684
|
isUsed;
|
|
14529
|
-
resolver;
|
|
14530
|
-
resolverIterator;
|
|
14531
|
-
resolverIteratorResult;
|
|
14532
|
-
options;
|
|
14533
14685
|
constructor(args) {
|
|
14534
14686
|
this.resolver = args.resolver;
|
|
14535
14687
|
this.options = args.options;
|
|
@@ -14539,7 +14691,6 @@ ${operationTypes.join("\n")}
|
|
|
14539
14691
|
callFrame
|
|
14540
14692
|
};
|
|
14541
14693
|
this.isUsed = false;
|
|
14542
|
-
this.__kind = "RequestHandler";
|
|
14543
14694
|
}
|
|
14544
14695
|
/**
|
|
14545
14696
|
* Parse the intercepted request to extract additional information from it.
|
|
@@ -15553,40 +15704,205 @@ ${operationTypes.join("\n")}
|
|
|
15553
15704
|
return message4.toString();
|
|
15554
15705
|
}
|
|
15555
15706
|
|
|
15556
|
-
// node_modules/.pnpm
|
|
15557
|
-
var
|
|
15558
|
-
|
|
15559
|
-
|
|
15560
|
-
|
|
15561
|
-
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
}
|
|
15567
|
-
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
15568
|
-
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
15569
|
-
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
15570
|
-
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
15571
|
-
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
15572
|
-
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
15573
|
-
return InterceptorReadyState$1;
|
|
15574
|
-
})({});
|
|
15575
|
-
var Interceptor = class {
|
|
15576
|
-
constructor(symbol) {
|
|
15577
|
-
this.symbol = symbol;
|
|
15578
|
-
this.readyState = InterceptorReadyState.INACTIVE;
|
|
15579
|
-
this.emitter = new Emitter();
|
|
15580
|
-
this.subscriptions = [];
|
|
15581
|
-
this.logger = new Logger(symbol.description);
|
|
15582
|
-
this.emitter.setMaxListeners(0);
|
|
15583
|
-
this.logger.info("constructing the interceptor...");
|
|
15707
|
+
// node_modules/.pnpm/strict-event-emitter@0.5.1/node_modules/strict-event-emitter/lib/index.mjs
|
|
15708
|
+
var MemoryLeakError = class extends Error {
|
|
15709
|
+
constructor(emitter, type, count) {
|
|
15710
|
+
super(
|
|
15711
|
+
`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
|
|
15712
|
+
);
|
|
15713
|
+
this.emitter = emitter;
|
|
15714
|
+
this.type = type;
|
|
15715
|
+
this.count = count;
|
|
15716
|
+
this.name = "MaxListenersExceededWarning";
|
|
15584
15717
|
}
|
|
15585
|
-
|
|
15586
|
-
|
|
15587
|
-
|
|
15588
|
-
|
|
15589
|
-
|
|
15718
|
+
};
|
|
15719
|
+
var _Emitter = class {
|
|
15720
|
+
static listenerCount(emitter, eventName) {
|
|
15721
|
+
return emitter.listenerCount(eventName);
|
|
15722
|
+
}
|
|
15723
|
+
constructor() {
|
|
15724
|
+
this.events = /* @__PURE__ */ new Map();
|
|
15725
|
+
this.maxListeners = _Emitter.defaultMaxListeners;
|
|
15726
|
+
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
15727
|
+
}
|
|
15728
|
+
_emitInternalEvent(internalEventName, eventName, listener) {
|
|
15729
|
+
this.emit(
|
|
15730
|
+
internalEventName,
|
|
15731
|
+
...[eventName, listener]
|
|
15732
|
+
);
|
|
15733
|
+
}
|
|
15734
|
+
_getListeners(eventName) {
|
|
15735
|
+
return Array.prototype.concat.apply([], this.events.get(eventName)) || [];
|
|
15736
|
+
}
|
|
15737
|
+
_removeListener(listeners, listener) {
|
|
15738
|
+
const index = listeners.indexOf(listener);
|
|
15739
|
+
if (index > -1) {
|
|
15740
|
+
listeners.splice(index, 1);
|
|
15741
|
+
}
|
|
15742
|
+
return [];
|
|
15743
|
+
}
|
|
15744
|
+
_wrapOnceListener(eventName, listener) {
|
|
15745
|
+
const onceListener = (...data) => {
|
|
15746
|
+
this.removeListener(eventName, onceListener);
|
|
15747
|
+
return listener.apply(this, data);
|
|
15748
|
+
};
|
|
15749
|
+
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
15750
|
+
return onceListener;
|
|
15751
|
+
}
|
|
15752
|
+
setMaxListeners(maxListeners) {
|
|
15753
|
+
this.maxListeners = maxListeners;
|
|
15754
|
+
return this;
|
|
15755
|
+
}
|
|
15756
|
+
/**
|
|
15757
|
+
* Returns the current max listener value for the `Emitter` which is
|
|
15758
|
+
* either set by `emitter.setMaxListeners(n)` or defaults to
|
|
15759
|
+
* `Emitter.defaultMaxListeners`.
|
|
15760
|
+
*/
|
|
15761
|
+
getMaxListeners() {
|
|
15762
|
+
return this.maxListeners;
|
|
15763
|
+
}
|
|
15764
|
+
/**
|
|
15765
|
+
* Returns an array listing the events for which the emitter has registered listeners.
|
|
15766
|
+
* The values in the array will be strings or Symbols.
|
|
15767
|
+
*/
|
|
15768
|
+
eventNames() {
|
|
15769
|
+
return Array.from(this.events.keys());
|
|
15770
|
+
}
|
|
15771
|
+
/**
|
|
15772
|
+
* Synchronously calls each of the listeners registered for the event named `eventName`,
|
|
15773
|
+
* in the order they were registered, passing the supplied arguments to each.
|
|
15774
|
+
* Returns `true` if the event has listeners, `false` otherwise.
|
|
15775
|
+
*
|
|
15776
|
+
* @example
|
|
15777
|
+
* const emitter = new Emitter<{ hello: [string] }>()
|
|
15778
|
+
* emitter.emit('hello', 'John')
|
|
15779
|
+
*/
|
|
15780
|
+
emit(eventName, ...data) {
|
|
15781
|
+
const listeners = this._getListeners(eventName);
|
|
15782
|
+
listeners.forEach((listener) => {
|
|
15783
|
+
listener.apply(this, data);
|
|
15784
|
+
});
|
|
15785
|
+
return listeners.length > 0;
|
|
15786
|
+
}
|
|
15787
|
+
addListener(eventName, listener) {
|
|
15788
|
+
this._emitInternalEvent("newListener", eventName, listener);
|
|
15789
|
+
const nextListeners = this._getListeners(eventName).concat(listener);
|
|
15790
|
+
this.events.set(eventName, nextListeners);
|
|
15791
|
+
if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
|
|
15792
|
+
this.hasWarnedAboutPotentialMemoryLeak = true;
|
|
15793
|
+
const memoryLeakWarning = new MemoryLeakError(
|
|
15794
|
+
this,
|
|
15795
|
+
eventName,
|
|
15796
|
+
this.listenerCount(eventName)
|
|
15797
|
+
);
|
|
15798
|
+
console.warn(memoryLeakWarning);
|
|
15799
|
+
}
|
|
15800
|
+
return this;
|
|
15801
|
+
}
|
|
15802
|
+
on(eventName, listener) {
|
|
15803
|
+
return this.addListener(eventName, listener);
|
|
15804
|
+
}
|
|
15805
|
+
once(eventName, listener) {
|
|
15806
|
+
return this.addListener(
|
|
15807
|
+
eventName,
|
|
15808
|
+
this._wrapOnceListener(eventName, listener)
|
|
15809
|
+
);
|
|
15810
|
+
}
|
|
15811
|
+
prependListener(eventName, listener) {
|
|
15812
|
+
const listeners = this._getListeners(eventName);
|
|
15813
|
+
if (listeners.length > 0) {
|
|
15814
|
+
const nextListeners = [listener].concat(listeners);
|
|
15815
|
+
this.events.set(eventName, nextListeners);
|
|
15816
|
+
} else {
|
|
15817
|
+
this.events.set(eventName, listeners.concat(listener));
|
|
15818
|
+
}
|
|
15819
|
+
return this;
|
|
15820
|
+
}
|
|
15821
|
+
prependOnceListener(eventName, listener) {
|
|
15822
|
+
return this.prependListener(
|
|
15823
|
+
eventName,
|
|
15824
|
+
this._wrapOnceListener(eventName, listener)
|
|
15825
|
+
);
|
|
15826
|
+
}
|
|
15827
|
+
removeListener(eventName, listener) {
|
|
15828
|
+
const listeners = this._getListeners(eventName);
|
|
15829
|
+
if (listeners.length > 0) {
|
|
15830
|
+
this._removeListener(listeners, listener);
|
|
15831
|
+
this.events.set(eventName, listeners);
|
|
15832
|
+
this._emitInternalEvent("removeListener", eventName, listener);
|
|
15833
|
+
}
|
|
15834
|
+
return this;
|
|
15835
|
+
}
|
|
15836
|
+
/**
|
|
15837
|
+
* Alias for `emitter.removeListener()`.
|
|
15838
|
+
*
|
|
15839
|
+
* @example
|
|
15840
|
+
* emitter.off('hello', listener)
|
|
15841
|
+
*/
|
|
15842
|
+
off(eventName, listener) {
|
|
15843
|
+
return this.removeListener(eventName, listener);
|
|
15844
|
+
}
|
|
15845
|
+
removeAllListeners(eventName) {
|
|
15846
|
+
if (eventName) {
|
|
15847
|
+
this.events.delete(eventName);
|
|
15848
|
+
} else {
|
|
15849
|
+
this.events.clear();
|
|
15850
|
+
}
|
|
15851
|
+
return this;
|
|
15852
|
+
}
|
|
15853
|
+
/**
|
|
15854
|
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
15855
|
+
*/
|
|
15856
|
+
listeners(eventName) {
|
|
15857
|
+
return Array.from(this._getListeners(eventName));
|
|
15858
|
+
}
|
|
15859
|
+
/**
|
|
15860
|
+
* Returns the number of listeners listening to the event named `eventName`.
|
|
15861
|
+
*/
|
|
15862
|
+
listenerCount(eventName) {
|
|
15863
|
+
return this._getListeners(eventName).length;
|
|
15864
|
+
}
|
|
15865
|
+
rawListeners(eventName) {
|
|
15866
|
+
return this.listeners(eventName);
|
|
15867
|
+
}
|
|
15868
|
+
};
|
|
15869
|
+
var Emitter2 = _Emitter;
|
|
15870
|
+
Emitter2.defaultMaxListeners = 10;
|
|
15871
|
+
|
|
15872
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
15873
|
+
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
15874
|
+
function getGlobalSymbol(symbol) {
|
|
15875
|
+
return globalThis[symbol] || void 0;
|
|
15876
|
+
}
|
|
15877
|
+
function setGlobalSymbol(symbol, value) {
|
|
15878
|
+
globalThis[symbol] = value;
|
|
15879
|
+
}
|
|
15880
|
+
function deleteGlobalSymbol(symbol) {
|
|
15881
|
+
delete globalThis[symbol];
|
|
15882
|
+
}
|
|
15883
|
+
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
15884
|
+
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
15885
|
+
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
15886
|
+
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
15887
|
+
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
15888
|
+
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
15889
|
+
return InterceptorReadyState$1;
|
|
15890
|
+
})({});
|
|
15891
|
+
var Interceptor = class {
|
|
15892
|
+
constructor(symbol) {
|
|
15893
|
+
this.symbol = symbol;
|
|
15894
|
+
this.readyState = InterceptorReadyState.INACTIVE;
|
|
15895
|
+
this.emitter = new Emitter2();
|
|
15896
|
+
this.subscriptions = [];
|
|
15897
|
+
this.logger = new Logger(symbol.description);
|
|
15898
|
+
this.emitter.setMaxListeners(0);
|
|
15899
|
+
this.logger.info("constructing the interceptor...");
|
|
15900
|
+
}
|
|
15901
|
+
/**
|
|
15902
|
+
* Determine if this interceptor can be applied
|
|
15903
|
+
* in the current environment.
|
|
15904
|
+
*/
|
|
15905
|
+
checkEnvironment() {
|
|
15590
15906
|
return true;
|
|
15591
15907
|
}
|
|
15592
15908
|
/**
|
|
@@ -19772,59 +20088,303 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
19772
20088
|
}
|
|
19773
20089
|
};
|
|
19774
20090
|
|
|
19775
|
-
// src/core/
|
|
19776
|
-
|
|
19777
|
-
|
|
19778
|
-
|
|
19779
|
-
|
|
19780
|
-
|
|
19781
|
-
|
|
19782
|
-
|
|
19783
|
-
|
|
19784
|
-
this[kEmitter] = new Emitter();
|
|
19785
|
-
this.callFrame = getCallFrame(new Error());
|
|
19786
|
-
this.__kind = "EventHandler";
|
|
20091
|
+
// src/core/utils/internal/isObject.ts
|
|
20092
|
+
function isObject2(value) {
|
|
20093
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
20094
|
+
}
|
|
20095
|
+
|
|
20096
|
+
// src/core/ws/utils/getMessageLength.ts
|
|
20097
|
+
function getMessageLength(data) {
|
|
20098
|
+
if (data instanceof Blob) {
|
|
20099
|
+
return data.size;
|
|
19787
20100
|
}
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
callFrame;
|
|
19791
|
-
[kEmitter];
|
|
19792
|
-
parse(args) {
|
|
19793
|
-
const clientUrl = new URL(args.url);
|
|
19794
|
-
const resolvedHandlerUrl = this.url instanceof RegExp || this.url.startsWith("*") ? this.url : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl);
|
|
19795
|
-
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
19796
|
-
const match2 = matchRequestUrl(
|
|
19797
|
-
clientUrl,
|
|
19798
|
-
resolvedHandlerUrl,
|
|
19799
|
-
args.resolutionContext?.baseUrl
|
|
19800
|
-
);
|
|
19801
|
-
return {
|
|
19802
|
-
match: match2
|
|
19803
|
-
};
|
|
20101
|
+
if (isObject2(data) && "byteLength" in data) {
|
|
20102
|
+
return data.byteLength;
|
|
19804
20103
|
}
|
|
19805
|
-
|
|
19806
|
-
|
|
20104
|
+
return new Blob([data]).size;
|
|
20105
|
+
}
|
|
20106
|
+
|
|
20107
|
+
// src/core/ws/utils/truncateMessage.ts
|
|
20108
|
+
var MAX_LENGTH = 24;
|
|
20109
|
+
function truncateMessage(message4) {
|
|
20110
|
+
if (message4.length <= MAX_LENGTH) {
|
|
20111
|
+
return message4;
|
|
19807
20112
|
}
|
|
19808
|
-
|
|
19809
|
-
|
|
19810
|
-
|
|
19811
|
-
|
|
19812
|
-
|
|
19813
|
-
|
|
19814
|
-
|
|
19815
|
-
}
|
|
19816
|
-
const resolvedConnection = {
|
|
19817
|
-
...connection,
|
|
19818
|
-
params: parsedResult.match.params || {}
|
|
19819
|
-
};
|
|
19820
|
-
return this.connect(resolvedConnection);
|
|
20113
|
+
return `${message4.slice(0, MAX_LENGTH)}\u2026`;
|
|
20114
|
+
}
|
|
20115
|
+
|
|
20116
|
+
// src/core/ws/utils/getPublicData.ts
|
|
20117
|
+
async function getPublicData(data) {
|
|
20118
|
+
if (data instanceof Blob) {
|
|
20119
|
+
const text = await data.text();
|
|
20120
|
+
return `Blob(${truncateMessage(text)})`;
|
|
19821
20121
|
}
|
|
19822
|
-
|
|
19823
|
-
|
|
19824
|
-
|
|
19825
|
-
|
|
19826
|
-
|
|
19827
|
-
|
|
20122
|
+
if (isObject2(data)) {
|
|
20123
|
+
const text = new TextDecoder().decode(data);
|
|
20124
|
+
return `ArrayBuffer(${truncateMessage(text)})`;
|
|
20125
|
+
}
|
|
20126
|
+
return truncateMessage(data);
|
|
20127
|
+
}
|
|
20128
|
+
|
|
20129
|
+
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
20130
|
+
var colors = {
|
|
20131
|
+
system: "#3b82f6",
|
|
20132
|
+
outgoing: "#22c55e",
|
|
20133
|
+
incoming: "#ef4444",
|
|
20134
|
+
mocked: "#ff6a33"
|
|
20135
|
+
};
|
|
20136
|
+
function attachWebSocketLogger(connection) {
|
|
20137
|
+
const { client, server } = connection;
|
|
20138
|
+
const controller = new AbortController();
|
|
20139
|
+
logConnectionOpen(client);
|
|
20140
|
+
client.addEventListener(
|
|
20141
|
+
"message",
|
|
20142
|
+
(event) => {
|
|
20143
|
+
logOutgoingClientMessage(event);
|
|
20144
|
+
},
|
|
20145
|
+
{ signal: controller.signal }
|
|
20146
|
+
);
|
|
20147
|
+
client.addEventListener(
|
|
20148
|
+
"close",
|
|
20149
|
+
(event) => {
|
|
20150
|
+
logConnectionClose(event);
|
|
20151
|
+
},
|
|
20152
|
+
{ signal: controller.signal }
|
|
20153
|
+
);
|
|
20154
|
+
client.socket.addEventListener(
|
|
20155
|
+
"error",
|
|
20156
|
+
(event) => {
|
|
20157
|
+
logClientError(event);
|
|
20158
|
+
},
|
|
20159
|
+
{ signal: controller.signal }
|
|
20160
|
+
);
|
|
20161
|
+
const { send: originalClientSend } = client;
|
|
20162
|
+
client.send = new Proxy(client.send, {
|
|
20163
|
+
apply(target, thisArg, args) {
|
|
20164
|
+
const [data] = args;
|
|
20165
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
20166
|
+
Object.defineProperties(messageEvent, {
|
|
20167
|
+
currentTarget: {
|
|
20168
|
+
enumerable: true,
|
|
20169
|
+
writable: false,
|
|
20170
|
+
value: client.socket
|
|
20171
|
+
},
|
|
20172
|
+
target: {
|
|
20173
|
+
enumerable: true,
|
|
20174
|
+
writable: false,
|
|
20175
|
+
value: client.socket
|
|
20176
|
+
}
|
|
20177
|
+
});
|
|
20178
|
+
queueMicrotask(() => {
|
|
20179
|
+
logIncomingMockedClientMessage(messageEvent);
|
|
20180
|
+
});
|
|
20181
|
+
return Reflect.apply(target, thisArg, args);
|
|
20182
|
+
}
|
|
20183
|
+
});
|
|
20184
|
+
server.addEventListener(
|
|
20185
|
+
"open",
|
|
20186
|
+
() => {
|
|
20187
|
+
server.addEventListener("message", (event) => {
|
|
20188
|
+
logIncomingServerMessage(event);
|
|
20189
|
+
});
|
|
20190
|
+
},
|
|
20191
|
+
{
|
|
20192
|
+
once: true,
|
|
20193
|
+
signal: controller.signal
|
|
20194
|
+
}
|
|
20195
|
+
);
|
|
20196
|
+
const { send: originalServerSend } = server;
|
|
20197
|
+
server.send = new Proxy(server.send, {
|
|
20198
|
+
apply(target, thisArg, args) {
|
|
20199
|
+
const [data] = args;
|
|
20200
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
20201
|
+
Object.defineProperties(messageEvent, {
|
|
20202
|
+
currentTarget: {
|
|
20203
|
+
enumerable: true,
|
|
20204
|
+
writable: false,
|
|
20205
|
+
value: server.socket
|
|
20206
|
+
},
|
|
20207
|
+
target: {
|
|
20208
|
+
enumerable: true,
|
|
20209
|
+
writable: false,
|
|
20210
|
+
value: server.socket
|
|
20211
|
+
}
|
|
20212
|
+
});
|
|
20213
|
+
logOutgoingMockedClientMessage(messageEvent);
|
|
20214
|
+
return Reflect.apply(target, thisArg, args);
|
|
20215
|
+
}
|
|
20216
|
+
});
|
|
20217
|
+
controller.signal.addEventListener(
|
|
20218
|
+
"abort",
|
|
20219
|
+
() => {
|
|
20220
|
+
client.send = originalClientSend;
|
|
20221
|
+
server.send = originalServerSend;
|
|
20222
|
+
},
|
|
20223
|
+
{ once: true }
|
|
20224
|
+
);
|
|
20225
|
+
return () => {
|
|
20226
|
+
controller.abort();
|
|
20227
|
+
};
|
|
20228
|
+
}
|
|
20229
|
+
function logConnectionOpen(client) {
|
|
20230
|
+
const publicUrl = toPublicUrl(client.url);
|
|
20231
|
+
console.groupCollapsed(
|
|
20232
|
+
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
20233
|
+
`color:${colors.system}`,
|
|
20234
|
+
"color:inherit"
|
|
20235
|
+
);
|
|
20236
|
+
console.log("Client:", client.socket);
|
|
20237
|
+
console.groupEnd();
|
|
20238
|
+
}
|
|
20239
|
+
function logConnectionClose(event) {
|
|
20240
|
+
const target = event.target;
|
|
20241
|
+
const publicUrl = toPublicUrl(target.url);
|
|
20242
|
+
console.groupCollapsed(
|
|
20243
|
+
devUtils.formatMessage(
|
|
20244
|
+
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
20245
|
+
),
|
|
20246
|
+
`color:${colors.system}`,
|
|
20247
|
+
"color:inherit"
|
|
20248
|
+
);
|
|
20249
|
+
console.log(event);
|
|
20250
|
+
console.groupEnd();
|
|
20251
|
+
}
|
|
20252
|
+
function logClientError(event) {
|
|
20253
|
+
const socket = event.target;
|
|
20254
|
+
const publicUrl = toPublicUrl(socket.url);
|
|
20255
|
+
console.groupCollapsed(
|
|
20256
|
+
devUtils.formatMessage(
|
|
20257
|
+
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
20258
|
+
),
|
|
20259
|
+
`color:${colors.system}`,
|
|
20260
|
+
"color:inherit"
|
|
20261
|
+
);
|
|
20262
|
+
console.log(event);
|
|
20263
|
+
console.groupEnd();
|
|
20264
|
+
}
|
|
20265
|
+
async function logOutgoingClientMessage(event) {
|
|
20266
|
+
const byteLength = getMessageLength(event.data);
|
|
20267
|
+
const publicData = await getPublicData(event.data);
|
|
20268
|
+
const arrow = event.defaultPrevented ? "\u21E1" : "\u2B06";
|
|
20269
|
+
console.groupCollapsed(
|
|
20270
|
+
devUtils.formatMessage(
|
|
20271
|
+
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
20272
|
+
),
|
|
20273
|
+
`color:${colors.outgoing}`,
|
|
20274
|
+
"color:inherit",
|
|
20275
|
+
"color:gray;font-weight:normal",
|
|
20276
|
+
"color:inherit;font-weight:inherit"
|
|
20277
|
+
);
|
|
20278
|
+
console.log(event);
|
|
20279
|
+
console.groupEnd();
|
|
20280
|
+
}
|
|
20281
|
+
async function logOutgoingMockedClientMessage(event) {
|
|
20282
|
+
const byteLength = getMessageLength(event.data);
|
|
20283
|
+
const publicData = await getPublicData(event.data);
|
|
20284
|
+
console.groupCollapsed(
|
|
20285
|
+
devUtils.formatMessage(
|
|
20286
|
+
`${getTimestamp({ milliseconds: true })} %c\u2B06%c ${publicData} %c${byteLength}%c`
|
|
20287
|
+
),
|
|
20288
|
+
`color:${colors.mocked}`,
|
|
20289
|
+
"color:inherit",
|
|
20290
|
+
"color:gray;font-weight:normal",
|
|
20291
|
+
"color:inherit;font-weight:inherit"
|
|
20292
|
+
);
|
|
20293
|
+
console.log(event);
|
|
20294
|
+
console.groupEnd();
|
|
20295
|
+
}
|
|
20296
|
+
async function logIncomingMockedClientMessage(event) {
|
|
20297
|
+
const byteLength = getMessageLength(event.data);
|
|
20298
|
+
const publicData = await getPublicData(event.data);
|
|
20299
|
+
console.groupCollapsed(
|
|
20300
|
+
devUtils.formatMessage(
|
|
20301
|
+
`${getTimestamp({ milliseconds: true })} %c\u2B07%c ${publicData} %c${byteLength}%c`
|
|
20302
|
+
),
|
|
20303
|
+
`color:${colors.mocked}`,
|
|
20304
|
+
"color:inherit",
|
|
20305
|
+
"color:gray;font-weight:normal",
|
|
20306
|
+
"color:inherit;font-weight:inherit"
|
|
20307
|
+
);
|
|
20308
|
+
console.log(event);
|
|
20309
|
+
console.groupEnd();
|
|
20310
|
+
}
|
|
20311
|
+
async function logIncomingServerMessage(event) {
|
|
20312
|
+
const byteLength = getMessageLength(event.data);
|
|
20313
|
+
const publicData = await getPublicData(event.data);
|
|
20314
|
+
const arrow = event.defaultPrevented ? "\u21E3" : "\u2B07";
|
|
20315
|
+
console.groupCollapsed(
|
|
20316
|
+
devUtils.formatMessage(
|
|
20317
|
+
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
20318
|
+
),
|
|
20319
|
+
`color:${colors.incoming}`,
|
|
20320
|
+
"color:inherit",
|
|
20321
|
+
"color:gray;font-weight:normal",
|
|
20322
|
+
"color:inherit;font-weight:inherit"
|
|
20323
|
+
);
|
|
20324
|
+
console.log(event);
|
|
20325
|
+
console.groupEnd();
|
|
20326
|
+
}
|
|
20327
|
+
|
|
20328
|
+
// src/core/handlers/WebSocketHandler.ts
|
|
20329
|
+
var kEmitter = Symbol("kEmitter");
|
|
20330
|
+
var kSender = Symbol("kSender");
|
|
20331
|
+
var kConnect = Symbol("kConnect");
|
|
20332
|
+
var kAutoConnect = Symbol("kAutoConnect");
|
|
20333
|
+
var kStopPropagationPatched = Symbol("kStopPropagationPatched");
|
|
20334
|
+
var KOnStopPropagation = Symbol("KOnStopPropagation");
|
|
20335
|
+
var WebSocketHandler = class {
|
|
20336
|
+
constructor(url) {
|
|
20337
|
+
this.url = url;
|
|
20338
|
+
this.id = createRequestId();
|
|
20339
|
+
this[kEmitter] = new Emitter2();
|
|
20340
|
+
this.callFrame = getCallFrame(new Error());
|
|
20341
|
+
}
|
|
20342
|
+
id;
|
|
20343
|
+
callFrame;
|
|
20344
|
+
kind = "websocket";
|
|
20345
|
+
[kEmitter];
|
|
20346
|
+
parse(args) {
|
|
20347
|
+
const clientUrl = new URL(args.url);
|
|
20348
|
+
const resolvedHandlerUrl = this.url instanceof RegExp || this.url.startsWith("*") ? this.url : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl);
|
|
20349
|
+
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
20350
|
+
const match2 = matchRequestUrl(
|
|
20351
|
+
clientUrl,
|
|
20352
|
+
resolvedHandlerUrl,
|
|
20353
|
+
args.resolutionContext?.baseUrl
|
|
20354
|
+
);
|
|
20355
|
+
return {
|
|
20356
|
+
match: match2
|
|
20357
|
+
};
|
|
20358
|
+
}
|
|
20359
|
+
predicate(args) {
|
|
20360
|
+
return args.parsedResult.match.matches;
|
|
20361
|
+
}
|
|
20362
|
+
async run(connection, resolutionContext) {
|
|
20363
|
+
const parsedResult = this.parse({
|
|
20364
|
+
url: connection.client.url,
|
|
20365
|
+
resolutionContext
|
|
20366
|
+
});
|
|
20367
|
+
if (!this.predicate({ url: connection.client.url, parsedResult })) {
|
|
20368
|
+
return null;
|
|
20369
|
+
}
|
|
20370
|
+
const resolvedConnection = {
|
|
20371
|
+
...connection,
|
|
20372
|
+
params: parsedResult.match.params || {}
|
|
20373
|
+
};
|
|
20374
|
+
if (resolutionContext?.[kAutoConnect]) {
|
|
20375
|
+
if (this[kConnect](resolvedConnection)) {
|
|
20376
|
+
return resolvedConnection;
|
|
20377
|
+
}
|
|
20378
|
+
return null;
|
|
20379
|
+
}
|
|
20380
|
+
return resolvedConnection;
|
|
20381
|
+
}
|
|
20382
|
+
[kConnect](connection) {
|
|
20383
|
+
connection.client.addEventListener(
|
|
20384
|
+
"message",
|
|
20385
|
+
createStopPropagationListener(this)
|
|
20386
|
+
);
|
|
20387
|
+
connection.client.addEventListener(
|
|
19828
20388
|
"close",
|
|
19829
20389
|
createStopPropagationListener(this)
|
|
19830
20390
|
);
|
|
@@ -19846,6 +20406,9 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
19846
20406
|
);
|
|
19847
20407
|
return this[kEmitter].emit("connection", connection);
|
|
19848
20408
|
}
|
|
20409
|
+
log(connection) {
|
|
20410
|
+
return attachWebSocketLogger(connection);
|
|
20411
|
+
}
|
|
19849
20412
|
#resolveWebSocketUrl(url, baseUrl) {
|
|
19850
20413
|
const resolvedUrl = resolveWebSocketUrl(
|
|
19851
20414
|
baseUrl ? (
|
|
@@ -20247,223 +20810,15 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
20247
20810
|
});
|
|
20248
20811
|
}
|
|
20249
20812
|
|
|
20250
|
-
// src/core/
|
|
20251
|
-
|
|
20252
|
-
return
|
|
20253
|
-
}
|
|
20254
|
-
|
|
20255
|
-
|
|
20256
|
-
|
|
20257
|
-
|
|
20258
|
-
|
|
20259
|
-
}
|
|
20260
|
-
if (isObject2(data) && "byteLength" in data) {
|
|
20261
|
-
return data.byteLength;
|
|
20262
|
-
}
|
|
20263
|
-
return new Blob([data]).size;
|
|
20264
|
-
}
|
|
20265
|
-
|
|
20266
|
-
// src/core/ws/utils/truncateMessage.ts
|
|
20267
|
-
var MAX_LENGTH = 24;
|
|
20268
|
-
function truncateMessage(message4) {
|
|
20269
|
-
if (message4.length <= MAX_LENGTH) {
|
|
20270
|
-
return message4;
|
|
20271
|
-
}
|
|
20272
|
-
return `${message4.slice(0, MAX_LENGTH)}\u2026`;
|
|
20273
|
-
}
|
|
20274
|
-
|
|
20275
|
-
// src/core/ws/utils/getPublicData.ts
|
|
20276
|
-
async function getPublicData(data) {
|
|
20277
|
-
if (data instanceof Blob) {
|
|
20278
|
-
const text = await data.text();
|
|
20279
|
-
return `Blob(${truncateMessage(text)})`;
|
|
20280
|
-
}
|
|
20281
|
-
if (isObject2(data)) {
|
|
20282
|
-
const text = new TextDecoder().decode(data);
|
|
20283
|
-
return `ArrayBuffer(${truncateMessage(text)})`;
|
|
20284
|
-
}
|
|
20285
|
-
return truncateMessage(data);
|
|
20286
|
-
}
|
|
20287
|
-
|
|
20288
|
-
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
20289
|
-
var colors = {
|
|
20290
|
-
system: "#3b82f6",
|
|
20291
|
-
outgoing: "#22c55e",
|
|
20292
|
-
incoming: "#ef4444",
|
|
20293
|
-
mocked: "#ff6a33"
|
|
20294
|
-
};
|
|
20295
|
-
function attachWebSocketLogger(connection) {
|
|
20296
|
-
const { client, server } = connection;
|
|
20297
|
-
logConnectionOpen(client);
|
|
20298
|
-
client.addEventListener("message", (event) => {
|
|
20299
|
-
logOutgoingClientMessage(event);
|
|
20300
|
-
});
|
|
20301
|
-
client.addEventListener("close", (event) => {
|
|
20302
|
-
logConnectionClose(event);
|
|
20303
|
-
});
|
|
20304
|
-
client.socket.addEventListener("error", (event) => {
|
|
20305
|
-
logClientError(event);
|
|
20306
|
-
});
|
|
20307
|
-
client.send = new Proxy(client.send, {
|
|
20308
|
-
apply(target, thisArg, args) {
|
|
20309
|
-
const [data] = args;
|
|
20310
|
-
const messageEvent = new MessageEvent("message", { data });
|
|
20311
|
-
Object.defineProperties(messageEvent, {
|
|
20312
|
-
currentTarget: {
|
|
20313
|
-
enumerable: true,
|
|
20314
|
-
writable: false,
|
|
20315
|
-
value: client.socket
|
|
20316
|
-
},
|
|
20317
|
-
target: {
|
|
20318
|
-
enumerable: true,
|
|
20319
|
-
writable: false,
|
|
20320
|
-
value: client.socket
|
|
20321
|
-
}
|
|
20322
|
-
});
|
|
20323
|
-
queueMicrotask(() => {
|
|
20324
|
-
logIncomingMockedClientMessage(messageEvent);
|
|
20325
|
-
});
|
|
20326
|
-
return Reflect.apply(target, thisArg, args);
|
|
20327
|
-
}
|
|
20328
|
-
});
|
|
20329
|
-
server.addEventListener(
|
|
20330
|
-
"open",
|
|
20331
|
-
() => {
|
|
20332
|
-
server.addEventListener("message", (event) => {
|
|
20333
|
-
logIncomingServerMessage(event);
|
|
20334
|
-
});
|
|
20335
|
-
},
|
|
20336
|
-
{ once: true }
|
|
20337
|
-
);
|
|
20338
|
-
server.send = new Proxy(server.send, {
|
|
20339
|
-
apply(target, thisArg, args) {
|
|
20340
|
-
const [data] = args;
|
|
20341
|
-
const messageEvent = new MessageEvent("message", { data });
|
|
20342
|
-
Object.defineProperties(messageEvent, {
|
|
20343
|
-
currentTarget: {
|
|
20344
|
-
enumerable: true,
|
|
20345
|
-
writable: false,
|
|
20346
|
-
value: server.socket
|
|
20347
|
-
},
|
|
20348
|
-
target: {
|
|
20349
|
-
enumerable: true,
|
|
20350
|
-
writable: false,
|
|
20351
|
-
value: server.socket
|
|
20352
|
-
}
|
|
20353
|
-
});
|
|
20354
|
-
logOutgoingMockedClientMessage(messageEvent);
|
|
20355
|
-
return Reflect.apply(target, thisArg, args);
|
|
20356
|
-
}
|
|
20357
|
-
});
|
|
20358
|
-
}
|
|
20359
|
-
function logConnectionOpen(client) {
|
|
20360
|
-
const publicUrl = toPublicUrl(client.url);
|
|
20361
|
-
console.groupCollapsed(
|
|
20362
|
-
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
20363
|
-
`color:${colors.system}`,
|
|
20364
|
-
"color:inherit"
|
|
20365
|
-
);
|
|
20366
|
-
console.log("Client:", client.socket);
|
|
20367
|
-
console.groupEnd();
|
|
20368
|
-
}
|
|
20369
|
-
function logConnectionClose(event) {
|
|
20370
|
-
const target = event.target;
|
|
20371
|
-
const publicUrl = toPublicUrl(target.url);
|
|
20372
|
-
console.groupCollapsed(
|
|
20373
|
-
devUtils.formatMessage(
|
|
20374
|
-
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
20375
|
-
),
|
|
20376
|
-
`color:${colors.system}`,
|
|
20377
|
-
"color:inherit"
|
|
20378
|
-
);
|
|
20379
|
-
console.log(event);
|
|
20380
|
-
console.groupEnd();
|
|
20381
|
-
}
|
|
20382
|
-
function logClientError(event) {
|
|
20383
|
-
const socket = event.target;
|
|
20384
|
-
const publicUrl = toPublicUrl(socket.url);
|
|
20385
|
-
console.groupCollapsed(
|
|
20386
|
-
devUtils.formatMessage(
|
|
20387
|
-
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
20388
|
-
),
|
|
20389
|
-
`color:${colors.system}`,
|
|
20390
|
-
"color:inherit"
|
|
20391
|
-
);
|
|
20392
|
-
console.log(event);
|
|
20393
|
-
console.groupEnd();
|
|
20394
|
-
}
|
|
20395
|
-
async function logOutgoingClientMessage(event) {
|
|
20396
|
-
const byteLength = getMessageLength(event.data);
|
|
20397
|
-
const publicData = await getPublicData(event.data);
|
|
20398
|
-
const arrow = event.defaultPrevented ? "\u21E1" : "\u2B06";
|
|
20399
|
-
console.groupCollapsed(
|
|
20400
|
-
devUtils.formatMessage(
|
|
20401
|
-
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
20402
|
-
),
|
|
20403
|
-
`color:${colors.outgoing}`,
|
|
20404
|
-
"color:inherit",
|
|
20405
|
-
"color:gray;font-weight:normal",
|
|
20406
|
-
"color:inherit;font-weight:inherit"
|
|
20407
|
-
);
|
|
20408
|
-
console.log(event);
|
|
20409
|
-
console.groupEnd();
|
|
20410
|
-
}
|
|
20411
|
-
async function logOutgoingMockedClientMessage(event) {
|
|
20412
|
-
const byteLength = getMessageLength(event.data);
|
|
20413
|
-
const publicData = await getPublicData(event.data);
|
|
20414
|
-
console.groupCollapsed(
|
|
20415
|
-
devUtils.formatMessage(
|
|
20416
|
-
`${getTimestamp({ milliseconds: true })} %c\u2B06%c ${publicData} %c${byteLength}%c`
|
|
20417
|
-
),
|
|
20418
|
-
`color:${colors.mocked}`,
|
|
20419
|
-
"color:inherit",
|
|
20420
|
-
"color:gray;font-weight:normal",
|
|
20421
|
-
"color:inherit;font-weight:inherit"
|
|
20422
|
-
);
|
|
20423
|
-
console.log(event);
|
|
20424
|
-
console.groupEnd();
|
|
20425
|
-
}
|
|
20426
|
-
async function logIncomingMockedClientMessage(event) {
|
|
20427
|
-
const byteLength = getMessageLength(event.data);
|
|
20428
|
-
const publicData = await getPublicData(event.data);
|
|
20429
|
-
console.groupCollapsed(
|
|
20430
|
-
devUtils.formatMessage(
|
|
20431
|
-
`${getTimestamp({ milliseconds: true })} %c\u2B07%c ${publicData} %c${byteLength}%c`
|
|
20432
|
-
),
|
|
20433
|
-
`color:${colors.mocked}`,
|
|
20434
|
-
"color:inherit",
|
|
20435
|
-
"color:gray;font-weight:normal",
|
|
20436
|
-
"color:inherit;font-weight:inherit"
|
|
20437
|
-
);
|
|
20438
|
-
console.log(event);
|
|
20439
|
-
console.groupEnd();
|
|
20440
|
-
}
|
|
20441
|
-
async function logIncomingServerMessage(event) {
|
|
20442
|
-
const byteLength = getMessageLength(event.data);
|
|
20443
|
-
const publicData = await getPublicData(event.data);
|
|
20444
|
-
const arrow = event.defaultPrevented ? "\u21E3" : "\u2B07";
|
|
20445
|
-
console.groupCollapsed(
|
|
20446
|
-
devUtils.formatMessage(
|
|
20447
|
-
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
20448
|
-
),
|
|
20449
|
-
`color:${colors.incoming}`,
|
|
20450
|
-
"color:inherit",
|
|
20451
|
-
"color:gray;font-weight:normal",
|
|
20452
|
-
"color:inherit;font-weight:inherit"
|
|
20453
|
-
);
|
|
20454
|
-
console.log(event);
|
|
20455
|
-
console.groupEnd();
|
|
20456
|
-
}
|
|
20457
|
-
|
|
20458
|
-
// src/core/sse.ts
|
|
20459
|
-
var sse = (path, resolver) => {
|
|
20460
|
-
return new ServerSentEventHandler(path, resolver);
|
|
20461
|
-
};
|
|
20462
|
-
var SSE_RESPONSE_INIT = {
|
|
20463
|
-
headers: {
|
|
20464
|
-
"content-type": "text/event-stream",
|
|
20465
|
-
"cache-control": "no-cache",
|
|
20466
|
-
connection: "keep-alive"
|
|
20813
|
+
// src/core/sse.ts
|
|
20814
|
+
var sse = (path, resolver) => {
|
|
20815
|
+
return new ServerSentEventHandler(path, resolver);
|
|
20816
|
+
};
|
|
20817
|
+
var SSE_RESPONSE_INIT = {
|
|
20818
|
+
headers: {
|
|
20819
|
+
"content-type": "text/event-stream",
|
|
20820
|
+
"cache-control": "no-cache",
|
|
20821
|
+
connection: "keep-alive"
|
|
20467
20822
|
}
|
|
20468
20823
|
};
|
|
20469
20824
|
var ServerSentEventHandler = class extends HttpHandler {
|
|
@@ -20494,7 +20849,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
20494
20849
|
});
|
|
20495
20850
|
return new Response(stream, SSE_RESPONSE_INIT);
|
|
20496
20851
|
});
|
|
20497
|
-
this.#emitter = new
|
|
20852
|
+
this.#emitter = new Emitter2();
|
|
20498
20853
|
}
|
|
20499
20854
|
async predicate(args) {
|
|
20500
20855
|
if (args.request.headers.get("accept") !== "text/event-stream") {
|
|
@@ -21237,493 +21592,47 @@ Read more: https://mswjs.io/docs/http/intercepting-requests`;
|
|
|
21237
21592
|
// src/core/index.ts
|
|
21238
21593
|
checkGlobals();
|
|
21239
21594
|
|
|
21240
|
-
//
|
|
21241
|
-
function
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
21246
|
-
result[key] = leftValue.concat(rightValue);
|
|
21247
|
-
return result;
|
|
21248
|
-
}
|
|
21249
|
-
if (isObject2(leftValue) && isObject2(rightValue)) {
|
|
21250
|
-
result[key] = mergeRight(leftValue, rightValue);
|
|
21251
|
-
return result;
|
|
21252
|
-
}
|
|
21253
|
-
result[key] = rightValue;
|
|
21254
|
-
return result;
|
|
21255
|
-
},
|
|
21256
|
-
Object.assign({}, left)
|
|
21257
|
-
);
|
|
21595
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
21596
|
+
async function emitAsync(emitter, eventName, ...data) {
|
|
21597
|
+
const listeners = emitter.listeners(eventName);
|
|
21598
|
+
if (listeners.length === 0) return;
|
|
21599
|
+
for (const listener of listeners) await listener.apply(emitter, data);
|
|
21258
21600
|
}
|
|
21259
|
-
|
|
21260
|
-
|
|
21261
|
-
|
|
21262
|
-
|
|
21263
|
-
|
|
21264
|
-
|
|
21265
|
-
|
|
21266
|
-
|
|
21267
|
-
waitUntilReady: true,
|
|
21268
|
-
onUnhandledRequest: "warn",
|
|
21269
|
-
findWorker(scriptURL, mockServiceWorkerUrl) {
|
|
21270
|
-
return scriptURL === mockServiceWorkerUrl;
|
|
21601
|
+
function hasConfigurableGlobal(propertyName) {
|
|
21602
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
21603
|
+
if (typeof descriptor === "undefined") return false;
|
|
21604
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
21605
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
21606
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
21607
|
+
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
21608
|
+
return false;
|
|
21271
21609
|
}
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
21275
|
-
function getAbsoluteWorkerUrl(workerUrl) {
|
|
21276
|
-
return new URL(workerUrl, location.href).href;
|
|
21610
|
+
return true;
|
|
21277
21611
|
}
|
|
21278
21612
|
|
|
21279
|
-
//
|
|
21280
|
-
function
|
|
21281
|
-
|
|
21282
|
-
|
|
21283
|
-
|
|
21284
|
-
|
|
21285
|
-
|
|
21286
|
-
|
|
21287
|
-
|
|
21288
|
-
|
|
21289
|
-
|
|
21290
|
-
|
|
21613
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
21614
|
+
function bindEvent(target, event) {
|
|
21615
|
+
Object.defineProperties(event, {
|
|
21616
|
+
target: {
|
|
21617
|
+
value: target,
|
|
21618
|
+
enumerable: true,
|
|
21619
|
+
writable: true
|
|
21620
|
+
},
|
|
21621
|
+
currentTarget: {
|
|
21622
|
+
value: target,
|
|
21623
|
+
enumerable: true,
|
|
21624
|
+
writable: true
|
|
21625
|
+
}
|
|
21291
21626
|
});
|
|
21292
|
-
return
|
|
21293
|
-
}
|
|
21294
|
-
|
|
21295
|
-
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
21296
|
-
var getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
21297
|
-
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
21298
|
-
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then(
|
|
21299
|
-
(registrations) => registrations.filter(
|
|
21300
|
-
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
21301
|
-
)
|
|
21302
|
-
);
|
|
21303
|
-
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
21304
|
-
location.reload();
|
|
21305
|
-
}
|
|
21306
|
-
const [existingRegistration] = mockRegistrations;
|
|
21307
|
-
if (existingRegistration) {
|
|
21308
|
-
existingRegistration.update();
|
|
21309
|
-
return [
|
|
21310
|
-
getWorkerByRegistration(
|
|
21311
|
-
existingRegistration,
|
|
21312
|
-
absoluteWorkerUrl,
|
|
21313
|
-
findWorker
|
|
21314
|
-
),
|
|
21315
|
-
existingRegistration
|
|
21316
|
-
];
|
|
21317
|
-
}
|
|
21318
|
-
const [registrationError, registrationResult] = await until(async () => {
|
|
21319
|
-
const registration = await navigator.serviceWorker.register(url, options);
|
|
21320
|
-
return [
|
|
21321
|
-
// Compare existing worker registration by its worker URL,
|
|
21322
|
-
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
21323
|
-
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
21324
|
-
registration
|
|
21325
|
-
];
|
|
21326
|
-
});
|
|
21327
|
-
if (registrationError) {
|
|
21328
|
-
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
21329
|
-
if (isWorkerMissing) {
|
|
21330
|
-
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
21331
|
-
throw new Error(
|
|
21332
|
-
devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
21333
|
-
|
|
21334
|
-
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
21335
|
-
|
|
21336
|
-
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
21337
|
-
);
|
|
21338
|
-
}
|
|
21339
|
-
throw new Error(
|
|
21340
|
-
devUtils.formatMessage(
|
|
21341
|
-
"Failed to register the Service Worker:\n\n%s",
|
|
21342
|
-
registrationError.message
|
|
21343
|
-
)
|
|
21344
|
-
);
|
|
21345
|
-
}
|
|
21346
|
-
return registrationResult;
|
|
21347
|
-
};
|
|
21348
|
-
|
|
21349
|
-
// src/browser/setupWorker/start/utils/printStartMessage.ts
|
|
21350
|
-
function printStartMessage(args = {}) {
|
|
21351
|
-
if (args.quiet) {
|
|
21352
|
-
return;
|
|
21353
|
-
}
|
|
21354
|
-
const message4 = args.message || "Mocking enabled.";
|
|
21355
|
-
console.groupCollapsed(
|
|
21356
|
-
`%c${devUtils.formatMessage(message4)}`,
|
|
21357
|
-
"color:orangered;font-weight:bold;"
|
|
21358
|
-
);
|
|
21359
|
-
console.log(
|
|
21360
|
-
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
21361
|
-
"font-weight:bold",
|
|
21362
|
-
"font-weight:normal"
|
|
21363
|
-
);
|
|
21364
|
-
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
21365
|
-
if (args.workerUrl) {
|
|
21366
|
-
console.log("Worker script URL:", args.workerUrl);
|
|
21367
|
-
}
|
|
21368
|
-
if (args.workerScope) {
|
|
21369
|
-
console.log("Worker scope:", args.workerScope);
|
|
21370
|
-
}
|
|
21371
|
-
if (args.client) {
|
|
21372
|
-
console.log("Client ID: %s (%s)", args.client.id, args.client.frameType);
|
|
21373
|
-
}
|
|
21374
|
-
console.groupEnd();
|
|
21375
|
-
}
|
|
21376
|
-
|
|
21377
|
-
// src/browser/setupWorker/start/utils/enableMocking.ts
|
|
21378
|
-
function enableMocking(context, options) {
|
|
21379
|
-
const mockingEnabledPromise = new DeferredPromise();
|
|
21380
|
-
context.workerChannel.postMessage("MOCK_ACTIVATE");
|
|
21381
|
-
context.workerChannel.once("MOCKING_ENABLED", async (event) => {
|
|
21382
|
-
context.isMockingEnabled = true;
|
|
21383
|
-
const worker = await context.workerPromise;
|
|
21384
|
-
printStartMessage({
|
|
21385
|
-
quiet: options.quiet,
|
|
21386
|
-
workerScope: context.registration?.scope,
|
|
21387
|
-
workerUrl: worker.scriptURL,
|
|
21388
|
-
client: event.data.client
|
|
21389
|
-
});
|
|
21390
|
-
mockingEnabledPromise.resolve(true);
|
|
21391
|
-
});
|
|
21392
|
-
return mockingEnabledPromise;
|
|
21393
|
-
}
|
|
21394
|
-
|
|
21395
|
-
// src/browser/utils/pruneGetRequestBody.ts
|
|
21396
|
-
function pruneGetRequestBody(request) {
|
|
21397
|
-
if (["HEAD", "GET"].includes(request.method)) {
|
|
21398
|
-
return void 0;
|
|
21399
|
-
}
|
|
21400
|
-
return request.body;
|
|
21401
|
-
}
|
|
21402
|
-
|
|
21403
|
-
// src/browser/utils/deserializeRequest.ts
|
|
21404
|
-
function deserializeRequest(serializedRequest) {
|
|
21405
|
-
return new Request(serializedRequest.url, {
|
|
21406
|
-
...serializedRequest,
|
|
21407
|
-
body: pruneGetRequestBody(serializedRequest)
|
|
21408
|
-
});
|
|
21409
|
-
}
|
|
21410
|
-
|
|
21411
|
-
// src/browser/utils/supports.ts
|
|
21412
|
-
function supportsServiceWorker() {
|
|
21413
|
-
return typeof navigator !== "undefined" && "serviceWorker" in navigator && typeof location !== "undefined" && location.protocol !== "file:";
|
|
21414
|
-
}
|
|
21415
|
-
function supportsReadableStreamTransfer() {
|
|
21416
|
-
try {
|
|
21417
|
-
const stream = new ReadableStream({
|
|
21418
|
-
start: (controller) => controller.close()
|
|
21419
|
-
});
|
|
21420
|
-
const message4 = new MessageChannel();
|
|
21421
|
-
message4.port1.postMessage(stream, [stream]);
|
|
21422
|
-
return true;
|
|
21423
|
-
} catch {
|
|
21424
|
-
return false;
|
|
21425
|
-
}
|
|
21426
|
-
}
|
|
21427
|
-
|
|
21428
|
-
// src/core/utils/toResponseInit.ts
|
|
21429
|
-
function toResponseInit(response) {
|
|
21430
|
-
return {
|
|
21431
|
-
status: response.status,
|
|
21432
|
-
statusText: response.statusText,
|
|
21433
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
21434
|
-
};
|
|
21435
|
-
}
|
|
21436
|
-
|
|
21437
|
-
// src/core/utils/internal/isHandlerKind.ts
|
|
21438
|
-
function isHandlerKind(kind) {
|
|
21439
|
-
return (input) => {
|
|
21440
|
-
return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
|
|
21441
|
-
};
|
|
21442
|
-
}
|
|
21443
|
-
|
|
21444
|
-
// src/browser/setupWorker/start/createRequestListener.ts
|
|
21445
|
-
var SUPPORTS_READABLE_STREAM_TRANSFER = supportsReadableStreamTransfer();
|
|
21446
|
-
var createRequestListener = (context, options) => {
|
|
21447
|
-
return async (event) => {
|
|
21448
|
-
if (!context.isMockingEnabled && context.workerStoppedAt && event.data.interceptedAt > context.workerStoppedAt) {
|
|
21449
|
-
event.postMessage("PASSTHROUGH");
|
|
21450
|
-
return;
|
|
21451
|
-
}
|
|
21452
|
-
const requestId = event.data.id;
|
|
21453
|
-
const request = deserializeRequest(event.data);
|
|
21454
|
-
const requestCloneForLogs = request.clone();
|
|
21455
|
-
const requestClone = request.clone();
|
|
21456
|
-
RequestHandler.cache.set(request, requestClone);
|
|
21457
|
-
try {
|
|
21458
|
-
await handleRequest(
|
|
21459
|
-
request,
|
|
21460
|
-
requestId,
|
|
21461
|
-
context.getRequestHandlers().filter(isHandlerKind("RequestHandler")),
|
|
21462
|
-
options,
|
|
21463
|
-
context.emitter,
|
|
21464
|
-
{
|
|
21465
|
-
resolutionContext: {
|
|
21466
|
-
quiet: options.quiet
|
|
21467
|
-
},
|
|
21468
|
-
onPassthroughResponse() {
|
|
21469
|
-
event.postMessage("PASSTHROUGH");
|
|
21470
|
-
},
|
|
21471
|
-
async onMockedResponse(response, { handler, parsedResult }) {
|
|
21472
|
-
const responseClone = response.clone();
|
|
21473
|
-
const responseCloneForLogs = response.clone();
|
|
21474
|
-
const responseInit = toResponseInit(response);
|
|
21475
|
-
if (SUPPORTS_READABLE_STREAM_TRANSFER) {
|
|
21476
|
-
const responseStreamOrNull = response.body;
|
|
21477
|
-
event.postMessage(
|
|
21478
|
-
"MOCK_RESPONSE",
|
|
21479
|
-
{
|
|
21480
|
-
...responseInit,
|
|
21481
|
-
body: responseStreamOrNull
|
|
21482
|
-
},
|
|
21483
|
-
responseStreamOrNull ? [responseStreamOrNull] : void 0
|
|
21484
|
-
);
|
|
21485
|
-
} else {
|
|
21486
|
-
const responseBufferOrNull = response.body === null ? null : await responseClone.arrayBuffer();
|
|
21487
|
-
event.postMessage("MOCK_RESPONSE", {
|
|
21488
|
-
...responseInit,
|
|
21489
|
-
body: responseBufferOrNull
|
|
21490
|
-
});
|
|
21491
|
-
}
|
|
21492
|
-
if (!options.quiet) {
|
|
21493
|
-
context.emitter.once("response:mocked", () => {
|
|
21494
|
-
handler.log({
|
|
21495
|
-
request: requestCloneForLogs,
|
|
21496
|
-
response: responseCloneForLogs,
|
|
21497
|
-
parsedResult
|
|
21498
|
-
});
|
|
21499
|
-
});
|
|
21500
|
-
}
|
|
21501
|
-
}
|
|
21502
|
-
}
|
|
21503
|
-
);
|
|
21504
|
-
} catch (error3) {
|
|
21505
|
-
if (error3 instanceof Error) {
|
|
21506
|
-
devUtils.error(
|
|
21507
|
-
`Uncaught exception in the request handler for "%s %s":
|
|
21508
|
-
|
|
21509
|
-
%s
|
|
21510
|
-
|
|
21511
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
|
|
21512
|
-
request.method,
|
|
21513
|
-
request.url,
|
|
21514
|
-
error3.stack ?? error3
|
|
21515
|
-
);
|
|
21516
|
-
event.postMessage("MOCK_RESPONSE", {
|
|
21517
|
-
status: 500,
|
|
21518
|
-
statusText: "Request Handler Error",
|
|
21519
|
-
headers: {
|
|
21520
|
-
"Content-Type": "application/json"
|
|
21521
|
-
},
|
|
21522
|
-
body: JSON.stringify({
|
|
21523
|
-
name: error3.name,
|
|
21524
|
-
message: error3.message,
|
|
21525
|
-
stack: error3.stack
|
|
21526
|
-
})
|
|
21527
|
-
});
|
|
21528
|
-
}
|
|
21529
|
-
}
|
|
21530
|
-
};
|
|
21531
|
-
};
|
|
21532
|
-
|
|
21533
|
-
// src/browser/utils/checkWorkerIntegrity.ts
|
|
21534
|
-
function checkWorkerIntegrity(context) {
|
|
21535
|
-
const integrityCheckPromise = new DeferredPromise();
|
|
21536
|
-
context.workerChannel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
21537
|
-
context.workerChannel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
21538
|
-
const { checksum, packageVersion } = event.data;
|
|
21539
|
-
if (checksum !== "4db4a41e972cec1b64cc569c66952d82") {
|
|
21540
|
-
devUtils.warn(
|
|
21541
|
-
`The currently registered Service Worker has been generated by a different version of MSW (${packageVersion}) and may not be fully compatible with the installed version.
|
|
21542
|
-
|
|
21543
|
-
It's recommended you update your worker script by running this command:
|
|
21544
|
-
|
|
21545
|
-
\u2022 npx msw init <PUBLIC_DIR>
|
|
21546
|
-
|
|
21547
|
-
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
21548
|
-
);
|
|
21549
|
-
}
|
|
21550
|
-
integrityCheckPromise.resolve();
|
|
21551
|
-
});
|
|
21552
|
-
return integrityCheckPromise;
|
|
21553
|
-
}
|
|
21554
|
-
|
|
21555
|
-
// src/browser/setupWorker/start/createResponseListener.ts
|
|
21556
|
-
function createResponseListener(context) {
|
|
21557
|
-
return (event) => {
|
|
21558
|
-
const responseMessage = event.data;
|
|
21559
|
-
const request = deserializeRequest(responseMessage.request);
|
|
21560
|
-
if (responseMessage.response.type?.includes("opaque")) {
|
|
21561
|
-
return;
|
|
21562
|
-
}
|
|
21563
|
-
const response = responseMessage.response.status === 0 ? Response.error() : new FetchResponse(
|
|
21564
|
-
/**
|
|
21565
|
-
* Responses may be streams here, but when we create a response object
|
|
21566
|
-
* with null-body status codes, like 204, 205, 304 Response will
|
|
21567
|
-
* throw when passed a non-null body, so ensure it's null here
|
|
21568
|
-
* for those codes
|
|
21569
|
-
*/
|
|
21570
|
-
FetchResponse.isResponseWithBody(responseMessage.response.status) ? responseMessage.response.body : null,
|
|
21571
|
-
{
|
|
21572
|
-
...responseMessage.response,
|
|
21573
|
-
/**
|
|
21574
|
-
* Set response URL if it's not set already.
|
|
21575
|
-
* @see https://github.com/mswjs/msw/issues/2030
|
|
21576
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
21577
|
-
*/
|
|
21578
|
-
url: request.url
|
|
21579
|
-
}
|
|
21580
|
-
);
|
|
21581
|
-
context.emitter.emit(
|
|
21582
|
-
responseMessage.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
21583
|
-
{
|
|
21584
|
-
requestId: responseMessage.request.id,
|
|
21585
|
-
request,
|
|
21586
|
-
response
|
|
21587
|
-
}
|
|
21588
|
-
);
|
|
21589
|
-
};
|
|
21590
|
-
}
|
|
21591
|
-
|
|
21592
|
-
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
21593
|
-
function validateWorkerScope(registration, options) {
|
|
21594
|
-
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
21595
|
-
devUtils.warn(
|
|
21596
|
-
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
21597
|
-
|
|
21598
|
-
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
21599
|
-
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
21600
|
-
);
|
|
21601
|
-
}
|
|
21602
|
-
}
|
|
21603
|
-
|
|
21604
|
-
// src/browser/setupWorker/start/createStartHandler.ts
|
|
21605
|
-
var createStartHandler = (context) => {
|
|
21606
|
-
return function start(options, customOptions) {
|
|
21607
|
-
const startWorkerInstance = async () => {
|
|
21608
|
-
context.workerChannel.removeAllListeners();
|
|
21609
|
-
context.workerChannel.on(
|
|
21610
|
-
"REQUEST",
|
|
21611
|
-
createRequestListener(context, options)
|
|
21612
|
-
);
|
|
21613
|
-
context.workerChannel.on("RESPONSE", createResponseListener(context));
|
|
21614
|
-
const instance = await getWorkerInstance(
|
|
21615
|
-
options.serviceWorker.url,
|
|
21616
|
-
options.serviceWorker.options,
|
|
21617
|
-
options.findWorker
|
|
21618
|
-
);
|
|
21619
|
-
const [worker, registration] = instance;
|
|
21620
|
-
if (!worker) {
|
|
21621
|
-
const missingWorkerMessage = customOptions?.findWorker ? devUtils.formatMessage(
|
|
21622
|
-
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
21623
|
-
|
|
21624
|
-
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
21625
|
-
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
21626
|
-
`,
|
|
21627
|
-
options.serviceWorker.url
|
|
21628
|
-
) : devUtils.formatMessage(
|
|
21629
|
-
`Failed to locate the Service Worker registration.
|
|
21630
|
-
|
|
21631
|
-
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
21632
|
-
|
|
21633
|
-
Please consider using a custom "serviceWorker.url" option to point to the actual worker script location, or a custom "findWorker" option to resolve the Service Worker registration manually. More details: https://mswjs.io/docs/api/setup-worker/start`,
|
|
21634
|
-
options.serviceWorker.url,
|
|
21635
|
-
location.host
|
|
21636
|
-
);
|
|
21637
|
-
throw new Error(missingWorkerMessage);
|
|
21638
|
-
}
|
|
21639
|
-
context.workerPromise.resolve(worker);
|
|
21640
|
-
context.registration = registration;
|
|
21641
|
-
window.addEventListener("beforeunload", () => {
|
|
21642
|
-
if (worker.state !== "redundant") {
|
|
21643
|
-
context.workerChannel.postMessage("CLIENT_CLOSED");
|
|
21644
|
-
}
|
|
21645
|
-
window.clearInterval(context.keepAliveInterval);
|
|
21646
|
-
window.postMessage({ type: "msw/worker:stop" });
|
|
21647
|
-
});
|
|
21648
|
-
await checkWorkerIntegrity(context).catch((error3) => {
|
|
21649
|
-
devUtils.error(
|
|
21650
|
-
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
21651
|
-
);
|
|
21652
|
-
console.error(error3);
|
|
21653
|
-
});
|
|
21654
|
-
context.keepAliveInterval = window.setInterval(
|
|
21655
|
-
() => context.workerChannel.postMessage("KEEPALIVE_REQUEST"),
|
|
21656
|
-
5e3
|
|
21657
|
-
);
|
|
21658
|
-
validateWorkerScope(registration, context.startOptions);
|
|
21659
|
-
return registration;
|
|
21660
|
-
};
|
|
21661
|
-
const workerRegistration = startWorkerInstance().then(
|
|
21662
|
-
async (registration) => {
|
|
21663
|
-
const pendingInstance = registration.installing || registration.waiting;
|
|
21664
|
-
if (pendingInstance) {
|
|
21665
|
-
const activationPromise = new DeferredPromise();
|
|
21666
|
-
pendingInstance.addEventListener("statechange", () => {
|
|
21667
|
-
if (pendingInstance.state === "activated") {
|
|
21668
|
-
activationPromise.resolve();
|
|
21669
|
-
}
|
|
21670
|
-
});
|
|
21671
|
-
await activationPromise;
|
|
21672
|
-
}
|
|
21673
|
-
await enableMocking(context, options).catch((error3) => {
|
|
21674
|
-
devUtils.error(
|
|
21675
|
-
"Failed to enable mocking. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
21676
|
-
);
|
|
21677
|
-
throw error3;
|
|
21678
|
-
});
|
|
21679
|
-
return registration;
|
|
21680
|
-
}
|
|
21681
|
-
);
|
|
21682
|
-
return workerRegistration;
|
|
21683
|
-
};
|
|
21684
|
-
};
|
|
21685
|
-
|
|
21686
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
21687
|
-
async function emitAsync(emitter, eventName, ...data) {
|
|
21688
|
-
const listeners = emitter.listeners(eventName);
|
|
21689
|
-
if (listeners.length === 0) return;
|
|
21690
|
-
for (const listener of listeners) await listener.apply(emitter, data);
|
|
21691
|
-
}
|
|
21692
|
-
function hasConfigurableGlobal(propertyName) {
|
|
21693
|
-
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
21694
|
-
if (typeof descriptor === "undefined") return false;
|
|
21695
|
-
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
21696
|
-
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
21697
|
-
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
21698
|
-
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
21699
|
-
return false;
|
|
21700
|
-
}
|
|
21701
|
-
return true;
|
|
21702
|
-
}
|
|
21703
|
-
|
|
21704
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
21705
|
-
function bindEvent(target, event) {
|
|
21706
|
-
Object.defineProperties(event, {
|
|
21707
|
-
target: {
|
|
21708
|
-
value: target,
|
|
21709
|
-
enumerable: true,
|
|
21710
|
-
writable: true
|
|
21711
|
-
},
|
|
21712
|
-
currentTarget: {
|
|
21713
|
-
value: target,
|
|
21714
|
-
enumerable: true,
|
|
21715
|
-
writable: true
|
|
21716
|
-
}
|
|
21717
|
-
});
|
|
21718
|
-
return event;
|
|
21627
|
+
return event;
|
|
21719
21628
|
}
|
|
21720
21629
|
var kCancelable = Symbol("kCancelable");
|
|
21721
|
-
var
|
|
21630
|
+
var kDefaultPrevented2 = Symbol("kDefaultPrevented");
|
|
21722
21631
|
var CancelableMessageEvent = class extends MessageEvent {
|
|
21723
21632
|
constructor(type, init) {
|
|
21724
21633
|
super(type, init);
|
|
21725
21634
|
this[kCancelable] = !!init.cancelable;
|
|
21726
|
-
this[
|
|
21635
|
+
this[kDefaultPrevented2] = false;
|
|
21727
21636
|
}
|
|
21728
21637
|
get cancelable() {
|
|
21729
21638
|
return this[kCancelable];
|
|
@@ -21732,13 +21641,13 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21732
21641
|
this[kCancelable] = nextCancelable;
|
|
21733
21642
|
}
|
|
21734
21643
|
get defaultPrevented() {
|
|
21735
|
-
return this[
|
|
21644
|
+
return this[kDefaultPrevented2];
|
|
21736
21645
|
}
|
|
21737
21646
|
set defaultPrevented(nextDefaultPrevented) {
|
|
21738
|
-
this[
|
|
21647
|
+
this[kDefaultPrevented2] = nextDefaultPrevented;
|
|
21739
21648
|
}
|
|
21740
21649
|
preventDefault() {
|
|
21741
|
-
if (this.cancelable && !this[
|
|
21650
|
+
if (this.cancelable && !this[kDefaultPrevented2]) this[kDefaultPrevented2] = true;
|
|
21742
21651
|
}
|
|
21743
21652
|
};
|
|
21744
21653
|
var CloseEvent = class extends Event {
|
|
@@ -21753,7 +21662,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21753
21662
|
constructor(type, init = {}) {
|
|
21754
21663
|
super(type, init);
|
|
21755
21664
|
this[kCancelable] = !!init.cancelable;
|
|
21756
|
-
this[
|
|
21665
|
+
this[kDefaultPrevented2] = false;
|
|
21757
21666
|
}
|
|
21758
21667
|
get cancelable() {
|
|
21759
21668
|
return this[kCancelable];
|
|
@@ -21762,13 +21671,13 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21762
21671
|
this[kCancelable] = nextCancelable;
|
|
21763
21672
|
}
|
|
21764
21673
|
get defaultPrevented() {
|
|
21765
|
-
return this[
|
|
21674
|
+
return this[kDefaultPrevented2];
|
|
21766
21675
|
}
|
|
21767
21676
|
set defaultPrevented(nextDefaultPrevented) {
|
|
21768
|
-
this[
|
|
21677
|
+
this[kDefaultPrevented2] = nextDefaultPrevented;
|
|
21769
21678
|
}
|
|
21770
21679
|
preventDefault() {
|
|
21771
|
-
if (this.cancelable && !this[
|
|
21680
|
+
if (this.cancelable && !this[kDefaultPrevented2]) this[kDefaultPrevented2] = true;
|
|
21772
21681
|
}
|
|
21773
21682
|
};
|
|
21774
21683
|
var kEmitter$1 = Symbol("kEmitter");
|
|
@@ -22204,328 +22113,725 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22204
22113
|
});
|
|
22205
22114
|
this.subscriptions.push(() => {
|
|
22206
22115
|
Object.defineProperty(globalThis, "WebSocket", originalWebSocketDescriptor);
|
|
22207
|
-
});
|
|
22208
|
-
}
|
|
22209
|
-
};
|
|
22210
|
-
|
|
22211
|
-
// src/core/ws/webSocketInterceptor.ts
|
|
22212
|
-
var webSocketInterceptor = new WebSocketInterceptor();
|
|
22213
|
-
|
|
22214
|
-
// src/core/ws/handleWebSocketEvent.ts
|
|
22215
|
-
function handleWebSocketEvent(options) {
|
|
22216
|
-
webSocketInterceptor.on("connection", async (connection) => {
|
|
22217
|
-
const handlers = options.getHandlers().filter(isHandlerKind("EventHandler"));
|
|
22218
|
-
if (handlers.length > 0) {
|
|
22219
|
-
options?.onMockedConnection(connection);
|
|
22220
|
-
await Promise.all(
|
|
22221
|
-
handlers.map((handler) => {
|
|
22222
|
-
return handler.run(connection);
|
|
22223
|
-
})
|
|
22224
|
-
);
|
|
22225
|
-
return;
|
|
22226
|
-
}
|
|
22227
|
-
const request = new Request(connection.client.url, {
|
|
22228
|
-
headers: {
|
|
22229
|
-
upgrade: "websocket",
|
|
22230
|
-
connection: "upgrade"
|
|
22231
|
-
}
|
|
22232
|
-
});
|
|
22233
|
-
await onUnhandledRequest(
|
|
22234
|
-
request,
|
|
22235
|
-
options.getUnhandledRequestStrategy()
|
|
22236
|
-
).catch((error3) => {
|
|
22237
|
-
const errorEvent = new Event("error");
|
|
22238
|
-
Object.defineProperty(errorEvent, "cause", {
|
|
22239
|
-
enumerable: true,
|
|
22240
|
-
configurable: false,
|
|
22241
|
-
value: error3
|
|
22242
|
-
});
|
|
22243
|
-
connection.client.socket.dispatchEvent(errorEvent);
|
|
22244
|
-
});
|
|
22245
|
-
options?.onPassthroughConnection(connection);
|
|
22246
|
-
connection.server.connect();
|
|
22247
|
-
});
|
|
22248
|
-
}
|
|
22249
|
-
|
|
22250
|
-
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
|
|
22251
|
-
var LensList = class {
|
|
22252
|
-
#list;
|
|
22253
|
-
#lens;
|
|
22254
|
-
constructor() {
|
|
22255
|
-
this.#list = [];
|
|
22256
|
-
this.#lens = /* @__PURE__ */ new Map();
|
|
22257
|
-
}
|
|
22258
|
-
get [Symbol.iterator]() {
|
|
22259
|
-
return this.#list[Symbol.iterator].bind(this.#list);
|
|
22260
|
-
}
|
|
22261
|
-
entries() {
|
|
22262
|
-
return this.#lens.entries();
|
|
22263
|
-
}
|
|
22264
|
-
/**
|
|
22265
|
-
* Return an order-sensitive list of values by the given key.
|
|
22266
|
-
*/
|
|
22267
|
-
get(key) {
|
|
22268
|
-
return this.#lens.get(key) || [];
|
|
22116
|
+
});
|
|
22269
22117
|
}
|
|
22270
|
-
|
|
22271
|
-
|
|
22272
|
-
|
|
22273
|
-
|
|
22274
|
-
|
|
22118
|
+
};
|
|
22119
|
+
|
|
22120
|
+
// src/core/experimental/define-network.ts
|
|
22121
|
+
function colorlessPromiseAll(values) {
|
|
22122
|
+
const promises = [];
|
|
22123
|
+
for (const value of values) {
|
|
22124
|
+
if (value instanceof Promise) {
|
|
22125
|
+
promises.push(value);
|
|
22126
|
+
}
|
|
22275
22127
|
}
|
|
22276
|
-
|
|
22277
|
-
|
|
22278
|
-
|
|
22279
|
-
append(key, value) {
|
|
22280
|
-
this.#list.push([key, value]);
|
|
22281
|
-
this.#openLens(key, (list) => list.push(value));
|
|
22128
|
+
if (promises.length > 0) {
|
|
22129
|
+
return Promise.all(promises).then(() => {
|
|
22130
|
+
});
|
|
22282
22131
|
}
|
|
22283
|
-
|
|
22284
|
-
|
|
22285
|
-
|
|
22286
|
-
|
|
22287
|
-
|
|
22288
|
-
|
|
22132
|
+
}
|
|
22133
|
+
function defineNetwork(options) {
|
|
22134
|
+
let readyState = 0 /* DISABLED */;
|
|
22135
|
+
const events = new Emitter();
|
|
22136
|
+
const deriveHandlersController = (handlers) => {
|
|
22137
|
+
return handlers instanceof HandlersController ? handlers : new InMemoryHandlersController(handlers || []);
|
|
22138
|
+
};
|
|
22139
|
+
let resolvedOptions = {
|
|
22140
|
+
...options
|
|
22141
|
+
};
|
|
22142
|
+
let handlersController = deriveHandlersController(resolvedOptions.handlers);
|
|
22143
|
+
let listenersController;
|
|
22144
|
+
return {
|
|
22145
|
+
get readyState() {
|
|
22146
|
+
return readyState;
|
|
22147
|
+
},
|
|
22148
|
+
events,
|
|
22149
|
+
configure(options2) {
|
|
22150
|
+
invariant(readyState === 0 /* DISABLED */, "");
|
|
22151
|
+
if (options2.handlers && !Object.is(options2.handlers, resolvedOptions.handlers)) {
|
|
22152
|
+
handlersController = deriveHandlersController(options2.handlers);
|
|
22153
|
+
}
|
|
22154
|
+
resolvedOptions = {
|
|
22155
|
+
...resolvedOptions,
|
|
22156
|
+
...options2
|
|
22157
|
+
};
|
|
22158
|
+
},
|
|
22159
|
+
enable() {
|
|
22160
|
+
invariant(
|
|
22161
|
+
readyState === 0 /* DISABLED */,
|
|
22162
|
+
'Failed to call "enable" on the network: already enabled'
|
|
22163
|
+
);
|
|
22164
|
+
listenersController = new AbortController();
|
|
22165
|
+
readyState = 1 /* ENABLED */;
|
|
22166
|
+
const result = resolvedOptions.sources.map((source) => {
|
|
22167
|
+
source.on("frame", async ({ frame }) => {
|
|
22168
|
+
frame.events.on("*", (event) => events.emit(event), {
|
|
22169
|
+
signal: listenersController.signal
|
|
22170
|
+
});
|
|
22171
|
+
const handlers = frame.getHandlers(handlersController);
|
|
22172
|
+
await frame.resolve(
|
|
22173
|
+
handlers,
|
|
22174
|
+
resolvedOptions.onUnhandledFrame || "warn",
|
|
22175
|
+
resolvedOptions.context
|
|
22176
|
+
);
|
|
22177
|
+
});
|
|
22178
|
+
return source.enable();
|
|
22179
|
+
});
|
|
22180
|
+
return colorlessPromiseAll(result);
|
|
22181
|
+
},
|
|
22182
|
+
disable() {
|
|
22183
|
+
invariant(
|
|
22184
|
+
readyState === 1 /* ENABLED */,
|
|
22185
|
+
'Failed to call "disable" on the network: already disabled'
|
|
22186
|
+
);
|
|
22187
|
+
listenersController.abort();
|
|
22188
|
+
readyState = 0 /* DISABLED */;
|
|
22189
|
+
return colorlessPromiseAll(
|
|
22190
|
+
resolvedOptions.sources.map((source) => source.disable())
|
|
22191
|
+
);
|
|
22192
|
+
},
|
|
22193
|
+
use(...handlers) {
|
|
22194
|
+
handlersController.use(handlers);
|
|
22195
|
+
},
|
|
22196
|
+
resetHandlers(...handlers) {
|
|
22197
|
+
handlersController.reset(handlers);
|
|
22198
|
+
},
|
|
22199
|
+
restoreHandlers() {
|
|
22200
|
+
for (const handler of handlersController.currentHandlers()) {
|
|
22201
|
+
if ("isUsed" in handler) {
|
|
22202
|
+
handler.isUsed = false;
|
|
22203
|
+
}
|
|
22204
|
+
}
|
|
22205
|
+
},
|
|
22206
|
+
listHandlers() {
|
|
22207
|
+
return toReadonlyArray(handlersController.currentHandlers());
|
|
22208
|
+
}
|
|
22209
|
+
};
|
|
22210
|
+
}
|
|
22211
|
+
|
|
22212
|
+
// src/core/experimental/sources/network-source.ts
|
|
22213
|
+
var NetworkFrameEvent = class extends TypedEvent {
|
|
22214
|
+
frame;
|
|
22215
|
+
constructor(type, frame) {
|
|
22216
|
+
super(...[type, {}]);
|
|
22217
|
+
this.frame = frame;
|
|
22289
22218
|
}
|
|
22290
|
-
|
|
22291
|
-
|
|
22292
|
-
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
22296
|
-
for (const [existingKey, values] of this.#lens) if (existingKey === key && values.includes(value)) values.splice(values.indexOf(value), 1);
|
|
22219
|
+
};
|
|
22220
|
+
var NetworkSource = class {
|
|
22221
|
+
emitter;
|
|
22222
|
+
constructor() {
|
|
22223
|
+
this.emitter = new Emitter();
|
|
22297
22224
|
}
|
|
22298
|
-
|
|
22299
|
-
|
|
22300
|
-
|
|
22301
|
-
|
|
22302
|
-
|
|
22303
|
-
this.#list = this.#list.filter((item) => item[0] !== key);
|
|
22304
|
-
this.#lens.delete(key);
|
|
22225
|
+
async queue(frame) {
|
|
22226
|
+
await this.emitter.emitAsPromise(
|
|
22227
|
+
// @ts-expect-error Trouble handling a conditional type parameter.
|
|
22228
|
+
new NetworkFrameEvent("frame", frame)
|
|
22229
|
+
);
|
|
22305
22230
|
}
|
|
22306
|
-
|
|
22307
|
-
|
|
22231
|
+
on(type, listener, options) {
|
|
22232
|
+
this.emitter.on(type, listener, options);
|
|
22308
22233
|
}
|
|
22309
|
-
|
|
22310
|
-
|
|
22311
|
-
this.#list.length = 0;
|
|
22312
|
-
this.#lens.clear();
|
|
22234
|
+
disable() {
|
|
22235
|
+
this.emitter.removeAllListeners();
|
|
22313
22236
|
}
|
|
22314
|
-
|
|
22315
|
-
|
|
22237
|
+
};
|
|
22238
|
+
|
|
22239
|
+
// src/core/experimental/frames/network-frame.ts
|
|
22240
|
+
var NetworkFrame = class {
|
|
22241
|
+
constructor(protocol, data) {
|
|
22242
|
+
this.protocol = protocol;
|
|
22243
|
+
this.data = data;
|
|
22244
|
+
this.events = new Emitter();
|
|
22316
22245
|
}
|
|
22246
|
+
events;
|
|
22317
22247
|
};
|
|
22318
22248
|
|
|
22319
|
-
//
|
|
22320
|
-
var
|
|
22321
|
-
|
|
22322
|
-
|
|
22323
|
-
|
|
22324
|
-
|
|
22325
|
-
|
|
22326
|
-
|
|
22327
|
-
|
|
22328
|
-
|
|
22329
|
-
|
|
22330
|
-
|
|
22331
|
-
|
|
22332
|
-
|
|
22333
|
-
|
|
22334
|
-
|
|
22335
|
-
|
|
22249
|
+
// src/core/experimental/request-utils.ts
|
|
22250
|
+
var REQUEST_INTENTION_HEADER_NAME = "x-msw-intention";
|
|
22251
|
+
function shouldBypassRequest(request) {
|
|
22252
|
+
return !!request.headers.get("accept")?.includes("msw/passthrough");
|
|
22253
|
+
}
|
|
22254
|
+
function isPassthroughResponse(response) {
|
|
22255
|
+
return response.status === 302 && response.headers.get(REQUEST_INTENTION_HEADER_NAME) === "passthrough" /* passthrough */;
|
|
22256
|
+
}
|
|
22257
|
+
function deleteRequestPassthroughHeader(request) {
|
|
22258
|
+
const acceptHeader = request.headers.get("accept");
|
|
22259
|
+
if (acceptHeader) {
|
|
22260
|
+
const nextAcceptHeader = acceptHeader.replace(/(,\s+)?msw\/passthrough/, "");
|
|
22261
|
+
if (nextAcceptHeader) {
|
|
22262
|
+
request.headers.set("accept", nextAcceptHeader);
|
|
22263
|
+
} else {
|
|
22264
|
+
request.headers.delete("accept");
|
|
22265
|
+
}
|
|
22336
22266
|
}
|
|
22337
|
-
|
|
22338
|
-
|
|
22267
|
+
}
|
|
22268
|
+
|
|
22269
|
+
// src/core/experimental/on-unhandled-frame.ts
|
|
22270
|
+
async function executeUnhandledFrameHandle(frame, handle) {
|
|
22271
|
+
const printStrategyMessage = async (strategy) => {
|
|
22272
|
+
if (strategy === "bypass") {
|
|
22273
|
+
return;
|
|
22274
|
+
}
|
|
22275
|
+
const message4 = await frame.getUnhandledMessage();
|
|
22276
|
+
switch (strategy) {
|
|
22277
|
+
case "warn": {
|
|
22278
|
+
return devUtils.warn("Warning: %s", message4);
|
|
22279
|
+
}
|
|
22280
|
+
case "error": {
|
|
22281
|
+
return devUtils.error("Error: %s", message4);
|
|
22282
|
+
}
|
|
22283
|
+
}
|
|
22284
|
+
};
|
|
22285
|
+
const applyStrategy = async (strategy) => {
|
|
22286
|
+
invariant.as(
|
|
22287
|
+
InternalError,
|
|
22288
|
+
strategy === "bypass" || strategy === "warn" || strategy === "error",
|
|
22289
|
+
/**
|
|
22290
|
+
* @fixme Rename "onUnhandledRequest" to "onUnhandledFrame" in the error message
|
|
22291
|
+
* with the next major release.
|
|
22292
|
+
*/
|
|
22293
|
+
devUtils.formatMessage(
|
|
22294
|
+
'Failed to react to an unhandled network frame: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
22295
|
+
strategy
|
|
22296
|
+
)
|
|
22297
|
+
);
|
|
22298
|
+
if (strategy === "bypass") {
|
|
22299
|
+
return;
|
|
22300
|
+
}
|
|
22301
|
+
await printStrategyMessage(strategy);
|
|
22302
|
+
if (strategy === "error") {
|
|
22303
|
+
return Promise.reject(
|
|
22304
|
+
new InternalError(
|
|
22305
|
+
devUtils.formatMessage(
|
|
22306
|
+
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
22307
|
+
)
|
|
22308
|
+
)
|
|
22309
|
+
);
|
|
22310
|
+
}
|
|
22311
|
+
};
|
|
22312
|
+
if (typeof handle === "function") {
|
|
22313
|
+
return handle({
|
|
22314
|
+
frame,
|
|
22315
|
+
defaults: {
|
|
22316
|
+
warn: printStrategyMessage.bind(null, "warn"),
|
|
22317
|
+
/**
|
|
22318
|
+
* @note The defaults only print the corresponding messages now.
|
|
22319
|
+
* They do not affect the frame resolution (e.g. do not error the frame).
|
|
22320
|
+
* That is only for backward compatibility reasons. In the future, these should
|
|
22321
|
+
* be an alias to `applyStrategy.bind(null, 'error')` instead.
|
|
22322
|
+
*/
|
|
22323
|
+
error: printStrategyMessage.bind(null, "error")
|
|
22324
|
+
}
|
|
22325
|
+
});
|
|
22339
22326
|
}
|
|
22340
|
-
|
|
22341
|
-
|
|
22342
|
-
this[kDefaultPrevented2] = true;
|
|
22327
|
+
if (frame instanceof HttpNetworkFrame && isCommonAssetRequest(frame.data.request)) {
|
|
22328
|
+
return;
|
|
22343
22329
|
}
|
|
22344
|
-
|
|
22345
|
-
|
|
22346
|
-
|
|
22330
|
+
return applyStrategy(handle);
|
|
22331
|
+
}
|
|
22332
|
+
|
|
22333
|
+
// src/core/experimental/frames/http-frame.ts
|
|
22334
|
+
var RequestEvent = class extends TypedEvent {
|
|
22335
|
+
requestId;
|
|
22336
|
+
request;
|
|
22337
|
+
constructor(type, data) {
|
|
22338
|
+
super(...[type, {}]);
|
|
22339
|
+
this.requestId = data.requestId;
|
|
22340
|
+
this.request = data.request;
|
|
22347
22341
|
}
|
|
22348
22342
|
};
|
|
22349
|
-
var
|
|
22350
|
-
|
|
22351
|
-
|
|
22352
|
-
|
|
22353
|
-
|
|
22343
|
+
var ResponseEvent = class extends TypedEvent {
|
|
22344
|
+
requestId;
|
|
22345
|
+
request;
|
|
22346
|
+
response;
|
|
22347
|
+
constructor(type, data) {
|
|
22348
|
+
super(...[type, {}]);
|
|
22349
|
+
this.requestId = data.requestId;
|
|
22350
|
+
this.request = data.request;
|
|
22351
|
+
this.response = data.response;
|
|
22354
22352
|
}
|
|
22355
|
-
|
|
22356
|
-
|
|
22357
|
-
|
|
22358
|
-
|
|
22359
|
-
|
|
22360
|
-
|
|
22353
|
+
};
|
|
22354
|
+
var UnhandledExceptionEvent = class extends TypedEvent {
|
|
22355
|
+
error;
|
|
22356
|
+
requestId;
|
|
22357
|
+
request;
|
|
22358
|
+
constructor(type, data) {
|
|
22359
|
+
super(...[type, {}]);
|
|
22360
|
+
this.error = data.error;
|
|
22361
|
+
this.requestId = data.requestId;
|
|
22362
|
+
this.request = data.request;
|
|
22361
22363
|
}
|
|
22362
|
-
|
|
22363
|
-
|
|
22364
|
-
|
|
22365
|
-
|
|
22366
|
-
|
|
22367
|
-
...options || {},
|
|
22368
|
-
once: true
|
|
22369
|
-
});
|
|
22364
|
+
};
|
|
22365
|
+
var HttpNetworkFrame = class extends NetworkFrame {
|
|
22366
|
+
constructor(options) {
|
|
22367
|
+
const id = options.id || createRequestId();
|
|
22368
|
+
super("http", { id, request: options.request });
|
|
22370
22369
|
}
|
|
22371
|
-
|
|
22372
|
-
|
|
22373
|
-
*/
|
|
22374
|
-
earlyOn(type, listener, options) {
|
|
22375
|
-
this.#addListener(type, listener, options, "prepend");
|
|
22376
|
-
return this;
|
|
22370
|
+
getHandlers(controller) {
|
|
22371
|
+
return controller.getHandlersByKind("request");
|
|
22377
22372
|
}
|
|
22378
|
-
|
|
22379
|
-
|
|
22380
|
-
|
|
22381
|
-
|
|
22382
|
-
|
|
22383
|
-
|
|
22384
|
-
|
|
22385
|
-
|
|
22373
|
+
async getUnhandledMessage() {
|
|
22374
|
+
const { request } = this.data;
|
|
22375
|
+
const url = new URL(request.url);
|
|
22376
|
+
const publicUrl = toPublicUrl(url) + url.search;
|
|
22377
|
+
const requestBody = request.body == null ? null : await request.clone().text();
|
|
22378
|
+
const details = `
|
|
22379
|
+
|
|
22380
|
+
\u2022 ${request.method} ${publicUrl}
|
|
22381
|
+
|
|
22382
|
+
${requestBody ? ` \u2022 Request body: ${requestBody}
|
|
22383
|
+
|
|
22384
|
+
` : ""}`;
|
|
22385
|
+
const message4 = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
22386
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`;
|
|
22387
|
+
return message4;
|
|
22386
22388
|
}
|
|
22387
|
-
|
|
22388
|
-
|
|
22389
|
-
|
|
22390
|
-
|
|
22391
|
-
|
|
22392
|
-
|
|
22393
|
-
|
|
22394
|
-
|
|
22395
|
-
const proxiedEvent = this.#proxyEvent(event);
|
|
22396
|
-
for (const listener of this.#matchListeners(event.type)) {
|
|
22397
|
-
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
22398
|
-
proxiedEvent.revoke();
|
|
22399
|
-
return false;
|
|
22400
|
-
}
|
|
22401
|
-
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
22402
|
-
this.#callListener(proxiedEvent.event, listener);
|
|
22389
|
+
async resolve(handlers, onUnhandledFrame, resolutionContext) {
|
|
22390
|
+
const { id: requestId, request } = this.data;
|
|
22391
|
+
const requestCloneForLogs = resolutionContext?.quiet ? null : request.clone();
|
|
22392
|
+
this.events.emit(new RequestEvent("request:start", { requestId, request }));
|
|
22393
|
+
if (shouldBypassRequest(request)) {
|
|
22394
|
+
this.events.emit(new RequestEvent("request:end", { requestId, request }));
|
|
22395
|
+
this.passthrough();
|
|
22396
|
+
return null;
|
|
22403
22397
|
}
|
|
22404
|
-
|
|
22405
|
-
|
|
22406
|
-
|
|
22407
|
-
|
|
22408
|
-
|
|
22409
|
-
|
|
22410
|
-
|
|
22411
|
-
|
|
22412
|
-
|
|
22413
|
-
|
|
22414
|
-
|
|
22415
|
-
if (
|
|
22416
|
-
|
|
22417
|
-
|
|
22418
|
-
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22398
|
+
const [lookupError, lookupResult] = await until(() => {
|
|
22399
|
+
return executeHandlers({
|
|
22400
|
+
requestId,
|
|
22401
|
+
request,
|
|
22402
|
+
handlers,
|
|
22403
|
+
resolutionContext: {
|
|
22404
|
+
baseUrl: resolutionContext?.baseUrl?.toString(),
|
|
22405
|
+
quiet: resolutionContext?.quiet
|
|
22406
|
+
}
|
|
22407
|
+
});
|
|
22408
|
+
});
|
|
22409
|
+
if (lookupError != null) {
|
|
22410
|
+
if (!this.events.emit(
|
|
22411
|
+
new UnhandledExceptionEvent("unhandledException", {
|
|
22412
|
+
error: lookupError,
|
|
22413
|
+
requestId,
|
|
22414
|
+
request
|
|
22415
|
+
})
|
|
22416
|
+
)) {
|
|
22417
|
+
console.error(lookupError);
|
|
22418
|
+
devUtils.error(
|
|
22419
|
+
'Encountered an unhandled exception during the handler lookup for "%s %s". Please see the original error above.',
|
|
22420
|
+
request.method,
|
|
22421
|
+
request.url
|
|
22422
|
+
);
|
|
22422
22423
|
}
|
|
22423
|
-
|
|
22424
|
-
|
|
22425
|
-
|
|
22424
|
+
this.errorWith(lookupError);
|
|
22425
|
+
return null;
|
|
22426
|
+
}
|
|
22427
|
+
if (lookupResult == null) {
|
|
22428
|
+
this.events.emit(
|
|
22429
|
+
new RequestEvent("request:unhandled", {
|
|
22430
|
+
requestId,
|
|
22431
|
+
request
|
|
22432
|
+
})
|
|
22433
|
+
);
|
|
22434
|
+
await executeUnhandledFrameHandle(this, onUnhandledFrame).then(
|
|
22435
|
+
() => this.passthrough(),
|
|
22436
|
+
(error3) => this.errorWith(error3)
|
|
22437
|
+
);
|
|
22438
|
+
this.events.emit(
|
|
22439
|
+
new RequestEvent("request:end", {
|
|
22440
|
+
requestId,
|
|
22441
|
+
request
|
|
22442
|
+
})
|
|
22443
|
+
);
|
|
22444
|
+
return false;
|
|
22445
|
+
}
|
|
22446
|
+
const { response, handler, parsedResult } = lookupResult;
|
|
22447
|
+
this.events.emit(
|
|
22448
|
+
new RequestEvent("request:match", {
|
|
22449
|
+
requestId,
|
|
22450
|
+
request
|
|
22451
|
+
})
|
|
22452
|
+
);
|
|
22453
|
+
if (response == null) {
|
|
22454
|
+
this.events.emit(
|
|
22455
|
+
new RequestEvent("request:end", {
|
|
22456
|
+
requestId,
|
|
22457
|
+
request
|
|
22458
|
+
})
|
|
22459
|
+
);
|
|
22460
|
+
this.passthrough();
|
|
22461
|
+
return null;
|
|
22462
|
+
}
|
|
22463
|
+
if (isPassthroughResponse(response)) {
|
|
22464
|
+
this.events.emit(
|
|
22465
|
+
new RequestEvent("request:end", {
|
|
22466
|
+
requestId,
|
|
22467
|
+
request
|
|
22468
|
+
})
|
|
22469
|
+
);
|
|
22470
|
+
this.passthrough();
|
|
22471
|
+
return null;
|
|
22472
|
+
}
|
|
22473
|
+
await storeResponseCookies(request, response);
|
|
22474
|
+
this.respondWith(response.clone());
|
|
22475
|
+
this.events.emit(
|
|
22476
|
+
new RequestEvent("request:end", {
|
|
22477
|
+
requestId,
|
|
22478
|
+
request
|
|
22479
|
+
})
|
|
22480
|
+
);
|
|
22481
|
+
if (!resolutionContext?.quiet) {
|
|
22482
|
+
handler.log({
|
|
22483
|
+
request: requestCloneForLogs,
|
|
22484
|
+
response,
|
|
22485
|
+
parsedResult
|
|
22486
|
+
});
|
|
22426
22487
|
}
|
|
22427
|
-
|
|
22428
|
-
|
|
22429
|
-
|
|
22488
|
+
return true;
|
|
22489
|
+
}
|
|
22490
|
+
};
|
|
22491
|
+
|
|
22492
|
+
// src/core/experimental/frames/websocket-frame.ts
|
|
22493
|
+
var WebSocketConnectionEvent = class extends TypedEvent {
|
|
22494
|
+
url;
|
|
22495
|
+
protocols;
|
|
22496
|
+
constructor(type, data) {
|
|
22497
|
+
super(...[type, {}]);
|
|
22498
|
+
this.url = data.url;
|
|
22499
|
+
this.protocols = data.protocols;
|
|
22500
|
+
}
|
|
22501
|
+
};
|
|
22502
|
+
var UnhandledWebSocketExceptionEvent = class extends TypedEvent {
|
|
22503
|
+
url;
|
|
22504
|
+
protocols;
|
|
22505
|
+
error;
|
|
22506
|
+
constructor(type, data) {
|
|
22507
|
+
super(...[type, {}]);
|
|
22508
|
+
this.url = data.url;
|
|
22509
|
+
this.protocols = data.protocols;
|
|
22510
|
+
this.error = data.error;
|
|
22511
|
+
}
|
|
22512
|
+
};
|
|
22513
|
+
var WebSocketNetworkFrame = class extends NetworkFrame {
|
|
22514
|
+
constructor(options) {
|
|
22515
|
+
super("ws", {
|
|
22516
|
+
connection: options.connection
|
|
22430
22517
|
});
|
|
22431
22518
|
}
|
|
22432
|
-
|
|
22433
|
-
|
|
22434
|
-
|
|
22435
|
-
|
|
22436
|
-
|
|
22437
|
-
|
|
22438
|
-
|
|
22439
|
-
|
|
22440
|
-
|
|
22441
|
-
|
|
22442
|
-
|
|
22443
|
-
|
|
22519
|
+
getHandlers(controller) {
|
|
22520
|
+
return controller.getHandlersByKind("websocket");
|
|
22521
|
+
}
|
|
22522
|
+
async resolve(handlers, onUnhandledFrame, resolutionContext) {
|
|
22523
|
+
const { connection } = this.data;
|
|
22524
|
+
this.events.emit(
|
|
22525
|
+
new WebSocketConnectionEvent("connection", {
|
|
22526
|
+
url: connection.client.url,
|
|
22527
|
+
protocols: connection.info.protocols
|
|
22528
|
+
})
|
|
22529
|
+
);
|
|
22530
|
+
if (handlers.length === 0) {
|
|
22531
|
+
await executeUnhandledFrameHandle(this, onUnhandledFrame).then(
|
|
22532
|
+
() => this.passthrough(),
|
|
22533
|
+
(error3) => this.errorWith(error3)
|
|
22534
|
+
);
|
|
22535
|
+
return false;
|
|
22536
|
+
}
|
|
22537
|
+
let hasMatchingHandlers = false;
|
|
22538
|
+
for (const handler of handlers) {
|
|
22539
|
+
const handlerConnection = await handler.run(connection, {
|
|
22540
|
+
baseUrl: resolutionContext?.baseUrl?.toString(),
|
|
22541
|
+
/**
|
|
22542
|
+
* @note Do not emit the "connection" event when running the handler.
|
|
22543
|
+
* Use the run only to get the resolved connection object.
|
|
22544
|
+
*/
|
|
22545
|
+
[kAutoConnect]: false
|
|
22546
|
+
});
|
|
22547
|
+
if (!handlerConnection) {
|
|
22548
|
+
continue;
|
|
22549
|
+
}
|
|
22550
|
+
hasMatchingHandlers = true;
|
|
22551
|
+
const removeLogger = !resolutionContext?.quiet ? handler.log(connection) : void 0;
|
|
22552
|
+
try {
|
|
22553
|
+
if (!handler[kConnect](handlerConnection)) {
|
|
22554
|
+
removeLogger?.();
|
|
22555
|
+
}
|
|
22556
|
+
} catch (error3) {
|
|
22557
|
+
if (!this.events.emit(
|
|
22558
|
+
new UnhandledWebSocketExceptionEvent("unhandledException", {
|
|
22559
|
+
error: error3,
|
|
22560
|
+
url: connection.client.url,
|
|
22561
|
+
protocols: connection.info.protocols
|
|
22562
|
+
})
|
|
22563
|
+
)) {
|
|
22564
|
+
console.error(error3);
|
|
22565
|
+
devUtils.error(
|
|
22566
|
+
'Encountered an unhandled exception during the handler lookup for "%s". Please see the original error above.',
|
|
22567
|
+
connection.client.url
|
|
22568
|
+
);
|
|
22569
|
+
}
|
|
22570
|
+
throw error3;
|
|
22444
22571
|
}
|
|
22445
|
-
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
22446
|
-
const returnValue = this.#callListener(proxiedEvent.event, listener);
|
|
22447
|
-
if (!this.#isTypelessListener(listener)) yield returnValue;
|
|
22448
22572
|
}
|
|
22449
|
-
|
|
22573
|
+
if (!hasMatchingHandlers) {
|
|
22574
|
+
await executeUnhandledFrameHandle(this, onUnhandledFrame).then(
|
|
22575
|
+
() => this.passthrough(),
|
|
22576
|
+
(error3) => this.errorWith(error3)
|
|
22577
|
+
);
|
|
22578
|
+
return false;
|
|
22579
|
+
}
|
|
22580
|
+
return true;
|
|
22450
22581
|
}
|
|
22451
|
-
|
|
22452
|
-
|
|
22453
|
-
|
|
22454
|
-
|
|
22455
|
-
|
|
22582
|
+
async getUnhandledMessage() {
|
|
22583
|
+
const { connection } = this.data;
|
|
22584
|
+
const details = `
|
|
22585
|
+
|
|
22586
|
+
\u2022 ${connection.client.url}
|
|
22587
|
+
|
|
22588
|
+
`;
|
|
22589
|
+
return `intercepted a WebSocket connection without a matching event handler:${details}If you still wish to intercept this unhandled connection, please create an event handler for it.
|
|
22590
|
+
Read more: https://mswjs.io/docs/websocket`;
|
|
22456
22591
|
}
|
|
22457
|
-
|
|
22458
|
-
|
|
22459
|
-
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22592
|
+
};
|
|
22593
|
+
|
|
22594
|
+
// src/core/experimental/sources/interceptor-source.ts
|
|
22595
|
+
var InterceptorSource = class extends NetworkSource {
|
|
22596
|
+
#interceptor;
|
|
22597
|
+
#frames;
|
|
22598
|
+
constructor(options) {
|
|
22599
|
+
super();
|
|
22600
|
+
this.#interceptor = new BatchInterceptor({
|
|
22601
|
+
name: "interceptor-source",
|
|
22602
|
+
interceptors: options.interceptors
|
|
22603
|
+
});
|
|
22604
|
+
this.#frames = /* @__PURE__ */ new Map();
|
|
22605
|
+
}
|
|
22606
|
+
enable() {
|
|
22607
|
+
this.#interceptor.apply();
|
|
22608
|
+
this.#interceptor.on("request", this.#handleRequest.bind(this)).on("response", this.#handleResponse.bind(this)).on("connection", this.#handleWebSocketConnection.bind(this));
|
|
22609
|
+
}
|
|
22610
|
+
disable() {
|
|
22611
|
+
super.disable();
|
|
22612
|
+
this.#interceptor.dispose();
|
|
22613
|
+
this.#frames.clear();
|
|
22614
|
+
}
|
|
22615
|
+
async #handleRequest({
|
|
22616
|
+
requestId,
|
|
22617
|
+
request,
|
|
22618
|
+
controller
|
|
22619
|
+
}) {
|
|
22620
|
+
const httpFrame = new InterceptorHttpNetworkFrame({
|
|
22621
|
+
id: requestId,
|
|
22622
|
+
request,
|
|
22623
|
+
controller
|
|
22624
|
+
});
|
|
22625
|
+
this.#frames.set(requestId, httpFrame);
|
|
22626
|
+
await this.queue(httpFrame);
|
|
22627
|
+
}
|
|
22628
|
+
async #handleResponse({
|
|
22629
|
+
requestId,
|
|
22630
|
+
request,
|
|
22631
|
+
response,
|
|
22632
|
+
isMockedResponse
|
|
22633
|
+
}) {
|
|
22634
|
+
const httpFrame = this.#frames.get(requestId);
|
|
22635
|
+
this.#frames.delete(requestId);
|
|
22636
|
+
if (httpFrame == null) {
|
|
22464
22637
|
return;
|
|
22465
22638
|
}
|
|
22466
|
-
|
|
22639
|
+
queueMicrotask(() => {
|
|
22640
|
+
httpFrame.events.emit(
|
|
22641
|
+
new ResponseEvent(
|
|
22642
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
22643
|
+
{
|
|
22644
|
+
requestId,
|
|
22645
|
+
request,
|
|
22646
|
+
response
|
|
22647
|
+
}
|
|
22648
|
+
)
|
|
22649
|
+
);
|
|
22650
|
+
});
|
|
22467
22651
|
}
|
|
22468
|
-
|
|
22469
|
-
|
|
22470
|
-
|
|
22471
|
-
|
|
22472
|
-
|
|
22473
|
-
|
|
22474
|
-
return this.#listeners.get(type);
|
|
22652
|
+
async #handleWebSocketConnection(connection) {
|
|
22653
|
+
await this.queue(
|
|
22654
|
+
new InterceptorWebSocketNetworkFrame({
|
|
22655
|
+
connection
|
|
22656
|
+
})
|
|
22657
|
+
);
|
|
22475
22658
|
}
|
|
22476
|
-
|
|
22477
|
-
|
|
22478
|
-
|
|
22479
|
-
|
|
22480
|
-
|
|
22481
|
-
|
|
22482
|
-
|
|
22659
|
+
};
|
|
22660
|
+
var InterceptorHttpNetworkFrame = class extends HttpNetworkFrame {
|
|
22661
|
+
#controller;
|
|
22662
|
+
constructor(options) {
|
|
22663
|
+
super({
|
|
22664
|
+
id: options.id,
|
|
22665
|
+
request: options.request
|
|
22666
|
+
});
|
|
22667
|
+
this.#controller = options.controller;
|
|
22483
22668
|
}
|
|
22484
|
-
|
|
22485
|
-
|
|
22486
|
-
|
|
22487
|
-
|
|
22488
|
-
|
|
22489
|
-
|
|
22490
|
-
|
|
22491
|
-
|
|
22669
|
+
passthrough() {
|
|
22670
|
+
deleteRequestPassthroughHeader(this.data.request);
|
|
22671
|
+
}
|
|
22672
|
+
respondWith(response) {
|
|
22673
|
+
if (response) {
|
|
22674
|
+
this.#controller.respondWith(response);
|
|
22675
|
+
}
|
|
22676
|
+
}
|
|
22677
|
+
errorWith(reason) {
|
|
22678
|
+
if (reason instanceof Response) {
|
|
22679
|
+
return this.respondWith(reason);
|
|
22680
|
+
}
|
|
22681
|
+
if (reason instanceof InternalError) {
|
|
22682
|
+
this.#controller.errorWith(reason);
|
|
22683
|
+
}
|
|
22684
|
+
throw reason;
|
|
22685
|
+
}
|
|
22686
|
+
};
|
|
22687
|
+
var InterceptorWebSocketNetworkFrame = class extends WebSocketNetworkFrame {
|
|
22688
|
+
constructor(args) {
|
|
22689
|
+
super({ connection: args.connection });
|
|
22690
|
+
}
|
|
22691
|
+
errorWith(reason) {
|
|
22692
|
+
if (reason instanceof Error) {
|
|
22693
|
+
const { client } = this.data.connection;
|
|
22694
|
+
const errorEvent = new Event("error");
|
|
22695
|
+
Object.defineProperty(errorEvent, "cause", {
|
|
22696
|
+
enumerable: true,
|
|
22697
|
+
configurable: false,
|
|
22698
|
+
value: reason
|
|
22492
22699
|
});
|
|
22493
|
-
|
|
22494
|
-
this.removeListener(type, listener);
|
|
22495
|
-
}, { once: true });
|
|
22700
|
+
client.socket.dispatchEvent(errorEvent);
|
|
22496
22701
|
}
|
|
22497
22702
|
}
|
|
22498
|
-
|
|
22499
|
-
|
|
22500
|
-
event.stopPropagation = new Proxy(event.stopPropagation, { apply: (target, thisArg, argArray) => {
|
|
22501
|
-
event[kPropagationStopped] = this;
|
|
22502
|
-
return Reflect.apply(target, thisArg, argArray);
|
|
22503
|
-
} });
|
|
22504
|
-
return {
|
|
22505
|
-
event,
|
|
22506
|
-
revoke() {
|
|
22507
|
-
event.stopPropagation = stopPropagation;
|
|
22508
|
-
}
|
|
22509
|
-
};
|
|
22703
|
+
passthrough() {
|
|
22704
|
+
this.data.connection.server.connect();
|
|
22510
22705
|
}
|
|
22511
|
-
|
|
22512
|
-
|
|
22513
|
-
|
|
22514
|
-
|
|
22515
|
-
|
|
22706
|
+
};
|
|
22707
|
+
|
|
22708
|
+
// src/core/experimental/compat.ts
|
|
22709
|
+
function fromLegacyOnUnhandledRequest(getLegacyValue) {
|
|
22710
|
+
return ({ frame, defaults }) => {
|
|
22711
|
+
const legacyOnUnhandledRequestStrategy = getLegacyValue();
|
|
22712
|
+
if (legacyOnUnhandledRequestStrategy == null) {
|
|
22713
|
+
return;
|
|
22516
22714
|
}
|
|
22517
|
-
|
|
22715
|
+
if (typeof legacyOnUnhandledRequestStrategy === "function") {
|
|
22716
|
+
const request = frame instanceof HttpNetworkFrame ? frame.data.request : frame instanceof WebSocketNetworkFrame ? new Request(frame.data.connection.client.url, {
|
|
22717
|
+
headers: {
|
|
22718
|
+
connection: "upgrade",
|
|
22719
|
+
upgrade: "websocket"
|
|
22720
|
+
}
|
|
22721
|
+
}) : null;
|
|
22722
|
+
invariant(
|
|
22723
|
+
request != null,
|
|
22724
|
+
'Failed to coerce a network frame to a legacy `onUnhandledRequest` strategy: unknown frame protocol "%s"',
|
|
22725
|
+
frame.protocol
|
|
22726
|
+
);
|
|
22727
|
+
return legacyOnUnhandledRequestStrategy(request, {
|
|
22728
|
+
warning: defaults.warn,
|
|
22729
|
+
error: defaults.error
|
|
22730
|
+
});
|
|
22731
|
+
}
|
|
22732
|
+
return executeUnhandledFrameHandle(frame, legacyOnUnhandledRequestStrategy);
|
|
22733
|
+
};
|
|
22734
|
+
}
|
|
22735
|
+
|
|
22736
|
+
// src/browser/utils/supports.ts
|
|
22737
|
+
function supportsServiceWorker() {
|
|
22738
|
+
return typeof navigator !== "undefined" && "serviceWorker" in navigator && typeof location !== "undefined" && location.protocol !== "file:";
|
|
22739
|
+
}
|
|
22740
|
+
function supportsReadableStreamTransfer() {
|
|
22741
|
+
try {
|
|
22742
|
+
const stream = new ReadableStream({
|
|
22743
|
+
start: (controller) => controller.close()
|
|
22744
|
+
});
|
|
22745
|
+
const message4 = new MessageChannel();
|
|
22746
|
+
message4.port1.postMessage(stream, [stream]);
|
|
22747
|
+
return true;
|
|
22748
|
+
} catch {
|
|
22749
|
+
return false;
|
|
22518
22750
|
}
|
|
22519
|
-
|
|
22520
|
-
|
|
22521
|
-
|
|
22522
|
-
|
|
22523
|
-
|
|
22524
|
-
|
|
22751
|
+
}
|
|
22752
|
+
|
|
22753
|
+
// src/core/utils/toResponseInit.ts
|
|
22754
|
+
function toResponseInit(response) {
|
|
22755
|
+
return {
|
|
22756
|
+
status: response.status,
|
|
22757
|
+
statusText: response.statusText,
|
|
22758
|
+
headers: Object.fromEntries(response.headers.entries())
|
|
22759
|
+
};
|
|
22760
|
+
}
|
|
22761
|
+
|
|
22762
|
+
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
22763
|
+
function getAbsoluteWorkerUrl(workerUrl) {
|
|
22764
|
+
return new URL(workerUrl, location.href).href;
|
|
22765
|
+
}
|
|
22766
|
+
|
|
22767
|
+
// src/browser/utils/get-worker-by-registration.ts
|
|
22768
|
+
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
22769
|
+
const allStates = [
|
|
22770
|
+
registration.active,
|
|
22771
|
+
registration.installing,
|
|
22772
|
+
registration.waiting
|
|
22773
|
+
];
|
|
22774
|
+
const relevantStates = allStates.filter((state) => {
|
|
22775
|
+
return state != null;
|
|
22776
|
+
});
|
|
22777
|
+
const worker = relevantStates.find((worker2) => {
|
|
22778
|
+
return findWorker(worker2.scriptURL, absoluteWorkerUrl);
|
|
22779
|
+
});
|
|
22780
|
+
return worker || null;
|
|
22781
|
+
}
|
|
22782
|
+
|
|
22783
|
+
// src/browser/utils/get-worker-instance.ts
|
|
22784
|
+
var getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
22785
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
22786
|
+
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then(
|
|
22787
|
+
(registrations) => registrations.filter(
|
|
22788
|
+
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
22789
|
+
)
|
|
22790
|
+
);
|
|
22791
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
22792
|
+
location.reload();
|
|
22525
22793
|
}
|
|
22526
|
-
|
|
22527
|
-
|
|
22794
|
+
const [existingRegistration] = mockRegistrations;
|
|
22795
|
+
if (existingRegistration) {
|
|
22796
|
+
existingRegistration.update();
|
|
22797
|
+
return [
|
|
22798
|
+
getWorkerByRegistration(
|
|
22799
|
+
existingRegistration,
|
|
22800
|
+
absoluteWorkerUrl,
|
|
22801
|
+
findWorker
|
|
22802
|
+
),
|
|
22803
|
+
existingRegistration
|
|
22804
|
+
];
|
|
22805
|
+
}
|
|
22806
|
+
const [registrationError, registrationResult] = await until(async () => {
|
|
22807
|
+
const registration = await navigator.serviceWorker.register(url, options);
|
|
22808
|
+
return [
|
|
22809
|
+
// Compare existing worker registration by its worker URL,
|
|
22810
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
22811
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
22812
|
+
registration
|
|
22813
|
+
];
|
|
22814
|
+
});
|
|
22815
|
+
if (registrationError) {
|
|
22816
|
+
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
22817
|
+
if (isWorkerMissing) {
|
|
22818
|
+
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
22819
|
+
throw new Error(
|
|
22820
|
+
devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
22821
|
+
|
|
22822
|
+
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
22823
|
+
|
|
22824
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
22825
|
+
);
|
|
22826
|
+
}
|
|
22827
|
+
throw new Error(
|
|
22828
|
+
devUtils.formatMessage(
|
|
22829
|
+
"Failed to register the Service Worker:\n\n%s",
|
|
22830
|
+
registrationError.message
|
|
22831
|
+
)
|
|
22832
|
+
);
|
|
22528
22833
|
}
|
|
22834
|
+
return registrationResult;
|
|
22529
22835
|
};
|
|
22530
22836
|
|
|
22531
22837
|
// src/browser/utils/workerChannel.ts
|
|
@@ -22555,7 +22861,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22555
22861
|
);
|
|
22556
22862
|
}
|
|
22557
22863
|
};
|
|
22558
|
-
var WorkerChannel = class extends
|
|
22864
|
+
var WorkerChannel = class extends Emitter {
|
|
22559
22865
|
constructor(options) {
|
|
22560
22866
|
super();
|
|
22561
22867
|
this.options = options;
|
|
@@ -22587,6 +22893,330 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22587
22893
|
}
|
|
22588
22894
|
};
|
|
22589
22895
|
|
|
22896
|
+
// src/browser/utils/pruneGetRequestBody.ts
|
|
22897
|
+
function pruneGetRequestBody(request) {
|
|
22898
|
+
if (["HEAD", "GET"].includes(request.method)) {
|
|
22899
|
+
return void 0;
|
|
22900
|
+
}
|
|
22901
|
+
return request.body;
|
|
22902
|
+
}
|
|
22903
|
+
|
|
22904
|
+
// src/browser/utils/deserializeRequest.ts
|
|
22905
|
+
function deserializeRequest(serializedRequest) {
|
|
22906
|
+
return new Request(serializedRequest.url, {
|
|
22907
|
+
...serializedRequest,
|
|
22908
|
+
body: pruneGetRequestBody(serializedRequest)
|
|
22909
|
+
});
|
|
22910
|
+
}
|
|
22911
|
+
|
|
22912
|
+
// src/browser/utils/validate-worker-scope.ts
|
|
22913
|
+
function validateWorkerScope(registration) {
|
|
22914
|
+
if (!location.href.startsWith(registration.scope)) {
|
|
22915
|
+
devUtils.warn(
|
|
22916
|
+
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
22917
|
+
|
|
22918
|
+
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
22919
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
22920
|
+
);
|
|
22921
|
+
}
|
|
22922
|
+
}
|
|
22923
|
+
|
|
22924
|
+
// src/browser/sources/service-worker-source.ts
|
|
22925
|
+
var ServiceWorkerSource = class extends NetworkSource {
|
|
22926
|
+
constructor(options) {
|
|
22927
|
+
super();
|
|
22928
|
+
this.options = options;
|
|
22929
|
+
invariant(
|
|
22930
|
+
supportsServiceWorker(),
|
|
22931
|
+
"Failed to use Service Worker as the network source: the Service Worker API is not supported in this environment"
|
|
22932
|
+
);
|
|
22933
|
+
this.#frames = /* @__PURE__ */ new Map();
|
|
22934
|
+
this.workerPromise = new DeferredPromise();
|
|
22935
|
+
this.#channel = new WorkerChannel({
|
|
22936
|
+
worker: this.workerPromise.then(([worker]) => worker)
|
|
22937
|
+
});
|
|
22938
|
+
}
|
|
22939
|
+
#frames;
|
|
22940
|
+
#channel;
|
|
22941
|
+
#clientPromise;
|
|
22942
|
+
#keepAliveInterval;
|
|
22943
|
+
#stoppedAt;
|
|
22944
|
+
workerPromise;
|
|
22945
|
+
async enable() {
|
|
22946
|
+
this.#stoppedAt = void 0;
|
|
22947
|
+
if (this.workerPromise.state !== "pending") {
|
|
22948
|
+
devUtils.warn(
|
|
22949
|
+
'Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.'
|
|
22950
|
+
);
|
|
22951
|
+
return this.workerPromise.then(([, registration2]) => registration2);
|
|
22952
|
+
}
|
|
22953
|
+
this.#channel.removeAllListeners();
|
|
22954
|
+
const [worker, registration] = await this.#startWorker();
|
|
22955
|
+
if (worker.state !== "activated") {
|
|
22956
|
+
const controller = new AbortController();
|
|
22957
|
+
const activationPromise = new DeferredPromise();
|
|
22958
|
+
activationPromise.then(() => controller.abort());
|
|
22959
|
+
worker.addEventListener(
|
|
22960
|
+
"statechange",
|
|
22961
|
+
() => {
|
|
22962
|
+
if (worker.state === "activated") {
|
|
22963
|
+
activationPromise.resolve();
|
|
22964
|
+
}
|
|
22965
|
+
},
|
|
22966
|
+
{ signal: controller.signal }
|
|
22967
|
+
);
|
|
22968
|
+
await activationPromise;
|
|
22969
|
+
}
|
|
22970
|
+
this.#channel.postMessage("MOCK_ACTIVATE");
|
|
22971
|
+
const clientConfirmationPromise = new DeferredPromise();
|
|
22972
|
+
this.#clientPromise = clientConfirmationPromise;
|
|
22973
|
+
this.#channel.once("MOCKING_ENABLED", (event) => {
|
|
22974
|
+
clientConfirmationPromise.resolve(event.data.client);
|
|
22975
|
+
});
|
|
22976
|
+
await clientConfirmationPromise;
|
|
22977
|
+
if (!this.options.quiet) {
|
|
22978
|
+
this.#printStartMessage();
|
|
22979
|
+
}
|
|
22980
|
+
return registration;
|
|
22981
|
+
}
|
|
22982
|
+
disable() {
|
|
22983
|
+
if (typeof this.#stoppedAt !== "undefined") {
|
|
22984
|
+
devUtils.warn(
|
|
22985
|
+
`Found a redundant "worker.stop()" call. Notice that stopping the worker after it has already been stopped has no effect. Consider removing this "worker.stop()" call.`
|
|
22986
|
+
);
|
|
22987
|
+
return;
|
|
22988
|
+
}
|
|
22989
|
+
this.#stoppedAt = Date.now();
|
|
22990
|
+
this.#frames.clear();
|
|
22991
|
+
this.workerPromise = new DeferredPromise();
|
|
22992
|
+
if (!this.options.quiet) {
|
|
22993
|
+
this.#printStopMessage();
|
|
22994
|
+
}
|
|
22995
|
+
}
|
|
22996
|
+
async #startWorker() {
|
|
22997
|
+
if (this.#keepAliveInterval) {
|
|
22998
|
+
clearInterval(this.#keepAliveInterval);
|
|
22999
|
+
}
|
|
23000
|
+
const workerUrl = this.options.serviceWorker.url;
|
|
23001
|
+
const [worker, registration] = await getWorkerInstance(
|
|
23002
|
+
workerUrl,
|
|
23003
|
+
this.options.serviceWorker.options,
|
|
23004
|
+
this.options.findWorker || this.#defaultFindWorker
|
|
23005
|
+
);
|
|
23006
|
+
if (worker == null) {
|
|
23007
|
+
const missingWorkerMessage = this.options?.findWorker ? devUtils.formatMessage(
|
|
23008
|
+
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
23009
|
+
|
|
23010
|
+
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
23011
|
+
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
23012
|
+
`,
|
|
23013
|
+
workerUrl
|
|
23014
|
+
) : devUtils.formatMessage(
|
|
23015
|
+
`Failed to locate the Service Worker registration.
|
|
23016
|
+
|
|
23017
|
+
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
23018
|
+
|
|
23019
|
+
Please consider using a custom "serviceWorker.url" option to point to the actual worker script location, or a custom "findWorker" option to resolve the Service Worker registration manually. More details: https://mswjs.io/docs/api/setup-worker/start`,
|
|
23020
|
+
workerUrl,
|
|
23021
|
+
location.host
|
|
23022
|
+
);
|
|
23023
|
+
throw new Error(missingWorkerMessage);
|
|
23024
|
+
}
|
|
23025
|
+
this.workerPromise.resolve([worker, registration]);
|
|
23026
|
+
this.#channel.on("REQUEST", this.#handleRequest.bind(this));
|
|
23027
|
+
this.#channel.on("RESPONSE", this.#handleResponse.bind(this));
|
|
23028
|
+
window.addEventListener("beforeunload", () => {
|
|
23029
|
+
if (worker.state !== "redundant") {
|
|
23030
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
23031
|
+
}
|
|
23032
|
+
clearInterval(this.#keepAliveInterval);
|
|
23033
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
23034
|
+
});
|
|
23035
|
+
await this.#checkWorkerIntegrity().catch((error3) => {
|
|
23036
|
+
devUtils.error(
|
|
23037
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
23038
|
+
);
|
|
23039
|
+
console.error(error3);
|
|
23040
|
+
});
|
|
23041
|
+
this.#keepAliveInterval = window.setInterval(() => {
|
|
23042
|
+
this.#channel.postMessage("KEEPALIVE_REQUEST");
|
|
23043
|
+
}, 5e3);
|
|
23044
|
+
if (!this.options.quiet) {
|
|
23045
|
+
validateWorkerScope(registration);
|
|
23046
|
+
}
|
|
23047
|
+
return [worker, registration];
|
|
23048
|
+
}
|
|
23049
|
+
async #handleRequest(event) {
|
|
23050
|
+
if (this.#stoppedAt && event.data.interceptedAt > this.#stoppedAt) {
|
|
23051
|
+
return event.postMessage("PASSTHROUGH");
|
|
23052
|
+
}
|
|
23053
|
+
const request = deserializeRequest(event.data);
|
|
23054
|
+
RequestHandler.cache.set(request, request.clone());
|
|
23055
|
+
const frame = new ServiceWorkerHttpNetworkFrame({
|
|
23056
|
+
event,
|
|
23057
|
+
request
|
|
23058
|
+
});
|
|
23059
|
+
this.#frames.set(event.data.id, frame);
|
|
23060
|
+
await this.queue(frame);
|
|
23061
|
+
}
|
|
23062
|
+
async #handleResponse(event) {
|
|
23063
|
+
const { request, response, isMockedResponse } = event.data;
|
|
23064
|
+
if (response.type?.includes("opaque")) {
|
|
23065
|
+
this.#frames.delete(request.id);
|
|
23066
|
+
return;
|
|
23067
|
+
}
|
|
23068
|
+
const frame = this.#frames.get(request.id);
|
|
23069
|
+
this.#frames.delete(request.id);
|
|
23070
|
+
if (frame == null) {
|
|
23071
|
+
return;
|
|
23072
|
+
}
|
|
23073
|
+
const fetchRequest = deserializeRequest(request);
|
|
23074
|
+
const fetchResponse = response.status === 0 ? Response.error() : new FetchResponse(
|
|
23075
|
+
/**
|
|
23076
|
+
* Responses may be streams here, but when we create a response object
|
|
23077
|
+
* with null-body status codes, like 204, 205, 304 Response will
|
|
23078
|
+
* throw when passed a non-null body, so ensure it's null here
|
|
23079
|
+
* for those codes
|
|
23080
|
+
*/
|
|
23081
|
+
FetchResponse.isResponseWithBody(response.status) ? response.body : null,
|
|
23082
|
+
{
|
|
23083
|
+
...response,
|
|
23084
|
+
/**
|
|
23085
|
+
* Set response URL if it's not set already.
|
|
23086
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
23087
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
23088
|
+
*/
|
|
23089
|
+
url: request.url
|
|
23090
|
+
}
|
|
23091
|
+
);
|
|
23092
|
+
frame.events.emit(
|
|
23093
|
+
new ResponseEvent(
|
|
23094
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
23095
|
+
{
|
|
23096
|
+
requestId: frame.data.id,
|
|
23097
|
+
request: fetchRequest,
|
|
23098
|
+
response: fetchResponse,
|
|
23099
|
+
isMockedResponse
|
|
23100
|
+
}
|
|
23101
|
+
)
|
|
23102
|
+
);
|
|
23103
|
+
}
|
|
23104
|
+
#defaultFindWorker = (workerUrl, mockServiceWorkerUrl) => {
|
|
23105
|
+
return workerUrl === mockServiceWorkerUrl;
|
|
23106
|
+
};
|
|
23107
|
+
async #checkWorkerIntegrity() {
|
|
23108
|
+
const integrityCheckPromise = new DeferredPromise();
|
|
23109
|
+
this.#channel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
23110
|
+
this.#channel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
23111
|
+
const { checksum, packageVersion } = event.data;
|
|
23112
|
+
if (checksum !== "4db4a41e972cec1b64cc569c66952d82") {
|
|
23113
|
+
devUtils.warn(
|
|
23114
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${packageVersion}) and may not be fully compatible with the installed version.
|
|
23115
|
+
|
|
23116
|
+
It's recommended you update your worker script by running this command:
|
|
23117
|
+
|
|
23118
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
23119
|
+
|
|
23120
|
+
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
23121
|
+
);
|
|
23122
|
+
}
|
|
23123
|
+
integrityCheckPromise.resolve();
|
|
23124
|
+
});
|
|
23125
|
+
return integrityCheckPromise;
|
|
23126
|
+
}
|
|
23127
|
+
async #printStartMessage() {
|
|
23128
|
+
if (this.workerPromise.state === "rejected") {
|
|
23129
|
+
return;
|
|
23130
|
+
}
|
|
23131
|
+
invariant(
|
|
23132
|
+
this.#clientPromise != null,
|
|
23133
|
+
"[ServiceWorkerSource] Failed to print a start message: client confirmation not received"
|
|
23134
|
+
);
|
|
23135
|
+
const client = await this.#clientPromise;
|
|
23136
|
+
const [worker, registration] = await this.workerPromise;
|
|
23137
|
+
console.groupCollapsed(
|
|
23138
|
+
`%c${devUtils.formatMessage("Mocking enabled.")}`,
|
|
23139
|
+
"color:orangered;font-weight:bold;"
|
|
23140
|
+
);
|
|
23141
|
+
console.log(
|
|
23142
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
23143
|
+
"font-weight:bold",
|
|
23144
|
+
"font-weight:normal"
|
|
23145
|
+
);
|
|
23146
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
23147
|
+
console.log("Worker script URL:", worker.scriptURL);
|
|
23148
|
+
console.log("Worker scope:", registration.scope);
|
|
23149
|
+
if (client) {
|
|
23150
|
+
console.log("Client ID: %s (%s)", client.id, client.frameType);
|
|
23151
|
+
}
|
|
23152
|
+
console.groupEnd();
|
|
23153
|
+
}
|
|
23154
|
+
#printStopMessage() {
|
|
23155
|
+
console.log(
|
|
23156
|
+
`%c${devUtils.formatMessage("Mocking disabled.")}`,
|
|
23157
|
+
"color:orangered;font-weight:bold;"
|
|
23158
|
+
);
|
|
23159
|
+
}
|
|
23160
|
+
};
|
|
23161
|
+
var ServiceWorkerHttpNetworkFrame = class extends HttpNetworkFrame {
|
|
23162
|
+
#event;
|
|
23163
|
+
constructor(options) {
|
|
23164
|
+
super({ request: options.request });
|
|
23165
|
+
this.#event = options.event;
|
|
23166
|
+
}
|
|
23167
|
+
passthrough() {
|
|
23168
|
+
this.#event.postMessage("PASSTHROUGH");
|
|
23169
|
+
}
|
|
23170
|
+
respondWith(response) {
|
|
23171
|
+
if (response) {
|
|
23172
|
+
this.#respondWith(response);
|
|
23173
|
+
}
|
|
23174
|
+
}
|
|
23175
|
+
errorWith(reason) {
|
|
23176
|
+
if (reason instanceof Response) {
|
|
23177
|
+
return this.respondWith(reason);
|
|
23178
|
+
}
|
|
23179
|
+
devUtils.warn(
|
|
23180
|
+
`Uncaught exception in the request handler for "%s %s". This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
|
|
23181
|
+
this.data.request.method,
|
|
23182
|
+
this.data.request.url
|
|
23183
|
+
);
|
|
23184
|
+
const error3 = reason instanceof Error ? reason : new Error(reason?.toString() || "Request failure");
|
|
23185
|
+
this.respondWith(
|
|
23186
|
+
HttpResponse.json(
|
|
23187
|
+
{
|
|
23188
|
+
name: error3.name,
|
|
23189
|
+
message: error3.message,
|
|
23190
|
+
stack: error3.stack
|
|
23191
|
+
},
|
|
23192
|
+
{
|
|
23193
|
+
status: 500,
|
|
23194
|
+
statusText: "Request Handler Error"
|
|
23195
|
+
}
|
|
23196
|
+
)
|
|
23197
|
+
);
|
|
23198
|
+
}
|
|
23199
|
+
async #respondWith(response) {
|
|
23200
|
+
let responseBody;
|
|
23201
|
+
let transfer;
|
|
23202
|
+
const responseInit = toResponseInit(response);
|
|
23203
|
+
if (supportsReadableStreamTransfer()) {
|
|
23204
|
+
responseBody = response.body;
|
|
23205
|
+
transfer = response.body == null ? void 0 : [response.body];
|
|
23206
|
+
} else {
|
|
23207
|
+
responseBody = response.body == null ? null : await response.clone().arrayBuffer();
|
|
23208
|
+
}
|
|
23209
|
+
this.#event.postMessage(
|
|
23210
|
+
"MOCK_RESPONSE",
|
|
23211
|
+
{
|
|
23212
|
+
...responseInit,
|
|
23213
|
+
body: responseBody
|
|
23214
|
+
},
|
|
23215
|
+
transfer
|
|
23216
|
+
);
|
|
23217
|
+
}
|
|
23218
|
+
};
|
|
23219
|
+
|
|
22590
23220
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
22591
23221
|
var until2 = async (promise) => {
|
|
22592
23222
|
try {
|
|
@@ -23531,180 +24161,139 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
23531
24161
|
}
|
|
23532
24162
|
};
|
|
23533
24163
|
|
|
23534
|
-
// src/browser/
|
|
23535
|
-
|
|
23536
|
-
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23543
|
-
|
|
23544
|
-
|
|
23545
|
-
|
|
23546
|
-
options,
|
|
23547
|
-
context.emitter,
|
|
23548
|
-
{
|
|
23549
|
-
resolutionContext: {
|
|
23550
|
-
quiet: options.quiet
|
|
23551
|
-
},
|
|
23552
|
-
onMockedResponse(_, { handler, parsedResult }) {
|
|
23553
|
-
if (!options.quiet) {
|
|
23554
|
-
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
23555
|
-
handler.log({
|
|
23556
|
-
request: requestCloneForLogs,
|
|
23557
|
-
response: response2,
|
|
23558
|
-
parsedResult
|
|
23559
|
-
});
|
|
23560
|
-
});
|
|
23561
|
-
}
|
|
23562
|
-
}
|
|
23563
|
-
}
|
|
23564
|
-
);
|
|
23565
|
-
if (response) {
|
|
23566
|
-
controller.respondWith(response);
|
|
24164
|
+
// src/browser/sources/fallback-http-source.ts
|
|
24165
|
+
var FallbackHttpSource = class extends InterceptorSource {
|
|
24166
|
+
constructor(options) {
|
|
24167
|
+
super({
|
|
24168
|
+
interceptors: [new XMLHttpRequestInterceptor(), new FetchInterceptor()]
|
|
24169
|
+
});
|
|
24170
|
+
this.options = options;
|
|
24171
|
+
}
|
|
24172
|
+
enable() {
|
|
24173
|
+
super.enable();
|
|
24174
|
+
if (!this.options.quiet) {
|
|
24175
|
+
this.#printStartMessage();
|
|
23567
24176
|
}
|
|
23568
|
-
}
|
|
23569
|
-
|
|
23570
|
-
|
|
23571
|
-
(
|
|
23572
|
-
|
|
23573
|
-
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
23574
|
-
{
|
|
23575
|
-
response,
|
|
23576
|
-
request,
|
|
23577
|
-
requestId
|
|
23578
|
-
}
|
|
23579
|
-
);
|
|
24177
|
+
}
|
|
24178
|
+
disable() {
|
|
24179
|
+
super.disable();
|
|
24180
|
+
if (!this.options.quiet) {
|
|
24181
|
+
this.#printStopMessage();
|
|
23580
24182
|
}
|
|
23581
|
-
);
|
|
23582
|
-
interceptor.apply();
|
|
23583
|
-
return interceptor;
|
|
23584
|
-
}
|
|
23585
|
-
|
|
23586
|
-
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
23587
|
-
function printStopMessage(args = {}) {
|
|
23588
|
-
if (args.quiet) {
|
|
23589
|
-
return;
|
|
23590
24183
|
}
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
|
|
23595
|
-
}
|
|
23596
|
-
|
|
23597
|
-
// src/browser/setupWorker/setupWorker.ts
|
|
23598
|
-
var SetupWorkerApi = class extends SetupApi {
|
|
23599
|
-
context;
|
|
23600
|
-
constructor(...handlers) {
|
|
23601
|
-
super(...handlers);
|
|
23602
|
-
invariant(
|
|
23603
|
-
!isNodeProcess(),
|
|
23604
|
-
devUtils.formatMessage(
|
|
23605
|
-
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
23606
|
-
)
|
|
24184
|
+
#printStartMessage() {
|
|
24185
|
+
console.groupCollapsed(
|
|
24186
|
+
`%c${devUtils.formatMessage("Mocking enabled (fallback mode).")}`,
|
|
24187
|
+
"color:orangered;font-weight:bold;"
|
|
23607
24188
|
);
|
|
23608
|
-
|
|
23609
|
-
|
|
23610
|
-
|
|
23611
|
-
|
|
23612
|
-
|
|
23613
|
-
|
|
23614
|
-
|
|
23615
|
-
isMockingEnabled: false,
|
|
23616
|
-
startOptions: null,
|
|
23617
|
-
workerPromise,
|
|
23618
|
-
registration: void 0,
|
|
23619
|
-
getRequestHandlers: () => {
|
|
23620
|
-
return this.handlersController.currentHandlers();
|
|
23621
|
-
},
|
|
23622
|
-
emitter: this.emitter,
|
|
23623
|
-
workerChannel: new WorkerChannel({
|
|
23624
|
-
worker: workerPromise
|
|
23625
|
-
})
|
|
23626
|
-
};
|
|
24189
|
+
console.log(
|
|
24190
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
24191
|
+
"font-weight:bold",
|
|
24192
|
+
"font-weight:normal"
|
|
24193
|
+
);
|
|
24194
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
24195
|
+
console.groupEnd();
|
|
23627
24196
|
}
|
|
23628
|
-
|
|
23629
|
-
|
|
23630
|
-
devUtils.
|
|
23631
|
-
|
|
23632
|
-
);
|
|
23633
|
-
}
|
|
23634
|
-
if (this.context.isMockingEnabled) {
|
|
23635
|
-
devUtils.warn(
|
|
23636
|
-
`Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.`
|
|
23637
|
-
);
|
|
23638
|
-
return this.context.registration;
|
|
23639
|
-
}
|
|
23640
|
-
this.context.workerStoppedAt = void 0;
|
|
23641
|
-
this.context.startOptions = mergeRight(
|
|
23642
|
-
DEFAULT_START_OPTIONS,
|
|
23643
|
-
options
|
|
24197
|
+
#printStopMessage() {
|
|
24198
|
+
console.log(
|
|
24199
|
+
`%c${devUtils.formatMessage("Mocking disabled.")}`,
|
|
24200
|
+
"color:orangered;font-weight:bold;"
|
|
23644
24201
|
);
|
|
23645
|
-
|
|
23646
|
-
|
|
23647
|
-
|
|
23648
|
-
|
|
23649
|
-
|
|
23650
|
-
|
|
23651
|
-
|
|
23652
|
-
|
|
23653
|
-
|
|
23654
|
-
|
|
23655
|
-
|
|
23656
|
-
|
|
23657
|
-
|
|
24202
|
+
}
|
|
24203
|
+
};
|
|
24204
|
+
|
|
24205
|
+
// src/browser/setup-worker.ts
|
|
24206
|
+
var DEFAULT_WORKER_URL = "/mockServiceWorker.js";
|
|
24207
|
+
function setupWorker(...handlers) {
|
|
24208
|
+
invariant(
|
|
24209
|
+
!isNodeProcess(),
|
|
24210
|
+
devUtils.formatMessage(
|
|
24211
|
+
"Failed to execute `setupWorker` in a non-browser environment"
|
|
24212
|
+
)
|
|
24213
|
+
);
|
|
24214
|
+
const network = defineNetwork({
|
|
24215
|
+
sources: [],
|
|
24216
|
+
handlers
|
|
24217
|
+
});
|
|
24218
|
+
return {
|
|
24219
|
+
async start(options) {
|
|
24220
|
+
if (options?.waitUntilReady != null) {
|
|
24221
|
+
devUtils.warn(
|
|
24222
|
+
`The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.`
|
|
24223
|
+
);
|
|
23658
24224
|
}
|
|
23659
|
-
|
|
23660
|
-
|
|
23661
|
-
|
|
23662
|
-
|
|
23663
|
-
|
|
23664
|
-
|
|
23665
|
-
const
|
|
23666
|
-
|
|
23667
|
-
|
|
23668
|
-
|
|
23669
|
-
|
|
23670
|
-
|
|
24225
|
+
if (network.readyState === 1 /* ENABLED */) {
|
|
24226
|
+
devUtils.warn(
|
|
24227
|
+
'Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.'
|
|
24228
|
+
);
|
|
24229
|
+
return;
|
|
24230
|
+
}
|
|
24231
|
+
const httpSource = supportsServiceWorker() ? new ServiceWorkerSource({
|
|
24232
|
+
serviceWorker: {
|
|
24233
|
+
url: options?.serviceWorker?.url?.toString() || DEFAULT_WORKER_URL,
|
|
24234
|
+
options: options?.serviceWorker?.options
|
|
24235
|
+
},
|
|
24236
|
+
findWorker: options?.findWorker,
|
|
24237
|
+
quiet: options?.quiet
|
|
24238
|
+
}) : new FallbackHttpSource({
|
|
24239
|
+
quiet: options?.quiet
|
|
23671
24240
|
});
|
|
23672
|
-
|
|
23673
|
-
|
|
23674
|
-
|
|
23675
|
-
|
|
24241
|
+
network.configure({
|
|
24242
|
+
sources: [
|
|
24243
|
+
httpSource,
|
|
24244
|
+
new InterceptorSource({
|
|
24245
|
+
interceptors: [new WebSocketInterceptor()]
|
|
24246
|
+
})
|
|
24247
|
+
],
|
|
24248
|
+
onUnhandledFrame: fromLegacyOnUnhandledRequest(() => {
|
|
24249
|
+
return options?.onUnhandledRequest || "warn";
|
|
24250
|
+
}),
|
|
24251
|
+
context: {
|
|
24252
|
+
quiet: options?.quiet
|
|
24253
|
+
}
|
|
23676
24254
|
});
|
|
23677
|
-
|
|
23678
|
-
|
|
23679
|
-
|
|
23680
|
-
|
|
23681
|
-
|
|
23682
|
-
|
|
23683
|
-
|
|
23684
|
-
|
|
23685
|
-
|
|
23686
|
-
|
|
23687
|
-
|
|
23688
|
-
|
|
23689
|
-
|
|
23690
|
-
|
|
23691
|
-
|
|
23692
|
-
|
|
23693
|
-
|
|
23694
|
-
|
|
23695
|
-
|
|
23696
|
-
|
|
23697
|
-
|
|
23698
|
-
|
|
23699
|
-
|
|
23700
|
-
|
|
23701
|
-
|
|
23702
|
-
|
|
24255
|
+
await network.enable();
|
|
24256
|
+
if (httpSource instanceof ServiceWorkerSource) {
|
|
24257
|
+
const [, registration] = await httpSource.workerPromise;
|
|
24258
|
+
return registration;
|
|
24259
|
+
}
|
|
24260
|
+
},
|
|
24261
|
+
stop() {
|
|
24262
|
+
if (network.readyState === 0 /* DISABLED */) {
|
|
24263
|
+
devUtils.warn(
|
|
24264
|
+
`Found a redundant "worker.stop()" call. Notice that stopping the worker after it has already been stopped has no effect. Consider removing this "worker.stop()" call.`
|
|
24265
|
+
);
|
|
24266
|
+
return;
|
|
24267
|
+
}
|
|
24268
|
+
network.disable();
|
|
24269
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
24270
|
+
},
|
|
24271
|
+
events: network.events,
|
|
24272
|
+
use: network.use.bind(network),
|
|
24273
|
+
resetHandlers: network.resetHandlers.bind(network),
|
|
24274
|
+
restoreHandlers: network.restoreHandlers.bind(network),
|
|
24275
|
+
listHandlers: network.listHandlers.bind(network)
|
|
24276
|
+
};
|
|
24277
|
+
}
|
|
24278
|
+
var SetupWorkerApi = class {
|
|
24279
|
+
start;
|
|
24280
|
+
stop;
|
|
24281
|
+
use;
|
|
24282
|
+
resetHandlers;
|
|
24283
|
+
restoreHandlers;
|
|
24284
|
+
listHandlers;
|
|
24285
|
+
events;
|
|
24286
|
+
constructor() {
|
|
24287
|
+
const worker = setupWorker();
|
|
24288
|
+
this.start = worker.start.bind(worker);
|
|
24289
|
+
this.stop = worker.stop.bind(worker);
|
|
24290
|
+
this.use = worker.use.bind(worker);
|
|
24291
|
+
this.resetHandlers = worker.resetHandlers.bind(worker);
|
|
24292
|
+
this.restoreHandlers = worker.restoreHandlers.bind(worker);
|
|
24293
|
+
this.listHandlers = worker.listHandlers.bind(worker);
|
|
24294
|
+
this.events = worker.events;
|
|
23703
24295
|
}
|
|
23704
24296
|
};
|
|
23705
|
-
function setupWorker(...handlers) {
|
|
23706
|
-
return new SetupWorkerApi(...handlers);
|
|
23707
|
-
}
|
|
23708
24297
|
return __toCommonJS(index_exports);
|
|
23709
24298
|
})();
|
|
23710
24299
|
/*! Bundled license information:
|