@fluidframework/id-compressor 2.0.0-dev-rc.1.0.0.224419
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +27 -0
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/id-compressor.api.md +139 -0
- package/dist/appendOnlySortedMap.cjs +318 -0
- package/dist/appendOnlySortedMap.cjs.map +1 -0
- package/dist/appendOnlySortedMap.d.ts +124 -0
- package/dist/appendOnlySortedMap.d.ts.map +1 -0
- package/dist/finalSpace.cjs +62 -0
- package/dist/finalSpace.cjs.map +1 -0
- package/dist/finalSpace.d.ts +29 -0
- package/dist/finalSpace.d.ts.map +1 -0
- package/dist/id-compressor-alpha.d.ts +320 -0
- package/dist/id-compressor-beta.d.ts +172 -0
- package/dist/id-compressor-public.d.ts +172 -0
- package/dist/id-compressor-untrimmed.d.ts +333 -0
- package/dist/idCompressor.cjs +502 -0
- package/dist/idCompressor.cjs.map +1 -0
- package/dist/idCompressor.d.ts +84 -0
- package/dist/idCompressor.d.ts.map +1 -0
- package/dist/identifiers.cjs +15 -0
- package/dist/identifiers.cjs.map +1 -0
- package/dist/identifiers.d.ts +32 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/packageVersion.cjs +12 -0
- package/dist/packageVersion.cjs.map +1 -0
- package/dist/packageVersion.d.ts +9 -0
- package/dist/packageVersion.d.ts.map +1 -0
- package/dist/persistanceUtilities.cjs +43 -0
- package/dist/persistanceUtilities.cjs.map +1 -0
- package/dist/persistanceUtilities.d.ts +22 -0
- package/dist/persistanceUtilities.d.ts.map +1 -0
- package/dist/sessionSpaceNormalizer.cjs +80 -0
- package/dist/sessionSpaceNormalizer.cjs.map +1 -0
- package/dist/sessionSpaceNormalizer.d.ts +46 -0
- package/dist/sessionSpaceNormalizer.d.ts.map +1 -0
- package/dist/sessions.cjs +305 -0
- package/dist/sessions.cjs.map +1 -0
- package/dist/sessions.d.ts +115 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/idCompressor.cjs +7 -0
- package/dist/types/idCompressor.cjs.map +1 -0
- package/dist/types/idCompressor.d.ts +139 -0
- package/dist/types/idCompressor.d.ts.map +1 -0
- package/dist/types/identifiers.cjs +7 -0
- package/dist/types/identifiers.cjs.map +1 -0
- package/dist/types/identifiers.d.ts +40 -0
- package/dist/types/identifiers.d.ts.map +1 -0
- package/dist/types/index.cjs +7 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/persisted-types/0.0.1.cjs +7 -0
- package/dist/types/persisted-types/0.0.1.cjs.map +1 -0
- package/dist/types/persisted-types/0.0.1.d.ts +52 -0
- package/dist/types/persisted-types/0.0.1.d.ts.map +1 -0
- package/dist/types/persisted-types/index.cjs +7 -0
- package/dist/types/persisted-types/index.cjs.map +1 -0
- package/dist/types/persisted-types/index.d.ts +6 -0
- package/dist/types/persisted-types/index.d.ts.map +1 -0
- package/dist/utilities.cjs +170 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.ts +53 -0
- package/dist/utilities.d.ts.map +1 -0
- package/lib/appendOnlySortedMap.d.mts +124 -0
- package/lib/appendOnlySortedMap.d.mts.map +1 -0
- package/lib/appendOnlySortedMap.mjs +312 -0
- package/lib/appendOnlySortedMap.mjs.map +1 -0
- package/lib/finalSpace.d.mts +29 -0
- package/lib/finalSpace.d.mts.map +1 -0
- package/lib/finalSpace.mjs +58 -0
- package/lib/finalSpace.mjs.map +1 -0
- package/lib/id-compressor-alpha.d.mts +320 -0
- package/lib/id-compressor-beta.d.mts +172 -0
- package/lib/id-compressor-public.d.mts +172 -0
- package/lib/id-compressor-untrimmed.d.mts +333 -0
- package/lib/idCompressor.d.mts +84 -0
- package/lib/idCompressor.d.mts.map +1 -0
- package/lib/idCompressor.mjs +496 -0
- package/lib/idCompressor.mjs.map +1 -0
- package/lib/identifiers.d.mts +32 -0
- package/lib/identifiers.d.mts.map +1 -0
- package/lib/identifiers.mjs +11 -0
- package/lib/identifiers.mjs.map +1 -0
- package/lib/index.d.mts +8 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +7 -0
- package/lib/index.mjs.map +1 -0
- package/lib/packageVersion.d.mts +9 -0
- package/lib/packageVersion.d.mts.map +1 -0
- package/lib/packageVersion.mjs +9 -0
- package/lib/packageVersion.mjs.map +1 -0
- package/lib/persistanceUtilities.d.mts +22 -0
- package/lib/persistanceUtilities.d.mts.map +1 -0
- package/lib/persistanceUtilities.mjs +34 -0
- package/lib/persistanceUtilities.mjs.map +1 -0
- package/lib/sessionSpaceNormalizer.d.mts +46 -0
- package/lib/sessionSpaceNormalizer.d.mts.map +1 -0
- package/lib/sessionSpaceNormalizer.mjs +76 -0
- package/lib/sessionSpaceNormalizer.mjs.map +1 -0
- package/lib/sessions.d.mts +115 -0
- package/lib/sessions.d.mts.map +1 -0
- package/lib/sessions.mjs +290 -0
- package/lib/sessions.mjs.map +1 -0
- package/lib/types/idCompressor.d.mts +139 -0
- package/lib/types/idCompressor.d.mts.map +1 -0
- package/lib/types/idCompressor.mjs +6 -0
- package/lib/types/idCompressor.mjs.map +1 -0
- package/lib/types/identifiers.d.mts +40 -0
- package/lib/types/identifiers.d.mts.map +1 -0
- package/lib/types/identifiers.mjs +6 -0
- package/lib/types/identifiers.mjs.map +1 -0
- package/lib/types/index.d.mts +8 -0
- package/lib/types/index.d.mts.map +1 -0
- package/lib/types/index.mjs +6 -0
- package/lib/types/index.mjs.map +1 -0
- package/lib/types/persisted-types/0.0.1.d.mts +52 -0
- package/lib/types/persisted-types/0.0.1.d.mts.map +1 -0
- package/lib/types/persisted-types/0.0.1.mjs +6 -0
- package/lib/types/persisted-types/0.0.1.mjs.map +1 -0
- package/lib/types/persisted-types/index.d.mts +6 -0
- package/lib/types/persisted-types/index.d.mts.map +1 -0
- package/lib/types/persisted-types/index.mjs +6 -0
- package/lib/types/persisted-types/index.mjs.map +1 -0
- package/lib/utilities.d.mts +53 -0
- package/lib/utilities.d.mts.map +1 -0
- package/lib/utilities.mjs +151 -0
- package/lib/utilities.mjs.map +1 -0
- package/package.json +114 -0
- package/prettier.config.cjs +8 -0
- package/src/appendOnlySortedMap.ts +366 -0
- package/src/finalSpace.ts +67 -0
- package/src/idCompressor.ts +685 -0
- package/src/identifiers.ts +42 -0
- package/src/index.ts +23 -0
- package/src/packageVersion.ts +9 -0
- package/src/persistanceUtilities.ts +58 -0
- package/src/sessionSpaceNormalizer.ts +83 -0
- package/src/sessions.ts +405 -0
- package/src/types/idCompressor.ts +155 -0
- package/src/types/identifiers.ts +39 -0
- package/src/types/index.ts +15 -0
- package/src/types/persisted-types/0.0.1.ts +58 -0
- package/src/types/persisted-types/README.md +3 -0
- package/src/types/persisted-types/index.ts +11 -0
- package/src/utilities.ts +191 -0
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { IdCreationRange, IIdCompressor, IIdCompressorCore, OpSpaceCompressedId, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, SessionId, SessionSpaceCompressedId, StableId } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* See {@link IIdCompressor} and {@link IIdCompressorCore}
|
|
9
|
+
*
|
|
10
|
+
* @alpha
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Not intended for public use and will be removed from the public API in the future.
|
|
13
|
+
* Use `createIdCompressor` instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare class IdCompressor implements IIdCompressor, IIdCompressorCore {
|
|
16
|
+
private readonly logger?;
|
|
17
|
+
/**
|
|
18
|
+
* Max allowed initial cluster size.
|
|
19
|
+
*/
|
|
20
|
+
static readonly maxClusterSize: number;
|
|
21
|
+
readonly localSessionId: SessionId;
|
|
22
|
+
private readonly localSession;
|
|
23
|
+
private readonly normalizer;
|
|
24
|
+
private localGenCount;
|
|
25
|
+
private nextRangeBaseGenCount;
|
|
26
|
+
private readonly sessions;
|
|
27
|
+
private readonly finalSpace;
|
|
28
|
+
/**
|
|
29
|
+
* Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.
|
|
30
|
+
* Eventually, this can be adjusted dynamically to have cluster reservation policies that
|
|
31
|
+
* optimize the number of eager finals.
|
|
32
|
+
* It is not readonly as it is accessed by tests for clear-box testing.
|
|
33
|
+
*/
|
|
34
|
+
private nextRequestedClusterSize;
|
|
35
|
+
private telemetryLocalIdCount;
|
|
36
|
+
private telemetryEagerFinalIdCount;
|
|
37
|
+
private constructor();
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `createIdCompressor` instead.
|
|
40
|
+
*/
|
|
41
|
+
static create(logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use `createIdCompressor` instead.
|
|
44
|
+
*/
|
|
45
|
+
static create(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
46
|
+
generateCompressedId(): SessionSpaceCompressedId;
|
|
47
|
+
private generateNextLocalId;
|
|
48
|
+
takeNextCreationRange(): IdCreationRange;
|
|
49
|
+
private static assertValidRange;
|
|
50
|
+
finalizeCreationRange(range: IdCreationRange): void;
|
|
51
|
+
private addEmptyCluster;
|
|
52
|
+
normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
|
|
53
|
+
normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
|
|
54
|
+
decompress(id: SessionSpaceCompressedId): StableId;
|
|
55
|
+
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
56
|
+
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
57
|
+
serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
|
|
58
|
+
serialize(withSession: false): SerializedIdCompressorWithNoSession;
|
|
59
|
+
static deserialize(serialized: SerializedIdCompressorWithOngoingSession): IdCompressor;
|
|
60
|
+
static deserialize(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId): IdCompressor;
|
|
61
|
+
equals(other: IdCompressor, includeLocalState: boolean): boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a new {@link IIdCompressor}.
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
export declare function createIdCompressor(logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
68
|
+
/**
|
|
69
|
+
* Create a new {@link IIdCompressor}.
|
|
70
|
+
* @param sessionId - The seed ID for the compressor.
|
|
71
|
+
* @alpha
|
|
72
|
+
*/
|
|
73
|
+
export declare function createIdCompressor(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
74
|
+
/**
|
|
75
|
+
* Deserializes the supplied state into an ID compressor.
|
|
76
|
+
* @alpha
|
|
77
|
+
*/
|
|
78
|
+
export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithOngoingSession): IIdCompressor & IIdCompressorCore;
|
|
79
|
+
/**
|
|
80
|
+
* Deserializes the supplied state into an ID compressor.
|
|
81
|
+
* @alpha
|
|
82
|
+
*/
|
|
83
|
+
export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId): IIdCompressor & IIdCompressorCore;
|
|
84
|
+
//# sourceMappingURL=idCompressor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idCompressor.d.ts","sourceRoot":"","sources":["../src/idCompressor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EACN,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EAEnB,mCAAmC,EACnC,wCAAwC,EACxC,SAAS,EACT,wBAAwB,EACxB,QAAQ,EACR,MAAM,SAAS,CAAC;AAqCjB;;;;;;;GAOG;AACH,qBAAa,YAAa,YAAW,aAAa,EAAE,iBAAiB;IA6CnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IA5CzB;;OAEG;IACH,gBAAuB,cAAc,SAAW;IAIhD,SAAgB,cAAc,EAAE,SAAS,CAAC;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;IAE3D,OAAO,CAAC,aAAa,CAAK;IAQ1B,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAM/C;;;;;OAKG;IAEH,OAAO,CAAC,wBAAwB,CAAe;IAE/C,OAAO,CAAC,qBAAqB,CAAK;IAElC,OAAO,CAAC,0BAA0B,CAAK;IAIvC,OAAO;IAqBP;;OAEG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,aAAa,GAAG,iBAAiB;IACtF;;OAEG;WACW,MAAM,CACnB,SAAS,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,oBAAoB,GAC3B,aAAa,GAAG,iBAAiB;IAyB7B,oBAAoB,IAAI,wBAAwB;IAyBvD,OAAO,CAAC,mBAAmB;IAMpB,qBAAqB,IAAI,eAAe;IAoB/C,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAaxB,qBAAqB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAmF1D,OAAO,CAAC,eAAe;IAWhB,kBAAkB,CAAC,EAAE,EAAE,wBAAwB,GAAG,mBAAmB;IAerE,uBAAuB,CAC7B,EAAE,EAAE,mBAAmB,EACvB,eAAe,EAAE,SAAS,GACxB,wBAAwB;IA4CpB,UAAU,CAAC,EAAE,EAAE,wBAAwB,GAAG,QAAQ;IAwClD,UAAU,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB;IAQ5D,aAAa,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB,GAAG,SAAS;IAwC3E,SAAS,CAAC,WAAW,EAAE,IAAI,GAAG,wCAAwC;IACtE,SAAS,CAAC,WAAW,EAAE,KAAK,GAAG,mCAAmC;WAuE3D,WAAW,CAAC,UAAU,EAAE,wCAAwC,GAAG,YAAY;WAC/E,WAAW,CACxB,UAAU,EAAE,mCAAmC,EAC/C,YAAY,EAAE,SAAS,GACrB,YAAY;IAyER,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,GAAG,OAAO;CAgBvE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,CAAC,EAAE,oBAAoB,GAC3B,aAAa,GAAG,iBAAiB,CAAC;AACrC;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,oBAAoB,GAC3B,aAAa,GAAG,iBAAiB,CAAC;AAQrC;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,wCAAwC,GAClD,aAAa,GAAG,iBAAiB,CAAC;AACrC;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,mCAAmC,EAC/C,YAAY,EAAE,SAAS,GACrB,aAAa,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isFinalId = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* @returns true if the supplied ID is a final ID.
|
|
10
|
+
*/
|
|
11
|
+
function isFinalId(id) {
|
|
12
|
+
return id >= 0;
|
|
13
|
+
}
|
|
14
|
+
exports.isFinalId = isFinalId;
|
|
15
|
+
//# sourceMappingURL=identifiers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiers.cjs","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwBH;;GAEG;AACH,SAAgB,SAAS,CACxB,EAAkD;IAElD,OAAO,EAAE,IAAI,CAAC,CAAC;AAChB,CAAC;AAJD,8BAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { OpSpaceCompressedId, SessionSpaceCompressedId } from \"./types\";\n\n/**\n * A compressed ID that is stable and unique within the scope of network of compressors (i.e. a document).\n * It can only be used/decompressed in the context of the originating document.\n */\nexport type FinalCompressedId = number & {\n\treadonly FinalCompressedId: \"5d83d1e2-98b7-4e4e-a889-54c855cfa73d\";\n\n\t// Same brand as OpNormalizedCompressedId, as final IDs are always finally normalized\n\treadonly OpNormalized: \"9209432d-a959-4df7-b2ad-767ead4dbcae\";\n};\n\n/**\n * A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).\n * Internally, it should not be persisted outside a scope annotated with the originating SessionId in order to be unambiguous.\n * If external persistence is needed (e.g. by a client), a StableId should be used instead.\n */\nexport type LocalCompressedId = number & {\n\treadonly LocalCompressedId: \"6fccb42f-e2a4-4243-bd29-f13d12b9c6d1\";\n} & SessionSpaceCompressedId; // Same brand as CompressedId, as local IDs are always locally normalized\n\n/**\n * @returns true if the supplied ID is a final ID.\n */\nexport function isFinalId(\n\tid: SessionSpaceCompressedId | OpSpaceCompressedId,\n): id is FinalCompressedId {\n\treturn id >= 0;\n}\n\n/**\n * A StableId which is suitable for use as a session identifier\n */\nexport type NumericUuid = bigint & {\n\treadonly NumericUuid: \"be04dd4d-9d7e-4337-a833-eec64c61aa46\";\n};\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { OpSpaceCompressedId, SessionSpaceCompressedId } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* A compressed ID that is stable and unique within the scope of network of compressors (i.e. a document).
|
|
8
|
+
* It can only be used/decompressed in the context of the originating document.
|
|
9
|
+
*/
|
|
10
|
+
export type FinalCompressedId = number & {
|
|
11
|
+
readonly FinalCompressedId: "5d83d1e2-98b7-4e4e-a889-54c855cfa73d";
|
|
12
|
+
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).
|
|
16
|
+
* Internally, it should not be persisted outside a scope annotated with the originating SessionId in order to be unambiguous.
|
|
17
|
+
* If external persistence is needed (e.g. by a client), a StableId should be used instead.
|
|
18
|
+
*/
|
|
19
|
+
export type LocalCompressedId = number & {
|
|
20
|
+
readonly LocalCompressedId: "6fccb42f-e2a4-4243-bd29-f13d12b9c6d1";
|
|
21
|
+
} & SessionSpaceCompressedId;
|
|
22
|
+
/**
|
|
23
|
+
* @returns true if the supplied ID is a final ID.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isFinalId(id: SessionSpaceCompressedId | OpSpaceCompressedId): id is FinalCompressedId;
|
|
26
|
+
/**
|
|
27
|
+
* A StableId which is suitable for use as a session identifier
|
|
28
|
+
*/
|
|
29
|
+
export type NumericUuid = bigint & {
|
|
30
|
+
readonly NumericUuid: "be04dd4d-9d7e-4337-a833-eec64c61aa46";
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=identifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IACxC,QAAQ,CAAC,iBAAiB,EAAE,sCAAsC,CAAC;IAGnE,QAAQ,CAAC,YAAY,EAAE,sCAAsC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IACxC,QAAQ,CAAC,iBAAiB,EAAE,sCAAsC,CAAC;CACnE,GAAG,wBAAwB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,SAAS,CACxB,EAAE,EAAE,wBAAwB,GAAG,mBAAmB,GAChD,EAAE,IAAI,iBAAiB,CAEzB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAClC,QAAQ,CAAC,WAAW,EAAE,sCAAsC,CAAC;CAC7D,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isStableId = exports.generateStableId = exports.assertIsStableId = exports.createSessionId = exports.IdCompressor = exports.deserializeIdCompressor = exports.createIdCompressor = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Exports for `id-compressor`
|
|
10
|
+
*/
|
|
11
|
+
var idCompressor_1 = require("./idCompressor.cjs");
|
|
12
|
+
Object.defineProperty(exports, "createIdCompressor", { enumerable: true, get: function () { return idCompressor_1.createIdCompressor; } });
|
|
13
|
+
Object.defineProperty(exports, "deserializeIdCompressor", { enumerable: true, get: function () { return idCompressor_1.deserializeIdCompressor; } });
|
|
14
|
+
Object.defineProperty(exports, "IdCompressor", { enumerable: true, get: function () { return idCompressor_1.IdCompressor; } });
|
|
15
|
+
var utilities_1 = require("./utilities.cjs");
|
|
16
|
+
Object.defineProperty(exports, "createSessionId", { enumerable: true, get: function () { return utilities_1.createSessionId; } });
|
|
17
|
+
Object.defineProperty(exports, "assertIsStableId", { enumerable: true, get: function () { return utilities_1.assertIsStableId; } });
|
|
18
|
+
Object.defineProperty(exports, "generateStableId", { enumerable: true, get: function () { return utilities_1.generateStableId; } });
|
|
19
|
+
Object.defineProperty(exports, "isStableId", { enumerable: true, get: function () { return utilities_1.isStableId; } });
|
|
20
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AAEH,mDAA2F;AAAlF,kHAAA,kBAAkB,OAAA;AAAE,uHAAA,uBAAuB,OAAA;AAAE,4GAAA,YAAY,OAAA;AAClE,6CAA8F;AAArF,4GAAA,eAAe,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,uGAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Exports for `id-compressor`\n */\n\nexport { createIdCompressor, deserializeIdCompressor, IdCompressor } from \"./idCompressor\";\nexport { createSessionId, assertIsStableId, generateStableId, isStableId } from \"./utilities\";\nexport {\n\tIIdCompressorCore,\n\tIIdCompressor,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithOngoingSession,\n\tSerializedIdCompressorWithNoSession,\n\tSessionSpaceCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n\tStableId,\n\tIdCreationRange,\n} from \"./types\";\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Exports for `id-compressor`
|
|
7
|
+
*/
|
|
8
|
+
export { createIdCompressor, deserializeIdCompressor, IdCompressor } from "./idCompressor";
|
|
9
|
+
export { createSessionId, assertIsStableId, generateStableId, isStableId } from "./utilities";
|
|
10
|
+
export { IIdCompressorCore, IIdCompressor, SerializedIdCompressor, SerializedIdCompressorWithOngoingSession, SerializedIdCompressorWithNoSession, SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId, IdCreationRange, } from "./types";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,wCAAwC,EACxC,mCAAmC,EACnC,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,eAAe,GACf,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
|
+
exports.pkgName = "@fluidframework/id-compressor";
|
|
11
|
+
exports.pkgVersion = "2.0.0-dev-rc.1.0.0.224419";
|
|
12
|
+
//# sourceMappingURL=packageVersion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.cjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,+BAA+B,CAAC;AAC1C,QAAA,UAAU,GAAG,2BAA2B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/id-compressor\";\nexport const pkgVersion = \"2.0.0-dev-rc.1.0.0.224419\";\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
|
+
*/
|
|
7
|
+
export declare const pkgName = "@fluidframework/id-compressor";
|
|
8
|
+
export declare const pkgVersion = "2.0.0-dev-rc.1.0.0.224419";
|
|
9
|
+
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,kCAAkC,CAAC;AACvD,eAAO,MAAM,UAAU,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.readBoolean = exports.readNumericUuid = exports.readNumber = exports.writeBoolean = exports.writeNumericUuid = exports.writeNumber = void 0;
|
|
8
|
+
const halfNumeric = BigInt("0xFFFFFFFFFFFFFFFF");
|
|
9
|
+
const sixtyFour = BigInt(64);
|
|
10
|
+
function writeNumber(buffer, index, value) {
|
|
11
|
+
buffer[index] = value;
|
|
12
|
+
return index + 1;
|
|
13
|
+
}
|
|
14
|
+
exports.writeNumber = writeNumber;
|
|
15
|
+
function writeNumericUuid(buffer, index, value) {
|
|
16
|
+
buffer[index] = value & halfNumeric;
|
|
17
|
+
buffer[index + 1] = value >> sixtyFour;
|
|
18
|
+
return index + 2; // UUID values are 16 bytes.
|
|
19
|
+
}
|
|
20
|
+
exports.writeNumericUuid = writeNumericUuid;
|
|
21
|
+
function writeBoolean(buffer, index, value) {
|
|
22
|
+
return writeNumber(buffer, index, value ? 1 : 0);
|
|
23
|
+
}
|
|
24
|
+
exports.writeBoolean = writeBoolean;
|
|
25
|
+
function readNumber(index) {
|
|
26
|
+
const value = index.bufferFloat[index.index];
|
|
27
|
+
index.index += 1;
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
exports.readNumber = readNumber;
|
|
31
|
+
function readNumericUuid(index) {
|
|
32
|
+
const lowerHalf = index.bufferUint[index.index];
|
|
33
|
+
const upperHalf = index.bufferUint[index.index + 1];
|
|
34
|
+
const value = (upperHalf << sixtyFour) | lowerHalf;
|
|
35
|
+
index.index += 2;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
exports.readNumericUuid = readNumericUuid;
|
|
39
|
+
function readBoolean(index) {
|
|
40
|
+
return readNumber(index) === 1;
|
|
41
|
+
}
|
|
42
|
+
exports.readBoolean = readBoolean;
|
|
43
|
+
//# sourceMappingURL=persistanceUtilities.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistanceUtilities.cjs","sourceRoot":"","sources":["../src/persistanceUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,MAAM,WAAW,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACjD,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAE7B,SAAgB,WAAW,CAAC,MAAoB,EAAE,KAAa,EAAE,KAAa;IAC7E,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACtB,OAAO,KAAK,GAAG,CAAC,CAAC;AAClB,CAAC;AAHD,kCAGC;AAED,SAAgB,gBAAgB,CAC/B,MAAsB,EACtB,KAAa,EACb,KAAkB;IAElB,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC;IACvC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,4BAA4B;AAC/C,CAAC;AARD,4CAQC;AAED,SAAgB,YAAY,CAAC,MAAoB,EAAE,KAAa,EAAE,KAAc;IAC/E,OAAO,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC;AAFD,oCAEC;AAaD,SAAgB,UAAU,CAAC,KAAY;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACjB,OAAO,KAAK,CAAC;AACd,CAAC;AAJD,gCAIC;AAED,SAAgB,eAAe,CAAC,KAAY;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,GAAG,SAAS,CAAC;IACnD,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACjB,OAAO,KAAoB,CAAC;AAC7B,CAAC;AAND,0CAMC;AAED,SAAgB,WAAW,CAAC,KAAY;IACvC,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAFD,kCAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { NumericUuid } from \"./identifiers\";\n\nconst halfNumeric = BigInt(\"0xFFFFFFFFFFFFFFFF\");\nconst sixtyFour = BigInt(64);\n\nexport function writeNumber(buffer: Float64Array, index: number, value: number): number {\n\tbuffer[index] = value;\n\treturn index + 1;\n}\n\nexport function writeNumericUuid(\n\tbuffer: BigUint64Array,\n\tindex: number,\n\tvalue: NumericUuid,\n): number {\n\tbuffer[index] = value & halfNumeric;\n\tbuffer[index + 1] = value >> sixtyFour;\n\treturn index + 2; // UUID values are 16 bytes.\n}\n\nexport function writeBoolean(buffer: Float64Array, index: number, value: boolean): number {\n\treturn writeNumber(buffer, index, value ? 1 : 0);\n}\n\n/**\n * Helper type to allow returning a value when reading as well as incrementing an index to make\n * deserialization easier.\n * Should be constructed with two views of the same buffer and index set to 0.\n */\nexport interface Index {\n\tbufferFloat: Float64Array;\n\tbufferUint: BigUint64Array;\n\tindex: number;\n}\n\nexport function readNumber(index: Index): number {\n\tconst value = index.bufferFloat[index.index];\n\tindex.index += 1;\n\treturn value;\n}\n\nexport function readNumericUuid(index: Index): NumericUuid {\n\tconst lowerHalf = index.bufferUint[index.index];\n\tconst upperHalf = index.bufferUint[index.index + 1];\n\tconst value = (upperHalf << sixtyFour) | lowerHalf;\n\tindex.index += 2;\n\treturn value as NumericUuid;\n}\n\nexport function readBoolean(index: Index): boolean {\n\treturn readNumber(index) === 1;\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { NumericUuid } from "./identifiers";
|
|
6
|
+
export declare function writeNumber(buffer: Float64Array, index: number, value: number): number;
|
|
7
|
+
export declare function writeNumericUuid(buffer: BigUint64Array, index: number, value: NumericUuid): number;
|
|
8
|
+
export declare function writeBoolean(buffer: Float64Array, index: number, value: boolean): number;
|
|
9
|
+
/**
|
|
10
|
+
* Helper type to allow returning a value when reading as well as incrementing an index to make
|
|
11
|
+
* deserialization easier.
|
|
12
|
+
* Should be constructed with two views of the same buffer and index set to 0.
|
|
13
|
+
*/
|
|
14
|
+
export interface Index {
|
|
15
|
+
bufferFloat: Float64Array;
|
|
16
|
+
bufferUint: BigUint64Array;
|
|
17
|
+
index: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function readNumber(index: Index): number;
|
|
20
|
+
export declare function readNumericUuid(index: Index): NumericUuid;
|
|
21
|
+
export declare function readBoolean(index: Index): boolean;
|
|
22
|
+
//# sourceMappingURL=persistanceUtilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistanceUtilities.d.ts","sourceRoot":"","sources":["../src/persistanceUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,GAChB,MAAM,CAIR;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAExF;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACrB,WAAW,EAAE,YAAY,CAAC;IAC1B,UAAU,EAAE,cAAc,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAI/C;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAMzD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEjD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SessionSpaceNormalizer = void 0;
|
|
8
|
+
const appendOnlySortedMap_1 = require("./appendOnlySortedMap.cjs");
|
|
9
|
+
const utilities_1 = require("./utilities.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.
|
|
12
|
+
* More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific
|
|
13
|
+
* ID was produced by the local session. This information can be used to determine whether the nth ID created by the local session
|
|
14
|
+
* was produced as a local ID (negative) or a final ID (positive).
|
|
15
|
+
*
|
|
16
|
+
* The local and final forms of IDs made by a session can be thought of as two equal-length sparse arrays, aligned such
|
|
17
|
+
* that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.
|
|
18
|
+
* Below is an example to illustrate how various mappings can arise:
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
* +- Creation Index
|
|
22
|
+
* / +- Locals
|
|
23
|
+
* / / +- Finals
|
|
24
|
+
* / / /
|
|
25
|
+
* ---+-----+----
|
|
26
|
+
* 0 | -1 | 0 -|___ Two IDs are allocated as locals since no cluster exists. A new cluster is created when acked.
|
|
27
|
+
* 1 | -2 | 1 -|
|
|
28
|
+
* 2 | | 2 -|
|
|
29
|
+
* 3 | | 3 --|-- Three more IDs are allocated as finals eagerly since a cluster exists with available capacity.
|
|
30
|
+
* 4 | | 4 -|
|
|
31
|
+
* 5 | -6 | 10 ----- One ID is allocated as a local (it overflows the existing cluster) and a new cluster is created after ack.
|
|
32
|
+
* 6 | | 11 ----- This ID (and the subsequent few) is allocated eagerly as a final ID into the existing cluster.
|
|
33
|
+
* 7 | | 12
|
|
34
|
+
* 8 | | 13
|
|
35
|
+
* 9 | | 14
|
|
36
|
+
* 10 | -11 | ----- The cluster is out of room, so a local ID is allocated. It has no corresponding final ID since it has not been acked.
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* This class stores the set of local IDs and thus their indices, as local IDs are essentially negative offsets from the first ID.
|
|
40
|
+
* The form (local or final) of a given ID index (for example, the 5th ID made by the local session) can be deduced from this information.
|
|
41
|
+
*/
|
|
42
|
+
class SessionSpaceNormalizer {
|
|
43
|
+
constructor() {
|
|
44
|
+
// Run-length encoding of IDs that were generated as local IDs. They are stored as a list of tuples (genCount, count)
|
|
45
|
+
// that are sorted on the genCount so that contains checks can use a binary search.
|
|
46
|
+
this.localIdRanges = new appendOnlySortedMap_1.AppendOnlySortedMap(utilities_1.compareFiniteNumbers);
|
|
47
|
+
}
|
|
48
|
+
get idRanges() {
|
|
49
|
+
return this.localIdRanges;
|
|
50
|
+
}
|
|
51
|
+
addLocalRange(baseGenCount, count) {
|
|
52
|
+
const last = this.localIdRanges.last();
|
|
53
|
+
if (last !== undefined) {
|
|
54
|
+
const [lastGenCount, lastCount] = last;
|
|
55
|
+
// Check to see if the added run of local IDs is contiguous with the last range added.
|
|
56
|
+
// If it is, simply merge them (this is the common case).
|
|
57
|
+
if (lastGenCount + lastCount === baseGenCount) {
|
|
58
|
+
this.localIdRanges.replaceLast(lastGenCount, lastCount + count);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.localIdRanges.append(baseGenCount, count);
|
|
63
|
+
}
|
|
64
|
+
contains(query) {
|
|
65
|
+
const genCount = (0, utilities_1.genCountFromLocalId)(query);
|
|
66
|
+
const containingBlock = this.localIdRanges.getPairOrNextLower(genCount);
|
|
67
|
+
if (containingBlock !== undefined) {
|
|
68
|
+
const [baseGenCount, count] = containingBlock;
|
|
69
|
+
if (genCount <= baseGenCount + (count - 1)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
equals(other) {
|
|
76
|
+
return this.localIdRanges.equals(other.localIdRanges, (countA, countB) => countA === countB);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.SessionSpaceNormalizer = SessionSpaceNormalizer;
|
|
80
|
+
//# sourceMappingURL=sessionSpaceNormalizer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionSpaceNormalizer.cjs","sourceRoot":"","sources":["../src/sessionSpaceNormalizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mEAA4D;AAE5D,+CAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,sBAAsB;IAAnC;QACC,qHAAqH;QACrH,mFAAmF;QAClE,kBAAa,GAAG,IAAI,yCAAmB,CAAiB,gCAAoB,CAAC,CAAC;IAsChG,CAAC;IApCA,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IAEM,aAAa,CAAC,YAAoB,EAAE,KAAa;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,KAAK,SAAS,EAAE;YACvB,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;YACvC,sFAAsF;YACtF,yDAAyD;YACzD,IAAI,YAAY,GAAG,SAAS,KAAK,YAAY,EAAE;gBAC9C,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,EAAE,SAAS,GAAG,KAAK,CAAC,CAAC;gBAChE,OAAO;aACP;SACD;QACD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;IAEM,QAAQ,CAAC,KAAwB;QACvC,MAAM,QAAQ,GAAG,IAAA,+BAAmB,EAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,eAAe,KAAK,SAAS,EAAE;YAClC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,eAAe,CAAC;YAC9C,IAAI,QAAQ,IAAI,YAAY,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE;gBAC3C,OAAO,IAAI,CAAC;aACZ;SACD;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,KAA6B;QAC1C,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAC/B,KAAK,CAAC,aAAa,EACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,CACrC,CAAC;IACH,CAAC;CACD;AAzCD,wDAyCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AppendOnlySortedMap } from \"./appendOnlySortedMap\";\nimport { LocalCompressedId } from \"./identifiers\";\nimport { compareFiniteNumbers, genCountFromLocalId } from \"./utilities\";\n\n/**\n * The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.\n * More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific\n * ID was produced by the local session. This information can be used to determine whether the nth ID created by the local session\n * was produced as a local ID (negative) or a final ID (positive).\n *\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 ----- This ID (and the subsequent few) is allocated eagerly as a final ID into the existing cluster.\n * 7 | | 12\n * 8 | | 13\n * 9 | | 14\n * 10 | -11 | ----- The cluster is out of room, so a local ID is allocated. It has no corresponding final ID since it has not been acked.\n * ```\n *\n * This class stores the set of local IDs and thus their indices, as local IDs are essentially negative offsets from the first ID.\n * The form (local or final) of a given ID index (for example, the 5th ID made by the local session) can be deduced from this information.\n */\nexport class SessionSpaceNormalizer {\n\t// Run-length encoding of IDs that were generated as local IDs. They are stored as a list of tuples (genCount, count)\n\t// that are sorted on the genCount so that contains checks can use a binary search.\n\tprivate readonly localIdRanges = new AppendOnlySortedMap<number, number>(compareFiniteNumbers);\n\n\tpublic get idRanges(): Pick<AppendOnlySortedMap<number, number>, \"size\" | \"entries\"> {\n\t\treturn this.localIdRanges;\n\t}\n\n\tpublic addLocalRange(baseGenCount: number, count: number): void {\n\t\tconst last = this.localIdRanges.last();\n\t\tif (last !== undefined) {\n\t\t\tconst [lastGenCount, lastCount] = last;\n\t\t\t// Check to see if the added run of local IDs is contiguous with the last range added.\n\t\t\t// If it is, simply merge them (this is the common case).\n\t\t\tif (lastGenCount + lastCount === baseGenCount) {\n\t\t\t\tthis.localIdRanges.replaceLast(lastGenCount, lastCount + count);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.localIdRanges.append(baseGenCount, count);\n\t}\n\n\tpublic contains(query: LocalCompressedId): boolean {\n\t\tconst genCount = genCountFromLocalId(query);\n\t\tconst containingBlock = this.localIdRanges.getPairOrNextLower(genCount);\n\t\tif (containingBlock !== undefined) {\n\t\t\tconst [baseGenCount, count] = containingBlock;\n\t\t\tif (genCount <= baseGenCount + (count - 1)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic equals(other: SessionSpaceNormalizer): boolean {\n\t\treturn this.localIdRanges.equals(\n\t\t\tother.localIdRanges,\n\t\t\t(countA, countB) => countA === countB,\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { AppendOnlySortedMap } from "./appendOnlySortedMap";
|
|
6
|
+
import { LocalCompressedId } from "./identifiers";
|
|
7
|
+
/**
|
|
8
|
+
* The `SessionSpaceNormalizer` tracks the form of the IDs created by the local session.
|
|
9
|
+
* More precisely, it acts as a set of all `LocalCompressedId`s created by the local session and allows querying whether a specific
|
|
10
|
+
* ID was produced by the local session. This information can be used to determine whether the nth ID created by the local session
|
|
11
|
+
* was produced as a local ID (negative) or a final ID (positive).
|
|
12
|
+
*
|
|
13
|
+
* The local and final forms of IDs made by a session can be thought of as two equal-length sparse arrays, aligned such
|
|
14
|
+
* that normalizeLocalToFinal(locals[i]) === finals[i] and vice versa.
|
|
15
|
+
* Below is an example to illustrate how various mappings can arise:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* +- Creation Index
|
|
19
|
+
* / +- Locals
|
|
20
|
+
* / / +- Finals
|
|
21
|
+
* / / /
|
|
22
|
+
* ---+-----+----
|
|
23
|
+
* 0 | -1 | 0 -|___ Two IDs are allocated as locals since no cluster exists. A new cluster is created when acked.
|
|
24
|
+
* 1 | -2 | 1 -|
|
|
25
|
+
* 2 | | 2 -|
|
|
26
|
+
* 3 | | 3 --|-- Three more IDs are allocated as finals eagerly since a cluster exists with available capacity.
|
|
27
|
+
* 4 | | 4 -|
|
|
28
|
+
* 5 | -6 | 10 ----- One ID is allocated as a local (it overflows the existing cluster) and a new cluster is created after ack.
|
|
29
|
+
* 6 | | 11 ----- This ID (and the subsequent few) is allocated eagerly as a final ID into the existing cluster.
|
|
30
|
+
* 7 | | 12
|
|
31
|
+
* 8 | | 13
|
|
32
|
+
* 9 | | 14
|
|
33
|
+
* 10 | -11 | ----- The cluster is out of room, so a local ID is allocated. It has no corresponding final ID since it has not been acked.
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This class stores the set of local IDs and thus their indices, as local IDs are essentially negative offsets from the first ID.
|
|
37
|
+
* The form (local or final) of a given ID index (for example, the 5th ID made by the local session) can be deduced from this information.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SessionSpaceNormalizer {
|
|
40
|
+
private readonly localIdRanges;
|
|
41
|
+
get idRanges(): Pick<AppendOnlySortedMap<number, number>, "size" | "entries">;
|
|
42
|
+
addLocalRange(baseGenCount: number, count: number): void;
|
|
43
|
+
contains(query: LocalCompressedId): boolean;
|
|
44
|
+
equals(other: SessionSpaceNormalizer): boolean;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=sessionSpaceNormalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionSpaceNormalizer.d.ts","sourceRoot":"","sources":["../src/sessionSpaceNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,sBAAsB;IAGlC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiE;IAE/F,IAAW,QAAQ,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAEnF;IAEM,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAcxD,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO;IAY3C,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;CAMrD"}
|