Skip to content

Commit

Permalink
fix!(core/xref): use new /xref/search endpoint (#4686)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Apr 12, 2024
1 parent 3f9bf15 commit 71e3aa0
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 99 deletions.
13 changes: 6 additions & 7 deletions src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function findExplicitExternalLinks() {
*/
function normalizeConfig(xref) {
const defaults = {
url: API_URL,
url: new URL("search/", API_URL).href,
specs: null,
};

Expand Down Expand Up @@ -313,24 +313,23 @@ async function getData(queryKeys, apiUrl) {
}

/**
* @param {RequestEntry[]} keys
* @param {RequestEntry[]} queries
* @param {string} url
* @returns {Promise<Map<string, SearchResultEntry[]>>}
*/
async function fetchFromNetwork(keys, url) {
if (!keys.length) return new Map();
async function fetchFromNetwork(queries, url) {
if (!queries.length) return new Map();

const query = { keys };
const options = {
method: "POST",
body: JSON.stringify(query),
body: JSON.stringify({ queries }),
headers: {
"Content-Type": "application/json",
},
};
const response = await fetch(url, options);
const json = await response.json();
return new Map(json.result);
return new Map(json.results.map(({ id, result }) => [id, result]));
}

/**
Expand Down
182 changes: 90 additions & 92 deletions tests/data/xref/refs.json
Original file line number Diff line number Diff line change
@@ -1,166 +1,164 @@
{
"result": [
[
"ab7db5bcda5172f65990774c08b2d5623d0ca4d9",
[
"results": [
{
"id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9",
"query": {
"term": "fake inform 1",
"types": ["_CONCEPT_"],
"id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9"
},
"result": [
{
"shortname": "local-1",
"type": "dfn",
"normative": false,
"uri": "#fake-inform-1"
}
]
],
[
"cb3348a71fc96423a724d214e32b0a6f6d19f270",
[
},
{
"id": "cb3348a71fc96423a724d214e32b0a6f6d19f270",
"query": {
"term": "list",
"types": ["_CONCEPT_"],
"id": "cb3348a71fc96423a724d214e32b0a6f6d19f270"
},
"result": [
{
"shortname": "infra",
"type": "dfn",
"normative": true,
"uri": "#list"
}
]
],
[
"8ab59f6080eccb6cd1cb43884d30467b294761dd",
[
},
{
"id": "8ab59f6080eccb6cd1cb43884d30467b294761dd",
"query": {
"term": "bearing angle",
"types": ["_CONCEPT_"],
"id": "8ab59f6080eccb6cd1cb43884d30467b294761dd"
},
"result": [
{
"shortname": "css-values",
"type": "dfn",
"normative": false,
"uri": "#bearing-angle"
}
]
],
[
"a99184f1d06a2664d14b22732d462985ba9993a1",
[
},
{
"id": "a99184f1d06a2664d14b22732d462985ba9993a1",
"query": {
"term": "url parser",
"types": ["_CONCEPT_"],
"id": "a99184f1d06a2664d14b22732d462985ba9993a1"
},
"result": [
{
"shortname": "url",
"type": "dfn",
"normative": true,
"uri": "#concept-url-parser"
}
]
],
[
"98f59682aab42126e30db05b4fc748fb891654b1",
[
},
{
"id": "98f59682aab42126e30db05b4fc748fb891654b1",
"query": {
"term": "fake inform 2",
"types": ["_CONCEPT_"],
"id": "98f59682aab42126e30db05b4fc748fb891654b1"
},
"result": [
{
"shortname": "local-2",
"type": "dfn",
"normative": false,
"uri": "#fake-inform-2"
}
]
],
[
"2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071",
[
},
{
"id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071",
"query": {
"term": "event handler",
"types": ["_CONCEPT_"],
"id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071"
},
"result": [
{
"shortname": "html",
"type": "dfn",
"normative": true,
"uri": "webappapis.html#event-handlers"
}
]
],
[
"ea274f5f7e4d9bd49503932f92e96377bcc6d32c",
[
},
{
"id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c",
"query": {
"term": "fake inform 3",
"types": ["_CONCEPT_"],
"id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c"
},
"result": [
{
"shortname": "local-3",
"type": "dfn",
"normative": false,
"uri": "#fake-inform-3"
}
]
],
[
"3f57765140cc67750fba716a57c6acd2897aac33",
[
},
{
"id": "3f57765140cc67750fba716a57c6acd2897aac33",
"query": {
"term": "dictionary",
"types": ["_CONCEPT_"],
"id": "3f57765140cc67750fba716a57c6acd2897aac33"
},
"result": [
{
"shortname": "webidl",
"type": "dfn",
"normative": true,
"uri": "#dfn-dictionary"
}
]
],
[
"2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b",
[
},
{
"id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b",
"query": {
"term": "fake inform 4",
"types": ["_CONCEPT_"],
"id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b"
},
"result": [
{
"shortname": "local-4",
"type": "dfn",
"normative": false,
"uri": "#fake-inform-4"
}
]
],
[
"4ef7705f121b9b2228672ec56b8d3a4f491a0c20",
[
},
{
"id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20",
"query": {
"term": "ascii alphanumeric",
"types": ["_CONCEPT_"],
"id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20"
},
"result": [
{
"shortname": "infra",
"type": "dfn",
"normative": true,
"uri": "#ascii-alphanumeric"
}
]
]
],
"query": [
{
"term": "fake inform 1",
"types": ["_CONCEPT_"],
"id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9"
},
{
"term": "list",
"types": ["_CONCEPT_"],
"id": "cb3348a71fc96423a724d214e32b0a6f6d19f270"
},
{
"term": "bearing angle",
"types": ["_CONCEPT_"],
"id": "8ab59f6080eccb6cd1cb43884d30467b294761dd"
},
{
"term": "url parser",
"types": ["_CONCEPT_"],
"id": "a99184f1d06a2664d14b22732d462985ba9993a1"
},
{
"term": "fake inform 2",
"types": ["_CONCEPT_"],
"id": "98f59682aab42126e30db05b4fc748fb891654b1"
},
{
"term": "event handler",
"types": ["_CONCEPT_"],
"id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071"
},
{
"term": "fake inform 3",
"types": ["_CONCEPT_"],
"id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c"
},
{
"term": "dictionary",
"types": ["_CONCEPT_"],
"id": "3f57765140cc67750fba716a57c6acd2897aac33"
},
{
"term": "fake inform 4",
"types": ["_CONCEPT_"],
"id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b"
},
{
"term": "ascii alphanumeric",
"types": ["_CONCEPT_"],
"id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20"
}
]
}

0 comments on commit 71e3aa0

Please sign in to comment.