@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.
@@ -31,7 +31,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
31
31
  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");
32
32
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
33
33
  };
34
- var _EnrichmentAudit_instances, _EnrichmentAudit_consumed, _EnrichmentAudit_children, _EnrichmentAudit_warnings, _EnrichmentAudit_reported, _EnrichmentAudit_isConsumed, _EnrichmentAudit_divergenceSuggestion, _EnrichmentAudit_checkBlock;
34
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
35
+ if (kind === "m") throw new TypeError("Private method is not writable");
36
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
+ 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");
38
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
+ };
40
+ var _EnrichmentAudit_instances, _EnrichmentAudit_consumed, _EnrichmentAudit_children, _EnrichmentAudit_warnings, _EnrichmentAudit_reported, _EnrichmentAudit_records, _EnrichmentAudit_isConsumed, _EnrichmentAudit_divergenceSuggestion, _EnrichmentAudit_checkBlock;
35
41
  import { STACK_ENRICHMENT_KEY, isReservedEnrichmentKey } from '../types/Enrichments.js';
36
42
  import { formatEnrichmentPath } from './EnrichmentWarning.js';
37
43
  import { nearestKey } from '../helpers/nearestKey.js';
@@ -51,17 +57,41 @@ export class EnrichmentAudit {
51
57
  );
52
58
  /** Identity keys of reported warnings — reads repeat, warnings must not. */
53
59
  _EnrichmentAudit_reported.set(this, new Set()
60
+ /** `false` inside {@link withoutRecording}. */
61
+ );
62
+ /** `false` inside {@link withoutRecording}. */
63
+ _EnrichmentAudit_records.set(this, true
54
64
  /**
55
- * Record one enrichment lookup. Every prefix of `segments` is marked
56
- * consumed, so block-level and leaf-level reads land in one namespace.
65
+ * Runs `fn` with nothing recorded: no lookup counts as a use, and no
66
+ * warning is kept. For a reader that is not the run, such as the file
67
+ * plan: it reads enrichments for projections the run may never insert,
68
+ * and those reads must not make configured paths look used.
57
69
  */
58
70
  );
59
71
  }
72
+ /**
73
+ * Runs `fn` with nothing recorded: no lookup counts as a use, and no
74
+ * warning is kept. For a reader that is not the run, such as the file
75
+ * plan: it reads enrichments for projections the run may never insert,
76
+ * and those reads must not make configured paths look used.
77
+ */
78
+ withoutRecording(fn) {
79
+ const records = __classPrivateFieldGet(this, _EnrichmentAudit_records, "f");
80
+ __classPrivateFieldSet(this, _EnrichmentAudit_records, false, "f");
81
+ try {
82
+ return fn();
83
+ }
84
+ finally {
85
+ __classPrivateFieldSet(this, _EnrichmentAudit_records, records, "f");
86
+ }
87
+ }
60
88
  /**
61
89
  * Record one enrichment lookup. Every prefix of `segments` is marked
62
90
  * consumed, so block-level and leaf-level reads land in one namespace.
63
91
  */
64
92
  consume(segments) {
93
+ if (!__classPrivateFieldGet(this, _EnrichmentAudit_records, "f"))
94
+ return;
65
95
  let parentKey = toPathKey([]);
66
96
  for (let end = 1; end <= segments.length; end++) {
67
97
  const key = toPathKey(segments.slice(0, end));
@@ -82,6 +112,8 @@ export class EnrichmentAudit {
82
112
  * warning.
83
113
  */
84
114
  report(warning) {
115
+ if (!__classPrivateFieldGet(this, _EnrichmentAudit_records, "f"))
116
+ return;
85
117
  const key = toPathKey([warning.type, ...warning.path]);
86
118
  if (__classPrivateFieldGet(this, _EnrichmentAudit_reported, "f").has(key))
87
119
  return;
@@ -177,7 +209,7 @@ export class EnrichmentAudit {
177
209
  return [...__classPrivateFieldGet(this, _EnrichmentAudit_warnings, "f")];
178
210
  }
179
211
  }
180
- _EnrichmentAudit_consumed = new WeakMap(), _EnrichmentAudit_children = new WeakMap(), _EnrichmentAudit_warnings = new WeakMap(), _EnrichmentAudit_reported = new WeakMap(), _EnrichmentAudit_instances = new WeakSet(), _EnrichmentAudit_isConsumed = function _EnrichmentAudit_isConsumed(segments) {
212
+ _EnrichmentAudit_consumed = new WeakMap(), _EnrichmentAudit_children = new WeakMap(), _EnrichmentAudit_warnings = new WeakMap(), _EnrichmentAudit_reported = new WeakMap(), _EnrichmentAudit_records = new WeakMap(), _EnrichmentAudit_instances = new WeakSet(), _EnrichmentAudit_isConsumed = function _EnrichmentAudit_isConsumed(segments) {
181
213
  return __classPrivateFieldGet(this, _EnrichmentAudit_consumed, "f").has(toPathKey(segments));
182
214
  }, _EnrichmentAudit_divergenceSuggestion = function _EnrichmentAudit_divergenceSuggestion(path) {
183
215
  for (let depth = 0; depth < path.length; depth++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.54.1",
3
+ "version": "0.55.0",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -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,192 @@
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 _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;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FilePlan = void 0;
16
+ const Subject_js_1 = require("./Subject.js");
17
+ const refFns_js_1 = require("../helpers/refFns.js");
18
+ const toVariantList_js_1 = require("../helpers/toVariantList.js");
19
+ /**
20
+ * Which subjects of a run hold each file, known before the run from what the
21
+ * entries declared. A subject holds a file when it can write to it or read
22
+ * from it:
23
+ *
24
+ * - a declared projection of the subject's kind maps the subject to the file;
25
+ * - the file is one that a declared model projection maps a model to, and
26
+ * the subject names that model or a model that reaches it.
27
+ *
28
+ * When the last subject that holds a file has run, the file is complete.
29
+ * {@link finish} gives those files.
30
+ *
31
+ * The plan may hold a file for longer than the run needs it: a reach can
32
+ * have a model no generator gets to. It never knows a file that no declared
33
+ * projection maps a subject to, so such a file is never given by `finish`.
34
+ *
35
+ * Many subjects name one model, so the plan counts in two steps: the
36
+ * subjects left that name a model, and for a file, its own subjects left
37
+ * plus the named models left that reach it. A model's reach is then read
38
+ * one time, not one time for each subject that names the model.
39
+ */
40
+ class FilePlan {
41
+ constructor({ context, subjects, projections, reach, toFilePath }) {
42
+ _FilePlan_instances.add(this);
43
+ _FilePlan_context.set(this, void 0);
44
+ /** The declared projections, by the kind of subject they take. */
45
+ _FilePlan_projections.set(this, void 0);
46
+ _FilePlan_toFilePath.set(this, void 0);
47
+ _FilePlan_paths.set(this, []);
48
+ _FilePlan_indexes.set(this, new Map()
49
+ /** By a file's index: the holds on it by subjects left to run, plus the named models left that reach it. */
50
+ );
51
+ /** By a file's index: the holds on it by subjects left to run, plus the named models left that reach it. */
52
+ _FilePlan_left.set(this, []);
53
+ _FilePlan_held.set(this, new Map()
54
+ /** By a model's key: how many subjects that name it are left to run. */
55
+ );
56
+ /** By a model's key: how many subjects that name it are left to run. */
57
+ _FilePlan_namedLeft.set(this, new Map()
58
+ /** By a named model's key: the indexes of the files of every model it reaches, its own included. */
59
+ );
60
+ /** By a named model's key: the indexes of the files of every model it reaches, its own included. */
61
+ _FilePlan_filesBehind.set(this, new Map()
62
+ /** By a model's key: the indexes of the files the declared model projections map it to. */
63
+ );
64
+ /** By a model's key: the indexes of the files the declared model projections map it to. */
65
+ _FilePlan_modelFiles.set(this, new Map()
66
+ /**
67
+ * How many times a projection could not say where a subject's file is: a
68
+ * static threw, or the subject's enrichments have variants and no `main`.
69
+ * The run reports such a fault where it happens. The plan leaves the file out.
70
+ */
71
+ );
72
+ /**
73
+ * How many times a projection could not say where a subject's file is: a
74
+ * static threw, or the subject's enrichments have variants and no `main`.
75
+ * The run reports such a fault where it happens. The plan leaves the file out.
76
+ */
77
+ Object.defineProperty(this, "unanswered", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: 0
82
+ });
83
+ __classPrivateFieldSet(this, _FilePlan_context, context, "f");
84
+ __classPrivateFieldSet(this, _FilePlan_projections, Map.groupBy(projections, projection => projection.type), "f");
85
+ __classPrivateFieldSet(this, _FilePlan_toFilePath, toFilePath, "f");
86
+ subjects.forEach(subject => {
87
+ // A model names itself, so its own files are among the files behind
88
+ // its key; asking for them here too would answer each projection twice.
89
+ const files = subject.type === 'model' ? [] : __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFiles).call(this, subject);
90
+ const models = subject.toNamedModels(reach);
91
+ files.forEach(file => {
92
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] += 1;
93
+ });
94
+ models.forEach(key => {
95
+ const namedLeft = __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").get(key) ?? 0;
96
+ if (namedLeft === 0) {
97
+ __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFilesBehind).call(this, key, reach).forEach(file => {
98
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] += 1;
99
+ });
100
+ }
101
+ __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").set(key, namedLeft + 1);
102
+ });
103
+ __classPrivateFieldGet(this, _FilePlan_held, "f").set(subject, { files, models });
104
+ });
105
+ }
106
+ /** Whether the plan knows the file at `path`. */
107
+ has(path) {
108
+ return __classPrivateFieldGet(this, _FilePlan_indexes, "f").has(path);
109
+ }
110
+ /** The files `subject` holds, while it is left to run. */
111
+ filesOf(subject) {
112
+ const held = __classPrivateFieldGet(this, _FilePlan_held, "f").get(subject);
113
+ if (held === undefined) {
114
+ return [];
115
+ }
116
+ const behind = held.models.flatMap(key => __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key) ?? []);
117
+ return [...new Set([...held.files, ...behind])].map(file => __classPrivateFieldGet(this, _FilePlan_paths, "f")[file]);
118
+ }
119
+ /**
120
+ * `subject` has run. Gives the files that no subject left to run holds:
121
+ * nothing writes to them or reads from them after this.
122
+ */
123
+ finish(subject) {
124
+ const held = __classPrivateFieldGet(this, _FilePlan_held, "f").get(subject);
125
+ if (held === undefined) {
126
+ return [];
127
+ }
128
+ __classPrivateFieldGet(this, _FilePlan_held, "f").delete(subject);
129
+ const released = held.models.flatMap(key => {
130
+ const namedLeft = (__classPrivateFieldGet(this, _FilePlan_namedLeft, "f").get(key) ?? 0) - 1;
131
+ __classPrivateFieldGet(this, _FilePlan_namedLeft, "f").set(key, namedLeft);
132
+ return namedLeft === 0 ? (__classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key) ?? []) : [];
133
+ });
134
+ return [...held.files, ...released].flatMap(file => {
135
+ __classPrivateFieldGet(this, _FilePlan_left, "f")[file] -= 1;
136
+ return __classPrivateFieldGet(this, _FilePlan_left, "f")[file] === 0 ? [__classPrivateFieldGet(this, _FilePlan_paths, "f")[file]] : [];
137
+ });
138
+ }
139
+ }
140
+ exports.FilePlan = FilePlan;
141
+ _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) {
142
+ const found = __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").get(key);
143
+ if (found !== undefined) {
144
+ return found;
145
+ }
146
+ const reached = [...reach.ofModel((0, refFns_js_1.fromModelKey)(key))];
147
+ const files = [...new Set(reached.flatMap(model => __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toModelFiles).call(this, model)))];
148
+ __classPrivateFieldGet(this, _FilePlan_filesBehind, "f").set(key, files);
149
+ return files;
150
+ }, _FilePlan_toModelFiles = function _FilePlan_toModelFiles(key) {
151
+ const found = __classPrivateFieldGet(this, _FilePlan_modelFiles, "f").get(key);
152
+ if (found !== undefined) {
153
+ return found;
154
+ }
155
+ const files = __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toFiles).call(this, new Subject_js_1.ModelSubject((0, refFns_js_1.fromModelKey)(key)));
156
+ __classPrivateFieldGet(this, _FilePlan_modelFiles, "f").set(key, files);
157
+ return files;
158
+ }, _FilePlan_toFiles = function _FilePlan_toFiles(subject) {
159
+ const projections = __classPrivateFieldGet(this, _FilePlan_projections, "f").get(subject.type) ?? [];
160
+ return projections.flatMap(projection => __classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toVariants).call(this, subject, projection).flatMap(variant => {
161
+ try {
162
+ const exportPath = subject.toExportPath({ projection, context: __classPrivateFieldGet(this, _FilePlan_context, "f"), variant });
163
+ return exportPath === undefined ? [] : [__classPrivateFieldGet(this, _FilePlan_instances, "m", _FilePlan_toIndex).call(this, __classPrivateFieldGet(this, _FilePlan_toFilePath, "f").call(this, exportPath, projection.id))];
164
+ }
165
+ catch {
166
+ this.unanswered += 1;
167
+ return [];
168
+ }
169
+ }));
170
+ }, _FilePlan_toVariants = function _FilePlan_toVariants(subject, projection) {
171
+ try {
172
+ return (0, toVariantList_js_1.toVariantList)({
173
+ opEnrichments: __classPrivateFieldGet(this, _FilePlan_context, "f").readEnrichment([projection.id, ...subject.enrichmentPath]),
174
+ generatorId: projection.id,
175
+ operationLabel: subject.label
176
+ });
177
+ }
178
+ catch {
179
+ this.unanswered += 1;
180
+ return [];
181
+ }
182
+ }, _FilePlan_toIndex = function _FilePlan_toIndex(path) {
183
+ const found = __classPrivateFieldGet(this, _FilePlan_indexes, "f").get(path);
184
+ if (found !== undefined) {
185
+ return found;
186
+ }
187
+ const index = __classPrivateFieldGet(this, _FilePlan_paths, "f").length;
188
+ __classPrivateFieldGet(this, _FilePlan_paths, "f").push(path);
189
+ __classPrivateFieldGet(this, _FilePlan_left, "f").push(0);
190
+ __classPrivateFieldGet(this, _FilePlan_indexes, "f").set(path, index);
191
+ return index;
192
+ };
@@ -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
@@ -32,6 +32,7 @@ const ContentSettings_js_1 = require("../dsl/ContentSettings.js");
32
32
  const Variant_js_1 = require("../types/Variant.js");
33
33
  const toVariantList_js_1 = require("../helpers/toVariantList.js");
34
34
  const Subject_js_1 = require("./Subject.js");
35
+ const FilePlan_js_1 = require("./FilePlan.js");
35
36
  var Subject_js_2 = require("./Subject.js");
36
37
  Object.defineProperty(exports, "toGqlOperationSource", { enumerable: true, get: function () { return Subject_js_2.toGqlOperationSource; } });
37
38
  Object.defineProperty(exports, "toModelSource", { enumerable: true, get: function () { return Subject_js_2.toModelSource; } });
@@ -306,6 +307,32 @@ class GenerateContext {
306
307
  enrichmentWarnings
307
308
  };
308
309
  }
310
+ /**
311
+ * @internal
312
+ * The file plan of a run of this context: which of `subjects` hold each
313
+ * file, from the projection classes that the entries of the run declared.
314
+ * An entry that declared none adds no file to the plan, and a generator
315
+ * that `settings.skip` names whole adds none either, and a GraphQL
316
+ * document's plan knows no file. Building the plan
317
+ * leaves the run as it is: its reads of enrichments are not recorded.
318
+ */
319
+ toFilePlan({ subjects, reach }) {
320
+ const skipped = this.settings?.skip ?? [];
321
+ const generators = Object.values(this.toGeneratorConfigMap());
322
+ // A GraphQL document has no reach (`toReach` reads only OpenAPI refs), so
323
+ // no subject would hold the files of the models it reaches. Its plan
324
+ // knows no file, and each file stays to the end.
325
+ const projections = this.document.type === 'gql'
326
+ ? []
327
+ : generators.filter(({ id }) => !skipped.includes(id)).flatMap(generator => generator.projections ?? []);
328
+ return __classPrivateFieldGet(this, _GenerateContext_enrichmentAudit, "f").withoutRecording(() => new FilePlan_js_1.FilePlan({
329
+ context: this,
330
+ subjects,
331
+ projections: [...new Set(projections)],
332
+ reach,
333
+ toFilePath: (exportPath, generatorId) => __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, exportPath, generatorId)
334
+ }));
335
+ }
309
336
  /**
310
337
  * Evaluate each generator's `isSupported` over the parsed document's subjects
311
338
  * and report the subjects each generator supports — capability only, no
@@ -998,7 +1025,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
998
1025
  __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, this.document.value.operations.map(operation => new Subject_js_1.GqlOperationSubject(operation)), { include: undefined, skip: undefined }, st);
999
1026
  break;
1000
1027
  case 'model':
1001
- __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).map(refName => new Subject_js_1.ModelSubject(refName)), {
1028
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runSubjects).call(this, generatorConfig, __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).map(refName => new Subject_js_1.ModelSubject((0, refFns_js_1.toSchemaComponentRef)(refName))), {
1002
1029
  include: toIncludeModels(include, generatorConfig.id),
1003
1030
  skip: toSkipModels(skip, generatorConfig.id)
1004
1031
  }, 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 = {