/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { ITelemetryBaseLogger } from "@fluidframework/core-interfaces"; import type { TelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal"; import type { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/legacy"; import { type Index } from "./persistanceUtilities.js"; import { Sessions } from "./sessions.js"; import type { IIdCompressor, IIdCompressorCore, IdCreationRange, OpSpaceCompressedId, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, SessionId, SessionSpaceCompressedId, StableId } from "./types/index.js"; /** * See {@link IIdCompressor} and {@link IIdCompressorCore} */ export declare class IdCompressor implements IIdCompressor, IIdCompressorCore { private readonly logger; /** * Max allowed initial cluster size. */ static readonly maxClusterSize: number; readonly localSessionId: SessionId; private readonly localSession; private readonly normalizer; private localGenCount; /** * The gen count to be annotated on the range returned by the next call to `takeNextCreationRange`. * This is advanced to `generatedIdCount` + 1 each time it is called. * On the other hand, when `resetUnfinalizedCreationRange` is called, * this is moved back to the start of the unfinalized range, to ensure those IDs are included in the next range. */ private nextRangeBaseGenCount; private readonly sessions; private readonly finalSpace; /** * Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs. * Eventually, this can be adjusted dynamically to have cluster reservation policies that * optimize the number of eager finals. * It is not readonly as it is accessed by tests for clear-box testing. */ private nextRequestedClusterSize; private telemetryLocalIdCount; private telemetryEagerFinalIdCount; private ongoingGhostSession?; constructor(localSessionIdOrDeserialized: SessionId | Sessions, logger: TelemetryLoggerExt | undefined); generateCompressedId(): SessionSpaceCompressedId; generateDocumentUniqueId(): (SessionSpaceCompressedId & OpSpaceCompressedId) | StableId; /** * Starts a ghost session. Only exposed for test purposes (this class is not exported from the package). * @param ghostSessionId - The session ID to start the ghost session with. */ startGhostSession(ghostSessionId: SessionId): void; /** * {@inheritdoc IIdCompressorCore.beginGhostSession} */ beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): void; private generateNextLocalId; takeNextCreationRange(): IdCreationRange; takeUnfinalizedCreationRange(): IdCreationRange; resetUnfinalizedCreationRange(): void; private updateToRange; private static assertValidRange; finalizeCreationRange(range: IdCreationRange): void; private addEmptyCluster; normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId; normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId; decompress(id: SessionSpaceCompressedId): StableId; recompress(uncompressed: StableId): SessionSpaceCompressedId; tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined; serialize(withSession: true): SerializedIdCompressorWithOngoingSession; serialize(withSession: false): SerializedIdCompressorWithNoSession; static deserialize(params: { serialized: SerializedIdCompressorWithOngoingSession; logger?: TelemetryLoggerExt | undefined; newSessionId?: never; } | { serialized: SerializedIdCompressorWithNoSession; newSessionId: SessionId; logger?: TelemetryLoggerExt | undefined; }): IdCompressor; static deserialize2_0(index: Index, sessionId: SessionId | undefined, logger: TelemetryLoggerExt | undefined): IdCompressor; equals(other: IdCompressor, includeLocalState: boolean): boolean; } /** * Create a new {@link IIdCompressor}. * * @legacy @beta */ export declare function createIdCompressor(logger?: ITelemetryBaseLogger): IIdCompressor; /** * Create a new {@link IIdCompressor}. * @param sessionId - The seed ID for the compressor. * * @legacy @beta */ export declare function createIdCompressor(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor; /** * Deserializes the supplied state into an ID compressor. * * @legacy @beta */ export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithOngoingSession, logger?: ITelemetryLoggerExt): IIdCompressor; /** * Deserializes the supplied state into an ID compressor. * * @legacy @beta */ export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId, logger?: ITelemetryLoggerExt): IIdCompressor; /** * Serializes an ID compressor. * @param compressor - The compressor to serialize. * @param withSession - If true, the serialized state will include local session * state (for stashing). If false, only finalized state is included (for summaries). * @legacy @beta */ export declare function serializeIdCompressor(compressor: IIdCompressor, withSession: true): SerializedIdCompressorWithOngoingSession; /** * Serializes an ID compressor. * @param compressor - The compressor to serialize. * @param withSession - If true, the serialized state will include local session * state (for stashing). If false, only finalized state is included (for summaries). * @legacy @beta */ export declare function serializeIdCompressor(compressor: IIdCompressor, withSession: false): SerializedIdCompressorWithNoSession; /** * Casts an {@link IIdCompressor} to include {@link IIdCompressorCore}. * * @remarks * Compressors returned by `createIdCompressor` and `deserializeIdCompressor` * always implement both {@link IIdCompressor} and {@link IIdCompressorCore}, but their * public return type is narrowed to {@link IIdCompressor}. Internal consumers that * need access to core compressor operations (serialization, range management, etc.) * use this function to recover the {@link IIdCompressorCore} surface. * * @param compressor - A compressor created by `createIdCompressor` or * `deserializeIdCompressor`. * @returns The same compressor, typed to include {@link IIdCompressorCore}. * @internal */ export declare function toIdCompressorWithCore(compressor: IIdCompressor): IIdCompressor & IIdCompressorCore; //# sourceMappingURL=idCompressor.d.ts.map