@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
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_previews, _GenerateContext_captureChannel, _GenerateContext_enrichmentAudit, _GenerateContext_reportSkippedEnrichment, _GenerateContext_schemaRefNames, _GenerateContext_subjectDefaults, _GenerateContext_runOasOperationGenerator, _GenerateContext_runWebhookGenerator, _GenerateContext_runGqlOperationGenerator, _GenerateContext_runModelGenerator, _GenerateContext_addPreview, _GenerateContext_toContentSettingsExportPath, _GenerateContext_ejectedBySuffixedPath_get, _GenerateContext_ejectedBySuffixedPathCache, _GenerateContext_findContainer, _GenerateContext_toContainer;
16
+ var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_previews, _GenerateContext_captureChannel, _GenerateContext_enrichmentAudit, _GenerateContext_currentSubjectTrail, _GenerateContext_reportSkippedEnrichment, _GenerateContext_logError, _GenerateContext_schemaRefNames, _GenerateContext_subjectDefaults, _GenerateContext_runOasOperationGenerator, _GenerateContext_runWebhookGenerator, _GenerateContext_runGqlOperationGenerator, _GenerateContext_runModelGenerator, _GenerateContext_addPreview, _GenerateContext_toContentSettingsExportPath, _GenerateContext_ejectedBySuffixedPath_get, _GenerateContext_ejectedBySuffixedPathCache, _GenerateContext_findContainer, _GenerateContext_toContainer;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource = exports.toOasOperationSource = exports.GenerateContext = void 0;
19
19
  const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
@@ -35,6 +35,7 @@ const JsonFile_js_1 = require("../dsl/JsonFile.js");
35
35
  const MarkdownFile_js_1 = require("../dsl/MarkdownFile.js");
36
36
  const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
37
37
  const EnrichmentAudit_js_1 = require("../enrichments/EnrichmentAudit.js");
38
+ const SerializedError_js_1 = require("../types/SerializedError.js");
38
39
  const EnrichmentWarning_js_1 = require("../enrichments/EnrichmentWarning.js");
39
40
  /**
40
41
  * The generation context for the second phase of the SKMTC transformation pipeline.
@@ -147,6 +148,8 @@ class GenerateContext {
147
148
  * `enrichmentWarnings` at the end of {@link toArtifacts}.
148
149
  */
149
150
  _GenerateContext_enrichmentAudit.set(this, void 0);
151
+ /** See {@link currentSubjectTrail}. */
152
+ _GenerateContext_currentSubjectTrail.set(this, void 0);
150
153
  _GenerateContext_ejectedBySuffixedPathCache.set(this, void 0);
151
154
  this.logger = logger;
152
155
  __classPrivateFieldSet(this, _GenerateContext_files, new Map(), "f");
@@ -189,6 +192,28 @@ class GenerateContext {
189
192
  get captureSink() {
190
193
  return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
191
194
  }
195
+ /**
196
+ * The trail of the subject whose variant is being generated, or
197
+ * `undefined` outside one. Log lines and the results the logger
198
+ * records are addressed by it.
199
+ */
200
+ get currentSubjectTrail() {
201
+ return __classPrivateFieldGet(this, _GenerateContext_currentSubjectTrail, "f");
202
+ }
203
+ /**
204
+ * Runs `fn` with {@link currentSubjectTrail} set to `stackTrail`, and
205
+ * restores the previous value afterwards.
206
+ */
207
+ withSubjectTrail(stackTrail, fn) {
208
+ const previous = __classPrivateFieldGet(this, _GenerateContext_currentSubjectTrail, "f");
209
+ __classPrivateFieldSet(this, _GenerateContext_currentSubjectTrail, stackTrail, "f");
210
+ try {
211
+ return fn();
212
+ }
213
+ finally {
214
+ __classPrivateFieldSet(this, _GenerateContext_currentSubjectTrail, previous, "f");
215
+ }
216
+ }
192
217
  /**
193
218
  * @internal
194
219
  */
@@ -835,7 +860,7 @@ class GenerateContext {
835
860
  }
836
861
  }
837
862
  exports.GenerateContext = GenerateContext;
838
- _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(), _GenerateContext_captureChannel = new WeakMap(), _GenerateContext_enrichmentAudit = new WeakMap(), _GenerateContext_ejectedBySuffixedPathCache = new WeakMap(), _GenerateContext_instances = new WeakSet(), _GenerateContext_reportSkippedEnrichment = function _GenerateContext_reportSkippedEnrichment(block, variant, path) {
863
+ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(), _GenerateContext_captureChannel = new WeakMap(), _GenerateContext_enrichmentAudit = new WeakMap(), _GenerateContext_currentSubjectTrail = new WeakMap(), _GenerateContext_ejectedBySuffixedPathCache = new WeakMap(), _GenerateContext_instances = new WeakSet(), _GenerateContext_reportSkippedEnrichment = function _GenerateContext_reportSkippedEnrichment(block, variant, path) {
839
864
  if (!(0, EnrichmentAudit_js_1.hasVariantEnrichment)(block, variant))
840
865
  return;
841
866
  __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").report({
@@ -845,6 +870,8 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
845
870
  message: `enrichment at '${(0, EnrichmentWarning_js_1.formatEnrichmentPath)(path)}' targets a skipped item — ` +
846
871
  `it was not applied in this run`
847
872
  });
873
+ }, _GenerateContext_logError = function _GenerateContext_logError(error) {
874
+ this.logger.error((0, SerializedError_js_1.toSerializedError)(error).message, error);
848
875
  }, _GenerateContext_schemaRefNames = function _GenerateContext_schemaRefNames() {
849
876
  switch (this.document.type) {
850
877
  case 'oas':
@@ -866,7 +893,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
866
893
  return isEnrichmentLeaf(subject) ? subject : undefined;
867
894
  }
868
895
  catch (error) {
869
- this.logger.error(error);
896
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
870
897
  return undefined;
871
898
  }
872
899
  }, _GenerateContext_runOasOperationGenerator = function _GenerateContext_runOasOperationGenerator(oasDocument, generatorConfig, include, skip, stackTrail) {
@@ -894,7 +921,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
894
921
  operationLabel: `${operation.method.toUpperCase()} ${operation.path}`
895
922
  });
896
923
  variants.forEach(variant => {
897
- opTrail.trace(['variant', variant], st => {
924
+ opTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
898
925
  try {
899
926
  if (typeof generatorConfig?.isSupported === 'function' &&
900
927
  !generatorConfig.isSupported({ operation, context: this, variant })) {
@@ -951,10 +978,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
951
978
  this.captureCurrentResult('success', st);
952
979
  }
953
980
  catch (error) {
954
- this.logger.error(error);
981
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
955
982
  this.captureCurrentResult('error', st);
956
983
  }
957
- });
984
+ }));
958
985
  });
959
986
  });
960
987
  });
@@ -976,7 +1003,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
976
1003
  operationLabel: `webhook '${webhook.name}' (${webhook.method.toUpperCase()})`
977
1004
  });
978
1005
  variants.forEach(variant => {
979
- webhookTrail.trace(['variant', variant], st => {
1006
+ webhookTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
980
1007
  try {
981
1008
  if (typeof generatorConfig?.isSupported === 'function' &&
982
1009
  !generatorConfig.isSupported({ webhook, context: this, variant })) {
@@ -1032,10 +1059,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1032
1059
  this.captureCurrentResult('success', st);
1033
1060
  }
1034
1061
  catch (error) {
1035
- this.logger.error(error);
1062
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1036
1063
  this.captureCurrentResult('error', st);
1037
1064
  }
1038
- });
1065
+ }));
1039
1066
  });
1040
1067
  });
1041
1068
  });
@@ -1055,7 +1082,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1055
1082
  operationLabel: `${operation.rootKind} ${operation.fieldName}`
1056
1083
  });
1057
1084
  variants.forEach(variant => {
1058
- opTrail.trace(['variant', variant], st => {
1085
+ opTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
1059
1086
  try {
1060
1087
  if (typeof generatorConfig.isSupported === 'function' &&
1061
1088
  !generatorConfig.isSupported({ operation, context: this, variant })) {
@@ -1076,10 +1103,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1076
1103
  this.captureCurrentResult('success', st);
1077
1104
  }
1078
1105
  catch (error) {
1079
- this.logger.error(error);
1106
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1080
1107
  this.captureCurrentResult('error', st);
1081
1108
  }
1082
- });
1109
+ }));
1083
1110
  });
1084
1111
  });
1085
1112
  });
@@ -1107,7 +1134,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1107
1134
  operationLabel: refName
1108
1135
  });
1109
1136
  variants.forEach(variant => {
1110
- refTrail.trace(['variant', variant], st => {
1137
+ refTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
1111
1138
  try {
1112
1139
  if (typeof generatorConfig.isSupported === 'function' &&
1113
1140
  !generatorConfig.isSupported({ refName, context: this, variant })) {
@@ -1118,7 +1145,8 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1118
1145
  // (deny). Match is on `(refName, variant)`. An empty variant
1119
1146
  // array on a refName means "every variant of this refName"; a
1120
1147
  // populated array names the variants the entry applies to.
1121
- if (include !== undefined && !matchesRefFilter({ refs: include, refName, variant })) {
1148
+ if (include !== undefined &&
1149
+ !matchesRefFilter({ refs: include, refName, variant })) {
1122
1150
  __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_reportSkippedEnrichment).call(this, modelEnrichments, variant, [
1123
1151
  generatorConfig.id,
1124
1152
  refName,
@@ -1150,10 +1178,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1150
1178
  this.captureCurrentResult('success', st);
1151
1179
  }
1152
1180
  catch (error) {
1153
- this.logger.error(error);
1181
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1154
1182
  this.captureCurrentResult('error', st);
1155
1183
  }
1156
- });
1184
+ }));
1157
1185
  });
1158
1186
  });
1159
1187
  });
@@ -0,0 +1,28 @@
1
+ import { type LevelName } from '../deps/jsr.io/@std/log/0.224.14/levels.js';
2
+ import type { LogRecord } from '../deps/jsr.io/@std/log/0.224.14/logger.js';
3
+ import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
4
+ import type { LogLine } from '../types/LogLine.js';
5
+ /** Configuration options for the {@link LogLinesHandler}. */
6
+ export type LogLinesHandlerOptions = {
7
+ /** The trail of the subject being generated, or `undefined` outside one. */
8
+ toTrail: () => string | undefined;
9
+ };
10
+ /**
11
+ * Keeps each log record at or above its level as a {@link LogLine}, in
12
+ * memory, for `toArtifacts` to return.
13
+ */
14
+ export declare class LogLinesHandler extends BaseHandler {
15
+ #private;
16
+ constructor(levelName: LevelName, { toTrail }: LogLinesHandlerOptions);
17
+ /** The lines kept so far, in the order they were logged. */
18
+ get lines(): LogLine[];
19
+ /**
20
+ * Records `logRecord` as a structured line. Overrides `handle` because
21
+ * `BaseHandler.handle` formats the record to a string before `log`.
22
+ *
23
+ * @override
24
+ */
25
+ handle(logRecord: LogRecord): void;
26
+ /** Not used: {@link handle} records the structured line. */
27
+ log(_msg: string): void;
28
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _LogLinesHandler_toTrail, _LogLinesHandler_lines;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LogLinesHandler = void 0;
16
+ const levels_js_1 = require("../deps/jsr.io/@std/log/0.224.14/levels.js");
17
+ const base_handler_js_1 = require("../deps/jsr.io/@std/log/0.224.14/base_handler.js");
18
+ const SerializedError_js_1 = require("../types/SerializedError.js");
19
+ /**
20
+ * Keeps each log record at or above its level as a {@link LogLine}, in
21
+ * memory, for `toArtifacts` to return.
22
+ */
23
+ class LogLinesHandler extends base_handler_js_1.BaseHandler {
24
+ constructor(levelName, { toTrail }) {
25
+ super(levelName);
26
+ _LogLinesHandler_toTrail.set(this, void 0);
27
+ _LogLinesHandler_lines.set(this, []);
28
+ __classPrivateFieldSet(this, _LogLinesHandler_toTrail, toTrail, "f");
29
+ }
30
+ /** The lines kept so far, in the order they were logged. */
31
+ get lines() {
32
+ return __classPrivateFieldGet(this, _LogLinesHandler_lines, "f");
33
+ }
34
+ /**
35
+ * Records `logRecord` as a structured line. Overrides `handle` because
36
+ * `BaseHandler.handle` formats the record to a string before `log`.
37
+ *
38
+ * @override
39
+ */
40
+ handle(logRecord) {
41
+ if (this.level > logRecord.level) {
42
+ return;
43
+ }
44
+ // Taken now: the trail object changes after the subject's callback returns.
45
+ const trail = __classPrivateFieldGet(this, _LogLinesHandler_toTrail, "f").call(this);
46
+ const error = logRecord.args.find(arg => arg instanceof Error);
47
+ __classPrivateFieldGet(this, _LogLinesHandler_lines, "f").push({
48
+ seq: __classPrivateFieldGet(this, _LogLinesHandler_lines, "f").length,
49
+ level: toLogLineLevel(logRecord.level),
50
+ ...(trail === undefined ? {} : { trail }),
51
+ message: logRecord.msg,
52
+ ...(error === undefined ? {} : { error: (0, SerializedError_js_1.toSerializedError)(error) }),
53
+ time: logRecord.datetime.getTime()
54
+ });
55
+ }
56
+ /** Not used: {@link handle} records the structured line. */
57
+ log(_msg) { }
58
+ }
59
+ exports.LogLinesHandler = LogLinesHandler;
60
+ _LogLinesHandler_toTrail = new WeakMap(), _LogLinesHandler_lines = new WeakMap();
61
+ const toLogLineLevel = (level) => {
62
+ if (level >= levels_js_1.LogLevels.ERROR)
63
+ return 'ERROR';
64
+ if (level >= levels_js_1.LogLevels.WARN)
65
+ return 'WARN';
66
+ if (level >= levels_js_1.LogLevels.INFO)
67
+ return 'INFO';
68
+ return 'DEBUG';
69
+ };
@@ -43,6 +43,25 @@ const parseGqlDocument_js_1 = require("../gql/document/parseGqlDocument.js");
43
43
  const StackTrail_js_1 = require("./StackTrail.js");
44
44
  const isPlainObject_js_1 = require("../parse/isPlainObject.js");
45
45
  const pathParameters_js_1 = require("../parse/pathParameters.js");
46
+ const SerializedError_js_1 = require("../types/SerializedError.js");
47
+ /** The stored form of an issue: an error's `cause` as a `SerializedError`. */
48
+ const toParseIssue = (issue) => {
49
+ if (issue.level !== 'error') {
50
+ return issue;
51
+ }
52
+ const { protocol, location, message } = issue;
53
+ const cause = issue.cause === undefined ? {} : { cause: (0, SerializedError_js_1.toSerializedError)(issue.cause) };
54
+ switch (protocol) {
55
+ case 'oas':
56
+ return { protocol, level: 'error', type: issue.type, location, message, ...cause };
57
+ case 'gql':
58
+ return { protocol, level: 'error', type: issue.type, location, message, ...cause };
59
+ default: {
60
+ const _exhaustive = protocol;
61
+ throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
62
+ }
63
+ }
64
+ };
46
65
  class ParseContext {
47
66
  constructor({ input, logger, silent = true, options }) {
48
67
  _ParseContext_instances.add(this);
@@ -200,7 +219,7 @@ class ParseContext {
200
219
  * removes those frames before it reads a trail as a document address.
201
220
  */
202
221
  parse(stackTrail) {
203
- __classPrivateFieldSet(this, _ParseContext_rootFrames, [...stackTrail.stackTrail], "f");
222
+ __classPrivateFieldSet(this, _ParseContext_rootFrames, stackTrail.stackTrail, "f");
204
223
  switch (this.protocol.type) {
205
224
  case 'oas': {
206
225
  const oasState = this.protocol;
@@ -368,7 +387,7 @@ class ParseContext {
368
387
  * manifest).
369
388
  */
370
389
  logIssueAt(issue, parent) {
371
- this.issues.push(issue);
390
+ this.issues.push(toParseIssue(issue));
372
391
  if (!this.silent) {
373
392
  this.logger.warn({
374
393
  protocol: issue.protocol,
@@ -574,7 +593,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
574
593
  type: 'INVALID_DEPENDENCY_REF',
575
594
  location,
576
595
  message,
577
- cause: error
596
+ cause: (0, SerializedError_js_1.toSerializedError)(error)
578
597
  });
579
598
  break;
580
599
  case 'gql':
@@ -584,7 +603,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
584
603
  type: 'INVALID_DEPENDENCY_REF',
585
604
  location,
586
605
  message,
587
- cause: error
606
+ cause: (0, SerializedError_js_1.toSerializedError)(error)
588
607
  });
589
608
  break;
590
609
  default: {
@@ -3,11 +3,11 @@
3
3
  * GraphQL parsing. Each variant stands on its own — no shared base —
4
4
  * so TypeScript narrows cleanly on `protocol` and `level`.
5
5
  *
6
- * `cause?: unknown` is only present on the error variants. Warnings and
7
- * `debug` issues are synthesized by the parser with all the information
8
- * needed for the `message`; errors usually wrap a thrown `Error`, which
9
- * we keep in `cause` for debugging without forcing renderers to know
10
- * about it.
6
+ * `cause?: SerializedError` is only present on the error variants.
7
+ * Warnings and `debug` issues are synthesized by the parser with all the
8
+ * information needed for the `message`; errors usually wrap a thrown
9
+ * `Error`, which is stored in `cause` as a {@link SerializedError} so its
10
+ * name, message and stack survive `JSON.stringify`.
11
11
  *
12
12
  * Three severities: `error` (broken — drives exit status), `warning` (a
13
13
  * real deviation that was handled, e.g. a 3.0 schema missing `type`), and
@@ -23,6 +23,7 @@
23
23
  */
24
24
  import * as v from 'valibot';
25
25
  import type { OasIssueType } from './generateTypes.js';
26
+ import type { SerializedError } from '../types/SerializedError.js';
26
27
  /**
27
28
  * Categories of issues recorded during GraphQL → OAS mapping.
28
29
  *
@@ -49,22 +50,24 @@ import type { OasIssueType } from './generateTypes.js';
49
50
  * implementer references a type that failed to parse, and the
50
51
  * consumer was pruned by `removeErroredItems`. Mirrors OAS's
51
52
  * identically-named issue.
53
+ * - `RUN_FAILED` — the run itself failed outside the per-item catches.
54
+ * Mirrors OAS's identically-named issue.
52
55
  */
53
- export type GqlIssueType = 'NESTED_LIST_LOSSY' | 'UNKNOWN_TYPE_KIND' | 'DROPPED_DIRECTIVE' | 'SKIPPED_FIELD_ARGUMENTS' | 'SKIPPED_FEATURE' | 'INVALID_TYPE_DEFINITION' | 'INVALID_DEPENDENCY_REF';
56
+ export type GqlIssueType = 'NESTED_LIST_LOSSY' | 'UNKNOWN_TYPE_KIND' | 'DROPPED_DIRECTIVE' | 'SKIPPED_FIELD_ARGUMENTS' | 'SKIPPED_FEATURE' | 'INVALID_TYPE_DEFINITION' | 'INVALID_DEPENDENCY_REF' | 'RUN_FAILED';
54
57
  /**
55
58
  * Valibot schema for {@link GqlIssueType}. Annotation deliberately
56
59
  * omitted so the precise literal-union output type flows through to
57
60
  * consumers; drift between this list and {@link GqlIssueType} is
58
61
  * caught by the compile-time assertion below.
59
62
  */
60
- export declare const gqlIssueType: v.UnionSchema<[v.LiteralSchema<"NESTED_LIST_LOSSY", undefined>, v.LiteralSchema<"UNKNOWN_TYPE_KIND", undefined>, v.LiteralSchema<"DROPPED_DIRECTIVE", undefined>, v.LiteralSchema<"SKIPPED_FIELD_ARGUMENTS", undefined>, v.LiteralSchema<"SKIPPED_FEATURE", undefined>, v.LiteralSchema<"INVALID_TYPE_DEFINITION", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>], undefined>;
63
+ export declare const gqlIssueType: v.UnionSchema<[v.LiteralSchema<"NESTED_LIST_LOSSY", undefined>, v.LiteralSchema<"UNKNOWN_TYPE_KIND", undefined>, v.LiteralSchema<"DROPPED_DIRECTIVE", undefined>, v.LiteralSchema<"SKIPPED_FIELD_ARGUMENTS", undefined>, v.LiteralSchema<"SKIPPED_FEATURE", undefined>, v.LiteralSchema<"INVALID_TYPE_DEFINITION", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"RUN_FAILED", undefined>], undefined>;
61
64
  export type ParseIssue = {
62
65
  protocol: 'oas';
63
66
  level: 'error';
64
67
  type: OasIssueType;
65
68
  location: string;
66
69
  message: string;
67
- cause?: unknown;
70
+ cause?: SerializedError;
68
71
  } | {
69
72
  protocol: 'oas';
70
73
  level: 'warning';
@@ -83,7 +86,7 @@ export type ParseIssue = {
83
86
  type: GqlIssueType;
84
87
  location: string;
85
88
  message: string;
86
- cause?: unknown;
89
+ cause?: SerializedError;
87
90
  } | {
88
91
  protocol: 'gql';
89
92
  level: 'warning';
@@ -4,11 +4,11 @@
4
4
  * GraphQL parsing. Each variant stands on its own — no shared base —
5
5
  * so TypeScript narrows cleanly on `protocol` and `level`.
6
6
  *
7
- * `cause?: unknown` is only present on the error variants. Warnings and
8
- * `debug` issues are synthesized by the parser with all the information
9
- * needed for the `message`; errors usually wrap a thrown `Error`, which
10
- * we keep in `cause` for debugging without forcing renderers to know
11
- * about it.
7
+ * `cause?: SerializedError` is only present on the error variants.
8
+ * Warnings and `debug` issues are synthesized by the parser with all the
9
+ * information needed for the `message`; errors usually wrap a thrown
10
+ * `Error`, which is stored in `cause` as a {@link SerializedError} so its
11
+ * name, message and stack survive `JSON.stringify`.
12
12
  *
13
13
  * Three severities: `error` (broken — drives exit status), `warning` (a
14
14
  * real deviation that was handled, e.g. a 3.0 schema missing `type`), and
@@ -71,7 +71,8 @@ exports.gqlIssueType = v.union([
71
71
  v.literal('SKIPPED_FIELD_ARGUMENTS'),
72
72
  v.literal('SKIPPED_FEATURE'),
73
73
  v.literal('INVALID_TYPE_DEFINITION'),
74
- v.literal('INVALID_DEPENDENCY_REF')
74
+ v.literal('INVALID_DEPENDENCY_REF'),
75
+ v.literal('RUN_FAILED')
75
76
  ]);
76
77
  const _gqlIssueTypeDriftCheck = exports.gqlIssueType;
77
78
  void _gqlIssueTypeDriftCheck;
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _RenderContext_captureChannel, _RenderContext_sink, _RenderContext_captures;
16
+ var _RenderContext_captureChannel, _RenderContext_capture;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.RenderContext = void 0;
19
19
  const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
@@ -84,25 +84,11 @@ class RenderContext {
84
84
  */
85
85
  _RenderContext_captureChannel.set(this, void 0);
86
86
  /**
87
- * Active capture sink for the in-progress render pass, or `undefined`
88
- * when rendering without attribution. `collate` checks this to decide
89
- * whether to capture; set + cleared by `render`.
87
+ * The capturing render in progress, or `undefined` when rendering
88
+ * without attribution. `collate` checks this to decide whether to
89
+ * capture; set + cleared by `render`.
90
90
  */
91
- _RenderContext_sink.set(this, void 0);
92
- /**
93
- * Per-file render output retained during a capturing render, consumed
94
- * by `render` to build sidecars. Reset each capturing render.
95
- */
96
- _RenderContext_captures.set(this, []
97
- /**
98
- * Creates a new RenderContext instance with the specified configuration.
99
- *
100
- * Initializes the rendering context with files to render, preview data,
101
- * formatting configuration, and logging/tracing infrastructure.
102
- *
103
- * @param args - Constructor arguments containing all required configuration
104
- */
105
- );
91
+ _RenderContext_capture.set(this, void 0);
106
92
  this.files = files;
107
93
  this.previews = previews;
108
94
  this.basePath = basePath;
@@ -157,11 +143,15 @@ class RenderContext {
157
143
  // the shared channel for the single `collate` walk, and close it in
158
144
  // `finally`. Snippets' self-installed `toString` wrappers observe into
159
145
  // the sink; `collate` routes each File's render through it.
160
- const sink = new CaptureSink_js_1.CaptureSink();
161
- __classPrivateFieldSet(this, _RenderContext_sink, sink, "f");
162
- __classPrivateFieldSet(this, _RenderContext_captures, [], "f");
146
+ const capture = {
147
+ sink: new CaptureSink_js_1.CaptureSink(),
148
+ postPass: postPassConfig,
149
+ sidecars: {},
150
+ generationMap: []
151
+ };
152
+ __classPrivateFieldSet(this, _RenderContext_capture, capture, "f");
163
153
  if (__classPrivateFieldGet(this, _RenderContext_captureChannel, "f")) {
164
- __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = sink;
154
+ __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = capture.sink;
165
155
  }
166
156
  let result;
167
157
  try {
@@ -171,38 +161,14 @@ class RenderContext {
171
161
  if (__classPrivateFieldGet(this, _RenderContext_captureChannel, "f")) {
172
162
  __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = undefined;
173
163
  }
174
- __classPrivateFieldSet(this, _RenderContext_sink, undefined, "f");
164
+ __classPrivateFieldSet(this, _RenderContext_capture, undefined, "f");
175
165
  }
176
- // Build one sidecar per captured File from the spans the sink
177
- // resolved (no re-render, no `toString`). Keyed by the resolved artifact
178
- // path, matching `artifacts` and the manifest, so a sidecar sits at
179
- // `<outDir>/<artifact key>.skm.json` where doctor looks for it.
180
- const { parser, schemaSrc, generatorMeta } = postPassConfig;
181
- const sidecars = {};
182
- const generationMap = [];
183
- for (const capture of __classPrivateFieldGet(this, _RenderContext_captures, "f")) {
184
- const sidecar = (0, postPass_js_1.postPass)({
185
- filePath: capture.filePath,
186
- source: capture.source,
187
- spans: capture.spans,
188
- schemaSrc,
189
- parser,
190
- generatorMeta
191
- });
192
- const artifactPath = (0, toResolvedArtifactPath_js_1.toResolvedArtifactPath)({
193
- basePath: this.basePath,
194
- destinationPath: capture.destinationPath
195
- });
196
- sidecars[artifactPath] = sidecar;
197
- generationMap.push(...(0, generationMap_js_1.entriesForSidecar)(sidecar));
198
- }
199
- __classPrivateFieldSet(this, _RenderContext_captures, [], "f");
200
166
  return {
201
167
  artifacts: result.artifacts,
202
168
  files: result.files,
203
169
  previews: this.previews,
204
- sidecars,
205
- generationMap
170
+ sidecars: capture.sidecars,
171
+ generationMap: capture.generationMap
206
172
  };
207
173
  }
208
174
  /**
@@ -242,25 +208,26 @@ class RenderContext {
242
208
  // JsonFile (and the non-capturing path) render plainly — the
243
209
  // installed wrapper is inert while the sink is not in a
244
210
  // `captureFile` call.
245
- let content;
246
- if (__classPrivateFieldGet(this, _RenderContext_sink, "f") && file instanceof CodeFileBase_js_1.CodeFileBase) {
247
- const captured = __classPrivateFieldGet(this, _RenderContext_sink, "f").captureFile(() => file.toString());
248
- content = captured.text;
249
- __classPrivateFieldGet(this, _RenderContext_captures, "f").push({
250
- destinationPath,
211
+ const capture = __classPrivateFieldGet(this, _RenderContext_capture, "f");
212
+ const captured = capture && file instanceof CodeFileBase_js_1.CodeFileBase
213
+ ? capture.sink.captureFile(() => file.toString())
214
+ : undefined;
215
+ const renderedFile = renderFile({
216
+ content: captured?.text ?? file.toString(),
217
+ destinationPath,
218
+ basePath: this.basePath
219
+ });
220
+ if (capture && captured) {
221
+ // The post-pass runs inside this file's trace, so a post-pass
222
+ // that throws stops the render here: this file and the files
223
+ // after it get no result, and the run fails with RUN_FAILED.
224
+ addSidecar(capture, {
225
+ artifactPath: renderedFile.path,
251
226
  filePath: file.path,
252
227
  source: captured.text,
253
228
  spans: captured.spans
254
229
  });
255
230
  }
256
- else {
257
- content = file.toString();
258
- }
259
- const renderedFile = renderFile({
260
- content,
261
- destinationPath,
262
- basePath: this.basePath
263
- });
264
231
  this.captureCurrentResult('success', st);
265
232
  return renderedFile;
266
233
  });
@@ -345,7 +312,22 @@ class RenderContext {
345
312
  }
346
313
  }
347
314
  exports.RenderContext = RenderContext;
348
- _RenderContext_captureChannel = new WeakMap(), _RenderContext_sink = new WeakMap(), _RenderContext_captures = new WeakMap();
315
+ _RenderContext_captureChannel = new WeakMap(), _RenderContext_capture = new WeakMap();
316
+ /**
317
+ * Builds the sidecar of one captured File from the spans the sink
318
+ * resolved (no re-render, no `toString`) and adds it to the capturing
319
+ * render. Keyed by the resolved artifact path, matching `artifacts` and
320
+ * the manifest, so a sidecar sits at `<outDir>/<artifact key>.skm.json`
321
+ * where doctor looks for it.
322
+ */
323
+ const addSidecar = (capture, { artifactPath, filePath, source, spans }) => {
324
+ const { parser, schemaSrc, generatorMeta } = capture.postPass;
325
+ const sidecar = (0, postPass_js_1.postPass)({ filePath, source, spans, schemaSrc, parser, generatorMeta });
326
+ capture.sidecars[artifactPath] = sidecar;
327
+ for (const entry of (0, generationMap_js_1.entriesForSidecar)(sidecar)) {
328
+ capture.generationMap.push(entry);
329
+ }
330
+ };
349
331
  /**
350
332
  * Renders a single file with metadata calculation.
351
333
  *
@@ -60,10 +60,11 @@ export declare class ResultsHandler extends BaseHandler implements LogHandlerBas
60
60
  /**
61
61
  * Captures log messages as results in the context.
62
62
  *
63
- * Converts log level names to result types and captures them
64
- * in the associated CoreContext for later analysis.
63
+ * Converts log level names to result types and captures them in the
64
+ * associated CoreContext at the trail of the subject being generated.
65
+ * A line logged outside a subject records nothing.
65
66
  *
66
- * @param levelName - The log level name ('WARN' or 'ERROR')
67
+ * @param levelName - The log level name ('WARN', 'ERROR' or 'CRITICAL')
67
68
  *
68
69
  * @throws {Error} When an unsupported log level is provided
69
70
  *
@@ -72,6 +73,7 @@ export declare class ResultsHandler extends BaseHandler implements LogHandlerBas
72
73
  * // This is called automatically by the logging system
73
74
  * handler.log('WARN'); // Captures as 'warning' result
74
75
  * handler.log('ERROR'); // Captures as 'error' result
76
+ * handler.log('CRITICAL'); // Captures as 'error' result
75
77
  * ```
76
78
  */
77
79
  log(levelName: string): void;