feat: version 2 beta

This commit is contained in:
2025-04-25 22:39:47 +00:00
commit 1e58359905
75 changed files with 6899 additions and 0 deletions

49
libraries/timestamp.ts Normal file
View File

@@ -0,0 +1,49 @@
export const RADIX = 36;
export class Timestamp {
readonly time: number;
readonly logical: number;
constructor(time: TimeLike, logical = 0) {
this.time = typeof time === "string" ? parseInt(time, RADIX) : time;
this.logical = logical;
}
static bigger(a: Timestamp, b: Timestamp): Timestamp {
return a.compare(b) === -1 ? b : a;
}
encode(): string {
return this.time.toString(RADIX);
}
compare(other: Timestamp): 1 | 0 | -1 {
if (this.time > other.time) {
return 1;
}
if (this.time < other.time) {
return -1;
}
if (this.logical > other.logical) {
return 1;
}
if (this.logical < other.logical) {
return -1;
}
return 0;
}
toJSON(): TimestampJSON {
return Object.freeze({
time: this.encode(),
logical: this.logical,
});
}
}
export type TimeLike = string | number;
type TimestampJSON = {
readonly time: string;
readonly logical: number;
};