@miadi/relational-git-repository-mapper 0.5.0 → 0.5.2

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 CHANGED
@@ -1,169 +1,10 @@
1
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.
2
+ // What a version bump touches lives in @medicine-wheel/developer-repository-mapping (P20).
11
3
  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
- }
4
+ exports.satisfies = exports.impactOf = exports.consumesEdges = exports.bumpVersion = exports.PackageReadingSchema = void 0;
5
+ var developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
6
+ Object.defineProperty(exports, "PackageReadingSchema", { enumerable: true, get: function () { return developer_repository_mapping_1.PackageReadingSchema; } });
7
+ Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return developer_repository_mapping_1.bumpVersion; } });
8
+ Object.defineProperty(exports, "consumesEdges", { enumerable: true, get: function () { return developer_repository_mapping_1.consumesEdges; } });
9
+ Object.defineProperty(exports, "impactOf", { enumerable: true, get: function () { return developer_repository_mapping_1.impactOf; } });
10
+ Object.defineProperty(exports, "satisfies", { enumerable: true, get: function () { return developer_repository_mapping_1.satisfies; } });
package/dist/index.d.ts CHANGED
@@ -2,12 +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
- export { scanRepository, type ScanOptions, type ScanResult } from "./scan";
7
+ export { readRepositoryCapabilities, scanRepository, type RepositoryCapabilities, type ScanOptions, type ScanResult } from "./scan";
8
8
  export { PackageReadingSchema, consumesEdges, bumpVersion, satisfies, impactOf, type PackageReading, type ConsumesEdge, type BumpLevel, type ImpactLink, type ImpactConsumer, type ImpactAnswer, } from "./impact";
9
9
  export { RepositoryHostSchema, RepositoryWhereSchema, parseWhere, whereOf, webUrlOf, type RepositoryHost, type RepositoryWhere, } from "./hosts";
10
10
  export { checkWhere, type CheckWhereOptions } from "./where";
11
11
  export { SHIPPED_PACKAGES } from "./shipped-capabilities";
12
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";
13
+ export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, readWhere, readPackages, repositoryImpact, findCapability, type CapabilityRecord, type RelatedCapability, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
package/dist/index.js CHANGED
@@ -4,8 +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.repositoryDetail = exports.repositoryListing = exports.readMapper = 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.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.repositoryImpact = exports.readPackages = exports.readWhere = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = void 0;
7
+ 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.readRepositoryCapabilities = 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 = exports.readHubState = void 0;
9
9
  var join_1 = require("./join");
10
10
  Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
11
11
  Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
@@ -36,11 +36,15 @@ Object.defineProperty(exports, "capabilityRows", { enumerable: true, get: functi
36
36
  Object.defineProperty(exports, "mergeCapabilityRows", { enumerable: true, get: function () { return capabilities_1.mergeCapabilityRows; } });
37
37
  Object.defineProperty(exports, "providesEdges", { enumerable: true, get: function () { return capabilities_1.providesEdges; } });
38
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; } });
39
42
  var shipped_capabilities_1 = require("./shipped-capabilities");
40
43
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES; } });
41
44
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SCANS", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS; } });
42
45
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SOURCE", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE; } });
43
46
  var scan_1 = require("./scan");
47
+ Object.defineProperty(exports, "readRepositoryCapabilities", { enumerable: true, get: function () { return scan_1.readRepositoryCapabilities; } });
44
48
  Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return scan_1.scanRepository; } });
45
49
  var impact_1 = require("./impact");
46
50
  Object.defineProperty(exports, "PackageReadingSchema", { enumerable: true, get: function () { return impact_1.PackageReadingSchema; } });
@@ -75,3 +79,4 @@ Object.defineProperty(exports, "repositoryCapabilities", { enumerable: true, get
75
79
  Object.defineProperty(exports, "readWhere", { enumerable: true, get: function () { return read_1.readWhere; } });
76
80
  Object.defineProperty(exports, "readPackages", { enumerable: true, get: function () { return read_1.readPackages; } });
77
81
  Object.defineProperty(exports, "repositoryImpact", { enumerable: true, get: function () { return read_1.repositoryImpact; } });
82
+ Object.defineProperty(exports, "findCapability", { enumerable: true, get: function () { return read_1.findCapability; } });
package/dist/lineage.d.ts CHANGED
@@ -15,46 +15,46 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
15
15
  /** what was learned, at most 55 words */
16
16
  description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
17
17
  }, "strict", z.ZodTypeAny, {
18
- revision: "pending" | "revised" | "affirmed";
19
18
  type: "learned-from";
20
19
  from: string;
21
20
  to: string;
22
21
  statedBy: string;
23
22
  statedAt: string;
24
23
  grounding: string[];
24
+ revision: "pending" | "revised" | "affirmed";
25
25
  description?: string | undefined;
26
26
  revisedBy?: string | undefined;
27
27
  revisedAt?: string | undefined;
28
28
  }, {
29
- revision: "pending" | "revised" | "affirmed";
30
29
  type: "learned-from";
31
30
  from: string;
32
31
  to: string;
33
32
  statedBy: string;
34
33
  statedAt: string;
35
34
  grounding: string[];
35
+ revision: "pending" | "revised" | "affirmed";
36
36
  description?: string | undefined;
37
37
  revisedBy?: string | undefined;
38
38
  revisedAt?: string | undefined;
39
39
  }>, {
40
- revision: "pending" | "revised" | "affirmed";
41
40
  type: "learned-from";
42
41
  from: string;
43
42
  to: string;
44
43
  statedBy: string;
45
44
  statedAt: string;
46
45
  grounding: string[];
46
+ revision: "pending" | "revised" | "affirmed";
47
47
  description?: string | undefined;
48
48
  revisedBy?: string | undefined;
49
49
  revisedAt?: string | undefined;
50
50
  }, {
51
- revision: "pending" | "revised" | "affirmed";
52
51
  type: "learned-from";
53
52
  from: string;
54
53
  to: string;
55
54
  statedBy: string;
56
55
  statedAt: string;
57
56
  grounding: string[];
57
+ revision: "pending" | "revised" | "affirmed";
58
58
  description?: string | undefined;
59
59
  revisedBy?: string | undefined;
60
60
  revisedAt?: string | undefined;
package/dist/read.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface WhereRead {
33
33
  /** Where repositories live: a host's own readings first, then the readings this package ships. */
34
34
  export declare function readWhere(path?: string | undefined): WhereRead;
35
35
  /** The packages the shipped scan read, with their versions and first-party ranges. */
36
- export declare function readPackages(): {
36
+ export declare function readPackages(file?: string | undefined): {
37
37
  packages: PackageReading[];
38
38
  issues: MappingIssue[];
39
39
  };
@@ -67,13 +67,50 @@ export interface CapabilitiesAnswer {
67
67
  repository?: string;
68
68
  /** how many of each kind */
69
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 */
70
71
  capabilities: (CapabilityFacet & {
71
72
  kind?: CapabilityKind;
73
+ address?: string;
72
74
  })[];
73
75
  provides: ProvidesEdge[];
74
76
  }
75
77
  /** "What does this repository provide?", or with no repository, every capability. Reads no hub and no inventory. */
76
78
  export declare function repositoryCapabilities(repository?: string, options?: Pick<ReadOptions, "capabilities">): CapabilitiesAnswer;
79
+ /** A capability beside another one, with the address that opens it. */
80
+ export interface RelatedCapability {
81
+ relation: "consumes" | "consumed-by" | "ships" | "shipped-by";
82
+ kind: CapabilityKind;
83
+ name: string;
84
+ address: string;
85
+ version?: string;
86
+ /** for `consumes` and `consumed-by`: the range declared */
87
+ range?: string;
88
+ }
89
+ export interface CapabilityRecord {
90
+ /** the row, with its kind and the address a person cites it by */
91
+ capability: CapabilityFacet & {
92
+ kind: CapabilityKind;
93
+ address: string;
94
+ };
95
+ /** `repository:<owner>/<name>`, the provider the address names */
96
+ repository: string;
97
+ /** for a package: its version, the manifest and commit it was read at, and what it consumes and what consumes it */
98
+ impact?: ImpactAnswer;
99
+ /** the capabilities beside it: what a package consumes, what consumes it, the commands it ships, the package a command comes from */
100
+ related: RelatedCapability[];
101
+ scans: typeof SHIPPED_CAPABILITIES_SCANS;
102
+ }
103
+ /**
104
+ * The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
105
+ * the row of that kind and name that the repository provides, compared
106
+ * case-folded on the repository. Undefined when the registry holds none.
107
+ */
108
+ export declare function findCapability(parts: {
109
+ owner: string;
110
+ repo: string;
111
+ kind: string;
112
+ name: string;
113
+ }, options?: Pick<ReadOptions, "capabilities">): CapabilityRecord | undefined;
77
114
  export interface LineageRead {
78
115
  /** the files read, in precedence order */
79
116
  from: string[];
package/dist/read.js CHANGED
@@ -10,6 +10,7 @@ exports.readPackages = readPackages;
10
10
  exports.repositoryImpact = repositoryImpact;
11
11
  exports.readCapabilities = readCapabilities;
12
12
  exports.repositoryCapabilities = repositoryCapabilities;
13
+ exports.findCapability = findCapability;
13
14
  exports.readLineage = readLineage;
14
15
  exports.readHubState = readHubState;
15
16
  exports.readMapper = readMapper;
@@ -56,13 +57,27 @@ function readWhere(path = process.env.MIADI_REPOSITORY_HOSTS?.trim() || undefine
56
57
  return { from: texts.map((t) => t.source), readings: parsed.readings, issues: [...unread, ...parsed.issues] };
57
58
  }
58
59
  /** The packages the shipped scan read, with their versions and first-party ranges. */
59
- function readPackages() {
60
+ function readPackages(file = process.env.MIADI_REPOSITORY_PACKAGES) {
60
61
  const packages = [];
61
62
  const issues = [];
63
+ // A host's own reading first (`mw-repomap capabilities map --packages <file>`): the first to name a package speaks for it.
64
+ if (file) {
65
+ try {
66
+ const parsed = (0, developer_repository_mapping_1.parseJsonl)((0, node_fs_1.readFileSync)(file, "utf8"), impact_1.PackageReadingSchema, file);
67
+ packages.push(...parsed.rows);
68
+ issues.push(...parsed.issues);
69
+ }
70
+ catch (error) {
71
+ issues.push({ severity: "error", file, message: `could not read: ${error.message}` });
72
+ }
73
+ }
74
+ const named = new Set(packages.map((p) => p.name));
62
75
  shipped_capabilities_1.SHIPPED_PACKAGES.forEach((row, index) => {
63
76
  const parsed = impact_1.PackageReadingSchema.safeParse(row);
64
- if (parsed.success)
65
- packages.push(parsed.data);
77
+ if (parsed.success) {
78
+ if (!named.has(parsed.data.name))
79
+ packages.push(parsed.data);
80
+ }
66
81
  else
67
82
  issues.push({ severity: "error", file: shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE, line: index + 1, message: parsed.error.issues.map((i) => i.message).join("; ") });
68
83
  });
@@ -123,11 +138,54 @@ function repositoryCapabilities(repository, options = {}) {
123
138
  const capabilities = rows.map((c) => {
124
139
  const kind = (0, capabilities_2.kindOf)(c.nodeId);
125
140
  counts[kind ?? "other"] += 1;
126
- return kind ? { ...c, kind } : { ...c };
141
+ const provider = (id && c.providedBy.find((p) => p.toLowerCase() === id.toLowerCase())) || c.providedBy[0];
142
+ return kind ? { ...c, kind, ...(provider ? { address: (0, capabilities_2.capabilityAddress)(provider, kind, c.name) } : {}) } : { ...c };
127
143
  });
128
144
  const provides = (0, capabilities_2.providesEdges)(rows).filter((e) => !id || e.from.toLowerCase() === id.toLowerCase());
129
145
  return { from: read.from, scans: read.scans, issues: read.issues, ...(id ? { repository: id } : {}), counts, capabilities, provides };
130
146
  }
147
+ /**
148
+ * The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
149
+ * the row of that kind and name that the repository provides, compared
150
+ * case-folded on the repository. Undefined when the registry holds none.
151
+ */
152
+ function findCapability(parts, options = {}) {
153
+ const repository = `repository:${parts.owner}/${parts.repo}`.toLowerCase();
154
+ const read = readCapabilities(options.capabilities);
155
+ for (const c of read.capabilities) {
156
+ const kind = (0, capabilities_2.kindOf)(c.nodeId);
157
+ if (kind !== parts.kind || c.name !== parts.name)
158
+ continue;
159
+ const provider = c.providedBy.find((p) => p.toLowerCase() === repository);
160
+ if (!provider)
161
+ continue;
162
+ const { packages } = readPackages();
163
+ const impact = kind === "package" ? (0, impact_1.impactOf)(c.name, packages) : undefined;
164
+ const related = [];
165
+ const version = (v) => (v ? { version: v } : {});
166
+ if (impact) {
167
+ for (const l of impact.consumes)
168
+ related.push({ relation: "consumes", kind: "package", name: l.name, address: (0, capabilities_2.capabilityAddress)(l.repository, "package", l.name), ...version(l.version), range: l.range });
169
+ for (const l of impact.consumers.filter((x) => x.depth === 1))
170
+ related.push({ relation: "consumed-by", kind: "package", name: l.name, address: (0, capabilities_2.capabilityAddress)(l.repository, "package", l.name), ...version(l.version), range: l.range });
171
+ for (const bin of packages.find((p) => p.name === c.name)?.bins ?? [])
172
+ related.push({ relation: "ships", kind: "cli", name: bin, address: (0, capabilities_2.capabilityAddress)(provider, "cli", bin) });
173
+ }
174
+ if (kind === "cli") {
175
+ const shipper = packages.find((p) => p.repository.toLowerCase() === repository && p.bins?.includes(c.name));
176
+ if (shipper)
177
+ related.push({ relation: "shipped-by", kind: "package", name: shipper.name, address: (0, capabilities_2.capabilityAddress)(shipper.repository, "package", shipper.name), ...version(shipper.version) });
178
+ }
179
+ return {
180
+ capability: { ...c, kind, address: (0, capabilities_2.capabilityAddress)(provider, kind, c.name) },
181
+ repository: provider,
182
+ ...(impact ? { impact } : {}),
183
+ related,
184
+ scans: read.scans,
185
+ };
186
+ }
187
+ return undefined;
188
+ }
131
189
  /**
132
190
  * The lineage: a host's own file first (`--lineage` or
133
191
  * `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
package/dist/scan.d.ts CHANGED
@@ -1,19 +1,2 @@
1
- import type { CapabilityFacet } from "@medicine-wheel/capabilities";
2
- import type { PackageReading } from "./impact";
3
- export interface ScanOptions {
4
- /** the ref to read; default the remote's default branch (`origin/HEAD`), else HEAD */
5
- ref?: string;
6
- /** `owner/name` or `repository:owner/name`; default from the `origin` remote */
7
- repository?: string;
8
- observedBy: string;
9
- now?: Date;
10
- }
11
- export interface ScanResult {
12
- repository: string;
13
- ref: string;
14
- commit: string;
15
- capabilities: CapabilityFacet[];
16
- /** each package's version and the ranges it declares, all of them */
17
- packages: PackageReading[];
18
- }
19
- export declare function scanRepository(clone: string, options: ScanOptions): Promise<ScanResult>;
1
+ export { readRepositoryCapabilities, scanRepository } from "@medicine-wheel/developer-repository-mapping/node";
2
+ export type { RepositoryCapabilities, ScanOptions, ScanResult } from "@medicine-wheel/developer-repository-mapping/node";
package/dist/scan.js CHANGED
@@ -1,76 +1,9 @@
1
1
  "use strict";
2
- // The scan, on Node: a clone's packages, CLIs and skills read at one commit,
3
- // from git objects, never from the working tree. A clone on another branch
4
- // or with edits of its own reads the same as a clean one, and every row names
5
- // the commit it was read at. Read-only: git ls-tree, git show, git rev-parse.
2
+ // The scan on Node lives in @medicine-wheel/developer-repository-mapping/node
3
+ // (P20). `readRepositoryCapabilities` takes a repository's own
4
+ // .miadi/capabilities.jsonl first, and falls back to its files.
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.scanRepository = scanRepository;
8
- const node_child_process_1 = require("node:child_process");
9
- const node_util_1 = require("node:util");
10
- const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
11
- const capabilities_1 = require("./capabilities");
12
- const run = (0, node_util_1.promisify)(node_child_process_1.execFile);
13
- async function git(clone, args) {
14
- try {
15
- const { stdout } = await run("git", ["-C", clone, ...args], { maxBuffer: 256 * 1024 * 1024 });
16
- return stdout;
17
- }
18
- catch {
19
- return undefined;
20
- }
21
- }
22
- async function scanRepository(clone, options) {
23
- if ((await git(clone, ["rev-parse", "--git-dir"])) === undefined)
24
- throw new Error(`not a git clone: ${clone}`);
25
- const ref = options.ref ?? ((await git(clone, ["rev-parse", "--verify", "-q", "origin/HEAD"])) ? "origin/HEAD" : "HEAD");
26
- const commit = (await git(clone, ["rev-parse", "--verify", `${ref}^{commit}`]))?.trim();
27
- if (!commit)
28
- throw new Error(`${clone}: no commit at ${ref}`);
29
- let repository = options.repository
30
- ? options.repository.startsWith("repository:") ? options.repository : `repository:${options.repository}`
31
- : undefined;
32
- if (!repository) {
33
- const remote = (0, developer_repository_mapping_1.parseGithubRemote)((await git(clone, ["remote", "get-url", "origin"]))?.trim() ?? "");
34
- if (!remote)
35
- throw new Error(`${clone}: origin is not on GitHub; pass --repository owner/name`);
36
- repository = (0, developer_repository_mapping_1.repositoryNodeId)(remote.owner, remote.name);
37
- }
38
- const files = ((await git(clone, ["ls-tree", "-r", "--name-only", commit])) ?? "").split("\n").filter(Boolean);
39
- const show = (path) => git(clone, ["show", `${commit}:${path}`]);
40
- const globs = (0, capabilities_1.workspaceGlobs)(await show("package.json"), files.includes("pnpm-workspace.yaml") ? await show("pnpm-workspace.yaml") : undefined);
41
- const artefacts = [];
42
- const packages = [];
43
- for (const manifest of (0, capabilities_1.packageManifests)(globs, files)) {
44
- const pkg = (0, capabilities_1.parsePackageJson)((await show(manifest)) ?? "");
45
- if (!pkg.name)
46
- continue;
47
- packages.push({
48
- capability: (0, capabilities_1.capabilityId)("package", pkg.name),
49
- name: pkg.name,
50
- ...(pkg.version ? { version: pkg.version } : {}),
51
- repository,
52
- path: manifest,
53
- commit: commit.slice(0, 12),
54
- dependsOn: pkg.dependsOn,
55
- });
56
- artefacts.push({ kind: "package", name: pkg.name, ...(pkg.description ? { description: pkg.description } : {}), path: manifest });
57
- for (const bin of pkg.bins) {
58
- artefacts.push({ kind: "cli", name: bin, description: `The ${bin} command, shipped by ${pkg.name}.`, path: manifest });
59
- }
60
- }
61
- for (const file of (0, capabilities_1.skillFiles)(files)) {
62
- const front = (0, capabilities_1.parseSkillFrontMatter)((await show(file)) ?? "");
63
- const name = front.name ?? file.split("/").slice(-2, -1)[0];
64
- if (!name)
65
- continue;
66
- artefacts.push({ kind: "skill", name, ...(front.description ? { description: front.description } : {}), path: file });
67
- }
68
- const observedAt = (options.now ?? new Date()).toISOString();
69
- return {
70
- repository,
71
- ref,
72
- commit,
73
- capabilities: (0, capabilities_1.capabilityRows)(artefacts, { repository, commit, observedBy: options.observedBy, observedAt }),
74
- packages,
75
- };
76
- }
6
+ exports.scanRepository = exports.readRepositoryCapabilities = void 0;
7
+ var node_1 = require("@medicine-wheel/developer-repository-mapping/node");
8
+ Object.defineProperty(exports, "readRepositoryCapabilities", { enumerable: true, get: function () { return node_1.readRepositoryCapabilities; } });
9
+ Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return node_1.scanRepository; } });