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
|
|
|
};
|
|
|
|
|
2024-12-22 14:00:51 -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 = {
|
2024-12-22 14:00:51 -06:00
|
|
|
filterExpr: JSON
|
2024-12-21 21:16:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export type QueryResult = {
|
2024-12-22 14:00:51 -06:00
|
|
|
deltas: Delta[]
|
2024-12-21 21:16:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export enum Decision {
|
2024-12-22 14:00:51 -06:00
|
|
|
Accept,
|
|
|
|
Reject,
|
|
|
|
Defer
|
2024-12-21 21:16:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export type JSONLogic = object;
|
|
|
|
|
|
|
|
export type FilterExpr = JSONLogic;
|
|
|
|
|
|
|
|
export type FilterGenerator = () => FilterExpr;
|
|
|
|
|
2024-12-23 20:44:54 -06:00
|
|
|
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};
|
|
|
|
|
2024-12-22 14:00:51 -06:00
|
|
|
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();
|
2024-12-22 14:00:51 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|