@webpieces/api-doc-model 0.4.920 → 0.4.922
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 +2 -2
- package/src/extract/ApiDocExtractor.d.ts +18 -1
- package/src/extract/ApiDocExtractor.js +63 -5
- package/src/extract/ApiDocExtractor.js.map +1 -1
- package/src/extract/CompiledKeyDefinitions.d.ts +25 -0
- package/src/extract/CompiledKeyDefinitions.js +98 -0
- package/src/extract/CompiledKeyDefinitions.js.map +1 -0
- package/src/extract/ConstantFolder.d.ts +14 -0
- package/src/extract/ConstantFolder.js +39 -26
- package/src/extract/ConstantFolder.js.map +1 -1
- package/src/extract/ContextKeyHeaderFolder.d.ts +63 -0
- package/src/extract/ContextKeyHeaderFolder.js +194 -0
- package/src/extract/ContextKeyHeaderFolder.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/model/ApiDocModel.d.ts +10 -4
- package/src/model/ApiDocModel.js +6 -3
- package/src/model/ApiDocModel.js.map +1 -1
|
@@ -60,25 +60,52 @@ class ConstantFolder {
|
|
|
60
60
|
return expression;
|
|
61
61
|
}
|
|
62
62
|
seen.add(expression);
|
|
63
|
-
if (
|
|
63
|
+
if (this.isTransparentWrapper(expression)) {
|
|
64
64
|
return this.followThrough(expression.expression, seen);
|
|
65
65
|
}
|
|
66
66
|
if (!ts.isIdentifier(expression) && !ts.isPropertyAccessExpression(expression)) {
|
|
67
67
|
return expression;
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const initializer = this.initializerOf(this.checker.getSymbolAtLocation(expression));
|
|
70
|
+
return initializer === undefined ? expression : this.followThrough(initializer, seen);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The initializer a symbol was DECLARED with — a `const`, an object-literal property, or a
|
|
74
|
+
* class's `static readonly` property — following an import alias first. Undefined when the
|
|
75
|
+
* declaration has none (a parameter, a `.d.ts` declaration, a `let` with no initializer).
|
|
76
|
+
*/
|
|
77
|
+
initializerOf(symbol) {
|
|
78
|
+
for (const declaration of this.unaliased(symbol)?.declarations ?? []) {
|
|
74
79
|
if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
|
|
75
|
-
return
|
|
80
|
+
return declaration.initializer;
|
|
76
81
|
}
|
|
77
82
|
if (ts.isPropertyAssignment(declaration) && ts.isExpression(declaration.initializer)) {
|
|
78
|
-
return
|
|
83
|
+
return declaration.initializer;
|
|
84
|
+
}
|
|
85
|
+
if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {
|
|
86
|
+
return declaration.initializer;
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
|
-
return
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
/** The symbol a name denotes, with an import alias followed to what it imports. */
|
|
92
|
+
symbolOf(expression) {
|
|
93
|
+
return this.unaliased(this.checker.getSymbolAtLocation(expression));
|
|
94
|
+
}
|
|
95
|
+
unaliased(symbol) {
|
|
96
|
+
return symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0
|
|
97
|
+
? this.checker.getAliasedSymbol(symbol)
|
|
98
|
+
: symbol;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `(x)`, `x as T`, `x satisfies T` and `x!` all DENOTE `x` — none of them changes the value, so a
|
|
102
|
+
* reader looks straight through them. `Keys.ORG_ID.httpHeader!` is the everyday shape (#1249).
|
|
103
|
+
*/
|
|
104
|
+
isTransparentWrapper(expression) {
|
|
105
|
+
return (ts.isParenthesizedExpression(expression) ||
|
|
106
|
+
ts.isAsExpression(expression) ||
|
|
107
|
+
ts.isSatisfiesExpression(expression) ||
|
|
108
|
+
ts.isNonNullExpression(expression));
|
|
82
109
|
}
|
|
83
110
|
tryFold(expression, seen) {
|
|
84
111
|
if (seen.has(expression)) {
|
|
@@ -113,29 +140,15 @@ class ConstantFolder {
|
|
|
113
140
|
if (ts.isIdentifier(expression) || ts.isPropertyAccessExpression(expression)) {
|
|
114
141
|
return this.foldThroughSymbol(expression, seen);
|
|
115
142
|
}
|
|
116
|
-
if (
|
|
143
|
+
if (this.isTransparentWrapper(expression)) {
|
|
117
144
|
return this.tryFold(expression.expression, seen);
|
|
118
145
|
}
|
|
119
146
|
return undefined;
|
|
120
147
|
}
|
|
121
148
|
/** Follow an identifier / `Obj.MEMBER` to its declaration's initializer and fold that. */
|
|
122
149
|
foldThroughSymbol(expression, seen) {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
? this.checker.getAliasedSymbol(symbol)
|
|
126
|
-
: symbol;
|
|
127
|
-
for (const declaration of resolved?.declarations ?? []) {
|
|
128
|
-
if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
|
|
129
|
-
return this.tryFold(declaration.initializer, seen);
|
|
130
|
-
}
|
|
131
|
-
if (ts.isPropertyAssignment(declaration) && ts.isExpression(declaration.initializer)) {
|
|
132
|
-
return this.tryFold(declaration.initializer, seen);
|
|
133
|
-
}
|
|
134
|
-
if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {
|
|
135
|
-
return this.tryFold(declaration.initializer, seen);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return undefined;
|
|
150
|
+
const initializer = this.initializerOf(this.checker.getSymbolAtLocation(expression));
|
|
151
|
+
return initializer === undefined ? undefined : this.tryFold(initializer, seen);
|
|
139
152
|
}
|
|
140
153
|
}
|
|
141
154
|
exports.ConstantFolder = ConstantFolder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConstantFolder.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/ConstantFolder.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,mEAAgE;AAChE,qDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAa,cAAc;IACM;IAA7B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OA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AwIC","sourcesContent":["import * as ts from 'typescript';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\nimport { SourceLocation } from './SourceLocation';\n\n/**\n * Decorator arguments are constants as often as they are literals — `@Endpoint(POST, SAVE_PATH, READ,\n * RPC)`, `@ApiPath(PATHS.SAVE)` — and a document that printed `SAVE_PATH` as the path, or `RPC` as the\n * trigger, would be worse than no document.\n *\n * So the folder resolves them, and where it CANNOT it FAILS. There is deliberately no fallback to\n * the source text and no \"best effort\" path: a partner-grade document that is quietly wrong about a\n * URL is the one failure mode nobody catches by reading it.\n *\n * It asks the CHECKER first, which is what makes this robust across re-exports, imports and\n * `as const` objects: a `const` initialised with a string has a string-LITERAL type, and the checker\n * has already done the resolution. The syntactic walk below it exists only for the shapes the\n * checker widens.\n */\nexport class ConstantFolder {\n constructor(private readonly checker: ts.TypeChecker) {}\n\n /**\n * The string this expression denotes.\n *\n * @throws ApiDocExtractionError when it cannot be established — never a guess.\n */\n foldString(expression: ts.Expression, what: string): string {\n const folded = this.tryFold(expression, new Set<ts.Node>());\n if (folded === undefined) {\n throw new ApiDocExtractionError(\n `${what} is not a foldable constant: '${expression.getText()}'`,\n SourceLocation.of(expression),\n 'Declare it as a `const` initialised with a string literal (or write the literal inline). ' +\n 'A value only known at runtime cannot appear in a published document.',\n );\n }\n return folded;\n }\n\n /** The string this expression denotes, or undefined. No throw — for optional arguments. */\n tryFoldString(expression: ts.Expression): string | undefined {\n return this.tryFold(expression, new Set<ts.Node>());\n }\n\n /**\n * The expression a name ultimately DENOTES, following `const` declarations through imports.\n *\n * A decorator argument is a constant as often as it is a literal, and that is true of structures\n * too: a credential list shared by every method of a contract is written once as a `const` and\n * named five times, which is better source than five copies. A reader that only understood a\n * literal would force the copies — so the copies would happen, and one of them would drift.\n *\n * Returns the expression unchanged when it is not a name, so a caller can follow first and then\n * ask what shape it is.\n */\n follow(expression: ts.Expression): ts.Expression {\n return this.followThrough(expression, new Set<ts.Node>());\n }\n\n private followThrough(expression: ts.Expression, seen: Set<ts.Node>): ts.Expression {\n if (seen.has(expression)) {\n return expression;\n }\n seen.add(expression);\n if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression)) {\n return this.followThrough(expression.expression, seen);\n }\n if (!ts.isIdentifier(expression) && !ts.isPropertyAccessExpression(expression)) {\n return expression;\n }\n const symbol = this.checker.getSymbolAtLocation(expression);\n const resolved =\n symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0\n ? this.checker.getAliasedSymbol(symbol)\n : symbol;\n for (const declaration of resolved?.declarations ?? []) {\n if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n return this.followThrough(declaration.initializer, seen);\n }\n if (ts.isPropertyAssignment(declaration) && ts.isExpression(declaration.initializer)) {\n return this.followThrough(declaration.initializer, seen);\n }\n }\n return expression;\n }\n\n private tryFold(expression: ts.Expression, seen: Set<ts.Node>): string | undefined {\n if (seen.has(expression)) {\n return undefined; // a const initialised from itself; not our problem to diagnose\n }\n seen.add(expression);\n\n if (ts.isStringLiteralLike(expression)) {\n return expression.text;\n }\n\n // The checker's answer, which already resolved imports, re-exports and `as const`.\n const type = this.checker.getTypeAtLocation(expression);\n if (type.isStringLiteral()) {\n return type.value;\n }\n\n if (ts.isTemplateExpression(expression)) {\n let out = expression.head.text;\n for (const span of expression.templateSpans) {\n const part = this.tryFold(span.expression, seen);\n if (part === undefined) {\n return undefined;\n }\n out += part + span.literal.text;\n }\n return out;\n }\n\n if (\n ts.isBinaryExpression(expression) &&\n expression.operatorToken.kind === ts.SyntaxKind.PlusToken\n ) {\n const left = this.tryFold(expression.left, seen);\n const right = this.tryFold(expression.right, seen);\n return left === undefined || right === undefined ? undefined : left + right;\n }\n\n if (ts.isIdentifier(expression) || ts.isPropertyAccessExpression(expression)) {\n return this.foldThroughSymbol(expression, seen);\n }\n\n if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression)) {\n return this.tryFold(expression.expression, seen);\n }\n\n return undefined;\n }\n\n /** Follow an identifier / `Obj.MEMBER` to its declaration's initializer and fold that. */\n private foldThroughSymbol(expression: ts.Expression, seen: Set<ts.Node>): string | undefined {\n const symbol = this.checker.getSymbolAtLocation(expression);\n const resolved =\n symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0\n ? this.checker.getAliasedSymbol(symbol)\n : symbol;\n for (const declaration of resolved?.declarations ?? []) {\n if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n return this.tryFold(declaration.initializer, seen);\n }\n if (ts.isPropertyAssignment(declaration) && ts.isExpression(declaration.initializer)) {\n return this.tryFold(declaration.initializer, seen);\n }\n if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {\n return this.tryFold(declaration.initializer, seen);\n }\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ConstantFolder.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/ConstantFolder.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,mEAAgE;AAChE,qDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAa,cAAc;IACM;IAA7B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD;;;;OAIG;IACH,UAAU,CAAC,UAAyB,EAAE,IAAY;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,GAAG,EAAW,CAAC,CAAC;QAC5D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,6CAAqB,CAC3B,GAAG,IAAI,iCAAiC,UAAU,CAAC,OAAO,EAAE,GAAG,EAC/D,+BAAc,CAAC,EAAE,CAAC,UAAU,CAAC,EAC7B,2FAA2F;gBACvF,sEAAsE,CAC7E,CAAC;QACN,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,2FAA2F;IAC3F,aAAa,CAAC,UAAyB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,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AE,CAAC;YAC3E,OAAO,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,0FAA0F;IAClF,iBAAiB,CAAC,UAAyB,EAAE,IAAkB;QACnE,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;QACrF,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC;CACJ;AA/JD,wCA+JC","sourcesContent":["import * as ts from 'typescript';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\nimport { SourceLocation } from './SourceLocation';\n\n/**\n * Decorator arguments are constants as often as they are literals — `@Endpoint(POST, SAVE_PATH, READ,\n * RPC)`, `@ApiPath(PATHS.SAVE)` — and a document that printed `SAVE_PATH` as the path, or `RPC` as the\n * trigger, would be worse than no document.\n *\n * So the folder resolves them, and where it CANNOT it FAILS. There is deliberately no fallback to\n * the source text and no \"best effort\" path: a partner-grade document that is quietly wrong about a\n * URL is the one failure mode nobody catches by reading it.\n *\n * It asks the CHECKER first, which is what makes this robust across re-exports, imports and\n * `as const` objects: a `const` initialised with a string has a string-LITERAL type, and the checker\n * has already done the resolution. The syntactic walk below it exists only for the shapes the\n * checker widens.\n */\nexport class ConstantFolder {\n constructor(private readonly checker: ts.TypeChecker) {}\n\n /**\n * The string this expression denotes.\n *\n * @throws ApiDocExtractionError when it cannot be established — never a guess.\n */\n foldString(expression: ts.Expression, what: string): string {\n const folded = this.tryFold(expression, new Set<ts.Node>());\n if (folded === undefined) {\n throw new ApiDocExtractionError(\n `${what} is not a foldable constant: '${expression.getText()}'`,\n SourceLocation.of(expression),\n 'Declare it as a `const` initialised with a string literal (or write the literal inline). ' +\n 'A value only known at runtime cannot appear in a published document.',\n );\n }\n return folded;\n }\n\n /** The string this expression denotes, or undefined. No throw — for optional arguments. */\n tryFoldString(expression: ts.Expression): string | undefined {\n return this.tryFold(expression, new Set<ts.Node>());\n }\n\n /**\n * The expression a name ultimately DENOTES, following `const` declarations through imports.\n *\n * A decorator argument is a constant as often as it is a literal, and that is true of structures\n * too: a credential list shared by every method of a contract is written once as a `const` and\n * named five times, which is better source than five copies. A reader that only understood a\n * literal would force the copies — so the copies would happen, and one of them would drift.\n *\n * Returns the expression unchanged when it is not a name, so a caller can follow first and then\n * ask what shape it is.\n */\n follow(expression: ts.Expression): ts.Expression {\n return this.followThrough(expression, new Set<ts.Node>());\n }\n\n private followThrough(expression: ts.Expression, seen: Set<ts.Node>): ts.Expression {\n if (seen.has(expression)) {\n return expression;\n }\n seen.add(expression);\n if (this.isTransparentWrapper(expression)) {\n return this.followThrough(expression.expression, seen);\n }\n if (!ts.isIdentifier(expression) && !ts.isPropertyAccessExpression(expression)) {\n return expression;\n }\n const initializer = this.initializerOf(this.checker.getSymbolAtLocation(expression));\n return initializer === undefined ? expression : this.followThrough(initializer, seen);\n }\n\n /**\n * The initializer a symbol was DECLARED with — a `const`, an object-literal property, or a\n * class's `static readonly` property — following an import alias first. Undefined when the\n * declaration has none (a parameter, a `.d.ts` declaration, a `let` with no initializer).\n */\n initializerOf(symbol: ts.Symbol | undefined): ts.Expression | undefined {\n for (const declaration of this.unaliased(symbol)?.declarations ?? []) {\n if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n return declaration.initializer;\n }\n if (ts.isPropertyAssignment(declaration) && ts.isExpression(declaration.initializer)) {\n return declaration.initializer;\n }\n if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {\n return declaration.initializer;\n }\n }\n return undefined;\n }\n\n /** The symbol a name denotes, with an import alias followed to what it imports. */\n symbolOf(expression: ts.Expression): ts.Symbol | undefined {\n return this.unaliased(this.checker.getSymbolAtLocation(expression));\n }\n\n private unaliased(symbol: ts.Symbol | undefined): ts.Symbol | undefined {\n return symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0\n ? this.checker.getAliasedSymbol(symbol)\n : symbol;\n }\n\n /**\n * `(x)`, `x as T`, `x satisfies T` and `x!` all DENOTE `x` — none of them changes the value, so a\n * reader looks straight through them. `Keys.ORG_ID.httpHeader!` is the everyday shape (#1249).\n */\n private isTransparentWrapper(\n expression: ts.Expression,\n ): expression is\n | ts.ParenthesizedExpression\n | ts.AsExpression\n | ts.SatisfiesExpression\n | ts.NonNullExpression {\n return (\n ts.isParenthesizedExpression(expression) ||\n ts.isAsExpression(expression) ||\n ts.isSatisfiesExpression(expression) ||\n ts.isNonNullExpression(expression)\n );\n }\n\n private tryFold(expression: ts.Expression, seen: Set<ts.Node>): string | undefined {\n if (seen.has(expression)) {\n return undefined; // a const initialised from itself; not our problem to diagnose\n }\n seen.add(expression);\n\n if (ts.isStringLiteralLike(expression)) {\n return expression.text;\n }\n\n // The checker's answer, which already resolved imports, re-exports and `as const`.\n const type = this.checker.getTypeAtLocation(expression);\n if (type.isStringLiteral()) {\n return type.value;\n }\n\n if (ts.isTemplateExpression(expression)) {\n let out = expression.head.text;\n for (const span of expression.templateSpans) {\n const part = this.tryFold(span.expression, seen);\n if (part === undefined) {\n return undefined;\n }\n out += part + span.literal.text;\n }\n return out;\n }\n\n if (\n ts.isBinaryExpression(expression) &&\n expression.operatorToken.kind === ts.SyntaxKind.PlusToken\n ) {\n const left = this.tryFold(expression.left, seen);\n const right = this.tryFold(expression.right, seen);\n return left === undefined || right === undefined ? undefined : left + right;\n }\n\n if (ts.isIdentifier(expression) || ts.isPropertyAccessExpression(expression)) {\n return this.foldThroughSymbol(expression, seen);\n }\n\n if (this.isTransparentWrapper(expression)) {\n return this.tryFold(expression.expression, seen);\n }\n\n return undefined;\n }\n\n /** Follow an identifier / `Obj.MEMBER` to its declaration's initializer and fold that. */\n private foldThroughSymbol(expression: ts.Expression, seen: Set<ts.Node>): string | undefined {\n const initializer = this.initializerOf(this.checker.getSymbolAtLocation(expression));\n return initializer === undefined ? undefined : this.tryFold(initializer, seen);\n }\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { ConstantFolder } from './ConstantFolder';
|
|
3
|
+
/** Which of a ContextKey's two wire names to read. */
|
|
4
|
+
export declare enum ContextKeyHeaderSlot {
|
|
5
|
+
/** `httpHeader` — the name the key rides under on a REQUEST. An api-key credential's header. */
|
|
6
|
+
REQUEST = "httpHeader",
|
|
7
|
+
/** `responseHeader` — the name the key is written back under on a RESPONSE. */
|
|
8
|
+
RESPONSE = "responseHeader"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read a HEADER NAME off a `ContextKey` reference, statically (#1249).
|
|
12
|
+
*
|
|
13
|
+
* Header names are never written as strings on a documented surface: an api-key credential names
|
|
14
|
+
* the ContextKey carrying it (`{ in: 'header', key: OneTabletKey.ORG_ID }`), and a manifest's
|
|
15
|
+
* response header names an exported ContextKey const. ONE definition of each header — the
|
|
16
|
+
* `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` call — is therefore what the server,
|
|
17
|
+
* the clients and the published document all read, so a rename cannot leave a copy stale.
|
|
18
|
+
*
|
|
19
|
+
* This follows the reference — through `!`, `as`, `satisfies`, parentheses, `const`s, imports,
|
|
20
|
+
* object-literal properties and a class's `static readonly` properties — to that factory call, and
|
|
21
|
+
* folds the header argument with the same {@link ConstantFolder} every other decorator argument
|
|
22
|
+
* goes through.
|
|
23
|
+
*
|
|
24
|
+
* It FAILS rather than guessing, and the refusal quotes the EXPRESSION it could not resolve: a
|
|
25
|
+
* document that silently dropped a header would tell a partner they need one credential fewer than
|
|
26
|
+
* the running hook demands.
|
|
27
|
+
*/
|
|
28
|
+
export declare class ContextKeyHeaderFolder {
|
|
29
|
+
private readonly folder;
|
|
30
|
+
private readonly compiled;
|
|
31
|
+
constructor(folder: ConstantFolder);
|
|
32
|
+
/**
|
|
33
|
+
* The header name `expression` — a reference to a ContextKey — rides under in `slot`.
|
|
34
|
+
*
|
|
35
|
+
* @param what names the surface for the refusal, e.g. "the apiKey(...) header credential's key".
|
|
36
|
+
* @throws ApiDocExtractionError naming the expression when it cannot be established.
|
|
37
|
+
*/
|
|
38
|
+
fold(expression: ts.Expression, slot: ContextKeyHeaderSlot, what: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Same as {@link fold}, starting from a SYMBOL — an exported const a manifest names, possibly a
|
|
41
|
+
* dotted path into a class or object (`OneTabletKey.TX_ID`).
|
|
42
|
+
*/
|
|
43
|
+
foldSymbol(symbol: ts.Symbol, written: string, where: string, slot: ContextKeyHeaderSlot, what: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* The definition a `.d.ts` declaration lost, read from its compiled `.js` sibling — see
|
|
46
|
+
* {@link CompiledKeyDefinitions}. Undefined when the symbol is not declared in a `.d.ts`.
|
|
47
|
+
*/
|
|
48
|
+
private publishedDefinition;
|
|
49
|
+
/**
|
|
50
|
+
* Fold a definition read from COMPILED JavaScript. Those nodes are outside the checker's
|
|
51
|
+
* program, so nothing here asks the checker: the factory is recognised by its spelling
|
|
52
|
+
* (`<anything>.ContextKey.untrusted(...)`, the shape tsc emits for an import) and the header must
|
|
53
|
+
* be a string literal in the compiled call; anything else is refused quoting the compiled text.
|
|
54
|
+
*/
|
|
55
|
+
private foldPublished;
|
|
56
|
+
private publishedFactoryOf;
|
|
57
|
+
private noHeader;
|
|
58
|
+
private foldDefinition;
|
|
59
|
+
private unresolvable;
|
|
60
|
+
/** `trusted` / `untrusted` when this is `ContextKey.trusted(...)` / `ContextKey.untrusted(...)`. */
|
|
61
|
+
private factoryOf;
|
|
62
|
+
private isUndefined;
|
|
63
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextKeyHeaderFolder = exports.ContextKeyHeaderSlot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
6
|
+
const ApiDocExtractionError_1 = require("./ApiDocExtractionError");
|
|
7
|
+
const CompiledKeyDefinitions_1 = require("./CompiledKeyDefinitions");
|
|
8
|
+
const SourceLocation_1 = require("./SourceLocation");
|
|
9
|
+
/** Which of a ContextKey's two wire names to read. */
|
|
10
|
+
var ContextKeyHeaderSlot;
|
|
11
|
+
(function (ContextKeyHeaderSlot) {
|
|
12
|
+
/** `httpHeader` — the name the key rides under on a REQUEST. An api-key credential's header. */
|
|
13
|
+
ContextKeyHeaderSlot["REQUEST"] = "httpHeader";
|
|
14
|
+
/** `responseHeader` — the name the key is written back under on a RESPONSE. */
|
|
15
|
+
ContextKeyHeaderSlot["RESPONSE"] = "responseHeader";
|
|
16
|
+
})(ContextKeyHeaderSlot || (exports.ContextKeyHeaderSlot = ContextKeyHeaderSlot = {}));
|
|
17
|
+
/** The class whose two factories define every context key. Matched by name, through imports. */
|
|
18
|
+
const CONTEXT_KEY = 'ContextKey';
|
|
19
|
+
/**
|
|
20
|
+
* WHERE each factory takes each header, positionally — the two factories differ by `provenance`,
|
|
21
|
+
* which only `trusted` has:
|
|
22
|
+
*
|
|
23
|
+
* ContextKey.trusted(name, provenance, httpHeader?, maskInLogs?, isLogged?, responseHeader?, merge?)
|
|
24
|
+
* ContextKey.untrusted(name, httpHeader?, maskInLogs?, isLogged?, responseHeader?, merge?)
|
|
25
|
+
*/
|
|
26
|
+
const ARGUMENT_INDEX = new Map([
|
|
27
|
+
[
|
|
28
|
+
'trusted',
|
|
29
|
+
new Map([
|
|
30
|
+
[ContextKeyHeaderSlot.REQUEST, 2],
|
|
31
|
+
[ContextKeyHeaderSlot.RESPONSE, 5],
|
|
32
|
+
]),
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
'untrusted',
|
|
36
|
+
new Map([
|
|
37
|
+
[ContextKeyHeaderSlot.REQUEST, 1],
|
|
38
|
+
[ContextKeyHeaderSlot.RESPONSE, 4],
|
|
39
|
+
]),
|
|
40
|
+
],
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Read a HEADER NAME off a `ContextKey` reference, statically (#1249).
|
|
44
|
+
*
|
|
45
|
+
* Header names are never written as strings on a documented surface: an api-key credential names
|
|
46
|
+
* the ContextKey carrying it (`{ in: 'header', key: OneTabletKey.ORG_ID }`), and a manifest's
|
|
47
|
+
* response header names an exported ContextKey const. ONE definition of each header — the
|
|
48
|
+
* `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` call — is therefore what the server,
|
|
49
|
+
* the clients and the published document all read, so a rename cannot leave a copy stale.
|
|
50
|
+
*
|
|
51
|
+
* This follows the reference — through `!`, `as`, `satisfies`, parentheses, `const`s, imports,
|
|
52
|
+
* object-literal properties and a class's `static readonly` properties — to that factory call, and
|
|
53
|
+
* folds the header argument with the same {@link ConstantFolder} every other decorator argument
|
|
54
|
+
* goes through.
|
|
55
|
+
*
|
|
56
|
+
* It FAILS rather than guessing, and the refusal quotes the EXPRESSION it could not resolve: a
|
|
57
|
+
* document that silently dropped a header would tell a partner they need one credential fewer than
|
|
58
|
+
* the running hook demands.
|
|
59
|
+
*/
|
|
60
|
+
class ContextKeyHeaderFolder {
|
|
61
|
+
folder;
|
|
62
|
+
compiled = new CompiledKeyDefinitions_1.CompiledKeyDefinitions();
|
|
63
|
+
constructor(folder) {
|
|
64
|
+
this.folder = folder;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The header name `expression` — a reference to a ContextKey — rides under in `slot`.
|
|
68
|
+
*
|
|
69
|
+
* @param what names the surface for the refusal, e.g. "the apiKey(...) header credential's key".
|
|
70
|
+
* @throws ApiDocExtractionError naming the expression when it cannot be established.
|
|
71
|
+
*/
|
|
72
|
+
fold(expression, slot, what) {
|
|
73
|
+
const definition = this.folder.follow(expression);
|
|
74
|
+
if (!ts.isCallExpression(definition)) {
|
|
75
|
+
// Followed as far as source goes: a key from a PUBLISHED package stops at its `.d.ts`.
|
|
76
|
+
const published = this.publishedDefinition(this.folder.symbolOf(definition));
|
|
77
|
+
if (published !== undefined) {
|
|
78
|
+
return this.foldPublished(published, expression.getText(), slot, what);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return this.foldDefinition(definition, expression.getText(), expression, slot, what);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Same as {@link fold}, starting from a SYMBOL — an exported const a manifest names, possibly a
|
|
85
|
+
* dotted path into a class or object (`OneTabletKey.TX_ID`).
|
|
86
|
+
*/
|
|
87
|
+
foldSymbol(symbol, written, where, slot, what) {
|
|
88
|
+
const initializer = this.folder.initializerOf(symbol);
|
|
89
|
+
if (initializer === undefined) {
|
|
90
|
+
const published = this.publishedDefinition(symbol);
|
|
91
|
+
if (published !== undefined) {
|
|
92
|
+
return this.foldPublished(published, written, slot, what);
|
|
93
|
+
}
|
|
94
|
+
throw this.unresolvable(written, where, what);
|
|
95
|
+
}
|
|
96
|
+
const definition = this.folder.follow(initializer);
|
|
97
|
+
if (!ts.isCallExpression(definition)) {
|
|
98
|
+
const published = this.publishedDefinition(this.folder.symbolOf(definition));
|
|
99
|
+
if (published !== undefined) {
|
|
100
|
+
return this.foldPublished(published, written, slot, what);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return this.foldDefinition(definition, written, initializer, slot, what);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The definition a `.d.ts` declaration lost, read from its compiled `.js` sibling — see
|
|
107
|
+
* {@link CompiledKeyDefinitions}. Undefined when the symbol is not declared in a `.d.ts`.
|
|
108
|
+
*/
|
|
109
|
+
publishedDefinition(symbol) {
|
|
110
|
+
for (const declaration of symbol?.declarations ?? []) {
|
|
111
|
+
const initializer = this.compiled.initializerOf(declaration);
|
|
112
|
+
if (initializer !== undefined) {
|
|
113
|
+
return initializer;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Fold a definition read from COMPILED JavaScript. Those nodes are outside the checker's
|
|
120
|
+
* program, so nothing here asks the checker: the factory is recognised by its spelling
|
|
121
|
+
* (`<anything>.ContextKey.untrusted(...)`, the shape tsc emits for an import) and the header must
|
|
122
|
+
* be a string literal in the compiled call; anything else is refused quoting the compiled text.
|
|
123
|
+
*/
|
|
124
|
+
foldPublished(definition, written, slot, what) {
|
|
125
|
+
const factory = ts.isCallExpression(definition) ? this.publishedFactoryOf(definition) : undefined;
|
|
126
|
+
if (factory === undefined || !ts.isCallExpression(definition)) {
|
|
127
|
+
throw this.unresolvable(written, definition.getSourceFile().fileName, what);
|
|
128
|
+
}
|
|
129
|
+
const argument = definition.arguments[ARGUMENT_INDEX.get(factory).get(slot)];
|
|
130
|
+
if (argument === undefined || this.isUndefined(argument)) {
|
|
131
|
+
throw this.noHeader(written, definition, factory, slot, what);
|
|
132
|
+
}
|
|
133
|
+
if (!ts.isStringLiteralLike(argument) || argument.text.trim() === '') {
|
|
134
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`${what} '${written}': the ${slot} of its published ContextKey is not a string literal: '${argument.getText()}'`, SourceLocation_1.SourceLocation.of(argument), "Write the header name as a string literal in the key's ContextKey.trusted(...) / " +
|
|
135
|
+
'ContextKey.untrusted(...) call in the package that defines it.');
|
|
136
|
+
}
|
|
137
|
+
return argument.text;
|
|
138
|
+
}
|
|
139
|
+
publishedFactoryOf(call) {
|
|
140
|
+
const callee = call.expression;
|
|
141
|
+
if (!ts.isPropertyAccessExpression(callee) || !ARGUMENT_INDEX.has(callee.name.text)) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const owner = callee.expression;
|
|
145
|
+
const named = (ts.isIdentifier(owner) && owner.text === CONTEXT_KEY) ||
|
|
146
|
+
(ts.isPropertyAccessExpression(owner) && owner.name.text === CONTEXT_KEY);
|
|
147
|
+
return named ? callee.name.text : undefined;
|
|
148
|
+
}
|
|
149
|
+
noHeader(written, definition, factory, slot, what) {
|
|
150
|
+
return new ApiDocExtractionError_1.ApiDocExtractionError(`${what} '${written}' is a ContextKey that declares no ${slot}`, SourceLocation_1.SourceLocation.of(definition), `Give the key its ${slot} in its ContextKey.${factory}(...) definition — a key with no ` +
|
|
151
|
+
'header name never crosses the wire, so it cannot be documented as one.');
|
|
152
|
+
}
|
|
153
|
+
foldDefinition(definition, written, at, slot, what) {
|
|
154
|
+
const factory = ts.isCallExpression(definition) ? this.factoryOf(definition) : undefined;
|
|
155
|
+
if (factory === undefined || !ts.isCallExpression(definition)) {
|
|
156
|
+
throw this.unresolvable(written, SourceLocation_1.SourceLocation.of(at), what);
|
|
157
|
+
}
|
|
158
|
+
const index = ARGUMENT_INDEX.get(factory).get(slot);
|
|
159
|
+
const argument = definition.arguments[index];
|
|
160
|
+
if (argument === undefined || this.isUndefined(argument)) {
|
|
161
|
+
throw this.noHeader(written, definition, factory, slot, what);
|
|
162
|
+
}
|
|
163
|
+
const header = this.folder.tryFoldString(argument);
|
|
164
|
+
if (header === undefined || header.trim() === '') {
|
|
165
|
+
throw new ApiDocExtractionError_1.ApiDocExtractionError(`${what} '${written}': the ${slot} of its ContextKey is not a foldable constant: '${argument.getText()}'`, SourceLocation_1.SourceLocation.of(argument), 'Write the header name as a string literal (or a `const` initialised with one) in the ' +
|
|
166
|
+
"key's ContextKey.trusted(...) / ContextKey.untrusted(...) call.");
|
|
167
|
+
}
|
|
168
|
+
return header;
|
|
169
|
+
}
|
|
170
|
+
unresolvable(written, where, what) {
|
|
171
|
+
return new ApiDocExtractionError_1.ApiDocExtractionError(`cannot statically resolve ${what} '${written}' to a ContextKey.trusted(...) / ContextKey.untrusted(...) definition`, where, 'Reference a ContextKey declared as a `const`, an object property, or a class `static readonly` ' +
|
|
172
|
+
'initialised directly by ContextKey.trusted(...) or ContextKey.untrusted(...) — in source, or in ' +
|
|
173
|
+
'a published package whose compiled .js ships beside its .d.ts. A key only known at runtime ' +
|
|
174
|
+
'has no header name a document can read.');
|
|
175
|
+
}
|
|
176
|
+
/** `trusted` / `untrusted` when this is `ContextKey.trusted(...)` / `ContextKey.untrusted(...)`. */
|
|
177
|
+
factoryOf(call) {
|
|
178
|
+
const callee = call.expression;
|
|
179
|
+
if (!ts.isPropertyAccessExpression(callee) || !ARGUMENT_INDEX.has(callee.name.text)) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const resolved = this.folder.symbolOf(callee.expression);
|
|
183
|
+
// The resolved name covers an aliased import (`import { ContextKey as Key }`); the written
|
|
184
|
+
// name covers a program that could not resolve the module at all.
|
|
185
|
+
const named = resolved?.name === CONTEXT_KEY ||
|
|
186
|
+
(ts.isIdentifier(callee.expression) && callee.expression.text === CONTEXT_KEY);
|
|
187
|
+
return named ? callee.name.text : undefined;
|
|
188
|
+
}
|
|
189
|
+
isUndefined(argument) {
|
|
190
|
+
return ts.isIdentifier(argument) && argument.text === 'undefined';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.ContextKeyHeaderFolder = ContextKeyHeaderFolder;
|
|
194
|
+
//# sourceMappingURL=ContextKeyHeaderFolder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextKeyHeaderFolder.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/ContextKeyHeaderFolder.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,mEAAgE;AAChE,qEAAkE;AAElE,qDAAkD;AAElD,sDAAsD;AACtD,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC5B,gGAAgG;IAChG,8CAAsB,CAAA;IACtB,+EAA+E;IAC/E,mDAA2B,CAAA;AAC/B,CAAC,EALW,oB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5F,SAAS,CAAC,IAAuB;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClF,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzD,2FAA2F;QAC3F,kEAAkE;QAClE,MAAM,KAAK,GACP,QAAQ,EAAE,IAAI,KAAK,WAAW;YAC9B,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QACnF,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAChD,CAAC;IAEO,WAAW,CAAC,QAAuB;QACvC,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,CAAC;IACtE,CAAC;CACJ;AAhLD,wDAgLC","sourcesContent":["import * as ts from 'typescript';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\nimport { CompiledKeyDefinitions } from './CompiledKeyDefinitions';\nimport { ConstantFolder } from './ConstantFolder';\nimport { SourceLocation } from './SourceLocation';\n\n/** Which of a ContextKey's two wire names to read. */\nexport enum ContextKeyHeaderSlot {\n /** `httpHeader` — the name the key rides under on a REQUEST. An api-key credential's header. */\n REQUEST = 'httpHeader',\n /** `responseHeader` — the name the key is written back under on a RESPONSE. */\n RESPONSE = 'responseHeader',\n}\n\n/** The class whose two factories define every context key. Matched by name, through imports. */\nconst CONTEXT_KEY = 'ContextKey';\n\n/**\n * WHERE each factory takes each header, positionally — the two factories differ by `provenance`,\n * which only `trusted` has:\n *\n * ContextKey.trusted(name, provenance, httpHeader?, maskInLogs?, isLogged?, responseHeader?, merge?)\n * ContextKey.untrusted(name, httpHeader?, maskInLogs?, isLogged?, responseHeader?, merge?)\n */\nconst ARGUMENT_INDEX: ReadonlyMap<string, ReadonlyMap<ContextKeyHeaderSlot, number>> = new Map([\n [\n 'trusted',\n new Map([\n [ContextKeyHeaderSlot.REQUEST, 2],\n [ContextKeyHeaderSlot.RESPONSE, 5],\n ]),\n ],\n [\n 'untrusted',\n new Map([\n [ContextKeyHeaderSlot.REQUEST, 1],\n [ContextKeyHeaderSlot.RESPONSE, 4],\n ]),\n ],\n]);\n\n/**\n * Read a HEADER NAME off a `ContextKey` reference, statically (#1249).\n *\n * Header names are never written as strings on a documented surface: an api-key credential names\n * the ContextKey carrying it (`{ in: 'header', key: OneTabletKey.ORG_ID }`), and a manifest's\n * response header names an exported ContextKey const. ONE definition of each header — the\n * `ContextKey.trusted(...)` / `ContextKey.untrusted(...)` call — is therefore what the server,\n * the clients and the published document all read, so a rename cannot leave a copy stale.\n *\n * This follows the reference — through `!`, `as`, `satisfies`, parentheses, `const`s, imports,\n * object-literal properties and a class's `static readonly` properties — to that factory call, and\n * folds the header argument with the same {@link ConstantFolder} every other decorator argument\n * goes through.\n *\n * It FAILS rather than guessing, and the refusal quotes the EXPRESSION it could not resolve: a\n * document that silently dropped a header would tell a partner they need one credential fewer than\n * the running hook demands.\n */\nexport class ContextKeyHeaderFolder {\n private readonly compiled = new CompiledKeyDefinitions();\n\n constructor(private readonly folder: ConstantFolder) {}\n\n /**\n * The header name `expression` — a reference to a ContextKey — rides under in `slot`.\n *\n * @param what names the surface for the refusal, e.g. \"the apiKey(...) header credential's key\".\n * @throws ApiDocExtractionError naming the expression when it cannot be established.\n */\n fold(expression: ts.Expression, slot: ContextKeyHeaderSlot, what: string): string {\n const definition = this.folder.follow(expression);\n if (!ts.isCallExpression(definition)) {\n // Followed as far as source goes: a key from a PUBLISHED package stops at its `.d.ts`.\n const published = this.publishedDefinition(this.folder.symbolOf(definition));\n if (published !== undefined) {\n return this.foldPublished(published, expression.getText(), slot, what);\n }\n }\n return this.foldDefinition(definition, expression.getText(), expression, slot, what);\n }\n\n /**\n * Same as {@link fold}, starting from a SYMBOL — an exported const a manifest names, possibly a\n * dotted path into a class or object (`OneTabletKey.TX_ID`).\n */\n foldSymbol(\n symbol: ts.Symbol,\n written: string,\n where: string,\n slot: ContextKeyHeaderSlot,\n what: string,\n ): string {\n const initializer = this.folder.initializerOf(symbol);\n if (initializer === undefined) {\n const published = this.publishedDefinition(symbol);\n if (published !== undefined) {\n return this.foldPublished(published, written, slot, what);\n }\n throw this.unresolvable(written, where, what);\n }\n const definition = this.folder.follow(initializer);\n if (!ts.isCallExpression(definition)) {\n const published = this.publishedDefinition(this.folder.symbolOf(definition));\n if (published !== undefined) {\n return this.foldPublished(published, written, slot, what);\n }\n }\n return this.foldDefinition(definition, written, initializer, slot, what);\n }\n\n /**\n * The definition a `.d.ts` declaration lost, read from its compiled `.js` sibling — see\n * {@link CompiledKeyDefinitions}. Undefined when the symbol is not declared in a `.d.ts`.\n */\n private publishedDefinition(symbol: ts.Symbol | undefined): ts.Expression | undefined {\n for (const declaration of symbol?.declarations ?? []) {\n const initializer = this.compiled.initializerOf(declaration);\n if (initializer !== undefined) {\n return initializer;\n }\n }\n return undefined;\n }\n\n /**\n * Fold a definition read from COMPILED JavaScript. Those nodes are outside the checker's\n * program, so nothing here asks the checker: the factory is recognised by its spelling\n * (`<anything>.ContextKey.untrusted(...)`, the shape tsc emits for an import) and the header must\n * be a string literal in the compiled call; anything else is refused quoting the compiled text.\n */\n private foldPublished(definition: ts.Expression, written: string, slot: ContextKeyHeaderSlot, what: string): string {\n const factory = ts.isCallExpression(definition) ? this.publishedFactoryOf(definition) : undefined;\n if (factory === undefined || !ts.isCallExpression(definition)) {\n throw this.unresolvable(written, definition.getSourceFile().fileName, what);\n }\n const argument = definition.arguments[ARGUMENT_INDEX.get(factory)!.get(slot)!];\n if (argument === undefined || this.isUndefined(argument)) {\n throw this.noHeader(written, definition, factory, slot, what);\n }\n if (!ts.isStringLiteralLike(argument) || argument.text.trim() === '') {\n throw new ApiDocExtractionError(\n `${what} '${written}': the ${slot} of its published ContextKey is not a string literal: '${argument.getText()}'`,\n SourceLocation.of(argument),\n \"Write the header name as a string literal in the key's ContextKey.trusted(...) / \" +\n 'ContextKey.untrusted(...) call in the package that defines it.',\n );\n }\n return argument.text;\n }\n\n private publishedFactoryOf(call: ts.CallExpression): string | undefined {\n const callee = call.expression;\n if (!ts.isPropertyAccessExpression(callee) || !ARGUMENT_INDEX.has(callee.name.text)) {\n return undefined;\n }\n const owner = callee.expression;\n const named =\n (ts.isIdentifier(owner) && owner.text === CONTEXT_KEY) ||\n (ts.isPropertyAccessExpression(owner) && owner.name.text === CONTEXT_KEY);\n return named ? callee.name.text : undefined;\n }\n\n private noHeader(\n written: string,\n definition: ts.Node,\n factory: string,\n slot: ContextKeyHeaderSlot,\n what: string,\n ): ApiDocExtractionError {\n return new ApiDocExtractionError(\n `${what} '${written}' is a ContextKey that declares no ${slot}`,\n SourceLocation.of(definition),\n `Give the key its ${slot} in its ContextKey.${factory}(...) definition — a key with no ` +\n 'header name never crosses the wire, so it cannot be documented as one.',\n );\n }\n\n private foldDefinition(\n definition: ts.Expression,\n written: string,\n at: ts.Node,\n slot: ContextKeyHeaderSlot,\n what: string,\n ): string {\n const factory = ts.isCallExpression(definition) ? this.factoryOf(definition) : undefined;\n if (factory === undefined || !ts.isCallExpression(definition)) {\n throw this.unresolvable(written, SourceLocation.of(at), what);\n }\n const index = ARGUMENT_INDEX.get(factory)!.get(slot)!;\n const argument = definition.arguments[index];\n if (argument === undefined || this.isUndefined(argument)) {\n throw this.noHeader(written, definition, factory, slot, what);\n }\n const header = this.folder.tryFoldString(argument);\n if (header === undefined || header.trim() === '') {\n throw new ApiDocExtractionError(\n `${what} '${written}': the ${slot} of its ContextKey is not a foldable constant: '${argument.getText()}'`,\n SourceLocation.of(argument),\n 'Write the header name as a string literal (or a `const` initialised with one) in the ' +\n \"key's ContextKey.trusted(...) / ContextKey.untrusted(...) call.\",\n );\n }\n return header;\n }\n\n private unresolvable(written: string, where: string, what: string): ApiDocExtractionError {\n return new ApiDocExtractionError(\n `cannot statically resolve ${what} '${written}' to a ContextKey.trusted(...) / ContextKey.untrusted(...) definition`,\n where,\n 'Reference a ContextKey declared as a `const`, an object property, or a class `static readonly` ' +\n 'initialised directly by ContextKey.trusted(...) or ContextKey.untrusted(...) — in source, or in ' +\n 'a published package whose compiled .js ships beside its .d.ts. A key only known at runtime ' +\n 'has no header name a document can read.',\n );\n }\n\n /** `trusted` / `untrusted` when this is `ContextKey.trusted(...)` / `ContextKey.untrusted(...)`. */\n private factoryOf(call: ts.CallExpression): string | undefined {\n const callee = call.expression;\n if (!ts.isPropertyAccessExpression(callee) || !ARGUMENT_INDEX.has(callee.name.text)) {\n return undefined;\n }\n const resolved = this.folder.symbolOf(callee.expression);\n // The resolved name covers an aliased import (`import { ContextKey as Key }`); the written\n // name covers a program that could not resolve the module at all.\n const named =\n resolved?.name === CONTEXT_KEY ||\n (ts.isIdentifier(callee.expression) && callee.expression.text === CONTEXT_KEY);\n return named ? callee.name.text : undefined;\n }\n\n private isUndefined(argument: ts.Expression): boolean {\n return ts.isIdentifier(argument) && argument.text === 'undefined';\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
export { ApiDocExtractor } from './extract/ApiDocExtractor';
|
|
12
12
|
export { SchemaNames, SchemaNameEntry } from './model/SchemaNames';
|
|
13
13
|
export { ApiDocExtractionError } from './extract/ApiDocExtractionError';
|
|
14
|
+
export { ContextKeyHeaderSlot } from './extract/ContextKeyHeaderFolder';
|
|
14
15
|
export { DeclaringPackage, PackageOfFile } from './extract/PackageOfFile';
|
|
15
16
|
export { ApiComponentsModel, ApiDocModel, DocumentedApiKey, DocumentedApiKeyCredential, DocumentedAuth, DocumentedAuthMethod, DocumentedEndpoint, DocumentedEndpointOptions, DocumentedField, DocumentedMcpTool, DocumentedType, TypeNameCollision, UnionDiscriminator, UnmappedType, } from './model/ApiDocModel';
|
|
16
17
|
export { McpRenderError } from './render/McpRenderError';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamingSchemaRenderer = exports.TypeRef = exports.SkippedMcpTool = exports.McpSchemaRenderer = exports.McpCatalogRender = exports.McpRenderError = exports.UnmappedType = exports.UnionDiscriminator = exports.TypeNameCollision = exports.DocumentedType = exports.DocumentedMcpTool = exports.DocumentedField = exports.DocumentedEndpointOptions = exports.DocumentedEndpoint = exports.DocumentedAuthMethod = exports.DocumentedAuth = exports.DocumentedApiKeyCredential = exports.DocumentedApiKey = exports.ApiDocModel = exports.ApiComponentsModel = exports.PackageOfFile = exports.DeclaringPackage = exports.ApiDocExtractionError = exports.SchemaNameEntry = exports.SchemaNames = exports.ApiDocExtractor = void 0;
|
|
3
|
+
exports.StreamingSchemaRenderer = exports.TypeRef = exports.SkippedMcpTool = exports.McpSchemaRenderer = exports.McpCatalogRender = exports.McpRenderError = exports.UnmappedType = exports.UnionDiscriminator = exports.TypeNameCollision = exports.DocumentedType = exports.DocumentedMcpTool = exports.DocumentedField = exports.DocumentedEndpointOptions = exports.DocumentedEndpoint = exports.DocumentedAuthMethod = exports.DocumentedAuth = exports.DocumentedApiKeyCredential = exports.DocumentedApiKey = exports.ApiDocModel = exports.ApiComponentsModel = exports.PackageOfFile = exports.DeclaringPackage = exports.ContextKeyHeaderSlot = exports.ApiDocExtractionError = exports.SchemaNameEntry = exports.SchemaNames = exports.ApiDocExtractor = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* `@webpieces/api-doc-model` — read a webpieces API contract with the TypeScript compiler API and
|
|
6
6
|
* produce ONE in-memory {@link ApiDocModel}.
|
|
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "SchemaNames", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "SchemaNameEntry", { enumerable: true, get: function () { return SchemaNames_1.SchemaNameEntry; } });
|
|
19
19
|
var ApiDocExtractionError_1 = require("./extract/ApiDocExtractionError");
|
|
20
20
|
Object.defineProperty(exports, "ApiDocExtractionError", { enumerable: true, get: function () { return ApiDocExtractionError_1.ApiDocExtractionError; } });
|
|
21
|
+
var ContextKeyHeaderFolder_1 = require("./extract/ContextKeyHeaderFolder");
|
|
22
|
+
Object.defineProperty(exports, "ContextKeyHeaderSlot", { enumerable: true, get: function () { return ContextKeyHeaderFolder_1.ContextKeyHeaderSlot; } });
|
|
21
23
|
var PackageOfFile_1 = require("./extract/PackageOfFile");
|
|
22
24
|
Object.defineProperty(exports, "DeclaringPackage", { enumerable: true, get: function () { return PackageOfFile_1.DeclaringPackage; } });
|
|
23
25
|
Object.defineProperty(exports, "PackageOfFile", { enumerable: true, get: function () { return PackageOfFile_1.PackageOfFile; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/api-doc-model/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,6DAA4D;AAAnD,kHAAA,eAAe,OAAA;AACxB,mDAAmE;AAA1D,0GAAA,WAAW,OAAA;AAAE,8GAAA,eAAe,OAAA;AACrC,yEAAwE;AAA/D,8HAAA,qBAAqB,OAAA;AAC9B,yDAA0E;AAAjE,iHAAA,gBAAgB,OAAA;AAAE,8GAAA,aAAa,OAAA;AACxC,mDAe6B;AAdzB,iHAAA,kBAAkB,OAAA;AAClB,0GAAA,WAAW,OAAA;AACX,+GAAA,gBAAgB,OAAA;AAChB,yHAAA,0BAA0B,OAAA;AAC1B,6GAAA,cAAc,OAAA;AACd,mHAAA,oBAAoB,OAAA;AACpB,iHAAA,kBAAkB,OAAA;AAClB,wHAAA,yBAAyB,OAAA;AACzB,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AACjB,6GAAA,cAAc,OAAA;AACd,gHAAA,iBAAiB,OAAA;AACjB,iHAAA,kBAAkB,OAAA;AAClB,2GAAA,YAAY,OAAA;AAEhB,0DAAyD;AAAhD,gHAAA,cAAc,OAAA;AACvB,gEAAiG;AAAxF,qHAAA,gBAAgB,OAAA;AAAE,sHAAA,iBAAiB,OAAA;AAAE,mHAAA,cAAc,OAAA;AAC5D,2CAA0C;AAAjC,kGAAA,OAAO,OAAA;AAEhB,4EAA2E;AAAlE,kIAAA,uBAAuB,OAAA","sourcesContent":["/**\n * `@webpieces/api-doc-model` — read a webpieces API contract with the TypeScript compiler API and\n * produce ONE in-memory {@link ApiDocModel}.\n *\n * This is the single extraction pass both the OpenAPI documents and the MCP tool list (#982) are\n * rendered from. It emits nothing itself, and it takes every decorator NAME it matches on from the\n * real `@webpieces/core-util` symbol — so renaming a decorator is a compile error here rather than a\n * literal that quietly stops matching and empties a document (issue #1001). See\n * `responsibilities.md` for why that import is not the coupling it looks like.\n */\nexport { ApiDocExtractor } from './extract/ApiDocExtractor';\nexport { SchemaNames, SchemaNameEntry } from './model/SchemaNames';\nexport { ApiDocExtractionError } from './extract/ApiDocExtractionError';\nexport { DeclaringPackage, PackageOfFile } from './extract/PackageOfFile';\nexport {\n ApiComponentsModel,\n ApiDocModel,\n DocumentedApiKey,\n DocumentedApiKeyCredential,\n DocumentedAuth,\n DocumentedAuthMethod,\n DocumentedEndpoint,\n DocumentedEndpointOptions,\n DocumentedField,\n DocumentedMcpTool,\n DocumentedType,\n TypeNameCollision,\n UnionDiscriminator,\n UnmappedType,\n} from './model/ApiDocModel';\nexport { McpRenderError } from './render/McpRenderError';\nexport { McpCatalogRender, McpSchemaRenderer, SkippedMcpTool } from './render/McpSchemaRenderer';\nexport { TypeRef } from './model/TypeRef';\nexport type { PrimitiveKind, TypeRefKind } from './model/TypeRef';\nexport { StreamingSchemaRenderer } from './render/StreamingSchemaRenderer';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/api-doc-model/src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,6DAA4D;AAAnD,kHAAA,eAAe,OAAA;AACxB,mDAAmE;AAA1D,0GAAA,WAAW,OAAA;AAAE,8GAAA,eAAe,OAAA;AACrC,yEAAwE;AAA/D,8HAAA,qBAAqB,OAAA;AAC9B,2EAAwE;AAA/D,8HAAA,oBAAoB,OAAA;AAC7B,yDAA0E;AAAjE,iHAAA,gBAAgB,OAAA;AAAE,8GAAA,aAAa,OAAA;AACxC,mDAe6B;AAdzB,iHAAA,kBAAkB,OAAA;AAClB,0GAAA,WAAW,OAAA;AACX,+GAAA,gBAAgB,OAAA;AAChB,yHAAA,0BAA0B,OAAA;AAC1B,6GAAA,cAAc,OAAA;AACd,mHAAA,oBAAoB,OAAA;AACpB,iHAAA,kBAAkB,OAAA;AAClB,wHAAA,yBAAyB,OAAA;AACzB,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AACjB,6GAAA,cAAc,OAAA;AACd,gHAAA,iBAAiB,OAAA;AACjB,iHAAA,kBAAkB,OAAA;AAClB,2GAAA,YAAY,OAAA;AAEhB,0DAAyD;AAAhD,gHAAA,cAAc,OAAA;AACvB,gEAAiG;AAAxF,qHAAA,gBAAgB,OAAA;AAAE,sHAAA,iBAAiB,OAAA;AAAE,mHAAA,cAAc,OAAA;AAC5D,2CAA0C;AAAjC,kGAAA,OAAO,OAAA;AAEhB,4EAA2E;AAAlE,kIAAA,uBAAuB,OAAA","sourcesContent":["/**\n * `@webpieces/api-doc-model` — read a webpieces API contract with the TypeScript compiler API and\n * produce ONE in-memory {@link ApiDocModel}.\n *\n * This is the single extraction pass both the OpenAPI documents and the MCP tool list (#982) are\n * rendered from. It emits nothing itself, and it takes every decorator NAME it matches on from the\n * real `@webpieces/core-util` symbol — so renaming a decorator is a compile error here rather than a\n * literal that quietly stops matching and empties a document (issue #1001). See\n * `responsibilities.md` for why that import is not the coupling it looks like.\n */\nexport { ApiDocExtractor } from './extract/ApiDocExtractor';\nexport { SchemaNames, SchemaNameEntry } from './model/SchemaNames';\nexport { ApiDocExtractionError } from './extract/ApiDocExtractionError';\nexport { ContextKeyHeaderSlot } from './extract/ContextKeyHeaderFolder';\nexport { DeclaringPackage, PackageOfFile } from './extract/PackageOfFile';\nexport {\n ApiComponentsModel,\n ApiDocModel,\n DocumentedApiKey,\n DocumentedApiKeyCredential,\n DocumentedAuth,\n DocumentedAuthMethod,\n DocumentedEndpoint,\n DocumentedEndpointOptions,\n DocumentedField,\n DocumentedMcpTool,\n DocumentedType,\n TypeNameCollision,\n UnionDiscriminator,\n UnmappedType,\n} from './model/ApiDocModel';\nexport { McpRenderError } from './render/McpRenderError';\nexport { McpCatalogRender, McpSchemaRenderer, SkippedMcpTool } from './render/McpSchemaRenderer';\nexport { TypeRef } from './model/TypeRef';\nexport type { PrimitiveKind, TypeRefKind } from './model/TypeRef';\nexport { StreamingSchemaRenderer } from './render/StreamingSchemaRenderer';\n"]}
|
|
@@ -269,26 +269,32 @@ export declare class DocumentedMcpTool {
|
|
|
269
269
|
title: string, profiles: readonly string[]);
|
|
270
270
|
}
|
|
271
271
|
/**
|
|
272
|
-
* ONE credential of an api-key regime, PARSED — `{ in: 'header',
|
|
272
|
+
* ONE credential of an api-key regime, PARSED — `{ in: 'header', key: MyKeys.API_KEY }` or
|
|
273
273
|
* `{ in: 'bearer' }`.
|
|
274
274
|
*
|
|
275
275
|
* Parsed rather than left as source text because it is the one auth argument a renderer must turn
|
|
276
276
|
* into a STRUCTURE: an OpenAPI `securityScheme` is `{type: apiKey, in, name}` or
|
|
277
277
|
* `{type: http, scheme: bearer}`, and those are different documents. A renderer handed the string
|
|
278
|
-
* `"{ in: 'header',
|
|
278
|
+
* `"{ in: 'header', key: MyKeys.API_KEY }"` would have to parse TypeScript to emit either one, which
|
|
279
279
|
* is this package's job and not a renderer's.
|
|
280
280
|
*/
|
|
281
281
|
export declare class DocumentedApiKeyCredential {
|
|
282
282
|
/** `header` or `bearer`, verbatim from the declaration. */
|
|
283
283
|
readonly location: string;
|
|
284
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* The header name, read off the `httpHeader` of the ContextKey the credential's `key` names
|
|
286
|
+
* (#1249). Undefined for `bearer`, whose location IS `Authorization`.
|
|
287
|
+
*/
|
|
285
288
|
readonly name: string | undefined;
|
|
286
289
|
/** The prose a docs site renders on its authorization card. */
|
|
287
290
|
readonly description: string | undefined;
|
|
288
291
|
constructor(
|
|
289
292
|
/** `header` or `bearer`, verbatim from the declaration. */
|
|
290
293
|
location: string,
|
|
291
|
-
/**
|
|
294
|
+
/**
|
|
295
|
+
* The header name, read off the `httpHeader` of the ContextKey the credential's `key` names
|
|
296
|
+
* (#1249). Undefined for `bearer`, whose location IS `Authorization`.
|
|
297
|
+
*/
|
|
292
298
|
name: string | undefined,
|
|
293
299
|
/** The prose a docs site renders on its authorization card. */
|
|
294
300
|
description: string | undefined);
|
package/src/model/ApiDocModel.js
CHANGED
|
@@ -253,13 +253,13 @@ class DocumentedMcpTool {
|
|
|
253
253
|
}
|
|
254
254
|
exports.DocumentedMcpTool = DocumentedMcpTool;
|
|
255
255
|
/**
|
|
256
|
-
* ONE credential of an api-key regime, PARSED — `{ in: 'header',
|
|
256
|
+
* ONE credential of an api-key regime, PARSED — `{ in: 'header', key: MyKeys.API_KEY }` or
|
|
257
257
|
* `{ in: 'bearer' }`.
|
|
258
258
|
*
|
|
259
259
|
* Parsed rather than left as source text because it is the one auth argument a renderer must turn
|
|
260
260
|
* into a STRUCTURE: an OpenAPI `securityScheme` is `{type: apiKey, in, name}` or
|
|
261
261
|
* `{type: http, scheme: bearer}`, and those are different documents. A renderer handed the string
|
|
262
|
-
* `"{ in: 'header',
|
|
262
|
+
* `"{ in: 'header', key: MyKeys.API_KEY }"` would have to parse TypeScript to emit either one, which
|
|
263
263
|
* is this package's job and not a renderer's.
|
|
264
264
|
*/
|
|
265
265
|
class DocumentedApiKeyCredential {
|
|
@@ -269,7 +269,10 @@ class DocumentedApiKeyCredential {
|
|
|
269
269
|
constructor(
|
|
270
270
|
/** `header` or `bearer`, verbatim from the declaration. */
|
|
271
271
|
location,
|
|
272
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* The header name, read off the `httpHeader` of the ContextKey the credential's `key` names
|
|
274
|
+
* (#1249). Undefined for `bearer`, whose location IS `Authorization`.
|
|
275
|
+
*/
|
|
273
276
|
name,
|
|
274
277
|
/** The prose a docs site renders on its authorization card. */
|
|
275
278
|
description) {
|