@wevu/web-apis 1.2.21 → 1.2.23
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/dist/abort.mjs +1 -1
- package/dist/{fetch-CETKuRWs.mjs → fetch-CKch4mSy.mjs} +6 -5
- package/dist/fetch.mjs +1 -1
- package/dist/http.d.mts +5 -2
- package/dist/http.mjs +9 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +5 -9
- package/dist/{shared-B_5_ZEFl.mjs → shared-C4EOQbWG.mjs} +11 -2
- package/dist/shared.d.mts +8 -1
- package/dist/shared.mjs +2 -2
- package/dist/web.d.mts +3 -5
- package/dist/web.mjs +4 -4
- package/dist/websocket.d.mts +2 -2
- package/dist/websocket.mjs +4 -4
- package/dist/xhr.mjs +2 -2
- package/package.json +1 -1
package/dist/abort.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HeadersPolyfill, ResponsePolyfill } from "./http.mjs";
|
|
3
|
-
import { resolveRequestMiniProgramOptions } from "./networkDefaults.mjs";
|
|
1
|
+
import { d as normalizeHeaderName, h as isUrlSearchParamsInstance, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-C4EOQbWG.mjs";
|
|
4
2
|
import { FormDataPolyfill } from "./web.mjs";
|
|
3
|
+
import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, getRequestBodyValue } from "./http.mjs";
|
|
4
|
+
import { resolveRequestMiniProgramOptions } from "./networkDefaults.mjs";
|
|
5
5
|
import { wpi } from "@wevu/api";
|
|
6
6
|
//#region src/multipart.ts
|
|
7
7
|
const CRLF = "\r\n";
|
|
@@ -135,6 +135,7 @@ function isFormDataInstance(value) {
|
|
|
135
135
|
async function extractRequestBodyFromInput(input) {
|
|
136
136
|
if (!input || typeof input.clone !== "function") return;
|
|
137
137
|
if (input.bodyUsed) throw new TypeError("Failed to execute fetch: request body is already used");
|
|
138
|
+
if (input instanceof RequestPolyfill) return getRequestBodyValue(input);
|
|
138
139
|
const cloned = input.clone();
|
|
139
140
|
if (cloned?.arrayBuffer) return cloned.arrayBuffer();
|
|
140
141
|
if (cloned?.text) return cloned.text();
|
|
@@ -149,9 +150,9 @@ async function normalizeRequestBody(body, headers) {
|
|
|
149
150
|
if (!hasHeader(headers, "content-type")) headers["content-type"] = "application/x-www-form-urlencoded;charset=UTF-8";
|
|
150
151
|
return body.toString();
|
|
151
152
|
}
|
|
152
|
-
if (body
|
|
153
|
+
if (isArrayBufferLike(body)) return cloneArrayBuffer(body);
|
|
153
154
|
if (ArrayBuffer.isView(body)) return cloneArrayBufferView(body);
|
|
154
|
-
if (
|
|
155
|
+
if (isBlobLike(body)) {
|
|
155
156
|
if (body.type && !hasHeader(headers, "content-type")) headers["content-type"] = body.type;
|
|
156
157
|
return body.arrayBuffer();
|
|
157
158
|
}
|
package/dist/fetch.mjs
CHANGED
package/dist/http.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { RequestGlobalsBlobLike } from "./shared.mjs";
|
|
1
2
|
import { URLPolyfill } from "./url.mjs";
|
|
3
|
+
import { FormDataPolyfill } from "./web.mjs";
|
|
2
4
|
|
|
3
5
|
//#region src/http.d.ts
|
|
4
6
|
type HeaderRecord = Record<string, string>;
|
|
@@ -17,7 +19,8 @@ declare class HeadersPolyfill {
|
|
|
17
19
|
values(): ArrayIterator<string>;
|
|
18
20
|
[Symbol.iterator](): ArrayIterator<[string, string]>;
|
|
19
21
|
}
|
|
20
|
-
type RequestBodyLike = string | ArrayBuffer | ArrayBufferView | Blob | null | undefined;
|
|
22
|
+
type RequestBodyLike = string | ArrayBuffer | ArrayBufferView | Blob | RequestGlobalsBlobLike | FormData | FormDataPolyfill | null | undefined;
|
|
23
|
+
declare function getRequestBodyValue(request?: RequestPolyfill): RequestBodyLike;
|
|
21
24
|
declare class RequestPolyfill {
|
|
22
25
|
readonly url: string;
|
|
23
26
|
readonly method: string;
|
|
@@ -54,4 +57,4 @@ declare class ResponsePolyfill {
|
|
|
54
57
|
}
|
|
55
58
|
declare function headersToObject(headers: HeadersPolyfill | Headers): HeaderRecord;
|
|
56
59
|
//#endregion
|
|
57
|
-
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, headersToObject };
|
|
60
|
+
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, getRequestBodyValue, headersToObject };
|
package/dist/http.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as normalizeHeaderName, i as decodeText, l as isArrayBufferLike, m as isUrlInstance, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-C4EOQbWG.mjs";
|
|
2
|
+
import { FormDataPolyfill } from "./web.mjs";
|
|
2
3
|
//#region src/http.ts
|
|
3
4
|
const SET_COOKIE_HEADER_NAME = "set-cookie";
|
|
4
5
|
function isIterableHeaders(input) {
|
|
@@ -77,16 +78,18 @@ const requestBodyUsedStore = /* @__PURE__ */ new WeakMap();
|
|
|
77
78
|
const responseBodyStore = /* @__PURE__ */ new WeakMap();
|
|
78
79
|
const responseBodyUsedStore = /* @__PURE__ */ new WeakMap();
|
|
79
80
|
function normalizeBody(body) {
|
|
80
|
-
if (body == null || typeof body === "string" || body
|
|
81
|
-
if (
|
|
81
|
+
if (body == null || typeof body === "string" || isArrayBufferLike(body) || ArrayBuffer.isView(body)) return body;
|
|
82
|
+
if (isBlobLike(body)) return body;
|
|
83
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) return body;
|
|
84
|
+
if (body instanceof FormDataPolyfill) return body;
|
|
82
85
|
return String(body);
|
|
83
86
|
}
|
|
84
87
|
async function readBodyAsArrayBuffer(body) {
|
|
85
88
|
if (body == null) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
86
89
|
if (typeof body === "string") return encodeText(body);
|
|
87
|
-
if (body
|
|
90
|
+
if (isArrayBufferLike(body)) return cloneArrayBuffer(body);
|
|
88
91
|
if (ArrayBuffer.isView(body)) return cloneArrayBufferView(body);
|
|
89
|
-
if (
|
|
92
|
+
if (isBlobLike(body)) return body.arrayBuffer();
|
|
90
93
|
return encodeText(String(body));
|
|
91
94
|
}
|
|
92
95
|
async function readBodyAsText(body) {
|
|
@@ -213,4 +216,4 @@ function headersToObject(headers) {
|
|
|
213
216
|
return result;
|
|
214
217
|
}
|
|
215
218
|
//#endregion
|
|
216
|
-
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, headersToObject };
|
|
219
|
+
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, getRequestBodyValue, headersToObject };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
|
|
|
3
3
|
import { MiniProgramNetworkDefaults, RequestGlobalsMiniProgramOptions, WebSocketMiniProgramOptions, getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
|
|
4
4
|
import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
|
|
5
5
|
import { fetch } from "./fetch.mjs";
|
|
6
|
-
import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
|
|
7
6
|
import { BlobPolyfill, FilePolyfill, FormDataPolyfill } from "./web.mjs";
|
|
7
|
+
import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
|
|
8
8
|
import { WebSocketPolyfill } from "./websocket.mjs";
|
|
9
9
|
import { XMLHttpRequestPolyfill } from "./xhr.mjs";
|
|
10
10
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as decodeTextFallback, c as installRequestGlobalBinding,
|
|
1
|
+
import { a as decodeTextFallback, c as installRequestGlobalBinding, f as resolveRequestGlobalsHost, l as isArrayBufferLike, n as cloneArrayBuffer, p as resolveRequestGlobalsHosts, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, v as getMiniProgramRuntimeGlobalKeys } from "./shared-C4EOQbWG.mjs";
|
|
2
2
|
import { URLPolyfill, URLSearchParamsPolyfill } from "./url.mjs";
|
|
3
3
|
import { AbortControllerPolyfill, AbortSignalPolyfill } from "./abort.mjs";
|
|
4
|
+
import { BlobPolyfill, FilePolyfill, FormDataPolyfill } from "./web.mjs";
|
|
4
5
|
import { HeadersPolyfill, RequestPolyfill, ResponsePolyfill } from "./http.mjs";
|
|
5
|
-
import { t as fetch } from "./fetch-
|
|
6
|
+
import { t as fetch } from "./fetch-CKch4mSy.mjs";
|
|
6
7
|
import { getMiniProgramNetworkDefaults, resetMiniProgramNetworkDefaults, setMiniProgramNetworkDefaults } from "./networkDefaults.mjs";
|
|
7
|
-
import { BlobPolyfill, FilePolyfill, FormDataPolyfill } from "./web.mjs";
|
|
8
8
|
import { WebSocketPolyfill } from "./websocket.mjs";
|
|
9
9
|
import { XMLHttpRequestPolyfill } from "./xhr.mjs";
|
|
10
10
|
import { REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_PLACEHOLDER_KEY } from "@weapp-core/constants";
|
|
@@ -174,12 +174,8 @@ function queueMicrotaskPolyfill(callback) {
|
|
|
174
174
|
//#region src/textCodec.ts
|
|
175
175
|
function normalizeTextDecoderInput(input) {
|
|
176
176
|
if (input == null) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
177
|
-
if (input
|
|
178
|
-
if (ArrayBuffer.isView(input))
|
|
179
|
-
const copied = new Uint8Array(input.byteLength);
|
|
180
|
-
copied.set(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
|
|
181
|
-
return copied.buffer;
|
|
182
|
-
}
|
|
177
|
+
if (isArrayBufferLike(input)) return cloneArrayBuffer(input);
|
|
178
|
+
if (ArrayBuffer.isView(input)) return cloneArrayBufferView(input);
|
|
183
179
|
return /* @__PURE__ */ new ArrayBuffer(0);
|
|
184
180
|
}
|
|
185
181
|
var TextEncoderPolyfill = class {
|
|
@@ -631,8 +631,17 @@ function installRequestGlobalBinding(name, value) {
|
|
|
631
631
|
host[name] = value;
|
|
632
632
|
} catch {}
|
|
633
633
|
}
|
|
634
|
+
function isArrayBufferLike(value) {
|
|
635
|
+
return Object.prototype.toString.call(value) === "[object ArrayBuffer]" && typeof value.byteLength === "number";
|
|
636
|
+
}
|
|
637
|
+
function isBlobLike(value) {
|
|
638
|
+
return value != null && typeof value === "object" && typeof value.arrayBuffer === "function" && (typeof value.size === "number" || typeof value.type === "string");
|
|
639
|
+
}
|
|
634
640
|
function cloneArrayBuffer(buffer) {
|
|
635
|
-
return buffer.slice(0);
|
|
641
|
+
if (typeof buffer.slice === "function") return buffer.slice(0);
|
|
642
|
+
const copied = new Uint8Array(buffer.byteLength);
|
|
643
|
+
copied.set(new Uint8Array(buffer));
|
|
644
|
+
return copied.buffer;
|
|
636
645
|
}
|
|
637
646
|
function cloneArrayBufferView(view) {
|
|
638
647
|
const copied = new Uint8Array(view.byteLength);
|
|
@@ -669,4 +678,4 @@ function normalizeHeaderName(name) {
|
|
|
669
678
|
return name.trim().toLowerCase();
|
|
670
679
|
}
|
|
671
680
|
//#endregion
|
|
672
|
-
export { decodeTextFallback as a, installRequestGlobalBinding as c,
|
|
681
|
+
export { resolveUrlConstructor as _, decodeTextFallback as a, installRequestGlobalBinding as c, normalizeHeaderName as d, resolveRequestGlobalsHost as f, resolveTextEncoderConstructor as g, isUrlSearchParamsInstance as h, decodeText as i, isArrayBufferLike as l, isUrlInstance as m, cloneArrayBuffer as n, encodeText as o, resolveRequestGlobalsHosts as p, cloneArrayBufferView as r, encodeTextFallback as s, RequestGlobalsEventTarget as t, isBlobLike as u, getMiniProgramRuntimeGlobalKeys as v };
|
package/dist/shared.d.mts
CHANGED
|
@@ -19,6 +19,13 @@ declare class RequestGlobalsEventTarget implements RequestGlobalsEventTargetLike
|
|
|
19
19
|
declare function resolveRequestGlobalsHost(): Record<string, any>;
|
|
20
20
|
declare function resolveRequestGlobalsHosts(): Record<string, any>[];
|
|
21
21
|
declare function installRequestGlobalBinding(name: string, value: unknown): void;
|
|
22
|
+
declare function isArrayBufferLike(value: unknown): value is ArrayBuffer;
|
|
23
|
+
interface RequestGlobalsBlobLike {
|
|
24
|
+
readonly size?: number;
|
|
25
|
+
readonly type?: string;
|
|
26
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
27
|
+
}
|
|
28
|
+
declare function isBlobLike(value: unknown): value is RequestGlobalsBlobLike;
|
|
22
29
|
declare function cloneArrayBuffer(buffer: ArrayBuffer): ArrayBuffer;
|
|
23
30
|
declare function cloneArrayBufferView(view: ArrayBufferView): ArrayBuffer;
|
|
24
31
|
declare function encodeTextFallback(value: string): ArrayBuffer;
|
|
@@ -27,4 +34,4 @@ declare function decodeTextFallback(value: ArrayBuffer): string;
|
|
|
27
34
|
declare function decodeText(value: ArrayBuffer): string;
|
|
28
35
|
declare function normalizeHeaderName(name: string): string;
|
|
29
36
|
//#endregion
|
|
30
|
-
export { RequestGlobalsEventLike, RequestGlobalsEventTarget, RequestGlobalsEventTargetLike, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
|
37
|
+
export { RequestGlobalsBlobLike, RequestGlobalsEventLike, RequestGlobalsEventTarget, RequestGlobalsEventTargetLike, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, isArrayBufferLike, isBlobLike, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
package/dist/shared.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as decodeTextFallback, c as installRequestGlobalBinding, d as
|
|
2
|
-
export { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
|
1
|
+
import { a as decodeTextFallback, c as installRequestGlobalBinding, d as normalizeHeaderName, f as resolveRequestGlobalsHost, i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, p as resolveRequestGlobalsHosts, r as cloneArrayBufferView, s as encodeTextFallback, t as RequestGlobalsEventTarget, u as isBlobLike } from "./shared-C4EOQbWG.mjs";
|
|
2
|
+
export { RequestGlobalsEventTarget, cloneArrayBuffer, cloneArrayBufferView, decodeText, decodeTextFallback, encodeText, encodeTextFallback, installRequestGlobalBinding, isArrayBufferLike, isBlobLike, normalizeHeaderName, resolveRequestGlobalsHost, resolveRequestGlobalsHosts };
|
package/dist/web.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { RequestGlobalsBlobLike } from "./shared.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/web.d.ts
|
|
2
|
-
|
|
3
|
-
readonly size?: number;
|
|
4
|
-
readonly type?: string;
|
|
5
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
6
|
-
}
|
|
4
|
+
type BlobLikePart = RequestGlobalsBlobLike;
|
|
7
5
|
type BlobPart = ArrayBuffer | ArrayBufferView | BlobLikePart | string;
|
|
8
6
|
type FormDataEntryValue = FilePolyfill | BlobPolyfill | string;
|
|
9
7
|
interface BlobPropertyBag {
|
package/dist/web.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { i as decodeText, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView } from "./shared-
|
|
1
|
+
import { i as decodeText, l as isArrayBufferLike, n as cloneArrayBuffer, o as encodeText, r as cloneArrayBufferView, u as isBlobLike } from "./shared-C4EOQbWG.mjs";
|
|
2
2
|
//#region src/web.ts
|
|
3
3
|
function normalizeBlobPart(part) {
|
|
4
4
|
if (typeof part === "string") return Promise.resolve(encodeText(part));
|
|
5
|
-
if (part
|
|
6
|
-
if (part
|
|
5
|
+
if (isBlobLike(part)) return part.arrayBuffer();
|
|
6
|
+
if (isArrayBufferLike(part)) return Promise.resolve(cloneArrayBuffer(part));
|
|
7
7
|
if (ArrayBuffer.isView(part)) return Promise.resolve(cloneArrayBufferView(part));
|
|
8
8
|
return Promise.resolve(encodeText(String(part)));
|
|
9
9
|
}
|
|
@@ -17,7 +17,7 @@ var BlobPolyfill = class {
|
|
|
17
17
|
this.size = parts.reduce((total, part) => {
|
|
18
18
|
if (typeof part === "string") return total + String(part).length;
|
|
19
19
|
if (part && typeof part === "object" && typeof part.size === "number") return total + Number(part.size);
|
|
20
|
-
if (part
|
|
20
|
+
if (isArrayBufferLike(part)) return total + part.byteLength;
|
|
21
21
|
if (ArrayBuffer.isView(part)) return total + part.byteLength;
|
|
22
22
|
return total;
|
|
23
23
|
}, 0);
|
package/dist/websocket.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RequestGlobalsEventTarget } from "./shared.mjs";
|
|
1
|
+
import { RequestGlobalsBlobLike, RequestGlobalsEventTarget } from "./shared.mjs";
|
|
2
2
|
import { WebSocketMiniProgramOptions } from "./networkDefaults.mjs";
|
|
3
3
|
import { BlobPolyfill } from "./web.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/websocket.d.ts
|
|
6
6
|
type WebSocketBinaryType = 'blob' | 'arraybuffer';
|
|
7
|
-
type WebSocketSendData = string | ArrayBuffer | ArrayBufferView | Blob;
|
|
7
|
+
type WebSocketSendData = string | ArrayBuffer | ArrayBufferView | Blob | RequestGlobalsBlobLike;
|
|
8
8
|
type WebSocketMessageData = string | ArrayBuffer | Blob | BlobPolyfill;
|
|
9
9
|
interface WebSocketCloseEventLike {
|
|
10
10
|
code: number;
|
package/dist/websocket.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
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-C4EOQbWG.mjs";
|
|
2
2
|
import { URLPolyfill } from "./url.mjs";
|
|
3
|
-
import { resolveWebSocketMiniProgramOptions } from "./networkDefaults.mjs";
|
|
4
3
|
import { BlobPolyfill } from "./web.mjs";
|
|
4
|
+
import { resolveWebSocketMiniProgramOptions } from "./networkDefaults.mjs";
|
|
5
5
|
import { wpi } from "@wevu/api";
|
|
6
6
|
//#region src/websocket.ts
|
|
7
7
|
const WHITESPACE_RE = /\s/u;
|
|
@@ -69,9 +69,9 @@ function isSocketTask(value) {
|
|
|
69
69
|
}
|
|
70
70
|
function toBinaryPayload(data) {
|
|
71
71
|
if (typeof data === "string") return data;
|
|
72
|
-
if (data
|
|
72
|
+
if (isArrayBufferLike(data)) return cloneArrayBuffer(data);
|
|
73
73
|
if (ArrayBuffer.isView(data)) return cloneArrayBufferView(data);
|
|
74
|
-
if (
|
|
74
|
+
if (isBlobLike(data)) return data.arrayBuffer();
|
|
75
75
|
throw new TypeError("Failed to execute send: data must be a string, ArrayBuffer, ArrayBufferView or Blob");
|
|
76
76
|
}
|
|
77
77
|
function createErrorEvent(error) {
|
package/dist/xhr.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as resolveRequestGlobalsHost, t as RequestGlobalsEventTarget } from "./shared-C4EOQbWG.mjs";
|
|
2
2
|
import { AbortControllerPolyfill } from "./abort.mjs";
|
|
3
3
|
import { HeadersPolyfill, headersToObject } from "./http.mjs";
|
|
4
|
-
import { t as fetch } from "./fetch-
|
|
4
|
+
import { t as fetch } from "./fetch-CKch4mSy.mjs";
|
|
5
5
|
//#region src/xhr.ts
|
|
6
6
|
function createProgressEvent(type) {
|
|
7
7
|
return {
|
package/package.json
CHANGED