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 @@