@hamur/devtools 0.0.0-stage → 0.0.1
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/LICENSE +22 -0
- package/README.md +24 -2
- package/dist/src/client.js +780 -0
- package/dist/src/index.js +1711 -0
- package/dist/types/src/apps/locator.d.ts +3 -0
- package/dist/types/src/bridge.d.ts +8 -0
- package/dist/types/src/client.d.ts +3 -0
- package/dist/types/src/dev/analyze.d.ts +31 -0
- package/dist/types/src/dev/assets.d.ts +33 -0
- package/dist/types/src/dev/authz.d.ts +49 -0
- package/dist/types/src/dev/bundle.d.ts +22 -0
- package/dist/types/src/dev/config.d.ts +24 -0
- package/dist/types/src/dev/handler.d.ts +20 -0
- package/dist/types/src/dev/modules.d.ts +28 -0
- package/dist/types/src/dev/overview.d.ts +20 -0
- package/dist/types/src/dev/processes.d.ts +4 -0
- package/dist/types/src/dev/server-routes.d.ts +7 -0
- package/dist/types/src/dev/tasks.d.ts +26 -0
- package/dist/types/src/dev/timeline.d.ts +20 -0
- package/dist/types/src/dev/virtual.d.ts +9 -0
- package/dist/types/src/icons.d.ts +24 -0
- package/dist/types/src/index.d.ts +8 -0
- package/dist/types/src/locator.d.ts +17 -0
- package/dist/types/src/mask.d.ts +8 -0
- package/dist/types/src/module.d.ts +27 -0
- package/dist/types/src/open-in-editor.d.ts +4 -0
- package/dist/types/src/options.d.ts +14 -0
- package/dist/types/src/panel/document.d.ts +16 -0
- package/dist/types/src/panel/groups.d.ts +14 -0
- package/dist/types/src/panel/index.d.ts +1 -0
- package/dist/types/src/panel/settings.d.ts +69 -0
- package/dist/types/src/panel/style.d.ts +1 -0
- package/dist/types/src/panel/ui.d.ts +34 -0
- package/dist/types/src/server/authz.d.ts +30 -0
- package/dist/types/src/server/index.d.ts +3 -0
- package/dist/types/src/server/routes.d.ts +6 -0
- package/dist/types/src/server/storage.d.ts +56 -0
- package/dist/types/src/source-link.d.ts +2 -0
- package/dist/types/src/tabs/analyze-model.d.ts +31 -0
- package/dist/types/src/tabs/analyze.d.ts +2 -0
- package/dist/types/src/tabs/assets.d.ts +11 -0
- package/dist/types/src/tabs/audit-model.d.ts +42 -0
- package/dist/types/src/tabs/audit.d.ts +2 -0
- package/dist/types/src/tabs/authz-model.d.ts +11 -0
- package/dist/types/src/tabs/authz.d.ts +2 -0
- package/dist/types/src/tabs/config.d.ts +8 -0
- package/dist/types/src/tabs/inspect.d.ts +7 -0
- package/dist/types/src/tabs/modules.d.ts +4 -0
- package/dist/types/src/tabs/overview.d.ts +2 -0
- package/dist/types/src/tabs/pages.d.ts +2 -0
- package/dist/types/src/tabs/payload.d.ts +6 -0
- package/dist/types/src/tabs/plugins-model.d.ts +15 -0
- package/dist/types/src/tabs/plugins.d.ts +2 -0
- package/dist/types/src/tabs/seo-model.d.ts +36 -0
- package/dist/types/src/tabs/seo.d.ts +2 -0
- package/dist/types/src/tabs/server-routes.d.ts +2 -0
- package/dist/types/src/tabs/storage.d.ts +13 -0
- package/dist/types/src/tabs/tasks-model.d.ts +16 -0
- package/dist/types/src/tabs/tasks.d.ts +2 -0
- package/dist/types/src/tabs/terminals-model.d.ts +53 -0
- package/dist/types/src/tabs/terminals.d.ts +2 -0
- package/dist/types/src/tabs/timeline-model.d.ts +58 -0
- package/dist/types/src/tabs/timeline.d.ts +2 -0
- package/dist/types/src/tester.d.ts +43 -0
- package/dist/types/src/toolbar/element.d.ts +28 -0
- package/dist/types/src/toolbar/shortcut.d.ts +14 -0
- package/dist/types/src/toolbar/style.d.ts +3 -0
- package/dist/types/src/view-context.d.ts +13 -0
- package/package.json +28 -4
- package/src/apps/locator.ts +131 -0
- package/src/bridge.ts +172 -0
- package/src/client.ts +10 -0
- package/src/dev/analyze.ts +128 -0
- package/src/dev/assets.ts +208 -0
- package/src/dev/authz.ts +162 -0
- package/src/dev/bundle.ts +91 -0
- package/src/dev/config.ts +132 -0
- package/src/dev/handler.ts +161 -0
- package/src/dev/modules.ts +60 -0
- package/src/dev/overview.ts +57 -0
- package/src/dev/processes.ts +34 -0
- package/src/dev/server-routes.ts +14 -0
- package/src/dev/tasks.ts +93 -0
- package/src/dev/timeline.ts +43 -0
- package/src/dev/virtual.ts +40 -0
- package/src/env.d.ts +21 -0
- package/src/icons.ts +48 -0
- package/src/index.ts +12 -0
- package/src/locator.ts +31 -0
- package/src/mask.ts +16 -0
- package/src/module.ts +352 -0
- package/src/open-in-editor.ts +18 -0
- package/src/options.ts +36 -0
- package/src/panel/document.ts +60 -0
- package/src/panel/groups.ts +41 -0
- package/src/panel/index.ts +429 -0
- package/src/panel/settings.ts +224 -0
- package/src/panel/style.ts +321 -0
- package/src/panel/ui.ts +52 -0
- package/src/server/authz.ts +110 -0
- package/src/server/index.ts +25 -0
- package/src/server/routes.ts +51 -0
- package/src/server/storage.ts +251 -0
- package/src/source-link.ts +29 -0
- package/src/tabs/analyze-model.ts +97 -0
- package/src/tabs/analyze.ts +217 -0
- package/src/tabs/assets.ts +375 -0
- package/src/tabs/audit-model.ts +216 -0
- package/src/tabs/audit.ts +223 -0
- package/src/tabs/authz-model.ts +28 -0
- package/src/tabs/authz.ts +337 -0
- package/src/tabs/config.ts +250 -0
- package/src/tabs/inspect.ts +101 -0
- package/src/tabs/modules.ts +58 -0
- package/src/tabs/overview.ts +104 -0
- package/src/tabs/pages.ts +188 -0
- package/src/tabs/payload.ts +224 -0
- package/src/tabs/plugins-model.ts +44 -0
- package/src/tabs/plugins.ts +95 -0
- package/src/tabs/seo-model.ts +140 -0
- package/src/tabs/seo.ts +162 -0
- package/src/tabs/server-routes.ts +469 -0
- package/src/tabs/storage.ts +313 -0
- package/src/tabs/tasks-model.ts +59 -0
- package/src/tabs/tasks.ts +287 -0
- package/src/tabs/terminals-model.ts +127 -0
- package/src/tabs/terminals.ts +294 -0
- package/src/tabs/timeline-model.ts +200 -0
- package/src/tabs/timeline.ts +260 -0
- package/src/tester.ts +158 -0
- package/src/toolbar/element.ts +428 -0
- package/src/toolbar/shortcut.ts +56 -0
- package/src/toolbar/style.ts +94 -0
- package/src/view-context.ts +93 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Storage } from "hamur/server";
|
|
2
|
+
/** The keys one answer lists at most. */
|
|
3
|
+
export declare const KEYS_MAX = 1000;
|
|
4
|
+
/** The longest key or prefix the routes take. */
|
|
5
|
+
export declare const KEY_MAX_LENGTH = 512;
|
|
6
|
+
/** The largest `PUT api/storage/item` body. */
|
|
7
|
+
export declare const ITEM_MAX_BYTES: number;
|
|
8
|
+
export declare const answer: (body: unknown, status?: number, headers?: Record<string, string>) => Response;
|
|
9
|
+
export declare const failure: (message: string, status: number, headers?: Record<string, string>) => Response;
|
|
10
|
+
export declare const wrongMethod: (name: string, methods: string) => Response;
|
|
11
|
+
/** What `devtools:storage` carries. */
|
|
12
|
+
export interface StorageChange {
|
|
13
|
+
mount: string;
|
|
14
|
+
key: string;
|
|
15
|
+
op: "set" | "remove";
|
|
16
|
+
}
|
|
17
|
+
export type StoragePush = (change: StorageChange) => void;
|
|
18
|
+
/** Posts to the dev runner, which sends it to the devtools sockets; this door runs only in the SSR process of `hamur dev`. */
|
|
19
|
+
export declare const postDevtoolsEvent: (event: string, data: unknown) => void;
|
|
20
|
+
export declare const postToRunner: StoragePush;
|
|
21
|
+
export declare function watchMount(mount: string, push: StoragePush): void;
|
|
22
|
+
/** Watches every mount there is now, so a new server process pushes changes before any panel asks for the mounts. */
|
|
23
|
+
export declare function watchMounts(push?: StoragePush): void;
|
|
24
|
+
export declare function unwatchMounts(): void;
|
|
25
|
+
/** An item as the tab shows it: `raw` when its bytes are not a value `setItem` wrote, so a save writes bytes back with `setItemRaw`. */
|
|
26
|
+
export type ItemValue = {
|
|
27
|
+
type: "json";
|
|
28
|
+
value: unknown;
|
|
29
|
+
raw?: true;
|
|
30
|
+
} | {
|
|
31
|
+
type: "text";
|
|
32
|
+
value: string;
|
|
33
|
+
raw?: true;
|
|
34
|
+
} | {
|
|
35
|
+
type: "bytes";
|
|
36
|
+
value: string;
|
|
37
|
+
raw?: true;
|
|
38
|
+
};
|
|
39
|
+
export declare const toHex: (bytes: Uint8Array) => string;
|
|
40
|
+
/** `undefined` unless `text` is pairs of hex digits (white space ignored). */
|
|
41
|
+
export declare function fromHex(text: string): Uint8Array | undefined;
|
|
42
|
+
export declare function readItem(storage: Storage, key: string): Promise<ItemValue | undefined>;
|
|
43
|
+
/** Reads a `PUT` body `{ type, value, raw? }`, or the message of what is wrong with it. */
|
|
44
|
+
export declare function parseItem(body: unknown): ItemValue | string;
|
|
45
|
+
export declare function writeItem(storage: Storage, key: string, item: ItemValue): Promise<void>;
|
|
46
|
+
/** The router decodes escapes, so `/_hamur/devtool%73/…` reaches these handlers too; only the literal path is answered. */
|
|
47
|
+
export declare const literal: (request: Request, name: string) => boolean;
|
|
48
|
+
/** `GET api/storage/mounts`: every mount with its driver; each one listed is watched from then on. */
|
|
49
|
+
export declare function answerMounts(request: Request, push?: StoragePush): Promise<Response>;
|
|
50
|
+
/** `GET api/storage/keys?mount=<m>&prefix=<p>`: `{ keys, truncated }`, sorted, at most `KEYS_MAX`. */
|
|
51
|
+
export declare function answerKeys(request: Request): Promise<Response>;
|
|
52
|
+
export declare function readBody(request: Request): Promise<unknown | Response>;
|
|
53
|
+
/** `api/storage/item?mount=<m>&key=<k>`: GET the item, PUT `{ type, value, raw? }`, DELETE it (204). */
|
|
54
|
+
export declare function answerItem(request: Request): Promise<Response>;
|
|
55
|
+
/** Any other `api/<name>` that reached the server process: no module answers it. */
|
|
56
|
+
export declare function answerUnknown(request: Request): Response;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DevAnalyzeReport } from "hamur/kit";
|
|
2
|
+
type Chunk = DevAnalyzeReport["client"]["chunks"][number];
|
|
3
|
+
export interface Size {
|
|
4
|
+
bytes: number;
|
|
5
|
+
gzip: number;
|
|
6
|
+
}
|
|
7
|
+
/** A row of a comparison: the size in each run (absent where the chunk or route does not exist) and `after - before`. */
|
|
8
|
+
export interface Delta {
|
|
9
|
+
name: string;
|
|
10
|
+
before?: Size;
|
|
11
|
+
after?: Size;
|
|
12
|
+
bytes: number;
|
|
13
|
+
gzip: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Comparison {
|
|
16
|
+
chunks: Delta[];
|
|
17
|
+
routes: Delta[];
|
|
18
|
+
bytes: number;
|
|
19
|
+
gzip: number;
|
|
20
|
+
}
|
|
21
|
+
/** A chunk's name across builds: its import map key, else its file without the content hash, else (for the anonymous `chunk-<hash>.js`) its largest module. */
|
|
22
|
+
export declare function chunkName(chunk: Chunk): string;
|
|
23
|
+
/** Each chunk of a target by `chunkName`, a repeated name numbered `name (2)` in file order. */
|
|
24
|
+
export declare function namedChunks(chunks: readonly Chunk[]): Map<string, Size>;
|
|
25
|
+
/** The size change from `base` to `next`, per chunk and per route (first-load JS), every row of either run, the largest change first. */
|
|
26
|
+
export declare function compareRuns(base: DevAnalyzeReport, next: DevAnalyzeReport): Comparison;
|
|
27
|
+
/** `+1.2 KB`, `-300 B`, `0 B`. */
|
|
28
|
+
export declare function formatDelta(bytes: number): string;
|
|
29
|
+
/** A larger bundle is worse: `up` (red), `down` (green) or `same`. */
|
|
30
|
+
export declare const trend: (bytes: number) => "up" | "down" | "same";
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AssetRow, AssetType } from "../dev/assets.ts";
|
|
2
|
+
export type AssetFilter = AssetType | "all";
|
|
3
|
+
export declare const FILTERS: Array<[AssetFilter, string]>;
|
|
4
|
+
/** `1536` → `1.5 KB`: bytes below 1024, then KB and MB with one decimal. */
|
|
5
|
+
export declare function formatBytes(bytes: number): string;
|
|
6
|
+
/** The rows of one type whose URL holds `text`, ignoring case. */
|
|
7
|
+
export declare function filterAssets(rows: AssetRow[], type: AssetFilter, text: string): AssetRow[];
|
|
8
|
+
/** The card's second line: size, then `width×height` for an image whose header was read. */
|
|
9
|
+
export declare function assetDetail(row: AssetRow): string;
|
|
10
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type SourceLocation } from "../locator.ts";
|
|
2
|
+
export type AuditSeverity = "error" | "warning";
|
|
3
|
+
/** One element of the page as the rules read it; `ref` is its index in the list the snapshot was made from. */
|
|
4
|
+
export interface AuditElement {
|
|
5
|
+
ref: number;
|
|
6
|
+
tag: string;
|
|
7
|
+
attrs: Record<string, string>;
|
|
8
|
+
/** The accessible name: `aria-label`, `aria-labelledby`, the text, an inner image's `alt`, or `title`. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Whether a `<label>`, `aria-label`, `aria-labelledby` or `title` names a form control. */
|
|
11
|
+
labelled: boolean;
|
|
12
|
+
/** Distance from the top of the document, in CSS pixels. */
|
|
13
|
+
top: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
naturalWidth: number;
|
|
17
|
+
naturalHeight: number;
|
|
18
|
+
/** `data-hamur-src` of the nearest element that has one. */
|
|
19
|
+
source?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface AuditSnapshot {
|
|
22
|
+
viewportHeight: number;
|
|
23
|
+
elements: AuditElement[];
|
|
24
|
+
}
|
|
25
|
+
export interface AuditFinding {
|
|
26
|
+
rule: string;
|
|
27
|
+
severity: AuditSeverity;
|
|
28
|
+
title: string;
|
|
29
|
+
hint: string;
|
|
30
|
+
ref: number;
|
|
31
|
+
snippet: string;
|
|
32
|
+
source?: SourceLocation;
|
|
33
|
+
}
|
|
34
|
+
/** The opening tag of an element as the finding shows it, cut at 120 characters. */
|
|
35
|
+
export declare function snippetOf(element: Pick<AuditElement, "tag" | "attrs">): string;
|
|
36
|
+
/** The findings of the Hamur-written rules on a snapshot of the page, in document order and then rule order. */
|
|
37
|
+
export declare function auditSnapshot(snapshot: AuditSnapshot): AuditFinding[];
|
|
38
|
+
/** How many findings of each severity there are. */
|
|
39
|
+
export declare function countBySeverity(findings: readonly AuditFinding[]): {
|
|
40
|
+
error: number;
|
|
41
|
+
warning: number;
|
|
42
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DecisionRow } from "../server/authz.ts";
|
|
2
|
+
/** The tab keeps the checks the dev server keeps. */
|
|
3
|
+
export declare const KEPT_DECISIONS = 200;
|
|
4
|
+
/** `incoming` (oldest first, as a push sends them) in front of `list` (newest first), the checks the tab already holds left out, cut to `KEPT_DECISIONS`. */
|
|
5
|
+
export declare function mergeDecisions(list: readonly DecisionRow[], incoming: readonly DecisionRow[]): DecisionRow[];
|
|
6
|
+
export declare const uidText: (uid: {
|
|
7
|
+
type: string;
|
|
8
|
+
id: string;
|
|
9
|
+
}) => string;
|
|
10
|
+
/** The explain form's context box as the request's `context`: empty is none, anything else must be a JSON object. */
|
|
11
|
+
export declare function contextValue(text: string): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Every value under the object `value` that is not a non-empty object, with its dot path below `prefix`. */
|
|
2
|
+
export declare function leaves(value: unknown, prefix: string): Array<[string, unknown]>;
|
|
3
|
+
/** The text typed for a public value, read as JSON; a parse error names the path. */
|
|
4
|
+
export declare function parseConfigValue(path: string, typed: string): unknown;
|
|
5
|
+
/** Shows a leaf when its path or value holds `query`, and a branch when one of its leaves shows; a search opens the branches it keeps. */
|
|
6
|
+
export declare function filterTree(root: HTMLElement, query: string): void;
|
|
7
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VirtualRow } from "../dev/virtual.ts";
|
|
2
|
+
/** The rows whose id holds `text`, ignoring case and surrounding spaces. */
|
|
3
|
+
export declare const filterVirtual: (rows: readonly VirtualRow[], text: string) => VirtualRow[];
|
|
4
|
+
/** The inspect page's address below `app.baseURL`; `theme` follows the panel. */
|
|
5
|
+
export declare const inspectURL: (baseURL: string, theme: string | undefined) => string;
|
|
6
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A value as the tab shows it: JSON, or its string form when JSON cannot write it. */
|
|
2
|
+
export declare function shown(value: unknown, indent?: number): string;
|
|
3
|
+
/** The text typed for a `useState` value, read as JSON; a parse error names the key. */
|
|
4
|
+
export declare function parseStateValue(key: string, text: string): unknown;
|
|
5
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginsAnswer } from "../dev/modules.ts";
|
|
2
|
+
import type { MarkLike } from "./timeline-model.ts";
|
|
3
|
+
export interface PluginRow {
|
|
4
|
+
kind: "app" | "server";
|
|
5
|
+
name: string;
|
|
6
|
+
file: string;
|
|
7
|
+
order: number;
|
|
8
|
+
mode?: string;
|
|
9
|
+
/** The page's `hamur:plugin:<name>` measure in milliseconds; `null` for a server plugin and an app plugin the page has not run. */
|
|
10
|
+
ms: number | null;
|
|
11
|
+
}
|
|
12
|
+
/** The setup time of each app plugin the page ran, by name; a plugin measured twice (a reload of the page's app) keeps the latest. */
|
|
13
|
+
export declare function pluginTimes(marks: readonly MarkLike[]): Map<string, number>;
|
|
14
|
+
/** App plugins in run order with their measured setup time, then server plugins in the order `defineServer` lists them. */
|
|
15
|
+
export declare function pluginRows(answer: PluginsAnswer, marks: readonly MarkLike[]): PluginRow[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface HeadEntry {
|
|
2
|
+
tag: string;
|
|
3
|
+
attrs: Record<string, string>;
|
|
4
|
+
text?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const NETWORKS: readonly ["x", "facebook", "linkedin", "slack"];
|
|
7
|
+
export type Network = (typeof NETWORKS)[number];
|
|
8
|
+
export declare const NETWORK_TITLES: Record<Network, string>;
|
|
9
|
+
export interface SeoCheck {
|
|
10
|
+
name: string;
|
|
11
|
+
value?: string;
|
|
12
|
+
/** A required check with no value is reported as missing. */
|
|
13
|
+
required: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface SeoCard {
|
|
16
|
+
network: Network;
|
|
17
|
+
/** The host the card shows. */
|
|
18
|
+
domain: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
/** An absolute URL. */
|
|
22
|
+
image?: string;
|
|
23
|
+
/** Slack's `og:site_name`, else the domain. */
|
|
24
|
+
siteName?: string;
|
|
25
|
+
layout: "large" | "small";
|
|
26
|
+
}
|
|
27
|
+
export interface SeoReport {
|
|
28
|
+
checks: SeoCheck[];
|
|
29
|
+
/** The names of the required checks with no value, in the order of `checks`. */
|
|
30
|
+
missing: string[];
|
|
31
|
+
cards: Record<Network, SeoCard>;
|
|
32
|
+
}
|
|
33
|
+
/** The `content` of the first `<meta>` whose `property` or `name` is `key`. */
|
|
34
|
+
export declare function metaValue(head: readonly HeadEntry[], key: string): string | undefined;
|
|
35
|
+
/** The checks and the four card previews of the current head (`lang` is `<html lang>`, `pageUrl` the page's address). */
|
|
36
|
+
export declare function seoReport(head: readonly HeadEntry[], lang: string, pageUrl: string): SeoReport;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ItemValue } from "../server/storage.ts";
|
|
2
|
+
export type EditorMode = "json" | "text" | "hex";
|
|
3
|
+
/** The editor's mode and text for an item as `api/storage/item` answers it. */
|
|
4
|
+
export declare function editorOf(item: ItemValue): {
|
|
5
|
+
mode: EditorMode;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
/** The editor's text read in `from` and written in `to`: text and hex convert through UTF-8, JSON is kept as its text. */
|
|
9
|
+
export declare function convertEditor(text: string, from: EditorMode, to: EditorMode): string;
|
|
10
|
+
/** The `PUT` body for the editor's text in `mode`; `raw` is kept from the item that was opened. */
|
|
11
|
+
export declare function itemOf(text: string, mode: EditorMode, raw: boolean): ItemValue;
|
|
12
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TaskRunRecord } from "hamur/kit";
|
|
2
|
+
/** The tab keeps the newest settled runs the runner keeps. */
|
|
3
|
+
export declare const KEPT_SETTLED = 200;
|
|
4
|
+
export declare const isSettled: (run: TaskRunRecord) => boolean;
|
|
5
|
+
/** Puts `incoming` into `runs` by id, then drops the oldest settled runs beyond `KEPT_SETTLED`; a settled run is not replaced by an unsettled one. */
|
|
6
|
+
export declare function mergeRuns(runs: Map<string, TaskRunRecord>, incoming: readonly TaskRunRecord[]): void;
|
|
7
|
+
/** Newest `createdAt` first. */
|
|
8
|
+
export declare const newestFirst: (runs: ReadonlyMap<string, TaskRunRecord>) => TaskRunRecord[];
|
|
9
|
+
/** The `pending` runs, the soonest start first. */
|
|
10
|
+
export declare const pendingFirst: (runs: ReadonlyMap<string, TaskRunRecord>) => TaskRunRecord[];
|
|
11
|
+
export declare function durationText(ms: number | undefined): string;
|
|
12
|
+
export declare function sizeText(bytes: number): string;
|
|
13
|
+
/** The payload box's text as a request body: empty is no payload, anything else must be JSON. */
|
|
14
|
+
export declare function payloadBody(text: string): string;
|
|
15
|
+
/** What a failed task endpoint answer says: its `message`, else its text. */
|
|
16
|
+
export declare function failureText(status: number, body: string): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DevProcessInfo } from "hamur/kit";
|
|
2
|
+
export declare const LOG_LEVELS: readonly ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
3
|
+
export type LogLevelName = (typeof LOG_LEVELS)[number];
|
|
4
|
+
/** A record of `/_hamur/logs` as the runner writes it. */
|
|
5
|
+
export interface LogEntry {
|
|
6
|
+
time: number;
|
|
7
|
+
level: LogLevelName;
|
|
8
|
+
msg: string;
|
|
9
|
+
bindings: Record<string, unknown>;
|
|
10
|
+
fields?: Record<string, unknown>;
|
|
11
|
+
err?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** The tab keeps this many log records and process lines, as the runner does. */
|
|
14
|
+
export declare const KEPT = 1000;
|
|
15
|
+
export interface LogFilter {
|
|
16
|
+
levels: ReadonlySet<LogLevelName>;
|
|
17
|
+
/** Kept when it is empty; else only the records of that request. */
|
|
18
|
+
reqId: string;
|
|
19
|
+
}
|
|
20
|
+
/** One `data:` payload of the stream; `undefined` for anything that is not a record. */
|
|
21
|
+
export declare function parseLogEvent(data: string): LogEntry | undefined;
|
|
22
|
+
export declare const requestIdOf: (record: LogEntry) => string | undefined;
|
|
23
|
+
export declare function filterLogs(records: readonly LogEntry[], filter: LogFilter): LogEntry[];
|
|
24
|
+
/** `HH:MM:SS.mmm [name] msg key=value`, the level shown apart. */
|
|
25
|
+
export declare function logText(record: LogEntry): string;
|
|
26
|
+
/** Adds `record` and drops the oldest past `KEPT`. */
|
|
27
|
+
export declare function keep<T>(list: T[], item: T): T[];
|
|
28
|
+
/** The `devtools:process` push. */
|
|
29
|
+
export interface ProcessEvent {
|
|
30
|
+
name: string;
|
|
31
|
+
line?: string;
|
|
32
|
+
stderr?: true;
|
|
33
|
+
status?: DevProcessInfo["status"];
|
|
34
|
+
code?: number;
|
|
35
|
+
}
|
|
36
|
+
/** A process as the tab holds it: its lines with the stream each came from. */
|
|
37
|
+
export interface ProcessView {
|
|
38
|
+
name: string;
|
|
39
|
+
module: string;
|
|
40
|
+
command: string;
|
|
41
|
+
args: string[];
|
|
42
|
+
status: DevProcessInfo["status"];
|
|
43
|
+
code?: number;
|
|
44
|
+
lines: Array<{
|
|
45
|
+
text: string;
|
|
46
|
+
stderr: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
export declare function processView(info: DevProcessInfo): ProcessView;
|
|
50
|
+
/** Applies a push to the process it names; `false` when the tab does not know that name. */
|
|
51
|
+
export declare function applyProcessEvent(views: Map<string, ProcessView>, event: ProcessEvent): boolean;
|
|
52
|
+
/** The words next to a process's status dot. */
|
|
53
|
+
export declare function statusText(view: Pick<ProcessView, "status" | "code">): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DevHook } from "hamur/kit";
|
|
2
|
+
import type { SpanRow } from "../dev/timeline.ts";
|
|
3
|
+
export type EventKind = "navigation" | "hydration" | "update" | "middleware" | "loader" | "fetch" | "chunk";
|
|
4
|
+
/** One client event on the Timeline; `start` and `end` are epoch milliseconds. */
|
|
5
|
+
export interface TimelineEvent {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: EventKind;
|
|
8
|
+
name: string;
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
/** A loader's trace id and the span id it sent as `traceparent`'s parent. */
|
|
12
|
+
trace?: string;
|
|
13
|
+
span?: string;
|
|
14
|
+
detail: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface MarkLike {
|
|
17
|
+
name: string;
|
|
18
|
+
startTime: number;
|
|
19
|
+
duration: number;
|
|
20
|
+
detail?: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface ResourceLike {
|
|
23
|
+
name: string;
|
|
24
|
+
initiatorType: string;
|
|
25
|
+
startTime: number;
|
|
26
|
+
duration: number;
|
|
27
|
+
}
|
|
28
|
+
/** A line of the waterfall: a client event (depth 0) or a server span below it. */
|
|
29
|
+
export interface TimelineRow {
|
|
30
|
+
id: string;
|
|
31
|
+
kind: EventKind | "server";
|
|
32
|
+
label: string;
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
depth: number;
|
|
36
|
+
detail: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/** The client events of the page: its `hamur:*` measures and the fetches and script and style loads Resource Timing recorded. */
|
|
39
|
+
export declare function clientEvents(marks: readonly MarkLike[], resources: readonly ResourceLike[], timeOrigin: number): TimelineEvent[];
|
|
40
|
+
/** The spans of `spans` below the span `parentId`, children after their parent and by start; `depth` 1 is a child of `parentId`. */
|
|
41
|
+
export declare function nestSpans(spans: readonly SpanRow[], parentId: string): Array<{
|
|
42
|
+
span: SpanRow;
|
|
43
|
+
depth: number;
|
|
44
|
+
}>;
|
|
45
|
+
/** The waterfall rows: each event, then the server spans of its trace nested below it by `traceparent`. */
|
|
46
|
+
export declare function timelineRows(events: readonly TimelineEvent[], spansByTrace: ReadonlyMap<string, readonly SpanRow[]>): TimelineRow[];
|
|
47
|
+
export interface HookRow {
|
|
48
|
+
hook: string;
|
|
49
|
+
kind: "build" | "app" | "server";
|
|
50
|
+
calls: number;
|
|
51
|
+
totalMs: number;
|
|
52
|
+
}
|
|
53
|
+
/** The Hooks view: the runner's build and server hooks, and the app hooks the page measured (`hamur:hook:<name>`), most time first. */
|
|
54
|
+
export declare function hookRows(runner: readonly DevHook[], marks: readonly MarkLike[]): HookRow[];
|
|
55
|
+
/** `1.234` → `1.2 ms`, `1234` → `1.23 s`. */
|
|
56
|
+
export declare function formatMs(ms: number): string;
|
|
57
|
+
/** A tick distance of 1, 2 or 5 times a power of ten that puts at most `max` ticks on `total` milliseconds. */
|
|
58
|
+
export declare function tickStep(total: number, max?: number): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const REQUESTS_KEY = "hamur:devtools:requests";
|
|
2
|
+
/** A value that satisfies `schema`, the way a person would start typing one: an `example`, `default`, `const` or first `enum` entry wins, else the type's empty value; an object holds each of its properties. */
|
|
3
|
+
export declare function prefillBody(schema: unknown, depth?: number): unknown;
|
|
4
|
+
/** The names a server route pattern (`/api/users/:id`, `/api/**:rest`) reads from the path. */
|
|
5
|
+
export declare function paramNames(pattern: string): string[];
|
|
6
|
+
/** `pattern` with each `:name` replaced by its value, percent-encoded (a `**:name` keeps its slashes); a name with no value stays as written. */
|
|
7
|
+
export declare function fillPattern(pattern: string, params: Record<string, string>): string;
|
|
8
|
+
export type Pairs = Array<[string, string]>;
|
|
9
|
+
/** `path` with `query` appended after any query it already has; empty names are left out. */
|
|
10
|
+
export declare function withQuery(path: string, query: Pairs): string;
|
|
11
|
+
/** The URL `typed` names on `origin`; a URL of another host (a full URL, `//host/…`, a different port or scheme) is refused. */
|
|
12
|
+
export declare function sameOriginURL(typed: string, origin: string): URL;
|
|
13
|
+
export type BodyKind = "none" | "json" | "form";
|
|
14
|
+
export interface TesterState {
|
|
15
|
+
method: string;
|
|
16
|
+
url: string;
|
|
17
|
+
params: Record<string, string>;
|
|
18
|
+
query: Pairs;
|
|
19
|
+
headers: Pairs;
|
|
20
|
+
bodyKind: BodyKind;
|
|
21
|
+
json: string;
|
|
22
|
+
form: Pairs;
|
|
23
|
+
cookies: Pairs;
|
|
24
|
+
}
|
|
25
|
+
export interface BuiltRequest {
|
|
26
|
+
url: URL;
|
|
27
|
+
init: RequestInit;
|
|
28
|
+
}
|
|
29
|
+
/** The `fetch` arguments of a form state; throws a message for a URL of another origin or a JSON body that does not parse. */
|
|
30
|
+
export declare function buildRequest(state: TesterState, origin: string): BuiltRequest;
|
|
31
|
+
/** The `name=value` cookies to set before a request, as `document.cookie` writes them. */
|
|
32
|
+
export declare function cookieWrites(cookies: Pairs): string[];
|
|
33
|
+
export interface SavedRequest {
|
|
34
|
+
savedAt: string;
|
|
35
|
+
state: TesterState;
|
|
36
|
+
}
|
|
37
|
+
export type SavedRequests = Record<string, SavedRequest[]>;
|
|
38
|
+
export declare const routeKey: (method: string, path: string) => string;
|
|
39
|
+
/** The saved requests of every route; anything that is not the saved shape reads as none. */
|
|
40
|
+
export declare function readSaved(storage: Pick<Storage, "getItem"> | undefined): SavedRequests;
|
|
41
|
+
/** `saved` with `request` added first under `key`, at most `MAX_SAVED` kept. */
|
|
42
|
+
export declare function addSaved(saved: SavedRequests, key: string, request: SavedRequest): SavedRequests;
|
|
43
|
+
export declare function writeSaved(storage: Pick<Storage, "setItem"> | undefined, saved: SavedRequests): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DevtoolsApp } from "hamur/app";
|
|
2
|
+
import { type PanelRect, type Placement } from "../panel/settings.ts";
|
|
3
|
+
export declare const TOOLBAR_TAG = "hamur-devtools";
|
|
4
|
+
export interface ToolbarApp {
|
|
5
|
+
name: string;
|
|
6
|
+
title: string;
|
|
7
|
+
icon: string;
|
|
8
|
+
load: () => Promise<{
|
|
9
|
+
default: DevtoolsApp;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolbarConfig {
|
|
13
|
+
baseURL: string;
|
|
14
|
+
shortcut: string | false;
|
|
15
|
+
placement: Placement;
|
|
16
|
+
apps: ToolbarApp[];
|
|
17
|
+
}
|
|
18
|
+
export interface ToolbarControl {
|
|
19
|
+
open(tab?: string): void;
|
|
20
|
+
close(): void;
|
|
21
|
+
/** The frame as a rectangle in px, whether docked or floating. */
|
|
22
|
+
rect(): PanelRect;
|
|
23
|
+
/** Puts the frame at `rect` (kept inside the viewport); `commit` keeps it in the settings. */
|
|
24
|
+
place(rect: PanelRect, commit: boolean): void;
|
|
25
|
+
dock(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Defines `<hamur-devtools>`, appends one to `body` and puts it back when the app replaces the body's children. */
|
|
28
|
+
export declare function mountToolbar(config: ToolbarConfig): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Shortcut {
|
|
2
|
+
ctrl: boolean;
|
|
3
|
+
alt: boolean;
|
|
4
|
+
shift: boolean;
|
|
5
|
+
meta: boolean;
|
|
6
|
+
/** The `KeyboardEvent.code` of the key: `KeyD`, `Digit1`, `F5`. */
|
|
7
|
+
code: string;
|
|
8
|
+
}
|
|
9
|
+
/** Modifiers each at most once, then one key `a`–`z`, `0`–`9` or `f1`–`f12`; case ignored. */
|
|
10
|
+
export declare function parseShortcut(text: string): Shortcut | undefined;
|
|
11
|
+
/** Matched by `code`, so `alt` on macOS, which changes `key`, still matches. */
|
|
12
|
+
export declare function matchesShortcut(event: Pick<KeyboardEvent, "code" | "ctrlKey" | "altKey" | "shiftKey" | "metaKey">, shortcut: Shortcut): boolean;
|
|
13
|
+
/** A keydown in a field the user types into is not a shortcut. */
|
|
14
|
+
export declare function isTyping(event: Event): boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const HAMUR_ICON = "<svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M4 16.5c0-5.5 3.6-9.5 8-9.5s8 4 8 9.5z\" fill=\"currentColor\" fill-opacity=\"0.16\" stroke=\"none\"></path><path d=\"M4 16.5c0-5.5 3.6-9.5 8-9.5s8 4 8 9.5M3 16.5h18M9.5 12v1M14.5 12v1\"></path></svg>";
|
|
2
|
+
/** The shadow root's sheet, the panel's tokens and the utilities the toolbar uses, in px since `rem` is the page's. */
|
|
3
|
+
export declare const TOOLBAR_CSS: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DevtoolsApp, DevtoolsAppContext, DevtoolsPage } from "hamur/app";
|
|
2
|
+
type Listener = (data: unknown) => void;
|
|
3
|
+
/** Calls `fn` with the data of each devtools push named `event`; returns the function that stops it. */
|
|
4
|
+
export declare function onDevtoolsEvent(event: string, fn: Listener): () => void;
|
|
5
|
+
/** `POST <baseURL>_hamur/devtools/api/rpc/<name>` with the args as JSON. */
|
|
6
|
+
export declare function callDevtoolsRpc<R>(baseURL: string, name: string, args?: unknown): Promise<R>;
|
|
7
|
+
/** The `ctx` a tab's or an app's `init` gets. */
|
|
8
|
+
export declare function viewContext(baseURL: string, page: DevtoolsPage | undefined, setBadge: (text: string | undefined) => void): DevtoolsAppContext;
|
|
9
|
+
/** Runs a view's `init` and gives back its teardown; a failed load or `init` stops its listeners, and after either `on` and `setBadge` do nothing. */
|
|
10
|
+
export declare function startView(load: () => Promise<{
|
|
11
|
+
default: DevtoolsApp;
|
|
12
|
+
}>, canvas: HTMLElement, ctx: DevtoolsAppContext): Promise<() => void>;
|
|
13
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hamur/devtools",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/productdevbook/hamur.git",
|
|
9
|
+
"directory": "packages/devtools"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
14
|
+
"default": "./dist/src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"types": "./dist/types/src/client.d.ts",
|
|
18
|
+
"default": "./dist/src/client.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"hamur": "~0.0.1"
|
|
29
|
+
}
|
|
30
|
+
}
|