@gscdump/cli 0.8.0 → 0.8.1
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 +81 -14
- package/dist/THIRD-PARTY-LICENSES.md +155 -0
- package/dist/_chunks/config.mjs +45 -0
- package/dist/_chunks/libs/destr.mjs +42 -0
- package/dist/_chunks/libs/node-fetch-native.mjs +4136 -0
- package/dist/_chunks/libs/ofetch.mjs +417 -0
- package/dist/_chunks/rolldown-runtime.mjs +13 -0
- package/dist/index.mjs +2831 -436
- package/package.json +8 -8
- package/LICENSE +0 -21
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { i as r$1, n as T, r as n } from "./node-fetch-native.mjs";
|
|
2
|
+
import { t as destr } from "./destr.mjs";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
String.fromCharCode;
|
|
6
|
+
const HASH_RE = /#/g;
|
|
7
|
+
const AMPERSAND_RE = /&/g;
|
|
8
|
+
const SLASH_RE = /\//g;
|
|
9
|
+
const EQUAL_RE = /=/g;
|
|
10
|
+
const PLUS_RE = /\+/g;
|
|
11
|
+
const ENC_CARET_RE = /%5e/gi;
|
|
12
|
+
const ENC_BACKTICK_RE = /%60/gi;
|
|
13
|
+
const ENC_PIPE_RE = /%7c/gi;
|
|
14
|
+
const ENC_SPACE_RE = /%20/gi;
|
|
15
|
+
function encode(text) {
|
|
16
|
+
return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
|
|
17
|
+
}
|
|
18
|
+
function encodeQueryValue(input) {
|
|
19
|
+
return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
|
|
20
|
+
}
|
|
21
|
+
function encodeQueryKey(text) {
|
|
22
|
+
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
|
23
|
+
}
|
|
24
|
+
function decode(text = "") {
|
|
25
|
+
try {
|
|
26
|
+
return decodeURIComponent("" + text);
|
|
27
|
+
} catch {
|
|
28
|
+
return "" + text;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function decodeQueryKey(text) {
|
|
32
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
33
|
+
}
|
|
34
|
+
function decodeQueryValue(text) {
|
|
35
|
+
return decode(text.replace(PLUS_RE, " "));
|
|
36
|
+
}
|
|
37
|
+
function parseQuery(parametersString = "") {
|
|
38
|
+
const object = /* @__PURE__ */ Object.create(null);
|
|
39
|
+
if (parametersString[0] === "?") parametersString = parametersString.slice(1);
|
|
40
|
+
for (const parameter of parametersString.split("&")) {
|
|
41
|
+
const s = parameter.match(/([^=]+)=?(.*)/) || [];
|
|
42
|
+
if (s.length < 2) continue;
|
|
43
|
+
const key = decodeQueryKey(s[1]);
|
|
44
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
45
|
+
const value = decodeQueryValue(s[2] || "");
|
|
46
|
+
if (object[key] === void 0) object[key] = value;
|
|
47
|
+
else if (Array.isArray(object[key])) object[key].push(value);
|
|
48
|
+
else object[key] = [object[key], value];
|
|
49
|
+
}
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
function encodeQueryItem(key, value) {
|
|
53
|
+
if (typeof value === "number" || typeof value === "boolean") value = String(value);
|
|
54
|
+
if (!value) return encodeQueryKey(key);
|
|
55
|
+
if (Array.isArray(value)) return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
|
|
56
|
+
return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
|
|
57
|
+
}
|
|
58
|
+
function stringifyQuery(query) {
|
|
59
|
+
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
|
|
60
|
+
}
|
|
61
|
+
const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
|
|
62
|
+
const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
|
|
63
|
+
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
|
|
64
|
+
const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
|
|
65
|
+
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
66
|
+
function hasProtocol(inputString, opts = {}) {
|
|
67
|
+
if (typeof opts === "boolean") opts = { acceptRelative: opts };
|
|
68
|
+
if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
|
|
69
|
+
return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
|
|
70
|
+
}
|
|
71
|
+
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
72
|
+
if (!respectQueryAndFragment) return input.endsWith("/");
|
|
73
|
+
return TRAILING_SLASH_RE.test(input);
|
|
74
|
+
}
|
|
75
|
+
function withoutTrailingSlash(input = "", respectQueryAndFragment) {
|
|
76
|
+
if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
77
|
+
if (!hasTrailingSlash(input, true)) return input || "/";
|
|
78
|
+
let path = input;
|
|
79
|
+
let fragment = "";
|
|
80
|
+
const fragmentIndex = input.indexOf("#");
|
|
81
|
+
if (fragmentIndex !== -1) {
|
|
82
|
+
path = input.slice(0, fragmentIndex);
|
|
83
|
+
fragment = input.slice(fragmentIndex);
|
|
84
|
+
}
|
|
85
|
+
const [s0, ...s] = path.split("?");
|
|
86
|
+
return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
87
|
+
}
|
|
88
|
+
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
89
|
+
if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
|
|
90
|
+
if (hasTrailingSlash(input, true)) return input || "/";
|
|
91
|
+
let path = input;
|
|
92
|
+
let fragment = "";
|
|
93
|
+
const fragmentIndex = input.indexOf("#");
|
|
94
|
+
if (fragmentIndex !== -1) {
|
|
95
|
+
path = input.slice(0, fragmentIndex);
|
|
96
|
+
fragment = input.slice(fragmentIndex);
|
|
97
|
+
if (!path) return fragment;
|
|
98
|
+
}
|
|
99
|
+
const [s0, ...s] = path.split("?");
|
|
100
|
+
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
101
|
+
}
|
|
102
|
+
function withBase(input, base) {
|
|
103
|
+
if (isEmptyURL(base) || hasProtocol(input)) return input;
|
|
104
|
+
const _base = withoutTrailingSlash(base);
|
|
105
|
+
if (input.startsWith(_base)) {
|
|
106
|
+
const nextChar = input[_base.length];
|
|
107
|
+
if (!nextChar || nextChar === "/" || nextChar === "?") return input;
|
|
108
|
+
}
|
|
109
|
+
return joinURL(_base, input);
|
|
110
|
+
}
|
|
111
|
+
function withQuery(input, query) {
|
|
112
|
+
const parsed = parseURL(input);
|
|
113
|
+
parsed.search = stringifyQuery({
|
|
114
|
+
...parseQuery(parsed.search),
|
|
115
|
+
...query
|
|
116
|
+
});
|
|
117
|
+
return stringifyParsedURL(parsed);
|
|
118
|
+
}
|
|
119
|
+
function isEmptyURL(url) {
|
|
120
|
+
return !url || url === "/";
|
|
121
|
+
}
|
|
122
|
+
function isNonEmptyURL(url) {
|
|
123
|
+
return url && url !== "/";
|
|
124
|
+
}
|
|
125
|
+
function joinURL(base, ...input) {
|
|
126
|
+
let url = base || "";
|
|
127
|
+
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
|
|
128
|
+
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
129
|
+
url = withTrailingSlash(url) + _segment;
|
|
130
|
+
} else url = segment;
|
|
131
|
+
return url;
|
|
132
|
+
}
|
|
133
|
+
const protocolRelative = Symbol.for("ufo:protocolRelative");
|
|
134
|
+
function parseURL(input = "", defaultProto) {
|
|
135
|
+
const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
|
|
136
|
+
if (_specialProtoMatch) {
|
|
137
|
+
const [, _proto, _pathname = ""] = _specialProtoMatch;
|
|
138
|
+
return {
|
|
139
|
+
protocol: _proto.toLowerCase(),
|
|
140
|
+
pathname: _pathname,
|
|
141
|
+
href: _proto + _pathname,
|
|
142
|
+
auth: "",
|
|
143
|
+
host: "",
|
|
144
|
+
search: "",
|
|
145
|
+
hash: ""
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
|
149
|
+
const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
|
|
150
|
+
let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
|
|
151
|
+
if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
|
|
152
|
+
const { pathname, search, hash } = parsePath(path);
|
|
153
|
+
return {
|
|
154
|
+
protocol: protocol.toLowerCase(),
|
|
155
|
+
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
|
156
|
+
host,
|
|
157
|
+
pathname,
|
|
158
|
+
search,
|
|
159
|
+
hash,
|
|
160
|
+
[protocolRelative]: !protocol
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function parsePath(input = "") {
|
|
164
|
+
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
|
165
|
+
return {
|
|
166
|
+
pathname,
|
|
167
|
+
search,
|
|
168
|
+
hash
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function stringifyParsedURL(parsed) {
|
|
172
|
+
const pathname = parsed.pathname || "";
|
|
173
|
+
const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
|
|
174
|
+
const hash = parsed.hash || "";
|
|
175
|
+
const auth = parsed.auth ? parsed.auth + "@" : "";
|
|
176
|
+
const host = parsed.host || "";
|
|
177
|
+
return (parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "") + auth + host + pathname + search + hash;
|
|
178
|
+
}
|
|
179
|
+
var FetchError = class extends Error {
|
|
180
|
+
constructor(message, opts) {
|
|
181
|
+
super(message, opts);
|
|
182
|
+
this.name = "FetchError";
|
|
183
|
+
if (opts?.cause && !this.cause) this.cause = opts.cause;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
function createFetchError(ctx) {
|
|
187
|
+
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
188
|
+
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
189
|
+
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
190
|
+
const fetchError = new FetchError(`${`[${method}] ${JSON.stringify(url)}`}: ${ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>"}${errorMessage ? ` ${errorMessage}` : ""}`, ctx.error ? { cause: ctx.error } : void 0);
|
|
191
|
+
for (const key of [
|
|
192
|
+
"request",
|
|
193
|
+
"options",
|
|
194
|
+
"response"
|
|
195
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
196
|
+
return ctx[key];
|
|
197
|
+
} });
|
|
198
|
+
for (const [key, refKey] of [
|
|
199
|
+
["data", "_data"],
|
|
200
|
+
["status", "status"],
|
|
201
|
+
["statusCode", "status"],
|
|
202
|
+
["statusText", "statusText"],
|
|
203
|
+
["statusMessage", "statusText"]
|
|
204
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
205
|
+
return ctx.response && ctx.response[refKey];
|
|
206
|
+
} });
|
|
207
|
+
return fetchError;
|
|
208
|
+
}
|
|
209
|
+
const payloadMethods = new Set(Object.freeze([
|
|
210
|
+
"PATCH",
|
|
211
|
+
"POST",
|
|
212
|
+
"PUT",
|
|
213
|
+
"DELETE"
|
|
214
|
+
]));
|
|
215
|
+
function isPayloadMethod(method = "GET") {
|
|
216
|
+
return payloadMethods.has(method.toUpperCase());
|
|
217
|
+
}
|
|
218
|
+
function isJSONSerializable(value) {
|
|
219
|
+
if (value === void 0) return false;
|
|
220
|
+
const t = typeof value;
|
|
221
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
222
|
+
if (t !== "object") return false;
|
|
223
|
+
if (Array.isArray(value)) return true;
|
|
224
|
+
if (value.buffer) return false;
|
|
225
|
+
if (value instanceof FormData || value instanceof URLSearchParams) return false;
|
|
226
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
227
|
+
}
|
|
228
|
+
const textTypes = /* @__PURE__ */ new Set([
|
|
229
|
+
"image/svg",
|
|
230
|
+
"application/xml",
|
|
231
|
+
"application/xhtml",
|
|
232
|
+
"application/html"
|
|
233
|
+
]);
|
|
234
|
+
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
235
|
+
function detectResponseType(_contentType = "") {
|
|
236
|
+
if (!_contentType) return "json";
|
|
237
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
238
|
+
if (JSON_RE.test(contentType)) return "json";
|
|
239
|
+
if (contentType === "text/event-stream") return "stream";
|
|
240
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
241
|
+
return "blob";
|
|
242
|
+
}
|
|
243
|
+
function resolveFetchOptions(request, input, defaults, Headers) {
|
|
244
|
+
const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
|
|
245
|
+
let query;
|
|
246
|
+
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
247
|
+
...defaults?.params,
|
|
248
|
+
...defaults?.query,
|
|
249
|
+
...input?.params,
|
|
250
|
+
...input?.query
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
...defaults,
|
|
254
|
+
...input,
|
|
255
|
+
query,
|
|
256
|
+
params: query,
|
|
257
|
+
headers
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function mergeHeaders(input, defaults, Headers) {
|
|
261
|
+
if (!defaults) return new Headers(input);
|
|
262
|
+
const headers = new Headers(defaults);
|
|
263
|
+
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
|
|
264
|
+
return headers;
|
|
265
|
+
}
|
|
266
|
+
async function callHooks(context, hooks) {
|
|
267
|
+
if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
|
|
268
|
+
else await hooks(context);
|
|
269
|
+
}
|
|
270
|
+
const retryStatusCodes = /* @__PURE__ */ new Set([
|
|
271
|
+
408,
|
|
272
|
+
409,
|
|
273
|
+
425,
|
|
274
|
+
429,
|
|
275
|
+
500,
|
|
276
|
+
502,
|
|
277
|
+
503,
|
|
278
|
+
504
|
|
279
|
+
]);
|
|
280
|
+
const nullBodyResponses = /* @__PURE__ */ new Set([
|
|
281
|
+
101,
|
|
282
|
+
204,
|
|
283
|
+
205,
|
|
284
|
+
304
|
|
285
|
+
]);
|
|
286
|
+
function createFetch(globalOptions = {}) {
|
|
287
|
+
const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
|
|
288
|
+
async function onError(context) {
|
|
289
|
+
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
290
|
+
if (context.options.retry !== false && !isAbort) {
|
|
291
|
+
let retries;
|
|
292
|
+
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
293
|
+
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
294
|
+
const responseCode = context.response && context.response.status || 500;
|
|
295
|
+
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
296
|
+
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
297
|
+
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
298
|
+
return $fetchRaw(context.request, {
|
|
299
|
+
...context.options,
|
|
300
|
+
retry: retries - 1
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const error = createFetchError(context);
|
|
305
|
+
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
309
|
+
const context = {
|
|
310
|
+
request: _request,
|
|
311
|
+
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
|
|
312
|
+
response: void 0,
|
|
313
|
+
error: void 0
|
|
314
|
+
};
|
|
315
|
+
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
316
|
+
if (context.options.onRequest) {
|
|
317
|
+
await callHooks(context, context.options.onRequest);
|
|
318
|
+
if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
|
|
319
|
+
}
|
|
320
|
+
if (typeof context.request === "string") {
|
|
321
|
+
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
322
|
+
if (context.options.query) {
|
|
323
|
+
context.request = withQuery(context.request, context.options.query);
|
|
324
|
+
delete context.options.query;
|
|
325
|
+
}
|
|
326
|
+
if ("query" in context.options) delete context.options.query;
|
|
327
|
+
if ("params" in context.options) delete context.options.params;
|
|
328
|
+
}
|
|
329
|
+
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
330
|
+
if (isJSONSerializable(context.options.body)) {
|
|
331
|
+
const contentType = context.options.headers.get("content-type");
|
|
332
|
+
if (typeof context.options.body !== "string") context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(context.options.body).toString() : JSON.stringify(context.options.body);
|
|
333
|
+
if (!contentType) context.options.headers.set("content-type", "application/json");
|
|
334
|
+
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
335
|
+
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
336
|
+
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
let abortTimeout;
|
|
340
|
+
if (!context.options.signal && context.options.timeout) {
|
|
341
|
+
const controller = new AbortController();
|
|
342
|
+
abortTimeout = setTimeout(() => {
|
|
343
|
+
const error = /* @__PURE__ */ new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
344
|
+
error.name = "TimeoutError";
|
|
345
|
+
error.code = 23;
|
|
346
|
+
controller.abort(error);
|
|
347
|
+
}, context.options.timeout);
|
|
348
|
+
context.options.signal = controller.signal;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
context.response = await fetch(context.request, context.options);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
context.error = error;
|
|
354
|
+
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
355
|
+
return await onError(context);
|
|
356
|
+
} finally {
|
|
357
|
+
if (abortTimeout) clearTimeout(abortTimeout);
|
|
358
|
+
}
|
|
359
|
+
if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
|
|
360
|
+
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
361
|
+
switch (responseType) {
|
|
362
|
+
case "json": {
|
|
363
|
+
const data = await context.response.text();
|
|
364
|
+
const parseFunction = context.options.parseResponse || destr;
|
|
365
|
+
context.response._data = parseFunction(data);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case "stream":
|
|
369
|
+
context.response._data = context.response.body || context.response._bodyInit;
|
|
370
|
+
break;
|
|
371
|
+
default: context.response._data = await context.response[responseType]();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
375
|
+
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
376
|
+
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
377
|
+
return await onError(context);
|
|
378
|
+
}
|
|
379
|
+
return context.response;
|
|
380
|
+
};
|
|
381
|
+
const $fetch = async function $fetch2(request, options) {
|
|
382
|
+
return (await $fetchRaw(request, options))._data;
|
|
383
|
+
};
|
|
384
|
+
$fetch.raw = $fetchRaw;
|
|
385
|
+
$fetch.native = (...args) => fetch(...args);
|
|
386
|
+
$fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
|
|
387
|
+
...globalOptions,
|
|
388
|
+
...customGlobalOptions,
|
|
389
|
+
defaults: {
|
|
390
|
+
...globalOptions.defaults,
|
|
391
|
+
...customGlobalOptions.defaults,
|
|
392
|
+
...defaultOptions
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return $fetch;
|
|
396
|
+
}
|
|
397
|
+
function createNodeFetch() {
|
|
398
|
+
if (!JSON.parse(process.env.FETCH_KEEP_ALIVE || "false")) return r$1;
|
|
399
|
+
const agentOptions = { keepAlive: true };
|
|
400
|
+
const httpAgent = new http.Agent(agentOptions);
|
|
401
|
+
const httpsAgent = new https.Agent(agentOptions);
|
|
402
|
+
const nodeFetchOptions = { agent(parsedURL) {
|
|
403
|
+
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
|
|
404
|
+
} };
|
|
405
|
+
return function nodeFetchWithKeepAlive(input, init) {
|
|
406
|
+
return r$1(input, {
|
|
407
|
+
...nodeFetchOptions,
|
|
408
|
+
...init
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
const ofetch = createFetch({
|
|
413
|
+
fetch: globalThis.fetch ? (...args) => globalThis.fetch(...args) : createNodeFetch(),
|
|
414
|
+
Headers: globalThis.Headers || n,
|
|
415
|
+
AbortController: globalThis.AbortController || T
|
|
416
|
+
});
|
|
417
|
+
export { ofetch as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
13
|
+
export { __require as n, __exportAll as t };
|