@skmtc/core 0.0.795 → 0.0.796
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/context/ResultsHandler.d.ts +152 -0
- package/esm/context/ResultsHandler.d.ts.map +1 -1
- package/esm/context/ResultsHandler.js +166 -1
- package/package.json +1 -1
- package/script/context/ResultsHandler.d.ts +152 -0
- package/script/context/ResultsHandler.d.ts.map +1 -1
- package/script/context/ResultsHandler.js +166 -1
|
@@ -3,17 +3,169 @@ import type { LogRecord } from '../deps/jsr.io/@std/log/0.224.14/logger.js';
|
|
|
3
3
|
import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
|
|
4
4
|
import type { BaseHandlerOptions } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
|
|
5
5
|
import type { CoreContext } from './CoreContext.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the {@link ResultsHandler}.
|
|
8
|
+
*/
|
|
6
9
|
export interface ResultsHandlerOptions extends BaseHandlerOptions {
|
|
10
|
+
/** The CoreContext instance to capture results to */
|
|
7
11
|
context: CoreContext;
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom log handler that captures warning and error results for SKMTC processing.
|
|
15
|
+
*
|
|
16
|
+
* The `ResultsHandler` extends Deno's standard library BaseHandler to provide
|
|
17
|
+
* specialized logging behavior for the SKMTC pipeline. It integrates with the
|
|
18
|
+
* CoreContext to capture warnings and errors as structured results that can be
|
|
19
|
+
* analyzed and reported after processing completes.
|
|
20
|
+
*
|
|
21
|
+
* This handler ensures that important processing issues are captured and stored
|
|
22
|
+
* in the context's results system rather than just being logged to the console.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Result Capture**: Automatically captures WARN and ERROR logs as results
|
|
27
|
+
* - **Immediate Flushing**: Critical errors trigger immediate flush
|
|
28
|
+
* - **Lifecycle Management**: Proper setup and cleanup with event handlers
|
|
29
|
+
* - **Context Integration**: Seamlessly integrates with CoreContext results system
|
|
30
|
+
*
|
|
31
|
+
* @example Setting up the handler
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { getLogger } from '@std/log';
|
|
34
|
+
* import { ResultsHandler, CoreContext } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* const context = new CoreContext({
|
|
37
|
+
* // ... context options
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const handler = new ResultsHandler('WARN', {
|
|
41
|
+
* context: context,
|
|
42
|
+
* formatter: '[{levelName}] {msg}'
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const logger = getLogger();
|
|
46
|
+
* logger.addHandler(handler);
|
|
47
|
+
*
|
|
48
|
+
* // Now warnings and errors will be captured as results
|
|
49
|
+
* logger.warning('Schema validation issue detected');
|
|
50
|
+
* logger.error('Failed to process operation');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Integration in pipeline
|
|
54
|
+
* ```typescript
|
|
55
|
+
* class ProcessingPipeline {
|
|
56
|
+
* async process(document: OasDocument) {
|
|
57
|
+
* const context = new CoreContext(options);
|
|
58
|
+
*
|
|
59
|
+
* // Set up results handler
|
|
60
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
61
|
+
* const logger = getLogger();
|
|
62
|
+
* logger.addHandler(handler);
|
|
63
|
+
*
|
|
64
|
+
* try {
|
|
65
|
+
* const result = await this.processDocument(document, context);
|
|
66
|
+
*
|
|
67
|
+
* // Check captured results
|
|
68
|
+
* if (context.results.hasWarnings()) {
|
|
69
|
+
* console.log('Processing completed with warnings');
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* return result;
|
|
73
|
+
* } finally {
|
|
74
|
+
* handler.destroy();
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
9
80
|
export declare class ResultsHandler extends BaseHandler {
|
|
10
81
|
#private;
|
|
82
|
+
/** The CoreContext instance for capturing results */
|
|
11
83
|
context: CoreContext;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new ResultsHandler instance.
|
|
86
|
+
*
|
|
87
|
+
* @param levelName - The minimum log level to handle
|
|
88
|
+
* @param options - Handler configuration including CoreContext
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const context = new CoreContext(contextOptions);
|
|
93
|
+
* const handler = new ResultsHandler('WARN', {
|
|
94
|
+
* context,
|
|
95
|
+
* formatter: '[{levelName}] {msg}'
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
12
99
|
constructor(levelName: LevelName, options: ResultsHandlerOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Sets up the handler with event listeners.
|
|
102
|
+
*
|
|
103
|
+
* Registers cleanup callbacks for process termination to ensure
|
|
104
|
+
* proper resource cleanup and result flushing.
|
|
105
|
+
*
|
|
106
|
+
* @override
|
|
107
|
+
*/
|
|
13
108
|
setup(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Handles incoming log records.
|
|
111
|
+
*
|
|
112
|
+
* Processes log records through the base handler and triggers
|
|
113
|
+
* immediate flushing for critical errors above ERROR level.
|
|
114
|
+
*
|
|
115
|
+
* @param logRecord - The log record to handle
|
|
116
|
+
*
|
|
117
|
+
* @override
|
|
118
|
+
*/
|
|
14
119
|
handle(logRecord: LogRecord): void;
|
|
120
|
+
/**
|
|
121
|
+
* Captures log messages as results in the context.
|
|
122
|
+
*
|
|
123
|
+
* Converts log level names to result types and captures them
|
|
124
|
+
* in the associated CoreContext for later analysis.
|
|
125
|
+
*
|
|
126
|
+
* @param levelName - The log level name ('WARN' or 'ERROR')
|
|
127
|
+
*
|
|
128
|
+
* @throws {Error} When an unsupported log level is provided
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // This is called automatically by the logging system
|
|
133
|
+
* handler.log('WARN'); // Captures as 'warning' result
|
|
134
|
+
* handler.log('ERROR'); // Captures as 'error' result
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
15
137
|
log(levelName: string): void;
|
|
138
|
+
/**
|
|
139
|
+
* Flushes any buffered content.
|
|
140
|
+
*
|
|
141
|
+
* This implementation resets the internal buffer. Override
|
|
142
|
+
* this method in subclasses to implement custom flushing behavior.
|
|
143
|
+
*
|
|
144
|
+
* @override
|
|
145
|
+
*/
|
|
16
146
|
flush(): void;
|
|
147
|
+
/**
|
|
148
|
+
* Destroys the handler and cleans up resources.
|
|
149
|
+
*
|
|
150
|
+
* Flushes any remaining content and removes event listeners
|
|
151
|
+
* to prevent memory leaks.
|
|
152
|
+
*
|
|
153
|
+
* @override
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
158
|
+
*
|
|
159
|
+
* try {
|
|
160
|
+
* // Use handler
|
|
161
|
+
* logger.addHandler(handler);
|
|
162
|
+
* await processDocument();
|
|
163
|
+
* } finally {
|
|
164
|
+
* // Always clean up
|
|
165
|
+
* handler.destroy();
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
17
169
|
destroy(): void;
|
|
18
170
|
}
|
|
19
171
|
//# sourceMappingURL=ResultsHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResultsHandler.d.ts","sourceRoot":"","sources":["../../src/context/ResultsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,4CAA4C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,OAAO,EAAE,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"ResultsHandler.d.ts","sourceRoot":"","sources":["../../src/context/ResultsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,4CAA4C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IAOpB;;;;;;;;;;;;;;OAcG;gBACS,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,qBAAqB;IAMhE;;;;;;;OAOG;IACM,KAAK;IAMd;;;;;;;;;OASG;IACM,MAAM,CAAC,SAAS,EAAE,SAAS;IASpC;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM;IAWrB;;;;;;;OAOG;IACH,KAAK;IAWL;;;;;;;;;;;;;;;;;;;;;OAqBG;IACM,OAAO;CAKjB"}
|
|
@@ -7,25 +7,143 @@ var _ResultsHandler_instances, _ResultsHandler_unloadCallback, _ResultsHandler_r
|
|
|
7
7
|
import { LogLevels } from '../deps/jsr.io/@std/log/0.224.14/levels.js';
|
|
8
8
|
import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
|
|
9
9
|
import { match } from 'ts-pattern';
|
|
10
|
+
/**
|
|
11
|
+
* Custom log handler that captures warning and error results for SKMTC processing.
|
|
12
|
+
*
|
|
13
|
+
* The `ResultsHandler` extends Deno's standard library BaseHandler to provide
|
|
14
|
+
* specialized logging behavior for the SKMTC pipeline. It integrates with the
|
|
15
|
+
* CoreContext to capture warnings and errors as structured results that can be
|
|
16
|
+
* analyzed and reported after processing completes.
|
|
17
|
+
*
|
|
18
|
+
* This handler ensures that important processing issues are captured and stored
|
|
19
|
+
* in the context's results system rather than just being logged to the console.
|
|
20
|
+
*
|
|
21
|
+
* ## Key Features
|
|
22
|
+
*
|
|
23
|
+
* - **Result Capture**: Automatically captures WARN and ERROR logs as results
|
|
24
|
+
* - **Immediate Flushing**: Critical errors trigger immediate flush
|
|
25
|
+
* - **Lifecycle Management**: Proper setup and cleanup with event handlers
|
|
26
|
+
* - **Context Integration**: Seamlessly integrates with CoreContext results system
|
|
27
|
+
*
|
|
28
|
+
* @example Setting up the handler
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { getLogger } from '@std/log';
|
|
31
|
+
* import { ResultsHandler, CoreContext } from '@skmtc/core';
|
|
32
|
+
*
|
|
33
|
+
* const context = new CoreContext({
|
|
34
|
+
* // ... context options
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const handler = new ResultsHandler('WARN', {
|
|
38
|
+
* context: context,
|
|
39
|
+
* formatter: '[{levelName}] {msg}'
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* const logger = getLogger();
|
|
43
|
+
* logger.addHandler(handler);
|
|
44
|
+
*
|
|
45
|
+
* // Now warnings and errors will be captured as results
|
|
46
|
+
* logger.warning('Schema validation issue detected');
|
|
47
|
+
* logger.error('Failed to process operation');
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Integration in pipeline
|
|
51
|
+
* ```typescript
|
|
52
|
+
* class ProcessingPipeline {
|
|
53
|
+
* async process(document: OasDocument) {
|
|
54
|
+
* const context = new CoreContext(options);
|
|
55
|
+
*
|
|
56
|
+
* // Set up results handler
|
|
57
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
58
|
+
* const logger = getLogger();
|
|
59
|
+
* logger.addHandler(handler);
|
|
60
|
+
*
|
|
61
|
+
* try {
|
|
62
|
+
* const result = await this.processDocument(document, context);
|
|
63
|
+
*
|
|
64
|
+
* // Check captured results
|
|
65
|
+
* if (context.results.hasWarnings()) {
|
|
66
|
+
* console.log('Processing completed with warnings');
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* return result;
|
|
70
|
+
* } finally {
|
|
71
|
+
* handler.destroy();
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
10
77
|
export class ResultsHandler extends BaseHandler {
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new ResultsHandler instance.
|
|
80
|
+
*
|
|
81
|
+
* @param levelName - The minimum log level to handle
|
|
82
|
+
* @param options - Handler configuration including CoreContext
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const context = new CoreContext(contextOptions);
|
|
87
|
+
* const handler = new ResultsHandler('WARN', {
|
|
88
|
+
* context,
|
|
89
|
+
* formatter: '[{levelName}] {msg}'
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
11
93
|
constructor(levelName, options) {
|
|
12
94
|
super(levelName, options);
|
|
13
95
|
_ResultsHandler_instances.add(this);
|
|
96
|
+
/** The CoreContext instance for capturing results */
|
|
14
97
|
Object.defineProperty(this, "context", {
|
|
15
98
|
enumerable: true,
|
|
16
99
|
configurable: true,
|
|
17
100
|
writable: true,
|
|
18
101
|
value: void 0
|
|
19
102
|
});
|
|
103
|
+
/** Bound callback for cleanup on process unload */
|
|
20
104
|
_ResultsHandler_unloadCallback.set(this, (() => {
|
|
21
105
|
this.destroy();
|
|
22
|
-
}).bind(this)
|
|
106
|
+
}).bind(this)
|
|
107
|
+
/**
|
|
108
|
+
* Creates a new ResultsHandler instance.
|
|
109
|
+
*
|
|
110
|
+
* @param levelName - The minimum log level to handle
|
|
111
|
+
* @param options - Handler configuration including CoreContext
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const context = new CoreContext(contextOptions);
|
|
116
|
+
* const handler = new ResultsHandler('WARN', {
|
|
117
|
+
* context,
|
|
118
|
+
* formatter: '[{levelName}] {msg}'
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
);
|
|
23
123
|
this.context = options.context;
|
|
24
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Sets up the handler with event listeners.
|
|
127
|
+
*
|
|
128
|
+
* Registers cleanup callbacks for process termination to ensure
|
|
129
|
+
* proper resource cleanup and result flushing.
|
|
130
|
+
*
|
|
131
|
+
* @override
|
|
132
|
+
*/
|
|
25
133
|
setup() {
|
|
26
134
|
__classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
|
|
27
135
|
addEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
|
|
28
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Handles incoming log records.
|
|
139
|
+
*
|
|
140
|
+
* Processes log records through the base handler and triggers
|
|
141
|
+
* immediate flushing for critical errors above ERROR level.
|
|
142
|
+
*
|
|
143
|
+
* @param logRecord - The log record to handle
|
|
144
|
+
*
|
|
145
|
+
* @override
|
|
146
|
+
*/
|
|
29
147
|
handle(logRecord) {
|
|
30
148
|
super.handle(logRecord);
|
|
31
149
|
// Immediately flush if log level is higher than ERROR
|
|
@@ -33,6 +151,23 @@ export class ResultsHandler extends BaseHandler {
|
|
|
33
151
|
this.flush();
|
|
34
152
|
}
|
|
35
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Captures log messages as results in the context.
|
|
156
|
+
*
|
|
157
|
+
* Converts log level names to result types and captures them
|
|
158
|
+
* in the associated CoreContext for later analysis.
|
|
159
|
+
*
|
|
160
|
+
* @param levelName - The log level name ('WARN' or 'ERROR')
|
|
161
|
+
*
|
|
162
|
+
* @throws {Error} When an unsupported log level is provided
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // This is called automatically by the logging system
|
|
167
|
+
* handler.log('WARN'); // Captures as 'warning' result
|
|
168
|
+
* handler.log('ERROR'); // Captures as 'error' result
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
36
171
|
log(levelName) {
|
|
37
172
|
this.context.captureCurrentResult(match(levelName)
|
|
38
173
|
.with('WARN', () => 'warning')
|
|
@@ -41,9 +176,39 @@ export class ResultsHandler extends BaseHandler {
|
|
|
41
176
|
throw new Error(`Unexpected log level name: ${levelName}`);
|
|
42
177
|
}));
|
|
43
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Flushes any buffered content.
|
|
181
|
+
*
|
|
182
|
+
* This implementation resets the internal buffer. Override
|
|
183
|
+
* this method in subclasses to implement custom flushing behavior.
|
|
184
|
+
*
|
|
185
|
+
* @override
|
|
186
|
+
*/
|
|
44
187
|
flush() {
|
|
45
188
|
__classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
|
|
46
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Destroys the handler and cleans up resources.
|
|
192
|
+
*
|
|
193
|
+
* Flushes any remaining content and removes event listeners
|
|
194
|
+
* to prevent memory leaks.
|
|
195
|
+
*
|
|
196
|
+
* @override
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
201
|
+
*
|
|
202
|
+
* try {
|
|
203
|
+
* // Use handler
|
|
204
|
+
* logger.addHandler(handler);
|
|
205
|
+
* await processDocument();
|
|
206
|
+
* } finally {
|
|
207
|
+
* // Always clean up
|
|
208
|
+
* handler.destroy();
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
47
212
|
destroy() {
|
|
48
213
|
this.flush();
|
|
49
214
|
removeEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
|
package/package.json
CHANGED
|
@@ -3,17 +3,169 @@ import type { LogRecord } from '../deps/jsr.io/@std/log/0.224.14/logger.js';
|
|
|
3
3
|
import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
|
|
4
4
|
import type { BaseHandlerOptions } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
|
|
5
5
|
import type { CoreContext } from './CoreContext.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the {@link ResultsHandler}.
|
|
8
|
+
*/
|
|
6
9
|
export interface ResultsHandlerOptions extends BaseHandlerOptions {
|
|
10
|
+
/** The CoreContext instance to capture results to */
|
|
7
11
|
context: CoreContext;
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom log handler that captures warning and error results for SKMTC processing.
|
|
15
|
+
*
|
|
16
|
+
* The `ResultsHandler` extends Deno's standard library BaseHandler to provide
|
|
17
|
+
* specialized logging behavior for the SKMTC pipeline. It integrates with the
|
|
18
|
+
* CoreContext to capture warnings and errors as structured results that can be
|
|
19
|
+
* analyzed and reported after processing completes.
|
|
20
|
+
*
|
|
21
|
+
* This handler ensures that important processing issues are captured and stored
|
|
22
|
+
* in the context's results system rather than just being logged to the console.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Result Capture**: Automatically captures WARN and ERROR logs as results
|
|
27
|
+
* - **Immediate Flushing**: Critical errors trigger immediate flush
|
|
28
|
+
* - **Lifecycle Management**: Proper setup and cleanup with event handlers
|
|
29
|
+
* - **Context Integration**: Seamlessly integrates with CoreContext results system
|
|
30
|
+
*
|
|
31
|
+
* @example Setting up the handler
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { getLogger } from '@std/log';
|
|
34
|
+
* import { ResultsHandler, CoreContext } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* const context = new CoreContext({
|
|
37
|
+
* // ... context options
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const handler = new ResultsHandler('WARN', {
|
|
41
|
+
* context: context,
|
|
42
|
+
* formatter: '[{levelName}] {msg}'
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const logger = getLogger();
|
|
46
|
+
* logger.addHandler(handler);
|
|
47
|
+
*
|
|
48
|
+
* // Now warnings and errors will be captured as results
|
|
49
|
+
* logger.warning('Schema validation issue detected');
|
|
50
|
+
* logger.error('Failed to process operation');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Integration in pipeline
|
|
54
|
+
* ```typescript
|
|
55
|
+
* class ProcessingPipeline {
|
|
56
|
+
* async process(document: OasDocument) {
|
|
57
|
+
* const context = new CoreContext(options);
|
|
58
|
+
*
|
|
59
|
+
* // Set up results handler
|
|
60
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
61
|
+
* const logger = getLogger();
|
|
62
|
+
* logger.addHandler(handler);
|
|
63
|
+
*
|
|
64
|
+
* try {
|
|
65
|
+
* const result = await this.processDocument(document, context);
|
|
66
|
+
*
|
|
67
|
+
* // Check captured results
|
|
68
|
+
* if (context.results.hasWarnings()) {
|
|
69
|
+
* console.log('Processing completed with warnings');
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* return result;
|
|
73
|
+
* } finally {
|
|
74
|
+
* handler.destroy();
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
9
80
|
export declare class ResultsHandler extends BaseHandler {
|
|
10
81
|
#private;
|
|
82
|
+
/** The CoreContext instance for capturing results */
|
|
11
83
|
context: CoreContext;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new ResultsHandler instance.
|
|
86
|
+
*
|
|
87
|
+
* @param levelName - The minimum log level to handle
|
|
88
|
+
* @param options - Handler configuration including CoreContext
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const context = new CoreContext(contextOptions);
|
|
93
|
+
* const handler = new ResultsHandler('WARN', {
|
|
94
|
+
* context,
|
|
95
|
+
* formatter: '[{levelName}] {msg}'
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
12
99
|
constructor(levelName: LevelName, options: ResultsHandlerOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Sets up the handler with event listeners.
|
|
102
|
+
*
|
|
103
|
+
* Registers cleanup callbacks for process termination to ensure
|
|
104
|
+
* proper resource cleanup and result flushing.
|
|
105
|
+
*
|
|
106
|
+
* @override
|
|
107
|
+
*/
|
|
13
108
|
setup(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Handles incoming log records.
|
|
111
|
+
*
|
|
112
|
+
* Processes log records through the base handler and triggers
|
|
113
|
+
* immediate flushing for critical errors above ERROR level.
|
|
114
|
+
*
|
|
115
|
+
* @param logRecord - The log record to handle
|
|
116
|
+
*
|
|
117
|
+
* @override
|
|
118
|
+
*/
|
|
14
119
|
handle(logRecord: LogRecord): void;
|
|
120
|
+
/**
|
|
121
|
+
* Captures log messages as results in the context.
|
|
122
|
+
*
|
|
123
|
+
* Converts log level names to result types and captures them
|
|
124
|
+
* in the associated CoreContext for later analysis.
|
|
125
|
+
*
|
|
126
|
+
* @param levelName - The log level name ('WARN' or 'ERROR')
|
|
127
|
+
*
|
|
128
|
+
* @throws {Error} When an unsupported log level is provided
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // This is called automatically by the logging system
|
|
133
|
+
* handler.log('WARN'); // Captures as 'warning' result
|
|
134
|
+
* handler.log('ERROR'); // Captures as 'error' result
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
15
137
|
log(levelName: string): void;
|
|
138
|
+
/**
|
|
139
|
+
* Flushes any buffered content.
|
|
140
|
+
*
|
|
141
|
+
* This implementation resets the internal buffer. Override
|
|
142
|
+
* this method in subclasses to implement custom flushing behavior.
|
|
143
|
+
*
|
|
144
|
+
* @override
|
|
145
|
+
*/
|
|
16
146
|
flush(): void;
|
|
147
|
+
/**
|
|
148
|
+
* Destroys the handler and cleans up resources.
|
|
149
|
+
*
|
|
150
|
+
* Flushes any remaining content and removes event listeners
|
|
151
|
+
* to prevent memory leaks.
|
|
152
|
+
*
|
|
153
|
+
* @override
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
158
|
+
*
|
|
159
|
+
* try {
|
|
160
|
+
* // Use handler
|
|
161
|
+
* logger.addHandler(handler);
|
|
162
|
+
* await processDocument();
|
|
163
|
+
* } finally {
|
|
164
|
+
* // Always clean up
|
|
165
|
+
* handler.destroy();
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
17
169
|
destroy(): void;
|
|
18
170
|
}
|
|
19
171
|
//# sourceMappingURL=ResultsHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResultsHandler.d.ts","sourceRoot":"","sources":["../../src/context/ResultsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,4CAA4C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,OAAO,EAAE,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"ResultsHandler.d.ts","sourceRoot":"","sources":["../../src/context/ResultsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,4CAA4C,CAAA;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IAOpB;;;;;;;;;;;;;;OAcG;gBACS,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,qBAAqB;IAMhE;;;;;;;OAOG;IACM,KAAK;IAMd;;;;;;;;;OASG;IACM,MAAM,CAAC,SAAS,EAAE,SAAS;IASpC;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM;IAWrB;;;;;;;OAOG;IACH,KAAK;IAWL;;;;;;;;;;;;;;;;;;;;;OAqBG;IACM,OAAO;CAKjB"}
|
|
@@ -10,25 +10,143 @@ exports.ResultsHandler = void 0;
|
|
|
10
10
|
const levels_js_1 = require("../deps/jsr.io/@std/log/0.224.14/levels.js");
|
|
11
11
|
const base_handler_js_1 = require("../deps/jsr.io/@std/log/0.224.14/base_handler.js");
|
|
12
12
|
const ts_pattern_1 = require("ts-pattern");
|
|
13
|
+
/**
|
|
14
|
+
* Custom log handler that captures warning and error results for SKMTC processing.
|
|
15
|
+
*
|
|
16
|
+
* The `ResultsHandler` extends Deno's standard library BaseHandler to provide
|
|
17
|
+
* specialized logging behavior for the SKMTC pipeline. It integrates with the
|
|
18
|
+
* CoreContext to capture warnings and errors as structured results that can be
|
|
19
|
+
* analyzed and reported after processing completes.
|
|
20
|
+
*
|
|
21
|
+
* This handler ensures that important processing issues are captured and stored
|
|
22
|
+
* in the context's results system rather than just being logged to the console.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Result Capture**: Automatically captures WARN and ERROR logs as results
|
|
27
|
+
* - **Immediate Flushing**: Critical errors trigger immediate flush
|
|
28
|
+
* - **Lifecycle Management**: Proper setup and cleanup with event handlers
|
|
29
|
+
* - **Context Integration**: Seamlessly integrates with CoreContext results system
|
|
30
|
+
*
|
|
31
|
+
* @example Setting up the handler
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { getLogger } from '@std/log';
|
|
34
|
+
* import { ResultsHandler, CoreContext } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* const context = new CoreContext({
|
|
37
|
+
* // ... context options
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const handler = new ResultsHandler('WARN', {
|
|
41
|
+
* context: context,
|
|
42
|
+
* formatter: '[{levelName}] {msg}'
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const logger = getLogger();
|
|
46
|
+
* logger.addHandler(handler);
|
|
47
|
+
*
|
|
48
|
+
* // Now warnings and errors will be captured as results
|
|
49
|
+
* logger.warning('Schema validation issue detected');
|
|
50
|
+
* logger.error('Failed to process operation');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Integration in pipeline
|
|
54
|
+
* ```typescript
|
|
55
|
+
* class ProcessingPipeline {
|
|
56
|
+
* async process(document: OasDocument) {
|
|
57
|
+
* const context = new CoreContext(options);
|
|
58
|
+
*
|
|
59
|
+
* // Set up results handler
|
|
60
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
61
|
+
* const logger = getLogger();
|
|
62
|
+
* logger.addHandler(handler);
|
|
63
|
+
*
|
|
64
|
+
* try {
|
|
65
|
+
* const result = await this.processDocument(document, context);
|
|
66
|
+
*
|
|
67
|
+
* // Check captured results
|
|
68
|
+
* if (context.results.hasWarnings()) {
|
|
69
|
+
* console.log('Processing completed with warnings');
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* return result;
|
|
73
|
+
* } finally {
|
|
74
|
+
* handler.destroy();
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
13
80
|
class ResultsHandler extends base_handler_js_1.BaseHandler {
|
|
81
|
+
/**
|
|
82
|
+
* Creates a new ResultsHandler instance.
|
|
83
|
+
*
|
|
84
|
+
* @param levelName - The minimum log level to handle
|
|
85
|
+
* @param options - Handler configuration including CoreContext
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const context = new CoreContext(contextOptions);
|
|
90
|
+
* const handler = new ResultsHandler('WARN', {
|
|
91
|
+
* context,
|
|
92
|
+
* formatter: '[{levelName}] {msg}'
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
14
96
|
constructor(levelName, options) {
|
|
15
97
|
super(levelName, options);
|
|
16
98
|
_ResultsHandler_instances.add(this);
|
|
99
|
+
/** The CoreContext instance for capturing results */
|
|
17
100
|
Object.defineProperty(this, "context", {
|
|
18
101
|
enumerable: true,
|
|
19
102
|
configurable: true,
|
|
20
103
|
writable: true,
|
|
21
104
|
value: void 0
|
|
22
105
|
});
|
|
106
|
+
/** Bound callback for cleanup on process unload */
|
|
23
107
|
_ResultsHandler_unloadCallback.set(this, (() => {
|
|
24
108
|
this.destroy();
|
|
25
|
-
}).bind(this)
|
|
109
|
+
}).bind(this)
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new ResultsHandler instance.
|
|
112
|
+
*
|
|
113
|
+
* @param levelName - The minimum log level to handle
|
|
114
|
+
* @param options - Handler configuration including CoreContext
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const context = new CoreContext(contextOptions);
|
|
119
|
+
* const handler = new ResultsHandler('WARN', {
|
|
120
|
+
* context,
|
|
121
|
+
* formatter: '[{levelName}] {msg}'
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
);
|
|
26
126
|
this.context = options.context;
|
|
27
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Sets up the handler with event listeners.
|
|
130
|
+
*
|
|
131
|
+
* Registers cleanup callbacks for process termination to ensure
|
|
132
|
+
* proper resource cleanup and result flushing.
|
|
133
|
+
*
|
|
134
|
+
* @override
|
|
135
|
+
*/
|
|
28
136
|
setup() {
|
|
29
137
|
__classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
|
|
30
138
|
addEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
|
|
31
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Handles incoming log records.
|
|
142
|
+
*
|
|
143
|
+
* Processes log records through the base handler and triggers
|
|
144
|
+
* immediate flushing for critical errors above ERROR level.
|
|
145
|
+
*
|
|
146
|
+
* @param logRecord - The log record to handle
|
|
147
|
+
*
|
|
148
|
+
* @override
|
|
149
|
+
*/
|
|
32
150
|
handle(logRecord) {
|
|
33
151
|
super.handle(logRecord);
|
|
34
152
|
// Immediately flush if log level is higher than ERROR
|
|
@@ -36,6 +154,23 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
|
|
|
36
154
|
this.flush();
|
|
37
155
|
}
|
|
38
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Captures log messages as results in the context.
|
|
159
|
+
*
|
|
160
|
+
* Converts log level names to result types and captures them
|
|
161
|
+
* in the associated CoreContext for later analysis.
|
|
162
|
+
*
|
|
163
|
+
* @param levelName - The log level name ('WARN' or 'ERROR')
|
|
164
|
+
*
|
|
165
|
+
* @throws {Error} When an unsupported log level is provided
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // This is called automatically by the logging system
|
|
170
|
+
* handler.log('WARN'); // Captures as 'warning' result
|
|
171
|
+
* handler.log('ERROR'); // Captures as 'error' result
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
39
174
|
log(levelName) {
|
|
40
175
|
this.context.captureCurrentResult((0, ts_pattern_1.match)(levelName)
|
|
41
176
|
.with('WARN', () => 'warning')
|
|
@@ -44,9 +179,39 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
|
|
|
44
179
|
throw new Error(`Unexpected log level name: ${levelName}`);
|
|
45
180
|
}));
|
|
46
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Flushes any buffered content.
|
|
184
|
+
*
|
|
185
|
+
* This implementation resets the internal buffer. Override
|
|
186
|
+
* this method in subclasses to implement custom flushing behavior.
|
|
187
|
+
*
|
|
188
|
+
* @override
|
|
189
|
+
*/
|
|
47
190
|
flush() {
|
|
48
191
|
__classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
|
|
49
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Destroys the handler and cleans up resources.
|
|
195
|
+
*
|
|
196
|
+
* Flushes any remaining content and removes event listeners
|
|
197
|
+
* to prevent memory leaks.
|
|
198
|
+
*
|
|
199
|
+
* @override
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const handler = new ResultsHandler('WARN', { context });
|
|
204
|
+
*
|
|
205
|
+
* try {
|
|
206
|
+
* // Use handler
|
|
207
|
+
* logger.addHandler(handler);
|
|
208
|
+
* await processDocument();
|
|
209
|
+
* } finally {
|
|
210
|
+
* // Always clean up
|
|
211
|
+
* handler.destroy();
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
50
215
|
destroy() {
|
|
51
216
|
this.flush();
|
|
52
217
|
removeEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
|