rezo 1.0.30 → 1.0.32
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/adapters/curl.cjs +8 -10
- package/dist/adapters/curl.js +8 -10
- package/dist/adapters/entries/curl.d.ts +169 -313
- package/dist/adapters/entries/fetch.d.ts +169 -313
- package/dist/adapters/entries/http.d.ts +169 -313
- package/dist/adapters/entries/http2.d.ts +169 -313
- package/dist/adapters/entries/react-native.d.ts +169 -313
- package/dist/adapters/entries/xhr.d.ts +169 -313
- package/dist/adapters/fetch.cjs +10 -7
- package/dist/adapters/fetch.js +10 -7
- package/dist/adapters/http.cjs +9 -12
- package/dist/adapters/http.js +9 -12
- package/dist/adapters/http2.cjs +6 -11
- package/dist/adapters/http2.js +6 -11
- package/dist/adapters/index.cjs +6 -6
- package/dist/adapters/react-native.cjs +4 -4
- package/dist/adapters/react-native.js +4 -4
- package/dist/adapters/xhr.cjs +4 -4
- package/dist/adapters/xhr.js +4 -4
- package/dist/cache/index.cjs +13 -13
- package/dist/cache/universal-response-cache.cjs +165 -0
- package/dist/cache/universal-response-cache.js +162 -0
- package/dist/core/rezo.cjs +2 -8
- package/dist/core/rezo.js +2 -8
- package/dist/crawler.d.ts +163 -313
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +24 -24
- package/dist/index.d.ts +169 -313
- package/dist/platform/browser.d.ts +169 -313
- package/dist/platform/bun.d.ts +169 -313
- package/dist/platform/deno.d.ts +169 -313
- package/dist/platform/node.d.ts +169 -313
- package/dist/platform/react-native.d.ts +169 -313
- package/dist/platform/worker.d.ts +169 -313
- package/dist/plugin/crawler.cjs +1 -1
- package/dist/plugin/crawler.js +1 -1
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +4 -4
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/buildResponse.cjs +15 -15
- package/dist/responses/buildResponse.js +15 -15
- package/dist/responses/universal/download.cjs +23 -0
- package/dist/responses/universal/download.js +22 -0
- package/dist/responses/universal/event-emitter.cjs +104 -0
- package/dist/responses/universal/event-emitter.js +102 -0
- package/dist/responses/universal/index.cjs +11 -0
- package/dist/responses/universal/index.js +4 -0
- package/dist/responses/universal/stream.cjs +32 -0
- package/dist/responses/universal/stream.js +31 -0
- package/dist/responses/universal/upload.cjs +23 -0
- package/dist/responses/universal/upload.js +22 -0
- package/dist/utils/cookies.browser.cjs +63 -0
- package/dist/utils/cookies.browser.js +61 -0
- package/dist/utils/form-data.cjs +212 -189
- package/dist/utils/form-data.js +212 -189
- package/dist/utils/http-config.cjs +28 -15
- package/dist/utils/http-config.js +28 -15
- package/package.json +11 -4
- package/dist/types/cookies.cjs +0 -394
- package/dist/types/cookies.js +0 -391
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UniversalEventEmitter } from './event-emitter.js';
|
|
2
|
+
|
|
3
|
+
export class UniversalStreamResponse extends UniversalEventEmitter {
|
|
4
|
+
_finished = false;
|
|
5
|
+
_encoding;
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
setEncoding(encoding) {
|
|
10
|
+
this._encoding = encoding;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
getEncoding() {
|
|
14
|
+
return this._encoding;
|
|
15
|
+
}
|
|
16
|
+
isFinished() {
|
|
17
|
+
return this._finished;
|
|
18
|
+
}
|
|
19
|
+
_markFinished() {
|
|
20
|
+
this._finished = true;
|
|
21
|
+
}
|
|
22
|
+
write(chunk) {
|
|
23
|
+
this.emit("data", chunk);
|
|
24
|
+
}
|
|
25
|
+
end() {
|
|
26
|
+
this._finished = true;
|
|
27
|
+
this.emit("close");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { UniversalStreamResponse as StreamResponse };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { UniversalEventEmitter } = require('./event-emitter.cjs');
|
|
2
|
+
|
|
3
|
+
class UniversalUploadResponse extends UniversalEventEmitter {
|
|
4
|
+
url;
|
|
5
|
+
fileName;
|
|
6
|
+
status;
|
|
7
|
+
statusText;
|
|
8
|
+
_finished = false;
|
|
9
|
+
constructor(url, fileName) {
|
|
10
|
+
super();
|
|
11
|
+
this.url = url;
|
|
12
|
+
this.fileName = fileName;
|
|
13
|
+
}
|
|
14
|
+
isFinished() {
|
|
15
|
+
return this._finished;
|
|
16
|
+
}
|
|
17
|
+
_markFinished() {
|
|
18
|
+
this._finished = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.UploadResponse = UniversalUploadResponse;
|
|
23
|
+
exports.UniversalUploadResponse = UniversalUploadResponse;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UniversalEventEmitter } from './event-emitter.js';
|
|
2
|
+
|
|
3
|
+
export class UniversalUploadResponse extends UniversalEventEmitter {
|
|
4
|
+
url;
|
|
5
|
+
fileName;
|
|
6
|
+
status;
|
|
7
|
+
statusText;
|
|
8
|
+
_finished = false;
|
|
9
|
+
constructor(url, fileName) {
|
|
10
|
+
super();
|
|
11
|
+
this.url = url;
|
|
12
|
+
this.fileName = fileName;
|
|
13
|
+
}
|
|
14
|
+
isFinished() {
|
|
15
|
+
return this._finished;
|
|
16
|
+
}
|
|
17
|
+
_markFinished() {
|
|
18
|
+
this._finished = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { UniversalUploadResponse as UploadResponse };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class Cookie {
|
|
2
|
+
key;
|
|
3
|
+
value;
|
|
4
|
+
domain = null;
|
|
5
|
+
path = "/";
|
|
6
|
+
expires = null;
|
|
7
|
+
httpOnly = false;
|
|
8
|
+
secure = false;
|
|
9
|
+
sameSite;
|
|
10
|
+
maxAge = null;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.key = options.key;
|
|
13
|
+
this.value = options.value;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return `${this.key}=${this.value}`;
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return { key: this.key, value: this.value };
|
|
20
|
+
}
|
|
21
|
+
static parse(_str) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const EMPTY_COOKIES = { array: [], serialized: [], netscape: "", string: "", setCookiesString: [] };
|
|
26
|
+
|
|
27
|
+
class RezoCookieJar {
|
|
28
|
+
constructor(_cookies, _url) {}
|
|
29
|
+
setCookie(_c, _u) {}
|
|
30
|
+
setCookiesSync(_c, _u) {}
|
|
31
|
+
getCookiesSync(_u) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
getCookieStringSync(_u) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
removeAllCookiesSync() {}
|
|
38
|
+
cookies() {
|
|
39
|
+
return EMPTY_COOKIES;
|
|
40
|
+
}
|
|
41
|
+
toJSON() {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
static fromJSON(_d) {
|
|
45
|
+
return new RezoCookieJar;
|
|
46
|
+
}
|
|
47
|
+
generateCookies(_u, _s) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
parseResponseCookies(_s, _u) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
toCookieString(_u) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
toNetscapeCookie() {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.default = Cookie;
|
|
62
|
+
exports.Cookie = Cookie;
|
|
63
|
+
exports.RezoCookieJar = RezoCookieJar;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export class Cookie {
|
|
2
|
+
key;
|
|
3
|
+
value;
|
|
4
|
+
domain = null;
|
|
5
|
+
path = "/";
|
|
6
|
+
expires = null;
|
|
7
|
+
httpOnly = false;
|
|
8
|
+
secure = false;
|
|
9
|
+
sameSite;
|
|
10
|
+
maxAge = null;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.key = options.key;
|
|
13
|
+
this.value = options.value;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return `${this.key}=${this.value}`;
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return { key: this.key, value: this.value };
|
|
20
|
+
}
|
|
21
|
+
static parse(_str) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const EMPTY_COOKIES = { array: [], serialized: [], netscape: "", string: "", setCookiesString: [] };
|
|
26
|
+
|
|
27
|
+
export class RezoCookieJar {
|
|
28
|
+
constructor(_cookies, _url) {}
|
|
29
|
+
setCookie(_c, _u) {}
|
|
30
|
+
setCookiesSync(_c, _u) {}
|
|
31
|
+
getCookiesSync(_u) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
getCookieStringSync(_u) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
removeAllCookiesSync() {}
|
|
38
|
+
cookies() {
|
|
39
|
+
return EMPTY_COOKIES;
|
|
40
|
+
}
|
|
41
|
+
toJSON() {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
static fromJSON(_d) {
|
|
45
|
+
return new RezoCookieJar;
|
|
46
|
+
}
|
|
47
|
+
generateCookies(_u, _s) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
parseResponseCookies(_s, _u) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
toCookieString(_u) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
toNetscapeCookie() {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { Cookie as default };
|
package/dist/utils/form-data.cjs
CHANGED
|
@@ -1,218 +1,241 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
const hasBuffer = typeof Buffer !== "undefined";
|
|
2
|
+
function isBuffer(value) {
|
|
3
|
+
return hasBuffer && Buffer.isBuffer(value);
|
|
4
|
+
}
|
|
5
|
+
function toBlob(value, contentType) {
|
|
6
|
+
const options = contentType ? { type: contentType } : undefined;
|
|
7
|
+
const copy = new ArrayBuffer(value.byteLength);
|
|
8
|
+
new Uint8Array(copy).set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
9
|
+
return new Blob([copy], options);
|
|
4
10
|
}
|
|
5
11
|
|
|
6
|
-
class RezoFormData
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const entries = [];
|
|
13
|
-
const fields = this._fields || [];
|
|
14
|
-
for (const field of fields) {
|
|
15
|
-
if (field && field.name && field.value !== undefined) {
|
|
16
|
-
entries.push([field.name, field.value]);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
resolve(entries);
|
|
20
|
-
});
|
|
12
|
+
class RezoFormData {
|
|
13
|
+
_fd;
|
|
14
|
+
_cachedContentType = null;
|
|
15
|
+
_cachedBuffer = null;
|
|
16
|
+
constructor() {
|
|
17
|
+
this._fd = new FormData;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
31
|
-
}
|
|
32
|
-
const buffer = Buffer.concat(chunks);
|
|
33
|
-
const blob = new Blob([buffer]);
|
|
34
|
-
formData.append(key, blob);
|
|
35
|
-
} else {
|
|
36
|
-
formData.append(key, value);
|
|
37
|
-
}
|
|
19
|
+
append(name, value, filename) {
|
|
20
|
+
this._invalidateCache();
|
|
21
|
+
if (isBuffer(value)) {
|
|
22
|
+
const blob = toBlob(value);
|
|
23
|
+
if (filename) {
|
|
24
|
+
this._fd.append(name, blob, filename);
|
|
25
|
+
} else {
|
|
26
|
+
this._fd.append(name, blob);
|
|
38
27
|
}
|
|
39
|
-
|
|
28
|
+
} else if (filename && value instanceof Blob) {
|
|
29
|
+
this._fd.append(name, value, filename);
|
|
30
|
+
} else {
|
|
31
|
+
this._fd.append(name, value);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
49
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
50
|
-
rezoFormData.append(key, buffer, {
|
|
51
|
-
filename: file.name,
|
|
52
|
-
contentType: file.type || "application/octet-stream"
|
|
53
|
-
});
|
|
54
|
-
} else if (typeof Blob !== "undefined" && value instanceof Blob) {
|
|
55
|
-
const blob = value;
|
|
56
|
-
const arrayBuffer = await blob.arrayBuffer();
|
|
57
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
58
|
-
rezoFormData.append(key, buffer, {
|
|
59
|
-
contentType: blob.type || "application/octet-stream"
|
|
60
|
-
});
|
|
33
|
+
}
|
|
34
|
+
set(name, value, filename) {
|
|
35
|
+
this._invalidateCache();
|
|
36
|
+
if (isBuffer(value)) {
|
|
37
|
+
const blob = toBlob(value);
|
|
38
|
+
if (filename) {
|
|
39
|
+
this._fd.set(name, blob, filename);
|
|
61
40
|
} else {
|
|
62
|
-
|
|
41
|
+
this._fd.set(name, blob);
|
|
63
42
|
}
|
|
43
|
+
} else if (filename && value instanceof Blob) {
|
|
44
|
+
this._fd.set(name, value, filename);
|
|
45
|
+
} else {
|
|
46
|
+
this._fd.set(name, value);
|
|
64
47
|
}
|
|
65
|
-
return rezoFormData;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
return
|
|
49
|
+
get(name) {
|
|
50
|
+
return this._fd.get(name);
|
|
69
51
|
}
|
|
70
|
-
|
|
71
|
-
return
|
|
52
|
+
getAll(name) {
|
|
53
|
+
return this._fd.getAll(name);
|
|
72
54
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
76
|
-
RezoFormData.appendValue(formData, key, value);
|
|
77
|
-
}
|
|
78
|
-
return formData;
|
|
55
|
+
has(name) {
|
|
56
|
+
return this._fd.has(name);
|
|
79
57
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
RezoFormData.appendValue(formData, key, item);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
58
|
+
delete(name) {
|
|
59
|
+
this._invalidateCache();
|
|
60
|
+
this._fd.delete(name);
|
|
61
|
+
}
|
|
62
|
+
entries() {
|
|
63
|
+
return this._fd.entries();
|
|
64
|
+
}
|
|
65
|
+
keys() {
|
|
66
|
+
return this._fd.keys();
|
|
67
|
+
}
|
|
68
|
+
values() {
|
|
69
|
+
return this._fd.values();
|
|
70
|
+
}
|
|
71
|
+
forEach(callback) {
|
|
72
|
+
this._fd.forEach(callback);
|
|
73
|
+
}
|
|
74
|
+
[Symbol.iterator]() {
|
|
75
|
+
return this._fd.entries();
|
|
76
|
+
}
|
|
77
|
+
toNativeFormData() {
|
|
78
|
+
return this._fd;
|
|
79
|
+
}
|
|
80
|
+
_invalidateCache() {
|
|
81
|
+
this._cachedContentType = null;
|
|
82
|
+
this._cachedBuffer = null;
|
|
83
|
+
}
|
|
84
|
+
async _buildResponse() {
|
|
85
|
+
if (this._cachedBuffer === null || this._cachedContentType === null) {
|
|
86
|
+
const response = new Response(this._fd);
|
|
87
|
+
this._cachedContentType = response.headers.get("content-type") || "multipart/form-data";
|
|
88
|
+
this._cachedBuffer = await response.arrayBuffer();
|
|
89
|
+
}
|
|
90
|
+
return new Response(this._cachedBuffer, {
|
|
91
|
+
headers: { "content-type": this._cachedContentType }
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getBoundary() {
|
|
95
|
+
if (!this._cachedContentType) {
|
|
96
|
+
return "";
|
|
122
97
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
98
|
+
const match = this._cachedContentType.match(/boundary=([^;]+)/);
|
|
99
|
+
return match ? match[1] : "";
|
|
100
|
+
}
|
|
101
|
+
getContentType() {
|
|
102
|
+
return this._cachedContentType || undefined;
|
|
103
|
+
}
|
|
104
|
+
async getContentTypeAsync() {
|
|
105
|
+
await this._buildResponse();
|
|
106
|
+
return this._cachedContentType;
|
|
107
|
+
}
|
|
108
|
+
getHeaders() {
|
|
109
|
+
if (this._cachedContentType) {
|
|
110
|
+
return { "content-type": this._cachedContentType };
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
async getHeadersAsync() {
|
|
115
|
+
const contentType = await this.getContentTypeAsync();
|
|
116
|
+
const length = await this.getLength();
|
|
117
|
+
return {
|
|
118
|
+
"content-type": contentType,
|
|
119
|
+
"content-length": String(length)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
getLengthSync() {
|
|
123
|
+
return this._cachedBuffer?.byteLength;
|
|
124
|
+
}
|
|
125
|
+
async getLength() {
|
|
126
|
+
await this._buildResponse();
|
|
127
|
+
return this._cachedBuffer.byteLength;
|
|
128
|
+
}
|
|
129
|
+
getBuffer() {
|
|
130
|
+
if (!hasBuffer || !this._cachedBuffer) {
|
|
131
|
+
return null;
|
|
140
132
|
}
|
|
141
|
-
|
|
133
|
+
return Buffer.from(this._cachedBuffer);
|
|
142
134
|
}
|
|
143
|
-
async
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
135
|
+
async toBuffer() {
|
|
136
|
+
await this._buildResponse();
|
|
137
|
+
return Buffer.from(this._cachedBuffer);
|
|
138
|
+
}
|
|
139
|
+
async toArrayBuffer() {
|
|
140
|
+
await this._buildResponse();
|
|
141
|
+
return this._cachedBuffer;
|
|
142
|
+
}
|
|
143
|
+
async toUint8Array() {
|
|
144
|
+
await this._buildResponse();
|
|
145
|
+
return new Uint8Array(this._cachedBuffer);
|
|
146
|
+
}
|
|
147
|
+
static fromObject(obj) {
|
|
148
|
+
const fd = new RezoFormData;
|
|
149
|
+
const appendValue = (key, value) => {
|
|
150
|
+
if (value === null || value === undefined) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "string") {
|
|
154
|
+
fd.append(key, value);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
158
|
+
fd.append(key, String(value));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (value instanceof Blob) {
|
|
162
|
+
const filename = value instanceof File ? value.name : undefined;
|
|
163
|
+
fd.append(key, value, filename);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (isBuffer(value)) {
|
|
167
|
+
fd.append(key, toBlob(value));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (value instanceof Uint8Array) {
|
|
171
|
+
fd.append(key, toBlob(value));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (value instanceof ArrayBuffer) {
|
|
175
|
+
fd.append(key, new Blob([value]));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
for (let i = 0;i < value.length; i++) {
|
|
180
|
+
appendValue(`${key}[${i}]`, value[i]);
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "object" && value !== null) {
|
|
185
|
+
if ("value" in value && (("filename" in value) || ("contentType" in value))) {
|
|
186
|
+
const v = value;
|
|
187
|
+
if (v.value instanceof Blob) {
|
|
188
|
+
fd.append(key, v.value, v.filename);
|
|
189
|
+
} else if (isBuffer(v.value)) {
|
|
190
|
+
const blob = toBlob(v.value, v.contentType);
|
|
191
|
+
fd.append(key, blob, v.filename);
|
|
192
|
+
} else if (v.value instanceof Uint8Array) {
|
|
193
|
+
const blob = toBlob(v.value, v.contentType);
|
|
194
|
+
fd.append(key, blob, v.filename);
|
|
166
195
|
} else {
|
|
167
|
-
|
|
196
|
+
fd.append(key, String(v.value));
|
|
168
197
|
}
|
|
169
|
-
|
|
170
|
-
hasOmittedData = true;
|
|
198
|
+
return;
|
|
171
199
|
}
|
|
200
|
+
for (const [subKey, subValue] of Object.entries(value)) {
|
|
201
|
+
appendValue(`${key}[${subKey}]`, subValue);
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
172
204
|
}
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
fd.append(key, String(value));
|
|
206
|
+
};
|
|
207
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
208
|
+
appendValue(key, value);
|
|
175
209
|
}
|
|
176
|
-
|
|
177
|
-
|
|
210
|
+
return fd;
|
|
211
|
+
}
|
|
212
|
+
static fromNativeFormData(formData) {
|
|
213
|
+
const fd = new RezoFormData;
|
|
214
|
+
for (const [key, value] of formData.entries()) {
|
|
215
|
+
if (typeof value === "string") {
|
|
216
|
+
fd.append(key, value);
|
|
217
|
+
} else {
|
|
218
|
+
const filename = value.name || undefined;
|
|
219
|
+
fd.append(key, value, filename);
|
|
220
|
+
}
|
|
178
221
|
}
|
|
179
|
-
return
|
|
222
|
+
return fd;
|
|
180
223
|
}
|
|
181
|
-
|
|
224
|
+
toUrlQueryString() {
|
|
182
225
|
const params = new URLSearchParams;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
for (const [name, value] of entries) {
|
|
187
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
188
|
-
params.append(name, String(value));
|
|
189
|
-
} else if (value instanceof Buffer) {
|
|
190
|
-
if (convertBinaryToBase64) {
|
|
191
|
-
params.append(name, value.toString("base64"));
|
|
192
|
-
} else {
|
|
193
|
-
hasOmittedData = true;
|
|
194
|
-
}
|
|
195
|
-
} else if (isReadableStream(value) || typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob) {
|
|
196
|
-
if (convertBinaryToBase64 && value instanceof File) {
|
|
197
|
-
hasOmittedData = true;
|
|
198
|
-
} else {
|
|
199
|
-
hasOmittedData = true;
|
|
200
|
-
}
|
|
201
|
-
} else if (typeof value === "object" && value && "value" in value) {
|
|
202
|
-
if (typeof value.value === "string" || typeof value.value === "number" || typeof value.value === "boolean") {
|
|
203
|
-
params.append(name, String(value.value));
|
|
204
|
-
} else {
|
|
205
|
-
hasOmittedData = true;
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
hasOmittedData = true;
|
|
209
|
-
}
|
|
226
|
+
for (const [key, value] of this._fd.entries()) {
|
|
227
|
+
if (typeof value === "string") {
|
|
228
|
+
params.append(key, value);
|
|
210
229
|
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.warn("RezoFormData.toURLSearchParams(): Error reading form data entries:", error);
|
|
213
230
|
}
|
|
214
|
-
|
|
215
|
-
|
|
231
|
+
return params.toString();
|
|
232
|
+
}
|
|
233
|
+
toURLSearchParams() {
|
|
234
|
+
const params = new URLSearchParams;
|
|
235
|
+
for (const [key, value] of this._fd.entries()) {
|
|
236
|
+
if (typeof value === "string") {
|
|
237
|
+
params.append(key, value);
|
|
238
|
+
}
|
|
216
239
|
}
|
|
217
240
|
return params;
|
|
218
241
|
}
|