@nocobase/plugin-ai-gigachat 2.3.0-beta.13 → 2.3.0-beta.15
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/externalVersion.js +5 -5
- package/dist/node_modules/gigachat/package.json +1 -1
- package/dist/node_modules/langchain-gigachat/package.json +1 -1
- package/package.json +2 -2
- package/dist/node_modules/gigachat/node_modules/axios/dist/axios.js +0 -5249
- package/dist/node_modules/gigachat/node_modules/axios/dist/axios.min.js +0 -5
- package/dist/node_modules/gigachat/node_modules/axios/dist/browser/axios.cjs +0 -5146
- package/dist/node_modules/gigachat/node_modules/axios/dist/esm/axios.js +0 -5167
- package/dist/node_modules/gigachat/node_modules/axios/dist/esm/axios.min.js +0 -3
- package/dist/node_modules/gigachat/node_modules/axios/dist/node/axios.cjs +0 -5996
- package/dist/node_modules/gigachat/node_modules/axios/index.d.cts +0 -738
- package/dist/node_modules/gigachat/node_modules/axios/index.d.ts +0 -755
- package/dist/node_modules/gigachat/node_modules/axios/index.js +0 -45
- package/dist/node_modules/gigachat/node_modules/axios/lib/adapters/adapters.js +0 -132
- package/dist/node_modules/gigachat/node_modules/axios/lib/adapters/fetch.js +0 -643
- package/dist/node_modules/gigachat/node_modules/axios/lib/adapters/http.js +0 -1417
- package/dist/node_modules/gigachat/node_modules/axios/lib/adapters/xhr.js +0 -228
- package/dist/node_modules/gigachat/node_modules/axios/lib/axios.js +0 -89
- package/dist/node_modules/gigachat/node_modules/axios/lib/cancel/CancelToken.js +0 -135
- package/dist/node_modules/gigachat/node_modules/axios/lib/cancel/CanceledError.js +0 -22
- package/dist/node_modules/gigachat/node_modules/axios/lib/cancel/isCancel.js +0 -5
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/Axios.js +0 -283
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/AxiosError.js +0 -188
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/AxiosHeaders.js +0 -351
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/InterceptorManager.js +0 -72
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/buildFullPath.js +0 -50
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/dispatchRequest.js +0 -89
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/mergeConfig.js +0 -159
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/settle.js +0 -27
- package/dist/node_modules/gigachat/node_modules/axios/lib/core/transformData.js +0 -28
- package/dist/node_modules/gigachat/node_modules/axios/lib/defaults/index.js +0 -177
- package/dist/node_modules/gigachat/node_modules/axios/lib/defaults/transitional.js +0 -10
- package/dist/node_modules/gigachat/node_modules/axios/lib/env/classes/FormData.js +0 -2
- package/dist/node_modules/gigachat/node_modules/axios/lib/env/data.js +0 -1
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/AxiosTransformStream.js +0 -156
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +0 -59
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/Http2Sessions.js +0 -119
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/HttpStatusCode.js +0 -77
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js +0 -29
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/bind.js +0 -14
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/buildURL.js +0 -69
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/callbackify.js +0 -18
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/combineURLs.js +0 -15
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/composeSignals.js +0 -57
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/cookies.js +0 -64
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/deprecatedMethod.js +0 -31
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +0 -105
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/formDataToJSON.js +0 -119
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/formDataToStream.js +0 -119
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/fromDataURI.js +0 -68
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/isAbsoluteURL.js +0 -19
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/isAxiosError.js +0 -14
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/isURLSameOrigin.js +0 -16
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/null.js +0 -2
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/parseHeaders.js +0 -69
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/parseProtocol.js +0 -6
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/progressEventReducer.js +0 -54
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/readBlob.js +0 -15
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/resolveConfig.js +0 -119
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/sanitizeHeaderValue.js +0 -60
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/shouldBypassProxy.js +0 -210
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/speedometer.js +0 -55
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/spread.js +0 -28
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/throttle.js +0 -44
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/toFormData.js +0 -285
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/toURLEncodedForm.js +0 -19
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/trackStream.js +0 -89
- package/dist/node_modules/gigachat/node_modules/axios/lib/helpers/validator.js +0 -112
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/browser/classes/Blob.js +0 -3
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/browser/classes/FormData.js +0 -3
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +0 -4
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/browser/index.js +0 -13
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/common/utils.js +0 -52
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/index.js +0 -7
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/node/classes/FormData.js +0 -3
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/node/classes/URLSearchParams.js +0 -4
- package/dist/node_modules/gigachat/node_modules/axios/lib/platform/node/index.js +0 -37
- package/dist/node_modules/gigachat/node_modules/axios/lib/utils.js +0 -1017
- package/dist/node_modules/gigachat/node_modules/axios/package.json +0 -201
- package/dist/node_modules/gigachat/node_modules/follow-redirects/debug.js +0 -15
- package/dist/node_modules/gigachat/node_modules/follow-redirects/http.js +0 -1
- package/dist/node_modules/gigachat/node_modules/follow-redirects/https.js +0 -1
- package/dist/node_modules/gigachat/node_modules/follow-redirects/index.js +0 -709
- package/dist/node_modules/gigachat/node_modules/follow-redirects/package.json +0 -58
- package/dist/node_modules/gigachat/node_modules/proxy-from-env/index.cjs +0 -105
- package/dist/node_modules/gigachat/node_modules/proxy-from-env/index.js +0 -103
- package/dist/node_modules/gigachat/node_modules/proxy-from-env/package.json +0 -43
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
const LOOPBACK_HOSTNAMES = new Set(['localhost', '0.0.0.0']);
|
|
2
|
-
|
|
3
|
-
const isIPv4Loopback = (host) => {
|
|
4
|
-
const parts = host.split('.');
|
|
5
|
-
if (parts.length !== 4) return false;
|
|
6
|
-
if (parts[0] !== '127') return false;
|
|
7
|
-
return parts.every((p) => /^\d+$/.test(p) && Number(p) >= 0 && Number(p) <= 255);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const isIPv6ZeroGroup = (group) => /^0{1,4}$/.test(group);
|
|
11
|
-
|
|
12
|
-
// The unspecified address (IPv4 0.0.0.0 / IPv6 ::) resolves to the local host
|
|
13
|
-
// for outbound connections, so treat it as loopback-equivalent for NO_PROXY
|
|
14
|
-
// matching. 0.0.0.0 is covered by LOOPBACK_HOSTNAMES; this handles compressed
|
|
15
|
-
// and full IPv6 all-zero forms so both families bypass symmetrically.
|
|
16
|
-
const isIPv6Unspecified = (host) => {
|
|
17
|
-
if (host === '::') return true;
|
|
18
|
-
|
|
19
|
-
const compressionIndex = host.indexOf('::');
|
|
20
|
-
|
|
21
|
-
if (compressionIndex !== -1) {
|
|
22
|
-
if (compressionIndex !== host.lastIndexOf('::')) return false;
|
|
23
|
-
|
|
24
|
-
const left = host.slice(0, compressionIndex);
|
|
25
|
-
const right = host.slice(compressionIndex + 2);
|
|
26
|
-
const leftGroups = left ? left.split(':') : [];
|
|
27
|
-
const rightGroups = right ? right.split(':') : [];
|
|
28
|
-
const explicitGroups = leftGroups.length + rightGroups.length;
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
explicitGroups < 8 &&
|
|
32
|
-
leftGroups.every(isIPv6ZeroGroup) &&
|
|
33
|
-
rightGroups.every(isIPv6ZeroGroup)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const groups = host.split(':');
|
|
38
|
-
return groups.length === 8 && groups.every(isIPv6ZeroGroup);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const isIPv6Loopback = (host) => {
|
|
42
|
-
// Collapse all-zero groups: any form of ::1 / 0:0:...:0:1
|
|
43
|
-
// First, strip any leading "::" by normalising with Set lookup of common forms,
|
|
44
|
-
// then fall back to structural check.
|
|
45
|
-
if (host === '::1') return true;
|
|
46
|
-
|
|
47
|
-
// Check IPv4-mapped IPv6 loopback: ::ffff:<v4-loopback> or ::ffff:<hex-v4-loopback>
|
|
48
|
-
// Node's URL parser normalises ::ffff:127.0.0.1 → ::ffff:7f00:1
|
|
49
|
-
const v4MappedDotted = host.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|
50
|
-
if (v4MappedDotted) return isIPv4Loopback(v4MappedDotted[1]);
|
|
51
|
-
|
|
52
|
-
const v4MappedHex = host.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
|
|
53
|
-
if (v4MappedHex) {
|
|
54
|
-
const high = parseInt(v4MappedHex[1], 16);
|
|
55
|
-
// High 16 bits must start with 127 (0x7f) — i.e. 0x7f00..0x7fff
|
|
56
|
-
return high >= 0x7f00 && high <= 0x7fff;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Full-form ::1 variants: any number of zero groups followed by trailing 1
|
|
60
|
-
// e.g. 0:0:0:0:0:0:0:1, 0000:...:0001
|
|
61
|
-
const groups = host.split(':');
|
|
62
|
-
if (groups.length === 8) {
|
|
63
|
-
for (let i = 0; i < 7; i++) {
|
|
64
|
-
if (!/^0+$/.test(groups[i])) return false;
|
|
65
|
-
}
|
|
66
|
-
return /^0*1$/.test(groups[7]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return false;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const isLoopback = (host) => {
|
|
73
|
-
if (!host) return false;
|
|
74
|
-
if (LOOPBACK_HOSTNAMES.has(host)) return true;
|
|
75
|
-
if (isIPv4Loopback(host)) return true;
|
|
76
|
-
if (isIPv6Unspecified(host)) return true;
|
|
77
|
-
return isIPv6Loopback(host);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const DEFAULT_PORTS = {
|
|
81
|
-
http: 80,
|
|
82
|
-
https: 443,
|
|
83
|
-
ws: 80,
|
|
84
|
-
wss: 443,
|
|
85
|
-
ftp: 21,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const parseNoProxyEntry = (entry) => {
|
|
89
|
-
let entryHost = entry;
|
|
90
|
-
let entryPort = 0;
|
|
91
|
-
|
|
92
|
-
if (entryHost.charAt(0) === '[') {
|
|
93
|
-
const bracketIndex = entryHost.indexOf(']');
|
|
94
|
-
|
|
95
|
-
if (bracketIndex !== -1) {
|
|
96
|
-
const host = entryHost.slice(1, bracketIndex);
|
|
97
|
-
const rest = entryHost.slice(bracketIndex + 1);
|
|
98
|
-
|
|
99
|
-
if (rest.charAt(0) === ':' && /^\d+$/.test(rest.slice(1))) {
|
|
100
|
-
entryPort = Number.parseInt(rest.slice(1), 10);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return [host, entryPort];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const firstColon = entryHost.indexOf(':');
|
|
108
|
-
const lastColon = entryHost.lastIndexOf(':');
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
firstColon !== -1 &&
|
|
112
|
-
firstColon === lastColon &&
|
|
113
|
-
/^\d+$/.test(entryHost.slice(lastColon + 1))
|
|
114
|
-
) {
|
|
115
|
-
entryPort = Number.parseInt(entryHost.slice(lastColon + 1), 10);
|
|
116
|
-
entryHost = entryHost.slice(0, lastColon);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return [entryHost, entryPort];
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Convert IPv4-mapped IPv6 (::ffff:0:0/96 prefix) to IPv4 dotted form so both
|
|
123
|
-
// sides of a NO_PROXY comparison see the same canonical address. Without this,
|
|
124
|
-
// `NO_PROXY=192.168.1.5` would not match a request to `http://[::ffff:192.168.1.5]/`
|
|
125
|
-
// (Node's URL parser normalises that to `[::ffff:c0a8:105]`), and vice-versa,
|
|
126
|
-
// allowing the proxy-bypass policy to be circumvented by using the alternate
|
|
127
|
-
// representation. Returns the input unchanged when not IPv4-mapped.
|
|
128
|
-
const IPV4_MAPPED_DOTTED_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:(\d+\.\d+\.\d+\.\d+)$/i;
|
|
129
|
-
const IPV4_MAPPED_HEX_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i;
|
|
130
|
-
|
|
131
|
-
const unmapIPv4MappedIPv6 = (host) => {
|
|
132
|
-
if (typeof host !== 'string' || host.indexOf(':') === -1) return host;
|
|
133
|
-
|
|
134
|
-
const dotted = host.match(IPV4_MAPPED_DOTTED_RE);
|
|
135
|
-
if (dotted) return dotted[1];
|
|
136
|
-
|
|
137
|
-
const hex = host.match(IPV4_MAPPED_HEX_RE);
|
|
138
|
-
if (hex) {
|
|
139
|
-
const high = parseInt(hex[1], 16);
|
|
140
|
-
const low = parseInt(hex[2], 16);
|
|
141
|
-
return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return host;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const normalizeNoProxyHost = (hostname) => {
|
|
148
|
-
if (!hostname) {
|
|
149
|
-
return hostname;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (hostname.charAt(0) === '[' && hostname.charAt(hostname.length - 1) === ']') {
|
|
153
|
-
hostname = hostname.slice(1, -1);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return unmapIPv4MappedIPv6(hostname.replace(/\.+$/, ''));
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default function shouldBypassProxy(location) {
|
|
160
|
-
let parsed;
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
parsed = new URL(location);
|
|
164
|
-
} catch (_err) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
|
|
169
|
-
|
|
170
|
-
if (!noProxy) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (noProxy === '*') {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const port =
|
|
179
|
-
Number.parseInt(parsed.port, 10) || DEFAULT_PORTS[parsed.protocol.split(':', 1)[0]] || 0;
|
|
180
|
-
|
|
181
|
-
const hostname = normalizeNoProxyHost(parsed.hostname.toLowerCase());
|
|
182
|
-
|
|
183
|
-
return noProxy.split(/[\s,]+/).some((entry) => {
|
|
184
|
-
if (!entry) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let [entryHost, entryPort] = parseNoProxyEntry(entry);
|
|
189
|
-
|
|
190
|
-
entryHost = normalizeNoProxyHost(entryHost);
|
|
191
|
-
|
|
192
|
-
if (!entryHost) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (entryPort && entryPort !== port) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (entryHost.charAt(0) === '*') {
|
|
201
|
-
entryHost = entryHost.slice(1);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (entryHost.charAt(0) === '.') {
|
|
205
|
-
return hostname.endsWith(entryHost);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return hostname === entryHost || (isLoopback(hostname) && isLoopback(entryHost));
|
|
209
|
-
});
|
|
210
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Calculate data maxRate
|
|
5
|
-
* @param {Number} [samplesCount= 10]
|
|
6
|
-
* @param {Number} [min= 1000]
|
|
7
|
-
* @returns {Function}
|
|
8
|
-
*/
|
|
9
|
-
function speedometer(samplesCount, min) {
|
|
10
|
-
samplesCount = samplesCount || 10;
|
|
11
|
-
const bytes = new Array(samplesCount);
|
|
12
|
-
const timestamps = new Array(samplesCount);
|
|
13
|
-
let head = 0;
|
|
14
|
-
let tail = 0;
|
|
15
|
-
let firstSampleTS;
|
|
16
|
-
|
|
17
|
-
min = min !== undefined ? min : 1000;
|
|
18
|
-
|
|
19
|
-
return function push(chunkLength) {
|
|
20
|
-
const now = Date.now();
|
|
21
|
-
|
|
22
|
-
const startedAt = timestamps[tail];
|
|
23
|
-
|
|
24
|
-
if (!firstSampleTS) {
|
|
25
|
-
firstSampleTS = now;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
bytes[head] = chunkLength;
|
|
29
|
-
timestamps[head] = now;
|
|
30
|
-
|
|
31
|
-
let i = tail;
|
|
32
|
-
let bytesCount = 0;
|
|
33
|
-
|
|
34
|
-
while (i !== head) {
|
|
35
|
-
bytesCount += bytes[i++];
|
|
36
|
-
i = i % samplesCount;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
head = (head + 1) % samplesCount;
|
|
40
|
-
|
|
41
|
-
if (head === tail) {
|
|
42
|
-
tail = (tail + 1) % samplesCount;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (now - firstSampleTS < min) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const passed = startedAt && now - startedAt;
|
|
50
|
-
|
|
51
|
-
return passed ? Math.round((bytesCount * 1000) / passed) : undefined;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default speedometer;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
5
|
-
*
|
|
6
|
-
* Common use case would be to use `Function.prototype.apply`.
|
|
7
|
-
*
|
|
8
|
-
* ```js
|
|
9
|
-
* function f(x, y, z) {}
|
|
10
|
-
* const args = [1, 2, 3];
|
|
11
|
-
* f.apply(null, args);
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* With `spread` this example can be re-written.
|
|
15
|
-
*
|
|
16
|
-
* ```js
|
|
17
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param {Function} callback
|
|
21
|
-
*
|
|
22
|
-
* @returns {Function}
|
|
23
|
-
*/
|
|
24
|
-
export default function spread(callback) {
|
|
25
|
-
return function wrap(arr) {
|
|
26
|
-
return callback.apply(null, arr);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle decorator
|
|
3
|
-
* @param {Function} fn
|
|
4
|
-
* @param {Number} freq
|
|
5
|
-
* @return {Function}
|
|
6
|
-
*/
|
|
7
|
-
function throttle(fn, freq) {
|
|
8
|
-
let timestamp = 0;
|
|
9
|
-
let threshold = 1000 / freq;
|
|
10
|
-
let lastArgs;
|
|
11
|
-
let timer;
|
|
12
|
-
|
|
13
|
-
const invoke = (args, now = Date.now()) => {
|
|
14
|
-
timestamp = now;
|
|
15
|
-
lastArgs = null;
|
|
16
|
-
if (timer) {
|
|
17
|
-
clearTimeout(timer);
|
|
18
|
-
timer = null;
|
|
19
|
-
}
|
|
20
|
-
fn(...args);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const throttled = (...args) => {
|
|
24
|
-
const now = Date.now();
|
|
25
|
-
const passed = now - timestamp;
|
|
26
|
-
if (passed >= threshold) {
|
|
27
|
-
invoke(args, now);
|
|
28
|
-
} else {
|
|
29
|
-
lastArgs = args;
|
|
30
|
-
if (!timer) {
|
|
31
|
-
timer = setTimeout(() => {
|
|
32
|
-
timer = null;
|
|
33
|
-
invoke(lastArgs);
|
|
34
|
-
}, threshold - passed);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const flush = () => lastArgs && invoke(lastArgs);
|
|
40
|
-
|
|
41
|
-
return [throttled, flush];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default throttle;
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import utils from '../utils.js';
|
|
4
|
-
import AxiosError from '../core/AxiosError.js';
|
|
5
|
-
// temporary hotfix to avoid circular references until AxiosURLSearchParams is refactored
|
|
6
|
-
import PlatformFormData from '../platform/node/classes/FormData.js';
|
|
7
|
-
|
|
8
|
-
// Default nesting limit shared with the inverse transform (formDataToJSON) so
|
|
9
|
-
// the FormData <-> JSON round-trip stays symmetric.
|
|
10
|
-
export const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Determines if the given thing is a array or js object.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} thing - The object or array to be visited.
|
|
16
|
-
*
|
|
17
|
-
* @returns {boolean}
|
|
18
|
-
*/
|
|
19
|
-
function isVisitable(thing) {
|
|
20
|
-
return utils.isPlainObject(thing) || utils.isArray(thing);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* It removes the brackets from the end of a string
|
|
25
|
-
*
|
|
26
|
-
* @param {string} key - The key of the parameter.
|
|
27
|
-
*
|
|
28
|
-
* @returns {string} the key without the brackets.
|
|
29
|
-
*/
|
|
30
|
-
function removeBrackets(key) {
|
|
31
|
-
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* It takes a path, a key, and a boolean, and returns a string
|
|
36
|
-
*
|
|
37
|
-
* @param {string} path - The path to the current key.
|
|
38
|
-
* @param {string} key - The key of the current object being iterated over.
|
|
39
|
-
* @param {string} dots - If true, the key will be rendered with dots instead of brackets.
|
|
40
|
-
*
|
|
41
|
-
* @returns {string} The path to the current key.
|
|
42
|
-
*/
|
|
43
|
-
function renderKey(path, key, dots) {
|
|
44
|
-
if (!path) return key;
|
|
45
|
-
return path
|
|
46
|
-
.concat(key)
|
|
47
|
-
.map(function each(token, i) {
|
|
48
|
-
// eslint-disable-next-line no-param-reassign
|
|
49
|
-
token = removeBrackets(token);
|
|
50
|
-
return !dots && i ? '[' + token + ']' : token;
|
|
51
|
-
})
|
|
52
|
-
.join(dots ? '.' : '');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* If the array is an array and none of its elements are visitable, then it's a flat array.
|
|
57
|
-
*
|
|
58
|
-
* @param {Array<any>} arr - The array to check
|
|
59
|
-
*
|
|
60
|
-
* @returns {boolean}
|
|
61
|
-
*/
|
|
62
|
-
function isFlatArray(arr) {
|
|
63
|
-
return utils.isArray(arr) && !arr.some(isVisitable);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
|
67
|
-
return /^is[A-Z]/.test(prop);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Convert a data object to FormData
|
|
72
|
-
*
|
|
73
|
-
* @param {Object} obj
|
|
74
|
-
* @param {?Object} [formData]
|
|
75
|
-
* @param {?Object} [options]
|
|
76
|
-
* @param {Function} [options.visitor]
|
|
77
|
-
* @param {Boolean} [options.metaTokens = true]
|
|
78
|
-
* @param {Boolean} [options.dots = false]
|
|
79
|
-
* @param {?Boolean} [options.indexes = false]
|
|
80
|
-
*
|
|
81
|
-
* @returns {Object}
|
|
82
|
-
**/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* It converts an object into a FormData object
|
|
86
|
-
*
|
|
87
|
-
* @param {Object<any, any>} obj - The object to convert to form data.
|
|
88
|
-
* @param {string} formData - The FormData object to append to.
|
|
89
|
-
* @param {Object<string, any>} options
|
|
90
|
-
*
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
function toFormData(obj, formData, options) {
|
|
94
|
-
if (!utils.isObject(obj)) {
|
|
95
|
-
throw new TypeError('target must be an object');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// eslint-disable-next-line no-param-reassign
|
|
99
|
-
formData = formData || new (PlatformFormData || FormData)();
|
|
100
|
-
|
|
101
|
-
// eslint-disable-next-line no-param-reassign
|
|
102
|
-
options = utils.toFlatObject(
|
|
103
|
-
options,
|
|
104
|
-
{
|
|
105
|
-
metaTokens: true,
|
|
106
|
-
dots: false,
|
|
107
|
-
indexes: false,
|
|
108
|
-
},
|
|
109
|
-
false,
|
|
110
|
-
function defined(option, source) {
|
|
111
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
112
|
-
return !utils.isUndefined(source[option]);
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const metaTokens = options.metaTokens;
|
|
117
|
-
// eslint-disable-next-line no-use-before-define
|
|
118
|
-
const visitor = options.visitor || defaultVisitor;
|
|
119
|
-
const dots = options.dots;
|
|
120
|
-
const indexes = options.indexes;
|
|
121
|
-
const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
|
|
122
|
-
const maxDepth = options.maxDepth === undefined ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
|
|
123
|
-
const useBlob = _Blob && utils.isSpecCompliantForm(formData);
|
|
124
|
-
const stack = [];
|
|
125
|
-
|
|
126
|
-
if (!utils.isFunction(visitor)) {
|
|
127
|
-
throw new TypeError('visitor must be a function');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function convertValue(value) {
|
|
131
|
-
if (value === null) return '';
|
|
132
|
-
|
|
133
|
-
if (utils.isDate(value)) {
|
|
134
|
-
return value.toISOString();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (utils.isBoolean(value)) {
|
|
138
|
-
return value.toString();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (!useBlob && utils.isBlob(value)) {
|
|
142
|
-
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
|
146
|
-
if (useBlob && typeof _Blob === 'function') {
|
|
147
|
-
return new _Blob([value]);
|
|
148
|
-
}
|
|
149
|
-
if (typeof Buffer !== 'undefined') {
|
|
150
|
-
return Buffer.from(value);
|
|
151
|
-
}
|
|
152
|
-
throw new AxiosError('Blob is not supported. Use a Buffer instead.', AxiosError.ERR_NOT_SUPPORT);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return value;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function throwIfMaxDepthExceeded(depth) {
|
|
159
|
-
if (depth > maxDepth) {
|
|
160
|
-
throw new AxiosError(
|
|
161
|
-
'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
|
|
162
|
-
AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function stringifyWithDepthLimit(value, depth) {
|
|
168
|
-
if (maxDepth === Infinity) {
|
|
169
|
-
return JSON.stringify(value);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const ancestors = [];
|
|
173
|
-
|
|
174
|
-
return JSON.stringify(value, function limitDepth(_key, currentValue) {
|
|
175
|
-
if (!utils.isObject(currentValue)) {
|
|
176
|
-
return currentValue;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
|
|
180
|
-
ancestors.pop();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
ancestors.push(currentValue);
|
|
184
|
-
throwIfMaxDepthExceeded(depth + ancestors.length - 1);
|
|
185
|
-
|
|
186
|
-
return currentValue;
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Default visitor.
|
|
192
|
-
*
|
|
193
|
-
* @param {*} value
|
|
194
|
-
* @param {String|Number} key
|
|
195
|
-
* @param {Array<String|Number>} path
|
|
196
|
-
* @this {FormData}
|
|
197
|
-
*
|
|
198
|
-
* @returns {boolean} return true to visit the each prop of the value recursively
|
|
199
|
-
*/
|
|
200
|
-
function defaultVisitor(value, key, path) {
|
|
201
|
-
let arr = value;
|
|
202
|
-
|
|
203
|
-
if (utils.isReactNative(formData) && utils.isReactNativeBlob(value)) {
|
|
204
|
-
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (value && !path && typeof value === 'object') {
|
|
209
|
-
if (utils.endsWith(key, '{}')) {
|
|
210
|
-
// eslint-disable-next-line no-param-reassign
|
|
211
|
-
key = metaTokens ? key : key.slice(0, -2);
|
|
212
|
-
// eslint-disable-next-line no-param-reassign
|
|
213
|
-
value = stringifyWithDepthLimit(value, 1);
|
|
214
|
-
} else if (
|
|
215
|
-
(utils.isArray(value) && isFlatArray(value)) ||
|
|
216
|
-
((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
|
|
217
|
-
) {
|
|
218
|
-
// eslint-disable-next-line no-param-reassign
|
|
219
|
-
key = removeBrackets(key);
|
|
220
|
-
|
|
221
|
-
arr.forEach(function each(el, index) {
|
|
222
|
-
!(utils.isUndefined(el) || el === null) &&
|
|
223
|
-
formData.append(
|
|
224
|
-
// eslint-disable-next-line no-nested-ternary
|
|
225
|
-
indexes === true
|
|
226
|
-
? renderKey([key], index, dots)
|
|
227
|
-
: indexes === null
|
|
228
|
-
? key
|
|
229
|
-
: key + '[]',
|
|
230
|
-
convertValue(el)
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (isVisitable(value)) {
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
242
|
-
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const exposedHelpers = Object.assign(predicates, {
|
|
247
|
-
defaultVisitor,
|
|
248
|
-
convertValue,
|
|
249
|
-
isVisitable,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
function build(value, path, depth = 0) {
|
|
253
|
-
if (utils.isUndefined(value)) return;
|
|
254
|
-
|
|
255
|
-
throwIfMaxDepthExceeded(depth);
|
|
256
|
-
|
|
257
|
-
if (stack.indexOf(value) !== -1) {
|
|
258
|
-
throw new Error('Circular reference detected in ' + path.join('.'));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
stack.push(value);
|
|
262
|
-
|
|
263
|
-
utils.forEach(value, function each(el, key) {
|
|
264
|
-
const result =
|
|
265
|
-
!(utils.isUndefined(el) || el === null) &&
|
|
266
|
-
visitor.call(formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|
267
|
-
|
|
268
|
-
if (result === true) {
|
|
269
|
-
build(el, path ? path.concat(key) : [key], depth + 1);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
stack.pop();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (!utils.isObject(obj)) {
|
|
277
|
-
throw new TypeError('data must be an object');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
build(obj);
|
|
281
|
-
|
|
282
|
-
return formData;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export default toFormData;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import utils from '../utils.js';
|
|
4
|
-
import toFormData from './toFormData.js';
|
|
5
|
-
import platform from '../platform/index.js';
|
|
6
|
-
|
|
7
|
-
export default function toURLEncodedForm(data, options) {
|
|
8
|
-
return toFormData(data, new platform.classes.URLSearchParams(), {
|
|
9
|
-
visitor: function (value, key, path, helpers) {
|
|
10
|
-
if (platform.isNode && utils.isBuffer(value)) {
|
|
11
|
-
this.append(key, value.toString('base64'));
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
|
16
|
-
},
|
|
17
|
-
...options,
|
|
18
|
-
});
|
|
19
|
-
}
|