@hexaijs/plugin-contracts-generator 0.2.0 → 0.2.1

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/index.d.ts CHANGED
@@ -1,34 +1,8 @@
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';
1
+ import { F as FileSystem, 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 ContextConfig, I as InputContextConfig, c as ContractsPluginConfig } from './cli-DajurpEQ.js';
2
+ export { A as ArrayType, d as ClassDefinition, e as ClassImport, f as Config, g as Dependency, h as DependencyKind, E as EnumDefinition, i as EnumMember, j as ExtractionError, k as ExtractionResult, l as ExtractionWarning, m as Field, n as FileStats, o as FunctionParameter, p as FunctionType, q as ImportSource, r as IntersectionType, L as LiteralType, s as Message, t as MessageBase, O as ObjectType, P as PrimitiveType, u as ReferenceType, v as TupleType, w as TypeDefinitionKind, x as TypeRef, U as UnionType, y as isArrayType, z as isCommand, B as isDomainEvent, G as isFunctionType, H as isIntersectionType, J as isLiteralType, K as isObjectType, N as isPrimitiveType, V as isReferenceType, W as isTupleType, X as isUnionType, Y as nodeFileSystem } from './cli-DajurpEQ.js';
3
+ export { PublicCommand, PublicCommandOptions, PublicEvent, PublicEventOptions, PublicQuery, PublicQueryOptions } from '@hexaijs/contracts/decorators';
4
4
  import { HexaiCliPlugin } from '@hexaijs/cli';
5
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
6
  interface ScannerOptions {
33
7
  exclude?: string[];
34
8
  fileSystem?: FileSystem;
@@ -78,48 +52,6 @@ declare class Parser {
78
52
  private buildTypeDefinition;
79
53
  }
80
54
 
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
- }
88
- /**
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
55
  interface ImportInfo {
124
56
  moduleSpecifier: string;
125
57
  resolvedPath: string | null;
@@ -324,17 +256,13 @@ interface ContractsConfig {
324
256
  interface ConfigLoaderOptions {
325
257
  fileSystem?: FileSystem;
326
258
  }
259
+ declare function resolveContextEntries(entries: readonly (string | InputContextConfig)[], configDir: string, fs?: FileSystem): Promise<ContextConfig[]>;
327
260
  declare class ConfigLoader {
328
261
  private readonly fs;
329
262
  constructor(options?: ConfigLoaderOptions);
330
263
  load(configPath: string): Promise<ContractsConfig>;
331
264
  private loadTypeScriptConfig;
332
265
  private extractContractsConfig;
333
- private resolveContexts;
334
- private resolveStringContext;
335
- private expandGlobPattern;
336
- private createObjectContext;
337
- private matchGlobPattern;
338
266
  }
339
267
 
340
268
  interface RegistryGeneratorOptions {
@@ -548,4 +476,4 @@ interface ProcessContextResult {
548
476
  }
549
477
  declare function processContext(options: ProcessContextOptions): Promise<ProcessContextResult>;
550
478
 
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 };
479
+ export { type AnalyzeOptions, Command, ConfigLoadError, ConfigLoader, ConfigurationError, ConsoleLogger, type ConsoleLoggerOptions, ContextConfig, type ContextMessages, type ContractsConfig, ContractsPipeline, DomainEvent, FileCopier, FileGraphResolver, FileNotFoundError, FileReadError, FileSystem, FileSystemError, FileWriteError, type GenerateOptions, 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, noopLogger, processContext, resolveContextEntries };
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import 'reflect-metadata';
1
+ export { PublicCommand, PublicEvent, PublicQuery } from '@hexaijs/contracts/decorators';
2
2
  import { glob } from 'glob';
3
3
  import { readFile, readdir, writeFile, mkdir, access, stat } from 'fs/promises';
4
4
  import { constants } from 'fs';
5
5
  import * as ts6 from 'typescript';
6
6
  import ts6__default from 'typescript';
7
7
  import * as path3 from 'path';
8
- import path3__default, { resolve, dirname, basename, relative, join } from 'path';
8
+ import path3__default, { resolve, dirname, join, relative, basename } from 'path';
9
9
  import { minimatch } from 'minimatch';
10
10
  import { fileURLToPath } from 'url';
11
11
 
@@ -54,27 +54,6 @@ function isDomainEvent(message) {
54
54
  function isCommand(message) {
55
55
  return message.messageType === "command";
56
56
  }
57
- var PUBLIC_EVENT_METADATA = /* @__PURE__ */ Symbol("publicEvent");
58
- var PUBLIC_COMMAND_METADATA = /* @__PURE__ */ Symbol("publicCommand");
59
- var PUBLIC_QUERY_METADATA = /* @__PURE__ */ Symbol("publicQuery");
60
- function PublicEvent(options = {}) {
61
- return (target) => {
62
- Reflect.defineMetadata(PUBLIC_EVENT_METADATA, options, target);
63
- return target;
64
- };
65
- }
66
- function PublicCommand(options = {}) {
67
- return (target) => {
68
- Reflect.defineMetadata(PUBLIC_COMMAND_METADATA, options, target);
69
- return target;
70
- };
71
- }
72
- function PublicQuery(options = {}) {
73
- return (target) => {
74
- Reflect.defineMetadata(PUBLIC_QUERY_METADATA, options, target);
75
- return target;
76
- };
77
- }
78
57
 
79
58
  // src/errors.ts
80
59
  var MessageParserError = class extends Error {
@@ -1773,6 +1752,90 @@ var ContextConfig = class _ContextConfig {
1773
1752
 
1774
1753
  // src/config-loader.ts
1775
1754
  var SUPPORTED_GLOB_PARTS_COUNT = 2;
1755
+ async function resolveContextEntries(entries, configDir, fs = nodeFileSystem) {
1756
+ const contexts = [];
1757
+ for (let i = 0; i < entries.length; i++) {
1758
+ const item = entries[i];
1759
+ if (typeof item === "string") {
1760
+ const resolved = await resolveStringEntry(item, configDir, fs);
1761
+ contexts.push(...resolved);
1762
+ } else {
1763
+ const contextConfig = await createObjectContext(item, i, configDir, fs);
1764
+ contexts.push(contextConfig);
1765
+ }
1766
+ }
1767
+ return contexts;
1768
+ }
1769
+ async function resolveStringEntry(contextPath, configDir, fs) {
1770
+ if (contextPath.includes("*")) {
1771
+ return expandGlobPattern(contextPath, configDir, fs);
1772
+ }
1773
+ const basePath = resolve(configDir, contextPath);
1774
+ const name = basename(basePath);
1775
+ return [await ContextConfig.create(
1776
+ { name, path: contextPath },
1777
+ configDir,
1778
+ fs
1779
+ )];
1780
+ }
1781
+ async function expandGlobPattern(pattern, configDir, fs) {
1782
+ const packageDirs = await matchGlobPattern(pattern, configDir, fs);
1783
+ return Promise.all(
1784
+ packageDirs.map((dir) => {
1785
+ const name = basename(dir);
1786
+ const relativePath = relative(configDir, dir);
1787
+ return ContextConfig.create(
1788
+ { name, path: relativePath },
1789
+ configDir,
1790
+ fs
1791
+ );
1792
+ })
1793
+ );
1794
+ }
1795
+ async function createObjectContext(ctx, index, configDir, fs) {
1796
+ if (!ctx.name || typeof ctx.name !== "string") {
1797
+ throw new ConfigLoadError(
1798
+ `Invalid context at index ${index}: missing 'name'`
1799
+ );
1800
+ }
1801
+ if (!ctx.path || typeof ctx.path !== "string") {
1802
+ throw new ConfigLoadError(
1803
+ `Invalid context at index ${index}: missing 'path'`
1804
+ );
1805
+ }
1806
+ return ContextConfig.create(ctx, configDir, fs);
1807
+ }
1808
+ async function matchGlobPattern(pattern, configDir, fs) {
1809
+ const globParts = pattern.split("*");
1810
+ if (globParts.length !== SUPPORTED_GLOB_PARTS_COUNT) {
1811
+ throw new ConfigLoadError(
1812
+ `Invalid glob pattern: "${pattern}". Only single wildcard patterns like "packages/*" are supported.`
1813
+ );
1814
+ }
1815
+ const [prefix, suffix] = globParts;
1816
+ const baseDir = resolve(configDir, prefix);
1817
+ if (!await fs.exists(baseDir)) {
1818
+ return [];
1819
+ }
1820
+ const entries = await fs.readdir(baseDir);
1821
+ const matchedDirs = [];
1822
+ for (const entry of entries) {
1823
+ const fullPath = resolve(baseDir, entry);
1824
+ const stats = await fs.stat(fullPath);
1825
+ if (!stats.isDirectory()) {
1826
+ continue;
1827
+ }
1828
+ if (suffix) {
1829
+ const suffixPath = resolve(fullPath, suffix.replace(/^\//, ""));
1830
+ if (await fs.exists(suffixPath)) {
1831
+ matchedDirs.push(fullPath);
1832
+ }
1833
+ } else {
1834
+ matchedDirs.push(fullPath);
1835
+ }
1836
+ }
1837
+ return matchedDirs.sort();
1838
+ }
1776
1839
  var ConfigLoader = class {
1777
1840
  fs;
1778
1841
  constructor(options = {}) {
@@ -1805,7 +1868,7 @@ var ConfigLoader = class {
1805
1868
  if (!contracts.contexts || !Array.isArray(contracts.contexts)) {
1806
1869
  throw new ConfigLoadError("Missing 'contracts.contexts' in config");
1807
1870
  }
1808
- const contexts = await this.resolveContexts(contracts.contexts, configDir);
1871
+ const contexts = await resolveContextEntries(contracts.contexts, configDir, this.fs);
1809
1872
  if (contexts.length === 0) {
1810
1873
  throw new ConfigLoadError("No contexts found from 'contexts'");
1811
1874
  }
@@ -1819,90 +1882,6 @@ var ConfigLoader = class {
1819
1882
  removeDecorators: contracts.removeDecorators ?? true
1820
1883
  };
1821
1884
  }
1822
- async resolveContexts(contextsConfig, configDir) {
1823
- const contexts = [];
1824
- for (let i = 0; i < contextsConfig.length; i++) {
1825
- const item = contextsConfig[i];
1826
- if (typeof item === "string") {
1827
- const resolvedContexts = await this.resolveStringContext(item, configDir);
1828
- contexts.push(...resolvedContexts);
1829
- } else {
1830
- const contextConfig = await this.createObjectContext(item, i, configDir);
1831
- contexts.push(contextConfig);
1832
- }
1833
- }
1834
- return contexts;
1835
- }
1836
- async resolveStringContext(contextPath, configDir) {
1837
- if (contextPath.includes("*")) {
1838
- return this.expandGlobPattern(contextPath, configDir);
1839
- }
1840
- const basePath = resolve(configDir, contextPath);
1841
- const name = basename(basePath);
1842
- return [await ContextConfig.create(
1843
- { name, path: contextPath },
1844
- configDir,
1845
- this.fs
1846
- )];
1847
- }
1848
- async expandGlobPattern(pattern, configDir) {
1849
- const packageDirs = await this.matchGlobPattern(pattern, configDir);
1850
- return Promise.all(
1851
- packageDirs.map((dir) => {
1852
- const name = basename(dir);
1853
- const relativePath = relative(configDir, dir);
1854
- return ContextConfig.create(
1855
- { name, path: relativePath },
1856
- configDir,
1857
- this.fs
1858
- );
1859
- })
1860
- );
1861
- }
1862
- async createObjectContext(ctx, index, configDir) {
1863
- if (!ctx.name || typeof ctx.name !== "string") {
1864
- throw new ConfigLoadError(
1865
- `Invalid context at index ${index}: missing 'name'`
1866
- );
1867
- }
1868
- if (!ctx.path || typeof ctx.path !== "string") {
1869
- throw new ConfigLoadError(
1870
- `Invalid context at index ${index}: missing 'path'`
1871
- );
1872
- }
1873
- return ContextConfig.create(ctx, configDir, this.fs);
1874
- }
1875
- async matchGlobPattern(pattern, configDir) {
1876
- const globParts = pattern.split("*");
1877
- if (globParts.length !== SUPPORTED_GLOB_PARTS_COUNT) {
1878
- throw new ConfigLoadError(
1879
- `Invalid glob pattern: "${pattern}". Only single wildcard patterns like "packages/*" are supported.`
1880
- );
1881
- }
1882
- const [prefix, suffix] = globParts;
1883
- const baseDir = resolve(configDir, prefix);
1884
- if (!await this.fs.exists(baseDir)) {
1885
- return [];
1886
- }
1887
- const entries = await this.fs.readdir(baseDir);
1888
- const matchedDirs = [];
1889
- for (const entry of entries) {
1890
- const fullPath = resolve(baseDir, entry);
1891
- const stats = await this.fs.stat(fullPath);
1892
- if (!stats.isDirectory()) {
1893
- continue;
1894
- }
1895
- if (suffix) {
1896
- const suffixPath = resolve(fullPath, suffix.replace(/^\//, ""));
1897
- if (await this.fs.exists(suffixPath)) {
1898
- matchedDirs.push(fullPath);
1899
- }
1900
- } else {
1901
- matchedDirs.push(fullPath);
1902
- }
1903
- }
1904
- return matchedDirs.sort();
1905
- }
1906
1885
  };
1907
1886
 
1908
1887
  // src/registry-generator.ts
@@ -2453,9 +2432,12 @@ Config file format:
2453
2432
  export default {
2454
2433
  contracts: {
2455
2434
  contexts: [
2435
+ "packages/*", // glob: auto-discover all contexts
2436
+ "packages/auth", // string: name inferred from directory
2456
2437
  {
2457
2438
  name: "lecture",
2458
- sourceDir: "packages/lecture/src",
2439
+ path: "packages/lecture", // required: base directory
2440
+ sourceDir: "src", // optional, default: "src"
2459
2441
  },
2460
2442
  ],
2461
2443
  pathAliasRewrites: {
@@ -2541,19 +2523,10 @@ async function run(args) {
2541
2523
  }
2542
2524
  }
2543
2525
  async function toContractsConfig(pluginConfig) {
2544
- const contexts = await Promise.all(
2545
- pluginConfig.contexts.map(
2546
- (ctx) => ContextConfig.create(
2547
- {
2548
- name: ctx.name,
2549
- path: ctx.path,
2550
- sourceDir: ctx.sourceDir,
2551
- tsconfigPath: ctx.tsconfigPath
2552
- },
2553
- process.cwd(),
2554
- nodeFileSystem
2555
- )
2556
- )
2526
+ const contexts = await resolveContextEntries(
2527
+ pluginConfig.contexts,
2528
+ process.cwd(),
2529
+ nodeFileSystem
2557
2530
  );
2558
2531
  return {
2559
2532
  contexts,
@@ -2739,6 +2712,6 @@ async function processContext(options) {
2739
2712
  });
2740
2713
  }
2741
2714
 
2742
- export { ConfigLoadError, ConfigLoader, ConfigurationError, ConsoleLogger, ContextConfig, ContractsPipeline, FileCopier, FileGraphResolver, FileNotFoundError, FileReadError, FileSystemError, FileWriteError, JsonParseError, MessageParserError, ModuleResolutionError, ParseError, Parser, PublicCommand, PublicEvent, PublicQuery, ReexportGenerator, RegistryGenerator, ResolutionError, Scanner, cliPlugin, isArrayType, isCommand, isDomainEvent, isFunctionType, isIntersectionType, isLiteralType, isObjectType, isPrimitiveType, isReferenceType, isTupleType, isUnionType, nodeFileSystem, noopLogger, processContext };
2715
+ export { ConfigLoadError, ConfigLoader, ConfigurationError, ConsoleLogger, ContextConfig, ContractsPipeline, FileCopier, FileGraphResolver, FileNotFoundError, FileReadError, FileSystemError, FileWriteError, JsonParseError, MessageParserError, ModuleResolutionError, ParseError, Parser, ReexportGenerator, RegistryGenerator, ResolutionError, Scanner, cliPlugin, isArrayType, isCommand, isDomainEvent, isFunctionType, isIntersectionType, isLiteralType, isObjectType, isPrimitiveType, isReferenceType, isTupleType, isUnionType, nodeFileSystem, noopLogger, processContext, resolveContextEntries };
2743
2716
  //# sourceMappingURL=index.js.map
2744
2717
  //# sourceMappingURL=index.js.map