req-race 1.0.0 → 1.1.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.
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/bin/req-race.js +84 -44
- package/config.schema.json +16 -0
- package/dist/browser/req-race.global.js +1 -0
- package/dist/cjs/browser.cjs +843 -0
- package/dist/cjs/cypress.cjs +618 -0
- package/dist/cjs/index.cjs +1064 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/playwright.cjs +257 -0
- package/dist/cjs/puppeteer.cjs +257 -0
- package/dist/esm/browser.js +813 -0
- package/dist/esm/cypress.js +591 -0
- package/dist/esm/index.js +1002 -0
- package/dist/esm/playwright.js +221 -0
- package/dist/esm/puppeteer.js +221 -0
- package/dist/types/browser.d.cts +9 -0
- package/dist/types/browser.d.ts +9 -0
- package/dist/types/chaos.d.cts +25 -0
- package/dist/types/chaos.d.ts +25 -0
- package/dist/types/config.d.cts +3 -0
- package/dist/types/config.d.ts +3 -0
- package/dist/types/cypress.d.cts +1 -0
- package/dist/types/cypress.d.ts +1 -0
- package/dist/types/index.d.cts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/playwright.d.cts +82 -0
- package/dist/types/playwright.d.ts +82 -0
- package/dist/types/prng.d.cts +1 -0
- package/dist/types/prng.d.ts +1 -0
- package/dist/types/puppeteer.d.cts +2 -0
- package/dist/types/puppeteer.d.ts +2 -0
- package/dist/types/reporters.d.cts +33 -0
- package/dist/types/reporters.d.ts +33 -0
- package/dist/types/safe-fetch.d.cts +24 -0
- package/dist/types/safe-fetch.d.ts +24 -0
- package/dist/types/types.d.cts +215 -0
- package/dist/types/types.d.ts +215 -0
- package/package.json +87 -13
- package/src/index.d.ts +0 -56
- package/src/index.js +0 -373
- package/src/playwright.d.ts +0 -30
- package/src/playwright.js +0 -113
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/browser.ts
|
|
21
|
+
var browser_exports = {};
|
|
22
|
+
__export(browser_exports, {
|
|
23
|
+
ReqRace: () => ReqRace,
|
|
24
|
+
createLatestGuard: () => createLatestGuard,
|
|
25
|
+
createRaceSafeFetch: () => createRaceSafeFetch,
|
|
26
|
+
default: () => browser_default,
|
|
27
|
+
enableFetchRaceChaos: () => enableFetchRaceChaos
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(browser_exports);
|
|
30
|
+
|
|
31
|
+
// src/prng.ts
|
|
32
|
+
function createSeededRandom(seed = Date.now()) {
|
|
33
|
+
let h = 2166136261;
|
|
34
|
+
const s = String(seed);
|
|
35
|
+
for (let i = 0; i < s.length; i++) {
|
|
36
|
+
h ^= s.charCodeAt(i);
|
|
37
|
+
h = Math.imul(h, 16777619);
|
|
38
|
+
}
|
|
39
|
+
let state = h >>> 0;
|
|
40
|
+
return function nextRandom() {
|
|
41
|
+
state = state + 1831565813 | 0;
|
|
42
|
+
let t = Math.imul(state ^ state >>> 15, 1 | state);
|
|
43
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
44
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/types.ts
|
|
49
|
+
var SupersededError = class extends Error {
|
|
50
|
+
code = "ERR_SUPERSEDED";
|
|
51
|
+
reason = "superseded";
|
|
52
|
+
constructor(message = "Superseded by newer request") {
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = "AbortError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var TimeoutError = class extends Error {
|
|
58
|
+
code = "ETIMEDOUT";
|
|
59
|
+
constructor(message = "Request timed out") {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = "TimeoutError";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var AlreadyEnabledError = class extends Error {
|
|
65
|
+
code = "ALREADY_ENABLED";
|
|
66
|
+
constructor(message = "req-race chaos is already enabled on this target. Call disable() first.") {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = "AlreadyEnabledError";
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var ChaosCallbackError = class extends Error {
|
|
72
|
+
code = "ERR_CHAOS_CALLBACK";
|
|
73
|
+
constructor(message, options) {
|
|
74
|
+
super(message, options);
|
|
75
|
+
this.name = "ChaosCallbackError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var UnknownModeError = class extends Error {
|
|
79
|
+
code = "ERR_UNKNOWN_MODE";
|
|
80
|
+
constructor(mode) {
|
|
81
|
+
super(`Unknown req-race mode: "${mode}".`);
|
|
82
|
+
this.name = "UnknownModeError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function isSupersededError(err) {
|
|
86
|
+
return Boolean(
|
|
87
|
+
err && typeof err === "object" && (err.code === "ERR_SUPERSEDED" || err.reason === "superseded")
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/chaos.ts
|
|
92
|
+
var MODES = [
|
|
93
|
+
"reverse-order",
|
|
94
|
+
"jitter",
|
|
95
|
+
"throttle-mutations",
|
|
96
|
+
"timeout",
|
|
97
|
+
"slow",
|
|
98
|
+
"flaky",
|
|
99
|
+
"error-status",
|
|
100
|
+
"rate-limit",
|
|
101
|
+
"offline",
|
|
102
|
+
"hang",
|
|
103
|
+
"abort-mid-body",
|
|
104
|
+
"shuffle",
|
|
105
|
+
"custom"
|
|
106
|
+
];
|
|
107
|
+
var DEFAULT_OPTIONS = {
|
|
108
|
+
mode: "reverse-order",
|
|
109
|
+
delayMs: 1e3,
|
|
110
|
+
timeoutMs: 1500,
|
|
111
|
+
minDelayMs: 100,
|
|
112
|
+
maxDelayMs: 900,
|
|
113
|
+
doubleSubmitWindowMs: 500,
|
|
114
|
+
errorRate: 0.3,
|
|
115
|
+
status: 503,
|
|
116
|
+
statusText: "Service Unavailable",
|
|
117
|
+
body: "",
|
|
118
|
+
headers: {},
|
|
119
|
+
rateLimitAfter: 3,
|
|
120
|
+
rateLimitWindowMs: 1e3,
|
|
121
|
+
retryAfterSeconds: 1,
|
|
122
|
+
partialBytes: 16,
|
|
123
|
+
shuffleWindowMs: 300,
|
|
124
|
+
maxLogs: 1e3
|
|
125
|
+
};
|
|
126
|
+
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
127
|
+
var ACTIVE_TARGETS = /* @__PURE__ */ new WeakSet();
|
|
128
|
+
var DEFAULT_CLOCK = {
|
|
129
|
+
now: () => Date.now(),
|
|
130
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
131
|
+
clearTimeout: (id) => globalThis.clearTimeout(id)
|
|
132
|
+
};
|
|
133
|
+
function sleepWithClock(ms, clock, signal) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
if (signal?.aborted) {
|
|
136
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const timer = clock.setTimeout(() => {
|
|
140
|
+
signal?.removeEventListener("abort", onAbort);
|
|
141
|
+
resolve();
|
|
142
|
+
}, ms);
|
|
143
|
+
function onAbort() {
|
|
144
|
+
clock.clearTimeout(timer);
|
|
145
|
+
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
146
|
+
}
|
|
147
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function hangUntilAbort(signal) {
|
|
151
|
+
return new Promise((_resolve, reject) => {
|
|
152
|
+
if (signal?.aborted) {
|
|
153
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
signal?.addEventListener(
|
|
157
|
+
"abort",
|
|
158
|
+
() => reject(signal.reason ?? new DOMException("Aborted", "AbortError")),
|
|
159
|
+
{ once: true }
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function defaultNormalizeKey(url, method) {
|
|
164
|
+
try {
|
|
165
|
+
const parsed = new URL(url, "http://localhost");
|
|
166
|
+
return `${method}:${parsed.pathname}`;
|
|
167
|
+
} catch {
|
|
168
|
+
return `${method}:${String(url).split("#")[0]?.split("?")[0] ?? ""}`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function extractUrl(input) {
|
|
172
|
+
if (typeof input === "string") return input;
|
|
173
|
+
if (input instanceof URL) return input.href;
|
|
174
|
+
if (input && typeof input.url === "string") return input.url;
|
|
175
|
+
return String(input);
|
|
176
|
+
}
|
|
177
|
+
function matchesUrl(url, pattern) {
|
|
178
|
+
if (!pattern) return true;
|
|
179
|
+
if (typeof pattern === "function") return pattern(url);
|
|
180
|
+
if (pattern instanceof RegExp) return pattern.test(url);
|
|
181
|
+
return url.includes(String(pattern));
|
|
182
|
+
}
|
|
183
|
+
function validateModes(modeInput) {
|
|
184
|
+
const list = Array.isArray(modeInput) ? modeInput : [modeInput];
|
|
185
|
+
for (const m of list) {
|
|
186
|
+
if (!MODES.includes(m)) {
|
|
187
|
+
throw new UnknownModeError(String(m));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return list;
|
|
191
|
+
}
|
|
192
|
+
function makePartialBodyResponse(original, partialBytes) {
|
|
193
|
+
const stream = new ReadableStream({
|
|
194
|
+
async start(controller) {
|
|
195
|
+
try {
|
|
196
|
+
const text = await original.text();
|
|
197
|
+
const encoded = new TextEncoder().encode(text);
|
|
198
|
+
controller.enqueue(encoded.slice(0, Math.max(0, partialBytes)));
|
|
199
|
+
controller.error(new TypeError("network error mid-body"));
|
|
200
|
+
} catch (err) {
|
|
201
|
+
controller.error(err);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return new Response(stream, {
|
|
206
|
+
status: original.status,
|
|
207
|
+
statusText: original.statusText,
|
|
208
|
+
headers: original.headers
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function enableFetchRaceChaos(options = {}) {
|
|
212
|
+
const target = options.target ?? (typeof globalThis !== "undefined" ? globalThis : null);
|
|
213
|
+
if (!target || typeof target.fetch !== "function") {
|
|
214
|
+
throw new Error("enableFetchRaceChaos requires a target with a fetch() function.");
|
|
215
|
+
}
|
|
216
|
+
if (ACTIVE_TARGETS.has(target)) {
|
|
217
|
+
throw new AlreadyEnabledError();
|
|
218
|
+
}
|
|
219
|
+
let activeModes = validateModes(options.mode ?? DEFAULT_OPTIONS.mode);
|
|
220
|
+
let offlineForced = false;
|
|
221
|
+
let enabled = true;
|
|
222
|
+
const seed = options.seed ?? Math.floor(Math.random() * 1e9);
|
|
223
|
+
const rand = createSeededRandom(seed);
|
|
224
|
+
const clock = options.clock ?? DEFAULT_CLOCK;
|
|
225
|
+
const delayMs = options.delayMs ?? DEFAULT_OPTIONS.delayMs;
|
|
226
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_OPTIONS.timeoutMs;
|
|
227
|
+
const minDelayMs = options.minDelayMs ?? DEFAULT_OPTIONS.minDelayMs;
|
|
228
|
+
const maxDelayMs = options.maxDelayMs ?? DEFAULT_OPTIONS.maxDelayMs;
|
|
229
|
+
const doubleSubmitWindowMs = options.doubleSubmitWindowMs ?? DEFAULT_OPTIONS.doubleSubmitWindowMs;
|
|
230
|
+
const errorRate = options.errorRate ?? DEFAULT_OPTIONS.errorRate;
|
|
231
|
+
const maxLogs = options.maxLogs ?? DEFAULT_OPTIONS.maxLogs;
|
|
232
|
+
const normalizeKey = options.normalizeKey ?? defaultNormalizeKey;
|
|
233
|
+
const rawOriginalFetch = target.fetch;
|
|
234
|
+
const originalFetch = rawOriginalFetch.bind(target);
|
|
235
|
+
const inFlightByKey = /* @__PURE__ */ new Map();
|
|
236
|
+
const recentMutations = /* @__PURE__ */ new Map();
|
|
237
|
+
const rateLimitWindows = /* @__PURE__ */ new Map();
|
|
238
|
+
const logs = [];
|
|
239
|
+
const stats = {
|
|
240
|
+
totalRequests: 0,
|
|
241
|
+
reorderedResponses: 0,
|
|
242
|
+
abortedCount: 0,
|
|
243
|
+
unabortedStaleCount: 0,
|
|
244
|
+
duplicateMutations: 0,
|
|
245
|
+
timeouts: 0,
|
|
246
|
+
failedRequests: 0,
|
|
247
|
+
injectedErrors: 0,
|
|
248
|
+
rateLimited: 0,
|
|
249
|
+
hungRequests: 0,
|
|
250
|
+
partialBodies: 0,
|
|
251
|
+
retriedCount: 0,
|
|
252
|
+
deduplicatedCount: 0,
|
|
253
|
+
maxConcurrentPerKey: {},
|
|
254
|
+
byKey: {},
|
|
255
|
+
seed
|
|
256
|
+
};
|
|
257
|
+
let seq = 0;
|
|
258
|
+
ACTIVE_TARGETS.add(target);
|
|
259
|
+
const pushLog = (entry) => {
|
|
260
|
+
logs.push(entry);
|
|
261
|
+
if (logs.length > maxLogs) {
|
|
262
|
+
logs.shift();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const nav = target.navigator;
|
|
266
|
+
const rawSendBeacon = nav?.sendBeacon;
|
|
267
|
+
if (options.patchBeacon && nav && typeof rawSendBeacon === "function") {
|
|
268
|
+
nav.sendBeacon = function patchedSendBeacon(url, data) {
|
|
269
|
+
const key = normalizeKey(url, "BEACON");
|
|
270
|
+
const now = clock.now();
|
|
271
|
+
stats.totalRequests++;
|
|
272
|
+
const prev = recentMutations.get(key);
|
|
273
|
+
if (prev && now - prev <= doubleSubmitWindowMs) {
|
|
274
|
+
stats.duplicateMutations++;
|
|
275
|
+
}
|
|
276
|
+
recentMutations.set(key, now);
|
|
277
|
+
return rawSendBeacon.call(nav, url, data);
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
target.fetch = async function reqRaceFetch(input, init = {}) {
|
|
281
|
+
const url = extractUrl(input);
|
|
282
|
+
const method = (init?.method || (typeof input === "object" && "method" in input ? input.method : void 0) || "GET").toUpperCase();
|
|
283
|
+
if (!matchesUrl(url, options.urlPattern)) {
|
|
284
|
+
return originalFetch(input, init);
|
|
285
|
+
}
|
|
286
|
+
if (options.methods && !options.methods.map((m) => m.toUpperCase()).includes(method)) {
|
|
287
|
+
return originalFetch(input, init);
|
|
288
|
+
}
|
|
289
|
+
const matchedRule = options.rules?.find(
|
|
290
|
+
(r) => matchesUrl(url, r.urlPattern) && (!r.methods || r.methods.map((m) => m.toUpperCase()).includes(method))
|
|
291
|
+
);
|
|
292
|
+
const modesToRun = matchedRule ? validateModes(matchedRule.mode) : activeModes;
|
|
293
|
+
const effDelay = matchedRule?.delayMs ?? delayMs;
|
|
294
|
+
const effTimeout = matchedRule?.timeoutMs ?? timeoutMs;
|
|
295
|
+
const effMinDelay = matchedRule?.minDelayMs ?? minDelayMs;
|
|
296
|
+
const effMaxDelay = matchedRule?.maxDelayMs ?? maxDelayMs;
|
|
297
|
+
const effErrorRate = matchedRule?.errorRate ?? errorRate;
|
|
298
|
+
const id = ++seq;
|
|
299
|
+
const key = normalizeKey(url, method);
|
|
300
|
+
const startedAt = clock.now();
|
|
301
|
+
const signal = init?.signal || (typeof input === "object" && "signal" in input ? input.signal : void 0);
|
|
302
|
+
stats.totalRequests++;
|
|
303
|
+
const keyStat = stats.byKey[key] ??= { requests: 0, reordered: 0, unabortedStale: 0 };
|
|
304
|
+
keyStat.requests++;
|
|
305
|
+
if (MUTATION_METHODS.has(method)) {
|
|
306
|
+
const prevTs = recentMutations.get(key);
|
|
307
|
+
if (prevTs !== void 0 && startedAt - prevTs <= doubleSubmitWindowMs) {
|
|
308
|
+
stats.duplicateMutations++;
|
|
309
|
+
options.onRaceDetected?.({
|
|
310
|
+
type: "duplicate-mutation",
|
|
311
|
+
method,
|
|
312
|
+
key,
|
|
313
|
+
url,
|
|
314
|
+
requestId: id,
|
|
315
|
+
detail: `Duplicate ${method} within ${startedAt - prevTs}ms`
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
recentMutations.set(key, startedAt);
|
|
319
|
+
}
|
|
320
|
+
const entry = {
|
|
321
|
+
id,
|
|
322
|
+
key,
|
|
323
|
+
method,
|
|
324
|
+
url,
|
|
325
|
+
startedAt,
|
|
326
|
+
endedAt: null,
|
|
327
|
+
delayApplied: 0,
|
|
328
|
+
action: "pass",
|
|
329
|
+
status: null,
|
|
330
|
+
aborted: false,
|
|
331
|
+
reordered: false,
|
|
332
|
+
staleRisk: false,
|
|
333
|
+
mode: modesToRun.join("+")
|
|
334
|
+
};
|
|
335
|
+
pushLog(entry);
|
|
336
|
+
options.onRequest?.(entry);
|
|
337
|
+
const activeList = inFlightByKey.get(key) ?? [];
|
|
338
|
+
for (const prev of activeList) {
|
|
339
|
+
if (!prev.signal?.aborted && !MUTATION_METHODS.has(method)) {
|
|
340
|
+
prev.staleRisk = true;
|
|
341
|
+
stats.unabortedStaleCount++;
|
|
342
|
+
keyStat.unabortedStale++;
|
|
343
|
+
options.onRaceDetected?.({
|
|
344
|
+
type: "unaborted-stale",
|
|
345
|
+
method,
|
|
346
|
+
key,
|
|
347
|
+
url,
|
|
348
|
+
requestId: prev.id,
|
|
349
|
+
supersededBy: id,
|
|
350
|
+
detail: `Request #${prev.id} not aborted when #${id} started`
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const tracker = { id, signal, staleRisk: false };
|
|
355
|
+
activeList.push(tracker);
|
|
356
|
+
inFlightByKey.set(key, activeList);
|
|
357
|
+
stats.maxConcurrentPerKey[key] = Math.max(
|
|
358
|
+
stats.maxConcurrentPerKey[key] ?? 0,
|
|
359
|
+
activeList.length
|
|
360
|
+
);
|
|
361
|
+
try {
|
|
362
|
+
if (offlineForced || modesToRun.includes("offline")) {
|
|
363
|
+
stats.injectedErrors++;
|
|
364
|
+
stats.failedRequests++;
|
|
365
|
+
entry.action = "offline-error";
|
|
366
|
+
throw new TypeError("Failed to fetch (offline)");
|
|
367
|
+
}
|
|
368
|
+
if (modesToRun.includes("hang")) {
|
|
369
|
+
stats.hungRequests++;
|
|
370
|
+
entry.action = "hang";
|
|
371
|
+
options.onRaceDetected?.({
|
|
372
|
+
type: "hang",
|
|
373
|
+
key,
|
|
374
|
+
method,
|
|
375
|
+
url,
|
|
376
|
+
requestId: id,
|
|
377
|
+
detail: "Request hung indefinitely"
|
|
378
|
+
});
|
|
379
|
+
await hangUntilAbort(signal);
|
|
380
|
+
}
|
|
381
|
+
if (modesToRun.includes("custom") && options.chaos) {
|
|
382
|
+
let decision;
|
|
383
|
+
try {
|
|
384
|
+
decision = await options.chaos(
|
|
385
|
+
{
|
|
386
|
+
method,
|
|
387
|
+
url,
|
|
388
|
+
key,
|
|
389
|
+
headers: {},
|
|
390
|
+
attempt: 1,
|
|
391
|
+
index: id,
|
|
392
|
+
indexForKey: keyStat.requests,
|
|
393
|
+
...signal ? { signal } : {}
|
|
394
|
+
},
|
|
395
|
+
{ random: rand, now: clock.now }
|
|
396
|
+
);
|
|
397
|
+
} catch (cbErr) {
|
|
398
|
+
throw new ChaosCallbackError("Chaos callback threw an error.", { cause: cbErr });
|
|
399
|
+
}
|
|
400
|
+
if (decision && "hang" in decision && decision.hang) {
|
|
401
|
+
stats.hungRequests++;
|
|
402
|
+
entry.action = "custom-hang";
|
|
403
|
+
await hangUntilAbort(signal);
|
|
404
|
+
} else if (decision && "fail" in decision) {
|
|
405
|
+
stats.injectedErrors++;
|
|
406
|
+
stats.failedRequests++;
|
|
407
|
+
if (decision.fail === "timeout") {
|
|
408
|
+
stats.timeouts++;
|
|
409
|
+
throw new TimeoutError();
|
|
410
|
+
}
|
|
411
|
+
if (decision.fail === "abort") {
|
|
412
|
+
throw new DOMException("Aborted by chaos", "AbortError");
|
|
413
|
+
}
|
|
414
|
+
throw new TypeError("Failed to fetch (custom chaos)");
|
|
415
|
+
} else if (decision && "respond" in decision) {
|
|
416
|
+
stats.injectedErrors++;
|
|
417
|
+
entry.status = decision.respond.status;
|
|
418
|
+
entry.action = "custom-respond";
|
|
419
|
+
return new Response(decision.respond.body ?? "", {
|
|
420
|
+
status: decision.respond.status,
|
|
421
|
+
...decision.respond.headers ? { headers: decision.respond.headers } : {}
|
|
422
|
+
});
|
|
423
|
+
} else if (decision && "delayMs" in decision) {
|
|
424
|
+
entry.delayApplied += decision.delayMs;
|
|
425
|
+
await sleepWithClock(decision.delayMs, clock, signal);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
for (const m of modesToRun) {
|
|
429
|
+
if (m === "timeout") {
|
|
430
|
+
await sleepWithClock(effTimeout, clock, signal);
|
|
431
|
+
stats.timeouts++;
|
|
432
|
+
stats.failedRequests++;
|
|
433
|
+
entry.action = "timeout";
|
|
434
|
+
options.onRaceDetected?.({
|
|
435
|
+
type: "timeout",
|
|
436
|
+
key,
|
|
437
|
+
method,
|
|
438
|
+
url,
|
|
439
|
+
requestId: id,
|
|
440
|
+
detail: `Timed out after ${effTimeout}ms`
|
|
441
|
+
});
|
|
442
|
+
throw new TimeoutError(`Request timed out after ${effTimeout}ms`);
|
|
443
|
+
}
|
|
444
|
+
if (m === "rate-limit") {
|
|
445
|
+
const limit = options.rateLimitAfter ?? DEFAULT_OPTIONS.rateLimitAfter;
|
|
446
|
+
const winMs = options.rateLimitWindowMs ?? DEFAULT_OPTIONS.rateLimitWindowMs;
|
|
447
|
+
const now = clock.now();
|
|
448
|
+
const recent = (rateLimitWindows.get(key) ?? []).filter((t) => now - t <= winMs);
|
|
449
|
+
recent.push(now);
|
|
450
|
+
rateLimitWindows.set(key, recent);
|
|
451
|
+
if (recent.length > limit) {
|
|
452
|
+
stats.rateLimited++;
|
|
453
|
+
stats.injectedErrors++;
|
|
454
|
+
entry.status = 429;
|
|
455
|
+
entry.action = "rate-limited";
|
|
456
|
+
options.onRaceDetected?.({
|
|
457
|
+
type: "rate-limited",
|
|
458
|
+
key,
|
|
459
|
+
method,
|
|
460
|
+
url,
|
|
461
|
+
requestId: id,
|
|
462
|
+
detail: "429 Too Many Requests"
|
|
463
|
+
});
|
|
464
|
+
return new Response("Too Many Requests", {
|
|
465
|
+
status: 429,
|
|
466
|
+
headers: {
|
|
467
|
+
"Retry-After": String(options.retryAfterSeconds ?? DEFAULT_OPTIONS.retryAfterSeconds)
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (m === "flaky" && rand() < effErrorRate) {
|
|
473
|
+
stats.injectedErrors++;
|
|
474
|
+
stats.failedRequests++;
|
|
475
|
+
entry.action = "flaky-error";
|
|
476
|
+
throw new TypeError("Failed to fetch (flaky)");
|
|
477
|
+
}
|
|
478
|
+
if (m === "error-status" && rand() < effErrorRate) {
|
|
479
|
+
const status = matchedRule?.status ?? options.status ?? DEFAULT_OPTIONS.status;
|
|
480
|
+
stats.injectedErrors++;
|
|
481
|
+
entry.status = status;
|
|
482
|
+
entry.action = "error-status";
|
|
483
|
+
return new Response(matchedRule?.body ?? options.body ?? "", {
|
|
484
|
+
status,
|
|
485
|
+
statusText: matchedRule?.statusText ?? options.statusText ?? DEFAULT_OPTIONS.statusText,
|
|
486
|
+
headers: matchedRule?.headers ?? options.headers ?? {}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (m === "slow") {
|
|
490
|
+
entry.delayApplied += effDelay;
|
|
491
|
+
await sleepWithClock(effDelay, clock, signal);
|
|
492
|
+
}
|
|
493
|
+
if (m === "jitter") {
|
|
494
|
+
const span = Math.max(0, effMaxDelay - effMinDelay);
|
|
495
|
+
const d = Math.floor(effMinDelay + rand() * span);
|
|
496
|
+
entry.delayApplied += d;
|
|
497
|
+
await sleepWithClock(d, clock, signal);
|
|
498
|
+
}
|
|
499
|
+
if (m === "shuffle") {
|
|
500
|
+
const d = Math.floor(rand() * (options.shuffleWindowMs ?? DEFAULT_OPTIONS.shuffleWindowMs));
|
|
501
|
+
entry.delayApplied += d;
|
|
502
|
+
await sleepWithClock(d, clock, signal);
|
|
503
|
+
}
|
|
504
|
+
if (m === "throttle-mutations" && MUTATION_METHODS.has(method)) {
|
|
505
|
+
entry.delayApplied += effDelay;
|
|
506
|
+
await sleepWithClock(effDelay, clock, signal);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
let response = await originalFetch(input, init);
|
|
510
|
+
if (modesToRun.includes("reverse-order")) {
|
|
511
|
+
const listNow = inFlightByKey.get(key) ?? [];
|
|
512
|
+
const hasNewer = listNow.some((item) => item.id > id);
|
|
513
|
+
if (hasNewer && !signal?.aborted) {
|
|
514
|
+
entry.delayApplied += effDelay;
|
|
515
|
+
entry.reordered = true;
|
|
516
|
+
entry.action = "reordered";
|
|
517
|
+
stats.reorderedResponses++;
|
|
518
|
+
keyStat.reordered++;
|
|
519
|
+
await sleepWithClock(effDelay, clock, signal);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (modesToRun.includes("abort-mid-body")) {
|
|
523
|
+
stats.partialBodies++;
|
|
524
|
+
entry.action = "abort-mid-body";
|
|
525
|
+
response = makePartialBodyResponse(
|
|
526
|
+
response,
|
|
527
|
+
options.partialBytes ?? DEFAULT_OPTIONS.partialBytes
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
entry.status = response.status ?? 200;
|
|
531
|
+
entry.endedAt = clock.now();
|
|
532
|
+
entry.staleRisk = tracker.staleRisk;
|
|
533
|
+
options.onResponse?.(entry);
|
|
534
|
+
return response;
|
|
535
|
+
} catch (err) {
|
|
536
|
+
if (err?.name === "AbortError" || signal?.aborted) {
|
|
537
|
+
entry.aborted = true;
|
|
538
|
+
stats.abortedCount++;
|
|
539
|
+
} else if (entry.action === "pass") {
|
|
540
|
+
stats.failedRequests++;
|
|
541
|
+
entry.error = err?.message ?? String(err);
|
|
542
|
+
}
|
|
543
|
+
entry.endedAt = clock.now();
|
|
544
|
+
entry.staleRisk = tracker.staleRisk;
|
|
545
|
+
throw err;
|
|
546
|
+
} finally {
|
|
547
|
+
const remaining = (inFlightByKey.get(key) ?? []).filter((item) => item.id !== id);
|
|
548
|
+
if (remaining.length > 0) {
|
|
549
|
+
inFlightByKey.set(key, remaining);
|
|
550
|
+
} else {
|
|
551
|
+
inFlightByKey.delete(key);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
return {
|
|
556
|
+
disable() {
|
|
557
|
+
if (!enabled) return;
|
|
558
|
+
enabled = false;
|
|
559
|
+
target.fetch = rawOriginalFetch;
|
|
560
|
+
if (options.patchBeacon && nav && rawSendBeacon) {
|
|
561
|
+
nav.sendBeacon = rawSendBeacon;
|
|
562
|
+
}
|
|
563
|
+
ACTIVE_TARGETS.delete(target);
|
|
564
|
+
},
|
|
565
|
+
getStats() {
|
|
566
|
+
return {
|
|
567
|
+
...stats,
|
|
568
|
+
maxConcurrentPerKey: { ...stats.maxConcurrentPerKey },
|
|
569
|
+
byKey: { ...stats.byKey }
|
|
570
|
+
};
|
|
571
|
+
},
|
|
572
|
+
getLogs() {
|
|
573
|
+
return logs.map((l) => ({ ...l }));
|
|
574
|
+
},
|
|
575
|
+
resetStats() {
|
|
576
|
+
stats.totalRequests = 0;
|
|
577
|
+
stats.reorderedResponses = 0;
|
|
578
|
+
stats.abortedCount = 0;
|
|
579
|
+
stats.unabortedStaleCount = 0;
|
|
580
|
+
stats.duplicateMutations = 0;
|
|
581
|
+
stats.timeouts = 0;
|
|
582
|
+
stats.failedRequests = 0;
|
|
583
|
+
stats.injectedErrors = 0;
|
|
584
|
+
stats.rateLimited = 0;
|
|
585
|
+
stats.hungRequests = 0;
|
|
586
|
+
stats.partialBodies = 0;
|
|
587
|
+
stats.retriedCount = 0;
|
|
588
|
+
stats.deduplicatedCount = 0;
|
|
589
|
+
stats.maxConcurrentPerKey = {};
|
|
590
|
+
stats.byKey = {};
|
|
591
|
+
logs.length = 0;
|
|
592
|
+
recentMutations.clear();
|
|
593
|
+
rateLimitWindows.clear();
|
|
594
|
+
},
|
|
595
|
+
setOffline(offline) {
|
|
596
|
+
offlineForced = offline;
|
|
597
|
+
},
|
|
598
|
+
setMode(mode) {
|
|
599
|
+
activeModes = validateModes(mode);
|
|
600
|
+
},
|
|
601
|
+
getSeed() {
|
|
602
|
+
return seed;
|
|
603
|
+
},
|
|
604
|
+
isEnabled() {
|
|
605
|
+
return enabled;
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/safe-fetch.ts
|
|
611
|
+
var MUTATION_METHODS2 = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
612
|
+
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
613
|
+
function mergeSignals(signals) {
|
|
614
|
+
const valid = signals.filter((s) => Boolean(s));
|
|
615
|
+
const controller = new AbortController();
|
|
616
|
+
const listeners = [];
|
|
617
|
+
for (const sig of valid) {
|
|
618
|
+
if (sig.aborted) {
|
|
619
|
+
controller.abort(sig.reason);
|
|
620
|
+
return { signal: controller.signal, cleanup: () => {
|
|
621
|
+
} };
|
|
622
|
+
}
|
|
623
|
+
const fn = () => controller.abort(sig.reason);
|
|
624
|
+
sig.addEventListener("abort", fn, { once: true });
|
|
625
|
+
listeners.push({ sig, fn });
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
signal: controller.signal,
|
|
629
|
+
cleanup: () => {
|
|
630
|
+
for (const { sig, fn } of listeners) {
|
|
631
|
+
sig.removeEventListener("abort", fn);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function sleep(ms, signal) {
|
|
637
|
+
return new Promise((resolve, reject) => {
|
|
638
|
+
if (signal?.aborted) {
|
|
639
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const timer = setTimeout(() => {
|
|
643
|
+
signal?.removeEventListener("abort", onAbort);
|
|
644
|
+
resolve();
|
|
645
|
+
}, ms);
|
|
646
|
+
function onAbort() {
|
|
647
|
+
clearTimeout(timer);
|
|
648
|
+
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
649
|
+
}
|
|
650
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
function parseRetryAfterMs(headerVal) {
|
|
654
|
+
if (!headerVal) return null;
|
|
655
|
+
const secs = Number(headerVal);
|
|
656
|
+
if (!Number.isNaN(secs) && secs >= 0) return secs * 1e3;
|
|
657
|
+
const dateMs = Date.parse(headerVal);
|
|
658
|
+
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
function createRaceSafeFetch(fetchImpl = (...args) => globalThis.fetch(...args), optionsOrNormalizeKey = {}) {
|
|
662
|
+
const isFn = typeof optionsOrNormalizeKey === "function";
|
|
663
|
+
const opts = isFn ? { normalizeKey: optionsOrNormalizeKey } : optionsOrNormalizeKey;
|
|
664
|
+
const normalizeKey = opts.keyBy ?? opts.normalizeKey ?? defaultNormalizeKey;
|
|
665
|
+
const supersedeMethods = new Set(
|
|
666
|
+
(opts.supersedeMethods ?? ["GET", "HEAD"]).map((m) => m.toUpperCase())
|
|
667
|
+
);
|
|
668
|
+
const dedupeMutations = Boolean(opts.dedupeMutations);
|
|
669
|
+
const dedupeWindowMs = opts.dedupeWindowMs ?? 0;
|
|
670
|
+
const timeoutMs = opts.timeoutMs ?? 0;
|
|
671
|
+
const totalTimeoutMs = opts.totalTimeoutMs ?? 0;
|
|
672
|
+
const retries = opts.retries ?? 0;
|
|
673
|
+
const retryMethods = new Set(
|
|
674
|
+
(opts.retryMethods ?? ["GET", "HEAD", "OPTIONS"]).map((m) => m.toUpperCase())
|
|
675
|
+
);
|
|
676
|
+
const retryDelayMs = opts.retryDelayMs ?? 200;
|
|
677
|
+
const retryBackoff = opts.retryBackoff ?? 2;
|
|
678
|
+
const maxRetryDelayMs = opts.maxRetryDelayMs ?? 1e4;
|
|
679
|
+
const retryJitter = opts.retryJitter ?? true;
|
|
680
|
+
const respectRetryAfter = opts.respectRetryAfter ?? true;
|
|
681
|
+
const controllers = /* @__PURE__ */ new Map();
|
|
682
|
+
const inFlightMutations = /* @__PURE__ */ new Map();
|
|
683
|
+
const defaultRetryOn = (resOrErr) => {
|
|
684
|
+
if (resOrErr instanceof Error) {
|
|
685
|
+
if (isSupersededError(resOrErr) || resOrErr.name === "AbortError") return false;
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
return RETRY_STATUSES.has(resOrErr.status);
|
|
689
|
+
};
|
|
690
|
+
const shouldRetry = opts.retryOn ?? defaultRetryOn;
|
|
691
|
+
const runOnce = async (input, init, baseSignal, key) => {
|
|
692
|
+
if (!timeoutMs || timeoutMs <= 0) {
|
|
693
|
+
return fetchImpl(input, { ...init, ...baseSignal ? { signal: baseSignal } : {} });
|
|
694
|
+
}
|
|
695
|
+
const timeoutController = new AbortController();
|
|
696
|
+
let timedOut = false;
|
|
697
|
+
const timer = setTimeout(() => {
|
|
698
|
+
timedOut = true;
|
|
699
|
+
const err = new TimeoutError(`Request timed out after ${timeoutMs}ms`);
|
|
700
|
+
timeoutController.abort(err);
|
|
701
|
+
if (key) opts.onTimeout?.({ key, timeoutMs });
|
|
702
|
+
}, timeoutMs);
|
|
703
|
+
const merged = mergeSignals([baseSignal, timeoutController.signal]);
|
|
704
|
+
try {
|
|
705
|
+
return await fetchImpl(input, { ...init, signal: merged.signal });
|
|
706
|
+
} catch (err) {
|
|
707
|
+
if (timedOut) {
|
|
708
|
+
throw new TimeoutError(`Request timed out after ${timeoutMs}ms`);
|
|
709
|
+
}
|
|
710
|
+
throw err;
|
|
711
|
+
} finally {
|
|
712
|
+
clearTimeout(timer);
|
|
713
|
+
merged.cleanup();
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
return async function raceSafeFetch(input, init = {}) {
|
|
717
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
718
|
+
const method = (init?.method || (typeof input === "object" && "method" in input ? input.method : void 0) || "GET").toUpperCase();
|
|
719
|
+
const key = normalizeKey(url, method);
|
|
720
|
+
const headers = new Headers(
|
|
721
|
+
init?.headers ?? (typeof input === "object" && "headers" in input ? input.headers : void 0)
|
|
722
|
+
);
|
|
723
|
+
if (opts.idempotencyKey && MUTATION_METHODS2.has(method) && !headers.has("Idempotency-Key")) {
|
|
724
|
+
const ikey = typeof opts.idempotencyKey === "function" ? opts.idempotencyKey(url, method) : `${key}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
725
|
+
headers.set("Idempotency-Key", ikey);
|
|
726
|
+
}
|
|
727
|
+
const nextInit = { ...init, headers };
|
|
728
|
+
if (supersedeMethods.has(method)) {
|
|
729
|
+
const prev = controllers.get(key);
|
|
730
|
+
if (prev) {
|
|
731
|
+
opts.onAbort?.({ key, url, method });
|
|
732
|
+
prev.abort(new SupersededError());
|
|
733
|
+
}
|
|
734
|
+
const controller = new AbortController();
|
|
735
|
+
controllers.set(key, controller);
|
|
736
|
+
const merged = mergeSignals([
|
|
737
|
+
init?.signal ?? (typeof input === "object" && "signal" in input ? input.signal : void 0),
|
|
738
|
+
controller.signal
|
|
739
|
+
]);
|
|
740
|
+
const totalDeadline = totalTimeoutMs > 0 ? Date.now() + totalTimeoutMs : Infinity;
|
|
741
|
+
try {
|
|
742
|
+
let attempt = 0;
|
|
743
|
+
while (true) {
|
|
744
|
+
try {
|
|
745
|
+
const res = await runOnce(input, nextInit, merged.signal, key);
|
|
746
|
+
if (attempt < retries && retryMethods.has(method) && shouldRetry(res, attempt + 1) && Date.now() < totalDeadline) {
|
|
747
|
+
attempt++;
|
|
748
|
+
const ra = respectRetryAfter ? parseRetryAfterMs(res.headers?.get?.("Retry-After") ?? null) : null;
|
|
749
|
+
const rawDelay = ra ?? Math.min(maxRetryDelayMs, retryDelayMs * retryBackoff ** (attempt - 1));
|
|
750
|
+
const d = retryJitter ? Math.floor(rawDelay * (0.5 + Math.random() * 0.5)) : rawDelay;
|
|
751
|
+
opts.onRetry?.({ key, attempt, delayMs: d });
|
|
752
|
+
await sleep(d, merged.signal);
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
return res;
|
|
756
|
+
} catch (err) {
|
|
757
|
+
const userAborted = isSupersededError(err) || err?.name === "AbortError" || merged.signal.aborted;
|
|
758
|
+
if (!userAborted && attempt < retries && retryMethods.has(method) && shouldRetry(err, attempt + 1) && Date.now() < totalDeadline) {
|
|
759
|
+
attempt++;
|
|
760
|
+
const rawDelay = Math.min(maxRetryDelayMs, retryDelayMs * retryBackoff ** (attempt - 1));
|
|
761
|
+
const d = retryJitter ? Math.floor(rawDelay * (0.5 + Math.random() * 0.5)) : rawDelay;
|
|
762
|
+
opts.onRetry?.({ key, attempt, delayMs: d });
|
|
763
|
+
await sleep(d, merged.signal);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
throw err;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
} finally {
|
|
770
|
+
merged.cleanup();
|
|
771
|
+
if (controllers.get(key) === controller) {
|
|
772
|
+
controllers.delete(key);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (dedupeMutations && MUTATION_METHODS2.has(method)) {
|
|
777
|
+
const existing = inFlightMutations.get(key);
|
|
778
|
+
if (existing && (dedupeWindowMs === 0 || Date.now() - existing.startedAt <= dedupeWindowMs)) {
|
|
779
|
+
opts.onDedupe?.({ key, url });
|
|
780
|
+
const res2 = await existing.promise;
|
|
781
|
+
return typeof res2?.clone === "function" ? res2.clone() : res2;
|
|
782
|
+
}
|
|
783
|
+
const promise = Promise.resolve(runOnce(input, nextInit, init?.signal ?? void 0, key)).finally(() => {
|
|
784
|
+
if (inFlightMutations.get(key)?.promise === promise) {
|
|
785
|
+
inFlightMutations.delete(key);
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
inFlightMutations.set(key, { promise, startedAt: Date.now() });
|
|
789
|
+
const res = await promise;
|
|
790
|
+
return typeof res?.clone === "function" ? res.clone() : res;
|
|
791
|
+
}
|
|
792
|
+
return runOnce(input, nextInit, init?.signal ?? void 0, key);
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function createLatestGuard() {
|
|
796
|
+
let currentId = 0;
|
|
797
|
+
let currentController = null;
|
|
798
|
+
return {
|
|
799
|
+
next() {
|
|
800
|
+
currentController?.abort(new SupersededError());
|
|
801
|
+
currentId++;
|
|
802
|
+
const id = currentId;
|
|
803
|
+
const controller = new AbortController();
|
|
804
|
+
currentController = controller;
|
|
805
|
+
return {
|
|
806
|
+
id,
|
|
807
|
+
signal: controller.signal,
|
|
808
|
+
isLatest: () => id === currentId
|
|
809
|
+
};
|
|
810
|
+
},
|
|
811
|
+
async run(fn) {
|
|
812
|
+
const ticket = this.next();
|
|
813
|
+
const value = await fn(ticket.signal);
|
|
814
|
+
if (!ticket.isLatest()) {
|
|
815
|
+
return { stale: true };
|
|
816
|
+
}
|
|
817
|
+
return { stale: false, value };
|
|
818
|
+
},
|
|
819
|
+
reset() {
|
|
820
|
+
currentController?.abort(new SupersededError());
|
|
821
|
+
currentController = null;
|
|
822
|
+
currentId++;
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// src/browser.ts
|
|
828
|
+
var ReqRace = {
|
|
829
|
+
enable: enableFetchRaceChaos,
|
|
830
|
+
createRaceSafeFetch,
|
|
831
|
+
createLatestGuard
|
|
832
|
+
};
|
|
833
|
+
if (typeof globalThis !== "undefined") {
|
|
834
|
+
globalThis.ReqRace = ReqRace;
|
|
835
|
+
}
|
|
836
|
+
var browser_default = ReqRace;
|
|
837
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
838
|
+
0 && (module.exports = {
|
|
839
|
+
ReqRace,
|
|
840
|
+
createLatestGuard,
|
|
841
|
+
createRaceSafeFetch,
|
|
842
|
+
enableFetchRaceChaos
|
|
843
|
+
});
|