@skmtc/core 0.0.794 → 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/esm/context/StackTrail.d.ts +293 -0
- package/esm/context/StackTrail.d.ts.map +1 -1
- package/esm/context/StackTrail.js +294 -0
- package/esm/types/Modifiers.d.ts +68 -0
- package/esm/types/Modifiers.d.ts.map +1 -1
- package/esm/types/TypeSystem.d.ts +419 -0
- package/esm/types/TypeSystem.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.d.ts +313 -0
- package/esm/typescript/FunctionParameter.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.js +328 -0
- 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
- package/script/context/StackTrail.d.ts +293 -0
- package/script/context/StackTrail.d.ts.map +1 -1
- package/script/context/StackTrail.js +294 -0
- package/script/types/Modifiers.d.ts +68 -0
- package/script/types/Modifiers.d.ts.map +1 -1
- package/script/types/TypeSystem.d.ts +419 -0
- package/script/types/TypeSystem.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.d.ts +313 -0
- package/script/typescript/FunctionParameter.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.js +328 -0
|
@@ -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"));
|
|
@@ -1,18 +1,311 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a stack-based trail for tracking document traversal in OpenAPI processing.
|
|
4
|
+
*
|
|
5
|
+
* The `StackTrail` class maintains a stack of string frames that represent the current
|
|
6
|
+
* path through an OpenAPI document structure. It's used throughout the SKMTC pipeline
|
|
7
|
+
* for tracking context during parsing, generating, and debugging schema processing.
|
|
8
|
+
*
|
|
9
|
+
* This class is essential for error reporting, debugging, and maintaining context
|
|
10
|
+
* when processing nested OpenAPI structures like schemas, operations, and components.
|
|
11
|
+
*
|
|
12
|
+
* ## Key Features
|
|
13
|
+
*
|
|
14
|
+
* - **Path Tracking**: Maintains a trail of traversed document elements
|
|
15
|
+
* - **Context Preservation**: Preserves parsing context for error reporting
|
|
16
|
+
* - **Stack Operations**: Supports push, pop, clone, and manipulation operations
|
|
17
|
+
* - **Reference Resolution**: Can generate OpenAPI reference strings from trails
|
|
18
|
+
* - **Serialization**: Supports string serialization and parsing for persistence
|
|
19
|
+
*
|
|
20
|
+
* @example Basic usage
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { StackTrail } from '@skmtc/core';
|
|
23
|
+
*
|
|
24
|
+
* // Start with empty trail
|
|
25
|
+
* const trail = new StackTrail();
|
|
26
|
+
*
|
|
27
|
+
* // Build a path through document structure
|
|
28
|
+
* trail.append('components')
|
|
29
|
+
* .append('schemas')
|
|
30
|
+
* .append('User')
|
|
31
|
+
* .append('properties')
|
|
32
|
+
* .append('name');
|
|
33
|
+
*
|
|
34
|
+
* console.log(trail.toString()); // 'components:schemas:User:properties:name'
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Schema reference generation
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const schemaTrail = new StackTrail(['components', 'schemas', 'User']);
|
|
40
|
+
* const ref = schemaTrail.toStackRef();
|
|
41
|
+
* console.log(ref); // '#/components/schemas/User'
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Error context tracking
|
|
45
|
+
* ```typescript
|
|
46
|
+
* class SchemaProcessor {
|
|
47
|
+
* processSchema(schema: OasSchema, trail: StackTrail) {
|
|
48
|
+
* try {
|
|
49
|
+
* // Process schema logic
|
|
50
|
+
* return this.transformSchema(schema);
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* throw new Error(`Error at ${trail.toString()}: ${error.message}`);
|
|
53
|
+
* // Error at components:schemas:User:properties:email: Invalid format
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Cloning and manipulation
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const baseTrail = new StackTrail(['components', 'schemas']);
|
|
62
|
+
*
|
|
63
|
+
* // Clone for processing different schemas
|
|
64
|
+
* const userTrail = baseTrail.clone().append('User');
|
|
65
|
+
* const productTrail = baseTrail.clone().append('Product');
|
|
66
|
+
*
|
|
67
|
+
* console.log(userTrail.toString()); // 'components:schemas:User'
|
|
68
|
+
* console.log(productTrail.toString()); // 'components:schemas:Product'
|
|
69
|
+
* console.log(baseTrail.toString()); // 'components:schemas' (unchanged)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
2
72
|
export declare class StackTrail {
|
|
3
73
|
#private;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new StackTrail instance.
|
|
76
|
+
*
|
|
77
|
+
* @param stack - Initial stack frames (defaults to empty array)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Empty trail
|
|
82
|
+
* const trail1 = new StackTrail();
|
|
83
|
+
*
|
|
84
|
+
* // Pre-populated trail
|
|
85
|
+
* const trail2 = new StackTrail(['components', 'schemas', 'User']);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
4
88
|
constructor(stack?: string[]);
|
|
89
|
+
/**
|
|
90
|
+
* Creates a shallow copy of the stack trail.
|
|
91
|
+
*
|
|
92
|
+
* @returns A new StackTrail instance with copied frames
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const original = new StackTrail(['components', 'schemas']);
|
|
97
|
+
* const copy = original.clone();
|
|
98
|
+
*
|
|
99
|
+
* copy.append('User');
|
|
100
|
+
* console.log(original.toString()); // 'components:schemas'
|
|
101
|
+
* console.log(copy.toString()); // 'components:schemas:User'
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
5
104
|
clone(): StackTrail;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new trail from a slice of the current trail.
|
|
107
|
+
*
|
|
108
|
+
* @param start - Starting index (inclusive)
|
|
109
|
+
* @param end - Ending index (exclusive, optional)
|
|
110
|
+
* @returns A new StackTrail with sliced frames
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const trail = new StackTrail(['a', 'b', 'c', 'd', 'e']);
|
|
115
|
+
*
|
|
116
|
+
* const slice1 = trail.slice(1, 3);
|
|
117
|
+
* console.log(slice1.toString()); // 'b:c'
|
|
118
|
+
*
|
|
119
|
+
* const slice2 = trail.slice(2);
|
|
120
|
+
* console.log(slice2.toString()); // 'c:d:e'
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
6
123
|
slice(start: number, end?: number): StackTrail;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if all specified frames exist in the trail.
|
|
126
|
+
*
|
|
127
|
+
* @param frames - Array of frames to check for
|
|
128
|
+
* @returns True if all frames are present in the trail
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const trail = new StackTrail(['components', 'schemas', 'User', 'properties']);
|
|
133
|
+
*
|
|
134
|
+
* console.log(trail.includes(['schemas', 'User'])); // true
|
|
135
|
+
* console.log(trail.includes(['schemas', 'Product'])); // false
|
|
136
|
+
* console.log(trail.includes(['components'])); // true
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
7
139
|
includes(frames: string[]): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Gets a copy of the current stack frames.
|
|
142
|
+
*
|
|
143
|
+
* @returns Array of stack frames in order
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const trail = new StackTrail(['components', 'schemas', 'User']);
|
|
148
|
+
* const frames = trail.stackTrail;
|
|
149
|
+
* console.log(frames); // ['components', 'schemas', 'User']
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
8
152
|
get stackTrail(): string[];
|
|
153
|
+
/**
|
|
154
|
+
* Appends frame(s) to the end of the trail.
|
|
155
|
+
*
|
|
156
|
+
* @param frame - Single frame string or array of frames to append
|
|
157
|
+
* @returns This StackTrail instance for chaining
|
|
158
|
+
*
|
|
159
|
+
* @throws {Error} When frame is not a string or string array
|
|
160
|
+
*
|
|
161
|
+
* @example Single frame
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const trail = new StackTrail(['components']);
|
|
164
|
+
* trail.append('schemas').append('User');
|
|
165
|
+
* console.log(trail.toString()); // 'components:schemas:User'
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Multiple frames
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const trail = new StackTrail();
|
|
171
|
+
* trail.append(['components', 'schemas', 'User']);
|
|
172
|
+
* console.log(trail.toString()); // 'components:schemas:User'
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
9
175
|
append(frame: string | string[]): StackTrail;
|
|
176
|
+
/**
|
|
177
|
+
* Gets the parent name of a property frame.
|
|
178
|
+
*
|
|
179
|
+
* This method is specifically designed to find parent object names
|
|
180
|
+
* for property trails in schema processing.
|
|
181
|
+
*
|
|
182
|
+
* @param frame - The frame name to find the parent of
|
|
183
|
+
* @returns Parent name if found, undefined otherwise
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const trail = new StackTrail(['components', 'schemas', 'User', 'properties', 'email']);
|
|
188
|
+
* const parent = trail.getParentOf('email');
|
|
189
|
+
* console.log(parent); // 'User'
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
10
192
|
getParentOf(frame: string): string | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Converts the trail to an OpenAPI reference string if applicable.
|
|
195
|
+
*
|
|
196
|
+
* Only trails that represent valid OpenAPI component references
|
|
197
|
+
* (starting with 'components') can be converted to reference strings.
|
|
198
|
+
*
|
|
199
|
+
* @returns OpenAPI reference string or undefined if not a valid reference trail
|
|
200
|
+
*
|
|
201
|
+
* @example Valid reference trail
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const trail = new StackTrail(['components', 'schemas', 'User']);
|
|
204
|
+
* const ref = trail.toStackRef();
|
|
205
|
+
* console.log(ref); // '#/components/schemas/User'
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @example Invalid trail
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const trail = new StackTrail(['paths', '/users', 'get']);
|
|
211
|
+
* const ref = trail.toStackRef();
|
|
212
|
+
* console.log(ref); // undefined
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
11
215
|
toStackRef(): string | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Removes frame(s) from the end of the trail.
|
|
218
|
+
*
|
|
219
|
+
* @param frame - Single frame string or array of frames to remove
|
|
220
|
+
* @returns This StackTrail instance for chaining
|
|
221
|
+
*
|
|
222
|
+
* @throws {Error} When trying to remove a frame that doesn't match the last frame
|
|
223
|
+
* @throws {Error} When frame is not a string or string array
|
|
224
|
+
*
|
|
225
|
+
* @example Single frame removal
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const trail = new StackTrail(['components', 'schemas', 'User', 'properties']);
|
|
228
|
+
* trail.remove('properties');
|
|
229
|
+
* console.log(trail.toString()); // 'components:schemas:User'
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example Multiple frame removal
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const trail = new StackTrail(['components', 'schemas', 'User', 'properties', 'name']);
|
|
235
|
+
* trail.remove(['name', 'properties']);
|
|
236
|
+
* console.log(trail.toString()); // 'components:schemas:User'
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
12
239
|
remove(frame: string | string[]): StackTrail;
|
|
240
|
+
/**
|
|
241
|
+
* Joins multiple stacks or strings into a single colon-separated string.
|
|
242
|
+
*
|
|
243
|
+
* @param stacks - Array of StackTrail instances or strings to join
|
|
244
|
+
* @returns Joined string with colon separators
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const trail1 = new StackTrail(['components', 'schemas']);
|
|
249
|
+
* const trail2 = new StackTrail(['User', 'properties']);
|
|
250
|
+
*
|
|
251
|
+
* const joined = StackTrail.join(trail1, 'separator', trail2);
|
|
252
|
+
* console.log(joined); // 'components:schemas:separator:User:properties'
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
13
255
|
static join(...stacks: (StackTrail | string)[]): string;
|
|
256
|
+
/**
|
|
257
|
+
* Parses a colon-separated string into a StackTrail instance.
|
|
258
|
+
*
|
|
259
|
+
* @param value - Colon-separated string to parse
|
|
260
|
+
* @returns New StackTrail instance
|
|
261
|
+
*
|
|
262
|
+
* @throws {Error} When the string contains empty tokens
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const trail = StackTrail.parse('components:schemas:User:properties:name');
|
|
267
|
+
* console.log(trail.stackTrail); // ['components', 'schemas', 'User', 'properties', 'name']
|
|
268
|
+
*
|
|
269
|
+
* // Handles escaped colons
|
|
270
|
+
* const escapedTrail = StackTrail.parse('components:schemas:User%3AType');
|
|
271
|
+
* console.log(escapedTrail.stackTrail); // ['components', 'schemas', 'User:Type']
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
14
274
|
static parse(value: string): StackTrail;
|
|
275
|
+
/**
|
|
276
|
+
* Converts the trail to JSON representation.
|
|
277
|
+
*
|
|
278
|
+
* Used for serialization in JSON contexts. Returns the same
|
|
279
|
+
* as toString() method.
|
|
280
|
+
*
|
|
281
|
+
* @returns String representation of the trail
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const trail = new StackTrail(['components', 'schemas', 'User']);
|
|
286
|
+
* const json = JSON.stringify({ path: trail });
|
|
287
|
+
* console.log(json); // '{"path":"components:schemas:User"}'
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
15
290
|
toJSON(): string;
|
|
291
|
+
/**
|
|
292
|
+
* Converts the trail to a colon-separated string representation.
|
|
293
|
+
*
|
|
294
|
+
* Colons within frame names are escaped as '%3A' to avoid conflicts
|
|
295
|
+
* with the separator character.
|
|
296
|
+
*
|
|
297
|
+
* @returns String representation of the trail
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const trail = new StackTrail(['components', 'schemas', 'User']);
|
|
302
|
+
* console.log(trail.toString()); // 'components:schemas:User'
|
|
303
|
+
*
|
|
304
|
+
* // With colon in frame name
|
|
305
|
+
* const trailWithColon = new StackTrail(['components', 'schemas', 'User:Type']);
|
|
306
|
+
* console.log(trailWithColon.toString()); // 'components:schemas:User%3AType'
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
16
309
|
toString(): string;
|
|
17
310
|
}
|
|
18
311
|
//# sourceMappingURL=StackTrail.d.ts.map
|