feat(jslib): implement toString for UpObject
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
also minor stylistic refactor
This commit is contained in:
parent
2f636288b6
commit
cc3f618375
2 changed files with 13 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
import type { IEntry, IValue, ListingResult } from "./types";
|
||||
|
||||
export { UpEndApi } from "./api";
|
||||
export { Query } from "./query";
|
||||
|
||||
|
@ -8,7 +9,7 @@ export class UpListing {
|
|||
|
||||
constructor(listing: ListingResult) {
|
||||
this.entries = Object.entries(listing).map(
|
||||
(lr) => new UpEntry(...lr, this)
|
||||
(lr) => new UpEntry(...lr, this),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -16,7 +17,7 @@ export class UpListing {
|
|||
const allEntities = new Set(this.entries.map((e) => e.entity));
|
||||
const result: { [key: string]: UpObject } = {};
|
||||
Array.from(allEntities).forEach(
|
||||
(entity) => (result[entity] = new UpObject(entity, this))
|
||||
(entity) => (result[entity] = new UpObject(entity, this)),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
@ -56,13 +57,13 @@ export class UpObject {
|
|||
|
||||
public get attributes() {
|
||||
return (this.listing?.entries || []).filter(
|
||||
(e) => e.entity === this.address
|
||||
(e) => e.entity === this.address,
|
||||
);
|
||||
}
|
||||
|
||||
public get backlinks() {
|
||||
return (this.listing?.entries || []).filter(
|
||||
(e) => e.value.c === this.address
|
||||
(e) => e.value.c === this.address,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -98,8 +99,13 @@ export class UpObject {
|
|||
}
|
||||
|
||||
public identify(): string[] {
|
||||
const lblValues = (this.attr["LBL"] || []).map((e) => String(e.value.c));
|
||||
return lblValues;
|
||||
return (this.attr["LBL"] || []).map((e) => String(e.value.c));
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return [`@${this.address}`, this.identify().join(", ")]
|
||||
.filter(Boolean)
|
||||
.join(" | ");
|
||||
}
|
||||
|
||||
public asDict() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@upnd/upend",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "Client library to interact with the UpEnd system.",
|
||||
"scripts": {
|
||||
"build": "tsc --build --verbose",
|
||||
|
|
Loading…
Reference in a new issue