@warlock.js/devtools 5.54.0 → 5.56.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 +36 -0
- package/README.md +26 -13
- package/cjs/{ai-source-CSPh1HqJ.cjs → ai-source-DTpxumMA.cjs} +54 -3
- package/cjs/{ai-source-CSPh1HqJ.cjs.map → ai-source-DTpxumMA.cjs.map} +1 -1
- package/cjs/auth-DzU0gHDG.cjs +1655 -0
- package/cjs/auth-DzU0gHDG.cjs.map +1 -0
- package/cjs/boot-BQi0Etor.cjs +138 -0
- package/cjs/boot-BQi0Etor.cjs.map +1 -0
- package/cjs/capture-CqIiaznN.cjs +1342 -0
- package/cjs/capture-CqIiaznN.cjs.map +1 -0
- package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
- package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
- package/cjs/collector-CJbQbzzK.cjs +271 -0
- package/cjs/collector-CJbQbzzK.cjs.map +1 -0
- package/cjs/contracts-CVmplkNb.cjs +112 -0
- package/cjs/contracts-CVmplkNb.cjs.map +1 -0
- package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
- package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
- package/cjs/errors-CyZp5yS-.cjs +177 -0
- package/cjs/errors-CyZp5yS-.cjs.map +1 -0
- package/cjs/histogram-BaI-PnCv.cjs +102 -0
- package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
- package/cjs/http-CabcUwBx.cjs +870 -0
- package/cjs/http-CabcUwBx.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/insights-BKtqxdnP.cjs +811 -0
- package/cjs/insights-BKtqxdnP.cjs.map +1 -0
- package/cjs/ip-DbNhPOzi.cjs +153 -0
- package/cjs/ip-DbNhPOzi.cjs.map +1 -0
- package/cjs/migrations-w7GMsrQw.cjs +297 -0
- package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
- package/cjs/openapi-CC7OAUc6.cjs +52 -0
- package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
- package/cjs/options-CWqFC5__.cjs +181 -0
- package/cjs/options-CWqFC5__.cjs.map +1 -0
- package/cjs/panels-B0dAfGbJ.cjs +298 -0
- package/cjs/panels-B0dAfGbJ.cjs.map +1 -0
- package/cjs/process-panel-DEOnLxoT.cjs +48 -0
- package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
- package/cjs/production/index.cjs +238 -0
- package/cjs/production/index.cjs.map +1 -0
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
- package/cjs/server-B6xdeKS8.cjs +184 -0
- package/cjs/server-B6xdeKS8.cjs.map +1 -0
- package/cjs/{src-BzuntLcd.cjs → src-Ce-3Lniv.cjs} +171 -308
- package/cjs/src-Ce-3Lniv.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-BGJa-zQu.cjs +875 -0
- package/cjs/stream-route-BGJa-zQu.cjs.map +1 -0
- package/esm/devtools-connector.d.mts +16 -12
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +137 -18
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +3 -2
- package/esm/options.mjs +3 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panels.mjs +267 -0
- package/esm/panels.mjs.map +1 -0
- package/esm/process-panel.mjs +20 -1
- package/esm/process-panel.mjs.map +1 -1
- package/esm/production/auth/common-passwords.mjs +303 -0
- package/esm/production/auth/common-passwords.mjs.map +1 -0
- package/esm/production/auth/default-crypto.mjs +19 -0
- package/esm/production/auth/default-crypto.mjs.map +1 -0
- package/esm/production/auth/helpers.mjs +77 -0
- package/esm/production/auth/helpers.mjs.map +1 -0
- package/esm/production/auth/index.mjs +6 -0
- package/esm/production/auth/passkeys.mjs +96 -0
- package/esm/production/auth/passkeys.mjs.map +1 -0
- package/esm/production/auth/service.mjs +1166 -0
- package/esm/production/auth/service.mjs.map +1 -0
- package/esm/production/boot.mjs +138 -0
- package/esm/production/boot.mjs.map +1 -0
- package/esm/production/capture/dev-stats.mjs +83 -0
- package/esm/production/capture/dev-stats.mjs.map +1 -0
- package/esm/production/capture/engine.mjs +442 -0
- package/esm/production/capture/engine.mjs.map +1 -0
- package/esm/production/capture/explain.mjs +271 -0
- package/esm/production/capture/explain.mjs.map +1 -0
- package/esm/production/capture/filter.mjs +24 -0
- package/esm/production/capture/filter.mjs.map +1 -0
- package/esm/production/capture/index.mjs +7 -0
- package/esm/production/capture/production-capture.mjs +134 -0
- package/esm/production/capture/production-capture.mjs.map +1 -0
- package/esm/production/capture/redact.mjs +109 -0
- package/esm/production/capture/redact.mjs.map +1 -0
- package/esm/production/capture/stats-stores.mjs +300 -0
- package/esm/production/capture/stats-stores.mjs.map +1 -0
- package/esm/production/cli/actions.mjs +151 -0
- package/esm/production/cli/actions.mjs.map +1 -0
- package/esm/production/cli/index.d.mts +17 -0
- package/esm/production/cli/index.d.mts.map +1 -0
- package/esm/production/cli/index.mjs +86 -0
- package/esm/production/cli/index.mjs.map +1 -0
- package/esm/production/contracts.d.mts +592 -0
- package/esm/production/contracts.d.mts.map +1 -0
- package/esm/production/contracts.mjs +95 -0
- package/esm/production/contracts.mjs.map +1 -0
- package/esm/production/errors.d.mts +31 -0
- package/esm/production/errors.d.mts.map +1 -0
- package/esm/production/errors.mjs +142 -0
- package/esm/production/errors.mjs.map +1 -0
- package/esm/production/http/access.mjs +124 -0
- package/esm/production/http/access.mjs.map +1 -0
- package/esm/production/http/auth-routes.mjs +280 -0
- package/esm/production/http/auth-routes.mjs.map +1 -0
- package/esm/production/http/client.mjs +57 -0
- package/esm/production/http/client.mjs.map +1 -0
- package/esm/production/http/constants.mjs +11 -0
- package/esm/production/http/constants.mjs.map +1 -0
- package/esm/production/http/context.mjs +14 -0
- package/esm/production/http/context.mjs.map +1 -0
- package/esm/production/http/cookie.mjs +39 -0
- package/esm/production/http/cookie.mjs.map +1 -0
- package/esm/production/http/headers.mjs +25 -0
- package/esm/production/http/headers.mjs.map +1 -0
- package/esm/production/http/index.mjs +10 -0
- package/esm/production/http/ip.mjs +130 -0
- package/esm/production/http/ip.mjs.map +1 -0
- package/esm/production/http/mount.mjs +300 -0
- package/esm/production/http/mount.mjs.map +1 -0
- package/esm/production/http/state.mjs +54 -0
- package/esm/production/http/state.mjs.map +1 -0
- package/esm/production/index.d.mts +6 -0
- package/esm/production/index.mjs +5 -0
- package/esm/production/insights/cap-report.mjs +67 -0
- package/esm/production/insights/cap-report.mjs.map +1 -0
- package/esm/production/insights/health.mjs +88 -0
- package/esm/production/insights/health.mjs.map +1 -0
- package/esm/production/insights/index.mjs +10 -0
- package/esm/production/insights/insights.mjs +167 -0
- package/esm/production/insights/insights.mjs.map +1 -0
- package/esm/production/insights/instance.mjs +24 -0
- package/esm/production/insights/instance.mjs.map +1 -0
- package/esm/production/insights/jobs.mjs +100 -0
- package/esm/production/insights/jobs.mjs.map +1 -0
- package/esm/production/insights/reporter.mjs +59 -0
- package/esm/production/insights/reporter.mjs.map +1 -0
- package/esm/production/insights/resources.mjs +139 -0
- package/esm/production/insights/resources.mjs.map +1 -0
- package/esm/production/insights/writer.mjs +72 -0
- package/esm/production/insights/writer.mjs.map +1 -0
- package/esm/production/openapi.mjs +52 -0
- package/esm/production/openapi.mjs.map +1 -0
- package/esm/production/options.d.mts +60 -0
- package/esm/production/options.d.mts.map +1 -0
- package/esm/production/options.mjs +170 -0
- package/esm/production/options.mjs.map +1 -0
- package/esm/production/stats/histogram.mjs +67 -0
- package/esm/production/stats/histogram.mjs.map +1 -0
- package/esm/production/stats/merge.mjs +106 -0
- package/esm/production/stats/merge.mjs.map +1 -0
- package/esm/production/store/cascade-store.mjs +322 -0
- package/esm/production/store/cascade-store.mjs.map +1 -0
- package/esm/production/store/index.mjs +5 -0
- package/esm/production/store/mapping.mjs +258 -0
- package/esm/production/store/mapping.mjs.map +1 -0
- package/esm/production/store/memory-store.mjs +291 -0
- package/esm/production/store/memory-store.mjs.map +1 -0
- package/esm/production/store/migrations.d.mts +11 -0
- package/esm/production/store/migrations.d.mts.map +1 -0
- package/esm/production/store/migrations.mjs +29 -0
- package/esm/production/store/migrations.mjs.map +1 -0
- package/esm/production/store/models/account.migration.mjs +34 -0
- package/esm/production/store/models/account.migration.mjs.map +1 -0
- package/esm/production/store/models/account.model.mjs +13 -0
- package/esm/production/store/models/account.model.mjs.map +1 -0
- package/esm/production/store/models/audit.migration.mjs +30 -0
- package/esm/production/store/models/audit.migration.mjs.map +1 -0
- package/esm/production/store/models/audit.model.mjs +13 -0
- package/esm/production/store/models/audit.model.mjs.map +1 -0
- package/esm/production/store/models/base.mjs +27 -0
- package/esm/production/store/models/base.mjs.map +1 -0
- package/esm/production/store/models/index.mjs +17 -0
- package/esm/production/store/models/invite.migration.mjs +26 -0
- package/esm/production/store/models/invite.migration.mjs.map +1 -0
- package/esm/production/store/models/invite.model.mjs +13 -0
- package/esm/production/store/models/invite.model.mjs.map +1 -0
- package/esm/production/store/models/report.migration.mjs +20 -0
- package/esm/production/store/models/report.migration.mjs.map +1 -0
- package/esm/production/store/models/report.model.mjs +13 -0
- package/esm/production/store/models/report.model.mjs.map +1 -0
- package/esm/production/store/models/sample.migration.mjs +25 -0
- package/esm/production/store/models/sample.migration.mjs.map +1 -0
- package/esm/production/store/models/sample.model.mjs +13 -0
- package/esm/production/store/models/sample.model.mjs.map +1 -0
- package/esm/production/store/models/session.migration.mjs +31 -0
- package/esm/production/store/models/session.migration.mjs.map +1 -0
- package/esm/production/store/models/session.model.mjs +13 -0
- package/esm/production/store/models/session.model.mjs.map +1 -0
- package/esm/production/store/models/state.migration.mjs +26 -0
- package/esm/production/store/models/state.migration.mjs.map +1 -0
- package/esm/production/store/models/state.model.mjs +13 -0
- package/esm/production/store/models/state.model.mjs.map +1 -0
- package/esm/query-shape.mjs +14 -1
- package/esm/query-shape.mjs.map +1 -1
- package/esm/server/explain-route.mjs +26 -1
- package/esm/server/explain-route.mjs.map +1 -1
- package/esm/server/index.mjs +16 -6
- package/esm/server/index.mjs.map +1 -1
- package/esm/server/insights-routes.mjs +62 -0
- package/esm/server/insights-routes.mjs.map +1 -0
- package/esm/server/log-routes.mjs +32 -5
- package/esm/server/log-routes.mjs.map +1 -1
- package/esm/server/openapi-routes.mjs +3 -2
- package/esm/server/openapi-routes.mjs.map +1 -1
- package/esm/server/panel-routes.mjs +44 -0
- package/esm/server/panel-routes.mjs.map +1 -0
- package/esm/server/requests-routes.mjs +125 -0
- package/esm/server/requests-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +42 -0
- package/esm/server/session-routes.mjs.map +1 -0
- package/esm/server/stream-route.mjs +81 -11
- package/esm/server/stream-route.mjs.map +1 -1
- package/esm/server/ui-assets.mjs +34 -12
- package/esm/server/ui-assets.mjs.map +1 -1
- package/esm/sources/log-source.mjs +14 -1
- package/esm/sources/log-source.mjs.map +1 -1
- package/esm/types.d.mts +271 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/ui-root.mjs +11 -6
- package/esm/ui-root.mjs.map +1 -1
- package/llms-full.txt +208 -19
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +208 -19
- package/ui/dashboard/assets/app.css +3 -0
- package/ui/dashboard/assets/app.js +50 -0
- package/ui/dashboard/build-info.json +21 -0
- package/ui/dashboard/index.html +15 -0
- package/ui/panels/processes.js +15 -0
- package/cjs/server-BlQshJLE.cjs +0 -658
- package/cjs/server-BlQshJLE.cjs.map +0 -1
- package/cjs/src-BzuntLcd.cjs.map +0 -1
- package/esm/server/process-routes.mjs +0 -11
- package/esm/server/process-routes.mjs.map +0 -1
- package/ui/app.css +0 -376
- package/ui/app.js +0 -1054
- package/ui/index.html +0 -28
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Zuuoy_Rh.cjs");
|
|
2
|
+
let _warlock_js_core = require("@warlock.js/core");
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/devtools/src/current-request-id.ts
|
|
5
|
+
var current_request_id_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ currentRequestId: () => currentRequestId });
|
|
6
|
+
/**
|
|
7
|
+
* The current request's id (core's `request.id`, threaded through
|
|
8
|
+
* `AsyncLocalStorage`), or `undefined` outside a request — sources feed
|
|
9
|
+
* devtools' background bucket in that case.
|
|
10
|
+
*
|
|
11
|
+
* Only ever reached through `./sources/*`, which the connector imports
|
|
12
|
+
* dynamically inside `boot()` — by then core is already running, so this
|
|
13
|
+
* static import never drags core's runtime graph into config-load time (see
|
|
14
|
+
* `devtools-connector.ts`).
|
|
15
|
+
*/
|
|
16
|
+
function currentRequestId() {
|
|
17
|
+
try {
|
|
18
|
+
return _warlock_js_core.requestContext.getRequest()?.id;
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
Object.defineProperty(exports, "currentRequestId", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return currentRequestId;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "current_request_id_exports", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return current_request_id_exports;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=current-request-id-BoJJb3y7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-request-id-BoJJb3y7.cjs","names":["requestContext"],"sources":["../../../../../../../packages/devtools/src/current-request-id.ts"],"sourcesContent":["import { requestContext } from \"@warlock.js/core\";\n\n/**\n * The current request's id (core's `request.id`, threaded through\n * `AsyncLocalStorage`), or `undefined` outside a request — sources feed\n * devtools' background bucket in that case.\n *\n * Only ever reached through `./sources/*`, which the connector imports\n * dynamically inside `boot()` — by then core is already running, so this\n * static import never drags core's runtime graph into config-load time (see\n * `devtools-connector.ts`).\n */\nexport function currentRequestId(): string | undefined {\n try {\n return requestContext.getRequest()?.id;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAgB,mBAAuC;CACrD,IAAI;EACF,OAAOA,gCAAe,WAAW,CAAC,EAAE;CACtC,QAAQ;EACN;CACF;AACF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
let node_crypto = require("node:crypto");
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/devtools/src/production/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Why production mode refused to start. Each code names one missing or
|
|
6
|
+
* invalid setting; the message says which and how to fix it.
|
|
7
|
+
*/
|
|
8
|
+
const DEVTOOLS_CONFIG_CODES = {
|
|
9
|
+
DT001: "Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.",
|
|
10
|
+
DT002: "The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".",
|
|
11
|
+
DT003: "Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.",
|
|
12
|
+
DT004: "DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (at least 8 characters, at most 72 bytes, not a common password, not the email). Choose another one.",
|
|
13
|
+
DT005: "Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.",
|
|
14
|
+
DT006: "Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.",
|
|
15
|
+
DT007: "A devtools production option has an invalid value. The message names the option and the accepted values.",
|
|
16
|
+
DT008: "The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.",
|
|
17
|
+
DT009: "Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.",
|
|
18
|
+
DT010: "DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32"
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Thrown while the devtools connector boots in production when the monitor is
|
|
22
|
+
* enabled but cannot start safely. It stops the app from booting, so a
|
|
23
|
+
* misconfigured deploy fails at once instead of serving an unprotected
|
|
24
|
+
* dashboard.
|
|
25
|
+
*/
|
|
26
|
+
var DevtoolsProductionConfigError = class extends Error {
|
|
27
|
+
constructor(code, detail) {
|
|
28
|
+
super(`[${code}] ${detail ? `${detail} ` : ""}${DEVTOOLS_CONFIG_CODES[code]}`);
|
|
29
|
+
this.name = "DevtoolsProductionConfigError";
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** The message every API error code answers with: what failed and what to do next. */
|
|
34
|
+
const DEVTOOLS_ERROR_MESSAGES = {
|
|
35
|
+
"auth.invalid-credentials": "The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.",
|
|
36
|
+
"auth.invalid-code": "The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.",
|
|
37
|
+
"auth.invalid-setup-token": "This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.",
|
|
38
|
+
"auth.password-too-short": "Use a password of at least 8 characters.",
|
|
39
|
+
"auth.password-too-long": "Use a password of at most 72 bytes (about 72 letters).",
|
|
40
|
+
"auth.password-common": "This password is too common. Choose one that is harder to guess.",
|
|
41
|
+
"auth.password-same-as-email": "The password must not be your email address. Choose another one.",
|
|
42
|
+
"auth.password-unchanged": "Choose a new password that differs from the current one.",
|
|
43
|
+
"auth.wrong-current-password": "The current password is not correct. Enter it again.",
|
|
44
|
+
"auth.busy": "The server is busy checking other sign-ins. Wait a few seconds and try again.",
|
|
45
|
+
"invite.invalid": "This invite link is not valid, was already used, or has expired. Ask an admin for a new one.",
|
|
46
|
+
"invite.email-taken": "An account with this email already exists. Sign in instead.",
|
|
47
|
+
"account.not-found": "This account no longer exists. Reload the list.",
|
|
48
|
+
"account.last-admin": "This is the last admin. Make another account an admin first.",
|
|
49
|
+
"account.self": "You cannot do this to your own account. Ask another admin.",
|
|
50
|
+
"account.last-factor": "This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.",
|
|
51
|
+
"role.forbidden": "Only admins can do this. Ask an admin.",
|
|
52
|
+
"csrf.invalid": "This page is out of date. Reload the dashboard and try again.",
|
|
53
|
+
"passkey.unavailable": "Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.",
|
|
54
|
+
"passkey.failed": "The passkey could not be verified. Try again, or use your authenticator app.",
|
|
55
|
+
"explain.not-allowed": "Only admins can run EXPLAIN. Ask an admin.",
|
|
56
|
+
"explain.unsupported": "This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.",
|
|
57
|
+
"explain.elsewhere": "Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.",
|
|
58
|
+
"explain.failed": "The database could not explain this query. The reference is in the server log.",
|
|
59
|
+
"request.not-found": "This request is no longer stored. Requests are kept for a limited time (24 hours by default).",
|
|
60
|
+
"request.invalid-filter": "A filter value is not valid. Check the status, method and dates.",
|
|
61
|
+
"stream.too-many": "Too many live views are open for this session. Close another dashboard tab and reload.",
|
|
62
|
+
"input.invalid": "Some fields are missing or not valid. Check the form and try again.",
|
|
63
|
+
"server.error": "The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown."
|
|
64
|
+
};
|
|
65
|
+
/** The HTTP status each code answers with. */
|
|
66
|
+
const DEVTOOLS_ERROR_STATUS = {
|
|
67
|
+
"auth.invalid-credentials": 401,
|
|
68
|
+
"auth.invalid-code": 401,
|
|
69
|
+
"auth.invalid-setup-token": 401,
|
|
70
|
+
"auth.password-too-short": 422,
|
|
71
|
+
"auth.password-too-long": 422,
|
|
72
|
+
"auth.password-common": 422,
|
|
73
|
+
"auth.password-same-as-email": 422,
|
|
74
|
+
"auth.password-unchanged": 422,
|
|
75
|
+
"auth.wrong-current-password": 401,
|
|
76
|
+
"auth.busy": 503,
|
|
77
|
+
"invite.invalid": 410,
|
|
78
|
+
"invite.email-taken": 409,
|
|
79
|
+
"account.not-found": 404,
|
|
80
|
+
"account.last-admin": 409,
|
|
81
|
+
"account.self": 409,
|
|
82
|
+
"account.last-factor": 409,
|
|
83
|
+
"role.forbidden": 403,
|
|
84
|
+
"csrf.invalid": 403,
|
|
85
|
+
"passkey.unavailable": 501,
|
|
86
|
+
"passkey.failed": 401,
|
|
87
|
+
"explain.not-allowed": 403,
|
|
88
|
+
"explain.unsupported": 400,
|
|
89
|
+
"explain.elsewhere": 409,
|
|
90
|
+
"explain.failed": 502,
|
|
91
|
+
"request.not-found": 404,
|
|
92
|
+
"request.invalid-filter": 400,
|
|
93
|
+
"stream.too-many": 429,
|
|
94
|
+
"input.invalid": 422,
|
|
95
|
+
"server.error": 500
|
|
96
|
+
};
|
|
97
|
+
/** A short reference id (8 characters, base32 alphabet) to quote to support. */
|
|
98
|
+
function createErrorRef() {
|
|
99
|
+
const alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
|
|
100
|
+
const bytes = (0, node_crypto.randomBytes)(8);
|
|
101
|
+
let ref = "";
|
|
102
|
+
for (const byte of bytes) ref += alphabet[byte % 31];
|
|
103
|
+
return ref;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* An error a dashboard route answers with. The production error handler turns
|
|
107
|
+
* it into `{ error, code, ref?, instance? }` with `statusCode`.
|
|
108
|
+
*/
|
|
109
|
+
var DevtoolsApiError = class extends Error {
|
|
110
|
+
constructor(code, options = {}) {
|
|
111
|
+
super(DEVTOOLS_ERROR_MESSAGES[code], options.cause === void 0 ? {} : { cause: options.cause });
|
|
112
|
+
this.name = "DevtoolsApiError";
|
|
113
|
+
this.code = code;
|
|
114
|
+
this.statusCode = DEVTOOLS_ERROR_STATUS[code];
|
|
115
|
+
this.ref = options.ref;
|
|
116
|
+
this.instance = options.instance;
|
|
117
|
+
}
|
|
118
|
+
/** The JSON body this error answers with. */
|
|
119
|
+
toBody() {
|
|
120
|
+
return {
|
|
121
|
+
error: this.message,
|
|
122
|
+
code: this.code,
|
|
123
|
+
...this.ref === void 0 ? {} : { ref: this.ref },
|
|
124
|
+
...this.instance === void 0 ? {} : { instance: this.instance }
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Raised by a store when a unique value is taken (an email) so callers can
|
|
130
|
+
* answer with their own error code.
|
|
131
|
+
*/
|
|
132
|
+
var DevtoolsStoreConflictError = class extends Error {
|
|
133
|
+
constructor(field) {
|
|
134
|
+
super(`A devtools record with this ${field} already exists.`);
|
|
135
|
+
this.field = field;
|
|
136
|
+
this.name = "DevtoolsStoreConflictError";
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
Object.defineProperty(exports, "DEVTOOLS_CONFIG_CODES", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function () {
|
|
144
|
+
return DEVTOOLS_CONFIG_CODES;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "DEVTOOLS_ERROR_MESSAGES", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return DEVTOOLS_ERROR_MESSAGES;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "DevtoolsApiError", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function () {
|
|
156
|
+
return DevtoolsApiError;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "DevtoolsProductionConfigError", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function () {
|
|
162
|
+
return DevtoolsProductionConfigError;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, "DevtoolsStoreConflictError", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function () {
|
|
168
|
+
return DevtoolsStoreConflictError;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(exports, "createErrorRef", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function () {
|
|
174
|
+
return createErrorRef;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
//# sourceMappingURL=errors-CyZp5yS-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CyZp5yS-.cjs","names":["randomBytes"],"sources":["../../../../../../../packages/devtools/src/production/errors.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type { DevtoolsApiErrorBody, DevtoolsErrorCode } from \"./contracts\";\n\n/**\n * Why production mode refused to start. Each code names one missing or\n * invalid setting; the message says which and how to fix it.\n */\nexport const DEVTOOLS_CONFIG_CODES = {\n DT001:\n \"Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.\",\n DT002:\n 'The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".',\n DT003:\n \"Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.\",\n DT004:\n \"DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (at least 8 characters, at most 72 bytes, not a common password, not the email). Choose another one.\",\n DT005:\n \"Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.\",\n DT006:\n \"Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.\",\n DT007:\n \"A devtools production option has an invalid value. The message names the option and the accepted values.\",\n DT008:\n \"The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.\",\n DT009: \"Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.\",\n DT010:\n \"DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32\",\n} as const;\n\n/** A production configuration error code (`DT001`–`DT010`). */\nexport type DevtoolsConfigCode = keyof typeof DEVTOOLS_CONFIG_CODES;\n\n/**\n * Thrown while the devtools connector boots in production when the monitor is\n * enabled but cannot start safely. It stops the app from booting, so a\n * misconfigured deploy fails at once instead of serving an unprotected\n * dashboard.\n */\nexport class DevtoolsProductionConfigError extends Error {\n public readonly code: DevtoolsConfigCode;\n\n public constructor(code: DevtoolsConfigCode, detail?: string) {\n super(`[${code}] ${detail ? `${detail} ` : \"\"}${DEVTOOLS_CONFIG_CODES[code]}`);\n this.name = \"DevtoolsProductionConfigError\";\n this.code = code;\n }\n}\n\n/** The message every API error code answers with: what failed and what to do next. */\nexport const DEVTOOLS_ERROR_MESSAGES: Record<DevtoolsErrorCode, string> = {\n \"auth.invalid-credentials\":\n \"The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.\",\n \"auth.invalid-code\":\n \"The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.\",\n \"auth.invalid-setup-token\":\n \"This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.\",\n \"auth.password-too-short\": \"Use a password of at least 8 characters.\",\n \"auth.password-too-long\": \"Use a password of at most 72 bytes (about 72 letters).\",\n \"auth.password-common\": \"This password is too common. Choose one that is harder to guess.\",\n \"auth.password-same-as-email\": \"The password must not be your email address. Choose another one.\",\n \"auth.password-unchanged\": \"Choose a new password that differs from the current one.\",\n \"auth.wrong-current-password\": \"The current password is not correct. Enter it again.\",\n \"auth.busy\": \"The server is busy checking other sign-ins. Wait a few seconds and try again.\",\n \"invite.invalid\":\n \"This invite link is not valid, was already used, or has expired. Ask an admin for a new one.\",\n \"invite.email-taken\": \"An account with this email already exists. Sign in instead.\",\n \"account.not-found\": \"This account no longer exists. Reload the list.\",\n \"account.last-admin\": \"This is the last admin. Make another account an admin first.\",\n \"account.self\": \"You cannot do this to your own account. Ask another admin.\",\n \"account.last-factor\":\n \"This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.\",\n \"role.forbidden\": \"Only admins can do this. Ask an admin.\",\n \"csrf.invalid\": \"This page is out of date. Reload the dashboard and try again.\",\n \"passkey.unavailable\":\n \"Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.\",\n \"passkey.failed\": \"The passkey could not be verified. Try again, or use your authenticator app.\",\n \"explain.not-allowed\": \"Only admins can run EXPLAIN. Ask an admin.\",\n \"explain.unsupported\":\n \"This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.\",\n \"explain.elsewhere\":\n \"Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.\",\n \"explain.failed\":\n \"The database could not explain this query. The reference is in the server log.\",\n \"request.not-found\":\n \"This request is no longer stored. Requests are kept for a limited time (24 hours by default).\",\n \"request.invalid-filter\": \"A filter value is not valid. Check the status, method and dates.\",\n \"stream.too-many\":\n \"Too many live views are open for this session. Close another dashboard tab and reload.\",\n \"input.invalid\": \"Some fields are missing or not valid. Check the form and try again.\",\n \"server.error\":\n \"The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown.\",\n};\n\n/** The HTTP status each code answers with. */\nexport const DEVTOOLS_ERROR_STATUS: Record<DevtoolsErrorCode, number> = {\n \"auth.invalid-credentials\": 401,\n \"auth.invalid-code\": 401,\n \"auth.invalid-setup-token\": 401,\n \"auth.password-too-short\": 422,\n \"auth.password-too-long\": 422,\n \"auth.password-common\": 422,\n \"auth.password-same-as-email\": 422,\n \"auth.password-unchanged\": 422,\n \"auth.wrong-current-password\": 401,\n \"auth.busy\": 503,\n \"invite.invalid\": 410,\n \"invite.email-taken\": 409,\n \"account.not-found\": 404,\n \"account.last-admin\": 409,\n \"account.self\": 409,\n \"account.last-factor\": 409,\n \"role.forbidden\": 403,\n \"csrf.invalid\": 403,\n \"passkey.unavailable\": 501,\n \"passkey.failed\": 401,\n \"explain.not-allowed\": 403,\n \"explain.unsupported\": 400,\n \"explain.elsewhere\": 409,\n \"explain.failed\": 502,\n \"request.not-found\": 404,\n \"request.invalid-filter\": 400,\n \"stream.too-many\": 429,\n \"input.invalid\": 422,\n \"server.error\": 500,\n};\n\n/** A short reference id (8 characters, base32 alphabet) to quote to support. */\nexport function createErrorRef(): string {\n const alphabet = \"ABCDEFGHJKMNPQRSTUVWXYZ23456789\";\n const bytes = randomBytes(8);\n let ref = \"\";\n\n for (const byte of bytes) ref += alphabet[byte % alphabet.length];\n\n return ref;\n}\n\n/**\n * An error a dashboard route answers with. The production error handler turns\n * it into `{ error, code, ref?, instance? }` with `statusCode`.\n */\nexport class DevtoolsApiError extends Error {\n public readonly code: DevtoolsErrorCode;\n public readonly statusCode: number;\n public readonly ref: string | undefined;\n public readonly instance: string | undefined;\n\n public constructor(\n code: DevtoolsErrorCode,\n options: { ref?: string; instance?: string; cause?: unknown } = {},\n ) {\n super(\n DEVTOOLS_ERROR_MESSAGES[code],\n options.cause === undefined ? {} : { cause: options.cause },\n );\n this.name = \"DevtoolsApiError\";\n this.code = code;\n this.statusCode = DEVTOOLS_ERROR_STATUS[code];\n this.ref = options.ref;\n this.instance = options.instance;\n }\n\n /** The JSON body this error answers with. */\n public toBody(): DevtoolsApiErrorBody {\n return {\n error: this.message,\n code: this.code,\n ...(this.ref === undefined ? {} : { ref: this.ref }),\n ...(this.instance === undefined ? {} : { instance: this.instance }),\n };\n }\n}\n\n/**\n * Raised by a store when a unique value is taken (an email) so callers can\n * answer with their own error code.\n */\nexport class DevtoolsStoreConflictError extends Error {\n public constructor(public readonly field: string) {\n super(`A devtools record with this ${field} already exists.`);\n this.name = \"DevtoolsStoreConflictError\";\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB;CACnC,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OAAO;CACP,OACE;AACJ;;;;;;;AAWA,IAAa,gCAAb,cAAmD,MAAM;CAGvD,AAAO,YAAY,MAA0B,QAAiB;EAC5D,MAAM,IAAI,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,KAAK,sBAAsB,OAAO;EAC7E,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;AAGA,MAAa,0BAA6D;CACxE,4BACE;CACF,qBACE;CACF,4BACE;CACF,2BAA2B;CAC3B,0BAA0B;CAC1B,wBAAwB;CACxB,+BAA+B;CAC/B,2BAA2B;CAC3B,+BAA+B;CAC/B,aAAa;CACb,kBACE;CACF,sBAAsB;CACtB,qBAAqB;CACrB,sBAAsB;CACtB,gBAAgB;CAChB,uBACE;CACF,kBAAkB;CAClB,gBAAgB;CAChB,uBACE;CACF,kBAAkB;CAClB,uBAAuB;CACvB,uBACE;CACF,qBACE;CACF,kBACE;CACF,qBACE;CACF,0BAA0B;CAC1B,mBACE;CACF,iBAAiB;CACjB,gBACE;AACJ;;AAGA,MAAa,wBAA2D;CACtE,4BAA4B;CAC5B,qBAAqB;CACrB,4BAA4B;CAC5B,2BAA2B;CAC3B,0BAA0B;CAC1B,wBAAwB;CACxB,+BAA+B;CAC/B,2BAA2B;CAC3B,+BAA+B;CAC/B,aAAa;CACb,kBAAkB;CAClB,sBAAsB;CACtB,qBAAqB;CACrB,sBAAsB;CACtB,gBAAgB;CAChB,uBAAuB;CACvB,kBAAkB;CAClB,gBAAgB;CAChB,uBAAuB;CACvB,kBAAkB;CAClB,uBAAuB;CACvB,uBAAuB;CACvB,qBAAqB;CACrB,kBAAkB;CAClB,qBAAqB;CACrB,0BAA0B;CAC1B,mBAAmB;CACnB,iBAAiB;CACjB,gBAAgB;AAClB;;AAGA,SAAgB,iBAAyB;CACvC,MAAM,WAAW;CACjB,MAAM,YAAQA,yBAAY,CAAC;CAC3B,IAAI,MAAM;CAEV,KAAK,MAAM,QAAQ,OAAO,OAAO,SAAS,OAAO;CAEjD,OAAO;AACT;;;;;AAMA,IAAa,mBAAb,cAAsC,MAAM;CAM1C,AAAO,YACL,MACA,UAAgE,CAAC,GACjE;EACA,MACE,wBAAwB,OACxB,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM,CAC5D;EACA,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa,sBAAsB;EACxC,KAAK,MAAM,QAAQ;EACnB,KAAK,WAAW,QAAQ;CAC1B;;CAGA,AAAO,SAA+B;EACpC,OAAO;GACL,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,GAAI,KAAK,QAAQ,SAAY,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI;GAClD,GAAI,KAAK,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;EACnE;CACF;AACF;;;;;AAMA,IAAa,6BAAb,cAAgD,MAAM;CACpD,AAAO,YAAY,AAAgB,OAAe;EAChD,MAAM,+BAA+B,MAAM,iBAAiB;EAD3B;EAEjC,KAAK,OAAO;CACd;AACF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_contracts = require("./contracts-CVmplkNb.cjs");
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/devtools/src/production/stats/histogram.ts
|
|
5
|
+
/** An empty histogram over `DEVTOOLS_LATENCY_BUCKETS_MS`. */
|
|
6
|
+
function createHistogram() {
|
|
7
|
+
return {
|
|
8
|
+
counts: new Array(require_contracts.DEVTOOLS_LATENCY_BUCKETS_MS.length + 1).fill(0),
|
|
9
|
+
count: 0,
|
|
10
|
+
sumMs: 0,
|
|
11
|
+
maxMs: 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** The bucket index a duration falls in. */
|
|
15
|
+
function bucketIndex(durationMs) {
|
|
16
|
+
for (let index = 0; index < require_contracts.DEVTOOLS_LATENCY_BUCKETS_MS.length; index++) if (durationMs <= require_contracts.DEVTOOLS_LATENCY_BUCKETS_MS[index]) return index;
|
|
17
|
+
return require_contracts.DEVTOOLS_LATENCY_BUCKETS_MS.length;
|
|
18
|
+
}
|
|
19
|
+
/** Adds one duration to `histogram` in place. A negative or non-finite value counts as 0. */
|
|
20
|
+
function recordDuration(histogram, durationMs) {
|
|
21
|
+
const value = Number.isFinite(durationMs) && durationMs > 0 ? durationMs : 0;
|
|
22
|
+
const index = bucketIndex(value);
|
|
23
|
+
histogram.counts[index] = (histogram.counts[index] ?? 0) + 1;
|
|
24
|
+
histogram.count += 1;
|
|
25
|
+
histogram.sumMs += value;
|
|
26
|
+
if (value > histogram.maxMs) histogram.maxMs = value;
|
|
27
|
+
}
|
|
28
|
+
/** The sum of several histograms (exact: they share the bucket bounds). */
|
|
29
|
+
function mergeHistograms(histograms) {
|
|
30
|
+
const merged = createHistogram();
|
|
31
|
+
for (const histogram of histograms) {
|
|
32
|
+
for (let index = 0; index < merged.counts.length; index++) merged.counts[index] = (merged.counts[index] ?? 0) + (histogram.counts[index] ?? 0);
|
|
33
|
+
merged.count += histogram.count;
|
|
34
|
+
merged.sumMs += histogram.sumMs;
|
|
35
|
+
if (histogram.maxMs > merged.maxMs) merged.maxMs = histogram.maxMs;
|
|
36
|
+
}
|
|
37
|
+
return merged;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The `q` quantile (0–1) of a histogram: the upper bound of the bucket that
|
|
41
|
+
* holds it, capped at the largest value seen. 0 for an empty histogram.
|
|
42
|
+
*/
|
|
43
|
+
function histogramQuantile(histogram, q) {
|
|
44
|
+
if (histogram.count === 0) return 0;
|
|
45
|
+
const rank = Math.max(1, Math.ceil(Math.min(Math.max(q, 0), 1) * histogram.count));
|
|
46
|
+
let seen = 0;
|
|
47
|
+
for (let index = 0; index < histogram.counts.length; index++) {
|
|
48
|
+
seen += histogram.counts[index] ?? 0;
|
|
49
|
+
if (seen >= rank) {
|
|
50
|
+
const bound = require_contracts.DEVTOOLS_LATENCY_BUCKETS_MS[index];
|
|
51
|
+
return bound === void 0 ? histogram.maxMs : Math.min(bound, histogram.maxMs);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return histogram.maxMs;
|
|
55
|
+
}
|
|
56
|
+
/** The mean duration, 0 for an empty histogram. */
|
|
57
|
+
function histogramMean(histogram) {
|
|
58
|
+
return histogram.count === 0 ? 0 : histogram.sumMs / histogram.count;
|
|
59
|
+
}
|
|
60
|
+
/** The first 16 hex characters of SHA-256: the id of a query shape or an error fingerprint. */
|
|
61
|
+
function shortId(value) {
|
|
62
|
+
return (0, node_crypto.createHash)("sha256").update(value).digest("hex").slice(0, 16);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
Object.defineProperty(exports, "createHistogram", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return createHistogram;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "histogramMean", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return histogramMean;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "histogramQuantile", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return histogramQuantile;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "mergeHistograms", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return mergeHistograms;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "recordDuration", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return recordDuration;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "shortId", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return shortId;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=histogram-BaI-PnCv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"histogram-BaI-PnCv.cjs","names":["DEVTOOLS_LATENCY_BUCKETS_MS","createHash"],"sources":["../../../../../../../packages/devtools/src/production/stats/histogram.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { DEVTOOLS_LATENCY_BUCKETS_MS, type DevtoolsHistogram } from \"../contracts\";\n\n/** An empty histogram over `DEVTOOLS_LATENCY_BUCKETS_MS`. */\nexport function createHistogram(): DevtoolsHistogram {\n return {\n counts: new Array<number>(DEVTOOLS_LATENCY_BUCKETS_MS.length + 1).fill(0),\n count: 0,\n sumMs: 0,\n maxMs: 0,\n };\n}\n\n/** The bucket index a duration falls in. */\nexport function bucketIndex(durationMs: number): number {\n for (let index = 0; index < DEVTOOLS_LATENCY_BUCKETS_MS.length; index++) {\n if (durationMs <= (DEVTOOLS_LATENCY_BUCKETS_MS[index] as number)) return index;\n }\n\n return DEVTOOLS_LATENCY_BUCKETS_MS.length;\n}\n\n/** Adds one duration to `histogram` in place. A negative or non-finite value counts as 0. */\nexport function recordDuration(histogram: DevtoolsHistogram, durationMs: number): void {\n const value = Number.isFinite(durationMs) && durationMs > 0 ? durationMs : 0;\n const index = bucketIndex(value);\n\n histogram.counts[index] = (histogram.counts[index] ?? 0) + 1;\n histogram.count += 1;\n histogram.sumMs += value;\n\n if (value > histogram.maxMs) histogram.maxMs = value;\n}\n\n/** The sum of several histograms (exact: they share the bucket bounds). */\nexport function mergeHistograms(histograms: readonly DevtoolsHistogram[]): DevtoolsHistogram {\n const merged = createHistogram();\n\n for (const histogram of histograms) {\n for (let index = 0; index < merged.counts.length; index++) {\n merged.counts[index] = (merged.counts[index] ?? 0) + (histogram.counts[index] ?? 0);\n }\n\n merged.count += histogram.count;\n merged.sumMs += histogram.sumMs;\n\n if (histogram.maxMs > merged.maxMs) merged.maxMs = histogram.maxMs;\n }\n\n return merged;\n}\n\n/**\n * The `q` quantile (0–1) of a histogram: the upper bound of the bucket that\n * holds it, capped at the largest value seen. 0 for an empty histogram.\n */\nexport function histogramQuantile(histogram: DevtoolsHistogram, q: number): number {\n if (histogram.count === 0) return 0;\n\n const rank = Math.max(1, Math.ceil(Math.min(Math.max(q, 0), 1) * histogram.count));\n let seen = 0;\n\n for (let index = 0; index < histogram.counts.length; index++) {\n seen += histogram.counts[index] ?? 0;\n\n if (seen >= rank) {\n const bound = DEVTOOLS_LATENCY_BUCKETS_MS[index];\n\n return bound === undefined ? histogram.maxMs : Math.min(bound, histogram.maxMs);\n }\n }\n\n return histogram.maxMs;\n}\n\n/** The mean duration, 0 for an empty histogram. */\nexport function histogramMean(histogram: DevtoolsHistogram): number {\n return histogram.count === 0 ? 0 : histogram.sumMs / histogram.count;\n}\n\n/** The first 16 hex characters of SHA-256: the id of a query shape or an error fingerprint. */\nexport function shortId(value: string): string {\n return createHash(\"sha256\").update(value).digest(\"hex\").slice(0, 16);\n}\n"],"mappings":";;;;;AAIA,SAAgB,kBAAqC;CACnD,OAAO;EACL,QAAQ,IAAI,MAAcA,8CAA4B,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;EACxE,OAAO;EACP,OAAO;EACP,OAAO;CACT;AACF;;AAGA,SAAgB,YAAY,YAA4B;CACtD,KAAK,IAAI,QAAQ,GAAG,QAAQA,8CAA4B,QAAQ,SAC9D,IAAI,cAAeA,8CAA4B,QAAmB,OAAO;CAG3E,OAAOA,8CAA4B;AACrC;;AAGA,SAAgB,eAAe,WAA8B,YAA0B;CACrF,MAAM,QAAQ,OAAO,SAAS,UAAU,KAAK,aAAa,IAAI,aAAa;CAC3E,MAAM,QAAQ,YAAY,KAAK;CAE/B,UAAU,OAAO,UAAU,UAAU,OAAO,UAAU,KAAK;CAC3D,UAAU,SAAS;CACnB,UAAU,SAAS;CAEnB,IAAI,QAAQ,UAAU,OAAO,UAAU,QAAQ;AACjD;;AAGA,SAAgB,gBAAgB,YAA6D;CAC3F,MAAM,SAAS,gBAAgB;CAE/B,KAAK,MAAM,aAAa,YAAY;EAClC,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,OAAO,QAAQ,SAChD,OAAO,OAAO,UAAU,OAAO,OAAO,UAAU,MAAM,UAAU,OAAO,UAAU;EAGnF,OAAO,SAAS,UAAU;EAC1B,OAAO,SAAS,UAAU;EAE1B,IAAI,UAAU,QAAQ,OAAO,OAAO,OAAO,QAAQ,UAAU;CAC/D;CAEA,OAAO;AACT;;;;;AAMA,SAAgB,kBAAkB,WAA8B,GAAmB;CACjF,IAAI,UAAU,UAAU,GAAG,OAAO;CAElC,MAAM,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,UAAU,KAAK,CAAC;CACjF,IAAI,OAAO;CAEX,KAAK,IAAI,QAAQ,GAAG,QAAQ,UAAU,OAAO,QAAQ,SAAS;EAC5D,QAAQ,UAAU,OAAO,UAAU;EAEnC,IAAI,QAAQ,MAAM;GAChB,MAAM,QAAQA,8CAA4B;GAE1C,OAAO,UAAU,SAAY,UAAU,QAAQ,KAAK,IAAI,OAAO,UAAU,KAAK;EAChF;CACF;CAEA,OAAO,UAAU;AACnB;;AAGA,SAAgB,cAAc,WAAsC;CAClE,OAAO,UAAU,UAAU,IAAI,IAAI,UAAU,QAAQ,UAAU;AACjE;;AAGA,SAAgB,QAAQ,OAAuB;CAC7C,WAAOC,wBAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE;AACrE"}
|