@skmtc/core 0.0.783 → 0.0.786

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 (59) hide show
  1. package/esm/dsl/File.d.ts +208 -0
  2. package/esm/dsl/File.d.ts.map +1 -1
  3. package/esm/dsl/File.js +197 -0
  4. package/esm/dsl/Identifier.d.ts +152 -0
  5. package/esm/dsl/Identifier.d.ts.map +1 -1
  6. package/esm/dsl/Identifier.js +152 -0
  7. package/esm/dsl/Import.d.ts +221 -0
  8. package/esm/dsl/Import.d.ts.map +1 -1
  9. package/esm/dsl/Import.js +202 -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 +356 -1
  14. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  15. package/esm/dsl/operation/OperationBase.js +347 -1
  16. package/esm/oas/document/Document.d.ts +155 -1
  17. package/esm/oas/document/Document.d.ts.map +1 -1
  18. package/esm/oas/document/Document.js +141 -2
  19. package/esm/oas/object/Object.d.ts +255 -10
  20. package/esm/oas/object/Object.d.ts.map +1 -1
  21. package/esm/oas/object/Object.js +229 -10
  22. package/esm/types/GeneratorKeys.d.ts +336 -0
  23. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  24. package/esm/types/GeneratorKeys.js +243 -0
  25. package/esm/types/GeneratorType.d.ts +119 -0
  26. package/esm/types/GeneratorType.d.ts.map +1 -1
  27. package/esm/types/Method.d.ts +109 -0
  28. package/esm/types/Method.d.ts.map +1 -1
  29. package/esm/types/Method.js +84 -0
  30. package/package.json +5 -1
  31. package/script/dsl/File.d.ts +208 -0
  32. package/script/dsl/File.d.ts.map +1 -1
  33. package/script/dsl/File.js +197 -0
  34. package/script/dsl/Identifier.d.ts +152 -0
  35. package/script/dsl/Identifier.d.ts.map +1 -1
  36. package/script/dsl/Identifier.js +152 -0
  37. package/script/dsl/Import.d.ts +221 -0
  38. package/script/dsl/Import.d.ts.map +1 -1
  39. package/script/dsl/Import.js +202 -0
  40. package/script/dsl/model/ModelBase.d.ts +257 -0
  41. package/script/dsl/model/ModelBase.d.ts.map +1 -1
  42. package/script/dsl/model/ModelBase.js +248 -0
  43. package/script/dsl/operation/OperationBase.d.ts +356 -1
  44. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  45. package/script/dsl/operation/OperationBase.js +347 -1
  46. package/script/oas/document/Document.d.ts +155 -1
  47. package/script/oas/document/Document.d.ts.map +1 -1
  48. package/script/oas/document/Document.js +141 -2
  49. package/script/oas/object/Object.d.ts +255 -10
  50. package/script/oas/object/Object.d.ts.map +1 -1
  51. package/script/oas/object/Object.js +229 -10
  52. package/script/types/GeneratorKeys.d.ts +336 -0
  53. package/script/types/GeneratorKeys.d.ts.map +1 -1
  54. package/script/types/GeneratorKeys.js +243 -0
  55. package/script/types/GeneratorType.d.ts +119 -0
  56. package/script/types/GeneratorType.d.ts.map +1 -1
  57. package/script/types/Method.d.ts +109 -0
  58. package/script/types/Method.d.ts.map +1 -1
  59. package/script/types/Method.js +84 -0
package/esm/dsl/File.d.ts CHANGED
@@ -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"}
package/esm/dsl/File.js CHANGED
@@ -1,36 +1,140 @@
1
1
  import { Import } from './Import.js';
2
+ /**
3
+ * Represents a TypeScript file in the SKMTC DSL system.
4
+ *
5
+ * The `File` class is a core component for generating TypeScript files with proper
6
+ * import management, re-exports, and content organization. It automatically handles
7
+ * module resolution, import optimization, and package-aware path normalization.
8
+ *
9
+ * ## Key Features
10
+ *
11
+ * - **Import Management**: Automatically tracks and organizes imports from other modules
12
+ * - **Re-export Handling**: Supports re-exporting symbols from other modules
13
+ * - **Package Awareness**: Handles module packages for complex project structures
14
+ * - **Definition Tracking**: Manages code definitions and their relationships
15
+ * - **Path Normalization**: Automatically resolves paths based on package configuration
16
+ *
17
+ * @example Basic file creation
18
+ * ```typescript
19
+ * import { File } from '@skmtc/core';
20
+ *
21
+ * const file = new File({
22
+ * path: './src/models/User.ts',
23
+ * settings: clientSettings
24
+ * });
25
+ *
26
+ * // Add imports
27
+ * file.imports.set('./types', new Set(['BaseModel', 'Validator']));
28
+ *
29
+ * // Add definitions
30
+ * file.definitions.set('User', userInterface);
31
+ *
32
+ * // Generate file content
33
+ * const content = file.toString();
34
+ * console.log(content);
35
+ * // import { BaseModel, Validator } from './types'
36
+ * //
37
+ * // export interface User extends BaseModel {
38
+ * // id: string;
39
+ * // name: string;
40
+ * // }
41
+ * ```
42
+ *
43
+ * @example With package configuration
44
+ * ```typescript
45
+ * const file = new File({
46
+ * path: './packages/client/src/api.ts',
47
+ * settings: {
48
+ * packages: [
49
+ * {
50
+ * rootPath: './packages/types',
51
+ * moduleName: '@myorg/types'
52
+ * }
53
+ * ]
54
+ * }
55
+ * });
56
+ *
57
+ * // Import from another package
58
+ * file.imports.set('./packages/types/models', new Set(['User']));
59
+ *
60
+ * // Will generate: import { User } from '@myorg/types/models'
61
+ * ```
62
+ *
63
+ * @example Re-exports
64
+ * ```typescript
65
+ * const file = new File({
66
+ * path: './src/index.ts',
67
+ * settings: clientSettings
68
+ * });
69
+ *
70
+ * // Add re-exports
71
+ * file.reExports.set('./models', {
72
+ * 'type': new Set(['User', 'Product']),
73
+ * 'const': new Set(['DEFAULT_CONFIG'])
74
+ * });
75
+ *
76
+ * // Will generate:
77
+ * // export type { User, Product } from './models'
78
+ * // export { DEFAULT_CONFIG } from './models'
79
+ * ```
80
+ */
2
81
  export class File {
82
+ /**
83
+ * Creates a new File instance.
84
+ *
85
+ * @param args - File configuration
86
+ * @param args.path - The output path for this file
87
+ * @param args.settings - Client settings containing package configuration
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const file = new File({
92
+ * path: './src/generated/models.ts',
93
+ * settings: {
94
+ * packages: [
95
+ * { rootPath: './packages/shared', moduleName: '@company/shared' }
96
+ * ]
97
+ * }
98
+ * });
99
+ * ```
100
+ */
3
101
  constructor({ path, settings }) {
102
+ /** The file type, always 'ts' for TypeScript files */
4
103
  Object.defineProperty(this, "fileType", {
5
104
  enumerable: true,
6
105
  configurable: true,
7
106
  writable: true,
8
107
  value: 'ts'
9
108
  });
109
+ /** The file path for this generated file */
10
110
  Object.defineProperty(this, "path", {
11
111
  enumerable: true,
12
112
  configurable: true,
13
113
  writable: true,
14
114
  value: void 0
15
115
  });
116
+ /** Map of module paths to re-exported symbols organized by export type */
16
117
  Object.defineProperty(this, "reExports", {
17
118
  enumerable: true,
18
119
  configurable: true,
19
120
  writable: true,
20
121
  value: void 0
21
122
  });
123
+ /** Map of module paths to imported symbols */
22
124
  Object.defineProperty(this, "imports", {
23
125
  enumerable: true,
24
126
  configurable: true,
25
127
  writable: true,
26
128
  value: void 0
27
129
  });
130
+ /** Map of definition names to their Definition objects */
28
131
  Object.defineProperty(this, "definitions", {
29
132
  enumerable: true,
30
133
  configurable: true,
31
134
  writable: true,
32
135
  value: void 0
33
136
  });
137
+ /** Package configuration for path resolution */
34
138
  Object.defineProperty(this, "packages", {
35
139
  enumerable: true,
36
140
  configurable: true,
@@ -43,6 +147,47 @@ export class File {
43
147
  this.definitions = new Map();
44
148
  this.packages = settings?.packages;
45
149
  }
150
+ /**
151
+ * Generates the complete TypeScript file content.
152
+ *
153
+ * This method orchestrates the rendering of all file components in the correct order:
154
+ * re-exports first, then imports, and finally definitions. It automatically handles
155
+ * module path normalization based on package configuration and filters out empty sections.
156
+ *
157
+ * @returns The complete TypeScript file content as a string
158
+ *
159
+ * @example Basic file generation
160
+ * ```typescript
161
+ * const file = new File({ path: './api.ts', settings: undefined });
162
+ *
163
+ * // Add some imports and definitions
164
+ * file.imports.set('./types', new Set(['User', 'Product']));
165
+ * file.definitions.set('ApiClient', someDefinition);
166
+ *
167
+ * const content = file.toString();
168
+ * console.log(content);
169
+ * // import { User, Product } from './types'
170
+ * //
171
+ * // export class ApiClient {
172
+ * // // ... definition content
173
+ * // }
174
+ * ```
175
+ *
176
+ * @example With re-exports
177
+ * ```typescript
178
+ * const file = new File({ path: './index.ts', settings: undefined });
179
+ *
180
+ * file.reExports.set('./models', {
181
+ * 'type': new Set(['User', 'Product']),
182
+ * 'const': new Set(['DEFAULT_CONFIG'])
183
+ * });
184
+ *
185
+ * const content = file.toString();
186
+ * console.log(content);
187
+ * // export type { User, Product } from './models'
188
+ * // export { DEFAULT_CONFIG } from './models'
189
+ * ```
190
+ */
46
191
  toString() {
47
192
  const reExports = Array.from(this.reExports.entries()).flatMap(([module, entityTypes]) => {
48
193
  const updatedModuleName = normaliseModuleName({
@@ -72,6 +217,58 @@ export class File {
72
217
  .join('\n\n');
73
218
  }
74
219
  }
220
+ /**
221
+ * Normalizes module import/export paths based on package configuration.
222
+ *
223
+ * This function handles path resolution for complex project structures with multiple
224
+ * packages. It converts file system paths to appropriate module names based on:
225
+ * - Whether the destination and export paths are in the same package
226
+ * - Package-specific module naming conventions
227
+ * - Root path truncation for intra-package imports
228
+ *
229
+ * @param args - Path normalization arguments
230
+ * @param args.destinationPath - The path of the file that will contain the import/export
231
+ * @param args.exportPath - The original path being imported/exported from
232
+ * @param args.packages - Package configuration for path resolution (defaults to empty array)
233
+ * @returns The normalized module name to use in import/export statements
234
+ *
235
+ * @throws {Error} When a matching package is found but has no moduleName configured
236
+ *
237
+ * @example Cross-package import
238
+ * ```typescript
239
+ * const normalized = normaliseModuleName({
240
+ * destinationPath: './packages/client/src/api.ts',
241
+ * exportPath: './packages/types/models/User.ts',
242
+ * packages: [
243
+ * { rootPath: './packages/types', moduleName: '@company/types' },
244
+ * { rootPath: './packages/client', moduleName: '@company/client' }
245
+ * ]
246
+ * });
247
+ * console.log(normalized); // '@company/types'
248
+ * ```
249
+ *
250
+ * @example Intra-package import (same package)
251
+ * ```typescript
252
+ * const normalized = normaliseModuleName({
253
+ * destinationPath: './packages/types/src/index.ts',
254
+ * exportPath: './packages/types/models/User.ts',
255
+ * packages: [
256
+ * { rootPath: './packages/types', moduleName: '@company/types' }
257
+ * ]
258
+ * });
259
+ * console.log(normalized); // '@/models/User.ts' (truncates root path)
260
+ * ```
261
+ *
262
+ * @example No package match (returns original path)
263
+ * ```typescript
264
+ * const normalized = normaliseModuleName({
265
+ * destinationPath: './src/index.ts',
266
+ * exportPath: './src/utils.ts',
267
+ * packages: []
268
+ * });
269
+ * console.log(normalized); // './src/utils.ts'
270
+ * ```
271
+ */
75
272
  export const normaliseModuleName = ({ destinationPath, exportPath, packages = [] }) => {
76
273
  const matchingModule = packages.find(packageModule => {
77
274
  return exportPath.startsWith(packageModule.rootPath);
@@ -1,11 +1,163 @@
1
1
  import { EntityType } from './EntityType.js';
2
+ /**
3
+ * Represents a TypeScript identifier in the SKMTC DSL system.
4
+ *
5
+ * The `Identifier` class encapsulates named entities in generated code,
6
+ * providing type-safe creation and management of variables, types, and other
7
+ * identifiers. It distinguishes between different kinds of identifiers and
8
+ * optionally tracks type information.
9
+ *
10
+ * This class uses factory methods instead of direct construction to ensure
11
+ * proper entity type classification and to provide a cleaner API.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Type Safety**: Distinguishes between variables, types, and other entities
16
+ * - **Factory Methods**: Provides semantic constructors for different identifier types
17
+ * - **Optional Typing**: Can associate type information with variable identifiers
18
+ * - **String Conversion**: Clean string representation for code generation
19
+ *
20
+ * @example Creating variable identifiers
21
+ * ```typescript
22
+ * import { Identifier } from '@skmtc/core';
23
+ *
24
+ * // Simple variable without type
25
+ * const userName = Identifier.createVariable('userName');
26
+ * console.log(userName.toString()); // 'userName'
27
+ *
28
+ * // Typed variable
29
+ * const userId = Identifier.createVariable('userId', 'string');
30
+ * console.log(userId.name); // 'userId'
31
+ * console.log(userId.typeName); // 'string'
32
+ * ```
33
+ *
34
+ * @example Creating type identifiers
35
+ * ```typescript
36
+ * // Type identifier
37
+ * const userType = Identifier.createType('User');
38
+ * console.log(userType.toString()); // 'User'
39
+ * console.log(userType.entityType.value); // 'type'
40
+ * ```
41
+ *
42
+ * @example Using in code generation
43
+ * ```typescript
44
+ * import { Definition, Identifier } from '@skmtc/core';
45
+ *
46
+ * class ApiGenerator {
47
+ * generateFunction(name: string) {
48
+ * const funcId = Identifier.createVariable(name);
49
+ * const requestType = Identifier.createType('RequestType');
50
+ *
51
+ * return new Definition({
52
+ * name: funcId.name,
53
+ * content: `function ${funcId}(data: ${requestType}) {
54
+ * // Implementation
55
+ * }`
56
+ * });
57
+ * }
58
+ * }
59
+ * ```
60
+ */
2
61
  export declare class Identifier {
62
+ /** The identifier name */
3
63
  name: string;
64
+ /** The entity type (variable, type, etc.) */
4
65
  entityType: EntityType;
66
+ /** Optional type name for typed variables */
5
67
  typeName?: string;
68
+ /**
69
+ * Creates a new Identifier instance.
70
+ *
71
+ * This constructor is private to enforce the use of factory methods
72
+ * that provide better semantic clarity and type safety.
73
+ *
74
+ * @param args - Identifier configuration
75
+ */
6
76
  private constructor();
77
+ /**
78
+ * Creates a variable identifier with optional type information.
79
+ *
80
+ * This factory method creates an identifier for variables, constants,
81
+ * function parameters, and other value-based entities. Optionally
82
+ * associates type information for typed variables.
83
+ *
84
+ * @param name - The variable name
85
+ * @param typeName - Optional type name for the variable
86
+ * @returns A new variable Identifier instance
87
+ *
88
+ * @example Untyped variable
89
+ * ```typescript
90
+ * const count = Identifier.createVariable('count');
91
+ * console.log(count.name); // 'count'
92
+ * console.log(count.typeName); // undefined
93
+ * ```
94
+ *
95
+ * @example Typed variable
96
+ * ```typescript
97
+ * const userId = Identifier.createVariable('userId', 'string');
98
+ * console.log(userId.name); // 'userId'
99
+ * console.log(userId.typeName); // 'string'
100
+ * ```
101
+ *
102
+ * @example In function generation
103
+ * ```typescript
104
+ * const param = Identifier.createVariable('data', 'RequestData');
105
+ * const funcDef = `function processRequest(${param.name}: ${param.typeName}) {}`;
106
+ * ```
107
+ */
7
108
  static createVariable(name: string, typeName?: string): Identifier;
109
+ /**
110
+ * Creates a type identifier for TypeScript types.
111
+ *
112
+ * This factory method creates an identifier for type entities like
113
+ * interfaces, type aliases, classes, and other type-level constructs.
114
+ * Type identifiers don't have associated type information since they
115
+ * represent types themselves.
116
+ *
117
+ * @param name - The type name
118
+ * @returns A new type Identifier instance
119
+ *
120
+ * @example Interface type
121
+ * ```typescript
122
+ * const userInterface = Identifier.createType('User');
123
+ * console.log(userInterface.name); // 'User'
124
+ * console.log(userInterface.entityType.value); // 'type'
125
+ * ```
126
+ *
127
+ * @example Type alias
128
+ * ```typescript
129
+ * const statusType = Identifier.createType('Status');
130
+ * const typeDef = `type ${statusType} = 'pending' | 'complete'`;
131
+ * ```
132
+ *
133
+ * @example Generic type
134
+ * ```typescript
135
+ * const responseType = Identifier.createType('ApiResponse');
136
+ * const genericDef = `interface ${responseType}<T> { data: T; success: boolean; }`;
137
+ * ```
138
+ */
8
139
  static createType(name: string): Identifier;
140
+ /**
141
+ * Returns the string representation of the identifier.
142
+ *
143
+ * This method simply returns the identifier name, which is the most
144
+ * common usage when generating code. The name can be used directly
145
+ * in code generation contexts.
146
+ *
147
+ * @returns The identifier name as a string
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const variable = Identifier.createVariable('userName');
152
+ * const typeId = Identifier.createType('User');
153
+ *
154
+ * console.log(variable.toString()); // 'userName'
155
+ * console.log(typeId.toString()); // 'User'
156
+ *
157
+ * // Can be used directly in template strings
158
+ * const code = `const ${variable}: ${typeId} = getUserData();`;
159
+ * ```
160
+ */
9
161
  toString(): string;
10
162
  }
11
163
  //# sourceMappingURL=Identifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../../src/dsl/Identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAQ5C,qBAAa,UAAU;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,OAAO;IAMP,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU;IAelE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAO3C,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"Identifier.d.ts","sourceRoot":"","sources":["../../src/dsl/Identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAc5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,qBAAa,UAAU;IACrB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IAEZ,6CAA6C;IAC7C,UAAU,EAAE,UAAU,CAAA;IAEtB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;;;;OAOG;IACH,OAAO;IAMP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU;IAelE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAO3C;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}