@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
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  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
- const StackTrail_js_1 = require("./StackTrail.js");
13
12
  class ResultsHandler extends base_handler_js_1.BaseHandler {
14
13
  /**
15
14
  * Creates a new ResultsHandler instance.
@@ -90,10 +89,11 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
90
89
  /**
91
90
  * Captures log messages as results in the context.
92
91
  *
93
- * Converts log level names to result types and captures them
94
- * in the associated CoreContext for later analysis.
92
+ * Converts log level names to result types and captures them in the
93
+ * associated CoreContext at the trail of the subject being generated.
94
+ * A line logged outside a subject records nothing.
95
95
  *
96
- * @param levelName - The log level name ('WARN' or 'ERROR')
96
+ * @param levelName - The log level name ('WARN', 'ERROR' or 'CRITICAL')
97
97
  *
98
98
  * @throws {Error} When an unsupported log level is provided
99
99
  *
@@ -102,6 +102,7 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
102
102
  * // This is called automatically by the logging system
103
103
  * handler.log('WARN'); // Captures as 'warning' result
104
104
  * handler.log('ERROR'); // Captures as 'error' result
105
+ * handler.log('CRITICAL'); // Captures as 'error' result
105
106
  * ```
106
107
  */
107
108
  log(levelName) {
@@ -111,12 +112,17 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
111
112
  resultType = 'warning';
112
113
  break;
113
114
  case 'ERROR':
115
+ case 'CRITICAL':
114
116
  resultType = 'error';
115
117
  break;
116
118
  default:
117
119
  throw new Error(`Unexpected log level name: ${levelName}`);
118
120
  }
119
- this.context.captureCurrentResult(resultType, new StackTrail_js_1.StackTrail(['SKIPPED']));
121
+ // Outside a subject there is no result to record against.
122
+ const subjectTrail = this.context.currentSubjectTrail;
123
+ if (subjectTrail !== undefined) {
124
+ this.context.captureCurrentResult(resultType, subjectTrail);
125
+ }
120
126
  }
121
127
  /**
122
128
  * 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}. */
@@ -10,18 +10,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _StackTrail_stack;
13
+ var _StackTrail_instances, _StackTrail_last, _StackTrail_mapFrames, _StackTrail_rootPhaseFrame, _StackTrail_frameAtDepth;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.StackTrail = void 0;
16
16
  require("../_dnt.polyfills.js");
17
17
  const Components_js_1 = require("../oas/components/Components.js");
18
18
  const JsonPointer_js_1 = require("../types/JsonPointer.js");
19
19
  const documentTrail_js_1 = require("./documentTrail.js");
20
+ const toTrailFrame = (parent, frame) => ({
21
+ frame,
22
+ parent,
23
+ depth: (parent?.depth ?? 0) + 1
24
+ });
25
+ const asIs = (frame) => frame;
20
26
  class StackTrail {
21
27
  constructor(stack = []) {
22
- /** Internal stack of traversal frames */
23
- _StackTrail_stack.set(this, void 0);
24
- __classPrivateFieldSet(this, _StackTrail_stack, stack, "f");
28
+ _StackTrail_instances.add(this);
29
+ /**
30
+ * Last frame of the trail; `undefined` for the empty trail. A parsed
31
+ * document holds one trail per node, so the frames are a shared linked
32
+ * list and not one array per trail.
33
+ */
34
+ _StackTrail_last.set(this, void 0);
35
+ __classPrivateFieldSet(this, _StackTrail_last, stack.reduce(toTrailFrame, undefined), "f");
25
36
  }
26
37
  /**
27
38
  * The canonical empty trail — used for nodes that were synthesized
@@ -34,12 +45,13 @@ class StackTrail {
34
45
  }
35
46
  /** True when the trail holds no frames (a synthetic / positionless node). */
36
47
  isEmpty() {
37
- return __classPrivateFieldGet(this, _StackTrail_stack, "f").length === 0;
48
+ return __classPrivateFieldGet(this, _StackTrail_last, "f") === undefined;
38
49
  }
39
50
  /**
40
- * Creates a shallow copy of the stack trail.
51
+ * Creates an independent trail with the same frames. The frames are
52
+ * shared, not copied.
41
53
  *
42
- * @returns A new StackTrail instance with copied frames
54
+ * @returns A new StackTrail instance with the same frames
43
55
  *
44
56
  * @example
45
57
  * ```typescript
@@ -52,11 +64,16 @@ class StackTrail {
52
64
  * ```
53
65
  */
54
66
  clone() {
55
- return new StackTrail([...__classPrivateFieldGet(this, _StackTrail_stack, "f")]);
67
+ const copy = new StackTrail();
68
+ __classPrivateFieldSet(copy, _StackTrail_last, __classPrivateFieldGet(this, _StackTrail_last, "f"), "f");
69
+ return copy;
56
70
  }
57
71
  /**
58
- * The live array of stack frames, not a copy: {@link trace} pops it after
59
- * `fn` returns. Copy it (`[...trail.stackTrail]`) to keep the frames.
72
+ * The frames of the trail as a new read-only array, built on each read.
73
+ * Change the trail with {@link append}, {@link remove} or {@link trace},
74
+ * not through this array. The trail itself is live: {@link trace}
75
+ * removes its frame after `fn` returns, so read the frames inside `fn`
76
+ * to keep them.
60
77
  *
61
78
  * @returns Array of stack frames in order
62
79
  *
@@ -68,7 +85,7 @@ class StackTrail {
68
85
  * ```
69
86
  */
70
87
  get stackTrail() {
71
- return __classPrivateFieldGet(this, _StackTrail_stack, "f");
88
+ return __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, asIs);
72
89
  }
73
90
  /**
74
91
  * Appends frame(s) to the end of the trail.
@@ -94,7 +111,7 @@ class StackTrail {
94
111
  */
95
112
  append(frame) {
96
113
  if (typeof frame === 'string') {
97
- __classPrivateFieldGet(this, _StackTrail_stack, "f").push(frame);
114
+ __classPrivateFieldSet(this, _StackTrail_last, toTrailFrame(__classPrivateFieldGet(this, _StackTrail_last, "f"), frame), "f");
98
115
  return this;
99
116
  }
100
117
  if (Array.isArray(frame)) {
@@ -106,8 +123,13 @@ class StackTrail {
106
123
  /**
107
124
  * Runs `fn` on a copy of the trail with `key` appended: one frame for a
108
125
  * string, one frame per element for an array.
126
+ *
127
+ * When `fn` returns, `key` is removed and must be the last frame. When
128
+ * `fn` throws, the copy goes back to the frames it started with and the
129
+ * error from `fn` is rethrown: a frame check there would replace it.
109
130
  */
110
131
  trace(key, fn) {
132
+ const start = __classPrivateFieldGet(this, _StackTrail_last, "f");
111
133
  const stackTrail = this.clone();
112
134
  stackTrail.append(key);
113
135
  try {
@@ -116,12 +138,13 @@ class StackTrail {
116
138
  return result;
117
139
  }
118
140
  catch (error) {
119
- stackTrail.remove(key);
141
+ __classPrivateFieldSet(stackTrail, _StackTrail_last, start, "f");
120
142
  throw error;
121
143
  }
122
144
  }
123
145
  /** Async form of {@link trace}. */
124
146
  async traceAsync(key, fn) {
147
+ const start = __classPrivateFieldGet(this, _StackTrail_last, "f");
125
148
  const stackTrail = this.clone();
126
149
  stackTrail.append(key);
127
150
  try {
@@ -130,7 +153,7 @@ class StackTrail {
130
153
  return result;
131
154
  }
132
155
  catch (error) {
133
- stackTrail.remove(key);
156
+ __classPrivateFieldSet(stackTrail, _StackTrail_last, start, "f");
134
157
  throw error;
135
158
  }
136
159
  }
@@ -182,7 +205,7 @@ class StackTrail {
182
205
  * ```
183
206
  */
184
207
  toJsonPointer() {
185
- return (0, JsonPointer_js_1.toJsonPointer)(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
208
+ return (0, JsonPointer_js_1.toJsonPointer)(this.stackTrail);
186
209
  }
187
210
  /**
188
211
  * The **document-relative** JSON Pointer for a parsed node, with the
@@ -215,20 +238,20 @@ class StackTrail {
215
238
  * ```
216
239
  */
217
240
  toSchemaPointer() {
218
- return (0, JsonPointer_js_1.toJsonPointer)((0, documentTrail_js_1.toDocumentFrames)(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
241
+ return (0, JsonPointer_js_1.toJsonPointer)(__classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, asIs, __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_rootPhaseFrame).call(this)));
219
242
  }
220
243
  toStackRef() {
221
- const [first, second, third] = this.stackTrail;
222
- if (first !== 'components') {
223
- return;
224
- }
225
- if (typeof second !== 'string' || !Components_js_1.componentsKeys.includes(second)) {
244
+ // Reads the first three frames only, without building the whole array.
245
+ const third = __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_frameAtDepth).call(this, 3);
246
+ const second = third?.parent;
247
+ const first = second?.parent;
248
+ if (third === undefined || second === undefined || first?.frame !== 'components') {
226
249
  return;
227
250
  }
228
- if (typeof third !== 'string') {
251
+ if (!Components_js_1.componentsKeys.includes(second.frame)) {
229
252
  return;
230
253
  }
231
- return `#/${first}/${second}/${third}`;
254
+ return `#/${first.frame}/${second.frame}/${third.frame}`;
232
255
  }
233
256
  /**
234
257
  * Removes frame(s) from the end of the trail.
@@ -255,9 +278,12 @@ class StackTrail {
255
278
  */
256
279
  remove(frame) {
257
280
  if (typeof frame === 'string') {
258
- const lastItem = __classPrivateFieldGet(this, _StackTrail_stack, "f").pop();
259
- if (lastItem !== frame) {
260
- throw new Error(`Expected to remove frame '${frame}' but found '${lastItem}'`);
281
+ const last = __classPrivateFieldGet(this, _StackTrail_last, "f");
282
+ // The last frame leaves the trail whether or not it matches, as
283
+ // `Array.pop` did before the check.
284
+ __classPrivateFieldSet(this, _StackTrail_last, last?.parent, "f");
285
+ if (last?.frame !== frame) {
286
+ throw new Error(`Expected to remove frame '${frame}' but found '${last?.frame}'`);
261
287
  }
262
288
  return this;
263
289
  }
@@ -301,7 +327,7 @@ class StackTrail {
301
327
  * ```
302
328
  */
303
329
  toString() {
304
- return (0, documentTrail_js_1.toTrailString)(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
330
+ return __classPrivateFieldGet(this, _StackTrail_instances, "m", _StackTrail_mapFrames).call(this, documentTrail_js_1.escapeTrailFrame).join(':');
305
331
  }
306
332
  /**
307
333
  * Reads a string written by {@link StackTrail.toString} back into a trail.
@@ -324,5 +350,27 @@ class StackTrail {
324
350
  }
325
351
  }
326
352
  exports.StackTrail = StackTrail;
327
- _StackTrail_stack = new WeakMap();
353
+ _StackTrail_last = new WeakMap(), _StackTrail_instances = new WeakSet(), _StackTrail_mapFrames = function _StackTrail_mapFrames(fn, above) {
354
+ // Pushed and then reversed, so the array stays packed. An array made
355
+ // with `new Array(n)` stays holey in V8 after it is filled.
356
+ const frames = [];
357
+ for (let node = __classPrivateFieldGet(this, _StackTrail_last, "f"); node !== undefined && node !== above; node = node.parent) {
358
+ frames.push(fn(node.frame));
359
+ }
360
+ return frames.reverse();
361
+ }, _StackTrail_rootPhaseFrame = function _StackTrail_rootPhaseFrame() {
362
+ let found;
363
+ for (let node = __classPrivateFieldGet(this, _StackTrail_last, "f"); node !== undefined; node = node.parent) {
364
+ if ((0, documentTrail_js_1.isPhaseFrame)(node.frame)) {
365
+ found = node;
366
+ }
367
+ }
368
+ return found;
369
+ }, _StackTrail_frameAtDepth = function _StackTrail_frameAtDepth(depth) {
370
+ let node = __classPrivateFieldGet(this, _StackTrail_last, "f");
371
+ while (node !== undefined && node.depth > depth) {
372
+ node = node.parent;
373
+ }
374
+ return node?.depth === depth ? node : undefined;
375
+ };
328
376
  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;
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toDocumentString = exports.toDocumentFrames = exports.toTrailString = void 0;
3
+ exports.toDocumentString = exports.toDocumentFrames = exports.toTrailString = exports.isPhaseFrame = exports.escapeTrailFrame = void 0;
4
4
  const escapes = { '%': '%25', ':': '%3A' };
5
5
  // Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
6
6
  // `post-pass` trace).
7
7
  const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
8
+ /** Escapes `%` as `%25` and `:` as `%3A` inside one trail frame. */
9
+ const escapeTrailFrame = (frame) => frame.replace(/[%:]/g, character => escapes[character]);
10
+ exports.escapeTrailFrame = escapeTrailFrame;
11
+ /** True for a phase frame that `CoreContext.toArtifacts` seeds. */
12
+ const isPhaseFrame = (frame) => phaseFrames.has(frame);
13
+ exports.isPhaseFrame = isPhaseFrame;
8
14
  /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
9
- const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
15
+ const toTrailString = (frames) => frames.map(exports.escapeTrailFrame).join(':');
10
16
  exports.toTrailString = toTrailString;
11
17
  /**
12
18
  * The frames of a trail that address the input document: everything after
@@ -17,7 +23,7 @@ const toDocumentFrames = (frames) => {
17
23
  // FIRST match is the boundary — a document key that happens to share a
18
24
  // phase name (e.g. a schema literally named `parse`) appears later and
19
25
  // is unaffected.
20
- const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
26
+ const phaseIndex = frames.findIndex(exports.isPhaseFrame);
21
27
  return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
22
28
  };
23
29
  exports.toDocumentFrames = toDocumentFrames;
@@ -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
  /**
@@ -71,7 +71,8 @@ exports.oasIssueType = v.union([
71
71
  v.literal('INVALID_EXTERNAL_DOCS'),
72
72
  v.literal('UNSUPPORTED_OPERATION_METHOD'),
73
73
  v.literal('WILDCARD_MEDIA_TYPE'),
74
- v.literal('NO_JSON_MEDIA_TYPE')
74
+ v.literal('NO_JSON_MEDIA_TYPE'),
75
+ v.literal('RUN_FAILED')
75
76
  ]);
76
77
  // Compile-time drift detector: this binding fails to type-check if
77
78
  // `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
  /**
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _ResultsLog_instances, _ResultsLog_results, _ResultsLog_incomingResultIsWorse;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ResultsLog = void 0;
16
+ const documentTrail_js_1 = require("../context/documentTrail.js");
16
17
  /**
17
18
  * Records one result per stack trail and builds the `manifest.results` tree.
18
19
  *
@@ -44,13 +45,15 @@ class ResultsLog {
44
45
  * Captures `result` at `stackTrail`, unless a more severe result is
45
46
  * already recorded there.
46
47
  *
47
- * Stores a copy of the frames: `StackTrail.trace` pops the live array
48
- * after its callback returns.
48
+ * Stores the frames as they are now: `StackTrail.trace` removes its
49
+ * frame from the trail after its callback returns.
49
50
  */
50
51
  capture(stackTrail, result) {
51
- const key = stackTrail.toString();
52
+ // `stackTrail` builds a new array on each read, so read it once.
53
+ const frames = stackTrail.stackTrail;
54
+ const key = (0, documentTrail_js_1.toTrailString)(frames);
52
55
  if (__classPrivateFieldGet(this, _ResultsLog_instances, "m", _ResultsLog_incomingResultIsWorse).call(this, __classPrivateFieldGet(this, _ResultsLog_results, "f").get(key)?.result, result)) {
53
- __classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames: [...stackTrail.stackTrail], result });
56
+ __classPrivateFieldGet(this, _ResultsLog_results, "f").set(key, { frames, result });
54
57
  }
55
58
  }
56
59
  /**
package/script/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/script/mod.js CHANGED
@@ -218,6 +218,8 @@ __exportStar(require("./types/Modifiers.js"), exports);
218
218
  __exportStar(require("./types/ModuleExport.js"), exports);
219
219
  __exportStar(require("./types/ModuleSelect.js"), exports);
220
220
  __exportStar(require("./types/SchemaPath.js"), exports);
221
+ __exportStar(require("./types/SerializedError.js"), exports);
222
+ __exportStar(require("./types/LogLine.js"), exports);
221
223
  __exportStar(require("./enrichments/toEnrichmentDescriptor.js"), exports);
222
224
  __exportStar(require("./enrichments/validateConfig.js"), exports);
223
225
  __exportStar(require("./enrichments/readEnrichments.js"), exports);
@@ -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;
@@ -70,9 +70,9 @@ const CoreContext_js_1 = require("../context/CoreContext.js");
70
70
  * }
71
71
  * ```
72
72
  */
73
- const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }) => {
74
- const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent });
75
- const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection } = context.toArtifacts({
73
+ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }) => {
74
+ const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent, logLevel });
75
+ const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection, logs } = context.toArtifacts({
76
76
  settings,
77
77
  toGeneratorConfigMap,
78
78
  document,
@@ -94,6 +94,6 @@ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap
94
94
  startAt,
95
95
  endAt: Date.now()
96
96
  };
97
- return { artifacts, manifest, sidecars, generationMap, inspection };
97
+ return { artifacts, manifest, logs, sidecars, generationMap, inspection };
98
98
  };
99
99
  exports.toArtifacts = toArtifacts;
@@ -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>;