@skmtc/core 0.53.0 → 0.54.1
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/GenerateContext.d.ts +1 -61
- package/esm/context/GenerateContext.js +45 -390
- package/esm/context/ParseContext.d.ts +7 -0
- package/esm/context/ParseContext.js +16 -16
- package/esm/context/Subject.d.ts +165 -0
- package/esm/context/Subject.js +328 -0
- package/esm/parse/Reach.d.ts +56 -0
- package/esm/parse/Reach.js +131 -0
- package/esm/parse/toCyclicRefs.d.ts +3 -0
- package/esm/parse/toCyclicRefs.js +1 -1
- package/esm/parse/toRefKey.d.ts +11 -0
- package/esm/parse/toRefKey.js +16 -0
- package/package.json +1 -1
- package/script/context/GenerateContext.d.ts +1 -61
- package/script/context/GenerateContext.js +50 -395
- package/script/context/ParseContext.d.ts +7 -0
- package/script/context/ParseContext.js +18 -18
- package/script/context/Subject.d.ts +165 -0
- package/script/context/Subject.js +339 -0
- package/script/parse/Reach.d.ts +56 -0
- package/script/parse/Reach.js +135 -0
- package/script/parse/toCyclicRefs.d.ts +3 -0
- package/script/parse/toCyclicRefs.js +3 -2
- package/script/parse/toRefKey.d.ts +11 -0
- package/script/parse/toRefKey.js +20 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { GenerateContextType } from './generateTypes.js';
|
|
2
|
+
import type { OasOperationEntry } from '../dsl/operation/oas/toOasOperationEntry.js';
|
|
3
|
+
import type { WebhookEntry } from '../dsl/webhook/toWebhookEntry.js';
|
|
4
|
+
import type { GqlOperationEntry } from '../dsl/operation/gql/toGqlOperationEntry.js';
|
|
5
|
+
import type { ModelEntry } from '../dsl/model/toModelEntry.js';
|
|
6
|
+
import type { OasOperation } from '../oas/operation/Operation.js';
|
|
7
|
+
import type { OasWebhook } from '../oas/webhook/Webhook.js';
|
|
8
|
+
import type { GqlOperation } from '../gql/operation/GqlOperation.js';
|
|
9
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
10
|
+
import type { RefName } from '../types/RefName.js';
|
|
11
|
+
import type { IncludeModelRefs, IncludePaths, SkipModelRefs, SkipPaths } from '../types/Settings.js';
|
|
12
|
+
import type { GqlOperationSource, ModelSource, OasOperationSource, PreviewModule, WebhookSource } from '../types/Preview.js';
|
|
13
|
+
/** A generator entry, the run's context and one variant: what a subject is asked with. */
|
|
14
|
+
type AskArgs<Entry> = {
|
|
15
|
+
entry: Entry;
|
|
16
|
+
context: GenerateContextType;
|
|
17
|
+
variant: string;
|
|
18
|
+
};
|
|
19
|
+
type ToSourceArgs = {
|
|
20
|
+
generatorId: string;
|
|
21
|
+
variant: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* One subject of a run: an OpenAPI operation, a webhook, a GraphQL operation
|
|
25
|
+
* or a model. For the run, it holds how its kind differs from the others:
|
|
26
|
+
* where its results and its enrichments are, what a message calls it, which
|
|
27
|
+
* filter names it, and how an entry of its kind is called with it. The run
|
|
28
|
+
* asks every kind the same questions, in the same order.
|
|
29
|
+
*
|
|
30
|
+
* @template Entry - The generator entry of the subject's kind
|
|
31
|
+
* @template Filter - One generator's `settings.include` or `settings.skip`
|
|
32
|
+
* filter for the kind; `never` for a kind that has none
|
|
33
|
+
*/
|
|
34
|
+
export type Subject<Entry, Filter> = {
|
|
35
|
+
/** Its frame or frames below the generator's in a trail, and so its place in `manifest.results`. */
|
|
36
|
+
readonly trail: string | string[];
|
|
37
|
+
/** Where its enrichments are below a generator's id. A variant's name follows. */
|
|
38
|
+
readonly enrichmentPath: string[];
|
|
39
|
+
/** What a message calls it. */
|
|
40
|
+
readonly label: string;
|
|
41
|
+
isSupported: (args: AskArgs<Entry>) => boolean;
|
|
42
|
+
/** Whether a filter of `settings.include` or `settings.skip` names this variant of it. */
|
|
43
|
+
matches(filter: Filter | undefined, variant: string): boolean;
|
|
44
|
+
transform: (args: AskArgs<Entry>) => void;
|
|
45
|
+
toPreviewModule: (args: AskArgs<Entry>) => PreviewModule | undefined;
|
|
46
|
+
toSource(args: ToSourceArgs): OasOperationSource | WebhookSource | GqlOperationSource | ModelSource;
|
|
47
|
+
};
|
|
48
|
+
/** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
|
|
49
|
+
export declare class OasOperationSubject implements Subject<OasOperationEntry, IncludePaths | SkipPaths> {
|
|
50
|
+
operation: OasOperation;
|
|
51
|
+
trail: string[];
|
|
52
|
+
enrichmentPath: string[];
|
|
53
|
+
label: string;
|
|
54
|
+
constructor(operation: OasOperation);
|
|
55
|
+
isSupported({ entry, context, variant }: AskArgs<OasOperationEntry>): boolean;
|
|
56
|
+
matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
|
|
57
|
+
transform({ entry, context, variant }: AskArgs<OasOperationEntry>): void;
|
|
58
|
+
toPreviewModule({ entry, context, variant }: AskArgs<OasOperationEntry>): PreviewModule | undefined;
|
|
59
|
+
toSource({ generatorId, variant }: ToSourceArgs): OasOperationSource;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
|
|
63
|
+
* and its enrichments at `[name][method]`. A filter has the shape of an
|
|
64
|
+
* operation's, with the webhook's name in the place of the path.
|
|
65
|
+
*/
|
|
66
|
+
export declare class WebhookSubject implements Subject<WebhookEntry, IncludePaths | SkipPaths> {
|
|
67
|
+
webhook: OasWebhook;
|
|
68
|
+
trail: string[];
|
|
69
|
+
enrichmentPath: string[];
|
|
70
|
+
label: string;
|
|
71
|
+
constructor(webhook: OasWebhook);
|
|
72
|
+
isSupported({ entry, context, variant }: AskArgs<WebhookEntry>): boolean;
|
|
73
|
+
matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
|
|
74
|
+
transform({ entry, context, variant }: AskArgs<WebhookEntry>): void;
|
|
75
|
+
toPreviewModule({ entry, context, variant }: AskArgs<WebhookEntry>): PreviewModule | undefined;
|
|
76
|
+
toSource({ generatorId, variant }: ToSourceArgs): WebhookSource;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A GraphQL operation as a subject. Its results and enrichments are at
|
|
80
|
+
* `[rootKind][fieldName]`. `settings.include` and `settings.skip` have no
|
|
81
|
+
* filter for a GraphQL operation, so no filter names it.
|
|
82
|
+
*/
|
|
83
|
+
export declare class GqlOperationSubject implements Subject<GqlOperationEntry, never> {
|
|
84
|
+
operation: GqlOperation;
|
|
85
|
+
trail: string[];
|
|
86
|
+
enrichmentPath: string[];
|
|
87
|
+
label: string;
|
|
88
|
+
constructor(operation: GqlOperation);
|
|
89
|
+
isSupported({ entry, context, variant }: AskArgs<GqlOperationEntry>): boolean;
|
|
90
|
+
matches(): boolean;
|
|
91
|
+
transform({ entry, context, variant }: AskArgs<GqlOperationEntry>): void;
|
|
92
|
+
toPreviewModule({ entry, context, variant }: AskArgs<GqlOperationEntry>): PreviewModule | undefined;
|
|
93
|
+
toSource({ generatorId, variant }: ToSourceArgs): GqlOperationSource;
|
|
94
|
+
}
|
|
95
|
+
/** A model as a subject: a schema component of either protocol. Its results and enrichments are at `[refName]`. */
|
|
96
|
+
export declare class ModelSubject implements Subject<ModelEntry, IncludeModelRefs | SkipModelRefs> {
|
|
97
|
+
refName: RefName;
|
|
98
|
+
ref: RefParts;
|
|
99
|
+
trail: string;
|
|
100
|
+
enrichmentPath: string[];
|
|
101
|
+
label: string;
|
|
102
|
+
constructor(refName: RefName);
|
|
103
|
+
isSupported({ entry, context, variant }: AskArgs<ModelEntry>): boolean;
|
|
104
|
+
matches(filter: IncludeModelRefs | SkipModelRefs | undefined, variant: string): boolean;
|
|
105
|
+
transform({ entry, context, variant }: AskArgs<ModelEntry>): void;
|
|
106
|
+
toPreviewModule({ entry, context, variant }: AskArgs<ModelEntry>): PreviewModule | undefined;
|
|
107
|
+
toSource({ generatorId, variant }: ToSourceArgs): ModelSource;
|
|
108
|
+
}
|
|
109
|
+
type ToOasOperationSourceArgs = {
|
|
110
|
+
operation: OasOperation;
|
|
111
|
+
generatorId: string;
|
|
112
|
+
/** Operation variant the artifact was emitted for (see {@link Variant}) */
|
|
113
|
+
variant: string;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Creates an OasOperationSource from an operation, generator ID, and variant.
|
|
117
|
+
*
|
|
118
|
+
* Transforms operation and generator information into a source descriptor
|
|
119
|
+
* that can be used for tracking operation origins in the generation pipeline.
|
|
120
|
+
*
|
|
121
|
+
* @param args - Arguments containing operation, generator ID, and variant
|
|
122
|
+
* @returns OasOperationSource descriptor for the operation
|
|
123
|
+
*/
|
|
124
|
+
export declare const toOasOperationSource: ({ operation, generatorId, variant }: ToOasOperationSourceArgs) => OasOperationSource;
|
|
125
|
+
type ToWebhookSourceArgs = {
|
|
126
|
+
webhook: OasWebhook;
|
|
127
|
+
generatorId: string;
|
|
128
|
+
/** Webhook variant the artifact was emitted for (see {@link Variant}) */
|
|
129
|
+
variant: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Creates a {@link WebhookSource} from a webhook, generator ID, and variant.
|
|
133
|
+
* Sibling of {@link toOasOperationSource} for the 3.1 webhook subject.
|
|
134
|
+
*/
|
|
135
|
+
export declare const toWebhookSource: ({ webhook, generatorId, variant }: ToWebhookSourceArgs) => WebhookSource;
|
|
136
|
+
type ToGqlOperationSourceArgs = {
|
|
137
|
+
operation: GqlOperation;
|
|
138
|
+
generatorId: string;
|
|
139
|
+
/** Operation variant the artifact was emitted for (see {@link Variant}) */
|
|
140
|
+
variant: string;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates a GraphQL operation source descriptor.
|
|
144
|
+
*
|
|
145
|
+
* Sibling to {@link toOasOperationSource} for the GraphQL protocol — encodes
|
|
146
|
+
* `rootKind` and `fieldName` instead of `path` / `method`.
|
|
147
|
+
*/
|
|
148
|
+
export declare const toGqlOperationSource: ({ operation, generatorId, variant }: ToGqlOperationSourceArgs) => GqlOperationSource;
|
|
149
|
+
type ToModelSourceArgs = {
|
|
150
|
+
refName: RefName;
|
|
151
|
+
generatorId: string;
|
|
152
|
+
/** Model variant the artifact was emitted for (see {@link Variant}) */
|
|
153
|
+
variant: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Creates a ModelSource from a reference name, generator ID, and variant.
|
|
157
|
+
*
|
|
158
|
+
* Transforms model reference and generator information into a source descriptor
|
|
159
|
+
* that can be used for tracking model origins in the generation pipeline.
|
|
160
|
+
*
|
|
161
|
+
* @param args - Arguments containing reference name, generator ID, and variant
|
|
162
|
+
* @returns ModelSource descriptor for the model
|
|
163
|
+
*/
|
|
164
|
+
export declare const toModelSource: ({ refName, generatorId, variant }: ToModelSourceArgs) => ModelSource;
|
|
165
|
+
export {};
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource = exports.toOasOperationSource = exports.ModelSubject = exports.GqlOperationSubject = exports.WebhookSubject = exports.OasOperationSubject = void 0;
|
|
4
|
+
const refFns_js_1 = require("../helpers/refFns.js");
|
|
5
|
+
/** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
|
|
6
|
+
class OasOperationSubject {
|
|
7
|
+
constructor(operation) {
|
|
8
|
+
Object.defineProperty(this, "operation", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "trail", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "label", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
this.operation = operation;
|
|
33
|
+
this.trail = [operation.path, operation.method];
|
|
34
|
+
this.enrichmentPath = this.trail;
|
|
35
|
+
this.label = `${operation.method.toUpperCase()} ${operation.path}`;
|
|
36
|
+
}
|
|
37
|
+
isSupported({ entry, context, variant }) {
|
|
38
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
39
|
+
entry.isSupported({ operation: this.operation, context, variant }));
|
|
40
|
+
}
|
|
41
|
+
matches(filter, variant) {
|
|
42
|
+
const { path, method } = this.operation;
|
|
43
|
+
return matchesPathFilter({ paths: filter, path, method, variant });
|
|
44
|
+
}
|
|
45
|
+
transform({ entry, context, variant }) {
|
|
46
|
+
entry.transform({ context, operation: this.operation, variant });
|
|
47
|
+
}
|
|
48
|
+
toPreviewModule({ entry, context, variant }) {
|
|
49
|
+
return entry.toPreviewModule?.({ context, operation: this.operation, variant });
|
|
50
|
+
}
|
|
51
|
+
toSource({ generatorId, variant }) {
|
|
52
|
+
return (0, exports.toOasOperationSource)({ operation: this.operation, generatorId, variant });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.OasOperationSubject = OasOperationSubject;
|
|
56
|
+
/**
|
|
57
|
+
* A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
|
|
58
|
+
* and its enrichments at `[name][method]`. A filter has the shape of an
|
|
59
|
+
* operation's, with the webhook's name in the place of the path.
|
|
60
|
+
*/
|
|
61
|
+
class WebhookSubject {
|
|
62
|
+
constructor(webhook) {
|
|
63
|
+
Object.defineProperty(this, "webhook", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "trail", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "label", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
this.webhook = webhook;
|
|
88
|
+
this.trail = ['webhook', webhook.name, webhook.method];
|
|
89
|
+
this.enrichmentPath = [webhook.name, webhook.method];
|
|
90
|
+
this.label = `webhook '${webhook.name}' (${webhook.method.toUpperCase()})`;
|
|
91
|
+
}
|
|
92
|
+
isSupported({ entry, context, variant }) {
|
|
93
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
94
|
+
entry.isSupported({ webhook: this.webhook, context, variant }));
|
|
95
|
+
}
|
|
96
|
+
matches(filter, variant) {
|
|
97
|
+
const { name, method } = this.webhook;
|
|
98
|
+
return matchesPathFilter({ paths: filter, path: name, method, variant });
|
|
99
|
+
}
|
|
100
|
+
transform({ entry, context, variant }) {
|
|
101
|
+
entry.transform({ context, webhook: this.webhook, variant });
|
|
102
|
+
}
|
|
103
|
+
toPreviewModule({ entry, context, variant }) {
|
|
104
|
+
return entry.toPreviewModule?.({ context, webhook: this.webhook, variant });
|
|
105
|
+
}
|
|
106
|
+
toSource({ generatorId, variant }) {
|
|
107
|
+
return (0, exports.toWebhookSource)({ webhook: this.webhook, generatorId, variant });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.WebhookSubject = WebhookSubject;
|
|
111
|
+
/**
|
|
112
|
+
* A GraphQL operation as a subject. Its results and enrichments are at
|
|
113
|
+
* `[rootKind][fieldName]`. `settings.include` and `settings.skip` have no
|
|
114
|
+
* filter for a GraphQL operation, so no filter names it.
|
|
115
|
+
*/
|
|
116
|
+
class GqlOperationSubject {
|
|
117
|
+
constructor(operation) {
|
|
118
|
+
Object.defineProperty(this, "operation", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: void 0
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(this, "trail", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: void 0
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
configurable: true,
|
|
133
|
+
writable: true,
|
|
134
|
+
value: void 0
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(this, "label", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true,
|
|
140
|
+
value: void 0
|
|
141
|
+
});
|
|
142
|
+
this.operation = operation;
|
|
143
|
+
this.trail = [operation.rootKind, operation.fieldName];
|
|
144
|
+
this.enrichmentPath = this.trail;
|
|
145
|
+
this.label = `${operation.rootKind} ${operation.fieldName}`;
|
|
146
|
+
}
|
|
147
|
+
isSupported({ entry, context, variant }) {
|
|
148
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
149
|
+
entry.isSupported({ operation: this.operation, context, variant }));
|
|
150
|
+
}
|
|
151
|
+
matches() {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
transform({ entry, context, variant }) {
|
|
155
|
+
entry.transform({ context, operation: this.operation, variant });
|
|
156
|
+
}
|
|
157
|
+
toPreviewModule({ entry, context, variant }) {
|
|
158
|
+
return entry.toPreviewModule?.({ context, operation: this.operation, variant });
|
|
159
|
+
}
|
|
160
|
+
toSource({ generatorId, variant }) {
|
|
161
|
+
return (0, exports.toGqlOperationSource)({ operation: this.operation, generatorId, variant });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.GqlOperationSubject = GqlOperationSubject;
|
|
165
|
+
/** A model as a subject: a schema component of either protocol. Its results and enrichments are at `[refName]`. */
|
|
166
|
+
class ModelSubject {
|
|
167
|
+
constructor(refName) {
|
|
168
|
+
Object.defineProperty(this, "refName", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: true,
|
|
171
|
+
writable: true,
|
|
172
|
+
value: void 0
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(this, "ref", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true,
|
|
177
|
+
writable: true,
|
|
178
|
+
value: void 0
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(this, "trail", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
configurable: true,
|
|
183
|
+
writable: true,
|
|
184
|
+
value: void 0
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
configurable: true,
|
|
189
|
+
writable: true,
|
|
190
|
+
value: void 0
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(this, "label", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
configurable: true,
|
|
195
|
+
writable: true,
|
|
196
|
+
value: void 0
|
|
197
|
+
});
|
|
198
|
+
this.refName = refName;
|
|
199
|
+
this.ref = (0, refFns_js_1.toSchemaComponentRef)(refName);
|
|
200
|
+
this.trail = refName;
|
|
201
|
+
this.enrichmentPath = [refName];
|
|
202
|
+
this.label = refName;
|
|
203
|
+
}
|
|
204
|
+
isSupported({ entry, context, variant }) {
|
|
205
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
206
|
+
entry.isSupported({ ref: this.ref, context, variant }));
|
|
207
|
+
}
|
|
208
|
+
matches(filter, variant) {
|
|
209
|
+
return matchesRefFilter({ refs: filter, refName: this.refName, variant });
|
|
210
|
+
}
|
|
211
|
+
transform({ entry, context, variant }) {
|
|
212
|
+
entry.transform({ context, ref: this.ref, variant });
|
|
213
|
+
}
|
|
214
|
+
toPreviewModule({ entry, context, variant }) {
|
|
215
|
+
return entry.toPreviewModule?.({ context, ref: this.ref, variant });
|
|
216
|
+
}
|
|
217
|
+
toSource({ generatorId, variant }) {
|
|
218
|
+
return (0, exports.toModelSource)({ refName: this.refName, generatorId, variant });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.ModelSubject = ModelSubject;
|
|
222
|
+
/**
|
|
223
|
+
* Match a `(path, method, variant)` tuple against an operation-shaped
|
|
224
|
+
* skip or include entry. Shared by both arms because skip and include
|
|
225
|
+
* have the same matching rules; only the engine's interpretation of
|
|
226
|
+
* the result differs (skip = deny, include = allow).
|
|
227
|
+
*
|
|
228
|
+
* Returns `false` when:
|
|
229
|
+
* - `paths` is `undefined` (no filter applies)
|
|
230
|
+
* - the `path` isn't keyed in the entry
|
|
231
|
+
* - the `method` isn't present in the inner record
|
|
232
|
+
*
|
|
233
|
+
* Returns `true` when:
|
|
234
|
+
* - the method's variant array is empty (matches every variant)
|
|
235
|
+
* - the method's variant array contains `variant`
|
|
236
|
+
*/
|
|
237
|
+
const matchesPathFilter = ({ paths, path, method, variant }) => {
|
|
238
|
+
if (!paths) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
const methodMap = paths[path];
|
|
242
|
+
if (!methodMap) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
const variants = methodMap[method];
|
|
246
|
+
if (variants === undefined) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (variants.length === 0) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
return variants.includes(variant);
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Match a `(refName, variant)` tuple against a model-shaped skip or
|
|
256
|
+
* include entry. Sibling to {@link matchesPathFilter} — both arms
|
|
257
|
+
* share matching rules; only the engine's interpretation of the
|
|
258
|
+
* result differs (skip = deny, include = allow).
|
|
259
|
+
*
|
|
260
|
+
* Returns `false` when:
|
|
261
|
+
* - `refs` is `undefined` (no filter applies)
|
|
262
|
+
* - the `refName` isn't keyed in the entry
|
|
263
|
+
*
|
|
264
|
+
* Returns `true` when:
|
|
265
|
+
* - the refName's variant array is empty (matches every variant)
|
|
266
|
+
* - the refName's variant array contains `variant`
|
|
267
|
+
*/
|
|
268
|
+
const matchesRefFilter = ({ refs, refName, variant }) => {
|
|
269
|
+
if (!refs) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
const variants = refs[refName];
|
|
273
|
+
if (variants === undefined) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
if (variants.length === 0) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
return variants.includes(variant);
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Creates an OasOperationSource from an operation, generator ID, and variant.
|
|
283
|
+
*
|
|
284
|
+
* Transforms operation and generator information into a source descriptor
|
|
285
|
+
* that can be used for tracking operation origins in the generation pipeline.
|
|
286
|
+
*
|
|
287
|
+
* @param args - Arguments containing operation, generator ID, and variant
|
|
288
|
+
* @returns OasOperationSource descriptor for the operation
|
|
289
|
+
*/
|
|
290
|
+
const toOasOperationSource = ({ operation, generatorId, variant }) => ({
|
|
291
|
+
type: 'oasOperation',
|
|
292
|
+
generatorId,
|
|
293
|
+
operationPath: operation.path,
|
|
294
|
+
operationMethod: operation.method,
|
|
295
|
+
variant
|
|
296
|
+
});
|
|
297
|
+
exports.toOasOperationSource = toOasOperationSource;
|
|
298
|
+
/**
|
|
299
|
+
* Creates a {@link WebhookSource} from a webhook, generator ID, and variant.
|
|
300
|
+
* Sibling of {@link toOasOperationSource} for the 3.1 webhook subject.
|
|
301
|
+
*/
|
|
302
|
+
const toWebhookSource = ({ webhook, generatorId, variant }) => ({
|
|
303
|
+
type: 'webhook',
|
|
304
|
+
generatorId,
|
|
305
|
+
webhookName: webhook.name,
|
|
306
|
+
webhookMethod: webhook.method,
|
|
307
|
+
variant
|
|
308
|
+
});
|
|
309
|
+
exports.toWebhookSource = toWebhookSource;
|
|
310
|
+
/**
|
|
311
|
+
* Creates a GraphQL operation source descriptor.
|
|
312
|
+
*
|
|
313
|
+
* Sibling to {@link toOasOperationSource} for the GraphQL protocol — encodes
|
|
314
|
+
* `rootKind` and `fieldName` instead of `path` / `method`.
|
|
315
|
+
*/
|
|
316
|
+
const toGqlOperationSource = ({ operation, generatorId, variant }) => ({
|
|
317
|
+
type: 'gqlOperation',
|
|
318
|
+
generatorId,
|
|
319
|
+
rootKind: operation.rootKind,
|
|
320
|
+
fieldName: operation.fieldName,
|
|
321
|
+
variant
|
|
322
|
+
});
|
|
323
|
+
exports.toGqlOperationSource = toGqlOperationSource;
|
|
324
|
+
/**
|
|
325
|
+
* Creates a ModelSource from a reference name, generator ID, and variant.
|
|
326
|
+
*
|
|
327
|
+
* Transforms model reference and generator information into a source descriptor
|
|
328
|
+
* that can be used for tracking model origins in the generation pipeline.
|
|
329
|
+
*
|
|
330
|
+
* @param args - Arguments containing reference name, generator ID, and variant
|
|
331
|
+
* @returns ModelSource descriptor for the model
|
|
332
|
+
*/
|
|
333
|
+
const toModelSource = ({ refName, generatorId, variant }) => ({
|
|
334
|
+
type: 'model',
|
|
335
|
+
generatorId,
|
|
336
|
+
refName,
|
|
337
|
+
variant
|
|
338
|
+
});
|
|
339
|
+
exports.toModelSource = toModelSource;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
2
|
+
import type { OasRefData } from '../oas/ref/ref-types.js';
|
|
3
|
+
/** A ref the parser read, and where it is. */
|
|
4
|
+
export type ReadRef = {
|
|
5
|
+
/** The ref, with the kind of object the parser read it as: only a `schema` ref can name a model. */
|
|
6
|
+
ref: RefParts & {
|
|
7
|
+
refType: OasRefData['refType'];
|
|
8
|
+
};
|
|
9
|
+
/** The frames of the ref's place in the document: `['paths', '/pets', 'get', …]`. */
|
|
10
|
+
place: readonly string[];
|
|
11
|
+
/** The key of the ref target the parser read it for; `undefined` in the document's own walk. */
|
|
12
|
+
refTarget: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
/** Where an operation is in a document. An `OasOperation` fits it. */
|
|
15
|
+
type OperationPlace = {
|
|
16
|
+
path: string;
|
|
17
|
+
method: string;
|
|
18
|
+
};
|
|
19
|
+
/** Where a webhook is in a document. An `OasWebhook` fits it. */
|
|
20
|
+
type WebhookPlace = {
|
|
21
|
+
name: string;
|
|
22
|
+
method: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* What a subject of a document can reach through `$ref`s: the models a
|
|
26
|
+
* generator can get to from it, each by its model key (`toModelKey`).
|
|
27
|
+
*
|
|
28
|
+
* It is read from the refs the parser itself read, each with its place
|
|
29
|
+
* (`ParseContext.toReach`). So it has what a generator can follow in the
|
|
30
|
+
* parsed document, and no more: a `$ref` the parser took for data is not in
|
|
31
|
+
* it, and neither is the parent of an `allOf` that the parser merged into
|
|
32
|
+
* its child. It needs no walk of the document of its own.
|
|
33
|
+
*
|
|
34
|
+
* A place is a model, an operation, the parameters of a path item, or a
|
|
35
|
+
* component that is no schema. The models a place names are those its own
|
|
36
|
+
* refs give, and those behind each such component it refers to. A model
|
|
37
|
+
* reaches the models it names, and the models those name.
|
|
38
|
+
*/
|
|
39
|
+
export declare class Reach {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(refs: Iterable<ReadRef>);
|
|
42
|
+
/** The keys of the models a model reaches, its own included. */
|
|
43
|
+
ofModel(ref: RefParts): readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* The keys of the models an operation names: `paths[path][method]`, with
|
|
46
|
+
* what every operation of the path has, which is the path item's
|
|
47
|
+
* `parameters`, and any ref kept at the path item itself. The parser does
|
|
48
|
+
* not read a path item's own `$ref` yet, so that last place is empty. A
|
|
49
|
+
* path item parameter the operation overrides is still named: one model too
|
|
50
|
+
* many is safe for a plan, one too few is not.
|
|
51
|
+
*/
|
|
52
|
+
namedByOperation({ path, method }: OperationPlace): readonly string[];
|
|
53
|
+
/** The keys of the models a webhook names: `webhooks[name][method]`, as {@link namedByOperation}. */
|
|
54
|
+
namedByWebhook({ name, method }: WebhookPlace): readonly string[];
|
|
55
|
+
}
|
|
56
|
+
export {};
|