@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.
- package/esm/context/BuiltOnRead.d.ts +37 -0
- package/esm/context/BuiltOnRead.js +199 -0
- package/esm/context/CoreContext.js +11 -5
- package/esm/context/GenerateContext.d.ts +3 -0
- package/esm/context/GenerateContext.js +48 -5
- package/esm/context/ParseContext.js +116 -11
- package/esm/context/Subject.d.ts +29 -2
- package/esm/context/Subject.js +67 -6
- package/esm/dsl/model/toModelProjectionBase.d.ts +4 -1
- package/esm/oas/document/Document.d.ts +5 -1
- package/esm/oas/document/Document.js +10 -1
- package/esm/oas/document/documentSource.d.ts +37 -0
- package/esm/oas/document/documentSource.js +27 -0
- package/esm/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
- package/esm/parse/v3-0/operation/toOperationsV3.js +68 -67
- package/esm/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
- package/esm/parse/v3-1/operation/toOperationsV3.js +68 -67
- package/esm/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
- package/esm/parse/v3-2/operation/toOperationsV3.js +69 -68
- package/package.json +1 -1
- package/script/context/BuiltOnRead.d.ts +37 -0
- package/script/context/BuiltOnRead.js +203 -0
- package/script/context/CoreContext.js +11 -5
- package/script/context/GenerateContext.d.ts +3 -0
- package/script/context/GenerateContext.js +48 -5
- package/script/context/ParseContext.js +116 -11
- package/script/context/Subject.d.ts +29 -2
- package/script/context/Subject.js +67 -6
- package/script/dsl/model/toModelProjectionBase.d.ts +4 -1
- package/script/oas/document/Document.d.ts +5 -1
- package/script/oas/document/Document.js +10 -1
- package/script/oas/document/documentSource.d.ts +37 -0
- package/script/oas/document/documentSource.js +36 -0
- package/script/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
- package/script/parse/v3-0/operation/toOperationsV3.js +71 -69
- package/script/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
- package/script/parse/v3-1/operation/toOperationsV3.js +71 -69
- package/script/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
- package/script/parse/v3-2/operation/toOperationsV3.js +72 -70
|
@@ -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,199 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
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;
|
|
13
|
+
import { OasOperationSubject } from './Subject.js';
|
|
14
|
+
import { fromModelKey } from '../helpers/refFns.js';
|
|
15
|
+
import { setUnlistedOperations, toDocumentSource } from '../oas/document/documentSource.js';
|
|
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 class BuiltOnRead {
|
|
21
|
+
constructor(schemas) {
|
|
22
|
+
_BuiltOnRead_schemas.set(this, void 0);
|
|
23
|
+
__classPrivateFieldSet(this, _BuiltOnRead_schemas, schemas, "f");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Lets the parsed operations and component schemas of `document` go, or
|
|
27
|
+
* returns `undefined` when its parse context builds nothing again (a run
|
|
28
|
+
* without `onArtifact`). Call it once the file plan is built.
|
|
29
|
+
*/
|
|
30
|
+
static start({ document, subjects, reach }) {
|
|
31
|
+
const source = toDocumentSource(document);
|
|
32
|
+
if (source === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const operations = new OperationsOnRead({ document, source });
|
|
36
|
+
subjects.forEach(subject => {
|
|
37
|
+
if (subject instanceof OasOperationSubject) {
|
|
38
|
+
subject.buildOnRead(operations);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return new BuiltOnRead(new SchemasOnRead({ document, source, subjects, reach }));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `subject`'s step starts. The first read of its operation in the step
|
|
45
|
+
* builds it, and every generator of the step gets that object.
|
|
46
|
+
*/
|
|
47
|
+
start(subject) {
|
|
48
|
+
if (subject instanceof OasOperationSubject) {
|
|
49
|
+
subject.startStep();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** `subject`'s step has run: its operation goes, and each schema no subject left reaches. */
|
|
53
|
+
finish(subject) {
|
|
54
|
+
if (subject instanceof OasOperationSubject) {
|
|
55
|
+
subject.finishStep();
|
|
56
|
+
}
|
|
57
|
+
__classPrivateFieldGet(this, _BuiltOnRead_schemas, "f").finish(subject);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_BuiltOnRead_schemas = new WeakMap();
|
|
61
|
+
/** The key of an operation's place. A method has no space in it. */
|
|
62
|
+
const toPlaceKey = ({ path, method }) => `${method} ${path}`;
|
|
63
|
+
/**
|
|
64
|
+
* The operations of a document, built when a step loads one. Listing
|
|
65
|
+
* `document.operations` builds every one and keeps it for the rest of the
|
|
66
|
+
* run: a subject's operation is then the listed object.
|
|
67
|
+
*/
|
|
68
|
+
class OperationsOnRead {
|
|
69
|
+
constructor({ document, source }) {
|
|
70
|
+
_OperationsOnRead_instances.add(this);
|
|
71
|
+
_OperationsOnRead_source.set(this, void 0);
|
|
72
|
+
/** The place of each operation pass 1 kept, in document order. */
|
|
73
|
+
_OperationsOnRead_places.set(this, void 0);
|
|
74
|
+
/** The operations loaded and not let go yet. */
|
|
75
|
+
_OperationsOnRead_held.set(this, new Map()
|
|
76
|
+
/** Every operation, once they are listed. */
|
|
77
|
+
);
|
|
78
|
+
/** Every operation, once they are listed. */
|
|
79
|
+
_OperationsOnRead_listed.set(this, void 0);
|
|
80
|
+
__classPrivateFieldSet(this, _OperationsOnRead_source, source, "f");
|
|
81
|
+
const operations = document.operations;
|
|
82
|
+
__classPrivateFieldSet(this, _OperationsOnRead_places, operations.map(({ path, method }) => ({ path, method })), "f");
|
|
83
|
+
// The getter gives the document's own array: emptying it lets the parsed operations go.
|
|
84
|
+
operations.splice(0);
|
|
85
|
+
setUnlistedOperations(document, () => __classPrivateFieldGet(this, _OperationsOnRead_instances, "m", _OperationsOnRead_list).call(this));
|
|
86
|
+
}
|
|
87
|
+
load(place) {
|
|
88
|
+
const key = toPlaceKey(place);
|
|
89
|
+
const found = __classPrivateFieldGet(this, _OperationsOnRead_listed, "f")?.get(key) ?? __classPrivateFieldGet(this, _OperationsOnRead_held, "f").get(key);
|
|
90
|
+
if (found !== undefined) {
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
const operation = __classPrivateFieldGet(this, _OperationsOnRead_source, "f").toOperation(place);
|
|
94
|
+
__classPrivateFieldGet(this, _OperationsOnRead_held, "f").set(key, operation);
|
|
95
|
+
return operation;
|
|
96
|
+
}
|
|
97
|
+
letGo(place) {
|
|
98
|
+
__classPrivateFieldGet(this, _OperationsOnRead_held, "f").delete(toPlaceKey(place));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_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() {
|
|
102
|
+
const operations = __classPrivateFieldGet(this, _OperationsOnRead_places, "f").map(place => this.load(place));
|
|
103
|
+
__classPrivateFieldSet(this, _OperationsOnRead_listed, new Map(operations.map(operation => [toPlaceKey(operation), operation])), "f");
|
|
104
|
+
__classPrivateFieldGet(this, _OperationsOnRead_held, "f").clear();
|
|
105
|
+
return operations;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The component schemas of a document, built when read. `components.schemas`
|
|
109
|
+
* keeps its names in their order, and each entry is built when it is read. A
|
|
110
|
+
* built schema is kept while a subject left to run reaches it, and while the
|
|
111
|
+
* step that read it runs. A read after that builds it again.
|
|
112
|
+
*
|
|
113
|
+
* The count is the plan's two-step count: by a model's key, how many
|
|
114
|
+
* subjects left name it; by a schema's name, how many named models with
|
|
115
|
+
* subjects left reach it.
|
|
116
|
+
*/
|
|
117
|
+
class SchemasOnRead {
|
|
118
|
+
constructor({ document, source, subjects, reach }) {
|
|
119
|
+
_SchemasOnRead_instances.add(this);
|
|
120
|
+
_SchemasOnRead_source.set(this, void 0);
|
|
121
|
+
_SchemasOnRead_reach.set(this, void 0);
|
|
122
|
+
/** The names of the schemas, which are their model keys. */
|
|
123
|
+
_SchemasOnRead_names.set(this, void 0);
|
|
124
|
+
_SchemasOnRead_built.set(this, new Map()
|
|
125
|
+
/** The schemas built in this step that no subject left reaches. */
|
|
126
|
+
);
|
|
127
|
+
/** The schemas built in this step that no subject left reaches. */
|
|
128
|
+
_SchemasOnRead_readInStep.set(this, new Set());
|
|
129
|
+
_SchemasOnRead_named.set(this, new Map()
|
|
130
|
+
/** By a model's key: how many subjects that name it are left to run. */
|
|
131
|
+
);
|
|
132
|
+
/** By a model's key: how many subjects that name it are left to run. */
|
|
133
|
+
_SchemasOnRead_namedLeft.set(this, new Map()
|
|
134
|
+
/** By a schema's name: how many named models with subjects left reach it. */
|
|
135
|
+
);
|
|
136
|
+
/** By a schema's name: how many named models with subjects left reach it. */
|
|
137
|
+
_SchemasOnRead_reachedLeft.set(this, new Map());
|
|
138
|
+
__classPrivateFieldSet(this, _SchemasOnRead_source, source, "f");
|
|
139
|
+
__classPrivateFieldSet(this, _SchemasOnRead_reach, reach, "f");
|
|
140
|
+
const record = document.components?.schemas ?? {};
|
|
141
|
+
const names = document.components?.toSchemasRefNames() ?? [];
|
|
142
|
+
__classPrivateFieldSet(this, _SchemasOnRead_names, new Set(names), "f");
|
|
143
|
+
subjects.forEach(subject => {
|
|
144
|
+
const named = subject.toNamedModels(reach);
|
|
145
|
+
named.forEach(key => {
|
|
146
|
+
const namedLeft = __classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").get(key) ?? 0;
|
|
147
|
+
if (namedLeft === 0) {
|
|
148
|
+
__classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_toReached).call(this, key).forEach(name => {
|
|
149
|
+
__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").set(name, (__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) + 1);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
__classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").set(key, namedLeft + 1);
|
|
153
|
+
});
|
|
154
|
+
__classPrivateFieldGet(this, _SchemasOnRead_named, "f").set(subject, named);
|
|
155
|
+
});
|
|
156
|
+
// Each entry becomes a getter at its own position, so the names keep
|
|
157
|
+
// their order, and the parsed schema it held is let go.
|
|
158
|
+
names.forEach(name => {
|
|
159
|
+
Object.defineProperty(record, name, {
|
|
160
|
+
get: () => __classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_read).call(this, name),
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
finish(subject) {
|
|
167
|
+
const named = __classPrivateFieldGet(this, _SchemasOnRead_named, "f").get(subject) ?? [];
|
|
168
|
+
__classPrivateFieldGet(this, _SchemasOnRead_named, "f").delete(subject);
|
|
169
|
+
named.forEach(key => {
|
|
170
|
+
const namedLeft = (__classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").get(key) ?? 0) - 1;
|
|
171
|
+
__classPrivateFieldGet(this, _SchemasOnRead_namedLeft, "f").set(key, namedLeft);
|
|
172
|
+
if (namedLeft === 0) {
|
|
173
|
+
__classPrivateFieldGet(this, _SchemasOnRead_instances, "m", _SchemasOnRead_toReached).call(this, key).forEach(name => {
|
|
174
|
+
const reachedLeft = (__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) - 1;
|
|
175
|
+
__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").set(name, reachedLeft);
|
|
176
|
+
if (reachedLeft === 0) {
|
|
177
|
+
__classPrivateFieldGet(this, _SchemasOnRead_built, "f").delete(name);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
__classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").forEach(name => __classPrivateFieldGet(this, _SchemasOnRead_built, "f").delete(name));
|
|
183
|
+
__classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").clear();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
_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) {
|
|
187
|
+
const found = __classPrivateFieldGet(this, _SchemasOnRead_built, "f").get(name);
|
|
188
|
+
if (found !== undefined) {
|
|
189
|
+
return found;
|
|
190
|
+
}
|
|
191
|
+
const schema = __classPrivateFieldGet(this, _SchemasOnRead_source, "f").toSchema(name);
|
|
192
|
+
__classPrivateFieldGet(this, _SchemasOnRead_built, "f").set(name, schema);
|
|
193
|
+
if ((__classPrivateFieldGet(this, _SchemasOnRead_reachedLeft, "f").get(name) ?? 0) === 0) {
|
|
194
|
+
__classPrivateFieldGet(this, _SchemasOnRead_readInStep, "f").add(name);
|
|
195
|
+
}
|
|
196
|
+
return schema;
|
|
197
|
+
}, _SchemasOnRead_toReached = function _SchemasOnRead_toReached(key) {
|
|
198
|
+
return __classPrivateFieldGet(this, _SchemasOnRead_reach, "f").ofModel(fromModelKey(key)).filter(model => __classPrivateFieldGet(this, _SchemasOnRead_names, "f").has(model));
|
|
199
|
+
};
|
|
@@ -27,6 +27,7 @@ import { bold, gray, red, yellow, blue } from '../deps/jsr.io/@std/fmt/1.0.10/co
|
|
|
27
27
|
import { toSerializedError } from '../types/SerializedError.js';
|
|
28
28
|
import { GenerationFailure } from './toGenerationFailure.js';
|
|
29
29
|
import { toCountPhrase } from '../helpers/toCountPhrase.js';
|
|
30
|
+
import { markPlannedParse } from '../oas/document/documentSource.js';
|
|
30
31
|
/**
|
|
31
32
|
* The main orchestration class for the SKMTC transformation pipeline.
|
|
32
33
|
*
|
|
@@ -308,7 +309,12 @@ export class CoreContext {
|
|
|
308
309
|
__classPrivateFieldSet(this, _CoreContext_phaseName, 'parse', "f");
|
|
309
310
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, [], "f");
|
|
310
311
|
__classPrivateFieldSet(this, _CoreContext_enrichmentWarnings, [], "f");
|
|
311
|
-
|
|
312
|
+
// A capturing render and an inspection read every file at the end
|
|
313
|
+
// of the run, so such a run gives no file before then. A run that
|
|
314
|
+
// gives files early can build its operations and schemas again when
|
|
315
|
+
// a generator reads them, so the parse context knows it first.
|
|
316
|
+
const givesFilesEarly = onArtifact !== undefined && !attribution?.postPass && !inspect;
|
|
317
|
+
const phase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, document, settings, givesFilesEarly);
|
|
312
318
|
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
313
319
|
__classPrivateFieldSet(this, _CoreContext_parseIssues, phase.context.issues, "f");
|
|
314
320
|
const parsedDocument = stackTrail.trace('parse', st => phase.context.parse(st));
|
|
@@ -334,9 +340,6 @@ export class CoreContext {
|
|
|
334
340
|
captureChannel
|
|
335
341
|
});
|
|
336
342
|
__classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
|
|
337
|
-
// A capturing render and an inspection read every file at the end
|
|
338
|
-
// of the run, so such a run gives no file before then.
|
|
339
|
-
const givesFilesEarly = onArtifact !== undefined && !attribution?.postPass && !inspect;
|
|
340
343
|
const generated = generatePhase.context.toArtifacts(st, givesFilesEarly
|
|
341
344
|
? {
|
|
342
345
|
reach: phase.context.toReach(),
|
|
@@ -639,7 +642,7 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
|
|
|
639
642
|
throw new Error(`Unhandled protocol type: ${JSON.stringify(_exhaustive)}`);
|
|
640
643
|
}
|
|
641
644
|
}
|
|
642
|
-
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input, settings) {
|
|
645
|
+
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(input, settings, planned = false) {
|
|
643
646
|
if (settings?.parse && settings.system) {
|
|
644
647
|
this.logger.warn('settings.parse and settings.system are both set: settings.parse is used and settings.system is ignored. ' +
|
|
645
648
|
'settings.system is the deprecated name of settings.parse; remove it.');
|
|
@@ -650,6 +653,9 @@ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreC
|
|
|
650
653
|
silent: this.silent,
|
|
651
654
|
system: settings?.parse ?? settings?.system
|
|
652
655
|
});
|
|
656
|
+
if (planned) {
|
|
657
|
+
markPlannedParse(parseContext);
|
|
658
|
+
}
|
|
653
659
|
return { type: 'parse', context: parseContext };
|
|
654
660
|
}, _CoreContext_setupGeneratePhase = function _CoreContext_setupGeneratePhase({ document, settings, toGeneratorConfigMap, captureChannel }) {
|
|
655
661
|
const generateContext = new 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
|
/**
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_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;
|
|
12
|
+
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;
|
|
13
13
|
import { applyGeneratedSuffixToWorkspacePath, normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
14
14
|
import { getByWorkspacePath } from '../helpers/getByWorkspacePath.js';
|
|
15
15
|
import { DEFAULT_GENERATED_SUFFIX } from '../helpers/applyGeneratedSuffix.js';
|
|
@@ -27,6 +27,7 @@ import { DEFAULT_VARIANT } from '../types/Variant.js';
|
|
|
27
27
|
import { toVariantList } from '../helpers/toVariantList.js';
|
|
28
28
|
import { GqlOperationSubject, ModelSubject, OasOperationSubject, WebhookSubject } from './Subject.js';
|
|
29
29
|
import { FilePlan } from './FilePlan.js';
|
|
30
|
+
import { BuiltOnRead } from './BuiltOnRead.js';
|
|
30
31
|
export { toGqlOperationSource, toModelSource, toOasOperationSource, toWebhookSource } from './Subject.js';
|
|
31
32
|
import { getPath } from '../helpers/getPath.js';
|
|
32
33
|
import { Inserted } from '../dsl/Inserted.js';
|
|
@@ -203,6 +204,21 @@ export class GenerateContext {
|
|
|
203
204
|
/** The counts of the generator {@link toArtifacts} is running. */
|
|
204
205
|
_GenerateContext_subjectCounts.set(this, { offered: 0, transformed: 0, failed: 0 });
|
|
205
206
|
_GenerateContext_ejectedBySuffixedPathCache.set(this, void 0);
|
|
207
|
+
/** By a model projection class: the name and the export path of each model and variant it was asked for. */
|
|
208
|
+
_GenerateContext_modelIdentities.set(this, new Map()
|
|
209
|
+
/**
|
|
210
|
+
* Look up an already-registered file by path, or `undefined` if none
|
|
211
|
+
* exists. In a run with `onArtifact`, a lookup of a file that was given
|
|
212
|
+
* to the host throws. Neutral primitive: returns the abstract `FileBase` and never
|
|
213
|
+
* constructs anything, so a (future) language-owned `register` can ask
|
|
214
|
+
* "does this file exist yet?" without the engine knowing the language.
|
|
215
|
+
* To create on a miss, add a file your language constructs with
|
|
216
|
+
* {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
|
|
217
|
+
*
|
|
218
|
+
* `filePath` may be in any spelling. It is normalized only when it is no
|
|
219
|
+
* key: a key is a normalized path. The file's own `path` is the key.
|
|
220
|
+
*/
|
|
221
|
+
);
|
|
206
222
|
this.logger = logger;
|
|
207
223
|
__classPrivateFieldSet(this, _GenerateContext_logsGeneratorLines, logsGeneratorLines, "f");
|
|
208
224
|
__classPrivateFieldSet(this, _GenerateContext_files, new Map(), "f");
|
|
@@ -873,17 +889,38 @@ export class GenerateContext {
|
|
|
873
889
|
* `toEnrichments` against the given `ref` and `variant`. The full
|
|
874
890
|
* identifier is assembled through the projection's language
|
|
875
891
|
* (`lang.toIdentifier`).
|
|
892
|
+
*
|
|
893
|
+
* With no projection options, `toIdentifierName` and `toExportPath` are
|
|
894
|
+
* asked once in a run for each projection, ref and variant.
|
|
876
895
|
*/
|
|
877
896
|
toModelContentSettings(args) {
|
|
878
897
|
const { ref, projection, variant = DEFAULT_VARIANT } = args;
|
|
879
898
|
const options = readProjectionOptions(args);
|
|
880
899
|
const enrichments = projection.toEnrichments({ ref, context: this, variant });
|
|
900
|
+
// A model is referred to many times in a run, and its name and its
|
|
901
|
+
// export path are the same each time: they come from the ref, the
|
|
902
|
+
// enrichments and the variant. With options they can differ, so only a
|
|
903
|
+
// call with no options is kept.
|
|
904
|
+
// Each part of the key can hold any character: the lengths keep them apart.
|
|
905
|
+
const key = options === undefined
|
|
906
|
+
? `${ref.refPath.length}:${ref.refName.length}:${ref.refPath}${ref.refName}${variant}`
|
|
907
|
+
: undefined;
|
|
908
|
+
const kept = key === undefined ? undefined : __classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").get(projection)?.get(key);
|
|
909
|
+
const identity = kept ?? {
|
|
910
|
+
name: projection.toIdentifierName({ ref, enrichments, variant, options }),
|
|
911
|
+
exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({ ref, enrichments, variant, options }), projection.id)
|
|
912
|
+
};
|
|
913
|
+
if (key !== undefined && kept === undefined) {
|
|
914
|
+
const byKey = __classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").get(projection) ?? new Map();
|
|
915
|
+
byKey.set(key, identity);
|
|
916
|
+
__classPrivateFieldGet(this, _GenerateContext_modelIdentities, "f").set(projection, byKey);
|
|
917
|
+
}
|
|
881
918
|
return new ContentSettings({
|
|
882
919
|
identifier: projection.lang.toIdentifier({
|
|
883
|
-
name:
|
|
920
|
+
name: identity.name,
|
|
884
921
|
...projection.toIdentifierType(ref, this)
|
|
885
922
|
}),
|
|
886
|
-
exportPath:
|
|
923
|
+
exportPath: identity.exportPath,
|
|
887
924
|
enrichments,
|
|
888
925
|
variant
|
|
889
926
|
});
|
|
@@ -953,7 +990,7 @@ export class GenerateContext {
|
|
|
953
990
|
return place?.findDefinitions({ name })?.[0];
|
|
954
991
|
}
|
|
955
992
|
}
|
|
956
|
-
_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) {
|
|
993
|
+
_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) {
|
|
957
994
|
if (!hasVariantEnrichment(block, variant))
|
|
958
995
|
return;
|
|
959
996
|
__classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").report({
|
|
@@ -1025,11 +1062,17 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1025
1062
|
...(readyAfter.get(0) ?? []),
|
|
1026
1063
|
...modelSteps.flatMap((step, index) => [step, ...(readyAfter.get(index + 1) ?? [])])
|
|
1027
1064
|
];
|
|
1028
|
-
const
|
|
1065
|
+
const subjects = steps.map(({ subject }) => subject);
|
|
1066
|
+
const plan = this.toFilePlan({ subjects, reach });
|
|
1067
|
+
// The plan asked the pass 1 operations. From here each step builds its
|
|
1068
|
+
// operation again, and each schema is built when it is read.
|
|
1069
|
+
const builtOnRead = BuiltOnRead.start({ document: oasDocument, subjects, reach });
|
|
1029
1070
|
steps.forEach(step => {
|
|
1071
|
+
builtOnRead?.start(step.subject);
|
|
1030
1072
|
step.run();
|
|
1031
1073
|
// A run that has failed gives no more files: it will write nothing.
|
|
1032
1074
|
const complete = plan.finish(step.subject);
|
|
1075
|
+
builtOnRead?.finish(step.subject);
|
|
1033
1076
|
if (__classPrivateFieldGet(this, _GenerateContext_failedItems, "f").length === 0) {
|
|
1034
1077
|
complete.forEach(path => __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_release).call(this, path, onFile));
|
|
1035
1078
|
}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
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;
|
|
12
|
+
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;
|
|
13
13
|
/**
|
|
14
14
|
* Unified parse context for both OAS and GraphQL inputs.
|
|
15
15
|
*
|
|
@@ -51,6 +51,21 @@ import { toRefKey } from '../parse/toRefKey.js';
|
|
|
51
51
|
import { toRefTargetV3 } from '../parse/v3-0/ref/toRefTargetV3.js';
|
|
52
52
|
import { toRefTargetV3 as toRefTargetV31 } from '../parse/v3-1/ref/toRefTargetV3.js';
|
|
53
53
|
import { toRefTargetV3 as toRefTargetV32 } from '../parse/v3-2/ref/toRefTargetV3.js';
|
|
54
|
+
import { toPathOperationsV3 } from '../parse/v3-0/operation/toOperationsV3.js';
|
|
55
|
+
import { toPathOperationsV3 as toPathOperationsV31 } from '../parse/v3-1/operation/toOperationsV3.js';
|
|
56
|
+
import { toPathOperationsV3 as toPathOperationsV32 } from '../parse/v3-2/operation/toOperationsV3.js';
|
|
57
|
+
import { toSchemaV3 } from '../parse/v3-0/schema/toSchemasV3.js';
|
|
58
|
+
import { toSchemaV3 as toSchemaV31 } from '../parse/v3-1/schema/toSchemasV3.js';
|
|
59
|
+
import { toSchemaV3 as toSchemaV32 } from '../parse/v3-2/schema/toSchemasV3.js';
|
|
60
|
+
import { isPlannedParse, setDocumentSource } from '../oas/document/documentSource.js';
|
|
61
|
+
/** Takes a removed path-level parameter out of `pathItem`, which its operations share. */
|
|
62
|
+
const removePathParameter = (pathItem, { entryRef, name, in: location }) => {
|
|
63
|
+
if (pathItem?.parameters) {
|
|
64
|
+
pathItem.parameters = pathItem.parameters.filter(parameter => parameter.isRef()
|
|
65
|
+
? parameter.$ref !== entryRef
|
|
66
|
+
: entryRef !== undefined || parameter.name !== name || parameter.location !== location);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
54
69
|
/** The issue logged when a ref target's parser throws. */
|
|
55
70
|
const toInvalidType = (refType) => {
|
|
56
71
|
switch (refType) {
|
|
@@ -177,7 +192,17 @@ export class ParseContext {
|
|
|
177
192
|
* 'parse']` through `toArtifacts`). Every trail built during the walk
|
|
178
193
|
* starts with them; `#toDocumentTrail` strips them.
|
|
179
194
|
*/
|
|
180
|
-
_ParseContext_rootFrames.set(this, []
|
|
195
|
+
_ParseContext_rootFrames.set(this, []
|
|
196
|
+
/** The dialect `parse()` picked for an OpenAPI document. */
|
|
197
|
+
);
|
|
198
|
+
/** The dialect `parse()` picked for an OpenAPI document. */
|
|
199
|
+
_ParseContext_dialect.set(this, void 0);
|
|
200
|
+
/** While a part of the document is built again, nothing is recorded: no issue, no ref and no ref error. */
|
|
201
|
+
_ParseContext_rebuilding.set(this, false
|
|
202
|
+
/** By path: the path-level parameters `#removePathParameterConsumer` took out of the path item. */
|
|
203
|
+
);
|
|
204
|
+
/** By path: the path-level parameters `#removePathParameterConsumer` took out of the path item. */
|
|
205
|
+
_ParseContext_removedPathParameters.set(this, new Map());
|
|
181
206
|
this.logger = logger;
|
|
182
207
|
this.silent = silent;
|
|
183
208
|
this.system = system ?? {};
|
|
@@ -295,6 +320,7 @@ export class ParseContext {
|
|
|
295
320
|
// parser tree. Everything downstream is version-specific code living
|
|
296
321
|
// in its own tree (v3-0 / v3-1 / v3-2) and never re-checks the version.
|
|
297
322
|
const dialect = toOasDialect(oasState.documentObject.openapi);
|
|
323
|
+
__classPrivateFieldSet(this, _ParseContext_dialect, dialect, "f");
|
|
298
324
|
switch (dialect) {
|
|
299
325
|
case '3.0':
|
|
300
326
|
oasState.oasDocument.fields = toDocumentFieldsV3({
|
|
@@ -327,6 +353,14 @@ export class ParseContext {
|
|
|
327
353
|
}
|
|
328
354
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_checkRefs).call(this);
|
|
329
355
|
this.removeErroredItems();
|
|
356
|
+
// A run that gives files early builds its operations and component
|
|
357
|
+
// schemas again when a generator reads them (`BuiltOnRead`).
|
|
358
|
+
if (isPlannedParse(this)) {
|
|
359
|
+
setDocumentSource(oasState.oasDocument, {
|
|
360
|
+
toOperation: place => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_rebuildOperation).call(this, place),
|
|
361
|
+
toSchema: name => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_rebuildSchema).call(this, name)
|
|
362
|
+
});
|
|
363
|
+
}
|
|
330
364
|
return { type: 'oas', value: oasState.oasDocument };
|
|
331
365
|
}
|
|
332
366
|
case 'gql': {
|
|
@@ -438,6 +472,9 @@ export class ParseContext {
|
|
|
438
472
|
* would use type names or qualified field paths.
|
|
439
473
|
*/
|
|
440
474
|
registerRef(consumer, refKey) {
|
|
475
|
+
if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
441
478
|
const refConsumer = { consumer, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") };
|
|
442
479
|
const existing = __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey);
|
|
443
480
|
if (existing) {
|
|
@@ -454,6 +491,9 @@ export class ParseContext {
|
|
|
454
491
|
* resolve it there.
|
|
455
492
|
*/
|
|
456
493
|
registerOasRef(consumer, ref) {
|
|
494
|
+
if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
457
497
|
this.registerRef(consumer, toRefKey(ref));
|
|
458
498
|
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") });
|
|
459
499
|
}
|
|
@@ -490,7 +530,7 @@ export class ParseContext {
|
|
|
490
530
|
* each `INVALID_DEPENDENCY_REF` it causes names it.
|
|
491
531
|
*/
|
|
492
532
|
registerRefError(error, refKey, location) {
|
|
493
|
-
if (!refKey)
|
|
533
|
+
if (!refKey || __classPrivateFieldGet(this, _ParseContext_rebuilding, "f"))
|
|
494
534
|
return;
|
|
495
535
|
const refError = { error, location };
|
|
496
536
|
const existing = __classPrivateFieldGet(this, _ParseContext_refErrors, "f").get(refKey);
|
|
@@ -518,6 +558,10 @@ export class ParseContext {
|
|
|
518
558
|
* manifest).
|
|
519
559
|
*/
|
|
520
560
|
logIssueAt(issue, parent) {
|
|
561
|
+
// A rebuild logs nothing: pass 1 logged each issue once. Every issue is kept through here.
|
|
562
|
+
if (__classPrivateFieldGet(this, _ParseContext_rebuilding, "f")) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
521
565
|
const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
|
|
522
566
|
if (added && !this.silent) {
|
|
523
567
|
const message = `${issue.type} at ${__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentLocation).call(this, issue)}: ${issue.message}`;
|
|
@@ -651,7 +695,69 @@ export class ParseContext {
|
|
|
651
695
|
});
|
|
652
696
|
}
|
|
653
697
|
}
|
|
654
|
-
_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(),
|
|
698
|
+
_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 }) {
|
|
699
|
+
const pathItem = this.documentObject.paths?.[path];
|
|
700
|
+
if (!isPlainObject(pathItem)) {
|
|
701
|
+
throw new Error(`Cannot build the operation '${method.toUpperCase()} ${path}' again: the document has no such path`);
|
|
702
|
+
}
|
|
703
|
+
const args = {
|
|
704
|
+
path,
|
|
705
|
+
pathItem,
|
|
706
|
+
method,
|
|
707
|
+
stackTrail: new StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), 'paths', path]),
|
|
708
|
+
context: this
|
|
709
|
+
};
|
|
710
|
+
const [operation] = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_whileRebuilding).call(this, () => {
|
|
711
|
+
switch (__classPrivateFieldGet(this, _ParseContext_dialect, "f")) {
|
|
712
|
+
case '3.0':
|
|
713
|
+
return toPathOperationsV3(args);
|
|
714
|
+
case '3.1':
|
|
715
|
+
return toPathOperationsV31(args);
|
|
716
|
+
case '3.2':
|
|
717
|
+
return toPathOperationsV32(args);
|
|
718
|
+
default:
|
|
719
|
+
throw new Error('Cannot build an operation again before the document is parsed');
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
if (operation === undefined) {
|
|
723
|
+
throw new Error(`Cannot build the operation '${method.toUpperCase()} ${path}' again: it does not parse`);
|
|
724
|
+
}
|
|
725
|
+
__classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f")
|
|
726
|
+
.get(path)
|
|
727
|
+
?.forEach(removed => removePathParameter(operation.pathItem, removed));
|
|
728
|
+
return operation;
|
|
729
|
+
}, _ParseContext_rebuildSchema = function _ParseContext_rebuildSchema(name) {
|
|
730
|
+
const schema = this.documentObject.components?.schemas?.[name];
|
|
731
|
+
if (schema === undefined) {
|
|
732
|
+
throw new Error(`Cannot build the schema '${name}' again: the document has no such schema`);
|
|
733
|
+
}
|
|
734
|
+
const args = {
|
|
735
|
+
schema,
|
|
736
|
+
stackTrail: new StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), 'components', 'schemas', name]),
|
|
737
|
+
context: this
|
|
738
|
+
};
|
|
739
|
+
return __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_whileRebuilding).call(this, () => {
|
|
740
|
+
switch (__classPrivateFieldGet(this, _ParseContext_dialect, "f")) {
|
|
741
|
+
case '3.0':
|
|
742
|
+
return toSchemaV3(args);
|
|
743
|
+
case '3.1':
|
|
744
|
+
return toSchemaV31(args);
|
|
745
|
+
case '3.2':
|
|
746
|
+
return toSchemaV32(args);
|
|
747
|
+
default:
|
|
748
|
+
throw new Error('Cannot build a schema again before the document is parsed');
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}, _ParseContext_whileRebuilding = function _ParseContext_whileRebuilding(fn) {
|
|
752
|
+
const previous = __classPrivateFieldGet(this, _ParseContext_rebuilding, "f");
|
|
753
|
+
__classPrivateFieldSet(this, _ParseContext_rebuilding, true, "f");
|
|
754
|
+
try {
|
|
755
|
+
return fn();
|
|
756
|
+
}
|
|
757
|
+
finally {
|
|
758
|
+
__classPrivateFieldSet(this, _ParseContext_rebuilding, previous, "f");
|
|
759
|
+
}
|
|
760
|
+
}, _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
|
|
655
761
|
if (this.protocol.type !== 'oas') {
|
|
656
762
|
return;
|
|
657
763
|
}
|
|
@@ -760,19 +866,18 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
760
866
|
? rawEntry
|
|
761
867
|
: toRawRefTarget(documentObject, toRefParts({ $ref: entryRef })));
|
|
762
868
|
const broken = [{ location: documentTrail.toString(), message: '', ...nameAndIn }];
|
|
869
|
+
const removed = { entryRef, ...nameAndIn };
|
|
870
|
+
// An operation built again later gets a path item of its own, which loses the entry the same way.
|
|
871
|
+
if (first === 'paths') {
|
|
872
|
+
__classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f").set(second, [...(__classPrivateFieldGet(this, _ParseContext_removedPathParameters, "f").get(second) ?? []), removed]);
|
|
873
|
+
}
|
|
763
874
|
const operations = first === 'paths'
|
|
764
875
|
? oasDocument.operations.filter(({ path }) => path === second)
|
|
765
876
|
: oasDocument.webhooks.filter(({ name }) => name === second);
|
|
766
877
|
const removedLocations = operations.flatMap(({ method, pathItem }) => {
|
|
767
878
|
const rawOperation = isPlainObject(rawPathItem) ? rawPathItem[method] : undefined;
|
|
768
879
|
if (toApplyingBrokenParameter({ broken, operation: rawOperation }) === undefined) {
|
|
769
|
-
|
|
770
|
-
pathItem.parameters = pathItem.parameters.filter(parameter => parameter.isRef()
|
|
771
|
-
? parameter.$ref !== entryRef
|
|
772
|
-
: entryRef !== undefined ||
|
|
773
|
-
parameter.name !== nameAndIn.name ||
|
|
774
|
-
parameter.location !== nameAndIn.in);
|
|
775
|
-
}
|
|
880
|
+
removePathParameter(pathItem, removed);
|
|
776
881
|
return [];
|
|
777
882
|
}
|
|
778
883
|
return oasDocument.removeItem(new StackTrail([first, second, method])) === undefined
|