@skmtc/core 0.54.0 → 0.55.0
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/FilePlan.d.ts +56 -0
- package/esm/context/FilePlan.js +188 -0
- package/esm/context/GenerateContext.d.ts +19 -61
- package/esm/context/GenerateContext.js +72 -390
- package/esm/context/Subject.d.ts +209 -0
- package/esm/context/Subject.js +396 -0
- package/esm/enrichments/EnrichmentAudit.d.ts +7 -0
- package/esm/enrichments/EnrichmentAudit.js +36 -4
- package/package.json +1 -1
- package/script/context/FilePlan.d.ts +56 -0
- package/script/context/FilePlan.js +192 -0
- package/script/context/GenerateContext.d.ts +19 -61
- package/script/context/GenerateContext.js +77 -395
- package/script/context/Subject.d.ts +209 -0
- package/script/context/Subject.js +407 -0
- package/script/enrichments/EnrichmentAudit.d.ts +7 -0
- package/script/enrichments/EnrichmentAudit.js +36 -4
|
@@ -0,0 +1,209 @@
|
|
|
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 { DeclaredProjection } from '../dsl/DeclaredProjection.js';
|
|
10
|
+
import type { Reach } from '../parse/Reach.js';
|
|
11
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
12
|
+
import type { RefName } from '../types/RefName.js';
|
|
13
|
+
import type { IncludeModelRefs, IncludePaths, SkipModelRefs, SkipPaths } from '../types/Settings.js';
|
|
14
|
+
import type { GqlOperationSource, ModelSource, OasOperationSource, PreviewModule, WebhookSource } from '../types/Preview.js';
|
|
15
|
+
/** A generator entry, the run's context and one variant: what a subject is asked with. */
|
|
16
|
+
type AskArgs<Entry> = {
|
|
17
|
+
entry: Entry;
|
|
18
|
+
context: GenerateContextType;
|
|
19
|
+
variant: string;
|
|
20
|
+
};
|
|
21
|
+
type ToSourceArgs = {
|
|
22
|
+
generatorId: string;
|
|
23
|
+
variant: string;
|
|
24
|
+
};
|
|
25
|
+
type ToExportPathArgs = {
|
|
26
|
+
projection: DeclaredProjection;
|
|
27
|
+
context: GenerateContextType;
|
|
28
|
+
variant: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* What the file plan asks of a subject: where its enrichments are, the
|
|
32
|
+
* file a projection gives it, and the models it can get to.
|
|
33
|
+
*/
|
|
34
|
+
export type PlannedSubject = {
|
|
35
|
+
/** Its kind, which is the `type` of the entries and the projections that take it. */
|
|
36
|
+
readonly type: DeclaredProjection['type'];
|
|
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
|
+
/**
|
|
42
|
+
* The export path a declared projection gives it for one variant, as the
|
|
43
|
+
* projection's statics say it. `undefined` for a projection of another kind.
|
|
44
|
+
*/
|
|
45
|
+
toExportPath(args: ToExportPathArgs): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The keys of the models it names: for a model, its own key; for any other
|
|
48
|
+
* subject, the models its `$ref`s give (`Reach.namedByOperation`, `Reach.namedByWebhook`). It can get to
|
|
49
|
+
* each of them, and to what each reaches.
|
|
50
|
+
*/
|
|
51
|
+
toNamedModels(reach: Reach): readonly string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* One subject of a run: an OpenAPI operation, a webhook, a GraphQL operation
|
|
55
|
+
* or a model. For the run, it holds how its kind differs from the others:
|
|
56
|
+
* where its results and its enrichments are, what a message calls it, which
|
|
57
|
+
* filter names it, and how an entry of its kind is called with it. The run
|
|
58
|
+
* asks every kind the same questions, in the same order.
|
|
59
|
+
*
|
|
60
|
+
* @template Entry - The generator entry of the subject's kind
|
|
61
|
+
* @template Filter - One generator's `settings.include` or `settings.skip`
|
|
62
|
+
* filter for the kind; `never` for a kind that has none
|
|
63
|
+
*/
|
|
64
|
+
export type Subject<Entry, Filter> = PlannedSubject & {
|
|
65
|
+
/** Its frame or frames below the generator's in a trail, and so its place in `manifest.results`. */
|
|
66
|
+
readonly trail: string | string[];
|
|
67
|
+
isSupported: (args: AskArgs<Entry>) => boolean;
|
|
68
|
+
/** Whether a filter of `settings.include` or `settings.skip` names this variant of it. */
|
|
69
|
+
matches(filter: Filter | undefined, variant: string): boolean;
|
|
70
|
+
transform: (args: AskArgs<Entry>) => void;
|
|
71
|
+
toPreviewModule: (args: AskArgs<Entry>) => PreviewModule | undefined;
|
|
72
|
+
toSource(args: ToSourceArgs): OasOperationSource | WebhookSource | GqlOperationSource | ModelSource;
|
|
73
|
+
};
|
|
74
|
+
/** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
|
|
75
|
+
export declare class OasOperationSubject implements Subject<OasOperationEntry, IncludePaths | SkipPaths> {
|
|
76
|
+
readonly type = "oasOperation";
|
|
77
|
+
operation: OasOperation;
|
|
78
|
+
trail: string[];
|
|
79
|
+
enrichmentPath: string[];
|
|
80
|
+
label: string;
|
|
81
|
+
constructor(operation: OasOperation);
|
|
82
|
+
isSupported({ entry, context, variant }: AskArgs<OasOperationEntry>): boolean;
|
|
83
|
+
matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
|
|
84
|
+
transform({ entry, context, variant }: AskArgs<OasOperationEntry>): void;
|
|
85
|
+
toPreviewModule({ entry, context, variant }: AskArgs<OasOperationEntry>): PreviewModule | undefined;
|
|
86
|
+
toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
|
|
87
|
+
toNamedModels(reach: Reach): readonly string[];
|
|
88
|
+
toSource({ generatorId, variant }: ToSourceArgs): OasOperationSource;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
|
|
92
|
+
* and its enrichments at `[name][method]`. A filter has the shape of an
|
|
93
|
+
* operation's, with the webhook's name in the place of the path.
|
|
94
|
+
*/
|
|
95
|
+
export declare class WebhookSubject implements Subject<WebhookEntry, IncludePaths | SkipPaths> {
|
|
96
|
+
readonly type = "webhook";
|
|
97
|
+
webhook: OasWebhook;
|
|
98
|
+
trail: string[];
|
|
99
|
+
enrichmentPath: string[];
|
|
100
|
+
label: string;
|
|
101
|
+
constructor(webhook: OasWebhook);
|
|
102
|
+
isSupported({ entry, context, variant }: AskArgs<WebhookEntry>): boolean;
|
|
103
|
+
matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
|
|
104
|
+
transform({ entry, context, variant }: AskArgs<WebhookEntry>): void;
|
|
105
|
+
toPreviewModule({ entry, context, variant }: AskArgs<WebhookEntry>): PreviewModule | undefined;
|
|
106
|
+
toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
|
|
107
|
+
toNamedModels(reach: Reach): readonly string[];
|
|
108
|
+
toSource({ generatorId, variant }: ToSourceArgs): WebhookSource;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A GraphQL operation as a subject. Its results and enrichments are at
|
|
112
|
+
* `[rootKind][fieldName]`. `settings.include` and `settings.skip` have no
|
|
113
|
+
* filter for a GraphQL operation, so no filter names it.
|
|
114
|
+
*/
|
|
115
|
+
export declare class GqlOperationSubject implements Subject<GqlOperationEntry, never> {
|
|
116
|
+
readonly type = "gqlOperation";
|
|
117
|
+
operation: GqlOperation;
|
|
118
|
+
trail: string[];
|
|
119
|
+
enrichmentPath: string[];
|
|
120
|
+
label: string;
|
|
121
|
+
constructor(operation: GqlOperation);
|
|
122
|
+
isSupported({ entry, context, variant }: AskArgs<GqlOperationEntry>): boolean;
|
|
123
|
+
matches(): boolean;
|
|
124
|
+
transform({ entry, context, variant }: AskArgs<GqlOperationEntry>): void;
|
|
125
|
+
toPreviewModule({ entry, context, variant }: AskArgs<GqlOperationEntry>): PreviewModule | undefined;
|
|
126
|
+
toExportPath(): undefined;
|
|
127
|
+
toNamedModels(): readonly string[];
|
|
128
|
+
toSource({ generatorId, variant }: ToSourceArgs): GqlOperationSource;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A model as a subject. Its results and enrichments are at its model key
|
|
132
|
+
* (`toModelKey`): the `refName` of a component, the whole pointer of any
|
|
133
|
+
* other model. The run makes one for each schema component of either
|
|
134
|
+
* protocol; the file plan also makes one for a model that is no component,
|
|
135
|
+
* which a `$ref` to a place inside a schema gives.
|
|
136
|
+
*/
|
|
137
|
+
export declare class ModelSubject implements Subject<ModelEntry, IncludeModelRefs | SkipModelRefs> {
|
|
138
|
+
readonly type = "model";
|
|
139
|
+
refName: RefName;
|
|
140
|
+
ref: RefParts;
|
|
141
|
+
trail: string;
|
|
142
|
+
enrichmentPath: string[];
|
|
143
|
+
label: string;
|
|
144
|
+
constructor(ref: RefParts);
|
|
145
|
+
isSupported({ entry, context, variant }: AskArgs<ModelEntry>): boolean;
|
|
146
|
+
matches(filter: IncludeModelRefs | SkipModelRefs | undefined, variant: string): boolean;
|
|
147
|
+
transform({ entry, context, variant }: AskArgs<ModelEntry>): void;
|
|
148
|
+
toPreviewModule({ entry, context, variant }: AskArgs<ModelEntry>): PreviewModule | undefined;
|
|
149
|
+
toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
|
|
150
|
+
toNamedModels(): readonly string[];
|
|
151
|
+
toSource({ generatorId, variant }: ToSourceArgs): ModelSource;
|
|
152
|
+
}
|
|
153
|
+
type ToOasOperationSourceArgs = {
|
|
154
|
+
operation: OasOperation;
|
|
155
|
+
generatorId: string;
|
|
156
|
+
/** Operation variant the artifact was emitted for (see {@link Variant}) */
|
|
157
|
+
variant: string;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Creates an OasOperationSource from an operation, generator ID, and variant.
|
|
161
|
+
*
|
|
162
|
+
* Transforms operation and generator information into a source descriptor
|
|
163
|
+
* that can be used for tracking operation origins in the generation pipeline.
|
|
164
|
+
*
|
|
165
|
+
* @param args - Arguments containing operation, generator ID, and variant
|
|
166
|
+
* @returns OasOperationSource descriptor for the operation
|
|
167
|
+
*/
|
|
168
|
+
export declare const toOasOperationSource: ({ operation, generatorId, variant }: ToOasOperationSourceArgs) => OasOperationSource;
|
|
169
|
+
type ToWebhookSourceArgs = {
|
|
170
|
+
webhook: OasWebhook;
|
|
171
|
+
generatorId: string;
|
|
172
|
+
/** Webhook variant the artifact was emitted for (see {@link Variant}) */
|
|
173
|
+
variant: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Creates a {@link WebhookSource} from a webhook, generator ID, and variant.
|
|
177
|
+
* Sibling of {@link toOasOperationSource} for the 3.1 webhook subject.
|
|
178
|
+
*/
|
|
179
|
+
export declare const toWebhookSource: ({ webhook, generatorId, variant }: ToWebhookSourceArgs) => WebhookSource;
|
|
180
|
+
type ToGqlOperationSourceArgs = {
|
|
181
|
+
operation: GqlOperation;
|
|
182
|
+
generatorId: string;
|
|
183
|
+
/** Operation variant the artifact was emitted for (see {@link Variant}) */
|
|
184
|
+
variant: string;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Creates a GraphQL operation source descriptor.
|
|
188
|
+
*
|
|
189
|
+
* Sibling to {@link toOasOperationSource} for the GraphQL protocol — encodes
|
|
190
|
+
* `rootKind` and `fieldName` instead of `path` / `method`.
|
|
191
|
+
*/
|
|
192
|
+
export declare const toGqlOperationSource: ({ operation, generatorId, variant }: ToGqlOperationSourceArgs) => GqlOperationSource;
|
|
193
|
+
type ToModelSourceArgs = {
|
|
194
|
+
refName: RefName;
|
|
195
|
+
generatorId: string;
|
|
196
|
+
/** Model variant the artifact was emitted for (see {@link Variant}) */
|
|
197
|
+
variant: string;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Creates a ModelSource from a reference name, generator ID, and variant.
|
|
201
|
+
*
|
|
202
|
+
* Transforms model reference and generator information into a source descriptor
|
|
203
|
+
* that can be used for tracking model origins in the generation pipeline.
|
|
204
|
+
*
|
|
205
|
+
* @param args - Arguments containing reference name, generator ID, and variant
|
|
206
|
+
* @returns ModelSource descriptor for the model
|
|
207
|
+
*/
|
|
208
|
+
export declare const toModelSource: ({ refName, generatorId, variant }: ToModelSourceArgs) => ModelSource;
|
|
209
|
+
export {};
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { toModelKey } from '../helpers/refFns.js';
|
|
2
|
+
/** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
|
|
3
|
+
export class OasOperationSubject {
|
|
4
|
+
constructor(operation) {
|
|
5
|
+
Object.defineProperty(this, "type", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: 'oasOperation'
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "operation", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "trail", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "label", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
this.operation = operation;
|
|
36
|
+
this.trail = [operation.path, operation.method];
|
|
37
|
+
this.enrichmentPath = this.trail;
|
|
38
|
+
this.label = `${operation.method.toUpperCase()} ${operation.path}`;
|
|
39
|
+
}
|
|
40
|
+
isSupported({ entry, context, variant }) {
|
|
41
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
42
|
+
entry.isSupported({ operation: this.operation, context, variant }));
|
|
43
|
+
}
|
|
44
|
+
matches(filter, variant) {
|
|
45
|
+
const { path, method } = this.operation;
|
|
46
|
+
return matchesPathFilter({ paths: filter, path, method, variant });
|
|
47
|
+
}
|
|
48
|
+
transform({ entry, context, variant }) {
|
|
49
|
+
entry.transform({ context, operation: this.operation, variant });
|
|
50
|
+
}
|
|
51
|
+
toPreviewModule({ entry, context, variant }) {
|
|
52
|
+
return entry.toPreviewModule?.({ context, operation: this.operation, variant });
|
|
53
|
+
}
|
|
54
|
+
toExportPath({ projection, context, variant }) {
|
|
55
|
+
if (projection.type !== 'oasOperation') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const enrichments = projection.toEnrichments({ operation: this.operation, context, variant });
|
|
59
|
+
return projection.toExportPath({ operation: this.operation, enrichments, variant });
|
|
60
|
+
}
|
|
61
|
+
toNamedModels(reach) {
|
|
62
|
+
return reach.namedByOperation(this.operation);
|
|
63
|
+
}
|
|
64
|
+
toSource({ generatorId, variant }) {
|
|
65
|
+
return toOasOperationSource({ operation: this.operation, generatorId, variant });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
|
|
70
|
+
* and its enrichments at `[name][method]`. A filter has the shape of an
|
|
71
|
+
* operation's, with the webhook's name in the place of the path.
|
|
72
|
+
*/
|
|
73
|
+
export class WebhookSubject {
|
|
74
|
+
constructor(webhook) {
|
|
75
|
+
Object.defineProperty(this, "type", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: 'webhook'
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "webhook", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "trail", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: void 0
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "label", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: void 0
|
|
104
|
+
});
|
|
105
|
+
this.webhook = webhook;
|
|
106
|
+
this.trail = ['webhook', webhook.name, webhook.method];
|
|
107
|
+
this.enrichmentPath = [webhook.name, webhook.method];
|
|
108
|
+
this.label = `webhook '${webhook.name}' (${webhook.method.toUpperCase()})`;
|
|
109
|
+
}
|
|
110
|
+
isSupported({ entry, context, variant }) {
|
|
111
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
112
|
+
entry.isSupported({ webhook: this.webhook, context, variant }));
|
|
113
|
+
}
|
|
114
|
+
matches(filter, variant) {
|
|
115
|
+
const { name, method } = this.webhook;
|
|
116
|
+
return matchesPathFilter({ paths: filter, path: name, method, variant });
|
|
117
|
+
}
|
|
118
|
+
transform({ entry, context, variant }) {
|
|
119
|
+
entry.transform({ context, webhook: this.webhook, variant });
|
|
120
|
+
}
|
|
121
|
+
toPreviewModule({ entry, context, variant }) {
|
|
122
|
+
return entry.toPreviewModule?.({ context, webhook: this.webhook, variant });
|
|
123
|
+
}
|
|
124
|
+
toExportPath({ projection, context, variant }) {
|
|
125
|
+
if (projection.type !== 'webhook') {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
const enrichments = projection.toEnrichments({ webhook: this.webhook, context, variant });
|
|
129
|
+
return projection.toExportPath({ webhook: this.webhook, enrichments, variant });
|
|
130
|
+
}
|
|
131
|
+
toNamedModels(reach) {
|
|
132
|
+
return reach.namedByWebhook(this.webhook);
|
|
133
|
+
}
|
|
134
|
+
toSource({ generatorId, variant }) {
|
|
135
|
+
return toWebhookSource({ webhook: this.webhook, generatorId, variant });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A GraphQL operation as a subject. Its results and enrichments are at
|
|
140
|
+
* `[rootKind][fieldName]`. `settings.include` and `settings.skip` have no
|
|
141
|
+
* filter for a GraphQL operation, so no filter names it.
|
|
142
|
+
*/
|
|
143
|
+
export class GqlOperationSubject {
|
|
144
|
+
constructor(operation) {
|
|
145
|
+
Object.defineProperty(this, "type", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: true,
|
|
148
|
+
writable: true,
|
|
149
|
+
value: 'gqlOperation'
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(this, "operation", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: true,
|
|
154
|
+
writable: true,
|
|
155
|
+
value: void 0
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(this, "trail", {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
configurable: true,
|
|
160
|
+
writable: true,
|
|
161
|
+
value: void 0
|
|
162
|
+
});
|
|
163
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
164
|
+
enumerable: true,
|
|
165
|
+
configurable: true,
|
|
166
|
+
writable: true,
|
|
167
|
+
value: void 0
|
|
168
|
+
});
|
|
169
|
+
Object.defineProperty(this, "label", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
configurable: true,
|
|
172
|
+
writable: true,
|
|
173
|
+
value: void 0
|
|
174
|
+
});
|
|
175
|
+
this.operation = operation;
|
|
176
|
+
this.trail = [operation.rootKind, operation.fieldName];
|
|
177
|
+
this.enrichmentPath = this.trail;
|
|
178
|
+
this.label = `${operation.rootKind} ${operation.fieldName}`;
|
|
179
|
+
}
|
|
180
|
+
isSupported({ entry, context, variant }) {
|
|
181
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
182
|
+
entry.isSupported({ operation: this.operation, context, variant }));
|
|
183
|
+
}
|
|
184
|
+
matches() {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
transform({ entry, context, variant }) {
|
|
188
|
+
entry.transform({ context, operation: this.operation, variant });
|
|
189
|
+
}
|
|
190
|
+
toPreviewModule({ entry, context, variant }) {
|
|
191
|
+
return entry.toPreviewModule?.({ context, operation: this.operation, variant });
|
|
192
|
+
}
|
|
193
|
+
// A GraphQL document has no `$ref`s to read a reach from, so its files are not planned.
|
|
194
|
+
toExportPath() {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
toNamedModels() {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
toSource({ generatorId, variant }) {
|
|
201
|
+
return toGqlOperationSource({ operation: this.operation, generatorId, variant });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* A model as a subject. Its results and enrichments are at its model key
|
|
206
|
+
* (`toModelKey`): the `refName` of a component, the whole pointer of any
|
|
207
|
+
* other model. The run makes one for each schema component of either
|
|
208
|
+
* protocol; the file plan also makes one for a model that is no component,
|
|
209
|
+
* which a `$ref` to a place inside a schema gives.
|
|
210
|
+
*/
|
|
211
|
+
export class ModelSubject {
|
|
212
|
+
constructor(ref) {
|
|
213
|
+
Object.defineProperty(this, "type", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
configurable: true,
|
|
216
|
+
writable: true,
|
|
217
|
+
value: 'model'
|
|
218
|
+
});
|
|
219
|
+
Object.defineProperty(this, "refName", {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
configurable: true,
|
|
222
|
+
writable: true,
|
|
223
|
+
value: void 0
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(this, "ref", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
configurable: true,
|
|
228
|
+
writable: true,
|
|
229
|
+
value: void 0
|
|
230
|
+
});
|
|
231
|
+
Object.defineProperty(this, "trail", {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
configurable: true,
|
|
234
|
+
writable: true,
|
|
235
|
+
value: void 0
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(this, "enrichmentPath", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: true,
|
|
240
|
+
writable: true,
|
|
241
|
+
value: void 0
|
|
242
|
+
});
|
|
243
|
+
Object.defineProperty(this, "label", {
|
|
244
|
+
enumerable: true,
|
|
245
|
+
configurable: true,
|
|
246
|
+
writable: true,
|
|
247
|
+
value: void 0
|
|
248
|
+
});
|
|
249
|
+
this.refName = ref.refName;
|
|
250
|
+
this.ref = ref;
|
|
251
|
+
const key = toModelKey(ref);
|
|
252
|
+
this.trail = key;
|
|
253
|
+
this.enrichmentPath = [key];
|
|
254
|
+
this.label = key;
|
|
255
|
+
}
|
|
256
|
+
isSupported({ entry, context, variant }) {
|
|
257
|
+
return (typeof entry.isSupported !== 'function' ||
|
|
258
|
+
entry.isSupported({ ref: this.ref, context, variant }));
|
|
259
|
+
}
|
|
260
|
+
matches(filter, variant) {
|
|
261
|
+
return matchesRefFilter({ refs: filter, refName: this.refName, variant });
|
|
262
|
+
}
|
|
263
|
+
transform({ entry, context, variant }) {
|
|
264
|
+
entry.transform({ context, ref: this.ref, variant });
|
|
265
|
+
}
|
|
266
|
+
toPreviewModule({ entry, context, variant }) {
|
|
267
|
+
return entry.toPreviewModule?.({ context, ref: this.ref, variant });
|
|
268
|
+
}
|
|
269
|
+
toExportPath({ projection, context, variant }) {
|
|
270
|
+
if (projection.type !== 'model') {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
const enrichments = projection.toEnrichments({ ref: this.ref, context, variant });
|
|
274
|
+
return projection.toExportPath({ ref: this.ref, enrichments, variant });
|
|
275
|
+
}
|
|
276
|
+
toNamedModels() {
|
|
277
|
+
return [toModelKey(this.ref)];
|
|
278
|
+
}
|
|
279
|
+
toSource({ generatorId, variant }) {
|
|
280
|
+
return toModelSource({ refName: this.refName, generatorId, variant });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Match a `(path, method, variant)` tuple against an operation-shaped
|
|
285
|
+
* skip or include entry. Shared by both arms because skip and include
|
|
286
|
+
* have the same matching rules; only the engine's interpretation of
|
|
287
|
+
* the result differs (skip = deny, include = allow).
|
|
288
|
+
*
|
|
289
|
+
* Returns `false` when:
|
|
290
|
+
* - `paths` is `undefined` (no filter applies)
|
|
291
|
+
* - the `path` isn't keyed in the entry
|
|
292
|
+
* - the `method` isn't present in the inner record
|
|
293
|
+
*
|
|
294
|
+
* Returns `true` when:
|
|
295
|
+
* - the method's variant array is empty (matches every variant)
|
|
296
|
+
* - the method's variant array contains `variant`
|
|
297
|
+
*/
|
|
298
|
+
const matchesPathFilter = ({ paths, path, method, variant }) => {
|
|
299
|
+
if (!paths) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
const methodMap = paths[path];
|
|
303
|
+
if (!methodMap) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
const variants = methodMap[method];
|
|
307
|
+
if (variants === undefined) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (variants.length === 0) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
return variants.includes(variant);
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Match a `(refName, variant)` tuple against a model-shaped skip or
|
|
317
|
+
* include entry. Sibling to {@link matchesPathFilter} — both arms
|
|
318
|
+
* share matching rules; only the engine's interpretation of the
|
|
319
|
+
* result differs (skip = deny, include = allow).
|
|
320
|
+
*
|
|
321
|
+
* Returns `false` when:
|
|
322
|
+
* - `refs` is `undefined` (no filter applies)
|
|
323
|
+
* - the `refName` isn't keyed in the entry
|
|
324
|
+
*
|
|
325
|
+
* Returns `true` when:
|
|
326
|
+
* - the refName's variant array is empty (matches every variant)
|
|
327
|
+
* - the refName's variant array contains `variant`
|
|
328
|
+
*/
|
|
329
|
+
const matchesRefFilter = ({ refs, refName, variant }) => {
|
|
330
|
+
if (!refs) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
const variants = refs[refName];
|
|
334
|
+
if (variants === undefined) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
if (variants.length === 0) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
return variants.includes(variant);
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Creates an OasOperationSource from an operation, generator ID, and variant.
|
|
344
|
+
*
|
|
345
|
+
* Transforms operation and generator information into a source descriptor
|
|
346
|
+
* that can be used for tracking operation origins in the generation pipeline.
|
|
347
|
+
*
|
|
348
|
+
* @param args - Arguments containing operation, generator ID, and variant
|
|
349
|
+
* @returns OasOperationSource descriptor for the operation
|
|
350
|
+
*/
|
|
351
|
+
export const toOasOperationSource = ({ operation, generatorId, variant }) => ({
|
|
352
|
+
type: 'oasOperation',
|
|
353
|
+
generatorId,
|
|
354
|
+
operationPath: operation.path,
|
|
355
|
+
operationMethod: operation.method,
|
|
356
|
+
variant
|
|
357
|
+
});
|
|
358
|
+
/**
|
|
359
|
+
* Creates a {@link WebhookSource} from a webhook, generator ID, and variant.
|
|
360
|
+
* Sibling of {@link toOasOperationSource} for the 3.1 webhook subject.
|
|
361
|
+
*/
|
|
362
|
+
export const toWebhookSource = ({ webhook, generatorId, variant }) => ({
|
|
363
|
+
type: 'webhook',
|
|
364
|
+
generatorId,
|
|
365
|
+
webhookName: webhook.name,
|
|
366
|
+
webhookMethod: webhook.method,
|
|
367
|
+
variant
|
|
368
|
+
});
|
|
369
|
+
/**
|
|
370
|
+
* Creates a GraphQL operation source descriptor.
|
|
371
|
+
*
|
|
372
|
+
* Sibling to {@link toOasOperationSource} for the GraphQL protocol — encodes
|
|
373
|
+
* `rootKind` and `fieldName` instead of `path` / `method`.
|
|
374
|
+
*/
|
|
375
|
+
export const toGqlOperationSource = ({ operation, generatorId, variant }) => ({
|
|
376
|
+
type: 'gqlOperation',
|
|
377
|
+
generatorId,
|
|
378
|
+
rootKind: operation.rootKind,
|
|
379
|
+
fieldName: operation.fieldName,
|
|
380
|
+
variant
|
|
381
|
+
});
|
|
382
|
+
/**
|
|
383
|
+
* Creates a ModelSource from a reference name, generator ID, and variant.
|
|
384
|
+
*
|
|
385
|
+
* Transforms model reference and generator information into a source descriptor
|
|
386
|
+
* that can be used for tracking model origins in the generation pipeline.
|
|
387
|
+
*
|
|
388
|
+
* @param args - Arguments containing reference name, generator ID, and variant
|
|
389
|
+
* @returns ModelSource descriptor for the model
|
|
390
|
+
*/
|
|
391
|
+
export const toModelSource = ({ refName, generatorId, variant }) => ({
|
|
392
|
+
type: 'model',
|
|
393
|
+
generatorId,
|
|
394
|
+
refName,
|
|
395
|
+
variant
|
|
396
|
+
});
|
|
@@ -50,6 +50,13 @@ type FinalizeArgs = {
|
|
|
50
50
|
};
|
|
51
51
|
export declare class EnrichmentAudit {
|
|
52
52
|
#private;
|
|
53
|
+
/**
|
|
54
|
+
* Runs `fn` with nothing recorded: no lookup counts as a use, and no
|
|
55
|
+
* warning is kept. For a reader that is not the run, such as the file
|
|
56
|
+
* plan: it reads enrichments for projections the run may never insert,
|
|
57
|
+
* and those reads must not make configured paths look used.
|
|
58
|
+
*/
|
|
59
|
+
withoutRecording<T>(fn: () => T): T;
|
|
53
60
|
/**
|
|
54
61
|
* Record one enrichment lookup. Every prefix of `segments` is marked
|
|
55
62
|
* consumed, so block-level and leaf-level reads land in one namespace.
|