@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.
- package/esm/dsl/GeneratedValueList.d.ts +158 -0
- package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
- package/esm/dsl/GeneratedValueList.js +158 -0
- package/esm/dsl/Stringable.d.ts +76 -0
- package/esm/dsl/Stringable.d.ts.map +1 -1
- package/esm/dsl/Stringable.js +75 -0
- package/esm/helpers/ResultsLog.d.ts +193 -0
- package/esm/helpers/ResultsLog.d.ts.map +1 -1
- package/esm/helpers/ResultsLog.js +213 -0
- package/esm/helpers/collateExamples.d.ts +150 -0
- package/esm/helpers/collateExamples.d.ts.map +1 -1
- package/esm/helpers/collateExamples.js +145 -0
- package/esm/helpers/formatNumber.d.ts +95 -0
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +95 -0
- package/esm/helpers/generationStats.d.ts +287 -1
- package/esm/helpers/generationStats.d.ts.map +1 -1
- package/esm/helpers/generationStats.js +266 -0
- package/esm/helpers/isEmpty.d.ts +62 -0
- package/esm/helpers/isEmpty.d.ts.map +1 -1
- package/esm/helpers/isEmpty.js +62 -0
- package/esm/helpers/isImported.d.ts +80 -0
- package/esm/helpers/isImported.d.ts.map +1 -1
- package/esm/helpers/isImported.js +80 -0
- package/esm/helpers/parseModuleName.d.ts +175 -0
- package/esm/helpers/parseModuleName.d.ts.map +1 -1
- package/esm/helpers/parseModuleName.js +153 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/esm/helpers/toResolvedArtifactPath.js +140 -0
- package/esm/helpers/tracer.d.ts +124 -0
- package/esm/helpers/tracer.d.ts.map +1 -1
- package/esm/helpers/tracer.js +124 -0
- package/esm/oas/schema/Schema.d.ts +117 -0
- package/esm/oas/schema/Schema.d.ts.map +1 -1
- package/esm/typescript/PathParams.d.ts +198 -0
- package/esm/typescript/PathParams.d.ts.map +1 -1
- package/esm/typescript/PathParams.js +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/esm/typescript/ReactRouterPathParams.js +183 -0
- package/esm/typescript/identifiers.d.ts +159 -0
- package/esm/typescript/identifiers.d.ts.map +1 -1
- package/esm/typescript/identifiers.js +159 -0
- package/esm/typescript/keyValues.d.ts +125 -0
- package/esm/typescript/keyValues.d.ts.map +1 -1
- package/esm/typescript/keyValues.js +125 -1
- package/esm/typescript/toPathParams.d.ts +179 -0
- package/esm/typescript/toPathParams.d.ts.map +1 -1
- package/esm/typescript/toPathParams.js +179 -0
- package/esm/typescript/toPathTemplate.d.ts +114 -0
- package/esm/typescript/toPathTemplate.d.ts.map +1 -1
- package/esm/typescript/toPathTemplate.js +114 -0
- package/esm/typescript/withDescription.d.ts +119 -0
- package/esm/typescript/withDescription.d.ts.map +1 -1
- package/esm/typescript/withDescription.js +119 -0
- package/package.json +1 -1
- package/script/dsl/GeneratedValueList.d.ts +158 -0
- package/script/dsl/GeneratedValueList.d.ts.map +1 -1
- package/script/dsl/GeneratedValueList.js +158 -0
- package/script/dsl/Stringable.d.ts +76 -0
- package/script/dsl/Stringable.d.ts.map +1 -1
- package/script/dsl/Stringable.js +75 -0
- package/script/helpers/ResultsLog.d.ts +193 -0
- package/script/helpers/ResultsLog.d.ts.map +1 -1
- package/script/helpers/ResultsLog.js +213 -0
- package/script/helpers/collateExamples.d.ts +150 -0
- package/script/helpers/collateExamples.d.ts.map +1 -1
- package/script/helpers/collateExamples.js +145 -0
- package/script/helpers/formatNumber.d.ts +95 -0
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +95 -0
- package/script/helpers/generationStats.d.ts +287 -1
- package/script/helpers/generationStats.d.ts.map +1 -1
- package/script/helpers/generationStats.js +266 -0
- package/script/helpers/isEmpty.d.ts +62 -0
- package/script/helpers/isEmpty.d.ts.map +1 -1
- package/script/helpers/isEmpty.js +62 -0
- package/script/helpers/isImported.d.ts +80 -0
- package/script/helpers/isImported.d.ts.map +1 -1
- package/script/helpers/isImported.js +80 -0
- package/script/helpers/parseModuleName.d.ts +175 -0
- package/script/helpers/parseModuleName.d.ts.map +1 -1
- package/script/helpers/parseModuleName.js +153 -0
- package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/script/helpers/toResolvedArtifactPath.js +140 -0
- package/script/helpers/tracer.d.ts +124 -0
- package/script/helpers/tracer.d.ts.map +1 -1
- package/script/helpers/tracer.js +124 -0
- package/script/oas/schema/Schema.d.ts +117 -0
- package/script/oas/schema/Schema.d.ts.map +1 -1
- package/script/typescript/PathParams.d.ts +198 -0
- package/script/typescript/PathParams.d.ts.map +1 -1
- package/script/typescript/PathParams.js +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/script/typescript/ReactRouterPathParams.js +183 -0
- package/script/typescript/identifiers.d.ts +159 -0
- package/script/typescript/identifiers.d.ts.map +1 -1
- package/script/typescript/identifiers.js +159 -0
- package/script/typescript/keyValues.d.ts +125 -0
- package/script/typescript/keyValues.d.ts.map +1 -1
- package/script/typescript/keyValues.js +125 -1
- package/script/typescript/toPathParams.d.ts +179 -0
- package/script/typescript/toPathParams.d.ts.map +1 -1
- package/script/typescript/toPathParams.js +179 -0
- package/script/typescript/toPathTemplate.d.ts +114 -0
- package/script/typescript/toPathTemplate.d.ts.map +1 -1
- package/script/typescript/toPathTemplate.js +114 -0
- package/script/typescript/withDescription.d.ts +119 -0
- package/script/typescript/withDescription.d.ts.map +1 -1
- package/script/typescript/withDescription.js +119 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,OAAO,sBAAsB,CAAC;AAE9B,MAAM,MAAM,UAAU,GAAG;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,MAAM,CAAA;CACvB,CAAA"}
|
package/script/dsl/Stringable.js
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Represents any object that can be converted to a string representation.
|
|
5
|
+
*
|
|
6
|
+
* The `Stringable` interface is a fundamental type used throughout the SKMTC DSL
|
|
7
|
+
* system to ensure that objects can be converted to strings for code generation.
|
|
8
|
+
* This interface matches JavaScript's built-in `toString()` contract and is used
|
|
9
|
+
* extensively by the {@link List} class and other string-building utilities.
|
|
10
|
+
*
|
|
11
|
+
* ## Usage in SKMTC
|
|
12
|
+
*
|
|
13
|
+
* This type is used as a constraint in generic classes and functions that need
|
|
14
|
+
* to output string representations. It allows for type-safe string building
|
|
15
|
+
* while accommodating both primitive types and custom objects.
|
|
16
|
+
*
|
|
17
|
+
* @example Built-in types are stringable
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import type { Stringable } from '@skmtc/core';
|
|
20
|
+
*
|
|
21
|
+
* // All these types implement Stringable
|
|
22
|
+
* const str: Stringable = 'hello'; // string
|
|
23
|
+
* const num: Stringable = 42; // number
|
|
24
|
+
* const bool: Stringable = true; // boolean
|
|
25
|
+
* const obj: Stringable = { toString: () => 'custom' }; // custom object
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Custom classes implementing Stringable
|
|
29
|
+
* ```typescript
|
|
30
|
+
* class CodeBlock implements Stringable {
|
|
31
|
+
* constructor(private code: string) {}
|
|
32
|
+
*
|
|
33
|
+
* toString(): string {
|
|
34
|
+
* return `{\n ${this.code}\n}`;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* const block = new CodeBlock('console.log("hello");');
|
|
39
|
+
* console.log(block.toString());
|
|
40
|
+
* // {
|
|
41
|
+
* // console.log("hello");
|
|
42
|
+
* // }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Using with List class
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { List } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* // List accepts any Stringable items
|
|
50
|
+
* const stringables: Stringable[] = [
|
|
51
|
+
* 'string literal',
|
|
52
|
+
* 42,
|
|
53
|
+
* true,
|
|
54
|
+
* { toString: () => 'custom object' },
|
|
55
|
+
* new CodeBlock('return value;')
|
|
56
|
+
* ];
|
|
57
|
+
*
|
|
58
|
+
* const list = new List(stringables);
|
|
59
|
+
* console.log(list.toString());
|
|
60
|
+
* // string literal, 42, true, custom object, {
|
|
61
|
+
* // return value;
|
|
62
|
+
* // }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example Type constraints in generics
|
|
66
|
+
* ```typescript
|
|
67
|
+
* function joinWithCommas<T extends Stringable>(items: T[]): string {
|
|
68
|
+
* return items.map(item => item.toString()).join(', ');
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* const result = joinWithCommas([1, 2, 3]); // "1, 2, 3"
|
|
72
|
+
* const identifiers = joinWithCommas([
|
|
73
|
+
* Identifier.createVariable('user'),
|
|
74
|
+
* Identifier.createType('User')
|
|
75
|
+
* ]); // "user, User"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
3
78
|
require("../_dnt.polyfills.js");
|
|
@@ -1,8 +1,201 @@
|
|
|
1
1
|
import type { ResultsItem, ResultType } from '../types/Results.js';
|
|
2
|
+
/**
|
|
3
|
+
* Manages and organizes generation results with intelligent prioritization.
|
|
4
|
+
*
|
|
5
|
+
* `ResultsLog` tracks the outcomes of code generation operations, maintaining
|
|
6
|
+
* a hierarchical structure of results organized by stack trail paths. It implements
|
|
7
|
+
* intelligent result prioritization, ensuring that more severe results (errors)
|
|
8
|
+
* take precedence over less severe ones (success, warnings) when multiple results
|
|
9
|
+
* exist for the same path.
|
|
10
|
+
*
|
|
11
|
+
* The class is designed to work with the SKMTC tracing system, using stack trail
|
|
12
|
+
* identifiers to organize results in a meaningful hierarchical structure that
|
|
13
|
+
* reflects the execution flow of the generation process.
|
|
14
|
+
*
|
|
15
|
+
* ## Key Features
|
|
16
|
+
*
|
|
17
|
+
* - **Result Prioritization**: Automatically prioritizes more severe results
|
|
18
|
+
* - **Hierarchical Organization**: Organizes results by stack trail paths
|
|
19
|
+
* - **Tree Structure**: Converts flat result logs into nested tree structures
|
|
20
|
+
* - **Duplicate Handling**: Prevents less severe results from overwriting more severe ones
|
|
21
|
+
*
|
|
22
|
+
* @example Basic usage
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { ResultsLog } from '@skmtc/core';
|
|
25
|
+
*
|
|
26
|
+
* const resultsLog = new ResultsLog();
|
|
27
|
+
*
|
|
28
|
+
* // Capture results from different parts of generation
|
|
29
|
+
* resultsLog.capture('models:User', 'success');
|
|
30
|
+
* resultsLog.capture('models:Product', 'error');
|
|
31
|
+
* resultsLog.capture('types:Status', 'success');
|
|
32
|
+
*
|
|
33
|
+
* // Convert to hierarchical structure
|
|
34
|
+
* const tree = resultsLog.toTree();
|
|
35
|
+
* console.log(tree);
|
|
36
|
+
* // {
|
|
37
|
+
* // models: {
|
|
38
|
+
* // User: 'success',
|
|
39
|
+
* // Product: 'error'
|
|
40
|
+
* // },
|
|
41
|
+
* // types: {
|
|
42
|
+
* // Status: 'success'
|
|
43
|
+
* // }
|
|
44
|
+
* // }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Result prioritization
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const resultsLog = new ResultsLog();
|
|
50
|
+
*
|
|
51
|
+
* // First capture a success
|
|
52
|
+
* resultsLog.capture('api:createUser', 'success');
|
|
53
|
+
*
|
|
54
|
+
* // Later encounter an error at the same path
|
|
55
|
+
* resultsLog.capture('api:createUser', 'error');
|
|
56
|
+
*
|
|
57
|
+
* // Error takes precedence
|
|
58
|
+
* const tree = resultsLog.toTree();
|
|
59
|
+
* console.log(tree.api.createUser); // 'error'
|
|
60
|
+
*
|
|
61
|
+
* // But success won't overwrite error
|
|
62
|
+
* resultsLog.capture('api:createUser', 'success');
|
|
63
|
+
* console.log(resultsLog.toTree().api.createUser); // Still 'error'
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Complex nested paths
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const resultsLog = new ResultsLog();
|
|
69
|
+
*
|
|
70
|
+
* resultsLog.capture('generation:models:User:properties:name', 'success');
|
|
71
|
+
* resultsLog.capture('generation:models:User:properties:email', 'warning');
|
|
72
|
+
* resultsLog.capture('generation:models:Product:validation', 'error');
|
|
73
|
+
* resultsLog.capture('generation:operations:createUser', 'success');
|
|
74
|
+
*
|
|
75
|
+
* const tree = resultsLog.toTree();
|
|
76
|
+
* console.log(tree);
|
|
77
|
+
* // {
|
|
78
|
+
* // generation: {
|
|
79
|
+
* // models: {
|
|
80
|
+
* // User: {
|
|
81
|
+
* // properties: {
|
|
82
|
+
* // name: 'success',
|
|
83
|
+
* // email: 'warning'
|
|
84
|
+
* // }
|
|
85
|
+
* // },
|
|
86
|
+
* // Product: {
|
|
87
|
+
* // validation: 'error'
|
|
88
|
+
* // }
|
|
89
|
+
* // },
|
|
90
|
+
* // operations: {
|
|
91
|
+
* // createUser: 'success'
|
|
92
|
+
* // }
|
|
93
|
+
* // }
|
|
94
|
+
* // }
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Integration with tracing
|
|
98
|
+
* ```typescript
|
|
99
|
+
* class TrackedGenerator {
|
|
100
|
+
* private resultsLog = new ResultsLog();
|
|
101
|
+
*
|
|
102
|
+
* generateModel(name: string, schema: OasSchema) {
|
|
103
|
+
* const stackPath = `models:${name}`;
|
|
104
|
+
*
|
|
105
|
+
* try {
|
|
106
|
+
* const model = this.processSchema(schema);
|
|
107
|
+
* this.resultsLog.capture(stackPath, 'success');
|
|
108
|
+
* return model;
|
|
109
|
+
* } catch (error) {
|
|
110
|
+
* this.resultsLog.capture(stackPath, 'error');
|
|
111
|
+
* throw error;
|
|
112
|
+
* }
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* generateOperation(operationId: string, operation: OasOperation) {
|
|
116
|
+
* const stackPath = `operations:${operationId}`;
|
|
117
|
+
*
|
|
118
|
+
* if (!this.supportsOperation(operation)) {
|
|
119
|
+
* this.resultsLog.capture(stackPath, 'notSupported');
|
|
120
|
+
* return null;
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* const result = this.processOperation(operation);
|
|
124
|
+
* this.resultsLog.capture(stackPath, 'success');
|
|
125
|
+
* return result;
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* getResults(): ResultsItem {
|
|
129
|
+
* return this.resultsLog.toTree();
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
2
134
|
export declare class ResultsLog {
|
|
3
135
|
#private;
|
|
136
|
+
/**
|
|
137
|
+
* Creates a new ResultsLog instance.
|
|
138
|
+
*
|
|
139
|
+
* Initializes an empty results tracking system ready to capture
|
|
140
|
+
* generation outcomes from various parts of the pipeline.
|
|
141
|
+
*/
|
|
4
142
|
constructor();
|
|
143
|
+
/**
|
|
144
|
+
* Captures a generation result for a specific stack trail path.
|
|
145
|
+
*
|
|
146
|
+
* This method records the outcome of a generation operation, using intelligent
|
|
147
|
+
* prioritization to ensure that more severe results take precedence over less
|
|
148
|
+
* severe ones. For example, an error result will not be overwritten by a
|
|
149
|
+
* success result, but a success can be overwritten by an error.
|
|
150
|
+
*
|
|
151
|
+
* @param stackTrail - Colon-separated path identifying the operation location
|
|
152
|
+
* @param result - The result type to capture (error, warning, success, etc.)
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const resultsLog = new ResultsLog();
|
|
157
|
+
*
|
|
158
|
+
* // Capture various results
|
|
159
|
+
* resultsLog.capture('models:User:properties:email', 'success');
|
|
160
|
+
* resultsLog.capture('models:User:validation', 'warning');
|
|
161
|
+
* resultsLog.capture('operations:createUser', 'error');
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
5
164
|
capture(stackTrail: string, result: ResultType): void;
|
|
165
|
+
/**
|
|
166
|
+
* Converts the flat results structure into a hierarchical tree.
|
|
167
|
+
*
|
|
168
|
+
* This method transforms the internal flat storage (using colon-separated paths)
|
|
169
|
+
* into a nested object structure that reflects the hierarchy of generation
|
|
170
|
+
* operations. This makes it easier to understand and process results in
|
|
171
|
+
* a structured way.
|
|
172
|
+
*
|
|
173
|
+
* @returns Nested object structure representing the results hierarchy
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const resultsLog = new ResultsLog();
|
|
178
|
+
* resultsLog.capture('api:models:User', 'success');
|
|
179
|
+
* resultsLog.capture('api:operations:getUser', 'error');
|
|
180
|
+
* resultsLog.capture('types:Status', 'success');
|
|
181
|
+
*
|
|
182
|
+
* const tree = resultsLog.toTree();
|
|
183
|
+
* console.log(tree);
|
|
184
|
+
* // {
|
|
185
|
+
* // api: {
|
|
186
|
+
* // models: {
|
|
187
|
+
* // User: 'success'
|
|
188
|
+
* // },
|
|
189
|
+
* // operations: {
|
|
190
|
+
* // getUser: 'error'
|
|
191
|
+
* // }
|
|
192
|
+
* // },
|
|
193
|
+
* // types: {
|
|
194
|
+
* // Status: 'success'
|
|
195
|
+
* // }
|
|
196
|
+
* // }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
6
199
|
toTree(): ResultsItem;
|
|
7
200
|
}
|
|
8
201
|
//# sourceMappingURL=ResultsLog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResultsLog.d.ts","sourceRoot":"","sources":["../../src/helpers/ResultsLog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAElE,qBAAa,UAAU
|
|
1
|
+
{"version":3,"file":"ResultsLog.d.ts","sourceRoot":"","sources":["../../src/helpers/ResultsLog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmIG;AACH,qBAAa,UAAU;;IAGrB;;;;;OAKG;;IAKH;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IA8B9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,MAAM,IAAI,WAAW;CAWtB"}
|
|
@@ -14,17 +14,210 @@ var _ResultsLog_instances, _ResultsLog_results, _ResultsLog_incomingResultIsWors
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ResultsLog = void 0;
|
|
16
16
|
const lodash_es_1 = require("lodash-es");
|
|
17
|
+
/**
|
|
18
|
+
* Manages and organizes generation results with intelligent prioritization.
|
|
19
|
+
*
|
|
20
|
+
* `ResultsLog` tracks the outcomes of code generation operations, maintaining
|
|
21
|
+
* a hierarchical structure of results organized by stack trail paths. It implements
|
|
22
|
+
* intelligent result prioritization, ensuring that more severe results (errors)
|
|
23
|
+
* take precedence over less severe ones (success, warnings) when multiple results
|
|
24
|
+
* exist for the same path.
|
|
25
|
+
*
|
|
26
|
+
* The class is designed to work with the SKMTC tracing system, using stack trail
|
|
27
|
+
* identifiers to organize results in a meaningful hierarchical structure that
|
|
28
|
+
* reflects the execution flow of the generation process.
|
|
29
|
+
*
|
|
30
|
+
* ## Key Features
|
|
31
|
+
*
|
|
32
|
+
* - **Result Prioritization**: Automatically prioritizes more severe results
|
|
33
|
+
* - **Hierarchical Organization**: Organizes results by stack trail paths
|
|
34
|
+
* - **Tree Structure**: Converts flat result logs into nested tree structures
|
|
35
|
+
* - **Duplicate Handling**: Prevents less severe results from overwriting more severe ones
|
|
36
|
+
*
|
|
37
|
+
* @example Basic usage
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { ResultsLog } from '@skmtc/core';
|
|
40
|
+
*
|
|
41
|
+
* const resultsLog = new ResultsLog();
|
|
42
|
+
*
|
|
43
|
+
* // Capture results from different parts of generation
|
|
44
|
+
* resultsLog.capture('models:User', 'success');
|
|
45
|
+
* resultsLog.capture('models:Product', 'error');
|
|
46
|
+
* resultsLog.capture('types:Status', 'success');
|
|
47
|
+
*
|
|
48
|
+
* // Convert to hierarchical structure
|
|
49
|
+
* const tree = resultsLog.toTree();
|
|
50
|
+
* console.log(tree);
|
|
51
|
+
* // {
|
|
52
|
+
* // models: {
|
|
53
|
+
* // User: 'success',
|
|
54
|
+
* // Product: 'error'
|
|
55
|
+
* // },
|
|
56
|
+
* // types: {
|
|
57
|
+
* // Status: 'success'
|
|
58
|
+
* // }
|
|
59
|
+
* // }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Result prioritization
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const resultsLog = new ResultsLog();
|
|
65
|
+
*
|
|
66
|
+
* // First capture a success
|
|
67
|
+
* resultsLog.capture('api:createUser', 'success');
|
|
68
|
+
*
|
|
69
|
+
* // Later encounter an error at the same path
|
|
70
|
+
* resultsLog.capture('api:createUser', 'error');
|
|
71
|
+
*
|
|
72
|
+
* // Error takes precedence
|
|
73
|
+
* const tree = resultsLog.toTree();
|
|
74
|
+
* console.log(tree.api.createUser); // 'error'
|
|
75
|
+
*
|
|
76
|
+
* // But success won't overwrite error
|
|
77
|
+
* resultsLog.capture('api:createUser', 'success');
|
|
78
|
+
* console.log(resultsLog.toTree().api.createUser); // Still 'error'
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Complex nested paths
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const resultsLog = new ResultsLog();
|
|
84
|
+
*
|
|
85
|
+
* resultsLog.capture('generation:models:User:properties:name', 'success');
|
|
86
|
+
* resultsLog.capture('generation:models:User:properties:email', 'warning');
|
|
87
|
+
* resultsLog.capture('generation:models:Product:validation', 'error');
|
|
88
|
+
* resultsLog.capture('generation:operations:createUser', 'success');
|
|
89
|
+
*
|
|
90
|
+
* const tree = resultsLog.toTree();
|
|
91
|
+
* console.log(tree);
|
|
92
|
+
* // {
|
|
93
|
+
* // generation: {
|
|
94
|
+
* // models: {
|
|
95
|
+
* // User: {
|
|
96
|
+
* // properties: {
|
|
97
|
+
* // name: 'success',
|
|
98
|
+
* // email: 'warning'
|
|
99
|
+
* // }
|
|
100
|
+
* // },
|
|
101
|
+
* // Product: {
|
|
102
|
+
* // validation: 'error'
|
|
103
|
+
* // }
|
|
104
|
+
* // },
|
|
105
|
+
* // operations: {
|
|
106
|
+
* // createUser: 'success'
|
|
107
|
+
* // }
|
|
108
|
+
* // }
|
|
109
|
+
* // }
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Integration with tracing
|
|
113
|
+
* ```typescript
|
|
114
|
+
* class TrackedGenerator {
|
|
115
|
+
* private resultsLog = new ResultsLog();
|
|
116
|
+
*
|
|
117
|
+
* generateModel(name: string, schema: OasSchema) {
|
|
118
|
+
* const stackPath = `models:${name}`;
|
|
119
|
+
*
|
|
120
|
+
* try {
|
|
121
|
+
* const model = this.processSchema(schema);
|
|
122
|
+
* this.resultsLog.capture(stackPath, 'success');
|
|
123
|
+
* return model;
|
|
124
|
+
* } catch (error) {
|
|
125
|
+
* this.resultsLog.capture(stackPath, 'error');
|
|
126
|
+
* throw error;
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* generateOperation(operationId: string, operation: OasOperation) {
|
|
131
|
+
* const stackPath = `operations:${operationId}`;
|
|
132
|
+
*
|
|
133
|
+
* if (!this.supportsOperation(operation)) {
|
|
134
|
+
* this.resultsLog.capture(stackPath, 'notSupported');
|
|
135
|
+
* return null;
|
|
136
|
+
* }
|
|
137
|
+
*
|
|
138
|
+
* const result = this.processOperation(operation);
|
|
139
|
+
* this.resultsLog.capture(stackPath, 'success');
|
|
140
|
+
* return result;
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* getResults(): ResultsItem {
|
|
144
|
+
* return this.resultsLog.toTree();
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
17
149
|
class ResultsLog {
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new ResultsLog instance.
|
|
152
|
+
*
|
|
153
|
+
* Initializes an empty results tracking system ready to capture
|
|
154
|
+
* generation outcomes from various parts of the pipeline.
|
|
155
|
+
*/
|
|
18
156
|
constructor() {
|
|
19
157
|
_ResultsLog_instances.add(this);
|
|
20
158
|
_ResultsLog_results.set(this, void 0);
|
|
21
159
|
__classPrivateFieldSet(this, _ResultsLog_results, {}, "f");
|
|
22
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Captures a generation result for a specific stack trail path.
|
|
163
|
+
*
|
|
164
|
+
* This method records the outcome of a generation operation, using intelligent
|
|
165
|
+
* prioritization to ensure that more severe results take precedence over less
|
|
166
|
+
* severe ones. For example, an error result will not be overwritten by a
|
|
167
|
+
* success result, but a success can be overwritten by an error.
|
|
168
|
+
*
|
|
169
|
+
* @param stackTrail - Colon-separated path identifying the operation location
|
|
170
|
+
* @param result - The result type to capture (error, warning, success, etc.)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const resultsLog = new ResultsLog();
|
|
175
|
+
*
|
|
176
|
+
* // Capture various results
|
|
177
|
+
* resultsLog.capture('models:User:properties:email', 'success');
|
|
178
|
+
* resultsLog.capture('models:User:validation', 'warning');
|
|
179
|
+
* resultsLog.capture('operations:createUser', 'error');
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
23
182
|
capture(stackTrail, result) {
|
|
24
183
|
if (__classPrivateFieldGet(this, _ResultsLog_instances, "m", _ResultsLog_incomingResultIsWorse).call(this, __classPrivateFieldGet(this, _ResultsLog_results, "f")[stackTrail], result)) {
|
|
25
184
|
__classPrivateFieldGet(this, _ResultsLog_results, "f")[stackTrail] = result;
|
|
26
185
|
}
|
|
27
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Converts the flat results structure into a hierarchical tree.
|
|
189
|
+
*
|
|
190
|
+
* This method transforms the internal flat storage (using colon-separated paths)
|
|
191
|
+
* into a nested object structure that reflects the hierarchy of generation
|
|
192
|
+
* operations. This makes it easier to understand and process results in
|
|
193
|
+
* a structured way.
|
|
194
|
+
*
|
|
195
|
+
* @returns Nested object structure representing the results hierarchy
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const resultsLog = new ResultsLog();
|
|
200
|
+
* resultsLog.capture('api:models:User', 'success');
|
|
201
|
+
* resultsLog.capture('api:operations:getUser', 'error');
|
|
202
|
+
* resultsLog.capture('types:Status', 'success');
|
|
203
|
+
*
|
|
204
|
+
* const tree = resultsLog.toTree();
|
|
205
|
+
* console.log(tree);
|
|
206
|
+
* // {
|
|
207
|
+
* // api: {
|
|
208
|
+
* // models: {
|
|
209
|
+
* // User: 'success'
|
|
210
|
+
* // },
|
|
211
|
+
* // operations: {
|
|
212
|
+
* // getUser: 'error'
|
|
213
|
+
* // }
|
|
214
|
+
* // },
|
|
215
|
+
* // types: {
|
|
216
|
+
* // Status: 'success'
|
|
217
|
+
* // }
|
|
218
|
+
* // }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
28
221
|
toTree() {
|
|
29
222
|
const tree = {};
|
|
30
223
|
Object.entries(__classPrivateFieldGet(this, _ResultsLog_results, "f")).forEach(([key, value]) => {
|
|
@@ -41,6 +234,26 @@ _ResultsLog_results = new WeakMap(), _ResultsLog_instances = new WeakSet(), _Res
|
|
|
41
234
|
}
|
|
42
235
|
return resultRankings[current] < resultRankings[incoming];
|
|
43
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* Priority rankings for different result types.
|
|
239
|
+
*
|
|
240
|
+
* This mapping defines the severity hierarchy used by the ResultsLog to determine
|
|
241
|
+
* which results should take precedence when multiple results are captured for the
|
|
242
|
+
* same path. Higher numbers indicate higher severity/priority.
|
|
243
|
+
*
|
|
244
|
+
* The ranking system ensures that critical issues (errors) are never masked by
|
|
245
|
+
* less important results (success), while still allowing for proper escalation
|
|
246
|
+
* when more severe conditions are encountered.
|
|
247
|
+
*
|
|
248
|
+
* @example Ranking hierarchy (high to low priority)
|
|
249
|
+
* ```
|
|
250
|
+
* error (50) - Critical failures that prevent generation
|
|
251
|
+
* warning (40) - Issues that allow generation but need attention
|
|
252
|
+
* success (30) - Normal successful completion
|
|
253
|
+
* skipped (20) - Operations that were intentionally bypassed
|
|
254
|
+
* notSupported (10) - Features not yet implemented
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
44
257
|
const resultRankings = {
|
|
45
258
|
error: 50,
|
|
46
259
|
warning: 40,
|
|
@@ -1,10 +1,160 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
2
|
import type { OasRef } from '../oas/ref/Ref.js';
|
|
3
3
|
import type { OasSchema } from '../oas/schema/Schema.js';
|
|
4
|
+
/**
|
|
5
|
+
* Arguments for collating examples from OpenAPI schemas.
|
|
6
|
+
*/
|
|
4
7
|
type CollatedExampleArgs = {
|
|
8
|
+
/** The OpenAPI schema or reference to extract examples from */
|
|
5
9
|
objectSchema: OasSchema | OasRef<'schema'> | undefined;
|
|
10
|
+
/** Current recursion depth (used to prevent infinite loops) */
|
|
6
11
|
depth: number;
|
|
7
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Recursively collates and builds example values from OpenAPI schemas.
|
|
15
|
+
*
|
|
16
|
+
* This function traverses OpenAPI schema structures and generates comprehensive
|
|
17
|
+
* example values based on the schema definitions and any explicit examples provided.
|
|
18
|
+
* It handles complex nested structures including objects, arrays, unions, and
|
|
19
|
+
* references while preventing infinite recursion through depth limiting.
|
|
20
|
+
*
|
|
21
|
+
* The function prioritizes explicit examples when available and falls back to
|
|
22
|
+
* generating examples from nested schemas. It's particularly useful for creating
|
|
23
|
+
* realistic test data, API documentation examples, and mock responses.
|
|
24
|
+
*
|
|
25
|
+
* @param args - Configuration for example collation
|
|
26
|
+
* @param args.objectSchema - The schema to extract examples from
|
|
27
|
+
* @param args.depth - Current recursion depth (prevents infinite loops)
|
|
28
|
+
* @returns Collated example value matching the schema structure, or undefined if no examples
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
|
|
31
|
+
*
|
|
32
|
+
* @example Basic schema examples
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { collateExamples } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* // String schema with example
|
|
37
|
+
* const stringSchema = new OasString({ example: 'john.doe@example.com' });
|
|
38
|
+
* const example = collateExamples({ objectSchema: stringSchema, depth: 0 });
|
|
39
|
+
* console.log(example); // 'john.doe@example.com'
|
|
40
|
+
*
|
|
41
|
+
* // Number schema with example
|
|
42
|
+
* const numberSchema = new OasNumber({ example: 42 });
|
|
43
|
+
* const numExample = collateExamples({ objectSchema: numberSchema, depth: 0 });
|
|
44
|
+
* console.log(numExample); // 42
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Object schema examples
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Object schema with nested properties
|
|
50
|
+
* const userSchema = new OasObject({
|
|
51
|
+
* properties: {
|
|
52
|
+
* id: new OasInteger({ example: 123 }),
|
|
53
|
+
* name: new OasString({ example: 'John Doe' }),
|
|
54
|
+
* email: new OasString({ example: 'john@example.com' }),
|
|
55
|
+
* age: new OasInteger({ example: 30 })
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const userExample = collateExamples({ objectSchema: userSchema, depth: 0 });
|
|
60
|
+
* console.log(userExample);
|
|
61
|
+
* // {
|
|
62
|
+
* // id: 123,
|
|
63
|
+
* // name: 'John Doe',
|
|
64
|
+
* // email: 'john@example.com',
|
|
65
|
+
* // age: 30
|
|
66
|
+
* // }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Array schema examples
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Array of objects
|
|
72
|
+
* const usersArraySchema = new OasArray({
|
|
73
|
+
* items: new OasObject({
|
|
74
|
+
* properties: {
|
|
75
|
+
* id: new OasInteger({ example: 1 }),
|
|
76
|
+
* name: new OasString({ example: 'Jane Smith' })
|
|
77
|
+
* }
|
|
78
|
+
* })
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* const arrayExample = collateExamples({ objectSchema: usersArraySchema, depth: 0 });
|
|
82
|
+
* console.log(arrayExample);
|
|
83
|
+
* // [
|
|
84
|
+
* // {
|
|
85
|
+
* // id: 1,
|
|
86
|
+
* // name: 'Jane Smith'
|
|
87
|
+
* // }
|
|
88
|
+
* // ]
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Union schema examples
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Union of string and number
|
|
94
|
+
* const unionSchema = new OasUnion({
|
|
95
|
+
* members: [
|
|
96
|
+
* new OasString({ example: 'text-value' }),
|
|
97
|
+
* new OasNumber({ example: 99 })
|
|
98
|
+
* ]
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* const unionExample = collateExamples({ objectSchema: unionSchema, depth: 0 });
|
|
102
|
+
* console.log(unionExample); // 'text-value' (first member with example)
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @example Reference resolution
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Schema with reference to another schema
|
|
108
|
+
* const addressRef = new OasRef({
|
|
109
|
+
* $ref: '#/components/schemas/Address',
|
|
110
|
+
* resolve: () => new OasObject({
|
|
111
|
+
* properties: {
|
|
112
|
+
* street: new OasString({ example: '123 Main St' }),
|
|
113
|
+
* city: new OasString({ example: 'Springfield' })
|
|
114
|
+
* }
|
|
115
|
+
* })
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* const refExample = collateExamples({ objectSchema: addressRef, depth: 0 });
|
|
119
|
+
* console.log(refExample);
|
|
120
|
+
* // {
|
|
121
|
+
* // street: '123 Main St',
|
|
122
|
+
* // city: 'Springfield'
|
|
123
|
+
* // }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example Depth limiting and error handling
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Deep nesting detection
|
|
129
|
+
* try {
|
|
130
|
+
* const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
|
|
131
|
+
* } catch (error) {
|
|
132
|
+
* console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* // Handling missing schemas
|
|
136
|
+
* const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
|
|
137
|
+
* console.log(emptyExample); // undefined
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Using in API documentation generation
|
|
141
|
+
* ```typescript
|
|
142
|
+
* class ApiDocGenerator {
|
|
143
|
+
* generateExampleResponse(responseSchema: OasSchema) {
|
|
144
|
+
* const example = collateExamples({ objectSchema: responseSchema, depth: 0 });
|
|
145
|
+
*
|
|
146
|
+
* if (example) {
|
|
147
|
+
* return {
|
|
148
|
+
* description: 'Example response',
|
|
149
|
+
* value: example
|
|
150
|
+
* };
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* return { description: 'No example available' };
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
8
158
|
export declare const collateExamples: ({ objectSchema, depth }: CollatedExampleArgs) => unknown;
|
|
9
159
|
export {};
|
|
10
160
|
//# sourceMappingURL=collateExamples.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,KAAK,mBAAmB,GAAG;IACzB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}
|
|
1
|
+
{"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD;;GAEG;AACH,KAAK,mBAAmB,GAAG;IACzB,+DAA+D;IAC/D,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgJG;AACH,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}
|