@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
|
@@ -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(),
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
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;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
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 _OasOperationSubject_operation, _OasOperationSubject_loader, _OasOperationSubject_inStep;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource = exports.toOasOperationSource = exports.ModelSubject = exports.GqlOperationSubject = exports.WebhookSubject = exports.OasOperationSubject = void 0;
|
|
4
16
|
const refFns_js_1 = require("../helpers/refFns.js");
|
|
5
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`.
|
|
19
|
+
*
|
|
20
|
+
* It holds the operation it is constructed with. In a run that builds
|
|
21
|
+
* operations on read, it lets that one go once the file plan is built. In
|
|
22
|
+
* its step, the first read builds its operation through the document, and
|
|
23
|
+
* it lets the operation go when the step has run.
|
|
24
|
+
*/
|
|
6
25
|
class OasOperationSubject {
|
|
7
26
|
constructor(operation) {
|
|
8
27
|
Object.defineProperty(this, "type", {
|
|
@@ -11,7 +30,13 @@ class OasOperationSubject {
|
|
|
11
30
|
writable: true,
|
|
12
31
|
value: 'oasOperation'
|
|
13
32
|
});
|
|
14
|
-
Object.defineProperty(this, "
|
|
33
|
+
Object.defineProperty(this, "path", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "method", {
|
|
15
40
|
enumerable: true,
|
|
16
41
|
configurable: true,
|
|
17
42
|
writable: true,
|
|
@@ -35,18 +60,53 @@ class OasOperationSubject {
|
|
|
35
60
|
writable: true,
|
|
36
61
|
value: void 0
|
|
37
62
|
});
|
|
38
|
-
this
|
|
63
|
+
_OasOperationSubject_operation.set(this, void 0);
|
|
64
|
+
_OasOperationSubject_loader.set(this, void 0);
|
|
65
|
+
/** Whether its step runs now. */
|
|
66
|
+
_OasOperationSubject_inStep.set(this, false);
|
|
67
|
+
__classPrivateFieldSet(this, _OasOperationSubject_operation, operation, "f");
|
|
68
|
+
this.path = operation.path;
|
|
69
|
+
this.method = operation.method;
|
|
39
70
|
this.trail = [operation.path, operation.method];
|
|
40
71
|
this.enrichmentPath = this.trail;
|
|
41
72
|
this.label = `${operation.method.toUpperCase()} ${operation.path}`;
|
|
42
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Its operation. In a run that builds operations on read, only while its
|
|
76
|
+
* step runs: the first read in the step builds it.
|
|
77
|
+
*/
|
|
78
|
+
get operation() {
|
|
79
|
+
if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined && __classPrivateFieldGet(this, _OasOperationSubject_inStep, "f") && __classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
|
|
80
|
+
__classPrivateFieldSet(this, _OasOperationSubject_operation, __classPrivateFieldGet(this, _OasOperationSubject_loader, "f").load(this), "f");
|
|
81
|
+
}
|
|
82
|
+
if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined) {
|
|
83
|
+
throw new Error(`The operation of ${this.label} is read outside its step, after it was let go`);
|
|
84
|
+
}
|
|
85
|
+
return __classPrivateFieldGet(this, _OasOperationSubject_operation, "f");
|
|
86
|
+
}
|
|
87
|
+
/** Lets go of the operation it was constructed with: from now on, `loader` gives it. */
|
|
88
|
+
buildOnRead(loader) {
|
|
89
|
+
__classPrivateFieldSet(this, _OasOperationSubject_loader, loader, "f");
|
|
90
|
+
__classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
|
|
91
|
+
}
|
|
92
|
+
/** Its step starts. A step that never reads its operation, such as one with no generator, builds none. */
|
|
93
|
+
startStep() {
|
|
94
|
+
__classPrivateFieldSet(this, _OasOperationSubject_inStep, true, "f");
|
|
95
|
+
}
|
|
96
|
+
/** Its step has run: it lets go of the operation the step built. */
|
|
97
|
+
finishStep() {
|
|
98
|
+
__classPrivateFieldSet(this, _OasOperationSubject_inStep, false, "f");
|
|
99
|
+
if (__classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
|
|
100
|
+
__classPrivateFieldGet(this, _OasOperationSubject_loader, "f").letGo(this);
|
|
101
|
+
__classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
43
104
|
isSupported({ entry, context, variant }) {
|
|
44
105
|
return (typeof entry.isSupported !== 'function' ||
|
|
45
106
|
entry.isSupported({ operation: this.operation, context, variant }));
|
|
46
107
|
}
|
|
47
108
|
matches(filter, variant) {
|
|
48
|
-
|
|
49
|
-
return matchesPathFilter({ paths: filter, path, method, variant });
|
|
109
|
+
return matchesPathFilter({ paths: filter, path: this.path, method: this.method, variant });
|
|
50
110
|
}
|
|
51
111
|
transform({ entry, context, variant }) {
|
|
52
112
|
entry.transform({ context, operation: this.operation, variant });
|
|
@@ -62,13 +122,14 @@ class OasOperationSubject {
|
|
|
62
122
|
return projection.toExportPath({ operation: this.operation, enrichments, variant });
|
|
63
123
|
}
|
|
64
124
|
toNamedModels(reach) {
|
|
65
|
-
return reach.namedByOperation(this
|
|
125
|
+
return reach.namedByOperation(this);
|
|
66
126
|
}
|
|
67
127
|
toSource({ generatorId, variant }) {
|
|
68
128
|
return (0, exports.toOasOperationSource)({ operation: this.operation, generatorId, variant });
|
|
69
129
|
}
|
|
70
130
|
}
|
|
71
131
|
exports.OasOperationSubject = OasOperationSubject;
|
|
132
|
+
_OasOperationSubject_operation = new WeakMap(), _OasOperationSubject_loader = new WeakMap(), _OasOperationSubject_inStep = new WeakMap();
|
|
72
133
|
/**
|
|
73
134
|
* A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
|
|
74
135
|
* and its enrichments at `[name][method]`. A filter has the shape of an
|
|
@@ -44,7 +44,10 @@ type ToEnrichmentsArgs = {
|
|
|
44
44
|
*/
|
|
45
45
|
export type ModelProjectionBaseConfig<EnrichmentType = undefined, IdType extends IdentifierType = IdentifierType, ProjectionOptions = undefined> = {
|
|
46
46
|
id: string;
|
|
47
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Pure: the cache-key name. With no projection options,
|
|
49
|
+
* `toModelContentSettings` asks for it once in a run and keeps it.
|
|
50
|
+
*/
|
|
48
51
|
toIdentifierName: (args: ToModelIdentifierNameArgs<EnrichmentType, ProjectionOptions>) => string;
|
|
49
52
|
/**
|
|
50
53
|
* Context-aware, overridable: the non-`name` parts of the identifier
|
|
@@ -231,7 +231,11 @@ export declare class OasDocument {
|
|
|
231
231
|
/** API metadata */
|
|
232
232
|
get info(): OasInfo;
|
|
233
233
|
get servers(): OasServer[] | undefined;
|
|
234
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* List of all operations for the API. In a run with `onArtifact` the parsed
|
|
236
|
+
* operations are let go once the file plan is built; the first time they
|
|
237
|
+
* are listed after that, each is built again and kept.
|
|
238
|
+
*/
|
|
235
239
|
get operations(): OasOperation[];
|
|
236
240
|
/** List of all 3.1 webhooks for the API (kept separate from operations) */
|
|
237
241
|
get webhooks(): OasWebhook[];
|
|
@@ -14,6 +14,7 @@ var _OasDocument_fields, _OasDocument_refTargets;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.OasDocument = void 0;
|
|
16
16
|
require("../../_dnt.polyfills.js");
|
|
17
|
+
const documentSource_js_1 = require("./documentSource.js");
|
|
17
18
|
/**
|
|
18
19
|
* Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
|
|
19
20
|
*
|
|
@@ -292,11 +293,19 @@ class OasDocument {
|
|
|
292
293
|
}
|
|
293
294
|
return __classPrivateFieldGet(this, _OasDocument_fields, "f").servers;
|
|
294
295
|
}
|
|
295
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* List of all operations for the API. In a run with `onArtifact` the parsed
|
|
298
|
+
* operations are let go once the file plan is built; the first time they
|
|
299
|
+
* are listed after that, each is built again and kept.
|
|
300
|
+
*/
|
|
296
301
|
get operations() {
|
|
297
302
|
if (!__classPrivateFieldGet(this, _OasDocument_fields, "f")) {
|
|
298
303
|
throw new Error(`Accessing 'operations' before fields are set`);
|
|
299
304
|
}
|
|
305
|
+
const list = (0, documentSource_js_1.takeUnlistedOperations)(this);
|
|
306
|
+
if (list !== undefined) {
|
|
307
|
+
__classPrivateFieldGet(this, _OasDocument_fields, "f").operations = list();
|
|
308
|
+
}
|
|
300
309
|
return __classPrivateFieldGet(this, _OasDocument_fields, "f").operations;
|
|
301
310
|
}
|
|
302
311
|
/** List of all 3.1 webhooks for the API (kept separate from operations) */
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A document whose operations and component schemas are built again when a
|
|
3
|
+
* generator reads them, in a run with `onArtifact`. Internal: `mod.ts` does
|
|
4
|
+
* not list this file.
|
|
5
|
+
*/
|
|
6
|
+
import type { OasDocument } from './Document.js';
|
|
7
|
+
import type { OasOperation } from '../operation/Operation.js';
|
|
8
|
+
import type { OasSchema } from '../schema/Schema.js';
|
|
9
|
+
import type { OasRef } from '../ref/Ref.js';
|
|
10
|
+
import type { Method } from '../../types/Method.js';
|
|
11
|
+
import type { RefName } from '../../types/RefName.js';
|
|
12
|
+
/** Where an operation is in a document. An `OasOperation` fits it. */
|
|
13
|
+
export type OperationPlace = {
|
|
14
|
+
path: string;
|
|
15
|
+
method: Method;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* How the parse context that parsed a document builds one of its operations
|
|
19
|
+
* or component schemas again from the input document. A rebuild records no
|
|
20
|
+
* issue and no ref.
|
|
21
|
+
*/
|
|
22
|
+
export type DocumentSource = {
|
|
23
|
+
toOperation(place: OperationPlace): OasOperation;
|
|
24
|
+
toSchema(name: RefName): OasSchema | OasRef<'schema'>;
|
|
25
|
+
};
|
|
26
|
+
/** Marks a parse context, before it parses, as one of a run that gives files early. */
|
|
27
|
+
export declare const markPlannedParse: (parseContext: object) => void;
|
|
28
|
+
/** Whether `markPlannedParse` marked the parse context. */
|
|
29
|
+
export declare const isPlannedParse: (parseContext: object) => boolean;
|
|
30
|
+
/** Keeps how the parse context builds the parts of `document` again. */
|
|
31
|
+
export declare const setDocumentSource: (document: OasDocument, source: DocumentSource) => void;
|
|
32
|
+
/** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
|
|
33
|
+
export declare const toDocumentSource: (document: OasDocument) => DocumentSource | undefined;
|
|
34
|
+
/** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
|
|
35
|
+
export declare const setUnlistedOperations: (document: OasDocument, list: () => OasOperation[]) => void;
|
|
36
|
+
/** How to list the operations of `document` that were let go, once: after that they are listed. */
|
|
37
|
+
export declare const takeUnlistedOperations: (document: OasDocument) => (() => OasOperation[]) | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.takeUnlistedOperations = exports.setUnlistedOperations = exports.toDocumentSource = exports.setDocumentSource = exports.isPlannedParse = exports.markPlannedParse = void 0;
|
|
4
|
+
const sources = new WeakMap();
|
|
5
|
+
/** The parse contexts of runs that give files early, whose documents are built on read. */
|
|
6
|
+
const plannedParses = new WeakSet();
|
|
7
|
+
/** Marks a parse context, before it parses, as one of a run that gives files early. */
|
|
8
|
+
const markPlannedParse = (parseContext) => {
|
|
9
|
+
plannedParses.add(parseContext);
|
|
10
|
+
};
|
|
11
|
+
exports.markPlannedParse = markPlannedParse;
|
|
12
|
+
/** Whether `markPlannedParse` marked the parse context. */
|
|
13
|
+
const isPlannedParse = (parseContext) => plannedParses.has(parseContext);
|
|
14
|
+
exports.isPlannedParse = isPlannedParse;
|
|
15
|
+
/** Each document whose parsed operations were let go, and how to list them all again. */
|
|
16
|
+
const unlistedOperations = new WeakMap();
|
|
17
|
+
/** Keeps how the parse context builds the parts of `document` again. */
|
|
18
|
+
const setDocumentSource = (document, source) => {
|
|
19
|
+
sources.set(document, source);
|
|
20
|
+
};
|
|
21
|
+
exports.setDocumentSource = setDocumentSource;
|
|
22
|
+
/** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
|
|
23
|
+
const toDocumentSource = (document) => sources.get(document);
|
|
24
|
+
exports.toDocumentSource = toDocumentSource;
|
|
25
|
+
/** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
|
|
26
|
+
const setUnlistedOperations = (document, list) => {
|
|
27
|
+
unlistedOperations.set(document, list);
|
|
28
|
+
};
|
|
29
|
+
exports.setUnlistedOperations = setUnlistedOperations;
|
|
30
|
+
/** How to list the operations of `document` that were let go, once: after that they are listed. */
|
|
31
|
+
const takeUnlistedOperations = (document) => {
|
|
32
|
+
const list = unlistedOperations.get(document);
|
|
33
|
+
unlistedOperations.delete(document);
|
|
34
|
+
return list;
|
|
35
|
+
};
|
|
36
|
+
exports.takeUnlistedOperations = takeUnlistedOperations;
|
|
@@ -22,4 +22,18 @@ export type ToOperationsV3Args = {
|
|
|
22
22
|
context: ParseContextType;
|
|
23
23
|
};
|
|
24
24
|
export declare const toOperationsV3: ({ paths, stackTrail, context }: ToOperationsV3Args) => OasOperation[];
|
|
25
|
+
export type ToPathOperationsV3Args = {
|
|
26
|
+
path: string;
|
|
27
|
+
pathItem: OpenAPIV3.PathItemObject;
|
|
28
|
+
/** The trail of the path item, with `path` already pushed. */
|
|
29
|
+
stackTrail: StackTrail;
|
|
30
|
+
context: ParseContextType;
|
|
31
|
+
/** Parses only the operation at this method. */
|
|
32
|
+
method?: Method;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The operations of the path item at `path`. They share one parsed path
|
|
36
|
+
* item. With `method`, only the operation at that method is parsed.
|
|
37
|
+
*/
|
|
38
|
+
export declare const toPathOperationsV3: ({ path, pathItem, stackTrail: pathStack, context, method: only }: ToPathOperationsV3Args) => OasOperation[];
|
|
25
39
|
export {};
|