@skmtc/core 0.0.782 → 0.0.785

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 (61) hide show
  1. package/esm/context/CoreContext.d.ts +175 -0
  2. package/esm/context/CoreContext.d.ts.map +1 -1
  3. package/esm/context/CoreContext.js +178 -0
  4. package/esm/dsl/ContentBase.d.ts +115 -0
  5. package/esm/dsl/ContentBase.d.ts.map +1 -1
  6. package/esm/dsl/ContentBase.js +110 -0
  7. package/esm/dsl/File.d.ts +208 -0
  8. package/esm/dsl/File.d.ts.map +1 -1
  9. package/esm/dsl/File.js +197 -0
  10. package/esm/dsl/model/ModelBase.d.ts +257 -0
  11. package/esm/dsl/model/ModelBase.d.ts.map +1 -1
  12. package/esm/dsl/model/ModelBase.js +248 -0
  13. package/esm/dsl/operation/OperationBase.d.ts +175 -0
  14. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  15. package/esm/dsl/operation/OperationBase.js +166 -0
  16. package/esm/helpers/strings.d.ts +63 -0
  17. package/esm/helpers/strings.d.ts.map +1 -1
  18. package/esm/helpers/strings.js +59 -0
  19. package/esm/mod.d.ts +66 -0
  20. package/esm/mod.d.ts.map +1 -1
  21. package/esm/mod.js +66 -0
  22. package/esm/run/toArtifacts.d.ts +114 -0
  23. package/esm/run/toArtifacts.d.ts.map +1 -1
  24. package/esm/run/toArtifacts.js +86 -0
  25. package/esm/types/Settings.d.ts +129 -0
  26. package/esm/types/Settings.d.ts.map +1 -1
  27. package/esm/types/Settings.js +3 -0
  28. package/esm/typescript/List.d.ts +111 -0
  29. package/esm/typescript/List.d.ts.map +1 -1
  30. package/esm/typescript/List.js +106 -0
  31. package/package.json +5 -1
  32. package/script/context/CoreContext.d.ts +175 -0
  33. package/script/context/CoreContext.d.ts.map +1 -1
  34. package/script/context/CoreContext.js +178 -0
  35. package/script/dsl/ContentBase.d.ts +115 -0
  36. package/script/dsl/ContentBase.d.ts.map +1 -1
  37. package/script/dsl/ContentBase.js +110 -0
  38. package/script/dsl/File.d.ts +208 -0
  39. package/script/dsl/File.d.ts.map +1 -1
  40. package/script/dsl/File.js +197 -0
  41. package/script/dsl/model/ModelBase.d.ts +257 -0
  42. package/script/dsl/model/ModelBase.d.ts.map +1 -1
  43. package/script/dsl/model/ModelBase.js +248 -0
  44. package/script/dsl/operation/OperationBase.d.ts +175 -0
  45. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  46. package/script/dsl/operation/OperationBase.js +166 -0
  47. package/script/helpers/strings.d.ts +63 -0
  48. package/script/helpers/strings.d.ts.map +1 -1
  49. package/script/helpers/strings.js +59 -0
  50. package/script/mod.d.ts +66 -0
  51. package/script/mod.d.ts.map +1 -1
  52. package/script/mod.js +66 -0
  53. package/script/run/toArtifacts.d.ts +114 -0
  54. package/script/run/toArtifacts.d.ts.map +1 -1
  55. package/script/run/toArtifacts.js +86 -0
  56. package/script/types/Settings.d.ts +129 -0
  57. package/script/types/Settings.d.ts.map +1 -1
  58. package/script/types/Settings.js +3 -0
  59. package/script/typescript/List.d.ts +111 -0
  60. package/script/typescript/List.d.ts.map +1 -1
  61. package/script/typescript/List.js +106 -0
@@ -1,20 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContentBase = void 0;
4
+ /**
5
+ * Base class for all content generators in the SKMTC DSL system.
6
+ *
7
+ * `ContentBase` provides the foundation for creating custom generators that transform
8
+ * OpenAPI Schema (OAS) objects into code artifacts. It handles registration with the
9
+ * generation context, skipping logic, and provides access to the pipeline's utilities.
10
+ *
11
+ * ## Generator Lifecycle
12
+ *
13
+ * 1. **Construction**: Initialize with context and optional generator key
14
+ * 2. **Registration**: Call {@link register} to add artifacts to the pipeline
15
+ * 3. **Generation**: Implement custom logic using context utilities
16
+ * 4. **Rendering**: Artifacts are automatically rendered by the pipeline
17
+ *
18
+ * @example Basic generator
19
+ * ```typescript
20
+ * import { ContentBase } from '@skmtc/core';
21
+ *
22
+ * class MyModelGenerator extends ContentBase {
23
+ * generate() {
24
+ * // Skip if not needed
25
+ * if (this.shouldSkip()) return;
26
+ *
27
+ * // Access OAS objects through context
28
+ * const schemas = this.context.oasDocument.components.schemas;
29
+ *
30
+ * for (const [name, schema] of Object.entries(schemas)) {
31
+ * if (schema.isRef()) continue;
32
+ *
33
+ * const file = new File({
34
+ * context: this.context,
35
+ * path: `./models/${name}.ts`,
36
+ * content: this.generateModelContent(schema)
37
+ * });
38
+ *
39
+ * // Register the file for rendering
40
+ * this.register({ file });
41
+ * }
42
+ * }
43
+ *
44
+ * private generateModelContent(schema: OasObject): string {
45
+ * // Custom model generation logic
46
+ * return `export interface ${schema.name} { ... }`;
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @example Generator with skipping logic
52
+ * ```typescript
53
+ * class ConditionalGenerator extends ContentBase {
54
+ * generate() {
55
+ * // Check if generation should be skipped
56
+ * if (this.shouldSkipBasedOnSettings()) {
57
+ * this.skip('Disabled in settings');
58
+ * return;
59
+ * }
60
+ *
61
+ * // Continue with generation...
62
+ * const file = this.createOutputFile();
63
+ * this.register({ file });
64
+ * }
65
+ *
66
+ * private shouldSkipBasedOnSettings(): boolean {
67
+ * return this.context.settings?.skip?.models?.includes('MyModel') ?? false;
68
+ * }
69
+ * }
70
+ * ```
71
+ */
4
72
  class ContentBase {
73
+ /**
74
+ * Creates a new ContentBase instance.
75
+ *
76
+ * @param args - Construction arguments
77
+ * @param args.context - The generation context
78
+ * @param args.generatorKey - Optional generator key
79
+ */
5
80
  constructor({ context, generatorKey }) {
81
+ /** The generation context providing access to OAS objects and utilities */
6
82
  Object.defineProperty(this, "context", {
7
83
  enumerable: true,
8
84
  configurable: true,
9
85
  writable: true,
10
86
  value: void 0
11
87
  });
88
+ /** Whether this generator has been skipped */
12
89
  Object.defineProperty(this, "skipped", {
13
90
  enumerable: true,
14
91
  configurable: true,
15
92
  writable: true,
16
93
  value: false
17
94
  });
95
+ /** Optional generator key for identification and tracking */
18
96
  Object.defineProperty(this, "generatorKey", {
19
97
  enumerable: true,
20
98
  configurable: true,
@@ -24,6 +102,38 @@ class ContentBase {
24
102
  this.context = context;
25
103
  this.generatorKey = generatorKey;
26
104
  }
105
+ /**
106
+ * Registers generated artifacts with the rendering pipeline.
107
+ *
108
+ * This method is called by generator implementations to add files,
109
+ * JSON artifacts, or other content to the generation output.
110
+ *
111
+ * @param args - The artifacts to register
112
+ * @param args.file - Optional file to register
113
+ * @param args.jsonFile - Optional JSON file to register
114
+ *
115
+ * @example Registering a file
116
+ * ```typescript
117
+ * const file = new File({
118
+ * context: this.context,
119
+ * path: './output.ts',
120
+ * content: 'export const value = 42;'
121
+ * });
122
+ *
123
+ * this.register({ file });
124
+ * ```
125
+ *
126
+ * @example Registering JSON data
127
+ * ```typescript
128
+ * const jsonFile = new JsonFile({
129
+ * context: this.context,
130
+ * path: './config.json',
131
+ * data: { version: '1.0.0', features: ['api'] }
132
+ * });
133
+ *
134
+ * this.register({ jsonFile });
135
+ * ```
136
+ */
27
137
  register(args) {
28
138
  this.context.register(args);
29
139
  }
@@ -1,24 +1,232 @@
1
1
  import type { Definition } from './Definition.js';
2
2
  import type { ClientSettings, ModulePackage } from '../types/Settings.js';
3
+ /**
4
+ * Constructor arguments for {@link File}.
5
+ */
3
6
  type FileArgs = {
7
+ /** The file path for the generated file */
4
8
  path: string;
9
+ /** Client settings containing package configuration */
5
10
  settings: ClientSettings | undefined;
6
11
  };
12
+ /**
13
+ * Represents a TypeScript file in the SKMTC DSL system.
14
+ *
15
+ * The `File` class is a core component for generating TypeScript files with proper
16
+ * import management, re-exports, and content organization. It automatically handles
17
+ * module resolution, import optimization, and package-aware path normalization.
18
+ *
19
+ * ## Key Features
20
+ *
21
+ * - **Import Management**: Automatically tracks and organizes imports from other modules
22
+ * - **Re-export Handling**: Supports re-exporting symbols from other modules
23
+ * - **Package Awareness**: Handles module packages for complex project structures
24
+ * - **Definition Tracking**: Manages code definitions and their relationships
25
+ * - **Path Normalization**: Automatically resolves paths based on package configuration
26
+ *
27
+ * @example Basic file creation
28
+ * ```typescript
29
+ * import { File } from '@skmtc/core';
30
+ *
31
+ * const file = new File({
32
+ * path: './src/models/User.ts',
33
+ * settings: clientSettings
34
+ * });
35
+ *
36
+ * // Add imports
37
+ * file.imports.set('./types', new Set(['BaseModel', 'Validator']));
38
+ *
39
+ * // Add definitions
40
+ * file.definitions.set('User', userInterface);
41
+ *
42
+ * // Generate file content
43
+ * const content = file.toString();
44
+ * console.log(content);
45
+ * // import { BaseModel, Validator } from './types'
46
+ * //
47
+ * // export interface User extends BaseModel {
48
+ * // id: string;
49
+ * // name: string;
50
+ * // }
51
+ * ```
52
+ *
53
+ * @example With package configuration
54
+ * ```typescript
55
+ * const file = new File({
56
+ * path: './packages/client/src/api.ts',
57
+ * settings: {
58
+ * packages: [
59
+ * {
60
+ * rootPath: './packages/types',
61
+ * moduleName: '@myorg/types'
62
+ * }
63
+ * ]
64
+ * }
65
+ * });
66
+ *
67
+ * // Import from another package
68
+ * file.imports.set('./packages/types/models', new Set(['User']));
69
+ *
70
+ * // Will generate: import { User } from '@myorg/types/models'
71
+ * ```
72
+ *
73
+ * @example Re-exports
74
+ * ```typescript
75
+ * const file = new File({
76
+ * path: './src/index.ts',
77
+ * settings: clientSettings
78
+ * });
79
+ *
80
+ * // Add re-exports
81
+ * file.reExports.set('./models', {
82
+ * 'type': new Set(['User', 'Product']),
83
+ * 'const': new Set(['DEFAULT_CONFIG'])
84
+ * });
85
+ *
86
+ * // Will generate:
87
+ * // export type { User, Product } from './models'
88
+ * // export { DEFAULT_CONFIG } from './models'
89
+ * ```
90
+ */
7
91
  export declare class File {
92
+ /** The file type, always 'ts' for TypeScript files */
8
93
  fileType: 'ts';
94
+ /** The file path for this generated file */
9
95
  path: string;
96
+ /** Map of module paths to re-exported symbols organized by export type */
10
97
  reExports: Map<string, Record<string, Set<string>>>;
98
+ /** Map of module paths to imported symbols */
11
99
  imports: Map<string, Set<string>>;
100
+ /** Map of definition names to their Definition objects */
12
101
  definitions: Map<string, Definition>;
102
+ /** Package configuration for path resolution */
13
103
  packages: ModulePackage[] | undefined;
104
+ /**
105
+ * Creates a new File instance.
106
+ *
107
+ * @param args - File configuration
108
+ * @param args.path - The output path for this file
109
+ * @param args.settings - Client settings containing package configuration
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const file = new File({
114
+ * path: './src/generated/models.ts',
115
+ * settings: {
116
+ * packages: [
117
+ * { rootPath: './packages/shared', moduleName: '@company/shared' }
118
+ * ]
119
+ * }
120
+ * });
121
+ * ```
122
+ */
14
123
  constructor({ path, settings }: FileArgs);
124
+ /**
125
+ * Generates the complete TypeScript file content.
126
+ *
127
+ * This method orchestrates the rendering of all file components in the correct order:
128
+ * re-exports first, then imports, and finally definitions. It automatically handles
129
+ * module path normalization based on package configuration and filters out empty sections.
130
+ *
131
+ * @returns The complete TypeScript file content as a string
132
+ *
133
+ * @example Basic file generation
134
+ * ```typescript
135
+ * const file = new File({ path: './api.ts', settings: undefined });
136
+ *
137
+ * // Add some imports and definitions
138
+ * file.imports.set('./types', new Set(['User', 'Product']));
139
+ * file.definitions.set('ApiClient', someDefinition);
140
+ *
141
+ * const content = file.toString();
142
+ * console.log(content);
143
+ * // import { User, Product } from './types'
144
+ * //
145
+ * // export class ApiClient {
146
+ * // // ... definition content
147
+ * // }
148
+ * ```
149
+ *
150
+ * @example With re-exports
151
+ * ```typescript
152
+ * const file = new File({ path: './index.ts', settings: undefined });
153
+ *
154
+ * file.reExports.set('./models', {
155
+ * 'type': new Set(['User', 'Product']),
156
+ * 'const': new Set(['DEFAULT_CONFIG'])
157
+ * });
158
+ *
159
+ * const content = file.toString();
160
+ * console.log(content);
161
+ * // export type { User, Product } from './models'
162
+ * // export { DEFAULT_CONFIG } from './models'
163
+ * ```
164
+ */
15
165
  toString(): string;
16
166
  }
167
+ /**
168
+ * Arguments for the {@link normaliseModuleName} function.
169
+ */
17
170
  export type NormaliseModuleNameArgs = {
171
+ /** The path of the file that will contain the import/export */
18
172
  destinationPath: string;
173
+ /** The original path being imported/exported from */
19
174
  exportPath: string;
175
+ /** Package configuration for path resolution */
20
176
  packages: ModulePackage[] | undefined;
21
177
  };
178
+ /**
179
+ * Normalizes module import/export paths based on package configuration.
180
+ *
181
+ * This function handles path resolution for complex project structures with multiple
182
+ * packages. It converts file system paths to appropriate module names based on:
183
+ * - Whether the destination and export paths are in the same package
184
+ * - Package-specific module naming conventions
185
+ * - Root path truncation for intra-package imports
186
+ *
187
+ * @param args - Path normalization arguments
188
+ * @param args.destinationPath - The path of the file that will contain the import/export
189
+ * @param args.exportPath - The original path being imported/exported from
190
+ * @param args.packages - Package configuration for path resolution (defaults to empty array)
191
+ * @returns The normalized module name to use in import/export statements
192
+ *
193
+ * @throws {Error} When a matching package is found but has no moduleName configured
194
+ *
195
+ * @example Cross-package import
196
+ * ```typescript
197
+ * const normalized = normaliseModuleName({
198
+ * destinationPath: './packages/client/src/api.ts',
199
+ * exportPath: './packages/types/models/User.ts',
200
+ * packages: [
201
+ * { rootPath: './packages/types', moduleName: '@company/types' },
202
+ * { rootPath: './packages/client', moduleName: '@company/client' }
203
+ * ]
204
+ * });
205
+ * console.log(normalized); // '@company/types'
206
+ * ```
207
+ *
208
+ * @example Intra-package import (same package)
209
+ * ```typescript
210
+ * const normalized = normaliseModuleName({
211
+ * destinationPath: './packages/types/src/index.ts',
212
+ * exportPath: './packages/types/models/User.ts',
213
+ * packages: [
214
+ * { rootPath: './packages/types', moduleName: '@company/types' }
215
+ * ]
216
+ * });
217
+ * console.log(normalized); // '@/models/User.ts' (truncates root path)
218
+ * ```
219
+ *
220
+ * @example No package match (returns original path)
221
+ * ```typescript
222
+ * const normalized = normaliseModuleName({
223
+ * destinationPath: './src/index.ts',
224
+ * exportPath: './src/utils.ts',
225
+ * packages: []
226
+ * });
227
+ * console.log(normalized); // './src/utils.ts'
228
+ * ```
229
+ */
22
230
  export declare const normaliseModuleName: ({ destinationPath, exportPath, packages }: NormaliseModuleNameArgs) => string;
23
231
  export {};
24
232
  //# sourceMappingURL=File.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/dsl/File.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzE,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,qBAAa,IAAI;IACf,QAAQ,EAAE,IAAI,CAAO;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACnD,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACpC,QAAQ,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;gBAEzB,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ;IAQxC,QAAQ,IAAI,MAAM;CAkCnB;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,2CAIjC,uBAAuB,WAqBzB,CAAA"}
1
+ {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/dsl/File.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzE;;GAEG;AACH,KAAK,QAAQ,GAAG;IACd,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,qBAAa,IAAI;IACf,sDAAsD;IACtD,QAAQ,EAAE,IAAI,CAAO;IAErB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAA;IAEZ,0EAA0E;IAC1E,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAEnD,8CAA8C;IAC9C,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjC,0DAA0D;IAC1D,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEpC,gDAAgD;IAChD,QAAQ,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;IAErC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ;IAQxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,QAAQ,IAAI,MAAM;CAkCnB;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,+DAA+D;IAC/D,eAAe,EAAE,MAAM,CAAA;IACvB,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAA;IAClB,gDAAgD;IAChD,QAAQ,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,mBAAmB,GAAI,2CAIjC,uBAAuB,KAAG,MAqB5B,CAAA"}
@@ -2,38 +2,142 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normaliseModuleName = exports.File = void 0;
4
4
  const Import_js_1 = require("./Import.js");
5
+ /**
6
+ * Represents a TypeScript file in the SKMTC DSL system.
7
+ *
8
+ * The `File` class is a core component for generating TypeScript files with proper
9
+ * import management, re-exports, and content organization. It automatically handles
10
+ * module resolution, import optimization, and package-aware path normalization.
11
+ *
12
+ * ## Key Features
13
+ *
14
+ * - **Import Management**: Automatically tracks and organizes imports from other modules
15
+ * - **Re-export Handling**: Supports re-exporting symbols from other modules
16
+ * - **Package Awareness**: Handles module packages for complex project structures
17
+ * - **Definition Tracking**: Manages code definitions and their relationships
18
+ * - **Path Normalization**: Automatically resolves paths based on package configuration
19
+ *
20
+ * @example Basic file creation
21
+ * ```typescript
22
+ * import { File } from '@skmtc/core';
23
+ *
24
+ * const file = new File({
25
+ * path: './src/models/User.ts',
26
+ * settings: clientSettings
27
+ * });
28
+ *
29
+ * // Add imports
30
+ * file.imports.set('./types', new Set(['BaseModel', 'Validator']));
31
+ *
32
+ * // Add definitions
33
+ * file.definitions.set('User', userInterface);
34
+ *
35
+ * // Generate file content
36
+ * const content = file.toString();
37
+ * console.log(content);
38
+ * // import { BaseModel, Validator } from './types'
39
+ * //
40
+ * // export interface User extends BaseModel {
41
+ * // id: string;
42
+ * // name: string;
43
+ * // }
44
+ * ```
45
+ *
46
+ * @example With package configuration
47
+ * ```typescript
48
+ * const file = new File({
49
+ * path: './packages/client/src/api.ts',
50
+ * settings: {
51
+ * packages: [
52
+ * {
53
+ * rootPath: './packages/types',
54
+ * moduleName: '@myorg/types'
55
+ * }
56
+ * ]
57
+ * }
58
+ * });
59
+ *
60
+ * // Import from another package
61
+ * file.imports.set('./packages/types/models', new Set(['User']));
62
+ *
63
+ * // Will generate: import { User } from '@myorg/types/models'
64
+ * ```
65
+ *
66
+ * @example Re-exports
67
+ * ```typescript
68
+ * const file = new File({
69
+ * path: './src/index.ts',
70
+ * settings: clientSettings
71
+ * });
72
+ *
73
+ * // Add re-exports
74
+ * file.reExports.set('./models', {
75
+ * 'type': new Set(['User', 'Product']),
76
+ * 'const': new Set(['DEFAULT_CONFIG'])
77
+ * });
78
+ *
79
+ * // Will generate:
80
+ * // export type { User, Product } from './models'
81
+ * // export { DEFAULT_CONFIG } from './models'
82
+ * ```
83
+ */
5
84
  class File {
85
+ /**
86
+ * Creates a new File instance.
87
+ *
88
+ * @param args - File configuration
89
+ * @param args.path - The output path for this file
90
+ * @param args.settings - Client settings containing package configuration
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const file = new File({
95
+ * path: './src/generated/models.ts',
96
+ * settings: {
97
+ * packages: [
98
+ * { rootPath: './packages/shared', moduleName: '@company/shared' }
99
+ * ]
100
+ * }
101
+ * });
102
+ * ```
103
+ */
6
104
  constructor({ path, settings }) {
105
+ /** The file type, always 'ts' for TypeScript files */
7
106
  Object.defineProperty(this, "fileType", {
8
107
  enumerable: true,
9
108
  configurable: true,
10
109
  writable: true,
11
110
  value: 'ts'
12
111
  });
112
+ /** The file path for this generated file */
13
113
  Object.defineProperty(this, "path", {
14
114
  enumerable: true,
15
115
  configurable: true,
16
116
  writable: true,
17
117
  value: void 0
18
118
  });
119
+ /** Map of module paths to re-exported symbols organized by export type */
19
120
  Object.defineProperty(this, "reExports", {
20
121
  enumerable: true,
21
122
  configurable: true,
22
123
  writable: true,
23
124
  value: void 0
24
125
  });
126
+ /** Map of module paths to imported symbols */
25
127
  Object.defineProperty(this, "imports", {
26
128
  enumerable: true,
27
129
  configurable: true,
28
130
  writable: true,
29
131
  value: void 0
30
132
  });
133
+ /** Map of definition names to their Definition objects */
31
134
  Object.defineProperty(this, "definitions", {
32
135
  enumerable: true,
33
136
  configurable: true,
34
137
  writable: true,
35
138
  value: void 0
36
139
  });
140
+ /** Package configuration for path resolution */
37
141
  Object.defineProperty(this, "packages", {
38
142
  enumerable: true,
39
143
  configurable: true,
@@ -46,6 +150,47 @@ class File {
46
150
  this.definitions = new Map();
47
151
  this.packages = settings?.packages;
48
152
  }
153
+ /**
154
+ * Generates the complete TypeScript file content.
155
+ *
156
+ * This method orchestrates the rendering of all file components in the correct order:
157
+ * re-exports first, then imports, and finally definitions. It automatically handles
158
+ * module path normalization based on package configuration and filters out empty sections.
159
+ *
160
+ * @returns The complete TypeScript file content as a string
161
+ *
162
+ * @example Basic file generation
163
+ * ```typescript
164
+ * const file = new File({ path: './api.ts', settings: undefined });
165
+ *
166
+ * // Add some imports and definitions
167
+ * file.imports.set('./types', new Set(['User', 'Product']));
168
+ * file.definitions.set('ApiClient', someDefinition);
169
+ *
170
+ * const content = file.toString();
171
+ * console.log(content);
172
+ * // import { User, Product } from './types'
173
+ * //
174
+ * // export class ApiClient {
175
+ * // // ... definition content
176
+ * // }
177
+ * ```
178
+ *
179
+ * @example With re-exports
180
+ * ```typescript
181
+ * const file = new File({ path: './index.ts', settings: undefined });
182
+ *
183
+ * file.reExports.set('./models', {
184
+ * 'type': new Set(['User', 'Product']),
185
+ * 'const': new Set(['DEFAULT_CONFIG'])
186
+ * });
187
+ *
188
+ * const content = file.toString();
189
+ * console.log(content);
190
+ * // export type { User, Product } from './models'
191
+ * // export { DEFAULT_CONFIG } from './models'
192
+ * ```
193
+ */
49
194
  toString() {
50
195
  const reExports = Array.from(this.reExports.entries()).flatMap(([module, entityTypes]) => {
51
196
  const updatedModuleName = (0, exports.normaliseModuleName)({
@@ -76,6 +221,58 @@ class File {
76
221
  }
77
222
  }
78
223
  exports.File = File;
224
+ /**
225
+ * Normalizes module import/export paths based on package configuration.
226
+ *
227
+ * This function handles path resolution for complex project structures with multiple
228
+ * packages. It converts file system paths to appropriate module names based on:
229
+ * - Whether the destination and export paths are in the same package
230
+ * - Package-specific module naming conventions
231
+ * - Root path truncation for intra-package imports
232
+ *
233
+ * @param args - Path normalization arguments
234
+ * @param args.destinationPath - The path of the file that will contain the import/export
235
+ * @param args.exportPath - The original path being imported/exported from
236
+ * @param args.packages - Package configuration for path resolution (defaults to empty array)
237
+ * @returns The normalized module name to use in import/export statements
238
+ *
239
+ * @throws {Error} When a matching package is found but has no moduleName configured
240
+ *
241
+ * @example Cross-package import
242
+ * ```typescript
243
+ * const normalized = normaliseModuleName({
244
+ * destinationPath: './packages/client/src/api.ts',
245
+ * exportPath: './packages/types/models/User.ts',
246
+ * packages: [
247
+ * { rootPath: './packages/types', moduleName: '@company/types' },
248
+ * { rootPath: './packages/client', moduleName: '@company/client' }
249
+ * ]
250
+ * });
251
+ * console.log(normalized); // '@company/types'
252
+ * ```
253
+ *
254
+ * @example Intra-package import (same package)
255
+ * ```typescript
256
+ * const normalized = normaliseModuleName({
257
+ * destinationPath: './packages/types/src/index.ts',
258
+ * exportPath: './packages/types/models/User.ts',
259
+ * packages: [
260
+ * { rootPath: './packages/types', moduleName: '@company/types' }
261
+ * ]
262
+ * });
263
+ * console.log(normalized); // '@/models/User.ts' (truncates root path)
264
+ * ```
265
+ *
266
+ * @example No package match (returns original path)
267
+ * ```typescript
268
+ * const normalized = normaliseModuleName({
269
+ * destinationPath: './src/index.ts',
270
+ * exportPath: './src/utils.ts',
271
+ * packages: []
272
+ * });
273
+ * console.log(normalized); // './src/utils.ts'
274
+ * ```
275
+ */
79
276
  const normaliseModuleName = ({ destinationPath, exportPath, packages = [] }) => {
80
277
  const matchingModule = packages.find(packageModule => {
81
278
  return exportPath.startsWith(packageModule.rootPath);