@ultimat3/manifest 29.3.2 → 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/sources.ts CHANGED
@@ -5,11 +5,18 @@
5
5
  // a global registry. Routes and policies are supplied by the caller: the route table lives
6
6
  // in `@ultimat3/render`, which is this same tier.
7
7
 
8
- import { describeActions, jsonSchemaOf } from '@ultimat3/action';
8
+ import {
9
+ actionHttpPinOf,
10
+ apiDeclaration,
11
+ describeActions,
12
+ getAction,
13
+ jsonSchemaOf,
14
+ } from '@ultimat3/action';
9
15
  import { describeEntities, registeredEntities, sealedFields } from '@ultimat3/entity';
10
- import { describeJobs } from '@ultimat3/jobs';
11
- import { describeQueries, getQuery } from '@ultimat3/query';
16
+ import { describeJobs, registeredConsumers, registeredSubjects } from '@ultimat3/jobs';
17
+ import { describeQueries, getQuery, queryHttpPinOf } from '@ultimat3/query';
12
18
  import { describeChannels } from '@ultimat3/realtime/server';
19
+ import { toWireOutputSchema } from '@ultimat3/schema';
13
20
  import type { ManifestSources } from './build';
14
21
  import type {
15
22
  AdminFact,
@@ -19,6 +26,7 @@ import type {
19
26
  RouteFact,
20
27
  TaskFact,
21
28
  } from './schema';
29
+ import type { SubjectFact } from './schema-subjects';
22
30
  import { declaredAdmins } from './sources-admin';
23
31
 
24
32
  export interface FrameworkSourcesInput {
@@ -55,6 +63,31 @@ const queryInput = (name: string): { readonly input?: JsonValue } => {
55
63
  return handle === undefined ? {} : { input: asJson(jsonSchemaOf(handle.input)) };
56
64
  };
57
65
 
66
+ /**
67
+ * The row the read's OpenAPI operation and MCP tool publish, through the one narrowing both call.
68
+ * Absent when none is declared or it cannot be introspected: there is no fact to write.
69
+ */
70
+ const queryRows = (name: string): { readonly rows?: JsonValue } => {
71
+ const row = toWireOutputSchema(getQuery(name)?.rows);
72
+ return row === undefined ? {} : { rows: asJson(row) };
73
+ };
74
+
75
+ /**
76
+ * A pinned `http: { path, method }`, written only when pinned: an unpinned primitive's URL is the
77
+ * style's derivation, which the manifest never carried, so absence keeps every fact's bytes.
78
+ */
79
+ const actionHttp = (name: string) => {
80
+ const target = getAction(name);
81
+ const pin = target === undefined ? undefined : actionHttpPinOf(target);
82
+ return pin === undefined ? {} : { http: pin };
83
+ };
84
+
85
+ const queryHttp = (name: string) => {
86
+ const target = getQuery(name);
87
+ const pin = target === undefined ? undefined : queryHttpPinOf(target);
88
+ return pin === undefined ? {} : { http: pin };
89
+ };
90
+
58
91
  /** Absent stays absent: only a sealed column carries the field. */
59
92
  const sealedFact = (
60
93
  how: 'opaque' | 'lookup' | undefined,
@@ -80,6 +113,35 @@ function sealedColumns(): ReadonlyMap<string, ReadonlyMap<string, 'opaque' | 'lo
80
113
  );
81
114
  }
82
115
 
116
+ /**
117
+ * One `defineSubject()`, projected: each treatment's KIND and its columns or reason — never the
118
+ * anonymized values, which are code (a function, a constant) and not a contract fact.
119
+ */
120
+ function subjectFact(subject: ReturnType<typeof registeredSubjects>[number]): SubjectFact {
121
+ const tables = Object.entries(subject.init.tables).map(([entity, treatment]) =>
122
+ treatment === 'delete'
123
+ ? { entity, treatment: 'delete' as const }
124
+ : 'retain' in treatment
125
+ ? { entity, treatment: 'retain' as const, reason: treatment.retain }
126
+ : { entity, treatment: 'anonymize' as const, columns: Object.keys(treatment.anonymize) },
127
+ );
128
+ const links = Object.entries(subject.init.columns ?? {}).map(([entity, column]) => ({
129
+ entity,
130
+ column,
131
+ }));
132
+ return {
133
+ entity: subject.entity,
134
+ batch: subject.batch,
135
+ tables,
136
+ targets: (subject.init.targets ?? []).map((entry) =>
137
+ 'target' in entry
138
+ ? { name: entry.target.name, retained: true }
139
+ : { name: entry.name, retained: false },
140
+ ),
141
+ ...(links.length === 0 ? {} : { links }),
142
+ };
143
+ }
144
+
83
145
  export function frameworkSources(input: FrameworkSourcesInput): ManifestSources {
84
146
  const sealed = sealedColumns();
85
147
  return {
@@ -105,6 +167,11 @@ export function frameworkSources(input: FrameworkSourcesInput): ManifestSources
105
167
  ...sealedFact(sealed.get(entity.name)?.get(column.column)),
106
168
  })),
107
169
  invariants: entity.invariants.map((invariant) => invariant.name),
170
+ ...(entity.shared === undefined ? {} : { shared: entity.shared }),
171
+ ...(entity.scan === undefined ? {} : { scan: entity.scan }),
172
+ ...(entity.view === undefined || entity.view === null
173
+ ? {}
174
+ : { view: { materialized: entity.view.materialized === true } }),
108
175
  })),
109
176
  actions: describeActions().map((action) => ({
110
177
  name: action.name,
@@ -116,6 +183,12 @@ export function frameworkSources(input: FrameworkSourcesInput): ManifestSources
116
183
  // Written only when declared, exactly like `mcp.description`: absence already reads as
117
184
  // "no limit", and the descriptor's `null` is not a JSON fact worth a line per action.
118
185
  ...(action.rateLimit === null ? {} : { rateLimit: action.rateLimit }),
186
+ // A per-call limit has no fixed pair, and dropping its window read as "no rate limit".
187
+ ...(action.rateLimitPerCall === null
188
+ ? {}
189
+ : { rateLimitPerCall: { windowMs: action.rateLimitPerCall.windowMs } }),
190
+ // The same rule: absent reads as "no meter"; a per-call limit keeps its `null` (`MeterFact`).
191
+ ...(action.meter === null ? {} : { meter: action.meter }),
119
192
  mcp: {
120
193
  expose: action.mcp.expose,
121
194
  ...(action.mcp.description === null ? {} : { description: action.mcp.description }),
@@ -124,6 +197,9 @@ export function frameworkSources(input: FrameworkSourcesInput): ManifestSources
124
197
  // so absence already reads as "a plain action", and a `false` on every other action would
125
198
  // be bytes added to a file that is reviewed by hand for no fact gained.
126
199
  ...(action.mutator ? { mutator: true } : {}),
200
+ // Written when declared, sorted; `null` is the descriptor's "declares none" (an open list).
201
+ ...(action.errors === null ? {} : { errors: [...action.errors].sort() }),
202
+ ...actionHttp(action.name),
127
203
  })),
128
204
  queries: describeQueries().map((query) => ({
129
205
  name: query.name,
@@ -137,6 +213,17 @@ export function frameworkSources(input: FrameworkSourcesInput): ManifestSources
137
213
  // empty list is refused at `query()`, so absence carries the whole meaning.
138
214
  ...(query.subscribes === null ? {} : { subscribes: query.subscribes }),
139
215
  cacheTags: query.tags,
216
+ // Written only when true — the reason `mutator` is: absence already means "answers rows".
217
+ ...(query.download ? { download: true as const } : {}),
218
+ ...queryRows(query.name),
219
+ ...(query.errors === null ? {} : { errors: [...query.errors].sort() }),
220
+ ...queryHttp(query.name),
221
+ })),
222
+ // The prefix and the cut, field by field: `resolveToken` is a function, and the rest of a mount
223
+ // decides nothing about whether a held token's call still finds its route.
224
+ mounts: (apiDeclaration().http?.mounts ?? []).map((mount) => ({
225
+ prefix: mount.prefix,
226
+ scopes: mount.scopes,
140
227
  })),
141
228
  // Already the fact's shape, sorted and flattened by `describeChannels` — projected field by
142
229
  // field all the same, for the reason above.
@@ -172,5 +259,16 @@ export function frameworkSources(input: FrameworkSourcesInput): ManifestSources
172
259
  // The same rule: only a job that declares the hook carries the key.
173
260
  ...(job.onSettled ? { onSettled: true as const } : {}),
174
261
  })),
262
+ // Field by field, for the reason above: `kind` is the declaration's tag, not a fact.
263
+ consumers: registeredConsumers().map((consumer) => ({
264
+ name: consumer.name,
265
+ queue: consumer.queue,
266
+ supervisor: consumer.supervisor,
267
+ arm: consumer.arm,
268
+ rearm: consumer.rearm,
269
+ batch: consumer.batch,
270
+ lags: consumer.lags,
271
+ })),
272
+ subjects: registeredSubjects().map(subjectFact),
175
273
  };
176
274
  }