@ultimat3/manifest 29.4.0 → 30.1.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/CLAUDE.md +18 -2
- package/README.md +44 -5
- package/package.json +20 -8
- package/src/build.ts +39 -0
- package/src/diff-consumers.ts +44 -0
- package/src/diff-entities.ts +50 -0
- package/src/diff-meter.ts +132 -0
- package/src/diff-mounts.ts +72 -0
- package/src/diff-operations.ts +65 -1
- package/src/diff-rate-limit.ts +45 -3
- package/src/diff-registries.ts +50 -4
- package/src/diff-rows.ts +127 -0
- package/src/diff-subjects.ts +88 -0
- package/src/diff.ts +8 -0
- package/src/docs-scan.ts +9 -4
- package/src/docs-search-subpath.ts +7 -0
- package/src/docs-search.ts +60 -94
- package/src/docs-tokens.ts +87 -0
- package/src/docs-wiki.ts +167 -0
- package/src/emit.ts +3 -0
- package/src/graph-schema.ts +95 -0
- package/src/graph.ts +297 -0
- package/src/index.ts +26 -1
- package/src/schema-subjects.ts +34 -0
- package/src/schema.ts +102 -1
- package/src/sources.ts +99 -3
package/CLAUDE.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @ultimat3/manifest — boundary
|
|
2
2
|
|
|
3
3
|
Tier 4. May import tier 0–3: `core schema i18n money time cache seo entity policy http action
|
|
4
|
-
query jobs realtime`. **Never** `render mcp ai pwa ui admin testing cli`.
|
|
4
|
+
query jobs realtime`. **Never** `render mcp ai pwa ui admin testing cli`. `package.json` and
|
|
5
|
+
`tsconfig.json` declare `schema` too (`sources.ts`).
|
|
5
6
|
|
|
6
7
|
Route, policy, task and locale facts come from tier 4 / per-app code, so they are **injected**
|
|
7
8
|
by the CLI, not imported.
|
|
@@ -18,6 +19,7 @@ by the CLI, not imported.
|
|
|
18
19
|
| `diff-change.ts` | the shared vocabulary: `ManifestChange`, `index`, `diffNamedSet`, `diffScalar` |
|
|
19
20
|
| `diff-operations.ts` | actions, queries and the permissions they require |
|
|
20
21
|
| `diff-rate-limit.ts` | how a declared rate limit moved |
|
|
22
|
+
| `diff-meter.ts` | how a declared `meter:` moved: breaking iff a call pattern the old one admitted is refused (UTC periods nest — a shorter period at the same limit is LOOSER); a rename is breaking (`meta.meter` is public), `warnAt` internal |
|
|
21
23
|
| `diff-entities.ts` | tables, columns, keys, invariants |
|
|
22
24
|
| `diff-work.ts` | jobs and tasks — the two things that fail by silently not happening |
|
|
23
25
|
| `diff-routes.ts` | a URL's surface and its delivery facts |
|
|
@@ -29,6 +31,14 @@ by the CLI, not imported.
|
|
|
29
31
|
| `agents-md.ts` | read-only AGENTS.md existence + size check |
|
|
30
32
|
| `docs-scan.ts` | read-only: an installed package tree → `DocEntry[]`. Never writes |
|
|
31
33
|
| `docs-search.ts` | pure ranking of `DocEntry[]` against a question. No I/O, no clock |
|
|
34
|
+
| `docs-search-subpath.ts` | the `./docs-search` entry: `searchDocs`, `nearestTopics`, the entry types. Nothing with I/O may join its graph — an island imports it (`docs-search-subpath.test.ts` bundles it for a browser) |
|
|
35
|
+
| `docs-wiki.ts` | read-only: a shipped `wiki/` directory → `DocEntry[]`, topic `wiki.<Page>#<GitHub anchor>`; `wikiSection` is one whole section. Never reads `Error-Codes.md` |
|
|
36
|
+
| `docs-tokens.ts` | pure: the query/name splitter and the one-suffix stem both sides of `docs-search` share |
|
|
37
|
+
| `diff-rows.ts` | a read's row, member by member: removed, retyped or no longer required is breaking, added is additive. Never `canonicalJson` inequality: an entity gaining a column would flip every `rows: X.$schema` read |
|
|
38
|
+
| `diff-mounts.ts` | a bearer mount's cut, per (scope, name): the one classifier that sees a held token's 404, because the primitive stays registered |
|
|
39
|
+
| `diff-consumers.ts` | the `consumers` section: a consumer removed is breaking (its stream is never read again, nothing throws); every field that moved is internal |
|
|
40
|
+
| `graph.ts` / `graph-schema.ts` | the app graph: `buildGraph` (pure — manifest + injected `ModuleFacts` + observed edges; never a registry or a file), `impactOf`, `pathBetween`, `findNode`. Never written to `x.manifest.json`: a contract that churned on every import. Every edge carries its provenance |
|
|
41
|
+
| `schema-subjects.ts` / `diff-subjects.ts` | the `subjects` section (`defineSubject()`): a subject removed, or a table's treatment moving from `retain`/`anonymize` to `delete`, is breaking; a subject or table added is additive; the anonymized VALUES are code and never projected |
|
|
32
42
|
|
|
33
43
|
## Invariants
|
|
34
44
|
|
|
@@ -76,7 +86,9 @@ by the CLI, not imported.
|
|
|
76
86
|
and no schema in the file moved); one dropped is additive but reported, because a widening of
|
|
77
87
|
access is what a reviewer most needs to see. A rate limit tightened — in burst OR in refill rate,
|
|
78
88
|
compared cross-multiplied so no rounding can invent a change — is breaking, and so is
|
|
79
|
-
introducing one where there was none; loosening or removing is additive.
|
|
89
|
+
introducing one where there was none; loosening or removing is additive. A limit resolved per call
|
|
90
|
+
is `rateLimitPerCall: { windowMs }` (never beside `rateLimit`): a move to or from one is breaking,
|
|
91
|
+
`diff-meter.ts`'s per-call rule; two of them compare windows (longer is breaking).
|
|
80
92
|
- **An absent `permissions` is NOT an empty one.** Unlike `mcp.expose` there is no value to fold
|
|
81
93
|
absence into: `[]` asserts "this operation requires nothing", so reading an absent field that
|
|
82
94
|
way would call every permission of every operation newly required the first time an app diffs
|
|
@@ -107,6 +119,8 @@ by the CLI, not imported.
|
|
|
107
119
|
- `docs-scan.ts` indexes the **file header comment**, not JSDoc: `As of 2026-08`, 99.8% of source
|
|
108
120
|
files carry a header, 42.3% of public exports carry JSDoc, and `job()` is in the missing 57.7%.
|
|
109
121
|
- A guide topic is unique within its package — repeated headings take a document-order suffix.
|
|
122
|
+
- **`docs-search-eval-set-fixture.ts` is the ranking's regression set**: `docs-search.test.ts` holds it at
|
|
123
|
+
`EVAL_FLOOR` (18 of 20) over the repo's `packages/` and `wiki/`. Ranking is not a stable surface.
|
|
110
124
|
- Neither docs module may import a registry or a clock. `docs-search.ts` is pure; `docs-scan.ts`
|
|
111
125
|
reads files and nothing else.
|
|
112
126
|
- **A new manifest field ⇒ a `diff-*.ts` rule for it.** Always — a field nothing classifies is a
|
|
@@ -163,6 +177,8 @@ by the CLI, not imported.
|
|
|
163
177
|
`before` is a file parsed off disk, so an older or hand-trimmed manifest can carry an absent or
|
|
164
178
|
non-boolean value that `!==` would classify from; and the fact `sources.ts` publishes has to be
|
|
165
179
|
the answer `@ultimat3/mcp`'s catalog gives, or the gate demands a major bump for a tool that never existed.
|
|
180
|
+
- **`consumers` follows `mounts`' rule** (`As of 2026-11`): written only when one is declared, `?? []` on both sides in `diff.ts`. So does `subjects`.
|
|
181
|
+
- **`mounts` is written only when there is one** (`As of 2026-11`), unlike `channels` and `admin`, so an app without a mount keeps its bytes; `diff.ts` reads `?? []` on BOTH sides because the key is absent after the last mount leaves. **`QueryFact.rows` present before and absent after is breaking** (the 200 turns untyped; `before` carrying it proves its writer knew the field); absent before is additive.
|
|
166
182
|
|
|
167
183
|
## Commands
|
|
168
184
|
|
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Generated facts. `x.manifest.json` is emitted from code, committed, and diffed in review —
|
|
4
4
|
it is how an agent learns what the app *is* without reading every file.
|
|
5
5
|
|
|
6
|
+
`bun add @ultimat3/manifest` · guide: [Agents](https://github.com/developerz-ai/ultimate/wiki/Agents)
|
|
7
|
+
|
|
6
8
|
```ts
|
|
7
9
|
import { buildManifest, emitManifest, assertNoDrift, verifyContract } from '@ultimat3/manifest';
|
|
8
10
|
|
|
@@ -19,10 +21,12 @@ verifyContract({ before: committed, after: manifest });
|
|
|
19
21
|
| `routes` | url, render mode, offline strategy, hydrate, revalidate tags, budget |
|
|
20
22
|
| `entities` | table, columns (type, nullability, PK, FK), named invariants |
|
|
21
23
|
| `actions` | input + output schema, policy label, **required permissions**, cache invalidations, declared rate limit, MCP exposure, `mutator` when it is one |
|
|
22
|
-
| `queries` | input schema, policy label, **required permissions**, live, cache tags |
|
|
24
|
+
| `queries` | input schema, policy label, **required permissions**, live, cache tags, and `rows` — the declared row's wire schema, only when there is one |
|
|
25
|
+
| `mounts` | one entry per bearer mount: `prefix` and `scopes` (scope → names, sorted). Never `resolveToken`. No key at all for an app with no mount |
|
|
23
26
|
| `admin` | one entry per `defineAdmin()`: `basePath`; each resource's `filters`, `sorts`, `scopes` (`name`, `default`, `count`) and `rowScoped`; each mounted route's `url`, `view`, `entity` and `permissions`. `[]` for an app with no admin. Read off the process's own declarations — the one section the CLI does not inject |
|
|
24
27
|
| `jobs` | input schema, queue, retry policy, step names, and — only when the job declares a cap — `concurrency: { limit, keyed, whenBusy }` |
|
|
25
28
|
| `tasks` | cron, tz, jobs enqueued |
|
|
29
|
+
| `subjects` | one entry per `defineSubject()`: the entity, `batch`, each reached table's treatment kind (`delete`, `anonymize` with its columns, `retain` with its reason), the framework targets and any `links`. Never the anonymized values. No key for an app with none |
|
|
26
30
|
| `policies` | permission, where enforced |
|
|
27
31
|
| `permissions` | **derived** from policies + each operation's own list, never declared twice |
|
|
28
32
|
| `locales`, `errorCodes` | catalogs a tool can enumerate |
|
|
@@ -35,6 +39,24 @@ An operation's `policy` is its **display label** — a composite renders as
|
|
|
35
39
|
against `permissions`; matching on `policy` reports every non-trivially-guarded operation as
|
|
36
40
|
enforcing nothing.
|
|
37
41
|
|
|
42
|
+
## The app graph — `buildGraph`, `impactOf`, `pathBetween`
|
|
43
|
+
|
|
44
|
+
Pure, never stored: `buildGraph(manifest, modules?, observed?)` joins the manifest's declared facts
|
|
45
|
+
to the module facts the CLI scans (`ModuleFacts`: each file's imports, opaque files, which file
|
|
46
|
+
declares which primitive) and to edges a run observed. Every edge carries `declared`, `import` or
|
|
47
|
+
`observed`. `impactOf(graph, id)` walks dependents — an opaque file and its dependents are always in
|
|
48
|
+
— and sorts them into routes, actions, queries, jobs, MCP tools, published operations, tests and
|
|
49
|
+
budgets; `pathBetween` explains one link; `findNode` resolves a name, id or path, or names the
|
|
50
|
+
nearest three. `GRAPH_VERSION` versions the shape. `x graph` and `x impact` are its readers.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { buildGraph, impactOf, type Manifest } from '@ultimat3/manifest';
|
|
54
|
+
|
|
55
|
+
declare const manifest: Manifest;
|
|
56
|
+
const reach = impactOf(buildGraph(manifest), 'query:postById');
|
|
57
|
+
reach.publishedOperations; // non-empty: contract-diff will have an opinion
|
|
58
|
+
```
|
|
59
|
+
|
|
38
60
|
## Determinism
|
|
39
61
|
|
|
40
62
|
The file is committed and reviewed, so two builds of the same tree must produce identical
|
|
@@ -60,8 +82,8 @@ whole mechanism.
|
|
|
60
82
|
|
|
61
83
|
| Class | Examples |
|
|
62
84
|
|---|---|
|
|
63
|
-
| **breaking** | action/query/route/job/**task**/entity/**policy**/**error code** removed; input or output schema changed; policy changed; **an operation gained a required permission**; **a policy gained an enforcement site**; **a rate limit was tightened or introduced**; MCP exposure withdrawn; column removed, retyped, or made NOT NULL; **a column sealed, unsealed, or moved from `lookup` to opaque** (sealing removes the field from every output; unsealing leaves stored values ciphertext); **a column's `primaryKey` or `references` changed in either direction**; **an entity's `table` renamed**; **an invariant added**; **a job's `queue` moved or its `retry.attempts` lowered**; **a route's `surface` changed**; live query became non-live; **an admin, an admin resource or an admin route removed; an admin list's filter, sort or scope removed; its default scope moved; a row scope introduced** |
|
|
64
|
-
| **additive** | primitive added; nullable column added; **a column that lost NOT NULL**; **a sealed column moved from opaque to `lookup`** (reported: equal values now store equal strings); a required permission dropped; an enforcement site dropped; **an invariant dropped**; a rate limit loosened or removed; **more retry attempts**; MCP exposure granted; locale added; an admin, resource, route, filter, sort or scope added; a row scope removed |
|
|
85
|
+
| **breaking** | action/query/route/job/**task**/entity/**policy**/**error code** removed; input or output schema changed; policy changed; **an operation gained a required permission**; **a policy gained an enforcement site**; **a rate limit was tightened or introduced**; MCP exposure withdrawn; column removed, retyped, or made NOT NULL; **a column sealed, unsealed, or moved from `lookup` to opaque** (sealing removes the field from every output; unsealing leaves stored values ciphertext); **a column's `primaryKey` or `references` changed in either direction**; **an entity's `table` renamed**; **an invariant added**; **a job's `queue` moved or its `retry.attempts` lowered**; **a route's `surface` changed**; live query became non-live; **an admin, an admin resource or an admin route removed; an admin list's filter, sort or scope removed; its default scope moved; a row scope introduced**; **a read's row member removed, retyped or no longer required, or its row no longer published**; **a mount's prefix removed, or a name leaving its cut or moving scope** |
|
|
86
|
+
| **additive** | primitive added; nullable column added; **a column that lost NOT NULL**; **a sealed column moved from opaque to `lookup`** (reported: equal values now store equal strings); a required permission dropped; an enforcement site dropped; **an invariant dropped**; a rate limit loosened or removed; **more retry attempts**; MCP exposure granted; locale added; an admin, resource, route, filter, sort or scope added; a row scope removed; **a read's row member added, or newly required**; **a mount, scope or name added** |
|
|
65
87
|
| **internal** | cache tags changed (actions **and queries**); render mode changed; **a route's `offline`/`hydrate`/`budget`/`revalidateTags`**; **a task's `cron`/`tz`/`enqueues`**; **a job's `retry.backoff`**; **a job's `concurrency`, declared, edited or removed**; job steps reordered; **an error code's owning package**; `buildId` |
|
|
66
88
|
|
|
67
89
|
Every top-level section is classified, and that is checked rather than promised:
|
|
@@ -71,7 +93,8 @@ every scheduled task reported `internal buildId: content changed` and passed the
|
|
|
71
93
|
|
|
72
94
|
One classifier per section, each in its own file: `diff-operations.ts` (actions, queries,
|
|
73
95
|
permissions), `diff-rate-limit.ts`, `diff-entities.ts`, `diff-work.ts` (jobs, tasks),
|
|
74
|
-
`diff-routes.ts`, `diff-admin.ts`, `diff-registries.ts`
|
|
96
|
+
`diff-rows.ts`, `diff-mounts.ts`, `diff-routes.ts`, `diff-admin.ts`, `diff-registries.ts`
|
|
97
|
+
(policies, error codes), over the shared vocabulary in
|
|
75
98
|
`diff-change.ts`. `diff.ts` is the orchestrator and nothing else.
|
|
76
99
|
|
|
77
100
|
`verifyContract()` is the gate: a breaking change fails unless the app's **major** version
|
|
@@ -101,6 +124,8 @@ really does have clients to keep a promise to.
|
|
|
101
124
|
|
|
102
125
|
`checkAgentsMd()` / `assertAgentsMd()` verify that a **hand-written** `AGENTS.md` exists and
|
|
103
126
|
is under 12kB. They do not generate prose, and there is deliberately no generator to point at.
|
|
127
|
+
`x new` writes `AGENTS.md` as a relative symlink to `CLAUDE.md` (one source), and the check reads
|
|
128
|
+
through the link — so the budget holds that one file; `agentsMdMaxBytes` in `x.verify.json` raises it.
|
|
104
129
|
|
|
105
130
|
Research shows LLM-generated context files *reduce* task success and add steps: the prose
|
|
106
131
|
reads plausibly, drifts from reality the moment anything changes, and an agent trusts it over
|
|
@@ -133,7 +158,21 @@ disagree with the installed version, because it *is* the installed version.
|
|
|
133
158
|
| Entry | Source | Topic |
|
|
134
159
|
|---|---|---|
|
|
135
160
|
| `module` | the file header comment on a module `src/index.ts` re-exports, plus its public symbols | `jobs.retry` |
|
|
136
|
-
| `guide` | a `##` section of `README.md` or `CLAUDE.md`, quoted verbatim | `money.README#why-no-floats` |
|
|
161
|
+
| `guide` | a `##` section of `README.md` or `CLAUDE.md`, quoted verbatim; a fenced `##` line is code, never a heading | `money.README#why-no-floats` |
|
|
162
|
+
| `guide` | a wiki page (`scanWikiDocs(dir, origin)`): its intro, then one entry per heading, anchored as GitHub anchors it. `Error-Codes.md` is never read | `wiki.Upgrading#28x--2900-entry-by-entry` |
|
|
163
|
+
|
|
164
|
+
`githubSlug(heading)` and `wikiHeadings(markdown)` are GitHub's anchor rule, numbering included —
|
|
165
|
+
the one copy: `scripts/wiki-anchors.ts` and `scripts/release-notes.ts` import them, so a topic
|
|
166
|
+
`x docs` prints and a link the gate accepts cannot drift apart.
|
|
167
|
+
`wikiSection(markdown, anchor)` is a page's whole section — subsections included, up to the next
|
|
168
|
+
heading of its level — for `x docs Upgrading#<anchor>`. `tokenize()` is the query and name splitter
|
|
169
|
+
(camelCase and digit runs, stop words dropped); `searchDocs()` compares one-suffix stems, and at an
|
|
170
|
+
equal score ranks a guide over a source header. The ranking is not a stable surface; the regression
|
|
171
|
+
set is `docs-search-eval-set-fixture.ts`, held at 18 of 20 by `docs-search.test.ts`.
|
|
172
|
+
|
|
173
|
+
`@ultimat3/manifest/docs-search` is the ranker alone — `searchDocs`, `nearestTopics` and the
|
|
174
|
+
`DocEntry`/`DocHit` types — for a browser island that searches a prebuilt index: no scanner, no
|
|
175
|
+
`node:fs`, a few kB minified (`docs-search-subpath.test.ts` bundles it and holds that).
|
|
137
176
|
|
|
138
177
|
The **file header** is the doc unit, not JSDoc. Measured across this repo, `As of 2026-08`: 99.8%
|
|
139
178
|
of source files carry a 1–4 line header (2,510 of 2,514), while only 42.3% of public exports have
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/manifest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "30.1.0",
|
|
4
4
|
"description": "x.manifest.json: deterministic generated facts, contract diff, AGENTS.md budget",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ultimate",
|
|
7
|
+
"bun",
|
|
8
|
+
"framework",
|
|
9
|
+
"manifest",
|
|
10
|
+
"openapi",
|
|
11
|
+
"contract",
|
|
12
|
+
"agents"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/developerz-ai/ultimate/wiki/Agents",
|
|
5
15
|
"license": "MIT",
|
|
6
16
|
"type": "module",
|
|
7
17
|
"repository": {
|
|
@@ -14,7 +24,8 @@
|
|
|
14
24
|
"provenance": true
|
|
15
25
|
},
|
|
16
26
|
"exports": {
|
|
17
|
-
".": "./src/index.ts"
|
|
27
|
+
".": "./src/index.ts",
|
|
28
|
+
"./docs-search": "./src/docs-search-subpath.ts"
|
|
18
29
|
},
|
|
19
30
|
"files": [
|
|
20
31
|
"src",
|
|
@@ -32,11 +43,12 @@
|
|
|
32
43
|
"test": "bun test"
|
|
33
44
|
},
|
|
34
45
|
"dependencies": {
|
|
35
|
-
"@ultimat3/action": "
|
|
36
|
-
"@ultimat3/core": "
|
|
37
|
-
"@ultimat3/entity": "
|
|
38
|
-
"@ultimat3/jobs": "
|
|
39
|
-
"@ultimat3/query": "
|
|
40
|
-
"@ultimat3/realtime": "
|
|
46
|
+
"@ultimat3/action": "30.1.0",
|
|
47
|
+
"@ultimat3/core": "30.1.0",
|
|
48
|
+
"@ultimat3/entity": "30.1.0",
|
|
49
|
+
"@ultimat3/jobs": "30.1.0",
|
|
50
|
+
"@ultimat3/query": "30.1.0",
|
|
51
|
+
"@ultimat3/realtime": "30.1.0",
|
|
52
|
+
"@ultimat3/schema": "30.1.0"
|
|
41
53
|
}
|
|
42
54
|
}
|
package/src/build.ts
CHANGED
|
@@ -22,16 +22,19 @@ import type {
|
|
|
22
22
|
ActionFact,
|
|
23
23
|
AdminFact,
|
|
24
24
|
ChannelFact,
|
|
25
|
+
ConsumerFact,
|
|
25
26
|
EntityFact,
|
|
26
27
|
ErrorCodeFact,
|
|
27
28
|
JobFact,
|
|
28
29
|
Manifest,
|
|
30
|
+
MountFact,
|
|
29
31
|
PolicyFact,
|
|
30
32
|
QueryFact,
|
|
31
33
|
RouteFact,
|
|
32
34
|
TaskFact,
|
|
33
35
|
} from './schema';
|
|
34
36
|
import { MANIFEST_VERSION } from './schema';
|
|
37
|
+
import type { SubjectFact } from './schema-subjects';
|
|
35
38
|
|
|
36
39
|
export interface ManifestSources {
|
|
37
40
|
readonly app: { readonly name: string; readonly version: string };
|
|
@@ -41,13 +44,28 @@ export interface ManifestSources {
|
|
|
41
44
|
readonly queries?: readonly QueryFact[];
|
|
42
45
|
readonly channels?: readonly ChannelFact[];
|
|
43
46
|
readonly admin?: readonly AdminFact[];
|
|
47
|
+
readonly mounts?: readonly MountFact[];
|
|
44
48
|
readonly jobs?: readonly JobFact[];
|
|
49
|
+
readonly consumers?: readonly ConsumerFact[];
|
|
50
|
+
readonly subjects?: readonly SubjectFact[];
|
|
45
51
|
readonly tasks?: readonly TaskFact[];
|
|
46
52
|
readonly policies?: readonly PolicyFact[];
|
|
47
53
|
readonly locales?: readonly string[];
|
|
48
54
|
readonly errorCodes?: readonly ErrorCodeFact[];
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
/** Every list in a subject in code-unit order, so declaration order is never a diff. */
|
|
58
|
+
const normalizeSubject = (subject: SubjectFact): SubjectFact => ({
|
|
59
|
+
...subject,
|
|
60
|
+
tables: sortBy(subject.tables, (t) => t.entity).map((t) =>
|
|
61
|
+
t.columns === undefined ? t : { ...t, columns: [...t.columns].sort() },
|
|
62
|
+
),
|
|
63
|
+
targets: sortBy(subject.targets, (t) => t.name),
|
|
64
|
+
...(subject.links === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: { links: sortBy(subject.links, (l) => `${l.entity}.${l.column}`) }),
|
|
67
|
+
});
|
|
68
|
+
|
|
51
69
|
export function buildManifest(sources: ManifestSources): Manifest {
|
|
52
70
|
const routes = sortBy(sources.routes ?? [], (r) => r.url).map(normalizeRoute);
|
|
53
71
|
const entities = sortBy(sources.entities ?? [], (e) => e.name).map(normalizeEntity);
|
|
@@ -55,7 +73,10 @@ export function buildManifest(sources: ManifestSources): Manifest {
|
|
|
55
73
|
const queries = sortBy(sources.queries ?? [], (q) => q.name).map(normalizeQuery);
|
|
56
74
|
const channels = sortBy(sources.channels ?? [], (c) => c.name).map(normalizeChannel);
|
|
57
75
|
const admin = sortBy(sources.admin ?? [], (a) => a.basePath).map(normalizeAdmin);
|
|
76
|
+
const mounts = sortBy(sources.mounts ?? [], (m) => m.prefix).map(normalizeMount);
|
|
58
77
|
const jobs = sortBy(sources.jobs ?? [], (j) => j.name).map(normalizeJob);
|
|
78
|
+
const consumers = sortBy(sources.consumers ?? [], (c) => c.name);
|
|
79
|
+
const subjects = sortBy(sources.subjects ?? [], (s) => s.entity).map(normalizeSubject);
|
|
59
80
|
const tasks = sortBy(sources.tasks ?? [], (t) => t.name).map((t) => ({
|
|
60
81
|
...t,
|
|
61
82
|
enqueues: [...t.enqueues].sort(),
|
|
@@ -89,7 +110,13 @@ export function buildManifest(sources: ManifestSources): Manifest {
|
|
|
89
110
|
queries,
|
|
90
111
|
channels,
|
|
91
112
|
admin,
|
|
113
|
+
// Only when there is one: `[]` would stale the committed file of every app without a mount.
|
|
114
|
+
...(mounts.length === 0 ? {} : { mounts }),
|
|
92
115
|
jobs,
|
|
116
|
+
// `mounts`' rule: `[]` would stale the committed file of every app without a consumer.
|
|
117
|
+
...(consumers.length === 0 ? {} : { consumers }),
|
|
118
|
+
// The same rule: `[]` would stale every app that declares no subject.
|
|
119
|
+
...(subjects.length === 0 ? {} : { subjects }),
|
|
93
120
|
tasks,
|
|
94
121
|
policies,
|
|
95
122
|
permissions,
|
|
@@ -172,6 +199,18 @@ const normalizeChannel = (channel: ChannelFact): ChannelFact => ({
|
|
|
172
199
|
permissions: [...channel.permissions].sort(),
|
|
173
200
|
});
|
|
174
201
|
|
|
202
|
+
// A mount is a set of prefixes, each a set of scopes, each a set of names: nothing about the order
|
|
203
|
+
// they were declared in reaches a caller. `Object.fromEntries` defines, so a scope named
|
|
204
|
+
// `__proto__` stays a member rather than re-prototyping the record.
|
|
205
|
+
const normalizeMount = (mount: MountFact): MountFact => ({
|
|
206
|
+
prefix: mount.prefix,
|
|
207
|
+
scopes: Object.fromEntries(
|
|
208
|
+
Object.entries(mount.scopes)
|
|
209
|
+
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
|
|
210
|
+
.map(([scope, names]) => [scope, [...names].sort()]),
|
|
211
|
+
),
|
|
212
|
+
});
|
|
213
|
+
|
|
175
214
|
// Job steps keep their DECLARED order — a job's steps are a sequence, not a set, and
|
|
176
215
|
// sorting them would misrepresent the program.
|
|
177
216
|
const normalizeJob = (job: JobFact): JobFact => ({ ...job, steps: [...job.steps] });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// `consumer()` declarations in a contract diff. Its job and its supervisor task are judged by
|
|
2
|
+
// `diff-work.ts` already; this file sees the one fact neither does — that a stream stopped being
|
|
3
|
+
// read. Removal is breaking (nothing throws, the cursor simply stops); every other field internal.
|
|
4
|
+
|
|
5
|
+
import type { ManifestChange } from './diff-change';
|
|
6
|
+
import { diffScalar, index } from './diff-change';
|
|
7
|
+
import type { ConsumerFact } from './schema';
|
|
8
|
+
|
|
9
|
+
const FIELDS = ['queue', 'supervisor', 'arm', 'rearm', 'batch', 'lags'] as const;
|
|
10
|
+
|
|
11
|
+
export function diffConsumers(
|
|
12
|
+
before: readonly ConsumerFact[],
|
|
13
|
+
after: readonly ConsumerFact[],
|
|
14
|
+
): readonly ManifestChange[] {
|
|
15
|
+
const changes: ManifestChange[] = [];
|
|
16
|
+
const afterByName = index(after, (consumer) => consumer.name);
|
|
17
|
+
const beforeByName = index(before, (consumer) => consumer.name);
|
|
18
|
+
|
|
19
|
+
for (const consumer of before) {
|
|
20
|
+
const path = `consumers.${consumer.name}`;
|
|
21
|
+
const next = afterByName.get(consumer.name);
|
|
22
|
+
if (next === undefined) {
|
|
23
|
+
changes.push({
|
|
24
|
+
kind: 'breaking',
|
|
25
|
+
path,
|
|
26
|
+
detail: 'consumer removed; its stream is never read',
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
for (const field of FIELDS) {
|
|
31
|
+
changes.push(...diffScalar('internal', `${path}.${field}`, consumer[field], next[field]));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const consumer of after) {
|
|
35
|
+
if (!beforeByName.has(consumer.name)) {
|
|
36
|
+
changes.push({
|
|
37
|
+
kind: 'additive',
|
|
38
|
+
path: `consumers.${consumer.name}`,
|
|
39
|
+
detail: 'consumer added',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return changes;
|
|
44
|
+
}
|
package/src/diff-entities.ts
CHANGED
|
@@ -34,6 +34,9 @@ export function diffEntities(
|
|
|
34
34
|
);
|
|
35
35
|
changes.push(...diffColumns(path, entity, next));
|
|
36
36
|
changes.push(...diffInvariants(`${path}.invariants`, entity.invariants, next.invariants));
|
|
37
|
+
changes.push(...diffReason('shared', `${path}.shared`, entity.shared, next.shared));
|
|
38
|
+
changes.push(...diffReason('scan', `${path}.scan`, entity.scan, next.scan));
|
|
39
|
+
changes.push(...diffView(`${path}.view`, entity.view, next.view));
|
|
37
40
|
}
|
|
38
41
|
for (const entity of after) {
|
|
39
42
|
if (!beforeByName.has(entity.name)) {
|
|
@@ -74,6 +77,53 @@ function diffInvariants(
|
|
|
74
77
|
];
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
/**
|
|
81
|
+
* `shared` and `scan` are reasons, never constraints: no row is refused and no field moves on any
|
|
82
|
+
* wire, so every move is additive. Reported all the same — a reviewer reads why a table belongs to
|
|
83
|
+
* no tenant, or why it may be read whole.
|
|
84
|
+
*/
|
|
85
|
+
function diffReason(
|
|
86
|
+
label: 'shared' | 'scan',
|
|
87
|
+
path: string,
|
|
88
|
+
before: string | undefined,
|
|
89
|
+
after: string | undefined,
|
|
90
|
+
): readonly ManifestChange[] {
|
|
91
|
+
if (before === after) return [];
|
|
92
|
+
const detail =
|
|
93
|
+
before === undefined
|
|
94
|
+
? `${label} declared: ${after}`
|
|
95
|
+
: after === undefined
|
|
96
|
+
? `${label} reason dropped`
|
|
97
|
+
: `${label} reason ${before} -> ${after}`;
|
|
98
|
+
return [{ kind: 'additive', path, detail }];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A table becoming a view refuses every write that worked a moment ago; a view becoming a table
|
|
103
|
+
* only widens. Stored or not moves no row any reader sees, only when they are recomputed.
|
|
104
|
+
*/
|
|
105
|
+
function diffView(
|
|
106
|
+
path: string,
|
|
107
|
+
before: EntityFact['view'],
|
|
108
|
+
after: EntityFact['view'],
|
|
109
|
+
): readonly ManifestChange[] {
|
|
110
|
+
if (before === undefined && after === undefined) return [];
|
|
111
|
+
if (before === undefined) {
|
|
112
|
+
return [{ kind: 'breaking', path, detail: 'became a view; every write is refused' }];
|
|
113
|
+
}
|
|
114
|
+
if (after === undefined) {
|
|
115
|
+
return [{ kind: 'additive', path, detail: 'became a table; writes are accepted' }];
|
|
116
|
+
}
|
|
117
|
+
if (before.materialized === after.materialized) return [];
|
|
118
|
+
return [
|
|
119
|
+
{
|
|
120
|
+
kind: 'internal',
|
|
121
|
+
path,
|
|
122
|
+
detail: after.materialized ? 'view became materialized' : 'view is no longer materialized',
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
|
|
77
127
|
function diffColumns(
|
|
78
128
|
path: string,
|
|
79
129
|
before: EntityFact,
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// One rule: how a declared meter moved, judged by what it refuses. A meter tightened refuses a
|
|
2
|
+
// caller the old build served and leaves every schema in the manifest untouched, so nothing else
|
|
3
|
+
// in the diff can see it — `diff-rate-limit.ts`'s reason, one period longer.
|
|
4
|
+
|
|
5
|
+
import type { ManifestChange } from './diff-change';
|
|
6
|
+
import type { ActionFact, MeterFact } from './schema';
|
|
7
|
+
|
|
8
|
+
type MeterReading = MeterFact | 'none' | 'unreadable';
|
|
9
|
+
|
|
10
|
+
const PERIOD_RANK = new Map<string, number>([
|
|
11
|
+
['hour', 0],
|
|
12
|
+
['day', 1],
|
|
13
|
+
['month', 2],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The most periods of `inner` one period of `outer` holds — UTC, so no DST-length day: 24 hours a
|
|
18
|
+
* day, at most 31 days a month. Keyed `inner>outer`, a `Map` for the proto-index guard's reason.
|
|
19
|
+
*/
|
|
20
|
+
const MOST_NESTED = new Map<string, number>([
|
|
21
|
+
['hour>day', 24],
|
|
22
|
+
['day>month', 31],
|
|
23
|
+
['hour>month', 744],
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export function diffMeter(
|
|
27
|
+
path: string,
|
|
28
|
+
before: ActionFact,
|
|
29
|
+
after: ActionFact,
|
|
30
|
+
): readonly ManifestChange[] {
|
|
31
|
+
const declared = readMeter(before);
|
|
32
|
+
const next = readMeter(after);
|
|
33
|
+
if (declared === 'unreadable' || next === 'unreadable') return [];
|
|
34
|
+
const at = `${path}.meter`;
|
|
35
|
+
|
|
36
|
+
if (declared === 'none') {
|
|
37
|
+
if (next === 'none') return [];
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
kind: 'breaking',
|
|
41
|
+
path: at,
|
|
42
|
+
detail: `meter introduced (${render(next)}); an unmetered caller can now be refused`,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
if (next === 'none') {
|
|
47
|
+
return [{ kind: 'additive', path: at, detail: `meter removed (was ${render(declared)})` }];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const changes: ManifestChange[] = [];
|
|
51
|
+
// The name is a counter's identity AND a key of the refusal's public `meta` a client may
|
|
52
|
+
// switch on, so a rename is a wire change whatever the allowance did.
|
|
53
|
+
if (declared.name !== next.name) {
|
|
54
|
+
changes.push({
|
|
55
|
+
kind: 'breaking',
|
|
56
|
+
path: `${at}.name`,
|
|
57
|
+
detail: `meter renamed ${declared.name} -> ${next.name}; a client reading meta.meter sees another name`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (declared.warnAt !== next.warnAt) {
|
|
61
|
+
changes.push({
|
|
62
|
+
kind: 'internal',
|
|
63
|
+
path: `${at}.warnAt`,
|
|
64
|
+
detail: `warnAt ${String(declared.warnAt)} -> ${String(next.warnAt)}`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const allowance = classifyAllowance(declared, next);
|
|
68
|
+
if (allowance !== undefined) {
|
|
69
|
+
const detail = `meter ${allowanceWord(allowance)} ${render(declared)} -> ${render(next)}`;
|
|
70
|
+
changes.push({ kind: allowance, path: at, detail });
|
|
71
|
+
}
|
|
72
|
+
return changes;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const allowanceWord = (kind: ManifestChange['kind']): string =>
|
|
76
|
+
kind === 'breaking'
|
|
77
|
+
? 'tightened; a caller within the old allowance is refused:'
|
|
78
|
+
: kind === 'additive'
|
|
79
|
+
? 'loosened'
|
|
80
|
+
: 'moved, refusing every call on both sides:';
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Breaking iff some call pattern the old meter admitted is refused by the new one. Periods nest,
|
|
84
|
+
* so the old meter's heaviest admitted load on one NEW period is `limit` when the new period is
|
|
85
|
+
* no longer, and `limit × MOST_NESTED` when it is longer. Anything else that differs admits more.
|
|
86
|
+
*/
|
|
87
|
+
function classifyAllowance(from: MeterFact, to: MeterFact): ManifestChange['kind'] | undefined {
|
|
88
|
+
if (from.limit === to.limit && from.period === to.period) return undefined;
|
|
89
|
+
if (from.limit === null || to.limit === null) {
|
|
90
|
+
// A per-call limit is the app's function of the tenant: no static number proves that a
|
|
91
|
+
// tenant the old build served still is, so a move to or from one is breaking...
|
|
92
|
+
if (from.limit !== to.limit) return 'breaking';
|
|
93
|
+
// ...and two of them are taken as the same resolver over a moved period.
|
|
94
|
+
return rank(to.period) > rank(from.period) ? 'breaking' : 'additive';
|
|
95
|
+
}
|
|
96
|
+
if (from.limit === 0 && to.limit === 0) return 'internal';
|
|
97
|
+
const heaviest = from.limit * nested(from.period, to.period);
|
|
98
|
+
return to.limit < heaviest ? 'breaking' : 'additive';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const rank = (period: string): number => PERIOD_RANK.get(period) ?? 0;
|
|
102
|
+
|
|
103
|
+
const nested = (inner: string, outer: string): number =>
|
|
104
|
+
rank(outer) > rank(inner) ? (MOST_NESTED.get(`${inner}>${outer}`) ?? 1) : 1;
|
|
105
|
+
|
|
106
|
+
const render = (meter: MeterFact): string =>
|
|
107
|
+
`${meter.limit === null ? 'per-call' : meter.limit}/${meter.period}@${meter.timeZone}`;
|
|
108
|
+
|
|
109
|
+
/** The shape `meterFact` writes; anything else is a file this reader cannot judge. */
|
|
110
|
+
function readMeter(fact: ActionFact): MeterReading {
|
|
111
|
+
const value: unknown = fact.meter;
|
|
112
|
+
if (value === undefined || value === null) return 'none';
|
|
113
|
+
if (typeof value !== 'object') return 'unreadable';
|
|
114
|
+
const record = value as Record<string, unknown>;
|
|
115
|
+
const { name, period, timeZone, limit, warnAt } = record;
|
|
116
|
+
if (typeof name !== 'string' || typeof period !== 'string' || !PERIOD_RANK.has(period)) {
|
|
117
|
+
return 'unreadable';
|
|
118
|
+
}
|
|
119
|
+
// Only UTC exists; a zone this reader does not know cuts periods it cannot compare.
|
|
120
|
+
if (timeZone !== 'UTC') return 'unreadable';
|
|
121
|
+
if (limit !== null && !(typeof limit === 'number' && Number.isSafeInteger(limit) && limit >= 0)) {
|
|
122
|
+
return 'unreadable';
|
|
123
|
+
}
|
|
124
|
+
const warning = typeof warnAt === 'number' ? warnAt : null;
|
|
125
|
+
return {
|
|
126
|
+
name,
|
|
127
|
+
period: period as MeterFact['period'],
|
|
128
|
+
timeZone,
|
|
129
|
+
limit: limit as number | null,
|
|
130
|
+
warnAt: warning,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// A bearer mount's cut in a contract diff. The primitive behind a name stays registered when a name
|
|
2
|
+
// leaves a mount, so `diffActions` and `diffQueries` see nothing: only this file sees a held token's
|
|
3
|
+
// call turn into a 404. Judged per (scope, name), because a token reaches what its scopes list.
|
|
4
|
+
|
|
5
|
+
import type { ManifestChange } from './diff-change';
|
|
6
|
+
import { index } from './diff-change';
|
|
7
|
+
import type { MountFact } from './schema';
|
|
8
|
+
|
|
9
|
+
export function diffMounts(
|
|
10
|
+
before: readonly MountFact[],
|
|
11
|
+
after: readonly MountFact[],
|
|
12
|
+
): readonly ManifestChange[] {
|
|
13
|
+
const changes: ManifestChange[] = [];
|
|
14
|
+
const afterByPrefix = index(after, (mount) => mount.prefix);
|
|
15
|
+
const beforeByPrefix = index(before, (mount) => mount.prefix);
|
|
16
|
+
|
|
17
|
+
for (const mount of before) {
|
|
18
|
+
const path = `mounts.${mount.prefix}`;
|
|
19
|
+
const next = afterByPrefix.get(mount.prefix);
|
|
20
|
+
if (next === undefined) {
|
|
21
|
+
changes.push({ kind: 'breaking', path, detail: 'mount removed; every call under it is 404' });
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
changes.push(...diffScopes(path, mount.scopes, next.scopes));
|
|
25
|
+
}
|
|
26
|
+
for (const mount of after) {
|
|
27
|
+
if (!beforeByPrefix.has(mount.prefix)) {
|
|
28
|
+
changes.push({ kind: 'additive', path: `mounts.${mount.prefix}`, detail: 'mount added' });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return changes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Scopes = MountFact['scopes'];
|
|
35
|
+
|
|
36
|
+
const scopesHolding = (scopes: Scopes, name: string): readonly string[] =>
|
|
37
|
+
Object.entries(scopes)
|
|
38
|
+
.filter(([, names]) => names.includes(name))
|
|
39
|
+
.map(([scope]) => scope);
|
|
40
|
+
|
|
41
|
+
function diffScopes(path: string, before: Scopes, after: Scopes): readonly ManifestChange[] {
|
|
42
|
+
const changes: ManifestChange[] = [];
|
|
43
|
+
for (const [scope, names] of Object.entries(before)) {
|
|
44
|
+
const scopePath = `${path}.scopes.${scope}`;
|
|
45
|
+
const kept = Object.hasOwn(after, scope) ? (after[scope] ?? []) : [];
|
|
46
|
+
if (names.length === 0 && !Object.hasOwn(after, scope)) {
|
|
47
|
+
changes.push({ kind: 'internal', path: scopePath, detail: 'empty scope removed' });
|
|
48
|
+
}
|
|
49
|
+
for (const name of names) {
|
|
50
|
+
if (kept.includes(name)) continue;
|
|
51
|
+
const elsewhere = scopesHolding(after, name);
|
|
52
|
+
changes.push({
|
|
53
|
+
kind: 'breaking',
|
|
54
|
+
path: `${scopePath}.${name}`,
|
|
55
|
+
detail:
|
|
56
|
+
elsewhere.length === 0
|
|
57
|
+
? 'left the cut; a held token now answers 404'
|
|
58
|
+
: `moved to ${elsewhere.join(', ')}; a token holding ${scope} now answers 404`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const [scope, names] of Object.entries(after)) {
|
|
63
|
+
const scopePath = `${path}.scopes.${scope}`;
|
|
64
|
+
const known = Object.hasOwn(before, scope);
|
|
65
|
+
if (!known) changes.push({ kind: 'additive', path: scopePath, detail: 'scope added' });
|
|
66
|
+
for (const name of names) {
|
|
67
|
+
if (known && (before[scope] ?? []).includes(name)) continue;
|
|
68
|
+
changes.push({ kind: 'additive', path: `${scopePath}.${name}`, detail: 'added to the cut' });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return changes;
|
|
72
|
+
}
|