@fluidframework/id-compressor 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.1
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/CHANGELOG.md +23 -0
- package/api-report/id-compressor.api.md +2 -1
- package/dist/appendOnlySortedMap.js +2 -2
- package/dist/appendOnlySortedMap.js.map +1 -1
- package/dist/finalSpace.d.ts +1 -1
- package/dist/finalSpace.d.ts.map +1 -1
- package/dist/finalSpace.js +2 -2
- package/dist/finalSpace.js.map +1 -1
- package/dist/idCompressor.d.ts +1 -1
- package/dist/idCompressor.d.ts.map +1 -1
- package/dist/idCompressor.js +25 -24
- package/dist/idCompressor.js.map +1 -1
- package/dist/legacy.d.ts +28 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +18 -0
- package/dist/sessionSpaceNormalizer.d.ts +2 -0
- package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
- package/dist/sessionSpaceNormalizer.js +44 -0
- package/dist/sessionSpaceNormalizer.js.map +1 -1
- package/dist/sessions.d.ts +1 -1
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +5 -5
- package/dist/sessions.js.map +1 -1
- package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -1
- package/dist/test/appendOnlySortedMap.spec.js.map +1 -1
- package/dist/test/idCompressor.perf.spec.js.map +1 -1
- package/dist/test/idCompressor.spec.js.map +1 -1
- package/dist/test/idCompressorTestUtilities.d.ts +2 -2
- package/dist/test/idCompressorTestUtilities.d.ts.map +1 -1
- package/dist/test/idCompressorTestUtilities.js +25 -1
- package/dist/test/idCompressorTestUtilities.js.map +1 -1
- package/dist/test/numericUuid.spec.js.map +1 -1
- package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -1
- package/dist/test/snapshots/summary.spec.js.map +1 -1
- package/dist/test/testCommon.d.ts +1 -1
- package/dist/test/testCommon.d.ts.map +1 -1
- package/dist/test/testCommon.js +4 -4
- package/dist/test/testCommon.js.map +1 -1
- package/dist/types/idCompressor.d.ts +2 -2
- package/dist/types/idCompressor.d.ts.map +1 -1
- package/dist/types/idCompressor.js.map +1 -1
- package/dist/types/persisted-types/0.0.1.d.ts +4 -0
- package/dist/types/persisted-types/0.0.1.d.ts.map +1 -1
- package/dist/types/persisted-types/0.0.1.js.map +1 -1
- package/dist/utilities.d.ts +1 -1
- package/dist/utilities.d.ts.map +1 -1
- package/dist/utilities.js +2 -2
- package/dist/utilities.js.map +1 -1
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/appendOnlySortedMap.js +1 -1
- package/lib/appendOnlySortedMap.js.map +1 -1
- package/lib/finalSpace.d.ts +1 -1
- package/lib/finalSpace.d.ts.map +1 -1
- package/lib/finalSpace.js +1 -1
- package/lib/finalSpace.js.map +1 -1
- package/lib/idCompressor.d.ts +1 -1
- package/lib/idCompressor.d.ts.map +1 -1
- package/lib/idCompressor.js +6 -5
- package/lib/idCompressor.js.map +1 -1
- package/lib/legacy.d.ts +28 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +18 -0
- package/lib/sessionSpaceNormalizer.d.ts +2 -0
- package/lib/sessionSpaceNormalizer.d.ts.map +1 -1
- package/lib/sessionSpaceNormalizer.js +44 -0
- package/lib/sessionSpaceNormalizer.js.map +1 -1
- package/lib/sessions.d.ts +1 -1
- package/lib/sessions.d.ts.map +1 -1
- package/lib/sessions.js +2 -2
- package/lib/sessions.js.map +1 -1
- package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -1
- package/lib/test/appendOnlySortedMap.spec.js.map +1 -1
- package/lib/test/idCompressor.perf.spec.js.map +1 -1
- package/lib/test/idCompressor.spec.js.map +1 -1
- package/lib/test/idCompressorTestUtilities.d.ts +2 -2
- package/lib/test/idCompressorTestUtilities.d.ts.map +1 -1
- package/lib/test/idCompressorTestUtilities.js +27 -3
- package/lib/test/idCompressorTestUtilities.js.map +1 -1
- package/lib/test/numericUuid.spec.js.map +1 -1
- package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -1
- package/lib/test/snapshots/summary.spec.js.map +1 -1
- package/lib/test/testCommon.d.ts +1 -1
- package/lib/test/testCommon.d.ts.map +1 -1
- package/lib/test/testCommon.js +1 -1
- package/lib/test/testCommon.js.map +1 -1
- package/lib/types/idCompressor.d.ts +2 -2
- package/lib/types/idCompressor.d.ts.map +1 -1
- package/lib/types/idCompressor.js.map +1 -1
- package/lib/types/persisted-types/0.0.1.d.ts +4 -0
- package/lib/types/persisted-types/0.0.1.d.ts.map +1 -1
- package/lib/types/persisted-types/0.0.1.js.map +1 -1
- package/lib/utilities.d.ts +1 -1
- package/lib/utilities.d.ts.map +1 -1
- package/lib/utilities.js +1 -1
- package/lib/utilities.js.map +1 -1
- package/package.json +35 -65
- package/src/appendOnlySortedMap.ts +1 -1
- package/src/finalSpace.ts +3 -2
- package/src/idCompressor.ts +31 -25
- package/src/packageVersion.ts +1 -1
- package/src/sessionSpaceNormalizer.ts +63 -0
- package/src/sessions.ts +5 -4
- package/src/test/idCompressorTestUtilities.ts +38 -10
- package/src/test/testCommon.ts +4 -3
- package/src/test/tsconfig.json +1 -1
- package/src/types/idCompressor.ts +2 -2
- package/src/types/persisted-types/0.0.1.ts +5 -0
- package/src/utilities.ts +3 -2
- package/api-extractor-cjs.json +0 -8
- package/dist/id-compressor-alpha.d.ts +0 -352
- package/dist/id-compressor-beta.d.ts +0 -179
- package/dist/id-compressor-public.d.ts +0 -179
- package/dist/id-compressor-untrimmed.d.ts +0 -365
- package/lib/id-compressor-alpha.d.ts +0 -352
- package/lib/id-compressor-beta.d.ts +0 -179
- package/lib/id-compressor-public.d.ts +0 -179
- package/lib/id-compressor-untrimmed.d.ts +0 -365
- package/lib/test/appendOnlySortedMap.perf.spec.js +0 -49
- package/lib/test/appendOnlySortedMap.spec.js +0 -166
- package/lib/test/idCompressor.perf.spec.js +0 -281
- package/lib/test/idCompressor.spec.js +0 -953
- package/lib/test/numericUuid.spec.js +0 -74
- package/lib/test/sessionSpaceNormalizer.spec.js +0 -43
- package/lib/test/snapshots/summary.spec.js +0 -127
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
2
|
-
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
3
|
-
|
|
4
|
-
/* Excluded from this release type: assertIsStableId */
|
|
5
|
-
|
|
6
|
-
/* Excluded from this release type: createIdCompressor */
|
|
7
|
-
|
|
8
|
-
/* Excluded from this release type: createSessionId */
|
|
9
|
-
|
|
10
|
-
/* Excluded from this release type: deserializeIdCompressor */
|
|
11
|
-
|
|
12
|
-
/* Excluded from this release type: generateStableId */
|
|
13
|
-
|
|
14
|
-
/* Excluded from this release type: IdCreationRange */
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A distributed UUID generator and compressor.
|
|
18
|
-
* `IdCompressor` offers the ability to generate arbitrary non-colliding v4 UUIDs, called stable IDs, while compressing them into small integers
|
|
19
|
-
* for efficient storage and transmission. It also provides the ability to decompress these integers back into their original UUIDs.
|
|
20
|
-
*
|
|
21
|
-
* The compressor is designed to be used in a distributed environment, where multiple clients may be generating IDs concurrently.
|
|
22
|
-
* IDs generated by a compressor, via calls to `generateCompressedId`, are created in the compressor's "local" session.
|
|
23
|
-
* These IDs are unique within the session, but may not be unique across sessions. In the context of Fluid, the scope of a session
|
|
24
|
-
* is the same as the scope of a container. This means that anytime IDs are transferred between sessions, they must be translated
|
|
25
|
-
* through a process called "normalization":
|
|
26
|
-
* - The scope of a local session (in which local IDs are unique) is called the "session space" of the client.
|
|
27
|
-
* - The context of persisted state (in Fluid, this is the context of ops and summaries) is called "op space".
|
|
28
|
-
* - `SessionSpaceCompressedId`s, generated via calls to `generateCompressedId`, should NEVER be serialized directly.
|
|
29
|
-
* In Fluid, this means they should not be included in ops or summaries.
|
|
30
|
-
* - Before serialization, IDs must be normalized to op space to ensure they are interpretable by other clients.
|
|
31
|
-
* - Upon receipt, IDs should be normalized back to session space before use.
|
|
32
|
-
*
|
|
33
|
-
* Example Usage:
|
|
34
|
-
*
|
|
35
|
-
* ### Client A (Sender)
|
|
36
|
-
*
|
|
37
|
-
* ```typescript
|
|
38
|
-
* // Generate several local IDs
|
|
39
|
-
* const localId1 = idCompressor.generateCompressedId();
|
|
40
|
-
* const localId2 = idCompressor.generateCompressedId();
|
|
41
|
-
* const localId3 = idCompressor.generateCompressedId();
|
|
42
|
-
*
|
|
43
|
-
* // Normalize these IDs to op space for inclusion in a message
|
|
44
|
-
* const opSpaceId1 = idCompressor.normalizeToOpSpace(localId1);
|
|
45
|
-
* const opSpaceId2 = idCompressor.normalizeToOpSpace(localId2);
|
|
46
|
-
* const opSpaceId3 = idCompressor.normalizeToOpSpace(localId3);
|
|
47
|
-
*
|
|
48
|
-
* // Create and send a message containing these op space IDs along with the sender's session ID
|
|
49
|
-
* // In Fluid, this would be an op or summary
|
|
50
|
-
* const message = {
|
|
51
|
-
* sessionID: idCompressor.localSessionId,
|
|
52
|
-
* ids: [opSpaceId1, opSpaceId2, opSpaceId3]
|
|
53
|
-
* };
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* ### Client B (Receiver)
|
|
57
|
-
*
|
|
58
|
-
* ```typescript
|
|
59
|
-
* // Receive the message from Client A
|
|
60
|
-
* const receivedMessage = ...; // In Fluid, this would be an op or summary
|
|
61
|
-
*
|
|
62
|
-
* // Normalize the received IDs back to session space, utilizing the sender's session ID
|
|
63
|
-
* const sessionSpaceId1 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[0], receivedMessage.sessionID);
|
|
64
|
-
* const sessionSpaceId2 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[1], receivedMessage.sessionID);
|
|
65
|
-
* const sessionSpaceId3 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[2], receivedMessage.sessionID);
|
|
66
|
-
* ```
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export declare interface IIdCompressor {
|
|
70
|
-
/**
|
|
71
|
-
* The local session ID.
|
|
72
|
-
*/
|
|
73
|
-
localSessionId: SessionId;
|
|
74
|
-
/**
|
|
75
|
-
* Generates a new compressed ID.
|
|
76
|
-
* The returned ID is in session space and should not be serialized directly. See `IIdCompressor` for more details.
|
|
77
|
-
* @returns A new local ID in session space.
|
|
78
|
-
*/
|
|
79
|
-
generateCompressedId(): SessionSpaceCompressedId;
|
|
80
|
-
/**
|
|
81
|
-
* Generates a new ID that is guaranteed to be unique across all sessions known to this compressor without the need for any
|
|
82
|
-
* normalization. The returned ID is not guaranteed to be a compressed ID (small number); it may be a stable ID (UUID string).
|
|
83
|
-
* In Fluid, the likelihood of generating the bulkier stable ID is dictated by network conditions and is highly probably in
|
|
84
|
-
* scenarios such as offline. This is still useful for use cases where simplicity is more important than performance and
|
|
85
|
-
* this approach will often be superior to generating a UUID.
|
|
86
|
-
* If small numbers are a requirement, `generateCompressedId` and normalization should be used instead.
|
|
87
|
-
* See `IIdCompressor` for more details.
|
|
88
|
-
* @returns A new local ID in session space.
|
|
89
|
-
*/
|
|
90
|
-
generateDocumentUniqueId(): (SessionSpaceCompressedId & OpSpaceCompressedId) | StableId;
|
|
91
|
-
/**
|
|
92
|
-
* Normalizes a session space ID into op space.
|
|
93
|
-
* The returned ID is in op space and can be safely serialized. However, it should be normalized back to session space before use.
|
|
94
|
-
* See `IIdCompressor` for more details.
|
|
95
|
-
* @param id - The local ID to normalize.
|
|
96
|
-
* @returns The ID in op space.
|
|
97
|
-
*/
|
|
98
|
-
normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
|
|
99
|
-
/**
|
|
100
|
-
* Normalizes an ID into session space.
|
|
101
|
-
* @param id - The ID to normalize.
|
|
102
|
-
* @param originSessionId - The session from which `id` originated. This should be the ID of the client that normalized `id` to op space.
|
|
103
|
-
* This means that it may not be the client that created `id` in the first place, but rather the client that serialized it.
|
|
104
|
-
* This is an important distinction in the case of a reference, where a client might refer to an ID created by another client.
|
|
105
|
-
* @returns The session-space ID in the local session corresponding to `id`.
|
|
106
|
-
*/
|
|
107
|
-
normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
|
|
108
|
-
/**
|
|
109
|
-
* Decompresses a previously compressed ID into a UUID.
|
|
110
|
-
* @param id - The compressed ID to be decompressed.
|
|
111
|
-
* @returns The UUID associated with the compressed ID.
|
|
112
|
-
* @throws If the ID was not generated by any session known to this compressor.
|
|
113
|
-
*/
|
|
114
|
-
decompress(id: SessionSpaceCompressedId): StableId;
|
|
115
|
-
/**
|
|
116
|
-
* Recompresses a UUID.
|
|
117
|
-
* @param uncompressed - The UUID to recompress.
|
|
118
|
-
* @returns The `CompressedId` associated with `uncompressed`.
|
|
119
|
-
* @throws If the UUID was not generated by any session known to this compressor.
|
|
120
|
-
*/
|
|
121
|
-
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
122
|
-
/**
|
|
123
|
-
* Attempts to recompress a UUID.
|
|
124
|
-
* @param uncompressed - The UUID to recompress.
|
|
125
|
-
* @returns The `CompressedId` associated with `uncompressed` or undefined if the UUID was not generated by any session known to this compressor.
|
|
126
|
-
*/
|
|
127
|
-
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Excluded from this release type: IIdCompressorCore */
|
|
131
|
-
|
|
132
|
-
/* Excluded from this release type: isStableId */
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* A compressed ID that has been normalized into "op space".
|
|
136
|
-
* Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
|
|
137
|
-
* received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
|
|
138
|
-
* @public
|
|
139
|
-
*/
|
|
140
|
-
export declare type OpSpaceCompressedId = number & {
|
|
141
|
-
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/* Excluded from this release type: SerializedIdCompressor */
|
|
145
|
-
|
|
146
|
-
/* Excluded from this release type: SerializedIdCompressorWithNoSession */
|
|
147
|
-
|
|
148
|
-
/* Excluded from this release type: SerializedIdCompressorWithOngoingSession */
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* A StableId which is suitable for use as a session identifier
|
|
152
|
-
* @public
|
|
153
|
-
*/
|
|
154
|
-
export declare type SessionId = StableId & {
|
|
155
|
-
readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
|
|
160
|
-
* Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
|
|
161
|
-
* the scope of the session (i.e. compressor) that produced them.
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
export declare type SessionSpaceCompressedId = number & {
|
|
165
|
-
readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
|
|
170
|
-
* A 128-bit Universally Unique IDentifier. Represented here
|
|
171
|
-
* with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
|
|
172
|
-
* where x is a lowercase hex digit.
|
|
173
|
-
* @public
|
|
174
|
-
*/
|
|
175
|
-
export declare type StableId = string & {
|
|
176
|
-
readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export { }
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
2
|
-
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Asserts that the given string is a stable ID.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export declare function assertIsStableId(stableId: string): StableId;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create a new {@link IIdCompressor}.
|
|
12
|
-
* @alpha
|
|
13
|
-
*/
|
|
14
|
-
export declare function createIdCompressor(logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Create a new {@link IIdCompressor}.
|
|
18
|
-
* @param sessionId - The seed ID for the compressor.
|
|
19
|
-
* @alpha
|
|
20
|
-
*/
|
|
21
|
-
export declare function createIdCompressor(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Generate a random session ID
|
|
25
|
-
* @alpha
|
|
26
|
-
*/
|
|
27
|
-
export declare function createSessionId(): SessionId;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Deserializes the supplied state into an ID compressor.
|
|
31
|
-
* @alpha
|
|
32
|
-
*/
|
|
33
|
-
export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithOngoingSession, logger?: ITelemetryLoggerExt): IIdCompressor & IIdCompressorCore;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Deserializes the supplied state into an ID compressor.
|
|
37
|
-
* @alpha
|
|
38
|
-
*/
|
|
39
|
-
export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId, logger?: ITelemetryLoggerExt): IIdCompressor & IIdCompressorCore;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Generate a random stable ID
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
export declare function generateStableId(): StableId;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Data describing a range of session-local IDs (from a remote or local session).
|
|
49
|
-
*
|
|
50
|
-
* A range is composed of local IDs that were generated.
|
|
51
|
-
* @alpha
|
|
52
|
-
*/
|
|
53
|
-
export declare interface IdCreationRange {
|
|
54
|
-
readonly sessionId: SessionId;
|
|
55
|
-
readonly ids?: {
|
|
56
|
-
/**
|
|
57
|
-
* The gen count of the first ID in the range created by `sessionId.`
|
|
58
|
-
*/
|
|
59
|
-
readonly firstGenCount: number;
|
|
60
|
-
/**
|
|
61
|
-
* The number of IDs created in the range created by `sessionId.`
|
|
62
|
-
*/
|
|
63
|
-
readonly count: number;
|
|
64
|
-
/**
|
|
65
|
-
* The size of the ID cluster to create if `count` overflows the existing cluster for
|
|
66
|
-
* `sessionId`, if one exists. This request will be respected, and the size of the cluster
|
|
67
|
-
* will be equal to overflow + `requestedClusterSize`.
|
|
68
|
-
*/
|
|
69
|
-
readonly requestedClusterSize: number;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A distributed UUID generator and compressor.
|
|
75
|
-
* `IdCompressor` offers the ability to generate arbitrary non-colliding v4 UUIDs, called stable IDs, while compressing them into small integers
|
|
76
|
-
* for efficient storage and transmission. It also provides the ability to decompress these integers back into their original UUIDs.
|
|
77
|
-
*
|
|
78
|
-
* The compressor is designed to be used in a distributed environment, where multiple clients may be generating IDs concurrently.
|
|
79
|
-
* IDs generated by a compressor, via calls to `generateCompressedId`, are created in the compressor's "local" session.
|
|
80
|
-
* These IDs are unique within the session, but may not be unique across sessions. In the context of Fluid, the scope of a session
|
|
81
|
-
* is the same as the scope of a container. This means that anytime IDs are transferred between sessions, they must be translated
|
|
82
|
-
* through a process called "normalization":
|
|
83
|
-
* - The scope of a local session (in which local IDs are unique) is called the "session space" of the client.
|
|
84
|
-
* - The context of persisted state (in Fluid, this is the context of ops and summaries) is called "op space".
|
|
85
|
-
* - `SessionSpaceCompressedId`s, generated via calls to `generateCompressedId`, should NEVER be serialized directly.
|
|
86
|
-
* In Fluid, this means they should not be included in ops or summaries.
|
|
87
|
-
* - Before serialization, IDs must be normalized to op space to ensure they are interpretable by other clients.
|
|
88
|
-
* - Upon receipt, IDs should be normalized back to session space before use.
|
|
89
|
-
*
|
|
90
|
-
* Example Usage:
|
|
91
|
-
*
|
|
92
|
-
* ### Client A (Sender)
|
|
93
|
-
*
|
|
94
|
-
* ```typescript
|
|
95
|
-
* // Generate several local IDs
|
|
96
|
-
* const localId1 = idCompressor.generateCompressedId();
|
|
97
|
-
* const localId2 = idCompressor.generateCompressedId();
|
|
98
|
-
* const localId3 = idCompressor.generateCompressedId();
|
|
99
|
-
*
|
|
100
|
-
* // Normalize these IDs to op space for inclusion in a message
|
|
101
|
-
* const opSpaceId1 = idCompressor.normalizeToOpSpace(localId1);
|
|
102
|
-
* const opSpaceId2 = idCompressor.normalizeToOpSpace(localId2);
|
|
103
|
-
* const opSpaceId3 = idCompressor.normalizeToOpSpace(localId3);
|
|
104
|
-
*
|
|
105
|
-
* // Create and send a message containing these op space IDs along with the sender's session ID
|
|
106
|
-
* // In Fluid, this would be an op or summary
|
|
107
|
-
* const message = {
|
|
108
|
-
* sessionID: idCompressor.localSessionId,
|
|
109
|
-
* ids: [opSpaceId1, opSpaceId2, opSpaceId3]
|
|
110
|
-
* };
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* ### Client B (Receiver)
|
|
114
|
-
*
|
|
115
|
-
* ```typescript
|
|
116
|
-
* // Receive the message from Client A
|
|
117
|
-
* const receivedMessage = ...; // In Fluid, this would be an op or summary
|
|
118
|
-
*
|
|
119
|
-
* // Normalize the received IDs back to session space, utilizing the sender's session ID
|
|
120
|
-
* const sessionSpaceId1 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[0], receivedMessage.sessionID);
|
|
121
|
-
* const sessionSpaceId2 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[1], receivedMessage.sessionID);
|
|
122
|
-
* const sessionSpaceId3 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[2], receivedMessage.sessionID);
|
|
123
|
-
* ```
|
|
124
|
-
* @public
|
|
125
|
-
*/
|
|
126
|
-
export declare interface IIdCompressor {
|
|
127
|
-
/**
|
|
128
|
-
* The local session ID.
|
|
129
|
-
*/
|
|
130
|
-
localSessionId: SessionId;
|
|
131
|
-
/**
|
|
132
|
-
* Generates a new compressed ID.
|
|
133
|
-
* The returned ID is in session space and should not be serialized directly. See `IIdCompressor` for more details.
|
|
134
|
-
* @returns A new local ID in session space.
|
|
135
|
-
*/
|
|
136
|
-
generateCompressedId(): SessionSpaceCompressedId;
|
|
137
|
-
/**
|
|
138
|
-
* Generates a new ID that is guaranteed to be unique across all sessions known to this compressor without the need for any
|
|
139
|
-
* normalization. The returned ID is not guaranteed to be a compressed ID (small number); it may be a stable ID (UUID string).
|
|
140
|
-
* In Fluid, the likelihood of generating the bulkier stable ID is dictated by network conditions and is highly probably in
|
|
141
|
-
* scenarios such as offline. This is still useful for use cases where simplicity is more important than performance and
|
|
142
|
-
* this approach will often be superior to generating a UUID.
|
|
143
|
-
* If small numbers are a requirement, `generateCompressedId` and normalization should be used instead.
|
|
144
|
-
* See `IIdCompressor` for more details.
|
|
145
|
-
* @returns A new local ID in session space.
|
|
146
|
-
*/
|
|
147
|
-
generateDocumentUniqueId(): (SessionSpaceCompressedId & OpSpaceCompressedId) | StableId;
|
|
148
|
-
/**
|
|
149
|
-
* Normalizes a session space ID into op space.
|
|
150
|
-
* The returned ID is in op space and can be safely serialized. However, it should be normalized back to session space before use.
|
|
151
|
-
* See `IIdCompressor` for more details.
|
|
152
|
-
* @param id - The local ID to normalize.
|
|
153
|
-
* @returns The ID in op space.
|
|
154
|
-
*/
|
|
155
|
-
normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
|
|
156
|
-
/**
|
|
157
|
-
* Normalizes an ID into session space.
|
|
158
|
-
* @param id - The ID to normalize.
|
|
159
|
-
* @param originSessionId - The session from which `id` originated. This should be the ID of the client that normalized `id` to op space.
|
|
160
|
-
* This means that it may not be the client that created `id` in the first place, but rather the client that serialized it.
|
|
161
|
-
* This is an important distinction in the case of a reference, where a client might refer to an ID created by another client.
|
|
162
|
-
* @returns The session-space ID in the local session corresponding to `id`.
|
|
163
|
-
*/
|
|
164
|
-
normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
|
|
165
|
-
/**
|
|
166
|
-
* Decompresses a previously compressed ID into a UUID.
|
|
167
|
-
* @param id - The compressed ID to be decompressed.
|
|
168
|
-
* @returns The UUID associated with the compressed ID.
|
|
169
|
-
* @throws If the ID was not generated by any session known to this compressor.
|
|
170
|
-
*/
|
|
171
|
-
decompress(id: SessionSpaceCompressedId): StableId;
|
|
172
|
-
/**
|
|
173
|
-
* Recompresses a UUID.
|
|
174
|
-
* @param uncompressed - The UUID to recompress.
|
|
175
|
-
* @returns The `CompressedId` associated with `uncompressed`.
|
|
176
|
-
* @throws If the UUID was not generated by any session known to this compressor.
|
|
177
|
-
*/
|
|
178
|
-
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
179
|
-
/**
|
|
180
|
-
* Attempts to recompress a UUID.
|
|
181
|
-
* @param uncompressed - The UUID to recompress.
|
|
182
|
-
* @returns The `CompressedId` associated with `uncompressed` or undefined if the UUID was not generated by any session known to this compressor.
|
|
183
|
-
*/
|
|
184
|
-
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* A distributed UUID generator and compressor.
|
|
189
|
-
*
|
|
190
|
-
* Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple "sessions" (which can be distributed across the network),
|
|
191
|
-
* providing each session with the ability to map these UUIDs to `numbers`.
|
|
192
|
-
*
|
|
193
|
-
* A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API
|
|
194
|
-
* which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is
|
|
195
|
-
* created it is said to be created by the compressor's "local" session.
|
|
196
|
-
*
|
|
197
|
-
* For each stable ID created, two numeric IDs are provided by the compressor:
|
|
198
|
-
*
|
|
199
|
-
* 1. A session-local ID, which is stable for the lifetime of the session (which could be longer than that of the compressor object, as it may
|
|
200
|
-
* be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
|
|
201
|
-
* safely usable within the scope of the compressor that created it.
|
|
202
|
-
*
|
|
203
|
-
* 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
|
|
204
|
-
* the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
|
|
205
|
-
* Final IDs are known to and publicly usable by any compressor that has received them.
|
|
206
|
-
*
|
|
207
|
-
* Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
|
|
208
|
-
* to map the UUIDs to the numbers.
|
|
209
|
-
*
|
|
210
|
-
* The following invariants are upheld by IdCompressor:
|
|
211
|
-
*
|
|
212
|
-
* 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
|
|
213
|
-
*
|
|
214
|
-
* 2. Final IDs will always decompress to the same UUIDs.
|
|
215
|
-
*
|
|
216
|
-
* 3. After a server-processed range of session-local IDs (from any session) is received by a compressor, any of those session-local IDs may be
|
|
217
|
-
* translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
|
|
218
|
-
* same final ID.
|
|
219
|
-
*
|
|
220
|
-
* 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
|
|
221
|
-
*
|
|
222
|
-
* Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
|
|
223
|
-
* be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
|
|
224
|
-
*
|
|
225
|
-
* Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
|
|
226
|
-
* could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
|
|
227
|
-
* session-local ID but is later queried using the final ID (which is semantically equal, as it decompresses to the same UUID/string) it will
|
|
228
|
-
* produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
|
|
229
|
-
* session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
|
|
230
|
-
*
|
|
231
|
-
* 1. Session space: in this space, all IDs are normalized to their "most local form". This means that all IDs created by the local session
|
|
232
|
-
* will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after
|
|
233
|
-
* finalizing and will never have a local form for the compressor, will of course be final IDs. This space should be used with consumer APIs
|
|
234
|
-
* and data structures, as the lifetime of the IDs is guaranteed to be the same as the compressor object. Care must be taken to not use
|
|
235
|
-
* these IDs across compressor objects, as the local IDs are specific to the compressor that created them.
|
|
236
|
-
*
|
|
237
|
-
* 2. Op space: in this space, all IDs are normalized to their "most final form". This means that all IDs except session-local IDs that
|
|
238
|
-
* have not yet been finalized will be in final ID form. This space is useful for serialization in ops (e.g. references), as other clients
|
|
239
|
-
* that receive them need not do any work to normalize them to *their* session-space in the common case. Note that IDs in op space may move
|
|
240
|
-
* out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
|
|
241
|
-
* Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
|
|
242
|
-
* incorrect to use this type for a runtime variable. This is an asymmetry that does not affect session space, as local IDs are always as
|
|
243
|
-
* "local as possible".
|
|
244
|
-
*
|
|
245
|
-
* These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
|
|
246
|
-
* should use op-space IDs.
|
|
247
|
-
* @alpha
|
|
248
|
-
*/
|
|
249
|
-
export declare interface IIdCompressorCore {
|
|
250
|
-
/**
|
|
251
|
-
* Returns a range of IDs created by this session in a format for sending to the server for finalizing.
|
|
252
|
-
* The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.
|
|
253
|
-
* @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before
|
|
254
|
-
* it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
|
|
255
|
-
*/
|
|
256
|
-
takeNextCreationRange(): IdCreationRange;
|
|
257
|
-
/**
|
|
258
|
-
* Finalizes the supplied range of IDs (which may be from either a remote or local session).
|
|
259
|
-
* @param range - the range of session-local IDs to finalize.
|
|
260
|
-
*/
|
|
261
|
-
finalizeCreationRange(range: IdCreationRange): void;
|
|
262
|
-
/**
|
|
263
|
-
* Run a callback that is performed from the perspective of a special "ghost" session.
|
|
264
|
-
* Any ids generated by this session will be immediately finalized on the local client as if
|
|
265
|
-
* they were created by a remote client with `ghostSessionId`.
|
|
266
|
-
*
|
|
267
|
-
* *WARNING:* This API requires an external consensus mechanism to safely use:
|
|
268
|
-
* In an attached container (i.e. multiple clients may have the document loaded), all clients must guarantee that:
|
|
269
|
-
* - They invoke this API starting from the same finalized creation ranges
|
|
270
|
-
* - This API is invoked with the same ghost session id
|
|
271
|
-
* - `ghostSessionCallback` deterministically mints the same number of ids on each client within the ghost session
|
|
272
|
-
* Failure to meet these requirement will result in divergence across clients and eventual consistency errors.
|
|
273
|
-
* While the ghost sesion callback is running, IdCompressor does not support serialization.
|
|
274
|
-
* @remarks This API is primarily intended for data migration scenarios which are able to deterministically transform
|
|
275
|
-
* data in some format into data in a new format.
|
|
276
|
-
* The first requirement (that all clients must invoke the API with the same finalized creation ranges) is guaranteed
|
|
277
|
-
* for this scenario because the data transformation callback occurs at a specific ack within the op stream on all
|
|
278
|
-
* clients, and clients don't finalize creation ranges for local changes they might have at this point in time.
|
|
279
|
-
* @param ghostSessionId - The session id that minted ids generated within `ghostSessionCallback` should be attributed to.
|
|
280
|
-
* @param ghostSessionCallback - Callback which mints ids attributed to the ghost session.
|
|
281
|
-
*/
|
|
282
|
-
beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): any;
|
|
283
|
-
/**
|
|
284
|
-
* Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
|
|
285
|
-
* This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
|
|
286
|
-
*/
|
|
287
|
-
serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
|
|
288
|
-
/**
|
|
289
|
-
* Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
|
|
290
|
-
* This only includes finalized state and is therefore suitable for use in summaries.
|
|
291
|
-
*/
|
|
292
|
-
serialize(withSession: false): SerializedIdCompressorWithNoSession;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
297
|
-
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
298
|
-
* @internal
|
|
299
|
-
*/
|
|
300
|
-
export declare function isStableId(str: string): str is StableId;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* A compressed ID that has been normalized into "op space".
|
|
304
|
-
* Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
|
|
305
|
-
* received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
|
|
306
|
-
* @public
|
|
307
|
-
*/
|
|
308
|
-
export declare type OpSpaceCompressedId = number & {
|
|
309
|
-
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
314
|
-
* @alpha
|
|
315
|
-
*/
|
|
316
|
-
export declare type SerializedIdCompressor = string & {
|
|
317
|
-
readonly _serializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
322
|
-
* @alpha
|
|
323
|
-
*/
|
|
324
|
-
export declare type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {
|
|
325
|
-
readonly _noLocalState: "3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb";
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
330
|
-
* @alpha
|
|
331
|
-
*/
|
|
332
|
-
export declare type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {
|
|
333
|
-
readonly _hasLocalState: "1281acae-6d14-47e7-bc92-71c8ee0819cb";
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* A StableId which is suitable for use as a session identifier
|
|
338
|
-
* @public
|
|
339
|
-
*/
|
|
340
|
-
export declare type SessionId = StableId & {
|
|
341
|
-
readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
|
|
346
|
-
* Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
|
|
347
|
-
* the scope of the session (i.e. compressor) that produced them.
|
|
348
|
-
* @public
|
|
349
|
-
*/
|
|
350
|
-
export declare type SessionSpaceCompressedId = number & {
|
|
351
|
-
readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
|
|
356
|
-
* A 128-bit Universally Unique IDentifier. Represented here
|
|
357
|
-
* with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
|
|
358
|
-
* where x is a lowercase hex digit.
|
|
359
|
-
* @public
|
|
360
|
-
*/
|
|
361
|
-
export declare type StableId = string & {
|
|
362
|
-
readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
export { }
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { benchmark, BenchmarkType } from "@fluid-tools/benchmark";
|
|
6
|
-
import { makeRandom } from "@fluid-private/stochastic-test-utils";
|
|
7
|
-
import { AppendOnlySortedMap } from "../appendOnlySortedMap.js";
|
|
8
|
-
import { compareFiniteNumbers } from "../utilities.js";
|
|
9
|
-
function runAppendOnlyMapPerfTests(mapBuilder) {
|
|
10
|
-
const type = BenchmarkType.Measurement;
|
|
11
|
-
let map;
|
|
12
|
-
let rand;
|
|
13
|
-
const keyChoices = [];
|
|
14
|
-
let localChoice = 0;
|
|
15
|
-
const before = () => {
|
|
16
|
-
rand = makeRandom(42);
|
|
17
|
-
map = mapBuilder();
|
|
18
|
-
let curKey = 0;
|
|
19
|
-
for (let i = 0; i < 100000; i++) {
|
|
20
|
-
map.append(curKey, rand.integer(0, Number.MAX_SAFE_INTEGER));
|
|
21
|
-
curKey += rand.integer(1, 10);
|
|
22
|
-
}
|
|
23
|
-
const keys = [...map.keys()];
|
|
24
|
-
for (let i = 0; i < map.size; i++) {
|
|
25
|
-
keyChoices.push(keys[rand.integer(0, map.size - 1)]);
|
|
26
|
-
}
|
|
27
|
-
localChoice = 0;
|
|
28
|
-
};
|
|
29
|
-
benchmark({
|
|
30
|
-
type,
|
|
31
|
-
title: `lookup a key`,
|
|
32
|
-
before,
|
|
33
|
-
benchmarkFn: () => {
|
|
34
|
-
map.get(keyChoices[localChoice++ % keyChoices.length]);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
benchmark({
|
|
38
|
-
type,
|
|
39
|
-
title: `lookup a pair or lower`,
|
|
40
|
-
before,
|
|
41
|
-
benchmarkFn: () => {
|
|
42
|
-
map.getPairOrNextLower(keyChoices[localChoice++ % keyChoices.length]);
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
describe("AppendOnlySortedMap Perf", () => {
|
|
47
|
-
runAppendOnlyMapPerfTests(() => new AppendOnlySortedMap(compareFiniteNumbers));
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=appendOnlySortedMap.perf.spec.js.map
|