@fluidframework/id-compressor 3.3.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/idCompressor.d.ts +10 -17
  3. package/dist/idCompressor.d.ts.map +1 -1
  4. package/dist/idCompressor.js +68 -35
  5. package/dist/idCompressor.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/packageVersion.d.ts +1 -1
  10. package/dist/packageVersion.js +1 -1
  11. package/dist/packageVersion.js.map +1 -1
  12. package/dist/test/sharding.fuzz.spec.js.map +1 -1
  13. package/dist/test/sharding.spec.js.map +1 -1
  14. package/dist/test/types/validateIdCompressorPrevious.generated.js.map +1 -1
  15. package/dist/types/idCompressor.d.ts +110 -31
  16. package/dist/types/idCompressor.d.ts.map +1 -1
  17. package/dist/types/idCompressor.js.map +1 -1
  18. package/dist/types/index.d.ts +1 -1
  19. package/dist/types/index.d.ts.map +1 -1
  20. package/dist/types/index.js.map +1 -1
  21. package/lib/idCompressor.d.ts +10 -17
  22. package/lib/idCompressor.d.ts.map +1 -1
  23. package/lib/idCompressor.js +69 -36
  24. package/lib/idCompressor.js.map +1 -1
  25. package/lib/index.d.ts +1 -1
  26. package/lib/index.d.ts.map +1 -1
  27. package/lib/index.js.map +1 -1
  28. package/lib/packageVersion.d.ts +1 -1
  29. package/lib/packageVersion.js +1 -1
  30. package/lib/packageVersion.js.map +1 -1
  31. package/lib/test/sharding.fuzz.spec.js.map +1 -1
  32. package/lib/test/sharding.spec.js.map +1 -1
  33. package/lib/test/types/validateIdCompressorPrevious.generated.js.map +1 -1
  34. package/lib/types/idCompressor.d.ts +110 -31
  35. package/lib/types/idCompressor.d.ts.map +1 -1
  36. package/lib/types/idCompressor.js.map +1 -1
  37. package/lib/types/index.d.ts +1 -1
  38. package/lib/types/index.d.ts.map +1 -1
  39. package/lib/types/index.js.map +1 -1
  40. package/package.json +9 -42
  41. package/src/idCompressor.ts +90 -42
  42. package/src/index.ts +10 -7
  43. package/src/packageVersion.ts +1 -1
  44. package/src/test/types/validateIdCompressorPrevious.generated.ts +1 -121
  45. package/src/types/idCompressor.ts +119 -31
  46. package/src/types/index.ts +3 -0
@@ -1 +1 @@
1
- {"version":3,"file":"idCompressor.js","sourceRoot":"","sources":["../src/idCompressor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAunCH,gDA2BC;AA4BD,0DA4BC;AAuDD,sDAMC;AAiBD,wDAQC;AA9xCD,+DAA8E;AAE9E,kEAA6D;AAE7D,uEAIkD;AAIlD,mDAA6C;AAC7C,qDAK0B;AAC1B,uEAQmC;AACnC,2EAAqE;AACrE,+CAQuB;AAevB,+CAAwD;AACxD,iDAQwB;AAExB,SAAS,sBAAsB,CAAC,aAAqB,EAAE,WAAmB;IACzE,OAAO,IAAI,uBAAY,CAAC,+BAA+B,EAAE;QACxD,aAAa;QACb,WAAW;KACX,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC;;GAEG;AACH,MAAa,YAAY;IAyFN;IAMA;IA9FlB;;OAEG;IACI,MAAM,CAAU,cAAc,GAAG,CAAC,IAAI,EAAE,CAAC;IAEhD,sBAAsB;IAEN,cAAc,CAAY;IACzB,YAAY,CAAU;IACtB,UAAU,GAAG,IAAI,kDAAsB,EAAE,CAAC;IAC3D,mDAAmD;IAC3C,aAAa,GAAG,CAAC,CAAC;IAE1B;;;;;;OAMG;IACK,aAAa,CA6BR;IAEb,aAAa;IAEb,sBAAsB;IAEtB;;;;;OAKG;IACK,qBAAqB,GAAG,CAAC,CAAC;IACjB,QAAQ,GAAG,IAAI,sBAAQ,EAAE,CAAC;IAC1B,UAAU,GAAG,IAAI,0BAAU,EAAE,CAAC;IAE/C,aAAa;IAEb,0BAA0B;IAE1B;;;;;OAKG;IACH,8DAA8D;IACt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CAAC;AACxD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport type { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { TelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tLoggingError,\n\tcreateChildLogger,\n\textractTelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n// eslint-disable-next-line import-x/no-internal-modules -- Needed to avoid specialized /internal ITelemetryLoggerExt\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/legacy\";\n\nimport { FinalSpace } from \"./finalSpace.js\";\nimport {\n\ttype FinalCompressedId,\n\ttype LocalCompressedId,\n\ttype NumericUuid,\n\tisFinalId,\n} from \"./identifiers.js\";\nimport {\n\ttype Index,\n\treadBoolean,\n\treadNumber,\n\treadNumericUuid,\n\twriteBoolean,\n\twriteNumber,\n\twriteNumericUuid,\n} from \"./persistanceUtilities.js\";\nimport { SessionSpaceNormalizer } from \"./sessionSpaceNormalizer.js\";\nimport {\n\ttype IdCluster,\n\tSession,\n\tSessions,\n\tgetAlignedFinal,\n\tgetAlignedLocal,\n\tlastFinalizedFinal,\n\tlastFinalizedLocal,\n} from \"./sessions.js\";\nimport type {\n\tShardToken,\n\tIIdCompressor,\n\tIIdCompressorCore,\n\tIdCreationRange,\n\tOpSpaceCompressedId,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n\tSessionId,\n\tSessionSpaceCompressedId,\n\tStableId,\n\tShardSynchronizationToken,\n} from \"./types/index.js\";\nimport { SerializationVersion } from \"./types/index.js\";\nimport {\n\tcreateSessionId,\n\tgenCountFromLocalId,\n\tlocalIdFromGenCount,\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n} from \"./utilities.js\";\n\nfunction rangeFinalizationError(expectedStart: number, actualStart: number): LoggingError {\n\treturn new LoggingError(\"Ranges finalized out of order\", {\n\t\texpectedStart,\n\t\tactualStart,\n\t});\n}\n\nconst MAX_STRIDE_LENGTH = 1000000;\n\n/**\n * See {@link IIdCompressor} and {@link IIdCompressorCore}\n */\nexport class IdCompressor implements IIdCompressor, IIdCompressorCore {\n\t/**\n\t * Max allowed initial cluster size.\n\t */\n\tpublic static readonly maxClusterSize = 2 ** 20;\n\n\t// #region Local state\n\n\tpublic readonly localSessionId: SessionId;\n\tprivate readonly localSession: Session;\n\tprivate readonly normalizer = new SessionSpaceNormalizer();\n\t// The number of IDs generated by the local session\n\tprivate localGenCount = 0;\n\n\t/**\n\t * The sharding state of this compressor, if it has been sharded or is a shard itself.\n\t * When defined, this compressor operates in \"sharding mode\" where:\n\t * - IDs are generated using stride-based allocation (no eager finals)\n\t * - The normalizer backfills all IDs in each stride cycle\n\t * - Normal operation resumes when all children are disposed\n\t */\n\tprivate shardingState?:\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Current stride - used when this compressor has active children.\n\t\t\t\t * Changes each time shard() is called.\n\t\t\t\t */\n\t\t\t\tcurrentStride: number;\n\n\t\t\t\t/**\n\t\t\t\t * Original stride - the stride this compressor was created with.\n\t\t\t\t * Used when this compressor has no children (is a leaf).\n\t\t\t\t * IMMUTABLE after creation.\n\t\t\t\t */\n\t\t\t\toriginalStride: number;\n\n\t\t\t\t/**\n\t\t\t\t * Set of unique child shard IDs (UUIDs) currently active.\n\t\t\t\t * Each child is assigned a UUID when created via shard().\n\t\t\t\t * Safe across serialization/deserialization cycles.\n\t\t\t\t */\n\t\t\t\tactiveChildIds: Set<SessionId>;\n\n\t\t\t\t/**\n\t\t\t\t * This compressor's unique shard ID within its parent (if it's a child).\n\t\t\t\t * Undefined for root compressors.\n\t\t\t\t * Assigned by parent when creating this shard.\n\t\t\t\t */\n\t\t\t\tshardId?: SessionId;\n\t\t }\n\t\t| undefined;\n\n\t// #endregion\n\n\t// #region Final state\n\n\t/**\n\t * The gen count to be annotated on the range returned by the next call to `takeNextCreationRange`.\n\t * This is advanced to `localGenCount` + 1 each time it is called.\n\t * On the other hand, when `resetUnfinalizedCreationRange` is called,\n\t * this is moved back to the start of the unfinalized range, to ensure those IDs are included in the next range.\n\t */\n\tprivate nextRangeBaseGenCount = 1;\n\tprivate readonly sessions = new Sessions();\n\tprivate readonly finalSpace = new FinalSpace();\n\n\t// #endregion\n\n\t// #region Ephemeral state\n\n\t/**\n\t * Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.\n\t * Eventually, this can be adjusted dynamically to have cluster reservation policies that\n\t * optimize the number of eager finals.\n\t * It is not readonly as it is accessed by tests for clear-box testing.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/prefer-readonly\n\tprivate nextRequestedClusterSize: number = 512;\n\t// The number of local IDs generated since the last telemetry was sent.\n\tprivate telemetryLocalIdCount = 0;\n\t// The number of eager final IDs generated since the last telemetry was sent.\n\tprivate telemetryEagerFinalIdCount = 0;\n\t// The ongoing ghost session, if one exists.\n\tprivate ongoingGhostSession?: { cluster?: IdCluster; ghostSessionId: SessionId } | undefined;\n\n\t// #endregion\n\n\tpublic constructor(\n\t\tlocalSessionIdOrDeserialized: SessionId | Sessions,\n\t\tprivate readonly logger: TelemetryLoggerExt | undefined,\n\t\t/**\n\t\t * The version this compressor will write out.\n\t\t * This applies to both `serialize` and creation range functions.\n\t\t * This number also determines what features are available (e.g. sharding support starts at V3).\n\t\t */\n\t\tprivate readonly writeVersion: SerializationVersion,\n\t) {\n\t\tif (typeof localSessionIdOrDeserialized === \"string\") {\n\t\t\tthis.localSessionId = localSessionIdOrDeserialized;\n\t\t\tthis.localSession = this.sessions.getOrCreate(localSessionIdOrDeserialized);\n\t\t} else {\n\t\t\t// Deserialize case\n\t\t\tthis.sessions = localSessionIdOrDeserialized;\n\t\t\t// As policy, the first session is always the local session. Preserve this invariant\n\t\t\t// during deserialization.\n\t\t\tconst firstSession = localSessionIdOrDeserialized.sessions().next();\n\t\t\tassert(!firstSession.done, 0x754 /* First session must be present. */);\n\t\t\tthis.localSession = firstSession.value;\n\t\t\tthis.localSessionId = stableIdFromNumericUuid(\n\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t) as SessionId;\n\t\t}\n\t}\n\n\tpublic generateCompressedId(): SessionSpaceCompressedId {\n\t\t// This ghost session code inside this block should not be changed without a version bump (it is performed at a consensus point)\n\t\tif (this.ongoingGhostSession) {\n\t\t\tif (this.ongoingGhostSession.cluster === undefined) {\n\t\t\t\tthis.ongoingGhostSession.cluster = this.addEmptyCluster(\n\t\t\t\t\tthis.sessions.getOrCreate(this.ongoingGhostSession.ghostSessionId),\n\t\t\t\t\t1,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.ongoingGhostSession.cluster.capacity++;\n\t\t\t}\n\t\t\tthis.ongoingGhostSession.cluster.count++;\n\t\t\treturn lastFinalizedFinal(\n\t\t\t\tthis.ongoingGhostSession.cluster,\n\t\t\t) as unknown as SessionSpaceCompressedId;\n\t\t}\n\n\t\t// In sharding mode, always generate local IDs with stride-based allocation.\n\t\t// Eager finals are disabled because shards backfill IDs not in their stride cycle.\n\t\t// If another shard generated them as eager finals, ingesting IDs from another shard\n\t\t// would fail depending on timing.\n\t\tif (this.shardingState !== undefined) {\n\t\t\tthis.telemetryLocalIdCount++;\n\t\t\tconst { currentStride } = this.shardingState;\n\t\t\tthis.normalizer.addLocalRange(this.localGenCount + 1, currentStride);\n\t\t\tthis.localGenCount += currentStride;\n\t\t\treturn localIdFromGenCount(this.localGenCount);\n\t\t}\n\n\t\t// Normal ID generation\n\t\tthis.localGenCount++;\n\t\tconst lastCluster = this.localSession.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\tthis.telemetryLocalIdCount++;\n\t\t\treturn this.generateNextLocalId();\n\t\t}\n\n\t\t// If there exists a cluster of final IDs already claimed by the local session that still has room in it,\n\t\t// it is known prior to range sequencing what a local ID's corresponding final ID will be.\n\t\t// In this case, it is safe to return the final ID immediately. This is guaranteed to be safe because\n\t\t// any op that the local session sends that contains one of those final IDs are guaranteed to arrive to\n\t\t// collaborators *after* the one containing the creation range.\n\t\tconst clusterOffset = this.localGenCount - genCountFromLocalId(lastCluster.baseLocalId);\n\t\tif (lastCluster.capacity > clusterOffset) {\n\t\t\tthis.telemetryEagerFinalIdCount++;\n\t\t\t// Space in the cluster: eager final\n\t\t\treturn ((lastCluster.baseFinalId as number) + clusterOffset) as SessionSpaceCompressedId;\n\t\t}\n\t\t// No space in the cluster, return next local\n\t\tthis.telemetryLocalIdCount++;\n\t\treturn this.generateNextLocalId();\n\t}\n\n\tpublic generateDocumentUniqueId():\n\t\t| (SessionSpaceCompressedId & OpSpaceCompressedId)\n\t\t| StableId {\n\t\tconst id = this.generateCompressedId();\n\t\treturn isFinalId(id) ? id : this.decompress(id);\n\t}\n\n\t/**\n\t * Starts a ghost session. Only exposed for test purposes (this class is not exported from the package).\n\t * @param ghostSessionId - The session ID to start the ghost session with.\n\t */\n\tpublic startGhostSession(ghostSessionId: SessionId): void {\n\t\tassert(!this.ongoingGhostSession, 0x8fe /* Ghost session already in progress. */);\n\t\tthis.ongoingGhostSession = { ghostSessionId };\n\t}\n\n\t/**\n\t * {@inheritdoc IIdCompressorCore.beginGhostSession}\n\t */\n\tpublic beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): void {\n\t\tif (this.shardingState) {\n\t\t\tthrow new Error(\"Cannot start a ghost session while sharded.\");\n\t\t}\n\t\tthis.startGhostSession(ghostSessionId);\n\t\ttry {\n\t\t\tghostSessionCallback();\n\t\t} finally {\n\t\t\tthis.ongoingGhostSession = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc IIdCompressorCore.shard}\n\t */\n\tpublic shard(newShardCount: number): SerializedIdCompressorWithOngoingSession[] {\n\t\tif (!Number.isSafeInteger(newShardCount) || newShardCount <= 0) {\n\t\t\tthrow new Error(\"Shard count must be a positive safe integer\");\n\t\t}\n\t\tif (this.ongoingGhostSession) {\n\t\t\tthrow new Error(\"Cannot shard during ghost session\");\n\t\t}\n\t\tif (this.writeVersion < SerializationVersion.V3) {\n\t\t\tthrow new Error(\n\t\t\t\t`Sharding requires document version ${SerializationVersion.V3} or higher, but this document is version ${this.writeVersion}`,\n\t\t\t);\n\t\t}\n\n\t\tconst currentStride = this.shardingState?.currentStride ?? 1;\n\t\tconst newStride = currentStride * (newShardCount + 1);\n\n\t\t// ID usage is exponential in stride count. Limit to practical size to avoid overflow.\n\t\tif (newStride > MAX_STRIDE_LENGTH) {\n\t\t\tthrow new Error(\"Sharding limit reached.\");\n\t\t}\n\t\tassert(Number.isSafeInteger(newStride), 0xd52 /* Shard stride must be a safe integer */);\n\n\t\tif (this.shardingState === undefined) {\n\t\t\t// First time sharding - initialize state\n\t\t\tthis.shardingState = {\n\t\t\t\tcurrentStride: newStride,\n\t\t\t\toriginalStride: 1,\n\t\t\t\tactiveChildIds: new Set(),\n\t\t\t};\n\t\t} else {\n\t\t\tthis.shardingState.currentStride = newStride;\n\t\t}\n\n\t\t// Cache to avoid repeating per child\n\t\tconst serialized = this.serialize(true);\n\t\tconst { localGenCount: parentGenCount } = this;\n\n\t\tconst shards: SerializedIdCompressorWithOngoingSession[] = [];\n\n\t\t// Children are positioned at consecutive positions within the parents current stride cycle\n\t\t// e.g. if parent owns the \"evens\" space (-2, -4, -6, ...) and is sharded into 3 (two children)\n\t\t// while at -8, then the child shards will start at -10 and -12 with a stride of 6\n\t\tfor (let i = 1; i <= newShardCount; i++) {\n\t\t\tconst childShardId = createSessionId();\n\t\t\tthis.shardingState.activeChildIds.add(childShardId);\n\n\t\t\tconst childLocalGenCount = parentGenCount + i * currentStride;\n\n\t\t\t// This code results in a double roundtrip, but is probably plenty fast enough for scenarios that need sharding,\n\t\t\t// as they necessarily have process boundaries to deal with.\n\t\t\t// If this ever became an issue we can implement a fast clone of compressors\n\t\t\tconst child = deserializeIdCompressor(serialized, this.writeVersion) as IdCompressor;\n\t\t\tconst genCountJump = childLocalGenCount - parentGenCount;\n\t\t\tassert(\n\t\t\t\tchild.localGenCount === parentGenCount && genCountJump > 0,\n\t\t\t\t0xd53 /* Child offsets incorrectly calculated. */,\n\t\t\t);\n\n\t\t\tchild.normalizer.addLocalRange(child.localGenCount + 1, genCountJump);\n\t\t\tchild.localGenCount = childLocalGenCount;\n\t\t\tchild.shardingState = {\n\t\t\t\tcurrentStride: newStride,\n\t\t\t\toriginalStride: newStride,\n\t\t\t\tactiveChildIds: new Set(),\n\t\t\t\tshardId: childShardId,\n\t\t\t};\n\n\t\t\tshards.push(child.serialize(true));\n\t\t}\n\n\t\treturn shards;\n\t}\n\t/**\n\t * {@inheritdoc IIdCompressorCore.synchronizeWithShard}\n\t */\n\tpublic synchronizeWithShard(syncToken: ShardSynchronizationToken): void {\n\t\tconst isNowLeaf = this.synchronizeChild(syncToken);\n\t\t// A disposal token additionally reclaims the child's ID space. If reclaiming the last child\n\t\t// returns this compressor to a leaf and it is the root (originalStride === 1), exit sharding mode.\n\t\tif (syncToken.disposed) {\n\t\t\tassert(this.shardingState !== undefined, 0xd54 /* Must be sharded */);\n\t\t\tif (isNowLeaf && this.shardingState.originalStride === 1) {\n\t\t\t\tthis.shardingState = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate synchronizeChild(syncToken: ShardToken): boolean {\n\t\tconst childDisposed = syncToken.disposed;\n\t\tif (this.writeVersion < SerializationVersion.V3) {\n\t\t\tthrow new Error(\n\t\t\t\t`Sharding requires document version ${SerializationVersion.V3} or higher, but this document is version ${this.writeVersion}`,\n\t\t\t);\n\t\t}\n\t\tif (this.shardingState === undefined) {\n\t\t\tthrow new Error(\"Must be in sharding mode.\");\n\t\t}\n\n\t\tconst childShardId = syncToken.shardId;\n\t\tconst { activeChildIds, originalStride } = this.shardingState;\n\n\t\t// Verify this child belongs to us\n\t\tif (!activeChildIds.has(childShardId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot synchronize with child with ID ${childShardId}: not in active children set`,\n\t\t\t);\n\t\t}\n\n\t\t// Only disposal removes the child from the active set. A plain synchronization leaves the\n\t\t// child active so it can continue generating IDs and be synchronized with again later.\n\t\tif (childDisposed) {\n\t\t\tactiveChildIds.delete(childShardId);\n\t\t}\n\n\t\tconst isLeaf = activeChildIds.size === 0;\n\t\tif (isLeaf && childDisposed) {\n\t\t\tthis.shardingState.currentStride = originalStride;\n\t\t}\n\n\t\t// Read currentStride after the possible stride reset above, so that a leaf-making disposal\n\t\t// realigns the parent on its original (reclaimed) stride rather than the wider sharded stride.\n\t\tconst { currentStride } = this.shardingState;\n\t\tconst childGenCount = syncToken.localGenCount;\n\n\t\t// Realign parent to next position in its sequence if child is ahead\n\t\tif (childGenCount > this.localGenCount) {\n\t\t\t// Find next aligned position in parent's sequence after child's genCount\n\t\t\tconst distance = childGenCount - this.localGenCount + 1;\n\t\t\tconst steps = Math.ceil(distance / currentStride);\n\t\t\tconst count = steps * currentStride;\n\t\t\tthis.normalizer.addLocalRange(this.localGenCount + 1, count);\n\t\t\tthis.localGenCount += count;\n\t\t}\n\n\t\treturn isLeaf;\n\t}\n\n\t/**\n\t * {@inheritdoc IIdCompressorCore.dispose}\n\t */\n\tpublic disposeShard(): ShardSynchronizationToken | undefined {\n\t\tif (this.shardingState === undefined) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\tif (this.shardingState.activeChildIds.size > 0) {\n\t\t\t\tthrow new Error(\"Cannot dispose a shard with active children.\");\n\t\t\t}\n\t\t}\n\n\t\t// A disposal token is a sync token that additionally signals reclamation of this shard's ID space.\n\t\tconst token = this.makeShardToken(true);\n\n\t\t// Make this compressor unusable by replacing all methods with throwing stubs\n\t\t// This is a one-time mutation that avoids runtime checks in every method\n\t\tmakeCompressorUnusable(this);\n\n\t\treturn token;\n\t}\n\n\t/**\n\t * {@inheritdoc IIdCompressorCore.getShardSyncToken}\n\t */\n\tpublic getShardSyncToken(): ShardSynchronizationToken | undefined {\n\t\tif (this.shardingState === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.makeShardToken(false);\n\t}\n\n\t/**\n\t * Builds a token describing this shard's current progress.\n\t * @param disposed - Whether the token also signals disposal (reclamation of this shard's ID space).\n\t */\n\tprivate makeShardToken(disposed: boolean): ShardSynchronizationToken {\n\t\tassert(this.shardingState !== undefined, 0xd55 /* Compressor is not sharded. */);\n\n\t\t// Root cannot produce a token (shardId is undefined for root)\n\t\tif (this.shardingState.shardId === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Cannot get a token for a root compressor - only shards can be disposed\",\n\t\t\t);\n\t\t}\n\n\t\tconst token: ShardToken = {\n\t\t\tlocalGenCount: this.localGenCount,\n\t\t\tshardId: this.shardingState.shardId,\n\t\t\tdisposed,\n\t\t};\n\n\t\treturn token as unknown as ShardSynchronizationToken;\n\t}\n\n\tprivate generateNextLocalId(): LocalCompressedId {\n\t\t// Must tell the normalizer that we generated a local ID\n\t\tthis.normalizer.addLocalRange(this.localGenCount, 1);\n\t\treturn localIdFromGenCount(this.localGenCount);\n\t}\n\n\tpublic takeNextCreationRange(): IdCreationRange {\n\t\t// Child (non-root) shards must not submit their own creation ranges. All shards in a shard tree share a\n\t\t// single session, and only the root shard is responsible for finalizing that session's IDs with the server.\n\t\t// A child's generated IDs are reconciled with the root via shard synchronization tokens (see\n\t\t// synchronizeWithShard / disposeShard), not by independently sending ranges, which would overlap and\n\t\t// conflict with the root's ranges for the shared session.\n\t\tif (this.shardingState?.shardId !== undefined) {\n\t\t\tthrow new Error(\"Cannot take a creation range from a non-root shard.\");\n\t\t}\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a6 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst count = this.localGenCount - (this.nextRangeBaseGenCount - 1);\n\t\tif (count === 0) {\n\t\t\treturn {\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t};\n\t\t}\n\t\tconst range: IdCreationRange = {\n\t\t\tsessionId: this.localSessionId,\n\t\t\tids: {\n\t\t\t\tfirstGenCount: this.nextRangeBaseGenCount,\n\t\t\t\tcount,\n\t\t\t\trequestedClusterSize: this.nextRequestedClusterSize,\n\t\t\t\tlocalIdRanges: this.normalizer.getRangesBetween(\n\t\t\t\t\tthis.nextRangeBaseGenCount,\n\t\t\t\t\tthis.localGenCount,\n\t\t\t\t),\n\t\t\t},\n\t\t};\n\t\treturn this.updateToRange(range);\n\t}\n\n\tpublic takeUnfinalizedCreationRange(): IdCreationRange {\n\t\tthis.resetUnfinalizedCreationRange();\n\t\treturn this.takeNextCreationRange();\n\t}\n\n\tpublic resetUnfinalizedCreationRange(): void {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0xcec /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\n\t\tconst lastLocalCluster = this.localSession.getLastCluster();\n\t\tthis.nextRangeBaseGenCount =\n\t\t\tlastLocalCluster === undefined\n\t\t\t\t? 1\n\t\t\t\t: genCountFromLocalId(\n\t\t\t\t\t\t(lastLocalCluster.baseLocalId - lastLocalCluster.count) as LocalCompressedId,\n\t\t\t\t\t);\n\t}\n\n\tprivate updateToRange(range: IdCreationRange): IdCreationRange {\n\t\tthis.nextRangeBaseGenCount = this.localGenCount + 1;\n\t\treturn IdCompressor.assertValidRange(range);\n\t}\n\n\tprivate static assertValidRange(range: IdCreationRange): IdCreationRange {\n\t\tif (range.ids === undefined) {\n\t\t\treturn range;\n\t\t}\n\t\tconst { count, requestedClusterSize } = range.ids;\n\t\tassert(count > 0, 0x755 /* Malformed ID Range. */);\n\t\tassert(requestedClusterSize > 0, 0x876 /* Clusters must have a positive capacity. */);\n\t\tassert(\n\t\t\trequestedClusterSize <= IdCompressor.maxClusterSize,\n\t\t\t0x877 /* Clusters must not exceed max cluster size. */,\n\t\t);\n\t\treturn range;\n\t}\n\n\tpublic finalizeCreationRange(range: IdCreationRange): void {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a7 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\t// Check if the range has IDs\n\t\tif (range.ids === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tIdCompressor.assertValidRange(range);\n\t\tconst { sessionId, ids } = range;\n\t\tconst { count, firstGenCount, requestedClusterSize } = ids;\n\t\tconst session = this.sessions.getOrCreate(sessionId);\n\t\tconst isLocal = session === this.localSession;\n\t\tconst rangeBaseLocal = localIdFromGenCount(firstGenCount);\n\t\tlet lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// This is the first cluster in the session space\n\t\t\tif (rangeBaseLocal !== -1) {\n\t\t\t\tthrow rangeFinalizationError(-1, rangeBaseLocal);\n\t\t\t}\n\t\t\tlastCluster = this.addEmptyCluster(session, requestedClusterSize + count);\n\t\t\tif (isLocal) {\n\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\teventName: \"RuntimeIdCompressor:FirstCluster\",\n\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst remainingCapacity = lastCluster.capacity - lastCluster.count;\n\t\tif (lastCluster.baseLocalId - lastCluster.count !== rangeBaseLocal) {\n\t\t\tthrow rangeFinalizationError(\n\t\t\t\tlastCluster.baseLocalId - lastCluster.count,\n\t\t\t\trangeBaseLocal,\n\t\t\t);\n\t\t}\n\n\t\tif (remainingCapacity >= count) {\n\t\t\t// The current range fits in the existing cluster\n\t\t\tlastCluster.count += count;\n\t\t} else {\n\t\t\tconst overflow = count - remainingCapacity;\n\t\t\tconst newClaimedFinalCount = overflow + requestedClusterSize;\n\t\t\tif (lastCluster === this.finalSpace.getLastCluster()) {\n\t\t\t\t// The last cluster in the sessions chain is the last cluster globally, so it can be expanded.\n\t\t\t\tlastCluster.capacity += newClaimedFinalCount;\n\t\t\t\tlastCluster.count += count;\n\t\t\t\tassert(\n\t\t\t\t\t!this.sessions.clusterCollides(lastCluster),\n\t\t\t\t\t0x756 /* Cluster collision detected. */,\n\t\t\t\t);\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:ClusterExpansion\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t\tpreviousCapacity: lastCluster.capacity - newClaimedFinalCount,\n\t\t\t\t\t\tnewCapacity: lastCluster.capacity,\n\t\t\t\t\t\toverflow,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// The last cluster in the sessions chain is *not* the last cluster globally. Fill and overflow to new.\n\t\t\t\tlastCluster.count = lastCluster.capacity;\n\t\t\t\tconst newCluster = this.addEmptyCluster(session, newClaimedFinalCount);\n\t\t\t\tnewCluster.count += overflow;\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:NewCluster\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (isLocal) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"RuntimeIdCompressor:IdCompressorStatus\",\n\t\t\t\teagerFinalIdCount: this.telemetryEagerFinalIdCount,\n\t\t\t\tlocalIdCount: this.telemetryLocalIdCount,\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t});\n\t\t\tthis.telemetryEagerFinalIdCount = 0;\n\t\t\tthis.telemetryLocalIdCount = 0;\n\t\t}\n\n\t\tassert(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);\n\t}\n\n\tprivate addEmptyCluster(session: Session, capacity: number): IdCluster {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession?.cluster,\n\t\t\t0x8a8 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst newCluster = session.addNewCluster(\n\t\t\tthis.finalSpace.getAllocatedIdLimit(),\n\t\t\tcapacity,\n\t\t\t0,\n\t\t);\n\t\tassert(\n\t\t\t!this.sessions.clusterCollides(newCluster),\n\t\t\t0x758 /* Cluster collision detected. */,\n\t\t);\n\t\tthis.finalSpace.addCluster(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId {\n\t\tif (isFinalId(id)) {\n\t\t\treturn id;\n\t\t} else {\n\t\t\tconst local = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(local)) {\n\t\t\t\tthrow new Error(\"Invalid ID to normalize.\");\n\t\t\t}\n\t\t\tconst finalForm = this.localSession.tryConvertToFinal(local, true);\n\t\t\treturn finalForm === undefined\n\t\t\t\t? (local as unknown as OpSpaceCompressedId)\n\t\t\t\t: (finalForm as OpSpaceCompressedId);\n\t\t}\n\t}\n\n\tpublic tryNormalizeToSessionSpaceWithoutSession(\n\t\tid: OpSpaceCompressedId,\n\t): SessionSpaceCompressedId | undefined {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = this.localSession.getClusterByAllocatedFinal(id);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\t// Does not exist in local cluster chain\n\t\t\t\tif (id >= this.finalSpace.getFinalizedIdLimit()) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t} else {\n\t\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tif (genCountFromLocalId(alignedLocal) > this.localGenCount) {\n\t\t\t\t\t\t// The ID is not valid in this compressor. It is either from a future version of this compressor, or another compressor.\n\t\t\t\t\t\t// Since IDs from other compressors often are valid in this one, but uncompress incorrectly,\n\t\t\t\t\t\t// we cannot rely on this function (tryNormalizeToSessionSpaceWithoutSession) to validate that the IDs are from the same compressor.\n\t\t\t\t\t\t// Since such validation can not be robust, this \"try\" function is explicitly documented not to be allowed to be used for this case.\n\t\t\t\t\t\t// Therefore, as documented in the API docs for this function, calls can not rely on a specific output in this case,\n\t\t\t\t\t\t// and therefore the document behavior of throwing makes the most sense (helps catch bugs).\n\t\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t\t}\n\t\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic normalizeToSessionSpace(\n\t\tid: OpSpaceCompressedId,\n\t\toriginSessionId: SessionId,\n\t): SessionSpaceCompressedId {\n\t\tconst normalizedWithoutSession = this.tryNormalizeToSessionSpaceWithoutSession(id);\n\t\tif (normalizedWithoutSession === undefined) {\n\t\t\tconst localToNormalize = id as unknown as LocalCompressedId;\n\t\t\tif (originSessionId === this.localSessionId) {\n\t\t\t\tif (this.normalizer.contains(localToNormalize)) {\n\t\t\t\t\treturn localToNormalize;\n\t\t\t\t} else {\n\t\t\t\t\t// We never generated this local ID, so fail\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// LocalId from a remote session\n\t\t\t\tconst remoteSession = this.sessions.get(originSessionId);\n\t\t\t\tif (remoteSession === undefined) {\n\t\t\t\t\tthrow new Error(\"No IDs have ever been finalized by the supplied session.\");\n\t\t\t\t}\n\t\t\t\tconst correspondingFinal = remoteSession.tryConvertToFinal(localToNormalize, false);\n\t\t\t\tif (correspondingFinal === undefined) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn correspondingFinal as unknown as SessionSpaceCompressedId;\n\t\t\t}\n\t\t} else {\n\t\t\treturn normalizedWithoutSession;\n\t\t}\n\t}\n\n\tpublic decompress(id: SessionSpaceCompressedId): StableId {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = Session.getContainingCluster(id, this.finalSpace.clusters);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\tconst alignedGenCount = genCountFromLocalId(alignedLocal);\n\t\t\tconst lastFinalizedGenCount = genCountFromLocalId(lastFinalizedLocal(containingCluster));\n\t\t\tif (alignedGenCount > lastFinalizedGenCount) {\n\t\t\t\t// should be an eager final id generated by the local session\n\t\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t\tassert(!this.normalizer.contains(alignedLocal), 0x759 /* Normalizer out of sync. */);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(containingCluster.session.sessionUuid, alignedGenCount - 1),\n\t\t\t);\n\t\t} else {\n\t\t\tconst localToDecompress = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(localToDecompress)) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(\n\t\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t\t\tgenCountFromLocalId(localToDecompress) - 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic recompress(uncompressed: StableId): SessionSpaceCompressedId {\n\t\tconst recompressed = this.tryRecompress(uncompressed);\n\t\tif (recompressed === undefined) {\n\t\t\tthrow new Error(\"Could not recompress.\");\n\t\t}\n\t\treturn recompressed;\n\t}\n\n\tpublic tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined {\n\t\tconst match = this.sessions.getContainingCluster(uncompressed);\n\t\tif (match === undefined) {\n\t\t\tconst numericUncompressed = numericUuidFromStableId(uncompressed);\n\t\t\tconst offset = subtractNumericUuids(numericUncompressed, this.localSession.sessionUuid);\n\t\t\tif (offset < Number.MAX_SAFE_INTEGER) {\n\t\t\t\tconst genCountEquivalent = Number(offset) + 1;\n\t\t\t\tconst localEquivalent = localIdFromGenCount(genCountEquivalent);\n\t\t\t\tif (this.normalizer.contains(localEquivalent)) {\n\t\t\t\t\treturn localEquivalent;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\tconst [containingCluster, alignedLocal] = match;\n\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t// Local session\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tgenCountFromLocalId(alignedLocal) <= this.localGenCount,\n\t\t\t\t\t\t0x75a /* Clusters out of sync. */,\n\t\t\t\t\t);\n\t\t\t\t\t// Id is an eager final\n\t\t\t\t\treturn getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t| undefined;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Not the local session\n\t\t\t\treturn genCountFromLocalId(alignedLocal) >= lastFinalizedLocal(containingCluster)\n\t\t\t\t\t? (getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t\t| undefined)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic serialize(withSession: true): SerializedIdCompressorWithOngoingSession;\n\tpublic serialize(withSession: false): SerializedIdCompressorWithNoSession;\n\tpublic serialize(hasLocalState: boolean): SerializedIdCompressor {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a9 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst { normalizer, finalSpace, sessions, localGenCount, logger, nextRangeBaseGenCount } =\n\t\t\tthis;\n\t\tconst sessionIndexMap = new Map<Session, number>();\n\t\tlet sessionIndex = 0;\n\t\tfor (const session of sessions.sessions()) {\n\t\t\t// Filter empty sessions to prevent them accumulating in the serialized state\n\t\t\tif (!session.isEmpty() || hasLocalState) {\n\t\t\t\tsessionIndexMap.set(session, sessionIndex);\n\t\t\t\tsessionIndex++;\n\t\t\t}\n\t\t}\n\t\tconst sizeOfUuid = 2;\n\t\tconst shardingStateSize =\n\t\t\thasLocalState && this.writeVersion >= SerializationVersion.V3\n\t\t\t\t? this.shardingState === undefined\n\t\t\t\t\t? 1 // Boolean: no sharding state\n\t\t\t\t\t: 1 + // Boolean: has sharding state\n\t\t\t\t\t\t2 + // Numbers: currentStride, originalStride (Float64)\n\t\t\t\t\t\t1 + // Number: activeChildIds count (Float64)\n\t\t\t\t\t\tthis.shardingState.activeChildIds.size * sizeOfUuid + // UUIDs: each is 128-bit\n\t\t\t\t\t\t1 + // Boolean: hasShardId\n\t\t\t\t\t\t(this.shardingState.shardId === undefined ? 0 : sizeOfUuid) // UUID: 128-bit if present\n\t\t\t\t: 0;\n\t\tconst localStateSize = hasLocalState\n\t\t\t? 1 + // generated ID count\n\t\t\t\t1 + // next range base genCount\n\t\t\t\t1 + // count of normalizer pairs\n\t\t\t\tnormalizer.idRanges.size * 2 + // pairs\n\t\t\t\tshardingStateSize // sharding state if present\n\t\t\t: 0;\n\t\t// Layout size, in 8 byte increments\n\t\tconst totalSize =\n\t\t\t1 + // version\n\t\t\t1 + // hasLocalState\n\t\t\t1 + // session count\n\t\t\t1 + // cluster count\n\t\t\tsessionIndexMap.size * sizeOfUuid + // session IDs\n\t\t\tfinalSpace.clusters.length * 3 + // clusters: (sessionIndex, capacity, count)[]\n\t\t\tlocalStateSize; // local state, if present\n\n\t\tconst serializedFloat = new Float64Array(totalSize);\n\t\tconst serializedUint = new BigUint64Array(serializedFloat.buffer);\n\t\tlet index = 0;\n\t\tindex = writeNumber(serializedFloat, index, this.writeVersion);\n\t\tindex = writeBoolean(serializedFloat, index, hasLocalState);\n\t\tindex = writeNumber(serializedFloat, index, sessionIndexMap.size);\n\t\tindex = writeNumber(serializedFloat, index, finalSpace.clusters.length);\n\n\t\tfor (const [session] of sessionIndexMap.entries()) {\n\t\t\tindex = writeNumericUuid(serializedUint, index, session.sessionUuid);\n\t\t}\n\n\t\tfor (const cluster of finalSpace.clusters) {\n\t\t\tindex = writeNumber(\n\t\t\t\tserializedFloat,\n\t\t\t\tindex,\n\t\t\t\tsessionIndexMap.get(cluster.session) as number,\n\t\t\t);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.capacity);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.count);\n\t\t}\n\n\t\tif (hasLocalState) {\n\t\t\tindex = writeNumber(serializedFloat, index, localGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, nextRangeBaseGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, normalizer.idRanges.size);\n\t\t\tfor (const [leadingGenCount, count] of normalizer.idRanges.entries()) {\n\t\t\t\tindex = writeNumber(serializedFloat, index, leadingGenCount);\n\t\t\t\tindex = writeNumber(serializedFloat, index, count);\n\t\t\t}\n\n\t\t\t// Write sharding state (version 3+)\n\t\t\tif (this.writeVersion >= SerializationVersion.V3) {\n\t\t\t\tindex = writeBoolean(serializedFloat, index, this.shardingState !== undefined);\n\t\t\t\tif (this.shardingState !== undefined) {\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.currentStride);\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.originalStride);\n\n\t\t\t\t\t// Write activeChildIds Set as count + array of NumericUuids\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.activeChildIds.size);\n\t\t\t\t\tfor (const childId of this.shardingState.activeChildIds) {\n\t\t\t\t\t\tindex = writeNumericUuid(serializedUint, index, numericUuidFromStableId(childId));\n\t\t\t\t\t}\n\n\t\t\t\t\t// Write shardId (optional)\n\t\t\t\t\tindex = writeBoolean(\n\t\t\t\t\t\tserializedFloat,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tthis.shardingState.shardId !== undefined,\n\t\t\t\t\t);\n\t\t\t\t\tif (this.shardingState.shardId !== undefined) {\n\t\t\t\t\t\tindex = writeNumericUuid(\n\t\t\t\t\t\t\tserializedUint,\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tnumericUuidFromStableId(this.shardingState.shardId),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tassert(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);\n\t\tlogger?.sendTelemetryEvent({\n\t\t\teventName: \"RuntimeIdCompressor:SerializedIdCompressorSize\",\n\t\t\tsize: serializedFloat.byteLength,\n\t\t\tclusterCount: finalSpace.clusters.length,\n\t\t\tsessionCount: sessionIndexMap.size,\n\t\t});\n\n\t\treturn bufferToString(serializedFloat.buffer, \"base64\") as SerializedIdCompressor;\n\t}\n\n\tpublic static deserialize(\n\t\tparams:\n\t\t\t| {\n\t\t\t\t\tserialized: SerializedIdCompressorWithOngoingSession;\n\t\t\t\t\trequestedWriteVersion: SerializationVersion;\n\t\t\t\t\tlogger?: TelemetryLoggerExt | undefined;\n\t\t\t\t\tnewSessionId?: never;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\tserialized: SerializedIdCompressorWithNoSession;\n\t\t\t\t\tnewSessionId: SessionId;\n\t\t\t\t\trequestedWriteVersion: SerializationVersion;\n\t\t\t\t\tlogger?: TelemetryLoggerExt | undefined;\n\t\t\t },\n\t): IdCompressor {\n\t\tconst { serialized, newSessionId: sessionId, logger, requestedWriteVersion } = params;\n\t\tconst buffer = stringToBuffer(serialized, \"base64\");\n\t\tconst index: Index = {\n\t\t\tindex: 0,\n\t\t\tbufferFloat: new Float64Array(buffer),\n\t\t\tbufferUint: new BigUint64Array(buffer),\n\t\t};\n\t\tconst serializedVersion = readNumber(index) as SerializationVersion;\n\t\t// If requested version is < the serialized version, we must write the version serialized\n\t\t// to avoid losing data.\n\t\tconst writeVersion = Math.max(\n\t\t\trequestedWriteVersion,\n\t\t\tserializedVersion,\n\t\t) as SerializationVersion;\n\n\t\tswitch (serializedVersion) {\n\t\t\tcase 2:\n\t\t\tcase 3: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tif (serializedVersion === 1) {\n\t\t\t\t\tthrow new Error(\"IdCompressor version 1.0 is no longer supported.\");\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"Unknown IdCompressor serialized version.\");\n\t\t\t}\n\t\t}\n\n\t\tconst hasLocalState = readBoolean(index);\n\t\tconst sessionCount = readNumber(index);\n\t\tconst clusterCount = readNumber(index);\n\n\t\t// Sessions\n\t\tlet sessionOffset = 0;\n\t\tconst sessions: [NumericUuid, Session][] = [];\n\t\tif (hasLocalState) {\n\t\t\tassert(\n\t\t\t\tsessionId === undefined,\n\t\t\t\t0x75e /* Local state should not exist in serialized form. */,\n\t\t\t);\n\t\t} else {\n\t\t\t// If !hasLocalState, there won't be a serialized local session ID so insert one at the beginning\n\t\t\tassert(sessionId !== undefined, 0x75d /* Local session ID is undefined. */);\n\t\t\tconst localSessionNumeric = numericUuidFromStableId(sessionId);\n\t\t\tsessions.push([localSessionNumeric, new Session(localSessionNumeric)]);\n\t\t\tsessionOffset = 1;\n\t\t}\n\n\t\tfor (let i = 0; i < sessionCount; i++) {\n\t\t\tconst numeric = readNumericUuid(index);\n\t\t\tsessions.push([numeric, new Session(numeric)]);\n\t\t}\n\n\t\tconst compressor = new IdCompressor(new Sessions(sessions), logger, writeVersion);\n\n\t\t// Clusters\n\t\tlet baseFinalId = 0;\n\t\tfor (let i = 0; i < clusterCount; i++) {\n\t\t\tconst sessionIndex = readNumber(index);\n\t\t\tconst sessionArray = sessions[sessionIndex + sessionOffset];\n\t\t\tassert(\n\t\t\t\tsessionArray !== undefined,\n\t\t\t\t0x9d8 /* sessionArray is undefined in IdCompressor.deserialize2_0 */,\n\t\t\t);\n\t\t\tconst session = sessionArray[1];\n\t\t\tconst capacity = readNumber(index);\n\t\t\tconst count = readNumber(index);\n\t\t\tconst cluster = session.addNewCluster(baseFinalId as FinalCompressedId, capacity, count);\n\t\t\tcompressor.finalSpace.addCluster(cluster);\n\t\t\tbaseFinalId += capacity;\n\t\t}\n\n\t\t// Local state\n\t\tif (hasLocalState) {\n\t\t\tcompressor.localGenCount = readNumber(index);\n\t\t\tcompressor.nextRangeBaseGenCount = readNumber(index);\n\t\t\tconst normalizerCount = readNumber(index);\n\t\t\tfor (let i = 0; i < normalizerCount; i++) {\n\t\t\t\tcompressor.normalizer.addLocalRange(readNumber(index), readNumber(index));\n\t\t\t}\n\n\t\t\t// Sharding state (version 3+)\n\t\t\tif (serializedVersion >= 3) {\n\t\t\t\tconst hasShardingState = readBoolean(index);\n\t\t\t\tif (hasShardingState) {\n\t\t\t\t\tconst currentStride = readNumber(index);\n\t\t\t\t\tconst originalStride = readNumber(index);\n\n\t\t\t\t\t// Read activeChildIds Set\n\t\t\t\t\tconst activeChildCount = readNumber(index);\n\t\t\t\t\tconst activeChildIds = new Set<SessionId>();\n\t\t\t\t\tfor (let i = 0; i < activeChildCount; i++) {\n\t\t\t\t\t\tconst childIdNumeric = readNumericUuid(index);\n\t\t\t\t\t\t// Safe cast: these were serialized as SessionIds\n\t\t\t\t\t\tactiveChildIds.add(stableIdFromNumericUuid(childIdNumeric) as SessionId);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Read shardId (optional)\n\t\t\t\t\tconst hasShardId = readBoolean(index);\n\t\t\t\t\tconst shardId: SessionId | undefined = hasShardId\n\t\t\t\t\t\t? (stableIdFromNumericUuid(readNumericUuid(index)) as SessionId)\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t// Build sharding state object, conditionally including shardId\n\t\t\t\t\tcompressor.shardingState = {\n\t\t\t\t\t\tcurrentStride,\n\t\t\t\t\t\toriginalStride,\n\t\t\t\t\t\tactiveChildIds,\n\t\t\t\t\t\t...(shardId !== undefined && { shardId }),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tindex.index === index.bufferFloat.length,\n\t\t\t0x75f /* Failed to read entire serialized compressor. */,\n\t\t);\n\t\treturn compressor;\n\t}\n\n\tpublic equals(other: IdCompressor, includeLocalState: boolean): boolean {\n\t\tif (\n\t\t\tincludeLocalState &&\n\t\t\t(this.localSessionId !== other.localSessionId ||\n\t\t\t\t!this.localSession.equals(other.localSession) ||\n\t\t\t\t!this.normalizer.equals(other.normalizer) ||\n\t\t\t\tthis.nextRangeBaseGenCount !== other.nextRangeBaseGenCount ||\n\t\t\t\tthis.localGenCount !== other.localGenCount)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\t// Shard ownership affects future local ID allocation, even when the generated IDs match.\n\t\t// It is not part of finalized state, so ignore it when comparing only that state.\n\t\tif (includeLocalState) {\n\t\t\tconst state = this.shardingState;\n\t\t\tconst otherState = other.shardingState;\n\t\t\tif (state === undefined || otherState === undefined) {\n\t\t\t\t// Two unsharded compressors match here; a sharded and an unsharded compressor do not.\n\t\t\t\tif (state !== otherState) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tstate.currentStride !== otherState.currentStride ||\n\t\t\t\t\tstate.originalStride !== otherState.originalStride ||\n\t\t\t\t\tstate.shardId !== otherState.shardId ||\n\t\t\t\t\tstate.activeChildIds.size !== otherState.activeChildIds.size\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t// Child ownership is an unordered set. Equal sizes and membership imply equal sets,\n\t\t\t\t// regardless of insertion order or whether the state was deserialized.\n\t\t\t\tfor (const childId of state.activeChildIds) {\n\t\t\t\t\tif (!otherState.activeChildIds.has(childId)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (\n\t\t\tthis.sessions.equals(other.sessions, includeLocalState) &&\n\t\t\tthis.finalSpace.equals(other.finalSpace)\n\t\t);\n\t}\n}\n\n/**\n * Create a new {@link IIdCompressor}.\n * @param writeVersion - The version the compressor will write when serializing. Use SerializationVersion.V2 for base format, or SerializationVersion.V3 for sharding support.\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function createIdCompressor(\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Create a new {@link IIdCompressor}.\n * @param sessionId - The seed ID for the compressor.\n * @param writeVersion - The version the compressor will write when serializing. Use SerializationVersion.V2 for base format, or SerializationVersion.V3 for sharding support.\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function createIdCompressor(\n\tsessionId: SessionId,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\nexport function createIdCompressor(\n\tsessionIdOrDocumentVersion: SessionId | SerializationVersion,\n\twriteVersionOrLogger?: SerializationVersion | ITelemetryBaseLogger,\n\tloggerOrUndefined?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore {\n\tlet localSessionId: SessionId;\n\tlet writeVersion: SerializationVersion;\n\tlet logger: ITelemetryBaseLogger | undefined;\n\n\tif (typeof sessionIdOrDocumentVersion === \"string\") {\n\t\t// Called with sessionId, writeVersion, logger?\n\t\tlocalSessionId = sessionIdOrDocumentVersion;\n\t\twriteVersion = writeVersionOrLogger as SerializationVersion;\n\t\tlogger = loggerOrUndefined;\n\t} else {\n\t\t// Called with writeVersion, logger?\n\t\tlocalSessionId = createSessionId();\n\t\twriteVersion = sessionIdOrDocumentVersion;\n\t\tlogger = writeVersionOrLogger as ITelemetryBaseLogger | undefined;\n\t}\n\n\tconst compressor = new IdCompressor(\n\t\tlocalSessionId,\n\t\tlogger === undefined ? undefined : createChildLogger({ logger }),\n\t\twriteVersion,\n\t);\n\treturn compressor;\n}\n\n/**\n * Deserializes the supplied state into an ID compressor.\n * @param serialized - The serialized compressor state with an ongoing session.\n * @param writeVersion - The version the compressor will write when serializing. This determines what features are available (e.g., V3 enables sharding support).\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressorWithOngoingSession,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Deserializes the supplied state into an ID compressor.\n * @param serialized - The serialized compressor state without a session.\n * @param newSessionId - The session ID to use for the deserialized compressor.\n * @param writeVersion - The version the compressor will write when serializing. This determines what features are available (e.g., V3 enables sharding support).\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressorWithNoSession,\n\tnewSessionId: SessionId,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore;\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressor | SerializedIdCompressorWithNoSession,\n\tsessionIdOrDocumentVersion: SessionId | SerializationVersion,\n\twriteVersionOrLogger?: SerializationVersion | ITelemetryLoggerExt,\n\tloggerOrUndefined?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore {\n\tif (typeof sessionIdOrDocumentVersion === \"string\") {\n\t\t// Called with (serialized, sessionId, writeVersion, logger?)\n\t\treturn IdCompressor.deserialize({\n\t\t\tserialized: serialized as SerializedIdCompressorWithNoSession,\n\t\t\tlogger: extractTelemetryLoggerExt<{ PossiblyUndefined: true }>(loggerOrUndefined),\n\t\t\tnewSessionId: sessionIdOrDocumentVersion,\n\t\t\trequestedWriteVersion: writeVersionOrLogger as SerializationVersion,\n\t\t});\n\t}\n\n\tassert(\n\t\tloggerOrUndefined === undefined,\n\t\t0xc2d /* logger would be in sessionIdOrLogger in this codepath */,\n\t);\n\t// Called with (serialized, writeVersion, logger?)\n\treturn IdCompressor.deserialize({\n\t\tserialized: serialized as SerializedIdCompressorWithOngoingSession,\n\t\tlogger: extractTelemetryLoggerExt<{ PossiblyUndefined: true }>(\n\t\t\twriteVersionOrLogger as ITelemetryLoggerExt | undefined,\n\t\t),\n\t\trequestedWriteVersion: sessionIdOrDocumentVersion,\n\t});\n}\n\n/**\n * Throws an error indicating the compressor has been disposed.\n */\nconst throwDisposed = (): never => {\n\tthrow new Error(\n\t\t\"This compressor has been disposed via disposeShard() and can no longer be used.\",\n\t);\n};\n\n/**\n * Makes an IdCompressor instance unusable by replacing all its methods with functions that throw.\n * This is called once when disposeShard() is invoked to make the compressor permanently unusable.\n * @param compressor - The compressor instance to make unusable\n */\nfunction makeCompressorUnusable(compressor: IdCompressor): void {\n\t// Get all method names from the prototype (where class methods live)\n\tconst proto = Object.getPrototypeOf(compressor) as object;\n\tfor (const key of Reflect.ownKeys(proto)) {\n\t\tif (key !== \"constructor\" && typeof Reflect.get(proto, key) === \"function\") {\n\t\t\t// Shadow the method only on this instance so other compressors remain usable.\n\t\t\t// Omitting `enumerable` keeps new overrides non-enumerable, like class methods.\n\t\t\t// Reflection supports string and symbol keys without adding an index signature.\n\t\t\tObject.defineProperty(compressor, key, {\n\t\t\t\tvalue: throwDisposed,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Serializes an ID compressor.\n * @param compressor - The compressor to serialize.\n * @param withSession - If true, the serialized state will include local session\n * state (for stashing). If false, only finalized state is included (for summaries).\n * @internal\n */\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: true,\n): SerializedIdCompressorWithOngoingSession;\n/**\n * Serializes an ID compressor.\n * @param compressor - The compressor to serialize.\n * @param withSession - If true, the serialized state will include local session\n * state (for stashing). If false, only finalized state is included (for summaries).\n * @internal\n */\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: false,\n): SerializedIdCompressorWithNoSession;\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: boolean,\n): SerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession {\n\tconst core = toIdCompressorWithCore(compressor);\n\treturn withSession ? core.serialize(true) : core.serialize(false);\n}\n\n/**\n * Casts an {@link IIdCompressor} to include {@link IIdCompressorCore}.\n *\n * @remarks\n * Compressors returned by `createIdCompressor` and `deserializeIdCompressor`\n * always implement both {@link IIdCompressor} and {@link IIdCompressorCore}, but their\n * public return type is narrowed to {@link IIdCompressor}. Internal consumers that\n * need access to core compressor operations (serialization, range management, etc.)\n * use this function to recover the {@link IIdCompressorCore} surface.\n *\n * @param compressor - A compressor created by `createIdCompressor` or\n * `deserializeIdCompressor`.\n * @returns The same compressor, typed to include {@link IIdCompressorCore}.\n * @internal\n */\nexport function toIdCompressorWithCore(\n\tcompressor: IIdCompressor,\n): IIdCompressor & IIdCompressorCore {\n\tassert(\n\t\t\"serialize\" in compressor,\n\t\t0xced /* Expected compressor to implement IIdCompressorCore */,\n\t);\n\treturn compressor as IIdCompressor & IIdCompressorCore;\n}\n"]}
1
+ {"version":3,"file":"idCompressor.js","sourceRoot":"","sources":["../src/idCompressor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuqCH,gDA2BC;AA4BD,0DA4BC;AAuDD,sDAMC;AAiBD,wDAQC;AA90CD,+DAA6F;AAE7F,kEAA6D;AAE7D,uEAIkD;AAIlD,mDAA6C;AAC7C,qDAK0B;AAC1B,uEAQmC;AACnC,2EAAqE;AACrE,+CAQuB;AAkBvB,+CAAwD;AACxD,iDAQwB;AAExB,SAAS,sBAAsB,CAAC,aAAqB,EAAE,WAAmB;IACzE,OAAO,IAAI,uBAAY,CAAC,+BAA+B,EAAE;QACxD,aAAa;QACb,WAAW;KACX,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,aAAqB;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI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AG,KAAK,aAAa,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,UAAU,EAAE,CAAC;YAC5E,8EAA8E;YAC9E,gFAAgF;YAChF,gFAAgF;YAChF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE;gBACtC,KAAK,EAAE,aAAa;gBACpB,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC;AAwBD,SAAgB,qBAAqB,CACpC,UAAyB,EACzB,WAAoB;IAEpB,MAAM,IAAI,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB,CACrC,UAAyB;IAEzB,IAAA,iBAAM,EACL,WAAW,IAAI,UAAU,EACzB,KAAK,CAAC,wDAAwD,CAC9D,CAAC;IACF,OAAO,UAA+C,CAAC;AACxD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString, createEmitter, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport type { ITelemetryBaseLogger, Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { TelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tLoggingError,\n\tcreateChildLogger,\n\textractTelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n// eslint-disable-next-line import-x/no-internal-modules -- Needed to avoid specialized /internal ITelemetryLoggerExt\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/legacy\";\n\nimport { FinalSpace } from \"./finalSpace.js\";\nimport {\n\ttype FinalCompressedId,\n\ttype LocalCompressedId,\n\ttype NumericUuid,\n\tisFinalId,\n} from \"./identifiers.js\";\nimport {\n\ttype Index,\n\treadBoolean,\n\treadNumber,\n\treadNumericUuid,\n\twriteBoolean,\n\twriteNumber,\n\twriteNumericUuid,\n} from \"./persistanceUtilities.js\";\nimport { SessionSpaceNormalizer } from \"./sessionSpaceNormalizer.js\";\nimport {\n\ttype IdCluster,\n\tSession,\n\tSessions,\n\tgetAlignedFinal,\n\tgetAlignedLocal,\n\tlastFinalizedFinal,\n\tlastFinalizedLocal,\n} from \"./sessions.js\";\nimport type {\n\tShardToken,\n\tIIdCompressor,\n\tIIdCompressorCore,\n\tIdCreationRange,\n\tOpSpaceCompressedId,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n\tSessionId,\n\tSessionSpaceCompressedId,\n\tStableId,\n\tShardSynchronizationToken,\n\tSerializedIdCompressorShard,\n\tParentShardSynchronizationToken,\n\tIdCompressorEvents,\n} from \"./types/index.js\";\nimport { SerializationVersion } from \"./types/index.js\";\nimport {\n\tcreateSessionId,\n\tgenCountFromLocalId,\n\tlocalIdFromGenCount,\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n} from \"./utilities.js\";\n\nfunction rangeFinalizationError(expectedStart: number, actualStart: number): LoggingError {\n\treturn new LoggingError(\"Ranges finalized out of order\", {\n\t\texpectedStart,\n\t\tactualStart,\n\t});\n}\n\nconst MAX_STRIDE_LENGTH = 1000000;\n\n/**\n * Validates the generation count in a shard synchronization token.\n *\n * @param localGenCount - The number of positions filled, including backfilled positions.\n * @throws {@link TypeError} if the count is not a nonnegative safe integer.\n */\nfunction validateShardGenerationCount(localGenCount: number): void {\n\tif (!Number.isSafeInteger(localGenCount) || localGenCount < 0) {\n\t\tthrow new TypeError(\"Invalid shard synchronization token generation count.\");\n\t}\n}\n\n/**\n * See {@link IIdCompressor} and {@link IIdCompressorCore}\n */\nexport class IdCompressor implements IIdCompressor, IIdCompressorCore {\n\tprivate readonly eventEmitter = createEmitter<IdCompressorEvents>();\n\n\tpublic readonly events: Listenable<IdCompressorEvents> = this.eventEmitter;\n\n\t/**\n\t * Max allowed initial cluster size.\n\t */\n\tpublic static readonly maxClusterSize = 2 ** 20;\n\n\t// #region Local state\n\n\tpublic readonly localSessionId: SessionId;\n\tprivate readonly localSession: Session;\n\tprivate readonly normalizer = new SessionSpaceNormalizer();\n\t// The number of IDs generated by the local session\n\tprivate localGenCount = 0;\n\n\t/**\n\t * The sharding state of this compressor, if it has been sharded or is a shard itself.\n\t * When defined, this compressor operates in \"sharding mode\" where:\n\t * - IDs are generated using stride-based allocation (no eager finals)\n\t * - The normalizer backfills all IDs in each stride cycle\n\t * - Normal operation resumes when all children are disposed\n\t */\n\tprivate shardingState?:\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Current stride - used when this compressor has active children.\n\t\t\t\t * Changes each time shard() is called.\n\t\t\t\t */\n\t\t\t\tcurrentStride: number;\n\n\t\t\t\t/**\n\t\t\t\t * Original stride - the stride this compressor was created with.\n\t\t\t\t * Used when this compressor has no children (is a leaf).\n\t\t\t\t * IMMUTABLE after creation.\n\t\t\t\t */\n\t\t\t\toriginalStride: number;\n\n\t\t\t\t/**\n\t\t\t\t * Set of unique child shard IDs (UUIDs) currently active.\n\t\t\t\t * Each child is assigned a UUID when created via shard().\n\t\t\t\t * Safe across serialization/deserialization cycles.\n\t\t\t\t */\n\t\t\t\tactiveChildIds: Set<SessionId>;\n\n\t\t\t\t/**\n\t\t\t\t * This compressor's unique shard ID within its parent (if it's a child).\n\t\t\t\t * Undefined for root compressors.\n\t\t\t\t * Assigned by parent when creating this shard.\n\t\t\t\t */\n\t\t\t\tshardId?: SessionId;\n\t\t }\n\t\t| undefined;\n\n\t// #endregion\n\n\t// #region Final state\n\n\t/**\n\t * The gen count to be annotated on the range returned by the next call to `takeNextCreationRange`.\n\t * This is advanced to `localGenCount` + 1 each time it is called.\n\t * On the other hand, when `resetUnfinalizedCreationRange` is called,\n\t * this is moved back to the start of the unfinalized range, to ensure those IDs are included in the next range.\n\t */\n\tprivate nextRangeBaseGenCount = 1;\n\tprivate readonly sessions = new Sessions();\n\tprivate readonly finalSpace = new FinalSpace();\n\n\t// #endregion\n\n\t// #region Ephemeral state\n\n\t/**\n\t * Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.\n\t * Eventually, this can be adjusted dynamically to have cluster reservation policies that\n\t * optimize the number of eager finals.\n\t * It is not readonly as it is accessed by tests for clear-box testing.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/prefer-readonly\n\tprivate nextRequestedClusterSize: number = 512;\n\t// The number of local IDs generated since the last telemetry was sent.\n\tprivate telemetryLocalIdCount = 0;\n\t// The number of eager final IDs generated since the last telemetry was sent.\n\tprivate telemetryEagerFinalIdCount = 0;\n\t// The ongoing ghost session, if one exists.\n\tprivate ongoingGhostSession?: { cluster?: IdCluster; ghostSessionId: SessionId } | undefined;\n\n\t// #endregion\n\n\tpublic constructor(\n\t\tlocalSessionIdOrDeserialized: SessionId | Sessions,\n\t\tprivate readonly logger: TelemetryLoggerExt | undefined,\n\t\t/**\n\t\t * The version this compressor will write out.\n\t\t * This applies to both `serialize` and creation range functions.\n\t\t * This number also determines what features are available (e.g. sharding support starts at V3).\n\t\t */\n\t\tprivate readonly writeVersion: SerializationVersion,\n\t) {\n\t\tif (typeof localSessionIdOrDeserialized === \"string\") {\n\t\t\tthis.localSessionId = localSessionIdOrDeserialized;\n\t\t\tthis.localSession = this.sessions.getOrCreate(localSessionIdOrDeserialized);\n\t\t} else {\n\t\t\t// Deserialize case\n\t\t\tthis.sessions = localSessionIdOrDeserialized;\n\t\t\t// As policy, the first session is always the local session. Preserve this invariant\n\t\t\t// during deserialization.\n\t\t\tconst firstSession = localSessionIdOrDeserialized.sessions().next();\n\t\t\tassert(!firstSession.done, 0x754 /* First session must be present. */);\n\t\t\tthis.localSession = firstSession.value;\n\t\t\tthis.localSessionId = stableIdFromNumericUuid(\n\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t) as SessionId;\n\t\t}\n\t}\n\n\tpublic generateCompressedId(): SessionSpaceCompressedId {\n\t\t// This ghost session code inside this block should not be changed without a version bump (it is performed at a consensus point)\n\t\tif (this.ongoingGhostSession) {\n\t\t\tif (this.ongoingGhostSession.cluster === undefined) {\n\t\t\t\tthis.ongoingGhostSession.cluster = this.addEmptyCluster(\n\t\t\t\t\tthis.sessions.getOrCreate(this.ongoingGhostSession.ghostSessionId),\n\t\t\t\t\t1,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.ongoingGhostSession.cluster.capacity++;\n\t\t\t}\n\t\t\tthis.ongoingGhostSession.cluster.count++;\n\t\t\treturn lastFinalizedFinal(\n\t\t\t\tthis.ongoingGhostSession.cluster,\n\t\t\t) as unknown as SessionSpaceCompressedId;\n\t\t}\n\n\t\t// In sharding mode, always generate local IDs with stride-based allocation.\n\t\t// Eager finals are disabled because shards backfill IDs not in their stride cycle.\n\t\t// If another shard generated them as eager finals, ingesting IDs from another shard\n\t\t// would fail depending on timing.\n\t\tif (this.shardingState !== undefined) {\n\t\t\tthis.telemetryLocalIdCount++;\n\t\t\tconst { currentStride } = this.shardingState;\n\t\t\tthis.normalizer.addLocalRange(this.localGenCount + 1, currentStride);\n\t\t\tthis.localGenCount += currentStride;\n\t\t\treturn localIdFromGenCount(this.localGenCount);\n\t\t}\n\n\t\t// Normal ID generation\n\t\tthis.localGenCount++;\n\t\tconst lastCluster = this.localSession.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\tthis.telemetryLocalIdCount++;\n\t\t\treturn this.generateNextLocalId();\n\t\t}\n\n\t\t// If there exists a cluster of final IDs already claimed by the local session that still has room in it,\n\t\t// it is known prior to range sequencing what a local ID's corresponding final ID will be.\n\t\t// In this case, it is safe to return the final ID immediately. This is guaranteed to be safe because\n\t\t// any op that the local session sends that contains one of those final IDs are guaranteed to arrive to\n\t\t// collaborators *after* the one containing the creation range.\n\t\tconst clusterOffset = this.localGenCount - genCountFromLocalId(lastCluster.baseLocalId);\n\t\tif (lastCluster.capacity > clusterOffset) {\n\t\t\tthis.telemetryEagerFinalIdCount++;\n\t\t\t// Space in the cluster: eager final\n\t\t\treturn ((lastCluster.baseFinalId as number) + clusterOffset) as SessionSpaceCompressedId;\n\t\t}\n\t\t// No space in the cluster, return next local\n\t\tthis.telemetryLocalIdCount++;\n\t\treturn this.generateNextLocalId();\n\t}\n\n\tpublic generateDocumentUniqueId():\n\t\t| (SessionSpaceCompressedId & OpSpaceCompressedId)\n\t\t| StableId {\n\t\tconst id = this.generateCompressedId();\n\t\treturn isFinalId(id) ? id : this.decompress(id);\n\t}\n\n\t/**\n\t * Starts a ghost session. Only exposed for test purposes (this class is not exported from the package).\n\t * @param ghostSessionId - The session ID to start the ghost session with.\n\t */\n\tpublic startGhostSession(ghostSessionId: SessionId): void {\n\t\tassert(!this.ongoingGhostSession, 0x8fe /* Ghost session already in progress. */);\n\t\tthis.ongoingGhostSession = { ghostSessionId };\n\t}\n\n\tpublic beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): void {\n\t\tif (this.shardingState) {\n\t\t\tthrow new Error(\"Cannot start a ghost session while sharded.\");\n\t\t}\n\t\tthis.startGhostSession(ghostSessionId);\n\t\ttry {\n\t\t\tghostSessionCallback();\n\t\t} finally {\n\t\t\tthis.ongoingGhostSession = undefined;\n\t\t}\n\t}\n\n\tpublic shard(newShardCount: number): SerializedIdCompressorShard[] {\n\t\tif (!Number.isSafeInteger(newShardCount) || newShardCount <= 0) {\n\t\t\tthrow new Error(\"Shard count must be a positive safe integer\");\n\t\t}\n\t\tif (this.ongoingGhostSession) {\n\t\t\tthrow new Error(\"Cannot shard during ghost session\");\n\t\t}\n\t\tif (this.writeVersion < SerializationVersion.V3) {\n\t\t\tthrow new Error(\n\t\t\t\t`Sharding requires document version ${SerializationVersion.V3} or higher, but this document is version ${this.writeVersion}`,\n\t\t\t);\n\t\t}\n\n\t\tconst currentStride = this.shardingState?.currentStride ?? 1;\n\t\tconst newStride = currentStride * (newShardCount + 1);\n\n\t\t// ID usage is exponential in stride count. Limit to practical size to avoid overflow.\n\t\tif (newStride > MAX_STRIDE_LENGTH) {\n\t\t\tthrow new Error(\"Sharding limit reached.\");\n\t\t}\n\t\tassert(Number.isSafeInteger(newStride), 0xd52 /* Shard stride must be a safe integer */);\n\n\t\tif (this.shardingState === undefined) {\n\t\t\t// First time sharding - initialize state\n\t\t\tthis.shardingState = {\n\t\t\t\tcurrentStride: newStride,\n\t\t\t\toriginalStride: 1,\n\t\t\t\tactiveChildIds: new Set(),\n\t\t\t};\n\t\t} else {\n\t\t\tthis.shardingState.currentStride = newStride;\n\t\t}\n\n\t\t// Cache to avoid repeating per child\n\t\tconst serialized = this.serialize(true);\n\t\tconst { localGenCount: parentGenCount } = this;\n\n\t\tconst shards: SerializedIdCompressorShard[] = [];\n\n\t\t// Children are positioned at consecutive positions within the parents current stride cycle\n\t\t// e.g. if parent owns the \"evens\" space (-2, -4, -6, ...) and is sharded into 3 (two children)\n\t\t// while at -8, then the child shards will start at -10 and -12 with a stride of 6\n\t\tfor (let i = 1; i <= newShardCount; i++) {\n\t\t\tconst childShardId = createSessionId();\n\t\t\tthis.shardingState.activeChildIds.add(childShardId);\n\n\t\t\tconst childLocalGenCount = parentGenCount + i * currentStride;\n\n\t\t\t// This code results in a double roundtrip, but is probably plenty fast enough for scenarios that need sharding,\n\t\t\t// as they necessarily have process boundaries to deal with.\n\t\t\t// If this ever became an issue we can implement a fast clone of compressors\n\t\t\tconst child = deserializeIdCompressor(serialized, this.writeVersion) as IdCompressor;\n\t\t\tconst genCountJump = childLocalGenCount - parentGenCount;\n\t\t\tassert(\n\t\t\t\tchild.localGenCount === parentGenCount && genCountJump > 0,\n\t\t\t\t0xd53 /* Child offsets incorrectly calculated. */,\n\t\t\t);\n\n\t\t\tchild.normalizer.addLocalRange(child.localGenCount + 1, genCountJump);\n\t\t\tchild.localGenCount = childLocalGenCount;\n\t\t\tchild.shardingState = {\n\t\t\t\tcurrentStride: newStride,\n\t\t\t\toriginalStride: newStride,\n\t\t\t\tactiveChildIds: new Set(),\n\t\t\t\tshardId: childShardId,\n\t\t\t};\n\n\t\t\tshards.push({\n\t\t\t\tserialized: child.serialize(true),\n\t\t\t\tsyncToken: child.makeShardToken(false),\n\t\t\t});\n\t\t}\n\n\t\treturn shards;\n\t}\n\n\tpublic synchronizeWithShard(syncToken: ShardSynchronizationToken): void {\n\t\tconst isNowLeaf = this.synchronizeChild(syncToken);\n\t\t// A disposal token additionally reclaims the child's ID space. If reclaiming the last child\n\t\t// returns this compressor to a leaf and it is the root (originalStride === 1), exit sharding mode.\n\t\tif (syncToken.disposed) {\n\t\t\tassert(this.shardingState !== undefined, 0xd54 /* Must be sharded */);\n\t\t\tif (isNowLeaf && this.shardingState.originalStride === 1) {\n\t\t\t\tthis.shardingState = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getChildShardSyncToken(\n\t\tchildToken: ShardSynchronizationToken,\n\t): ParentShardSynchronizationToken {\n\t\tif (!this.shardingState?.activeChildIds.has(childToken.shardId)) {\n\t\t\tthrow new Error(\"Cannot get a synchronization token for an inactive child shard.\");\n\t\t}\n\t\tconst token: ParentShardSynchronizationToken = {\n\t\t\ttype: \"parentIdSpaceShardSyncToken\",\n\t\t\tshardId: childToken.shardId,\n\t\t\tlocalGenCount: this.localGenCount,\n\t\t};\n\t\treturn token;\n\t}\n\n\tpublic synchronizeWithParent(token: ParentShardSynchronizationToken): void {\n\t\tconst state = this.shardingState;\n\t\tif (\n\t\t\ttoken.type !== \"parentIdSpaceShardSyncToken\" ||\n\t\t\tstate?.shardId === undefined ||\n\t\t\tstate.shardId !== token.shardId\n\t\t) {\n\t\t\tthrow new Error(\"Invalid parent synchronization token for this child shard.\");\n\t\t}\n\t\tvalidateShardGenerationCount(token.localGenCount);\n\t\tif (token.localGenCount <= this.localGenCount) {\n\t\t\t// A child can already be ahead through its own allocations. Its local range\n\t\t\t// then includes the parent's IDs through this generation count.\n\t\t\treturn;\n\t\t}\n\t\tthis.backfillToNextStridePosition(token.localGenCount, state.currentStride);\n\t}\n\n\t/**\n\t * Adds IDs through the next position in this shard's stride after the given generation count.\n\t */\n\tprivate backfillToNextStridePosition(targetGenCount: number, stride: number): void {\n\t\tif (targetGenCount <= this.localGenCount) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = Math.ceil((targetGenCount - this.localGenCount + 1) / stride) * stride;\n\t\tconst nextGenCount = this.localGenCount + count;\n\t\tif (!Number.isSafeInteger(nextGenCount)) {\n\t\t\tthrow new TypeError(\"Shard progress exceeds the supported ID space.\");\n\t\t}\n\t\tthis.normalizer.addLocalRange(this.localGenCount + 1, count);\n\t\tthis.localGenCount = nextGenCount;\n\t}\n\n\tprivate synchronizeChild(syncToken: ShardToken): boolean {\n\t\tconst childDisposed = syncToken.disposed;\n\t\tif (this.writeVersion < SerializationVersion.V3) {\n\t\t\tthrow new Error(\n\t\t\t\t`Sharding requires document version ${SerializationVersion.V3} or higher, but this document is version ${this.writeVersion}`,\n\t\t\t);\n\t\t}\n\t\tif (this.shardingState === undefined) {\n\t\t\tthrow new Error(\"Must be in sharding mode.\");\n\t\t}\n\n\t\tconst childShardId = syncToken.shardId;\n\t\tconst { activeChildIds, originalStride } = this.shardingState;\n\n\t\t// Verify this child belongs to us\n\t\tif (!activeChildIds.has(childShardId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot synchronize with child with ID ${childShardId}: not in active children set`,\n\t\t\t);\n\t\t}\n\t\tvalidateShardGenerationCount(syncToken.localGenCount);\n\n\t\t// A last-child disposal realigns on the original stride. Backfill before changing\n\t\t// membership so invalid progress cannot accidentally reclaim the child.\n\t\tconst isLeaf = childDisposed && activeChildIds.size === 1;\n\t\tthis.backfillToNextStridePosition(\n\t\t\tsyncToken.localGenCount,\n\t\t\tisLeaf ? originalStride : this.shardingState.currentStride,\n\t\t);\n\n\t\t// A plain synchronization leaves the child active so it can keep generating IDs.\n\t\tif (childDisposed) {\n\t\t\tactiveChildIds.delete(childShardId);\n\t\t\tif (isLeaf) {\n\t\t\t\tthis.shardingState.currentStride = originalStride;\n\t\t\t}\n\t\t}\n\n\t\treturn isLeaf;\n\t}\n\n\tpublic disposeShard(): ShardSynchronizationToken | undefined {\n\t\tif (this.shardingState === undefined) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\tif (this.shardingState.activeChildIds.size > 0) {\n\t\t\t\tthrow new Error(\"Cannot dispose a shard with active children.\");\n\t\t\t}\n\t\t}\n\n\t\t// A disposal token is a sync token that additionally signals reclamation of this shard's ID space.\n\t\tconst token = this.makeShardToken(true);\n\n\t\t// Make this compressor unusable by replacing all methods with throwing stubs\n\t\t// This is a one-time mutation that avoids runtime checks in every method\n\t\tmakeCompressorUnusable(this);\n\n\t\treturn token;\n\t}\n\n\tpublic getShardSyncToken(): ShardSynchronizationToken | undefined {\n\t\tif (this.shardingState === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.makeShardToken(false);\n\t}\n\n\t/**\n\t * Builds a token describing this shard's current progress.\n\t * @param disposed - Whether the token also signals disposal (reclamation of this shard's ID space).\n\t */\n\tprivate makeShardToken(disposed: boolean): ShardSynchronizationToken {\n\t\tassert(this.shardingState !== undefined, 0xd55 /* Compressor is not sharded. */);\n\n\t\t// Root cannot produce a token (shardId is undefined for root)\n\t\tif (this.shardingState.shardId === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Cannot get a token for a root compressor - only shards can be disposed\",\n\t\t\t);\n\t\t}\n\n\t\tconst token: ShardToken = {\n\t\t\tlocalGenCount: this.localGenCount,\n\t\t\tshardId: this.shardingState.shardId,\n\t\t\tdisposed,\n\t\t};\n\n\t\treturn token as unknown as ShardSynchronizationToken;\n\t}\n\n\tprivate generateNextLocalId(): LocalCompressedId {\n\t\t// Must tell the normalizer that we generated a local ID\n\t\tthis.normalizer.addLocalRange(this.localGenCount, 1);\n\t\treturn localIdFromGenCount(this.localGenCount);\n\t}\n\n\tpublic takeNextCreationRange(): IdCreationRange {\n\t\t// Child (non-root) shards must not submit their own creation ranges. All shards in a shard tree share a\n\t\t// single session, and only the root shard is responsible for finalizing that session's IDs with the server.\n\t\t// A child's generated IDs are reconciled with the root via shard synchronization tokens (see\n\t\t// synchronizeWithShard / disposeShard), not by independently sending ranges, which would overlap and\n\t\t// conflict with the root's ranges for the shared session.\n\t\tif (this.shardingState?.shardId !== undefined) {\n\t\t\tthrow new Error(\"Cannot take a creation range from a non-root shard.\");\n\t\t}\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a6 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst count = this.localGenCount - (this.nextRangeBaseGenCount - 1);\n\t\tif (count === 0) {\n\t\t\treturn {\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t};\n\t\t}\n\t\tconst range: IdCreationRange = {\n\t\t\tsessionId: this.localSessionId,\n\t\t\tids: {\n\t\t\t\tfirstGenCount: this.nextRangeBaseGenCount,\n\t\t\t\tcount,\n\t\t\t\trequestedClusterSize: this.nextRequestedClusterSize,\n\t\t\t\tlocalIdRanges: this.normalizer.getRangesBetween(\n\t\t\t\t\tthis.nextRangeBaseGenCount,\n\t\t\t\t\tthis.localGenCount,\n\t\t\t\t),\n\t\t\t},\n\t\t};\n\t\treturn this.updateToRange(range);\n\t}\n\n\tpublic takeUnfinalizedCreationRange(): IdCreationRange {\n\t\tthis.resetUnfinalizedCreationRange();\n\t\treturn this.takeNextCreationRange();\n\t}\n\n\tpublic resetUnfinalizedCreationRange(): void {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0xcec /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\n\t\tconst lastLocalCluster = this.localSession.getLastCluster();\n\t\tthis.nextRangeBaseGenCount =\n\t\t\tlastLocalCluster === undefined\n\t\t\t\t? 1\n\t\t\t\t: genCountFromLocalId(\n\t\t\t\t\t\t(lastLocalCluster.baseLocalId - lastLocalCluster.count) as LocalCompressedId,\n\t\t\t\t\t);\n\t}\n\n\tprivate updateToRange(range: IdCreationRange): IdCreationRange {\n\t\tthis.nextRangeBaseGenCount = this.localGenCount + 1;\n\t\treturn IdCompressor.assertValidRange(range);\n\t}\n\n\tprivate static assertValidRange(range: IdCreationRange): IdCreationRange {\n\t\tif (range.ids === undefined) {\n\t\t\treturn range;\n\t\t}\n\t\tconst { count, requestedClusterSize } = range.ids;\n\t\tassert(count > 0, 0x755 /* Malformed ID Range. */);\n\t\tassert(requestedClusterSize > 0, 0x876 /* Clusters must have a positive capacity. */);\n\t\tassert(\n\t\t\trequestedClusterSize <= IdCompressor.maxClusterSize,\n\t\t\t0x877 /* Clusters must not exceed max cluster size. */,\n\t\t);\n\t\treturn range;\n\t}\n\n\tpublic finalizeCreationRange(range: IdCreationRange): void {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a7 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\t// Check if the range has IDs\n\t\tif (range.ids === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tIdCompressor.assertValidRange(range);\n\t\tconst { sessionId, ids } = range;\n\t\tconst { count, firstGenCount, requestedClusterSize } = ids;\n\t\tconst session = this.sessions.getOrCreate(sessionId);\n\t\tconst isLocal = session === this.localSession;\n\t\tconst rangeBaseLocal = localIdFromGenCount(firstGenCount);\n\t\tlet lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// This is the first cluster in the session space\n\t\t\tif (rangeBaseLocal !== -1) {\n\t\t\t\tthrow rangeFinalizationError(-1, rangeBaseLocal);\n\t\t\t}\n\t\t\tlastCluster = this.addEmptyCluster(session, requestedClusterSize + count);\n\t\t\tif (isLocal) {\n\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\teventName: \"RuntimeIdCompressor:FirstCluster\",\n\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst remainingCapacity = lastCluster.capacity - lastCluster.count;\n\t\tif (lastCluster.baseLocalId - lastCluster.count !== rangeBaseLocal) {\n\t\t\tthrow rangeFinalizationError(\n\t\t\t\tlastCluster.baseLocalId - lastCluster.count,\n\t\t\t\trangeBaseLocal,\n\t\t\t);\n\t\t}\n\n\t\tif (remainingCapacity >= count) {\n\t\t\t// The current range fits in the existing cluster\n\t\t\tlastCluster.count += count;\n\t\t} else {\n\t\t\tconst overflow = count - remainingCapacity;\n\t\t\tconst newClaimedFinalCount = overflow + requestedClusterSize;\n\t\t\tif (lastCluster === this.finalSpace.getLastCluster()) {\n\t\t\t\t// The last cluster in the sessions chain is the last cluster globally, so it can be expanded.\n\t\t\t\tlastCluster.capacity += newClaimedFinalCount;\n\t\t\t\tlastCluster.count += count;\n\t\t\t\tassert(\n\t\t\t\t\t!this.sessions.clusterCollides(lastCluster),\n\t\t\t\t\t0x756 /* Cluster collision detected. */,\n\t\t\t\t);\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:ClusterExpansion\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t\tpreviousCapacity: lastCluster.capacity - newClaimedFinalCount,\n\t\t\t\t\t\tnewCapacity: lastCluster.capacity,\n\t\t\t\t\t\toverflow,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// The last cluster in the sessions chain is *not* the last cluster globally. Fill and overflow to new.\n\t\t\t\tlastCluster.count = lastCluster.capacity;\n\t\t\t\tconst newCluster = this.addEmptyCluster(session, newClaimedFinalCount);\n\t\t\t\tnewCluster.count += overflow;\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:NewCluster\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (isLocal) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"RuntimeIdCompressor:IdCompressorStatus\",\n\t\t\t\teagerFinalIdCount: this.telemetryEagerFinalIdCount,\n\t\t\t\tlocalIdCount: this.telemetryLocalIdCount,\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t});\n\t\t\tthis.telemetryEagerFinalIdCount = 0;\n\t\t\tthis.telemetryLocalIdCount = 0;\n\t\t}\n\n\t\tassert(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);\n\t\tthis.eventEmitter.emit(\"rangeFinalized\", range);\n\t}\n\n\tprivate addEmptyCluster(session: Session, capacity: number): IdCluster {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession?.cluster,\n\t\t\t0x8a8 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst newCluster = session.addNewCluster(\n\t\t\tthis.finalSpace.getAllocatedIdLimit(),\n\t\t\tcapacity,\n\t\t\t0,\n\t\t);\n\t\tassert(\n\t\t\t!this.sessions.clusterCollides(newCluster),\n\t\t\t0x758 /* Cluster collision detected. */,\n\t\t);\n\t\tthis.finalSpace.addCluster(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId {\n\t\tif (isFinalId(id)) {\n\t\t\treturn id;\n\t\t} else {\n\t\t\tconst local = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(local)) {\n\t\t\t\tthrow new Error(\"Invalid ID to normalize.\");\n\t\t\t}\n\t\t\tconst finalForm = this.localSession.tryConvertToFinal(local, true);\n\t\t\treturn finalForm === undefined\n\t\t\t\t? (local as unknown as OpSpaceCompressedId)\n\t\t\t\t: (finalForm as OpSpaceCompressedId);\n\t\t}\n\t}\n\n\tpublic tryNormalizeToSessionSpaceWithoutSession(\n\t\tid: OpSpaceCompressedId,\n\t): SessionSpaceCompressedId | undefined {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = this.localSession.getClusterByAllocatedFinal(id);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\t// Does not exist in local cluster chain\n\t\t\t\tif (id >= this.finalSpace.getFinalizedIdLimit()) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t} else {\n\t\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tif (genCountFromLocalId(alignedLocal) > this.localGenCount) {\n\t\t\t\t\t\t// The ID is not valid in this compressor. It is either from a future version of this compressor, or another compressor.\n\t\t\t\t\t\t// Since IDs from other compressors often are valid in this one, but uncompress incorrectly,\n\t\t\t\t\t\t// we cannot rely on this function (tryNormalizeToSessionSpaceWithoutSession) to validate that the IDs are from the same compressor.\n\t\t\t\t\t\t// Since such validation can not be robust, this \"try\" function is explicitly documented not to be allowed to be used for this case.\n\t\t\t\t\t\t// Therefore, as documented in the API docs for this function, calls can not rely on a specific output in this case,\n\t\t\t\t\t\t// and therefore the document behavior of throwing makes the most sense (helps catch bugs).\n\t\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t\t}\n\t\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic normalizeToSessionSpace(\n\t\tid: OpSpaceCompressedId,\n\t\toriginSessionId: SessionId,\n\t): SessionSpaceCompressedId {\n\t\tconst normalizedWithoutSession = this.tryNormalizeToSessionSpaceWithoutSession(id);\n\t\tif (normalizedWithoutSession === undefined) {\n\t\t\tconst localToNormalize = id as unknown as LocalCompressedId;\n\t\t\tif (originSessionId === this.localSessionId) {\n\t\t\t\tif (this.normalizer.contains(localToNormalize)) {\n\t\t\t\t\treturn localToNormalize;\n\t\t\t\t} else {\n\t\t\t\t\t// We never generated this local ID, so fail\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// LocalId from a remote session\n\t\t\t\tconst remoteSession = this.sessions.get(originSessionId);\n\t\t\t\tif (remoteSession === undefined) {\n\t\t\t\t\tthrow new Error(\"No IDs have ever been finalized by the supplied session.\");\n\t\t\t\t}\n\t\t\t\tconst correspondingFinal = remoteSession.tryConvertToFinal(localToNormalize, false);\n\t\t\t\tif (correspondingFinal === undefined) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn correspondingFinal as unknown as SessionSpaceCompressedId;\n\t\t\t}\n\t\t} else {\n\t\t\treturn normalizedWithoutSession;\n\t\t}\n\t}\n\n\tpublic decompress(id: SessionSpaceCompressedId): StableId {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = Session.getContainingCluster(id, this.finalSpace.clusters);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\tconst alignedGenCount = genCountFromLocalId(alignedLocal);\n\t\t\tconst lastFinalizedGenCount = genCountFromLocalId(lastFinalizedLocal(containingCluster));\n\t\t\tif (alignedGenCount > lastFinalizedGenCount) {\n\t\t\t\t// should be an eager final id generated by the local session\n\t\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t\tassert(!this.normalizer.contains(alignedLocal), 0x759 /* Normalizer out of sync. */);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(containingCluster.session.sessionUuid, alignedGenCount - 1),\n\t\t\t);\n\t\t} else {\n\t\t\tconst localToDecompress = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(localToDecompress)) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(\n\t\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t\t\tgenCountFromLocalId(localToDecompress) - 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic recompress(uncompressed: StableId): SessionSpaceCompressedId {\n\t\tconst recompressed = this.tryRecompress(uncompressed);\n\t\tif (recompressed === undefined) {\n\t\t\tthrow new Error(\"Could not recompress.\");\n\t\t}\n\t\treturn recompressed;\n\t}\n\n\tpublic tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined {\n\t\tconst match = this.sessions.getContainingCluster(uncompressed);\n\t\tif (match === undefined) {\n\t\t\tconst numericUncompressed = numericUuidFromStableId(uncompressed);\n\t\t\tconst offset = subtractNumericUuids(numericUncompressed, this.localSession.sessionUuid);\n\t\t\tif (offset < Number.MAX_SAFE_INTEGER) {\n\t\t\t\tconst genCountEquivalent = Number(offset) + 1;\n\t\t\t\tconst localEquivalent = localIdFromGenCount(genCountEquivalent);\n\t\t\t\tif (this.normalizer.contains(localEquivalent)) {\n\t\t\t\t\treturn localEquivalent;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\tconst [containingCluster, alignedLocal] = match;\n\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t// Local session\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tgenCountFromLocalId(alignedLocal) <= this.localGenCount,\n\t\t\t\t\t\t0x75a /* Clusters out of sync. */,\n\t\t\t\t\t);\n\t\t\t\t\t// Id is an eager final\n\t\t\t\t\treturn getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t| undefined;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Not the local session\n\t\t\t\treturn genCountFromLocalId(alignedLocal) >= lastFinalizedLocal(containingCluster)\n\t\t\t\t\t? (getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t\t| undefined)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic serialize(withSession: true): SerializedIdCompressorWithOngoingSession;\n\tpublic serialize(withSession: false): SerializedIdCompressorWithNoSession;\n\tpublic serialize(hasLocalState: boolean): SerializedIdCompressor {\n\t\tassert(\n\t\t\t!this.ongoingGhostSession,\n\t\t\t0x8a9 /* IdCompressor should not be operated normally when in a ghost session */,\n\t\t);\n\t\tconst { normalizer, finalSpace, sessions, localGenCount, logger, nextRangeBaseGenCount } =\n\t\t\tthis;\n\t\tconst sessionIndexMap = new Map<Session, number>();\n\t\tlet sessionIndex = 0;\n\t\tfor (const session of sessions.sessions()) {\n\t\t\t// Filter empty sessions to prevent them accumulating in the serialized state\n\t\t\tif (!session.isEmpty() || hasLocalState) {\n\t\t\t\tsessionIndexMap.set(session, sessionIndex);\n\t\t\t\tsessionIndex++;\n\t\t\t}\n\t\t}\n\t\tconst sizeOfUuid = 2;\n\t\tconst shardingStateSize =\n\t\t\thasLocalState && this.writeVersion >= SerializationVersion.V3\n\t\t\t\t? this.shardingState === undefined\n\t\t\t\t\t? 1 // Boolean: no sharding state\n\t\t\t\t\t: 1 + // Boolean: has sharding state\n\t\t\t\t\t\t2 + // Numbers: currentStride, originalStride (Float64)\n\t\t\t\t\t\t1 + // Number: activeChildIds count (Float64)\n\t\t\t\t\t\tthis.shardingState.activeChildIds.size * sizeOfUuid + // UUIDs: each is 128-bit\n\t\t\t\t\t\t1 + // Boolean: hasShardId\n\t\t\t\t\t\t(this.shardingState.shardId === undefined ? 0 : sizeOfUuid) // UUID: 128-bit if present\n\t\t\t\t: 0;\n\t\tconst localStateSize = hasLocalState\n\t\t\t? 1 + // generated ID count\n\t\t\t\t1 + // next range base genCount\n\t\t\t\t1 + // count of normalizer pairs\n\t\t\t\tnormalizer.idRanges.size * 2 + // pairs\n\t\t\t\tshardingStateSize // sharding state if present\n\t\t\t: 0;\n\t\t// Layout size, in 8 byte increments\n\t\tconst totalSize =\n\t\t\t1 + // version\n\t\t\t1 + // hasLocalState\n\t\t\t1 + // session count\n\t\t\t1 + // cluster count\n\t\t\tsessionIndexMap.size * sizeOfUuid + // session IDs\n\t\t\tfinalSpace.clusters.length * 3 + // clusters: (sessionIndex, capacity, count)[]\n\t\t\tlocalStateSize; // local state, if present\n\n\t\tconst serializedFloat = new Float64Array(totalSize);\n\t\tconst serializedUint = new BigUint64Array(serializedFloat.buffer);\n\t\tlet index = 0;\n\t\tindex = writeNumber(serializedFloat, index, this.writeVersion);\n\t\tindex = writeBoolean(serializedFloat, index, hasLocalState);\n\t\tindex = writeNumber(serializedFloat, index, sessionIndexMap.size);\n\t\tindex = writeNumber(serializedFloat, index, finalSpace.clusters.length);\n\n\t\tfor (const [session] of sessionIndexMap.entries()) {\n\t\t\tindex = writeNumericUuid(serializedUint, index, session.sessionUuid);\n\t\t}\n\n\t\tfor (const cluster of finalSpace.clusters) {\n\t\t\tindex = writeNumber(\n\t\t\t\tserializedFloat,\n\t\t\t\tindex,\n\t\t\t\tsessionIndexMap.get(cluster.session) as number,\n\t\t\t);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.capacity);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.count);\n\t\t}\n\n\t\tif (hasLocalState) {\n\t\t\tindex = writeNumber(serializedFloat, index, localGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, nextRangeBaseGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, normalizer.idRanges.size);\n\t\t\tfor (const [leadingGenCount, count] of normalizer.idRanges.entries()) {\n\t\t\t\tindex = writeNumber(serializedFloat, index, leadingGenCount);\n\t\t\t\tindex = writeNumber(serializedFloat, index, count);\n\t\t\t}\n\n\t\t\t// Write sharding state (version 3+)\n\t\t\tif (this.writeVersion >= SerializationVersion.V3) {\n\t\t\t\tindex = writeBoolean(serializedFloat, index, this.shardingState !== undefined);\n\t\t\t\tif (this.shardingState !== undefined) {\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.currentStride);\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.originalStride);\n\n\t\t\t\t\t// Write activeChildIds Set as count + array of NumericUuids\n\t\t\t\t\tindex = writeNumber(serializedFloat, index, this.shardingState.activeChildIds.size);\n\t\t\t\t\tfor (const childId of this.shardingState.activeChildIds) {\n\t\t\t\t\t\tindex = writeNumericUuid(serializedUint, index, numericUuidFromStableId(childId));\n\t\t\t\t\t}\n\n\t\t\t\t\t// Write shardId (optional)\n\t\t\t\t\tindex = writeBoolean(\n\t\t\t\t\t\tserializedFloat,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tthis.shardingState.shardId !== undefined,\n\t\t\t\t\t);\n\t\t\t\t\tif (this.shardingState.shardId !== undefined) {\n\t\t\t\t\t\tindex = writeNumericUuid(\n\t\t\t\t\t\t\tserializedUint,\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tnumericUuidFromStableId(this.shardingState.shardId),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tassert(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);\n\t\tlogger?.sendTelemetryEvent({\n\t\t\teventName: \"RuntimeIdCompressor:SerializedIdCompressorSize\",\n\t\t\tsize: serializedFloat.byteLength,\n\t\t\tclusterCount: finalSpace.clusters.length,\n\t\t\tsessionCount: sessionIndexMap.size,\n\t\t});\n\n\t\treturn bufferToString(serializedFloat.buffer, \"base64\") as SerializedIdCompressor;\n\t}\n\n\tpublic static deserialize(\n\t\tparams:\n\t\t\t| {\n\t\t\t\t\tserialized: SerializedIdCompressorWithOngoingSession;\n\t\t\t\t\trequestedWriteVersion: SerializationVersion;\n\t\t\t\t\tlogger?: TelemetryLoggerExt | undefined;\n\t\t\t\t\tnewSessionId?: never;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\tserialized: SerializedIdCompressorWithNoSession;\n\t\t\t\t\tnewSessionId: SessionId;\n\t\t\t\t\trequestedWriteVersion: SerializationVersion;\n\t\t\t\t\tlogger?: TelemetryLoggerExt | undefined;\n\t\t\t },\n\t): IdCompressor {\n\t\tconst { serialized, newSessionId: sessionId, logger, requestedWriteVersion } = params;\n\t\tconst buffer = stringToBuffer(serialized, \"base64\");\n\t\tconst index: Index = {\n\t\t\tindex: 0,\n\t\t\tbufferFloat: new Float64Array(buffer),\n\t\t\tbufferUint: new BigUint64Array(buffer),\n\t\t};\n\t\tconst serializedVersion = readNumber(index) as SerializationVersion;\n\t\t// If requested version is < the serialized version, we must write the version serialized\n\t\t// to avoid losing data.\n\t\tconst writeVersion = Math.max(\n\t\t\trequestedWriteVersion,\n\t\t\tserializedVersion,\n\t\t) as SerializationVersion;\n\n\t\tswitch (serializedVersion) {\n\t\t\tcase 2:\n\t\t\tcase 3: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tif (serializedVersion === 1) {\n\t\t\t\t\tthrow new Error(\"IdCompressor version 1.0 is no longer supported.\");\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"Unknown IdCompressor serialized version.\");\n\t\t\t}\n\t\t}\n\n\t\tconst hasLocalState = readBoolean(index);\n\t\tconst sessionCount = readNumber(index);\n\t\tconst clusterCount = readNumber(index);\n\n\t\t// Sessions\n\t\tlet sessionOffset = 0;\n\t\tconst sessions: [NumericUuid, Session][] = [];\n\t\tif (hasLocalState) {\n\t\t\tassert(\n\t\t\t\tsessionId === undefined,\n\t\t\t\t0x75e /* Local state should not exist in serialized form. */,\n\t\t\t);\n\t\t} else {\n\t\t\t// If !hasLocalState, there won't be a serialized local session ID so insert one at the beginning\n\t\t\tassert(sessionId !== undefined, 0x75d /* Local session ID is undefined. */);\n\t\t\tconst localSessionNumeric = numericUuidFromStableId(sessionId);\n\t\t\tsessions.push([localSessionNumeric, new Session(localSessionNumeric)]);\n\t\t\tsessionOffset = 1;\n\t\t}\n\n\t\tfor (let i = 0; i < sessionCount; i++) {\n\t\t\tconst numeric = readNumericUuid(index);\n\t\t\tsessions.push([numeric, new Session(numeric)]);\n\t\t}\n\n\t\tconst compressor = new IdCompressor(new Sessions(sessions), logger, writeVersion);\n\n\t\t// Clusters\n\t\tlet baseFinalId = 0;\n\t\tfor (let i = 0; i < clusterCount; i++) {\n\t\t\tconst sessionIndex = readNumber(index);\n\t\t\tconst sessionArray = sessions[sessionIndex + sessionOffset];\n\t\t\tassert(\n\t\t\t\tsessionArray !== undefined,\n\t\t\t\t0x9d8 /* sessionArray is undefined in IdCompressor.deserialize2_0 */,\n\t\t\t);\n\t\t\tconst session = sessionArray[1];\n\t\t\tconst capacity = readNumber(index);\n\t\t\tconst count = readNumber(index);\n\t\t\tconst cluster = session.addNewCluster(baseFinalId as FinalCompressedId, capacity, count);\n\t\t\tcompressor.finalSpace.addCluster(cluster);\n\t\t\tbaseFinalId += capacity;\n\t\t}\n\n\t\t// Local state\n\t\tif (hasLocalState) {\n\t\t\tcompressor.localGenCount = readNumber(index);\n\t\t\tcompressor.nextRangeBaseGenCount = readNumber(index);\n\t\t\tconst normalizerCount = readNumber(index);\n\t\t\tfor (let i = 0; i < normalizerCount; i++) {\n\t\t\t\tcompressor.normalizer.addLocalRange(readNumber(index), readNumber(index));\n\t\t\t}\n\n\t\t\t// Sharding state (version 3+)\n\t\t\tif (serializedVersion >= 3) {\n\t\t\t\tconst hasShardingState = readBoolean(index);\n\t\t\t\tif (hasShardingState) {\n\t\t\t\t\tconst currentStride = readNumber(index);\n\t\t\t\t\tconst originalStride = readNumber(index);\n\n\t\t\t\t\t// Read activeChildIds Set\n\t\t\t\t\tconst activeChildCount = readNumber(index);\n\t\t\t\t\tconst activeChildIds = new Set<SessionId>();\n\t\t\t\t\tfor (let i = 0; i < activeChildCount; i++) {\n\t\t\t\t\t\tconst childIdNumeric = readNumericUuid(index);\n\t\t\t\t\t\t// Safe cast: these were serialized as SessionIds\n\t\t\t\t\t\tactiveChildIds.add(stableIdFromNumericUuid(childIdNumeric) as SessionId);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Read shardId (optional)\n\t\t\t\t\tconst hasShardId = readBoolean(index);\n\t\t\t\t\tconst shardId: SessionId | undefined = hasShardId\n\t\t\t\t\t\t? (stableIdFromNumericUuid(readNumericUuid(index)) as SessionId)\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t// Build sharding state object, conditionally including shardId\n\t\t\t\t\tcompressor.shardingState = {\n\t\t\t\t\t\tcurrentStride,\n\t\t\t\t\t\toriginalStride,\n\t\t\t\t\t\tactiveChildIds,\n\t\t\t\t\t\t...(shardId !== undefined && { shardId }),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tindex.index === index.bufferFloat.length,\n\t\t\t0x75f /* Failed to read entire serialized compressor. */,\n\t\t);\n\t\treturn compressor;\n\t}\n\n\tpublic equals(other: IdCompressor, includeLocalState: boolean): boolean {\n\t\tif (\n\t\t\tincludeLocalState &&\n\t\t\t(this.localSessionId !== other.localSessionId ||\n\t\t\t\t!this.localSession.equals(other.localSession) ||\n\t\t\t\t!this.normalizer.equals(other.normalizer) ||\n\t\t\t\tthis.nextRangeBaseGenCount !== other.nextRangeBaseGenCount ||\n\t\t\t\tthis.localGenCount !== other.localGenCount)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\t// Shard ownership affects future local ID allocation, even when the generated IDs match.\n\t\t// It is not part of finalized state, so ignore it when comparing only that state.\n\t\tif (includeLocalState) {\n\t\t\tconst state = this.shardingState;\n\t\t\tconst otherState = other.shardingState;\n\t\t\tif (state === undefined || otherState === undefined) {\n\t\t\t\t// Two unsharded compressors match here; a sharded and an unsharded compressor do not.\n\t\t\t\tif (state !== otherState) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tstate.currentStride !== otherState.currentStride ||\n\t\t\t\t\tstate.originalStride !== otherState.originalStride ||\n\t\t\t\t\tstate.shardId !== otherState.shardId ||\n\t\t\t\t\tstate.activeChildIds.size !== otherState.activeChildIds.size\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t// Child ownership is an unordered set. Equal sizes and membership imply equal sets,\n\t\t\t\t// regardless of insertion order or whether the state was deserialized.\n\t\t\t\tfor (const childId of state.activeChildIds) {\n\t\t\t\t\tif (!otherState.activeChildIds.has(childId)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (\n\t\t\tthis.sessions.equals(other.sessions, includeLocalState) &&\n\t\t\tthis.finalSpace.equals(other.finalSpace)\n\t\t);\n\t}\n}\n\n/**\n * Create a new {@link IIdCompressor}.\n * @param writeVersion - The version the compressor will write when serializing. Use SerializationVersion.V2 for base format, or SerializationVersion.V3 for sharding support.\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function createIdCompressor(\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Create a new {@link IIdCompressor}.\n * @param sessionId - The seed ID for the compressor.\n * @param writeVersion - The version the compressor will write when serializing. Use SerializationVersion.V2 for base format, or SerializationVersion.V3 for sharding support.\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function createIdCompressor(\n\tsessionId: SessionId,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\nexport function createIdCompressor(\n\tsessionIdOrDocumentVersion: SessionId | SerializationVersion,\n\twriteVersionOrLogger?: SerializationVersion | ITelemetryBaseLogger,\n\tloggerOrUndefined?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore {\n\tlet localSessionId: SessionId;\n\tlet writeVersion: SerializationVersion;\n\tlet logger: ITelemetryBaseLogger | undefined;\n\n\tif (typeof sessionIdOrDocumentVersion === \"string\") {\n\t\t// Called with sessionId, writeVersion, logger?\n\t\tlocalSessionId = sessionIdOrDocumentVersion;\n\t\twriteVersion = writeVersionOrLogger as SerializationVersion;\n\t\tlogger = loggerOrUndefined;\n\t} else {\n\t\t// Called with writeVersion, logger?\n\t\tlocalSessionId = createSessionId();\n\t\twriteVersion = sessionIdOrDocumentVersion;\n\t\tlogger = writeVersionOrLogger as ITelemetryBaseLogger | undefined;\n\t}\n\n\tconst compressor = new IdCompressor(\n\t\tlocalSessionId,\n\t\tlogger === undefined ? undefined : createChildLogger({ logger }),\n\t\twriteVersion,\n\t);\n\treturn compressor;\n}\n\n/**\n * Deserializes the supplied state into an ID compressor.\n * @param serialized - The serialized compressor state with an ongoing session.\n * @param writeVersion - The version the compressor will write when serializing. This determines what features are available (e.g., V3 enables sharding support).\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressorWithOngoingSession,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Deserializes the supplied state into an ID compressor.\n * @param serialized - The serialized compressor state without a session.\n * @param newSessionId - The session ID to use for the deserialized compressor.\n * @param writeVersion - The version the compressor will write when serializing. This determines what features are available (e.g., V3 enables sharding support).\n * @param logger - Optional telemetry logger.\n * @internal\n */\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressorWithNoSession,\n\tnewSessionId: SessionId,\n\twriteVersion: SerializationVersion,\n\tlogger?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore;\nexport function deserializeIdCompressor(\n\tserialized: SerializedIdCompressor | SerializedIdCompressorWithNoSession,\n\tsessionIdOrDocumentVersion: SessionId | SerializationVersion,\n\twriteVersionOrLogger?: SerializationVersion | ITelemetryLoggerExt,\n\tloggerOrUndefined?: ITelemetryLoggerExt,\n): IIdCompressor & IIdCompressorCore {\n\tif (typeof sessionIdOrDocumentVersion === \"string\") {\n\t\t// Called with (serialized, sessionId, writeVersion, logger?)\n\t\treturn IdCompressor.deserialize({\n\t\t\tserialized: serialized as SerializedIdCompressorWithNoSession,\n\t\t\tlogger: extractTelemetryLoggerExt<{ PossiblyUndefined: true }>(loggerOrUndefined),\n\t\t\tnewSessionId: sessionIdOrDocumentVersion,\n\t\t\trequestedWriteVersion: writeVersionOrLogger as SerializationVersion,\n\t\t});\n\t}\n\n\tassert(\n\t\tloggerOrUndefined === undefined,\n\t\t0xc2d /* logger would be in sessionIdOrLogger in this codepath */,\n\t);\n\t// Called with (serialized, writeVersion, logger?)\n\treturn IdCompressor.deserialize({\n\t\tserialized: serialized as SerializedIdCompressorWithOngoingSession,\n\t\tlogger: extractTelemetryLoggerExt<{ PossiblyUndefined: true }>(\n\t\t\twriteVersionOrLogger as ITelemetryLoggerExt | undefined,\n\t\t),\n\t\trequestedWriteVersion: sessionIdOrDocumentVersion,\n\t});\n}\n\n/**\n * Throws an error indicating the compressor has been disposed.\n */\nconst throwDisposed = (): never => {\n\tthrow new Error(\n\t\t\"This compressor has been disposed via disposeShard() and can no longer be used.\",\n\t);\n};\n\n/**\n * Makes an IdCompressor instance unusable by replacing all its methods with functions that throw.\n * This is called once when disposeShard() is invoked to make the compressor permanently unusable.\n * @param compressor - The compressor instance to make unusable\n */\nfunction makeCompressorUnusable(compressor: IdCompressor): void {\n\t// Get all method names from the prototype (where class methods live)\n\tconst proto = Object.getPrototypeOf(compressor) as object;\n\tfor (const key of Reflect.ownKeys(proto)) {\n\t\tif (key !== \"constructor\" && typeof Reflect.get(proto, key) === \"function\") {\n\t\t\t// Shadow the method only on this instance so other compressors remain usable.\n\t\t\t// Omitting `enumerable` keeps new overrides non-enumerable, like class methods.\n\t\t\t// Reflection supports string and symbol keys without adding an index signature.\n\t\t\tObject.defineProperty(compressor, key, {\n\t\t\t\tvalue: throwDisposed,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Serializes an ID compressor.\n * @param compressor - The compressor to serialize.\n * @param withSession - If true, the serialized state will include local session\n * state (for stashing). If false, only finalized state is included (for summaries).\n * @internal\n */\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: true,\n): SerializedIdCompressorWithOngoingSession;\n/**\n * Serializes an ID compressor.\n * @param compressor - The compressor to serialize.\n * @param withSession - If true, the serialized state will include local session\n * state (for stashing). If false, only finalized state is included (for summaries).\n * @internal\n */\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: false,\n): SerializedIdCompressorWithNoSession;\nexport function serializeIdCompressor(\n\tcompressor: IIdCompressor,\n\twithSession: boolean,\n): SerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession {\n\tconst core = toIdCompressorWithCore(compressor);\n\treturn withSession ? core.serialize(true) : core.serialize(false);\n}\n\n/**\n * Casts an {@link IIdCompressor} to include {@link IIdCompressorCore}.\n *\n * @remarks\n * Compressors returned by `createIdCompressor` and `deserializeIdCompressor`\n * always implement both {@link IIdCompressor} and {@link IIdCompressorCore}, but their\n * public return type is narrowed to {@link IIdCompressor}. Internal consumers that\n * need access to core compressor operations (serialization, range management, etc.)\n * use this function to recover the {@link IIdCompressorCore} surface.\n *\n * @param compressor - A compressor created by `createIdCompressor` or\n * `deserializeIdCompressor`.\n * @returns The same compressor, typed to include {@link IIdCompressorCore}.\n * @internal\n */\nexport function toIdCompressorWithCore(\n\tcompressor: IIdCompressor,\n): IIdCompressor & IIdCompressorCore {\n\tassert(\n\t\t\"serialize\" in compressor,\n\t\t0xced /* Expected compressor to implement IIdCompressorCore */,\n\t);\n\treturn compressor as IIdCompressor & IIdCompressorCore;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -9,5 +9,5 @@ export { createIdCompressor, deserializeIdCompressor, serializeIdCompressor, toI
9
9
  export { SerializationVersion } from "./types/index.js";
10
10
  export { type FinalCompressedId, isFinalId } from "./identifiers.js";
11
11
  export { createSessionId, assertIsStableId, generateStableId, isStableId, } from "./utilities.js";
12
- export type { IIdCompressorCore, IIdCompressor, SerializedIdCompressor, SerializedIdCompressorWithOngoingSession, SerializedIdCompressorWithNoSession, SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId, IdCreationRange, ShardToken, ShardSynchronizationToken, } from "./types/index.js";
12
+ export type { IdCreationRange, IIdCompressor, IIdCompressorCore, IdCompressorEvents, OpSpaceCompressedId, ParentShardSynchronizationToken, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, SerializedIdCompressorShard, SessionId, SessionSpaceCompressedId, ShardSynchronizationToken, ShardToken, StableId, } from "./types/index.js";
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EACN,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,iBAAiB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACX,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,wCAAwC,EACxC,mCAAmC,EACnC,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,eAAe,EACf,UAAU,EACV,yBAAyB,GACzB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EACN,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,iBAAiB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,+BAA+B,EAC/B,sBAAsB,EACtB,mCAAmC,EACnC,wCAAwC,EACxC,2BAA2B,EAC3B,SAAS,EACT,wBAAwB,EACxB,yBAAyB,EACzB,UAAU,EACV,QAAQ,GACR,MAAM,kBAAkB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AAEH,qDAK2B;AAJ1B,qHAAA,kBAAkB,OAAA;AAClB,0HAAA,uBAAuB,OAAA;AACvB,wHAAA,qBAAqB,OAAA;AACrB,yHAAA,sBAAsB,OAAA;AAEvB,6CAAwD;AAA/C,gHAAA,oBAAoB,OAAA;AAC7B,mDAAqE;AAApC,2GAAA,SAAS,OAAA;AAC1C,+CAKwB;AAJvB,+GAAA,eAAe,OAAA;AACf,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAChB,0GAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Exports for `id-compressor`\n */\n\nexport {\n\tcreateIdCompressor,\n\tdeserializeIdCompressor,\n\tserializeIdCompressor,\n\ttoIdCompressorWithCore,\n} from \"./idCompressor.js\";\nexport { SerializationVersion } from \"./types/index.js\";\nexport { type FinalCompressedId, isFinalId } from \"./identifiers.js\";\nexport {\n\tcreateSessionId,\n\tassertIsStableId,\n\tgenerateStableId,\n\tisStableId,\n} from \"./utilities.js\";\nexport type {\n\tIIdCompressorCore,\n\tIIdCompressor,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithOngoingSession,\n\tSerializedIdCompressorWithNoSession,\n\tSessionSpaceCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n\tStableId,\n\tIdCreationRange,\n\tShardToken,\n\tShardSynchronizationToken,\n} from \"./types/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AAEH,qDAK2B;AAJ1B,qHAAA,kBAAkB,OAAA;AAClB,0HAAA,uBAAuB,OAAA;AACvB,wHAAA,qBAAqB,OAAA;AACrB,yHAAA,sBAAsB,OAAA;AAEvB,6CAAwD;AAA/C,gHAAA,oBAAoB,OAAA;AAC7B,mDAAqE;AAApC,2GAAA,SAAS,OAAA;AAC1C,+CAKwB;AAJvB,+GAAA,eAAe,OAAA;AACf,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAChB,0GAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Exports for `id-compressor`\n */\n\nexport {\n\tcreateIdCompressor,\n\tdeserializeIdCompressor,\n\tserializeIdCompressor,\n\ttoIdCompressorWithCore,\n} from \"./idCompressor.js\";\nexport { SerializationVersion } from \"./types/index.js\";\nexport { type FinalCompressedId, isFinalId } from \"./identifiers.js\";\nexport {\n\tcreateSessionId,\n\tassertIsStableId,\n\tgenerateStableId,\n\tisStableId,\n} from \"./utilities.js\";\nexport type {\n\tIdCreationRange,\n\tIIdCompressor,\n\tIIdCompressorCore,\n\tIdCompressorEvents,\n\tOpSpaceCompressedId,\n\tParentShardSynchronizationToken,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n\tSerializedIdCompressorShard,\n\tSessionId,\n\tSessionSpaceCompressedId,\n\tShardSynchronizationToken,\n\tShardToken,\n\tStableId,\n} from \"./types/index.js\";\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/id-compressor";
8
- export declare const pkgVersion = "3.3.0";
8
+ export declare const pkgVersion = "3.5.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/id-compressor";
11
- exports.pkgVersion = "3.3.0";
11
+ exports.pkgVersion = "3.5.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,+BAA+B,CAAC;AAC1C,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/id-compressor\";\nexport const pkgVersion = \"3.3.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,+BAA+B,CAAC;AAC1C,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/id-compressor\";\nexport const pkgVersion = \"3.5.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sharding.fuzz.spec.js","sourceRoot":"","sources":["../../src/test/sharding.fuzz.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,gFAS8C;AAE9C,wDAAkD;AAElD,gDAAyD;AACzD,kDAAkD;AA6ElD;;GAEG;AACH,SAAS,cAAc,CAAC,KAA4B;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,OAAO;QACN,IAAI,EAAE,OAAO;QACb,UAAU;QACV,SAAS;KACT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAA4B;IACrD,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;IAC1C,0CAA0C;IAC1C,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,cAAc,CAAC,CAAC;IAE3E,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,2DAA2D;QAC3D,OAAO;YACN,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,KAAK,CAAC,cAAc;SAC1B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,iB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,aAAa,EAAE,EAAE;YACjB,gBAAgB,EAAE,EAAE;YACpB,gBAAgB,EAAE,GAAG;SACrB,CAAC,CACF,CAAC;QACF,0BAA0B,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACvF,MAAM,SAAS,GAAG,IAAA,8BAAe,GAAE,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,8BAAY,CAAC,SAAS,EAAE,SAAS,EAAE,+BAAoB,CAAC,EAAE,CAAC,CAAC;QAC7E,2FAA2F;QAC3F,iFAAiF;QACjF,MAAM,SAAS,GAAG,IAAA,4BAAI,EACrB,IAAI,EACJ,uBAAuB,CAAC;YACvB,WAAW,EAAE,CAAC;YACd,aAAa,EAAE,CAAC;YAChB,iBAAiB,EAAE,EAAE;YACrB,gBAAgB,EAAE,EAAE;YACpB,gBAAgB,EAAE,GAAG;SACrB,CAAC,CACF,CAAC;QACF,0BAA0B,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype BaseFuzzTestState,\n\ttype Generator,\n\tcreateWeightedGenerator,\n\tinterleave,\n\tmakeRandom,\n\tperformFuzzActions as performFuzzActionsBase,\n\trepeat,\n\ttake,\n} from \"@fluid-private/stochastic-test-utils\";\n\nimport { IdCompressor } from \"../idCompressor.js\";\nimport type { SessionSpaceCompressedId, StableId } from \"../index.js\";\nimport { SerializationVersion } from \"../types/index.js\";\nimport { createSessionId } from \"../utilities.js\";\n\n/**\n * State for sharding fuzz tests.\n * Tracks a tree of compressors and all generated IDs for collision detection and validation.\n */\ninterface ShardingFuzzTestState extends BaseFuzzTestState {\n\t/** The root compressor that started the tree */\n\trootCompressor: IdCompressor;\n\t/** Map from compressor to its parent (undefined for root) */\n\tparentMap: Map<IdCompressor, IdCompressor | undefined>;\n\t/** Map from compressor to its children */\n\tchildrenMap: Map<IdCompressor, Set<IdCompressor>>;\n\t/** All active compressors (not disposed) */\n\tactiveCompressors: Set<IdCompressor>;\n\t/** Leaf compressors that can be unsharded */\n\tleafCompressors: Set<IdCompressor>;\n\t/** Map from compressor to all local IDs it has generated */\n\tcompressorGeneratedIds: Map<IdCompressor, SessionSpaceCompressedId[]>;\n\t/**\n\t * Map from compressor to the set of local IDs it has been synchronized with (and so must be able\n\t * to decompress) but did not itself generate. Populated by synchronize operations.\n\t */\n\tsynchronizedIds: Map<IdCompressor, Set<SessionSpaceCompressedId>>;\n\t/** Global set of all generated local IDs for collision detection */\n\tglobalLocalIds: Set<SessionSpaceCompressedId>;\n\t/** Global set of all decompressed stable IDs for collision detection */\n\tglobalStableIds: Set<StableId>;\n}\n\n/**\n * Operation to shard a compressor into multiple child shards.\n */\ninterface ShardOperation {\n\ttype: \"shard\";\n\tcompressor: IdCompressor;\n\tnumShards: number;\n}\n\n/**\n * Operation to unshard a leaf compressor back into its parent.\n */\ninterface UnshardOperation {\n\ttype: \"unshard\";\n\tleaf: IdCompressor;\n}\n\n/**\n * Operation to synchronize a child shard's progress into its parent without disposing the child.\n */\ninterface SynchronizeOperation {\n\ttype: \"synchronize\";\n\tchild: IdCompressor;\n}\n\n/**\n * Operation to generate a new compressed ID.\n */\ninterface GenerateIdOperation {\n\ttype: \"generateId\";\n\tcompressor: IdCompressor;\n}\n\n/**\n * Operation to validate the current state of all compressors.\n */\ninterface ValidateShardingOperation {\n\ttype: \"validateSharding\";\n}\n\ntype ShardingOperation =\n\t| ShardOperation\n\t| UnshardOperation\n\t| SynchronizeOperation\n\t| GenerateIdOperation\n\t| ValidateShardingOperation;\n\n/**\n * Generates a shard operation targeting a random active compressor.\n */\nfunction shardGenerator(state: ShardingFuzzTestState): ShardOperation {\n\tconst compressor = state.random.pick([...state.activeCompressors]);\n\tconst numShards = state.random.integer(1, 3);\n\treturn {\n\t\ttype: \"shard\",\n\t\tcompressor,\n\t\tnumShards,\n\t};\n}\n\n/**\n * Generates an unshard operation targeting a random leaf compressor.\n * If there are no leaves (only root), returns a no-op operation.\n */\nfunction unshardGenerator(state: ShardingFuzzTestState): UnshardOperation {\n\tconst leaves = [...state.leafCompressors];\n\t// Filter out root - it can't be unsharded\n\tconst unshardableLeaves = leaves.filter((l) => l !== state.rootCompressor);\n\n\tif (unshardableLeaves.length === 0) {\n\t\t// No-op: target root which will be filtered out in handler\n\t\treturn {\n\t\t\ttype: \"unshard\",\n\t\t\tleaf: state.rootCompressor,\n\t\t};\n\t}\n\n\tconst leaf = state.random.pick(unshardableLeaves);\n\treturn {\n\t\ttype: \"unshard\",\n\t\tleaf,\n\t};\n}\n\n/**\n * Generates a synchronize operation targeting a random non-root active compressor.\n * The selected compressor's parent will be synchronized with it.\n * If there are no non-root compressors, returns a no-op targeting the root (filtered out in the handler).\n */\nfunction synchronizeGenerator(state: ShardingFuzzTestState): SynchronizeOperation {\n\tconst children = [...state.activeCompressors].filter((c) => c !== state.rootCompressor);\n\tif (children.length === 0) {\n\t\t// No-op: target root which will be filtered out in the handler.\n\t\treturn {\n\t\t\ttype: \"synchronize\",\n\t\t\tchild: state.rootCompressor,\n\t\t};\n\t}\n\treturn {\n\t\ttype: \"synchronize\",\n\t\tchild: state.random.pick(children),\n\t};\n}\n\n/**\n * Generates an operation to generate a new ID from a random compressor.\n */\nfunction generateIdGenerator(state: ShardingFuzzTestState): GenerateIdOperation {\n\tconst compressor = state.random.pick([...state.activeCompressors]);\n\treturn {\n\t\ttype: \"generateId\",\n\t\tcompressor,\n\t};\n}\n\n/**\n * Generates a validation operation.\n */\nfunction validateGenerator(): ValidateShardingOperation {\n\treturn { type: \"validateSharding\" };\n}\n\n/**\n * Configuration for the sharding operation generator.\n */\ninterface ShardingOpGeneratorConfig {\n\t/** Weight for shard operations (default: 3) */\n\tshardWeight?: number;\n\t/** Weight for unshard operations (default: 3) */\n\tunshardWeight?: number;\n\t/** Weight for synchronize operations (default: 5) */\n\tsynchronizeWeight?: number;\n\t/** Weight for ID generation operations (default: 20) */\n\tgenerateIdWeight?: number;\n\t/** How often to inject validation operations (default: every 100 ops) */\n\tvalidateInterval?: number;\n}\n\n/**\n * Creates a weighted generator for sharding fuzz test operations.\n */\nfunction makeShardingOpGenerator(\n\tconfig: ShardingOpGeneratorConfig,\n): Generator<ShardingOperation, ShardingFuzzTestState> {\n\tconst {\n\t\tshardWeight = 3,\n\t\tunshardWeight = 3,\n\t\tsynchronizeWeight = 5,\n\t\tgenerateIdWeight = 20,\n\t\tvalidateInterval = 100,\n\t} = config;\n\n\treturn interleave(\n\t\tcreateWeightedGenerator<ShardingOperation, ShardingFuzzTestState>([\n\t\t\t[shardGenerator, shardWeight],\n\t\t\t[unshardGenerator, unshardWeight],\n\t\t\t[synchronizeGenerator, synchronizeWeight],\n\t\t\t[generateIdGenerator, generateIdWeight],\n\t\t]),\n\t\ttake(1, repeat<ShardingOperation, ShardingFuzzTestState>(validateGenerator())),\n\t\tvalidateInterval,\n\t);\n}\n\n/**\n * Handles a shard operation by creating new child shards and updating the tree structure.\n */\nfunction handleShard(state: ShardingFuzzTestState, op: ShardOperation): ShardingFuzzTestState {\n\tconst { compressor, numShards } = op;\n\n\tlet serializedShards: ReturnType<IdCompressor[\"shard\"]>;\n\ttry {\n\t\tserializedShards = compressor.shard(numShards);\n\t} catch (error) {\n\t\t// Sharding multiplies the stride; once it would exceed the supported maximum, shard() throws\n\t\t// before mutating any state. This is expected for sufficiently deep trees, so treat it as a no-op.\n\t\tif (error instanceof Error && error.message === \"Sharding limit reached.\") {\n\t\t\treturn state;\n\t\t}\n\t\tthrow error;\n\t}\n\n\tfor (const serialized of serializedShards) {\n\t\tconst shard = IdCompressor.deserialize({\n\t\t\tserialized,\n\t\t\trequestedWriteVersion: SerializationVersion.V3,\n\t\t});\n\n\t\t// Update tree structure\n\t\tstate.parentMap.set(shard, compressor);\n\n\t\tlet children = state.childrenMap.get(compressor);\n\t\tif (children === undefined) {\n\t\t\tchildren = new Set();\n\t\t\tstate.childrenMap.set(compressor, children);\n\t\t}\n\t\tchildren.add(shard);\n\n\t\tstate.childrenMap.set(shard, new Set());\n\t\tstate.activeCompressors.add(shard);\n\t\tstate.leafCompressors.add(shard);\n\t\tstate.compressorGeneratedIds.set(shard, []);\n\t\tstate.synchronizedIds.set(shard, new Set());\n\t}\n\n\t// Parent is no longer a leaf after sharding\n\tstate.leafCompressors.delete(compressor);\n\n\treturn state;\n}\n\n/**\n * Handles an unshard operation by disposing a leaf and merging it back into its parent.\n * No-op if the target is the root or not a leaf.\n */\nfunction handleUnshard(\n\tstate: ShardingFuzzTestState,\n\top: UnshardOperation,\n): ShardingFuzzTestState {\n\tconst { leaf } = op;\n\n\t// Can't unshard root or non-leaves\n\tif (leaf === state.rootCompressor || !state.leafCompressors.has(leaf)) {\n\t\treturn state;\n\t}\n\n\tconst parent = state.parentMap.get(leaf);\n\tif (parent === undefined) {\n\t\treturn state;\n\t}\n\n\tconst disposalToken = leaf.disposeShard();\n\tif (disposalToken === undefined) {\n\t\treturn state;\n\t}\n\n\tparent.synchronizeWithShard(disposalToken);\n\n\t// Update tree structure\n\tconst siblings = state.childrenMap.get(parent);\n\tif (siblings !== undefined) {\n\t\tsiblings.delete(leaf);\n\n\t\t// If parent has no more children, it becomes a leaf\n\t\tif (siblings.size === 0) {\n\t\t\tstate.leafCompressors.add(parent);\n\t\t}\n\t}\n\n\t// The disposed leaf's IDs become the parent's responsibility to decompress.\n\tconst parentSynced = state.synchronizedIds.get(parent) ?? new Set();\n\tfor (const id of state.compressorGeneratedIds.get(leaf) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tfor (const id of state.synchronizedIds.get(leaf) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tstate.synchronizedIds.set(parent, parentSynced);\n\n\tstate.parentMap.delete(leaf);\n\tstate.childrenMap.delete(leaf);\n\tstate.activeCompressors.delete(leaf);\n\tstate.leafCompressors.delete(leaf);\n\tstate.compressorGeneratedIds.delete(leaf);\n\tstate.synchronizedIds.delete(leaf);\n\n\treturn state;\n}\n\n/**\n * Handles a synchronize operation by synchronizing a child's parent with the child's current progress,\n * without disposing the child. After this, the parent must be able to decompress every ID the child has\n * generated (and every ID the child had itself been synchronized with) up to this point.\n * No-op if the target is the root or is otherwise no longer eligible.\n */\nfunction handleSynchronize(\n\tstate: ShardingFuzzTestState,\n\top: SynchronizeOperation,\n): ShardingFuzzTestState {\n\tconst { child } = op;\n\n\tif (child === state.rootCompressor || !state.activeCompressors.has(child)) {\n\t\treturn state;\n\t}\n\n\tconst parent = state.parentMap.get(child);\n\tif (parent === undefined || !state.activeCompressors.has(parent)) {\n\t\treturn state;\n\t}\n\n\tconst token = child.getShardSyncToken();\n\tif (token === undefined) {\n\t\treturn state;\n\t}\n\n\tparent.synchronizeWithShard(token);\n\n\t// Record everything the parent must now be able to decompress: the child's own generated IDs plus\n\t// whatever the child had previously been synchronized with (this models upward propagation, since\n\t// the child's gen count was advanced past those IDs when it synchronized with its own children).\n\tlet parentSynced = state.synchronizedIds.get(parent);\n\tif (parentSynced === undefined) {\n\t\tparentSynced = new Set();\n\t\tstate.synchronizedIds.set(parent, parentSynced);\n\t}\n\tfor (const id of state.compressorGeneratedIds.get(child) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tfor (const id of state.synchronizedIds.get(child) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\n\treturn state;\n}\n\n/**\n * Handles an ID generation operation.\n * Generates a new ID and checks for collisions in both local ID space and stable ID space.\n * Fails immediately if a collision is detected.\n */\nfunction handleGenerateId(\n\tstate: ShardingFuzzTestState,\n\top: GenerateIdOperation,\n): ShardingFuzzTestState {\n\tconst { compressor } = op;\n\n\tif (!state.activeCompressors.has(compressor)) {\n\t\tthrow new Error(\"Attempting to generate ID from disposed/inactive compressor\");\n\t}\n\n\tconst localId = compressor.generateCompressedId();\n\n\tif (state.globalLocalIds.has(localId)) {\n\t\tthrow new Error(\n\t\t\t`Local ID collision detected! ID ${localId} was already generated by another compressor.`,\n\t\t);\n\t}\n\tstate.globalLocalIds.add(localId);\n\n\tconst stableId = compressor.decompress(localId);\n\tif (state.globalStableIds.has(stableId)) {\n\t\tthrow new Error(\n\t\t\t`Stable ID collision detected! Stable ID ${stableId} (from local ID ${localId}) was already generated.`,\n\t\t);\n\t}\n\tstate.globalStableIds.add(stableId);\n\n\t// Track this ID for this compressor (compressor is always in the map when active)\n\tstate.compressorGeneratedIds.get(compressor)?.push(localId);\n\n\treturn state;\n}\n\n/**\n * Handles a validation operation.\n * For each compressor, verifies it can decompress all IDs in the range from -1 to its last generated ID.\n */\nfunction handleValidate(state: ShardingFuzzTestState): ShardingFuzzTestState {\n\tfor (const compressor of state.activeCompressors) {\n\t\tconst idsGenerated = state.compressorGeneratedIds.get(compressor);\n\t\tconst lastId = idsGenerated?.at(-1);\n\t\tif (lastId === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Local IDs are negative, so we iterate from -1 down to lastId (e.g., -20)\n\t\tfor (let id = -1; id >= lastId; id--) {\n\t\t\tconst localId = id as SessionSpaceCompressedId;\n\n\t\t\tif (!state.globalLocalIds.has(localId)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst stableId = compressor.decompress(localId);\n\t\t\t\tif (!state.globalStableIds.has(stableId)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Validation failed: Compressor decompressed ID ${localId} to unknown stable ID ${stableId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Validation failed: Compressor could not decompress ID ${localId} (last generated: ${lastId}): ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Every compressor must be able to decompress all IDs it has been synchronized with.\n\tfor (const compressor of state.activeCompressors) {\n\t\tconst syncedIds = state.synchronizedIds.get(compressor);\n\t\tif (syncedIds === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const localId of syncedIds) {\n\t\t\ttry {\n\t\t\t\tconst stableId = compressor.decompress(localId);\n\t\t\t\tif (!state.globalStableIds.has(stableId)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Validation failed: Compressor decompressed synchronized ID ${localId} to unknown stable ID ${stableId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Validation failed: Compressor could not decompress synchronized ID ${localId}: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Performs fuzz testing of sharding operations on an ID compressor.\n * @param generator - The operation generator\n * @param rootCompressor - The initial compressor to start the tree\n * @param seed - Random seed for reproducibility\n */\nfunction performShardingFuzzActions(\n\tgenerator: Generator<ShardingOperation, ShardingFuzzTestState>,\n\trootCompressor: IdCompressor,\n\tseed: number,\n): void {\n\tconst random = makeRandom(seed);\n\n\tconst initialState: ShardingFuzzTestState = {\n\t\trandom,\n\t\trootCompressor,\n\t\tparentMap: new Map([[rootCompressor, undefined]]),\n\t\tchildrenMap: new Map([[rootCompressor, new Set()]]),\n\t\tactiveCompressors: new Set([rootCompressor]),\n\t\tleafCompressors: new Set([rootCompressor]),\n\t\tcompressorGeneratedIds: new Map([[rootCompressor, []]]),\n\t\tsynchronizedIds: new Map([[rootCompressor, new Set()]]),\n\t\tglobalLocalIds: new Set(),\n\t\tglobalStableIds: new Set(),\n\t};\n\n\tconst handlers = {\n\t\tshard: handleShard,\n\t\tunshard: handleUnshard,\n\t\tsynchronize: handleSynchronize,\n\t\tgenerateId: handleGenerateId,\n\t\tvalidateSharding: handleValidate,\n\t};\n\n\tperformFuzzActionsBase(generator, handlers, initialState);\n}\n\ndescribe(\"IdCompressor Sharding Fuzz Tests\", () => {\n\tit(\"small fuzz test - basic correctness\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t200,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 2,\n\t\t\t\tunshardWeight: 2,\n\t\t\t\tgenerateIdWeight: 10,\n\t\t\t\tvalidateInterval: 50,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 42);\n\t});\n\n\tit(\"balanced fuzz test - equal sharding and unsharding\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t1000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 3,\n\t\t\t\tunshardWeight: 3,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 100,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 123);\n\t});\n\n\tit(\"large and deep fuzz test - heavy ID generation with deep sharding\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t5000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 2,\n\t\t\t\tunshardWeight: 10,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 200,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 456);\n\t});\n\n\tit(\"synchronization-heavy fuzz test - long-lived deep shards synchronized upward\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\t// High shard and low unshard weights keep trees deep and shards long-lived, while the high\n\t\t// synchronize weight drives many repeated, multi-ancestor synchronization steps.\n\t\tconst generator = take(\n\t\t\t3000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 5,\n\t\t\t\tunshardWeight: 1,\n\t\t\t\tsynchronizeWeight: 15,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 100,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 789);\n\t});\n});\n"]}
1
+ {"version":3,"file":"sharding.fuzz.spec.js","sourceRoot":"","sources":["../../src/test/sharding.fuzz.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,gFAS8C;AAE9C,wDAAkD;AAElD,gDAAyD;AACzD,kDAAkD;AA6ElD;;GAEG;AACH,SAAS,cAAc,CAAC,KAA4B;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,OAAO;QACN,IAAI,EAAE,OAAO;QACb,UAAU;QACV,SAAS;KACT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAA4B;IACrD,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;IAC1C,0CAA0C;IAC1C,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,cAAc,CAAC,CAAC;IAE3E,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,2DAA2D;QAC3D,OAAO;YACN,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,KAAK,CAAC,cAAc;SAC1B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAClD,OAAO;QACN,IAAI,EAAE,SAAS;QACf,IAAI;KACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAA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F,0BAA0B,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACvF,MAAM,SAAS,GAAG,IAAA,8BAAe,GAAE,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,8BAAY,CAAC,SAAS,EAAE,SAAS,EAAE,+BAAoB,CAAC,EAAE,CAAC,CAAC;QAC7E,2FAA2F;QAC3F,iFAAiF;QACjF,MAAM,SAAS,GAAG,IAAA,4BAAI,EACrB,IAAI,EACJ,uBAAuB,CAAC;YACvB,WAAW,EAAE,CAAC;YACd,aAAa,EAAE,CAAC;YAChB,iBAAiB,EAAE,EAAE;YACrB,gBAAgB,EAAE,EAAE;YACpB,gBAAgB,EAAE,GAAG;SACrB,CAAC,CACF,CAAC;QACF,0BAA0B,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype BaseFuzzTestState,\n\ttype Generator,\n\tcreateWeightedGenerator,\n\tinterleave,\n\tmakeRandom,\n\tperformFuzzActions as performFuzzActionsBase,\n\trepeat,\n\ttake,\n} from \"@fluid-private/stochastic-test-utils\";\n\nimport { IdCompressor } from \"../idCompressor.js\";\nimport type { SessionSpaceCompressedId, StableId } from \"../index.js\";\nimport { SerializationVersion } from \"../types/index.js\";\nimport { createSessionId } from \"../utilities.js\";\n\n/**\n * State for sharding fuzz tests.\n * Tracks a tree of compressors and all generated IDs for collision detection and validation.\n */\ninterface ShardingFuzzTestState extends BaseFuzzTestState {\n\t/** The root compressor that started the tree */\n\trootCompressor: IdCompressor;\n\t/** Map from compressor to its parent (undefined for root) */\n\tparentMap: Map<IdCompressor, IdCompressor | undefined>;\n\t/** Map from compressor to its children */\n\tchildrenMap: Map<IdCompressor, Set<IdCompressor>>;\n\t/** All active compressors (not disposed) */\n\tactiveCompressors: Set<IdCompressor>;\n\t/** Leaf compressors that can be unsharded */\n\tleafCompressors: Set<IdCompressor>;\n\t/** Map from compressor to all local IDs it has generated */\n\tcompressorGeneratedIds: Map<IdCompressor, SessionSpaceCompressedId[]>;\n\t/**\n\t * Map from compressor to the set of local IDs it has been synchronized with (and so must be able\n\t * to decompress) but did not itself generate. Populated by synchronize operations.\n\t */\n\tsynchronizedIds: Map<IdCompressor, Set<SessionSpaceCompressedId>>;\n\t/** Global set of all generated local IDs for collision detection */\n\tglobalLocalIds: Set<SessionSpaceCompressedId>;\n\t/** Global set of all decompressed stable IDs for collision detection */\n\tglobalStableIds: Set<StableId>;\n}\n\n/**\n * Operation to shard a compressor into multiple child shards.\n */\ninterface ShardOperation {\n\ttype: \"shard\";\n\tcompressor: IdCompressor;\n\tnumShards: number;\n}\n\n/**\n * Operation to unshard a leaf compressor back into its parent.\n */\ninterface UnshardOperation {\n\ttype: \"unshard\";\n\tleaf: IdCompressor;\n}\n\n/**\n * Operation to synchronize a child shard's progress into its parent without disposing the child.\n */\ninterface SynchronizeOperation {\n\ttype: \"synchronize\";\n\tchild: IdCompressor;\n}\n\n/**\n * Operation to generate a new compressed ID.\n */\ninterface GenerateIdOperation {\n\ttype: \"generateId\";\n\tcompressor: IdCompressor;\n}\n\n/**\n * Operation to validate the current state of all compressors.\n */\ninterface ValidateShardingOperation {\n\ttype: \"validateSharding\";\n}\n\ntype ShardingOperation =\n\t| ShardOperation\n\t| UnshardOperation\n\t| SynchronizeOperation\n\t| GenerateIdOperation\n\t| ValidateShardingOperation;\n\n/**\n * Generates a shard operation targeting a random active compressor.\n */\nfunction shardGenerator(state: ShardingFuzzTestState): ShardOperation {\n\tconst compressor = state.random.pick([...state.activeCompressors]);\n\tconst numShards = state.random.integer(1, 3);\n\treturn {\n\t\ttype: \"shard\",\n\t\tcompressor,\n\t\tnumShards,\n\t};\n}\n\n/**\n * Generates an unshard operation targeting a random leaf compressor.\n * If there are no leaves (only root), returns a no-op operation.\n */\nfunction unshardGenerator(state: ShardingFuzzTestState): UnshardOperation {\n\tconst leaves = [...state.leafCompressors];\n\t// Filter out root - it can't be unsharded\n\tconst unshardableLeaves = leaves.filter((l) => l !== state.rootCompressor);\n\n\tif (unshardableLeaves.length === 0) {\n\t\t// No-op: target root which will be filtered out in handler\n\t\treturn {\n\t\t\ttype: \"unshard\",\n\t\t\tleaf: state.rootCompressor,\n\t\t};\n\t}\n\n\tconst leaf = state.random.pick(unshardableLeaves);\n\treturn {\n\t\ttype: \"unshard\",\n\t\tleaf,\n\t};\n}\n\n/**\n * Generates a synchronize operation targeting a random non-root active compressor.\n * The selected compressor's parent will be synchronized with it.\n * If there are no non-root compressors, returns a no-op targeting the root (filtered out in the handler).\n */\nfunction synchronizeGenerator(state: ShardingFuzzTestState): SynchronizeOperation {\n\tconst children = [...state.activeCompressors].filter((c) => c !== state.rootCompressor);\n\tif (children.length === 0) {\n\t\t// No-op: target root which will be filtered out in the handler.\n\t\treturn {\n\t\t\ttype: \"synchronize\",\n\t\t\tchild: state.rootCompressor,\n\t\t};\n\t}\n\treturn {\n\t\ttype: \"synchronize\",\n\t\tchild: state.random.pick(children),\n\t};\n}\n\n/**\n * Generates an operation to generate a new ID from a random compressor.\n */\nfunction generateIdGenerator(state: ShardingFuzzTestState): GenerateIdOperation {\n\tconst compressor = state.random.pick([...state.activeCompressors]);\n\treturn {\n\t\ttype: \"generateId\",\n\t\tcompressor,\n\t};\n}\n\n/**\n * Generates a validation operation.\n */\nfunction validateGenerator(): ValidateShardingOperation {\n\treturn { type: \"validateSharding\" };\n}\n\n/**\n * Configuration for the sharding operation generator.\n */\ninterface ShardingOpGeneratorConfig {\n\t/** Weight for shard operations (default: 3) */\n\tshardWeight?: number;\n\t/** Weight for unshard operations (default: 3) */\n\tunshardWeight?: number;\n\t/** Weight for synchronize operations (default: 5) */\n\tsynchronizeWeight?: number;\n\t/** Weight for ID generation operations (default: 20) */\n\tgenerateIdWeight?: number;\n\t/** How often to inject validation operations (default: every 100 ops) */\n\tvalidateInterval?: number;\n}\n\n/**\n * Creates a weighted generator for sharding fuzz test operations.\n */\nfunction makeShardingOpGenerator(\n\tconfig: ShardingOpGeneratorConfig,\n): Generator<ShardingOperation, ShardingFuzzTestState> {\n\tconst {\n\t\tshardWeight = 3,\n\t\tunshardWeight = 3,\n\t\tsynchronizeWeight = 5,\n\t\tgenerateIdWeight = 20,\n\t\tvalidateInterval = 100,\n\t} = config;\n\n\treturn interleave(\n\t\tcreateWeightedGenerator<ShardingOperation, ShardingFuzzTestState>([\n\t\t\t[shardGenerator, shardWeight],\n\t\t\t[unshardGenerator, unshardWeight],\n\t\t\t[synchronizeGenerator, synchronizeWeight],\n\t\t\t[generateIdGenerator, generateIdWeight],\n\t\t]),\n\t\ttake(1, repeat<ShardingOperation, ShardingFuzzTestState>(validateGenerator())),\n\t\tvalidateInterval,\n\t);\n}\n\n/**\n * Handles a shard operation by creating new child shards and updating the tree structure.\n */\nfunction handleShard(state: ShardingFuzzTestState, op: ShardOperation): ShardingFuzzTestState {\n\tconst { compressor, numShards } = op;\n\n\tlet serializedShards: ReturnType<IdCompressor[\"shard\"]>;\n\ttry {\n\t\tserializedShards = compressor.shard(numShards);\n\t} catch (error) {\n\t\t// Sharding multiplies the stride; once it would exceed the supported maximum, shard() throws\n\t\t// before mutating any state. This is expected for sufficiently deep trees, so treat it as a no-op.\n\t\tif (error instanceof Error && error.message === \"Sharding limit reached.\") {\n\t\t\treturn state;\n\t\t}\n\t\tthrow error;\n\t}\n\n\tfor (const { serialized } of serializedShards) {\n\t\tconst shard = IdCompressor.deserialize({\n\t\t\tserialized,\n\t\t\trequestedWriteVersion: SerializationVersion.V3,\n\t\t});\n\n\t\t// Update tree structure\n\t\tstate.parentMap.set(shard, compressor);\n\n\t\tlet children = state.childrenMap.get(compressor);\n\t\tif (children === undefined) {\n\t\t\tchildren = new Set();\n\t\t\tstate.childrenMap.set(compressor, children);\n\t\t}\n\t\tchildren.add(shard);\n\n\t\tstate.childrenMap.set(shard, new Set());\n\t\tstate.activeCompressors.add(shard);\n\t\tstate.leafCompressors.add(shard);\n\t\tstate.compressorGeneratedIds.set(shard, []);\n\t\tstate.synchronizedIds.set(shard, new Set());\n\t}\n\n\t// Parent is no longer a leaf after sharding\n\tstate.leafCompressors.delete(compressor);\n\n\treturn state;\n}\n\n/**\n * Handles an unshard operation by disposing a leaf and merging it back into its parent.\n * No-op if the target is the root or not a leaf.\n */\nfunction handleUnshard(\n\tstate: ShardingFuzzTestState,\n\top: UnshardOperation,\n): ShardingFuzzTestState {\n\tconst { leaf } = op;\n\n\t// Can't unshard root or non-leaves\n\tif (leaf === state.rootCompressor || !state.leafCompressors.has(leaf)) {\n\t\treturn state;\n\t}\n\n\tconst parent = state.parentMap.get(leaf);\n\tif (parent === undefined) {\n\t\treturn state;\n\t}\n\n\tconst disposalToken = leaf.disposeShard();\n\tif (disposalToken === undefined) {\n\t\treturn state;\n\t}\n\n\tparent.synchronizeWithShard(disposalToken);\n\n\t// Update tree structure\n\tconst siblings = state.childrenMap.get(parent);\n\tif (siblings !== undefined) {\n\t\tsiblings.delete(leaf);\n\n\t\t// If parent has no more children, it becomes a leaf\n\t\tif (siblings.size === 0) {\n\t\t\tstate.leafCompressors.add(parent);\n\t\t}\n\t}\n\n\t// The disposed leaf's IDs become the parent's responsibility to decompress.\n\tconst parentSynced = state.synchronizedIds.get(parent) ?? new Set();\n\tfor (const id of state.compressorGeneratedIds.get(leaf) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tfor (const id of state.synchronizedIds.get(leaf) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tstate.synchronizedIds.set(parent, parentSynced);\n\n\tstate.parentMap.delete(leaf);\n\tstate.childrenMap.delete(leaf);\n\tstate.activeCompressors.delete(leaf);\n\tstate.leafCompressors.delete(leaf);\n\tstate.compressorGeneratedIds.delete(leaf);\n\tstate.synchronizedIds.delete(leaf);\n\n\treturn state;\n}\n\n/**\n * Handles a synchronize operation by synchronizing a child's parent with the child's current progress,\n * without disposing the child. After this, the parent must be able to decompress every ID the child has\n * generated (and every ID the child had itself been synchronized with) up to this point.\n * No-op if the target is the root or is otherwise no longer eligible.\n */\nfunction handleSynchronize(\n\tstate: ShardingFuzzTestState,\n\top: SynchronizeOperation,\n): ShardingFuzzTestState {\n\tconst { child } = op;\n\n\tif (child === state.rootCompressor || !state.activeCompressors.has(child)) {\n\t\treturn state;\n\t}\n\n\tconst parent = state.parentMap.get(child);\n\tif (parent === undefined || !state.activeCompressors.has(parent)) {\n\t\treturn state;\n\t}\n\n\tconst token = child.getShardSyncToken();\n\tif (token === undefined) {\n\t\treturn state;\n\t}\n\n\tparent.synchronizeWithShard(token);\n\n\t// Record everything the parent must now be able to decompress: the child's own generated IDs plus\n\t// whatever the child had previously been synchronized with (this models upward propagation, since\n\t// the child's gen count was advanced past those IDs when it synchronized with its own children).\n\tlet parentSynced = state.synchronizedIds.get(parent);\n\tif (parentSynced === undefined) {\n\t\tparentSynced = new Set();\n\t\tstate.synchronizedIds.set(parent, parentSynced);\n\t}\n\tfor (const id of state.compressorGeneratedIds.get(child) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\tfor (const id of state.synchronizedIds.get(child) ?? []) {\n\t\tparentSynced.add(id);\n\t}\n\n\treturn state;\n}\n\n/**\n * Handles an ID generation operation.\n * Generates a new ID and checks for collisions in both local ID space and stable ID space.\n * Fails immediately if a collision is detected.\n */\nfunction handleGenerateId(\n\tstate: ShardingFuzzTestState,\n\top: GenerateIdOperation,\n): ShardingFuzzTestState {\n\tconst { compressor } = op;\n\n\tif (!state.activeCompressors.has(compressor)) {\n\t\tthrow new Error(\"Attempting to generate ID from disposed/inactive compressor\");\n\t}\n\n\tconst localId = compressor.generateCompressedId();\n\n\tif (state.globalLocalIds.has(localId)) {\n\t\tthrow new Error(\n\t\t\t`Local ID collision detected! ID ${localId} was already generated by another compressor.`,\n\t\t);\n\t}\n\tstate.globalLocalIds.add(localId);\n\n\tconst stableId = compressor.decompress(localId);\n\tif (state.globalStableIds.has(stableId)) {\n\t\tthrow new Error(\n\t\t\t`Stable ID collision detected! Stable ID ${stableId} (from local ID ${localId}) was already generated.`,\n\t\t);\n\t}\n\tstate.globalStableIds.add(stableId);\n\n\t// Track this ID for this compressor (compressor is always in the map when active)\n\tstate.compressorGeneratedIds.get(compressor)?.push(localId);\n\n\treturn state;\n}\n\n/**\n * Handles a validation operation.\n * For each compressor, verifies it can decompress all IDs in the range from -1 to its last generated ID.\n */\nfunction handleValidate(state: ShardingFuzzTestState): ShardingFuzzTestState {\n\tfor (const compressor of state.activeCompressors) {\n\t\tconst idsGenerated = state.compressorGeneratedIds.get(compressor);\n\t\tconst lastId = idsGenerated?.at(-1);\n\t\tif (lastId === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Local IDs are negative, so we iterate from -1 down to lastId (e.g., -20)\n\t\tfor (let id = -1; id >= lastId; id--) {\n\t\t\tconst localId = id as SessionSpaceCompressedId;\n\n\t\t\tif (!state.globalLocalIds.has(localId)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst stableId = compressor.decompress(localId);\n\t\t\t\tif (!state.globalStableIds.has(stableId)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Validation failed: Compressor decompressed ID ${localId} to unknown stable ID ${stableId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Validation failed: Compressor could not decompress ID ${localId} (last generated: ${lastId}): ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Every compressor must be able to decompress all IDs it has been synchronized with.\n\tfor (const compressor of state.activeCompressors) {\n\t\tconst syncedIds = state.synchronizedIds.get(compressor);\n\t\tif (syncedIds === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const localId of syncedIds) {\n\t\t\ttry {\n\t\t\t\tconst stableId = compressor.decompress(localId);\n\t\t\t\tif (!state.globalStableIds.has(stableId)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Validation failed: Compressor decompressed synchronized ID ${localId} to unknown stable ID ${stableId}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Validation failed: Compressor could not decompress synchronized ID ${localId}: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Performs fuzz testing of sharding operations on an ID compressor.\n * @param generator - The operation generator\n * @param rootCompressor - The initial compressor to start the tree\n * @param seed - Random seed for reproducibility\n */\nfunction performShardingFuzzActions(\n\tgenerator: Generator<ShardingOperation, ShardingFuzzTestState>,\n\trootCompressor: IdCompressor,\n\tseed: number,\n): void {\n\tconst random = makeRandom(seed);\n\n\tconst initialState: ShardingFuzzTestState = {\n\t\trandom,\n\t\trootCompressor,\n\t\tparentMap: new Map([[rootCompressor, undefined]]),\n\t\tchildrenMap: new Map([[rootCompressor, new Set()]]),\n\t\tactiveCompressors: new Set([rootCompressor]),\n\t\tleafCompressors: new Set([rootCompressor]),\n\t\tcompressorGeneratedIds: new Map([[rootCompressor, []]]),\n\t\tsynchronizedIds: new Map([[rootCompressor, new Set()]]),\n\t\tglobalLocalIds: new Set(),\n\t\tglobalStableIds: new Set(),\n\t};\n\n\tconst handlers = {\n\t\tshard: handleShard,\n\t\tunshard: handleUnshard,\n\t\tsynchronize: handleSynchronize,\n\t\tgenerateId: handleGenerateId,\n\t\tvalidateSharding: handleValidate,\n\t};\n\n\tperformFuzzActionsBase(generator, handlers, initialState);\n}\n\ndescribe(\"IdCompressor Sharding Fuzz Tests\", () => {\n\tit(\"small fuzz test - basic correctness\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t200,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 2,\n\t\t\t\tunshardWeight: 2,\n\t\t\t\tgenerateIdWeight: 10,\n\t\t\t\tvalidateInterval: 50,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 42);\n\t});\n\n\tit(\"balanced fuzz test - equal sharding and unsharding\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t1000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 3,\n\t\t\t\tunshardWeight: 3,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 100,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 123);\n\t});\n\n\tit(\"large and deep fuzz test - heavy ID generation with deep sharding\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\tconst generator = take(\n\t\t\t5000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 2,\n\t\t\t\tunshardWeight: 10,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 200,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 456);\n\t});\n\n\tit(\"synchronization-heavy fuzz test - long-lived deep shards synchronized upward\", () => {\n\t\tconst sessionId = createSessionId();\n\t\tconst root = new IdCompressor(sessionId, undefined, SerializationVersion.V3);\n\t\t// High shard and low unshard weights keep trees deep and shards long-lived, while the high\n\t\t// synchronize weight drives many repeated, multi-ancestor synchronization steps.\n\t\tconst generator = take(\n\t\t\t3000,\n\t\t\tmakeShardingOpGenerator({\n\t\t\t\tshardWeight: 5,\n\t\t\t\tunshardWeight: 1,\n\t\t\t\tsynchronizeWeight: 15,\n\t\t\t\tgenerateIdWeight: 20,\n\t\t\t\tvalidateInterval: 100,\n\t\t\t}),\n\t\t);\n\t\tperformShardingFuzzActions(generator, root, 789);\n\t});\n});\n"]}