@webpieces/api-doc-model 0.4.938 → 0.4.940

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/api-doc-model",
3
- "version": "0.4.938",
3
+ "version": "0.4.940",
4
4
  "description": "TypeScript-compiler-API extractor producing one in-memory ApiDocModel from a webpieces API contract. No renderer, no runtime, no app-specific import.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@webpieces/core-util": "0.4.938",
26
+ "@webpieces/core-util": "0.4.940",
27
27
  "typescript": "5.9.3",
28
28
  "minimatch": "10.0.1"
29
29
  }
@@ -0,0 +1,51 @@
1
+ import * as ts from 'typescript';
2
+ import { SchemaNames } from '../model/SchemaNames';
3
+ import { TypeRegistry } from './TypeRegistry';
4
+ /** Any of TypeScript's three inline link tags. */
5
+ type LinkPart = ts.JSDocLink | ts.JSDocLinkCode | ts.JSDocLinkPlain;
6
+ /**
7
+ * One JSDoc `{@link}` -> the text that stands for it in model prose (#1284).
8
+ *
9
+ * The COMPILER resolves the target, so a link means what the editor says it means — an import alias,
10
+ * a qualified name and a `#member` all land on the declaration itself. What it lands on decides what
11
+ * is recorded:
12
+ *
13
+ * | target | recorded as |
14
+ * |---|---|
15
+ * | a class, interface, enum or type alias | {@link DocLinkKind.TYPE}: its model key and published schema name |
16
+ * | a member of one (`MenuDto.items`, `Gender.F`) | {@link DocLinkKind.TYPE} of the owner, the `.member` tail kept as written |
17
+ * | an `@Endpoint` method of an `@ApiPath` contract | {@link DocLinkKind.OPERATION}: contract, method, `@WpMcpTool` name |
18
+ * | a URL (`{@link https://…}`) | a markdown link, written out here — it names no declaration |
19
+ * | anything else, or nothing | {@link DocLinkKind.UNRESOLVED}, with the reason |
20
+ *
21
+ * Nothing is refused HERE: whether a target is published is a question about one rendered output, so
22
+ * every renderer refuses what it cannot name, naming every offender in one run.
23
+ */
24
+ export declare class DocLinkReader {
25
+ private readonly checker;
26
+ private readonly registry;
27
+ private readonly schemaNames;
28
+ private readonly folder;
29
+ constructor(checker: ts.TypeChecker, registry: TypeRegistry, schemaNames: SchemaNames);
30
+ /** The text `part` contributes to a prose string. */
31
+ textOf(part: LinkPart): string;
32
+ private linkOf;
33
+ private typeLink;
34
+ private operationLink;
35
+ /** The declaration's symbol, through an import alias; a `#member` resolves on its right side. */
36
+ private symbolOf;
37
+ private static isNamedType;
38
+ /** The type a member belongs to — through a type literal to the alias that names it. */
39
+ private static ownerOf;
40
+ /** `.items` of `MenuDto.items`, `#items` of `MenuDto#items` — the tail exactly as written. */
41
+ private static tailOf;
42
+ /**
43
+ * `{@link https://x | Example}` -> `[Example](https://x)`, `{@link https://x}` -> `<https://x>`.
44
+ * TypeScript reads the scheme as the link's NAME and the rest as its text, so the URL is rebuilt.
45
+ */
46
+ private static urlOf;
47
+ /** `| the label` / ` the label` -> `the label`; nothing -> undefined. */
48
+ private static labelOf;
49
+ private static unresolved;
50
+ }
51
+ export {};
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocLinkReader = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ts = tslib_1.__importStar(require("typescript"));
6
+ const core_util_1 = require("@webpieces/core-util");
7
+ const DocLink_1 = require("../model/DocLink");
8
+ const ConstantFolder_1 = require("./ConstantFolder");
9
+ const FieldDecorators_1 = require("./FieldDecorators");
10
+ const SourceLocation_1 = require("./SourceLocation");
11
+ /** The decorator names, from the REAL SYMBOLS — see `ApiDocExtractor`'s constants (#1001). */
12
+ const API_PATH = core_util_1.ApiPath.name;
13
+ const ENDPOINT = core_util_1.Endpoint.name;
14
+ const MCP_TOOL = core_util_1.WpMcpTool.name;
15
+ /** `https://…`, `mailto:` and friends: a link to the web, not to a declaration. */
16
+ const URL_TARGET = /^[a-z][a-z0-9+.-]*:\S*/i;
17
+ /**
18
+ * One JSDoc `{@link}` -> the text that stands for it in model prose (#1284).
19
+ *
20
+ * The COMPILER resolves the target, so a link means what the editor says it means — an import alias,
21
+ * a qualified name and a `#member` all land on the declaration itself. What it lands on decides what
22
+ * is recorded:
23
+ *
24
+ * | target | recorded as |
25
+ * |---|---|
26
+ * | a class, interface, enum or type alias | {@link DocLinkKind.TYPE}: its model key and published schema name |
27
+ * | a member of one (`MenuDto.items`, `Gender.F`) | {@link DocLinkKind.TYPE} of the owner, the `.member` tail kept as written |
28
+ * | an `@Endpoint` method of an `@ApiPath` contract | {@link DocLinkKind.OPERATION}: contract, method, `@WpMcpTool` name |
29
+ * | a URL (`{@link https://…}`) | a markdown link, written out here — it names no declaration |
30
+ * | anything else, or nothing | {@link DocLinkKind.UNRESOLVED}, with the reason |
31
+ *
32
+ * Nothing is refused HERE: whether a target is published is a question about one rendered output, so
33
+ * every renderer refuses what it cannot name, naming every offender in one run.
34
+ */
35
+ class DocLinkReader {
36
+ checker;
37
+ registry;
38
+ schemaNames;
39
+ folder;
40
+ constructor(checker, registry, schemaNames) {
41
+ this.checker = checker;
42
+ this.registry = registry;
43
+ this.schemaNames = schemaNames;
44
+ this.folder = new ConstantFolder_1.ConstantFolder(checker);
45
+ }
46
+ /** The text `part` contributes to a prose string. */
47
+ textOf(part) {
48
+ const written = part.name?.getText() ?? '';
49
+ const url = DocLinkReader.urlOf(written, part.text);
50
+ if (url !== undefined) {
51
+ return url;
52
+ }
53
+ const label = DocLinkReader.labelOf(part.text);
54
+ return DocLink_1.DocLinkText.encode(this.linkOf(part, written, label));
55
+ }
56
+ linkOf(part, written, label) {
57
+ const location = SourceLocation_1.SourceLocation.of(part);
58
+ const symbol = part.name === undefined ? undefined : this.symbolOf(part.name);
59
+ const declaration = symbol?.declarations?.[0];
60
+ if (declaration === undefined) {
61
+ return DocLinkReader.unresolved(written, label, location, 'the compiler cannot resolve it — import the target into this file, or fix the name');
62
+ }
63
+ if (DocLinkReader.isNamedType(declaration)) {
64
+ return this.typeLink(declaration, written, label, location, '');
65
+ }
66
+ const owner = DocLinkReader.ownerOf(declaration);
67
+ if (DocLinkReader.isNamedType(owner)) {
68
+ if (ts.isClassDeclaration(owner) && FieldDecorators_1.FieldDecorators.hasDecorator(owner, API_PATH)) {
69
+ return this.operationLink(owner, declaration, written, label, location);
70
+ }
71
+ return this.typeLink(owner, written, label, location, DocLinkReader.tailOf(part.name));
72
+ }
73
+ return DocLinkReader.unresolved(written, label, location, 'it names neither a published type nor a contract operation');
74
+ }
75
+ typeLink(declaration, written, label, location, member) {
76
+ if (ts.isClassDeclaration(declaration) &&
77
+ FieldDecorators_1.FieldDecorators.hasDecorator(declaration, API_PATH)) {
78
+ return DocLinkReader.unresolved(written, label, location, 'a contract class is not published under its own name — link one of its methods');
79
+ }
80
+ const name = declaration.name.text;
81
+ return new DocLink_1.DocLink(DocLink_1.DocLinkKind.TYPE, written, label, location, this.registry.keyFor(name, declaration), this.schemaNames.nameOf(name, declaration.getSourceFile().fileName), member, undefined, '');
82
+ }
83
+ operationLink(contract, member, written, label, location) {
84
+ if (!ts.isMethodDeclaration(member) || !FieldDecorators_1.FieldDecorators.hasDecorator(member, ENDPOINT)) {
85
+ return DocLinkReader.unresolved(written, label, location, `it names a member of contract ${contract.name?.text ?? '<anonymous>'} that is not an @${ENDPOINT} method`);
86
+ }
87
+ const tool = FieldDecorators_1.FieldDecorators.decoratorCall(member, MCP_TOOL)?.arguments[0];
88
+ return new DocLink_1.DocLink(DocLink_1.DocLinkKind.OPERATION, written, label, location, contract.name?.text ?? '<anonymous>', member.name.getText(), '', tool === undefined ? undefined : this.folder.tryFoldString(tool), '');
89
+ }
90
+ /** The declaration's symbol, through an import alias; a `#member` resolves on its right side. */
91
+ symbolOf(name) {
92
+ const symbol = this.checker.getSymbolAtLocation(name) ??
93
+ (ts.isJSDocMemberName(name) ? this.checker.getSymbolAtLocation(name.right) : undefined);
94
+ if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
95
+ return this.checker.getAliasedSymbol(symbol);
96
+ }
97
+ return symbol;
98
+ }
99
+ // webpieces-disable no-function-outside-class -- private static helper of this class
100
+ static isNamedType(node) {
101
+ return (node !== undefined &&
102
+ (ts.isClassDeclaration(node) ||
103
+ ts.isInterfaceDeclaration(node) ||
104
+ ts.isEnumDeclaration(node) ||
105
+ ts.isTypeAliasDeclaration(node)) &&
106
+ node.name !== undefined);
107
+ }
108
+ /** The type a member belongs to — through a type literal to the alias that names it. */
109
+ // webpieces-disable no-function-outside-class -- private static helper of this class
110
+ static ownerOf(member) {
111
+ const parent = member.parent;
112
+ return ts.isTypeLiteralNode(parent) && ts.isTypeAliasDeclaration(parent.parent)
113
+ ? parent.parent
114
+ : parent;
115
+ }
116
+ /** `.items` of `MenuDto.items`, `#items` of `MenuDto#items` — the tail exactly as written. */
117
+ // webpieces-disable no-function-outside-class -- private static helper of this class
118
+ static tailOf(name) {
119
+ if (ts.isQualifiedName(name)) {
120
+ return `.${name.right.text}`;
121
+ }
122
+ if (ts.isJSDocMemberName(name)) {
123
+ return `#${name.right.text}`;
124
+ }
125
+ return '';
126
+ }
127
+ /**
128
+ * `{@link https://x | Example}` -> `[Example](https://x)`, `{@link https://x}` -> `<https://x>`.
129
+ * TypeScript reads the scheme as the link's NAME and the rest as its text, so the URL is rebuilt.
130
+ */
131
+ // webpieces-disable no-function-outside-class -- private static helper of this class
132
+ static urlOf(written, text) {
133
+ const raw = `${written}${text}`.trim();
134
+ if (!URL_TARGET.test(raw) || !raw.startsWith(`${written}:`)) {
135
+ return undefined;
136
+ }
137
+ const pipe = raw.indexOf('|');
138
+ const url = pipe >= 0 ? raw.slice(0, pipe).trim() : (raw.split(/\s/)[0] ?? raw);
139
+ const label = DocLinkReader.labelOf(pipe >= 0 ? raw.slice(pipe + 1) : raw.slice(url.length));
140
+ return label === undefined ? `<${url}>` : `[${label}](${url})`;
141
+ }
142
+ /** `| the label` / ` the label` -> `the label`; nothing -> undefined. */
143
+ // webpieces-disable no-function-outside-class -- private static helper of this class
144
+ static labelOf(text) {
145
+ const label = text.replace(/^[|\s]+/, '').trim();
146
+ return label === '' ? undefined : label;
147
+ }
148
+ // webpieces-disable no-function-outside-class -- private static helper of this class
149
+ static unresolved(written, label, location, reason) {
150
+ return new DocLink_1.DocLink(DocLink_1.DocLinkKind.UNRESOLVED, written, label, location, '', '', '', undefined, reason);
151
+ }
152
+ }
153
+ exports.DocLinkReader = DocLinkReader;
154
+ //# sourceMappingURL=DocLinkReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocLinkReader.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/DocLinkReader.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,oDAAoE;AACpE,8CAAqE;AAErE,qDAAkD;AAClD,uDAAoD;AACpD,qDAAkD;AAGlD,8FAA8F;AAC9F,MAAM,QAAQ,GAAG,mBAAO,CAAC,IAAI,CAAC;AAC9B,MAAM,QAAQ,GAAG,oBAAQ,CAAC,IAAI,CAAC;AAC/B,MAAM,QAAQ,GAAG,qBAAS,CAAC,IAAI,CAAC;AAEhC,mFAAmF;AACnF,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAK7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,aAAa;IAID;IACA;IACA;IALJ,MAAM,CAAiB;IAExC,YACqB,OAAuB,EACvB,QAAsB,EACtB,WAAwB;QAFxB,YAAO,GAAP,OAAO,CAAgB;QACvB,aAAQ,GAAR,QAAQ,CAAc;QACtB,gBAAW,GAAX,WAAW,CAAa;QAEzC,IAAI,CAAC,MAAM,GAAG,IAAI,+BAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,qDAAqD;IACrD,MAAM,CAAC,IAAc;QACjB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,aAAa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ApiPath, Endpoint, WpMcpTool } from '@webpieces/core-util';\nimport { DocLink, DocLinkKind, DocLinkText } from '../model/DocLink';\nimport { SchemaNames } from '../model/SchemaNames';\nimport { ConstantFolder } from './ConstantFolder';\nimport { FieldDecorators } from './FieldDecorators';\nimport { SourceLocation } from './SourceLocation';\nimport { TypeRegistry } from './TypeRegistry';\n\n/** The decorator names, from the REAL SYMBOLS — see `ApiDocExtractor`'s constants (#1001). */\nconst API_PATH = ApiPath.name;\nconst ENDPOINT = Endpoint.name;\nconst MCP_TOOL = WpMcpTool.name;\n\n/** `https://…`, `mailto:` and friends: a link to the web, not to a declaration. */\nconst URL_TARGET = /^[a-z][a-z0-9+.-]*:\\S*/i;\n\n/** Any of TypeScript's three inline link tags. */\ntype LinkPart = ts.JSDocLink | ts.JSDocLinkCode | ts.JSDocLinkPlain;\n\n/**\n * One JSDoc `{@link}` -> the text that stands for it in model prose (#1284).\n *\n * The COMPILER resolves the target, so a link means what the editor says it means — an import alias,\n * a qualified name and a `#member` all land on the declaration itself. What it lands on decides what\n * is recorded:\n *\n * | target | recorded as |\n * |---|---|\n * | a class, interface, enum or type alias | {@link DocLinkKind.TYPE}: its model key and published schema name |\n * | a member of one (`MenuDto.items`, `Gender.F`) | {@link DocLinkKind.TYPE} of the owner, the `.member` tail kept as written |\n * | an `@Endpoint` method of an `@ApiPath` contract | {@link DocLinkKind.OPERATION}: contract, method, `@WpMcpTool` name |\n * | a URL (`{@link https://…}`) | a markdown link, written out here — it names no declaration |\n * | anything else, or nothing | {@link DocLinkKind.UNRESOLVED}, with the reason |\n *\n * Nothing is refused HERE: whether a target is published is a question about one rendered output, so\n * every renderer refuses what it cannot name, naming every offender in one run.\n */\nexport class DocLinkReader {\n private readonly folder: ConstantFolder;\n\n constructor(\n private readonly checker: ts.TypeChecker,\n private readonly registry: TypeRegistry,\n private readonly schemaNames: SchemaNames,\n ) {\n this.folder = new ConstantFolder(checker);\n }\n\n /** The text `part` contributes to a prose string. */\n textOf(part: LinkPart): string {\n const written = part.name?.getText() ?? '';\n const url = DocLinkReader.urlOf(written, part.text);\n if (url !== undefined) {\n return url;\n }\n const label = DocLinkReader.labelOf(part.text);\n return DocLinkText.encode(this.linkOf(part, written, label));\n }\n\n private linkOf(part: LinkPart, written: string, label: string | undefined): DocLink {\n const location = SourceLocation.of(part);\n const symbol = part.name === undefined ? undefined : this.symbolOf(part.name);\n const declaration = symbol?.declarations?.[0];\n if (declaration === undefined) {\n return DocLinkReader.unresolved(\n written,\n label,\n location,\n 'the compiler cannot resolve it — import the target into this file, or fix the name',\n );\n }\n if (DocLinkReader.isNamedType(declaration)) {\n return this.typeLink(declaration, written, label, location, '');\n }\n const owner = DocLinkReader.ownerOf(declaration);\n if (DocLinkReader.isNamedType(owner)) {\n if (ts.isClassDeclaration(owner) && FieldDecorators.hasDecorator(owner, API_PATH)) {\n return this.operationLink(owner, declaration, written, label, location);\n }\n return this.typeLink(owner, written, label, location, DocLinkReader.tailOf(part.name!));\n }\n return DocLinkReader.unresolved(\n written,\n label,\n location,\n 'it names neither a published type nor a contract operation',\n );\n }\n\n private typeLink(\n declaration: NamedTypeDeclaration,\n written: string,\n label: string | undefined,\n location: string,\n member: string,\n ): DocLink {\n if (\n ts.isClassDeclaration(declaration) &&\n FieldDecorators.hasDecorator(declaration, API_PATH)\n ) {\n return DocLinkReader.unresolved(\n written,\n label,\n location,\n 'a contract class is not published under its own name — link one of its methods',\n );\n }\n const name = declaration.name!.text;\n return new DocLink(\n DocLinkKind.TYPE,\n written,\n label,\n location,\n this.registry.keyFor(name, declaration),\n this.schemaNames.nameOf(name, declaration.getSourceFile().fileName),\n member,\n undefined,\n '',\n );\n }\n\n private operationLink(\n contract: ts.ClassDeclaration,\n member: ts.Declaration,\n written: string,\n label: string | undefined,\n location: string,\n ): DocLink {\n if (!ts.isMethodDeclaration(member) || !FieldDecorators.hasDecorator(member, ENDPOINT)) {\n return DocLinkReader.unresolved(\n written,\n label,\n location,\n `it names a member of contract ${contract.name?.text ?? '<anonymous>'} that is not an @${ENDPOINT} method`,\n );\n }\n const tool = FieldDecorators.decoratorCall(member, MCP_TOOL)?.arguments[0];\n return new DocLink(\n DocLinkKind.OPERATION,\n written,\n label,\n location,\n contract.name?.text ?? '<anonymous>',\n member.name.getText(),\n '',\n tool === undefined ? undefined : this.folder.tryFoldString(tool),\n '',\n );\n }\n\n /** The declaration's symbol, through an import alias; a `#member` resolves on its right side. */\n private symbolOf(name: ts.EntityName | ts.JSDocMemberName): ts.Symbol | undefined {\n const symbol =\n this.checker.getSymbolAtLocation(name) ??\n (ts.isJSDocMemberName(name) ? this.checker.getSymbolAtLocation(name.right) : undefined);\n if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {\n return this.checker.getAliasedSymbol(symbol);\n }\n return symbol;\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static isNamedType(node: ts.Node | undefined): node is NamedTypeDeclaration {\n return (\n node !== undefined &&\n (ts.isClassDeclaration(node) ||\n ts.isInterfaceDeclaration(node) ||\n ts.isEnumDeclaration(node) ||\n ts.isTypeAliasDeclaration(node)) &&\n node.name !== undefined\n );\n }\n\n /** The type a member belongs to — through a type literal to the alias that names it. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static ownerOf(member: ts.Declaration): ts.Node | undefined {\n const parent = member.parent;\n return ts.isTypeLiteralNode(parent) && ts.isTypeAliasDeclaration(parent.parent)\n ? parent.parent\n : parent;\n }\n\n /** `.items` of `MenuDto.items`, `#items` of `MenuDto#items` — the tail exactly as written. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static tailOf(name: ts.EntityName | ts.JSDocMemberName): string {\n if (ts.isQualifiedName(name)) {\n return `.${name.right.text}`;\n }\n if (ts.isJSDocMemberName(name)) {\n return `#${name.right.text}`;\n }\n return '';\n }\n\n /**\n * `{@link https://x | Example}` -> `[Example](https://x)`, `{@link https://x}` -> `<https://x>`.\n * TypeScript reads the scheme as the link's NAME and the rest as its text, so the URL is rebuilt.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static urlOf(written: string, text: string): string | undefined {\n const raw = `${written}${text}`.trim();\n if (!URL_TARGET.test(raw) || !raw.startsWith(`${written}:`)) {\n return undefined;\n }\n const pipe = raw.indexOf('|');\n const url = pipe >= 0 ? raw.slice(0, pipe).trim() : (raw.split(/\\s/)[0] ?? raw);\n const label = DocLinkReader.labelOf(\n pipe >= 0 ? raw.slice(pipe + 1) : raw.slice(url.length),\n );\n return label === undefined ? `<${url}>` : `[${label}](${url})`;\n }\n\n /** `| the label` / ` the label` -> `the label`; nothing -> undefined. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static labelOf(text: string): string | undefined {\n const label = text.replace(/^[|\\s]+/, '').trim();\n return label === '' ? undefined : label;\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static unresolved(\n written: string,\n label: string | undefined,\n location: string,\n reason: string,\n ): DocLink {\n return new DocLink(\n DocLinkKind.UNRESOLVED,\n written,\n label,\n location,\n '',\n '',\n '',\n undefined,\n reason,\n );\n }\n}\n\n/** A declaration that names a type a document can publish. */\ntype NamedTypeDeclaration = (\n | ts.ClassDeclaration\n | ts.InterfaceDeclaration\n | ts.EnumDeclaration\n | ts.TypeAliasDeclaration\n) & { name: ts.Identifier };\n"]}
@@ -1,5 +1,6 @@
1
1
  import * as ts from 'typescript';
2
2
  import { StackedJsDoc } from '../model/ApiDocModel';
3
+ import { DocLinkReader } from './DocLinkReader';
3
4
  /**
4
5
  * The PROSE half of the model: the JSDoc body, the `@summary` tag, the `@returns` tag, the `@format`
5
6
  * tag and the `@mcp` override.
@@ -10,19 +11,21 @@ import { StackedJsDoc } from '../model/ApiDocModel';
10
11
  * is dropped together with its text, and `@privateRemarks` — TSDoc's standard "inside the doc block,
11
12
  * never published" tag — is the one an author writes ON PURPOSE to keep a note out of every document:
12
13
  * OpenAPI, MCP tool catalogs, tag and schema descriptions. It is dropped HERE, at extraction, so no
13
- * renderer can ever reach it — the same reason `{@link}` is flattened here (below). `//` and `/* *\/`
14
+ * renderer can ever reach it — the same reason `{@link}` is read here (below). `//` and `/* *\/`
14
15
  * comments are private by construction: the compiler attaches no JSDoc for them.
15
16
  *
16
- * `{@link Foo.bar}` is flattened to `Foo.bar` HERE, at this boundary, and that placement is the
17
- * point: a link is a TypeScript editor affordance, and every downstream renderer — OpenAPI
18
- * `description`, an MCP tool description, an HTML page — would otherwise each have to know the inline
19
- * tag grammar and each get it slightly differently wrong. One flattening, at extraction.
17
+ * `{@link Foo.bar}` is RESOLVED here, by the compiler, into a `DocLink` encoded in the prose (#1284):
18
+ * what it points at — a type and its model key, a contract operation, or nothing publishable. It is
19
+ * not flattened to its source text, because the source name is exactly what must not be published:
20
+ * a renderer names it as it publishes — the stripped schema name, the operationId, an MCP tool's
21
+ * name — as a markdown code span, through the one grammar `DocLinkText` owns. Nothing downstream
22
+ * parses the inline tag grammar.
20
23
  */
21
24
  export declare class JsDoc {
22
25
  /**
23
- * The body text, links flattened, trimmed. Empty string when undocumented. A block TAG is never
24
- * part of it — `@summary`, `@returns` and the rest are read into their own fields (or dropped),
25
- * so the short title never repeats inside the description it heads.
26
+ * The body text, links encoded (see the class doc), trimmed. Empty string when undocumented.
27
+ * A block TAG is never part of it — `@summary`, `@returns` and the rest are read into their
28
+ * own fields (or dropped), so the short title never repeats inside the description it heads.
26
29
  */
27
30
  readonly description: string;
28
31
  /**
@@ -59,8 +62,8 @@ export declare class JsDoc {
59
62
  */
60
63
  readonly mcpHeader: string | undefined;
61
64
  private constructor();
62
- /** Read the JSDoc attached to one declaration. */
63
- static read(node: ts.Node): JsDoc;
65
+ /** Read the JSDoc attached to one declaration, resolving every `{@link}` with `links`. */
66
+ static read(node: ts.Node, links: DocLinkReader): JsDoc;
64
67
  /**
65
68
  * The {@link StackedJsDoc} record for `node` when it carries TWO OR MORE JSDoc blocks, else
66
69
  * undefined (#1286).
@@ -73,8 +76,7 @@ export declare class JsDoc {
73
76
  /** `Widget`, `Widget.name`, `save` — what an author searches the file for. */
74
77
  private static nameOf;
75
78
  /**
76
- * A comment's text with every inline tag replaced by its own text: `{@link Foo.bar}` -> `Foo.bar`,
77
- * `{@link Foo.bar|the widget}` -> `the widget`.
79
+ * A comment's text with every inline link replaced by what {@link DocLinkReader} makes of it.
78
80
  *
79
81
  * TypeScript hands a commented node either a plain string or an array of parts, and the link
80
82
  * parts are the ones with structure. Both shapes are handled here so no caller has to.
@@ -25,13 +25,15 @@ const SUMMARY_TAG = 'summary';
25
25
  * is dropped together with its text, and `@privateRemarks` — TSDoc's standard "inside the doc block,
26
26
  * never published" tag — is the one an author writes ON PURPOSE to keep a note out of every document:
27
27
  * OpenAPI, MCP tool catalogs, tag and schema descriptions. It is dropped HERE, at extraction, so no
28
- * renderer can ever reach it — the same reason `{@link}` is flattened here (below). `//` and `/* *\/`
28
+ * renderer can ever reach it — the same reason `{@link}` is read here (below). `//` and `/* *\/`
29
29
  * comments are private by construction: the compiler attaches no JSDoc for them.
30
30
  *
31
- * `{@link Foo.bar}` is flattened to `Foo.bar` HERE, at this boundary, and that placement is the
32
- * point: a link is a TypeScript editor affordance, and every downstream renderer — OpenAPI
33
- * `description`, an MCP tool description, an HTML page — would otherwise each have to know the inline
34
- * tag grammar and each get it slightly differently wrong. One flattening, at extraction.
31
+ * `{@link Foo.bar}` is RESOLVED here, by the compiler, into a `DocLink` encoded in the prose (#1284):
32
+ * what it points at — a type and its model key, a contract operation, or nothing publishable. It is
33
+ * not flattened to its source text, because the source name is exactly what must not be published:
34
+ * a renderer names it as it publishes — the stripped schema name, the operationId, an MCP tool's
35
+ * name — as a markdown code span, through the one grammar `DocLinkText` owns. Nothing downstream
36
+ * parses the inline tag grammar.
35
37
  */
36
38
  class JsDoc {
37
39
  description;
@@ -42,9 +44,9 @@ class JsDoc {
42
44
  mcpHeader;
43
45
  constructor(
44
46
  /**
45
- * The body text, links flattened, trimmed. Empty string when undocumented. A block TAG is never
46
- * part of it — `@summary`, `@returns` and the rest are read into their own fields (or dropped),
47
- * so the short title never repeats inside the description it heads.
47
+ * The body text, links encoded (see the class doc), trimmed. Empty string when undocumented.
48
+ * A block TAG is never part of it — `@summary`, `@returns` and the rest are read into their
49
+ * own fields (or dropped), so the short title never repeats inside the description it heads.
48
50
  */
49
51
  description,
50
52
  /**
@@ -87,9 +89,9 @@ class JsDoc {
87
89
  this.mcp = mcp;
88
90
  this.mcpHeader = mcpHeader;
89
91
  }
90
- /** Read the JSDoc attached to one declaration. */
92
+ /** Read the JSDoc attached to one declaration, resolving every `{@link}` with `links`. */
91
93
  // webpieces-disable no-function-outside-class -- static factory; JsDoc has a private constructor so a caller cannot invent prose
92
- static read(node) {
94
+ static read(node, links) {
93
95
  const symbolLike = node;
94
96
  const blocks = symbolLike.jsDoc ?? [];
95
97
  const bodies = [];
@@ -99,10 +101,10 @@ class JsDoc {
99
101
  let mcp;
100
102
  let mcpHeader;
101
103
  for (const block of blocks) {
102
- bodies.push(JsDoc.flatten(block.comment));
104
+ bodies.push(JsDoc.flatten(block.comment, links));
103
105
  for (const tag of block.tags ?? []) {
104
106
  const name = tag.tagName.text;
105
- const text = JsDoc.flatten(tag.comment);
107
+ const text = JsDoc.flatten(tag.comment, links);
106
108
  // `@privateRemarks` (and every tag not named below) is skipped with its text — see
107
109
  // the class doc: it is never published anywhere.
108
110
  if (name === SUMMARY_TAG && text !== '') {
@@ -155,14 +157,13 @@ class JsDoc {
155
157
  return isMember && parent.name !== undefined ? `${parent.name.getText()}.${own}` : own;
156
158
  }
157
159
  /**
158
- * A comment's text with every inline tag replaced by its own text: `{@link Foo.bar}` -> `Foo.bar`,
159
- * `{@link Foo.bar|the widget}` -> `the widget`.
160
+ * A comment's text with every inline link replaced by what {@link DocLinkReader} makes of it.
160
161
  *
161
162
  * TypeScript hands a commented node either a plain string or an array of parts, and the link
162
163
  * parts are the ones with structure. Both shapes are handled here so no caller has to.
163
164
  */
164
165
  // webpieces-disable no-function-outside-class -- private static helper of this class
165
- static flatten(comment) {
166
+ static flatten(comment, links) {
166
167
  if (comment === undefined) {
167
168
  return '';
168
169
  }
@@ -172,10 +173,7 @@ class JsDoc {
172
173
  const parts = [];
173
174
  for (const part of comment) {
174
175
  if (ts.isJSDocLink(part) || ts.isJSDocLinkCode(part) || ts.isJSDocLinkPlain(part)) {
175
- // `text` is whatever followed the target ('|the widget'); the NAME is the target.
176
- const label = part.text.replace(/^[|\s]+/, '').trim();
177
- const target = part.name ? part.name.getText() : '';
178
- parts.push(label !== '' ? label : target);
176
+ parts.push(links.textOf(part));
179
177
  }
180
178
  else {
181
179
  parts.push(part.text);
@@ -1 +1 @@
1
- {"version":3,"file":"JsDoc.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/JsDoc.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,sDAAoD;AACpD,qDAAkD;AAQlD;;;GAGG;AACH,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B;;;GAGG;AACH,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,KAAK;IAOD;IAQA;IAMA;IAEA;IAOA;IAUA;IAvCb;IACI;;;;OAIG;IACM,WAAmB;IAC5B;;;;;;OAMG;IACM,OAA2B;IACpC;;;;OAIG;IACM,OAA2B;IACpC,kEAAkE;IACzD,MAA0B;IACnC;;;;;OAKG;IACM,GAAuB;IAChC;;;;;;;;OAQG;IACM,SAA6B;QAjC7B,gBAAW,GAAX,WAAW,CAAQ;QAQnB,YAAO,GAAP,OAAO,CAAoB;QAM3B,YAAO,GAAP,OAAO,CAAoB;QAE3B,WAAM,GAAN,MAAM,CAAoB;QAO1B,QAAG,GAAH,GAAG,CAAoB;QAUvB,cAAS,GAAT,SAAS,CAAoB;IACvC,CAAC;IAEJ,kDAAkD;IAClD,iIAAiI;IACjI,MAAM,CAAC,IAAI,CAAC,IAAa;QACrB,MAAM,UAAU,GAAG,IAAoB,CAAC;QACxC,MAAM,MAAM,GAAG,U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AAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AA7ID,sBA6IC","sourcesContent":["import * as ts from 'typescript';\nimport { StackedJsDoc } from '../model/ApiDocModel';\nimport { SourceLocation } from './SourceLocation';\n\n/**\n * A node the compiler has attached JSDoc blocks to. `jsDoc` is internal to the TypeScript API and is\n * therefore not on `ts.Node`, so it is named HERE, once, instead of being cast at the use site.\n */\ntype JsDocCarrier = ts.Node & { jsDoc?: ts.JSDoc[] };\n\n/**\n * TSDoc's spelling of the success-response tag. JSDoc's older `@return` is deliberately NOT read: one\n * spelling per fact, and a refusal naming `@returns` is how an author finds out.\n */\nconst RETURNS_TAG = 'returns';\n\n/**\n * The standard JSDoc tag for an endpoint's one-line short title (#1296), published as OpenAPI\n * `summary` and MCP `title` / `annotations.title`.\n */\nconst SUMMARY_TAG = 'summary';\n\n/**\n * The PROSE half of the model: the JSDoc body, the `@summary` tag, the `@returns` tag, the `@format`\n * tag and the `@mcp` override.\n *\n * ## Every `/** *\\/` is published — except `@privateRemarks` (#1292)\n *\n * The body and the five tags named here are the ONLY text read out of a block. Every other block tag\n * is dropped together with its text, and `@privateRemarks` — TSDoc's standard \"inside the doc block,\n * never published\" tag — is the one an author writes ON PURPOSE to keep a note out of every document:\n * OpenAPI, MCP tool catalogs, tag and schema descriptions. It is dropped HERE, at extraction, so no\n * renderer can ever reach it — the same reason `{@link}` is flattened here (below). `//` and `/* *\\/`\n * comments are private by construction: the compiler attaches no JSDoc for them.\n *\n * `{@link Foo.bar}` is flattened to `Foo.bar` HERE, at this boundary, and that placement is the\n * point: a link is a TypeScript editor affordance, and every downstream renderer — OpenAPI\n * `description`, an MCP tool description, an HTML page — would otherwise each have to know the inline\n * tag grammar and each get it slightly differently wrong. One flattening, at extraction.\n */\nexport class JsDoc {\n private constructor(\n /**\n * The body text, links flattened, trimmed. Empty string when undocumented. A block TAG is never\n * part of it — `@summary`, `@returns` and the rest are read into their own fields (or dropped),\n * so the short title never repeats inside the description it heads.\n */\n readonly description: string,\n /**\n * The `@summary` block tag's text — the endpoint's one-line short title (#1296), published as\n * the OpenAPI operation `summary` and as MCP `Tool.title` AND `annotations.title`. Undefined\n * when the author wrote none (or wrote the tag with no text); the OpenAPI generator refuses\n * that for every published operation. Kept VERBATIM (trimmed): a second line is the author's\n * mistake to be told about, not something to silently join or cut.\n */\n readonly summary: string | undefined,\n /**\n * The `@returns` block tag's text — what a method's success response carries, published as\n * that response's `description` (#1292). Undefined when the author wrote none (or wrote the\n * tag with no text), which an OpenAPI renderer refuses for an operation with a body.\n */\n readonly returns: string | undefined,\n /** The `@format` block tag's text, e.g. `email` / `date-time`. */\n readonly format: string | undefined,\n /**\n * The `@mcp` block tag's text — the OPTIONAL agent-facing override. Undefined means the\n * author wrote none, which a renderer answers by falling back to {@link description}. The\n * fallback is NOT applied here: \"the author wrote an agent-facing sentence\" and \"we reused\n * the human one\" are different facts, and only the first is worth trusting.\n */\n readonly mcp: string | undefined,\n /**\n * The `@mcpHeader <token>` block tag — the MCP 2026 SEP-2243 header a PRIMITIVE tool\n * parameter is mirrored into (`Mcp-Param-{token}`).\n *\n * It is a JSDoc tag and not a decorator because it is a DOCUMENTATION fact about one field\n * of one wire document, and this epic's rule is that documentation has one source. It is the\n * ONLY spelling: the equivalence gate (#983) proved the deleted decorator argument said the\n * same thing, and #984 deleted it.\n */\n readonly mcpHeader: string | undefined,\n ) {}\n\n /** Read the JSDoc attached to one declaration. */\n // webpieces-disable no-function-outside-class -- static factory; JsDoc has a private constructor so a caller cannot invent prose\n static read(node: ts.Node): JsDoc {\n const symbolLike = node as JsDocCarrier;\n const blocks = symbolLike.jsDoc ?? [];\n const bodies: string[] = [];\n let summary: string | undefined;\n let returns: string | undefined;\n let format: string | undefined;\n let mcp: string | undefined;\n let mcpHeader: string | undefined;\n\n for (const block of blocks) {\n bodies.push(JsDoc.flatten(block.comment));\n for (const tag of block.tags ?? []) {\n const name = tag.tagName.text;\n const text = JsDoc.flatten(tag.comment);\n // `@privateRemarks` (and every tag not named below) is skipped with its text — see\n // the class doc: it is never published anywhere.\n if (name === SUMMARY_TAG && text !== '') {\n summary = text;\n } else if (name === RETURNS_TAG && text !== '') {\n returns = text;\n } else if (name === 'format' && text !== '') {\n format = text;\n } else if (name === 'mcp' && text !== '') {\n mcp = text;\n } else if (name === 'mcpHeader' && text !== '') {\n mcpHeader = text;\n }\n }\n }\n\n return new JsDoc(bodies.join('\\n').trim(), summary, returns, format, mcp, mcpHeader);\n }\n\n /**\n * The {@link StackedJsDoc} record for `node` when it carries TWO OR MORE JSDoc blocks, else\n * undefined (#1286).\n *\n * A declaration under `node_modules` is never recorded: it is a published package's to own, its\n * author cannot be handed the cure from here, and that package's own generation is what refuses it\n * — the same line the wire closure draws.\n */\n // webpieces-disable no-function-outside-class -- static reader beside read(); both interpret the same jsDoc array\n static stackedAt(node: ts.Node): StackedJsDoc | undefined {\n const blocks = (node as JsDocCarrier).jsDoc ?? [];\n if (blocks.length < 2) {\n return undefined;\n }\n const file = node.getSourceFile();\n if (file.fileName.includes('/node_modules/')) {\n return undefined;\n }\n const blockLines = blocks.map(\n (block: ts.JSDoc) => file.getLineAndCharacterOfPosition(block.getStart(file)).line + 1,\n );\n return new StackedJsDoc(JsDoc.nameOf(node), SourceLocation.of(node), blockLines);\n }\n\n /** `Widget`, `Widget.name`, `save` — what an author searches the file for. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static nameOf(node: ts.Node): string {\n const name = (node as ts.NamedDeclaration).name;\n const own = name !== undefined ? name.getText() : ts.SyntaxKind[node.kind];\n const parent = node.parent as ts.NamedDeclaration | undefined;\n const isMember = parent !== undefined && (ts.isClassLike(parent) || ts.isInterfaceDeclaration(parent));\n return isMember && parent.name !== undefined ? `${parent.name.getText()}.${own}` : own;\n }\n\n /**\n * A comment's text with every inline tag replaced by its own text: `{@link Foo.bar}` -> `Foo.bar`,\n * `{@link Foo.bar|the widget}` -> `the widget`.\n *\n * TypeScript hands a commented node either a plain string or an array of parts, and the link\n * parts are the ones with structure. Both shapes are handled here so no caller has to.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static flatten(comment: string | ts.NodeArray<ts.JSDocComment> | undefined): string {\n if (comment === undefined) {\n return '';\n }\n if (typeof comment === 'string') {\n return comment.trim();\n }\n const parts: string[] = [];\n for (const part of comment) {\n if (ts.isJSDocLink(part) || ts.isJSDocLinkCode(part) || ts.isJSDocLinkPlain(part)) {\n // `text` is whatever followed the target ('|the widget'); the NAME is the target.\n const label = part.text.replace(/^[|\\s]+/, '').trim();\n const target = part.name ? part.name.getText() : '';\n parts.push(label !== '' ? label : target);\n } else {\n parts.push(part.text);\n }\n }\n return parts.join('').trim();\n }\n}\n"]}
1
+ {"version":3,"file":"JsDoc.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/JsDoc.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,sDAAoD;AAEpD,qDAAkD;AAQlD;;;GAGG;AACH,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B;;;GAGG;AACH,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,KAAK;IAOD;IAQA;IAMA;IAEA;IAOA;IAUA;IAvCb;IACI;;;;OAIG;IACM,WAAmB;IAC5B;;;;;;OAMG;IACM,OAA2B;IACpC;;;;OAIG;IACM,OAA2B;IACpC,kEAAkE;IACzD,MAA0B;IACnC;;;;;OAKG;IACM,GAAuB;IAChC;;;;;;;;OAQG;IACM,SAA6B;QAjC7B,gBAAW,GAAX,WAAW,CAAQ;QAQnB,YAAO,GAAP,OAAO,CAAoB;QAM3B,YAAO,GAAP,OAAO,CAAoB;QAE3B,WAAM,GAAN,MAAM,CAAoB;QAO1B,QAAG,GAAH,GAAG,CAAoB;QAUvB,cAAS,GAAT,SAAS,CAAoB;IACvC,CAAC;IAEJ,0FAA0F;IAC1F,iIAAiI;IACjI,MAAM,CAAC,IAAI,CAAC,IA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AAC,MAAyC,CAAC;QAC9D,MAAM,QAAQ,GACV,MAAM,KAAK,SAAS,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1F,OAAO,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3F,CAAC;IAED;;;;;OAKG;IACH,qFAAqF;IAC7E,MAAM,CAAC,OAAO,CAClB,OAA2D,EAC3D,KAAoB;QAEpB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,CAAC;QACd,CAAC;QACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YACzB,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AA7ID,sBA6IC","sourcesContent":["import * as ts from 'typescript';\nimport { StackedJsDoc } from '../model/ApiDocModel';\nimport { DocLinkReader } from './DocLinkReader';\nimport { SourceLocation } from './SourceLocation';\n\n/**\n * A node the compiler has attached JSDoc blocks to. `jsDoc` is internal to the TypeScript API and is\n * therefore not on `ts.Node`, so it is named HERE, once, instead of being cast at the use site.\n */\ntype JsDocCarrier = ts.Node & { jsDoc?: ts.JSDoc[] };\n\n/**\n * TSDoc's spelling of the success-response tag. JSDoc's older `@return` is deliberately NOT read: one\n * spelling per fact, and a refusal naming `@returns` is how an author finds out.\n */\nconst RETURNS_TAG = 'returns';\n\n/**\n * The standard JSDoc tag for an endpoint's one-line short title (#1296), published as OpenAPI\n * `summary` and MCP `title` / `annotations.title`.\n */\nconst SUMMARY_TAG = 'summary';\n\n/**\n * The PROSE half of the model: the JSDoc body, the `@summary` tag, the `@returns` tag, the `@format`\n * tag and the `@mcp` override.\n *\n * ## Every `/** *\\/` is published — except `@privateRemarks` (#1292)\n *\n * The body and the five tags named here are the ONLY text read out of a block. Every other block tag\n * is dropped together with its text, and `@privateRemarks` — TSDoc's standard \"inside the doc block,\n * never published\" tag — is the one an author writes ON PURPOSE to keep a note out of every document:\n * OpenAPI, MCP tool catalogs, tag and schema descriptions. It is dropped HERE, at extraction, so no\n * renderer can ever reach it — the same reason `{@link}` is read here (below). `//` and `/* *\\/`\n * comments are private by construction: the compiler attaches no JSDoc for them.\n *\n * `{@link Foo.bar}` is RESOLVED here, by the compiler, into a `DocLink` encoded in the prose (#1284):\n * what it points at — a type and its model key, a contract operation, or nothing publishable. It is\n * not flattened to its source text, because the source name is exactly what must not be published:\n * a renderer names it as it publishes — the stripped schema name, the operationId, an MCP tool's\n * name — as a markdown code span, through the one grammar `DocLinkText` owns. Nothing downstream\n * parses the inline tag grammar.\n */\nexport class JsDoc {\n private constructor(\n /**\n * The body text, links encoded (see the class doc), trimmed. Empty string when undocumented.\n * A block TAG is never part of it — `@summary`, `@returns` and the rest are read into their\n * own fields (or dropped), so the short title never repeats inside the description it heads.\n */\n readonly description: string,\n /**\n * The `@summary` block tag's text — the endpoint's one-line short title (#1296), published as\n * the OpenAPI operation `summary` and as MCP `Tool.title` AND `annotations.title`. Undefined\n * when the author wrote none (or wrote the tag with no text); the OpenAPI generator refuses\n * that for every published operation. Kept VERBATIM (trimmed): a second line is the author's\n * mistake to be told about, not something to silently join or cut.\n */\n readonly summary: string | undefined,\n /**\n * The `@returns` block tag's text — what a method's success response carries, published as\n * that response's `description` (#1292). Undefined when the author wrote none (or wrote the\n * tag with no text), which an OpenAPI renderer refuses for an operation with a body.\n */\n readonly returns: string | undefined,\n /** The `@format` block tag's text, e.g. `email` / `date-time`. */\n readonly format: string | undefined,\n /**\n * The `@mcp` block tag's text — the OPTIONAL agent-facing override. Undefined means the\n * author wrote none, which a renderer answers by falling back to {@link description}. The\n * fallback is NOT applied here: \"the author wrote an agent-facing sentence\" and \"we reused\n * the human one\" are different facts, and only the first is worth trusting.\n */\n readonly mcp: string | undefined,\n /**\n * The `@mcpHeader <token>` block tag — the MCP 2026 SEP-2243 header a PRIMITIVE tool\n * parameter is mirrored into (`Mcp-Param-{token}`).\n *\n * It is a JSDoc tag and not a decorator because it is a DOCUMENTATION fact about one field\n * of one wire document, and this epic's rule is that documentation has one source. It is the\n * ONLY spelling: the equivalence gate (#983) proved the deleted decorator argument said the\n * same thing, and #984 deleted it.\n */\n readonly mcpHeader: string | undefined,\n ) {}\n\n /** Read the JSDoc attached to one declaration, resolving every `{@link}` with `links`. */\n // webpieces-disable no-function-outside-class -- static factory; JsDoc has a private constructor so a caller cannot invent prose\n static read(node: ts.Node, links: DocLinkReader): JsDoc {\n const symbolLike = node as JsDocCarrier;\n const blocks = symbolLike.jsDoc ?? [];\n const bodies: string[] = [];\n let summary: string | undefined;\n let returns: string | undefined;\n let format: string | undefined;\n let mcp: string | undefined;\n let mcpHeader: string | undefined;\n\n for (const block of blocks) {\n bodies.push(JsDoc.flatten(block.comment, links));\n for (const tag of block.tags ?? []) {\n const name = tag.tagName.text;\n const text = JsDoc.flatten(tag.comment, links);\n // `@privateRemarks` (and every tag not named below) is skipped with its text — see\n // the class doc: it is never published anywhere.\n if (name === SUMMARY_TAG && text !== '') {\n summary = text;\n } else if (name === RETURNS_TAG && text !== '') {\n returns = text;\n } else if (name === 'format' && text !== '') {\n format = text;\n } else if (name === 'mcp' && text !== '') {\n mcp = text;\n } else if (name === 'mcpHeader' && text !== '') {\n mcpHeader = text;\n }\n }\n }\n\n return new JsDoc(bodies.join('\\n').trim(), summary, returns, format, mcp, mcpHeader);\n }\n\n /**\n * The {@link StackedJsDoc} record for `node` when it carries TWO OR MORE JSDoc blocks, else\n * undefined (#1286).\n *\n * A declaration under `node_modules` is never recorded: it is a published package's to own, its\n * author cannot be handed the cure from here, and that package's own generation is what refuses it\n * — the same line the wire closure draws.\n */\n // webpieces-disable no-function-outside-class -- static reader beside read(); both interpret the same jsDoc array\n static stackedAt(node: ts.Node): StackedJsDoc | undefined {\n const blocks = (node as JsDocCarrier).jsDoc ?? [];\n if (blocks.length < 2) {\n return undefined;\n }\n const file = node.getSourceFile();\n if (file.fileName.includes('/node_modules/')) {\n return undefined;\n }\n const blockLines = blocks.map(\n (block: ts.JSDoc) => file.getLineAndCharacterOfPosition(block.getStart(file)).line + 1,\n );\n return new StackedJsDoc(JsDoc.nameOf(node), SourceLocation.of(node), blockLines);\n }\n\n /** `Widget`, `Widget.name`, `save` — what an author searches the file for. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static nameOf(node: ts.Node): string {\n const name = (node as ts.NamedDeclaration).name;\n const own = name !== undefined ? name.getText() : ts.SyntaxKind[node.kind];\n const parent = node.parent as ts.NamedDeclaration | undefined;\n const isMember =\n parent !== undefined && (ts.isClassLike(parent) || ts.isInterfaceDeclaration(parent));\n return isMember && parent.name !== undefined ? `${parent.name.getText()}.${own}` : own;\n }\n\n /**\n * A comment's text with every inline link replaced by what {@link DocLinkReader} makes of it.\n *\n * TypeScript hands a commented node either a plain string or an array of parts, and the link\n * parts are the ones with structure. Both shapes are handled here so no caller has to.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static flatten(\n comment: string | ts.NodeArray<ts.JSDocComment> | undefined,\n links: DocLinkReader,\n ): string {\n if (comment === undefined) {\n return '';\n }\n if (typeof comment === 'string') {\n return comment.trim();\n }\n const parts: string[] = [];\n for (const part of comment) {\n if (ts.isJSDocLink(part) || ts.isJSDocLinkCode(part) || ts.isJSDocLinkPlain(part)) {\n parts.push(links.textOf(part));\n } else {\n parts.push(part.text);\n }\n }\n return parts.join('').trim();\n }\n}\n"]}
@@ -46,6 +46,8 @@ export declare class TypeResolver {
46
46
  /** Anonymous type literals currently being expanded — the cycle stop for the ANONYMOUS case. */
47
47
  private readonly expandingAnonymous;
48
48
  private readonly bases;
49
+ /** Resolves every `{@link}` in the prose this resolver reads (#1284). */
50
+ private readonly links;
49
51
  constructor(checker: ts.TypeChecker, packages: PackageOfFile,
50
52
  /** The package of the file being extracted — its types are keyed by their bare name. */
51
53
  homePackage: string | undefined, schemaNames: SchemaNames);
@@ -6,6 +6,7 @@ const ts = tslib_1.__importStar(require("typescript"));
6
6
  const core_util_1 = require("@webpieces/core-util");
7
7
  const ApiDocModel_1 = require("../model/ApiDocModel");
8
8
  const TypeRef_1 = require("../model/TypeRef");
9
+ const DocLinkReader_1 = require("./DocLinkReader");
9
10
  const JsDoc_1 = require("./JsDoc");
10
11
  const ObjectShapeBases_1 = require("./ObjectShapeBases");
11
12
  const FieldDecorators_1 = require("./FieldDecorators");
@@ -73,12 +74,15 @@ class TypeResolver {
73
74
  /** Anonymous type literals currently being expanded — the cycle stop for the ANONYMOUS case. */
74
75
  expandingAnonymous = new Set();
75
76
  bases;
77
+ /** Resolves every `{@link}` in the prose this resolver reads (#1284). */
78
+ links;
76
79
  constructor(checker, packages,
77
80
  /** The package of the file being extracted — its types are keyed by their bare name. */
78
81
  homePackage, schemaNames) {
79
82
  this.schemaNames = schemaNames;
80
83
  this.bases = new ObjectShapeBases_1.ObjectShapeBases(checker);
81
84
  this.registry = new TypeRegistry_1.TypeRegistry(packages, homePackage, schemaNames);
85
+ this.links = new DocLinkReader_1.DocLinkReader(checker, this.registry, schemaNames);
82
86
  }
83
87
  /** Every named type reached so far, by key — see {@link DocumentedType.keyOf}. */
84
88
  collectedTypes() {
@@ -103,7 +107,7 @@ class TypeResolver {
103
107
  if (stacked !== undefined && !this.stacked.has(stacked.location)) {
104
108
  this.stacked.set(stacked.location, stacked);
105
109
  }
106
- return JsDoc_1.JsDoc.read(node);
110
+ return JsDoc_1.JsDoc.read(node, this.links);
107
111
  }
108
112
  /** Same-named, different declarations in one package — see {@link TypeNameCollision}. */
109
113
  collectedCollisions() {