@skmtc/core 0.0.785 → 0.0.787

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 (93) hide show
  1. package/esm/dsl/ContentSettings.d.ts +164 -0
  2. package/esm/dsl/ContentSettings.d.ts.map +1 -1
  3. package/esm/dsl/ContentSettings.js +151 -0
  4. package/esm/dsl/Definition.d.ts +199 -0
  5. package/esm/dsl/Definition.d.ts.map +1 -1
  6. package/esm/dsl/Definition.js +189 -0
  7. package/esm/dsl/EntityType.d.ts +83 -0
  8. package/esm/dsl/EntityType.d.ts.map +1 -1
  9. package/esm/dsl/EntityType.js +83 -0
  10. package/esm/dsl/Identifier.d.ts +152 -0
  11. package/esm/dsl/Identifier.d.ts.map +1 -1
  12. package/esm/dsl/Identifier.js +152 -0
  13. package/esm/dsl/Import.d.ts +221 -0
  14. package/esm/dsl/Import.d.ts.map +1 -1
  15. package/esm/dsl/Import.js +202 -0
  16. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  17. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  18. package/esm/dsl/operation/OperationBase.js +181 -1
  19. package/esm/oas/array/Array.d.ts +109 -1
  20. package/esm/oas/array/Array.d.ts.map +1 -1
  21. package/esm/oas/array/Array.js +93 -1
  22. package/esm/oas/document/Document.d.ts +155 -1
  23. package/esm/oas/document/Document.d.ts.map +1 -1
  24. package/esm/oas/document/Document.js +141 -2
  25. package/esm/oas/integer/Integer.d.ts +98 -0
  26. package/esm/oas/integer/Integer.d.ts.map +1 -1
  27. package/esm/oas/integer/Integer.js +80 -0
  28. package/esm/oas/object/Object.d.ts +255 -10
  29. package/esm/oas/object/Object.d.ts.map +1 -1
  30. package/esm/oas/object/Object.js +229 -10
  31. package/esm/oas/string/String.d.ts +103 -1
  32. package/esm/oas/string/String.d.ts.map +1 -1
  33. package/esm/oas/string/String.js +87 -1
  34. package/esm/types/Brand.d.ts +74 -0
  35. package/esm/types/Brand.d.ts.map +1 -1
  36. package/esm/types/Brand.js +9 -0
  37. package/esm/types/GeneratorKeys.d.ts +336 -0
  38. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  39. package/esm/types/GeneratorKeys.js +243 -0
  40. package/esm/types/GeneratorType.d.ts +119 -0
  41. package/esm/types/GeneratorType.d.ts.map +1 -1
  42. package/esm/types/Method.d.ts +109 -0
  43. package/esm/types/Method.d.ts.map +1 -1
  44. package/esm/types/Method.js +84 -0
  45. package/esm/types/RefName.d.ts +61 -0
  46. package/esm/types/RefName.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/script/dsl/ContentSettings.d.ts +164 -0
  49. package/script/dsl/ContentSettings.d.ts.map +1 -1
  50. package/script/dsl/ContentSettings.js +151 -0
  51. package/script/dsl/Definition.d.ts +199 -0
  52. package/script/dsl/Definition.d.ts.map +1 -1
  53. package/script/dsl/Definition.js +189 -0
  54. package/script/dsl/EntityType.d.ts +83 -0
  55. package/script/dsl/EntityType.d.ts.map +1 -1
  56. package/script/dsl/EntityType.js +83 -0
  57. package/script/dsl/Identifier.d.ts +152 -0
  58. package/script/dsl/Identifier.d.ts.map +1 -1
  59. package/script/dsl/Identifier.js +152 -0
  60. package/script/dsl/Import.d.ts +221 -0
  61. package/script/dsl/Import.d.ts.map +1 -1
  62. package/script/dsl/Import.js +202 -0
  63. package/script/dsl/operation/OperationBase.d.ts +181 -1
  64. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  65. package/script/dsl/operation/OperationBase.js +181 -1
  66. package/script/oas/array/Array.d.ts +109 -1
  67. package/script/oas/array/Array.d.ts.map +1 -1
  68. package/script/oas/array/Array.js +93 -1
  69. package/script/oas/document/Document.d.ts +155 -1
  70. package/script/oas/document/Document.d.ts.map +1 -1
  71. package/script/oas/document/Document.js +141 -2
  72. package/script/oas/integer/Integer.d.ts +98 -0
  73. package/script/oas/integer/Integer.d.ts.map +1 -1
  74. package/script/oas/integer/Integer.js +80 -0
  75. package/script/oas/object/Object.d.ts +255 -10
  76. package/script/oas/object/Object.d.ts.map +1 -1
  77. package/script/oas/object/Object.js +229 -10
  78. package/script/oas/string/String.d.ts +103 -1
  79. package/script/oas/string/String.d.ts.map +1 -1
  80. package/script/oas/string/String.js +87 -1
  81. package/script/types/Brand.d.ts +74 -0
  82. package/script/types/Brand.d.ts.map +1 -1
  83. package/script/types/Brand.js +9 -0
  84. package/script/types/GeneratorKeys.d.ts +336 -0
  85. package/script/types/GeneratorKeys.d.ts.map +1 -1
  86. package/script/types/GeneratorKeys.js +243 -0
  87. package/script/types/GeneratorType.d.ts +119 -0
  88. package/script/types/GeneratorType.d.ts.map +1 -1
  89. package/script/types/Method.d.ts +109 -0
  90. package/script/types/Method.d.ts.map +1 -1
  91. package/script/types/Method.js +84 -0
  92. package/script/types/RefName.d.ts +61 -0
  93. package/script/types/RefName.d.ts.map +1 -1
@@ -1,18 +1,88 @@
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 class Identifier {
62
+ /**
63
+ * Creates a new Identifier instance.
64
+ *
65
+ * This constructor is private to enforce the use of factory methods
66
+ * that provide better semantic clarity and type safety.
67
+ *
68
+ * @param args - Identifier configuration
69
+ */
3
70
  constructor({ name, typeName, entityType }) {
71
+ /** The identifier name */
4
72
  Object.defineProperty(this, "name", {
5
73
  enumerable: true,
6
74
  configurable: true,
7
75
  writable: true,
8
76
  value: void 0
9
77
  });
78
+ /** The entity type (variable, type, etc.) */
10
79
  Object.defineProperty(this, "entityType", {
11
80
  enumerable: true,
12
81
  configurable: true,
13
82
  writable: true,
14
83
  value: void 0
15
84
  });
85
+ /** Optional type name for typed variables */
16
86
  Object.defineProperty(this, "typeName", {
17
87
  enumerable: true,
18
88
  configurable: true,
@@ -23,6 +93,37 @@ export class Identifier {
23
93
  this.typeName = typeName;
24
94
  this.entityType = entityType;
25
95
  }
96
+ /**
97
+ * Creates a variable identifier with optional type information.
98
+ *
99
+ * This factory method creates an identifier for variables, constants,
100
+ * function parameters, and other value-based entities. Optionally
101
+ * associates type information for typed variables.
102
+ *
103
+ * @param name - The variable name
104
+ * @param typeName - Optional type name for the variable
105
+ * @returns A new variable Identifier instance
106
+ *
107
+ * @example Untyped variable
108
+ * ```typescript
109
+ * const count = Identifier.createVariable('count');
110
+ * console.log(count.name); // 'count'
111
+ * console.log(count.typeName); // undefined
112
+ * ```
113
+ *
114
+ * @example Typed variable
115
+ * ```typescript
116
+ * const userId = Identifier.createVariable('userId', 'string');
117
+ * console.log(userId.name); // 'userId'
118
+ * console.log(userId.typeName); // 'string'
119
+ * ```
120
+ *
121
+ * @example In function generation
122
+ * ```typescript
123
+ * const param = Identifier.createVariable('data', 'RequestData');
124
+ * const funcDef = `function processRequest(${param.name}: ${param.typeName}) {}`;
125
+ * ```
126
+ */
26
127
  static createVariable(name, typeName) {
27
128
  if (typeName) {
28
129
  return new Identifier({
@@ -36,12 +137,63 @@ export class Identifier {
36
137
  entityType: new EntityType('variable')
37
138
  });
38
139
  }
140
+ /**
141
+ * Creates a type identifier for TypeScript types.
142
+ *
143
+ * This factory method creates an identifier for type entities like
144
+ * interfaces, type aliases, classes, and other type-level constructs.
145
+ * Type identifiers don't have associated type information since they
146
+ * represent types themselves.
147
+ *
148
+ * @param name - The type name
149
+ * @returns A new type Identifier instance
150
+ *
151
+ * @example Interface type
152
+ * ```typescript
153
+ * const userInterface = Identifier.createType('User');
154
+ * console.log(userInterface.name); // 'User'
155
+ * console.log(userInterface.entityType.value); // 'type'
156
+ * ```
157
+ *
158
+ * @example Type alias
159
+ * ```typescript
160
+ * const statusType = Identifier.createType('Status');
161
+ * const typeDef = `type ${statusType} = 'pending' | 'complete'`;
162
+ * ```
163
+ *
164
+ * @example Generic type
165
+ * ```typescript
166
+ * const responseType = Identifier.createType('ApiResponse');
167
+ * const genericDef = `interface ${responseType}<T> { data: T; success: boolean; }`;
168
+ * ```
169
+ */
39
170
  static createType(name) {
40
171
  return new Identifier({
41
172
  name,
42
173
  entityType: new EntityType('type')
43
174
  });
44
175
  }
176
+ /**
177
+ * Returns the string representation of the identifier.
178
+ *
179
+ * This method simply returns the identifier name, which is the most
180
+ * common usage when generating code. The name can be used directly
181
+ * in code generation contexts.
182
+ *
183
+ * @returns The identifier name as a string
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const variable = Identifier.createVariable('userName');
188
+ * const typeId = Identifier.createType('User');
189
+ *
190
+ * console.log(variable.toString()); // 'userName'
191
+ * console.log(typeId.toString()); // 'User'
192
+ *
193
+ * // Can be used directly in template strings
194
+ * const code = `const ${variable}: ${typeId} = getUserData();`;
195
+ * ```
196
+ */
45
197
  toString() {
46
198
  return this.name;
47
199
  }
@@ -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"}
package/esm/dsl/Import.js CHANGED
@@ -1,11 +1,101 @@
1
+ /**
2
+ * Represents a TypeScript import statement in the SKMTC DSL system.
3
+ *
4
+ * The `Import` class generates properly formatted import statements for TypeScript
5
+ * files, handling named imports with optional aliases. It's used throughout the
6
+ * code generation pipeline to manage module dependencies.
7
+ *
8
+ * This class supports both simple string imports and aliased imports, making it
9
+ * easy to avoid naming conflicts and provide cleaner import statements.
10
+ *
11
+ * @example Basic named imports
12
+ * ```typescript
13
+ * import { Import } from '@skmtc/core';
14
+ *
15
+ * const basicImport = new Import({
16
+ * module: './types',
17
+ * importNames: ['User', 'Product', 'Order']
18
+ * });
19
+ *
20
+ * console.log(basicImport.toString());
21
+ * // import { User, Product, Order } from './types'
22
+ * ```
23
+ *
24
+ * @example Imports with aliases
25
+ * ```typescript
26
+ * const aliasedImport = new Import({
27
+ * module: 'react',
28
+ * importNames: [
29
+ * 'useState',
30
+ * 'useEffect',
31
+ * { 'default': 'React' } // Import default as React
32
+ * ]
33
+ * });
34
+ *
35
+ * console.log(aliasedImport.toString());
36
+ * // import { useState, useEffect, default as React } from 'react'
37
+ * ```
38
+ *
39
+ * @example Mixed imports
40
+ * ```typescript
41
+ * const mixedImport = new Import({
42
+ * module: './api/client',
43
+ * importNames: [
44
+ * 'ApiClient',
45
+ * { 'RequestOptions': 'Options' }, // Alias to avoid conflicts
46
+ * 'ResponseType'
47
+ * ]
48
+ * });
49
+ *
50
+ * console.log(mixedImport.toString());
51
+ * // import { ApiClient, RequestOptions as Options, ResponseType } from './api/client'
52
+ * ```
53
+ *
54
+ * @example Using in File generation
55
+ * ```typescript
56
+ * import { File, Import } from '@skmtc/core';
57
+ *
58
+ * const file = new File({ path: './generated.ts', settings: undefined });
59
+ *
60
+ * // Add import to file
61
+ * file.imports.set('./types', new Set(['User', 'Product']));
62
+ *
63
+ * // Or create Import directly for more control
64
+ * const customImport = new Import({
65
+ * module: './helpers',
66
+ * importNames: [{ 'validateEmail': 'emailValidator' }]
67
+ * });
68
+ * ```
69
+ */
1
70
  export class Import {
71
+ /**
72
+ * Creates a new Import instance.
73
+ *
74
+ * @param args - Import configuration
75
+ * @param args.module - The module path to import from (e.g., './types', 'react')
76
+ * @param args.importNames - Array of import names, can be strings or alias objects
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const importStatement = new Import({
81
+ * module: './models/User',
82
+ * importNames: [
83
+ * 'User', // Simple import
84
+ * { 'UserType': 'IUser' }, // Aliased import
85
+ * 'createUser' // Another simple import
86
+ * ]
87
+ * });
88
+ * ```
89
+ */
2
90
  constructor({ module, importNames }) {
91
+ /** The module path to import from */
3
92
  Object.defineProperty(this, "module", {
4
93
  enumerable: true,
5
94
  configurable: true,
6
95
  writable: true,
7
96
  value: void 0
8
97
  });
98
+ /** Array of parsed import names with potential aliases */
9
99
  Object.defineProperty(this, "importNames", {
10
100
  enumerable: true,
11
101
  configurable: true,
@@ -15,25 +105,116 @@ export class Import {
15
105
  this.module = module;
16
106
  this.importNames = importNames.map(importName => new ImportName(importName));
17
107
  }
108
+ /**
109
+ * Converts the import to a record format.
110
+ *
111
+ * This method creates a record representation where the module path is the key
112
+ * and the import names are the value. Useful for serialization or when working
113
+ * with import maps.
114
+ *
115
+ * @returns A record with module as key and import names as value
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const importStatement = new Import({
120
+ * module: './types',
121
+ * importNames: ['User', { 'Product': 'IProduct' }]
122
+ * });
123
+ *
124
+ * const record = importStatement.toRecord();
125
+ * console.log(record);
126
+ * // {
127
+ * // './types': ['User', { 'Product': 'IProduct' }]
128
+ * // }
129
+ * ```
130
+ */
18
131
  toRecord() {
19
132
  return {
20
133
  [this.module]: this.importNames.map(({ name, alias }) => alias ? { [name]: alias } : name)
21
134
  };
22
135
  }
136
+ /**
137
+ * Generates the TypeScript import statement string.
138
+ *
139
+ * This method produces a properly formatted ES6 import statement that can be
140
+ * written directly to a TypeScript file. It handles both simple and aliased
141
+ * imports correctly.
142
+ *
143
+ * @returns The formatted import statement string
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const basicImport = new Import({
148
+ * module: './utils',
149
+ * importNames: ['formatDate', 'parseJson']
150
+ * });
151
+ *
152
+ * console.log(basicImport.toString());
153
+ * // import { formatDate, parseJson } from './utils'
154
+ *
155
+ * const aliasedImport = new Import({
156
+ * module: 'lodash',
157
+ * importNames: [{ 'isEqual': 'deepEqual' }, 'cloneDeep']
158
+ * });
159
+ *
160
+ * console.log(aliasedImport.toString());
161
+ * // import { isEqual as deepEqual, cloneDeep } from 'lodash'
162
+ * ```
163
+ *
164
+ * @todo Move syntax to typescript package to enable language-agnostic use
165
+ */
23
166
  toString() {
24
167
  // @TODO move syntax to typescript package to enable
25
168
  // language agnostic use
26
169
  return `import { ${this.importNames.join(', ')} } from '${this.module}'`;
27
170
  }
28
171
  }
172
+ /**
173
+ * Represents a single import name with optional aliasing.
174
+ *
175
+ * This class handles the parsing and formatting of individual import specifiers,
176
+ * supporting both simple imports and aliased imports. It's used internally by
177
+ * the {@link Import} class to manage import statement components.
178
+ *
179
+ * @example Simple import name
180
+ * ```typescript
181
+ * const simple = new ImportName('useState');
182
+ * console.log(simple.toString()); // 'useState'
183
+ * ```
184
+ *
185
+ * @example Aliased import name
186
+ * ```typescript
187
+ * const aliased = new ImportName({ 'React': 'ReactLib' });
188
+ * console.log(aliased.toString()); // 'React as ReactLib'
189
+ * ```
190
+ */
29
191
  export class ImportName {
192
+ /**
193
+ * Creates a new ImportName instance.
194
+ *
195
+ * @param name - Either a string for simple imports or an object for aliased imports
196
+ *
197
+ * @example Simple import
198
+ * ```typescript
199
+ * const importName = new ImportName('User');
200
+ * // Results in: User
201
+ * ```
202
+ *
203
+ * @example Aliased import
204
+ * ```typescript
205
+ * const importName = new ImportName({ 'UserInterface': 'IUser' });
206
+ * // Results in: UserInterface as IUser
207
+ * ```
208
+ */
30
209
  constructor(name) {
210
+ /** The original name being imported */
31
211
  Object.defineProperty(this, "name", {
32
212
  enumerable: true,
33
213
  configurable: true,
34
214
  writable: true,
35
215
  value: void 0
36
216
  });
217
+ /** The alias to use (if any) */
37
218
  Object.defineProperty(this, "alias", {
38
219
  enumerable: true,
39
220
  configurable: true,
@@ -49,6 +230,27 @@ export class ImportName {
49
230
  this.alias = alias;
50
231
  }
51
232
  }
233
+ /**
234
+ * Generates the string representation of the import name.
235
+ *
236
+ * This method creates the appropriate import specifier syntax,
237
+ * either a simple name or an aliased import using TypeScript's
238
+ * 'as' keyword.
239
+ *
240
+ * @returns The formatted import specifier string
241
+ *
242
+ * @example Simple import
243
+ * ```typescript
244
+ * const simple = new ImportName('useState');
245
+ * console.log(simple.toString()); // 'useState'
246
+ * ```
247
+ *
248
+ * @example Aliased import
249
+ * ```typescript
250
+ * const aliased = new ImportName({ 'Component': 'ReactComponent' });
251
+ * console.log(aliased.toString()); // 'Component as ReactComponent'
252
+ * ```
253
+ */
52
254
  toString() {
53
255
  return this.alias ? `${this.name} as ${this.alias}` : this.name;
54
256
  }