msw 1.3.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -29
- package/browser/package.json +5 -0
- package/cli/init.js +3 -3
- package/config/constants.js +1 -2
- package/lib/browser/index.d.ts +104 -0
- package/lib/browser/index.js +751 -0
- package/lib/browser/index.mjs +733 -0
- package/lib/core/GraphQLHandler-b42ca96f.d.ts +74 -0
- package/lib/core/HttpResponse.d.ts +2 -0
- package/lib/core/HttpResponse.js +94 -0
- package/lib/core/HttpResponse.mjs +77 -0
- package/lib/core/RequestHandler-1a5dbdc7.d.ts +172 -0
- package/lib/core/SetupApi.d.ts +26 -0
- package/lib/core/SetupApi.js +83 -0
- package/lib/core/SetupApi.mjs +63 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +36 -0
- package/lib/core/bypass.mjs +16 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +92 -0
- package/lib/core/delay.mjs +72 -0
- package/lib/core/graphql.d.ts +109 -0
- package/lib/core/graphql.js +112 -0
- package/lib/core/graphql.mjs +96 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +5 -0
- package/lib/core/handlers/GraphQLHandler.js +145 -0
- package/lib/core/handlers/GraphQLHandler.mjs +130 -0
- package/lib/core/handlers/HttpHandler.d.ts +62 -0
- package/lib/core/handlers/HttpHandler.js +149 -0
- package/lib/core/handlers/HttpHandler.mjs +133 -0
- package/lib/core/handlers/RequestHandler.d.ts +2 -0
- package/lib/core/handlers/RequestHandler.js +180 -0
- package/lib/core/handlers/RequestHandler.mjs +162 -0
- package/lib/core/http.d.ts +26 -0
- package/lib/core/http.js +39 -0
- package/lib/core/http.mjs +22 -0
- package/lib/core/http.spec.d.ts +2 -0
- package/lib/core/http.spec.js +15 -0
- package/lib/core/http.spec.mjs +14 -0
- package/lib/core/index.d.ts +18 -0
- package/lib/core/index.js +49 -0
- package/lib/core/index.mjs +28 -0
- package/lib/core/passthrough.d.ts +17 -0
- package/lib/core/passthrough.js +32 -0
- package/lib/core/passthrough.mjs +12 -0
- package/lib/core/sharedOptions.d.ts +66 -0
- package/lib/core/sharedOptions.js +16 -0
- package/lib/core/sharedOptions.mjs +0 -0
- package/lib/core/typeUtils.d.ts +7 -0
- package/lib/core/typeUtils.js +16 -0
- package/lib/core/typeUtils.mjs +0 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +12 -0
- package/lib/core/utils/HttpResponse/decorators.js +80 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +52 -0
- package/lib/core/utils/getResponse.d.ts +2 -0
- package/lib/core/utils/getResponse.js +64 -0
- package/lib/core/utils/getResponse.mjs +44 -0
- package/lib/core/utils/handleRequest.d.ts +30 -0
- package/lib/core/utils/handleRequest.js +102 -0
- package/lib/core/utils/handleRequest.mjs +82 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +53 -0
- package/lib/core/utils/internal/Disposable.mjs +33 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +33 -0
- package/lib/core/utils/internal/checkGlobals.mjs +13 -0
- package/lib/core/utils/internal/devUtils.d.ts +19 -0
- package/lib/core/utils/internal/devUtils.js +40 -0
- package/lib/core/utils/internal/devUtils.mjs +20 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +40 -0
- package/lib/core/utils/internal/getCallFrame.mjs +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +6 -0
- package/lib/core/utils/internal/isIterable.js +29 -0
- package/lib/core/utils/internal/isIterable.mjs +9 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +26 -0
- package/lib/core/utils/internal/isObject.mjs +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +26 -0
- package/lib/core/utils/internal/isStringEqual.mjs +6 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +30 -0
- package/lib/core/utils/internal/jsonParse.mjs +10 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +39 -0
- package/lib/core/utils/internal/mergeRight.mjs +19 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +5 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +184 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +165 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +10 -0
- package/lib/core/utils/internal/parseMultipartData.js +81 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +61 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +34 -0
- package/lib/core/utils/internal/pipeEvents.mjs +14 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +8 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +36 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +16 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +28 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +8 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +31 -0
- package/lib/core/utils/internal/tryCatch.mjs +11 -0
- package/lib/core/utils/internal/uuidv4.d.ts +3 -0
- package/lib/core/utils/internal/uuidv4.js +26 -0
- package/lib/core/utils/internal/uuidv4.mjs +6 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +39 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +19 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +6 -0
- package/lib/core/utils/logging/getTimestamp.js +27 -0
- package/lib/core/utils/logging/getTimestamp.mjs +7 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +55 -0
- package/lib/core/utils/logging/serializeRequest.mjs +35 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +69 -0
- package/lib/core/utils/logging/serializeResponse.mjs +39 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +19 -0
- package/lib/core/utils/matching/matchRequestUrl.js +50 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +30 -0
- package/lib/core/utils/matching/normalizePath.d.ts +12 -0
- package/lib/core/utils/matching/normalizePath.js +32 -0
- package/lib/core/utils/matching/normalizePath.mjs +12 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.d.ts +7 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js +30 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs +10 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +8 -0
- package/lib/core/utils/request/getRequestCookies.js +88 -0
- package/lib/core/utils/request/getRequestCookies.mjs +60 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +12 -0
- package/lib/core/utils/request/onUnhandledRequest.js +193 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +165 -0
- package/lib/core/utils/request/readResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/readResponseCookies.js +45 -0
- package/lib/core/utils/request/readResponseCookies.mjs +27 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +30 -0
- package/lib/core/utils/toResponseInit.mjs +10 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +37 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +17 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +26 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +6 -0
- package/lib/iife/index.js +6203 -12360
- package/lib/mockServiceWorker.js +82 -93
- package/lib/native/index.d.ts +67 -7
- package/lib/native/index.js +74 -1500
- package/lib/native/index.mjs +69 -1514
- package/lib/node/index.d.ts +68 -9
- package/lib/node/index.js +77 -1508
- package/lib/node/index.mjs +71 -1521
- package/native/package.json +2 -1
- package/node/package.json +2 -1
- package/package.json +53 -23
- package/lib/SetupServerApi-1855d9c6.d.ts +0 -20
- package/lib/glossary-de6278a9.d.ts +0 -385
- package/lib/iife/index.js.map +0 -1
- package/lib/index.d.ts +0 -365
- package/lib/index.js +0 -2295
- package/lib/index.js.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/index.mjs.map +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { invariant } from "outvariant";
|
|
41
|
+
import { getCallFrame } from '../utils/internal/getCallFrame.mjs';
|
|
42
|
+
import { isIterable } from '../utils/internal/isIterable.mjs';
|
|
43
|
+
class RequestHandler {
|
|
44
|
+
constructor(args) {
|
|
45
|
+
this.resolver = args.resolver;
|
|
46
|
+
this.options = args.options;
|
|
47
|
+
const callFrame = getCallFrame(new Error());
|
|
48
|
+
this.info = __spreadProps(__spreadValues({}, args.info), {
|
|
49
|
+
callFrame
|
|
50
|
+
});
|
|
51
|
+
this.isUsed = false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse the intercepted request to extract additional information from it.
|
|
55
|
+
* Parsed result is then exposed to other methods of this request handler.
|
|
56
|
+
*/
|
|
57
|
+
parse(_args) {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
return {};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Test if this handler matches the given request.
|
|
64
|
+
*/
|
|
65
|
+
test(args) {
|
|
66
|
+
return __async(this, null, function* () {
|
|
67
|
+
const parsedResult = yield this.parse({
|
|
68
|
+
request: args.request,
|
|
69
|
+
resolutionContext: args.resolutionContext
|
|
70
|
+
});
|
|
71
|
+
return this.predicate({
|
|
72
|
+
request: args.request,
|
|
73
|
+
parsedResult,
|
|
74
|
+
resolutionContext: args.resolutionContext
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
extendResolverArgs(_args) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Execute this request handler and produce a mocked response
|
|
83
|
+
* using the given resolver function.
|
|
84
|
+
*/
|
|
85
|
+
run(args) {
|
|
86
|
+
return __async(this, null, function* () {
|
|
87
|
+
var _a;
|
|
88
|
+
if (this.isUsed && ((_a = this.options) == null ? void 0 : _a.once)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const mainRequestRef = args.request.clone();
|
|
92
|
+
this.isUsed = true;
|
|
93
|
+
const parsedResult = yield this.parse({
|
|
94
|
+
request: args.request,
|
|
95
|
+
resolutionContext: args.resolutionContext
|
|
96
|
+
});
|
|
97
|
+
const shouldInterceptRequest = this.predicate({
|
|
98
|
+
request: args.request,
|
|
99
|
+
parsedResult,
|
|
100
|
+
resolutionContext: args.resolutionContext
|
|
101
|
+
});
|
|
102
|
+
if (!shouldInterceptRequest) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const executeResolver = this.wrapResolver(this.resolver);
|
|
106
|
+
const resolverExtras = this.extendResolverArgs({
|
|
107
|
+
request: args.request,
|
|
108
|
+
parsedResult
|
|
109
|
+
});
|
|
110
|
+
const mockedResponse = yield executeResolver(__spreadProps(__spreadValues({}, resolverExtras), {
|
|
111
|
+
request: args.request
|
|
112
|
+
}));
|
|
113
|
+
const executionResult = this.createExecutionResult({
|
|
114
|
+
// Pass the cloned request to the result so that logging
|
|
115
|
+
// and other consumers could read its body once more.
|
|
116
|
+
request: mainRequestRef,
|
|
117
|
+
response: mockedResponse,
|
|
118
|
+
parsedResult
|
|
119
|
+
});
|
|
120
|
+
return executionResult;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
wrapResolver(resolver) {
|
|
124
|
+
return (info) => __async(this, null, function* () {
|
|
125
|
+
const result = this.resolverGenerator || (yield resolver(info));
|
|
126
|
+
if (isIterable(result)) {
|
|
127
|
+
this.isUsed = false;
|
|
128
|
+
const { value, done } = result[Symbol.iterator]().next();
|
|
129
|
+
const nextResponse = yield value;
|
|
130
|
+
if (done) {
|
|
131
|
+
this.isUsed = true;
|
|
132
|
+
}
|
|
133
|
+
if (!nextResponse && done) {
|
|
134
|
+
invariant(
|
|
135
|
+
this.resolverGeneratorResult,
|
|
136
|
+
"Failed to returned a previously stored generator response: the value is not a valid Response."
|
|
137
|
+
);
|
|
138
|
+
return this.resolverGeneratorResult.clone();
|
|
139
|
+
}
|
|
140
|
+
if (!this.resolverGenerator) {
|
|
141
|
+
this.resolverGenerator = result;
|
|
142
|
+
}
|
|
143
|
+
if (nextResponse) {
|
|
144
|
+
this.resolverGeneratorResult = nextResponse == null ? void 0 : nextResponse.clone();
|
|
145
|
+
}
|
|
146
|
+
return nextResponse;
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
createExecutionResult(args) {
|
|
152
|
+
return {
|
|
153
|
+
handler: this,
|
|
154
|
+
request: args.request,
|
|
155
|
+
response: args.response,
|
|
156
|
+
parsedResult: args.parsedResult
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
RequestHandler
|
|
162
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { D as DefaultBodyType, a as ResponseResolver, c as RequestHandlerOptions } from './RequestHandler-1a5dbdc7.js';
|
|
2
|
+
import { HttpRequestResolverExtras, HttpHandler } from './handlers/HttpHandler.js';
|
|
3
|
+
import { PathParams, Path } from './utils/matching/matchRequestUrl.js';
|
|
4
|
+
import './typeUtils.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A namespace to intercept and mock HTTP requests.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* http.get('/user', resolver)
|
|
11
|
+
* http.post('/post/:id', resolver)
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://mswjs.io/docs/api/http `http` API reference}
|
|
14
|
+
*/
|
|
15
|
+
declare const http: {
|
|
16
|
+
all: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params>, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => HttpHandler;
|
|
17
|
+
head: <Params_1 extends PathParams<keyof Params_1> = PathParams, RequestBodyType_1 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_1 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_1>, RequestBodyType_1, ResponseBodyType_1>, options?: RequestHandlerOptions) => HttpHandler;
|
|
18
|
+
get: <Params_2 extends PathParams<keyof Params_2> = PathParams, RequestBodyType_2 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_2 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_2>, RequestBodyType_2, ResponseBodyType_2>, options?: RequestHandlerOptions) => HttpHandler;
|
|
19
|
+
post: <Params_3 extends PathParams<keyof Params_3> = PathParams, RequestBodyType_3 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_3 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_3>, RequestBodyType_3, ResponseBodyType_3>, options?: RequestHandlerOptions) => HttpHandler;
|
|
20
|
+
put: <Params_4 extends PathParams<keyof Params_4> = PathParams, RequestBodyType_4 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_4 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_4>, RequestBodyType_4, ResponseBodyType_4>, options?: RequestHandlerOptions) => HttpHandler;
|
|
21
|
+
delete: <Params_5 extends PathParams<keyof Params_5> = PathParams, RequestBodyType_5 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_5 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_5>, RequestBodyType_5, ResponseBodyType_5>, options?: RequestHandlerOptions) => HttpHandler;
|
|
22
|
+
patch: <Params_6 extends PathParams<keyof Params_6> = PathParams, RequestBodyType_6 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_6 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_6>, RequestBodyType_6, ResponseBodyType_6>, options?: RequestHandlerOptions) => HttpHandler;
|
|
23
|
+
options: <Params_7 extends PathParams<keyof Params_7> = PathParams, RequestBodyType_7 extends DefaultBodyType = DefaultBodyType, ResponseBodyType_7 extends DefaultBodyType = undefined>(path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<Params_7>, RequestBodyType_7, ResponseBodyType_7>, options?: RequestHandlerOptions) => HttpHandler;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { http };
|
package/lib/core/http.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var http_exports = {};
|
|
20
|
+
__export(http_exports, {
|
|
21
|
+
http: () => http
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(http_exports);
|
|
24
|
+
var import_HttpHandler = require("./handlers/HttpHandler.js");
|
|
25
|
+
function createHttpHandler(method) {
|
|
26
|
+
return (path, resolver, options = {}) => {
|
|
27
|
+
return new import_HttpHandler.HttpHandler(method, path, resolver, options);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const http = {
|
|
31
|
+
all: createHttpHandler(/.+/),
|
|
32
|
+
head: createHttpHandler(import_HttpHandler.HttpMethods.HEAD),
|
|
33
|
+
get: createHttpHandler(import_HttpHandler.HttpMethods.GET),
|
|
34
|
+
post: createHttpHandler(import_HttpHandler.HttpMethods.POST),
|
|
35
|
+
put: createHttpHandler(import_HttpHandler.HttpMethods.PUT),
|
|
36
|
+
delete: createHttpHandler(import_HttpHandler.HttpMethods.DELETE),
|
|
37
|
+
patch: createHttpHandler(import_HttpHandler.HttpMethods.PATCH),
|
|
38
|
+
options: createHttpHandler(import_HttpHandler.HttpMethods.OPTIONS)
|
|
39
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HttpMethods,
|
|
3
|
+
HttpHandler
|
|
4
|
+
} from './handlers/HttpHandler.mjs';
|
|
5
|
+
function createHttpHandler(method) {
|
|
6
|
+
return (path, resolver, options = {}) => {
|
|
7
|
+
return new HttpHandler(method, path, resolver, options);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const http = {
|
|
11
|
+
all: createHttpHandler(/.+/),
|
|
12
|
+
head: createHttpHandler(HttpMethods.HEAD),
|
|
13
|
+
get: createHttpHandler(HttpMethods.GET),
|
|
14
|
+
post: createHttpHandler(HttpMethods.POST),
|
|
15
|
+
put: createHttpHandler(HttpMethods.PUT),
|
|
16
|
+
delete: createHttpHandler(HttpMethods.DELETE),
|
|
17
|
+
patch: createHttpHandler(HttpMethods.PATCH),
|
|
18
|
+
options: createHttpHandler(HttpMethods.OPTIONS)
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
http
|
|
22
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_http = require("./http.js");
|
|
3
|
+
test("exports all REST API methods", () => {
|
|
4
|
+
expect(import_http.http).toBeDefined();
|
|
5
|
+
expect(Object.keys(import_http.http)).toEqual([
|
|
6
|
+
"all",
|
|
7
|
+
"head",
|
|
8
|
+
"get",
|
|
9
|
+
"post",
|
|
10
|
+
"put",
|
|
11
|
+
"delete",
|
|
12
|
+
"patch",
|
|
13
|
+
"options"
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { SetupApi } from './SetupApi.js';
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, f as HttpResponse, H as HttpResponseInit, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, e as StrictResponse } from './RequestHandler-1a5dbdc7.js';
|
|
3
|
+
export { http } from './http.js';
|
|
4
|
+
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
|
|
5
|
+
export { graphql } from './graphql.js';
|
|
6
|
+
export { G as GraphQLHandler, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, a as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-b42ca96f.js';
|
|
7
|
+
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
|
|
8
|
+
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
|
|
9
|
+
export { cleanUrl } from './utils/url/cleanUrl.js';
|
|
10
|
+
export { LifeCycleEventsMap, SharedOptions } from './sharedOptions.js';
|
|
11
|
+
export { DelayMode, MAX_SERVER_RESPONSE_TIME, MIN_SERVER_RESPONSE_TIME, NODE_SERVER_RESPONSE_TIME, SET_TIMEOUT_MAX_ALLOWED_INT, delay } from './delay.js';
|
|
12
|
+
export { bypass } from './bypass.js';
|
|
13
|
+
export { passthrough } from './passthrough.js';
|
|
14
|
+
import 'strict-event-emitter';
|
|
15
|
+
import './utils/internal/Disposable.js';
|
|
16
|
+
import './typeUtils.js';
|
|
17
|
+
import 'graphql';
|
|
18
|
+
import './utils/request/onUnhandledRequest.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var core_exports = {};
|
|
21
|
+
__export(core_exports, {
|
|
22
|
+
GraphQLHandler: () => import_GraphQLHandler.GraphQLHandler,
|
|
23
|
+
HttpHandler: () => import_HttpHandler.HttpHandler,
|
|
24
|
+
HttpMethods: () => import_HttpHandler.HttpMethods,
|
|
25
|
+
RequestHandler: () => import_RequestHandler.RequestHandler,
|
|
26
|
+
SetupApi: () => import_SetupApi.SetupApi,
|
|
27
|
+
bypass: () => import_bypass.bypass,
|
|
28
|
+
cleanUrl: () => import_cleanUrl.cleanUrl,
|
|
29
|
+
graphql: () => import_graphql.graphql,
|
|
30
|
+
http: () => import_http.http,
|
|
31
|
+
matchRequestUrl: () => import_matchRequestUrl.matchRequestUrl,
|
|
32
|
+
passthrough: () => import_passthrough.passthrough
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(core_exports);
|
|
35
|
+
var import_checkGlobals = require("./utils/internal/checkGlobals.js");
|
|
36
|
+
var import_SetupApi = require("./SetupApi.js");
|
|
37
|
+
var import_RequestHandler = require("./handlers/RequestHandler.js");
|
|
38
|
+
var import_http = require("./http.js");
|
|
39
|
+
var import_HttpHandler = require("./handlers/HttpHandler.js");
|
|
40
|
+
var import_graphql = require("./graphql.js");
|
|
41
|
+
var import_GraphQLHandler = require("./handlers/GraphQLHandler.js");
|
|
42
|
+
var import_matchRequestUrl = require("./utils/matching/matchRequestUrl.js");
|
|
43
|
+
__reExport(core_exports, require("./utils/handleRequest.js"), module.exports);
|
|
44
|
+
var import_cleanUrl = require("./utils/url/cleanUrl.js");
|
|
45
|
+
__reExport(core_exports, require("./HttpResponse.js"), module.exports);
|
|
46
|
+
__reExport(core_exports, require("./delay.js"), module.exports);
|
|
47
|
+
var import_bypass = require("./bypass.js");
|
|
48
|
+
var import_passthrough = require("./passthrough.js");
|
|
49
|
+
(0, import_checkGlobals.checkGlobals)();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { checkGlobals } from './utils/internal/checkGlobals.mjs';
|
|
2
|
+
import { SetupApi } from './SetupApi.mjs';
|
|
3
|
+
import { RequestHandler } from './handlers/RequestHandler.mjs';
|
|
4
|
+
import { http } from './http.mjs';
|
|
5
|
+
import { HttpHandler, HttpMethods } from './handlers/HttpHandler.mjs';
|
|
6
|
+
import { graphql } from './graphql.mjs';
|
|
7
|
+
import { GraphQLHandler } from './handlers/GraphQLHandler.mjs';
|
|
8
|
+
import { matchRequestUrl } from './utils/matching/matchRequestUrl.mjs';
|
|
9
|
+
export * from './utils/handleRequest.mjs';
|
|
10
|
+
import { cleanUrl } from './utils/url/cleanUrl.mjs';
|
|
11
|
+
export * from './HttpResponse.mjs';
|
|
12
|
+
export * from './delay.mjs';
|
|
13
|
+
import { bypass } from './bypass.mjs';
|
|
14
|
+
import { passthrough } from './passthrough.mjs';
|
|
15
|
+
checkGlobals();
|
|
16
|
+
export {
|
|
17
|
+
GraphQLHandler,
|
|
18
|
+
HttpHandler,
|
|
19
|
+
HttpMethods,
|
|
20
|
+
RequestHandler,
|
|
21
|
+
SetupApi,
|
|
22
|
+
bypass,
|
|
23
|
+
cleanUrl,
|
|
24
|
+
graphql,
|
|
25
|
+
http,
|
|
26
|
+
matchRequestUrl,
|
|
27
|
+
passthrough
|
|
28
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs the intercepted request as-is.
|
|
3
|
+
*
|
|
4
|
+
* This stops request handler lookup so no other handlers
|
|
5
|
+
* can affect this request past this point.
|
|
6
|
+
* Unlike `bypass()`, this will not trigger an additional request.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* http.get('/resource', () => {
|
|
10
|
+
* return passthrough()
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://mswjs.io/docs/api/passthrough `passthrough()` API reference}
|
|
14
|
+
*/
|
|
15
|
+
declare function passthrough(): Response;
|
|
16
|
+
|
|
17
|
+
export { passthrough };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var passthrough_exports = {};
|
|
20
|
+
__export(passthrough_exports, {
|
|
21
|
+
passthrough: () => passthrough
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(passthrough_exports);
|
|
24
|
+
function passthrough() {
|
|
25
|
+
return new Response(null, {
|
|
26
|
+
status: 302,
|
|
27
|
+
statusText: "Passthrough",
|
|
28
|
+
headers: {
|
|
29
|
+
"x-msw-intention": "passthrough"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Emitter } from 'strict-event-emitter';
|
|
2
|
+
import { UnhandledRequestStrategy } from './utils/request/onUnhandledRequest.js';
|
|
3
|
+
import './RequestHandler-1a5dbdc7.js';
|
|
4
|
+
import './typeUtils.js';
|
|
5
|
+
|
|
6
|
+
interface SharedOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Specifies how to react to a request that has no corresponding
|
|
9
|
+
* request handler. Warns on unhandled requests by default.
|
|
10
|
+
*
|
|
11
|
+
* @example worker.start({ onUnhandledRequest: 'bypass' })
|
|
12
|
+
* @example worker.start({ onUnhandledRequest: 'warn' })
|
|
13
|
+
* @example server.listen({ onUnhandledRequest: 'error' })
|
|
14
|
+
*/
|
|
15
|
+
onUnhandledRequest?: UnhandledRequestStrategy;
|
|
16
|
+
}
|
|
17
|
+
type LifeCycleEventsMap = {
|
|
18
|
+
'request:start': [
|
|
19
|
+
args: {
|
|
20
|
+
request: Request;
|
|
21
|
+
requestId: string;
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
'request:match': [
|
|
25
|
+
args: {
|
|
26
|
+
request: Request;
|
|
27
|
+
requestId: string;
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
'request:unhandled': [
|
|
31
|
+
args: {
|
|
32
|
+
request: Request;
|
|
33
|
+
requestId: string;
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
'request:end': [
|
|
37
|
+
args: {
|
|
38
|
+
request: Request;
|
|
39
|
+
requestId: string;
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
'response:mocked': [
|
|
43
|
+
args: {
|
|
44
|
+
response: Response;
|
|
45
|
+
request: Request;
|
|
46
|
+
requestId: string;
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
'response:bypass': [
|
|
50
|
+
args: {
|
|
51
|
+
response: Response;
|
|
52
|
+
request: Request;
|
|
53
|
+
requestId: string;
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
unhandledException: [
|
|
57
|
+
args: {
|
|
58
|
+
error: Error;
|
|
59
|
+
request: Request;
|
|
60
|
+
requestId: string;
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
};
|
|
64
|
+
type LifeCycleEventEmitter<EventsMap extends Record<string | symbol, any>> = Pick<Emitter<EventsMap>, 'on' | 'removeListener' | 'removeAllListeners'>;
|
|
65
|
+
|
|
66
|
+
export { LifeCycleEventEmitter, LifeCycleEventsMap, SharedOptions };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var sharedOptions_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(sharedOptions_exports);
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Fn = (...arg: any[]) => any;
|
|
2
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
type RequiredDeep<Type, U extends Record<string, unknown> | Fn | undefined = undefined> = Type extends Fn ? Type : Type extends Record<string, any> ? {
|
|
4
|
+
[Key in keyof Type]-?: NonNullable<Type[Key]> extends NonNullable<U> ? NonNullable<Type[Key]> : RequiredDeep<NonNullable<Type[Key]>, U>;
|
|
5
|
+
} : Type;
|
|
6
|
+
|
|
7
|
+
export { MaybePromise, RequiredDeep };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var typeUtils_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(typeUtils_exports);
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { H as HttpResponseInit } from '../../RequestHandler-1a5dbdc7.js';
|
|
2
|
+
import '../../typeUtils.js';
|
|
3
|
+
|
|
4
|
+
interface HttpResponseDecoratedInit extends HttpResponseInit {
|
|
5
|
+
status: number;
|
|
6
|
+
statusText: string;
|
|
7
|
+
headers: Headers;
|
|
8
|
+
}
|
|
9
|
+
declare function normalizeResponseInit(init?: HttpResponseInit): HttpResponseDecoratedInit;
|
|
10
|
+
declare function decorateResponse(response: Response, init: HttpResponseDecoratedInit): Response;
|
|
11
|
+
|
|
12
|
+
export { HttpResponseDecoratedInit, decorateResponse, normalizeResponseInit };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var decorators_exports = {};
|
|
47
|
+
__export(decorators_exports, {
|
|
48
|
+
decorateResponse: () => decorateResponse,
|
|
49
|
+
normalizeResponseInit: () => normalizeResponseInit
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(decorators_exports);
|
|
52
|
+
var import_statuses = __toESM(require("@bundled-es-modules/statuses"));
|
|
53
|
+
const { message } = import_statuses.default;
|
|
54
|
+
function normalizeResponseInit(init = {}) {
|
|
55
|
+
const status = (init == null ? void 0 : init.status) || 200;
|
|
56
|
+
const statusText = (init == null ? void 0 : init.statusText) || message[status] || "";
|
|
57
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
58
|
+
return __spreadProps(__spreadValues({}, init), {
|
|
59
|
+
headers,
|
|
60
|
+
status,
|
|
61
|
+
statusText
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function decorateResponse(response, init) {
|
|
65
|
+
var _a;
|
|
66
|
+
if (init.type) {
|
|
67
|
+
Object.defineProperty(response, "type", {
|
|
68
|
+
value: init.type,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
writable: false
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (typeof document !== "undefined") {
|
|
74
|
+
const responseCookies = ((_a = init.headers.get("Set-Cookie")) == null ? void 0 : _a.split(",")) || [];
|
|
75
|
+
for (const cookieString of responseCookies) {
|
|
76
|
+
document.cookie = cookieString;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
}
|