@webpieces/api-doc-model 0.4.940 → 0.4.942
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.
|
|
3
|
+
"version": "0.4.942",
|
|
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.
|
|
26
|
+
"@webpieces/core-util": "0.4.942",
|
|
27
27
|
"typescript": "5.9.3",
|
|
28
28
|
"minimatch": "10.0.1"
|
|
29
29
|
}
|
|
@@ -14,6 +14,7 @@ type LinkPart = ts.JSDocLink | ts.JSDocLinkCode | ts.JSDocLinkPlain;
|
|
|
14
14
|
* |---|---|
|
|
15
15
|
* | a class, interface, enum or type alias | {@link DocLinkKind.TYPE}: its model key and published schema name |
|
|
16
16
|
* | a member of one (`MenuDto.items`, `Gender.F`) | {@link DocLinkKind.TYPE} of the owner, the `.member` tail kept as written |
|
|
17
|
+
* | a member written BARE (`{@link storeId}` in a sibling's JSDoc) | {@link DocLinkKind.MEMBER}: the member's published name, no owner prefix |
|
|
17
18
|
* | an `@Endpoint` method of an `@ApiPath` contract | {@link DocLinkKind.OPERATION}: contract, method, `@WpMcpTool` name |
|
|
18
19
|
* | a URL (`{@link https://…}`) | a markdown link, written out here — it names no declaration |
|
|
19
20
|
* | anything else, or nothing | {@link DocLinkKind.UNRESOLVED}, with the reason |
|
|
@@ -31,12 +32,26 @@ export declare class DocLinkReader {
|
|
|
31
32
|
textOf(part: LinkPart): string;
|
|
32
33
|
private linkOf;
|
|
33
34
|
private typeLink;
|
|
35
|
+
/**
|
|
36
|
+
* A member written bare (#1308). TypeScript resolves `{@link storeId}` in a member's JSDoc to the
|
|
37
|
+
* property of the enclosing class or interface — its own, or one it inherits — so the owner here is
|
|
38
|
+
* the type that DECLARES it, which may be a base the document flattens away. Nothing about that
|
|
39
|
+
* owner is checked: the published name is the member's own, read the way the field is.
|
|
40
|
+
*/
|
|
41
|
+
private memberLink;
|
|
34
42
|
private operationLink;
|
|
35
43
|
/** The declaration's symbol, through an import alias; a `#member` resolves on its right side. */
|
|
36
44
|
private symbolOf;
|
|
37
45
|
private static isNamedType;
|
|
38
46
|
/** The type a member belongs to — through a type literal to the alias that names it. */
|
|
39
47
|
private static ownerOf;
|
|
48
|
+
/**
|
|
49
|
+
* The published name of a member the link names BARE — an identifier, not `Type.member` /
|
|
50
|
+
* `Type#member` — read exactly as `TypeResolver` names a field (an identifier's or a quoted
|
|
51
|
+
* name's text; nothing renames a property on the wire). Undefined when the link is qualified or
|
|
52
|
+
* the member has no such name.
|
|
53
|
+
*/
|
|
54
|
+
private static bareMemberName;
|
|
40
55
|
/** `.items` of `MenuDto.items`, `#items` of `MenuDto#items` — the tail exactly as written. */
|
|
41
56
|
private static tailOf;
|
|
42
57
|
/**
|
|
@@ -25,6 +25,7 @@ const URL_TARGET = /^[a-z][a-z0-9+.-]*:\S*/i;
|
|
|
25
25
|
* |---|---|
|
|
26
26
|
* | a class, interface, enum or type alias | {@link DocLinkKind.TYPE}: its model key and published schema name |
|
|
27
27
|
* | a member of one (`MenuDto.items`, `Gender.F`) | {@link DocLinkKind.TYPE} of the owner, the `.member` tail kept as written |
|
|
28
|
+
* | a member written BARE (`{@link storeId}` in a sibling's JSDoc) | {@link DocLinkKind.MEMBER}: the member's published name, no owner prefix |
|
|
28
29
|
* | an `@Endpoint` method of an `@ApiPath` contract | {@link DocLinkKind.OPERATION}: contract, method, `@WpMcpTool` name |
|
|
29
30
|
* | a URL (`{@link https://…}`) | a markdown link, written out here — it names no declaration |
|
|
30
31
|
* | anything else, or nothing | {@link DocLinkKind.UNRESOLVED}, with the reason |
|
|
@@ -68,6 +69,10 @@ class DocLinkReader {
|
|
|
68
69
|
if (ts.isClassDeclaration(owner) && FieldDecorators_1.FieldDecorators.hasDecorator(owner, API_PATH)) {
|
|
69
70
|
return this.operationLink(owner, declaration, written, label, location);
|
|
70
71
|
}
|
|
72
|
+
const bare = DocLinkReader.bareMemberName(part.name, declaration);
|
|
73
|
+
if (bare !== undefined) {
|
|
74
|
+
return this.memberLink(owner, bare, written, label, location);
|
|
75
|
+
}
|
|
71
76
|
return this.typeLink(owner, written, label, location, DocLinkReader.tailOf(part.name));
|
|
72
77
|
}
|
|
73
78
|
return DocLinkReader.unresolved(written, label, location, 'it names neither a published type nor a contract operation');
|
|
@@ -80,6 +85,16 @@ class DocLinkReader {
|
|
|
80
85
|
const name = declaration.name.text;
|
|
81
86
|
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
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* A member written bare (#1308). TypeScript resolves `{@link storeId}` in a member's JSDoc to the
|
|
90
|
+
* property of the enclosing class or interface — its own, or one it inherits — so the owner here is
|
|
91
|
+
* the type that DECLARES it, which may be a base the document flattens away. Nothing about that
|
|
92
|
+
* owner is checked: the published name is the member's own, read the way the field is.
|
|
93
|
+
*/
|
|
94
|
+
memberLink(owner, member, written, label, location) {
|
|
95
|
+
const name = owner.name.text;
|
|
96
|
+
return new DocLink_1.DocLink(DocLink_1.DocLinkKind.MEMBER, written, label, location, this.registry.keyFor(name, owner), this.schemaNames.nameOf(name, owner.getSourceFile().fileName), member, undefined, '');
|
|
97
|
+
}
|
|
83
98
|
operationLink(contract, member, written, label, location) {
|
|
84
99
|
if (!ts.isMethodDeclaration(member) || !FieldDecorators_1.FieldDecorators.hasDecorator(member, ENDPOINT)) {
|
|
85
100
|
return DocLinkReader.unresolved(written, label, location, `it names a member of contract ${contract.name?.text ?? '<anonymous>'} that is not an @${ENDPOINT} method`);
|
|
@@ -113,6 +128,24 @@ class DocLinkReader {
|
|
|
113
128
|
? parent.parent
|
|
114
129
|
: parent;
|
|
115
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* The published name of a member the link names BARE — an identifier, not `Type.member` /
|
|
133
|
+
* `Type#member` — read exactly as `TypeResolver` names a field (an identifier's or a quoted
|
|
134
|
+
* name's text; nothing renames a property on the wire). Undefined when the link is qualified or
|
|
135
|
+
* the member has no such name.
|
|
136
|
+
*/
|
|
137
|
+
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
138
|
+
static bareMemberName(name, member) {
|
|
139
|
+
if (!ts.isIdentifier(name)) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
const memberName = member.name;
|
|
143
|
+
if (memberName === undefined ||
|
|
144
|
+
(!ts.isIdentifier(memberName) && !ts.isStringLiteral(memberName))) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return memberName.text;
|
|
148
|
+
}
|
|
116
149
|
/** `.items` of `MenuDto.items`, `#items` of `MenuDto#items` — the tail exactly as written. */
|
|
117
150
|
// webpieces-disable no-function-outside-class -- private static helper of this class
|
|
118
151
|
static tailOf(name) {
|
|
@@ -1 +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;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,CAAC,IAAY;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5C,CAAC;IAED,qFAAqF;IAC7E,MAAM,CAAC,UAAU,CACrB,OAAe,EACf,KAAyB,EACzB,QAAgB,EAChB,MAAc;QAEd,OAAO,IAAI,iBAAO,CACd,qBAAW,CAAC,UAAU,EACtB,OAAO,EACP,KAAK,EACL,QAAQ,EACR,EAAE,EACF,EAAE,EACF,EAAE,EACF,SAAS,EACT,MAAM,CACT,CAAC;IACN,CAAC;CACJ;AAzMD,sCAyMC","sourcesContent":["import * as ts from 'typescript';\nimport { 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
|
+
{"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;;;;;;;;;;;;;;;;;;GAkBG;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,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,OAAO,qBAAW,CAAC,MAAM,CAAC,IAAI,CAAC,M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F,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAC/B,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAC1D,CAAC;QACF,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,GAAG,GAAG,CAAC;IACnE,CAAC;IAED,yEAAyE;IACzE,qFAAqF;IAC7E,MAAM,CAAC,OAAO,CAAC,IAAY;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5C,CAAC;IAED,qFAAqF;IAC7E,MAAM,CAAC,UAAU,CACrB,OAAe,EACf,KAAyB,EACzB,QAAgB,EAChB,MAAc;QAEd,OAAO,IAAI,iBAAO,CACd,qBAAW,CAAC,UAAU,EACtB,OAAO,EACP,KAAK,EACL,QAAQ,EACR,EAAE,EACF,EAAE,EACF,EAAE,EACF,SAAS,EACT,MAAM,CACT,CAAC;IACN,CAAC;CACJ;AAhQD,sCAgQC","sourcesContent":["import * as ts from 'typescript';\nimport { 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 * | a member written BARE (`{@link storeId}` in a sibling's JSDoc) | {@link DocLinkKind.MEMBER}: the member's published name, no owner prefix |\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 const bare = DocLinkReader.bareMemberName(part.name!, declaration);\n if (bare !== undefined) {\n return this.memberLink(owner, bare, 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 /**\n * A member written bare (#1308). TypeScript resolves `{@link storeId}` in a member's JSDoc to the\n * property of the enclosing class or interface — its own, or one it inherits — so the owner here is\n * the type that DECLARES it, which may be a base the document flattens away. Nothing about that\n * owner is checked: the published name is the member's own, read the way the field is.\n */\n private memberLink(\n owner: NamedTypeDeclaration,\n member: string,\n written: string,\n label: string | undefined,\n location: string,\n ): DocLink {\n const name = owner.name.text;\n return new DocLink(\n DocLinkKind.MEMBER,\n written,\n label,\n location,\n this.registry.keyFor(name, owner),\n this.schemaNames.nameOf(name, owner.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 /**\n * The published name of a member the link names BARE — an identifier, not `Type.member` /\n * `Type#member` — read exactly as `TypeResolver` names a field (an identifier's or a quoted\n * name's text; nothing renames a property on the wire). Undefined when the link is qualified or\n * the member has no such name.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static bareMemberName(\n name: ts.EntityName | ts.JSDocMemberName,\n member: ts.Declaration,\n ): string | undefined {\n if (!ts.isIdentifier(name)) {\n return undefined;\n }\n const memberName = (member as ts.NamedDeclaration).name;\n if (\n memberName === undefined ||\n (!ts.isIdentifier(memberName) && !ts.isStringLiteral(memberName))\n ) {\n return undefined;\n }\n return memberName.text;\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"]}
|
package/src/model/DocLink.d.ts
CHANGED
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
export declare enum DocLinkKind {
|
|
14
14
|
/** A named type — class, interface, enum or alias — optionally with a `.member` tail. */
|
|
15
15
|
TYPE = "type",
|
|
16
|
+
/**
|
|
17
|
+
* A member — property or enum member — written BARE (`{@link storeId}`), as TypeScript resolves
|
|
18
|
+
* it inside a member's own JSDoc: a sibling, or one its type inherits (#1308). Published as the
|
|
19
|
+
* member's own name, with no type prefix, because the reader is already on that schema — the one
|
|
20
|
+
* the member is a field of, its inherited fields flattened in. Every output publishes it.
|
|
21
|
+
*/
|
|
22
|
+
MEMBER = "member",
|
|
16
23
|
/** A method of an `@ApiPath` contract: a published operation. */
|
|
17
24
|
OPERATION = "operation",
|
|
18
25
|
/** A target that names nothing any document publishes. Always refused by a renderer. */
|
|
@@ -34,7 +41,11 @@ export declare class DocLink {
|
|
|
34
41
|
*/
|
|
35
42
|
readonly owner: string;
|
|
36
43
|
readonly ownerName: string;
|
|
37
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty.
|
|
46
|
+
* {@link DocLinkKind.MEMBER}: the member's published name (`storeId`), the type it is
|
|
47
|
+
* declared on in `owner` / `ownerName`.
|
|
48
|
+
*/
|
|
38
49
|
readonly member: string;
|
|
39
50
|
/** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */
|
|
40
51
|
readonly mcpToolName: string | undefined;
|
|
@@ -53,7 +64,11 @@ export declare class DocLink {
|
|
|
53
64
|
* method name. Empty for the other kinds.
|
|
54
65
|
*/
|
|
55
66
|
owner: string, ownerName: string,
|
|
56
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty.
|
|
69
|
+
* {@link DocLinkKind.MEMBER}: the member's published name (`storeId`), the type it is
|
|
70
|
+
* declared on in `owner` / `ownerName`.
|
|
71
|
+
*/
|
|
57
72
|
member: string,
|
|
58
73
|
/** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */
|
|
59
74
|
mcpToolName: string | undefined,
|
|
@@ -97,6 +112,7 @@ export interface DocLinkNaming {
|
|
|
97
112
|
* |---|---|
|
|
98
113
|
* | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |
|
|
99
114
|
* | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |
|
|
115
|
+
* | `{@link storeId}`, from a sibling field's JSDoc | `` `storeId` `` (the field's own name — no type prefix) |
|
|
100
116
|
* | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |
|
|
101
117
|
* | `{@link OrdersApi.fetchOrders \| the order list}` | `the order list (`fetchOrders`)` |
|
|
102
118
|
*
|
package/src/model/DocLink.js
CHANGED
|
@@ -17,6 +17,13 @@ var DocLinkKind;
|
|
|
17
17
|
(function (DocLinkKind) {
|
|
18
18
|
/** A named type — class, interface, enum or alias — optionally with a `.member` tail. */
|
|
19
19
|
DocLinkKind["TYPE"] = "type";
|
|
20
|
+
/**
|
|
21
|
+
* A member — property or enum member — written BARE (`{@link storeId}`), as TypeScript resolves
|
|
22
|
+
* it inside a member's own JSDoc: a sibling, or one its type inherits (#1308). Published as the
|
|
23
|
+
* member's own name, with no type prefix, because the reader is already on that schema — the one
|
|
24
|
+
* the member is a field of, its inherited fields flattened in. Every output publishes it.
|
|
25
|
+
*/
|
|
26
|
+
DocLinkKind["MEMBER"] = "member";
|
|
20
27
|
/** A method of an `@ApiPath` contract: a published operation. */
|
|
21
28
|
DocLinkKind["OPERATION"] = "operation";
|
|
22
29
|
/** A target that names nothing any document publishes. Always refused by a renderer. */
|
|
@@ -46,7 +53,11 @@ class DocLink {
|
|
|
46
53
|
* method name. Empty for the other kinds.
|
|
47
54
|
*/
|
|
48
55
|
owner, ownerName,
|
|
49
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty.
|
|
58
|
+
* {@link DocLinkKind.MEMBER}: the member's published name (`storeId`), the type it is
|
|
59
|
+
* declared on in `owner` / `ownerName`.
|
|
60
|
+
*/
|
|
50
61
|
member,
|
|
51
62
|
/** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */
|
|
52
63
|
mcpToolName,
|
|
@@ -101,6 +112,7 @@ const ENCODED = /([^]*)/g;
|
|
|
101
112
|
* |---|---|
|
|
102
113
|
* | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |
|
|
103
114
|
* | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |
|
|
115
|
+
* | `{@link storeId}`, from a sibling field's JSDoc | `` `storeId` `` (the field's own name — no type prefix) |
|
|
104
116
|
* | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |
|
|
105
117
|
* | `{@link OrdersApi.fetchOrders \| the order list}` | `the order list (`fetchOrders`)` |
|
|
106
118
|
*
|
|
@@ -158,6 +170,9 @@ class DocLinkText {
|
|
|
158
170
|
static resolve(text, naming, output, problems) {
|
|
159
171
|
return text.replace(ENCODED, (_all, body) => {
|
|
160
172
|
const link = DocLinkText.decode(body);
|
|
173
|
+
if (link.kind === DocLinkKind.MEMBER) {
|
|
174
|
+
return DocLinkText.spell(link, link.member);
|
|
175
|
+
}
|
|
161
176
|
const name = link.kind === DocLinkKind.UNRESOLVED ? undefined : naming.publishedName(link);
|
|
162
177
|
if (name === undefined) {
|
|
163
178
|
problems.push(new DocLinkProblem(link.location, link.written, DocLinkText.why(link, output)));
|
package/src/model/DocLink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocLink.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/DocLink.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,IAAY,WAOX;AAPD,WAAY,WAAW;IACnB,yFAAyF;IACzF,4BAAa,CAAA;IACb,iEAAiE;IACjE,sCAAuB,CAAA;IACvB,wFAAwF;IACxF,wCAAyB,CAAA;AAC7B,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB;AAED,0FAA0F;AAC1F,MAAa,OAAO;IAEH;IAEA;IAEA;IAEA;IAMA;IACA;IAEA;IAEA;IAEA;IApBb,YACa,IAAiB;IAC1B,gFAAgF;IACvE,OAAe;IACxB,6FAA6F;IACpF,KAAyB;IAClC,4FAA4F;IACnF,QAAgB;IACzB;;;;OAIG;IACM,KAAa,EACb,SAAiB;IAC1B,8FAA8F;IACrF,MAAc;IACvB,wFAAwF;IAC/E,WAA+B;IACxC,uFAAuF;IAC9E,MAAc;QAnBd,SAAI,GAAJ,IAAI,CAAa;QAEjB,YAAO,GAAP,OAAO,CAAQ;QAEf,UAAK,GAAL,KAAK,CAAoB;QAEzB,aAAQ,GAAR,QAAQ,CAAQ;QAMhB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAQ;QAEjB,WAAM,GAAN,MAAM,CAAQ;QAEd,gBAAW,GAAX,WAAW,CAAoB;QAE/B,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAvBD,0BAuBC;AAED,gGAAgG;AAChG,MAAa,cAAc;IAGV;IAEA;IAEA;IANb;IACI,wDAAwD;IAC/C,QAAgB;IACzB,6BAA6B;IACpB,OAAe;IACxB,0BAA0B;IACjB,MAAc;QAJd,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,YAAO,GAAP,OAAO,CAAQ;QAEf,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;IAEJ,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oc `{@link X}` names, as the COMPILER resolved it at extraction (#1284).\n *\n * A link is a reference, and a reference is published under the target's PUBLISHED identity — never\n * its source name. `{@link MenuDto}` must publish the schema name `Menu` when `schemaNames` strips\n * `Dto`, and `{@link OrdersApi.fetchOrders}` must publish the operation, not leak the contract class\n * name to a partner. Neither name is known where the JSDoc is read: the schema name of a type in a\n * bundled document depends on what else that document reaches, the operationId on the manifest's\n * `operationIds` style, and an MCP catalog names a tool by its `@WpMcpTool` name. So extraction\n * records WHAT the link points at, as one of these, and each renderer names it — see\n * {@link DocLinkText}.\n */\nexport enum DocLinkKind {\n /** A named type — class, interface, enum or alias — optionally with a `.member` tail. */\n TYPE = 'type',\n /** A method of an `@ApiPath` contract: a published operation. */\n OPERATION = 'operation',\n /** A target that names nothing any document publishes. Always refused by a renderer. */\n UNRESOLVED = 'unresolved',\n}\n\n/** One resolved `{@link}`. Data only: a renderer reads it through {@link DocLinkText}. */\nexport class DocLink {\n constructor(\n readonly kind: DocLinkKind,\n /** The target exactly as written — `MenuDto.items`, `OrdersApi.fetchOrders`. */\n readonly written: string,\n /** `{@link X | the label}` / `{@link X the label}`'s label; undefined when there is none. */\n readonly label: string | undefined,\n /** Pointer-style `path/to/File.ts:12:5` of the link itself, for a refusal that names it. */\n readonly location: string,\n /**\n * {@link DocLinkKind.TYPE}: the {@link ApiDocModel.types} key of the type, and its\n * schemaNames-stripped published name. {@link DocLinkKind.OPERATION}: the contract class and\n * method name. Empty for the other kinds.\n */\n readonly owner: string,\n readonly ownerName: string,\n /** {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty. */\n readonly member: string,\n /** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */\n readonly mcpToolName: string | undefined,\n /** {@link DocLinkKind.UNRESOLVED}: why it names nothing publishable, in one clause. */\n readonly reason: string,\n ) {}\n}\n\n/** One `{@link}` a rendered output could not name. A renderer refuses every one, in one run. */\nexport class DocLinkProblem {\n constructor(\n /** Pointer-style `path/to/File.ts:12:5` of the link. */\n readonly location: string,\n /** The target as written. */\n readonly written: string,\n /** Why, in one clause. */\n readonly reason: string,\n ) {}\n\n toString(): string {\n return `${this.location} {@link ${this.written}} — ${this.reason}`;\n }\n}\n\n/**\n * How ONE rendered output names a link's target: the published schema name in THIS document, the\n * operationId, an MCP tool name. Undefined means the output does not publish the target, which the\n * resolver records as a {@link DocLinkProblem}.\n */\nexport interface DocLinkNaming {\n publishedName(link: DocLink): string | undefined;\n}\n\n/** Brackets one encoded link inside a model string. Private-use code points: no author types them. */\nconst OPEN = '';\nconst CLOSE = '';\nconst ENCODED = /([^]*)/g;\n\n/**\n * The ONE grammar for a `{@link}` inside model prose (#1284).\n *\n * Every prose string the model carries — a description, a `@summary`, a `@returns`, an `@mcp` — holds\n * each link ENCODED in place, so concatenation, trimming and joining by any renderer cannot separate a\n * link from the sentence it sits in. A renderer resolves the string as it publishes it, with its own\n * {@link DocLinkNaming}, and every renderer emits the SAME spelling:\n *\n * | written | published |\n * |---|---|\n * | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |\n * | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |\n * | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |\n * | `{@link OrdersApi.fetchOrders \\| the order list}` | `the order list (`fetchOrders`)` |\n *\n * A markdown CODE SPAN, because OpenAPI descriptions are CommonMark: every renderer shows it as code,\n * and a docs site can turn a code span naming a known operationId or schema into a link. A labelled\n * link keeps the author's words AND the identity, so the reference survives into a site's hyperlink.\n *\n * A model string must never reach a published output unresolved; a renderer that forgets is caught by\n * {@link hasLinks}, which every published output is checked with.\n */\nexport class DocLinkText {\n /** `link`, encoded for a place in a model string. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static encode(link: DocLink): string {\n const fields = [\n link.kind,\n link.written,\n link.label ?? null,\n link.location,\n link.owner,\n link.ownerName,\n link.member,\n link.mcpToolName ?? null,\n link.reason,\n ];\n return `${OPEN}${JSON.stringify(fields)}${CLOSE}`;\n }\n\n /** True when `text` still holds an encoded link — a published output never may. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static hasLinks(text: string): boolean {\n return text.includes(OPEN);\n }\n\n /**\n * Every link in `text` as WRITTEN, in the published spelling: for a measurement that must not count\n * the encoding (a `@summary`'s length) and for a reader that publishes nothing.\n */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static asWritten(text: string): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n return DocLinkText.spell(link, link.written);\n });\n }\n\n /** Every encoded link in `text`, in order. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static linksIn(text: string): readonly DocLink[] {\n const links: DocLink[] = [];\n for (const match of text.matchAll(ENCODED)) {\n links.push(DocLinkText.decode(match[1] ?? ''));\n }\n return links;\n }\n\n /** `text` with every link published under the name `naming` gives it; misses go to `problems`. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static resolve(\n text: string,\n naming: DocLinkNaming,\n output: string,\n problems: DocLinkProblem[],\n ): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n const name =\n link.kind === DocLinkKind.UNRESOLVED ? undefined : naming.publishedName(link);\n if (name === undefined) {\n problems.push(\n new DocLinkProblem(link.location, link.written, DocLinkText.why(link, output)),\n );\n return DocLinkText.spell(link, link.written);\n }\n return DocLinkText.spell(\n link,\n link.kind === DocLinkKind.TYPE ? `${name}${link.member}` : name,\n );\n });\n }\n\n /** The one published spelling — see the class doc. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static spell(link: DocLink, name: string): string {\n const code = `\\`${name}\\``;\n return link.label === undefined ? code : `${link.label} (${code})`;\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static why(link: DocLink, output: string): string {\n switch (link.kind) {\n case DocLinkKind.TYPE:\n return `type ${link.ownerName} is not published in ${output}`;\n case DocLinkKind.OPERATION:\n return `operation ${link.owner}.${link.ownerName} is not published in ${output}`;\n default:\n return link.reason;\n }\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static decode(body: string): DocLink {\n const f = JSON.parse(body) as (string | null)[];\n return new DocLink(\n f[0] as DocLinkKind,\n f[1] ?? '',\n f[2] ?? undefined,\n f[3] ?? '',\n f[4] ?? '',\n f[5] ?? '',\n f[6] ?? '',\n f[7] ?? undefined,\n f[8] ?? '',\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DocLink.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/DocLink.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,IAAY,WAcX;AAdD,WAAY,WAAW;IACnB,yFAAyF;IACzF,4BAAa,CAAA;IACb;;;;;OAKG;IACH,gCAAiB,CAAA;IACjB,iEAAiE;IACjE,sCAAuB,CAAA;IACvB,wFAAwF;IACxF,wCAAyB,CAAA;AAC7B,CAAC,EAdW,WAAW,2BAAX,WAAW,QActB;AAED,0FAA0F;AAC1F,MAAa,OAAO;IAEH;IAEA;IAEA;IAEA;IAMA;IACA;IAMA;IAEA;IAEA;IAxBb,YACa,IAAiB;IAC1B,gFAAgF;IACvE,OAAe;IACxB,6FAA6F;IACpF,KAAyB;IAClC,4FAA4F;IACnF,QAAgB;IACzB;;;;OAIG;IACM,KAAa,EACb,SAAiB;IAC1B;;;;OAIG;IACM,MAAc;IACvB,wFAAwF;IAC/E,WAA+B;IACxC,uFAAuF;IAC9E,MAAc;QAvBd,SAAI,GAAJ,IAAI,CAAa;QAEjB,YAAO,GAAP,OAAO,CAAQ;QAEf,UAAK,GAAL,KAAK,CAAoB;QAEzB,aAAQ,GAAR,QAAQ,CAAQ;QAMhB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAQ;QAMjB,WAAM,GAAN,MAAM,CAAQ;QAEd,gBAAW,GAAX,WAAW,CAAo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,CAAC,IAAI,CAAsB,CAAC;QAChD,OAAO,IAAI,OAAO,CACd,CAAC,CAAC,CAAC,CAAgB,EACnB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EACjB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACV,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,EACjB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CACb,CAAC;IACN,CAAC;CACJ;AA5GD,kCA4GC","sourcesContent":["/**\n * What a JSDoc `{@link X}` names, as the COMPILER resolved it at extraction (#1284).\n *\n * A link is a reference, and a reference is published under the target's PUBLISHED identity — never\n * its source name. `{@link MenuDto}` must publish the schema name `Menu` when `schemaNames` strips\n * `Dto`, and `{@link OrdersApi.fetchOrders}` must publish the operation, not leak the contract class\n * name to a partner. Neither name is known where the JSDoc is read: the schema name of a type in a\n * bundled document depends on what else that document reaches, the operationId on the manifest's\n * `operationIds` style, and an MCP catalog names a tool by its `@WpMcpTool` name. So extraction\n * records WHAT the link points at, as one of these, and each renderer names it — see\n * {@link DocLinkText}.\n */\nexport enum DocLinkKind {\n /** A named type — class, interface, enum or alias — optionally with a `.member` tail. */\n TYPE = 'type',\n /**\n * A member — property or enum member — written BARE (`{@link storeId}`), as TypeScript resolves\n * it inside a member's own JSDoc: a sibling, or one its type inherits (#1308). Published as the\n * member's own name, with no type prefix, because the reader is already on that schema — the one\n * the member is a field of, its inherited fields flattened in. Every output publishes it.\n */\n MEMBER = 'member',\n /** A method of an `@ApiPath` contract: a published operation. */\n OPERATION = 'operation',\n /** A target that names nothing any document publishes. Always refused by a renderer. */\n UNRESOLVED = 'unresolved',\n}\n\n/** One resolved `{@link}`. Data only: a renderer reads it through {@link DocLinkText}. */\nexport class DocLink {\n constructor(\n readonly kind: DocLinkKind,\n /** The target exactly as written — `MenuDto.items`, `OrdersApi.fetchOrders`. */\n readonly written: string,\n /** `{@link X | the label}` / `{@link X the label}`'s label; undefined when there is none. */\n readonly label: string | undefined,\n /** Pointer-style `path/to/File.ts:12:5` of the link itself, for a refusal that names it. */\n readonly location: string,\n /**\n * {@link DocLinkKind.TYPE}: the {@link ApiDocModel.types} key of the type, and its\n * schemaNames-stripped published name. {@link DocLinkKind.OPERATION}: the contract class and\n * method name. Empty for the other kinds.\n */\n readonly owner: string,\n readonly ownerName: string,\n /**\n * {@link DocLinkKind.TYPE}: the `.member` tail exactly as written (`.items`), else empty.\n * {@link DocLinkKind.MEMBER}: the member's published name (`storeId`), the type it is\n * declared on in `owner` / `ownerName`.\n */\n readonly member: string,\n /** {@link DocLinkKind.OPERATION}: the method's `@WpMcpTool` name, when it is a tool. */\n readonly mcpToolName: string | undefined,\n /** {@link DocLinkKind.UNRESOLVED}: why it names nothing publishable, in one clause. */\n readonly reason: string,\n ) {}\n}\n\n/** One `{@link}` a rendered output could not name. A renderer refuses every one, in one run. */\nexport class DocLinkProblem {\n constructor(\n /** Pointer-style `path/to/File.ts:12:5` of the link. */\n readonly location: string,\n /** The target as written. */\n readonly written: string,\n /** Why, in one clause. */\n readonly reason: string,\n ) {}\n\n toString(): string {\n return `${this.location} {@link ${this.written}} — ${this.reason}`;\n }\n}\n\n/**\n * How ONE rendered output names a link's target: the published schema name in THIS document, the\n * operationId, an MCP tool name. Undefined means the output does not publish the target, which the\n * resolver records as a {@link DocLinkProblem}.\n */\nexport interface DocLinkNaming {\n publishedName(link: DocLink): string | undefined;\n}\n\n/** Brackets one encoded link inside a model string. Private-use code points: no author types them. */\nconst OPEN = '';\nconst CLOSE = '';\nconst ENCODED = /([^]*)/g;\n\n/**\n * The ONE grammar for a `{@link}` inside model prose (#1284).\n *\n * Every prose string the model carries — a description, a `@summary`, a `@returns`, an `@mcp` — holds\n * each link ENCODED in place, so concatenation, trimming and joining by any renderer cannot separate a\n * link from the sentence it sits in. A renderer resolves the string as it publishes it, with its own\n * {@link DocLinkNaming}, and every renderer emits the SAME spelling:\n *\n * | written | published |\n * |---|---|\n * | `{@link MenuDto}` | `` `Menu` `` (the published schema name) |\n * | `{@link MenuDto.items}` | `` `Menu.items` `` (the tail kept as written) |\n * | `{@link storeId}`, from a sibling field's JSDoc | `` `storeId` `` (the field's own name — no type prefix) |\n * | `{@link OrdersApi.fetchOrders}` | `` `fetchOrders` `` (the operationId; an MCP tool's name in a tool catalog) |\n * | `{@link OrdersApi.fetchOrders \\| the order list}` | `the order list (`fetchOrders`)` |\n *\n * A markdown CODE SPAN, because OpenAPI descriptions are CommonMark: every renderer shows it as code,\n * and a docs site can turn a code span naming a known operationId or schema into a link. A labelled\n * link keeps the author's words AND the identity, so the reference survives into a site's hyperlink.\n *\n * A model string must never reach a published output unresolved; a renderer that forgets is caught by\n * {@link hasLinks}, which every published output is checked with.\n */\nexport class DocLinkText {\n /** `link`, encoded for a place in a model string. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static encode(link: DocLink): string {\n const fields = [\n link.kind,\n link.written,\n link.label ?? null,\n link.location,\n link.owner,\n link.ownerName,\n link.member,\n link.mcpToolName ?? null,\n link.reason,\n ];\n return `${OPEN}${JSON.stringify(fields)}${CLOSE}`;\n }\n\n /** True when `text` still holds an encoded link — a published output never may. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static hasLinks(text: string): boolean {\n return text.includes(OPEN);\n }\n\n /**\n * Every link in `text` as WRITTEN, in the published spelling: for a measurement that must not count\n * the encoding (a `@summary`'s length) and for a reader that publishes nothing.\n */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static asWritten(text: string): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n return DocLinkText.spell(link, link.written);\n });\n }\n\n /** Every encoded link in `text`, in order. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static linksIn(text: string): readonly DocLink[] {\n const links: DocLink[] = [];\n for (const match of text.matchAll(ENCODED)) {\n links.push(DocLinkText.decode(match[1] ?? ''));\n }\n return links;\n }\n\n /** `text` with every link published under the name `naming` gives it; misses go to `problems`. */\n // webpieces-disable no-function-outside-class -- static codec of the grammar this class owns\n static resolve(\n text: string,\n naming: DocLinkNaming,\n output: string,\n problems: DocLinkProblem[],\n ): string {\n return text.replace(ENCODED, (_all: string, body: string) => {\n const link = DocLinkText.decode(body);\n if (link.kind === DocLinkKind.MEMBER) {\n return DocLinkText.spell(link, link.member);\n }\n const name =\n link.kind === DocLinkKind.UNRESOLVED ? undefined : naming.publishedName(link);\n if (name === undefined) {\n problems.push(\n new DocLinkProblem(link.location, link.written, DocLinkText.why(link, output)),\n );\n return DocLinkText.spell(link, link.written);\n }\n return DocLinkText.spell(\n link,\n link.kind === DocLinkKind.TYPE ? `${name}${link.member}` : name,\n );\n });\n }\n\n /** The one published spelling — see the class doc. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static spell(link: DocLink, name: string): string {\n const code = `\\`${name}\\``;\n return link.label === undefined ? code : `${link.label} (${code})`;\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static why(link: DocLink, output: string): string {\n switch (link.kind) {\n case DocLinkKind.TYPE:\n return `type ${link.ownerName} is not published in ${output}`;\n case DocLinkKind.OPERATION:\n return `operation ${link.owner}.${link.ownerName} is not published in ${output}`;\n default:\n return link.reason;\n }\n }\n\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static decode(body: string): DocLink {\n const f = JSON.parse(body) as (string | null)[];\n return new DocLink(\n f[0] as DocLinkKind,\n f[1] ?? '',\n f[2] ?? undefined,\n f[3] ?? '',\n f[4] ?? '',\n f[5] ?? '',\n f[6] ?? '',\n f[7] ?? undefined,\n f[8] ?? '',\n );\n }\n}\n"]}
|