@miadi/relational-git-repository-mapper 0.4.0 → 0.5.1

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/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
@@ -2,7 +2,12 @@ export type { RepositorySession, MappingState, HubState, RepositoryView, Reposit
2
2
  export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, sessionsByRepository, repositoryView, listRepositories, type SessionsByRepository, } from "./join";
3
3
  export { LineageRowSchema, parseLineage, lineageOf, lineageGraph, type LineageRow, type LineageEdge, type LineageLink, type RepositoryLineage, type LineageGraph, } from "./lineage";
4
4
  export { SHIPPED_LINEAGE_JSONL, SHIPPED_LINEAGE_SOURCE } from "./shipped-lineage";
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";
5
+ export { CAPABILITY_KINDS, capabilityId, kindOf, parsePackageJson, parseSkillFrontMatter, workspaceGlobs, packageManifests, skillFiles, capabilityRows, mergeCapabilityRows, providesEdges, capabilitiesOf, capabilityAddress, medicineWheelSkills, CODE_READERS, type CapabilityKind, type CodeReader, 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 { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, } from "./read";
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, findCapability, type CapabilityRecord, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@
4
4
  // "Repository" here is always a git repository, never the DDD Repository or a
5
5
  // Data Mapper. Formerly @miadi/relational-repository-mapper (deprecated).
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.scanRepository = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = exports.capabilitiesOf = exports.providesEdges = exports.mergeCapabilityRows = exports.capabilityRows = exports.skillFiles = exports.packageManifests = exports.workspaceGlobs = exports.parseSkillFrontMatter = exports.parsePackageJson = exports.kindOf = exports.capabilityId = exports.CAPABILITY_KINDS = exports.SHIPPED_LINEAGE_SOURCE = exports.SHIPPED_LINEAGE_JSONL = exports.lineageGraph = exports.lineageOf = exports.parseLineage = exports.LineageRowSchema = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
7
+ exports.readHubState = exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = exports.SHIPPED_PACKAGES = exports.checkWhere = exports.webUrlOf = exports.whereOf = exports.parseWhere = exports.RepositoryWhereSchema = exports.RepositoryHostSchema = exports.impactOf = exports.satisfies = exports.bumpVersion = exports.consumesEdges = exports.PackageReadingSchema = exports.scanRepository = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = exports.CODE_READERS = exports.medicineWheelSkills = exports.capabilityAddress = exports.capabilitiesOf = exports.providesEdges = exports.mergeCapabilityRows = exports.capabilityRows = exports.skillFiles = exports.packageManifests = exports.workspaceGlobs = exports.parseSkillFrontMatter = exports.parsePackageJson = exports.kindOf = exports.capabilityId = exports.CAPABILITY_KINDS = exports.SHIPPED_LINEAGE_SOURCE = exports.SHIPPED_LINEAGE_JSONL = exports.lineageGraph = exports.lineageOf = exports.parseLineage = exports.LineageRowSchema = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
8
+ exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = void 0;
8
9
  var join_1 = require("./join");
9
10
  Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
10
11
  Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
@@ -35,12 +36,34 @@ Object.defineProperty(exports, "capabilityRows", { enumerable: true, get: functi
35
36
  Object.defineProperty(exports, "mergeCapabilityRows", { enumerable: true, get: function () { return capabilities_1.mergeCapabilityRows; } });
36
37
  Object.defineProperty(exports, "providesEdges", { enumerable: true, get: function () { return capabilities_1.providesEdges; } });
37
38
  Object.defineProperty(exports, "capabilitiesOf", { enumerable: true, get: function () { return capabilities_1.capabilitiesOf; } });
39
+ Object.defineProperty(exports, "capabilityAddress", { enumerable: true, get: function () { return capabilities_1.capabilityAddress; } });
40
+ Object.defineProperty(exports, "medicineWheelSkills", { enumerable: true, get: function () { return capabilities_1.medicineWheelSkills; } });
41
+ Object.defineProperty(exports, "CODE_READERS", { enumerable: true, get: function () { return capabilities_1.CODE_READERS; } });
38
42
  var shipped_capabilities_1 = require("./shipped-capabilities");
39
43
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES; } });
40
44
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SCANS", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS; } });
41
45
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SOURCE", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE; } });
42
46
  var scan_1 = require("./scan");
43
47
  Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return scan_1.scanRepository; } });
48
+ var impact_1 = require("./impact");
49
+ Object.defineProperty(exports, "PackageReadingSchema", { enumerable: true, get: function () { return impact_1.PackageReadingSchema; } });
50
+ Object.defineProperty(exports, "consumesEdges", { enumerable: true, get: function () { return impact_1.consumesEdges; } });
51
+ Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return impact_1.bumpVersion; } });
52
+ Object.defineProperty(exports, "satisfies", { enumerable: true, get: function () { return impact_1.satisfies; } });
53
+ Object.defineProperty(exports, "impactOf", { enumerable: true, get: function () { return impact_1.impactOf; } });
54
+ var hosts_1 = require("./hosts");
55
+ Object.defineProperty(exports, "RepositoryHostSchema", { enumerable: true, get: function () { return hosts_1.RepositoryHostSchema; } });
56
+ Object.defineProperty(exports, "RepositoryWhereSchema", { enumerable: true, get: function () { return hosts_1.RepositoryWhereSchema; } });
57
+ Object.defineProperty(exports, "parseWhere", { enumerable: true, get: function () { return hosts_1.parseWhere; } });
58
+ Object.defineProperty(exports, "whereOf", { enumerable: true, get: function () { return hosts_1.whereOf; } });
59
+ Object.defineProperty(exports, "webUrlOf", { enumerable: true, get: function () { return hosts_1.webUrlOf; } });
60
+ var where_1 = require("./where");
61
+ Object.defineProperty(exports, "checkWhere", { enumerable: true, get: function () { return where_1.checkWhere; } });
62
+ var shipped_capabilities_2 = require("./shipped-capabilities");
63
+ Object.defineProperty(exports, "SHIPPED_PACKAGES", { enumerable: true, get: function () { return shipped_capabilities_2.SHIPPED_PACKAGES; } });
64
+ var shipped_hosts_1 = require("./shipped-hosts");
65
+ Object.defineProperty(exports, "SHIPPED_HOSTS", { enumerable: true, get: function () { return shipped_hosts_1.SHIPPED_HOSTS; } });
66
+ Object.defineProperty(exports, "SHIPPED_HOSTS_SOURCE", { enumerable: true, get: function () { return shipped_hosts_1.SHIPPED_HOSTS_SOURCE; } });
44
67
  var read_1 = require("./read");
45
68
  Object.defineProperty(exports, "inventoryDir", { enumerable: true, get: function () { return read_1.inventoryDir; } });
46
69
  Object.defineProperty(exports, "hubPath", { enumerable: true, get: function () { return read_1.hubPath; } });
@@ -52,3 +75,7 @@ Object.defineProperty(exports, "readLineage", { enumerable: true, get: function
52
75
  Object.defineProperty(exports, "repositoryLineage", { enumerable: true, get: function () { return read_1.repositoryLineage; } });
53
76
  Object.defineProperty(exports, "readCapabilities", { enumerable: true, get: function () { return read_1.readCapabilities; } });
54
77
  Object.defineProperty(exports, "repositoryCapabilities", { enumerable: true, get: function () { return read_1.repositoryCapabilities; } });
78
+ Object.defineProperty(exports, "readWhere", { enumerable: true, get: function () { return read_1.readWhere; } });
79
+ Object.defineProperty(exports, "readPackages", { enumerable: true, get: function () { return read_1.readPackages; } });
80
+ Object.defineProperty(exports, "repositoryImpact", { enumerable: true, get: function () { return read_1.repositoryImpact; } });
81
+ Object.defineProperty(exports, "findCapability", { enumerable: true, get: function () { return read_1.findCapability; } });
package/dist/join.d.ts CHANGED
@@ -2,6 +2,7 @@ import { type RepositoryMapping } from "@medicine-wheel/developer-repository-map
2
2
  import type { InventorySnapshot } from "@miadi/hooks-interpreter";
3
3
  import type { CapabilityFacet } from "@medicine-wheel/capabilities";
4
4
  import { type LineageEdge } from "./lineage";
5
+ import { type RepositoryWhere } from "./hosts";
5
6
  import type { RepositorySession, RepositorySummary, RepositoryView } from "./types";
6
7
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
7
8
  export declare function dayOf(date: string | undefined): string | undefined;
@@ -24,6 +25,6 @@ export declare function sessionsByRepository(records: ReadonlyMap<string, Invent
24
25
  * One repository: its rows when a hub holds them, its sessions, and its
25
26
  * lineage. Undefined when no hub, no record and no lineage names it.
26
27
  */
27
- export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[]): RepositoryView | undefined;
28
+ export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[], whereReadings?: readonly RepositoryWhere[]): RepositoryView | undefined;
28
29
  /** Every repository a hub holds, a record names or a lineage names, most sessions first. */
29
- export declare function listRepositories(mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[]): RepositorySummary[];
30
+ export declare function listRepositories(mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[], whereReadings?: readonly RepositoryWhere[]): RepositorySummary[];
package/dist/join.js CHANGED
@@ -15,6 +15,7 @@ exports.listRepositories = listRepositories;
15
15
  const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
16
16
  const capabilities_1 = require("./capabilities");
17
17
  const lineage_1 = require("./lineage");
18
+ const hosts_1 = require("./hosts");
18
19
  const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
19
20
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
20
21
  function dayOf(date) {
@@ -36,6 +37,10 @@ function sessionOf(sessionId, snapshot) {
36
37
  const team = teamOf(snapshot);
37
38
  const disposition = dispositionOf(snapshot);
38
39
  const date = dayOf(snapshot.date);
40
+ const ep = snapshot.episode;
41
+ const episode = ep && (ep.number !== undefined || ep.folder)
42
+ ? { ...(ep.number !== undefined ? { number: ep.number } : {}), ...(ep.title ? { title: ep.title } : {}), ...(ep.folder ? { folder: ep.folder } : {}) }
43
+ : undefined;
39
44
  return {
40
45
  session_id: sessionId,
41
46
  ...(snapshot.tmux_session_name ? { tmux_session_name: snapshot.tmux_session_name } : {}),
@@ -46,6 +51,7 @@ function sessionOf(sessionId, snapshot) {
46
51
  work_completed: (snapshot.work_completed ?? []).map((item) => item.title),
47
52
  ...(disposition ? { disposition } : {}),
48
53
  ...(snapshot.evidence?.length ? { evidence: snapshot.evidence } : {}),
54
+ ...(episode ? { episode } : {}),
49
55
  modified_at: snapshot.modified_at,
50
56
  };
51
57
  }
@@ -80,7 +86,7 @@ const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
80
86
  * One repository: its rows when a hub holds them, its sessions, and its
81
87
  * lineage. Undefined when no hub, no record and no lineage names it.
82
88
  */
83
- function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = [], capabilityRows = []) {
89
+ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = [], capabilityRows = [], whereReadings = []) {
84
90
  const key = repositoryKey(repository);
85
91
  if (!key)
86
92
  return undefined;
@@ -93,11 +99,32 @@ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEd
93
99
  return undefined;
94
100
  const nodeId = row?.nodeId ?? named ?? `repository:${bySessions.spelled.get(key) ?? key}`;
95
101
  const { owner, name } = (0, developer_repository_mapping_1.parseRepositoryNodeId)(nodeId);
102
+ const where = (0, hosts_1.whereOf)(nodeId, whereReadings);
103
+ const url = (0, hosts_1.webUrlOf)(where);
104
+ const episodes = new Map();
105
+ for (const s of sessions) {
106
+ if (!s.episode)
107
+ continue;
108
+ const key = s.episode.folder ?? String(s.episode.number);
109
+ const known = episodes.get(key);
110
+ if (known)
111
+ known.sessions += 1;
112
+ else
113
+ episodes.set(key, { ...s.episode, sessions: 1 });
114
+ }
96
115
  return {
97
116
  nodeId,
98
117
  owner,
99
118
  name,
100
- url: (0, developer_repository_mapping_1.repositoryUrl)(nodeId),
119
+ ...(url ? { url } : {}),
120
+ where: {
121
+ host: where.host,
122
+ ...("url" in where && where.url ? { url: where.url } : {}),
123
+ ...("note" in where && where.note ? { note: where.note } : {}),
124
+ ...("private" in where && where.private ? { private: true } : {}),
125
+ ...("archived" in where && where.archived ? { archived: true } : {}),
126
+ },
127
+ episodes: [...episodes.values()].sort((a, b) => b.sessions - a.sessions || (b.number ?? 0) - (a.number ?? 0)),
101
128
  mapped: Boolean(row),
102
129
  ...(row ? { repository: row, reading: (0, developer_repository_mapping_1.reconcileLifecycle)(row) } : {}),
103
130
  ...(row && sources[row.nodeId] ? { source: sources[row.nodeId] } : {}),
@@ -112,7 +139,7 @@ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEd
112
139
  };
113
140
  }
114
141
  /** Every repository a hub holds, a record names or a lineage names, most sessions first. */
115
- function listRepositories(mapping, bySessions, lineageEdges = [], capabilityRows = []) {
142
+ function listRepositories(mapping, bySessions, lineageEdges = [], capabilityRows = [], whereReadings = []) {
116
143
  const keys = new Set([
117
144
  ...bySessions.sessions.keys(),
118
145
  ...(mapping?.repositories ?? []).map((r) => keyOfNode(r.nodeId)),
@@ -121,13 +148,15 @@ function listRepositories(mapping, bySessions, lineageEdges = [], capabilityRows
121
148
  ]);
122
149
  return [...keys]
123
150
  .map((key) => {
124
- const view = repositoryView(key, mapping, bySessions, {}, lineageEdges, capabilityRows);
151
+ const view = repositoryView(key, mapping, bySessions, {}, lineageEdges, capabilityRows, whereReadings);
125
152
  const teams = [...new Set(view.sessions.flatMap((s) => (s.team ? [s.team] : [])))].sort();
126
153
  return {
127
154
  nodeId: view.nodeId,
128
155
  owner: view.owner,
129
156
  name: view.name,
130
157
  mapped: view.mapped,
158
+ host: view.where.host,
159
+ ...(view.url ? { url: view.url } : {}),
131
160
  ...(view.repository ? { lifecycle: view.repository.lifecycle } : {}),
132
161
  ...(view.reading ? { drift: view.reading.drift } : {}),
133
162
  sessions: view.sessions.length,
package/dist/lineage.d.ts CHANGED
@@ -16,9 +16,9 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
16
16
  description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
17
17
  }, "strict", z.ZodTypeAny, {
18
18
  revision: "pending" | "revised" | "affirmed";
19
+ type: "learned-from";
19
20
  from: string;
20
21
  to: string;
21
- type: "learned-from";
22
22
  statedBy: string;
23
23
  statedAt: string;
24
24
  grounding: string[];
@@ -27,9 +27,9 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
27
27
  revisedAt?: string | undefined;
28
28
  }, {
29
29
  revision: "pending" | "revised" | "affirmed";
30
+ type: "learned-from";
30
31
  from: string;
31
32
  to: string;
32
- type: "learned-from";
33
33
  statedBy: string;
34
34
  statedAt: string;
35
35
  grounding: string[];
@@ -38,9 +38,9 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
38
38
  revisedAt?: string | undefined;
39
39
  }>, {
40
40
  revision: "pending" | "revised" | "affirmed";
41
+ type: "learned-from";
41
42
  from: string;
42
43
  to: string;
43
- type: "learned-from";
44
44
  statedBy: string;
45
45
  statedAt: string;
46
46
  grounding: string[];
@@ -49,9 +49,9 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
49
49
  revisedAt?: string | undefined;
50
50
  }, {
51
51
  revision: "pending" | "revised" | "affirmed";
52
+ type: "learned-from";
52
53
  from: string;
53
54
  to: string;
54
- type: "learned-from";
55
55
  statedBy: string;
56
56
  statedAt: string;
57
57
  grounding: string[];
package/dist/read.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { SHIPPED_CAPABILITIES_SCANS } from "./shipped-capabilities";
2
+ import { type BumpLevel, type ImpactAnswer, type PackageReading } from "./impact";
3
+ import { type RepositoryWhere } from "./hosts";
2
4
  import { type CapabilityFacet } from "@medicine-wheel/capabilities";
3
5
  import { type CapabilityKind, type ProvidesEdge } from "./capabilities";
4
6
  import { type MappingIssue, type MergedMapping } from "@medicine-wheel/developer-repository-mapping";
@@ -19,7 +21,29 @@ export interface ReadOptions {
19
21
  lineage?: string;
20
22
  /** a capability JSONL read before the shipped rows; default `MIADI_REPOSITORY_CAPABILITIES` */
21
23
  capabilities?: string;
24
+ /** a where JSONL (`miadi-repomap where --write`) read before the shipped readings; default `MIADI_REPOSITORY_HOSTS` */
25
+ hosts?: string;
22
26
  }
27
+ export interface WhereRead {
28
+ /** the sources read, in precedence order */
29
+ from: string[];
30
+ readings: RepositoryWhere[];
31
+ issues: MappingIssue[];
32
+ }
33
+ /** Where repositories live: a host's own readings first, then the readings this package ships. */
34
+ export declare function readWhere(path?: string | undefined): WhereRead;
35
+ /** The packages the shipped scan read, with their versions and first-party ranges. */
36
+ export declare function readPackages(): {
37
+ packages: PackageReading[];
38
+ issues: MappingIssue[];
39
+ };
40
+ export interface ImpactRead {
41
+ scans: typeof SHIPPED_CAPABILITIES_SCANS;
42
+ issues: MappingIssue[];
43
+ impact?: ImpactAnswer;
44
+ }
45
+ /** What bumping a package touches: what it consumes, who consumes it, which ranges stop reaching the new version. */
46
+ export declare function repositoryImpact(packageOrCapability: string, bump?: BumpLevel): ImpactRead;
23
47
  export interface CapabilitiesRead {
24
48
  /** the sources read, in precedence order */
25
49
  from: string[];
@@ -43,13 +67,38 @@ export interface CapabilitiesAnswer {
43
67
  repository?: string;
44
68
  /** how many of each kind */
45
69
  counts: Record<CapabilityKind | "other", number>;
70
+ /** each with its kind and the address a person cites it by, for the repository asked about or its first provider */
46
71
  capabilities: (CapabilityFacet & {
47
72
  kind?: CapabilityKind;
73
+ address?: string;
48
74
  })[];
49
75
  provides: ProvidesEdge[];
50
76
  }
51
77
  /** "What does this repository provide?", or with no repository, every capability. Reads no hub and no inventory. */
52
78
  export declare function repositoryCapabilities(repository?: string, options?: Pick<ReadOptions, "capabilities">): CapabilitiesAnswer;
79
+ export interface CapabilityRecord {
80
+ /** the row, with its kind and the address a person cites it by */
81
+ capability: CapabilityFacet & {
82
+ kind: CapabilityKind;
83
+ address: string;
84
+ };
85
+ /** `repository:<owner>/<name>`, the provider the address names */
86
+ repository: string;
87
+ /** for a package: its version, the manifest and commit it was read at, and what it consumes and what consumes it */
88
+ impact?: ImpactAnswer;
89
+ scans: typeof SHIPPED_CAPABILITIES_SCANS;
90
+ }
91
+ /**
92
+ * The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
93
+ * the row of that kind and name that the repository provides, compared
94
+ * case-folded on the repository. Undefined when the registry holds none.
95
+ */
96
+ export declare function findCapability(parts: {
97
+ owner: string;
98
+ repo: string;
99
+ kind: string;
100
+ name: string;
101
+ }, options?: Pick<ReadOptions, "capabilities">): CapabilityRecord | undefined;
53
102
  export interface LineageRead {
54
103
  /** the files read, in precedence order */
55
104
  from: string[];
@@ -73,6 +122,7 @@ export interface MapperRead {
73
122
  sessions: SessionsByRepository;
74
123
  lineage: LineageRead;
75
124
  capabilities: CapabilitiesRead;
125
+ where: WhereRead;
76
126
  }
77
127
  export declare function readMapper(options?: ReadOptions): Promise<MapperRead>;
78
128
  export declare function repositoryListing(options?: ReadOptions): Promise<RepositoryListing>;
package/dist/read.js CHANGED
@@ -5,8 +5,12 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.inventoryDir = inventoryDir;
7
7
  exports.hubPath = hubPath;
8
+ exports.readWhere = readWhere;
9
+ exports.readPackages = readPackages;
10
+ exports.repositoryImpact = repositoryImpact;
8
11
  exports.readCapabilities = readCapabilities;
9
12
  exports.repositoryCapabilities = repositoryCapabilities;
13
+ exports.findCapability = findCapability;
10
14
  exports.readLineage = readLineage;
11
15
  exports.readHubState = readHubState;
12
16
  exports.readMapper = readMapper;
@@ -16,6 +20,9 @@ exports.repositoryLineage = repositoryLineage;
16
20
  const node_fs_1 = require("node:fs");
17
21
  const shipped_lineage_1 = require("./shipped-lineage");
18
22
  const shipped_capabilities_1 = require("./shipped-capabilities");
23
+ const shipped_hosts_1 = require("./shipped-hosts");
24
+ const impact_1 = require("./impact");
25
+ const hosts_1 = require("./hosts");
19
26
  const capabilities_1 = require("@medicine-wheel/capabilities");
20
27
  const capabilities_2 = require("./capabilities");
21
28
  const node_os_1 = require("node:os");
@@ -33,6 +40,41 @@ function inventoryDir(env = process.env) {
33
40
  function hubPath(env = process.env) {
34
41
  return env.MIADI_REPOSITORY_MAPPING_HUB?.trim() || undefined;
35
42
  }
43
+ /** Where repositories live: a host's own readings first, then the readings this package ships. */
44
+ function readWhere(path = process.env.MIADI_REPOSITORY_HOSTS?.trim() || undefined) {
45
+ const texts = [];
46
+ const unread = [];
47
+ if (path) {
48
+ try {
49
+ texts.push({ text: (0, node_fs_1.readFileSync)(path, "utf8"), source: path });
50
+ }
51
+ catch (error) {
52
+ unread.push({ severity: "error", file: path, message: `hosts not read: ${error.message}` });
53
+ }
54
+ }
55
+ texts.push({ text: shipped_hosts_1.SHIPPED_HOSTS.map((r) => JSON.stringify(r)).join("\n"), source: shipped_hosts_1.SHIPPED_HOSTS_SOURCE });
56
+ const parsed = (0, hosts_1.parseWhere)(texts);
57
+ return { from: texts.map((t) => t.source), readings: parsed.readings, issues: [...unread, ...parsed.issues] };
58
+ }
59
+ /** The packages the shipped scan read, with their versions and first-party ranges. */
60
+ function readPackages() {
61
+ const packages = [];
62
+ const issues = [];
63
+ shipped_capabilities_1.SHIPPED_PACKAGES.forEach((row, index) => {
64
+ const parsed = impact_1.PackageReadingSchema.safeParse(row);
65
+ if (parsed.success)
66
+ packages.push(parsed.data);
67
+ else
68
+ issues.push({ severity: "error", file: shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE, line: index + 1, message: parsed.error.issues.map((i) => i.message).join("; ") });
69
+ });
70
+ return { packages, issues };
71
+ }
72
+ /** What bumping a package touches: what it consumes, who consumes it, which ranges stop reaching the new version. */
73
+ function repositoryImpact(packageOrCapability, bump) {
74
+ const read = readPackages();
75
+ const impact = (0, impact_1.impactOf)(packageOrCapability, read.packages, bump);
76
+ return { scans: shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS, issues: read.issues, ...(impact ? { impact } : {}) };
77
+ }
36
78
  /**
37
79
  * The capabilities: a host's own JSONL first (`--capabilities` or
38
80
  * `MIADI_REPOSITORY_CAPABILITIES`), then the rows this package ships, scanned
@@ -82,11 +124,37 @@ function repositoryCapabilities(repository, options = {}) {
82
124
  const capabilities = rows.map((c) => {
83
125
  const kind = (0, capabilities_2.kindOf)(c.nodeId);
84
126
  counts[kind ?? "other"] += 1;
85
- return kind ? { ...c, kind } : { ...c };
127
+ const provider = (id && c.providedBy.find((p) => p.toLowerCase() === id.toLowerCase())) || c.providedBy[0];
128
+ return kind ? { ...c, kind, ...(provider ? { address: (0, capabilities_2.capabilityAddress)(provider, kind, c.name) } : {}) } : { ...c };
86
129
  });
87
130
  const provides = (0, capabilities_2.providesEdges)(rows).filter((e) => !id || e.from.toLowerCase() === id.toLowerCase());
88
131
  return { from: read.from, scans: read.scans, issues: read.issues, ...(id ? { repository: id } : {}), counts, capabilities, provides };
89
132
  }
133
+ /**
134
+ * The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
135
+ * the row of that kind and name that the repository provides, compared
136
+ * case-folded on the repository. Undefined when the registry holds none.
137
+ */
138
+ function findCapability(parts, options = {}) {
139
+ const repository = `repository:${parts.owner}/${parts.repo}`.toLowerCase();
140
+ const read = readCapabilities(options.capabilities);
141
+ for (const c of read.capabilities) {
142
+ const kind = (0, capabilities_2.kindOf)(c.nodeId);
143
+ if (kind !== parts.kind || c.name !== parts.name)
144
+ continue;
145
+ const provider = c.providedBy.find((p) => p.toLowerCase() === repository);
146
+ if (!provider)
147
+ continue;
148
+ const impact = kind === "package" ? (0, impact_1.impactOf)(c.name, readPackages().packages) : undefined;
149
+ return {
150
+ capability: { ...c, kind, address: (0, capabilities_2.capabilityAddress)(provider, kind, c.name) },
151
+ repository: provider,
152
+ ...(impact ? { impact } : {}),
153
+ scans: read.scans,
154
+ };
155
+ }
156
+ return undefined;
157
+ }
90
158
  /**
91
159
  * The lineage: a host's own file first (`--lineage` or
92
160
  * `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
@@ -131,19 +199,22 @@ async function readMapper(options = {}) {
131
199
  sessions,
132
200
  lineage: readLineage(options.lineage),
133
201
  capabilities: readCapabilities(options.capabilities),
202
+ where: readWhere(options.hosts),
134
203
  };
135
204
  }
136
205
  async function repositoryListing(options = {}) {
137
206
  const read = await readMapper(options);
207
+ const all = (0, join_1.listRepositories)(read.mapping, read.sessions, read.lineage.edges, read.capabilities.capabilities, read.where.readings);
138
208
  return {
139
209
  hub: read.hub,
140
210
  inventory: read.inventory,
141
- repositories: (0, join_1.listRepositories)(read.mapping, read.sessions, read.lineage.edges, read.capabilities.capabilities),
211
+ repositories: all.filter((r) => r.host !== "missing"),
212
+ missing: all.filter((r) => r.host === "missing"),
142
213
  };
143
214
  }
144
215
  async function repositoryDetail(repository, options = {}) {
145
216
  const read = await readMapper(options);
146
- const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources, read.lineage.edges, read.capabilities.capabilities);
217
+ const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources, read.lineage.edges, read.capabilities.capabilities, read.where.readings);
147
218
  return { hub: read.hub, inventory: read.inventory, ...(view ? { repository: view } : {}) };
148
219
  }
149
220
  /** "What did this repository learn from?", or with no repository, every lineage. Reads no hub and no inventory. */
package/dist/scan.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CapabilityFacet } from "@medicine-wheel/capabilities";
2
+ import type { PackageReading } from "./impact";
2
3
  export interface ScanOptions {
3
4
  /** the ref to read; default the remote's default branch (`origin/HEAD`), else HEAD */
4
5
  ref?: string;
@@ -12,5 +13,7 @@ export interface ScanResult {
12
13
  ref: string;
13
14
  commit: string;
14
15
  capabilities: CapabilityFacet[];
16
+ /** each package's version and the ranges it declares, all of them */
17
+ packages: PackageReading[];
15
18
  }
16
19
  export declare function scanRepository(clone: string, options: ScanOptions): Promise<ScanResult>;