diff --git a/tools/upend_js/index.ts b/tools/upend_js/index.ts index 429a8ba..e57144b 100644 --- a/tools/upend_js/index.ts +++ b/tools/upend_js/index.ts @@ -67,9 +67,9 @@ export class UpObject { ); } - private _attr: { [key: string]: UpEntry[] } | undefined; + private _attr: Record | undefined; - public get attr() { + public get attr(): Record { if (!this._attr) { const result = {} as { [key: string]: UpEntry[] }; this.attributes.forEach((entry) => { @@ -94,8 +94,8 @@ export class UpObject { return this._attr; } - public get(attr: string) { - return this.attr[attr] ? this.attr[attr][0].value.c : undefined; + public get(attr: string): string | number | null | undefined { + return this.attr[attr]?.[0].value.c; } public identify(): string[] { diff --git a/tools/upend_js/package.json b/tools/upend_js/package.json index 90381ab..468e592 100644 --- a/tools/upend_js/package.json +++ b/tools/upend_js/package.json @@ -1,6 +1,6 @@ { "name": "@upnd/upend", - "version": "0.3.2", + "version": "0.3.3", "description": "Client library to interact with the UpEnd system.", "scripts": { "build": "tsc --build --verbose", diff --git a/webui/src/lib/components/Inspect.svelte b/webui/src/lib/components/Inspect.svelte index b4c6350..b66bb46 100644 --- a/webui/src/lib/components/Inspect.svelte +++ b/webui/src/lib/components/Inspect.svelte @@ -237,7 +237,7 @@ }); break; case 'entry-delete': { - const inEntry = $entity?.attr[`~${ATTR_IN}`].find((e) => e.entity === change.address); + const inEntry = $entity?.attr[`~${ATTR_IN}`]?.find((e) => e.entity === change.address); if (inEntry) { await api.deleteEntry(inEntry.address); } else { diff --git a/webui/src/lib/components/MultiGroupEditor.svelte b/webui/src/lib/components/MultiGroupEditor.svelte index bdd845c..cc65a6e 100644 --- a/webui/src/lib/components/MultiGroupEditor.svelte +++ b/webui/src/lib/components/MultiGroupEditor.svelte @@ -26,7 +26,7 @@ .map((v) => v.c as string) .filter((groupAddr) => { return Object.values(allGroups.objects).every((obj) => { - return obj.attr[ATTR_IN].some((v) => v.value.c === groupAddr); + return obj.attr[ATTR_IN]?.some((v) => v.value.c === groupAddr); }); }) ); @@ -55,7 +55,7 @@ async function removeGroup(address: string) { await Promise.all( entities.map((entity) => { - const group = groupListing?.objects[entity].attr[ATTR_IN].find( + const group = groupListing?.objects[entity].attr[ATTR_IN]?.find( (v) => v.value.c === address ); if (group) { diff --git a/webui/src/lib/components/display/blobs/ImageViewer.svelte b/webui/src/lib/components/display/blobs/ImageViewer.svelte index 8f652ac..476a20b 100644 --- a/webui/src/lib/components/display/blobs/ImageViewer.svelte +++ b/webui/src/lib/components/display/blobs/ImageViewer.svelte @@ -57,7 +57,7 @@ if (annotation.get('W3C_FRAGMENT_SELECTOR')) { anno.addAnnotation({ type: 'Annotation', - body: annotation.attr[ATTR_LABEL].map((e) => { + body: (annotation.attr[ATTR_LABEL] || []).map((e) => { return { type: 'TextualBody', value: String(e.value.c), @@ -145,9 +145,9 @@ anno.on('updateAnnotation', async (annotation) => { const annotationObject = await api.fetchEntity(annotation.id); await Promise.all( - annotationObject.attr[ATTR_LABEL].concat( - annotationObject.attr['W3C_FRAGMENT_SELECTOR'] - ).map(async (e) => api.deleteEntry(e.address)) + (annotationObject.attr[ATTR_LABEL] || []) + .concat(annotationObject.attr['W3C_FRAGMENT_SELECTOR'] || []) + .map(async (e) => api.deleteEntry(e.address)) ); await api.putEntry([ {