@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.
@@ -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"));
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"StackTrail.d.ts","sourceRoot":"","sources":["../../src/context/StackTrail.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAG9B,qBAAa,UAAU;;gBAGT,KAAK,GAAE,MAAM,EAAO;IAIhC,KAAK,IAAI,UAAU;IAInB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU;IAI9C,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO;IAInC,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAgB5C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAW9C,UAAU,IAAI,MAAM,GAAG,SAAS;IAkBhC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAsB5C,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM;IAIvD,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAYvC,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;CAOnB"}
1
+ {"version":3,"file":"StackTrail.d.ts","sourceRoot":"","sources":["../../src/context/StackTrail.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAG9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,qBAAa,UAAU;;IAIrB;;;;;;;;;;;;;OAaG;gBACS,KAAK,GAAE,MAAM,EAAO;IAIhC;;;;;;;;;;;;;;OAcG;IACH,KAAK,IAAI,UAAU;IAInB;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU;IAI9C;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO;IAInC;;;;;;;;;;;OAWG;IACH,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAgB5C;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAW9C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAkBhC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAsB5C;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM;IAIvD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAYvC;;;;;;;;;;;;;;OAcG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,IAAI,MAAM;CAOnB"}