@skmtc/core 0.36.1 → 0.38.0

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 (67) hide show
  1. package/esm/_dnt.polyfills.d.ts +6 -6
  2. package/esm/anchors/postPass.d.ts +6 -3
  3. package/esm/anchors/postPass.js +6 -3
  4. package/esm/context/CoreContext.d.ts +10 -2
  5. package/esm/context/CoreContext.js +158 -87
  6. package/esm/context/GenerateContext.d.ts +11 -0
  7. package/esm/context/GenerateContext.js +44 -16
  8. package/esm/context/LogLinesHandler.d.ts +28 -0
  9. package/esm/context/LogLinesHandler.js +65 -0
  10. package/esm/context/ParseContext.js +23 -4
  11. package/esm/context/ParseIssue.d.ts +12 -9
  12. package/esm/context/ParseIssue.js +7 -6
  13. package/esm/context/RenderContext.js +47 -65
  14. package/esm/context/ResultsHandler.d.ts +5 -3
  15. package/esm/context/ResultsHandler.js +11 -5
  16. package/esm/context/StackTrail.d.ts +14 -6
  17. package/esm/context/StackTrail.js +77 -29
  18. package/esm/context/documentTrail.d.ts +7 -3
  19. package/esm/context/documentTrail.js +6 -2
  20. package/esm/context/generateTypes.d.ts +21 -2
  21. package/esm/context/generateTypes.js +2 -1
  22. package/esm/helpers/ResultsLog.d.ts +2 -2
  23. package/esm/helpers/ResultsLog.js +7 -4
  24. package/esm/mod.d.ts +2 -0
  25. package/esm/mod.js +2 -0
  26. package/esm/run/toArtifacts.d.ts +9 -1
  27. package/esm/run/toArtifacts.js +4 -4
  28. package/esm/types/LogLine.d.ts +36 -0
  29. package/esm/types/LogLine.js +26 -0
  30. package/esm/types/Manifest.d.ts +1 -1
  31. package/esm/types/Manifest.js +16 -4
  32. package/esm/types/SerializedError.d.ts +25 -0
  33. package/esm/types/SerializedError.js +50 -0
  34. package/package.json +1 -1
  35. package/script/_dnt.polyfills.d.ts +6 -6
  36. package/script/anchors/postPass.d.ts +6 -3
  37. package/script/anchors/postPass.js +6 -3
  38. package/script/context/CoreContext.d.ts +10 -2
  39. package/script/context/CoreContext.js +158 -87
  40. package/script/context/GenerateContext.d.ts +11 -0
  41. package/script/context/GenerateContext.js +44 -16
  42. package/script/context/LogLinesHandler.d.ts +28 -0
  43. package/script/context/LogLinesHandler.js +69 -0
  44. package/script/context/ParseContext.js +23 -4
  45. package/script/context/ParseIssue.d.ts +12 -9
  46. package/script/context/ParseIssue.js +7 -6
  47. package/script/context/RenderContext.js +47 -65
  48. package/script/context/ResultsHandler.d.ts +5 -3
  49. package/script/context/ResultsHandler.js +11 -5
  50. package/script/context/StackTrail.d.ts +14 -6
  51. package/script/context/StackTrail.js +76 -28
  52. package/script/context/documentTrail.d.ts +7 -3
  53. package/script/context/documentTrail.js +9 -3
  54. package/script/context/generateTypes.d.ts +21 -2
  55. package/script/context/generateTypes.js +2 -1
  56. package/script/helpers/ResultsLog.d.ts +2 -2
  57. package/script/helpers/ResultsLog.js +7 -4
  58. package/script/mod.d.ts +2 -0
  59. package/script/mod.js +2 -0
  60. package/script/run/toArtifacts.d.ts +9 -1
  61. package/script/run/toArtifacts.js +4 -4
  62. package/script/types/LogLine.d.ts +36 -0
  63. package/script/types/LogLine.js +62 -0
  64. package/script/types/Manifest.d.ts +1 -1
  65. package/script/types/Manifest.js +16 -4
  66. package/script/types/SerializedError.d.ts +25 -0
  67. package/script/types/SerializedError.js +87 -0
@@ -6,7 +6,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _ResultsHandler_instances, _ResultsHandler_unloadCallback, _ResultsHandler_resetBuffer;
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
- import { StackTrail } from './StackTrail.js';
10
9
  export class ResultsHandler extends BaseHandler {
11
10
  /**
12
11
  * Creates a new ResultsHandler instance.
@@ -87,10 +86,11 @@ export class ResultsHandler extends BaseHandler {
87
86
  /**
88
87
  * Captures log messages as results in the context.
89
88
  *
90
- * Converts log level names to result types and captures them
91
- * in the associated CoreContext for later analysis.
89
+ * Converts log level names to result types and captures them in the
90
+ * associated CoreContext at the trail of the subject being generated.
91
+ * A line logged outside a subject records nothing.
92
92
  *
93
- * @param levelName - The log level name ('WARN' or 'ERROR')
93
+ * @param levelName - The log level name ('WARN', 'ERROR' or 'CRITICAL')
94
94
  *
95
95
  * @throws {Error} When an unsupported log level is provided
96
96
  *
@@ -99,6 +99,7 @@ export class ResultsHandler extends BaseHandler {
99
99
  * // This is called automatically by the logging system
100
100
  * handler.log('WARN'); // Captures as 'warning' result
101
101
  * handler.log('ERROR'); // Captures as 'error' result
102
+ * handler.log('CRITICAL'); // Captures as 'error' result
102
103
  * ```
103
104
  */
104
105
  log(levelName) {
@@ -108,12 +109,17 @@ export class ResultsHandler extends BaseHandler {
108
109
  resultType = 'warning';
109
110
  break;
110
111
  case 'ERROR':
112
+ case 'CRITICAL':
111
113
  resultType = 'error';
112
114
  break;
113
115
  default:
114
116
  throw new Error(`Unexpected log level name: ${levelName}`);
115
117
  }
116
- this.context.captureCurrentResult(resultType, new StackTrail(['SKIPPED']));
118
+ // Outside a subject there is no result to record against.
119
+ const subjectTrail = this.context.currentSubjectTrail;
120
+ if (subjectTrail !== undefined) {
121
+ this.context.captureCurrentResult(resultType, subjectTrail);
122
+ }
117
123
  }
118
124
  /**
119
125
  * Flushes any buffered content.
@@ -2,7 +2,7 @@ import "../_dnt.polyfills.js";
2
2
  import { type JsonPointer } from '../types/JsonPointer.js';
3
3
  export declare class StackTrail {
4
4
  #private;
5
- constructor(stack?: string[]);
5
+ constructor(stack?: readonly string[]);
6
6
  /**
7
7
  * The canonical empty trail — used for nodes that were synthesized
8
8
  * programmatically rather than parsed from a source document (they
@@ -13,9 +13,10 @@ export declare class StackTrail {
13
13
  /** True when the trail holds no frames (a synthetic / positionless node). */
14
14
  isEmpty(): boolean;
15
15
  /**
16
- * Creates a shallow copy of the stack trail.
16
+ * Creates an independent trail with the same frames. The frames are
17
+ * shared, not copied.
17
18
  *
18
- * @returns A new StackTrail instance with copied frames
19
+ * @returns A new StackTrail instance with the same frames
19
20
  *
20
21
  * @example
21
22
  * ```typescript
@@ -29,8 +30,11 @@ export declare class StackTrail {
29
30
  */
30
31
  clone(): StackTrail;
31
32
  /**
32
- * The live array of stack frames, not a copy: {@link trace} pops it after
33
- * `fn` returns. Copy it (`[...trail.stackTrail]`) to keep the frames.
33
+ * The frames of the trail as a new read-only array, built on each read.
34
+ * Change the trail with {@link append}, {@link remove} or {@link trace},
35
+ * not through this array. The trail itself is live: {@link trace}
36
+ * removes its frame after `fn` returns, so read the frames inside `fn`
37
+ * to keep them.
34
38
  *
35
39
  * @returns Array of stack frames in order
36
40
  *
@@ -41,7 +45,7 @@ export declare class StackTrail {
41
45
  * console.log(frames); // ['components', 'schemas', 'User']
42
46
  * ```
43
47
  */
44
- get stackTrail(): string[];
48
+ get stackTrail(): readonly string[];
45
49
  /**
46
50
  * Appends frame(s) to the end of the trail.
47
51
  *
@@ -68,6 +72,10 @@ export declare class StackTrail {
68
72
  /**
69
73
  * Runs `fn` on a copy of the trail with `key` appended: one frame for a
70
74
  * string, one frame per element for an array.
75
+ *
76
+ * When `fn` returns, `key` is removed and must be the last frame. When
77
+ * `fn` throws, the copy goes back to the frames it started with and the
78
+ * error from `fn` is rethrown: a frame check there would replace it.
71
79
  */
72
80
  trace<T>(key: string | string[], fn: (st: StackTrail) => T): T;
73
81
  /** Async form of {@link trace}. */
@@ -9,16 +9,27 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _StackTrail_stack;
12
+ var _StackTrail_instances, _StackTrail_last, _StackTrail_mapFrames, _StackTrail_rootPhaseFrame, _StackTrail_frameAtDepth;
13
13
  import "../_dnt.polyfills.js";
14
14
  import { componentsKeys } from '../oas/components/Components.js';
15
15
  import { toJsonPointer } from '../types/JsonPointer.js';
16
- import { toDocumentFrames, toTrailString } from './documentTrail.js';
16
+ import { escapeTrailFrame, isPhaseFrame } from './documentTrail.js';
17
+ const toTrailFrame = (parent, frame) => ({
18
+ frame,
19
+ parent,
20
+ depth: (parent?.depth ?? 0) + 1
21
+ });
22
+ const asIs = (frame) => frame;
17
23
  export class StackTrail {
18
24
  constructor(stack = []) {
19
- /** Internal stack of traversal frames */
20
- _StackTrail_stack.set(this, void 0);
21
- __classPrivateFieldSet(this, _StackTrail_stack, stack, "f");
25
+ _StackTrail_instances.add(this);
26
+ /**
27
+ * Last frame of the trail; `undefined` for the empty trail. A parsed
28
+ * document holds one trail per node, so the frames are a shared linked
29
+ * list and not one array per trail.
30
+ */
31
+ _StackTrail_last.set(this, void 0);
32
+ __classPrivateFieldSet(this, _StackTrail_last, stack.reduce(toTrailFrame, undefined), "f");
22
33
  }
23
34
  /**
24
35
  * The canonical empty trail — used for nodes that were synthesized
@@ -31,12 +42,13 @@ export class StackTrail {
31
42
  }
32
43
  /** True when the trail holds no frames (a synthetic / positionless node). */
33
44
  isEmpty() {
34
- return __classPrivateFieldGet(this, _StackTrail_stack, "f").length === 0;
45
+ return __classPrivateFieldGet(this, _StackTrail_last, "f") === undefined;
35
46
  }
36
47
  /**
37
- * Creates a shallow copy of the stack trail.
48
+ * Creates an independent trail with the same frames. The frames are
49
+ * shared, not copied.
38
50
  *
39
- * @returns A new StackTrail instance with copied frames
51
+ * @returns A new StackTrail instance with the same frames
40
52
  *
41
53
  * @example
42
54
  * ```typescript
@@ -49,11 +61,16 @@ export class StackTrail {
49
61
  * ```
50
62
  */
51
63
  clone() {
52
- return new StackTrail([...__classPrivateFieldGet(this, _StackTrail_stack, "f")]);
64
+ const copy = new StackTrail();
65
+ __classPrivateFieldSet(copy, _StackTrail_last, __classPrivateFieldGet(this, _StackTrail_last, "f"), "f");
66
+ return copy;
53
67
  }
54
68
  /**
55
- * The live array of stack frames, not a copy: {@link trace} pops it after
56
- * `fn` returns. Copy it (`[...trail.stackTrail]`) to keep the frames.
69
+ * The frames of the trail as a new read-only array, built on each read.
70
+ * Change the trail with {@link append}, {@link remove} or {@link trace},
71
+ * not through this array. The trail itself is live: {@link trace}
72
+ * removes its frame after `fn` returns, so read the frames inside `fn`
73
+ * to keep them.
57
74
  *
58
75
  * @returns Array of stack frames in order
59
76
  *
@@ -65,7 +82,7 @@ export class StackTrail {
65
82
  * ```
66
83
  */
67
84
  get stackTrail() {
68
- return __classPrivateFieldGet(this, _StackTrail_stack, "f");
85
+ return __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, asIs);
69
86
  }
70
87
  /**
71
88
  * Appends frame(s) to the end of the trail.
@@ -91,7 +108,7 @@ export class StackTrail {
91
108
  */
92
109
  append(frame) {
93
110
  if (typeof frame === 'string') {
94
- __classPrivateFieldGet(this, _StackTrail_stack, "f").push(frame);
111
+ __classPrivateFieldSet(this, _StackTrail_last, toTrailFrame(__classPrivateFieldGet(this, _StackTrail_last, "f"), frame), "f");
95
112
  return this;
96
113
  }
97
114
  if (Array.isArray(frame)) {
@@ -103,8 +120,13 @@ export class StackTrail {
103
120
  /**
104
121
  * Runs `fn` on a copy of the trail with `key` appended: one frame for a
105
122
  * string, one frame per element for an array.
123
+ *
124
+ * When `fn` returns, `key` is removed and must be the last frame. When
125
+ * `fn` throws, the copy goes back to the frames it started with and the
126
+ * error from `fn` is rethrown: a frame check there would replace it.
106
127
  */
107
128
  trace(key, fn) {
129
+ const start = __classPrivateFieldGet(this, _StackTrail_last, "f");
108
130
  const stackTrail = this.clone();
109
131
  stackTrail.append(key);
110
132
  try {
@@ -113,12 +135,13 @@ export class StackTrail {
113
135
  return result;
114
136
  }
115
137
  catch (error) {
116
- stackTrail.remove(key);
138
+ __classPrivateFieldSet(stackTrail, _StackTrail_last, start, "f");
117
139
  throw error;
118
140
  }
119
141
  }
120
142
  /** Async form of {@link trace}. */
121
143
  async traceAsync(key, fn) {
144
+ const start = __classPrivateFieldGet(this, _StackTrail_last, "f");
122
145
  const stackTrail = this.clone();
123
146
  stackTrail.append(key);
124
147
  try {
@@ -127,7 +150,7 @@ export class StackTrail {
127
150
  return result;
128
151
  }
129
152
  catch (error) {
130
- stackTrail.remove(key);
153
+ __classPrivateFieldSet(stackTrail, _StackTrail_last, start, "f");
131
154
  throw error;
132
155
  }
133
156
  }
@@ -179,7 +202,7 @@ export class StackTrail {
179
202
  * ```
180
203
  */
181
204
  toJsonPointer() {
182
- return toJsonPointer(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
205
+ return toJsonPointer(this.stackTrail);
183
206
  }
184
207
  /**
185
208
  * The **document-relative** JSON Pointer for a parsed node, with the
@@ -212,20 +235,20 @@ export class StackTrail {
212
235
  * ```
213
236
  */
214
237
  toSchemaPointer() {
215
- return toJsonPointer(toDocumentFrames(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
238
+ return toJsonPointer(__classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, asIs, __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_rootPhaseFrame).call(this)));
216
239
  }
217
240
  toStackRef() {
218
- const [first, second, third] = this.stackTrail;
219
- if (first !== 'components') {
220
- return;
221
- }
222
- if (typeof second !== 'string' || !componentsKeys.includes(second)) {
241
+ // Reads the first three frames only, without building the whole array.
242
+ const third = __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_frameAtDepth).call(this, 3);
243
+ const second = third?.parent;
244
+ const first = second?.parent;
245
+ if (third === undefined || second === undefined || first?.frame !== 'components') {
223
246
  return;
224
247
  }
225
- if (typeof third !== 'string') {
248
+ if (!componentsKeys.includes(second.frame)) {
226
249
  return;
227
250
  }
228
- return `#/${first}/${second}/${third}`;
251
+ return `#/${first.frame}/${second.frame}/${third.frame}`;
229
252
  }
230
253
  /**
231
254
  * Removes frame(s) from the end of the trail.
@@ -252,9 +275,12 @@ export class StackTrail {
252
275
  */
253
276
  remove(frame) {
254
277
  if (typeof frame === 'string') {
255
- const lastItem = __classPrivateFieldGet(this, _StackTrail_stack, "f").pop();
256
- if (lastItem !== frame) {
257
- throw new Error(`Expected to remove frame '${frame}' but found '${lastItem}'`);
278
+ const last = __classPrivateFieldGet(this, _StackTrail_last, "f");
279
+ // The last frame leaves the trail whether or not it matches, as
280
+ // `Array.pop` did before the check.
281
+ __classPrivateFieldSet(this, _StackTrail_last, last?.parent, "f");
282
+ if (last?.frame !== frame) {
283
+ throw new Error(`Expected to remove frame '${frame}' but found '${last?.frame}'`);
258
284
  }
259
285
  return this;
260
286
  }
@@ -298,7 +324,7 @@ export class StackTrail {
298
324
  * ```
299
325
  */
300
326
  toString() {
301
- return toTrailString(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
327
+ return __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, escapeTrailFrame).join(':');
302
328
  }
303
329
  /**
304
330
  * Reads a string written by {@link StackTrail.toString} back into a trail.
@@ -320,5 +346,27 @@ export class StackTrail {
320
346
  return new StackTrail(value.split(':').map(frame => frame.replace(/%(25|3A)/g, (_, code) => decodes[code])));
321
347
  }
322
348
  }
323
- _StackTrail_stack = new WeakMap();
349
+ _StackTrail_last = new WeakMap(), _StackTrail_instances = new WeakSet(), _StackTrail_mapFrames = function _StackTrail_mapFrames(fn, above) {
350
+ // Pushed and then reversed, so the array stays packed. An array made
351
+ // with `new Array(n)` stays holey in V8 after it is filled.
352
+ const frames = [];
353
+ for (let node = __classPrivateFieldGet(this, _StackTrail_last, "f"); node !== undefined && node !== above; node = node.parent) {
354
+ frames.push(fn(node.frame));
355
+ }
356
+ return frames.reverse();
357
+ }, _StackTrail_rootPhaseFrame = function _StackTrail_rootPhaseFrame() {
358
+ let found;
359
+ for (let node = __classPrivateFieldGet(this, _StackTrail_last, "f"); node !== undefined; node = node.parent) {
360
+ if (isPhaseFrame(node.frame)) {
361
+ found = node;
362
+ }
363
+ }
364
+ return found;
365
+ }, _StackTrail_frameAtDepth = function _StackTrail_frameAtDepth(depth) {
366
+ let node = __classPrivateFieldGet(this, _StackTrail_last, "f");
367
+ while (node !== undefined && node.depth > depth) {
368
+ node = node.parent;
369
+ }
370
+ return node?.depth === depth ? node : undefined;
371
+ };
324
372
  const decodes = { '25': '%', '3A': ':' };
@@ -1,10 +1,14 @@
1
+ /** Escapes `%` as `%25` and `:` as `%3A` inside one trail frame. */
2
+ export declare const escapeTrailFrame: (frame: string) => string;
3
+ /** True for a phase frame that `CoreContext.toArtifacts` seeds. */
4
+ export declare const isPhaseFrame: (frame: string) => boolean;
1
5
  /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
2
- export declare const toTrailString: (frames: string[]) => string;
6
+ export declare const toTrailString: (frames: readonly string[]) => string;
3
7
  /**
4
8
  * The frames of a trail that address the input document: everything after
5
9
  * the first phase frame, or every frame when there is no phase frame.
6
10
  */
7
- export declare const toDocumentFrames: (frames: string[]) => string[];
11
+ export declare const toDocumentFrames: (frames: readonly string[]) => readonly string[];
8
12
  /**
9
13
  * The document-relative trail in `StackTrail.toString` form.
10
14
  *
@@ -14,4 +18,4 @@ export declare const toDocumentFrames: (frames: string[]) => string[];
14
18
  * // 'paths:/pets:parameters:0'
15
19
  * ```
16
20
  */
17
- export declare const toDocumentString: (frames: string[]) => string;
21
+ export declare const toDocumentString: (frames: readonly string[]) => string;
@@ -2,8 +2,12 @@ const escapes = { '%': '%25', ':': '%3A' };
2
2
  // Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
3
3
  // `post-pass` trace).
4
4
  const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
5
+ /** Escapes `%` as `%25` and `:` as `%3A` inside one trail frame. */
6
+ export const escapeTrailFrame = (frame) => frame.replace(/[%:]/g, character => escapes[character]);
7
+ /** True for a phase frame that `CoreContext.toArtifacts` seeds. */
8
+ export const isPhaseFrame = (frame) => phaseFrames.has(frame);
5
9
  /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
6
- export const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
10
+ export const toTrailString = (frames) => frames.map(escapeTrailFrame).join(':');
7
11
  /**
8
12
  * The frames of a trail that address the input document: everything after
9
13
  * the first phase frame, or every frame when there is no phase frame.
@@ -13,7 +17,7 @@ export const toDocumentFrames = (frames) => {
13
17
  // FIRST match is the boundary — a document key that happens to share a
14
18
  // phase name (e.g. a schema literally named `parse`) appears later and
15
19
  // is unaffected.
16
- const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
20
+ const phaseIndex = frames.findIndex(isPhaseFrame);
17
21
  return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
18
22
  };
19
23
  /**
@@ -28,6 +28,8 @@ import type { GqlOperationProjection } from '../dsl/operation/gql/types.js';
28
28
  import type { GqlOperation } from '../gql/operation/GqlOperation.js';
29
29
  import type { SkmtcParsedDocument } from '../types/SkmtcDocument.js';
30
30
  import type { AttributionState } from '../types/AttributionState.js';
31
+ import type { Logger } from '../types/Logger.js';
32
+ import type { LogLine } from '../types/LogLine.js';
31
33
  import type { EnrichmentWarning } from '../enrichments/EnrichmentWarning.js';
32
34
  import type { CaptureSink } from '../anchors/CaptureSink.js';
33
35
  import type { Sidecar } from '../anchors/sidecar.js';
@@ -143,6 +145,13 @@ export type ToArtifactsResult = RenderResult & {
143
145
  * the VS Code debugger views.
144
146
  */
145
147
  inspection?: unknown;
148
+ /**
149
+ * The lines the run's logger received at or above the `logLevel`
150
+ * `toArtifacts` was called with (`'WARN'` by default), in order. A
151
+ * line logged while a subject was generated carries the subject's
152
+ * trail, which is also its key in `results`.
153
+ */
154
+ logs: LogLine[];
146
155
  };
147
156
  /**
148
157
  * Union type representing any supported OpenAPI document version.
@@ -166,8 +175,12 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
166
175
  * body, and its keys include a range: `application/*`, or `*\/*` with a
167
176
  * scalar schema (a text body or a file). A body with only specific
168
177
  * non-JSON types (`multipart/form-data`, `text/plain`) logs nothing.
178
+ *
179
+ * `RUN_FAILED` (`error`) — the run itself failed outside the per-item
180
+ * catches. Its `location` names the entry and phase, for example
181
+ * `toArtifacts:render`.
169
182
  */
170
- export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
183
+ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE' | 'RUN_FAILED';
171
184
  /**
172
185
  * Valibot schema for {@link OasIssueType}. Annotation deliberately omitted
173
186
  * so the precise literal-union output type flows through to consumers
@@ -175,7 +188,7 @@ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISS
175
188
  * this list and {@link OasIssueType} is caught by `assertSchemaMatchesType`
176
189
  * below.
177
190
  */
178
- export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
191
+ export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>, v.LiteralSchema<"RUN_FAILED", undefined>], undefined>;
179
192
  export type GenerateResult = {
180
193
  files: Map<string, FileBase>;
181
194
  previews: Record<string, Preview>;
@@ -396,6 +409,12 @@ export type ToWebhookSettingsArgs<V extends GeneratedValue, EnrichmentType = und
396
409
  export type InsertNormalizedModelReturn<V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid> = Schema extends OasRef<'schema'> ? DefinitionBase<V> : DefinitionBase<TypeSystemOutput<SchemaToNonRef<Schema>['type']>>;
397
410
  export type GenerateContextType = {
398
411
  settings: ClientSettings | undefined;
412
+ /**
413
+ * The run's logger. A line logged inside a transform carries the
414
+ * subject's stack trail, and a `warn` or `error` line sets the
415
+ * subject's result to `'warning'` or `'error'`.
416
+ */
417
+ logger: Logger;
399
418
  modelDepth: Record<string, number>;
400
419
  document: SkmtcParsedDocument;
401
420
  /**
@@ -35,7 +35,8 @@ export const oasIssueType = v.union([
35
35
  v.literal('INVALID_EXTERNAL_DOCS'),
36
36
  v.literal('UNSUPPORTED_OPERATION_METHOD'),
37
37
  v.literal('WILDCARD_MEDIA_TYPE'),
38
- v.literal('NO_JSON_MEDIA_TYPE')
38
+ v.literal('NO_JSON_MEDIA_TYPE'),
39
+ v.literal('RUN_FAILED')
39
40
  ]);
40
41
  // Compile-time drift detector: this binding fails to type-check if
41
42
  // `OasIssueType` and the literal list above disagree in either
@@ -24,8 +24,8 @@ export declare class ResultsLog {
24
24
  * Captures `result` at `stackTrail`, unless a more severe result is
25
25
  * already recorded there.
26
26
  *
27
- * Stores a copy of the frames: `StackTrail.trace` pops the live array
28
- * after its callback returns.
27
+ * Stores the frames as they are now: `StackTrail.trace` removes its
28
+ * frame from the trail after its callback returns.
29
29
  */
30
30
  capture(stackTrail: StackTrail, result: ResultType): void;
31
31
  /**
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _ResultsLog_instances, _ResultsLog_results, _ResultsLog_incomingResultIsWorse;
13
+ import { toTrailString } from '../context/documentTrail.js';
13
14
  /**
14
15
  * Records one result per stack trail and builds the `manifest.results` tree.
15
16
  *
@@ -41,13 +42,15 @@ export class ResultsLog {
41
42
  * Captures `result` at `stackTrail`, unless a more severe result is
42
43
  * already recorded there.
43
44
  *
44
- * Stores a copy of the frames: `StackTrail.trace` pops the live array
45
- * after its callback returns.
45
+ * Stores the frames as they are now: `StackTrail.trace` removes its
46
+ * frame from the trail after its callback returns.
46
47
  */
47
48
  capture(stackTrail, result) {
48
- const key = stackTrail.toString();
49
+ // `stackTrail` builds a new array on each read, so read it once.
50
+ const frames = stackTrail.stackTrail;
51
+ const key = toTrailString(frames);
49
52
  if (__classPrivateFieldGet(this, _ResultsLog_instances, "m", _ResultsLog_incomingResultIsWorse).call(this, __classPrivateFieldGet(this, _ResultsLog_results, "f").get(key)?.result, result)) {
50
- __classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames: [...stackTrail.stackTrail], result });
53
+ __classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames, result });
51
54
  }
52
55
  }
53
56
  /**
package/esm/mod.d.ts CHANGED
@@ -204,6 +204,8 @@ export * from './types/Modifiers.js';
204
204
  export * from './types/ModuleExport.js';
205
205
  export * from './types/ModuleSelect.js';
206
206
  export * from './types/SchemaPath.js';
207
+ export * from './types/SerializedError.js';
208
+ export * from './types/LogLine.js';
207
209
  export * from './enrichments/toEnrichmentDescriptor.js';
208
210
  export * from './enrichments/validateConfig.js';
209
211
  export * from './enrichments/readEnrichments.js';
package/esm/mod.js CHANGED
@@ -202,6 +202,8 @@ export * from './types/Modifiers.js';
202
202
  export * from './types/ModuleExport.js';
203
203
  export * from './types/ModuleSelect.js';
204
204
  export * from './types/SchemaPath.js';
205
+ export * from './types/SerializedError.js';
206
+ export * from './types/LogLine.js';
205
207
  export * from './enrichments/toEnrichmentDescriptor.js';
206
208
  export * from './enrichments/validateConfig.js';
207
209
  export * from './enrichments/readEnrichments.js';
@@ -6,6 +6,7 @@ import type { SkmtcDocumentInput } from '../types/SkmtcDocument.js';
6
6
  import type { AttributionState } from '../types/AttributionState.js';
7
7
  import type { Sidecar } from '../anchors/sidecar.js';
8
8
  import type { GenerationMapEntry } from '../anchors/generationMap.js';
9
+ import type { LogLine, LogLineLevel } from '../types/LogLine.js';
9
10
  /**
10
11
  * Arguments for the {@link toArtifacts} transformation function.
11
12
  *
@@ -49,6 +50,11 @@ type TransformArgs = {
49
50
  startAt: number;
50
51
  /** Whether to suppress console output during generation */
51
52
  silent: boolean;
53
+ /**
54
+ * The lowest level kept in the returned `logs`. Defaults to `'WARN'`,
55
+ * so `DEBUG` and `INFO` lines are left out unless asked for.
56
+ */
57
+ logLevel?: LogLineLevel;
52
58
  /**
53
59
  * Optional attribution (gen-maps) state. When set with a
54
60
  * `postPass` block, the pipeline emits sidecars + a generation-map index
@@ -130,9 +136,11 @@ type TransformArgs = {
130
136
  * }
131
137
  * ```
132
138
  */
133
- export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }: TransformArgs) => {
139
+ export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }: TransformArgs) => {
134
140
  artifacts: Record<string, string>;
135
141
  manifest: ManifestContent;
142
+ /** The run's log lines (see {@link LogLine}). Not part of the manifest. */
143
+ logs: LogLine[];
136
144
  sidecars?: Record<string, Sidecar>;
137
145
  generationMap?: GenerationMapEntry[];
138
146
  inspection?: unknown;
@@ -67,9 +67,9 @@ import { CoreContext } from '../context/CoreContext.js';
67
67
  * }
68
68
  * ```
69
69
  */
70
- export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }) => {
71
- const context = new CoreContext({ spanId, logsPath, silent });
72
- const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection } = context.toArtifacts({
70
+ export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }) => {
71
+ const context = new CoreContext({ spanId, logsPath, silent, logLevel });
72
+ const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection, logs } = context.toArtifacts({
73
73
  settings,
74
74
  toGeneratorConfigMap,
75
75
  document,
@@ -91,5 +91,5 @@ export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorCo
91
91
  startAt,
92
92
  endAt: Date.now()
93
93
  };
94
- return { artifacts, manifest, sidecars, generationMap, inspection };
94
+ return { artifacts, manifest, logs, sidecars, generationMap, inspection };
95
95
  };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One structured log line that `toArtifacts` returns in `logs`.
3
+ *
4
+ * A line logged while a subject is generated carries the subject's stack
5
+ * trail in `trail`. That is the same string `manifest.results` is keyed
6
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
7
+ *
8
+ * @module LogLine
9
+ */
10
+ import * as v from 'valibot';
11
+ import { type SerializedError } from './SerializedError.js';
12
+ /** The level of a {@link LogLine}. A `CRITICAL` record is recorded as `'ERROR'`. */
13
+ export type LogLineLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
14
+ /** Valibot schema for {@link LogLineLevel}. */
15
+ export declare const logLineLevel: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
16
+ export type LogLine = {
17
+ /** Position of the line in the run, from 0. */
18
+ seq: number;
19
+ level: LogLineLevel;
20
+ /** The subject's stack trail. Absent outside a subject (parse, render). */
21
+ trail?: string;
22
+ message: string;
23
+ /** The first `Error` the line was logged with. */
24
+ error?: SerializedError;
25
+ /** When the line was logged, in milliseconds since the epoch. */
26
+ time: number;
27
+ };
28
+ /** Valibot schema for {@link LogLine}. */
29
+ export declare const logLine: v.ObjectSchema<{
30
+ readonly seq: v.NumberSchema<undefined>;
31
+ readonly level: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
32
+ readonly trail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
33
+ readonly message: v.StringSchema<undefined>;
34
+ readonly error: v.OptionalSchema<v.GenericSchema<SerializedError>, undefined>;
35
+ readonly time: v.NumberSchema<undefined>;
36
+ }, undefined>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * One structured log line that `toArtifacts` returns in `logs`.
3
+ *
4
+ * A line logged while a subject is generated carries the subject's stack
5
+ * trail in `trail`. That is the same string `manifest.results` is keyed
6
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
7
+ *
8
+ * @module LogLine
9
+ */
10
+ import * as v from 'valibot';
11
+ import { serializedError } from './SerializedError.js';
12
+ /** Valibot schema for {@link LogLineLevel}. */
13
+ export const logLineLevel = v.picklist(['DEBUG', 'INFO', 'WARN', 'ERROR']);
14
+ const _logLineLevelDriftCheck = logLineLevel;
15
+ void _logLineLevelDriftCheck;
16
+ /** Valibot schema for {@link LogLine}. */
17
+ export const logLine = v.object({
18
+ seq: v.number(),
19
+ level: logLineLevel,
20
+ trail: v.optional(v.string()),
21
+ message: v.string(),
22
+ error: v.optional(serializedError),
23
+ time: v.number()
24
+ });
25
+ const _logLineDriftCheck = logLine;
26
+ void _logLineDriftCheck;
@@ -121,4 +121,4 @@ export type ManifestContent = {
121
121
  startAt: number;
122
122
  endAt: number;
123
123
  };
124
- export declare const manifestContent: v.GenericSchema<ManifestContent>;
124
+ export declare const manifestContent: v.GenericSchema<unknown, ManifestContent>;