@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,7 @@ 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 _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;
12
+ 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;
13
13
  import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
14
14
  import { applyGeneratedSuffix, DEFAULT_GENERATED_SUFFIX } from '../helpers/applyGeneratedSuffix.js';
15
15
  import { OasOperationDriver } from '../dsl/operation/oas/OasOperationDriver.js';
@@ -29,6 +29,7 @@ import { JsonFile } from '../dsl/JsonFile.js';
29
29
  import { MarkdownFile } from '../dsl/MarkdownFile.js';
30
30
  import invariant from 'tiny-invariant';
31
31
  import { EnrichmentAudit, hasVariantEnrichment } from '../enrichments/EnrichmentAudit.js';
32
+ import { toSerializedError } from '../types/SerializedError.js';
32
33
  import { formatEnrichmentPath } from '../enrichments/EnrichmentWarning.js';
33
34
  /**
34
35
  * The generation context for the second phase of the SKMTC transformation pipeline.
@@ -141,6 +142,8 @@ export class GenerateContext {
141
142
  * `enrichmentWarnings` at the end of {@link toArtifacts}.
142
143
  */
143
144
  _GenerateContext_enrichmentAudit.set(this, void 0);
145
+ /** See {@link currentSubjectTrail}. */
146
+ _GenerateContext_currentSubjectTrail.set(this, void 0);
144
147
  _GenerateContext_ejectedBySuffixedPathCache.set(this, void 0);
145
148
  this.logger = logger;
146
149
  __classPrivateFieldSet(this, _GenerateContext_files, new Map(), "f");
@@ -183,6 +186,28 @@ export class GenerateContext {
183
186
  get captureSink() {
184
187
  return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
185
188
  }
189
+ /**
190
+ * The trail of the subject whose variant is being generated, or
191
+ * `undefined` outside one. Log lines and the results the logger
192
+ * records are addressed by it.
193
+ */
194
+ get currentSubjectTrail() {
195
+ return __classPrivateFieldGet(this, _GenerateContext_currentSubjectTrail, "f");
196
+ }
197
+ /**
198
+ * Runs `fn` with {@link currentSubjectTrail} set to `stackTrail`, and
199
+ * restores the previous value afterwards.
200
+ */
201
+ withSubjectTrail(stackTrail, fn) {
202
+ const previous = __classPrivateFieldGet(this, _GenerateContext_currentSubjectTrail, "f");
203
+ __classPrivateFieldSet(this, _GenerateContext_currentSubjectTrail, stackTrail, "f");
204
+ try {
205
+ return fn();
206
+ }
207
+ finally {
208
+ __classPrivateFieldSet(this, _GenerateContext_currentSubjectTrail, previous, "f");
209
+ }
210
+ }
186
211
  /**
187
212
  * @internal
188
213
  */
@@ -828,7 +853,7 @@ export class GenerateContext {
828
853
  return place?.findDefinitions({ name })?.[0];
829
854
  }
830
855
  }
831
- _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) {
856
+ _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) {
832
857
  if (!hasVariantEnrichment(block, variant))
833
858
  return;
834
859
  __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").report({
@@ -838,6 +863,8 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
838
863
  message: `enrichment at '${formatEnrichmentPath(path)}' targets a skipped item — ` +
839
864
  `it was not applied in this run`
840
865
  });
866
+ }, _GenerateContext_logError = function _GenerateContext_logError(error) {
867
+ this.logger.error(toSerializedError(error).message, error);
841
868
  }, _GenerateContext_schemaRefNames = function _GenerateContext_schemaRefNames() {
842
869
  switch (this.document.type) {
843
870
  case 'oas':
@@ -859,7 +886,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
859
886
  return isEnrichmentLeaf(subject) ? subject : undefined;
860
887
  }
861
888
  catch (error) {
862
- this.logger.error(error);
889
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
863
890
  return undefined;
864
891
  }
865
892
  }, _GenerateContext_runOasOperationGenerator = function _GenerateContext_runOasOperationGenerator(oasDocument, generatorConfig, include, skip, stackTrail) {
@@ -887,7 +914,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
887
914
  operationLabel: `${operation.method.toUpperCase()} ${operation.path}`
888
915
  });
889
916
  variants.forEach(variant => {
890
- opTrail.trace(['variant', variant], st => {
917
+ opTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
891
918
  try {
892
919
  if (typeof generatorConfig?.isSupported === 'function' &&
893
920
  !generatorConfig.isSupported({ operation, context: this, variant })) {
@@ -944,10 +971,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
944
971
  this.captureCurrentResult('success', st);
945
972
  }
946
973
  catch (error) {
947
- this.logger.error(error);
974
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
948
975
  this.captureCurrentResult('error', st);
949
976
  }
950
- });
977
+ }));
951
978
  });
952
979
  });
953
980
  });
@@ -969,7 +996,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
969
996
  operationLabel: `webhook '${webhook.name}' (${webhook.method.toUpperCase()})`
970
997
  });
971
998
  variants.forEach(variant => {
972
- webhookTrail.trace(['variant', variant], st => {
999
+ webhookTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
973
1000
  try {
974
1001
  if (typeof generatorConfig?.isSupported === 'function' &&
975
1002
  !generatorConfig.isSupported({ webhook, context: this, variant })) {
@@ -1025,10 +1052,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1025
1052
  this.captureCurrentResult('success', st);
1026
1053
  }
1027
1054
  catch (error) {
1028
- this.logger.error(error);
1055
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1029
1056
  this.captureCurrentResult('error', st);
1030
1057
  }
1031
- });
1058
+ }));
1032
1059
  });
1033
1060
  });
1034
1061
  });
@@ -1048,7 +1075,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1048
1075
  operationLabel: `${operation.rootKind} ${operation.fieldName}`
1049
1076
  });
1050
1077
  variants.forEach(variant => {
1051
- opTrail.trace(['variant', variant], st => {
1078
+ opTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
1052
1079
  try {
1053
1080
  if (typeof generatorConfig.isSupported === 'function' &&
1054
1081
  !generatorConfig.isSupported({ operation, context: this, variant })) {
@@ -1069,10 +1096,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1069
1096
  this.captureCurrentResult('success', st);
1070
1097
  }
1071
1098
  catch (error) {
1072
- this.logger.error(error);
1099
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1073
1100
  this.captureCurrentResult('error', st);
1074
1101
  }
1075
- });
1102
+ }));
1076
1103
  });
1077
1104
  });
1078
1105
  });
@@ -1100,7 +1127,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1100
1127
  operationLabel: refName
1101
1128
  });
1102
1129
  variants.forEach(variant => {
1103
- refTrail.trace(['variant', variant], st => {
1130
+ refTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
1104
1131
  try {
1105
1132
  if (typeof generatorConfig.isSupported === 'function' &&
1106
1133
  !generatorConfig.isSupported({ refName, context: this, variant })) {
@@ -1111,7 +1138,8 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1111
1138
  // (deny). Match is on `(refName, variant)`. An empty variant
1112
1139
  // array on a refName means "every variant of this refName"; a
1113
1140
  // populated array names the variants the entry applies to.
1114
- if (include !== undefined && !matchesRefFilter({ refs: include, refName, variant })) {
1141
+ if (include !== undefined &&
1142
+ !matchesRefFilter({ refs: include, refName, variant })) {
1115
1143
  __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_reportSkippedEnrichment).call(this, modelEnrichments, variant, [
1116
1144
  generatorConfig.id,
1117
1145
  refName,
@@ -1143,10 +1171,10 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_previews = new WeakMap(
1143
1171
  this.captureCurrentResult('success', st);
1144
1172
  }
1145
1173
  catch (error) {
1146
- this.logger.error(error);
1174
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_logError).call(this, error);
1147
1175
  this.captureCurrentResult('error', st);
1148
1176
  }
1149
- });
1177
+ }));
1150
1178
  });
1151
1179
  });
1152
1180
  });
@@ -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,65 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _LogLinesHandler_toTrail, _LogLinesHandler_lines;
13
+ import { LogLevels } from '../deps/jsr.io/@std/log/0.224.14/levels.js';
14
+ import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
15
+ import { toSerializedError } from '../types/SerializedError.js';
16
+ /**
17
+ * Keeps each log record at or above its level as a {@link LogLine}, in
18
+ * memory, for `toArtifacts` to return.
19
+ */
20
+ export class LogLinesHandler extends BaseHandler {
21
+ constructor(levelName, { toTrail }) {
22
+ super(levelName);
23
+ _LogLinesHandler_toTrail.set(this, void 0);
24
+ _LogLinesHandler_lines.set(this, []);
25
+ __classPrivateFieldSet(this, _LogLinesHandler_toTrail, toTrail, "f");
26
+ }
27
+ /** The lines kept so far, in the order they were logged. */
28
+ get lines() {
29
+ return __classPrivateFieldGet(this, _LogLinesHandler_lines, "f");
30
+ }
31
+ /**
32
+ * Records `logRecord` as a structured line. Overrides `handle` because
33
+ * `BaseHandler.handle` formats the record to a string before `log`.
34
+ *
35
+ * @override
36
+ */
37
+ handle(logRecord) {
38
+ if (this.level > logRecord.level) {
39
+ return;
40
+ }
41
+ // Taken now: the trail object changes after the subject's callback returns.
42
+ const trail = __classPrivateFieldGet(this, _LogLinesHandler_toTrail, "f").call(this);
43
+ const error = logRecord.args.find(arg => arg instanceof Error);
44
+ __classPrivateFieldGet(this, _LogLinesHandler_lines, "f").push({
45
+ seq: __classPrivateFieldGet(this, _LogLinesHandler_lines, "f").length,
46
+ level: toLogLineLevel(logRecord.level),
47
+ ...(trail === undefined ? {} : { trail }),
48
+ message: logRecord.msg,
49
+ ...(error === undefined ? {} : { error: toSerializedError(error) }),
50
+ time: logRecord.datetime.getTime()
51
+ });
52
+ }
53
+ /** Not used: {@link handle} records the structured line. */
54
+ log(_msg) { }
55
+ }
56
+ _LogLinesHandler_toTrail = new WeakMap(), _LogLinesHandler_lines = new WeakMap();
57
+ const toLogLineLevel = (level) => {
58
+ if (level >= LogLevels.ERROR)
59
+ return 'ERROR';
60
+ if (level >= LogLevels.WARN)
61
+ return 'WARN';
62
+ if (level >= LogLevels.INFO)
63
+ return 'INFO';
64
+ return 'DEBUG';
65
+ };
@@ -40,6 +40,25 @@ import { parseGqlDocument } from '../gql/document/parseGqlDocument.js';
40
40
  import { StackTrail } from './StackTrail.js';
41
41
  import { isPlainObject } from '../parse/isPlainObject.js';
42
42
  import { toApplyingBrokenParameter, toNameAndIn } from '../parse/pathParameters.js';
43
+ import { toSerializedError } from '../types/SerializedError.js';
44
+ /** The stored form of an issue: an error's `cause` as a `SerializedError`. */
45
+ const toParseIssue = (issue) => {
46
+ if (issue.level !== 'error') {
47
+ return issue;
48
+ }
49
+ const { protocol, location, message } = issue;
50
+ const cause = issue.cause === undefined ? {} : { cause: toSerializedError(issue.cause) };
51
+ switch (protocol) {
52
+ case 'oas':
53
+ return { protocol, level: 'error', type: issue.type, location, message, ...cause };
54
+ case 'gql':
55
+ return { protocol, level: 'error', type: issue.type, location, message, ...cause };
56
+ default: {
57
+ const _exhaustive = protocol;
58
+ throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
59
+ }
60
+ }
61
+ };
43
62
  export class ParseContext {
44
63
  constructor({ input, logger, silent = true, options }) {
45
64
  _ParseContext_instances.add(this);
@@ -197,7 +216,7 @@ export class ParseContext {
197
216
  * removes those frames before it reads a trail as a document address.
198
217
  */
199
218
  parse(stackTrail) {
200
- __classPrivateFieldSet(this, _ParseContext_rootFrames, [...stackTrail.stackTrail], "f");
219
+ __classPrivateFieldSet(this, _ParseContext_rootFrames, stackTrail.stackTrail, "f");
201
220
  switch (this.protocol.type) {
202
221
  case 'oas': {
203
222
  const oasState = this.protocol;
@@ -365,7 +384,7 @@ export class ParseContext {
365
384
  * manifest).
366
385
  */
367
386
  logIssueAt(issue, parent) {
368
- this.issues.push(issue);
387
+ this.issues.push(toParseIssue(issue));
369
388
  if (!this.silent) {
370
389
  this.logger.warn({
371
390
  protocol: issue.protocol,
@@ -570,7 +589,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
570
589
  type: 'INVALID_DEPENDENCY_REF',
571
590
  location,
572
591
  message,
573
- cause: error
592
+ cause: toSerializedError(error)
574
593
  });
575
594
  break;
576
595
  case 'gql':
@@ -580,7 +599,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
580
599
  type: 'INVALID_DEPENDENCY_REF',
581
600
  location,
582
601
  message,
583
- cause: error
602
+ cause: toSerializedError(error)
584
603
  });
585
604
  break;
586
605
  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';
@@ -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
@@ -35,7 +35,8 @@ export const gqlIssueType = v.union([
35
35
  v.literal('SKIPPED_FIELD_ARGUMENTS'),
36
36
  v.literal('SKIPPED_FEATURE'),
37
37
  v.literal('INVALID_TYPE_DEFINITION'),
38
- v.literal('INVALID_DEPENDENCY_REF')
38
+ v.literal('INVALID_DEPENDENCY_REF'),
39
+ v.literal('RUN_FAILED')
39
40
  ]);
40
41
  const _gqlIssueTypeDriftCheck = gqlIssueType;
41
42
  void _gqlIssueTypeDriftCheck;
@@ -9,7 +9,7 @@ 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 _RenderContext_captureChannel, _RenderContext_sink, _RenderContext_captures;
12
+ var _RenderContext_captureChannel, _RenderContext_capture;
13
13
  import invariant from 'tiny-invariant';
14
14
  import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
15
15
  import { toResolvedArtifactPath } from '../helpers/toResolvedArtifactPath.js';
@@ -78,25 +78,11 @@ export class RenderContext {
78
78
  */
79
79
  _RenderContext_captureChannel.set(this, void 0);
80
80
  /**
81
- * Active capture sink for the in-progress render pass, or `undefined`
82
- * when rendering without attribution. `collate` checks this to decide
83
- * whether to capture; set + cleared by `render`.
81
+ * The capturing render in progress, or `undefined` when rendering
82
+ * without attribution. `collate` checks this to decide whether to
83
+ * capture; set + cleared by `render`.
84
84
  */
85
- _RenderContext_sink.set(this, void 0);
86
- /**
87
- * Per-file render output retained during a capturing render, consumed
88
- * by `render` to build sidecars. Reset each capturing render.
89
- */
90
- _RenderContext_captures.set(this, []
91
- /**
92
- * Creates a new RenderContext instance with the specified configuration.
93
- *
94
- * Initializes the rendering context with files to render, preview data,
95
- * formatting configuration, and logging/tracing infrastructure.
96
- *
97
- * @param args - Constructor arguments containing all required configuration
98
- */
99
- );
85
+ _RenderContext_capture.set(this, void 0);
100
86
  this.files = files;
101
87
  this.previews = previews;
102
88
  this.basePath = basePath;
@@ -151,11 +137,15 @@ export class RenderContext {
151
137
  // the shared channel for the single `collate` walk, and close it in
152
138
  // `finally`. Snippets' self-installed `toString` wrappers observe into
153
139
  // the sink; `collate` routes each File's render through it.
154
- const sink = new CaptureSink();
155
- __classPrivateFieldSet(this, _RenderContext_sink, sink, "f");
156
- __classPrivateFieldSet(this, _RenderContext_captures, [], "f");
140
+ const capture = {
141
+ sink: new CaptureSink(),
142
+ postPass: postPassConfig,
143
+ sidecars: {},
144
+ generationMap: []
145
+ };
146
+ __classPrivateFieldSet(this, _RenderContext_capture, capture, "f");
157
147
  if (__classPrivateFieldGet(this, _RenderContext_captureChannel, "f")) {
158
- __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = sink;
148
+ __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = capture.sink;
159
149
  }
160
150
  let result;
161
151
  try {
@@ -165,38 +155,14 @@ export class RenderContext {
165
155
  if (__classPrivateFieldGet(this, _RenderContext_captureChannel, "f")) {
166
156
  __classPrivateFieldGet(this, _RenderContext_captureChannel, "f").sink = undefined;
167
157
  }
168
- __classPrivateFieldSet(this, _RenderContext_sink, undefined, "f");
158
+ __classPrivateFieldSet(this, _RenderContext_capture, undefined, "f");
169
159
  }
170
- // Build one sidecar per captured File from the spans the sink
171
- // resolved (no re-render, no `toString`). Keyed by the resolved artifact
172
- // path, matching `artifacts` and the manifest, so a sidecar sits at
173
- // `<outDir>/<artifact key>.skm.json` where doctor looks for it.
174
- const { parser, schemaSrc, generatorMeta } = postPassConfig;
175
- const sidecars = {};
176
- const generationMap = [];
177
- for (const capture of __classPrivateFieldGet(this, _RenderContext_captures, "f")) {
178
- const sidecar = postPass({
179
- filePath: capture.filePath,
180
- source: capture.source,
181
- spans: capture.spans,
182
- schemaSrc,
183
- parser,
184
- generatorMeta
185
- });
186
- const artifactPath = toResolvedArtifactPath({
187
- basePath: this.basePath,
188
- destinationPath: capture.destinationPath
189
- });
190
- sidecars[artifactPath] = sidecar;
191
- generationMap.push(...entriesForSidecar(sidecar));
192
- }
193
- __classPrivateFieldSet(this, _RenderContext_captures, [], "f");
194
160
  return {
195
161
  artifacts: result.artifacts,
196
162
  files: result.files,
197
163
  previews: this.previews,
198
- sidecars,
199
- generationMap
164
+ sidecars: capture.sidecars,
165
+ generationMap: capture.generationMap
200
166
  };
201
167
  }
202
168
  /**
@@ -236,25 +202,26 @@ export class RenderContext {
236
202
  // JsonFile (and the non-capturing path) render plainly — the
237
203
  // installed wrapper is inert while the sink is not in a
238
204
  // `captureFile` call.
239
- let content;
240
- if (__classPrivateFieldGet(this, _RenderContext_sink, "f") && file instanceof CodeFileBase) {
241
- const captured = __classPrivateFieldGet(this, _RenderContext_sink, "f").captureFile(() => file.toString());
242
- content = captured.text;
243
- __classPrivateFieldGet(this, _RenderContext_captures, "f").push({
244
- destinationPath,
205
+ const capture = __classPrivateFieldGet(this, _RenderContext_capture, "f");
206
+ const captured = capture && file instanceof CodeFileBase
207
+ ? capture.sink.captureFile(() => file.toString())
208
+ : undefined;
209
+ const renderedFile = renderFile({
210
+ content: captured?.text ?? file.toString(),
211
+ destinationPath,
212
+ basePath: this.basePath
213
+ });
214
+ if (capture && captured) {
215
+ // The post-pass runs inside this file's trace, so a post-pass
216
+ // that throws stops the render here: this file and the files
217
+ // after it get no result, and the run fails with RUN_FAILED.
218
+ addSidecar(capture, {
219
+ artifactPath: renderedFile.path,
245
220
  filePath: file.path,
246
221
  source: captured.text,
247
222
  spans: captured.spans
248
223
  });
249
224
  }
250
- else {
251
- content = file.toString();
252
- }
253
- const renderedFile = renderFile({
254
- content,
255
- destinationPath,
256
- basePath: this.basePath
257
- });
258
225
  this.captureCurrentResult('success', st);
259
226
  return renderedFile;
260
227
  });
@@ -338,7 +305,22 @@ export class RenderContext {
338
305
  return file.findDefinitions({ name })?.[0];
339
306
  }
340
307
  }
341
- _RenderContext_captureChannel = new WeakMap(), _RenderContext_sink = new WeakMap(), _RenderContext_captures = new WeakMap();
308
+ _RenderContext_captureChannel = new WeakMap(), _RenderContext_capture = new WeakMap();
309
+ /**
310
+ * Builds the sidecar of one captured File from the spans the sink
311
+ * resolved (no re-render, no `toString`) and adds it to the capturing
312
+ * render. Keyed by the resolved artifact path, matching `artifacts` and
313
+ * the manifest, so a sidecar sits at `<outDir>/<artifact key>.skm.json`
314
+ * where doctor looks for it.
315
+ */
316
+ const addSidecar = (capture, { artifactPath, filePath, source, spans }) => {
317
+ const { parser, schemaSrc, generatorMeta } = capture.postPass;
318
+ const sidecar = postPass({ filePath, source, spans, schemaSrc, parser, generatorMeta });
319
+ capture.sidecars[artifactPath] = sidecar;
320
+ for (const entry of entriesForSidecar(sidecar)) {
321
+ capture.generationMap.push(entry);
322
+ }
323
+ };
342
324
  /**
343
325
  * Renders a single file with metadata calculation.
344
326
  *
@@ -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;