From b175a1aadc36275a4c01525344365f12426500df Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:19:51 -0500 Subject: [PATCH 1/7] feat(metadata): build the docs view from the loaded model Every documentation page reads one port-neutral document of facts, the docs view, and a port builds it from the model it has already loaded rather than from re-derived JSON. This is the first step of making docs ordinary configured Mustache codegen in every port. - metadata: buildDocsView / serializeDocsView. Nodes of any type with effective attrs, members grouped by type (declaredOn for an inherited member), refs from the loader's own resolution and their reverse, claims through the gate's resolver, files and routes; the requirements flat with depth, status, links and roll-up; packages, counts, advisories and slices. Facts only, every key always present, object values in code-unit key order. - docs-site: the explorer pages read the view through a ViewIndex. build.ts, index-model.ts and types.ts are deleted, with markInherited and the seven-kind edge list. The pages look the same: a member with no row gets an empty anchor in the crumbs, and "Referenced by" and the map now carry every resolved reference. The map draws only edges whose two ends it draws. Templates are unchanged, so an ejected theme keeps working. - fixtures/explorer-conformance: shop re-pinned as the view (effective.json dropped, routes.json added); new crm case with provider.json vocabulary whose members and refs appear with no docs code that names them. - docs: docs/features/docs-view.md (the contract); explorer-data.md rewritten around the inputs; explorer-site, CONFORMANCE, READMEs and CHANGELOG updated. --- CHANGELOG.md | 40 +- docs/CONFORMANCE.md | 29 +- docs/README.md | 5 +- docs/features/docs-view.md | 262 ++ docs/features/explorer-data.md | 170 +- docs/features/explorer-site.md | 27 +- docs/features/own-your-codegen.md | 2 +- fixtures/docs-page-conformance/README.md | 2 +- fixtures/explorer-conformance/README.md | 88 +- .../explorer-conformance/crm/expected.json | 1342 ++++++ .../crm/project/metaobjects/meta.crm.json | 65 + .../crm/project/metaobjects/meta.tax.json | 8 + .../explorer-conformance/crm/provider.json | 42 + fixtures/explorer-conformance/crm/verify.json | 62 + .../explorer-conformance/shop/effective.json | 348 -- .../explorer-conformance/shop/expected.json | 3843 +++++++++++++---- .../explorer-conformance/shop/routes.json | 7 + .../cli/test/docs-page-shapes.test.ts | 60 +- .../cli/test/explorer-fixture.test.ts | 84 +- .../cli/test/explorer-site-ledger.test.ts | 8 +- .../cli/test/gen-docs-generators.test.ts | 4 +- .../cli/test/unit/rules-inert.test.ts | 39 +- .../src/generators/docs-site-file.ts | 31 +- .../test/docs-site-explorer.test.ts | 34 +- .../typescript/packages/docs-site/README.md | 8 +- .../packages/docs-site/assets/explorer.js | 2 +- .../packages/docs-site/src/explorer/build.ts | 457 -- .../packages/docs-site/src/explorer/html.ts | 4 +- .../docs-site/src/explorer/index-model.ts | 348 -- .../packages/docs-site/src/explorer/pages.ts | 332 +- .../packages/docs-site/src/explorer/site.ts | 52 +- .../packages/docs-site/src/explorer/types.ts | 135 - .../docs-site/src/explorer/view-index.ts | 375 ++ .../packages/docs-site/src/index.ts | 20 +- .../docs-site/test/explorer-build.test.ts | 177 - .../docs-site/test/explorer-site.test.ts | 106 +- .../test/fixture/custom-vocabulary.ts | 61 - .../packages/docs-site/test/fixture/views.ts | 58 + .../packages/metadata/src/docs-view/build.ts | 698 +++ .../packages/metadata/src/docs-view/index.ts | 3 + .../packages/metadata/src/docs-view/types.ts | 298 ++ .../typescript/packages/metadata/src/index.ts | 3 + .../test/docs-view-conformance.test.ts | 197 + 43 files changed, 7079 insertions(+), 2857 deletions(-) create mode 100644 docs/features/docs-view.md create mode 100644 fixtures/explorer-conformance/crm/expected.json create mode 100644 fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json create mode 100644 fixtures/explorer-conformance/crm/project/metaobjects/meta.tax.json create mode 100644 fixtures/explorer-conformance/crm/provider.json create mode 100644 fixtures/explorer-conformance/crm/verify.json delete mode 100644 fixtures/explorer-conformance/shop/effective.json create mode 100644 fixtures/explorer-conformance/shop/routes.json delete mode 100644 server/typescript/packages/docs-site/src/explorer/build.ts delete mode 100644 server/typescript/packages/docs-site/src/explorer/index-model.ts delete mode 100644 server/typescript/packages/docs-site/src/explorer/types.ts create mode 100644 server/typescript/packages/docs-site/src/explorer/view-index.ts delete mode 100644 server/typescript/packages/docs-site/test/explorer-build.test.ts delete mode 100644 server/typescript/packages/docs-site/test/fixture/custom-vocabulary.ts create mode 100644 server/typescript/packages/docs-site/test/fixture/views.ts create mode 100644 server/typescript/packages/metadata/src/docs-view/build.ts create mode 100644 server/typescript/packages/metadata/src/docs-view/index.ts create mode 100644 server/typescript/packages/metadata/src/docs-view/types.ts create mode 100644 server/typescript/packages/metadata/test/docs-view-conformance.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cfd8307b..e206603331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1341,8 +1341,7 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru for Pagefind, work at phone width, depend on the model alone (so `meta verify --codegen` holds them) and are link-checked. The graphs load Cytoscape.js from `assetBase`. `meta eject docs-site` now copies the explorer's `explorer-*.mustache` templates and `explorer.css` / - `explorer.js` beside the classic theme. `buildExplorer` takes an optional `routes` input, and - nodes carry their declaration `order`. Each `requirements.rows` entry in `meta verify + `explorer.js` beside the classic theme. Each `requirements.rows` entry in `meta verify --format json` now carries `node`: the entity's resolution key on a `WARN_REQUIREMENT_OBJECT_UNCLAIMED` row, `""` on every other row, and each finding in a `requirementLedger` row carries its `message`. See `docs/features/explorer-site.md`. @@ -1458,13 +1457,34 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru `{ "hash", "generatedBy", "sourceNode" }`. `EmittedFile.sourceNode` lets an owned generator set it, and `perEntity` sets it automatically. A file rendered from the whole model keeps the plain hash entry. The field is not called `generator`, because on the JVM that word claims ownership. - - `@metaobjectsdev/docs-site` exports `buildExplorer` and `serializeExplorer`. Together they build a - deterministic `explorer.json` from those three inputs. The file holds nodes, typed edges, the - requirement ledger, the generated files for each node, and derived slices for each package, - requirement subtree and prompt. - - Gated by the new `fixtures/explorer-conformance/` corpus. See `docs/features/explorer-data.md`. - No metamodel vocabulary changes, and `metamodelVersion` does not move. + - `@metaobjectsdev/metadata` exports `buildDocsView` and `serializeDocsView`, which build the + **docs view**: one port-neutral document of the facts every documentation page reads, built + from the model the port has already loaded, with those inputs and the routes the run mounts + as optional additions. It holds every top-level node of any type with its effective + attributes, its members grouped by type (an inherited member names the node that declares + it), the references the loader resolved and their reverse, requirement claims and generated + files; the requirements flat, with depth, status, links and the roll-up of the statuses + below; packages, counts, the gate's advisories and derived slices for each package, + requirement subtree and prompt. Facts only, no HTML, with a boolean or a count wherever a + page must choose, so a Mustache template can render it. A provider's own vocabulary gets + its members and links with no docs code: the view reads the loader's resolution, never a + list of attribute names. `docsSiteFile()` writes it as the site's `explorer.json`. + + Gated by the new `fixtures/explorer-conformance/` corpus (`shop`, and `crm` for vocabulary a + data-driven provider registers), which every port that builds the view is held to byte for + byte. See `docs/features/docs-view.md` and `docs/features/explorer-data.md`. No metamodel + vocabulary changes, and `metamodelVersion` does not move. **If you ran 1.3.0-rc.1 or rc.2:** + those candidates exported `buildExplorer`, `serializeExplorer` and the `ExplorerJson` types + from `@metaobjectsdev/docs-site` and wrote a `metaobjects-explorer/1` file built from + `meta export --effective`; all are gone. Build the view from the loaded model + (`buildDocsView({ root, verify, manifest, routes })`), pass it to `generateExplorerSite` as + `view`, and regenerate: `explorer.json` and the explorer pages change. Map edges are labelled + with the reference attribute (`objectRef`, `payloadRef`, `responseRef`, …) and, with each + page's "Referenced by", include every reference the loader resolves (`@from`, `@of`, `@via`, + `@through`, `@spine` too). An attribute links to a node only when the loader resolved it as a + reference, never because its text matches a name, and a map-valued attribute such as + `@filter` prints its keys sorted. A theme ejected from an rc needs no change. + Generated-output change — regenerate to pick it up; three-way merge preserves hand edits. - **`@flattenedColumnPrefix`: name a flattened value object's columns.** On a `field.object` with `@storage: "flattened"`, it replaces the default prefix (the field's column and `_`) verbatim; `""` keeps the members' own column names. It sits on the embedding field because one value @@ -3011,7 +3031,7 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru (`caseRow`) that a collection-name clash already took. - **The model explorer builds on a project with its own top-level vocabulary.** Two top-level nodes of different types sharing a package and a name (an entity `Lead` and a page `Lead`) - made `buildExplorer` throw `two nodes share the id`. The object now keeps the plain + made the explorer throw `two nodes share the id`. The object now keeps the plain `::` id and each other node adds its type, `acme::crm::Lead[page.list]`, as a nested sibling already did; a model with no such collision gets the same ids as before. A requirement whose id took a qualifier still takes its ledger row. diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index f222113fe5..8bd17e0ef3 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -73,7 +73,7 @@ regenerate with `ls -d fixtures//*/ | wc -l` for directory-shaped corpor | [`fixtures/cube-model/`](../fixtures/cube-model/) (FR-044 Plan 4 — the `cube-model` generator's golden Cube files, plus the canonical model's golden) | 46 cases (36 trees + 10 errors) + 1 canonical golden | ✓ (the exporter is TypeScript-only, spec R6; its `cube` lane also loads the files into a real Cube) | — | — | — | — | — | | [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 88 cases (31 core + 10 TypeScript + 9 Java + 12 Kotlin + 6 C# + 12 Python + 8 Rust) | ✓ (the first writer; core and TypeScript dialect) | ✓ (core and Java dialect; `JavaWriter` in `codegen-base`) | ✓ (core and Kotlin dialect; `KotlinWriter` in `codegen-kotlin`) | ✓ (core and C# dialect) | ✓ (core and Python dialect) | ✓ (core and Rust dialect) | | [`fixtures/contract-conformance/`](../fixtures/contract-conformance/) (FR-022 — the `contract-schema` and `openapi` generators' golden trees and refusals) | 22 cases (17 trees + 5 errors) | ✓ (one neutral engine, ADR-0034 Amendment 10; the generated API lanes also hold real traffic to the documents) | — | — | — | — | — | -| [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the `explorer.json` data spine: `meta export --effective` + `meta verify --format json` + the generated-file manifest in, one explorer document out) | 1 case (`shop`) | ✓ (the builder is TypeScript, and reads only port-neutral inputs) | — | — | — | — | — | +| [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the docs view: a loaded project + the verify payload, manifest and routes in, one `explorer.json` out) | 2 cases (`shop`, `crm`) | ✓ | — | — | — | — | — | **Rust (ADR-0065)** joined the table with its service stack. Its ledgers (the metamodel corpus's `server/rust/metaobjects/tests/conformance-expected-failures.json`, empty; the YAML @@ -897,21 +897,24 @@ message. The case list, with the rule each pins, is the (`server/typescript/packages/integration-tests/cube-live/cube-model.live.ts`) loads the same files into a real Cube. -### `fixtures/explorer-conformance/` (1 case) +### `fixtures/explorer-conformance/` (2 cases) -The `shop` case → [features/explorer-data.md](features/explorer-data.md). Its `project/` is a -small model with inheritance, a value object, a reference, a prompt with a payload and a reply, -and a five-level requirement tree that has a resolved member claim, a dangling planned claim and a -live requirement nothing implements. `effective.json` and `verify.json` are what -`meta export --effective` and `meta verify --format json` write for it, `hashes.json` is a -hand-written manifest with node provenance, and `expected.json` is the explorer document built -from the three, compared byte for byte. +The docs view → [features/docs-view.md](features/docs-view.md). Each case is a `project/` and +its optional committed inputs (`verify.json`, what `meta verify --format json` writes for it; +`hashes.json`, a hand-written manifest with node provenance; `routes.json`), and `expected.json` +is the docs view a port builds from the LOADED project and those inputs, compared byte for byte. +`shop` is a small model with inheritance, a value object, a reference, a prompt with a payload +and a reply, and a five-level requirement tree that has a resolved member claim, a dangling +planned claim and a live requirement nothing implements. `crm` adds a `provider.json`, a +data-driven provider for vocabulary the core does not register (`page.list`, `block.table`, +`capability.module`): its members and references must appear with no docs code that names them. **One port runs it:** TypeScript, in -`server/typescript/packages/docs-site/test/explorer-build.test.ts` (the builder) and -`server/typescript/packages/cli/test/explorer-fixture.test.ts` (the two committed inputs are -what the CLI writes today). The builder reads no loader, so a port that writes the same effective -JSON and verify payload feeds it unchanged. +`server/typescript/packages/metadata/test/docs-view-conformance.test.ts` (the view) and +`server/typescript/packages/cli/test/explorer-fixture.test.ts` (the committed `verify.json` files +are what the gate writes today). A port loads the project with the provider applied, builds its +own view and compares; the view reads the port's own loaded model, so it is a port's step, not a +shared input. ## Orphaned fixtures (tested but not yet documented) diff --git a/docs/README.md b/docs/README.md index 9a75224a90..546f1a58e4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -51,7 +51,8 @@ docs/ │ ├── business-rules.md # operations, permission names and lifecycles: vocabulary, load rules, verify checks (ADR-0066) │ ├── contract-emitters.md # the contract-schema and openapi generators: JSON Schema and OpenAPI for the REST contract (FR-022) │ ├── cube-export.md # the cube-model generator: reporting vocabulary as Cube data-model files (FR-044) -│ ├── explorer-data.md # explorer.json and its inputs: export --effective, the verify ledger rows, manifest provenance +│ ├── docs-view.md # the docs view (explorer.json): the port-neutral facts every docs page reads, built from the loaded model +│ ├── explorer-data.md # the docs view's inputs: the verify ledger rows, manifest provenance, routes, export --effective │ ├── explorer-site.md # the model explorer site docsSiteFile() builds from explorer.json │ ├── metadata-driven-runtime.md # one grid, one form and one route mount for every entity, read from the loaded metadata (TypeScript example, measured) │ ├── own-your-codegen.md # scaffold-and-own generator ownership (ADR-0034) @@ -89,7 +90,7 @@ this tree is documentation, not the source of truth. | Keep Prisma as the ORM, with `schema.prisma` generated from the model and gated by `verify` (TypeScript) | [`recipes/prisma.md`](recipes/prisma.md) | | Publish the API as JSON Schema or OpenAPI, and check a change against the last release | [`features/contract-emitters.md`](features/contract-emitters.md), [`recipes/check-api-against-last-release.md`](recipes/check-api-against-last-release.md) | | Export the reporting vocabulary to Cube (`cube-model`: cubes, joins, rollups; the `cube` lane that checks it against a real Cube) | [`features/cube-export.md`](features/cube-export.md) | -| Build the data a model explorer reads (`explorer.json` from `meta export --effective`, `meta verify --format json` and the generated-file manifest) | [`features/explorer-data.md`](features/explorer-data.md) | +| Build the data a model explorer reads (the docs view, `explorer.json`, from the loaded model, `meta verify --format json`, the generated-file manifest and the routes) | [`features/docs-view.md`](features/docs-view.md), [`features/explorer-data.md`](features/explorer-data.md) | | Build the model explorer site: what the software does, the model map, requirement pages, the matrix, trace and gaps (`docsSiteFile()`) | [`features/explorer-site.md`](features/explorer-site.md) | | Wire prompt construction (FR-004) | [`features/templates-and-payloads.md`](features/templates-and-payloads.md) | | Share a metadata shape across multiple instances (abstracts, `extends:`) | [`features/abstracts-and-inheritance.md`](features/abstracts-and-inheritance.md) | diff --git a/docs/features/docs-view.md b/docs/features/docs-view.md new file mode 100644 index 0000000000..7f9ad8003b --- /dev/null +++ b/docs/features/docs-view.md @@ -0,0 +1,262 @@ +# The docs view + +Every documentation page about a model reads the same facts: which nodes there are, what each +holds, what it references and what references it, which requirement claims it, and which files +were generated from it. The **docs view** is one document per build that holds those facts and +nothing else. A port builds it from the model it has already loaded, and a page is then a +template that reads it. + +The view holds facts only: no HTML, no Markdown and no sentences. Where a page must choose +(show a section or not, draw a badge or not) the view gives it a boolean or a count, so a +logic-less template such as Mustache can render it unaided. Every port that builds the view +writes the same bytes for the same model, and the shared corpus +[`fixtures/explorer-conformance/`](../../fixtures/explorer-conformance/) holds them to that. + +TypeScript builds it today. `buildDocsView` and `serializeDocsView` are exported from +`@metaobjectsdev/metadata`, and `docsSiteFile()` writes the result as the site's +`explorer.json` (see [explorer-site.md](explorer-site.md)). The other ports build it as their +own step of the same plan. The explorer pages still render their HTML in TypeScript; moving that +into templates is a later step. + +## What it is built from + +| Input | Required | What it adds | +| --- | --- | --- | +| The loaded, resolved model | yes | every node, member, attribute, reference, inheritance and claim | +| The verify payload (`meta verify --format json`) | no | each requirement's verdict, digest and findings; the counts; the advisories; which entity nobody claims | +| The generation manifest (`.metaobjects/.gen-state/.hashes/`, merged) | no | which generated files each node produced | +| The routes the run mounts (`[{ node, method, path }]`) | no | each node's REST routes | + +The builder re-derives nothing the loader already decided. Ids come from walking the +effective tree. Inheritance comes from where each effective child is declared, and references +come from the loader's own resolution of every attribute it treats as a reference. Claims are +resolved by the same resolver the requirement gate uses. A provider's vocabulary therefore +gets its members and its links with no change to the docs code. The corpus's `crm` case +declares a `page.list` and a `capability.module` in a data-driven provider, and both appear, +linked, with nothing in the builder that names them. + +The verify payload, manifest and routes are optional. A missing or malformed one leaves its +part empty, and `sources` says which were read. Claims do not need the verify payload: they are +the model's own `@implementedBy`, so they hold without it. + +The input formats are described in [explorer-data.md](explorer-data.md). + +## Conventions + +- **Every key is always present.** An absent fact is `""`, `false`, `0`, `[]` or `null`, never a + missing key, so a template never tests for existence. +- **Key order is the order on disk**, as the types below list it. +- **Sorting is by code unit**, never by locale, so every runtime sorts alike. +- **`serializeDocsView`** writes the view as JSON indented by two spaces, with one trailing + newline. +- **`format`** is `"metaobjects-docs-view/1"`. It changes when a field changes meaning or is + removed, and not when a field is added. + +### Links + +A pointer to anything in the view is a link: + +```ts +interface DocsViewLink { + label: string; // what a page prints + id: string; // the target's id; "" when unresolved + path: string; // site-relative page, with # for a member; "" when unresolved + kind: string; // "."; "" when unresolved + unresolved: boolean; +} +``` + +The `label` is a top-level node's name, a requirement's `@title` (else its name), or +`.` for a member. An unresolved link keeps the text as written in its +`label`, so a page can print it without linking it. A link to an inherited member lands on the +node that declares it, because a reference to that member resolves there. + +### Ids + +- A top-level node is `::`, or just `` with no package. +- When top-level nodes of different types share a package and a name (an entity `Lead` and an + application's page `Lead`), the object keeps the plain id, since every model reference names an + object. If none of them is an object, the first one declared keeps it. Each other one adds its + type: `acme::crm::Lead[page.list]`. +- A member is its parent's id plus `.`, or `#` when it has no name. When siblings of + different types share a name, the first one keeps `.`, because that is the node a dotted + `@implementedBy` such as `AuditEntry.id` resolves to. Each later one adds its type: + `acme::shop::AuditEntry.id[identity.primary]`. +- Two nodes that would still share an id make the builder throw, naming the id. + +### Pages and anchors + +- A top-level node's page is `model//.html`. The package directory is the + package with `::` turned into `/`, or `-root` for no package. The stem is the name, or + `.node` when the name is `index` (in any case), so it never takes the package's index + page. A node whose id carries a type qualifier adds `.-`: + `Lead.page-list.html`. +- A requirement and everything inside it land on + `requirements//.html`. +- A direct member of a top-level node lands on its owner's page at `#`. The anchor is + `m-` for a field, `m--` for anything else, and `m--` for a member + with no name. A deeper member lands on the anchor of the direct member that holds it. A page + must carry an element with every direct member's anchor, so that every link in the view lands. + +## The document + +```ts +interface DocsView { + format: "metaobjects-docs-view/1"; + sources: { requirements: boolean; files: boolean; routes: boolean }; + counts: DocsViewCounts; + packages: DocsViewPackage[]; + nodes: DocsViewNode[]; // every top-level node, sorted by id + requirements: DocsViewRequirement[]; + advisories: DocsViewAdvisory[]; + slices: DocsViewSlice[]; +} +``` + +The types are exported from `@metaobjectsdev/metadata`. + +### `nodes` + +One entry per top-level node of any type: objects, prompts, requirements, and any type a +provider registers. + +| Field | Meaning | +| --- | --- | +| `id`, `name`, `package`, `type`, `subType` | As above. `package` is the effective package. | +| `order` | Its position among the top-level nodes in declaration order, which the id sort does not keep. | +| `path` | Its page. | +| `title`, `description`, `summary` | The documentation attributes, or `""`. | +| `abstract` | As declared. | +| `extends` | A link to its super, or `null`. | +| `attrs` | Every effective attribute (see below). | +| `memberGroups` | Its members, by type (see below). | +| `refs` | Every reference from the node or any of its members, in walk order. | +| `referencedBy` | Every reference into the node or any of its members, from another top-level node. | +| `claims` | Every requirement claim on the node or on anything in it. | +| `files` | `{ generatedBy, paths }`, one group per generator, sorted by generator, paths sorted. | +| `routes` | `{ method, path }`, method upper-case, sorted by path then method, duplicates removed. | +| `unclaimed` | The gate reported that no requirement claims this entity (`WARN_REQUIREMENT_OBJECT_UNCLAIMED`, matched on the finding's `node`, never its message). | +| `counts` | `members` (direct), `refs`, `referencedBy`, `claims`, `files`, `routes`. | + +### Attributes + +```ts +interface DocsViewAttr { + name: string; // without the @ + value: unknown; // the effective value + values: { text: string; link: DocsViewLink | null }[]; +} +``` + +Attributes are the effective ones, inherited through `extends` included, sorted by name. +`value` is written as the canonical serializer writes it, with every object's keys in code-unit +order, so a map attribute such as `@intValueMap` reads the same from every port. A +string gives one value and a list of strings gives one value per element. Any other value gives +one, written as compact JSON. `link` is set only on an attribute the loader resolves as a +reference. It points at the member the value's dotted tail names when there is one, otherwise +at the node the loader bound. An attribute that merely spells a node's name is text: the view +never matches names itself. + +### Members + +```ts +interface DocsViewMemberGroup { type: string; count: number; members: DocsViewMember[] } +``` + +The members of one type (every subtype of it), in declaration order. Groups are ordered by their +first member. Grouping is by type alone, so a custom type's members group with no change to the +builder. + +A member has `id`, `name`, `type`, `subType`, `order` (among its siblings in the effective tree), +`anchor` (`""` below a direct member), `path`, `abstract`, `isArray` (resolved through +`extends`), `extends`, `attrs`, `refs` (from its own attributes and `extends`), `claims` (on it or +anything in it), its own `memberGroups`, and: + +- **`declaredOn`**: when the member is inherited through `extends`, a link to the node that + declares it, otherwise `null`. An entity extending `BaseEntity` lists `id` among its own + members, in its effective place, with `declaredOn` pointing at `BaseEntity`. + +### References + +```ts +interface DocsViewRef { attr: string; via: DocsViewLink | null; target: DocsViewLink } +interface DocsViewReferrer { attr: string; from: DocsViewLink; via: DocsViewLink | null; target: DocsViewLink } +``` + +`attr` is the attribute without the `@`, or `extends`. `via` is the member that carries the +reference, or `null` when the node itself does. Only resolved references are listed. A +`referencedBy` entry is sorted by `from`, `attr`, `via` and target, with duplicates removed. +References within one top-level node are not listed as `referencedBy`. + +### Claims + +```ts +interface DocsViewClaim { requirement: DocsViewLink; member: string; status: string; level: number | null } +``` + +A claim is one resolved `@implementedBy` link. It is listed on the top-level node and on every +member down to the one it names. `member` is the dotted path below the top-level node, or `""` +when the claim is on the node itself. + +### `requirements` + +Every requirement at any depth, flat, in document order. + +| Field | Meaning | +| --- | --- | +| `id`, `name`, `label`, `path` | As above. | +| `address` | The dotted path of requirement names that every `verify` diagnostic prints. | +| `package`, `qualifiedPath` | The effective requirement package, and `::
`. | +| `subType`, `level`, `status`, `disposition` | As declared; `level` is `null` when not declared. | +| `statement`, `counterexample`, `title`, `description`, `trackedBy` | As declared. | +| `depth` | How many requirements are above it. | +| `parent`, `breadcrumbs`, `children` | Links: the requirement above, every one above (outermost first), the ones directly below. | +| `implementedBy` | `{ ref, resolves, target }` per link as authored. `target` is unresolved when `resolves` is false. | +| `supersededBy` | The same, as the gate resolved it; `null` without one or without a verify payload. | +| `inLedger`, `verdict`, `digest`, `diagnostics` | From the gate's ledger row (`verdict` is `clean`, `warn` or `error`); `false` / `""` / `[]` without one. A ledger row is matched by `qualifiedPath`, in order, so two requirements with one path keep their own rows. | +| `rollup`, `rollupTotal` | The declared statuses of the requirements below that name the model (level 4 or 5, or no level and an `@implementedBy`), as one `{ status, count }` per status in the fixed order `planned`, `live`, `partial`, `retired` (the order the status vocabulary declares). A requirement with none such below counts itself. | +| `belowCount`, `childCount` | Requirements anywhere below, and directly below. | +| `targets`, `targetCount` | The top-level nodes it and the requirements below it claim, sorted by id. | + +### `packages` + +One entry per package, sorted by name (`""` for nodes with no package): `{ name, count, +groups }`, where each group is `{ type, subType, count, nodes }`, sorted by `.`. + +### `counts` + +`nodes`, `packages`, `requirements`, `functional`, `architectural`, `byStatus` (as `rollup`), +`claims` (resolved `@implementedBy` links), `files` (distinct paths), and `routes`. From the +verify payload: `undecided`, `coverageMeasured` (whether the gate measured entity coverage), +`entitiesClaimed` and `entitiesTotal`, each `0` or `false` without one. + +### `advisories` + +Every finding `meta verify` reported, in its order: `{ code, path, subject, severity, source, +message }`. `path` is the requirement's address, or `""` when the subject is not a requirement. +`subject` is a link to the node a non-requirement finding is about, or `null`. `source` is +`gate` for a finding that can fail the build and `lint` for one that never can. + +### `slices` + +Named node sets a map view opens on, all derived, each `{ id, kind, anchor, nodes }` with +`nodes` sorted, the list sorted by `id`: + +- `package:`: the package's top-level nodes. +- `requirement:`: one per requirement with requirements below it. It holds the subtree, + every node the subtree claims, and the top-level node holding each claimed member. +- `prompt:`: one per template. It holds the template and what its own attributes reference + (its payload and reply). + +## Verified by + +- [`fixtures/explorer-conformance/`](../../fixtures/explorer-conformance/): each case's + `expected.json` is the view of its project and committed inputs, byte for byte. + `server/typescript/packages/metadata/test/docs-view-conformance.test.ts` runs it, and also + checks inheritance, references, the requirement list, custom vocabulary and a build without + the optional inputs. +- `server/typescript/packages/cli/test/explorer-fixture.test.ts`: the committed `verify.json` + files are what the gate writes today, and a fresh verify payload builds the committed + `shop/expected.json`. +- `server/typescript/packages/docs-site/test/explorer-site.test.ts`: the explorer site built + from the view passes its own link check, and ships the view as `explorer.json` unchanged. diff --git a/docs/features/explorer-data.md b/docs/features/explorer-data.md index 09051e8a28..f3827a9b4f 100644 --- a/docs/features/explorer-data.md +++ b/docs/features/explorer-data.md @@ -1,31 +1,33 @@ -# Explorer data: `explorer.json` and the inputs it reads +# Explorer data: the inputs a docs build reads A model explorer shows one project so a reader can see what it does and how it was designed: the objects and how they connect, the prompts and what they send and get back, the requirement -tree and whether each claim holds, and which generated files each node produced. All of that -is read from one data file, `explorer.json`. This page documents that file and the inputs it is -built from. +tree and whether each claim holds, and which generated files each node produced. Every page of +it reads one document, the **docs view**, which the site ships as `explorer.json`. Its shape is +[docs-view.md](docs-view.md). -This page is the data layer. The site that reads it, built by `docsSiteFile()`, is -[explorer-site.md](explorer-site.md); that generator builds the file during `meta gen`, so -you only build it by hand to feed a tool of your own. +This page documents what the view is built from besides the model: the requirement gate's +ledger, the generated-file manifest, and the routes. The site that reads the view, built by +`docsSiteFile()`, is [explorer-site.md](explorer-site.md); that generator builds the view during +`meta gen`, so you only build it by hand to feed a tool of your own. -## The inputs are port-neutral +## What the view is built from -The builder (`buildExplorer` in `@metaobjectsdev/docs-site`) never loads metadata itself. It -reads three documents, and a fourth optional input, the REST routes (see [`api`](#api)): +`buildDocsView` (in `@metaobjectsdev/metadata`) takes the model the port has already loaded, +plus three optional inputs: | Input | Produced by | What it contributes | | --- | --- | --- | -| Effective canonical JSON | `meta export --effective` | nodes, inheritance, every model edge | -| The verify payload | `meta verify --format json` | the requirement ledger, and the `implementedBy` / `supersededBy` edges | +| The loaded model | the port's own loader | nodes, members, inheritance, every reference, every claim | +| The verify payload | `meta verify --format json` | the requirement ledger: each requirement's verdict, digest and findings, the counts, the findings about other nodes | | The generated-file manifest | `.metaobjects/.gen-state/.hashes/`, written by `meta gen` | which generated files each node produced | +| The routes | the generators that mount them | which REST routes each node serves | -Only the first is required. Without the verify payload there is no `ledger` and no requirement -claim edge; without the manifest there is no `generated` section. - -Because the builder reads no loader and no provider, it does not depend on which port wrote -its inputs. Every port has a canonical serializer and writes the same manifest file. +Only the model is required. The view reads the model the loader resolved, so it re-derives +nothing (no reference is matched by name, no inheritance is re-walked). An earlier version read +the effective canonical JSON from `meta export --effective` and rebuilt references from a fixed +list of attribute names; the view replaced it, and a provider's own vocabulary now gets its +links with no change to the docs code. ### `meta export --effective` @@ -41,7 +43,8 @@ as the canonical fully-qualified name. Reference attributes (`@references`, `@ob `@payloadRef`, `@responseRef`) are written in their canonical form in both modes. The effective document is for reading, not for loading back. A loader reading it would see -each inherited member twice, once on the base and once on the subtype. +each inherited member twice, once on the base and once on the subtype. The docs view does not +read it. ### `meta verify --format json`: `requirementLedger` @@ -84,9 +87,10 @@ in `requirements.rows` and in no ledger row. Each `requirements.rows` entry is ` node, severity, source, message }`. `path` is the requirement's dotted path, or `""` when the subject is not a requirement. `node` names that other subject: a `WARN_REQUIREMENT_OBJECT_UNCLAIMED` row carries the entity's resolution key there (for example -`"node": "acme::shop::AuditEntry"`, the entity's id in `explorer.json`), and every other row +`"node": "acme::shop::AuditEntry"`, the entity's id in the docs view), and every other row carries `""`. Read the subject from `path` and `node`, never from `message`, whose wording may -change. The structured payload is TypeScript-only, as the rest of `--format json` is. +change. The docs view turns these rows into its `advisories`, and an entity's `unclaimed` flag +comes from the `node` field. The structured payload is TypeScript-only, as the rest of `--format json` is. ### Node provenance in the manifest @@ -115,138 +119,50 @@ manifest, `generator` means that generator owns the file (ADR-0060), and the orp on that ownership. TypeScript does not make that claim. TypeScript is the only port that writes provenance today, and the JVM rewrites its manifest without these fields. -## The `explorer.json` shape - -```ts -interface ExplorerJson { - format: "metaobjects-explorer/1"; - nodes: ExplorerNode[]; - edges: ExplorerEdge[]; - ledger?: ExplorerLedger; // absent without a verify payload with requirements - generated?: ExplorerGenerated[]; // absent without a manifest - api?: ExplorerRoute[]; // absent without a routes input - slices: ExplorerSlice[]; -} -``` - -The types are exported from `@metaobjectsdev/docs-site`. The `format` value changes when a field -changes meaning or is removed. Adding a field does not change it. - -### `nodes` - -The output has one node for each top-level node (object, prompt, requirement) and one for -each node nested inside one (field, identity, source, view, index, nested requirement). - -| Field | Meaning | -| --- | --- | -| `id` | A top-level node's id is `::`. When top-level nodes of different types share a package and a name (an entity `Lead` and an application's page `Lead`), the object keeps `::`, because every model reference names an object; if none is an object, the first one in the effective JSON keeps it. Each other one adds its type, for example `acme::crm::Lead[page.list]`. A model with no such collision gets no qualified top-level id. A nested node's id is its parent's id followed by `.`, for example `acme::shop::Order.total`. A nested requirement's id equals its ledger row's `qualifiedPath`. A nested node with no name gets `#` in place of `.`. When siblings of different types share a name, the first one in the effective JSON keeps `.`, because that is the node a dotted `@implementedBy` reference such as `Order.id` resolves to. Each later one adds its type, for example `acme::shop::AuditEntry.id[identity.primary]`. | -| `type`, `subType`, `name`, `package` | As in the model. `package` is the package of the top-level ancestor. | -| `parent` | The id of the node it is nested in. A top-level node has no `parent`. | -| `order` | Its position among its siblings in the effective tree, from 0: the declaration order, which the id sort does not keep. | -| `extends`, `abstract`, `isArray` | As in the effective JSON. | -| `inheritedFrom` | Set on a member that came from a super. It holds the id of the object the member is declared on, meaning the topmost ancestor that has a member with the same type, name and body. A member redeclared with a different body belongs to the node itself. | -| `attrs` | Every `@` attribute, without the `@`, with keys sorted. | - -Two nodes that would still share an id are an error: two top-level nodes with one name in one package, or two siblings with the same type and name. The builder throws and names the id. - -### `edges` - -Each edge is typed. An edge is emitted only when both its ends are nodes in the file. - -| `kind` | From → to | Source | -| --- | --- | --- | -| `extends` | node → its super | `extends` | -| `references` | object → referenced object, `via` the `identity.reference` | `@references` | -| `objectRef` | object → value or entity, `via` the `field.object` | `@objectRef` on a field | -| `association` | object → target, `via` the `relationship.*` | `@objectRef` on a relationship | -| `payload` | prompt → payload object | `@payloadRef` | -| `reply` | prompt → reply object | `@responseRef` | -| `contains` | requirement → nested requirement | nesting | -| `implementedBy` | requirement → object or member | a ledger row's resolved `target` | -| `supersededBy` | requirement → replacing requirement | a ledger row's resolved `target` | - -An `implementedBy` edge exists only when the verify payload resolved that link. The builder -never matches names itself. A planned requirement that names a node that does not exist yet -has a ledger row whose link is `"resolves": false`, and it has no edge. - -### `ledger` - -`counts` is `requirementCounts`, copied as is. `rows` holds the `requirementLedger` rows, each -with a `node` id added. `diagnostics` is `requirements.rows`, copied as is: every gate and lint -finding, including those about something other than a single requirement. - -### `generated` - -The manifest entries that carry `sourceNode`, grouped by node: `{ node, files: [{ path, -generatedBy }] }`, sorted by node and then by path. A plain entry has no node and is left out. - -### `api` - -One row per REST route: `{ node, method, path }`, with the project's `apiPrefix` in the path, -sorted by node, then path, then method. Absent when no routes were passed. - -### `slices` - -Slices are named node sets that a view can open on. They are all derived from the model, so -none needs to be written by hand: - -- `package:`: the top-level nodes of one package. -- `requirement:`: one for every requirement that has nested requirements. It holds the - subtree, every node the subtree claims, and the object that owns each claimed member. -- `prompt:`: one for every prompt. It holds the prompt, its payload and its reply. - -The design report also proposes slices saved by hand. Those belong in tool configuration, -never in metadata, and are not built yet. - -### Determinism - -The same inputs always produce the same bytes. Nodes are sorted by id. Edges are sorted -by kind, then `from`, then `to`, then `via`, with duplicates removed. Slices are sorted by id, -and ledger rows stay in the verify payload's order. `serializeExplorer` writes JSON indented -two spaces, with one trailing newline. That makes the file safe to commit and diff. - -## Building it +## Building it by hand ```ts import { readdirSync, readFileSync, writeFileSync } from "node:fs"; -import { buildExplorer, serializeExplorer } from "@metaobjectsdev/docs-site"; +import { MetaDataLoader, buildDocsView, serializeDocsView } from "@metaobjectsdev/metadata"; const read = (f: string) => JSON.parse(readFileSync(f, "utf8")); -// The manifest is one file per model package; the explorer wants their union. +// The manifest is one file per model package; the view wants their union. const hashes = ".metaobjects/.gen-state/.hashes"; const manifest = Object.assign( {}, ...readdirSync(hashes).filter((f) => f.endsWith(".json")).map((f) => read(`${hashes}/${f}`)), ); -writeFileSync("explorer.json", serializeExplorer(buildExplorer({ - model: read("effective.json"), // meta export --effective --out effective.json +const { root } = await MetaDataLoader.fromDirectory("metaobjects", { strict: true }); +writeFileSync("explorer.json", serializeDocsView(buildDocsView({ + root, verify: read("verify.json"), // meta verify --format json > verify.json manifest, }))); ``` -`routes` (optional) is a list of `{ node, method, path }`, one per REST route, and becomes the -`api` section; `docsSiteFile()` fills it from the routes the run mounts. The manifest records -files, not the routes inside them, so a hand build that wants routes passes them here. - -A `verify`, `manifest` or `routes` that is missing or malformed leaves its section out. A `model` that is -not canonical metadata JSON makes the builder throw. +`routes` (optional) is a list of `{ node, method, path }`, one per REST route, with `node` a +resolution key and the project's `apiPrefix` in `path`; `docsSiteFile()` fills it from the +routes the run mounts. The manifest records files, not the routes inside them, so a hand build +that wants routes passes them here. A `verify`, `manifest` or `routes` that is missing or +malformed leaves its part of the view empty. ## Not built yet - **`usage`**: which hand-written modules import a generated module. The design marks it optional, and nothing builds it yet. - **Provenance from the JVM, Python and C# generators.** Their manifests have no `sourceNode` - yet, so for those ports `generated` is empty. + yet, so for those ports a node lists no files. +- **The docs view in the other ports.** TypeScript builds it today; the corpus is what the + other ports will be held to. ## Verified by -- [`fixtures/explorer-conformance/shop/`](../../fixtures/explorer-conformance/shop/): a small - model with inheritance, a prompt, and a five-level requirement tree. Its `expected.json` is - checked byte for byte. `server/typescript/packages/cli/test/explorer-fixture.test.ts` checks - that the CLI still writes the committed `effective.json` and `verify.json`, and checks the - `requirementLedger` rows. +- [`fixtures/explorer-conformance/`](../../fixtures/explorer-conformance/): the view of each + case, byte for byte ([docs-view.md](docs-view.md)). + `server/typescript/packages/cli/test/explorer-fixture.test.ts` checks that the gate still + writes each case's committed `verify.json`, and checks the `requirementLedger` rows and + `meta export --effective`. - `server/typescript/packages/codegen-ts/test/generated-provenance.test.ts`: covers how `perEntity` stamps each file, the object and plain manifest forms, and that JVM owner fields are preserved. diff --git a/docs/features/explorer-site.md b/docs/features/explorer-site.md index 626b1fc57b..3989c6549e 100644 --- a/docs/features/explorer-site.md +++ b/docs/features/explorer-site.md @@ -2,7 +2,7 @@ `docsSiteFile()` builds a static site that shows one project: what the software does, how the model is put together, and whether each requirement claim holds. Every page is drawn from one -data file, [`explorer.json`](explorer-data.md), which the generator builds during the same +data file, [`explorer.json`](docs-view.md) (the docs view), which the generator builds during the same `meta gen` run. A page never works a model fact out for itself. The explorer is the default site. The earlier site (package navigation, a page per object, the @@ -87,7 +87,7 @@ docsSiteFile({ assetBase: "/vendor/npm" }) | Model map | `map.html` | Every top-level node and the edges between them. Open a slice (a package, a requirement subtree, a prompt), colour by kind, API, claims, capability or status, and hide or show value objects and nodes outside the slice. The URL keeps the choice (`?slice=&colour=&focus=`) | | Object | `model//.html` | Why it exists (the requirements that claim it), its fields, inherited ones marked, relationships, indexes, a one-hop mini-map, its routes and the files generated from it. A projection shows its read model and each field's origin; a report shows where its rows come from, its dimensions and its measures | | Prompt | `model//.html` | The payload and reply types, the template text with each variable marked, and which payload fields the text never uses | -| Any other node | `model//.html` | A generic page for every other top-level type, including vocabulary an application registers itself (a `capability.module`, a `page.list`): its attributes, each one linked when it names a node, its members, the requirements that claim it, what references it and the files generated from it | +| Any other node | `model//.html` | A generic page for every other top-level type, including vocabulary an application registers itself (a `capability.module`, a `page.list`): its attributes, each one linked when the loader resolves it as a reference, its members, the requirements that claim it, what references it and the files generated from it | | Features, qualities | `requirements/features.html`, `requirements/qualities.html` | The requirement tree, one card per entry | | Requirement | `requirements//.html` | Its status, what it claims, the entries below it with their roll-up, what the gate found, its authoring advisories apart, and links to its slice of the map and its trace | | Matrix | `matrix.html` | Requirements against stored entities and prompts. An empty column is a node nothing claims | @@ -98,7 +98,7 @@ docsSiteFile({ assetBase: "/vendor/npm" }) An object named `index` gets `index.node.html`, so it never takes its package's index page, and a model with no package puts its pages under `model/-root/`. A node whose id carries its type (because a node of another type has the same name in its package, see -[explorer-data.md](explorer-data.md)) carries it in its file name too: the page `Lead` beside +[docs-view.md](docs-view.md#ids)) carries it in its file name too: the page `Lead` beside the entity `Lead` is `Lead.page-list.html`. Every page works at phone width: the navigation scrolls, the tiles stack in two columns, and @@ -144,20 +144,22 @@ one. ## As a library ```ts -import { generateExplorerSite, readPromptTexts, type ExplorerJson } from "@metaobjectsdev/docs-site"; +import { MetaDataLoader, buildDocsView } from "@metaobjectsdev/metadata"; +import { generateExplorerSite, readPromptTexts } from "@metaobjectsdev/docs-site"; -const explorer: ExplorerJson = JSON.parse(readFileSync("explorer.json", "utf8")); +const { root } = await MetaDataLoader.fromDirectory("metaobjects", { strict: true }); +const view = buildDocsView({ root }); generateExplorerSite({ - explorer, + view, outDir: "site", title: "Shop", - texts: readPromptTexts(explorer, ["prompts"]), + texts: readPromptTexts(view, ["prompts"]), }); ``` It takes `templatesDir`, `assetsDir`, `assetBase` and `stamp` as well, and throws on a -dangling link. Build `explorer.json` itself with `buildExplorer` -([explorer-data.md](explorer-data.md)). +dangling link. `buildDocsView` also takes the verify payload, the manifest and the routes +([explorer-data.md](explorer-data.md)); the view's shape is [docs-view.md](docs-view.md). ## Not built yet @@ -170,11 +172,12 @@ dangling link. Build `explorer.json` itself with `buildExplorer` ## Verified by -- `server/typescript/packages/docs-site/test/explorer-site.test.ts`: the shop fixture - (`fixtures/explorer-conformance/shop/`) and the fitness model +- `server/typescript/packages/docs-site/test/explorer-site.test.ts`: the shop and crm cases + (`fixtures/explorer-conformance/`) and the fitness model (`fixtures/persistence-conformance/canonical/meta.fitness.json`). Every screen is written, links resolve, two builds match byte for byte, status chips and verdict outlines are - distinct, and projection and report pages show their read model. + distinct, projection and report pages show their read model, and a provider's own vocabulary + gets its pages and links. - `server/typescript/packages/codegen-ts/test/docs-site-explorer.test.ts`: the generator sees the files and routes of generators listed after it, and the ledger is asked for once. - `server/typescript/packages/cli/test/explorer-site-ledger.test.ts`: the requirement views read diff --git a/docs/features/own-your-codegen.md b/docs/features/own-your-codegen.md index 5290820de3..b10aee9b41 100644 --- a/docs/features/own-your-codegen.md +++ b/docs/features/own-your-codegen.md @@ -537,7 +537,7 @@ replaced (`overwrite`). There is **no three-way merge** A TypeScript entry can also carry the node the file was rendered from, `{ "hash", "generatedBy", "sourceNode" }`. That is provenance, not ownership, which is why it does not use the JVM's `generator` field. Every reader takes `hash` from either form. See -[explorer-data.md](explorer-data.md#node-provenance-in-hashesjson). +[explorer-data.md](explorer-data.md#node-provenance-in-the-manifest). The `GENERATED` token in the header still matters at one moment: a file at a generated path that the manifest has no record of. A file that carries the token is taken as generated diff --git a/fixtures/docs-page-conformance/README.md b/fixtures/docs-page-conformance/README.md index 613f680200..909040d206 100644 --- a/fixtures/docs-page-conformance/README.md +++ b/fixtures/docs-page-conformance/README.md @@ -40,7 +40,7 @@ built over these rows, not a new extraction. A port checks its rows first (compa values), then its page data, then the bytes. The model-only page data follows from the rows and the model alone; the TypeScript runner proves it by rebuilding the page from `rows/schema.json` (`schemaInputFromRows`). `cli/test/docs-page-shapes.test.ts` holds the -requirement rows equal to the explorer graph's (on `fixtures/explorer-conformance/shop/`) and +requirement rows equal to the docs view's (on `fixtures/explorer-conformance/shop/`) and the schema rows to a subset of `meta schema`'s output. A page the case does not list is a page the port must NOT write: a model with no diff --git a/fixtures/explorer-conformance/README.md b/fixtures/explorer-conformance/README.md index 2dc475a8e7..2f677a581c 100644 --- a/fixtures/explorer-conformance/README.md +++ b/fixtures/explorer-conformance/README.md @@ -1,49 +1,87 @@ # explorer-conformance -The `explorer.json` data spine: three port-neutral inputs in, one explorer document out, -compared byte for byte. The shape is documented in -[docs/features/explorer-data.md](../../docs/features/explorer-data.md). +The docs view: a loaded project and its optional inputs in, one `explorer.json` out, compared +byte for byte. The shape is [docs/features/docs-view.md](../../docs/features/docs-view.md); the +inputs are [docs/features/explorer-data.md](../../docs/features/explorer-data.md). -## `shop/` +Each case is a directory: | File | What it is | How it is produced | | --- | --- | --- | -| `project/` | A small project: an abstract `BaseEntity` two entities extend, a value object held by a `field.object`, an `identity.reference`, an index, an entity no requirement claims, a `template.prompt` with a payload and a reply, and a requirement tree five levels deep. | Hand-written. | -| `effective.json` | The effective canonical JSON. | `meta export --effective` from `project/`. | -| `verify.json` | The verify payload, with one `requirementLedger` row per requirement. | `meta verify --format json` from `project/`. | -| `hashes.json` | A generated-file manifest: three entries carry node provenance, one is a plain hash. | Hand-written (the project wires no generators). | -| `expected.json` | The explorer document. | `buildExplorer` over the three files above. | +| `project/metaobjects/` | The model. | Hand-written. | +| `provider.json` | Optional: a data-driven provider definition for vocabulary the core does not register. A runner applies it before loading, every type as a plain node. | Hand-written. | +| `verify.json` | Optional: the verify payload, with one `requirementLedger` row per requirement. | The gate's output for `project/` (see below). | +| `hashes.json` | Optional: a generated-file manifest. | Hand-written. | +| `routes.json` | Optional: the routes, `[{ node, method, path }]`. | Hand-written. | +| `expected.json` | The docs view of the loaded project and the inputs present. | `buildDocsView` + `serializeDocsView`. | + +A port loads `project/metaobjects/` strictly (with `provider.json` applied when present), +builds its view with whichever inputs are present, serializes it, and compares with +`expected.json`. + +## `shop/` -What the requirement tree exercises: +A small project: an abstract `BaseEntity` two entities extend, a value object held by a +`field.object`, an `identity.reference`, an index, an entity no requirement claims, a +`template.prompt` with a payload and a reply, and a requirement tree five levels deep. Its +`hashes.json` has three entries with node provenance and one plain hash. Its `routes.json` +lists one route twice, which the view lists once. +- `Customer` and `Order` extend `BaseEntity`, so each lists `id` as its own member with + `declaredOn` pointing at `BaseEntity`. - `Shop.Checkout.Orders.Recorded` claims two objects, and its child `Quotable` claims a member (`Order.reference`), so the slice for `Recorded` also holds `Order`, the member's owner. -- `Shop.Checkout.Orders.Refunded` is `planned` and names `Refund`, which does not exist: the - ledger row says the link does not resolve, and no edge is drawn. -- `Shop.Checkout.Shipping` is `live` and nothing under it implements anything: its row's verdict - is `warn` (`WARN_REQUIREMENT_NOTHING_IMPLEMENTS`). -- `AuditEntry` is claimed by nothing, which the gate reports with no requirement path; it lands - in `ledger.diagnostics` and in no row. +- `Shop.Checkout.Orders.Refunded` is `planned` and names `Refund`, which does not exist: its + link does not resolve, and no node lists the claim. +- `Shop.Checkout.Shipping` is `live` and nothing under it implements anything: its verdict is + `warn` (`WARN_REQUIREMENT_NOTHING_IMPLEMENTS`). +- `AuditEntry` is claimed by nothing, which the gate reports with no requirement path; it is an + advisory whose `subject` is `AuditEntry`, and the node is `unclaimed`. - `AuditEntry` names its field and its primary identity both `id`. The field comes first and keeps the id `acme::shop::AuditEntry.id`; the identity is `acme::shop::AuditEntry.id[identity.primary]`. +## `crm/` + +Application-owned vocabulary, declared in `provider.json`: a `page.list` with `block.table` +children (each with an `@objectRef` and a `@columns` list) and a `capability.module`. Neither +the builder nor any page names them. + +- The entity `Lead` and the page `Lead` share a package and a name: the entity keeps + `acme::crm::Lead`, and the page is `acme::crm::Lead[page.list]`, on `Lead.page-list.html`. +- The page's `@objectRef` and its blocks' `@objectRef` are resolved by the loader, so they are + references (to `Lead` and `Account`) and both entities list the page in `referencedBy`. The + blocks' `@columns` is not a reference attribute, so it stays text. +- `Crm.Leads` claims `acme::tax::tax`, a `capability.module` in another package, and the claim + resolves like any other. + ## Regenerating -From the repository root, after a deliberate change to either command's output or to the builder: +After a deliberate change to the builder, from `server/typescript/packages/metadata`: + +``` +UPDATE_DOCS_VIEW=1 bun test test/docs-view-conformance.test.ts +``` + +After a deliberate change to the gate's output, rewrite `verify.json` first. For `shop`, from +the repository root: ``` ( cd fixtures/explorer-conformance/shop/project && \ - bun ../../../../server/typescript/packages/cli/bin/meta.ts export --effective --out ../effective.json && \ bun ../../../../server/typescript/packages/cli/bin/meta.ts verify --format json > ../verify.json ) ``` -Then rebuild `expected.json` with `buildExplorer` and `serializeExplorer` from -`@metaobjectsdev/docs-site`, and review the diff: every changed line is a change to what an -explorer shows. +For `crm`, whose vocabulary comes from `provider.json` rather than a TypeScript config, from +`server/typescript/packages/cli`: + +``` +UPDATE_DOCS_VIEW=1 bun test test/explorer-fixture.test.ts +``` + +Then review the diff: every changed line is a change to what a docs page can show. ## Who runs it -- `server/typescript/packages/docs-site/test/explorer-build.test.ts`: the builder reproduces - `expected.json` from the committed inputs. -- `server/typescript/packages/cli/test/explorer-fixture.test.ts`: the CLI still writes - `effective.json` and `verify.json` exactly, and the fresh inputs still build `expected.json`. +- `server/typescript/packages/metadata/test/docs-view-conformance.test.ts`: the view of every + case reproduces `expected.json`. +- `server/typescript/packages/cli/test/explorer-fixture.test.ts`: the gate still writes each + committed `verify.json`, and a fresh shop payload still builds `shop/expected.json`. diff --git a/fixtures/explorer-conformance/crm/expected.json b/fixtures/explorer-conformance/crm/expected.json new file mode 100644 index 0000000000..1d173834ad --- /dev/null +++ b/fixtures/explorer-conformance/crm/expected.json @@ -0,0 +1,1342 @@ +{ + "format": "metaobjects-docs-view/1", + "sources": { + "requirements": true, + "files": false, + "routes": false + }, + "counts": { + "nodes": 5, + "packages": 2, + "requirements": 2, + "functional": 2, + "architectural": 0, + "byStatus": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 2 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "claims": 3, + "files": 0, + "routes": 0, + "undecided": 0, + "coverageMeasured": true, + "entitiesClaimed": 2, + "entitiesTotal": 2 + }, + "packages": [ + { + "name": "acme::crm", + "count": 4, + "groups": [ + { + "type": "object", + "subType": "entity", + "count": 2, + "nodes": [ + { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + ] + }, + { + "type": "page", + "subType": "list", + "count": 1, + "nodes": [ + { + "label": "Lead", + "id": "acme::crm::Lead[page.list]", + "path": "model/acme/crm/Lead.page-list.html", + "kind": "page.list", + "unresolved": false + } + ] + }, + { + "type": "requirement", + "subType": "functional", + "count": 1, + "nodes": [ + { + "label": "Crm", + "id": "acme::crm::Crm", + "path": "requirements/acme/crm/Crm.html", + "kind": "requirement.functional", + "unresolved": false + } + ] + } + ] + }, + { + "name": "acme::tax", + "count": 1, + "groups": [ + { + "type": "capability", + "subType": "module", + "count": 1, + "nodes": [ + { + "label": "tax", + "id": "acme::tax::tax", + "path": "model/acme/tax/tax.html", + "kind": "capability.module", + "unresolved": false + } + ] + } + ] + } + ], + "nodes": [ + { + "id": "acme::crm::Account", + "name": "Account", + "package": "acme::crm", + "type": "object", + "subType": "entity", + "order": 1, + "path": "model/acme/crm/Account.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 2, + "members": [ + { + "id": "acme::crm::Account.id", + "name": "id", + "type": "field", + "subType": "long", + "order": 0, + "anchor": "m-id", + "path": "model/acme/crm/Account.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::crm::Account.name", + "name": "name", + "type": "field", + "subType": "string", + "order": 1, + "anchor": "m-name", + "path": "model/acme/crm/Account.html#m-name", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 1, + "members": [ + { + "id": "acme::crm::Account.pk", + "name": "pk", + "type": "identity", + "subType": "primary", + "order": 2, + "anchor": "m-identity-pk", + "path": "model/acme/crm/Account.html#m-identity-pk", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::crm::Account.db", + "name": "db", + "type": "source", + "subType": "rdb", + "order": 3, + "anchor": "m-source-db", + "path": "model/acme/crm/Account.html#m-source-db", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "table", + "value": "accounts", + "values": [ + { + "text": "accounts", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "references", + "from": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + }, + "via": { + "label": "Lead.accountRef", + "id": "acme::crm::Lead.accountRef", + "path": "model/acme/crm/Lead.html#m-identity-accountRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "objectRef", + "from": { + "label": "Lead", + "id": "acme::crm::Lead[page.list]", + "path": "model/acme/crm/Lead.page-list.html", + "kind": "page.list", + "unresolved": false + }, + "via": { + "label": "Lead.accounts", + "id": "acme::crm::Lead[page.list].accounts", + "path": "model/acme/crm/Lead.page-list.html#m-block-accounts", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [ + { + "requirement": { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + } + ], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 4, + "refs": 0, + "referencedBy": 2, + "claims": 1, + "files": 0, + "routes": 0 + } + }, + { + "id": "acme::crm::Crm", + "name": "Crm", + "package": "acme::crm", + "type": "requirement", + "subType": "functional", + "order": 3, + "path": "requirements/acme/crm/Crm.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "counterexample", + "value": "A lead is recorded with no account it can be traced to.", + "values": [ + { + "text": "A lead is recorded with no account it can be traced to.", + "link": null + } + ] + }, + { + "name": "level", + "value": 1, + "values": [ + { + "text": "1", + "link": null + } + ] + }, + { + "name": "statement", + "value": "The software tracks leads and the accounts they belong to.", + "values": [ + { + "text": "The software tracks leads and the accounts they belong to.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "memberGroups": [ + { + "type": "requirement", + "count": 1, + "members": [ + { + "id": "acme::crm::Crm.Leads", + "name": "Leads", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "m-requirement-Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A lead's email is lost on save.", + "values": [ + { + "text": "A lead's email is lost on save.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "Lead", + "Account", + "acme::tax::tax" + ], + "values": [ + { + "text": "Lead", + "link": null + }, + { + "text": "Account", + "link": null + }, + { + "text": "acme::tax::tax", + "link": null + } + ] + }, + { + "name": "level", + "value": 4, + "values": [ + { + "text": "4", + "link": null + } + ] + }, + { + "name": "statement", + "value": "Each lead is stored with its email and account.", + "values": [ + { + "text": "Each lead is stored with its email and account.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 + } + }, + { + "id": "acme::crm::Lead", + "name": "Lead", + "package": "acme::crm", + "type": "object", + "subType": "entity", + "order": 0, + "path": "model/acme/crm/Lead.html", + "title": "", + "description": "A prospective customer.", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "description", + "value": "A prospective customer.", + "values": [ + { + "text": "A prospective customer.", + "link": null + } + ] + } + ], + "memberGroups": [ + { + "type": "field", + "count": 3, + "members": [ + { + "id": "acme::crm::Lead.id", + "name": "id", + "type": "field", + "subType": "long", + "order": 0, + "anchor": "m-id", + "path": "model/acme/crm/Lead.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::crm::Lead.email", + "name": "email", + "type": "field", + "subType": "string", + "order": 1, + "anchor": "m-email", + "path": "model/acme/crm/Lead.html#m-email", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::crm::Lead.accountId", + "name": "accountId", + "type": "field", + "subType": "long", + "order": 2, + "anchor": "m-accountId", + "path": "model/acme/crm/Lead.html#m-accountId", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 2, + "members": [ + { + "id": "acme::crm::Lead.pk", + "name": "pk", + "type": "identity", + "subType": "primary", + "order": 3, + "anchor": "m-identity-pk", + "path": "model/acme/crm/Lead.html#m-identity-pk", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::crm::Lead.accountRef", + "name": "accountRef", + "type": "identity", + "subType": "reference", + "order": 4, + "anchor": "m-identity-accountRef", + "path": "model/acme/crm/Lead.html#m-identity-accountRef", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "accountId" + ], + "values": [ + { + "text": "accountId", + "link": null + } + ] + }, + { + "name": "references", + "value": "acme::crm::Account", + "values": [ + { + "text": "acme::crm::Account", + "link": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "references", + "via": { + "label": "Lead.accountRef", + "id": "acme::crm::Lead.accountRef", + "path": "model/acme/crm/Lead.html#m-identity-accountRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::crm::Lead.db", + "name": "db", + "type": "source", + "subType": "rdb", + "order": 5, + "anchor": "m-source-db", + "path": "model/acme/crm/Lead.html#m-source-db", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "table", + "value": "leads", + "values": [ + { + "text": "leads", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [ + { + "attr": "references", + "via": { + "label": "Lead.accountRef", + "id": "acme::crm::Lead.accountRef", + "path": "model/acme/crm/Lead.html#m-identity-accountRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "referencedBy": [ + { + "attr": "objectRef", + "from": { + "label": "Lead", + "id": "acme::crm::Lead[page.list]", + "path": "model/acme/crm/Lead.page-list.html", + "kind": "page.list", + "unresolved": false + }, + "via": null, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "objectRef", + "from": { + "label": "Lead", + "id": "acme::crm::Lead[page.list]", + "path": "model/acme/crm/Lead.page-list.html", + "kind": "page.list", + "unresolved": false + }, + "via": { + "label": "Lead.leads", + "id": "acme::crm::Lead[page.list].leads", + "path": "model/acme/crm/Lead.page-list.html#m-block-leads", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [ + { + "requirement": { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + } + ], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 6, + "refs": 1, + "referencedBy": 2, + "claims": 1, + "files": 0, + "routes": 0 + } + }, + { + "id": "acme::crm::Lead[page.list]", + "name": "Lead", + "package": "acme::crm", + "type": "page", + "subType": "list", + "order": 2, + "path": "model/acme/crm/Lead.page-list.html", + "title": "Leads", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "objectRef", + "value": "acme::crm::Lead", + "values": [ + { + "text": "acme::crm::Lead", + "link": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + }, + { + "name": "route", + "value": "/leads", + "values": [ + { + "text": "/leads", + "link": null + } + ] + }, + { + "name": "title", + "value": "Leads", + "values": [ + { + "text": "Leads", + "link": null + } + ] + } + ], + "memberGroups": [ + { + "type": "block", + "count": 2, + "members": [ + { + "id": "acme::crm::Lead[page.list].leads", + "name": "leads", + "type": "block", + "subType": "table", + "order": 0, + "anchor": "m-block-leads", + "path": "model/acme/crm/Lead.page-list.html#m-block-leads", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "columns", + "value": [ + "email", + "accountId" + ], + "values": [ + { + "text": "email", + "link": null + }, + { + "text": "accountId", + "link": null + } + ] + }, + { + "name": "objectRef", + "value": "acme::crm::Lead", + "values": [ + { + "text": "acme::crm::Lead", + "link": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "objectRef", + "via": { + "label": "Lead.leads", + "id": "acme::crm::Lead[page.list].leads", + "path": "model/acme/crm/Lead.page-list.html#m-block-leads", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::crm::Lead[page.list].accounts", + "name": "accounts", + "type": "block", + "subType": "table", + "order": 1, + "anchor": "m-block-accounts", + "path": "model/acme/crm/Lead.page-list.html#m-block-accounts", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "columns", + "value": [ + "name" + ], + "values": [ + { + "text": "name", + "link": null + } + ] + }, + { + "name": "objectRef", + "value": "acme::crm::Account", + "values": [ + { + "text": "acme::crm::Account", + "link": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "objectRef", + "via": { + "label": "Lead.accounts", + "id": "acme::crm::Lead[page.list].accounts", + "path": "model/acme/crm/Lead.page-list.html#m-block-accounts", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [ + { + "attr": "objectRef", + "via": null, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "objectRef", + "via": { + "label": "Lead.leads", + "id": "acme::crm::Lead[page.list].leads", + "path": "model/acme/crm/Lead.page-list.html#m-block-leads", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "objectRef", + "via": { + "label": "Lead.accounts", + "id": "acme::crm::Lead[page.list].accounts", + "path": "model/acme/crm/Lead.page-list.html#m-block-accounts", + "kind": "block.table", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 2, + "refs": 3, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 + } + }, + { + "id": "acme::tax::tax", + "name": "tax", + "package": "acme::tax", + "type": "capability", + "subType": "module", + "order": 4, + "path": "model/acme/tax/tax.html", + "title": "", + "description": "Sales tax.", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "description", + "value": "Sales tax.", + "values": [ + { + "text": "Sales tax.", + "link": null + } + ] + }, + { + "name": "owner", + "value": "finance", + "values": [ + { + "text": "finance", + "link": null + } + ] + } + ], + "memberGroups": [], + "refs": [], + "referencedBy": [], + "claims": [ + { + "requirement": { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + } + ], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 0, + "refs": 0, + "referencedBy": 0, + "claims": 1, + "files": 0, + "routes": 0 + } + } + ], + "requirements": [ + { + "id": "acme::crm::Crm", + "name": "Crm", + "label": "Crm", + "path": "requirements/acme/crm/Crm.html", + "address": "Crm", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm", + "subType": "functional", + "level": 1, + "status": "live", + "disposition": "", + "statement": "The software tracks leads and the accounts they belong to.", + "counterexample": "A lead is recorded with no account it can be traced to.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 0, + "parent": null, + "breadcrumbs": [], + "children": [ + { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "implementedBy": [], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "f347de6f80a855b33009120f1a497ab46df959a527ad969f3e8caded5155fa72", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 1, + "childCount": 1, + "targets": [ + { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "tax", + "id": "acme::tax::tax", + "path": "model/acme/tax/tax.html", + "kind": "capability.module", + "unresolved": false + } + ], + "targetCount": 3 + }, + { + "id": "acme::crm::Crm.Leads", + "name": "Leads", + "label": "Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "address": "Crm.Leads", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm.Leads", + "subType": "functional", + "level": 4, + "status": "live", + "disposition": "", + "statement": "Each lead is stored with its email and account.", + "counterexample": "A lead's email is lost on save.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 1, + "parent": { + "label": "Crm", + "id": "acme::crm::Crm", + "path": "requirements/acme/crm/Crm.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Crm", + "id": "acme::crm::Crm", + "path": "requirements/acme/crm/Crm.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [], + "implementedBy": [ + { + "ref": "Lead", + "resolves": true, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "ref": "Account", + "resolves": true, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "ref": "acme::tax::tax", + "resolves": true, + "target": { + "label": "tax", + "id": "acme::tax::tax", + "path": "model/acme/tax/tax.html", + "kind": "capability.module", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "29446ca9b724321faf53f1e69602a10043a0c99b26dc4ed41e61d4f661e5359b", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [ + { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "tax", + "id": "acme::tax::tax", + "path": "model/acme/tax/tax.html", + "kind": "capability.module", + "unresolved": false + } + ], + "targetCount": 3 + } + ], + "advisories": [], + "slices": [ + { + "id": "package:acme::crm", + "kind": "package", + "anchor": "acme::crm", + "nodes": [ + "acme::crm::Account", + "acme::crm::Crm", + "acme::crm::Lead", + "acme::crm::Lead[page.list]" + ] + }, + { + "id": "package:acme::tax", + "kind": "package", + "anchor": "acme::tax", + "nodes": [ + "acme::tax::tax" + ] + }, + { + "id": "requirement:acme::crm::Crm", + "kind": "requirement", + "anchor": "acme::crm::Crm", + "nodes": [ + "acme::crm::Account", + "acme::crm::Crm", + "acme::crm::Crm.Leads", + "acme::crm::Lead", + "acme::tax::tax" + ] + } + ] +} diff --git a/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json b/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json new file mode 100644 index 0000000000..5dcaba9c01 --- /dev/null +++ b/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json @@ -0,0 +1,65 @@ +{ + "metadata.root": { + "package": "acme::crm", + "children": [ + { + "object.entity": { + "name": "Lead", + "@description": "A prospective customer.", + "children": [ + { "field.long": { "name": "id" } }, + { "field.string": { "name": "email" } }, + { "field.long": { "name": "accountId" } }, + { "identity.primary": { "name": "pk", "@fields": ["id"] } }, + { "identity.reference": { "name": "accountRef", "@fields": ["accountId"], "@references": "Account" } }, + { "source.rdb": { "name": "db", "@table": "leads" } } + ] + } + }, + { + "object.entity": { + "name": "Account", + "children": [ + { "field.long": { "name": "id" } }, + { "field.string": { "name": "name" } }, + { "identity.primary": { "name": "pk", "@fields": ["id"] } }, + { "source.rdb": { "name": "db", "@table": "accounts" } } + ] + } + }, + { + "page.list": { + "name": "Lead", + "@title": "Leads", + "@objectRef": "Lead", + "@route": "/leads", + "children": [ + { "block.table": { "name": "leads", "@objectRef": "Lead", "@columns": ["email", "accountId"] } }, + { "block.table": { "name": "accounts", "@objectRef": "Account", "@columns": ["name"] } } + ] + } + }, + { + "requirement.functional": { + "name": "Crm", + "@level": 1, + "@status": "live", + "@statement": "The software tracks leads and the accounts they belong to.", + "@counterexample": "A lead is recorded with no account it can be traced to.", + "children": [ + { + "requirement.functional": { + "name": "Leads", + "@level": 4, + "@status": "live", + "@statement": "Each lead is stored with its email and account.", + "@counterexample": "A lead's email is lost on save.", + "@implementedBy": ["Lead", "Account", "acme::tax::tax"] + } + } + ] + } + } + ] + } +} diff --git a/fixtures/explorer-conformance/crm/project/metaobjects/meta.tax.json b/fixtures/explorer-conformance/crm/project/metaobjects/meta.tax.json new file mode 100644 index 0000000000..fedc936d05 --- /dev/null +++ b/fixtures/explorer-conformance/crm/project/metaobjects/meta.tax.json @@ -0,0 +1,8 @@ +{ + "metadata.root": { + "package": "acme::tax", + "children": [ + { "capability.module": { "name": "tax", "@description": "Sales tax.", "@owner": "finance" } } + ] + } +} diff --git a/fixtures/explorer-conformance/crm/provider.json b/fixtures/explorer-conformance/crm/provider.json new file mode 100644 index 0000000000..d8198ab6ca --- /dev/null +++ b/fixtures/explorer-conformance/crm/provider.json @@ -0,0 +1,42 @@ +{ + "provider": "example-docs-vocabulary", + "types": [ + { + "type": "page", + "subType": "list", + "description": "An application page listing the rows of one object.", + "children": [ + { "type": "attr", "subType": "string", "name": "objectRef", "min": 1, "max": 1, "description": "The object the page lists." }, + { "type": "attr", "subType": "string", "name": "route", "min": 0, "max": 1, "description": "The path the page is served at." }, + { "type": "block", "subType": "*", "name": "*", "min": 0, "max": null } + ] + }, + { + "type": "block", + "subType": "table", + "description": "A table of one object's rows on a page.", + "children": [ + { "type": "attr", "subType": "string", "name": "objectRef", "min": 1, "max": 1, "description": "The object whose rows the table shows." }, + { "type": "attr", "subType": "string", "name": "columns", "isArray": true, "min": 0, "max": 1, "description": "The fields shown, in order." } + ] + }, + { + "type": "capability", + "subType": "module", + "description": "A unit of capability the application ships.", + "children": [ + { "type": "attr", "subType": "string", "name": "owner", "min": 0, "max": 1, "description": "The team that owns it." } + ] + } + ], + "extends": [ + { + "type": "metadata", + "subType": "root", + "children": [ + { "type": "page", "subType": "*", "name": "*", "min": 0, "max": null }, + { "type": "capability", "subType": "*", "name": "*", "min": 0, "max": null } + ] + } + ] +} diff --git a/fixtures/explorer-conformance/crm/verify.json b/fixtures/explorer-conformance/crm/verify.json new file mode 100644 index 0000000000..e1d37ffbc2 --- /dev/null +++ b/fixtures/explorer-conformance/crm/verify.json @@ -0,0 +1,62 @@ +{ + "requirementLedger": [ + { + "path": "Crm", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm", + "subType": "functional", + "level": 1, + "status": "live", + "digest": "f347de6f80a855b33009120f1a497ab46df959a527ad969f3e8caded5155fa72", + "implementedBy": [], + "diagnostics": [], + "verdict": "clean" + }, + { + "path": "Crm.Leads", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm.Leads", + "subType": "functional", + "level": 4, + "status": "live", + "digest": "29446ca9b724321faf53f1e69602a10043a0c99b26dc4ed41e61d4f661e5359b", + "implementedBy": [ + { + "ref": "Lead", + "resolves": true, + "target": "acme::crm::Lead" + }, + { + "ref": "Account", + "resolves": true, + "target": "acme::crm::Account" + }, + { + "ref": "acme::tax::tax", + "resolves": true, + "target": "acme::tax::tax" + } + ], + "diagnostics": [], + "verdict": "clean" + } + ], + "requirementCounts": { + "total": 2, + "functional": 2, + "architectural": 0, + "byStatus": [ + { + "status": "live", + "count": 2 + } + ], + "undecided": 0, + "entitiesClaimed": 2, + "entitiesTotal": 2, + "metadataFiles": 2 + }, + "requirements": { + "rows": [] + } +} diff --git a/fixtures/explorer-conformance/shop/effective.json b/fixtures/explorer-conformance/shop/effective.json deleted file mode 100644 index 2b3a0fb71e..0000000000 --- a/fixtures/explorer-conformance/shop/effective.json +++ /dev/null @@ -1,348 +0,0 @@ -{ - "metadata.root": { - "package": "acme::shop", - "children": [ - { - "object.entity": { - "name": "BaseEntity", - "abstract": true, - "children": [ - { - "field.uuid": { - "name": "id" - } - }, - { - "field.timestamp": { - "name": "createdAt" - } - }, - { - "identity.primary": { - "name": "pk", - "@fields": [ - "id" - ] - } - } - ] - } - }, - { - "object.value": { - "name": "Address", - "children": [ - { - "field.string": { - "name": "street" - } - }, - { - "field.string": { - "name": "city" - } - } - ] - } - }, - { - "object.entity": { - "name": "Customer", - "extends": "acme::shop::BaseEntity", - "children": [ - { - "field.uuid": { - "name": "id" - } - }, - { - "field.timestamp": { - "name": "createdAt" - } - }, - { - "identity.primary": { - "name": "pk", - "@fields": [ - "id" - ] - } - }, - { - "field.string": { - "name": "name", - "@required": true - } - }, - { - "field.string": { - "name": "email" - } - }, - { - "field.object": { - "name": "shippingAddress", - "@objectRef": "acme::shop::Address" - } - }, - { - "source.rdb": { - "name": "db", - "@table": "customers" - } - } - ] - } - }, - { - "object.entity": { - "name": "Order", - "extends": "acme::shop::BaseEntity", - "children": [ - { - "field.uuid": { - "name": "id" - } - }, - { - "field.timestamp": { - "name": "createdAt" - } - }, - { - "identity.primary": { - "name": "pk", - "@fields": [ - "id" - ] - } - }, - { - "field.uuid": { - "name": "customerId" - } - }, - { - "field.string": { - "name": "reference" - } - }, - { - "field.decimal": { - "name": "total" - } - }, - { - "field.enum": { - "name": "state", - "@values": [ - "OPEN", - "PAID", - "SHIPPED" - ] - } - }, - { - "identity.reference": { - "name": "customerRef", - "@fields": [ - "customerId" - ], - "@references": "acme::shop::Customer" - } - }, - { - "index.lookup": { - "name": "orderByCustomerId", - "@fields": [ - "customerId" - ] - } - }, - { - "source.rdb": { - "name": "db", - "@table": "orders" - } - } - ] - } - }, - { - "object.entity": { - "name": "AuditEntry", - "children": [ - { - "field.uuid": { - "name": "id" - } - }, - { - "identity.primary": { - "name": "id", - "@fields": [ - "id" - ] - } - }, - { - "field.string": { - "name": "message" - } - }, - { - "source.rdb": { - "name": "db", - "@table": "audit_entries" - } - } - ] - } - }, - { - "object.value": { - "name": "OrderNoteRequest", - "children": [ - { - "field.string": { - "name": "reference", - "@required": true - } - } - ] - } - }, - { - "object.value": { - "name": "OrderNote", - "children": [ - { - "field.string": { - "name": "text", - "@required": true - } - } - ] - } - }, - { - "template.prompt": { - "name": "OrderNotePrompt", - "@format": "text", - "@payloadRef": "acme::shop::OrderNoteRequest", - "@responseFormat": "json", - "@responseRef": "acme::shop::OrderNote", - "@textRef": "shop/order-note" - } - }, - { - "requirement.architectural": { - "name": "Addressable", - "@counterexample": "A row nobody can point at.", - "@implementedBy": [ - "BaseEntity" - ], - "@statement": "Every stored row has a stable id.", - "@status": "live" - } - }, - { - "requirement.functional": { - "name": "Shop", - "@counterexample": "A customer who cannot place an order.", - "@level": 1, - "@statement": "A customer can buy from the shop.", - "@status": "live", - "children": [ - { - "requirement.functional": { - "name": "Checkout", - "@counterexample": "An order taken outside checkout.", - "@disposition": "deferred", - "@level": 2, - "@statement": "Orders are taken at checkout.", - "@status": "partial", - "@trackedBy": [ - "https://example.invalid/issues/1" - ], - "children": [ - { - "requirement.functional": { - "name": "Orders", - "@counterexample": "A placed order that is lost.", - "@level": 3, - "@statement": "Every placed order is kept.", - "@status": "live", - "children": [ - { - "requirement.functional": { - "name": "Recorded", - "@counterexample": "A placed order has no row.", - "@implementedBy": [ - "Order", - "Customer" - ], - "@level": 4, - "@statement": "An order is recorded when it is placed.", - "@status": "live", - "children": [ - { - "requirement.functional": { - "name": "Quotable", - "@counterexample": "An order nobody can quote back.", - "@implementedBy": [ - "Order.reference" - ], - "@level": 5, - "@statement": "An order carries a reference the customer can quote.", - "@status": "live" - } - } - ] - } - }, - { - "requirement.functional": { - "name": "Noted", - "@counterexample": "An order with no note.", - "@implementedBy": [ - "OrderNotePrompt" - ], - "@level": 4, - "@statement": "A placed order gets a short note for the customer.", - "@status": "live" - } - }, - { - "requirement.functional": { - "name": "Refunded", - "@counterexample": "A paid order that cannot be refunded.", - "@implementedBy": [ - "Refund" - ], - "@level": 4, - "@statement": "A paid order can be refunded.", - "@status": "planned" - } - } - ] - } - }, - { - "requirement.functional": { - "name": "Shipping", - "@counterexample": "A paid order that never ships.", - "@level": 3, - "@statement": "A paid order is shipped.", - "@status": "live" - } - } - ] - } - } - ] - } - } - ] - } -} diff --git a/fixtures/explorer-conformance/shop/expected.json b/fixtures/explorer-conformance/shop/expected.json index fc4b44dda3..6c055ef32b 100644 --- a/fixtures/explorer-conformance/shop/expected.json +++ b/fixtures/explorer-conformance/shop/expected.json @@ -1,890 +1,3187 @@ { - "format": "metaobjects-explorer/1", + "format": "metaobjects-docs-view/1", + "sources": { + "requirements": true, + "files": true, + "routes": true + }, + "counts": { + "nodes": 10, + "packages": 1, + "requirements": 9, + "functional": 8, + "architectural": 1, + "byStatus": [ + { + "status": "planned", + "count": 1 + }, + { + "status": "live", + "count": 7 + }, + { + "status": "partial", + "count": 1 + }, + { + "status": "retired", + "count": 0 + } + ], + "claims": 5, + "files": 3, + "routes": 4, + "undecided": 1, + "coverageMeasured": true, + "entitiesClaimed": 2, + "entitiesTotal": 3 + }, + "packages": [ + { + "name": "acme::shop", + "count": 10, + "groups": [ + { + "type": "object", + "subType": "entity", + "count": 4, + "nodes": [ + { + "label": "AuditEntry", + "id": "acme::shop::AuditEntry", + "path": "model/acme/shop/AuditEntry.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + } + ] + }, + { + "type": "object", + "subType": "value", + "count": 3, + "nodes": [ + { + "label": "Address", + "id": "acme::shop::Address", + "path": "model/acme/shop/Address.html", + "kind": "object.value", + "unresolved": false + }, + { + "label": "OrderNote", + "id": "acme::shop::OrderNote", + "path": "model/acme/shop/OrderNote.html", + "kind": "object.value", + "unresolved": false + }, + { + "label": "OrderNoteRequest", + "id": "acme::shop::OrderNoteRequest", + "path": "model/acme/shop/OrderNoteRequest.html", + "kind": "object.value", + "unresolved": false + } + ] + }, + { + "type": "requirement", + "subType": "architectural", + "count": 1, + "nodes": [ + { + "label": "Addressable", + "id": "acme::shop::Addressable", + "path": "requirements/acme/shop/Addressable.html", + "kind": "requirement.architectural", + "unresolved": false + } + ] + }, + { + "type": "requirement", + "subType": "functional", + "count": 1, + "nodes": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + } + ] + }, + { + "type": "template", + "subType": "prompt", + "count": 1, + "nodes": [ + { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + } + ] + } + ] + } + ], "nodes": [ { "id": "acme::shop::Address", - "type": "object", - "subType": "value", "name": "Address", "package": "acme::shop", + "type": "object", + "subType": "value", "order": 1, - "attrs": {} - }, - { - "id": "acme::shop::Address.city", - "type": "field", - "subType": "string", - "name": "city", - "package": "acme::shop", - "order": 1, - "parent": "acme::shop::Address", - "attrs": {} - }, - { - "id": "acme::shop::Address.street", - "type": "field", - "subType": "string", - "name": "street", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Address", - "attrs": {} + "path": "model/acme/shop/Address.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 2, + "members": [ + { + "id": "acme::shop::Address.street", + "name": "street", + "type": "field", + "subType": "string", + "order": 0, + "anchor": "m-street", + "path": "model/acme/shop/Address.html#m-street", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Address.city", + "name": "city", + "type": "field", + "subType": "string", + "order": 1, + "anchor": "m-city", + "path": "model/acme/shop/Address.html#m-city", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "objectRef", + "from": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + "via": { + "label": "Customer.shippingAddress", + "id": "acme::shop::Customer.shippingAddress", + "path": "model/acme/shop/Customer.html#m-shippingAddress", + "kind": "field.object", + "unresolved": false + }, + "target": { + "label": "Address", + "id": "acme::shop::Address", + "path": "model/acme/shop/Address.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 2, + "refs": 0, + "referencedBy": 1, + "claims": 0, + "files": 0, + "routes": 0 + } }, { "id": "acme::shop::Addressable", - "type": "requirement", - "subType": "architectural", "name": "Addressable", "package": "acme::shop", + "type": "requirement", + "subType": "architectural", "order": 8, - "attrs": { - "counterexample": "A row nobody can point at.", - "implementedBy": [ - "BaseEntity" - ], - "statement": "Every stored row has a stable id.", - "status": "live" + "path": "requirements/acme/shop/Addressable.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "counterexample", + "value": "A row nobody can point at.", + "values": [ + { + "text": "A row nobody can point at.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "BaseEntity" + ], + "values": [ + { + "text": "BaseEntity", + "link": null + } + ] + }, + { + "name": "statement", + "value": "Every stored row has a stable id.", + "values": [ + { + "text": "Every stored row has a stable id.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "memberGroups": [], + "refs": [], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 0, + "refs": 0, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 } }, { "id": "acme::shop::AuditEntry", - "type": "object", - "subType": "entity", "name": "AuditEntry", "package": "acme::shop", + "type": "object", + "subType": "entity", "order": 4, - "attrs": {} - }, - { - "id": "acme::shop::AuditEntry.db", - "type": "source", - "subType": "rdb", - "name": "db", - "package": "acme::shop", - "order": 3, - "parent": "acme::shop::AuditEntry", - "attrs": { - "table": "audit_entries" - } - }, - { - "id": "acme::shop::AuditEntry.id", - "type": "field", - "subType": "uuid", - "name": "id", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::AuditEntry", - "attrs": {} - }, - { - "id": "acme::shop::AuditEntry.id[identity.primary]", - "type": "identity", - "subType": "primary", - "name": "id", - "package": "acme::shop", - "order": 1, - "parent": "acme::shop::AuditEntry", - "attrs": { - "fields": [ - "id" - ] + "path": "model/acme/shop/AuditEntry.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 2, + "members": [ + { + "id": "acme::shop::AuditEntry.id", + "name": "id", + "type": "field", + "subType": "uuid", + "order": 0, + "anchor": "m-id", + "path": "model/acme/shop/AuditEntry.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::AuditEntry.message", + "name": "message", + "type": "field", + "subType": "string", + "order": 2, + "anchor": "m-message", + "path": "model/acme/shop/AuditEntry.html#m-message", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 1, + "members": [ + { + "id": "acme::shop::AuditEntry.id[identity.primary]", + "name": "id", + "type": "identity", + "subType": "primary", + "order": 1, + "anchor": "m-identity-id", + "path": "model/acme/shop/AuditEntry.html#m-identity-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::shop::AuditEntry.db", + "name": "db", + "type": "source", + "subType": "rdb", + "order": 3, + "anchor": "m-source-db", + "path": "model/acme/shop/AuditEntry.html#m-source-db", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "table", + "value": "audit_entries", + "values": [ + { + "text": "audit_entries", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": true, + "counts": { + "members": 4, + "refs": 0, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 } }, - { - "id": "acme::shop::AuditEntry.message", - "type": "field", - "subType": "string", - "name": "message", - "package": "acme::shop", - "order": 2, - "parent": "acme::shop::AuditEntry", - "attrs": {} - }, { "id": "acme::shop::BaseEntity", - "type": "object", - "subType": "entity", "name": "BaseEntity", "package": "acme::shop", + "type": "object", + "subType": "entity", "order": 0, + "path": "model/acme/shop/BaseEntity.html", + "title": "", + "description": "", + "summary": "", "abstract": true, - "attrs": {} - }, - { - "id": "acme::shop::BaseEntity.createdAt", - "type": "field", - "subType": "timestamp", - "name": "createdAt", - "package": "acme::shop", - "order": 1, - "parent": "acme::shop::BaseEntity", - "attrs": {} - }, - { - "id": "acme::shop::BaseEntity.id", - "type": "field", - "subType": "uuid", - "name": "id", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::BaseEntity", - "attrs": {} - }, - { - "id": "acme::shop::BaseEntity.pk", - "type": "identity", - "subType": "primary", - "name": "pk", - "package": "acme::shop", - "order": 2, - "parent": "acme::shop::BaseEntity", - "attrs": { - "fields": [ - "id" - ] + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 2, + "members": [ + { + "id": "acme::shop::BaseEntity.id", + "name": "id", + "type": "field", + "subType": "uuid", + "order": 0, + "anchor": "m-id", + "path": "model/acme/shop/BaseEntity.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::BaseEntity.createdAt", + "name": "createdAt", + "type": "field", + "subType": "timestamp", + "order": 1, + "anchor": "m-createdAt", + "path": "model/acme/shop/BaseEntity.html#m-createdAt", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 1, + "members": [ + { + "id": "acme::shop::BaseEntity.pk", + "name": "pk", + "type": "identity", + "subType": "primary", + "order": 2, + "anchor": "m-identity-pk", + "path": "model/acme/shop/BaseEntity.html#m-identity-pk", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "extends", + "from": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + "via": null, + "target": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "extends", + "from": { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + }, + "via": null, + "target": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [ + { + "requirement": { + "label": "Addressable", + "id": "acme::shop::Addressable", + "path": "requirements/acme/shop/Addressable.html", + "kind": "requirement.architectural", + "unresolved": false + }, + "member": "", + "status": "live", + "level": null + } + ], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 3, + "refs": 0, + "referencedBy": 2, + "claims": 1, + "files": 0, + "routes": 0 } }, { "id": "acme::shop::Customer", - "type": "object", - "subType": "entity", "name": "Customer", "package": "acme::shop", + "type": "object", + "subType": "entity", "order": 2, - "extends": "acme::shop::BaseEntity", - "attrs": {} - }, - { - "id": "acme::shop::Customer.createdAt", - "type": "field", - "subType": "timestamp", - "name": "createdAt", - "package": "acme::shop", - "order": 1, - "parent": "acme::shop::Customer", - "attrs": {}, - "inheritedFrom": "acme::shop::BaseEntity" - }, - { - "id": "acme::shop::Customer.db", - "type": "source", - "subType": "rdb", - "name": "db", - "package": "acme::shop", - "order": 6, - "parent": "acme::shop::Customer", - "attrs": { - "table": "customers" - } - }, - { - "id": "acme::shop::Customer.email", - "type": "field", - "subType": "string", - "name": "email", - "package": "acme::shop", - "order": 4, - "parent": "acme::shop::Customer", - "attrs": {} - }, - { - "id": "acme::shop::Customer.id", - "type": "field", - "subType": "uuid", - "name": "id", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Customer", - "attrs": {}, - "inheritedFrom": "acme::shop::BaseEntity" - }, - { - "id": "acme::shop::Customer.name", - "type": "field", - "subType": "string", - "name": "name", - "package": "acme::shop", - "order": 3, - "parent": "acme::shop::Customer", - "attrs": { - "required": true - } - }, - { - "id": "acme::shop::Customer.pk", - "type": "identity", - "subType": "primary", - "name": "pk", - "package": "acme::shop", - "order": 2, - "parent": "acme::shop::Customer", - "attrs": { - "fields": [ - "id" - ] + "path": "model/acme/shop/Customer.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false }, - "inheritedFrom": "acme::shop::BaseEntity" - }, - { - "id": "acme::shop::Customer.shippingAddress", - "type": "field", - "subType": "object", - "name": "shippingAddress", - "package": "acme::shop", - "order": 5, - "parent": "acme::shop::Customer", - "attrs": { - "objectRef": "acme::shop::Address" + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 5, + "members": [ + { + "id": "acme::shop::Customer.id", + "name": "id", + "type": "field", + "subType": "uuid", + "order": 0, + "anchor": "m-id", + "path": "model/acme/shop/Customer.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Customer.createdAt", + "name": "createdAt", + "type": "field", + "subType": "timestamp", + "order": 1, + "anchor": "m-createdAt", + "path": "model/acme/shop/Customer.html#m-createdAt", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Customer.name", + "name": "name", + "type": "field", + "subType": "string", + "order": 3, + "anchor": "m-name", + "path": "model/acme/shop/Customer.html#m-name", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "required", + "value": true, + "values": [ + { + "text": "true", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Customer.email", + "name": "email", + "type": "field", + "subType": "string", + "order": 4, + "anchor": "m-email", + "path": "model/acme/shop/Customer.html#m-email", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Customer.shippingAddress", + "name": "shippingAddress", + "type": "field", + "subType": "object", + "order": 5, + "anchor": "m-shippingAddress", + "path": "model/acme/shop/Customer.html#m-shippingAddress", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "objectRef", + "value": "acme::shop::Address", + "values": [ + { + "text": "acme::shop::Address", + "link": { + "label": "Address", + "id": "acme::shop::Address", + "path": "model/acme/shop/Address.html", + "kind": "object.value", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "objectRef", + "via": { + "label": "Customer.shippingAddress", + "id": "acme::shop::Customer.shippingAddress", + "path": "model/acme/shop/Customer.html#m-shippingAddress", + "kind": "field.object", + "unresolved": false + }, + "target": { + "label": "Address", + "id": "acme::shop::Address", + "path": "model/acme/shop/Address.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 1, + "members": [ + { + "id": "acme::shop::Customer.pk", + "name": "pk", + "type": "identity", + "subType": "primary", + "order": 2, + "anchor": "m-identity-pk", + "path": "model/acme/shop/Customer.html#m-identity-pk", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::shop::Customer.db", + "name": "db", + "type": "source", + "subType": "rdb", + "order": 6, + "anchor": "m-source-db", + "path": "model/acme/shop/Customer.html#m-source-db", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "table", + "value": "customers", + "values": [ + { + "text": "customers", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [ + { + "attr": "extends", + "via": null, + "target": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "objectRef", + "via": { + "label": "Customer.shippingAddress", + "id": "acme::shop::Customer.shippingAddress", + "path": "model/acme/shop/Customer.html#m-shippingAddress", + "kind": "field.object", + "unresolved": false + }, + "target": { + "label": "Address", + "id": "acme::shop::Address", + "path": "model/acme/shop/Address.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "referencedBy": [ + { + "attr": "references", + "from": { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + }, + "via": { + "label": "Order.customerRef", + "id": "acme::shop::Order.customerRef", + "path": "model/acme/shop/Order.html#m-identity-customerRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [ + { + "requirement": { + "label": "Recorded", + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + } + ], + "files": [ + { + "generatedBy": "entity", + "paths": [ + "src/generated/acme/shop/Customer.ts" + ] + } + ], + "routes": [ + { + "method": "GET", + "path": "/api/customers" + } + ], + "unclaimed": false, + "counts": { + "members": 7, + "refs": 2, + "referencedBy": 1, + "claims": 1, + "files": 1, + "routes": 1 } }, { "id": "acme::shop::Order", - "type": "object", - "subType": "entity", "name": "Order", "package": "acme::shop", + "type": "object", + "subType": "entity", "order": 3, - "extends": "acme::shop::BaseEntity", - "attrs": {} + "path": "model/acme/shop/Order.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 6, + "members": [ + { + "id": "acme::shop::Order.id", + "name": "id", + "type": "field", + "subType": "uuid", + "order": 0, + "anchor": "m-id", + "path": "model/acme/shop/Order.html#m-id", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.createdAt", + "name": "createdAt", + "type": "field", + "subType": "timestamp", + "order": 1, + "anchor": "m-createdAt", + "path": "model/acme/shop/Order.html#m-createdAt", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.customerId", + "name": "customerId", + "type": "field", + "subType": "uuid", + "order": 3, + "anchor": "m-customerId", + "path": "model/acme/shop/Order.html#m-customerId", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.reference", + "name": "reference", + "type": "field", + "subType": "string", + "order": 4, + "anchor": "m-reference", + "path": "model/acme/shop/Order.html#m-reference", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [ + { + "requirement": { + "label": "Quotable", + "id": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.Quotable.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "reference", + "status": "live", + "level": 5 + } + ], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.total", + "name": "total", + "type": "field", + "subType": "decimal", + "order": 5, + "anchor": "m-total", + "path": "model/acme/shop/Order.html#m-total", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.state", + "name": "state", + "type": "field", + "subType": "enum", + "order": 6, + "anchor": "m-state", + "path": "model/acme/shop/Order.html#m-state", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "values", + "value": [ + "OPEN", + "PAID", + "SHIPPED" + ], + "values": [ + { + "text": "OPEN", + "link": null + }, + { + "text": "PAID", + "link": null + }, + { + "text": "SHIPPED", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "identity", + "count": 2, + "members": [ + { + "id": "acme::shop::Order.pk", + "name": "pk", + "type": "identity", + "subType": "primary", + "order": 2, + "anchor": "m-identity-pk", + "path": "model/acme/shop/Order.html#m-identity-pk", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [ + { + "name": "fields", + "value": [ + "id" + ], + "values": [ + { + "text": "id", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Order.customerRef", + "name": "customerRef", + "type": "identity", + "subType": "reference", + "order": 7, + "anchor": "m-identity-customerRef", + "path": "model/acme/shop/Order.html#m-identity-customerRef", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "customerId" + ], + "values": [ + { + "text": "customerId", + "link": null + } + ] + }, + { + "name": "references", + "value": "acme::shop::Customer", + "values": [ + { + "text": "acme::shop::Customer", + "link": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "references", + "via": { + "label": "Order.customerRef", + "id": "acme::shop::Order.customerRef", + "path": "model/acme/shop/Order.html#m-identity-customerRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "index", + "count": 1, + "members": [ + { + "id": "acme::shop::Order.orderByCustomerId", + "name": "orderByCustomerId", + "type": "index", + "subType": "lookup", + "order": 8, + "anchor": "m-index-orderByCustomerId", + "path": "model/acme/shop/Order.html#m-index-orderByCustomerId", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "fields", + "value": [ + "customerId" + ], + "values": [ + { + "text": "customerId", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::shop::Order.db", + "name": "db", + "type": "source", + "subType": "rdb", + "order": 9, + "anchor": "m-source-db", + "path": "model/acme/shop/Order.html#m-source-db", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "table", + "value": "orders", + "values": [ + { + "text": "orders", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [ + { + "attr": "extends", + "via": null, + "target": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "attr": "references", + "via": { + "label": "Order.customerRef", + "id": "acme::shop::Order.customerRef", + "path": "model/acme/shop/Order.html#m-identity-customerRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "referencedBy": [], + "claims": [ + { + "requirement": { + "label": "Recorded", + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + }, + { + "requirement": { + "label": "Quotable", + "id": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.Quotable.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "reference", + "status": "live", + "level": 5 + } + ], + "files": [ + { + "generatedBy": "entity", + "paths": [ + "src/generated/acme/shop/Order.ts" + ] + }, + { + "generatedBy": "queries", + "paths": [ + "src/generated/acme/shop/Order.queries.ts" + ] + } + ], + "routes": [ + { + "method": "GET", + "path": "/api/orders" + }, + { + "method": "POST", + "path": "/api/orders" + }, + { + "method": "GET", + "path": "/api/orders/{id}" + } + ], + "unclaimed": false, + "counts": { + "members": 10, + "refs": 2, + "referencedBy": 0, + "claims": 2, + "files": 2, + "routes": 3 + } }, { - "id": "acme::shop::Order.createdAt", - "type": "field", - "subType": "timestamp", - "name": "createdAt", + "id": "acme::shop::OrderNote", + "name": "OrderNote", "package": "acme::shop", - "order": 1, - "parent": "acme::shop::Order", - "attrs": {}, - "inheritedFrom": "acme::shop::BaseEntity" + "type": "object", + "subType": "value", + "order": 6, + "path": "model/acme/shop/OrderNote.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 1, + "members": [ + { + "id": "acme::shop::OrderNote.text", + "name": "text", + "type": "field", + "subType": "string", + "order": 0, + "anchor": "m-text", + "path": "model/acme/shop/OrderNote.html#m-text", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "required", + "value": true, + "values": [ + { + "text": "true", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "responseRef", + "from": { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + }, + "via": null, + "target": { + "label": "OrderNote", + "id": "acme::shop::OrderNote", + "path": "model/acme/shop/OrderNote.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 1, + "claims": 0, + "files": 0, + "routes": 0 + } }, { - "id": "acme::shop::Order.customerId", - "type": "field", - "subType": "uuid", - "name": "customerId", + "id": "acme::shop::OrderNotePrompt", + "name": "OrderNotePrompt", "package": "acme::shop", - "order": 3, - "parent": "acme::shop::Order", - "attrs": {} - }, - { - "id": "acme::shop::Order.customerRef", - "type": "identity", - "subType": "reference", - "name": "customerRef", - "package": "acme::shop", - "order": 7, - "parent": "acme::shop::Order", - "attrs": { - "fields": [ - "customerId" - ], - "references": "acme::shop::Customer" - } - }, - { - "id": "acme::shop::Order.db", - "type": "source", - "subType": "rdb", - "name": "db", - "package": "acme::shop", - "order": 9, - "parent": "acme::shop::Order", - "attrs": { - "table": "orders" - } - }, - { - "id": "acme::shop::Order.id", - "type": "field", - "subType": "uuid", - "name": "id", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Order", - "attrs": {}, - "inheritedFrom": "acme::shop::BaseEntity" - }, - { - "id": "acme::shop::Order.orderByCustomerId", - "type": "index", - "subType": "lookup", - "name": "orderByCustomerId", - "package": "acme::shop", - "order": 8, - "parent": "acme::shop::Order", - "attrs": { - "fields": [ - "customerId" - ] - } - }, - { - "id": "acme::shop::Order.pk", - "type": "identity", - "subType": "primary", - "name": "pk", - "package": "acme::shop", - "order": 2, - "parent": "acme::shop::Order", - "attrs": { - "fields": [ - "id" - ] - }, - "inheritedFrom": "acme::shop::BaseEntity" - }, - { - "id": "acme::shop::Order.reference", - "type": "field", - "subType": "string", - "name": "reference", - "package": "acme::shop", - "order": 4, - "parent": "acme::shop::Order", - "attrs": {} - }, - { - "id": "acme::shop::Order.state", - "type": "field", - "subType": "enum", - "name": "state", - "package": "acme::shop", - "order": 6, - "parent": "acme::shop::Order", - "attrs": { - "values": [ - "OPEN", - "PAID", - "SHIPPED" - ] - } - }, - { - "id": "acme::shop::Order.total", - "type": "field", - "subType": "decimal", - "name": "total", - "package": "acme::shop", - "order": 5, - "parent": "acme::shop::Order", - "attrs": {} - }, - { - "id": "acme::shop::OrderNote", - "type": "object", - "subType": "value", - "name": "OrderNote", - "package": "acme::shop", - "order": 6, - "attrs": {} - }, - { - "id": "acme::shop::OrderNote.text", - "type": "field", - "subType": "string", - "name": "text", - "package": "acme::shop", - "order": 0, - "parent": "acme::shop::OrderNote", - "attrs": { - "required": true - } - }, - { - "id": "acme::shop::OrderNotePrompt", "type": "template", "subType": "prompt", - "name": "OrderNotePrompt", - "package": "acme::shop", "order": 7, - "attrs": { - "format": "text", - "payloadRef": "acme::shop::OrderNoteRequest", - "responseFormat": "json", - "responseRef": "acme::shop::OrderNote", - "textRef": "shop/order-note" + "path": "model/acme/shop/OrderNotePrompt.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "format", + "value": "text", + "values": [ + { + "text": "text", + "link": null + } + ] + }, + { + "name": "payloadRef", + "value": "acme::shop::OrderNoteRequest", + "values": [ + { + "text": "acme::shop::OrderNoteRequest", + "link": { + "label": "OrderNoteRequest", + "id": "acme::shop::OrderNoteRequest", + "path": "model/acme/shop/OrderNoteRequest.html", + "kind": "object.value", + "unresolved": false + } + } + ] + }, + { + "name": "responseFormat", + "value": "json", + "values": [ + { + "text": "json", + "link": null + } + ] + }, + { + "name": "responseRef", + "value": "acme::shop::OrderNote", + "values": [ + { + "text": "acme::shop::OrderNote", + "link": { + "label": "OrderNote", + "id": "acme::shop::OrderNote", + "path": "model/acme/shop/OrderNote.html", + "kind": "object.value", + "unresolved": false + } + } + ] + }, + { + "name": "textRef", + "value": "shop/order-note", + "values": [ + { + "text": "shop/order-note", + "link": null + } + ] + } + ], + "memberGroups": [], + "refs": [ + { + "attr": "payloadRef", + "via": null, + "target": { + "label": "OrderNoteRequest", + "id": "acme::shop::OrderNoteRequest", + "path": "model/acme/shop/OrderNoteRequest.html", + "kind": "object.value", + "unresolved": false + } + }, + { + "attr": "responseRef", + "via": null, + "target": { + "label": "OrderNote", + "id": "acme::shop::OrderNote", + "path": "model/acme/shop/OrderNote.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "referencedBy": [], + "claims": [ + { + "requirement": { + "label": "Noted", + "id": "acme::shop::Shop.Checkout.Orders.Noted", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Noted.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "", + "status": "live", + "level": 4 + } + ], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 0, + "refs": 2, + "referencedBy": 0, + "claims": 1, + "files": 0, + "routes": 0 } }, { "id": "acme::shop::OrderNoteRequest", - "type": "object", - "subType": "value", "name": "OrderNoteRequest", "package": "acme::shop", + "type": "object", + "subType": "value", "order": 5, - "attrs": {} + "path": "model/acme/shop/OrderNoteRequest.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 1, + "members": [ + { + "id": "acme::shop::OrderNoteRequest.reference", + "name": "reference", + "type": "field", + "subType": "string", + "order": 0, + "anchor": "m-reference", + "path": "model/acme/shop/OrderNoteRequest.html#m-reference", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "required", + "value": true, + "values": [ + { + "text": "true", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "payloadRef", + "from": { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + }, + "via": null, + "target": { + "label": "OrderNoteRequest", + "id": "acme::shop::OrderNoteRequest", + "path": "model/acme/shop/OrderNoteRequest.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 1, + "claims": 0, + "files": 0, + "routes": 0 + } }, { - "id": "acme::shop::OrderNoteRequest.reference", - "type": "field", - "subType": "string", - "name": "reference", + "id": "acme::shop::Shop", + "name": "Shop", "package": "acme::shop", - "order": 0, - "parent": "acme::shop::OrderNoteRequest", - "attrs": { - "required": true + "type": "requirement", + "subType": "functional", + "order": 9, + "path": "requirements/acme/shop/Shop.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [ + { + "name": "counterexample", + "value": "A customer who cannot place an order.", + "values": [ + { + "text": "A customer who cannot place an order.", + "link": null + } + ] + }, + { + "name": "level", + "value": 1, + "values": [ + { + "text": "1", + "link": null + } + ] + }, + { + "name": "statement", + "value": "A customer can buy from the shop.", + "values": [ + { + "text": "A customer can buy from the shop.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "memberGroups": [ + { + "type": "requirement", + "count": 1, + "members": [ + { + "id": "acme::shop::Shop.Checkout", + "name": "Checkout", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "m-requirement-Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "An order taken outside checkout.", + "values": [ + { + "text": "An order taken outside checkout.", + "link": null + } + ] + }, + { + "name": "disposition", + "value": "deferred", + "values": [ + { + "text": "deferred", + "link": null + } + ] + }, + { + "name": "level", + "value": 2, + "values": [ + { + "text": "2", + "link": null + } + ] + }, + { + "name": "statement", + "value": "Orders are taken at checkout.", + "values": [ + { + "text": "Orders are taken at checkout.", + "link": null + } + ] + }, + { + "name": "status", + "value": "partial", + "values": [ + { + "text": "partial", + "link": null + } + ] + }, + { + "name": "trackedBy", + "value": [ + "https://example.invalid/issues/1" + ], + "values": [ + { + "text": "https://example.invalid/issues/1", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [ + { + "type": "requirement", + "count": 2, + "members": [ + { + "id": "acme::shop::Shop.Checkout.Orders", + "name": "Orders", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A placed order that is lost.", + "values": [ + { + "text": "A placed order that is lost.", + "link": null + } + ] + }, + { + "name": "level", + "value": 3, + "values": [ + { + "text": "3", + "link": null + } + ] + }, + { + "name": "statement", + "value": "Every placed order is kept.", + "values": [ + { + "text": "Every placed order is kept.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [ + { + "type": "requirement", + "count": 3, + "members": [ + { + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "name": "Recorded", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A placed order has no row.", + "values": [ + { + "text": "A placed order has no row.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "Order", + "Customer" + ], + "values": [ + { + "text": "Order", + "link": null + }, + { + "text": "Customer", + "link": null + } + ] + }, + { + "name": "level", + "value": 4, + "values": [ + { + "text": "4", + "link": null + } + ] + }, + { + "name": "statement", + "value": "An order is recorded when it is placed.", + "values": [ + { + "text": "An order is recorded when it is placed.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [ + { + "type": "requirement", + "count": 1, + "members": [ + { + "id": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", + "name": "Quotable", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.Quotable.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "An order nobody can quote back.", + "values": [ + { + "text": "An order nobody can quote back.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "Order.reference" + ], + "values": [ + { + "text": "Order.reference", + "link": null + } + ] + }, + { + "name": "level", + "value": 5, + "values": [ + { + "text": "5", + "link": null + } + ] + }, + { + "name": "statement", + "value": "An order carries a reference the customer can quote.", + "values": [ + { + "text": "An order carries a reference the customer can quote.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ] + }, + { + "id": "acme::shop::Shop.Checkout.Orders.Noted", + "name": "Noted", + "type": "requirement", + "subType": "functional", + "order": 1, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Noted.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "An order with no note.", + "values": [ + { + "text": "An order with no note.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "OrderNotePrompt" + ], + "values": [ + { + "text": "OrderNotePrompt", + "link": null + } + ] + }, + { + "name": "level", + "value": 4, + "values": [ + { + "text": "4", + "link": null + } + ] + }, + { + "name": "statement", + "value": "A placed order gets a short note for the customer.", + "values": [ + { + "text": "A placed order gets a short note for the customer.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + }, + { + "id": "acme::shop::Shop.Checkout.Orders.Refunded", + "name": "Refunded", + "type": "requirement", + "subType": "functional", + "order": 2, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Refunded.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A paid order that cannot be refunded.", + "values": [ + { + "text": "A paid order that cannot be refunded.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "Refund" + ], + "values": [ + { + "text": "Refund", + "link": null + } + ] + }, + { + "name": "level", + "value": 4, + "values": [ + { + "text": "4", + "link": null + } + ] + }, + { + "name": "statement", + "value": "A paid order can be refunded.", + "values": [ + { + "text": "A paid order can be refunded.", + "link": null + } + ] + }, + { + "name": "status", + "value": "planned", + "values": [ + { + "text": "planned", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ] + }, + { + "id": "acme::shop::Shop.Checkout.Shipping", + "name": "Shipping", + "type": "requirement", + "subType": "functional", + "order": 1, + "anchor": "", + "path": "requirements/acme/shop/Shop.Checkout.Shipping.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A paid order that never ships.", + "values": [ + { + "text": "A paid order that never ships.", + "link": null + } + ] + }, + { + "name": "level", + "value": 3, + "values": [ + { + "text": "3", + "link": null + } + ] + }, + { + "name": "statement", + "value": "A paid order is shipped.", + "values": [ + { + "text": "A paid order is shipped.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ] + } + ] + } + ], + "refs": [], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 } + } + ], + "requirements": [ + { + "id": "acme::shop::Addressable", + "name": "Addressable", + "label": "Addressable", + "path": "requirements/acme/shop/Addressable.html", + "address": "Addressable", + "package": "acme::shop", + "qualifiedPath": "acme::shop::Addressable", + "subType": "architectural", + "level": null, + "status": "live", + "disposition": "", + "statement": "Every stored row has a stable id.", + "counterexample": "A row nobody can point at.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 0, + "parent": null, + "breadcrumbs": [], + "children": [], + "implementedBy": [ + { + "ref": "BaseEntity", + "resolves": true, + "target": { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "c22897fd7559820a2a7a69bae54353900122be23f3d0058e9ec2b6195ae840e1", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [ + { + "label": "BaseEntity", + "id": "acme::shop::BaseEntity", + "path": "model/acme/shop/BaseEntity.html", + "kind": "object.entity", + "unresolved": false + } + ], + "targetCount": 1 }, { "id": "acme::shop::Shop", - "type": "requirement", - "subType": "functional", "name": "Shop", + "label": "Shop", + "path": "requirements/acme/shop/Shop.html", + "address": "Shop", "package": "acme::shop", - "order": 9, - "attrs": { - "counterexample": "A customer who cannot place an order.", - "level": 1, - "statement": "A customer can buy from the shop.", - "status": "live" - } + "qualifiedPath": "acme::shop::Shop", + "subType": "functional", + "level": 1, + "status": "live", + "disposition": "", + "statement": "A customer can buy from the shop.", + "counterexample": "A customer who cannot place an order.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 0, + "parent": null, + "breadcrumbs": [], + "children": [ + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "implementedBy": [], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "edc8a9b8159eb03a08d020427683253d6d1471032e0cf48115956362fc121653", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 1 + }, + { + "status": "live", + "count": 3 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 4, + "belowCount": 7, + "childCount": 1, + "targets": [ + { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + } + ], + "targetCount": 3 }, { "id": "acme::shop::Shop.Checkout", - "type": "requirement", - "subType": "functional", "name": "Checkout", + "label": "Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "address": "Shop.Checkout", "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Shop", - "attrs": { - "counterexample": "An order taken outside checkout.", - "disposition": "deferred", - "level": 2, - "statement": "Orders are taken at checkout.", - "status": "partial", - "trackedBy": [ - "https://example.invalid/issues/1" - ] - } + "qualifiedPath": "acme::shop::Shop.Checkout", + "subType": "functional", + "level": 2, + "status": "partial", + "disposition": "deferred", + "statement": "Orders are taken at checkout.", + "counterexample": "An order taken outside checkout.", + "title": "", + "description": "", + "trackedBy": [ + "https://example.invalid/issues/1" + ], + "depth": 1, + "parent": { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [ + { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Shipping", + "id": "acme::shop::Shop.Checkout.Shipping", + "path": "requirements/acme/shop/Shop.Checkout.Shipping.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "implementedBy": [], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "111b8c39a19c717933fdd529af808540a27c0592406d0a792c524960ac775a2d", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 1 + }, + { + "status": "live", + "count": 3 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 4, + "belowCount": 6, + "childCount": 2, + "targets": [ + { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + } + ], + "targetCount": 3 }, { "id": "acme::shop::Shop.Checkout.Orders", - "type": "requirement", - "subType": "functional", "name": "Orders", + "label": "Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "address": "Shop.Checkout.Orders", "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Shop.Checkout", - "attrs": { - "counterexample": "A placed order that is lost.", - "level": 3, - "statement": "Every placed order is kept.", - "status": "live" - } - }, - { - "id": "acme::shop::Shop.Checkout.Orders.Noted", - "type": "requirement", + "qualifiedPath": "acme::shop::Shop.Checkout.Orders", "subType": "functional", - "name": "Noted", - "package": "acme::shop", - "order": 1, - "parent": "acme::shop::Shop.Checkout.Orders", - "attrs": { - "counterexample": "An order with no note.", - "implementedBy": [ - "OrderNotePrompt" - ], - "level": 4, - "statement": "A placed order gets a short note for the customer.", - "status": "live" - } + "level": 3, + "status": "live", + "disposition": "", + "statement": "Every placed order is kept.", + "counterexample": "A placed order that is lost.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 2, + "parent": { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [ + { + "label": "Recorded", + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Noted", + "id": "acme::shop::Shop.Checkout.Orders.Noted", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Noted.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Refunded", + "id": "acme::shop::Shop.Checkout.Orders.Refunded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Refunded.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "implementedBy": [], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "e84c69fda54cb9f04f3949af069c2c5d56027e008be3198a08c4ee4fbcad8be6", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 1 + }, + { + "status": "live", + "count": 3 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 4, + "belowCount": 4, + "childCount": 3, + "targets": [ + { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + } + ], + "targetCount": 3 }, { "id": "acme::shop::Shop.Checkout.Orders.Recorded", - "type": "requirement", - "subType": "functional", "name": "Recorded", + "label": "Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "address": "Shop.Checkout.Orders.Recorded", "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Shop.Checkout.Orders", - "attrs": { - "counterexample": "A placed order has no row.", - "implementedBy": [ - "Order", - "Customer" - ], - "level": 4, - "statement": "An order is recorded when it is placed.", - "status": "live" - } + "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Recorded", + "subType": "functional", + "level": 4, + "status": "live", + "disposition": "", + "statement": "An order is recorded when it is placed.", + "counterexample": "A placed order has no row.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 3, + "parent": { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [ + { + "label": "Quotable", + "id": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.Quotable.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "implementedBy": [ + { + "ref": "Order", + "resolves": true, + "target": { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + } + }, + { + "ref": "Customer", + "resolves": true, + "target": { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "6feebe1e415dda976cc6843c4546c1541b25e8ee44b85316811bfdb177f77635", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 2 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 2, + "belowCount": 1, + "childCount": 1, + "targets": [ + { + "label": "Customer", + "id": "acme::shop::Customer", + "path": "model/acme/shop/Customer.html", + "kind": "object.entity", + "unresolved": false + }, + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + } + ], + "targetCount": 2 }, { "id": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", - "type": "requirement", - "subType": "functional", "name": "Quotable", + "label": "Quotable", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.Quotable.html", + "address": "Shop.Checkout.Orders.Recorded.Quotable", "package": "acme::shop", - "order": 0, - "parent": "acme::shop::Shop.Checkout.Orders.Recorded", - "attrs": { - "counterexample": "An order nobody can quote back.", - "implementedBy": [ - "Order.reference" - ], - "level": 5, - "statement": "An order carries a reference the customer can quote.", - "status": "live" - } - }, - { - "id": "acme::shop::Shop.Checkout.Orders.Refunded", - "type": "requirement", + "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", "subType": "functional", - "name": "Refunded", - "package": "acme::shop", - "order": 2, - "parent": "acme::shop::Shop.Checkout.Orders", - "attrs": { - "counterexample": "A paid order that cannot be refunded.", - "implementedBy": [ - "Refund" - ], - "level": 4, - "statement": "A paid order can be refunded.", - "status": "planned" - } + "level": 5, + "status": "live", + "disposition": "", + "statement": "An order carries a reference the customer can quote.", + "counterexample": "An order nobody can quote back.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 4, + "parent": { + "label": "Recorded", + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Recorded", + "id": "acme::shop::Shop.Checkout.Orders.Recorded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Recorded.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [], + "implementedBy": [ + { + "ref": "Order.reference", + "resolves": true, + "target": { + "label": "Order.reference", + "id": "acme::shop::Order.reference", + "path": "model/acme/shop/Order.html#m-reference", + "kind": "field.string", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "b5d7fb7a9657bfda7b30e2629617bf5c56e4337ef7a06abfe55715613ecdda63", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [ + { + "label": "Order", + "id": "acme::shop::Order", + "path": "model/acme/shop/Order.html", + "kind": "object.entity", + "unresolved": false + } + ], + "targetCount": 1 }, { - "id": "acme::shop::Shop.Checkout.Shipping", - "type": "requirement", - "subType": "functional", - "name": "Shipping", + "id": "acme::shop::Shop.Checkout.Orders.Noted", + "name": "Noted", + "label": "Noted", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Noted.html", + "address": "Shop.Checkout.Orders.Noted", "package": "acme::shop", - "order": 1, - "parent": "acme::shop::Shop.Checkout", - "attrs": { - "counterexample": "A paid order that never ships.", - "level": 3, - "statement": "A paid order is shipped.", - "status": "live" - } - } - ], - "edges": [ - { - "kind": "contains", - "from": "acme::shop::Shop", - "to": "acme::shop::Shop.Checkout" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout", - "to": "acme::shop::Shop.Checkout.Orders" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout", - "to": "acme::shop::Shop.Checkout.Shipping" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout.Orders", - "to": "acme::shop::Shop.Checkout.Orders.Noted" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout.Orders", - "to": "acme::shop::Shop.Checkout.Orders.Recorded" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout.Orders", - "to": "acme::shop::Shop.Checkout.Orders.Refunded" - }, - { - "kind": "contains", - "from": "acme::shop::Shop.Checkout.Orders.Recorded", - "to": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable" - }, - { - "kind": "extends", - "from": "acme::shop::Customer", - "to": "acme::shop::BaseEntity" - }, - { - "kind": "extends", - "from": "acme::shop::Order", - "to": "acme::shop::BaseEntity" - }, - { - "kind": "implementedBy", - "from": "acme::shop::Addressable", - "to": "acme::shop::BaseEntity" - }, - { - "kind": "implementedBy", - "from": "acme::shop::Shop.Checkout.Orders.Noted", - "to": "acme::shop::OrderNotePrompt" - }, - { - "kind": "implementedBy", - "from": "acme::shop::Shop.Checkout.Orders.Recorded", - "to": "acme::shop::Customer" - }, - { - "kind": "implementedBy", - "from": "acme::shop::Shop.Checkout.Orders.Recorded", - "to": "acme::shop::Order" - }, - { - "kind": "implementedBy", - "from": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", - "to": "acme::shop::Order.reference" - }, - { - "kind": "objectRef", - "from": "acme::shop::Customer", - "to": "acme::shop::Address", - "via": "acme::shop::Customer.shippingAddress" - }, - { - "kind": "payload", - "from": "acme::shop::OrderNotePrompt", - "to": "acme::shop::OrderNoteRequest" - }, - { - "kind": "references", - "from": "acme::shop::Order", - "to": "acme::shop::Customer", - "via": "acme::shop::Order.customerRef" - }, - { - "kind": "reply", - "from": "acme::shop::OrderNotePrompt", - "to": "acme::shop::OrderNote" - } - ], - "ledger": { - "counts": { - "total": 9, - "functional": 8, - "architectural": 1, - "byStatus": [ + "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Noted", + "subType": "functional", + "level": 4, + "status": "live", + "disposition": "", + "statement": "A placed order gets a short note for the customer.", + "counterexample": "An order with no note.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 3, + "parent": { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [], + "implementedBy": [ + { + "ref": "OrderNotePrompt", + "resolves": true, + "target": { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "45ed514b57928304f2d8b7c69e4cc3e5196cd8131ea57bc5ececc8056f52b995", + "diagnostics": [], + "rollup": [ { "status": "planned", - "count": 1 + "count": 0 }, { "status": "live", - "count": 7 + "count": 1 }, { "status": "partial", - "count": 1 + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [ + { + "label": "OrderNotePrompt", + "id": "acme::shop::OrderNotePrompt", + "path": "model/acme/shop/OrderNotePrompt.html", + "kind": "template.prompt", + "unresolved": false } ], - "undecided": 1, - "entitiesClaimed": 2, - "entitiesTotal": 3, - "metadataFiles": 1 + "targetCount": 1 }, - "rows": [ - { - "node": "acme::shop::Addressable", - "path": "Addressable", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Addressable", - "subType": "architectural", - "status": "live", - "digest": "c22897fd7559820a2a7a69bae54353900122be23f3d0058e9ec2b6195ae840e1", - "implementedBy": [ - { - "ref": "BaseEntity", - "resolves": true, - "target": "acme::shop::BaseEntity" - } - ], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop", - "path": "Shop", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop", - "subType": "functional", - "level": 1, - "status": "live", - "digest": "edc8a9b8159eb03a08d020427683253d6d1471032e0cf48115956362fc121653", - "implementedBy": [], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout", - "path": "Shop.Checkout", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout", - "subType": "functional", - "level": 2, - "status": "partial", - "disposition": "deferred", - "digest": "111b8c39a19c717933fdd529af808540a27c0592406d0a792c524960ac775a2d", - "implementedBy": [], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout.Orders", - "path": "Shop.Checkout.Orders", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Orders", - "subType": "functional", - "level": 3, - "status": "live", - "digest": "e84c69fda54cb9f04f3949af069c2c5d56027e008be3198a08c4ee4fbcad8be6", - "implementedBy": [], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout.Orders.Recorded", - "path": "Shop.Checkout.Orders.Recorded", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Recorded", - "subType": "functional", - "level": 4, - "status": "live", - "digest": "6feebe1e415dda976cc6843c4546c1541b25e8ee44b85316811bfdb177f77635", - "implementedBy": [ - { - "ref": "Order", - "resolves": true, - "target": "acme::shop::Order" - }, - { - "ref": "Customer", - "resolves": true, - "target": "acme::shop::Customer" - } - ], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", - "path": "Shop.Checkout.Orders.Recorded.Quotable", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", - "subType": "functional", - "level": 5, - "status": "live", - "digest": "b5d7fb7a9657bfda7b30e2629617bf5c56e4337ef7a06abfe55715613ecdda63", - "implementedBy": [ - { - "ref": "Order.reference", - "resolves": true, - "target": "acme::shop::Order.reference" - } - ], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout.Orders.Noted", - "path": "Shop.Checkout.Orders.Noted", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Noted", - "subType": "functional", - "level": 4, - "status": "live", - "digest": "45ed514b57928304f2d8b7c69e4cc3e5196cd8131ea57bc5ececc8056f52b995", - "implementedBy": [ - { - "ref": "OrderNotePrompt", - "resolves": true, - "target": "acme::shop::OrderNotePrompt" - } - ], - "diagnostics": [], - "verdict": "clean" - }, - { - "node": "acme::shop::Shop.Checkout.Orders.Refunded", - "path": "Shop.Checkout.Orders.Refunded", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Refunded", - "subType": "functional", - "level": 4, - "status": "planned", - "digest": "dcaacae2ee305ce97e804148559dfe32c13dc69083ff736f09cab1b60a8d7a74", - "implementedBy": [ - { - "ref": "Refund", - "resolves": false - } - ], - "diagnostics": [], - "verdict": "clean" + { + "id": "acme::shop::Shop.Checkout.Orders.Refunded", + "name": "Refunded", + "label": "Refunded", + "path": "requirements/acme/shop/Shop.Checkout.Orders.Refunded.html", + "address": "Shop.Checkout.Orders.Refunded", + "package": "acme::shop", + "qualifiedPath": "acme::shop::Shop.Checkout.Orders.Refunded", + "subType": "functional", + "level": 4, + "status": "planned", + "disposition": "", + "statement": "A paid order can be refunded.", + "counterexample": "A paid order that cannot be refunded.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 3, + "parent": { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false }, - { - "node": "acme::shop::Shop.Checkout.Shipping", - "path": "Shop.Checkout.Shipping", - "package": "acme::shop", - "qualifiedPath": "acme::shop::Shop.Checkout.Shipping", - "subType": "functional", - "level": 3, - "status": "live", - "digest": "d7d26a3dd5661647327cec62f969b61c74346e1df1e954de4d8392705bdecf31", - "implementedBy": [], - "diagnostics": [ - { - "code": "WARN_REQUIREMENT_NOTHING_IMPLEMENTS", - "severity": "warn", - "source": "gate", - "message": "is 'live' but neither it nor anything nested under it names an implementing node. A functional requirement's check is existence — a subtree that claims nothing is a capability nobody built." + "breadcrumbs": [ + { + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Orders", + "id": "acme::shop::Shop.Checkout.Orders", + "path": "requirements/acme/shop/Shop.Checkout.Orders.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [], + "implementedBy": [ + { + "ref": "Refund", + "resolves": false, + "target": { + "label": "Refund", + "id": "", + "path": "", + "kind": "", + "unresolved": true } - ], - "verdict": "warn" - } - ], - "diagnostics": [ - { - "code": "WARN_REQUIREMENT_NOTHING_IMPLEMENTS", - "path": "Shop.Checkout.Shipping", - "node": "", - "severity": "warn", - "source": "gate", - "message": "is 'live' but neither it nor anything nested under it names an implementing node. A functional requirement's check is existence — a subtree that claims nothing is a capability nobody built." - }, - { - "code": "WARN_REQUIREMENT_OBJECT_UNCLAIMED", - "path": "", - "node": "acme::shop::AuditEntry", - "severity": "warn", - "source": "gate", - "message": "no requirement claims 'acme::shop::AuditEntry'. Add it to an L4 requirement's 'implementedBy'." - } - ] - }, - "generated": [ - { - "node": "acme::shop::Customer", - "files": [ + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "dcaacae2ee305ce97e804148559dfe32c13dc69083ff736f09cab1b60a8d7a74", + "diagnostics": [], + "rollup": [ { - "path": "src/generated/acme/shop/Customer.ts", - "generatedBy": "entity" + "status": "planned", + "count": 1 + }, + { + "status": "live", + "count": 0 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 } - ] + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [], + "targetCount": 0 }, { - "node": "acme::shop::Order", - "files": [ + "id": "acme::shop::Shop.Checkout.Shipping", + "name": "Shipping", + "label": "Shipping", + "path": "requirements/acme/shop/Shop.Checkout.Shipping.html", + "address": "Shop.Checkout.Shipping", + "package": "acme::shop", + "qualifiedPath": "acme::shop::Shop.Checkout.Shipping", + "subType": "functional", + "level": 3, + "status": "live", + "disposition": "", + "statement": "A paid order is shipped.", + "counterexample": "A paid order that never ships.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 2, + "parent": { + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ { - "path": "src/generated/acme/shop/Order.queries.ts", - "generatedBy": "queries" + "label": "Shop", + "id": "acme::shop::Shop", + "path": "requirements/acme/shop/Shop.html", + "kind": "requirement.functional", + "unresolved": false }, { - "path": "src/generated/acme/shop/Order.ts", - "generatedBy": "entity" + "label": "Checkout", + "id": "acme::shop::Shop.Checkout", + "path": "requirements/acme/shop/Shop.Checkout.html", + "kind": "requirement.functional", + "unresolved": false } - ] + ], + "children": [], + "implementedBy": [], + "supersededBy": null, + "inLedger": true, + "verdict": "warn", + "digest": "d7d26a3dd5661647327cec62f969b61c74346e1df1e954de4d8392705bdecf31", + "diagnostics": [ + { + "code": "WARN_REQUIREMENT_NOTHING_IMPLEMENTS", + "severity": "warn", + "source": "gate", + "message": "is 'live' but neither it nor anything nested under it names an implementing node. A functional requirement's check is existence — a subtree that claims nothing is a capability nobody built." + } + ], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [], + "targetCount": 0 + } + ], + "advisories": [ + { + "code": "WARN_REQUIREMENT_NOTHING_IMPLEMENTS", + "path": "Shop.Checkout.Shipping", + "subject": null, + "severity": "warn", + "source": "gate", + "message": "is 'live' but neither it nor anything nested under it names an implementing node. A functional requirement's check is existence — a subtree that claims nothing is a capability nobody built." + }, + { + "code": "WARN_REQUIREMENT_OBJECT_UNCLAIMED", + "path": "", + "subject": { + "label": "AuditEntry", + "id": "acme::shop::AuditEntry", + "path": "model/acme/shop/AuditEntry.html", + "kind": "object.entity", + "unresolved": false + }, + "severity": "warn", + "source": "gate", + "message": "no requirement claims 'acme::shop::AuditEntry'. Add it to an L4 requirement's 'implementedBy'." } ], "slices": [ diff --git a/fixtures/explorer-conformance/shop/routes.json b/fixtures/explorer-conformance/shop/routes.json new file mode 100644 index 0000000000..8a73ed2453 --- /dev/null +++ b/fixtures/explorer-conformance/shop/routes.json @@ -0,0 +1,7 @@ +[ + { "node": "acme::shop::Order", "method": "get", "path": "/api/orders" }, + { "node": "acme::shop::Order", "method": "post", "path": "/api/orders" }, + { "node": "acme::shop::Order", "method": "get", "path": "/api/orders/{id}" }, + { "node": "acme::shop::Customer", "method": "get", "path": "/api/customers" }, + { "node": "acme::shop::Customer", "method": "get", "path": "/api/customers" } +] diff --git a/server/typescript/packages/cli/test/docs-page-shapes.test.ts b/server/typescript/packages/cli/test/docs-page-shapes.test.ts index 796d57f021..2557a4879a 100644 --- a/server/typescript/packages/cli/test/docs-page-shapes.test.ts +++ b/server/typescript/packages/cli/test/docs-page-shapes.test.ts @@ -5,18 +5,17 @@ // those rows rather than pinning a second shape for the same facts. This file holds that to // the two sources the site actually reads: // -// - the requirement rows are what the explorer graph (`explorer.json`: the requirement nodes -// and the verify ledger) already holds, field for field; +// - the requirement rows are what the docs view (`explorer.json`, `buildDocsView`) already +// holds, field for field; // - the schema rows are a literal subset of `meta schema --as json` (the `serializeSnapshot` // format), the storage lens's input. import { describe, expect, test } from "bun:test"; import { readdirSync, readFileSync } from "node:fs"; import { join, resolve } from "node:path"; -import { InMemoryStringSource, MetaDataLoader } from "@metaobjectsdev/metadata"; +import { InMemoryStringSource, MetaDataLoader, buildDocsView, type DocsView } from "@metaobjectsdev/metadata"; import type { MetaRoot } from "@metaobjectsdev/metadata"; import { requirementRows, type RequirementRow, type SchemaRows } from "@metaobjectsdev/codegen-ts"; -import { buildExplorer, type ExplorerJson } from "@metaobjectsdev/docs-site"; import { resolveSchemaConventions, serializeSnapshot } from "@metaobjectsdev/migrate-ts"; import { buildAgentSchemaInput } from "../src/lib/agent-schema.js"; @@ -41,33 +40,23 @@ function metaFiles(dir: string): { id: string; text: string }[] { const str = (v: unknown): string | undefined => (typeof v === "string" && v !== "" ? v : undefined); -/** The requirement rows as the docs site would read them off the explorer graph. */ -function rowsFromGraph(doc: ExplorerJson): RequirementRow[] { - const nodes = new Map(doc.nodes.map((n) => [n.id, n])); - return (doc.ledger?.rows ?? []).map((row) => { - const attrs = nodes.get(row.node)?.attrs ?? {}; - const trackedBy = attrs["trackedBy"]; - const concerns = row.implementedBy - .filter((l) => l.resolves && l.target !== undefined) - .map((l) => nodes.get(l.target as string)) - .filter((n) => n !== undefined) - .map((n) => `${n.type}.${n.subType}`); - return { - path: row.path, - depth: row.path.split(".").length - 1, - title: str(attrs["title"]), - subType: row.subType, - level: row.level, - status: row.status, - disposition: row.disposition, - trackedBy: Array.isArray(trackedBy) ? (trackedBy as string[]) : [], - statement: str(attrs["statement"]), - counterexample: str(attrs["counterexample"]), - description: str(attrs["description"]), - implementedBy: row.implementedBy.map((l) => l.ref), - claimedConcerns: [...new Set(concerns)], - }; - }); +/** The requirement rows as the docs site would read them off the docs view. */ +function rowsFromView(view: DocsView): RequirementRow[] { + return view.requirements.map((r) => ({ + path: r.address, + depth: r.depth, + title: str(r.title), + subType: r.subType, + level: r.level ?? undefined, + status: r.status, + disposition: str(r.disposition), + trackedBy: r.trackedBy, + statement: str(r.statement), + counterexample: str(r.counterexample), + description: str(r.description), + implementedBy: r.implementedBy.map((l) => l.ref), + claimedConcerns: [...new Set(r.implementedBy.filter((l) => l.resolves).map((l) => l.target.kind))], + })); } /** True when every key of `part` is in `whole` with an equal value (arrays: element-wise). */ @@ -86,16 +75,13 @@ function isSubset(part: unknown, whole: unknown): boolean { const byName = (list: readonly T[]): Map => new Map(list.map((x) => [x.name, x])); describe("docs page rows are the docs site's rows", () => { - test("requirement rows equal what the explorer graph holds (explorer-conformance/shop)", async () => { + test("requirement rows equal what the docs view holds (explorer-conformance/shop)", async () => { const root = await load(metaFiles(join(SHOP, "project/metaobjects"))); - const doc = buildExplorer({ - model: JSON.parse(readFileSync(join(SHOP, "effective.json"), "utf8")), - verify: JSON.parse(readFileSync(join(SHOP, "verify.json"), "utf8")), - }); + const view = buildDocsView({ root, verify: JSON.parse(readFileSync(join(SHOP, "verify.json"), "utf8")) as unknown }); const fromModel = requirementRows(root); expect(fromModel.length).toBeGreaterThan(0); // JSON round trip: absent keys and `undefined` values compare the same, as they do on disk. - expect(JSON.parse(JSON.stringify(rowsFromGraph(doc)))).toEqual(JSON.parse(JSON.stringify(fromModel))); + expect(JSON.parse(JSON.stringify(rowsFromView(view)))).toEqual(JSON.parse(JSON.stringify(fromModel))); }); const cases = readdirSync(CORPUS, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort(); diff --git a/server/typescript/packages/cli/test/explorer-fixture.test.ts b/server/typescript/packages/cli/test/explorer-fixture.test.ts index 08debae401..3c43ccc1f3 100644 --- a/server/typescript/packages/cli/test/explorer-fixture.test.ts +++ b/server/typescript/packages/cli/test/explorer-fixture.test.ts @@ -1,22 +1,42 @@ -// The explorer data spine, end to end, over `fixtures/explorer-conformance/shop/`: +// The docs view corpus, end to end (`fixtures/explorer-conformance/`): // -// `meta export --effective` → effective.json (committed) -// `meta verify --format json` → verify.json (committed; carries `requirementLedger`) -// buildExplorer(both + the manifest) → expected.json (committed, byte-checked in docs-site) +// shop/ `meta verify --format json` → verify.json (committed; carries `requirementLedger`) +// crm/ the same payload (`requirementPayload`), loaded with the fixture's provider.json, +// since the CLI reads providers from a TypeScript config the fixture does not carry +// buildDocsView(the loaded project + the committed inputs) → expected.json +// (committed, byte-checked in metadata's docs-view-conformance.test.ts) // // This file keeps the committed INPUTS honest: regenerating them from `project/` must give -// the same bytes, so a change to either command's output shows up here as a fixture diff -// rather than as an explorer that quietly reads stale data. +// the same bytes, so a change to the gate's output shows up here as a fixture diff rather +// than as a docs site that quietly reads stale data. +// +// Regenerate crm/verify.json after a deliberate change: `UPDATE_DOCS_VIEW=1 bun test test/explorer-fixture.test.ts`. import { describe, test, expect, beforeEach, afterEach, afterAll } from "bun:test"; -import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; -import { buildExplorer, serializeExplorer } from "@metaobjectsdev/docs-site"; +import { + MetaData, + MetaDataLoader, + applyProviderDefinition, + buildDocsView, + composeRegistry, + coreProviders, + serializeDocsView, + type FactoryMap, + type ProviderDefinition, +} from "@metaobjectsdev/metadata"; +import { requirementPayload } from "../src/lib/requirement-payload.js"; import { run } from "../src/index.js"; -const FIXTURE = resolve(import.meta.dir, "../../../../../fixtures/explorer-conformance/shop"); +/** A node of a type the fixture's provider.json declares: no behaviour beyond MetaData's own. */ +class FixtureNode extends MetaData {} + +const CORPUS = resolve(import.meta.dir, "../../../../../fixtures/explorer-conformance"); +const FIXTURE = join(CORPUS, "shop"); const PROJECT = join(FIXTURE, "project"); -const committed = (name: string): string => readFileSync(join(FIXTURE, name), "utf8"); +const CRM = join(CORPUS, "crm"); +const committed = (name: string, dir = FIXTURE): string => readFileSync(join(dir, name), "utf8"); const dirs: string[] = []; afterAll(() => { @@ -53,6 +73,20 @@ async function verifyJson(): Promise { return out.join("\n") + "\n"; } +/** The crm project, loaded with the vocabulary its provider.json declares. */ +async function loadCrm(): Promise { + const def = JSON.parse(committed("provider.json", CRM)) as ProviderDefinition; + const factories: FactoryMap = {}; + for (const t of def.types ?? []) factories[`${t.type}.${t.subType}`] = (id, name) => new FixtureNode(id, name); + const registry = composeRegistry([ + ...coreProviders, + { id: def.provider, dependencies: ["metaobjects-core-types"], registerTypes: (r) => applyProviderDefinition(r, def, factories) }, + ]); + const loaded = await MetaDataLoader.fromDirectory(join(CRM, "project", "metaobjects"), { strict: true, registry }); + expect(loaded.errors.map(String)).toEqual([]); + return loaded.root; +} + interface LedgerRow { path: string; qualifiedPath: string; @@ -62,21 +96,29 @@ interface LedgerRow { diagnostics: { code: string; severity: string; source: string; message: string }[]; } -describe("explorer fixture — the committed inputs are what the CLI writes today", () => { - test("`meta export --effective` reproduces effective.json", async () => { - expect(await exportJson(true)).toBe(committed("effective.json")); +describe("docs view corpus — the committed inputs are what the gate writes today", () => { + test("shop: `meta verify --format json` reproduces verify.json", async () => { + expect(await verifyJson()).toBe(committed("verify.json")); }); - test("`meta verify --format json` reproduces verify.json", async () => { - expect(await verifyJson()).toBe(committed("verify.json")); + test("shop: the fresh verify payload builds the committed expected.json", async () => { + const verify = JSON.parse(await verifyJson()) as unknown; + const loaded = await MetaDataLoader.fromDirectory(join(PROJECT, "metaobjects"), { strict: true }); + const view = buildDocsView({ + root: loaded.root, + verify, + manifest: JSON.parse(committed("hashes.json")) as unknown, + routes: JSON.parse(committed("routes.json")) as unknown, + }); + expect(serializeDocsView(view)).toBe(committed("expected.json")); }); - test("the fresh inputs build the committed expected.json", async () => { - const model = JSON.parse(await exportJson(true)); - out = []; - const verify = JSON.parse(await verifyJson()); - const manifest = JSON.parse(committed("hashes.json")); - expect(serializeExplorer(buildExplorer({ model, verify, manifest }))).toBe(committed("expected.json")); + test("crm: the gate's payload reproduces verify.json", async () => { + const root = await loadCrm(); + const files = readdirSync(join(CRM, "project", "metaobjects")).sort(); + const actual = JSON.stringify(requirementPayload(root, { inCoverage: () => true, files }), null, 2) + "\n"; + if (process.env.UPDATE_DOCS_VIEW === "1") writeFileSync(join(CRM, "verify.json"), actual); + expect(actual).toBe(committed("verify.json", CRM)); }); }); diff --git a/server/typescript/packages/cli/test/explorer-site-ledger.test.ts b/server/typescript/packages/cli/test/explorer-site-ledger.test.ts index 4bc3e27e4f..7c9a3b646c 100644 --- a/server/typescript/packages/cli/test/explorer-site-ledger.test.ts +++ b/server/typescript/packages/cli/test/explorer-site-ledger.test.ts @@ -5,9 +5,9 @@ import { afterAll, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { canonicalSerializeEffective } from "@metaobjectsdev/metadata"; +import { buildDocsView } from "@metaobjectsdev/metadata"; import { loadMemory } from "@metaobjectsdev/sdk"; -import { buildExplorer, generateExplorerSite } from "@metaobjectsdev/docs-site"; +import { generateExplorerSite } from "@metaobjectsdev/docs-site"; import { requirementPayload } from "../src/lib/requirement-payload.js"; import { ERR_REQUIREMENT_DANGLING_REF, WARN_REQUIREMENT_NOTHING_IMPLEMENTS } from "../src/lib/requirement-check.js"; import { WARN_REQUIREMENT_TITLE_IS_AN_ID } from "../src/lib/requirement-lint.js"; @@ -27,9 +27,9 @@ async function site(files: Record): Promise<{ page: (p: string) const root = await loadMemory(dir, { strict: true }); const verify = requirementPayload(root, { inCoverage: () => true, files: Object.keys(files) }); if (verify === undefined) throw new Error("the model declares requirements"); - const explorer = buildExplorer({ model: JSON.parse(canonicalSerializeEffective(root)) as unknown, verify }); + const view = buildDocsView({ root, verify }); const out = join(dir, "site"); - generateExplorerSite({ explorer, outDir: out, title: "Ledger" }); + generateExplorerSite({ view, outDir: out, title: "Ledger" }); return { page: (p) => readFileSync(join(out, p), "utf8"), undecided: verify.requirementCounts.undecided }; } diff --git a/server/typescript/packages/cli/test/gen-docs-generators.test.ts b/server/typescript/packages/cli/test/gen-docs-generators.test.ts index c50009060e..efbcd18b43 100644 --- a/server/typescript/packages/cli/test/gen-docs-generators.test.ts +++ b/server/typescript/packages/cli/test/gen-docs-generators.test.ts @@ -254,8 +254,8 @@ describe("meta gen writes the documentation the list declares", () => { expect(index).toContain("by the metaobjects docs-site generator. Static"); expect(existsSync(join(site, "model", "app", "Talk.html"))).toBe(true); // It runs after the entity generator, so the files that run wrote are traced to their node. - const explorer = JSON.parse(readFileSync(join(site, "explorer.json"), "utf8")) as { generated?: { node: string; files: { path: string }[] }[] }; - expect(explorer.generated?.find((g) => g.node === "app::Talk")?.files.map((f) => f.path)).toEqual( + const view = JSON.parse(readFileSync(join(site, "explorer.json"), "utf8")) as { nodes: { id: string; files: { paths: string[] }[] }[] }; + expect(view.nodes.find((x) => x.id === "app::Talk")?.files.flatMap((g) => g.paths)).toEqual( expect.arrayContaining([expect.stringContaining("Talk.ts")]), ); diff --git a/server/typescript/packages/cli/test/unit/rules-inert.test.ts b/server/typescript/packages/cli/test/unit/rules-inert.test.ts index e0e091a2ef..d90beabf02 100644 --- a/server/typescript/packages/cli/test/unit/rules-inert.test.ts +++ b/server/typescript/packages/cli/test/unit/rules-inert.test.ts @@ -24,7 +24,7 @@ import { copyFileSync, mkdirSync, mkdtempSync, rmSync, readFileSync, readdirSync import { tmpdir } from "node:os"; import { join, relative, resolve, sep } from "node:path"; import { pathToFileURL } from "node:url"; -import { loadUris, TYPE_API, type MetaRoot } from "@metaobjectsdev/metadata"; +import { loadUris, TYPE_API, type DocsView, type MetaRoot } from "@metaobjectsdev/metadata"; import { runGen, buildProjectionViews, type Generator, type MetaobjectsGenConfig } from "@metaobjectsdev/codegen-ts"; import { buildExpectedSchema } from "@metaobjectsdev/migrate-ts"; import { composeCatalog } from "../../src/lib/catalog.js"; @@ -179,7 +179,8 @@ describe("ADR-0066 the business-rules vocabulary is inert in every generator and const actual = await emit(withRules, [catalog[DOCS_SITE]!.factory()]); expect(expected[""]).toBeUndefined(); // Every top-level node gets an explorer page, so the declared API (`Purchasing`) adds its - // own; no page the model already had goes away. + // own; no page the model already had goes away. The value objects its operations name in + // `@inputRef` / `@outputRef` are referenced by it, so their pages list it. const site = "src/generated/site/"; expect(Object.keys(expected).filter((p) => !(p in actual))).toEqual([]); expect(Object.keys(actual).filter((p) => !(p in expected))).toEqual([`${site}model/acme/purchasing/Purchasing.html`]); @@ -188,18 +189,31 @@ describe("ADR-0066 the business-rules vocabulary is inert in every generator and `${site}assets/explorer-data.js`, `${site}explorer.json`, `${site}index.html`, + `${site}model/acme/purchasing/DecisionInput.html`, + `${site}model/acme/purchasing/RequestSummary.html`, `${site}model/acme/purchasing/index.html`, `${site}model/index.html`, ]); - // The data payload: every line it had is still there, in order; every added line belongs to - // a new node. + // The data payload (the docs view): the API is the one new node; every node the model had + // keeps its members, references and claims, and gains a referrer only from the API. const data = `${site}explorer.json`; + const v0 = JSON.parse(expected[data]!) as DocsView; + const v1 = JSON.parse(actual[data]!) as DocsView; + const ids0 = new Set(v0.nodes.map((x) => x.id)); + const api = v1.nodes.filter((x) => !ids0.has(x.id)); + expect(api.map((x) => x.type)).toEqual([TYPE_API]); + const apiId = api[0]!.id; + expect(v1.requirements).toEqual(v0.requirements); + for (const n0 of v0.nodes) { + const n1 = v1.nodes.find((x) => x.id === n0.id)!; + const fresh = n1.referencedBy.filter((r) => !n0.referencedBy.some((q) => JSON.stringify(q) === JSON.stringify(r))); + expect({ node: n0.id, from: [...new Set(fresh.map((r) => r.from.id))] }).toEqual({ node: n0.id, from: fresh.length > 0 ? [apiId] : [] }); + expect(n1.refs).toEqual(n0.refs); + expect(n1.claims).toEqual(n0.claims); + } const before = expected[data]!.split("\n"); const after = actual[data]!.split("\n"); - let kept = 0; - for (const line of after) if (line === before[kept]) kept++; - expect(kept).toBe(before.length); const beforeLines = new Set(before); const ids = after.filter((l) => !beforeLines.has(l) && l.includes(`"type": `)).map((l) => l.trim()); expect([...new Set(ids)].sort()).toEqual( @@ -216,8 +230,15 @@ describe("ADR-0066 the business-rules vocabulary is inert in every generator and ]); expect({ ...g1, search: undefined }).toEqual({ ...g0, search: undefined }); - // The HTML pages that list the package's members name the API, and change nowhere else. - for (const page of [`${site}index.html`, `${site}model/index.html`, `${site}model/acme/purchasing/index.html`]) { + // The HTML pages that list the package's members, or what references a node, name the API, + // and change nowhere else. + for (const page of [ + `${site}index.html`, + `${site}model/index.html`, + `${site}model/acme/purchasing/index.html`, + `${site}model/acme/purchasing/DecisionInput.html`, + `${site}model/acme/purchasing/RequestSummary.html`, + ]) { const b = new Set(expected[page]!.split("\n")); const changed = actual[page]!.split("\n").filter((l) => !b.has(l)); // The page and the offending lines, so a failure names what moved. diff --git a/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts b/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts index b5b8153fe1..6241ea9fd5 100644 --- a/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts +++ b/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts @@ -23,14 +23,8 @@ import { readFileSync } from "node:fs"; import { basename, join, resolve } from "node:path"; import { existsSync } from "node:fs"; -import { canonicalSerializeEffective } from "@metaobjectsdev/metadata"; -import { - buildExplorer, - generateExplorerSite, - generateSite, - readPromptTexts, - type ExplorerRoute, -} from "@metaobjectsdev/docs-site"; +import { buildDocsView } from "@metaobjectsdev/metadata"; +import { generateExplorerSite, generateSite, readPromptTexts } from "@metaobjectsdev/docs-site"; import type { EmittedFile, GenContext, Generator, GeneratorFactory } from "../generator.js"; import { DOCS_TARGET_NAME } from "../docs-run.js"; import { buildApiModelForRun } from "./api-model.js"; @@ -162,8 +156,15 @@ async function buildInScratch(prefix: string, build: (outDir: string) => string[ } /** The routes the run mounts, as the api reference states them (`METHOD /path` per symbol). */ -function runRoutes(ctx: GenContext): ExplorerRoute[] { - const routes: ExplorerRoute[] = []; +/** A route the run mounts, keyed by its node's resolution key: the docs view's `routes` input. */ +interface RunRoute { + node: string; + method: string; + path: string; +} + +function runRoutes(ctx: GenContext): RunRoute[] { + const routes: RunRoute[] = []; for (const unit of buildApiModelForRun(ctx).units) { const node = unit.package !== undefined && unit.package !== "" ? `${unit.package}::${unit.node}` : unit.node; for (const sym of unit.symbols) { @@ -194,13 +195,15 @@ async function explorerSite(ctx: GenContext, project: string, prefix: string, op // No route at all means this run recorded none (no routes generator, or REST off), which the // site says as such; an empty list would claim the run mounted nothing. const routes = runRoutes(ctx); - const explorer = buildExplorer({ - model: JSON.parse(canonicalSerializeEffective(ctx.loadedRoot)) as unknown, + // The docs view is built from the model this run already loaded: ids, pages, inheritance and + // references are the loader's, never re-derived from a serialized copy. + const view = buildDocsView({ + root: ctx.loadedRoot, ...(ledger !== undefined && { verify: ledger }), manifest, ...(routes.length > 0 && { routes }), }); - const texts = readPromptTexts(explorer, promptSourceDirs(ctx, project, opts, ctx.sourceRoots ?? [])); + const texts = readPromptTexts(view, promptSourceDirs(ctx, project, opts, ctx.sourceRoots ?? [])); const owned = ownedSiteDirs(project); if (owned.templatesDir !== undefined && !existsSync(join(owned.templatesDir, EXPLORER_MARKER_TEMPLATE))) { ctx.warn( @@ -210,7 +213,7 @@ async function explorerSite(ctx: GenContext, project: string, prefix: string, op ); } return buildInScratch(prefix, (outDir) => generateExplorerSite({ - explorer, + view, outDir, title: opts?.title ?? (basename(project) || "Metadata"), stamp: opts?.stamp ?? "", diff --git a/server/typescript/packages/codegen-ts/test/docs-site-explorer.test.ts b/server/typescript/packages/codegen-ts/test/docs-site-explorer.test.ts index 86f4c24a04..d9a8ff5be4 100644 --- a/server/typescript/packages/codegen-ts/test/docs-site-explorer.test.ts +++ b/server/typescript/packages/codegen-ts/test/docs-site-explorer.test.ts @@ -1,10 +1,10 @@ -// docsSiteFile() builds the model explorer by default: explorer.json from the effective model, -// the requirement ledger the caller hands the run, the files the run wrote and the routes it -// mounts. It runs after the generators declared beside it, whatever their order. +// docsSiteFile() builds the model explorer by default: explorer.json (the docs view, +// docs/features/docs-view.md) from the loaded model, the requirement ledger the caller hands +// the run, the files the run wrote and the routes it mounts. It runs after the generators declared beside it, whatever their order. import { describe, test, expect, beforeEach, afterEach } from "bun:test"; import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs"; import { join, resolve } from "node:path"; -import { MetaDataLoader, type MetaRoot } from "@metaobjectsdev/metadata"; +import { MetaDataLoader, type DocsView, type MetaRoot } from "@metaobjectsdev/metadata"; import { FileSource } from "@metaobjectsdev/metadata/core"; import { runGen } from "../src/runner.js"; import { defineConfig } from "../src/metaobjects-config.js"; @@ -14,12 +14,6 @@ import { makeScratchDir, removeTree } from "../src/scratch-dir.js"; const FIXTURE = resolve(import.meta.dir, "fixtures", "single-entity.json"); -interface ExplorerShape { - generated?: { node: string; files: { path: string; generatedBy: string }[] }[]; - api?: { node: string; method: string; path: string }[]; - ledger?: unknown; -} - let tmp: string; let root: MetaRoot; // The run's one metadata source directory (the classic site loads whole directories). @@ -44,8 +38,8 @@ const config = (generators: Generator[]) => generators, }); -const explorerOf = (): ExplorerShape => - JSON.parse(readFileSync(join(tmp, "docs", "site", "explorer.json"), "utf8")) as ExplorerShape; +const explorerOf = (): DocsView => + JSON.parse(readFileSync(join(tmp, "docs", "site", "explorer.json"), "utf8")) as DocsView; describe("docsSiteFile() builds the model explorer", () => { test("declared first, it still sees what the code generators wrote, and the routes they mount", async () => { @@ -57,15 +51,19 @@ describe("docsSiteFile() builds the model explorer", () => { }); expect(existsSync(join(tmp, "docs", "site", "index.html"))).toBe(true); const ex = explorerOf(); - const post = ex.generated?.find((g) => g.node.endsWith("Post")); - expect(post?.files.map((f) => f.generatedBy)).toEqual(expect.arrayContaining(["entity-file", "routes-file"])); - expect(ex.api?.some((r) => r.node.endsWith("Post") && r.method === "GET" && r.path.startsWith("/api/"))).toBe(true); + const post = ex.nodes.find((n) => n.id.endsWith("Post")); + expect(ex.sources.files).toBe(true); + expect(post?.files.map((g) => g.generatedBy)).toEqual(expect.arrayContaining(["entity-file", "routes-file"])); + expect(ex.sources.routes).toBe(true); + expect(post?.routes.some((r) => r.method === "GET" && r.path.startsWith("/api/"))).toBe(true); expect(readFileSync(join(tmp, "docs", "site", "api.html"), "utf8")).toContain("/api/"); }); test("without a routes generator in the run, the site says no routes were recorded, not that none are mounted", async () => { await runGen({ config: config([entityFile(), docsSiteFile()]), metadata: root, projectRoot: tmp, sourceRoots: [sources] }); - expect(explorerOf().api).toBeUndefined(); + const ex = explorerOf(); + expect(ex.sources.routes).toBe(false); + expect(ex.nodes.every((n) => n.routes.length === 0)).toBe(true); expect(readFileSync(join(tmp, "docs", "site", "api.html"), "utf8")).toContain("recorded no routes"); }); @@ -77,7 +75,7 @@ describe("docsSiteFile() builds the model explorer", () => { sourceRoots: [sources], requirementLedger: () => { throw new Error("gate exploded"); }, }); - expect(explorerOf().ledger).toBeUndefined(); + expect(explorerOf().sources.requirements).toBe(false); expect(result.warnings.some((w) => w.includes("gate exploded"))).toBe(true); }); @@ -94,7 +92,7 @@ describe("docsSiteFile() builds the model explorer", () => { }, }); expect(calls).toBe(1); - expect(explorerOf().ledger).toBeDefined(); + expect(explorerOf().sources.requirements).toBe(true); }); test("site: \"classic\" builds the earlier site and no explorer.json", async () => { diff --git a/server/typescript/packages/docs-site/README.md b/server/typescript/packages/docs-site/README.md index c3938a9f7a..97a1ba15bb 100644 --- a/server/typescript/packages/docs-site/README.md +++ b/server/typescript/packages/docs-site/README.md @@ -75,10 +75,12 @@ packaged copy is what the option fills. The explorer: ```ts -import { buildExplorer, generateExplorerSite, readPromptTexts } from "@metaobjectsdev/docs-site"; +import { buildDocsView } from "@metaobjectsdev/metadata"; +import { generateExplorerSite, readPromptTexts } from "@metaobjectsdev/docs-site"; -const explorer = buildExplorer({ model, verify, manifest, routes }); -generateExplorerSite({ explorer, outDir: "docs/site", title: "My Model", texts: readPromptTexts(explorer, ["prompts"]) }); +// root: the loaded model. verify, manifest and routes are optional (docs/features/docs-view.md). +const view = buildDocsView({ root, verify, manifest, routes }); +generateExplorerSite({ view, outDir: "docs/site", title: "My Model", texts: readPromptTexts(view, ["prompts"]) }); ``` The classic site: diff --git a/server/typescript/packages/docs-site/assets/explorer.js b/server/typescript/packages/docs-site/assets/explorer.js index 680dc59d2c..094bc5075f 100644 --- a/server/typescript/packages/docs-site/assets/explorer.js +++ b/server/typescript/packages/docs-site/assets/explorer.js @@ -156,7 +156,7 @@ var promptSet = function () { var s = {}; D.nodes.forEach(function (n) { if (n.kind === "prompt" || n.kind === "template") s[n.id] = 1; }); - D.edges.forEach(function (e) { if (s[e.s] && (e.k === "payload" || e.k === "reply")) s[e.t] = 1; }); + D.edges.forEach(function (e) { if (s[e.s] && (e.k === "payloadRef" || e.k === "responseRef")) s[e.t] = 1; }); D.edges.forEach(function (e) { if (s[e.s] && byId[e.s] && byId[e.s].kind === "value" && e.k === "objectRef") s[e.t] = 1; }); return s; }; diff --git a/server/typescript/packages/docs-site/src/explorer/build.ts b/server/typescript/packages/docs-site/src/explorer/build.ts deleted file mode 100644 index 899dbc15ea..0000000000 --- a/server/typescript/packages/docs-site/src/explorer/build.ts +++ /dev/null @@ -1,457 +0,0 @@ -// The `explorer.json` builder — the data spine every explorer page reads. -// -// PORT-NEUTRAL INPUT, on purpose. It reads three documents and never the loader: -// -// model the EFFECTIVE canonical JSON (`meta export --effective`): inheritance and -// overlays already resolved, references already in their canonical spelling. -// verify the `meta verify --format json` payload: the requirement ledger rows, each -// link as the gate resolved it, the counts and the findings. -// manifest the entries of `.metaobjects/.gen-state/.hashes/`: which generated file came from which -// node, where the port records it. -// -// Every port already has a canonical serializer and writes the same manifest, so a Java, C# -// or Python project can feed this without the Node CLI knowing its providers. The builder -// therefore resolves nothing the inputs have not resolved: an `@implementedBy` link becomes -// an edge only because the verify row names its target, never by a name match here. -// -// DETERMINISTIC: the same three inputs give the same bytes (`serializeExplorer`), so the -// file can sit under a drift gate. - -import { - ATTR_PREFIX, - FIELD_ATTR_OBJECT_REF, - IDENTITY_REFERENCE_ATTR_REFERENCES, - IDENTITY_SUBTYPE_REFERENCE, - PACKAGE_SEPARATOR, - CHILD_REF_SEPARATOR, - RELATIONSHIP_ATTR_OBJECT_REF, - RESERVED_KEY_ABSTRACT, - RESERVED_KEY_CHILDREN, - RESERVED_KEY_EXTENDS, - RESERVED_KEY_IS_ARRAY, - RESERVED_KEY_NAME, - RESERVED_KEY_PACKAGE, - SUBTYPE_ROOT, - TEMPLATE_ATTR_PAYLOAD_REF, - TEMPLATE_ATTR_RESPONSE_REF, - TYPE_FIELD, - TYPE_IDENTITY, - TYPE_METADATA, - TYPE_OBJECT, - TYPE_RELATIONSHIP, - TYPE_REQUIREMENT, - TYPE_SUBTYPE_SEPARATOR, - TYPE_TEMPLATE, -} from "@metaobjectsdev/metadata/constants"; -import { - EXPLORER_FORMAT, - type ExplorerEdge, - type ExplorerEdgeKind, - type ExplorerGenerated, - type ExplorerJson, - type ExplorerLedger, - type ExplorerLedgerRow, - type ExplorerNode, - type ExplorerRoute, - type ExplorerSlice, -} from "./types.js"; - -export interface ExplorerInput { - /** Parsed `meta export --effective` output (or any port's effective canonical JSON). */ - model: unknown; - /** Parsed `meta verify --format json` output. Without it there is no ledger and no - * `implementedBy` / `supersededBy` edge. */ - verify?: unknown; - /** The merged entries of `.metaobjects/.gen-state/.hashes/`. Without it there is no `generated`. */ - manifest?: unknown; - /** The routes the project mounts: `[{ node, method, path }]`, one per route, `node` a node - * id. A route whose node is not in the model is dropped. Without it there is no `api`. */ - routes?: unknown; -} - -const ROOT_KEY = `${TYPE_METADATA}${TYPE_SUBTYPE_SEPARATOR}${SUBTYPE_ROOT}`; - -/** Code-unit order: the same in every runtime and locale, unlike `localeCompare`. */ -const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0); - -function isRecord(v: unknown): v is Record { - return typeof v === "object" && v !== null && !Array.isArray(v); -} - -/** One `{ ".": body }` element of a `children` array. */ -interface RawChild { - type: string; - subType: string; - body: Record; -} - -function rawChildren(body: Record): RawChild[] { - const list = body[RESERVED_KEY_CHILDREN]; - if (!Array.isArray(list)) return []; - const out: RawChild[] = []; - for (const el of list) { - if (!isRecord(el)) continue; - const keys = Object.keys(el); - if (keys.length !== 1) continue; - const key = keys[0] as string; - const inner = el[key]; - if (!isRecord(inner)) continue; - const sep = key.indexOf(TYPE_SUBTYPE_SEPARATOR); - out.push({ - type: sep === -1 ? key : key.slice(0, sep), - subType: sep === -1 ? "" : key.slice(sep + 1), - body: inner, - }); - } - return out; -} - -function attrsOf(body: Record): Record { - const out: Record = {}; - for (const key of Object.keys(body).sort(byCodeUnit)) { - if (key.startsWith(ATTR_PREFIX)) out[key.slice(ATTR_PREFIX.length)] = body[key]; - } - return out; -} - -function stringAttr(body: Record, name: string): string | undefined { - const v = body[`${ATTR_PREFIX}${name}`]; - return typeof v === "string" && v !== "" ? v : undefined; -} - -/** A node as walked, before it is written out: its id, its raw body and its top-level owner. */ -interface Walked { - node: ExplorerNode; - body: Record; - /** The id of the top-level node this one sits under (itself, at the top). */ - owner: string; - /** The id as a dotted path names it, before any type qualifier: what `verify` prints. */ - path: string; -} - -function walkModel(model: unknown): Walked[] { - if (!isRecord(model) || !isRecord(model[ROOT_KEY])) { - throw new Error(`explorer: the model is not canonical metadata JSON — expected one "${ROOT_KEY}" object`); - } - const root = model[ROOT_KEY] as Record; - const rootPkg = typeof root[RESERVED_KEY_PACKAGE] === "string" ? (root[RESERVED_KEY_PACKAGE] as string) : ""; - const out: Walked[] = []; - const seen = new Set(); - const topLevel = rawChildren(root); - const topPlainId = (child: RawChild): string => { - const name = typeof child.body[RESERVED_KEY_NAME] === "string" ? (child.body[RESERVED_KEY_NAME] as string) : ""; - const own = child.body[RESERVED_KEY_PACKAGE]; - const pkg = typeof own === "string" ? own : rootPkg; - return pkg === "" ? name : `${pkg}${PACKAGE_SEPARATOR}${name}`; - }; - // Top-level nodes of different types may share a package and a name (an entity `Lead` and - // an application's page `Lead`). One of them keeps the plain id: the object, since every - // reference in the model (`@objectRef`, `@payloadRef`, `extends`) names an object, else the - // first declared. Each other one is qualified by its type, as a nested sibling is. - const plainHolder = new Map(); - for (const child of topLevel) { - const id = topPlainId(child); - const held = plainHolder.get(id); - if (held === undefined || (held.type !== TYPE_OBJECT && child.type === TYPE_OBJECT)) plainHolder.set(id, child); - } - - const visit = (child: RawChild, index: number, parent: Walked | undefined): void => { - const name = typeof child.body[RESERVED_KEY_NAME] === "string" ? (child.body[RESERVED_KEY_NAME] as string) : ""; - let pkg: string; - let id: string; - if (parent === undefined) { - const own = child.body[RESERVED_KEY_PACKAGE]; - pkg = typeof own === "string" ? own : rootPkg; - id = topPlainId(child); - const holder = plainHolder.get(id); - if (name !== "" && holder !== child && holder?.type !== child.type) id = qualified(id, child); - } else { - pkg = parent.node.package; - id = name === "" ? `${parent.node.id}#${index}` : `${parent.node.id}${CHILD_REF_SEPARATOR}${name}`; - // The first sibling of a name keeps the plain id: it is the one a dotted reference - // resolves to. A later sibling of another type sharing the name is qualified by type. - if (name !== "" && seen.has(id)) id = qualified(id, child); - } - if (seen.has(id)) { - throw new Error(`explorer: two nodes share the id "${id}" — the model names two siblings alike`); - } - seen.add(id); - const ext = child.body[RESERVED_KEY_EXTENDS]; - const node: ExplorerNode = { - id, - type: child.type, - subType: child.subType, - name, - package: pkg, - order: index, - ...(parent !== undefined ? { parent: parent.node.id } : {}), - ...(typeof ext === "string" && ext !== "" ? { extends: nodeIdOf(ext) } : {}), - ...(child.body[RESERVED_KEY_ABSTRACT] === true ? { abstract: true as const } : {}), - ...(child.body[RESERVED_KEY_IS_ARRAY] === true ? { isArray: true as const } : {}), - attrs: attrsOf(child.body), - }; - const path = - parent === undefined ? topPlainId(child) : name === "" ? `${parent.path}#${index}` : `${parent.path}${CHILD_REF_SEPARATOR}${name}`; - const walked: Walked = { node, body: child.body, owner: parent === undefined ? id : parent.owner, path }; - out.push(walked); - rawChildren(child.body).forEach((c, i) => visit(c, i, walked)); - }; - - topLevel.forEach((c, i) => visit(c, i, undefined)); - return out; -} - -/** A plain id qualified by the node's type: `[.]`. */ -function qualified(id: string, child: RawChild): string { - return `${id}[${child.type}${TYPE_SUBTYPE_SEPARATOR}${child.subType}]`; -} - -/** A canonical reference spells a root-level target `::Name`; the node's id is `Name`. */ -function nodeIdOf(ref: string): string { - return ref.startsWith(PACKAGE_SEPARATOR) ? ref.slice(PACKAGE_SEPARATOR.length) : ref; -} - -/** - * Mark the members a top-level node's effective tree inherited: a direct child whose type, - * name and body equal a direct child of an ancestor named through `extends`. The id recorded - * is the TOPMOST such ancestor — where the member is declared. - */ -function markInherited(walked: Walked[], byId: Map): void { - const childKey = (w: Walked): string => `${w.node.type}${TYPE_SUBTYPE_SEPARATOR}${w.node.subType}:${w.node.name}`; - const directChildren = new Map>(); - for (const w of walked) { - if (w.node.parent === undefined || w.node.name === "") continue; - const m = directChildren.get(w.node.parent) ?? new Map(); - m.set(childKey(w), w); - directChildren.set(w.node.parent, m); - } - for (const w of walked) { - if (w.node.parent !== undefined || w.node.extends === undefined) continue; - const members = directChildren.get(w.node.id); - if (members === undefined) continue; - for (const [key, member] of members) { - const body = JSON.stringify(member.body); - let declaredOn: string | undefined; - const visited = new Set([w.node.id]); - let cur = byId.get(w.node.extends); - while (cur !== undefined && !visited.has(cur.node.id)) { - visited.add(cur.node.id); - const same = directChildren.get(cur.node.id)?.get(key); - if (same === undefined || JSON.stringify(same.body) !== body) break; - declaredOn = cur.node.id; - cur = cur.node.extends === undefined ? undefined : byId.get(cur.node.extends); - } - if (declaredOn !== undefined) member.node.inheritedFrom = declaredOn; - } - } -} - -function modelEdges(walked: Walked[], byId: Map): ExplorerEdge[] { - const edges: ExplorerEdge[] = []; - const add = (kind: ExplorerEdgeKind, from: string, to: string | undefined, via?: string): void => { - if (to === undefined) return; - const target = nodeIdOf(to); - if (!byId.has(from) || !byId.has(target)) return; - edges.push({ kind, from, to: target, ...(via !== undefined && via !== from ? { via } : {}) }); - }; - for (const w of walked) { - const { node, body, owner } = w; - if (node.extends !== undefined) add("extends", node.id, node.extends); - if (node.type === TYPE_IDENTITY && node.subType === IDENTITY_SUBTYPE_REFERENCE) { - add("references", owner, stringAttr(body, IDENTITY_REFERENCE_ATTR_REFERENCES), node.id); - } - if (node.type === TYPE_FIELD) add("objectRef", owner, stringAttr(body, FIELD_ATTR_OBJECT_REF), node.id); - if (node.type === TYPE_RELATIONSHIP) add("association", owner, stringAttr(body, RELATIONSHIP_ATTR_OBJECT_REF), node.id); - if (node.type === TYPE_TEMPLATE) { - add("payload", node.id, stringAttr(body, TEMPLATE_ATTR_PAYLOAD_REF)); - add("reply", node.id, stringAttr(body, TEMPLATE_ATTR_RESPONSE_REF)); - } - if (node.type === TYPE_REQUIREMENT && node.parent !== undefined && byId.get(node.parent)?.node.type === TYPE_REQUIREMENT) { - add("contains", node.parent, node.id); - } - } - return edges; -} - -function asLinks(v: unknown): { ref: string; resolves: boolean; target?: string }[] { - if (!Array.isArray(v)) return []; - return v.map(asLink).filter((l): l is NonNullable => l !== undefined); -} - -function asLink(v: unknown): { ref: string; resolves: boolean; target?: string } | undefined { - if (!isRecord(v) || typeof v.ref !== "string") return undefined; - return { - ref: v.ref, - resolves: v.resolves === true, - ...(typeof v.target === "string" ? { target: v.target } : {}), - }; -} - -function ledgerFrom(verify: unknown, byId: Map, edges: ExplorerEdge[]): ExplorerLedger | undefined { - if (!isRecord(verify) || !Array.isArray(verify.requirementLedger)) return undefined; - // A ledger row names its requirement by dotted path; the node's id differs only when a - // same-named node of another type took the plain id. - const reqByPath = new Map(); - for (const w of byId.values()) if (w.node.type === TYPE_REQUIREMENT) reqByPath.set(w.path, w.node.id); - const rows: ExplorerLedgerRow[] = []; - for (const raw of verify.requirementLedger) { - if (!isRecord(raw) || typeof raw.qualifiedPath !== "string" || typeof raw.path !== "string") continue; - const node = reqByPath.get(raw.qualifiedPath) ?? raw.qualifiedPath; - const implementedBy = asLinks(raw.implementedBy); - const supersededBy = asLink(raw.supersededBy); - const diagnostics = Array.isArray(raw.diagnostics) - ? raw.diagnostics.filter(isRecord).map((d) => ({ - code: String(d.code ?? ""), - severity: String(d.severity ?? ""), - source: String(d.source ?? ""), - message: String(d.message ?? ""), - })) - : []; - rows.push({ - node, - path: raw.path, - package: typeof raw.package === "string" ? raw.package : "", - qualifiedPath: raw.qualifiedPath, - subType: typeof raw.subType === "string" ? raw.subType : "", - ...(typeof raw.level === "number" ? { level: raw.level } : {}), - ...(typeof raw.status === "string" ? { status: raw.status } : {}), - ...(typeof raw.disposition === "string" ? { disposition: raw.disposition } : {}), - digest: typeof raw.digest === "string" ? raw.digest : "", - implementedBy, - ...(supersededBy !== undefined ? { supersededBy } : {}), - diagnostics, - verdict: typeof raw.verdict === "string" ? raw.verdict : "", - }); - if (byId.has(node)) { - for (const link of implementedBy) { - if (link.target !== undefined && byId.has(link.target)) edges.push({ kind: "implementedBy", from: node, to: link.target }); - } - if (supersededBy?.target !== undefined && byId.has(supersededBy.target)) { - edges.push({ kind: "supersededBy", from: node, to: supersededBy.target }); - } - } - } - const requirements = verify.requirements; - return { - counts: isRecord(verify.requirementCounts) ? verify.requirementCounts : {}, - rows, - diagnostics: isRecord(requirements) && Array.isArray(requirements.rows) ? requirements.rows : [], - }; -} - -function generatedFrom(manifest: unknown): ExplorerGenerated[] | undefined { - if (!isRecord(manifest)) return undefined; - const byNode = new Map(); - for (const [path, entry] of Object.entries(manifest)) { - if (!isRecord(entry) || typeof entry.sourceNode !== "string") continue; - const by = typeof entry.generatedBy === "string" ? entry.generatedBy : ""; - const list = byNode.get(entry.sourceNode) ?? []; - list.push({ path, generatedBy: by }); - byNode.set(entry.sourceNode, list); - } - return [...byNode.keys()].sort(byCodeUnit).map((node) => ({ - node, - files: (byNode.get(node) ?? []).sort((a, b) => byCodeUnit(a.path, b.path)), - })); -} - -function routesFrom(routes: unknown, byId: Map): ExplorerRoute[] | undefined { - if (!Array.isArray(routes)) return undefined; - const seen = new Map(); - for (const r of routes) { - if (!isRecord(r) || typeof r.node !== "string" || typeof r.method !== "string" || typeof r.path !== "string") continue; - if (!byId.has(r.node)) continue; - const route: ExplorerRoute = { node: r.node, method: r.method.toUpperCase(), path: r.path }; - seen.set(`${route.node}\u0000${route.path}\u0000${route.method}`, route); - } - return [...seen.keys()].sort(byCodeUnit).map((k) => seen.get(k) as ExplorerRoute); -} - -function derivedSlices(walked: Walked[], byId: Map, edges: ExplorerEdge[]): ExplorerSlice[] { - const slices: ExplorerSlice[] = []; - const ownerOf = (id: string): string => byId.get(id)?.owner ?? id; - const sorted = (s: Set): string[] => [...s].sort(byCodeUnit); - - // Per package: its top-level nodes. - const packages = new Map>(); - for (const w of walked) { - if (w.node.parent !== undefined) continue; - const set = packages.get(w.node.package) ?? new Set(); - set.add(w.node.id); - packages.set(w.node.package, set); - } - for (const [pkg, ids] of packages) slices.push({ id: `package:${pkg}`, kind: "package", anchor: pkg, nodes: sorted(ids) }); - - // Per requirement subtree, for every requirement with nested requirements: the subtree, - // each node it claims, and the object owning a claimed member. - const containsFrom = new Map(); - const claimsFrom = new Map(); - for (const e of edges) { - const target = e.kind === "contains" ? containsFrom : e.kind === "implementedBy" ? claimsFrom : undefined; - if (target === undefined) continue; - const list = target.get(e.from) ?? []; - list.push(e.to); - target.set(e.from, list); - } - for (const w of walked) { - if (w.node.type !== TYPE_REQUIREMENT || !containsFrom.has(w.node.id)) continue; - const set = new Set(); - const stack = [w.node.id]; - while (stack.length > 0) { - const id = stack.pop() as string; - if (set.has(id)) continue; - set.add(id); - for (const t of claimsFrom.get(id) ?? []) { - set.add(t); - set.add(ownerOf(t)); - } - stack.push(...(containsFrom.get(id) ?? [])); - } - slices.push({ id: `requirement:${w.node.id}`, kind: "requirement", anchor: w.node.id, nodes: sorted(set) }); - } - - // Per prompt: the prompt, its payload and its reply. - for (const w of walked) { - if (w.node.type !== TYPE_TEMPLATE || w.node.parent !== undefined) continue; - const set = new Set([w.node.id]); - for (const e of edges) if (e.from === w.node.id && (e.kind === "payload" || e.kind === "reply")) set.add(e.to); - slices.push({ id: `prompt:${w.node.id}`, kind: "prompt", anchor: w.node.id, nodes: sorted(set) }); - } - - return slices.sort((a, b) => byCodeUnit(a.id, b.id)); -} - -const edgeKey = (e: ExplorerEdge): string => `${e.kind}\u0000${e.from}\u0000${e.to}\u0000${e.via ?? ""}`; - -/** Build `explorer.json` from the port-neutral inputs. Throws when `model` is not canonical - * metadata JSON; a missing or malformed `verify` / `manifest` only leaves its part out. */ -export function buildExplorer(input: ExplorerInput): ExplorerJson { - const walked = walkModel(input.model); - const byId = new Map(walked.map((w) => [w.node.id, w] as const)); - markInherited(walked, byId); - const edges = modelEdges(walked, byId); - const ledger = input.verify !== undefined ? ledgerFrom(input.verify, byId, edges) : undefined; - const generated = input.manifest !== undefined ? generatedFrom(input.manifest) : undefined; - const api = input.routes !== undefined ? routesFrom(input.routes, byId) : undefined; - - // One edge per (kind, from, to, via): an object can reach one target twice through two - // members, which is two edges, but never the same edge twice. - const unique = new Map(); - for (const e of edges) unique.set(edgeKey(e), e); - const sortedEdges = [...unique].sort(([a], [b]) => byCodeUnit(a, b)).map(([, e]) => e); - - return { - format: EXPLORER_FORMAT, - nodes: walked.map((w) => w.node).sort((a, b) => byCodeUnit(a.id, b.id)), - edges: sortedEdges, - ...(ledger !== undefined ? { ledger } : {}), - ...(generated !== undefined ? { generated } : {}), - ...(api !== undefined ? { api } : {}), - slices: derivedSlices(walked, byId, sortedEdges), - }; -} - -/** The file's bytes: two-space JSON and one trailing newline. */ -export function serializeExplorer(explorer: ExplorerJson): string { - return JSON.stringify(explorer, null, 2) + "\n"; -} diff --git a/server/typescript/packages/docs-site/src/explorer/html.ts b/server/typescript/packages/docs-site/src/explorer/html.ts index 278824a70a..d6d2933b58 100644 --- a/server/typescript/packages/docs-site/src/explorer/html.ts +++ b/server/typescript/packages/docs-site/src/explorer/html.ts @@ -9,7 +9,7 @@ // Nothing here colours a test result: the build does not read one. import { REQUIREMENT_ATTR_DISPOSITION } from "@metaobjectsdev/metadata"; -import { STATUSES, STATUS_GLYPH, type ReqEntry, type Rollup } from "./index-model.js"; +import { STATUSES, STATUS_GLYPH, type ReqEntry, type Rollup } from "./view-index.js"; export function esc(s: unknown): string { return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!); @@ -41,7 +41,7 @@ export const GATE_SOURCE = "gate"; /** A gate verdict as an outlined badge: `error` or `warn`, with the finding codes. Authoring * advisories never reach it. */ export function verdictBadge(r: ReqEntry): string { - const gate = (r.row?.diagnostics ?? []).filter((d) => d.source === GATE_SOURCE); + const gate = r.req.diagnostics.filter((d) => d.source === GATE_SOURCE); if (gate.length === 0) return ""; const worst = gate.some((d) => d.severity === "error") ? "error" : "warn"; const codes = gate.map((d) => d.code).join(", "); diff --git a/server/typescript/packages/docs-site/src/explorer/index-model.ts b/server/typescript/packages/docs-site/src/explorer/index-model.ts deleted file mode 100644 index 4d90576dc9..0000000000 --- a/server/typescript/packages/docs-site/src/explorer/index-model.ts +++ /dev/null @@ -1,348 +0,0 @@ -// An in-memory index over one `explorer.json`: the lookups every explorer page shares. -// -// It reads the document and nothing else. A view asks this index; it never walks the loader, so -// what a page shows is exactly what the data spine states (design report §3.1, "views never -// re-derive model facts"). The only arithmetic here is the explorer's own: the roll-up of the -// statuses below a requirement, which §4.2 calls computable and ungated, and which a page shows -// as a separate bar, never as the requirement's colour. - -import { - OBJECT_SUBTYPE_ENTITY, - OBJECT_SUBTYPE_PROJECTION, - OBJECT_SUBTYPE_REPORT, - OBJECT_SUBTYPE_VALUE, - SOURCE_ATTR_KIND, - SOURCE_ATTR_TABLE, - SOURCE_ATTR_VIEW, - SOURCE_KIND_VIEW, - TEMPLATE_SUBTYPE_PROMPT, - TYPE_FIELD, - TYPE_OBJECT, - TYPE_REQUIREMENT, - TYPE_SOURCE, - TYPE_TEMPLATE, -} from "@metaobjectsdev/metadata/constants"; -import { - REQUIREMENT_ATTR_LEVEL, - REQUIREMENT_ATTR_STATUS, - REQUIREMENT_SUBTYPE_ARCHITECTURAL, - REQUIREMENT_SUBTYPE_FUNCTIONAL, - REQUIREMENT_STATUSES, - REQUIREMENT_STATUS_LIVE, - REQUIREMENT_STATUS_PARTIAL, - REQUIREMENT_STATUS_PLANNED, - REQUIREMENT_STATUS_RETIRED, -} from "@metaobjectsdev/metadata"; -import type { ExplorerEdge, ExplorerGeneratedFile, ExplorerJson, ExplorerLedgerRow, ExplorerNode, ExplorerRoute, ExplorerSlice } from "./types.js"; - -/** The four declared statuses, in the order every bar and legend draws them: live first, since - * it is the claim a reader looks for, and the bar reads left to right as "done". */ -export const STATUSES: readonly string[] = [ - REQUIREMENT_STATUS_LIVE, - REQUIREMENT_STATUS_PARTIAL, - REQUIREMENT_STATUS_PLANNED, - REQUIREMENT_STATUS_RETIRED, -].filter((s) => (REQUIREMENT_STATUSES as readonly string[]).includes(s)); -const STATUS_ORDER = STATUSES; - -/** The glyph for each status, so the colour is never the only signal (§4.2). */ -export const STATUS_GLYPH: Readonly> = { - [REQUIREMENT_STATUS_LIVE]: "●", - [REQUIREMENT_STATUS_PARTIAL]: "◐", - [REQUIREMENT_STATUS_PLANNED]: "○", - [REQUIREMENT_STATUS_RETIRED]: "⊘", -}; - -/** Edges drawn between model nodes on the map and the mini-maps. */ -export const MODEL_EDGE_KINDS: readonly string[] = ["references", "association", "objectRef", "payload", "reply", "extends"]; - -const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0); - -/** One requirement as the pages read it: the node, its ledger row, its place in the tree. */ -export interface ReqEntry { - node: ExplorerNode; - row?: ExplorerLedgerRow; - parent?: ReqEntry; - children: ReqEntry[]; - level?: number; - status: string; - /** functional | architectural */ - kind: string; -} - -/** A requirement's claim on a model node, as the ledger resolved it. */ -export interface Claim { - req: ReqEntry; - /** The member path when the claim names a member (`Order.reference`), else undefined. */ - member?: string; -} - -export type Rollup = Record; - -export class ExplorerIndex { - readonly doc: ExplorerJson; - readonly byId = new Map(); - private readonly kids = new Map(); - /** Top-level object nodes (entity, value, projection, report, …), by id. */ - readonly objects: ExplorerNode[] = []; - /** Top-level template nodes (prompt, output, …), by id. */ - readonly templates: ExplorerNode[] = []; - /** Top-level nodes of every other type but requirement: vocabulary an application or a - * provider pack registered (a `capability.module`, a `page.list`), each on a generic page. */ - readonly others: ExplorerNode[] = []; - /** Every requirement, in document order (the ledger's order when there is one). */ - readonly requirements: ReqEntry[] = []; - readonly reqById = new Map(); - /** The top of each requirement tree, in document order. */ - readonly topRequirements: ReqEntry[] = []; - private readonly claimsOn = new Map(); - private readonly generatedOf = new Map(); - private readonly routesOf = new Map(); - readonly packages: string[]; - - constructor(doc: ExplorerJson) { - this.doc = doc; - for (const n of doc.nodes) this.byId.set(n.id, n); - for (const n of doc.nodes) { - if (n.parent === undefined) continue; - const list = this.kids.get(n.parent) ?? []; - list.push(n); - this.kids.set(n.parent, list); - } - for (const list of this.kids.values()) list.sort((a, b) => a.order - b.order || byCodeUnit(a.id, b.id)); - for (const n of doc.nodes) { - if (n.parent !== undefined) continue; - if (n.type === TYPE_OBJECT) this.objects.push(n); - else if (n.type === TYPE_TEMPLATE) this.templates.push(n); - else if (n.type !== TYPE_REQUIREMENT) this.others.push(n); - } - this.packages = [...new Set(doc.nodes.filter((n) => n.parent === undefined).map((n) => n.package))].sort(byCodeUnit); - this.indexRequirements(); - for (const e of doc.edges) { - if (e.kind !== "implementedBy") continue; - const req = this.reqById.get(e.from); - if (req === undefined) continue; - const owner = this.ownerOf(e.to); - const member = owner === e.to ? undefined : e.to.slice(owner.length + 1); - const list = this.claimsOn.get(owner) ?? []; - list.push({ req, ...(member !== undefined ? { member } : {}) }); - this.claimsOn.set(owner, list); - } - for (const g of doc.generated ?? []) this.generatedOf.set(g.node, g.files); - for (const r of doc.api ?? []) { - const list = this.routesOf.get(r.node) ?? []; - list.push(r); - this.routesOf.set(r.node, list); - } - } - - private indexRequirements(): void { - const rows = new Map((this.doc.ledger?.rows ?? []).map((r) => [r.node, r] as const)); - const reqNodes = this.doc.nodes.filter((n) => n.type === TYPE_REQUIREMENT); - // Document order: the ledger's when there is one (the verify payload walks the model in - // declaration order), else each node's sibling order under its parent. - const ledgerOrder = new Map((this.doc.ledger?.rows ?? []).map((r, i) => [r.node, i] as const)); - const depthFirst: ExplorerNode[] = []; - const visit = (n: ExplorerNode): void => { - depthFirst.push(n); - for (const c of this.children(n.id)) if (c.type === TYPE_REQUIREMENT) visit(c); - }; - const tops = reqNodes - .filter((n) => n.parent === undefined || this.byId.get(n.parent)?.type !== TYPE_REQUIREMENT) - .sort((a, b) => (ledgerOrder.get(a.id) ?? Infinity) - (ledgerOrder.get(b.id) ?? Infinity) || a.order - b.order || byCodeUnit(a.id, b.id)); - for (const t of tops) visit(t); - for (const n of depthFirst) { - const row = rows.get(n.id); - const level = typeof n.attrs[REQUIREMENT_ATTR_LEVEL] === "number" ? (n.attrs[REQUIREMENT_ATTR_LEVEL] as number) : row?.level; - const status = typeof n.attrs[REQUIREMENT_ATTR_STATUS] === "string" ? (n.attrs[REQUIREMENT_ATTR_STATUS] as string) : (row?.status ?? ""); - const parent = n.parent !== undefined ? this.reqById.get(n.parent) : undefined; - const entry: ReqEntry = { - node: n, - ...(row !== undefined ? { row } : {}), - ...(parent !== undefined ? { parent } : {}), - children: [], - ...(level !== undefined ? { level } : {}), - status, - kind: n.subType, - }; - this.requirements.push(entry); - this.reqById.set(n.id, entry); - if (parent !== undefined) parent.children.push(entry); - else this.topRequirements.push(entry); - } - } - - /** Direct children of a node, in declaration order. */ - children(id: string): ExplorerNode[] { - return this.kids.get(id) ?? []; - } - - /** The top-level node a node sits under (itself at the top). */ - ownerOf(id: string): string { - let cur = this.byId.get(id); - while (cur?.parent !== undefined) cur = this.byId.get(cur.parent); - return cur?.id ?? id; - } - - fields(id: string): ExplorerNode[] { - return this.children(id).filter((c) => c.type === TYPE_FIELD); - } - - /** The node's `source.*` child, when it declares one. */ - source(id: string): ExplorerNode | undefined { - return this.children(id).find((c) => c.type === TYPE_SOURCE); - } - - /** `table x`, `view v_x`, or undefined: what the source declares, never a derived name. */ - storage(id: string): { kind: "table" | "view"; name?: string } | undefined { - const s = this.source(id); - if (s === undefined) return undefined; - const view = s.attrs[SOURCE_ATTR_VIEW]; - const table = s.attrs[SOURCE_ATTR_TABLE]; - const isView = s.attrs[SOURCE_ATTR_KIND] === SOURCE_KIND_VIEW || typeof view === "string"; - const name = typeof view === "string" ? view : typeof table === "string" ? table : undefined; - return { kind: isView ? "view" : "table", ...(name !== undefined ? { name } : {}) }; - } - - isEntity(n: ExplorerNode): boolean { - return n.type === TYPE_OBJECT && n.subType === OBJECT_SUBTYPE_ENTITY; - } - - isPrompt(n: ExplorerNode): boolean { - return n.type === TYPE_TEMPLATE && n.subType === TEMPLATE_SUBTYPE_PROMPT; - } - - /** The kind a page and the map name a top-level node by. */ - kindOf(n: ExplorerNode): "entity" | "value" | "projection" | "report" | "prompt" | "template" | "object" | "other" { - if (n.type === TYPE_TEMPLATE) return n.subType === TEMPLATE_SUBTYPE_PROMPT ? "prompt" : "template"; - if (n.type !== TYPE_OBJECT) return "other"; - if (n.subType === OBJECT_SUBTYPE_ENTITY) return "entity"; - if (n.subType === OBJECT_SUBTYPE_VALUE) return "value"; - if (n.subType === OBJECT_SUBTYPE_PROJECTION) return "projection"; - if (n.subType === OBJECT_SUBTYPE_REPORT) return "report"; - return "object"; - } - - /** Concrete stored entities: `object.entity`, not abstract. */ - storedEntities(): ExplorerNode[] { - return this.objects.filter((o) => this.isEntity(o) && o.abstract !== true); - } - - claims(id: string): Claim[] { - return this.claimsOn.get(id) ?? []; - } - - generated(id: string): ExplorerGeneratedFile[] { - return this.generatedOf.get(id) ?? []; - } - - routes(id: string): ExplorerRoute[] { - return this.routesOf.get(id) ?? []; - } - - hasRequirements(): boolean { - return this.requirements.length > 0; - } - - /** Whether any requirement claims anything: object coverage only means something then. */ - hasClaims(): boolean { - return this.claimsOn.size > 0; - } - - /** The requirement and every requirement below it, depth first. */ - subtree(r: ReqEntry): ReqEntry[] { - const out: ReqEntry[] = []; - const walk = (x: ReqEntry): void => { - out.push(x); - for (const c of x.children) walk(c); - }; - walk(r); - return out; - } - - below(r: ReqEntry): ReqEntry[] { - return this.subtree(r).slice(1); - } - - /** The declared statuses of the entries below that name the model (L4, L5, or a flat - * architectural policy with links), counted. A leaf counts itself. */ - rollup(r: ReqEntry): Rollup { - const linked = this.subtree(r).filter((x) => (x.level ?? 0) >= 4 || (x.level === undefined && (x.row?.implementedBy.length ?? 0) > 0)); - const counted = linked.length > 0 ? linked : [r]; - const c: Rollup = {}; - for (const x of counted) if (x.status !== "") c[x.status] = (c[x.status] ?? 0) + 1; - return c; - } - - /** The model nodes the subtree claims (owners, deduplicated, sorted). */ - targetsOf(r: ReqEntry): string[] { - const set = new Set(); - for (const x of this.subtree(r)) { - for (const l of x.row?.implementedBy ?? []) if (l.target !== undefined && this.byId.has(l.target)) set.add(this.ownerOf(l.target)); - } - return [...set].sort(byCodeUnit); - } - - /** The ledger's gate verdict for a requirement: "error" | "warn" | "clean" | "". */ - verdict(r: ReqEntry): string { - return r.row?.verdict ?? ""; - } - - /** The L1 feature (functional top) with the most claims on a node, by document order on a tie. */ - featureOf(id: string): ReqEntry | undefined { - const count = new Map(); - for (const c of this.claims(id)) { - let top = c.req; - while (top.parent !== undefined) top = top.parent; - if (top.kind !== REQUIREMENT_SUBTYPE_FUNCTIONAL) continue; - count.set(top, (count.get(top) ?? 0) + 1); - } - let best: ReqEntry | undefined; - for (const t of this.features()) { - const n = count.get(t) ?? 0; - if (n > 0 && (best === undefined || n > (count.get(best) ?? 0))) best = t; - } - return best; - } - - features(): ReqEntry[] { - return this.topRequirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL); - } - - qualities(): ReqEntry[] { - return this.topRequirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_ARCHITECTURAL); - } - - /** The best declared status among a node's claims, or "unclaimed". */ - claimStatus(id: string): string { - const cl = this.claims(id); - if (cl.length === 0) return "unclaimed"; - for (const s of STATUS_ORDER) if (cl.some((c) => c.req.status === s)) return s; - return "unclaimed"; - } - - /** Model edges between two top-level nodes (a member's edge is drawn from its owner). */ - modelEdges(): ExplorerEdge[] { - const out: ExplorerEdge[] = []; - const seen = new Set(); - for (const e of this.doc.edges) { - if (!MODEL_EDGE_KINDS.includes(e.kind)) continue; - const from = this.ownerOf(e.from); - const to = this.ownerOf(e.to); - if (from === to) continue; - const a = this.byId.get(from); - const b = this.byId.get(to); - if (a === undefined || b === undefined) continue; - if (a.type === TYPE_REQUIREMENT || b.type === TYPE_REQUIREMENT) continue; - const key = `${e.kind}\u0000${from}\u0000${to}`; - if (seen.has(key)) continue; - seen.add(key); - out.push({ kind: e.kind, from, to, ...(e.via !== undefined ? { via: e.via } : {}) }); - } - return out; - } - - slice(id: string): ExplorerSlice | undefined { - return this.doc.slices.find((s) => s.id === id); - } -} diff --git a/server/typescript/packages/docs-site/src/explorer/pages.ts b/server/typescript/packages/docs-site/src/explorer/pages.ts index 9b8fd055b2..812c696a99 100644 --- a/server/typescript/packages/docs-site/src/explorer/pages.ts +++ b/server/typescript/packages/docs-site/src/explorer/pages.ts @@ -3,8 +3,9 @@ // template renders; every string in it is already HTML-escaped, because the renderer's text // format does not escape. // -// Every fact a page states is read off the ExplorerIndex, which reads only `explorer.json`. The -// pages add presentation (grouping, ordering, wording) and the explorer checks the gaps page +// Every fact a page states is read off the ViewIndex, which reads only the docs view +// (`buildDocsView`, `docs/features/docs-view.md`): ids, pages, links, inheritance, references +// and claims are the view's, built from the loaded model. The pages add presentation (grouping, ordering, wording) and the explorer checks the gaps page // labels as such; they never recompute what the loader or the gate decided. import { @@ -18,7 +19,6 @@ import { FIELD_ATTR_VALUES, FIELD_SUBTYPE_ENUM, IDENTITY_ATTR_FIELDS, - PACKAGE_SEPARATOR, IDENTITY_REFERENCE_ATTR_REFERENCES, OBJECT_REPORT_ATTR_DIMENSIONS, OBJECT_REPORT_ATTR_FILTER, @@ -54,7 +54,6 @@ import { TEMPLATE_ATTR_TEXT_REF, DOC_ATTR_DESCRIPTION, DOC_ATTR_SUMMARY, - DOC_ATTR_TITLE, TYPE_DIMENSION, TYPE_FIELD, TYPE_IDENTITY, @@ -83,9 +82,9 @@ import { REQUIREMENT_SUBTYPE_ARCHITECTURAL, REQUIREMENT_SUBTYPE_FUNCTIONAL, } from "@metaobjectsdev/metadata"; -import type { ExplorerIndex, ReqEntry } from "./index-model.js"; -import { STATUSES } from "./index-model.js"; -import type { ExplorerNode } from "./types.js"; +import type { DocsViewAttrValue, DocsViewLink } from "@metaobjectsdev/metadata"; +import type { PageNode, ReqEntry, ViewIndex } from "./view-index.js"; +import { STATUSES } from "./view-index.js"; import { dispositionPill, esc, @@ -111,17 +110,21 @@ export const PAGE_API = "api.html"; export const PAGE_GAPS = "gaps.html"; export const PAGE_MODEL = "model/index.html"; -/** The member types a page gives an anchor, so an L5 link can land on its row. */ -const ANCHORED_TYPES = new Set([TYPE_FIELD, TYPE_IDENTITY, TYPE_INDEX, TYPE_RELATIONSHIP, TYPE_DIMENSION, TYPE_MEASURE, TYPE_SEGMENT]); - -/** A member row's anchor: `m-` for a field, `m--` for anything else, since - * siblings of different types may share a name. */ -const memberAnchor = (n: ExplorerNode): string => (n.type === TYPE_FIELD ? `m-${n.name}` : `m-${n.type}-${n.name}`); +/** The member types the object page gives a row (and so the row carries the member's anchor). + * Every other direct member gets an empty anchor element, so a link the view states lands. */ +const ROWED_TYPES = new Set([TYPE_FIELD, TYPE_IDENTITY, TYPE_INDEX, TYPE_RELATIONSHIP, TYPE_DIMENSION, TYPE_MEASURE, TYPE_SEGMENT]); /** The gate codes that report the level and nesting rules (the proof table's "Level rules"). */ const LEVEL_RULE_CODES = new Set(["ERR_REQUIREMENT_BAD_LEVEL", "ERR_REQUIREMENT_LEVEL_NESTING", "ERR_REQUIREMENT_LINK_ABOVE_FLOOR"]); const CODE_OBJECT_UNCLAIMED = "WARN_REQUIREMENT_OBJECT_UNCLAIMED"; +/** A requirement's `@implementedBy` link as the pages read it: the target's id when it resolves. */ +interface ImplLink { + ref: string; + resolves: boolean; + target?: string; +} + const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0); const str = (v: unknown): string | undefined => (typeof v === "string" ? v : undefined); const strs = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : typeof v === "string" ? [v] : []); @@ -132,11 +135,6 @@ function pkgDir(pkg: string): string { return pkg === "" ? "-root" : pkg.split("::").join("/"); } -/** A page's file stem: the name, unless it would take the package page's `index.html` (on a - * case-insensitive file system too). */ -function pageStem(name: string): string { - return name.toLowerCase() === "index" ? `${name}.node` : name; -} /** A short form of an id for display: the part after the package. */ export function localName(id: string): string { @@ -145,16 +143,13 @@ export function localName(id: string): string { } export class Pages { - constructor(readonly ix: ExplorerIndex) {} + constructor(readonly ix: ViewIndex) {} // ─── Addresses ─────────────────────────────────────────────────────────────── - /** A top-level node's page. A node whose id is qualified by its type (another type holds - * the plain id) carries the type in its file name too, so the two never share a page. */ - objectPage(n: ExplorerNode): string { - const qualifier = `[${n.type}.${n.subType}]`; - const typed = n.parent === undefined && n.id.endsWith(qualifier) ? `.${n.type}-${n.subType}` : ""; - return `model/${pkgDir(n.package)}/${pageStem(n.name)}${typed}.html`; + /** A top-level node's page, as the view states it. */ + objectPage(n: PageNode): string { + return n.path; } packagePage(pkg: string): string { @@ -162,43 +157,62 @@ export class Pages { } reqPage(r: ReqEntry): string { - return `requirements/${pkgDir(r.node.package)}/${pageStem(this.reqPath(r))}.html`; + return r.req.path; } /** The requirement's dotted path, as every `verify` diagnostic prints it. */ reqPath(r: ReqEntry): string { - if (r.row !== undefined) return r.row.path; - const prefix = r.node.package === "" ? "" : `${r.node.package}::`; - return r.node.id.startsWith(prefix) ? r.node.id.slice(prefix.length) : r.node.id; + return r.req.address; } reqLabel(r: ReqEntry): string { - return str(r.node.attrs[DOC_ATTR_TITLE]) ?? r.node.name; + return r.req.label; } - /** Where a node id lands: its own page, or its owner's page at the member's row. */ + /** Where a node id lands, as the view states it: its own page, or its owner's page at the + * member's anchor. */ pageOf(id: string): string | undefined { - const req = this.ix.reqById.get(id); - if (req !== undefined) return this.reqPage(req); - const ownerId = this.ix.ownerOf(id); - const owner = this.ix.byId.get(ownerId); - if (owner === undefined || owner.type === TYPE_REQUIREMENT) return undefined; - const page = this.objectPage(owner); - if (ownerId === id) return page; - const member = this.memberOf(ownerId, id); - if (member === undefined) return page; - // A generic page lists every member, so each one has a row to land on. - return ANCHORED_TYPES.has(member.type) || this.ix.kindOf(owner) === "other" ? `${page}#${memberAnchor(member)}` : page; + const path = this.ix.byId.get(id)?.path; + return path === undefined || path === "" ? undefined : path; + } + + /** A requirement's `@implementedBy` links, each with the id it resolved to. */ + implLinks(r: ReqEntry): ImplLink[] { + return r.req.implementedBy.map((l) => ({ ref: l.ref, resolves: l.resolves, ...(l.resolves && this.ix.byId.has(l.target.id) ? { target: l.target.id } : {}) })); + } + + /** The values of one attribute of a node, each with the link the loader resolved. */ + attrValues(n: PageNode, name: string): DocsViewAttrValue[] { + return n.view.attrs.find((a) => a.name === name)?.values ?? []; + } + + /** The nodes one attribute of a node references, where the loader resolved them. */ + refLinks(n: PageNode, name: string): DocsViewLink[] { + return this.attrValues(n, name).flatMap((v) => (v.link !== null && !v.link.unresolved ? [v.link] : [])); + } + + /** Links to what one attribute of a node references, joined; "" when it names nothing. A + * value the loader did not resolve renders as the red "unresolved" chip. */ + refHtml(from: string, n: PageNode, name: string, label?: (text: string) => string): string { + return this.attrValues(n, name) + .filter((v) => v.link !== null) + .map((v) => this.viewLink(from, v.link!, label?.(v.text))) + .join(", "); } - /** The direct child of `ownerId` that `id` sits in (or is). */ - private memberOf(ownerId: string, id: string): ExplorerNode | undefined { - let cur = this.ix.byId.get(id); - while (cur !== undefined && cur.parent !== ownerId) cur = cur.parent !== undefined ? this.ix.byId.get(cur.parent) : undefined; - return cur; + /** A link the view states, relative to `from`. */ + viewLink(from: string, l: DocsViewLink, label?: string): string { + return l.unresolved ? `${esc(label ?? localName(l.label))} (unresolved)` : this.link(from, l.id, label); } - kindClass(n: ExplorerNode): string { + /** An empty element per direct member a page gives no row, so every link the view states + * lands. It rides in the crumbs, which every explorer template prints, so a template a + * project owns needs no change for it. */ + private memberAnchors(n: PageNode, rowed: ReadonlySet): string { + return this.ix.children(n.id).filter((c) => !rowed.has(c.type) && c.anchor !== "").map((c) => ``).join(""); + } + + kindClass(n: PageNode): string { return `k-${this.ix.kindOf(n)}`; } @@ -217,7 +231,7 @@ export class Pages { return `${esc(this.reqLabel(r))}`; } - description(n: ExplorerNode): string { + description(n: PageNode): string { return esc(str(n.attrs[DOC_ATTR_DESCRIPTION]) ?? str(n.attrs[DOC_ATTR_SUMMARY]) ?? ""); } @@ -238,40 +252,34 @@ export class Pages { const values = ix.objects.filter((o) => ix.kindOf(o) === "value").length; const projections = ix.objects.filter((o) => ix.kindOf(o) === "projection").length; const reports = ix.objects.filter((o) => ix.kindOf(o) === "report").length; - const counts = ix.doc.ledger?.counts ?? {}; - const num = (k: string): number | undefined => (typeof counts[k] === "number" ? (counts[k] as number) : undefined); - const features = ix.requirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL).length; - const qualities = ix.requirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_ARCHITECTURAL).length; + const vc = ix.view.counts; const tiles: { n: string; l: string; href: string }[] = []; tiles.push({ n: `${stored.length}`, l: `stored entities${abstract > 0 ? ` (${abstract} abstract base${abstract === 1 ? "" : "s"})` : ""}`, href: relHref(from, PAGE_MAP) }); tiles.push({ n: `${prompts.length}`, l: `declared prompt${prompts.length === 1 ? "" : "s"}, ${count(values, "payload or reply type", "payload and reply types")}`, href: relHref(from, PAGE_PROMPTS) }); if (ix.hasRequirements()) { - tiles.push({ n: `${num("total") ?? ix.requirements.length}`, l: `requirements: ${count(num("functional") ?? features, "feature")}, ${count(num("architectural") ?? qualities, "quality", "qualities")}`, href: relHref(from, PAGE_FEATURES) }); + tiles.push({ n: `${vc.requirements}`, l: `requirements: ${count(vc.functional, "feature")}, ${count(vc.architectural, "quality", "qualities")}`, href: relHref(from, PAGE_FEATURES) }); } else { tiles.push({ n: `${projections + reports}`, l: `read models: ${projections} projection${projections === 1 ? "" : "s"}, ${reports} report${reports === 1 ? "" : "s"}`, href: relHref(from, PAGE_MODEL) }); } - const claimed = num("entitiesClaimed"); - const claimTotal = num("entitiesTotal"); - if (claimed !== undefined && claimTotal !== undefined && claimTotal > 0) { - tiles.push({ n: `${claimed}/${claimTotal}`, l: "entities claimed by a requirement (gate)", href: relHref(from, PAGE_GAPS) }); + if (vc.coverageMeasured && vc.entitiesTotal > 0) { + tiles.push({ n: `${vc.entitiesClaimed}/${vc.entitiesTotal}`, l: "entities claimed by a requirement (gate)", href: relHref(from, PAGE_GAPS) }); } else { tiles.push({ n: `${ix.packages.length}`, l: `package${ix.packages.length === 1 ? "" : "s"} in the model`, href: relHref(from, PAGE_MODEL) }); } - if (ix.doc.api !== undefined) { + if (ix.view.sources.routes) { const routed = ix.objects.filter((o) => ix.routes(o.id).length > 0).length; tiles.push({ n: `${routed}`, l: "objects with mounted REST routes", href: relHref(from, PAGE_API) }); } else { tiles.push({ n: "—", l: "REST routes: none recorded by this run", href: relHref(from, PAGE_API) }); } - const genFiles = new Set((ix.doc.generated ?? []).flatMap((g) => g.files.map((f) => f.path))); tiles.push({ - n: ix.doc.generated !== undefined ? `${genFiles.size}` : "—", - l: ix.doc.generated !== undefined ? "generated files traced to a node" : "generated files: no manifest read", + n: ix.view.sources.files ? `${vc.files}` : "—", + l: ix.view.sources.files ? "generated files traced to a node" : "generated files: no manifest read", href: relHref(from, PAGE_TRACE), }); const sources = ["the effective model"]; - if (ix.doc.ledger !== undefined) sources.push("the requirement gate's ledger"); - if (ix.doc.generated !== undefined) sources.push("the generation manifest"); + if (ix.view.sources.requirements) sources.push("the requirement gate's ledger"); + if (ix.view.sources.files) sources.push("the generation manifest"); return { heading: esc(`What ${title} does`), sourcesLine: esc(joinAnd(sources)), @@ -343,7 +351,7 @@ export class Pages { // ─── S3: Object page (entity, value, projection, report) ───────────────────── - object(n: ExplorerNode): Record { + object(n: PageNode): Record { const ix = this.ix; const from = this.objectPage(n); const kind = ix.kindOf(n); @@ -357,14 +365,16 @@ export class Pages { const layouts = ix.children(n.id).filter((c) => c.type === TYPE_LAYOUT).map((l) => this.layoutRow(l)); const isUnclaimed = this.unclaimedEntity(n); const whyRows = this.whyRows(from, n); - const usedBy = ix.doc.edges.filter((e) => (e.kind === "payload" || e.kind === "reply") && e.to === n.id).map((e) => this.link(from, e.from)); - const refBy = [...new Set(ix.modelEdges().filter((e) => e.to === n.id && e.kind !== "payload" && e.kind !== "reply").map((e) => e.from))].sort(byCodeUnit).map((id) => this.link(from, id)); + const referrers = ix.top(n.id)?.referencedBy ?? []; + const isPromptRef = (attr: string): boolean => attr === TEMPLATE_ATTR_PAYLOAD_REF || attr === TEMPLATE_ATTR_RESPONSE_REF; + const usedBy = [...new Set(referrers.filter((e) => isPromptRef(e.attr)).map((e) => e.from.id))].sort(byCodeUnit).map((id) => this.link(from, id)); + const refBy = [...new Set(referrers.filter((e) => !isPromptRef(e.attr)).map((e) => e.from.id))].sort(byCodeUnit).map((id) => this.link(from, id)); const ext = n.extends !== undefined ? this.link(from, n.extends) : ""; return { id: esc(n.id), name: esc(n.name), kindLabel: esc(`object.${n.subType}`), - crumbsHtml: `Model › ${esc(n.package === "" ? "(no package)" : n.package)} › object.${esc(n.subType)}`, + crumbsHtml: `Model › ${esc(n.package === "" ? "(no package)" : n.package)} › object.${esc(n.subType)}${this.memberAnchors(n, ROWED_TYPES)}`, isAbstract: n.abstract === true, isUnclaimed, isReadOnly: storage?.kind === "view", @@ -390,12 +400,12 @@ export class Pages { report: kind === "report" ? this.reportBlock(from, n) : undefined, routes: ix.routes(n.id).map((r) => ({ method: esc(r.method), path: esc(r.path) })), hasRoutes: ix.routes(n.id).length > 0, - routesNote: ix.doc.api === undefined ? "This run recorded no routes." : "No generated routes are mounted for it.", + routesNote: !ix.view.sources.routes ? "This run recorded no routes." : "No generated routes are mounted for it.", usedByHtml: usedBy.join(", "), referencedByHtml: refBy.join(", "), generated: this.generatedGroups(n.id), hasGenerated: ix.generated(n.id).length > 0, - generatedNote: ix.doc.generated === undefined ? "No generation manifest was read." : "Nothing generated is traced to it.", + generatedNote: !ix.view.sources.files ? "No generation manifest was read." : "Nothing generated is traced to it.", claimCount: claims.length, }; } @@ -403,14 +413,13 @@ export class Pages { /** A concrete entity that no requirement claims, once any requirement claims anything. That * is the gate's object coverage (`WARN_REQUIREMENT_OBJECT_UNCLAIMED`), which only activates * when the project's requirements claim something. */ - unclaimedEntity(n: ExplorerNode): boolean { + unclaimedEntity(n: PageNode): boolean { const ix = this.ix; if (!ix.isEntity(n) || n.abstract === true) return false; - const diags = ix.doc.ledger?.diagnostics ?? []; - return diags.some((d) => isDiag(d) && d.code === CODE_OBJECT_UNCLAIMED && d.node === n.id); + return ix.top(n.id)?.unclaimed === true; } - private whyRows(from: string, n: ExplorerNode): Record[] { + private whyRows(from: string, n: PageNode): Record[] { const claims = [...this.ix.claims(n.id)].sort((a, b) => this.ix.requirements.indexOf(a.req) - this.ix.requirements.indexOf(b.req)); const rows: Record[] = []; let lastTop: ReqEntry | undefined; @@ -429,14 +438,14 @@ export class Pages { return rows; } - private whyEmpty(n: ExplorerNode): string { + private whyEmpty(n: PageNode): string { if (!this.ix.hasRequirements()) return `This model declares no requirements, so nothing states why ${esc(n.name)} exists.`; if (this.unclaimedEntity(n)) return `No requirement claims ${esc(n.name)}. The gate reports this as ${CODE_OBJECT_UNCLAIMED}.`; return `No requirement claims ${esc(n.name)}.`; } - private fieldRow(from: string, owner: ExplorerNode, f: ExplorerNode): { [k: string]: unknown; column: string } { - const ref = str(f.attrs[FIELD_ATTR_OBJECT_REF]); + private fieldRow(from: string, owner: PageNode, f: PageNode): { [k: string]: unknown; column: string } { + const ref = this.refHtml(from, f, FIELD_ATTR_OBJECT_REF); const values = f.subType === FIELD_SUBTYPE_ENUM ? strs(f.attrs[FIELD_ATTR_VALUES]) : []; const flags: string[] = []; if (f.attrs[FIELD_ATTR_REQUIRED] === true) flags.push("required"); @@ -447,11 +456,11 @@ export class Pages { if (this.ix.children(f.id).some((c) => c.type === TYPE_ORIGIN)) flags.push("derived"); const claims = this.ix.claims(owner.id).filter((c) => c.member !== undefined && c.member.split(".")[0] === f.name); return { - anchor: esc(memberAnchor(f)), + anchor: esc(f.anchor), name: esc(f.name), inheritedHtml: f.inheritedFrom !== undefined ? `inherited` : "", type: esc(`${f.subType}${f.isArray === true ? "[]" : ""}`), - refHtml: ref !== undefined ? ` → ${this.link(from, ref)}` : "", + refHtml: ref !== "" ? ` → ${ref}` : "", valuesHtml: values.length > 0 ? `
${values.map(esc).join(" | ")}
` : "", column: esc(str(f.attrs[FIELD_ATTR_COLUMN]) ?? ""), flagsHtml: flags.map((x) => `${esc(x)}`).join(""), @@ -459,29 +468,29 @@ export class Pages { }; } - private keyRow(from: string, c: ExplorerNode): Record { + private keyRow(from: string, c: PageNode): Record { const fields = strs(c.attrs[IDENTITY_ATTR_FIELDS]); - const target = str(c.attrs[IDENTITY_REFERENCE_ATTR_REFERENCES]) ?? str(c.attrs[RELATIONSHIP_ATTR_OBJECT_REF]); + const target = this.refHtml(from, c, IDENTITY_REFERENCE_ATTR_REFERENCES) || this.refHtml(from, c, RELATIONSHIP_ATTR_OBJECT_REF); const through = str(c.attrs[RELATIONSHIP_ATTR_THROUGH]); const card = str(c.attrs[RELATIONSHIP_ATTR_CARDINALITY]); const shape = c.type === TYPE_RELATIONSHIP ? [card, through !== undefined ? `through ${localName(through)}` : undefined].filter((x) => x !== undefined).join(", ") : `(${fields.join(", ")})`; return { - anchor: esc(memberAnchor(c)), + anchor: esc(c.anchor), kind: esc(`${c.type}.${c.subType}`), name: esc(c.name), inheritedHtml: c.inheritedFrom !== undefined ? `inherited` : "", shape: esc(shape), - targetHtml: target !== undefined ? `→ ${this.link(from, target)}` : "", + targetHtml: target !== "" ? `→ ${target}` : "", }; } - private reportingRow(from: string, c: ExplorerNode): Record { + private reportingRow(from: string, c: PageNode): Record { const a = c.attrs; const parts: string[] = []; const agg = str(a[REPORTING_ATTR_AGG]); - const of = strs(a[REPORTING_ATTR_OF]); - if (agg !== undefined) parts.push(`${esc(agg)}(${of.map((o) => this.link(from, o, localName(o))).join(", ")})`); - else if (of.length > 0) parts.push(`of ${of.map((o) => this.link(from, o, localName(o))).join(", ")}`); + const of = this.refHtml(from, c, REPORTING_ATTR_OF, localName); + if (agg !== undefined) parts.push(`${esc(agg)}(${of})`); + else if (of !== "") parts.push(`of ${of}`); const num = str(a[REPORTING_ATTR_NUMERATOR]); const den = str(a[REPORTING_ATTR_DENOMINATOR]); if (num !== undefined && den !== undefined) parts.push(`${esc(num)} ÷ ${esc(den)}`); @@ -493,10 +502,10 @@ export class Pages { if (seg !== undefined) parts.push(`segment ${esc(seg)}`); if (a[REPORTING_ATTR_FILTER] !== undefined) parts.push(`filter ${esc(fmt(a[REPORTING_ATTR_FILTER]))}`); if (a[REPORTING_ATTR_DEFAULT] !== undefined) parts.push(`default ${esc(fmt(a[REPORTING_ATTR_DEFAULT]))}`); - return { anchor: esc(memberAnchor(c)), kind: esc(`${c.type}.${c.subType}`), name: esc(c.name), definitionHtml: parts.join(" · ") }; + return { anchor: esc(c.anchor), kind: esc(`${c.type}.${c.subType}`), name: esc(c.name), definitionHtml: parts.join(" · ") }; } - private layoutRow(l: ExplorerNode): Record { + private layoutRow(l: PageNode): Record { const parts: string[] = []; const cols = strs(l.attrs[LAYOUT_DATA_GRID_ATTR_COLUMNS]); if (cols.length > 0) parts.push(`columns ${cols.map((c) => `${esc(c)}`).join(", ")}`); @@ -506,7 +515,7 @@ export class Pages { return { kind: esc(`${l.type}.${l.subType}`), name: esc(l.name), detailHtml: parts.join(", ") }; } - private projectionBlock(from: string, n: ExplorerNode): Record { + private projectionBlock(from: string, n: PageNode): Record { const ix = this.ix; const rows: Record[] = []; const bases = new Set(); @@ -514,8 +523,7 @@ export class Pages { if (f.extends !== undefined) bases.add(ix.ownerOf(f.extends)); for (const o of ix.children(f.id).filter((c) => c.type === TYPE_ORIGIN)) { const def = this.originDefinition(from, o); - const src = str(o.attrs[ORIGIN_PASSTHROUGH_ATTR_FROM]); - if (src !== undefined && ix.byId.has(src)) bases.add(ix.ownerOf(src)); + for (const src of this.refLinks(o, ORIGIN_PASSTHROUGH_ATTR_FROM)) bases.add(ix.ownerOf(src.id)); rows.push({ field: esc(f.name), origin: esc(`origin.${o.subType}`), definitionHtml: def }); } } @@ -526,26 +534,27 @@ export class Pages { }; } - private originDefinition(from: string, o: ExplorerNode): string { + private originDefinition(from: string, o: PageNode): string { const a = o.attrs; - const ref = (v: unknown): string => { - const s = str(v); - return s === undefined ? "" : this.ix.byId.has(s) ? this.link(from, s, localName(s)) : `${esc(localName(s))}`; - }; + // A value the loader resolved links to its node; any other is shown as written. + const ref = (name: string): string => + this.attrValues(o, name) + .map((v) => (v.link !== null && !v.link.unresolved ? this.link(from, v.link.id, localName(v.text)) : `${esc(localName(v.text))}`)) + .join(", "); const parts: string[] = []; const agg = str(a[ORIGIN_AGGREGATE_ATTR_AGG]); - if (agg !== undefined) parts.push(`${esc(agg)}(${ref(a[ORIGIN_AGGREGATE_ATTR_OF])})`); - else if (a[ORIGIN_AGGREGATE_ATTR_OF] !== undefined) parts.push(`of ${ref(a[ORIGIN_AGGREGATE_ATTR_OF])}`); - if (a[ORIGIN_PASSTHROUGH_ATTR_FROM] !== undefined) parts.push(`from ${ref(a[ORIGIN_PASSTHROUGH_ATTR_FROM])}`); + if (agg !== undefined) parts.push(`${esc(agg)}(${ref(ORIGIN_AGGREGATE_ATTR_OF)})`); + else if (a[ORIGIN_AGGREGATE_ATTR_OF] !== undefined) parts.push(`of ${ref(ORIGIN_AGGREGATE_ATTR_OF)}`); + if (a[ORIGIN_PASSTHROUGH_ATTR_FROM] !== undefined) parts.push(`from ${ref(ORIGIN_PASSTHROUGH_ATTR_FROM)}`); if (a[ORIGIN_AGGREGATE_ATTR_VIA] !== undefined) parts.push(`via ${esc(localName(String(a[ORIGIN_AGGREGATE_ATTR_VIA])))}`); if (a[ORIGIN_COMPUTED_ATTR_EXPR] !== undefined) parts.push(`${esc(fmt(a[ORIGIN_COMPUTED_ATTR_EXPR]))}`); if (a[ORIGIN_AGGREGATE_ATTR_FILTER] !== undefined) parts.push(`filter ${esc(fmt(a[ORIGIN_AGGREGATE_ATTR_FILTER]))}`); return parts.join(" · "); } - private reportBlock(from: string, n: ExplorerNode): Record { + private reportBlock(from: string, n: PageNode): Record { const a = n.attrs; - const fromId = str(a[OBJECT_REPORT_ATTR_FROM]); + const fromId = this.refLinks(n, OBJECT_REPORT_ATTR_FROM)[0]?.id ?? str(a[OBJECT_REPORT_ATTR_FROM]); const resolve = (name: string, kindType: string): string => { const candidates = [fromId !== undefined ? `${fromId}.${name}` : undefined, `${n.package === "" ? "" : `${n.package}::`}${name}`].filter((x): x is string => x !== undefined); const hit = candidates.find((c) => this.ix.byId.get(c)?.type === kindType || (this.ix.byId.has(c) && name.includes("."))); @@ -553,7 +562,7 @@ export class Pages { }; const spine = str(a[OBJECT_REPORT_ATTR_SPINE]); return { - fromHtml: fromId !== undefined ? this.link(from, fromId) : "", + fromHtml: this.refHtml(from, n, OBJECT_REPORT_ATTR_FROM), spineHtml: spine !== undefined ? `${esc(spine)}` : "", dimensionsHtml: strs(a[OBJECT_REPORT_ATTR_DIMENSIONS]).map((d) => resolve(d, TYPE_DIMENSION)).join(", "), measuresHtml: strs(a[OBJECT_REPORT_ATTR_MEASURES]).map((m) => resolve(m, TYPE_MEASURE)).join(", "), @@ -573,13 +582,16 @@ export class Pages { /** The page of a top-level node the explorer has no specific screen for: what the model * states about it (attributes, members), why it exists, what points at it, what was * generated from it. Every value comes off the node; nothing is interpreted. */ - node(n: ExplorerNode): Record { + node(n: PageNode): Record { const ix = this.ix; const from = this.objectPage(n); const kindLabel = `${n.type}.${n.subType}`; const whyRows = this.whyRows(from, n); const attrs = this.attrRows(from, n); - const refBy = [...new Set(ix.doc.edges.filter((e) => e.to === n.id || ix.ownerOf(e.to) === n.id).map((e) => ix.ownerOf(e.from)).filter((id) => id !== n.id))] + // What points at it: every node referencing it or a member of it, and every requirement + // (by its top-level requirement) that claims it. + const referrers = [...(ix.top(n.id)?.referencedBy ?? []).map((e) => e.from.id), ...ix.claims(n.id).map((c) => this.topOf(c.req).node.id)]; + const refBy = [...new Set(referrers.filter((id) => id !== n.id))] .sort(byCodeUnit) .map((id) => this.link(from, id)); return { @@ -593,7 +605,7 @@ export class Pages { attrs, hasAttrs: attrs.length > 0, members: ix.children(n.id).map((c) => ({ - anchor: esc(memberAnchor(c)), + anchor: esc(c.anchor), kind: esc(`${c.type}.${c.subType}`), nameHtml: ix.reqById.has(c.id) ? this.link(from, c.id) : esc(c.name === "" ? `#${c.order}` : c.name), attrsHtml: this.attrRows(from, c).map((a) => `@${a.name} ${a.valueHtml}`).join("
"), @@ -606,29 +618,29 @@ export class Pages { referencedByHtml: refBy.join(", "), generated: this.generatedGroups(n.id), hasGenerated: ix.generated(n.id).length > 0, - generatedNote: ix.doc.generated === undefined ? "No generation manifest was read." : "Nothing generated is traced to it.", + generatedNote: !ix.view.sources.files ? "No generation manifest was read." : "Nothing generated is traced to it.", }; } - /** A node's attributes, sorted, each value linked when it names a node. */ - private attrRows(from: string, n: ExplorerNode): { name: string; valueHtml: string }[] { - return Object.keys(n.attrs) - .sort(byCodeUnit) - .map((k) => { - const v = n.attrs[k]; - const target = typeof v === "string" ? (v.startsWith(PACKAGE_SEPARATOR) ? v.slice(PACKAGE_SEPARATOR.length) : v) : undefined; - const linked = target !== undefined && this.ix.byId.has(target) && this.pageOf(target) !== undefined; - return { name: esc(k), valueHtml: linked ? this.link(from, target) : `${esc(fmt(v))}` }; - }); + /** A node's attributes, as the view orders them, each value linked where the loader resolved + * it as a reference. */ + private attrRows(from: string, n: PageNode): { name: string; valueHtml: string }[] { + return n.view.attrs.map((a) => { + const links = a.values.filter((v) => v.link !== null && !v.link.unresolved); + return { + name: esc(a.name), + valueHtml: links.length > 0 && links.length === a.values.length ? links.map((v) => this.link(from, v.link!.id)).join(", ") : `${esc(fmt(a.value))}`, + }; + }); } // ─── S4: Prompt (and other template) page ──────────────────────────────────── - prompt(n: ExplorerNode, text: string | undefined): Record { + prompt(n: PageNode, text: string | undefined): Record { const ix = this.ix; const from = this.objectPage(n); - const payloadId = str(n.attrs[TEMPLATE_ATTR_PAYLOAD_REF]); - const replyId = str(n.attrs[TEMPLATE_ATTR_RESPONSE_REF]); + const payloadId = this.refLinks(n, TEMPLATE_ATTR_PAYLOAD_REF)[0]?.id; + const replyId = this.refLinks(n, TEMPLATE_ATTR_RESPONSE_REF)[0]?.id; const vars = text !== undefined ? templateVariables(text) : undefined; const payload = payloadId !== undefined ? ix.byId.get(payloadId) : undefined; const reply = replyId !== undefined ? ix.byId.get(replyId) : undefined; @@ -636,7 +648,7 @@ export class Pages { name: esc(f.name), requiredHtml: f.attrs[FIELD_ATTR_REQUIRED] === true ? `required` : "", type: esc(`${f.subType}${f.isArray === true ? "[]" : ""}`), - refHtml: str(f.attrs[FIELD_ATTR_OBJECT_REF]) !== undefined ? ` → ${this.link(from, str(f.attrs[FIELD_ATTR_OBJECT_REF])!)}` : "", + refHtml: this.refHtml(from, f, FIELD_ATTR_OBJECT_REF) !== "" ? ` → ${this.refHtml(from, f, FIELD_ATTR_OBJECT_REF)}` : "", usedHtml: vars === undefined ? `text not read` : vars.has(f.name) ? "yes" : `no`, })) : []; const replyRows = reply !== undefined ? ix.fields(reply.id).map((f) => ({ @@ -655,7 +667,7 @@ export class Pages { return { name: esc(n.name), kindLabel: esc(`template.${n.subType}`), - crumbsHtml: `Prompts › ${esc(n.package === "" ? "(no package)" : n.package)} › template.${esc(n.subType)}`, + crumbsHtml: `Prompts › ${esc(n.package === "" ? "(no package)" : n.package)} › template.${esc(n.subType)}${this.memberAnchors(n, new Set())}`, isUnclaimed: ix.hasClaims() && claimed.length === 0, description: this.description(n), attrsHtml: attrs, @@ -671,7 +683,7 @@ export class Pages { hasText: text !== undefined, generated: this.generatedGroups(n.id), hasGenerated: ix.generated(n.id).length > 0, - generatedNote: ix.doc.generated === undefined ? "No generation manifest was read." : "Nothing generated is traced to it.", + generatedNote: !ix.view.sources.files ? "No generation manifest was read." : "Nothing generated is traced to it.", whyRows, hasWhy: whyRows.length > 0, whyEmptyHtml: ix.hasRequirements() ? `No requirement claims ${esc(n.name)}. The gate counts entity coverage only, so this shows here and on the gaps page, not in meta verify.` : `This model declares no requirements.`, @@ -683,15 +695,15 @@ export class Pages { prompts(): Record { const from = PAGE_PROMPTS; const rows = this.ix.templates.map((p) => { - const payload = str(p.attrs[TEMPLATE_ATTR_PAYLOAD_REF]); - const reply = str(p.attrs[TEMPLATE_ATTR_RESPONSE_REF]); + const payload = this.refHtml(from, p, TEMPLATE_ATTR_PAYLOAD_REF); + const reply = this.refHtml(from, p, TEMPLATE_ATTR_RESPONSE_REF); const claims = this.ix.claims(p.id); return { linkHtml: this.link(from, p.id), kind: esc(`template.${p.subType}`), description: this.description(p), - payloadHtml: payload !== undefined ? this.link(from, payload) : `none`, - replyHtml: reply !== undefined ? this.link(from, reply) : `none (outbound only)`, + payloadHtml: payload !== "" ? payload : `none`, + replyHtml: reply !== "" ? reply : `none (outbound only)`, claimsHtml: claims.length > 0 ? claims.map((c) => statusChip(c.req.status)).join("") : this.ix.hasClaims() ? `unclaimed` : `—`, }; }); @@ -716,8 +728,8 @@ export class Pages { } private treeNode(from: string, r: ReqEntry): string { - const links = (r.row?.implementedBy ?? []).map((l) => { - if (l.target !== undefined && this.ix.byId.has(l.target)) return `${this.link(from, l.target, l.ref)}`; + const links = this.implLinks(r).map((l) => { + if (l.target !== undefined) return `${this.link(from, l.target, l.ref)}`; return r.status === REQUIREMENT_STATUS_PLANNED ? `${esc(l.ref)} (not yet)` : `${esc(l.ref)} (dangling)`; @@ -735,8 +747,9 @@ export class Pages { const chain: ReqEntry[] = []; for (let x: ReqEntry | undefined = r; x !== undefined; x = x.parent) chain.unshift(x); const tab = r.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL ? { href: PAGE_FEATURES, label: "Features" } : { href: PAGE_QUALITIES, label: "Qualities" }; - const row = r.row; - const links = row?.implementedBy ?? []; + const inLedger = r.req.inLedger; + const diagnostics = r.req.diagnostics; + const links = this.implLinks(r); const linkRows = links.map((l) => { const target = l.target !== undefined ? ix.byId.get(l.target) : undefined; return { @@ -749,9 +762,9 @@ export class Pages { : `dangling`, }; }); - const findings = (row?.diagnostics ?? []).filter((d) => d.source === GATE_SOURCE); - const advisories = (row?.diagnostics ?? []).filter((d) => d.source !== GATE_SOURCE); - const levelFinding = row?.diagnostics.some((d) => LEVEL_RULE_CODES.has(d.code)) ?? false; + const findings = diagnostics.filter((d) => d.source === GATE_SOURCE); + const advisories = diagnostics.filter((d) => d.source !== GATE_SOURCE); + const levelFinding = diagnostics.some((d) => LEVEL_RULE_CODES.has(d.code)); const testable = r.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL && (r.level ?? 0) >= REQUIREMENT_LEVEL_OBJECT; const linksOk = links.length === 0 ? "none" : links.every((l) => l.resolves) ? "yes" : "no"; const below = ix.below(r); @@ -767,7 +780,7 @@ export class Pages { statusHtml: statusChip(r.status), dispositionHtml: dispositionPill(r), verdictHtml: verdictBadge(r), - address: esc(`${row?.qualifiedPath ?? r.node.id} · requirement.${r.kind}`), + address: esc(`${r.req.qualifiedPath} · requirement.${r.kind}`), statement: esc(str(r.node.attrs[REQUIREMENT_ATTR_STATEMENT]) ?? ""), counterexample: esc(str(r.node.attrs[REQUIREMENT_ATTR_COUNTEREXAMPLE]) ?? ""), description: desc, @@ -793,15 +806,15 @@ export class Pages { { what: "Level rules", verdictHtml: levelFinding ? `no` : `yes`, how: "Nesting agrees with level, and links sit only at L4 and L5." }, { what: "Gate findings", - verdictHtml: findings.length > 0 ? `${findings.length}` : row !== undefined ? `none` : `not read`, - how: findings.length > 0 ? findings.map((d) => `${esc(d.code)} ${esc(d.message)}`).join("
") : row !== undefined ? "Nothing reported for this entry." : "This build read no meta verify output.", + verdictHtml: findings.length > 0 ? `${findings.length}` : inLedger ? `none` : `not read`, + how: findings.length > 0 ? findings.map((d) => `${esc(d.code)} ${esc(d.message)}`).join("
") : inLedger ? "Nothing reported for this entry." : "This build read no meta verify output.", }, { what: "Authoring advisories", - verdictHtml: row !== undefined ? `${advisories.length}` : `not read`, + verdictHtml: inLedger ? `${advisories.length}` : `not read`, how: advisories.length > 0 ? advisories.map((d) => `${esc(d.code)} ${esc(d.message)}`).join("
") - : row !== undefined ? "None. The authoring lint never fails a build." : "This build read no meta verify output.", + : inLedger ? "None. The authoring lint never fails a build." : "This build read no meta verify output.", }, { what: "Test exists", @@ -814,7 +827,7 @@ export class Pages { { what: "Status is true", verdictHtml: `unprovable`, how: "No gate can prove the status. The colour is the author's claim, held to referential integrity." }, ].map((p) => ({ what: esc(p.what), verdictHtml: p.verdictHtml, howHtml: p.how })), trackedHtml: tracked.map((t) => `${esc(t)}`).join(" "), - digest: esc(row?.digest ?? ""), + digest: esc(r.req.digest), }; } @@ -825,7 +838,7 @@ export class Pages { const from = PAGE_MATRIX; // Stored entities and prompts, plus anything else a row claims (an abstract base a policy // names), so no claim lands outside the grid. - const claimed = ix.requirements.flatMap((r) => (r.row?.implementedBy ?? []).flatMap((l) => (l.target !== undefined ? [ix.ownerOf(l.target)] : []))); + const claimed = ix.requirements.flatMap((r) => this.implLinks(r).flatMap((l) => (l.target !== undefined ? [ix.ownerOf(l.target)] : []))); const colSet = new Set([...ix.storedEntities(), ...ix.templates.filter((t) => ix.isPrompt(t))].map((n) => n.id)); for (const id of claimed) if (ix.byId.get(id)?.parent === undefined && ix.byId.get(id)?.type !== TYPE_REQUIREMENT) colSet.add(id); const cols = [...colSet].map((id) => ix.byId.get(id)!).sort( @@ -834,11 +847,11 @@ export class Pages { const head = `${cols.map((o) => `
${this.link(from, o.id)}
`).join("")}`; const rows: string[] = []; for (const top of ix.topRequirements) { - const leaves = ix.subtree(top).filter((x) => (x.row?.implementedBy.length ?? 0) > 0); + const leaves = ix.subtree(top).filter((x) => x.req.implementedBy.length > 0); if (leaves.length === 0) continue; rows.push(`${top.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL ? "Feature" : "Quality"}: ${this.reqLink(from, top)}${cols.map(() => ``).join("")}`); for (const r of leaves) { - const tg = new Set((r.row?.implementedBy ?? []).filter((l) => l.target !== undefined).map((l) => ix.ownerOf(l.target!))); + const tg = new Set(this.implLinks(r).filter((l) => l.target !== undefined).map((l) => ix.ownerOf(l.target!))); const label = this.reqPath(r).split(".").slice(1).join(".") || this.reqLabel(r); rows.push( `${levelBadge(r)}${esc(label)}${cols @@ -871,12 +884,12 @@ export class Pages { const card = (title: string, count: number | string, source: string, why: string, bodyHtml: string): void => { cards.push({ title: esc(title), count: esc(String(count)), source: esc(source), isGate: source === "meta verify", whyHtml: why, bodyHtml }); }; - if (ix.doc.ledger !== undefined) { + if (ix.view.sources.requirements) { // Each requirement's own findings come from its ledger row, which the gate scoped to that // node; the flat list contributes only the findings with no requirement subject. const findingsOf = (gate: boolean): { req?: ReqEntry; d: { code: string; severity: string; message: string } }[] => [ - ...ix.requirements.flatMap((req) => (req.row?.diagnostics ?? []).filter((d) => (d.source === GATE_SOURCE) === gate).map((d) => ({ req, d }))), - ...(ix.doc.ledger?.diagnostics ?? []).filter((d): d is Diag => isDiag(d) && d.path === "" && (d.source === GATE_SOURCE) === gate).map((d) => ({ d })), + ...ix.requirements.flatMap((req) => req.req.diagnostics.filter((d) => (d.source === GATE_SOURCE) === gate).map((d) => ({ req, d }))), + ...ix.view.advisories.filter((d) => d.path === "" && (d.source === GATE_SOURCE) === gate).map((d) => ({ d })), ]; const table = (rows: ReturnType, chip: (severity: string) => string): string => rows.length === 0 @@ -890,8 +903,7 @@ export class Pages { card("Entities no requirement claims", unclaimed.length, "meta verify", "The gate's coverage warning. Each is a capability nobody has written down.", unclaimed.length > 0 ? unclaimed.map((e) => this.link(from, e.id)).join(", ") : `
None.
`); const outstanding = (r: ReqEntry): boolean => (REQUIREMENT_STATUSES_WITH_OUTSTANDING_WORK as readonly string[]).includes(r.status); const undecided = ix.requirements.filter((r) => outstanding(r) && r.node.attrs[REQUIREMENT_ATTR_DISPOSITION] === undefined && !ix.below(r).some(outstanding)); - const counted = ix.doc.ledger.counts["undecided"]; - card("Undecided gaps", typeof counted === "number" ? counted : "—", "meta verify", "A partial or planned entry with no @disposition and no outstanding work below it: a gap nobody has ruled on. A roll-up parent is left out, since a ruling on it settles nothing. The gate counts these.", list(undecided.map((r) => `${levelBadge(r)}${this.reqLink(from, r)} ${statusChip(r.status)}`))); + card("Undecided gaps", ix.view.counts.undecided, "meta verify", "A partial or planned entry with no @disposition and no outstanding work below it: a gap nobody has ruled on. A roll-up parent is left out, since a ruling on it settles nothing. The gate counts these.", list(undecided.map((r) => `${levelBadge(r)}${this.reqLink(from, r)} ${statusChip(r.status)}`))); } if (ix.hasRequirements()) { const behind = ix.requirements.filter((r) => r.status === REQUIREMENT_STATUS_PLANNED && ix.below(r).some((x) => x.status === REQUIREMENT_STATUS_LIVE)); @@ -915,12 +927,12 @@ export class Pages { /** Set by the site builder: prompt id → text, for the gaps page's payload check. */ texts = new Map(); - private unusedPayload(): { p: ExplorerNode; f: ExplorerNode }[] | undefined { - const out: { p: ExplorerNode; f: ExplorerNode }[] = []; + private unusedPayload(): { p: PageNode; f: PageNode }[] | undefined { + const out: { p: PageNode; f: PageNode }[] = []; let read = false; for (const p of this.ix.templates) { const text = this.texts.get(p.id); - const payload = str(p.attrs[TEMPLATE_ATTR_PAYLOAD_REF]); + const payload = this.refLinks(p, TEMPLATE_ATTR_PAYLOAD_REF)[0]?.id; if (text === undefined || payload === undefined) continue; read = true; const vars = templateVariables(text); @@ -944,7 +956,7 @@ export class Pages { return { groups, hasGroups: groups.length > 0, - recorded: ix.doc.api !== undefined, + recorded: ix.view.sources.routes, summary: esc(`${total} route${total === 1 ? "" : "s"} on ${groups.length} object${groups.length === 1 ? "" : "s"}`), }; } @@ -977,22 +989,6 @@ export class Pages { // ─── Small helpers ─────────────────────────────────────────────────────────────────────────── -interface Diag { - code: string; - path: string; - severity: string; - source?: string; - /** The entity an object-coverage finding is about; "" or absent otherwise. */ - node?: string; - message: string; -} - -function isDiag(d: unknown): d is Diag { - if (typeof d !== "object" || d === null) return false; - const r = d as Record; - return typeof r["code"] === "string" && typeof r["path"] === "string" && typeof r["message"] === "string" && typeof r["severity"] === "string"; -} - function list(items: string[]): string { return items.length === 0 ? `
None.
` : `
    ${items.map((i) => `
  • ${i}
  • `).join("")}
`; } diff --git a/server/typescript/packages/docs-site/src/explorer/site.ts b/server/typescript/packages/docs-site/src/explorer/site.ts index e3530c9059..e6c2d016f3 100644 --- a/server/typescript/packages/docs-site/src/explorer/site.ts +++ b/server/typescript/packages/docs-site/src/explorer/site.ts @@ -1,6 +1,7 @@ // generateExplorerSite(): the model explorer as a static site (design report §3.3, phase P1). // -// It reads one `explorer.json` (and, for the prompt pages, the prompt texts), renders a page per +// It reads one docs view (`buildDocsView` in `@metaobjectsdev/metadata`, and, for the prompt +// pages, the prompt texts), renders a page per // screen through the bundled Mustache templates, and writes: // // index.html S1 what the project does @@ -15,7 +16,7 @@ // matrix.html, trace.html, gaps.html, api.html, prompts.html, model/index.html, model//index.html // assets/explorer.css, assets/explorer.js the theme (`meta eject docs-site` copies them) // assets/explorer-data.js the graph and the search index the scripts read -// explorer.json the data spine itself, byte for byte +// explorer.json the docs view itself, byte for byte // // The output depends on its inputs alone (no clock, no random layout seed in the files), so the // site can sit under `meta verify --codegen`. Search works offline from explorer-data.js; when the @@ -26,12 +27,11 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, isAbsolute, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { render, InMemoryProvider } from "@metaobjectsdev/render"; -import { REQUIREMENT_ATTR_STATEMENT, REQUIREMENT_SUBTYPE_ARCHITECTURAL, REQUIREMENT_SUBTYPE_FUNCTIONAL } from "@metaobjectsdev/metadata"; -import { TEMPLATE_ATTR_TEXT_REF, TYPE_REQUIREMENT, DOC_ATTR_DESCRIPTION, OBJECT_SUBTYPE_REPORT, OBJECT_REPORT_ATTR_FROM } from "@metaobjectsdev/metadata/constants"; +import { REQUIREMENT_SUBTYPE_ARCHITECTURAL, REQUIREMENT_SUBTYPE_FUNCTIONAL, serializeDocsView, type DocsView } from "@metaobjectsdev/metadata"; +import { TEMPLATE_ATTR_TEXT_REF, TYPE_REQUIREMENT, DOC_ATTR_DESCRIPTION } from "@metaobjectsdev/metadata/constants"; import { checkLinks } from "../link-check.js"; import { EXPLORER_ASSET_NAMES, EXPLORER_TEMPLATE_NAMES } from "../scaffold.js"; -import { ExplorerIndex } from "./index-model.js"; -import { serializeExplorer } from "./build.js"; +import { ViewIndex } from "./view-index.js"; import { esc, legendHtml, relHref } from "./html.js"; import { PAGE_API, @@ -46,7 +46,6 @@ import { PAGE_TRACE, Pages, } from "./pages.js"; -import type { ExplorerJson } from "./types.js"; export { EXPLORER_ASSET_NAMES, EXPLORER_TEMPLATE_NAMES }; @@ -56,7 +55,8 @@ export const CYTOSCAPE_PATH = "cytoscape@3.30.2/dist/cytoscape.min.js"; const DEFAULT_ASSET_BASE = "https://cdn.jsdelivr.net/npm"; export interface ExplorerSiteOptions { - explorer: ExplorerJson; + /** The docs view of the model (`buildDocsView`). */ + view: DocsView; outDir: string; /** The project's name, as the header and the home page print it. */ title: string; @@ -108,11 +108,11 @@ const NAV: readonly NavItem[] = [ ]; /** Read each prompt's `.mustache` text from the directories the model's `@textRef` resolves in. */ -export function readPromptTexts(explorer: ExplorerJson, dirs: readonly string[]): Map { +export function readPromptTexts(view: DocsView, dirs: readonly string[]): Map { const out = new Map(); - for (const n of explorer.nodes) { - const ref = n.attrs[TEMPLATE_ATTR_TEXT_REF]; - if (n.parent !== undefined || typeof ref !== "string") continue; + for (const n of view.nodes) { + const ref = n.attrs.find((a) => a.name === TEMPLATE_ATTR_TEXT_REF)?.value; + if (typeof ref !== "string") continue; // A ref names a file below one of the directories: an absolute ref, or one that climbs out // with `..`, is not read, so a model cannot pull an arbitrary file into a published page. const segments = ref.split(/[\\/]/); @@ -129,7 +129,7 @@ export function readPromptTexts(explorer: ExplorerJson, dirs: readonly string[]) } export function generateExplorerSite(opts: ExplorerSiteOptions): ExplorerSiteResult { - const ix = new ExplorerIndex(opts.explorer); + const ix = new ViewIndex(opts.view); const pagesModel = new Pages(ix); for (const [id, text] of opts.texts ?? []) pagesModel.texts.set(id, text); // The one partial: the requirement card S1 repeats (`{{> card}}`). @@ -201,7 +201,7 @@ export function generateExplorerSite(opts: ExplorerSiteOptions): ExplorerSiteRes for (const a of EXPLORER_ASSET_NAMES) write(`assets/${a}`, loadFrom(BUNDLED_ASSETS, a, opts.assetsDir)); write("assets/explorer-data.js", `window.MO_EXPLORER = ${JSON.stringify(graphData(ix, pagesModel))};\n`); - write("explorer.json", serializeExplorer(opts.explorer)); + write("explorer.json", serializeDocsView(opts.view)); const dangling = checkLinks(opts.outDir, pages); if (dangling.length > 0) throw new Error("explorer link check failed:\n" + dangling.join("\n")); @@ -209,7 +209,7 @@ export function generateExplorerSite(opts: ExplorerSiteOptions): ExplorerSiteRes } /** The data the map, mini-maps, trace and search read. Every value comes off the index. */ -function graphData(ix: ExplorerIndex, p: Pages): Record { +function graphData(ix: ViewIndex, p: Pages): Record { const features = ix.features(); const top = [...ix.objects, ...ix.templates]; const nodes = top.map((n) => { @@ -235,7 +235,7 @@ function graphData(ix: ExplorerIndex, p: Pages): Record { }); const ids = new Set(top.map((n) => n.id)); const slices: Record = {}; - for (const s of ix.doc.slices) slices[s.id] = [...new Set(s.nodes.map((x) => ix.ownerOf(x)).filter((x) => ids.has(x)))].sort(); + for (const s of ix.view.slices) slices[s.id] = [...new Set(s.nodes.map((x) => ix.ownerOf(x)).filter((x) => ids.has(x)))].sort(); const reqs = ix.requirements.map((r) => ({ id: r.node.id, label: p.reqLabel(r), @@ -245,8 +245,8 @@ function graphData(ix: ExplorerIndex, p: Pages): Record { kind: r.kind, parent: r.parent?.node.id ?? "", href: p.reqPage(r), - targets: (r.row?.implementedBy ?? []).filter((l) => l.target !== undefined && ix.byId.has(l.target)).map((l) => ix.ownerOf(l.target!)), - statement: typeof r.node.attrs[REQUIREMENT_ATTR_STATEMENT] === "string" ? r.node.attrs[REQUIREMENT_ATTR_STATEMENT] : "", + targets: ix.linkTargets(r).map((id) => ix.ownerOf(id)), + statement: r.req.statement, rollup: ix.rollup(r), claimed: ix.targetsOf(r).length, })); @@ -274,18 +274,18 @@ function graphData(ix: ExplorerIndex, p: Pages): Record { t: p.reqLabel(r), s: `${r.level !== undefined ? `L${r.level}` : "—"} ${r.kind}${r.status !== "" ? ` · ${r.status}` : ""} · ${p.reqPath(r)}`, h: p.reqPage(r), - k: `${p.reqPath(r)} ${r.node.id} ${p.reqLabel(r)} ${String(r.node.attrs[REQUIREMENT_ATTR_STATEMENT] ?? "")}`.toLowerCase(), + k: `${p.reqPath(r)} ${r.node.id} ${p.reqLabel(r)} ${r.req.statement}`.toLowerCase(), }); } return { nodes, - edges: [ - ...ix.modelEdges().map((e) => ({ s: e.from, t: e.to, k: e.kind, ...(e.via !== undefined ? { v: localTail(e.via) } : {}) })), - // A report reads its rows from the `@from` entity: drawn so a report is not an island. - ...ix.objects - .filter((n) => n.subType === OBJECT_SUBTYPE_REPORT && typeof n.attrs[OBJECT_REPORT_ATTR_FROM] === "string" && ix.byId.has(n.attrs[OBJECT_REPORT_ATTR_FROM] as string)) - .map((n) => ({ s: n.id, t: n.attrs[OBJECT_REPORT_ATTR_FROM] as string, k: "from" })), - ], + // Every reference the view lists between two nodes on the map, labelled by the attribute + // that carries it (a report's `@from` among them, so a report is not an island). The map + // draws objects and prompts, and an edge to a node it does not draw would not load. + edges: ix + .modelEdges() + .filter((e) => ids.has(e.from) && ids.has(e.to)) + .map((e) => ({ s: e.from, t: e.to, k: e.kind, ...(e.via !== undefined ? { v: localTail(e.via) } : {}) })), slices, features: features.map((f) => ({ id: f.node.id, label: p.reqLabel(f) })), reqs, diff --git a/server/typescript/packages/docs-site/src/explorer/types.ts b/server/typescript/packages/docs-site/src/explorer/types.ts deleted file mode 100644 index 30dcaf5c39..0000000000 --- a/server/typescript/packages/docs-site/src/explorer/types.ts +++ /dev/null @@ -1,135 +0,0 @@ -// The `explorer.json` shape: the one data file every explorer view reads. -// -// It is BUILT from port-neutral inputs only (see build.ts), so its fields hold what those -// inputs state and nothing a loader would have to recompute. - -/** Bumped when a field changes meaning or is removed; adding a field does not bump it. */ -export const EXPLORER_FORMAT = "metaobjects-explorer/1"; - -/** One metadata node: a top-level node (object, prompt, requirement, …) or any node nested - * in one (field, identity, source, view, nested requirement, …). */ -export interface ExplorerNode { - /** `::` for a top-level node (`` with no package), then `.` - * per nesting level: `acme::shop::Order`, `acme::shop::Order.total`, - * `acme::shop::Shop.Checkout`. A nested node with no name gets `#` instead. */ - id: string; - type: string; - subType: string; - /** "" for a nested node with no name. */ - name: string; - /** The package of the node's top-level ancestor, "" when it has none. */ - package: string; - /** Its position among its siblings in the effective tree (0-based): declaration order, - * which `nodes` (sorted by id) does not keep. */ - order: number; - /** The id of the node this one is nested in; absent on a top-level node. */ - parent?: string; - /** The id `extends` names, as the effective tree spells it. */ - extends?: string; - abstract?: true; - isArray?: true; - /** On a member the effective tree materialized from a super: the id of the object it is - * declared on. Read as "same type, name and body as that ancestor's member", so a member - * redeclared with a different body is this node's own. */ - inheritedFrom?: string; - /** Every `@` attribute on the effective node, without the `@`, keys sorted. */ - attrs: Record; -} - -export const EXPLORER_EDGE_KINDS = [ - "extends", - "references", - "association", - "objectRef", - "payload", - "reply", - "contains", - "implementedBy", - "supersededBy", -] as const; -export type ExplorerEdgeKind = (typeof EXPLORER_EDGE_KINDS)[number]; - -/** A typed link between two nodes. Only links whose both ends are nodes are drawn. */ -export interface ExplorerEdge { - kind: ExplorerEdgeKind; - from: string; - to: string; - /** The member that carries the link, when it is not `from` itself: the - * `identity.reference`, the `field.object`, the `relationship.*`. */ - via?: string; -} - -/** One requirement as `meta verify --format json` judged it (`requirementLedger[]`), with - * the node id it has here. */ -export interface ExplorerLedgerRow { - node: string; - path: string; - package: string; - qualifiedPath: string; - subType: string; - level?: number; - status?: string; - disposition?: string; - digest: string; - implementedBy: { ref: string; resolves: boolean; target?: string }[]; - supersededBy?: { ref: string; resolves: boolean; target?: string }; - diagnostics: { code: string; severity: string; source: string; message: string }[]; - verdict: string; -} - -export interface ExplorerLedger { - /** `requirementCounts` from the verify payload, verbatim. */ - counts: Record; - /** One row per requirement, in the verify payload's (document) order. */ - rows: ExplorerLedgerRow[]; - /** `requirements.rows` from the verify payload, verbatim: every gate and lint finding, - * including the ones whose subject is not a requirement (an unclaimed entity). */ - diagnostics: unknown[]; -} - -export interface ExplorerGeneratedFile { - /** Project-relative, as the manifest keys it. */ - path: string; - generatedBy: string; -} - -/** The generated files the manifest attributes to one node. */ -export interface ExplorerGenerated { - node: string; - files: ExplorerGeneratedFile[]; -} - -export type ExplorerSliceKind = "requirement" | "package" | "prompt"; - -/** A named node set a view opens on, derived from the model with no authoring. */ -export interface ExplorerSlice { - /** `:`. */ - id: string; - kind: ExplorerSliceKind; - /** The requirement, package or prompt the slice is derived from ("" for the root package). */ - anchor: string; - /** Node ids, sorted. */ - nodes: string[]; -} - -/** One HTTP route the project mounts for a node, as the run that generated the routes states - * it. */ -export interface ExplorerRoute { - node: string; - method: string; - /** The mounted path, with the project's `apiPrefix`: `/api/orders/{id}`. */ - path: string; -} - -export interface ExplorerJson { - format: typeof EXPLORER_FORMAT; - nodes: ExplorerNode[]; - edges: ExplorerEdge[]; - /** Absent without a verify payload, or when the model declares no requirement. */ - ledger?: ExplorerLedger; - /** Absent without a manifest. */ - generated?: ExplorerGenerated[]; - /** Absent without a routes input. Sorted by node, then path, then method. */ - api?: ExplorerRoute[]; - slices: ExplorerSlice[]; -} diff --git a/server/typescript/packages/docs-site/src/explorer/view-index.ts b/server/typescript/packages/docs-site/src/explorer/view-index.ts new file mode 100644 index 0000000000..dd63eff392 --- /dev/null +++ b/server/typescript/packages/docs-site/src/explorer/view-index.ts @@ -0,0 +1,375 @@ +// An in-memory index over one docs view: the lookups every explorer page shares. +// +// It reads the view and nothing else, and it derives nothing the view does not state: it only +// files the view's nodes, members, requirements, claims, files and routes by id so a page can +// find them. Ids, pages, inheritance, references, claims and roll-ups are the view's +// (`buildDocsView` in `@metaobjectsdev/metadata`, built from the loaded model). + +import { + OBJECT_SUBTYPE_ENTITY, + OBJECT_SUBTYPE_PROJECTION, + OBJECT_SUBTYPE_REPORT, + OBJECT_SUBTYPE_VALUE, + SOURCE_ATTR_KIND, + SOURCE_ATTR_TABLE, + SOURCE_ATTR_VIEW, + SOURCE_KIND_VIEW, + TEMPLATE_SUBTYPE_PROMPT, + TYPE_FIELD, + TYPE_OBJECT, + TYPE_REQUIREMENT, + TYPE_SOURCE, + TYPE_TEMPLATE, +} from "@metaobjectsdev/metadata/constants"; +import { + REQUIREMENT_SUBTYPE_ARCHITECTURAL, + REQUIREMENT_SUBTYPE_FUNCTIONAL, + REQUIREMENT_STATUSES, + REQUIREMENT_STATUS_LIVE, + REQUIREMENT_STATUS_PARTIAL, + REQUIREMENT_STATUS_PLANNED, + REQUIREMENT_STATUS_RETIRED, + type DocsView, + type DocsViewMember, + type DocsViewNode, + type DocsViewRequirement, + type DocsViewRoute, + type DocsViewSlice, +} from "@metaobjectsdev/metadata"; + +/** The four declared statuses, in the order every bar and legend draws them: live first, since + * it is the claim a reader looks for, and the bar reads left to right as "done". */ +export const STATUSES: readonly string[] = [ + REQUIREMENT_STATUS_LIVE, + REQUIREMENT_STATUS_PARTIAL, + REQUIREMENT_STATUS_PLANNED, + REQUIREMENT_STATUS_RETIRED, +].filter((s) => (REQUIREMENT_STATUSES as readonly string[]).includes(s)); + +/** The glyph for each status, so the colour is never the only signal (§4.2). */ +export const STATUS_GLYPH: Readonly> = { + [REQUIREMENT_STATUS_LIVE]: "●", + [REQUIREMENT_STATUS_PARTIAL]: "◐", + [REQUIREMENT_STATUS_PLANNED]: "○", + [REQUIREMENT_STATUS_RETIRED]: "⊘", +}; + +const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0); + +/** A top-level node or a member, filed by id, with its attributes by name. */ +export interface PageNode { + id: string; + type: string; + subType: string; + name: string; + /** The package of its top-level node. */ + package: string; + order: number; + /** The id of the node it is nested in; absent at the top. */ + parent?: string; + /** Where a link to it lands. */ + path: string; + /** The anchor its row carries, on a direct member of a top-level node; "" otherwise. */ + anchor: string; + /** The id `extends` resolved to. */ + extends?: string; + abstract: boolean; + isArray: boolean; + /** The id of the node that declares it, when it is inherited. */ + inheritedFrom?: string; + /** Every effective attribute's value, by name. */ + attrs: Record; + view: DocsViewNode | DocsViewMember; +} + +/** One requirement as the pages read it: the view's entry and its place in the tree. */ +export interface ReqEntry { + node: PageNode; + req: DocsViewRequirement; + parent?: ReqEntry; + children: ReqEntry[]; + level?: number; + status: string; + /** functional | architectural */ + kind: string; +} + +/** A requirement's claim on a model node. */ +export interface Claim { + req: ReqEntry; + /** The member path when the claim names a member (`Order.reference`), else undefined. */ + member?: string; +} + +export type Rollup = Record; + +/** A link drawn between two top-level nodes on the map, from a reference the view lists. */ +export interface ModelEdge { + /** The attribute that carries it (`objectRef`, `payloadRef`, …), or `extends`. */ + kind: string; + from: string; + to: string; + via?: string; +} + +export interface GeneratedFile { + path: string; + generatedBy: string; +} + +export class ViewIndex { + readonly view: DocsView; + readonly byId = new Map(); + private readonly kids = new Map(); + /** Top-level object nodes, by id. */ + readonly objects: PageNode[] = []; + /** Top-level template nodes, by id. */ + readonly templates: PageNode[] = []; + /** Top-level nodes of every other type but requirement, each on a generic page. */ + readonly others: PageNode[] = []; + /** Every requirement, in document order. */ + readonly requirements: ReqEntry[] = []; + readonly reqById = new Map(); + readonly topRequirements: ReqEntry[] = []; + readonly packages: string[]; + private readonly topOf = new Map(); + + constructor(view: DocsView) { + this.view = view; + for (const n of view.nodes) { + const top = this.file(n, n.package, undefined); + this.topOf.set(n.id, n); + for (const g of n.memberGroups) for (const m of g.members) this.fileMember(m, n.package, top.id); + if (n.type === TYPE_OBJECT) this.objects.push(top); + else if (n.type === TYPE_TEMPLATE) this.templates.push(top); + else if (n.type !== TYPE_REQUIREMENT) this.others.push(top); + } + for (const list of this.kids.values()) list.sort((a, b) => a.order - b.order || byCodeUnit(a.id, b.id)); + this.packages = view.packages.map((p) => p.name); + for (const r of view.requirements) { + const node = this.byId.get(r.id); + if (node === undefined) continue; + const parent = r.parent !== null ? this.reqById.get(r.parent.id) : undefined; + const entry: ReqEntry = { + node, + req: r, + ...(parent !== undefined ? { parent } : {}), + children: [], + ...(r.level !== null ? { level: r.level } : {}), + status: r.status, + kind: r.subType, + }; + this.requirements.push(entry); + this.reqById.set(r.id, entry); + if (parent !== undefined) parent.children.push(entry); + else this.topRequirements.push(entry); + } + } + + private file(v: DocsViewNode | DocsViewMember, pkg: string, parent: string | undefined): PageNode { + const attrs: Record = {}; + for (const a of v.attrs) attrs[a.name] = a.value; + const declaredOn = "declaredOn" in v ? v.declaredOn : null; + const n: PageNode = { + id: v.id, + type: v.type, + subType: v.subType, + name: v.name, + package: pkg, + order: v.order, + ...(parent !== undefined ? { parent } : {}), + path: v.path, + anchor: "anchor" in v ? v.anchor : "", + ...(v.extends !== null && !v.extends.unresolved ? { extends: v.extends.id } : {}), + abstract: v.abstract, + isArray: "isArray" in v ? v.isArray : false, + ...(declaredOn !== null && !declaredOn.unresolved ? { inheritedFrom: declaredOn.id } : {}), + attrs, + view: v, + }; + this.byId.set(n.id, n); + if (parent !== undefined) this.kids.set(parent, [...(this.kids.get(parent) ?? []), n]); + return n; + } + + private fileMember(m: DocsViewMember, pkg: string, parent: string): void { + this.file(m, pkg, parent); + for (const g of m.memberGroups) for (const c of g.members) this.fileMember(c, pkg, m.id); + } + + /** Direct children of a node, in declaration order. */ + children(id: string): PageNode[] { + return this.kids.get(id) ?? []; + } + + /** The top-level node a node sits under (itself at the top). */ + ownerOf(id: string): string { + let cur = this.byId.get(id); + while (cur?.parent !== undefined) cur = this.byId.get(cur.parent); + return cur?.id ?? id; + } + + /** The view's entry for a top-level node. */ + top(id: string): DocsViewNode | undefined { + return this.topOf.get(id); + } + + fields(id: string): PageNode[] { + return this.children(id).filter((c) => c.type === TYPE_FIELD); + } + + /** The node's `source.*` child, when it declares one. */ + source(id: string): PageNode | undefined { + return this.children(id).find((c) => c.type === TYPE_SOURCE); + } + + /** `table x`, `view v_x`, or undefined: what the source declares, never a derived name. */ + storage(id: string): { kind: "table" | "view"; name?: string } | undefined { + const s = this.source(id); + if (s === undefined) return undefined; + const view = s.attrs[SOURCE_ATTR_VIEW]; + const table = s.attrs[SOURCE_ATTR_TABLE]; + const isView = s.attrs[SOURCE_ATTR_KIND] === SOURCE_KIND_VIEW || typeof view === "string"; + const name = typeof view === "string" ? view : typeof table === "string" ? table : undefined; + return { kind: isView ? "view" : "table", ...(name !== undefined ? { name } : {}) }; + } + + isEntity(n: PageNode): boolean { + return n.type === TYPE_OBJECT && n.subType === OBJECT_SUBTYPE_ENTITY; + } + + isPrompt(n: PageNode): boolean { + return n.type === TYPE_TEMPLATE && n.subType === TEMPLATE_SUBTYPE_PROMPT; + } + + /** The kind a page and the map name a top-level node by. */ + kindOf(n: PageNode): "entity" | "value" | "projection" | "report" | "prompt" | "template" | "object" | "other" { + if (n.type === TYPE_TEMPLATE) return n.subType === TEMPLATE_SUBTYPE_PROMPT ? "prompt" : "template"; + if (n.type !== TYPE_OBJECT) return "other"; + if (n.subType === OBJECT_SUBTYPE_ENTITY) return "entity"; + if (n.subType === OBJECT_SUBTYPE_VALUE) return "value"; + if (n.subType === OBJECT_SUBTYPE_PROJECTION) return "projection"; + if (n.subType === OBJECT_SUBTYPE_REPORT) return "report"; + return "object"; + } + + /** Concrete stored entities: `object.entity`, not abstract. */ + storedEntities(): PageNode[] { + return this.objects.filter((o) => this.isEntity(o) && !o.abstract); + } + + claims(id: string): Claim[] { + const v = this.byId.get(id)?.view; + if (v === undefined) return []; + return v.claims.flatMap((c) => { + const req = this.reqById.get(c.requirement.id); + return req === undefined ? [] : [{ req, ...(c.member !== "" ? { member: c.member } : {}) }]; + }); + } + + generated(id: string): GeneratedFile[] { + return (this.topOf.get(id)?.files ?? []).flatMap((g) => g.paths.map((path) => ({ path, generatedBy: g.generatedBy }))); + } + + routes(id: string): DocsViewRoute[] { + return this.topOf.get(id)?.routes ?? []; + } + + hasRequirements(): boolean { + return this.requirements.length > 0; + } + + /** Whether any requirement claims anything: object coverage only means something then. */ + hasClaims(): boolean { + return this.view.counts.claims > 0; + } + + /** The requirement and every requirement below it, depth first. */ + subtree(r: ReqEntry): ReqEntry[] { + const out: ReqEntry[] = []; + const walk = (x: ReqEntry): void => { + out.push(x); + for (const c of x.children) walk(c); + }; + walk(r); + return out; + } + + below(r: ReqEntry): ReqEntry[] { + return this.subtree(r).slice(1); + } + + /** The view's roll-up of the statuses below, by status. */ + rollup(r: ReqEntry): Rollup { + const c: Rollup = {}; + for (const s of r.req.rollup) if (s.count > 0) c[s.status] = s.count; + return c; + } + + /** The top-level nodes the subtree claims (sorted). */ + targetsOf(r: ReqEntry): string[] { + return r.req.targets.map((t) => t.id); + } + + /** The node ids an `@implementedBy` of the requirement resolves to. */ + linkTargets(r: ReqEntry): string[] { + return r.req.implementedBy.filter((l) => l.resolves && this.byId.has(l.target.id)).map((l) => l.target.id); + } + + /** The L1 feature (functional top) with the most claims on a node, by document order on a tie. */ + featureOf(id: string): ReqEntry | undefined { + const count = new Map(); + for (const c of this.claims(id)) { + let top = c.req; + while (top.parent !== undefined) top = top.parent; + if (top.kind !== REQUIREMENT_SUBTYPE_FUNCTIONAL) continue; + count.set(top, (count.get(top) ?? 0) + 1); + } + let best: ReqEntry | undefined; + for (const t of this.features()) { + const n = count.get(t) ?? 0; + if (n > 0 && (best === undefined || n > (count.get(best) ?? 0))) best = t; + } + return best; + } + + features(): ReqEntry[] { + return this.topRequirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_FUNCTIONAL); + } + + qualities(): ReqEntry[] { + return this.topRequirements.filter((r) => r.kind === REQUIREMENT_SUBTYPE_ARCHITECTURAL); + } + + /** The best declared status among a node's claims, or "unclaimed". */ + claimStatus(id: string): string { + const cl = this.claims(id); + if (cl.length === 0) return "unclaimed"; + for (const s of STATUSES) if (cl.some((c) => c.req.status === s)) return s; + return "unclaimed"; + } + + /** The references between two top-level nodes, one per (kind, from, to): a member's + * reference is drawn from its top-level node. Requirements are left out. */ + modelEdges(): ModelEdge[] { + const out: ModelEdge[] = []; + const seen = new Set(); + for (const n of this.view.nodes) { + if (n.type === TYPE_REQUIREMENT) continue; + for (const r of n.refs) { + const to = this.ownerOf(r.target.id); + const b = this.byId.get(to); + if (to === n.id || b === undefined || b.type === TYPE_REQUIREMENT) continue; + const key = `${r.attr}\u0000${n.id}\u0000${to}`; + if (seen.has(key)) continue; + seen.add(key); + out.push({ kind: r.attr, from: n.id, to, ...(r.via !== null ? { via: r.via.id } : {}) }); + } + } + return out.sort((a, b) => byCodeUnit(`${a.kind}\u0000${a.from}\u0000${a.to}`, `${b.kind}\u0000${b.from}\u0000${b.to}`)); + } + + slice(id: string): DocsViewSlice | undefined { + return this.view.slices.find((s) => s.id === id); + } +} diff --git a/server/typescript/packages/docs-site/src/index.ts b/server/typescript/packages/docs-site/src/index.ts index 98f363b62c..8e5c99c062 100644 --- a/server/typescript/packages/docs-site/src/index.ts +++ b/server/typescript/packages/docs-site/src/index.ts @@ -2,21 +2,9 @@ export { generateSite, DEFAULT_ASSET_BASE } from "./site.js"; export type { SiteOptions, SiteResult } from "./site.js"; export { SITE_TEMPLATE_NAMES, SITE_ASSET_NAMES, CLASSIC_TEMPLATE_NAMES, CLASSIC_ASSET_NAMES, readSiteFile } from "./scaffold.js"; export type { MetaDataTypeProvider } from "@metaobjectsdev/metadata"; -export { buildExplorer, serializeExplorer } from "./explorer/build.js"; -export type { ExplorerInput } from "./explorer/build.js"; -export { EXPLORER_FORMAT, EXPLORER_EDGE_KINDS } from "./explorer/types.js"; -export type { - ExplorerJson, - ExplorerNode, - ExplorerEdge, - ExplorerEdgeKind, - ExplorerLedger, - ExplorerLedgerRow, - ExplorerGenerated, - ExplorerGeneratedFile, - ExplorerSlice, - ExplorerSliceKind, -} from "./explorer/types.js"; +// The explorer reads the docs view, which `@metaobjectsdev/metadata` builds from the loaded model +// (`buildDocsView`, `docs/features/docs-view.md`). +export { ViewIndex, STATUSES, STATUS_GLYPH } from "./explorer/view-index.js"; +export type { PageNode, ReqEntry, Claim, ModelEdge } from "./explorer/view-index.js"; export { generateExplorerSite, readPromptTexts, EXPLORER_TEMPLATE_NAMES, EXPLORER_ASSET_NAMES, CYTOSCAPE_PATH } from "./explorer/site.js"; export type { ExplorerSiteOptions, ExplorerSiteResult } from "./explorer/site.js"; -export type { ExplorerRoute } from "./explorer/types.js"; diff --git a/server/typescript/packages/docs-site/test/explorer-build.test.ts b/server/typescript/packages/docs-site/test/explorer-build.test.ts deleted file mode 100644 index 2a2eaef273..0000000000 --- a/server/typescript/packages/docs-site/test/explorer-build.test.ts +++ /dev/null @@ -1,177 +0,0 @@ -// `buildExplorer` — the explorer data spine — over the committed conformance fixture -// (`fixtures/explorer-conformance/shop/`), checked byte for byte, plus the behaviour a -// byte check alone would not explain when it breaks. -import { describe, test, expect } from "bun:test"; -import { readFileSync } from "node:fs"; -import { join, resolve } from "node:path"; -import { buildExplorer, serializeExplorer, type ExplorerJson } from "../src/index.js"; -import { CUSTOM_VOCABULARY_MODEL, CUSTOM_VOCABULARY_VERIFY } from "./fixture/custom-vocabulary.js"; - -const FIXTURE = resolve(import.meta.dir, "../../../../../fixtures/explorer-conformance/shop"); -const text = (name: string): string => readFileSync(join(FIXTURE, name), "utf8"); -const json = (name: string): unknown => JSON.parse(text(name)); - -function build(parts: { verify?: boolean; manifest?: boolean } = { verify: true, manifest: true }): ExplorerJson { - return buildExplorer({ - model: json("effective.json"), - ...(parts.verify ? { verify: json("verify.json") } : {}), - ...(parts.manifest ? { manifest: json("hashes.json") } : {}), - }); -} - -describe("explorer-conformance/shop", () => { - test("builds expected.json byte for byte", () => { - expect(serializeExplorer(build())).toBe(text("expected.json")); - }); - - test("object key order in the model and the manifest does not change the bytes", () => { - const reversed = (v: unknown): unknown => - Array.isArray(v) ? v.map(reversed) - : typeof v === "object" && v !== null - ? Object.fromEntries(Object.entries(v).reverse().map(([k, x]) => [k, reversed(x)])) - : v; - const explorer = buildExplorer({ - model: reversed(json("effective.json")), - verify: json("verify.json"), - manifest: reversed(json("hashes.json")), - }); - expect(serializeExplorer(explorer)).toBe(text("expected.json")); - }); -}); - -describe("buildExplorer", () => { - test("marks inherited members with the object that declares them", () => { - const nodes = new Map(build().nodes.map((n) => [n.id, n])); - expect(nodes.get("acme::shop::Order.id")?.inheritedFrom).toBe("acme::shop::BaseEntity"); - expect(nodes.get("acme::shop::Order.total")?.inheritedFrom).toBeUndefined(); - // AuditEntry declares its own `id` and does not extend BaseEntity. - expect(nodes.get("acme::shop::AuditEntry.id")?.inheritedFrom).toBeUndefined(); - }); - - test("an implementedBy edge exists only where the verify ledger resolved the link", () => { - const withVerify = build().edges.filter((e) => e.kind === "implementedBy"); - expect(withVerify).toContainEqual({ kind: "implementedBy", from: "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", to: "acme::shop::Order.reference" }); - // `Refunded` names `Refund`, which does not exist: a ledger row, no edge. - expect(withVerify.some((e) => e.from.endsWith("Refunded"))).toBe(false); - expect(build({ manifest: true }).edges.some((e) => e.kind === "implementedBy")).toBe(false); - expect(build({ manifest: true }).ledger).toBeUndefined(); - }); - - test("generated groups the manifest's attributed files by node; plain entries are skipped", () => { - expect(build().generated?.map((g) => g.node)).toEqual(["acme::shop::Customer", "acme::shop::Order"]); - expect(build({ verify: true }).generated).toBeUndefined(); - }); - - test("routes are kept per known node, sorted, deduplicated; without them there is no api", () => { - const api = buildExplorer({ - model: json("effective.json"), - routes: [ - { node: "acme::shop::Order", method: "post", path: "/api/orders" }, - { node: "acme::shop::Order", method: "GET", path: "/api/orders" }, - { node: "acme::shop::Order", method: "GET", path: "/api/orders" }, - { node: "acme::shop::Customer", method: "GET", path: "/api/customers/{id}" }, - { node: "acme::shop::Gone", method: "GET", path: "/api/gone" }, - { node: "acme::shop::Order", path: "/api/no-method" }, - ], - }).api; - expect(api).toEqual([ - { node: "acme::shop::Customer", method: "GET", path: "/api/customers/{id}" }, - { node: "acme::shop::Order", method: "GET", path: "/api/orders" }, - { node: "acme::shop::Order", method: "POST", path: "/api/orders" }, - ]); - expect(build().api).toBeUndefined(); - }); - - test("a requirement slice holds the subtree, its targets and the owner of a claimed member", () => { - const slice = build().slices.find((s) => s.id === "requirement:acme::shop::Shop.Checkout.Orders.Recorded"); - expect(slice?.nodes).toEqual([ - "acme::shop::Customer", - "acme::shop::Order", - "acme::shop::Order.reference", - "acme::shop::Shop.Checkout.Orders.Recorded", - "acme::shop::Shop.Checkout.Orders.Recorded.Quotable", - ]); - }); - - test("rejects input that is not canonical metadata JSON", () => { - expect(() => buildExplorer({ model: { nodes: [] } })).toThrow(/not canonical metadata JSON/); - }); - - test("a sibling sharing a member's name gets a type-qualified id; the member keeps the plain one", () => { - const nodes = new Map(build().nodes.map((n) => [n.id, n])); - expect(nodes.get("acme::shop::AuditEntry.id")?.type).toBe("field"); - expect(nodes.get("acme::shop::AuditEntry.id[identity.primary]")?.type).toBe("identity"); - }); - - test("a top-level node of another type sharing an object's name gets a type-qualified id; the object keeps the plain one", () => { - // The page is declared first: the object keeps the plain id anyway, since references name objects. - const built = buildExplorer({ model: CUSTOM_VOCABULARY_MODEL, verify: CUSTOM_VOCABULARY_VERIFY }); - const nodes = new Map(built.nodes.map((n) => [n.id, n])); - expect(nodes.get("acme::crm::Lead")?.type).toBe("object"); - expect(nodes.get("acme::crm::Lead.email")?.type).toBe("field"); - expect(nodes.get("acme::crm::Lead[page.list]")?.type).toBe("page"); - expect(nodes.get("acme::crm::Lead[page.list].leads")?.parent).toBe("acme::crm::Lead[page.list]"); - expect(built.edges).toContainEqual({ kind: "implementedBy", from: "acme::tax::Tax", to: "acme::tax::tax" }); - }); - - test("a model with no collision keeps every top-level id plain", () => { - for (const n of build().nodes) if (n.parent === undefined) expect(n.id).not.toContain("["); - }); - - test("a requirement whose id is qualified still takes its ledger row", () => { - const model = { - "metadata.root": { - package: "p", - children: [ - { "object.entity": { name: "Billing" } }, - { "requirement.functional": { name: "Billing", "@status": "live", children: [{ "requirement.functional": { name: "Invoices", "@status": "live" } }] } }, - ], - }, - }; - const row = (path: string): unknown => ({ path, package: "p", qualifiedPath: `p::${path}`, subType: "functional", status: "live", digest: "", implementedBy: [{ ref: "Billing", resolves: true, target: "p::Billing" }], diagnostics: [], verdict: "clean" }); - const built = buildExplorer({ model, verify: { requirementLedger: [row("Billing"), row("Billing.Invoices")] } }); - expect(built.ledger?.rows.map((r) => r.node)).toEqual(["p::Billing[requirement.functional]", "p::Billing[requirement.functional].Invoices"]); - expect(built.edges).toContainEqual({ kind: "implementedBy", from: "p::Billing[requirement.functional]", to: "p::Billing" }); - }); - - test("rejects two top-level nodes of one type sharing an id", () => { - const model = { - "metadata.root": { - package: "p", - children: [ - { "object.entity": { name: "A" } }, - { "object.value": { name: "A" } }, - ], - }, - }; - expect(() => buildExplorer({ model })).toThrow(/two nodes share the id "p::A"/); - }); - - test("a root-level target spelled `::Name` still gets its edges and inheritedFrom", () => { - const idField = { name: "id", type: "long" }; - const model = { - "metadata.root": { - children: [ - { "object.entity": { name: "BaseEntity", abstract: true, children: [{ "field.long": idField }] } }, - { - "object.entity": { - name: "Order", - package: "acme::shop", - extends: "::BaseEntity", - children: [ - { "field.long": idField }, - { "relationship.association": { name: "owner", "@objectRef": "::BaseEntity" } }, - ], - }, - }, - ], - }, - }; - const built = buildExplorer({ model }); - const nodes = new Map(built.nodes.map((n) => [n.id, n])); - expect(nodes.get("acme::shop::Order")?.extends).toBe("BaseEntity"); - expect(nodes.get("acme::shop::Order.id")?.inheritedFrom).toBe("BaseEntity"); - expect(built.edges).toContainEqual({ kind: "extends", from: "acme::shop::Order", to: "BaseEntity" }); - expect(built.edges).toContainEqual({ kind: "association", from: "acme::shop::Order", to: "BaseEntity", via: "acme::shop::Order.owner" }); - }); -}); diff --git a/server/typescript/packages/docs-site/test/explorer-site.test.ts b/server/typescript/packages/docs-site/test/explorer-site.test.ts index f535596b8f..466949e18a 100644 --- a/server/typescript/packages/docs-site/test/explorer-site.test.ts +++ b/server/typescript/packages/docs-site/test/explorer-site.test.ts @@ -1,20 +1,15 @@ -// The model explorer site (`generateExplorerSite`) over the public fixtures: the shop -// explorer-conformance fixture (requirements, a prompt, an unclaimed entity) and the -// persistence-conformance fitness model (projections, reports, no requirements). +// The model explorer site (`generateExplorerSite`) over the public fixtures: the docs view +// corpus's shop fixture (requirements, a prompt, an unclaimed entity) and crm fixture +// (application-owned vocabulary), and the persistence-conformance fitness model (projections, +// reports, no requirements). Every view is built from a loaded model, as `meta gen` builds it. import { afterAll, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, relative, resolve } from "node:path"; -import { MetaDataLoader, canonicalSerializeEffective } from "@metaobjectsdev/metadata"; +import { MetaDataLoader, buildDocsView, type DocsView } from "@metaobjectsdev/metadata"; import { FileSource } from "@metaobjectsdev/metadata/core"; -import { - buildExplorer, - EXPLORER_ASSET_NAMES, - generateExplorerSite, - readPromptTexts, - type ExplorerJson, -} from "../src/index.js"; -import { CUSTOM_VOCABULARY_MODEL, CUSTOM_VOCABULARY_VERIFY } from "./fixture/custom-vocabulary.js"; +import { EXPLORER_ASSET_NAMES, generateExplorerSite, readPromptTexts } from "../src/index.js"; +import { corpusView, inlineView } from "./fixture/views.js"; const REPO = resolve(import.meta.dir, "../../../../.."); const SHOP = join(REPO, "fixtures/explorer-conformance/shop"); @@ -37,25 +32,24 @@ function filesUnder(dir: string): string[] { .sort(); } -const shopExplorer = (): ExplorerJson => JSON.parse(readFileSync(join(SHOP, "expected.json"), "utf8")) as ExplorerJson; +const shopView = await corpusView("shop"); -function buildShop(): { out: string; pages: string[]; files: string[]; page: (p: string) => string } { - const explorer = shopExplorer(); +function buildShop(view: DocsView = shopView): { out: string; pages: string[]; files: string[]; page: (p: string) => string } { const out = scratch(); const r = generateExplorerSite({ - explorer, + view, outDir: out, title: "Shop", - texts: readPromptTexts(explorer, [join(SHOP, "project/prompts"), join(SHOP, "project")]), + texts: readPromptTexts(view, [join(SHOP, "project/prompts"), join(SHOP, "project")]), }); return { out, pages: r.pages, files: r.files, page: (p) => readFileSync(join(out, p), "utf8") }; } async function buildFitness(): Promise<{ page: (p: string) => string; files: string[] }> { const root = (await new MetaDataLoader().load([new FileSource(join(FITNESS, "meta.fitness.json"))])).root; - const explorer = buildExplorer({ model: JSON.parse(canonicalSerializeEffective(root)) as unknown }); + const view = buildDocsView({ root }); const out = scratch(); - const r = generateExplorerSite({ explorer, outDir: out, title: "Fitness", texts: readPromptTexts(explorer, [join(FITNESS, "prompts"), FITNESS]) }); + const r = generateExplorerSite({ view, outDir: out, title: "Fitness", texts: readPromptTexts(view, [join(FITNESS, "prompts"), FITNESS]) }); return { files: r.files, page: (p) => readFileSync(join(out, p), "utf8") }; } @@ -82,7 +76,7 @@ describe("explorer site over explorer-conformance/shop", () => { for (const f of shop.files) expect(again.page(f)).toBe(shop.page(f)); }); - test("the explorer.json it ships is the one it read", () => { + test("the explorer.json it ships is the docs view it read, byte for byte", () => { expect(shop.page("explorer.json")).toBe(readFileSync(join(SHOP, "expected.json"), "utf8")); }); @@ -125,24 +119,19 @@ describe("explorer site over explorer-conformance/shop", () => { expect(audit).toContain("WARN_REQUIREMENT_OBJECT_UNCLAIMED"); }); - test("the unclaimed outline follows the finding's node field, not its message", () => { - const reworded = (node: string, message: string): ExplorerJson => { - const explorer = shopExplorer(); - const ledger = explorer.ledger; - if (ledger === undefined) throw new Error("the shop fixture has a ledger"); - ledger.diagnostics = ledger.diagnostics.map((d) => { - const r = d as Record; - return r["code"] === "WARN_REQUIREMENT_OBJECT_UNCLAIMED" ? { ...r, node, message } : d; + test("the unclaimed outline follows the finding's node field, not its message", async () => { + const reworded = (node: string, message: string): Promise => + corpusView("shop", (input) => { + const verify = input.verify as { requirements: { rows: Record[] } }; + verify.requirements.rows = verify.requirements.rows.map((r) => (r["code"] === "WARN_REQUIREMENT_OBJECT_UNCLAIMED" ? { ...r, node, message } : r)); }); - return explorer; - }; - const auditPage = (explorer: ExplorerJson): string => { + const auditPage = (view: DocsView): string => { const out = scratch(); - generateExplorerSite({ explorer, outDir: out, title: "Shop" }); + generateExplorerSite({ view, outDir: out, title: "Shop" }); return readFileSync(join(out, "model/acme/shop/AuditEntry.html"), "utf8"); }; - expect(auditPage(reworded("acme::shop::AuditEntry", "an entity is unclaimed"))).toContain("chip v-unclaimed"); - expect(auditPage(reworded("", "no requirement claims 'acme::shop::AuditEntry'."))).not.toContain("chip v-unclaimed"); + expect(auditPage(await reworded("acme::shop::AuditEntry", "an entity is unclaimed"))).toContain("chip v-unclaimed"); + expect(auditPage(await reworded("", "no requirement claims 'acme::shop::AuditEntry'."))).not.toContain("chip v-unclaimed"); }); test("a field and a key that share a name get distinct anchors", () => { @@ -158,6 +147,9 @@ describe("explorer site over explorer-conformance/shop", () => { expect(order).toContain('href="../../../requirements/acme/shop/Shop.Checkout.Orders.Recorded.html"'); expect(order).toContain('id="m-reference"'); expect(order).toContain("src/generated/acme/shop/Order.queries.ts"); + expect(order).toContain("/api/orders/{id}"); + // A member with no row (the source) still has an anchor, so the view's link to it lands. + expect(order).toContain(''); expect(order).toContain('
{ }); }); -describe("explorer site over application-owned vocabulary", () => { +describe("explorer site over application-owned vocabulary (explorer-conformance/crm)", async () => { + const view = await corpusView("crm"); const build = (): { pages: string[]; page: (p: string) => string } => { const out = scratch(); - const r = generateExplorerSite({ explorer: buildExplorer({ model: CUSTOM_VOCABULARY_MODEL, verify: CUSTOM_VOCABULARY_VERIFY }), outDir: out, title: "Acme" }); + const r = generateExplorerSite({ view, outDir: out, title: "Acme" }); return { pages: r.pages, page: (p) => readFileSync(join(out, p), "utf8") }; }; @@ -230,12 +223,32 @@ describe("explorer site over application-owned vocabulary", () => { const tax = page("model/acme/tax/tax.html"); expect(tax).toContain("capability.module"); expect(tax).toContain("Sales tax."); - expect(tax).toContain("The software computes sales tax."); + expect(tax).toContain("Each lead is stored with its email and account."); const list = page("model/acme/crm/Lead.page-list.html"); expect(list).toContain("page.list"); expect(list).toContain(`id="m-block-leads"`); - // An attribute naming a node links to that node's page. + // An attribute the loader resolves as a reference links to its node's page; one it does + // not resolve stays text, whatever it happens to spell. expect(list).toContain(`href="../../../model/acme/crm/Lead.html"`); + expect(list).toContain(`href="../../../model/acme/crm/Account.html"`); + expect(list).toContain("["email","accountId"]"); + }); + + test("the map draws only edges whose two ends it draws", () => { + const out = scratch(); + generateExplorerSite({ view, outDir: out, title: "Acme" }); + const js = readFileSync(join(out, "assets/explorer-data.js"), "utf8"); + const data = JSON.parse(js.slice(js.indexOf("=") + 1).trim().replace(/;$/, "")) as { nodes: { id: string }[]; edges: { s: string; t: string; k: string; v?: string }[] }; + const drawn = new Set(data.nodes.map((n) => n.id)); + // The page.list references Lead and Account, but the map does not draw the page. + expect(drawn.has("acme::crm::Lead[page.list]")).toBe(false); + expect(data.edges.filter((e) => !drawn.has(e.s) || !drawn.has(e.t))).toEqual([]); + expect(data.edges).toContainEqual({ s: "acme::crm::Lead", t: "acme::crm::Account", k: "references", v: "accountRef" }); + }); + + test("an entity's page lists the custom node referencing it", () => { + const { page } = build(); + expect(page("model/acme/crm/Account.html")).toContain(`href="../../../model/acme/crm/Lead.page-list.html"`); }); test("the package page lists the custom nodes beside the objects", () => { @@ -252,29 +265,30 @@ describe("explorer site page paths", () => { }); const entity = (name: string): unknown => ({ "object.entity": { name, children: [{ "field.string": { name: "title" } }] } }); - test("an object named index does not take its package's index page", () => { + test("an object named index does not take its package's index page", async () => { const out = scratch(); - const r = generateExplorerSite({ explorer: buildExplorer({ model: model("acme", [entity("index"), entity("Order")]) }), outDir: out, title: "T" }); + const r = generateExplorerSite({ view: await inlineView(model("acme", [entity("index"), entity("Order")])), outDir: out, title: "T" }); expect(r.pages).toContain("model/acme/index.html"); expect(r.pages).toContain("model/acme/index.node.html"); expect(readFileSync(join(out, "model/acme/index.html"), "utf8")).toContain("Order"); }); - test("a model with no package gets pages under a directory no package name can take", () => { + test("a model with no package gets pages under a directory no package name can take", async () => { const out = scratch(); - const r = generateExplorerSite({ explorer: buildExplorer({ model: model(undefined, [entity("Order")]) }), outDir: out, title: "T" }); + const r = generateExplorerSite({ view: await inlineView(model(undefined, [entity("Order")])), outDir: out, title: "T" }); expect(r.pages).toContain("model/-root/Order.html"); }); - test("a prompt's @textRef is read only below the directories it is given", () => { + test("a prompt's @textRef is read only below the directories it is given", async () => { const base = scratch(); const prompts = join(base, "prompts"); mkdirSync(prompts); writeFileSync(join(prompts, "ok.mustache"), "Hello {{name}}"); writeFileSync(join(base, "secret.mustache"), "outside"); - const prompt = (name: string, ref: string): unknown => ({ "template.prompt": { name, "@textRef": ref } }); - const explorer = buildExplorer({ model: model("acme", [prompt("Ok", "ok"), prompt("Up", "../secret"), prompt("Abs", join(base, "secret"))]) }); - const texts = readPromptTexts(explorer, [prompts]); + const prompt = (name: string, ref: string): unknown => ({ "template.prompt": { name, "@textRef": ref, "@payloadRef": "Req" } }); + const req = { "object.value": { name: "Req", children: [{ "field.string": { name: "name" } }] } }; + const view = await inlineView(model("acme", [req, prompt("Ok", "ok"), prompt("Up", "../secret"), prompt("Abs", join(base, "secret"))])); + const texts = readPromptTexts(view, [prompts]); expect(texts.get("acme::Ok")).toBe("Hello {{name}}"); expect(texts.has("acme::Up")).toBe(false); expect(texts.has("acme::Abs")).toBe(false); diff --git a/server/typescript/packages/docs-site/test/fixture/custom-vocabulary.ts b/server/typescript/packages/docs-site/test/fixture/custom-vocabulary.ts deleted file mode 100644 index c743c088e2..0000000000 --- a/server/typescript/packages/docs-site/test/fixture/custom-vocabulary.ts +++ /dev/null @@ -1,61 +0,0 @@ -// A model with application-owned top-level vocabulary, as an adopter with its own providers -// exports it: an entity and a page of a custom type sharing a package and a name, and a -// requirement claiming a node of a custom type. Both shapes broke the explorer: the first -// threw on a duplicate id, the second left a link with no page behind it. -// -// The explorer reads canonical JSON and never the loader, so the custom types (`page.list`, -// `capability.module`) need no provider here. - -export const CUSTOM_VOCABULARY_MODEL = { - "metadata.root": { - children: [ - { - "page.list": { - name: "Lead", - package: "acme::crm", - "@entity": "acme::crm::Lead", - children: [{ "block.table": { name: "leads", "@entity": "acme::crm::Lead" } }], - }, - }, - { - "object.entity": { - name: "Lead", - package: "acme::crm", - "@description": "A prospective customer.", - children: [ - { "field.long": { name: "id" } }, - { "field.string": { name: "email" } }, - ], - }, - }, - { "capability.module": { name: "tax", package: "acme::tax", "@description": "Sales tax." } }, - { - "requirement.functional": { - name: "Tax", - package: "acme::tax", - "@level": 1, - "@status": "live", - "@statement": "The software computes sales tax.", - "@implementedBy": ["acme::tax::tax"], - }, - }, - ], - }, -}; - -export const CUSTOM_VOCABULARY_VERIFY = { - requirementLedger: [ - { - path: "Tax", - package: "acme::tax", - qualifiedPath: "acme::tax::Tax", - subType: "functional", - level: 1, - status: "live", - digest: "", - implementedBy: [{ ref: "acme::tax::tax", resolves: true, target: "acme::tax::tax" }], - diagnostics: [], - verdict: "clean", - }, - ], -}; diff --git a/server/typescript/packages/docs-site/test/fixture/views.ts b/server/typescript/packages/docs-site/test/fixture/views.ts new file mode 100644 index 0000000000..b0e7facece --- /dev/null +++ b/server/typescript/packages/docs-site/test/fixture/views.ts @@ -0,0 +1,58 @@ +// Docs views for the explorer tests, each built the way `meta gen` builds one: from a LOADED +// model, plus the optional inputs a fixture carries. +import { existsSync, readFileSync } from "node:fs"; +import { join, resolve } from "node:path"; +import { + InMemoryStringSource, + MetaData, + MetaDataLoader, + applyProviderDefinition, + buildDocsView, + composeRegistry, + coreProviders, + type DocsView, + type DocsViewInput, + type FactoryMap, + type MetaDataTypeProvider, + type ProviderDefinition, +} from "@metaobjectsdev/metadata"; + +/** A node of a type the fixture's provider.json declares: no behaviour beyond MetaData's own. */ +class FixtureNode extends MetaData {} + +export const CORPUS = resolve(import.meta.dir, "../../../../../../fixtures/explorer-conformance"); + +function readJson(dir: string, name: string): unknown { + const p = join(dir, name); + return existsSync(p) ? (JSON.parse(readFileSync(p, "utf8")) as unknown) : undefined; +} + +/** A provider for a fixture's `provider.json`: every type it declares is a plain node. */ +function fixtureProvider(def: ProviderDefinition): MetaDataTypeProvider { + const factories: FactoryMap = {}; + for (const t of def.types ?? []) factories[`${t.type}.${t.subType}`] = (id, name) => new FixtureNode(id, name); + return { id: def.provider, dependencies: ["metaobjects-core-types"], registerTypes: (r) => applyProviderDefinition(r, def, factories) }; +} + +/** One corpus fixture's view, with its committed inputs; `edit` may change them first. */ +export async function corpusView(name: string, edit?: (input: Omit) => void): Promise { + const dir = join(CORPUS, name); + const def = readJson(dir, "provider.json") as ProviderDefinition | undefined; + const registry = composeRegistry(def !== undefined ? [...coreProviders, fixtureProvider(def)] : coreProviders); + const loaded = await MetaDataLoader.fromDirectory(join(dir, "project", "metaobjects"), { strict: true, registry }); + if (loaded.errors.length > 0) throw new Error(`fixture ${name} does not load: ${loaded.errors.map(String).join("; ")}`); + const input: Omit = {}; + for (const [key, file] of [["verify", "verify.json"], ["manifest", "hashes.json"], ["routes", "routes.json"]] as const) { + const v = readJson(dir, file); + if (v !== undefined) input[key] = v; + } + edit?.(input); + return buildDocsView({ root: loaded.root, ...input }); +} + +/** The view of a model written inline as canonical JSON. */ +export async function inlineView(model: unknown): Promise { + const loaded = await new MetaDataLoader().load([new InMemoryStringSource(JSON.stringify(model))]); + if (loaded.errors.length > 0) throw new Error(`model does not load: ${loaded.errors.map(String).join("; ")}`); + return buildDocsView({ root: loaded.root }); +} diff --git a/server/typescript/packages/metadata/src/docs-view/build.ts b/server/typescript/packages/metadata/src/docs-view/build.ts new file mode 100644 index 0000000000..ce9c701ba7 --- /dev/null +++ b/server/typescript/packages/metadata/src/docs-view/build.ts @@ -0,0 +1,698 @@ +// buildDocsView(): the docs view of a loaded model (`docs/features/docs-view.md`). +// +// It reads the model the loader already built and resolved, and re-derives none of it: +// +// ids and pages from the effective tree (`children()`), walked once in declaration order; +// inheritance an effective child whose `parent` is another node is inherited, and that +// parent is where it is declared; +// references the loader's own resolution (`MetaAttr.resolvedTarget` on every attribute +// it treats as a reference, `superData` for `extends`), so a provider's +// vocabulary gets its links with no change here; +// claims `@implementedBy`, through the resolver the requirement gate uses. +// +// Two optional inputs add what the model does not hold: the `meta verify --format json` +// payload (each requirement's verdict, digest and findings, the counts, the advisories), the +// generation manifest (which file came from which node) and the routes the run mounts. +// +// DETERMINISTIC: the same inputs give the same bytes (`serializeDocsView`), so every port can +// be held to one corpus and the file can sit under a drift gate. + +import type { MetaData } from "../shared/meta-data.js"; +import type { MetaAttr } from "../core/attr/meta-attr.js"; +import type { MetaRequirement } from "../core/requirement/meta-requirement.js"; +import { TYPE_FIELD, TYPE_OBJECT, TYPE_REQUIREMENT, TYPE_TEMPLATE } from "../shared/base-types.js"; +import { CHILD_REF_SEPARATOR, PACKAGE_SEPARATOR, TYPE_SUBTYPE_SEPARATOR } from "../shared/structural.js"; +import { DOC_ATTR_DESCRIPTION, DOC_ATTR_SUMMARY, DOC_ATTR_TITLE } from "../core/documentation/doc-constants.js"; +import { + REQUIREMENT_ATTR_COUNTEREXAMPLE, + REQUIREMENT_ATTR_STATEMENT, + REQUIREMENT_LEVEL_OBJECT, + REQUIREMENT_STATUSES, + REQUIREMENT_SUBTYPE_ARCHITECTURAL, + REQUIREMENT_SUBTYPE_FUNCTIONAL, +} from "../core/requirement/requirement-constants.js"; +import { effectiveRequirementPackage, resolveClaimTarget, resolveMember } from "../core/requirement/resolve-claim.js"; +import { effectivePackageOf, isRefBearingAttr, lookupCanonical, topLevelNodeOf } from "../naming-refs.js"; +import { + DOCS_VIEW_FORMAT, + type DocsView, + type DocsViewAdvisory, + type DocsViewAttr, + type DocsViewAttrValue, + type DocsViewClaim, + type DocsViewCounts, + type DocsViewDiagnostic, + type DocsViewFileGroup, + type DocsViewLink, + type DocsViewMember, + type DocsViewMemberGroup, + type DocsViewNode, + type DocsViewPackage, + type DocsViewRef, + type DocsViewReferrer, + type DocsViewRequirement, + type DocsViewRequirementLink, + type DocsViewRoute, + type DocsViewSlice, + type DocsViewStatusCount, +} from "./types.js"; + +export interface DocsViewInput { + /** The loaded, resolved model. */ + root: MetaData; + /** Parsed `meta verify --format json` output: `requirementLedger`, `requirementCounts` and + * `requirements.rows`. Without it the gate's verdicts, counts and findings are absent. */ + verify?: unknown; + /** The merged entries of `.metaobjects/.gen-state/.hashes/`, `path → { generatedBy, + * sourceNode }`. Without it no node lists files. */ + manifest?: unknown; + /** The routes the run mounts: `[{ node, method, path }]`, `node` a resolution key. */ + routes?: unknown; +} + +/** The gate's object-coverage finding: a concrete entity no requirement claims. */ +const CODE_OBJECT_UNCLAIMED = "WARN_REQUIREMENT_OBJECT_UNCLAIMED"; +const EXTENDS = "extends"; + +/** Code-unit order: the same in every runtime and locale, unlike `localeCompare`. */ +const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0); + +function isRecord(v: unknown): v is Record { + return typeof v === "object" && v !== null && !Array.isArray(v); +} +const str = (v: unknown): string => (typeof v === "string" ? v : ""); + +/** The directory of a package's pages. A package segment is an identifier, so `-root` (for + * the empty package) cannot be one. */ +export function docsPackageDir(pkg: string): string { + return pkg === "" ? "-root" : pkg.split(PACKAGE_SEPARATOR).join("/"); +} + +/** A page's file stem: the name, unless it would take the package page's `index.html` (on a + * case-insensitive file system too). */ +export function docsPageStem(name: string): string { + return name.toLowerCase() === "index" ? `${name}.node` : name; +} + +/** A node as walked: where it sits, and the ids and pages it gets. */ +interface Walked { + md: MetaData; + id: string; + /** The id before any type qualifier: what a dotted reference spells. */ + plain: string; + /** The top-level node it sits under (itself, at the top). */ + top: Walked; + parent: Walked | undefined; + /** The direct member of `top` it sits in (itself, for a direct member); undefined at the top. */ + direct: Walked | undefined; + /** The nearest requirement at or above it. */ + requirement: Walked | undefined; + order: number; + /** On the walk path that physically holds the node: the one place a reference to the node + * resolves to. */ + canonical: boolean; + /** The node that declares it, when it is inherited through `extends`. */ + declaredOn: MetaData | undefined; + anchor: string; + path: string; + children: Walked[]; + /** Requirement address (dotted requirement names), set on requirements. */ + address: string; +} + +class Builder { + readonly walked: Walked[] = []; + readonly tops: Walked[] = []; + readonly byId = new Map(); + /** Each node instance at its canonical walk position. */ + readonly canonical = new Map(); + /** Plain path → walked node (the first holder of a plain path). */ + readonly byPlain = new Map(); + readonly requirements: Walked[] = []; + + constructor(readonly root: MetaData) { + this.walk(); + } + + private walk(): void { + const topLevel = [...this.root.children()]; + const plainOf = (md: MetaData): string => { + const pkg = effectivePackageOf(md); + return pkg === "" ? md.name : `${pkg}${PACKAGE_SEPARATOR}${md.name}`; + }; + // Top-level nodes of different types may share a package and a name (an entity `Lead` and + // an application's page `Lead`). The object keeps the plain id, since every reference in the + // model names an object, else the first declared; each other one is qualified by its type. + const holder = new Map(); + for (const md of topLevel) { + const id = plainOf(md); + const held = holder.get(id); + if (held === undefined || (held.type !== TYPE_OBJECT && md.type === TYPE_OBJECT)) holder.set(id, md); + } + const seen = new Set(); + const visit = (md: MetaData, index: number, parent: Walked | undefined, reqPrefix: string): void => { + let id: string; + let plain: string; + if (parent === undefined) { + plain = md.name === "" ? `#${index}` : plainOf(md); + id = plain; + const held = holder.get(plain); + if (md.name !== "" && held !== md && held?.type !== md.type) id = qualified(plain, md); + } else { + plain = md.name === "" ? `${parent.plain}#${index}` : `${parent.plain}${CHILD_REF_SEPARATOR}${md.name}`; + id = md.name === "" ? `${parent.id}#${index}` : `${parent.id}${CHILD_REF_SEPARATOR}${md.name}`; + // The first sibling of a name keeps the plain id: it is the one a dotted reference + // resolves to. A later sibling of another type sharing the name is qualified by type. + if (md.name !== "" && seen.has(id)) id = qualified(id, md); + } + if (seen.has(id)) throw new Error(`docs view: two nodes share the id "${id}" — the model names two siblings alike`); + seen.add(id); + const isReq = md.type === TYPE_REQUIREMENT; + const address = isReq ? (reqPrefix === "" ? md.name : `${reqPrefix}${CHILD_REF_SEPARATOR}${md.name}`) : reqPrefix; + const inherited = parent !== undefined && md.parent !== parent.md; + const w: Walked = { + md, + id, + plain, + top: undefined as unknown as Walked, + parent, + direct: undefined, + requirement: undefined, + order: index, + canonical: parent === undefined ? true : parent.canonical && !inherited, + declaredOn: inherited ? md.parent : undefined, + anchor: "", + path: "", + children: [], + address: isReq ? address : "", + }; + w.top = parent === undefined ? w : parent.top; + w.direct = parent === undefined ? undefined : parent.parent === undefined ? w : parent.direct; + w.requirement = isReq ? w : parent?.requirement; + if (w.direct === w) w.anchor = memberAnchor(md, index); + this.walked.push(w); + this.byId.set(id, w); + if (!this.byPlain.has(plain)) this.byPlain.set(plain, w); + if (w.canonical) this.canonical.set(md, w); + if (parent === undefined) this.tops.push(w); + else parent.children.push(w); + if (isReq) this.requirements.push(w); + md.children().forEach((c, i) => visit(c, i, w, address)); + }; + topLevel.forEach((md, i) => visit(md, i, undefined, "")); + for (const w of this.walked) w.path = this.pathOf(w); + } + + private pathOf(w: Walked): string { + if (w.requirement !== undefined) { + const r = w.requirement; + return `requirements/${docsPackageDir(effectivePackageOf(r.top.md))}/${docsPageStem(r.address)}.html`; + } + const top = w.top; + const qualifier = `[${top.md.type}${TYPE_SUBTYPE_SEPARATOR}${top.md.subType}]`; + const typed = top.id.endsWith(qualifier) ? `.${top.md.type}-${top.md.subType}` : ""; + const page = `model/${docsPackageDir(effectivePackageOf(top.md))}/${docsPageStem(top.md.name)}${typed}.html`; + return w.direct === undefined ? page : `${page}#${w.direct.anchor}`; + } + + link(w: Walked): DocsViewLink { + const req = w.requirement === w ? w : undefined; + const label = + req !== undefined + ? str(w.md.attr(DOC_ATTR_TITLE)) || w.md.name + : w === w.top + ? w.md.name + : `${w.top.md.name}.${w.id.slice(w.top.id.length + 1)}`; + return { label, id: w.id, path: w.path, kind: `${w.md.type}${TYPE_SUBTYPE_SEPARATOR}${w.md.subType}`, unresolved: false }; + } + + linkTo(md: MetaData | undefined, text: string): DocsViewLink { + const w = md === undefined ? undefined : this.canonical.get(md); + return w !== undefined ? this.link(w) : unresolved(text); + } + + /** The link a reference value lands on: the member its dotted tail names, else the owner the + * loader bound. */ + refLink(owner: MetaData | undefined, value: string): DocsViewLink { + if (owner === undefined) return unresolved(value); + const exact = value.includes(CHILD_REF_SEPARATOR) ? lookupCanonical(this.root, value) : undefined; + const target = exact !== undefined && topLevelNodeOf(exact) === owner ? exact : owner; + return this.linkTo(target, value); + } +} + +function qualified(id: string, md: MetaData): string { + return `${id}[${md.type}${TYPE_SUBTYPE_SEPARATOR}${md.subType}]`; +} + +/** A direct member's anchor: `m-` for a field, `m--` for anything else (siblings + * of different types may share a name), `m--` for one with no name. */ +function memberAnchor(md: MetaData, order: number): string { + if (md.name === "") return `m-${md.type}-${order}`; + return md.type === TYPE_FIELD ? `m-${md.name}` : `m-${md.type}-${md.name}`; +} + +function unresolved(text: string): DocsViewLink { + return { label: text, id: "", path: "", kind: "", unresolved: true }; +} + +/** The attribute node that declares `name` for `md`: its own, else the nearest `extends` + * ancestor's — where the loader recorded what the reference resolved to. */ +function declaringAttr(md: MetaData, name: string): MetaAttr | undefined { + const seen = new Set(); + for (let n: MetaData | undefined = md; n !== undefined && !seen.has(n); n = n.superData) { + seen.add(n); + // ADR-0039: own — locating the layer that declares the attr, walking the super chain. + const a = n.ownMetaAttr(name); + if (a !== undefined) return a; + } + return undefined; +} + +/** A value with every object's keys in code-unit order, as the canonical serializer writes + * them: a map attribute's key order must not depend on a port's map type. */ +function canonicalValue(v: unknown): unknown { + if (Array.isArray(v)) return v.map(canonicalValue); + if (!isRecord(v)) return v; + const out: Record = {}; + for (const k of Object.keys(v).sort(byCodeUnit)) out[k] = canonicalValue(v[k]); + return out; +} + +function textOf(v: unknown): string { + return typeof v === "string" ? v : JSON.stringify(v) ?? ""; +} + +/** A node's effective attributes, by name, each value linked where the loader resolved it. */ +function attrsOf(b: Builder, md: MetaData): { attrs: DocsViewAttr[]; refs: { attr: string; target: DocsViewLink }[] } { + const attrs: DocsViewAttr[] = []; + const refs: { attr: string; target: DocsViewLink }[] = []; + const map = md.attrs(); + for (const name of [...map.keys()].sort(byCodeUnit)) { + const value = canonicalValue(map.get(name)); + const isRef = isRefBearingAttr(md, name); + const resolved = isRef ? declaringAttr(md, name)?.resolvedTarget : undefined; + const values: DocsViewAttrValue[] = []; + if (typeof value === "string") { + const link = isRef ? b.refLink(Array.isArray(resolved) ? undefined : (resolved as MetaData | undefined), value) : null; + values.push({ text: value, link }); + if (link !== null && !link.unresolved) refs.push({ attr: name, target: link }); + } else if (Array.isArray(value) && value.every((x) => typeof x === "string")) { + (value as string[]).forEach((item, i) => { + const owner = Array.isArray(resolved) ? (resolved as readonly (MetaData | undefined)[])[i] : undefined; + const link = isRef ? b.refLink(owner, item) : null; + values.push({ text: item, link }); + if (link !== null && !link.unresolved) refs.push({ attr: name, target: link }); + }); + } else { + values.push({ text: textOf(value), link: null }); + } + attrs.push({ name, value: value ?? null, values }); + } + return { attrs, refs }; +} + +function groupMembers(members: DocsViewMember[]): DocsViewMemberGroup[] { + const groups = new Map(); + for (const m of members) { + let g = groups.get(m.type); + if (g === undefined) { + g = { type: m.type, count: 0, members: [] }; + groups.set(m.type, g); + } + g.count++; + g.members.push(m); + } + return [...groups.values()]; +} + +function statusCounts(statuses: readonly string[]): DocsViewStatusCount[] { + return REQUIREMENT_STATUSES.map((status) => ({ status, count: statuses.filter((s) => s === status).length })); +} + +/** Split `@implementedBy`'s `owner.member.path` after the package: the gate's own split. */ +function splitMemberRef(ref: string): { owner: string; path: string[] } { + const pkgEnd = ref.lastIndexOf(PACKAGE_SEPARATOR); + const from = pkgEnd === -1 ? 0 : pkgEnd + PACKAGE_SEPARATOR.length; + const dot = ref.indexOf(CHILD_REF_SEPARATOR, from); + if (dot === -1) return { owner: ref, path: [] }; + return { owner: ref.slice(0, dot), path: ref.slice(dot + 1).split(CHILD_REF_SEPARATOR) }; +} + +interface LedgerRow { + qualifiedPath: string; + digest: string; + verdict: string; + diagnostics: DocsViewDiagnostic[]; + supersededBy: { ref: string; resolves: boolean; target: string } | undefined; +} + +function ledgerRows(verify: unknown): Map | undefined { + if (!isRecord(verify) || !Array.isArray(verify.requirementLedger)) return undefined; + const out = new Map(); + for (const raw of verify.requirementLedger) { + if (!isRecord(raw) || typeof raw.qualifiedPath !== "string") continue; + const sup = isRecord(raw.supersededBy) && typeof raw.supersededBy.ref === "string" ? raw.supersededBy : undefined; + const row: LedgerRow = { + qualifiedPath: raw.qualifiedPath, + digest: str(raw.digest), + verdict: str(raw.verdict), + diagnostics: Array.isArray(raw.diagnostics) + ? raw.diagnostics.filter(isRecord).map((d) => ({ code: str(d.code), severity: str(d.severity), source: str(d.source), message: str(d.message) })) + : [], + supersededBy: sup !== undefined ? { ref: str(sup.ref), resolves: sup.resolves === true, target: str(sup.target) } : undefined, + }; + out.set(row.qualifiedPath, [...(out.get(row.qualifiedPath) ?? []), row]); + } + return out; +} + +/** Build the docs view of a loaded model. A missing or malformed optional input only leaves + * its part out. */ +export function buildDocsView(input: DocsViewInput): DocsView { + const b = new Builder(input.root); + const ledger = ledgerRows(input.verify); + const hasVerify = ledger !== undefined; + + // ── Requirements: claims first, since nodes and members list them. ── + const claimsOn = new Map(); + const reqLinks = new Map(); + const reqTargets = new Map(); + for (const r of b.requirements) { + const req = r.md as MetaRequirement; + const referrerPkg = effectiveRequirementPackage(req); + const links: DocsViewRequirementLink[] = []; + const targets: Walked[] = []; + for (const ref of req.implementedBy()) { + const { owner, path } = splitMemberRef(ref); + const node = resolveClaimTarget(b.root, owner, referrerPkg); + const member = node !== undefined && path.length > 0 ? resolveMember(node, path) : node; + const key = node === undefined ? "" : path.length === 0 ? node.resolutionKey() : `${node.resolutionKey()}${CHILD_REF_SEPARATOR}${path.join(CHILD_REF_SEPARATOR)}`; + const w = member !== undefined ? b.byPlain.get(key) : undefined; + if (w === undefined) { + links.push({ ref, resolves: false, target: unresolved(ref) }); + continue; + } + links.push({ ref, resolves: true, target: b.link(w) }); + targets.push(w); + const claim: DocsViewClaim = { + requirement: b.link(r), + member: w === w.top ? "" : w.id.slice(w.top.id.length + 1), + status: str(req.status()), + level: req.level() ?? null, + }; + // The claim is on the top-level node and on every member down to the one it names. + for (let x: Walked | undefined = w; x !== undefined; x = x.parent) claimsOn.set(x, [...(claimsOn.get(x) ?? []), claim]); + } + reqLinks.set(r, links); + reqTargets.set(r, targets); + } + + // ── Files and routes. ── + const filesOf = new Map>(); + if (isRecord(input.manifest)) { + for (const [path, entry] of Object.entries(input.manifest)) { + if (!isRecord(entry) || typeof entry.sourceNode !== "string") continue; + const w = b.byPlain.get(entry.sourceNode); + if (w === undefined) continue; + const by = filesOf.get(w.top) ?? new Map(); + const gen = str(entry.generatedBy); + by.set(gen, [...(by.get(gen) ?? []), path]); + filesOf.set(w.top, by); + } + } + const routesOf = new Map>(); + if (Array.isArray(input.routes)) { + for (const r of input.routes) { + if (!isRecord(r) || typeof r.node !== "string" || typeof r.method !== "string" || typeof r.path !== "string") continue; + const w = b.byPlain.get(r.node); + if (w === undefined) continue; + const route = { method: r.method.toUpperCase(), path: r.path }; + const m = routesOf.get(w.top) ?? new Map(); + m.set(`${route.path}\u0000${route.method}`, route); + routesOf.set(w.top, m); + } + } + + // ── Advisories. ── + const advisories: DocsViewAdvisory[] = []; + if (hasVerify && isRecord(input.verify) && isRecord(input.verify.requirements) && Array.isArray(input.verify.requirements.rows)) { + for (const d of input.verify.requirements.rows) { + if (!isRecord(d)) continue; + const node = str(d.node); + const subject = node === "" ? null : b.byPlain.has(node) ? b.link(b.byPlain.get(node)!.top) : unresolved(node); + advisories.push({ code: str(d.code), path: str(d.path), subject, severity: str(d.severity), source: str(d.source), message: str(d.message) }); + } + } + const unclaimedIds = new Set(advisories.filter((a) => a.code === CODE_OBJECT_UNCLAIMED && a.subject !== null).map((a) => a.subject!.id)); + + // ── Members and references. ── + const refsFrom = new Map(); + const member = (w: Walked): DocsViewMember => { + const { attrs, refs } = attrsOf(b, w.md); + const ext = w.md.superData !== undefined || w.md.superRef !== undefined ? b.linkTo(w.md.superData, w.md.superRef ?? "") : null; + const own: DocsViewRef[] = [ + ...(ext !== null && !ext.unresolved ? [{ attr: EXTENDS, via: b.link(w), target: ext }] : []), + ...refs.map((r) => ({ attr: r.attr, via: b.link(w), target: r.target })), + ]; + refsFrom.set(w, own); + return { + id: w.id, + name: w.md.name, + type: w.md.type, + subType: w.md.subType, + order: w.order, + anchor: w.anchor, + path: w.path, + abstract: w.md.isAbstract === true, + isArray: w.md.resolvedIsArray(), + extends: ext, + declaredOn: w.declaredOn !== undefined ? b.linkTo(w.declaredOn, w.declaredOn.name) : null, + attrs, + refs: own, + claims: claimsOn.get(w) ?? [], + memberGroups: groupMembers(w.children.map(member)), + }; + }; + + const nodes: DocsViewNode[] = []; + const nodeRefs = new Map(); + for (const t of b.tops) { + const { attrs, refs } = attrsOf(b, t.md); + const ext = t.md.superData !== undefined || t.md.superRef !== undefined ? b.linkTo(t.md.superData, t.md.superRef ?? "") : null; + const memberGroups = groupMembers(t.children.map(member)); + const all: DocsViewRef[] = [ + ...(ext !== null && !ext.unresolved ? [{ attr: EXTENDS, via: null, target: ext }] : []), + ...refs.map((r) => ({ attr: r.attr, via: null, target: r.target })), + ]; + const below = (w: Walked): void => { + for (const c of w.children) { + all.push(...(refsFrom.get(c) ?? [])); + below(c); + } + }; + below(t); + nodeRefs.set(t, all); + const files: DocsViewFileGroup[] = [...(filesOf.get(t) ?? new Map()).entries()] + .sort(([a], [b2]) => byCodeUnit(a, b2)) + .map(([generatedBy, paths]) => ({ generatedBy, paths: [...paths].sort(byCodeUnit) })); + const routes = [...(routesOf.get(t) ?? new Map()).entries()].sort(([a], [b2]) => byCodeUnit(a, b2)).map(([, r]) => r); + nodes.push({ + id: t.id, + name: t.md.name, + package: effectivePackageOf(t.md), + type: t.md.type, + subType: t.md.subType, + order: t.order, + path: t.path, + title: str(t.md.attr(DOC_ATTR_TITLE)), + description: str(t.md.attr(DOC_ATTR_DESCRIPTION)), + summary: str(t.md.attr(DOC_ATTR_SUMMARY)), + abstract: t.md.isAbstract === true, + extends: ext, + attrs, + memberGroups, + refs: all, + referencedBy: [], + claims: claimsOn.get(t) ?? [], + files, + routes, + unclaimed: unclaimedIds.has(t.id), + counts: { members: t.children.length, refs: all.length, referencedBy: 0, claims: (claimsOn.get(t) ?? []).length, files: files.reduce((a, g) => a + g.paths.length, 0), routes: routes.length }, + }); + } + + // referencedBy: every reference into a top-level node (or a member of it) from another one. + const nodeById = new Map(nodes.map((n) => [n.id, n] as const)); + const incoming = new Map>(); + for (const t of b.tops) { + for (const r of nodeRefs.get(t) ?? []) { + const target = b.byId.get(r.target.id); + if (target === undefined || target.top === t) continue; + const referrer: DocsViewReferrer = { attr: r.attr, from: b.link(t), via: r.via, target: r.target }; + const key = [t.id, r.attr, r.via?.id ?? "", r.target.id].join("\u0000"); + const m = incoming.get(target.top.id) ?? new Map(); + m.set(key, referrer); + incoming.set(target.top.id, m); + } + } + for (const [id, m] of incoming) { + const n = nodeById.get(id); + if (n === undefined) continue; + n.referencedBy = [...m.entries()].sort(([a], [b2]) => byCodeUnit(a, b2)).map(([, r]) => r); + n.counts.referencedBy = n.referencedBy.length; + } + nodes.sort((a, c) => byCodeUnit(a.id, c.id)); + + // ── The requirement list, flat, in document order. ── + const reqChildren = new Map(); + const reqParent = (r: Walked): Walked | undefined => r.parent?.requirement; + for (const r of b.requirements) { + const p = reqParent(r); + if (p !== undefined) reqChildren.set(p, [...(reqChildren.get(p) ?? []), r]); + } + const subtree = (r: Walked): Walked[] => [r, ...(reqChildren.get(r) ?? []).flatMap(subtree)]; + const requirements: DocsViewRequirement[] = b.requirements.map((r) => { + const req = r.md as MetaRequirement; + const pkg = effectiveRequirementPackage(req); + const qualifiedPath = pkg === "" ? r.address : `${pkg}${PACKAGE_SEPARATOR}${r.address}`; + const row = ledger?.get(qualifiedPath)?.shift(); + const chain: Walked[] = []; + for (let p = reqParent(r); p !== undefined; p = reqParent(p)) chain.unshift(p); + const sub = subtree(r); + const linked = sub.filter((x) => { + const level = (x.md as MetaRequirement).level(); + return (level ?? 0) >= REQUIREMENT_LEVEL_OBJECT || (level === undefined && (x.md as MetaRequirement).implementedBy().length > 0); + }); + const counted = linked.length > 0 ? linked : [r]; + const statuses = counted.map((x) => str((x.md as MetaRequirement).status())).filter((s) => s !== ""); + const targets = [...new Map(sub.flatMap((x) => reqTargets.get(x) ?? []).map((w) => [w.top.id, w.top] as const)).values()].sort((a, c) => byCodeUnit(a.id, c.id)); + const children = reqChildren.get(r) ?? []; + const sup = row?.supersededBy; + const supTarget = sup?.target !== undefined && sup.target !== "" ? b.requirements.find((x) => { + const p = effectiveRequirementPackage(x.md); + return (p === "" ? x.address : `${p}${PACKAGE_SEPARATOR}${x.address}`) === sup.target; + }) : undefined; + return { + id: r.id, + name: r.md.name, + label: b.link(r).label, + path: r.path, + address: r.address, + package: pkg, + qualifiedPath, + subType: r.md.subType, + level: req.level() ?? null, + status: str(req.status()), + disposition: str(req.disposition()), + statement: str(req.attr(REQUIREMENT_ATTR_STATEMENT)), + counterexample: str(req.attr(REQUIREMENT_ATTR_COUNTEREXAMPLE)), + title: str(req.attr(DOC_ATTR_TITLE)), + description: str(req.attr(DOC_ATTR_DESCRIPTION)), + trackedBy: req.trackedBy(), + depth: chain.length, + parent: chain.length > 0 ? b.link(chain[chain.length - 1]!) : null, + breadcrumbs: chain.map((x) => b.link(x)), + children: children.map((x) => b.link(x)), + implementedBy: reqLinks.get(r) ?? [], + supersededBy: sup === undefined ? null : { ref: sup.ref, resolves: sup.resolves, target: supTarget !== undefined ? b.link(supTarget) : unresolved(sup.ref) }, + inLedger: row !== undefined, + verdict: row?.verdict ?? "", + digest: row?.digest ?? "", + diagnostics: row?.diagnostics ?? [], + rollup: statusCounts(statuses), + rollupTotal: statuses.length, + belowCount: sub.length - 1, + childCount: children.length, + targets: targets.map((w) => b.link(w)), + targetCount: targets.length, + }; + }); + + // ── Packages, counts, slices. ── + const packages: DocsViewPackage[] = [...new Set(nodes.map((n) => n.package))].sort(byCodeUnit).map((name) => { + const inPkg = nodes.filter((n) => n.package === name); + const groups = new Map(); + for (const n of inPkg) { + const key = `${n.type}${TYPE_SUBTYPE_SEPARATOR}${n.subType}`; + const g = groups.get(key) ?? { type: n.type, subType: n.subType, count: 0, nodes: [] }; + g.count++; + g.nodes.push(b.link(b.byId.get(n.id)!)); + groups.set(key, g); + } + return { name, count: inPkg.length, groups: [...groups.entries()].sort(([a], [c]) => byCodeUnit(a, c)).map(([, g]) => g) }; + }); + + const verify = isRecord(input.verify) ? input.verify : undefined; + const vc = verify !== undefined && isRecord(verify.requirementCounts) ? verify.requirementCounts : undefined; + const num = (k: string): number | undefined => (vc !== undefined && typeof vc[k] === "number" ? (vc[k] as number) : undefined); + const allFiles = new Set(nodes.flatMap((n) => n.files.flatMap((g) => g.paths))); + const counts: DocsViewCounts = { + nodes: nodes.length, + packages: packages.length, + requirements: requirements.length, + functional: requirements.filter((r) => r.subType === REQUIREMENT_SUBTYPE_FUNCTIONAL).length, + architectural: requirements.filter((r) => r.subType === REQUIREMENT_SUBTYPE_ARCHITECTURAL).length, + byStatus: statusCounts(requirements.map((r) => r.status)), + claims: requirements.reduce((a, r) => a + r.implementedBy.filter((l) => l.resolves).length, 0), + files: allFiles.size, + routes: nodes.reduce((a, n) => a + n.routes.length, 0), + undecided: num("undecided") ?? 0, + coverageMeasured: num("entitiesTotal") !== undefined, + entitiesClaimed: num("entitiesClaimed") ?? 0, + entitiesTotal: num("entitiesTotal") ?? 0, + }; + + return { + format: DOCS_VIEW_FORMAT, + sources: { requirements: hasVerify, files: isRecord(input.manifest), routes: Array.isArray(input.routes) }, + counts, + packages, + nodes, + requirements, + advisories, + slices: slicesOf(b, nodes, requirements), + }; +} + +function slicesOf(b: Builder, nodes: DocsViewNode[], requirements: DocsViewRequirement[]): DocsViewSlice[] { + const slices: DocsViewSlice[] = []; + const sorted = (s: Iterable): string[] => [...new Set(s)].sort(byCodeUnit); + for (const pkg of sorted(nodes.map((n) => n.package))) { + slices.push({ id: `package:${pkg}`, kind: "package", anchor: pkg, nodes: sorted(nodes.filter((n) => n.package === pkg).map((n) => n.id)) }); + } + // A requirement with requirements below it: the subtree, each node it claims, and the + // top-level node holding a claimed member. + const byId = new Map(requirements.map((r) => [r.id, r] as const)); + for (const r of requirements) { + if (r.childCount === 0) continue; + const ids: string[] = []; + const visit = (x: DocsViewRequirement): void => { + ids.push(x.id); + for (const l of x.implementedBy) { + if (!l.resolves) continue; + ids.push(l.target.id); + const w = b.byId.get(l.target.id); + if (w !== undefined) ids.push(w.top.id); + } + for (const c of x.children) { + const child = byId.get(c.id); + if (child !== undefined) visit(child); + } + }; + visit(r); + slices.push({ id: `requirement:${r.id}`, kind: "requirement", anchor: r.id, nodes: sorted(ids) }); + } + // A template: itself and what its own attributes reference. + for (const n of nodes) { + if (n.type !== TYPE_TEMPLATE) continue; + const ids = [n.id, ...n.refs.filter((r) => r.via === null).map((r) => b.byId.get(r.target.id)?.top.id ?? r.target.id)]; + slices.push({ id: `prompt:${n.id}`, kind: "prompt", anchor: n.id, nodes: sorted(ids) }); + } + return slices.sort((a, c) => byCodeUnit(a.id, c.id)); +} + +/** The file's bytes: two-space JSON and one trailing newline. */ +export function serializeDocsView(view: DocsView): string { + return JSON.stringify(view, null, 2) + "\n"; +} diff --git a/server/typescript/packages/metadata/src/docs-view/index.ts b/server/typescript/packages/metadata/src/docs-view/index.ts new file mode 100644 index 0000000000..cda70ffa46 --- /dev/null +++ b/server/typescript/packages/metadata/src/docs-view/index.ts @@ -0,0 +1,3 @@ +export { buildDocsView, serializeDocsView, docsPackageDir, docsPageStem } from "./build.js"; +export type { DocsViewInput } from "./build.js"; +export * from "./types.js"; diff --git a/server/typescript/packages/metadata/src/docs-view/types.ts b/server/typescript/packages/metadata/src/docs-view/types.ts new file mode 100644 index 0000000000..4eae8cc267 --- /dev/null +++ b/server/typescript/packages/metadata/src/docs-view/types.ts @@ -0,0 +1,298 @@ +// The docs view: one port-neutral document per build, the facts every documentation page reads. +// +// Built from the LOADED, RESOLVED model (see build.ts), it holds facts only: no HTML, no +// Markdown, no sentences. Where a page has to choose, the view gives it a boolean or a count. +// Every key is always present (an absent fact is "", false, 0, [] or null), and the key order +// below is the order on disk, so every port writes the same bytes for the same model. The +// contract is `docs/features/docs-view.md`, pinned by `fixtures/explorer-conformance/`. + +/** Bumped when a field changes meaning or is removed. */ +export const DOCS_VIEW_FORMAT = "metaobjects-docs-view/1"; + +/** A pointer to a node of the view, or to a reference that did not resolve. */ +export interface DocsViewLink { + /** What a page prints for the target: a top-level node's name, a requirement's title (else + * its name), `.` for a member. The text as written when + * unresolved. */ + label: string; + /** The target's id; "" when unresolved. */ + id: string; + /** The site-relative page the target lands on, with `#` for a member; "" when + * unresolved. */ + path: string; + /** `.` of the target; "" when unresolved. */ + kind: string; + unresolved: boolean; +} + +/** One value of an attribute: its text, and the node it names when the loader resolved it. */ +export interface DocsViewAttrValue { + text: string; + /** Set only on an attribute the loader resolves as a reference. */ + link: DocsViewLink | null; +} + +export interface DocsViewAttr { + /** Without the `@`. */ + name: string; + /** The effective value, as the canonical JSON states it (an object's keys in code-unit order). */ + value: unknown; + /** One per element of a list of strings; otherwise one, a string verbatim or any other value + * as compact JSON. */ + values: DocsViewAttrValue[]; +} + +/** A reference the loader resolved, from this node or one of its members. */ +export interface DocsViewRef { + /** The attribute that carries it, without the `@`, or `extends`. */ + attr: string; + /** The member that carries it; null when the node itself does. */ + via: DocsViewLink | null; + target: DocsViewLink; +} + +/** A reference into this node or one of its members, from another top-level node. */ +export interface DocsViewReferrer { + attr: string; + /** The top-level node the reference sits in. */ + from: DocsViewLink; + via: DocsViewLink | null; + target: DocsViewLink; +} + +/** A requirement's `@implementedBy` link onto this node or one of its members. */ +export interface DocsViewClaim { + requirement: DocsViewLink; + /** The dotted member path below the top-level node; "" for the whole node. */ + member: string; + status: string; + level: number | null; +} + +export interface DocsViewFileGroup { + generatedBy: string; + /** Project-relative, sorted. */ + paths: string[]; +} + +export interface DocsViewRoute { + method: string; + /** The mounted path, with the project's `apiPrefix`. */ + path: string; +} + +/** The members of one type (every subtype of it), in declaration order. Groups are ordered by + * their first member's declaration. */ +export interface DocsViewMemberGroup { + type: string; + count: number; + members: DocsViewMember[]; +} + +/** A node nested in a top-level node, at any depth. */ +export interface DocsViewMember { + id: string; + name: string; + type: string; + subType: string; + /** Its position among its siblings in the effective tree (0-based). */ + order: number; + /** On a direct member of a top-level node, the id its row carries; "" deeper down. */ + anchor: string; + /** Where a link to it lands. */ + path: string; + abstract: boolean; + isArray: boolean; + extends: DocsViewLink | null; + /** When the member is inherited through `extends`: the node that declares it. */ + declaredOn: DocsViewLink | null; + attrs: DocsViewAttr[]; + /** The references its own attributes and `extends` carry. */ + refs: DocsViewRef[]; + /** The claims on it or on anything nested in it. */ + claims: DocsViewClaim[]; + memberGroups: DocsViewMemberGroup[]; +} + +export interface DocsViewNodeCounts { + members: number; + refs: number; + referencedBy: number; + claims: number; + files: number; + routes: number; +} + +/** A top-level node of any type. */ +export interface DocsViewNode { + id: string; + name: string; + package: string; + type: string; + subType: string; + /** Its position among the top-level nodes, in declaration order (0-based). */ + order: number; + /** Its page. */ + path: string; + title: string; + description: string; + summary: string; + abstract: boolean; + extends: DocsViewLink | null; + attrs: DocsViewAttr[]; + memberGroups: DocsViewMemberGroup[]; + /** Every reference from it or any of its members, in walk order. */ + refs: DocsViewRef[]; + referencedBy: DocsViewReferrer[]; + claims: DocsViewClaim[]; + files: DocsViewFileGroup[]; + routes: DocsViewRoute[]; + /** The requirement gate reports that no requirement claims this entity. */ + unclaimed: boolean; + counts: DocsViewNodeCounts; +} + +export interface DocsViewStatusCount { + status: string; + count: number; +} + +export interface DocsViewRequirementLink { + /** As authored. */ + ref: string; + resolves: boolean; + /** Unresolved when `resolves` is false. */ + target: DocsViewLink; +} + +export interface DocsViewDiagnostic { + code: string; + severity: string; + /** "gate" can fail the build; "lint" never can. */ + source: string; + message: string; +} + +/** One requirement, at any depth, in document order. */ +export interface DocsViewRequirement { + id: string; + name: string; + label: string; + /** Its page. */ + path: string; + /** The dotted path of requirement names every `verify` diagnostic prints. */ + address: string; + package: string; + /** `::
`, or the address with no package. */ + qualifiedPath: string; + subType: string; + level: number | null; + status: string; + disposition: string; + statement: string; + counterexample: string; + title: string; + description: string; + trackedBy: string[]; + /** The number of requirements above it. */ + depth: number; + parent: DocsViewLink | null; + /** The requirements above it, outermost first. */ + breadcrumbs: DocsViewLink[]; + children: DocsViewLink[]; + implementedBy: DocsViewRequirementLink[]; + /** As the gate resolved it; null without one, or without a verify payload. */ + supersededBy: DocsViewRequirementLink | null; + /** The verify payload carried a ledger row for it. */ + inLedger: boolean; + /** "clean" | "warn" | "error", from the gate; "" without a ledger row. */ + verdict: string; + digest: string; + diagnostics: DocsViewDiagnostic[]; + /** The declared statuses of the requirements below that name the model (level 4 or 5, or no + * level and an `@implementedBy`), each status with its count. A requirement with none such + * below counts itself. */ + rollup: DocsViewStatusCount[]; + rollupTotal: number; + belowCount: number; + childCount: number; + /** The top-level nodes it and the requirements below it claim, sorted by id. */ + targets: DocsViewLink[]; + targetCount: number; +} + +export interface DocsViewTypeGroup { + type: string; + subType: string; + count: number; + nodes: DocsViewLink[]; +} + +export interface DocsViewPackage { + /** "" for nodes with no package. */ + name: string; + count: number; + groups: DocsViewTypeGroup[]; +} + +export interface DocsViewCounts { + nodes: number; + packages: number; + requirements: number; + functional: number; + architectural: number; + byStatus: DocsViewStatusCount[]; + claims: number; + files: number; + routes: number; + /** From the verify payload; 0 without one. */ + undecided: number; + /** The gate measured entity coverage. */ + coverageMeasured: boolean; + entitiesClaimed: number; + entitiesTotal: number; +} + +/** Which optional inputs the build read. */ +export interface DocsViewSources { + requirements: boolean; + files: boolean; + routes: boolean; +} + +/** One finding `meta verify` reported. */ +export interface DocsViewAdvisory { + code: string; + /** The requirement's address; "" when the subject is not a requirement. */ + path: string; + /** The node the finding is about when it is not a requirement. */ + subject: DocsViewLink | null; + severity: string; + source: string; + message: string; +} + +export type DocsViewSliceKind = "package" | "prompt" | "requirement"; + +/** A named set of nodes the map opens on. */ +export interface DocsViewSlice { + /** `:`. */ + id: string; + kind: DocsViewSliceKind; + /** The package, prompt id or requirement id it is derived from. */ + anchor: string; + /** Node ids, sorted. */ + nodes: string[]; +} + +export interface DocsView { + format: typeof DOCS_VIEW_FORMAT; + sources: DocsViewSources; + counts: DocsViewCounts; + packages: DocsViewPackage[]; + /** Every top-level node, sorted by id. */ + nodes: DocsViewNode[]; + requirements: DocsViewRequirement[]; + advisories: DocsViewAdvisory[]; + slices: DocsViewSlice[]; +} diff --git a/server/typescript/packages/metadata/src/index.ts b/server/typescript/packages/metadata/src/index.ts index c7fdde7318..861384811d 100644 --- a/server/typescript/packages/metadata/src/index.ts +++ b/server/typescript/packages/metadata/src/index.ts @@ -524,3 +524,6 @@ export { export type { AttrContradiction } from "./attr-contradictions.js"; export { rewriteDocument } from "./vocabulary-rewrite.js"; export type { RewriteResult, RewriteChange, RewriteRefusal, RewriteOpts } from "./vocabulary-rewrite.js"; + +// The docs view: the port-neutral facts every documentation page reads (docs/features/docs-view.md). +export * from "./docs-view/index.js"; diff --git a/server/typescript/packages/metadata/test/docs-view-conformance.test.ts b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts new file mode 100644 index 0000000000..c05b3ebd20 --- /dev/null +++ b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts @@ -0,0 +1,197 @@ +// The docs view corpus (`fixtures/explorer-conformance/`, `docs/features/docs-view.md`): each +// fixture's project is loaded, its committed optional inputs are read, and `buildDocsView` +// must reproduce the fixture's `expected.json` byte for byte. Every port that builds the docs +// view is held to the same files. +// +// A fixture may carry `provider.json`, a data-driven provider definition for vocabulary the +// core does not register. Its references must come out linked with no change to the builder: +// the view reads the loader's resolution, never a list of attribute names. +// +// Regenerate after a deliberate change: `UPDATE_DOCS_VIEW=1 bun test test/docs-view-conformance.test.ts`. +import { describe, expect, test } from "bun:test"; +import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { join, resolve } from "node:path"; +import { + InMemoryStringSource, + MetaData, + MetaDataLoader, + applyProviderDefinition, + buildDocsView, + composeRegistry, + coreProviders, + serializeDocsView, + type DocsView, + type FactoryMap, + type MetaDataTypeProvider, + type ProviderDefinition, +} from "../src/index.js"; + +/** A node of a type the fixture's provider.json declares: no behaviour beyond MetaData's own. */ +class FixtureNode extends MetaData {} + +const CORPUS = resolve(import.meta.dir, "../../../../../fixtures/explorer-conformance"); +const UPDATE = process.env.UPDATE_DOCS_VIEW === "1"; + +const fixtures = readdirSync(CORPUS, { withFileTypes: true }) + .filter((d) => d.isDirectory()) + .map((d) => d.name) + .sort(); + +function readJson(dir: string, name: string): unknown { + const p = join(dir, name); + return existsSync(p) ? (JSON.parse(readFileSync(p, "utf8")) as unknown) : undefined; +} + +/** A provider for a fixture's `provider.json`: every type it declares is a plain node. */ +export function fixtureProvider(def: ProviderDefinition): MetaDataTypeProvider { + const factories: FactoryMap = {}; + for (const t of def.types ?? []) factories[`${t.type}.${t.subType}`] = (id, name) => new FixtureNode(id, name); + return { + id: def.provider, + dependencies: ["metaobjects-core-types"], + registerTypes: (registry) => applyProviderDefinition(registry, def, factories), + }; +} + +async function viewOf(name: string): Promise { + const dir = join(CORPUS, name); + const def = readJson(dir, "provider.json") as ProviderDefinition | undefined; + const registry = composeRegistry(def !== undefined ? [...coreProviders, fixtureProvider(def)] : coreProviders); + const loaded = await MetaDataLoader.fromDirectory(join(dir, "project", "metaobjects"), { strict: true, registry }); + expect(loaded.errors.map(String)).toEqual([]); + const verify = readJson(dir, "verify.json"); + const manifest = readJson(dir, "hashes.json"); + const routes = readJson(dir, "routes.json"); + return buildDocsView({ + root: loaded.root, + ...(verify !== undefined ? { verify } : {}), + ...(manifest !== undefined ? { manifest } : {}), + ...(routes !== undefined ? { routes } : {}), + }); +} + +describe("docs view corpus", () => { + test("the corpus holds the fixtures the README describes", () => { + expect(fixtures).toEqual(["crm", "shop"]); + }); + + for (const name of fixtures) { + test(`${name}: buildDocsView reproduces expected.json`, async () => { + const actual = serializeDocsView(await viewOf(name)); + const file = join(CORPUS, name, "expected.json"); + if (UPDATE) writeFileSync(file, actual); + expect(actual).toBe(readFileSync(file, "utf8")); + }); + } +}); + +describe("buildDocsView over the corpus", () => { + test("ids, pages and inheritance come from the loaded model", async () => { + const v = await viewOf("shop"); + const customer = v.nodes.find((n) => n.id === "acme::shop::Customer")!; + expect(customer.path).toBe("model/acme/shop/Customer.html"); + expect(customer.extends?.id).toBe("acme::shop::BaseEntity"); + const members = customer.memberGroups.flatMap((g) => g.members); + // An inherited member keeps its place on the subtype and names where it is declared. + const id = members.find((m) => m.name === "id")!; + expect(id.declaredOn?.id).toBe("acme::shop::BaseEntity"); + expect(id.path).toBe("model/acme/shop/Customer.html#m-id"); + expect(members.find((m) => m.name === "name")!.declaredOn).toBeNull(); + // Of a field and an identity both named `id`, the field keeps the plain id. + const audit = v.nodes.find((n) => n.id === "acme::shop::AuditEntry")!; + expect(audit.memberGroups.flatMap((g) => g.members).map((m) => m.id)).toContain("acme::shop::AuditEntry.id[identity.primary]"); + expect(audit.unclaimed).toBe(true); + }); + + test("references and their reverse come from the loader's resolution", async () => { + const v = await viewOf("shop"); + const order = v.nodes.find((n) => n.id === "acme::shop::Order")!; + expect(order.refs.map((r) => [r.attr, r.via?.id ?? null, r.target.id])).toEqual([ + ["extends", null, "acme::shop::BaseEntity"], + ["references", "acme::shop::Order.customerRef", "acme::shop::Customer"], + ]); + const customer = v.nodes.find((n) => n.id === "acme::shop::Customer")!; + expect(customer.referencedBy.map((r) => [r.attr, r.from.id])).toEqual([["references", "acme::shop::Order"]]); + }); + + test("requirements are flat, in document order, with depth, claims and roll-up", async () => { + const v = await viewOf("shop"); + expect(v.requirements.map((r) => [r.address, r.depth])).toEqual([ + ["Addressable", 0], + ["Shop", 0], + ["Shop.Checkout", 1], + ["Shop.Checkout.Orders", 2], + ["Shop.Checkout.Orders.Recorded", 3], + ["Shop.Checkout.Orders.Recorded.Quotable", 4], + ["Shop.Checkout.Orders.Noted", 3], + ["Shop.Checkout.Orders.Refunded", 3], + ["Shop.Checkout.Shipping", 2], + ]); + const refunded = v.requirements.find((r) => r.address === "Shop.Checkout.Orders.Refunded")!; + expect(refunded.implementedBy).toEqual([{ ref: "Refund", resolves: false, target: { label: "Refund", id: "", path: "", kind: "", unresolved: true } }]); + const quotable = v.requirements.find((r) => r.address === "Shop.Checkout.Orders.Recorded.Quotable")!; + expect(quotable.implementedBy[0]!.target.path).toBe("model/acme/shop/Order.html#m-reference"); + const order = v.nodes.find((n) => n.id === "acme::shop::Order")!; + const reference = order.memberGroups.flatMap((g) => g.members).find((m) => m.name === "reference")!; + expect(reference.claims.map((c) => c.requirement.id)).toEqual(["acme::shop::Shop.Checkout.Orders.Recorded.Quotable"]); + const shop = v.requirements.find((r) => r.address === "Shop")!; + expect(shop.rollup.filter((s) => s.count > 0)).toEqual([{ status: "planned", count: 1 }, { status: "live", count: 3 }]); + }); + + test("custom vocabulary: members and references appear with no docs code for them", async () => { + const v = await viewOf("crm"); + const page = v.nodes.find((n) => n.id === "acme::crm::Lead[page.list]")!; + expect(page.path).toBe("model/acme/crm/Lead.page-list.html"); + expect(page.memberGroups.map((g) => [g.type, g.count])).toEqual([["block", 2]]); + expect(page.refs.map((r) => [r.attr, r.via?.id ?? null, r.target.id])).toEqual([ + ["objectRef", null, "acme::crm::Lead"], + ["objectRef", "acme::crm::Lead[page.list].leads", "acme::crm::Lead"], + ["objectRef", "acme::crm::Lead[page.list].accounts", "acme::crm::Account"], + ]); + // An attribute the provider declares but the loader does not resolve stays text. + const columns = page.memberGroups[0]!.members[0]!.attrs.find((a) => a.name === "columns")!; + expect(columns.values.map((x) => [x.text, x.link])).toEqual([["email", null], ["accountId", null]]); + const account = v.nodes.find((n) => n.id === "acme::crm::Account")!; + expect(account.referencedBy.map((r) => [r.attr, r.from.id])).toEqual([ + ["references", "acme::crm::Lead"], + ["objectRef", "acme::crm::Lead[page.list]"], + ]); + const tax = v.nodes.find((n) => n.id === "acme::tax::tax")!; + expect(tax.claims.map((c) => c.requirement.id)).toEqual(["acme::crm::Crm.Leads"]); + }); + + test("without the optional inputs their parts are empty and say so", async () => { + const dir = join(CORPUS, "shop"); + const loaded = await MetaDataLoader.fromDirectory(join(dir, "project", "metaobjects"), { strict: true }); + const v = buildDocsView({ root: loaded.root }); + expect(v.sources).toEqual({ requirements: false, files: false, routes: false }); + expect(v.advisories).toEqual([]); + expect(v.requirements.every((r) => !r.inLedger && r.verdict === "")).toBe(true); + expect(v.nodes.every((n) => n.files.length === 0 && n.routes.length === 0)).toBe(true); + // Claims are the model's own, so they hold without the gate's payload. + expect(v.counts.claims).toBe(5); + }); + + test("a map attribute's keys are in code-unit order, whatever order they were declared in", async () => { + const model = { + "metadata.root": { + package: "p", + children: [{ "object.entity": { name: "Doc", children: [ + { "field.enum": { name: "state", "@values": ["DRAFT", "PUBLISHED", "ARCHIVED"], "@intValueMap": { DRAFT: 0, PUBLISHED: 5, ARCHIVED: 9 } } }, + ] } }], + }, + }; + const loaded = await new MetaDataLoader().load([new InMemoryStringSource(JSON.stringify(model))]); + expect(loaded.errors.map(String)).toEqual([]); + const state = buildDocsView({ root: loaded.root }).nodes[0]!.memberGroups[0]!.members[0]!; + const map = state.attrs.find((a) => a.name === "intValueMap")!; + expect(JSON.stringify(map.value)).toBe(`{"ARCHIVED":9,"DRAFT":0,"PUBLISHED":5}`); + expect(map.values[0]!.text).toBe(`{"ARCHIVED":9,"DRAFT":0,"PUBLISHED":5}`); + // A list keeps its order: it is the declaration. + expect(state.attrs.find((a) => a.name === "values")!.values.map((v) => v.text)).toEqual(["DRAFT", "PUBLISHED", "ARCHIVED"]); + }); + + test("the same inputs give the same bytes", async () => { + expect(serializeDocsView(await viewOf("shop"))).toBe(serializeDocsView(await viewOf("shop"))); + }); +}); From 633ac38ebe92f2f4601c9544df28d35f60080a12 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:27:02 -0500 Subject: [PATCH 2/7] no-mistakes(review): apply reviewer inline fixes --- CHANGELOG.md | 3 ++- docs/features/docs-view.md | 4 +++- docs/features/explorer-data.md | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e206603331..189e0d41c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1468,7 +1468,8 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru requirement subtree and prompt. Facts only, no HTML, with a boolean or a count wherever a page must choose, so a Mustache template can render it. A provider's own vocabulary gets its members and links with no docs code: the view reads the loader's resolution, never a - list of attribute names. `docsSiteFile()` writes it as the site's `explorer.json`. + list the docs code keeps, so a provider attribute links when the loader resolves it as a + reference (one of the reference attributes it knows, such as `@objectRef`). `docsSiteFile()` writes it as the site's `explorer.json`. Gated by the new `fixtures/explorer-conformance/` corpus (`shop`, and `crm` for vocabulary a data-driven provider registers), which every port that builds the view is held to byte for diff --git a/docs/features/docs-view.md b/docs/features/docs-view.md index 7f9ad8003b..b469cdb84c 100644 --- a/docs/features/docs-view.md +++ b/docs/features/docs-view.md @@ -31,7 +31,9 @@ The builder re-derives nothing the loader already decided. Ids come from walking effective tree. Inheritance comes from where each effective child is declared, and references come from the loader's own resolution of every attribute it treats as a reference. Claims are resolved by the same resolver the requirement gate uses. A provider's vocabulary therefore -gets its members and its links with no change to the docs code. The corpus's `crm` case +gets its members and its links with no change to the docs code. A link needs an attribute +the loader resolves as a reference (such as `@objectRef`); any other attribute stays text. The +corpus's `crm` case declares a `page.list` and a `capability.module` in a data-driven provider, and both appear, linked, with nothing in the builder that names them. diff --git a/docs/features/explorer-data.md b/docs/features/explorer-data.md index f3827a9b4f..3670be7a73 100644 --- a/docs/features/explorer-data.md +++ b/docs/features/explorer-data.md @@ -27,7 +27,7 @@ Only the model is required. The view reads the model the loader resolved, so it nothing (no reference is matched by name, no inheritance is re-walked). An earlier version read the effective canonical JSON from `meta export --effective` and rebuilt references from a fixed list of attribute names; the view replaced it, and a provider's own vocabulary now gets its -links with no change to the docs code. +links, on every attribute the loader resolves as a reference, with no change to the docs code. ### `meta export --effective` From 7b75a726a0cad79a53477de5b49e6c01ce02dcf5 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:37:26 -0500 Subject: [PATCH 3/7] no-mistakes(review): Fix docs view plain-id lookup and member links --- docs/features/docs-view.md | 22 +++-- .../packages/docs-site/src/index.ts | 2 - .../packages/metadata/src/docs-view/build.ts | 30 ++++--- .../packages/metadata/src/docs-view/index.ts | 2 +- .../test/docs-view-conformance.test.ts | 81 ++++++++++++++++++- 5 files changed, 114 insertions(+), 23 deletions(-) diff --git a/docs/features/docs-view.md b/docs/features/docs-view.md index b469cdb84c..eb6ac7bcee 100644 --- a/docs/features/docs-view.md +++ b/docs/features/docs-view.md @@ -68,10 +68,13 @@ interface DocsViewLink { } ``` -The `label` is a top-level node's name, a requirement's `@title` (else its name), or -`.` for a member. An unresolved link keeps the text as written in its -`label`, so a page can print it without linking it. A link to an inherited member lands on the -node that declares it, because a reference to that member resolves there. +The `label` is a top-level node's name, a requirement's `@title` (else its name), or for a +member the owner's name followed by the member's id after the owner's id: `Order.email`, or +`Order#3` for a member with no name. An unresolved link keeps the text as written in its +`label`, so a page can print it without linking it. A reference value or an `@implementedBy` +claim that names a member the owner inherits (`Order.total`, with `total` declared on `Order`'s +base) lands on the owner's own row for that member (`Order.html#m-total`). `extends` and a +member's `declaredOn` name the node that declares it. ### Ids @@ -85,6 +88,9 @@ node that declares it, because a reference to that member resolves there. `@implementedBy` such as `AuditEntry.id` resolves to. Each later one adds its type: `acme::shop::AuditEntry.id[identity.primary]`. - Two nodes that would still share an id make the builder throw, naming the id. +- A name in an optional input (a file's `sourceNode`, a route's `node`, a finding's `node`) and a + claim name a node by its unqualified id, so they land on the node that holds that id, and on + its members, whatever order the nodes of that name are declared in. ### Pages and anchors @@ -155,8 +161,8 @@ Attributes are the effective ones, inherited through `extends` included, sorted order, so a map attribute such as `@intValueMap` reads the same from every port. A string gives one value and a list of strings gives one value per element. Any other value gives one, written as compact JSON. `link` is set only on an attribute the loader resolves as a -reference. It points at the member the value's dotted tail names when there is one, otherwise -at the node the loader bound. An attribute that merely spells a node's name is text: the view +reference. It points at the owner's row for the member the value's dotted tail names when +there is one (inherited or not), otherwise at the node the loader bound. An attribute that merely spells a node's name is text: the view never matches names itself. ### Members @@ -197,8 +203,8 @@ interface DocsViewClaim { requirement: DocsViewLink; member: string; status: str ``` A claim is one resolved `@implementedBy` link. It is listed on the top-level node and on every -member down to the one it names. `member` is the dotted path below the top-level node, or `""` -when the claim is on the node itself. +member down to the one it names. `member` is the member's id after the top-level node's +(`reference`, or `#3` for a member with no name), or `""` when the claim is on the node itself. ### `requirements` diff --git a/server/typescript/packages/docs-site/src/index.ts b/server/typescript/packages/docs-site/src/index.ts index 8e5c99c062..87a1cc6635 100644 --- a/server/typescript/packages/docs-site/src/index.ts +++ b/server/typescript/packages/docs-site/src/index.ts @@ -4,7 +4,5 @@ export { SITE_TEMPLATE_NAMES, SITE_ASSET_NAMES, CLASSIC_TEMPLATE_NAMES, CLASSIC_ export type { MetaDataTypeProvider } from "@metaobjectsdev/metadata"; // The explorer reads the docs view, which `@metaobjectsdev/metadata` builds from the loaded model // (`buildDocsView`, `docs/features/docs-view.md`). -export { ViewIndex, STATUSES, STATUS_GLYPH } from "./explorer/view-index.js"; -export type { PageNode, ReqEntry, Claim, ModelEdge } from "./explorer/view-index.js"; export { generateExplorerSite, readPromptTexts, EXPLORER_TEMPLATE_NAMES, EXPLORER_ASSET_NAMES, CYTOSCAPE_PATH } from "./explorer/site.js"; export type { ExplorerSiteOptions, ExplorerSiteResult } from "./explorer/site.js"; diff --git a/server/typescript/packages/metadata/src/docs-view/build.ts b/server/typescript/packages/metadata/src/docs-view/build.ts index ce9c701ba7..cb188b1f1f 100644 --- a/server/typescript/packages/metadata/src/docs-view/build.ts +++ b/server/typescript/packages/metadata/src/docs-view/build.ts @@ -32,7 +32,7 @@ import { REQUIREMENT_SUBTYPE_FUNCTIONAL, } from "../core/requirement/requirement-constants.js"; import { effectiveRequirementPackage, resolveClaimTarget, resolveMember } from "../core/requirement/resolve-claim.js"; -import { effectivePackageOf, isRefBearingAttr, lookupCanonical, topLevelNodeOf } from "../naming-refs.js"; +import { effectivePackageOf, isRefBearingAttr, lookupCanonical, splitChildTail, topLevelNodeOf } from "../naming-refs.js"; import { DOCS_VIEW_FORMAT, type DocsView, @@ -84,13 +84,13 @@ const str = (v: unknown): string => (typeof v === "string" ? v : ""); /** The directory of a package's pages. A package segment is an identifier, so `-root` (for * the empty package) cannot be one. */ -export function docsPackageDir(pkg: string): string { +function docsPackageDir(pkg: string): string { return pkg === "" ? "-root" : pkg.split(PACKAGE_SEPARATOR).join("/"); } /** A page's file stem: the name, unless it would take the package page's `index.html` (on a * case-insensitive file system too). */ -export function docsPageStem(name: string): string { +function docsPageStem(name: string): string { return name.toLowerCase() === "index" ? `${name}.node` : name; } @@ -126,7 +126,8 @@ class Builder { readonly byId = new Map(); /** Each node instance at its canonical walk position. */ readonly canonical = new Map(); - /** Plain path → walked node (the first holder of a plain path). */ + /** Plain path → walked node: the first holder of a plain path under a top-level node that + * holds its plain id, whatever order the other nodes of that name are declared in. */ readonly byPlain = new Map(); readonly requirements: Walked[] = []; @@ -192,7 +193,7 @@ class Builder { if (w.direct === w) w.anchor = memberAnchor(md, index); this.walked.push(w); this.byId.set(id, w); - if (!this.byPlain.has(plain)) this.byPlain.set(plain, w); + if (w.top.id === w.top.plain && !this.byPlain.has(plain)) this.byPlain.set(plain, w); if (w.canonical) this.canonical.set(md, w); if (parent === undefined) this.tops.push(w); else parent.children.push(w); @@ -222,7 +223,7 @@ class Builder { ? str(w.md.attr(DOC_ATTR_TITLE)) || w.md.name : w === w.top ? w.md.name - : `${w.top.md.name}.${w.id.slice(w.top.id.length + 1)}`; + : `${w.top.md.name}${w.id.slice(w.top.id.length)}`; return { label, id: w.id, path: w.path, kind: `${w.md.type}${TYPE_SUBTYPE_SEPARATOR}${w.md.subType}`, unresolved: false }; } @@ -231,16 +232,25 @@ class Builder { return w !== undefined ? this.link(w) : unresolved(text); } - /** The link a reference value lands on: the member its dotted tail names, else the owner the + /** The link a reference value lands on: the owner's row for the member its dotted tail + * names (the owner's own row of an inherited member, as a claim lands), else the owner the * loader bound. */ refLink(owner: MetaData | undefined, value: string): DocsViewLink { if (owner === undefined) return unresolved(value); const exact = value.includes(CHILD_REF_SEPARATOR) ? lookupCanonical(this.root, value) : undefined; - const target = exact !== undefined && topLevelNodeOf(exact) === owner ? exact : owner; - return this.linkTo(target, value); + if (exact === undefined) return this.linkTo(owner, value); + if (topLevelNodeOf(exact) === owner) return this.linkTo(exact, value); + const row = this.byPlain.get(`${owner.resolutionKey()}${splitChildTail(value).tail}`); + return row !== undefined ? this.link(row) : this.linkTo(owner, value); } } +/** A member's id after its top-level node's: `email`, `items.price`, or `#3` with no name. */ +function memberPath(w: Walked): string { + const rest = w.id.slice(w.top.id.length); + return rest.startsWith(CHILD_REF_SEPARATOR) ? rest.slice(CHILD_REF_SEPARATOR.length) : rest; +} + function qualified(id: string, md: MetaData): string { return `${id}[${md.type}${TYPE_SUBTYPE_SEPARATOR}${md.subType}]`; } @@ -397,7 +407,7 @@ export function buildDocsView(input: DocsViewInput): DocsView { targets.push(w); const claim: DocsViewClaim = { requirement: b.link(r), - member: w === w.top ? "" : w.id.slice(w.top.id.length + 1), + member: w === w.top ? "" : memberPath(w), status: str(req.status()), level: req.level() ?? null, }; diff --git a/server/typescript/packages/metadata/src/docs-view/index.ts b/server/typescript/packages/metadata/src/docs-view/index.ts index cda70ffa46..eb65058175 100644 --- a/server/typescript/packages/metadata/src/docs-view/index.ts +++ b/server/typescript/packages/metadata/src/docs-view/index.ts @@ -1,3 +1,3 @@ -export { buildDocsView, serializeDocsView, docsPackageDir, docsPageStem } from "./build.js"; +export { buildDocsView, serializeDocsView } from "./build.js"; export type { DocsViewInput } from "./build.js"; export * from "./types.js"; diff --git a/server/typescript/packages/metadata/test/docs-view-conformance.test.ts b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts index c05b3ebd20..20678473f8 100644 --- a/server/typescript/packages/metadata/test/docs-view-conformance.test.ts +++ b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts @@ -4,8 +4,9 @@ // view is held to the same files. // // A fixture may carry `provider.json`, a data-driven provider definition for vocabulary the -// core does not register. Its references must come out linked with no change to the builder: -// the view reads the loader's resolution, never a list of attribute names. +// core does not register. A provider attribute comes out linked when the loader resolves it as +// a reference (such as `@objectRef`), with no change to the builder: the view reads the +// loader's resolution, never a list of attribute names of its own. // // Regenerate after a deliberate change: `UPDATE_DOCS_VIEW=1 bun test test/docs-view-conformance.test.ts`. import { describe, expect, test } from "bun:test"; @@ -191,6 +192,82 @@ describe("buildDocsView over the corpus", () => { expect(state.attrs.find((a) => a.name === "values")!.values.map((v) => v.text)).toEqual(["DRAFT", "PUBLISHED", "ARCHIVED"]); }); + test("a node named like an entity and declared before it leaves the entity its claims, files, routes and findings", async () => { + const req = { "@level": 1, "@status": "live", "@statement": "s", "@counterexample": "c" }; + const model = { + "metadata.root": { + package: "acme::shop", + children: [ + { "requirement.functional": { name: "Order", ...req, "@implementedBy": ["Order", "Order.email"], children: [ + { "requirement.functional": { name: "email", ...req } }, + ] } }, + { "object.entity": { name: "Order", children: [{ "field.string": { name: "email" } }] } }, + ], + }, + }; + const loaded = await new MetaDataLoader().load([new InMemoryStringSource(JSON.stringify(model))]); + expect(loaded.errors.map(String)).toEqual([]); + const finding = { code: "WARN_REQUIREMENT_OBJECT_UNCLAIMED", node: "acme::shop::Order", path: "", severity: "warn", source: "", message: "" }; + const v = buildDocsView({ + root: loaded.root, + verify: { requirementLedger: [], requirements: { rows: [finding] } }, + manifest: { "src/Order.ts": { generatedBy: "entity", sourceNode: "acme::shop::Order" } }, + routes: [{ node: "acme::shop::Order", method: "get", path: "/orders" }], + }); + const entity = v.nodes.find((n) => n.id === "acme::shop::Order")!; + expect(entity.type).toBe("object"); + expect(entity.claims.map((c) => c.member)).toEqual(["", "email"]); + expect(entity.memberGroups[0]!.members[0]!.claims.map((c) => c.member)).toEqual(["email"]); + expect(entity.files).toEqual([{ generatedBy: "entity", paths: ["src/Order.ts"] }]); + expect(entity.routes).toEqual([{ method: "GET", path: "/orders" }]); + expect(entity.unclaimed).toBe(true); + const named = v.nodes.find((n) => n.id === "acme::shop::Order[requirement.functional]")!; + expect([named.claims, named.files, named.routes, named.unclaimed]).toEqual([[], [], [], false]); + expect(v.requirements[0]!.implementedBy.map((l) => l.target.path)).toEqual(["model/acme/shop/Order.html", "model/acme/shop/Order.html#m-email"]); + expect(v.advisories[0]!.subject?.id).toBe("acme::shop::Order"); + }); + + test("a reference and a claim naming an inherited member land on the owner's row; extends names the declarer", async () => { + const model = { + "metadata.root": { + package: "acme::shop", + children: [ + { "requirement.functional": { name: "Totals", "@level": 4, "@status": "live", "@statement": "s", "@counterexample": "c", "@implementedBy": ["Order.total"] } }, + { "object.entity": { name: "Base", abstract: true, children: [ + { "field.long": { name: "id" } }, + { "field.long": { name: "total" } }, + { "identity.primary": { name: "pk", "@fields": "id" } }, + ] } }, + { "object.entity": { name: "Order", extends: "Base", children: [] } }, + { "object.entity": { name: "Customer", children: [ + { "field.long": { name: "id" } }, + { "relationship.association": { name: "orders", "@objectRef": "Order", "@cardinality": "many" } }, + { "identity.primary": { name: "pk", "@fields": "id" } }, + ] } }, + { "object.value": { name: "Params", children: [{ "field.long": { name: "customerId" } }] } }, + { "object.projection": { name: "CustomerTotals", children: [ + { "source.rdb": { "@kind": "storedProc", "@storedProc": "p_totals", "@parameterRef": "Params" } }, + { "field.long": { name: "sum", children: [ + { "origin.aggregate": { "@agg": "sum", "@of": "Order.total", "@via": "Customer.orders" } }, + ] } }, + ] } }, + ], + }, + }; + const loaded = await new MetaDataLoader().load([new InMemoryStringSource(JSON.stringify(model))]); + expect(loaded.errors.map(String)).toEqual([]); + const v = buildDocsView({ root: loaded.root }); + const totals = v.nodes.find((n) => n.id === "acme::shop::CustomerTotals")!; + const of = totals.refs.find((r) => r.attr === "of")!; + expect([of.target.id, of.target.path, of.target.label]).toEqual(["acme::shop::Order.total", "model/acme/shop/Order.html#m-total", "Order.total"]); + expect(v.requirements[0]!.implementedBy[0]!.target.path).toBe("model/acme/shop/Order.html#m-total"); + const total = v.nodes.find((n) => n.id === "acme::shop::Order")!.memberGroups.flatMap((g) => g.members).find((m) => m.name === "total")!; + expect(total.declaredOn?.path).toBe("model/acme/shop/Base.html"); + // A member with no name keeps its index in its label, as in its id. + const source = totals.refs.find((r) => r.attr === "parameterRef")!; + expect([source.via?.id, source.via?.label]).toEqual(["acme::shop::CustomerTotals#0", "CustomerTotals#0"]); + }); + test("the same inputs give the same bytes", async () => { expect(serializeDocsView(await viewOf("shop"))).toBe(serializeDocsView(await viewOf("shop"))); }); From f0834d7a82b71a3163fa6d4c3178507efdbbcc6a Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:39:16 -0500 Subject: [PATCH 4/7] no-mistakes(review): apply reviewer inline fixes --- .../packages/codegen-ts/src/generators/docs-site-file.ts | 2 +- server/typescript/packages/metadata/src/docs-view/types.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts b/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts index 6241ea9fd5..a3824cdaf8 100644 --- a/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts +++ b/server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts @@ -155,7 +155,6 @@ async function buildInScratch(prefix: string, build: (outDir: string) => string[ } } -/** The routes the run mounts, as the api reference states them (`METHOD /path` per symbol). */ /** A route the run mounts, keyed by its node's resolution key: the docs view's `routes` input. */ interface RunRoute { node: string; @@ -163,6 +162,7 @@ interface RunRoute { path: string; } +/** The routes the run mounts, as the api reference states them (`METHOD /path` per symbol). */ function runRoutes(ctx: GenContext): RunRoute[] { const routes: RunRoute[] = []; for (const unit of buildApiModelForRun(ctx).units) { diff --git a/server/typescript/packages/metadata/src/docs-view/types.ts b/server/typescript/packages/metadata/src/docs-view/types.ts index 4eae8cc267..1909a9658e 100644 --- a/server/typescript/packages/metadata/src/docs-view/types.ts +++ b/server/typescript/packages/metadata/src/docs-view/types.ts @@ -12,8 +12,8 @@ export const DOCS_VIEW_FORMAT = "metaobjects-docs-view/1"; /** A pointer to a node of the view, or to a reference that did not resolve. */ export interface DocsViewLink { /** What a page prints for the target: a top-level node's name, a requirement's title (else - * its name), `.` for a member. The text as written when - * unresolved. */ + * its name), or for a member the owner's name followed by the member's id after the + * owner's id (`Order.email`, `Order#3` with no name). The text as written when unresolved. */ label: string; /** The target's id; "" when unresolved. */ id: string; @@ -63,7 +63,8 @@ export interface DocsViewReferrer { /** A requirement's `@implementedBy` link onto this node or one of its members. */ export interface DocsViewClaim { requirement: DocsViewLink; - /** The dotted member path below the top-level node; "" for the whole node. */ + /** The member's id after the top-level node's (`reference`, or `#3` with no name); "" for + * the whole node. */ member: string; status: string; level: number | null; From 39632ab3ac0acb9605aceca46a85587bcf630955 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:44:12 -0500 Subject: [PATCH 5/7] no-mistakes(review): Pin docs-view id rules in crm corpus fixture --- docs/CONFORMANCE.md | 3 + fixtures/explorer-conformance/README.md | 7 + .../explorer-conformance/crm/expected.json | 991 +++++++++++++++++- .../crm/project/metaobjects/meta.crm.json | 63 +- fixtures/explorer-conformance/crm/verify.json | 24 +- .../packages/metadata/src/docs-view/build.ts | 8 +- .../test/docs-view-conformance.test.ts | 12 + 7 files changed, 1042 insertions(+), 66 deletions(-) diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index 8bd17e0ef3..06e2d063ed 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -908,6 +908,9 @@ and a reply, and a five-level requirement tree that has a resolved member claim, planned claim and a live requirement nothing implements. `crm` adds a `provider.json`, a data-driven provider for vocabulary the core does not register (`page.list`, `block.table`, `capability.module`): its members and references must appear with no docs code that names them. +It also pins three id rules: a page declared before the entity it shares a name with leaves the +entity its claims, a reference and a claim naming an inherited member land on the owner's row, +and a nameless member keeps its index in its label. **One port runs it:** TypeScript, in `server/typescript/packages/metadata/test/docs-view-conformance.test.ts` (the view) and diff --git a/fixtures/explorer-conformance/README.md b/fixtures/explorer-conformance/README.md index 2f677a581c..c95f7abc76 100644 --- a/fixtures/explorer-conformance/README.md +++ b/fixtures/explorer-conformance/README.md @@ -48,11 +48,18 @@ the builder nor any page names them. - The entity `Lead` and the page `Lead` share a package and a name: the entity keeps `acme::crm::Lead`, and the page is `acme::crm::Lead[page.list]`, on `Lead.page-list.html`. + The page is declared first, and the entity still holds every claim that names `Lead`. - The page's `@objectRef` and its blocks' `@objectRef` are resolved by the loader, so they are references (to `Lead` and `Account`) and both entities list the page in `referencedBy`. The blocks' `@columns` is not a reference attribute, so it stays text. - `Crm.Leads` claims `acme::tax::tax`, a `capability.module` in another package, and the claim resolves like any other. +- `Lead` extends the abstract `Scored` and inherits `score`. The projection `AccountScore` + totals it with `@of: Lead.score`, and its child `Crm.Leads.Scoring` claims `Lead.score`: the + reference and the claim both land on Lead's own row (`Lead.html#m-score`), while the member's + `declaredOn` names `Scored`. +- `AccountScore`'s `source.rdb` has no name and carries `@parameterRef`: the member is + `acme::crm::AccountScore#0`, labelled `AccountScore#0`. ## Regenerating diff --git a/fixtures/explorer-conformance/crm/expected.json b/fixtures/explorer-conformance/crm/expected.json index 1d173834ad..21e857bf28 100644 --- a/fixtures/explorer-conformance/crm/expected.json +++ b/fixtures/explorer-conformance/crm/expected.json @@ -6,10 +6,10 @@ "routes": false }, "counts": { - "nodes": 5, + "nodes": 8, "packages": 2, - "requirements": 2, - "functional": 2, + "requirements": 3, + "functional": 3, "architectural": 0, "byStatus": [ { @@ -18,7 +18,7 @@ }, { "status": "live", - "count": 2 + "count": 3 }, { "status": "partial", @@ -29,7 +29,7 @@ "count": 0 } ], - "claims": 3, + "claims": 4, "files": 0, "routes": 0, "undecided": 0, @@ -40,12 +40,12 @@ "packages": [ { "name": "acme::crm", - "count": 4, + "count": 7, "groups": [ { "type": "object", "subType": "entity", - "count": 2, + "count": 3, "nodes": [ { "label": "Account", @@ -60,6 +60,41 @@ "path": "model/acme/crm/Lead.html", "kind": "object.entity", "unresolved": false + }, + { + "label": "Scored", + "id": "acme::crm::Scored", + "path": "model/acme/crm/Scored.html", + "kind": "object.entity", + "unresolved": false + } + ] + }, + { + "type": "object", + "subType": "projection", + "count": 1, + "nodes": [ + { + "label": "AccountScore", + "id": "acme::crm::AccountScore", + "path": "model/acme/crm/AccountScore.html", + "kind": "object.projection", + "unresolved": false + } + ] + }, + { + "type": "object", + "subType": "value", + "count": 1, + "nodes": [ + { + "label": "ScoreParams", + "id": "acme::crm::ScoreParams", + "path": "model/acme/crm/ScoreParams.html", + "kind": "object.value", + "unresolved": false } ] }, @@ -121,7 +156,7 @@ "package": "acme::crm", "type": "object", "subType": "entity", - "order": 1, + "order": 3, "path": "model/acme/crm/Account.html", "title": "", "description": "", @@ -170,6 +205,74 @@ } ] }, + { + "type": "relationship", + "count": 1, + "members": [ + { + "id": "acme::crm::Account.leads", + "name": "leads", + "type": "relationship", + "subType": "association", + "order": 2, + "anchor": "m-relationship-leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "cardinality", + "value": "many", + "values": [ + { + "text": "many", + "link": null + } + ] + }, + { + "name": "objectRef", + "value": "acme::crm::Lead", + "values": [ + { + "text": "acme::crm::Lead", + "link": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "objectRef", + "via": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + }, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + }, { "type": "identity", "count": 1, @@ -179,7 +282,7 @@ "name": "pk", "type": "identity", "subType": "primary", - "order": 2, + "order": 3, "anchor": "m-identity-pk", "path": "model/acme/crm/Account.html#m-identity-pk", "abstract": false, @@ -215,7 +318,7 @@ "name": "db", "type": "source", "subType": "rdb", - "order": 3, + "order": 4, "anchor": "m-source-db", "path": "model/acme/crm/Account.html#m-source-db", "abstract": false, @@ -241,8 +344,50 @@ ] } ], - "refs": [], + "refs": [ + { + "attr": "objectRef", + "via": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + }, + "target": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + } + ], "referencedBy": [ + { + "attr": "via", + "from": { + "label": "AccountScore", + "id": "acme::crm::AccountScore", + "path": "model/acme/crm/AccountScore.html", + "kind": "object.projection", + "unresolved": false + }, + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + } + }, { "attr": "references", "from": { @@ -310,21 +455,307 @@ "routes": [], "unclaimed": false, "counts": { - "members": 4, - "refs": 0, - "referencedBy": 2, + "members": 5, + "refs": 1, + "referencedBy": 3, "claims": 1, "files": 0, "routes": 0 } }, + { + "id": "acme::crm::AccountScore", + "name": "AccountScore", + "package": "acme::crm", + "type": "object", + "subType": "projection", + "order": 5, + "path": "model/acme/crm/AccountScore.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "source", + "count": 1, + "members": [ + { + "id": "acme::crm::AccountScore#0", + "name": "", + "type": "source", + "subType": "rdb", + "order": 0, + "anchor": "m-source-0", + "path": "model/acme/crm/AccountScore.html#m-source-0", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "kind", + "value": "storedProc", + "values": [ + { + "text": "storedProc", + "link": null + } + ] + }, + { + "name": "parameterRef", + "value": "acme::crm::ScoreParams", + "values": [ + { + "text": "acme::crm::ScoreParams", + "link": { + "label": "ScoreParams", + "id": "acme::crm::ScoreParams", + "path": "model/acme/crm/ScoreParams.html", + "kind": "object.value", + "unresolved": false + } + } + ] + }, + { + "name": "proc", + "value": "account_score", + "values": [ + { + "text": "account_score", + "link": null + } + ] + } + ], + "refs": [ + { + "attr": "parameterRef", + "via": { + "label": "AccountScore#0", + "id": "acme::crm::AccountScore#0", + "path": "model/acme/crm/AccountScore.html#m-source-0", + "kind": "source.rdb", + "unresolved": false + }, + "target": { + "label": "ScoreParams", + "id": "acme::crm::ScoreParams", + "path": "model/acme/crm/ScoreParams.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + }, + { + "type": "field", + "count": 1, + "members": [ + { + "id": "acme::crm::AccountScore.totalScore", + "name": "totalScore", + "type": "field", + "subType": "long", + "order": 1, + "anchor": "m-totalScore", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [ + { + "type": "origin", + "count": 1, + "members": [ + { + "id": "acme::crm::AccountScore.totalScore#0", + "name": "", + "type": "origin", + "subType": "aggregate", + "order": 0, + "anchor": "", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "agg", + "value": "sum", + "values": [ + { + "text": "sum", + "link": null + } + ] + }, + { + "name": "of", + "value": "acme::crm::Lead.score", + "values": [ + { + "text": "acme::crm::Lead.score", + "link": { + "label": "Lead.score", + "id": "acme::crm::Lead.score", + "path": "model/acme/crm/Lead.html#m-score", + "kind": "field.long", + "unresolved": false + } + } + ] + }, + { + "name": "via", + "value": "acme::crm::Account.leads", + "values": [ + { + "text": "acme::crm::Account.leads", + "link": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + } + } + ] + } + ], + "refs": [ + { + "attr": "of", + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Lead.score", + "id": "acme::crm::Lead.score", + "path": "model/acme/crm/Lead.html#m-score", + "kind": "field.long", + "unresolved": false + } + }, + { + "attr": "via", + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + } + } + ], + "claims": [], + "memberGroups": [] + } + ] + } + ] + } + ] + } + ], + "refs": [ + { + "attr": "parameterRef", + "via": { + "label": "AccountScore#0", + "id": "acme::crm::AccountScore#0", + "path": "model/acme/crm/AccountScore.html#m-source-0", + "kind": "source.rdb", + "unresolved": false + }, + "target": { + "label": "ScoreParams", + "id": "acme::crm::ScoreParams", + "path": "model/acme/crm/ScoreParams.html", + "kind": "object.value", + "unresolved": false + } + }, + { + "attr": "of", + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Lead.score", + "id": "acme::crm::Lead.score", + "path": "model/acme/crm/Lead.html#m-score", + "kind": "field.long", + "unresolved": false + } + }, + { + "attr": "via", + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", + "unresolved": false + } + } + ], + "referencedBy": [], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 2, + "refs": 3, + "referencedBy": 0, + "claims": 0, + "files": 0, + "routes": 0 + } + }, { "id": "acme::crm::Crm", "name": "Crm", "package": "acme::crm", "type": "requirement", "subType": "functional", - "order": 3, + "order": 6, "path": "requirements/acme/crm/Crm.html", "title": "", "description": "", @@ -456,7 +887,84 @@ ], "refs": [], "claims": [], - "memberGroups": [] + "memberGroups": [ + { + "type": "requirement", + "count": 1, + "members": [ + { + "id": "acme::crm::Crm.Leads.Scoring", + "name": "Scoring", + "type": "requirement", + "subType": "functional", + "order": 0, + "anchor": "", + "path": "requirements/acme/crm/Crm.Leads.Scoring.html", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [ + { + "name": "counterexample", + "value": "A lead whose score is left out of its account's total.", + "values": [ + { + "text": "A lead whose score is left out of its account's total.", + "link": null + } + ] + }, + { + "name": "implementedBy", + "value": [ + "Lead.score" + ], + "values": [ + { + "text": "Lead.score", + "link": null + } + ] + }, + { + "name": "level", + "value": 5, + "values": [ + { + "text": "5", + "link": null + } + ] + }, + { + "name": "statement", + "value": "Each lead carries a score its account totals.", + "values": [ + { + "text": "Each lead carries a score its account totals.", + "link": null + } + ] + }, + { + "name": "status", + "value": "live", + "values": [ + { + "text": "live", + "link": null + } + ] + } + ], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ] } ] } @@ -482,13 +990,19 @@ "package": "acme::crm", "type": "object", "subType": "entity", - "order": 0, + "order": 2, "path": "model/acme/crm/Lead.html", "title": "", "description": "A prospective customer.", "summary": "", "abstract": false, - "extends": null, + "extends": { + "label": "Scored", + "id": "acme::crm::Scored", + "path": "model/acme/crm/Scored.html", + "kind": "object.entity", + "unresolved": false + }, "attrs": [ { "name": "description", @@ -504,14 +1018,50 @@ "memberGroups": [ { "type": "field", - "count": 3, + "count": 4, "members": [ + { + "id": "acme::crm::Lead.score", + "name": "score", + "type": "field", + "subType": "long", + "order": 0, + "anchor": "m-score", + "path": "model/acme/crm/Lead.html#m-score", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": { + "label": "Scored", + "id": "acme::crm::Scored", + "path": "model/acme/crm/Scored.html", + "kind": "object.entity", + "unresolved": false + }, + "attrs": [], + "refs": [], + "claims": [ + { + "requirement": { + "label": "Scoring", + "id": "acme::crm::Crm.Leads.Scoring", + "path": "requirements/acme/crm/Crm.Leads.Scoring.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "score", + "status": "live", + "level": 5 + } + ], + "memberGroups": [] + }, { "id": "acme::crm::Lead.id", "name": "id", "type": "field", "subType": "long", - "order": 0, + "order": 1, "anchor": "m-id", "path": "model/acme/crm/Lead.html#m-id", "abstract": false, @@ -528,7 +1078,7 @@ "name": "email", "type": "field", "subType": "string", - "order": 1, + "order": 2, "anchor": "m-email", "path": "model/acme/crm/Lead.html#m-email", "abstract": false, @@ -545,7 +1095,7 @@ "name": "accountId", "type": "field", "subType": "long", - "order": 2, + "order": 3, "anchor": "m-accountId", "path": "model/acme/crm/Lead.html#m-accountId", "abstract": false, @@ -568,7 +1118,7 @@ "name": "pk", "type": "identity", "subType": "primary", - "order": 3, + "order": 4, "anchor": "m-identity-pk", "path": "model/acme/crm/Lead.html#m-identity-pk", "abstract": false, @@ -598,7 +1148,7 @@ "name": "accountRef", "type": "identity", "subType": "reference", - "order": 4, + "order": 5, "anchor": "m-identity-accountRef", "path": "model/acme/crm/Lead.html#m-identity-accountRef", "abstract": false, @@ -668,7 +1218,7 @@ "name": "db", "type": "source", "subType": "rdb", - "order": 5, + "order": 6, "anchor": "m-source-db", "path": "model/acme/crm/Lead.html#m-source-db", "abstract": false, @@ -695,25 +1245,84 @@ } ], "refs": [ + { + "attr": "extends", + "via": null, + "target": { + "label": "Scored", + "id": "acme::crm::Scored", + "path": "model/acme/crm/Scored.html", + "kind": "object.entity", + "unresolved": false + } + }, { "attr": "references", "via": { - "label": "Lead.accountRef", - "id": "acme::crm::Lead.accountRef", - "path": "model/acme/crm/Lead.html#m-identity-accountRef", - "kind": "identity.reference", + "label": "Lead.accountRef", + "id": "acme::crm::Lead.accountRef", + "path": "model/acme/crm/Lead.html#m-identity-accountRef", + "kind": "identity.reference", + "unresolved": false + }, + "target": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "referencedBy": [ + { + "attr": "objectRef", + "from": { + "label": "Account", + "id": "acme::crm::Account", + "path": "model/acme/crm/Account.html", + "kind": "object.entity", + "unresolved": false + }, + "via": { + "label": "Account.leads", + "id": "acme::crm::Account.leads", + "path": "model/acme/crm/Account.html#m-relationship-leads", + "kind": "relationship.association", "unresolved": false }, "target": { - "label": "Account", - "id": "acme::crm::Account", - "path": "model/acme/crm/Account.html", + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", "kind": "object.entity", "unresolved": false } - } - ], - "referencedBy": [ + }, + { + "attr": "of", + "from": { + "label": "AccountScore", + "id": "acme::crm::AccountScore", + "path": "model/acme/crm/AccountScore.html", + "kind": "object.projection", + "unresolved": false + }, + "via": { + "label": "AccountScore.totalScore#0", + "id": "acme::crm::AccountScore.totalScore#0", + "path": "model/acme/crm/AccountScore.html#m-totalScore", + "kind": "origin.aggregate", + "unresolved": false + }, + "target": { + "label": "Lead.score", + "id": "acme::crm::Lead.score", + "path": "model/acme/crm/Lead.html#m-score", + "kind": "field.long", + "unresolved": false + } + }, { "attr": "objectRef", "from": { @@ -769,16 +1378,28 @@ "member": "", "status": "live", "level": 4 + }, + { + "requirement": { + "label": "Scoring", + "id": "acme::crm::Crm.Leads.Scoring", + "path": "requirements/acme/crm/Crm.Leads.Scoring.html", + "kind": "requirement.functional", + "unresolved": false + }, + "member": "score", + "status": "live", + "level": 5 } ], "files": [], "routes": [], "unclaimed": false, "counts": { - "members": 6, - "refs": 1, - "referencedBy": 2, - "claims": 1, + "members": 7, + "refs": 2, + "referencedBy": 4, + "claims": 2, "files": 0, "routes": 0 } @@ -789,7 +1410,7 @@ "package": "acme::crm", "type": "page", "subType": "list", - "order": 2, + "order": 0, "path": "model/acme/crm/Lead.page-list.html", "title": "Leads", "description": "", @@ -1036,13 +1657,165 @@ "routes": 0 } }, + { + "id": "acme::crm::ScoreParams", + "name": "ScoreParams", + "package": "acme::crm", + "type": "object", + "subType": "value", + "order": 4, + "path": "model/acme/crm/ScoreParams.html", + "title": "", + "description": "", + "summary": "", + "abstract": false, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 1, + "members": [ + { + "id": "acme::crm::ScoreParams.accountId", + "name": "accountId", + "type": "field", + "subType": "long", + "order": 0, + "anchor": "m-accountId", + "path": "model/acme/crm/ScoreParams.html#m-accountId", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "parameterRef", + "from": { + "label": "AccountScore", + "id": "acme::crm::AccountScore", + "path": "model/acme/crm/AccountScore.html", + "kind": "object.projection", + "unresolved": false + }, + "via": { + "label": "AccountScore#0", + "id": "acme::crm::AccountScore#0", + "path": "model/acme/crm/AccountScore.html#m-source-0", + "kind": "source.rdb", + "unresolved": false + }, + "target": { + "label": "ScoreParams", + "id": "acme::crm::ScoreParams", + "path": "model/acme/crm/ScoreParams.html", + "kind": "object.value", + "unresolved": false + } + } + ], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 1, + "claims": 0, + "files": 0, + "routes": 0 + } + }, + { + "id": "acme::crm::Scored", + "name": "Scored", + "package": "acme::crm", + "type": "object", + "subType": "entity", + "order": 1, + "path": "model/acme/crm/Scored.html", + "title": "", + "description": "", + "summary": "", + "abstract": true, + "extends": null, + "attrs": [], + "memberGroups": [ + { + "type": "field", + "count": 1, + "members": [ + { + "id": "acme::crm::Scored.score", + "name": "score", + "type": "field", + "subType": "long", + "order": 0, + "anchor": "m-score", + "path": "model/acme/crm/Scored.html#m-score", + "abstract": false, + "isArray": false, + "extends": null, + "declaredOn": null, + "attrs": [], + "refs": [], + "claims": [], + "memberGroups": [] + } + ] + } + ], + "refs": [], + "referencedBy": [ + { + "attr": "extends", + "from": { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + }, + "via": null, + "target": { + "label": "Scored", + "id": "acme::crm::Scored", + "path": "model/acme/crm/Scored.html", + "kind": "object.entity", + "unresolved": false + } + } + ], + "claims": [], + "files": [], + "routes": [], + "unclaimed": false, + "counts": { + "members": 1, + "refs": 0, + "referencedBy": 1, + "claims": 0, + "files": 0, + "routes": 0 + } + }, { "id": "acme::tax::tax", "name": "tax", "package": "acme::tax", "type": "capability", "subType": "module", - "order": 4, + "order": 7, "path": "model/acme/tax/tax.html", "title": "", "description": "Sales tax.", @@ -1144,7 +1917,7 @@ }, { "status": "live", - "count": 1 + "count": 2 }, { "status": "partial", @@ -1155,8 +1928,8 @@ "count": 0 } ], - "rollupTotal": 1, - "belowCount": 1, + "rollupTotal": 2, + "belowCount": 2, "childCount": 1, "targets": [ { @@ -1217,7 +1990,15 @@ "unresolved": false } ], - "children": [], + "children": [ + { + "label": "Scoring", + "id": "acme::crm::Crm.Leads.Scoring", + "path": "requirements/acme/crm/Crm.Leads.Scoring.html", + "kind": "requirement.functional", + "unresolved": false + } + ], "implementedBy": [ { "ref": "Lead", @@ -1265,7 +2046,7 @@ }, { "status": "live", - "count": 1 + "count": 2 }, { "status": "partial", @@ -1276,9 +2057,9 @@ "count": 0 } ], - "rollupTotal": 1, - "belowCount": 0, - "childCount": 0, + "rollupTotal": 2, + "belowCount": 1, + "childCount": 1, "targets": [ { "label": "Account", @@ -1303,6 +2084,98 @@ } ], "targetCount": 3 + }, + { + "id": "acme::crm::Crm.Leads.Scoring", + "name": "Scoring", + "label": "Scoring", + "path": "requirements/acme/crm/Crm.Leads.Scoring.html", + "address": "Crm.Leads.Scoring", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm.Leads.Scoring", + "subType": "functional", + "level": 5, + "status": "live", + "disposition": "", + "statement": "Each lead carries a score its account totals.", + "counterexample": "A lead whose score is left out of its account's total.", + "title": "", + "description": "", + "trackedBy": [], + "depth": 2, + "parent": { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + }, + "breadcrumbs": [ + { + "label": "Crm", + "id": "acme::crm::Crm", + "path": "requirements/acme/crm/Crm.html", + "kind": "requirement.functional", + "unresolved": false + }, + { + "label": "Leads", + "id": "acme::crm::Crm.Leads", + "path": "requirements/acme/crm/Crm.Leads.html", + "kind": "requirement.functional", + "unresolved": false + } + ], + "children": [], + "implementedBy": [ + { + "ref": "Lead.score", + "resolves": true, + "target": { + "label": "Lead.score", + "id": "acme::crm::Lead.score", + "path": "model/acme/crm/Lead.html#m-score", + "kind": "field.long", + "unresolved": false + } + } + ], + "supersededBy": null, + "inLedger": true, + "verdict": "clean", + "digest": "6990b1edf77a7367a183eb110b02e990d84cee610f9c9531d7062270bbe2d000", + "diagnostics": [], + "rollup": [ + { + "status": "planned", + "count": 0 + }, + { + "status": "live", + "count": 1 + }, + { + "status": "partial", + "count": 0 + }, + { + "status": "retired", + "count": 0 + } + ], + "rollupTotal": 1, + "belowCount": 0, + "childCount": 0, + "targets": [ + { + "label": "Lead", + "id": "acme::crm::Lead", + "path": "model/acme/crm/Lead.html", + "kind": "object.entity", + "unresolved": false + } + ], + "targetCount": 1 } ], "advisories": [], @@ -1313,9 +2186,12 @@ "anchor": "acme::crm", "nodes": [ "acme::crm::Account", + "acme::crm::AccountScore", "acme::crm::Crm", "acme::crm::Lead", - "acme::crm::Lead[page.list]" + "acme::crm::Lead[page.list]", + "acme::crm::ScoreParams", + "acme::crm::Scored" ] }, { @@ -1334,7 +2210,22 @@ "acme::crm::Account", "acme::crm::Crm", "acme::crm::Crm.Leads", + "acme::crm::Crm.Leads.Scoring", + "acme::crm::Lead", + "acme::crm::Lead.score", + "acme::tax::tax" + ] + }, + { + "id": "requirement:acme::crm::Crm.Leads", + "kind": "requirement", + "anchor": "acme::crm::Crm.Leads", + "nodes": [ + "acme::crm::Account", + "acme::crm::Crm.Leads", + "acme::crm::Crm.Leads.Scoring", "acme::crm::Lead", + "acme::crm::Lead.score", "acme::tax::tax" ] } diff --git a/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json b/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json index 5dcaba9c01..9cf35f8848 100644 --- a/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json +++ b/fixtures/explorer-conformance/crm/project/metaobjects/meta.crm.json @@ -2,9 +2,31 @@ "metadata.root": { "package": "acme::crm", "children": [ + { + "page.list": { + "name": "Lead", + "@title": "Leads", + "@objectRef": "Lead", + "@route": "/leads", + "children": [ + { "block.table": { "name": "leads", "@objectRef": "Lead", "@columns": ["email", "accountId"] } }, + { "block.table": { "name": "accounts", "@objectRef": "Account", "@columns": ["name"] } } + ] + } + }, + { + "object.entity": { + "name": "Scored", + "abstract": true, + "children": [ + { "field.long": { "name": "score" } } + ] + } + }, { "object.entity": { "name": "Lead", + "extends": "Scored", "@description": "A prospective customer.", "children": [ { "field.long": { "name": "id" } }, @@ -22,20 +44,33 @@ "children": [ { "field.long": { "name": "id" } }, { "field.string": { "name": "name" } }, + { "relationship.association": { "name": "leads", "@objectRef": "Lead", "@cardinality": "many" } }, { "identity.primary": { "name": "pk", "@fields": ["id"] } }, { "source.rdb": { "name": "db", "@table": "accounts" } } ] } }, { - "page.list": { - "name": "Lead", - "@title": "Leads", - "@objectRef": "Lead", - "@route": "/leads", + "object.value": { + "name": "ScoreParams", "children": [ - { "block.table": { "name": "leads", "@objectRef": "Lead", "@columns": ["email", "accountId"] } }, - { "block.table": { "name": "accounts", "@objectRef": "Account", "@columns": ["name"] } } + { "field.long": { "name": "accountId" } } + ] + } + }, + { + "object.projection": { + "name": "AccountScore", + "children": [ + { "source.rdb": { "@kind": "storedProc", "@proc": "account_score", "@parameterRef": "ScoreParams" } }, + { + "field.long": { + "name": "totalScore", + "children": [ + { "origin.aggregate": { "@agg": "sum", "@of": "Lead.score", "@via": "Account.leads" } } + ] + } + } ] } }, @@ -54,7 +89,19 @@ "@status": "live", "@statement": "Each lead is stored with its email and account.", "@counterexample": "A lead's email is lost on save.", - "@implementedBy": ["Lead", "Account", "acme::tax::tax"] + "@implementedBy": ["Lead", "Account", "acme::tax::tax"], + "children": [ + { + "requirement.functional": { + "name": "Scoring", + "@level": 5, + "@status": "live", + "@statement": "Each lead carries a score its account totals.", + "@counterexample": "A lead whose score is left out of its account's total.", + "@implementedBy": ["Lead.score"] + } + } + ] } } ] diff --git a/fixtures/explorer-conformance/crm/verify.json b/fixtures/explorer-conformance/crm/verify.json index e1d37ffbc2..ad562cc7e4 100644 --- a/fixtures/explorer-conformance/crm/verify.json +++ b/fixtures/explorer-conformance/crm/verify.json @@ -39,16 +39,34 @@ ], "diagnostics": [], "verdict": "clean" + }, + { + "path": "Crm.Leads.Scoring", + "package": "acme::crm", + "qualifiedPath": "acme::crm::Crm.Leads.Scoring", + "subType": "functional", + "level": 5, + "status": "live", + "digest": "6990b1edf77a7367a183eb110b02e990d84cee610f9c9531d7062270bbe2d000", + "implementedBy": [ + { + "ref": "Lead.score", + "resolves": true, + "target": "acme::crm::Lead.score" + } + ], + "diagnostics": [], + "verdict": "clean" } ], "requirementCounts": { - "total": 2, - "functional": 2, + "total": 3, + "functional": 3, "architectural": 0, "byStatus": [ { "status": "live", - "count": 2 + "count": 3 } ], "undecided": 0, diff --git a/server/typescript/packages/metadata/src/docs-view/build.ts b/server/typescript/packages/metadata/src/docs-view/build.ts index cb188b1f1f..5749839b53 100644 --- a/server/typescript/packages/metadata/src/docs-view/build.ts +++ b/server/typescript/packages/metadata/src/docs-view/build.ts @@ -32,7 +32,7 @@ import { REQUIREMENT_SUBTYPE_FUNCTIONAL, } from "../core/requirement/requirement-constants.js"; import { effectiveRequirementPackage, resolveClaimTarget, resolveMember } from "../core/requirement/resolve-claim.js"; -import { effectivePackageOf, isRefBearingAttr, lookupCanonical, splitChildTail, topLevelNodeOf } from "../naming-refs.js"; +import { effectivePackageOf, isRefBearingAttr, splitChildTail } from "../naming-refs.js"; import { DOCS_VIEW_FORMAT, type DocsView, @@ -237,10 +237,8 @@ class Builder { * loader bound. */ refLink(owner: MetaData | undefined, value: string): DocsViewLink { if (owner === undefined) return unresolved(value); - const exact = value.includes(CHILD_REF_SEPARATOR) ? lookupCanonical(this.root, value) : undefined; - if (exact === undefined) return this.linkTo(owner, value); - if (topLevelNodeOf(exact) === owner) return this.linkTo(exact, value); - const row = this.byPlain.get(`${owner.resolutionKey()}${splitChildTail(value).tail}`); + const { tail } = splitChildTail(value); + const row = tail === "" ? undefined : this.byPlain.get(`${owner.resolutionKey()}${tail}`); return row !== undefined ? this.link(row) : this.linkTo(owner, value); } } diff --git a/server/typescript/packages/metadata/test/docs-view-conformance.test.ts b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts index 20678473f8..80fb96da49 100644 --- a/server/typescript/packages/metadata/test/docs-view-conformance.test.ts +++ b/server/typescript/packages/metadata/test/docs-view-conformance.test.ts @@ -154,9 +154,21 @@ describe("buildDocsView over the corpus", () => { expect(columns.values.map((x) => [x.text, x.link])).toEqual([["email", null], ["accountId", null]]); const account = v.nodes.find((n) => n.id === "acme::crm::Account")!; expect(account.referencedBy.map((r) => [r.attr, r.from.id])).toEqual([ + ["via", "acme::crm::AccountScore"], ["references", "acme::crm::Lead"], ["objectRef", "acme::crm::Lead[page.list]"], ]); + // The page is declared before the entity it shares a name with; the entity keeps its claims. + const lead = v.nodes.find((n) => n.id === "acme::crm::Lead")!; + expect(lead.claims.map((c) => [c.requirement.id, c.member])).toEqual([["acme::crm::Crm.Leads", ""], ["acme::crm::Crm.Leads.Scoring", "score"]]); + expect(page.claims).toEqual([]); + // `@of` names `score`, which Lead inherits from Scored: it lands on Lead's own row. + const score = v.nodes.find((n) => n.id === "acme::crm::AccountScore")!; + const of = score.refs.find((r) => r.attr === "of")!; + expect([of.target.id, of.target.path]).toEqual(["acme::crm::Lead.score", "model/acme/crm/Lead.html#m-score"]); + // A nameless source keeps its index in its id and its label. + const source = score.refs.find((r) => r.attr === "parameterRef")!; + expect([source.via?.id, source.via?.label, source.target.id]).toEqual(["acme::crm::AccountScore#0", "AccountScore#0", "acme::crm::ScoreParams"]); const tax = v.nodes.find((n) => n.id === "acme::tax::tax")!; expect(tax.claims.map((c) => c.requirement.id)).toEqual(["acme::crm::Crm.Leads"]); }); From 77b5352593a3ffadfddba20fba1a320535ae5ef9 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:53:51 -0500 Subject: [PATCH 6/7] no-mistakes(document): docs: point explorer inputs at docs view --- docs/features/cli.md | 2 +- docs/features/explorer-site.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/features/cli.md b/docs/features/cli.md index 01c5574189..c222826160 100644 --- a/docs/features/cli.md +++ b/docs/features/cli.md @@ -33,7 +33,7 @@ command surface splits in two: | **Codegen drift** (`verify --codegen`) | **Node `meta`** | `meta verify --codegen` | TS reference (ADR-0021 D2) — regen-to-temp + diff committed output | | **Template/prompt drift** (`verify --templates`) | **Node `meta`** | `meta verify --templates` | TS reference (ADR-0021 D2) — `{{field}}`↔payload; part of the bare-`verify` default | | **Vocabulary upgrade** (`upgrade`) | **Node `meta`** | `meta upgrade [--to ] [--apply]` | **any backend** — rewrites RETIRED metadata vocabulary (`@violation` → `@counterexample`, `@readOnly` → `@mutability`, dropping `@verifiedBy`) and resolves ATTRIBUTE CONTRADICTIONS (`@fields` beside `@expr` on an index key). Node-only because it edits the metadata documents themselves, which every port shares; a non-TS project runs `npx meta upgrade` against its own `metaobjects/`. **Canonical JSON and YAML alike.** Previews by default. Retirements needing a human decision are refused and the run exits non-zero, so CI cannot record a partial migration as finished | -| **Model export** (`export`) | **Node `meta`** | `meta export [--effective] [--out ]` | the loaded model, overlays merged, as one canonical JSON document. `--effective` also writes every inherited field, child and attribute onto the node that inherits it, which is the input the [explorer builder](explorer-data.md) reads. The output is for reading: loading an effective document back would declare each inherited member twice | +| **Model export** (`export`) | **Node `meta`** | `meta export [--effective] [--out ]` | the loaded model, overlays merged, as one canonical JSON document. `--effective` also writes every inherited field, child and attribute onto the node that inherits it. The docs view does not read it (see [explorer-data.md](explorer-data.md)). The output is for reading: loading an effective document back would declare each inherited member twice | | **Vocabulary search** (`types`) | **Node `meta`** | `meta types [query]` | **any backend** — apropos/`kubectl explain` over the live metamodel registry (names + descriptions + when-to-use); the vocabulary is cross-port identical (registry-conformance) | | **Dependency sync** (`deps`) | **Node `meta`** | `meta deps sync \| check \| list` | **any backend** — resolves a declared metadata dependency (`path`, an installed `npm` / `python` package, or a `maven` jar / `nuget` package already in the local Maven repository / NuGet cache; it never downloads) into a committed snapshot + lock (FR-023), so `sync`/`check`/`list` themselves stay Node-only regardless of your server language. TypeScript, Python and Java then LOAD that snapshot at every rung of their own source ladder (Kotlin loads through Java's loader and Maven plugin); C# loads the snapshot through `dotnet meta` (Phase 2 S6). On a project whose own metadata Node `meta` cannot read (a Maven `src/main/resources/metadata` directory, a C# metadata directory, or another port's vocabulary), `sync` and `check` prove the locked dependencies load together and say that the port's own `verify` is the full check. See [`metadata-dependencies.md`](metadata-dependencies.md) | | **Canonical format** (`fmt`) | every port | `meta fmt` / `dotnet meta fmt` / `mvn metaobjects:fmt` / `metaobjects fmt` | (#304) ships in **every** port — the canonical serializer already exists in all five, so formatting is local, not Node-only. `--check` lists non-canonical files and exits non-zero without changing anything. Formats each file STANDALONE — own-mode, declared-here layer only (ADR-0039); an `extends` onto another file's base is preserved as-is, never resolved or erred on; a file declaring `overlay: true` anywhere — whether or not a same-file base exists — is reported as skipped rather than merged (merging would drop the overlay marker, a structural change fmt never makes). A YAML file is always skipped — no canonical YAML emitter exists (ADR-0006). Before writing, every port reloads the whole project with the candidate swapped in and refuses the write unless the reloaded model's canonical form is byte-identical to the untouched baseline — fmt never changes meaning. See [Fixture corpus](#meta-fmt--canonical-formatting-304) below and `fixtures/fmt-conformance/README.md` | diff --git a/docs/features/explorer-site.md b/docs/features/explorer-site.md index 3989c6549e..9bf9aa9556 100644 --- a/docs/features/explorer-site.md +++ b/docs/features/explorer-site.md @@ -30,7 +30,7 @@ generator in the run, wherever it appears in the list, because it reads what the | `explorer.json` input | Where `meta gen` gets it | |---|---| -| The effective model | The model this run loaded (the same bytes as `meta export --effective`) | +| The effective model | The model this run loaded, through `buildDocsView` ([docs-view.md](docs-view.md)) | | The requirement ledger | The requirement gate, run with its defaults (the rows `meta verify --format json` prints) | | Generated files per node | The files this run wrote, with the node each came from. Files under a target whose `outDir` lies outside the project are left out, under `meta gen` and `verify --codegen` alike | | Routes per node | The REST routes this run's routes generator mounts; none if the run has no routes generator | From 1b95f198f1ddb3450d6d1256df4a3360f2fd6c69 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 27 Nov 2026 02:55:50 -0500 Subject: [PATCH 7/7] no-mistakes(document): docs: point explorer inputs at docs view --- docs/features/codegen-data-shapes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/features/codegen-data-shapes.md b/docs/features/codegen-data-shapes.md index e817b15397..c97ab322ec 100644 --- a/docs/features/codegen-data-shapes.md +++ b/docs/features/codegen-data-shapes.md @@ -83,9 +83,9 @@ the expected schema writes) leaves out. The corpus also pins the rows those builders start from (`expected/rows/`): `RequirementRow[]` (`requirementRows`) for both requirements pages, and `SchemaRows` (`schemaRows`, a subset of the -`meta schema --as json` shape) for the model-only schema page. These are the rows the docs site -reads too: the requirement rows are what the explorer graph holds, and the schema rows are part -of the storage lens's input. One shape serves the pages and the site, so it is not pinned twice. +`meta schema --as json` shape) for the model-only schema page. These are the rows the pages +read: the requirement rows feed the requirements pages, and the schema rows are part +of the agent schema page's input. The docs site does not read these rows: its explorer builds requirements from the verify payload's `requirementLedger` and the loaded model ([docs-view.md](docs-view.md), pinned by `fixtures/explorer-conformance/`). ### Neutral structural shapes → `EntityTemplateData` / `PackageTemplateData` / `ModelTemplateData`