@skmtc/core 0.50.0 → 0.52.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/anchors/CaptureSink.d.ts +3 -2
- package/esm/anchors/CaptureSink.js +3 -2
- package/esm/context/CoreContext.d.ts +4 -3
- package/esm/context/CoreContext.js +10 -8
- package/esm/context/GenerateContext.d.ts +8 -1
- package/esm/context/GenerateContext.js +8 -0
- package/esm/context/RenderContext.js +2 -3
- package/esm/context/generateTypes.d.ts +12 -7
- 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/SnippetBase.d.ts +5 -2
- package/esm/dsl/SnippetBase.js +18 -12
- package/esm/dsl/model/ModelDriver.d.ts +4 -2
- package/esm/dsl/model/ModelDriver.js +12 -12
- package/esm/types/AttributionState.d.ts +10 -9
- package/esm/types/AttributionState.js +10 -9
- package/package.json +1 -1
- package/script/anchors/CaptureSink.d.ts +3 -2
- package/script/anchors/CaptureSink.js +3 -2
- package/script/context/CoreContext.d.ts +4 -3
- package/script/context/CoreContext.js +10 -8
- package/script/context/GenerateContext.d.ts +8 -1
- package/script/context/GenerateContext.js +8 -0
- package/script/context/RenderContext.js +2 -3
- package/script/context/generateTypes.d.ts +12 -7
- 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/SnippetBase.d.ts +5 -2
- package/script/dsl/SnippetBase.js +18 -12
- package/script/dsl/model/ModelDriver.d.ts +4 -2
- package/script/dsl/model/ModelDriver.js +12 -12
- package/script/types/AttributionState.d.ts +10 -9
- package/script/types/AttributionState.js +10 -9
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
|
|
5
5
|
* {@link import('@/context/RenderContext.ts').RenderContext} for the
|
|
6
6
|
* duration of the single render pass and published to snippets through the
|
|
7
|
-
* shared {@link CaptureChannel}:
|
|
8
|
-
* its `toString` at construction
|
|
7
|
+
* shared {@link CaptureChannel}: in a run that has a channel, every
|
|
8
|
+
* `SnippetBase` instance self-wraps its `toString` at construction
|
|
9
|
+
* (own-property wrapper), and the wrapper
|
|
9
10
|
* observes into the channel's sink while the **capture interval** is open
|
|
10
11
|
* — the span while `channel.sink` is set. Each `toString` invocation is
|
|
11
12
|
* observed into an **occurrence tree** — one node per call, keyed by
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
|
|
5
5
|
* {@link import('@/context/RenderContext.ts').RenderContext} for the
|
|
6
6
|
* duration of the single render pass and published to snippets through the
|
|
7
|
-
* shared {@link CaptureChannel}:
|
|
8
|
-
* its `toString` at construction
|
|
7
|
+
* shared {@link CaptureChannel}: in a run that has a channel, every
|
|
8
|
+
* `SnippetBase` instance self-wraps its `toString` at construction
|
|
9
|
+
* (own-property wrapper), and the wrapper
|
|
9
10
|
* observes into the channel's sink while the **capture interval** is open
|
|
10
11
|
* — the span while `channel.sink` is set. Each `toString` invocation is
|
|
11
12
|
* observed into an **occurrence tree** — one node per call, keyed by
|
|
@@ -96,9 +96,10 @@ export type ToArtifactsArgs = {
|
|
|
96
96
|
/** Whether to suppress console output */
|
|
97
97
|
silent: boolean;
|
|
98
98
|
/**
|
|
99
|
-
* Optional attribution (gen-maps) **emission** config.
|
|
100
|
-
* always on; when `postPass` is set, the
|
|
101
|
-
*
|
|
99
|
+
* Optional attribution (gen-maps) **emission** config. Location
|
|
100
|
+
* capture is always on; when `postPass` is set, the run's snippets wrap
|
|
101
|
+
* their `toString` and the pipeline emits sidecars + a generation map
|
|
102
|
+
* alongside the usual artifacts. See
|
|
102
103
|
* {@link AttributionState}.
|
|
103
104
|
*/
|
|
104
105
|
attribution?: AttributionState;
|
|
@@ -314,8 +314,12 @@ export class CoreContext {
|
|
|
314
314
|
// The shared attribution capture channel: snippets constructed
|
|
315
315
|
// during generate hold the GenerateContext, whose `captureSink`
|
|
316
316
|
// reads this slot; RenderContext flips it around the one capturing
|
|
317
|
-
// render. One object per run wires the two phases together.
|
|
318
|
-
|
|
317
|
+
// render. One object per run wires the two phases together. A run
|
|
318
|
+
// with no `attribution.postPass` has no capturing render, so it has
|
|
319
|
+
// no channel, and its snippets install no `toString` wrapper.
|
|
320
|
+
const captureChannel = attribution?.postPass
|
|
321
|
+
? { sink: undefined }
|
|
322
|
+
: undefined;
|
|
319
323
|
const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
|
|
320
324
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
321
325
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -416,13 +420,12 @@ export class CoreContext {
|
|
|
416
420
|
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
417
421
|
const subjects = stackTrail.trace('generate', () => {
|
|
418
422
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
419
|
-
// Capability probing never renders, so
|
|
420
|
-
// opens — a throwaway channel satisfies the wiring.
|
|
423
|
+
// Capability probing never renders, so it has no capture channel.
|
|
421
424
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
422
425
|
toGeneratorConfigMap,
|
|
423
426
|
document: parsedDocument,
|
|
424
427
|
settings,
|
|
425
|
-
captureChannel:
|
|
428
|
+
captureChannel: undefined
|
|
426
429
|
});
|
|
427
430
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
428
431
|
return generatePhase.context.toSupportedSubjects();
|
|
@@ -466,13 +469,12 @@ export class CoreContext {
|
|
|
466
469
|
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
467
470
|
const enrichmentDefaults = stackTrail.trace('generate', () => {
|
|
468
471
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
469
|
-
// Seeding never renders, so
|
|
470
|
-
// throwaway channel satisfies the wiring.
|
|
472
|
+
// Seeding never renders, so it has no capture channel.
|
|
471
473
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
472
474
|
toGeneratorConfigMap,
|
|
473
475
|
document: parsedDocument,
|
|
474
476
|
settings,
|
|
475
|
-
captureChannel:
|
|
477
|
+
captureChannel: undefined
|
|
476
478
|
});
|
|
477
479
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
478
480
|
return generatePhase.context.toEnrichmentDefaults();
|
|
@@ -47,7 +47,8 @@ type ConstructorArgs = {
|
|
|
47
47
|
* Shared attribution capture channel — the slot `RenderContext` flips to
|
|
48
48
|
* open/close the capture interval. Snippets read it through this
|
|
49
49
|
* context's {@link GenerateContext.captureSink}. Optional: when omitted
|
|
50
|
-
* (tests, capture-less runs) `captureSink` is always `undefined
|
|
50
|
+
* (tests, capture-less runs) `captureSink` is always `undefined` and
|
|
51
|
+
* `capturesRender` is false, so no snippet installs a `toString` wrapper.
|
|
51
52
|
*/
|
|
52
53
|
captureChannel?: CaptureChannel;
|
|
53
54
|
/**
|
|
@@ -178,6 +179,12 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
178
179
|
* shared channel's `sink`.
|
|
179
180
|
*/
|
|
180
181
|
get captureSink(): CaptureSink | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Whether this run has a capturing render: it was given a capture
|
|
184
|
+
* channel. A `SnippetBase` instance installs its `toString` wrapper only
|
|
185
|
+
* then.
|
|
186
|
+
*/
|
|
187
|
+
get capturesRender(): boolean;
|
|
181
188
|
/**
|
|
182
189
|
* The trail of the subject whose variant is being generated, or
|
|
183
190
|
* `undefined` outside one. Log lines and the results the logger
|
|
@@ -218,6 +218,14 @@ export class GenerateContext {
|
|
|
218
218
|
get captureSink() {
|
|
219
219
|
return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Whether this run has a capturing render: it was given a capture
|
|
223
|
+
* channel. A `SnippetBase` instance installs its `toString` wrapper only
|
|
224
|
+
* then.
|
|
225
|
+
*/
|
|
226
|
+
get capturesRender() {
|
|
227
|
+
return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f") !== undefined;
|
|
228
|
+
}
|
|
221
229
|
/**
|
|
222
230
|
* The trail of the subject whose variant is being generated, or
|
|
223
231
|
* `undefined` outside one. Log lines and the results the logger
|
|
@@ -123,9 +123,8 @@ export class RenderContext {
|
|
|
123
123
|
*/
|
|
124
124
|
render(stackTrail) {
|
|
125
125
|
const postPassConfig = this.attribution?.postPass;
|
|
126
|
-
// No emission configured → plain render, no capture: the
|
|
127
|
-
//
|
|
128
|
-
// the pass-through path.
|
|
126
|
+
// No emission configured → plain render, no capture: the run has no
|
|
127
|
+
// capture channel, so its snippets have no `toString` wrapper.
|
|
129
128
|
if (!postPassConfig) {
|
|
130
129
|
const result = this.collate(stackTrail);
|
|
131
130
|
return {
|
|
@@ -450,11 +450,8 @@ export type GenerateContextType = {
|
|
|
450
450
|
pendingStack: PendingDefinition[];
|
|
451
451
|
document: SkmtcParsedDocument;
|
|
452
452
|
/**
|
|
453
|
-
* Attribution (gen-maps) state.
|
|
454
|
-
*
|
|
455
|
-
* module-level render stack, so the post-render span resolver can
|
|
456
|
-
* attribute byte ranges to producers. When omitted, the wrap is
|
|
457
|
-
* skipped entirely — zero cost.
|
|
453
|
+
* Attribution (gen-maps) state. It does not decide whether a
|
|
454
|
+
* `SnippetBase` wraps its `toString`: {@link capturesRender} does.
|
|
458
455
|
*/
|
|
459
456
|
attribution?: AttributionState;
|
|
460
457
|
/**
|
|
@@ -462,10 +459,18 @@ export type GenerateContextType = {
|
|
|
462
459
|
* capture interval. Read by every `SnippetBase` instance's `toString`
|
|
463
460
|
* wrapper; `RenderContext` opens/closes the interval through the shared
|
|
464
461
|
* {@link import('@/anchors/CaptureSink.ts').CaptureChannel} that
|
|
465
|
-
* `CoreContext` wires into both contexts.
|
|
466
|
-
* `
|
|
462
|
+
* `CoreContext` wires into both contexts. In a run with no capturing
|
|
463
|
+
* render (`capturesRender` false, as in a bare test mock) no snippet
|
|
464
|
+
* has a wrapper, so nothing reads it.
|
|
467
465
|
*/
|
|
468
466
|
captureSink: CaptureSink | undefined;
|
|
467
|
+
/**
|
|
468
|
+
* Whether the run has a capturing render (attribution emission is
|
|
469
|
+
* configured). Read once by every `SnippetBase` instance, at
|
|
470
|
+
* construction: it installs its `toString` wrapper only when this is
|
|
471
|
+
* true.
|
|
472
|
+
*/
|
|
473
|
+
capturesRender: boolean;
|
|
469
474
|
toArtifacts: (stackTrail: StackTrail) => GenerateResult;
|
|
470
475
|
registerJson: ({ destinationPath, json }: RegisterJsonArgs) => void;
|
|
471
476
|
registerMarkdown: ({ destinationPath, markdown }: RegisterMarkdownArgs) => void;
|
package/esm/dsl/Definition.d.ts
CHANGED
|
@@ -37,14 +37,14 @@ export declare abstract class DefinitionBase<V extends GeneratedValue = Generate
|
|
|
37
37
|
/** The generated value content */
|
|
38
38
|
value: V;
|
|
39
39
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* not construct.
|
|
40
|
+
* The model lowest on the pending stack that this Definition's model led
|
|
41
|
+
* back to while its projection was being constructed
|
|
42
|
+
* (`PendingDefinition.leadsTo`). A reference to this model is inside a
|
|
43
|
+
* cycle for as long as that cycle is open (`toOpenEnd`). Set by the
|
|
44
|
+
* `ModelDriver`; `undefined` for a model that led back to none, and for a
|
|
45
|
+
* Definition the Driver did not construct.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
leadsTo: PendingDefinition | undefined;
|
|
48
48
|
constructor({ context, identifier, value }: DefinitionBaseArgs<V>);
|
|
49
49
|
/** Renders the definition's code. Implemented by the concrete subclass. */
|
|
50
50
|
abstract toString(): string;
|
package/esm/dsl/Definition.js
CHANGED
|
@@ -32,14 +32,14 @@ export class DefinitionBase extends SnippetBase {
|
|
|
32
32
|
value: void 0
|
|
33
33
|
});
|
|
34
34
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* not construct.
|
|
35
|
+
* The model lowest on the pending stack that this Definition's model led
|
|
36
|
+
* back to while its projection was being constructed
|
|
37
|
+
* (`PendingDefinition.leadsTo`). A reference to this model is inside a
|
|
38
|
+
* cycle for as long as that cycle is open (`toOpenEnd`). Set by the
|
|
39
|
+
* `ModelDriver`; `undefined` for a model that led back to none, and for a
|
|
40
|
+
* Definition the Driver did not construct.
|
|
41
41
|
*/
|
|
42
|
-
Object.defineProperty(this, "
|
|
42
|
+
Object.defineProperty(this, "leadsTo", {
|
|
43
43
|
enumerable: true,
|
|
44
44
|
configurable: true,
|
|
45
45
|
writable: true,
|
|
@@ -36,13 +36,29 @@ export declare class PendingDefinition {
|
|
|
36
36
|
backReferences: number;
|
|
37
37
|
/** True while the projection's constructor runs; false once it returned, however it returned. */
|
|
38
38
|
pending: boolean;
|
|
39
|
+
/** The model's place on the pending stack, counted from the bottom. The Driver sets it when it pushes the model. */
|
|
40
|
+
depth: number;
|
|
39
41
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* The model lowest on the pending stack that this model's construction led
|
|
43
|
+
* back to, directly or through the models it refers to: itself when it led
|
|
44
|
+
* back to none. The models are constructed depth first, so this is the
|
|
45
|
+
* lowlink of Tarjan's algorithm, and a model that leads back to itself
|
|
46
|
+
* alone is the root of its cycle. When the constructor returns, the Driver
|
|
47
|
+
* hands it to the Definition (`DefinitionBase.leadsTo`).
|
|
44
48
|
*/
|
|
45
|
-
|
|
49
|
+
leadsTo: PendingDefinition;
|
|
46
50
|
constructor({ identifier, exportPath, generatorKey, options, projection }: PendingDefinitionArgs);
|
|
51
|
+
/**
|
|
52
|
+
* Record that this model's construction led back to `other`, a model on
|
|
53
|
+
* the pending stack. The lowest one is kept.
|
|
54
|
+
*/
|
|
55
|
+
leadBackTo(other: PendingDefinition): void;
|
|
56
|
+
/**
|
|
57
|
+
* The model under construction this model still leads back to: itself
|
|
58
|
+
* while its own constructor runs, and after that the one its cycle goes
|
|
59
|
+
* back to, for as long as that cycle is not complete. `undefined` once the
|
|
60
|
+
* root of its cycle has returned: the model is in no cycle that is open.
|
|
61
|
+
*/
|
|
62
|
+
toOpenEnd(): PendingDefinition | undefined;
|
|
47
63
|
}
|
|
48
64
|
export {};
|
|
@@ -62,17 +62,26 @@ export class PendingDefinition {
|
|
|
62
62
|
writable: true,
|
|
63
63
|
value: true
|
|
64
64
|
});
|
|
65
|
+
/** The model's place on the pending stack, counted from the bottom. The Driver sets it when it pushes the model. */
|
|
66
|
+
Object.defineProperty(this, "depth", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: 0
|
|
71
|
+
});
|
|
65
72
|
/**
|
|
66
|
-
* The
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
73
|
+
* The model lowest on the pending stack that this model's construction led
|
|
74
|
+
* back to, directly or through the models it refers to: itself when it led
|
|
75
|
+
* back to none. The models are constructed depth first, so this is the
|
|
76
|
+
* lowlink of Tarjan's algorithm, and a model that leads back to itself
|
|
77
|
+
* alone is the root of its cycle. When the constructor returns, the Driver
|
|
78
|
+
* hands it to the Definition (`DefinitionBase.leadsTo`).
|
|
70
79
|
*/
|
|
71
|
-
Object.defineProperty(this, "
|
|
80
|
+
Object.defineProperty(this, "leadsTo", {
|
|
72
81
|
enumerable: true,
|
|
73
82
|
configurable: true,
|
|
74
83
|
writable: true,
|
|
75
|
-
value:
|
|
84
|
+
value: this
|
|
76
85
|
});
|
|
77
86
|
this.identifier = identifier;
|
|
78
87
|
this.exportPath = exportPath;
|
|
@@ -80,4 +89,25 @@ export class PendingDefinition {
|
|
|
80
89
|
this.options = options;
|
|
81
90
|
this.projection = projection;
|
|
82
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Record that this model's construction led back to `other`, a model on
|
|
94
|
+
* the pending stack. The lowest one is kept.
|
|
95
|
+
*/
|
|
96
|
+
leadBackTo(other) {
|
|
97
|
+
if (other.depth < this.leadsTo.depth) {
|
|
98
|
+
this.leadsTo = other;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The model under construction this model still leads back to: itself
|
|
103
|
+
* while its own constructor runs, and after that the one its cycle goes
|
|
104
|
+
* back to, for as long as that cycle is not complete. `undefined` once the
|
|
105
|
+
* root of its cycle has returned: the model is in no cycle that is open.
|
|
106
|
+
*/
|
|
107
|
+
toOpenEnd() {
|
|
108
|
+
if (this.pending) {
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
return this.leadsTo === this ? undefined : this.leadsTo.toOpenEnd();
|
|
112
|
+
}
|
|
83
113
|
}
|
package/esm/dsl/SnippetBase.d.ts
CHANGED
|
@@ -47,8 +47,11 @@ export type SnippetBaseArgs = {
|
|
|
47
47
|
*
|
|
48
48
|
* ## Attribution (gen-maps)
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* In a run that captures a render (`context.capturesRender`: attribution
|
|
51
|
+
* emission is configured), every instance self-wraps its `toString` at
|
|
52
|
+
* construction (an own-property wrapper — shared function,
|
|
53
|
+
* non-enumerable). In any other run no instance has a wrapper, and
|
|
54
|
+
* `toString` is the subclass's own. The wrapper is
|
|
52
55
|
* gated by the **capture interval**: the span while
|
|
53
56
|
* {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
|
|
54
57
|
* is set, which `RenderContext` opens around the one capturing render and
|
package/esm/dsl/SnippetBase.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { StackTrail } from '../context/StackTrail.js';
|
|
2
2
|
/**
|
|
3
|
-
* The own-property `toString` wrapper
|
|
4
|
-
* installs at construction
|
|
3
|
+
* The own-property `toString` wrapper a {@link SnippetBase} instance
|
|
4
|
+
* installs at construction, in a run that captures a render
|
|
5
|
+
* (`context.capturesRender`) — ONE shared function, no per-instance closure.
|
|
5
6
|
*
|
|
6
7
|
* Own properties shadow every prototype, so this intercepts the leaf
|
|
7
8
|
* subclass's `toString` no matter where in the hierarchy it is declared —
|
|
@@ -11,9 +12,7 @@ import { StackTrail } from '../context/StackTrail.js';
|
|
|
11
12
|
* instance's own property).
|
|
12
13
|
*
|
|
13
14
|
* Outside the capture interval (`context.captureSink` unset) this is a
|
|
14
|
-
* pure pass-through — one property read and one branch.
|
|
15
|
-
* (`{} as GenerateContextType`) read `undefined` and take the pass-through
|
|
16
|
-
* path.
|
|
15
|
+
* pure pass-through — one property read and one branch.
|
|
17
16
|
*/
|
|
18
17
|
const capturingToString = function () {
|
|
19
18
|
const impl = Object.getPrototypeOf(this).toString;
|
|
@@ -43,8 +42,11 @@ const capturingToString = function () {
|
|
|
43
42
|
*
|
|
44
43
|
* ## Attribution (gen-maps)
|
|
45
44
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* In a run that captures a render (`context.capturesRender`: attribution
|
|
46
|
+
* emission is configured), every instance self-wraps its `toString` at
|
|
47
|
+
* construction (an own-property wrapper — shared function,
|
|
48
|
+
* non-enumerable). In any other run no instance has a wrapper, and
|
|
49
|
+
* `toString` is the subclass's own. The wrapper is
|
|
48
50
|
* gated by the **capture interval**: the span while
|
|
49
51
|
* {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
|
|
50
52
|
* is set, which `RenderContext` opens around the one capturing render and
|
|
@@ -104,10 +106,14 @@ export class SnippetBase {
|
|
|
104
106
|
// Self-wrap for attribution capture: an own-property `toString`
|
|
105
107
|
// (shared function value, non-enumerable) that observes into the
|
|
106
108
|
// context's capture sink while the capture interval is open and
|
|
107
|
-
// passes through otherwise.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
// passes through otherwise. A run with no capturing render never
|
|
110
|
+
// opens the interval, so its snippets get no wrapper: one property
|
|
111
|
+
// definition for each snippet of the run is otherwise made for nothing.
|
|
112
|
+
if (context.capturesRender) {
|
|
113
|
+
Object.defineProperty(this, 'toString', {
|
|
114
|
+
value: capturingToString,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
112
118
|
}
|
|
113
119
|
}
|
|
@@ -83,8 +83,10 @@ export type ModelRef<V extends GeneratedValue, EnrichmentType> = {
|
|
|
83
83
|
settings: ContentSettings<EnrichmentType>;
|
|
84
84
|
definition: GeneratedDefinition<V>;
|
|
85
85
|
/**
|
|
86
|
-
* The model
|
|
87
|
-
*
|
|
86
|
+
* The model is in a cycle that is not complete yet: it leads back to a
|
|
87
|
+
* model that is still pending. The source is constructed inside that
|
|
88
|
+
* pending model, so this reference is inside the cycle, in whatever
|
|
89
|
+
* order the models are reached. Every reference inside a cycle must be deferred where
|
|
88
90
|
* the target language reads the value when the module loads (zod's
|
|
89
91
|
* `z.lazy`): any model of the cycle can be the first one loaded.
|
|
90
92
|
*/
|
|
@@ -167,7 +167,7 @@ export class ModelDriver {
|
|
|
167
167
|
value,
|
|
168
168
|
noExport: this.noExport
|
|
169
169
|
});
|
|
170
|
-
definition.
|
|
170
|
+
definition.leadsTo = marker.leadsTo === marker ? undefined : marker.leadsTo;
|
|
171
171
|
// Added once the constructor returned, so the Definition renders after
|
|
172
172
|
// the models it refers to, and a constructor that throws adds no file.
|
|
173
173
|
const taken = findDefinitionAt({ context: this.context, name: identifier.name, exportPath });
|
|
@@ -225,6 +225,7 @@ const assertSameOptions = ({ name, exportPath, cachedOptions, options }) => {
|
|
|
225
225
|
};
|
|
226
226
|
/** Run `construct` with `marker` on top of the context's pending stack, popped however `construct` ends. */
|
|
227
227
|
const whilePending = ({ context, marker }, construct) => {
|
|
228
|
+
marker.depth = context.pendingStack.length;
|
|
228
229
|
context.pendingStack.push(marker);
|
|
229
230
|
try {
|
|
230
231
|
return construct();
|
|
@@ -264,8 +265,6 @@ const stitchModelImport = ({ context, lang, identifier, exportPath, destinationP
|
|
|
264
265
|
destinationPath: toImportFile({ context, lang, destination: importInto }).path
|
|
265
266
|
});
|
|
266
267
|
};
|
|
267
|
-
/** The models `definition`'s construction reached that are still pending. */
|
|
268
|
-
const toOpenReaches = (definition) => [...(definition.reaches ?? [])].filter(reached => reached.pending);
|
|
269
268
|
/**
|
|
270
269
|
* Whether anything referred back to the model of `settings` while its
|
|
271
270
|
* projection was being constructed: the model is recursive, on its own or in
|
|
@@ -320,8 +319,8 @@ export const toModelRef = (args) => {
|
|
|
320
319
|
projection
|
|
321
320
|
});
|
|
322
321
|
pending.backReferences++;
|
|
323
|
-
// The model whose constructor is running
|
|
324
|
-
context.pendingStack.at(-1)?.
|
|
322
|
+
// The model whose constructor is running led back to a pending model.
|
|
323
|
+
context.pendingStack.at(-1)?.leadBackTo(pending);
|
|
325
324
|
stitchModelImport({
|
|
326
325
|
context,
|
|
327
326
|
lang: projection.lang,
|
|
@@ -332,17 +331,18 @@ export const toModelRef = (args) => {
|
|
|
332
331
|
return { suspended: true, settings };
|
|
333
332
|
}
|
|
334
333
|
const driver = new ModelDriver(args, settings);
|
|
335
|
-
//
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
// Constructed now or found in the cache, the Definition carries the model
|
|
335
|
+
// its construction led back to. While the cycle that model is in is open,
|
|
336
|
+
// this reference is inside it, and the source leads back there too.
|
|
337
|
+
const openEnd = driver.definition.leadsTo?.toOpenEnd();
|
|
338
|
+
if (openEnd !== undefined) {
|
|
339
|
+
context.pendingStack.at(-1)?.leadBackTo(openEnd);
|
|
340
|
+
}
|
|
341
341
|
return {
|
|
342
342
|
suspended: false,
|
|
343
343
|
settings: driver.settings,
|
|
344
344
|
definition: driver.definition,
|
|
345
|
-
inCycle:
|
|
345
|
+
inCycle: openEnd !== undefined
|
|
346
346
|
};
|
|
347
347
|
};
|
|
348
348
|
/**
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Attribution (gen-maps) **emission** config.
|
|
3
3
|
*
|
|
4
|
-
* Attribution *capture* is always on and needs no configuration
|
|
5
|
-
* intrinsic to the pipeline:
|
|
4
|
+
* Attribution *location capture* is always on and needs no configuration:
|
|
6
5
|
*
|
|
7
6
|
* - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
|
|
8
7
|
* `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
|
|
9
|
-
* - **Generate phase**: every `SnippetBase`
|
|
10
|
-
* `toString` to capture parent/child edges
|
|
11
|
-
*
|
|
8
|
+
* - **Generate phase**: in a run with `postPass`, every `SnippetBase`
|
|
9
|
+
* instance wraps its `toString` to capture parent/child edges, so the
|
|
10
|
+
* post-render span resolver can attribute byte ranges to producers. A
|
|
11
|
+
* run with no `postPass` installs no wrapper.
|
|
12
12
|
*
|
|
13
13
|
* This type configures only **emission**: it is supplied at the run level
|
|
14
14
|
* (`CoreContext.toArtifacts`) and consumed solely by the post-render
|
|
15
|
-
* pass. The parse and generate contexts do not carry it
|
|
16
|
-
*
|
|
17
|
-
* on-disk output; setting
|
|
18
|
-
* `
|
|
15
|
+
* pass. The parse and generate contexts do not carry it; the generate
|
|
16
|
+
* context only knows whether the run has a capture channel. Without
|
|
17
|
+
* `postPass` you get location capture but no on-disk output; setting
|
|
18
|
+
* `postPass` activates the pass and surfaces `sidecars` /
|
|
19
|
+
* `generationMap` on the result.
|
|
19
20
|
*/
|
|
20
21
|
import type { ParserAdapter } from '../anchors/ParserAdapter.js';
|
|
21
22
|
import type { GeneratorMetaLookup } from '../anchors/postPass.js';
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Attribution (gen-maps) **emission** config.
|
|
3
3
|
*
|
|
4
|
-
* Attribution *capture* is always on and needs no configuration
|
|
5
|
-
* intrinsic to the pipeline:
|
|
4
|
+
* Attribution *location capture* is always on and needs no configuration:
|
|
6
5
|
*
|
|
7
6
|
* - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
|
|
8
7
|
* `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
|
|
9
|
-
* - **Generate phase**: every `SnippetBase`
|
|
10
|
-
* `toString` to capture parent/child edges
|
|
11
|
-
*
|
|
8
|
+
* - **Generate phase**: in a run with `postPass`, every `SnippetBase`
|
|
9
|
+
* instance wraps its `toString` to capture parent/child edges, so the
|
|
10
|
+
* post-render span resolver can attribute byte ranges to producers. A
|
|
11
|
+
* run with no `postPass` installs no wrapper.
|
|
12
12
|
*
|
|
13
13
|
* This type configures only **emission**: it is supplied at the run level
|
|
14
14
|
* (`CoreContext.toArtifacts`) and consumed solely by the post-render
|
|
15
|
-
* pass. The parse and generate contexts do not carry it
|
|
16
|
-
*
|
|
17
|
-
* on-disk output; setting
|
|
18
|
-
* `
|
|
15
|
+
* pass. The parse and generate contexts do not carry it; the generate
|
|
16
|
+
* context only knows whether the run has a capture channel. Without
|
|
17
|
+
* `postPass` you get location capture but no on-disk output; setting
|
|
18
|
+
* `postPass` activates the pass and surfaces `sidecars` /
|
|
19
|
+
* `generationMap` on the result.
|
|
19
20
|
*/
|
|
20
21
|
export {};
|
package/package.json
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
|
|
5
5
|
* {@link import('@/context/RenderContext.ts').RenderContext} for the
|
|
6
6
|
* duration of the single render pass and published to snippets through the
|
|
7
|
-
* shared {@link CaptureChannel}:
|
|
8
|
-
* its `toString` at construction
|
|
7
|
+
* shared {@link CaptureChannel}: in a run that has a channel, every
|
|
8
|
+
* `SnippetBase` instance self-wraps its `toString` at construction
|
|
9
|
+
* (own-property wrapper), and the wrapper
|
|
9
10
|
* observes into the channel's sink while the **capture interval** is open
|
|
10
11
|
* — the span while `channel.sink` is set. Each `toString` invocation is
|
|
11
12
|
* observed into an **occurrence tree** — one node per call, keyed by
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
|
|
6
6
|
* {@link import('@/context/RenderContext.ts').RenderContext} for the
|
|
7
7
|
* duration of the single render pass and published to snippets through the
|
|
8
|
-
* shared {@link CaptureChannel}:
|
|
9
|
-
* its `toString` at construction
|
|
8
|
+
* shared {@link CaptureChannel}: in a run that has a channel, every
|
|
9
|
+
* `SnippetBase` instance self-wraps its `toString` at construction
|
|
10
|
+
* (own-property wrapper), and the wrapper
|
|
10
11
|
* observes into the channel's sink while the **capture interval** is open
|
|
11
12
|
* — the span while `channel.sink` is set. Each `toString` invocation is
|
|
12
13
|
* observed into an **occurrence tree** — one node per call, keyed by
|
|
@@ -96,9 +96,10 @@ export type ToArtifactsArgs = {
|
|
|
96
96
|
/** Whether to suppress console output */
|
|
97
97
|
silent: boolean;
|
|
98
98
|
/**
|
|
99
|
-
* Optional attribution (gen-maps) **emission** config.
|
|
100
|
-
* always on; when `postPass` is set, the
|
|
101
|
-
*
|
|
99
|
+
* Optional attribution (gen-maps) **emission** config. Location
|
|
100
|
+
* capture is always on; when `postPass` is set, the run's snippets wrap
|
|
101
|
+
* their `toString` and the pipeline emits sidecars + a generation map
|
|
102
|
+
* alongside the usual artifacts. See
|
|
102
103
|
* {@link AttributionState}.
|
|
103
104
|
*/
|
|
104
105
|
attribution?: AttributionState;
|
|
@@ -352,8 +352,12 @@ class CoreContext {
|
|
|
352
352
|
// The shared attribution capture channel: snippets constructed
|
|
353
353
|
// during generate hold the GenerateContext, whose `captureSink`
|
|
354
354
|
// reads this slot; RenderContext flips it around the one capturing
|
|
355
|
-
// render. One object per run wires the two phases together.
|
|
356
|
-
|
|
355
|
+
// render. One object per run wires the two phases together. A run
|
|
356
|
+
// with no `attribution.postPass` has no capturing render, so it has
|
|
357
|
+
// no channel, and its snippets install no `toString` wrapper.
|
|
358
|
+
const captureChannel = attribution?.postPass
|
|
359
|
+
? { sink: undefined }
|
|
360
|
+
: undefined;
|
|
357
361
|
const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
|
|
358
362
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
359
363
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
@@ -454,13 +458,12 @@ class CoreContext {
|
|
|
454
458
|
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
455
459
|
const subjects = stackTrail.trace('generate', () => {
|
|
456
460
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
457
|
-
// Capability probing never renders, so
|
|
458
|
-
// opens — a throwaway channel satisfies the wiring.
|
|
461
|
+
// Capability probing never renders, so it has no capture channel.
|
|
459
462
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
460
463
|
toGeneratorConfigMap,
|
|
461
464
|
document: parsedDocument,
|
|
462
465
|
settings,
|
|
463
|
-
captureChannel:
|
|
466
|
+
captureChannel: undefined
|
|
464
467
|
});
|
|
465
468
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
466
469
|
return generatePhase.context.toSupportedSubjects();
|
|
@@ -504,13 +507,12 @@ class CoreContext {
|
|
|
504
507
|
__classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
|
|
505
508
|
const enrichmentDefaults = stackTrail.trace('generate', () => {
|
|
506
509
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
|
|
507
|
-
// Seeding never renders, so
|
|
508
|
-
// throwaway channel satisfies the wiring.
|
|
510
|
+
// Seeding never renders, so it has no capture channel.
|
|
509
511
|
const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
510
512
|
toGeneratorConfigMap,
|
|
511
513
|
document: parsedDocument,
|
|
512
514
|
settings,
|
|
513
|
-
captureChannel:
|
|
515
|
+
captureChannel: undefined
|
|
514
516
|
});
|
|
515
517
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
516
518
|
return generatePhase.context.toEnrichmentDefaults();
|
|
@@ -47,7 +47,8 @@ type ConstructorArgs = {
|
|
|
47
47
|
* Shared attribution capture channel — the slot `RenderContext` flips to
|
|
48
48
|
* open/close the capture interval. Snippets read it through this
|
|
49
49
|
* context's {@link GenerateContext.captureSink}. Optional: when omitted
|
|
50
|
-
* (tests, capture-less runs) `captureSink` is always `undefined
|
|
50
|
+
* (tests, capture-less runs) `captureSink` is always `undefined` and
|
|
51
|
+
* `capturesRender` is false, so no snippet installs a `toString` wrapper.
|
|
51
52
|
*/
|
|
52
53
|
captureChannel?: CaptureChannel;
|
|
53
54
|
/**
|
|
@@ -178,6 +179,12 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
178
179
|
* shared channel's `sink`.
|
|
179
180
|
*/
|
|
180
181
|
get captureSink(): CaptureSink | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Whether this run has a capturing render: it was given a capture
|
|
184
|
+
* channel. A `SnippetBase` instance installs its `toString` wrapper only
|
|
185
|
+
* then.
|
|
186
|
+
*/
|
|
187
|
+
get capturesRender(): boolean;
|
|
181
188
|
/**
|
|
182
189
|
* The trail of the subject whose variant is being generated, or
|
|
183
190
|
* `undefined` outside one. Log lines and the results the logger
|
|
@@ -224,6 +224,14 @@ class GenerateContext {
|
|
|
224
224
|
get captureSink() {
|
|
225
225
|
return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Whether this run has a capturing render: it was given a capture
|
|
229
|
+
* channel. A `SnippetBase` instance installs its `toString` wrapper only
|
|
230
|
+
* then.
|
|
231
|
+
*/
|
|
232
|
+
get capturesRender() {
|
|
233
|
+
return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f") !== undefined;
|
|
234
|
+
}
|
|
227
235
|
/**
|
|
228
236
|
* The trail of the subject whose variant is being generated, or
|
|
229
237
|
* `undefined` outside one. Log lines and the results the logger
|
|
@@ -129,9 +129,8 @@ class RenderContext {
|
|
|
129
129
|
*/
|
|
130
130
|
render(stackTrail) {
|
|
131
131
|
const postPassConfig = this.attribution?.postPass;
|
|
132
|
-
// No emission configured → plain render, no capture: the
|
|
133
|
-
//
|
|
134
|
-
// the pass-through path.
|
|
132
|
+
// No emission configured → plain render, no capture: the run has no
|
|
133
|
+
// capture channel, so its snippets have no `toString` wrapper.
|
|
135
134
|
if (!postPassConfig) {
|
|
136
135
|
const result = this.collate(stackTrail);
|
|
137
136
|
return {
|
|
@@ -450,11 +450,8 @@ export type GenerateContextType = {
|
|
|
450
450
|
pendingStack: PendingDefinition[];
|
|
451
451
|
document: SkmtcParsedDocument;
|
|
452
452
|
/**
|
|
453
|
-
* Attribution (gen-maps) state.
|
|
454
|
-
*
|
|
455
|
-
* module-level render stack, so the post-render span resolver can
|
|
456
|
-
* attribute byte ranges to producers. When omitted, the wrap is
|
|
457
|
-
* skipped entirely — zero cost.
|
|
453
|
+
* Attribution (gen-maps) state. It does not decide whether a
|
|
454
|
+
* `SnippetBase` wraps its `toString`: {@link capturesRender} does.
|
|
458
455
|
*/
|
|
459
456
|
attribution?: AttributionState;
|
|
460
457
|
/**
|
|
@@ -462,10 +459,18 @@ export type GenerateContextType = {
|
|
|
462
459
|
* capture interval. Read by every `SnippetBase` instance's `toString`
|
|
463
460
|
* wrapper; `RenderContext` opens/closes the interval through the shared
|
|
464
461
|
* {@link import('@/anchors/CaptureSink.ts').CaptureChannel} that
|
|
465
|
-
* `CoreContext` wires into both contexts.
|
|
466
|
-
* `
|
|
462
|
+
* `CoreContext` wires into both contexts. In a run with no capturing
|
|
463
|
+
* render (`capturesRender` false, as in a bare test mock) no snippet
|
|
464
|
+
* has a wrapper, so nothing reads it.
|
|
467
465
|
*/
|
|
468
466
|
captureSink: CaptureSink | undefined;
|
|
467
|
+
/**
|
|
468
|
+
* Whether the run has a capturing render (attribution emission is
|
|
469
|
+
* configured). Read once by every `SnippetBase` instance, at
|
|
470
|
+
* construction: it installs its `toString` wrapper only when this is
|
|
471
|
+
* true.
|
|
472
|
+
*/
|
|
473
|
+
capturesRender: boolean;
|
|
469
474
|
toArtifacts: (stackTrail: StackTrail) => GenerateResult;
|
|
470
475
|
registerJson: ({ destinationPath, json }: RegisterJsonArgs) => void;
|
|
471
476
|
registerMarkdown: ({ destinationPath, markdown }: RegisterMarkdownArgs) => void;
|
|
@@ -37,14 +37,14 @@ export declare abstract class DefinitionBase<V extends GeneratedValue = Generate
|
|
|
37
37
|
/** The generated value content */
|
|
38
38
|
value: V;
|
|
39
39
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* not construct.
|
|
40
|
+
* The model lowest on the pending stack that this Definition's model led
|
|
41
|
+
* back to while its projection was being constructed
|
|
42
|
+
* (`PendingDefinition.leadsTo`). A reference to this model is inside a
|
|
43
|
+
* cycle for as long as that cycle is open (`toOpenEnd`). Set by the
|
|
44
|
+
* `ModelDriver`; `undefined` for a model that led back to none, and for a
|
|
45
|
+
* Definition the Driver did not construct.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
leadsTo: PendingDefinition | undefined;
|
|
48
48
|
constructor({ context, identifier, value }: DefinitionBaseArgs<V>);
|
|
49
49
|
/** Renders the definition's code. Implemented by the concrete subclass. */
|
|
50
50
|
abstract toString(): string;
|
package/script/dsl/Definition.js
CHANGED
|
@@ -35,14 +35,14 @@ class DefinitionBase extends SnippetBase_js_1.SnippetBase {
|
|
|
35
35
|
value: void 0
|
|
36
36
|
});
|
|
37
37
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* not construct.
|
|
38
|
+
* The model lowest on the pending stack that this Definition's model led
|
|
39
|
+
* back to while its projection was being constructed
|
|
40
|
+
* (`PendingDefinition.leadsTo`). A reference to this model is inside a
|
|
41
|
+
* cycle for as long as that cycle is open (`toOpenEnd`). Set by the
|
|
42
|
+
* `ModelDriver`; `undefined` for a model that led back to none, and for a
|
|
43
|
+
* Definition the Driver did not construct.
|
|
44
44
|
*/
|
|
45
|
-
Object.defineProperty(this, "
|
|
45
|
+
Object.defineProperty(this, "leadsTo", {
|
|
46
46
|
enumerable: true,
|
|
47
47
|
configurable: true,
|
|
48
48
|
writable: true,
|
|
@@ -36,13 +36,29 @@ export declare class PendingDefinition {
|
|
|
36
36
|
backReferences: number;
|
|
37
37
|
/** True while the projection's constructor runs; false once it returned, however it returned. */
|
|
38
38
|
pending: boolean;
|
|
39
|
+
/** The model's place on the pending stack, counted from the bottom. The Driver sets it when it pushes the model. */
|
|
40
|
+
depth: number;
|
|
39
41
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* The model lowest on the pending stack that this model's construction led
|
|
43
|
+
* back to, directly or through the models it refers to: itself when it led
|
|
44
|
+
* back to none. The models are constructed depth first, so this is the
|
|
45
|
+
* lowlink of Tarjan's algorithm, and a model that leads back to itself
|
|
46
|
+
* alone is the root of its cycle. When the constructor returns, the Driver
|
|
47
|
+
* hands it to the Definition (`DefinitionBase.leadsTo`).
|
|
44
48
|
*/
|
|
45
|
-
|
|
49
|
+
leadsTo: PendingDefinition;
|
|
46
50
|
constructor({ identifier, exportPath, generatorKey, options, projection }: PendingDefinitionArgs);
|
|
51
|
+
/**
|
|
52
|
+
* Record that this model's construction led back to `other`, a model on
|
|
53
|
+
* the pending stack. The lowest one is kept.
|
|
54
|
+
*/
|
|
55
|
+
leadBackTo(other: PendingDefinition): void;
|
|
56
|
+
/**
|
|
57
|
+
* The model under construction this model still leads back to: itself
|
|
58
|
+
* while its own constructor runs, and after that the one its cycle goes
|
|
59
|
+
* back to, for as long as that cycle is not complete. `undefined` once the
|
|
60
|
+
* root of its cycle has returned: the model is in no cycle that is open.
|
|
61
|
+
*/
|
|
62
|
+
toOpenEnd(): PendingDefinition | undefined;
|
|
47
63
|
}
|
|
48
64
|
export {};
|
|
@@ -65,17 +65,26 @@ class PendingDefinition {
|
|
|
65
65
|
writable: true,
|
|
66
66
|
value: true
|
|
67
67
|
});
|
|
68
|
+
/** The model's place on the pending stack, counted from the bottom. The Driver sets it when it pushes the model. */
|
|
69
|
+
Object.defineProperty(this, "depth", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: 0
|
|
74
|
+
});
|
|
68
75
|
/**
|
|
69
|
-
* The
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
76
|
+
* The model lowest on the pending stack that this model's construction led
|
|
77
|
+
* back to, directly or through the models it refers to: itself when it led
|
|
78
|
+
* back to none. The models are constructed depth first, so this is the
|
|
79
|
+
* lowlink of Tarjan's algorithm, and a model that leads back to itself
|
|
80
|
+
* alone is the root of its cycle. When the constructor returns, the Driver
|
|
81
|
+
* hands it to the Definition (`DefinitionBase.leadsTo`).
|
|
73
82
|
*/
|
|
74
|
-
Object.defineProperty(this, "
|
|
83
|
+
Object.defineProperty(this, "leadsTo", {
|
|
75
84
|
enumerable: true,
|
|
76
85
|
configurable: true,
|
|
77
86
|
writable: true,
|
|
78
|
-
value:
|
|
87
|
+
value: this
|
|
79
88
|
});
|
|
80
89
|
this.identifier = identifier;
|
|
81
90
|
this.exportPath = exportPath;
|
|
@@ -83,5 +92,26 @@ class PendingDefinition {
|
|
|
83
92
|
this.options = options;
|
|
84
93
|
this.projection = projection;
|
|
85
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Record that this model's construction led back to `other`, a model on
|
|
97
|
+
* the pending stack. The lowest one is kept.
|
|
98
|
+
*/
|
|
99
|
+
leadBackTo(other) {
|
|
100
|
+
if (other.depth < this.leadsTo.depth) {
|
|
101
|
+
this.leadsTo = other;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The model under construction this model still leads back to: itself
|
|
106
|
+
* while its own constructor runs, and after that the one its cycle goes
|
|
107
|
+
* back to, for as long as that cycle is not complete. `undefined` once the
|
|
108
|
+
* root of its cycle has returned: the model is in no cycle that is open.
|
|
109
|
+
*/
|
|
110
|
+
toOpenEnd() {
|
|
111
|
+
if (this.pending) {
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
return this.leadsTo === this ? undefined : this.leadsTo.toOpenEnd();
|
|
115
|
+
}
|
|
86
116
|
}
|
|
87
117
|
exports.PendingDefinition = PendingDefinition;
|
|
@@ -47,8 +47,11 @@ export type SnippetBaseArgs = {
|
|
|
47
47
|
*
|
|
48
48
|
* ## Attribution (gen-maps)
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* In a run that captures a render (`context.capturesRender`: attribution
|
|
51
|
+
* emission is configured), every instance self-wraps its `toString` at
|
|
52
|
+
* construction (an own-property wrapper — shared function,
|
|
53
|
+
* non-enumerable). In any other run no instance has a wrapper, and
|
|
54
|
+
* `toString` is the subclass's own. The wrapper is
|
|
52
55
|
* gated by the **capture interval**: the span while
|
|
53
56
|
* {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
|
|
54
57
|
* is set, which `RenderContext` opens around the one capturing render and
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SnippetBase = void 0;
|
|
4
4
|
const StackTrail_js_1 = require("../context/StackTrail.js");
|
|
5
5
|
/**
|
|
6
|
-
* The own-property `toString` wrapper
|
|
7
|
-
* installs at construction
|
|
6
|
+
* The own-property `toString` wrapper a {@link SnippetBase} instance
|
|
7
|
+
* installs at construction, in a run that captures a render
|
|
8
|
+
* (`context.capturesRender`) — ONE shared function, no per-instance closure.
|
|
8
9
|
*
|
|
9
10
|
* Own properties shadow every prototype, so this intercepts the leaf
|
|
10
11
|
* subclass's `toString` no matter where in the hierarchy it is declared —
|
|
@@ -14,9 +15,7 @@ const StackTrail_js_1 = require("../context/StackTrail.js");
|
|
|
14
15
|
* instance's own property).
|
|
15
16
|
*
|
|
16
17
|
* Outside the capture interval (`context.captureSink` unset) this is a
|
|
17
|
-
* pure pass-through — one property read and one branch.
|
|
18
|
-
* (`{} as GenerateContextType`) read `undefined` and take the pass-through
|
|
19
|
-
* path.
|
|
18
|
+
* pure pass-through — one property read and one branch.
|
|
20
19
|
*/
|
|
21
20
|
const capturingToString = function () {
|
|
22
21
|
const impl = Object.getPrototypeOf(this).toString;
|
|
@@ -46,8 +45,11 @@ const capturingToString = function () {
|
|
|
46
45
|
*
|
|
47
46
|
* ## Attribution (gen-maps)
|
|
48
47
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* In a run that captures a render (`context.capturesRender`: attribution
|
|
49
|
+
* emission is configured), every instance self-wraps its `toString` at
|
|
50
|
+
* construction (an own-property wrapper — shared function,
|
|
51
|
+
* non-enumerable). In any other run no instance has a wrapper, and
|
|
52
|
+
* `toString` is the subclass's own. The wrapper is
|
|
51
53
|
* gated by the **capture interval**: the span while
|
|
52
54
|
* {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
|
|
53
55
|
* is set, which `RenderContext` opens around the one capturing render and
|
|
@@ -107,11 +109,15 @@ class SnippetBase {
|
|
|
107
109
|
// Self-wrap for attribution capture: an own-property `toString`
|
|
108
110
|
// (shared function value, non-enumerable) that observes into the
|
|
109
111
|
// context's capture sink while the capture interval is open and
|
|
110
|
-
// passes through otherwise.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
// passes through otherwise. A run with no capturing render never
|
|
113
|
+
// opens the interval, so its snippets get no wrapper: one property
|
|
114
|
+
// definition for each snippet of the run is otherwise made for nothing.
|
|
115
|
+
if (context.capturesRender) {
|
|
116
|
+
Object.defineProperty(this, 'toString', {
|
|
117
|
+
value: capturingToString,
|
|
118
|
+
configurable: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
exports.SnippetBase = SnippetBase;
|
|
@@ -83,8 +83,10 @@ export type ModelRef<V extends GeneratedValue, EnrichmentType> = {
|
|
|
83
83
|
settings: ContentSettings<EnrichmentType>;
|
|
84
84
|
definition: GeneratedDefinition<V>;
|
|
85
85
|
/**
|
|
86
|
-
* The model
|
|
87
|
-
*
|
|
86
|
+
* The model is in a cycle that is not complete yet: it leads back to a
|
|
87
|
+
* model that is still pending. The source is constructed inside that
|
|
88
|
+
* pending model, so this reference is inside the cycle, in whatever
|
|
89
|
+
* order the models are reached. Every reference inside a cycle must be deferred where
|
|
88
90
|
* the target language reads the value when the module loads (zod's
|
|
89
91
|
* `z.lazy`): any model of the cycle can be the first one loaded.
|
|
90
92
|
*/
|
|
@@ -173,7 +173,7 @@ class ModelDriver {
|
|
|
173
173
|
value,
|
|
174
174
|
noExport: this.noExport
|
|
175
175
|
});
|
|
176
|
-
definition.
|
|
176
|
+
definition.leadsTo = marker.leadsTo === marker ? undefined : marker.leadsTo;
|
|
177
177
|
// Added once the constructor returned, so the Definition renders after
|
|
178
178
|
// the models it refers to, and a constructor that throws adds no file.
|
|
179
179
|
const taken = (0, driverFiles_js_1.findDefinitionAt)({ context: this.context, name: identifier.name, exportPath });
|
|
@@ -232,6 +232,7 @@ const assertSameOptions = ({ name, exportPath, cachedOptions, options }) => {
|
|
|
232
232
|
};
|
|
233
233
|
/** Run `construct` with `marker` on top of the context's pending stack, popped however `construct` ends. */
|
|
234
234
|
const whilePending = ({ context, marker }, construct) => {
|
|
235
|
+
marker.depth = context.pendingStack.length;
|
|
235
236
|
context.pendingStack.push(marker);
|
|
236
237
|
try {
|
|
237
238
|
return construct();
|
|
@@ -271,8 +272,6 @@ const stitchModelImport = ({ context, lang, identifier, exportPath, destinationP
|
|
|
271
272
|
destinationPath: (0, driverFiles_js_1.toImportFile)({ context, lang, destination: importInto }).path
|
|
272
273
|
});
|
|
273
274
|
};
|
|
274
|
-
/** The models `definition`'s construction reached that are still pending. */
|
|
275
|
-
const toOpenReaches = (definition) => [...(definition.reaches ?? [])].filter(reached => reached.pending);
|
|
276
275
|
/**
|
|
277
276
|
* Whether anything referred back to the model of `settings` while its
|
|
278
277
|
* projection was being constructed: the model is recursive, on its own or in
|
|
@@ -328,8 +327,8 @@ const toModelRef = (args) => {
|
|
|
328
327
|
projection
|
|
329
328
|
});
|
|
330
329
|
pending.backReferences++;
|
|
331
|
-
// The model whose constructor is running
|
|
332
|
-
context.pendingStack.at(-1)?.
|
|
330
|
+
// The model whose constructor is running led back to a pending model.
|
|
331
|
+
context.pendingStack.at(-1)?.leadBackTo(pending);
|
|
333
332
|
stitchModelImport({
|
|
334
333
|
context,
|
|
335
334
|
lang: projection.lang,
|
|
@@ -340,17 +339,18 @@ const toModelRef = (args) => {
|
|
|
340
339
|
return { suspended: true, settings };
|
|
341
340
|
}
|
|
342
341
|
const driver = new ModelDriver(args, settings);
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
342
|
+
// Constructed now or found in the cache, the Definition carries the model
|
|
343
|
+
// its construction led back to. While the cycle that model is in is open,
|
|
344
|
+
// this reference is inside it, and the source leads back there too.
|
|
345
|
+
const openEnd = driver.definition.leadsTo?.toOpenEnd();
|
|
346
|
+
if (openEnd !== undefined) {
|
|
347
|
+
context.pendingStack.at(-1)?.leadBackTo(openEnd);
|
|
348
|
+
}
|
|
349
349
|
return {
|
|
350
350
|
suspended: false,
|
|
351
351
|
settings: driver.settings,
|
|
352
352
|
definition: driver.definition,
|
|
353
|
-
inCycle:
|
|
353
|
+
inCycle: openEnd !== undefined
|
|
354
354
|
};
|
|
355
355
|
};
|
|
356
356
|
exports.toModelRef = toModelRef;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Attribution (gen-maps) **emission** config.
|
|
3
3
|
*
|
|
4
|
-
* Attribution *capture* is always on and needs no configuration
|
|
5
|
-
* intrinsic to the pipeline:
|
|
4
|
+
* Attribution *location capture* is always on and needs no configuration:
|
|
6
5
|
*
|
|
7
6
|
* - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
|
|
8
7
|
* `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
|
|
9
|
-
* - **Generate phase**: every `SnippetBase`
|
|
10
|
-
* `toString` to capture parent/child edges
|
|
11
|
-
*
|
|
8
|
+
* - **Generate phase**: in a run with `postPass`, every `SnippetBase`
|
|
9
|
+
* instance wraps its `toString` to capture parent/child edges, so the
|
|
10
|
+
* post-render span resolver can attribute byte ranges to producers. A
|
|
11
|
+
* run with no `postPass` installs no wrapper.
|
|
12
12
|
*
|
|
13
13
|
* This type configures only **emission**: it is supplied at the run level
|
|
14
14
|
* (`CoreContext.toArtifacts`) and consumed solely by the post-render
|
|
15
|
-
* pass. The parse and generate contexts do not carry it
|
|
16
|
-
*
|
|
17
|
-
* on-disk output; setting
|
|
18
|
-
* `
|
|
15
|
+
* pass. The parse and generate contexts do not carry it; the generate
|
|
16
|
+
* context only knows whether the run has a capture channel. Without
|
|
17
|
+
* `postPass` you get location capture but no on-disk output; setting
|
|
18
|
+
* `postPass` activates the pass and surfaces `sidecars` /
|
|
19
|
+
* `generationMap` on the result.
|
|
19
20
|
*/
|
|
20
21
|
import type { ParserAdapter } from '../anchors/ParserAdapter.js';
|
|
21
22
|
import type { GeneratorMetaLookup } from '../anchors/postPass.js';
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Attribution (gen-maps) **emission** config.
|
|
4
4
|
*
|
|
5
|
-
* Attribution *capture* is always on and needs no configuration
|
|
6
|
-
* intrinsic to the pipeline:
|
|
5
|
+
* Attribution *location capture* is always on and needs no configuration:
|
|
7
6
|
*
|
|
8
7
|
* - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
|
|
9
8
|
* `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
|
|
10
|
-
* - **Generate phase**: every `SnippetBase`
|
|
11
|
-
* `toString` to capture parent/child edges
|
|
12
|
-
*
|
|
9
|
+
* - **Generate phase**: in a run with `postPass`, every `SnippetBase`
|
|
10
|
+
* instance wraps its `toString` to capture parent/child edges, so the
|
|
11
|
+
* post-render span resolver can attribute byte ranges to producers. A
|
|
12
|
+
* run with no `postPass` installs no wrapper.
|
|
13
13
|
*
|
|
14
14
|
* This type configures only **emission**: it is supplied at the run level
|
|
15
15
|
* (`CoreContext.toArtifacts`) and consumed solely by the post-render
|
|
16
|
-
* pass. The parse and generate contexts do not carry it
|
|
17
|
-
*
|
|
18
|
-
* on-disk output; setting
|
|
19
|
-
* `
|
|
16
|
+
* pass. The parse and generate contexts do not carry it; the generate
|
|
17
|
+
* context only knows whether the run has a capture channel. Without
|
|
18
|
+
* `postPass` you get location capture but no on-disk output; setting
|
|
19
|
+
* `postPass` activates the pass and surfaces `sidecars` /
|
|
20
|
+
* `generationMap` on the result.
|
|
20
21
|
*/
|
|
21
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|