rhizome/src/types.ts

41 lines
847 B
TypeScript
Raw Normal View History

2024-12-21 21:16:18 -06:00
export type JSONLogic = object;
export type FilterExpr = JSONLogic;
export type FilterGenerator = () => FilterExpr;
export type PropertyTypes = string | number | undefined;
export type DomainEntityID = string;
export type PropertyID = string;
export type Properties = {[key: PropertyID]: PropertyTypes};
2024-12-23 17:29:38 -06:00
export class PeerAddress {
addr: string;
port: number;
2024-12-25 16:13:48 -06:00
constructor(addr: string, port: number) {
this.addr = addr;
this.port = port;
}
2024-12-25 16:13:48 -06:00
static fromString(addrString: string): PeerAddress {
const [addr, port] = addrString.trim().split(':');
return new PeerAddress(addr, parseInt(port));
}
2024-12-25 16:13:48 -06:00
toAddrString() {
return `${this.addr}:${this.port}`;
}
2024-12-25 16:13:48 -06:00
toJSON() {
2024-12-22 14:17:44 -06:00
return this.toAddrString();
}
2024-12-25 16:13:48 -06:00
isEqual(other: PeerAddress) {
return this.addr === other.addr && this.port === other.port;
}
};