@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/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 +74 -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 +108 -1
- package/src/sources.ts +101 -3
package/src/diff-operations.ts
CHANGED
|
@@ -5,8 +5,11 @@ import { canonicalJson, isMcpExposed } from '@ultimat3/core';
|
|
|
5
5
|
import type { ManifestChange } from './diff-change';
|
|
6
6
|
import { diffScalar, index } from './diff-change';
|
|
7
7
|
import { diffInput } from './diff-input';
|
|
8
|
+
import { diffMeter } from './diff-meter';
|
|
8
9
|
import { diffRateLimit } from './diff-rate-limit';
|
|
9
|
-
import
|
|
10
|
+
import { diffDeclaredErrors } from './diff-registries';
|
|
11
|
+
import { diffRows } from './diff-rows';
|
|
12
|
+
import type { ActionFact, HttpPinFact, QueryFact } from './schema';
|
|
10
13
|
|
|
11
14
|
/** Any fact that names the permissions it requires — an action, a query, a channel. */
|
|
12
15
|
export interface PermissionBearing {
|
|
@@ -84,7 +87,10 @@ export function diffActions(
|
|
|
84
87
|
});
|
|
85
88
|
}
|
|
86
89
|
changes.push(...diffPermissions(path, action, next));
|
|
90
|
+
changes.push(...diffHttpPin(path, action.http, next.http));
|
|
91
|
+
changes.push(...diffDeclaredErrors(path, action.errors, next.errors));
|
|
87
92
|
changes.push(...diffRateLimit(path, action, next));
|
|
93
|
+
changes.push(...diffMeter(path, action, next));
|
|
88
94
|
if (canonicalJson(action.cacheInvalidates) !== canonicalJson(next.cacheInvalidates)) {
|
|
89
95
|
changes.push({
|
|
90
96
|
kind: 'internal',
|
|
@@ -121,6 +127,21 @@ export function diffQueries(
|
|
|
121
127
|
if (query.input !== undefined && next.input !== undefined) {
|
|
122
128
|
changes.push(...diffInput(`${path}.input`, query.input, next.input, 'input schema changed'));
|
|
123
129
|
}
|
|
130
|
+
// `rows` on `before` proves its writer knew the field, and `after` is always this build, so a
|
|
131
|
+
// row gone from `after` is the published 200 falling back to `items: {}`: breaking, no version
|
|
132
|
+
// needed. Absent on `before` is ambiguous (older file, or newly declared) and only widens.
|
|
133
|
+
// Members, never `canonicalJson`: see `diff-rows.ts`.
|
|
134
|
+
if (query.rows !== undefined && next.rows !== undefined) {
|
|
135
|
+
changes.push(...diffRows(`${path}.rows`, query.rows, next.rows));
|
|
136
|
+
} else if (query.rows !== undefined) {
|
|
137
|
+
changes.push({
|
|
138
|
+
kind: 'breaking',
|
|
139
|
+
path: `${path}.rows`,
|
|
140
|
+
detail: 'row no longer published; the 200 is untyped',
|
|
141
|
+
});
|
|
142
|
+
} else if (next.rows !== undefined) {
|
|
143
|
+
changes.push({ kind: 'additive', path: `${path}.rows`, detail: 'row published' });
|
|
144
|
+
}
|
|
124
145
|
if (query.policy !== next.policy) {
|
|
125
146
|
changes.push({
|
|
126
147
|
kind: 'breaking',
|
|
@@ -129,6 +150,8 @@ export function diffQueries(
|
|
|
129
150
|
});
|
|
130
151
|
}
|
|
131
152
|
changes.push(...diffPermissions(path, query, next));
|
|
153
|
+
changes.push(...diffHttpPin(path, query.http, next.http));
|
|
154
|
+
changes.push(...diffDeclaredErrors(path, query.errors, next.errors));
|
|
132
155
|
if (query.live !== next.live) {
|
|
133
156
|
// Losing live-ness breaks subscribers; gaining it breaks nobody.
|
|
134
157
|
changes.push({
|
|
@@ -137,6 +160,15 @@ export function diffQueries(
|
|
|
137
160
|
detail: `live ${String(query.live)} -> ${String(next.live)}`,
|
|
138
161
|
});
|
|
139
162
|
}
|
|
163
|
+
// Rows one side, a minted URL and a file the other: every caller of the read is written
|
|
164
|
+
// against one answer, so the flip breaks them whichever way it goes.
|
|
165
|
+
if ((query.download === true) !== (next.download === true)) {
|
|
166
|
+
changes.push({
|
|
167
|
+
kind: 'breaking',
|
|
168
|
+
path: `${path}.download`,
|
|
169
|
+
detail: next.download === true ? 'rows -> download' : 'download -> rows',
|
|
170
|
+
});
|
|
171
|
+
}
|
|
140
172
|
// The same fact as an action's `cacheInvalidates`, and the same class: which tag flushes a
|
|
141
173
|
// read is not a caller's contract, but a reviewer has to see it move.
|
|
142
174
|
if (canonicalJson(query.cacheTags) !== canonicalJson(next.cacheTags)) {
|
|
@@ -160,6 +192,47 @@ export function diffQueries(
|
|
|
160
192
|
return changes;
|
|
161
193
|
}
|
|
162
194
|
|
|
195
|
+
/**
|
|
196
|
+
* A pinned `http: { path, method }` moving: every caller holding the URL or the verb is refused
|
|
197
|
+
* (`404`/`405`), so a changed or withdrawn pin is breaking. A pin appearing where `before` had
|
|
198
|
+
* none is additive: a manifest written before the fact existed carries no `http` for a pin that
|
|
199
|
+
* was always there, and reading that as a move would flag every pinned action on upgrade.
|
|
200
|
+
*/
|
|
201
|
+
export function diffHttpPin(
|
|
202
|
+
path: string,
|
|
203
|
+
before: HttpPinFact | undefined,
|
|
204
|
+
after: HttpPinFact | undefined,
|
|
205
|
+
): readonly ManifestChange[] {
|
|
206
|
+
if (before === undefined) {
|
|
207
|
+
return after === undefined
|
|
208
|
+
? []
|
|
209
|
+
: [
|
|
210
|
+
{
|
|
211
|
+
kind: 'additive',
|
|
212
|
+
path: `${path}.http`,
|
|
213
|
+
detail: `pinned ${after.method} ${after.path}`,
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
if (after === undefined) {
|
|
218
|
+
return [
|
|
219
|
+
{
|
|
220
|
+
kind: 'breaking',
|
|
221
|
+
path: `${path}.http`,
|
|
222
|
+
detail: `${before.method} ${before.path} unpinned`,
|
|
223
|
+
},
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
if (before.method === after.method && before.path === after.path) return [];
|
|
227
|
+
return [
|
|
228
|
+
{
|
|
229
|
+
kind: 'breaking',
|
|
230
|
+
path: `${path}.http`,
|
|
231
|
+
detail: `${before.method} ${before.path} -> ${after.method} ${after.path}`,
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
|
|
163
236
|
/**
|
|
164
237
|
* The permissions an operation REQUIRES, and the direction each move points.
|
|
165
238
|
*
|
package/src/diff-rate-limit.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// One rule: how a declared rate limit moved. A tightened limit refuses a caller the old pair
|
|
2
2
|
// served, which is the definition of breaking — and it is the one contract change that leaves
|
|
3
|
-
// every schema in the manifest untouched, so nothing else in the diff can see it.
|
|
3
|
+
// every schema in the manifest untouched, so nothing else in the diff can see it. A limit resolved
|
|
4
|
+
// per call is judged as `diff-meter.ts` judges a per-call meter.
|
|
4
5
|
|
|
5
6
|
import type { ManifestChange } from './diff-change';
|
|
6
7
|
import type { ActionFact, RateLimitFact } from './schema';
|
|
7
8
|
|
|
9
|
+
/** A limit resolved per call: only its window is a static fact. */
|
|
10
|
+
interface PerCallReading {
|
|
11
|
+
readonly perCall: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
/** No declaration at all, a declaration, or one this reader cannot make sense of. */
|
|
9
|
-
type RateLimitReading = RateLimitFact | 'none' | 'unreadable';
|
|
15
|
+
type RateLimitReading = RateLimitFact | PerCallReading | 'none' | 'unreadable';
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* Introducing a limit where there was none is the same event at its extreme: a client that was
|
|
@@ -35,6 +41,7 @@ export function diffRateLimit(
|
|
|
35
41
|
if (next === 'none') {
|
|
36
42
|
return [{ kind: 'additive', path: at, detail: `rate limit removed (was ${render(declared)})` }];
|
|
37
43
|
}
|
|
44
|
+
if ('perCall' in declared || 'perCall' in next) return perCall(at, declared, next);
|
|
38
45
|
if (tighter(declared, next)) {
|
|
39
46
|
return [
|
|
40
47
|
{
|
|
@@ -66,10 +73,45 @@ export function diffRateLimit(
|
|
|
66
73
|
const tighter = (from: RateLimitFact, to: RateLimitFact): boolean =>
|
|
67
74
|
to.limit < from.limit || to.limit * from.windowMs < from.limit * to.windowMs;
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
/**
|
|
77
|
+
* A per-call limit is the app's function of the caller, so no static number proves a caller the
|
|
78
|
+
* old build served still is: a move to or from one is breaking. Two of them are taken as the same
|
|
79
|
+
* resolver over a moved window, where a longer window refills slower.
|
|
80
|
+
*/
|
|
81
|
+
function perCall(
|
|
82
|
+
at: string,
|
|
83
|
+
from: RateLimitFact | PerCallReading,
|
|
84
|
+
to: RateLimitFact | PerCallReading,
|
|
85
|
+
): readonly ManifestChange[] {
|
|
86
|
+
const moved = `${render(from)} -> ${render(to)}`;
|
|
87
|
+
if (!('perCall' in from) || !('perCall' in to)) {
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
kind: 'breaking',
|
|
91
|
+
path: at,
|
|
92
|
+
detail: `rate limit ${moved}; no static limit proves an old caller is still served`,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
if (to.perCall === from.perCall) return [];
|
|
97
|
+
return to.perCall > from.perCall
|
|
98
|
+
? [{ kind: 'breaking', path: at, detail: `per-call rate limit window lengthened ${moved}` }]
|
|
99
|
+
: [{ kind: 'additive', path: at, detail: `per-call rate limit window shortened ${moved}` }];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const render = (limit: RateLimitFact | PerCallReading): string =>
|
|
103
|
+
'perCall' in limit ? `per-call/${limit.perCall}ms` : `${limit.limit}/${limit.windowMs}ms`;
|
|
70
104
|
|
|
71
105
|
function readRateLimit(fact: ActionFact): RateLimitReading {
|
|
72
106
|
const value: unknown = fact.rateLimit;
|
|
107
|
+
const perCallValue: unknown = fact.rateLimitPerCall;
|
|
108
|
+
if (perCallValue !== undefined && perCallValue !== null) {
|
|
109
|
+
// `describe()` publishes one or the other, never both: a file carrying both is not its output.
|
|
110
|
+
if (value !== undefined && value !== null) return 'unreadable';
|
|
111
|
+
if (typeof perCallValue !== 'object') return 'unreadable';
|
|
112
|
+
const windowMs = (perCallValue as Record<string, unknown>)['windowMs'];
|
|
113
|
+
return positive(windowMs) ? { perCall: windowMs } : 'unreadable';
|
|
114
|
+
}
|
|
73
115
|
if (value === undefined || value === null) return 'none';
|
|
74
116
|
if (typeof value !== 'object') return 'unreadable';
|
|
75
117
|
const record = value as Record<string, unknown>;
|
package/src/diff-registries.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
3
|
-
// on — a permission it grants, a code it branches on — so losing an entry is
|
|
4
|
-
// metadata beside it is internal.
|
|
1
|
+
// The declaration registries: `policies` (a permission, where it is enforced), `errorCodes` (a
|
|
2
|
+
// code, the package that owns it) and an operation's declared `errors:`. Each is keyed by a string
|
|
3
|
+
// a consumer matches on — a permission it grants, a code it branches on — so losing an entry is
|
|
4
|
+
// breaking and the metadata beside it is internal.
|
|
5
5
|
|
|
6
6
|
import type { ManifestChange } from './diff-change';
|
|
7
7
|
import { diffScalar, index } from './diff-change';
|
|
@@ -114,3 +114,49 @@ export function diffErrorCodes(
|
|
|
114
114
|
}
|
|
115
115
|
return changes;
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* An action's or a query's `errors:` (`ActionFact.errors`, `QueryFact.errors`), code by code: a
|
|
120
|
+
* caller branches on each, so a code leaving the list is breaking and one joining it additive.
|
|
121
|
+
* Absent is the open contract — declaring a list adds a promise, dropping it withdraws every one.
|
|
122
|
+
* For `diffActions`/`diffQueries` to call per operation, with the operation's dotted path.
|
|
123
|
+
*/
|
|
124
|
+
export function diffDeclaredErrors(
|
|
125
|
+
path: string,
|
|
126
|
+
before: readonly string[] | undefined,
|
|
127
|
+
after: readonly string[] | undefined,
|
|
128
|
+
): readonly ManifestChange[] {
|
|
129
|
+
if (before === undefined && after === undefined) return [];
|
|
130
|
+
if (before === undefined) {
|
|
131
|
+
return [{ kind: 'additive', path: `${path}.errors`, detail: 'errors declared' }];
|
|
132
|
+
}
|
|
133
|
+
if (after === undefined) {
|
|
134
|
+
return [
|
|
135
|
+
{
|
|
136
|
+
kind: 'breaking',
|
|
137
|
+
path: `${path}.errors`,
|
|
138
|
+
detail: 'errors list removed; the codes it declared are no longer a contract',
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
const kept = new Set(after);
|
|
143
|
+
const had = new Set(before);
|
|
144
|
+
return [
|
|
145
|
+
...[...before]
|
|
146
|
+
.sort()
|
|
147
|
+
.filter((code) => !kept.has(code))
|
|
148
|
+
.map((code) => ({
|
|
149
|
+
kind: 'breaking' as const,
|
|
150
|
+
path: `${path}.errors.${code}`,
|
|
151
|
+
detail: 'declared error removed; a caller branching on it is no longer told it can happen',
|
|
152
|
+
})),
|
|
153
|
+
...[...after]
|
|
154
|
+
.sort()
|
|
155
|
+
.filter((code) => !had.has(code))
|
|
156
|
+
.map((code) => ({
|
|
157
|
+
kind: 'additive' as const,
|
|
158
|
+
path: `${path}.errors.${code}`,
|
|
159
|
+
detail: 'declared error added',
|
|
160
|
+
})),
|
|
161
|
+
];
|
|
162
|
+
}
|
package/src/diff-rows.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// A read's declared row in a contract diff, member by member. Never `canonicalJson` inequality as
|
|
2
|
+
// for an action's output (`diff-operations.ts`): an entity gaining a column would flip every
|
|
3
|
+
// `rows: X.$schema` read to breaking. The axis is what a client decoding the row can no longer rely
|
|
4
|
+
// on. A schema this cannot walk (a union, an enum) compares whole: over-reporting is the safe side.
|
|
5
|
+
|
|
6
|
+
import { canonicalJson, isJsonObject } from '@ultimat3/core';
|
|
7
|
+
import type { ManifestChange } from './diff-change';
|
|
8
|
+
|
|
9
|
+
/** Prose for a reader: what no decoder acts on, so it can never be a contract change. */
|
|
10
|
+
const ANNOTATIONS = new Set(['title', 'description']);
|
|
11
|
+
/** Everything but prose and the keys walked below has to match whole. */
|
|
12
|
+
const NOT_WHOLE = new Set([...ANNOTATIONS, 'properties', 'required', 'items']);
|
|
13
|
+
|
|
14
|
+
const whole = (schema: object): Readonly<Record<string, unknown>> =>
|
|
15
|
+
Object.fromEntries(Object.entries(schema).filter(([key]) => !NOT_WHOLE.has(key)));
|
|
16
|
+
|
|
17
|
+
const requiredOf = (schema: Readonly<Record<string, unknown>>): ReadonlySet<string> => {
|
|
18
|
+
const required = schema['required'];
|
|
19
|
+
return new Set(
|
|
20
|
+
Array.isArray(required)
|
|
21
|
+
? required.filter((item): item is string => typeof item === 'string')
|
|
22
|
+
: [],
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const same = (left: unknown, right: unknown): boolean =>
|
|
27
|
+
canonicalJson(left) === canonicalJson(right);
|
|
28
|
+
|
|
29
|
+
const retyped = (path: string): ManifestChange => ({
|
|
30
|
+
kind: 'breaking',
|
|
31
|
+
path,
|
|
32
|
+
detail: 'row member retyped',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** The change between two row schemas at `path`: `queries.<name>.rows`, then one per member. */
|
|
36
|
+
export function diffRows(path: string, before: unknown, after: unknown): readonly ManifestChange[] {
|
|
37
|
+
if (same(before, after)) return [];
|
|
38
|
+
if (!isJsonObject(before) || !isJsonObject(after)) return [retyped(path)];
|
|
39
|
+
if (!same(whole(before), whole(after))) return [retyped(path)];
|
|
40
|
+
const changes: ManifestChange[] = [];
|
|
41
|
+
if (!sameAnnotations(before, after)) {
|
|
42
|
+
changes.push({ kind: 'internal', path, detail: 'row description changed' });
|
|
43
|
+
}
|
|
44
|
+
changes.push(...diffItems(path, before['items'], after['items']));
|
|
45
|
+
const members = before['properties'];
|
|
46
|
+
const nextMembers = after['properties'];
|
|
47
|
+
if (isJsonObject(members) && isJsonObject(nextMembers)) {
|
|
48
|
+
changes.push(...diffMembers(path, before, after, members, nextMembers));
|
|
49
|
+
} else if (!same(members, nextMembers)) {
|
|
50
|
+
changes.push(retyped(path));
|
|
51
|
+
} else {
|
|
52
|
+
// No members to walk, but `required` still promises names: compared as a set of its own.
|
|
53
|
+
changes.push(...diffRequired(path, requiredOf(before), requiredOf(after)));
|
|
54
|
+
}
|
|
55
|
+
return changes;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function diffRequired(
|
|
59
|
+
path: string,
|
|
60
|
+
before: ReadonlySet<string>,
|
|
61
|
+
after: ReadonlySet<string>,
|
|
62
|
+
): readonly ManifestChange[] {
|
|
63
|
+
const changes: ManifestChange[] = [];
|
|
64
|
+
for (const name of before) {
|
|
65
|
+
if (!after.has(name)) {
|
|
66
|
+
changes.push({
|
|
67
|
+
kind: 'breaking',
|
|
68
|
+
path: `${path}.${name}`,
|
|
69
|
+
detail: 'row member no longer required',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const name of after) {
|
|
74
|
+
if (!before.has(name)) {
|
|
75
|
+
changes.push({
|
|
76
|
+
kind: 'additive',
|
|
77
|
+
path: `${path}.${name}`,
|
|
78
|
+
detail: 'row member now required',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return changes;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function sameAnnotations(
|
|
86
|
+
before: Readonly<Record<string, unknown>>,
|
|
87
|
+
after: Readonly<Record<string, unknown>>,
|
|
88
|
+
): boolean {
|
|
89
|
+
return [...ANNOTATIONS].every((key) => same(before[key] ?? null, after[key] ?? null));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function diffItems(path: string, before: unknown, after: unknown): readonly ManifestChange[] {
|
|
93
|
+
if (before === undefined && after === undefined) return [];
|
|
94
|
+
if (before === undefined || after === undefined) return [retyped(path)];
|
|
95
|
+
return diffRows(`${path}[]`, before, after);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function diffMembers(
|
|
99
|
+
path: string,
|
|
100
|
+
before: Readonly<Record<string, unknown>>,
|
|
101
|
+
after: Readonly<Record<string, unknown>>,
|
|
102
|
+
members: Readonly<Record<string, unknown>>,
|
|
103
|
+
nextMembers: Readonly<Record<string, unknown>>,
|
|
104
|
+
): readonly ManifestChange[] {
|
|
105
|
+
const changes: ManifestChange[] = [];
|
|
106
|
+
const required = requiredOf(before);
|
|
107
|
+
const nextRequired = requiredOf(after);
|
|
108
|
+
for (const [name, schema] of Object.entries(members)) {
|
|
109
|
+
const memberPath = `${path}.${name}`;
|
|
110
|
+
if (!Object.hasOwn(nextMembers, name)) {
|
|
111
|
+
changes.push({ kind: 'breaking', path: memberPath, detail: 'row member removed' });
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
changes.push(...diffRows(memberPath, schema, nextMembers[name]));
|
|
115
|
+
if (required.has(name) && !nextRequired.has(name)) {
|
|
116
|
+
changes.push({ kind: 'breaking', path: memberPath, detail: 'row member no longer required' });
|
|
117
|
+
} else if (!required.has(name) && nextRequired.has(name)) {
|
|
118
|
+
changes.push({ kind: 'additive', path: memberPath, detail: 'row member now required' });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const name of Object.keys(nextMembers)) {
|
|
122
|
+
if (!Object.hasOwn(members, name)) {
|
|
123
|
+
changes.push({ kind: 'additive', path: `${path}.${name}`, detail: 'row member added' });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return changes;
|
|
127
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// `subjects` under `x manifest diff`: a subject removed, or a table's treatment moving from kept
|
|
2
|
+
// (`retain`, `anonymize`) to `delete`, is breaking — an erase that destroys rows the last release
|
|
3
|
+
// kept cannot be taken back. A subject or a reached table added is additive; the rest internal.
|
|
4
|
+
|
|
5
|
+
import type { ManifestChange } from './diff-change';
|
|
6
|
+
import { diffScalar, index } from './diff-change';
|
|
7
|
+
import type { SubjectFact, SubjectTableFact } from './schema-subjects';
|
|
8
|
+
|
|
9
|
+
function diffTables(
|
|
10
|
+
path: string,
|
|
11
|
+
before: readonly SubjectTableFact[],
|
|
12
|
+
after: readonly SubjectTableFact[],
|
|
13
|
+
): readonly ManifestChange[] {
|
|
14
|
+
const changes: ManifestChange[] = [];
|
|
15
|
+
const afterByEntity = index(after, (table) => table.entity);
|
|
16
|
+
const beforeByEntity = index(before, (table) => table.entity);
|
|
17
|
+
for (const table of before) {
|
|
18
|
+
const at = `${path}.tables.${table.entity}`;
|
|
19
|
+
const next = afterByEntity.get(table.entity);
|
|
20
|
+
if (next === undefined) {
|
|
21
|
+
changes.push({
|
|
22
|
+
kind: 'internal',
|
|
23
|
+
path: at,
|
|
24
|
+
detail: 'table no longer reached by the subject',
|
|
25
|
+
});
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (table.treatment !== 'delete' && next.treatment === 'delete') {
|
|
29
|
+
changes.push({
|
|
30
|
+
kind: 'breaking',
|
|
31
|
+
path: `${at}.treatment`,
|
|
32
|
+
detail: `${table.treatment} -> delete: an erase now destroys rows it used to keep`,
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
changes.push(...diffScalar('internal', `${at}.treatment`, table.treatment, next.treatment));
|
|
36
|
+
}
|
|
37
|
+
changes.push(
|
|
38
|
+
...diffScalar('internal', `${at}.columns`, table.columns?.join(','), next.columns?.join(',')),
|
|
39
|
+
...diffScalar('internal', `${at}.reason`, table.reason, next.reason),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
for (const table of after) {
|
|
43
|
+
if (!beforeByEntity.has(table.entity)) {
|
|
44
|
+
changes.push({
|
|
45
|
+
kind: 'additive',
|
|
46
|
+
path: `${path}.tables.${table.entity}`,
|
|
47
|
+
detail: 'table added',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return changes;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function diffSubjects(
|
|
55
|
+
before: readonly SubjectFact[],
|
|
56
|
+
after: readonly SubjectFact[],
|
|
57
|
+
): readonly ManifestChange[] {
|
|
58
|
+
const changes: ManifestChange[] = [];
|
|
59
|
+
const afterByEntity = index(after, (subject) => subject.entity);
|
|
60
|
+
const beforeByEntity = index(before, (subject) => subject.entity);
|
|
61
|
+
for (const subject of before) {
|
|
62
|
+
const path = `subjects.${subject.entity}`;
|
|
63
|
+
const next = afterByEntity.get(subject.entity);
|
|
64
|
+
if (next === undefined) {
|
|
65
|
+
changes.push({
|
|
66
|
+
kind: 'breaking',
|
|
67
|
+
path,
|
|
68
|
+
detail: "subject removed; a person's export and erase no longer exist",
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
changes.push(...diffScalar('internal', `${path}.batch`, subject.batch, next.batch));
|
|
73
|
+
changes.push(...diffTables(path, subject.tables, next.tables));
|
|
74
|
+
const targets = (s: SubjectFact): string =>
|
|
75
|
+
s.targets.map((t) => `${t.name}${t.retained ? ':retained' : ''}`).join(',');
|
|
76
|
+
changes.push(...diffScalar('internal', `${path}.targets`, targets(subject), targets(next)));
|
|
77
|
+
}
|
|
78
|
+
for (const subject of after) {
|
|
79
|
+
if (!beforeByEntity.has(subject.entity)) {
|
|
80
|
+
changes.push({
|
|
81
|
+
kind: 'additive',
|
|
82
|
+
path: `subjects.${subject.entity}`,
|
|
83
|
+
detail: 'subject added',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return changes;
|
|
88
|
+
}
|
package/src/diff.ts
CHANGED
|
@@ -15,10 +15,13 @@ import { diffAdmins } from './diff-admin';
|
|
|
15
15
|
import type { ManifestChange } from './diff-change';
|
|
16
16
|
import { diffNamedSet } from './diff-change';
|
|
17
17
|
import { diffChannels } from './diff-channels';
|
|
18
|
+
import { diffConsumers } from './diff-consumers';
|
|
18
19
|
import { diffEntities } from './diff-entities';
|
|
20
|
+
import { diffMounts } from './diff-mounts';
|
|
19
21
|
import { diffActions, diffQueries } from './diff-operations';
|
|
20
22
|
import { diffErrorCodes, diffPolicies } from './diff-registries';
|
|
21
23
|
import { diffRoutes } from './diff-routes';
|
|
24
|
+
import { diffSubjects } from './diff-subjects';
|
|
22
25
|
import { diffJobs, diffTasks } from './diff-work';
|
|
23
26
|
import type { Manifest } from './schema';
|
|
24
27
|
|
|
@@ -52,9 +55,14 @@ export function diffManifest(before: Manifest, after: Manifest): ManifestDiff {
|
|
|
52
55
|
changes.push(...diffChannels(before.channels ?? [], after.channels ?? []));
|
|
53
56
|
// The same `?? []`, for the same reason: no `admin` key is a file older than the section.
|
|
54
57
|
changes.push(...diffAdmins(before.admin ?? [], after.admin ?? []));
|
|
58
|
+
// The same `?? []`, and on the `after` side too: the key is absent there when the last mount left.
|
|
59
|
+
changes.push(...diffMounts(before.mounts ?? [], after.mounts ?? []));
|
|
55
60
|
changes.push(...diffRoutes(before.routes, after.routes));
|
|
56
61
|
changes.push(...diffJobs(before.jobs, after.jobs));
|
|
57
62
|
changes.push(...diffTasks(before.tasks, after.tasks));
|
|
63
|
+
// `mounts`' `?? []` on both sides: the key is absent before the first consumer and after the last.
|
|
64
|
+
changes.push(...diffConsumers(before.consumers ?? [], after.consumers ?? []));
|
|
65
|
+
changes.push(...diffSubjects(before.subjects ?? [], after.subjects ?? []));
|
|
58
66
|
changes.push(...diffEntities(before.entities, after.entities));
|
|
59
67
|
changes.push(...diffPolicies(before.policies, after.policies));
|
|
60
68
|
changes.push(...diffErrorCodes(before.errorCodes, after.errorCodes));
|
package/src/docs-scan.ts
CHANGED
|
@@ -46,9 +46,12 @@ const MAX_TEXT = 1_200;
|
|
|
46
46
|
/** Only `README.md` and `CLAUDE.md`: the two files every package is already gated on carrying. */
|
|
47
47
|
const GUIDE_FILES = ['README.md', 'CLAUDE.md'] as const;
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
export const clampDocText = (text: string): string =>
|
|
50
50
|
text.length <= MAX_TEXT ? text : `${text.slice(0, MAX_TEXT).trimEnd()}…`;
|
|
51
51
|
|
|
52
|
+
/** A fence opener or closer. Inside one, a `## line` is a shell comment, never a heading. */
|
|
53
|
+
export const isFence = (line: string): boolean => /^\s*(?:```|~~~)/.test(line);
|
|
54
|
+
|
|
52
55
|
const read = async (path: string): Promise<string | undefined> => {
|
|
53
56
|
const file = Bun.file(path);
|
|
54
57
|
return (await file.exists()) ? file.text() : undefined;
|
|
@@ -112,7 +115,7 @@ export function headerComment(source: string): string {
|
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
// A rule of dashes under a heading is a separator in prose, never a sentence.
|
|
115
|
-
return
|
|
118
|
+
return clampDocText(
|
|
116
119
|
out
|
|
117
120
|
.join('\n')
|
|
118
121
|
.replace(/^-{3,}$/gm, '')
|
|
@@ -134,14 +137,16 @@ export function parseGuideSections(
|
|
|
134
137
|
markdown: string,
|
|
135
138
|
): readonly { readonly heading: string; readonly body: string }[] {
|
|
136
139
|
const sections: { heading: string; body: string[] }[] = [];
|
|
140
|
+
let fenced = false;
|
|
137
141
|
for (const line of markdown.split('\n')) {
|
|
138
|
-
|
|
142
|
+
if (isFence(line)) fenced = !fenced;
|
|
143
|
+
const heading = fenced ? null : /^#{2,}\s+(.+?)\s*$/.exec(line);
|
|
139
144
|
if (heading !== null) sections.push({ heading: heading[1] ?? '', body: [] });
|
|
140
145
|
else sections.at(-1)?.body.push(line);
|
|
141
146
|
}
|
|
142
147
|
return sections.map((section) => ({
|
|
143
148
|
heading: section.heading,
|
|
144
|
-
body:
|
|
149
|
+
body: clampDocText(section.body.join('\n').trim()),
|
|
145
150
|
}));
|
|
146
151
|
}
|
|
147
152
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The `@ultimat3/manifest/docs-search` entry: the ranker and the entry shape, nothing else. A
|
|
2
|
+
// subpath, never the barrel: an island that searches docs must not pay for the scanner's `node:fs`
|
|
3
|
+
// walk or the manifest's generators (axiom 6). `docs-search-subpath.test.ts` pins the split.
|
|
4
|
+
|
|
5
|
+
export type { DocEntry, DocEntryKind } from './docs-scan';
|
|
6
|
+
export type { DocHit } from './docs-search';
|
|
7
|
+
export { nearestTopics, searchDocs } from './docs-search';
|