@miadi/relational-git-repository-mapper 0.4.0 → 0.5.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/README.md +36 -2
- package/dist/capabilities.d.ts +3 -0
- package/dist/capabilities.js +15 -4
- package/dist/cli.js +79 -7
- package/dist/hosts.d.ts +56 -0
- package/dist/hosts.js +60 -0
- package/dist/impact.d.ts +89 -0
- package/dist/impact.js +169 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +24 -1
- package/dist/join.d.ts +3 -2
- package/dist/join.js +33 -4
- package/dist/lineage.d.ts +4 -4
- package/dist/read.d.ts +25 -0
- package/dist/read.js +46 -2
- package/dist/scan.d.ts +3 -0
- package/dist/scan.js +11 -0
- package/dist/shipped-capabilities.d.ts +1 -0
- package/dist/shipped-capabilities.js +1541 -326
- package/dist/shipped-hosts.d.ts +2 -0
- package/dist/shipped-hosts.js +190 -0
- package/dist/types.d.ts +28 -1
- package/dist/where.d.ts +11 -0
- package/dist/where.js +85 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ reads it.
|
|
|
74
74
|
|
|
75
75
|
The package ships a scan of `jgwill/Miadi` and the three lineages (`avadisabelle/coaia-narrative`,
|
|
76
76
|
`jgwill/coaiajs`, `jgwill/medicine-wheel`), regenerated with
|
|
77
|
-
`node scripts/ship-capabilities.mjs <scan.jsonl> <scan.log
|
|
77
|
+
`node scripts/ship-capabilities.mjs <scan.jsonl> <scan.log> <packages.jsonl>` (and the host readings with `node scripts/ship-hosts.mjs <hosts.jsonl>`). A host's JSONL
|
|
78
78
|
(`--capabilities` or `MIADI_REPOSITORY_CAPABILITIES`) is read first; the first source to name
|
|
79
79
|
a capability speaks for it.
|
|
80
80
|
|
|
@@ -82,6 +82,36 @@ In the app: `GET /api/repositories/capabilities[?repository=owner/name]` answers
|
|
|
82
82
|
capabilities and their `provides` edges, `GET /api/repositories/{owner}/{name}` carries them,
|
|
83
83
|
and the repository page's Lineage card lists them by kind.
|
|
84
84
|
|
|
85
|
+
## Where a repository lives
|
|
86
|
+
|
|
87
|
+
A name like `jgwill/episodes` does not say where the repository is. `miadi-repomap where`
|
|
88
|
+
checks each repository the mapper names: on GitHub (with a token from `GH_TOKEN`,
|
|
89
|
+
`GITHUB_TOKEN` or `gh auth token`, so a private one is seen), else as a bare repository on
|
|
90
|
+
this host (`/srv/git`, or `MIADI_HOST_GIT_ROOTS`). Each reading says `github`, `host-git`,
|
|
91
|
+
`missing` (a 404 a token could have seen, and no bare repository) or `unchecked`. Only a
|
|
92
|
+
GitHub repository gets a GitHub link. `list` and the `/repositories` page set the missing
|
|
93
|
+
ones apart: a session record named a repository that does not exist, and the record is what
|
|
94
|
+
needs correcting. The package ships the readings of its last check; a host's own
|
|
95
|
+
(`where --write <file>`, read through `--hosts` or `MIADI_REPOSITORY_HOSTS`) come first.
|
|
96
|
+
|
|
97
|
+
## What a version bump touches
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
miadi-repomap impact @miadi/hooks-interpreter --bump minor
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The scan reads each package's version and the ranges it declares on other packages it
|
|
104
|
+
read, across repositories. `impact` answers what a package consumes (upstream), who
|
|
105
|
+
consumes it, directly and through others (downstream), and with `--bump`, what each direct
|
|
106
|
+
consumer needs: nothing (its range already reaches the new version), a wider range, or a
|
|
107
|
+
new release because `workspace:*` and `workspace:^` publish the version current at the
|
|
108
|
+
time. In the app: `GET /api/repositories/impact?package=…&bump=…`.
|
|
109
|
+
|
|
110
|
+
## Episodes
|
|
111
|
+
|
|
112
|
+
A repository's view lists the episodes its sessions worked in, as their inventory records
|
|
113
|
+
name them (`miadi-chronicle://<number>`), linked to the chronicle page.
|
|
114
|
+
|
|
85
115
|
## Configuration
|
|
86
116
|
|
|
87
117
|
| variable | default | |
|
|
@@ -90,6 +120,8 @@ and the repository page's Lineage card lists them by kind.
|
|
|
90
120
|
| `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
|
|
91
121
|
| `MIADI_REPOSITORY_LINEAGE` | none | a lineage JSONL read before the shipped rows |
|
|
92
122
|
| `MIADI_REPOSITORY_CAPABILITIES` | none | a capability JSONL read before the shipped rows |
|
|
123
|
+
| `MIADI_REPOSITORY_HOSTS` | none | a where JSONL (`where --write`) read before the shipped readings |
|
|
124
|
+
| `MIADI_HOST_GIT_ROOTS` | `/srv/git` | where `where` looks for bare repositories, colon-separated |
|
|
93
125
|
|
|
94
126
|
## CLI
|
|
95
127
|
|
|
@@ -98,7 +130,9 @@ miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json
|
|
|
98
130
|
miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
99
131
|
miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
|
|
100
132
|
miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]
|
|
101
|
-
miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>]
|
|
133
|
+
miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
|
|
134
|
+
miadi-repomap where [<owner/name>...] [--write <file>] [--json]
|
|
135
|
+
miadi-repomap impact <package> [--bump major|minor|patch] [--json]
|
|
102
136
|
```
|
|
103
137
|
|
|
104
138
|
Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -17,8 +17,11 @@ export interface Artefact {
|
|
|
17
17
|
/** The fields of a package.json the scan reads. Never throws: an unreadable manifest has no name. */
|
|
18
18
|
export declare function parsePackageJson(text: string): {
|
|
19
19
|
name?: string;
|
|
20
|
+
version?: string;
|
|
20
21
|
description?: string;
|
|
21
22
|
bins: string[];
|
|
23
|
+
/** runtime dependencies (dependencies, peerDependencies, optionalDependencies): name → range */
|
|
24
|
+
dependsOn: Record<string, string>;
|
|
22
25
|
};
|
|
23
26
|
/** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
|
|
24
27
|
export declare function parseSkillFrontMatter(text: string): {
|
package/dist/capabilities.js
CHANGED
|
@@ -40,17 +40,28 @@ function kindOf(nodeId) {
|
|
|
40
40
|
function parsePackageJson(text) {
|
|
41
41
|
try {
|
|
42
42
|
const p = JSON.parse(text);
|
|
43
|
-
const
|
|
44
|
-
const
|
|
43
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
44
|
+
const name = str(p.name);
|
|
45
|
+
const version = str(p.version);
|
|
46
|
+
const description = str(p.description);
|
|
45
47
|
let bins = [];
|
|
46
48
|
if (typeof p.bin === "string" && name)
|
|
47
49
|
bins = [name.replace(/^@[^/]+\//, "")];
|
|
48
50
|
else if (p.bin && typeof p.bin === "object")
|
|
49
51
|
bins = Object.keys(p.bin);
|
|
50
|
-
|
|
52
|
+
const dependsOn = {};
|
|
53
|
+
for (const key of ["optionalDependencies", "peerDependencies", "dependencies"]) {
|
|
54
|
+
const deps = p[key];
|
|
55
|
+
if (deps && typeof deps === "object") {
|
|
56
|
+
for (const [dep, range] of Object.entries(deps))
|
|
57
|
+
if (typeof range === "string")
|
|
58
|
+
dependsOn[dep] = range;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { ...(name ? { name } : {}), ...(version ? { version } : {}), ...(description ? { description } : {}), bins, dependsOn };
|
|
51
62
|
}
|
|
52
63
|
catch {
|
|
53
|
-
return { bins: [] };
|
|
64
|
+
return { bins: [], dependsOn: {} };
|
|
54
65
|
}
|
|
55
66
|
}
|
|
56
67
|
/** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
// miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
7
7
|
// miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
|
|
8
8
|
// miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]
|
|
9
|
-
// miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>]
|
|
9
|
+
// miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
|
|
10
|
+
// miadi-repomap where [<owner/name>...] [--write <file>] [--json]
|
|
11
|
+
// miadi-repomap impact <package> [--bump major|minor|patch] [--json]
|
|
10
12
|
//
|
|
11
13
|
// `lineage <owner/name>` answers "what did this repository learn from", and
|
|
12
14
|
// who learned from it; with no repository it prints every lineage. A lineage
|
|
@@ -20,6 +22,13 @@
|
|
|
20
22
|
// tree) and prints those rows as JSONL, pending until a person reads them.
|
|
21
23
|
// --capabilities adds a host's JSONL before the shipped rows (default
|
|
22
24
|
// MIADI_REPOSITORY_CAPABILITIES).
|
|
25
|
+
//
|
|
26
|
+
// `where` checks where each repository lives, on GitHub (with a token from
|
|
27
|
+
// GH_TOKEN, GITHUB_TOKEN or `gh auth token`) or as a bare repository on this
|
|
28
|
+
// host (/srv/git, or MIADI_HOST_GIT_ROOTS), for the repositories named or
|
|
29
|
+
// every one the mapper names. `list` sets apart the repositories found
|
|
30
|
+
// nowhere. `impact` answers what bumping a package touches: what it consumes,
|
|
31
|
+
// who consumes it, and which ranges stop reaching the new version.
|
|
23
32
|
// --hub defaults to MIADI_REPOSITORY_MAPPING_HUB (a jgwill/jgwill clone, or a
|
|
24
33
|
// mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
|
|
25
34
|
// ~/workspace/.mino/session-inventory. Read-only.
|
|
@@ -61,21 +70,27 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
61
70
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
71
|
const os = __importStar(require("node:os"));
|
|
63
72
|
const capabilities_1 = require("./capabilities");
|
|
73
|
+
const node_fs_1 = require("node:fs");
|
|
64
74
|
const read_1 = require("./read");
|
|
75
|
+
const where_1 = require("./where");
|
|
65
76
|
const scan_1 = require("./scan");
|
|
66
77
|
const USAGE = [
|
|
67
78
|
"usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
|
|
68
79
|
" miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
|
|
69
80
|
" miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]",
|
|
70
81
|
" miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]",
|
|
71
|
-
" miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>]",
|
|
82
|
+
" miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]",
|
|
83
|
+
" miadi-repomap where [<owner/name>...] [--write <file>] [--json]",
|
|
84
|
+
" miadi-repomap impact <package> [--bump major|minor|patch] [--json]",
|
|
72
85
|
].join("\n");
|
|
73
86
|
const FLAGS = {
|
|
74
|
-
list: ["hub", "inventory", "lineage", "capabilities", "json"],
|
|
75
|
-
show: ["hub", "inventory", "lineage", "capabilities", "json"],
|
|
87
|
+
list: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
|
|
88
|
+
show: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
|
|
76
89
|
lineage: ["lineage", "json"],
|
|
77
90
|
capabilities: ["capabilities", "json"],
|
|
78
|
-
scan: ["ref", "repository", "by"],
|
|
91
|
+
scan: ["ref", "repository", "by", "packages"],
|
|
92
|
+
where: ["write", "json", "hub", "inventory", "by"],
|
|
93
|
+
impact: ["bump", "json"],
|
|
79
94
|
};
|
|
80
95
|
class UsageError extends Error {
|
|
81
96
|
}
|
|
@@ -137,7 +152,51 @@ async function main() {
|
|
|
137
152
|
inventory: value(flags, "inventory"),
|
|
138
153
|
lineage: value(flags, "lineage"),
|
|
139
154
|
capabilities: value(flags, "capabilities"),
|
|
155
|
+
hosts: value(flags, "hosts"),
|
|
140
156
|
};
|
|
157
|
+
if (command === "where") {
|
|
158
|
+
const named = positional.slice(1);
|
|
159
|
+
const listing = named.length ? undefined : await (0, read_1.repositoryListing)(options);
|
|
160
|
+
const ids = listing ? [...listing.repositories, ...listing.missing].map((r) => r.nodeId) : named;
|
|
161
|
+
const readings = await (0, where_1.checkWhere)(ids, { checkedBy: value(flags, "by") ?? `miadi-repomap where (${os.userInfo().username}@${os.hostname()})` });
|
|
162
|
+
const write = value(flags, "write");
|
|
163
|
+
if (write)
|
|
164
|
+
(0, node_fs_1.writeFileSync)(write, readings.map((r) => JSON.stringify(r)).join("\n") + "\n");
|
|
165
|
+
if (flags.json)
|
|
166
|
+
console.log(JSON.stringify(readings, null, 2));
|
|
167
|
+
else
|
|
168
|
+
for (const r of readings)
|
|
169
|
+
console.log(`${short(r.repository).padEnd(48)} ${r.host.padEnd(10)} ${r.url ?? ""}${r.note ? ` (${r.note})` : ""}`);
|
|
170
|
+
if (write)
|
|
171
|
+
console.error(`${readings.length} readings written to ${write}`);
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
if (command === "impact") {
|
|
175
|
+
if (!positional[1])
|
|
176
|
+
throw new UsageError("impact needs a package: @scope/name or capability:package-…");
|
|
177
|
+
const bump = value(flags, "bump");
|
|
178
|
+
if (bump && !["major", "minor", "patch"].includes(bump))
|
|
179
|
+
throw new UsageError("--bump is major, minor or patch");
|
|
180
|
+
const read = (0, read_1.repositoryImpact)(positional[1], bump);
|
|
181
|
+
if (flags.json) {
|
|
182
|
+
console.log(JSON.stringify(read, null, 2));
|
|
183
|
+
return read.impact ? 0 : 1;
|
|
184
|
+
}
|
|
185
|
+
const i = read.impact;
|
|
186
|
+
if (!i) {
|
|
187
|
+
console.error(`miadi-repomap: ${positional[1]} is not a package the shipped scan read`);
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const lines = [
|
|
191
|
+
`${i.package.name}${i.package.version ? `@${i.package.version}` : ""} (${short(i.package.repository)})${i.bump ? ` ${i.bump.level} bump → ${i.bump.to}` : ""}`,
|
|
192
|
+
` consumes (${i.consumes.length}):`,
|
|
193
|
+
...i.consumes.map((c) => ` ${c.name}${c.version ? `@${c.version}` : ""} ${c.range} (${short(c.repository)})`),
|
|
194
|
+
` consumed by (${i.consumers.length}):`,
|
|
195
|
+
...i.consumers.map((c) => ` ${" ".repeat(c.depth - 1)}${c.name} ${c.depth === 1 ? c.range : `via ${c.via}`} (${short(c.repository)})${c.action ? ` — ${c.action}` : ""}`),
|
|
196
|
+
];
|
|
197
|
+
console.log(lines.join("\n"));
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
141
200
|
if (command === "scan") {
|
|
142
201
|
const clones = positional.slice(1);
|
|
143
202
|
if (!clones.length)
|
|
@@ -146,13 +205,18 @@ async function main() {
|
|
|
146
205
|
throw new UsageError("--repository names one clone's repository: scan one clone with it");
|
|
147
206
|
const observedBy = value(flags, "by") ?? `miadi-repomap scan (${os.userInfo().username}@${os.hostname()})`;
|
|
148
207
|
const rows = [];
|
|
208
|
+
const packages = [];
|
|
149
209
|
for (const clone of clones) {
|
|
150
210
|
const result = await (0, scan_1.scanRepository)(clone, { ref: value(flags, "ref"), repository: value(flags, "repository"), observedBy });
|
|
151
211
|
console.error(`${result.repository.replace(/^repository:/, "")} @ ${result.commit.slice(0, 12)} (${result.ref}): ${result.capabilities.length} capabilities`);
|
|
152
212
|
rows.push(...result.capabilities);
|
|
213
|
+
packages.push(...result.packages);
|
|
153
214
|
}
|
|
154
215
|
for (const row of (0, capabilities_1.mergeCapabilityRows)(rows))
|
|
155
216
|
console.log(JSON.stringify(row));
|
|
217
|
+
const packagesFile = value(flags, "packages");
|
|
218
|
+
if (packagesFile)
|
|
219
|
+
(0, node_fs_1.writeFileSync)(packagesFile, packages.map((p) => JSON.stringify(p)).join("\n") + "\n");
|
|
156
220
|
return 0;
|
|
157
221
|
}
|
|
158
222
|
if (command === "capabilities") {
|
|
@@ -204,9 +268,14 @@ async function main() {
|
|
|
204
268
|
console.error(hubLine(listing.hub));
|
|
205
269
|
for (const r of listing.repositories) {
|
|
206
270
|
const state = r.mapped ? `${r.lifecycle} · ${r.drift}` : "no mapping yet";
|
|
207
|
-
console.log(`${`${r.owner}/${r.name}`.padEnd(48)} ${String(r.sessions).padStart(4)} sessions ${(r.last_session ?? "").padEnd(10)} ${state.padEnd(24)} ${r.teams.join(",") || "-"}`);
|
|
271
|
+
console.log(`${`${r.owner}/${r.name}`.padEnd(48)} ${r.host.padEnd(10)} ${String(r.sessions).padStart(4)} sessions ${(r.last_session ?? "").padEnd(10)} ${state.padEnd(24)} ${r.teams.join(",") || "-"}`);
|
|
208
272
|
}
|
|
209
273
|
console.error(`${listing.repositories.length} repositories; ${listing.inventory.records} records read from ${listing.inventory.from}, ${listing.inventory.without_repo} without a repo`);
|
|
274
|
+
if (listing.missing.length) {
|
|
275
|
+
console.error(`named by session records but found nowhere (${listing.missing.length}):`);
|
|
276
|
+
for (const r of listing.missing)
|
|
277
|
+
console.error(` ${r.owner}/${r.name} ${r.sessions} sessions`);
|
|
278
|
+
}
|
|
210
279
|
return 0;
|
|
211
280
|
}
|
|
212
281
|
if (command === "show") {
|
|
@@ -223,7 +292,8 @@ async function main() {
|
|
|
223
292
|
return 1;
|
|
224
293
|
}
|
|
225
294
|
const lines = [
|
|
226
|
-
`${r.owner}/${r.name} ${r.url}`,
|
|
295
|
+
`${r.owner}/${r.name} ${r.url ?? r.where.url ?? ""} [${r.where.host}${r.where.private ? ", private" : ""}${r.where.archived ? ", archived" : ""}]`,
|
|
296
|
+
r.where.note ? ` where: ${r.where.note}` : "",
|
|
227
297
|
r.repository
|
|
228
298
|
? ` ${r.repository.lifecycle} · ${r.repository.origin} · ${r.repository.revision}${r.source ? ` · from ${r.source}` : ""}`
|
|
229
299
|
: ` ${hubLine(detail.hub)}`,
|
|
@@ -239,6 +309,8 @@ async function main() {
|
|
|
239
309
|
...linkLines(r.lineage.taught),
|
|
240
310
|
r.capabilities.length ? ` provides (${r.capabilities.length}):` : "",
|
|
241
311
|
...r.capabilities.map((c) => ` ${(c.kind ?? "other").padEnd(8)} ${c.name}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`),
|
|
312
|
+
r.episodes.length ? ` episodes (${r.episodes.length}):` : "",
|
|
313
|
+
...r.episodes.map((e) => ` ${e.number !== undefined ? `miadi-chronicle://${e.number}` : e.folder}${e.title ? ` ${e.title}` : ""} (${e.sessions} sessions)`),
|
|
242
314
|
` sessions (${r.sessions.length}):`,
|
|
243
315
|
...r.sessions.map(sessionLine),
|
|
244
316
|
];
|
package/dist/hosts.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type MappingIssue } from "@medicine-wheel/developer-repository-mapping";
|
|
3
|
+
export declare const RepositoryHostSchema: z.ZodEnum<["github", "host-git", "missing", "unchecked"]>;
|
|
4
|
+
export type RepositoryHost = z.infer<typeof RepositoryHostSchema>;
|
|
5
|
+
export declare const RepositoryWhereSchema: z.ZodObject<{
|
|
6
|
+
repository: z.ZodString;
|
|
7
|
+
host: z.ZodEnum<["github", "host-git", "missing", "unchecked"]>;
|
|
8
|
+
/** github: the web page; host-git: `<host>:<path>` of the bare repository */
|
|
9
|
+
url: z.ZodOptional<z.ZodString>;
|
|
10
|
+
private: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
archived: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
/** why, in a few words: "404 from GitHub with a token, no /srv/git/jgwill/x.git" */
|
|
13
|
+
note: z.ZodOptional<z.ZodString>;
|
|
14
|
+
checkedBy: z.ZodString;
|
|
15
|
+
checkedAt: z.ZodString;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
repository: string;
|
|
18
|
+
host: "github" | "host-git" | "missing" | "unchecked";
|
|
19
|
+
checkedBy: string;
|
|
20
|
+
checkedAt: string;
|
|
21
|
+
note?: string | undefined;
|
|
22
|
+
url?: string | undefined;
|
|
23
|
+
private?: boolean | undefined;
|
|
24
|
+
archived?: boolean | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
repository: string;
|
|
27
|
+
host: "github" | "host-git" | "missing" | "unchecked";
|
|
28
|
+
checkedBy: string;
|
|
29
|
+
checkedAt: string;
|
|
30
|
+
note?: string | undefined;
|
|
31
|
+
url?: string | undefined;
|
|
32
|
+
private?: boolean | undefined;
|
|
33
|
+
archived?: boolean | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export type RepositoryWhere = z.infer<typeof RepositoryWhereSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* Readings from several JSONL texts, in precedence order: the first to name a
|
|
38
|
+
* repository speaks for it. Never throws.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseWhere(texts: readonly {
|
|
41
|
+
text: string;
|
|
42
|
+
source: string;
|
|
43
|
+
}[]): {
|
|
44
|
+
readings: RepositoryWhere[];
|
|
45
|
+
issues: MappingIssue[];
|
|
46
|
+
};
|
|
47
|
+
/** Where a repository lives, or `unchecked` when no reading names it. Matched case-folded. */
|
|
48
|
+
export declare function whereOf(repository: string, readings: readonly RepositoryWhere[]): RepositoryWhere | {
|
|
49
|
+
repository: string;
|
|
50
|
+
host: "unchecked";
|
|
51
|
+
};
|
|
52
|
+
/** The web page of a repository: only GitHub repositories have one here. */
|
|
53
|
+
export declare function webUrlOf(where: {
|
|
54
|
+
host: RepositoryHost;
|
|
55
|
+
url?: string;
|
|
56
|
+
}): string | undefined;
|
package/dist/hosts.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Where a git repository lives, pure. A record or a scan names
|
|
3
|
+
// `repository:<owner>/<name>`, and that name does not say where the repository
|
|
4
|
+
// is: GitHub, a host's own git server (gaia's /srv/git holds jgwill/episodes,
|
|
5
|
+
// the chronicle vessel), or nowhere, when a record named a repository that
|
|
6
|
+
// does not exist. A reading says which, who checked and when; a repository no
|
|
7
|
+
// reading names is `unchecked`. Only a GitHub repository gets a GitHub link.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RepositoryWhereSchema = exports.RepositoryHostSchema = void 0;
|
|
10
|
+
exports.parseWhere = parseWhere;
|
|
11
|
+
exports.whereOf = whereOf;
|
|
12
|
+
exports.webUrlOf = webUrlOf;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const capabilities_1 = require("@medicine-wheel/capabilities");
|
|
15
|
+
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
16
|
+
exports.RepositoryHostSchema = zod_1.z.enum(["github", "host-git", "missing", "unchecked"]);
|
|
17
|
+
exports.RepositoryWhereSchema = zod_1.z
|
|
18
|
+
.object({
|
|
19
|
+
repository: developer_repository_mapping_1.RepositoryNodeIdSchema,
|
|
20
|
+
host: exports.RepositoryHostSchema,
|
|
21
|
+
/** github: the web page; host-git: `<host>:<path>` of the bare repository */
|
|
22
|
+
url: zod_1.z.string().min(1).optional(),
|
|
23
|
+
private: zod_1.z.boolean().optional(),
|
|
24
|
+
archived: zod_1.z.boolean().optional(),
|
|
25
|
+
/** why, in a few words: "404 from GitHub with a token, no /srv/git/jgwill/x.git" */
|
|
26
|
+
note: zod_1.z.string().min(1).optional(),
|
|
27
|
+
checkedBy: zod_1.z.string().min(1),
|
|
28
|
+
checkedAt: capabilities_1.TimestampSchema,
|
|
29
|
+
})
|
|
30
|
+
.strict();
|
|
31
|
+
const fold = (id) => id.toLowerCase();
|
|
32
|
+
/**
|
|
33
|
+
* Readings from several JSONL texts, in precedence order: the first to name a
|
|
34
|
+
* repository speaks for it. Never throws.
|
|
35
|
+
*/
|
|
36
|
+
function parseWhere(texts) {
|
|
37
|
+
const readings = [];
|
|
38
|
+
const issues = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const { text, source } of texts) {
|
|
41
|
+
const parsed = (0, developer_repository_mapping_1.parseJsonl)(text, exports.RepositoryWhereSchema, source);
|
|
42
|
+
issues.push(...parsed.issues);
|
|
43
|
+
for (const row of parsed.rows) {
|
|
44
|
+
if (seen.has(fold(row.repository)))
|
|
45
|
+
continue;
|
|
46
|
+
seen.add(fold(row.repository));
|
|
47
|
+
readings.push(row);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { readings, issues };
|
|
51
|
+
}
|
|
52
|
+
/** Where a repository lives, or `unchecked` when no reading names it. Matched case-folded. */
|
|
53
|
+
function whereOf(repository, readings) {
|
|
54
|
+
const id = repository.startsWith("repository:") ? repository : `repository:${repository}`;
|
|
55
|
+
return readings.find((r) => fold(r.repository) === fold(id)) ?? { repository: id, host: "unchecked" };
|
|
56
|
+
}
|
|
57
|
+
/** The web page of a repository: only GitHub repositories have one here. */
|
|
58
|
+
function webUrlOf(where) {
|
|
59
|
+
return where.host === "github" ? where.url : undefined;
|
|
60
|
+
}
|
package/dist/impact.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const PackageReadingSchema: z.ZodObject<{
|
|
3
|
+
/** `capability:package-…` */
|
|
4
|
+
capability: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
version: z.ZodOptional<z.ZodString>;
|
|
7
|
+
repository: z.ZodString;
|
|
8
|
+
path: z.ZodString;
|
|
9
|
+
commit: z.ZodString;
|
|
10
|
+
/** runtime dependencies as declared (dependencies, peer, optional): name → range */
|
|
11
|
+
dependsOn: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
12
|
+
}, "strict", z.ZodTypeAny, {
|
|
13
|
+
name: string;
|
|
14
|
+
capability: string;
|
|
15
|
+
repository: string;
|
|
16
|
+
path: string;
|
|
17
|
+
commit: string;
|
|
18
|
+
dependsOn: Record<string, string>;
|
|
19
|
+
version?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
name: string;
|
|
22
|
+
capability: string;
|
|
23
|
+
repository: string;
|
|
24
|
+
path: string;
|
|
25
|
+
commit: string;
|
|
26
|
+
dependsOn: Record<string, string>;
|
|
27
|
+
version?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
export type PackageReading = z.infer<typeof PackageReadingSchema>;
|
|
30
|
+
export interface ConsumesEdge {
|
|
31
|
+
/** the consuming package's capability */
|
|
32
|
+
from: string;
|
|
33
|
+
/** the consumed package's capability */
|
|
34
|
+
to: string;
|
|
35
|
+
type: "consumes";
|
|
36
|
+
fromName: string;
|
|
37
|
+
toName: string;
|
|
38
|
+
/** the range `from` declares on `to` */
|
|
39
|
+
range: string;
|
|
40
|
+
}
|
|
41
|
+
/** `consumes` edges between the packages read, first-party only. */
|
|
42
|
+
export declare function consumesEdges(packages: readonly PackageReading[]): ConsumesEdge[];
|
|
43
|
+
export type BumpLevel = "major" | "minor" | "patch";
|
|
44
|
+
export declare function bumpVersion(version: string, level: BumpLevel): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Whether `version` satisfies `range`, for the forms first-party manifests
|
|
47
|
+
* use: exact, `^`, `~`, `>=`, `*`/`latest`/empty, and pnpm's `workspace:`
|
|
48
|
+
* forms, read as pnpm publishes them against `published` (the consumed
|
|
49
|
+
* package's version when the consumer was released). Undefined for anything
|
|
50
|
+
* else (`||`, `<`, `file:`, git URLs): read it by hand.
|
|
51
|
+
*/
|
|
52
|
+
export declare function satisfies(version: string, range: string, published?: string): boolean | undefined;
|
|
53
|
+
export interface ImpactLink {
|
|
54
|
+
name: string;
|
|
55
|
+
capability: string;
|
|
56
|
+
repository: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
/** the range the consumer declares (downstream) or this package declares (upstream) */
|
|
59
|
+
range: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ImpactConsumer extends ImpactLink {
|
|
62
|
+
/** 1 for a direct consumer, 2 for a consumer of a consumer, … */
|
|
63
|
+
depth: number;
|
|
64
|
+
/** the consumer it is reached through, from depth 2 */
|
|
65
|
+
via?: string;
|
|
66
|
+
/** with a bump, depth 1: whether its range reaches the new version */
|
|
67
|
+
accepts?: boolean;
|
|
68
|
+
/** with a bump: what the consumer needs */
|
|
69
|
+
action?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ImpactAnswer {
|
|
72
|
+
package: {
|
|
73
|
+
name: string;
|
|
74
|
+
capability: string;
|
|
75
|
+
version?: string;
|
|
76
|
+
repository: string;
|
|
77
|
+
};
|
|
78
|
+
bump?: {
|
|
79
|
+
level: BumpLevel;
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
};
|
|
83
|
+
/** upstream: the first-party packages it consumes */
|
|
84
|
+
consumes: ImpactLink[];
|
|
85
|
+
/** downstream: who consumes it, directly or through others */
|
|
86
|
+
consumers: ImpactConsumer[];
|
|
87
|
+
}
|
|
88
|
+
/** The impact of a package, found by name (`@miadi/x`) or capability id; undefined when no reading names it. */
|
|
89
|
+
export declare function impactOf(packageOrCapability: string, packages: readonly PackageReading[], bump?: BumpLevel): ImpactAnswer | undefined;
|
package/dist/impact.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What a version bump touches, pure. The scan reads each package's version
|
|
3
|
+
// and the ranges it declares on other packages it maps; a `consumes` edge
|
|
4
|
+
// joins a package to each first-party package it depends on, across
|
|
5
|
+
// repositories. `impactOf` answers, for one package: what it consumes
|
|
6
|
+
// (upstream), who consumes it, directly and through others (downstream), and
|
|
7
|
+
// with a bump, which direct consumers' ranges stop reaching the new version.
|
|
8
|
+
// A range published with `workspace:*` pins the exact version, so its
|
|
9
|
+
// consumer is released again after any bump: the drift
|
|
10
|
+
// verify-published-deps reported when hooks-interpreter moved to 0.7.
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PackageReadingSchema = void 0;
|
|
13
|
+
exports.consumesEdges = consumesEdges;
|
|
14
|
+
exports.bumpVersion = bumpVersion;
|
|
15
|
+
exports.satisfies = satisfies;
|
|
16
|
+
exports.impactOf = impactOf;
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
exports.PackageReadingSchema = zod_1.z
|
|
19
|
+
.object({
|
|
20
|
+
/** `capability:package-…` */
|
|
21
|
+
capability: zod_1.z.string().min(1),
|
|
22
|
+
name: zod_1.z.string().min(1),
|
|
23
|
+
version: zod_1.z.string().min(1).optional(),
|
|
24
|
+
repository: zod_1.z.string().min(1),
|
|
25
|
+
path: zod_1.z.string().min(1),
|
|
26
|
+
commit: zod_1.z.string().min(1),
|
|
27
|
+
/** runtime dependencies as declared (dependencies, peer, optional): name → range */
|
|
28
|
+
dependsOn: zod_1.z.record(zod_1.z.string()),
|
|
29
|
+
})
|
|
30
|
+
.strict();
|
|
31
|
+
/** `consumes` edges between the packages read, first-party only. */
|
|
32
|
+
function consumesEdges(packages) {
|
|
33
|
+
const byName = new Map(packages.map((p) => [p.name, p]));
|
|
34
|
+
return packages.flatMap((p) => Object.entries(p.dependsOn).flatMap(([name, range]) => {
|
|
35
|
+
const to = byName.get(name);
|
|
36
|
+
return to && to.name !== p.name ? [{ from: p.capability, to: to.capability, type: "consumes", fromName: p.name, toName: to.name, range }] : [];
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
function parseVersion(v) {
|
|
40
|
+
const m = v ? /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/.exec(v.trim()) : null;
|
|
41
|
+
return m ? [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)] : undefined;
|
|
42
|
+
}
|
|
43
|
+
const cmp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
44
|
+
function bumpVersion(version, level) {
|
|
45
|
+
const v = parseVersion(version);
|
|
46
|
+
if (!v)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (level === "major")
|
|
49
|
+
return `${v[0] + 1}.0.0`;
|
|
50
|
+
if (level === "minor")
|
|
51
|
+
return `${v[0]}.${v[1] + 1}.0`;
|
|
52
|
+
return `${v[0]}.${v[1]}.${v[2] + 1}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether `version` satisfies `range`, for the forms first-party manifests
|
|
56
|
+
* use: exact, `^`, `~`, `>=`, `*`/`latest`/empty, and pnpm's `workspace:`
|
|
57
|
+
* forms, read as pnpm publishes them against `published` (the consumed
|
|
58
|
+
* package's version when the consumer was released). Undefined for anything
|
|
59
|
+
* else (`||`, `<`, `file:`, git URLs): read it by hand.
|
|
60
|
+
*/
|
|
61
|
+
function satisfies(version, range, published) {
|
|
62
|
+
const r = range.trim();
|
|
63
|
+
if (r.startsWith("workspace:")) {
|
|
64
|
+
const form = r.slice("workspace:".length);
|
|
65
|
+
if (!published)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (form === "*" || form === "")
|
|
68
|
+
return satisfies(version, published);
|
|
69
|
+
if (form === "^" || form === "~")
|
|
70
|
+
return satisfies(version, `${form}${published}`);
|
|
71
|
+
return satisfies(version, form);
|
|
72
|
+
}
|
|
73
|
+
if (r === "*" || r === "" || r === "latest" || r === "x")
|
|
74
|
+
return true;
|
|
75
|
+
const v = parseVersion(version);
|
|
76
|
+
if (!v)
|
|
77
|
+
return undefined;
|
|
78
|
+
if (/^\^/.test(r)) {
|
|
79
|
+
const base = parseVersion(r.slice(1));
|
|
80
|
+
if (!base)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (cmp(v, base) < 0)
|
|
83
|
+
return false;
|
|
84
|
+
if (base[0] > 0)
|
|
85
|
+
return v[0] === base[0];
|
|
86
|
+
if (base[1] > 0)
|
|
87
|
+
return v[0] === 0 && v[1] === base[1];
|
|
88
|
+
return v[0] === 0 && v[1] === 0 && v[2] === base[2];
|
|
89
|
+
}
|
|
90
|
+
if (/^~/.test(r)) {
|
|
91
|
+
const base = parseVersion(r.slice(1));
|
|
92
|
+
return base ? cmp(v, base) >= 0 && v[0] === base[0] && v[1] === base[1] : undefined;
|
|
93
|
+
}
|
|
94
|
+
if (/^>=/.test(r)) {
|
|
95
|
+
const base = parseVersion(r.slice(2));
|
|
96
|
+
return base ? cmp(v, base) >= 0 : undefined;
|
|
97
|
+
}
|
|
98
|
+
if (/^\d/.test(r) && !/[\s|<>]/.test(r)) {
|
|
99
|
+
const base = parseVersion(r);
|
|
100
|
+
return base ? cmp(v, base) === 0 : undefined;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
/** The impact of a package, found by name (`@miadi/x`) or capability id; undefined when no reading names it. */
|
|
105
|
+
function impactOf(packageOrCapability, packages, bump) {
|
|
106
|
+
const target = packages.find((p) => p.name === packageOrCapability || p.capability === packageOrCapability);
|
|
107
|
+
if (!target)
|
|
108
|
+
return undefined;
|
|
109
|
+
const edges = consumesEdges(packages);
|
|
110
|
+
const byCapability = new Map(packages.map((p) => [p.capability, p]));
|
|
111
|
+
const to = bump && target.version ? bumpVersion(target.version, bump) : undefined;
|
|
112
|
+
const consumes = edges
|
|
113
|
+
.filter((e) => e.from === target.capability)
|
|
114
|
+
.map((e) => {
|
|
115
|
+
const p = byCapability.get(e.to);
|
|
116
|
+
return { name: p.name, capability: p.capability, repository: p.repository, ...(p.version ? { version: p.version } : {}), range: e.range };
|
|
117
|
+
});
|
|
118
|
+
const consumers = [];
|
|
119
|
+
const seen = new Set([target.capability]);
|
|
120
|
+
let frontier = [{ capability: target.capability }];
|
|
121
|
+
for (let depth = 1; frontier.length; depth++) {
|
|
122
|
+
const next = [];
|
|
123
|
+
for (const { capability } of frontier) {
|
|
124
|
+
for (const e of edges.filter((x) => x.to === capability)) {
|
|
125
|
+
if (seen.has(e.from))
|
|
126
|
+
continue;
|
|
127
|
+
seen.add(e.from);
|
|
128
|
+
const p = byCapability.get(e.from);
|
|
129
|
+
const link = {
|
|
130
|
+
name: p.name,
|
|
131
|
+
capability: p.capability,
|
|
132
|
+
repository: p.repository,
|
|
133
|
+
...(p.version ? { version: p.version } : {}),
|
|
134
|
+
range: e.range,
|
|
135
|
+
depth,
|
|
136
|
+
...(depth > 1 ? { via: byCapability.get(capability).name } : {}),
|
|
137
|
+
};
|
|
138
|
+
if (to && target.version) {
|
|
139
|
+
if (depth === 1) {
|
|
140
|
+
const accepts = satisfies(to, e.range, target.version);
|
|
141
|
+
if (accepts !== undefined)
|
|
142
|
+
link.accepts = accepts;
|
|
143
|
+
link.action =
|
|
144
|
+
accepts === true
|
|
145
|
+
? `${e.range} already reaches ${to}`
|
|
146
|
+
: e.range.startsWith("workspace:")
|
|
147
|
+
? `release ${p.name} again: ${e.range} is published as ${e.range === "workspace:*" ? target.version : `${e.range.slice(10)}${target.version}`}, which does not reach ${to}`
|
|
148
|
+
: accepts === false
|
|
149
|
+
? `widen ${e.range} to reach ${to}, then release ${p.name}`
|
|
150
|
+
: `read ${e.range} by hand`;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
link.action = `downstream through ${link.via}`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
consumers.push(link);
|
|
157
|
+
next.push({ capability: e.from });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
frontier = next;
|
|
161
|
+
}
|
|
162
|
+
consumers.sort((a, b) => a.depth - b.depth || a.name.localeCompare(b.name));
|
|
163
|
+
return {
|
|
164
|
+
package: { name: target.name, capability: target.capability, ...(target.version ? { version: target.version } : {}), repository: target.repository },
|
|
165
|
+
...(to && bump && target.version ? { bump: { level: bump, from: target.version, to } } : {}),
|
|
166
|
+
consumes,
|
|
167
|
+
consumers,
|
|
168
|
+
};
|
|
169
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,9 @@ export { SHIPPED_LINEAGE_JSONL, SHIPPED_LINEAGE_SOURCE } from "./shipped-lineage
|
|
|
5
5
|
export { CAPABILITY_KINDS, capabilityId, kindOf, parsePackageJson, parseSkillFrontMatter, workspaceGlobs, packageManifests, skillFiles, capabilityRows, mergeCapabilityRows, providesEdges, capabilitiesOf, type CapabilityKind, type Artefact, type CapabilityRowContext, type ProvidesEdge, } from "./capabilities";
|
|
6
6
|
export { SHIPPED_CAPABILITIES, SHIPPED_CAPABILITIES_SCANS, SHIPPED_CAPABILITIES_SOURCE } from "./shipped-capabilities";
|
|
7
7
|
export { scanRepository, type ScanOptions, type ScanResult } from "./scan";
|
|
8
|
-
export {
|
|
8
|
+
export { PackageReadingSchema, consumesEdges, bumpVersion, satisfies, impactOf, type PackageReading, type ConsumesEdge, type BumpLevel, type ImpactLink, type ImpactConsumer, type ImpactAnswer, } from "./impact";
|
|
9
|
+
export { RepositoryHostSchema, RepositoryWhereSchema, parseWhere, whereOf, webUrlOf, type RepositoryHost, type RepositoryWhere, } from "./hosts";
|
|
10
|
+
export { checkWhere, type CheckWhereOptions } from "./where";
|
|
11
|
+
export { SHIPPED_PACKAGES } from "./shipped-capabilities";
|
|
12
|
+
export { SHIPPED_HOSTS, SHIPPED_HOSTS_SOURCE } from "./shipped-hosts";
|
|
13
|
+
export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, readWhere, readPackages, repositoryImpact, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
|