@fluid-experimental/tree 2.72.0 → 2.74.0-365691
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.
- package/.eslintrc.cjs +0 -9
- package/CHANGELOG.md +4 -0
- package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
- package/dist/id-compressor/IdCompressor.js +6 -0
- package/dist/id-compressor/IdCompressor.js.map +1 -1
- package/dist/id-compressor/SessionIdNormalizer.d.ts.map +1 -1
- package/dist/id-compressor/SessionIdNormalizer.js +1 -0
- package/dist/id-compressor/SessionIdNormalizer.js.map +1 -1
- package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
- package/lib/id-compressor/IdCompressor.js +6 -0
- package/lib/id-compressor/IdCompressor.js.map +1 -1
- package/lib/id-compressor/SessionIdNormalizer.d.ts.map +1 -1
- package/lib/id-compressor/SessionIdNormalizer.js +1 -0
- package/lib/id-compressor/SessionIdNormalizer.js.map +1 -1
- package/package.json +24 -24
- package/src/id-compressor/IdCompressor.ts +6 -0
- package/src/id-compressor/SessionIdNormalizer.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionIdNormalizer.d.ts","sourceRoot":"","sources":["../../src/id-compressor/SessionIdNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAGnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,mBAAmB,CAAC,YAAY;IAkBzB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAjBpD,OAAO,CAAC,WAAW,CAA8C;IACjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAcvB;gBAEkC,gBAAgB,UAAQ;IAE5D;;;OAGG;IACI,iBAAiB,CAAC,OAAO,E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BG;IACI,WAAW,CAAC,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,YAAY,GAAG,IAAI;IAuChH;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACI,oBAAoB,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,GAAG,IAAI;IAmBjH,OAAO,CAAC,uBAAuB;IAwB/B;;OAEG;IACK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,wBAAwB,CAAC;IAwBhE,SAAS,IAAI,6BAA6B;WAqBnC,WAAW,CAAC,YAAY,EACrC,UAAU,EAAE,6BAA6B,EACzC,cAAc,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,YAAY,GAC1D,mBAAmB,CAAC,YAAY,CAAC;IAuB7B,MAAM,CACZ,KAAK,EAAE,mBAAmB,CAAC,YAAY,CAAC,EACxC,mBAAmB,GAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,KAAK,OAA2B,GACpF,OAAO;CA6BV"}
|
|
@@ -116,6 +116,7 @@ class SessionIdNormalizer {
|
|
|
116
116
|
const [alignedLocal, [firstFinal, lastFinal]] = finalRange;
|
|
117
117
|
if (finalId <= lastFinal) {
|
|
118
118
|
const finalDelta = finalId - firstFinal;
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
119
120
|
return -alignedLocal - 1 + finalDelta;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionIdNormalizer.js","sourceRoot":"","sources":["../../src/id-compressor/SessionIdNormalizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,4CAAiG;AAGjG,qEAAqE;AAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,mBAAmB;IAkB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,WAAW,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,QAAQ,CAAC,CAAC,OAAO,CAChB,UAA6B,EAC7B,WAAkD;IAElD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;gBAC3C,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { Mutable, compareFiniteNumbers, compareFiniteNumbersReversed, fail } from '../Common.js';\nimport { FinalCompressedId, LocalCompressedId, SessionSpaceCompressedId } from '../Identifiers.js';\n\nimport { AppendOnlyDoublySortedMap } from './AppendOnlySortedMap.js';\nimport { SerializedSessionIdNormalizer } from './persisted-types/index.js';\n\n/**\n * Maps IDs created by a session between their local and final forms (i.e. normalization). These IDs are in a contiguous range.\n * The local and final forms of IDs made by a session can be thought of as two equal-length sparse arrays, aligned such\n * that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.\n * Below is an example to illustrate how various mappings can arise:\n *\n * ```\n * +- Creation Index\n * / +- Locals\n * / / +- Finals\n * / / /\n * ---+-----+----\n * 0 | -1 | 0 -|___ Two IDs are allocated as locals since no cluster exists. A new cluster is created when acked.\n * 1 | -2 | 1 -|\n * 2 | | 2 -|\n * 3 | | 3 --|-- Three more IDs are allocated as finals eagerly since a cluster exists with available capacity.\n * 4 | | 4 -|\n * 5 | -6 | 10 ----- One ID is allocated as a local (it overflows the existing cluster) and a new cluster is created after ack.\n * 6 | | 11 ----- One ID is allocated as a final eagerly into the existing cluster.\n * 7 | -8 | 12 ----- A local ID with an override is allocated. The override forces it to be a local ID.\n * 8 | | 13\n * 9 | | 14\n * 10 | -11 | ----- A local ID is allocated. It has no corresponding final ID since it has not been acked.\n * ```\n *\n * Note that in this example, some IDs (those at indices 2, 3, 4, 6, 8, and 9) have no local form. The ID at index 10 has no final form.\n * These kinds of \"gaps\" occur due to the timing of allocation calls on the client and how they relate to finalization/cluster creation,\n * which depends on receiving an ack/sequence number from the server. Given this context, \"session space\" can be thought of as:\n *\n * ```\n * for each index in the range of IDs created by a session:\n * \tthe local form if it exists, otherwise the final form\n * ```\n *\n * This class is designed to efficiently build and query these mappings by leveraging the facts that much of the range (in both local and\n * final space) is uninterrupted by \"gaps\" and can be compactly represented by a (first, last) pair and is easily binary searched for\n * normalization between local and final space.\n */\nexport class SessionIdNormalizer<TRangeObject> {\n\tprivate nextLocalId: LocalCompressedId = -1 as LocalCompressedId;\n\tprivate readonly idRanges: AppendOnlyDoublySortedMap<\n\t\tLocalCompressedId,\n\t\t[lastLocal: LocalCompressedId, finalRanges: FinalRanges<TRangeObject> | undefined],\n\t\tFinalCompressedId\n\t> = new AppendOnlyDoublySortedMap(\n\t\tcompareFiniteNumbersReversed,\n\t\t([_, finalRanges]) => {\n\t\t\tif (finalRanges !== undefined) {\n\t\t\t\tconst first = getFirstRange(finalRanges);\n\t\t\t\treturn extractFirstFinalFromRange(first);\n\t\t\t}\n\t\t\treturn Number.POSITIVE_INFINITY as FinalCompressedId;\n\t\t},\n\t\tcompareFiniteNumbers\n\t);\n\n\tpublic constructor(private readonly expensiveAsserts = false) {}\n\n\t/**\n\t * Converts the final ID to its session-space representation.\n\t * This will be the corresponding local if a local form exists, and `finalId` otherwise.\n\t */\n\tpublic getSessionSpaceId(finalId: FinalCompressedId): SessionSpaceCompressedId | undefined {\n\t\tconst localRange = this.idRanges.getPairOrNextLowerByValue(finalId);\n\t\tif (localRange !== undefined) {\n\t\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\t\tconst finalRange = getPairOrNextLowerByValue(firstLocal, finalRanges, finalId);\n\t\t\tif (finalRange !== undefined) {\n\t\t\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\t\t\tif (finalId <= lastFinal) {\n\t\t\t\t\tconst localRangeDelta = alignedLocal - lastLocal;\n\t\t\t\t\tconst finalDelta = finalId - firstFinal;\n\t\t\t\t\tif (finalDelta <= localRangeDelta) {\n\t\t\t\t\t\treturn (alignedLocal - finalDelta) as LocalCompressedId;\n\t\t\t\t\t}\n\t\t\t\t\t// `finalId` was an eagerly generated final ID\n\t\t\t\t\treturn finalId as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Converts the local ID to its corresponding final ID, if one exists.\n\t */\n\tpublic getFinalId(localId: LocalCompressedId): [FinalCompressedId, TRangeObject] | undefined {\n\t\tconst localRange =\n\t\t\tthis.idRanges.getPairOrNextLower(localId) ?? fail('Local ID was never recorded with this normalizer.');\n\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\tif (localId < lastLocal) {\n\t\t\tfail('Local ID was never recorded with this normalizer.');\n\t\t}\n\t\tconst finalRange = getPairOrNextLower(firstLocal, finalRanges, localId);\n\t\tif (finalRange !== undefined) {\n\t\t\tconst [alignedLocal, [firstFinal, lastFinal, rangeObject]] = finalRange;\n\t\t\tconst rangeDelta = lastFinal - firstFinal;\n\t\t\tconst localDelta = alignedLocal - localId;\n\t\t\tif (localDelta <= rangeDelta) {\n\t\t\t\t// Local is within a range segment that has a corresponding final\n\t\t\t\treturn [(firstFinal + localDelta) as FinalCompressedId, rangeObject];\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Returns the index of the local ID corresponding to the supplied final ID in the total range of IDs created by the session,\n\t * if the ID was created by the session for this `SessionIdNormalizer`.\n\t */\n\tpublic getCreationIndex(finalId: FinalCompressedId): number | undefined {\n\t\tconst localRange = this.idRanges.getPairOrNextLowerByValue(finalId);\n\t\tif (localRange !== undefined) {\n\t\t\tconst [firstLocal, [_, finalRanges]] = localRange;\n\t\t\tconst finalRange = getPairOrNextLowerByValue(firstLocal, finalRanges, finalId);\n\t\t\tif (finalRange !== undefined) {\n\t\t\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\t\t\tif (finalId <= lastFinal) {\n\t\t\t\t\tconst finalDelta = finalId - firstFinal;\n\t\t\t\t\treturn -alignedLocal - 1 + finalDelta;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Returns the session-space ID at the supplied creation index, if one exists.\n\t */\n\tpublic getIdByCreationIndex(index: number): SessionSpaceCompressedId | undefined {\n\t\tconst localByIndex = -(index + 1) as LocalCompressedId;\n\t\tconst localRange = this.idRanges.getPairOrNextLower(localByIndex);\n\t\tif (localRange === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\tif (localByIndex >= lastLocal) {\n\t\t\treturn localByIndex;\n\t\t}\n\t\tconst finalRange =\n\t\t\tgetPairOrNextLower(firstLocal, finalRanges, localByIndex) ??\n\t\t\tfail('Final ranges not aligned with owning local range.');\n\n\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\tconst localDelta = alignedLocal - localByIndex;\n\t\tconst finalId = firstFinal + localDelta;\n\t\tif (finalId <= lastFinal) {\n\t\t\t// `finalId` was an eagerly generated final ID\n\t\t\treturn finalId as SessionSpaceCompressedId;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate static makeFinalRangesMap<TRangeObject>(): FinalRangesMap<TRangeObject> {\n\t\treturn new AppendOnlyDoublySortedMap(\n\t\t\tcompareFiniteNumbersReversed,\n\t\t\textractFirstFinalFromRange,\n\t\t\tcompareFiniteNumbers\n\t\t);\n\t}\n\n\t/**\n\t * Returns the last final ID known to this normalizer.\n\t */\n\tpublic getLastFinalId(): FinalCompressedId | undefined {\n\t\tconst lastIndex = this.idRanges.size - 1;\n\t\tconst secondToLast = Math.max(0, lastIndex - 1);\n\t\tfor (let i = lastIndex; i >= secondToLast; i--) {\n\t\t\tconst localRange = this.idRanges.getAtIndex(i);\n\t\t\tif (localRange !== undefined) {\n\t\t\t\tconst finalRanges = localRange[1][1];\n\t\t\t\tif (finalRanges !== undefined) {\n\t\t\t\t\treturn getLastRange(finalRanges)[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Registers and returns the next ID in local space with this normalizer. An example:\n\t *\n\t * Locals: [-1, -2, X, X]\n\t * Finals: [ 0, 1, 2, 3]\n\t * In this scenario, a call to this method would generate and return -5.\n\t */\n\tpublic addLocalId(): LocalCompressedId {\n\t\tconst localId = this.nextLocalId-- as LocalCompressedId;\n\t\tconst lastLocalRange = this.idRanges.last();\n\t\tif (lastLocalRange !== undefined) {\n\t\t\tconst lastLocal = lastLocalRange[1][0];\n\t\t\tif (localId === lastLocal - 1) {\n\t\t\t\t// New local simply expands the last local range tracked\n\t\t\t\tlastLocalRange[1][0] = localId;\n\t\t\t\treturn localId;\n\t\t\t}\n\t\t}\n\n\t\tif (this.expensiveAsserts) {\n\t\t\tif (lastLocalRange === undefined) {\n\t\t\t\tassert(localId === -1, 0x657 /* Local ID space must start at -1. */);\n\t\t\t} else {\n\t\t\t\tconst [firstLocal, [_, finalRanges]] = lastLocalRange;\n\t\t\t\tlet finalDelta = 0;\n\t\t\t\tfor (const [_, [firstFinal, lastFinal]] of entries(firstLocal, finalRanges)) {\n\t\t\t\t\tfinalDelta += lastFinal - firstFinal + 1;\n\t\t\t\t}\n\t\t\t\tassert(localId === firstLocal - finalDelta, 0x658 /* Local ID space must be contiguous. */);\n\t\t\t}\n\t\t}\n\n\t\tthis.idRanges.append(localId, [localId, undefined]);\n\t\treturn localId;\n\t}\n\n\t/**\n\t * Registers one or more final IDs with this normalizer.\n\t * If there are any local IDs at the tip of session-space that do not have a corresponding final, they will be registered (aligned)\n\t * starting with the first of those. Otherwise, will be registered as the next ID in session space in creation order.\n\t *\n\t * An example:\n\t * Locals: [-1, -2, X, -4]\n\t * Finals: [ 0, 1, 2, X]\n\t * Calling `addFinalIds` with first === last === 5 results in the following:\n\t * Locals: [-1, -2, X, -4]\n\t * Finals: [ 0, 1, 2, 5]\n\t * Subsequently calling `addFinalIds` with first === last === 6 results in the following:\n\t * Locals: [-1, -2, X, -4, X]\n\t * Finals: [ 0, 1, 2, 5, 6]\n\t *\n\t * Non-contiguous final IDs (i.e. the first final after a \"gap\" in final space) must always correspond to a local ID. For example,\n\t * in the final call to `addFinalIds` above would fail if first === last === 9, because the resulting state would have a\n\t * non-contiguous final ID without a local form:\n\t * Locals: [-1, -2, X, -4, X]\n\t * Finals: [ 0, 1, 2, 5, 9]\n\t *\n\t * ^final ID 9 is not contiguous and does not have a corresponding local ID\n\t */\n\tpublic addFinalIds(firstFinal: FinalCompressedId, lastFinal: FinalCompressedId, rangeObject: TRangeObject): void {\n\t\tassert(lastFinal >= firstFinal, 0x659 /* Malformed normalization range. */);\n\t\tconst [firstLocal, finalRangesObj] =\n\t\t\tthis.idRanges.last() ?? fail('Final IDs must be added to an existing local range.');\n\t\tconst [lastLocal, finalRanges] = finalRangesObj;\n\t\tlet nextLocal: LocalCompressedId;\n\t\tif (finalRanges === undefined) {\n\t\t\tfinalRangesObj[1] = [firstFinal, lastFinal, rangeObject];\n\t\t\tnextLocal = Math.min(this.nextLocalId, firstLocal - (lastFinal - firstFinal) - 1) as LocalCompressedId;\n\t\t} else {\n\t\t\tconst [firstAlignedLocal, lastAlignedLocal, lastAlignedFinal, lastFinalRange] = this.getAlignmentOfLastRange(\n\t\t\t\tfirstLocal,\n\t\t\t\tfinalRanges\n\t\t\t);\n\t\t\tnextLocal = Math.min(this.nextLocalId, lastAlignedLocal - (lastFinal - firstFinal) - 2) as LocalCompressedId;\n\t\t\tif (firstFinal === lastAlignedFinal + 1) {\n\t\t\t\tlastFinalRange[1] = lastFinal;\n\t\t\t} else {\n\t\t\t\tconst alignedLocal = (lastAlignedLocal - 1) as LocalCompressedId;\n\t\t\t\tlet rangeMap: FinalRangesMap<TRangeObject>;\n\t\t\t\tif (isSingleRange(finalRanges)) {\n\t\t\t\t\t// Convert the single range to a range collection\n\t\t\t\t\trangeMap = SessionIdNormalizer.makeFinalRangesMap();\n\t\t\t\t\trangeMap.append(firstAlignedLocal, lastFinalRange);\n\t\t\t\t\tfinalRangesObj[1] = rangeMap;\n\t\t\t\t} else {\n\t\t\t\t\trangeMap = finalRanges;\n\t\t\t\t}\n\t\t\t\trangeMap.append(alignedLocal, [firstFinal, lastFinal, rangeObject]);\n\t\t\t\tassert(alignedLocal >= lastLocal, 0x65a /* Gaps in final space must align to a local. */);\n\t\t\t}\n\t\t\tif (this.expensiveAsserts) {\n\t\t\t\tthis.idRanges.assertValid();\n\t\t\t}\n\t\t}\n\n\t\tthis.nextLocalId = nextLocal;\n\t}\n\n\t/**\n\t * Alerts the normalizer to the existence of a block of final IDs that are *allocated* (but may not be entirely used).\n\t *\n\t * The normalizer may have unaligned (unfinalized) local IDs; any such outstanding locals will be eagerly aligned with\n\t * as many finals from the registered block as possible.\n\t *\n\t * It is important to register blocks via this method as soon as they are created for future eager final generations to be utilized, as such\n\t * generation is dependant on the normalizer being up-to-date with which local IDs have been aligned with finals. If, for instance,\n\t * a block of finals is not immediately registered with the normalizer and there are outstanding locals that would have aligned with them,\n\t * those locals will not be finalized until their creation range is finalized, which could be later if the block was created by an earlier\n\t * creation range's finalization but is large enough to span them both. In this scenario, no eager finals can be generated until the second\n\t * creation range is finalized.\n\t *\n\t * A usage example:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, X, X, X]\n\t * Calling `registerFinalIdBlock` with firstFinalInBlock === 5 and count === 10 results in the following:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, 5, 6, 7]\n\t * Instead calling `registerFinalIdBlock` with firstFinalInBlock === 5 and count === 2 results in the following:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, 5, 6, X]\n\t *\n\t */\n\tpublic registerFinalIdBlock(firstFinalInBlock: FinalCompressedId, count: number, rangeObject: TRangeObject): void {\n\t\tassert(count >= 1, 0x65b /* Malformed normalization block. */);\n\t\tconst [firstLocal, [lastLocal, finalRanges]] =\n\t\t\tthis.idRanges.last() ?? fail('Final ID block should not be registered before any locals.');\n\t\tlet unalignedLocalCount: number;\n\t\tif (finalRanges === undefined) {\n\t\t\tunalignedLocalCount = firstLocal - lastLocal + 1;\n\t\t} else {\n\t\t\tconst [_, lastAlignedLocal] = this.getAlignmentOfLastRange(firstLocal, finalRanges);\n\t\t\tunalignedLocalCount = lastAlignedLocal - lastLocal;\n\t\t}\n\t\tassert(\n\t\t\tunalignedLocalCount > 0,\n\t\t\t0x65c /* Final ID block should not be registered without an existing local range. */\n\t\t);\n\t\tconst lastFinal = (firstFinalInBlock + Math.min(unalignedLocalCount, count) - 1) as FinalCompressedId;\n\t\tthis.addFinalIds(firstFinalInBlock, lastFinal, rangeObject);\n\t}\n\n\tprivate getAlignmentOfLastRange(\n\t\tfirstLocal: LocalCompressedId,\n\t\tfinalRanges: FinalRanges<TRangeObject>\n\t): [\n\t\tfirstAlignedLocal: LocalCompressedId,\n\t\tlastAlignedLocal: LocalCompressedId,\n\t\tlastAlignedFinal: FinalCompressedId,\n\t\tlastFinalRange: FinalRange<TRangeObject>,\n\t] {\n\t\tconst isSingle = isSingleRange(finalRanges);\n\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\tlet firstAlignedLocal: LocalCompressedId;\n\t\tif (isSingle) {\n\t\t\tfirstAlignedLocal = firstLocal;\n\t\t\tlastFinalRange = finalRanges;\n\t\t} else {\n\t\t\t[firstAlignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t}\n\n\t\tconst [firstAlignedFinal, lastAlignedFinal] = lastFinalRange;\n\t\tconst lastAlignedLocal = firstAlignedLocal - (lastAlignedFinal - firstAlignedFinal);\n\t\treturn [firstAlignedLocal, lastAlignedLocal as LocalCompressedId, lastAlignedFinal, lastFinalRange];\n\t}\n\n\t/**\n\t * Returns an enumerable of all session-space IDs known to this normalizer, in creation order.\n\t */\n\tpublic *[Symbol.iterator](): IterableIterator<SessionSpaceCompressedId> {\n\t\tfor (const [firstLocal, [lastLocal, finalRanges]] of this.idRanges.entries()) {\n\t\t\tfor (let i = firstLocal; i >= lastLocal; i--) {\n\t\t\t\tyield i;\n\t\t\t}\n\t\t\tif (finalRanges !== undefined) {\n\t\t\t\t// Safe to get only the last final range, as all others must have corresponding locals (see `addFinalIds` docs)\n\t\t\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\t\t\tlet alignedLocal: LocalCompressedId;\n\t\t\t\tif (isSingleRange(finalRanges)) {\n\t\t\t\t\talignedLocal = firstLocal;\n\t\t\t\t\tlastFinalRange = finalRanges;\n\t\t\t\t} else {\n\t\t\t\t\t[alignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t\t\t}\n\t\t\t\tconst [firstFinal, lastFinal] = lastFinalRange;\n\t\t\t\tconst localRangeDelta = alignedLocal - lastLocal;\n\t\t\t\tfor (let i = firstFinal + localRangeDelta + 1; i <= lastFinal; i++) {\n\t\t\t\t\tyield i as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic serialize(): SerializedSessionIdNormalizer {\n\t\tconst serialized: Mutable<SerializedSessionIdNormalizer> = {\n\t\t\tlocalRanges: [],\n\t\t\tnextLocalId: this.nextLocalId,\n\t\t};\n\t\tconst localRanges = serialized.localRanges as Mutable<typeof serialized.localRanges>;\n\t\tfor (const [firstLocal, finalRanges] of this.idRanges.entries()) {\n\t\t\tconst [lastLocal, finalRangesTable] = finalRanges;\n\t\t\tif (finalRangesTable !== undefined) {\n\t\t\t\tconst serializedFinalRanges: [LocalCompressedId, FinalCompressedId, FinalCompressedId][] = [];\n\t\t\t\tfor (const [alignedLocal, [firstFinal, lastFinal]] of entries(firstLocal, finalRangesTable)) {\n\t\t\t\t\tserializedFinalRanges.push([alignedLocal, firstFinal, lastFinal]);\n\t\t\t\t}\n\t\t\t\tlocalRanges.push([firstLocal, lastLocal, serializedFinalRanges]);\n\t\t\t} else {\n\t\t\t\tlocalRanges.push([firstLocal, lastLocal]);\n\t\t\t}\n\t\t}\n\t\treturn serialized;\n\t}\n\n\tpublic static deserialize<TRangeObject>(\n\t\tserialized: SerializedSessionIdNormalizer,\n\t\tgetRangeObject: (finalId: FinalCompressedId) => TRangeObject\n\t): SessionIdNormalizer<TRangeObject> {\n\t\tconst normalizer = new SessionIdNormalizer<TRangeObject>();\n\t\tconst { idRanges } = normalizer;\n\t\tfor (const [firstLocal, lastLocal, serializedFinalRanges] of serialized.localRanges) {\n\t\t\tlet finalRanges: FinalRanges<TRangeObject> | undefined;\n\t\t\tif (serializedFinalRanges !== undefined) {\n\t\t\t\tassert(serializedFinalRanges.length !== 0, 0x65d /* Empty range should not be reified. */);\n\t\t\t\tif (serializedFinalRanges.length === 1) {\n\t\t\t\t\tconst [_, firstFinal, lastFinal] = serializedFinalRanges[0];\n\t\t\t\t\tfinalRanges = [firstFinal, lastFinal, getRangeObject(firstFinal)];\n\t\t\t\t} else {\n\t\t\t\t\tfinalRanges = SessionIdNormalizer.makeFinalRangesMap<TRangeObject>();\n\t\t\t\t\tfor (const [alignedLocal, firstFinal, lastFinal] of serializedFinalRanges) {\n\t\t\t\t\t\tfinalRanges.append(alignedLocal, [firstFinal, lastFinal, getRangeObject(firstFinal)]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tidRanges.append(firstLocal, [lastLocal, finalRanges]);\n\t\t}\n\t\tnormalizer.nextLocalId = serialized.nextLocalId;\n\t\treturn normalizer;\n\t}\n\n\tpublic equals(\n\t\tother: SessionIdNormalizer<TRangeObject>,\n\t\tcompareRangeObjects: (a: TRangeObject, b: TRangeObject) => boolean = (a, b) => a === b\n\t): boolean {\n\t\treturn (\n\t\t\tthis.nextLocalId === other.nextLocalId &&\n\t\t\tthis.idRanges.equals(other.idRanges, (localRangeA, localRangeB) => {\n\t\t\t\tconst [lastLocalA, finalRangesA] = localRangeA;\n\t\t\t\tconst [lastLocalB, finalRangesB] = localRangeB;\n\t\t\t\tif (finalRangesA === undefined || finalRangesB === undefined) {\n\t\t\t\t\treturn finalRangesA === finalRangesB;\n\t\t\t\t}\n\n\t\t\t\tconst rangeEquals = (finalRangeA: FinalRange<TRangeObject>, finalRangeB: FinalRange<TRangeObject>) => {\n\t\t\t\t\tconst [firstFinalA, lastFinalA, rangeObjectA] = finalRangeA;\n\t\t\t\t\tconst [firstFinalB, lastFinalB, rangeObjectB] = finalRangeB;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tfirstFinalA === firstFinalB && lastFinalA === lastFinalB && compareRangeObjects(rangeObjectA, rangeObjectB)\n\t\t\t\t\t);\n\t\t\t\t};\n\n\t\t\t\tif (isSingleRange(finalRangesA) || isSingleRange(finalRangesB)) {\n\t\t\t\t\tif (!isSingleRange(finalRangesA) || !isSingleRange(finalRangesB)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn rangeEquals(finalRangesA, finalRangesB);\n\t\t\t\t}\n\n\t\t\t\treturn lastLocalA === lastLocalB && finalRangesA.equals(finalRangesB, rangeEquals);\n\t\t\t})\n\t\t);\n\t}\n}\n\ntype FinalRange<TRangeObject> = [\n\tfirstFinal: FinalCompressedId,\n\tlastFinal: FinalCompressedId,\n\trangeObject: TRangeObject,\n];\n\ntype FinalRangesMap<TRangeObject> = AppendOnlyDoublySortedMap<\n\tLocalCompressedId,\n\tFinalRange<TRangeObject>,\n\tFinalCompressedId\n>;\n\ntype FinalRanges<TRangeObject> = FinalRange<TRangeObject> | FinalRangesMap<TRangeObject>;\n\nfunction isSingleRange<TRangeObject>(ranges: FinalRanges<TRangeObject>): ranges is FinalRange<TRangeObject> {\n\treturn Array.isArray(ranges);\n}\n\nfunction getLastRange<TRangeObject>(finalRanges: FinalRanges<TRangeObject>): FinalRange<TRangeObject> {\n\tif (isSingleRange(finalRanges)) {\n\t\treturn finalRanges;\n\t}\n\treturn (finalRanges.last() ?? fail('Map must be non-empty'))[1];\n}\n\nfunction getFirstRange<TRangeObject>(finalRanges: FinalRanges<TRangeObject>): FinalRange<TRangeObject> {\n\tif (isSingleRange(finalRanges)) {\n\t\treturn finalRanges;\n\t}\n\treturn (finalRanges.first() ?? fail('Map must be non-empty'))[1];\n}\n\nfunction extractFirstFinalFromRange<TRangeObject>(finalRange: FinalRange<TRangeObject>): FinalCompressedId {\n\treturn finalRange[0];\n}\n\nfunction getPairOrNextLowerByValue<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined,\n\tfinalId: FinalCompressedId\n): readonly [LocalCompressedId, FinalRange<TRangeObject>] | undefined {\n\tif (finalRanges === undefined) {\n\t\treturn undefined;\n\t}\n\tif (isSingleRange(finalRanges)) {\n\t\tif (finalId < finalRanges[0]) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [firstLocal, finalRanges];\n\t}\n\treturn finalRanges.getPairOrNextLowerByValue(finalId);\n}\n\nfunction getPairOrNextLower<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined,\n\tlocalId: LocalCompressedId\n): readonly [LocalCompressedId, FinalRange<TRangeObject>] | undefined {\n\tif (finalRanges === undefined) {\n\t\treturn undefined;\n\t}\n\tif (isSingleRange(finalRanges)) {\n\t\tif (localId > firstLocal) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [firstLocal, finalRanges];\n\t}\n\treturn finalRanges.getPairOrNextLower(localId);\n}\n\nfunction* entries<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined\n): IterableIterator<readonly [LocalCompressedId, FinalRange<TRangeObject>]> {\n\tif (finalRanges !== undefined) {\n\t\tif (isSingleRange(finalRanges)) {\n\t\t\tyield [firstLocal, finalRanges];\n\t\t} else {\n\t\t\tfor (const range of finalRanges.entries()) {\n\t\t\t\tyield range;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SessionIdNormalizer.js","sourceRoot":"","sources":["../../src/id-compressor/SessionIdNormalizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,4CAAiG;AAGjG,qEAAqE;AAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,mBAAmB;IAkB/B,YAAoC,mBAAmB,KAAK;QAAxB,qBAAgB,GAAhB,gBAAgB,CAAQ;QAjBpD,gBAAW,GAAsB,CAAC,CAAsB,CAAC;QAChD,aAAQ,GAIrB,IAAI,kDAAyB,CAChC,wCAA4B,EAC5B,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,EAAE;YACpB,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;gBACzC,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;YACD,OAAO,MAAM,CAAC,iBAAsC,CAAC;QACtD,CAAC,EACD,gCAAoB,CACpB,CAAC;IAE6D,CAAC;IAEhE;;;OAGG;IACI,iBAAiB,CAAC,OAA0B;QAClD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;QACpE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,GAAG,UAAU,CAAC;YAC1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AC,EAAE,CAAC;QAChC,IAAI,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,WAAW,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,kBAAkB,CAC1B,UAA6B,EAC7B,WAAkD,EAClD,OAA0B;IAE1B,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,QAAQ,CAAC,CAAC,OAAO,CAChB,UAA6B,EAC7B,WAAkD;IAElD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;gBAC3C,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from '@fluidframework/core-utils/internal';\n\nimport { Mutable, compareFiniteNumbers, compareFiniteNumbersReversed, fail } from '../Common.js';\nimport { FinalCompressedId, LocalCompressedId, SessionSpaceCompressedId } from '../Identifiers.js';\n\nimport { AppendOnlyDoublySortedMap } from './AppendOnlySortedMap.js';\nimport { SerializedSessionIdNormalizer } from './persisted-types/index.js';\n\n/**\n * Maps IDs created by a session between their local and final forms (i.e. normalization). These IDs are in a contiguous range.\n * The local and final forms of IDs made by a session can be thought of as two equal-length sparse arrays, aligned such\n * that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.\n * Below is an example to illustrate how various mappings can arise:\n *\n * ```\n * +- Creation Index\n * / +- Locals\n * / / +- Finals\n * / / /\n * ---+-----+----\n * 0 | -1 | 0 -|___ Two IDs are allocated as locals since no cluster exists. A new cluster is created when acked.\n * 1 | -2 | 1 -|\n * 2 | | 2 -|\n * 3 | | 3 --|-- Three more IDs are allocated as finals eagerly since a cluster exists with available capacity.\n * 4 | | 4 -|\n * 5 | -6 | 10 ----- One ID is allocated as a local (it overflows the existing cluster) and a new cluster is created after ack.\n * 6 | | 11 ----- One ID is allocated as a final eagerly into the existing cluster.\n * 7 | -8 | 12 ----- A local ID with an override is allocated. The override forces it to be a local ID.\n * 8 | | 13\n * 9 | | 14\n * 10 | -11 | ----- A local ID is allocated. It has no corresponding final ID since it has not been acked.\n * ```\n *\n * Note that in this example, some IDs (those at indices 2, 3, 4, 6, 8, and 9) have no local form. The ID at index 10 has no final form.\n * These kinds of \"gaps\" occur due to the timing of allocation calls on the client and how they relate to finalization/cluster creation,\n * which depends on receiving an ack/sequence number from the server. Given this context, \"session space\" can be thought of as:\n *\n * ```\n * for each index in the range of IDs created by a session:\n * \tthe local form if it exists, otherwise the final form\n * ```\n *\n * This class is designed to efficiently build and query these mappings by leveraging the facts that much of the range (in both local and\n * final space) is uninterrupted by \"gaps\" and can be compactly represented by a (first, last) pair and is easily binary searched for\n * normalization between local and final space.\n */\nexport class SessionIdNormalizer<TRangeObject> {\n\tprivate nextLocalId: LocalCompressedId = -1 as LocalCompressedId;\n\tprivate readonly idRanges: AppendOnlyDoublySortedMap<\n\t\tLocalCompressedId,\n\t\t[lastLocal: LocalCompressedId, finalRanges: FinalRanges<TRangeObject> | undefined],\n\t\tFinalCompressedId\n\t> = new AppendOnlyDoublySortedMap(\n\t\tcompareFiniteNumbersReversed,\n\t\t([_, finalRanges]) => {\n\t\t\tif (finalRanges !== undefined) {\n\t\t\t\tconst first = getFirstRange(finalRanges);\n\t\t\t\treturn extractFirstFinalFromRange(first);\n\t\t\t}\n\t\t\treturn Number.POSITIVE_INFINITY as FinalCompressedId;\n\t\t},\n\t\tcompareFiniteNumbers\n\t);\n\n\tpublic constructor(private readonly expensiveAsserts = false) {}\n\n\t/**\n\t * Converts the final ID to its session-space representation.\n\t * This will be the corresponding local if a local form exists, and `finalId` otherwise.\n\t */\n\tpublic getSessionSpaceId(finalId: FinalCompressedId): SessionSpaceCompressedId | undefined {\n\t\tconst localRange = this.idRanges.getPairOrNextLowerByValue(finalId);\n\t\tif (localRange !== undefined) {\n\t\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\t\tconst finalRange = getPairOrNextLowerByValue(firstLocal, finalRanges, finalId);\n\t\t\tif (finalRange !== undefined) {\n\t\t\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\t\t\tif (finalId <= lastFinal) {\n\t\t\t\t\tconst localRangeDelta = alignedLocal - lastLocal;\n\t\t\t\t\tconst finalDelta = finalId - firstFinal;\n\t\t\t\t\tif (finalDelta <= localRangeDelta) {\n\t\t\t\t\t\treturn (alignedLocal - finalDelta) as LocalCompressedId;\n\t\t\t\t\t}\n\t\t\t\t\t// `finalId` was an eagerly generated final ID\n\t\t\t\t\treturn finalId as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Converts the local ID to its corresponding final ID, if one exists.\n\t */\n\tpublic getFinalId(localId: LocalCompressedId): [FinalCompressedId, TRangeObject] | undefined {\n\t\tconst localRange =\n\t\t\tthis.idRanges.getPairOrNextLower(localId) ?? fail('Local ID was never recorded with this normalizer.');\n\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\tif (localId < lastLocal) {\n\t\t\tfail('Local ID was never recorded with this normalizer.');\n\t\t}\n\t\tconst finalRange = getPairOrNextLower(firstLocal, finalRanges, localId);\n\t\tif (finalRange !== undefined) {\n\t\t\tconst [alignedLocal, [firstFinal, lastFinal, rangeObject]] = finalRange;\n\t\t\tconst rangeDelta = lastFinal - firstFinal;\n\t\t\tconst localDelta = alignedLocal - localId;\n\t\t\tif (localDelta <= rangeDelta) {\n\t\t\t\t// Local is within a range segment that has a corresponding final\n\t\t\t\treturn [(firstFinal + localDelta) as FinalCompressedId, rangeObject];\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Returns the index of the local ID corresponding to the supplied final ID in the total range of IDs created by the session,\n\t * if the ID was created by the session for this `SessionIdNormalizer`.\n\t */\n\tpublic getCreationIndex(finalId: FinalCompressedId): number | undefined {\n\t\tconst localRange = this.idRanges.getPairOrNextLowerByValue(finalId);\n\t\tif (localRange !== undefined) {\n\t\t\tconst [firstLocal, [_, finalRanges]] = localRange;\n\t\t\tconst finalRange = getPairOrNextLowerByValue(firstLocal, finalRanges, finalId);\n\t\t\tif (finalRange !== undefined) {\n\t\t\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\t\t\tif (finalId <= lastFinal) {\n\t\t\t\t\tconst finalDelta = finalId - firstFinal;\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus\n\t\t\t\t\treturn -alignedLocal - 1 + finalDelta;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Returns the session-space ID at the supplied creation index, if one exists.\n\t */\n\tpublic getIdByCreationIndex(index: number): SessionSpaceCompressedId | undefined {\n\t\tconst localByIndex = -(index + 1) as LocalCompressedId;\n\t\tconst localRange = this.idRanges.getPairOrNextLower(localByIndex);\n\t\tif (localRange === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [firstLocal, [lastLocal, finalRanges]] = localRange;\n\t\tif (localByIndex >= lastLocal) {\n\t\t\treturn localByIndex;\n\t\t}\n\t\tconst finalRange =\n\t\t\tgetPairOrNextLower(firstLocal, finalRanges, localByIndex) ??\n\t\t\tfail('Final ranges not aligned with owning local range.');\n\n\t\tconst [alignedLocal, [firstFinal, lastFinal]] = finalRange;\n\t\tconst localDelta = alignedLocal - localByIndex;\n\t\tconst finalId = firstFinal + localDelta;\n\t\tif (finalId <= lastFinal) {\n\t\t\t// `finalId` was an eagerly generated final ID\n\t\t\treturn finalId as SessionSpaceCompressedId;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate static makeFinalRangesMap<TRangeObject>(): FinalRangesMap<TRangeObject> {\n\t\treturn new AppendOnlyDoublySortedMap(\n\t\t\tcompareFiniteNumbersReversed,\n\t\t\textractFirstFinalFromRange,\n\t\t\tcompareFiniteNumbers\n\t\t);\n\t}\n\n\t/**\n\t * Returns the last final ID known to this normalizer.\n\t */\n\tpublic getLastFinalId(): FinalCompressedId | undefined {\n\t\tconst lastIndex = this.idRanges.size - 1;\n\t\tconst secondToLast = Math.max(0, lastIndex - 1);\n\t\tfor (let i = lastIndex; i >= secondToLast; i--) {\n\t\t\tconst localRange = this.idRanges.getAtIndex(i);\n\t\t\tif (localRange !== undefined) {\n\t\t\t\tconst finalRanges = localRange[1][1];\n\t\t\t\tif (finalRanges !== undefined) {\n\t\t\t\t\treturn getLastRange(finalRanges)[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Registers and returns the next ID in local space with this normalizer. An example:\n\t *\n\t * Locals: [-1, -2, X, X]\n\t * Finals: [ 0, 1, 2, 3]\n\t * In this scenario, a call to this method would generate and return -5.\n\t */\n\tpublic addLocalId(): LocalCompressedId {\n\t\tconst localId = this.nextLocalId-- as LocalCompressedId;\n\t\tconst lastLocalRange = this.idRanges.last();\n\t\tif (lastLocalRange !== undefined) {\n\t\t\tconst lastLocal = lastLocalRange[1][0];\n\t\t\tif (localId === lastLocal - 1) {\n\t\t\t\t// New local simply expands the last local range tracked\n\t\t\t\tlastLocalRange[1][0] = localId;\n\t\t\t\treturn localId;\n\t\t\t}\n\t\t}\n\n\t\tif (this.expensiveAsserts) {\n\t\t\tif (lastLocalRange === undefined) {\n\t\t\t\tassert(localId === -1, 0x657 /* Local ID space must start at -1. */);\n\t\t\t} else {\n\t\t\t\tconst [firstLocal, [_, finalRanges]] = lastLocalRange;\n\t\t\t\tlet finalDelta = 0;\n\t\t\t\tfor (const [_, [firstFinal, lastFinal]] of entries(firstLocal, finalRanges)) {\n\t\t\t\t\tfinalDelta += lastFinal - firstFinal + 1;\n\t\t\t\t}\n\t\t\t\tassert(localId === firstLocal - finalDelta, 0x658 /* Local ID space must be contiguous. */);\n\t\t\t}\n\t\t}\n\n\t\tthis.idRanges.append(localId, [localId, undefined]);\n\t\treturn localId;\n\t}\n\n\t/**\n\t * Registers one or more final IDs with this normalizer.\n\t * If there are any local IDs at the tip of session-space that do not have a corresponding final, they will be registered (aligned)\n\t * starting with the first of those. Otherwise, will be registered as the next ID in session space in creation order.\n\t *\n\t * An example:\n\t * Locals: [-1, -2, X, -4]\n\t * Finals: [ 0, 1, 2, X]\n\t * Calling `addFinalIds` with first === last === 5 results in the following:\n\t * Locals: [-1, -2, X, -4]\n\t * Finals: [ 0, 1, 2, 5]\n\t * Subsequently calling `addFinalIds` with first === last === 6 results in the following:\n\t * Locals: [-1, -2, X, -4, X]\n\t * Finals: [ 0, 1, 2, 5, 6]\n\t *\n\t * Non-contiguous final IDs (i.e. the first final after a \"gap\" in final space) must always correspond to a local ID. For example,\n\t * in the final call to `addFinalIds` above would fail if first === last === 9, because the resulting state would have a\n\t * non-contiguous final ID without a local form:\n\t * Locals: [-1, -2, X, -4, X]\n\t * Finals: [ 0, 1, 2, 5, 9]\n\t *\n\t * ^final ID 9 is not contiguous and does not have a corresponding local ID\n\t */\n\tpublic addFinalIds(firstFinal: FinalCompressedId, lastFinal: FinalCompressedId, rangeObject: TRangeObject): void {\n\t\tassert(lastFinal >= firstFinal, 0x659 /* Malformed normalization range. */);\n\t\tconst [firstLocal, finalRangesObj] =\n\t\t\tthis.idRanges.last() ?? fail('Final IDs must be added to an existing local range.');\n\t\tconst [lastLocal, finalRanges] = finalRangesObj;\n\t\tlet nextLocal: LocalCompressedId;\n\t\tif (finalRanges === undefined) {\n\t\t\tfinalRangesObj[1] = [firstFinal, lastFinal, rangeObject];\n\t\t\tnextLocal = Math.min(this.nextLocalId, firstLocal - (lastFinal - firstFinal) - 1) as LocalCompressedId;\n\t\t} else {\n\t\t\tconst [firstAlignedLocal, lastAlignedLocal, lastAlignedFinal, lastFinalRange] = this.getAlignmentOfLastRange(\n\t\t\t\tfirstLocal,\n\t\t\t\tfinalRanges\n\t\t\t);\n\t\t\tnextLocal = Math.min(this.nextLocalId, lastAlignedLocal - (lastFinal - firstFinal) - 2) as LocalCompressedId;\n\t\t\tif (firstFinal === lastAlignedFinal + 1) {\n\t\t\t\tlastFinalRange[1] = lastFinal;\n\t\t\t} else {\n\t\t\t\tconst alignedLocal = (lastAlignedLocal - 1) as LocalCompressedId;\n\t\t\t\tlet rangeMap: FinalRangesMap<TRangeObject>;\n\t\t\t\tif (isSingleRange(finalRanges)) {\n\t\t\t\t\t// Convert the single range to a range collection\n\t\t\t\t\trangeMap = SessionIdNormalizer.makeFinalRangesMap();\n\t\t\t\t\trangeMap.append(firstAlignedLocal, lastFinalRange);\n\t\t\t\t\tfinalRangesObj[1] = rangeMap;\n\t\t\t\t} else {\n\t\t\t\t\trangeMap = finalRanges;\n\t\t\t\t}\n\t\t\t\trangeMap.append(alignedLocal, [firstFinal, lastFinal, rangeObject]);\n\t\t\t\tassert(alignedLocal >= lastLocal, 0x65a /* Gaps in final space must align to a local. */);\n\t\t\t}\n\t\t\tif (this.expensiveAsserts) {\n\t\t\t\tthis.idRanges.assertValid();\n\t\t\t}\n\t\t}\n\n\t\tthis.nextLocalId = nextLocal;\n\t}\n\n\t/**\n\t * Alerts the normalizer to the existence of a block of final IDs that are *allocated* (but may not be entirely used).\n\t *\n\t * The normalizer may have unaligned (unfinalized) local IDs; any such outstanding locals will be eagerly aligned with\n\t * as many finals from the registered block as possible.\n\t *\n\t * It is important to register blocks via this method as soon as they are created for future eager final generations to be utilized, as such\n\t * generation is dependant on the normalizer being up-to-date with which local IDs have been aligned with finals. If, for instance,\n\t * a block of finals is not immediately registered with the normalizer and there are outstanding locals that would have aligned with them,\n\t * those locals will not be finalized until their creation range is finalized, which could be later if the block was created by an earlier\n\t * creation range's finalization but is large enough to span them both. In this scenario, no eager finals can be generated until the second\n\t * creation range is finalized.\n\t *\n\t * A usage example:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, X, X, X]\n\t * Calling `registerFinalIdBlock` with firstFinalInBlock === 5 and count === 10 results in the following:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, 5, 6, 7]\n\t * Instead calling `registerFinalIdBlock` with firstFinalInBlock === 5 and count === 2 results in the following:\n\t * Locals: [-1, -2, X, -4, -5, -6]\n\t * Finals: [ 0, 1, 2, 5, 6, X]\n\t *\n\t */\n\tpublic registerFinalIdBlock(firstFinalInBlock: FinalCompressedId, count: number, rangeObject: TRangeObject): void {\n\t\tassert(count >= 1, 0x65b /* Malformed normalization block. */);\n\t\tconst [firstLocal, [lastLocal, finalRanges]] =\n\t\t\tthis.idRanges.last() ?? fail('Final ID block should not be registered before any locals.');\n\t\tlet unalignedLocalCount: number;\n\t\tif (finalRanges === undefined) {\n\t\t\tunalignedLocalCount = firstLocal - lastLocal + 1;\n\t\t} else {\n\t\t\tconst [_, lastAlignedLocal] = this.getAlignmentOfLastRange(firstLocal, finalRanges);\n\t\t\tunalignedLocalCount = lastAlignedLocal - lastLocal;\n\t\t}\n\t\tassert(\n\t\t\tunalignedLocalCount > 0,\n\t\t\t0x65c /* Final ID block should not be registered without an existing local range. */\n\t\t);\n\t\tconst lastFinal = (firstFinalInBlock + Math.min(unalignedLocalCount, count) - 1) as FinalCompressedId;\n\t\tthis.addFinalIds(firstFinalInBlock, lastFinal, rangeObject);\n\t}\n\n\tprivate getAlignmentOfLastRange(\n\t\tfirstLocal: LocalCompressedId,\n\t\tfinalRanges: FinalRanges<TRangeObject>\n\t): [\n\t\tfirstAlignedLocal: LocalCompressedId,\n\t\tlastAlignedLocal: LocalCompressedId,\n\t\tlastAlignedFinal: FinalCompressedId,\n\t\tlastFinalRange: FinalRange<TRangeObject>,\n\t] {\n\t\tconst isSingle = isSingleRange(finalRanges);\n\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\tlet firstAlignedLocal: LocalCompressedId;\n\t\tif (isSingle) {\n\t\t\tfirstAlignedLocal = firstLocal;\n\t\t\tlastFinalRange = finalRanges;\n\t\t} else {\n\t\t\t[firstAlignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t}\n\n\t\tconst [firstAlignedFinal, lastAlignedFinal] = lastFinalRange;\n\t\tconst lastAlignedLocal = firstAlignedLocal - (lastAlignedFinal - firstAlignedFinal);\n\t\treturn [firstAlignedLocal, lastAlignedLocal as LocalCompressedId, lastAlignedFinal, lastFinalRange];\n\t}\n\n\t/**\n\t * Returns an enumerable of all session-space IDs known to this normalizer, in creation order.\n\t */\n\tpublic *[Symbol.iterator](): IterableIterator<SessionSpaceCompressedId> {\n\t\tfor (const [firstLocal, [lastLocal, finalRanges]] of this.idRanges.entries()) {\n\t\t\tfor (let i = firstLocal; i >= lastLocal; i--) {\n\t\t\t\tyield i;\n\t\t\t}\n\t\t\tif (finalRanges !== undefined) {\n\t\t\t\t// Safe to get only the last final range, as all others must have corresponding locals (see `addFinalIds` docs)\n\t\t\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\t\t\tlet alignedLocal: LocalCompressedId;\n\t\t\t\tif (isSingleRange(finalRanges)) {\n\t\t\t\t\talignedLocal = firstLocal;\n\t\t\t\t\tlastFinalRange = finalRanges;\n\t\t\t\t} else {\n\t\t\t\t\t[alignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t\t\t}\n\t\t\t\tconst [firstFinal, lastFinal] = lastFinalRange;\n\t\t\t\tconst localRangeDelta = alignedLocal - lastLocal;\n\t\t\t\tfor (let i = firstFinal + localRangeDelta + 1; i <= lastFinal; i++) {\n\t\t\t\t\tyield i as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic serialize(): SerializedSessionIdNormalizer {\n\t\tconst serialized: Mutable<SerializedSessionIdNormalizer> = {\n\t\t\tlocalRanges: [],\n\t\t\tnextLocalId: this.nextLocalId,\n\t\t};\n\t\tconst localRanges = serialized.localRanges as Mutable<typeof serialized.localRanges>;\n\t\tfor (const [firstLocal, finalRanges] of this.idRanges.entries()) {\n\t\t\tconst [lastLocal, finalRangesTable] = finalRanges;\n\t\t\tif (finalRangesTable !== undefined) {\n\t\t\t\tconst serializedFinalRanges: [LocalCompressedId, FinalCompressedId, FinalCompressedId][] = [];\n\t\t\t\tfor (const [alignedLocal, [firstFinal, lastFinal]] of entries(firstLocal, finalRangesTable)) {\n\t\t\t\t\tserializedFinalRanges.push([alignedLocal, firstFinal, lastFinal]);\n\t\t\t\t}\n\t\t\t\tlocalRanges.push([firstLocal, lastLocal, serializedFinalRanges]);\n\t\t\t} else {\n\t\t\t\tlocalRanges.push([firstLocal, lastLocal]);\n\t\t\t}\n\t\t}\n\t\treturn serialized;\n\t}\n\n\tpublic static deserialize<TRangeObject>(\n\t\tserialized: SerializedSessionIdNormalizer,\n\t\tgetRangeObject: (finalId: FinalCompressedId) => TRangeObject\n\t): SessionIdNormalizer<TRangeObject> {\n\t\tconst normalizer = new SessionIdNormalizer<TRangeObject>();\n\t\tconst { idRanges } = normalizer;\n\t\tfor (const [firstLocal, lastLocal, serializedFinalRanges] of serialized.localRanges) {\n\t\t\tlet finalRanges: FinalRanges<TRangeObject> | undefined;\n\t\t\tif (serializedFinalRanges !== undefined) {\n\t\t\t\tassert(serializedFinalRanges.length !== 0, 0x65d /* Empty range should not be reified. */);\n\t\t\t\tif (serializedFinalRanges.length === 1) {\n\t\t\t\t\tconst [_, firstFinal, lastFinal] = serializedFinalRanges[0];\n\t\t\t\t\tfinalRanges = [firstFinal, lastFinal, getRangeObject(firstFinal)];\n\t\t\t\t} else {\n\t\t\t\t\tfinalRanges = SessionIdNormalizer.makeFinalRangesMap<TRangeObject>();\n\t\t\t\t\tfor (const [alignedLocal, firstFinal, lastFinal] of serializedFinalRanges) {\n\t\t\t\t\t\tfinalRanges.append(alignedLocal, [firstFinal, lastFinal, getRangeObject(firstFinal)]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tidRanges.append(firstLocal, [lastLocal, finalRanges]);\n\t\t}\n\t\tnormalizer.nextLocalId = serialized.nextLocalId;\n\t\treturn normalizer;\n\t}\n\n\tpublic equals(\n\t\tother: SessionIdNormalizer<TRangeObject>,\n\t\tcompareRangeObjects: (a: TRangeObject, b: TRangeObject) => boolean = (a, b) => a === b\n\t): boolean {\n\t\treturn (\n\t\t\tthis.nextLocalId === other.nextLocalId &&\n\t\t\tthis.idRanges.equals(other.idRanges, (localRangeA, localRangeB) => {\n\t\t\t\tconst [lastLocalA, finalRangesA] = localRangeA;\n\t\t\t\tconst [lastLocalB, finalRangesB] = localRangeB;\n\t\t\t\tif (finalRangesA === undefined || finalRangesB === undefined) {\n\t\t\t\t\treturn finalRangesA === finalRangesB;\n\t\t\t\t}\n\n\t\t\t\tconst rangeEquals = (finalRangeA: FinalRange<TRangeObject>, finalRangeB: FinalRange<TRangeObject>) => {\n\t\t\t\t\tconst [firstFinalA, lastFinalA, rangeObjectA] = finalRangeA;\n\t\t\t\t\tconst [firstFinalB, lastFinalB, rangeObjectB] = finalRangeB;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tfirstFinalA === firstFinalB && lastFinalA === lastFinalB && compareRangeObjects(rangeObjectA, rangeObjectB)\n\t\t\t\t\t);\n\t\t\t\t};\n\n\t\t\t\tif (isSingleRange(finalRangesA) || isSingleRange(finalRangesB)) {\n\t\t\t\t\tif (!isSingleRange(finalRangesA) || !isSingleRange(finalRangesB)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn rangeEquals(finalRangesA, finalRangesB);\n\t\t\t\t}\n\n\t\t\t\treturn lastLocalA === lastLocalB && finalRangesA.equals(finalRangesB, rangeEquals);\n\t\t\t})\n\t\t);\n\t}\n}\n\ntype FinalRange<TRangeObject> = [\n\tfirstFinal: FinalCompressedId,\n\tlastFinal: FinalCompressedId,\n\trangeObject: TRangeObject,\n];\n\ntype FinalRangesMap<TRangeObject> = AppendOnlyDoublySortedMap<\n\tLocalCompressedId,\n\tFinalRange<TRangeObject>,\n\tFinalCompressedId\n>;\n\ntype FinalRanges<TRangeObject> = FinalRange<TRangeObject> | FinalRangesMap<TRangeObject>;\n\nfunction isSingleRange<TRangeObject>(ranges: FinalRanges<TRangeObject>): ranges is FinalRange<TRangeObject> {\n\treturn Array.isArray(ranges);\n}\n\nfunction getLastRange<TRangeObject>(finalRanges: FinalRanges<TRangeObject>): FinalRange<TRangeObject> {\n\tif (isSingleRange(finalRanges)) {\n\t\treturn finalRanges;\n\t}\n\treturn (finalRanges.last() ?? fail('Map must be non-empty'))[1];\n}\n\nfunction getFirstRange<TRangeObject>(finalRanges: FinalRanges<TRangeObject>): FinalRange<TRangeObject> {\n\tif (isSingleRange(finalRanges)) {\n\t\treturn finalRanges;\n\t}\n\treturn (finalRanges.first() ?? fail('Map must be non-empty'))[1];\n}\n\nfunction extractFirstFinalFromRange<TRangeObject>(finalRange: FinalRange<TRangeObject>): FinalCompressedId {\n\treturn finalRange[0];\n}\n\nfunction getPairOrNextLowerByValue<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined,\n\tfinalId: FinalCompressedId\n): readonly [LocalCompressedId, FinalRange<TRangeObject>] | undefined {\n\tif (finalRanges === undefined) {\n\t\treturn undefined;\n\t}\n\tif (isSingleRange(finalRanges)) {\n\t\tif (finalId < finalRanges[0]) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [firstLocal, finalRanges];\n\t}\n\treturn finalRanges.getPairOrNextLowerByValue(finalId);\n}\n\nfunction getPairOrNextLower<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined,\n\tlocalId: LocalCompressedId\n): readonly [LocalCompressedId, FinalRange<TRangeObject>] | undefined {\n\tif (finalRanges === undefined) {\n\t\treturn undefined;\n\t}\n\tif (isSingleRange(finalRanges)) {\n\t\tif (localId > firstLocal) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [firstLocal, finalRanges];\n\t}\n\treturn finalRanges.getPairOrNextLower(localId);\n}\n\nfunction* entries<TRangeObject>(\n\tfirstLocal: LocalCompressedId,\n\tfinalRanges: FinalRanges<TRangeObject> | undefined\n): IterableIterator<readonly [LocalCompressedId, FinalRange<TRangeObject>]> {\n\tif (finalRanges !== undefined) {\n\t\tif (isSingleRange(finalRanges)) {\n\t\t\tyield [firstLocal, finalRanges];\n\t\t} else {\n\t\t\tfor (const range of finalRanges.entries()) {\n\t\t\t\tyield range;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdCompressor.d.ts","sourceRoot":"","sources":["../../src/id-compressor/IdCompressor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAkBvE,OAAO,EACN,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,wBAAwB,EACxB,QAAQ,EAER,MAAM,mBAAmB,CAAC;AAe3B,OAAO,KAAK,EACX,eAAe,EAIf,mCAAm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IAuGzE;;OAEG;WACW,WAAW,CAAC,UAAU,EAAE,wCAAwC,GAAG,YAAY;IAE7F;;;;;OAKG;WACW,WAAW,CACxB,UAAU,EAAE,mCAAmC,EAC/C,YAAY,EAAE,SAAS,EACvB,aAAa,CAAC,EAAE,aAAa,GAC3B,YAAY;IA8Kf;;;;OAIG;WACW,uBAAuB,CACpC,oBAAoB,EAAE,+BAA+B,EACrD,UAAU,EAAE,KAAK,GACf,mCAAmC;IAEtC;;;;OAIG;WACW,uBAAuB,CACpC,oBAAoB,EAAE,+BAA+B,EACrD,UAAU,EAAE,IAAI,GACd,wCAAwC;CAe3C;AAOD;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,UAAU,EAAE,mCAAmC,GAAG,wCAAwC,GACxF,UAAU,IAAI,wCAAwC,CAExD"}
|
|
@@ -781,6 +781,7 @@ export class IdCompressor {
|
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
else {
|
|
784
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
784
785
|
const idOffset = -id; // Convert to a positive number
|
|
785
786
|
if (idOffset > this.localIdCount) {
|
|
786
787
|
// This local ID was never allocated.
|
|
@@ -869,6 +870,7 @@ export class IdCompressor {
|
|
|
869
870
|
return id;
|
|
870
871
|
}
|
|
871
872
|
// Check if this local ID has not been allocated yet
|
|
873
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
872
874
|
if (-id > this.localIdCount) {
|
|
873
875
|
fail('Supplied local ID was not created by this compressor.');
|
|
874
876
|
}
|
|
@@ -907,6 +909,7 @@ export class IdCompressor {
|
|
|
907
909
|
normalizeToSessionSpace(id, sessionIdIfLocal) {
|
|
908
910
|
if (isLocalId(id)) {
|
|
909
911
|
if (sessionIdIfLocal === undefined || sessionIdIfLocal === this.localSessionId) {
|
|
912
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
910
913
|
const localIndex = -id;
|
|
911
914
|
if (localIndex > this.localIdCount) {
|
|
912
915
|
fail('Supplied local ID was not created by this compressor.');
|
|
@@ -915,6 +918,7 @@ export class IdCompressor {
|
|
|
915
918
|
}
|
|
916
919
|
else {
|
|
917
920
|
const session = this.sessions.get(sessionIdIfLocal) ?? fail('No IDs have ever been finalized by the supplied session.');
|
|
921
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
918
922
|
const localCount = -id;
|
|
919
923
|
const numericUuid = incrementUuid(session.sessionUuid, localCount - 1);
|
|
920
924
|
return this.compressNumericUuid(numericUuid) ?? fail('ID is not known to this compressor.');
|
|
@@ -1263,6 +1267,7 @@ export class IdCompressor {
|
|
|
1263
1267
|
const { sessionIndex, capacity, count, overrides } = deserializeCluster(serializedCluster);
|
|
1264
1268
|
const { session, sessionId } = sessionInfos[sessionIndex];
|
|
1265
1269
|
const { lastFinalizedLocalId, sessionUuid } = session;
|
|
1270
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
1266
1271
|
const currentIdCount = lastFinalizedLocalId === undefined ? 0 : -lastFinalizedLocalId;
|
|
1267
1272
|
const cluster = {
|
|
1268
1273
|
capacity,
|
|
@@ -1329,6 +1334,7 @@ export class IdCompressor {
|
|
|
1329
1334
|
});
|
|
1330
1335
|
}
|
|
1331
1336
|
assertWithMessage(compressor.localSession.lastFinalizedLocalId === undefined ||
|
|
1337
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-unary-minus
|
|
1332
1338
|
compressor.localIdCount >= -compressor.localSession.lastFinalizedLocalId);
|
|
1333
1339
|
return compressor;
|
|
1334
1340
|
}
|