diff --git a/lxl-web/src/lib/types/search.ts b/lxl-web/src/lib/types/search.ts index 1aeec90df..6256deb65 100644 --- a/lxl-web/src/lib/types/search.ts +++ b/lxl-web/src/lib/types/search.ts @@ -134,7 +134,7 @@ type MappingObj = { [key in SearchOperators]: SearchMapping[] | string | FramedD export interface SearchMapping extends MappingObj { alias: string; - property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom; + property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom | InvalidProperty; object?: FramedData; up: { '@id': string }; } @@ -148,6 +148,11 @@ export interface DatatypeProperty { '@id': string; } +interface InvalidProperty { + '@type': '_Invalid'; + label: string; +} + interface PropertyChainAxiom { propertyChainAxiom: (ObjectProperty | DatatypeProperty)[]; label: string; // e.g. "instanceOf language" diff --git a/lxl-web/src/lib/utils/search.ts b/lxl-web/src/lib/utils/search.ts index 2925ba60e..139de61fd 100644 --- a/lxl-web/src/lib/utils/search.ts +++ b/lxl-web/src/lib/utils/search.ts @@ -26,6 +26,8 @@ import { type LocaleCode as LangCode } from '$lib/i18n/locales'; import { bestImage, bestSize, toSecure } from '$lib/utils/auxd'; import getAtPath from '$lib/utils/getAtPath'; import { getUriSlug } from '$lib/utils/http'; +import { error } from '@sveltejs/kit'; +import { env } from '$env/dynamic/public'; export async function asResult( view: PartialCollectionView, @@ -90,6 +92,16 @@ export function displayMappings( const operator = _hasOperator(m); if ('property' in m && operator) { + // Mock old behaviour for 'classic' search GUI, i.e show error page + // when encountering an invalid property in order to provide feedback. + // TODO remove this when Supersearch is fully implemented. + const useSuperSearch = env?.PUBLIC_USE_SUPERSEARCH === 'true'; + if (!useSuperSearch && m.property?.['@type'] === '_Invalid') { + error(400, { + message: `Invalid query, please check the documentation. Unrecognized property alias: ${m.property?.label ?? ''}` + }); + } + const property = m[operator] as FramedData; return { ...(isObject(m.property) && { '@id': m.property['@id'] }), @@ -102,7 +114,7 @@ export function displayMappings( 'No label', // lensandformat? property: m.property?.librisQueryCode || - m.property?.['@id'].replace('https://id.kb.se/vocab/', '') || + m.property?.['@id']?.replace('https://id.kb.se/vocab/', '') || '', //TODO replace with something better operator, ...('up' in m && { up: replacePath(m.up as Link, usePath) })