@skmtc/core 0.0.793 → 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/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/tracer.d.ts +124 -0
- package/esm/helpers/tracer.d.ts.map +1 -1
- package/esm/helpers/tracer.js +124 -0
- 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/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/package.json +1 -1
- 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/tracer.d.ts +124 -0
- package/script/helpers/tracer.d.ts.map +1 -1
- package/script/helpers/tracer.js +124 -0
- 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/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
|
@@ -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,4 +1,128 @@
|
|
|
1
1
|
import type { Logger } from '../deps/jsr.io/@std/log/0.224.14/logger.js';
|
|
2
2
|
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* Executes a function with distributed tracing support and stack trail management.
|
|
5
|
+
*
|
|
6
|
+
* This utility function provides distributed tracing capabilities for the SKMTC
|
|
7
|
+
* generation pipeline. It manages stack trail tokens that help track execution
|
|
8
|
+
* context across complex nested operations, making debugging and performance
|
|
9
|
+
* analysis much easier.
|
|
10
|
+
*
|
|
11
|
+
* The tracer ensures proper cleanup of stack trail tokens even if the wrapped
|
|
12
|
+
* function throws an error, maintaining the integrity of the tracing system.
|
|
13
|
+
* This is essential for accurate debugging and performance monitoring in
|
|
14
|
+
* complex code generation scenarios.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The return type of the traced function
|
|
17
|
+
* @param stackTrail - The stack trail instance for tracking execution context
|
|
18
|
+
* @param token - Token(s) to identify this execution step in traces
|
|
19
|
+
* @param fn - The function to execute with tracing
|
|
20
|
+
* @param log - Logger instance for error reporting
|
|
21
|
+
* @returns The result of the wrapped function execution
|
|
22
|
+
*
|
|
23
|
+
* @throws Re-throws any error from the wrapped function after cleanup
|
|
24
|
+
*
|
|
25
|
+
* @example Basic tracing usage
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { tracer } from '@skmtc/core';
|
|
28
|
+
*
|
|
29
|
+
* class ModelGenerator {
|
|
30
|
+
* generateModel(stackTrail: StackTrail, logger: Logger) {
|
|
31
|
+
* return tracer(stackTrail, 'generate-model', () => {
|
|
32
|
+
* // Complex model generation logic here
|
|
33
|
+
* return this.createModelDefinition();
|
|
34
|
+
* }, logger);
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Nested tracing
|
|
40
|
+
* ```typescript
|
|
41
|
+
* class ComplexProcessor {
|
|
42
|
+
* processSchema(stackTrail: StackTrail, logger: Logger) {
|
|
43
|
+
* return tracer(stackTrail, 'process-schema', () => {
|
|
44
|
+
* const parsed = tracer(stackTrail, 'parse', () => {
|
|
45
|
+
* return this.parseSchema();
|
|
46
|
+
* }, logger);
|
|
47
|
+
*
|
|
48
|
+
* const validated = tracer(stackTrail, 'validate', () => {
|
|
49
|
+
* return this.validateSchema(parsed);
|
|
50
|
+
* }, logger);
|
|
51
|
+
*
|
|
52
|
+
* return tracer(stackTrail, 'transform', () => {
|
|
53
|
+
* return this.transformSchema(validated);
|
|
54
|
+
* }, logger);
|
|
55
|
+
* }, logger);
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Stack trail will show: ['process-schema', 'parse'] -> ['process-schema', 'validate'] -> ['process-schema', 'transform']
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Multiple token tracing
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const result = tracer(
|
|
65
|
+
* stackTrail,
|
|
66
|
+
* ['file-generation', 'models.ts'], // Multiple tokens for detailed context
|
|
67
|
+
* () => {
|
|
68
|
+
* return generateModelsFile();
|
|
69
|
+
* },
|
|
70
|
+
* logger
|
|
71
|
+
* );
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example Error handling with tracing
|
|
75
|
+
* ```typescript
|
|
76
|
+
* class SafeGenerator {
|
|
77
|
+
* generateWithTracing(stackTrail: StackTrail, logger: Logger) {
|
|
78
|
+
* try {
|
|
79
|
+
* return tracer(stackTrail, 'risky-operation', () => {
|
|
80
|
+
* // This might throw an error
|
|
81
|
+
* return this.complexGeneration();
|
|
82
|
+
* }, logger);
|
|
83
|
+
* } catch (error) {
|
|
84
|
+
* // Stack trail is automatically cleaned up
|
|
85
|
+
* logger.error(`Generation failed: ${error.message}`);
|
|
86
|
+
* return this.fallbackGeneration();
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example Performance monitoring
|
|
93
|
+
* ```typescript
|
|
94
|
+
* class PerformanceAwareGenerator {
|
|
95
|
+
* timedGeneration(stackTrail: StackTrail, logger: Logger) {
|
|
96
|
+
* const startTime = Date.now();
|
|
97
|
+
*
|
|
98
|
+
* const result = tracer(stackTrail, 'timed-generation', () => {
|
|
99
|
+
* return this.heavyComputation();
|
|
100
|
+
* }, logger);
|
|
101
|
+
*
|
|
102
|
+
* const duration = Date.now() - startTime;
|
|
103
|
+
* logger.info(`Generation completed in ${duration}ms`);
|
|
104
|
+
*
|
|
105
|
+
* return result;
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example Integration with context classes
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // Typically used within context classes like this:
|
|
113
|
+
* class GenerateContext {
|
|
114
|
+
* trace<T>(token: string | string[], fn: () => T): T {
|
|
115
|
+
* return tracer(this.stackTrail, token, fn, this.logger);
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* processModel(schema: OasSchema) {
|
|
119
|
+
* return this.trace(['model', schema.type], () => {
|
|
120
|
+
* // Model processing logic
|
|
121
|
+
* return this.createModel(schema);
|
|
122
|
+
* });
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
3
127
|
export declare const tracer: <T>(stackTrail: StackTrail, token: string | string[], fn: () => T, log: Logger) => T;
|
|
4
128
|
//# sourceMappingURL=tracer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,eAAO,MAAM,MAAM,GAAI,CAAC,EACtB,YAAY,UAAU,EACtB,OAAO,MAAM,GAAG,MAAM,EAAE,EACxB,IAAI,MAAM,CAAC,EACX,KAAK,MAAM,MAgBZ,CAAA"}
|
|
1
|
+
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/helpers/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2HG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,EACtB,YAAY,UAAU,EACtB,OAAO,MAAM,GAAG,MAAM,EAAE,EACxB,IAAI,MAAM,CAAC,EACX,KAAK,MAAM,MAgBZ,CAAA"}
|