diff --git a/tools/upend_js/index.ts b/tools/upend_js/index.ts index a70e9a9..21326fb 100644 --- a/tools/upend_js/index.ts +++ b/tools/upend_js/index.ts @@ -1,25 +1,19 @@ -import type { - Address, - IEntry, - ListingResult, - OrderedListing, - VALUE_TYPE, -} from "./types"; +import type { IEntry, ListingResult, VALUE_TYPE } from "./types"; -export function listingAsOrdered(listing: ListingResult): OrderedListing { - const entries = Object.entries(listing) as [Address, IEntry][]; - return entries - .sort(([_, a], [__, b]) => - String(a.value.c).localeCompare(String(b.value.c)) - ) - .sort(([_, a], [__, b]) => - String(a.value.t).localeCompare(String(b.value.t)) - ) - .sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute)); -} +// export function listingAsOrdered(listing: ListingResult): OrderedListing { +// const entries = Object.entries(listing) as [Address, IEntry][]; +// return entries +// .sort(([_, a], [__, b]) => +// String(a.value.c).localeCompare(String(b.value.c)) +// ) +// .sort(([_, a], [__, b]) => +// String(a.value.t).localeCompare(String(b.value.t)) +// ) +// .sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute)); +// } export class UpListing { - private entries: UpEntry[]; + public readonly entries: UpEntry[]; constructor(listing: ListingResult) { this.entries = Object.entries(listing).map((lr) => new UpEntry(...lr)); @@ -46,17 +40,27 @@ export class UpObject { this.entries = entries; } + public bindAppend(entries: UpEntry[]) { + this.entries.push(...entries); + } + + public get attributes() { + return this.entries.filter((e) => e.entity === this.address); + } + + public get backlinks() { + return this.entries.filter((e) => e.value.c === this.address); + } + public get attr() { const result = {} as { [key: string]: UpEntry[] }; - this.entries - .filter((e) => e.entity == this.address) - .forEach((entry) => { - if (!result[entry.attribute]) { - result[entry.attribute] = []; - } + this.attributes.forEach((entry) => { + if (!result[entry.attribute]) { + result[entry.attribute] = []; + } - result[entry.attribute].push(entry); - }); + result[entry.attribute].push(entry); + }); return result; } @@ -65,6 +69,25 @@ export class UpObject { return this.attr[attr] ? this.attr[attr][0].value.c : undefined; } + public identify(): string[] { + // Get all places where this Object is "had" + const hasEntries = this.backlinks + .filter((entry) => entry.attribute === "HAS") + .map((entry) => entry.address); + + // Out of those relations, retrieve their ALIAS attrs + const hasAliases = this.entries + .filter( + (entry) => + entry.attribute === "ALIAS" && hasEntries.includes(entry.entity) + ) + .map((entry) => String(entry.value.c)); + + const lblValues = (this.attr["LBL"] || []).map((e) => String(e.value.c)); + + return lblValues.concat(hasAliases); + } + public asDict() { return { address: this.address, diff --git a/tools/upend_js/types.ts b/tools/upend_js/types.ts index 7b825f7..6e4adbd 100644 --- a/tools/upend_js/types.ts +++ b/tools/upend_js/types.ts @@ -11,7 +11,7 @@ export interface ListingResult { [key: string]: IEntry; } -export type OrderedListing = [Address, IEntry][]; +// export type OrderedListing = [Address, IEntry][]; export interface Job { title: string; diff --git a/ui/src/components/Address.svelte b/ui/src/components/Address.svelte index 00795ec..f9ba4b0 100644 --- a/ui/src/components/Address.svelte +++ b/ui/src/components/Address.svelte @@ -1,10 +1,10 @@
diff --git a/ui/src/components/Inspect.svelte b/ui/src/components/Inspect.svelte index 0e0a07f..b2e2c33 100644 --- a/ui/src/components/Inspect.svelte +++ b/ui/src/components/Inspect.svelte @@ -7,6 +7,7 @@ import BlobPreview from "./BlobPreview.svelte"; import { setContext } from "svelte"; import { writable } from "svelte/store"; + import type { UpEntry } from "upend"; export let address: string; export let index: number | undefined; @@ -17,12 +18,9 @@ setContext("browse", { index: indexStore }); - $: ({ error, revalidate, attributes, backlinks } = useEntity(address)); + $: ({ entity, error, revalidate } = useEntity(address)); - $: allTypeAddresses = $attributes - .map(([_, attr]) => attr) - .filter((attr) => attr.attribute == "IS") - .map((attr) => attr.value.c); + $: allTypeAddresses = ($entity?.attr["IS"] || []).map((attr) => attr.value.c); $: allTypeEntries = query( () => @@ -34,19 +32,19 @@ let allTypes: { [key: string]: UpType } = {}; $: { allTypes = {}; - $allTypeEntries.forEach(([_, entry]) => { + ($allTypeEntries?.entries || []).forEach((entry) => { if (allTypes[entry.entity] === undefined) { allTypes[entry.entity] = new UpType(entry.entity); } switch (entry.attribute) { case "TYPE": - allTypes[entry.entity].name = entry.value.c; + allTypes[entry.entity].name = String(entry.value.c); break; case "TYPE_HAS": case "TYPE_REQUIRES": case "TYPE_ID": - allTypes[entry.entity].attributes.push(entry.value.c); + allTypes[entry.entity].attributes.push(String(entry.value.c)); break; } }); @@ -54,14 +52,14 @@ allTypes = allTypes; } - let typedAttributes = {} as { [key: string]: [string, IEntry][] }; - let untypedAttributes = [] as [string, IEntry][]; + let typedAttributes = {} as { [key: string]: UpEntry[] }; + let untypedAttributes = [] as UpEntry[]; $: { typedAttributes = {}; untypedAttributes = []; - $attributes.forEach(([entryAddr, entry]) => { + ($entity?.attributes || []).forEach((entry) => { const entryTypes = Object.entries(allTypes).filter(([_, t]) => t.attributes.includes(entry.attribute) ); @@ -70,10 +68,10 @@ if (typedAttributes[addr] == undefined) { typedAttributes[addr] = []; } - typedAttributes[addr].push([entryAddr, entry]); + typedAttributes[addr].push(entry); }); } else { - untypedAttributes.push([entryAddr, entry]); + untypedAttributes.push(entry); } }); @@ -82,9 +80,9 @@ } $: filteredUntypedAttributes = untypedAttributes.filter( - ([_, entry]) => + (entry) => entry.attribute !== "IS" || - !Object.keys(typedAttributes).includes(entry.value.c) + !Object.keys(typedAttributes).includes(String(entry.value.c)) ); @@ -113,11 +111,11 @@ on:changed={revalidate} /> {/if} - {#if $backlinks.length > 0} + {#if $entity?.backlinks.length > 0} diff --git a/ui/src/components/widgets/List.svelte b/ui/src/components/widgets/List.svelte index fbc8e89..3b6aaed 100644 --- a/ui/src/components/widgets/List.svelte +++ b/ui/src/components/widgets/List.svelte @@ -1,13 +1,14 @@ diff --git a/ui/src/components/widgets/Table.svelte b/ui/src/components/widgets/Table.svelte index cdcd8dc..414051f 100644 --- a/ui/src/components/widgets/Table.svelte +++ b/ui/src/components/widgets/Table.svelte @@ -1,20 +1,20 @@