@fluid-experimental/tree 1.2.7 → 2.0.0-dev.1.3.0.96595
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/.mocharc.js +12 -0
- package/.prettierignore +6 -0
- package/README.md +1 -1
- package/dist/Checkout.d.ts +9 -4
- package/dist/Checkout.d.ts.map +1 -1
- package/dist/Checkout.js +34 -25
- package/dist/Checkout.js.map +1 -1
- package/dist/Common.d.ts +31 -18
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js +33 -22
- package/dist/Common.js.map +1 -1
- package/dist/EditLog.js +2 -2
- package/dist/EditLog.js.map +1 -1
- package/dist/EditUtilities.d.ts +5 -0
- package/dist/EditUtilities.d.ts.map +1 -1
- package/dist/EditUtilities.js +4 -3
- package/dist/EditUtilities.js.map +1 -1
- package/dist/EventTypes.d.ts +11 -6
- package/dist/EventTypes.d.ts.map +1 -1
- package/dist/EventTypes.js +11 -6
- package/dist/EventTypes.js.map +1 -1
- package/dist/HistoryEditFactory.d.ts +5 -3
- package/dist/HistoryEditFactory.d.ts.map +1 -1
- package/dist/HistoryEditFactory.js +25 -6
- package/dist/HistoryEditFactory.js.map +1 -1
- package/dist/LogViewer.d.ts +12 -6
- package/dist/LogViewer.d.ts.map +1 -1
- package/dist/LogViewer.js.map +1 -1
- package/dist/RevisionValueCache.d.ts +8 -4
- package/dist/RevisionValueCache.d.ts.map +1 -1
- package/dist/RevisionValueCache.js +4 -2
- package/dist/RevisionValueCache.js.map +1 -1
- package/dist/SharedTree.d.ts +22 -11
- package/dist/SharedTree.d.ts.map +1 -1
- package/dist/SharedTree.js +25 -19
- package/dist/SharedTree.js.map +1 -1
- package/dist/StringInterner.d.ts +4 -3
- package/dist/StringInterner.d.ts.map +1 -1
- package/dist/StringInterner.js +4 -3
- package/dist/StringInterner.js.map +1 -1
- package/dist/Transaction.d.ts +2 -2
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +3 -2
- package/dist/Transaction.js.map +1 -1
- package/dist/TransactionInternal.d.ts.map +1 -1
- package/dist/TransactionInternal.js +1 -0
- package/dist/TransactionInternal.js.map +1 -1
- package/dist/id-compressor/IdCompressor.d.ts +14 -8
- package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
- package/dist/id-compressor/IdCompressor.js +14 -8
- package/dist/id-compressor/IdCompressor.js.map +1 -1
- package/dist/id-compressor/NumericUuid.d.ts +4 -0
- package/dist/id-compressor/NumericUuid.d.ts.map +1 -1
- package/dist/id-compressor/NumericUuid.js +13 -3
- package/dist/id-compressor/NumericUuid.js.map +1 -1
- package/dist/id-compressor/SessionIdNormalizer.d.ts +8 -3
- package/dist/id-compressor/SessionIdNormalizer.d.ts.map +1 -1
- package/dist/id-compressor/SessionIdNormalizer.js +8 -3
- package/dist/id-compressor/SessionIdNormalizer.js.map +1 -1
- package/dist/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
- package/dist/id-compressor/persisted-types/0.0.1.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/lib/Checkout.d.ts +9 -4
- package/lib/Checkout.d.ts.map +1 -1
- package/lib/Checkout.js +36 -27
- package/lib/Checkout.js.map +1 -1
- package/lib/Common.d.ts +31 -18
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +31 -21
- package/lib/Common.js.map +1 -1
- package/lib/EditLog.js +2 -2
- package/lib/EditLog.js.map +1 -1
- package/lib/EditUtilities.d.ts +5 -0
- package/lib/EditUtilities.d.ts.map +1 -1
- package/lib/EditUtilities.js +4 -3
- package/lib/EditUtilities.js.map +1 -1
- package/lib/EventTypes.d.ts +11 -6
- package/lib/EventTypes.d.ts.map +1 -1
- package/lib/EventTypes.js +11 -6
- package/lib/EventTypes.js.map +1 -1
- package/lib/HistoryEditFactory.d.ts +5 -3
- package/lib/HistoryEditFactory.d.ts.map +1 -1
- package/lib/HistoryEditFactory.js +25 -6
- package/lib/HistoryEditFactory.js.map +1 -1
- package/lib/LogViewer.d.ts +12 -6
- package/lib/LogViewer.d.ts.map +1 -1
- package/lib/LogViewer.js.map +1 -1
- package/lib/RevisionValueCache.d.ts +8 -4
- package/lib/RevisionValueCache.d.ts.map +1 -1
- package/lib/RevisionValueCache.js +4 -2
- package/lib/RevisionValueCache.js.map +1 -1
- package/lib/SharedTree.d.ts +22 -11
- package/lib/SharedTree.d.ts.map +1 -1
- package/lib/SharedTree.js +26 -20
- package/lib/SharedTree.js.map +1 -1
- package/lib/StringInterner.d.ts +4 -3
- package/lib/StringInterner.d.ts.map +1 -1
- package/lib/StringInterner.js +4 -3
- package/lib/StringInterner.js.map +1 -1
- package/lib/Transaction.d.ts +2 -2
- package/lib/Transaction.d.ts.map +1 -1
- package/lib/Transaction.js +3 -2
- package/lib/Transaction.js.map +1 -1
- package/lib/TransactionInternal.d.ts.map +1 -1
- package/lib/TransactionInternal.js +1 -0
- package/lib/TransactionInternal.js.map +1 -1
- package/lib/id-compressor/IdCompressor.d.ts +14 -8
- package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
- package/lib/id-compressor/IdCompressor.js +14 -8
- package/lib/id-compressor/IdCompressor.js.map +1 -1
- package/lib/id-compressor/NumericUuid.d.ts +4 -0
- package/lib/id-compressor/NumericUuid.d.ts.map +1 -1
- package/lib/id-compressor/NumericUuid.js +13 -3
- package/lib/id-compressor/NumericUuid.js.map +1 -1
- package/lib/id-compressor/SessionIdNormalizer.d.ts +8 -3
- package/lib/id-compressor/SessionIdNormalizer.d.ts.map +1 -1
- package/lib/id-compressor/SessionIdNormalizer.js +8 -3
- package/lib/id-compressor/SessionIdNormalizer.js.map +1 -1
- package/lib/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
- package/lib/id-compressor/persisted-types/0.0.1.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/test/AppendOnlySortedMap.perf.tests.js.map +1 -1
- package/lib/test/Checkout.tests.d.ts.map +1 -1
- package/lib/test/Checkout.tests.js +39 -10
- package/lib/test/Checkout.tests.js.map +1 -1
- package/lib/test/Common.tests.js +20 -1
- package/lib/test/Common.tests.js.map +1 -1
- package/lib/test/HistoryEditFactory.tests.js +48 -9
- package/lib/test/HistoryEditFactory.tests.js.map +1 -1
- package/lib/test/SessionIdNormalizer.tests.js +3 -2
- package/lib/test/SessionIdNormalizer.tests.js.map +1 -1
- package/lib/test/fuzz/Generators.d.ts.map +1 -1
- package/lib/test/fuzz/Generators.js.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.d.ts.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.js +2 -3
- package/lib/test/fuzz/SharedTreeFuzzTests.js.map +1 -1
- package/lib/test/utilities/MockTransaction.d.ts.map +1 -1
- package/lib/test/utilities/MockTransaction.js +1 -0
- package/lib/test/utilities/MockTransaction.js.map +1 -1
- package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
- package/lib/test/utilities/SharedTreeTests.js +35 -26
- package/lib/test/utilities/SharedTreeTests.js.map +1 -1
- package/lib/test/utilities/SharedTreeVersioningTests.d.ts.map +1 -1
- package/lib/test/utilities/SharedTreeVersioningTests.js +7 -0
- package/lib/test/utilities/SharedTreeVersioningTests.js.map +1 -1
- package/lib/test/utilities/TestUtilities.d.ts +5 -0
- package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
- package/lib/test/utilities/TestUtilities.js +4 -3
- package/lib/test/utilities/TestUtilities.js.map +1 -1
- package/lib/test/utilities/UndoRedoTests.js +3 -2
- package/lib/test/utilities/UndoRedoTests.js.map +1 -1
- package/package.json +28 -23
- package/src/Checkout.ts +56 -14
- package/src/Common.ts +39 -21
- package/src/EditLog.ts +2 -2
- package/src/EditUtilities.ts +3 -3
- package/src/EventTypes.ts +12 -6
- package/src/HistoryEditFactory.ts +31 -6
- package/src/LogViewer.ts +12 -6
- package/src/RevisionValueCache.ts +8 -4
- package/src/SharedTree.ts +39 -26
- package/src/StringInterner.ts +4 -3
- package/src/Transaction.ts +5 -4
- package/src/TransactionInternal.ts +1 -0
- package/src/id-compressor/IdCompressor.ts +27 -17
- package/src/id-compressor/NumericUuid.ts +17 -3
- package/src/id-compressor/SessionIdNormalizer.ts +8 -3
- package/src/id-compressor/persisted-types/0.0.1.ts +1 -0
- package/src/index.ts +1 -1
|
@@ -6,9 +6,13 @@ import { SessionId, StableId } from '../Identifiers';
|
|
|
6
6
|
/**
|
|
7
7
|
* A UUID (128 bit identifier) optimized for use as a 128 bit unsigned integer with fast addition and toString operations.
|
|
8
8
|
* The string entry is the upper 76 bits of the uuid and the integer entry holds the lower 52 bits:
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
9
11
|
* UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid
|
|
10
12
|
* SSSSSSSS-SSSS-SSSS-SSS - array[0]: string
|
|
11
13
|
* N NNNNNNNNNNNN - array[1]: integer
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
12
16
|
* The integer keeps the common case cost of incrementing and computing deltas very low.
|
|
13
17
|
* The string optimizes toString by caching the the majority of the resulting string.
|
|
14
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericUuid.d.ts","sourceRoot":"","sources":["../../src/id-compressor/NumericUuid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGrD
|
|
1
|
+
{"version":3,"file":"NumericUuid.d.ts","sourceRoot":"","sources":["../../src/id-compressor/NumericUuid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGrD;;;;;;;;;;;;GAYG;AACH,oBAAY,WAAW,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IACrD,QAAQ,CAAC,WAAW,EAAE,sCAAsC,CAAC;CAC7D,CAAC;AAQF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgDrG;AAaD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,SAAI,GAAG,QAAQ,CAQ/E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAKvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAEzE;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CA+C5E;AA2ID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAgB3D"}
|
|
@@ -169,6 +169,7 @@ function incrementUuid(uuid, amount) {
|
|
|
169
169
|
return newUuid;
|
|
170
170
|
}
|
|
171
171
|
exports.incrementUuid = incrementUuid;
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
172
173
|
var ChunkMath;
|
|
173
174
|
(function (ChunkMath) {
|
|
174
175
|
/*
|
|
@@ -199,7 +200,10 @@ var ChunkMath;
|
|
|
199
200
|
/** The maximum numeric value that can be represented by the numerically relevant bits in the variant chunk */
|
|
200
201
|
const maxVariantNumber = 2 ** 22 - 1;
|
|
201
202
|
ChunkMath.twentyThirdBit = 2 ** 22;
|
|
202
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* The upper chunk, denoted by 'U's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
|
|
205
|
+
*/
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
203
207
|
let Upper;
|
|
204
208
|
(function (Upper) {
|
|
205
209
|
function parse(stringEntry) {
|
|
@@ -215,7 +219,10 @@ var ChunkMath;
|
|
|
215
219
|
}
|
|
216
220
|
Upper.slice = slice;
|
|
217
221
|
})(Upper = ChunkMath.Upper || (ChunkMath.Upper = {}));
|
|
218
|
-
/**
|
|
222
|
+
/**
|
|
223
|
+
* The variant chunk, denoted by 'V's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
|
|
224
|
+
*/
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
219
226
|
let Variant;
|
|
220
227
|
(function (Variant) {
|
|
221
228
|
function parse(stringEntry) {
|
|
@@ -227,7 +234,10 @@ var ChunkMath;
|
|
|
227
234
|
}
|
|
228
235
|
Variant.hyphenate = hyphenate;
|
|
229
236
|
})(Variant = ChunkMath.Variant || (ChunkMath.Variant = {}));
|
|
230
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* The lower chunk, denoted by 'L's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL
|
|
239
|
+
*/
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
231
241
|
let Lower;
|
|
232
242
|
(function (Lower) {
|
|
233
243
|
function parse(stableId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericUuid.js","sourceRoot":"","sources":["../../src/id-compressor/NumericUuid.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,sCAAyC;AAEzC,oDAAoD;AAepD,MAAM,wBAAwB,GAAG,EAAE,CAAC,CAAC,8BAA8B;AACnE,MAAM,2BAA2B,GAAG,wBAAwB,GAAG,CAAC,CAAC;AACjE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,qBAAqB,GAAG,CAAC,IAAI,wBAAwB,GAAG,CAAC,CAAC;AAChE,MAAM,aAAa,GAAG,CAAC,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reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert, fail } from '../Common';\nimport { SessionId, StableId } from '../Identifiers';\nimport { generateStableId } from '../UuidUtilities';\n\n/**\n * A UUID (128 bit identifier) optimized for use as a 128 bit unsigned integer with fast addition and toString operations.\n * The string entry is the upper 76 bits of the uuid and the integer entry holds the lower 52 bits:\n * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n * SSSSSSSS-SSSS-SSSS-SSS - array[0]: string\n * N NNNNNNNNNNNN - array[1]: integer\n * The integer keeps the common case cost of incrementing and computing deltas very low.\n * The string optimizes toString by caching the the majority of the resulting string.\n */\nexport type NumericUuid = readonly [string, number] & {\n\treadonly NumericUuid: '9132ea20-a811-4756-85f8-aa6da5ca90f8';\n};\n\nconst bitsInNumericUuidInteger = 52; // Not tunable. Do not change.\nconst nibblesInNumericUuidInteger = bitsInNumericUuidInteger / 4;\nconst stringEntryLength = 22;\nconst maxNumericUuidInteger = 2 ** bitsInNumericUuidInteger - 1;\nconst fiftyThirdBit = 2 ** 52;\n\n/**\n * Calculates the numeric delta between a and b (i.e. a - b).\n * @param a - an uuid\n * @param b - an other uuid\n * @param maxDelta - the maximum integer delta (inclusive) to tolerate.\n * @returns undefined if the delta is negative or greater than `maxDelta`\n */\nexport function getPositiveDelta(a: NumericUuid, b: NumericUuid, maxDelta: number): number | undefined {\n\tconst [stringEntryA, lowNumberA] = a;\n\tconst [stringEntryB, lowNumberB] = b;\n\n\tif (stringEntryA === stringEntryB) {\n\t\tconst difference = lowNumberA - lowNumberB;\n\t\tif (difference >= 0 && difference <= maxDelta) {\n\t\t\treturn difference;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tconst highNumberA = Number.parseInt(ChunkMath.Upper.parse(stringEntryA), 16);\n\tconst highNumberB = Number.parseInt(ChunkMath.Upper.parse(stringEntryB), 16);\n\n\tlet subtractHigh = highNumberA - highNumberB;\n\tif (Math.abs(subtractHigh) > 1) {\n\t\t// If the high bits differ by more than 1, then there is no chance that any lower bits could compensate\n\t\treturn undefined;\n\t}\n\n\tlet midNumberA = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryA));\n\tconst midNumberB = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryB));\n\n\tlet subtractLow = lowNumberA - lowNumberB;\n\tif (subtractLow < 0) {\n\t\tmidNumberA -= 1;\n\t\tsubtractLow += fiftyThirdBit;\n\t}\n\n\tlet subtractMid = midNumberA - midNumberB;\n\tif (subtractMid < 0) {\n\t\tsubtractHigh -= 1;\n\t\tsubtractMid += ChunkMath.twentyThirdBit;\n\t}\n\n\tif (subtractHigh !== 0) {\n\t\t// a < b, no positive delta, or\n\t\t// a > b by much more than MAX_SAFE_INTEGER\n\t\treturn undefined;\n\t}\n\n\tif (subtractMid > 1) {\n\t\treturn undefined;\n\t} else {\n\t\tconst trueDelta = fiftyThirdBit * subtractMid + subtractLow;\n\t\treturn trueDelta > maxDelta ? undefined : trueDelta;\n\t}\n}\n\n// Pre-allocated array of strings of zeros.\n// Used to pad hex strings up to 52 bits\nconst zeros: string[] = [];\nfor (let i = 0; i < nibblesInNumericUuidInteger; i++) {\n\tzeros.push('0'.repeat(i));\n}\n\nfunction padToLengthWithZeros(str: string, count: number): string {\n\treturn str.length === count ? str : zeros[count - str.length] + str;\n}\n\n/**\n * @param offset - an optional offset to increment the returned StableId\n * @returns the string representation of a `NumericUuid`.\n */\nexport function stableIdFromNumericUuid(uuid: NumericUuid, offset = 0): StableId {\n\tconst lowerAdd = uuid[1] + offset;\n\t// Common fast-path\n\tif (lowerAdd <= maxNumericUuidInteger) {\n\t\tconst lowerString = padToLengthWithZeros(lowerAdd.toString(16), nibblesInNumericUuidInteger);\n\t\treturn `${uuid[0] + lowerString.slice(0, 1)}-${lowerString.slice(1)}` as StableId;\n\t}\n\treturn stableIdFromNumericUuid(incrementUuid(uuid, offset));\n}\n\n/**\n * @param stableId - a minimal uuid string\n * @returns a numeric representation of `stableId`.\n */\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuid: (string | number)[] = new Array(2);\n\tuuid[0] = stableId.slice(0, stringEntryLength);\n\tuuid[1] = Number.parseInt(ChunkMath.Lower.parse(stableId), 16);\n\treturn uuid as readonly (number | string)[] as NumericUuid;\n}\n\n/**\n * Creates a session base ID.\n * This method (rather than standard uuid generation methods) should be used to generate session IDs.\n */\nexport function createSessionId(): SessionId {\n\treturn ensureSessionUuid(generateStableId());\n}\n\n/**\n * Compares numeric uuids for equality.\n */\nexport function numericUuidEquals(a: NumericUuid, b: NumericUuid): boolean {\n\treturn a[0] === b[0] && a[1] === b[1];\n}\n\n/**\n * The maximum value that can be contained in the upper string region of a numeric UUID (i.e. the string region excluding the version\n * nibble and the variant chunk)\n */\nconst maxUpperNumber = 2 ** 48 - 1;\n\n/**\n * Increments the uuid. `amount` must be a positive integer.\n * @returns the result of incrementing the uuid by `amount`.\n */\nexport function incrementUuid(uuid: NumericUuid, amount: number): NumericUuid {\n\t/*\n\t * UUIDs incremented beyond the max UUID \"ffffffff-ffff-4fff-bfff-ffffffffffff\" will cause a failure.\n\t * Also, some reserved bits of the v4 UUID must be treated as immutable (e.g. the version and\n\t * variant bits) and thus must not be incremented.\n\t */\n\tlet newUuid: [string, number];\n\tconst result = uuid[1] + amount;\n\tif (result <= maxNumericUuidInteger) {\n\t\t// The new number still fits within the number region of a numeric UUID.\n\t\t// Incrementing is usually done with small amounts, so this is the dominantly common case.\n\t\tnewUuid = [uuid[0], result];\n\t} else {\n\t\t// The numeric UUID's number region has overflowed. We will need to carry the overflow into the variant chunk (see `VariantChunk`).\n\t\t/** The amount left over after filling up the rest of the uuid's number region with the increment amount */\n\t\tconst remainder = amount - (maxNumericUuidInteger - uuid[1]) - 1;\n\t\tconst stringEntry = uuid[0];\n\t\tconst [newVariantChunkString, carried] = ChunkMath.increment(stringEntry);\n\n\t\tif (carried) {\n\t\t\t// The variant chunk itself also overflowed. We'll need to carry the overflow further, into the upper string region of the UUID.\n\t\t\tconst upperString = ChunkMath.Upper.parse(stringEntry);\n\t\t\tconst upperNumber = Number.parseInt(upperString, 16);\n\t\t\tassert(upperNumber <= maxUpperNumber);\n\t\t\tconst newUpperNumber = upperNumber + 1;\n\t\t\tif (newUpperNumber > maxUpperNumber) {\n\t\t\t\tfail('Exceeded maximum numeric UUID');\n\t\t\t} else {\n\t\t\t\t// The variant chunk overflowed but the upper string region did not. Splice in the incremented string region.\n\t\t\t\tconst newUpperChunk = padToLengthWithZeros(newUpperNumber.toString(16), 12);\n\t\t\t\tnewUuid = [\n\t\t\t\t\t`${ChunkMath.Upper.hyphenate(newUpperChunk)}-4${ChunkMath.Variant.hyphenate(\n\t\t\t\t\t\tnewVariantChunkString\n\t\t\t\t\t)}`,\n\t\t\t\t\tremainder,\n\t\t\t\t];\n\t\t\t}\n\t\t} else {\n\t\t\t// The variant chunk did not overflow, so just splice it back in.\n\t\t\tnewUuid = [\n\t\t\t\t`${ChunkMath.Upper.slice(stringEntry)}-4${ChunkMath.Variant.hyphenate(newVariantChunkString)}`,\n\t\t\t\tremainder,\n\t\t\t];\n\t\t}\n\t}\n\n\treturn newUuid as readonly [string, number] as NumericUuid;\n}\n\nnamespace ChunkMath {\n\t/*\n\t * Recall the UUID diagram from the top of this file which describes the layout of a Numeric UUID. To implement addition, we define\n\t * another region called the \"variant chunk\" which overlaps with the \"string\" region. Note that it is just beneath the required v4 uuid\n\t * version identifier (the 13th nibble 'V' which is always '4' in a v4 UUID) and just above the \"number\" region of the layout. It\n\t * contains inside of it the v4 UUID variant identifier bits as well (see https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.1).\n\t *\n\t * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n\t * SSSSSSSS SSSS SSSS SSS - array[0]: string\n\t * N NNNNNNNNNNNN - array[1]: integer\n\t * VVV-VVV - the variant chunk\n\t *\n\t * By defining the variant chunk in this way it is simple to splice in the v4 UUID version identifier ('V') just above it and any\n\t * \"bit math\" required due to the fact that the variant identifier bits ('v') do not fill up an entire nibble is handled within it.\n\t * The variant chunk is made up of 6 nibbles. Note the \"vv\" which denotes the two bits used for the v4 UUID variant identifier:\n\t *\n\t * AAAA BBBB CCCC vvDD EEEE FFFF\n\t *\n\t * Since we'll be needing to \"skip\" the variant bits (\"vv\") when doing addition, we define a a few masks which will be used below to\n\t * separate the variant chunk into pieces before recombining it:\n\t */\n\n\t// AAAA BBBB CCCC vvDD EEEE FFFF\n\tconst upperVariantChunkMask = 0xfff000; // XXXX XXXX XXXX\n\tconst variantBitMask = 0x800; // XX\n\tconst middleVariantChunkMask = 0x300; // XX\n\tconst lowerVariantChunkMask = 0xff; // XXXX XXXX\n\n\t/** The maximum numeric value that can be represented by the numerically relevant bits in the variant chunk */\n\tconst maxVariantNumber = 2 ** 22 - 1;\n\n\texport const twentyThirdBit = 2 ** 22;\n\n\t/** the upper chunk, denoted by 'U's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL */\n\texport namespace Upper {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 8) + stringEntry.slice(9, 13);\n\t\t}\n\n\t\texport function hyphenate(upperChunk: string): string {\n\t\t\treturn `${upperChunk.slice(0, 8)}-${upperChunk.slice(8)}`;\n\t\t}\n\n\t\texport function slice(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 13);\n\t\t}\n\t}\n\n\t/** the variant chunk, denoted by 'V's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL */\n\texport namespace Variant {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(15, 18) + stringEntry.slice(19, 22);\n\t\t}\n\n\t\texport function hyphenate(variantChunk: string): string {\n\t\t\treturn `${variantChunk.slice(0, 3)}-${variantChunk.slice(3)}`;\n\t\t}\n\t}\n\n\t/** the lower chunk, denoted by 'L's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL */\n\texport namespace Lower {\n\t\texport function parse(stableId: StableId): string {\n\t\t\treturn stableId.slice(stringEntryLength, stringEntryLength + 1) + stableId.slice(stringEntryLength + 2);\n\t\t}\n\n\t\texport function hyphenate(lowerChunk: string): string {\n\t\t\treturn `${lowerChunk.slice(0, 1)}-${lowerChunk.slice(1)}`;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the number representation of the given bits corresponding to the variant chunk. The value is derived by\n\t * parsing all bits except for reserved bits (i.e. the variant bits).\n\t * @param variantChunk - the variantChunk\n\t */\n\texport function getNumericValue(variantChunk: string): number {\n\t\tconst variantChunkBits = Number.parseInt(variantChunk, 16);\n\t\tconst upperVariantBits = (variantChunkBits & upperVariantChunkMask) >> 2;\n\t\tconst middleVariantBits = variantChunkBits & middleVariantChunkMask;\n\t\tconst lowerVariantBits = variantChunkBits & lowerVariantChunkMask;\n\t\treturn upperVariantBits + middleVariantBits + lowerVariantBits;\n\t}\n\n\t/**\n\t * Given the string portion of a numeric uuid, add one to it.\n\t * @returns the resulting hex string and whether or not the new value overflowed, i.e. it exceeds `maxVariantNumber`. In this case,\n\t * the resulting hex string will wrap around to its minimum value '000b00'\n\t */\n\texport function increment(stringEntry: string): [newVariantChunk: string, overflowed: boolean] {\n\t\t// To implement addition, the variant identifier bits are extracted from the variant chunk, the chunk is interpreted as a number,\n\t\t// that number is incremented by 1, and then the variant identifier bits are returned as we convert the number back into a hex\n\t\t// string.\n\n\t\t// This diagram may be helpful for seeing how the nibbles line up before and after the variant identifier bits are extracted. The\n\t\t// letters used for each nibble (\"AAAA\", \"BBBB\") etc. are arbitrary and are simply there to differentiate the nibbles as they shift.\n\t\t// --------------------------------\n\t\t// 1. AAAA BBBB CCCC vvDD EEEE FFFF\n\t\t// 2. AA AABB BBCC CCDD EEEE FFFF\n\t\t// 3. AA AABB BBCC CCDD EEEE FFFF\n\t\t// + 1\n\t\t// = GG GGHH HHII IIJJ JJKK KKLL\n\t\t// 4. GGGG HHHH IIII vvJJ JJKK KKLL\n\n\t\t// 1. The variant chunk is given as a 6 character (6 nibble) hex string, where the fourth nibble contains the variant bits\n\t\t// 2. The numerically important bits (i.e. not the variant identifier bits vv which are constant) are extracted into a single number\n\t\tconst variantChunk = Variant.parse(stringEntry);\n\t\tconst variantNumber = getNumericValue(variantChunk);\n\t\tassert(variantNumber <= maxVariantNumber);\n\t\t// 3. Add one to the variant number to produce our new variant number.\n\t\tconst newVariantNumber = variantNumber + 1;\n\t\t// 4. The variant identifier bits are added back into the number, which is then turned back into a hex string\n\t\tconst newUpperVariantBits = (newVariantNumber & (upperVariantChunkMask >> 2)) << 2;\n\t\tconst newMiddleVariantBits = (newVariantNumber & middleVariantChunkMask) | variantBitMask; // Add the variant bits back in\n\t\tconst newLowerVariantBits = newVariantNumber & lowerVariantChunkMask;\n\t\tconst newVariantChunkBits = newUpperVariantBits + newMiddleVariantBits + newLowerVariantBits;\n\t\tconst newVariantChunk = padToLengthWithZeros(newVariantChunkBits.toString(16), variantChunk.length);\n\t\treturn [newVariantChunk, newVariantNumber > maxVariantNumber];\n\t}\n}\n\nconst maxUpperUuid = 'ffffffff-ffff-4fff-bf';\nconst maxNibbleCount = [...maxUpperUuid].filter((n) => n === 'f').length;\nconst newNibbles = ['7', 'b', 'd', 'e'];\nfunction isMaxUpperNibble(index: number): boolean {\n\treturn maxUpperUuid.charAt(index) === 'f';\n}\n\n/**\n * Any session uuid with all of its highish bits set is in danger of overflowing after fewer than 2^53 increments.\n * By zeroing one of those bits at random, potential overflow is prevented.\n */\nexport function ensureSessionUuid(uuid: StableId): SessionId {\n\tif (uuid.startsWith(maxUpperUuid)) {\n\t\tconst targetNibble = Math.floor(Math.random() * maxNibbleCount);\n\t\tlet actualIndex = 0;\n\t\tfor (let nibbleIndex = 0; nibbleIndex < targetNibble && !isMaxUpperNibble(actualIndex); actualIndex += 1) {\n\t\t\tif (isMaxUpperNibble(actualIndex)) {\n\t\t\t\tnibbleIndex++;\n\t\t\t}\n\t\t}\n\n\t\tconst newNibble = newNibbles[Math.floor(Math.random() * newNibbles.length)]; // Randomly choose a bit to zero\n\t\tconst newUuid = uuid.slice(0, actualIndex) + newNibble + uuid.slice(actualIndex + 1);\n\t\treturn newUuid as SessionId;\n\t}\n\n\treturn uuid as SessionId;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NumericUuid.js","sourceRoot":"","sources":["../../src/id-compressor/NumericUuid.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,sCAAyC;AAEzC,oDAAoD;AAmBpD,MAAM,wBAAwB,GAAG,EAAE,CAAC,CAAC,8BAA8B;AACnE,MAAM,2BAA2B,GAAG,wBAAwB,GAAG,CAAC,CAAC;AACjE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,qBAAqB,GAAG,CAAC,IAAI,wBAAwB,GAAG,CAAC,CAAC;AAChE,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,CAAC;AAE9B;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,CAAc,EAAE,CAAc,EAAE,QAAgB;IAChF,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAErC,IAAI,YAAY,KAAK,YAAY,EAAE;QAClC,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;QAC3C,IAAI,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,QAAQ,EAAE;YAC9C,OAAO,UAAU,CAAC;SAClB;QACD,OAAO,SAAS,CAAC;KACjB;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7E,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7E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,IAAI,WAAW,GAAG,CAAC,EAAE,WAAW,GAAG,YAAY,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,WAAW,IAAI,CAAC,EAAE;YACzG,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE;gBAClC,WAAW,EAAE,CAAC;aACd;SACD;QAED,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gCAAgC;QAC7G,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACrF,OAAO,OAAoB,CAAC;KAC5B;IAED,OAAO,IAAiB,CAAC;AAC1B,CAAC;AAhBD,8CAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert, fail } from '../Common';\nimport { SessionId, StableId } from '../Identifiers';\nimport { generateStableId } from '../UuidUtilities';\n\n/**\n * A UUID (128 bit identifier) optimized for use as a 128 bit unsigned integer with fast addition and toString operations.\n * The string entry is the upper 76 bits of the uuid and the integer entry holds the lower 52 bits:\n *\n * ```\n * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n * SSSSSSSS-SSSS-SSSS-SSS - array[0]: string\n * N NNNNNNNNNNNN - array[1]: integer\n * ```\n *\n * The integer keeps the common case cost of incrementing and computing deltas very low.\n * The string optimizes toString by caching the the majority of the resulting string.\n */\nexport type NumericUuid = readonly [string, number] & {\n\treadonly NumericUuid: '9132ea20-a811-4756-85f8-aa6da5ca90f8';\n};\n\nconst bitsInNumericUuidInteger = 52; // Not tunable. Do not change.\nconst nibblesInNumericUuidInteger = bitsInNumericUuidInteger / 4;\nconst stringEntryLength = 22;\nconst maxNumericUuidInteger = 2 ** bitsInNumericUuidInteger - 1;\nconst fiftyThirdBit = 2 ** 52;\n\n/**\n * Calculates the numeric delta between a and b (i.e. a - b).\n * @param a - an uuid\n * @param b - an other uuid\n * @param maxDelta - the maximum integer delta (inclusive) to tolerate.\n * @returns undefined if the delta is negative or greater than `maxDelta`\n */\nexport function getPositiveDelta(a: NumericUuid, b: NumericUuid, maxDelta: number): number | undefined {\n\tconst [stringEntryA, lowNumberA] = a;\n\tconst [stringEntryB, lowNumberB] = b;\n\n\tif (stringEntryA === stringEntryB) {\n\t\tconst difference = lowNumberA - lowNumberB;\n\t\tif (difference >= 0 && difference <= maxDelta) {\n\t\t\treturn difference;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tconst highNumberA = Number.parseInt(ChunkMath.Upper.parse(stringEntryA), 16);\n\tconst highNumberB = Number.parseInt(ChunkMath.Upper.parse(stringEntryB), 16);\n\n\tlet subtractHigh = highNumberA - highNumberB;\n\tif (Math.abs(subtractHigh) > 1) {\n\t\t// If the high bits differ by more than 1, then there is no chance that any lower bits could compensate\n\t\treturn undefined;\n\t}\n\n\tlet midNumberA = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryA));\n\tconst midNumberB = ChunkMath.getNumericValue(ChunkMath.Variant.parse(stringEntryB));\n\n\tlet subtractLow = lowNumberA - lowNumberB;\n\tif (subtractLow < 0) {\n\t\tmidNumberA -= 1;\n\t\tsubtractLow += fiftyThirdBit;\n\t}\n\n\tlet subtractMid = midNumberA - midNumberB;\n\tif (subtractMid < 0) {\n\t\tsubtractHigh -= 1;\n\t\tsubtractMid += ChunkMath.twentyThirdBit;\n\t}\n\n\tif (subtractHigh !== 0) {\n\t\t// a < b, no positive delta, or\n\t\t// a > b by much more than MAX_SAFE_INTEGER\n\t\treturn undefined;\n\t}\n\n\tif (subtractMid > 1) {\n\t\treturn undefined;\n\t} else {\n\t\tconst trueDelta = fiftyThirdBit * subtractMid + subtractLow;\n\t\treturn trueDelta > maxDelta ? undefined : trueDelta;\n\t}\n}\n\n// Pre-allocated array of strings of zeros.\n// Used to pad hex strings up to 52 bits\nconst zeros: string[] = [];\nfor (let i = 0; i < nibblesInNumericUuidInteger; i++) {\n\tzeros.push('0'.repeat(i));\n}\n\nfunction padToLengthWithZeros(str: string, count: number): string {\n\treturn str.length === count ? str : zeros[count - str.length] + str;\n}\n\n/**\n * @param offset - an optional offset to increment the returned StableId\n * @returns the string representation of a `NumericUuid`.\n */\nexport function stableIdFromNumericUuid(uuid: NumericUuid, offset = 0): StableId {\n\tconst lowerAdd = uuid[1] + offset;\n\t// Common fast-path\n\tif (lowerAdd <= maxNumericUuidInteger) {\n\t\tconst lowerString = padToLengthWithZeros(lowerAdd.toString(16), nibblesInNumericUuidInteger);\n\t\treturn `${uuid[0] + lowerString.slice(0, 1)}-${lowerString.slice(1)}` as StableId;\n\t}\n\treturn stableIdFromNumericUuid(incrementUuid(uuid, offset));\n}\n\n/**\n * @param stableId - a minimal uuid string\n * @returns a numeric representation of `stableId`.\n */\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuid: (string | number)[] = new Array(2);\n\tuuid[0] = stableId.slice(0, stringEntryLength);\n\tuuid[1] = Number.parseInt(ChunkMath.Lower.parse(stableId), 16);\n\treturn uuid as readonly (number | string)[] as NumericUuid;\n}\n\n/**\n * Creates a session base ID.\n * This method (rather than standard uuid generation methods) should be used to generate session IDs.\n */\nexport function createSessionId(): SessionId {\n\treturn ensureSessionUuid(generateStableId());\n}\n\n/**\n * Compares numeric uuids for equality.\n */\nexport function numericUuidEquals(a: NumericUuid, b: NumericUuid): boolean {\n\treturn a[0] === b[0] && a[1] === b[1];\n}\n\n/**\n * The maximum value that can be contained in the upper string region of a numeric UUID (i.e. the string region excluding the version\n * nibble and the variant chunk)\n */\nconst maxUpperNumber = 2 ** 48 - 1;\n\n/**\n * Increments the uuid. `amount` must be a positive integer.\n * @returns the result of incrementing the uuid by `amount`.\n */\nexport function incrementUuid(uuid: NumericUuid, amount: number): NumericUuid {\n\t/*\n\t * UUIDs incremented beyond the max UUID \"ffffffff-ffff-4fff-bfff-ffffffffffff\" will cause a failure.\n\t * Also, some reserved bits of the v4 UUID must be treated as immutable (e.g. the version and\n\t * variant bits) and thus must not be incremented.\n\t */\n\tlet newUuid: [string, number];\n\tconst result = uuid[1] + amount;\n\tif (result <= maxNumericUuidInteger) {\n\t\t// The new number still fits within the number region of a numeric UUID.\n\t\t// Incrementing is usually done with small amounts, so this is the dominantly common case.\n\t\tnewUuid = [uuid[0], result];\n\t} else {\n\t\t// The numeric UUID's number region has overflowed. We will need to carry the overflow into the variant chunk (see `VariantChunk`).\n\t\t/** The amount left over after filling up the rest of the uuid's number region with the increment amount */\n\t\tconst remainder = amount - (maxNumericUuidInteger - uuid[1]) - 1;\n\t\tconst stringEntry = uuid[0];\n\t\tconst [newVariantChunkString, carried] = ChunkMath.increment(stringEntry);\n\n\t\tif (carried) {\n\t\t\t// The variant chunk itself also overflowed. We'll need to carry the overflow further, into the upper string region of the UUID.\n\t\t\tconst upperString = ChunkMath.Upper.parse(stringEntry);\n\t\t\tconst upperNumber = Number.parseInt(upperString, 16);\n\t\t\tassert(upperNumber <= maxUpperNumber);\n\t\t\tconst newUpperNumber = upperNumber + 1;\n\t\t\tif (newUpperNumber > maxUpperNumber) {\n\t\t\t\tfail('Exceeded maximum numeric UUID');\n\t\t\t} else {\n\t\t\t\t// The variant chunk overflowed but the upper string region did not. Splice in the incremented string region.\n\t\t\t\tconst newUpperChunk = padToLengthWithZeros(newUpperNumber.toString(16), 12);\n\t\t\t\tnewUuid = [\n\t\t\t\t\t`${ChunkMath.Upper.hyphenate(newUpperChunk)}-4${ChunkMath.Variant.hyphenate(\n\t\t\t\t\t\tnewVariantChunkString\n\t\t\t\t\t)}`,\n\t\t\t\t\tremainder,\n\t\t\t\t];\n\t\t\t}\n\t\t} else {\n\t\t\t// The variant chunk did not overflow, so just splice it back in.\n\t\t\tnewUuid = [\n\t\t\t\t`${ChunkMath.Upper.slice(stringEntry)}-4${ChunkMath.Variant.hyphenate(newVariantChunkString)}`,\n\t\t\t\tremainder,\n\t\t\t];\n\t\t}\n\t}\n\n\treturn newUuid as readonly [string, number] as NumericUuid;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nnamespace ChunkMath {\n\t/*\n\t * Recall the UUID diagram from the top of this file which describes the layout of a Numeric UUID. To implement addition, we define\n\t * another region called the \"variant chunk\" which overlaps with the \"string\" region. Note that it is just beneath the required v4 uuid\n\t * version identifier (the 13th nibble 'V' which is always '4' in a v4 UUID) and just above the \"number\" region of the layout. It\n\t * contains inside of it the v4 UUID variant identifier bits as well (see https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.1).\n\t *\n\t * UUUUUUUU-UUUU-VUUU-vUUU-UUUUUUUUUUUU - the uuid\n\t * SSSSSSSS SSSS SSSS SSS - array[0]: string\n\t * N NNNNNNNNNNNN - array[1]: integer\n\t * VVV-VVV - the variant chunk\n\t *\n\t * By defining the variant chunk in this way it is simple to splice in the v4 UUID version identifier ('V') just above it and any\n\t * \"bit math\" required due to the fact that the variant identifier bits ('v') do not fill up an entire nibble is handled within it.\n\t * The variant chunk is made up of 6 nibbles. Note the \"vv\" which denotes the two bits used for the v4 UUID variant identifier:\n\t *\n\t * AAAA BBBB CCCC vvDD EEEE FFFF\n\t *\n\t * Since we'll be needing to \"skip\" the variant bits (\"vv\") when doing addition, we define a a few masks which will be used below to\n\t * separate the variant chunk into pieces before recombining it:\n\t */\n\n\t// AAAA BBBB CCCC vvDD EEEE FFFF\n\tconst upperVariantChunkMask = 0xfff000; // XXXX XXXX XXXX\n\tconst variantBitMask = 0x800; // XX\n\tconst middleVariantChunkMask = 0x300; // XX\n\tconst lowerVariantChunkMask = 0xff; // XXXX XXXX\n\n\t/** The maximum numeric value that can be represented by the numerically relevant bits in the variant chunk */\n\tconst maxVariantNumber = 2 ** 22 - 1;\n\n\texport const twentyThirdBit = 2 ** 22;\n\n\t/**\n\t * The upper chunk, denoted by 'U's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-namespace\n\texport namespace Upper {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 8) + stringEntry.slice(9, 13);\n\t\t}\n\n\t\texport function hyphenate(upperChunk: string): string {\n\t\t\treturn `${upperChunk.slice(0, 8)}-${upperChunk.slice(8)}`;\n\t\t}\n\n\t\texport function slice(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(0, 13);\n\t\t}\n\t}\n\n\t/**\n\t * The variant chunk, denoted by 'V's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-namespace\n\texport namespace Variant {\n\t\texport function parse(stringEntry: string): string {\n\t\t\treturn stringEntry.slice(15, 18) + stringEntry.slice(19, 22);\n\t\t}\n\n\t\texport function hyphenate(variantChunk: string): string {\n\t\t\treturn `${variantChunk.slice(0, 3)}-${variantChunk.slice(3)}`;\n\t\t}\n\t}\n\n\t/**\n\t * The lower chunk, denoted by 'L's in UUUUUUUU-UUUU-VVVV-vVVL-LLLLLLLLLLLL\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-namespace\n\texport namespace Lower {\n\t\texport function parse(stableId: StableId): string {\n\t\t\treturn stableId.slice(stringEntryLength, stringEntryLength + 1) + stableId.slice(stringEntryLength + 2);\n\t\t}\n\n\t\texport function hyphenate(lowerChunk: string): string {\n\t\t\treturn `${lowerChunk.slice(0, 1)}-${lowerChunk.slice(1)}`;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the number representation of the given bits corresponding to the variant chunk. The value is derived by\n\t * parsing all bits except for reserved bits (i.e. the variant bits).\n\t * @param variantChunk - the variantChunk\n\t */\n\texport function getNumericValue(variantChunk: string): number {\n\t\tconst variantChunkBits = Number.parseInt(variantChunk, 16);\n\t\tconst upperVariantBits = (variantChunkBits & upperVariantChunkMask) >> 2;\n\t\tconst middleVariantBits = variantChunkBits & middleVariantChunkMask;\n\t\tconst lowerVariantBits = variantChunkBits & lowerVariantChunkMask;\n\t\treturn upperVariantBits + middleVariantBits + lowerVariantBits;\n\t}\n\n\t/**\n\t * Given the string portion of a numeric uuid, add one to it.\n\t * @returns the resulting hex string and whether or not the new value overflowed, i.e. it exceeds `maxVariantNumber`. In this case,\n\t * the resulting hex string will wrap around to its minimum value '000b00'\n\t */\n\texport function increment(stringEntry: string): [newVariantChunk: string, overflowed: boolean] {\n\t\t// To implement addition, the variant identifier bits are extracted from the variant chunk, the chunk is interpreted as a number,\n\t\t// that number is incremented by 1, and then the variant identifier bits are returned as we convert the number back into a hex\n\t\t// string.\n\n\t\t// This diagram may be helpful for seeing how the nibbles line up before and after the variant identifier bits are extracted. The\n\t\t// letters used for each nibble (\"AAAA\", \"BBBB\") etc. are arbitrary and are simply there to differentiate the nibbles as they shift.\n\t\t// --------------------------------\n\t\t// 1. AAAA BBBB CCCC vvDD EEEE FFFF\n\t\t// 2. AA AABB BBCC CCDD EEEE FFFF\n\t\t// 3. AA AABB BBCC CCDD EEEE FFFF\n\t\t// + 1\n\t\t// = GG GGHH HHII IIJJ JJKK KKLL\n\t\t// 4. GGGG HHHH IIII vvJJ JJKK KKLL\n\n\t\t// 1. The variant chunk is given as a 6 character (6 nibble) hex string, where the fourth nibble contains the variant bits\n\t\t// 2. The numerically important bits (i.e. not the variant identifier bits vv which are constant) are extracted into a single number\n\t\tconst variantChunk = Variant.parse(stringEntry);\n\t\tconst variantNumber = getNumericValue(variantChunk);\n\t\tassert(variantNumber <= maxVariantNumber);\n\t\t// 3. Add one to the variant number to produce our new variant number.\n\t\tconst newVariantNumber = variantNumber + 1;\n\t\t// 4. The variant identifier bits are added back into the number, which is then turned back into a hex string\n\t\tconst newUpperVariantBits = (newVariantNumber & (upperVariantChunkMask >> 2)) << 2;\n\t\tconst newMiddleVariantBits = (newVariantNumber & middleVariantChunkMask) | variantBitMask; // Add the variant bits back in\n\t\tconst newLowerVariantBits = newVariantNumber & lowerVariantChunkMask;\n\t\tconst newVariantChunkBits = newUpperVariantBits + newMiddleVariantBits + newLowerVariantBits;\n\t\tconst newVariantChunk = padToLengthWithZeros(newVariantChunkBits.toString(16), variantChunk.length);\n\t\treturn [newVariantChunk, newVariantNumber > maxVariantNumber];\n\t}\n}\n\nconst maxUpperUuid = 'ffffffff-ffff-4fff-bf';\nconst maxNibbleCount = [...maxUpperUuid].filter((n) => n === 'f').length;\nconst newNibbles = ['7', 'b', 'd', 'e'];\nfunction isMaxUpperNibble(index: number): boolean {\n\treturn maxUpperUuid.charAt(index) === 'f';\n}\n\n/**\n * Any session uuid with all of its highish bits set is in danger of overflowing after fewer than 2^53 increments.\n * By zeroing one of those bits at random, potential overflow is prevented.\n */\nexport function ensureSessionUuid(uuid: StableId): SessionId {\n\tif (uuid.startsWith(maxUpperUuid)) {\n\t\tconst targetNibble = Math.floor(Math.random() * maxNibbleCount);\n\t\tlet actualIndex = 0;\n\t\tfor (let nibbleIndex = 0; nibbleIndex < targetNibble && !isMaxUpperNibble(actualIndex); actualIndex += 1) {\n\t\t\tif (isMaxUpperNibble(actualIndex)) {\n\t\t\t\tnibbleIndex++;\n\t\t\t}\n\t\t}\n\n\t\tconst newNibble = newNibbles[Math.floor(Math.random() * newNibbles.length)]; // Randomly choose a bit to zero\n\t\tconst newUuid = uuid.slice(0, actualIndex) + newNibble + uuid.slice(actualIndex + 1);\n\t\treturn newUuid as SessionId;\n\t}\n\n\treturn uuid as SessionId;\n}\n"]}
|
|
@@ -10,6 +10,7 @@ import { SerializedSessionIdNormalizer } from './persisted-types';
|
|
|
10
10
|
* that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.
|
|
11
11
|
* Below is an example to illustrate how various mappings can arise:
|
|
12
12
|
*
|
|
13
|
+
* ```
|
|
13
14
|
* +- Creation Index
|
|
14
15
|
* / +- Locals
|
|
15
16
|
* / / +- Finals
|
|
@@ -26,13 +27,16 @@ import { SerializedSessionIdNormalizer } from './persisted-types';
|
|
|
26
27
|
* 8 | | 13
|
|
27
28
|
* 9 | | 14
|
|
28
29
|
* 10 | -11 | ----- A local ID is allocated. It has no corresponding final ID since it has not been acked.
|
|
30
|
+
* ```
|
|
29
31
|
*
|
|
30
32
|
* 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.
|
|
31
33
|
* These kinds of "gaps" occur due to the timing of allocation calls on the client and how they relate to finalization/cluster creation,
|
|
32
34
|
* which depends on receiving an ack/sequence number from the server. Given this context, "session space" can be thought of as:
|
|
33
35
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
+
* ```
|
|
37
|
+
* for each index in the range of IDs created by a session:
|
|
38
|
+
* the local form if it exists, otherwise the final form
|
|
39
|
+
* ```
|
|
36
40
|
*
|
|
37
41
|
* This class is designed to efficiently build and query these mappings by leveraging the facts that much of the range (in both local and
|
|
38
42
|
* final space) is uninterrupted by "gaps" and can be compactly represented by a (first, last) pair and is easily binary searched for
|
|
@@ -93,7 +97,8 @@ export declare class SessionIdNormalizer<TRangeObject> {
|
|
|
93
97
|
* non-contiguous final ID without a local form:
|
|
94
98
|
* Locals: [-1, -2, X, -4, X]
|
|
95
99
|
* Finals: [ 0, 1, 2, 5, 9]
|
|
96
|
-
*
|
|
100
|
+
*
|
|
101
|
+
* ^final ID 9 is not contiguous and does not have a corresponding local ID
|
|
97
102
|
*/
|
|
98
103
|
addFinalIds(firstFinal: FinalCompressedId, lastFinal: FinalCompressedId, rangeObject: TRangeObject): void;
|
|
99
104
|
/**
|
|
@@ -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,gBAAgB,CAAC;AAEhG,OAAO,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wB,CAAC;IAwBhE,SAAS,IAAI,6BAA6B;WAkBnC,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;CA+BV"}
|
|
@@ -14,6 +14,7 @@ const AppendOnlySortedMap_1 = require("./AppendOnlySortedMap");
|
|
|
14
14
|
* that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.
|
|
15
15
|
* Below is an example to illustrate how various mappings can arise:
|
|
16
16
|
*
|
|
17
|
+
* ```
|
|
17
18
|
* +- Creation Index
|
|
18
19
|
* / +- Locals
|
|
19
20
|
* / / +- Finals
|
|
@@ -30,13 +31,16 @@ const AppendOnlySortedMap_1 = require("./AppendOnlySortedMap");
|
|
|
30
31
|
* 8 | | 13
|
|
31
32
|
* 9 | | 14
|
|
32
33
|
* 10 | -11 | ----- A local ID is allocated. It has no corresponding final ID since it has not been acked.
|
|
34
|
+
* ```
|
|
33
35
|
*
|
|
34
36
|
* 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.
|
|
35
37
|
* These kinds of "gaps" occur due to the timing of allocation calls on the client and how they relate to finalization/cluster creation,
|
|
36
38
|
* which depends on receiving an ack/sequence number from the server. Given this context, "session space" can be thought of as:
|
|
37
39
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* ```
|
|
41
|
+
* for each index in the range of IDs created by a session:
|
|
42
|
+
* the local form if it exists, otherwise the final form
|
|
43
|
+
* ```
|
|
40
44
|
*
|
|
41
45
|
* This class is designed to efficiently build and query these mappings by leveraging the facts that much of the range (in both local and
|
|
42
46
|
* final space) is uninterrupted by "gaps" and can be compactly represented by a (first, last) pair and is easily binary searched for
|
|
@@ -216,7 +220,8 @@ class SessionIdNormalizer {
|
|
|
216
220
|
* non-contiguous final ID without a local form:
|
|
217
221
|
* Locals: [-1, -2, X, -4, X]
|
|
218
222
|
* Finals: [ 0, 1, 2, 5, 9]
|
|
219
|
-
*
|
|
223
|
+
*
|
|
224
|
+
* ^final ID 9 is not contiguous and does not have a corresponding local ID
|
|
220
225
|
*/
|
|
221
226
|
addFinalIds(firstFinal, lastFinal, rangeObject) {
|
|
222
227
|
var _a, _b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionIdNormalizer.js","sourceRoot":"","sources":["../../src/id-compressor/SessionIdNormalizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,8DAA8D;AAE9D,sCAAsG;AAEtG,+DAAkE;AAGlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAa,mBAAmB;IAkB/B,YAAoC,mBAAmB,KAAK;QAAxB,qBAAgB,GAAhB,gBAAgB,CAAQ;QAjBpD,gBAAW,GAAsB,CAAC,CAAsB,CAAC;QAChD,aAAQ,GAIrB,IAAI,+CAAyB,CAChC,qCAA4B,EAC5B,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,EAAE;YACpB,IAAI,WAAW,KAAK,SAAS,EAAE;gBAC9B,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;gBACzC,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;aACzC;YACD,OAAO,MAAM,CAAC,iBAAsC,CAAC;QACtD,CAAC,EACD,6BAAoB,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;YAC7B,MAAM,CAAC,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C;AAED,QAAQ,CAAC,CAAC,OAAO,CAChB,UAA6B,EAC7B,WAAkD;IAElD,IAAI,WAAW,KAAK,SAAS,EAAE;QAC9B,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;YAC/B,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;SAChC;aAAM;YACN,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE;gBAC1C,MAAM,KAAK,CAAC;aACZ;SACD;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/restrict-plus-operands */\n\nimport { assert, compareFiniteNumbers, compareFiniteNumbersReversed, fail, Mutable } from '../Common';\nimport { FinalCompressedId, LocalCompressedId, SessionSpaceCompressedId } from '../Identifiers';\nimport { AppendOnlyDoublySortedMap } from './AppendOnlySortedMap';\nimport { SerializedSessionIdNormalizer } from './persisted-types';\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 * +- 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 * 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 * \t\tfor each index in the range of IDs created by a session:\n * \t\t\tthe local form if it exists, otherwise the final form\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, '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, '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 a final ID with this normalizer.\n\t * If there are any local IDs at the tip of session-space that do not have a corresponding final, it will be registered (aligned) with\n\t * the first of those. Otherwise, will be registered as the next ID in session space in creation order. An example:\n\t *\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 * 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 * ^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, '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 isSingle = isSingleRange(finalRanges);\n\t\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\t\tlet firstAlignedLocal: LocalCompressedId;\n\t\t\tif (isSingle) {\n\t\t\t\tfirstAlignedLocal = firstLocal;\n\t\t\t\tlastFinalRange = finalRanges;\n\t\t\t} else {\n\t\t\t\t[firstAlignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t\t}\n\n\t\t\tconst [firstAlignedFinal, lastAlignedFinal] = lastFinalRange;\n\t\t\tconst lastAlignedLocal = firstAlignedLocal - (lastAlignedFinal - firstAlignedFinal);\n\t\t\tnextLocal = Math.min(\n\t\t\t\tthis.nextLocalId,\n\t\t\t\tlastAlignedLocal - (lastFinal - firstFinal) - 2\n\t\t\t) 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 (isSingle) {\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, '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 * 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> = { localRanges: [], nextLocalId: this.nextLocalId };\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, '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 &&\n\t\t\t\t\t\tlastFinalA === lastFinalB &&\n\t\t\t\t\t\tcompareRangeObjects(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,8DAA8D;AAE9D,sCAAsG;AAEtG,+DAAkE;AAGlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,mBAAmB;IAkB/B,YAAoC,mBAAmB,KAAK;QAAxB,qBAAgB,GAAhB,gBAAgB,CAAQ;QAjBpD,gBAAW,GAAsB,CAAC,CAAsB,CAAC;QAChD,aAAQ,GAIrB,IAAI,+CAAyB,CAChC,qCAA4B,EAC5B,CAAC,CAAC,CAAC,EAAE,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,CAAC;KACjC;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;QAC9B,OAAO,SAAS,CAAC;KACjB;IACD,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;QAC/B,IAAI,OAAO,GAAG,UAAU,EAAE;YACzB,OAAO,SAAS,CAAC;SACjB;QACD,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;KACjC;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;QAC9B,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;YAC/B,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;SAChC;aAAM;YACN,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE;gBAC1C,MAAM,KAAK,CAAC;aACZ;SACD;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/restrict-plus-operands */\n\nimport { assert, compareFiniteNumbers, compareFiniteNumbersReversed, fail, Mutable } from '../Common';\nimport { FinalCompressedId, LocalCompressedId, SessionSpaceCompressedId } from '../Identifiers';\nimport { AppendOnlyDoublySortedMap } from './AppendOnlySortedMap';\nimport { SerializedSessionIdNormalizer } from './persisted-types';\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, '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, '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 a final ID with this normalizer.\n\t * If there are any local IDs at the tip of session-space that do not have a corresponding final, it will be registered (aligned) with\n\t * the first of those. Otherwise, will be registered as the next ID in session space in creation order. An example:\n\t *\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 * 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, '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 isSingle = isSingleRange(finalRanges);\n\t\t\tlet lastFinalRange: FinalRange<TRangeObject>;\n\t\t\tlet firstAlignedLocal: LocalCompressedId;\n\t\t\tif (isSingle) {\n\t\t\t\tfirstAlignedLocal = firstLocal;\n\t\t\t\tlastFinalRange = finalRanges;\n\t\t\t} else {\n\t\t\t\t[firstAlignedLocal, lastFinalRange] = finalRanges.last() ?? fail('Map should be non-empty.');\n\t\t\t}\n\n\t\t\tconst [firstAlignedFinal, lastAlignedFinal] = lastFinalRange;\n\t\t\tconst lastAlignedLocal = firstAlignedLocal - (lastAlignedFinal - firstAlignedFinal);\n\t\t\tnextLocal = Math.min(\n\t\t\t\tthis.nextLocalId,\n\t\t\t\tlastAlignedLocal - (lastFinal - firstFinal) - 2\n\t\t\t) 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 (isSingle) {\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, '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 * 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> = { localRanges: [], nextLocalId: this.nextLocalId };\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, '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 &&\n\t\t\t\t\t\tlastFinalA === lastFinalB &&\n\t\t\t\t\t\tcompareRangeObjects(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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AACH,MAAM,WAAW,wCAAyC,SAAQ,sBAAsB;IACvF,QAAQ,CAAC,cAAc,EAAE,sCAAsC,CAAC;IAChE,qEAAqE;IACrE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC;IACnC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;CACvC;AAED,oBAAY,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,CAAC;AAGrE,yBAAiB,eAAe,CAAC;IAChC,KAAY,GAAG,GACZ;QACA,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;KAC7B,GACD,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC;KAC9B,GAAG,YAAY,CAAC,CAAC;IAErB,UAAiB,YAAY;QAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;KAC9B;IAED,KAAY,QAAQ,GAAG,SAAS,CAAC,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvE,KAAY,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;CAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0.0.1.js","sourceRoot":"","sources":["../../../src/id-compressor/persisted-types/0.0.1.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tAttributionId,\n\tFinalCompressedId,\n\tLocalCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from '../../Identifiers';\n\n/**\n * A serialized ID allocation session for an `IdCompressor`.\n */\nexport type SerializedSessionData = readonly [\n\t/**\n\t * The ID of the session.\n\t */\n\tsessionId: SessionId,\n\n\t/**\n\t * Index into the serialized AttributionIDs array; points to the attribution ID provided for this session\n\t */\n\tattributionId?: number\n];\n\nexport type SerializedClusterOverrides = readonly [\n\t/** The overridden final ID, represented as an index into the cluster's ID range */\n\toverriddenFinalIndex: number, // A cluster with base UUID '...beef' and an `overriddenFinalIndex` of 3 would correspond to '...bef2'\n\t/** The override string */\n\toverride: string,\n\t/** The first ID that was finalized and associated with this override, set only if different than the `overriddenFinalIndex` */\n\toverriddenId?: FinalCompressedId\n][];\n\n/**\n * A serialized final ID cluster.\n */\nexport type SerializedCluster = readonly [\n\t/**\n\t * Index into the serialized sessions array. Can be converted into a baseUuid via its order in `clusters`.\n\t * If negative, then this cluster was created by the local session.\n\t */\n\tsessionIndex: number,\n\n\t/**\n\t * The capacity of the cluster.\n\t */\n\tcapacity: number,\n\n\t/**\n\t * The number of IDs in the cluster. Omitted if count === capacity.\n\t * --OR--\n\t * The overrides in this cluster. Omitted if no overrides exist in the cluster.\n\t */\n\tcountOrOverrides?: number | SerializedClusterOverrides,\n\n\t/**\n\t * Overrides in this cluster. Omitted if no overrides exist in the cluster.\n\t */\n\toverrides?: SerializedClusterOverrides\n];\n\nexport type SerializedLocalOverrides = readonly (readonly [LocalCompressedId, string])[];\n\nexport interface SerializedLocalState {\n\t/**\n\t * The total number of local IDs created by this session\n\t */\n\treadonly localIdCount: number;\n\t/**\n\t * Overrides generated by this session. Omitted if no local overrides exist in the session.\n\t */\n\treadonly overrides?: SerializedLocalOverrides;\n\n\t/**\n\t * The most recent local ID in a range returned by `takeNextCreationRange`.\n\t */\n\treadonly lastTakenLocalId: LocalCompressedId | undefined;\n\n\t/**\n\t * Serialized table for normalizing IDs made by the local session.\n\t */\n\treadonly sessionNormalizer: SerializedSessionIdNormalizer;\n}\n\n/**\n * Serialized table for normalizing IDs made by the local session.\n */\nexport interface SerializedSessionIdNormalizer {\n\treadonly nextLocalId: LocalCompressedId;\n\treadonly localRanges: readonly (readonly [\n\t\tfirstLocal: LocalCompressedId,\n\t\tlastLocal: LocalCompressedId,\n\t\tfinalRanges?: readonly (readonly [\n\t\t\talignedLocal: LocalCompressedId,\n\t\t\tfirstFinal: FinalCompressedId,\n\t\t\tlastFinal: FinalCompressedId\n\t\t])[]\n\t])[];\n}\n\n/**\n * The minimal required contents of a serialized IdCompressor.\n */\nexport interface VersionedSerializedIdCompressor {\n\treadonly _versionedSerializedIdCompressor: '8c73c57c-1cf4-4278-8915-6444cb4f6af5';\n\treadonly version: string;\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressor extends VersionedSerializedIdCompressor {\n\t/** The cluster capacity of this compressor */\n\treadonly clusterCapacity: number;\n\t/** The number of reserved IDs in this compressor */\n\treadonly reservedIdCount: number;\n\t/** All sessions except the local session. */\n\treadonly sessions: readonly SerializedSessionData[];\n\t/** All clusters in the compressor in the order they were created. */\n\treadonly clusters: readonly SerializedCluster[];\n\t/** All attribution IDs for all sessions */\n\treadonly attributionIds?: readonly AttributionId[];\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressorWithNoSession extends SerializedIdCompressor {\n\treadonly _noLocalState: '3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb';\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressorWithOngoingSession extends SerializedIdCompressor {\n\treadonly _hasLocalState: '1281acae-6d14-47e7-bc92-71c8ee0819cb';\n\t/** The session ID of the local session, by index into `sessions`. */\n\treadonly localSessionIndex: number;\n\t/** This is only present if the local session made any IDs. */\n\treadonly localState?: SerializedLocalState;\n}\n\n/**\n * Data describing a range of session-local IDs (from a remote or local session).\n *\n * A range is composed of local IDs that were generated. Some of these may have overrides.\n *\n * @example\n * Suppose an IdCompressor generated a sequence of local IDs as follows:\n * ```\n * compressor.generateLocalId()\n * compressor.generateLocalId('0093cf29-9454-4034-8940-33b1077b41c3')\n * compressor.generateLocalId()\n * compressor.generateLocalId('0ed545f8-e97e-4dc1-acf9-c4a783258bdf')\n * compressor.generateLocalId()\n * compressor.generateLocalId()\n * compressor.takeNextCreationRange()\n * ```\n * This would result in the following range:\n * ```\n * {\n * first: localId1,\n * last: localId6,\n * overrides: [[localId2, '0093cf29-9454-4034-8940-33b1077b41c3'], [localId4, '0ed545f8-e97e-4dc1-acf9-c4a783258bdf']]\n * }\n * ```\n */\nexport interface IdCreationRange {\n\treadonly sessionId: SessionId;\n\treadonly ids?: IdCreationRange.Ids;\n\treadonly attributionId?: AttributionId;\n}\n\nexport type UnackedLocalId = LocalCompressedId & OpSpaceCompressedId;\n\nexport namespace IdCreationRange {\n\texport type Ids =\n\t\t| {\n\t\t\t\treadonly first: UnackedLocalId;\n\t\t\t\treadonly last: UnackedLocalId;\n\t\t }\n\t\t| ({\n\t\t\t\treadonly first?: UnackedLocalId;\n\t\t\t\treadonly last?: UnackedLocalId;\n\t\t } & HasOverrides);\n\n\texport interface HasOverrides {\n\t\treadonly overrides: Overrides;\n\t}\n\n\texport type Override = readonly [id: UnackedLocalId, override: string];\n\texport type Overrides = readonly [Override, ...Override[]];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"0.0.1.js","sourceRoot":"","sources":["../../../src/id-compressor/persisted-types/0.0.1.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tAttributionId,\n\tFinalCompressedId,\n\tLocalCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from '../../Identifiers';\n\n/**\n * A serialized ID allocation session for an `IdCompressor`.\n */\nexport type SerializedSessionData = readonly [\n\t/**\n\t * The ID of the session.\n\t */\n\tsessionId: SessionId,\n\n\t/**\n\t * Index into the serialized AttributionIDs array; points to the attribution ID provided for this session\n\t */\n\tattributionId?: number\n];\n\nexport type SerializedClusterOverrides = readonly [\n\t/** The overridden final ID, represented as an index into the cluster's ID range */\n\toverriddenFinalIndex: number, // A cluster with base UUID '...beef' and an `overriddenFinalIndex` of 3 would correspond to '...bef2'\n\t/** The override string */\n\toverride: string,\n\t/** The first ID that was finalized and associated with this override, set only if different than the `overriddenFinalIndex` */\n\toverriddenId?: FinalCompressedId\n][];\n\n/**\n * A serialized final ID cluster.\n */\nexport type SerializedCluster = readonly [\n\t/**\n\t * Index into the serialized sessions array. Can be converted into a baseUuid via its order in `clusters`.\n\t * If negative, then this cluster was created by the local session.\n\t */\n\tsessionIndex: number,\n\n\t/**\n\t * The capacity of the cluster.\n\t */\n\tcapacity: number,\n\n\t/**\n\t * The number of IDs in the cluster. Omitted if count === capacity.\n\t * --OR--\n\t * The overrides in this cluster. Omitted if no overrides exist in the cluster.\n\t */\n\tcountOrOverrides?: number | SerializedClusterOverrides,\n\n\t/**\n\t * Overrides in this cluster. Omitted if no overrides exist in the cluster.\n\t */\n\toverrides?: SerializedClusterOverrides\n];\n\nexport type SerializedLocalOverrides = readonly (readonly [LocalCompressedId, string])[];\n\nexport interface SerializedLocalState {\n\t/**\n\t * The total number of local IDs created by this session\n\t */\n\treadonly localIdCount: number;\n\t/**\n\t * Overrides generated by this session. Omitted if no local overrides exist in the session.\n\t */\n\treadonly overrides?: SerializedLocalOverrides;\n\n\t/**\n\t * The most recent local ID in a range returned by `takeNextCreationRange`.\n\t */\n\treadonly lastTakenLocalId: LocalCompressedId | undefined;\n\n\t/**\n\t * Serialized table for normalizing IDs made by the local session.\n\t */\n\treadonly sessionNormalizer: SerializedSessionIdNormalizer;\n}\n\n/**\n * Serialized table for normalizing IDs made by the local session.\n */\nexport interface SerializedSessionIdNormalizer {\n\treadonly nextLocalId: LocalCompressedId;\n\treadonly localRanges: readonly (readonly [\n\t\tfirstLocal: LocalCompressedId,\n\t\tlastLocal: LocalCompressedId,\n\t\tfinalRanges?: readonly (readonly [\n\t\t\talignedLocal: LocalCompressedId,\n\t\t\tfirstFinal: FinalCompressedId,\n\t\t\tlastFinal: FinalCompressedId\n\t\t])[]\n\t])[];\n}\n\n/**\n * The minimal required contents of a serialized IdCompressor.\n */\nexport interface VersionedSerializedIdCompressor {\n\treadonly _versionedSerializedIdCompressor: '8c73c57c-1cf4-4278-8915-6444cb4f6af5';\n\treadonly version: string;\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressor extends VersionedSerializedIdCompressor {\n\t/** The cluster capacity of this compressor */\n\treadonly clusterCapacity: number;\n\t/** The number of reserved IDs in this compressor */\n\treadonly reservedIdCount: number;\n\t/** All sessions except the local session. */\n\treadonly sessions: readonly SerializedSessionData[];\n\t/** All clusters in the compressor in the order they were created. */\n\treadonly clusters: readonly SerializedCluster[];\n\t/** All attribution IDs for all sessions */\n\treadonly attributionIds?: readonly AttributionId[];\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressorWithNoSession extends SerializedIdCompressor {\n\treadonly _noLocalState: '3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb';\n}\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n */\nexport interface SerializedIdCompressorWithOngoingSession extends SerializedIdCompressor {\n\treadonly _hasLocalState: '1281acae-6d14-47e7-bc92-71c8ee0819cb';\n\t/** The session ID of the local session, by index into `sessions`. */\n\treadonly localSessionIndex: number;\n\t/** This is only present if the local session made any IDs. */\n\treadonly localState?: SerializedLocalState;\n}\n\n/**\n * Data describing a range of session-local IDs (from a remote or local session).\n *\n * A range is composed of local IDs that were generated. Some of these may have overrides.\n *\n * @example\n * Suppose an IdCompressor generated a sequence of local IDs as follows:\n * ```\n * compressor.generateLocalId()\n * compressor.generateLocalId('0093cf29-9454-4034-8940-33b1077b41c3')\n * compressor.generateLocalId()\n * compressor.generateLocalId('0ed545f8-e97e-4dc1-acf9-c4a783258bdf')\n * compressor.generateLocalId()\n * compressor.generateLocalId()\n * compressor.takeNextCreationRange()\n * ```\n * This would result in the following range:\n * ```\n * {\n * first: localId1,\n * last: localId6,\n * overrides: [[localId2, '0093cf29-9454-4034-8940-33b1077b41c3'], [localId4, '0ed545f8-e97e-4dc1-acf9-c4a783258bdf']]\n * }\n * ```\n */\nexport interface IdCreationRange {\n\treadonly sessionId: SessionId;\n\treadonly ids?: IdCreationRange.Ids;\n\treadonly attributionId?: AttributionId;\n}\n\nexport type UnackedLocalId = LocalCompressedId & OpSpaceCompressedId;\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace IdCreationRange {\n\texport type Ids =\n\t\t| {\n\t\t\t\treadonly first: UnackedLocalId;\n\t\t\t\treadonly last: UnackedLocalId;\n\t\t }\n\t\t| ({\n\t\t\t\treadonly first?: UnackedLocalId;\n\t\t\t\treadonly last?: UnackedLocalId;\n\t\t } & HasOverrides);\n\n\texport interface HasOverrides {\n\t\treadonly overrides: Overrides;\n\t}\n\n\texport type Override = readonly [id: UnackedLocalId, override: string];\n\texport type Overrides = readonly [Override, ...Override[]];\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* This file represents the public API. Consumers of this
|
|
11
|
+
* This file represents the public API. Consumers of this library will not see exported modules unless they are enumerated here.
|
|
12
12
|
* Removing / editing existing exports here will often indicate a breaking change, so please be cognizant of changes made here.
|
|
13
13
|
*/
|
|
14
14
|
export { initialTree } from './InitialTree';
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.getSerializedUploadedEditChunkContents = exports.getUploadedEditChunkCon
|
|
|
21
21
|
* @packageDocumentation
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
24
|
-
* This file represents the public API. Consumers of this
|
|
24
|
+
* This file represents the public API. Consumers of this library will not see exported modules unless they are enumerated here.
|
|
25
25
|
* Removing / editing existing exports here will often indicate a breaking change, so please be cognizant of changes made here.
|
|
26
26
|
*/
|
|
27
27
|
// API Exports
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH,cAAc;AAEd,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mCAAiE;AAAjD,gGAAA,MAAM,OAAA;AACtB,mCAAmF;AAA1E,sHAAA,4BAA4B,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,gGAAA,MAAM,OAAA;AAkBhE,6CAAqD;AAA5C,mHAAA,oBAAoB,OAAA;AAI7B,uCAA4F;AAAnF,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAmB,gHAAA,oBAAoB,OAAA;AACvE,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,uDAAqC;AACrC,gDAA8B;AAC9B,sDAAoC;AAEpC,qDAyC2B;AAxC1B,uGAAA,IAAI,OAAA;AACJ,6GAAA,UAAU,OAAA;AAIV,mHAAA,gBAAgB,OAAA;AAEhB,iHAAA,cAAc,OAAA;AAqBd,qHAAA,kBAAkB,OAAA;AAElB,8GAAA,WAAW,OAAA;AAEX,sHAAA,mBAAmB,OAAA;AACnB,sHAAA,mBAAmB,OAAA;AAQpB,2CAcsB;AATrB,+GAAA,iBAAiB,OAAA;AACjB,wGAAA,UAAU,OAAA;AASX,+CAA6B;AAC7B,iDAQyB;AAPxB,yGAAA,QAAQ,OAAA;AACR,kIAAA,iCAAiC,OAAA;AAGjC,sHAAA,qBAAqB,OAAA;AAErB,0HAAA,yBAAyB,OAAA;AAE1B,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,6DAa+B;AAZ9B,0HAAA,mBAAmB,OAAA;AACnB,yHAAA,kBAAkB,OAAA;AAYnB,uCASoB;AALnB,oGAAA,QAAQ,OAAA;AAMT,+CAA+D;AAAtD,4GAAA,YAAY,OAAA;AAAE,+GAAA,eAAe,OAAA;AAEtC,6CAAiF;AAAxE,0GAAA,WAAW,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAEtC;;GAEG;AACH,+DAIgC;AAH/B,wEAAwE;AACxE,oIAAA,sCAAsC,OAAgC;AACtE,8IAAA,sCAAsC,OAAA;AAGvC,gDAA8B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Fluid DDS storing a tree.\n *\n * @packageDocumentation\n */\n\n/**\n * This file represents the public API. Consumers of this
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH,cAAc;AAEd,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mCAAiE;AAAjD,gGAAA,MAAM,OAAA;AACtB,mCAAmF;AAA1E,sHAAA,4BAA4B,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,gGAAA,MAAM,OAAA;AAkBhE,6CAAqD;AAA5C,mHAAA,oBAAoB,OAAA;AAI7B,uCAA4F;AAAnF,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAmB,gHAAA,oBAAoB,OAAA;AACvE,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,uDAAqC;AACrC,gDAA8B;AAC9B,sDAAoC;AAEpC,qDAyC2B;AAxC1B,uGAAA,IAAI,OAAA;AACJ,6GAAA,UAAU,OAAA;AAIV,mHAAA,gBAAgB,OAAA;AAEhB,iHAAA,cAAc,OAAA;AAqBd,qHAAA,kBAAkB,OAAA;AAElB,8GAAA,WAAW,OAAA;AAEX,sHAAA,mBAAmB,OAAA;AACnB,sHAAA,mBAAmB,OAAA;AAQpB,2CAcsB;AATrB,+GAAA,iBAAiB,OAAA;AACjB,wGAAA,UAAU,OAAA;AASX,+CAA6B;AAC7B,iDAQyB;AAPxB,yGAAA,QAAQ,OAAA;AACR,kIAAA,iCAAiC,OAAA;AAGjC,sHAAA,qBAAqB,OAAA;AAErB,0HAAA,yBAAyB,OAAA;AAE1B,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,6DAa+B;AAZ9B,0HAAA,mBAAmB,OAAA;AACnB,yHAAA,kBAAkB,OAAA;AAYnB,uCASoB;AALnB,oGAAA,QAAQ,OAAA;AAMT,+CAA+D;AAAtD,4GAAA,YAAY,OAAA;AAAE,+GAAA,eAAe,OAAA;AAEtC,6CAAiF;AAAxE,0GAAA,WAAW,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAEtC;;GAEG;AACH,+DAIgC;AAH/B,wEAAwE;AACxE,oIAAA,sCAAsC,OAAgC;AACtE,8IAAA,sCAAsC,OAAA;AAGvC,gDAA8B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Fluid DDS storing a tree.\n *\n * @packageDocumentation\n */\n\n/**\n * This file represents the public API. Consumers of this library will not see exported modules unless they are enumerated here.\n * Removing / editing existing exports here will often indicate a breaking change, so please be cognizant of changes made here.\n */\n\n// API Exports\n\nexport { initialTree } from './InitialTree';\nexport { TreeNodeHandle } from './TreeNodeHandle';\nexport { Delta, Forest, ForestNode, ParentData } from './Forest';\nexport { sharedTreeAssertionErrorType, isSharedTreeEvent, Result } from './Common';\nexport type {\n\tCompressedId,\n\tDefinition,\n\tDetachedSequenceId,\n\tEditId,\n\tInternedStringId,\n\tFinalCompressedId,\n\tLocalCompressedId,\n\tNodeId,\n\tNodeIdBrand,\n\tStableNodeId,\n\tSessionSpaceCompressedId,\n\tSessionUnique,\n\tTraitLabel,\n\tUuidString,\n\tAttributionId,\n} from './Identifiers';\nexport { isDetachedSequenceId } from './Identifiers';\nexport type { OrderedEditSet, EditHandle } from './EditLog';\nexport { LogViewer } from './LogViewer';\nexport { Revision } from './RevisionValueCache';\nexport { Checkout, CheckoutEvent, ICheckoutEvents, EditValidationResult } from './Checkout';\nexport { LazyCheckout } from './LazyCheckout';\nexport { EagerCheckout } from './EagerCheckout';\nexport * from './ReconciliationPath';\nexport * from './MergeHealth';\nexport * from './TreeViewUtilities';\nexport { StringInterner } from './StringInterner';\nexport {\n\tSide,\n\tEditStatus,\n\tTreeNode,\n\tTreeNodeSequence,\n\tPayload,\n\tConstraintEffect,\n\tEdit,\n\tChangeInternal,\n\tInternalizedChange,\n\tChangeNode,\n\tChangeNode_0_0_2,\n\tEditLogSummary,\n\tFluidEditHandle,\n\tSharedTreeSummaryBase,\n\tEditWithoutId,\n\tPlaceholderTree,\n\tEditBase,\n\tHasTraits,\n\tInsertInternal,\n\tDetachInternal,\n\tBuildInternal,\n\tSetValueInternal,\n\tConstraintInternal,\n\tBuildNodeInternal,\n\tStablePlaceInternal_0_0_2,\n\tStableRangeInternal_0_0_2,\n\tNodeData,\n\tTraitMap,\n\tChangeTypeInternal,\n\tTraitLocationInternal_0_0_2,\n\tWriteFormat,\n\tConstraintInternal_0_0_2,\n\tStablePlaceInternal,\n\tStableRangeInternal,\n\tBuildNodeInternal_0_0_2,\n\tBuildInternal_0_0_2,\n\tInsertInternal_0_0_2,\n\tDetachInternal_0_0_2,\n\tSetValueInternal_0_0_2,\n\tTraitLocationInternal,\n} from './persisted-types';\nexport {\n\tSharedTreeArgs,\n\tSharedTreeOptions,\n\tSharedTreeOptions_0_0_2,\n\tSharedTreeOptions_0_1_1,\n\tSharedTreeFactory,\n\tSharedTree,\n\tEditCommittedHandler,\n\tSequencedEditAppliedHandler,\n\tEditCommittedEventArguments,\n\tSequencedEditAppliedEventArguments,\n\tEditApplicationOutcome,\n\tISharedTreeEvents,\n\tStashedLocalOpMetadata,\n} from './SharedTree';\nexport * from './EventTypes';\nexport {\n\tsetTrait,\n\tareRevisionViewsSemanticallyEqual,\n\tBadPlaceValidationResult,\n\tBadRangeValidationResult,\n\tPlaceValidationResult,\n\tRangeValidationResult,\n\tRangeValidationResultKind,\n} from './EditUtilities';\nexport { comparePayloads } from './PayloadUtilities';\nexport {\n\tTransactionInternal,\n\tGenericTransaction,\n\tGenericTransactionPolicy,\n\tEditingResult,\n\tEditingResultBase,\n\tFailedEditingResult,\n\tValidEditingResult,\n\tTransactionState,\n\tTransactionFailure,\n\tSucceedingTransactionState,\n\tFailingTransactionState,\n\tChangeResult,\n} from './TransactionInternal';\nexport {\n\tNodeInTrait,\n\tPlaceIndex,\n\tTreeViewNode,\n\tTreeView,\n\tTraitNodeIndex,\n\tTreeViewPlace,\n\tTreeViewRange,\n\tTraitLocation,\n} from './TreeView';\nexport { RevisionView, TransactionView } from './RevisionView';\nexport { NodeIdContext, NodeIdGenerator, NodeIdConverter } from './NodeIdUtilities';\nexport { Transaction, TransactionEvent, TransactionEvents } from './Transaction';\n\n/**\n * TODO:#61413: Publish test utilities from a separate test package\n */\nexport {\n\t/** @deprecated Use `getSerializedUploadedEditChunkContents` instead. */\n\tgetSerializedUploadedEditChunkContents as getUploadedEditChunkContents,\n\tgetSerializedUploadedEditChunkContents,\n} from './SummaryTestUtilities';\n\nexport * from './ChangeTypes';\n"]}
|
package/lib/Checkout.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export declare abstract class Checkout extends EventEmitterWithErrorHandling<ICh
|
|
|
99
99
|
* operations that modify `currentEdit.view` must call `emitChange` to handle invalidation.
|
|
100
100
|
*/
|
|
101
101
|
private currentEdit?;
|
|
102
|
+
private readonly logger;
|
|
102
103
|
disposed: boolean;
|
|
103
104
|
protected constructor(tree: SharedTree, currentView: RevisionView, onEditCommitted: EditCommittedHandler);
|
|
104
105
|
/**
|
|
@@ -142,24 +143,28 @@ export declare abstract class Checkout extends EventEmitterWithErrorHandling<ICh
|
|
|
142
143
|
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
143
144
|
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
144
145
|
*/
|
|
145
|
-
applyChanges(
|
|
146
|
+
applyChanges(changes: readonly Change[]): void;
|
|
147
|
+
applyChanges(...changes: readonly Change[]): void;
|
|
146
148
|
/**
|
|
147
149
|
* Applies the supplied changes to the tree and emits a change event.
|
|
148
150
|
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
149
151
|
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
150
152
|
*/
|
|
151
|
-
protected tryApplyChangesInternal(
|
|
153
|
+
protected tryApplyChangesInternal(changes: readonly ChangeInternal[]): EditStatus;
|
|
154
|
+
protected tryApplyChangesInternal(...changes: readonly ChangeInternal[]): EditStatus;
|
|
152
155
|
/**
|
|
153
156
|
* Convenience helper for applying an edit containing the given changes.
|
|
154
157
|
* Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).
|
|
155
158
|
*/
|
|
156
|
-
applyEdit(
|
|
159
|
+
applyEdit(changes: readonly Change[]): EditId;
|
|
160
|
+
applyEdit(...changes: readonly Change[]): EditId;
|
|
157
161
|
/**
|
|
158
162
|
* Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).
|
|
159
163
|
* If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.
|
|
160
164
|
* @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.
|
|
161
165
|
*/
|
|
162
|
-
tryApplyEdit(
|
|
166
|
+
tryApplyEdit(changes: readonly Change[]): EditId | undefined;
|
|
167
|
+
tryApplyEdit(...changes: readonly Change[]): EditId | undefined;
|
|
163
168
|
/**
|
|
164
169
|
* Rebases the ongoing edit to the latest revision loaded by this 'Checkout'.
|
|
165
170
|
* If the rebase succeeds (none of the changes in the ongoing edit became invalid), the ongoing edit will remain open and the current
|
package/lib/Checkout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,WAAW,EAA0C,MAAM,oCAAoC,CAAC;AAEtH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAA2C,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;GAGG;AACH,oBAAY,aAAa;IACxB;;;OAGG;IACH,UAAU,eAAe;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,WAAW;IACnD,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAE;CAC7E;AAED;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