@skmtc/core 0.0.795 → 0.0.797

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.
Files changed (61) hide show
  1. package/esm/app/validate.d.ts +32 -0
  2. package/esm/app/validate.d.ts.map +1 -1
  3. package/esm/app/validate.js +32 -0
  4. package/esm/context/CoreContext.d.ts +137 -1
  5. package/esm/context/CoreContext.d.ts.map +1 -1
  6. package/esm/context/CoreContext.js +87 -0
  7. package/esm/context/ResultsHandler.d.ts +152 -0
  8. package/esm/context/ResultsHandler.d.ts.map +1 -1
  9. package/esm/context/ResultsHandler.js +166 -1
  10. package/esm/dsl/constants.d.ts +28 -0
  11. package/esm/dsl/constants.d.ts.map +1 -1
  12. package/esm/dsl/constants.js +28 -0
  13. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  14. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  15. package/esm/oas/_helpers/parseDefault.js +128 -0
  16. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  17. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseEnum.js +104 -0
  19. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  20. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseExample.js +87 -0
  22. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  23. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseFormat.js +138 -0
  25. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  26. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  27. package/esm/oas/_helpers/parseNullable.js +113 -0
  28. package/esm/run/toV3JsonDocument.d.ts +90 -0
  29. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  30. package/esm/run/toV3JsonDocument.js +84 -0
  31. package/package.json +1 -1
  32. package/script/app/validate.d.ts +32 -0
  33. package/script/app/validate.d.ts.map +1 -1
  34. package/script/app/validate.js +32 -0
  35. package/script/context/CoreContext.d.ts +137 -1
  36. package/script/context/CoreContext.d.ts.map +1 -1
  37. package/script/context/CoreContext.js +87 -0
  38. package/script/context/ResultsHandler.d.ts +152 -0
  39. package/script/context/ResultsHandler.d.ts.map +1 -1
  40. package/script/context/ResultsHandler.js +166 -1
  41. package/script/dsl/constants.d.ts +28 -0
  42. package/script/dsl/constants.d.ts.map +1 -1
  43. package/script/dsl/constants.js +28 -0
  44. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  45. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  46. package/script/oas/_helpers/parseDefault.js +128 -0
  47. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  48. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  49. package/script/oas/_helpers/parseEnum.js +104 -0
  50. package/script/oas/_helpers/parseExample.d.ts +107 -0
  51. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  52. package/script/oas/_helpers/parseExample.js +87 -0
  53. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  54. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  55. package/script/oas/_helpers/parseFormat.js +138 -0
  56. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  57. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  58. package/script/oas/_helpers/parseNullable.js +113 -0
  59. package/script/run/toV3JsonDocument.d.ts +90 -0
  60. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  61. package/script/run/toV3JsonDocument.js +84 -0
@@ -1,6 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkProjectName = void 0;
4
+ /**
5
+ * Validates a project name against SKMTC naming conventions.
6
+ *
7
+ * Ensures project names follow standard naming patterns suitable for package
8
+ * managers and file systems. Names must be lowercase, contain only letters,
9
+ * numbers, and hyphens, with specific length and format requirements.
10
+ *
11
+ * @param name - The project name to validate
12
+ * @returns An error message string if validation fails, undefined if valid
13
+ *
14
+ * @example Valid project names
15
+ * ```typescript
16
+ * checkProjectName('my-api-client'); // undefined (valid)
17
+ * checkProjectName('user-service'); // undefined (valid)
18
+ * checkProjectName('api2'); // undefined (valid)
19
+ * ```
20
+ *
21
+ * @example Invalid project names
22
+ * ```typescript
23
+ * checkProjectName('A'); // 'Name must be at least 2 characters long'
24
+ * checkProjectName('My-API-Client'); // 'Name must only contain lowercase letters, numbers and hyphens'
25
+ * checkProjectName('-api-client'); // 'Name cannot start with a hyphen'
26
+ * checkProjectName('api-client-'); // 'Name cannot end with a hyphen'
27
+ * ```
28
+ *
29
+ * @example Validation rules
30
+ * - Minimum length: 2 characters
31
+ * - Maximum length: 20 characters
32
+ * - Allowed characters: a-z, 0-9, hyphens (-)
33
+ * - Cannot start or end with hyphen
34
+ * - Must be lowercase only
35
+ */
4
36
  require("../_dnt.polyfills.js");
5
37
  const checkProjectName = (name) => {
6
38
  if (name.length < 2) {
@@ -9,29 +9,70 @@ import * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
9
9
  import type { GeneratorsMapContainer } from '../types/GeneratorType.js';
10
10
  import type { OpenAPIV3 } from 'openapi-types';
11
11
  import type { RenderResult } from './types.js';
12
+ /**
13
+ * Represents the parse phase of the SKMTC pipeline.
14
+ *
15
+ * The parse phase converts OpenAPI v3 JSON documents into internal OAS objects,
16
+ * handling schema validation, reference resolution, and data transformation.
17
+ */
12
18
  export type ParsePhase = {
19
+ /** Identifies this as the parse phase */
13
20
  type: 'parse';
21
+ /** The parse context containing parsed document and utilities */
14
22
  context: ParseContext;
15
23
  };
24
+ /**
25
+ * Represents the generate phase of the SKMTC pipeline.
26
+ *
27
+ * The generate phase transforms parsed OAS objects into generator-specific artifacts,
28
+ * applying templates, handling references, and preparing output files.
29
+ */
16
30
  export type GeneratePhase = {
31
+ /** Identifies this as the generate phase */
17
32
  type: 'generate';
33
+ /** The generate context for artifact creation and processing */
18
34
  context: GenerateContext;
19
35
  };
36
+ /**
37
+ * Represents the render phase of the SKMTC pipeline.
38
+ *
39
+ * The render phase takes generator artifacts and renders them to formatted files,
40
+ * applying code formatting, file system operations, and final output generation.
41
+ */
20
42
  export type RenderPhase = {
43
+ /** Identifies this as the render phase */
21
44
  type: 'render';
45
+ /** The render context for file output and formatting */
22
46
  context: RenderContext;
23
47
  };
48
+ /**
49
+ * Union type representing any phase of the SKMTC pipeline execution.
50
+ *
51
+ * Each execution phase contains its type identifier and associated context,
52
+ * allowing for type-safe phase handling and context access throughout the pipeline.
53
+ */
24
54
  export type ExecutionPhase = ParsePhase | GeneratePhase | RenderPhase;
25
55
  type CoreContextArgs = {
26
56
  spanId: string;
27
57
  logsPath?: string;
28
58
  silent: boolean;
29
59
  };
30
- type ToArtifactsArgs = {
60
+ /**
61
+ * Arguments for the `toArtifacts` method of CoreContext.
62
+ *
63
+ * Contains all the necessary configuration for transforming an OpenAPI document
64
+ * into code artifacts through the SKMTC pipeline.
65
+ */
66
+ export type ToArtifactsArgs = {
67
+ /** The OpenAPI v3 document to process */
31
68
  documentObject: OpenAPIV3.Document;
69
+ /** Client settings for customization (optional) */
32
70
  settings: ClientSettings | undefined;
71
+ /** Function that returns the generator configuration map */
33
72
  toGeneratorConfigMap: <EnrichmentType = undefined>() => GeneratorsMapContainer<EnrichmentType>;
73
+ /** Prettier configuration for code formatting (optional) */
34
74
  prettier?: PrettierConfigType;
75
+ /** Whether to suppress console output */
35
76
  silent: boolean;
36
77
  };
37
78
  /**
@@ -218,13 +259,108 @@ export declare class CoreContext {
218
259
  * @throws Will throw an error if any phase of the pipeline fails
219
260
  */
220
261
  toArtifacts({ documentObject, settings, toGeneratorConfigMap, prettier }: ToArtifactsArgs): Promise<RenderResult>;
262
+ /**
263
+ * Executes a function with distributed tracing and logging.
264
+ *
265
+ * This method wraps function execution with tracing capabilities, updating the
266
+ * stack trail for context tracking and logging execution details. It's used
267
+ * throughout the SKMTC pipeline to maintain execution context and debugging information.
268
+ *
269
+ * @template T - The return type of the traced function
270
+ * @param token - Single token or array of tokens to add to the trace stack
271
+ * @param fn - The function to execute within the trace context
272
+ * @returns The result of executing the traced function
273
+ *
274
+ * @example Single token tracing
275
+ * ```typescript
276
+ * const result = context.trace('parse-schema', () => {
277
+ * // Schema parsing logic here
278
+ * return parsedSchema;
279
+ * });
280
+ * ```
281
+ *
282
+ * @example Multiple token tracing (nested context)
283
+ * ```typescript
284
+ * const result = context.trace(['components', 'schemas', 'User'], () => {
285
+ * // Process User schema
286
+ * return processedUserSchema;
287
+ * });
288
+ * ```
289
+ */
221
290
  trace<T>(token: string | string[], fn: () => T): T;
291
+ /**
292
+ * Captures a result at the current execution position in the stack trail.
293
+ *
294
+ * This method records processing results (success, warning, error, etc.) at the
295
+ * current location in the document traversal stack. Results are associated with
296
+ * the current stack trail position, enabling detailed error reporting and
297
+ * debugging of OpenAPI processing issues.
298
+ *
299
+ * @param result - The type of result to capture (success, warning, error, etc.)
300
+ *
301
+ * @example Capturing a warning result
302
+ * ```typescript
303
+ * context.captureCurrentResult('warning');
304
+ * // Result captured at current stack position like: "components.schemas.User.properties.email"
305
+ * ```
306
+ *
307
+ * @example Usage during schema processing
308
+ * ```typescript
309
+ * context.trace(['components', 'schemas', 'User'], () => {
310
+ * try {
311
+ * processUserSchema();
312
+ * context.captureCurrentResult('success');
313
+ * } catch (error) {
314
+ * context.captureCurrentResult('error');
315
+ * }
316
+ * });
317
+ * ```
318
+ */
222
319
  captureCurrentResult(result: ResultType): void;
223
320
  }
321
+ /**
322
+ * Arguments for the SKMTC JSON log formatter.
323
+ *
324
+ * Contains the log record and stack trail information needed to format
325
+ * structured JSON log entries for the SKMTC processing pipeline.
326
+ */
224
327
  export type JsonFormatterArgs = {
328
+ /** The Deno log record containing log level, message, and metadata */
225
329
  logRecord: log.LogRecord;
330
+ /** String representation of the current stack trail position */
226
331
  stackTrail: string;
227
332
  };
333
+ /**
334
+ * Custom JSON formatter for SKMTC log entries.
335
+ *
336
+ * Formats log records into structured JSON that includes stack trail context,
337
+ * making it easier to trace execution and debug issues in the SKMTC pipeline.
338
+ * The formatter flattens log arguments and includes execution context.
339
+ *
340
+ * @param args - Formatter arguments containing log record and stack trail
341
+ * @returns Formatted JSON string for the log entry
342
+ *
343
+ * @example Usage in logger setup
344
+ * ```typescript
345
+ * const handler = new ConsoleHandler("DEBUG", {
346
+ * formatter: (logRecord) => skmtcFormatter({
347
+ * logRecord,
348
+ * stackTrail: context.stackTrail.toString()
349
+ * })
350
+ * });
351
+ * ```
352
+ *
353
+ * @example Output format
354
+ * ```json
355
+ * {
356
+ * "stackTrail": "components.schemas.User.properties.email",
357
+ * "level": "INFO",
358
+ * "datetime": 1645123456789,
359
+ * "message": "Processing email property",
360
+ * "args": { "format": "email", "required": true }
361
+ * }
362
+ * ```
363
+ */
228
364
  export declare function skmtcFormatter({ logRecord, stackTrail }: JsonFormatterArgs): string;
229
365
  export {};
230
366
  //# sourceMappingURL=CoreContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CoreContext.d.ts","sourceRoot":"","sources":["../../src/context/CoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,GAAG,MAAM,yCAAyC,CAAA;AAQ9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAEvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,KAAK,E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lB,yCAAyC;IACzC,MAAM,EAAE,OAAO,CAAA;IAEf;;;;;;;;;;;;;;;;;;;;;;;OAuBG;gBACS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,eAAe;IAmDzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,QAAQ,GAAG;QAAE,WAAW,EAAE,WAAW,CAAA;KAAE;IAUvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsEG;IACG,WAAW,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,oBAAoB,EAAE,QAAQ,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC;IA2DvH;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAkClD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAkB/C;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,sEAAsE;IACtE,SAAS,EAAE,GAAG,CAAC,SAAS,CAAA;IACxB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAQnF"}
@@ -315,11 +315,67 @@ class CoreContext {
315
315
  });
316
316
  }
317
317
  }
318
+ /**
319
+ * Executes a function with distributed tracing and logging.
320
+ *
321
+ * This method wraps function execution with tracing capabilities, updating the
322
+ * stack trail for context tracking and logging execution details. It's used
323
+ * throughout the SKMTC pipeline to maintain execution context and debugging information.
324
+ *
325
+ * @template T - The return type of the traced function
326
+ * @param token - Single token or array of tokens to add to the trace stack
327
+ * @param fn - The function to execute within the trace context
328
+ * @returns The result of executing the traced function
329
+ *
330
+ * @example Single token tracing
331
+ * ```typescript
332
+ * const result = context.trace('parse-schema', () => {
333
+ * // Schema parsing logic here
334
+ * return parsedSchema;
335
+ * });
336
+ * ```
337
+ *
338
+ * @example Multiple token tracing (nested context)
339
+ * ```typescript
340
+ * const result = context.trace(['components', 'schemas', 'User'], () => {
341
+ * // Process User schema
342
+ * return processedUserSchema;
343
+ * });
344
+ * ```
345
+ */
318
346
  trace(token, fn) {
319
347
  console.log('trace', token);
320
348
  this.logger.info('trace', token);
321
349
  return (0, tracer_js_1.tracer)(__classPrivateFieldGet(this, _CoreContext_stackTrail, "f"), token, fn, this.logger);
322
350
  }
351
+ /**
352
+ * Captures a result at the current execution position in the stack trail.
353
+ *
354
+ * This method records processing results (success, warning, error, etc.) at the
355
+ * current location in the document traversal stack. Results are associated with
356
+ * the current stack trail position, enabling detailed error reporting and
357
+ * debugging of OpenAPI processing issues.
358
+ *
359
+ * @param result - The type of result to capture (success, warning, error, etc.)
360
+ *
361
+ * @example Capturing a warning result
362
+ * ```typescript
363
+ * context.captureCurrentResult('warning');
364
+ * // Result captured at current stack position like: "components.schemas.User.properties.email"
365
+ * ```
366
+ *
367
+ * @example Usage during schema processing
368
+ * ```typescript
369
+ * context.trace(['components', 'schemas', 'User'], () => {
370
+ * try {
371
+ * processUserSchema();
372
+ * context.captureCurrentResult('success');
373
+ * } catch (error) {
374
+ * context.captureCurrentResult('error');
375
+ * }
376
+ * });
377
+ * ```
378
+ */
323
379
  captureCurrentResult(result) {
324
380
  __classPrivateFieldGet(this, _CoreContext_results, "f").capture(__classPrivateFieldGet(this, _CoreContext_stackTrail, "f").toString(), result);
325
381
  }
@@ -392,6 +448,37 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
392
448
  });
393
449
  return { type: 'render', context: renderContext };
394
450
  };
451
+ /**
452
+ * Custom JSON formatter for SKMTC log entries.
453
+ *
454
+ * Formats log records into structured JSON that includes stack trail context,
455
+ * making it easier to trace execution and debug issues in the SKMTC pipeline.
456
+ * The formatter flattens log arguments and includes execution context.
457
+ *
458
+ * @param args - Formatter arguments containing log record and stack trail
459
+ * @returns Formatted JSON string for the log entry
460
+ *
461
+ * @example Usage in logger setup
462
+ * ```typescript
463
+ * const handler = new ConsoleHandler("DEBUG", {
464
+ * formatter: (logRecord) => skmtcFormatter({
465
+ * logRecord,
466
+ * stackTrail: context.stackTrail.toString()
467
+ * })
468
+ * });
469
+ * ```
470
+ *
471
+ * @example Output format
472
+ * ```json
473
+ * {
474
+ * "stackTrail": "components.schemas.User.properties.email",
475
+ * "level": "INFO",
476
+ * "datetime": 1645123456789,
477
+ * "message": "Processing email property",
478
+ * "args": { "format": "email", "required": true }
479
+ * }
480
+ * ```
481
+ */
395
482
  function skmtcFormatter({ logRecord, stackTrail }) {
396
483
  return JSON.stringify({
397
484
  stackTrail,
@@ -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;gBAMR,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,qBAAqB;IAMvD,KAAK;IAML,MAAM,CAAC,SAAS,EAAE,SAAS;IASpC,GAAG,CAAC,SAAS,EAAE,MAAM;IAWrB,KAAK;IAMI,OAAO;CAKjB"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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