@skmtc/core 0.0.783 → 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.
@@ -12,17 +12,192 @@ import type { RefName } from '../../types/RefName.js';
12
12
  import { OasSchema } from '../../oas/schema/Schema.js';
13
13
  import { OasRef } from '../../oas/ref/Ref.js';
14
14
  import { OasVoid } from '../../oas/void/Void.js';
15
+ /**
16
+ * Constructor arguments for {@link OperationBase}.
17
+ *
18
+ * @template EnrichmentType - Optional type for custom enrichment data
19
+ */
15
20
  export type OperationBaseArgs<EnrichmentType = undefined> = {
21
+ /** The generation context providing access to the processing pipeline */
16
22
  context: GenerateContext;
23
+ /** Content settings including export path and enrichment configuration */
17
24
  settings: ContentSettings<EnrichmentType>;
25
+ /** Unique identifier for this generator type */
18
26
  generatorKey: GeneratorKey;
27
+ /** The OpenAPI operation being processed */
19
28
  operation: OasOperation;
20
29
  };
30
+ /**
31
+ * Base class for operation generators in the SKMTC DSL system.
32
+ *
33
+ * `OperationBase` extends {@link ContentBase} to provide specialized functionality for
34
+ * generating code from OpenAPI operations. It offers type-safe methods for inserting
35
+ * related operations and models, managing complex operation dependencies, and handling
36
+ * enrichments specific to API operations.
37
+ *
38
+ * This class serves as the foundation for creating custom operation generators that
39
+ * transform OpenAPI operations into various code artifacts like API clients, server
40
+ * handlers, validation middleware, or documentation.
41
+ *
42
+ * ## Key Features
43
+ *
44
+ * - **Operation Insertion**: Insert related operations with automatic dependency tracking
45
+ * - **Model Integration**: Seamlessly insert related models from operation schemas
46
+ * - **Schema Normalization**: Handle complex request/response schema references
47
+ * - **Export Management**: Control which operations are exported from generated files
48
+ * - **Enrichment Support**: Extend functionality with operation-specific enrichment data
49
+ * - **Type Safety**: Full TypeScript support with generic enrichment types
50
+ *
51
+ * @template EnrichmentType - Optional type for custom enrichment data
52
+ *
53
+ * @example Basic API client generator
54
+ * ```typescript
55
+ * import { OperationBase, Definition } from '@skmtc/core';
56
+ *
57
+ * class ApiClientMethod extends OperationBase {
58
+ * toDefinition(): Definition {
59
+ * const { method, path, operationId } = this.operation;
60
+ *
61
+ * return new Definition({
62
+ * name: operationId || `${method}${this.pascalCasePath()}`,
63
+ * content: `async ${operationId}(${this.generateParameters()}) {
64
+ * return this.request('${method}', '${path}', ${this.generateRequestBody()});
65
+ * }`
66
+ * });
67
+ * }
68
+ * }
69
+ * ```
70
+ *
71
+ * @example With request/response models
72
+ * ```typescript
73
+ * class TypedApiMethod extends OperationBase {
74
+ * toDefinition(): Definition {
75
+ * const operation = this.operation;
76
+ *
77
+ * // Generate request model if needed
78
+ * let requestType = 'void';
79
+ * if (operation.requestBody?.content?.['application/json']?.schema) {
80
+ * const requestModel = this.insertNormalizedModel(
81
+ * new RequestModel({ ... }),
82
+ * {
83
+ * schema: operation.requestBody.content['application/json'].schema,
84
+ * fallbackName: `${operation.operationId}Request`
85
+ * }
86
+ * );
87
+ * requestType = requestModel.value;
88
+ * }
89
+ *
90
+ * // Generate response model
91
+ * const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
92
+ * const responseModel = this.insertNormalizedModel(
93
+ * new ResponseModel({ ... }),
94
+ * { schema: responseSchema, fallbackName: `${operation.operationId}Response` }
95
+ * );
96
+ *
97
+ * return new Definition({
98
+ * name: operation.operationId,
99
+ * content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}> {
100
+ * return this.request('${operation.method}', '${operation.path}', data);
101
+ * }`
102
+ * });
103
+ * }
104
+ * }
105
+ * ```
106
+ *
107
+ * @example With enrichments
108
+ * ```typescript
109
+ * type AuthEnrichment = {
110
+ * requiresAuth: boolean;
111
+ * permissions: string[];
112
+ * };
113
+ *
114
+ * class SecuredApiMethod extends OperationBase<AuthEnrichment> {
115
+ * toDefinition(): Definition {
116
+ * const enrichment = this.settings.enrichment;
117
+ * const requiresAuth = enrichment?.requiresAuth ?? false;
118
+ *
119
+ * const authCheck = requiresAuth
120
+ * ? 'this.checkAuth();'
121
+ * : '';
122
+ *
123
+ * return new Definition({
124
+ * name: this.operation.operationId,
125
+ * content: `async ${this.operation.operationId}() {
126
+ * ${authCheck}
127
+ * return this.request('${this.operation.method}', '${this.operation.path}');
128
+ * }`
129
+ * });
130
+ * }
131
+ * }
132
+ * ```
133
+ */
21
134
  export declare class OperationBase<EnrichmentType = undefined> extends ContentBase {
135
+ /** Content settings including export path and enrichment configuration */
22
136
  settings: ContentSettings<EnrichmentType>;
137
+ /** The OpenAPI operation being processed */
23
138
  operation: OasOperation;
139
+ /** Generator key identifying this generator type */
24
140
  generatorKey: GeneratorKey;
141
+ /**
142
+ * Creates a new OperationBase instance.
143
+ *
144
+ * @param args - Operation generator configuration
145
+ * @param args.context - The generation context providing pipeline access
146
+ * @param args.settings - Content settings with export path and enrichments
147
+ * @param args.generatorKey - Unique identifier for this generator type
148
+ * @param args.operation - The OpenAPI operation being processed
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const operation = new OperationBase({
153
+ * context: generateContext,
154
+ * settings: {
155
+ * exportPath: './src/api.ts',
156
+ * enrichment: customEnrichments
157
+ * },
158
+ * generatorKey: 'api-client',
159
+ * operation: oasOperation
160
+ * });
161
+ * ```
162
+ */
25
163
  constructor({ context, generatorKey, settings, operation }: OperationBaseArgs<EnrichmentType>);
164
+ /**
165
+ * Inserts a related operation with forced generation.
166
+ *
167
+ * This method adds a related operation to the current generation context, ensuring
168
+ * it will be generated regardless of whether it already exists. This is useful for
169
+ * operations that depend on other operations or need to generate helper operations.
170
+ *
171
+ * @template V - Type of generated value returned by the insertable
172
+ * @template EnrichmentType - Type of enrichment data for the insertable
173
+ * @param insertable - The operation generator to insert
174
+ * @param operation - The OpenAPI operation to process
175
+ * @param options - Insertion options
176
+ * @param options.noExport - Whether to skip exporting the inserted operation
177
+ * @returns Inserted operation reference with generated value
178
+ *
179
+ * @example Inserting helper operations
180
+ * ```typescript
181
+ * class CrudApiClient extends OperationBase {
182
+ * toDefinition(): Definition {
183
+ * // Insert a related validation operation
184
+ * const validator = this.insertOperation(
185
+ * new ValidationOperation({ ... }),
186
+ * this.operation,
187
+ * { noExport: true }
188
+ * );
189
+ *
190
+ * return new Definition({
191
+ * name: this.operation.operationId,
192
+ * content: `async ${this.operation.operationId}(data: any) {
193
+ * ${validator.value}(data);
194
+ * return this.request('${this.operation.method}', '${this.operation.path}', data);
195
+ * }`
196
+ * });
197
+ * }
198
+ * }
199
+ * ```
200
+ */
26
201
  insertOperation<V extends GeneratedValue, EnrichmentType = undefined>(insertable: OperationInsertable<V, EnrichmentType>, operation: OasOperation, options?: Pick<InsertOperationOptions<'force'>, 'noExport'>): Inserted<V, 'force', EnrichmentType>;
27
202
  insertModel<V extends GeneratedValue, EnrichmentType = undefined>(insertable: ModelInsertable<V, EnrichmentType>, refName: RefName, options?: Pick<InsertModelOptions<'force'>, 'noExport'>): Inserted<V, 'force', EnrichmentType>;
28
203
  insertNormalizedModel<V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid, EnrichmentType = undefined>(insertable: ModelInsertable<V, EnrichmentType>, { schema, fallbackName }: Omit<InsertNormalisedModelArgs<Schema>, 'destinationPath'>, options?: Pick<InsertModelOptions<'force'>, 'noExport'>): InsertNormalisedModelReturn<V, Schema>;
@@ -1 +1 @@
1
- {"version":3,"file":"OperationBase.d.ts","sourceRoot":"","sources":["../../../src/dsl/operation/OperationBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA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iB,CAAC,CAAC,SAAS,cAAc,EAAE,EAC1C,UAAU,EACV,KAAK,EACL,QAAQ,EACT,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAS3D,QAAQ,CAAC,IAAI,EAAE,gBAAgB;CAMzC"}
@@ -1,19 +1,148 @@
1
1
  import { ContentBase } from '../ContentBase.js';
2
+ /**
3
+ * Base class for operation generators in the SKMTC DSL system.
4
+ *
5
+ * `OperationBase` extends {@link ContentBase} to provide specialized functionality for
6
+ * generating code from OpenAPI operations. It offers type-safe methods for inserting
7
+ * related operations and models, managing complex operation dependencies, and handling
8
+ * enrichments specific to API operations.
9
+ *
10
+ * This class serves as the foundation for creating custom operation generators that
11
+ * transform OpenAPI operations into various code artifacts like API clients, server
12
+ * handlers, validation middleware, or documentation.
13
+ *
14
+ * ## Key Features
15
+ *
16
+ * - **Operation Insertion**: Insert related operations with automatic dependency tracking
17
+ * - **Model Integration**: Seamlessly insert related models from operation schemas
18
+ * - **Schema Normalization**: Handle complex request/response schema references
19
+ * - **Export Management**: Control which operations are exported from generated files
20
+ * - **Enrichment Support**: Extend functionality with operation-specific enrichment data
21
+ * - **Type Safety**: Full TypeScript support with generic enrichment types
22
+ *
23
+ * @template EnrichmentType - Optional type for custom enrichment data
24
+ *
25
+ * @example Basic API client generator
26
+ * ```typescript
27
+ * import { OperationBase, Definition } from '@skmtc/core';
28
+ *
29
+ * class ApiClientMethod extends OperationBase {
30
+ * toDefinition(): Definition {
31
+ * const { method, path, operationId } = this.operation;
32
+ *
33
+ * return new Definition({
34
+ * name: operationId || `${method}${this.pascalCasePath()}`,
35
+ * content: `async ${operationId}(${this.generateParameters()}) {
36
+ * return this.request('${method}', '${path}', ${this.generateRequestBody()});
37
+ * }`
38
+ * });
39
+ * }
40
+ * }
41
+ * ```
42
+ *
43
+ * @example With request/response models
44
+ * ```typescript
45
+ * class TypedApiMethod extends OperationBase {
46
+ * toDefinition(): Definition {
47
+ * const operation = this.operation;
48
+ *
49
+ * // Generate request model if needed
50
+ * let requestType = 'void';
51
+ * if (operation.requestBody?.content?.['application/json']?.schema) {
52
+ * const requestModel = this.insertNormalizedModel(
53
+ * new RequestModel({ ... }),
54
+ * {
55
+ * schema: operation.requestBody.content['application/json'].schema,
56
+ * fallbackName: `${operation.operationId}Request`
57
+ * }
58
+ * );
59
+ * requestType = requestModel.value;
60
+ * }
61
+ *
62
+ * // Generate response model
63
+ * const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
64
+ * const responseModel = this.insertNormalizedModel(
65
+ * new ResponseModel({ ... }),
66
+ * { schema: responseSchema, fallbackName: `${operation.operationId}Response` }
67
+ * );
68
+ *
69
+ * return new Definition({
70
+ * name: operation.operationId,
71
+ * content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}> {
72
+ * return this.request('${operation.method}', '${operation.path}', data);
73
+ * }`
74
+ * });
75
+ * }
76
+ * }
77
+ * ```
78
+ *
79
+ * @example With enrichments
80
+ * ```typescript
81
+ * type AuthEnrichment = {
82
+ * requiresAuth: boolean;
83
+ * permissions: string[];
84
+ * };
85
+ *
86
+ * class SecuredApiMethod extends OperationBase<AuthEnrichment> {
87
+ * toDefinition(): Definition {
88
+ * const enrichment = this.settings.enrichment;
89
+ * const requiresAuth = enrichment?.requiresAuth ?? false;
90
+ *
91
+ * const authCheck = requiresAuth
92
+ * ? 'this.checkAuth();'
93
+ * : '';
94
+ *
95
+ * return new Definition({
96
+ * name: this.operation.operationId,
97
+ * content: `async ${this.operation.operationId}() {
98
+ * ${authCheck}
99
+ * return this.request('${this.operation.method}', '${this.operation.path}');
100
+ * }`
101
+ * });
102
+ * }
103
+ * }
104
+ * ```
105
+ */
2
106
  export class OperationBase extends ContentBase {
107
+ /**
108
+ * Creates a new OperationBase instance.
109
+ *
110
+ * @param args - Operation generator configuration
111
+ * @param args.context - The generation context providing pipeline access
112
+ * @param args.settings - Content settings with export path and enrichments
113
+ * @param args.generatorKey - Unique identifier for this generator type
114
+ * @param args.operation - The OpenAPI operation being processed
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const operation = new OperationBase({
119
+ * context: generateContext,
120
+ * settings: {
121
+ * exportPath: './src/api.ts',
122
+ * enrichment: customEnrichments
123
+ * },
124
+ * generatorKey: 'api-client',
125
+ * operation: oasOperation
126
+ * });
127
+ * ```
128
+ */
3
129
  constructor({ context, generatorKey, settings, operation }) {
4
130
  super({ context });
131
+ /** Content settings including export path and enrichment configuration */
5
132
  Object.defineProperty(this, "settings", {
6
133
  enumerable: true,
7
134
  configurable: true,
8
135
  writable: true,
9
136
  value: void 0
10
137
  });
138
+ /** The OpenAPI operation being processed */
11
139
  Object.defineProperty(this, "operation", {
12
140
  enumerable: true,
13
141
  configurable: true,
14
142
  writable: true,
15
143
  value: void 0
16
144
  });
145
+ /** Generator key identifying this generator type */
17
146
  Object.defineProperty(this, "generatorKey", {
18
147
  enumerable: true,
19
148
  configurable: true,
@@ -24,6 +153,43 @@ export class OperationBase extends ContentBase {
24
153
  this.operation = operation;
25
154
  this.settings = settings;
26
155
  }
156
+ /**
157
+ * Inserts a related operation with forced generation.
158
+ *
159
+ * This method adds a related operation to the current generation context, ensuring
160
+ * it will be generated regardless of whether it already exists. This is useful for
161
+ * operations that depend on other operations or need to generate helper operations.
162
+ *
163
+ * @template V - Type of generated value returned by the insertable
164
+ * @template EnrichmentType - Type of enrichment data for the insertable
165
+ * @param insertable - The operation generator to insert
166
+ * @param operation - The OpenAPI operation to process
167
+ * @param options - Insertion options
168
+ * @param options.noExport - Whether to skip exporting the inserted operation
169
+ * @returns Inserted operation reference with generated value
170
+ *
171
+ * @example Inserting helper operations
172
+ * ```typescript
173
+ * class CrudApiClient extends OperationBase {
174
+ * toDefinition(): Definition {
175
+ * // Insert a related validation operation
176
+ * const validator = this.insertOperation(
177
+ * new ValidationOperation({ ... }),
178
+ * this.operation,
179
+ * { noExport: true }
180
+ * );
181
+ *
182
+ * return new Definition({
183
+ * name: this.operation.operationId,
184
+ * content: `async ${this.operation.operationId}(data: any) {
185
+ * ${validator.value}(data);
186
+ * return this.request('${this.operation.method}', '${this.operation.path}', data);
187
+ * }`
188
+ * });
189
+ * }
190
+ * }
191
+ * ```
192
+ */
27
193
  insertOperation(insertable, operation, options = {}) {
28
194
  return this.context.insertOperation(insertable, operation, {
29
195
  generation: 'force',
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.783",
3
+ "version": "0.0.785",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/skmtc/skmtc.git"
7
+ },
4
8
  "main": "./script/mod.js",
5
9
  "module": "./esm/mod.js",
6
10
  "exports": {
@@ -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,O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