@fluidframework/id-compressor 2.0.0-rc.1.0.4 → 2.0.0-rc.2.0.0
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 → .eslintrc.cjs} +5 -5
- package/{.mocharc.js → .mocharc.cjs} +1 -1
- package/CHANGELOG.md +8 -0
- package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
- package/api-extractor-lint.json +1 -1
- package/api-extractor.json +1 -1
- package/api-report/id-compressor.api.md +5 -42
- package/dist/finalSpace.d.ts +2 -2
- package/dist/finalSpace.d.ts.map +1 -1
- package/dist/finalSpace.js +4 -4
- package/dist/finalSpace.js.map +1 -1
- package/dist/id-compressor-alpha.d.ts +117 -112
- package/dist/id-compressor-beta.d.ts +84 -77
- package/dist/id-compressor-public.d.ts +84 -77
- package/dist/id-compressor-untrimmed.d.ts +117 -112
- package/dist/idCompressor.d.ts +15 -19
- package/dist/idCompressor.d.ts.map +1 -1
- package/dist/idCompressor.js +107 -94
- package/dist/idCompressor.js.map +1 -1
- package/dist/identifiers.d.ts +1 -1
- package/dist/identifiers.d.ts.map +1 -1
- package/dist/identifiers.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/persistanceUtilities.d.ts +1 -1
- package/dist/persistanceUtilities.d.ts.map +1 -1
- package/dist/persistanceUtilities.js.map +1 -1
- package/dist/sessionSpaceNormalizer.d.ts +2 -2
- package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
- package/dist/sessionSpaceNormalizer.js +4 -4
- package/dist/sessionSpaceNormalizer.js.map +1 -1
- package/dist/sessions.d.ts +2 -2
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +12 -12
- package/dist/sessions.js.map +1 -1
- package/dist/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
- package/dist/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
- package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -0
- package/dist/test/appendOnlySortedMap.spec.d.ts +6 -0
- package/dist/test/appendOnlySortedMap.spec.d.ts.map +1 -0
- package/dist/test/appendOnlySortedMap.spec.js.map +1 -0
- package/dist/test/idCompressor.perf.spec.d.ts +6 -0
- package/dist/test/idCompressor.perf.spec.d.ts.map +1 -0
- package/dist/test/idCompressor.perf.spec.js.map +1 -0
- package/dist/test/idCompressor.spec.d.ts +6 -0
- package/dist/test/idCompressor.spec.d.ts.map +1 -0
- package/dist/test/idCompressor.spec.js.map +1 -0
- package/dist/test/idCompressorTestUtilities.d.ts +245 -0
- package/dist/test/idCompressorTestUtilities.d.ts.map +1 -0
- package/dist/test/idCompressorTestUtilities.js +589 -0
- package/dist/test/idCompressorTestUtilities.js.map +1 -0
- package/dist/test/index.d.ts +9 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +13 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/numericUuid.spec.d.ts +6 -0
- package/dist/test/numericUuid.spec.d.ts.map +1 -0
- package/dist/test/numericUuid.spec.js.map +1 -0
- package/dist/test/sessionSpaceNormalizer.spec.d.ts +6 -0
- package/dist/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
- package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -0
- package/dist/test/snapshots/dirname.cjs +16 -0
- package/dist/test/snapshots/dirname.cjs.map +1 -0
- package/dist/test/snapshots/dirname.d.cts +6 -0
- package/dist/test/snapshots/dirname.d.cts.map +1 -0
- package/{lib/types/idCompressor.mjs → dist/test/snapshots/summary.spec.d.ts} +1 -1
- package/dist/test/snapshots/summary.spec.d.ts.map +1 -0
- package/dist/test/snapshots/summary.spec.js.map +1 -0
- package/dist/test/testCommon.d.ts +90 -0
- package/dist/test/testCommon.d.ts.map +1 -0
- package/dist/test/testCommon.js +90 -0
- package/dist/test/testCommon.js.map +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/idCompressor.d.ts +134 -67
- package/dist/types/idCompressor.d.ts.map +1 -1
- package/dist/types/idCompressor.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/persisted-types/0.0.1.d.ts +1 -1
- 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/types/persisted-types/index.d.ts +1 -1
- package/dist/types/persisted-types/index.d.ts.map +1 -1
- package/dist/types/persisted-types/index.js.map +1 -1
- package/dist/utilities.d.ts +2 -2
- package/dist/utilities.d.ts.map +1 -1
- package/dist/utilities.js.map +1 -1
- package/lib/{appendOnlySortedMap.d.mts → appendOnlySortedMap.d.ts} +1 -1
- package/lib/appendOnlySortedMap.d.ts.map +1 -0
- package/lib/{appendOnlySortedMap.mjs → appendOnlySortedMap.js} +3 -1
- package/lib/appendOnlySortedMap.js.map +1 -0
- package/lib/{finalSpace.d.mts → finalSpace.d.ts} +3 -3
- package/lib/finalSpace.d.ts.map +1 -0
- package/lib/{finalSpace.mjs → finalSpace.js} +2 -2
- package/lib/finalSpace.js.map +1 -0
- package/lib/{id-compressor-alpha.d.mts → id-compressor-alpha.d.ts} +117 -112
- package/lib/id-compressor-beta.d.ts +179 -0
- package/lib/id-compressor-public.d.ts +179 -0
- package/lib/{id-compressor-untrimmed.d.mts → id-compressor-untrimmed.d.ts} +117 -112
- package/lib/{idCompressor.d.mts → idCompressor.d.ts} +16 -20
- package/lib/idCompressor.d.ts.map +1 -0
- package/lib/{idCompressor.mjs → idCompressor.js} +54 -41
- package/lib/idCompressor.js.map +1 -0
- package/lib/{identifiers.d.mts → identifiers.d.ts} +2 -2
- package/lib/identifiers.d.ts.map +1 -0
- package/lib/{identifiers.mjs → identifiers.js} +1 -1
- package/lib/identifiers.js.map +1 -0
- package/lib/{index.d.mts → index.d.ts} +7 -4
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
- package/lib/packageVersion.js.map +1 -0
- package/lib/{persistanceUtilities.d.mts → persistanceUtilities.d.ts} +2 -2
- package/lib/persistanceUtilities.d.ts.map +1 -0
- package/lib/{persistanceUtilities.mjs → persistanceUtilities.js} +1 -1
- package/lib/persistanceUtilities.js.map +1 -0
- package/lib/{sessionSpaceNormalizer.d.mts → sessionSpaceNormalizer.d.ts} +3 -3
- package/lib/sessionSpaceNormalizer.d.ts.map +1 -0
- package/lib/{sessionSpaceNormalizer.mjs → sessionSpaceNormalizer.js} +3 -3
- package/lib/sessionSpaceNormalizer.js.map +1 -0
- package/lib/{sessions.d.mts → sessions.d.ts} +3 -3
- package/lib/sessions.d.ts.map +1 -0
- package/lib/{sessions.mjs → sessions.js} +2 -2
- package/lib/sessions.js.map +1 -0
- package/lib/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
- package/lib/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
- package/lib/test/appendOnlySortedMap.perf.spec.js +49 -0
- package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -0
- package/lib/test/appendOnlySortedMap.spec.d.ts +6 -0
- package/lib/test/appendOnlySortedMap.spec.d.ts.map +1 -0
- package/lib/test/appendOnlySortedMap.spec.js +166 -0
- package/lib/test/appendOnlySortedMap.spec.js.map +1 -0
- package/lib/test/idCompressor.perf.spec.d.ts +6 -0
- package/lib/test/idCompressor.perf.spec.d.ts.map +1 -0
- package/lib/test/idCompressor.perf.spec.js +281 -0
- package/lib/test/idCompressor.perf.spec.js.map +1 -0
- package/lib/test/idCompressor.spec.d.ts +6 -0
- package/lib/test/idCompressor.spec.d.ts.map +1 -0
- package/lib/test/idCompressor.spec.js +953 -0
- package/lib/test/idCompressor.spec.js.map +1 -0
- package/lib/test/idCompressorTestUtilities.d.ts +245 -0
- package/lib/test/idCompressorTestUtilities.d.ts.map +1 -0
- package/lib/test/idCompressorTestUtilities.js +576 -0
- package/lib/test/idCompressorTestUtilities.js.map +1 -0
- package/lib/test/index.d.ts +9 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +9 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/numericUuid.spec.d.ts +6 -0
- package/lib/test/numericUuid.spec.d.ts.map +1 -0
- package/lib/test/numericUuid.spec.js +74 -0
- package/lib/test/numericUuid.spec.js.map +1 -0
- package/lib/test/sessionSpaceNormalizer.spec.d.ts +6 -0
- package/lib/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
- package/lib/test/sessionSpaceNormalizer.spec.js +43 -0
- package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -0
- package/lib/test/snapshots/dirname.cjs +16 -0
- package/lib/test/snapshots/dirname.cjs.map +1 -0
- package/lib/test/snapshots/dirname.d.cts +6 -0
- package/lib/test/snapshots/dirname.d.cts.map +1 -0
- package/lib/test/snapshots/summary.spec.d.ts +6 -0
- package/lib/test/snapshots/summary.spec.d.ts.map +1 -0
- package/lib/test/snapshots/summary.spec.js +127 -0
- package/lib/test/snapshots/summary.spec.js.map +1 -0
- package/lib/test/testCommon.d.ts +90 -0
- package/lib/test/testCommon.d.ts.map +1 -0
- package/lib/test/testCommon.js +80 -0
- package/lib/test/testCommon.js.map +1 -0
- package/lib/types/{idCompressor.d.mts → idCompressor.d.ts} +135 -68
- package/lib/types/idCompressor.d.ts.map +1 -0
- package/lib/types/{identifiers.mjs → idCompressor.js} +1 -1
- package/lib/types/idCompressor.js.map +1 -0
- package/lib/types/{identifiers.d.mts → identifiers.d.ts} +1 -1
- package/lib/types/identifiers.d.ts.map +1 -0
- package/lib/types/identifiers.js +6 -0
- package/lib/types/identifiers.js.map +1 -0
- package/lib/types/{index.d.mts → index.d.ts} +4 -4
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/{persisted-types/0.0.1.mjs → index.js} +1 -1
- package/lib/types/index.js.map +1 -0
- package/lib/types/persisted-types/{0.0.1.d.mts → 0.0.1.d.ts} +2 -2
- package/lib/types/persisted-types/0.0.1.d.ts.map +1 -0
- package/lib/types/persisted-types/{index.mjs → 0.0.1.js} +1 -1
- package/lib/types/persisted-types/0.0.1.js.map +1 -0
- package/lib/types/persisted-types/{index.d.mts → index.d.ts} +2 -2
- package/lib/types/persisted-types/index.d.ts.map +1 -0
- package/lib/types/{index.mjs → persisted-types/index.js} +1 -1
- package/lib/types/persisted-types/index.js.map +1 -0
- package/lib/{utilities.d.mts → utilities.d.ts} +3 -3
- package/lib/utilities.d.ts.map +1 -0
- package/lib/{utilities.mjs → utilities.js} +2 -1
- package/lib/utilities.js.map +1 -0
- package/package.json +87 -21
- package/src/finalSpace.ts +2 -2
- package/src/idCompressor.ts +75 -59
- package/src/identifiers.ts +1 -1
- package/src/index.ts +3 -3
- package/src/packageVersion.ts +1 -1
- package/src/persistanceUtilities.ts +1 -1
- package/src/sessionSpaceNormalizer.ts +3 -3
- package/src/sessions.ts +3 -3
- package/src/test/idCompressorTestUtilities.ts +921 -0
- package/src/test/index.ts +10 -0
- package/src/test/snapshots/dirname.cts +13 -0
- package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client +1 -0
- package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client-client2 +1 -0
- package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients +1 -0
- package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients-client2 +1 -0
- package/src/test/snapshots/files/empty-compressor-summary +1 -0
- package/src/test/snapshots/files/expansion-semantics +1 -0
- package/src/test/snapshots/files/expansion-semantics-client2 +1 -0
- package/src/test/testCommon.ts +143 -0
- package/src/test/tsconfig.cjs.json +12 -0
- package/src/test/tsconfig.json +20 -0
- package/src/types/idCompressor.ts +147 -72
- package/src/types/index.ts +8 -3
- package/src/types/persisted-types/0.0.1.ts +1 -1
- package/src/types/persisted-types/index.ts +1 -1
- package/src/utilities.ts +2 -2
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +2 -5
- package/lib/appendOnlySortedMap.d.mts.map +0 -1
- package/lib/appendOnlySortedMap.mjs.map +0 -1
- package/lib/finalSpace.d.mts.map +0 -1
- package/lib/finalSpace.mjs.map +0 -1
- package/lib/id-compressor-beta.d.mts +0 -172
- package/lib/id-compressor-public.d.mts +0 -172
- package/lib/idCompressor.d.mts.map +0 -1
- package/lib/idCompressor.mjs.map +0 -1
- package/lib/identifiers.d.mts.map +0 -1
- package/lib/identifiers.mjs.map +0 -1
- package/lib/index.d.mts.map +0 -1
- package/lib/index.mjs +0 -7
- package/lib/index.mjs.map +0 -1
- package/lib/packageVersion.d.mts.map +0 -1
- package/lib/packageVersion.mjs.map +0 -1
- package/lib/persistanceUtilities.d.mts.map +0 -1
- package/lib/persistanceUtilities.mjs.map +0 -1
- package/lib/sessionSpaceNormalizer.d.mts.map +0 -1
- package/lib/sessionSpaceNormalizer.mjs.map +0 -1
- package/lib/sessions.d.mts.map +0 -1
- package/lib/sessions.mjs.map +0 -1
- package/lib/types/idCompressor.d.mts.map +0 -1
- package/lib/types/idCompressor.mjs.map +0 -1
- package/lib/types/identifiers.d.mts.map +0 -1
- package/lib/types/identifiers.mjs.map +0 -1
- package/lib/types/index.d.mts.map +0 -1
- package/lib/types/index.mjs.map +0 -1
- package/lib/types/persisted-types/0.0.1.d.mts.map +0 -1
- package/lib/types/persisted-types/0.0.1.mjs.map +0 -1
- package/lib/types/persisted-types/index.d.mts.map +0 -1
- package/lib/types/persisted-types/index.mjs.map +0 -1
- package/lib/utilities.d.mts.map +0 -1
- package/lib/utilities.mjs.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
2
|
+
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
2
3
|
|
|
3
4
|
/* Excluded from this release type: assertIsStableId */
|
|
4
5
|
|
|
@@ -10,112 +11,118 @@ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
|
10
11
|
|
|
11
12
|
/* Excluded from this release type: generateStableId */
|
|
12
13
|
|
|
13
|
-
/* Excluded from this release type: IdCompressor */
|
|
14
|
-
|
|
15
14
|
/* Excluded from this release type: IdCreationRange */
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* A distributed UUID generator and compressor.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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.
|
|
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
|
+
* ```
|
|
77
67
|
* @public
|
|
78
68
|
*/
|
|
79
69
|
export declare interface IIdCompressor {
|
|
70
|
+
/**
|
|
71
|
+
* The local session ID.
|
|
72
|
+
*/
|
|
80
73
|
localSessionId: SessionId;
|
|
81
74
|
/**
|
|
82
|
-
* Generates a new compressed ID
|
|
83
|
-
*
|
|
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.
|
|
84
77
|
* @returns A new local ID in session space.
|
|
85
78
|
*/
|
|
86
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;
|
|
87
91
|
/**
|
|
88
92
|
* Normalizes a session space ID into op space.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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.
|
|
91
97
|
*/
|
|
92
98
|
normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
|
|
93
99
|
/**
|
|
94
100
|
* Normalizes an ID into session space.
|
|
95
|
-
* @param id -
|
|
96
|
-
* to
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* range that contained it from the server.
|
|
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`.
|
|
101
106
|
*/
|
|
102
107
|
normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
|
|
103
108
|
/**
|
|
104
109
|
* Decompresses a previously compressed ID into a UUID.
|
|
105
|
-
* @param id -
|
|
106
|
-
* @returns
|
|
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.
|
|
107
113
|
*/
|
|
108
114
|
decompress(id: SessionSpaceCompressedId): StableId;
|
|
109
115
|
/**
|
|
110
116
|
* Recompresses a UUID.
|
|
111
|
-
* @param uncompressed -
|
|
112
|
-
* @returns
|
|
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.
|
|
113
120
|
*/
|
|
114
121
|
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
115
122
|
/**
|
|
116
|
-
* Attempts to
|
|
117
|
-
* @param uncompressed -
|
|
118
|
-
* @returns
|
|
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.
|
|
119
126
|
*/
|
|
120
127
|
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
121
128
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
2
|
+
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
2
3
|
|
|
3
4
|
/* Excluded from this release type: assertIsStableId */
|
|
4
5
|
|
|
@@ -10,112 +11,118 @@ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
|
10
11
|
|
|
11
12
|
/* Excluded from this release type: generateStableId */
|
|
12
13
|
|
|
13
|
-
/* Excluded from this release type: IdCompressor */
|
|
14
|
-
|
|
15
14
|
/* Excluded from this release type: IdCreationRange */
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* A distributed UUID generator and compressor.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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.
|
|
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
|
+
* ```
|
|
77
67
|
* @public
|
|
78
68
|
*/
|
|
79
69
|
export declare interface IIdCompressor {
|
|
70
|
+
/**
|
|
71
|
+
* The local session ID.
|
|
72
|
+
*/
|
|
80
73
|
localSessionId: SessionId;
|
|
81
74
|
/**
|
|
82
|
-
* Generates a new compressed ID
|
|
83
|
-
*
|
|
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.
|
|
84
77
|
* @returns A new local ID in session space.
|
|
85
78
|
*/
|
|
86
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;
|
|
87
91
|
/**
|
|
88
92
|
* Normalizes a session space ID into op space.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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.
|
|
91
97
|
*/
|
|
92
98
|
normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
|
|
93
99
|
/**
|
|
94
100
|
* Normalizes an ID into session space.
|
|
95
|
-
* @param id -
|
|
96
|
-
* to
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* range that contained it from the server.
|
|
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`.
|
|
101
106
|
*/
|
|
102
107
|
normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
|
|
103
108
|
/**
|
|
104
109
|
* Decompresses a previously compressed ID into a UUID.
|
|
105
|
-
* @param id -
|
|
106
|
-
* @returns
|
|
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.
|
|
107
113
|
*/
|
|
108
114
|
decompress(id: SessionSpaceCompressedId): StableId;
|
|
109
115
|
/**
|
|
110
116
|
* Recompresses a UUID.
|
|
111
|
-
* @param uncompressed -
|
|
112
|
-
* @returns
|
|
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.
|
|
113
120
|
*/
|
|
114
121
|
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
115
122
|
/**
|
|
116
|
-
* Attempts to
|
|
117
|
-
* @param uncompressed -
|
|
118
|
-
* @returns
|
|
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.
|
|
119
126
|
*/
|
|
120
127
|
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
121
128
|
}
|