football-docs 0.17.1 → 0.17.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/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,18 +130,29 @@ 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
+ const bridges = await register.query("SELECT provider, namespace, external_id FROM bridges WHERE reep_id = $id ORDER BY provider, namespace, external_id", { id: target.id });
134
151
  found.push({
135
- reep_id: hit.reep_id,
152
+ reep_id: target.id,
136
153
  label: String(entity[0].label),
137
154
  entity_type: String(entity[0].entity_type),
138
- requested_id: hit.requested_id,
155
+ requested_id: target.id === hit.reep_id ? undefined : hit.reep_id,
139
156
  matched: hit.matched,
140
157
  matched_namespace: hit.matched_namespace,
141
158
  bridges: bridges.map((b) => ({
@@ -145,10 +162,13 @@ async function localLookup(register, q) {
145
162
  })),
146
163
  });
147
164
  }
148
- return { found };
165
+ if (q.kind === "reep_id" && tombstones.length)
166
+ return { found: [], tombstone: tombstones[0], tombstones };
167
+ return { found, tombstones };
149
168
  }
150
169
  /** What a tombstone means, from the redirects table's published schema note. */
151
170
  function tombstoneText(t) {
171
+ const matched = t.matched ? `${t.matched} points at ${t.requested_id ?? t.id}. ` : "";
152
172
  const via = t.requested_id ? `${t.requested_id} was merged into ${t.id}, and ` : "";
153
173
  const what = t.reason === "de_corroborated"
154
174
  ? "is withdrawn (reason: de_corroborated). It was in an earlier release, and this release no longer admits it " +
@@ -157,8 +177,8 @@ function tombstoneText(t) {
157
177
  ? "is withheld (reason: withheld). It is a live, corroborated ID that a publication rule (for example named " +
158
178
  "teams or the season horizon) keeps out of this release."
159
179
  : `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.");
180
+ 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: ` +
181
+ "it was published, and the ID will never be reused.");
162
182
  }
163
183
  /**
164
184
  * A provider-ID lookup without a namespace. Reep keys bridges on (provider,
@@ -318,9 +338,13 @@ function sqlFor(q) {
318
338
  const quote = (s) => `'${s.replace(/'/g, "''")}'`;
319
339
  if (q.kind === "provider") {
320
340
  return [
321
- "SELECT e.reep_id, e.label, e.entity_type, o.provider, o.namespace, o.external_id",
341
+ "-- A bridge can name a merged Reep ID: follow its redirect to the survivor. An empty",
342
+ "-- to_id is a tombstone (redirect_reason de_corroborated or withheld), not a merge.",
343
+ "SELECT b.reep_id AS bridged_id, r.reason AS redirect_reason, e.reep_id, e.label, e.entity_type,",
344
+ " o.provider, o.namespace, o.external_id",
322
345
  "FROM bridges b",
323
- "JOIN entities e USING (reep_id)",
346
+ "LEFT JOIN redirects r ON r.from_id = b.reep_id",
347
+ "JOIN entities e ON e.reep_id = coalesce(nullif(r.to_id, ''), b.reep_id)",
324
348
  "JOIN bridges o ON o.reep_id = e.reep_id",
325
349
  `WHERE b.provider = ${quote(q.provider)}${q.namespace ? ` AND b.namespace = ${quote(q.namespace)}` : ""}`,
326
350
  ` AND b.external_id = ${quote(q.id)}`,
@@ -337,6 +361,7 @@ function sqlFor(q) {
337
361
  "SELECT e.reep_id, e.label, e.entity_type, b.provider, b.namespace, b.external_id",
338
362
  "FROM entities e JOIN bridges b USING (reep_id)",
339
363
  `WHERE e.reep_id = coalesce((SELECT nullif(to_id, '') FROM redirects WHERE from_id = ${quote(q.reepId)}), ${quote(q.reepId)})`,
364
+ ` AND NOT EXISTS (SELECT 1 FROM redirects WHERE from_id = ${quote(q.reepId)} AND coalesce(to_id, '') = '')`,
340
365
  "ORDER BY b.provider, b.namespace;",
341
366
  ].join("\n");
342
367
  }
@@ -405,13 +430,16 @@ export async function resolveEntity(args, options = {}) {
405
430
  if (path) {
406
431
  try {
407
432
  const register = await localRegister(path, options);
408
- const { found, tombstone } = await localLookup(register, q);
433
+ const { found, tombstone, tombstones } = await localLookup(register, q);
409
434
  const note = await freshnessNote(path, register.stamp, fetchImpl);
410
435
  if (tombstone)
411
436
  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}`);
437
+ const gone = tombstones.map((t) => tombstoneText(t)).join("\n\n");
438
+ if (!found.length) {
439
+ return textResult(`${gone || "No Reep entity matches that query in the local register."}\n\n${note}`);
440
+ }
441
+ return textResult(`Found ${found.length} result(s) in the local Reep register:\n\n${formatFound(found)}${namespaceNote(q, found)}` +
442
+ `${gone ? `\n\n${gone}` : ""}\n\n${note}`);
415
443
  }
416
444
  catch (error) {
417
445
  const reason = error instanceof Error ? error.message : String(error);
@@ -58,6 +58,7 @@ 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.
61
62
  - A withdrawn or withheld Reep ID (a tombstone in `redirects`, with an empty
62
63
  `to_id`) is reported as withdrawn or withheld, with the reason. It is not
63
64
  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.2",
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",