likec4 1.48.0 → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5941 -4496
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1228 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +4649 -1897
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +169 -141
  10. package/dist/THIRD-PARTY-LICENSES.md +1769 -0
  11. package/dist/_chunks/LikeC4.mjs +1154 -202
  12. package/dist/_chunks/binary.mjs +72 -0
  13. package/dist/_chunks/index.d.mts +234 -140
  14. package/dist/_chunks/index2.d.mts +2043 -1828
  15. package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
  27. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  28. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -10
  29. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  30. package/dist/_chunks/libs/ajv.mjs +1 -777
  31. package/dist/_chunks/libs/atomically.mjs +1 -362
  32. package/dist/_chunks/libs/birpc.mjs +1 -201
  33. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  34. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  35. package/dist/_chunks/libs/conf.mjs +1 -2258
  36. package/dist/_chunks/libs/defu.mjs +1 -42
  37. package/dist/_chunks/libs/esm-env.mjs +1 -5
  38. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  39. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  40. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  41. package/dist/_chunks/libs/get-port.mjs +1 -107
  42. package/dist/_chunks/libs/is-docker.mjs +1 -26
  43. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  44. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  45. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  46. package/dist/_chunks/libs/isexe.mjs +1 -127
  47. package/dist/_chunks/libs/json5.mjs +14 -959
  48. package/dist/_chunks/libs/khroma.mjs +1 -605
  49. package/dist/_chunks/libs/ky.mjs +2 -807
  50. package/dist/_chunks/libs/langium.d.mts +2913 -2876
  51. package/dist/_chunks/libs/langium.mjs +33 -20351
  52. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  53. package/dist/_chunks/libs/p-limit.mjs +1 -120
  54. package/dist/_chunks/libs/p-queue.mjs +1 -449
  55. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  56. package/dist/_chunks/libs/package-up.mjs +1 -10
  57. package/dist/_chunks/libs/pako.mjs +1 -0
  58. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  59. package/dist/_chunks/libs/pathe.mjs +1 -0
  60. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  61. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  62. package/dist/_chunks/libs/remeda.mjs +2 -690
  63. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  64. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  65. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  66. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  67. package/dist/_chunks/libs/ufo.mjs +1 -240
  68. package/dist/_chunks/libs/which.mjs +1 -84
  69. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence.mjs +1 -0
  72. package/dist/_chunks/src.mjs +15 -0
  73. package/dist/_chunks/src2.mjs +499 -0
  74. package/dist/cli/index.mjs +77 -1952
  75. package/dist/config/index.d.mts +2 -2
  76. package/dist/config/index.mjs +1 -6
  77. package/dist/index.d.mts +150 -7
  78. package/dist/index.mjs +1 -21
  79. package/dist/model/builder.mjs +1 -3
  80. package/dist/model/index.d.mts +57 -3
  81. package/dist/model/index.mjs +1 -5
  82. package/dist/vite-plugin/index.d.mts +7 -3
  83. package/dist/vite-plugin/index.mjs +1 -22
  84. package/dist/vite-plugin/internal.d.mts +6 -7
  85. package/dist/vite-plugin/internal.mjs +1 -68
  86. package/package.json +64 -45
  87. package/react/{index.d.ts → index.d.mts} +114 -72
  88. package/react/{index.js → index.mjs} +21320 -22041
  89. package/react/package.json +2 -5
  90. package/vite-plugin-modules.d.ts +10 -5
  91. package/dist/_chunks/LikeC4.d.mts +0 -121
  92. package/dist/_chunks/config-app.prod.d.mts +0 -18
  93. package/dist/_chunks/config-app.prod.mjs +0 -188
  94. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  95. package/dist/_chunks/define-config.mjs +0 -409
  96. package/dist/_chunks/index3.d.mts +0 -60
  97. package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -3969
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/libs/nanostores.d.mts +0 -63
  101. package/dist/_chunks/libs/nanostores.mjs +0 -198
  102. package/dist/_chunks/model.mjs +0 -12
  103. package/dist/_chunks/module.d.mts +0 -71
  104. package/dist/_chunks/module.mjs +0 -18657
  105. package/dist/_chunks/plugin.mjs +0 -996
  106. package/dist/_chunks/sequence-view.mjs +0 -575
  107. package/dist/_chunks/vite-build.mjs +0 -69
  108. package/dist/_chunks/vite-dev.mjs +0 -79
  109. package/dist/_chunks/vite-preview.mjs +0 -27
  110. package/dist/language/module.d.mts +0 -5
  111. package/dist/language/module.mjs +0 -20
  112. package/dist/vite/vite-build.d.mts +0 -26
  113. package/dist/vite/vite-build.mjs +0 -27
  114. package/dist/vite/vite-dev.d.mts +0 -34
  115. package/dist/vite/vite-dev.mjs +0 -29
  116. package/dist/vite/vite-preview.d.mts +0 -20
  117. package/dist/vite/vite-preview.mjs +0 -26
  118. /package/dist/_chunks/{index4.d.mts → libs/@chevrotain/types.d.mts} +0 -0
@@ -1,808 +1,3 @@
1
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/errors/HTTPError.js
2
- var HTTPError = class extends Error {
3
- response;
4
- request;
5
- options;
6
- constructor(response, request, options) {
7
- const status = `${response.status || response.status === 0 ? response.status : ""} ${response.statusText ?? ""}`.trim();
8
- const reason = status ? `status code ${status}` : "an unknown error";
9
- super(`Request failed with ${reason}: ${request.method} ${request.url}`);
10
- this.name = "HTTPError";
11
- this.response = response;
12
- this.request = request;
13
- this.options = options;
14
- }
15
- };
16
-
17
- //#endregion
18
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/errors/NonError.js
19
- /**
20
- Wrapper for non-Error values that were thrown.
21
-
22
- In JavaScript, any value can be thrown (not just Error instances). This class wraps such values to ensure consistent error handling.
23
- */
24
- var NonError = class extends Error {
25
- name = "NonError";
26
- value;
27
- constructor(value) {
28
- let message = "Non-error value was thrown";
29
- try {
30
- if (typeof value === "string") message = value;
31
- else if (value && typeof value === "object" && "message" in value && typeof value.message === "string") message = value.message;
32
- } catch {}
33
- super(message);
34
- this.value = value;
35
- }
36
- };
37
-
38
- //#endregion
39
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/errors/ForceRetryError.js
40
- /**
41
- Internal error used to signal a forced retry from afterResponse hooks.
42
- This is thrown when a user returns ky.retry() from an afterResponse hook.
43
- */
44
- var ForceRetryError = class extends Error {
45
- name = "ForceRetryError";
46
- customDelay;
47
- code;
48
- customRequest;
49
- constructor(options) {
50
- const cause = options?.cause ? options.cause instanceof Error ? options.cause : new NonError(options.cause) : void 0;
51
- super(options?.code ? `Forced retry: ${options.code}` : "Forced retry", cause ? { cause } : void 0);
52
- this.customDelay = options?.delay;
53
- this.code = options?.code;
54
- this.customRequest = options?.request;
55
- }
56
- };
57
-
58
- //#endregion
59
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/core/constants.js
60
- const supportsRequestStreams = (() => {
61
- let duplexAccessed = false;
62
- let hasContentType = false;
63
- const supportsReadableStream = typeof globalThis.ReadableStream === "function";
64
- const supportsRequest = typeof globalThis.Request === "function";
65
- if (supportsReadableStream && supportsRequest) try {
66
- hasContentType = new globalThis.Request("https://empty.invalid", {
67
- body: new globalThis.ReadableStream(),
68
- method: "POST",
69
- get duplex() {
70
- duplexAccessed = true;
71
- return "half";
72
- }
73
- }).headers.has("Content-Type");
74
- } catch (error) {
75
- if (error instanceof Error && error.message === "unsupported BodyInit type") return false;
76
- throw error;
77
- }
78
- return duplexAccessed && !hasContentType;
79
- })();
80
- const supportsAbortController = typeof globalThis.AbortController === "function";
81
- const supportsAbortSignal = typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortSignal.any === "function";
82
- const supportsResponseStreams = typeof globalThis.ReadableStream === "function";
83
- const supportsFormData = typeof globalThis.FormData === "function";
84
- const requestMethods = [
85
- "get",
86
- "post",
87
- "put",
88
- "patch",
89
- "head",
90
- "delete"
91
- ];
92
- const validate = () => void 0;
93
- validate();
94
- const responseTypes = {
95
- json: "application/json",
96
- text: "text/*",
97
- formData: "multipart/form-data",
98
- arrayBuffer: "*/*",
99
- blob: "*/*",
100
- bytes: "*/*"
101
- };
102
- const maxSafeTimeout = 2147483647;
103
- const usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
104
- const stop = Symbol("stop");
105
- /**
106
- Marker returned by ky.retry() to signal a forced retry from afterResponse hooks.
107
- */
108
- var RetryMarker = class {
109
- options;
110
- constructor(options) {
111
- this.options = options;
112
- }
113
- };
114
- /**
115
- Force a retry from an `afterResponse` hook.
116
-
117
- This allows you to retry a request based on the response content, even if the response has a successful status code. The retry will respect the `retry.limit` option and skip the `shouldRetry` check. The forced retry is observable in `beforeRetry` hooks, where the error will be a `ForceRetryError`.
118
-
119
- @param options - Optional configuration for the retry.
120
-
121
- @example
122
- ```
123
- import ky, {isForceRetryError} from 'ky';
124
-
125
- const api = ky.extend({
126
- hooks: {
127
- afterResponse: [
128
- async (request, options, response) => {
129
- // Retry based on response body content
130
- if (response.status === 200) {
131
- const data = await response.clone().json();
132
-
133
- // Simple retry with default delay
134
- if (data.error?.code === 'TEMPORARY_ERROR') {
135
- return ky.retry();
136
- }
137
-
138
- // Retry with custom delay from API response
139
- if (data.error?.code === 'RATE_LIMIT') {
140
- return ky.retry({
141
- delay: data.error.retryAfter * 1000,
142
- code: 'RATE_LIMIT'
143
- });
144
- }
145
-
146
- // Retry with a modified request (e.g., fallback endpoint)
147
- if (data.error?.code === 'FALLBACK_TO_BACKUP') {
148
- return ky.retry({
149
- request: new Request('https://backup-api.com/endpoint', {
150
- method: request.method,
151
- headers: request.headers,
152
- }),
153
- code: 'BACKUP_ENDPOINT'
154
- });
155
- }
156
-
157
- // Retry with refreshed authentication
158
- if (data.error?.code === 'TOKEN_REFRESH' && data.newToken) {
159
- return ky.retry({
160
- request: new Request(request, {
161
- headers: {
162
- ...Object.fromEntries(request.headers),
163
- 'Authorization': `Bearer ${data.newToken}`
164
- }
165
- }),
166
- code: 'TOKEN_REFRESHED'
167
- });
168
- }
169
-
170
- // Retry with cause to preserve error chain
171
- try {
172
- validateResponse(data);
173
- } catch (error) {
174
- return ky.retry({
175
- code: 'VALIDATION_FAILED',
176
- cause: error
177
- });
178
- }
179
- }
180
- }
181
- ],
182
- beforeRetry: [
183
- ({error, retryCount}) => {
184
- // Observable in beforeRetry hooks
185
- if (isForceRetryError(error)) {
186
- console.log(`Forced retry #${retryCount}: ${error.message}`);
187
- // Example output: "Forced retry #1: Forced retry: RATE_LIMIT"
188
- }
189
- }
190
- ]
191
- }
192
- });
193
-
194
- const response = await api.get('https://example.com/api');
195
- ```
196
- */
197
- const retry = (options) => new RetryMarker(options);
198
- const kyOptionKeys = {
199
- json: true,
200
- parseJson: true,
201
- stringifyJson: true,
202
- searchParams: true,
203
- prefixUrl: true,
204
- retry: true,
205
- timeout: true,
206
- hooks: true,
207
- throwHttpErrors: true,
208
- onDownloadProgress: true,
209
- onUploadProgress: true,
210
- fetch: true,
211
- context: true
212
- };
213
- const vendorSpecificOptions = { next: true };
214
- const requestOptionsRegistry = {
215
- method: true,
216
- headers: true,
217
- body: true,
218
- mode: true,
219
- credentials: true,
220
- cache: true,
221
- redirect: true,
222
- referrer: true,
223
- referrerPolicy: true,
224
- integrity: true,
225
- keepalive: true,
226
- signal: true,
227
- window: true,
228
- duplex: true
229
- };
230
-
231
- //#endregion
232
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/body.js
233
- const getBodySize = (body) => {
234
- if (!body) return 0;
235
- if (body instanceof FormData) {
236
- let size = 0;
237
- for (const [key, value] of body) {
238
- size += usualFormBoundarySize;
239
- size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
240
- size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
241
- }
242
- return size;
243
- }
244
- if (body instanceof Blob) return body.size;
245
- if (body instanceof ArrayBuffer) return body.byteLength;
246
- if (typeof body === "string") return new TextEncoder().encode(body).length;
247
- if (body instanceof URLSearchParams) return new TextEncoder().encode(body.toString()).length;
248
- if ("byteLength" in body) return body.byteLength;
249
- if (typeof body === "object" && body !== null) try {
250
- const jsonString = JSON.stringify(body);
251
- return new TextEncoder().encode(jsonString).length;
252
- } catch {
253
- return 0;
254
- }
255
- return 0;
256
- };
257
- const withProgress = (stream, totalBytes, onProgress) => {
258
- let previousChunk;
259
- let transferredBytes = 0;
260
- return stream.pipeThrough(new TransformStream({
261
- transform(currentChunk, controller) {
262
- controller.enqueue(currentChunk);
263
- if (previousChunk) {
264
- transferredBytes += previousChunk.byteLength;
265
- let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
266
- if (percent >= 1) percent = 1 - Number.EPSILON;
267
- onProgress?.({
268
- percent,
269
- totalBytes: Math.max(totalBytes, transferredBytes),
270
- transferredBytes
271
- }, previousChunk);
272
- }
273
- previousChunk = currentChunk;
274
- },
275
- flush() {
276
- if (previousChunk) {
277
- transferredBytes += previousChunk.byteLength;
278
- onProgress?.({
279
- percent: 1,
280
- totalBytes: Math.max(totalBytes, transferredBytes),
281
- transferredBytes
282
- }, previousChunk);
283
- }
284
- }
285
- }));
286
- };
287
- const streamResponse = (response, onDownloadProgress) => {
288
- if (!response.body) return response;
289
- if (response.status === 204) return new Response(null, {
290
- status: response.status,
291
- statusText: response.statusText,
292
- headers: response.headers
293
- });
294
- const totalBytes = Math.max(0, Number(response.headers.get("content-length")) || 0);
295
- return new Response(withProgress(response.body, totalBytes, onDownloadProgress), {
296
- status: response.status,
297
- statusText: response.statusText,
298
- headers: response.headers
299
- });
300
- };
301
- const streamRequest = (request, onUploadProgress, originalBody) => {
302
- if (!request.body) return request;
303
- const totalBytes = getBodySize(originalBody ?? request.body);
304
- return new Request(request, {
305
- duplex: "half",
306
- body: withProgress(request.body, totalBytes, onUploadProgress)
307
- });
308
- };
309
-
310
- //#endregion
311
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/is.js
312
- const isObject = (value) => value !== null && typeof value === "object";
313
-
314
- //#endregion
315
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/merge.js
316
- const validateAndMerge = (...sources) => {
317
- for (const source of sources) if ((!isObject(source) || Array.isArray(source)) && source !== void 0) throw new TypeError("The `options` argument must be an object");
318
- return deepMerge({}, ...sources);
319
- };
320
- const mergeHeaders = (source1 = {}, source2 = {}) => {
321
- const result = new globalThis.Headers(source1);
322
- const isHeadersInstance = source2 instanceof globalThis.Headers;
323
- const source = new globalThis.Headers(source2);
324
- for (const [key, value] of source.entries()) if (isHeadersInstance && value === "undefined" || value === void 0) result.delete(key);
325
- else result.set(key, value);
326
- return result;
327
- };
328
- function newHookValue(original, incoming, property) {
329
- return Object.hasOwn(incoming, property) && incoming[property] === void 0 ? [] : deepMerge(original[property] ?? [], incoming[property] ?? []);
330
- }
331
- const mergeHooks = (original = {}, incoming = {}) => ({
332
- beforeRequest: newHookValue(original, incoming, "beforeRequest"),
333
- beforeRetry: newHookValue(original, incoming, "beforeRetry"),
334
- afterResponse: newHookValue(original, incoming, "afterResponse"),
335
- beforeError: newHookValue(original, incoming, "beforeError")
336
- });
337
- const appendSearchParameters = (target, source) => {
338
- const result = new URLSearchParams();
339
- for (const input of [target, source]) {
340
- if (input === void 0) continue;
341
- if (input instanceof URLSearchParams) for (const [key, value] of input.entries()) result.append(key, value);
342
- else if (Array.isArray(input)) for (const pair of input) {
343
- if (!Array.isArray(pair) || pair.length !== 2) throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
344
- result.append(String(pair[0]), String(pair[1]));
345
- }
346
- else if (isObject(input)) {
347
- for (const [key, value] of Object.entries(input)) if (value !== void 0) result.append(key, String(value));
348
- } else {
349
- const parameters = new URLSearchParams(input);
350
- for (const [key, value] of parameters.entries()) result.append(key, value);
351
- }
352
- }
353
- return result;
354
- };
355
- const deepMerge = (...sources) => {
356
- let returnValue = {};
357
- let headers = {};
358
- let hooks = {};
359
- let searchParameters;
360
- const signals = [];
361
- for (const source of sources) if (Array.isArray(source)) {
362
- if (!Array.isArray(returnValue)) returnValue = [];
363
- returnValue = [...returnValue, ...source];
364
- } else if (isObject(source)) {
365
- for (let [key, value] of Object.entries(source)) {
366
- if (key === "signal" && value instanceof globalThis.AbortSignal) {
367
- signals.push(value);
368
- continue;
369
- }
370
- if (key === "context") {
371
- if (value !== void 0 && value !== null && (!isObject(value) || Array.isArray(value))) throw new TypeError("The `context` option must be an object");
372
- returnValue = {
373
- ...returnValue,
374
- context: value === void 0 || value === null ? {} : {
375
- ...returnValue.context,
376
- ...value
377
- }
378
- };
379
- continue;
380
- }
381
- if (key === "searchParams") {
382
- if (value === void 0 || value === null) searchParameters = void 0;
383
- else searchParameters = searchParameters === void 0 ? value : appendSearchParameters(searchParameters, value);
384
- continue;
385
- }
386
- if (isObject(value) && key in returnValue) value = deepMerge(returnValue[key], value);
387
- returnValue = {
388
- ...returnValue,
389
- [key]: value
390
- };
391
- }
392
- if (isObject(source.hooks)) {
393
- hooks = mergeHooks(hooks, source.hooks);
394
- returnValue.hooks = hooks;
395
- }
396
- if (isObject(source.headers)) {
397
- headers = mergeHeaders(headers, source.headers);
398
- returnValue.headers = headers;
399
- }
400
- }
401
- if (searchParameters !== void 0) returnValue.searchParams = searchParameters;
402
- if (signals.length > 0) if (signals.length === 1) returnValue.signal = signals[0];
403
- else if (supportsAbortSignal) returnValue.signal = AbortSignal.any(signals);
404
- else returnValue.signal = signals.at(-1);
405
- if (returnValue.context === void 0) returnValue.context = {};
406
- return returnValue;
407
- };
408
-
409
- //#endregion
410
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/normalize.js
411
- const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
412
- const defaultRetryOptions = {
413
- limit: 2,
414
- methods: [
415
- "get",
416
- "put",
417
- "head",
418
- "delete",
419
- "options",
420
- "trace"
421
- ],
422
- statusCodes: [
423
- 408,
424
- 413,
425
- 429,
426
- 500,
427
- 502,
428
- 503,
429
- 504
430
- ],
431
- afterStatusCodes: [
432
- 413,
433
- 429,
434
- 503
435
- ],
436
- maxRetryAfter: Number.POSITIVE_INFINITY,
437
- backoffLimit: Number.POSITIVE_INFINITY,
438
- delay: (attemptCount) => .3 * 2 ** (attemptCount - 1) * 1e3,
439
- jitter: void 0,
440
- retryOnTimeout: false
441
- };
442
- const normalizeRetryOptions = (retry = {}) => {
443
- if (typeof retry === "number") return {
444
- ...defaultRetryOptions,
445
- limit: retry
446
- };
447
- if (retry.methods && !Array.isArray(retry.methods)) throw new Error("retry.methods must be an array");
448
- if (retry.statusCodes && !Array.isArray(retry.statusCodes)) throw new Error("retry.statusCodes must be an array");
449
- const normalizedRetry = Object.fromEntries(Object.entries(retry).filter(([, value]) => value !== void 0));
450
- return {
451
- ...defaultRetryOptions,
452
- ...normalizedRetry
453
- };
454
- };
455
-
456
- //#endregion
457
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/errors/TimeoutError.js
458
- var TimeoutError = class extends Error {
459
- request;
460
- constructor(request) {
461
- super(`Request timed out: ${request.method} ${request.url}`);
462
- this.name = "TimeoutError";
463
- this.request = request;
464
- }
465
- };
466
-
467
- //#endregion
468
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/timeout.js
469
- async function timeout(request, init, abortController, options) {
470
- return new Promise((resolve, reject) => {
471
- const timeoutId = setTimeout(() => {
472
- if (abortController) abortController.abort();
473
- reject(new TimeoutError(request));
474
- }, options.timeout);
475
- options.fetch(request, init).then(resolve).catch(reject).then(() => {
476
- clearTimeout(timeoutId);
477
- });
478
- });
479
- }
480
-
481
- //#endregion
482
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/delay.js
483
- async function delay(ms, { signal }) {
484
- return new Promise((resolve, reject) => {
485
- if (signal) {
486
- signal.throwIfAborted();
487
- signal.addEventListener("abort", abortHandler, { once: true });
488
- }
489
- function abortHandler() {
490
- clearTimeout(timeoutId);
491
- reject(signal.reason);
492
- }
493
- const timeoutId = setTimeout(() => {
494
- signal?.removeEventListener("abort", abortHandler);
495
- resolve();
496
- }, ms);
497
- });
498
- }
499
-
500
- //#endregion
501
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/options.js
502
- const findUnknownOptions = (request, options) => {
503
- const unknownOptions = {};
504
- for (const key in options) {
505
- if (!Object.hasOwn(options, key)) continue;
506
- if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && (!(key in request) || key in vendorSpecificOptions)) unknownOptions[key] = options[key];
507
- }
508
- return unknownOptions;
509
- };
510
- const hasSearchParameters = (search) => {
511
- if (search === void 0) return false;
512
- if (Array.isArray(search)) return search.length > 0;
513
- if (search instanceof URLSearchParams) return search.size > 0;
514
- if (typeof search === "object") return Object.keys(search).length > 0;
515
- if (typeof search === "string") return search.trim().length > 0;
516
- return Boolean(search);
517
- };
518
-
519
- //#endregion
520
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/utils/type-guards.js
521
- /**
522
- Type guard to check if an error is an HTTPError.
523
-
524
- @param error - The error to check
525
- @returns `true` if the error is an HTTPError, `false` otherwise
526
-
527
- @example
528
- ```
529
- import ky, {isHTTPError} from 'ky';
530
- try {
531
- const response = await ky.get('/api/data');
532
- } catch (error) {
533
- if (isHTTPError(error)) {
534
- console.log('HTTP error status:', error.response.status);
535
- }
536
- }
537
- ```
538
- */
539
- function isHTTPError(error) {
540
- return error instanceof HTTPError || error?.name === HTTPError.name;
541
- }
542
- /**
543
- Type guard to check if an error is a TimeoutError.
544
-
545
- @param error - The error to check
546
- @returns `true` if the error is a TimeoutError, `false` otherwise
547
-
548
- @example
549
- ```
550
- import ky, {isTimeoutError} from 'ky';
551
- try {
552
- const response = await ky.get('/api/data', { timeout: 1000 });
553
- } catch (error) {
554
- if (isTimeoutError(error)) {
555
- console.log('Request timed out:', error.request.url);
556
- }
557
- }
558
- ```
559
- */
560
- function isTimeoutError(error) {
561
- return error instanceof TimeoutError || error?.name === TimeoutError.name;
562
- }
563
-
564
- //#endregion
565
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/core/Ky.js
566
- var Ky = class Ky {
567
- static create(input, options) {
568
- const ky = new Ky(input, options);
569
- const function_ = async () => {
570
- if (typeof ky.#options.timeout === "number" && ky.#options.timeout > maxSafeTimeout) throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
571
- await Promise.resolve();
572
- let response = await ky.#fetch();
573
- for (const hook of ky.#options.hooks.afterResponse) {
574
- const clonedResponse = ky.#decorateResponse(response.clone());
575
- const modifiedResponse = await hook(ky.request, ky.#getNormalizedOptions(), clonedResponse, { retryCount: ky.#retryCount });
576
- if (modifiedResponse instanceof globalThis.Response) response = modifiedResponse;
577
- if (modifiedResponse instanceof RetryMarker) {
578
- await Promise.all([clonedResponse.body?.cancel(), response.body?.cancel()]);
579
- throw new ForceRetryError(modifiedResponse.options);
580
- }
581
- }
582
- ky.#decorateResponse(response);
583
- if (!response.ok && (typeof ky.#options.throwHttpErrors === "function" ? ky.#options.throwHttpErrors(response.status) : ky.#options.throwHttpErrors)) {
584
- let error = new HTTPError(response, ky.request, ky.#getNormalizedOptions());
585
- for (const hook of ky.#options.hooks.beforeError) error = await hook(error, { retryCount: ky.#retryCount });
586
- throw error;
587
- }
588
- if (ky.#options.onDownloadProgress) {
589
- if (typeof ky.#options.onDownloadProgress !== "function") throw new TypeError("The `onDownloadProgress` option must be a function");
590
- if (!supportsResponseStreams) throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
591
- return streamResponse(response.clone(), ky.#options.onDownloadProgress);
592
- }
593
- return response;
594
- };
595
- const result = ky.#retry(function_).finally(async () => {
596
- const originalRequest = ky.#originalRequest;
597
- const cleanupPromises = [];
598
- if (originalRequest && !originalRequest.bodyUsed) cleanupPromises.push(originalRequest.body?.cancel());
599
- if (!ky.request.bodyUsed) cleanupPromises.push(ky.request.body?.cancel());
600
- await Promise.all(cleanupPromises);
601
- });
602
- for (const [type, mimeType] of Object.entries(responseTypes)) {
603
- if (type === "bytes" && typeof globalThis.Response?.prototype?.bytes !== "function") continue;
604
- result[type] = async () => {
605
- ky.request.headers.set("accept", ky.request.headers.get("accept") || mimeType);
606
- const response = await result;
607
- if (type === "json") {
608
- if (response.status === 204) return "";
609
- const text = await response.text();
610
- if (text === "") return "";
611
- if (options.parseJson) return options.parseJson(text);
612
- return JSON.parse(text);
613
- }
614
- return response[type]();
615
- };
616
- }
617
- return result;
618
- }
619
- static #normalizeSearchParams(searchParams) {
620
- if (searchParams && typeof searchParams === "object" && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => value !== void 0));
621
- return searchParams;
622
- }
623
- request;
624
- #abortController;
625
- #retryCount = 0;
626
- #input;
627
- #options;
628
- #originalRequest;
629
- #userProvidedAbortSignal;
630
- #cachedNormalizedOptions;
631
- constructor(input, options = {}) {
632
- this.#input = input;
633
- this.#options = {
634
- ...options,
635
- headers: mergeHeaders(this.#input.headers, options.headers),
636
- hooks: mergeHooks({
637
- beforeRequest: [],
638
- beforeRetry: [],
639
- beforeError: [],
640
- afterResponse: []
641
- }, options.hooks),
642
- method: normalizeRequestMethod(options.method ?? this.#input.method ?? "GET"),
643
- prefixUrl: String(options.prefixUrl || ""),
644
- retry: normalizeRetryOptions(options.retry),
645
- throwHttpErrors: options.throwHttpErrors ?? true,
646
- timeout: options.timeout ?? 1e4,
647
- fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
648
- context: options.context ?? {}
649
- };
650
- if (typeof this.#input !== "string" && !(this.#input instanceof URL || this.#input instanceof globalThis.Request)) throw new TypeError("`input` must be a string, URL, or Request");
651
- if (this.#options.prefixUrl && typeof this.#input === "string") {
652
- if (this.#input.startsWith("/")) throw new Error("`input` must not begin with a slash when using `prefixUrl`");
653
- if (!this.#options.prefixUrl.endsWith("/")) this.#options.prefixUrl += "/";
654
- this.#input = this.#options.prefixUrl + this.#input;
655
- }
656
- if (supportsAbortController && supportsAbortSignal) {
657
- this.#userProvidedAbortSignal = this.#options.signal ?? this.#input.signal;
658
- this.#abortController = new globalThis.AbortController();
659
- this.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;
660
- }
661
- if (supportsRequestStreams) this.#options.duplex = "half";
662
- if (this.#options.json !== void 0) {
663
- this.#options.body = this.#options.stringifyJson?.(this.#options.json) ?? JSON.stringify(this.#options.json);
664
- this.#options.headers.set("content-type", this.#options.headers.get("content-type") ?? "application/json");
665
- }
666
- const userProvidedContentType = options.headers && new globalThis.Headers(options.headers).has("content-type");
667
- if (this.#input instanceof globalThis.Request && (supportsFormData && this.#options.body instanceof globalThis.FormData || this.#options.body instanceof URLSearchParams) && !userProvidedContentType) this.#options.headers.delete("content-type");
668
- this.request = new globalThis.Request(this.#input, this.#options);
669
- if (hasSearchParameters(this.#options.searchParams)) {
670
- const searchParams = "?" + (typeof this.#options.searchParams === "string" ? this.#options.searchParams.replace(/^\?/, "") : new URLSearchParams(Ky.#normalizeSearchParams(this.#options.searchParams)).toString());
671
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
672
- this.request = new globalThis.Request(url, this.#options);
673
- }
674
- if (this.#options.onUploadProgress) {
675
- if (typeof this.#options.onUploadProgress !== "function") throw new TypeError("The `onUploadProgress` option must be a function");
676
- if (!supportsRequestStreams) throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
677
- this.request = this.#wrapRequestWithUploadProgress(this.request, this.#options.body ?? void 0);
678
- }
679
- }
680
- #calculateDelay() {
681
- const retryDelay = this.#options.retry.delay(this.#retryCount);
682
- let jitteredDelay = retryDelay;
683
- if (this.#options.retry.jitter === true) jitteredDelay = Math.random() * retryDelay;
684
- else if (typeof this.#options.retry.jitter === "function") {
685
- jitteredDelay = this.#options.retry.jitter(retryDelay);
686
- if (!Number.isFinite(jitteredDelay) || jitteredDelay < 0) jitteredDelay = retryDelay;
687
- }
688
- const backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;
689
- return Math.min(backoffLimit, jitteredDelay);
690
- }
691
- async #calculateRetryDelay(error) {
692
- this.#retryCount++;
693
- if (this.#retryCount > this.#options.retry.limit) throw error;
694
- const errorObject = error instanceof Error ? error : new NonError(error);
695
- if (errorObject instanceof ForceRetryError) return errorObject.customDelay ?? this.#calculateDelay();
696
- if (!this.#options.retry.methods.includes(this.request.method.toLowerCase())) throw error;
697
- if (this.#options.retry.shouldRetry !== void 0) {
698
- const result = await this.#options.retry.shouldRetry({
699
- error: errorObject,
700
- retryCount: this.#retryCount
701
- });
702
- if (result === false) throw error;
703
- if (result === true) return this.#calculateDelay();
704
- }
705
- if (isTimeoutError(error) && !this.#options.retry.retryOnTimeout) throw error;
706
- if (isHTTPError(error)) {
707
- if (!this.#options.retry.statusCodes.includes(error.response.status)) throw error;
708
- const retryAfter = error.response.headers.get("Retry-After") ?? error.response.headers.get("RateLimit-Reset") ?? error.response.headers.get("X-RateLimit-Retry-After") ?? error.response.headers.get("X-RateLimit-Reset") ?? error.response.headers.get("X-Rate-Limit-Reset");
709
- if (retryAfter && this.#options.retry.afterStatusCodes.includes(error.response.status)) {
710
- let after = Number(retryAfter) * 1e3;
711
- if (Number.isNaN(after)) after = Date.parse(retryAfter) - Date.now();
712
- else if (after >= Date.parse("2024-01-01")) after -= Date.now();
713
- const max = this.#options.retry.maxRetryAfter ?? after;
714
- return after < max ? after : max;
715
- }
716
- if (error.response.status === 413) throw error;
717
- }
718
- return this.#calculateDelay();
719
- }
720
- #decorateResponse(response) {
721
- if (this.#options.parseJson) response.json = async () => this.#options.parseJson(await response.text());
722
- return response;
723
- }
724
- async #retry(function_) {
725
- try {
726
- return await function_();
727
- } catch (error) {
728
- const ms = Math.min(await this.#calculateRetryDelay(error), maxSafeTimeout);
729
- if (this.#retryCount < 1) throw error;
730
- await delay(ms, this.#userProvidedAbortSignal ? { signal: this.#userProvidedAbortSignal } : {});
731
- if (error instanceof ForceRetryError && error.customRequest) {
732
- const managedRequest = this.#options.signal ? new globalThis.Request(error.customRequest, { signal: this.#options.signal }) : new globalThis.Request(error.customRequest);
733
- this.#assignRequest(managedRequest);
734
- }
735
- for (const hook of this.#options.hooks.beforeRetry) {
736
- const hookResult = await hook({
737
- request: this.request,
738
- options: this.#getNormalizedOptions(),
739
- error,
740
- retryCount: this.#retryCount
741
- });
742
- if (hookResult instanceof globalThis.Request) {
743
- this.#assignRequest(hookResult);
744
- break;
745
- }
746
- if (hookResult instanceof globalThis.Response) return hookResult;
747
- if (hookResult === stop) return;
748
- }
749
- return this.#retry(function_);
750
- }
751
- }
752
- async #fetch() {
753
- if (this.#abortController?.signal.aborted) {
754
- this.#abortController = new globalThis.AbortController();
755
- this.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;
756
- this.request = new globalThis.Request(this.request, { signal: this.#options.signal });
757
- }
758
- for (const hook of this.#options.hooks.beforeRequest) {
759
- const result = await hook(this.request, this.#getNormalizedOptions(), { retryCount: this.#retryCount });
760
- if (result instanceof Response) return result;
761
- if (result instanceof globalThis.Request) {
762
- this.#assignRequest(result);
763
- break;
764
- }
765
- }
766
- const nonRequestOptions = findUnknownOptions(this.request, this.#options);
767
- this.#originalRequest = this.request;
768
- this.request = this.#originalRequest.clone();
769
- if (this.#options.timeout === false) return this.#options.fetch(this.#originalRequest, nonRequestOptions);
770
- return timeout(this.#originalRequest, nonRequestOptions, this.#abortController, this.#options);
771
- }
772
- #getNormalizedOptions() {
773
- if (!this.#cachedNormalizedOptions) {
774
- const { hooks, ...normalizedOptions } = this.#options;
775
- this.#cachedNormalizedOptions = Object.freeze(normalizedOptions);
776
- }
777
- return this.#cachedNormalizedOptions;
778
- }
779
- #assignRequest(request) {
780
- this.#cachedNormalizedOptions = void 0;
781
- this.request = this.#wrapRequestWithUploadProgress(request);
782
- }
783
- #wrapRequestWithUploadProgress(request, originalBody) {
784
- if (!this.#options.onUploadProgress || !request.body) return request;
785
- return streamRequest(request, this.#options.onUploadProgress, originalBody ?? this.#options.body ?? void 0);
786
- }
787
- };
788
-
789
- //#endregion
790
- //#region ../../node_modules/.pnpm/ky@1.14.1/node_modules/ky/distribution/index.js
1
+ var e=class extends Error{response;request;options;constructor(e,t,n){let r=`${e.status||e.status===0?e.status:``} ${e.statusText??``}`.trim(),i=r?`status code ${r}`:`an unknown error`;super(`Request failed with ${i}: ${t.method} ${t.url}`),this.name=`HTTPError`,this.response=e,this.request=t,this.options=n}},t=class extends Error{name=`NonError`;value;constructor(e){let t=`Non-error value was thrown`;try{typeof e==`string`?t=e:e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`&&(t=e.message)}catch{}super(t),this.value=e}},n=class extends Error{name=`ForceRetryError`;customDelay;code;customRequest;constructor(e){let n=e?.cause?e.cause instanceof Error?e.cause:new t(e.cause):void 0;super(e?.code?`Forced retry: ${e.code}`:`Forced retry`,n?{cause:n}:void 0),this.customDelay=e?.delay,this.code=e?.code,this.customRequest=e?.request}};const r=(()=>{let e=!1,t=!1,n=typeof globalThis.ReadableStream==`function`,r=typeof globalThis.Request==`function`;if(n&&r)try{t=new globalThis.Request(`https://empty.invalid`,{body:new globalThis.ReadableStream,method:`POST`,get duplex(){return e=!0,`half`}}).headers.has(`Content-Type`)}catch(e){if(e instanceof Error&&e.message===`unsupported BodyInit type`)return!1;throw e}return e&&!t})(),i=typeof globalThis.AbortController==`function`,a=typeof globalThis.AbortSignal==`function`&&typeof globalThis.AbortSignal.any==`function`,o=typeof globalThis.ReadableStream==`function`,s=typeof globalThis.FormData==`function`,c=[`get`,`post`,`put`,`patch`,`head`,`delete`],l={json:`application/json`,text:`text/*`,formData:`multipart/form-data`,arrayBuffer:`*/*`,blob:`*/*`,bytes:`*/*`},u=2147483647,d=new TextEncoder().encode(`------WebKitFormBoundaryaxpyiPgbbPti10Rw`).length,f=Symbol(`stop`);var p=class{options;constructor(e){this.options=e}};const m=e=>new p(e),h={json:!0,parseJson:!0,stringifyJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,onUploadProgress:!0,fetch:!0,context:!0},g={next:!0},_={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,duplex:!0},v=e=>{if(!e)return 0;if(e instanceof FormData){let t=0;for(let[n,r]of e)t+=d,t+=new TextEncoder().encode(`Content-Disposition: form-data; name="${n}"`).length,t+=typeof r==`string`?new TextEncoder().encode(r).length:r.size;return t}if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer)return e.byteLength;if(typeof e==`string`)return new TextEncoder().encode(e).length;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(`byteLength`in e)return e.byteLength;if(typeof e==`object`&&e)try{let t=JSON.stringify(e);return new TextEncoder().encode(t).length}catch{return 0}return 0},y=(e,t,n)=>{let r,i=0;return e.pipeThrough(new TransformStream({transform(e,a){if(a.enqueue(e),r){i+=r.byteLength;let e=t===0?0:i/t;e>=1&&(e=1-2**-52),n?.({percent:e,totalBytes:Math.max(t,i),transferredBytes:i},r)}r=e},flush(){r&&(i+=r.byteLength,n?.({percent:1,totalBytes:Math.max(t,i),transferredBytes:i},r))}}))},b=(e,t)=>{if(!e.body)return e;if(e.status===204)return new Response(null,{status:e.status,statusText:e.statusText,headers:e.headers});let n=Math.max(0,Number(e.headers.get(`content-length`))||0);return new Response(y(e.body,n,t),{status:e.status,statusText:e.statusText,headers:e.headers})},x=(e,t,n)=>{if(!e.body)return e;let r=v(n??e.body);return new Request(e,{duplex:`half`,body:y(e.body,r,t)})},S=e=>typeof e==`object`&&!!e,C=(...e)=>{for(let t of e)if((!S(t)||Array.isArray(t))&&t!==void 0)throw TypeError("The `options` argument must be an object");return O({},...e)},w=(e={},t={})=>{let n=new globalThis.Headers(e),r=t instanceof globalThis.Headers,i=new globalThis.Headers(t);for(let[e,t]of i.entries())r&&t===`undefined`||t===void 0?n.delete(e):n.set(e,t);return n};function T(e,t,n){return Object.hasOwn(t,n)&&t[n]===void 0?[]:O(e[n]??[],t[n]??[])}const E=(e={},t={})=>({beforeRequest:T(e,t,`beforeRequest`),beforeRetry:T(e,t,`beforeRetry`),afterResponse:T(e,t,`afterResponse`),beforeError:T(e,t,`beforeError`)}),D=(e,t)=>{let n=new URLSearchParams;for(let r of[e,t])if(r!==void 0)if(r instanceof URLSearchParams)for(let[e,t]of r.entries())n.append(e,t);else if(Array.isArray(r))for(let e of r){if(!Array.isArray(e)||e.length!==2)throw TypeError(`Array search parameters must be provided in [[key, value], ...] format`);n.append(String(e[0]),String(e[1]))}else if(S(r))for(let[e,t]of Object.entries(r))t!==void 0&&n.append(e,String(t));else{let e=new URLSearchParams(r);for(let[t,r]of e.entries())n.append(t,r)}return n},O=(...e)=>{let t={},n={},r={},i,o=[];for(let a of e)if(Array.isArray(a))Array.isArray(t)||(t=[]),t=[...t,...a];else if(S(a)){for(let[e,n]of Object.entries(a)){if(e===`signal`&&n instanceof globalThis.AbortSignal){o.push(n);continue}if(e===`context`){if(n!=null&&(!S(n)||Array.isArray(n)))throw TypeError("The `context` option must be an object");t={...t,context:n==null?{}:{...t.context,...n}};continue}if(e===`searchParams`){i=n==null?void 0:i===void 0?n:D(i,n);continue}S(n)&&e in t&&(n=O(t[e],n)),t={...t,[e]:n}}S(a.hooks)&&(r=E(r,a.hooks),t.hooks=r),S(a.headers)&&(n=w(n,a.headers),t.headers=n)}return i!==void 0&&(t.searchParams=i),o.length>0&&(o.length===1?t.signal=o[0]:a?t.signal=AbortSignal.any(o):t.signal=o.at(-1)),t},k=e=>c.includes(e)?e.toUpperCase():e,A={limit:2,methods:[`get`,`put`,`head`,`delete`,`options`,`trace`],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:[413,429,503],maxRetryAfter:1/0,backoffLimit:1/0,delay:e=>.3*2**(e-1)*1e3,jitter:void 0,retryOnTimeout:!1},j=(e={})=>{if(typeof e==`number`)return{...A,limit:e};if(e.methods&&!Array.isArray(e.methods))throw Error(`retry.methods must be an array`);if(e.methods&&=e.methods.map(e=>e.toLowerCase()),e.statusCodes&&!Array.isArray(e.statusCodes))throw Error(`retry.statusCodes must be an array`);let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return{...A,...t}};var M=class extends Error{request;constructor(e){super(`Request timed out: ${e.method} ${e.url}`),this.name=`TimeoutError`,this.request=e}};async function N(e,t,n,r){return new Promise((i,a)=>{let o=setTimeout(()=>{n&&n.abort(),a(new M(e))},r.timeout);r.fetch(e,t).then(i).catch(a).then(()=>{clearTimeout(o)})})}async function P(e,{signal:t}){return new Promise((n,r)=>{t&&(t.throwIfAborted(),t.addEventListener(`abort`,i,{once:!0}));function i(){clearTimeout(a),r(t.reason)}let a=setTimeout(()=>{t?.removeEventListener(`abort`,i),n()},e)})}const F=(e,t)=>{let n={};for(let r in t)Object.hasOwn(t,r)&&!(r in _)&&!(r in h)&&(!(r in e)||r in g)&&(n[r]=t[r]);return n},I=e=>e===void 0?!1:Array.isArray(e)?e.length>0:e instanceof URLSearchParams?e.size>0:typeof e==`object`?Object.keys(e).length>0:typeof e==`string`?e.trim().length>0:!!e;function L(t){return t instanceof e||t?.name===e.name}function R(e){return e instanceof M||e?.name===M.name}var z=class c{static create(t,r){let i=new c(t,r),a=async()=>{if(typeof i.#i.timeout==`number`&&i.#i.timeout>u)throw RangeError(`The \`timeout\` option cannot be greater than ${u}`);await Promise.resolve();let t=await i.#m();for(let e of i.#i.hooks.afterResponse){let r=i.#u(t.clone()),a;try{a=await e(i.request,i.#h(),r,{retryCount:i.#n})}catch(e){throw i.#f(r),i.#f(t),e}if(a instanceof p)throw i.#f(r),i.#f(t),new n(a.options);let o=a instanceof globalThis.Response?a:t;r!==o&&i.#f(r),t!==o&&i.#f(t),t=o}if(i.#u(t),!t.ok&&(typeof i.#i.throwHttpErrors==`function`?i.#i.throwHttpErrors(t.status):i.#i.throwHttpErrors)){let n=new e(t,i.request,i.#h());for(let e of i.#i.hooks.beforeError)n=await e(n,{retryCount:i.#n});throw n}if(i.#i.onDownloadProgress){if(typeof i.#i.onDownloadProgress!=`function`)throw TypeError("The `onDownloadProgress` option must be a function");if(!o)throw Error("Streams are not supported in your environment. `ReadableStream` is missing.");let e=t.clone();return i.#f(t),b(e,i.#i.onDownloadProgress)}return t},s=i.#p(a).finally(()=>{let e=i.#a;i.#d(e?.body??void 0),i.#d(i.request.body??void 0)});for(let[e,t]of Object.entries(l))e===`bytes`&&typeof globalThis.Response?.prototype?.bytes!=`function`||(s[e]=async()=>{i.request.headers.set(`accept`,i.request.headers.get(`accept`)||t);let n=await s;if(e===`json`){if(n.status===204)return``;let e=await n.text();return e===``?``:r.parseJson?r.parseJson(e):JSON.parse(e)}return n[e]()});return s}static#e(e){return e&&typeof e==`object`&&!Array.isArray(e)&&!(e instanceof URLSearchParams)?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0)):e}request;#t;#n=0;#r;#i;#a;#o;#s;constructor(e,t={}){if(this.#r=e,this.#i={...t,headers:w(this.#r.headers,t.headers),hooks:E({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},t.hooks),method:k(t.method??this.#r.method??`GET`),prefixUrl:String(t.prefixUrl||``),retry:j(t.retry),throwHttpErrors:t.throwHttpErrors??!0,timeout:t.timeout??1e4,fetch:t.fetch??globalThis.fetch.bind(globalThis),context:t.context??{}},typeof this.#r!=`string`&&!(this.#r instanceof URL||this.#r instanceof globalThis.Request))throw TypeError("`input` must be a string, URL, or Request");if(this.#i.prefixUrl&&typeof this.#r==`string`){if(this.#r.startsWith(`/`))throw Error("`input` must not begin with a slash when using `prefixUrl`");this.#i.prefixUrl.endsWith(`/`)||(this.#i.prefixUrl+=`/`),this.#r=this.#i.prefixUrl+this.#r}i&&a&&(this.#o=this.#i.signal??this.#r.signal,this.#t=new globalThis.AbortController,this.#i.signal=this.#o?AbortSignal.any([this.#o,this.#t.signal]):this.#t.signal),r&&(this.#i.duplex=`half`),this.#i.json!==void 0&&(this.#i.body=this.#i.stringifyJson?.(this.#i.json)??JSON.stringify(this.#i.json),this.#i.headers.set(`content-type`,this.#i.headers.get(`content-type`)??`application/json`));let n=t.headers&&new globalThis.Headers(t.headers).has(`content-type`);if(this.#r instanceof globalThis.Request&&(s&&this.#i.body instanceof globalThis.FormData||this.#i.body instanceof URLSearchParams)&&!n&&this.#i.headers.delete(`content-type`),this.request=new globalThis.Request(this.#r,this.#i),I(this.#i.searchParams)){let e=`?`+(typeof this.#i.searchParams==`string`?this.#i.searchParams.replace(/^\?/,``):new URLSearchParams(c.#e(this.#i.searchParams)).toString()),t=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,e);this.request=new globalThis.Request(t,this.#i)}if(this.#i.onUploadProgress){if(typeof this.#i.onUploadProgress!=`function`)throw TypeError("The `onUploadProgress` option must be a function");if(!r)throw Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");this.request=this.#_(this.request,this.#i.body??void 0)}}#c(){let e=this.#i.retry.delay(this.#n),t=e;this.#i.retry.jitter===!0?t=Math.random()*e:typeof this.#i.retry.jitter==`function`&&(t=this.#i.retry.jitter(e),(!Number.isFinite(t)||t<0)&&(t=e));let n=this.#i.retry.backoffLimit??1/0;return Math.min(n,t)}async#l(e){if(this.#n++,this.#n>this.#i.retry.limit)throw e;let r=e instanceof Error?e:new t(e);if(r instanceof n)return r.customDelay??this.#c();if(!this.#i.retry.methods.includes(this.request.method.toLowerCase()))throw e;if(this.#i.retry.shouldRetry!==void 0){let t=await this.#i.retry.shouldRetry({error:r,retryCount:this.#n});if(t===!1)throw e;if(t===!0)return this.#c()}if(R(e)&&!this.#i.retry.retryOnTimeout)throw e;if(L(e)){if(!this.#i.retry.statusCodes.includes(e.response.status))throw e;let t=e.response.headers.get(`Retry-After`)??e.response.headers.get(`RateLimit-Reset`)??e.response.headers.get(`X-RateLimit-Retry-After`)??e.response.headers.get(`X-RateLimit-Reset`)??e.response.headers.get(`X-Rate-Limit-Reset`);if(t&&this.#i.retry.afterStatusCodes.includes(e.response.status)){let e=Number(t)*1e3;Number.isNaN(e)?e=Date.parse(t)-Date.now():e>=Date.parse(`2024-01-01`)&&(e-=Date.now());let n=this.#i.retry.maxRetryAfter??e;return e<n?e:n}if(e.response.status===413)throw e}return this.#c()}#u(e){return this.#i.parseJson&&(e.json=async()=>this.#i.parseJson(await e.text())),e}#d(e){e&&e.cancel().catch(()=>void 0)}#f(e){this.#d(e.body??void 0)}async#p(e){try{return await e()}catch(t){let r=Math.min(await this.#l(t),u);if(this.#n<1)throw t;if(await P(r,this.#o?{signal:this.#o}:{}),t instanceof n&&t.customRequest){let e=this.#i.signal?new globalThis.Request(t.customRequest,{signal:this.#i.signal}):new globalThis.Request(t.customRequest);this.#g(e)}for(let e of this.#i.hooks.beforeRetry){let n=await e({request:this.request,options:this.#h(),error:t,retryCount:this.#n});if(n instanceof globalThis.Request){this.#g(n);break}if(n instanceof globalThis.Response)return n;if(n===f)return}return this.#p(e)}}async#m(){this.#t?.signal.aborted&&(this.#t=new globalThis.AbortController,this.#i.signal=this.#o?AbortSignal.any([this.#o,this.#t.signal]):this.#t.signal,this.request=new globalThis.Request(this.request,{signal:this.#i.signal}));for(let e of this.#i.hooks.beforeRequest){let t=await e(this.request,this.#h(),{retryCount:this.#n});if(t instanceof Response)return t;if(t instanceof globalThis.Request){this.#g(t);break}}let e=F(this.request,this.#i);return this.#a=this.request,this.request=this.#a.clone(),this.#i.timeout===!1?this.#i.fetch(this.#a,e):N(this.#a,e,this.#t,this.#i)}#h(){if(!this.#s){let{hooks:e,...t}=this.#i;this.#s=Object.freeze(t)}return this.#s}#g(e){this.#s=void 0,this.request=this.#_(e)}#_(e,t){return!this.#i.onUploadProgress||!e.body?e:x(e,this.#i.onUploadProgress,t??this.#i.body??void 0)}};
791
2
  /*! MIT License © Sindre Sorhus */
792
- const createInstance = (defaults) => {
793
- const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
794
- for (const method of requestMethods) ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
795
- ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
796
- ky.extend = (newDefaults) => {
797
- if (typeof newDefaults === "function") newDefaults = newDefaults(defaults ?? {});
798
- return createInstance(validateAndMerge(defaults, newDefaults));
799
- };
800
- ky.stop = stop;
801
- ky.retry = retry;
802
- return ky;
803
- };
804
- const ky = createInstance();
805
- var distribution_default = ky;
806
-
807
- //#endregion
808
- export { distribution_default as t };
3
+ const B=e=>{let t=(t,n)=>z.create(t,C(e,n));for(let n of c)t[n]=(t,r)=>z.create(t,C(e,r,{method:n}));return t.create=e=>B(C(e)),t.extend=t=>(typeof t==`function`&&(t=t(e??{})),B(C(e,t))),t.stop=f,t.retry=m,t},V=B();export{V as t};