@warlock.js/grimoire 5.63.1 → 5.64.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 +44 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +24 -2
- package/esm/book/build.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +11 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/api-snapshot.mjs +39 -0
- package/esm/check/rules/api-snapshot.mjs.map +1 -0
- package/esm/check/rules/code-rules.mjs +45 -0
- package/esm/check/rules/code-rules.mjs.map +1 -0
- package/esm/check/rules/drift.mjs +54 -0
- package/esm/check/rules/drift.mjs.map +1 -0
- package/esm/check/rules/focused-tests.mjs +39 -0
- package/esm/check/rules/focused-tests.mjs.map +1 -0
- package/esm/check/rules/shows.mjs +52 -0
- package/esm/check/rules/shows.mjs.map +1 -0
- package/esm/codes/codes.d.mts +48 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +26 -1
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/guard.d.mts +104 -0
- package/esm/contracts/guard.d.mts.map +1 -0
- package/esm/contracts/index.mjs +5 -0
- package/esm/contracts/matrix.d.mts +75 -0
- package/esm/contracts/matrix.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +21 -0
- package/esm/contracts/scry.d.mts.map +1 -1
- package/esm/contracts/settings.d.mts +71 -0
- package/esm/contracts/settings.d.mts.map +1 -0
- package/esm/contracts/settings.mjs +67 -0
- package/esm/contracts/settings.mjs.map +1 -0
- package/esm/contracts/shots.d.mts +146 -0
- package/esm/contracts/shots.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +10 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +13 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs +7 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/approvals.mjs +59 -0
- package/esm/devtools/approvals.mjs.map +1 -0
- package/esm/devtools/data.mjs +2 -0
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/graphs.mjs +13 -3
- package/esm/devtools/graphs.mjs.map +1 -1
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +32 -2
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/matrix.mjs +207 -0
- package/esm/devtools/matrix.mjs.map +1 -0
- package/esm/devtools/product-map.d.mts.map +1 -1
- package/esm/devtools/product-map.mjs +87 -1
- package/esm/devtools/product-map.mjs.map +1 -1
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +12 -3
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +5 -1
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/git/index.d.mts +20 -0
- package/esm/git/index.d.mts.map +1 -0
- package/esm/git/index.mjs +280 -0
- package/esm/git/index.mjs.map +1 -0
- package/esm/guard/api.mjs +70 -0
- package/esm/guard/api.mjs.map +1 -0
- package/esm/guard/assertions.mjs +18 -0
- package/esm/guard/assertions.mjs.map +1 -0
- package/esm/guard/collect.mjs +139 -0
- package/esm/guard/collect.mjs.map +1 -0
- package/esm/guard/format.mjs +27 -0
- package/esm/guard/format.mjs.map +1 -0
- package/esm/guard/glob.mjs +79 -0
- package/esm/guard/glob.mjs.map +1 -0
- package/esm/guard/index.mjs +9 -0
- package/esm/guard/rules.mjs +310 -0
- package/esm/guard/rules.mjs.map +1 -0
- package/esm/guard/scope.mjs +95 -0
- package/esm/guard/scope.mjs.map +1 -0
- package/esm/index.d.mts +10 -3
- package/esm/index.mjs +6 -2
- package/esm/paths/index.d.mts +15 -1
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +27 -3
- package/esm/paths/index.mjs.map +1 -1
- package/esm/proves/index.mjs +2 -1
- package/esm/proves/scan-proofs.mjs +1 -1
- package/esm/proves/scan-proofs.mjs.map +1 -1
- package/esm/proves/scan-shows.d.mts +21 -0
- package/esm/proves/scan-shows.d.mts.map +1 -0
- package/esm/proves/scan-shows.mjs +168 -0
- package/esm/proves/scan-shows.mjs.map +1 -0
- package/esm/releases/index.d.mts.map +1 -1
- package/esm/releases/index.mjs +5 -3
- package/esm/releases/index.mjs.map +1 -1
- package/esm/releases/stamp.mjs +121 -0
- package/esm/releases/stamp.mjs.map +1 -0
- package/esm/rules/focused.mjs +26 -0
- package/esm/rules/focused.mjs.map +1 -0
- package/esm/rules/index.mjs +88 -0
- package/esm/rules/index.mjs.map +1 -0
- package/esm/rules/logical-css.mjs +112 -0
- package/esm/rules/logical-css.mjs.map +1 -0
- package/esm/rules/no-js-imports.mjs +22 -0
- package/esm/rules/no-js-imports.mjs.map +1 -0
- package/esm/rules/scan.mjs +196 -0
- package/esm/rules/scan.mjs.map +1 -0
- package/esm/rules/specific-errors.mjs +51 -0
- package/esm/rules/specific-errors.mjs.map +1 -0
- package/esm/rules/type-discriminator.mjs +27 -0
- package/esm/rules/type-discriminator.mjs.map +1 -0
- package/esm/scry/also-changes.mjs +106 -0
- package/esm/scry/also-changes.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +22 -0
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +7 -2
- package/esm/scry/query.mjs.map +1 -1
- package/esm/scry/search.d.mts.map +1 -1
- package/esm/scry/search.mjs +43 -11
- package/esm/scry/search.mjs.map +1 -1
- package/esm/shots/approve.mjs +195 -0
- package/esm/shots/approve.mjs.map +1 -0
- package/esm/shots/drift.mjs +174 -0
- package/esm/shots/drift.mjs.map +1 -0
- package/esm/shots/png.mjs +166 -0
- package/esm/shots/png.mjs.map +1 -0
- package/esm/shots/state.mjs +43 -0
- package/esm/shots/state.mjs.map +1 -0
- package/esm/shots/store.mjs +66 -0
- package/esm/shots/store.mjs.map +1 -0
- package/esm/shots/touched.mjs +38 -0
- package/esm/shots/touched.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +15 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/api-command.mjs +41 -0
- package/esm/warlock/api-command.mjs.map +1 -0
- package/esm/warlock/approve-command.mjs +80 -0
- package/esm/warlock/approve-command.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +1 -1
- package/esm/warlock/commands.d.mts.map +1 -1
- package/esm/warlock/commands.mjs +61 -8
- package/esm/warlock/commands.mjs.map +1 -1
- package/esm/warlock/guard-command.mjs +116 -0
- package/esm/warlock/guard-command.mjs.map +1 -0
- package/esm/warlock/index.d.mts +2 -1
- package/esm/warlock/index.mjs +2 -1
- package/esm/warlock/languages.mjs +75 -0
- package/esm/warlock/languages.mjs.map +1 -0
- package/esm/warlock/mcp-tools.mjs +2 -2
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/warlock/release-command.mjs +65 -0
- package/esm/warlock/release-command.mjs.map +1 -0
- package/esm/warlock/shows.d.mts +35 -0
- package/esm/warlock/shows.d.mts.map +1 -0
- package/esm/warlock/shows.mjs +195 -0
- package/esm/warlock/shows.mjs.map +1 -0
- package/esm/workspace/cache.mjs +4 -1
- package/esm/workspace/cache.mjs.map +1 -1
- package/esm/workspace/derived.mjs +11 -6
- package/esm/workspace/derived.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +8 -1
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/workspace/stored.mjs +4 -1
- package/esm/workspace/stored.mjs.map +1 -1
- package/esm/written/features.mjs +21 -5
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/index.mjs +2 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +16 -3
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/esm/written/settings.d.mts +11 -0
- package/esm/written/settings.d.mts.map +1 -0
- package/esm/written/settings.mjs +88 -0
- package/esm/written/settings.mjs.map +1 -0
- package/llms-full.txt +276 -39
- package/llms.txt +2 -0
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +4 -0
- package/skills/describe-an-app/SKILL.md +4 -1
- package/skills/guard-a-change/SKILL.md +85 -0
- package/skills/index.md +7 -3
- package/skills/record-a-change/SKILL.md +52 -16
- package/skills/review-a-change/SKILL.md +53 -0
- package/skills/use-the-grimoire/SKILL.md +21 -18
- package/skills/write-a-feature/SKILL.md +42 -1
- package/ui/grimoire-view.js +756 -40
- package/ui/grimoire.css +303 -28
- package/ui/product-map.css +43 -7
- package/ui/product-map.js +212 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/data.ts"],"sourcesContent":["/**\n * The answers of the tab, as functions of the snapshot. The devtools routes\n * and the static export both call them; questions about one item go to\n * `scry()`, the rest read the snapshot directly.\n */\nimport { explainGrimoireCode, isGrimoireCode } from \"../codes\";\nimport { checkGrimoire } from \"../check\";\nimport type { BookHost, BookPage, BookScreen } from \"../contracts/adapter\";\nimport type { TasksIndex, FeaturesIndex } from \"../contracts/bookmap\";\nimport type { GrimoireCheckReport, GrimoireFinding, RouteFreshness } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenApp, WrittenLayout, WrittenPage, WrittenRelease } from \"../contracts/written\";\nimport { scry } from \"../scry\";\nimport { compactFlow, STEP_FILE_SETS, stepFilePage } from \"../scry/compact\";\nimport { testResultsInfo } from \"../test-results\";\nimport { featureFileGroups, featureMap, featureProofs } from \"./feature-map\";\nimport { featureGraph, fileGraph, moduleGraph, pageGraph, type GrimoireGraph } from \"./graphs\";\nimport {\n STEP_FILES_PAGE_LIMIT,\n type GrimoireFeatureAnswer,\n type GrimoireCheckFilter,\n type GrimoireCheckGroup,\n type GrimoireCheckGroups,\n type GrimoireCheckPage,\n type GrimoireFlowAnswer,\n type GrimoireStepFilesAnswer,\n type StepFileSet,\n} from \"./answers\";\nimport type { TestResultsInfo } from \"../contracts/test-results\";\n\n/** An error a route answers with a status (devtools turns `statusCode` into the response status). */\nexport class GrimoirePanelError extends Error {\n public readonly statusCode: number;\n\n public constructor(statusCode: number, message: string) {\n super(message);\n this.name = \"GrimoirePanelError\";\n this.statusCode = statusCode;\n }\n}\n\nexport type GrimoireSummary = {\n /**\n * Flow steps by what was checked: `resolved` (`found === true`) and `missing` (`found === false`) were looked up\n * in the code; `unchecked` (`found === null`, no route facts yet) were not, and never count against the health.\n */\n steps: { checked: number; resolved: number; missing: number; unchecked: number };\n routes: RouteFreshness;\n features: FeaturesIndex;\n tasks: TasksIndex;\n counts: GrimoireCheckReport[\"counts\"];\n /** Whether any feature, app, task or release is written, and how big the book is. */\n written: boolean;\n book: { files: number; modules: number; builtAt: string };\n /** How many apps, pages, screens and releases are written (the tab's navigation and overview badges). */\n apps: { apps: number; pages: number; screens: number };\n releases: number;\n /** Whether test results were read, from where, and how many proofs have one. */\n results: TestResultsInfo;\n /** Framework brand and the app's name and version from the adapter; `null` when the adapter reports none. */\n host: BookHost | null;\n};\n\n/** One feature of the listing: the index entry plus what the cards show. */\nexport type GrimoireFeatureRow = Omit<FeaturesIndex[\"features\"][number], \"flows\"> & {\n /** The README paragraph under the heading, or `null`. */\n summary: string | null;\n /** The index flows with their headings. */\n flows: (FeaturesIndex[\"features\"][number][\"flows\"][number] & { heading: string | null })[];\n};\n\nexport type GrimoireFeaturesAnswer = { features: GrimoireFeatureRow[] };\n\n/** One page or screen of an app, as the listing shows it. */\nexport type GrimoireAppRow = {\n id: string;\n type: \"page\" | \"screen\";\n /** The page route or the screen name, or `null` when the file gives none. */\n route: string | null;\n heading: string | null;\n /** `confirmed` or `inferred` when the file says so, otherwise `null`. */\n origin: \"confirmed\" | \"inferred\" | null;\n layout: string | null;\n /** How many block rows the page lists itself. */\n blocks: number;\n};\n\nexport type GrimoireAppsAnswer = {\n apps: {\n id: string;\n type: string;\n root: string;\n pages: string[];\n screens: string[];\n /** Every page and screen with what the listing needs. */\n rows: GrimoireAppRow[];\n }[];\n};\n\nexport type GrimoirePageAnswer = {\n page: WrittenPage;\n layout: WrittenLayout | null;\n book: BookPage | BookScreen | null;\n};\n\nexport type GrimoireReleasesAnswer = {\n releases: { release: string; date: string; file: string }[];\n};\n\n/** `scry()` with its not-found codes turned into a 404 and the rest into a 400. */\nfunction ask<Result>(snapshot: GrimoireSnapshot, query: Parameters<typeof scry>[1]): Result {\n try {\n return scry(snapshot, query) as Result;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n\n if (typeof code === \"string\" && isGrimoireCode(code)) {\n throw new GrimoirePanelError(code === \"GR9006\" ? 400 : 404, (error as Error).message);\n }\n\n throw error;\n }\n}\n\nfunction required(value: string | undefined, name: string): string {\n if (value === undefined || value === \"\") throw new GrimoirePanelError(400, `Missing \"${name}\".`);\n\n return value;\n}\n\nexport function summary(snapshot: GrimoireSnapshot): GrimoireSummary {\n const files = snapshot.book.facts.files;\n const written = snapshot.written;\n\n const steps = Object.values(snapshot.collected.flows).flatMap((flow) => flow.steps);\n const resolved = steps.filter((step) => step.found === true).length;\n const missing = steps.filter((step) => step.found === false).length;\n\n return {\n steps: {\n checked: resolved + missing,\n resolved,\n missing,\n unchecked: steps.length - resolved - missing,\n },\n routes: snapshot.routes,\n features: snapshot.collected.featuresIndex,\n tasks: snapshot.collected.tasksIndex,\n counts: checkGrimoire(snapshot).counts,\n written: [written.features, written.apps, written.tasks, written.releases].some(\n (items) => items.length > 0,\n ),\n book: {\n files: files.length,\n modules: new Set(files.map((file) => file.module)).size,\n builtAt: snapshot.book.manifest.builtAt,\n },\n apps: {\n apps: written.apps.length,\n pages: written.apps.reduce((total, app) => total + app.pages.length, 0),\n screens: written.apps.reduce((total, app) => total + app.screens.length, 0),\n },\n releases: written.releases.length,\n results: testResultsInfo(snapshot),\n host: snapshot.host ?? null,\n };\n}\n\n/** The features listing: the features index with each README summary and flow headings. */\nexport function features(snapshot: GrimoireSnapshot): GrimoireFeaturesAnswer {\n const written = new Map(snapshot.written.features.map((feature) => [feature.id, feature]));\n\n return {\n features: snapshot.collected.featuresIndex.features.map((entry) => {\n const source = written.get(entry.id);\n const headings = new Map(\n (source?.flows ?? []).map((flow) => [flow.id.value, flow.heading?.value ?? null]),\n );\n\n return {\n ...entry,\n summary: source?.readme?.summary ?? null,\n flows: entry.flows.map((flow) => ({ ...flow, heading: headings.get(flow.id) ?? null })),\n };\n }),\n };\n}\n\nexport function search(snapshot: GrimoireSnapshot, text: string, limit?: number): ScrySearchResult {\n return ask<ScrySearchResult>(snapshot, {\n type: \"search\",\n text,\n ...(limit !== undefined && Number.isFinite(limit) && limit > 0\n ? { limit: Math.min(limit, 100) }\n : {}),\n });\n}\n\nexport function file(snapshot: GrimoireSnapshot, path: string | undefined): ScryFileResult {\n return ask(snapshot, { type: \"file\", file: required(path, \"path\") });\n}\n\nexport function impact(snapshot: GrimoireSnapshot, path: string | undefined): ScryImpactResult {\n return ask(snapshot, { type: \"impact\", file: required(path, \"path\") });\n}\n\nexport function route(\n snapshot: GrimoireSnapshot,\n method: string | undefined,\n path: string | undefined,\n): ScryRouteResult {\n return ask(snapshot, {\n type: \"route\",\n method: required(method, \"method\"),\n path: required(path, \"path\"),\n });\n}\n\nexport function feature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireFeatureAnswer {\n const wanted = required(id, \"feature\");\n const result = ask<ScryFeatureResult>(snapshot, { type: \"feature\", feature: wanted });\n const written = snapshot.written.features.find((item) => item.id === wanted);\n\n if (written === undefined)\n throw new GrimoirePanelError(404, `No feature \"${wanted}\" is written.`);\n\n return {\n ...result,\n map: featureMap(snapshot, written),\n fileGroups: featureFileGroups(snapshot, result.bookmap.own),\n proofs: featureProofs(snapshot, written),\n };\n}\n\nexport function flow(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): ScryFlowResult {\n return ask(snapshot, {\n type: \"flow\",\n feature: required(featureId, \"feature\"),\n flow: required(flowId, \"flow\"),\n });\n}\n\nexport function apps(snapshot: GrimoireSnapshot): GrimoireAppsAnswer {\n return {\n apps: snapshot.written.apps.map((app) => ({\n id: app.id.value,\n type: app.type.value,\n root: app.root.value,\n pages: app.pages.map((page) => page.id),\n screens: app.screens.map((screen) => screen.id),\n rows: [...app.pages, ...app.screens].map((item) => ({\n id: item.id,\n type: item.type,\n route: item.route?.value ?? item.screen?.value ?? null,\n heading: item.heading?.value ?? null,\n origin: item.origin?.value ?? null,\n layout: item.layout?.value ?? null,\n blocks: item.blocks.length,\n })),\n })),\n };\n}\n\nfunction findApp(snapshot: GrimoireSnapshot, id: string | undefined): WrittenApp {\n const app = snapshot.written.apps.find((candidate) => candidate.id.value === id);\n\n if (app === undefined)\n throw new GrimoirePanelError(404, `No app \"${id ?? \"\"}\" is written in grimoire/apps.`);\n\n return app;\n}\n\n/** A page or screen by its id or its route. */\nexport function findPage(app: WrittenApp, key: string): WrittenPage | undefined {\n return [...app.pages, ...app.screens].find(\n (page) => page.id === key || page.route?.value === key || page.screen?.value === key,\n );\n}\n\nexport function page(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoirePageAnswer {\n const app = findApp(snapshot, appId);\n const written = findPage(app, required(key, \"page\"));\n\n if (written === undefined) {\n throw new GrimoirePanelError(\n 404,\n `App \"${app.id.value}\" has no page or screen \"${key ?? \"\"}\".`,\n );\n }\n\n const match = snapshot.apps[app.id.value];\n const route = written.route?.value ?? written.screen?.value ?? null;\n let book: BookPage | BookScreen | null = null;\n\n if (route !== null && match?.site) {\n book =\n snapshot.book.facts.pages.find(\n (candidate) => candidate.site === match.site?.id && candidate.route === route,\n ) ?? null;\n } else if (route !== null && match?.mobile) {\n book = match.mobile.screens.find((screen) => screen.route === route) ?? null;\n }\n\n const layoutId = written.layout?.value ?? null;\n\n return {\n page: written,\n layout:\n layoutId === null ? null : (app.layouts.find((layout) => layout.id === layoutId) ?? null),\n book,\n };\n}\n\nexport function tasks(snapshot: GrimoireSnapshot): TasksIndex {\n return snapshot.collected.tasksIndex;\n}\n\nexport function releases(snapshot: GrimoireSnapshot): GrimoireReleasesAnswer {\n return {\n releases: snapshot.written.releases.map((release) => ({\n release: release.release.value,\n date: release.date.value,\n file: release.file,\n })),\n };\n}\n\nexport function release(snapshot: GrimoireSnapshot, id: string | undefined): WrittenRelease {\n const found = snapshot.written.releases.find((candidate) => candidate.release.value === id);\n\n if (found === undefined)\n throw new GrimoirePanelError(404, `No release \"${id ?? \"\"}\" in grimoire/releases.`);\n\n return found;\n}\n\nexport function check(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n return checkGrimoire(snapshot);\n}\n\nfunction graphOrNotFound(graph: GrimoireGraph | null, what: string): GrimoireGraph {\n if (graph === null) throw new GrimoirePanelError(404, `${what} is not in the book.`);\n\n return graph;\n}\n\nexport function graphOfFile(snapshot: GrimoireSnapshot, path: string | undefined): GrimoireGraph {\n const target = required(path, \"path\");\n\n return graphOrNotFound(fileGraph(snapshot, target), `\"${target}\"`);\n}\n\nexport function graphOfFeature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireGraph {\n const target = required(id, \"feature\");\n\n return graphOrNotFound(featureGraph(snapshot, target), `Feature \"${target}\"`);\n}\n\nexport function graphOfPage(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoireGraph {\n const target = required(key, \"page\");\n\n return graphOrNotFound(pageGraph(snapshot, required(appId, \"app\"), target), `Page \"${target}\"`);\n}\n\nexport function graphOfModules(snapshot: GrimoireSnapshot): GrimoireGraph {\n return moduleGraph(snapshot);\n}\n\n// ── Compact flow, step files, check pages and groups ───────────────────────\n\n/** `GET /flows/:feature/:flow`: the compact flow answer (step counts, direct imports, health, neighbours). */\nexport function flowAnswer(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): GrimoireFlowAnswer {\n return compactFlow(snapshot, flow(snapshot, featureId, flowId));\n}\n\n/** A whole number from a query value, or a 400 naming the parameter. */\nfunction whole(value: string | undefined, name: string, fallback: number, min: number): number {\n if (value === undefined || value === \"\") return fallback;\n\n const number = Number(value);\n\n if (!Number.isInteger(number) || number < min) {\n throw new GrimoirePanelError(400, `\"${name}\" must be a whole number of ${min} or more.`);\n }\n\n return number;\n}\n\n/** `GET /flows/:feature/:flow/steps/:index/files`: one page of a step's files. */\nexport function stepFiles(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n index: string | undefined,\n query: { set?: string | undefined; offset?: string | undefined; limit?: string | undefined },\n): GrimoireStepFilesAnswer {\n const feature = required(featureId, \"feature\");\n const id = required(flowId, \"flow\");\n const set = query.set === undefined || query.set === \"\" ? \"reachable\" : query.set;\n\n if (!(STEP_FILE_SETS as readonly string[]).includes(set)) {\n throw new GrimoirePanelError(\n 400,\n `Unknown set \"${set}\". Use one of: ${STEP_FILE_SETS.join(\", \")}.`,\n );\n }\n\n const stepIndex = whole(required(index, \"index\"), \"index\", 0, 0);\n const offset = whole(query.offset, \"offset\", 0, 0);\n const limit = Math.min(\n whole(query.limit, \"limit\", STEP_FILES_PAGE_LIMIT, 1),\n STEP_FILES_PAGE_LIMIT,\n );\n const written = snapshot.written.features\n .find((item) => item.id === feature)\n ?.flows.find((item) => item.id.value === id);\n const bookmap = written === undefined ? undefined : snapshot.collected.flows[written.ref];\n\n if (written === undefined || bookmap === undefined) {\n throw new GrimoirePanelError(404, `No flow ${feature}/${id} is written.`);\n }\n\n const step = bookmap.steps.find((item) => item.index === stepIndex);\n\n if (step === undefined) {\n throw new GrimoirePanelError(404, `${written.ref} has no step ${stepIndex}.`);\n }\n\n return stepFilePage(snapshot, bookmap, step, set as StepFileSet, offset, limit);\n}\n\n/** `GET /check?code=&feature=&flow=&severity=&state=&offset=&limit=`: matching findings, paged. */\nexport function checkPage(\n snapshot: GrimoireSnapshot,\n filter: GrimoireCheckFilter,\n): GrimoireCheckPage {\n const report = checkGrimoire(snapshot);\n const limit = Math.min(Math.max(1, Math.floor(filter.limit ?? 100)), 500);\n const offset = Math.max(0, Math.floor(filter.offset ?? 0));\n const code = filter.code?.trim().toUpperCase();\n const matching = report.findings.filter((finding) => {\n if (code !== undefined && code !== \"\" && finding.code !== code) return false;\n if (filter.severity !== undefined && finding.severity !== filter.severity) return false;\n if (filter.state !== undefined && finding.expected !== (filter.state === \"expected\"))\n return false;\n if (filter.flow !== undefined && filter.flow !== \"\" && finding.subject.flow !== filter.flow) {\n return false;\n }\n\n if (filter.feature !== undefined && filter.feature !== \"\") {\n return featureOfFinding(finding) === filter.feature;\n }\n\n return true;\n });\n\n return {\n ...report,\n findings: matching.slice(offset, offset + limit),\n total: matching.length,\n offset,\n limit,\n };\n}\n\n/** The feature a finding belongs to: its subject, else the feature of its flow, else `(none)`. */\nfunction featureOfFinding(finding: GrimoireFinding): string {\n return finding.subject.feature ?? finding.subject.flow?.split(\"/\")[0] ?? \"(none)\";\n}\n\n/** `GET /check/groups`: the check by code, errors first, then by count. */\nexport function checkGroups(snapshot: GrimoireSnapshot): GrimoireCheckGroups {\n const report = checkGrimoire(snapshot);\n const byCode = new Map<string, GrimoireFinding[]>();\n\n for (const finding of report.findings) {\n byCode.set(finding.code, [...(byCode.get(finding.code) ?? []), finding]);\n }\n\n const groups: GrimoireCheckGroup[] = [];\n\n for (const [code, findings] of byCode) {\n const definition = explainGrimoireCode(code);\n const unexpected = findings.filter((finding) => !finding.expected);\n const features = new Map<string, number>();\n\n for (const finding of unexpected) {\n const feature = featureOfFinding(finding);\n\n features.set(feature, (features.get(feature) ?? 0) + 1);\n }\n\n groups.push({\n code,\n severity: findings[0]?.severity ?? definition?.severity ?? \"warning\",\n area: definition?.area ?? \"\",\n title: definition?.title ?? code,\n fix: definition?.fix ?? findings[0]?.hint ?? \"\",\n count: unexpected.length,\n expected: findings.length - unexpected.length,\n features: [...features]\n .map(([feature, count]) => ({ feature, count }))\n .sort((left, right) => right.count - left.count || (left.feature < right.feature ? -1 : 1)),\n });\n }\n\n groups.sort(\n (left, right) =>\n (left.severity === right.severity ? 0 : left.severity === \"error\" ? -1 : 1) ||\n right.count - left.count ||\n (left.code < right.code ? -1 : 1),\n );\n\n return { counts: report.counts, ok: report.ok, groups };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAgB;CAEhB,AAAO,YAAY,YAAoB,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;AAuEA,SAAS,IAAY,UAA4B,OAA2C;CAC1F,IAAI;EACF,OAAO,KAAK,UAAU,KAAK;CAC7B,SAAS,OAAO;EACd,MAAM,OAAQ,MAA6B;EAE3C,IAAI,OAAO,SAAS,YAAY,eAAe,IAAI,GACjD,MAAM,IAAI,mBAAmB,SAAS,WAAW,MAAM,KAAM,MAAgB,OAAO;EAGtF,MAAM;CACR;AACF;AAEA,SAAS,SAAS,OAA2B,MAAsB;CACjE,IAAI,UAAU,UAAa,UAAU,IAAI,MAAM,IAAI,mBAAmB,KAAK,YAAY,KAAK,GAAG;CAE/F,OAAO;AACT;AAEA,SAAgB,QAAQ,UAA6C;CACnE,MAAM,QAAQ,SAAS,KAAK,MAAM;CAClC,MAAM,UAAU,SAAS;CAEzB,MAAM,QAAQ,OAAO,OAAO,SAAS,UAAU,KAAK,CAAC,CAAC,SAAS,SAAS,KAAK,KAAK;CAClF,MAAM,WAAW,MAAM,QAAQ,SAAS,KAAK,UAAU,IAAI,CAAC,CAAC;CAC7D,MAAM,UAAU,MAAM,QAA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Aa,UAAU,KAAK,MACzE,MAAM,QAAQ,KAAK,UAClB,KAAK,OAAO,MAAM,OAAO,KAAK,EACnC;CAEA,OAAO;EAAE,QAAQ,OAAO;EAAQ,IAAI,OAAO;EAAI;CAAO;AACxD"}
|
|
1
|
+
{"version":3,"file":"data.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/data.ts"],"sourcesContent":["/**\n * The answers of the tab, as functions of the snapshot. The devtools routes\n * and the static export both call them; questions about one item go to\n * `scry()`, the rest read the snapshot directly.\n */\nimport { explainGrimoireCode, isGrimoireCode } from \"../codes\";\nimport { checkGrimoire } from \"../check\";\nimport type { BookHost, BookPage, BookScreen } from \"../contracts/adapter\";\nimport type { TasksIndex, FeaturesIndex } from \"../contracts/bookmap\";\nimport type { GrimoireCheckReport, GrimoireFinding, RouteFreshness } from \"../contracts/findings\";\nimport type {\n ScryFeatureResult,\n ScryFileResult,\n ScryFlowResult,\n ScryImpactResult,\n ScryRouteResult,\n ScrySearchResult,\n} from \"../contracts/scry\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport type { WrittenApp, WrittenLayout, WrittenPage, WrittenRelease } from \"../contracts/written\";\nimport { scry } from \"../scry\";\nimport { compactFlow, STEP_FILE_SETS, stepFilePage } from \"../scry/compact\";\nimport { testResultsInfo } from \"../test-results\";\nimport { featureFileGroups, featureMap, featureProofs } from \"./feature-map\";\nimport { attentionOf, matrix } from \"./matrix\";\nimport { featureGraph, fileGraph, moduleGraph, pageGraph, type GrimoireGraph } from \"./graphs\";\nimport {\n STEP_FILES_PAGE_LIMIT,\n type GrimoireFeatureAnswer,\n type GrimoireCheckFilter,\n type GrimoireCheckGroup,\n type GrimoireCheckGroups,\n type GrimoireCheckPage,\n type GrimoireFlowAnswer,\n type GrimoireStepFilesAnswer,\n type StepFileSet,\n} from \"./answers\";\nimport type { TestResultsInfo } from \"../contracts/test-results\";\n\n/** An error a route answers with a status (devtools turns `statusCode` into the response status). */\nexport class GrimoirePanelError extends Error {\n public readonly statusCode: number;\n\n public constructor(statusCode: number, message: string) {\n super(message);\n this.name = \"GrimoirePanelError\";\n this.statusCode = statusCode;\n }\n}\n\nexport type GrimoireSummary = {\n /**\n * Flow steps by what was checked: `resolved` (`found === true`) and `missing` (`found === false`) were looked up\n * in the code; `unchecked` (`found === null`, no route facts yet) were not, and never count against the health.\n */\n steps: { checked: number; resolved: number; missing: number; unchecked: number };\n routes: RouteFreshness;\n features: FeaturesIndex;\n tasks: TasksIndex;\n counts: GrimoireCheckReport[\"counts\"];\n /** Whether any feature, app, task or release is written, and how big the book is. */\n written: boolean;\n book: { files: number; modules: number; builtAt: string };\n /** How many apps, pages, screens and releases are written (the tab's navigation and overview badges). */\n apps: { apps: number; pages: number; screens: number };\n releases: number;\n /** The Bird view's badge: failing, changed and rejected cells, and changes to whole flows. */\n birdView: number;\n /** Whether test results were read, from where, and how many proofs have one. */\n results: TestResultsInfo;\n /** Framework brand and the app's name and version from the adapter; `null` when the adapter reports none. */\n host: BookHost | null;\n};\n\n/** One feature of the listing: the index entry plus what the cards show. */\nexport type GrimoireFeatureRow = Omit<FeaturesIndex[\"features\"][number], \"flows\"> & {\n /** The README paragraph under the heading, or `null`. */\n summary: string | null;\n /** The index flows with their headings. */\n flows: (FeaturesIndex[\"features\"][number][\"flows\"][number] & { heading: string | null })[];\n};\n\nexport type GrimoireFeaturesAnswer = { features: GrimoireFeatureRow[] };\n\n/** One page or screen of an app, as the listing shows it. */\nexport type GrimoireAppRow = {\n id: string;\n type: \"page\" | \"screen\";\n /** The page route or the screen name, or `null` when the file gives none. */\n route: string | null;\n heading: string | null;\n /** `confirmed` or `inferred` when the file says so, otherwise `null`. */\n origin: \"confirmed\" | \"inferred\" | null;\n layout: string | null;\n /** How many block rows the page lists itself. */\n blocks: number;\n};\n\nexport type GrimoireAppsAnswer = {\n apps: {\n id: string;\n type: string;\n root: string;\n pages: string[];\n screens: string[];\n /** Every page and screen with what the listing needs. */\n rows: GrimoireAppRow[];\n }[];\n};\n\nexport type GrimoirePageAnswer = {\n page: WrittenPage;\n layout: WrittenLayout | null;\n book: BookPage | BookScreen | null;\n};\n\nexport type GrimoireReleasesAnswer = {\n releases: { release: string; date: string; file: string }[];\n};\n\n/** `scry()` with its not-found codes turned into a 404 and the rest into a 400. */\nfunction ask<Result>(snapshot: GrimoireSnapshot, query: Parameters<typeof scry>[1]): Result {\n try {\n return scry(snapshot, query) as Result;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n\n if (typeof code === \"string\" && isGrimoireCode(code)) {\n throw new GrimoirePanelError(code === \"GR9006\" ? 400 : 404, (error as Error).message);\n }\n\n throw error;\n }\n}\n\nfunction required(value: string | undefined, name: string): string {\n if (value === undefined || value === \"\") throw new GrimoirePanelError(400, `Missing \"${name}\".`);\n\n return value;\n}\n\nexport function summary(snapshot: GrimoireSnapshot): GrimoireSummary {\n const files = snapshot.book.facts.files;\n const written = snapshot.written;\n\n const steps = Object.values(snapshot.collected.flows).flatMap((flow) => flow.steps);\n const resolved = steps.filter((step) => step.found === true).length;\n const missing = steps.filter((step) => step.found === false).length;\n\n return {\n steps: {\n checked: resolved + missing,\n resolved,\n missing,\n unchecked: steps.length - resolved - missing,\n },\n routes: snapshot.routes,\n features: snapshot.collected.featuresIndex,\n tasks: snapshot.collected.tasksIndex,\n counts: checkGrimoire(snapshot).counts,\n written: [written.features, written.apps, written.tasks, written.releases].some(\n (items) => items.length > 0,\n ),\n book: {\n files: files.length,\n modules: new Set(files.map((file) => file.module)).size,\n builtAt: snapshot.book.manifest.builtAt,\n },\n apps: {\n apps: written.apps.length,\n pages: written.apps.reduce((total, app) => total + app.pages.length, 0),\n screens: written.apps.reduce((total, app) => total + app.screens.length, 0),\n },\n releases: written.releases.length,\n birdView: attentionOf(matrix(snapshot)),\n results: testResultsInfo(snapshot),\n host: snapshot.host ?? null,\n };\n}\n\n/** The features listing: the features index with each README summary and flow headings. */\nexport function features(snapshot: GrimoireSnapshot): GrimoireFeaturesAnswer {\n const written = new Map(snapshot.written.features.map((feature) => [feature.id, feature]));\n\n return {\n features: snapshot.collected.featuresIndex.features.map((entry) => {\n const source = written.get(entry.id);\n const headings = new Map(\n (source?.flows ?? []).map((flow) => [flow.id.value, flow.heading?.value ?? null]),\n );\n\n return {\n ...entry,\n summary: source?.readme?.summary ?? null,\n flows: entry.flows.map((flow) => ({ ...flow, heading: headings.get(flow.id) ?? null })),\n };\n }),\n };\n}\n\nexport function search(snapshot: GrimoireSnapshot, text: string, limit?: number): ScrySearchResult {\n return ask<ScrySearchResult>(snapshot, {\n type: \"search\",\n text,\n ...(limit !== undefined && Number.isFinite(limit) && limit > 0\n ? { limit: Math.min(limit, 100) }\n : {}),\n });\n}\n\nexport function file(snapshot: GrimoireSnapshot, path: string | undefined): ScryFileResult {\n return ask(snapshot, { type: \"file\", file: required(path, \"path\") });\n}\n\nexport function impact(snapshot: GrimoireSnapshot, path: string | undefined): ScryImpactResult {\n return ask(snapshot, { type: \"impact\", file: required(path, \"path\") });\n}\n\nexport function route(\n snapshot: GrimoireSnapshot,\n method: string | undefined,\n path: string | undefined,\n): ScryRouteResult {\n return ask(snapshot, {\n type: \"route\",\n method: required(method, \"method\"),\n path: required(path, \"path\"),\n });\n}\n\nexport function feature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireFeatureAnswer {\n const wanted = required(id, \"feature\");\n const result = ask<ScryFeatureResult>(snapshot, { type: \"feature\", feature: wanted });\n const written = snapshot.written.features.find((item) => item.id === wanted);\n\n if (written === undefined)\n throw new GrimoirePanelError(404, `No feature \"${wanted}\" is written.`);\n\n return {\n ...result,\n map: featureMap(snapshot, written),\n fileGroups: featureFileGroups(snapshot, result.bookmap.own),\n proofs: featureProofs(snapshot, written),\n };\n}\n\nexport function flow(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): ScryFlowResult {\n return ask(snapshot, {\n type: \"flow\",\n feature: required(featureId, \"feature\"),\n flow: required(flowId, \"flow\"),\n });\n}\n\nexport function apps(snapshot: GrimoireSnapshot): GrimoireAppsAnswer {\n return {\n apps: snapshot.written.apps.map((app) => ({\n id: app.id.value,\n type: app.type.value,\n root: app.root.value,\n pages: app.pages.map((page) => page.id),\n screens: app.screens.map((screen) => screen.id),\n rows: [...app.pages, ...app.screens].map((item) => ({\n id: item.id,\n type: item.type,\n route: item.route?.value ?? item.screen?.value ?? null,\n heading: item.heading?.value ?? null,\n origin: item.origin?.value ?? null,\n layout: item.layout?.value ?? null,\n blocks: item.blocks.length,\n })),\n })),\n };\n}\n\nfunction findApp(snapshot: GrimoireSnapshot, id: string | undefined): WrittenApp {\n const app = snapshot.written.apps.find((candidate) => candidate.id.value === id);\n\n if (app === undefined)\n throw new GrimoirePanelError(404, `No app \"${id ?? \"\"}\" is written in grimoire/apps.`);\n\n return app;\n}\n\n/** A page or screen by its id or its route. */\nexport function findPage(app: WrittenApp, key: string): WrittenPage | undefined {\n return [...app.pages, ...app.screens].find(\n (page) => page.id === key || page.route?.value === key || page.screen?.value === key,\n );\n}\n\nexport function page(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoirePageAnswer {\n const app = findApp(snapshot, appId);\n const written = findPage(app, required(key, \"page\"));\n\n if (written === undefined) {\n throw new GrimoirePanelError(\n 404,\n `App \"${app.id.value}\" has no page or screen \"${key ?? \"\"}\".`,\n );\n }\n\n const match = snapshot.apps[app.id.value];\n const route = written.route?.value ?? written.screen?.value ?? null;\n let book: BookPage | BookScreen | null = null;\n\n if (route !== null && match?.site) {\n book =\n snapshot.book.facts.pages.find(\n (candidate) => candidate.site === match.site?.id && candidate.route === route,\n ) ?? null;\n } else if (route !== null && match?.mobile) {\n book = match.mobile.screens.find((screen) => screen.route === route) ?? null;\n }\n\n const layoutId = written.layout?.value ?? null;\n\n return {\n page: written,\n layout:\n layoutId === null ? null : (app.layouts.find((layout) => layout.id === layoutId) ?? null),\n book,\n };\n}\n\nexport function tasks(snapshot: GrimoireSnapshot): TasksIndex {\n return snapshot.collected.tasksIndex;\n}\n\nexport function releases(snapshot: GrimoireSnapshot): GrimoireReleasesAnswer {\n return {\n releases: snapshot.written.releases.map((release) => ({\n release: release.release.value,\n date: release.date.value,\n file: release.file,\n })),\n };\n}\n\nexport function release(snapshot: GrimoireSnapshot, id: string | undefined): WrittenRelease {\n const found = snapshot.written.releases.find((candidate) => candidate.release.value === id);\n\n if (found === undefined)\n throw new GrimoirePanelError(404, `No release \"${id ?? \"\"}\" in grimoire/releases.`);\n\n return found;\n}\n\nexport function check(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n return checkGrimoire(snapshot);\n}\n\nfunction graphOrNotFound(graph: GrimoireGraph | null, what: string): GrimoireGraph {\n if (graph === null) throw new GrimoirePanelError(404, `${what} is not in the book.`);\n\n return graph;\n}\n\nexport function graphOfFile(snapshot: GrimoireSnapshot, path: string | undefined): GrimoireGraph {\n const target = required(path, \"path\");\n\n return graphOrNotFound(fileGraph(snapshot, target), `\"${target}\"`);\n}\n\nexport function graphOfFeature(snapshot: GrimoireSnapshot, id: string | undefined): GrimoireGraph {\n const target = required(id, \"feature\");\n\n return graphOrNotFound(featureGraph(snapshot, target), `Feature \"${target}\"`);\n}\n\nexport function graphOfPage(\n snapshot: GrimoireSnapshot,\n appId: string | undefined,\n key: string | undefined,\n): GrimoireGraph {\n const target = required(key, \"page\");\n\n return graphOrNotFound(pageGraph(snapshot, required(appId, \"app\"), target), `Page \"${target}\"`);\n}\n\nexport function graphOfModules(snapshot: GrimoireSnapshot): GrimoireGraph {\n return moduleGraph(snapshot);\n}\n\n// ── Compact flow, step files, check pages and groups ───────────────────────\n\n/** `GET /flows/:feature/:flow`: the compact flow answer (step counts, direct imports, health, neighbours). */\nexport function flowAnswer(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n): GrimoireFlowAnswer {\n return compactFlow(snapshot, flow(snapshot, featureId, flowId));\n}\n\n/** A whole number from a query value, or a 400 naming the parameter. */\nfunction whole(value: string | undefined, name: string, fallback: number, min: number): number {\n if (value === undefined || value === \"\") return fallback;\n\n const number = Number(value);\n\n if (!Number.isInteger(number) || number < min) {\n throw new GrimoirePanelError(400, `\"${name}\" must be a whole number of ${min} or more.`);\n }\n\n return number;\n}\n\n/** `GET /flows/:feature/:flow/steps/:index/files`: one page of a step's files. */\nexport function stepFiles(\n snapshot: GrimoireSnapshot,\n featureId: string | undefined,\n flowId: string | undefined,\n index: string | undefined,\n query: { set?: string | undefined; offset?: string | undefined; limit?: string | undefined },\n): GrimoireStepFilesAnswer {\n const feature = required(featureId, \"feature\");\n const id = required(flowId, \"flow\");\n const set = query.set === undefined || query.set === \"\" ? \"reachable\" : query.set;\n\n if (!(STEP_FILE_SETS as readonly string[]).includes(set)) {\n throw new GrimoirePanelError(\n 400,\n `Unknown set \"${set}\". Use one of: ${STEP_FILE_SETS.join(\", \")}.`,\n );\n }\n\n const stepIndex = whole(required(index, \"index\"), \"index\", 0, 0);\n const offset = whole(query.offset, \"offset\", 0, 0);\n const limit = Math.min(\n whole(query.limit, \"limit\", STEP_FILES_PAGE_LIMIT, 1),\n STEP_FILES_PAGE_LIMIT,\n );\n const written = snapshot.written.features\n .find((item) => item.id === feature)\n ?.flows.find((item) => item.id.value === id);\n const bookmap = written === undefined ? undefined : snapshot.collected.flows[written.ref];\n\n if (written === undefined || bookmap === undefined) {\n throw new GrimoirePanelError(404, `No flow ${feature}/${id} is written.`);\n }\n\n const step = bookmap.steps.find((item) => item.index === stepIndex);\n\n if (step === undefined) {\n throw new GrimoirePanelError(404, `${written.ref} has no step ${stepIndex}.`);\n }\n\n return stepFilePage(snapshot, bookmap, step, set as StepFileSet, offset, limit);\n}\n\n/** `GET /check?code=&feature=&flow=&severity=&state=&offset=&limit=`: matching findings, paged. */\nexport function checkPage(\n snapshot: GrimoireSnapshot,\n filter: GrimoireCheckFilter,\n): GrimoireCheckPage {\n const report = checkGrimoire(snapshot);\n const limit = Math.min(Math.max(1, Math.floor(filter.limit ?? 100)), 500);\n const offset = Math.max(0, Math.floor(filter.offset ?? 0));\n const code = filter.code?.trim().toUpperCase();\n const matching = report.findings.filter((finding) => {\n if (code !== undefined && code !== \"\" && finding.code !== code) return false;\n if (filter.severity !== undefined && finding.severity !== filter.severity) return false;\n if (filter.state !== undefined && finding.expected !== (filter.state === \"expected\"))\n return false;\n if (filter.flow !== undefined && filter.flow !== \"\" && finding.subject.flow !== filter.flow) {\n return false;\n }\n\n if (filter.feature !== undefined && filter.feature !== \"\") {\n return featureOfFinding(finding) === filter.feature;\n }\n\n return true;\n });\n\n return {\n ...report,\n findings: matching.slice(offset, offset + limit),\n total: matching.length,\n offset,\n limit,\n };\n}\n\n/** The feature a finding belongs to: its subject, else the feature of its flow, else `(none)`. */\nfunction featureOfFinding(finding: GrimoireFinding): string {\n return finding.subject.feature ?? finding.subject.flow?.split(\"/\")[0] ?? \"(none)\";\n}\n\n/** `GET /check/groups`: the check by code, errors first, then by count. */\nexport function checkGroups(snapshot: GrimoireSnapshot): GrimoireCheckGroups {\n const report = checkGrimoire(snapshot);\n const byCode = new Map<string, GrimoireFinding[]>();\n\n for (const finding of report.findings) {\n byCode.set(finding.code, [...(byCode.get(finding.code) ?? []), finding]);\n }\n\n const groups: GrimoireCheckGroup[] = [];\n\n for (const [code, findings] of byCode) {\n const definition = explainGrimoireCode(code);\n const unexpected = findings.filter((finding) => !finding.expected);\n const features = new Map<string, number>();\n\n for (const finding of unexpected) {\n const feature = featureOfFinding(finding);\n\n features.set(feature, (features.get(feature) ?? 0) + 1);\n }\n\n groups.push({\n code,\n severity: findings[0]?.severity ?? definition?.severity ?? \"warning\",\n area: definition?.area ?? \"\",\n title: definition?.title ?? code,\n fix: definition?.fix ?? findings[0]?.hint ?? \"\",\n count: unexpected.length,\n expected: findings.length - unexpected.length,\n features: [...features]\n .map(([feature, count]) => ({ feature, count }))\n .sort((left, right) => right.count - left.count || (left.feature < right.feature ? -1 : 1)),\n });\n }\n\n groups.sort(\n (left, right) =>\n (left.severity === right.severity ? 0 : left.severity === \"error\" ? -1 : 1) ||\n right.count - left.count ||\n (left.code < right.code ? -1 : 1),\n );\n\n return { counts: report.counts, ok: report.ok, groups };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,AAAgB;CAEhB,AAAO,YAAY,YAAoB,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;AAyEA,SAAS,IAAY,UAA4B,OAA2C;CAC1F,IAAI;EACF,OAAO,KAAK,UAAU,KAAK;CAC7B,SAAS,OAAO;EACd,MAAM,OAAQ,MAA6B;EAE3C,IAAI,OAAO,SAAS,YAAY,eAAe,IAAI,GACjD,MAAM,IAAI,mBAAmB,SAAS,WAAW,MAAM,KAAM,MAAgB,OAAO;EAGtF,MAAM;CACR;AACF;AAEA,SAAS,SAAS,OAA2B,MAAsB;CACjE,IAAI,UAAU,UAAa,UAAU,IAAI,MAAM,IAAI,mBAAmB,KAAK,YAAY,KAAK,GAAG;CAE/F,OAAO;AACT;AAEA,SAAgB,QAAQ,UAA6C;CACnE,MAAM,QAAQ,SAAS,KAAK,MAAM;CAClC,MAAM,UAAU,SAAS;CAEzB,MAAM,QAAQ,OAAO,OAAO,SAAS,UAAU,KAAK,CAAC,CAAC,SAAS,SAAS,KAAK,KAAK;CAClF,MAAM,WAAW,MAAM,QAAQ,SAAS,KAAK,UAAU,IAAI,CAAC,CAAC;CAC7D,MAAM,UAAU,MAAM,QAAQ,SAAS,KAAK,UAAU,KAAK,CAAC,CAAC;CAE7D,OAAO;EACL,OAAO;GACL,SAAS,WAAW;GACpB;GACA;GACA,WAAW,MAAM,SAAS,WAAW;EACvC;EACA,QAAQ,SAAS;EACjB,UAAU,SAAS,UAAU;EAC7B,OAAO,SAAS,UAAU;EAC1B,QAAQ,cAAc,QAAQ,CAAC,CAAC;EAChC,SAAS;GAAC,QAAQ;GAAU,QAAQ;GAAM,QAAQ;GAAO,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
|
|
6
6
|
nodes = /* @__PURE__ */ new Map();
|
|
7
7
|
edges = /* @__PURE__ */ new Map();
|
|
8
|
-
node(id, label, type) {
|
|
8
|
+
node(id, label, type, extra = {}) {
|
|
9
9
|
if (this.nodes.has(id)) return true;
|
|
10
10
|
if (this.nodes.size >= 60) return false;
|
|
11
11
|
this.nodes.set(id, {
|
|
12
12
|
id,
|
|
13
13
|
label,
|
|
14
|
-
type
|
|
14
|
+
type,
|
|
15
|
+
...extra
|
|
15
16
|
});
|
|
16
17
|
return true;
|
|
17
18
|
}
|
|
@@ -109,6 +110,8 @@ function pageGraph(snapshot, app, pageKey) {
|
|
|
109
110
|
}
|
|
110
111
|
return graph.build();
|
|
111
112
|
}
|
|
113
|
+
/** A module with more files than this shows its file count in the label. */
|
|
114
|
+
const MODULE_COUNT_LABEL_FROM = 500;
|
|
112
115
|
/** Modules as nodes, weighted import edges between them; the most connected modules when there are more than the limit. */
|
|
113
116
|
function moduleGraph(snapshot) {
|
|
114
117
|
const moduleOf = /* @__PURE__ */ new Map();
|
|
@@ -129,7 +132,14 @@ function moduleGraph(snapshot) {
|
|
|
129
132
|
}
|
|
130
133
|
const modules = [...sizes.keys()].sort((left, right) => (degree.get(right) ?? 0) - (degree.get(left) ?? 0) || left.localeCompare(right)).slice(0, 60);
|
|
131
134
|
const graph = new GraphBuilder();
|
|
132
|
-
for (const module of modules)
|
|
135
|
+
for (const module of modules) {
|
|
136
|
+
const files = sizes.get(module) ?? 0;
|
|
137
|
+
graph.node(`module:${module}`, files > 500 ? `${module} (${files.toLocaleString("en-US")} files)` : module, "module", {
|
|
138
|
+
title: `${module} (${files.toLocaleString("en-US")} ${files === 1 ? "file" : "files"})`,
|
|
139
|
+
group: module.startsWith("src/app/") ? "modules" : "roots",
|
|
140
|
+
files
|
|
141
|
+
});
|
|
142
|
+
}
|
|
133
143
|
for (const [key, weight] of [...weights.entries()].sort(([left], [right]) => left.localeCompare(right))) {
|
|
134
144
|
const [from, to] = key.split("\n");
|
|
135
145
|
if (from !== void 0 && to !== void 0) graph.edge(`module:${from}`, `module:${to}`, "imports", weight);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphs.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/graphs.ts"],"sourcesContent":["/**\n * The small graphs of the tab: a file's neighbours, a feature and its\n * neighbours, a page and its blocks, and module coupling. Each answer has at\n * most `GRAPH_LIMIT` nodes. Node ids carry their kind (`file:`, `feature:`,\n * `flow:`, `page:`, `block:`, `layout:`, `module:`, `app:`) so the view can link them.\n */\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\n\n/** The most nodes a graph answer holds. */\nexport const GRAPH_LIMIT = 60;\n\nexport type GraphNode = { id: string; label: string; type: string };\nexport type GraphEdge = { from: string; to: string; type: string; weight?: number };\nexport type GrimoireGraph = { nodes: GraphNode[]; edges: GraphEdge[] };\n\n/** Collects nodes and edges, dropping what goes over the limit. */\nclass GraphBuilder {\n private readonly nodes = new Map<string, GraphNode>();\n private readonly edges = new Map<string, GraphEdge>();\n\n public node(id: string, label: string, type: string): boolean {\n if (this.nodes.has(id)) return true;\n\n if (this.nodes.size >= GRAPH_LIMIT) return false;\n\n this.nodes.set(id, { id, label, type });\n\n return true;\n }\n\n public edge(from: string, to: string, type: string, weight?: number): void {\n if (!this.nodes.has(from) || !this.nodes.has(to) || from === to) return;\n\n const key = `${from}\\n${to}\\n${type}`;\n\n if (this.edges.has(key)) return;\n\n this.edges.set(key, weight === undefined ? { from, to, type } : { from, to, type, weight });\n }\n\n public build(): GrimoireGraph {\n return { nodes: [...this.nodes.values()], edges: [...this.edges.values()] };\n }\n}\n\n/** The short name shown for a project path. */\nfunction fileLabel(file: string): string {\n const parts = file.split(\"/\");\n\n return parts.slice(-2).join(\"/\");\n}\n\n/** A file, the files it imports and the files that import it. `null` when the file is not in the book. */\nexport function fileGraph(snapshot: GrimoireSnapshot, file: string): GrimoireGraph | null {\n const entry = snapshot.book.facts.files.find((candidate) => candidate.file === file);\n\n if (entry === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `file:${file}`;\n\n graph.node(center, fileLabel(file), \"center\");\n\n for (const target of entry.imports) {\n if (target.file === null) continue;\n\n if (graph.node(`file:${target.file}`, fileLabel(target.file), \"file\")) {\n graph.edge(center, `file:${target.file}`, \"imports\");\n }\n }\n\n for (const importer of entry.importedBy) {\n if (graph.node(`file:${importer}`, fileLabel(importer), \"file\")) {\n graph.edge(`file:${importer}`, center, \"imports\");\n }\n }\n\n return graph.build();\n}\n\n/** A feature, its flows, the apps showing them and the features it borrows from, lends to or affects. `null` for an unknown feature. */\nexport function featureGraph(snapshot: GrimoireSnapshot, feature: string): GrimoireGraph | null {\n const written = snapshot.written.features.find((candidate) => candidate.id === feature);\n\n if (written === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `feature:${feature}`;\n\n graph.node(center, feature, \"center\");\n\n for (const flow of written.flows) {\n const id = `flow:${flow.ref}`;\n\n if (graph.node(id, flow.id.value, \"flow\")) graph.edge(center, id, \"has\");\n\n for (const step of flow.steps) {\n if (step.affects === null) continue;\n\n const other = `feature:${step.affects.feature}`;\n\n if (graph.node(other, step.affects.feature, \"feature\")) graph.edge(id, other, \"affects\");\n }\n }\n\n const bookmap = snapshot.collected.features[feature];\n\n for (const borrowed of bookmap?.borrowed ?? []) {\n if (borrowed.owner === null) continue;\n\n const other = `feature:${borrowed.owner}`;\n\n if (graph.node(other, borrowed.owner, \"feature\")) graph.edge(center, other, \"borrows\");\n }\n\n for (const [other, ownership] of Object.entries(snapshot.ownership.features)) {\n if (\n other !== feature &&\n ownership.borrowed.some((file) => snapshot.ownership.files[file]?.owner === feature)\n ) {\n if (graph.node(`feature:${other}`, other, \"feature\"))\n graph.edge(`feature:${other}`, center, \"borrows\");\n }\n }\n\n for (const [flowRef, flowMap] of Object.entries(snapshot.collected.flows)) {\n if (flowMap.feature !== feature) continue;\n\n for (const shown of flowMap.shownBy) {\n const id = `app:${shown.app}`;\n\n if (graph.node(id, shown.app, \"app\")) graph.edge(id, `flow:${flowRef}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** A page (or screen), its layout, its blocks and the flows the blocks show. `null` for an unknown page. */\nexport function pageGraph(\n snapshot: GrimoireSnapshot,\n app: string,\n pageKey: string,\n): GrimoireGraph | null {\n const written = snapshot.written.apps.find((candidate) => candidate.id.value === app);\n const page = [...(written?.pages ?? []), ...(written?.screens ?? [])].find(\n (candidate) =>\n candidate.id === pageKey ||\n candidate.route?.value === pageKey ||\n candidate.screen?.value === pageKey,\n );\n\n if (written === undefined || page === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `page:${app}/${page.id}`;\n\n graph.node(center, page.heading?.value ?? page.id, \"center\");\n\n const layoutId = page.layout?.value ?? null;\n const layout =\n layoutId === null ? undefined : written.layouts.find((candidate) => candidate.id === layoutId);\n\n if (layout !== undefined && graph.node(`layout:${app}/${layout.id}`, layout.id, \"layout\")) {\n graph.edge(`layout:${app}/${layout.id}`, center, \"wraps\");\n }\n\n const blocks = [...(layout?.blocks ?? []), ...page.blocks];\n\n for (const block of blocks) {\n const id = `block:${app}/${page.id}/${block.block}`;\n\n if (!graph.node(id, block.block, \"block\")) continue;\n\n graph.edge(center, id, \"shows\");\n\n if (block.flow !== null && graph.node(`flow:${block.flow}`, block.flow, \"flow\")) {\n graph.edge(id, `flow:${block.flow}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** Modules as nodes, weighted import edges between them; the most connected modules when there are more than the limit. */\nexport function moduleGraph(snapshot: GrimoireSnapshot): GrimoireGraph {\n const moduleOf = new Map<string, string>();\n const sizes = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n moduleOf.set(file.file, file.module);\n sizes.set(file.module, (sizes.get(file.module) ?? 0) + 1);\n }\n\n const weights = new Map<string, number>();\n const degree = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n for (const target of file.imports) {\n const to = target.file === null ? undefined : moduleOf.get(target.file);\n\n if (to === undefined || to === file.module) continue;\n\n const key = `${file.module}\\n${to}`;\n\n weights.set(key, (weights.get(key) ?? 0) + 1);\n degree.set(file.module, (degree.get(file.module) ?? 0) + 1);\n degree.set(to, (degree.get(to) ?? 0) + 1);\n }\n }\n\n const modules = [...sizes.keys()]\n .sort(\n (left, right) =>\n (degree.get(right) ?? 0) - (degree.get(left) ?? 0) || left.localeCompare(right),\n )\n .slice(0, GRAPH_LIMIT);\n const graph = new GraphBuilder();\n\n for (const module of modules)\n graph.node(`module:${module}`, `${module} (${sizes.get(module) ?? 0})`, \"module\");\n\n for (const [key, weight] of [...weights.entries()].sort(([left], [right]) =>\n left.localeCompare(right),\n )) {\n const [from, to] = key.split(\"\\n\");\n\n if (from !== undefined && to !== undefined)\n graph.edge(`module:${from}`, `module:${to}`, \"imports\", weight);\n }\n\n return graph.build();\n}\n"],"mappings":";;AASA,MAAa,cAAc;;AAO3B,IAAM,eAAN,MAAmB;CACjB,AAAiB,wBAAQ,IAAI,IAAuB;CACpD,AAAiB,wBAAQ,IAAI,IAAuB;CAEpD,AAAO,KAAK,IAAY,OAAe,MAAuB;EAC5D,IAAI,KAAK,MAAM,IAAI,EAAE,GAAG,OAAO;EAE/B,IAAI,KAAK,MAAM,YAAqB,OAAO;EAE3C,KAAK,MAAM,IAAI,IAAI;GAAE;GAAI;GAAO;EAAK,CAAC;EAEtC,OAAO;CACT;CAEA,AAAO,KAAK,MAAc,IAAY,MAAc,QAAuB;EACzE,IAAI,CAAC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,MAAM,IAAI,EAAE,KAAK,SAAS,IAAI;EAEjE,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,IAAI;EAE/B,IAAI,KAAK,MAAM,IAAI,GAAG,GAAG;EAEzB,KAAK,MAAM,IAAI,KAAK,WAAW,SAAY;GAAE;GAAM;GAAI;EAAK,IAAI;GAAE;GAAM;GAAI;GAAM;EAAO,CAAC;CAC5F;CAEA,AAAO,QAAuB;EAC5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devtools/graphs.ts"],"sourcesContent":["/**\n * The small graphs of the tab: a file's neighbours, a feature and its\n * neighbours, a page and its blocks, and module coupling. Each answer has at\n * most `GRAPH_LIMIT` nodes. Node ids carry their kind (`file:`, `feature:`,\n * `flow:`, `page:`, `block:`, `layout:`, `module:`, `app:`) so the view can link them.\n */\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\n\n/** The most nodes a graph answer holds. */\nexport const GRAPH_LIMIT = 60;\n\nexport type GraphNode = {\n id: string;\n label: string;\n type: string;\n /** The full name for a tooltip, when `label` is shortened or carries a count. */\n title?: string;\n /** Module graph: `modules` for `src/app/<module>` folders, `roots` for the other roots (sites, mobile, config). */\n group?: \"modules\" | \"roots\";\n /** Module graph: how many files the module holds. */\n files?: number;\n};\nexport type GraphEdge = { from: string; to: string; type: string; weight?: number };\nexport type GrimoireGraph = { nodes: GraphNode[]; edges: GraphEdge[] };\n\n/** Collects nodes and edges, dropping what goes over the limit. */\nclass GraphBuilder {\n private readonly nodes = new Map<string, GraphNode>();\n private readonly edges = new Map<string, GraphEdge>();\n\n public node(\n id: string,\n label: string,\n type: string,\n extra: Partial<Omit<GraphNode, \"id\" | \"label\" | \"type\">> = {},\n ): boolean {\n if (this.nodes.has(id)) return true;\n\n if (this.nodes.size >= GRAPH_LIMIT) return false;\n\n this.nodes.set(id, { id, label, type, ...extra });\n\n return true;\n }\n\n public edge(from: string, to: string, type: string, weight?: number): void {\n if (!this.nodes.has(from) || !this.nodes.has(to) || from === to) return;\n\n const key = `${from}\\n${to}\\n${type}`;\n\n if (this.edges.has(key)) return;\n\n this.edges.set(key, weight === undefined ? { from, to, type } : { from, to, type, weight });\n }\n\n public build(): GrimoireGraph {\n return { nodes: [...this.nodes.values()], edges: [...this.edges.values()] };\n }\n}\n\n/** The short name shown for a project path. */\nfunction fileLabel(file: string): string {\n const parts = file.split(\"/\");\n\n return parts.slice(-2).join(\"/\");\n}\n\n/** A file, the files it imports and the files that import it. `null` when the file is not in the book. */\nexport function fileGraph(snapshot: GrimoireSnapshot, file: string): GrimoireGraph | null {\n const entry = snapshot.book.facts.files.find((candidate) => candidate.file === file);\n\n if (entry === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `file:${file}`;\n\n graph.node(center, fileLabel(file), \"center\");\n\n for (const target of entry.imports) {\n if (target.file === null) continue;\n\n if (graph.node(`file:${target.file}`, fileLabel(target.file), \"file\")) {\n graph.edge(center, `file:${target.file}`, \"imports\");\n }\n }\n\n for (const importer of entry.importedBy) {\n if (graph.node(`file:${importer}`, fileLabel(importer), \"file\")) {\n graph.edge(`file:${importer}`, center, \"imports\");\n }\n }\n\n return graph.build();\n}\n\n/** A feature, its flows, the apps showing them and the features it borrows from, lends to or affects. `null` for an unknown feature. */\nexport function featureGraph(snapshot: GrimoireSnapshot, feature: string): GrimoireGraph | null {\n const written = snapshot.written.features.find((candidate) => candidate.id === feature);\n\n if (written === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `feature:${feature}`;\n\n graph.node(center, feature, \"center\");\n\n for (const flow of written.flows) {\n const id = `flow:${flow.ref}`;\n\n if (graph.node(id, flow.id.value, \"flow\")) graph.edge(center, id, \"has\");\n\n for (const step of flow.steps) {\n if (step.affects === null) continue;\n\n const other = `feature:${step.affects.feature}`;\n\n if (graph.node(other, step.affects.feature, \"feature\")) graph.edge(id, other, \"affects\");\n }\n }\n\n const bookmap = snapshot.collected.features[feature];\n\n for (const borrowed of bookmap?.borrowed ?? []) {\n if (borrowed.owner === null) continue;\n\n const other = `feature:${borrowed.owner}`;\n\n if (graph.node(other, borrowed.owner, \"feature\")) graph.edge(center, other, \"borrows\");\n }\n\n for (const [other, ownership] of Object.entries(snapshot.ownership.features)) {\n if (\n other !== feature &&\n ownership.borrowed.some((file) => snapshot.ownership.files[file]?.owner === feature)\n ) {\n if (graph.node(`feature:${other}`, other, \"feature\"))\n graph.edge(`feature:${other}`, center, \"borrows\");\n }\n }\n\n for (const [flowRef, flowMap] of Object.entries(snapshot.collected.flows)) {\n if (flowMap.feature !== feature) continue;\n\n for (const shown of flowMap.shownBy) {\n const id = `app:${shown.app}`;\n\n if (graph.node(id, shown.app, \"app\")) graph.edge(id, `flow:${flowRef}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** A page (or screen), its layout, its blocks and the flows the blocks show. `null` for an unknown page. */\nexport function pageGraph(\n snapshot: GrimoireSnapshot,\n app: string,\n pageKey: string,\n): GrimoireGraph | null {\n const written = snapshot.written.apps.find((candidate) => candidate.id.value === app);\n const page = [...(written?.pages ?? []), ...(written?.screens ?? [])].find(\n (candidate) =>\n candidate.id === pageKey ||\n candidate.route?.value === pageKey ||\n candidate.screen?.value === pageKey,\n );\n\n if (written === undefined || page === undefined) return null;\n\n const graph = new GraphBuilder();\n const center = `page:${app}/${page.id}`;\n\n graph.node(center, page.heading?.value ?? page.id, \"center\");\n\n const layoutId = page.layout?.value ?? null;\n const layout =\n layoutId === null ? undefined : written.layouts.find((candidate) => candidate.id === layoutId);\n\n if (layout !== undefined && graph.node(`layout:${app}/${layout.id}`, layout.id, \"layout\")) {\n graph.edge(`layout:${app}/${layout.id}`, center, \"wraps\");\n }\n\n const blocks = [...(layout?.blocks ?? []), ...page.blocks];\n\n for (const block of blocks) {\n const id = `block:${app}/${page.id}/${block.block}`;\n\n if (!graph.node(id, block.block, \"block\")) continue;\n\n graph.edge(center, id, \"shows\");\n\n if (block.flow !== null && graph.node(`flow:${block.flow}`, block.flow, \"flow\")) {\n graph.edge(id, `flow:${block.flow}`, \"shows\");\n }\n }\n\n return graph.build();\n}\n\n/** A module with more files than this shows its file count in the label. */\nexport const MODULE_COUNT_LABEL_FROM = 500;\n\n/** Modules as nodes, weighted import edges between them; the most connected modules when there are more than the limit. */\nexport function moduleGraph(snapshot: GrimoireSnapshot): GrimoireGraph {\n const moduleOf = new Map<string, string>();\n const sizes = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n moduleOf.set(file.file, file.module);\n sizes.set(file.module, (sizes.get(file.module) ?? 0) + 1);\n }\n\n const weights = new Map<string, number>();\n const degree = new Map<string, number>();\n\n for (const file of snapshot.book.facts.files) {\n for (const target of file.imports) {\n const to = target.file === null ? undefined : moduleOf.get(target.file);\n\n if (to === undefined || to === file.module) continue;\n\n const key = `${file.module}\\n${to}`;\n\n weights.set(key, (weights.get(key) ?? 0) + 1);\n degree.set(file.module, (degree.get(file.module) ?? 0) + 1);\n degree.set(to, (degree.get(to) ?? 0) + 1);\n }\n }\n\n const modules = [...sizes.keys()]\n .sort(\n (left, right) =>\n (degree.get(right) ?? 0) - (degree.get(left) ?? 0) || left.localeCompare(right),\n )\n .slice(0, GRAPH_LIMIT);\n const graph = new GraphBuilder();\n\n for (const module of modules) {\n const files = sizes.get(module) ?? 0;\n\n // The label is the name; the file count is in the label only for a very large module, else in the tooltip.\n graph.node(\n `module:${module}`,\n files > MODULE_COUNT_LABEL_FROM\n ? `${module} (${files.toLocaleString(\"en-US\")} files)`\n : module,\n \"module\",\n {\n title: `${module} (${files.toLocaleString(\"en-US\")} ${files === 1 ? \"file\" : \"files\"})`,\n group: module.startsWith(\"src/app/\") ? \"modules\" : \"roots\",\n files,\n },\n );\n }\n\n for (const [key, weight] of [...weights.entries()].sort(([left], [right]) =>\n left.localeCompare(right),\n )) {\n const [from, to] = key.split(\"\\n\");\n\n if (from !== undefined && to !== undefined)\n graph.edge(`module:${from}`, `module:${to}`, \"imports\", weight);\n }\n\n return graph.build();\n}\n"],"mappings":";;AASA,MAAa,cAAc;;AAiB3B,IAAM,eAAN,MAAmB;CACjB,AAAiB,wBAAQ,IAAI,IAAuB;CACpD,AAAiB,wBAAQ,IAAI,IAAuB;CAEpD,AAAO,KACL,IACA,OACA,MACA,QAA2D,CAAC,GACnD;EACT,IAAI,KAAK,MAAM,IAAI,EAAE,GAAG,OAAO;EAE/B,IAAI,KAAK,MAAM,YAAqB,OAAO;EAE3C,KAAK,MAAM,IAAI,IAAI;GAAE;GAAI;GAAO;GAAM,GAAG;EAAM,CAAC;EAE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,KACJ,UAAU,UACV,cACI,GAAG,OAAO,IAAI,MAAM,eAAe,OAAO,EAAE,WAC5C,QACJ,UACA;GACE,OAAO,GAAG,OAAO,IAAI,MAAM,eAAe,OAAO,EAAE,GAAG,UAAU,IAAI,SAAS,QAAQ;GACrF,OAAO,OAAO,WAAW,UAAU,IAAI,YAAY;GACnD;EACF,CACF;CACF;CAEA,KAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,QAAQ,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WAChE,KAAK,cAAc,KAAK,CAC1B,GAAG;EACD,MAAM,CAAC,MAAM,MAAM,IAAI,MAAM,IAAI;EAEjC,IAAI,SAAS,UAAa,OAAO,QAC/B,MAAM,KAAK,UAAU,QAAQ,UAAU,MAAM,WAAW,MAAM;CAClE;CAEA,OAAO,MAAM,MAAM;AACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"mappings":";;;;;YAkCY;EACV,QAAQ,SAAS;EACjB,OAAO,SAAS;EAChB;;EAEA;;;YAIU;EACV,eAAe;EACf;EACA;EACA;;;YAIU;EACV;EACA;EACA,eAAe;EACf;IACE;IACA;IACA,UAAU,SAAS;;EAErB,SAAS,SAAS,wBAAwB;;EAE1C;IAAU;IAAa;;;EAEvB,QAAQ;;EAER;;;YAIU;;EAEV;;;;;EAKA;;EAEA,UAAU,qBAAqB,QAAQ;;;;;;EAMvC;;;;;;;EAOA;;EAEA,eAAe,iBAAiB;;;wBAWZ,sBACpB,SAAS,uBACR,QAAQ"}
|
package/esm/devtools/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { matrix } from "./matrix.mjs";
|
|
2
|
+
import { GrimoirePanelError, apps, check, checkGroups, checkPage, feature, features, file, flowAnswer, graphOfFeature, graphOfFile, graphOfModules, graphOfPage, impact, page, release, releases, route, search, stepFiles, summary, tasks } from "./data.mjs";
|
|
3
|
+
import { approveFromPanel, rejectFromPanel } from "./approvals.mjs";
|
|
4
|
+
import { productFeature, productFlow, productMap, productWhatsNew } from "./product-map.mjs";
|
|
3
5
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
4
6
|
import { buildProductSiteData, exportGrimoireSite, exportGrimoireSiteDetailed } from "./site.mjs";
|
|
5
7
|
import path from "node:path";
|
|
@@ -101,6 +103,7 @@ async function grimoireDevtoolsPanel(context) {
|
|
|
101
103
|
view: new URL("../../ui/product-map.js", import.meta.url),
|
|
102
104
|
routes: [
|
|
103
105
|
"/product",
|
|
106
|
+
"/product/whats-new",
|
|
104
107
|
"/product/features/:feature",
|
|
105
108
|
"/product/flows/:feature/:flow"
|
|
106
109
|
],
|
|
@@ -155,6 +158,10 @@ async function grimoireDevtoolsPanel(context) {
|
|
|
155
158
|
path: "/product",
|
|
156
159
|
handler: product((snapshot, _request, options) => productMap(snapshot, options))
|
|
157
160
|
},
|
|
161
|
+
{
|
|
162
|
+
path: "/product/whats-new",
|
|
163
|
+
handler: product((snapshot, _request, options) => productWhatsNew(snapshot, options))
|
|
164
|
+
},
|
|
158
165
|
{
|
|
159
166
|
path: "/product/features/:feature",
|
|
160
167
|
handler: product((snapshot, { params }, options) => productFeature(snapshot, params.feature, options))
|
|
@@ -163,6 +170,13 @@ async function grimoireDevtoolsPanel(context) {
|
|
|
163
170
|
path: "/product/flows/:feature/:flow",
|
|
164
171
|
handler: product((snapshot, { params }, options) => productFlow(snapshot, params.feature, params.flow, options))
|
|
165
172
|
},
|
|
173
|
+
{
|
|
174
|
+
path: "/matrix",
|
|
175
|
+
handler: answer((snapshot) => ({
|
|
176
|
+
...matrix(snapshot),
|
|
177
|
+
development
|
|
178
|
+
}))
|
|
179
|
+
},
|
|
166
180
|
{
|
|
167
181
|
path: "/apps",
|
|
168
182
|
handler: answer((snapshot) => apps(snapshot))
|
|
@@ -209,6 +223,22 @@ async function grimoireDevtoolsPanel(context) {
|
|
|
209
223
|
{
|
|
210
224
|
path: "/graph/modules",
|
|
211
225
|
handler: answer((snapshot) => graphOfModules(snapshot))
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
method: "POST",
|
|
229
|
+
path: "/approve",
|
|
230
|
+
handler: async (request) => {
|
|
231
|
+
if (!development || request.shared === true) throw new GrimoirePanelError(403, "Approving is only possible in development.");
|
|
232
|
+
return approveFromPanel(await source.get(), request.body);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
method: "POST",
|
|
237
|
+
path: "/reject",
|
|
238
|
+
handler: async (request) => {
|
|
239
|
+
if (!development || request.shared === true) throw new GrimoirePanelError(403, "Rejecting is only possible in development.");
|
|
240
|
+
return rejectFromPanel(await source.get(), request.body);
|
|
241
|
+
}
|
|
212
242
|
}
|
|
213
243
|
]
|
|
214
244
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["data.summary","data.search","data.file","data.impact","data.route","data.features","data.feature","data.flowAnswer","data.stepFiles","data.apps","data.page","data.tasks","data.releases","data.release","data.check","data.checkPage","data.checkGroups","data.graphOfFile","data.graphOfFeature","data.graphOfPage","data.graphOfModules"],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/devtools`: the Grimoire tab of the devtools\n * dashboard. An app enables it in `src/config/devtools.ts`:\n *\n * ```ts\n * panels: [\"@warlock.js/grimoire/devtools\"]\n * ```\n *\n * The default export is a panel factory (devtools' `DevtoolsPanelExport`),\n * typed structurally here so this entry needs no `@warlock.js/devtools`\n * import. The browser view lives in the package's `ui/` folder. Data routes\n * open the snapshot with `routes: \"cached\"` (never booting the app) and keep\n * the generated book up to date; agent-written files are only read.\n */\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport path from \"node:path\";\nimport type { GrimoireCheckFilter } from \"./answers\";\nimport * as data from \"./data\";\nimport { productFeature, productFlow, productMap, type ProductErrorSummary } from \"./product-map\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\nexport { buildProductSiteData, exportGrimoireSite, exportGrimoireSiteDetailed } from \"./site\";\nexport type { ExportGrimoireSiteOptions, GrimoireSiteExport } from \"./site\";\n\n/** The parts of devtools' `DevtoolsPanelRequest` the routes read. */\nexport type GrimoirePanelRequest = {\n params: Readonly<Record<string, string>>;\n query: Readonly<Record<string, string | readonly string[]>>;\n body: unknown;\n /** `true` when the request came through a read-only share link. */\n shared?: boolean;\n};\n\n/** Devtools' `DevtoolsPanelShare`, structurally: what a share link may show. */\nexport type GrimoireDevtoolsPanelShare = {\n view: string | URL;\n routes: readonly string[];\n assets?: readonly string[];\n files?: boolean;\n};\n\n/** Devtools' `DevtoolsPanel`, structurally. */\nexport type GrimoireDevtoolsPanel = {\n id: string;\n title: string;\n view: string | URL;\n routes?: readonly {\n method?: \"GET\" | \"POST\";\n path: string;\n handler: (request: GrimoirePanelRequest) => unknown;\n }[];\n assets?: Readonly<Record<string, string | URL>>;\n /** A folder of images served next to the panel. */\n files?: { dir: string; extensions?: readonly string[] };\n /** What a read-only share link may show. */\n share?: GrimoireDevtoolsPanelShare;\n /** Safe for the production monitor: the tab only reads (see `GrimoirePanelContext.mode`). */\n production?: boolean;\n};\n\n/** What the panel factory takes: devtools passes `{ root, mode }`; the rest is for tests and custom setups. */\nexport type GrimoirePanelContext = {\n /** The app root. */\n root: string;\n /**\n * Where the dashboard runs. In `\"production\"` the tab writes no files:\n * it reads the book as it is on disk. Default: development.\n */\n mode?: \"development\" | \"production\";\n /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long an opened snapshot is reused when the book did not change (ms).\n * Default in development: 2000, longer after a slow open; the old snapshot is served while a\n * background open refreshes it. Default in production: until the book changes.\n */\n ttlMs?: number;\n /**\n * Where the test results are read from (project-relative or absolute).\n * Default `grimoire/book/test-results.json`. Set it when the deploy ships\n * the results from CI; the Vitest reporter writes there with\n * `grimoireReporter({ file })`.\n */\n testResultsFile?: string;\n /** Captured error groups of the monitor (counts only), for the product map's health. Devtools passes it. */\n errors?: () => Promise<readonly ProductErrorSummary[]>;\n};\n\n/** The first value of a query parameter. */\nfunction one(query: GrimoirePanelRequest[\"query\"], name: string): string | undefined {\n const value = query[name];\n\n return Array.isArray(value) ? value[0] : (value as string | undefined);\n}\n\n/** Build the panel for the app at `root`. */\nexport async function grimoireDevtoolsPanel(\n context: GrimoirePanelContext,\n): Promise<GrimoireDevtoolsPanel> {\n // In development the tab keeps Warlock's generated files (book, book maps, indexes) up to date, so\n // the next open is incremental. In production it writes nothing. Agent-written files are only read,\n // and cached routes never boot the app.\n const development = context.mode !== \"production\";\n let live: Promise<BookAdapter> | undefined;\n const liveAdapter = (): Promise<BookAdapter> =>\n (live ??= import(\"../warlock\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({ live: true }),\n ));\n const source = createSnapshotSource(context.root, {\n write: context.mode !== \"production\",\n mode: context.mode ?? \"development\",\n // The panel runs inside the app's own process, so it never boots the app again (that would start every\n // connector twice and register the route and event modules twice). In development the default adapter\n // reads the route, event and job facts from the live registries; a custom adapter is used as given.\n ...(context.adapter === undefined\n ? development\n ? { adapter: liveAdapter, liveFacts: true }\n : {}\n : { adapter: context.adapter }),\n ...(context.ttlMs === undefined ? {} : { ttlMs: context.ttlMs }),\n ...(context.testResultsFile === undefined ? {} : { testResultsFile: context.testResultsFile }),\n });\n\n // Start opening the book now so the first tab view is fast. In development this runs in the background\n // (never awaited, failures ignored) and only with the default adapter, so a custom one is not called early.\n if (!development || context.adapter === undefined) source.warm();\n\n const answer =\n <Answer>(read: (snapshot: GrimoireSnapshot, request: GrimoirePanelRequest) => Answer) =>\n async (request: GrimoirePanelRequest): Promise<Answer> =>\n read(await source.get(), request);\n\n /** The product map answers: the shared flag from the request, the errors fetched per request. */\n const product =\n <Answer>(\n read: (\n snapshot: GrimoireSnapshot,\n request: GrimoirePanelRequest,\n options: { shared: boolean; errors: readonly ProductErrorSummary[] | null },\n ) => Answer,\n ) =>\n async (request: GrimoirePanelRequest): Promise<Answer> => {\n const snapshot = await source.get();\n let errors: readonly ProductErrorSummary[] | null = null;\n\n try {\n errors = (await context.errors?.()) ?? null;\n } catch {\n errors = null;\n }\n\n return read(snapshot, request, { shared: request.shared === true, errors });\n };\n\n const number = (value: string | undefined): number | undefined => {\n if (value === undefined || value === \"\") return undefined;\n\n const parsed = Number(value);\n\n return Number.isFinite(parsed) ? parsed : undefined;\n };\n\n const checkFilter = (query: GrimoirePanelRequest[\"query\"]): GrimoireCheckFilter | null => {\n const filter: GrimoireCheckFilter = {};\n const code = one(query, \"code\");\n const feature = one(query, \"feature\");\n const flow = one(query, \"flow\");\n const severity = one(query, \"severity\");\n const state = one(query, \"state\");\n const offset = number(one(query, \"offset\"));\n const limit = number(one(query, \"limit\"));\n let any = false;\n\n if (code) {\n filter.code = code;\n any = true;\n }\n if (feature) {\n filter.feature = feature;\n any = true;\n }\n if (flow) {\n filter.flow = flow;\n any = true;\n }\n if (severity === \"error\" || severity === \"warning\") {\n filter.severity = severity;\n any = true;\n }\n if (state === \"expected\" || state === \"unexpected\") {\n filter.state = state;\n any = true;\n }\n if (offset !== undefined) {\n filter.offset = offset;\n any = true;\n }\n if (limit !== undefined) {\n filter.limit = limit;\n any = true;\n }\n\n return any ? filter : null;\n };\n\n return {\n id: \"grimoire\",\n title: \"Grimoire\",\n production: true,\n view: new URL(\"../../ui/grimoire-view.js\", import.meta.url),\n assets: {\n \"grimoire.css\": new URL(\"../../ui/grimoire.css\", import.meta.url),\n \"product-map.js\": new URL(\"../../ui/product-map.js\", import.meta.url),\n \"product-map.css\": new URL(\"../../ui/product-map.css\", import.meta.url),\n },\n files: { dir: path.join(context.root, \"grimoire\", \"screenshots\") },\n share: {\n view: new URL(\"../../ui/product-map.js\", import.meta.url),\n routes: [\"/product\", \"/product/features/:feature\", \"/product/flows/:feature/:flow\"],\n assets: [\"product-map.css\"],\n files: true,\n },\n routes: [\n { path: \"/summary\", handler: answer((snapshot) => data.summary(snapshot)) },\n {\n path: \"/search\",\n handler: answer((snapshot, { query }) => {\n const limit = Number(one(query, \"limit\"));\n\n return data.search(\n snapshot,\n one(query, \"q\") ?? \"\",\n Number.isFinite(limit) && limit > 0 ? limit : undefined,\n );\n }),\n },\n {\n path: \"/file\",\n handler: answer((snapshot, { query }) => data.file(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/impact\",\n handler: answer((snapshot, { query }) => data.impact(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/route\",\n handler: answer((snapshot, { query }) =>\n data.route(snapshot, one(query, \"method\"), one(query, \"path\")),\n ),\n },\n { path: \"/features\", handler: answer((snapshot) => data.features(snapshot)) },\n {\n path: \"/features/:feature\",\n handler: answer((snapshot, { params }) => data.feature(snapshot, params.feature)),\n },\n {\n path: \"/flows/:feature/:flow\",\n handler: answer((snapshot, { params }) =>\n data.flowAnswer(snapshot, params.feature, params.flow),\n ),\n },\n {\n path: \"/flows/:feature/:flow/steps/:index/files\",\n handler: answer((snapshot, { params, query }) =>\n data.stepFiles(snapshot, params.feature, params.flow, params.index, {\n set: one(query, \"set\"),\n offset: one(query, \"offset\"),\n limit: one(query, \"limit\"),\n }),\n ),\n },\n {\n path: \"/product\",\n handler: product((snapshot, _request, options) => productMap(snapshot, options)),\n },\n {\n path: \"/product/features/:feature\",\n handler: product((snapshot, { params }, options) =>\n productFeature(snapshot, params.feature, options),\n ),\n },\n {\n path: \"/product/flows/:feature/:flow\",\n handler: product((snapshot, { params }, options) =>\n productFlow(snapshot, params.feature, params.flow, options),\n ),\n },\n { path: \"/apps\", handler: answer((snapshot) => data.apps(snapshot)) },\n {\n path: \"/apps/:app/pages/:page\",\n handler: answer((snapshot, { params }) => data.page(snapshot, params.app, params.page)),\n },\n { path: \"/tasks\", handler: answer((snapshot) => data.tasks(snapshot)) },\n { path: \"/releases\", handler: answer((snapshot) => data.releases(snapshot)) },\n {\n path: \"/releases/:release\",\n handler: answer((snapshot, { params }) => data.release(snapshot, params.release)),\n },\n {\n path: \"/check\",\n handler: answer((snapshot, { query }) => {\n const filter = checkFilter(query);\n\n return filter === null ? data.check(snapshot) : data.checkPage(snapshot, filter);\n }),\n },\n { path: \"/check/groups\", handler: answer((snapshot) => data.checkGroups(snapshot)) },\n {\n path: \"/graph/file\",\n handler: answer((snapshot, { query }) => data.graphOfFile(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/graph/feature/:feature\",\n handler: answer((snapshot, { params }) => data.graphOfFeature(snapshot, params.feature)),\n },\n {\n path: \"/graph/page\",\n handler: answer((snapshot, { query }) =>\n data.graphOfPage(snapshot, one(query, \"app\"), one(query, \"page\")),\n ),\n },\n { path: \"/graph/modules\", handler: answer((snapshot) => data.graphOfModules(snapshot)) },\n ],\n };\n}\n\nexport default grimoireDevtoolsPanel;\n"],"mappings":";;;;;;;;AA0FA,SAAS,IAAI,OAAsC,MAAkC;CACnF,MAAM,QAAQ,MAAM;CAEpB,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAM;AAC5C;;AAGA,eAAsB,sBACpB,SACgC;CAIhC,MAAM,cAAc,QAAQ,SAAS;CACrC,IAAI;CACJ,MAAM,oBACH,SAAS,OAAO,uBAAa,CAAC,MAAM,EAAE,2BACrC,qBAAqB,EAAE,MAAM,KAAK,CAAC,CACrC;CACF,MAAM,SAAS,qBAAqB,QAAQ,MAAM;EAChD,OAAO,QAAQ,SAAS;EACxB,MAAM,QAAQ,QAAQ;EAItB,GAAI,QAAQ,YAAY,SACpB,cACE;GAAE,SAAS;GAAa,WAAW;EAAK,IACxC,CAAC,IACH,EAAE,SAAS,QAAQ,QAAQ;EAC/B,GAAI,QAAQ,UAAU,S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,OAAO,CAAC;GAClF;GACA;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,YAAY;KACvC,MAAM,SAAS,YAAY,KAAK;KAEhC,OAAO,WAAW,OAAOC,MAAW,QAAQ,IAAIC,UAAe,UAAU,MAAM;IACjF,CAAC;GACH;GACA;IAAE,MAAM;IAAiB,SAAS,QAAQ,aAAaC,YAAiB,QAAQ,CAAC;GAAE;GACnF;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,YAAYC,YAAiB,UAAU,IAAI,OAAO,MAAM,CAAC,CAAC;GACzF;GACA;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,aAAaC,eAAoB,UAAU,OAAO,OAAO,CAAC;GACzF;GACA;IACE,MAAM;IACN,SAAS,QAAQ,UAAU,EAAE,YAC3BC,YAAiB,UAAU,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,MAAM,CAAC,CAClE;GACF;GACA;IAAE,MAAM;IAAkB,SAAS,QAAQ,aAAaC,eAAoB,QAAQ,CAAC;GAAE;EACzF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["data.summary","data.search","data.file","data.impact","data.route","data.features","data.feature","data.flowAnswer","data.stepFiles","data.apps","data.page","data.tasks","data.releases","data.release","data.check","data.checkPage","data.checkGroups","data.graphOfFile","data.graphOfFeature","data.graphOfPage","data.graphOfModules","data.GrimoirePanelError"],"sources":["../../../../../../../../packages/grimoire/src/devtools/index.ts"],"sourcesContent":["/**\n * `@warlock.js/grimoire/devtools`: the Grimoire tab of the devtools\n * dashboard. An app enables it in `src/config/devtools.ts`:\n *\n * ```ts\n * panels: [\"@warlock.js/grimoire/devtools\"]\n * ```\n *\n * The default export is a panel factory (devtools' `DevtoolsPanelExport`),\n * typed structurally here so this entry needs no `@warlock.js/devtools`\n * import. The browser view lives in the package's `ui/` folder. Data routes\n * open the snapshot with `routes: \"cached\"` (never booting the app) and keep\n * the generated book up to date; agent-written files are only read.\n */\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport path from \"node:path\";\nimport type { GrimoireCheckFilter } from \"./answers\";\nimport { approveFromPanel, rejectFromPanel } from \"./approvals\";\nimport * as data from \"./data\";\nimport { matrix } from \"./matrix\";\nimport {\n productFeature,\n productFlow,\n productMap,\n productWhatsNew,\n type ProductErrorSummary,\n} from \"./product-map\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\nexport { buildProductSiteData, exportGrimoireSite, exportGrimoireSiteDetailed } from \"./site\";\nexport type { ExportGrimoireSiteOptions, GrimoireSiteExport } from \"./site\";\n\n/** The parts of devtools' `DevtoolsPanelRequest` the routes read. */\nexport type GrimoirePanelRequest = {\n params: Readonly<Record<string, string>>;\n query: Readonly<Record<string, string | readonly string[]>>;\n body: unknown;\n /** `true` when the request came through a read-only share link. */\n shared?: boolean;\n};\n\n/** Devtools' `DevtoolsPanelShare`, structurally: what a share link may show. */\nexport type GrimoireDevtoolsPanelShare = {\n view: string | URL;\n routes: readonly string[];\n assets?: readonly string[];\n files?: boolean;\n};\n\n/** Devtools' `DevtoolsPanel`, structurally. */\nexport type GrimoireDevtoolsPanel = {\n id: string;\n title: string;\n view: string | URL;\n routes?: readonly {\n method?: \"GET\" | \"POST\";\n path: string;\n handler: (request: GrimoirePanelRequest) => unknown;\n }[];\n assets?: Readonly<Record<string, string | URL>>;\n /** A folder of images served next to the panel. */\n files?: { dir: string; extensions?: readonly string[] };\n /** What a read-only share link may show. */\n share?: GrimoireDevtoolsPanelShare;\n /** Safe for the production monitor: the tab only reads (see `GrimoirePanelContext.mode`). */\n production?: boolean;\n};\n\n/** What the panel factory takes: devtools passes `{ root, mode }`; the rest is for tests and custom setups. */\nexport type GrimoirePanelContext = {\n /** The app root. */\n root: string;\n /**\n * Where the dashboard runs. In `\"production\"` the tab writes no files:\n * it reads the book as it is on disk. Default: development.\n */\n mode?: \"development\" | \"production\";\n /** The adapter to open the book with. Default: the Warlock adapter, loaded on first request. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long an opened snapshot is reused when the book did not change (ms).\n * Default in development: 2000, longer after a slow open; the old snapshot is served while a\n * background open refreshes it. Default in production: until the book changes.\n */\n ttlMs?: number;\n /**\n * Where the test results are read from (project-relative or absolute).\n * Default `grimoire/book/test-results.json`. Set it when the deploy ships\n * the results from CI; the Vitest reporter writes there with\n * `grimoireReporter({ file })`.\n */\n testResultsFile?: string;\n /** Captured error groups of the monitor (counts only), for the product map's health. Devtools passes it. */\n errors?: () => Promise<readonly ProductErrorSummary[]>;\n};\n\n/** The first value of a query parameter. */\nfunction one(query: GrimoirePanelRequest[\"query\"], name: string): string | undefined {\n const value = query[name];\n\n return Array.isArray(value) ? value[0] : (value as string | undefined);\n}\n\n/** Build the panel for the app at `root`. */\nexport async function grimoireDevtoolsPanel(\n context: GrimoirePanelContext,\n): Promise<GrimoireDevtoolsPanel> {\n // In development the tab keeps Warlock's generated files (book, book maps, indexes) up to date, so\n // the next open is incremental. In production it writes nothing. Agent-written files are only read,\n // and cached routes never boot the app.\n const development = context.mode !== \"production\";\n let live: Promise<BookAdapter> | undefined;\n const liveAdapter = (): Promise<BookAdapter> =>\n (live ??= import(\"../warlock\").then(({ createWarlockAdapter }) =>\n createWarlockAdapter({ live: true }),\n ));\n const source = createSnapshotSource(context.root, {\n write: context.mode !== \"production\",\n mode: context.mode ?? \"development\",\n // The panel runs inside the app's own process, so it never boots the app again (that would start every\n // connector twice and register the route and event modules twice). In development the default adapter\n // reads the route, event and job facts from the live registries; a custom adapter is used as given.\n ...(context.adapter === undefined\n ? development\n ? { adapter: liveAdapter, liveFacts: true }\n : {}\n : { adapter: context.adapter }),\n ...(context.ttlMs === undefined ? {} : { ttlMs: context.ttlMs }),\n ...(context.testResultsFile === undefined ? {} : { testResultsFile: context.testResultsFile }),\n });\n\n // Start opening the book now so the first tab view is fast. In development this runs in the background\n // (never awaited, failures ignored) and only with the default adapter, so a custom one is not called early.\n if (!development || context.adapter === undefined) source.warm();\n\n const answer =\n <Answer>(read: (snapshot: GrimoireSnapshot, request: GrimoirePanelRequest) => Answer) =>\n async (request: GrimoirePanelRequest): Promise<Answer> =>\n read(await source.get(), request);\n\n /** The product map answers: the shared flag from the request, the errors fetched per request. */\n const product =\n <Answer>(\n read: (\n snapshot: GrimoireSnapshot,\n request: GrimoirePanelRequest,\n options: { shared: boolean; errors: readonly ProductErrorSummary[] | null },\n ) => Answer,\n ) =>\n async (request: GrimoirePanelRequest): Promise<Answer> => {\n const snapshot = await source.get();\n let errors: readonly ProductErrorSummary[] | null = null;\n\n try {\n errors = (await context.errors?.()) ?? null;\n } catch {\n errors = null;\n }\n\n return read(snapshot, request, { shared: request.shared === true, errors });\n };\n\n const number = (value: string | undefined): number | undefined => {\n if (value === undefined || value === \"\") return undefined;\n\n const parsed = Number(value);\n\n return Number.isFinite(parsed) ? parsed : undefined;\n };\n\n const checkFilter = (query: GrimoirePanelRequest[\"query\"]): GrimoireCheckFilter | null => {\n const filter: GrimoireCheckFilter = {};\n const code = one(query, \"code\");\n const feature = one(query, \"feature\");\n const flow = one(query, \"flow\");\n const severity = one(query, \"severity\");\n const state = one(query, \"state\");\n const offset = number(one(query, \"offset\"));\n const limit = number(one(query, \"limit\"));\n let any = false;\n\n if (code) {\n filter.code = code;\n any = true;\n }\n if (feature) {\n filter.feature = feature;\n any = true;\n }\n if (flow) {\n filter.flow = flow;\n any = true;\n }\n if (severity === \"error\" || severity === \"warning\") {\n filter.severity = severity;\n any = true;\n }\n if (state === \"expected\" || state === \"unexpected\") {\n filter.state = state;\n any = true;\n }\n if (offset !== undefined) {\n filter.offset = offset;\n any = true;\n }\n if (limit !== undefined) {\n filter.limit = limit;\n any = true;\n }\n\n return any ? filter : null;\n };\n\n return {\n id: \"grimoire\",\n title: \"Grimoire\",\n production: true,\n view: new URL(\"../../ui/grimoire-view.js\", import.meta.url),\n assets: {\n \"grimoire.css\": new URL(\"../../ui/grimoire.css\", import.meta.url),\n \"product-map.js\": new URL(\"../../ui/product-map.js\", import.meta.url),\n \"product-map.css\": new URL(\"../../ui/product-map.css\", import.meta.url),\n },\n files: { dir: path.join(context.root, \"grimoire\", \"screenshots\") },\n share: {\n view: new URL(\"../../ui/product-map.js\", import.meta.url),\n routes: [\n \"/product\",\n \"/product/whats-new\",\n \"/product/features/:feature\",\n \"/product/flows/:feature/:flow\",\n ],\n assets: [\"product-map.css\"],\n files: true,\n },\n routes: [\n { path: \"/summary\", handler: answer((snapshot) => data.summary(snapshot)) },\n {\n path: \"/search\",\n handler: answer((snapshot, { query }) => {\n const limit = Number(one(query, \"limit\"));\n\n return data.search(\n snapshot,\n one(query, \"q\") ?? \"\",\n Number.isFinite(limit) && limit > 0 ? limit : undefined,\n );\n }),\n },\n {\n path: \"/file\",\n handler: answer((snapshot, { query }) => data.file(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/impact\",\n handler: answer((snapshot, { query }) => data.impact(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/route\",\n handler: answer((snapshot, { query }) =>\n data.route(snapshot, one(query, \"method\"), one(query, \"path\")),\n ),\n },\n { path: \"/features\", handler: answer((snapshot) => data.features(snapshot)) },\n {\n path: \"/features/:feature\",\n handler: answer((snapshot, { params }) => data.feature(snapshot, params.feature)),\n },\n {\n path: \"/flows/:feature/:flow\",\n handler: answer((snapshot, { params }) =>\n data.flowAnswer(snapshot, params.feature, params.flow),\n ),\n },\n {\n path: \"/flows/:feature/:flow/steps/:index/files\",\n handler: answer((snapshot, { params, query }) =>\n data.stepFiles(snapshot, params.feature, params.flow, params.index, {\n set: one(query, \"set\"),\n offset: one(query, \"offset\"),\n limit: one(query, \"limit\"),\n }),\n ),\n },\n {\n path: \"/product\",\n handler: product((snapshot, _request, options) => productMap(snapshot, options)),\n },\n {\n path: \"/product/whats-new\",\n handler: product((snapshot, _request, options) => productWhatsNew(snapshot, options)),\n },\n {\n path: \"/product/features/:feature\",\n handler: product((snapshot, { params }, options) =>\n productFeature(snapshot, params.feature, options),\n ),\n },\n {\n path: \"/product/flows/:feature/:flow\",\n handler: product((snapshot, { params }, options) =>\n productFlow(snapshot, params.feature, params.flow, options),\n ),\n },\n // The Bird view: never shared (it names the test status of every criterion).\n {\n path: \"/matrix\",\n handler: answer((snapshot) => ({ ...matrix(snapshot), development })),\n },\n { path: \"/apps\", handler: answer((snapshot) => data.apps(snapshot)) },\n {\n path: \"/apps/:app/pages/:page\",\n handler: answer((snapshot, { params }) => data.page(snapshot, params.app, params.page)),\n },\n { path: \"/tasks\", handler: answer((snapshot) => data.tasks(snapshot)) },\n { path: \"/releases\", handler: answer((snapshot) => data.releases(snapshot)) },\n {\n path: \"/releases/:release\",\n handler: answer((snapshot, { params }) => data.release(snapshot, params.release)),\n },\n {\n path: \"/check\",\n handler: answer((snapshot, { query }) => {\n const filter = checkFilter(query);\n\n return filter === null ? data.check(snapshot) : data.checkPage(snapshot, filter);\n }),\n },\n { path: \"/check/groups\", handler: answer((snapshot) => data.checkGroups(snapshot)) },\n {\n path: \"/graph/file\",\n handler: answer((snapshot, { query }) => data.graphOfFile(snapshot, one(query, \"path\"))),\n },\n {\n path: \"/graph/feature/:feature\",\n handler: answer((snapshot, { params }) => data.graphOfFeature(snapshot, params.feature)),\n },\n {\n path: \"/graph/page\",\n handler: answer((snapshot, { query }) =>\n data.graphOfPage(snapshot, one(query, \"app\"), one(query, \"page\")),\n ),\n },\n { path: \"/graph/modules\", handler: answer((snapshot) => data.graphOfModules(snapshot)) },\n // The Bird view's buttons write the approved baseline: development only, never through a share link.\n {\n method: \"POST\",\n path: \"/approve\",\n handler: async (request) => {\n if (!development || request.shared === true) {\n throw new data.GrimoirePanelError(403, \"Approving is only possible in development.\");\n }\n\n return approveFromPanel(await source.get(), request.body);\n },\n },\n {\n method: \"POST\",\n path: \"/reject\",\n handler: async (request) => {\n if (!development || request.shared === true) {\n throw new data.GrimoirePanelError(403, \"Rejecting is only possible in development.\");\n }\n\n return rejectFromPanel(await source.get(), request.body);\n },\n },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U,EAAE,YAC3BC,YAAiB,UAAU,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,MAAM,CAAC,CAClE;GACF;GACA;IAAE,MAAM;IAAkB,SAAS,QAAQ,aAAaC,eAAoB,QAAQ,CAAC;GAAE;GAEvF;IACE,QAAQ;IACR,MAAM;IACN,SAAS,OAAO,YAAY;KAC1B,IAAI,CAAC,eAAe,QAAQ,WAAW,MACrC,MAAM,IAAIC,mBAAwB,KAAK,4CAA4C;KAGrF,OAAO,iBAAiB,MAAM,OAAO,IAAI,GAAG,QAAQ,IAAI;IAC1D;GACF;GACA;IACE,QAAQ;IACR,MAAM;IACN,SAAS,OAAO,YAAY;KAC1B,IAAI,CAAC,eAAe,QAAQ,WAAW,MACrC,MAAM,IAAIA,mBAAwB,KAAK,4CAA4C;KAGrF,OAAO,gBAAgB,MAAM,OAAO,IAAI,GAAG,QAAQ,IAAI;IACzD;GACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { DEFAULT_GRIMOIRE_SETTINGS } from "../contracts/settings.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/grimoire/src/devtools/matrix.ts
|
|
4
|
+
/** The feature that is listed first: the project's design rules. */
|
|
5
|
+
const DESIGN_SYSTEM = "design-system";
|
|
6
|
+
/** Worst first: the state of a cell is the first of these that applies. */
|
|
7
|
+
const STATE_ORDER = [
|
|
8
|
+
"rejected",
|
|
9
|
+
"fail",
|
|
10
|
+
"changed",
|
|
11
|
+
"stale",
|
|
12
|
+
"not-run",
|
|
13
|
+
"no-test",
|
|
14
|
+
"pass"
|
|
15
|
+
];
|
|
16
|
+
const cellKey = (ref, criterion, language) => `${ref}\n${criterion}\n${language}`;
|
|
17
|
+
function inputsOf(snapshot) {
|
|
18
|
+
const settings = snapshot.settings ?? DEFAULT_GRIMOIRE_SETTINGS;
|
|
19
|
+
const shots = snapshot.shots ?? null;
|
|
20
|
+
const captured = /* @__PURE__ */ new Map();
|
|
21
|
+
const approved = /* @__PURE__ */ new Map();
|
|
22
|
+
const drift = shots?.drift ?? [];
|
|
23
|
+
for (const capture of shots?.captures?.captures ?? []) captured.set(cellKey(capture.ref, capture.criterion, capture.language), capture);
|
|
24
|
+
for (const shot of shots?.baseline?.shots ?? []) approved.set(cellKey(shot.ref, shot.criterion, shot.language), shot.file);
|
|
25
|
+
return {
|
|
26
|
+
languages: settings.languages.length > 0 ? [...settings.languages] : [""],
|
|
27
|
+
shots,
|
|
28
|
+
captured,
|
|
29
|
+
approved,
|
|
30
|
+
mode: shots?.mode ?? settings.screenshots,
|
|
31
|
+
driftOf: (ref, criterion, language) => drift.filter((item) => item.ref === ref && item.criterion === criterion && (criterion === null || language === null || item.language === null || item.language === language))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function worst(states) {
|
|
35
|
+
return STATE_ORDER.find((state) => states.includes(state)) ?? "pass";
|
|
36
|
+
}
|
|
37
|
+
function cellOf(inputs, input) {
|
|
38
|
+
const { ref, criterion, language } = input;
|
|
39
|
+
const key = cellKey(ref, criterion, language);
|
|
40
|
+
const capture = inputs.captured.get(key) ?? null;
|
|
41
|
+
const approvedFile = inputs.approved.get(key) ?? null;
|
|
42
|
+
const items = inputs.driftOf(ref, criterion, language);
|
|
43
|
+
const baseline = inputs.shots?.baseline ?? null;
|
|
44
|
+
const standing = capture === null && approvedFile !== null && inputs.mode !== "all";
|
|
45
|
+
const shown = input.shows || input.removed && approvedFile !== null ? {
|
|
46
|
+
outcome: capture?.outcome ?? (standing && !input.removed ? "pass" : "not-run"),
|
|
47
|
+
shot: capture?.file ?? null,
|
|
48
|
+
approved: approvedFile,
|
|
49
|
+
ranAt: capture?.ranAt ?? null
|
|
50
|
+
} : null;
|
|
51
|
+
const approval = baseline === null ? null : items.some((item) => item.rejected !== null) ? "rejected" : items.length > 0 || input.removed ? "changed" : "approved";
|
|
52
|
+
const states = [];
|
|
53
|
+
if (approval === "rejected") states.push("rejected");
|
|
54
|
+
if (input.test === "fail" || shown?.outcome === "fail") states.push("fail");
|
|
55
|
+
if (approval === "changed") states.push("changed");
|
|
56
|
+
if (!input.removed) {
|
|
57
|
+
if (input.test === "stale") states.push("stale");
|
|
58
|
+
if (input.test === "not-run" || shown?.outcome === "not-run") states.push("not-run");
|
|
59
|
+
if (input.test === "no-test") states.push("no-test");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
language,
|
|
63
|
+
test: input.test,
|
|
64
|
+
shown,
|
|
65
|
+
approval,
|
|
66
|
+
drift: items.map((item) => item.id),
|
|
67
|
+
state: worst(states)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function removedCriteria(inputs, ref, approvedFlow, written) {
|
|
71
|
+
return approvedFlow.criteria.filter((criterion) => !written.has(criterion.id)).map((criterion) => ({
|
|
72
|
+
id: criterion.id,
|
|
73
|
+
text: criterion.text,
|
|
74
|
+
app: null,
|
|
75
|
+
removed: true,
|
|
76
|
+
cells: inputs.languages.map((language) => cellOf(inputs, {
|
|
77
|
+
ref,
|
|
78
|
+
criterion: criterion.id,
|
|
79
|
+
language,
|
|
80
|
+
test: "no-test",
|
|
81
|
+
shows: false,
|
|
82
|
+
removed: true
|
|
83
|
+
}))
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
function flowRow(snapshot, inputs, flow) {
|
|
87
|
+
const bookmap = snapshot.collected.flows[flow.ref];
|
|
88
|
+
const status = new Map((bookmap?.criteria ?? []).map((item) => [item.id, item.status]));
|
|
89
|
+
const shows = new Set((inputs.shots?.shows ?? []).filter((line) => line.ref === flow.ref).map((line) => line.criterion));
|
|
90
|
+
const approvedFlow = inputs.shots?.baseline?.flows.find((item) => item.ref === flow.ref);
|
|
91
|
+
const writtenIds = new Set(flow.criteria.map((criterion) => criterion.id));
|
|
92
|
+
const optedOut = flow.screenshots?.value === false || (inputs.shots?.optedOut ?? []).includes(flow.ref);
|
|
93
|
+
return {
|
|
94
|
+
ref: flow.ref,
|
|
95
|
+
id: flow.id.value,
|
|
96
|
+
title: flow.heading?.value ?? flow.id.value,
|
|
97
|
+
status: flow.status.value,
|
|
98
|
+
differsIn: flow.differs.map((line) => line.name),
|
|
99
|
+
screenshots: !optedOut,
|
|
100
|
+
removed: false,
|
|
101
|
+
criteria: [...flow.criteria.map((criterion) => ({
|
|
102
|
+
id: criterion.id,
|
|
103
|
+
text: criterion.text,
|
|
104
|
+
app: criterion.app,
|
|
105
|
+
removed: false,
|
|
106
|
+
cells: inputs.languages.map((language) => cellOf(inputs, {
|
|
107
|
+
ref: flow.ref,
|
|
108
|
+
criterion: criterion.id,
|
|
109
|
+
language,
|
|
110
|
+
test: status.get(criterion.id) ?? "no-test",
|
|
111
|
+
shows: !optedOut && inputs.mode !== "off" && shows.has(criterion.id),
|
|
112
|
+
removed: false
|
|
113
|
+
}))
|
|
114
|
+
})), ...approvedFlow === void 0 ? [] : removedCriteria(inputs, flow.ref, approvedFlow, writtenIds)],
|
|
115
|
+
drift: inputs.driftOf(flow.ref, null, null).map((item) => item.id)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function featureRow(snapshot, inputs, feature) {
|
|
119
|
+
return {
|
|
120
|
+
id: feature.id,
|
|
121
|
+
title: feature.readme?.title.value ?? feature.id,
|
|
122
|
+
designSystem: feature.id === DESIGN_SYSTEM,
|
|
123
|
+
flows: feature.flows.map((flow) => flowRow(snapshot, inputs, flow))
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Rows of the baseline that are no longer written: whole flows, and the features only they belonged to. */
|
|
127
|
+
function removedFlows(inputs, features, snapshot) {
|
|
128
|
+
const written = new Set(snapshot.written.features.flatMap((feature) => feature.flows.map((flow) => flow.ref)));
|
|
129
|
+
for (const approved of inputs.shots?.baseline?.flows ?? []) {
|
|
130
|
+
if (written.has(approved.ref)) continue;
|
|
131
|
+
const [featureId = "", flowId = ""] = approved.ref.split("/");
|
|
132
|
+
let feature = features.find((item) => item.id === featureId);
|
|
133
|
+
if (feature === void 0) {
|
|
134
|
+
feature = {
|
|
135
|
+
id: featureId,
|
|
136
|
+
title: featureId,
|
|
137
|
+
designSystem: featureId === DESIGN_SYSTEM,
|
|
138
|
+
flows: []
|
|
139
|
+
};
|
|
140
|
+
features.push(feature);
|
|
141
|
+
}
|
|
142
|
+
const flowDrift = inputs.driftOf(approved.ref, null, null).map((item) => item.id);
|
|
143
|
+
const criteria = removedCriteria(inputs, approved.ref, approved, /* @__PURE__ */ new Set()).map((row) => ({
|
|
144
|
+
...row,
|
|
145
|
+
cells: row.cells.map((cell) => ({
|
|
146
|
+
...cell,
|
|
147
|
+
drift: [.../* @__PURE__ */ new Set([...flowDrift, ...cell.drift])]
|
|
148
|
+
}))
|
|
149
|
+
}));
|
|
150
|
+
feature.flows.push({
|
|
151
|
+
ref: approved.ref,
|
|
152
|
+
id: flowId,
|
|
153
|
+
title: flowId,
|
|
154
|
+
status: null,
|
|
155
|
+
differsIn: [],
|
|
156
|
+
screenshots: true,
|
|
157
|
+
removed: true,
|
|
158
|
+
criteria,
|
|
159
|
+
drift: flowDrift
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** `GET /matrix`. */
|
|
164
|
+
function matrix(snapshot) {
|
|
165
|
+
const inputs = inputsOf(snapshot);
|
|
166
|
+
const settings = snapshot.settings ?? DEFAULT_GRIMOIRE_SETTINGS;
|
|
167
|
+
const features = snapshot.written.features.map((feature) => featureRow(snapshot, inputs, feature));
|
|
168
|
+
removedFlows(inputs, features, snapshot);
|
|
169
|
+
features.sort((left, right) => Number(right.designSystem) - Number(left.designSystem));
|
|
170
|
+
const counts = {
|
|
171
|
+
rejected: 0,
|
|
172
|
+
fail: 0,
|
|
173
|
+
changed: 0,
|
|
174
|
+
stale: 0,
|
|
175
|
+
"not-run": 0,
|
|
176
|
+
"no-test": 0,
|
|
177
|
+
pass: 0
|
|
178
|
+
};
|
|
179
|
+
for (const feature of features) for (const flow of feature.flows) for (const criterion of flow.criteria) for (const cell of criterion.cells) counts[cell.state] += 1;
|
|
180
|
+
const baseline = inputs.shots?.baseline ?? null;
|
|
181
|
+
return {
|
|
182
|
+
languages: inputs.languages,
|
|
183
|
+
mode: inputs.shots?.mode ?? settings.screenshots,
|
|
184
|
+
baseline: baseline === null ? null : { approvedAt: baseline.approvedAt },
|
|
185
|
+
features,
|
|
186
|
+
drift: inputs.shots?.drift ?? [],
|
|
187
|
+
counts
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** What needs a look in the bird-view: cells that failed, changed or were rejected, and the changes to whole flows. */
|
|
191
|
+
function attentionOf(answer) {
|
|
192
|
+
const flows = answer.features.reduce((total, feature) => total + feature.flows.reduce((sum, flow) => sum + flow.drift.length, 0), 0);
|
|
193
|
+
return answer.counts.fail + answer.counts.changed + answer.counts.rejected + flows;
|
|
194
|
+
}
|
|
195
|
+
/** Every image the matrix shows (captured and approved), as paths under `grimoire/screenshots/`, once each. */
|
|
196
|
+
function matrixImagePaths(answer) {
|
|
197
|
+
const found = /* @__PURE__ */ new Set();
|
|
198
|
+
for (const feature of answer.features) for (const flow of feature.flows) for (const criterion of flow.criteria) for (const cell of criterion.cells) {
|
|
199
|
+
if (cell.shown?.shot) found.add(cell.shown.shot);
|
|
200
|
+
if (cell.shown?.approved) found.add(cell.shown.approved);
|
|
201
|
+
}
|
|
202
|
+
return [...found].sort();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//#endregion
|
|
206
|
+
export { attentionOf, matrix, matrixImagePaths };
|
|
207
|
+
//# sourceMappingURL=matrix.mjs.map
|