@skmtc/core 0.36.0 → 0.37.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 (55) hide show
  1. package/esm/_dnt.polyfills.d.ts +6 -6
  2. package/esm/context/CoreContext.d.ts +10 -2
  3. package/esm/context/CoreContext.js +158 -87
  4. package/esm/context/GenerateContext.d.ts +11 -0
  5. package/esm/context/GenerateContext.js +44 -16
  6. package/esm/context/LogLinesHandler.d.ts +28 -0
  7. package/esm/context/LogLinesHandler.js +65 -0
  8. package/esm/context/ParseContext.js +22 -3
  9. package/esm/context/ParseIssue.d.ts +12 -9
  10. package/esm/context/ParseIssue.js +7 -6
  11. package/esm/context/ResultsHandler.d.ts +5 -3
  12. package/esm/context/ResultsHandler.js +11 -5
  13. package/esm/context/generateTypes.d.ts +21 -2
  14. package/esm/context/generateTypes.js +2 -1
  15. package/esm/mod.d.ts +2 -0
  16. package/esm/mod.js +2 -0
  17. package/esm/parse/v3-0/server/toServerV3.js +11 -1
  18. package/esm/parse/v3-1/server/toServerV3.js +11 -1
  19. package/esm/parse/v3-2/server/toServerV3.js +11 -1
  20. package/esm/run/toArtifacts.d.ts +9 -1
  21. package/esm/run/toArtifacts.js +4 -4
  22. package/esm/types/LogLine.d.ts +36 -0
  23. package/esm/types/LogLine.js +26 -0
  24. package/esm/types/Manifest.d.ts +1 -1
  25. package/esm/types/Manifest.js +16 -4
  26. package/esm/types/SerializedError.d.ts +25 -0
  27. package/esm/types/SerializedError.js +50 -0
  28. package/package.json +1 -1
  29. package/script/_dnt.polyfills.d.ts +6 -6
  30. package/script/context/CoreContext.d.ts +10 -2
  31. package/script/context/CoreContext.js +158 -87
  32. package/script/context/GenerateContext.d.ts +11 -0
  33. package/script/context/GenerateContext.js +44 -16
  34. package/script/context/LogLinesHandler.d.ts +28 -0
  35. package/script/context/LogLinesHandler.js +69 -0
  36. package/script/context/ParseContext.js +22 -3
  37. package/script/context/ParseIssue.d.ts +12 -9
  38. package/script/context/ParseIssue.js +7 -6
  39. package/script/context/ResultsHandler.d.ts +5 -3
  40. package/script/context/ResultsHandler.js +11 -5
  41. package/script/context/generateTypes.d.ts +21 -2
  42. package/script/context/generateTypes.js +2 -1
  43. package/script/mod.d.ts +2 -0
  44. package/script/mod.js +2 -0
  45. package/script/parse/v3-0/server/toServerV3.js +11 -1
  46. package/script/parse/v3-1/server/toServerV3.js +11 -1
  47. package/script/parse/v3-2/server/toServerV3.js +11 -1
  48. package/script/run/toArtifacts.d.ts +9 -1
  49. package/script/run/toArtifacts.js +4 -4
  50. package/script/types/LogLine.d.ts +36 -0
  51. package/script/types/LogLine.js +62 -0
  52. package/script/types/Manifest.d.ts +1 -1
  53. package/script/types/Manifest.js +16 -4
  54. package/script/types/SerializedError.d.ts +25 -0
  55. package/script/types/SerializedError.js +87 -0
@@ -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);
@@ -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;
@@ -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;
@@ -6,7 +6,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _ResultsHandler_instances, _ResultsHandler_unloadCallback, _ResultsHandler_resetBuffer;
7
7
  import { LogLevels } from '../deps/jsr.io/@std/log/0.224.14/levels.js';
8
8
  import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js';
9
- import { StackTrail } from './StackTrail.js';
10
9
  export class ResultsHandler extends BaseHandler {
11
10
  /**
12
11
  * Creates a new ResultsHandler instance.
@@ -87,10 +86,11 @@ export class ResultsHandler extends BaseHandler {
87
86
  /**
88
87
  * Captures log messages as results in the context.
89
88
  *
90
- * Converts log level names to result types and captures them
91
- * in the associated CoreContext for later analysis.
89
+ * Converts log level names to result types and captures them in the
90
+ * associated CoreContext at the trail of the subject being generated.
91
+ * A line logged outside a subject records nothing.
92
92
  *
93
- * @param levelName - The log level name ('WARN' or 'ERROR')
93
+ * @param levelName - The log level name ('WARN', 'ERROR' or 'CRITICAL')
94
94
  *
95
95
  * @throws {Error} When an unsupported log level is provided
96
96
  *
@@ -99,6 +99,7 @@ export class ResultsHandler extends BaseHandler {
99
99
  * // This is called automatically by the logging system
100
100
  * handler.log('WARN'); // Captures as 'warning' result
101
101
  * handler.log('ERROR'); // Captures as 'error' result
102
+ * handler.log('CRITICAL'); // Captures as 'error' result
102
103
  * ```
103
104
  */
104
105
  log(levelName) {
@@ -108,12 +109,17 @@ export class ResultsHandler extends BaseHandler {
108
109
  resultType = 'warning';
109
110
  break;
110
111
  case 'ERROR':
112
+ case 'CRITICAL':
111
113
  resultType = 'error';
112
114
  break;
113
115
  default:
114
116
  throw new Error(`Unexpected log level name: ${levelName}`);
115
117
  }
116
- this.context.captureCurrentResult(resultType, new StackTrail(['SKIPPED']));
118
+ // Outside a subject there is no result to record against.
119
+ const subjectTrail = this.context.currentSubjectTrail;
120
+ if (subjectTrail !== undefined) {
121
+ this.context.captureCurrentResult(resultType, subjectTrail);
122
+ }
117
123
  }
118
124
  /**
119
125
  * Flushes any buffered content.
@@ -28,6 +28,8 @@ import type { GqlOperationProjection } from '../dsl/operation/gql/types.js';
28
28
  import type { GqlOperation } from '../gql/operation/GqlOperation.js';
29
29
  import type { SkmtcParsedDocument } from '../types/SkmtcDocument.js';
30
30
  import type { AttributionState } from '../types/AttributionState.js';
31
+ import type { Logger } from '../types/Logger.js';
32
+ import type { LogLine } from '../types/LogLine.js';
31
33
  import type { EnrichmentWarning } from '../enrichments/EnrichmentWarning.js';
32
34
  import type { CaptureSink } from '../anchors/CaptureSink.js';
33
35
  import type { Sidecar } from '../anchors/sidecar.js';
@@ -143,6 +145,13 @@ export type ToArtifactsResult = RenderResult & {
143
145
  * the VS Code debugger views.
144
146
  */
145
147
  inspection?: unknown;
148
+ /**
149
+ * The lines the run's logger received at or above the `logLevel`
150
+ * `toArtifacts` was called with (`'WARN'` by default), in order. A
151
+ * line logged while a subject was generated carries the subject's
152
+ * trail, which is also its key in `results`.
153
+ */
154
+ logs: LogLine[];
146
155
  };
147
156
  /**
148
157
  * Union type representing any supported OpenAPI document version.
@@ -166,8 +175,12 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
166
175
  * body, and its keys include a range: `application/*`, or `*\/*` with a
167
176
  * scalar schema (a text body or a file). A body with only specific
168
177
  * non-JSON types (`multipart/form-data`, `text/plain`) logs nothing.
178
+ *
179
+ * `RUN_FAILED` (`error`) — the run itself failed outside the per-item
180
+ * catches. Its `location` names the entry and phase, for example
181
+ * `toArtifacts:render`.
169
182
  */
170
- export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
183
+ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE' | 'RUN_FAILED';
171
184
  /**
172
185
  * Valibot schema for {@link OasIssueType}. Annotation deliberately omitted
173
186
  * so the precise literal-union output type flows through to consumers
@@ -175,7 +188,7 @@ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISS
175
188
  * this list and {@link OasIssueType} is caught by `assertSchemaMatchesType`
176
189
  * below.
177
190
  */
178
- export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
191
+ export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>, v.LiteralSchema<"RUN_FAILED", undefined>], undefined>;
179
192
  export type GenerateResult = {
180
193
  files: Map<string, FileBase>;
181
194
  previews: Record<string, Preview>;
@@ -396,6 +409,12 @@ export type ToWebhookSettingsArgs<V extends GeneratedValue, EnrichmentType = und
396
409
  export type InsertNormalizedModelReturn<V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid> = Schema extends OasRef<'schema'> ? DefinitionBase<V> : DefinitionBase<TypeSystemOutput<SchemaToNonRef<Schema>['type']>>;
397
410
  export type GenerateContextType = {
398
411
  settings: ClientSettings | undefined;
412
+ /**
413
+ * The run's logger. A line logged inside a transform carries the
414
+ * subject's stack trail, and a `warn` or `error` line sets the
415
+ * subject's result to `'warning'` or `'error'`.
416
+ */
417
+ logger: Logger;
399
418
  modelDepth: Record<string, number>;
400
419
  document: SkmtcParsedDocument;
401
420
  /**
@@ -35,7 +35,8 @@ export const oasIssueType = v.union([
35
35
  v.literal('INVALID_EXTERNAL_DOCS'),
36
36
  v.literal('UNSUPPORTED_OPERATION_METHOD'),
37
37
  v.literal('WILDCARD_MEDIA_TYPE'),
38
- v.literal('NO_JSON_MEDIA_TYPE')
38
+ v.literal('NO_JSON_MEDIA_TYPE'),
39
+ v.literal('RUN_FAILED')
39
40
  ]);
40
41
  // Compile-time drift detector: this binding fails to type-check if
41
42
  // `OasIssueType` and the literal list above disagree in either
package/esm/mod.d.ts CHANGED
@@ -204,6 +204,8 @@ export * from './types/Modifiers.js';
204
204
  export * from './types/ModuleExport.js';
205
205
  export * from './types/ModuleSelect.js';
206
206
  export * from './types/SchemaPath.js';
207
+ export * from './types/SerializedError.js';
208
+ export * from './types/LogLine.js';
207
209
  export * from './enrichments/toEnrichmentDescriptor.js';
208
210
  export * from './enrichments/validateConfig.js';
209
211
  export * from './enrichments/readEnrichments.js';
package/esm/mod.js CHANGED
@@ -202,6 +202,8 @@ export * from './types/Modifiers.js';
202
202
  export * from './types/ModuleExport.js';
203
203
  export * from './types/ModuleSelect.js';
204
204
  export * from './types/SchemaPath.js';
205
+ export * from './types/SerializedError.js';
206
+ export * from './types/LogLine.js';
205
207
  export * from './enrichments/toEnrichmentDescriptor.js';
206
208
  export * from './enrichments/validateConfig.js';
207
209
  export * from './enrichments/readEnrichments.js';
@@ -3,6 +3,16 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
3
3
  import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
4
4
  import { tryParseAt } from '../../../context/tryParseAt.js';
5
5
  export const toServersV3 = ({ servers, stackTrail, context }) => {
6
+ if (!Array.isArray(servers)) {
7
+ context.logIssueNoKey({
8
+ level: 'error',
9
+ stackTrail,
10
+ parent: servers,
11
+ message: '"servers" must be an array; left out',
12
+ type: 'INVALID_OPERATION'
13
+ });
14
+ return [];
15
+ }
6
16
  return servers.flatMap((server, index) => {
7
17
  const parsed = tryParseAt({
8
18
  stackTrail,
@@ -21,7 +31,7 @@ export const toServersV3 = ({ servers, stackTrail, context }) => {
21
31
  });
22
32
  };
23
33
  export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
24
- if (!servers) {
34
+ if (servers === undefined || servers === null) {
25
35
  return undefined;
26
36
  }
27
37
  return toServersV3({ servers, stackTrail, context });
@@ -3,6 +3,16 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
3
3
  import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
4
4
  import { tryParseAt } from '../../../context/tryParseAt.js';
5
5
  export const toServersV3 = ({ servers, stackTrail, context }) => {
6
+ if (!Array.isArray(servers)) {
7
+ context.logIssueNoKey({
8
+ level: 'error',
9
+ stackTrail,
10
+ parent: servers,
11
+ message: '"servers" must be an array; left out',
12
+ type: 'INVALID_OPERATION'
13
+ });
14
+ return [];
15
+ }
6
16
  return servers.flatMap((server, index) => {
7
17
  const parsed = tryParseAt({
8
18
  stackTrail,
@@ -21,7 +31,7 @@ export const toServersV3 = ({ servers, stackTrail, context }) => {
21
31
  });
22
32
  };
23
33
  export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
24
- if (!servers) {
34
+ if (servers === undefined || servers === null) {
25
35
  return undefined;
26
36
  }
27
37
  return toServersV3({ servers, stackTrail, context });
@@ -3,6 +3,16 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
3
3
  import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
4
4
  import { tryParseAt } from '../../../context/tryParseAt.js';
5
5
  export const toServersV3 = ({ servers, stackTrail, context }) => {
6
+ if (!Array.isArray(servers)) {
7
+ context.logIssueNoKey({
8
+ level: 'error',
9
+ stackTrail,
10
+ parent: servers,
11
+ message: '"servers" must be an array; left out',
12
+ type: 'INVALID_OPERATION'
13
+ });
14
+ return [];
15
+ }
6
16
  return servers.flatMap((server, index) => {
7
17
  const parsed = tryParseAt({
8
18
  stackTrail,
@@ -21,7 +31,7 @@ export const toServersV3 = ({ servers, stackTrail, context }) => {
21
31
  });
22
32
  };
23
33
  export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
24
- if (!servers) {
34
+ if (servers === undefined || servers === null) {
25
35
  return undefined;
26
36
  }
27
37
  return toServersV3({ servers, stackTrail, context });
@@ -6,6 +6,7 @@ import type { SkmtcDocumentInput } from '../types/SkmtcDocument.js';
6
6
  import type { AttributionState } from '../types/AttributionState.js';
7
7
  import type { Sidecar } from '../anchors/sidecar.js';
8
8
  import type { GenerationMapEntry } from '../anchors/generationMap.js';
9
+ import type { LogLine, LogLineLevel } from '../types/LogLine.js';
9
10
  /**
10
11
  * Arguments for the {@link toArtifacts} transformation function.
11
12
  *
@@ -49,6 +50,11 @@ type TransformArgs = {
49
50
  startAt: number;
50
51
  /** Whether to suppress console output during generation */
51
52
  silent: boolean;
53
+ /**
54
+ * The lowest level kept in the returned `logs`. Defaults to `'WARN'`,
55
+ * so `DEBUG` and `INFO` lines are left out unless asked for.
56
+ */
57
+ logLevel?: LogLineLevel;
52
58
  /**
53
59
  * Optional attribution (gen-maps) state. When set with a
54
60
  * `postPass` block, the pipeline emits sidecars + a generation-map index
@@ -130,9 +136,11 @@ type TransformArgs = {
130
136
  * }
131
137
  * ```
132
138
  */
133
- export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }: TransformArgs) => {
139
+ export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }: TransformArgs) => {
134
140
  artifacts: Record<string, string>;
135
141
  manifest: ManifestContent;
142
+ /** The run's log lines (see {@link LogLine}). Not part of the manifest. */
143
+ logs: LogLine[];
136
144
  sidecars?: Record<string, Sidecar>;
137
145
  generationMap?: GenerationMapEntry[];
138
146
  inspection?: unknown;
@@ -67,9 +67,9 @@ import { CoreContext } from '../context/CoreContext.js';
67
67
  * }
68
68
  * ```
69
69
  */
70
- export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }) => {
71
- const context = new CoreContext({ spanId, logsPath, silent });
72
- const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection } = context.toArtifacts({
70
+ export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }) => {
71
+ const context = new CoreContext({ spanId, logsPath, silent, logLevel });
72
+ const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection, logs } = context.toArtifacts({
73
73
  settings,
74
74
  toGeneratorConfigMap,
75
75
  document,
@@ -91,5 +91,5 @@ export const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorCo
91
91
  startAt,
92
92
  endAt: Date.now()
93
93
  };
94
- return { artifacts, manifest, sidecars, generationMap, inspection };
94
+ return { artifacts, manifest, logs, sidecars, generationMap, inspection };
95
95
  };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One structured log line that `toArtifacts` returns in `logs`.
3
+ *
4
+ * A line logged while a subject is generated carries the subject's stack
5
+ * trail in `trail`. That is the same string `manifest.results` is keyed
6
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
7
+ *
8
+ * @module LogLine
9
+ */
10
+ import * as v from 'valibot';
11
+ import { type SerializedError } from './SerializedError.js';
12
+ /** The level of a {@link LogLine}. A `CRITICAL` record is recorded as `'ERROR'`. */
13
+ export type LogLineLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
14
+ /** Valibot schema for {@link LogLineLevel}. */
15
+ export declare const logLineLevel: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
16
+ export type LogLine = {
17
+ /** Position of the line in the run, from 0. */
18
+ seq: number;
19
+ level: LogLineLevel;
20
+ /** The subject's stack trail. Absent outside a subject (parse, render). */
21
+ trail?: string;
22
+ message: string;
23
+ /** The first `Error` the line was logged with. */
24
+ error?: SerializedError;
25
+ /** When the line was logged, in milliseconds since the epoch. */
26
+ time: number;
27
+ };
28
+ /** Valibot schema for {@link LogLine}. */
29
+ export declare const logLine: v.ObjectSchema<{
30
+ readonly seq: v.NumberSchema<undefined>;
31
+ readonly level: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
32
+ readonly trail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
33
+ readonly message: v.StringSchema<undefined>;
34
+ readonly error: v.OptionalSchema<v.GenericSchema<SerializedError>, undefined>;
35
+ readonly time: v.NumberSchema<undefined>;
36
+ }, undefined>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * One structured log line that `toArtifacts` returns in `logs`.
3
+ *
4
+ * A line logged while a subject is generated carries the subject's stack
5
+ * trail in `trail`. That is the same string `manifest.results` is keyed
6
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
7
+ *
8
+ * @module LogLine
9
+ */
10
+ import * as v from 'valibot';
11
+ import { serializedError } from './SerializedError.js';
12
+ /** Valibot schema for {@link LogLineLevel}. */
13
+ export const logLineLevel = v.picklist(['DEBUG', 'INFO', 'WARN', 'ERROR']);
14
+ const _logLineLevelDriftCheck = logLineLevel;
15
+ void _logLineLevelDriftCheck;
16
+ /** Valibot schema for {@link LogLine}. */
17
+ export const logLine = v.object({
18
+ seq: v.number(),
19
+ level: logLineLevel,
20
+ trail: v.optional(v.string()),
21
+ message: v.string(),
22
+ error: v.optional(serializedError),
23
+ time: v.number()
24
+ });
25
+ const _logLineDriftCheck = logLine;
26
+ void _logLineDriftCheck;
@@ -121,4 +121,4 @@ export type ManifestContent = {
121
121
  startAt: number;
122
122
  endAt: number;
123
123
  };
124
- export declare const manifestContent: v.GenericSchema<ManifestContent>;
124
+ export declare const manifestContent: v.GenericSchema<unknown, ManifestContent>;