@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.
- package/esm/_dnt.polyfills.d.ts +6 -6
- package/esm/anchors/postPass.d.ts +6 -3
- package/esm/anchors/postPass.js +6 -3
- package/esm/context/CoreContext.d.ts +10 -2
- package/esm/context/CoreContext.js +158 -87
- package/esm/context/GenerateContext.d.ts +11 -0
- package/esm/context/GenerateContext.js +44 -16
- package/esm/context/LogLinesHandler.d.ts +28 -0
- package/esm/context/LogLinesHandler.js +65 -0
- package/esm/context/ParseContext.js +23 -4
- package/esm/context/ParseIssue.d.ts +12 -9
- package/esm/context/ParseIssue.js +7 -6
- package/esm/context/RenderContext.js +47 -65
- package/esm/context/ResultsHandler.d.ts +5 -3
- package/esm/context/ResultsHandler.js +11 -5
- package/esm/context/StackTrail.d.ts +14 -6
- package/esm/context/StackTrail.js +77 -29
- package/esm/context/documentTrail.d.ts +7 -3
- package/esm/context/documentTrail.js +6 -2
- package/esm/context/generateTypes.d.ts +21 -2
- package/esm/context/generateTypes.js +2 -1
- package/esm/helpers/ResultsLog.d.ts +2 -2
- package/esm/helpers/ResultsLog.js +7 -4
- package/esm/mod.d.ts +2 -0
- package/esm/mod.js +2 -0
- package/esm/run/toArtifacts.d.ts +9 -1
- package/esm/run/toArtifacts.js +4 -4
- package/esm/types/LogLine.d.ts +36 -0
- package/esm/types/LogLine.js +26 -0
- package/esm/types/Manifest.d.ts +1 -1
- package/esm/types/Manifest.js +16 -4
- package/esm/types/SerializedError.d.ts +25 -0
- package/esm/types/SerializedError.js +50 -0
- package/package.json +1 -1
- package/script/_dnt.polyfills.d.ts +6 -6
- package/script/anchors/postPass.d.ts +6 -3
- package/script/anchors/postPass.js +6 -3
- package/script/context/CoreContext.d.ts +10 -2
- package/script/context/CoreContext.js +158 -87
- package/script/context/GenerateContext.d.ts +11 -0
- package/script/context/GenerateContext.js +44 -16
- package/script/context/LogLinesHandler.d.ts +28 -0
- package/script/context/LogLinesHandler.js +69 -0
- package/script/context/ParseContext.js +23 -4
- package/script/context/ParseIssue.d.ts +12 -9
- package/script/context/ParseIssue.js +7 -6
- package/script/context/RenderContext.js +47 -65
- package/script/context/ResultsHandler.d.ts +5 -3
- package/script/context/ResultsHandler.js +11 -5
- package/script/context/StackTrail.d.ts +14 -6
- package/script/context/StackTrail.js +76 -28
- package/script/context/documentTrail.d.ts +7 -3
- package/script/context/documentTrail.js +9 -3
- package/script/context/generateTypes.d.ts +21 -2
- package/script/context/generateTypes.js +2 -1
- package/script/helpers/ResultsLog.d.ts +2 -2
- package/script/helpers/ResultsLog.js +7 -4
- package/script/mod.d.ts +2 -0
- package/script/mod.js +2 -0
- package/script/run/toArtifacts.d.ts +9 -1
- package/script/run/toArtifacts.js +4 -4
- package/script/types/LogLine.d.ts +36 -0
- package/script/types/LogLine.js +62 -0
- package/script/types/Manifest.d.ts +1 -1
- package/script/types/Manifest.js +16 -4
- package/script/types/SerializedError.d.ts +25 -0
- package/script/types/SerializedError.js +87 -0
package/esm/types/Manifest.js
CHANGED
|
@@ -76,13 +76,25 @@ import { preview } from './Preview.js';
|
|
|
76
76
|
import { enrichmentWarning } from '../enrichments/EnrichmentWarning.js';
|
|
77
77
|
import { oasIssueType } from '../context/generateTypes.js';
|
|
78
78
|
import { gqlIssueType } from '../context/ParseIssue.js';
|
|
79
|
+
import { serializedError, toSerializedError } from './SerializedError.js';
|
|
79
80
|
import * as v from 'valibot';
|
|
81
|
+
/**
|
|
82
|
+
* The `cause` of an error issue. Manifests written before core stored a
|
|
83
|
+
* {@link SerializedError} hold `{}` (an `Error` after `JSON.stringify`)
|
|
84
|
+
* or a string; those are read and converted with {@link toSerializedError}.
|
|
85
|
+
*/
|
|
86
|
+
const legacyCause = v.union([v.string(), v.looseObject({})]);
|
|
87
|
+
const issueCause = v.union([
|
|
88
|
+
serializedError,
|
|
89
|
+
v.pipe(legacyCause, v.transform((legacy) => toSerializedError(legacy)))
|
|
90
|
+
]);
|
|
80
91
|
/**
|
|
81
92
|
* Valibot schema for the unified {@link ParseIssue} discriminated union.
|
|
82
93
|
*
|
|
83
94
|
* The TS type and this schema stay in sync via the
|
|
84
|
-
* `v.GenericSchema<ParseIssue>` annotation — adding a variant on
|
|
85
|
-
* side without the other fails to type-check.
|
|
95
|
+
* `v.GenericSchema<unknown, ParseIssue>` annotation — adding a variant on
|
|
96
|
+
* one side without the other fails to type-check. The input is `unknown`
|
|
97
|
+
* because a legacy `cause` is converted while it is read.
|
|
86
98
|
*/
|
|
87
99
|
const parseIssue = v.variant('protocol', [
|
|
88
100
|
v.variant('level', [
|
|
@@ -92,7 +104,7 @@ const parseIssue = v.variant('protocol', [
|
|
|
92
104
|
type: oasIssueType,
|
|
93
105
|
location: v.string(),
|
|
94
106
|
message: v.string(),
|
|
95
|
-
cause: v.optional(
|
|
107
|
+
cause: v.optional(issueCause)
|
|
96
108
|
}),
|
|
97
109
|
v.object({
|
|
98
110
|
protocol: v.literal('oas'),
|
|
@@ -116,7 +128,7 @@ const parseIssue = v.variant('protocol', [
|
|
|
116
128
|
type: gqlIssueType,
|
|
117
129
|
location: v.string(),
|
|
118
130
|
message: v.string(),
|
|
119
|
-
cause: v.optional(
|
|
131
|
+
cause: v.optional(issueCause)
|
|
120
132
|
}),
|
|
121
133
|
v.object({
|
|
122
134
|
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,50 @@
|
|
|
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
|
+
/** Valibot schema for {@link SerializedError}. */
|
|
11
|
+
export const serializedError = v.object({
|
|
12
|
+
name: v.string(),
|
|
13
|
+
message: v.string(),
|
|
14
|
+
stack: v.optional(v.string()),
|
|
15
|
+
cause: v.optional(v.lazy(() => serializedError))
|
|
16
|
+
});
|
|
17
|
+
const _serializedErrorDriftCheck = serializedError;
|
|
18
|
+
void _serializedErrorDriftCheck;
|
|
19
|
+
/** How many `cause` links are followed. Also ends a cycle such as `e.cause = e`. */
|
|
20
|
+
const MAX_CAUSE_DEPTH = 5;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a thrown value to a {@link SerializedError}. An `Error` keeps its
|
|
23
|
+
* name, message, stack and up to five levels of `cause`. Any other value
|
|
24
|
+
* becomes `{ name: 'NonError', message }`, where `message` is the string
|
|
25
|
+
* itself or the value as JSON.
|
|
26
|
+
*/
|
|
27
|
+
export const toSerializedError = (error, depth = 0) => {
|
|
28
|
+
if (error instanceof Error) {
|
|
29
|
+
return {
|
|
30
|
+
name: error.name,
|
|
31
|
+
message: error.message,
|
|
32
|
+
...(error.stack ? { stack: error.stack } : {}),
|
|
33
|
+
...(error.cause !== undefined && depth < MAX_CAUSE_DEPTH
|
|
34
|
+
? { cause: toSerializedError(error.cause, depth + 1) }
|
|
35
|
+
: {})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return { name: 'NonError', message: toNonErrorMessage(error) };
|
|
39
|
+
};
|
|
40
|
+
const toNonErrorMessage = (value) => {
|
|
41
|
+
if (typeof value === 'string') {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(value) ?? String(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Error {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
1
7
|
declare global {
|
|
2
8
|
interface Object {
|
|
3
9
|
/**
|
|
@@ -9,12 +15,6 @@ declare global {
|
|
|
9
15
|
}
|
|
10
16
|
}
|
|
11
17
|
export {};
|
|
12
|
-
declare global {
|
|
13
|
-
interface Error {
|
|
14
|
-
cause?: unknown;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
18
18
|
/**
|
|
19
19
|
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
20
20
|
* but instead of using npm to install additional dependencies,
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
* AST-resolve each span's landmark + path, and build the sidecar.
|
|
5
5
|
*
|
|
6
6
|
* Pure function over its inputs — no I/O, no global state, no `toString`,
|
|
7
|
-
* no pipeline hooks. The caller is `RenderContext
|
|
8
|
-
*
|
|
9
|
-
* `attribution.postPass`. The
|
|
7
|
+
* no pipeline hooks. The caller is `RenderContext`, which runs this right
|
|
8
|
+
* after each File renders, once per File, when the run supplies
|
|
9
|
+
* `attribution.postPass`. The capture channel's sink is still set at that
|
|
10
|
+
* point; it records nothing only because the sink is outside a
|
|
11
|
+
* `captureFile` call between files. So do not render snippets or call
|
|
12
|
+
* `toString` here. The CLI handles disk writes via a separate
|
|
10
13
|
* `writeSidecar` wrapper.
|
|
11
14
|
*/
|
|
12
15
|
import type { ParserAdapter } from './ParserAdapter.js';
|
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
* AST-resolve each span's landmark + path, and build the sidecar.
|
|
6
6
|
*
|
|
7
7
|
* Pure function over its inputs — no I/O, no global state, no `toString`,
|
|
8
|
-
* no pipeline hooks. The caller is `RenderContext
|
|
9
|
-
*
|
|
10
|
-
* `attribution.postPass`. The
|
|
8
|
+
* no pipeline hooks. The caller is `RenderContext`, which runs this right
|
|
9
|
+
* after each File renders, once per File, when the run supplies
|
|
10
|
+
* `attribution.postPass`. The capture channel's sink is still set at that
|
|
11
|
+
* point; it records nothing only because the sink is outside a
|
|
12
|
+
* `captureFile` call between files. So do not render snippets or call
|
|
13
|
+
* `toString` here. The CLI handles disk writes via a separate
|
|
11
14
|
* `writeSidecar` wrapper.
|
|
12
15
|
*/
|
|
13
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5,7 +5,8 @@ import type { OasDocument } from '../oas/document/Document.js';
|
|
|
5
5
|
import type { ClientSettings } from '../types/Settings.js';
|
|
6
6
|
import type { ResultType } from '../types/Results.js';
|
|
7
7
|
import type { Logger } from '../types/Logger.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { LogLineLevel } from '../types/LogLine.js';
|
|
9
|
+
import { StackTrail } from './StackTrail.js';
|
|
9
10
|
import type { GeneratorsMapContainer } from '../types/GeneratorType.js';
|
|
10
11
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
11
12
|
import type { ToArtifactsResult } from './generateTypes.js';
|
|
@@ -62,6 +63,8 @@ type CoreContextArgs = {
|
|
|
62
63
|
spanId: string;
|
|
63
64
|
logsPath?: string;
|
|
64
65
|
silent: boolean;
|
|
66
|
+
/** The lowest level kept in the returned `logs`. Defaults to `'WARN'`. */
|
|
67
|
+
logLevel?: LogLineLevel;
|
|
65
68
|
};
|
|
66
69
|
/**
|
|
67
70
|
* Arguments for the `toArtifacts` method of CoreContext.
|
|
@@ -182,7 +185,12 @@ export declare class CoreContext {
|
|
|
182
185
|
* });
|
|
183
186
|
* ```
|
|
184
187
|
*/
|
|
185
|
-
constructor({ spanId, logsPath, silent }: CoreContextArgs);
|
|
188
|
+
constructor({ spanId, logsPath, silent, logLevel }: CoreContextArgs);
|
|
189
|
+
/**
|
|
190
|
+
* The trail of the subject being generated, or `undefined` outside one
|
|
191
|
+
* (parse, render, and generate work that is not a subject's variant).
|
|
192
|
+
*/
|
|
193
|
+
get currentSubjectTrail(): StackTrail | undefined;
|
|
186
194
|
/**
|
|
187
195
|
* Parses an OpenAPI v3 document into internal OAS objects.
|
|
188
196
|
*
|
|
@@ -43,7 +43,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
43
43
|
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");
|
|
44
44
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
45
45
|
};
|
|
46
|
-
var _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_setupLogger, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
46
|
+
var _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_logLines, _CoreContext_phaseName, _CoreContext_parseIssues, _CoreContext_setupLogger, _CoreContext_toLogTrail, _CoreContext_closeFileHandlers, _CoreContext_toRunFailedIssue, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.CoreContext = void 0;
|
|
49
49
|
exports.skmtcFormatter = skmtcFormatter;
|
|
@@ -54,9 +54,12 @@ const RenderContext_js_1 = require("./RenderContext.js");
|
|
|
54
54
|
const ParseContext_js_1 = require("./ParseContext.js");
|
|
55
55
|
const log = __importStar(require("../deps/jsr.io/@std/log/0.224.14/mod.js"));
|
|
56
56
|
const ResultsHandler_js_1 = require("./ResultsHandler.js");
|
|
57
|
+
const LogLinesHandler_js_1 = require("./LogLinesHandler.js");
|
|
58
|
+
const StackTrail_js_1 = require("./StackTrail.js");
|
|
57
59
|
const ResultsLog_js_1 = require("../helpers/ResultsLog.js");
|
|
58
60
|
const join_js_1 = require("../deps/jsr.io/@std/path/1.1.6/join.js");
|
|
59
61
|
const colors_js_1 = require("../deps/jsr.io/@std/fmt/1.0.10/colors.js");
|
|
62
|
+
const SerializedError_js_1 = require("../types/SerializedError.js");
|
|
60
63
|
/**
|
|
61
64
|
* The main orchestration class for the SKMTC transformation pipeline.
|
|
62
65
|
*
|
|
@@ -128,7 +131,7 @@ class CoreContext {
|
|
|
128
131
|
* });
|
|
129
132
|
* ```
|
|
130
133
|
*/
|
|
131
|
-
constructor({ spanId, logsPath, silent }) {
|
|
134
|
+
constructor({ spanId, logsPath, silent, logLevel = 'WARN' }) {
|
|
132
135
|
_CoreContext_instances.add(this);
|
|
133
136
|
/** Logger instance for the context */
|
|
134
137
|
Object.defineProperty(this, "logger", {
|
|
@@ -148,10 +151,62 @@ class CoreContext {
|
|
|
148
151
|
writable: true,
|
|
149
152
|
value: void 0
|
|
150
153
|
});
|
|
154
|
+
/** Keeps this run's log lines for `toArtifacts` to return. */
|
|
155
|
+
_CoreContext_logLines.set(this, void 0);
|
|
156
|
+
/**
|
|
157
|
+
* The phase that is running. Set when a phase starts, before its
|
|
158
|
+
* context is set up, so a failure names the phase it happened in.
|
|
159
|
+
*/
|
|
160
|
+
_CoreContext_phaseName.set(this, 'parse'
|
|
161
|
+
/**
|
|
162
|
+
* The issues of this run's parse context, kept after the generate and
|
|
163
|
+
* render phases replace `#phase`, so a later failure still returns them.
|
|
164
|
+
*/
|
|
165
|
+
);
|
|
166
|
+
/**
|
|
167
|
+
* The issues of this run's parse context, kept after the generate and
|
|
168
|
+
* render phases replace `#phase`, so a later failure still returns them.
|
|
169
|
+
*/
|
|
170
|
+
_CoreContext_parseIssues.set(this, []
|
|
171
|
+
/**
|
|
172
|
+
* Creates a new CoreContext instance.
|
|
173
|
+
*
|
|
174
|
+
* @param args - Configuration for the context
|
|
175
|
+
* @param args.spanId - Unique identifier for this transformation span
|
|
176
|
+
* @param args.logsPath - Optional directory path for log files
|
|
177
|
+
* @param args.silent - Whether to suppress console output
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* // Basic context with console logging
|
|
182
|
+
* const context = new CoreContext({
|
|
183
|
+
* spanId: 'my-generation',
|
|
184
|
+
* silent: false
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // Context with file logging
|
|
188
|
+
* const context = new CoreContext({
|
|
189
|
+
* spanId: 'batch-job-123',
|
|
190
|
+
* logsPath: './logs/generation',
|
|
191
|
+
* silent: true
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
);
|
|
151
196
|
__classPrivateFieldSet(this, _CoreContext_results, new ResultsLog_js_1.ResultsLog(), "f");
|
|
152
|
-
|
|
197
|
+
__classPrivateFieldSet(this, _CoreContext_logLines, new LogLinesHandler_js_1.LogLinesHandler(logLevel, {
|
|
198
|
+
toTrail: () => this.currentSubjectTrail?.toString()
|
|
199
|
+
}), "f");
|
|
200
|
+
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath, logLines: __classPrivateFieldGet(this, _CoreContext_logLines, "f") });
|
|
153
201
|
this.silent = silent;
|
|
154
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* The trail of the subject being generated, or `undefined` outside one
|
|
205
|
+
* (parse, render, and generate work that is not a subject's variant).
|
|
206
|
+
*/
|
|
207
|
+
get currentSubjectTrail() {
|
|
208
|
+
return __classPrivateFieldGet(this, _CoreContext_phase, "f")?.type === 'generate' ? __classPrivateFieldGet(this, _CoreContext_phase, "f").context.currentSubjectTrail : undefined;
|
|
209
|
+
}
|
|
155
210
|
/**
|
|
156
211
|
* Parses an OpenAPI v3 document into internal OAS objects.
|
|
157
212
|
*
|
|
@@ -264,8 +319,12 @@ class CoreContext {
|
|
|
264
319
|
// Parse phase: one unified ParseContext handles both protocols
|
|
265
320
|
// via its internal protocol-discriminated state. `parse()` returns
|
|
266
321
|
// a SkmtcParsedDocument; we collect issues from `context.issues`.
|
|
322
|
+
// A throw while the parse context is set up counts as parse.
|
|
323
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
324
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
267
325
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
268
326
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
327
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
269
328
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
270
329
|
// The shared attribution capture channel: snippets constructed
|
|
271
330
|
// during generate hold the GenerateContext, whose `captureSink`
|
|
@@ -273,6 +332,7 @@ class CoreContext {
|
|
|
273
332
|
// render. One object per run wires the two phases together.
|
|
274
333
|
const captureChannel = { sink: undefined };
|
|
275
334
|
const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
|
|
335
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
276
336
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
277
337
|
toGeneratorConfigMap,
|
|
278
338
|
document: parsedDocument,
|
|
@@ -295,6 +355,7 @@ class CoreContext {
|
|
|
295
355
|
// post-pass, no re-render — the old `_rendered` cache that faked
|
|
296
356
|
// "render once" across two passes is gone.
|
|
297
357
|
const renderOutput = stackTrail.trace('render', st => {
|
|
358
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'render', "f");
|
|
298
359
|
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
|
|
299
360
|
files,
|
|
300
361
|
previews,
|
|
@@ -309,51 +370,38 @@ class CoreContext {
|
|
|
309
370
|
results: __classPrivateFieldGet(this, _CoreContext_results, "f").toTree(),
|
|
310
371
|
parseIssues: phase.context.issues,
|
|
311
372
|
enrichmentWarnings,
|
|
312
|
-
inspection
|
|
373
|
+
inspection,
|
|
374
|
+
logs: [...__classPrivateFieldGet(this, _CoreContext_logLines, "f").lines]
|
|
313
375
|
};
|
|
314
376
|
}
|
|
315
377
|
catch (error) {
|
|
316
378
|
console.error(error);
|
|
317
|
-
this.logger.error(error);
|
|
379
|
+
this.logger.error((0, SerializedError_js_1.toSerializedError)(error).message, error);
|
|
318
380
|
// Surface the fatal error as a synthesized parse-issue so
|
|
319
381
|
// downstream consumers (CLI `generate`, the manifest writer)
|
|
320
382
|
// can tell a successful 0-file run apart from a crashed run.
|
|
321
|
-
// Before this, the catch returned `parseIssues: []` and an
|
|
322
|
-
// empty `artifacts`, which read on the CLI side as "everything
|
|
323
|
-
// generated, just nothing emitted" — silent failure.
|
|
324
383
|
//
|
|
325
|
-
//
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const fatalIssue = {
|
|
335
|
-
protocol: 'oas',
|
|
336
|
-
level: 'error',
|
|
337
|
-
type: 'INVALID_SCHEMA',
|
|
338
|
-
location: 'toArtifacts',
|
|
339
|
-
message: `Top-level toArtifacts failure: ${message}`,
|
|
340
|
-
cause: error
|
|
341
|
-
};
|
|
384
|
+
// The parse issues recorded before the throw are kept, in any
|
|
385
|
+
// phase, so incremental diagnostics aren't lost, and the
|
|
386
|
+
// top-level failure is appended on the end.
|
|
387
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
388
|
+
const fatalIssue = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, {
|
|
389
|
+
entry: 'toArtifacts',
|
|
390
|
+
protocol: document.type,
|
|
391
|
+
error
|
|
392
|
+
});
|
|
342
393
|
return {
|
|
343
394
|
artifacts: {},
|
|
344
395
|
files: {},
|
|
345
396
|
previews: {},
|
|
346
397
|
results: __classPrivateFieldGet(this, _CoreContext_results, "f").toTree(),
|
|
347
398
|
parseIssues: [...priorIssues, fatalIssue],
|
|
348
|
-
enrichmentWarnings: []
|
|
399
|
+
enrichmentWarnings: [],
|
|
400
|
+
logs: [...__classPrivateFieldGet(this, _CoreContext_logLines, "f").lines]
|
|
349
401
|
};
|
|
350
402
|
}
|
|
351
403
|
finally {
|
|
352
|
-
this.
|
|
353
|
-
if (handler instanceof log.FileHandler) {
|
|
354
|
-
handler.flush();
|
|
355
|
-
}
|
|
356
|
-
});
|
|
404
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
357
405
|
}
|
|
358
406
|
}
|
|
359
407
|
/**
|
|
@@ -363,10 +411,14 @@ class CoreContext {
|
|
|
363
411
|
*/
|
|
364
412
|
toSupportedSubjects({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
365
413
|
try {
|
|
414
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
415
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
366
416
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
367
417
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
418
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
368
419
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
369
420
|
const subjects = stackTrail.trace('generate', () => {
|
|
421
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
370
422
|
// Capability probing never renders, so the capture interval never
|
|
371
423
|
// opens — a throwaway channel satisfies the wiring.
|
|
372
424
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -381,24 +433,19 @@ class CoreContext {
|
|
|
381
433
|
return { subjects, parseIssues: phase.context.issues };
|
|
382
434
|
}
|
|
383
435
|
catch (error) {
|
|
384
|
-
this.logger.error(error);
|
|
385
|
-
const priorIssues = __classPrivateFieldGet(this,
|
|
386
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
436
|
+
this.logger.error((0, SerializedError_js_1.toSerializedError)(error).message, error);
|
|
437
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
387
438
|
return {
|
|
388
439
|
subjects: {},
|
|
389
440
|
parseIssues: [
|
|
390
441
|
...priorIssues,
|
|
391
|
-
{
|
|
392
|
-
protocol: 'oas',
|
|
393
|
-
level: 'error',
|
|
394
|
-
type: 'INVALID_SCHEMA',
|
|
395
|
-
location: 'toSupportedSubjects',
|
|
396
|
-
message: `Top-level toSupportedSubjects failure: ${message}`,
|
|
397
|
-
cause: error
|
|
398
|
-
}
|
|
442
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, { entry: 'toSupportedSubjects', protocol: document.type, error })
|
|
399
443
|
]
|
|
400
444
|
};
|
|
401
445
|
}
|
|
446
|
+
finally {
|
|
447
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
448
|
+
}
|
|
402
449
|
}
|
|
403
450
|
/**
|
|
404
451
|
* Seed-values sibling of {@link toSupportedSubjects}: parse the document, then
|
|
@@ -410,10 +457,14 @@ class CoreContext {
|
|
|
410
457
|
*/
|
|
411
458
|
toEnrichmentDefaults({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
412
459
|
try {
|
|
460
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
461
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
413
462
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
414
463
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
464
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
415
465
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
416
466
|
const enrichmentDefaults = stackTrail.trace('generate', () => {
|
|
467
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
417
468
|
// Seeding never renders, so the capture interval never opens — a
|
|
418
469
|
// throwaway channel satisfies the wiring.
|
|
419
470
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -428,24 +479,19 @@ class CoreContext {
|
|
|
428
479
|
return { enrichmentDefaults, parseIssues: phase.context.issues };
|
|
429
480
|
}
|
|
430
481
|
catch (error) {
|
|
431
|
-
this.logger.error(error);
|
|
432
|
-
const priorIssues = __classPrivateFieldGet(this,
|
|
433
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
482
|
+
this.logger.error((0, SerializedError_js_1.toSerializedError)(error).message, error);
|
|
483
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
434
484
|
return {
|
|
435
485
|
enrichmentDefaults: {},
|
|
436
486
|
parseIssues: [
|
|
437
487
|
...priorIssues,
|
|
438
|
-
{
|
|
439
|
-
protocol: 'oas',
|
|
440
|
-
level: 'error',
|
|
441
|
-
type: 'INVALID_SCHEMA',
|
|
442
|
-
location: 'toEnrichmentDefaults',
|
|
443
|
-
message: `Top-level toEnrichmentDefaults failure: ${message}`,
|
|
444
|
-
cause: error
|
|
445
|
-
}
|
|
488
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, { entry: 'toEnrichmentDefaults', protocol: document.type, error })
|
|
446
489
|
]
|
|
447
490
|
};
|
|
448
491
|
}
|
|
492
|
+
finally {
|
|
493
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
494
|
+
}
|
|
449
495
|
}
|
|
450
496
|
/**
|
|
451
497
|
* Captures a result at `stackTrail`. Each frame of the trail becomes one
|
|
@@ -467,42 +513,54 @@ class CoreContext {
|
|
|
467
513
|
}
|
|
468
514
|
}
|
|
469
515
|
exports.CoreContext = CoreContext;
|
|
470
|
-
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger({ spanId, logsPath }) {
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
516
|
+
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_logLines = new WeakMap(), _CoreContext_phaseName = new WeakMap(), _CoreContext_parseIssues = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger({ spanId, logsPath, logLines }) {
|
|
517
|
+
const fileHandlers = logsPath
|
|
518
|
+
? [
|
|
519
|
+
new log.FileHandler('DEBUG', {
|
|
520
|
+
filename: (0, join_js_1.join)(logsPath, `${spanId}.txt`),
|
|
521
|
+
// JSON format for file logs (easier to parse and analyze)
|
|
522
|
+
formatter: logRecord => skmtcJsonFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toLogTrail).call(this) })
|
|
523
|
+
})
|
|
524
|
+
]
|
|
525
|
+
: [];
|
|
526
|
+
fileHandlers.forEach(handler => handler.setup());
|
|
527
|
+
return new log.Logger(spanId, 'DEBUG', {
|
|
528
|
+
handlers: [
|
|
529
|
+
new log.ConsoleHandler('DEBUG', {
|
|
530
|
+
formatter: logRecord => skmtcFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toLogTrail).call(this) }),
|
|
479
531
|
useColors: true
|
|
480
532
|
}),
|
|
481
|
-
...
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
// JSON format for file logs (easier to parse and analyze)
|
|
485
|
-
formatter: logRecord => {
|
|
486
|
-
return skmtcJsonFormatter({
|
|
487
|
-
logRecord,
|
|
488
|
-
stackTrail: 'SKIPPED'
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
})
|
|
492
|
-
}),
|
|
493
|
-
[`${spanId}-results`]: new ResultsHandler_js_1.ResultsHandler('WARN', {
|
|
533
|
+
...fileHandlers,
|
|
534
|
+
logLines,
|
|
535
|
+
new ResultsHandler_js_1.ResultsHandler('WARN', {
|
|
494
536
|
formatter: ({ levelName }) => levelName,
|
|
495
537
|
context: this
|
|
496
538
|
})
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
539
|
+
]
|
|
540
|
+
});
|
|
541
|
+
}, _CoreContext_toLogTrail = function _CoreContext_toLogTrail() {
|
|
542
|
+
return this.currentSubjectTrail?.toString() ?? 'SKIPPED';
|
|
543
|
+
}, _CoreContext_closeFileHandlers = function _CoreContext_closeFileHandlers() {
|
|
544
|
+
this.logger.handlers.forEach(handler => {
|
|
545
|
+
if (handler instanceof log.FileHandler) {
|
|
546
|
+
handler.destroy();
|
|
503
547
|
}
|
|
504
548
|
});
|
|
505
|
-
|
|
549
|
+
}, _CoreContext_toRunFailedIssue = function _CoreContext_toRunFailedIssue({ entry, protocol, error }) {
|
|
550
|
+
const phaseName = __classPrivateFieldGet(this, _CoreContext_phaseName, "f");
|
|
551
|
+
const cause = (0, SerializedError_js_1.toSerializedError)(error);
|
|
552
|
+
const location = new StackTrail_js_1.StackTrail([entry, phaseName]).toString();
|
|
553
|
+
const message = `${phaseName} phase failed: ${cause.message}`;
|
|
554
|
+
switch (protocol) {
|
|
555
|
+
case 'oas':
|
|
556
|
+
return { protocol, level: 'error', type: 'RUN_FAILED', location, message, cause };
|
|
557
|
+
case 'gql':
|
|
558
|
+
return { protocol, level: 'error', type: 'RUN_FAILED', location, message, cause };
|
|
559
|
+
default: {
|
|
560
|
+
const _exhaustive = protocol;
|
|
561
|
+
throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
506
564
|
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input) {
|
|
507
565
|
const parseContext = new ParseContext_js_1.ParseContext({
|
|
508
566
|
input,
|
|
@@ -587,7 +645,7 @@ function skmtcFormatter({ logRecord, stackTrail }) {
|
|
|
587
645
|
// Add stack trail if it's not "SKIPPED"
|
|
588
646
|
const stackTrailLine = stackTrail !== 'SKIPPED' ? `\n${(0, colors_js_1.gray)('Stack:')} ${stackTrail}` : '';
|
|
589
647
|
// Format the message (preserve multi-line errors and stack traces)
|
|
590
|
-
const formattedMessage =
|
|
648
|
+
const formattedMessage = toMessageWithStack(logRecord);
|
|
591
649
|
return `${header}${stackTrailLine}\n${formattedMessage}\n`;
|
|
592
650
|
}
|
|
593
651
|
/**
|
|
@@ -620,10 +678,23 @@ function skmtcJsonFormatter({ logRecord, stackTrail }) {
|
|
|
620
678
|
});
|
|
621
679
|
}
|
|
622
680
|
function flattenArgs(args) {
|
|
623
|
-
|
|
624
|
-
|
|
681
|
+
const serializable = args.map(arg => (arg instanceof Error ? (0, SerializedError_js_1.toSerializedError)(arg) : arg));
|
|
682
|
+
if (serializable.length === 1) {
|
|
683
|
+
return serializable[0];
|
|
625
684
|
}
|
|
626
|
-
else if (
|
|
627
|
-
return
|
|
685
|
+
else if (serializable.length > 1) {
|
|
686
|
+
return serializable;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* `msg`, followed by the stack of the first `Error` in `args`. A line
|
|
691
|
+
* logged as `logger.error(error.message, error)` prints the stack alone,
|
|
692
|
+
* which starts with the message.
|
|
693
|
+
*/
|
|
694
|
+
function toMessageWithStack({ msg, args }) {
|
|
695
|
+
const error = args.find(arg => arg instanceof Error);
|
|
696
|
+
if (error?.stack === undefined) {
|
|
697
|
+
return msg;
|
|
628
698
|
}
|
|
699
|
+
return error.message === msg ? error.stack : `${msg}\n${error.stack}`;
|
|
629
700
|
}
|
|
@@ -170,6 +170,17 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
170
170
|
* shared channel's `sink`.
|
|
171
171
|
*/
|
|
172
172
|
get captureSink(): CaptureSink | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* The trail of the subject whose variant is being generated, or
|
|
175
|
+
* `undefined` outside one. Log lines and the results the logger
|
|
176
|
+
* records are addressed by it.
|
|
177
|
+
*/
|
|
178
|
+
get currentSubjectTrail(): StackTrail | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Runs `fn` with {@link currentSubjectTrail} set to `stackTrail`, and
|
|
181
|
+
* restores the previous value afterwards.
|
|
182
|
+
*/
|
|
183
|
+
withSubjectTrail<T>(stackTrail: StackTrail, fn: () => T): T;
|
|
173
184
|
/**
|
|
174
185
|
* @internal
|
|
175
186
|
*/
|