@skmtc/core 0.49.1 → 0.51.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/context/CoreContext.js +80 -3
- package/esm/context/GenerateContext.d.ts +6 -1
- package/esm/context/GenerateContext.js +149 -81
- package/esm/context/LogLinesHandler.d.ts +1 -1
- package/esm/context/LogLinesHandler.js +3 -0
- package/esm/context/ParseContext.d.ts +3 -0
- package/esm/context/ParseContext.js +36 -14
- package/esm/dsl/Definition.d.ts +7 -7
- package/esm/dsl/Definition.js +7 -7
- package/esm/dsl/PendingDefinition.d.ts +21 -5
- package/esm/dsl/PendingDefinition.js +36 -6
- package/esm/dsl/model/ModelDriver.d.ts +4 -2
- package/esm/dsl/model/ModelDriver.js +12 -12
- package/esm/helpers/toCountPhrase.d.ts +11 -0
- package/esm/helpers/toCountPhrase.js +11 -0
- package/esm/types/LogLine.d.ts +40 -1
- package/esm/types/LogLine.js +25 -0
- package/package.json +1 -1
- package/script/context/CoreContext.js +80 -3
- package/script/context/GenerateContext.d.ts +6 -1
- package/script/context/GenerateContext.js +149 -81
- package/script/context/LogLinesHandler.d.ts +1 -1
- package/script/context/LogLinesHandler.js +3 -0
- package/script/context/ParseContext.d.ts +3 -0
- package/script/context/ParseContext.js +36 -14
- package/script/dsl/Definition.d.ts +7 -7
- package/script/dsl/Definition.js +7 -7
- package/script/dsl/PendingDefinition.d.ts +21 -5
- package/script/dsl/PendingDefinition.js +36 -6
- package/script/dsl/model/ModelDriver.d.ts +4 -2
- package/script/dsl/model/ModelDriver.js +12 -12
- package/script/helpers/toCountPhrase.d.ts +11 -0
- package/script/helpers/toCountPhrase.js +15 -0
- package/script/types/LogLine.d.ts +40 -1
- package/script/types/LogLine.js +27 -1
|
@@ -9,12 +9,13 @@ 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_logLines, _CoreContext_phaseName, _CoreContext_parseIssues, _CoreContext_enrichmentWarnings, _CoreContext_setupLogger, _CoreContext_toLogTrail, _CoreContext_closeFileHandlers, _CoreContext_toRunFailedIssue, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
12
|
+
var _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_logLines, _CoreContext_logsPhaseLines, _CoreContext_phaseName, _CoreContext_parseIssues, _CoreContext_enrichmentWarnings, _CoreContext_setupLogger, _CoreContext_toLogTrail, _CoreContext_logInfo, _CoreContext_logParseLine, _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
|
+
import { LogLevels } from '../deps/jsr.io/@std/log/0.224.14/levels.js';
|
|
18
19
|
import { ResultsHandler } from './ResultsHandler.js';
|
|
19
20
|
import { LogLinesHandler } from './LogLinesHandler.js';
|
|
20
21
|
import { StackTrail } from './StackTrail.js';
|
|
@@ -23,6 +24,7 @@ import { join } from '../deps/jsr.io/@std/path/1.1.6/join.js';
|
|
|
23
24
|
import { bold, gray, red, yellow, blue } from '../deps/jsr.io/@std/fmt/1.0.10/colors.js';
|
|
24
25
|
import { toSerializedError } from '../types/SerializedError.js';
|
|
25
26
|
import { GenerationFailure } from './toGenerationFailure.js';
|
|
27
|
+
import { toCountPhrase } from '../helpers/toCountPhrase.js';
|
|
26
28
|
/**
|
|
27
29
|
* The main orchestration class for the SKMTC transformation pipeline.
|
|
28
30
|
*
|
|
@@ -116,6 +118,12 @@ export class CoreContext {
|
|
|
116
118
|
});
|
|
117
119
|
/** Keeps this run's log lines for `toArtifacts` to return. */
|
|
118
120
|
_CoreContext_logLines.set(this, void 0);
|
|
121
|
+
/**
|
|
122
|
+
* Whether the run logs its phase lines at INFO: when it is not silent and
|
|
123
|
+
* its `logLevel` keeps INFO lines. At the default `'WARN'` it logs none,
|
|
124
|
+
* so the console of a CLI run does not change.
|
|
125
|
+
*/
|
|
126
|
+
_CoreContext_logsPhaseLines.set(this, void 0);
|
|
119
127
|
/**
|
|
120
128
|
* The phase that is running. Set when a phase starts, before its
|
|
121
129
|
* context is set up, so a failure names the phase it happened in.
|
|
@@ -172,6 +180,7 @@ export class CoreContext {
|
|
|
172
180
|
}), "f");
|
|
173
181
|
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath, logLines: __classPrivateFieldGet(this, _CoreContext_logLines, "f") });
|
|
174
182
|
this.silent = silent;
|
|
183
|
+
__classPrivateFieldSet(this, _CoreContext_logsPhaseLines, !silent && LogLevels[logLevel] <= LogLevels.INFO, "f");
|
|
175
184
|
}
|
|
176
185
|
/**
|
|
177
186
|
* The trail of the subject being generated, or `undefined` outside one
|
|
@@ -288,6 +297,7 @@ export class CoreContext {
|
|
|
288
297
|
* @throws Will throw an error if any phase of the pipeline fails
|
|
289
298
|
*/
|
|
290
299
|
toArtifacts({ document, settings, toGeneratorConfigMap, stackTrail, attribution, inspect }) {
|
|
300
|
+
const runStartedAt = performance.now();
|
|
291
301
|
try {
|
|
292
302
|
// Parse phase: one unified ParseContext handles both protocols
|
|
293
303
|
// via its internal protocol-discriminated state. `parse()` returns
|
|
@@ -300,6 +310,7 @@ export class CoreContext {
|
|
|
300
310
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
301
311
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
302
312
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
313
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
303
314
|
// The shared attribution capture channel: snippets constructed
|
|
304
315
|
// during generate hold the GenerateContext, whose `captureSink`
|
|
305
316
|
// reads this slot; RenderContext flips it around the one capturing
|
|
@@ -329,6 +340,7 @@ export class CoreContext {
|
|
|
329
340
|
// map (folded into `RenderContext.render`). No separate pre-render
|
|
330
341
|
// post-pass, no re-render — the old `_rendered` cache that faked
|
|
331
342
|
// "render once" across two passes is gone.
|
|
343
|
+
const renderStartedAt = performance.now();
|
|
332
344
|
const renderOutput = stackTrail.trace('render', st => {
|
|
333
345
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'render', "f");
|
|
334
346
|
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
|
|
@@ -340,6 +352,14 @@ export class CoreContext {
|
|
|
340
352
|
}), "f");
|
|
341
353
|
return __classPrivateFieldGet(this, _CoreContext_phase, "f").context.render(st);
|
|
342
354
|
});
|
|
355
|
+
if (__classPrivateFieldGet(this, _CoreContext_logsPhaseLines, "f")) {
|
|
356
|
+
const fileCount = toCountPhrase(Object.keys(renderOutput.artifacts).length, 'file');
|
|
357
|
+
const byteCount = toCountPhrase(toByteCount(renderOutput.artifacts), 'byte');
|
|
358
|
+
this.logger.info(`render: ${fileCount}, ${byteCount}, ${toElapsedMs(renderStartedAt)} ms`);
|
|
359
|
+
this.logger.info(`toArtifacts: ${toCountPhrase(Object.keys(toGeneratorConfigMap()).length, 'generator')}, ` +
|
|
360
|
+
`${fileCount}, ${byteCount}, ${toIssueCounts(phase.context.issues)}, ` +
|
|
361
|
+
`${toElapsedMs(runStartedAt)} ms`);
|
|
362
|
+
}
|
|
343
363
|
return {
|
|
344
364
|
...renderOutput,
|
|
345
365
|
results: __classPrivateFieldGet(this, _CoreContext_results, "f").toTree(),
|
|
@@ -385,6 +405,7 @@ export class CoreContext {
|
|
|
385
405
|
* no render. Returns the subjects each generator supports, plus parse issues.
|
|
386
406
|
*/
|
|
387
407
|
toSupportedSubjects({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
408
|
+
const runStartedAt = performance.now();
|
|
388
409
|
try {
|
|
389
410
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
390
411
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
@@ -392,6 +413,7 @@ export class CoreContext {
|
|
|
392
413
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
393
414
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
394
415
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
416
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
395
417
|
const subjects = stackTrail.trace('generate', () => {
|
|
396
418
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
397
419
|
// Capability probing never renders, so the capture interval never
|
|
@@ -405,6 +427,8 @@ export class CoreContext {
|
|
|
405
427
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
406
428
|
return generatePhase.context.toSupportedSubjects();
|
|
407
429
|
});
|
|
430
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logInfo).call(this, `toSupportedSubjects: ${toCountPhrase(Object.keys(subjects).length, 'generator')}, ` +
|
|
431
|
+
`${toIssueCounts(phase.context.issues)}, ${toElapsedMs(runStartedAt)} ms`);
|
|
408
432
|
return { subjects, parseIssues: phase.context.issues };
|
|
409
433
|
}
|
|
410
434
|
catch (error) {
|
|
@@ -431,6 +455,7 @@ export class CoreContext {
|
|
|
431
455
|
* defaults map is returned empty.
|
|
432
456
|
*/
|
|
433
457
|
toEnrichmentDefaults({ document, settings, toGeneratorConfigMap, stackTrail }) {
|
|
458
|
+
const runStartedAt = performance.now();
|
|
434
459
|
try {
|
|
435
460
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
436
461
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
@@ -438,6 +463,7 @@ export class CoreContext {
|
|
|
438
463
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
439
464
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
440
465
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
466
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
441
467
|
const enrichmentDefaults = stackTrail.trace('generate', () => {
|
|
442
468
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
443
469
|
// Seeding never renders, so the capture interval never opens — a
|
|
@@ -451,6 +477,8 @@ export class CoreContext {
|
|
|
451
477
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
452
478
|
return generatePhase.context.toEnrichmentDefaults();
|
|
453
479
|
});
|
|
480
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logInfo).call(this, `toEnrichmentDefaults: ${toCountPhrase(Object.keys(enrichmentDefaults).length, 'generator')} with defaults, ` +
|
|
481
|
+
`${toIssueCounts(phase.context.issues)}, ${toElapsedMs(runStartedAt)} ms`);
|
|
454
482
|
return { enrichmentDefaults, parseIssues: phase.context.issues };
|
|
455
483
|
}
|
|
456
484
|
catch (error) {
|
|
@@ -487,7 +515,7 @@ export class CoreContext {
|
|
|
487
515
|
__classPrivateFieldGet(this, _CoreContext_results, "f").capture(stackTrail, result);
|
|
488
516
|
}
|
|
489
517
|
}
|
|
490
|
-
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_logLines = new WeakMap(), _CoreContext_phaseName = new WeakMap(), _CoreContext_parseIssues = new WeakMap(), _CoreContext_enrichmentWarnings = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger({ spanId, logsPath, logLines }) {
|
|
518
|
+
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_logLines = new WeakMap(), _CoreContext_logsPhaseLines = new WeakMap(), _CoreContext_phaseName = new WeakMap(), _CoreContext_parseIssues = new WeakMap(), _CoreContext_enrichmentWarnings = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger({ spanId, logsPath, logLines }) {
|
|
491
519
|
const fileHandlers = logsPath
|
|
492
520
|
? [
|
|
493
521
|
new log.FileHandler('DEBUG', {
|
|
@@ -514,6 +542,36 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
|
|
|
514
542
|
});
|
|
515
543
|
}, _CoreContext_toLogTrail = function _CoreContext_toLogTrail() {
|
|
516
544
|
return this.currentSubjectTrail?.toString() ?? 'SKIPPED';
|
|
545
|
+
}, _CoreContext_logInfo = function _CoreContext_logInfo(message) {
|
|
546
|
+
if (__classPrivateFieldGet(this, _CoreContext_logsPhaseLines, "f")) {
|
|
547
|
+
this.logger.info(message);
|
|
548
|
+
}
|
|
549
|
+
}, _CoreContext_logParseLine = function _CoreContext_logParseLine(document, issues, startedAt) {
|
|
550
|
+
if (!__classPrivateFieldGet(this, _CoreContext_logsPhaseLines, "f")) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const issueCounts = toIssueCounts(issues);
|
|
554
|
+
const milliseconds = toElapsedMs(startedAt);
|
|
555
|
+
switch (document.type) {
|
|
556
|
+
case 'oas': {
|
|
557
|
+
const { openapi, operations, webhooks, components } = document.value;
|
|
558
|
+
const webhookCount = webhooks.length > 0 ? `${toCountPhrase(webhooks.length, 'webhook')}, ` : '';
|
|
559
|
+
const modelCount = components?.toSchemasRefNames().length ?? 0;
|
|
560
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logInfo).call(this, `parse: OpenAPI ${openapi}, ${toCountPhrase(operations.length, 'operation')}, ${webhookCount}` +
|
|
561
|
+
`${toCountPhrase(modelCount, 'model')}, ${issueCounts}, ${milliseconds} ms`);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case 'gql': {
|
|
565
|
+
const { operations, registry } = document.value;
|
|
566
|
+
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logInfo).call(this, `parse: GraphQL, ${toCountPhrase(operations.length, 'operation')}, ` +
|
|
567
|
+
`${toCountPhrase(registry.toSchemasRefNames().length, 'model')}, ${issueCounts}, ${milliseconds} ms`);
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
default: {
|
|
571
|
+
const _exhaustive = document;
|
|
572
|
+
throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
517
575
|
}, _CoreContext_closeFileHandlers = function _CoreContext_closeFileHandlers() {
|
|
518
576
|
this.logger.handlers.forEach(handler => {
|
|
519
577
|
if (handler instanceof log.FileHandler) {
|
|
@@ -554,7 +612,8 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
|
|
|
554
612
|
logger: this.logger,
|
|
555
613
|
captureCurrentResult: this.captureCurrentResult.bind(this),
|
|
556
614
|
toGeneratorConfigMap,
|
|
557
|
-
captureChannel
|
|
615
|
+
captureChannel,
|
|
616
|
+
logsGeneratorLines: __classPrivateFieldGet(this, _CoreContext_logsPhaseLines, "f")
|
|
558
617
|
});
|
|
559
618
|
return { type: 'generate', context: generateContext };
|
|
560
619
|
}, _CoreContext_setupRenderPhase = function _CoreContext_setupRenderPhase({ files, previews, basePath, attribution, captureChannel }) {
|
|
@@ -569,6 +628,24 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
|
|
|
569
628
|
});
|
|
570
629
|
return { type: 'render', context: renderContext };
|
|
571
630
|
};
|
|
631
|
+
/** Milliseconds since `startedAt`, a `performance.now()` reading, rounded. */
|
|
632
|
+
const toElapsedMs = (startedAt) => Math.round(performance.now() - startedAt);
|
|
633
|
+
/** The size of the artifacts in UTF-8 bytes. */
|
|
634
|
+
const toByteCount = (artifacts) => {
|
|
635
|
+
const encoder = new TextEncoder();
|
|
636
|
+
return Object.values(artifacts).reduce((total, content) => total + encoder.encode(content).length, 0);
|
|
637
|
+
};
|
|
638
|
+
/** The issues by level: `0 errors, 1 warning, 2 debug`. */
|
|
639
|
+
const toIssueCounts = (issues) => {
|
|
640
|
+
const errors = issues.filter(issue => issue.level === 'error').length;
|
|
641
|
+
const warnings = issues.filter(issue => issue.level === 'warning').length;
|
|
642
|
+
const debug = issues.filter(issue => issue.level === 'debug').length;
|
|
643
|
+
return [
|
|
644
|
+
toCountPhrase(errors, 'error'),
|
|
645
|
+
toCountPhrase(warnings, 'warning'),
|
|
646
|
+
toCountPhrase(debug, 'debug', 'debug')
|
|
647
|
+
].join(', ');
|
|
648
|
+
};
|
|
572
649
|
/**
|
|
573
650
|
* Custom pretty-print formatter for SKMTC log entries.
|
|
574
651
|
*
|
|
@@ -50,6 +50,11 @@ type ConstructorArgs = {
|
|
|
50
50
|
* (tests, capture-less runs) `captureSink` is always `undefined`.
|
|
51
51
|
*/
|
|
52
52
|
captureChannel?: CaptureChannel;
|
|
53
|
+
/**
|
|
54
|
+
* Whether each generator logs an INFO line after it ran. Defaults to
|
|
55
|
+
* `false`; `CoreContext` turns it on when the run keeps INFO lines.
|
|
56
|
+
*/
|
|
57
|
+
logsGeneratorLines?: boolean;
|
|
53
58
|
};
|
|
54
59
|
/**
|
|
55
60
|
* Arguments for applying package imports to a generated file.
|
|
@@ -154,7 +159,7 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
154
159
|
toGeneratorConfigMap: <EnrichmentType = undefined>() => GeneratorsMapContainer<EnrichmentType>;
|
|
155
160
|
/** The pending models, outermost first: the last is the model whose projection constructor is running. */
|
|
156
161
|
pendingStack: PendingDefinition[];
|
|
157
|
-
constructor({ document, settings, logger, captureCurrentResult, toGeneratorConfigMap, captureChannel }: ConstructorArgs);
|
|
162
|
+
constructor({ document, settings, logger, captureCurrentResult, toGeneratorConfigMap, captureChannel, logsGeneratorLines }: ConstructorArgs);
|
|
158
163
|
/**
|
|
159
164
|
* The recording enrichment accessor — the single choke point every
|
|
160
165
|
* enrichment lookup routes through (dispatch loops, projection-base
|