@skmtc/core 0.0.792 → 0.0.793

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 (71) 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/collateExamples.d.ts +150 -0
  8. package/esm/helpers/collateExamples.d.ts.map +1 -1
  9. package/esm/helpers/collateExamples.js +145 -0
  10. package/esm/helpers/formatNumber.d.ts +95 -0
  11. package/esm/helpers/formatNumber.d.ts.map +1 -1
  12. package/esm/helpers/formatNumber.js +95 -0
  13. package/esm/helpers/generationStats.d.ts +287 -1
  14. package/esm/helpers/generationStats.d.ts.map +1 -1
  15. package/esm/helpers/generationStats.js +266 -0
  16. package/esm/helpers/isEmpty.d.ts +62 -0
  17. package/esm/helpers/isEmpty.d.ts.map +1 -1
  18. package/esm/helpers/isEmpty.js +62 -0
  19. package/esm/helpers/isImported.d.ts +80 -0
  20. package/esm/helpers/isImported.d.ts.map +1 -1
  21. package/esm/helpers/isImported.js +80 -0
  22. package/esm/helpers/parseModuleName.d.ts +175 -0
  23. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  24. package/esm/helpers/parseModuleName.js +153 -0
  25. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  26. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  27. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  28. package/esm/oas/schema/Schema.d.ts +117 -0
  29. package/esm/oas/schema/Schema.d.ts.map +1 -1
  30. package/esm/typescript/identifiers.d.ts +159 -0
  31. package/esm/typescript/identifiers.d.ts.map +1 -1
  32. package/esm/typescript/identifiers.js +159 -0
  33. package/esm/typescript/withDescription.d.ts +119 -0
  34. package/esm/typescript/withDescription.d.ts.map +1 -1
  35. package/esm/typescript/withDescription.js +119 -0
  36. package/package.json +1 -1
  37. package/script/dsl/GeneratedValueList.d.ts +158 -0
  38. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  39. package/script/dsl/GeneratedValueList.js +158 -0
  40. package/script/dsl/Stringable.d.ts +76 -0
  41. package/script/dsl/Stringable.d.ts.map +1 -1
  42. package/script/dsl/Stringable.js +75 -0
  43. package/script/helpers/collateExamples.d.ts +150 -0
  44. package/script/helpers/collateExamples.d.ts.map +1 -1
  45. package/script/helpers/collateExamples.js +145 -0
  46. package/script/helpers/formatNumber.d.ts +95 -0
  47. package/script/helpers/formatNumber.d.ts.map +1 -1
  48. package/script/helpers/formatNumber.js +95 -0
  49. package/script/helpers/generationStats.d.ts +287 -1
  50. package/script/helpers/generationStats.d.ts.map +1 -1
  51. package/script/helpers/generationStats.js +266 -0
  52. package/script/helpers/isEmpty.d.ts +62 -0
  53. package/script/helpers/isEmpty.d.ts.map +1 -1
  54. package/script/helpers/isEmpty.js +62 -0
  55. package/script/helpers/isImported.d.ts +80 -0
  56. package/script/helpers/isImported.d.ts.map +1 -1
  57. package/script/helpers/isImported.js +80 -0
  58. package/script/helpers/parseModuleName.d.ts +175 -0
  59. package/script/helpers/parseModuleName.d.ts.map +1 -1
  60. package/script/helpers/parseModuleName.js +153 -0
  61. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  62. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  63. package/script/helpers/toResolvedArtifactPath.js +140 -0
  64. package/script/oas/schema/Schema.d.ts +117 -0
  65. package/script/oas/schema/Schema.d.ts.map +1 -1
  66. package/script/typescript/identifiers.d.ts +159 -0
  67. package/script/typescript/identifiers.d.ts.map +1 -1
  68. package/script/typescript/identifiers.js +159 -0
  69. package/script/typescript/withDescription.d.ts +119 -0
  70. package/script/typescript/withDescription.d.ts.map +1 -1
  71. package/script/typescript/withDescription.js +119 -0
@@ -1,26 +1,312 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import type { ManifestContent } from '../types/Manifest.js';
3
3
  import type { ResultsItem, ResultType } from '../types/Results.js';
4
+ /**
5
+ * Arguments for generating comprehensive statistics from the build manifest and artifacts.
6
+ */
4
7
  type GenerationStatsArgs = {
8
+ /** The generation manifest containing build metadata and results */
5
9
  manifest: ManifestContent;
10
+ /** Generated artifacts as a map of file paths to content */
6
11
  artifacts: Record<string, string>;
7
12
  };
8
- export declare const toGenerationStats: ({ manifest, artifacts }: GenerationStatsArgs) => {
13
+ /**
14
+ * Comprehensive generation statistics extracted from build artifacts and manifest.
15
+ */
16
+ export type GenerationStats = {
17
+ /** Total number of GPT tokens in generated content */
9
18
  tokens: number;
19
+ /** Total number of lines generated */
10
20
  lines: number;
21
+ /** Total generation time in milliseconds */
11
22
  totalTime: number;
23
+ /** Error paths organized as nested arrays */
12
24
  errors: string[][];
25
+ /** Total number of generated files */
13
26
  files: number;
14
27
  };
28
+ /**
29
+ * Generates comprehensive statistics about the code generation process.
30
+ *
31
+ * This function analyzes the generation manifest and produced artifacts to create
32
+ * detailed statistics including token counts, lines of code, timing information,
33
+ * error tracking, and file counts. It's used for performance monitoring, debugging,
34
+ * and reporting on generation runs.
35
+ *
36
+ * The function combines multiple analysis methods to provide a complete picture
37
+ * of the generation process, including tokenization analysis for cost estimation,
38
+ * error path extraction for debugging, and timing analysis for performance optimization.
39
+ *
40
+ * @param args - Generation analysis configuration
41
+ * @param args.manifest - The generation manifest with metadata and results
42
+ * @param args.artifacts - Map of file paths to generated content
43
+ * @returns Comprehensive generation statistics object
44
+ *
45
+ * @example Basic usage
46
+ * ```typescript
47
+ * import { toGenerationStats } from '@skmtc/core';
48
+ *
49
+ * const stats = toGenerationStats({
50
+ * manifest: {
51
+ * startAt: 1672531200000,
52
+ * endAt: 1672531245000,
53
+ * files: {
54
+ * './models.ts': { lines: 150, characters: 4500 },
55
+ * './types.ts': { lines: 80, characters: 2100 }
56
+ * },
57
+ * results: { }
58
+ * },
59
+ * artifacts: {
60
+ * './models.ts': 'export interface User { id: string; name: string; }',
61
+ * './types.ts': 'export type Status = "active" | "inactive";'
62
+ * }
63
+ * });
64
+ *
65
+ * console.log(stats);
66
+ * // {
67
+ * // tokens: 250,
68
+ * // lines: 230,
69
+ * // totalTime: 45000,
70
+ * // errors: [],
71
+ * // files: 2
72
+ * // }
73
+ * ```
74
+ *
75
+ * @example Performance monitoring
76
+ * ```typescript
77
+ * class GenerationMonitor {
78
+ * analyzeGeneration(manifest: ManifestContent, artifacts: Record<string, string>) {
79
+ * const stats = toGenerationStats({ manifest, artifacts });
80
+ *
81
+ * console.log(`Generation completed in ${stats.totalTime}ms`);
82
+ * console.log(`Generated ${stats.files} files with ${stats.lines} lines`);
83
+ * console.log(`Token usage: ${stats.tokens} tokens`);
84
+ *
85
+ * if (stats.errors.length > 0) {
86
+ * console.warn(`Found ${stats.errors.length} errors:`);
87
+ * stats.errors.forEach((errorPath, index) => {
88
+ * console.warn(` ${index + 1}. ${errorPath.join(' -> ')}`);
89
+ * });
90
+ * }
91
+ *
92
+ * return stats;
93
+ * }
94
+ * }
95
+ * ```
96
+ *
97
+ * @example Cost estimation
98
+ * ```typescript
99
+ * function estimateGenerationCost(stats: GenerationStats): number {
100
+ * const tokensPerDollar = 1000000; // Example rate
101
+ * const estimatedCost = stats.tokens / tokensPerDollar;
102
+ *
103
+ * console.log(`Estimated cost: $${estimatedCost.toFixed(4)}`);
104
+ * console.log(`Efficiency: ${stats.lines / stats.tokens} lines per token`);
105
+ *
106
+ * return estimatedCost;
107
+ * }
108
+ * ```
109
+ *
110
+ * @example Build reporting
111
+ * ```typescript
112
+ * function generateBuildReport(stats: GenerationStats): string {
113
+ * const efficiency = stats.totalTime / stats.files;
114
+ * const successRate = ((stats.files - stats.errors.length) / stats.files * 100).toFixed(1);
115
+ *
116
+ * return `
117
+ * Build Report:
118
+ * -----------
119
+ * Files Generated: ${stats.files}
120
+ * Total Lines: ${stats.lines.toLocaleString()}
121
+ * Token Count: ${stats.tokens.toLocaleString()}
122
+ * Generation Time: ${(stats.totalTime / 1000).toFixed(2)}s
123
+ * Average per File: ${efficiency.toFixed(0)}ms
124
+ * Success Rate: ${successRate}%
125
+ * Errors: ${stats.errors.length}
126
+ * `.trim();
127
+ * }
128
+ * ```
129
+ */
130
+ export declare const toGenerationStats: ({ manifest, artifacts }: GenerationStatsArgs) => GenerationStats;
131
+ /**
132
+ * Calculates the total number of GPT tokens in all generated artifacts.
133
+ *
134
+ * This function uses GPT tokenization to count the total number of tokens
135
+ * across all generated code artifacts. This is useful for cost estimation
136
+ * when using token-based pricing models and for understanding the size
137
+ * and complexity of generated content.
138
+ *
139
+ * @param artifacts - Map of file paths to generated content strings
140
+ * @returns Total number of GPT tokens across all artifacts
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const artifacts = {
145
+ * './models.ts': 'export interface User { id: string; name: string; }',
146
+ * './types.ts': 'export type Status = "active" | "inactive";'
147
+ * };
148
+ *
149
+ * const tokens = toManifestTokens(artifacts);
150
+ * console.log(tokens); // e.g., 24 tokens
151
+ * ```
152
+ */
15
153
  export declare const toManifestTokens: (artifacts: Record<string, string>) => number;
154
+ /**
155
+ * Calculates the total number of lines across all generated files.
156
+ *
157
+ * This function sums up the line counts from the manifest's file metadata
158
+ * to provide the total lines of code generated. This metric is useful
159
+ * for understanding the scale of code generation and tracking productivity.
160
+ *
161
+ * @param manifest - The generation manifest containing file metadata
162
+ * @returns Total number of lines across all generated files
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const manifest = {
167
+ * files: {
168
+ * './models.ts': { lines: 150, characters: 4500 },
169
+ * './types.ts': { lines: 80, characters: 2100 }
170
+ * },
171
+ * // ... other manifest properties
172
+ * };
173
+ *
174
+ * const lines = toManifestLines(manifest);
175
+ * console.log(lines); // 230
176
+ * ```
177
+ */
16
178
  export declare const toManifestLines: (manifest: ManifestContent) => number;
179
+ /**
180
+ * Calculates the total generation time from the manifest timestamps.
181
+ *
182
+ * This function computes the duration of the generation process by
183
+ * calculating the difference between the end and start timestamps
184
+ * recorded in the manifest. The result is in milliseconds.
185
+ *
186
+ * @param manifest - The generation manifest with timing information
187
+ * @returns Total generation time in milliseconds
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const manifest = {
192
+ * startAt: 1672531200000, // January 1, 2023 00:00:00 GMT
193
+ * endAt: 1672531245000, // January 1, 2023 00:00:45 GMT
194
+ * // ... other manifest properties
195
+ * };
196
+ *
197
+ * const duration = toTotalTime(manifest);
198
+ * console.log(duration); // 45000 (45 seconds)
199
+ * console.log(`${duration / 1000}s`); // "45s"
200
+ * ```
201
+ */
17
202
  export declare const toTotalTime: (manifest: ManifestContent) => number;
203
+ /**
204
+ * Extracts and organizes error paths from the manifest results.
205
+ *
206
+ * This function recursively traverses the results structure in the manifest
207
+ * to identify all error conditions and their associated file paths. Errors
208
+ * are returned as arrays of path segments, making it easy to understand
209
+ * the location and context of each error.
210
+ *
211
+ * @param results - The results object from the generation manifest
212
+ * @returns Array of error paths, each represented as an array of path segments
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const results = {
217
+ * 'models.ts': {
218
+ * 'User': 'success',
219
+ * 'Product': 'error'
220
+ * },
221
+ * 'types.ts': 'success'
222
+ * };
223
+ *
224
+ * const errors = toManifestErrors(results);
225
+ * console.log(errors); // [['models.ts', 'Product']]
226
+ *
227
+ * // Display errors in readable format
228
+ * errors.forEach(errorPath => {
229
+ * console.log(`Error at: ${errorPath.join(' -> ')}`);
230
+ * });
231
+ * // Output: "Error at: models.ts -> Product"
232
+ * ```
233
+ */
18
234
  export declare const toManifestErrors: (results: ManifestContent["results"]) => string[][];
235
+ /**
236
+ * Arguments for recursively checking results for error conditions.
237
+ */
19
238
  type CheckResultArgs = {
239
+ /** Current path segments being traversed */
20
240
  path: string[];
241
+ /** The result value to check (can be nested) */
21
242
  result: ResultsItem | (ResultsItem | null)[] | ResultType;
243
+ /** Array to accumulate error paths (mutated) */
22
244
  errors: string[][];
23
245
  };
246
+ /**
247
+ * Recursively checks results structure for error conditions and collects error paths.
248
+ *
249
+ * This function traverses the complex nested structure of generation results,
250
+ * identifying error conditions at any level and recording their full path context.
251
+ * It handles arrays, objects, strings, and null values, building a comprehensive
252
+ * map of all errors that occurred during generation.
253
+ *
254
+ * The function mutates the errors array parameter, accumulating error paths
255
+ * as it traverses the results structure. This approach is used for performance
256
+ * when processing large result sets.
257
+ *
258
+ * @param args - Arguments for result checking
259
+ * @param args.path - Current path segments being traversed
260
+ * @param args.result - The result value to check for errors
261
+ * @param args.errors - Array to accumulate error paths (mutated by function)
262
+ *
263
+ * @example Simple error detection
264
+ * ```typescript
265
+ * const errors: string[][] = [];
266
+ *
267
+ * checkResult({
268
+ * path: ['models.ts'],
269
+ * result: 'error',
270
+ * errors
271
+ * });
272
+ *
273
+ * console.log(errors); // [['models.ts']]
274
+ * ```
275
+ *
276
+ * @example Nested structure error detection
277
+ * ```typescript
278
+ * const errors: string[][] = [];
279
+ * const nestedResult = {
280
+ * 'User': 'success',
281
+ * 'Product': {
282
+ * 'validation': 'error',
283
+ * 'generation': 'success'
284
+ * }
285
+ * };
286
+ *
287
+ * checkResult({
288
+ * path: ['models.ts'],
289
+ * result: nestedResult,
290
+ * errors
291
+ * });
292
+ *
293
+ * console.log(errors); // [['models.ts', 'Product', 'validation']]
294
+ * ```
295
+ *
296
+ * @example Array handling
297
+ * ```typescript
298
+ * const errors: string[][] = [];
299
+ * const arrayResult = ['success', null, 'error', 'success'];
300
+ *
301
+ * checkResult({
302
+ * path: ['batch'],
303
+ * result: arrayResult,
304
+ * errors
305
+ * });
306
+ *
307
+ * console.log(errors); // [['batch']] - for the 'error' item
308
+ * ```
309
+ */
24
310
  export declare const checkResult: ({ path, result, errors }: CheckResultArgs) => void;
25
311
  export {};
26
312
  //# sourceMappingURL=generationStats.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generationStats.d.ts","sourceRoot":"","sources":["../../src/helpers/generationStats.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;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,gDAAgD;IAChD,MAAM,EAAE,WAAW,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,GAAG,UAAU,CAAA;IACzD,gDAAgD;IAChD,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,WAAW,GAAI,0BAA0B,eAAe,KAAG,IA0BvE,CAAA"}
@@ -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"}