@kivacore/devtools 0.0.0 → 0.9.2
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 +245 -1
- package/dist/core/index.d.ts +145 -0
- package/dist/core/index.js +1989 -0
- package/dist/core/index.js.map +1 -0
- package/dist/dom-selector-Dsp7e405.d.ts +274 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +5285 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -4
|
@@ -0,0 +1,1989 @@
|
|
|
1
|
+
import { DocyrusClient } from '@kivacore/addin-client';
|
|
2
|
+
import { RestApiClient } from '@kivacore/api-client';
|
|
3
|
+
|
|
4
|
+
// src/core/sanitize.ts
|
|
5
|
+
var REDACTED = "[redacted]";
|
|
6
|
+
var MAX_DEPTH = 4;
|
|
7
|
+
var MAX_ARRAY_ITEMS = 20;
|
|
8
|
+
var MAX_OBJECT_KEYS = 20;
|
|
9
|
+
var MAX_STRING_LENGTH = 400;
|
|
10
|
+
var MAX_STACK_LENGTH = 1200;
|
|
11
|
+
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
12
|
+
"authorization",
|
|
13
|
+
"cookie",
|
|
14
|
+
"password",
|
|
15
|
+
"token",
|
|
16
|
+
"access_token",
|
|
17
|
+
"refresh_token"
|
|
18
|
+
]);
|
|
19
|
+
function isSensitiveKey(key) {
|
|
20
|
+
const normalized = key.toLowerCase().replace(/[^a-z0-9_]/g, "");
|
|
21
|
+
if (SENSITIVE_KEYS.has(normalized)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return normalized.includes("token");
|
|
25
|
+
}
|
|
26
|
+
function truncateString(value, limit = MAX_STRING_LENGTH) {
|
|
27
|
+
if (value.length <= limit) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return `${value.slice(0, limit)}... (${value.length - limit} more chars)`;
|
|
31
|
+
}
|
|
32
|
+
function isPlainObject(value) {
|
|
33
|
+
if (!value || typeof value !== "object") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const prototype = Object.getPrototypeOf(value);
|
|
37
|
+
return prototype === Object.prototype || prototype === null;
|
|
38
|
+
}
|
|
39
|
+
function hasConstructor(ctor) {
|
|
40
|
+
return typeof ctor === "function";
|
|
41
|
+
}
|
|
42
|
+
function sanitizeHeadersLike(value) {
|
|
43
|
+
const output = {};
|
|
44
|
+
const entries = value instanceof Map ? value.entries() : value.entries();
|
|
45
|
+
for (const [key, entryValue] of entries) {
|
|
46
|
+
output[key] = isSensitiveKey(String(key)) ? REDACTED : truncateString(String(entryValue));
|
|
47
|
+
}
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
function sanitizeForDevtools(value, seen = /* @__PURE__ */ new WeakSet(), depth = 0) {
|
|
51
|
+
if (value == null || typeof value === "boolean" || typeof value === "number") {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "bigint") {
|
|
55
|
+
return `${value.toString()}n`;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === "string") {
|
|
58
|
+
return truncateString(value);
|
|
59
|
+
}
|
|
60
|
+
if (typeof value === "function") {
|
|
61
|
+
return `[Function ${value.name || "anonymous"}]`;
|
|
62
|
+
}
|
|
63
|
+
if (value instanceof Date) {
|
|
64
|
+
return value.toISOString();
|
|
65
|
+
}
|
|
66
|
+
if (value instanceof Error) {
|
|
67
|
+
return normalizeError(value);
|
|
68
|
+
}
|
|
69
|
+
if (hasConstructor(globalThis.Headers) && value instanceof Headers) {
|
|
70
|
+
return sanitizeHeadersLike(value);
|
|
71
|
+
}
|
|
72
|
+
if (value instanceof URLSearchParams) {
|
|
73
|
+
return sanitizeHeadersLike(value);
|
|
74
|
+
}
|
|
75
|
+
if (hasConstructor(globalThis.FormData) && value instanceof FormData) {
|
|
76
|
+
const entries = {};
|
|
77
|
+
let index = 0;
|
|
78
|
+
for (const [key, entryValue] of value.entries()) {
|
|
79
|
+
if (index >= MAX_OBJECT_KEYS) {
|
|
80
|
+
entries.__truncated__ = `Only the first ${MAX_OBJECT_KEYS} fields are shown`;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (isSensitiveKey(key)) {
|
|
84
|
+
entries[key] = REDACTED;
|
|
85
|
+
} else if (hasConstructor(globalThis.File) && entryValue instanceof File) {
|
|
86
|
+
entries[key] = {
|
|
87
|
+
type: "File",
|
|
88
|
+
name: entryValue.name,
|
|
89
|
+
size: entryValue.size,
|
|
90
|
+
mimeType: entryValue.type
|
|
91
|
+
};
|
|
92
|
+
} else {
|
|
93
|
+
entries[key] = truncateString(String(entryValue));
|
|
94
|
+
}
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
type: "FormData",
|
|
99
|
+
entries
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (hasConstructor(globalThis.Blob) && value instanceof Blob) {
|
|
103
|
+
return {
|
|
104
|
+
type: "Blob",
|
|
105
|
+
size: value.size,
|
|
106
|
+
mimeType: value.type || "application/octet-stream"
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
if (depth >= MAX_DEPTH) {
|
|
111
|
+
return `[Array(${value.length})]`;
|
|
112
|
+
}
|
|
113
|
+
const items = value.slice(0, MAX_ARRAY_ITEMS).map((item) => sanitizeForDevtools(item, seen, depth + 1));
|
|
114
|
+
if (value.length > MAX_ARRAY_ITEMS) {
|
|
115
|
+
items.push(`... (${value.length - MAX_ARRAY_ITEMS} more items)`);
|
|
116
|
+
}
|
|
117
|
+
return items;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === "object") {
|
|
120
|
+
if (seen.has(value)) {
|
|
121
|
+
return "[Circular]";
|
|
122
|
+
}
|
|
123
|
+
if (depth >= MAX_DEPTH) {
|
|
124
|
+
const name = value.constructor?.name;
|
|
125
|
+
return name ? `[${name}]` : "[Object]";
|
|
126
|
+
}
|
|
127
|
+
seen.add(value);
|
|
128
|
+
if (!isPlainObject(value)) {
|
|
129
|
+
const output2 = {
|
|
130
|
+
__type: value.constructor?.name || "Object"
|
|
131
|
+
};
|
|
132
|
+
for (const [key, entryValue] of Object.entries(value).slice(0, MAX_OBJECT_KEYS)) {
|
|
133
|
+
output2[key] = isSensitiveKey(key) ? REDACTED : sanitizeForDevtools(entryValue, seen, depth + 1);
|
|
134
|
+
}
|
|
135
|
+
return output2;
|
|
136
|
+
}
|
|
137
|
+
const output = {};
|
|
138
|
+
const keys = Object.keys(value).sort().slice(0, MAX_OBJECT_KEYS);
|
|
139
|
+
for (const key of keys) {
|
|
140
|
+
output[key] = isSensitiveKey(key) ? REDACTED : sanitizeForDevtools(value[key], seen, depth + 1);
|
|
141
|
+
}
|
|
142
|
+
if (Object.keys(value).length > MAX_OBJECT_KEYS) {
|
|
143
|
+
output.__truncated__ = `Only the first ${MAX_OBJECT_KEYS} keys are shown`;
|
|
144
|
+
}
|
|
145
|
+
return output;
|
|
146
|
+
}
|
|
147
|
+
return String(value);
|
|
148
|
+
}
|
|
149
|
+
function stableStringify(value) {
|
|
150
|
+
if (value == null || typeof value === "boolean" || typeof value === "number") {
|
|
151
|
+
return JSON.stringify(value);
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "string") {
|
|
154
|
+
return JSON.stringify(value);
|
|
155
|
+
}
|
|
156
|
+
if (Array.isArray(value)) {
|
|
157
|
+
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
158
|
+
}
|
|
159
|
+
if (typeof value === "object") {
|
|
160
|
+
const entries = Object.entries(value).sort(([left], [right]) => left.localeCompare(right));
|
|
161
|
+
return `{${entries.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`;
|
|
162
|
+
}
|
|
163
|
+
return JSON.stringify(String(value));
|
|
164
|
+
}
|
|
165
|
+
function normalizeError(error) {
|
|
166
|
+
if (error instanceof Error) {
|
|
167
|
+
return {
|
|
168
|
+
name: error.name,
|
|
169
|
+
message: error.message,
|
|
170
|
+
stack: error.stack ? truncateString(error.stack, MAX_STACK_LENGTH) : void 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
name: "Error",
|
|
175
|
+
message: typeof error === "string" ? truncateString(error) : truncateString(String(error))
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/core/store.ts
|
|
180
|
+
function performanceNow() {
|
|
181
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
182
|
+
}
|
|
183
|
+
function createId(prefix) {
|
|
184
|
+
const randomId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
185
|
+
return `${prefix}-${randomId}`;
|
|
186
|
+
}
|
|
187
|
+
var DevtoolsStoreImpl = class {
|
|
188
|
+
entries = [];
|
|
189
|
+
consoleEntries = [];
|
|
190
|
+
messageEntries = [];
|
|
191
|
+
issues = /* @__PURE__ */ new Map();
|
|
192
|
+
pending = /* @__PURE__ */ new Map();
|
|
193
|
+
listeners = /* @__PURE__ */ new Set();
|
|
194
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
195
|
+
recentStarts = [];
|
|
196
|
+
maxEntries;
|
|
197
|
+
slowThresholdMs;
|
|
198
|
+
cachedSnapshot = null;
|
|
199
|
+
constructor(options = {}) {
|
|
200
|
+
this.maxEntries = options.maxEntries ?? 200;
|
|
201
|
+
this.slowThresholdMs = options.slowThresholdMs ?? 1e3;
|
|
202
|
+
this.getSnapshot = this.getSnapshot.bind(this);
|
|
203
|
+
this.subscribe = this.subscribe.bind(this);
|
|
204
|
+
}
|
|
205
|
+
getSnapshot() {
|
|
206
|
+
if (this.cachedSnapshot) {
|
|
207
|
+
return this.cachedSnapshot;
|
|
208
|
+
}
|
|
209
|
+
const issues = Array.from(this.issues.values()).sort((left, right) => right.lastSeenAt - left.lastSeenAt);
|
|
210
|
+
const entries = [...this.entries].sort((left, right) => right.startedAt - left.startedAt);
|
|
211
|
+
this.cachedSnapshot = {
|
|
212
|
+
entries,
|
|
213
|
+
issues,
|
|
214
|
+
consoleEntries: [...this.consoleEntries].sort((left, right) => right.timestamp - left.timestamp),
|
|
215
|
+
messageEntries: [...this.messageEntries].sort((left, right) => right.timestamp - left.timestamp),
|
|
216
|
+
errorCount: entries.filter((entry) => entry.outcome === "error").length,
|
|
217
|
+
warningCount: issues.filter((issue) => issue.severity === "warning").length,
|
|
218
|
+
maxEntries: this.maxEntries,
|
|
219
|
+
slowThresholdMs: this.slowThresholdMs
|
|
220
|
+
};
|
|
221
|
+
return this.cachedSnapshot;
|
|
222
|
+
}
|
|
223
|
+
subscribe(listener) {
|
|
224
|
+
this.listeners.add(listener);
|
|
225
|
+
return () => {
|
|
226
|
+
this.listeners.delete(listener);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
clear() {
|
|
230
|
+
this.entries = [];
|
|
231
|
+
this.consoleEntries = [];
|
|
232
|
+
this.messageEntries = [];
|
|
233
|
+
this.issues.clear();
|
|
234
|
+
this.pending.clear();
|
|
235
|
+
this.inFlight.clear();
|
|
236
|
+
this.recentStarts = [];
|
|
237
|
+
this.emit();
|
|
238
|
+
}
|
|
239
|
+
updateOptions(options) {
|
|
240
|
+
const nextMaxEntries = options.maxEntries ?? this.maxEntries;
|
|
241
|
+
const nextSlowThresholdMs = options.slowThresholdMs ?? this.slowThresholdMs;
|
|
242
|
+
if (nextMaxEntries === this.maxEntries && nextSlowThresholdMs === this.slowThresholdMs) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.maxEntries = nextMaxEntries;
|
|
246
|
+
this.slowThresholdMs = nextSlowThresholdMs;
|
|
247
|
+
this.trimEntries();
|
|
248
|
+
this.emit();
|
|
249
|
+
}
|
|
250
|
+
beginEntry(input) {
|
|
251
|
+
const id = createId("entry");
|
|
252
|
+
const startedAt = Date.now();
|
|
253
|
+
const pending = {
|
|
254
|
+
...input,
|
|
255
|
+
id,
|
|
256
|
+
startedAt,
|
|
257
|
+
startedPerf: performanceNow()
|
|
258
|
+
};
|
|
259
|
+
this.pending.set(id, pending);
|
|
260
|
+
if (input.kind !== "fetch") {
|
|
261
|
+
this.pushRecentStart(input.fingerprint, input.routeKey, startedAt);
|
|
262
|
+
}
|
|
263
|
+
const inFlightKey = this.getInFlightKey(input.routeKey, input.fingerprint);
|
|
264
|
+
const existing = this.inFlight.get(inFlightKey) ?? /* @__PURE__ */ new Set();
|
|
265
|
+
if (existing.size > 0) {
|
|
266
|
+
this.recordIssue({
|
|
267
|
+
code: "duplicate-request",
|
|
268
|
+
title: "Duplicate request",
|
|
269
|
+
message: `Overlapping request detected for ${input.operation}`,
|
|
270
|
+
routeKey: input.routeKey,
|
|
271
|
+
fingerprint: input.fingerprint,
|
|
272
|
+
context: {
|
|
273
|
+
operation: input.operation,
|
|
274
|
+
target: input.target,
|
|
275
|
+
method: input.method
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
existing.add(id);
|
|
280
|
+
this.inFlight.set(inFlightKey, existing);
|
|
281
|
+
return id;
|
|
282
|
+
}
|
|
283
|
+
finalizeEntry(entryId, input = {}) {
|
|
284
|
+
const pending = this.pending.get(entryId);
|
|
285
|
+
if (!pending) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.pending.delete(entryId);
|
|
289
|
+
this.releaseInFlight(pending);
|
|
290
|
+
const durationMs = Math.round(performanceNow() - pending.startedPerf);
|
|
291
|
+
const entry = {
|
|
292
|
+
id: entryId,
|
|
293
|
+
kind: pending.kind,
|
|
294
|
+
source: pending.source,
|
|
295
|
+
operation: pending.operation,
|
|
296
|
+
method: pending.method,
|
|
297
|
+
target: pending.target,
|
|
298
|
+
routeKey: pending.routeKey,
|
|
299
|
+
fingerprint: pending.fingerprint,
|
|
300
|
+
startedAt: pending.startedAt,
|
|
301
|
+
finishedAt: Date.now(),
|
|
302
|
+
durationMs,
|
|
303
|
+
outcome: "success",
|
|
304
|
+
status: input.status,
|
|
305
|
+
params: sanitizeForDevtools(pending.params),
|
|
306
|
+
request: sanitizeForDevtools(pending.request),
|
|
307
|
+
response: sanitizeForDevtools(input.response),
|
|
308
|
+
meta: sanitizeForDevtools({
|
|
309
|
+
...pending.meta,
|
|
310
|
+
...input.meta
|
|
311
|
+
})
|
|
312
|
+
};
|
|
313
|
+
this.entries.push(entry);
|
|
314
|
+
this.trimEntries();
|
|
315
|
+
if (durationMs > this.slowThresholdMs) {
|
|
316
|
+
this.recordIssue({
|
|
317
|
+
code: "slow-request",
|
|
318
|
+
title: "Slow request",
|
|
319
|
+
message: `${pending.operation} took ${durationMs} ms`,
|
|
320
|
+
routeKey: pending.routeKey,
|
|
321
|
+
fingerprint: pending.fingerprint,
|
|
322
|
+
latestDurationMs: durationMs,
|
|
323
|
+
context: {
|
|
324
|
+
operation: pending.operation,
|
|
325
|
+
target: pending.target,
|
|
326
|
+
method: pending.method
|
|
327
|
+
},
|
|
328
|
+
entryId
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
this.emit();
|
|
333
|
+
}
|
|
334
|
+
failEntry(entryId, input) {
|
|
335
|
+
const pending = this.pending.get(entryId);
|
|
336
|
+
if (!pending) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
this.pending.delete(entryId);
|
|
340
|
+
this.releaseInFlight(pending);
|
|
341
|
+
const durationMs = Math.round(performanceNow() - pending.startedPerf);
|
|
342
|
+
const entry = {
|
|
343
|
+
id: entryId,
|
|
344
|
+
kind: pending.kind,
|
|
345
|
+
source: pending.source,
|
|
346
|
+
operation: pending.operation,
|
|
347
|
+
method: pending.method,
|
|
348
|
+
target: pending.target,
|
|
349
|
+
routeKey: pending.routeKey,
|
|
350
|
+
fingerprint: pending.fingerprint,
|
|
351
|
+
startedAt: pending.startedAt,
|
|
352
|
+
finishedAt: Date.now(),
|
|
353
|
+
durationMs,
|
|
354
|
+
outcome: "error",
|
|
355
|
+
status: input.status,
|
|
356
|
+
params: sanitizeForDevtools(pending.params),
|
|
357
|
+
request: sanitizeForDevtools(pending.request),
|
|
358
|
+
error: normalizeError(input.error),
|
|
359
|
+
meta: sanitizeForDevtools({
|
|
360
|
+
...pending.meta,
|
|
361
|
+
...input.meta
|
|
362
|
+
})
|
|
363
|
+
};
|
|
364
|
+
this.entries.push(entry);
|
|
365
|
+
this.trimEntries();
|
|
366
|
+
if (durationMs > this.slowThresholdMs) {
|
|
367
|
+
this.recordIssue({
|
|
368
|
+
code: "slow-request",
|
|
369
|
+
title: "Slow request",
|
|
370
|
+
message: `${pending.operation} failed after ${durationMs} ms`,
|
|
371
|
+
routeKey: pending.routeKey,
|
|
372
|
+
fingerprint: pending.fingerprint,
|
|
373
|
+
latestDurationMs: durationMs,
|
|
374
|
+
context: {
|
|
375
|
+
operation: pending.operation,
|
|
376
|
+
target: pending.target,
|
|
377
|
+
method: pending.method
|
|
378
|
+
},
|
|
379
|
+
entryId
|
|
380
|
+
});
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
this.emit();
|
|
384
|
+
}
|
|
385
|
+
recordConsoleEntry(input) {
|
|
386
|
+
const timestamp = input.timestamp ?? Date.now();
|
|
387
|
+
const entry = {
|
|
388
|
+
id: createId("console"),
|
|
389
|
+
level: input.level,
|
|
390
|
+
source: input.source ?? "console",
|
|
391
|
+
message: input.message ?? "",
|
|
392
|
+
args: sanitizeForDevtools(input.args ?? []),
|
|
393
|
+
timestamp,
|
|
394
|
+
stack: input.stack
|
|
395
|
+
};
|
|
396
|
+
this.consoleEntries.push(entry);
|
|
397
|
+
this.trimConsoleEntries();
|
|
398
|
+
this.emit();
|
|
399
|
+
}
|
|
400
|
+
recordMessageEntry(input) {
|
|
401
|
+
const timestamp = input.timestamp ?? Date.now();
|
|
402
|
+
const inferredType = input.type ?? (input.payload && typeof input.payload === "object" && !Array.isArray(input.payload) && typeof input.payload.type === "string" ? input.payload.type : void 0);
|
|
403
|
+
const entry = {
|
|
404
|
+
id: createId("message"),
|
|
405
|
+
direction: input.direction,
|
|
406
|
+
transport: input.transport ?? "iframe",
|
|
407
|
+
type: inferredType,
|
|
408
|
+
origin: input.origin,
|
|
409
|
+
targetOrigin: input.targetOrigin,
|
|
410
|
+
payload: sanitizeForDevtools(input.payload),
|
|
411
|
+
timestamp
|
|
412
|
+
};
|
|
413
|
+
this.messageEntries.push(entry);
|
|
414
|
+
this.trimMessageEntries();
|
|
415
|
+
this.emit();
|
|
416
|
+
}
|
|
417
|
+
recordIssue(input) {
|
|
418
|
+
const key = `${input.code}::${input.routeKey}::${input.fingerprint}`;
|
|
419
|
+
const now = Date.now();
|
|
420
|
+
const existing = this.issues.get(key);
|
|
421
|
+
if (existing) {
|
|
422
|
+
existing.count += 1;
|
|
423
|
+
existing.lastSeenAt = now;
|
|
424
|
+
existing.latestDurationMs = input.latestDurationMs ?? existing.latestDurationMs;
|
|
425
|
+
existing.context = sanitizeForDevtools(input.context);
|
|
426
|
+
if (input.entryId && !existing.entryIds.includes(input.entryId)) {
|
|
427
|
+
existing.entryIds = [...existing.entryIds, input.entryId];
|
|
428
|
+
}
|
|
429
|
+
} else {
|
|
430
|
+
this.issues.set(key, {
|
|
431
|
+
id: key,
|
|
432
|
+
code: input.code,
|
|
433
|
+
severity: input.severity ?? "warning",
|
|
434
|
+
title: input.title,
|
|
435
|
+
message: input.message,
|
|
436
|
+
routeKey: input.routeKey,
|
|
437
|
+
fingerprint: input.fingerprint,
|
|
438
|
+
count: 1,
|
|
439
|
+
firstSeenAt: now,
|
|
440
|
+
lastSeenAt: now,
|
|
441
|
+
latestDurationMs: input.latestDurationMs,
|
|
442
|
+
context: sanitizeForDevtools(input.context),
|
|
443
|
+
entryIds: input.entryId ? [input.entryId] : []
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
this.emit();
|
|
447
|
+
}
|
|
448
|
+
shouldSkipFetchCapture(input) {
|
|
449
|
+
const threshold = 150;
|
|
450
|
+
this.recentStarts = this.recentStarts.filter((item) => input.startedAt - item.startedAt < 2e3);
|
|
451
|
+
return this.recentStarts.some((item) => item.fingerprint === input.fingerprint && item.routeKey === input.routeKey && Math.abs(item.startedAt - input.startedAt) <= threshold);
|
|
452
|
+
}
|
|
453
|
+
pushRecentStart(fingerprint, routeKey, startedAt) {
|
|
454
|
+
this.recentStarts.push({ fingerprint, routeKey, startedAt });
|
|
455
|
+
this.recentStarts = this.recentStarts.filter((item) => startedAt - item.startedAt < 2e3);
|
|
456
|
+
}
|
|
457
|
+
releaseInFlight(pending) {
|
|
458
|
+
const key = this.getInFlightKey(pending.routeKey, pending.fingerprint);
|
|
459
|
+
const current = this.inFlight.get(key);
|
|
460
|
+
if (!current) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
current.delete(pending.id);
|
|
464
|
+
if (current.size === 0) {
|
|
465
|
+
this.inFlight.delete(key);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
this.inFlight.set(key, current);
|
|
469
|
+
}
|
|
470
|
+
getInFlightKey(routeKey, fingerprint) {
|
|
471
|
+
return `${routeKey}::${fingerprint}`;
|
|
472
|
+
}
|
|
473
|
+
trimEntries() {
|
|
474
|
+
if (this.entries.length <= this.maxEntries) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.entries = this.entries.slice(this.entries.length - this.maxEntries);
|
|
478
|
+
}
|
|
479
|
+
trimConsoleEntries() {
|
|
480
|
+
if (this.consoleEntries.length <= this.maxEntries) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
this.consoleEntries = this.consoleEntries.slice(this.consoleEntries.length - this.maxEntries);
|
|
484
|
+
}
|
|
485
|
+
trimMessageEntries() {
|
|
486
|
+
if (this.messageEntries.length <= this.maxEntries) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
this.messageEntries = this.messageEntries.slice(this.messageEntries.length - this.maxEntries);
|
|
490
|
+
}
|
|
491
|
+
emit() {
|
|
492
|
+
this.cachedSnapshot = null;
|
|
493
|
+
for (const listener of this.listeners) {
|
|
494
|
+
listener();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
function createDevtoolsStore(options = {}) {
|
|
499
|
+
return new DevtoolsStoreImpl(options);
|
|
500
|
+
}
|
|
501
|
+
var apiClientPatches = /* @__PURE__ */ new WeakMap();
|
|
502
|
+
var html2PdfPatches = /* @__PURE__ */ new WeakMap();
|
|
503
|
+
var addinClientPatches = /* @__PURE__ */ new WeakMap();
|
|
504
|
+
var fetchPatch;
|
|
505
|
+
function getRouteKey() {
|
|
506
|
+
if (typeof window === "undefined") {
|
|
507
|
+
return "/";
|
|
508
|
+
}
|
|
509
|
+
return `${window.location.pathname}${window.location.search}`;
|
|
510
|
+
}
|
|
511
|
+
function createFingerprint(input) {
|
|
512
|
+
return stableStringify(sanitizeForDevtools(input));
|
|
513
|
+
}
|
|
514
|
+
function appendQueryParams(url, params) {
|
|
515
|
+
if (!params) {
|
|
516
|
+
return url;
|
|
517
|
+
}
|
|
518
|
+
for (const [key, value] of Object.entries(params)) {
|
|
519
|
+
if (Array.isArray(value)) {
|
|
520
|
+
for (const item of value) {
|
|
521
|
+
if (item == null) {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
url.searchParams.append(key, String(item));
|
|
525
|
+
}
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
if (value == null) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
url.searchParams.set(key, String(value));
|
|
532
|
+
}
|
|
533
|
+
url.searchParams.sort();
|
|
534
|
+
return url;
|
|
535
|
+
}
|
|
536
|
+
function resolveTarget(baseURL, endpoint, params) {
|
|
537
|
+
const base = typeof baseURL === "string" && baseURL ? baseURL : void 0;
|
|
538
|
+
try {
|
|
539
|
+
if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
|
|
540
|
+
return appendQueryParams(new URL(endpoint), params).toString();
|
|
541
|
+
}
|
|
542
|
+
if (base) {
|
|
543
|
+
return appendQueryParams(new URL(endpoint, base), params).toString();
|
|
544
|
+
}
|
|
545
|
+
} catch {
|
|
546
|
+
}
|
|
547
|
+
if (!params || Object.keys(params).length === 0) {
|
|
548
|
+
return endpoint;
|
|
549
|
+
}
|
|
550
|
+
const url = new URL(endpoint, "https://docyrus.local");
|
|
551
|
+
return appendQueryParams(url, params).pathname + url.search;
|
|
552
|
+
}
|
|
553
|
+
function matchesDocyrusOrigin(url, docyrusOrigins) {
|
|
554
|
+
if (!docyrusOrigins || docyrusOrigins.length === 0) {
|
|
555
|
+
return url.hostname.includes("docyrus");
|
|
556
|
+
}
|
|
557
|
+
return docyrusOrigins.some((origin) => {
|
|
558
|
+
if (!origin) {
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
if (origin.includes("://")) {
|
|
562
|
+
return url.origin === origin;
|
|
563
|
+
}
|
|
564
|
+
return url.hostname === origin || url.hostname.endsWith(`.${origin}`);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
async function readResponsePreview(response) {
|
|
568
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
569
|
+
if (contentType.includes("application/json")) {
|
|
570
|
+
return sanitizeForDevtools(await response.json());
|
|
571
|
+
}
|
|
572
|
+
if (contentType.startsWith("text/")) {
|
|
573
|
+
return sanitizeForDevtools(await response.text());
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
type: "Response",
|
|
577
|
+
status: response.status,
|
|
578
|
+
contentType: contentType || "unknown"
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function retainStoreRef(refs, store, optionsMap, options) {
|
|
582
|
+
refs.set(store, (refs.get(store) ?? 0) + 1);
|
|
583
|
+
if (optionsMap) {
|
|
584
|
+
optionsMap.set(store, options);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function releaseStoreRef(refs, store, optionsMap) {
|
|
588
|
+
const count = refs.get(store);
|
|
589
|
+
if (!count) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (count === 1) {
|
|
593
|
+
refs.delete(store);
|
|
594
|
+
optionsMap?.delete(store);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
refs.set(store, count - 1);
|
|
598
|
+
}
|
|
599
|
+
function beginForStores(stores, input) {
|
|
600
|
+
const entries = [];
|
|
601
|
+
for (const store of stores) {
|
|
602
|
+
entries.push({
|
|
603
|
+
store,
|
|
604
|
+
entryId: store.beginEntry(input)
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
return entries;
|
|
608
|
+
}
|
|
609
|
+
function finalizeForStores(entries, input) {
|
|
610
|
+
for (const entry of entries) {
|
|
611
|
+
entry.store.finalizeEntry(entry.entryId, input);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function failForStores(entries, error, status) {
|
|
615
|
+
for (const entry of entries) {
|
|
616
|
+
entry.store.failEntry(entry.entryId, { error, status });
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function instrumentApiClient(client, options) {
|
|
620
|
+
const currentRequest = client.request;
|
|
621
|
+
if (typeof currentRequest !== "function") {
|
|
622
|
+
return () => void 0;
|
|
623
|
+
}
|
|
624
|
+
let patch = apiClientPatches.get(client);
|
|
625
|
+
if (!patch) {
|
|
626
|
+
const apiPatch = {
|
|
627
|
+
refs: /* @__PURE__ */ new Map(),
|
|
628
|
+
original: currentRequest.bind(client)
|
|
629
|
+
};
|
|
630
|
+
patch = apiPatch;
|
|
631
|
+
apiClientPatches.set(client, apiPatch);
|
|
632
|
+
client.request = async (method, endpoint, data, config) => {
|
|
633
|
+
const routeKey = getRouteKey();
|
|
634
|
+
const target = resolveTarget(client.baseURL, endpoint, config?.params);
|
|
635
|
+
const fingerprint = createFingerprint({
|
|
636
|
+
method,
|
|
637
|
+
target,
|
|
638
|
+
body: data
|
|
639
|
+
});
|
|
640
|
+
const activeStores = Array.from(apiPatch.refs.keys());
|
|
641
|
+
const entries = beginForStores(activeStores, {
|
|
642
|
+
kind: "api",
|
|
643
|
+
source: "api-client",
|
|
644
|
+
operation: `${method.toUpperCase()} ${endpoint}`,
|
|
645
|
+
method: method.toUpperCase(),
|
|
646
|
+
target,
|
|
647
|
+
fingerprint,
|
|
648
|
+
routeKey,
|
|
649
|
+
params: config?.params,
|
|
650
|
+
request: data
|
|
651
|
+
});
|
|
652
|
+
try {
|
|
653
|
+
const response = await apiPatch.original(method, endpoint, data, config);
|
|
654
|
+
finalizeForStores(entries, {
|
|
655
|
+
response: response?.data,
|
|
656
|
+
status: response?.status
|
|
657
|
+
});
|
|
658
|
+
return response;
|
|
659
|
+
} catch (error) {
|
|
660
|
+
failForStores(entries, error, error?.status);
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
retainStoreRef(patch.refs, options.store);
|
|
666
|
+
const html2Pdf = client.html2pdf;
|
|
667
|
+
let htmlPatch = html2PdfPatches.get(client);
|
|
668
|
+
if (typeof html2Pdf === "function" && !htmlPatch) {
|
|
669
|
+
const currentHtmlPatch = {
|
|
670
|
+
refs: /* @__PURE__ */ new Map(),
|
|
671
|
+
original: html2Pdf.bind(client)
|
|
672
|
+
};
|
|
673
|
+
htmlPatch = currentHtmlPatch;
|
|
674
|
+
html2PdfPatches.set(client, currentHtmlPatch);
|
|
675
|
+
client.html2pdf = async (...args) => {
|
|
676
|
+
const routeKey = getRouteKey();
|
|
677
|
+
const target = "https://html2pdf.cf.docyrus.app/";
|
|
678
|
+
const fingerprint = createFingerprint({
|
|
679
|
+
method: "POST",
|
|
680
|
+
target,
|
|
681
|
+
body: args[0]
|
|
682
|
+
});
|
|
683
|
+
const activeStores = Array.from(currentHtmlPatch.refs.keys());
|
|
684
|
+
const entries = beginForStores(activeStores, {
|
|
685
|
+
kind: "api",
|
|
686
|
+
source: "api-client",
|
|
687
|
+
operation: "POST html2pdf",
|
|
688
|
+
method: "POST",
|
|
689
|
+
target,
|
|
690
|
+
fingerprint,
|
|
691
|
+
routeKey,
|
|
692
|
+
request: args[0]
|
|
693
|
+
});
|
|
694
|
+
try {
|
|
695
|
+
const result = await currentHtmlPatch.original(...args);
|
|
696
|
+
finalizeForStores(entries, {
|
|
697
|
+
response: result
|
|
698
|
+
});
|
|
699
|
+
return result;
|
|
700
|
+
} catch (error) {
|
|
701
|
+
failForStores(entries, error, error?.status);
|
|
702
|
+
throw error;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
if (htmlPatch) {
|
|
707
|
+
retainStoreRef(htmlPatch.refs, options.store);
|
|
708
|
+
}
|
|
709
|
+
return () => {
|
|
710
|
+
const latestPatch = apiClientPatches.get(client);
|
|
711
|
+
if (latestPatch) {
|
|
712
|
+
releaseStoreRef(latestPatch.refs, options.store);
|
|
713
|
+
if (latestPatch.refs.size === 0) {
|
|
714
|
+
client.request = latestPatch.original;
|
|
715
|
+
apiClientPatches.delete(client);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const latestHtmlPatch = html2PdfPatches.get(client);
|
|
719
|
+
if (!latestHtmlPatch) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
releaseStoreRef(latestHtmlPatch.refs, options.store);
|
|
723
|
+
if (latestHtmlPatch.refs.size === 0) {
|
|
724
|
+
client.html2pdf = latestHtmlPatch.original;
|
|
725
|
+
html2PdfPatches.delete(client);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function instrumentAddinClient(client, options) {
|
|
730
|
+
const currentCall = client.call;
|
|
731
|
+
if (typeof currentCall !== "function") {
|
|
732
|
+
return () => void 0;
|
|
733
|
+
}
|
|
734
|
+
let patch = addinClientPatches.get(client);
|
|
735
|
+
if (!patch) {
|
|
736
|
+
const addinPatch = {
|
|
737
|
+
refs: /* @__PURE__ */ new Map(),
|
|
738
|
+
original: currentCall.bind(client)
|
|
739
|
+
};
|
|
740
|
+
patch = addinPatch;
|
|
741
|
+
addinClientPatches.set(client, addinPatch);
|
|
742
|
+
client.call = async (method, params) => {
|
|
743
|
+
const routeKey = getRouteKey();
|
|
744
|
+
const fingerprint = createFingerprint({
|
|
745
|
+
kind: "addin",
|
|
746
|
+
method,
|
|
747
|
+
params
|
|
748
|
+
});
|
|
749
|
+
const activeStores = Array.from(addinPatch.refs.keys());
|
|
750
|
+
const entries = beginForStores(activeStores, {
|
|
751
|
+
kind: "addin",
|
|
752
|
+
source: "addin-client",
|
|
753
|
+
operation: method,
|
|
754
|
+
method: "RPC",
|
|
755
|
+
target: method,
|
|
756
|
+
fingerprint,
|
|
757
|
+
routeKey,
|
|
758
|
+
request: params
|
|
759
|
+
});
|
|
760
|
+
try {
|
|
761
|
+
const result = await addinPatch.original(method, params);
|
|
762
|
+
finalizeForStores(entries, {
|
|
763
|
+
response: result
|
|
764
|
+
});
|
|
765
|
+
return result;
|
|
766
|
+
} catch (error) {
|
|
767
|
+
failForStores(entries, error);
|
|
768
|
+
throw error;
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
retainStoreRef(patch.refs, options.store);
|
|
773
|
+
return () => {
|
|
774
|
+
const latestPatch = addinClientPatches.get(client);
|
|
775
|
+
if (!latestPatch) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
releaseStoreRef(latestPatch.refs, options.store);
|
|
779
|
+
if (latestPatch.refs.size === 0) {
|
|
780
|
+
client.call = latestPatch.original;
|
|
781
|
+
addinClientPatches.delete(client);
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function instrumentClient(client, options) {
|
|
786
|
+
if (client instanceof DocyrusClient) {
|
|
787
|
+
return instrumentAddinClient(client, options);
|
|
788
|
+
}
|
|
789
|
+
if (client instanceof RestApiClient || typeof client.request === "function") {
|
|
790
|
+
return instrumentApiClient(client, options);
|
|
791
|
+
}
|
|
792
|
+
return () => void 0;
|
|
793
|
+
}
|
|
794
|
+
function instrumentFetch(options) {
|
|
795
|
+
if (typeof globalThis.fetch !== "function") {
|
|
796
|
+
return () => void 0;
|
|
797
|
+
}
|
|
798
|
+
if (!fetchPatch) {
|
|
799
|
+
const patchState = {
|
|
800
|
+
refs: /* @__PURE__ */ new Map(),
|
|
801
|
+
options: /* @__PURE__ */ new Map(),
|
|
802
|
+
original: globalThis.fetch.bind(globalThis)
|
|
803
|
+
};
|
|
804
|
+
fetchPatch = patchState;
|
|
805
|
+
globalThis.fetch = async (input, init) => {
|
|
806
|
+
const currentPatch = patchState;
|
|
807
|
+
const request = input instanceof Request ? input : void 0;
|
|
808
|
+
const rawUrl = request?.url ?? (input instanceof URL ? input.toString() : String(input));
|
|
809
|
+
let url;
|
|
810
|
+
try {
|
|
811
|
+
url = new URL(rawUrl, typeof window !== "undefined" ? window.location.origin : "https://docyrus.local");
|
|
812
|
+
} catch {
|
|
813
|
+
return currentPatch.original(input, init);
|
|
814
|
+
}
|
|
815
|
+
const allowedOrigins = Array.from(currentPatch.options.values()).flatMap((value) => value ?? []);
|
|
816
|
+
if (!matchesDocyrusOrigin(url, allowedOrigins)) {
|
|
817
|
+
return currentPatch.original(input, init);
|
|
818
|
+
}
|
|
819
|
+
const method = init?.method ?? request?.method ?? "GET";
|
|
820
|
+
const routeKey = getRouteKey();
|
|
821
|
+
const requestHeaders = init?.headers ?? request?.headers;
|
|
822
|
+
const requestBody = init?.body ?? (request ? { type: "Request", bodyUsed: request.bodyUsed } : void 0);
|
|
823
|
+
const fingerprint = createFingerprint({
|
|
824
|
+
method,
|
|
825
|
+
target: url.toString(),
|
|
826
|
+
body: requestBody
|
|
827
|
+
});
|
|
828
|
+
const startedAt = Date.now();
|
|
829
|
+
const activeStores = Array.from(currentPatch.refs.keys()).filter((store) => !store.shouldSkipFetchCapture({
|
|
830
|
+
fingerprint,
|
|
831
|
+
routeKey,
|
|
832
|
+
startedAt
|
|
833
|
+
}));
|
|
834
|
+
if (activeStores.length === 0) {
|
|
835
|
+
return currentPatch.original(input, init);
|
|
836
|
+
}
|
|
837
|
+
const entries = beginForStores(activeStores, {
|
|
838
|
+
kind: "fetch",
|
|
839
|
+
source: "fetch",
|
|
840
|
+
operation: `${method.toUpperCase()} ${url.pathname}`,
|
|
841
|
+
method: method.toUpperCase(),
|
|
842
|
+
target: url.toString(),
|
|
843
|
+
fingerprint,
|
|
844
|
+
routeKey,
|
|
845
|
+
request: {
|
|
846
|
+
headers: sanitizeForDevtools(requestHeaders),
|
|
847
|
+
body: sanitizeForDevtools(requestBody)
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
try {
|
|
851
|
+
const response = await currentPatch.original(input, init);
|
|
852
|
+
let responsePreview;
|
|
853
|
+
try {
|
|
854
|
+
responsePreview = await readResponsePreview(response.clone());
|
|
855
|
+
} catch {
|
|
856
|
+
responsePreview = {
|
|
857
|
+
type: "Response",
|
|
858
|
+
status: response.status
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
finalizeForStores(entries, {
|
|
862
|
+
status: response.status,
|
|
863
|
+
response: responsePreview
|
|
864
|
+
});
|
|
865
|
+
return response;
|
|
866
|
+
} catch (error) {
|
|
867
|
+
failForStores(entries, error, error?.status);
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
retainStoreRef(fetchPatch.refs, options.store, fetchPatch.options, options.docyrusOrigins);
|
|
873
|
+
return () => {
|
|
874
|
+
if (!fetchPatch) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
releaseStoreRef(fetchPatch.refs, options.store, fetchPatch.options);
|
|
878
|
+
if (fetchPatch.refs.size === 0) {
|
|
879
|
+
globalThis.fetch = fetchPatch.original;
|
|
880
|
+
fetchPatch = void 0;
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// src/core/query-client.ts
|
|
886
|
+
function getRouteKey2() {
|
|
887
|
+
if (typeof window === "undefined") {
|
|
888
|
+
return "/";
|
|
889
|
+
}
|
|
890
|
+
return `${window.location.pathname}${window.location.search}`;
|
|
891
|
+
}
|
|
892
|
+
function getQueryFingerprint(query) {
|
|
893
|
+
if (query.queryHash) {
|
|
894
|
+
return query.queryHash;
|
|
895
|
+
}
|
|
896
|
+
return JSON.stringify(query.queryKey ?? "unknown-query");
|
|
897
|
+
}
|
|
898
|
+
function getMutationFingerprint(mutation) {
|
|
899
|
+
if (mutation.options?.mutationKey) {
|
|
900
|
+
return JSON.stringify(mutation.options.mutationKey);
|
|
901
|
+
}
|
|
902
|
+
return String(mutation.mutationId ?? "unknown-mutation");
|
|
903
|
+
}
|
|
904
|
+
function attachQueryClient(options) {
|
|
905
|
+
const queryClient = options.queryClient;
|
|
906
|
+
const activeQueries = /* @__PURE__ */ new Map();
|
|
907
|
+
const activeMutations = /* @__PURE__ */ new Map();
|
|
908
|
+
const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {
|
|
909
|
+
const query = event?.query;
|
|
910
|
+
if (!query) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
const fingerprint = getQueryFingerprint(query);
|
|
914
|
+
const fetchStatus = query.state?.fetchStatus;
|
|
915
|
+
const routeKey = getRouteKey2();
|
|
916
|
+
const tracker = activeQueries.get(fingerprint);
|
|
917
|
+
const isFetchAction = event?.action?.type === "fetch";
|
|
918
|
+
if (fetchStatus === "fetching") {
|
|
919
|
+
if (!tracker) {
|
|
920
|
+
activeQueries.set(fingerprint, {
|
|
921
|
+
routeKey,
|
|
922
|
+
startedAt: Date.now(),
|
|
923
|
+
duplicateCount: 0,
|
|
924
|
+
duplicateReported: false
|
|
925
|
+
});
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (isFetchAction) {
|
|
929
|
+
tracker.duplicateCount += 1;
|
|
930
|
+
if (!tracker.duplicateReported) {
|
|
931
|
+
tracker.duplicateReported = true;
|
|
932
|
+
options.store.recordIssue({
|
|
933
|
+
code: "duplicate-query",
|
|
934
|
+
title: "Duplicate query",
|
|
935
|
+
message: `Overlapping query detected for ${fingerprint}`,
|
|
936
|
+
routeKey,
|
|
937
|
+
fingerprint,
|
|
938
|
+
context: {
|
|
939
|
+
queryKey: query.queryKey
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
if (!tracker) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
activeQueries.delete(fingerprint);
|
|
950
|
+
const durationMs = Date.now() - tracker.startedAt;
|
|
951
|
+
if (durationMs > options.store.getSnapshot().slowThresholdMs) {
|
|
952
|
+
options.store.recordIssue({
|
|
953
|
+
code: "slow-query",
|
|
954
|
+
title: "Slow query",
|
|
955
|
+
message: `Query ${fingerprint} took ${durationMs} ms`,
|
|
956
|
+
routeKey: tracker.routeKey,
|
|
957
|
+
fingerprint,
|
|
958
|
+
latestDurationMs: durationMs,
|
|
959
|
+
context: {
|
|
960
|
+
queryKey: query.queryKey
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
const unsubscribeMutations = queryClient.getMutationCache().subscribe((event) => {
|
|
966
|
+
const mutation = event?.mutation;
|
|
967
|
+
if (!mutation) {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
const fingerprint = getMutationFingerprint(mutation);
|
|
971
|
+
const status = mutation.state?.status;
|
|
972
|
+
const tracker = activeMutations.get(fingerprint);
|
|
973
|
+
if (status === "pending") {
|
|
974
|
+
if (!tracker) {
|
|
975
|
+
activeMutations.set(fingerprint, {
|
|
976
|
+
routeKey: getRouteKey2(),
|
|
977
|
+
startedAt: Date.now()
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
if (!tracker) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
activeMutations.delete(fingerprint);
|
|
986
|
+
const durationMs = Date.now() - tracker.startedAt;
|
|
987
|
+
if (durationMs > options.store.getSnapshot().slowThresholdMs) {
|
|
988
|
+
options.store.recordIssue({
|
|
989
|
+
code: "slow-mutation",
|
|
990
|
+
title: "Slow mutation",
|
|
991
|
+
message: `Mutation ${fingerprint} took ${durationMs} ms`,
|
|
992
|
+
routeKey: tracker.routeKey,
|
|
993
|
+
fingerprint,
|
|
994
|
+
latestDurationMs: durationMs,
|
|
995
|
+
context: {
|
|
996
|
+
mutationKey: mutation.options?.mutationKey
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
return () => {
|
|
1002
|
+
unsubscribeQueries();
|
|
1003
|
+
unsubscribeMutations();
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/core/host-bridge.ts
|
|
1008
|
+
var DEVTOOLS_MESSAGE_TYPE = "DOCY_DEVTOOLS";
|
|
1009
|
+
var hostBridgeState;
|
|
1010
|
+
function getRouteKey3() {
|
|
1011
|
+
if (typeof window === "undefined") {
|
|
1012
|
+
return "/";
|
|
1013
|
+
}
|
|
1014
|
+
return `${window.location.pathname}${window.location.search}`;
|
|
1015
|
+
}
|
|
1016
|
+
function getActiveStore() {
|
|
1017
|
+
if (!hostBridgeState || hostBridgeState.refs.size === 0) {
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
return Array.from(hostBridgeState.refs.keys()).at(-1) ?? null;
|
|
1021
|
+
}
|
|
1022
|
+
function getStateFromStore(store) {
|
|
1023
|
+
const snapshot = store.getSnapshot();
|
|
1024
|
+
return {
|
|
1025
|
+
consoleEntries: snapshot.consoleEntries,
|
|
1026
|
+
entries: snapshot.entries,
|
|
1027
|
+
errors: snapshot.entries.filter((entry) => entry.outcome === "error"),
|
|
1028
|
+
issues: snapshot.issues,
|
|
1029
|
+
route: getRouteKey3(),
|
|
1030
|
+
timestamp: Date.now(),
|
|
1031
|
+
url: typeof window === "undefined" ? "" : window.location.href
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
function isAllowedOrigin(expectedOrigin, actualOrigin) {
|
|
1035
|
+
if (!expectedOrigin || expectedOrigin === "*") {
|
|
1036
|
+
return true;
|
|
1037
|
+
}
|
|
1038
|
+
return expectedOrigin === actualOrigin;
|
|
1039
|
+
}
|
|
1040
|
+
function postMessageToParent(data, hostOrigin = "*") {
|
|
1041
|
+
if (typeof window === "undefined") {
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
if (window.parent && window.parent !== window) {
|
|
1045
|
+
window.parent.postMessage(data, hostOrigin);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function postResponseToSource(event, data) {
|
|
1049
|
+
if (!event.source || typeof event.source.postMessage !== "function") {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
event.source.postMessage(data, event.origin);
|
|
1053
|
+
}
|
|
1054
|
+
function createWindowApi() {
|
|
1055
|
+
return {
|
|
1056
|
+
getConsoleEntries(level) {
|
|
1057
|
+
const store = getActiveStore();
|
|
1058
|
+
if (!store) {
|
|
1059
|
+
return [];
|
|
1060
|
+
}
|
|
1061
|
+
const { consoleEntries } = store.getSnapshot();
|
|
1062
|
+
return level && level !== "all" ? consoleEntries.filter((entry) => entry.level === level) : consoleEntries;
|
|
1063
|
+
},
|
|
1064
|
+
getErrors() {
|
|
1065
|
+
const store = getActiveStore();
|
|
1066
|
+
if (!store) {
|
|
1067
|
+
return [];
|
|
1068
|
+
}
|
|
1069
|
+
return store.getSnapshot().entries.filter((entry) => entry.outcome === "error");
|
|
1070
|
+
},
|
|
1071
|
+
getIssues() {
|
|
1072
|
+
const store = getActiveStore();
|
|
1073
|
+
if (!store) {
|
|
1074
|
+
return [];
|
|
1075
|
+
}
|
|
1076
|
+
return store.getSnapshot().issues;
|
|
1077
|
+
},
|
|
1078
|
+
getState() {
|
|
1079
|
+
const store = getActiveStore();
|
|
1080
|
+
return store ? getStateFromStore(store) : null;
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
function postDevtoolsMessageToHost(action, payload, hostOrigin = "*") {
|
|
1085
|
+
postMessageToParent({
|
|
1086
|
+
type: DEVTOOLS_MESSAGE_TYPE,
|
|
1087
|
+
action,
|
|
1088
|
+
payload
|
|
1089
|
+
}, hostOrigin);
|
|
1090
|
+
}
|
|
1091
|
+
function attachHostBridge(options) {
|
|
1092
|
+
if (typeof window === "undefined") {
|
|
1093
|
+
return () => void 0;
|
|
1094
|
+
}
|
|
1095
|
+
if (!hostBridgeState) {
|
|
1096
|
+
const bridgeState = {
|
|
1097
|
+
refs: /* @__PURE__ */ new Map(),
|
|
1098
|
+
hostOrigins: /* @__PURE__ */ new Map(),
|
|
1099
|
+
onMessage(event) {
|
|
1100
|
+
const { data } = event;
|
|
1101
|
+
if (!data || typeof data !== "object" || data.type !== DEVTOOLS_MESSAGE_TYPE) {
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
const store = getActiveStore();
|
|
1105
|
+
if (!store) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const expectedOrigin = hostBridgeState?.hostOrigins.get(store);
|
|
1109
|
+
if (!isAllowedOrigin(expectedOrigin, event.origin)) {
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
const { action } = data;
|
|
1113
|
+
const { requestId } = data;
|
|
1114
|
+
let responsePayload;
|
|
1115
|
+
let responseAction = null;
|
|
1116
|
+
switch (action) {
|
|
1117
|
+
case "getState":
|
|
1118
|
+
responseAction = "state";
|
|
1119
|
+
responsePayload = getStateFromStore(store);
|
|
1120
|
+
break;
|
|
1121
|
+
case "getErrors":
|
|
1122
|
+
responseAction = "errors";
|
|
1123
|
+
responsePayload = store.getSnapshot().entries.filter((entry) => entry.outcome === "error");
|
|
1124
|
+
break;
|
|
1125
|
+
case "getIssues":
|
|
1126
|
+
responseAction = "issues";
|
|
1127
|
+
responsePayload = store.getSnapshot().issues;
|
|
1128
|
+
break;
|
|
1129
|
+
case "getConsoleEntries": {
|
|
1130
|
+
const requestedLevel = data.payload?.level;
|
|
1131
|
+
const { consoleEntries } = store.getSnapshot();
|
|
1132
|
+
responseAction = "consoleEntries";
|
|
1133
|
+
responsePayload = requestedLevel && requestedLevel !== "all" ? consoleEntries.filter((entry) => entry.level === requestedLevel) : consoleEntries;
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
default:
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
postResponseToSource(event, {
|
|
1140
|
+
type: DEVTOOLS_MESSAGE_TYPE,
|
|
1141
|
+
action: responseAction,
|
|
1142
|
+
requestId,
|
|
1143
|
+
payload: responsePayload
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
hostBridgeState = bridgeState;
|
|
1148
|
+
window.__DOCYRUS_DEVTOOLS__ = createWindowApi();
|
|
1149
|
+
window.addEventListener("message", bridgeState.onMessage);
|
|
1150
|
+
}
|
|
1151
|
+
const currentBridge = hostBridgeState;
|
|
1152
|
+
currentBridge.refs.set(
|
|
1153
|
+
options.store,
|
|
1154
|
+
(currentBridge.refs.get(options.store) ?? 0) + 1
|
|
1155
|
+
);
|
|
1156
|
+
currentBridge.hostOrigins.set(options.store, options.hostOrigin);
|
|
1157
|
+
return () => {
|
|
1158
|
+
if (!hostBridgeState) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const count = hostBridgeState.refs.get(options.store);
|
|
1162
|
+
if (!count) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
if (count === 1) {
|
|
1166
|
+
hostBridgeState.refs.delete(options.store);
|
|
1167
|
+
hostBridgeState.hostOrigins.delete(options.store);
|
|
1168
|
+
} else {
|
|
1169
|
+
hostBridgeState.refs.set(options.store, count - 1);
|
|
1170
|
+
}
|
|
1171
|
+
if (hostBridgeState.refs.size > 0) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
window.removeEventListener("message", hostBridgeState.onMessage);
|
|
1175
|
+
delete window.__DOCYRUS_DEVTOOLS__;
|
|
1176
|
+
hostBridgeState = void 0;
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/core/console.ts
|
|
1181
|
+
var CONSOLE_LEVELS = [
|
|
1182
|
+
"log",
|
|
1183
|
+
"info",
|
|
1184
|
+
"warn",
|
|
1185
|
+
"error",
|
|
1186
|
+
"debug"
|
|
1187
|
+
];
|
|
1188
|
+
var consolePatch;
|
|
1189
|
+
function formatConsoleValue(value) {
|
|
1190
|
+
if (typeof value === "string") {
|
|
1191
|
+
return value;
|
|
1192
|
+
}
|
|
1193
|
+
if (value instanceof Error) {
|
|
1194
|
+
return value.message;
|
|
1195
|
+
}
|
|
1196
|
+
const sanitized = sanitizeForDevtools(value);
|
|
1197
|
+
if (typeof sanitized === "string") {
|
|
1198
|
+
return sanitized;
|
|
1199
|
+
}
|
|
1200
|
+
return stableStringify(sanitized);
|
|
1201
|
+
}
|
|
1202
|
+
function createConsoleMessage(args) {
|
|
1203
|
+
return args.map(formatConsoleValue).join(" ").trim();
|
|
1204
|
+
}
|
|
1205
|
+
function recordForStores(stores, level, args, source = "console", stack, message) {
|
|
1206
|
+
for (const store of stores) {
|
|
1207
|
+
store.recordConsoleEntry({
|
|
1208
|
+
level,
|
|
1209
|
+
source,
|
|
1210
|
+
args,
|
|
1211
|
+
message: message ?? createConsoleMessage(args),
|
|
1212
|
+
stack
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
function instrumentConsole(options) {
|
|
1217
|
+
if (!globalThis.console) {
|
|
1218
|
+
return () => void 0;
|
|
1219
|
+
}
|
|
1220
|
+
if (!consolePatch) {
|
|
1221
|
+
const original = Object.fromEntries(
|
|
1222
|
+
CONSOLE_LEVELS.map((level) => [level, globalThis.console[level].bind(globalThis.console)])
|
|
1223
|
+
);
|
|
1224
|
+
const patch = {
|
|
1225
|
+
refs: /* @__PURE__ */ new Map(),
|
|
1226
|
+
original,
|
|
1227
|
+
onError(event) {
|
|
1228
|
+
const stores = Array.from(patch.refs.keys());
|
|
1229
|
+
recordForStores(
|
|
1230
|
+
stores,
|
|
1231
|
+
"error",
|
|
1232
|
+
[event.error ?? event.message],
|
|
1233
|
+
"window-error",
|
|
1234
|
+
event.error instanceof Error ? normalizeError(event.error).stack : void 0,
|
|
1235
|
+
event.message
|
|
1236
|
+
);
|
|
1237
|
+
},
|
|
1238
|
+
onUnhandledRejection(event) {
|
|
1239
|
+
const reason = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
1240
|
+
const stores = Array.from(patch.refs.keys());
|
|
1241
|
+
recordForStores(
|
|
1242
|
+
stores,
|
|
1243
|
+
"error",
|
|
1244
|
+
[reason],
|
|
1245
|
+
"unhandledrejection",
|
|
1246
|
+
normalizeError(reason).stack,
|
|
1247
|
+
reason.message
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
consolePatch = patch;
|
|
1252
|
+
for (const level of CONSOLE_LEVELS) {
|
|
1253
|
+
globalThis.console[level] = (...args) => {
|
|
1254
|
+
recordForStores(Array.from(patch.refs.keys()), level, args);
|
|
1255
|
+
return patch.original[level](...args);
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
if (typeof window !== "undefined") {
|
|
1259
|
+
window.addEventListener("error", patch.onError);
|
|
1260
|
+
window.addEventListener("unhandledrejection", patch.onUnhandledRejection);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
const currentPatch = consolePatch;
|
|
1264
|
+
currentPatch.refs.set(
|
|
1265
|
+
options.store,
|
|
1266
|
+
(currentPatch.refs.get(options.store) ?? 0) + 1
|
|
1267
|
+
);
|
|
1268
|
+
return () => {
|
|
1269
|
+
if (!consolePatch) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
const count = consolePatch.refs.get(options.store);
|
|
1273
|
+
if (!count) {
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (count === 1) {
|
|
1277
|
+
consolePatch.refs.delete(options.store);
|
|
1278
|
+
} else {
|
|
1279
|
+
consolePatch.refs.set(options.store, count - 1);
|
|
1280
|
+
}
|
|
1281
|
+
if (consolePatch.refs.size > 0) {
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
for (const level of CONSOLE_LEVELS) {
|
|
1285
|
+
globalThis.console[level] = consolePatch.original[level];
|
|
1286
|
+
}
|
|
1287
|
+
if (typeof window !== "undefined") {
|
|
1288
|
+
window.removeEventListener("error", consolePatch.onError);
|
|
1289
|
+
window.removeEventListener("unhandledrejection", consolePatch.onUnhandledRejection);
|
|
1290
|
+
}
|
|
1291
|
+
consolePatch = void 0;
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// src/core/iframe-messages.ts
|
|
1296
|
+
var DEFAULT_IGNORE_TYPES = ["DOCY_DEVTOOLS"];
|
|
1297
|
+
var messagesPatch;
|
|
1298
|
+
function extractType(payload) {
|
|
1299
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
1300
|
+
return void 0;
|
|
1301
|
+
}
|
|
1302
|
+
const value = payload.type;
|
|
1303
|
+
return typeof value === "string" ? value : void 0;
|
|
1304
|
+
}
|
|
1305
|
+
function recordForStores2(direction, payload, meta) {
|
|
1306
|
+
if (!messagesPatch) return;
|
|
1307
|
+
const type = extractType(payload);
|
|
1308
|
+
for (const [store, { ignoreTypes }] of messagesPatch.refs) {
|
|
1309
|
+
if (type && ignoreTypes.has(type)) continue;
|
|
1310
|
+
store.recordMessageEntry({
|
|
1311
|
+
direction,
|
|
1312
|
+
payload,
|
|
1313
|
+
transport: meta?.transport,
|
|
1314
|
+
origin: meta?.origin,
|
|
1315
|
+
targetOrigin: meta?.targetOrigin,
|
|
1316
|
+
type
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
function instrumentIframeMessages(options) {
|
|
1321
|
+
if (typeof window === "undefined") {
|
|
1322
|
+
return () => void 0;
|
|
1323
|
+
}
|
|
1324
|
+
if (!messagesPatch) {
|
|
1325
|
+
const patch = {
|
|
1326
|
+
refs: /* @__PURE__ */ new Map(),
|
|
1327
|
+
onMessage(event) {
|
|
1328
|
+
const transport = event.source && event.source !== window ? "iframe" : "window";
|
|
1329
|
+
recordForStores2("in", event.data, { transport, origin: event.origin });
|
|
1330
|
+
},
|
|
1331
|
+
previousTap: window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__
|
|
1332
|
+
};
|
|
1333
|
+
messagesPatch = patch;
|
|
1334
|
+
window.addEventListener("message", patch.onMessage);
|
|
1335
|
+
window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__ = (direction, payload, meta) => {
|
|
1336
|
+
recordForStores2(direction, payload, meta);
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
const ignoreTypes = new Set(options.ignoreTypes ?? DEFAULT_IGNORE_TYPES);
|
|
1340
|
+
messagesPatch.refs.set(options.store, { ignoreTypes });
|
|
1341
|
+
return () => {
|
|
1342
|
+
if (!messagesPatch) return;
|
|
1343
|
+
messagesPatch.refs.delete(options.store);
|
|
1344
|
+
if (messagesPatch.refs.size > 0) return;
|
|
1345
|
+
window.removeEventListener("message", messagesPatch.onMessage);
|
|
1346
|
+
if (messagesPatch.previousTap) {
|
|
1347
|
+
window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__ = messagesPatch.previousTap;
|
|
1348
|
+
} else {
|
|
1349
|
+
delete window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__;
|
|
1350
|
+
}
|
|
1351
|
+
messagesPatch = void 0;
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// src/core/dom-selector.ts
|
|
1356
|
+
var ACCEPTED_ATTR_NAMES = /* @__PURE__ */ new Set([
|
|
1357
|
+
"role",
|
|
1358
|
+
"name",
|
|
1359
|
+
"aria-label",
|
|
1360
|
+
"rel",
|
|
1361
|
+
"href"
|
|
1362
|
+
]);
|
|
1363
|
+
function wordLike(value) {
|
|
1364
|
+
if (!/^[a-z-]{3,}$/i.test(value)) {
|
|
1365
|
+
return false;
|
|
1366
|
+
}
|
|
1367
|
+
const words = value.split(/-|[A-Z]/);
|
|
1368
|
+
for (const word of words) {
|
|
1369
|
+
if (word.length <= 2) return false;
|
|
1370
|
+
if (/[^aeiou]{4,}/i.test(word)) return false;
|
|
1371
|
+
}
|
|
1372
|
+
return true;
|
|
1373
|
+
}
|
|
1374
|
+
function isAcceptedAttr(name, value) {
|
|
1375
|
+
let nameOk = ACCEPTED_ATTR_NAMES.has(name);
|
|
1376
|
+
nameOk ||= name.startsWith("data-") && wordLike(name);
|
|
1377
|
+
let valueOk = wordLike(value) && value.length < 100;
|
|
1378
|
+
valueOk ||= value.startsWith("#") && wordLike(value.slice(1));
|
|
1379
|
+
return nameOk && valueOk;
|
|
1380
|
+
}
|
|
1381
|
+
function getCssEscape() {
|
|
1382
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
1383
|
+
return CSS.escape.bind(CSS);
|
|
1384
|
+
}
|
|
1385
|
+
return (value) => String(value).replace(/[^a-zA-Z0-9_-]/g, "\\$&");
|
|
1386
|
+
}
|
|
1387
|
+
function indexOfElement(input, tagName) {
|
|
1388
|
+
const parent = input.parentNode;
|
|
1389
|
+
if (!parent) return void 0;
|
|
1390
|
+
let child = parent.firstChild;
|
|
1391
|
+
if (!child) return void 0;
|
|
1392
|
+
let index = 0;
|
|
1393
|
+
while (child) {
|
|
1394
|
+
if (child.nodeType === Node.ELEMENT_NODE && (tagName === void 0 || child.tagName.toLowerCase() === tagName)) {
|
|
1395
|
+
index++;
|
|
1396
|
+
}
|
|
1397
|
+
if (child === input) break;
|
|
1398
|
+
child = child.nextSibling;
|
|
1399
|
+
}
|
|
1400
|
+
return index;
|
|
1401
|
+
}
|
|
1402
|
+
function nthChild(tag, i) {
|
|
1403
|
+
return tag === "html" ? "html" : `${tag}:nth-child(${i})`;
|
|
1404
|
+
}
|
|
1405
|
+
function nthOfType(tag, i) {
|
|
1406
|
+
return tag === "html" ? "html" : `${tag}:nth-of-type(${i})`;
|
|
1407
|
+
}
|
|
1408
|
+
function tie(element) {
|
|
1409
|
+
const level = [];
|
|
1410
|
+
const escape = getCssEscape();
|
|
1411
|
+
const id = element.getAttribute("id");
|
|
1412
|
+
if (id && wordLike(id)) {
|
|
1413
|
+
level.push({ name: `#${escape(id)}`, penalty: 0 });
|
|
1414
|
+
}
|
|
1415
|
+
for (let i = 0; i < element.classList.length; i++) {
|
|
1416
|
+
const name = element.classList[i];
|
|
1417
|
+
if (name && wordLike(name)) {
|
|
1418
|
+
level.push({ name: `.${escape(name)}`, penalty: 1 });
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
1422
|
+
const attr = element.attributes[i];
|
|
1423
|
+
if (attr && isAcceptedAttr(attr.name, attr.value)) {
|
|
1424
|
+
level.push({
|
|
1425
|
+
name: `[${escape(attr.name)}="${escape(attr.value)}"]`,
|
|
1426
|
+
penalty: 2
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
const tag = element.tagName.toLowerCase();
|
|
1431
|
+
level.push({ name: tag, penalty: 5 });
|
|
1432
|
+
const typedIndex = indexOfElement(element, tag);
|
|
1433
|
+
if (typedIndex !== void 0) {
|
|
1434
|
+
level.push({ name: nthOfType(tag, typedIndex), penalty: 10 });
|
|
1435
|
+
}
|
|
1436
|
+
const childIndex = indexOfElement(element);
|
|
1437
|
+
if (childIndex !== void 0) {
|
|
1438
|
+
level.push({ name: nthChild(tag, childIndex), penalty: 50 });
|
|
1439
|
+
}
|
|
1440
|
+
return level;
|
|
1441
|
+
}
|
|
1442
|
+
function createSelector(path) {
|
|
1443
|
+
const first = path[0];
|
|
1444
|
+
if (!first) return "";
|
|
1445
|
+
let node = first;
|
|
1446
|
+
let query = node.name;
|
|
1447
|
+
for (let i = 1; i < path.length; i++) {
|
|
1448
|
+
const next = path[i];
|
|
1449
|
+
if (!next) continue;
|
|
1450
|
+
const lvl = next.level ?? 0;
|
|
1451
|
+
query = node.level === lvl - 1 ? `${next.name} > ${query}` : `${next.name} ${query}`;
|
|
1452
|
+
node = next;
|
|
1453
|
+
}
|
|
1454
|
+
return query;
|
|
1455
|
+
}
|
|
1456
|
+
function pathPenalty(path) {
|
|
1457
|
+
return path.reduce((acc, node) => acc + node.penalty, 0);
|
|
1458
|
+
}
|
|
1459
|
+
function* combinations(stack, path = []) {
|
|
1460
|
+
if (stack.length === 0) {
|
|
1461
|
+
yield path;
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
const first = stack[0];
|
|
1465
|
+
if (!first) return;
|
|
1466
|
+
for (const node of first) {
|
|
1467
|
+
yield* combinations(stack.slice(1), path.concat(node));
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
function isUniquePath(path, root) {
|
|
1471
|
+
const css = createSelector(path);
|
|
1472
|
+
if (!css) return false;
|
|
1473
|
+
return root.querySelectorAll(css).length === 1;
|
|
1474
|
+
}
|
|
1475
|
+
function* optimize(path, input, root, startTime) {
|
|
1476
|
+
if (path.length <= 2) return;
|
|
1477
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
1478
|
+
if (Date.now() - startTime > 1e3) return;
|
|
1479
|
+
const next = [...path];
|
|
1480
|
+
next.splice(i, 1);
|
|
1481
|
+
if (isUniquePath(next, root) && root.querySelector(createSelector(next)) === input) {
|
|
1482
|
+
yield next;
|
|
1483
|
+
yield* optimize(next, input, root, startTime);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
function finder(input) {
|
|
1488
|
+
if (input.tagName.toLowerCase() === "html") return "html";
|
|
1489
|
+
const root = input.getRootNode();
|
|
1490
|
+
const stack = [];
|
|
1491
|
+
let paths = [];
|
|
1492
|
+
let current = input;
|
|
1493
|
+
let levelIndex = 0;
|
|
1494
|
+
const startTime = Date.now();
|
|
1495
|
+
let foundPath;
|
|
1496
|
+
while (current && current !== root && current !== document.body) {
|
|
1497
|
+
const level = tie(current);
|
|
1498
|
+
for (const node of level) node.level = levelIndex;
|
|
1499
|
+
stack.push(level);
|
|
1500
|
+
current = current.parentElement;
|
|
1501
|
+
levelIndex++;
|
|
1502
|
+
paths.push(...combinations(stack));
|
|
1503
|
+
if (levelIndex >= 3) {
|
|
1504
|
+
paths.sort((a, b) => pathPenalty(a) - pathPenalty(b));
|
|
1505
|
+
for (const candidate of paths) {
|
|
1506
|
+
if (Date.now() - startTime > 1e3) break;
|
|
1507
|
+
if (isUniquePath(candidate, root)) {
|
|
1508
|
+
foundPath = candidate;
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
if (foundPath) break;
|
|
1513
|
+
paths = [];
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
if (!foundPath) {
|
|
1517
|
+
paths.sort((a, b) => pathPenalty(a) - pathPenalty(b));
|
|
1518
|
+
for (const candidate of paths) {
|
|
1519
|
+
if (isUniquePath(candidate, root)) {
|
|
1520
|
+
foundPath = candidate;
|
|
1521
|
+
break;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
if (!foundPath) {
|
|
1526
|
+
current = input;
|
|
1527
|
+
levelIndex = 0;
|
|
1528
|
+
const fallback = [];
|
|
1529
|
+
while (current && current !== root && current !== document.body) {
|
|
1530
|
+
const tag = current.tagName.toLowerCase();
|
|
1531
|
+
const idx = indexOfElement(current, tag);
|
|
1532
|
+
if (idx === void 0) return null;
|
|
1533
|
+
fallback.push({ name: nthOfType(tag, idx), penalty: NaN, level: levelIndex });
|
|
1534
|
+
current = current.parentElement;
|
|
1535
|
+
levelIndex++;
|
|
1536
|
+
}
|
|
1537
|
+
if (fallback.length > 0 && isUniquePath(fallback, root)) {
|
|
1538
|
+
return createSelector(fallback);
|
|
1539
|
+
}
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
const optimized = [...optimize(foundPath, input, root, startTime)];
|
|
1543
|
+
optimized.sort((a, b) => pathPenalty(a) - pathPenalty(b));
|
|
1544
|
+
if (optimized.length > 0 && optimized[0]) {
|
|
1545
|
+
return createSelector(optimized[0]);
|
|
1546
|
+
}
|
|
1547
|
+
return createSelector(foundPath);
|
|
1548
|
+
}
|
|
1549
|
+
function getFilePath(el) {
|
|
1550
|
+
return el.getAttribute("data-current-file-path") || el.getAttribute("data-component-path");
|
|
1551
|
+
}
|
|
1552
|
+
function buildPayload(target) {
|
|
1553
|
+
const rect = target.getBoundingClientRect();
|
|
1554
|
+
const hasText = target.childNodes.length === 1 && target.childNodes[0]?.nodeType === Node.TEXT_NODE;
|
|
1555
|
+
const tagName = target.tagName.toLowerCase();
|
|
1556
|
+
let selector = null;
|
|
1557
|
+
try {
|
|
1558
|
+
selector = finder(target);
|
|
1559
|
+
} catch {
|
|
1560
|
+
selector = null;
|
|
1561
|
+
}
|
|
1562
|
+
return {
|
|
1563
|
+
rect: {
|
|
1564
|
+
left: rect.left,
|
|
1565
|
+
top: rect.top,
|
|
1566
|
+
right: rect.right,
|
|
1567
|
+
bottom: rect.bottom,
|
|
1568
|
+
width: rect.width,
|
|
1569
|
+
height: rect.height
|
|
1570
|
+
},
|
|
1571
|
+
componentName: target.getAttribute("data-component-name"),
|
|
1572
|
+
componentPath: target.getAttribute("data-component-path"),
|
|
1573
|
+
filePath: getFilePath(target),
|
|
1574
|
+
selector,
|
|
1575
|
+
tagName,
|
|
1576
|
+
className: typeof target.className === "string" ? target.className : "",
|
|
1577
|
+
hasTextContent: !!hasText,
|
|
1578
|
+
textContent: hasText ? target.textContent ?? "" : null,
|
|
1579
|
+
src: tagName === "img" ? target.getAttribute("src") ?? "" : null
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
function enableDomSelector(options) {
|
|
1583
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1584
|
+
return () => void 0;
|
|
1585
|
+
}
|
|
1586
|
+
const zIndex = options.overlayZIndex ?? 2147483646;
|
|
1587
|
+
const ignoreSelector = options.ignoreSelector ?? "[data-docyrus-devtools]";
|
|
1588
|
+
const overlay = document.createElement("div");
|
|
1589
|
+
Object.assign(overlay.style, {
|
|
1590
|
+
position: "fixed",
|
|
1591
|
+
pointerEvents: "none",
|
|
1592
|
+
border: "2px solid #3b82f6",
|
|
1593
|
+
backgroundColor: "rgba(59,130,246,0.25)",
|
|
1594
|
+
zIndex: String(zIndex),
|
|
1595
|
+
transition: "all 0.08s ease",
|
|
1596
|
+
display: "none",
|
|
1597
|
+
left: "0px",
|
|
1598
|
+
top: "0px",
|
|
1599
|
+
width: "0px",
|
|
1600
|
+
height: "0px",
|
|
1601
|
+
boxSizing: "border-box"
|
|
1602
|
+
});
|
|
1603
|
+
overlay.setAttribute("data-docyrus-devtools", "selector-overlay");
|
|
1604
|
+
document.body.appendChild(overlay);
|
|
1605
|
+
const originalCursor = document.body.style.cursor || "";
|
|
1606
|
+
document.body.style.cursor = "crosshair";
|
|
1607
|
+
function isIgnored(element) {
|
|
1608
|
+
return element === overlay || element.closest(ignoreSelector) !== null;
|
|
1609
|
+
}
|
|
1610
|
+
const handleMove = (event) => {
|
|
1611
|
+
const { target } = event;
|
|
1612
|
+
if (!(target instanceof Element) || isIgnored(target)) {
|
|
1613
|
+
overlay.style.display = "none";
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const rect = target.getBoundingClientRect();
|
|
1617
|
+
overlay.style.display = "block";
|
|
1618
|
+
overlay.style.left = `${rect.left}px`;
|
|
1619
|
+
overlay.style.top = `${rect.top}px`;
|
|
1620
|
+
overlay.style.width = `${rect.width}px`;
|
|
1621
|
+
overlay.style.height = `${rect.height}px`;
|
|
1622
|
+
};
|
|
1623
|
+
const handleClick = (event) => {
|
|
1624
|
+
const { target } = event;
|
|
1625
|
+
if (!(target instanceof Element)) return;
|
|
1626
|
+
if (isIgnored(target)) return;
|
|
1627
|
+
event.preventDefault();
|
|
1628
|
+
event.stopPropagation();
|
|
1629
|
+
overlay.style.display = "none";
|
|
1630
|
+
options.onSelect(buildPayload(target));
|
|
1631
|
+
};
|
|
1632
|
+
const handleLeave = () => {
|
|
1633
|
+
overlay.style.display = "none";
|
|
1634
|
+
};
|
|
1635
|
+
const handleKey = (event) => {
|
|
1636
|
+
if (event.key === "Escape") {
|
|
1637
|
+
options.onCancel?.();
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
document.addEventListener("pointermove", handleMove, { passive: true });
|
|
1641
|
+
document.addEventListener("click", handleClick, true);
|
|
1642
|
+
document.addEventListener("mouseleave", handleLeave);
|
|
1643
|
+
document.addEventListener("keydown", handleKey);
|
|
1644
|
+
return () => {
|
|
1645
|
+
document.removeEventListener("pointermove", handleMove);
|
|
1646
|
+
document.removeEventListener("click", handleClick, true);
|
|
1647
|
+
document.removeEventListener("mouseleave", handleLeave);
|
|
1648
|
+
document.removeEventListener("keydown", handleKey);
|
|
1649
|
+
overlay.remove();
|
|
1650
|
+
document.body.style.cursor = originalCursor;
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// src/core/openapi.ts
|
|
1655
|
+
var METHOD_ORDER = [
|
|
1656
|
+
"GET",
|
|
1657
|
+
"POST",
|
|
1658
|
+
"PUT",
|
|
1659
|
+
"PATCH",
|
|
1660
|
+
"DELETE",
|
|
1661
|
+
"HEAD",
|
|
1662
|
+
"OPTIONS"
|
|
1663
|
+
];
|
|
1664
|
+
function getExampleValue(schema, depth = 0) {
|
|
1665
|
+
if (!schema || depth > 4) {
|
|
1666
|
+
return void 0;
|
|
1667
|
+
}
|
|
1668
|
+
if (schema.example !== void 0) {
|
|
1669
|
+
return schema.example;
|
|
1670
|
+
}
|
|
1671
|
+
if (schema.default !== void 0) {
|
|
1672
|
+
return schema.default;
|
|
1673
|
+
}
|
|
1674
|
+
if (schema.enum?.length) {
|
|
1675
|
+
return schema.enum[0];
|
|
1676
|
+
}
|
|
1677
|
+
if (schema.oneOf?.length) {
|
|
1678
|
+
return getExampleValue(schema.oneOf[0], depth + 1);
|
|
1679
|
+
}
|
|
1680
|
+
if (schema.anyOf?.length) {
|
|
1681
|
+
return getExampleValue(schema.anyOf[0], depth + 1);
|
|
1682
|
+
}
|
|
1683
|
+
if (schema.allOf?.length) {
|
|
1684
|
+
const merged = schema.allOf.reduce((result, item) => {
|
|
1685
|
+
const example = getExampleValue(item, depth + 1);
|
|
1686
|
+
if (example && typeof example === "object" && !Array.isArray(example)) {
|
|
1687
|
+
Object.assign(result, example);
|
|
1688
|
+
}
|
|
1689
|
+
return result;
|
|
1690
|
+
}, {});
|
|
1691
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
1692
|
+
}
|
|
1693
|
+
switch (schema.type) {
|
|
1694
|
+
case "object": {
|
|
1695
|
+
const output = {};
|
|
1696
|
+
for (const [key, property] of Object.entries(schema.properties ?? {})) {
|
|
1697
|
+
output[key] = getExampleValue(property, depth + 1);
|
|
1698
|
+
}
|
|
1699
|
+
if (Object.keys(output).length > 0) {
|
|
1700
|
+
return output;
|
|
1701
|
+
}
|
|
1702
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
|
|
1703
|
+
return {
|
|
1704
|
+
key: getExampleValue(schema.additionalProperties, depth + 1)
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
return {};
|
|
1708
|
+
}
|
|
1709
|
+
case "array":
|
|
1710
|
+
return [getExampleValue(schema.items, depth + 1)];
|
|
1711
|
+
case "integer":
|
|
1712
|
+
case "number":
|
|
1713
|
+
return 0;
|
|
1714
|
+
case "boolean":
|
|
1715
|
+
return true;
|
|
1716
|
+
case "string":
|
|
1717
|
+
switch (schema.format) {
|
|
1718
|
+
case "date-time":
|
|
1719
|
+
return "2026-01-01T00:00:00.000Z";
|
|
1720
|
+
case "date":
|
|
1721
|
+
return "2026-01-01";
|
|
1722
|
+
case "email":
|
|
1723
|
+
return "user@example.com";
|
|
1724
|
+
case "uuid":
|
|
1725
|
+
return "00000000-0000-0000-0000-000000000000";
|
|
1726
|
+
default:
|
|
1727
|
+
return "";
|
|
1728
|
+
}
|
|
1729
|
+
default:
|
|
1730
|
+
return void 0;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function getMediaTypeExample(mediaType) {
|
|
1734
|
+
if (!mediaType) {
|
|
1735
|
+
return void 0;
|
|
1736
|
+
}
|
|
1737
|
+
if (mediaType.example !== void 0) {
|
|
1738
|
+
return mediaType.example;
|
|
1739
|
+
}
|
|
1740
|
+
const exampleEntry = Object.values(mediaType.examples ?? {}).find((example) => example?.value !== void 0);
|
|
1741
|
+
if (exampleEntry?.value !== void 0) {
|
|
1742
|
+
return exampleEntry.value;
|
|
1743
|
+
}
|
|
1744
|
+
return getExampleValue(mediaType.schema);
|
|
1745
|
+
}
|
|
1746
|
+
function pickPreferredContentType(content) {
|
|
1747
|
+
const contentTypes = Object.keys(content ?? {});
|
|
1748
|
+
if (contentTypes.length === 0) {
|
|
1749
|
+
return void 0;
|
|
1750
|
+
}
|
|
1751
|
+
return contentTypes.find((type) => type.includes("application/json")) ?? contentTypes.find((type) => type.includes("+json")) ?? contentTypes.find((type) => type.startsWith("text/")) ?? contentTypes.find((type) => type.includes("application/x-www-form-urlencoded")) ?? contentTypes.find((type) => type.includes("multipart/form-data")) ?? contentTypes[0];
|
|
1752
|
+
}
|
|
1753
|
+
function pickPreferredResponseType(responses) {
|
|
1754
|
+
const successCodes = Object.keys(responses ?? {}).sort().filter((code) => code.startsWith("2"));
|
|
1755
|
+
const preferredStatusCode = successCodes[0] ?? Object.keys(responses ?? {})[0];
|
|
1756
|
+
const preferredContentType = pickPreferredContentType(responses?.[preferredStatusCode]?.content);
|
|
1757
|
+
if (!preferredContentType) {
|
|
1758
|
+
return "json";
|
|
1759
|
+
}
|
|
1760
|
+
if (preferredContentType.startsWith("text/")) {
|
|
1761
|
+
return "text";
|
|
1762
|
+
}
|
|
1763
|
+
if (preferredContentType.includes("multipart/form-data")) {
|
|
1764
|
+
return "formData";
|
|
1765
|
+
}
|
|
1766
|
+
if (preferredContentType.includes("pdf") || preferredContentType.includes("octet-stream") || preferredContentType.startsWith("image/")) {
|
|
1767
|
+
return "blob";
|
|
1768
|
+
}
|
|
1769
|
+
return "json";
|
|
1770
|
+
}
|
|
1771
|
+
function createBodyTemplate(example, contentType) {
|
|
1772
|
+
if (example === void 0 || example === null) {
|
|
1773
|
+
return "";
|
|
1774
|
+
}
|
|
1775
|
+
if (typeof example === "string" && contentType && !contentType.includes("json")) {
|
|
1776
|
+
return example;
|
|
1777
|
+
}
|
|
1778
|
+
return JSON.stringify(example, null, 2);
|
|
1779
|
+
}
|
|
1780
|
+
function mergeParameters(pathParameters = [], operationParameters = []) {
|
|
1781
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1782
|
+
for (const parameter of pathParameters) {
|
|
1783
|
+
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
1784
|
+
}
|
|
1785
|
+
for (const parameter of operationParameters) {
|
|
1786
|
+
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
1787
|
+
}
|
|
1788
|
+
return Array.from(merged.values());
|
|
1789
|
+
}
|
|
1790
|
+
function getParameterDefaultValue(parameter) {
|
|
1791
|
+
if (parameter.example !== void 0) {
|
|
1792
|
+
return parameter.example;
|
|
1793
|
+
}
|
|
1794
|
+
const schemaExample = getExampleValue(parameter.schema);
|
|
1795
|
+
if (schemaExample !== void 0) {
|
|
1796
|
+
return schemaExample;
|
|
1797
|
+
}
|
|
1798
|
+
if (parameter.in === "path") {
|
|
1799
|
+
return parameter.name;
|
|
1800
|
+
}
|
|
1801
|
+
return "";
|
|
1802
|
+
}
|
|
1803
|
+
function normalizeMethod(method) {
|
|
1804
|
+
const normalized = method.toUpperCase();
|
|
1805
|
+
return METHOD_ORDER.includes(normalized) ? normalized : null;
|
|
1806
|
+
}
|
|
1807
|
+
function compareOperations(left, right) {
|
|
1808
|
+
if (left.path !== right.path) {
|
|
1809
|
+
return left.path.localeCompare(right.path);
|
|
1810
|
+
}
|
|
1811
|
+
return METHOD_ORDER.indexOf(left.method) - METHOD_ORDER.indexOf(right.method);
|
|
1812
|
+
}
|
|
1813
|
+
function buildOpenApiExplorerOperations(document2) {
|
|
1814
|
+
const operations = [];
|
|
1815
|
+
for (const [path, pathItem] of Object.entries(document2.paths ?? {})) {
|
|
1816
|
+
for (const [methodKey, operationValue] of Object.entries(pathItem)) {
|
|
1817
|
+
const method = normalizeMethod(methodKey);
|
|
1818
|
+
if (!method || !operationValue || methodKey === "parameters") {
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
const operation = operationValue;
|
|
1822
|
+
const parameters = mergeParameters(pathItem.parameters, operation.parameters);
|
|
1823
|
+
const requestContentTypes = Object.keys(operation.requestBody?.content ?? {});
|
|
1824
|
+
const preferredRequestContentType = pickPreferredContentType(operation.requestBody?.content);
|
|
1825
|
+
const defaultPathParams = {};
|
|
1826
|
+
const defaultQueryParams = {};
|
|
1827
|
+
const defaultHeaderParams = {};
|
|
1828
|
+
for (const parameter of parameters) {
|
|
1829
|
+
const value = getParameterDefaultValue(parameter);
|
|
1830
|
+
if (parameter.in === "path") {
|
|
1831
|
+
defaultPathParams[parameter.name] = String(value ?? "");
|
|
1832
|
+
continue;
|
|
1833
|
+
}
|
|
1834
|
+
if (parameter.in === "query") {
|
|
1835
|
+
defaultQueryParams[parameter.name] = value;
|
|
1836
|
+
continue;
|
|
1837
|
+
}
|
|
1838
|
+
if (parameter.in === "header" && parameter.name.toLowerCase() !== "authorization") {
|
|
1839
|
+
defaultHeaderParams[parameter.name] = value;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
const preferredMediaType = preferredRequestContentType ? operation.requestBody?.content?.[preferredRequestContentType] : void 0;
|
|
1843
|
+
const defaultBodyText = createBodyTemplate(
|
|
1844
|
+
getMediaTypeExample(preferredMediaType),
|
|
1845
|
+
preferredRequestContentType
|
|
1846
|
+
);
|
|
1847
|
+
operations.push({
|
|
1848
|
+
id: operation.operationId ?? `${method} ${path}`,
|
|
1849
|
+
method,
|
|
1850
|
+
path,
|
|
1851
|
+
summary: operation.summary ?? operation.operationId ?? `${method} ${path}`,
|
|
1852
|
+
description: operation.description,
|
|
1853
|
+
tags: operation.tags ?? [],
|
|
1854
|
+
parameters,
|
|
1855
|
+
requestContentTypes,
|
|
1856
|
+
preferredRequestContentType,
|
|
1857
|
+
preferredResponseType: pickPreferredResponseType(operation.responses),
|
|
1858
|
+
defaultPathParams,
|
|
1859
|
+
defaultQueryParams,
|
|
1860
|
+
defaultHeaderParams,
|
|
1861
|
+
defaultBodyText
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return operations.sort(compareOperations);
|
|
1866
|
+
}
|
|
1867
|
+
function normalizePathForMatch(path) {
|
|
1868
|
+
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
1869
|
+
try {
|
|
1870
|
+
return new URL(path).pathname;
|
|
1871
|
+
} catch {
|
|
1872
|
+
return path.split("?")[0] ?? path;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
return path.split("?")[0] ?? path;
|
|
1876
|
+
}
|
|
1877
|
+
function getPathSegments(path) {
|
|
1878
|
+
return normalizePathForMatch(path).split("/").filter(Boolean);
|
|
1879
|
+
}
|
|
1880
|
+
function decodePathSegment(value) {
|
|
1881
|
+
try {
|
|
1882
|
+
return decodeURIComponent(value);
|
|
1883
|
+
} catch {
|
|
1884
|
+
return value;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
function isVersionSegment(segment) {
|
|
1888
|
+
return /^v\d+$/i.test(segment);
|
|
1889
|
+
}
|
|
1890
|
+
function getOpenApiNamespace(path) {
|
|
1891
|
+
const segments = getPathSegments(path);
|
|
1892
|
+
if (segments.length === 0) {
|
|
1893
|
+
return "root";
|
|
1894
|
+
}
|
|
1895
|
+
if (segments[0] && isVersionSegment(segments[0])) {
|
|
1896
|
+
return segments[1] ?? segments[0];
|
|
1897
|
+
}
|
|
1898
|
+
return segments[0] ?? "root";
|
|
1899
|
+
}
|
|
1900
|
+
function matchOpenApiOperation(operations, method, path) {
|
|
1901
|
+
const concreteSegments = getPathSegments(path);
|
|
1902
|
+
for (const operation of operations) {
|
|
1903
|
+
if (operation.method !== method) {
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
const operationSegments = getPathSegments(operation.path);
|
|
1907
|
+
if (operationSegments.length !== concreteSegments.length) {
|
|
1908
|
+
continue;
|
|
1909
|
+
}
|
|
1910
|
+
const pathParams = {};
|
|
1911
|
+
let matches = true;
|
|
1912
|
+
for (const [index, operationSegment] of operationSegments.entries()) {
|
|
1913
|
+
const concreteSegment = concreteSegments[index];
|
|
1914
|
+
if (!concreteSegment) {
|
|
1915
|
+
matches = false;
|
|
1916
|
+
break;
|
|
1917
|
+
}
|
|
1918
|
+
if (operationSegment.startsWith("{") && operationSegment.endsWith("}")) {
|
|
1919
|
+
const parameterName = operationSegment.slice(1, -1);
|
|
1920
|
+
pathParams[parameterName] = decodePathSegment(concreteSegment);
|
|
1921
|
+
continue;
|
|
1922
|
+
}
|
|
1923
|
+
if (operationSegment !== concreteSegment) {
|
|
1924
|
+
matches = false;
|
|
1925
|
+
break;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
if (matches) {
|
|
1929
|
+
return {
|
|
1930
|
+
operation,
|
|
1931
|
+
pathParams
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
return null;
|
|
1936
|
+
}
|
|
1937
|
+
function replaceOpenApiPathParams(path, pathParams) {
|
|
1938
|
+
return path.replace(/\{([^}]+)\}/g, (_match, key) => {
|
|
1939
|
+
const value = pathParams[key];
|
|
1940
|
+
return encodeURIComponent(value ?? key);
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
function appendObjectEntries(target, value) {
|
|
1944
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
1945
|
+
if (entryValue == null) {
|
|
1946
|
+
continue;
|
|
1947
|
+
}
|
|
1948
|
+
if (Array.isArray(entryValue)) {
|
|
1949
|
+
for (const item of entryValue) {
|
|
1950
|
+
if (item == null) {
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
target.append(key, typeof item === "object" ? JSON.stringify(item) : String(item));
|
|
1954
|
+
}
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
if (typeof Blob !== "undefined" && entryValue instanceof Blob && target instanceof FormData) {
|
|
1958
|
+
target.append(key, entryValue);
|
|
1959
|
+
continue;
|
|
1960
|
+
}
|
|
1961
|
+
target.append(key, typeof entryValue === "object" ? JSON.stringify(entryValue) : String(entryValue));
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
function prepareOpenApiRequestBody(bodyText, contentType) {
|
|
1965
|
+
const trimmed = bodyText.trim();
|
|
1966
|
+
if (!trimmed) {
|
|
1967
|
+
return void 0;
|
|
1968
|
+
}
|
|
1969
|
+
if (!contentType || contentType.includes("json")) {
|
|
1970
|
+
return JSON.parse(trimmed);
|
|
1971
|
+
}
|
|
1972
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
1973
|
+
const parsed = JSON.parse(trimmed);
|
|
1974
|
+
const searchParams = new URLSearchParams();
|
|
1975
|
+
appendObjectEntries(searchParams, parsed);
|
|
1976
|
+
return searchParams;
|
|
1977
|
+
}
|
|
1978
|
+
if (contentType.includes("multipart/form-data")) {
|
|
1979
|
+
const parsed = JSON.parse(trimmed);
|
|
1980
|
+
const formData = new FormData();
|
|
1981
|
+
appendObjectEntries(formData, parsed);
|
|
1982
|
+
return formData;
|
|
1983
|
+
}
|
|
1984
|
+
return trimmed;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
export { DevtoolsStoreImpl, attachHostBridge, attachQueryClient, buildOpenApiExplorerOperations, createDevtoolsStore, enableDomSelector, getOpenApiNamespace, instrumentAddinClient, instrumentApiClient, instrumentClient, instrumentConsole, instrumentFetch, instrumentIframeMessages, matchOpenApiOperation, normalizeError, postDevtoolsMessageToHost, prepareOpenApiRequestBody, replaceOpenApiPathParams, sanitizeForDevtools, stableStringify };
|
|
1988
|
+
//# sourceMappingURL=index.js.map
|
|
1989
|
+
//# sourceMappingURL=index.js.map
|