@metamask-previews/messenger-cli 0.0.0-preview-e024252b6 → 0.1.0-preview-8f51c7a3a

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/docs/cli.cjs +199 -0
  5. package/dist/docs/cli.cjs.map +1 -0
  6. package/dist/docs/cli.d.cts +3 -0
  7. package/dist/docs/cli.d.cts.map +1 -0
  8. package/dist/docs/cli.d.mts +3 -0
  9. package/dist/docs/cli.d.mts.map +1 -0
  10. package/dist/docs/cli.mjs +198 -0
  11. package/dist/docs/cli.mjs.map +1 -0
  12. package/dist/docs/discovery.cjs +46 -0
  13. package/dist/docs/discovery.cjs.map +1 -0
  14. package/dist/docs/discovery.d.cts +17 -0
  15. package/dist/docs/discovery.d.cts.map +1 -0
  16. package/dist/docs/discovery.d.mts +17 -0
  17. package/dist/docs/discovery.d.mts.map +1 -0
  18. package/dist/docs/discovery.mjs +41 -0
  19. package/dist/docs/discovery.mjs.map +1 -0
  20. package/dist/docs/extraction.cjs +577 -0
  21. package/dist/docs/extraction.cjs.map +1 -0
  22. package/dist/docs/extraction.d.cts +10 -0
  23. package/dist/docs/extraction.d.cts.map +1 -0
  24. package/dist/docs/extraction.d.mts +10 -0
  25. package/dist/docs/extraction.d.mts.map +1 -0
  26. package/dist/docs/extraction.mjs +551 -0
  27. package/dist/docs/extraction.mjs.map +1 -0
  28. package/dist/docs/generate.cjs +254 -0
  29. package/dist/docs/generate.cjs.map +1 -0
  30. package/dist/docs/generate.d.cts +27 -0
  31. package/dist/docs/generate.d.cts.map +1 -0
  32. package/dist/docs/generate.d.mts +27 -0
  33. package/dist/docs/generate.d.mts.map +1 -0
  34. package/dist/docs/generate.mjs +227 -0
  35. package/dist/docs/generate.mjs.map +1 -0
  36. package/dist/docs/markdown.cjs +210 -0
  37. package/dist/docs/markdown.cjs.map +1 -0
  38. package/dist/docs/markdown.d.cts +35 -0
  39. package/dist/docs/markdown.d.cts.map +1 -0
  40. package/dist/docs/markdown.d.mts +35 -0
  41. package/dist/docs/markdown.d.mts.map +1 -0
  42. package/dist/docs/markdown.mjs +203 -0
  43. package/dist/docs/markdown.mjs.map +1 -0
  44. package/dist/docs/types.cjs +3 -0
  45. package/dist/docs/types.cjs.map +1 -0
  46. package/dist/docs/types.d.cts +23 -0
  47. package/dist/docs/types.d.cts.map +1 -0
  48. package/dist/docs/types.d.mts +23 -0
  49. package/dist/docs/types.d.mts.map +1 -0
  50. package/dist/docs/types.mjs +2 -0
  51. package/dist/docs/types.mjs.map +1 -0
  52. package/package.json +24 -4
  53. package/template/docusaurus.config.ts +123 -0
  54. package/template/src/css/custom.css +314 -0
  55. package/template/static/fonts/MM-Sans/MM_Sans_Mono-Regular.woff2 +0 -0
  56. package/template/static/img/favicons/favicon-96x96.png +0 -0
  57. package/template/static/img/metamask-fox.svg +12 -0
  58. package/template/static/img/metamask-logo-dark.svg +3 -0
  59. package/template/static/img/metamask-logo.svg +3 -0
  60. package/template/tsconfig.json +13 -0
@@ -0,0 +1,41 @@
1
+ import { glob } from "glob";
2
+ /**
3
+ * Find all non-test TypeScript source files in a directory.
4
+ * Skips node_modules, dist, test directories, and declaration files.
5
+ *
6
+ * @param dir - The directory to search.
7
+ * @returns A promise that resolves to an array of absolute file paths.
8
+ */
9
+ export async function findTsFiles(dir) {
10
+ return await glob('**/*.ts', {
11
+ cwd: dir,
12
+ absolute: true,
13
+ ignore: [
14
+ '**/node_modules/**',
15
+ '**/dist/**',
16
+ '**/__tests__/**',
17
+ '**/tests/**',
18
+ '**/test/**',
19
+ '**/__mocks__/**',
20
+ '**/*.test.ts',
21
+ '**/*.test-d.ts',
22
+ '**/*.spec.ts',
23
+ '**/*.d.ts',
24
+ ],
25
+ });
26
+ }
27
+ /**
28
+ * Find all `.d.cts` declaration files in a directory.
29
+ * Skips nested node_modules subdirectories.
30
+ *
31
+ * @param dir - The directory to search.
32
+ * @returns A promise that resolves to an array of absolute file paths.
33
+ */
34
+ export async function findDtsFiles(dir) {
35
+ return await glob('**/*.d.cts', {
36
+ cwd: dir,
37
+ absolute: true,
38
+ ignore: ['**/node_modules/**'],
39
+ });
40
+ }
41
+ //# sourceMappingURL=discovery.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.mjs","sourceRoot":"","sources":["../../src/docs/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa;AAE5B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAW;IAC3C,OAAO,MAAM,IAAI,CAAC,SAAS,EAAE;QAC3B,GAAG,EAAE,GAAG;QACR,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,oBAAoB;YACpB,YAAY;YACZ,iBAAiB;YACjB,aAAa;YACb,YAAY;YACZ,iBAAiB;YACjB,cAAc;YACd,gBAAgB;YAChB,cAAc;YACd,WAAW;SACZ;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,OAAO,MAAM,IAAI,CAAC,YAAY,EAAE;QAC9B,GAAG,EAAE,GAAG;QACR,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,CAAC,oBAAoB,CAAC;KAC/B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { glob } from 'glob';\n\n/**\n * Find all non-test TypeScript source files in a directory.\n * Skips node_modules, dist, test directories, and declaration files.\n *\n * @param dir - The directory to search.\n * @returns A promise that resolves to an array of absolute file paths.\n */\nexport async function findTsFiles(dir: string): Promise<string[]> {\n return await glob('**/*.ts', {\n cwd: dir,\n absolute: true,\n ignore: [\n '**/node_modules/**',\n '**/dist/**',\n '**/__tests__/**',\n '**/tests/**',\n '**/test/**',\n '**/__mocks__/**',\n '**/*.test.ts',\n '**/*.test-d.ts',\n '**/*.spec.ts',\n '**/*.d.ts',\n ],\n });\n}\n\n/**\n * Find all `.d.cts` declaration files in a directory.\n * Skips nested node_modules subdirectories.\n *\n * @param dir - The directory to search.\n * @returns A promise that resolves to an array of absolute file paths.\n */\nexport async function findDtsFiles(dir: string): Promise<string[]> {\n return await glob('**/*.d.cts', {\n cwd: dir,\n absolute: true,\n ignore: ['**/node_modules/**'],\n });\n}\n"]}
@@ -0,0 +1,577 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.extractFromFile = void 0;
27
+ const fs = __importStar(require("node:fs/promises"));
28
+ const path = __importStar(require("node:path"));
29
+ const typescript_1 = require("typescript");
30
+ /**
31
+ * Check whether a file exists.
32
+ *
33
+ * @param filePath - The path to check.
34
+ * @returns A promise that resolves to true if the file exists.
35
+ */
36
+ async function fileExists(filePath) {
37
+ try {
38
+ await fs.access(filePath);
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Extract string constants from top-level variable declarations in a source file.
47
+ * Only looks at top-level `const x = 'string'` or `const x = 'string' as const`.
48
+ *
49
+ * @param sourceFile - The TypeScript source file to extract constants from.
50
+ * @returns A map of constant name to string value.
51
+ */
52
+ function extractStringConstants(sourceFile) {
53
+ const names = new Map();
54
+ for (const statement of sourceFile.statements) {
55
+ if (!(0, typescript_1.isVariableStatement)(statement)) {
56
+ continue;
57
+ }
58
+ for (const decl of statement.declarationList.declarations) {
59
+ if (!(0, typescript_1.isIdentifier)(decl.name)) {
60
+ continue;
61
+ }
62
+ if (decl.initializer) {
63
+ const init = decl.initializer;
64
+ if ((0, typescript_1.isStringLiteral)(init)) {
65
+ names.set(decl.name.text, init.text);
66
+ }
67
+ else if ((0, typescript_1.isAsExpression)(init) && (0, typescript_1.isStringLiteral)(init.expression)) {
68
+ names.set(decl.name.text, init.expression.text);
69
+ }
70
+ }
71
+ // Handle `declare const x: "value"` (common in .d.cts files)
72
+ if (!decl.initializer &&
73
+ decl.type &&
74
+ (0, typescript_1.isLiteralTypeNode)(decl.type) &&
75
+ (0, typescript_1.isStringLiteral)(decl.type.literal)) {
76
+ names.set(decl.name.text, decl.type.literal.text);
77
+ }
78
+ }
79
+ }
80
+ return names;
81
+ }
82
+ /**
83
+ * Resolve the value of `controllerName` (or similar constant) defined in the
84
+ * same file or imported from a local `./constants*` module (single-hop only).
85
+ *
86
+ * @param sourceFile - The TypeScript source file to search.
87
+ * @param filePath - The absolute path of the source file on disk.
88
+ * @returns A promise that resolves to a map of constant name to resolved string value.
89
+ */
90
+ async function resolveControllerName(sourceFile, filePath) {
91
+ const names = extractStringConstants(sourceFile);
92
+ // Chase single-hop local imports (no further recursion):
93
+ // import { BRIDGE_CONTROLLER_NAME } from './constants/bridge';
94
+ for (const statement of sourceFile.statements) {
95
+ if (!(0, typescript_1.isImportDeclaration)(statement) ||
96
+ !statement.moduleSpecifier ||
97
+ !(0, typescript_1.isStringLiteral)(statement.moduleSpecifier)) {
98
+ continue;
99
+ }
100
+ const spec = statement.moduleSpecifier.text;
101
+ if (!spec.startsWith('.')) {
102
+ continue;
103
+ }
104
+ const dir = path.dirname(filePath);
105
+ const isDts = filePath.endsWith('.d.cts') || filePath.endsWith('.d.ts');
106
+ // Strip .cjs/.js extension from specifier for .d.cts resolution
107
+ const bareSpec = spec.replace(/\.(c|m)?js$/u, '');
108
+ const candidates = isDts
109
+ ? [
110
+ path.join(dir, `${bareSpec}.d.cts`),
111
+ path.join(dir, bareSpec, 'index.d.cts'),
112
+ path.join(dir, `${bareSpec}.d.ts`),
113
+ path.join(dir, bareSpec, 'index.d.ts'),
114
+ ]
115
+ : [path.join(dir, `${spec}.ts`), path.join(dir, spec, 'index.ts')];
116
+ for (const candidate of candidates) {
117
+ if (!(await fileExists(candidate))) {
118
+ continue;
119
+ }
120
+ const content = await fs.readFile(candidate, 'utf8');
121
+ const sf = (0, typescript_1.createSourceFile)(candidate, content, typescript_1.ScriptTarget.Latest, true);
122
+ // Only extract constants — do NOT follow further imports
123
+ const imported = extractStringConstants(sf);
124
+ if (statement.importClause?.namedBindings &&
125
+ (0, typescript_1.isNamedImports)(statement.importClause.namedBindings)) {
126
+ for (const element of statement.importClause.namedBindings.elements) {
127
+ const importedName = (element.propertyName ?? element.name).text;
128
+ const localName = element.name.text;
129
+ const value = imported.get(importedName);
130
+ if (value !== undefined) {
131
+ names.set(localName, value);
132
+ }
133
+ }
134
+ }
135
+ break;
136
+ }
137
+ }
138
+ return names;
139
+ }
140
+ /**
141
+ * Resolve a template-literal or string-literal `type` property to its string
142
+ * value. Returns null if unresolvable.
143
+ *
144
+ * @param node - The expression node to resolve.
145
+ * @param constants - A map of known constant names to their string values.
146
+ * @returns The resolved string value, or null if unresolvable.
147
+ */
148
+ function resolveTypeString(node, constants) {
149
+ if ((0, typescript_1.isStringLiteral)(node) || (0, typescript_1.isNoSubstitutionTemplateLiteral)(node)) {
150
+ return node.text;
151
+ }
152
+ if ((0, typescript_1.isTemplateExpression)(node)) {
153
+ let result = node.head.text;
154
+ for (const span of node.templateSpans) {
155
+ // typeof X → resolve X
156
+ if ((0, typescript_1.isTypeOfExpression)(span.expression)) {
157
+ if ((0, typescript_1.isIdentifier)(span.expression.expression)) {
158
+ const val = constants.get(span.expression.expression.text);
159
+ if (val === undefined) {
160
+ return null;
161
+ }
162
+ result += val;
163
+ }
164
+ else {
165
+ return null;
166
+ }
167
+ }
168
+ else if ((0, typescript_1.isIdentifier)(span.expression)) {
169
+ const val = constants.get(span.expression.text);
170
+ if (val === undefined) {
171
+ return null;
172
+ }
173
+ result += val;
174
+ }
175
+ else {
176
+ return null;
177
+ }
178
+ result += span.literal.text;
179
+ }
180
+ return result;
181
+ }
182
+ return null;
183
+ }
184
+ /**
185
+ * Resolve a TemplateLiteralTypeNode (used in type positions like
186
+ * `type: \`${typeof controllerName}:name\``) to its string value.
187
+ *
188
+ * @param node - The template literal type node to resolve.
189
+ * @param constants - A map of known constant names to their string values.
190
+ * @returns The resolved string value, or null if unresolvable.
191
+ */
192
+ function resolveTemplateLiteralType(node, constants) {
193
+ let result = node.head.text;
194
+ for (const span of node.templateSpans) {
195
+ // In type position, `typeof X` is a TypeQueryNode
196
+ if ((0, typescript_1.isTypeQueryNode)(span.type) && (0, typescript_1.isIdentifier)(span.type.exprName)) {
197
+ const val = constants.get(span.type.exprName.text);
198
+ if (val === undefined) {
199
+ return null;
200
+ }
201
+ result += val;
202
+ }
203
+ else if ((0, typescript_1.isLiteralTypeNode)(span.type) &&
204
+ (0, typescript_1.isStringLiteral)(span.type.literal)) {
205
+ result += span.type.literal.text;
206
+ }
207
+ else {
208
+ return null;
209
+ }
210
+ result += span.literal.text;
211
+ }
212
+ return result;
213
+ }
214
+ /**
215
+ * Extract cleaned JSDoc body text from a node.
216
+ *
217
+ * @param node - The AST node to extract JSDoc from.
218
+ * @param sourceFile - The source file containing the node.
219
+ * @returns The cleaned JSDoc text, or empty string if none.
220
+ */
221
+ function extractJsDocText(node, sourceFile) {
222
+ const jsDocs = (0, typescript_1.getJSDocCommentsAndTags)(node);
223
+ if (jsDocs.length === 0) {
224
+ return '';
225
+ }
226
+ const jsDoc = jsDocs[0];
227
+ if (!(0, typescript_1.isJSDoc)(jsDoc)) {
228
+ return '';
229
+ }
230
+ const fullText = sourceFile.getFullText();
231
+ const raw = fullText.substring(jsDoc.getFullStart(), jsDoc.getEnd()).trim();
232
+ // Strip comment delimiters, leading asterisks, and @param/@returns/@see tags
233
+ const lines = raw.split('\n');
234
+ const cleaned = [];
235
+ const skippedTags = [
236
+ '@param',
237
+ '@returns',
238
+ '@see',
239
+ '@throws',
240
+ '@template',
241
+ '@example',
242
+ ];
243
+ let currentTag = null;
244
+ let deprecatedParts = [];
245
+ for (const rawLine of lines) {
246
+ let trimmed = rawLine.trim();
247
+ if (trimmed === '/**' || trimmed === '*/') {
248
+ continue;
249
+ }
250
+ if (trimmed.startsWith('* ')) {
251
+ trimmed = trimmed.slice(2);
252
+ }
253
+ else if (trimmed === '*') {
254
+ trimmed = '';
255
+ }
256
+ else if (trimmed.startsWith('*')) {
257
+ trimmed = trimmed.slice(1);
258
+ }
259
+ // Check if this line starts a new tag
260
+ if (trimmed.startsWith('@')) {
261
+ // Flush any accumulated deprecated text
262
+ if (currentTag === 'deprecated' && deprecatedParts.length > 0) {
263
+ cleaned.push(`**Deprecated:** ${deprecatedParts.join(' ')}`);
264
+ deprecatedParts = [];
265
+ }
266
+ if (trimmed.startsWith('@deprecated')) {
267
+ currentTag = 'deprecated';
268
+ const depText = trimmed.slice('@deprecated'.length).trim();
269
+ if (depText) {
270
+ deprecatedParts.push(depText);
271
+ }
272
+ continue;
273
+ }
274
+ currentTag = skippedTags.some((tag) => trimmed.startsWith(tag))
275
+ ? 'skip'
276
+ : null;
277
+ if (currentTag === 'skip') {
278
+ continue;
279
+ }
280
+ }
281
+ else if (currentTag === 'skip') {
282
+ if (trimmed === '') {
283
+ currentTag = null;
284
+ }
285
+ else {
286
+ continue;
287
+ }
288
+ }
289
+ else if (currentTag === 'deprecated') {
290
+ if (trimmed === '') {
291
+ // End of deprecated tag
292
+ if (deprecatedParts.length > 0) {
293
+ cleaned.push(`**Deprecated:** ${deprecatedParts.join(' ')}`);
294
+ deprecatedParts = [];
295
+ }
296
+ currentTag = null;
297
+ }
298
+ else {
299
+ deprecatedParts.push(trimmed);
300
+ continue;
301
+ }
302
+ }
303
+ cleaned.push(trimmed);
304
+ }
305
+ // Flush any remaining deprecated text
306
+ if (deprecatedParts.length > 0) {
307
+ cleaned.push(`**Deprecated:** ${deprecatedParts.join(' ')}`);
308
+ }
309
+ let result = cleaned.join('\n').trim();
310
+ // Convert JSDoc {@link X} references to markdown backtick code
311
+ result = result.replace(/\{@link\s+([^}]+)\}/gu, '`$1`');
312
+ // Escape remaining curly braces for MDX safety (but not inside backtick code spans)
313
+ result = result.replace(/`[^`]*`|(\{)|(\})/gu, (match, open, close) => {
314
+ if (open) {
315
+ return '\\{';
316
+ }
317
+ if (close) {
318
+ return '\\}';
319
+ }
320
+ return match; // preserve content inside backticks
321
+ });
322
+ return result;
323
+ }
324
+ /**
325
+ * Check whether a node has an `@deprecated` JSDoc tag.
326
+ *
327
+ * @param node - The AST node to check.
328
+ * @returns True if the node has an `@deprecated` tag.
329
+ */
330
+ function isDeprecated(node) {
331
+ const tags = (0, typescript_1.getJSDocTags)(node);
332
+ return tags.some((tag) => tag.tagName.text === 'deprecated');
333
+ }
334
+ /**
335
+ * Collect method info from all class declarations in a source file.
336
+ * Returns a map keyed by "ClassName.methodName".
337
+ *
338
+ * @param sourceFile - The TypeScript source file to scan.
339
+ * @returns A map of "ClassName.methodName" to method info.
340
+ */
341
+ function collectClassMethods(sourceFile) {
342
+ const methods = new Map();
343
+ for (const statement of sourceFile.statements) {
344
+ if (!(0, typescript_1.isClassDeclaration)(statement) || !statement.name) {
345
+ continue;
346
+ }
347
+ const className = statement.name.text;
348
+ for (const member of statement.members) {
349
+ if (!(0, typescript_1.isMethodDeclaration)(member) ||
350
+ !member.name ||
351
+ !(0, typescript_1.isIdentifier)(member.name)) {
352
+ continue;
353
+ }
354
+ const methodName = member.name.text;
355
+ // Build parameter list
356
+ const params = member.parameters
357
+ .map((param) => {
358
+ const paramName = param.name.getText(sourceFile);
359
+ const optional = param.questionToken ? '?' : '';
360
+ const paramType = param.type
361
+ ? param.type.getText(sourceFile)
362
+ : 'unknown';
363
+ return `${paramName}${optional}: ${paramType}`;
364
+ })
365
+ .join(', ');
366
+ // Get return type
367
+ const returnType = member.type ? member.type.getText(sourceFile) : 'void';
368
+ // For async methods, the declared return type already includes Promise<>,
369
+ // so we don't need to wrap again.
370
+ const methodSignature = `(${params}) => ${returnType}`;
371
+ const jsDoc = extractJsDocText(member, sourceFile);
372
+ methods.set(`${className}.${methodName}`, {
373
+ jsDoc,
374
+ signature: methodSignature,
375
+ });
376
+ }
377
+ }
378
+ return methods;
379
+ }
380
+ /**
381
+ * If `handlerText` matches `ClassName['methodName']`, look it up in classMethodInfo
382
+ * and return the resolved signature. Otherwise return the original text.
383
+ *
384
+ * @param handlerText - The raw handler text to resolve.
385
+ * @param classMethods - A map of class methods collected from the source file.
386
+ * @returns An object with the resolved signature and any associated JSDoc.
387
+ */
388
+ function resolveHandler(handlerText, classMethods) {
389
+ const match = handlerText.match(/^(\w+)\['(\w+)'\]$/u);
390
+ if (match) {
391
+ const key = `${match[1]}.${match[2]}`;
392
+ const info = classMethods.get(key);
393
+ if (info) {
394
+ return { signature: info.signature, methodJsDoc: info.jsDoc };
395
+ }
396
+ }
397
+ return { signature: handlerText, methodJsDoc: '' };
398
+ }
399
+ /**
400
+ * Get the raw source text for a property value inside a type literal.
401
+ *
402
+ * @param members - The type literal members to search.
403
+ * @param propName - The property name to find.
404
+ * @param sourceFile - The source file for getText calls.
405
+ * @returns The raw text of the property type, or empty string if not found.
406
+ */
407
+ function getPropertyText(members, propName, sourceFile) {
408
+ for (const member of members) {
409
+ if ((0, typescript_1.isPropertySignature)(member) &&
410
+ member.name &&
411
+ (0, typescript_1.isIdentifier)(member.name) &&
412
+ member.name.text === propName &&
413
+ member.type) {
414
+ return member.type.getText(sourceFile).trim();
415
+ }
416
+ }
417
+ return '';
418
+ }
419
+ // ---------------------------------------------------------------------------
420
+ // Main extraction
421
+ // ---------------------------------------------------------------------------
422
+ /**
423
+ * Extract messenger action/event type definitions from a single TypeScript file.
424
+ *
425
+ * @param filePath - The absolute path to the TypeScript file.
426
+ * @param relBase - Base path for computing relative source paths.
427
+ * @returns A promise that resolves to an array of extracted messenger item docs.
428
+ */
429
+ async function extractFromFile(filePath, relBase) {
430
+ const content = await fs.readFile(filePath, 'utf8');
431
+ const sourceFile = (0, typescript_1.createSourceFile)(filePath, content, typescript_1.ScriptTarget.Latest, true);
432
+ const constants = await resolveControllerName(sourceFile, filePath);
433
+ const classMethods = collectClassMethods(sourceFile);
434
+ const items = [];
435
+ const relPath = path.relative(relBase, filePath);
436
+ // Type aliases and interfaces are always top-level statements
437
+ for (const statement of sourceFile.statements) {
438
+ // ---------------------------------------------------------------
439
+ // Pattern 1: { type: '...'; handler/payload: ... }
440
+ // Matches both:
441
+ // type X = { type: '...'; handler: ... } (type alias with literal body)
442
+ // interface X { type: '...'; handler: ... } (interface declaration)
443
+ // ---------------------------------------------------------------
444
+ let inlineNode;
445
+ let inlineMembers;
446
+ if ((0, typescript_1.isTypeAliasDeclaration)(statement) &&
447
+ (0, typescript_1.isTypeLiteralNode)(statement.type)) {
448
+ inlineNode = statement;
449
+ inlineMembers = statement.type.members;
450
+ }
451
+ else if ((0, typescript_1.isInterfaceDeclaration)(statement)) {
452
+ inlineNode = statement;
453
+ inlineMembers = statement.members;
454
+ }
455
+ if (inlineNode && inlineMembers) {
456
+ const typeName = inlineNode.name.text;
457
+ const line = sourceFile.getLineAndCharacterOfPosition(inlineNode.getStart()).line +
458
+ 1;
459
+ // Find `type` property
460
+ let typeString = null;
461
+ for (const member of inlineMembers) {
462
+ if ((0, typescript_1.isPropertySignature)(member) &&
463
+ member.name &&
464
+ (0, typescript_1.isIdentifier)(member.name) &&
465
+ member.name.text === 'type' &&
466
+ member.type) {
467
+ if ((0, typescript_1.isLiteralTypeNode)(member.type)) {
468
+ typeString = resolveTypeString(member.type.literal, constants);
469
+ }
470
+ else if ((0, typescript_1.isTemplateLiteralTypeNode)(member.type)) {
471
+ typeString = resolveTemplateLiteralType(member.type, constants);
472
+ }
473
+ }
474
+ }
475
+ if (typeString?.includes(':')) {
476
+ const handlerText = getPropertyText(inlineMembers, 'handler', sourceFile);
477
+ const payloadText = getPropertyText(inlineMembers, 'payload', sourceFile);
478
+ if (handlerText || payloadText) {
479
+ const kind = handlerText ? 'action' : 'event';
480
+ // For actions, resolve ClassName['methodName'] to actual signature + JSDoc
481
+ let resolvedHandler = handlerText || payloadText;
482
+ let typeAliasJsDoc = extractJsDocText(inlineNode, sourceFile);
483
+ if (handlerText) {
484
+ const resolved = resolveHandler(handlerText, classMethods);
485
+ resolvedHandler = resolved.signature;
486
+ // If the type alias has no JSDoc, use the method's JSDoc
487
+ if (!typeAliasJsDoc && resolved.methodJsDoc) {
488
+ typeAliasJsDoc = resolved.methodJsDoc;
489
+ }
490
+ }
491
+ items.push({
492
+ typeName,
493
+ typeString,
494
+ kind,
495
+ jsDoc: typeAliasJsDoc,
496
+ handlerOrPayload: resolvedHandler,
497
+ sourceFile: relPath,
498
+ line,
499
+ deprecated: isDeprecated(inlineNode),
500
+ });
501
+ }
502
+ }
503
+ }
504
+ // -------------------------------------------------------------------
505
+ // Patterns 2 & 3 only apply to type aliases (generic type references)
506
+ // -------------------------------------------------------------------
507
+ if (!(0, typescript_1.isTypeAliasDeclaration)(statement)) {
508
+ continue;
509
+ }
510
+ const node = statement;
511
+ const typeName = node.name.text;
512
+ const line = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
513
+ // -------------------------------------------------------------------
514
+ // Pattern 2: ControllerGetStateAction<typeof cn, State>
515
+ // -------------------------------------------------------------------
516
+ if ((0, typescript_1.isTypeReferenceNode)(node.type) &&
517
+ (0, typescript_1.isIdentifier)(node.type.typeName) &&
518
+ node.type.typeName.text === 'ControllerGetStateAction' &&
519
+ node.type.typeArguments &&
520
+ node.type.typeArguments.length >= 2) {
521
+ const firstArg = node.type.typeArguments[0];
522
+ const stateArg = node.type.typeArguments[1];
523
+ let namespace = null;
524
+ if ((0, typescript_1.isTypeQueryNode)(firstArg) && (0, typescript_1.isIdentifier)(firstArg.exprName)) {
525
+ namespace = constants.get(firstArg.exprName.text) ?? null;
526
+ }
527
+ if ((0, typescript_1.isLiteralTypeNode)(firstArg) && (0, typescript_1.isStringLiteral)(firstArg.literal)) {
528
+ namespace = firstArg.literal.text;
529
+ }
530
+ if (namespace) {
531
+ items.push({
532
+ typeName,
533
+ typeString: `${namespace}:getState`,
534
+ kind: 'action',
535
+ jsDoc: extractJsDocText(node, sourceFile),
536
+ handlerOrPayload: `() => ${stateArg.getText(sourceFile)}`,
537
+ sourceFile: relPath,
538
+ line,
539
+ deprecated: isDeprecated(node),
540
+ });
541
+ }
542
+ }
543
+ // -------------------------------------------------------------------
544
+ // Pattern 3: ControllerStateChangeEvent<typeof cn, State>
545
+ // -------------------------------------------------------------------
546
+ if ((0, typescript_1.isTypeReferenceNode)(node.type) &&
547
+ (0, typescript_1.isIdentifier)(node.type.typeName) &&
548
+ node.type.typeName.text === 'ControllerStateChangeEvent' &&
549
+ node.type.typeArguments &&
550
+ node.type.typeArguments.length >= 2) {
551
+ const firstArg = node.type.typeArguments[0];
552
+ const stateArg = node.type.typeArguments[1];
553
+ let namespace = null;
554
+ if ((0, typescript_1.isTypeQueryNode)(firstArg) && (0, typescript_1.isIdentifier)(firstArg.exprName)) {
555
+ namespace = constants.get(firstArg.exprName.text) ?? null;
556
+ }
557
+ if ((0, typescript_1.isLiteralTypeNode)(firstArg) && (0, typescript_1.isStringLiteral)(firstArg.literal)) {
558
+ namespace = firstArg.literal.text;
559
+ }
560
+ if (namespace) {
561
+ items.push({
562
+ typeName,
563
+ typeString: `${namespace}:stateChange`,
564
+ kind: 'event',
565
+ jsDoc: extractJsDocText(node, sourceFile),
566
+ handlerOrPayload: `[${stateArg.getText(sourceFile)}, Patch[]]`,
567
+ sourceFile: relPath,
568
+ line,
569
+ deprecated: isDeprecated(node),
570
+ });
571
+ }
572
+ }
573
+ }
574
+ return items;
575
+ }
576
+ exports.extractFromFile = extractFromFile;
577
+ //# sourceMappingURL=extraction.cjs.map