@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.
Files changed (157) hide show
  1. package/.eslintrc.js +27 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +7 -0
  4. package/LICENSE +21 -0
  5. package/README.md +170 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +4 -0
  8. package/api-report/id-compressor.api.md +139 -0
  9. package/dist/appendOnlySortedMap.cjs +318 -0
  10. package/dist/appendOnlySortedMap.cjs.map +1 -0
  11. package/dist/appendOnlySortedMap.d.ts +124 -0
  12. package/dist/appendOnlySortedMap.d.ts.map +1 -0
  13. package/dist/finalSpace.cjs +62 -0
  14. package/dist/finalSpace.cjs.map +1 -0
  15. package/dist/finalSpace.d.ts +29 -0
  16. package/dist/finalSpace.d.ts.map +1 -0
  17. package/dist/id-compressor-alpha.d.ts +320 -0
  18. package/dist/id-compressor-beta.d.ts +172 -0
  19. package/dist/id-compressor-public.d.ts +172 -0
  20. package/dist/id-compressor-untrimmed.d.ts +333 -0
  21. package/dist/idCompressor.cjs +502 -0
  22. package/dist/idCompressor.cjs.map +1 -0
  23. package/dist/idCompressor.d.ts +84 -0
  24. package/dist/idCompressor.d.ts.map +1 -0
  25. package/dist/identifiers.cjs +15 -0
  26. package/dist/identifiers.cjs.map +1 -0
  27. package/dist/identifiers.d.ts +32 -0
  28. package/dist/identifiers.d.ts.map +1 -0
  29. package/dist/index.cjs +20 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.ts +11 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/packageVersion.cjs +12 -0
  34. package/dist/packageVersion.cjs.map +1 -0
  35. package/dist/packageVersion.d.ts +9 -0
  36. package/dist/packageVersion.d.ts.map +1 -0
  37. package/dist/persistanceUtilities.cjs +43 -0
  38. package/dist/persistanceUtilities.cjs.map +1 -0
  39. package/dist/persistanceUtilities.d.ts +22 -0
  40. package/dist/persistanceUtilities.d.ts.map +1 -0
  41. package/dist/sessionSpaceNormalizer.cjs +80 -0
  42. package/dist/sessionSpaceNormalizer.cjs.map +1 -0
  43. package/dist/sessionSpaceNormalizer.d.ts +46 -0
  44. package/dist/sessionSpaceNormalizer.d.ts.map +1 -0
  45. package/dist/sessions.cjs +305 -0
  46. package/dist/sessions.cjs.map +1 -0
  47. package/dist/sessions.d.ts +115 -0
  48. package/dist/sessions.d.ts.map +1 -0
  49. package/dist/tsdoc-metadata.json +11 -0
  50. package/dist/types/idCompressor.cjs +7 -0
  51. package/dist/types/idCompressor.cjs.map +1 -0
  52. package/dist/types/idCompressor.d.ts +139 -0
  53. package/dist/types/idCompressor.d.ts.map +1 -0
  54. package/dist/types/identifiers.cjs +7 -0
  55. package/dist/types/identifiers.cjs.map +1 -0
  56. package/dist/types/identifiers.d.ts +40 -0
  57. package/dist/types/identifiers.d.ts.map +1 -0
  58. package/dist/types/index.cjs +7 -0
  59. package/dist/types/index.cjs.map +1 -0
  60. package/dist/types/index.d.ts +8 -0
  61. package/dist/types/index.d.ts.map +1 -0
  62. package/dist/types/persisted-types/0.0.1.cjs +7 -0
  63. package/dist/types/persisted-types/0.0.1.cjs.map +1 -0
  64. package/dist/types/persisted-types/0.0.1.d.ts +52 -0
  65. package/dist/types/persisted-types/0.0.1.d.ts.map +1 -0
  66. package/dist/types/persisted-types/index.cjs +7 -0
  67. package/dist/types/persisted-types/index.cjs.map +1 -0
  68. package/dist/types/persisted-types/index.d.ts +6 -0
  69. package/dist/types/persisted-types/index.d.ts.map +1 -0
  70. package/dist/utilities.cjs +170 -0
  71. package/dist/utilities.cjs.map +1 -0
  72. package/dist/utilities.d.ts +53 -0
  73. package/dist/utilities.d.ts.map +1 -0
  74. package/lib/appendOnlySortedMap.d.mts +124 -0
  75. package/lib/appendOnlySortedMap.d.mts.map +1 -0
  76. package/lib/appendOnlySortedMap.mjs +312 -0
  77. package/lib/appendOnlySortedMap.mjs.map +1 -0
  78. package/lib/finalSpace.d.mts +29 -0
  79. package/lib/finalSpace.d.mts.map +1 -0
  80. package/lib/finalSpace.mjs +58 -0
  81. package/lib/finalSpace.mjs.map +1 -0
  82. package/lib/id-compressor-alpha.d.mts +320 -0
  83. package/lib/id-compressor-beta.d.mts +172 -0
  84. package/lib/id-compressor-public.d.mts +172 -0
  85. package/lib/id-compressor-untrimmed.d.mts +333 -0
  86. package/lib/idCompressor.d.mts +84 -0
  87. package/lib/idCompressor.d.mts.map +1 -0
  88. package/lib/idCompressor.mjs +496 -0
  89. package/lib/idCompressor.mjs.map +1 -0
  90. package/lib/identifiers.d.mts +32 -0
  91. package/lib/identifiers.d.mts.map +1 -0
  92. package/lib/identifiers.mjs +11 -0
  93. package/lib/identifiers.mjs.map +1 -0
  94. package/lib/index.d.mts +8 -0
  95. package/lib/index.d.mts.map +1 -0
  96. package/lib/index.mjs +7 -0
  97. package/lib/index.mjs.map +1 -0
  98. package/lib/packageVersion.d.mts +9 -0
  99. package/lib/packageVersion.d.mts.map +1 -0
  100. package/lib/packageVersion.mjs +9 -0
  101. package/lib/packageVersion.mjs.map +1 -0
  102. package/lib/persistanceUtilities.d.mts +22 -0
  103. package/lib/persistanceUtilities.d.mts.map +1 -0
  104. package/lib/persistanceUtilities.mjs +34 -0
  105. package/lib/persistanceUtilities.mjs.map +1 -0
  106. package/lib/sessionSpaceNormalizer.d.mts +46 -0
  107. package/lib/sessionSpaceNormalizer.d.mts.map +1 -0
  108. package/lib/sessionSpaceNormalizer.mjs +76 -0
  109. package/lib/sessionSpaceNormalizer.mjs.map +1 -0
  110. package/lib/sessions.d.mts +115 -0
  111. package/lib/sessions.d.mts.map +1 -0
  112. package/lib/sessions.mjs +290 -0
  113. package/lib/sessions.mjs.map +1 -0
  114. package/lib/types/idCompressor.d.mts +139 -0
  115. package/lib/types/idCompressor.d.mts.map +1 -0
  116. package/lib/types/idCompressor.mjs +6 -0
  117. package/lib/types/idCompressor.mjs.map +1 -0
  118. package/lib/types/identifiers.d.mts +40 -0
  119. package/lib/types/identifiers.d.mts.map +1 -0
  120. package/lib/types/identifiers.mjs +6 -0
  121. package/lib/types/identifiers.mjs.map +1 -0
  122. package/lib/types/index.d.mts +8 -0
  123. package/lib/types/index.d.mts.map +1 -0
  124. package/lib/types/index.mjs +6 -0
  125. package/lib/types/index.mjs.map +1 -0
  126. package/lib/types/persisted-types/0.0.1.d.mts +52 -0
  127. package/lib/types/persisted-types/0.0.1.d.mts.map +1 -0
  128. package/lib/types/persisted-types/0.0.1.mjs +6 -0
  129. package/lib/types/persisted-types/0.0.1.mjs.map +1 -0
  130. package/lib/types/persisted-types/index.d.mts +6 -0
  131. package/lib/types/persisted-types/index.d.mts.map +1 -0
  132. package/lib/types/persisted-types/index.mjs +6 -0
  133. package/lib/types/persisted-types/index.mjs.map +1 -0
  134. package/lib/utilities.d.mts +53 -0
  135. package/lib/utilities.d.mts.map +1 -0
  136. package/lib/utilities.mjs +151 -0
  137. package/lib/utilities.mjs.map +1 -0
  138. package/package.json +114 -0
  139. package/prettier.config.cjs +8 -0
  140. package/src/appendOnlySortedMap.ts +366 -0
  141. package/src/finalSpace.ts +67 -0
  142. package/src/idCompressor.ts +685 -0
  143. package/src/identifiers.ts +42 -0
  144. package/src/index.ts +23 -0
  145. package/src/packageVersion.ts +9 -0
  146. package/src/persistanceUtilities.ts +58 -0
  147. package/src/sessionSpaceNormalizer.ts +83 -0
  148. package/src/sessions.ts +405 -0
  149. package/src/types/idCompressor.ts +155 -0
  150. package/src/types/identifiers.ts +39 -0
  151. package/src/types/index.ts +15 -0
  152. package/src/types/persisted-types/0.0.1.ts +58 -0
  153. package/src/types/persisted-types/README.md +3 -0
  154. package/src/types/persisted-types/index.ts +11 -0
  155. package/src/utilities.ts +191 -0
  156. package/tsc-multi.test.json +4 -0
  157. package/tsconfig.json +12 -0
@@ -0,0 +1,320 @@
1
+ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
2
+
3
+ /* Excluded from this release type: assertIsStableId */
4
+
5
+ /**
6
+ * Create a new {@link IIdCompressor}.
7
+ * @alpha
8
+ */
9
+ export declare function createIdCompressor(logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
10
+
11
+ /**
12
+ * Create a new {@link IIdCompressor}.
13
+ * @param sessionId - The seed ID for the compressor.
14
+ * @alpha
15
+ */
16
+ export declare function createIdCompressor(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
17
+
18
+ /**
19
+ * Generate a random session ID
20
+ * @alpha
21
+ */
22
+ export declare function createSessionId(): SessionId;
23
+
24
+ /**
25
+ * Deserializes the supplied state into an ID compressor.
26
+ * @alpha
27
+ */
28
+ export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithOngoingSession): IIdCompressor & IIdCompressorCore;
29
+
30
+ /**
31
+ * Deserializes the supplied state into an ID compressor.
32
+ * @alpha
33
+ */
34
+ export declare function deserializeIdCompressor(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId): IIdCompressor & IIdCompressorCore;
35
+
36
+ /* Excluded from this release type: generateStableId */
37
+
38
+ /**
39
+ * See {@link IIdCompressor} and {@link IIdCompressorCore}
40
+ *
41
+ * @alpha
42
+ *
43
+ * @deprecated Not intended for public use and will be removed from the public API in the future.
44
+ * Use `createIdCompressor` instead.
45
+ */
46
+ export declare class IdCompressor implements IIdCompressor, IIdCompressorCore {
47
+ private readonly logger?;
48
+ /**
49
+ * Max allowed initial cluster size.
50
+ */
51
+ static readonly maxClusterSize: number;
52
+ readonly localSessionId: SessionId;
53
+ private readonly localSession;
54
+ private readonly normalizer;
55
+ private localGenCount;
56
+ private nextRangeBaseGenCount;
57
+ private readonly sessions;
58
+ private readonly finalSpace;
59
+ /**
60
+ * Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.
61
+ * Eventually, this can be adjusted dynamically to have cluster reservation policies that
62
+ * optimize the number of eager finals.
63
+ * It is not readonly as it is accessed by tests for clear-box testing.
64
+ */
65
+ private nextRequestedClusterSize;
66
+ private telemetryLocalIdCount;
67
+ private telemetryEagerFinalIdCount;
68
+ private constructor();
69
+ /**
70
+ * @deprecated Use `createIdCompressor` instead.
71
+ */
72
+ static create(logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
73
+ /**
74
+ * @deprecated Use `createIdCompressor` instead.
75
+ */
76
+ static create(sessionId: SessionId, logger?: ITelemetryBaseLogger): IIdCompressor & IIdCompressorCore;
77
+ generateCompressedId(): SessionSpaceCompressedId;
78
+ private generateNextLocalId;
79
+ takeNextCreationRange(): IdCreationRange;
80
+ private static assertValidRange;
81
+ finalizeCreationRange(range: IdCreationRange): void;
82
+ private addEmptyCluster;
83
+ normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
84
+ normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
85
+ decompress(id: SessionSpaceCompressedId): StableId;
86
+ recompress(uncompressed: StableId): SessionSpaceCompressedId;
87
+ tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
88
+ serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
89
+ serialize(withSession: false): SerializedIdCompressorWithNoSession;
90
+ static deserialize(serialized: SerializedIdCompressorWithOngoingSession): IdCompressor;
91
+ static deserialize(serialized: SerializedIdCompressorWithNoSession, newSessionId: SessionId): IdCompressor;
92
+ equals(other: IdCompressor, includeLocalState: boolean): boolean;
93
+ }
94
+
95
+ /**
96
+ * Data describing a range of session-local IDs (from a remote or local session).
97
+ *
98
+ * A range is composed of local IDs that were generated.
99
+ * @alpha
100
+ */
101
+ export declare interface IdCreationRange {
102
+ readonly sessionId: SessionId;
103
+ readonly ids?: {
104
+ /**
105
+ * The gen count of the first ID in the range created by `sessionId.`
106
+ */
107
+ readonly firstGenCount: number;
108
+ /**
109
+ * The number of IDs created in the range created by `sessionId.`
110
+ */
111
+ readonly count: number;
112
+ /**
113
+ * The size of the ID cluster to create if `count` overflows the existing cluster for
114
+ * `sessionId`, if one exists. This request will be respected, and the size of the cluster
115
+ * will be equal to overflow + `requestedClusterSize`.
116
+ */
117
+ readonly requestedClusterSize: number;
118
+ };
119
+ }
120
+
121
+ /**
122
+ * A distributed UUID generator and compressor.
123
+ *
124
+ * Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple "sessions" (which can be distributed across the network),
125
+ * providing each session with the ability to map these UUIDs to `numbers`.
126
+ *
127
+ * A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API
128
+ * which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is
129
+ * created it is said to be created by the compressor's "local" session.
130
+ *
131
+ * For each stable ID created, two numeric IDs are provided by the compressor:
132
+ *
133
+ * 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
134
+ * be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
135
+ * safely usable within the scope of the compressor that created it.
136
+ *
137
+ * 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
138
+ * the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
139
+ * Final IDs are known to and publicly usable by any compressor that has received them.
140
+ *
141
+ * Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
142
+ * to map the UUIDs to the numbers.
143
+ *
144
+ * The following invariants are upheld by IdCompressor:
145
+ *
146
+ * 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
147
+ *
148
+ * 2. Final IDs will always decompress to the same UUIDs.
149
+ *
150
+ * 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
151
+ * translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
152
+ * same final ID.
153
+ *
154
+ * 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
155
+ *
156
+ * Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
157
+ * be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
158
+ *
159
+ * Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
160
+ * could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
161
+ * 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
162
+ * produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
163
+ * session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
164
+ *
165
+ * 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
166
+ * will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after
167
+ * 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
168
+ * 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
169
+ * these IDs across compressor objects, as the local IDs are specific to the compressor that created them.
170
+ *
171
+ * 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
172
+ * 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
173
+ * 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
174
+ * out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
175
+ * Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
176
+ * 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
177
+ * "local as possible".
178
+ *
179
+ * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
180
+ * should use op-space IDs.
181
+ * @public
182
+ */
183
+ export declare interface IIdCompressor {
184
+ localSessionId: SessionId;
185
+ /**
186
+ * Generates a new compressed ID or returns an existing one.
187
+ * This should ONLY be called to generate IDs for local operations.
188
+ * @returns A new local ID in session space.
189
+ */
190
+ generateCompressedId(): SessionSpaceCompressedId;
191
+ /**
192
+ * Normalizes a session space ID into op space.
193
+ * @param id - the local ID to normalize.
194
+ * @returns the ID in op space.
195
+ */
196
+ normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
197
+ /**
198
+ * Normalizes an ID into session space.
199
+ * @param id - the ID to normalize. If it is a local ID, it is assumed to have been created by the session corresponding
200
+ * to `sessionId`.
201
+ * @param originSessionId - the session from which `id` originated
202
+ * @returns the session-space ID corresponding to `id`, which might not have been a final ID if the client that created it had not yet
203
+ * finalized it. This can occur when a client references an ID during the window of time in which it is waiting to receive the ordered
204
+ * range that contained it from the server.
205
+ */
206
+ normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
207
+ /**
208
+ * Decompresses a previously compressed ID into a UUID.
209
+ * @param id - the compressed ID to be decompressed.
210
+ * @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
211
+ */
212
+ decompress(id: SessionSpaceCompressedId): StableId;
213
+ /**
214
+ * Recompresses a UUID.
215
+ * @param uncompressed - the UUID to recompress.
216
+ * @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
217
+ */
218
+ recompress(uncompressed: StableId): SessionSpaceCompressedId;
219
+ /**
220
+ * Attempts to recompresses a UUID.
221
+ * @param uncompressed - the UUID to recompress,
222
+ * @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
223
+ */
224
+ tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
225
+ }
226
+
227
+ /**
228
+ * @alpha
229
+ */
230
+ export declare interface IIdCompressorCore {
231
+ /**
232
+ * Returns a range of IDs created by this session in a format for sending to the server for finalizing.
233
+ * The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.
234
+ * @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before
235
+ * it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
236
+ */
237
+ takeNextCreationRange(): IdCreationRange;
238
+ /**
239
+ * Finalizes the supplied range of IDs (which may be from either a remote or local session).
240
+ * @param range - the range of session-local IDs to finalize.
241
+ */
242
+ finalizeCreationRange(range: IdCreationRange): void;
243
+ /**
244
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
245
+ * This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
246
+ */
247
+ serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
248
+ /**
249
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
250
+ * This only includes finalized state and is therefore suitable for use in summaries.
251
+ */
252
+ serialize(withSession: false): SerializedIdCompressorWithNoSession;
253
+ }
254
+
255
+ /* Excluded from this release type: isStableId */
256
+
257
+ /**
258
+ * A compressed ID that has been normalized into "op space".
259
+ * Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
260
+ * received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
261
+ * @public
262
+ */
263
+ export declare type OpSpaceCompressedId = number & {
264
+ readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
265
+ };
266
+
267
+ /**
268
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
269
+ * @alpha
270
+ */
271
+ export declare type SerializedIdCompressor = string & {
272
+ readonly _serializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
273
+ };
274
+
275
+ /**
276
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
277
+ * @alpha
278
+ */
279
+ export declare type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {
280
+ readonly _noLocalState: "3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb";
281
+ };
282
+
283
+ /**
284
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
285
+ * @alpha
286
+ */
287
+ export declare type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {
288
+ readonly _hasLocalState: "1281acae-6d14-47e7-bc92-71c8ee0819cb";
289
+ };
290
+
291
+ /**
292
+ * A StableId which is suitable for use as a session identifier
293
+ * @public
294
+ */
295
+ export declare type SessionId = StableId & {
296
+ readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
297
+ };
298
+
299
+ /**
300
+ * A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
301
+ * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
302
+ * the scope of the session (i.e. compressor) that produced them.
303
+ * @public
304
+ */
305
+ export declare type SessionSpaceCompressedId = number & {
306
+ readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
307
+ };
308
+
309
+ /**
310
+ * A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
311
+ * A 128-bit Universally Unique IDentifier. Represented here
312
+ * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
313
+ * where x is a lowercase hex digit.
314
+ * @public
315
+ */
316
+ export declare type StableId = string & {
317
+ readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
318
+ };
319
+
320
+ export { }
@@ -0,0 +1,172 @@
1
+ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
2
+
3
+ /* Excluded from this release type: assertIsStableId */
4
+
5
+ /* Excluded from this release type: createIdCompressor */
6
+
7
+ /* Excluded from this release type: createSessionId */
8
+
9
+ /* Excluded from this release type: deserializeIdCompressor */
10
+
11
+ /* Excluded from this release type: generateStableId */
12
+
13
+ /* Excluded from this release type: IdCompressor */
14
+
15
+ /* Excluded from this release type: IdCreationRange */
16
+
17
+ /**
18
+ * A distributed UUID generator and compressor.
19
+ *
20
+ * Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple "sessions" (which can be distributed across the network),
21
+ * providing each session with the ability to map these UUIDs to `numbers`.
22
+ *
23
+ * A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API
24
+ * which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is
25
+ * created it is said to be created by the compressor's "local" session.
26
+ *
27
+ * For each stable ID created, two numeric IDs are provided by the compressor:
28
+ *
29
+ * 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
30
+ * be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
31
+ * safely usable within the scope of the compressor that created it.
32
+ *
33
+ * 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
34
+ * the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
35
+ * Final IDs are known to and publicly usable by any compressor that has received them.
36
+ *
37
+ * Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
38
+ * to map the UUIDs to the numbers.
39
+ *
40
+ * The following invariants are upheld by IdCompressor:
41
+ *
42
+ * 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
43
+ *
44
+ * 2. Final IDs will always decompress to the same UUIDs.
45
+ *
46
+ * 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
47
+ * translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
48
+ * same final ID.
49
+ *
50
+ * 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
51
+ *
52
+ * Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
53
+ * be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
54
+ *
55
+ * Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
56
+ * could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
57
+ * 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
58
+ * produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
59
+ * session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
60
+ *
61
+ * 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
62
+ * will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after
63
+ * 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
64
+ * 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
65
+ * these IDs across compressor objects, as the local IDs are specific to the compressor that created them.
66
+ *
67
+ * 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
68
+ * 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
69
+ * 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
70
+ * out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
71
+ * Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
72
+ * 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
73
+ * "local as possible".
74
+ *
75
+ * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
76
+ * should use op-space IDs.
77
+ * @public
78
+ */
79
+ export declare interface IIdCompressor {
80
+ localSessionId: SessionId;
81
+ /**
82
+ * Generates a new compressed ID or returns an existing one.
83
+ * This should ONLY be called to generate IDs for local operations.
84
+ * @returns A new local ID in session space.
85
+ */
86
+ generateCompressedId(): SessionSpaceCompressedId;
87
+ /**
88
+ * Normalizes a session space ID into op space.
89
+ * @param id - the local ID to normalize.
90
+ * @returns the ID in op space.
91
+ */
92
+ normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
93
+ /**
94
+ * Normalizes an ID into session space.
95
+ * @param id - the ID to normalize. If it is a local ID, it is assumed to have been created by the session corresponding
96
+ * to `sessionId`.
97
+ * @param originSessionId - the session from which `id` originated
98
+ * @returns the session-space ID corresponding to `id`, which might not have been a final ID if the client that created it had not yet
99
+ * finalized it. This can occur when a client references an ID during the window of time in which it is waiting to receive the ordered
100
+ * range that contained it from the server.
101
+ */
102
+ normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
103
+ /**
104
+ * Decompresses a previously compressed ID into a UUID.
105
+ * @param id - the compressed ID to be decompressed.
106
+ * @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
107
+ */
108
+ decompress(id: SessionSpaceCompressedId): StableId;
109
+ /**
110
+ * Recompresses a UUID.
111
+ * @param uncompressed - the UUID to recompress.
112
+ * @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
113
+ */
114
+ recompress(uncompressed: StableId): SessionSpaceCompressedId;
115
+ /**
116
+ * Attempts to recompresses a UUID.
117
+ * @param uncompressed - the UUID to recompress,
118
+ * @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
119
+ */
120
+ tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
121
+ }
122
+
123
+ /* Excluded from this release type: IIdCompressorCore */
124
+
125
+ /* Excluded from this release type: isStableId */
126
+
127
+ /**
128
+ * A compressed ID that has been normalized into "op space".
129
+ * Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
130
+ * received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
131
+ * @public
132
+ */
133
+ export declare type OpSpaceCompressedId = number & {
134
+ readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
135
+ };
136
+
137
+ /* Excluded from this release type: SerializedIdCompressor */
138
+
139
+ /* Excluded from this release type: SerializedIdCompressorWithNoSession */
140
+
141
+ /* Excluded from this release type: SerializedIdCompressorWithOngoingSession */
142
+
143
+ /**
144
+ * A StableId which is suitable for use as a session identifier
145
+ * @public
146
+ */
147
+ export declare type SessionId = StableId & {
148
+ readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
149
+ };
150
+
151
+ /**
152
+ * A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
153
+ * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
154
+ * the scope of the session (i.e. compressor) that produced them.
155
+ * @public
156
+ */
157
+ export declare type SessionSpaceCompressedId = number & {
158
+ readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
159
+ };
160
+
161
+ /**
162
+ * A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
163
+ * A 128-bit Universally Unique IDentifier. Represented here
164
+ * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
165
+ * where x is a lowercase hex digit.
166
+ * @public
167
+ */
168
+ export declare type StableId = string & {
169
+ readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
170
+ };
171
+
172
+ export { }
@@ -0,0 +1,172 @@
1
+ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
2
+
3
+ /* Excluded from this release type: assertIsStableId */
4
+
5
+ /* Excluded from this release type: createIdCompressor */
6
+
7
+ /* Excluded from this release type: createSessionId */
8
+
9
+ /* Excluded from this release type: deserializeIdCompressor */
10
+
11
+ /* Excluded from this release type: generateStableId */
12
+
13
+ /* Excluded from this release type: IdCompressor */
14
+
15
+ /* Excluded from this release type: IdCreationRange */
16
+
17
+ /**
18
+ * A distributed UUID generator and compressor.
19
+ *
20
+ * Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple "sessions" (which can be distributed across the network),
21
+ * providing each session with the ability to map these UUIDs to `numbers`.
22
+ *
23
+ * A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API
24
+ * which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is
25
+ * created it is said to be created by the compressor's "local" session.
26
+ *
27
+ * For each stable ID created, two numeric IDs are provided by the compressor:
28
+ *
29
+ * 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
30
+ * be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
31
+ * safely usable within the scope of the compressor that created it.
32
+ *
33
+ * 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
34
+ * the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
35
+ * Final IDs are known to and publicly usable by any compressor that has received them.
36
+ *
37
+ * Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
38
+ * to map the UUIDs to the numbers.
39
+ *
40
+ * The following invariants are upheld by IdCompressor:
41
+ *
42
+ * 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
43
+ *
44
+ * 2. Final IDs will always decompress to the same UUIDs.
45
+ *
46
+ * 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
47
+ * translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
48
+ * same final ID.
49
+ *
50
+ * 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
51
+ *
52
+ * Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
53
+ * be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
54
+ *
55
+ * Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
56
+ * could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
57
+ * 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
58
+ * produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
59
+ * session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
60
+ *
61
+ * 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
62
+ * will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after
63
+ * 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
64
+ * 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
65
+ * these IDs across compressor objects, as the local IDs are specific to the compressor that created them.
66
+ *
67
+ * 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
68
+ * 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
69
+ * 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
70
+ * out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
71
+ * Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
72
+ * 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
73
+ * "local as possible".
74
+ *
75
+ * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
76
+ * should use op-space IDs.
77
+ * @public
78
+ */
79
+ export declare interface IIdCompressor {
80
+ localSessionId: SessionId;
81
+ /**
82
+ * Generates a new compressed ID or returns an existing one.
83
+ * This should ONLY be called to generate IDs for local operations.
84
+ * @returns A new local ID in session space.
85
+ */
86
+ generateCompressedId(): SessionSpaceCompressedId;
87
+ /**
88
+ * Normalizes a session space ID into op space.
89
+ * @param id - the local ID to normalize.
90
+ * @returns the ID in op space.
91
+ */
92
+ normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
93
+ /**
94
+ * Normalizes an ID into session space.
95
+ * @param id - the ID to normalize. If it is a local ID, it is assumed to have been created by the session corresponding
96
+ * to `sessionId`.
97
+ * @param originSessionId - the session from which `id` originated
98
+ * @returns the session-space ID corresponding to `id`, which might not have been a final ID if the client that created it had not yet
99
+ * finalized it. This can occur when a client references an ID during the window of time in which it is waiting to receive the ordered
100
+ * range that contained it from the server.
101
+ */
102
+ normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
103
+ /**
104
+ * Decompresses a previously compressed ID into a UUID.
105
+ * @param id - the compressed ID to be decompressed.
106
+ * @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
107
+ */
108
+ decompress(id: SessionSpaceCompressedId): StableId;
109
+ /**
110
+ * Recompresses a UUID.
111
+ * @param uncompressed - the UUID to recompress.
112
+ * @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
113
+ */
114
+ recompress(uncompressed: StableId): SessionSpaceCompressedId;
115
+ /**
116
+ * Attempts to recompresses a UUID.
117
+ * @param uncompressed - the UUID to recompress,
118
+ * @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
119
+ */
120
+ tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
121
+ }
122
+
123
+ /* Excluded from this release type: IIdCompressorCore */
124
+
125
+ /* Excluded from this release type: isStableId */
126
+
127
+ /**
128
+ * A compressed ID that has been normalized into "op space".
129
+ * Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
130
+ * received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
131
+ * @public
132
+ */
133
+ export declare type OpSpaceCompressedId = number & {
134
+ readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
135
+ };
136
+
137
+ /* Excluded from this release type: SerializedIdCompressor */
138
+
139
+ /* Excluded from this release type: SerializedIdCompressorWithNoSession */
140
+
141
+ /* Excluded from this release type: SerializedIdCompressorWithOngoingSession */
142
+
143
+ /**
144
+ * A StableId which is suitable for use as a session identifier
145
+ * @public
146
+ */
147
+ export declare type SessionId = StableId & {
148
+ readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
149
+ };
150
+
151
+ /**
152
+ * A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
153
+ * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
154
+ * the scope of the session (i.e. compressor) that produced them.
155
+ * @public
156
+ */
157
+ export declare type SessionSpaceCompressedId = number & {
158
+ readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
159
+ };
160
+
161
+ /**
162
+ * A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
163
+ * A 128-bit Universally Unique IDentifier. Represented here
164
+ * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
165
+ * where x is a lowercase hex digit.
166
+ * @public
167
+ */
168
+ export declare type StableId = string & {
169
+ readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
170
+ };
171
+
172
+ export { }