@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,151 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import { match } from 'ts-pattern';
3
3
  import { isEmpty } from './isEmpty.js';
4
+ /**
5
+ * Recursively collates and builds example values from OpenAPI schemas.
6
+ *
7
+ * This function traverses OpenAPI schema structures and generates comprehensive
8
+ * example values based on the schema definitions and any explicit examples provided.
9
+ * It handles complex nested structures including objects, arrays, unions, and
10
+ * references while preventing infinite recursion through depth limiting.
11
+ *
12
+ * The function prioritizes explicit examples when available and falls back to
13
+ * generating examples from nested schemas. It's particularly useful for creating
14
+ * realistic test data, API documentation examples, and mock responses.
15
+ *
16
+ * @param args - Configuration for example collation
17
+ * @param args.objectSchema - The schema to extract examples from
18
+ * @param args.depth - Current recursion depth (prevents infinite loops)
19
+ * @returns Collated example value matching the schema structure, or undefined if no examples
20
+ *
21
+ * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
22
+ *
23
+ * @example Basic schema examples
24
+ * ```typescript
25
+ * import { collateExamples } from '@skmtc/core';
26
+ *
27
+ * // String schema with example
28
+ * const stringSchema = new OasString({ example: 'john.doe@example.com' });
29
+ * const example = collateExamples({ objectSchema: stringSchema, depth: 0 });
30
+ * console.log(example); // 'john.doe@example.com'
31
+ *
32
+ * // Number schema with example
33
+ * const numberSchema = new OasNumber({ example: 42 });
34
+ * const numExample = collateExamples({ objectSchema: numberSchema, depth: 0 });
35
+ * console.log(numExample); // 42
36
+ * ```
37
+ *
38
+ * @example Object schema examples
39
+ * ```typescript
40
+ * // Object schema with nested properties
41
+ * const userSchema = new OasObject({
42
+ * properties: {
43
+ * id: new OasInteger({ example: 123 }),
44
+ * name: new OasString({ example: 'John Doe' }),
45
+ * email: new OasString({ example: 'john@example.com' }),
46
+ * age: new OasInteger({ example: 30 })
47
+ * }
48
+ * });
49
+ *
50
+ * const userExample = collateExamples({ objectSchema: userSchema, depth: 0 });
51
+ * console.log(userExample);
52
+ * // {
53
+ * // id: 123,
54
+ * // name: 'John Doe',
55
+ * // email: 'john@example.com',
56
+ * // age: 30
57
+ * // }
58
+ * ```
59
+ *
60
+ * @example Array schema examples
61
+ * ```typescript
62
+ * // Array of objects
63
+ * const usersArraySchema = new OasArray({
64
+ * items: new OasObject({
65
+ * properties: {
66
+ * id: new OasInteger({ example: 1 }),
67
+ * name: new OasString({ example: 'Jane Smith' })
68
+ * }
69
+ * })
70
+ * });
71
+ *
72
+ * const arrayExample = collateExamples({ objectSchema: usersArraySchema, depth: 0 });
73
+ * console.log(arrayExample);
74
+ * // [
75
+ * // {
76
+ * // id: 1,
77
+ * // name: 'Jane Smith'
78
+ * // }
79
+ * // ]
80
+ * ```
81
+ *
82
+ * @example Union schema examples
83
+ * ```typescript
84
+ * // Union of string and number
85
+ * const unionSchema = new OasUnion({
86
+ * members: [
87
+ * new OasString({ example: 'text-value' }),
88
+ * new OasNumber({ example: 99 })
89
+ * ]
90
+ * });
91
+ *
92
+ * const unionExample = collateExamples({ objectSchema: unionSchema, depth: 0 });
93
+ * console.log(unionExample); // 'text-value' (first member with example)
94
+ * ```
95
+ *
96
+ * @example Reference resolution
97
+ * ```typescript
98
+ * // Schema with reference to another schema
99
+ * const addressRef = new OasRef({
100
+ * $ref: '#/components/schemas/Address',
101
+ * resolve: () => new OasObject({
102
+ * properties: {
103
+ * street: new OasString({ example: '123 Main St' }),
104
+ * city: new OasString({ example: 'Springfield' })
105
+ * }
106
+ * })
107
+ * });
108
+ *
109
+ * const refExample = collateExamples({ objectSchema: addressRef, depth: 0 });
110
+ * console.log(refExample);
111
+ * // {
112
+ * // street: '123 Main St',
113
+ * // city: 'Springfield'
114
+ * // }
115
+ * ```
116
+ *
117
+ * @example Depth limiting and error handling
118
+ * ```typescript
119
+ * // Deep nesting detection
120
+ * try {
121
+ * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
122
+ * } catch (error) {
123
+ * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
124
+ * }
125
+ *
126
+ * // Handling missing schemas
127
+ * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
128
+ * console.log(emptyExample); // undefined
129
+ * ```
130
+ *
131
+ * @example Using in API documentation generation
132
+ * ```typescript
133
+ * class ApiDocGenerator {
134
+ * generateExampleResponse(responseSchema: OasSchema) {
135
+ * const example = collateExamples({ objectSchema: responseSchema, depth: 0 });
136
+ *
137
+ * if (example) {
138
+ * return {
139
+ * description: 'Example response',
140
+ * value: example
141
+ * };
142
+ * }
143
+ *
144
+ * return { description: 'No example available' };
145
+ * }
146
+ * }
147
+ * ```
148
+ */
4
149
  export const collateExamples = ({ objectSchema, depth }) => {
5
150
  if (!objectSchema) {
6
151
  return undefined;
@@ -1,3 +1,98 @@
1
+ /**
2
+ * Formats a number using locale-specific formatting without decimal places.
3
+ *
4
+ * This utility function formats numbers according to locale conventions,
5
+ * adding thousand separators and other locale-specific number formatting
6
+ * while ensuring the output contains no fractional digits. It's useful
7
+ * for displaying counts, statistics, or other whole numbers in a
8
+ * human-readable format.
9
+ *
10
+ * @param value - The number to format
11
+ * @param locales - The locale(s) to use for formatting (defaults to 'en-US')
12
+ * @returns The formatted number as a string with locale-appropriate thousand separators
13
+ *
14
+ * @example Basic formatting with default locale (en-US)
15
+ * ```typescript
16
+ * import { formatNumber } from '@skmtc/core';
17
+ *
18
+ * console.log(formatNumber(1234)); // '1,234'
19
+ * console.log(formatNumber(1234567)); // '1,234,567'
20
+ * console.log(formatNumber(42)); // '42'
21
+ * console.log(formatNumber(0)); // '0'
22
+ * ```
23
+ *
24
+ * @example Formatting with different locales
25
+ * ```typescript
26
+ * const bigNumber = 1234567;
27
+ *
28
+ * console.log(formatNumber(bigNumber, 'en-US')); // '1,234,567'
29
+ * console.log(formatNumber(bigNumber, 'de-DE')); // '1.234.567'
30
+ * console.log(formatNumber(bigNumber, 'fr-FR')); // '1 234 567'
31
+ * console.log(formatNumber(bigNumber, 'en-IN')); // '12,34,567'
32
+ * ```
33
+ *
34
+ * @example Formatting decimal numbers (fractional part removed)
35
+ * ```typescript
36
+ * // The function always rounds to whole numbers
37
+ * console.log(formatNumber(1234.56)); // '1,235' (rounded)
38
+ * console.log(formatNumber(999.99)); // '1,000' (rounded)
39
+ * console.log(formatNumber(1000.1)); // '1,000' (rounded)
40
+ * console.log(formatNumber(1000.0)); // '1,000'
41
+ * ```
42
+ *
43
+ * @example Usage in reporting and statistics
44
+ * ```typescript
45
+ * class StatsReporter {
46
+ * generateReport(stats: {
47
+ * totalFiles: number;
48
+ * linesGenerated: number;
49
+ * errors: number;
50
+ * }) {
51
+ * return `
52
+ * Generation Report:
53
+ * - Files generated: ${formatNumber(stats.totalFiles)}
54
+ * - Lines of code: ${formatNumber(stats.linesGenerated)}
55
+ * - Errors encountered: ${formatNumber(stats.errors)}
56
+ * `.trim();
57
+ * }
58
+ * }
59
+ *
60
+ * const reporter = new StatsReporter();
61
+ * const report = reporter.generateReport({
62
+ * totalFiles: 1234,
63
+ * linesGenerated: 567890,
64
+ * errors: 5
65
+ * });
66
+ *
67
+ * console.log(report);
68
+ * // Generation Report:
69
+ * // - Files generated: 1,234
70
+ * // - Lines of code: 567,890
71
+ * // - Errors encountered: 5
72
+ * ```
73
+ *
74
+ * @example International number formatting
75
+ * ```typescript
76
+ * const count = 50000;
77
+ *
78
+ * // Different regions format numbers differently
79
+ * const formats = [
80
+ * { locale: 'en-US', label: 'US English' },
81
+ * { locale: 'de-DE', label: 'German' },
82
+ * { locale: 'fr-FR', label: 'French' },
83
+ * { locale: 'ja-JP', label: 'Japanese' }
84
+ * ];
85
+ *
86
+ * formats.forEach(({ locale, label }) => {
87
+ * console.log(`${label}: ${formatNumber(count, locale)}`);
88
+ * });
89
+ *
90
+ * // US English: 50,000
91
+ * // German: 50.000
92
+ * // French: 50 000
93
+ * // Japanese: 50,000
94
+ * ```
95
+ */
1
96
  import "../_dnt.polyfills.js";
2
97
  export declare const formatNumber: (value: number, locales?: Intl.LocalesArgument) => string;
3
98
  //# sourceMappingURL=formatNumber.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatNumber.d.ts","sourceRoot":"","sources":["../../src/helpers/formatNumber.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,UAAS,IAAI,CAAC,eAAyB,KAAG,MAKrF,CAAA"}
1
+ {"version":3,"file":"formatNumber.d.ts","sourceRoot":"","sources":["../../src/helpers/formatNumber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,UAAS,IAAI,CAAC,eAAyB,KAAG,MAKrF,CAAA"}
@@ -1,3 +1,98 @@
1
+ /**
2
+ * Formats a number using locale-specific formatting without decimal places.
3
+ *
4
+ * This utility function formats numbers according to locale conventions,
5
+ * adding thousand separators and other locale-specific number formatting
6
+ * while ensuring the output contains no fractional digits. It's useful
7
+ * for displaying counts, statistics, or other whole numbers in a
8
+ * human-readable format.
9
+ *
10
+ * @param value - The number to format
11
+ * @param locales - The locale(s) to use for formatting (defaults to 'en-US')
12
+ * @returns The formatted number as a string with locale-appropriate thousand separators
13
+ *
14
+ * @example Basic formatting with default locale (en-US)
15
+ * ```typescript
16
+ * import { formatNumber } from '@skmtc/core';
17
+ *
18
+ * console.log(formatNumber(1234)); // '1,234'
19
+ * console.log(formatNumber(1234567)); // '1,234,567'
20
+ * console.log(formatNumber(42)); // '42'
21
+ * console.log(formatNumber(0)); // '0'
22
+ * ```
23
+ *
24
+ * @example Formatting with different locales
25
+ * ```typescript
26
+ * const bigNumber = 1234567;
27
+ *
28
+ * console.log(formatNumber(bigNumber, 'en-US')); // '1,234,567'
29
+ * console.log(formatNumber(bigNumber, 'de-DE')); // '1.234.567'
30
+ * console.log(formatNumber(bigNumber, 'fr-FR')); // '1 234 567'
31
+ * console.log(formatNumber(bigNumber, 'en-IN')); // '12,34,567'
32
+ * ```
33
+ *
34
+ * @example Formatting decimal numbers (fractional part removed)
35
+ * ```typescript
36
+ * // The function always rounds to whole numbers
37
+ * console.log(formatNumber(1234.56)); // '1,235' (rounded)
38
+ * console.log(formatNumber(999.99)); // '1,000' (rounded)
39
+ * console.log(formatNumber(1000.1)); // '1,000' (rounded)
40
+ * console.log(formatNumber(1000.0)); // '1,000'
41
+ * ```
42
+ *
43
+ * @example Usage in reporting and statistics
44
+ * ```typescript
45
+ * class StatsReporter {
46
+ * generateReport(stats: {
47
+ * totalFiles: number;
48
+ * linesGenerated: number;
49
+ * errors: number;
50
+ * }) {
51
+ * return `
52
+ * Generation Report:
53
+ * - Files generated: ${formatNumber(stats.totalFiles)}
54
+ * - Lines of code: ${formatNumber(stats.linesGenerated)}
55
+ * - Errors encountered: ${formatNumber(stats.errors)}
56
+ * `.trim();
57
+ * }
58
+ * }
59
+ *
60
+ * const reporter = new StatsReporter();
61
+ * const report = reporter.generateReport({
62
+ * totalFiles: 1234,
63
+ * linesGenerated: 567890,
64
+ * errors: 5
65
+ * });
66
+ *
67
+ * console.log(report);
68
+ * // Generation Report:
69
+ * // - Files generated: 1,234
70
+ * // - Lines of code: 567,890
71
+ * // - Errors encountered: 5
72
+ * ```
73
+ *
74
+ * @example International number formatting
75
+ * ```typescript
76
+ * const count = 50000;
77
+ *
78
+ * // Different regions format numbers differently
79
+ * const formats = [
80
+ * { locale: 'en-US', label: 'US English' },
81
+ * { locale: 'de-DE', label: 'German' },
82
+ * { locale: 'fr-FR', label: 'French' },
83
+ * { locale: 'ja-JP', label: 'Japanese' }
84
+ * ];
85
+ *
86
+ * formats.forEach(({ locale, label }) => {
87
+ * console.log(`${label}: ${formatNumber(count, locale)}`);
88
+ * });
89
+ *
90
+ * // US English: 50,000
91
+ * // German: 50.000
92
+ * // French: 50 000
93
+ * // Japanese: 50,000
94
+ * ```
95
+ */
1
96
  import "../_dnt.polyfills.js";
2
97
  export const formatNumber = (value, locales = 'en-US') => {
3
98
  return value.toLocaleString(locales, {
@@ -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.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAIlE,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,eAAe,CAAA;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAA;AACD,eAAO,MAAM,iBAAiB,GAAI,yBAAyB,mBAAmB,KAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAcrK,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAOpE,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,UAAU,eAAe,KAAG,MAO3D,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,UAAU,eAAe,KAAG,MAIvD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,eAAe,CAAC,SAAS,CAAC,KAAG,MAAM,EAAE,EAQ9E,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,MAAM,EAAE,WAAW,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,GAAG,UAAU,CAAA;IACzD,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,0BAA0B,eAAe,KAAG,IA0BvE,CAAA"}
1
+ {"version":3,"file":"generationStats.d.ts","sourceRoot":"","sources":["../../src/helpers/generationStats.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAIlE;;GAEG;AACH,KAAK,mBAAmB,GAAG;IACzB,oEAAoE;IACpE,QAAQ,EAAE,eAAe,CAAA;IACzB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;IAClB,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AACH,eAAO,MAAM,iBAAiB,GAAI,yBAAyB,mBAAmB,KAAG,eAchF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAOpE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,eAAe,KAAG,MAO3D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,eAAe,KAAG,MAIvD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,eAAe,CAAC,SAAS,CAAC,KAAG,MAAM,EAAE,EAQ9E,CAAA;AAED;;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"}