@wevu/web-apis 1.3.6 → 1.4.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 +36 -8
- package/dist/abort.d.mts +2 -4
- package/dist/abort.mjs +2 -3
- package/dist/eventsource-DUCc1iHv.d.mts +82 -0
- package/dist/eventsource-ojngrwBI.mjs +340 -0
- package/dist/eventsource.d.mts +2 -0
- package/dist/eventsource.mjs +2 -0
- package/dist/fetch-CQoQx3mz.mjs +301 -0
- package/dist/fetch-CSESA-oq.d.mts +33 -0
- package/dist/fetch.d.mts +2 -35
- package/dist/fetch.mjs +1 -188
- package/dist/http-DCCqK1QL.mjs +505 -0
- package/dist/{http-CE8-CIHE.d.mts → http-Dd6YCSHK.d.mts} +6 -14
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +19 -54
- package/dist/index.mjs +35 -104
- package/dist/networkDefaults.d.mts +1 -3
- package/dist/networkDefaults.mjs +1 -2
- package/dist/{shared-BI8xrWqd.mjs → shared-CARmZrDA.mjs} +5 -9
- package/dist/{shared-Dc42USJC.d.mts → shared-DfU0oEwy.d.mts} +0 -2
- package/dist/shared.d.mts +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/streams-6m8eQfZM.mjs +84 -0
- package/dist/streams.d.mts +31 -0
- package/dist/streams.mjs +1 -0
- package/dist/textCodec-muWByCAW.mjs +132 -0
- package/dist/{url-D0ANYIyk.d.mts → url-CEgyUgm2.d.mts} +0 -2
- package/dist/{url-CBepYY5Q.mjs → url-DjMmeEth.mjs} +2 -4
- package/dist/url.d.mts +1 -1
- package/dist/url.mjs +1 -1
- package/dist/{web-DRnPgdkX.mjs → web-DDzJNeV3.mjs} +6 -8
- package/dist/{web-DNBBg6y9.d.mts → web-DjLufM4u.d.mts} +1 -7
- package/dist/web.d.mts +1 -1
- package/dist/web.mjs +1 -1
- package/dist/websocket.d.mts +2 -4
- package/dist/websocket.mjs +4 -5
- package/dist/xhr.d.mts +1 -3
- package/dist/xhr.mjs +4 -5
- package/package.json +17 -5
- package/dist/http-DFOOhYXD.mjs +0 -303
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as RequestGlobalsBlobLike } from "./shared-
|
|
2
|
-
//#region src/web/blob.d.ts
|
|
1
|
+
import { t as RequestGlobalsBlobLike } from "./shared-DfU0oEwy.mjs";
|
|
3
2
|
type BlobLikePart = RequestGlobalsBlobLike;
|
|
4
3
|
type BlobPart = ArrayBuffer | ArrayBufferView | BlobLikePart | string;
|
|
5
4
|
interface BlobPropertyBag {
|
|
@@ -15,8 +14,6 @@ declare class BlobPolyfill {
|
|
|
15
14
|
slice(start?: number, end?: number, contentType?: string): BlobPolyfill;
|
|
16
15
|
get [Symbol.toStringTag](): string;
|
|
17
16
|
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/web/file.d.ts
|
|
20
17
|
interface FilePropertyBag extends BlobPropertyBag {
|
|
21
18
|
lastModified?: number;
|
|
22
19
|
}
|
|
@@ -27,8 +24,6 @@ declare class FilePolyfill extends BlobPolyfill {
|
|
|
27
24
|
get name(): string;
|
|
28
25
|
get [Symbol.toStringTag](): string;
|
|
29
26
|
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/web/formData.d.ts
|
|
32
27
|
type FormDataEntryValue = FilePolyfill | BlobPolyfill | string;
|
|
33
28
|
declare class FormDataPolyfill {
|
|
34
29
|
private readonly entriesList;
|
|
@@ -47,5 +42,4 @@ declare class FormDataPolyfill {
|
|
|
47
42
|
[Symbol.iterator](): Generator<[string, FormDataEntryValue], void, unknown>;
|
|
48
43
|
get [Symbol.toStringTag](): string;
|
|
49
44
|
}
|
|
50
|
-
//#endregion
|
|
51
45
|
export { BlobPart as a, BlobLikePart as i, FormDataPolyfill as n, BlobPolyfill as o, FilePolyfill as r, FormDataEntryValue as t };
|
package/dist/web.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as BlobPart, i as BlobLikePart, n as FormDataPolyfill, o as BlobPolyfill, r as FilePolyfill, t as FormDataEntryValue } from "./web-
|
|
1
|
+
import { a as BlobPart, i as BlobLikePart, n as FormDataPolyfill, o as BlobPolyfill, r as FilePolyfill, t as FormDataEntryValue } from "./web-DjLufM4u.mjs";
|
|
2
2
|
export { type BlobLikePart, type BlobPart, BlobPolyfill, FilePolyfill, type FormDataEntryValue, FormDataPolyfill };
|
package/dist/web.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { r as BlobPolyfill, n as FilePolyfill, t as FormDataPolyfill } from "./web-
|
|
1
|
+
export { r as BlobPolyfill, n as FilePolyfill, t as FormDataPolyfill } from "./web-DDzJNeV3.mjs";
|
package/dist/websocket.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { i as RequestGlobalsEventTarget, t as RequestGlobalsBlobLike } from "./shared-
|
|
1
|
+
import { i as RequestGlobalsEventTarget, t as RequestGlobalsBlobLike } from "./shared-DfU0oEwy.mjs";
|
|
2
2
|
import { WebSocketMiniProgramOptions } from "./networkDefaults.mjs";
|
|
3
|
-
import { o as BlobPolyfill } from "./web-
|
|
4
|
-
//#region src/websocket.d.ts
|
|
3
|
+
import { o as BlobPolyfill } from "./web-DjLufM4u.mjs";
|
|
5
4
|
type WebSocketBinaryType = 'blob' | 'arraybuffer';
|
|
6
5
|
type WebSocketSendData = string | ArrayBuffer | ArrayBufferView | Blob | RequestGlobalsBlobLike;
|
|
7
6
|
type WebSocketMessageData = string | ArrayBuffer | Blob | BlobPolyfill;
|
|
@@ -54,5 +53,4 @@ export declare class WebSocketPolyfill extends RequestGlobalsEventTarget {
|
|
|
54
53
|
private closeFromRuntime;
|
|
55
54
|
private emitError;
|
|
56
55
|
}
|
|
57
|
-
//#endregion
|
|
58
56
|
export {};
|
package/dist/websocket.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { _ as resolveUrlConstructor$1, g as resolveTextEncoderConstructor, l as isArrayBufferLike, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-
|
|
2
|
-
import { t as URLPolyfill } from "./url-
|
|
3
|
-
import { r as BlobPolyfill } from "./web-
|
|
1
|
+
import { _ as resolveUrlConstructor$1, g as resolveTextEncoderConstructor, l as isArrayBufferLike, n as cloneArrayBuffer, r as cloneArrayBufferView, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-CARmZrDA.mjs";
|
|
2
|
+
import { t as URLPolyfill } from "./url-DjMmeEth.mjs";
|
|
3
|
+
import { r as BlobPolyfill } from "./web-DDzJNeV3.mjs";
|
|
4
4
|
import { resolveWebSocketMiniProgramOptions } from "./networkDefaults.mjs";
|
|
5
5
|
import { wpi } from "@wevu/api";
|
|
6
|
-
|
|
6
|
+
// src/websocket.ts
|
|
7
7
|
const WHITESPACE_RE = /\s/u;
|
|
8
8
|
function isValidProtocol(protocol) {
|
|
9
9
|
return [...protocol].every((char) => {
|
|
@@ -203,5 +203,4 @@ var WebSocketPolyfill = class WebSocketPolyfill extends RequestGlobalsEventTarge
|
|
|
203
203
|
this.dispatchEvent(createErrorEvent(error));
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
//#endregion
|
|
207
206
|
export { WebSocketPolyfill };
|
package/dist/xhr.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { i as RequestGlobalsEventTarget } from "./shared-
|
|
1
|
+
import { i as RequestGlobalsEventTarget } from "./shared-DfU0oEwy.mjs";
|
|
2
2
|
import { RequestGlobalsMiniProgramOptions } from "./networkDefaults.mjs";
|
|
3
|
-
//#region src/xhr.d.ts
|
|
4
3
|
type XhrBody = Document | XMLHttpRequestBodyInit | null | undefined;
|
|
5
4
|
export declare class XMLHttpRequestUploadPolyfill extends RequestGlobalsEventTarget {}
|
|
6
5
|
export declare class XMLHttpRequestPolyfill extends RequestGlobalsEventTarget {
|
|
@@ -65,5 +64,4 @@ export declare class XMLHttpRequestPolyfill extends RequestGlobalsEventTarget {
|
|
|
65
64
|
private finish;
|
|
66
65
|
private transitionTo;
|
|
67
66
|
}
|
|
68
|
-
//#endregion
|
|
69
67
|
export {};
|
package/dist/xhr.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { f as resolveRequestGlobalsHost, t as RequestGlobalsEventTarget } from "./shared-
|
|
1
|
+
import { f as resolveRequestGlobalsHost, t as RequestGlobalsEventTarget } from "./shared-CARmZrDA.mjs";
|
|
2
2
|
import { AbortControllerPolyfill } from "./abort.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { fetch } from "./fetch.mjs";
|
|
5
|
-
|
|
3
|
+
import { d as headersToObject, u as HeadersPolyfill } from "./http-DCCqK1QL.mjs";
|
|
4
|
+
import { t as fetch } from "./fetch-CQoQx3mz.mjs";
|
|
5
|
+
// src/xhr.ts
|
|
6
6
|
function createProgressEvent(type) {
|
|
7
7
|
return {
|
|
8
8
|
type,
|
|
@@ -159,5 +159,4 @@ var XMLHttpRequestPolyfill = class XMLHttpRequestPolyfill extends RequestGlobals
|
|
|
159
159
|
this.dispatchEvent({ type: "readystatechange" });
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
|
-
//#endregion
|
|
163
162
|
export { XMLHttpRequestPolyfill, XMLHttpRequestUploadPolyfill };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/web-apis",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "Web API polyfills and global installers for mini-program runtimes",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -67,6 +67,14 @@
|
|
|
67
67
|
"./xhr": {
|
|
68
68
|
"types": "./dist/xhr.d.mts",
|
|
69
69
|
"import": "./dist/xhr.mjs"
|
|
70
|
+
},
|
|
71
|
+
"./streams": {
|
|
72
|
+
"types": "./dist/streams.d.mts",
|
|
73
|
+
"import": "./dist/streams.mjs"
|
|
74
|
+
},
|
|
75
|
+
"./eventsource": {
|
|
76
|
+
"types": "./dist/eventsource.d.mts",
|
|
77
|
+
"import": "./dist/eventsource.mjs"
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
80
|
"main": "./dist/index.mjs",
|
|
@@ -76,12 +84,13 @@
|
|
|
76
84
|
"dist"
|
|
77
85
|
],
|
|
78
86
|
"engines": {
|
|
79
|
-
"node": "^
|
|
87
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
80
88
|
},
|
|
81
89
|
"dependencies": {
|
|
82
|
-
"@weapp-core/api": "0.
|
|
83
|
-
"@weapp-core/constants": "0.
|
|
84
|
-
"@wevu/api": "0.
|
|
90
|
+
"@weapp-core/api": "0.4.0",
|
|
91
|
+
"@weapp-core/constants": "0.5.0",
|
|
92
|
+
"@wevu/api": "0.4.0",
|
|
93
|
+
"web-streams-polyfill": "4.3.0"
|
|
85
94
|
},
|
|
86
95
|
"publishConfig": {
|
|
87
96
|
"access": "public",
|
|
@@ -94,6 +103,9 @@
|
|
|
94
103
|
"paths": {}
|
|
95
104
|
}
|
|
96
105
|
},
|
|
106
|
+
"devDependencies": {
|
|
107
|
+
"eventsource-parser": "3.1.1"
|
|
108
|
+
},
|
|
97
109
|
"scripts": {
|
|
98
110
|
"dev": "tsdown -w --sourcemap",
|
|
99
111
|
"build": "tsdown",
|
package/dist/http-DFOOhYXD.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, i as decodeText, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-BI8xrWqd.mjs";
|
|
2
|
-
import { r as BlobPolyfill, t as FormDataPolyfill } from "./web-DRnPgdkX.mjs";
|
|
3
|
-
//#region src/http/headers.ts
|
|
4
|
-
const SET_COOKIE_HEADER_NAME = "set-cookie";
|
|
5
|
-
function isIterableHeaders(input) {
|
|
6
|
-
return Boolean(input) && typeof input[Symbol.iterator] === "function";
|
|
7
|
-
}
|
|
8
|
-
function isHeaderObject(input) {
|
|
9
|
-
return typeof input === "object" && input !== null;
|
|
10
|
-
}
|
|
11
|
-
var HeadersPolyfill = class {
|
|
12
|
-
store = /* @__PURE__ */ new Map();
|
|
13
|
-
constructor(init) {
|
|
14
|
-
if (!init) return;
|
|
15
|
-
if (isIterableHeaders(init)) {
|
|
16
|
-
for (const [key, value] of init) this.append(key, value);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (typeof init.forEach === "function") {
|
|
20
|
-
init.forEach((value, key) => {
|
|
21
|
-
this.set(key, value);
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (isHeaderObject(init)) for (const [key, value] of Object.entries(init)) this.append(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
26
|
-
}
|
|
27
|
-
append(key, value) {
|
|
28
|
-
const normalized = normalizeHeaderName(key);
|
|
29
|
-
if (!normalized) return;
|
|
30
|
-
const item = this.store.get(normalized);
|
|
31
|
-
if (item) {
|
|
32
|
-
item.values.push(String(value));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.store.set(normalized, {
|
|
36
|
-
key,
|
|
37
|
-
values: [String(value)]
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
set(key, value) {
|
|
41
|
-
const normalized = normalizeHeaderName(key);
|
|
42
|
-
if (!normalized) return;
|
|
43
|
-
this.store.set(normalized, {
|
|
44
|
-
key,
|
|
45
|
-
values: [String(value)]
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
get(key) {
|
|
49
|
-
return this.store.get(normalizeHeaderName(key))?.values.join(", ") ?? null;
|
|
50
|
-
}
|
|
51
|
-
getSetCookie() {
|
|
52
|
-
return this.store.get(SET_COOKIE_HEADER_NAME)?.values.slice() ?? [];
|
|
53
|
-
}
|
|
54
|
-
has(key) {
|
|
55
|
-
return this.store.has(normalizeHeaderName(key));
|
|
56
|
-
}
|
|
57
|
-
delete(key) {
|
|
58
|
-
this.store.delete(normalizeHeaderName(key));
|
|
59
|
-
}
|
|
60
|
-
forEach(callback, thisArg) {
|
|
61
|
-
for (const { key, values } of this.store.values()) callback.call(thisArg, values.join(", "), key, this);
|
|
62
|
-
}
|
|
63
|
-
entries() {
|
|
64
|
-
return Array.from(this.store.values(), (item) => [item.key, item.values.join(", ")])[Symbol.iterator]();
|
|
65
|
-
}
|
|
66
|
-
keys() {
|
|
67
|
-
return Array.from(this.store.values(), (item) => item.key)[Symbol.iterator]();
|
|
68
|
-
}
|
|
69
|
-
values() {
|
|
70
|
-
return Array.from(this.store.values(), (item) => item.values.join(", "))[Symbol.iterator]();
|
|
71
|
-
}
|
|
72
|
-
[Symbol.iterator]() {
|
|
73
|
-
return this.entries();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
function headersToObject(headers) {
|
|
77
|
-
const result = {};
|
|
78
|
-
headers.forEach((value, key) => {
|
|
79
|
-
result[key] = value;
|
|
80
|
-
});
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/multipart.ts
|
|
85
|
-
const CRLF = "\r\n";
|
|
86
|
-
function createMultipartBoundary() {
|
|
87
|
-
return `----weapp-vite-formdata-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
88
|
-
}
|
|
89
|
-
function escapeMultipartName(value) {
|
|
90
|
-
return String(value).replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
91
|
-
}
|
|
92
|
-
function concatArrayBuffers(buffers) {
|
|
93
|
-
const totalLength = buffers.reduce((sum, buffer) => sum + buffer.byteLength, 0);
|
|
94
|
-
const merged = new Uint8Array(totalLength);
|
|
95
|
-
let offset = 0;
|
|
96
|
-
for (const buffer of buffers) {
|
|
97
|
-
merged.set(new Uint8Array(buffer), offset);
|
|
98
|
-
offset += buffer.byteLength;
|
|
99
|
-
}
|
|
100
|
-
return merged.buffer;
|
|
101
|
-
}
|
|
102
|
-
function isBlobFormDataValue(value) {
|
|
103
|
-
return typeof value !== "string" && typeof value?.arrayBuffer === "function";
|
|
104
|
-
}
|
|
105
|
-
function getMultipartFilename(value) {
|
|
106
|
-
const name = value.name;
|
|
107
|
-
return typeof name === "string" && name.length > 0 ? name : "blob";
|
|
108
|
-
}
|
|
109
|
-
async function createMultipartPart(name, value) {
|
|
110
|
-
if (!isBlobFormDataValue(value)) return [
|
|
111
|
-
encodeText(`Content-Disposition: form-data; name="${escapeMultipartName(name)}"${CRLF}${CRLF}`),
|
|
112
|
-
encodeText(String(value)),
|
|
113
|
-
encodeText(CRLF)
|
|
114
|
-
];
|
|
115
|
-
const filename = getMultipartFilename(value);
|
|
116
|
-
const headers = [
|
|
117
|
-
`Content-Disposition: form-data; name="${escapeMultipartName(name)}"; filename="${escapeMultipartName(filename)}"`,
|
|
118
|
-
`Content-Type: ${value.type || "application/octet-stream"}`,
|
|
119
|
-
"",
|
|
120
|
-
""
|
|
121
|
-
].join(CRLF);
|
|
122
|
-
return [
|
|
123
|
-
encodeText(headers),
|
|
124
|
-
await value.arrayBuffer(),
|
|
125
|
-
encodeText(CRLF)
|
|
126
|
-
];
|
|
127
|
-
}
|
|
128
|
-
async function encodeMultipartFormData(formData) {
|
|
129
|
-
const boundary = createMultipartBoundary();
|
|
130
|
-
const buffers = [];
|
|
131
|
-
for (const [name, value] of formData) {
|
|
132
|
-
buffers.push(encodeText(`--${boundary}${CRLF}`));
|
|
133
|
-
buffers.push(...await createMultipartPart(name, value));
|
|
134
|
-
}
|
|
135
|
-
buffers.push(encodeText(`--${boundary}--${CRLF}`));
|
|
136
|
-
return {
|
|
137
|
-
body: concatArrayBuffers(buffers),
|
|
138
|
-
contentType: `multipart/form-data; boundary=${boundary}`
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/http/body.ts
|
|
143
|
-
const bodies = /* @__PURE__ */ new WeakMap();
|
|
144
|
-
function isFormData(value) {
|
|
145
|
-
return value instanceof FormDataPolyfill || typeof FormData === "function" && value instanceof FormData;
|
|
146
|
-
}
|
|
147
|
-
function initializeBody(owner, input) {
|
|
148
|
-
let value;
|
|
149
|
-
let contentType = "";
|
|
150
|
-
if (input == null) value = null;
|
|
151
|
-
else if (isArrayBufferLike(input)) value = cloneArrayBuffer(input);
|
|
152
|
-
else if (ArrayBuffer.isView(input)) value = cloneArrayBufferView(input);
|
|
153
|
-
else if (isBlobLike(input)) {
|
|
154
|
-
value = input;
|
|
155
|
-
contentType = input.type ?? "";
|
|
156
|
-
} else if (isFormData(input)) value = input;
|
|
157
|
-
else if (isUrlSearchParamsInstance(input)) {
|
|
158
|
-
value = input.toString();
|
|
159
|
-
contentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
|
160
|
-
} else {
|
|
161
|
-
value = String(input);
|
|
162
|
-
contentType = "text/plain;charset=UTF-8";
|
|
163
|
-
}
|
|
164
|
-
if (contentType && !owner.headers.has("content-type")) owner.headers.set("content-type", contentType);
|
|
165
|
-
bodies.set(owner, {
|
|
166
|
-
value,
|
|
167
|
-
used: false
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function getBodyValue(owner) {
|
|
171
|
-
return bodies.get(owner)?.value;
|
|
172
|
-
}
|
|
173
|
-
function assertBodyUnused(owner) {
|
|
174
|
-
if (bodies.get(owner)?.used) throw new TypeError("Body has already been consumed");
|
|
175
|
-
}
|
|
176
|
-
/** 在异步转换之前同步占用 body,确保并发读取与请求发送共享消费状态。 */
|
|
177
|
-
function consumeBodyValue(owner) {
|
|
178
|
-
assertBodyUnused(owner);
|
|
179
|
-
const state = bodies.get(owner);
|
|
180
|
-
if (state && state.value != null) state.used = true;
|
|
181
|
-
return state?.value;
|
|
182
|
-
}
|
|
183
|
-
async function bodyBytes(value) {
|
|
184
|
-
if (value == null) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
185
|
-
if (typeof value === "string") return encodeText(value);
|
|
186
|
-
if (isArrayBufferLike(value)) return cloneArrayBuffer(value);
|
|
187
|
-
if (ArrayBuffer.isView(value)) return cloneArrayBufferView(value);
|
|
188
|
-
if (isBlobLike(value)) return cloneArrayBuffer(await value.arrayBuffer());
|
|
189
|
-
return (await encodeMultipartFormData(value)).body;
|
|
190
|
-
}
|
|
191
|
-
/** 仅供 Request/Response 内部复用,不作为包的公开导出。 */
|
|
192
|
-
var HttpBody = class {
|
|
193
|
-
get body() {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
get bodyUsed() {
|
|
197
|
-
return bodies.get(this)?.used === true;
|
|
198
|
-
}
|
|
199
|
-
async arrayBuffer() {
|
|
200
|
-
return bodyBytes(consumeBodyValue(this));
|
|
201
|
-
}
|
|
202
|
-
async bytes() {
|
|
203
|
-
return new Uint8Array(await this.arrayBuffer());
|
|
204
|
-
}
|
|
205
|
-
async text() {
|
|
206
|
-
return decodeText(await this.arrayBuffer());
|
|
207
|
-
}
|
|
208
|
-
async json() {
|
|
209
|
-
return JSON.parse(await this.text());
|
|
210
|
-
}
|
|
211
|
-
async blob() {
|
|
212
|
-
const bytes = await this.arrayBuffer();
|
|
213
|
-
const contentType = this.headers.get("content-type") ?? "";
|
|
214
|
-
const type = /^[!#$%&'*+.^`|~\w-]+\/[!#$%&'*+.^`|~\w-]+(?:\s*;[^\r\n]*)?$/.test(contentType) ? contentType : "";
|
|
215
|
-
return new (typeof Blob === "function" ? Blob : BlobPolyfill)([bytes], { type });
|
|
216
|
-
}
|
|
217
|
-
async formData() {
|
|
218
|
-
throw new TypeError("formData is not supported in Body polyfill");
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/http/request.ts
|
|
223
|
-
var RequestPolyfill = class RequestPolyfill extends HttpBody {
|
|
224
|
-
url;
|
|
225
|
-
method;
|
|
226
|
-
headers;
|
|
227
|
-
signal;
|
|
228
|
-
[Symbol.toStringTag] = "Request";
|
|
229
|
-
constructor(input, init = {}) {
|
|
230
|
-
super();
|
|
231
|
-
const request = input instanceof RequestPolyfill ? input : void 0;
|
|
232
|
-
this.url = typeof input === "string" ? input : isUrlInstance(input) ? input.toString() : request?.url ?? "";
|
|
233
|
-
this.method = String(init.method ?? request?.method ?? "GET").toUpperCase();
|
|
234
|
-
this.headers = new HeadersPolyfill(init.headers ?? request?.headers);
|
|
235
|
-
this.signal = init.signal ?? request?.signal ?? null;
|
|
236
|
-
const inherited = init.body == null && request;
|
|
237
|
-
if (inherited) assertBodyUnused(request);
|
|
238
|
-
initializeBody(this, init.body ?? (request ? getBodyValue(request) : void 0));
|
|
239
|
-
if (inherited) consumeBodyValue(request);
|
|
240
|
-
}
|
|
241
|
-
clone() {
|
|
242
|
-
assertBodyUnused(this);
|
|
243
|
-
return new RequestPolyfill(this.url, {
|
|
244
|
-
method: this.method,
|
|
245
|
-
headers: this.headers,
|
|
246
|
-
signal: this.signal,
|
|
247
|
-
body: getBodyValue(this)
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
function getRequestBodyValue(request) {
|
|
252
|
-
return request ? getBodyValue(request) : void 0;
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/http/response.ts
|
|
256
|
-
var ResponsePolyfill = class ResponsePolyfill extends HttpBody {
|
|
257
|
-
headers;
|
|
258
|
-
status;
|
|
259
|
-
statusText;
|
|
260
|
-
ok;
|
|
261
|
-
url;
|
|
262
|
-
redirected = false;
|
|
263
|
-
type;
|
|
264
|
-
[Symbol.toStringTag] = "Response";
|
|
265
|
-
constructor(body, init = {}) {
|
|
266
|
-
super();
|
|
267
|
-
this.status = Number.isFinite(init.status) ? init.status : 200;
|
|
268
|
-
this.statusText = init.statusText ?? "";
|
|
269
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
270
|
-
this.headers = new HeadersPolyfill(init.headers);
|
|
271
|
-
this.url = init.url ?? "";
|
|
272
|
-
this.type = init.type ?? "basic";
|
|
273
|
-
initializeBody(this, body);
|
|
274
|
-
}
|
|
275
|
-
static error() {
|
|
276
|
-
return new ResponsePolyfill(null, {
|
|
277
|
-
status: 0,
|
|
278
|
-
type: "error"
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
static json(data, init = {}) {
|
|
282
|
-
const body = JSON.stringify(data);
|
|
283
|
-
if (body === void 0) throw new TypeError("Failed to execute 'json' on 'Response': data is not JSON serializable");
|
|
284
|
-
const headers = new HeadersPolyfill(init.headers);
|
|
285
|
-
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
286
|
-
return new ResponsePolyfill(body, {
|
|
287
|
-
...init,
|
|
288
|
-
headers
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
clone() {
|
|
292
|
-
assertBodyUnused(this);
|
|
293
|
-
return new ResponsePolyfill(getBodyValue(this), {
|
|
294
|
-
status: this.status,
|
|
295
|
-
statusText: this.statusText,
|
|
296
|
-
headers: this.headers,
|
|
297
|
-
url: this.url,
|
|
298
|
-
type: this.type
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
//#endregion
|
|
303
|
-
export { encodeMultipartFormData as a, consumeBodyValue as i, RequestPolyfill as n, HeadersPolyfill as o, getRequestBodyValue as r, headersToObject as s, ResponsePolyfill as t };
|