@skmtc/core 0.36.1 → 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.
- package/esm/_dnt.polyfills.d.ts +6 -6
- 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 +22 -3
- package/esm/context/ParseIssue.d.ts +12 -9
- package/esm/context/ParseIssue.js +7 -6
- package/esm/context/ResultsHandler.d.ts +5 -3
- package/esm/context/ResultsHandler.js +11 -5
- package/esm/context/generateTypes.d.ts +21 -2
- package/esm/context/generateTypes.js +2 -1
- 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/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 +22 -3
- package/script/context/ParseIssue.d.ts +12 -9
- package/script/context/ParseIssue.js +7 -6
- package/script/context/ResultsHandler.d.ts +5 -3
- package/script/context/ResultsHandler.js +11 -5
- package/script/context/generateTypes.d.ts +21 -2
- package/script/context/generateTypes.js +2 -1
- 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/_dnt.polyfills.d.ts
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,
|
|
@@ -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
|
*
|
|
@@ -9,16 +9,19 @@ 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 _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_setupLogger, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
12
|
+
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;
|
|
13
13
|
import { GenerateContext } from './GenerateContext.js';
|
|
14
14
|
import { toInspection } from '../run/toInspection.js';
|
|
15
15
|
import { RenderContext } from './RenderContext.js';
|
|
16
16
|
import { ParseContext } from './ParseContext.js';
|
|
17
17
|
import * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
|
|
18
18
|
import { ResultsHandler } from './ResultsHandler.js';
|
|
19
|
+
import { LogLinesHandler } from './LogLinesHandler.js';
|
|
20
|
+
import { StackTrail } from './StackTrail.js';
|
|
19
21
|
import { ResultsLog } from '../helpers/ResultsLog.js';
|
|
20
22
|
import { join } from '../deps/jsr.io/@std/path/1.1.6/join.js';
|
|
21
23
|
import { bold, gray, red, yellow, blue } from '../deps/jsr.io/@std/fmt/1.0.10/colors.js';
|
|
24
|
+
import { toSerializedError } from '../types/SerializedError.js';
|
|
22
25
|
/**
|
|
23
26
|
* The main orchestration class for the SKMTC transformation pipeline.
|
|
24
27
|
*
|
|
@@ -90,7 +93,7 @@ export class CoreContext {
|
|
|
90
93
|
* });
|
|
91
94
|
* ```
|
|
92
95
|
*/
|
|
93
|
-
constructor({ spanId, logsPath, silent }) {
|
|
96
|
+
constructor({ spanId, logsPath, silent, logLevel = 'WARN' }) {
|
|
94
97
|
_CoreContext_instances.add(this);
|
|
95
98
|
/** Logger instance for the context */
|
|
96
99
|
Object.defineProperty(this, "logger", {
|
|
@@ -110,10 +113,62 @@ export class CoreContext {
|
|
|
110
113
|
writable: true,
|
|
111
114
|
value: void 0
|
|
112
115
|
});
|
|
116
|
+
/** Keeps this run's log lines for `toArtifacts` to return. */
|
|
117
|
+
_CoreContext_logLines.set(this, void 0);
|
|
118
|
+
/**
|
|
119
|
+
* The phase that is running. Set when a phase starts, before its
|
|
120
|
+
* context is set up, so a failure names the phase it happened in.
|
|
121
|
+
*/
|
|
122
|
+
_CoreContext_phaseName.set(this, 'parse'
|
|
123
|
+
/**
|
|
124
|
+
* The issues of this run's parse context, kept after the generate and
|
|
125
|
+
* render phases replace `#phase`, so a later failure still returns them.
|
|
126
|
+
*/
|
|
127
|
+
);
|
|
128
|
+
/**
|
|
129
|
+
* The issues of this run's parse context, kept after the generate and
|
|
130
|
+
* render phases replace `#phase`, so a later failure still returns them.
|
|
131
|
+
*/
|
|
132
|
+
_CoreContext_parseIssues.set(this, []
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new CoreContext instance.
|
|
135
|
+
*
|
|
136
|
+
* @param args - Configuration for the context
|
|
137
|
+
* @param args.spanId - Unique identifier for this transformation span
|
|
138
|
+
* @param args.logsPath - Optional directory path for log files
|
|
139
|
+
* @param args.silent - Whether to suppress console output
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Basic context with console logging
|
|
144
|
+
* const context = new CoreContext({
|
|
145
|
+
* spanId: 'my-generation',
|
|
146
|
+
* silent: false
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* // Context with file logging
|
|
150
|
+
* const context = new CoreContext({
|
|
151
|
+
* spanId: 'batch-job-123',
|
|
152
|
+
* logsPath: './logs/generation',
|
|
153
|
+
* silent: true
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
);
|
|
113
158
|
__classPrivateFieldSet(this, _CoreContext_results, new ResultsLog(), "f");
|
|
114
|
-
|
|
159
|
+
__classPrivateFieldSet(this, _CoreContext_logLines, new LogLinesHandler(logLevel, {
|
|
160
|
+
toTrail: () => this.currentSubjectTrail?.toString()
|
|
161
|
+
}), "f");
|
|
162
|
+
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath, logLines: __classPrivateFieldGet(this, _CoreContext_logLines, "f") });
|
|
115
163
|
this.silent = silent;
|
|
116
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* The trail of the subject being generated, or `undefined` outside one
|
|
167
|
+
* (parse, render, and generate work that is not a subject's variant).
|
|
168
|
+
*/
|
|
169
|
+
get currentSubjectTrail() {
|
|
170
|
+
return __classPrivateFieldGet(this, _CoreContext_phase, "f")?.type === 'generate' ? __classPrivateFieldGet(this, _CoreContext_phase, "f").context.currentSubjectTrail : undefined;
|
|
171
|
+
}
|
|
117
172
|
/**
|
|
118
173
|
* Parses an OpenAPI v3 document into internal OAS objects.
|
|
119
174
|
*
|
|
@@ -226,8 +281,12 @@ export class CoreContext {
|
|
|
226
281
|
// Parse phase: one unified ParseContext handles both protocols
|
|
227
282
|
// via its internal protocol-discriminated state. `parse()` returns
|
|
228
283
|
// a SkmtcParsedDocument; we collect issues from `context.issues`.
|
|
284
|
+
// A throw while the parse context is set up counts as parse.
|
|
285
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
286
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
229
287
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
230
288
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
289
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
231
290
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
232
291
|
// The shared attribution capture channel: snippets constructed
|
|
233
292
|
// during generate hold the GenerateContext, whose `captureSink`
|
|
@@ -235,6 +294,7 @@ export class CoreContext {
|
|
|
235
294
|
// render. One object per run wires the two phases together.
|
|
236
295
|
const captureChannel = { sink: undefined };
|
|
237
296
|
const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
|
|
297
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
238
298
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
239
299
|
toGeneratorConfigMap,
|
|
240
300
|
document: parsedDocument,
|
|
@@ -257,6 +317,7 @@ export class CoreContext {
|
|
|
257
317
|
// post-pass, no re-render — the old `_rendered` cache that faked
|
|
258
318
|
// "render once" across two passes is gone.
|
|
259
319
|
const renderOutput = stackTrail.trace('render', st => {
|
|
320
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'render', "f");
|
|
260
321
|
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
|
|
261
322
|
files,
|
|
262
323
|
previews,
|
|
@@ -271,51 +332,38 @@ export class CoreContext {
|
|
|
271
332
|
results: __classPrivateFieldGet(this, _CoreContext_results, "f").toTree(),
|
|
272
333
|
parseIssues: phase.context.issues,
|
|
273
334
|
enrichmentWarnings,
|
|
274
|
-
inspection
|
|
335
|
+
inspection,
|
|
336
|
+
logs: [...__classPrivateFieldGet(this, _CoreContext_logLines, "f").lines]
|
|
275
337
|
};
|
|
276
338
|
}
|
|
277
339
|
catch (error) {
|
|
278
340
|
console.error(error);
|
|
279
|
-
this.logger.error(error);
|
|
341
|
+
this.logger.error(toSerializedError(error).message, error);
|
|
280
342
|
// Surface the fatal error as a synthesized parse-issue so
|
|
281
343
|
// downstream consumers (CLI `generate`, the manifest writer)
|
|
282
344
|
// can tell a successful 0-file run apart from a crashed run.
|
|
283
|
-
// Before this, the catch returned `parseIssues: []` and an
|
|
284
|
-
// empty `artifacts`, which read on the CLI side as "everything
|
|
285
|
-
// generated, just nothing emitted" — silent failure.
|
|
286
345
|
//
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const fatalIssue = {
|
|
297
|
-
protocol: 'oas',
|
|
298
|
-
level: 'error',
|
|
299
|
-
type: 'INVALID_SCHEMA',
|
|
300
|
-
location: 'toArtifacts',
|
|
301
|
-
message: `Top-level toArtifacts failure: ${message}`,
|
|
302
|
-
cause: error
|
|
303
|
-
};
|
|
346
|
+
// The parse issues recorded before the throw are kept, in any
|
|
347
|
+
// phase, so incremental diagnostics aren't lost, and the
|
|
348
|
+
// top-level failure is appended on the end.
|
|
349
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
350
|
+
const fatalIssue = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, {
|
|
351
|
+
entry: 'toArtifacts',
|
|
352
|
+
protocol: document.type,
|
|
353
|
+
error
|
|
354
|
+
});
|
|
304
355
|
return {
|
|
305
356
|
artifacts: {},
|
|
306
357
|
files: {},
|
|
307
358
|
previews: {},
|
|
308
359
|
results: __classPrivateFieldGet(this, _CoreContext_results, "f").toTree(),
|
|
309
360
|
parseIssues: [...priorIssues, fatalIssue],
|
|
310
|
-
enrichmentWarnings: []
|
|
361
|
+
enrichmentWarnings: [],
|
|
362
|
+
logs: [...__classPrivateFieldGet(this, _CoreContext_logLines, "f").lines]
|
|
311
363
|
};
|
|
312
364
|
}
|
|
313
365
|
finally {
|
|
314
|
-
this.
|
|
315
|
-
if (handler instanceof log.FileHandler) {
|
|
316
|
-
handler.flush();
|
|
317
|
-
}
|
|
318
|
-
});
|
|
366
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
319
367
|
}
|
|
320
368
|
}
|
|
321
369
|
/**
|
|
@@ -325,10 +373,14 @@ export class CoreContext {
|
|
|
325
373
|
*/
|
|
326
374
|
toSupportedSubjects({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
327
375
|
try {
|
|
376
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
377
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
328
378
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
329
379
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
380
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
330
381
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
331
382
|
const subjects = stackTrail.trace('generate', () => {
|
|
383
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
332
384
|
// Capability probing never renders, so the capture interval never
|
|
333
385
|
// opens — a throwaway channel satisfies the wiring.
|
|
334
386
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -343,24 +395,19 @@ export class CoreContext {
|
|
|
343
395
|
return { subjects, parseIssues: phase.context.issues };
|
|
344
396
|
}
|
|
345
397
|
catch (error) {
|
|
346
|
-
this.logger.error(error);
|
|
347
|
-
const priorIssues = __classPrivateFieldGet(this,
|
|
348
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
398
|
+
this.logger.error(toSerializedError(error).message, error);
|
|
399
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
349
400
|
return {
|
|
350
401
|
subjects: {},
|
|
351
402
|
parseIssues: [
|
|
352
403
|
...priorIssues,
|
|
353
|
-
{
|
|
354
|
-
protocol: 'oas',
|
|
355
|
-
level: 'error',
|
|
356
|
-
type: 'INVALID_SCHEMA',
|
|
357
|
-
location: 'toSupportedSubjects',
|
|
358
|
-
message: `Top-level toSupportedSubjects failure: ${message}`,
|
|
359
|
-
cause: error
|
|
360
|
-
}
|
|
404
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, { entry: 'toSupportedSubjects', protocol: document.type, error })
|
|
361
405
|
]
|
|
362
406
|
};
|
|
363
407
|
}
|
|
408
|
+
finally {
|
|
409
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
410
|
+
}
|
|
364
411
|
}
|
|
365
412
|
/**
|
|
366
413
|
* Seed-values sibling of {@link toSupportedSubjects}: parse the document, then
|
|
@@ -372,10 +419,14 @@ export class CoreContext {
|
|
|
372
419
|
*/
|
|
373
420
|
toEnrichmentDefaults({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
374
421
|
try {
|
|
422
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
423
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
375
424
|
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document);
|
|
376
425
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
426
|
+
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
377
427
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
378
428
|
const enrichmentDefaults = stackTrail.trace('generate', () => {
|
|
429
|
+
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
379
430
|
// Seeding never renders, so the capture interval never opens — a
|
|
380
431
|
// throwaway channel satisfies the wiring.
|
|
381
432
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -390,24 +441,19 @@ export class CoreContext {
|
|
|
390
441
|
return { enrichmentDefaults, parseIssues: phase.context.issues };
|
|
391
442
|
}
|
|
392
443
|
catch (error) {
|
|
393
|
-
this.logger.error(error);
|
|
394
|
-
const priorIssues = __classPrivateFieldGet(this,
|
|
395
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
444
|
+
this.logger.error(toSerializedError(error).message, error);
|
|
445
|
+
const priorIssues = __classPrivateFieldGet(this, _CoreContext_parseIssues, "f");
|
|
396
446
|
return {
|
|
397
447
|
enrichmentDefaults: {},
|
|
398
448
|
parseIssues: [
|
|
399
449
|
...priorIssues,
|
|
400
|
-
{
|
|
401
|
-
protocol: 'oas',
|
|
402
|
-
level: 'error',
|
|
403
|
-
type: 'INVALID_SCHEMA',
|
|
404
|
-
location: 'toEnrichmentDefaults',
|
|
405
|
-
message: `Top-level toEnrichmentDefaults failure: ${message}`,
|
|
406
|
-
cause: error
|
|
407
|
-
}
|
|
450
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toRunFailedIssue).call(this, { entry: 'toEnrichmentDefaults', protocol: document.type, error })
|
|
408
451
|
]
|
|
409
452
|
};
|
|
410
453
|
}
|
|
454
|
+
finally {
|
|
455
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_closeFileHandlers).call(this);
|
|
456
|
+
}
|
|
411
457
|
}
|
|
412
458
|
/**
|
|
413
459
|
* Captures a result at `stackTrail`. Each frame of the trail becomes one
|
|
@@ -428,42 +474,54 @@ export class CoreContext {
|
|
|
428
474
|
__classPrivateFieldGet(this, _CoreContext_results, "f").capture(stackTrail, result);
|
|
429
475
|
}
|
|
430
476
|
}
|
|
431
|
-
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger({ spanId, logsPath }) {
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
477
|
+
_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 }) {
|
|
478
|
+
const fileHandlers = logsPath
|
|
479
|
+
? [
|
|
480
|
+
new log.FileHandler('DEBUG', {
|
|
481
|
+
filename: join(logsPath, `${spanId}.txt`),
|
|
482
|
+
// JSON format for file logs (easier to parse and analyze)
|
|
483
|
+
formatter: logRecord => skmtcJsonFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toLogTrail).call(this) })
|
|
484
|
+
})
|
|
485
|
+
]
|
|
486
|
+
: [];
|
|
487
|
+
fileHandlers.forEach(handler => handler.setup());
|
|
488
|
+
return new log.Logger(spanId, 'DEBUG', {
|
|
489
|
+
handlers: [
|
|
490
|
+
new log.ConsoleHandler('DEBUG', {
|
|
491
|
+
formatter: logRecord => skmtcFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_toLogTrail).call(this) }),
|
|
440
492
|
useColors: true
|
|
441
493
|
}),
|
|
442
|
-
...
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
// JSON format for file logs (easier to parse and analyze)
|
|
446
|
-
formatter: logRecord => {
|
|
447
|
-
return skmtcJsonFormatter({
|
|
448
|
-
logRecord,
|
|
449
|
-
stackTrail: 'SKIPPED'
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
})
|
|
453
|
-
}),
|
|
454
|
-
[`${spanId}-results`]: new ResultsHandler('WARN', {
|
|
494
|
+
...fileHandlers,
|
|
495
|
+
logLines,
|
|
496
|
+
new ResultsHandler('WARN', {
|
|
455
497
|
formatter: ({ levelName }) => levelName,
|
|
456
498
|
context: this
|
|
457
499
|
})
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
500
|
+
]
|
|
501
|
+
});
|
|
502
|
+
}, _CoreContext_toLogTrail = function _CoreContext_toLogTrail() {
|
|
503
|
+
return this.currentSubjectTrail?.toString() ?? 'SKIPPED';
|
|
504
|
+
}, _CoreContext_closeFileHandlers = function _CoreContext_closeFileHandlers() {
|
|
505
|
+
this.logger.handlers.forEach(handler => {
|
|
506
|
+
if (handler instanceof log.FileHandler) {
|
|
507
|
+
handler.destroy();
|
|
464
508
|
}
|
|
465
509
|
});
|
|
466
|
-
|
|
510
|
+
}, _CoreContext_toRunFailedIssue = function _CoreContext_toRunFailedIssue({ entry, protocol, error }) {
|
|
511
|
+
const phaseName = __classPrivateFieldGet(this, _CoreContext_phaseName, "f");
|
|
512
|
+
const cause = toSerializedError(error);
|
|
513
|
+
const location = new StackTrail([entry, phaseName]).toString();
|
|
514
|
+
const message = `${phaseName} phase failed: ${cause.message}`;
|
|
515
|
+
switch (protocol) {
|
|
516
|
+
case 'oas':
|
|
517
|
+
return { protocol, level: 'error', type: 'RUN_FAILED', location, message, cause };
|
|
518
|
+
case 'gql':
|
|
519
|
+
return { protocol, level: 'error', type: 'RUN_FAILED', location, message, cause };
|
|
520
|
+
default: {
|
|
521
|
+
const _exhaustive = protocol;
|
|
522
|
+
throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
467
525
|
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input) {
|
|
468
526
|
const parseContext = new ParseContext({
|
|
469
527
|
input,
|
|
@@ -548,7 +606,7 @@ export function skmtcFormatter({ logRecord, stackTrail }) {
|
|
|
548
606
|
// Add stack trail if it's not "SKIPPED"
|
|
549
607
|
const stackTrailLine = stackTrail !== 'SKIPPED' ? `\n${gray('Stack:')} ${stackTrail}` : '';
|
|
550
608
|
// Format the message (preserve multi-line errors and stack traces)
|
|
551
|
-
const formattedMessage =
|
|
609
|
+
const formattedMessage = toMessageWithStack(logRecord);
|
|
552
610
|
return `${header}${stackTrailLine}\n${formattedMessage}\n`;
|
|
553
611
|
}
|
|
554
612
|
/**
|
|
@@ -581,10 +639,23 @@ export function skmtcJsonFormatter({ logRecord, stackTrail }) {
|
|
|
581
639
|
});
|
|
582
640
|
}
|
|
583
641
|
function flattenArgs(args) {
|
|
584
|
-
|
|
585
|
-
|
|
642
|
+
const serializable = args.map(arg => (arg instanceof Error ? toSerializedError(arg) : arg));
|
|
643
|
+
if (serializable.length === 1) {
|
|
644
|
+
return serializable[0];
|
|
586
645
|
}
|
|
587
|
-
else if (
|
|
588
|
-
return
|
|
646
|
+
else if (serializable.length > 1) {
|
|
647
|
+
return serializable;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* `msg`, followed by the stack of the first `Error` in `args`. A line
|
|
652
|
+
* logged as `logger.error(error.message, error)` prints the stack alone,
|
|
653
|
+
* which starts with the message.
|
|
654
|
+
*/
|
|
655
|
+
function toMessageWithStack({ msg, args }) {
|
|
656
|
+
const error = args.find(arg => arg instanceof Error);
|
|
657
|
+
if (error?.stack === undefined) {
|
|
658
|
+
return msg;
|
|
589
659
|
}
|
|
660
|
+
return error.message === msg ? error.stack : `${msg}\n${error.stack}`;
|
|
590
661
|
}
|
|
@@ -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
|
*/
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 &&
|
|
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.
|
|
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
|
});
|