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