@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
@@ -2,20 +2,90 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Identifier = void 0;
4
4
  const EntityType_js_1 = require("./EntityType.js");
5
+ /**
6
+ * Represents a TypeScript identifier in the SKMTC DSL system.
7
+ *
8
+ * The `Identifier` class encapsulates named entities in generated code,
9
+ * providing type-safe creation and management of variables, types, and other
10
+ * identifiers. It distinguishes between different kinds of identifiers and
11
+ * optionally tracks type information.
12
+ *
13
+ * This class uses factory methods instead of direct construction to ensure
14
+ * proper entity type classification and to provide a cleaner API.
15
+ *
16
+ * ## Key Features
17
+ *
18
+ * - **Type Safety**: Distinguishes between variables, types, and other entities
19
+ * - **Factory Methods**: Provides semantic constructors for different identifier types
20
+ * - **Optional Typing**: Can associate type information with variable identifiers
21
+ * - **String Conversion**: Clean string representation for code generation
22
+ *
23
+ * @example Creating variable identifiers
24
+ * ```typescript
25
+ * import { Identifier } from '@skmtc/core';
26
+ *
27
+ * // Simple variable without type
28
+ * const userName = Identifier.createVariable('userName');
29
+ * console.log(userName.toString()); // 'userName'
30
+ *
31
+ * // Typed variable
32
+ * const userId = Identifier.createVariable('userId', 'string');
33
+ * console.log(userId.name); // 'userId'
34
+ * console.log(userId.typeName); // 'string'
35
+ * ```
36
+ *
37
+ * @example Creating type identifiers
38
+ * ```typescript
39
+ * // Type identifier
40
+ * const userType = Identifier.createType('User');
41
+ * console.log(userType.toString()); // 'User'
42
+ * console.log(userType.entityType.value); // 'type'
43
+ * ```
44
+ *
45
+ * @example Using in code generation
46
+ * ```typescript
47
+ * import { Definition, Identifier } from '@skmtc/core';
48
+ *
49
+ * class ApiGenerator {
50
+ * generateFunction(name: string) {
51
+ * const funcId = Identifier.createVariable(name);
52
+ * const requestType = Identifier.createType('RequestType');
53
+ *
54
+ * return new Definition({
55
+ * name: funcId.name,
56
+ * content: `function ${funcId}(data: ${requestType}) {
57
+ * // Implementation
58
+ * }`
59
+ * });
60
+ * }
61
+ * }
62
+ * ```
63
+ */
5
64
  class Identifier {
65
+ /**
66
+ * Creates a new Identifier instance.
67
+ *
68
+ * This constructor is private to enforce the use of factory methods
69
+ * that provide better semantic clarity and type safety.
70
+ *
71
+ * @param args - Identifier configuration
72
+ */
6
73
  constructor({ name, typeName, entityType }) {
74
+ /** The identifier name */
7
75
  Object.defineProperty(this, "name", {
8
76
  enumerable: true,
9
77
  configurable: true,
10
78
  writable: true,
11
79
  value: void 0
12
80
  });
81
+ /** The entity type (variable, type, etc.) */
13
82
  Object.defineProperty(this, "entityType", {
14
83
  enumerable: true,
15
84
  configurable: true,
16
85
  writable: true,
17
86
  value: void 0
18
87
  });
88
+ /** Optional type name for typed variables */
19
89
  Object.defineProperty(this, "typeName", {
20
90
  enumerable: true,
21
91
  configurable: true,
@@ -26,6 +96,37 @@ class Identifier {
26
96
  this.typeName = typeName;
27
97
  this.entityType = entityType;
28
98
  }
99
+ /**
100
+ * Creates a variable identifier with optional type information.
101
+ *
102
+ * This factory method creates an identifier for variables, constants,
103
+ * function parameters, and other value-based entities. Optionally
104
+ * associates type information for typed variables.
105
+ *
106
+ * @param name - The variable name
107
+ * @param typeName - Optional type name for the variable
108
+ * @returns A new variable Identifier instance
109
+ *
110
+ * @example Untyped variable
111
+ * ```typescript
112
+ * const count = Identifier.createVariable('count');
113
+ * console.log(count.name); // 'count'
114
+ * console.log(count.typeName); // undefined
115
+ * ```
116
+ *
117
+ * @example Typed variable
118
+ * ```typescript
119
+ * const userId = Identifier.createVariable('userId', 'string');
120
+ * console.log(userId.name); // 'userId'
121
+ * console.log(userId.typeName); // 'string'
122
+ * ```
123
+ *
124
+ * @example In function generation
125
+ * ```typescript
126
+ * const param = Identifier.createVariable('data', 'RequestData');
127
+ * const funcDef = `function processRequest(${param.name}: ${param.typeName}) {}`;
128
+ * ```
129
+ */
29
130
  static createVariable(name, typeName) {
30
131
  if (typeName) {
31
132
  return new Identifier({
@@ -39,12 +140,63 @@ class Identifier {
39
140
  entityType: new EntityType_js_1.EntityType('variable')
40
141
  });
41
142
  }
143
+ /**
144
+ * Creates a type identifier for TypeScript types.
145
+ *
146
+ * This factory method creates an identifier for type entities like
147
+ * interfaces, type aliases, classes, and other type-level constructs.
148
+ * Type identifiers don't have associated type information since they
149
+ * represent types themselves.
150
+ *
151
+ * @param name - The type name
152
+ * @returns A new type Identifier instance
153
+ *
154
+ * @example Interface type
155
+ * ```typescript
156
+ * const userInterface = Identifier.createType('User');
157
+ * console.log(userInterface.name); // 'User'
158
+ * console.log(userInterface.entityType.value); // 'type'
159
+ * ```
160
+ *
161
+ * @example Type alias
162
+ * ```typescript
163
+ * const statusType = Identifier.createType('Status');
164
+ * const typeDef = `type ${statusType} = 'pending' | 'complete'`;
165
+ * ```
166
+ *
167
+ * @example Generic type
168
+ * ```typescript
169
+ * const responseType = Identifier.createType('ApiResponse');
170
+ * const genericDef = `interface ${responseType}<T> { data: T; success: boolean; }`;
171
+ * ```
172
+ */
42
173
  static createType(name) {
43
174
  return new Identifier({
44
175
  name,
45
176
  entityType: new EntityType_js_1.EntityType('type')
46
177
  });
47
178
  }
179
+ /**
180
+ * Returns the string representation of the identifier.
181
+ *
182
+ * This method simply returns the identifier name, which is the most
183
+ * common usage when generating code. The name can be used directly
184
+ * in code generation contexts.
185
+ *
186
+ * @returns The identifier name as a string
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const variable = Identifier.createVariable('userName');
191
+ * const typeId = Identifier.createType('User');
192
+ *
193
+ * console.log(variable.toString()); // 'userName'
194
+ * console.log(typeId.toString()); // 'User'
195
+ *
196
+ * // Can be used directly in template strings
197
+ * const code = `const ${variable}: ${typeId} = getUserData();`;
198
+ * ```
199
+ */
48
200
  toString() {
49
201
  return this.name;
50
202
  }
@@ -1,21 +1,242 @@
1
+ /**
2
+ * Constructor arguments for {@link Import}.
3
+ */
1
4
  type ConstructorArgs = {
5
+ /** The module path to import from */
2
6
  module: string;
7
+ /** Array of import names (can be strings or alias objects) */
3
8
  importNames: ImportNameArg[];
4
9
  };
10
+ /**
11
+ * Represents a TypeScript import statement in the SKMTC DSL system.
12
+ *
13
+ * The `Import` class generates properly formatted import statements for TypeScript
14
+ * files, handling named imports with optional aliases. It's used throughout the
15
+ * code generation pipeline to manage module dependencies.
16
+ *
17
+ * This class supports both simple string imports and aliased imports, making it
18
+ * easy to avoid naming conflicts and provide cleaner import statements.
19
+ *
20
+ * @example Basic named imports
21
+ * ```typescript
22
+ * import { Import } from '@skmtc/core';
23
+ *
24
+ * const basicImport = new Import({
25
+ * module: './types',
26
+ * importNames: ['User', 'Product', 'Order']
27
+ * });
28
+ *
29
+ * console.log(basicImport.toString());
30
+ * // import { User, Product, Order } from './types'
31
+ * ```
32
+ *
33
+ * @example Imports with aliases
34
+ * ```typescript
35
+ * const aliasedImport = new Import({
36
+ * module: 'react',
37
+ * importNames: [
38
+ * 'useState',
39
+ * 'useEffect',
40
+ * { 'default': 'React' } // Import default as React
41
+ * ]
42
+ * });
43
+ *
44
+ * console.log(aliasedImport.toString());
45
+ * // import { useState, useEffect, default as React } from 'react'
46
+ * ```
47
+ *
48
+ * @example Mixed imports
49
+ * ```typescript
50
+ * const mixedImport = new Import({
51
+ * module: './api/client',
52
+ * importNames: [
53
+ * 'ApiClient',
54
+ * { 'RequestOptions': 'Options' }, // Alias to avoid conflicts
55
+ * 'ResponseType'
56
+ * ]
57
+ * });
58
+ *
59
+ * console.log(mixedImport.toString());
60
+ * // import { ApiClient, RequestOptions as Options, ResponseType } from './api/client'
61
+ * ```
62
+ *
63
+ * @example Using in File generation
64
+ * ```typescript
65
+ * import { File, Import } from '@skmtc/core';
66
+ *
67
+ * const file = new File({ path: './generated.ts', settings: undefined });
68
+ *
69
+ * // Add import to file
70
+ * file.imports.set('./types', new Set(['User', 'Product']));
71
+ *
72
+ * // Or create Import directly for more control
73
+ * const customImport = new Import({
74
+ * module: './helpers',
75
+ * importNames: [{ 'validateEmail': 'emailValidator' }]
76
+ * });
77
+ * ```
78
+ */
5
79
  export declare class Import {
80
+ /** The module path to import from */
6
81
  module: string;
82
+ /** Array of parsed import names with potential aliases */
7
83
  importNames: ImportName[];
84
+ /**
85
+ * Creates a new Import instance.
86
+ *
87
+ * @param args - Import configuration
88
+ * @param args.module - The module path to import from (e.g., './types', 'react')
89
+ * @param args.importNames - Array of import names, can be strings or alias objects
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const importStatement = new Import({
94
+ * module: './models/User',
95
+ * importNames: [
96
+ * 'User', // Simple import
97
+ * { 'UserType': 'IUser' }, // Aliased import
98
+ * 'createUser' // Another simple import
99
+ * ]
100
+ * });
101
+ * ```
102
+ */
8
103
  constructor({ module, importNames }: ConstructorArgs);
104
+ /**
105
+ * Converts the import to a record format.
106
+ *
107
+ * This method creates a record representation where the module path is the key
108
+ * and the import names are the value. Useful for serialization or when working
109
+ * with import maps.
110
+ *
111
+ * @returns A record with module as key and import names as value
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const importStatement = new Import({
116
+ * module: './types',
117
+ * importNames: ['User', { 'Product': 'IProduct' }]
118
+ * });
119
+ *
120
+ * const record = importStatement.toRecord();
121
+ * console.log(record);
122
+ * // {
123
+ * // './types': ['User', { 'Product': 'IProduct' }]
124
+ * // }
125
+ * ```
126
+ */
9
127
  toRecord(): Record<string, ImportNameArg[]>;
128
+ /**
129
+ * Generates the TypeScript import statement string.
130
+ *
131
+ * This method produces a properly formatted ES6 import statement that can be
132
+ * written directly to a TypeScript file. It handles both simple and aliased
133
+ * imports correctly.
134
+ *
135
+ * @returns The formatted import statement string
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const basicImport = new Import({
140
+ * module: './utils',
141
+ * importNames: ['formatDate', 'parseJson']
142
+ * });
143
+ *
144
+ * console.log(basicImport.toString());
145
+ * // import { formatDate, parseJson } from './utils'
146
+ *
147
+ * const aliasedImport = new Import({
148
+ * module: 'lodash',
149
+ * importNames: [{ 'isEqual': 'deepEqual' }, 'cloneDeep']
150
+ * });
151
+ *
152
+ * console.log(aliasedImport.toString());
153
+ * // import { isEqual as deepEqual, cloneDeep } from 'lodash'
154
+ * ```
155
+ *
156
+ * @todo Move syntax to typescript package to enable language-agnostic use
157
+ */
10
158
  toString(): string;
11
159
  }
160
+ /**
161
+ * Argument type for import names - can be a simple string or an alias object.
162
+ *
163
+ * @example String import
164
+ * ```typescript
165
+ * const simpleImport: ImportNameArg = 'User';
166
+ * ```
167
+ *
168
+ * @example Aliased import
169
+ * ```typescript
170
+ * const aliasedImport: ImportNameArg = { 'User': 'IUser' };
171
+ * // This creates: User as IUser
172
+ * ```
173
+ */
12
174
  export type ImportNameArg = string | {
13
175
  [name: string]: string;
14
176
  };
177
+ /**
178
+ * Represents a single import name with optional aliasing.
179
+ *
180
+ * This class handles the parsing and formatting of individual import specifiers,
181
+ * supporting both simple imports and aliased imports. It's used internally by
182
+ * the {@link Import} class to manage import statement components.
183
+ *
184
+ * @example Simple import name
185
+ * ```typescript
186
+ * const simple = new ImportName('useState');
187
+ * console.log(simple.toString()); // 'useState'
188
+ * ```
189
+ *
190
+ * @example Aliased import name
191
+ * ```typescript
192
+ * const aliased = new ImportName({ 'React': 'ReactLib' });
193
+ * console.log(aliased.toString()); // 'React as ReactLib'
194
+ * ```
195
+ */
15
196
  export declare class ImportName {
197
+ /** The original name being imported */
16
198
  name: string;
199
+ /** The alias to use (if any) */
17
200
  alias?: string;
201
+ /**
202
+ * Creates a new ImportName instance.
203
+ *
204
+ * @param name - Either a string for simple imports or an object for aliased imports
205
+ *
206
+ * @example Simple import
207
+ * ```typescript
208
+ * const importName = new ImportName('User');
209
+ * // Results in: User
210
+ * ```
211
+ *
212
+ * @example Aliased import
213
+ * ```typescript
214
+ * const importName = new ImportName({ 'UserInterface': 'IUser' });
215
+ * // Results in: UserInterface as IUser
216
+ * ```
217
+ */
18
218
  constructor(name: ImportNameArg);
219
+ /**
220
+ * Generates the string representation of the import name.
221
+ *
222
+ * This method creates the appropriate import specifier syntax,
223
+ * either a simple name or an aliased import using TypeScript's
224
+ * 'as' keyword.
225
+ *
226
+ * @returns The formatted import specifier string
227
+ *
228
+ * @example Simple import
229
+ * ```typescript
230
+ * const simple = new ImportName('useState');
231
+ * console.log(simple.toString()); // 'useState'
232
+ * ```
233
+ *
234
+ * @example Aliased import
235
+ * ```typescript
236
+ * const aliased = new ImportName({ 'Component': 'ReactComponent' });
237
+ * console.log(aliased.toString()); // 'Component as ReactComponent'
238
+ * ```
239
+ */
19
240
  toString(): string;
20
241
  }
21
242
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Import.d.ts","sourceRoot":"","sources":["../../src/dsl/Import.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,aAAa,EAAE,CAAA;CAC7B,CAAA;AAED,qBAAa,MAAM;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,UAAU,EAAE,CAAA;gBAEb,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,eAAe;IAKpD,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;IAQ3C,QAAQ,IAAI,MAAM;CAKnB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAE/D,qBAAa,UAAU;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;gBAEF,IAAI,EAAE,aAAa;IAW/B,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"Import.d.ts","sourceRoot":"","sources":["../../src/dsl/Import.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,WAAW,EAAE,aAAa,EAAE,CAAA;CAC7B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,MAAM;IACjB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAA;IAEd,0DAA0D;IAC1D,WAAW,EAAE,UAAU,EAAE,CAAA;IAEzB;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,eAAe;IAKpD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;IAQ3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,QAAQ,IAAI,MAAM;CAKnB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAU;IACrB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IAEZ,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;;;;;;;;;;;;;OAgBG;gBACS,IAAI,EAAE,aAAa;IAW/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -1,14 +1,104 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportName = exports.Import = void 0;
4
+ /**
5
+ * Represents a TypeScript import statement in the SKMTC DSL system.
6
+ *
7
+ * The `Import` class generates properly formatted import statements for TypeScript
8
+ * files, handling named imports with optional aliases. It's used throughout the
9
+ * code generation pipeline to manage module dependencies.
10
+ *
11
+ * This class supports both simple string imports and aliased imports, making it
12
+ * easy to avoid naming conflicts and provide cleaner import statements.
13
+ *
14
+ * @example Basic named imports
15
+ * ```typescript
16
+ * import { Import } from '@skmtc/core';
17
+ *
18
+ * const basicImport = new Import({
19
+ * module: './types',
20
+ * importNames: ['User', 'Product', 'Order']
21
+ * });
22
+ *
23
+ * console.log(basicImport.toString());
24
+ * // import { User, Product, Order } from './types'
25
+ * ```
26
+ *
27
+ * @example Imports with aliases
28
+ * ```typescript
29
+ * const aliasedImport = new Import({
30
+ * module: 'react',
31
+ * importNames: [
32
+ * 'useState',
33
+ * 'useEffect',
34
+ * { 'default': 'React' } // Import default as React
35
+ * ]
36
+ * });
37
+ *
38
+ * console.log(aliasedImport.toString());
39
+ * // import { useState, useEffect, default as React } from 'react'
40
+ * ```
41
+ *
42
+ * @example Mixed imports
43
+ * ```typescript
44
+ * const mixedImport = new Import({
45
+ * module: './api/client',
46
+ * importNames: [
47
+ * 'ApiClient',
48
+ * { 'RequestOptions': 'Options' }, // Alias to avoid conflicts
49
+ * 'ResponseType'
50
+ * ]
51
+ * });
52
+ *
53
+ * console.log(mixedImport.toString());
54
+ * // import { ApiClient, RequestOptions as Options, ResponseType } from './api/client'
55
+ * ```
56
+ *
57
+ * @example Using in File generation
58
+ * ```typescript
59
+ * import { File, Import } from '@skmtc/core';
60
+ *
61
+ * const file = new File({ path: './generated.ts', settings: undefined });
62
+ *
63
+ * // Add import to file
64
+ * file.imports.set('./types', new Set(['User', 'Product']));
65
+ *
66
+ * // Or create Import directly for more control
67
+ * const customImport = new Import({
68
+ * module: './helpers',
69
+ * importNames: [{ 'validateEmail': 'emailValidator' }]
70
+ * });
71
+ * ```
72
+ */
4
73
  class Import {
74
+ /**
75
+ * Creates a new Import instance.
76
+ *
77
+ * @param args - Import configuration
78
+ * @param args.module - The module path to import from (e.g., './types', 'react')
79
+ * @param args.importNames - Array of import names, can be strings or alias objects
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const importStatement = new Import({
84
+ * module: './models/User',
85
+ * importNames: [
86
+ * 'User', // Simple import
87
+ * { 'UserType': 'IUser' }, // Aliased import
88
+ * 'createUser' // Another simple import
89
+ * ]
90
+ * });
91
+ * ```
92
+ */
5
93
  constructor({ module, importNames }) {
94
+ /** The module path to import from */
6
95
  Object.defineProperty(this, "module", {
7
96
  enumerable: true,
8
97
  configurable: true,
9
98
  writable: true,
10
99
  value: void 0
11
100
  });
101
+ /** Array of parsed import names with potential aliases */
12
102
  Object.defineProperty(this, "importNames", {
13
103
  enumerable: true,
14
104
  configurable: true,
@@ -18,11 +108,64 @@ class Import {
18
108
  this.module = module;
19
109
  this.importNames = importNames.map(importName => new ImportName(importName));
20
110
  }
111
+ /**
112
+ * Converts the import to a record format.
113
+ *
114
+ * This method creates a record representation where the module path is the key
115
+ * and the import names are the value. Useful for serialization or when working
116
+ * with import maps.
117
+ *
118
+ * @returns A record with module as key and import names as value
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const importStatement = new Import({
123
+ * module: './types',
124
+ * importNames: ['User', { 'Product': 'IProduct' }]
125
+ * });
126
+ *
127
+ * const record = importStatement.toRecord();
128
+ * console.log(record);
129
+ * // {
130
+ * // './types': ['User', { 'Product': 'IProduct' }]
131
+ * // }
132
+ * ```
133
+ */
21
134
  toRecord() {
22
135
  return {
23
136
  [this.module]: this.importNames.map(({ name, alias }) => alias ? { [name]: alias } : name)
24
137
  };
25
138
  }
139
+ /**
140
+ * Generates the TypeScript import statement string.
141
+ *
142
+ * This method produces a properly formatted ES6 import statement that can be
143
+ * written directly to a TypeScript file. It handles both simple and aliased
144
+ * imports correctly.
145
+ *
146
+ * @returns The formatted import statement string
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const basicImport = new Import({
151
+ * module: './utils',
152
+ * importNames: ['formatDate', 'parseJson']
153
+ * });
154
+ *
155
+ * console.log(basicImport.toString());
156
+ * // import { formatDate, parseJson } from './utils'
157
+ *
158
+ * const aliasedImport = new Import({
159
+ * module: 'lodash',
160
+ * importNames: [{ 'isEqual': 'deepEqual' }, 'cloneDeep']
161
+ * });
162
+ *
163
+ * console.log(aliasedImport.toString());
164
+ * // import { isEqual as deepEqual, cloneDeep } from 'lodash'
165
+ * ```
166
+ *
167
+ * @todo Move syntax to typescript package to enable language-agnostic use
168
+ */
26
169
  toString() {
27
170
  // @TODO move syntax to typescript package to enable
28
171
  // language agnostic use
@@ -30,14 +173,52 @@ class Import {
30
173
  }
31
174
  }
32
175
  exports.Import = Import;
176
+ /**
177
+ * Represents a single import name with optional aliasing.
178
+ *
179
+ * This class handles the parsing and formatting of individual import specifiers,
180
+ * supporting both simple imports and aliased imports. It's used internally by
181
+ * the {@link Import} class to manage import statement components.
182
+ *
183
+ * @example Simple import name
184
+ * ```typescript
185
+ * const simple = new ImportName('useState');
186
+ * console.log(simple.toString()); // 'useState'
187
+ * ```
188
+ *
189
+ * @example Aliased import name
190
+ * ```typescript
191
+ * const aliased = new ImportName({ 'React': 'ReactLib' });
192
+ * console.log(aliased.toString()); // 'React as ReactLib'
193
+ * ```
194
+ */
33
195
  class ImportName {
196
+ /**
197
+ * Creates a new ImportName instance.
198
+ *
199
+ * @param name - Either a string for simple imports or an object for aliased imports
200
+ *
201
+ * @example Simple import
202
+ * ```typescript
203
+ * const importName = new ImportName('User');
204
+ * // Results in: User
205
+ * ```
206
+ *
207
+ * @example Aliased import
208
+ * ```typescript
209
+ * const importName = new ImportName({ 'UserInterface': 'IUser' });
210
+ * // Results in: UserInterface as IUser
211
+ * ```
212
+ */
34
213
  constructor(name) {
214
+ /** The original name being imported */
35
215
  Object.defineProperty(this, "name", {
36
216
  enumerable: true,
37
217
  configurable: true,
38
218
  writable: true,
39
219
  value: void 0
40
220
  });
221
+ /** The alias to use (if any) */
41
222
  Object.defineProperty(this, "alias", {
42
223
  enumerable: true,
43
224
  configurable: true,
@@ -53,6 +234,27 @@ class ImportName {
53
234
  this.alias = alias;
54
235
  }
55
236
  }
237
+ /**
238
+ * Generates the string representation of the import name.
239
+ *
240
+ * This method creates the appropriate import specifier syntax,
241
+ * either a simple name or an aliased import using TypeScript's
242
+ * 'as' keyword.
243
+ *
244
+ * @returns The formatted import specifier string
245
+ *
246
+ * @example Simple import
247
+ * ```typescript
248
+ * const simple = new ImportName('useState');
249
+ * console.log(simple.toString()); // 'useState'
250
+ * ```
251
+ *
252
+ * @example Aliased import
253
+ * ```typescript
254
+ * const aliased = new ImportName({ 'Component': 'ReactComponent' });
255
+ * console.log(aliased.toString()); // 'Component as ReactComponent'
256
+ * ```
257
+ */
56
258
  toString() {
57
259
  return this.alias ? `${this.name} as ${this.alias}` : this.name;
58
260
  }