@skmtc/core 0.58.3 → 0.58.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/esm/context/BuiltOnRead.d.ts +37 -0
  2. package/esm/context/BuiltOnRead.js +199 -0
  3. package/esm/context/CoreContext.js +11 -5
  4. package/esm/context/GenerateContext.d.ts +3 -0
  5. package/esm/context/GenerateContext.js +48 -5
  6. package/esm/context/ParseContext.js +116 -11
  7. package/esm/context/Subject.d.ts +29 -2
  8. package/esm/context/Subject.js +67 -6
  9. package/esm/dsl/model/toModelProjectionBase.d.ts +4 -1
  10. package/esm/oas/document/Document.d.ts +5 -1
  11. package/esm/oas/document/Document.js +10 -1
  12. package/esm/oas/document/documentSource.d.ts +37 -0
  13. package/esm/oas/document/documentSource.js +27 -0
  14. package/esm/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  15. package/esm/parse/v3-0/operation/toOperationsV3.js +68 -67
  16. package/esm/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  17. package/esm/parse/v3-1/operation/toOperationsV3.js +68 -67
  18. package/esm/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  19. package/esm/parse/v3-2/operation/toOperationsV3.js +69 -68
  20. package/package.json +1 -1
  21. package/script/context/BuiltOnRead.d.ts +37 -0
  22. package/script/context/BuiltOnRead.js +203 -0
  23. package/script/context/CoreContext.js +11 -5
  24. package/script/context/GenerateContext.d.ts +3 -0
  25. package/script/context/GenerateContext.js +48 -5
  26. package/script/context/ParseContext.js +116 -11
  27. package/script/context/Subject.d.ts +29 -2
  28. package/script/context/Subject.js +67 -6
  29. package/script/dsl/model/toModelProjectionBase.d.ts +4 -1
  30. package/script/oas/document/Document.d.ts +5 -1
  31. package/script/oas/document/Document.js +10 -1
  32. package/script/oas/document/documentSource.d.ts +37 -0
  33. package/script/oas/document/documentSource.js +36 -0
  34. package/script/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  35. package/script/parse/v3-0/operation/toOperationsV3.js +71 -69
  36. package/script/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  37. package/script/parse/v3-1/operation/toOperationsV3.js +71 -69
  38. package/script/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  39. package/script/parse/v3-2/operation/toOperationsV3.js +72 -70
@@ -55,75 +55,76 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
55
55
  if (!paths) {
56
56
  return [];
57
57
  }
58
- return Object.entries(paths).flatMap(([path, pathItem]) => {
59
- return stackTrail.trace(path, pathStack => {
60
- if (!pathItem) {
61
- return [];
62
- }
63
- const fixedFields = dropAdditionalOperationsV3({ pathItem, stackTrail: pathStack, context });
64
- const cleaned = Object.entries(fixedFields).reduce(({ rest, methodObject }, [key, operation]) => {
65
- const method = toPathItemMethod(key);
66
- if (method) {
67
- const { [method]: _deleted, ...remaining } = rest;
68
- return {
69
- rest: remaining,
70
- methodObject: {
71
- ...methodObject,
72
- [method]: operation
73
- }
74
- };
58
+ return Object.entries(paths).flatMap(([path, pathItem]) => stackTrail.trace(path, pathStack => pathItem ? toPathOperationsV3({ path, pathItem, stackTrail: pathStack, context }) : []));
59
+ };
60
+ /**
61
+ * The operations of the path item at `path`. They share one parsed path
62
+ * item. With `method`, only the operation at that method is parsed.
63
+ */
64
+ export const toPathOperationsV3 = ({ path, pathItem, stackTrail: pathStack, context, method: only }) => {
65
+ const fixedFields = dropAdditionalOperationsV3({ pathItem, stackTrail: pathStack, context });
66
+ const cleaned = Object.entries(fixedFields).reduce(({ rest, methodObject }, [key, operation]) => {
67
+ const method = toPathItemMethod(key);
68
+ if (method) {
69
+ const { [method]: _deleted, ...remaining } = rest;
70
+ return {
71
+ rest: remaining,
72
+ methodObject: {
73
+ ...methodObject,
74
+ [method]: operation
75
75
  }
76
- return { rest, methodObject };
77
- }, {
78
- rest: fixedFields,
79
- methodObject: {}
80
- });
81
- const pathItemResult = !isEmpty(cleaned.rest)
82
- ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
83
- : undefined;
84
- const pathItemObject = pathItemResult?.pathItem;
85
- const brokenParameters = pathItemResult?.brokenParameters ?? [];
86
- return Object.entries(cleaned.methodObject)
87
- .map(([method, operation]) => {
88
- // Use `pathStack` (the trail with `path` already pushed),
89
- // not the outer `stackTrail` — otherwise downstream traces
90
- // record paths:<method>:... and lose the actual path
91
- // segment, which breaks `OasDocument.removeItem` and the
92
- // dependency-ref invalidation it backs.
93
- return pathStack.trace(method, st => {
94
- if (!operation) {
95
- return;
96
- }
97
- if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
98
- return undefined;
99
- }
100
- try {
101
- return toOperationV3({
102
- operation,
103
- operationInfo: {
104
- method: method,
105
- path,
106
- pathItem: pathItemObject
107
- },
108
- stackTrail: st,
109
- context
110
- });
111
- }
112
- catch (error) {
113
- const normalized = error instanceof Error ? error : new Error(String(error));
114
- context.logIssueNoKey({
115
- parent: operation,
116
- level: 'error',
117
- message: normalized.message,
118
- cause: normalized,
119
- stackTrail: st,
120
- type: 'INVALID_OPERATION'
121
- });
122
- return undefined;
123
- }
76
+ };
77
+ }
78
+ return { rest, methodObject };
79
+ }, {
80
+ rest: fixedFields,
81
+ methodObject: {}
82
+ });
83
+ const pathItemResult = !isEmpty(cleaned.rest)
84
+ ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
85
+ : undefined;
86
+ const pathItemObject = pathItemResult?.pathItem;
87
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
88
+ return Object.entries(cleaned.methodObject)
89
+ .filter(([method]) => only === undefined || method === only)
90
+ .map(([method, operation]) => {
91
+ // Use `pathStack` (the trail with `path` already pushed),
92
+ // not the outer `stackTrail` — otherwise downstream traces
93
+ // record paths:<method>:... and lose the actual path
94
+ // segment, which breaks `OasDocument.removeItem` and the
95
+ // dependency-ref invalidation it backs.
96
+ return pathStack.trace(method, st => {
97
+ if (!operation) {
98
+ return;
99
+ }
100
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
101
+ return undefined;
102
+ }
103
+ try {
104
+ return toOperationV3({
105
+ operation,
106
+ operationInfo: {
107
+ method: method,
108
+ path,
109
+ pathItem: pathItemObject
110
+ },
111
+ stackTrail: st,
112
+ context
124
113
  });
125
- })
126
- .filter((item) => Boolean(item));
114
+ }
115
+ catch (error) {
116
+ const normalized = error instanceof Error ? error : new Error(String(error));
117
+ context.logIssueNoKey({
118
+ parent: operation,
119
+ level: 'error',
120
+ message: normalized.message,
121
+ cause: normalized,
122
+ stackTrail: st,
123
+ type: 'INVALID_OPERATION'
124
+ });
125
+ return undefined;
126
+ }
127
127
  });
128
- });
128
+ })
129
+ .filter((item) => Boolean(item));
129
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.58.3",
3
+ "version": "0.58.5",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -0,0 +1,37 @@
1
+ /**
2
+ * In a run with `onArtifact`, the operations and the component schemas that
3
+ * pass 1 parsed are let go once the file plan is built. Each is built again
4
+ * from the input document when a generator reads it, and let go after the
5
+ * last subject that can read it. Internal: `mod.ts` does not list this file.
6
+ */
7
+ import type { OasDocument } from '../oas/document/Document.js';
8
+ import type { Reach } from '../parse/Reach.js';
9
+ import type { PlannedSubject } from './Subject.js';
10
+ type BuiltOnReadArgs = {
11
+ document: OasDocument;
12
+ /** The subjects of the run, in the order their steps run. */
13
+ subjects: PlannedSubject[];
14
+ reach: Reach;
15
+ };
16
+ /**
17
+ * The run's operations and component schemas, built when read. `start` and
18
+ * `finish` go round each step, as `FilePlan.finish` does.
19
+ */
20
+ export declare class BuiltOnRead {
21
+ #private;
22
+ private constructor();
23
+ /**
24
+ * Lets the parsed operations and component schemas of `document` go, or
25
+ * returns `undefined` when its parse context builds nothing again (a run
26
+ * without `onArtifact`). Call it once the file plan is built.
27
+ */
28
+ static start({ document, subjects, reach }: BuiltOnReadArgs): BuiltOnRead | undefined;
29
+ /**
30
+ * `subject`'s step starts. The first read of its operation in the step
31
+ * builds it, and every generator of the step gets that object.
32
+ */
33
+ start(subject: PlannedSubject): void;
34
+ /** `subject`'s step has run: its operation goes, and each schema no subject left reaches. */
35
+ finish(subject: PlannedSubject): void;
36
+ }
37
+ export {};
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _BuiltOnRead_schemas, _OperationsOnRead_instances, _OperationsOnRead_source, _OperationsOnRead_places, _OperationsOnRead_held, _OperationsOnRead_listed, _OperationsOnRead_list, _SchemasOnRead_instances, _SchemasOnRead_source, _SchemasOnRead_reach, _SchemasOnRead_names, _SchemasOnRead_built, _SchemasOnRead_readInStep, _SchemasOnRead_named, _SchemasOnRead_namedLeft, _SchemasOnRead_reachedLeft, _SchemasOnRead_read, _SchemasOnRead_toReached;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BuiltOnRead = void 0;
16
+ const Subject_js_1 = require("./Subject.js");
17
+ const refFns_js_1 = require("../helpers/refFns.js");
18
+ const documentSource_js_1 = require("../oas/document/documentSource.js");
19
+ /**
20
+ * The run's operations and component schemas, built when read. `start` and
21
+ * `finish` go round each step, as `FilePlan.finish` does.
22
+ */
23
+ class BuiltOnRead {
24
+ constructor(schemas) {
25
+ _BuiltOnRead_schemas.set(this, void 0);
26
+ __classPrivateFieldSet(this, _BuiltOnRead_schemas, schemas, "f");
27
+ }
28
+ /**
29
+ * Lets the parsed operations and component schemas of `document` go, or
30
+ * returns `undefined` when its parse context builds nothing again (a run
31
+ * without `onArtifact`). Call it once the file plan is built.
32
+ */
33
+ static start({ document, subjects, reach }) {
34
+ const source = (0, documentSource_js_1.toDocumentSource)(document);
35
+ if (source === undefined) {
36
+ return undefined;
37
+ }
38
+ const operations = new OperationsOnRead({ document, source });
39
+ subjects.forEach(subject => {
40
+ if (subject instanceof Subject_js_1.OasOperationSubject) {
41
+ subject.buildOnRead(operations);
42
+ }
43
+ });
44
+ return new BuiltOnRead(new SchemasOnRead({ document, source, subjects, reach }));
45
+ }
46
+ /**
47
+ * `subject`'s step starts. The first read of its operation in the step
48
+ * builds it, and every generator of the step gets that object.
49
+ */
50
+ start(subject) {
51
+ if (subject instanceof Subject_js_1.OasOperationSubject) {
52
+ subject.startStep();
53
+ }
54
+ }
55
+ /** `subject`'s step has run: its operation goes, and each schema no subject left reaches. */
56
+ finish(subject) {
57
+ if (subject instanceof Subject_js_1.OasOperationSubject) {
58
+ subject.finishStep();
59
+ }
60
+ __classPrivateFieldGet(this, _BuiltOnRead_schemas, "f").finish(subject);
61
+ }
62
+ }
63
+ exports.BuiltOnRead = BuiltOnRead;
64
+ _BuiltOnRead_schemas = new WeakMap();
65
+ /** The key of an operation's place. A method has no space in it. */
66
+ const toPlaceKey = ({ path, method }) => `${method} ${path}`;
67
+ /**
68
+ * The operations of a document, built when a step loads one. Listing
69
+ * `document.operations` builds every one and keeps it for the rest of the
70
+ * run: a subject's operation is then the listed object.
71
+ */
72
+ class OperationsOnRead {
73
+ constructor({ document, source }) {
74
+ _OperationsOnRead_instances.add(this);
75
+ _OperationsOnRead_source.set(this, void 0);
76
+ /** The place of each operation pass 1 kept, in document order. */
77
+ _OperationsOnRead_places.set(this, void 0);
78
+ /** The operations loaded and not let go yet. */
79
+ _OperationsOnRead_held.set(this, new Map()
80
+ /** Every operation, once they are listed. */
81
+ );
82
+ /** Every operation, once they are listed. */
83
+ _OperationsOnRead_listed.set(this, void 0);
84
+ __classPrivateFieldSet(this, _OperationsOnRead_source, source, "f");
85
+ const operations = document.operations;
86
+ __classPrivateFieldSet(this, _OperationsOnRead_places, operations.map(({ path, method }) => ({ path, method })), "f");
87
+ // The getter gives the document's own array: emptying it lets the parsed operations go.
88
+ operations.splice(0);
89
+ (0, documentSource_js_1.setUnlistedOperations)(document, () => __classPrivateFieldGet(this, _OperationsOnRead_instances, "m", _OperationsOnRead_list).call(this));
90
+ }
91
+ load(place) {
92
+ const key = toPlaceKey(place);
93
+ const found = __classPrivateFieldGet(this, _OperationsOnRead_listed, "f")?.get(key) ?? __classPrivateFieldGet(this, _OperationsOnRead_held, "f").get(key);
94
+ if (found !== undefined) {
95
+ return found;
96
+ }
97
+ const operation = __classPrivateFieldGet(this, _OperationsOnRead_source, "f").toOperation(place);
98
+ __classPrivateFieldGet(this, _OperationsOnRead_held, "f").set(key, operation);
99
+ return operation;
100
+ }
101
+ letGo(place) {
102
+ __classPrivateFieldGet(this, _OperationsOnRead_held, "f").delete(toPlaceKey(place));
103
+ }
104
+ }
105
+ _OperationsOnRead_source = new WeakMap(), _OperationsOnRead_places = new WeakMap(), _OperationsOnRead_held = new WeakMap(), _OperationsOnRead_listed = new WeakMap(), _OperationsOnRead_instances = new WeakSet(), _OperationsOnRead_list = function _OperationsOnRead_list() {
106
+ const operations = __classPrivateFieldGet(this, _OperationsOnRead_places, "f").map(place => this.load(place));
107
+ __classPrivateFieldSet(this, _OperationsOnRead_listed, new Map(operations.map(operation => [toPlaceKey(operation), operation])), "f");
108
+ __classPrivateFieldGet(this, _OperationsOnRead_held, "f").clear();
109
+ return operations;
110
+ };
111
+ /**
112
+ * The component schemas of a document, built when read. `components.schemas`
113
+ * keeps its names in their order, and each entry is built when it is read. A
114
+ * built schema is kept while a subject left to run reaches it, and while the
115
+ * step that read it runs. A read after that builds it again.
116
+ *
117
+ * The count is the plan's two-step count: by a model's key, how many
118
+ * subjects left name it; by a schema's name, how many named models with
119
+ * subjects left reach it.
120
+ */
121
+ class SchemasOnRead {
122
+ constructor({ document, source, subjects, reach }) {
123
+ _SchemasOnRead_instances.add(this);
124
+ _SchemasOnRead_source.set(this, void 0);
125
+ _SchemasOnRead_reach.set(this, void 0);
126
+ /** The names of the schemas, which are their model keys. */
127
+ _SchemasOnRead_names.set(this, void 0);
128
+ _SchemasOnRead_built.set(this, new Map()
129
+ /** The schemas built in this step that no subject left reaches. */
130
+ );
131
+ /** The schemas built in this step that no subject left reaches. */
132
+ _SchemasOnRead_readInStep.set(this, new Set());
133
+ _SchemasOnRead_named.set(this, new Map()
134
+ /** By a model's key: how many subjects that name it are left to run. */
135
+ );
136
+ /** By a model's key: how many subjects that name it are left to run. */
137
+ _SchemasOnRead_namedLeft.set(this, new Map()
138
+ /** By a schema's name: how many named models with subjects left reach it. */
139
+ );
140
+ /** By a schema's name: how many named models with subjects left reach it. */
141
+ _SchemasOnRead_reachedLeft.set(this, new Map());
142
+ __classPrivateFieldSet(this, _SchemasOnRead_source, source, "f");
143
+ __classPrivateFieldSet(this, _SchemasOnRead_reach, reach, "f");
144
+ const record = document.components?.schemas ?? {};
145
+ const names = document.components?.toSchemasRefNames() ?? [];
146
+ __classPrivateFieldSet(this, _SchemasOnRead_names, new Set(names), "f");
147
+ subjects.forEach(subject => {
148
+ const named = subject.toNamedModels(reach);
149
+ named.forEach(key => {
150
+ const namedLeft = __classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").get(key) ?? 0;
151
+ if (namedLeft === 0) {
152
+ __classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_toReached).call(this, key).forEach(name => {
153
+ __classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").set(name, (__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) + 1);
154
+ });
155
+ }
156
+ __classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").set(key, namedLeft + 1);
157
+ });
158
+ __classPrivateFieldGet(this, _SchemasOnRead_named, "f").set(subject, named);
159
+ });
160
+ // Each entry becomes a getter at its own position, so the names keep
161
+ // their order, and the parsed schema it held is let go.
162
+ names.forEach(name => {
163
+ Object.defineProperty(record, name, {
164
+ get: () => __classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_read).call(this, name),
165
+ enumerable: true,
166
+ configurable: true
167
+ });
168
+ });
169
+ }
170
+ finish(subject) {
171
+ const named = __classPrivateFieldGet(this, _SchemasOnRead_named, "f").get(subject) ?? [];
172
+ __classPrivateFieldGet(this, _SchemasOnRead_named, "f").delete(subject);
173
+ named.forEach(key => {
174
+ const namedLeft = (__classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").get(key) ?? 0) - 1;
175
+ __classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").set(key, namedLeft);
176
+ if (namedLeft === 0) {
177
+ __classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_toReached).call(this, key).forEach(name => {
178
+ const reachedLeft = (__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) - 1;
179
+ __classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").set(name, reachedLeft);
180
+ if (reachedLeft === 0) {
181
+ __classPrivateFieldGet(this, _SchemasOnRead_built, "f").delete(name);
182
+ }
183
+ });
184
+ }
185
+ });
186
+ __classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").forEach(name => __classPrivateFieldGet(this, _SchemasOnRead_built, "f").delete(name));
187
+ __classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").clear();
188
+ }
189
+ }
190
+ _SchemasOnRead_source = new WeakMap(), _SchemasOnRead_reach = new WeakMap(), _SchemasOnRead_names = new WeakMap(), _SchemasOnRead_built = new WeakMap(), _SchemasOnRead_readInStep = new WeakMap(), _SchemasOnRead_named = new WeakMap(), _SchemasOnRead_namedLeft = new WeakMap(), _SchemasOnRead_reachedLeft = new WeakMap(), _SchemasOnRead_instances = new WeakSet(), _SchemasOnRead_read = function _SchemasOnRead_read(name) {
191
+ const found = __classPrivateFieldGet(this, _SchemasOnRead_built, "f").get(name);
192
+ if (found !== undefined) {
193
+ return found;
194
+ }
195
+ const schema = __classPrivateFieldGet(this, _SchemasOnRead_source, "f").toSchema(name);
196
+ __classPrivateFieldGet(this, _SchemasOnRead_built, "f").set(name, schema);
197
+ if ((__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) === 0) {
198
+ __classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").add(name);
199
+ }
200
+ return schema;
201
+ }, _SchemasOnRead_toReached = function _SchemasOnRead_toReached(key) {
202
+ return __classPrivateFieldGet(this, _SchemasOnRead_reach, "f").ofModel((0, refFns_js_1.fromModelKey)(key)).filter(model => __classPrivateFieldGet(this, _SchemasOnRead_names, "f").has(model));
203
+ };
@@ -65,6 +65,7 @@ const colors_js_1 = require("../deps/jsr.io/@std/fmt/1.0.10/colors.js");
65
65
  const SerializedError_js_1 = require("../types/SerializedError.js");
66
66
  const toGenerationFailure_js_1 = require("./toGenerationFailure.js");
67
67
  const toCountPhrase_js_1 = require("../helpers/toCountPhrase.js");
68
+ const documentSource_js_1 = require("../oas/document/documentSource.js");
68
69
  /**
69
70
  * The main orchestration class for the SKMTC transformation pipeline.
70
71
  *
@@ -346,7 +347,12 @@ class CoreContext {
346
347
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
347
348
  __classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
348
349
  __classPrivateFieldSet(this, _CoreContext_enrichmentWarnings, [], "f");
349
- const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document, settings);
350
+ // A capturing render and an inspection read every file at the end
351
+ // of the run, so such a run gives no file before then. A run that
352
+ // gives files early can build its operations and schemas again when
353
+ // a generator reads them, so the parse context knows it first.
354
+ const givesFilesEarly = onArtifact !== undefined && !attribution?.postPass && !inspect;
355
+ const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document, settings, givesFilesEarly);
350
356
  __classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
351
357
  __classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
352
358
  const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
@@ -372,9 +378,6 @@ class CoreContext {
372
378
  captureChannel
373
379
  });
374
380
  __classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
375
- // A capturing render and an inspection read every file at the end
376
- // of the run, so such a run gives no file before then.
377
- const givesFilesEarly = onArtifact !== undefined && !attribution?.postPass && !inspect;
378
381
  const generated = generatePhase.context.toArtifacts(st, givesFilesEarly
379
382
  ? {
380
383
  reach: phase.context.toReach(),
@@ -678,7 +681,7 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
678
681
  throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
679
682
  }
680
683
  }
681
- }, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input, settings) {
684
+ }, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input, settings, planned = false) {
682
685
  if (settings?.parse && settings.system) {
683
686
  this.logger.warn('settings.parse and settings.system are both set: settings.parse is used and settings.system is ignored. ' +
684
687
  'settings.system is the deprecated name of settings.parse; remove it.');
@@ -689,6 +692,9 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
689
692
  silent: this.silent,
690
693
  system: settings?.parse ?? settings?.system
691
694
  });
695
+ if (planned) {
696
+ (0, documentSource_js_1.markPlannedParse)(parseContext);
697
+ }
692
698
  return { type: 'parse', context: parseContext };
693
699
  }, _CoreContext_setupGeneratePhase = function _CoreContext_setupGeneratePhase({ document, settings, toGeneratorConfigMap, captureChannel }) {
694
700
  const generateContext = new GenerateContext_js_1.GenerateContext({
@@ -368,6 +368,9 @@ export declare class GenerateContext implements GenerateContextType {
368
368
  * `toEnrichments` against the given `ref` and `variant`. The full
369
369
  * identifier is assembled through the projection's language
370
370
  * (`lang.toIdentifier`).
371
+ *
372
+ * With no projection options, `toIdentifierName` and `toExportPath` are
373
+ * asked once in a run for each projection, ref and variant.
371
374
  */
372
375
  toModelContentSettings<V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: BuildModelSettingsArgs<V, EnrichmentType, ProjectionOptions>): ContentSettings<EnrichmentType>;
373
376
  /**
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedItems, _GenerateContext_foldedPaths, _GenerateContext_released, _GenerateContext_previews, _GenerateContext_captureChannel, _GenerateContext_enrichmentAudit, _GenerateContext_currentSubjectTrail, _GenerateContext_logsGeneratorLines, _GenerateContext_subjectCounts, _GenerateContext_reportSkippedEnrichment, _GenerateContext_logError, _GenerateContext_failItem, _GenerateContext_captureSubjectResult, _GenerateContext_runByGenerator, _GenerateContext_runBySubject, _GenerateContext_toGeneratorRuns, _GenerateContext_toSteps, _GenerateContext_release, _GenerateContext_affirmNotReleased, _GenerateContext_logGeneratorLine, _GenerateContext_runGenerator, _GenerateContext_schemaRefNames, _GenerateContext_subjectDefaults, _GenerateContext_runSubjects, _GenerateContext_addPreview, _GenerateContext_toContentSettingsExportPath, _GenerateContext_ejectedBySuffixedPath_get, _GenerateContext_ejectedBySuffixedPathCache, _GenerateContext_findContainer, _GenerateContext_toContainer;
16
+ var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedItems, _GenerateContext_foldedPaths, _GenerateContext_released, _GenerateContext_previews, _GenerateContext_captureChannel, _GenerateContext_enrichmentAudit, _GenerateContext_currentSubjectTrail, _GenerateContext_logsGeneratorLines, _GenerateContext_subjectCounts, _GenerateContext_reportSkippedEnrichment, _GenerateContext_logError, _GenerateContext_failItem, _GenerateContext_captureSubjectResult, _GenerateContext_runByGenerator, _GenerateContext_runBySubject, _GenerateContext_toGeneratorRuns, _GenerateContext_toSteps, _GenerateContext_release, _GenerateContext_affirmNotReleased, _GenerateContext_logGeneratorLine, _GenerateContext_runGenerator, _GenerateContext_schemaRefNames, _GenerateContext_subjectDefaults, _GenerateContext_runSubjects, _GenerateContext_addPreview, _GenerateContext_toContentSettingsExportPath, _GenerateContext_ejectedBySuffixedPath_get, _GenerateContext_ejectedBySuffixedPathCache, _GenerateContext_modelIdentities, _GenerateContext_findContainer, _GenerateContext_toContainer;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.GenerateContext = exports.toWebhookSource = exports.toOasOperationSource = exports.toModelSource = exports.toGqlOperationSource = void 0;
19
19
  const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
@@ -33,6 +33,7 @@ const Variant_js_1 = require("../types/Variant.js");
33
33
  const toVariantList_js_1 = require("../helpers/toVariantList.js");
34
34
  const Subject_js_1 = require("./Subject.js");
35
35
  const FilePlan_js_1 = require("./FilePlan.js");
36
+ const BuiltOnRead_js_1 = require("./BuiltOnRead.js");
36
37
  var Subject_js_2 = require("./Subject.js");
37
38
  Object.defineProperty(exports, "toGqlOperationSource", { enumerable: true, get: function () { return Subject_js_2.toGqlOperationSource; } });
38
39
  Object.defineProperty(exports, "toModelSource", { enumerable: true, get: function () { return Subject_js_2.toModelSource; } });
@@ -213,6 +214,21 @@ class GenerateContext {
213
214
  /** The counts of the generator {@link toArtifacts} is running. */
214
215
  _GenerateContext_subjectCounts.set(this, { offered: 0, transformed: 0, failed: 0 });
215
216
  _GenerateContext_ejectedBySuffixedPathCache.set(this, void 0);
217
+ /** By a model projection class: the name and the export path of each model and variant it was asked for. */
218
+ _GenerateContext_modelIdentities.set(this, new Map()
219
+ /**
220
+ * Look up an already-registered file by path, or `undefined` if none
221
+ * exists. In a run with `onArtifact`, a lookup of a file that was given
222
+ * to the host throws. Neutral primitive: returns the abstract `FileBase` and never
223
+ * constructs anything, so a (future) language-owned `register` can ask
224
+ * "does this file exist yet?" without the engine knowing the language.
225
+ * To create on a miss, add a file your language constructs with
226
+ * {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
227
+ *
228
+ * `filePath` may be in any spelling. It is normalized only when it is no
229
+ * key: a key is a normalized path. The file's own `path` is the key.
230
+ */
231
+ );
216
232
  this.logger = logger;
217
233
  __classPrivateFieldSet(this, _GenerateContext_logsGeneratorLines, logsGeneratorLines, "f");
218
234
  __classPrivateFieldSet(this, _GenerateContext_files, new Map(), "f");
@@ -883,17 +899,38 @@ class GenerateContext {
883
899
  * `toEnrichments` against the given `ref` and `variant`. The full
884
900
  * identifier is assembled through the projection's language
885
901
  * (`lang.toIdentifier`).
902
+ *
903
+ * With no projection options, `toIdentifierName` and `toExportPath` are
904
+ * asked once in a run for each projection, ref and variant.
886
905
  */
887
906
  toModelContentSettings(args) {
888
907
  const { ref, projection, variant = Variant_js_1.DEFAULT_VARIANT } = args;
889
908
  const options = (0, ProjectionOptions_js_1.readProjectionOptions)(args);
890
909
  const enrichments = projection.toEnrichments({ ref, context: this, variant });
910
+ // A model is referred to many times in a run, and its name and its
911
+ // export path are the same each time: they come from the ref, the
912
+ // enrichments and the variant. With options they can differ, so only a
913
+ // call with no options is kept.
914
+ // Each part of the key can hold any character: the lengths keep them apart.
915
+ const key = options === undefined
916
+ ? `${ref.refPath.length}:${ref.refName.length}:${ref.refPath}${ref.refName}${variant}`
917
+ : undefined;
918
+ const kept = key === undefined ? undefined : __classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").get(projection)?.get(key);
919
+ const identity = kept ?? {
920
+ name: projection.toIdentifierName({ ref, enrichments, variant, options }),
921
+ exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({ ref, enrichments, variant, options }), projection.id)
922
+ };
923
+ if (key !== undefined && kept === undefined) {
924
+ const byKey = __classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").get(projection) ?? new Map();
925
+ byKey.set(key, identity);
926
+ __classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").set(projection, byKey);
927
+ }
891
928
  return new ContentSettings_js_1.ContentSettings({
892
929
  identifier: projection.lang.toIdentifier({
893
- name: projection.toIdentifierName({ ref, enrichments, variant, options }),
930
+ name: identity.name,
894
931
  ...projection.toIdentifierType(ref, this)
895
932
  }),
896
- exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({ ref, enrichments, variant, options }), projection.id),
933
+ exportPath: identity.exportPath,
897
934
  enrichments,
898
935
  variant
899
936
  });
@@ -964,7 +1001,7 @@ class GenerateContext {
964
1001
  }
965
1002
  }
966
1003
  exports.GenerateContext = GenerateContext;
967
- _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakMap(), _GenerateContext_foldedPaths = new WeakMap(), _GenerateContext_released = new WeakMap(), _GenerateContext_previews = new WeakMap(), _GenerateContext_captureChannel = new WeakMap(), _GenerateContext_enrichmentAudit = new WeakMap(), _GenerateContext_currentSubjectTrail = new WeakMap(), _GenerateContext_logsGeneratorLines = new WeakMap(), _GenerateContext_subjectCounts = new WeakMap(), _GenerateContext_ejectedBySuffixedPathCache = new WeakMap(), _GenerateContext_instances = new WeakSet(), _GenerateContext_reportSkippedEnrichment = function _GenerateContext_reportSkippedEnrichment(block, variant, path) {
1004
+ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakMap(), _GenerateContext_foldedPaths = new WeakMap(), _GenerateContext_released = new WeakMap(), _GenerateContext_previews = new WeakMap(), _GenerateContext_captureChannel = new WeakMap(), _GenerateContext_enrichmentAudit = new WeakMap(), _GenerateContext_currentSubjectTrail = new WeakMap(), _GenerateContext_logsGeneratorLines = new WeakMap(), _GenerateContext_subjectCounts = new WeakMap(), _GenerateContext_ejectedBySuffixedPathCache = new WeakMap(), _GenerateContext_modelIdentities = new WeakMap(), _GenerateContext_instances = new WeakSet(), _GenerateContext_reportSkippedEnrichment = function _GenerateContext_reportSkippedEnrichment(block, variant, path) {
968
1005
  if (!(0, EnrichmentAudit_js_1.hasVariantEnrichment)(block, variant))
969
1006
  return;
970
1007
  __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").report({
@@ -1036,11 +1073,17 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
1036
1073
  ...(readyAfter.get(0) ?? []),
1037
1074
  ...modelSteps.flatMap((step, index) => [step, ...(readyAfter.get(index + 1) ?? [])])
1038
1075
  ];
1039
- const plan = this.toFilePlan({ subjects: steps.map(({ subject }) => subject), reach });
1076
+ const subjects = steps.map(({ subject }) => subject);
1077
+ const plan = this.toFilePlan({ subjects, reach });
1078
+ // The plan asked the pass 1 operations. From here each step builds its
1079
+ // operation again, and each schema is built when it is read.
1080
+ const builtOnRead = BuiltOnRead_js_1.BuiltOnRead.start({ document: oasDocument, subjects, reach });
1040
1081
  steps.forEach(step => {
1082
+ builtOnRead?.start(step.subject);
1041
1083
  step.run();
1042
1084
  // A run that has failed gives no more files: it will write nothing.
1043
1085
  const complete = plan.finish(step.subject);
1086
+ builtOnRead?.finish(step.subject);
1044
1087
  if (__classPrivateFieldGet(this, _GenerateContext_failedItems, "f").length === 0) {
1045
1088
  complete.forEach(path => __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_release).call(this, path, onFile));
1046
1089
  }