rhizome/src/types.ts

65 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-12-23 17:29:38 -06:00
export type PointerTarget = string | number | undefined;
2024-12-21 21:16:18 -06:00
export type Pointer = {
2024-12-23 17:29:38 -06:00
localContext: string;
target: PointerTarget;
targetContext?: string;
2024-12-21 21:16:18 -06:00
};
export type Delta = {
2024-12-23 17:29:38 -06:00
creator: string;
host: string;
pointers: Pointer[];
receivedFrom?: PeerAddress;
2024-12-21 21:16:18 -06:00
}
export type DeltaContext = Delta & {
creatorAddress: string;
};
export type Query = {
filterExpr: JSON
2024-12-21 21:16:18 -06:00
};
export type QueryResult = {
deltas: Delta[]
2024-12-21 21:16:18 -06:00
};
export enum Decision {
Accept,
Reject,
Defer
2024-12-21 21:16:18 -06:00
};
export type JSONLogic = object;
export type FilterExpr = JSONLogic;
export type FilterGenerator = () => FilterExpr;
export type DeltaFilter = (delta: Delta) => boolean;
2024-12-21 21:16:18 -06:00
export type PropertyTypes = string | number | undefined;
2024-12-23 17:29:38 -06:00
export type Properties = {[key: string]: PropertyTypes};
export class PeerAddress {
addr: string;
port: number;
constructor(addr: string, port: number) {
this.addr = addr;
this.port = port;
}
static fromString(addrString: string): PeerAddress {
const [addr, port] = addrString.trim().split(':');
return new PeerAddress(addr, parseInt(port));
}
toAddrString() {
return `${this.addr}:${this.port}`;
}
toJSON() {
2024-12-22 14:17:44 -06:00
return this.toAddrString();
}
};