@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
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);