UNPKG

@kit-data-manager/react-search-component

Version:

All-in-one component for rendering an elastic search UI for searching anything. Built-in support for visualizing related items in a graph and resolving unique identifiers.

42 lines 1.28 kB
import * as z from "zod/mini"; /** * !TODO Replace with resolver from pid-component */ const TS4TIBResponse = z.object({ response: z.object({ docs: z.array(z.object({ label: z.string(), iri: z.string() })) }) }); const SPDX_LICENSE_REGEX = /https:\/\/spdx\.org\/licenses\/(.*)\.json/; export class TempResolver { async resolvePurl(url) { try { const result = await fetch(`https://service.tib.eu/ts4tib/api/select?q=${url}`); const data = await result.json(); const parsed = TS4TIBResponse.parse(data); const entry = parsed.response.docs.find((entry) => entry.iri === url); if (entry) return entry.label; else { console.log("Found no matching entry", parsed.response.docs); return url; } } catch (e) { console.error(e); return url; } } async resolveSpdx(url) { try { const match = SPDX_LICENSE_REGEX.exec(url); return match ? match[1] : null; } catch (e) { console.error(e); return url; } } } export const tempResolver = new TempResolver(); //# sourceMappingURL=TempResolver.js.map