football-docs 0.17.1 → 0.17.3

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/data/docs.db CHANGED
Binary file
package/dist/reep.js CHANGED
@@ -73,6 +73,26 @@ async function localRegister(path, options) {
73
73
  openFiles.set(path, { mtimeMs, ...opened });
74
74
  return opened.register;
75
75
  }
76
+ /**
77
+ * Follow merge redirects to the survivor (bounded, in case of a chain). A row
78
+ * with an empty to_id is a tombstone, not a merge: stop there. Bridges can name
79
+ * a merged ID too, so every hit goes through this, not only Reep ID lookups.
80
+ */
81
+ async function followRedirects(register, start) {
82
+ let current = start;
83
+ for (let hop = 0; hop < 5; hop++) {
84
+ const next = await register.query("SELECT to_id, reason FROM redirects WHERE from_id = $id", { id: current });
85
+ if (!next.length)
86
+ break;
87
+ const to = next[0].to_id == null ? "" : String(next[0].to_id).trim();
88
+ if (!to) {
89
+ const reason = next[0].reason == null ? "" : String(next[0].reason).trim();
90
+ return { id: current, tombstone: { id: current, reason, requested_id: current === start ? undefined : start } };
91
+ }
92
+ current = to;
93
+ }
94
+ return { id: current };
95
+ }
76
96
  async function localLookup(register, q) {
77
97
  let ids = [];
78
98
  if (q.kind === "provider") {
@@ -94,21 +114,7 @@ async function localLookup(register, q) {
94
114
  }));
95
115
  }
96
116
  else if (q.kind === "reep_id") {
97
- // Follow merge redirects to the survivor (bounded, in case of a chain). A row
98
- // with an empty to_id is a tombstone, not a merge: stop and report it.
99
- let current = q.reepId;
100
- for (let hop = 0; hop < 5; hop++) {
101
- const next = await register.query("SELECT to_id, reason FROM redirects WHERE from_id = $id", { id: current });
102
- if (!next.length)
103
- break;
104
- const to = next[0].to_id == null ? "" : String(next[0].to_id).trim();
105
- if (!to) {
106
- const reason = next[0].reason == null ? "" : String(next[0].reason).trim();
107
- return { found: [], tombstone: { id: current, reason, requested_id: current === q.reepId ? undefined : q.reepId } };
108
- }
109
- current = to;
110
- }
111
- ids = [{ reep_id: current, requested_id: current === q.reepId ? undefined : q.reepId }];
117
+ ids = [{ reep_id: q.reepId }];
112
118
  }
113
119
  else {
114
120
  const pattern = `%${q.name.replace(/[\\%_]/g, (c) => `\\${c}`)}%`;
@@ -124,31 +130,68 @@ async function localLookup(register, q) {
124
130
  }));
125
131
  }
126
132
  const found = [];
133
+ const tombstones = [];
134
+ const seen = new Set();
127
135
  for (const hit of ids) {
136
+ const target = await followRedirects(register, hit.reep_id);
137
+ if (target.tombstone) {
138
+ tombstones.push({ ...target.tombstone, matched: hit.matched });
139
+ continue;
140
+ }
141
+ // Two bridges (or search hits) can lead to the same survivor.
142
+ if (seen.has(target.id))
143
+ continue;
144
+ seen.add(target.id);
128
145
  const entity = await register.query("SELECT reep_id, label, entity_type FROM entities WHERE reep_id = $id", {
129
- id: hit.reep_id,
146
+ id: target.id,
130
147
  });
131
148
  if (!entity.length)
132
149
  continue;
133
- const bridges = await register.query("SELECT provider, namespace, external_id FROM bridges WHERE reep_id = $id ORDER BY provider, namespace, external_id", { id: hit.reep_id });
150
+ // A release can leave a provider ID on a merged Reep ID, not on its survivor,
151
+ // so the survivor's own bridges are incomplete. Add the bridges of every ID
152
+ // merged into it (through chains, bounded), marked with the merged ID.
153
+ const bridges = await register.query([
154
+ "WITH RECURSIVE merged(id, depth) AS (",
155
+ " SELECT from_id, 1 FROM redirects WHERE to_id = $id",
156
+ " UNION ALL",
157
+ " SELECT r.from_id, m.depth + 1 FROM redirects r JOIN merged m ON r.to_id = m.id WHERE m.depth < 5",
158
+ ")",
159
+ "SELECT provider, namespace, external_id, CASE WHEN reep_id = $id THEN NULL ELSE reep_id END AS via",
160
+ "FROM bridges WHERE reep_id = $id OR reep_id IN (SELECT id FROM merged)",
161
+ "ORDER BY provider, namespace, external_id, via NULLS FIRST",
162
+ ].join("\n"), { id: target.id });
163
+ const own = new Set();
134
164
  found.push({
135
- reep_id: hit.reep_id,
165
+ reep_id: target.id,
136
166
  label: String(entity[0].label),
137
167
  entity_type: String(entity[0].entity_type),
138
- requested_id: hit.requested_id,
168
+ requested_id: target.id === hit.reep_id ? undefined : hit.reep_id,
139
169
  matched: hit.matched,
140
170
  matched_namespace: hit.matched_namespace,
141
- bridges: bridges.map((b) => ({
171
+ bridges: bridges
172
+ .map((b) => ({
142
173
  provider: String(b.provider),
143
174
  namespace: String(b.namespace ?? ""),
144
175
  external_id: String(b.external_id),
145
- })),
176
+ via: b.via == null ? undefined : String(b.via),
177
+ }))
178
+ .filter((b) => {
179
+ // The survivor's own bridge wins over the same provider ID on a merged ID.
180
+ const key = `${b.provider}\u0000${b.namespace}\u0000${b.external_id}`;
181
+ if (own.has(key))
182
+ return false;
183
+ own.add(key);
184
+ return true;
185
+ }),
146
186
  });
147
187
  }
148
- return { found };
188
+ if (q.kind === "reep_id" && tombstones.length)
189
+ return { found: [], tombstone: tombstones[0], tombstones };
190
+ return { found, tombstones };
149
191
  }
150
192
  /** What a tombstone means, from the redirects table's published schema note. */
151
193
  function tombstoneText(t) {
194
+ const matched = t.matched ? `${t.matched} points at ${t.requested_id ?? t.id}. ` : "";
152
195
  const via = t.requested_id ? `${t.requested_id} was merged into ${t.id}, and ` : "";
153
196
  const what = t.reason === "de_corroborated"
154
197
  ? "is withdrawn (reason: de_corroborated). It was in an earlier release, and this release no longer admits it " +
@@ -157,8 +200,8 @@ function tombstoneText(t) {
157
200
  ? "is withheld (reason: withheld). It is a live, corroborated ID that a publication rule (for example named " +
158
201
  "teams or the season horizon) keeps out of this release."
159
202
  : `has a tombstone in the redirects table (reason: ${t.reason || "none given"}) with no survivor.`;
160
- return (`${via}Reep ID ${t.id} ${what} It is not a merge, so there is no survivor ID, and the release lists no provider ` +
161
- "IDs for it. Do not treat it as an unknown ID: it was published, and the ID will never be reused.");
203
+ return (`${matched}${via}Reep ID ${t.id} ${what} It is not a merge, so there is no survivor ID. Do not treat it as an unknown ID: ` +
204
+ "it was published, and the ID will never be reused.");
162
205
  }
163
206
  /**
164
207
  * A provider-ID lookup without a namespace. Reep keys bridges on (provider,
@@ -318,10 +361,15 @@ function sqlFor(q) {
318
361
  const quote = (s) => `'${s.replace(/'/g, "''")}'`;
319
362
  if (q.kind === "provider") {
320
363
  return [
321
- "SELECT e.reep_id, e.label, e.entity_type, o.provider, o.namespace, o.external_id",
364
+ "-- A bridge can name a merged Reep ID: follow its redirect to the survivor. An empty",
365
+ "-- to_id is a tombstone (redirect_reason de_corroborated or withheld), not a merge.",
366
+ "SELECT b.reep_id AS bridged_id, r.reason AS redirect_reason, e.reep_id, e.label, e.entity_type,",
367
+ " o.provider, o.namespace, o.external_id",
322
368
  "FROM bridges b",
323
- "JOIN entities e USING (reep_id)",
324
- "JOIN bridges o ON o.reep_id = e.reep_id",
369
+ "LEFT JOIN redirects r ON r.from_id = b.reep_id",
370
+ "JOIN entities e ON e.reep_id = coalesce(nullif(r.to_id, ''), b.reep_id)",
371
+ "-- The survivor's provider IDs, plus any still attached to an ID merged into it.",
372
+ "JOIN bridges o ON o.reep_id = e.reep_id OR o.reep_id IN (SELECT from_id FROM redirects WHERE to_id = e.reep_id)",
325
373
  `WHERE b.provider = ${quote(q.provider)}${q.namespace ? ` AND b.namespace = ${quote(q.namespace)}` : ""}`,
326
374
  ` AND b.external_id = ${quote(q.id)}`,
327
375
  "ORDER BY o.provider, o.namespace;",
@@ -333,10 +381,13 @@ function sqlFor(q) {
333
381
  "-- (reason de_corroborated) or withheld, not merged.",
334
382
  `SELECT from_id, to_id, reason FROM redirects WHERE from_id = ${quote(q.reepId)};`,
335
383
  "",
336
- "-- Then follow a merge redirect to the survivor, and list every provider ID.",
337
- "SELECT e.reep_id, e.label, e.entity_type, b.provider, b.namespace, b.external_id",
338
- "FROM entities e JOIN bridges b USING (reep_id)",
384
+ "-- Then follow a merge redirect to the survivor, and list every provider ID, including",
385
+ "-- any still attached to an ID merged into it (bridged_on names that ID).",
386
+ "SELECT e.reep_id, e.label, e.entity_type, b.provider, b.namespace, b.external_id, b.reep_id AS bridged_on",
387
+ "FROM entities e",
388
+ "JOIN bridges b ON b.reep_id = e.reep_id OR b.reep_id IN (SELECT from_id FROM redirects WHERE to_id = e.reep_id)",
339
389
  `WHERE e.reep_id = coalesce((SELECT nullif(to_id, '') FROM redirects WHERE from_id = ${quote(q.reepId)}), ${quote(q.reepId)})`,
390
+ ` AND NOT EXISTS (SELECT 1 FROM redirects WHERE from_id = ${quote(q.reepId)} AND coalesce(to_id, '') = '')`,
340
391
  "ORDER BY b.provider, b.namespace;",
341
392
  ].join("\n");
342
393
  }
@@ -383,7 +434,8 @@ function formatFound(found) {
383
434
  lines.push(" (none)");
384
435
  for (const b of f.bridges) {
385
436
  const role = b.role && b.role !== "canonical_bridge" ? ` (${b.role})` : "";
386
- lines.push(` ${b.provider}${b.namespace ? ` / ${b.namespace}` : ""}: ${b.external_id}${role}`);
437
+ const via = b.via ? ` (via merged ${b.via})` : "";
438
+ lines.push(` ${b.provider}${b.namespace ? ` / ${b.namespace}` : ""}: ${b.external_id}${role}${via}`);
387
439
  }
388
440
  }
389
441
  else if (f.bridge_count !== undefined) {
@@ -405,13 +457,16 @@ export async function resolveEntity(args, options = {}) {
405
457
  if (path) {
406
458
  try {
407
459
  const register = await localRegister(path, options);
408
- const { found, tombstone } = await localLookup(register, q);
460
+ const { found, tombstone, tombstones } = await localLookup(register, q);
409
461
  const note = await freshnessNote(path, register.stamp, fetchImpl);
410
462
  if (tombstone)
411
463
  return textResult(`${tombstoneText(tombstone)}\n\n${note}`);
412
- if (!found.length)
413
- return textResult(`No Reep entity matches that query in the local register.\n\n${note}`);
414
- return textResult(`Found ${found.length} result(s) in the local Reep register:\n\n${formatFound(found)}${namespaceNote(q, found)}\n\n${note}`);
464
+ const gone = tombstones.map((t) => tombstoneText(t)).join("\n\n");
465
+ if (!found.length) {
466
+ return textResult(`${gone || "No Reep entity matches that query in the local register."}\n\n${note}`);
467
+ }
468
+ return textResult(`Found ${found.length} result(s) in the local Reep register:\n\n${formatFound(found)}${namespaceNote(q, found)}` +
469
+ `${gone ? `\n\n${gone}` : ""}\n\n${note}`);
415
470
  }
416
471
  catch (error) {
417
472
  const reason = error instanceof Error ? error.message : String(error);
@@ -58,6 +58,9 @@ that answers the question from the download.
58
58
  What the answers say:
59
59
 
60
60
  - A merged Reep ID is followed to its survivor, and the answer names both IDs.
61
+ This includes a provider ID whose bridge still names the merged ID. The
62
+ survivor's provider IDs include any still attached to an ID merged into it,
63
+ marked "(via merged <id>)".
61
64
  - A withdrawn or withheld Reep ID (a tombstone in `redirects`, with an empty
62
65
  `to_id`) is reported as withdrawn or withheld, with the reason. It is not
63
66
  reported as unknown: it was published, and the ID is never reused.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "football-docs",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "Searchable football data provider documentation for AI coding agents. Like Context7 for football data.",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.34.4",