@skmtc/core 0.0.792 → 0.0.794

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 (113) hide show
  1. package/esm/dsl/GeneratedValueList.d.ts +158 -0
  2. package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
  3. package/esm/dsl/GeneratedValueList.js +158 -0
  4. package/esm/dsl/Stringable.d.ts +76 -0
  5. package/esm/dsl/Stringable.d.ts.map +1 -1
  6. package/esm/dsl/Stringable.js +75 -0
  7. package/esm/helpers/ResultsLog.d.ts +193 -0
  8. package/esm/helpers/ResultsLog.d.ts.map +1 -1
  9. package/esm/helpers/ResultsLog.js +213 -0
  10. package/esm/helpers/collateExamples.d.ts +150 -0
  11. package/esm/helpers/collateExamples.d.ts.map +1 -1
  12. package/esm/helpers/collateExamples.js +145 -0
  13. package/esm/helpers/formatNumber.d.ts +95 -0
  14. package/esm/helpers/formatNumber.d.ts.map +1 -1
  15. package/esm/helpers/formatNumber.js +95 -0
  16. package/esm/helpers/generationStats.d.ts +287 -1
  17. package/esm/helpers/generationStats.d.ts.map +1 -1
  18. package/esm/helpers/generationStats.js +266 -0
  19. package/esm/helpers/isEmpty.d.ts +62 -0
  20. package/esm/helpers/isEmpty.d.ts.map +1 -1
  21. package/esm/helpers/isEmpty.js +62 -0
  22. package/esm/helpers/isImported.d.ts +80 -0
  23. package/esm/helpers/isImported.d.ts.map +1 -1
  24. package/esm/helpers/isImported.js +80 -0
  25. package/esm/helpers/parseModuleName.d.ts +175 -0
  26. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  27. package/esm/helpers/parseModuleName.js +153 -0
  28. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  29. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  30. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  31. package/esm/helpers/tracer.d.ts +124 -0
  32. package/esm/helpers/tracer.d.ts.map +1 -1
  33. package/esm/helpers/tracer.js +124 -0
  34. package/esm/oas/schema/Schema.d.ts +117 -0
  35. package/esm/oas/schema/Schema.d.ts.map +1 -1
  36. package/esm/typescript/PathParams.d.ts +198 -0
  37. package/esm/typescript/PathParams.d.ts.map +1 -1
  38. package/esm/typescript/PathParams.js +190 -0
  39. package/esm/typescript/ReactRouterPathParams.d.ts +190 -0
  40. package/esm/typescript/ReactRouterPathParams.d.ts.map +1 -1
  41. package/esm/typescript/ReactRouterPathParams.js +183 -0
  42. package/esm/typescript/identifiers.d.ts +159 -0
  43. package/esm/typescript/identifiers.d.ts.map +1 -1
  44. package/esm/typescript/identifiers.js +159 -0
  45. package/esm/typescript/keyValues.d.ts +125 -0
  46. package/esm/typescript/keyValues.d.ts.map +1 -1
  47. package/esm/typescript/keyValues.js +125 -1
  48. package/esm/typescript/toPathParams.d.ts +179 -0
  49. package/esm/typescript/toPathParams.d.ts.map +1 -1
  50. package/esm/typescript/toPathParams.js +179 -0
  51. package/esm/typescript/toPathTemplate.d.ts +114 -0
  52. package/esm/typescript/toPathTemplate.d.ts.map +1 -1
  53. package/esm/typescript/toPathTemplate.js +114 -0
  54. package/esm/typescript/withDescription.d.ts +119 -0
  55. package/esm/typescript/withDescription.d.ts.map +1 -1
  56. package/esm/typescript/withDescription.js +119 -0
  57. package/package.json +1 -1
  58. package/script/dsl/GeneratedValueList.d.ts +158 -0
  59. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  60. package/script/dsl/GeneratedValueList.js +158 -0
  61. package/script/dsl/Stringable.d.ts +76 -0
  62. package/script/dsl/Stringable.d.ts.map +1 -1
  63. package/script/dsl/Stringable.js +75 -0
  64. package/script/helpers/ResultsLog.d.ts +193 -0
  65. package/script/helpers/ResultsLog.d.ts.map +1 -1
  66. package/script/helpers/ResultsLog.js +213 -0
  67. package/script/helpers/collateExamples.d.ts +150 -0
  68. package/script/helpers/collateExamples.d.ts.map +1 -1
  69. package/script/helpers/collateExamples.js +145 -0
  70. package/script/helpers/formatNumber.d.ts +95 -0
  71. package/script/helpers/formatNumber.d.ts.map +1 -1
  72. package/script/helpers/formatNumber.js +95 -0
  73. package/script/helpers/generationStats.d.ts +287 -1
  74. package/script/helpers/generationStats.d.ts.map +1 -1
  75. package/script/helpers/generationStats.js +266 -0
  76. package/script/helpers/isEmpty.d.ts +62 -0
  77. package/script/helpers/isEmpty.d.ts.map +1 -1
  78. package/script/helpers/isEmpty.js +62 -0
  79. package/script/helpers/isImported.d.ts +80 -0
  80. package/script/helpers/isImported.d.ts.map +1 -1
  81. package/script/helpers/isImported.js +80 -0
  82. package/script/helpers/parseModuleName.d.ts +175 -0
  83. package/script/helpers/parseModuleName.d.ts.map +1 -1
  84. package/script/helpers/parseModuleName.js +153 -0
  85. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  86. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  87. package/script/helpers/toResolvedArtifactPath.js +140 -0
  88. package/script/helpers/tracer.d.ts +124 -0
  89. package/script/helpers/tracer.d.ts.map +1 -1
  90. package/script/helpers/tracer.js +124 -0
  91. package/script/oas/schema/Schema.d.ts +117 -0
  92. package/script/oas/schema/Schema.d.ts.map +1 -1
  93. package/script/typescript/PathParams.d.ts +198 -0
  94. package/script/typescript/PathParams.d.ts.map +1 -1
  95. package/script/typescript/PathParams.js +190 -0
  96. package/script/typescript/ReactRouterPathParams.d.ts +190 -0
  97. package/script/typescript/ReactRouterPathParams.d.ts.map +1 -1
  98. package/script/typescript/ReactRouterPathParams.js +183 -0
  99. package/script/typescript/identifiers.d.ts +159 -0
  100. package/script/typescript/identifiers.d.ts.map +1 -1
  101. package/script/typescript/identifiers.js +159 -0
  102. package/script/typescript/keyValues.d.ts +125 -0
  103. package/script/typescript/keyValues.d.ts.map +1 -1
  104. package/script/typescript/keyValues.js +125 -1
  105. package/script/typescript/toPathParams.d.ts +179 -0
  106. package/script/typescript/toPathParams.d.ts.map +1 -1
  107. package/script/typescript/toPathParams.js +179 -0
  108. package/script/typescript/toPathTemplate.d.ts +114 -0
  109. package/script/typescript/toPathTemplate.d.ts.map +1 -1
  110. package/script/typescript/toPathTemplate.js +114 -0
  111. package/script/typescript/withDescription.d.ts +119 -0
  112. package/script/typescript/withDescription.d.ts.map +1 -1
  113. package/script/typescript/withDescription.js +119 -0
@@ -1,6 +1,108 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import { match, P } from 'ts-pattern';
3
3
  import { countTokens } from 'gpt-tokenizer';
4
+ /**
5
+ * Generates comprehensive statistics about the code generation process.
6
+ *
7
+ * This function analyzes the generation manifest and produced artifacts to create
8
+ * detailed statistics including token counts, lines of code, timing information,
9
+ * error tracking, and file counts. It's used for performance monitoring, debugging,
10
+ * and reporting on generation runs.
11
+ *
12
+ * The function combines multiple analysis methods to provide a complete picture
13
+ * of the generation process, including tokenization analysis for cost estimation,
14
+ * error path extraction for debugging, and timing analysis for performance optimization.
15
+ *
16
+ * @param args - Generation analysis configuration
17
+ * @param args.manifest - The generation manifest with metadata and results
18
+ * @param args.artifacts - Map of file paths to generated content
19
+ * @returns Comprehensive generation statistics object
20
+ *
21
+ * @example Basic usage
22
+ * ```typescript
23
+ * import { toGenerationStats } from '@skmtc/core';
24
+ *
25
+ * const stats = toGenerationStats({
26
+ * manifest: {
27
+ * startAt: 1672531200000,
28
+ * endAt: 1672531245000,
29
+ * files: {
30
+ * './models.ts': { lines: 150, characters: 4500 },
31
+ * './types.ts': { lines: 80, characters: 2100 }
32
+ * },
33
+ * results: { }
34
+ * },
35
+ * artifacts: {
36
+ * './models.ts': 'export interface User { id: string; name: string; }',
37
+ * './types.ts': 'export type Status = "active" | "inactive";'
38
+ * }
39
+ * });
40
+ *
41
+ * console.log(stats);
42
+ * // {
43
+ * // tokens: 250,
44
+ * // lines: 230,
45
+ * // totalTime: 45000,
46
+ * // errors: [],
47
+ * // files: 2
48
+ * // }
49
+ * ```
50
+ *
51
+ * @example Performance monitoring
52
+ * ```typescript
53
+ * class GenerationMonitor {
54
+ * analyzeGeneration(manifest: ManifestContent, artifacts: Record<string, string>) {
55
+ * const stats = toGenerationStats({ manifest, artifacts });
56
+ *
57
+ * console.log(`Generation completed in ${stats.totalTime}ms`);
58
+ * console.log(`Generated ${stats.files} files with ${stats.lines} lines`);
59
+ * console.log(`Token usage: ${stats.tokens} tokens`);
60
+ *
61
+ * if (stats.errors.length > 0) {
62
+ * console.warn(`Found ${stats.errors.length} errors:`);
63
+ * stats.errors.forEach((errorPath, index) => {
64
+ * console.warn(` ${index + 1}. ${errorPath.join(' -> ')}`);
65
+ * });
66
+ * }
67
+ *
68
+ * return stats;
69
+ * }
70
+ * }
71
+ * ```
72
+ *
73
+ * @example Cost estimation
74
+ * ```typescript
75
+ * function estimateGenerationCost(stats: GenerationStats): number {
76
+ * const tokensPerDollar = 1000000; // Example rate
77
+ * const estimatedCost = stats.tokens / tokensPerDollar;
78
+ *
79
+ * console.log(`Estimated cost: $${estimatedCost.toFixed(4)}`);
80
+ * console.log(`Efficiency: ${stats.lines / stats.tokens} lines per token`);
81
+ *
82
+ * return estimatedCost;
83
+ * }
84
+ * ```
85
+ *
86
+ * @example Build reporting
87
+ * ```typescript
88
+ * function generateBuildReport(stats: GenerationStats): string {
89
+ * const efficiency = stats.totalTime / stats.files;
90
+ * const successRate = ((stats.files - stats.errors.length) / stats.files * 100).toFixed(1);
91
+ *
92
+ * return `
93
+ * Build Report:
94
+ * -----------
95
+ * Files Generated: ${stats.files}
96
+ * Total Lines: ${stats.lines.toLocaleString()}
97
+ * Token Count: ${stats.tokens.toLocaleString()}
98
+ * Generation Time: ${(stats.totalTime / 1000).toFixed(2)}s
99
+ * Average per File: ${efficiency.toFixed(0)}ms
100
+ * Success Rate: ${successRate}%
101
+ * Errors: ${stats.errors.length}
102
+ * `.trim();
103
+ * }
104
+ * ```
105
+ */
4
106
  export const toGenerationStats = ({ manifest, artifacts }) => {
5
107
  const tokens = toManifestTokens(artifacts);
6
108
  const lines = toManifestLines(manifest);
@@ -15,18 +117,118 @@ export const toGenerationStats = ({ manifest, artifacts }) => {
15
117
  files
16
118
  };
17
119
  };
120
+ /**
121
+ * Calculates the total number of GPT tokens in all generated artifacts.
122
+ *
123
+ * This function uses GPT tokenization to count the total number of tokens
124
+ * across all generated code artifacts. This is useful for cost estimation
125
+ * when using token-based pricing models and for understanding the size
126
+ * and complexity of generated content.
127
+ *
128
+ * @param artifacts - Map of file paths to generated content strings
129
+ * @returns Total number of GPT tokens across all artifacts
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const artifacts = {
134
+ * './models.ts': 'export interface User { id: string; name: string; }',
135
+ * './types.ts': 'export type Status = "active" | "inactive";'
136
+ * };
137
+ *
138
+ * const tokens = toManifestTokens(artifacts);
139
+ * console.log(tokens); // e.g., 24 tokens
140
+ * ```
141
+ */
18
142
  export const toManifestTokens = (artifacts) => {
19
143
  const { tokens } = Object.values(artifacts).reduce((acc, artifact) => ({ tokens: acc.tokens + countTokens(artifact) }), { tokens: 0 });
20
144
  return tokens;
21
145
  };
146
+ /**
147
+ * Calculates the total number of lines across all generated files.
148
+ *
149
+ * This function sums up the line counts from the manifest's file metadata
150
+ * to provide the total lines of code generated. This metric is useful
151
+ * for understanding the scale of code generation and tracking productivity.
152
+ *
153
+ * @param manifest - The generation manifest containing file metadata
154
+ * @returns Total number of lines across all generated files
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const manifest = {
159
+ * files: {
160
+ * './models.ts': { lines: 150, characters: 4500 },
161
+ * './types.ts': { lines: 80, characters: 2100 }
162
+ * },
163
+ * // ... other manifest properties
164
+ * };
165
+ *
166
+ * const lines = toManifestLines(manifest);
167
+ * console.log(lines); // 230
168
+ * ```
169
+ */
22
170
  export const toManifestLines = (manifest) => {
23
171
  const { lines } = Object.values(manifest.files).reduce((acc, file) => ({ lines: acc.lines + file.lines }), { lines: 0 });
24
172
  return lines;
25
173
  };
174
+ /**
175
+ * Calculates the total generation time from the manifest timestamps.
176
+ *
177
+ * This function computes the duration of the generation process by
178
+ * calculating the difference between the end and start timestamps
179
+ * recorded in the manifest. The result is in milliseconds.
180
+ *
181
+ * @param manifest - The generation manifest with timing information
182
+ * @returns Total generation time in milliseconds
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const manifest = {
187
+ * startAt: 1672531200000, // January 1, 2023 00:00:00 GMT
188
+ * endAt: 1672531245000, // January 1, 2023 00:00:45 GMT
189
+ * // ... other manifest properties
190
+ * };
191
+ *
192
+ * const duration = toTotalTime(manifest);
193
+ * console.log(duration); // 45000 (45 seconds)
194
+ * console.log(`${duration / 1000}s`); // "45s"
195
+ * ```
196
+ */
26
197
  export const toTotalTime = (manifest) => {
27
198
  const totalTime = manifest.endAt - manifest.startAt;
28
199
  return totalTime;
29
200
  };
201
+ /**
202
+ * Extracts and organizes error paths from the manifest results.
203
+ *
204
+ * This function recursively traverses the results structure in the manifest
205
+ * to identify all error conditions and their associated file paths. Errors
206
+ * are returned as arrays of path segments, making it easy to understand
207
+ * the location and context of each error.
208
+ *
209
+ * @param results - The results object from the generation manifest
210
+ * @returns Array of error paths, each represented as an array of path segments
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * const results = {
215
+ * 'models.ts': {
216
+ * 'User': 'success',
217
+ * 'Product': 'error'
218
+ * },
219
+ * 'types.ts': 'success'
220
+ * };
221
+ *
222
+ * const errors = toManifestErrors(results);
223
+ * console.log(errors); // [['models.ts', 'Product']]
224
+ *
225
+ * // Display errors in readable format
226
+ * errors.forEach(errorPath => {
227
+ * console.log(`Error at: ${errorPath.join(' -> ')}`);
228
+ * });
229
+ * // Output: "Error at: models.ts -> Product"
230
+ * ```
231
+ */
30
232
  export const toManifestErrors = (results) => {
31
233
  const errors = [];
32
234
  Object.entries(results).map(([path, result]) => {
@@ -34,6 +236,70 @@ export const toManifestErrors = (results) => {
34
236
  });
35
237
  return errors;
36
238
  };
239
+ /**
240
+ * Recursively checks results structure for error conditions and collects error paths.
241
+ *
242
+ * This function traverses the complex nested structure of generation results,
243
+ * identifying error conditions at any level and recording their full path context.
244
+ * It handles arrays, objects, strings, and null values, building a comprehensive
245
+ * map of all errors that occurred during generation.
246
+ *
247
+ * The function mutates the errors array parameter, accumulating error paths
248
+ * as it traverses the results structure. This approach is used for performance
249
+ * when processing large result sets.
250
+ *
251
+ * @param args - Arguments for result checking
252
+ * @param args.path - Current path segments being traversed
253
+ * @param args.result - The result value to check for errors
254
+ * @param args.errors - Array to accumulate error paths (mutated by function)
255
+ *
256
+ * @example Simple error detection
257
+ * ```typescript
258
+ * const errors: string[][] = [];
259
+ *
260
+ * checkResult({
261
+ * path: ['models.ts'],
262
+ * result: 'error',
263
+ * errors
264
+ * });
265
+ *
266
+ * console.log(errors); // [['models.ts']]
267
+ * ```
268
+ *
269
+ * @example Nested structure error detection
270
+ * ```typescript
271
+ * const errors: string[][] = [];
272
+ * const nestedResult = {
273
+ * 'User': 'success',
274
+ * 'Product': {
275
+ * 'validation': 'error',
276
+ * 'generation': 'success'
277
+ * }
278
+ * };
279
+ *
280
+ * checkResult({
281
+ * path: ['models.ts'],
282
+ * result: nestedResult,
283
+ * errors
284
+ * });
285
+ *
286
+ * console.log(errors); // [['models.ts', 'Product', 'validation']]
287
+ * ```
288
+ *
289
+ * @example Array handling
290
+ * ```typescript
291
+ * const errors: string[][] = [];
292
+ * const arrayResult = ['success', null, 'error', 'success'];
293
+ *
294
+ * checkResult({
295
+ * path: ['batch'],
296
+ * result: arrayResult,
297
+ * errors
298
+ * });
299
+ *
300
+ * console.log(errors); // [['batch']] - for the 'error' item
301
+ * ```
302
+ */
37
303
  export const checkResult = ({ path, result, errors }) => {
38
304
  match(result)
39
305
  .with(P.array(), matchedResult => {
@@ -1,3 +1,65 @@
1
+ /**
2
+ * Checks whether a record/object is empty (has no enumerable properties).
3
+ *
4
+ * This utility function determines if an object contains any enumerable properties
5
+ * by checking the length of its keys array. It's commonly used throughout the
6
+ * SKMTC codebase to validate whether generated objects, configurations, or
7
+ * other data structures contain meaningful content.
8
+ *
9
+ * @param value - The record/object to check for emptiness
10
+ * @returns `true` if the object has no enumerable properties, `false` otherwise
11
+ *
12
+ * @example Basic usage
13
+ * ```typescript
14
+ * import { isEmpty } from '@skmtc/core';
15
+ *
16
+ * console.log(isEmpty({})); // true
17
+ * console.log(isEmpty({ name: 'John' })); // false
18
+ * console.log(isEmpty({ a: undefined })); // false (undefined is still a property)
19
+ * ```
20
+ *
21
+ * @example In conditional logic
22
+ * ```typescript
23
+ * const userPreferences = loadUserPreferences();
24
+ *
25
+ * if (isEmpty(userPreferences)) {
26
+ * // Apply default settings
27
+ * applyDefaults();
28
+ * } else {
29
+ * // Use user's custom settings
30
+ * applyUserSettings(userPreferences);
31
+ * }
32
+ * ```
33
+ *
34
+ * @example Filtering collections
35
+ * ```typescript
36
+ * const configurations = [
37
+ * { api: 'v1', settings: {} },
38
+ * { api: 'v2', settings: { timeout: 5000 } },
39
+ * { api: 'v3', settings: {} }
40
+ * ];
41
+ *
42
+ * const validConfigs = configurations.filter(config => !isEmpty(config.settings));
43
+ * console.log(validConfigs); // [{ api: 'v2', settings: { timeout: 5000 } }]
44
+ * ```
45
+ *
46
+ * @example Code generation usage
47
+ * ```typescript
48
+ * class Generator {
49
+ * generateInterface(properties: Record<string, string>) {
50
+ * if (isEmpty(properties)) {
51
+ * return 'interface EmptyInterface {}';
52
+ * }
53
+ *
54
+ * const props = Object.entries(properties)
55
+ * .map(([name, type]) => ` ${name}: ${type};`)
56
+ * .join('\n');
57
+ *
58
+ * return `interface GeneratedInterface {\n${props}\n}`;
59
+ * }
60
+ * }
61
+ * ```
62
+ */
1
63
  import "../_dnt.polyfills.js";
2
64
  export declare const isEmpty: (value: Record<string, any>) => boolean;
3
65
  //# sourceMappingURL=isEmpty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isEmpty.d.ts","sourceRoot":"","sources":["../../src/helpers/isEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,OAEpD,CAAA"}
1
+ {"version":3,"file":"isEmpty.d.ts","sourceRoot":"","sources":["../../src/helpers/isEmpty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,OAEpD,CAAA"}
@@ -1,3 +1,65 @@
1
+ /**
2
+ * Checks whether a record/object is empty (has no enumerable properties).
3
+ *
4
+ * This utility function determines if an object contains any enumerable properties
5
+ * by checking the length of its keys array. It's commonly used throughout the
6
+ * SKMTC codebase to validate whether generated objects, configurations, or
7
+ * other data structures contain meaningful content.
8
+ *
9
+ * @param value - The record/object to check for emptiness
10
+ * @returns `true` if the object has no enumerable properties, `false` otherwise
11
+ *
12
+ * @example Basic usage
13
+ * ```typescript
14
+ * import { isEmpty } from '@skmtc/core';
15
+ *
16
+ * console.log(isEmpty({})); // true
17
+ * console.log(isEmpty({ name: 'John' })); // false
18
+ * console.log(isEmpty({ a: undefined })); // false (undefined is still a property)
19
+ * ```
20
+ *
21
+ * @example In conditional logic
22
+ * ```typescript
23
+ * const userPreferences = loadUserPreferences();
24
+ *
25
+ * if (isEmpty(userPreferences)) {
26
+ * // Apply default settings
27
+ * applyDefaults();
28
+ * } else {
29
+ * // Use user's custom settings
30
+ * applyUserSettings(userPreferences);
31
+ * }
32
+ * ```
33
+ *
34
+ * @example Filtering collections
35
+ * ```typescript
36
+ * const configurations = [
37
+ * { api: 'v1', settings: {} },
38
+ * { api: 'v2', settings: { timeout: 5000 } },
39
+ * { api: 'v3', settings: {} }
40
+ * ];
41
+ *
42
+ * const validConfigs = configurations.filter(config => !isEmpty(config.settings));
43
+ * console.log(validConfigs); // [{ api: 'v2', settings: { timeout: 5000 } }]
44
+ * ```
45
+ *
46
+ * @example Code generation usage
47
+ * ```typescript
48
+ * class Generator {
49
+ * generateInterface(properties: Record<string, string>) {
50
+ * if (isEmpty(properties)) {
51
+ * return 'interface EmptyInterface {}';
52
+ * }
53
+ *
54
+ * const props = Object.entries(properties)
55
+ * .map(([name, type]) => ` ${name}: ${type};`)
56
+ * .join('\n');
57
+ *
58
+ * return `interface GeneratedInterface {\n${props}\n}`;
59
+ * }
60
+ * }
61
+ * ```
62
+ */
1
63
  import "../_dnt.polyfills.js";
2
64
  export const isEmpty = (value) => {
3
65
  return Object.keys(value).length === 0;
@@ -1,2 +1,82 @@
1
+ /**
2
+ * Determines whether two file paths represent different locations (import required).
3
+ *
4
+ * This utility function normalizes two file paths and compares them to determine
5
+ * if they represent different files. It's used throughout the SKMTC system to
6
+ * decide when import statements are needed - if two paths are different, an
7
+ * import is required to access symbols from one file in another.
8
+ *
9
+ * The function handles path normalization to ensure consistent comparisons
10
+ * across different operating systems and path formats (handling './' vs absolute
11
+ * paths, different separators, etc.).
12
+ *
13
+ * @param pathOne - The first file path to compare
14
+ * @param pathTwo - The second file path to compare
15
+ * @returns `true` if the paths are different (import needed), `false` if they're the same file
16
+ *
17
+ * @example Basic path comparison
18
+ * ```typescript
19
+ * import { isImported } from '@skmtc/core';
20
+ *
21
+ * // Same file, no import needed
22
+ * console.log(isImported('./src/user.ts', './src/user.ts')); // false
23
+ *
24
+ * // Different files, import needed
25
+ * console.log(isImported('./src/user.ts', './src/product.ts')); // true
26
+ * ```
27
+ *
28
+ * @example Path normalization handling
29
+ * ```typescript
30
+ * // These all represent the same file after normalization
31
+ * console.log(isImported('./src/user.ts', 'src/user.ts')); // false
32
+ * console.log(isImported('src/./user.ts', 'src/user.ts')); // false
33
+ * console.log(isImported('src/models/../user.ts', 'src/user.ts')); // false
34
+ * ```
35
+ *
36
+ * @example Usage in import decision logic
37
+ * ```typescript
38
+ * class FileGenerator {
39
+ * addImportIfNeeded(
40
+ * sourceFile: string,
41
+ * targetFile: string,
42
+ * importName: string
43
+ * ) {
44
+ * if (isImported(sourceFile, targetFile)) {
45
+ * // Files are different, add import
46
+ * this.addImport(sourceFile, targetFile, importName);
47
+ * console.log(`Added import: ${importName} from ${targetFile}`);
48
+ * } else {
49
+ * // Same file, no import needed
50
+ * console.log(`No import needed - same file: ${sourceFile}`);
51
+ * }
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * @example Cross-platform path handling
57
+ * ```typescript
58
+ * // Works consistently across platforms
59
+ * const windowsPath = 'src\\models\\user.ts';
60
+ * const unixPath = 'src/models/user.ts';
61
+ *
62
+ * console.log(isImported(windowsPath, unixPath)); // false (same file)
63
+ * ```
64
+ *
65
+ * @example In generator context
66
+ * ```typescript
67
+ * class ModelGenerator {
68
+ * generateModel(modelPath: string, referencePath: string) {
69
+ * const definition = this.createModelDefinition();
70
+ *
71
+ * if (isImported(modelPath, referencePath)) {
72
+ * // Need to import the referenced model
73
+ * definition.addImport(referencePath, 'ReferencedModel');
74
+ * }
75
+ *
76
+ * return definition;
77
+ * }
78
+ * }
79
+ * ```
80
+ */
1
81
  export declare const isImported: (pathOne: string, pathTwo: string) => boolean;
2
82
  //# sourceMappingURL=isImported.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isImported.d.ts","sourceRoot":"","sources":["../../src/helpers/isImported.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,OAE7D,CAAA"}
1
+ {"version":3,"file":"isImported.d.ts","sourceRoot":"","sources":["../../src/helpers/isImported.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,OAE7D,CAAA"}
@@ -1,4 +1,84 @@
1
1
  import { normalize } from '../deps/jsr.io/@std/path/1.1.2/normalize.js';
2
+ /**
3
+ * Determines whether two file paths represent different locations (import required).
4
+ *
5
+ * This utility function normalizes two file paths and compares them to determine
6
+ * if they represent different files. It's used throughout the SKMTC system to
7
+ * decide when import statements are needed - if two paths are different, an
8
+ * import is required to access symbols from one file in another.
9
+ *
10
+ * The function handles path normalization to ensure consistent comparisons
11
+ * across different operating systems and path formats (handling './' vs absolute
12
+ * paths, different separators, etc.).
13
+ *
14
+ * @param pathOne - The first file path to compare
15
+ * @param pathTwo - The second file path to compare
16
+ * @returns `true` if the paths are different (import needed), `false` if they're the same file
17
+ *
18
+ * @example Basic path comparison
19
+ * ```typescript
20
+ * import { isImported } from '@skmtc/core';
21
+ *
22
+ * // Same file, no import needed
23
+ * console.log(isImported('./src/user.ts', './src/user.ts')); // false
24
+ *
25
+ * // Different files, import needed
26
+ * console.log(isImported('./src/user.ts', './src/product.ts')); // true
27
+ * ```
28
+ *
29
+ * @example Path normalization handling
30
+ * ```typescript
31
+ * // These all represent the same file after normalization
32
+ * console.log(isImported('./src/user.ts', 'src/user.ts')); // false
33
+ * console.log(isImported('src/./user.ts', 'src/user.ts')); // false
34
+ * console.log(isImported('src/models/../user.ts', 'src/user.ts')); // false
35
+ * ```
36
+ *
37
+ * @example Usage in import decision logic
38
+ * ```typescript
39
+ * class FileGenerator {
40
+ * addImportIfNeeded(
41
+ * sourceFile: string,
42
+ * targetFile: string,
43
+ * importName: string
44
+ * ) {
45
+ * if (isImported(sourceFile, targetFile)) {
46
+ * // Files are different, add import
47
+ * this.addImport(sourceFile, targetFile, importName);
48
+ * console.log(`Added import: ${importName} from ${targetFile}`);
49
+ * } else {
50
+ * // Same file, no import needed
51
+ * console.log(`No import needed - same file: ${sourceFile}`);
52
+ * }
53
+ * }
54
+ * }
55
+ * ```
56
+ *
57
+ * @example Cross-platform path handling
58
+ * ```typescript
59
+ * // Works consistently across platforms
60
+ * const windowsPath = 'src\\models\\user.ts';
61
+ * const unixPath = 'src/models/user.ts';
62
+ *
63
+ * console.log(isImported(windowsPath, unixPath)); // false (same file)
64
+ * ```
65
+ *
66
+ * @example In generator context
67
+ * ```typescript
68
+ * class ModelGenerator {
69
+ * generateModel(modelPath: string, referencePath: string) {
70
+ * const definition = this.createModelDefinition();
71
+ *
72
+ * if (isImported(modelPath, referencePath)) {
73
+ * // Need to import the referenced model
74
+ * definition.addImport(referencePath, 'ReferencedModel');
75
+ * }
76
+ *
77
+ * return definition;
78
+ * }
79
+ * }
80
+ * ```
81
+ */
2
82
  export const isImported = (pathOne, pathTwo) => {
3
83
  return normalize(pathOne) !== normalize(pathTwo);
4
84
  };