@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 @@
|
|
|
1
|
+
{"version":3,"file":"histogram.mjs","names":[],"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,MAAc,4BAA4B,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;EACxE,OAAO;EACP,OAAO;EACP,OAAO;CACT;AACF;;AAGA,SAAgB,YAAY,YAA4B;CACtD,KAAK,IAAI,QAAQ,GAAG,QAAQ,4BAA4B,QAAQ,SAC9D,IAAI,cAAe,4BAA4B,QAAmB,OAAO;CAG3E,OAAO,4BAA4B;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,QAAQ,4BAA4B;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,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE;AACrE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { mergeHistograms } from "./histogram.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/devtools/src/production/stats/merge.ts
|
|
4
|
+
/** The later of two "slowest" records. */
|
|
5
|
+
function slower(a, b) {
|
|
6
|
+
if (a === null) return b;
|
|
7
|
+
if (b === null) return a;
|
|
8
|
+
return b.durationMs > a.durationMs ? b : a;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Merges the query statistics several instances reported: one row per shape
|
|
12
|
+
* id, counts and histograms summed, the slowest example kept, `instances`
|
|
13
|
+
* listing who reported it. Order: highest total time first.
|
|
14
|
+
*/
|
|
15
|
+
function mergeQueryShapeStats(reports) {
|
|
16
|
+
const merged = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const { instance, shapes } of reports) for (const shape of shapes) {
|
|
18
|
+
const current = merged.get(shape.id);
|
|
19
|
+
if (!current) {
|
|
20
|
+
merged.set(shape.id, {
|
|
21
|
+
...structuredClone(shape),
|
|
22
|
+
instances: [instance]
|
|
23
|
+
});
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
current.count += shape.count;
|
|
27
|
+
current.errors += shape.errors;
|
|
28
|
+
current.histogram = mergeHistograms([current.histogram, shape.histogram]);
|
|
29
|
+
current.nPlusOne = {
|
|
30
|
+
requests: current.nPlusOne.requests + shape.nPlusOne.requests,
|
|
31
|
+
maxPerRequest: Math.max(current.nPlusOne.maxPerRequest, shape.nPlusOne.maxPerRequest)
|
|
32
|
+
};
|
|
33
|
+
current.slowest = slower(current.slowest, shape.slowest);
|
|
34
|
+
current.firstSeen = Math.min(current.firstSeen, shape.firstSeen);
|
|
35
|
+
current.lastSeen = Math.max(current.lastSeen, shape.lastSeen);
|
|
36
|
+
current.explainable = current.explainable || shape.explainable;
|
|
37
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
38
|
+
}
|
|
39
|
+
return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);
|
|
40
|
+
}
|
|
41
|
+
/** Merges phase lists by name (counts and sums added, max kept), slowest total first, at most 30. */
|
|
42
|
+
function mergePhases(lists) {
|
|
43
|
+
const merged = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const list of lists) for (const phase of list) {
|
|
45
|
+
const current = merged.get(phase.name);
|
|
46
|
+
if (!current) {
|
|
47
|
+
merged.set(phase.name, { ...phase });
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
current.count += phase.count;
|
|
51
|
+
current.sumMs += phase.sumMs;
|
|
52
|
+
current.maxMs = Math.max(current.maxMs, phase.maxMs);
|
|
53
|
+
}
|
|
54
|
+
return [...merged.values()].sort((a, b) => b.sumMs - a.sumMs).slice(0, 30);
|
|
55
|
+
}
|
|
56
|
+
/** Merges route statistics by key, like `mergeQueryShapeStats`. */
|
|
57
|
+
function mergeRouteStats(reports) {
|
|
58
|
+
const merged = /* @__PURE__ */ new Map();
|
|
59
|
+
for (const { instance, routes } of reports) for (const route of routes) {
|
|
60
|
+
const current = merged.get(route.key);
|
|
61
|
+
if (!current) {
|
|
62
|
+
merged.set(route.key, {
|
|
63
|
+
...structuredClone(route),
|
|
64
|
+
instances: [instance]
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
current.count += route.count;
|
|
69
|
+
current.errors += route.errors;
|
|
70
|
+
current.histogram = mergeHistograms([current.histogram, route.histogram]);
|
|
71
|
+
current.phases = mergePhases([current.phases, route.phases]);
|
|
72
|
+
current.slowest = slower(current.slowest, route.slowest);
|
|
73
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
74
|
+
}
|
|
75
|
+
return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);
|
|
76
|
+
}
|
|
77
|
+
/** Merges error groups by id: counts added, the newest message/stack kept. Newest first. */
|
|
78
|
+
function mergeErrorGroups(reports) {
|
|
79
|
+
const merged = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const { instance, errors } of reports) for (const group of errors) {
|
|
81
|
+
const current = merged.get(group.id);
|
|
82
|
+
if (!current) {
|
|
83
|
+
merged.set(group.id, {
|
|
84
|
+
...structuredClone(group),
|
|
85
|
+
instances: [instance]
|
|
86
|
+
});
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const newer = group.lastSeen > current.lastSeen;
|
|
90
|
+
current.count += group.count;
|
|
91
|
+
current.firstSeen = Math.min(current.firstSeen, group.firstSeen);
|
|
92
|
+
if (newer) {
|
|
93
|
+
current.lastSeen = group.lastSeen;
|
|
94
|
+
current.message = group.message;
|
|
95
|
+
current.stack = group.stack;
|
|
96
|
+
current.status = group.status;
|
|
97
|
+
current.lastRequestId = group.lastRequestId;
|
|
98
|
+
}
|
|
99
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
100
|
+
}
|
|
101
|
+
return [...merged.values()].sort((a, b) => b.lastSeen - a.lastSeen);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { mergeErrorGroups, mergeQueryShapeStats, mergeRouteStats };
|
|
106
|
+
//# sourceMappingURL=merge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/stats/merge.ts"],"sourcesContent":["import type {\n DevtoolsErrorGroup,\n DevtoolsQueryShapeStats,\n DevtoolsRoutePhaseStats,\n DevtoolsRouteStats,\n} from \"../contracts\";\nimport { mergeHistograms } from \"./histogram\";\n\n/** The later of two \"slowest\" records. */\nfunction slower<T extends { durationMs: number }>(a: T | null, b: T | null): T | null {\n if (a === null) return b;\n if (b === null) return a;\n\n return b.durationMs > a.durationMs ? b : a;\n}\n\n/**\n * Merges the query statistics several instances reported: one row per shape\n * id, counts and histograms summed, the slowest example kept, `instances`\n * listing who reported it. Order: highest total time first.\n */\nexport function mergeQueryShapeStats(\n reports: readonly { instance: string; shapes: readonly DevtoolsQueryShapeStats[] }[],\n): (DevtoolsQueryShapeStats & { instances: string[] })[] {\n const merged = new Map<string, DevtoolsQueryShapeStats & { instances: string[] }>();\n\n for (const { instance, shapes } of reports) {\n for (const shape of shapes) {\n const current = merged.get(shape.id);\n\n if (!current) {\n merged.set(shape.id, { ...structuredClone(shape), instances: [instance] });\n continue;\n }\n\n current.count += shape.count;\n current.errors += shape.errors;\n current.histogram = mergeHistograms([current.histogram, shape.histogram]);\n current.nPlusOne = {\n requests: current.nPlusOne.requests + shape.nPlusOne.requests,\n maxPerRequest: Math.max(current.nPlusOne.maxPerRequest, shape.nPlusOne.maxPerRequest),\n };\n current.slowest = slower(current.slowest, shape.slowest);\n current.firstSeen = Math.min(current.firstSeen, shape.firstSeen);\n current.lastSeen = Math.max(current.lastSeen, shape.lastSeen);\n current.explainable = current.explainable || shape.explainable;\n\n if (!current.instances.includes(instance)) current.instances.push(instance);\n }\n }\n\n return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);\n}\n\n/** Merges phase lists by name (counts and sums added, max kept), slowest total first, at most 30. */\nfunction mergePhases(\n lists: readonly (readonly DevtoolsRoutePhaseStats[])[],\n): DevtoolsRoutePhaseStats[] {\n const merged = new Map<string, DevtoolsRoutePhaseStats>();\n\n for (const list of lists) {\n for (const phase of list) {\n const current = merged.get(phase.name);\n\n if (!current) {\n merged.set(phase.name, { ...phase });\n continue;\n }\n\n current.count += phase.count;\n current.sumMs += phase.sumMs;\n current.maxMs = Math.max(current.maxMs, phase.maxMs);\n }\n }\n\n return [...merged.values()].sort((a, b) => b.sumMs - a.sumMs).slice(0, 30);\n}\n\n/** Merges route statistics by key, like `mergeQueryShapeStats`. */\nexport function mergeRouteStats(\n reports: readonly { instance: string; routes: readonly DevtoolsRouteStats[] }[],\n): (DevtoolsRouteStats & { instances: string[] })[] {\n const merged = new Map<string, DevtoolsRouteStats & { instances: string[] }>();\n\n for (const { instance, routes } of reports) {\n for (const route of routes) {\n const current = merged.get(route.key);\n\n if (!current) {\n merged.set(route.key, { ...structuredClone(route), instances: [instance] });\n continue;\n }\n\n current.count += route.count;\n current.errors += route.errors;\n current.histogram = mergeHistograms([current.histogram, route.histogram]);\n current.phases = mergePhases([current.phases, route.phases]);\n current.slowest = slower(current.slowest, route.slowest);\n\n if (!current.instances.includes(instance)) current.instances.push(instance);\n }\n }\n\n return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);\n}\n\n/** Merges error groups by id: counts added, the newest message/stack kept. Newest first. */\nexport function mergeErrorGroups(\n reports: readonly { instance: string; errors: readonly DevtoolsErrorGroup[] }[],\n): (DevtoolsErrorGroup & { instances: string[] })[] {\n const merged = new Map<string, DevtoolsErrorGroup & { instances: string[] }>();\n\n for (const { instance, errors } of reports) {\n for (const group of errors) {\n const current = merged.get(group.id);\n\n if (!current) {\n merged.set(group.id, { ...structuredClone(group), instances: [instance] });\n continue;\n }\n\n const newer = group.lastSeen > current.lastSeen;\n\n current.count += group.count;\n current.firstSeen = Math.min(current.firstSeen, group.firstSeen);\n\n if (newer) {\n current.lastSeen = group.lastSeen;\n current.message = group.message;\n current.stack = group.stack;\n current.status = group.status;\n current.lastRequestId = group.lastRequestId;\n }\n\n if (!current.instances.includes(instance)) current.instances.push(instance);\n }\n }\n\n return [...merged.values()].sort((a, b) => b.lastSeen - a.lastSeen);\n}\n"],"mappings":";;;;AASA,SAAS,OAAyC,GAAa,GAAuB;CACpF,IAAI,MAAM,MAAM,OAAO;CACvB,IAAI,MAAM,MAAM,OAAO;CAEvB,OAAO,EAAE,aAAa,EAAE,aAAa,IAAI;AAC3C;;;;;;AAOA,SAAgB,qBACd,SACuD;CACvD,MAAM,yBAAS,IAAI,IAA+D;CAElF,KAAK,MAAM,EAAE,UAAU,YAAY,SACjC,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,OAAO,IAAI,MAAM,EAAE;EAEnC,IAAI,CAAC,SAAS;GACZ,OAAO,IAAI,MAAM,IAAI;IAAE,GAAG,gBAAgB,KAAK;IAAG,WAAW,CAAC,QAAQ;GAAE,CAAC;GACzE;EACF;EAEA,QAAQ,SAAS,MAAM;EACvB,QAAQ,UAAU,MAAM;EACxB,QAAQ,YAAY,gBAAgB,CAAC,QAAQ,WAAW,MAAM,SAAS,CAAC;EACxE,QAAQ,WAAW;GACjB,UAAU,QAAQ,SAAS,WAAW,MAAM,SAAS;GACrD,eAAe,KAAK,IAAI,QAAQ,SAAS,eAAe,MAAM,SAAS,aAAa;EACtF;EACA,QAAQ,UAAU,OAAO,QAAQ,SAAS,MAAM,OAAO;EACvD,QAAQ,YAAY,KAAK,IAAI,QAAQ,WAAW,MAAM,SAAS;EAC/D,QAAQ,WAAW,KAAK,IAAI,QAAQ,UAAU,MAAM,QAAQ;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AAU,OAAO,QAAQ,SAAS,MAAM,OAAO;EAEvD,IAAI,CAAC,QAAQ,UAAU,SAAS,QAAQ,GAAG,QAAQ,UAAU,KAAK,QAAQ;CAC5E;CAGF,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,UAAU,QAAQ,EAAE,UAAU,KAAK;AAClF;;AAGA,SAAgB,iBACd,SACkD;CAClD,MAAM,yBAAS,IAAI,IAA0D;CAE7E,KAAK,MAAM,EAAE,UAAU,YAAY,SACjC,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,OAAO,IAAI,MAAM,EAAE;EAEnC,IAAI,CAAC,SAAS;GACZ,OAAO,IAAI,MAAM,IAAI;IAAE,GAAG,gBAAgB,KAAK;IAAG,WAAW,CAAC,QAAQ;GAAE,CAAC;GACzE;EACF;EAEA,MAAM,QAAQ,MAAM,WAAW,QAAQ;EAEvC,QAAQ,SAAS,MAAM;EACvB,QAAQ,YAAY,KAAK,IAAI,QAAQ,WAAW,MAAM,SAAS;EAE/D,IAAI,OAAO;GACT,QAAQ,WAAW,MAAM;GACzB,QAAQ,UAAU,MAAM;GACxB,QAAQ,QAAQ,MAAM;GACtB,QAAQ,SAAS,MAAM;GACvB,QAAQ,gBAAgB,MAAM;EAChC;EAEA,IAAI,CAAC,QAAQ,UAAU,SAAS,QAAQ,GAAG,QAAQ,UAAU,KAAK,QAAQ;CAC5E;CAGF,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ;AACpE"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { DevtoolsProductionConfigError, DevtoolsStoreConflictError } from "../errors.mjs";
|
|
2
|
+
import { rateLimitClient } from "../http/ip.mjs";
|
|
3
|
+
import { accountPatchToRow, accountToRow, auditToRow, inviteToRow, reportToRow, rowToAccount, rowToAudit, rowToInvite, rowToReport, rowToSample, rowToSampleSummary, rowToSession, rowToState, sampleToRow, sessionPatchToRow, sessionToRow, statePatchToRow, stateToRow } from "./mapping.mjs";
|
|
4
|
+
import { defaultStateRecord, sampleMatches } from "./memory-store.mjs";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
//#region ../../packages/devtools/src/production/store/cascade-store.ts
|
|
8
|
+
/** The most rows scanned for a sample filter the database cannot apply (route, text). */
|
|
9
|
+
const SAMPLE_SCAN_LIMIT = 5e3;
|
|
10
|
+
/** A plain-row query (no model instances). */
|
|
11
|
+
function rows(table) {
|
|
12
|
+
return table.query().lean();
|
|
13
|
+
}
|
|
14
|
+
/** A query for counting and deleting. */
|
|
15
|
+
function query(table) {
|
|
16
|
+
return table.query();
|
|
17
|
+
}
|
|
18
|
+
function byId(table, id) {
|
|
19
|
+
return rows(table).where("id", "=", id).first();
|
|
20
|
+
}
|
|
21
|
+
async function insert(table, row) {
|
|
22
|
+
await table.create(row);
|
|
23
|
+
}
|
|
24
|
+
async function removeWhere(table, field, value) {
|
|
25
|
+
return await query(table).where(field, "=", value).delete() > 0;
|
|
26
|
+
}
|
|
27
|
+
/** Applies `$set` to the row only while its `version` still equals `expected`. */
|
|
28
|
+
async function compareAndSet(table, id, expected, set) {
|
|
29
|
+
return await table.atomic({
|
|
30
|
+
id,
|
|
31
|
+
version: expected
|
|
32
|
+
}, { $set: set }) > 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The production `DevtoolsStore`: the app's database through
|
|
36
|
+
* `@warlock.js/cascade` (MongoDB or SQL), using the models in `./models` and
|
|
37
|
+
* the tables `devtoolsMigrations` creates. Imports cascade lazily so loading
|
|
38
|
+
* this module never requires it.
|
|
39
|
+
*
|
|
40
|
+
* Throws `DevtoolsProductionConfigError("DT005")` when cascade is not
|
|
41
|
+
* installed or has no connection.
|
|
42
|
+
*/
|
|
43
|
+
async function createCascadeStore(options = {}) {
|
|
44
|
+
const now = options.now ?? Date.now;
|
|
45
|
+
let models;
|
|
46
|
+
try {
|
|
47
|
+
models = await import("./models/index.mjs");
|
|
48
|
+
models.DevtoolsAccountRow.getDataSource();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new DevtoolsProductionConfigError("DT005", error instanceof Error ? `(${error.message})` : void 0);
|
|
51
|
+
}
|
|
52
|
+
const { DevtoolsAccountRow: Accounts, DevtoolsSessionRow: Sessions, DevtoolsInviteRow: Invites, DevtoolsAuditRow: Audit, DevtoolsStateRow: State, DevtoolsSampleRow: Samples, DevtoolsReportRow: Reports } = models;
|
|
53
|
+
const tables = [
|
|
54
|
+
Accounts,
|
|
55
|
+
Sessions,
|
|
56
|
+
Invites,
|
|
57
|
+
Audit,
|
|
58
|
+
State,
|
|
59
|
+
Samples,
|
|
60
|
+
Reports
|
|
61
|
+
];
|
|
62
|
+
const accountById = async (id) => {
|
|
63
|
+
const row = await byId(Accounts, id);
|
|
64
|
+
return row ? rowToAccount(row) : null;
|
|
65
|
+
};
|
|
66
|
+
const sessionById = async (id) => {
|
|
67
|
+
const row = await byId(Sessions, id);
|
|
68
|
+
return row ? rowToSession(row) : null;
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
async verify() {
|
|
72
|
+
const blueprint = Accounts.getDriver().blueprint;
|
|
73
|
+
const missing = [];
|
|
74
|
+
for (const table of tables) if (!await blueprint.tableExists(table.table)) missing.push(table.table);
|
|
75
|
+
if (missing.length > 0) throw new DevtoolsProductionConfigError("DT008", `(missing: ${missing.join(", ")})`);
|
|
76
|
+
},
|
|
77
|
+
accounts: {
|
|
78
|
+
async findByEmail(email) {
|
|
79
|
+
const row = await rows(Accounts).where("email", "=", email).first();
|
|
80
|
+
return row ? rowToAccount(row) : null;
|
|
81
|
+
},
|
|
82
|
+
findById: accountById,
|
|
83
|
+
async list() {
|
|
84
|
+
return (await rows(Accounts).orderBy("created_at", "asc").get()).map(rowToAccount);
|
|
85
|
+
},
|
|
86
|
+
async countAdmins() {
|
|
87
|
+
return query(Accounts).where("role", "=", "admin").count();
|
|
88
|
+
},
|
|
89
|
+
async create(input) {
|
|
90
|
+
const at = now();
|
|
91
|
+
const record = {
|
|
92
|
+
...structuredClone(input),
|
|
93
|
+
id: randomUUID(),
|
|
94
|
+
createdAt: at,
|
|
95
|
+
updatedAt: at,
|
|
96
|
+
version: 1
|
|
97
|
+
};
|
|
98
|
+
if (await rows(Accounts).where("email", "=", record.email).first()) throw new DevtoolsStoreConflictError("email");
|
|
99
|
+
try {
|
|
100
|
+
await insert(Accounts, accountToRow(record));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (await rows(Accounts).where("email", "=", record.email).first()) throw new DevtoolsStoreConflictError("email");
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
return record;
|
|
106
|
+
},
|
|
107
|
+
async update(id, expectedVersion, patch) {
|
|
108
|
+
const current = await accountById(id);
|
|
109
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
110
|
+
if (patch.email !== void 0 && patch.email !== current.email) {
|
|
111
|
+
if (await rows(Accounts).where("email", "=", patch.email).first()) throw new DevtoolsStoreConflictError("email");
|
|
112
|
+
}
|
|
113
|
+
const set = {
|
|
114
|
+
...accountPatchToRow(structuredClone(patch)),
|
|
115
|
+
updated_at: now(),
|
|
116
|
+
version: expectedVersion + 1
|
|
117
|
+
};
|
|
118
|
+
let won;
|
|
119
|
+
try {
|
|
120
|
+
won = await compareAndSet(Accounts, id, expectedVersion, set);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (patch.email !== void 0 && await rows(Accounts).where("email", "=", patch.email).first()) throw new DevtoolsStoreConflictError("email");
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
return won ? accountById(id) : null;
|
|
126
|
+
},
|
|
127
|
+
async remove(id) {
|
|
128
|
+
return removeWhere(Accounts, "id", id);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
sessions: {
|
|
132
|
+
async create(input) {
|
|
133
|
+
const record = {
|
|
134
|
+
...structuredClone(input),
|
|
135
|
+
id: randomUUID(),
|
|
136
|
+
version: 1
|
|
137
|
+
};
|
|
138
|
+
await insert(Sessions, sessionToRow(record));
|
|
139
|
+
return record;
|
|
140
|
+
},
|
|
141
|
+
async findByTokenHash(tokenHash) {
|
|
142
|
+
const row = await rows(Sessions).where("token_hash", "=", tokenHash).first();
|
|
143
|
+
return row ? rowToSession(row) : null;
|
|
144
|
+
},
|
|
145
|
+
async listForAccount(accountId) {
|
|
146
|
+
return (await rows(Sessions).where("account_id", "=", accountId).orderBy("created_at", "desc").get()).map(rowToSession);
|
|
147
|
+
},
|
|
148
|
+
async update(id, expectedVersion, patch) {
|
|
149
|
+
const set = {
|
|
150
|
+
...sessionPatchToRow(structuredClone(patch)),
|
|
151
|
+
version: expectedVersion + 1
|
|
152
|
+
};
|
|
153
|
+
if (!await compareAndSet(Sessions, id, expectedVersion, set)) return null;
|
|
154
|
+
return sessionById(id);
|
|
155
|
+
},
|
|
156
|
+
async remove(id) {
|
|
157
|
+
return removeWhere(Sessions, "id", id);
|
|
158
|
+
},
|
|
159
|
+
async removeForAccount(accountId, exceptId) {
|
|
160
|
+
const target = query(Sessions).where("account_id", "=", accountId);
|
|
161
|
+
if (exceptId !== void 0) target.where("id", "!=", exceptId);
|
|
162
|
+
return target.delete();
|
|
163
|
+
},
|
|
164
|
+
async removeExpired(at) {
|
|
165
|
+
return query(Sessions).where("expires_at", "<", at).delete();
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
invites: {
|
|
169
|
+
async create(input) {
|
|
170
|
+
const record = {
|
|
171
|
+
...structuredClone(input),
|
|
172
|
+
id: randomUUID(),
|
|
173
|
+
usedAt: null,
|
|
174
|
+
accountId: null
|
|
175
|
+
};
|
|
176
|
+
await insert(Invites, inviteToRow(record));
|
|
177
|
+
return record;
|
|
178
|
+
},
|
|
179
|
+
async findByTokenHash(tokenHash) {
|
|
180
|
+
const row = await rows(Invites).where("token_hash", "=", tokenHash).first();
|
|
181
|
+
return row ? rowToInvite(row) : null;
|
|
182
|
+
},
|
|
183
|
+
async list(listOptions = {}) {
|
|
184
|
+
const target = rows(Invites);
|
|
185
|
+
if (listOptions.includeUsed !== true) target.whereNull("used_at");
|
|
186
|
+
return (await target.orderBy("created_at", "desc").get()).map(rowToInvite);
|
|
187
|
+
},
|
|
188
|
+
async markUsed(id, at, accountId) {
|
|
189
|
+
return await Invites.atomic({
|
|
190
|
+
id,
|
|
191
|
+
used_at: null,
|
|
192
|
+
expires_at: { $gt: at }
|
|
193
|
+
}, { $set: {
|
|
194
|
+
used_at: at,
|
|
195
|
+
account_id: accountId
|
|
196
|
+
} }, { trustedFilter: true }) > 0;
|
|
197
|
+
},
|
|
198
|
+
async remove(id) {
|
|
199
|
+
return removeWhere(Invites, "id", id);
|
|
200
|
+
},
|
|
201
|
+
async removeExpired(at) {
|
|
202
|
+
return query(Invites).whereNull("used_at").where("expires_at", "<", at).delete();
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
audit: {
|
|
206
|
+
async append(entry) {
|
|
207
|
+
const record = {
|
|
208
|
+
...structuredClone(entry),
|
|
209
|
+
id: randomUUID()
|
|
210
|
+
};
|
|
211
|
+
await insert(Audit, auditToRow(record));
|
|
212
|
+
return record;
|
|
213
|
+
},
|
|
214
|
+
async list(filter) {
|
|
215
|
+
const limit = Math.max(1, Math.min(500, filter.limit));
|
|
216
|
+
const target = rows(Audit);
|
|
217
|
+
if (filter.types !== void 0) target.whereIn("type", [...filter.types]);
|
|
218
|
+
if (filter.accountId !== void 0) target.where("account_id", "=", filter.accountId);
|
|
219
|
+
if (filter.before !== void 0) target.where("occurred_at", "<", filter.before);
|
|
220
|
+
return (await target.orderBy("occurred_at", "desc").limit(limit).get()).map(rowToAudit);
|
|
221
|
+
},
|
|
222
|
+
async count(filter) {
|
|
223
|
+
const target = query(Audit).whereIn("type", [...filter.types]).where("occurred_at", ">=", filter.since);
|
|
224
|
+
if (filter.accountId !== void 0) target.where("account_id", "=", filter.accountId);
|
|
225
|
+
if (filter.ip !== void 0) target.where("ip_bucket", "=", rateLimitClient(filter.ip));
|
|
226
|
+
return target.count();
|
|
227
|
+
},
|
|
228
|
+
async prune(before) {
|
|
229
|
+
return query(Audit).where("occurred_at", "<", before).delete();
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
state: {
|
|
233
|
+
async read() {
|
|
234
|
+
const row = await byId(State, "state");
|
|
235
|
+
return row ? rowToState(row) : defaultStateRecord(now());
|
|
236
|
+
},
|
|
237
|
+
async update(expectedVersion, patch) {
|
|
238
|
+
if (!await byId(State, "state")) {
|
|
239
|
+
if (expectedVersion !== 0) return null;
|
|
240
|
+
const record = {
|
|
241
|
+
...defaultStateRecord(now()),
|
|
242
|
+
...structuredClone(patch),
|
|
243
|
+
updatedAt: now(),
|
|
244
|
+
version: 1
|
|
245
|
+
};
|
|
246
|
+
try {
|
|
247
|
+
await insert(State, {
|
|
248
|
+
id: "state",
|
|
249
|
+
...stateToRow(record)
|
|
250
|
+
});
|
|
251
|
+
} catch {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return record;
|
|
255
|
+
}
|
|
256
|
+
const set = {
|
|
257
|
+
...statePatchToRow(structuredClone(patch)),
|
|
258
|
+
updated_at: now(),
|
|
259
|
+
version: expectedVersion + 1
|
|
260
|
+
};
|
|
261
|
+
if (!await compareAndSet(State, "state", expectedVersion, set)) return null;
|
|
262
|
+
const next = await byId(State, "state");
|
|
263
|
+
return next ? rowToState(next) : null;
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
samples: {
|
|
267
|
+
async insert(list) {
|
|
268
|
+
for (const sample of list) {
|
|
269
|
+
const { id, ...data } = sampleToRow(structuredClone(sample));
|
|
270
|
+
await Samples.upsert({ id }, data);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
async list(filter) {
|
|
274
|
+
const limit = Math.max(1, Math.min(1e3, filter.limit));
|
|
275
|
+
const target = rows(Samples).select(["summary"]);
|
|
276
|
+
const exact = !(filter.route !== void 0 || filter.q !== void 0);
|
|
277
|
+
if (filter.status !== void 0) {
|
|
278
|
+
const status = filter.status.trim().toLowerCase();
|
|
279
|
+
if (/^[1-5]xx$/.test(status)) {
|
|
280
|
+
const base = Number(status[0]) * 100;
|
|
281
|
+
target.where("status", ">=", base).where("status", "<", base + 100);
|
|
282
|
+
} else if (/^\d+$/.test(status) && String(Number(status)) === status) target.where("status", "=", Number(status));
|
|
283
|
+
else return [];
|
|
284
|
+
}
|
|
285
|
+
if (filter.method !== void 0) target.where("method", "=", filter.method.toUpperCase());
|
|
286
|
+
if (filter.since !== void 0) target.where("started_at", ">=", filter.since);
|
|
287
|
+
if (filter.until !== void 0) target.where("started_at", "<=", filter.until);
|
|
288
|
+
if (filter.instance !== void 0) target.where("instance", "=", filter.instance);
|
|
289
|
+
return (await target.orderBy("started_at", "desc").limit(exact ? limit : SAMPLE_SCAN_LIMIT).get()).map(rowToSampleSummary).filter((summary) => sampleMatches(summary, filter)).slice(0, limit);
|
|
290
|
+
},
|
|
291
|
+
async get(id) {
|
|
292
|
+
const row = await byId(Samples, id);
|
|
293
|
+
return row ? rowToSample(row) : null;
|
|
294
|
+
},
|
|
295
|
+
async prune(before) {
|
|
296
|
+
return query(Samples).where("started_at", "<", before).delete();
|
|
297
|
+
},
|
|
298
|
+
async clear() {
|
|
299
|
+
return query(Samples).where("started_at", ">=", 0).delete();
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
reports: {
|
|
303
|
+
async write(report) {
|
|
304
|
+
const { id, ...data } = reportToRow(report);
|
|
305
|
+
await Reports.upsert({ id }, data);
|
|
306
|
+
},
|
|
307
|
+
async list(seenSince) {
|
|
308
|
+
return (await rows(Reports).where("seen_at", ">=", seenSince).orderBy("seen_at", "desc").get()).map(rowToReport);
|
|
309
|
+
},
|
|
310
|
+
async prune(seenBefore) {
|
|
311
|
+
return query(Reports).where("seen_at", "<", seenBefore).delete();
|
|
312
|
+
},
|
|
313
|
+
async remove(instanceId) {
|
|
314
|
+
return removeWhere(Reports, "id", instanceId);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
//#endregion
|
|
321
|
+
export { createCascadeStore };
|
|
322
|
+
//# sourceMappingURL=cascade-store.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cascade-store.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/cascade-store.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { DevtoolsAuditEntry, DevtoolsInstanceReport } from \"../contracts\";\nimport { DevtoolsProductionConfigError, DevtoolsStoreConflictError } from \"../errors\";\nimport { rateLimitClient } from \"../http/ip\";\nimport {\n accountPatchToRow,\n accountToRow,\n auditToRow,\n inviteToRow,\n reportToRow,\n rowToAccount,\n rowToAudit,\n rowToInvite,\n rowToReport,\n rowToSample,\n rowToSampleSummary,\n rowToSession,\n rowToState,\n sampleToRow,\n sessionPatchToRow,\n sessionToRow,\n statePatchToRow,\n stateToRow,\n type Row,\n} from \"./mapping\";\nimport { defaultStateRecord, sampleMatches } from \"./memory-store\";\nimport type {\n DevtoolsAccountRecord,\n DevtoolsInviteRecord,\n DevtoolsSessionRecord,\n DevtoolsStore,\n} from \"./types\";\n\ntype ModelsModule = typeof import(\"./models\");\n\n/** The part of cascade's query builder this store uses. */\ninterface RowQuery {\n where(field: string, operator: string, value: unknown): RowQuery;\n whereIn(field: string, values: unknown[]): RowQuery;\n whereNull(field: string): RowQuery;\n orderBy(field: string, direction: \"asc\" | \"desc\"): RowQuery;\n limit(value: number): RowQuery;\n select(fields: string[]): RowQuery;\n get(): Promise<Row[]>;\n first(): Promise<Row | null>;\n delete(): Promise<number>;\n count(): Promise<number>;\n}\n\n/** The part of a cascade model class this store uses (every table class has this shape). */\ntype RowClass = ModelsModule[\"DevtoolsAccountRow\"];\n\nexport type CascadeStoreOptions = {\n /** The clock for `updatedAt` stamps; defaults to `Date.now`. */\n now?: () => number;\n};\n\n/** The most rows scanned for a sample filter the database cannot apply (route, text). */\nconst SAMPLE_SCAN_LIMIT = 5000;\n\n/** A plain-row query (no model instances). */\nfunction rows(table: RowClass): RowQuery {\n return table.query().lean() as unknown as RowQuery;\n}\n\n/** A query for counting and deleting. */\nfunction query(table: RowClass): RowQuery {\n return table.query() as unknown as RowQuery;\n}\n\nfunction byId(table: RowClass, id: string): Promise<Row | null> {\n return rows(table).where(\"id\", \"=\", id).first();\n}\n\nasync function insert(table: RowClass, row: Row): Promise<void> {\n await table.create(row as never);\n}\n\nasync function removeWhere(table: RowClass, field: string, value: unknown): Promise<boolean> {\n return (await query(table).where(field, \"=\", value).delete()) > 0;\n}\n\n/** Applies `$set` to the row only while its `version` still equals `expected`. */\nasync function compareAndSet(\n table: RowClass,\n id: string,\n expected: number,\n set: Row,\n): Promise<boolean> {\n const updated = await table.atomic({ id, version: expected }, { $set: set });\n\n return updated > 0;\n}\n\n/**\n * The production `DevtoolsStore`: the app's database through\n * `@warlock.js/cascade` (MongoDB or SQL), using the models in `./models` and\n * the tables `devtoolsMigrations` creates. Imports cascade lazily so loading\n * this module never requires it.\n *\n * Throws `DevtoolsProductionConfigError(\"DT005\")` when cascade is not\n * installed or has no connection.\n */\nexport async function createCascadeStore(\n options: CascadeStoreOptions = {},\n): Promise<DevtoolsStore> {\n const now = options.now ?? Date.now;\n let models: ModelsModule;\n\n try {\n models = await import(\"./models\");\n // Throws when the app has no data source.\n models.DevtoolsAccountRow.getDataSource();\n } catch (error) {\n throw new DevtoolsProductionConfigError(\n \"DT005\",\n error instanceof Error ? `(${error.message})` : undefined,\n );\n }\n\n const {\n DevtoolsAccountRow: Accounts,\n DevtoolsSessionRow: Sessions,\n DevtoolsInviteRow: Invites,\n DevtoolsAuditRow: Audit,\n DevtoolsStateRow: State,\n DevtoolsSampleRow: Samples,\n DevtoolsReportRow: Reports,\n } = models;\n const tables: RowClass[] = [Accounts, Sessions, Invites, Audit, State, Samples, Reports];\n\n const accountById = async (id: string): Promise<DevtoolsAccountRecord | null> => {\n const row = await byId(Accounts, id);\n\n return row ? rowToAccount(row) : null;\n };\n const sessionById = async (id: string): Promise<DevtoolsSessionRecord | null> => {\n const row = await byId(Sessions, id);\n\n return row ? rowToSession(row) : null;\n };\n\n return {\n async verify() {\n const blueprint = Accounts.getDriver().blueprint;\n const missing: string[] = [];\n\n for (const table of tables) {\n if (!(await blueprint.tableExists(table.table))) missing.push(table.table);\n }\n\n if (missing.length > 0) {\n throw new DevtoolsProductionConfigError(\"DT008\", `(missing: ${missing.join(\", \")})`);\n }\n },\n\n accounts: {\n async findByEmail(email) {\n const row = await rows(Accounts).where(\"email\", \"=\", email).first();\n\n return row ? rowToAccount(row) : null;\n },\n findById: accountById,\n async list() {\n const found = await rows(Accounts).orderBy(\"created_at\", \"asc\").get();\n\n return found.map(rowToAccount);\n },\n async countAdmins() {\n return query(Accounts).where(\"role\", \"=\", \"admin\").count();\n },\n async create(input) {\n const at = now();\n const record: DevtoolsAccountRecord = {\n ...structuredClone(input),\n id: randomUUID(),\n createdAt: at,\n updatedAt: at,\n version: 1,\n };\n\n if (await rows(Accounts).where(\"email\", \"=\", record.email).first()) {\n throw new DevtoolsStoreConflictError(\"email\");\n }\n\n try {\n await insert(Accounts, accountToRow(record));\n } catch (error) {\n // A concurrent request took the email between the check and the insert.\n if (await rows(Accounts).where(\"email\", \"=\", record.email).first()) {\n throw new DevtoolsStoreConflictError(\"email\");\n }\n\n throw error;\n }\n\n return record;\n },\n async update(id, expectedVersion, patch) {\n const current = await accountById(id);\n\n if (!current || current.version !== expectedVersion) return null;\n\n if (patch.email !== undefined && patch.email !== current.email) {\n if (await rows(Accounts).where(\"email\", \"=\", patch.email).first()) {\n throw new DevtoolsStoreConflictError(\"email\");\n }\n }\n\n const set = {\n ...accountPatchToRow(structuredClone(patch)),\n updated_at: now(),\n version: expectedVersion + 1,\n };\n let won: boolean;\n\n try {\n won = await compareAndSet(Accounts, id, expectedVersion, set);\n } catch (error) {\n if (\n patch.email !== undefined &&\n (await rows(Accounts).where(\"email\", \"=\", patch.email).first())\n ) {\n throw new DevtoolsStoreConflictError(\"email\");\n }\n\n throw error;\n }\n\n return won ? accountById(id) : null;\n },\n async remove(id) {\n return removeWhere(Accounts, \"id\", id);\n },\n },\n\n sessions: {\n async create(input) {\n const record: DevtoolsSessionRecord = {\n ...structuredClone(input),\n id: randomUUID(),\n version: 1,\n };\n\n await insert(Sessions, sessionToRow(record));\n\n return record;\n },\n async findByTokenHash(tokenHash) {\n const row = await rows(Sessions).where(\"token_hash\", \"=\", tokenHash).first();\n\n return row ? rowToSession(row) : null;\n },\n async listForAccount(accountId) {\n const found = await rows(Sessions)\n .where(\"account_id\", \"=\", accountId)\n .orderBy(\"created_at\", \"desc\")\n .get();\n\n return found.map(rowToSession);\n },\n async update(id, expectedVersion, patch) {\n const set = { ...sessionPatchToRow(structuredClone(patch)), version: expectedVersion + 1 };\n\n if (!(await compareAndSet(Sessions, id, expectedVersion, set))) return null;\n\n return sessionById(id);\n },\n async remove(id) {\n return removeWhere(Sessions, \"id\", id);\n },\n async removeForAccount(accountId, exceptId) {\n const target = query(Sessions).where(\"account_id\", \"=\", accountId);\n\n if (exceptId !== undefined) target.where(\"id\", \"!=\", exceptId);\n\n return target.delete();\n },\n async removeExpired(at) {\n return query(Sessions).where(\"expires_at\", \"<\", at).delete();\n },\n },\n\n invites: {\n async create(input) {\n const record: DevtoolsInviteRecord = {\n ...structuredClone(input),\n id: randomUUID(),\n usedAt: null,\n accountId: null,\n };\n\n await insert(Invites, inviteToRow(record));\n\n return record;\n },\n async findByTokenHash(tokenHash) {\n const row = await rows(Invites).where(\"token_hash\", \"=\", tokenHash).first();\n\n return row ? rowToInvite(row) : null;\n },\n async list(listOptions = {}) {\n const target = rows(Invites);\n\n if (listOptions.includeUsed !== true) target.whereNull(\"used_at\");\n\n return (await target.orderBy(\"created_at\", \"desc\").get()).map(rowToInvite);\n },\n async markUsed(id, at, accountId) {\n const updated = await Invites.atomic(\n { id, used_at: null, expires_at: { $gt: at } },\n { $set: { used_at: at, account_id: accountId } },\n // Code-authored filter; nothing here comes from a request.\n { trustedFilter: true },\n );\n\n return updated > 0;\n },\n async remove(id) {\n return removeWhere(Invites, \"id\", id);\n },\n async removeExpired(at) {\n return query(Invites).whereNull(\"used_at\").where(\"expires_at\", \"<\", at).delete();\n },\n },\n\n audit: {\n async append(entry) {\n const record: DevtoolsAuditEntry = { ...structuredClone(entry), id: randomUUID() };\n\n await insert(Audit, auditToRow(record));\n\n return record;\n },\n async list(filter) {\n const limit = Math.max(1, Math.min(500, filter.limit));\n const target = rows(Audit);\n\n if (filter.types !== undefined) target.whereIn(\"type\", [...filter.types]);\n if (filter.accountId !== undefined) target.where(\"account_id\", \"=\", filter.accountId);\n if (filter.before !== undefined) target.where(\"occurred_at\", \"<\", filter.before);\n\n const found = await target.orderBy(\"occurred_at\", \"desc\").limit(limit).get();\n\n return found.map(rowToAudit);\n },\n async count(filter) {\n const target = query(Audit)\n .whereIn(\"type\", [...filter.types])\n .where(\"occurred_at\", \">=\", filter.since);\n\n if (filter.accountId !== undefined) target.where(\"account_id\", \"=\", filter.accountId);\n if (filter.ip !== undefined) target.where(\"ip_bucket\", \"=\", rateLimitClient(filter.ip));\n\n return target.count();\n },\n async prune(before) {\n return query(Audit).where(\"occurred_at\", \"<\", before).delete();\n },\n },\n\n state: {\n async read() {\n const row = await byId(State, \"state\");\n\n return row ? rowToState(row) : defaultStateRecord(now());\n },\n async update(expectedVersion, patch) {\n const row = await byId(State, \"state\");\n\n if (!row) {\n if (expectedVersion !== 0) return null;\n\n const record = {\n ...defaultStateRecord(now()),\n ...structuredClone(patch),\n updatedAt: now(),\n version: 1,\n };\n\n try {\n await insert(State, { id: \"state\", ...stateToRow(record) });\n } catch {\n // Another process wrote the first row; this write lost the race.\n return null;\n }\n\n return record;\n }\n\n const set = {\n ...statePatchToRow(structuredClone(patch)),\n updated_at: now(),\n version: expectedVersion + 1,\n };\n\n if (!(await compareAndSet(State, \"state\", expectedVersion, set))) return null;\n\n const next = await byId(State, \"state\");\n\n return next ? rowToState(next) : null;\n },\n },\n\n samples: {\n async insert(list) {\n for (const sample of list) {\n const { id, ...data } = sampleToRow(structuredClone(sample));\n\n await Samples.upsert({ id } as never, data as never);\n }\n },\n async list(filter) {\n const limit = Math.max(1, Math.min(1000, filter.limit));\n const target = rows(Samples).select([\"summary\"]);\n const exact = !(filter.route !== undefined || filter.q !== undefined);\n\n if (filter.status !== undefined) {\n const status = filter.status.trim().toLowerCase();\n\n if (/^[1-5]xx$/.test(status)) {\n const base = Number(status[0]) * 100;\n\n target.where(\"status\", \">=\", base).where(\"status\", \"<\", base + 100);\n } else if (/^\\d+$/.test(status) && String(Number(status)) === status) {\n target.where(\"status\", \"=\", Number(status));\n } else {\n return [];\n }\n }\n\n if (filter.method !== undefined) target.where(\"method\", \"=\", filter.method.toUpperCase());\n if (filter.since !== undefined) target.where(\"started_at\", \">=\", filter.since);\n if (filter.until !== undefined) target.where(\"started_at\", \"<=\", filter.until);\n if (filter.instance !== undefined) target.where(\"instance\", \"=\", filter.instance);\n\n const found = await target\n .orderBy(\"started_at\", \"desc\")\n .limit(exact ? limit : SAMPLE_SCAN_LIMIT)\n .get();\n\n // Route and text filters are substring matches the databases do not\n // share, so they run here, with the same rules as the memory store.\n return found\n .map(rowToSampleSummary)\n .filter((summary) => sampleMatches(summary, filter))\n .slice(0, limit);\n },\n async get(id) {\n const row = await byId(Samples, id);\n\n return row ? rowToSample(row) : null;\n },\n async prune(before) {\n return query(Samples).where(\"started_at\", \"<\", before).delete();\n },\n async clear() {\n return query(Samples).where(\"started_at\", \">=\", 0).delete();\n },\n },\n\n reports: {\n async write(report: DevtoolsInstanceReport) {\n const { id, ...data } = reportToRow(report);\n\n await Reports.upsert({ id } as never, data as never);\n },\n async list(seenSince) {\n const found = await rows(Reports)\n .where(\"seen_at\", \">=\", seenSince)\n .orderBy(\"seen_at\", \"desc\")\n .get();\n\n return found.map(rowToReport);\n },\n async prune(seenBefore) {\n return query(Reports).where(\"seen_at\", \"<\", seenBefore).delete();\n },\n async remove(instanceId) {\n return removeWhere(Reports, \"id\", instanceId);\n },\n },\n };\n}\n"],"mappings":";;;;;;;;AA0DA,MAAM,oBAAoB;;AAG1B,SAAS,KAAK,OAA2B;CACvC,OAAO,MAAM,MAAM,CAAC,CAAC,KAAK;AAC5B;;AAGA,SAAS,MAAM,OAA2B;CACxC,OAAO,MAAM,MAAM;AACrB;AAEA,SAAS,KAAK,OAAiB,IAAiC;CAC9D,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC,MAAM;AAChD;AAEA,eAAe,OAAO,OAAiB,KAAyB;CAC9D,MAAM,MAAM,OAAO,GAAY;AACjC;AAEA,eAAe,YAAY,OAAiB,OAAe,OAAkC;CAC3F,OAAQ,MAAM,MAAM,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC,OAAO,IAAK;AAClE;;AAGA,eAAe,cACb,OACA,IACA,UACA,KACkB;CAGlB,OAAO,MAFe,MAAM,OAAO;EAAE;EAAI,SAAS;CAAS,GAAG,EAAE,MAAM,IAAI,CAAC,IAE1D;AACnB;;;;;;;;;;AAWA,eAAsB,mBACpB,UAA+B,CAAC,GACR;CACxB,MAAM,MAAM,QAAQ,OAAO,KAAK;CAChC,IAAI;CAEJ,IAAI;EACF,SAAS,MAAM,OAAO;EAEtB,OAAO,mBAAmB,cAAc;CAC1C,SAAS,OAAO;EACd,MAAM,IAAI,8BACR,SACA,iBAAiB,QAAQ,IAAI,MAAM,QAAQ,KAAK,MAClD;CACF;CAEA,MAAM,EACJ,oBAAoB,UACpB,oBAAoB,UACpB,mBAAmB,SACnB,kBAAkB,OAClB,kBAAkB,OAClB,mBAAmB,SACnB,mBAAmB,YACjB;CACJ,MAAM,SAAqB;EAAC;EAAU;EAAU;EAAS;EAAO;EAAO;EAAS;CAAO;CA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AAC,CAAC,CACnD,MAAM,GAAG,KAAK;GACnB;GACA,MAAM,IAAI,IAAI;IACZ,MAAM,MAAM,MAAM,KAAK,SAAS,EAAE;IAElC,OAAO,MAAM,YAAY,GAAG,IAAI;GAClC;GACA,MAAM,MAAM,QAAQ;IAClB,OAAO,MAAM,OAAO,CAAC,CAAC,MAAM,cAAc,KAAK,MAAM,CAAC,CAAC,OAAO;GAChE;GACA,MAAM,QAAQ;IACZ,OAAO,MAAM,OAAO,CAAC,CAAC,MAAM,cAAc,MAAM,CAAC,CAAC,CAAC,OAAO;GAC5D;EACF;EAEA,SAAS;GACP,MAAM,MAAM,QAAgC;IAC1C,MAAM,EAAE,IAAI,GAAG,SAAS,YAAY,MAAM;IAE1C,MAAM,QAAQ,OAAO,EAAE,GAAG,GAAY,IAAa;GACrD;GACA,MAAM,KAAK,WAAW;IAMpB,QAAO,MALa,KAAK,OAAO,CAAC,CAC9B,MAAM,WAAW,MAAM,SAAS,CAAC,CACjC,QAAQ,WAAW,MAAM,CAAC,CAC1B,IAAI,EAEK,CAAC,IAAI,WAAW;GAC9B;GACA,MAAM,MAAM,YAAY;IACtB,OAAO,MAAM,OAAO,CAAC,CAAC,MAAM,WAAW,KAAK,UAAU,CAAC,CAAC,OAAO;GACjE;GACA,MAAM,OAAO,YAAY;IACvB,OAAO,YAAY,SAAS,MAAM,UAAU;GAC9C;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { devtoolsMigrations } from "./migrations.mjs";
|
|
2
|
+
import { createMemoryStore, defaultStateRecord, sampleMatches, sampleStatusMatches } from "./memory-store.mjs";
|
|
3
|
+
import { createCascadeStore } from "./cascade-store.mjs";
|
|
4
|
+
|
|
5
|
+
export { createCascadeStore, createMemoryStore, defaultStateRecord, devtoolsMigrations, sampleMatches, sampleStatusMatches };
|