/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { FinalCompressedId, LocalCompressedId, NumericUuid } from "./identifiers.js"; import type { SessionId, StableId } from "./types/index.js"; /** * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms). * This collection of all sessions comprises a distributed document's IDs. */ export declare class Sessions { private readonly uuidSpace; private readonly sessionCache; constructor(sessions?: [sessionBase: NumericUuid, session: Session][]); sessions(): IterableIterator; getOrCreate(sessionId: SessionId): Session; get(sessionId: SessionId): Session | undefined; getContainingCluster(query: StableId): [cluster: IdCluster, alignedLocal: LocalCompressedId] | undefined; clusterCollides(cluster: IdCluster): boolean; equals(other: Sessions, includeLocalState: boolean): boolean; } /** * The IDs created by a specific session, stored as a cluster chain to allow for fast conversions. */ export declare class Session { private readonly clusterChain; readonly sessionUuid: NumericUuid; constructor(sessionId: SessionId | NumericUuid); /** * Adds a new empty cluster to the cluster chain of this session. */ addNewCluster(baseFinalId: FinalCompressedId, capacity: number, count: number): IdCluster; isEmpty(): boolean; /** * Returns the last cluster in this session's cluster chain, if any. */ getLastCluster(): IdCluster | undefined; /** * Converts the local ID from this session to a final ID, if possible. * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized. */ tryConvertToFinal(searchLocal: LocalCompressedId, includeAllocated: boolean): FinalCompressedId | undefined; /** * Returns the cluster containing the supplied local ID, if possible. * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized. */ getClusterByLocal(localId: LocalCompressedId, includeAllocated: boolean): IdCluster | undefined; /** * Returns the cluster containing the supplied final ID, if possible. */ getClusterByAllocatedFinal(final: FinalCompressedId): IdCluster | undefined; /** * Returns the cluster from the supplied cluster chain containing the supplied final ID, if possible. * `clusterChain` must be sorted by final/local base ID. */ static getContainingCluster(finalId: FinalCompressedId, clusterChain: readonly IdCluster[]): IdCluster | undefined; static binarySearch(search: S, arr: readonly T[], comparator: (a: S, b: T) => number): T | undefined; equals(other: Session): boolean; } /** * A cluster of final (sequenced via consensus), sequentially allocated compressed IDs. * A final ID in a cluster decompresses to a sequentially allocated UUID that is the result of adding its offset within * the cluster to base UUID for the session that created it. */ export interface IdCluster { /** * The session that created this cluster. */ readonly session: Session; /** * The first final ID in the cluster. */ readonly baseFinalId: FinalCompressedId; /** * The local ID aligned with `baseFinalId`. */ readonly baseLocalId: LocalCompressedId; /** * The total number of final IDs reserved for allocation in the cluster. * Clusters are reserved in blocks as a performance optimization. */ capacity: number; /** * The number of final IDs currently allocated in the cluster. */ count: number; } export declare function clustersEqual(a: IdCluster, b: IdCluster): boolean; /** * Returns the final ID that is aligned with the supplied local ID within a cluster. * Includes allocated IDs. */ export declare function getAlignedFinal(cluster: IdCluster, localWithin: LocalCompressedId): FinalCompressedId | undefined; /** * Returns the local ID that is aligned with the supplied final ID within a cluster. * Fails if the supplied ID does not fall within the cluster bounds. */ export declare function getAlignedLocal(cluster: IdCluster, finalWithin: FinalCompressedId): LocalCompressedId; /** * Returns the last allocated final ID (i.e. any ID between base final and base final + capacity) within a cluster */ export declare function lastAllocatedFinal(cluster: IdCluster): FinalCompressedId; /** * Returns the last allocated final ID (i.e. any ID between base final and base final + count) within a cluster */ export declare function lastFinalizedFinal(cluster: IdCluster): FinalCompressedId; /** * Returns the last allocated local ID (i.e. any ID between base local and base local + capacity) within a cluster */ export declare function lastAllocatedLocal(cluster: IdCluster): LocalCompressedId; /** * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster */ export declare function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId; //# sourceMappingURL=sessions.d.ts.map