/** * HLC -- Hybrid Logical Clock. * * Pure functions + Effect-based managed clock. * * @module */ import { Effect, Ref } from 'effect'; interface HLCShape { readonly wall_ms: number; readonly counter: number; readonly node_id: string; } /** * Compare two HLC timestamps. Returns -1, 0, or 1. * * Compares wall_ms first, then counter, then node_id lexicographically. * * @example * ```ts * const a = HLC.create('node-1'); * const b = HLC.increment(a, 1000); * const cmp = HLC.compare(a, b); * // cmp === -1 (a is before b) * ``` */ export declare const compare: (a: HLCShape, b: HLCShape) => -1 | 0 | 1; /** * Create a managed HLC clock as an Effect Ref. * * @example * ```ts * import { Effect } from 'effect'; * * const program = Effect.gen(function* () { * const clock = yield* HLC.makeClock('node-1'); * const ts = yield* HLC.tick(clock); * // ts.wall_ms === Date.now() (approximately) * }); * ``` */ export declare const makeClock: (nodeId: string) => Effect.Effect>; /** * Tick a managed clock forward, returning the new HLC timestamp. * * @example * ```ts * const ts = yield* HLC.tick(clock); * // ts.wall_ms >= previous wall_ms * ``` */ export declare const tick: (clock: Ref.Ref) => Effect.Effect; /** * Receive a remote HLC timestamp and merge it into the managed clock. * * @example * ```ts * const remoteTs = HLC.decode(remoteEncoded); * const merged = yield* HLC.receive(clock, remoteTs); * // merged.wall_ms >= remoteTs.wall_ms * ``` */ export declare const receive: (clock: Ref.Ref, remote: HLCShape) => Effect.Effect; /** * HLC namespace -- Hybrid Logical Clock. * * Pure functions for creating, comparing, incrementing, and merging HLC * timestamps, plus Effect-based managed clock helpers. Encodes to/from * a deterministic colon-separated hex string format. * * @example * ```ts * import { HLC } from '@czap/core'; * * const a = HLC.increment(HLC.create('A'), Date.now()); * const b = HLC.increment(HLC.create('B'), Date.now()); * const merged = HLC.merge(a, b, Date.now()); * const encoded = HLC.encode(merged); * const decoded = HLC.decode(encoded); * ``` */ export declare const HLC: { create: (nodeId: string) => HLCShape; compare: (a: HLCShape, b: HLCShape) => -1 | 0 | 1; increment: (hlc: HLCShape, now?: number) => HLCShape; merge: (local: HLCShape, remote: HLCShape, now?: number) => HLCShape; encode: (hlc: HLCShape) => string; decode: (s: string) => HLCShape; makeClock: (nodeId: string) => Effect.Effect>; tick: (clock: Ref.Ref) => Effect.Effect; receive: (clock: Ref.Ref, remote: HLCShape) => Effect.Effect; }; export declare namespace HLC { /** Structural shape of a hybrid logical clock timestamp: `{ wall_ms, counter, node_id }`. */ type Shape = HLCShape; } export {}; //# sourceMappingURL=hlc.d.ts.map