@miadi/relational-git-repository-mapper 0.5.1 → 0.6.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/dist/commit.js ADDED
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ // Which capability rows a commit changed (jgwill/Miadi#993). A row is changed
3
+ // when the commit changes a file that defines it: for a package, any file in
4
+ // its folder; for a CLI, its entry point; for a skill, its SKILL.md. A
5
+ // package.json whose change is only its version and its dependency ranges,
6
+ // and a lockfile, define nothing, so a commit that changes only those
7
+ // changes no capability. Each answer is a pending attribution until a person
8
+ // reads it.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CommitReadError = void 0;
11
+ exports.changesOnlyVersions = changesOnlyVersions;
12
+ exports.changedCapabilities = changedCapabilities;
13
+ exports.remoteRepository = remoteRepository;
14
+ exports.capabilitiesOfCommit = capabilitiesOfCommit;
15
+ const node_child_process_1 = require("node:child_process");
16
+ const node_path_1 = require("node:path");
17
+ const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
18
+ const capabilities_1 = require("./capabilities");
19
+ const join_1 = require("./join");
20
+ const read_1 = require("./read");
21
+ class CommitReadError extends Error {
22
+ code;
23
+ constructor(code, message) {
24
+ super(message);
25
+ this.code = code;
26
+ this.name = "CommitReadError";
27
+ }
28
+ }
29
+ exports.CommitReadError = CommitReadError;
30
+ const LOCKFILES = new Set(["pnpm-lock.yaml", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "bun.lockb"]);
31
+ const DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
32
+ /** A package.json with its version removed and each dependency map reduced to its names. Undefined when it does not parse. */
33
+ function manifestShape(text) {
34
+ if (text === undefined)
35
+ return undefined;
36
+ try {
37
+ const json = JSON.parse(text);
38
+ if (typeof json !== "object" || json === null || Array.isArray(json))
39
+ return undefined;
40
+ const { version: _version, ...rest } = json;
41
+ for (const field of DEPENDENCY_FIELDS) {
42
+ const map = rest[field];
43
+ if (map && typeof map === "object" && !Array.isArray(map))
44
+ rest[field] = Object.keys(map).sort();
45
+ }
46
+ return JSON.stringify(rest);
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ }
52
+ /** A package.json whose change, before to after, is only its version and the ranges of the dependencies it already had. */
53
+ function changesOnlyVersions(before, after) {
54
+ const a = manifestShape(before);
55
+ const b = manifestShape(after);
56
+ return a !== undefined && a === b;
57
+ }
58
+ /** The path a shipped row's grounding names (`owner/name@sha:<path>`), or undefined. */
59
+ function groundedPath(row) {
60
+ for (const g of row.grounding) {
61
+ const m = /^[^\s@]+@[0-9a-f]+:(.+)$/i.exec(g);
62
+ if (m)
63
+ return m[1];
64
+ }
65
+ return undefined;
66
+ }
67
+ /** The files a CLI entry point may be committed as: the `bin` path, and for a `dist/<x>.js` its `src/<x>` source. */
68
+ function entryCandidates(folder, entry) {
69
+ const rel = node_path_1.posix.normalize(entry.replace(/^\.\//, ""));
70
+ const out = [node_path_1.posix.join(folder, rel)];
71
+ const built = /^dist\/(.+)\.(?:c|m)?js$/.exec(rel);
72
+ if (built)
73
+ for (const ext of ["ts", "tsx", "mts", "cts", "js", "mjs", "cjs"])
74
+ out.push(node_path_1.posix.join(folder, "src", `${built[1]}.${ext}`));
75
+ return out;
76
+ }
77
+ /** A package's `bin` entry for one command: `bin` as a string ships the package's own name, unscoped. */
78
+ function binEntry(manifest, command) {
79
+ try {
80
+ const json = JSON.parse(manifest ?? "");
81
+ if (typeof json.bin === "string") {
82
+ const own = typeof json.name === "string" ? json.name.replace(/^@[^/]+\//, "") : undefined;
83
+ return own === command ? json.bin : undefined;
84
+ }
85
+ if (json.bin && typeof json.bin === "object") {
86
+ const entry = json.bin[command];
87
+ return typeof entry === "string" ? entry : undefined;
88
+ }
89
+ }
90
+ catch {
91
+ // an unreadable manifest ships no command
92
+ }
93
+ return undefined;
94
+ }
95
+ /** The pure half: which of the repository's rows the changed files define. */
96
+ function changedCapabilities(input) {
97
+ const key = (0, join_1.repositoryKey)(input.repository.replace(/^repository:/, ""));
98
+ const defining = input.files.filter((f) => {
99
+ if (LOCKFILES.has(node_path_1.posix.basename(f)))
100
+ return false;
101
+ if (node_path_1.posix.basename(f) === "package.json")
102
+ return !changesOnlyVersions(input.read(f, "before"), input.read(f, "after"));
103
+ return true;
104
+ });
105
+ if (input.files.length && !defining.length)
106
+ return { skipped: "versions-only", capabilities: [] };
107
+ const rows = input.rows.filter((r) => r.providedBy.some((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === key));
108
+ const provider = (r) => r.providedBy.find((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === key);
109
+ // A file belongs to the deepest package folder that holds it.
110
+ const packages = rows
111
+ .filter((r) => (0, capabilities_1.kindOf)(r.nodeId) === "package")
112
+ .flatMap((r) => {
113
+ const manifest = groundedPath(r);
114
+ return manifest && node_path_1.posix.basename(manifest) === "package.json" ? [{ row: r, folder: node_path_1.posix.dirname(manifest) }] : [];
115
+ })
116
+ .sort((a, b) => b.folder.length - a.folder.length);
117
+ const inFolder = (file, folder) => folder === "." || file.startsWith(`${folder}/`);
118
+ const changed = new Map();
119
+ const add = (row, kind, file) => {
120
+ const known = changed.get(row.nodeId) ?? { row, kind, files: [] };
121
+ if (!known.files.includes(file))
122
+ known.files.push(file);
123
+ changed.set(row.nodeId, known);
124
+ };
125
+ for (const file of defining) {
126
+ const owner = packages.find((p) => inFolder(file, p.folder));
127
+ if (owner)
128
+ add(owner.row, "package", file);
129
+ }
130
+ for (const row of rows) {
131
+ const kind = (0, capabilities_1.kindOf)(row.nodeId);
132
+ const path = groundedPath(row);
133
+ if (!path)
134
+ continue;
135
+ if (kind === "skill" && defining.includes(path))
136
+ add(row, "skill", path);
137
+ if (kind === "cli" && node_path_1.posix.basename(path) === "package.json") {
138
+ const entry = binEntry(input.read(path, "after") ?? input.read(path, "before"), row.name);
139
+ if (!entry)
140
+ continue;
141
+ for (const candidate of entryCandidates(node_path_1.posix.dirname(path), entry))
142
+ if (defining.includes(candidate))
143
+ add(row, "cli", candidate);
144
+ }
145
+ }
146
+ const at = input.at ?? new Date().toISOString();
147
+ const by = input.by ?? "@miadi/relational-git-repository-mapper";
148
+ const capabilities = [...changed.values()]
149
+ .map(({ row, kind, files }) => ({
150
+ address: (0, capabilities_1.capabilityAddress)(provider(row), kind, row.name),
151
+ nodeId: row.nodeId,
152
+ kind,
153
+ name: row.name,
154
+ files: files.sort(),
155
+ attribution: { statedBy: by, statedAt: at, grounding: [input.commit, ...files.sort().map((f) => `${input.commit}:${f}`)], revision: "pending" },
156
+ }))
157
+ .sort((a, b) => a.address.localeCompare(b.address));
158
+ return { capabilities };
159
+ }
160
+ /** `owner/name` of a remote URL: GitHub's, else the last two segments of the path (a host's own git server). */
161
+ function remoteRepository(url) {
162
+ const github = (0, developer_repository_mapping_1.parseGithubRemote)(url);
163
+ if (github)
164
+ return `${github.owner}/${github.name}`;
165
+ const m = /[/:]([^/:\s]+)\/([^/\s]+?)(?:\.git)?\/?$/.exec(url.trim());
166
+ return m ? `${m[1]}/${m[2]}` : undefined;
167
+ }
168
+ const git = (clone, args) => {
169
+ try {
170
+ return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
171
+ }
172
+ catch {
173
+ return undefined;
174
+ }
175
+ };
176
+ /**
177
+ * The capability rows `owner/name@sha` changed, read from a local clone whose
178
+ * `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
179
+ * `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
180
+ * not a commit ref, the clone's origin names another repository, or the clone
181
+ * does not hold the commit.
182
+ */
183
+ function capabilitiesOfCommit(ref, clone, options = {}) {
184
+ const rows = options.rows ?? (0, read_1.readCapabilities)().capabilities;
185
+ const t = (0, join_1.parseTraceRef)(ref);
186
+ if (!t)
187
+ throw new CommitReadError("not-a-commit-ref", `${ref} is not owner/name@sha`);
188
+ const origin = git(clone, ["remote", "get-url", "origin"])?.trim();
189
+ const named = origin ? remoteRepository(origin) : undefined;
190
+ if (!named || (0, join_1.repositoryKey)(named) !== t.key) {
191
+ throw new CommitReadError("clone-not-of-repository", `${clone}'s origin is ${origin ?? "unset"}, not ${t.repository}`);
192
+ }
193
+ const sha = git(clone, ["rev-parse", "--verify", "--quiet", `${t.sha}^{commit}`])?.trim();
194
+ if (!sha)
195
+ throw new CommitReadError("commit-not-in-clone", `${clone} does not hold ${t.sha}`);
196
+ const parent = git(clone, ["rev-parse", "--verify", "--quiet", `${sha}^1`])?.trim();
197
+ const listed = parent
198
+ ? git(clone, ["diff", "--name-only", "--no-renames", parent, sha])
199
+ : git(clone, ["diff-tree", "--root", "-r", "--name-only", "--no-commit-id", "--no-renames", sha]);
200
+ const files = (listed ?? "").split("\n").map((f) => f.trim()).filter(Boolean);
201
+ const read = (path, at) => {
202
+ const rev = at === "after" ? sha : parent;
203
+ return rev ? git(clone, ["show", `${rev}:${path}`]) : undefined;
204
+ };
205
+ const repository = rows.flatMap((r) => r.providedBy).find((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === t.key) ??
206
+ `repository:${t.repository}`;
207
+ const commit = `${t.repository}@${t.sha}`;
208
+ return { commit, repository, sha, files, ...changedCapabilities({ repository, commit, files, read, rows, by: options.by, at: options.at }) };
209
+ }
package/dist/impact.d.ts CHANGED
@@ -1,89 +1,2 @@
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;
1
+ export { PackageReadingSchema, bumpVersion, consumesEdges, impactOf, satisfies } from "@medicine-wheel/developer-repository-mapping";
2
+ export type { BumpLevel, ConsumesEdge, ImpactAnswer, ImpactConsumer, ImpactLink, PackageReading } from "@medicine-wheel/developer-repository-mapping";
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
@@ -1,13 +1,14 @@
1
1
  export type { RepositorySession, MappingState, HubState, RepositoryView, RepositorySummary, InventoryState, RepositoryListing, } from "./types";
2
- export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, sessionsByRepository, repositoryView, listRepositories, type SessionsByRepository, } from "./join";
2
+ export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, parseTraceRef, repositoriesOfRecord, capabilityKey, capabilitySessions, type CapabilitySession, 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
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, findCapability, type CapabilityRecord, 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";
14
+ export { capabilitiesOfCommit, changedCapabilities, changesOnlyVersions, remoteRepository, CommitReadError, type CommitCapability, type CommitCapabilities, type CommitCapabilitiesOptions, type CommitReadFailure, type ChangedCapabilitiesInput, } from "./commit";
package/dist/index.js CHANGED
@@ -4,14 +4,18 @@
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.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;
7
+ 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.capabilitySessions = exports.capabilityKey = exports.repositoriesOfRecord = exports.parseTraceRef = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
8
+ exports.CommitReadError = exports.remoteRepository = exports.changesOnlyVersions = exports.changedCapabilities = exports.capabilitiesOfCommit = exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = 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; } });
12
12
  Object.defineProperty(exports, "dispositionOf", { enumerable: true, get: function () { return join_1.dispositionOf; } });
13
13
  Object.defineProperty(exports, "sessionOf", { enumerable: true, get: function () { return join_1.sessionOf; } });
14
14
  Object.defineProperty(exports, "repositoryKey", { enumerable: true, get: function () { return join_1.repositoryKey; } });
15
+ Object.defineProperty(exports, "parseTraceRef", { enumerable: true, get: function () { return join_1.parseTraceRef; } });
16
+ Object.defineProperty(exports, "repositoriesOfRecord", { enumerable: true, get: function () { return join_1.repositoriesOfRecord; } });
17
+ Object.defineProperty(exports, "capabilityKey", { enumerable: true, get: function () { return join_1.capabilityKey; } });
18
+ Object.defineProperty(exports, "capabilitySessions", { enumerable: true, get: function () { return join_1.capabilitySessions; } });
15
19
  Object.defineProperty(exports, "sessionsByRepository", { enumerable: true, get: function () { return join_1.sessionsByRepository; } });
16
20
  Object.defineProperty(exports, "repositoryView", { enumerable: true, get: function () { return join_1.repositoryView; } });
17
21
  Object.defineProperty(exports, "listRepositories", { enumerable: true, get: function () { return join_1.listRepositories; } });
@@ -44,6 +48,7 @@ Object.defineProperty(exports, "SHIPPED_CAPABILITIES", { enumerable: true, get:
44
48
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SCANS", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS; } });
45
49
  Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SOURCE", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE; } });
46
50
  var scan_1 = require("./scan");
51
+ Object.defineProperty(exports, "readRepositoryCapabilities", { enumerable: true, get: function () { return scan_1.readRepositoryCapabilities; } });
47
52
  Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return scan_1.scanRepository; } });
48
53
  var impact_1 = require("./impact");
49
54
  Object.defineProperty(exports, "PackageReadingSchema", { enumerable: true, get: function () { return impact_1.PackageReadingSchema; } });
@@ -79,3 +84,9 @@ Object.defineProperty(exports, "readWhere", { enumerable: true, get: function ()
79
84
  Object.defineProperty(exports, "readPackages", { enumerable: true, get: function () { return read_1.readPackages; } });
80
85
  Object.defineProperty(exports, "repositoryImpact", { enumerable: true, get: function () { return read_1.repositoryImpact; } });
81
86
  Object.defineProperty(exports, "findCapability", { enumerable: true, get: function () { return read_1.findCapability; } });
87
+ var commit_1 = require("./commit");
88
+ Object.defineProperty(exports, "capabilitiesOfCommit", { enumerable: true, get: function () { return commit_1.capabilitiesOfCommit; } });
89
+ Object.defineProperty(exports, "changedCapabilities", { enumerable: true, get: function () { return commit_1.changedCapabilities; } });
90
+ Object.defineProperty(exports, "changesOnlyVersions", { enumerable: true, get: function () { return commit_1.changesOnlyVersions; } });
91
+ Object.defineProperty(exports, "remoteRepository", { enumerable: true, get: function () { return commit_1.remoteRepository; } });
92
+ Object.defineProperty(exports, "CommitReadError", { enumerable: true, get: function () { return commit_1.CommitReadError; } });
package/dist/join.d.ts CHANGED
@@ -9,9 +9,24 @@ export declare function dayOf(date: string | undefined): string | undefined;
9
9
  /** `team_fit.team.id` first: it is measured at inventory time and includes a team set later. Then `team`. */
10
10
  export declare function teamOf(snapshot: InventorySnapshot): string | undefined;
11
11
  export declare function dispositionOf(snapshot: InventorySnapshot): RepositorySession["disposition"];
12
- export declare function sessionOf(sessionId: string, snapshot: InventorySnapshot): RepositorySession;
12
+ export declare function sessionOf(sessionId: string, snapshot: InventorySnapshot, commits?: readonly string[]): RepositorySession;
13
13
  /** `owner/name`, case-folded, of a record's `repo`, or undefined when it names no repository. */
14
14
  export declare function repositoryKey(repo: string | undefined): string | undefined;
15
+ /** One `links.trace` ref, `owner/name@sha`: its repository as written and the commit. Undefined for any other ref. */
16
+ export declare function parseTraceRef(ref: string): {
17
+ repository: string;
18
+ key: string;
19
+ sha: string;
20
+ } | undefined;
21
+ /**
22
+ * The repositories a record names, case-folded, each with the commits its
23
+ * `links.trace` holds there: its `repo` first (with no commit when the trace
24
+ * names none in it), then every other repository the trace names.
25
+ */
26
+ export declare function repositoriesOfRecord(snapshot: InventorySnapshot): Map<string, {
27
+ spelled: string;
28
+ commits: string[];
29
+ }>;
15
30
  export interface SessionsByRepository {
16
31
  /** case-folded owner/name → its sessions, newest first */
17
32
  sessions: Map<string, RepositorySession[]>;
@@ -21,6 +36,18 @@ export interface SessionsByRepository {
21
36
  withoutRepo: number;
22
37
  }
23
38
  export declare function sessionsByRepository(records: ReadonlyMap<string, InventorySnapshot>): SessionsByRepository;
39
+ /** A capability address without its scheme, owner and repository case-folded: `miadi-capability:` and `miadi-capability://` read the same. */
40
+ export declare function capabilityKey(address: string): string | undefined;
41
+ /** One session whose record says what it did with a capability. */
42
+ export interface CapabilitySession extends RepositorySession {
43
+ /** uses, revises or brings-into-being, as the record writes it */
44
+ relation?: string;
45
+ version?: string;
46
+ /** the record's evidence for it: commits, issues, npm versions */
47
+ capability_evidence?: string[];
48
+ }
49
+ /** The sessions whose record's `capabilities[]` names this capability, newest first. */
50
+ export declare function capabilitySessions(address: string, records: ReadonlyMap<string, InventorySnapshot>): CapabilitySession[];
24
51
  /**
25
52
  * One repository: its rows when a hub holds them, its sessions, and its
26
53
  * lineage. Undefined when no hub, no record and no lineage names it.