@hexaijs/plugin-contracts-generator 0.1.0

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +337 -0
  3. package/dist/ast-utils.d.ts +6 -0
  4. package/dist/ast-utils.d.ts.map +1 -0
  5. package/dist/ast-utils.js +111 -0
  6. package/dist/ast-utils.js.map +1 -0
  7. package/dist/class-analyzer.d.ts +16 -0
  8. package/dist/class-analyzer.d.ts.map +1 -0
  9. package/dist/class-analyzer.js +155 -0
  10. package/dist/class-analyzer.js.map +1 -0
  11. package/dist/cli.d.ts +36 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +321 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/config-loader.d.ts +34 -0
  16. package/dist/config-loader.d.ts.map +1 -0
  17. package/dist/config-loader.js +188 -0
  18. package/dist/config-loader.js.map +1 -0
  19. package/dist/decorators/index.d.ts +143 -0
  20. package/dist/decorators/index.d.ts.map +1 -0
  21. package/dist/decorators/index.js +123 -0
  22. package/dist/decorators/index.js.map +1 -0
  23. package/dist/domain/index.d.ts +2 -0
  24. package/dist/domain/index.d.ts.map +1 -0
  25. package/dist/domain/index.js +18 -0
  26. package/dist/domain/index.js.map +1 -0
  27. package/dist/domain/types.d.ts +182 -0
  28. package/dist/domain/types.d.ts.map +1 -0
  29. package/dist/domain/types.js +65 -0
  30. package/dist/domain/types.js.map +1 -0
  31. package/dist/errors.d.ts +79 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +138 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/file-copier.d.ts +85 -0
  36. package/dist/file-copier.d.ts.map +1 -0
  37. package/dist/file-copier.js +773 -0
  38. package/dist/file-copier.js.map +1 -0
  39. package/dist/file-graph-resolver.d.ts +47 -0
  40. package/dist/file-graph-resolver.d.ts.map +1 -0
  41. package/dist/file-graph-resolver.js +230 -0
  42. package/dist/file-graph-resolver.js.map +1 -0
  43. package/dist/file-system.d.ts +26 -0
  44. package/dist/file-system.d.ts.map +1 -0
  45. package/dist/file-system.js +34 -0
  46. package/dist/file-system.js.map +1 -0
  47. package/dist/hexai-plugin.d.ts +16 -0
  48. package/dist/hexai-plugin.d.ts.map +1 -0
  49. package/dist/hexai-plugin.js +59 -0
  50. package/dist/hexai-plugin.js.map +1 -0
  51. package/dist/import-analyzer.d.ts +6 -0
  52. package/dist/import-analyzer.d.ts.map +1 -0
  53. package/dist/import-analyzer.js +77 -0
  54. package/dist/import-analyzer.js.map +1 -0
  55. package/dist/index.d.ts +58 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +97 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/logger.d.ts +21 -0
  60. package/dist/logger.d.ts.map +1 -0
  61. package/dist/logger.js +47 -0
  62. package/dist/logger.js.map +1 -0
  63. package/dist/parser.d.ts +32 -0
  64. package/dist/parser.d.ts.map +1 -0
  65. package/dist/parser.js +209 -0
  66. package/dist/parser.js.map +1 -0
  67. package/dist/pipeline.d.ts +56 -0
  68. package/dist/pipeline.d.ts.map +1 -0
  69. package/dist/pipeline.js +152 -0
  70. package/dist/pipeline.js.map +1 -0
  71. package/dist/reexport-generator.d.ts +81 -0
  72. package/dist/reexport-generator.d.ts.map +1 -0
  73. package/dist/reexport-generator.js +208 -0
  74. package/dist/reexport-generator.js.map +1 -0
  75. package/dist/registry-generator.d.ts +27 -0
  76. package/dist/registry-generator.d.ts.map +1 -0
  77. package/dist/registry-generator.js +108 -0
  78. package/dist/registry-generator.js.map +1 -0
  79. package/dist/runtime/index.d.ts +2 -0
  80. package/dist/runtime/index.d.ts.map +1 -0
  81. package/dist/runtime/index.js +6 -0
  82. package/dist/runtime/index.js.map +1 -0
  83. package/dist/runtime/message-registry.d.ts +23 -0
  84. package/dist/runtime/message-registry.d.ts.map +1 -0
  85. package/dist/runtime/message-registry.js +39 -0
  86. package/dist/runtime/message-registry.js.map +1 -0
  87. package/dist/scanner.d.ts +21 -0
  88. package/dist/scanner.d.ts.map +1 -0
  89. package/dist/scanner.js +53 -0
  90. package/dist/scanner.js.map +1 -0
  91. package/dist/test-utils.d.ts +23 -0
  92. package/dist/test-utils.d.ts.map +1 -0
  93. package/dist/test-utils.js +198 -0
  94. package/dist/test-utils.js.map +1 -0
  95. package/dist/tsconfig-loader.d.ts +8 -0
  96. package/dist/tsconfig-loader.d.ts.map +1 -0
  97. package/dist/tsconfig-loader.js +64 -0
  98. package/dist/tsconfig-loader.js.map +1 -0
  99. package/package.json +79 -0
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContractsPipeline = void 0;
4
+ const path_1 = require("path");
5
+ const scanner_1 = require("./scanner");
6
+ const parser_1 = require("./parser");
7
+ const file_graph_resolver_1 = require("./file-graph-resolver");
8
+ const file_copier_1 = require("./file-copier");
9
+ const file_system_1 = require("./file-system");
10
+ const logger_1 = require("./logger");
11
+ const DEFAULT_EXCLUDE_DEPENDENCIES = [
12
+ "**/*.test.ts",
13
+ "**/*.spec.ts",
14
+ "**/*.eh.ts",
15
+ "**/db.ts",
16
+ "**/infra/**",
17
+ ];
18
+ class ContractsPipeline {
19
+ deps;
20
+ messageTypes;
21
+ constructor(deps, messageTypes) {
22
+ this.deps = deps;
23
+ this.messageTypes = messageTypes;
24
+ }
25
+ static async create(options = {}) {
26
+ const fileSystem = options.fileSystem ?? file_system_1.nodeFileSystem;
27
+ const logger = options.logger ?? logger_1.noopLogger;
28
+ const excludeDependencies = options.excludeDependencies ?? DEFAULT_EXCLUDE_DEPENDENCIES;
29
+ const scanner = new scanner_1.Scanner({ fileSystem, messageTypes: options.messageTypes });
30
+ const parser = new parser_1.Parser({
31
+ responseNamingConventions: options.responseNamingConventions,
32
+ messageTypes: options.messageTypes,
33
+ });
34
+ const fileGraphResolver = await file_graph_resolver_1.FileGraphResolver.create({
35
+ tsconfigPath: options.tsconfigPath,
36
+ fileSystem,
37
+ excludeDependencies,
38
+ });
39
+ const fileCopier = new file_copier_1.FileCopier({ fileSystem });
40
+ return new ContractsPipeline({
41
+ scanner,
42
+ parser,
43
+ fileGraphResolver,
44
+ fileCopier,
45
+ fileSystem,
46
+ logger,
47
+ }, options.messageTypes);
48
+ }
49
+ static fromDependencies(deps) {
50
+ return new ContractsPipeline(deps);
51
+ }
52
+ async execute(options) {
53
+ const { contextName, sourceDir, outputDir, pathAliasRewrites, removeDecorators } = options;
54
+ const contextOutputDir = (0, path_1.join)(outputDir, contextName);
55
+ this.deps.logger.info(`Processing context: ${contextName}`);
56
+ this.deps.logger.debug(` Source: ${sourceDir}`);
57
+ this.deps.logger.debug(` Output: ${contextOutputDir}`);
58
+ const decoratedFiles = await this.scan(sourceDir);
59
+ const messages = await this.parse(decoratedFiles, sourceDir);
60
+ const fileGraph = await this.resolve(decoratedFiles, sourceDir);
61
+ const responseTypesToExport = this.collectResponseTypesToExport(messages);
62
+ const copiedFiles = await this.copy(fileGraph, sourceDir, contextOutputDir, pathAliasRewrites, responseTypesToExport, removeDecorators, this.messageTypes);
63
+ await this.exportBarrel(copiedFiles, contextOutputDir);
64
+ this.deps.logger.info(`Completed context: ${contextName} (${messages.events.length} events, ${messages.commands.length} commands, ${messages.queries.length} queries, ${copiedFiles.length} files)`);
65
+ return {
66
+ events: messages.events,
67
+ commands: messages.commands,
68
+ queries: messages.queries,
69
+ copiedFiles,
70
+ };
71
+ }
72
+ collectResponseTypesToExport(messages) {
73
+ const result = new Map();
74
+ const allMessages = [...messages.commands, ...messages.queries];
75
+ for (const message of allMessages) {
76
+ if (message.resultType?.kind !== "reference")
77
+ continue;
78
+ const typeName = message.resultType.name;
79
+ const sourceFile = message.sourceFile.absolutePath;
80
+ // Check if this type exists and is not exported
81
+ const typeDef = messages.typeDefinitions.find((t) => t.name === typeName &&
82
+ t.sourceFile.absolutePath === sourceFile &&
83
+ !t.exported);
84
+ if (typeDef) {
85
+ const existing = result.get(sourceFile) ?? [];
86
+ if (!existing.includes(typeName)) {
87
+ existing.push(typeName);
88
+ result.set(sourceFile, existing);
89
+ }
90
+ }
91
+ }
92
+ if (result.size > 0) {
93
+ this.deps.logger.debug(`Found ${result.size} file(s) with unexported response types`);
94
+ }
95
+ return result;
96
+ }
97
+ async scan(sourceDir) {
98
+ this.deps.logger.debug(`Scanning for decorated files in ${sourceDir}`);
99
+ const files = await this.deps.scanner.scan(sourceDir);
100
+ this.deps.logger.debug(`Found ${files.length} decorated file(s)`);
101
+ return files;
102
+ }
103
+ async parse(files, sourceRoot) {
104
+ this.deps.logger.debug(`Parsing ${files.length} file(s)`);
105
+ const events = [];
106
+ const commands = [];
107
+ const queries = [];
108
+ const typeDefinitions = [];
109
+ for (const file of files) {
110
+ const content = await this.deps.fileSystem.readFile(file);
111
+ const sourceFileInfo = {
112
+ absolutePath: file,
113
+ relativePath: (0, path_1.relative)(sourceRoot, file),
114
+ };
115
+ const result = this.deps.parser.parse(content, sourceFileInfo);
116
+ events.push(...result.events);
117
+ commands.push(...result.commands);
118
+ queries.push(...result.queries);
119
+ typeDefinitions.push(...result.typeDefinitions);
120
+ }
121
+ this.deps.logger.debug(`Parsed ${events.length} event(s), ${commands.length} command(s), ${queries.length} query(s), ${typeDefinitions.length} type(s)`);
122
+ return { events, commands, queries, typeDefinitions };
123
+ }
124
+ async resolve(entryPoints, sourceRoot) {
125
+ this.deps.logger.debug(`Resolving dependencies for ${entryPoints.length} entry point(s)`);
126
+ const graph = await this.deps.fileGraphResolver.buildGraph(entryPoints, sourceRoot);
127
+ this.deps.logger.debug(`Resolved ${graph.nodes.size} file(s) in dependency graph`);
128
+ return graph;
129
+ }
130
+ async copy(fileGraph, sourceRoot, outputDir, pathAliasRewrites, responseTypesToExport, removeDecorators, messageTypes) {
131
+ this.deps.logger.debug(`Copying files to ${outputDir}`);
132
+ await this.deps.fileSystem.mkdir(outputDir, { recursive: true });
133
+ const result = await this.deps.fileCopier.copyFiles({
134
+ sourceRoot,
135
+ outputDir,
136
+ fileGraph,
137
+ pathAliasRewrites,
138
+ responseTypesToExport,
139
+ removeDecorators,
140
+ messageTypes,
141
+ });
142
+ this.deps.logger.debug(`Copied ${result.copiedFiles.length} file(s)`);
143
+ return result.copiedFiles;
144
+ }
145
+ async exportBarrel(copiedFiles, outputDir) {
146
+ this.deps.logger.debug(`Generating barrel export at ${outputDir}/index.ts`);
147
+ const indexContent = this.deps.fileCopier.generateBarrelExport(copiedFiles, outputDir);
148
+ await this.deps.fileSystem.writeFile((0, path_1.join)(outputDir, "index.ts"), indexContent);
149
+ }
150
+ }
151
+ exports.ContractsPipeline = ContractsPipeline;
152
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":";;;AAAA,+BAAsC;AACtC,uCAAoC;AACpC,qCAAkC;AAClC,+DAA0E;AAC1E,+CAA2C;AAE3C,+CAAgE;AAChE,qCAAmD;AAEnD,MAAM,4BAA4B,GAAG;IACjC,cAAc;IACd,cAAc;IACd,YAAY;IACZ,UAAU;IACV,aAAa;CAChB,CAAC;AAiCF,MAAa,iBAAiB;IAIL;IAHJ,YAAY,CAA0B;IAEvD,YACqB,IAA0B,EAC3C,YAAqC;QADpB,SAAI,GAAJ,IAAI,CAAsB;QAG3C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAOhB,EAAE;QACF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,4BAAc,CAAC;QACxD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,mBAAU,CAAC;QAC5C,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,4BAA4B,CAAC;QACxF,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,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,EAAC,SAAS,EAAE,UAAU,CAAC,EAAE,YAAY,CAAC,CAAC;IACpF,CAAC;CACJ;AAlLD,8CAkLC"}
@@ -0,0 +1,81 @@
1
+ import { FileSystem } from "./file-system";
2
+ /**
3
+ * Represents an import that was rewritten via pathAliasRewrites
4
+ */
5
+ export interface RewrittenImport {
6
+ /** The rewritten module specifier (e.g., "@libera/contracts/common/request") */
7
+ readonly rewrittenPath: string;
8
+ /** The original module specifier before rewrite (e.g., "@libera/common/request") */
9
+ readonly originalPath: string;
10
+ /** The imported symbol names */
11
+ readonly symbols: readonly string[];
12
+ /** Whether this is a type-only import */
13
+ readonly isTypeOnly: boolean;
14
+ }
15
+ /**
16
+ * Represents a re-export file to be generated
17
+ */
18
+ export interface ReexportFile {
19
+ /** Relative path within contracts output dir (e.g., "common/request.ts") */
20
+ readonly relativePath: string;
21
+ /** The original module to re-export from */
22
+ readonly originalModule: string;
23
+ /** Symbols to re-export */
24
+ readonly symbols: readonly string[];
25
+ /** Whether all symbols are type-only */
26
+ readonly isTypeOnly: boolean;
27
+ }
28
+ export interface ReexportGeneratorOptions {
29
+ fileSystem?: FileSystem;
30
+ }
31
+ export interface AnalyzeOptions {
32
+ /** The files to analyze (absolute paths) */
33
+ readonly files: readonly string[];
34
+ /** Map of original path prefix -> rewritten path prefix */
35
+ readonly pathAliasRewrites: ReadonlyMap<string, string>;
36
+ }
37
+ export interface GenerateOptions {
38
+ /** The output directory for re-export files */
39
+ readonly outputDir: string;
40
+ /** The re-export files to generate */
41
+ readonly reexportFiles: readonly ReexportFile[];
42
+ }
43
+ /**
44
+ * Generates re-export files for pathAliasRewrites
45
+ */
46
+ export declare class ReexportGenerator {
47
+ private readonly fs;
48
+ constructor(options?: ReexportGeneratorOptions);
49
+ /**
50
+ * Analyzes files to find imports that match pathAliasRewrites
51
+ * and groups them by rewritten path
52
+ */
53
+ analyze(options: AnalyzeOptions): Promise<ReexportFile[]>;
54
+ /**
55
+ * Generates re-export files
56
+ */
57
+ generate(options: GenerateOptions): Promise<string[]>;
58
+ /**
59
+ * Extracts imports from source content that match rewritten prefixes
60
+ */
61
+ private extractRewrittenImports;
62
+ /**
63
+ * Extracts symbol names from import clause
64
+ */
65
+ private extractSymbolNames;
66
+ /**
67
+ * Groups imports by rewritten path and merges symbols
68
+ */
69
+ private groupImportsByPath;
70
+ /**
71
+ * Converts a rewritten package path to a relative file path
72
+ * e.g., "@libera/contracts/common/request" with prefix "@libera/contracts"
73
+ * -> "common/request.ts"
74
+ */
75
+ private rewrittenPathToRelativePath;
76
+ /**
77
+ * Generates the content for a re-export file
78
+ */
79
+ private generateReexportContent;
80
+ }
81
+ //# sourceMappingURL=reexport-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reexport-generator.d.ts","sourceRoot":"","sources":["../src/reexport-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAkB,MAAM,eAAe,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,4CAA4C;IAC5C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,2BAA2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB;IACrC,UAAU,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC3B,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,2DAA2D;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,eAAe;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;CACnD;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAa;gBAEpB,OAAO,GAAE,wBAA6B;IAIlD;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAsB/D;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB3D;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA4C/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA2C1B;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAwBnC;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAKlC"}
@@ -0,0 +1,208 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ReexportGenerator = void 0;
37
+ const ts = __importStar(require("typescript"));
38
+ const path = __importStar(require("path"));
39
+ const file_system_1 = require("./file-system");
40
+ /**
41
+ * Generates re-export files for pathAliasRewrites
42
+ */
43
+ class ReexportGenerator {
44
+ fs;
45
+ constructor(options = {}) {
46
+ this.fs = options.fileSystem ?? file_system_1.nodeFileSystem;
47
+ }
48
+ /**
49
+ * Analyzes files to find imports that match pathAliasRewrites
50
+ * and groups them by rewritten path
51
+ */
52
+ async analyze(options) {
53
+ const { files, pathAliasRewrites } = options;
54
+ // Invert the map: rewritten prefix -> original prefix
55
+ const rewrittenToOriginal = new Map();
56
+ for (const [original, rewritten] of pathAliasRewrites) {
57
+ rewrittenToOriginal.set(rewritten, original);
58
+ }
59
+ // Collect all rewritten imports across all files
60
+ const allImports = [];
61
+ for (const file of files) {
62
+ const content = await this.fs.readFile(file);
63
+ const imports = this.extractRewrittenImports(content, rewrittenToOriginal);
64
+ allImports.push(...imports);
65
+ }
66
+ // Group by rewritten path and merge symbols
67
+ return this.groupImportsByPath(allImports);
68
+ }
69
+ /**
70
+ * Generates re-export files
71
+ */
72
+ async generate(options) {
73
+ const { outputDir, reexportFiles } = options;
74
+ const generatedFiles = [];
75
+ for (const reexport of reexportFiles) {
76
+ const filePath = path.join(outputDir, reexport.relativePath);
77
+ const content = this.generateReexportContent(reexport);
78
+ await this.fs.mkdir(path.dirname(filePath), { recursive: true });
79
+ await this.fs.writeFile(filePath, content);
80
+ generatedFiles.push(filePath);
81
+ }
82
+ return generatedFiles;
83
+ }
84
+ /**
85
+ * Extracts imports from source content that match rewritten prefixes
86
+ */
87
+ extractRewrittenImports(content, rewrittenToOriginal) {
88
+ const sourceFile = ts.createSourceFile("temp.ts", content, ts.ScriptTarget.Latest, true);
89
+ const imports = [];
90
+ ts.forEachChild(sourceFile, (node) => {
91
+ if (!ts.isImportDeclaration(node) || !node.importClause) {
92
+ return;
93
+ }
94
+ const moduleSpecifier = node.moduleSpecifier.text;
95
+ // Check if this import matches any rewritten prefix
96
+ for (const [rewrittenPrefix, originalPrefix] of rewrittenToOriginal) {
97
+ if (moduleSpecifier.startsWith(rewrittenPrefix)) {
98
+ const symbols = this.extractSymbolNames(node.importClause);
99
+ if (symbols.length > 0) {
100
+ // Calculate the original path
101
+ const suffix = moduleSpecifier.slice(rewrittenPrefix.length);
102
+ const originalPath = originalPrefix + suffix;
103
+ imports.push({
104
+ rewrittenPath: moduleSpecifier,
105
+ originalPath,
106
+ symbols,
107
+ isTypeOnly: node.importClause.isTypeOnly ?? false,
108
+ });
109
+ }
110
+ break;
111
+ }
112
+ }
113
+ });
114
+ return imports;
115
+ }
116
+ /**
117
+ * Extracts symbol names from import clause
118
+ */
119
+ extractSymbolNames(importClause) {
120
+ const names = [];
121
+ // Default import
122
+ if (importClause.name) {
123
+ names.push(importClause.name.text);
124
+ }
125
+ // Named imports
126
+ if (importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
127
+ for (const element of importClause.namedBindings.elements) {
128
+ // Use the original name if aliased, otherwise use the imported name
129
+ const originalName = element.propertyName?.text ?? element.name.text;
130
+ names.push(originalName);
131
+ }
132
+ }
133
+ return names;
134
+ }
135
+ /**
136
+ * Groups imports by rewritten path and merges symbols
137
+ */
138
+ groupImportsByPath(imports) {
139
+ const grouped = new Map();
140
+ for (const imp of imports) {
141
+ const existing = grouped.get(imp.rewrittenPath);
142
+ if (existing) {
143
+ for (const symbol of imp.symbols) {
144
+ existing.symbols.add(symbol);
145
+ }
146
+ if (!imp.isTypeOnly) {
147
+ existing.hasValueImport = true;
148
+ }
149
+ }
150
+ else {
151
+ grouped.set(imp.rewrittenPath, {
152
+ originalPath: imp.originalPath,
153
+ symbols: new Set(imp.symbols),
154
+ hasValueImport: !imp.isTypeOnly,
155
+ });
156
+ }
157
+ }
158
+ // Convert to ReexportFile array
159
+ const result = [];
160
+ for (const [rewrittenPath, data] of grouped) {
161
+ // Convert rewritten package path to relative file path
162
+ // e.g., "@libera/contracts/common/request" -> "common/request.ts"
163
+ const relativePath = this.rewrittenPathToRelativePath(rewrittenPath);
164
+ result.push({
165
+ relativePath,
166
+ originalModule: data.originalPath,
167
+ symbols: Array.from(data.symbols).sort(),
168
+ isTypeOnly: !data.hasValueImport,
169
+ });
170
+ }
171
+ return result.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
172
+ }
173
+ /**
174
+ * Converts a rewritten package path to a relative file path
175
+ * e.g., "@libera/contracts/common/request" with prefix "@libera/contracts"
176
+ * -> "common/request.ts"
177
+ */
178
+ rewrittenPathToRelativePath(rewrittenPath) {
179
+ // Find the subpath after the package name
180
+ // Assume format: @scope/package/subpath or package/subpath
181
+ const parts = rewrittenPath.split("/");
182
+ let subpathStart;
183
+ if (parts[0].startsWith("@")) {
184
+ // Scoped package: @scope/package/subpath
185
+ subpathStart = 2;
186
+ }
187
+ else {
188
+ // Regular package: package/subpath
189
+ subpathStart = 1;
190
+ }
191
+ const subpath = parts.slice(subpathStart).join("/");
192
+ // If no subpath, use index.ts
193
+ if (!subpath) {
194
+ return "index.ts";
195
+ }
196
+ return subpath + ".ts";
197
+ }
198
+ /**
199
+ * Generates the content for a re-export file
200
+ */
201
+ generateReexportContent(reexport) {
202
+ const exportKeyword = reexport.isTypeOnly ? "export type" : "export";
203
+ const symbols = reexport.symbols.join(", ");
204
+ return `${exportKeyword} { ${symbols} } from "${reexport.originalModule}";\n`;
205
+ }
206
+ }
207
+ exports.ReexportGenerator = ReexportGenerator;
208
+ //# sourceMappingURL=reexport-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reexport-generator.js","sourceRoot":"","sources":["../src/reexport-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,2CAA6B;AAE7B,+CAA2D;AAgD3D;;GAEG;AACH,MAAa,iBAAiB;IACT,EAAE,CAAa;IAEhC,YAAY,UAAoC,EAAE;QAC9C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,UAAU,IAAI,4BAAc,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,OAAuB;QACjC,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;QAE7C,sDAAsD;QACtD,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAC;QACtD,KAAK,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,iBAAiB,EAAE,CAAC;YACpD,mBAAmB,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACjD,CAAC;QAED,iDAAiD;QACjD,MAAM,UAAU,GAAsB,EAAE,CAAC;QAEzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;YAC3E,UAAU,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAChC,CAAC;QAED,4CAA4C;QAC5C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istryImport: string;
4
+ readonly useNamespace?: boolean;
5
+ }
6
+ export interface ContextMessages {
7
+ readonly contextName: string;
8
+ readonly events: readonly DomainEvent[];
9
+ readonly commands: readonly Command[];
10
+ readonly queries?: readonly Query[];
11
+ readonly importPath?: string;
12
+ }
13
+ export declare class RegistryGenerator {
14
+ private readonly options;
15
+ constructor(options?: Partial<RegistryGeneratorOptions>);
16
+ generate(contexts: readonly ContextMessages[]): string;
17
+ private generateEmptyRegistry;
18
+ private generateWithNamespace;
19
+ private getNamespaceInfos;
20
+ private generateNamespaceImports;
21
+ private generateNamespaceExports;
22
+ private generateNamespaceRegistrations;
23
+ private toNamespace;
24
+ private generateImports;
25
+ private generateRegistrations;
26
+ }
27
+ //# sourceMappingURL=registry-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-generator.d.ts","sourceRoot":"","sources":["../src/registry-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIlE,MAAM,WAAW,wBAAwB;IACrC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAChC;AAkBD,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;gBAEvC,OAAO,GAAE,OAAO,CAAC,wBAAwB,CAAM;IAI3D,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM;IA2BtD,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,qBAAqB;IAkB7B,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,wBAAwB;IAWhC,OAAO,CAAC,8BAA8B;IAUtC,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,qBAAqB;CAQhC"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegistryGenerator = void 0;
4
+ const DEFAULT_OPTIONS = {
5
+ messageRegistryImport: "@hexaijs/plugin-contracts-generator/runtime",
6
+ };
7
+ function hasMessages(ctx) {
8
+ return (ctx.events.length > 0 ||
9
+ ctx.commands.length > 0 ||
10
+ (ctx.queries?.length ?? 0) > 0);
11
+ }
12
+ function getAllMessages(ctx) {
13
+ return [...ctx.events, ...ctx.commands, ...(ctx.queries ?? [])];
14
+ }
15
+ class RegistryGenerator {
16
+ options;
17
+ constructor(options = {}) {
18
+ this.options = { ...DEFAULT_OPTIONS, ...options };
19
+ }
20
+ generate(contexts) {
21
+ const allMessages = contexts.flatMap((ctx) => getAllMessages(ctx).map((message) => ({
22
+ message,
23
+ contextName: ctx.contextName,
24
+ })));
25
+ if (allMessages.length === 0) {
26
+ return this.generateEmptyRegistry();
27
+ }
28
+ if (this.options.useNamespace) {
29
+ return this.generateWithNamespace(contexts, allMessages);
30
+ }
31
+ const imports = this.generateImports(contexts);
32
+ const registrations = this.generateRegistrations(allMessages);
33
+ return [
34
+ imports,
35
+ "",
36
+ "export const messageRegistry = new MessageRegistry()",
37
+ registrations,
38
+ ].join("\n");
39
+ }
40
+ generateEmptyRegistry() {
41
+ return [
42
+ `import { MessageRegistry } from "${this.options.messageRegistryImport}";`,
43
+ "",
44
+ "export const messageRegistry = new MessageRegistry();",
45
+ "",
46
+ ].join("\n");
47
+ }
48
+ generateWithNamespace(contexts, allMessages) {
49
+ const imports = this.generateNamespaceImports(contexts);
50
+ const exports = this.generateNamespaceExports(contexts);
51
+ const registrations = this.generateNamespaceRegistrations(allMessages);
52
+ return [
53
+ imports,
54
+ "",
55
+ exports,
56
+ "",
57
+ "export const messageRegistry = new MessageRegistry()",
58
+ registrations,
59
+ ].join("\n");
60
+ }
61
+ getNamespaceInfos(contexts) {
62
+ return contexts.filter(hasMessages).map((ctx) => ({
63
+ importPath: ctx.importPath ?? `./${ctx.contextName}`,
64
+ namespace: this.toNamespace(ctx.contextName),
65
+ }));
66
+ }
67
+ generateNamespaceImports(contexts) {
68
+ return [
69
+ `import { MessageRegistry } from "${this.options.messageRegistryImport}";`,
70
+ ...this.getNamespaceInfos(contexts).map(({ importPath, namespace }) => `import * as ${namespace} from "${importPath}";`),
71
+ ].join("\n");
72
+ }
73
+ generateNamespaceExports(contexts) {
74
+ return this.getNamespaceInfos(contexts)
75
+ .map(({ importPath, namespace }) => `export * as ${namespace} from "${importPath}";`)
76
+ .join("\n");
77
+ }
78
+ generateNamespaceRegistrations(messages) {
79
+ const lines = messages.map(({ message, contextName }) => {
80
+ const namespace = this.toNamespace(contextName);
81
+ return ` .register(${namespace}.${message.name})`;
82
+ });
83
+ return lines.join("\n") + ";\n";
84
+ }
85
+ toNamespace(contextName) {
86
+ // kebab-case to camelCase
87
+ return contextName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
88
+ }
89
+ generateImports(contexts) {
90
+ const lines = [
91
+ `import { MessageRegistry } from "${this.options.messageRegistryImport}";`,
92
+ ];
93
+ for (const ctx of contexts) {
94
+ const messageNames = getAllMessages(ctx).map((m) => m.name);
95
+ if (messageNames.length > 0) {
96
+ const importPath = ctx.importPath ?? `./${ctx.contextName}`;
97
+ lines.push(`import { ${messageNames.join(", ")} } from "${importPath}";`);
98
+ }
99
+ }
100
+ return lines.join("\n");
101
+ }
102
+ generateRegistrations(messages) {
103
+ const lines = messages.map(({ message }) => ` .register(${message.name})`);
104
+ return lines.join("\n") + ";\n";
105
+ }
106
+ }
107
+ exports.RegistryGenerator = RegistryGenerator;
108
+ //# sourceMappingURL=registry-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-generator.js","sourceRoot":"","sources":["../src/registry-generator.ts"],"names":[],"mappings":";;;AAiBA,MAAM,eAAe,GAA6B;IAC9C,qBAAqB,EAAE,6CAA6C;CACvE,CAAC;AAEF,SAAS,WAAW,CAAC,GAAoB;IACrC,OAAO,CACH,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QACrB,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QACvB,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CACjC,CAAC;AACN,CAAC;AAED,SAAS,cAAc,CAAC,GAAoB;IACxC,OAAO,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAa,iBAAiB;IACT,OAAO,CAA2B;IAEnD,YAAY,UAA6C,EAAE;QACvD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IACtD,CAAC;IAED,QAAQ,CAAC,QAAoC;QACzC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CACzC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAClC,OAAO;YACP,WAAW,EAAE,GAAG,CAAC,WAAW;SAC/B,CAAC,CAAC,CACN,CAAC;QAEF,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACxC,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY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MAAM,YAAY,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAE5D,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;gBAC5D,KAAK,CAAC,IAAI,CACN,YAAY,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,UAAU,IAAI,CAChE,CAAC;YACN,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEO,qBAAqB,CACzB,QAA8D;QAE9D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CACtB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,iBAAiB,OAAO,CAAC,IAAI,GAAG,CACpD,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACpC,CAAC;CACJ;AAzID,8CAyIC"}
@@ -0,0 +1,2 @@
1
+ export { MessageRegistry, type MessageClass, type MessageHeaders, } from "./message-registry";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,cAAc,GACtB,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageRegistry = void 0;
4
+ var message_registry_1 = require("./message-registry");
5
+ Object.defineProperty(exports, "MessageRegistry", { enumerable: true, get: function () { return message_registry_1.MessageRegistry; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":";;;AAAA,uDAI4B;AAHxB,mHAAA,eAAe,OAAA"}
@@ -0,0 +1,23 @@
1
+ type Version = string | number | undefined;
2
+ export interface MessageHeaders {
3
+ id: string;
4
+ type: string;
5
+ schemaVersion?: Version;
6
+ createdAt: Date;
7
+ [key: string]: unknown;
8
+ }
9
+ export interface MessageClass<T = any> {
10
+ getSchemaVersion(): Version;
11
+ getType(): string;
12
+ from(rawPayload: Record<string, unknown>, header?: MessageHeaders): T;
13
+ new (payload: any, headers?: any): T;
14
+ }
15
+ export declare class MessageRegistry {
16
+ private readonly registry;
17
+ register(messageClass: MessageClass): this;
18
+ dehydrate<T>(header: MessageHeaders, body: Record<string, unknown>): T;
19
+ has(type: string, version?: Version): boolean;
20
+ size(): number;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=message-registry.d.ts.map