@skmtc/core 0.54.1 → 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.
@@ -0,0 +1,56 @@
1
+ import type { GenerateContextType } from './generateTypes.js';
2
+ import { type PlannedSubject } from './Subject.js';
3
+ import type { DeclaredProjection } from '../dsl/DeclaredProjection.js';
4
+ import type { WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
5
+ import type { Reach } from '../parse/Reach.js';
6
+ type FilePlanArgs = {
7
+ context: GenerateContextType;
8
+ /** Every subject of the run, of each kind. */
9
+ subjects: readonly PlannedSubject[];
10
+ /** The projection classes the entries of the run declared, each one time. */
11
+ projections: readonly DeclaredProjection[];
12
+ reach: Reach;
13
+ /** Makes an export path a projection gives into the path of a file of the run. */
14
+ toFilePath: (exportPath: string, generatorId: string) => WorkspacePath;
15
+ };
16
+ /**
17
+ * Which subjects of a run hold each file, known before the run from what the
18
+ * entries declared. A subject holds a file when it can write to it or read
19
+ * from it:
20
+ *
21
+ * - a declared projection of the subject's kind maps the subject to the file;
22
+ * - the file is one that a declared model projection maps a model to, and
23
+ * the subject names that model or a model that reaches it.
24
+ *
25
+ * When the last subject that holds a file has run, the file is complete.
26
+ * {@link finish} gives those files.
27
+ *
28
+ * The plan may hold a file for longer than the run needs it: a reach can
29
+ * have a model no generator gets to. It never knows a file that no declared
30
+ * projection maps a subject to, so such a file is never given by `finish`.
31
+ *
32
+ * Many subjects name one model, so the plan counts in two steps: the
33
+ * subjects left that name a model, and for a file, its own subjects left
34
+ * plus the named models left that reach it. A model's reach is then read
35
+ * one time, not one time for each subject that names the model.
36
+ */
37
+ export declare class FilePlan {
38
+ #private;
39
+ /**
40
+ * How many times a projection could not say where a subject's file is: a
41
+ * static threw, or the subject's enrichments have variants and no `main`.
42
+ * The run reports such a fault where it happens. The plan leaves the file out.
43
+ */
44
+ unanswered: number;
45
+ constructor({ context, subjects, projections, reach, toFilePath }: FilePlanArgs);
46
+ /** Whether the plan knows the file at `path`. */
47
+ has(path: WorkspacePath): boolean;
48
+ /** The files `subject` holds, while it is left to run. */
49
+ filesOf(subject: PlannedSubject): WorkspacePath[];
50
+ /**
51
+ * `subject` has run. Gives the files that no subject left to run holds:
52
+ * nothing writes to them or reads from them after this.
53
+ */
54
+ finish(subject: PlannedSubject): WorkspacePath[];
55
+ }
56
+ export {};
@@ -0,0 +1,188 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _FilePlan_instances, _FilePlan_context, _FilePlan_projections, _FilePlan_toFilePath, _FilePlan_paths, _FilePlan_indexes, _FilePlan_left, _FilePlan_held, _FilePlan_namedLeft, _FilePlan_filesBehind, _FilePlan_modelFiles, _FilePlan_toFilesBehind, _FilePlan_toModelFiles, _FilePlan_toFiles, _FilePlan_toVariants, _FilePlan_toIndex;
13
+ import { ModelSubject } from './Subject.js';
14
+ import { fromModelKey } from '../helpers/refFns.js';
15
+ import { toVariantList } from '../helpers/toVariantList.js';
16
+ /**
17
+ * Which subjects of a run hold each file, known before the run from what the
18
+ * entries declared. A subject holds a file when it can write to it or read
19
+ * from it:
20
+ *
21
+ * - a declared projection of the subject's kind maps the subject to the file;
22
+ * - the file is one that a declared model projection maps a model to, and
23
+ * the subject names that model or a model that reaches it.
24
+ *
25
+ * When the last subject that holds a file has run, the file is complete.
26
+ * {@link finish} gives those files.
27
+ *
28
+ * The plan may hold a file for longer than the run needs it: a reach can
29
+ * have a model no generator gets to. It never knows a file that no declared
30
+ * projection maps a subject to, so such a file is never given by `finish`.
31
+ *
32
+ * Many subjects name one model, so the plan counts in two steps: the
33
+ * subjects left that name a model, and for a file, its own subjects left
34
+ * plus the named models left that reach it. A model's reach is then read
35
+ * one time, not one time for each subject that names the model.
36
+ */
37
+ export class FilePlan {
38
+ constructor({ context, subjects, projections, reach, toFilePath }) {
39
+ _FilePlan_instances.add(this);
40
+ _FilePlan_context.set(this, void 0);
41
+ /** The declared projections, by the kind of subject they take. */
42
+ _FilePlan_projections.set(this, void 0);
43
+ _FilePlan_toFilePath.set(this, void 0);
44
+ _FilePlan_paths.set(this, []);
45
+ _FilePlan_indexes.set(this, new Map()
46
+ /** By a file's index: the holds on it by subjects left to run, plus the named models left that reach it. */
47
+ );
48
+ /** By a file's index: the holds on it by subjects left to run, plus the named models left that reach it. */
49
+ _FilePlan_left.set(this, []);
50
+ _FilePlan_held.set(this, new Map()
51
+ /** By a model's key: how many subjects that name it are left to run. */
52
+ );
53
+ /** By a model's key: how many subjects that name it are left to run. */
54
+ _FilePlan_namedLeft.set(this, new Map()
55
+ /** By a named model's key: the indexes of the files of every model it reaches, its own included. */
56
+ );
57
+ /** By a named model's key: the indexes of the files of every model it reaches, its own included. */
58
+ _FilePlan_filesBehind.set(this, new Map()
59
+ /** By a model's key: the indexes of the files the declared model projections map it to. */
60
+ );
61
+ /** By a model's key: the indexes of the files the declared model projections map it to. */
62
+ _FilePlan_modelFiles.set(this, new Map()
63
+ /**
64
+ * How many times a projection could not say where a subject's file is: a
65
+ * static threw, or the subject's enrichments have variants and no `main`.
66
+ * The run reports such a fault where it happens. The plan leaves the file out.
67
+ */
68
+ );
69
+ /**
70
+ * How many times a projection could not say where a subject's file is: a
71
+ * static threw, or the subject's enrichments have variants and no `main`.
72
+ * The run reports such a fault where it happens. The plan leaves the file out.
73
+ */
74
+ Object.defineProperty(this, "unanswered", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: 0
79
+ });
80
+ __classPrivateFieldSet(this, _FilePlan_context, context, "f");
81
+ __classPrivateFieldSet(this, _FilePlan_projections, Map.groupBy(projections, projection => projection.type), "f");
82
+ __classPrivateFieldSet(this, _FilePlan_toFilePath, toFilePath, "f");
83
+ subjects.forEach(subject => {
84
+ // A model names itself, so its own files are among the files behind
85
+ // its key; asking for them here too would answer each projection twice.
86
+ const files = subject.type === 'model' ? [] : __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFiles).call(this, subject);
87
+ const models = subject.toNamedModels(reach);
88
+ files.forEach(file => {
89
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] += 1;
90
+ });
91
+ models.forEach(key => {
92
+ const namedLeft = __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").get(key) ?? 0;
93
+ if (namedLeft === 0) {
94
+ __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFilesBehind).call(this, key, reach).forEach(file => {
95
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] += 1;
96
+ });
97
+ }
98
+ __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").set(key, namedLeft + 1);
99
+ });
100
+ __classPrivateFieldGet(this, _FilePlan_held, "f").set(subject, { files, models });
101
+ });
102
+ }
103
+ /** Whether the plan knows the file at `path`. */
104
+ has(path) {
105
+ return __classPrivateFieldGet(this, _FilePlan_indexes, "f").has(path);
106
+ }
107
+ /** The files `subject` holds, while it is left to run. */
108
+ filesOf(subject) {
109
+ const held = __classPrivateFieldGet(this, _FilePlan_held, "f").get(subject);
110
+ if (held === undefined) {
111
+ return [];
112
+ }
113
+ const behind = held.models.flatMap(key => __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key) ?? []);
114
+ return [...new Set([...held.files, ...behind])].map(file => __classPrivateFieldGet(this, _FilePlan_paths, "f")[file]);
115
+ }
116
+ /**
117
+ * `subject` has run. Gives the files that no subject left to run holds:
118
+ * nothing writes to them or reads from them after this.
119
+ */
120
+ finish(subject) {
121
+ const held = __classPrivateFieldGet(this, _FilePlan_held, "f").get(subject);
122
+ if (held === undefined) {
123
+ return [];
124
+ }
125
+ __classPrivateFieldGet(this, _FilePlan_held, "f").delete(subject);
126
+ const released = held.models.flatMap(key => {
127
+ const namedLeft = (__classPrivateFieldGet(this, _FilePlan_namedLeft, "f").get(key) ?? 0) - 1;
128
+ __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").set(key, namedLeft);
129
+ return namedLeft === 0 ? (__classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key) ?? []) : [];
130
+ });
131
+ return [...held.files, ...released].flatMap(file => {
132
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] -= 1;
133
+ return __classPrivateFieldGet(this, _FilePlan_left, "f")[file] === 0 ? [__classPrivateFieldGet(this, _FilePlan_paths, "f")[file]] : [];
134
+ });
135
+ }
136
+ }
137
+ _FilePlan_context = new WeakMap(), _FilePlan_projections = new WeakMap(), _FilePlan_toFilePath = new WeakMap(), _FilePlan_paths = new WeakMap(), _FilePlan_indexes = new WeakMap(), _FilePlan_left = new WeakMap(), _FilePlan_held = new WeakMap(), _FilePlan_namedLeft = new WeakMap(), _FilePlan_filesBehind = new WeakMap(), _FilePlan_modelFiles = new WeakMap(), _FilePlan_instances = new WeakSet(), _FilePlan_toFilesBehind = function _FilePlan_toFilesBehind(key, reach) {
138
+ const found = __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key);
139
+ if (found !== undefined) {
140
+ return found;
141
+ }
142
+ const reached = [...reach.ofModel(fromModelKey(key))];
143
+ const files = [...new Set(reached.flatMap(model => __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toModelFiles).call(this, model)))];
144
+ __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").set(key, files);
145
+ return files;
146
+ }, _FilePlan_toModelFiles = function _FilePlan_toModelFiles(key) {
147
+ const found = __classPrivateFieldGet(this, _FilePlan_modelFiles, "f").get(key);
148
+ if (found !== undefined) {
149
+ return found;
150
+ }
151
+ const files = __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFiles).call(this, new ModelSubject(fromModelKey(key)));
152
+ __classPrivateFieldGet(this, _FilePlan_modelFiles, "f").set(key, files);
153
+ return files;
154
+ }, _FilePlan_toFiles = function _FilePlan_toFiles(subject) {
155
+ const projections = __classPrivateFieldGet(this, _FilePlan_projections, "f").get(subject.type) ?? [];
156
+ return projections.flatMap(projection => __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toVariants).call(this, subject, projection).flatMap(variant => {
157
+ try {
158
+ const exportPath = subject.toExportPath({ projection, context: __classPrivateFieldGet(this, _FilePlan_context, "f"), variant });
159
+ return exportPath === undefined ? [] : [__classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toIndex).call(this, __classPrivateFieldGet(this, _FilePlan_toFilePath, "f").call(this, exportPath, projection.id))];
160
+ }
161
+ catch {
162
+ this.unanswered += 1;
163
+ return [];
164
+ }
165
+ }));
166
+ }, _FilePlan_toVariants = function _FilePlan_toVariants(subject, projection) {
167
+ try {
168
+ return toVariantList({
169
+ opEnrichments: __classPrivateFieldGet(this, _FilePlan_context, "f").readEnrichment([projection.id, ...subject.enrichmentPath]),
170
+ generatorId: projection.id,
171
+ operationLabel: subject.label
172
+ });
173
+ }
174
+ catch {
175
+ this.unanswered += 1;
176
+ return [];
177
+ }
178
+ }, _FilePlan_toIndex = function _FilePlan_toIndex(path) {
179
+ const found = __classPrivateFieldGet(this, _FilePlan_indexes, "f").get(path);
180
+ if (found !== undefined) {
181
+ return found;
182
+ }
183
+ const index = __classPrivateFieldGet(this, _FilePlan_paths, "f").length;
184
+ __classPrivateFieldGet(this, _FilePlan_paths, "f").push(path);
185
+ __classPrivateFieldGet(this, _FilePlan_left, "f").push(0);
186
+ __classPrivateFieldGet(this, _FilePlan_indexes, "f").set(path, index);
187
+ return index;
188
+ };
@@ -14,6 +14,9 @@ import type { OasOperation } from '../oas/operation/Operation.js';
14
14
  import { type ProjectionOptionsRest } from '../types/ProjectionOptions.js';
15
15
  import type { GeneratedValue } from '../dsl/GeneratedValue.js';
16
16
  import { ContentSettings } from '../dsl/ContentSettings.js';
17
+ import { type PlannedSubject } from './Subject.js';
18
+ import { FilePlan } from './FilePlan.js';
19
+ import type { Reach } from '../parse/Reach.js';
17
20
  export { toGqlOperationSource, toModelSource, toOasOperationSource, toWebhookSource } from './Subject.js';
18
21
  import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
19
22
  import type { Logger } from '../types/Logger.js';
@@ -54,6 +57,11 @@ type ConstructorArgs = {
54
57
  */
55
58
  logsGeneratorLines?: boolean;
56
59
  };
60
+ type ToFilePlanArgs = {
61
+ /** The subjects of the run, of each kind. */
62
+ subjects: readonly PlannedSubject[];
63
+ reach: Reach;
64
+ };
57
65
  /**
58
66
  * Arguments for applying package imports to a generated file.
59
67
  *
@@ -197,6 +205,16 @@ export declare class GenerateContext implements GenerateContextType {
197
205
  * @internal
198
206
  */
199
207
  toArtifacts(stackTrail: StackTrail): GenerateResult;
208
+ /**
209
+ * @internal
210
+ * The file plan of a run of this context: which of `subjects` hold each
211
+ * file, from the projection classes that the entries of the run declared.
212
+ * An entry that declared none adds no file to the plan, and a generator
213
+ * that `settings.skip` names whole adds none either, and a GraphQL
214
+ * document's plan knows no file. Building the plan
215
+ * leaves the run as it is: its reads of enrichments are not recorded.
216
+ */
217
+ toFilePlan({ subjects, reach }: ToFilePlanArgs): FilePlan;
200
218
  /**
201
219
  * Evaluate each generator's `isSupported` over the parsed document's subjects
202
220
  * and report the subjects each generator supports — capability only, no
@@ -26,6 +26,7 @@ import { ContentSettings } from '../dsl/ContentSettings.js';
26
26
  import { DEFAULT_VARIANT } from '../types/Variant.js';
27
27
  import { toVariantList } from '../helpers/toVariantList.js';
28
28
  import { GqlOperationSubject, ModelSubject, OasOperationSubject, WebhookSubject } from './Subject.js';
29
+ import { FilePlan } from './FilePlan.js';
29
30
  export { toGqlOperationSource, toModelSource, toOasOperationSource, toWebhookSource } from './Subject.js';
30
31
  import get from 'lodash-es/get.js';
31
32
  import { Inserted } from '../dsl/Inserted.js';
@@ -296,6 +297,32 @@ export class GenerateContext {
296
297
  enrichmentWarnings
297
298
  };
298
299
  }
300
+ /**
301
+ * @internal
302
+ * The file plan of a run of this context: which of `subjects` hold each
303
+ * file, from the projection classes that the entries of the run declared.
304
+ * An entry that declared none adds no file to the plan, and a generator
305
+ * that `settings.skip` names whole adds none either, and a GraphQL
306
+ * document's plan knows no file. Building the plan
307
+ * leaves the run as it is: its reads of enrichments are not recorded.
308
+ */
309
+ toFilePlan({ subjects, reach }) {
310
+ const skipped = this.settings?.skip ?? [];
311
+ const generators = Object.values(this.toGeneratorConfigMap());
312
+ // A GraphQL document has no reach (`toReach` reads only OpenAPI refs), so
313
+ // no subject would hold the files of the models it reaches. Its plan
314
+ // knows no file, and each file stays to the end.
315
+ const projections = this.document.type === 'gql'
316
+ ? []
317
+ : generators.filter(({ id }) => !skipped.includes(id)).flatMap(generator => generator.projections ?? []);
318
+ return __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").withoutRecording(() => new FilePlan({
319
+ context: this,
320
+ subjects,
321
+ projections: [...new Set(projections)],
322
+ reach,
323
+ toFilePath: (exportPath, generatorId) => __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, exportPath, generatorId)
324
+ }));
325
+ }
299
326
  /**
300
327
  * Evaluate each generator's `isSupported` over the parsed document's subjects
301
328
  * and report the subjects each generator supports — capability only, no
@@ -987,7 +1014,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
987
1014
  __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, this.document.value.operations.map(operation => new GqlOperationSubject(operation)), { include: undefined, skip: undefined }, st);
988
1015
  break;
989
1016
  case 'model':
990
- __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).map(refName => new ModelSubject(refName)), {
1017
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).map(refName => new ModelSubject(toSchemaComponentRef(refName))), {
991
1018
  include: toIncludeModels(include, generatorConfig.id),
992
1019
  skip: toSkipModels(skip, generatorConfig.id)
993
1020
  }, st);
@@ -6,6 +6,8 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
6
6
  import type { OasOperation } from '../oas/operation/Operation.js';
7
7
  import type { OasWebhook } from '../oas/webhook/Webhook.js';
8
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';
9
11
  import { type RefParts } from '../helpers/refFns.js';
10
12
  import type { RefName } from '../types/RefName.js';
11
13
  import type { IncludeModelRefs, IncludePaths, SkipModelRefs, SkipPaths } from '../types/Settings.js';
@@ -20,6 +22,34 @@ type ToSourceArgs = {
20
22
  generatorId: string;
21
23
  variant: string;
22
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
+ };
23
53
  /**
24
54
  * One subject of a run: an OpenAPI operation, a webhook, a GraphQL operation
25
55
  * or a model. For the run, it holds how its kind differs from the others:
@@ -31,13 +61,9 @@ type ToSourceArgs = {
31
61
  * @template Filter - One generator's `settings.include` or `settings.skip`
32
62
  * filter for the kind; `never` for a kind that has none
33
63
  */
34
- export type Subject<Entry, Filter> = {
64
+ export type Subject<Entry, Filter> = PlannedSubject & {
35
65
  /** Its frame or frames below the generator's in a trail, and so its place in `manifest.results`. */
36
66
  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
67
  isSupported: (args: AskArgs<Entry>) => boolean;
42
68
  /** Whether a filter of `settings.include` or `settings.skip` names this variant of it. */
43
69
  matches(filter: Filter | undefined, variant: string): boolean;
@@ -47,6 +73,7 @@ export type Subject<Entry, Filter> = {
47
73
  };
48
74
  /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
49
75
  export declare class OasOperationSubject implements Subject<OasOperationEntry, IncludePaths | SkipPaths> {
76
+ readonly type = "oasOperation";
50
77
  operation: OasOperation;
51
78
  trail: string[];
52
79
  enrichmentPath: string[];
@@ -56,6 +83,8 @@ export declare class OasOperationSubject implements Subject<OasOperationEntry, I
56
83
  matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
57
84
  transform({ entry, context, variant }: AskArgs<OasOperationEntry>): void;
58
85
  toPreviewModule({ entry, context, variant }: AskArgs<OasOperationEntry>): PreviewModule | undefined;
86
+ toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
87
+ toNamedModels(reach: Reach): readonly string[];
59
88
  toSource({ generatorId, variant }: ToSourceArgs): OasOperationSource;
60
89
  }
61
90
  /**
@@ -64,6 +93,7 @@ export declare class OasOperationSubject implements Subject<OasOperationEntry, I
64
93
  * operation's, with the webhook's name in the place of the path.
65
94
  */
66
95
  export declare class WebhookSubject implements Subject<WebhookEntry, IncludePaths | SkipPaths> {
96
+ readonly type = "webhook";
67
97
  webhook: OasWebhook;
68
98
  trail: string[];
69
99
  enrichmentPath: string[];
@@ -73,6 +103,8 @@ export declare class WebhookSubject implements Subject<WebhookEntry, IncludePath
73
103
  matches(filter: IncludePaths | SkipPaths | undefined, variant: string): boolean;
74
104
  transform({ entry, context, variant }: AskArgs<WebhookEntry>): void;
75
105
  toPreviewModule({ entry, context, variant }: AskArgs<WebhookEntry>): PreviewModule | undefined;
106
+ toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
107
+ toNamedModels(reach: Reach): readonly string[];
76
108
  toSource({ generatorId, variant }: ToSourceArgs): WebhookSource;
77
109
  }
78
110
  /**
@@ -81,6 +113,7 @@ export declare class WebhookSubject implements Subject<WebhookEntry, IncludePath
81
113
  * filter for a GraphQL operation, so no filter names it.
82
114
  */
83
115
  export declare class GqlOperationSubject implements Subject<GqlOperationEntry, never> {
116
+ readonly type = "gqlOperation";
84
117
  operation: GqlOperation;
85
118
  trail: string[];
86
119
  enrichmentPath: string[];
@@ -90,20 +123,31 @@ export declare class GqlOperationSubject implements Subject<GqlOperationEntry, n
90
123
  matches(): boolean;
91
124
  transform({ entry, context, variant }: AskArgs<GqlOperationEntry>): void;
92
125
  toPreviewModule({ entry, context, variant }: AskArgs<GqlOperationEntry>): PreviewModule | undefined;
126
+ toExportPath(): undefined;
127
+ toNamedModels(): readonly string[];
93
128
  toSource({ generatorId, variant }: ToSourceArgs): GqlOperationSource;
94
129
  }
95
- /** A model as a subject: a schema component of either protocol. Its results and enrichments are at `[refName]`. */
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
+ */
96
137
  export declare class ModelSubject implements Subject<ModelEntry, IncludeModelRefs | SkipModelRefs> {
138
+ readonly type = "model";
97
139
  refName: RefName;
98
140
  ref: RefParts;
99
141
  trail: string;
100
142
  enrichmentPath: string[];
101
143
  label: string;
102
- constructor(refName: RefName);
144
+ constructor(ref: RefParts);
103
145
  isSupported({ entry, context, variant }: AskArgs<ModelEntry>): boolean;
104
146
  matches(filter: IncludeModelRefs | SkipModelRefs | undefined, variant: string): boolean;
105
147
  transform({ entry, context, variant }: AskArgs<ModelEntry>): void;
106
148
  toPreviewModule({ entry, context, variant }: AskArgs<ModelEntry>): PreviewModule | undefined;
149
+ toExportPath({ projection, context, variant }: ToExportPathArgs): string | undefined;
150
+ toNamedModels(): readonly string[];
107
151
  toSource({ generatorId, variant }: ToSourceArgs): ModelSource;
108
152
  }
109
153
  type ToOasOperationSourceArgs = {
@@ -1,7 +1,13 @@
1
- import { toSchemaComponentRef } from '../helpers/refFns.js';
1
+ import { toModelKey } from '../helpers/refFns.js';
2
2
  /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
3
3
  export class OasOperationSubject {
4
4
  constructor(operation) {
5
+ Object.defineProperty(this, "type", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: 'oasOperation'
10
+ });
5
11
  Object.defineProperty(this, "operation", {
6
12
  enumerable: true,
7
13
  configurable: true,
@@ -45,6 +51,16 @@ export class OasOperationSubject {
45
51
  toPreviewModule({ entry, context, variant }) {
46
52
  return entry.toPreviewModule?.({ context, operation: this.operation, variant });
47
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
+ }
48
64
  toSource({ generatorId, variant }) {
49
65
  return toOasOperationSource({ operation: this.operation, generatorId, variant });
50
66
  }
@@ -56,6 +72,12 @@ export class OasOperationSubject {
56
72
  */
57
73
  export class WebhookSubject {
58
74
  constructor(webhook) {
75
+ Object.defineProperty(this, "type", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: 'webhook'
80
+ });
59
81
  Object.defineProperty(this, "webhook", {
60
82
  enumerable: true,
61
83
  configurable: true,
@@ -99,6 +121,16 @@ export class WebhookSubject {
99
121
  toPreviewModule({ entry, context, variant }) {
100
122
  return entry.toPreviewModule?.({ context, webhook: this.webhook, variant });
101
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
+ }
102
134
  toSource({ generatorId, variant }) {
103
135
  return toWebhookSource({ webhook: this.webhook, generatorId, variant });
104
136
  }
@@ -110,6 +142,12 @@ export class WebhookSubject {
110
142
  */
111
143
  export class GqlOperationSubject {
112
144
  constructor(operation) {
145
+ Object.defineProperty(this, "type", {
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true,
149
+ value: 'gqlOperation'
150
+ });
113
151
  Object.defineProperty(this, "operation", {
114
152
  enumerable: true,
115
153
  configurable: true,
@@ -152,13 +190,32 @@ export class GqlOperationSubject {
152
190
  toPreviewModule({ entry, context, variant }) {
153
191
  return entry.toPreviewModule?.({ context, operation: this.operation, variant });
154
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
+ }
155
200
  toSource({ generatorId, variant }) {
156
201
  return toGqlOperationSource({ operation: this.operation, generatorId, variant });
157
202
  }
158
203
  }
159
- /** A model as a subject: a schema component of either protocol. Its results and enrichments are at `[refName]`. */
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
+ */
160
211
  export class ModelSubject {
161
- constructor(refName) {
212
+ constructor(ref) {
213
+ Object.defineProperty(this, "type", {
214
+ enumerable: true,
215
+ configurable: true,
216
+ writable: true,
217
+ value: 'model'
218
+ });
162
219
  Object.defineProperty(this, "refName", {
163
220
  enumerable: true,
164
221
  configurable: true,
@@ -189,11 +246,12 @@ export class ModelSubject {
189
246
  writable: true,
190
247
  value: void 0
191
248
  });
192
- this.refName = refName;
193
- this.ref = toSchemaComponentRef(refName);
194
- this.trail = refName;
195
- this.enrichmentPath = [refName];
196
- this.label = refName;
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;
197
255
  }
198
256
  isSupported({ entry, context, variant }) {
199
257
  return (typeof entry.isSupported !== 'function' ||
@@ -208,6 +266,16 @@ export class ModelSubject {
208
266
  toPreviewModule({ entry, context, variant }) {
209
267
  return entry.toPreviewModule?.({ context, ref: this.ref, variant });
210
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
+ }
211
279
  toSource({ generatorId, variant }) {
212
280
  return toModelSource({ refName: this.refName, generatorId, variant });
213
281
  }
@@ -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.