@metamask-previews/platform-api-docs 0.0.0-preview-3c77cf4 → 0.0.0-preview-5cf810ca6
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/CHANGELOG.md +1 -1
- package/README.md +1 -50
- package/dist/cli.cjs +1 -54
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +1 -54
- package/dist/cli.mjs.map +1 -1
- package/dist/extraction.cjs +44 -70
- package/dist/extraction.cjs.map +1 -1
- package/dist/extraction.d.cts +1 -57
- package/dist/extraction.d.cts.map +1 -1
- package/dist/extraction.d.mts +1 -57
- package/dist/extraction.d.mts.map +1 -1
- package/dist/extraction.mjs +44 -68
- package/dist/extraction.mjs.map +1 -1
- package/dist/generate.cjs +6 -72
- package/dist/generate.cjs.map +1 -1
- package/dist/generate.d.cts +3 -28
- package/dist/generate.d.cts.map +1 -1
- package/dist/generate.d.mts +3 -28
- package/dist/generate.d.mts.map +1 -1
- package/dist/generate.mjs +6 -72
- package/dist/generate.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/root-messenger-discovery.cjs +0 -234
- package/dist/root-messenger-discovery.cjs.map +0 -1
- package/dist/root-messenger-discovery.d.cts +0 -58
- package/dist/root-messenger-discovery.d.cts.map +0 -1
- package/dist/root-messenger-discovery.d.mts +0 -58
- package/dist/root-messenger-discovery.d.mts.map +0 -1
- package/dist/root-messenger-discovery.mjs +0 -206
- package/dist/root-messenger-discovery.mjs.map +0 -1
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { MessengerCapabilityPacket } from "./types.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* A reference to a type in a file, written as `<file>#<TypeName>`.
|
|
4
|
-
*/
|
|
5
|
-
export type RootTypeReference = {
|
|
6
|
-
/** Path to the declaring file, relative to the project root. */
|
|
7
|
-
filePath: string;
|
|
8
|
-
/** Name of the type alias within that file. */
|
|
9
|
-
typeName: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Options for {@link discoverFromRootMessenger}.
|
|
13
|
-
*/
|
|
14
|
-
type RootMessengerDiscoveryOptions = {
|
|
15
|
-
/** Absolute path to the project to scan. */
|
|
16
|
-
projectPath: string;
|
|
17
|
-
/** Type aliasing the union of every action on the root messenger. */
|
|
18
|
-
actions: RootTypeReference;
|
|
19
|
-
/** Type aliasing the union of every event on the root messenger. */
|
|
20
|
-
events: RootTypeReference;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Labels for capability types that were found but couldn't be documented,
|
|
24
|
-
* grouped by why. Labels rather than counts, so warnings can name what to fix.
|
|
25
|
-
*/
|
|
26
|
-
type SkippedCapabilities = {
|
|
27
|
-
/** Declared inline in the union, so there is no name or JSDoc to document. */
|
|
28
|
-
unnamed: string[];
|
|
29
|
-
/** Named, but of a shape the extractor rejects. */
|
|
30
|
-
unextractable: string[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* The result of {@link discoverFromRootMessenger}.
|
|
34
|
-
*/
|
|
35
|
-
type RootMessengerDiscoveryResult = {
|
|
36
|
-
/** Every capability extracted, actions before events. */
|
|
37
|
-
packets: MessengerCapabilityPacket[];
|
|
38
|
-
/** Capabilities that couldn't be documented. */
|
|
39
|
-
skipped: SkippedCapabilities;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Split a `<file>#<TypeName>` reference into its parts, on the last `#` so
|
|
43
|
-
* that paths containing a `#` still work.
|
|
44
|
-
*
|
|
45
|
-
* @param reference - The raw reference, e.g. `src/messenger.ts#RootActions`.
|
|
46
|
-
* @returns The parsed reference.
|
|
47
|
-
* @throws If the reference has no `#`, or either side of it is empty.
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseRootTypeReference(reference: string): RootTypeReference;
|
|
50
|
-
/**
|
|
51
|
-
* Enumerate every action and event reachable from a project's root messenger.
|
|
52
|
-
*
|
|
53
|
-
* @param options - Discovery options.
|
|
54
|
-
* @returns The extracted capabilities plus anything skipped.
|
|
55
|
-
*/
|
|
56
|
-
export declare function discoverFromRootMessenger(options: RootMessengerDiscoveryOptions): RootMessengerDiscoveryResult;
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=root-messenger-discovery.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-messenger-discovery.d.cts","sourceRoot":"","sources":["../src/root-messenger-discovery.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,oBAAmB;AAW5D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,KAAK,6BAA6B,GAAG;IACnC,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,oEAAoE;IACpE,MAAM,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,KAAK,mBAAmB,GAAG;IACzB,8EAA8E;IAC9E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mDAAmD;IACnD,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,yDAAyD;IACzD,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACrC,gDAAgD;IAChD,OAAO,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAiB3E;AAqOD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,6BAA6B,GACrC,4BAA4B,CA6B9B"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { MessengerCapabilityPacket } from "./types.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* A reference to a type in a file, written as `<file>#<TypeName>`.
|
|
4
|
-
*/
|
|
5
|
-
export type RootTypeReference = {
|
|
6
|
-
/** Path to the declaring file, relative to the project root. */
|
|
7
|
-
filePath: string;
|
|
8
|
-
/** Name of the type alias within that file. */
|
|
9
|
-
typeName: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Options for {@link discoverFromRootMessenger}.
|
|
13
|
-
*/
|
|
14
|
-
type RootMessengerDiscoveryOptions = {
|
|
15
|
-
/** Absolute path to the project to scan. */
|
|
16
|
-
projectPath: string;
|
|
17
|
-
/** Type aliasing the union of every action on the root messenger. */
|
|
18
|
-
actions: RootTypeReference;
|
|
19
|
-
/** Type aliasing the union of every event on the root messenger. */
|
|
20
|
-
events: RootTypeReference;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Labels for capability types that were found but couldn't be documented,
|
|
24
|
-
* grouped by why. Labels rather than counts, so warnings can name what to fix.
|
|
25
|
-
*/
|
|
26
|
-
type SkippedCapabilities = {
|
|
27
|
-
/** Declared inline in the union, so there is no name or JSDoc to document. */
|
|
28
|
-
unnamed: string[];
|
|
29
|
-
/** Named, but of a shape the extractor rejects. */
|
|
30
|
-
unextractable: string[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* The result of {@link discoverFromRootMessenger}.
|
|
34
|
-
*/
|
|
35
|
-
type RootMessengerDiscoveryResult = {
|
|
36
|
-
/** Every capability extracted, actions before events. */
|
|
37
|
-
packets: MessengerCapabilityPacket[];
|
|
38
|
-
/** Capabilities that couldn't be documented. */
|
|
39
|
-
skipped: SkippedCapabilities;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Split a `<file>#<TypeName>` reference into its parts, on the last `#` so
|
|
43
|
-
* that paths containing a `#` still work.
|
|
44
|
-
*
|
|
45
|
-
* @param reference - The raw reference, e.g. `src/messenger.ts#RootActions`.
|
|
46
|
-
* @returns The parsed reference.
|
|
47
|
-
* @throws If the reference has no `#`, or either side of it is empty.
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseRootTypeReference(reference: string): RootTypeReference;
|
|
50
|
-
/**
|
|
51
|
-
* Enumerate every action and event reachable from a project's root messenger.
|
|
52
|
-
*
|
|
53
|
-
* @param options - Discovery options.
|
|
54
|
-
* @returns The extracted capabilities plus anything skipped.
|
|
55
|
-
*/
|
|
56
|
-
export declare function discoverFromRootMessenger(options: RootMessengerDiscoveryOptions): RootMessengerDiscoveryResult;
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=root-messenger-discovery.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-messenger-discovery.d.mts","sourceRoot":"","sources":["../src/root-messenger-discovery.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,oBAAmB;AAW5D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,KAAK,6BAA6B,GAAG;IACnC,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,oEAAoE;IACpE,MAAM,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,KAAK,mBAAmB,GAAG;IACzB,8EAA8E;IAC9E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mDAAmD;IACnD,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,yDAAyD;IACzD,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACrC,gDAAgD;IAChD,OAAO,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAiB3E;AAqOD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,6BAA6B,GACrC,4BAA4B,CA6B9B"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { Node as NodeGuards, Project, ts } from "ts-morph";
|
|
3
|
-
import { classifyMessengerCapabilityTypeDeclaration, extractFromMessengerCapabilityTypeDeclaration } from "./extraction.mjs";
|
|
4
|
-
/**
|
|
5
|
-
* Split a `<file>#<TypeName>` reference into its parts, on the last `#` so
|
|
6
|
-
* that paths containing a `#` still work.
|
|
7
|
-
*
|
|
8
|
-
* @param reference - The raw reference, e.g. `src/messenger.ts#RootActions`.
|
|
9
|
-
* @returns The parsed reference.
|
|
10
|
-
* @throws If the reference has no `#`, or either side of it is empty.
|
|
11
|
-
*/
|
|
12
|
-
export function parseRootTypeReference(reference) {
|
|
13
|
-
const separatorIndex = reference.lastIndexOf('#');
|
|
14
|
-
if (separatorIndex === -1) {
|
|
15
|
-
throw new Error(`Expected a reference of the form "<file>#<TypeName>", got "${reference}".`);
|
|
16
|
-
}
|
|
17
|
-
const filePath = reference.slice(0, separatorIndex);
|
|
18
|
-
const typeName = reference.slice(separatorIndex + 1);
|
|
19
|
-
if (filePath.length === 0 || typeName.length === 0) {
|
|
20
|
-
throw new Error(`Expected a reference of the form "<file>#<TypeName>", got "${reference}".`);
|
|
21
|
-
}
|
|
22
|
-
return { filePath, typeName };
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Create a ts-morph Project for resolving root messenger types.
|
|
26
|
-
*
|
|
27
|
-
* No file list is loaded: this strategy opens only the entry files and lets
|
|
28
|
-
* the checker pull in the rest.
|
|
29
|
-
*
|
|
30
|
-
* @returns A new ts-morph Project.
|
|
31
|
-
*/
|
|
32
|
-
function createRootMessengerProject() {
|
|
33
|
-
return new Project({
|
|
34
|
-
compilerOptions: {
|
|
35
|
-
noEmit: true,
|
|
36
|
-
// We need symbol resolution, not full typechecking, so a project's own
|
|
37
|
-
// strictness settings shouldn't be able to fail the docs build.
|
|
38
|
-
strict: false,
|
|
39
|
-
skipLibCheck: true,
|
|
40
|
-
target: ts.ScriptTarget.ESNext,
|
|
41
|
-
module: ts.ModuleKind.ESNext,
|
|
42
|
-
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Resolve the type alias a reference names.
|
|
48
|
-
*
|
|
49
|
-
* @param project - The ts-morph project to load the file into.
|
|
50
|
-
* @param projectPath - Absolute path to the project root.
|
|
51
|
-
* @param reference - The reference to resolve.
|
|
52
|
-
* @param flagName - The CLI flag the reference came from, used in errors.
|
|
53
|
-
* @returns The type alias declaration.
|
|
54
|
-
* @throws If the file can't be read or declares no such type alias.
|
|
55
|
-
*/
|
|
56
|
-
function resolveRootDeclaration(project, projectPath, reference, flagName) {
|
|
57
|
-
const absolutePath = path.resolve(projectPath, reference.filePath);
|
|
58
|
-
let sourceFile;
|
|
59
|
-
try {
|
|
60
|
-
sourceFile =
|
|
61
|
-
project.getSourceFile(absolutePath) ??
|
|
62
|
-
project.addSourceFileAtPath(absolutePath);
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
throw new Error(`Could not read ${absolutePath}, which was named by ${flagName}.`);
|
|
66
|
-
}
|
|
67
|
-
const declaration = sourceFile.getTypeAlias(reference.typeName);
|
|
68
|
-
if (!declaration) {
|
|
69
|
-
throw new Error(`No type alias named "${reference.typeName}" in ${reference.filePath}, which was named by ${flagName}.`);
|
|
70
|
-
}
|
|
71
|
-
return declaration;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Find the named declaration behind a union constituent.
|
|
75
|
-
*
|
|
76
|
-
* @param constituent - The resolved constituent type.
|
|
77
|
-
* @param rootDeclaration - The root union's own declaration.
|
|
78
|
-
* @param isLoneConstituent - Whether this is the root's only constituent.
|
|
79
|
-
* @returns The declaration, or undefined when the constituent is anonymous.
|
|
80
|
-
*/
|
|
81
|
-
function findCapabilityDeclaration(constituent, rootDeclaration, isLoneConstituent) {
|
|
82
|
-
// Prefer the alias symbol: for a type alias it carries the name and JSDoc,
|
|
83
|
-
// where the plain symbol points at the anonymous object type. Skip an alias
|
|
84
|
-
// resolving back to the root union itself, which is what the checker reports
|
|
85
|
-
// for a lone generic instantiation such as `type Actions = Foo<Bar>`.
|
|
86
|
-
const aliasDeclarations = (constituent.getAliasSymbol()?.getDeclarations() ?? []).filter((node) => node !== rootDeclaration);
|
|
87
|
-
// An interface has no alias symbol, being its own declaration.
|
|
88
|
-
const declarations = aliasDeclarations.length > 0
|
|
89
|
-
? aliasDeclarations
|
|
90
|
-
: (constituent.getSymbol()?.getDeclarations() ?? []);
|
|
91
|
-
const found = declarations.find((node) => NodeGuards.isTypeAliasDeclaration(node) ||
|
|
92
|
-
NodeGuards.isInterfaceDeclaration(node));
|
|
93
|
-
if (found) {
|
|
94
|
-
return found;
|
|
95
|
-
}
|
|
96
|
-
// Nothing named behind the type itself. When the root aliases a single
|
|
97
|
-
// generic instantiation, the declaration we want is the one its type node
|
|
98
|
-
// references — `Foo` in `type Actions = Foo<Bar>`. Only when it is the lone
|
|
99
|
-
// constituent, though: in a union, an anonymous member is genuinely
|
|
100
|
-
// anonymous, and attributing it to the wrapper would mislabel it.
|
|
101
|
-
return isLoneConstituent
|
|
102
|
-
? findDeclarationFromRootTypeNode(rootDeclaration)
|
|
103
|
-
: undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Resolve the declaration referenced by a root alias's type node.
|
|
107
|
-
*
|
|
108
|
-
* @param rootDeclaration - The root union's own declaration.
|
|
109
|
-
* @returns The referenced declaration, or undefined.
|
|
110
|
-
*/
|
|
111
|
-
function findDeclarationFromRootTypeNode(rootDeclaration) {
|
|
112
|
-
const typeNode = rootDeclaration.getTypeNode();
|
|
113
|
-
if (!typeNode || !NodeGuards.isTypeReference(typeNode)) {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
const localSymbol = typeNode.getTypeName().getSymbol();
|
|
117
|
-
const symbol = localSymbol?.getAliasedSymbol() ?? localSymbol;
|
|
118
|
-
return symbol
|
|
119
|
-
?.getDeclarations()
|
|
120
|
-
.find((node) => NodeGuards.isTypeAliasDeclaration(node) ||
|
|
121
|
-
NodeGuards.isInterfaceDeclaration(node));
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Render a short, single-line label for an anonymous type.
|
|
125
|
-
*
|
|
126
|
-
* @param type - The type to describe.
|
|
127
|
-
* @param enclosingNode - Node to render the type relative to, so an aliased
|
|
128
|
-
* type reads as its name rather than `import("<absolute path>").Name`.
|
|
129
|
-
* @returns The label.
|
|
130
|
-
*/
|
|
131
|
-
function summarizeType(type, enclosingNode) {
|
|
132
|
-
const text = type.getText(enclosingNode).replace(/\s+/gu, ' ');
|
|
133
|
-
return text.length > 80 ? `${text.slice(0, 77)}...` : text;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Extract every documentable capability from one root union.
|
|
137
|
-
*
|
|
138
|
-
* @param rootDeclaration - The root union's declaration.
|
|
139
|
-
* @param kind - Whether these are actions or events.
|
|
140
|
-
* @param projectPath - Absolute path to the project root.
|
|
141
|
-
* @param skipped - Labels collected as undocumentable constituents are found.
|
|
142
|
-
* @param reference - The reference that named this type, used in errors.
|
|
143
|
-
* @param flagName - The CLI flag the reference came from, used in errors.
|
|
144
|
-
* @returns The extracted capabilities.
|
|
145
|
-
* @throws If the union resolved to `any` or `unknown`.
|
|
146
|
-
*/
|
|
147
|
-
function extractFromRootType(rootDeclaration, kind, projectPath, skipped, reference, flagName) {
|
|
148
|
-
const rootType = rootDeclaration.getTypeNodeOrThrow().getType();
|
|
149
|
-
// TypeScript absorbs `any | T` into `any` and `unknown | T` into `unknown`,
|
|
150
|
-
// so a single member the checker can't resolve — typically a failed import —
|
|
151
|
-
// erases every other capability in the union. Fail instead of emitting a
|
|
152
|
-
// catalog that looks complete but silently isn't.
|
|
153
|
-
if (rootType.isAny() || rootType.isUnknown()) {
|
|
154
|
-
throw new Error(`${reference.filePath}#${reference.typeName}, named by ${flagName}, ` +
|
|
155
|
-
`resolved to \`${rootType.getText()}\` rather than a union of ` +
|
|
156
|
-
`capabilities. This usually means an import in that file could not be ` +
|
|
157
|
-
`resolved; because TypeScript absorbs the rest of a union into ` +
|
|
158
|
-
`\`any\`, every other capability in it would be missing.`);
|
|
159
|
-
}
|
|
160
|
-
// A project with no capabilities of this kind aliases the union to `never`.
|
|
161
|
-
if (rootType.isNever()) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
const constituents = rootType.isUnion()
|
|
165
|
-
? rootType.getUnionTypes()
|
|
166
|
-
: [rootType];
|
|
167
|
-
const packets = [];
|
|
168
|
-
for (const constituent of constituents) {
|
|
169
|
-
const declaration = findCapabilityDeclaration(constituent, rootDeclaration, constituents.length === 1);
|
|
170
|
-
if (!declaration) {
|
|
171
|
-
skipped.unnamed.push(summarizeType(constituent, rootDeclaration));
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
const classified = classifyMessengerCapabilityTypeDeclaration(declaration, kind);
|
|
175
|
-
const packet = classified &&
|
|
176
|
-
extractFromMessengerCapabilityTypeDeclaration(classified, projectPath);
|
|
177
|
-
if (!packet) {
|
|
178
|
-
const sourceFile = declaration.getSourceFile().getFilePath();
|
|
179
|
-
skipped.unextractable.push(`${declaration.getName()} (${path.relative(projectPath, sourceFile)}:${declaration.getStartLineNumber()})`);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
packets.push(packet);
|
|
183
|
-
}
|
|
184
|
-
return packets;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Enumerate every action and event reachable from a project's root messenger.
|
|
188
|
-
*
|
|
189
|
-
* @param options - Discovery options.
|
|
190
|
-
* @returns The extracted capabilities plus anything skipped.
|
|
191
|
-
*/
|
|
192
|
-
export function discoverFromRootMessenger(options) {
|
|
193
|
-
const { projectPath, actions, events } = options;
|
|
194
|
-
const project = createRootMessengerProject();
|
|
195
|
-
const skipped = { unnamed: [], unextractable: [] };
|
|
196
|
-
const packets = [];
|
|
197
|
-
for (const [reference, kind, flagName] of [
|
|
198
|
-
[actions, 'action', '--root-actions'],
|
|
199
|
-
[events, 'event', '--root-events'],
|
|
200
|
-
]) {
|
|
201
|
-
const rootDeclaration = resolveRootDeclaration(project, projectPath, reference, flagName);
|
|
202
|
-
packets.push(...extractFromRootType(rootDeclaration, kind, projectPath, skipped, reference, flagName));
|
|
203
|
-
}
|
|
204
|
-
return { packets, skipped };
|
|
205
|
-
}
|
|
206
|
-
//# sourceMappingURL=root-messenger-discovery.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-messenger-discovery.mjs","sourceRoot":"","sources":["../src/root-messenger-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,kBAAkB;AAOlC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,iBAAiB;AAE3D,OAAO,EACL,0CAA0C,EAC1C,6CAA6C,EAC9C,yBAAwB;AAuDzB;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAiB;IACtD,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,8DAA8D,SAAS,IAAI,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IACrD,IAAI,QAAQ,CAAC,MAAM,KAAK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ACjD,MAAM,OAAO,GAAG,0BAA0B,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAwB,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;IACxE,MAAM,OAAO,GAAgC,EAAE,CAAC;IAEhD,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI;QACxC,CAAC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,CAAC;QACrC,CAAC,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC;KAC1B,EAAE,CAAC;QACX,MAAM,eAAe,GAAG,sBAAsB,CAC5C,OAAO,EACP,WAAW,EACX,SAAS,EACT,QAAQ,CACT,CAAC;QACF,OAAO,CAAC,IAAI,CACV,GAAG,mBAAmB,CACpB,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,CACT,CACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import * as path from 'node:path';\nimport type {\n InterfaceDeclaration,\n Project as TsMorphProject,\n Type,\n TypeAliasDeclaration,\n} from 'ts-morph';\nimport { Node as NodeGuards, Project, ts } from 'ts-morph';\n\nimport {\n classifyMessengerCapabilityTypeDeclaration,\n extractFromMessengerCapabilityTypeDeclaration,\n} from './extraction.js';\nimport type { MessengerCapabilityPacket } from './types.js';\n\n// ---------------------------------------------------------------------------\n// The `root-messenger` strategy: resolve the unions a project declares for its\n// root messenger and let the type checker enumerate them. Going through the\n// checker rather than the AST means a union works whether it is written by\n// hand or computed (e.g. derived from a registry via `ReturnType<...>`). Each\n// capability it reports is handed to the shared extractor in `extraction.ts`,\n// so the output matches what the `scan` strategy produces.\n// ---------------------------------------------------------------------------\n\n/**\n * A reference to a type in a file, written as `<file>#<TypeName>`.\n */\nexport type RootTypeReference = {\n /** Path to the declaring file, relative to the project root. */\n filePath: string;\n /** Name of the type alias within that file. */\n typeName: string;\n};\n\n/**\n * Options for {@link discoverFromRootMessenger}.\n */\ntype RootMessengerDiscoveryOptions = {\n /** Absolute path to the project to scan. */\n projectPath: string;\n /** Type aliasing the union of every action on the root messenger. */\n actions: RootTypeReference;\n /** Type aliasing the union of every event on the root messenger. */\n events: RootTypeReference;\n};\n\n/**\n * Labels for capability types that were found but couldn't be documented,\n * grouped by why. Labels rather than counts, so warnings can name what to fix.\n */\ntype SkippedCapabilities = {\n /** Declared inline in the union, so there is no name or JSDoc to document. */\n unnamed: string[];\n /** Named, but of a shape the extractor rejects. */\n unextractable: string[];\n};\n\n/**\n * The result of {@link discoverFromRootMessenger}.\n */\ntype RootMessengerDiscoveryResult = {\n /** Every capability extracted, actions before events. */\n packets: MessengerCapabilityPacket[];\n /** Capabilities that couldn't be documented. */\n skipped: SkippedCapabilities;\n};\n\n/**\n * Split a `<file>#<TypeName>` reference into its parts, on the last `#` so\n * that paths containing a `#` still work.\n *\n * @param reference - The raw reference, e.g. `src/messenger.ts#RootActions`.\n * @returns The parsed reference.\n * @throws If the reference has no `#`, or either side of it is empty.\n */\nexport function parseRootTypeReference(reference: string): RootTypeReference {\n const separatorIndex = reference.lastIndexOf('#');\n if (separatorIndex === -1) {\n throw new Error(\n `Expected a reference of the form \"<file>#<TypeName>\", got \"${reference}\".`,\n );\n }\n\n const filePath = reference.slice(0, separatorIndex);\n const typeName = reference.slice(separatorIndex + 1);\n if (filePath.length === 0 || typeName.length === 0) {\n throw new Error(\n `Expected a reference of the form \"<file>#<TypeName>\", got \"${reference}\".`,\n );\n }\n\n return { filePath, typeName };\n}\n\n/**\n * Create a ts-morph Project for resolving root messenger types.\n *\n * No file list is loaded: this strategy opens only the entry files and lets\n * the checker pull in the rest.\n *\n * @returns A new ts-morph Project.\n */\nfunction createRootMessengerProject(): TsMorphProject {\n return new Project({\n compilerOptions: {\n noEmit: true,\n // We need symbol resolution, not full typechecking, so a project's own\n // strictness settings shouldn't be able to fail the docs build.\n strict: false,\n skipLibCheck: true,\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeJs,\n },\n });\n}\n\n/**\n * Resolve the type alias a reference names.\n *\n * @param project - The ts-morph project to load the file into.\n * @param projectPath - Absolute path to the project root.\n * @param reference - The reference to resolve.\n * @param flagName - The CLI flag the reference came from, used in errors.\n * @returns The type alias declaration.\n * @throws If the file can't be read or declares no such type alias.\n */\nfunction resolveRootDeclaration(\n project: TsMorphProject,\n projectPath: string,\n reference: RootTypeReference,\n flagName: string,\n): TypeAliasDeclaration {\n const absolutePath = path.resolve(projectPath, reference.filePath);\n\n let sourceFile;\n try {\n sourceFile =\n project.getSourceFile(absolutePath) ??\n project.addSourceFileAtPath(absolutePath);\n } catch {\n throw new Error(\n `Could not read ${absolutePath}, which was named by ${flagName}.`,\n );\n }\n\n const declaration = sourceFile.getTypeAlias(reference.typeName);\n if (!declaration) {\n throw new Error(\n `No type alias named \"${reference.typeName}\" in ${reference.filePath}, which was named by ${flagName}.`,\n );\n }\n\n return declaration;\n}\n\n/**\n * Find the named declaration behind a union constituent.\n *\n * @param constituent - The resolved constituent type.\n * @param rootDeclaration - The root union's own declaration.\n * @param isLoneConstituent - Whether this is the root's only constituent.\n * @returns The declaration, or undefined when the constituent is anonymous.\n */\nfunction findCapabilityDeclaration(\n constituent: Type,\n rootDeclaration: TypeAliasDeclaration,\n isLoneConstituent: boolean,\n): TypeAliasDeclaration | InterfaceDeclaration | undefined {\n // Prefer the alias symbol: for a type alias it carries the name and JSDoc,\n // where the plain symbol points at the anonymous object type. Skip an alias\n // resolving back to the root union itself, which is what the checker reports\n // for a lone generic instantiation such as `type Actions = Foo<Bar>`.\n const aliasDeclarations = (\n constituent.getAliasSymbol()?.getDeclarations() ?? []\n ).filter((node) => node !== rootDeclaration);\n\n // An interface has no alias symbol, being its own declaration.\n const declarations =\n aliasDeclarations.length > 0\n ? aliasDeclarations\n : (constituent.getSymbol()?.getDeclarations() ?? []);\n\n const found = declarations.find(\n (node): node is TypeAliasDeclaration | InterfaceDeclaration =>\n NodeGuards.isTypeAliasDeclaration(node) ||\n NodeGuards.isInterfaceDeclaration(node),\n );\n if (found) {\n return found;\n }\n\n // Nothing named behind the type itself. When the root aliases a single\n // generic instantiation, the declaration we want is the one its type node\n // references — `Foo` in `type Actions = Foo<Bar>`. Only when it is the lone\n // constituent, though: in a union, an anonymous member is genuinely\n // anonymous, and attributing it to the wrapper would mislabel it.\n return isLoneConstituent\n ? findDeclarationFromRootTypeNode(rootDeclaration)\n : undefined;\n}\n\n/**\n * Resolve the declaration referenced by a root alias's type node.\n *\n * @param rootDeclaration - The root union's own declaration.\n * @returns The referenced declaration, or undefined.\n */\nfunction findDeclarationFromRootTypeNode(\n rootDeclaration: TypeAliasDeclaration,\n): TypeAliasDeclaration | InterfaceDeclaration | undefined {\n const typeNode = rootDeclaration.getTypeNode();\n if (!typeNode || !NodeGuards.isTypeReference(typeNode)) {\n return undefined;\n }\n\n const localSymbol = typeNode.getTypeName().getSymbol();\n const symbol = localSymbol?.getAliasedSymbol() ?? localSymbol;\n return symbol\n ?.getDeclarations()\n .find(\n (node): node is TypeAliasDeclaration | InterfaceDeclaration =>\n NodeGuards.isTypeAliasDeclaration(node) ||\n NodeGuards.isInterfaceDeclaration(node),\n );\n}\n\n/**\n * Render a short, single-line label for an anonymous type.\n *\n * @param type - The type to describe.\n * @param enclosingNode - Node to render the type relative to, so an aliased\n * type reads as its name rather than `import(\"<absolute path>\").Name`.\n * @returns The label.\n */\nfunction summarizeType(\n type: Type,\n enclosingNode: TypeAliasDeclaration,\n): string {\n const text = type.getText(enclosingNode).replace(/\\s+/gu, ' ');\n return text.length > 80 ? `${text.slice(0, 77)}...` : text;\n}\n\n/**\n * Extract every documentable capability from one root union.\n *\n * @param rootDeclaration - The root union's declaration.\n * @param kind - Whether these are actions or events.\n * @param projectPath - Absolute path to the project root.\n * @param skipped - Labels collected as undocumentable constituents are found.\n * @param reference - The reference that named this type, used in errors.\n * @param flagName - The CLI flag the reference came from, used in errors.\n * @returns The extracted capabilities.\n * @throws If the union resolved to `any` or `unknown`.\n */\nfunction extractFromRootType(\n rootDeclaration: TypeAliasDeclaration,\n kind: 'action' | 'event',\n projectPath: string,\n skipped: SkippedCapabilities,\n reference: RootTypeReference,\n flagName: string,\n): MessengerCapabilityPacket[] {\n const rootType = rootDeclaration.getTypeNodeOrThrow().getType();\n\n // TypeScript absorbs `any | T` into `any` and `unknown | T` into `unknown`,\n // so a single member the checker can't resolve — typically a failed import —\n // erases every other capability in the union. Fail instead of emitting a\n // catalog that looks complete but silently isn't.\n if (rootType.isAny() || rootType.isUnknown()) {\n throw new Error(\n `${reference.filePath}#${reference.typeName}, named by ${flagName}, ` +\n `resolved to \\`${rootType.getText()}\\` rather than a union of ` +\n `capabilities. This usually means an import in that file could not be ` +\n `resolved; because TypeScript absorbs the rest of a union into ` +\n `\\`any\\`, every other capability in it would be missing.`,\n );\n }\n\n // A project with no capabilities of this kind aliases the union to `never`.\n if (rootType.isNever()) {\n return [];\n }\n\n const constituents = rootType.isUnion()\n ? rootType.getUnionTypes()\n : [rootType];\n const packets: MessengerCapabilityPacket[] = [];\n\n for (const constituent of constituents) {\n const declaration = findCapabilityDeclaration(\n constituent,\n rootDeclaration,\n constituents.length === 1,\n );\n if (!declaration) {\n skipped.unnamed.push(summarizeType(constituent, rootDeclaration));\n continue;\n }\n\n const classified = classifyMessengerCapabilityTypeDeclaration(\n declaration,\n kind,\n );\n const packet =\n classified &&\n extractFromMessengerCapabilityTypeDeclaration(classified, projectPath);\n if (!packet) {\n const sourceFile = declaration.getSourceFile().getFilePath();\n skipped.unextractable.push(\n `${declaration.getName()} (${path.relative(projectPath, sourceFile)}:${declaration.getStartLineNumber()})`,\n );\n continue;\n }\n\n packets.push(packet);\n }\n\n return packets;\n}\n\n/**\n * Enumerate every action and event reachable from a project's root messenger.\n *\n * @param options - Discovery options.\n * @returns The extracted capabilities plus anything skipped.\n */\nexport function discoverFromRootMessenger(\n options: RootMessengerDiscoveryOptions,\n): RootMessengerDiscoveryResult {\n const { projectPath, actions, events } = options;\n const project = createRootMessengerProject();\n const skipped: SkippedCapabilities = { unnamed: [], unextractable: [] };\n const packets: MessengerCapabilityPacket[] = [];\n\n for (const [reference, kind, flagName] of [\n [actions, 'action', '--root-actions'],\n [events, 'event', '--root-events'],\n ] as const) {\n const rootDeclaration = resolveRootDeclaration(\n project,\n projectPath,\n reference,\n flagName,\n );\n packets.push(\n ...extractFromRootType(\n rootDeclaration,\n kind,\n projectPath,\n skipped,\n reference,\n flagName,\n ),\n );\n }\n\n return { packets, skipped };\n}\n"]}
|