@skmtc/core 0.58.2 → 0.58.4

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 (63) 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 -3
  5. package/esm/context/GenerateContext.js +13 -6
  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/context/generateTypes.d.ts +2 -2
  10. package/esm/dsl/model/ModelDriver.js +2 -2
  11. package/esm/dsl/operation/gql/GqlOperationDriver.js +2 -2
  12. package/esm/dsl/operation/oas/OasOperationDriver.js +2 -2
  13. package/esm/dsl/webhook/WebhookDriver.js +2 -2
  14. package/esm/helpers/getPath.d.ts +6 -0
  15. package/esm/helpers/getPath.js +6 -0
  16. package/esm/helpers/isDeepEqual.d.ts +17 -0
  17. package/esm/helpers/isDeepEqual.js +93 -0
  18. package/esm/helpers/parseModuleName.d.ts +8 -8
  19. package/esm/helpers/parseModuleName.js +8 -8
  20. package/esm/helpers/toVariantList.d.ts +1 -1
  21. package/esm/oas/document/Document.d.ts +5 -1
  22. package/esm/oas/document/Document.js +10 -1
  23. package/esm/oas/document/documentSource.d.ts +37 -0
  24. package/esm/oas/document/documentSource.js +27 -0
  25. package/esm/oas/schema/siblings.js +6 -4
  26. package/esm/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  27. package/esm/parse/v3-0/operation/toOperationsV3.js +68 -67
  28. package/esm/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  29. package/esm/parse/v3-1/operation/toOperationsV3.js +68 -67
  30. package/esm/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  31. package/esm/parse/v3-2/operation/toOperationsV3.js +69 -68
  32. package/package.json +1 -4
  33. package/script/context/BuiltOnRead.d.ts +37 -0
  34. package/script/context/BuiltOnRead.js +203 -0
  35. package/script/context/CoreContext.js +11 -5
  36. package/script/context/GenerateContext.d.ts +3 -3
  37. package/script/context/GenerateContext.js +13 -6
  38. package/script/context/ParseContext.js +116 -11
  39. package/script/context/Subject.d.ts +29 -2
  40. package/script/context/Subject.js +67 -6
  41. package/script/context/generateTypes.d.ts +2 -2
  42. package/script/dsl/model/ModelDriver.js +2 -5
  43. package/script/dsl/operation/gql/GqlOperationDriver.js +2 -5
  44. package/script/dsl/operation/oas/OasOperationDriver.js +2 -2
  45. package/script/dsl/webhook/WebhookDriver.js +2 -5
  46. package/script/helpers/getPath.d.ts +6 -0
  47. package/script/helpers/getPath.js +10 -0
  48. package/script/helpers/isDeepEqual.d.ts +17 -0
  49. package/script/helpers/isDeepEqual.js +97 -0
  50. package/script/helpers/parseModuleName.d.ts +8 -8
  51. package/script/helpers/parseModuleName.js +8 -8
  52. package/script/helpers/toVariantList.d.ts +1 -1
  53. package/script/oas/document/Document.d.ts +5 -1
  54. package/script/oas/document/Document.js +10 -1
  55. package/script/oas/document/documentSource.d.ts +37 -0
  56. package/script/oas/document/documentSource.js +36 -0
  57. package/script/oas/schema/siblings.js +6 -7
  58. package/script/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  59. package/script/parse/v3-0/operation/toOperationsV3.js +71 -69
  60. package/script/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  61. package/script/parse/v3-1/operation/toOperationsV3.js +71 -69
  62. package/script/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  63. package/script/parse/v3-2/operation/toOperationsV3.js +72 -70
@@ -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({
@@ -175,9 +175,9 @@ export declare class GenerateContext implements GenerateContextType {
175
175
  * The recording enrichment accessor — the single choke point every
176
176
  * enrichment lookup routes through (dispatch loops, projection-base
177
177
  * `toEnrichments`, the Drivers' peer-variant guards). Segments are
178
- * literal keys (the array form of `get` keeps dotted paths intact);
179
- * the read is recorded so the post-walk consumption audit can flag
180
- * configured entries no lookup ever touched.
178
+ * literal keys (`getPath` keeps dotted paths intact); the read is
179
+ * recorded so the post-walk consumption audit can flag configured
180
+ * entries no lookup ever touched.
181
181
  */
182
182
  readEnrichment(segments: readonly string[]): unknown;
183
183
  /** Add a warning to this run's enrichment audit (deduplicated). */
@@ -33,12 +33,13 @@ 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; } });
39
40
  Object.defineProperty(exports, "toOasOperationSource", { enumerable: true, get: function () { return Subject_js_2.toOasOperationSource; } });
40
41
  Object.defineProperty(exports, "toWebhookSource", { enumerable: true, get: function () { return Subject_js_2.toWebhookSource; } });
41
- const get_js_1 = __importDefault(require("lodash-es/get.js"));
42
+ const getPath_js_1 = require("../helpers/getPath.js");
42
43
  const Inserted_js_1 = require("../dsl/Inserted.js");
43
44
  const CodeFileBase_js_1 = require("../dsl/CodeFileBase.js");
44
45
  const DefinitionContainer_js_1 = require("../dsl/DefinitionContainer.js");
@@ -228,9 +229,9 @@ class GenerateContext {
228
229
  * The recording enrichment accessor — the single choke point every
229
230
  * enrichment lookup routes through (dispatch loops, projection-base
230
231
  * `toEnrichments`, the Drivers' peer-variant guards). Segments are
231
- * literal keys (the array form of `get` keeps dotted paths intact);
232
- * the read is recorded so the post-walk consumption audit can flag
233
- * configured entries no lookup ever touched.
232
+ * literal keys (`getPath` keeps dotted paths intact); the read is
233
+ * recorded so the post-walk consumption audit can flag configured
234
+ * entries no lookup ever touched.
234
235
  */
235
236
  readEnrichment(segments) {
236
237
  // Recording only matters when there is config to audit — on the common
@@ -239,7 +240,7 @@ class GenerateContext {
239
240
  if (this.settings?.enrichments !== undefined) {
240
241
  __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").consume(segments);
241
242
  }
242
- return (0, get_js_1.default)(this.settings, ['enrichments', ...segments]);
243
+ return (0, getPath_js_1.getPath)(this.settings, ['enrichments', ...segments]);
243
244
  }
244
245
  /** Add a warning to this run's enrichment audit (deduplicated). */
245
246
  reportEnrichmentWarning(warning) {
@@ -1036,11 +1037,17 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
1036
1037
  ...(readyAfter.get(0) ?? []),
1037
1038
  ...modelSteps.flatMap((step, index) => [step, ...(readyAfter.get(index + 1) ?? [])])
1038
1039
  ];
1039
- const plan = this.toFilePlan({ subjects: steps.map(({ subject }) => subject), reach });
1040
+ const subjects = steps.map(({ subject }) => subject);
1041
+ const plan = this.toFilePlan({ subjects, reach });
1042
+ // The plan asked the pass 1 operations. From here each step builds its
1043
+ // operation again, and each schema is built when it is read.
1044
+ const builtOnRead = BuiltOnRead_js_1.BuiltOnRead.start({ document: oasDocument, subjects, reach });
1040
1045
  steps.forEach(step => {
1046
+ builtOnRead?.start(step.subject);
1041
1047
  step.run();
1042
1048
  // A run that has failed gives no more files: it will write nothing.
1043
1049
  const complete = plan.finish(step.subject);
1050
+ builtOnRead?.finish(step.subject);
1044
1051
  if (__classPrivateFieldGet(this, _GenerateContext_failedItems, "f").length === 0) {
1045
1052
  complete.forEach(path => __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_release).call(this, path, onFile));
1046
1053
  }
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  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");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_refTargets, _ParseContext_refTarget, _ParseContext_keptRefs, _ParseContext_issueIdentities, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_parseRefTargets, _ParseContext_inRefTarget, _ParseContext_addIssue, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_logDependencyIssue, _ParseContext_toDocumentLocation, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
13
+ var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_refTargets, _ParseContext_refTarget, _ParseContext_keptRefs, _ParseContext_issueIdentities, _ParseContext_rootFrames, _ParseContext_dialect, _ParseContext_rebuilding, _ParseContext_removedPathParameters, _ParseContext_rebuildOperation, _ParseContext_rebuildSchema, _ParseContext_whileRebuilding, _ParseContext_removeComponent, _ParseContext_parseRefTargets, _ParseContext_inRefTarget, _ParseContext_addIssue, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_logDependencyIssue, _ParseContext_toDocumentLocation, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ParseContext = void 0;
16
16
  /**
@@ -54,6 +54,21 @@ const toRefKey_js_1 = require("../parse/toRefKey.js");
54
54
  const toRefTargetV3_js_1 = require("../parse/v3-0/ref/toRefTargetV3.js");
55
55
  const toRefTargetV3_js_2 = require("../parse/v3-1/ref/toRefTargetV3.js");
56
56
  const toRefTargetV3_js_3 = require("../parse/v3-2/ref/toRefTargetV3.js");
57
+ const toOperationsV3_js_1 = require("../parse/v3-0/operation/toOperationsV3.js");
58
+ const toOperationsV3_js_2 = require("../parse/v3-1/operation/toOperationsV3.js");
59
+ const toOperationsV3_js_3 = require("../parse/v3-2/operation/toOperationsV3.js");
60
+ const toSchemasV3_js_1 = require("../parse/v3-0/schema/toSchemasV3.js");
61
+ const toSchemasV3_js_2 = require("../parse/v3-1/schema/toSchemasV3.js");
62
+ const toSchemasV3_js_3 = require("../parse/v3-2/schema/toSchemasV3.js");
63
+ const documentSource_js_1 = require("../oas/document/documentSource.js");
64
+ /** Takes a removed path-level parameter out of `pathItem`, which its operations share. */
65
+ const removePathParameter = (pathItem, { entryRef, name, in: location }) => {
66
+ if (pathItem?.parameters) {
67
+ pathItem.parameters = pathItem.parameters.filter(parameter => parameter.isRef()
68
+ ? parameter.$ref !== entryRef
69
+ : entryRef !== undefined || parameter.name !== name || parameter.location !== location);
70
+ }
71
+ };
57
72
  /** The issue logged when a ref target's parser throws. */
58
73
  const toInvalidType = (refType) => {
59
74
  switch (refType) {
@@ -180,7 +195,17 @@ class ParseContext {
180
195
  * 'parse']` through `toArtifacts`). Every trail built during the walk
181
196
  * starts with them; `#toDocumentTrail` strips them.
182
197
  */
183
- _ParseContext_rootFrames.set(this, []);
198
+ _ParseContext_rootFrames.set(this, []
199
+ /** The dialect `parse()` picked for an OpenAPI document. */
200
+ );
201
+ /** The dialect `parse()` picked for an OpenAPI document. */
202
+ _ParseContext_dialect.set(this, void 0);
203
+ /** While a part of the document is built again, nothing is recorded: no issue, no ref and no ref error. */
204
+ _ParseContext_rebuilding.set(this, false
205
+ /** By path: the path-level parameters `#removePathParameterConsumer` took out of the path item. */
206
+ );
207
+ /** By path: the path-level parameters `#removePathParameterConsumer` took out of the path item. */
208
+ _ParseContext_removedPathParameters.set(this, new Map());
184
209
  this.logger = logger;
185
210
  this.silent = silent;
186
211
  this.system = system ?? {};
@@ -298,6 +323,7 @@ class ParseContext {
298
323
  // parser tree. Everything downstream is version-specific code living
299
324
  // in its own tree (v3-0 / v3-1 / v3-2) and never re-checks the version.
300
325
  const dialect = (0, toOasDialect_js_1.toOasDialect)(oasState.documentObject.openapi);
326
+ __classPrivateFieldSet(this, _ParseContext_dialect, dialect, "f");
301
327
  switch (dialect) {
302
328
  case '3.0':
303
329
  oasState.oasDocument.fields = (0, toDocumentFieldsV3_js_1.toDocumentFieldsV3)({
@@ -330,6 +356,14 @@ class ParseContext {
330
356
  }
331
357
  __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_checkRefs).call(this);
332
358
  this.removeErroredItems();
359
+ // A run that gives files early builds its operations and component
360
+ // schemas again when a generator reads them (`BuiltOnRead`).
361
+ if ((0, documentSource_js_1.isPlannedParse)(this)) {
362
+ (0, documentSource_js_1.setDocumentSource)(oasState.oasDocument, {
363
+ toOperation: place => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_rebuildOperation).call(this, place),
364
+ toSchema: name => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_rebuildSchema).call(this, name)
365
+ });
366
+ }
333
367
  return { type: 'oas', value: oasState.oasDocument };
334
368
  }
335
369
  case 'gql': {
@@ -441,6 +475,9 @@ class ParseContext {
441
475
  * would use type names or qualified field paths.
442
476
  */
443
477
  registerRef(consumer, refKey) {
478
+ if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
479
+ return;
480
+ }
444
481
  const refConsumer = { consumer, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") };
445
482
  const existing = __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey);
446
483
  if (existing) {
@@ -457,6 +494,9 @@ class ParseContext {
457
494
  * resolve it there.
458
495
  */
459
496
  registerOasRef(consumer, ref) {
497
+ if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
498
+ return;
499
+ }
460
500
  this.registerRef(consumer, (0, toRefKey_js_1.toRefKey)(ref));
461
501
  __classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") });
462
502
  }
@@ -493,7 +533,7 @@ class ParseContext {
493
533
  * each `INVALID_DEPENDENCY_REF` it causes names it.
494
534
  */
495
535
  registerRefError(error, refKey, location) {
496
- if (!refKey)
536
+ if (!refKey || __classPrivateFieldGet(this, _ParseContext_rebuilding, "f"))
497
537
  return;
498
538
  const refError = { error, location };
499
539
  const existing = __classPrivateFieldGet(this, _ParseContext_refErrors, "f").get(refKey);
@@ -521,6 +561,10 @@ class ParseContext {
521
561
  * manifest).
522
562
  */
523
563
  logIssueAt(issue, parent) {
564
+ // A rebuild logs nothing: pass 1 logged each issue once. Every issue is kept through here.
565
+ if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
566
+ return;
567
+ }
524
568
  const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
525
569
  if (added && !this.silent) {
526
570
  const message = `${issue.type} at ${__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentLocation).call(this, issue)}: ${issue.message}`;
@@ -655,7 +699,69 @@ class ParseContext {
655
699
  }
656
700
  }
657
701
  exports.ParseContext = ParseContext;
658
- _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMap(), _ParseContext_oasRefs = new WeakMap(), _ParseContext_refTargets = new WeakMap(), _ParseContext_refTarget = new WeakMap(), _ParseContext_keptRefs = new WeakMap(), _ParseContext_issueIdentities = new WeakMap(), _ParseContext_rootFrames = new WeakMap(), _ParseContext_instances = new WeakSet(), _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
702
+ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMap(), _ParseContext_oasRefs = new WeakMap(), _ParseContext_refTargets = new WeakMap(), _ParseContext_refTarget = new WeakMap(), _ParseContext_keptRefs = new WeakMap(), _ParseContext_issueIdentities = new WeakMap(), _ParseContext_rootFrames = new WeakMap(), _ParseContext_dialect = new WeakMap(), _ParseContext_rebuilding = new WeakMap(), _ParseContext_removedPathParameters = new WeakMap(), _ParseContext_instances = new WeakSet(), _ParseContext_rebuildOperation = function _ParseContext_rebuildOperation({ path, method }) {
703
+ const pathItem = this.documentObject.paths?.[path];
704
+ if (!(0, isPlainObject_js_1.isPlainObject)(pathItem)) {
705
+ throw new Error(`Cannot build the operation '${method.toUpperCase()} ${path}' again: the document has no such path`);
706
+ }
707
+ const args = {
708
+ path,
709
+ pathItem,
710
+ method,
711
+ stackTrail: new StackTrail_js_1.StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), 'paths', path]),
712
+ context: this
713
+ };
714
+ const [operation] = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_whileRebuilding).call(this, () => {
715
+ switch (__classPrivateFieldGet(this, _ParseContext_dialect, "f")) {
716
+ case '3.0':
717
+ return (0, toOperationsV3_js_1.toPathOperationsV3)(args);
718
+ case '3.1':
719
+ return (0, toOperationsV3_js_2.toPathOperationsV3)(args);
720
+ case '3.2':
721
+ return (0, toOperationsV3_js_3.toPathOperationsV3)(args);
722
+ default:
723
+ throw new Error('Cannot build an operation again before the document is parsed');
724
+ }
725
+ });
726
+ if (operation === undefined) {
727
+ throw new Error(`Cannot build the operation '${method.toUpperCase()} ${path}' again: it does not parse`);
728
+ }
729
+ __classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f")
730
+ .get(path)
731
+ ?.forEach(removed => removePathParameter(operation.pathItem, removed));
732
+ return operation;
733
+ }, _ParseContext_rebuildSchema = function _ParseContext_rebuildSchema(name) {
734
+ const schema = this.documentObject.components?.schemas?.[name];
735
+ if (schema === undefined) {
736
+ throw new Error(`Cannot build the schema '${name}' again: the document has no such schema`);
737
+ }
738
+ const args = {
739
+ schema,
740
+ stackTrail: new StackTrail_js_1.StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), 'components', 'schemas', name]),
741
+ context: this
742
+ };
743
+ return __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_whileRebuilding).call(this, () => {
744
+ switch (__classPrivateFieldGet(this, _ParseContext_dialect, "f")) {
745
+ case '3.0':
746
+ return (0, toSchemasV3_js_1.toSchemaV3)(args);
747
+ case '3.1':
748
+ return (0, toSchemasV3_js_2.toSchemaV3)(args);
749
+ case '3.2':
750
+ return (0, toSchemasV3_js_3.toSchemaV3)(args);
751
+ default:
752
+ throw new Error('Cannot build a schema again before the document is parsed');
753
+ }
754
+ });
755
+ }, _ParseContext_whileRebuilding = function _ParseContext_whileRebuilding(fn) {
756
+ const previous = __classPrivateFieldGet(this, _ParseContext_rebuilding, "f");
757
+ __classPrivateFieldSet(this, _ParseContext_rebuilding, true, "f");
758
+ try {
759
+ return fn();
760
+ }
761
+ finally {
762
+ __classPrivateFieldSet(this, _ParseContext_rebuilding, previous, "f");
763
+ }
764
+ }, _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
659
765
  if (this.protocol.type !== 'oas') {
660
766
  return;
661
767
  }
@@ -764,19 +870,18 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
764
870
  ? rawEntry
765
871
  : (0, refFns_js_1.toRawRefTarget)(documentObject, (0, refFns_js_1.toRefParts)({ $ref: entryRef })));
766
872
  const broken = [{ location: documentTrail.toString(), message: '', ...nameAndIn }];
873
+ const removed = { entryRef, ...nameAndIn };
874
+ // An operation built again later gets a path item of its own, which loses the entry the same way.
875
+ if (first === 'paths') {
876
+ __classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f").set(second, [...(__classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f").get(second) ?? []), removed]);
877
+ }
767
878
  const operations = first === 'paths'
768
879
  ? oasDocument.operations.filter(({ path }) => path === second)
769
880
  : oasDocument.webhooks.filter(({ name }) => name === second);
770
881
  const removedLocations = operations.flatMap(({ method, pathItem }) => {
771
882
  const rawOperation = (0, isPlainObject_js_1.isPlainObject)(rawPathItem) ? rawPathItem[method] : undefined;
772
883
  if ((0, pathParameters_js_1.toApplyingBrokenParameter)({ broken, operation: rawOperation }) === undefined) {
773
- if (pathItem?.parameters) {
774
- pathItem.parameters = pathItem.parameters.filter(parameter => parameter.isRef()
775
- ? parameter.$ref !== entryRef
776
- : entryRef !== undefined ||
777
- parameter.name !== nameAndIn.name ||
778
- parameter.location !== nameAndIn.in);
779
- }
884
+ removePathParameter(pathItem, removed);
780
885
  return [];
781
886
  }
782
887
  return oasDocument.removeItem(new StackTrail_js_1.StackTrail([first, second, method])) === undefined
@@ -8,8 +8,10 @@ import type { OasWebhook } from '../oas/webhook/Webhook.js';
8
8
  import type { GqlOperation } from '../gql/operation/GqlOperation.js';
9
9
  import type { DeclaredProjection } from '../dsl/DeclaredProjection.js';
10
10
  import type { Reach } from '../parse/Reach.js';
11
+ import type { OperationPlace } from '../oas/document/documentSource.js';
11
12
  import { type RefParts } from '../helpers/refFns.js';
12
13
  import type { RefName } from '../types/RefName.js';
14
+ import type { Method } from '../types/Method.js';
13
15
  import type { IncludeModelRefs, IncludePaths, SkipModelRefs, SkipPaths } from '../types/Settings.js';
14
16
  import type { GqlOperationSource, ModelSource, OasOperationSource, PreviewModule, WebhookSource } from '../types/Preview.js';
15
17
  /** A generator entry, the run's context and one variant: what a subject is asked with. */
@@ -71,14 +73,39 @@ export type Subject<Entry, Filter> = PlannedSubject & {
71
73
  toPreviewModule: (args: AskArgs<Entry>) => PreviewModule | undefined;
72
74
  toSource(args: ToSourceArgs): OasOperationSource | WebhookSource | GqlOperationSource | ModelSource;
73
75
  };
74
- /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
76
+ /** What builds an operation again from its place, and lets it go. */
77
+ export type OperationLoader = {
78
+ load(place: OperationPlace): OasOperation;
79
+ letGo(place: OperationPlace): void;
80
+ };
81
+ /**
82
+ * An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`.
83
+ *
84
+ * It holds the operation it is constructed with. In a run that builds
85
+ * operations on read, it lets that one go once the file plan is built. In
86
+ * its step, the first read builds its operation through the document, and
87
+ * it lets the operation go when the step has run.
88
+ */
75
89
  export declare class OasOperationSubject implements Subject<OasOperationEntry, IncludePaths | SkipPaths> {
90
+ #private;
76
91
  readonly type = "oasOperation";
77
- operation: OasOperation;
92
+ readonly path: string;
93
+ readonly method: Method;
78
94
  trail: string[];
79
95
  enrichmentPath: string[];
80
96
  label: string;
81
97
  constructor(operation: OasOperation);
98
+ /**
99
+ * Its operation. In a run that builds operations on read, only while its
100
+ * step runs: the first read in the step builds it.
101
+ */
102
+ get operation(): OasOperation;
103
+ /** Lets go of the operation it was constructed with: from now on, `loader` gives it. */
104
+ buildOnRead(loader: OperationLoader): void;
105
+ /** Its step starts. A step that never reads its operation, such as one with no generator, builds none. */
106
+ startStep(): void;
107
+ /** Its step has run: it lets go of the operation the step built. */
108
+ finishStep(): void;
82
109
  isSupported({ entry, context, variant }: AskArgs<OasOperationEntry>): boolean;
83
110
  matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
84
111
  transform({ entry, context, variant }: AskArgs<OasOperationEntry>): void;