dowwntime 1.3.8 → 1.4.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/dist/cli.mjs +36 -37
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +36 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -28351,39 +28351,45 @@ const run = async (options) => {
|
|
|
28351
28351
|
}));
|
|
28352
28352
|
if (dereferenceResult.errors?.[0] || !dereferenceResult.schema) throw new Error("Failed to dereference OpenAPI spec.", { cause: dereferenceResult.errors?.[0] });
|
|
28353
28353
|
const schema$6 = dereferenceResult.schema;
|
|
28354
|
-
const
|
|
28355
|
-
if (
|
|
28354
|
+
const servers = options.baseUrl ? [{ url: options.baseUrl }] : schema$6.servers ?? [];
|
|
28355
|
+
if (servers.length === 0) throw new Error("No base URL found in OpenAPI spec and no baseUrl option provided.");
|
|
28356
|
+
const multipleServers = servers.length > 1;
|
|
28356
28357
|
const fetchConfigurations = /* @__PURE__ */ new Map();
|
|
28357
|
-
|
|
28358
|
-
const
|
|
28359
|
-
|
|
28360
|
-
if (
|
|
28361
|
-
|
|
28362
|
-
|
|
28363
|
-
|
|
28364
|
-
|
|
28365
|
-
let
|
|
28366
|
-
if (
|
|
28367
|
-
|
|
28368
|
-
|
|
28369
|
-
|
|
28370
|
-
|
|
28371
|
-
|
|
28372
|
-
|
|
28373
|
-
|
|
28374
|
-
|
|
28375
|
-
if (!exampleValue) {
|
|
28376
|
-
debug$1(`No example value for path parameter ${param.name} in ${path$2}`);
|
|
28358
|
+
for (const server of servers) {
|
|
28359
|
+
const baseUrl = server.url;
|
|
28360
|
+
const serverLabel = server.description ?? new URL(baseUrl).host;
|
|
28361
|
+
if (schema$6.paths) for (const path$2 of Object.keys(schema$6.paths)) {
|
|
28362
|
+
const pathItem = schema$6.paths[path$2];
|
|
28363
|
+
if (!pathItem) continue;
|
|
28364
|
+
if (!pathItem.get) continue;
|
|
28365
|
+
const url$2 = new URL(path$2, baseUrl);
|
|
28366
|
+
let _path = path$2;
|
|
28367
|
+
if ("200" in (pathItem.get?.responses ?? {}) && "text/event-stream" in (pathItem.get.responses?.["200"]?.content ?? {})) continue;
|
|
28368
|
+
for (const param of pathItem.get.parameters || []) {
|
|
28369
|
+
let exampleValue = options.getExampleValue?.(param.name, path$2) ?? param.example ?? param.examples?.[0] ?? param.schema?.example ?? param.schema?.examples?.[0];
|
|
28370
|
+
if (!exampleValue && (param.required || param.in === "path") && "enum" in param.schema) {
|
|
28371
|
+
const enumValues = param.schema.enum;
|
|
28372
|
+
if (Array.isArray(enumValues) && enumValues.length > 0) exampleValue = enumValues[0];
|
|
28373
|
+
}
|
|
28374
|
+
if (!exampleValue && param.required) {
|
|
28375
|
+
debug$1(`No example value for parameter ${param.name} in ${path$2}`);
|
|
28377
28376
|
continue;
|
|
28378
28377
|
}
|
|
28379
|
-
|
|
28380
|
-
|
|
28381
|
-
|
|
28378
|
+
if (param.in === "path") {
|
|
28379
|
+
if (!exampleValue) {
|
|
28380
|
+
debug$1(`No example value for path parameter ${param.name} in ${path$2}`);
|
|
28381
|
+
continue;
|
|
28382
|
+
}
|
|
28383
|
+
const placeholder = `{${param.name}}`;
|
|
28384
|
+
_path = _path.replace(placeholder, exampleValue);
|
|
28385
|
+
url$2.pathname = _path;
|
|
28386
|
+
}
|
|
28387
|
+
if (!exampleValue) continue;
|
|
28388
|
+
if (param.in === "query") url$2.searchParams.set(param.name, exampleValue);
|
|
28382
28389
|
}
|
|
28383
|
-
|
|
28384
|
-
|
|
28390
|
+
const key = multipleServers ? `[${serverLabel}] ${path$2}` : path$2;
|
|
28391
|
+
fetchConfigurations.set(key, url$2);
|
|
28385
28392
|
}
|
|
28386
|
-
fetchConfigurations.set(path$2, url$2);
|
|
28387
28393
|
}
|
|
28388
28394
|
const measurements = new Storage(options.storagePath, options.maxSpaceUsageBytes ?? 262144 * .95);
|
|
28389
28395
|
const measure = async (path$2) => {
|
|
@@ -28417,16 +28423,9 @@ const run = async (options) => {
|
|
|
28417
28423
|
})(measure);
|
|
28418
28424
|
await Promise.all(Array.from(fetchConfigurations.keys()).map(async (path$2) => {
|
|
28419
28425
|
const results = await Promise.all(Array.from({ length: options.samples ?? 5 }).map(() => throttledMeasure(path$2)));
|
|
28420
|
-
const
|
|
28421
|
-
const q1 = durations[Math.floor(durations.length * .25)] ?? 0;
|
|
28422
|
-
const q3 = durations[Math.floor(durations.length * .75)] ?? 0;
|
|
28423
|
-
const iqr = q3 - q1;
|
|
28424
|
-
const lowerBound = q1 - 1.5 * iqr;
|
|
28425
|
-
const upperBound = q3 + 1.5 * iqr;
|
|
28426
|
-
const filteredResults = results.filter((r) => r && r.durationMs >= lowerBound && r.durationMs <= upperBound);
|
|
28427
|
-
const durationMs = Math.round(filteredResults.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / filteredResults.length);
|
|
28426
|
+
const durationMs = Math.round(results.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / results.length);
|
|
28428
28427
|
let status = "down";
|
|
28429
|
-
const statusCode = Math.max(...
|
|
28428
|
+
const statusCode = Math.max(...results.map((r) => r?.statusCode ?? 0));
|
|
28430
28429
|
if (options.getStatus) status = options.getStatus(statusCode, path$2, durationMs);
|
|
28431
28430
|
else status = statusCode >= 200 && statusCode < 300 ? "up" : "down";
|
|
28432
28431
|
const measurement = {
|