@webpieces/api-doc-model 0.4.803 → 0.4.804
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/README.md +1 -1
- package/package.json +2 -1
- package/src/extract/ApiDocExtractor.d.ts +61 -7
- package/src/extract/ApiDocExtractor.js +235 -39
- package/src/extract/ApiDocExtractor.js.map +1 -1
- package/src/extract/ConstantFolder.d.ts +16 -3
- package/src/extract/ConstantFolder.js +42 -3
- package/src/extract/ConstantFolder.js.map +1 -1
- package/src/extract/TypeResolver.d.ts +9 -0
- package/src/extract/TypeResolver.js +31 -6
- package/src/extract/TypeResolver.js.map +1 -1
- package/src/index.d.ts +5 -4
- package/src/index.js +7 -4
- package/src/index.js.map +1 -1
- package/src/model/ApiDocModel.d.ts +139 -12
- package/src/model/ApiDocModel.js +115 -13
- package/src/model/ApiDocModel.js.map +1 -1
package/README.md
CHANGED
|
@@ -18,4 +18,4 @@ model.types; // ReadonlyMap<string, DocumentedType> — a renderer's $ref target
|
|
|
18
18
|
model.unmapped; // UnmappedType[] — recorded, never dropped
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
It depends on `typescript` and
|
|
21
|
+
It depends on `typescript` and `@webpieces/core-util`, from which it takes every decorator NAME it matches on — so renaming a decorator is a compile error here rather than a literal that quietly stops matching and empties a generated document. See `responsibilities.md` for what is in and out of scope, why that import is not the coupling it looks like, and why both `Integer` and `@WpInt()` are accepted spellings of integer-ness.
|
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.804",
|
|
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,6 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@webpieces/core-util": "0.4.804",
|
|
26
27
|
"typescript": "5.9.3"
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -12,13 +12,12 @@ import { ApiDocModel } from '../model/ApiDocModel';
|
|
|
12
12
|
* made of, so the only place they exist is the source, and the only honest way to read the source is
|
|
13
13
|
* the compiler.
|
|
14
14
|
*
|
|
15
|
-
* ## Why it
|
|
15
|
+
* ## Why it IMPORTS `@webpieces/core-util`
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* webpieces version differs from ours, which is everybody.
|
|
17
|
+
* Decorators are matched BY NAME on the syntax — they must be, because this reads a contract and
|
|
18
|
+
* never executes it. The NAMES come from the real symbols (`Endpoint.name`), so a rename in
|
|
19
|
+
* `core-util` is a compile error here instead of a literal that quietly stops matching. The full
|
|
20
|
+
* argument, and why the import is not the coupling it looks like, is at those constants.
|
|
22
21
|
*
|
|
23
22
|
* ## What it does NOT do
|
|
24
23
|
*
|
|
@@ -38,17 +37,72 @@ export declare class ApiDocExtractor {
|
|
|
38
37
|
extractFile(entryFile: string, compilerOptions?: ts.CompilerOptions): ApiDocModel;
|
|
39
38
|
/** The same extraction against a program the caller already built. */
|
|
40
39
|
extract(program: ts.Program, source: ts.SourceFile): ApiDocModel;
|
|
40
|
+
/**
|
|
41
|
+
* Extract ONE named type and everything it reaches, from a file that holds NO contract.
|
|
42
|
+
*
|
|
43
|
+
* This exists for a type nothing in a contract points at but a document still publishes — the
|
|
44
|
+
* document-wide error body a renderer's manifest names. Reading it with the SAME resolver is the
|
|
45
|
+
* point: a second reader would be a second answer to "what shape is this type", and the two
|
|
46
|
+
* would drift the first time a field changed.
|
|
47
|
+
*
|
|
48
|
+
* @throws ApiDocExtractionError when the file does not declare that name.
|
|
49
|
+
*/
|
|
50
|
+
extractType(entryFile: string, typeName: string, compilerOptions?: ts.CompilerOptions): ApiDocModel;
|
|
51
|
+
/** The interface / class / type alias / enum declared under `name` at the file's top level. */
|
|
52
|
+
private static declarationNamed;
|
|
41
53
|
/** The one `@ApiPath` class in the file. Zero is a hard failure; the FIRST wins if there are two. */
|
|
42
54
|
private findContract;
|
|
43
55
|
/** One `@Endpoint` method. Members without the decorator are not part of the contract. */
|
|
44
56
|
private endpointOf;
|
|
57
|
+
/**
|
|
58
|
+
* One REQUIRED positional argument of `@Endpoint`, folded to the string it denotes.
|
|
59
|
+
*
|
|
60
|
+
* Every one of the four is an enum member (`POST`, `READ`, `RPC`) as often as it is a literal,
|
|
61
|
+
* and the folder resolves both — a document that printed `RPC` where the trigger goes would be
|
|
62
|
+
* worse than no document. A missing one is a hard failure naming the position, because the
|
|
63
|
+
* alternative is a document quietly missing a verb.
|
|
64
|
+
*/
|
|
65
|
+
private requiredArgument;
|
|
66
|
+
/**
|
|
67
|
+
* `@ApiType(...)` on the contract, folded to the real values.
|
|
68
|
+
*
|
|
69
|
+
* A value that is not one of the three documents is a HARD FAILURE rather than a silent drop: a
|
|
70
|
+
* contract that named `CUSTOMER` by mistake would otherwise feed nothing, which looks exactly
|
|
71
|
+
* like a contract somebody deliberately kept internal.
|
|
72
|
+
*/
|
|
73
|
+
private declaredApiTypes;
|
|
74
|
+
/**
|
|
75
|
+
* MCP membership has exactly ONE spelling, and this is the build-time half of enforcing it
|
|
76
|
+
* (`assertApiTypeMatchesMcpTools` in `@webpieces/core-util` is the wiring-time half).
|
|
77
|
+
*
|
|
78
|
+
* Declared in two places, the two can disagree — and the disagreement is invisible, because each
|
|
79
|
+
* declaration is individually valid. That is the defect this whole epic exists to remove, so it
|
|
80
|
+
* fails the DOCUMENT build rather than producing one that quietly lists the wrong tools.
|
|
81
|
+
*/
|
|
82
|
+
private assertApiTypeMatchesMcpTools;
|
|
45
83
|
/** The FIRST parameter's declared type. An endpoint with no parameter has no request document. */
|
|
46
84
|
private requestOf;
|
|
47
85
|
/** The declared return type, unwrapped from `Promise<...>` by the resolver. */
|
|
48
86
|
private responseOf;
|
|
49
87
|
/** `@WpAuthPublic()`, `@WpAuthJwt({...})`, … — recorded verbatim; this package rules on nothing. */
|
|
50
88
|
private static authOf;
|
|
51
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* `@WpAuthApiKey(regime, [{in: 'header', name: 'x-api-key', description: '…'}, …])`, parsed.
|
|
91
|
+
*
|
|
92
|
+
* A malformed declaration FAILS rather than yielding a half-parsed regime: the credentials are
|
|
93
|
+
* what a published document's security block is made of, and a document that silently omitted
|
|
94
|
+
* one would tell a partner they need fewer credentials than the running hook demands.
|
|
95
|
+
*/
|
|
96
|
+
private static apiKeyOf;
|
|
97
|
+
/** ONE `{ in: …, name?: …, description?: … }` credential. */
|
|
98
|
+
private static credentialOf;
|
|
99
|
+
/**
|
|
100
|
+
* `@WpMcpTool({ name, openWorldHint })` — the two facts the source cannot otherwise state.
|
|
101
|
+
*
|
|
102
|
+
* `description` is NOT read: the method's JSDoc is the description for the agent and the partner
|
|
103
|
+
* alike. The three side-effect hints are not read either — they are computed from the endpoint's
|
|
104
|
+
* `operation`. See {@link DocumentedMcpTool} for why both of those are deliberate.
|
|
105
|
+
*/
|
|
52
106
|
private static mcpToolOf;
|
|
53
107
|
/** `@MaskLog({ refreshToken: 'full' })` -> field name -> mask mode. */
|
|
54
108
|
private static maskLogOf;
|
|
@@ -3,21 +3,77 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ApiDocExtractor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
6
|
+
const core_util_1 = require("@webpieces/core-util");
|
|
6
7
|
const ApiDocModel_1 = require("../model/ApiDocModel");
|
|
7
8
|
const ApiDocExtractionError_1 = require("./ApiDocExtractionError");
|
|
8
9
|
const ConstantFolder_1 = require("./ConstantFolder");
|
|
9
10
|
const JsDoc_1 = require("./JsDoc");
|
|
10
11
|
const SourceLocation_1 = require("./SourceLocation");
|
|
11
12
|
const TypeResolver_1 = require("./TypeResolver");
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The decorator names this extractor matches on, taken from the REAL SYMBOLS rather than re-typed as
|
|
15
|
+
* string literals.
|
|
16
|
+
*
|
|
17
|
+
* ## Why `.name` and not `'Endpoint'`
|
|
18
|
+
*
|
|
19
|
+
* The extractor matches decorators by NAME on the syntax — it must, because it reads a contract with
|
|
20
|
+
* the compiler and never executes it. The question is only where that name comes from, and a literal
|
|
21
|
+
* has a silent failure mode that a symbol does not: rename `@WpMcpTool` in `core-util` and a literal
|
|
22
|
+
* simply stops matching. The extractor then finds zero MCP tools, the MCP document is correctly not
|
|
23
|
+
* written because it has no tools in it, and the BUILD IS GREEN. A partner-facing document silently
|
|
24
|
+
* loses a section with nothing red anywhere (issue #1001).
|
|
25
|
+
*
|
|
26
|
+
* `Endpoint.name` makes that rename a COMPILE ERROR here, which in this repo is the delivery
|
|
27
|
+
* mechanism for a migration rather than an obstacle to one: a compile break names the new spelling
|
|
28
|
+
* and an agent applies it in one pass, where a green build teaches nobody anything.
|
|
29
|
+
*
|
|
30
|
+
* ## Why importing `@webpieces/core-util` is not the coupling it looks like
|
|
31
|
+
*
|
|
32
|
+
* Any contract carrying `@Endpoint` already depends on `core-util` by definition, so there is no
|
|
33
|
+
* upstream project this import could shut out. It is build-time only, it creates no cycle, and it
|
|
34
|
+
* costs a browser bundle nothing because nothing in a bundle imports this package. The direction that
|
|
35
|
+
* WOULD be fatal is `core-util` depending on the TypeScript compiler, and that is not this.
|
|
36
|
+
*/
|
|
37
|
+
const API_PATH = core_util_1.ApiPath.name;
|
|
38
|
+
const ENDPOINT = core_util_1.Endpoint.name;
|
|
39
|
+
const MASK_LOG = core_util_1.MaskLog.name;
|
|
40
|
+
const MCP_TOOL = core_util_1.WpMcpTool.name;
|
|
41
|
+
const MCP_AUTH = core_util_1.WpMcpAuthJwt.name;
|
|
42
|
+
const API_KEY_AUTH = core_util_1.WpAuthApiKey.name;
|
|
43
|
+
const API_TYPE = core_util_1.ApiType.name;
|
|
44
|
+
/**
|
|
45
|
+
* The prefix shared by every credential decorator. A PREFIX genuinely has no symbol to take a name
|
|
46
|
+
* from, so it stays a literal — but the set it selects is pinned below, which is what stops it
|
|
47
|
+
* quietly matching nothing.
|
|
48
|
+
*/
|
|
18
49
|
const AUTH_PREFIX = 'WpAuth';
|
|
19
|
-
/**
|
|
20
|
-
const
|
|
50
|
+
/** Every credential decorator, by real symbol, so a rename of any of them fails to compile here. */
|
|
51
|
+
const AUTH_DECORATORS = new Set([
|
|
52
|
+
core_util_1.WpAuthPublic.name,
|
|
53
|
+
core_util_1.WpAuthJwt.name,
|
|
54
|
+
core_util_1.WpAuthOidc.name,
|
|
55
|
+
core_util_1.WpAuthSharedSecret.name,
|
|
56
|
+
core_util_1.WpAuthWebhook.name,
|
|
57
|
+
core_util_1.WpAuthApiKey.name,
|
|
58
|
+
core_util_1.WpAuthLocalOnly.name,
|
|
59
|
+
]);
|
|
60
|
+
/** The REAL trigger kinds and side-effect contracts, so a contract cannot declare one that is not. */
|
|
61
|
+
const ENDPOINT_KINDS = [core_util_1.RPC, core_util_1.CLOUDTASKS, core_util_1.CRON, core_util_1.EXTERNAL];
|
|
62
|
+
const ENDPOINT_OPERATIONS = [core_util_1.READ, core_util_1.WRITE_IDEMPOTENT, core_util_1.WRITE];
|
|
63
|
+
const HTTP_METHODS = [core_util_1.GET, core_util_1.POST];
|
|
64
|
+
/** `@Endpoint`'s four required positions, named so a failure can say which one is missing. */
|
|
65
|
+
const ARGUMENT_NAMES = ['http method', 'path', 'operation', 'trigger kind'];
|
|
66
|
+
/** The allowed values of each required position, in the same order, for the same failure. */
|
|
67
|
+
const ARGUMENT_VALUES = [
|
|
68
|
+
HTTP_METHODS,
|
|
69
|
+
[],
|
|
70
|
+
ENDPOINT_OPERATIONS,
|
|
71
|
+
ENDPOINT_KINDS,
|
|
72
|
+
];
|
|
73
|
+
/** The REAL document types, so a contract cannot name a document that does not exist. */
|
|
74
|
+
const API_TYPES = [core_util_1.SVC_TO_SVC, core_util_1.EXTERNAL_CUSTOMER, core_util_1.MCP];
|
|
75
|
+
/** The fail-closed default: a contract that declares nothing feeds only the internal document. */
|
|
76
|
+
const DEFAULT_API_TYPES = [core_util_1.SVC_TO_SVC];
|
|
21
77
|
/**
|
|
22
78
|
* ONE contract file -> ONE {@link ApiDocModel}. The single extraction pass both the OpenAPI documents
|
|
23
79
|
* and the MCP tool list (#982) are rendered from.
|
|
@@ -30,13 +86,12 @@ const TOOL_HINTS = ['readOnly', 'destructive', 'idempotent', 'openWorld'];
|
|
|
30
86
|
* made of, so the only place they exist is the source, and the only honest way to read the source is
|
|
31
87
|
* the compiler.
|
|
32
88
|
*
|
|
33
|
-
* ## Why it
|
|
89
|
+
* ## Why it IMPORTS `@webpieces/core-util`
|
|
34
90
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* webpieces version differs from ours, which is everybody.
|
|
91
|
+
* Decorators are matched BY NAME on the syntax — they must be, because this reads a contract and
|
|
92
|
+
* never executes it. The NAMES come from the real symbols (`Endpoint.name`), so a rename in
|
|
93
|
+
* `core-util` is a compile error here instead of a literal that quietly stops matching. The full
|
|
94
|
+
* argument, and why the import is not the coupling it looks like, is at those constants.
|
|
40
95
|
*
|
|
41
96
|
* ## What it does NOT do
|
|
42
97
|
*
|
|
@@ -72,6 +127,7 @@ class ApiDocExtractor {
|
|
|
72
127
|
const basePath = basePathArgument === undefined
|
|
73
128
|
? ''
|
|
74
129
|
: folder.foldString(basePathArgument, '@ApiPath argument');
|
|
130
|
+
const apiTypes = this.declaredApiTypes(contract, folder);
|
|
75
131
|
const endpoints = [];
|
|
76
132
|
for (const member of contract.members) {
|
|
77
133
|
const endpoint = this.endpointOf(member, folder, resolver);
|
|
@@ -79,7 +135,46 @@ class ApiDocExtractor {
|
|
|
79
135
|
endpoints.push(endpoint);
|
|
80
136
|
}
|
|
81
137
|
}
|
|
82
|
-
|
|
138
|
+
this.assertApiTypeMatchesMcpTools(contract, apiTypes, endpoints);
|
|
139
|
+
return new ApiDocModel_1.ApiDocModel(contract.name?.text ?? '<anonymous>', apiTypes, basePath, JsDoc_1.JsDoc.read(contract).description, endpoints, resolver.collectedTypes(), resolver.collectedUnmapped());
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract ONE named type and everything it reaches, from a file that holds NO contract.
|
|
143
|
+
*
|
|
144
|
+
* This exists for a type nothing in a contract points at but a document still publishes — the
|
|
145
|
+
* document-wide error body a renderer's manifest names. Reading it with the SAME resolver is the
|
|
146
|
+
* point: a second reader would be a second answer to "what shape is this type", and the two
|
|
147
|
+
* would drift the first time a field changed.
|
|
148
|
+
*
|
|
149
|
+
* @throws ApiDocExtractionError when the file does not declare that name.
|
|
150
|
+
*/
|
|
151
|
+
extractType(entryFile, typeName, compilerOptions = {}) {
|
|
152
|
+
const program = ts.createProgram([entryFile], compilerOptions);
|
|
153
|
+
const source = program.getSourceFile(entryFile);
|
|
154
|
+
if (source === undefined) {
|
|
155
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError('entry file is not part of the program', entryFile, 'Pass an absolute path to a .ts file that exists.');
|
|
156
|
+
}
|
|
157
|
+
const resolver = new TypeResolver_1.TypeResolver(program.getTypeChecker());
|
|
158
|
+
const declaration = ApiDocExtractor.declarationNamed(source, typeName);
|
|
159
|
+
if (declaration === undefined) {
|
|
160
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`no type named '${typeName}' is declared in this file`, entryFile, `Declare and export '${typeName}' there, or name the file that does.`);
|
|
161
|
+
}
|
|
162
|
+
resolver.resolveDeclaration(typeName, declaration, typeName);
|
|
163
|
+
return new ApiDocModel_1.ApiDocModel(typeName, DEFAULT_API_TYPES, '', '', [], resolver.collectedTypes(), resolver.collectedUnmapped());
|
|
164
|
+
}
|
|
165
|
+
/** The interface / class / type alias / enum declared under `name` at the file's top level. */
|
|
166
|
+
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
167
|
+
static declarationNamed(source, name) {
|
|
168
|
+
for (const statement of source.statements) {
|
|
169
|
+
const named = ts.isInterfaceDeclaration(statement) ||
|
|
170
|
+
ts.isClassDeclaration(statement) ||
|
|
171
|
+
ts.isTypeAliasDeclaration(statement) ||
|
|
172
|
+
ts.isEnumDeclaration(statement);
|
|
173
|
+
if (named && statement.name?.text === name) {
|
|
174
|
+
return statement;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
83
178
|
}
|
|
84
179
|
/** The one `@ApiPath` class in the file. Zero is a hard failure; the FIRST wins if there are two. */
|
|
85
180
|
findContract(source) {
|
|
@@ -101,20 +196,81 @@ class ApiDocExtractor {
|
|
|
101
196
|
return undefined;
|
|
102
197
|
}
|
|
103
198
|
const methodName = member.name.text;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const path =
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
const kind = folder.foldString(kindArgument, `@Endpoint kind on '${methodName}'`);
|
|
114
|
-
const options = call.arguments[2];
|
|
199
|
+
// `@Endpoint(httpMethod, path, operation, kind, options?)` — METHOD-FIRST, five positions.
|
|
200
|
+
// The positions are read here and nowhere else, so the one place that has to change when the
|
|
201
|
+
// decorator changes is this block plus `ARGUMENT_NAMES` beside it.
|
|
202
|
+
const httpMethod = this.requiredArgument(call, methodName, 0, folder);
|
|
203
|
+
const path = this.requiredArgument(call, methodName, 1, folder);
|
|
204
|
+
const operation = this.requiredArgument(call, methodName, 2, folder);
|
|
205
|
+
const kind = this.requiredArgument(call, methodName, 3, folder);
|
|
206
|
+
const options = call.arguments[4];
|
|
115
207
|
const literal = options !== undefined && ts.isObjectLiteralExpression(options) ? options : undefined;
|
|
116
208
|
const doc = JsDoc_1.JsDoc.read(member);
|
|
117
|
-
|
|
209
|
+
const mcpTool = ApiDocExtractor.mcpToolOf(member, folder);
|
|
210
|
+
return new ApiDocModel_1.DocumentedEndpoint(methodName, httpMethod, path, operation, kind, ApiDocExtractor.booleanProperty(literal, 'hidden'), ApiDocExtractor.booleanProperty(literal, 'openWorld'), new ApiDocModel_1.DocumentedEndpointOptions(ApiDocExtractor.booleanProperty(literal, 'formPost'), ApiDocExtractor.stringProperty(literal, 'calledBy', folder), ApiDocExtractor.stringProperty(literal, 'callerKind', folder)), ApiDocExtractor.authOf(member, folder), mcpTool, ApiDocExtractor.decoratorCall(member, MCP_AUTH)?.arguments[0]?.getText(), ApiDocExtractor.maskLogOf(member), doc.description, doc.mcp, this.requestOf(member, methodName, resolver), this.responseOf(member, methodName, resolver));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* One REQUIRED positional argument of `@Endpoint`, folded to the string it denotes.
|
|
214
|
+
*
|
|
215
|
+
* Every one of the four is an enum member (`POST`, `READ`, `RPC`) as often as it is a literal,
|
|
216
|
+
* and the folder resolves both — a document that printed `RPC` where the trigger goes would be
|
|
217
|
+
* worse than no document. A missing one is a hard failure naming the position, because the
|
|
218
|
+
* alternative is a document quietly missing a verb.
|
|
219
|
+
*/
|
|
220
|
+
requiredArgument(call, methodName, index, folder) {
|
|
221
|
+
const argument = call.arguments[index];
|
|
222
|
+
const what = ARGUMENT_NAMES[index];
|
|
223
|
+
if (argument === undefined) {
|
|
224
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`@Endpoint on '${methodName}' declares no ${what}`, SourceLocation_1.SourceLocation.of(call), "Write all four: @Endpoint(POST, '/thing', READ, RPC).");
|
|
225
|
+
}
|
|
226
|
+
const value = folder.foldString(argument, `@Endpoint ${what} on '${methodName}'`);
|
|
227
|
+
const allowed = ARGUMENT_VALUES[index];
|
|
228
|
+
if (allowed.length > 0 && !allowed.includes(value)) {
|
|
229
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`@Endpoint on '${methodName}' declares ${what} '${value}', which is not one of ` +
|
|
230
|
+
allowed.join(', '), SourceLocation_1.SourceLocation.of(argument), `Use one of the exported constants: ${allowed.join(', ')}.`);
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* `@ApiType(...)` on the contract, folded to the real values.
|
|
236
|
+
*
|
|
237
|
+
* A value that is not one of the three documents is a HARD FAILURE rather than a silent drop: a
|
|
238
|
+
* contract that named `CUSTOMER` by mistake would otherwise feed nothing, which looks exactly
|
|
239
|
+
* like a contract somebody deliberately kept internal.
|
|
240
|
+
*/
|
|
241
|
+
declaredApiTypes(node, folder) {
|
|
242
|
+
const call = ApiDocExtractor.decoratorCall(node, API_TYPE);
|
|
243
|
+
if (call === undefined) {
|
|
244
|
+
return DEFAULT_API_TYPES;
|
|
245
|
+
}
|
|
246
|
+
const declared = call.arguments.map((argument) => folder.foldString(argument, `@${API_TYPE} argument`));
|
|
247
|
+
for (const apiType of declared) {
|
|
248
|
+
if (!API_TYPES.includes(apiType)) {
|
|
249
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`@${API_TYPE} names '${apiType}', which is not a generated document`, SourceLocation_1.SourceLocation.of(call), `Use one of the exported constants: ${API_TYPES.join(', ')}.`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return declared.length === 0 ? DEFAULT_API_TYPES : declared;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* MCP membership has exactly ONE spelling, and this is the build-time half of enforcing it
|
|
256
|
+
* (`assertApiTypeMatchesMcpTools` in `@webpieces/core-util` is the wiring-time half).
|
|
257
|
+
*
|
|
258
|
+
* Declared in two places, the two can disagree — and the disagreement is invisible, because each
|
|
259
|
+
* declaration is individually valid. That is the defect this whole epic exists to remove, so it
|
|
260
|
+
* fails the DOCUMENT build rather than producing one that quietly lists the wrong tools.
|
|
261
|
+
*/
|
|
262
|
+
assertApiTypeMatchesMcpTools(contract, apiTypes, endpoints) {
|
|
263
|
+
const tools = endpoints.filter((e) => e.mcpTool !== undefined);
|
|
264
|
+
const declaresMcp = apiTypes.includes(core_util_1.MCP);
|
|
265
|
+
if (declaresMcp && tools.length === 0) {
|
|
266
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`@${API_TYPE} names MCP but no method carries @${MCP_TOOL}`, SourceLocation_1.SourceLocation.of(contract), `Add @${MCP_TOOL}({name, description, openWorldHint}) to the methods agents may ` +
|
|
267
|
+
`call, or drop MCP from the @${API_TYPE} list.`);
|
|
268
|
+
}
|
|
269
|
+
if (!declaresMcp && tools.length > 0) {
|
|
270
|
+
const named = tools.map((e) => e.methodName).join(', ');
|
|
271
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`@${MCP_TOOL} is on ${named} but @${API_TYPE} does not name MCP`, SourceLocation_1.SourceLocation.of(contract), `Add MCP to the @${API_TYPE} list — membership has ONE spelling, so a tool on a ` +
|
|
272
|
+
'contract nobody published to agents is a contradiction, not a hint.');
|
|
273
|
+
}
|
|
118
274
|
}
|
|
119
275
|
/** The FIRST parameter's declared type. An endpoint with no parameter has no request document. */
|
|
120
276
|
requestOf(member, methodName, resolver) {
|
|
@@ -133,7 +289,7 @@ class ApiDocExtractor {
|
|
|
133
289
|
}
|
|
134
290
|
/** `@WpAuthPublic()`, `@WpAuthJwt({...})`, … — recorded verbatim; this package rules on nothing. */
|
|
135
291
|
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
136
|
-
static authOf(member) {
|
|
292
|
+
static authOf(member, folder) {
|
|
137
293
|
const decorators = ts.canHaveDecorators(member) ? (ts.getDecorators(member) ?? []) : [];
|
|
138
294
|
for (const decorator of decorators) {
|
|
139
295
|
const call = decorator.expression;
|
|
@@ -141,13 +297,60 @@ class ApiDocExtractor {
|
|
|
141
297
|
continue;
|
|
142
298
|
}
|
|
143
299
|
const name = call.expression.text;
|
|
144
|
-
if (name.startsWith(AUTH_PREFIX) && name
|
|
145
|
-
return new ApiDocModel_1.DocumentedAuth(name, call.arguments
|
|
300
|
+
if (name.startsWith(AUTH_PREFIX) && AUTH_DECORATORS.has(name)) {
|
|
301
|
+
return new ApiDocModel_1.DocumentedAuth(name, call.arguments.map((argument) => argument.getText()), name === API_KEY_AUTH ? ApiDocExtractor.apiKeyOf(call, folder) : undefined);
|
|
146
302
|
}
|
|
147
303
|
}
|
|
148
304
|
return undefined;
|
|
149
305
|
}
|
|
150
|
-
/**
|
|
306
|
+
/**
|
|
307
|
+
* `@WpAuthApiKey(regime, [{in: 'header', name: 'x-api-key', description: '…'}, …])`, parsed.
|
|
308
|
+
*
|
|
309
|
+
* A malformed declaration FAILS rather than yielding a half-parsed regime: the credentials are
|
|
310
|
+
* what a published document's security block is made of, and a document that silently omitted
|
|
311
|
+
* one would tell a partner they need fewer credentials than the running hook demands.
|
|
312
|
+
*/
|
|
313
|
+
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
314
|
+
static apiKeyOf(call, folder) {
|
|
315
|
+
const regimeArgument = call.arguments[0];
|
|
316
|
+
const credentialsArgument = call.arguments[1];
|
|
317
|
+
if (regimeArgument === undefined || credentialsArgument === undefined) {
|
|
318
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError('@WpAuthApiKey needs a regime AND its credentials', SourceLocation_1.SourceLocation.of(call), "Write both: @WpAuthApiKey('partner', [{ in: 'header', name: 'x-api-key' }]).");
|
|
319
|
+
}
|
|
320
|
+
const regime = folder.foldString(regimeArgument, '@WpAuthApiKey regime');
|
|
321
|
+
// FOLLOW a name first: a credential list shared by every method of a contract is written
|
|
322
|
+
// once as a `const` and named per method, which is better source than a copy per method.
|
|
323
|
+
const credentialsLiteral = folder.follow(credentialsArgument);
|
|
324
|
+
if (!ts.isArrayLiteralExpression(credentialsLiteral)) {
|
|
325
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError('@WpAuthApiKey credentials is not an array literal', SourceLocation_1.SourceLocation.of(credentialsArgument), 'Write the credentials as an array literal, inline or in a `const`; a value ' +
|
|
326
|
+
'assembled at runtime cannot appear in a published security scheme.');
|
|
327
|
+
}
|
|
328
|
+
const credentials = [];
|
|
329
|
+
for (const element of credentialsLiteral.elements) {
|
|
330
|
+
credentials.push(ApiDocExtractor.credentialOf(element, folder));
|
|
331
|
+
}
|
|
332
|
+
return new ApiDocModel_1.DocumentedApiKey(regime, credentials);
|
|
333
|
+
}
|
|
334
|
+
/** ONE `{ in: …, name?: …, description?: … }` credential. */
|
|
335
|
+
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
336
|
+
static credentialOf(expression, folder) {
|
|
337
|
+
const element = folder.follow(expression);
|
|
338
|
+
if (!ts.isObjectLiteralExpression(element)) {
|
|
339
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError('an @WpAuthApiKey credential is not an object literal', SourceLocation_1.SourceLocation.of(element), "Write it inline: { in: 'header', name: 'x-api-key' }.");
|
|
340
|
+
}
|
|
341
|
+
const location = ApiDocExtractor.stringProperty(element, 'in', folder);
|
|
342
|
+
if (location === undefined) {
|
|
343
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError('an @WpAuthApiKey credential declares no `in`', SourceLocation_1.SourceLocation.of(element), "Say where it rides: `in: 'header'` with a name, or `in: 'bearer'`.");
|
|
344
|
+
}
|
|
345
|
+
return new ApiDocModel_1.DocumentedApiKeyCredential(location, ApiDocExtractor.stringProperty(element, 'name', folder), ApiDocExtractor.stringProperty(element, 'description', folder));
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* `@WpMcpTool({ name, openWorldHint })` — the two facts the source cannot otherwise state.
|
|
349
|
+
*
|
|
350
|
+
* `description` is NOT read: the method's JSDoc is the description for the agent and the partner
|
|
351
|
+
* alike. The three side-effect hints are not read either — they are computed from the endpoint's
|
|
352
|
+
* `operation`. See {@link DocumentedMcpTool} for why both of those are deliberate.
|
|
353
|
+
*/
|
|
151
354
|
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
152
355
|
static mcpToolOf(member, folder) {
|
|
153
356
|
const call = ApiDocExtractor.decoratorCall(member, MCP_TOOL);
|
|
@@ -155,14 +358,7 @@ class ApiDocExtractor {
|
|
|
155
358
|
if (argument === undefined || !ts.isObjectLiteralExpression(argument)) {
|
|
156
359
|
return undefined;
|
|
157
360
|
}
|
|
158
|
-
|
|
159
|
-
for (const hint of TOOL_HINTS) {
|
|
160
|
-
const value = ApiDocExtractor.findProperty(argument, hint);
|
|
161
|
-
if (value !== undefined) {
|
|
162
|
-
hints.set(hint, value.kind === ts.SyntaxKind.TrueKeyword);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return new ApiDocModel_1.DocumentedMcpTool(ApiDocExtractor.stringProperty(argument, 'name', folder) ?? '', hints);
|
|
361
|
+
return new ApiDocModel_1.DocumentedMcpTool(ApiDocExtractor.stringProperty(argument, 'name', folder) ?? '');
|
|
166
362
|
}
|
|
167
363
|
/** `@MaskLog({ refreshToken: 'full' })` -> field name -> mask mode. */
|
|
168
364
|
// webpieces-disable no-function-outside-class -- private static reader of this class
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiDocExtractor.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/ApiDocExtractor.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,sDAM8B;AAE9B,mEAAgE;AAChE,qDAAkD;AAClD,mCAAgC;AAChC,qDAAkD;AAClD,iDAA8C;AAE9C,sGAAsG;AACtG,MAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,MAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,MAAM,QAAQ,GAAG,WAAW,CAAC;AAC7B,MAAM,QAAQ,GAAG,cAAc,CAAC;AAChC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,0DAA0D;AAC1D,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,aAAa,EAA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C;QACpF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC;YAClC,IACI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;gBAChC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,aAAa,EACxC,CAAC;gBACC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAnRD,0CAmRC","sourcesContent":["import * as ts from 'typescript';\nimport {\n ApiDocModel,\n DocumentedAuth,\n DocumentedEndpoint,\n DocumentedEndpointOptions,\n DocumentedMcpTool,\n} from '../model/ApiDocModel';\nimport { TypeRef } from '../model/TypeRef';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\nimport { ConstantFolder } from './ConstantFolder';\nimport { JsDoc } from './JsDoc';\nimport { SourceLocation } from './SourceLocation';\nimport { TypeResolver } from './TypeResolver';\n\n/** The decorator names this extractor reads, by NAME. It imports none of them — see the class doc. */\nconst API_PATH = 'ApiPath';\nconst ENDPOINT = 'Endpoint';\nconst MASK_LOG = 'MaskLog';\nconst MCP_TOOL = 'WpMcpTool';\nconst MCP_AUTH = 'WpMcpAuthJwt';\nconst AUTH_PREFIX = 'WpAuth';\n\n/** The MCP tool hints a renderer surfaces to an agent. */\nconst TOOL_HINTS = ['readOnly', 'destructive', 'idempotent', 'openWorld'];\n\n/**\n * ONE contract file -> ONE {@link ApiDocModel}. The single extraction pass both the OpenAPI documents\n * and the MCP tool list (#982) are rendered from.\n *\n * ## Why the compiler API at all\n *\n * A DTO field's TYPE IS ERASED AT RUNTIME. Reflection can see that `save` takes one argument; it\n * cannot see that the argument has a `deliveryWindow` that is a discriminated union of two shapes,\n * one of which carries an ISO timestamp. Those are precisely the shapes a partner-grade document is\n * made of, so the only place they exist is the source, and the only honest way to read the source is\n * the compiler.\n *\n * ## Why it imports NO webpieces package\n *\n * It depends on `typescript` and nothing else, so it can be pointed at ANY upstream project's\n * contract — which is the whole point of shipping it as a package rather than as a script in this\n * repo. Decorators are therefore matched BY NAME on the syntax, never by importing the real\n * decorator. One `@webpieces/core-util` import here would make the package unusable by anybody whose\n * webpieces version differs from ours, which is everybody.\n *\n * ## What it does NOT do\n *\n * It emits nothing. No OpenAPI, no MCP tool definitions, no file — that is #982, and keeping the\n * render out means the two renderers cannot drift apart about what the contract SAYS.\n */\nexport class ApiDocExtractor {\n /**\n * Extract the contract in `entryFile`.\n *\n * @param entryFile absolute path to the `.ts` file holding the `@ApiPath` class.\n * @param compilerOptions handed straight to `ts.createProgram`; the caller owns them because\n * only the caller knows its own `paths` / `lib` setup.\n * @throws ApiDocExtractionError when the file holds no `@ApiPath` class, or when something that\n * must be exact (a path constant, a numeric bound) cannot be established.\n */\n extractFile(entryFile: string, compilerOptions: ts.CompilerOptions = {}): ApiDocModel {\n const program = ts.createProgram([entryFile], compilerOptions);\n const source = program.getSourceFile(entryFile);\n if (source === undefined) {\n throw new ApiDocExtractionError(\n 'entry file is not part of the program',\n entryFile,\n 'Pass an absolute path to a .ts file that exists.',\n );\n }\n return this.extract(program, source);\n }\n\n /** The same extraction against a program the caller already built. */\n extract(program: ts.Program, source: ts.SourceFile): ApiDocModel {\n const checker = program.getTypeChecker();\n const folder = new ConstantFolder(checker);\n const resolver = new TypeResolver(checker);\n\n const contract = this.findContract(source);\n const pathDecorator = ApiDocExtractor.decoratorCall(contract, API_PATH)!;\n const basePathArgument = pathDecorator.arguments[0];\n const basePath =\n basePathArgument === undefined\n ? ''\n : folder.foldString(basePathArgument, '@ApiPath argument');\n\n const endpoints: DocumentedEndpoint[] = [];\n for (const member of contract.members) {\n const endpoint = this.endpointOf(member, folder, resolver);\n if (endpoint !== undefined) {\n endpoints.push(endpoint);\n }\n }\n\n return new ApiDocModel(\n contract.name?.text ?? '<anonymous>',\n basePath,\n JsDoc.read(contract).description,\n endpoints,\n resolver.collectedTypes(),\n resolver.collectedUnmapped(),\n );\n }\n\n /** The one `@ApiPath` class in the file. Zero is a hard failure; the FIRST wins if there are two. */\n private findContract(source: ts.SourceFile): ts.ClassDeclaration {\n for (const statement of source.statements) {\n if (\n ts.isClassDeclaration(statement) &&\n ApiDocExtractor.decoratorCall(statement, API_PATH) !== undefined\n ) {\n return statement;\n }\n }\n throw new ApiDocExtractionError(\n 'no @ApiPath class in this file',\n source.fileName,\n 'Point the extractor at the contract file — the one whose class carries @ApiPath.',\n );\n }\n\n /** One `@Endpoint` method. Members without the decorator are not part of the contract. */\n private endpointOf(\n member: ts.ClassElement,\n folder: ConstantFolder,\n resolver: TypeResolver,\n ): DocumentedEndpoint | undefined {\n if (!ts.isMethodDeclaration(member) || !ts.isIdentifier(member.name)) {\n return undefined;\n }\n const call = ApiDocExtractor.decoratorCall(member, ENDPOINT);\n if (call === undefined) {\n return undefined;\n }\n const methodName = member.name.text;\n\n const pathArgument = call.arguments[0];\n if (pathArgument === undefined) {\n throw new ApiDocExtractionError(\n `@Endpoint on '${methodName}' declares no path`,\n SourceLocation.of(call),\n \"Give it a path: @Endpoint('/thing', 'rpc').\",\n );\n }\n const path = folder.foldString(pathArgument, `@Endpoint path on '${methodName}'`);\n\n const kindArgument = call.arguments[1];\n if (kindArgument === undefined) {\n throw new ApiDocExtractionError(\n `@Endpoint on '${methodName}' declares no kind`,\n SourceLocation.of(call),\n \"State what triggers it: 'rpc', 'cloudtasks', 'cron' or 'external'.\",\n );\n }\n const kind = folder.foldString(kindArgument, `@Endpoint kind on '${methodName}'`);\n\n const options = call.arguments[2];\n const literal =\n options !== undefined && ts.isObjectLiteralExpression(options) ? options : undefined;\n\n const doc = JsDoc.read(member);\n return new DocumentedEndpoint(\n methodName,\n path,\n kind,\n ApiDocExtractor.booleanProperty(literal, 'hidden'),\n new DocumentedEndpointOptions(\n ApiDocExtractor.booleanProperty(literal, 'formPost'),\n ApiDocExtractor.stringProperty(literal, 'calledBy', folder),\n ApiDocExtractor.stringProperty(literal, 'callerKind', folder),\n ),\n ApiDocExtractor.authOf(member),\n ApiDocExtractor.mcpToolOf(member, folder),\n ApiDocExtractor.decoratorCall(member, MCP_AUTH)?.arguments[0]?.getText(),\n ApiDocExtractor.maskLogOf(member),\n doc.description,\n doc.mcp,\n this.requestOf(member, methodName, resolver),\n this.responseOf(member, methodName, resolver),\n );\n }\n\n /** The FIRST parameter's declared type. An endpoint with no parameter has no request document. */\n private requestOf(\n member: ts.MethodDeclaration,\n methodName: string,\n resolver: TypeResolver,\n ): TypeRef | undefined {\n const parameter = member.parameters[0];\n if (parameter?.type === undefined) {\n return undefined;\n }\n return resolver.resolve(parameter.type, `${methodName}.request`);\n }\n\n /** The declared return type, unwrapped from `Promise<...>` by the resolver. */\n private responseOf(\n member: ts.MethodDeclaration,\n methodName: string,\n resolver: TypeResolver,\n ): TypeRef | undefined {\n if (member.type === undefined) {\n return undefined;\n }\n return resolver.resolve(member.type, `${methodName}.response`);\n }\n\n /** `@WpAuthPublic()`, `@WpAuthJwt({...})`, … — recorded verbatim; this package rules on nothing. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static authOf(member: ts.Node): DocumentedAuth | undefined {\n const decorators = ts.canHaveDecorators(member) ? (ts.getDecorators(member) ?? []) : [];\n for (const decorator of decorators) {\n const call = decorator.expression;\n if (!ts.isCallExpression(call) || !ts.isIdentifier(call.expression)) {\n continue;\n }\n const name = call.expression.text;\n if (name.startsWith(AUTH_PREFIX) && name !== MCP_AUTH) {\n return new DocumentedAuth(name, call.arguments[0]?.getText());\n }\n }\n return undefined;\n }\n\n /** `@WpMcpTool({ name, readOnly, ... })` — the name plus whichever hints were declared. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static mcpToolOf(\n member: ts.Node,\n folder: ConstantFolder,\n ): DocumentedMcpTool | undefined {\n const call = ApiDocExtractor.decoratorCall(member, MCP_TOOL);\n const argument = call?.arguments[0];\n if (argument === undefined || !ts.isObjectLiteralExpression(argument)) {\n return undefined;\n }\n const hints = new Map<string, boolean>();\n for (const hint of TOOL_HINTS) {\n const value = ApiDocExtractor.findProperty(argument, hint);\n if (value !== undefined) {\n hints.set(hint, value.kind === ts.SyntaxKind.TrueKeyword);\n }\n }\n return new DocumentedMcpTool(\n ApiDocExtractor.stringProperty(argument, 'name', folder) ?? '',\n hints,\n );\n }\n\n /** `@MaskLog({ refreshToken: 'full' })` -> field name -> mask mode. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static maskLogOf(member: ts.Node): ReadonlyMap<string, string> {\n const fields = new Map<string, string>();\n const argument = ApiDocExtractor.decoratorCall(member, MASK_LOG)?.arguments[0];\n if (argument === undefined || !ts.isObjectLiteralExpression(argument)) {\n return fields;\n }\n for (const property of argument.properties) {\n if (\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n ts.isStringLiteralLike(property.initializer)\n ) {\n fields.set(property.name.text, property.initializer.text);\n }\n }\n return fields;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static booleanProperty(\n literal: ts.ObjectLiteralExpression | undefined,\n name: string,\n ): boolean {\n const value =\n literal === undefined ? undefined : ApiDocExtractor.findProperty(literal, name);\n return value?.kind === ts.SyntaxKind.TrueKeyword;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static stringProperty(\n literal: ts.ObjectLiteralExpression | undefined,\n name: string,\n folder: ConstantFolder,\n ): string | undefined {\n const value =\n literal === undefined ? undefined : ApiDocExtractor.findProperty(literal, name);\n return value === undefined ? undefined : folder.tryFoldString(value);\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static findProperty(\n literal: ts.ObjectLiteralExpression,\n name: string,\n ): ts.Expression | undefined {\n for (const property of literal.properties) {\n if (\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n property.name.text === name\n ) {\n return property.initializer;\n }\n }\n return undefined;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static decoratorCall(\n node: ts.Node,\n decoratorName: string,\n ): ts.CallExpression | undefined {\n const decorators = ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n for (const decorator of decorators) {\n const call = decorator.expression;\n if (\n ts.isCallExpression(call) &&\n ts.isIdentifier(call.expression) &&\n call.expression.text === decoratorName\n ) {\n return call;\n }\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ApiDocExtractor.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/ApiDocExtractor.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,oDA0B8B;AAC9B,sDAQ8B;AAE9B,mEAAgE;AAChE,qDAAkD;AAClD,mCAAgC;AAChC,qDAAkD;AAClD,iDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,QAAQ,GAAG,mBAAO,CAAC,IAAI,CAAC;AAC9B,MAAM,QAAQ,GAAG,oBAAQ,CAAC,IAAI,CAAC;AAC/B,MAAM,QAAQ,GAAG,mBAAO,CAAC,IAAI,CAAC;AAC9B,MAAM,QAAQ,GAAG,qBAAS,CAAC,IAAI,CAAC;AAChC,MAAM,QAAQ,GAAG,wBAAY,CAAC,IAAI,CAAC;AACnC,MAAM,YAAY,GAAG,wBAAY,CAAC,IAAI,CAAC;AACvC,MAAM,QAAQ,GAAG,mBAAO,CAAC,IAAI,CAAC;AAE9B;;;;GAIG;AACH,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,oGAAoG;AACpG,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,wBAAY,CAAC,IAAI;IACjB,qBAAS,CAAC,IAAI;IACd,sBAAU,CAAC,IAAI;IACf,8BAAkB,CAAC,IAAI;IACvB,yBAAa,CAAC,IAAI;IAClB,wBAAY,CAAC,IAAI;IACjB,2BAAe,CAAC,IAAI;CACvB,CAAC,CAAC;AAEH,sGAAs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C,IAAI,KAAK,IAAI,EAC7B,CAAC;gBACC,OAAO,QAAQ,CAAC,WAAW,CAAC;YAChC,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,qFAAqF;IAC7E,MAAM,CAAC,aAAa,CACxB,IAAa,EACb,aAAqB;QAErB,MAAM,UAAU,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC;YAClC,IACI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;gBAChC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,aAAa,EACxC,CAAC;gBACC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAnfD,0CAmfC","sourcesContent":["import * as ts from 'typescript';\nimport {\n ApiPath,\n CLOUDTASKS,\n CRON,\n Endpoint,\n EXTERNAL,\n GET,\n MaskLog,\n POST,\n READ,\n RPC,\n WRITE,\n WRITE_IDEMPOTENT,\n WpAuthApiKey,\n WpAuthJwt,\n WpAuthLocalOnly,\n WpAuthOidc,\n WpAuthPublic,\n WpAuthSharedSecret,\n WpAuthWebhook,\n ApiType,\n EXTERNAL_CUSTOMER,\n MCP,\n SVC_TO_SVC,\n WpMcpAuthJwt,\n WpMcpTool,\n} from '@webpieces/core-util';\nimport {\n ApiDocModel,\n DocumentedApiKey,\n DocumentedApiKeyCredential,\n DocumentedAuth,\n DocumentedEndpoint,\n DocumentedEndpointOptions,\n DocumentedMcpTool,\n} from '../model/ApiDocModel';\nimport { TypeRef } from '../model/TypeRef';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\nimport { ConstantFolder } from './ConstantFolder';\nimport { JsDoc } from './JsDoc';\nimport { SourceLocation } from './SourceLocation';\nimport { TypeResolver } from './TypeResolver';\n\n/**\n * The decorator names this extractor matches on, taken from the REAL SYMBOLS rather than re-typed as\n * string literals.\n *\n * ## Why `.name` and not `'Endpoint'`\n *\n * The extractor matches decorators by NAME on the syntax — it must, because it reads a contract with\n * the compiler and never executes it. The question is only where that name comes from, and a literal\n * has a silent failure mode that a symbol does not: rename `@WpMcpTool` in `core-util` and a literal\n * simply stops matching. The extractor then finds zero MCP tools, the MCP document is correctly not\n * written because it has no tools in it, and the BUILD IS GREEN. A partner-facing document silently\n * loses a section with nothing red anywhere (issue #1001).\n *\n * `Endpoint.name` makes that rename a COMPILE ERROR here, which in this repo is the delivery\n * mechanism for a migration rather than an obstacle to one: a compile break names the new spelling\n * and an agent applies it in one pass, where a green build teaches nobody anything.\n *\n * ## Why importing `@webpieces/core-util` is not the coupling it looks like\n *\n * Any contract carrying `@Endpoint` already depends on `core-util` by definition, so there is no\n * upstream project this import could shut out. It is build-time only, it creates no cycle, and it\n * costs a browser bundle nothing because nothing in a bundle imports this package. The direction that\n * WOULD be fatal is `core-util` depending on the TypeScript compiler, and that is not this.\n */\nconst API_PATH = ApiPath.name;\nconst ENDPOINT = Endpoint.name;\nconst MASK_LOG = MaskLog.name;\nconst MCP_TOOL = WpMcpTool.name;\nconst MCP_AUTH = WpMcpAuthJwt.name;\nconst API_KEY_AUTH = WpAuthApiKey.name;\nconst API_TYPE = ApiType.name;\n\n/**\n * The prefix shared by every credential decorator. A PREFIX genuinely has no symbol to take a name\n * from, so it stays a literal — but the set it selects is pinned below, which is what stops it\n * quietly matching nothing.\n */\nconst AUTH_PREFIX = 'WpAuth';\n\n/** Every credential decorator, by real symbol, so a rename of any of them fails to compile here. */\nconst AUTH_DECORATORS = new Set([\n WpAuthPublic.name,\n WpAuthJwt.name,\n WpAuthOidc.name,\n WpAuthSharedSecret.name,\n WpAuthWebhook.name,\n WpAuthApiKey.name,\n WpAuthLocalOnly.name,\n]);\n\n/** The REAL trigger kinds and side-effect contracts, so a contract cannot declare one that is not. */\nconst ENDPOINT_KINDS: readonly string[] = [RPC, CLOUDTASKS, CRON, EXTERNAL];\nconst ENDPOINT_OPERATIONS: readonly string[] = [READ, WRITE_IDEMPOTENT, WRITE];\nconst HTTP_METHODS: readonly string[] = [GET, POST];\n\n/** `@Endpoint`'s four required positions, named so a failure can say which one is missing. */\nconst ARGUMENT_NAMES = ['http method', 'path', 'operation', 'trigger kind'];\n\n/** The allowed values of each required position, in the same order, for the same failure. */\nconst ARGUMENT_VALUES: readonly (readonly string[])[] = [\n HTTP_METHODS,\n [],\n ENDPOINT_OPERATIONS,\n ENDPOINT_KINDS,\n];\n\n/** The REAL document types, so a contract cannot name a document that does not exist. */\nconst API_TYPES: readonly string[] = [SVC_TO_SVC, EXTERNAL_CUSTOMER, MCP];\n\n/** The fail-closed default: a contract that declares nothing feeds only the internal document. */\nconst DEFAULT_API_TYPES: readonly string[] = [SVC_TO_SVC];\n\n/**\n * ONE contract file -> ONE {@link ApiDocModel}. The single extraction pass both the OpenAPI documents\n * and the MCP tool list (#982) are rendered from.\n *\n * ## Why the compiler API at all\n *\n * A DTO field's TYPE IS ERASED AT RUNTIME. Reflection can see that `save` takes one argument; it\n * cannot see that the argument has a `deliveryWindow` that is a discriminated union of two shapes,\n * one of which carries an ISO timestamp. Those are precisely the shapes a partner-grade document is\n * made of, so the only place they exist is the source, and the only honest way to read the source is\n * the compiler.\n *\n * ## Why it IMPORTS `@webpieces/core-util`\n *\n * Decorators are matched BY NAME on the syntax — they must be, because this reads a contract and\n * never executes it. The NAMES come from the real symbols (`Endpoint.name`), so a rename in\n * `core-util` is a compile error here instead of a literal that quietly stops matching. The full\n * argument, and why the import is not the coupling it looks like, is at those constants.\n *\n * ## What it does NOT do\n *\n * It emits nothing. No OpenAPI, no MCP tool definitions, no file — that is #982, and keeping the\n * render out means the two renderers cannot drift apart about what the contract SAYS.\n */\nexport class ApiDocExtractor {\n /**\n * Extract the contract in `entryFile`.\n *\n * @param entryFile absolute path to the `.ts` file holding the `@ApiPath` class.\n * @param compilerOptions handed straight to `ts.createProgram`; the caller owns them because\n * only the caller knows its own `paths` / `lib` setup.\n * @throws ApiDocExtractionError when the file holds no `@ApiPath` class, or when something that\n * must be exact (a path constant, a numeric bound) cannot be established.\n */\n extractFile(entryFile: string, compilerOptions: ts.CompilerOptions = {}): ApiDocModel {\n const program = ts.createProgram([entryFile], compilerOptions);\n const source = program.getSourceFile(entryFile);\n if (source === undefined) {\n throw new ApiDocExtractionError(\n 'entry file is not part of the program',\n entryFile,\n 'Pass an absolute path to a .ts file that exists.',\n );\n }\n return this.extract(program, source);\n }\n\n /** The same extraction against a program the caller already built. */\n extract(program: ts.Program, source: ts.SourceFile): ApiDocModel {\n const checker = program.getTypeChecker();\n const folder = new ConstantFolder(checker);\n const resolver = new TypeResolver(checker);\n\n const contract = this.findContract(source);\n const pathDecorator = ApiDocExtractor.decoratorCall(contract, API_PATH)!;\n const basePathArgument = pathDecorator.arguments[0];\n const basePath =\n basePathArgument === undefined\n ? ''\n : folder.foldString(basePathArgument, '@ApiPath argument');\n\n const apiTypes = this.declaredApiTypes(contract, folder);\n const endpoints: DocumentedEndpoint[] = [];\n for (const member of contract.members) {\n const endpoint = this.endpointOf(member, folder, resolver);\n if (endpoint !== undefined) {\n endpoints.push(endpoint);\n }\n }\n this.assertApiTypeMatchesMcpTools(contract, apiTypes, endpoints);\n\n return new ApiDocModel(\n contract.name?.text ?? '<anonymous>',\n apiTypes,\n basePath,\n JsDoc.read(contract).description,\n endpoints,\n resolver.collectedTypes(),\n resolver.collectedUnmapped(),\n );\n }\n\n /**\n * Extract ONE named type and everything it reaches, from a file that holds NO contract.\n *\n * This exists for a type nothing in a contract points at but a document still publishes — the\n * document-wide error body a renderer's manifest names. Reading it with the SAME resolver is the\n * point: a second reader would be a second answer to \"what shape is this type\", and the two\n * would drift the first time a field changed.\n *\n * @throws ApiDocExtractionError when the file does not declare that name.\n */\n extractType(\n entryFile: string,\n typeName: string,\n compilerOptions: ts.CompilerOptions = {},\n ): ApiDocModel {\n const program = ts.createProgram([entryFile], compilerOptions);\n const source = program.getSourceFile(entryFile);\n if (source === undefined) {\n throw new ApiDocExtractionError(\n 'entry file is not part of the program',\n entryFile,\n 'Pass an absolute path to a .ts file that exists.',\n );\n }\n const resolver = new TypeResolver(program.getTypeChecker());\n const declaration = ApiDocExtractor.declarationNamed(source, typeName);\n if (declaration === undefined) {\n throw new ApiDocExtractionError(\n `no type named '${typeName}' is declared in this file`,\n entryFile,\n `Declare and export '${typeName}' there, or name the file that does.`,\n );\n }\n resolver.resolveDeclaration(typeName, declaration, typeName);\n return new ApiDocModel(\n typeName,\n DEFAULT_API_TYPES,\n '',\n '',\n [],\n resolver.collectedTypes(),\n resolver.collectedUnmapped(),\n );\n }\n\n /** The interface / class / type alias / enum declared under `name` at the file's top level. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static declarationNamed(\n source: ts.SourceFile,\n name: string,\n ): ts.Declaration | undefined {\n for (const statement of source.statements) {\n const named =\n ts.isInterfaceDeclaration(statement) ||\n ts.isClassDeclaration(statement) ||\n ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement);\n if (named && statement.name?.text === name) {\n return statement;\n }\n }\n return undefined;\n }\n\n /** The one `@ApiPath` class in the file. Zero is a hard failure; the FIRST wins if there are two. */\n private findContract(source: ts.SourceFile): ts.ClassDeclaration {\n for (const statement of source.statements) {\n if (\n ts.isClassDeclaration(statement) &&\n ApiDocExtractor.decoratorCall(statement, API_PATH) !== undefined\n ) {\n return statement;\n }\n }\n throw new ApiDocExtractionError(\n 'no @ApiPath class in this file',\n source.fileName,\n 'Point the extractor at the contract file — the one whose class carries @ApiPath.',\n );\n }\n\n /** One `@Endpoint` method. Members without the decorator are not part of the contract. */\n private endpointOf(\n member: ts.ClassElement,\n folder: ConstantFolder,\n resolver: TypeResolver,\n ): DocumentedEndpoint | undefined {\n if (!ts.isMethodDeclaration(member) || !ts.isIdentifier(member.name)) {\n return undefined;\n }\n const call = ApiDocExtractor.decoratorCall(member, ENDPOINT);\n if (call === undefined) {\n return undefined;\n }\n const methodName = member.name.text;\n\n // `@Endpoint(httpMethod, path, operation, kind, options?)` — METHOD-FIRST, five positions.\n // The positions are read here and nowhere else, so the one place that has to change when the\n // decorator changes is this block plus `ARGUMENT_NAMES` beside it.\n const httpMethod = this.requiredArgument(call, methodName, 0, folder);\n const path = this.requiredArgument(call, methodName, 1, folder);\n const operation = this.requiredArgument(call, methodName, 2, folder);\n const kind = this.requiredArgument(call, methodName, 3, folder);\n\n const options = call.arguments[4];\n const literal =\n options !== undefined && ts.isObjectLiteralExpression(options) ? options : undefined;\n\n const doc = JsDoc.read(member);\n const mcpTool = ApiDocExtractor.mcpToolOf(member, folder);\n return new DocumentedEndpoint(\n methodName,\n httpMethod,\n path,\n operation,\n kind,\n ApiDocExtractor.booleanProperty(literal, 'hidden'),\n ApiDocExtractor.booleanProperty(literal, 'openWorld'),\n new DocumentedEndpointOptions(\n ApiDocExtractor.booleanProperty(literal, 'formPost'),\n ApiDocExtractor.stringProperty(literal, 'calledBy', folder),\n ApiDocExtractor.stringProperty(literal, 'callerKind', folder),\n ),\n ApiDocExtractor.authOf(member, folder),\n mcpTool,\n ApiDocExtractor.decoratorCall(member, MCP_AUTH)?.arguments[0]?.getText(),\n ApiDocExtractor.maskLogOf(member),\n doc.description,\n doc.mcp,\n this.requestOf(member, methodName, resolver),\n this.responseOf(member, methodName, resolver),\n );\n }\n\n /**\n * One REQUIRED positional argument of `@Endpoint`, folded to the string it denotes.\n *\n * Every one of the four is an enum member (`POST`, `READ`, `RPC`) as often as it is a literal,\n * and the folder resolves both — a document that printed `RPC` where the trigger goes would be\n * worse than no document. A missing one is a hard failure naming the position, because the\n * alternative is a document quietly missing a verb.\n */\n private requiredArgument(\n call: ts.CallExpression,\n methodName: string,\n index: number,\n folder: ConstantFolder,\n ): string {\n const argument = call.arguments[index];\n const what = ARGUMENT_NAMES[index];\n if (argument === undefined) {\n throw new ApiDocExtractionError(\n `@Endpoint on '${methodName}' declares no ${what}`,\n SourceLocation.of(call),\n \"Write all four: @Endpoint(POST, '/thing', READ, RPC).\",\n );\n }\n const value = folder.foldString(argument, `@Endpoint ${what} on '${methodName}'`);\n const allowed = ARGUMENT_VALUES[index]!;\n if (allowed.length > 0 && !allowed.includes(value)) {\n throw new ApiDocExtractionError(\n `@Endpoint on '${methodName}' declares ${what} '${value}', which is not one of ` +\n allowed.join(', '),\n SourceLocation.of(argument),\n `Use one of the exported constants: ${allowed.join(', ')}.`,\n );\n }\n return value;\n }\n\n /**\n * `@ApiType(...)` on the contract, folded to the real values.\n *\n * A value that is not one of the three documents is a HARD FAILURE rather than a silent drop: a\n * contract that named `CUSTOMER` by mistake would otherwise feed nothing, which looks exactly\n * like a contract somebody deliberately kept internal.\n */\n private declaredApiTypes(node: ts.Node, folder: ConstantFolder): readonly string[] {\n const call = ApiDocExtractor.decoratorCall(node, API_TYPE);\n if (call === undefined) {\n return DEFAULT_API_TYPES;\n }\n const declared = call.arguments.map((argument: ts.Expression) =>\n folder.foldString(argument, `@${API_TYPE} argument`),\n );\n for (const apiType of declared) {\n if (!API_TYPES.includes(apiType)) {\n throw new ApiDocExtractionError(\n `@${API_TYPE} names '${apiType}', which is not a generated document`,\n SourceLocation.of(call),\n `Use one of the exported constants: ${API_TYPES.join(', ')}.`,\n );\n }\n }\n return declared.length === 0 ? DEFAULT_API_TYPES : declared;\n }\n\n /**\n * MCP membership has exactly ONE spelling, and this is the build-time half of enforcing it\n * (`assertApiTypeMatchesMcpTools` in `@webpieces/core-util` is the wiring-time half).\n *\n * Declared in two places, the two can disagree — and the disagreement is invisible, because each\n * declaration is individually valid. That is the defect this whole epic exists to remove, so it\n * fails the DOCUMENT build rather than producing one that quietly lists the wrong tools.\n */\n private assertApiTypeMatchesMcpTools(\n contract: ts.ClassDeclaration,\n apiTypes: readonly string[],\n endpoints: readonly DocumentedEndpoint[],\n ): void {\n const tools = endpoints.filter((e: DocumentedEndpoint) => e.mcpTool !== undefined);\n const declaresMcp = apiTypes.includes(MCP);\n if (declaresMcp && tools.length === 0) {\n throw new ApiDocExtractionError(\n `@${API_TYPE} names MCP but no method carries @${MCP_TOOL}`,\n SourceLocation.of(contract),\n `Add @${MCP_TOOL}({name, description, openWorldHint}) to the methods agents may ` +\n `call, or drop MCP from the @${API_TYPE} list.`,\n );\n }\n if (!declaresMcp && tools.length > 0) {\n const named = tools.map((e: DocumentedEndpoint) => e.methodName).join(', ');\n throw new ApiDocExtractionError(\n `@${MCP_TOOL} is on ${named} but @${API_TYPE} does not name MCP`,\n SourceLocation.of(contract),\n `Add MCP to the @${API_TYPE} list — membership has ONE spelling, so a tool on a ` +\n 'contract nobody published to agents is a contradiction, not a hint.',\n );\n }\n }\n\n /** The FIRST parameter's declared type. An endpoint with no parameter has no request document. */\n private requestOf(\n member: ts.MethodDeclaration,\n methodName: string,\n resolver: TypeResolver,\n ): TypeRef | undefined {\n const parameter = member.parameters[0];\n if (parameter?.type === undefined) {\n return undefined;\n }\n return resolver.resolve(parameter.type, `${methodName}.request`);\n }\n\n /** The declared return type, unwrapped from `Promise<...>` by the resolver. */\n private responseOf(\n member: ts.MethodDeclaration,\n methodName: string,\n resolver: TypeResolver,\n ): TypeRef | undefined {\n if (member.type === undefined) {\n return undefined;\n }\n return resolver.resolve(member.type, `${methodName}.response`);\n }\n\n /** `@WpAuthPublic()`, `@WpAuthJwt({...})`, … — recorded verbatim; this package rules on nothing. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static authOf(member: ts.Node, folder: ConstantFolder): DocumentedAuth | undefined {\n const decorators = ts.canHaveDecorators(member) ? (ts.getDecorators(member) ?? []) : [];\n for (const decorator of decorators) {\n const call = decorator.expression;\n if (!ts.isCallExpression(call) || !ts.isIdentifier(call.expression)) {\n continue;\n }\n const name = call.expression.text;\n if (name.startsWith(AUTH_PREFIX) && AUTH_DECORATORS.has(name)) {\n return new DocumentedAuth(\n name,\n call.arguments.map((argument: ts.Expression) => argument.getText()),\n name === API_KEY_AUTH ? ApiDocExtractor.apiKeyOf(call, folder) : undefined,\n );\n }\n }\n return undefined;\n }\n\n /**\n * `@WpAuthApiKey(regime, [{in: 'header', name: 'x-api-key', description: '…'}, …])`, parsed.\n *\n * A malformed declaration FAILS rather than yielding a half-parsed regime: the credentials are\n * what a published document's security block is made of, and a document that silently omitted\n * one would tell a partner they need fewer credentials than the running hook demands.\n */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static apiKeyOf(call: ts.CallExpression, folder: ConstantFolder): DocumentedApiKey {\n const regimeArgument = call.arguments[0];\n const credentialsArgument = call.arguments[1];\n if (regimeArgument === undefined || credentialsArgument === undefined) {\n throw new ApiDocExtractionError(\n '@WpAuthApiKey needs a regime AND its credentials',\n SourceLocation.of(call),\n \"Write both: @WpAuthApiKey('partner', [{ in: 'header', name: 'x-api-key' }]).\",\n );\n }\n const regime = folder.foldString(regimeArgument, '@WpAuthApiKey regime');\n // FOLLOW a name first: a credential list shared by every method of a contract is written\n // once as a `const` and named per method, which is better source than a copy per method.\n const credentialsLiteral = folder.follow(credentialsArgument);\n if (!ts.isArrayLiteralExpression(credentialsLiteral)) {\n throw new ApiDocExtractionError(\n '@WpAuthApiKey credentials is not an array literal',\n SourceLocation.of(credentialsArgument),\n 'Write the credentials as an array literal, inline or in a `const`; a value ' +\n 'assembled at runtime cannot appear in a published security scheme.',\n );\n }\n const credentials: DocumentedApiKeyCredential[] = [];\n for (const element of credentialsLiteral.elements) {\n credentials.push(ApiDocExtractor.credentialOf(element, folder));\n }\n return new DocumentedApiKey(regime, credentials);\n }\n\n /** ONE `{ in: …, name?: …, description?: … }` credential. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static credentialOf(\n expression: ts.Expression,\n folder: ConstantFolder,\n ): DocumentedApiKeyCredential {\n const element = folder.follow(expression);\n if (!ts.isObjectLiteralExpression(element)) {\n throw new ApiDocExtractionError(\n 'an @WpAuthApiKey credential is not an object literal',\n SourceLocation.of(element),\n \"Write it inline: { in: 'header', name: 'x-api-key' }.\",\n );\n }\n const location = ApiDocExtractor.stringProperty(element, 'in', folder);\n if (location === undefined) {\n throw new ApiDocExtractionError(\n 'an @WpAuthApiKey credential declares no `in`',\n SourceLocation.of(element),\n \"Say where it rides: `in: 'header'` with a name, or `in: 'bearer'`.\",\n );\n }\n return new DocumentedApiKeyCredential(\n location,\n ApiDocExtractor.stringProperty(element, 'name', folder),\n ApiDocExtractor.stringProperty(element, 'description', folder),\n );\n }\n\n /**\n * `@WpMcpTool({ name, openWorldHint })` — the two facts the source cannot otherwise state.\n *\n * `description` is NOT read: the method's JSDoc is the description for the agent and the partner\n * alike. The three side-effect hints are not read either — they are computed from the endpoint's\n * `operation`. See {@link DocumentedMcpTool} for why both of those are deliberate.\n */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static mcpToolOf(\n member: ts.Node,\n folder: ConstantFolder,\n ): DocumentedMcpTool | undefined {\n const call = ApiDocExtractor.decoratorCall(member, MCP_TOOL);\n const argument = call?.arguments[0];\n if (argument === undefined || !ts.isObjectLiteralExpression(argument)) {\n return undefined;\n }\n return new DocumentedMcpTool(\n ApiDocExtractor.stringProperty(argument, 'name', folder) ?? '',\n );\n }\n\n /** `@MaskLog({ refreshToken: 'full' })` -> field name -> mask mode. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static maskLogOf(member: ts.Node): ReadonlyMap<string, string> {\n const fields = new Map<string, string>();\n const argument = ApiDocExtractor.decoratorCall(member, MASK_LOG)?.arguments[0];\n if (argument === undefined || !ts.isObjectLiteralExpression(argument)) {\n return fields;\n }\n for (const property of argument.properties) {\n if (\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n ts.isStringLiteralLike(property.initializer)\n ) {\n fields.set(property.name.text, property.initializer.text);\n }\n }\n return fields;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static booleanProperty(\n literal: ts.ObjectLiteralExpression | undefined,\n name: string,\n ): boolean {\n const value =\n literal === undefined ? undefined : ApiDocExtractor.findProperty(literal, name);\n return value?.kind === ts.SyntaxKind.TrueKeyword;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static stringProperty(\n literal: ts.ObjectLiteralExpression | undefined,\n name: string,\n folder: ConstantFolder,\n ): string | undefined {\n const value =\n literal === undefined ? undefined : ApiDocExtractor.findProperty(literal, name);\n return value === undefined ? undefined : folder.tryFoldString(value);\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static findProperty(\n literal: ts.ObjectLiteralExpression,\n name: string,\n ): ts.Expression | undefined {\n for (const property of literal.properties) {\n if (\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n property.name.text === name\n ) {\n return property.initializer;\n }\n }\n return undefined;\n }\n\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static decoratorCall(\n node: ts.Node,\n decoratorName: string,\n ): ts.CallExpression | undefined {\n const decorators = ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? []) : [];\n for (const decorator of decorators) {\n const call = decorator.expression;\n if (\n ts.isCallExpression(call) &&\n ts.isIdentifier(call.expression) &&\n call.expression.text === decoratorName\n ) {\n return call;\n }\n }\n return undefined;\n }\n}\n"]}
|