@metamask-previews/messenger 0.3.0-preview-b9ae764 → 0.3.0-preview-3f2e0ea
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/dist/generate-action-types/check.cjs +8 -8
- package/dist/generate-action-types/check.cjs.map +1 -1
- package/dist/generate-action-types/check.d.cts +3 -3
- package/dist/generate-action-types/check.d.cts.map +1 -1
- package/dist/generate-action-types/check.d.mts +3 -3
- package/dist/generate-action-types/check.d.mts.map +1 -1
- package/dist/generate-action-types/check.mjs +8 -8
- package/dist/generate-action-types/check.mjs.map +1 -1
- package/dist/generate-action-types/cli.cjs +17 -13
- package/dist/generate-action-types/cli.cjs.map +1 -1
- package/dist/generate-action-types/cli.mjs +18 -14
- package/dist/generate-action-types/cli.mjs.map +1 -1
- package/dist/generate-action-types/fix.cjs +11 -11
- package/dist/generate-action-types/fix.cjs.map +1 -1
- package/dist/generate-action-types/fix.d.cts +4 -4
- package/dist/generate-action-types/fix.d.cts.map +1 -1
- package/dist/generate-action-types/fix.d.mts +4 -4
- package/dist/generate-action-types/fix.d.mts.map +1 -1
- package/dist/generate-action-types/fix.mjs +11 -11
- package/dist/generate-action-types/fix.mjs.map +1 -1
- package/dist/generate-action-types/generate-content.cjs +11 -11
- package/dist/generate-action-types/generate-content.cjs.map +1 -1
- package/dist/generate-action-types/generate-content.d.cts +3 -3
- package/dist/generate-action-types/generate-content.d.cts.map +1 -1
- package/dist/generate-action-types/generate-content.d.mts +3 -3
- package/dist/generate-action-types/generate-content.d.mts.map +1 -1
- package/dist/generate-action-types/generate-content.mjs +11 -11
- package/dist/generate-action-types/generate-content.mjs.map +1 -1
- package/dist/generate-action-types/index.cjs +3 -3
- package/dist/generate-action-types/index.cjs.map +1 -1
- package/dist/generate-action-types/index.d.cts +2 -2
- package/dist/generate-action-types/index.d.cts.map +1 -1
- package/dist/generate-action-types/index.d.mts +2 -2
- package/dist/generate-action-types/index.d.mts.map +1 -1
- package/dist/generate-action-types/index.mjs +1 -1
- package/dist/generate-action-types/index.mjs.map +1 -1
- package/dist/generate-action-types/parse-source.cjs +19 -19
- package/dist/generate-action-types/parse-source.cjs.map +1 -1
- package/dist/generate-action-types/parse-source.d.cts +9 -9
- package/dist/generate-action-types/parse-source.d.cts.map +1 -1
- package/dist/generate-action-types/parse-source.d.mts +9 -9
- package/dist/generate-action-types/parse-source.d.mts.map +1 -1
- package/dist/generate-action-types/parse-source.mjs +16 -16
- package/dist/generate-action-types/parse-source.mjs.map +1 -1
- package/dist/generate-action-types/types.cjs.map +1 -1
- package/dist/generate-action-types/types.d.cts +4 -12
- package/dist/generate-action-types/types.d.cts.map +1 -1
- package/dist/generate-action-types/types.d.mts +4 -12
- package/dist/generate-action-types/types.d.mts.map +1 -1
- package/dist/generate-action-types/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAIlC;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,
|
|
1
|
+
{"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAIlC;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,MAAkB;IAC3D,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,KAAK,YAAY,EAAE,CAAC;IAE7C,IAAI,OAAO,GAAG;;;;;gBAKA,MAAM,CAAC,IAAI,YAAY,gBAAgB;;CAEtD,CAAC;IAEA,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,eAAe,GACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,eAAe,QAAQ,CAAC;QAChE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAErD,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,eAAe,cAAc;YAChC,YAAY;aACX,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;OACjC,CAAC;IACN,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC;QACpD,OAAO,IAAI;kBACG,MAAM,CAAC,IAAI;;cAEf,aAAa,MAAM,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChE,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;AAClC,CAAC;AA1CD,gEA0CC","sourcesContent":["import * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @returns The content for the action types file.\n */\nexport function generateActionTypesContent(source: SourceInfo): string {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\n\n let content = `/**\n * This file is auto generated by \\`@metamask/messenger/generate-action-types\\`.\n * Do not edit manually.\n */\n\nimport type { ${source.name} } from '${sourceImportPath}';\n\n`;\n\n const actionTypeNames: string[] = [];\n\n for (const method of source.methods) {\n const capitalizedName =\n method.name.charAt(0).toUpperCase() + method.name.slice(1);\n const actionTypeName = `${source.name}${capitalizedName}Action`;\n const actionString = `${source.name}:${method.name}`;\n\n actionTypeNames.push(actionTypeName);\n\n if (method.jsDoc) {\n content += `${method.jsDoc}\\n`;\n }\n\n content += `export type ${actionTypeName} = {\n type: \\`${actionString}\\`;\n handler: ${source.name}['${method.name}'];\n};\\n\\n`;\n }\n\n if (actionTypeNames.length > 0) {\n const unionTypeName = `${source.name}MethodActions`;\n content += `/**\n * Union of all ${source.name} action types.\n */\nexport type ${unionTypeName} = ${actionTypeNames.join(' | ')};\\n`;\n }\n\n return `${content.trimEnd()}\\n`;\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Generates the content for the action types file.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param source - The source information object (controller or service).
|
|
6
6
|
* @returns The content for the action types file.
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateActionTypesContent(
|
|
8
|
+
export declare function generateActionTypesContent(source: SourceInfo): string;
|
|
9
9
|
//# sourceMappingURL=generate-content.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA0CrE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Generates the content for the action types file.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param source - The source information object (controller or service).
|
|
6
6
|
* @returns The content for the action types file.
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateActionTypesContent(
|
|
8
|
+
export declare function generateActionTypesContent(source: SourceInfo): string;
|
|
9
9
|
//# sourceMappingURL=generate-content.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA0CrE"}
|
|
@@ -2,38 +2,38 @@ import * as path from "node:path";
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates the content for the action types file.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param source - The source information object (controller or service).
|
|
6
6
|
* @returns The content for the action types file.
|
|
7
7
|
*/
|
|
8
|
-
export function generateActionTypesContent(
|
|
9
|
-
const baseFileName = path.basename(
|
|
10
|
-
const
|
|
8
|
+
export function generateActionTypesContent(source) {
|
|
9
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
10
|
+
const sourceImportPath = `./${baseFileName}`;
|
|
11
11
|
let content = `/**
|
|
12
12
|
* This file is auto generated by \`@metamask/messenger/generate-action-types\`.
|
|
13
13
|
* Do not edit manually.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type { ${
|
|
16
|
+
import type { ${source.name} } from '${sourceImportPath}';
|
|
17
17
|
|
|
18
18
|
`;
|
|
19
19
|
const actionTypeNames = [];
|
|
20
|
-
for (const method of
|
|
20
|
+
for (const method of source.methods) {
|
|
21
21
|
const capitalizedName = method.name.charAt(0).toUpperCase() + method.name.slice(1);
|
|
22
|
-
const actionTypeName = `${
|
|
23
|
-
const actionString = `${
|
|
22
|
+
const actionTypeName = `${source.name}${capitalizedName}Action`;
|
|
23
|
+
const actionString = `${source.name}:${method.name}`;
|
|
24
24
|
actionTypeNames.push(actionTypeName);
|
|
25
25
|
if (method.jsDoc) {
|
|
26
26
|
content += `${method.jsDoc}\n`;
|
|
27
27
|
}
|
|
28
28
|
content += `export type ${actionTypeName} = {
|
|
29
29
|
type: \`${actionString}\`;
|
|
30
|
-
handler: ${
|
|
30
|
+
handler: ${source.name}['${method.name}'];
|
|
31
31
|
};\n\n`;
|
|
32
32
|
}
|
|
33
33
|
if (actionTypeNames.length > 0) {
|
|
34
|
-
const unionTypeName = `${
|
|
34
|
+
const unionTypeName = `${source.name}MethodActions`;
|
|
35
35
|
content += `/**
|
|
36
|
-
* Union of all ${
|
|
36
|
+
* Union of all ${source.name} action types.
|
|
37
37
|
*/
|
|
38
38
|
export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.mjs","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,kBAAkB;AAIlC;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,
|
|
1
|
+
{"version":3,"file":"generate-content.mjs","sourceRoot":"","sources":["../../src/generate-action-types/generate-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,kBAAkB;AAIlC;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAkB;IAC3D,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,KAAK,YAAY,EAAE,CAAC;IAE7C,IAAI,OAAO,GAAG;;;;;gBAKA,MAAM,CAAC,IAAI,YAAY,gBAAgB;;CAEtD,CAAC;IAEA,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,eAAe,GACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,eAAe,QAAQ,CAAC;QAChE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAErD,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,eAAe,cAAc;YAChC,YAAY;aACX,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;OACjC,CAAC;IACN,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC;QACpD,OAAO,IAAI;kBACG,MAAM,CAAC,IAAI;;cAEf,aAAa,MAAM,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChE,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;AAClC,CAAC","sourcesContent":["import * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @returns The content for the action types file.\n */\nexport function generateActionTypesContent(source: SourceInfo): string {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\n\n let content = `/**\n * This file is auto generated by \\`@metamask/messenger/generate-action-types\\`.\n * Do not edit manually.\n */\n\nimport type { ${source.name} } from '${sourceImportPath}';\n\n`;\n\n const actionTypeNames: string[] = [];\n\n for (const method of source.methods) {\n const capitalizedName =\n method.name.charAt(0).toUpperCase() + method.name.slice(1);\n const actionTypeName = `${source.name}${capitalizedName}Action`;\n const actionString = `${source.name}:${method.name}`;\n\n actionTypeNames.push(actionTypeName);\n\n if (method.jsDoc) {\n content += `${method.jsDoc}\\n`;\n }\n\n content += `export type ${actionTypeName} = {\n type: \\`${actionString}\\`;\n handler: ${source.name}['${method.name}'];\n};\\n\\n`;\n }\n\n if (actionTypeNames.length > 0) {\n const unionTypeName = `${source.name}MethodActions`;\n content += `/**\n * Union of all ${source.name} action types.\n */\nexport type ${unionTypeName} = ${actionTypeNames.join(' | ')};\\n`;\n }\n\n return `${content.trimEnd()}\\n`;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseSourceFile = exports.findSourcesWithExposedMethods = exports.generateActionTypesContent = exports.generateAllActionTypesFiles = exports.checkActionTypesFiles = void 0;
|
|
4
4
|
var check_1 = require("./check.cjs");
|
|
5
5
|
Object.defineProperty(exports, "checkActionTypesFiles", { enumerable: true, get: function () { return check_1.checkActionTypesFiles; } });
|
|
6
6
|
var fix_1 = require("./fix.cjs");
|
|
@@ -8,6 +8,6 @@ Object.defineProperty(exports, "generateAllActionTypesFiles", { enumerable: true
|
|
|
8
8
|
var generate_content_1 = require("./generate-content.cjs");
|
|
9
9
|
Object.defineProperty(exports, "generateActionTypesContent", { enumerable: true, get: function () { return generate_content_1.generateActionTypesContent; } });
|
|
10
10
|
var parse_source_1 = require("./parse-source.cjs");
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
Object.defineProperty(exports, "
|
|
11
|
+
Object.defineProperty(exports, "findSourcesWithExposedMethods", { enumerable: true, get: function () { return parse_source_1.findSourcesWithExposedMethods; } });
|
|
12
|
+
Object.defineProperty(exports, "parseSourceFile", { enumerable: true, get: function () { return parse_source_1.parseSourceFile; } });
|
|
13
13
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,iCAAoD;AAA3C,kHAAA,2BAA2B,OAAA;AACpC,2DAAgE;AAAvD,8HAAA,0BAA0B,OAAA;AAEnC,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,iCAAoD;AAA3C,kHAAA,2BAA2B,OAAA;AACpC,2DAAgE;AAAvD,8HAAA,0BAA0B,OAAA;AAEnC,mDAAgF;AAAvE,6HAAA,6BAA6B,OAAA;AAAE,+GAAA,eAAe,OAAA","sourcesContent":["export { checkActionTypesFiles } from './check';\nexport { generateAllActionTypesFiles } from './fix';\nexport { generateActionTypesContent } from './generate-content';\nexport type { SourceInfo, MethodInfo } from './parse-source';\nexport { findSourcesWithExposedMethods, parseSourceFile } from './parse-source';\nexport type { ESLint } from './types';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { checkActionTypesFiles } from "./check.cjs";
|
|
2
2
|
export { generateAllActionTypesFiles } from "./fix.cjs";
|
|
3
3
|
export { generateActionTypesContent } from "./generate-content.cjs";
|
|
4
|
-
export type {
|
|
5
|
-
export {
|
|
4
|
+
export type { SourceInfo, MethodInfo } from "./parse-source.cjs";
|
|
5
|
+
export { findSourcesWithExposedMethods, parseSourceFile } from "./parse-source.cjs";
|
|
6
6
|
export type { ESLint } from "./types.cjs";
|
|
7
7
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAChE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAChE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,2BAAuB;AAC7D,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,2BAAuB;AAChF,YAAY,EAAE,MAAM,EAAE,oBAAgB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { checkActionTypesFiles } from "./check.mjs";
|
|
2
2
|
export { generateAllActionTypesFiles } from "./fix.mjs";
|
|
3
3
|
export { generateActionTypesContent } from "./generate-content.mjs";
|
|
4
|
-
export type {
|
|
5
|
-
export {
|
|
4
|
+
export type { SourceInfo, MethodInfo } from "./parse-source.mjs";
|
|
5
|
+
export { findSourcesWithExposedMethods, parseSourceFile } from "./parse-source.mjs";
|
|
6
6
|
export type { ESLint } from "./types.mjs";
|
|
7
7
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAChE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAChE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,2BAAuB;AAC7D,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,2BAAuB;AAChF,YAAY,EAAE,MAAM,EAAE,oBAAgB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { checkActionTypesFiles } from "./check.mjs";
|
|
2
2
|
export { generateAllActionTypesFiles } from "./fix.mjs";
|
|
3
3
|
export { generateActionTypesContent } from "./generate-content.mjs";
|
|
4
|
-
export {
|
|
4
|
+
export { findSourcesWithExposedMethods, parseSourceFile } from "./parse-source.mjs";
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAEhE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/generate-action-types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAEhE,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,2BAAuB","sourcesContent":["export { checkActionTypesFiles } from './check';\nexport { generateAllActionTypesFiles } from './fix';\nexport { generateActionTypesContent } from './generate-content';\nexport type { SourceInfo, MethodInfo } from './parse-source';\nexport { findSourcesWithExposedMethods, parseSourceFile } from './parse-source';\nexport type { ESLint } from './types';\n"]}
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.findSourcesWithExposedMethods = exports.parseSourceFile = void 0;
|
|
27
27
|
const utils_1 = require("@metamask/utils");
|
|
28
28
|
const fs = __importStar(require("node:fs"));
|
|
29
29
|
const path = __importStar(require("node:path"));
|
|
@@ -82,7 +82,7 @@ function formatJSDoc(rawJsDoc) {
|
|
|
82
82
|
return formattedLines.join('\n');
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* Visits AST nodes to find exposed methods and controller class.
|
|
85
|
+
* Visits AST nodes to find exposed methods and controller/service class.
|
|
86
86
|
*
|
|
87
87
|
* @param context - The visitor context.
|
|
88
88
|
* @returns A function to visit nodes.
|
|
@@ -167,7 +167,7 @@ function createProgramForFile(filePath) {
|
|
|
167
167
|
* @returns The class declaration node, or null if not found.
|
|
168
168
|
*/
|
|
169
169
|
function findClassInSourceFile(source, className) {
|
|
170
|
-
return (source.statements.find((node) => (0, typescript_1.isClassDeclaration)(node) && node.name?.text === className) ?? // istanbul ignore next: class is always found when called from
|
|
170
|
+
return (source.statements.find((node) => (0, typescript_1.isClassDeclaration)(node) && node.name?.text === className) ?? // istanbul ignore next: class is always found when called from parseSourceFile
|
|
171
171
|
null);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
@@ -217,12 +217,12 @@ async function isDirectory(pathValue) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
|
-
* Parses a
|
|
220
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
221
221
|
*
|
|
222
|
-
* @param filePath - Path to the controller file to parse.
|
|
223
|
-
* @returns
|
|
222
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
223
|
+
* @returns Source information or null if parsing fails.
|
|
224
224
|
*/
|
|
225
|
-
async function
|
|
225
|
+
async function parseSourceFile(filePath) {
|
|
226
226
|
try {
|
|
227
227
|
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
228
228
|
const source = (0, typescript_1.createSourceFile)(filePath, content, typescript_1.ScriptTarget.Latest, true);
|
|
@@ -266,16 +266,16 @@ async function parseControllerFile(filePath) {
|
|
|
266
266
|
return null;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
exports.
|
|
269
|
+
exports.parseSourceFile = parseSourceFile;
|
|
270
270
|
/**
|
|
271
|
-
* Finds all
|
|
271
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
272
272
|
*
|
|
273
|
-
* @param
|
|
274
|
-
* @returns A list of
|
|
273
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
274
|
+
* @returns A list of source information objects.
|
|
275
275
|
*/
|
|
276
|
-
async function
|
|
277
|
-
const srcPath = path.resolve(globalThis.process.cwd(),
|
|
278
|
-
const
|
|
276
|
+
async function findSourcesWithExposedMethods(sourcePath) {
|
|
277
|
+
const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);
|
|
278
|
+
const sources = [];
|
|
279
279
|
if (!(await isDirectory(srcPath))) {
|
|
280
280
|
throw new Error(`The specified path is not a directory: ${srcPath}`);
|
|
281
281
|
}
|
|
@@ -287,13 +287,13 @@ async function findControllersWithExposedMethods(controllerPath) {
|
|
|
287
287
|
const filePath = path.join(srcPath, file);
|
|
288
288
|
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
289
289
|
if (content.includes('MESSENGER_EXPOSED_METHODS')) {
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
290
|
+
const sourceInfo = await parseSourceFile(filePath);
|
|
291
|
+
if (sourceInfo) {
|
|
292
|
+
sources.push(sourceInfo);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
return
|
|
296
|
+
return sources;
|
|
297
297
|
}
|
|
298
|
-
exports.
|
|
298
|
+
exports.findSourcesWithExposedMethods = findSourcesWithExposedMethods;
|
|
299
299
|
//# sourceMappingURL=parse-source.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-source.cjs","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,4CAA8B;AAC9B,gDAAkC;AAUlC,2CAkBoB;AAoBpB;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,IAAuB,EAAE,MAAkB;IAC/D,MAAM,SAAS,GAAG,IAAA,oCAAuB,EAAC,IAAI,CAAC,CAAC;IAChD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,IAAA,oBAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,6FAA6F;IAC7F,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,QAAgB;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC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qB,EAAE,CAAC;IAEzC,IAAI,CAAC,CAAC,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,0CAA0C,OAAO,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpD,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7D,IAAI,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAClD,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YAC3D,IAAI,cAAc,EAAE,CAAC;gBACnB,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AA7BD,8EA6BC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type {\n ArrayLiteralExpression,\n ClassDeclaration,\n MethodDeclaration,\n Node as TSNode,\n Program,\n SourceFile,\n Type,\n} from 'typescript';\nimport {\n ScriptTarget,\n createProgram,\n createSourceFile,\n findConfigFile,\n forEachChild,\n getJSDocCommentsAndTags,\n isArrayLiteralExpression,\n isAsExpression,\n isClassDeclaration,\n isIdentifier,\n isJSDoc,\n isMethodDeclaration,\n isStringLiteral,\n isVariableStatement,\n parseJsonConfigFileContent,\n readConfigFile,\n sys,\n} from 'typescript';\n\nexport type MethodInfo = {\n name: string;\n jsDoc: string;\n};\n\nexport type ControllerInfo = {\n name: string;\n filePath: string;\n methods: MethodInfo[];\n};\n\ntype VisitorContext = {\n exposedMethods: string[];\n className: string;\n methods: MethodInfo[];\n sourceFile: SourceFile;\n};\n\n/**\n * Extracts JSDoc comment from a method declaration.\n *\n * @param node - The method declaration node.\n * @param source - The source file.\n * @returns The JSDoc comment.\n */\nfunction extractJSDoc(node: MethodDeclaration, source: SourceFile): string {\n const jsDocTags = getJSDocCommentsAndTags(node);\n if (jsDocTags.length === 0) {\n return '';\n }\n\n const jsDoc = jsDocTags[0];\n if (isJSDoc(jsDoc)) {\n const fullText = source.getFullText();\n const start = jsDoc.getFullStart();\n const end = jsDoc.getEnd();\n const rawJsDoc = fullText.substring(start, end).trim();\n return formatJSDoc(rawJsDoc);\n }\n\n // istanbul ignore next: defensive check — getJSDocCommentsAndTags always returns JSDoc nodes\n return '';\n}\n\n/**\n * Formats JSDoc comments to have consistent indentation for the generated file.\n *\n * @param rawJsDoc - The raw JSDoc comment from the source.\n * @returns The formatted JSDoc comment.\n */\nfunction formatJSDoc(rawJsDoc: string): string {\n const lines = rawJsDoc.split('\\n');\n const formattedLines: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (i === 0) {\n formattedLines.push('/**');\n } else if (i === lines.length - 1) {\n formattedLines.push(' */');\n } else {\n const trimmed = line.trim();\n if (trimmed.startsWith('*')) {\n const content = trimmed.substring(1).trim();\n formattedLines.push(content ? ` * ${content}` : ' *');\n } else {\n formattedLines.push(trimmed ? ` * ${trimmed}` : ' *');\n }\n }\n }\n\n return formattedLines.join('\\n');\n}\n\n/**\n * Visits AST nodes to find exposed methods and controller class.\n *\n * @param context - The visitor context.\n * @returns A function to visit nodes.\n */\nfunction createASTVisitor(context: VisitorContext): (node: TSNode) => void {\n function visitNode(node: TSNode): void {\n if (isVariableStatement(node)) {\n const declaration = node.declarationList.declarations[0];\n if (\n isIdentifier(declaration.name) &&\n declaration.name.text === 'MESSENGER_EXPOSED_METHODS'\n ) {\n if (declaration.initializer) {\n let arrayExpression: ArrayLiteralExpression | undefined;\n\n if (isArrayLiteralExpression(declaration.initializer)) {\n arrayExpression = declaration.initializer;\n } else if (\n isAsExpression(declaration.initializer) &&\n isArrayLiteralExpression(declaration.initializer.expression)\n ) {\n arrayExpression = declaration.initializer.expression;\n }\n\n if (arrayExpression) {\n context.exposedMethods = arrayExpression.elements\n .filter(isStringLiteral)\n .map((element) => element.text);\n }\n }\n }\n }\n\n if (isClassDeclaration(node) && node.name) {\n const classText = node.name.text;\n if (classText.includes('Controller') || classText.includes('Service')) {\n context.className = classText;\n\n const seenMethods = new Set<string>();\n for (const member of node.members) {\n if (\n isMethodDeclaration(member) &&\n member.name &&\n isIdentifier(member.name)\n ) {\n const methodName = member.name.text;\n if (\n context.exposedMethods.includes(methodName) &&\n !seenMethods.has(methodName)\n ) {\n seenMethods.add(methodName);\n const jsDoc = extractJSDoc(member, context.sourceFile);\n context.methods.push({\n name: methodName,\n jsDoc,\n });\n }\n }\n }\n }\n }\n\n forEachChild(node, visitNode);\n }\n\n return visitNode;\n}\n\n/**\n * Create a TypeScript program for the given file by locating the nearest\n * tsconfig.json.\n *\n * @param filePath - Absolute path to the source file.\n * @returns A TypeScript program, or null if no tsconfig was found.\n */\nfunction createProgramForFile(filePath: string): Program | null {\n const configPath = findConfigFile(\n path.dirname(filePath),\n sys.fileExists.bind(sys),\n 'tsconfig.json',\n );\n if (!configPath) {\n return null;\n }\n\n const { config, error } = readConfigFile(configPath, sys.readFile.bind(sys));\n\n if (error) {\n return null;\n }\n\n const parsedConfig = parseJsonConfigFileContent(\n config,\n sys,\n path.dirname(configPath),\n );\n\n return createProgram({\n rootNames: parsedConfig.fileNames,\n options: parsedConfig.options,\n });\n}\n\n/**\n * Find a class declaration with the given name in a source file.\n *\n * @param source - The source file to search.\n * @param className - The class name to look for.\n * @returns The class declaration node, or null if not found.\n */\nfunction findClassInSourceFile(\n source: SourceFile,\n className: string,\n): ClassDeclaration | null {\n return (\n source.statements.find(\n (node): node is ClassDeclaration =>\n isClassDeclaration(node) && node.name?.text === className,\n ) ?? // istanbul ignore next: class is always found when called from parseControllerFile\n null\n );\n}\n\n/**\n * Search through the class hierarchy of a TypeScript type to find the\n * declaration of a method with the given name.\n *\n * @param classType - The class type to search.\n * @param methodName - The method name to look for.\n * @returns The method declaration node, or null if not found.\n */\nfunction findMethodInHierarchy(\n classType: Type,\n methodName: string,\n): MethodDeclaration | null {\n const symbol = classType.getProperty(methodName);\n if (!symbol) {\n return null;\n }\n\n const declarations = symbol.getDeclarations();\n // istanbul ignore next: defensive check — symbols from getProperty always have declarations\n if (!declarations) {\n return null;\n }\n\n for (const declaration of declarations) {\n if (isMethodDeclaration(declaration)) {\n return declaration;\n }\n }\n\n // istanbul ignore next: defensive fallback — property found but not a method declaration\n return null;\n}\n\n/**\n * Check if a path is a directory.\n *\n * @param pathValue - The path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nasync function isDirectory(pathValue: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(pathValue);\n return stats.isDirectory();\n } catch (error) {\n if (\n isObject(error) &&\n hasProperty(error, 'code') &&\n error.code === 'ENOENT'\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\n/**\n * Parses a controller file to extract exposed methods and their metadata.\n *\n * @param filePath - Path to the controller file to parse.\n * @returns Controller information or null if parsing fails.\n */\nexport async function parseControllerFile(\n filePath: string,\n): Promise<ControllerInfo | null> {\n try {\n const content = await fs.promises.readFile(filePath, 'utf8');\n const source = createSourceFile(\n filePath,\n content,\n ScriptTarget.Latest,\n true,\n );\n\n const context: VisitorContext = {\n exposedMethods: [],\n className: '',\n methods: [],\n sourceFile: source,\n };\n\n createASTVisitor(context)(source);\n\n if (context.exposedMethods.length === 0 || !context.className) {\n return null;\n }\n\n const foundMethodNames = new Set(\n context.methods.map((method) => method.name),\n );\n\n const inheritedMethodNames = context.exposedMethods.filter(\n (name) => !foundMethodNames.has(name),\n );\n\n if (inheritedMethodNames.length > 0) {\n const program = createProgramForFile(filePath);\n const checker = program?.getTypeChecker();\n const programSourceFile = program?.getSourceFile(filePath);\n\n assert(\n checker,\n `Type checker could not be created for \"${filePath}\". Ensure a valid tsconfig.json is present.`,\n );\n\n assert(\n programSourceFile,\n `Source file \"${filePath}\" not found in program.`,\n );\n\n const classNode = findClassInSourceFile(\n programSourceFile,\n context.className,\n );\n\n assert(\n classNode,\n `Class \"${context.className}\" not found in \"${filePath}\".`,\n );\n\n const classType = checker.getTypeAtLocation(classNode);\n for (const methodName of inheritedMethodNames) {\n const methodDeclaration = findMethodInHierarchy(classType, methodName);\n\n const jsDoc = methodDeclaration\n ? extractJSDoc(methodDeclaration, methodDeclaration.getSourceFile())\n : '';\n context.methods.push({ name: methodName, jsDoc });\n }\n }\n\n return {\n name: context.className,\n filePath,\n methods: context.methods,\n };\n } catch (error) {\n console.error(`Error parsing ${filePath}:`, error);\n return null;\n }\n}\n\n/**\n * Finds all controller files that have MESSENGER_EXPOSED_METHODS constants.\n *\n * @param controllerPath - Path to the folder where controllers are located.\n * @returns A list of controller information objects.\n */\nexport async function findControllersWithExposedMethods(\n controllerPath: string,\n): Promise<ControllerInfo[]> {\n const srcPath = path.resolve(globalThis.process.cwd(), controllerPath);\n const controllers: ControllerInfo[] = [];\n\n if (!(await isDirectory(srcPath))) {\n throw new Error(`The specified path is not a directory: ${srcPath}`);\n }\n\n const srcFiles = await fs.promises.readdir(srcPath);\n\n for (const file of srcFiles) {\n if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {\n continue;\n }\n\n const filePath = path.join(srcPath, file);\n const content = await fs.promises.readFile(filePath, 'utf8');\n\n if (content.includes('MESSENGER_EXPOSED_METHODS')) {\n const controllerInfo = await parseControllerFile(filePath);\n if (controllerInfo) {\n controllers.push(controllerInfo);\n }\n }\n }\n\n return controllers;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parse-source.cjs","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,4CAA8B;AAC9B,gDAAkC;AAUlC,2CAkBoB;AAoBpB;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,IAAuB,EAAE,MAAkB;IAC/D,MAAM,SAAS,GAAG,IAAA,oCAAuB,EAAC,IAAI,CAAC,CAAC;IAChD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,IAAA,oBAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,6FAA6F;IAC7F,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,QAAgB;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,KA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EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpD,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7D,IAAI,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAClD,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAC;YACnD,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA7BD,sEA6BC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type {\n ArrayLiteralExpression,\n ClassDeclaration,\n MethodDeclaration,\n Node as TSNode,\n Program,\n SourceFile,\n Type,\n} from 'typescript';\nimport {\n ScriptTarget,\n createProgram,\n createSourceFile,\n findConfigFile,\n forEachChild,\n getJSDocCommentsAndTags,\n isArrayLiteralExpression,\n isAsExpression,\n isClassDeclaration,\n isIdentifier,\n isJSDoc,\n isMethodDeclaration,\n isStringLiteral,\n isVariableStatement,\n parseJsonConfigFileContent,\n readConfigFile,\n sys,\n} from 'typescript';\n\nexport type MethodInfo = {\n name: string;\n jsDoc: string;\n};\n\nexport type SourceInfo = {\n name: string;\n filePath: string;\n methods: MethodInfo[];\n};\n\ntype VisitorContext = {\n exposedMethods: string[];\n className: string;\n methods: MethodInfo[];\n sourceFile: SourceFile;\n};\n\n/**\n * Extracts JSDoc comment from a method declaration.\n *\n * @param node - The method declaration node.\n * @param source - The source file.\n * @returns The JSDoc comment.\n */\nfunction extractJSDoc(node: MethodDeclaration, source: SourceFile): string {\n const jsDocTags = getJSDocCommentsAndTags(node);\n if (jsDocTags.length === 0) {\n return '';\n }\n\n const jsDoc = jsDocTags[0];\n if (isJSDoc(jsDoc)) {\n const fullText = source.getFullText();\n const start = jsDoc.getFullStart();\n const end = jsDoc.getEnd();\n const rawJsDoc = fullText.substring(start, end).trim();\n return formatJSDoc(rawJsDoc);\n }\n\n // istanbul ignore next: defensive check — getJSDocCommentsAndTags always returns JSDoc nodes\n return '';\n}\n\n/**\n * Formats JSDoc comments to have consistent indentation for the generated file.\n *\n * @param rawJsDoc - The raw JSDoc comment from the source.\n * @returns The formatted JSDoc comment.\n */\nfunction formatJSDoc(rawJsDoc: string): string {\n const lines = rawJsDoc.split('\\n');\n const formattedLines: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (i === 0) {\n formattedLines.push('/**');\n } else if (i === lines.length - 1) {\n formattedLines.push(' */');\n } else {\n const trimmed = line.trim();\n if (trimmed.startsWith('*')) {\n const content = trimmed.substring(1).trim();\n formattedLines.push(content ? ` * ${content}` : ' *');\n } else {\n formattedLines.push(trimmed ? ` * ${trimmed}` : ' *');\n }\n }\n }\n\n return formattedLines.join('\\n');\n}\n\n/**\n * Visits AST nodes to find exposed methods and controller/service class.\n *\n * @param context - The visitor context.\n * @returns A function to visit nodes.\n */\nfunction createASTVisitor(context: VisitorContext): (node: TSNode) => void {\n function visitNode(node: TSNode): void {\n if (isVariableStatement(node)) {\n const declaration = node.declarationList.declarations[0];\n if (\n isIdentifier(declaration.name) &&\n declaration.name.text === 'MESSENGER_EXPOSED_METHODS'\n ) {\n if (declaration.initializer) {\n let arrayExpression: ArrayLiteralExpression | undefined;\n\n if (isArrayLiteralExpression(declaration.initializer)) {\n arrayExpression = declaration.initializer;\n } else if (\n isAsExpression(declaration.initializer) &&\n isArrayLiteralExpression(declaration.initializer.expression)\n ) {\n arrayExpression = declaration.initializer.expression;\n }\n\n if (arrayExpression) {\n context.exposedMethods = arrayExpression.elements\n .filter(isStringLiteral)\n .map((element) => element.text);\n }\n }\n }\n }\n\n if (isClassDeclaration(node) && node.name) {\n const classText = node.name.text;\n if (classText.includes('Controller') || classText.includes('Service')) {\n context.className = classText;\n\n const seenMethods = new Set<string>();\n for (const member of node.members) {\n if (\n isMethodDeclaration(member) &&\n member.name &&\n isIdentifier(member.name)\n ) {\n const methodName = member.name.text;\n if (\n context.exposedMethods.includes(methodName) &&\n !seenMethods.has(methodName)\n ) {\n seenMethods.add(methodName);\n const jsDoc = extractJSDoc(member, context.sourceFile);\n context.methods.push({\n name: methodName,\n jsDoc,\n });\n }\n }\n }\n }\n }\n\n forEachChild(node, visitNode);\n }\n\n return visitNode;\n}\n\n/**\n * Create a TypeScript program for the given file by locating the nearest\n * tsconfig.json.\n *\n * @param filePath - Absolute path to the source file.\n * @returns A TypeScript program, or null if no tsconfig was found.\n */\nfunction createProgramForFile(filePath: string): Program | null {\n const configPath = findConfigFile(\n path.dirname(filePath),\n sys.fileExists.bind(sys),\n 'tsconfig.json',\n );\n if (!configPath) {\n return null;\n }\n\n const { config, error } = readConfigFile(configPath, sys.readFile.bind(sys));\n\n if (error) {\n return null;\n }\n\n const parsedConfig = parseJsonConfigFileContent(\n config,\n sys,\n path.dirname(configPath),\n );\n\n return createProgram({\n rootNames: parsedConfig.fileNames,\n options: parsedConfig.options,\n });\n}\n\n/**\n * Find a class declaration with the given name in a source file.\n *\n * @param source - The source file to search.\n * @param className - The class name to look for.\n * @returns The class declaration node, or null if not found.\n */\nfunction findClassInSourceFile(\n source: SourceFile,\n className: string,\n): ClassDeclaration | null {\n return (\n source.statements.find(\n (node): node is ClassDeclaration =>\n isClassDeclaration(node) && node.name?.text === className,\n ) ?? // istanbul ignore next: class is always found when called from parseSourceFile\n null\n );\n}\n\n/**\n * Search through the class hierarchy of a TypeScript type to find the\n * declaration of a method with the given name.\n *\n * @param classType - The class type to search.\n * @param methodName - The method name to look for.\n * @returns The method declaration node, or null if not found.\n */\nfunction findMethodInHierarchy(\n classType: Type,\n methodName: string,\n): MethodDeclaration | null {\n const symbol = classType.getProperty(methodName);\n if (!symbol) {\n return null;\n }\n\n const declarations = symbol.getDeclarations();\n // istanbul ignore next: defensive check — symbols from getProperty always have declarations\n if (!declarations) {\n return null;\n }\n\n for (const declaration of declarations) {\n if (isMethodDeclaration(declaration)) {\n return declaration;\n }\n }\n\n // istanbul ignore next: defensive fallback — property found but not a method declaration\n return null;\n}\n\n/**\n * Check if a path is a directory.\n *\n * @param pathValue - The path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nasync function isDirectory(pathValue: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(pathValue);\n return stats.isDirectory();\n } catch (error) {\n if (\n isObject(error) &&\n hasProperty(error, 'code') &&\n error.code === 'ENOENT'\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\n/**\n * Parses a source file to extract exposed methods and their metadata.\n *\n * @param filePath - Path to the controller/service file to parse.\n * @returns Source information or null if parsing fails.\n */\nexport async function parseSourceFile(\n filePath: string,\n): Promise<SourceInfo | null> {\n try {\n const content = await fs.promises.readFile(filePath, 'utf8');\n const source = createSourceFile(\n filePath,\n content,\n ScriptTarget.Latest,\n true,\n );\n\n const context: VisitorContext = {\n exposedMethods: [],\n className: '',\n methods: [],\n sourceFile: source,\n };\n\n createASTVisitor(context)(source);\n\n if (context.exposedMethods.length === 0 || !context.className) {\n return null;\n }\n\n const foundMethodNames = new Set(\n context.methods.map((method) => method.name),\n );\n\n const inheritedMethodNames = context.exposedMethods.filter(\n (name) => !foundMethodNames.has(name),\n );\n\n if (inheritedMethodNames.length > 0) {\n const program = createProgramForFile(filePath);\n const checker = program?.getTypeChecker();\n const programSourceFile = program?.getSourceFile(filePath);\n\n assert(\n checker,\n `Type checker could not be created for \"${filePath}\". Ensure a valid tsconfig.json is present.`,\n );\n\n assert(\n programSourceFile,\n `Source file \"${filePath}\" not found in program.`,\n );\n\n const classNode = findClassInSourceFile(\n programSourceFile,\n context.className,\n );\n\n assert(\n classNode,\n `Class \"${context.className}\" not found in \"${filePath}\".`,\n );\n\n const classType = checker.getTypeAtLocation(classNode);\n for (const methodName of inheritedMethodNames) {\n const methodDeclaration = findMethodInHierarchy(classType, methodName);\n\n const jsDoc = methodDeclaration\n ? extractJSDoc(methodDeclaration, methodDeclaration.getSourceFile())\n : '';\n context.methods.push({ name: methodName, jsDoc });\n }\n }\n\n return {\n name: context.className,\n filePath,\n methods: context.methods,\n };\n } catch (error) {\n console.error(`Error parsing ${filePath}:`, error);\n return null;\n }\n}\n\n/**\n * Finds all source files that have MESSENGER_EXPOSED_METHODS constants.\n *\n * @param sourcePath - Path to the folder where controllers/services are located.\n * @returns A list of source information objects.\n */\nexport async function findSourcesWithExposedMethods(\n sourcePath: string,\n): Promise<SourceInfo[]> {\n const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);\n const sources: SourceInfo[] = [];\n\n if (!(await isDirectory(srcPath))) {\n throw new Error(`The specified path is not a directory: ${srcPath}`);\n }\n\n const srcFiles = await fs.promises.readdir(srcPath);\n\n for (const file of srcFiles) {\n if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {\n continue;\n }\n\n const filePath = path.join(srcPath, file);\n const content = await fs.promises.readFile(filePath, 'utf8');\n\n if (content.includes('MESSENGER_EXPOSED_METHODS')) {\n const sourceInfo = await parseSourceFile(filePath);\n if (sourceInfo) {\n sources.push(sourceInfo);\n }\n }\n }\n\n return sources;\n}\n"]}
|
|
@@ -2,23 +2,23 @@ export type MethodInfo = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
jsDoc: string;
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type SourceInfo = {
|
|
6
6
|
name: string;
|
|
7
7
|
filePath: string;
|
|
8
8
|
methods: MethodInfo[];
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Parses a
|
|
11
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
12
12
|
*
|
|
13
|
-
* @param filePath - Path to the controller file to parse.
|
|
14
|
-
* @returns
|
|
13
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
14
|
+
* @returns Source information or null if parsing fails.
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function parseSourceFile(filePath: string): Promise<SourceInfo | null>;
|
|
17
17
|
/**
|
|
18
|
-
* Finds all
|
|
18
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @returns A list of
|
|
20
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
21
|
+
* @returns A list of source information objects.
|
|
22
22
|
*/
|
|
23
|
-
export declare function
|
|
23
|
+
export declare function findSourcesWithExposedMethods(sourcePath: string): Promise<SourceInfo[]>;
|
|
24
24
|
//# sourceMappingURL=parse-source.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-source.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"parse-source.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAsPF;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4E5B;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA2BvB"}
|
|
@@ -2,23 +2,23 @@ export type MethodInfo = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
jsDoc: string;
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type SourceInfo = {
|
|
6
6
|
name: string;
|
|
7
7
|
filePath: string;
|
|
8
8
|
methods: MethodInfo[];
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Parses a
|
|
11
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
12
12
|
*
|
|
13
|
-
* @param filePath - Path to the controller file to parse.
|
|
14
|
-
* @returns
|
|
13
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
14
|
+
* @returns Source information or null if parsing fails.
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function parseSourceFile(filePath: string): Promise<SourceInfo | null>;
|
|
17
17
|
/**
|
|
18
|
-
* Finds all
|
|
18
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @returns A list of
|
|
20
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
21
|
+
* @returns A list of source information objects.
|
|
22
22
|
*/
|
|
23
|
-
export declare function
|
|
23
|
+
export declare function findSourcesWithExposedMethods(sourcePath: string): Promise<SourceInfo[]>;
|
|
24
24
|
//# sourceMappingURL=parse-source.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-source.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"parse-source.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAsPF;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4E5B;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA2BvB"}
|
|
@@ -57,7 +57,7 @@ function formatJSDoc(rawJsDoc) {
|
|
|
57
57
|
return formattedLines.join('\n');
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Visits AST nodes to find exposed methods and controller class.
|
|
60
|
+
* Visits AST nodes to find exposed methods and controller/service class.
|
|
61
61
|
*
|
|
62
62
|
* @param context - The visitor context.
|
|
63
63
|
* @returns A function to visit nodes.
|
|
@@ -142,7 +142,7 @@ function createProgramForFile(filePath) {
|
|
|
142
142
|
* @returns The class declaration node, or null if not found.
|
|
143
143
|
*/
|
|
144
144
|
function findClassInSourceFile(source, className) {
|
|
145
|
-
return (source.statements.find((node) => isClassDeclaration(node) && node.name?.text === className) ?? // istanbul ignore next: class is always found when called from
|
|
145
|
+
return (source.statements.find((node) => isClassDeclaration(node) && node.name?.text === className) ?? // istanbul ignore next: class is always found when called from parseSourceFile
|
|
146
146
|
null);
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
@@ -192,12 +192,12 @@ async function isDirectory(pathValue) {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
|
-
* Parses a
|
|
195
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
196
196
|
*
|
|
197
|
-
* @param filePath - Path to the controller file to parse.
|
|
198
|
-
* @returns
|
|
197
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
198
|
+
* @returns Source information or null if parsing fails.
|
|
199
199
|
*/
|
|
200
|
-
export async function
|
|
200
|
+
export async function parseSourceFile(filePath) {
|
|
201
201
|
try {
|
|
202
202
|
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
203
203
|
const source = createSourceFile(filePath, content, ScriptTarget.Latest, true);
|
|
@@ -242,14 +242,14 @@ export async function parseControllerFile(filePath) {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
|
-
* Finds all
|
|
245
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
246
246
|
*
|
|
247
|
-
* @param
|
|
248
|
-
* @returns A list of
|
|
247
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
248
|
+
* @returns A list of source information objects.
|
|
249
249
|
*/
|
|
250
|
-
export async function
|
|
251
|
-
const srcPath = path.resolve(globalThis.process.cwd(),
|
|
252
|
-
const
|
|
250
|
+
export async function findSourcesWithExposedMethods(sourcePath) {
|
|
251
|
+
const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);
|
|
252
|
+
const sources = [];
|
|
253
253
|
if (!(await isDirectory(srcPath))) {
|
|
254
254
|
throw new Error(`The specified path is not a directory: ${srcPath}`);
|
|
255
255
|
}
|
|
@@ -261,12 +261,12 @@ export async function findControllersWithExposedMethods(controllerPath) {
|
|
|
261
261
|
const filePath = path.join(srcPath, file);
|
|
262
262
|
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
263
263
|
if (content.includes('MESSENGER_EXPOSED_METHODS')) {
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
266
|
-
|
|
264
|
+
const sourceInfo = await parseSourceFile(filePath);
|
|
265
|
+
if (sourceInfo) {
|
|
266
|
+
sources.push(sourceInfo);
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
return
|
|
270
|
+
return sources;
|
|
271
271
|
}
|
|
272
272
|
//# sourceMappingURL=parse-source.mjs.map
|