diff --git a/src/core/xref.js b/src/core/xref.js index 4e0e9e8b76..dc4e0ba816 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -110,7 +110,7 @@ function findExplicitExternalLinks() { */ function normalizeConfig(xref) { const defaults = { - url: API_URL, + url: new URL("search/", API_URL).href, specs: null, }; @@ -313,24 +313,23 @@ async function getData(queryKeys, apiUrl) { } /** - * @param {RequestEntry[]} keys + * @param {RequestEntry[]} queries * @param {string} url * @returns {Promise>} */ -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])); } /** diff --git a/tests/data/xref/refs.json b/tests/data/xref/refs.json index 23fdd5ca63..4694a24054 100644 --- a/tests/data/xref/refs.json +++ b/tests/data/xref/refs.json @@ -1,8 +1,13 @@ { - "result": [ - [ - "ab7db5bcda5172f65990774c08b2d5623d0ca4d9", - [ + "results": [ + { + "id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9", + "query": { + "term": "fake inform 1", + "types": ["_CONCEPT_"], + "id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9" + }, + "result": [ { "shortname": "local-1", "type": "dfn", @@ -10,10 +15,15 @@ "uri": "#fake-inform-1" } ] - ], - [ - "cb3348a71fc96423a724d214e32b0a6f6d19f270", - [ + }, + { + "id": "cb3348a71fc96423a724d214e32b0a6f6d19f270", + "query": { + "term": "list", + "types": ["_CONCEPT_"], + "id": "cb3348a71fc96423a724d214e32b0a6f6d19f270" + }, + "result": [ { "shortname": "infra", "type": "dfn", @@ -21,10 +31,15 @@ "uri": "#list" } ] - ], - [ - "8ab59f6080eccb6cd1cb43884d30467b294761dd", - [ + }, + { + "id": "8ab59f6080eccb6cd1cb43884d30467b294761dd", + "query": { + "term": "bearing angle", + "types": ["_CONCEPT_"], + "id": "8ab59f6080eccb6cd1cb43884d30467b294761dd" + }, + "result": [ { "shortname": "css-values", "type": "dfn", @@ -32,10 +47,15 @@ "uri": "#bearing-angle" } ] - ], - [ - "a99184f1d06a2664d14b22732d462985ba9993a1", - [ + }, + { + "id": "a99184f1d06a2664d14b22732d462985ba9993a1", + "query": { + "term": "url parser", + "types": ["_CONCEPT_"], + "id": "a99184f1d06a2664d14b22732d462985ba9993a1" + }, + "result": [ { "shortname": "url", "type": "dfn", @@ -43,10 +63,15 @@ "uri": "#concept-url-parser" } ] - ], - [ - "98f59682aab42126e30db05b4fc748fb891654b1", - [ + }, + { + "id": "98f59682aab42126e30db05b4fc748fb891654b1", + "query": { + "term": "fake inform 2", + "types": ["_CONCEPT_"], + "id": "98f59682aab42126e30db05b4fc748fb891654b1" + }, + "result": [ { "shortname": "local-2", "type": "dfn", @@ -54,10 +79,15 @@ "uri": "#fake-inform-2" } ] - ], - [ - "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071", - [ + }, + { + "id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071", + "query": { + "term": "event handler", + "types": ["_CONCEPT_"], + "id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071" + }, + "result": [ { "shortname": "html", "type": "dfn", @@ -65,10 +95,15 @@ "uri": "webappapis.html#event-handlers" } ] - ], - [ - "ea274f5f7e4d9bd49503932f92e96377bcc6d32c", - [ + }, + { + "id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c", + "query": { + "term": "fake inform 3", + "types": ["_CONCEPT_"], + "id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c" + }, + "result": [ { "shortname": "local-3", "type": "dfn", @@ -76,10 +111,15 @@ "uri": "#fake-inform-3" } ] - ], - [ - "3f57765140cc67750fba716a57c6acd2897aac33", - [ + }, + { + "id": "3f57765140cc67750fba716a57c6acd2897aac33", + "query": { + "term": "dictionary", + "types": ["_CONCEPT_"], + "id": "3f57765140cc67750fba716a57c6acd2897aac33" + }, + "result": [ { "shortname": "webidl", "type": "dfn", @@ -87,10 +127,15 @@ "uri": "#dfn-dictionary" } ] - ], - [ - "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b", - [ + }, + { + "id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b", + "query": { + "term": "fake inform 4", + "types": ["_CONCEPT_"], + "id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b" + }, + "result": [ { "shortname": "local-4", "type": "dfn", @@ -98,10 +143,15 @@ "uri": "#fake-inform-4" } ] - ], - [ - "4ef7705f121b9b2228672ec56b8d3a4f491a0c20", - [ + }, + { + "id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20", + "query": { + "term": "ascii alphanumeric", + "types": ["_CONCEPT_"], + "id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20" + }, + "result": [ { "shortname": "infra", "type": "dfn", @@ -109,58 +159,6 @@ "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" } ] }