@hexaijs/plugin-contracts-generator 0.1.1 → 0.2.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/README.md +5 -2
  2. package/dist/cli-CPg-O4OY.d.ts +214 -0
  3. package/dist/cli.d.ts +1 -35
  4. package/dist/cli.js +2479 -232
  5. package/dist/cli.js.map +1 -1
  6. package/dist/decorators/index.d.ts +12 -11
  7. package/dist/decorators/index.js +21 -116
  8. package/dist/decorators/index.js.map +1 -1
  9. package/dist/index.d.ts +533 -40
  10. package/dist/index.js +2738 -91
  11. package/dist/index.js.map +1 -1
  12. package/dist/runtime/index.d.ts +23 -2
  13. package/dist/runtime/index.js +38 -5
  14. package/dist/runtime/index.js.map +1 -1
  15. package/package.json +10 -14
  16. package/dist/ast-utils.d.ts +0 -6
  17. package/dist/ast-utils.d.ts.map +0 -1
  18. package/dist/ast-utils.js +0 -111
  19. package/dist/ast-utils.js.map +0 -1
  20. package/dist/class-analyzer.d.ts +0 -16
  21. package/dist/class-analyzer.d.ts.map +0 -1
  22. package/dist/class-analyzer.js +0 -155
  23. package/dist/class-analyzer.js.map +0 -1
  24. package/dist/cli.d.ts.map +0 -1
  25. package/dist/config-loader.d.ts +0 -34
  26. package/dist/config-loader.d.ts.map +0 -1
  27. package/dist/config-loader.js +0 -188
  28. package/dist/config-loader.js.map +0 -1
  29. package/dist/decorators/index.d.ts.map +0 -1
  30. package/dist/domain/index.d.ts +0 -2
  31. package/dist/domain/index.d.ts.map +0 -1
  32. package/dist/domain/index.js +0 -18
  33. package/dist/domain/index.js.map +0 -1
  34. package/dist/domain/types.d.ts +0 -182
  35. package/dist/domain/types.d.ts.map +0 -1
  36. package/dist/domain/types.js +0 -65
  37. package/dist/domain/types.js.map +0 -1
  38. package/dist/errors.d.ts +0 -79
  39. package/dist/errors.d.ts.map +0 -1
  40. package/dist/errors.js +0 -138
  41. package/dist/errors.js.map +0 -1
  42. package/dist/file-copier.d.ts +0 -84
  43. package/dist/file-copier.d.ts.map +0 -1
  44. package/dist/file-copier.js +0 -758
  45. package/dist/file-copier.js.map +0 -1
  46. package/dist/file-graph-resolver.d.ts +0 -47
  47. package/dist/file-graph-resolver.d.ts.map +0 -1
  48. package/dist/file-graph-resolver.js +0 -230
  49. package/dist/file-graph-resolver.js.map +0 -1
  50. package/dist/file-system.d.ts +0 -26
  51. package/dist/file-system.d.ts.map +0 -1
  52. package/dist/file-system.js +0 -34
  53. package/dist/file-system.js.map +0 -1
  54. package/dist/hexai-plugin.d.ts +0 -16
  55. package/dist/hexai-plugin.d.ts.map +0 -1
  56. package/dist/hexai-plugin.js +0 -59
  57. package/dist/hexai-plugin.js.map +0 -1
  58. package/dist/import-analyzer.d.ts +0 -6
  59. package/dist/import-analyzer.d.ts.map +0 -1
  60. package/dist/import-analyzer.js +0 -77
  61. package/dist/import-analyzer.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/logger.d.ts +0 -21
  64. package/dist/logger.d.ts.map +0 -1
  65. package/dist/logger.js +0 -47
  66. package/dist/logger.js.map +0 -1
  67. package/dist/parser.d.ts +0 -32
  68. package/dist/parser.d.ts.map +0 -1
  69. package/dist/parser.js +0 -209
  70. package/dist/parser.js.map +0 -1
  71. package/dist/pipeline.d.ts +0 -56
  72. package/dist/pipeline.d.ts.map +0 -1
  73. package/dist/pipeline.js +0 -152
  74. package/dist/pipeline.js.map +0 -1
  75. package/dist/reexport-generator.d.ts +0 -81
  76. package/dist/reexport-generator.d.ts.map +0 -1
  77. package/dist/reexport-generator.js +0 -208
  78. package/dist/reexport-generator.js.map +0 -1
  79. package/dist/registry-generator.d.ts +0 -27
  80. package/dist/registry-generator.d.ts.map +0 -1
  81. package/dist/registry-generator.js +0 -108
  82. package/dist/registry-generator.js.map +0 -1
  83. package/dist/runtime/index.d.ts.map +0 -1
  84. package/dist/runtime/message-registry.d.ts +0 -23
  85. package/dist/runtime/message-registry.d.ts.map +0 -1
  86. package/dist/runtime/message-registry.js +0 -39
  87. package/dist/runtime/message-registry.js.map +0 -1
  88. package/dist/scanner.d.ts +0 -21
  89. package/dist/scanner.d.ts.map +0 -1
  90. package/dist/scanner.js +0 -53
  91. package/dist/scanner.js.map +0 -1
  92. package/dist/test-utils.d.ts +0 -23
  93. package/dist/test-utils.d.ts.map +0 -1
  94. package/dist/test-utils.js +0 -198
  95. package/dist/test-utils.js.map +0 -1
  96. package/dist/tsconfig-loader.d.ts +0 -8
  97. package/dist/tsconfig-loader.d.ts.map +0 -1
  98. package/dist/tsconfig-loader.js +0 -64
  99. package/dist/tsconfig-loader.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,43 +1,536 @@
1
+ import { D as DecoratorNames, M as MessageType, R as ResponseNamingConvention, S as SourceFile, a as DomainEvent, C as Command, Q as Query, T as TypeDefinition, b as ContractsPluginConfig } from './cli-CPg-O4OY.js';
2
+ export { A as ArrayType, c as ClassDefinition, d as ClassImport, e as Config, f as Dependency, g as DependencyKind, E as EnumDefinition, h as EnumMember, i as ExtractionError, j as ExtractionResult, k as ExtractionWarning, F as Field, l as FunctionParameter, m as FunctionType, I as ImportSource, n as IntersectionType, L as LiteralType, o as Message, p as MessageBase, O as ObjectType, P as PrimitiveType, q as ReferenceType, r as TupleType, s as TypeDefinitionKind, t as TypeRef, U as UnionType, u as isArrayType, v as isCommand, w as isDomainEvent, x as isFunctionType, y as isIntersectionType, z as isLiteralType, B as isObjectType, G as isPrimitiveType, H as isReferenceType, J as isTupleType, K as isUnionType } from './cli-CPg-O4OY.js';
3
+ export { PublicCommand, PublicCommandOptions, PublicEvent, PublicEventOptions, PublicQuery, PublicQueryOptions } from './decorators/index.js';
4
+ import { HexaiCliPlugin } from '@hexaijs/cli';
5
+
6
+ interface FileStats {
7
+ isDirectory(): boolean;
8
+ isFile(): boolean;
9
+ }
10
+ interface FileSystem {
11
+ readFile(path: string): Promise<string>;
12
+ readdir(path: string): Promise<string[]>;
13
+ writeFile(path: string, content: string): Promise<void>;
14
+ mkdir(path: string, options?: {
15
+ recursive?: boolean;
16
+ }): Promise<void>;
17
+ exists(path: string): Promise<boolean>;
18
+ stat(path: string): Promise<FileStats>;
19
+ }
20
+ declare class NodeFileSystem implements FileSystem {
21
+ readFile(path: string): Promise<string>;
22
+ readdir(path: string): Promise<string[]>;
23
+ writeFile(path: string, content: string): Promise<void>;
24
+ mkdir(path: string, options?: {
25
+ recursive?: boolean;
26
+ }): Promise<void>;
27
+ exists(path: string): Promise<boolean>;
28
+ stat(path: string): Promise<FileStats>;
29
+ }
30
+ declare const nodeFileSystem: NodeFileSystem;
31
+
32
+ interface ScannerOptions {
33
+ exclude?: string[];
34
+ fileSystem?: FileSystem;
35
+ decoratorNames?: DecoratorNames;
36
+ /**
37
+ * Filter which message types to scan for.
38
+ * Defaults to all types: ['event', 'command', 'query']
39
+ */
40
+ messageTypes?: MessageType[];
41
+ }
42
+ declare class Scanner {
43
+ private readonly exclude;
44
+ private readonly fs;
45
+ private readonly decoratorPatterns;
46
+ constructor(options?: ScannerOptions);
47
+ scan(sourceDir: string): Promise<string[]>;
48
+ private containsPublicDecorator;
49
+ }
50
+
51
+ interface ParseResult {
52
+ readonly events: readonly DomainEvent[];
53
+ readonly commands: readonly Command[];
54
+ readonly queries: readonly Query[];
55
+ readonly typeDefinitions: readonly TypeDefinition[];
56
+ }
57
+ interface ParserOptions {
58
+ decoratorNames?: DecoratorNames;
59
+ responseNamingConventions?: readonly ResponseNamingConvention[];
60
+ messageTypes?: readonly MessageType[];
61
+ }
62
+ declare class Parser {
63
+ private readonly decoratorMappings;
64
+ private readonly responseNamingConventions;
65
+ private readonly messageTypes;
66
+ constructor(options?: ParserOptions);
67
+ parse(sourceCode: string, sourceFileInfo: SourceFile): ParseResult;
68
+ private collectMessagesFromClass;
69
+ private applyNamingConventionMatching;
70
+ private findMatchingResponseType;
71
+ private buildMessage;
72
+ private extractMessageDetails;
73
+ private extractPayload;
74
+ private parsePayloadTypeArgument;
75
+ private flattenIntersectionToFields;
76
+ private extractTypeDefinition;
77
+ private extractInterfaceDefinition;
78
+ private buildTypeDefinition;
79
+ }
80
+
81
+ interface InputContextConfig {
82
+ readonly name: string;
83
+ readonly path: string;
84
+ readonly sourceDir?: string;
85
+ readonly tsconfigPath?: string;
86
+ readonly responseNamingConventions?: readonly ResponseNamingConvention[];
87
+ }
1
88
  /**
2
- * Contracts Generator
89
+ * Encapsulates context configuration with path resolution capabilities.
90
+ * Created via factory method to ensure proper initialization.
91
+ */
92
+ declare class ContextConfig {
93
+ private readonly fs;
94
+ private readonly tsconfig;
95
+ readonly name: string;
96
+ readonly sourceDir: string;
97
+ readonly responseNamingConventions?: readonly ResponseNamingConvention[];
98
+ private constructor();
99
+ /**
100
+ * Factory method to create ContextConfig with properly loaded tsconfig.
101
+ */
102
+ static create(input: InputContextConfig, configDir: string, fs?: FileSystem): Promise<ContextConfig>;
103
+ private static loadTsconfig;
104
+ /**
105
+ * Creates a ContextConfig without async loading (for cases where tsconfig is not needed
106
+ * or already handled externally).
107
+ */
108
+ static createSync(name: string, sourceDir: string, fs?: FileSystem, responseNamingConventions?: readonly ResponseNamingConvention[]): ContextConfig;
109
+ /**
110
+ * Resolves a module specifier (path alias) to actual file path.
111
+ * Only handles non-relative imports (path aliases).
112
+ *
113
+ * @param moduleSpecifier - The import path to resolve (e.g., "@/utils/helper")
114
+ * @returns Object with resolvedPath (null if external) and isExternal flag
115
+ */
116
+ resolvePath(moduleSpecifier: string): Promise<{
117
+ resolvedPath: string | null;
118
+ isExternal: boolean;
119
+ }>;
120
+ private tryResolveWithExtensions;
121
+ }
122
+
123
+ interface ImportInfo {
124
+ moduleSpecifier: string;
125
+ resolvedPath: string | null;
126
+ isExternal: boolean;
127
+ importedNames: string[];
128
+ }
129
+ interface FileNode {
130
+ absolutePath: string;
131
+ relativePath: string;
132
+ imports: ImportInfo[];
133
+ isEntryPoint: boolean;
134
+ }
135
+ interface FileGraph {
136
+ nodes: Map<string, FileNode>;
137
+ entryPoints: Set<string>;
138
+ excludedPaths: Set<string>;
139
+ }
140
+ interface FileGraphResolverOptions {
141
+ contextConfig: ContextConfig;
142
+ fileSystem?: FileSystem;
143
+ excludeDependencies?: string[];
144
+ }
145
+ declare class FileGraphResolver {
146
+ private readonly contextConfig;
147
+ private readonly fs;
148
+ private readonly excludeDependencies;
149
+ private constructor();
150
+ static create(options: FileGraphResolverOptions): FileGraphResolver;
151
+ buildGraph(entryPoints: string[], sourceRoot: string): Promise<FileGraph>;
152
+ private extractImports;
153
+ private readSourceFile;
154
+ private extractModuleSpecifier;
155
+ private extractImportedNamesFromNode;
156
+ private resolveModule;
157
+ private queueUnvisitedLocalDependencies;
158
+ private shouldExclude;
159
+ private resolveRelativeModule;
160
+ private tryResolveWithExtensions;
161
+ }
162
+
163
+ interface CopyOptions {
164
+ sourceRoot: string;
165
+ outputDir: string;
166
+ fileGraph: FileGraph;
167
+ pathAliasRewrites?: Map<string, string>;
168
+ removeDecorators?: boolean;
169
+ responseTypesToExport?: Map<string, string[]>;
170
+ messageTypes?: readonly MessageType[];
171
+ decoratorNames?: DecoratorNames;
172
+ }
173
+ interface CopyResult {
174
+ copiedFiles: string[];
175
+ rewrittenImports: Map<string, string[]>;
176
+ }
177
+ interface FileCopierOptions {
178
+ fileSystem?: FileSystem;
179
+ }
180
+ declare class FileCopier {
181
+ private readonly fs;
182
+ constructor(options?: FileCopierOptions);
183
+ copyFiles(options: CopyOptions): Promise<CopyResult>;
184
+ private preprocessEntryFiles;
185
+ private expandTransitiveDependencies;
186
+ private resolveNodeContent;
187
+ private applyTransformations;
188
+ generateBarrelExport(copiedFiles: string[], outputDir: string): string;
189
+ private readFileContent;
190
+ private writeOutputFile;
191
+ private processExcludedImports;
192
+ private processDecoratorRemoval;
193
+ private processTypeExports;
194
+ private processInternalPathAliases;
195
+ private processExternalPathAliases;
196
+ private createExportStatement;
197
+ private rewriteInternalPathAliases;
198
+ private isExternalOrRelativeImport;
199
+ private resolveInternalImport;
200
+ private rewriteModuleSpecifier;
201
+ private computeRelativePath;
202
+ private applyPathAliasRewrites;
203
+ private escapeRegex;
204
+ private removeExcludedImports;
205
+ private findExcludedModuleSpecifiers;
206
+ private createExcludedImportsVisitor;
207
+ private isImportFromExcludedModule;
208
+ private isExportFromExcludedModule;
209
+ private removeContractDecorators;
210
+ private createDecoratorRemovalVisitor;
211
+ private processContractGeneratorImport;
212
+ private createImportWithFilteredBindings;
213
+ private removeContractDecoratorsFromClass;
214
+ private extractDecoratorName;
215
+ private isDecoratorCallExpression;
216
+ private hasExportModifier;
217
+ private prependExportModifier;
218
+ private addExportToTypes;
219
+ private createExportAdditionVisitor;
220
+ private addExportToTypeAlias;
221
+ private addExportToInterface;
222
+ private transformSourceFile;
223
+ private extractSymbolsFromEntry;
224
+ private buildDecoratorToMessageTypeMap;
225
+ private findTargetClasses;
226
+ private computeRelatedTypeNames;
227
+ private collectUsedIdentifiers;
228
+ private collectDecoratorIdentifier;
229
+ private collectLocalTypeDeclarations;
230
+ private addToDeclarationMap;
231
+ private resolveIncludedLocalTypes;
232
+ private collectTypeIdentifiersFromNodes;
233
+ private collectComputedPropertyIdentifier;
234
+ private generateExtractedOutput;
235
+ private buildImportMap;
236
+ private filterImports;
237
+ private appendImportStatements;
238
+ private appendLocalTypeDeclarations;
239
+ private appendTargetClasses;
240
+ private appendNodeWithExport;
241
+ private nodeHasExportKeyword;
242
+ }
243
+
244
+ /**
245
+ * Base error class for all contracts-generator errors.
246
+ * Allows catching all library errors with `instanceof MessageParserError`.
247
+ */
248
+ declare class MessageParserError extends Error {
249
+ constructor(message: string, options?: ErrorOptions);
250
+ }
251
+ /**
252
+ * Base class for configuration-related errors.
253
+ */
254
+ declare class ConfigurationError extends MessageParserError {
255
+ constructor(message: string, options?: ErrorOptions);
256
+ }
257
+ /**
258
+ * Error thrown when loading application.config.ts fails.
259
+ */
260
+ declare class ConfigLoadError extends ConfigurationError {
261
+ constructor(message: string, options?: ErrorOptions);
262
+ }
263
+ /**
264
+ * Base class for file system operation errors.
265
+ */
266
+ declare class FileSystemError extends MessageParserError {
267
+ readonly path: string;
268
+ constructor(message: string, path: string, options?: ErrorOptions);
269
+ }
270
+ /**
271
+ * Error thrown when a required file is not found.
272
+ */
273
+ declare class FileNotFoundError extends FileSystemError {
274
+ constructor(path: string, options?: ErrorOptions);
275
+ }
276
+ /**
277
+ * Error thrown when reading a file fails.
278
+ */
279
+ declare class FileReadError extends FileSystemError {
280
+ constructor(path: string, options?: ErrorOptions);
281
+ }
282
+ /**
283
+ * Error thrown when writing a file fails.
284
+ */
285
+ declare class FileWriteError extends FileSystemError {
286
+ constructor(path: string, options?: ErrorOptions);
287
+ }
288
+ /**
289
+ * Base class for parsing errors.
290
+ */
291
+ declare class ParseError extends MessageParserError {
292
+ constructor(message: string, options?: ErrorOptions);
293
+ }
294
+ /**
295
+ * Error thrown when JSON parsing fails.
296
+ */
297
+ declare class JsonParseError extends ParseError {
298
+ readonly filePath?: string;
299
+ constructor(message: string, filePath?: string, options?: ErrorOptions);
300
+ }
301
+ /**
302
+ * Base class for module/path resolution errors.
303
+ */
304
+ declare class ResolutionError extends MessageParserError {
305
+ constructor(message: string, options?: ErrorOptions);
306
+ }
307
+ /**
308
+ * Error thrown when module resolution fails.
309
+ */
310
+ declare class ModuleResolutionError extends ResolutionError {
311
+ readonly moduleSpecifier: string;
312
+ readonly fromFile: string;
313
+ constructor(moduleSpecifier: string, fromFile: string, options?: ErrorOptions);
314
+ }
315
+
316
+ interface ContractsConfig {
317
+ readonly contexts: readonly ContextConfig[];
318
+ readonly pathAliasRewrites?: Readonly<Record<string, string>>;
319
+ readonly externalDependencies?: Readonly<Record<string, string>>;
320
+ readonly decoratorNames: Required<DecoratorNames>;
321
+ readonly responseNamingConventions?: readonly ResponseNamingConvention[];
322
+ readonly removeDecorators?: boolean;
323
+ }
324
+ interface ConfigLoaderOptions {
325
+ fileSystem?: FileSystem;
326
+ }
327
+ declare class ConfigLoader {
328
+ private readonly fs;
329
+ constructor(options?: ConfigLoaderOptions);
330
+ load(configPath: string): Promise<ContractsConfig>;
331
+ private loadTypeScriptConfig;
332
+ private extractContractsConfig;
333
+ private resolveContexts;
334
+ private resolveStringContext;
335
+ private expandGlobPattern;
336
+ private createObjectContext;
337
+ private matchGlobPattern;
338
+ }
339
+
340
+ interface RegistryGeneratorOptions {
341
+ readonly messageRegistryImport: string;
342
+ readonly useNamespace?: boolean;
343
+ }
344
+ interface ContextMessages {
345
+ readonly contextName: string;
346
+ readonly events: readonly DomainEvent[];
347
+ readonly commands: readonly Command[];
348
+ readonly queries?: readonly Query[];
349
+ readonly importPath?: string;
350
+ }
351
+ declare class RegistryGenerator {
352
+ private readonly options;
353
+ constructor(options?: Partial<RegistryGeneratorOptions>);
354
+ generate(contexts: readonly ContextMessages[]): string;
355
+ private generateEmptyRegistry;
356
+ private generateWithNamespace;
357
+ private getNamespaceInfos;
358
+ private generateNamespaceImports;
359
+ private generateNamespaceExports;
360
+ private generateNamespaceRegistrations;
361
+ private toNamespace;
362
+ private generateImports;
363
+ private generateRegistrations;
364
+ }
365
+
366
+ /**
367
+ * Represents an import that was rewritten via pathAliasRewrites
368
+ */
369
+ interface RewrittenImport {
370
+ /** The rewritten module specifier (e.g., "@libera/contracts/common/request") */
371
+ readonly rewrittenPath: string;
372
+ /** The original module specifier before rewrite (e.g., "@libera/common/request") */
373
+ readonly originalPath: string;
374
+ /** The imported symbol names */
375
+ readonly symbols: readonly string[];
376
+ /** Whether this is a type-only import */
377
+ readonly isTypeOnly: boolean;
378
+ }
379
+ /**
380
+ * Represents a re-export file to be generated
381
+ */
382
+ interface ReexportFile {
383
+ /** Relative path within contracts output dir (e.g., "common/request.ts") */
384
+ readonly relativePath: string;
385
+ /** The original module to re-export from */
386
+ readonly originalModule: string;
387
+ /** Symbols to re-export */
388
+ readonly symbols: readonly string[];
389
+ /** Whether all symbols are type-only */
390
+ readonly isTypeOnly: boolean;
391
+ }
392
+ interface ReexportGeneratorOptions {
393
+ fileSystem?: FileSystem;
394
+ }
395
+ interface AnalyzeOptions {
396
+ /** The files to analyze (absolute paths) */
397
+ readonly files: readonly string[];
398
+ /** Map of original path prefix -> rewritten path prefix */
399
+ readonly pathAliasRewrites: ReadonlyMap<string, string>;
400
+ }
401
+ interface GenerateOptions {
402
+ /** The output directory for re-export files */
403
+ readonly outputDir: string;
404
+ /** The re-export files to generate */
405
+ readonly reexportFiles: readonly ReexportFile[];
406
+ }
407
+ /**
408
+ * Generates re-export files for pathAliasRewrites
409
+ */
410
+ declare class ReexportGenerator {
411
+ private readonly fs;
412
+ constructor(options?: ReexportGeneratorOptions);
413
+ /**
414
+ * Analyzes files to find imports that match pathAliasRewrites
415
+ * and groups them by rewritten path
416
+ */
417
+ analyze(options: AnalyzeOptions): Promise<ReexportFile[]>;
418
+ /**
419
+ * Generates re-export files
420
+ */
421
+ generate(options: GenerateOptions): Promise<string[]>;
422
+ /**
423
+ * Extracts imports from source content that match rewritten prefixes
424
+ */
425
+ private extractRewrittenImports;
426
+ /**
427
+ * Extracts symbol names from import clause
428
+ */
429
+ private extractSymbolNames;
430
+ /**
431
+ * Groups imports by rewritten path and merges symbols
432
+ */
433
+ private groupImportsByPath;
434
+ /**
435
+ * Converts a rewritten package path to a relative file path
436
+ * e.g., "@libera/contracts/common/request" with prefix "@libera/contracts"
437
+ * -> "common/request.ts"
438
+ */
439
+ private rewrittenPathToRelativePath;
440
+ /**
441
+ * Generates the content for a re-export file
442
+ */
443
+ private generateReexportContent;
444
+ }
445
+
446
+ type LogLevel = "debug" | "info" | "warn" | "error";
447
+ interface Logger {
448
+ debug(message: string): void;
449
+ info(message: string): void;
450
+ warn(message: string): void;
451
+ error(message: string): void;
452
+ }
453
+ interface ConsoleLoggerOptions {
454
+ level?: LogLevel;
455
+ }
456
+ declare class ConsoleLogger implements Logger {
457
+ private readonly level;
458
+ constructor(options?: ConsoleLoggerOptions);
459
+ debug(message: string): void;
460
+ info(message: string): void;
461
+ warn(message: string): void;
462
+ error(message: string): void;
463
+ private shouldLog;
464
+ }
465
+ declare const noopLogger: Logger;
466
+
467
+ interface PipelineDependencies {
468
+ readonly scanner: Scanner;
469
+ readonly parser: Parser;
470
+ readonly fileGraphResolver: FileGraphResolver;
471
+ readonly fileCopier: FileCopier;
472
+ readonly fileSystem: FileSystem;
473
+ readonly logger: Logger;
474
+ }
475
+ interface PipelineOptions {
476
+ readonly contextName: string;
477
+ readonly sourceDir: string;
478
+ readonly outputDir: string;
479
+ readonly pathAliasRewrites?: Map<string, string>;
480
+ readonly removeDecorators?: boolean;
481
+ }
482
+ interface PipelineResult {
483
+ readonly events: readonly DomainEvent[];
484
+ readonly commands: readonly Command[];
485
+ readonly queries: readonly Query[];
486
+ readonly copiedFiles: string[];
487
+ }
488
+ interface ParsedMessages {
489
+ readonly events: readonly DomainEvent[];
490
+ readonly commands: readonly Command[];
491
+ readonly queries: readonly Query[];
492
+ readonly typeDefinitions: readonly TypeDefinition[];
493
+ }
494
+ declare class ContractsPipeline {
495
+ private readonly deps;
496
+ private readonly messageTypes?;
497
+ private constructor();
498
+ static create(options: {
499
+ contextConfig: ContextConfig;
500
+ responseNamingConventions?: readonly ResponseNamingConvention[];
501
+ fileSystem?: FileSystem;
502
+ logger?: Logger;
503
+ excludeDependencies?: string[];
504
+ messageTypes?: MessageType[];
505
+ }): ContractsPipeline;
506
+ static fromDependencies(deps: PipelineDependencies): ContractsPipeline;
507
+ execute(options: PipelineOptions): Promise<PipelineResult>;
508
+ private collectResponseTypesToExport;
509
+ scan(sourceDir: string): Promise<string[]>;
510
+ parse(files: string[], sourceRoot: string): Promise<ParsedMessages>;
511
+ resolve(entryPoints: string[], sourceRoot: string): Promise<FileGraph>;
512
+ copy(fileGraph: FileGraph, sourceRoot: string, outputDir: string, pathAliasRewrites?: Map<string, string>, responseTypesToExport?: Map<string, string[]>, removeDecorators?: boolean, messageTypes?: readonly MessageType[]): Promise<string[]>;
513
+ exportBarrel(copiedFiles: string[], outputDir: string): Promise<void>;
514
+ }
515
+
516
+ /**
517
+ * CLI plugin definition for hexai integration.
3
518
  *
4
- * Extract Domain Events and Commands from TypeScript source code using decorators.
519
+ * This allows the contracts generator to be invoked via `pnpm hexai generate-contracts`.
520
+ * Configuration is provided via hexai.config.ts.
5
521
  *
6
522
  * @example
7
- * ```typescript
8
- * import { extract } from '@hexaijs/plugin-contracts-generator';
9
- *
10
- * const result = await extract({
11
- * sourceDir: 'packages',
12
- * outputDir: 'packages/contracts',
13
- * });
14
- *
15
- * console.log(`Extracted ${result.events.length} events and ${result.commands.length} commands`);
523
+ * ```bash
524
+ * pnpm hexai generate-contracts -o packages/contracts/src
525
+ * pnpm hexai generate-contracts -o packages/contracts/src -m event,command
16
526
  * ```
17
527
  */
18
- export type { SourceFile, TypeRef, PrimitiveType, ArrayType, ObjectType, UnionType, IntersectionType, ReferenceType, LiteralType, TupleType, FunctionType, FunctionParameter, Field, TypeDefinition, TypeDefinitionKind, EnumMember, EnumDefinition, ClassDefinition, ClassImport, Message, MessageBase, DomainEvent, Command, Dependency, DependencyKind, ImportSource, ExtractionResult, ExtractionError, ExtractionWarning, Config, } from "./domain/types";
19
- export { isPrimitiveType, isArrayType, isObjectType, isUnionType, isIntersectionType, isReferenceType, isLiteralType, isTupleType, isFunctionType, isDomainEvent, isCommand, } from "./domain/types";
20
- export { PublicEvent, PublicCommand, PublicQuery, type PublicEventOptions, type PublicCommandOptions, type PublicQueryOptions, } from "./decorators";
21
- export { Scanner, type ScannerOptions } from "./scanner";
22
- export { Parser, type ParseResult } from "./parser";
23
- export { FileGraphResolver } from "./file-graph-resolver";
24
- export { FileCopier } from "./file-copier";
25
- export { TsconfigLoader } from "./tsconfig-loader";
26
- export { ConfigLoader, type ContractsConfig, type ContextConfig, } from "./config-loader";
27
- export { MessageParserError, ConfigurationError, ConfigLoadError, TsconfigLoadError, FileSystemError, FileNotFoundError, FileReadError, FileWriteError, ParseError, JsonParseError, ResolutionError, ModuleResolutionError, } from "./errors";
28
- export { RegistryGenerator, type RegistryGeneratorOptions, type ContextMessages, } from "./registry-generator";
29
- export { ReexportGenerator, type ReexportGeneratorOptions, type AnalyzeOptions, type GenerateOptions, type RewrittenImport, type ReexportFile, } from "./reexport-generator";
30
- import { type FileSystem } from "./file-system";
31
- import { type Logger } from "./logger";
32
- export type { FileSystem, FileStats } from "./file-system";
33
- export { nodeFileSystem } from "./file-system";
34
- export type { Logger, LogLevel, ConsoleLoggerOptions } from "./logger";
35
- export { ConsoleLogger, noopLogger } from "./logger";
36
- export { ContractsPipeline, type PipelineDependencies, type PipelineOptions, type PipelineResult, type ParsedMessages, } from "./pipeline";
37
- import type { ResponseNamingConvention, MessageType } from "./domain/types";
38
- export interface ProcessContextOptions {
528
+ declare const cliPlugin: HexaiCliPlugin<ContractsPluginConfig>;
529
+
530
+ interface ProcessContextOptions {
39
531
  contextName: string;
40
- sourceDir: string;
532
+ path: string;
533
+ sourceDir?: string;
41
534
  outputDir: string;
42
535
  pathAliasRewrites?: Map<string, string>;
43
536
  tsconfigPath?: string;
@@ -47,12 +540,12 @@ export interface ProcessContextOptions {
47
540
  fileSystem?: FileSystem;
48
541
  logger?: Logger;
49
542
  }
50
- export interface ProcessContextResult {
51
- events: readonly import("./domain/types").DomainEvent[];
52
- commands: readonly import("./domain/types").Command[];
53
- queries: readonly import("./domain/types").Query[];
543
+ interface ProcessContextResult {
544
+ events: readonly DomainEvent[];
545
+ commands: readonly Command[];
546
+ queries: readonly Query[];
54
547
  copiedFiles: string[];
55
548
  }
56
- export declare function processContext(options: ProcessContextOptions): Promise<ProcessContextResult>;
57
- export { cliPlugin } from "./hexai-plugin";
58
- //# sourceMappingURL=index.d.ts.map
549
+ declare function processContext(options: ProcessContextOptions): Promise<ProcessContextResult>;
550
+
551
+ export { type AnalyzeOptions, Command, ConfigLoadError, ConfigLoader, ConfigurationError, ConsoleLogger, type ConsoleLoggerOptions, ContextConfig, type ContextMessages, type ContractsConfig, ContractsPipeline, DomainEvent, FileCopier, FileGraphResolver, FileNotFoundError, FileReadError, type FileStats, type FileSystem, FileSystemError, FileWriteError, type GenerateOptions, type InputContextConfig, JsonParseError, type LogLevel, type Logger, MessageParserError, ModuleResolutionError, ParseError, type ParseResult, type ParsedMessages, Parser, type PipelineDependencies, type PipelineOptions, type PipelineResult, type ProcessContextOptions, type ProcessContextResult, type ReexportFile, ReexportGenerator, type ReexportGeneratorOptions, RegistryGenerator, type RegistryGeneratorOptions, ResolutionError, type RewrittenImport, Scanner, type ScannerOptions, SourceFile, TypeDefinition, cliPlugin, nodeFileSystem, noopLogger, processContext };