@ultimat3/manifest 29.4.0 → 30.0.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/src/graph.ts ADDED
@@ -0,0 +1,297 @@
1
+ // The app as one typed graph: the manifest's declared facts joined to the module graph's import
2
+ // edges (and, when a run recorded them, observed ones). Pure — no registry, no file, no clock:
3
+ // the CLI hands in what it loaded. `impactOf` walks dependents; `pathBetween` explains one link.
4
+
5
+ import type {
6
+ AppGraph,
7
+ EdgeProvenance,
8
+ GraphEdge,
9
+ GraphNode,
10
+ GraphNodeKind,
11
+ GraphPath,
12
+ Impact,
13
+ ImpactEntry,
14
+ } from './graph-schema';
15
+ import { GRAPH_VERSION } from './graph-schema';
16
+ import type { Manifest } from './schema';
17
+
18
+ /** What the module scan knows: each file's resolved imports, and which file declares what. */
19
+ export interface ModuleFacts {
20
+ readonly files: readonly {
21
+ /** App-root-relative POSIX path. */
22
+ readonly path: string;
23
+ /** App-root-relative paths it imports, type-only imports included. */
24
+ readonly imports: readonly string[];
25
+ /** A computed `import()`: it may load any file. */
26
+ readonly opaque: boolean;
27
+ readonly test: boolean;
28
+ }[];
29
+ readonly primitives: readonly {
30
+ readonly kind: 'route' | 'action' | 'query' | 'job' | 'task' | 'entity' | 'channel';
31
+ readonly name: string;
32
+ readonly file: string;
33
+ }[];
34
+ }
35
+
36
+ /** An edge a real run saw: `from` touched `to` (`.x/exercise.json`). */
37
+ export interface ObservedEdge {
38
+ readonly from: string;
39
+ readonly to: string;
40
+ readonly rel: string;
41
+ }
42
+
43
+ export const nodeId = (kind: GraphNodeKind, name: string): string => `${kind}:${name}`;
44
+
45
+ const byText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);
46
+
47
+ class Builder {
48
+ readonly nodes = new Map<string, GraphNode>();
49
+ readonly edges = new Map<string, GraphEdge>();
50
+
51
+ node(kind: GraphNodeKind, name: string, extra: Partial<GraphNode> = {}): string {
52
+ const id = nodeId(kind, name);
53
+ this.nodes.set(id, { ...this.nodes.get(id), id, kind, name, ...extra });
54
+ return id;
55
+ }
56
+
57
+ edge(from: string, to: string, rel: string, provenance: EdgeProvenance): void {
58
+ if (from === to) return;
59
+ this.edges.set(`${from}\u0000${to}\u0000${rel}`, { from, to, rel, provenance });
60
+ }
61
+ }
62
+
63
+ function declared(b: Builder, manifest: Manifest): Map<string, string> {
64
+ /** Primitive name → its node id, so the module scan can attach files by name. */
65
+ const ids = new Map<string, string>();
66
+ for (const permission of manifest.permissions) b.node('permission', permission);
67
+ for (const action of manifest.actions) {
68
+ const id = b.node(action.mutator === true ? 'mutator' : 'action', action.name);
69
+ ids.set(`action:${action.name}`, id);
70
+ for (const p of action.permissions) b.edge(id, b.node('permission', p), 'requires', 'declared');
71
+ for (const tag of action.cacheInvalidates) {
72
+ b.edge(id, b.node('tag', tag), 'invalidates', 'declared');
73
+ }
74
+ if (action.mcp.expose) b.edge(b.node('mcpTool', action.name), id, 'exposes', 'declared');
75
+ b.edge(b.node('operation', action.name), id, 'publishes', 'declared');
76
+ }
77
+ for (const query of manifest.queries) {
78
+ const id = b.node('query', query.name);
79
+ ids.set(`query:${query.name}`, id);
80
+ for (const p of query.permissions) b.edge(id, b.node('permission', p), 'requires', 'declared');
81
+ for (const tag of query.cacheTags) b.edge(id, b.node('tag', tag), 'reads-tag', 'declared');
82
+ b.edge(b.node('operation', query.name), id, 'publishes', 'declared');
83
+ }
84
+ for (const route of manifest.routes) {
85
+ const id = b.node(
86
+ 'route',
87
+ route.url,
88
+ route.budget?.js === undefined ? {} : { budget: route.budget.js },
89
+ );
90
+ ids.set(`route:${route.url}`, id);
91
+ for (const tag of route.revalidateTags ?? []) {
92
+ b.edge(id, b.node('tag', tag), 'revalidates', 'declared');
93
+ }
94
+ }
95
+ const tables = new Map(manifest.entities.map((entity) => [entity.table, entity.name]));
96
+ for (const entity of manifest.entities) {
97
+ const id = b.node('entity', entity.name);
98
+ ids.set(`entity:${entity.name}`, id);
99
+ for (const column of entity.columns) {
100
+ const target = column.references?.split('.')[0];
101
+ const name = target === undefined ? undefined : (tables.get(target) ?? target);
102
+ if (name !== undefined) b.edge(id, b.node('entity', name), 'references', 'declared');
103
+ }
104
+ }
105
+ for (const channel of manifest.channels ?? []) {
106
+ const id = b.node('channel', channel.name);
107
+ ids.set(`channel:${channel.name}`, id);
108
+ for (const p of channel.permissions)
109
+ b.edge(id, b.node('permission', p), 'requires', 'declared');
110
+ for (const record of channel.records) {
111
+ b.edge(id, b.node('entity', tables.get(record) ?? record), 'reads', 'declared');
112
+ }
113
+ }
114
+ for (const job of manifest.jobs) ids.set(`job:${job.name}`, b.node('job', job.name));
115
+ for (const task of manifest.tasks) {
116
+ const id = b.node('task', task.name);
117
+ ids.set(`task:${task.name}`, id);
118
+ for (const job of task.enqueues) b.edge(id, b.node('job', job), 'enqueues', 'declared');
119
+ }
120
+ return ids;
121
+ }
122
+
123
+ /** The graph: declared facts, then import edges, then what a run observed. Sorted throughout. */
124
+ export function buildGraph(
125
+ manifest: Manifest,
126
+ modules?: ModuleFacts,
127
+ observed: readonly ObservedEdge[] = [],
128
+ ): AppGraph {
129
+ const b = new Builder();
130
+ const ids = declared(b, manifest);
131
+ const tests = new Set((modules?.files ?? []).filter((f) => f.test).map((f) => f.path));
132
+ for (const file of modules?.files ?? []) {
133
+ const id = b.node(file.test ? 'test' : 'file', file.path);
134
+ for (const target of file.imports) {
135
+ b.edge(id, b.node(tests.has(target) ? 'test' : 'file', target), 'imports', 'import');
136
+ }
137
+ }
138
+ for (const primitive of modules?.primitives ?? []) {
139
+ const id =
140
+ ids.get(`${primitive.kind}:${primitive.name}`) ?? b.node(primitive.kind, primitive.name);
141
+ b.nodes.set(id, { ...(b.nodes.get(id) as GraphNode), file: primitive.file });
142
+ b.edge(id, nodeId('file', primitive.file), 'declared-in', 'import');
143
+ }
144
+ for (const edge of observed) {
145
+ if (b.nodes.has(edge.from) && b.nodes.has(edge.to))
146
+ b.edge(edge.from, edge.to, edge.rel, 'observed');
147
+ }
148
+ return {
149
+ graphVersion: GRAPH_VERSION,
150
+ nodes: [...b.nodes.values()].sort((x, y) => byText(x.id, y.id)),
151
+ edges: [...b.edges.values()].sort(
152
+ (x, y) => byText(x.from, y.from) || byText(x.to, y.to) || byText(x.rel, y.rel),
153
+ ),
154
+ opaque: (modules?.files ?? [])
155
+ .filter((file) => file.opaque)
156
+ .map((file) => nodeId(file.test ? 'test' : 'file', file.path))
157
+ .sort(byText),
158
+ };
159
+ }
160
+
161
+ /** Every node that depends on one of `starts`, with the provenances of the path that reached it. */
162
+ function dependents(graph: AppGraph, starts: readonly string[]): Map<string, Set<EdgeProvenance>> {
163
+ const into = new Map<string, GraphEdge[]>();
164
+ for (const edge of graph.edges) {
165
+ const list = into.get(edge.to);
166
+ if (list === undefined) into.set(edge.to, [edge]);
167
+ else list.push(edge);
168
+ }
169
+ const reached = new Map<string, Set<EdgeProvenance>>(starts.map((id) => [id, new Set()]));
170
+ const queue = [...starts];
171
+ for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
172
+ const carried = reached.get(at) ?? new Set();
173
+ for (const edge of into.get(at) ?? []) {
174
+ if (reached.has(edge.from)) continue;
175
+ reached.set(edge.from, new Set([...carried, edge.provenance]));
176
+ queue.push(edge.from);
177
+ }
178
+ }
179
+ return reached;
180
+ }
181
+
182
+ /**
183
+ * What a change to `id` reaches: its dependents, transitively. A primitive's own file is a start
184
+ * too — a change to the primitive is a change to it. An opaque file may import anything, so it and
185
+ * its dependents are always in the answer: a superset by construction, never a guess.
186
+ */
187
+ export function impactOf(graph: AppGraph, id: string): Impact {
188
+ const node = graph.nodes.find((candidate) => candidate.id === id);
189
+ const starts = [id, ...(node?.file === undefined ? [] : [nodeId('file', node.file)])];
190
+ const reached = dependents(graph, starts);
191
+ const anything = dependents(graph, graph.opaque);
192
+ for (const [opaqueId, provenance] of anything) {
193
+ if (!reached.has(opaqueId)) reached.set(opaqueId, new Set([...provenance, 'import']));
194
+ }
195
+ reached.delete(id);
196
+ const nodes = new Map(graph.nodes.map((n) => [n.id, n]));
197
+ const pick = (kinds: readonly GraphNodeKind[], also: (n: GraphNode) => boolean = () => true) =>
198
+ [...reached]
199
+ .map(([at, provenance]) => ({ node: nodes.get(at), provenance }))
200
+ .filter(
201
+ (entry): entry is { node: GraphNode; provenance: Set<EdgeProvenance> } =>
202
+ entry.node !== undefined && kinds.includes(entry.node.kind) && also(entry.node),
203
+ )
204
+ .map(
205
+ ({ node: n, provenance }): ImpactEntry => ({
206
+ id: n.id,
207
+ name: n.name,
208
+ provenance: [...provenance].sort(byText),
209
+ }),
210
+ )
211
+ .sort((x, y) => byText(x.id, y.id));
212
+ const searched = new Set(graph.edges.map((edge) => edge.provenance));
213
+ return {
214
+ node: id,
215
+ routes: pick(['route']),
216
+ actions: pick(['action', 'mutator']),
217
+ queries: pick(['query']),
218
+ jobs: pick(['job', 'task']),
219
+ mcpTools: pick(['mcpTool']),
220
+ publishedOperations: pick(['operation']),
221
+ tests: pick(['test']),
222
+ budgets: pick(['route'], (n) => n.budget !== undefined),
223
+ opaque: [...graph.opaque],
224
+ provenance: [...searched].sort(byText),
225
+ };
226
+ }
227
+
228
+ /**
229
+ * The shortest chain of edges linking `from` and `to`, each edge crossed in either direction —
230
+ * "this route reads the file this entity is declared in" is a link through two `declared-in`
231
+ * edges pointing opposite ways. `null` when none is known, with the provenances searched.
232
+ */
233
+ export function pathBetween(graph: AppGraph, from: string, to: string): GraphPath {
234
+ const searched = [...new Set(graph.edges.map((edge) => edge.provenance))].sort(byText);
235
+ const touching = new Map<string, GraphEdge[]>();
236
+ for (const edge of graph.edges) {
237
+ for (const end of [edge.from, edge.to]) {
238
+ const list = touching.get(end);
239
+ if (list === undefined) touching.set(end, [edge]);
240
+ else list.push(edge);
241
+ }
242
+ }
243
+ const via = new Map<string, { readonly edge: GraphEdge; readonly prev: string } | null>([
244
+ [from, null],
245
+ ]);
246
+ const queue = [from];
247
+ for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
248
+ if (at === to) {
249
+ const chain: GraphEdge[] = [];
250
+ for (let step = via.get(to); step; step = via.get(step.prev)) chain.unshift(step.edge);
251
+ return { from, to, edges: chain, searched };
252
+ }
253
+ for (const edge of touching.get(at) ?? []) {
254
+ const next = edge.from === at ? edge.to : edge.from;
255
+ if (via.has(next)) continue;
256
+ via.set(next, { edge, prev: at });
257
+ queue.push(next);
258
+ }
259
+ }
260
+ return { from, to, edges: null, searched };
261
+ }
262
+
263
+ /**
264
+ * The node a name answers to: an id, a primitive name, or a path. `candidates` are the nearest
265
+ * ids by shared prefix, for a refusal to list.
266
+ */
267
+ export function findNode(
268
+ graph: AppGraph,
269
+ text: string,
270
+ ): { readonly id: string | undefined; readonly candidates: readonly string[] } {
271
+ const exact =
272
+ graph.nodes.find((n) => n.id === text) ??
273
+ graph.nodes.find((n) => n.id === `file:${text}`) ??
274
+ graph.nodes.find((n) => n.id === `test:${text}`);
275
+ if (exact !== undefined) return { id: exact.id, candidates: [] };
276
+ const named = graph.nodes.filter(
277
+ (n) => n.name === text && n.kind !== 'operation' && n.kind !== 'mcpTool',
278
+ );
279
+ if (named.length === 1) return { id: named[0]?.id, candidates: [] };
280
+ const score = (id: string): number => {
281
+ const lower = id.toLowerCase();
282
+ const want = text.toLowerCase();
283
+ if (lower.includes(want)) return 1000 - lower.length;
284
+ let shared = 0;
285
+ while (shared < want.length && lower.includes(want.slice(0, shared + 1))) shared += 1;
286
+ return shared;
287
+ };
288
+ // A projection (`operation:`, `mcpTool:`) shares its primitive's name; the primitive is the answer.
289
+ const primary = graph.nodes.filter((n) => n.kind !== 'operation' && n.kind !== 'mcpTool');
290
+ const candidates = (named.length > 1 ? named : primary)
291
+ .map((n) => n.id)
292
+ .map((id) => ({ id, score: score(id) }))
293
+ .sort((x, y) => y.score - x.score || byText(x.id, y.id))
294
+ .slice(0, 3)
295
+ .map((entry) => entry.id);
296
+ return { id: undefined, candidates };
297
+ }
package/src/index.ts CHANGED
@@ -21,7 +21,10 @@ export {
21
21
  shortName,
22
22
  } from './docs-scan';
23
23
  export type { DocHit } from './docs-search';
24
- export { nearestTopics, searchDocs, tokenize } from './docs-search';
24
+ export { nearestTopics, searchDocs } from './docs-search';
25
+ export { tokenize } from './docs-tokens';
26
+ export type { WikiHeading, WikiOrigin } from './docs-wiki';
27
+ export { githubSlug, scanWikiDocs, wikiHeadings, wikiSection } from './docs-wiki';
25
28
  export type { EmitInput, EmitResult } from './emit';
26
29
  export {
27
30
  assertNoDrift,
@@ -41,6 +44,19 @@ export {
41
44
  ManifestDriftError,
42
45
  ManifestFactInvalidError,
43
46
  } from './errors';
47
+ export type { ModuleFacts, ObservedEdge } from './graph';
48
+ export { buildGraph, findNode, impactOf, nodeId, pathBetween } from './graph';
49
+ export type {
50
+ AppGraph,
51
+ EdgeProvenance,
52
+ GraphEdge,
53
+ GraphNode,
54
+ GraphNodeKind,
55
+ GraphPath,
56
+ Impact,
57
+ ImpactEntry,
58
+ } from './graph-schema';
59
+ export { GRAPH_NODE_KINDS, GRAPH_VERSION } from './graph-schema';
44
60
  export type {
45
61
  ActionFact,
46
62
  AdminFact,
@@ -49,11 +65,14 @@ export type {
49
65
  AdminScopeFact,
50
66
  ChannelFact,
51
67
  ColumnFact,
68
+ ConsumerFact,
52
69
  EntityFact,
53
70
  ErrorCodeFact,
54
71
  JobFact,
55
72
  JsonValue,
56
73
  Manifest,
74
+ MeterFact,
75
+ MountFact,
57
76
  PolicyFact,
58
77
  QueryFact,
59
78
  RateLimitFact,
@@ -61,6 +80,12 @@ export type {
61
80
  TaskFact,
62
81
  } from './schema';
63
82
  export { isCompatible, isManifest, MANIFEST_VERSION } from './schema';
83
+ export type {
84
+ SubjectFact,
85
+ SubjectTableFact,
86
+ SubjectTargetFact,
87
+ SubjectTreatmentFact,
88
+ } from './schema-subjects';
64
89
  export type { FrameworkSourcesInput } from './sources';
65
90
  export { frameworkSources } from './sources';
66
91
  export type { VerifyContractInput, VerifyContractResult } from './verify';
@@ -0,0 +1,34 @@
1
+ // The manifest's `subjects` section: each `defineSubject()` as a fact — whose data it is, and what
2
+ // an erase does to every table holding some of it. Types only; `schema.ts` composes it, so a
3
+ // treatment moving from kept to deleted is a change `x manifest diff` can call breaking.
4
+
5
+ /** The treatment's kind. Its arguments (the anonymized values) stay in code, never in the file. */
6
+ export type SubjectTreatmentFact = 'delete' | 'anonymize' | 'retain';
7
+
8
+ export interface SubjectTableFact {
9
+ /** The entity's name, as `entities` lists it. */
10
+ readonly entity: string;
11
+ readonly treatment: SubjectTreatmentFact;
12
+ /** `anonymize` only: the columns overwritten, sorted. */
13
+ readonly columns?: readonly string[];
14
+ /** `retain` only: the reason the export prints. */
15
+ readonly reason?: string;
16
+ }
17
+
18
+ export interface SubjectTargetFact {
19
+ /** A framework-held store (`x_users`, stored files): exported, and erased unless retained. */
20
+ readonly name: string;
21
+ readonly retained: boolean;
22
+ }
23
+
24
+ export interface SubjectFact {
25
+ /** The subject entity — one subject per entity. */
26
+ readonly entity: string;
27
+ readonly batch: number;
28
+ /** Every reached table, sorted by entity. */
29
+ readonly tables: readonly SubjectTableFact[];
30
+ /** Sorted by name; `[]` when none is declared. */
31
+ readonly targets: readonly SubjectTargetFact[];
32
+ /** Columns holding the subject's key with no foreign key, sorted; absent when none is listed. */
33
+ readonly links?: readonly { readonly entity: string; readonly column: string }[];
34
+ }
package/src/schema.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  // though every other field here is a plain literal: the manifest's `render` field means the same
10
10
  // thing as the route's, and two spellings of one closed set is what `'spa'` escaped through.
11
11
  import type { HydrateStrategy, OfflineStrategy, RenderMode } from '@ultimat3/core';
12
+ import type { SubjectFact } from './schema-subjects';
12
13
 
13
14
  /**
14
15
  * Bumped when a reader built for the previous version would be WRONG, not merely incomplete:
@@ -44,7 +45,7 @@ export interface RouteFact {
44
45
  readonly onInvalidate?: 'stale' | 'purge';
45
46
  /** `revalidate.maxStale`, as declared; absent when the route declared none. */
46
47
  readonly maxStale?: string | number;
47
- /** `revalidate.query`, sorted; absent when the route declared none (it keys on the whole query). */
48
+ /** `revalidate.query`, sorted; absent when the route declared none (it keys on no query). */
48
49
  readonly query?: readonly string[];
49
50
  readonly budget?: { readonly js?: string };
50
51
  /** Which surface the route lives in — `site` may never import from `app`. */
@@ -156,6 +157,16 @@ export interface EntityFact {
156
157
  readonly columns: readonly ColumnFact[];
157
158
  /** Named invariants, so an agent can see the rules without reading the migration. */
158
159
  readonly invariants: readonly string[];
160
+ /** `entity({ shared })`: why it belongs to no tenant. Absent when undeclared. */
161
+ readonly shared?: string;
162
+ /** `entity({ scan })`: why the table may be read whole. Absent when undeclared. */
163
+ readonly scan?: string;
164
+ /**
165
+ * `entity({ view })`: a relation Postgres derives, so every write to it is refused and the admin
166
+ * lists it read-only. `materialized` stores the rows a `refreshView()` job recomputes. Absent on
167
+ * every table. The query itself is the schema dump's (`packages/db/schema/07_views/`).
168
+ */
169
+ readonly view?: { readonly materialized: boolean };
159
170
  }
160
171
 
161
172
  /** A declared bucket as the author wrote it — `toBucket`'s input, never its converted output. */
@@ -164,6 +175,19 @@ export interface RateLimitFact {
164
175
  readonly windowMs: number;
165
176
  }
166
177
 
178
+ /**
179
+ * A declared `meter:` as `describe()` publishes it: the counter's name, its period and the zone
180
+ * that period is cut in, and the allowance — `null` when it is resolved per call from `ctx` (a
181
+ * tenant's plan), because no static number exists to publish. `warnAt` is the app's own signal.
182
+ */
183
+ export interface MeterFact {
184
+ readonly name: string;
185
+ readonly period: 'hour' | 'day' | 'month';
186
+ readonly timeZone: 'UTC';
187
+ readonly limit: number | null;
188
+ readonly warnAt: number | null;
189
+ }
190
+
167
191
  export interface ActionFact {
168
192
  readonly name: string;
169
193
  readonly input: JsonValue;
@@ -184,8 +208,34 @@ export interface ActionFact {
184
208
  * the manifest is the copy the gate reads, so without it the tightening passes clean.
185
209
  */
186
210
  readonly rateLimit?: RateLimitFact;
211
+ /**
212
+ * The window of a rate limit resolved per call (`limit: ({ ctx }) => …`), which has no static
213
+ * pair to publish; absent otherwise. Never beside `rateLimit`. Judged with it by `diffRateLimit`:
214
+ * a move to or from a per-call limit is breaking, the reason a per-call meter's is.
215
+ */
216
+ readonly rateLimitPerCall?: { readonly windowMs: number };
217
+ /**
218
+ * The declared durable allowance; absent when the action declares none. A contract for the
219
+ * reason `rateLimit` is: 100 a day tightened to 10 refuses a caller the old build served, and
220
+ * no schema in the manifest moves (`diffMeter`).
221
+ */
222
+ readonly meter?: MeterFact;
187
223
  readonly mcp: { readonly expose: boolean; readonly description?: string };
188
224
  readonly mutator?: boolean;
225
+ /**
226
+ * The declared refusals, sorted — absent for an action that declares none (an open contract),
227
+ * like `rateLimit`. A caller branches on each code: removing one is breaking, adding one additive
228
+ * (`diffDeclaredErrors`). `errors: []` is written: a closed list is a fact, an empty one too.
229
+ */
230
+ readonly errors?: readonly string[];
231
+ /** A pinned `http: { path, method }`, absent when unpinned. A change is `breaking`. */
232
+ readonly http?: HttpPinFact;
233
+ }
234
+
235
+ /** Where a pinned primitive is served: the `:param` template and its verb. */
236
+ export interface HttpPinFact {
237
+ readonly path: string;
238
+ readonly method: string;
189
239
  }
190
240
 
191
241
  export interface QueryFact {
@@ -219,6 +269,27 @@ export interface QueryFact {
219
269
  * no fact. A caller built against rows is broken by the flip, and one built against a URL too.
220
270
  */
221
271
  readonly download?: true;
272
+ /**
273
+ * The declared row, as `@ultimat3/schema`'s `toWireOutputSchema` narrows it: the document the
274
+ * read's OpenAPI operation and MCP tool publish. Written only when declared and introspectable,
275
+ * like `subscribes`. `diffQueries` compares members, never the whole schema: an entity gaining a
276
+ * column must not flip every `rows: X.$schema` read. Present before and absent after is breaking.
277
+ */
278
+ readonly rows?: JsonValue;
279
+ /** The declared refusals, sorted — `ActionFact.errors`, the same rule. */
280
+ readonly errors?: readonly string[];
281
+ /** `ActionFact.http`, the same rule; `method` is always `GET`. */
282
+ readonly http?: HttpPinFact;
283
+ }
284
+
285
+ /**
286
+ * A declared bearer mount's published cut: the prefix a caller dials and, by scope, the names a
287
+ * token holding it reaches. Sorted at every level. Neither `resolveToken`, nor the mount's rate
288
+ * limit, nor its document's file name: this is what turns a customer's call into a 404, no more.
289
+ */
290
+ export interface MountFact {
291
+ readonly prefix: string;
292
+ readonly scopes: Readonly<Record<string, readonly string[]>>;
222
293
  }
223
294
 
224
295
  /**
@@ -260,6 +331,23 @@ export interface JobFact {
260
331
  readonly onSettled?: true;
261
332
  }
262
333
 
334
+ /**
335
+ * One `consumer()` — a job plus its `.supervisor` task, both also listed under `jobs` and `tasks`.
336
+ * This row is what neither of those says: that the two are one declaration, how often every key
337
+ * is re-armed, and the batch a cursor commits with.
338
+ */
339
+ export interface ConsumerFact {
340
+ readonly name: string;
341
+ readonly queue: string;
342
+ readonly supervisor: string;
343
+ readonly arm: string;
344
+ /** The supervisor's cron, in UTC. */
345
+ readonly rearm: string;
346
+ readonly batch: number;
347
+ /** Whether a `lag` is declared, so a run reports how far behind its key is. */
348
+ readonly lags: boolean;
349
+ }
350
+
263
351
  export interface TaskFact {
264
352
  readonly name: string;
265
353
  readonly cron: string;
@@ -309,7 +397,17 @@ export interface Manifest {
309
397
  * `buildManifest` always writes it — `[]` for an app with no admin.
310
398
  */
311
399
  readonly admin?: readonly AdminFact[];
400
+ /**
401
+ * Absent, to a reader, for a file older than the section AND for an app with no mount:
402
+ * `buildManifest` writes the key only when there is one, so an app without a mount keeps its
403
+ * bytes across the upgrade that introduced it.
404
+ */
405
+ readonly mounts?: readonly MountFact[];
312
406
  readonly jobs: readonly JobFact[];
407
+ /** Absent for a file older than the section AND for an app with no consumer — `mounts`' rule. */
408
+ readonly consumers?: readonly ConsumerFact[];
409
+ /** Absent for a file older than the section AND for an app with no subject — `mounts`' rule. */
410
+ readonly subjects?: readonly SubjectFact[];
313
411
  readonly tasks: readonly TaskFact[];
314
412
  readonly policies: readonly PolicyFact[];
315
413
  readonly permissions: readonly string[];
@@ -368,6 +466,9 @@ export function isManifest(value: unknown): value is Manifest {
368
466
  // Absent is a pre-channel file and readable; present and not an array is a damaged one.
369
467
  if (m['channels'] !== undefined && !Array.isArray(m['channels'])) return false;
370
468
  if (m['admin'] !== undefined && !Array.isArray(m['admin'])) return false;
469
+ if (m['mounts'] !== undefined && !Array.isArray(m['mounts'])) return false;
470
+ if (m['consumers'] !== undefined && !Array.isArray(m['consumers'])) return false;
471
+ if (m['subjects'] !== undefined && !Array.isArray(m['subjects'])) return false;
371
472
  return isAppIdentity(m['app']);
372
473
  }
373
474