@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
@@ -6,6 +6,16 @@ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toS
6
6
  const toServerVariableV3_js_1 = require("../serverVariable/toServerVariableV3.js");
7
7
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
8
8
  const toServersV3 = ({ servers, stackTrail, context }) => {
9
+ if (!Array.isArray(servers)) {
10
+ context.logIssueNoKey({
11
+ level: 'error',
12
+ stackTrail,
13
+ parent: servers,
14
+ message: '"servers" must be an array; left out',
15
+ type: 'INVALID_OPERATION'
16
+ });
17
+ return [];
18
+ }
9
19
  return servers.flatMap((server, index) => {
10
20
  const parsed = (0, tryParseAt_js_1.tryParseAt)({
11
21
  stackTrail,
@@ -25,7 +35,7 @@ const toServersV3 = ({ servers, stackTrail, context }) => {
25
35
  };
26
36
  exports.toServersV3 = toServersV3;
27
37
  const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
28
- if (!servers) {
38
+ if (servers === undefined || servers === null) {
29
39
  return undefined;
30
40
  }
31
41
  return (0, exports.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;
@@ -70,9 +70,9 @@ const CoreContext_js_1 = require("../context/CoreContext.js");
70
70
  * }
71
71
  * ```
72
72
  */
73
- const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, stackTrail, attribution, inspect }) => {
74
- const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent });
75
- const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection } = context.toArtifacts({
73
+ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }) => {
74
+ const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent, logLevel });
75
+ const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection, logs } = context.toArtifacts({
76
76
  settings,
77
77
  toGeneratorConfigMap,
78
78
  document,
@@ -94,6 +94,6 @@ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap
94
94
  startAt,
95
95
  endAt: Date.now()
96
96
  };
97
- return { artifacts, manifest, sidecars, generationMap, inspection };
97
+ return { artifacts, manifest, logs, sidecars, generationMap, inspection };
98
98
  };
99
99
  exports.toArtifacts = toArtifacts;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One structured log line that `toArtifacts` returns in `logs`.
3
+ *
4
+ * A line logged while a subject is generated carries the subject's stack
5
+ * trail in `trail`. That is the same string `manifest.results` is keyed
6
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
7
+ *
8
+ * @module LogLine
9
+ */
10
+ import * as v from 'valibot';
11
+ import { type SerializedError } from './SerializedError.js';
12
+ /** The level of a {@link LogLine}. A `CRITICAL` record is recorded as `'ERROR'`. */
13
+ export type LogLineLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
14
+ /** Valibot schema for {@link LogLineLevel}. */
15
+ export declare const logLineLevel: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
16
+ export type LogLine = {
17
+ /** Position of the line in the run, from 0. */
18
+ seq: number;
19
+ level: LogLineLevel;
20
+ /** The subject's stack trail. Absent outside a subject (parse, render). */
21
+ trail?: string;
22
+ message: string;
23
+ /** The first `Error` the line was logged with. */
24
+ error?: SerializedError;
25
+ /** When the line was logged, in milliseconds since the epoch. */
26
+ time: number;
27
+ };
28
+ /** Valibot schema for {@link LogLine}. */
29
+ export declare const logLine: v.ObjectSchema<{
30
+ readonly seq: v.NumberSchema<undefined>;
31
+ readonly level: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
32
+ readonly trail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
33
+ readonly message: v.StringSchema<undefined>;
34
+ readonly error: v.OptionalSchema<v.GenericSchema<SerializedError>, undefined>;
35
+ readonly time: v.NumberSchema<undefined>;
36
+ }, undefined>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * One structured log line that `toArtifacts` returns in `logs`.
4
+ *
5
+ * A line logged while a subject is generated carries the subject's stack
6
+ * trail in `trail`. That is the same string `manifest.results` is keyed
7
+ * by, so an `ERROR` line joins to the `'error'` leaf of its subject.
8
+ *
9
+ * @module LogLine
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.logLine = exports.logLineLevel = void 0;
46
+ const v = __importStar(require("valibot"));
47
+ const SerializedError_js_1 = require("./SerializedError.js");
48
+ /** Valibot schema for {@link LogLineLevel}. */
49
+ exports.logLineLevel = v.picklist(['DEBUG', 'INFO', 'WARN', 'ERROR']);
50
+ const _logLineLevelDriftCheck = exports.logLineLevel;
51
+ void _logLineLevelDriftCheck;
52
+ /** Valibot schema for {@link LogLine}. */
53
+ exports.logLine = v.object({
54
+ seq: v.number(),
55
+ level: exports.logLineLevel,
56
+ trail: v.optional(v.string()),
57
+ message: v.string(),
58
+ error: v.optional(SerializedError_js_1.serializedError),
59
+ time: v.number()
60
+ });
61
+ const _logLineDriftCheck = exports.logLine;
62
+ 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>;
@@ -112,13 +112,25 @@ const Preview_js_1 = require("./Preview.js");
112
112
  const EnrichmentWarning_js_1 = require("../enrichments/EnrichmentWarning.js");
113
113
  const generateTypes_js_1 = require("../context/generateTypes.js");
114
114
  const ParseIssue_js_1 = require("../context/ParseIssue.js");
115
+ const SerializedError_js_1 = require("./SerializedError.js");
115
116
  const v = __importStar(require("valibot"));
117
+ /**
118
+ * The `cause` of an error issue. Manifests written before core stored a
119
+ * {@link SerializedError} hold `{}` (an `Error` after `JSON.stringify`)
120
+ * or a string; those are read and converted with {@link toSerializedError}.
121
+ */
122
+ const legacyCause = v.union([v.string(), v.looseObject({})]);
123
+ const issueCause = v.union([
124
+ SerializedError_js_1.serializedError,
125
+ v.pipe(legacyCause, v.transform((legacy) => (0, SerializedError_js_1.toSerializedError)(legacy)))
126
+ ]);
116
127
  /**
117
128
  * Valibot schema for the unified {@link ParseIssue} discriminated union.
118
129
  *
119
130
  * The TS type and this schema stay in sync via the
120
- * `v.GenericSchema<ParseIssue>` annotation — adding a variant on one
121
- * side without the other fails to type-check.
131
+ * `v.GenericSchema<unknown, ParseIssue>` annotation — adding a variant on
132
+ * one side without the other fails to type-check. The input is `unknown`
133
+ * because a legacy `cause` is converted while it is read.
122
134
  */
123
135
  const parseIssue = v.variant('protocol', [
124
136
  v.variant('level', [
@@ -128,7 +140,7 @@ const parseIssue = v.variant('protocol', [
128
140
  type: generateTypes_js_1.oasIssueType,
129
141
  location: v.string(),
130
142
  message: v.string(),
131
- cause: v.optional(v.unknown())
143
+ cause: v.optional(issueCause)
132
144
  }),
133
145
  v.object({
134
146
  protocol: v.literal('oas'),
@@ -152,7 +164,7 @@ const parseIssue = v.variant('protocol', [
152
164
  type: ParseIssue_js_1.gqlIssueType,
153
165
  location: v.string(),
154
166
  message: v.string(),
155
- cause: v.optional(v.unknown())
167
+ cause: v.optional(issueCause)
156
168
  }),
157
169
  v.object({
158
170
  protocol: v.literal('gql'),
@@ -0,0 +1,25 @@
1
+ /**
2
+ * An error as data: the name, message, stack and cause chain of a thrown
3
+ * value, in a shape that survives `JSON.stringify` and structured clone.
4
+ * `JSON.stringify(new Error('x'))` gives `{}`, because an `Error`'s own
5
+ * properties are not enumerable.
6
+ *
7
+ * @module SerializedError
8
+ */
9
+ import * as v from 'valibot';
10
+ /** A thrown value as data. A non-`Error` value has the name `'NonError'`. */
11
+ export type SerializedError = {
12
+ name: string;
13
+ message: string;
14
+ stack?: string;
15
+ cause?: SerializedError;
16
+ };
17
+ /** Valibot schema for {@link SerializedError}. */
18
+ export declare const serializedError: v.GenericSchema<SerializedError>;
19
+ /**
20
+ * Converts a thrown value to a {@link SerializedError}. An `Error` keeps its
21
+ * name, message, stack and up to five levels of `cause`. Any other value
22
+ * becomes `{ name: 'NonError', message }`, where `message` is the string
23
+ * itself or the value as JSON.
24
+ */
25
+ export declare const toSerializedError: (error: unknown, depth?: number) => SerializedError;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * An error as data: the name, message, stack and cause chain of a thrown
4
+ * value, in a shape that survives `JSON.stringify` and structured clone.
5
+ * `JSON.stringify(new Error('x'))` gives `{}`, because an `Error`'s own
6
+ * properties are not enumerable.
7
+ *
8
+ * @module SerializedError
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.toSerializedError = exports.serializedError = void 0;
45
+ const v = __importStar(require("valibot"));
46
+ /** Valibot schema for {@link SerializedError}. */
47
+ exports.serializedError = v.object({
48
+ name: v.string(),
49
+ message: v.string(),
50
+ stack: v.optional(v.string()),
51
+ cause: v.optional(v.lazy(() => exports.serializedError))
52
+ });
53
+ const _serializedErrorDriftCheck = exports.serializedError;
54
+ void _serializedErrorDriftCheck;
55
+ /** How many `cause` links are followed. Also ends a cycle such as `e.cause = e`. */
56
+ const MAX_CAUSE_DEPTH = 5;
57
+ /**
58
+ * Converts a thrown value to a {@link SerializedError}. An `Error` keeps its
59
+ * name, message, stack and up to five levels of `cause`. Any other value
60
+ * becomes `{ name: 'NonError', message }`, where `message` is the string
61
+ * itself or the value as JSON.
62
+ */
63
+ const toSerializedError = (error, depth = 0) => {
64
+ if (error instanceof Error) {
65
+ return {
66
+ name: error.name,
67
+ message: error.message,
68
+ ...(error.stack ? { stack: error.stack } : {}),
69
+ ...(error.cause !== undefined && depth < MAX_CAUSE_DEPTH
70
+ ? { cause: (0, exports.toSerializedError)(error.cause, depth + 1) }
71
+ : {})
72
+ };
73
+ }
74
+ return { name: 'NonError', message: toNonErrorMessage(error) };
75
+ };
76
+ exports.toSerializedError = toSerializedError;
77
+ const toNonErrorMessage = (value) => {
78
+ if (typeof value === 'string') {
79
+ return value;
80
+ }
81
+ try {
82
+ return JSON.stringify(value) ?? String(value);
83
+ }
84
+ catch {
85
+ return String(value);
86
+ }
87
+ };