@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/README.md CHANGED
@@ -150,7 +150,10 @@ export default {
150
150
  };
151
151
  ```
152
152
 
153
- Each matched package must have its own `application.config.ts` with `contextName` and `sourceDir`.
153
+ Each matched directory is treated as a context with sensible defaults:
154
+ - Context name = directory name (e.g., `packages/auth` → `auth`)
155
+ - Source directory = `src/` (default)
156
+ - TypeScript config = `tsconfig.json` (auto-detected if exists)
154
157
 
155
158
  ### Response Types
156
159
 
@@ -313,7 +316,7 @@ try {
313
316
  **Error hierarchy:**
314
317
 
315
318
  - `MessageParserError` (base)
316
- - `ConfigurationError` → `ConfigLoadError`, `TsconfigLoadError`
319
+ - `ConfigurationError` → `ConfigLoadError`
317
320
  - `FileSystemError` → `FileNotFoundError`, `FileReadError`, `FileWriteError`
318
321
  - `ParseError` → `JsonParseError`
319
322
  - `ResolutionError` → `ModuleResolutionError`
@@ -0,0 +1,214 @@
1
+ interface SourceFile {
2
+ readonly absolutePath: string;
3
+ readonly relativePath: string;
4
+ readonly packageName?: string;
5
+ }
6
+ type TypeRef = PrimitiveType | ArrayType | ObjectType | UnionType | IntersectionType | ReferenceType | LiteralType | TupleType | FunctionType;
7
+ interface PrimitiveType {
8
+ readonly kind: 'primitive';
9
+ readonly name: 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'void' | 'any' | 'unknown' | 'never' | 'bigint' | 'symbol';
10
+ }
11
+ interface ArrayType {
12
+ readonly kind: 'array';
13
+ readonly elementType: TypeRef;
14
+ }
15
+ interface ObjectType {
16
+ readonly kind: 'object';
17
+ readonly fields: readonly Field[];
18
+ }
19
+ interface UnionType {
20
+ readonly kind: 'union';
21
+ readonly types: readonly TypeRef[];
22
+ }
23
+ interface IntersectionType {
24
+ readonly kind: 'intersection';
25
+ readonly types: readonly TypeRef[];
26
+ }
27
+ interface ReferenceType {
28
+ readonly kind: 'reference';
29
+ readonly name: string;
30
+ readonly typeArguments?: readonly TypeRef[];
31
+ }
32
+ interface LiteralType {
33
+ readonly kind: 'literal';
34
+ readonly value: string | number | boolean;
35
+ }
36
+ interface TupleType {
37
+ readonly kind: 'tuple';
38
+ readonly elements: readonly TypeRef[];
39
+ }
40
+ interface FunctionType {
41
+ readonly kind: 'function';
42
+ readonly parameters: readonly FunctionParameter[];
43
+ readonly returnType: TypeRef;
44
+ }
45
+ interface FunctionParameter {
46
+ readonly name: string;
47
+ readonly type: TypeRef;
48
+ readonly optional: boolean;
49
+ }
50
+ interface Field {
51
+ readonly name: string;
52
+ readonly type: TypeRef;
53
+ readonly optional: boolean;
54
+ readonly readonly: boolean;
55
+ }
56
+ type TypeDefinitionKind = 'interface' | 'type' | 'enum' | 'class';
57
+ interface TypeDefinition {
58
+ readonly name: string;
59
+ readonly kind: TypeDefinitionKind;
60
+ readonly sourceFile: SourceFile;
61
+ readonly body: TypeRef;
62
+ readonly typeParameters?: readonly string[];
63
+ readonly exported: boolean;
64
+ }
65
+ interface EnumMember {
66
+ readonly name: string;
67
+ readonly value?: string | number;
68
+ }
69
+ interface EnumDefinition extends Omit<TypeDefinition, 'kind' | 'body'> {
70
+ readonly kind: 'enum';
71
+ readonly members: readonly EnumMember[];
72
+ }
73
+ interface ClassImport {
74
+ readonly names: readonly string[];
75
+ readonly source: string;
76
+ readonly isTypeOnly: boolean;
77
+ readonly isExternal: boolean;
78
+ }
79
+ interface ClassDefinition {
80
+ readonly name: string;
81
+ readonly kind: 'class';
82
+ readonly sourceFile: SourceFile;
83
+ readonly sourceText: string;
84
+ readonly imports: readonly ClassImport[];
85
+ readonly dependencies: readonly string[];
86
+ readonly baseClass?: string;
87
+ readonly exported: boolean;
88
+ }
89
+ interface MessageBase {
90
+ readonly name: string;
91
+ readonly sourceFile: SourceFile;
92
+ readonly fields: readonly Field[];
93
+ readonly baseClass?: string;
94
+ readonly sourceText: string;
95
+ readonly imports: readonly ClassImport[];
96
+ }
97
+ interface DomainEvent extends MessageBase {
98
+ readonly messageType: 'event';
99
+ readonly version?: number;
100
+ readonly context?: string;
101
+ readonly payloadType?: TypeRef;
102
+ }
103
+ interface Command extends MessageBase {
104
+ readonly messageType: 'command';
105
+ readonly resultType?: TypeRef;
106
+ readonly context?: string;
107
+ readonly payloadType?: TypeRef;
108
+ }
109
+ interface Query extends MessageBase {
110
+ readonly messageType: 'query';
111
+ readonly resultType?: TypeRef;
112
+ readonly context?: string;
113
+ readonly payloadType?: TypeRef;
114
+ }
115
+ type Message = DomainEvent | Command | Query;
116
+ /** Used to filter which decorators the scanner should look for. */
117
+ type MessageType = Message['messageType'];
118
+ type ImportSource = {
119
+ readonly type: 'local';
120
+ readonly path: string;
121
+ } | {
122
+ readonly type: 'external';
123
+ readonly package: string;
124
+ };
125
+ type DependencyKind = 'type' | 'value' | 'class';
126
+ interface Dependency {
127
+ readonly name: string;
128
+ readonly source: ImportSource;
129
+ readonly kind: DependencyKind;
130
+ readonly definition?: TypeDefinition;
131
+ }
132
+ interface SourceLocation {
133
+ readonly file: string;
134
+ readonly message: string;
135
+ readonly line?: number;
136
+ readonly column?: number;
137
+ }
138
+ type ExtractionError = SourceLocation;
139
+ type ExtractionWarning = SourceLocation;
140
+ interface ExtractionResult {
141
+ readonly events: readonly DomainEvent[];
142
+ readonly commands: readonly Command[];
143
+ readonly types: readonly TypeDefinition[];
144
+ readonly dependencies: readonly Dependency[];
145
+ readonly errors: readonly ExtractionError[];
146
+ readonly warnings: readonly ExtractionWarning[];
147
+ }
148
+ /** Customizes decorator names used to identify public messages. Unspecified names use defaults. */
149
+ interface DecoratorNames {
150
+ event?: string;
151
+ command?: string;
152
+ query?: string;
153
+ }
154
+ interface ResponseNamingConvention {
155
+ readonly messageSuffix: string;
156
+ readonly responseSuffix: string;
157
+ }
158
+ interface Config {
159
+ readonly sourceDir: string;
160
+ readonly outputDir: string;
161
+ readonly include?: readonly string[];
162
+ readonly exclude?: readonly string[];
163
+ readonly externalPackages?: Readonly<Record<string, string>>;
164
+ readonly decoratorNames?: DecoratorNames;
165
+ readonly responseNamingConventions?: readonly ResponseNamingConvention[];
166
+ }
167
+ declare function isPrimitiveType(type: TypeRef): type is PrimitiveType;
168
+ declare function isArrayType(type: TypeRef): type is ArrayType;
169
+ declare function isObjectType(type: TypeRef): type is ObjectType;
170
+ declare function isUnionType(type: TypeRef): type is UnionType;
171
+ declare function isIntersectionType(type: TypeRef): type is IntersectionType;
172
+ declare function isReferenceType(type: TypeRef): type is ReferenceType;
173
+ declare function isLiteralType(type: TypeRef): type is LiteralType;
174
+ declare function isTupleType(type: TypeRef): type is TupleType;
175
+ declare function isFunctionType(type: TypeRef): type is FunctionType;
176
+ declare function isDomainEvent(message: Message): message is DomainEvent;
177
+ declare function isCommand(message: Message): message is Command;
178
+
179
+ /**
180
+ * Options for runWithConfig when config is provided directly.
181
+ */
182
+ interface RunWithConfigOptions {
183
+ outputDir: string;
184
+ messageTypes?: MessageType[];
185
+ generateMessageRegistry?: boolean;
186
+ }
187
+ /**
188
+ * Plugin configuration structure for contracts generator.
189
+ * This is the config passed from hexai.config.ts.
190
+ */
191
+ interface ContractsPluginConfig {
192
+ contexts: Array<{
193
+ name: string;
194
+ path: string;
195
+ sourceDir?: string;
196
+ tsconfigPath?: string;
197
+ }>;
198
+ pathAliasRewrites?: Record<string, string>;
199
+ externalDependencies?: Record<string, string>;
200
+ decoratorNames?: DecoratorNames;
201
+ responseNamingConventions?: ResponseNamingConvention[];
202
+ removeDecorators?: boolean;
203
+ }
204
+ declare function run(args: string[]): Promise<void>;
205
+ /**
206
+ * Run contracts generator with config provided directly.
207
+ * This is used by the hexai CLI integration where config comes from hexai.config.ts.
208
+ *
209
+ * @param options - CLI options (outputDir, messageTypes, generateMessageRegistry)
210
+ * @param pluginConfig - Plugin configuration from hexai.config.ts
211
+ */
212
+ declare function runWithConfig(options: RunWithConfigOptions, pluginConfig: ContractsPluginConfig): Promise<void>;
213
+
214
+ export { type ArrayType as A, isObjectType as B, type Command as C, type DecoratorNames as D, type EnumDefinition as E, type Field as F, isPrimitiveType as G, isReferenceType as H, type ImportSource as I, isTupleType as J, isUnionType as K, type LiteralType as L, type MessageType as M, type RunWithConfigOptions as N, type ObjectType as O, type PrimitiveType as P, type Query as Q, type ResponseNamingConvention as R, type SourceFile as S, type TypeDefinition as T, type UnionType as U, run as V, runWithConfig as W, type DomainEvent as a, type ContractsPluginConfig as b, type ClassDefinition as c, type ClassImport as d, type Config as e, type Dependency as f, type DependencyKind as g, type EnumMember as h, type ExtractionError as i, type ExtractionResult as j, type ExtractionWarning as k, type FunctionParameter as l, type FunctionType as m, type IntersectionType as n, type Message as o, type MessageBase as p, type ReferenceType as q, type TupleType as r, type TypeDefinitionKind as s, type TypeRef as t, isArrayType as u, isCommand as v, isDomainEvent as w, isFunctionType as x, isIntersectionType as y, isLiteralType as z };
package/dist/cli.d.ts CHANGED
@@ -1,36 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import type { MessageType, DecoratorNames, ResponseNamingConvention } from "./domain/types";
3
- /**
4
- * Options for runWithConfig when config is provided directly.
5
- */
6
- export interface RunWithConfigOptions {
7
- outputDir: string;
8
- messageTypes?: MessageType[];
9
- generateMessageRegistry?: boolean;
10
- }
11
- /**
12
- * Plugin configuration structure for contracts generator.
13
- * This is the config passed from hexai.config.ts.
14
- */
15
- export interface ContractsPluginConfig {
16
- contexts: Array<{
17
- name: string;
18
- sourceDir: string;
19
- tsconfigPath?: string;
20
- }>;
21
- pathAliasRewrites?: Record<string, string>;
22
- externalDependencies?: Record<string, string>;
23
- decoratorNames?: DecoratorNames;
24
- responseNamingConventions?: ResponseNamingConvention[];
25
- removeDecorators?: boolean;
26
- }
27
- export declare function run(args: string[]): Promise<void>;
28
- /**
29
- * Run contracts generator with config provided directly.
30
- * This is used by the hexai CLI integration where config comes from hexai.config.ts.
31
- *
32
- * @param options - CLI options (outputDir, messageTypes, generateMessageRegistry)
33
- * @param pluginConfig - Plugin configuration from hexai.config.ts
34
- */
35
- export declare function runWithConfig(options: RunWithConfigOptions, pluginConfig: ContractsPluginConfig): Promise<void>;
36
- //# sourceMappingURL=cli.d.ts.map
2
+ export { b as ContractsPluginConfig, N as RunWithConfigOptions, V as run, W as runWithConfig } from './cli-CPg-O4OY.js';