@fluidframework/runtime-definitions 2.0.0-internal.6.1.0 → 2.0.0-internal.6.2.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/CHANGELOG.md +31 -0
- package/README.md +4 -3
- package/dist/dataStoreContext.d.ts +1 -2
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/id-compressor/idCompressor.d.ts +32 -50
- package/dist/id-compressor/idCompressor.d.ts.map +1 -1
- package/dist/id-compressor/idCompressor.js.map +1 -1
- package/dist/id-compressor/identifiers.d.ts +10 -51
- package/dist/id-compressor/identifiers.d.ts.map +1 -1
- package/dist/id-compressor/identifiers.js.map +1 -1
- package/dist/id-compressor/index.d.ts +2 -2
- package/dist/id-compressor/index.d.ts.map +1 -1
- package/dist/id-compressor/index.js +3 -0
- package/dist/id-compressor/index.js.map +1 -1
- package/dist/id-compressor/persisted-types/0.0.1.d.ts +18 -136
- package/dist/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
- package/dist/id-compressor/persisted-types/0.0.1.js +6 -0
- package/dist/id-compressor/persisted-types/0.0.1.js.map +1 -1
- package/dist/id-compressor/persisted-types/index.d.ts +1 -1
- package/dist/id-compressor/persisted-types/index.d.ts.map +1 -1
- package/dist/id-compressor/persisted-types/index.js +3 -0
- package/dist/id-compressor/persisted-types/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +126 -10
- package/src/dataStoreContext.ts +2 -1
- package/src/id-compressor/idCompressor.ts +32 -59
- package/src/id-compressor/identifiers.ts +10 -58
- package/src/id-compressor/index.ts +2 -19
- package/src/id-compressor/persisted-types/0.0.1.ts +18 -159
- package/src/id-compressor/persisted-types/index.ts +1 -8
- package/src/index.ts +1 -13
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
SessionSpaceCompressedId,
|
|
8
|
-
OpSpaceCompressedId,
|
|
9
|
-
SessionId,
|
|
10
|
-
FinalCompressedId,
|
|
11
|
-
StableId,
|
|
12
|
-
} from "./identifiers";
|
|
6
|
+
import { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers";
|
|
13
7
|
import {
|
|
14
8
|
IdCreationRange,
|
|
15
9
|
SerializedIdCompressorWithNoSession,
|
|
@@ -17,7 +11,13 @@ import {
|
|
|
17
11
|
} from "./persisted-types";
|
|
18
12
|
|
|
19
13
|
export interface IIdCompressorCore {
|
|
20
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Returns a range of IDs created by this session in a format for sending to the server for finalizing.
|
|
16
|
+
* The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.
|
|
17
|
+
* @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before
|
|
18
|
+
* it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
|
|
19
|
+
*/
|
|
20
|
+
takeNextCreationRange(): IdCreationRange;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Finalizes the supplied range of IDs (which may be from either a remote or local session).
|
|
@@ -25,14 +25,6 @@ export interface IIdCompressorCore {
|
|
|
25
25
|
*/
|
|
26
26
|
finalizeCreationRange(range: IdCreationRange): void;
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* Returns a range of local IDs created by this session in a format for sending to the server for finalizing.
|
|
30
|
-
* The range will include all local IDs generated via calls to `generateCompressedId` since the last time this method was called.
|
|
31
|
-
* @returns the range of session-local IDs, which may be empty. This range must be sent to the server for ordering before
|
|
32
|
-
* it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
|
|
33
|
-
*/
|
|
34
|
-
takeNextCreationRange(): IdCreationRange;
|
|
35
|
-
|
|
36
28
|
/**
|
|
37
29
|
* Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
|
|
38
30
|
* This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
|
|
@@ -58,38 +50,35 @@ export interface IIdCompressorCore {
|
|
|
58
50
|
*
|
|
59
51
|
* For each stable ID created, two numeric IDs are provided by the compressor:
|
|
60
52
|
*
|
|
61
|
-
* 1. A local ID, which is stable for the lifetime of the session (which could be longer than that of the compressor object, as it may
|
|
62
|
-
* be serialized for offline usage). Available as soon as the stable ID is allocated.
|
|
63
|
-
*
|
|
53
|
+
* 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
|
|
54
|
+
* be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
|
|
55
|
+
* safely usable within the scope of the compressor that created it.
|
|
64
56
|
*
|
|
65
57
|
* 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
|
|
66
|
-
* the corresponding local ID is totally ordered (via consensus) with respect to other sessions' allocations.
|
|
58
|
+
* the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
|
|
67
59
|
* Final IDs are known to and publicly usable by any compressor that has received them.
|
|
68
60
|
*
|
|
69
61
|
* Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
|
|
70
62
|
* to map the UUIDs to the numbers.
|
|
71
63
|
*
|
|
72
|
-
* A client may optionally supply an "override" for any generated ID, associating an arbitrary string with the local/final ID rather than
|
|
73
|
-
* the UUID that would otherwise be created.
|
|
74
|
-
*
|
|
75
64
|
* The following invariants are upheld by IdCompressor:
|
|
76
65
|
*
|
|
77
|
-
* 1.
|
|
66
|
+
* 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
|
|
78
67
|
*
|
|
79
|
-
* 2. Final IDs will always decompress to the same UUIDs
|
|
68
|
+
* 2. Final IDs will always decompress to the same UUIDs.
|
|
80
69
|
*
|
|
81
|
-
* 3. After a server-processed range of local IDs (from any session) is received by a compressor, any of those local IDs may be
|
|
82
|
-
* translated by the compressor into the corresponding final ID. For any given local ID, this translation will always yield the
|
|
70
|
+
* 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
|
|
71
|
+
* translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
|
|
83
72
|
* same final ID.
|
|
84
73
|
*
|
|
85
|
-
* 4. A UUID
|
|
74
|
+
* 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
|
|
86
75
|
*
|
|
87
|
-
*
|
|
76
|
+
* Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
|
|
88
77
|
* be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
|
|
89
78
|
*
|
|
90
79
|
* Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
|
|
91
|
-
* could make reasoning about equality of those two forms
|
|
92
|
-
* local ID but is later queried using the final ID (which is semantically equal, as it decompresses to the same UUID/string) it will
|
|
80
|
+
* could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
|
|
81
|
+
* 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
|
|
93
82
|
* produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
|
|
94
83
|
* session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
|
|
95
84
|
*
|
|
@@ -102,7 +91,7 @@ export interface IIdCompressorCore {
|
|
|
102
91
|
* 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
|
|
103
92
|
* 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
|
|
104
93
|
* 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
|
|
105
|
-
* out of Op space over time, namely, when a local ID in this space becomes finalized, and thereafter has a "more final form".
|
|
94
|
+
* out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
|
|
106
95
|
* Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
|
|
107
96
|
* 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
|
|
108
97
|
* "local as possible".
|
|
@@ -117,11 +106,9 @@ export interface IIdCompressor {
|
|
|
117
106
|
/**
|
|
118
107
|
* Generates a new compressed ID or returns an existing one.
|
|
119
108
|
* This should ONLY be called to generate IDs for local operations.
|
|
120
|
-
* @
|
|
121
|
-
* Performance note: assigning override strings incurs a performance overhead.
|
|
122
|
-
* @returns an existing ID if one already exists for `override`, and a new local ID otherwise. The returned ID is in session space.
|
|
109
|
+
* @returns A new local ID in session space.
|
|
123
110
|
*/
|
|
124
|
-
generateCompressedId(
|
|
111
|
+
generateCompressedId(): SessionSpaceCompressedId;
|
|
125
112
|
/**
|
|
126
113
|
* Normalizes a session space ID into op space.
|
|
127
114
|
* @param id - the local ID to normalize.
|
|
@@ -143,37 +130,23 @@ export interface IIdCompressor {
|
|
|
143
130
|
): SessionSpaceCompressedId;
|
|
144
131
|
|
|
145
132
|
/**
|
|
146
|
-
*
|
|
147
|
-
* @param id - the final ID to normalize.
|
|
148
|
-
* @returns the session-space ID corresponding to `id`.
|
|
149
|
-
*/
|
|
150
|
-
normalizeToSessionSpace(id: FinalCompressedId): SessionSpaceCompressedId;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Decompresses a previously compressed ID into a UUID or override string.
|
|
154
|
-
* @param id - the compressed ID to be decompressed.
|
|
155
|
-
* @returns the UUID or override string associated with the compressed ID. Fails if the ID was not generated by this compressor.
|
|
156
|
-
*/
|
|
157
|
-
decompress(id: SessionSpaceCompressedId | FinalCompressedId): StableId | string;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Attempts to decompress a previously compressed ID into a UUID or override string.
|
|
133
|
+
* Decompresses a previously compressed ID into a UUID.
|
|
161
134
|
* @param id - the compressed ID to be decompressed.
|
|
162
|
-
* @returns the UUID
|
|
135
|
+
* @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
|
|
163
136
|
*/
|
|
164
|
-
|
|
137
|
+
decompress(id: SessionSpaceCompressedId): StableId;
|
|
165
138
|
|
|
166
139
|
/**
|
|
167
|
-
* Recompresses a
|
|
168
|
-
* @param uncompressed - the UUID
|
|
140
|
+
* Recompresses a UUID.
|
|
141
|
+
* @param uncompressed - the UUID to recompress.
|
|
169
142
|
* @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
|
|
170
143
|
*/
|
|
171
|
-
recompress(uncompressed:
|
|
144
|
+
recompress(uncompressed: StableId): SessionSpaceCompressedId;
|
|
172
145
|
|
|
173
146
|
/**
|
|
174
|
-
* Attempts to recompresses a
|
|
175
|
-
* @param uncompressed - the UUID
|
|
147
|
+
* Attempts to recompresses a UUID.
|
|
148
|
+
* @param uncompressed - the UUID to recompress,
|
|
176
149
|
* @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
|
|
177
150
|
*/
|
|
178
|
-
tryRecompress(uncompressed:
|
|
151
|
+
tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
|
|
179
152
|
}
|
|
@@ -3,79 +3,31 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* An identifier (UUID) that has been shortened by a distributed compression algorithm.
|
|
8
|
-
* @alpha
|
|
9
|
-
*/
|
|
10
|
-
export type CompressedId = FinalCompressedId | LocalCompressedId;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A brand for identity types that are unique within a particular session (SharedTree instance).
|
|
14
|
-
*/
|
|
15
|
-
export interface SessionUnique {
|
|
16
|
-
readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
6
|
/**
|
|
20
7
|
* A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
|
|
21
|
-
* Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
|
|
22
|
-
* compressor that produced them.
|
|
23
|
-
* @alpha
|
|
8
|
+
* Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
|
|
9
|
+
* the scope of the session (i.e. compressor) that produced them.
|
|
24
10
|
*/
|
|
25
|
-
export type SessionSpaceCompressedId =
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A compressed ID that has been normalized into "op space" (see `IdCompressor` for more).
|
|
29
|
-
* Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require no normalizing when
|
|
30
|
-
* received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
|
|
31
|
-
*/
|
|
32
|
-
export type OpSpaceCompressedId = CompressedId & {
|
|
33
|
-
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
11
|
+
export type SessionSpaceCompressedId = number & {
|
|
12
|
+
readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
|
|
34
13
|
};
|
|
35
14
|
|
|
36
15
|
/**
|
|
37
|
-
* A compressed ID that
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @alpha
|
|
16
|
+
* A compressed ID that has been normalized into "op space".
|
|
17
|
+
* Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
|
|
18
|
+
* received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
|
|
41
19
|
*/
|
|
42
|
-
export type
|
|
43
|
-
readonly FinalCompressedId: "5d83d1e2-98b7-4e4e-a889-54c855cfa73d";
|
|
44
|
-
|
|
45
|
-
// Same brand as OpNormalizedCompressedId, as final IDs are always finally normalized
|
|
20
|
+
export type OpSpaceCompressedId = number & {
|
|
46
21
|
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
47
22
|
};
|
|
48
23
|
|
|
49
24
|
/**
|
|
50
|
-
* A
|
|
51
|
-
* It should not be persisted outside of the history as it can only be decompressed in the context of the originating session.
|
|
52
|
-
* If external persistence is needed (e.g. by a client), a StableId should be used instead.
|
|
53
|
-
* @alpha
|
|
54
|
-
*/
|
|
55
|
-
export type LocalCompressedId = number & {
|
|
56
|
-
readonly LocalCompressedId: "6fccb42f-e2a4-4243-bd29-f13d12b9c6d1";
|
|
57
|
-
} & SessionUnique; // Same brand as CompressedId, as local IDs are always locally normalized
|
|
58
|
-
|
|
59
|
-
export interface NodeIdBrand {
|
|
60
|
-
readonly NodeId: "e53e7d6b-c8b9-431a-8805-4843fc639342";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Type-safe identifiers for specific use cases.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
25
|
+
* A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
|
|
68
26
|
* A 128-bit Universally Unique IDentifier. Represented here
|
|
69
27
|
* with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
|
|
70
28
|
* where x is a lowercase hex digit.
|
|
71
|
-
* @public
|
|
72
|
-
*/
|
|
73
|
-
export type UuidString = string & { readonly UuidString: "9d40d0ae-90d9-44b1-9482-9f55d59d5465" };
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* A version 4, variant 2 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
|
|
77
29
|
*/
|
|
78
|
-
export type StableId =
|
|
30
|
+
export type StableId = string & { readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a" };
|
|
79
31
|
|
|
80
32
|
/**
|
|
81
33
|
* A StableId which is suitable for use as a session identifier
|
|
@@ -5,30 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
7
|
IdCreationRange,
|
|
8
|
-
SerializedCluster,
|
|
9
|
-
SerializedClusterOverrides,
|
|
10
8
|
SerializedIdCompressor,
|
|
11
9
|
SerializedIdCompressorWithNoSession,
|
|
12
10
|
SerializedIdCompressorWithOngoingSession,
|
|
13
|
-
SerializedLocalOverrides,
|
|
14
|
-
SerializedLocalState,
|
|
15
|
-
SerializedSessionData,
|
|
16
|
-
SerializedSessionIdNormalizer,
|
|
17
|
-
UnackedLocalId,
|
|
18
|
-
VersionedSerializedIdCompressor,
|
|
19
11
|
IdCreationRangeWithStashedState,
|
|
12
|
+
initialClusterCapacity,
|
|
20
13
|
} from "./persisted-types";
|
|
21
14
|
|
|
22
15
|
export { IIdCompressorCore, IIdCompressor } from "./idCompressor";
|
|
23
16
|
|
|
24
|
-
export {
|
|
25
|
-
SessionSpaceCompressedId,
|
|
26
|
-
OpSpaceCompressedId,
|
|
27
|
-
SessionId,
|
|
28
|
-
FinalCompressedId,
|
|
29
|
-
StableId,
|
|
30
|
-
UuidString,
|
|
31
|
-
CompressedId,
|
|
32
|
-
SessionUnique,
|
|
33
|
-
LocalCompressedId,
|
|
34
|
-
} from "./identifiers";
|
|
17
|
+
export { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers";
|
|
@@ -3,188 +3,47 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
FinalCompressedId,
|
|
8
|
-
LocalCompressedId,
|
|
9
|
-
OpSpaceCompressedId,
|
|
10
|
-
SessionId,
|
|
11
|
-
} from "../identifiers";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A serialized ID allocation session for an `IdCompressor`.
|
|
15
|
-
*/
|
|
16
|
-
export type SerializedSessionData = readonly [
|
|
17
|
-
/**
|
|
18
|
-
* The ID of the session.
|
|
19
|
-
*/
|
|
20
|
-
sessionId: SessionId,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export type SerializedClusterOverrides = readonly [
|
|
24
|
-
/** The overridden final ID, represented as an index into the cluster's ID range */
|
|
25
|
-
overriddenFinalIndex: number, // A cluster with base UUID '...beef' and an `overriddenFinalIndex` of 3 would correspond to '...bef2'
|
|
26
|
-
/** The override string */
|
|
27
|
-
override: string,
|
|
28
|
-
/** The first ID that was finalized and associated with this override, set only if different than the `overriddenFinalIndex` */
|
|
29
|
-
overriddenId?: FinalCompressedId,
|
|
30
|
-
][];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A serialized final ID cluster.
|
|
34
|
-
*/
|
|
35
|
-
export type SerializedCluster = readonly [
|
|
36
|
-
/**
|
|
37
|
-
* Index into the serialized sessions array. Can be converted into a baseUuid via its order in `clusters`.
|
|
38
|
-
* If negative, then this cluster was created by the local session.
|
|
39
|
-
*/
|
|
40
|
-
sessionIndex: number,
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The capacity of the cluster.
|
|
44
|
-
*/
|
|
45
|
-
capacity: number,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The number of IDs in the cluster. Omitted if count === capacity.
|
|
49
|
-
* --OR--
|
|
50
|
-
* The overrides in this cluster. Omitted if no overrides exist in the cluster.
|
|
51
|
-
*/
|
|
52
|
-
countOrOverrides?: number | SerializedClusterOverrides,
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Overrides in this cluster. Omitted if no overrides exist in the cluster.
|
|
56
|
-
*/
|
|
57
|
-
overrides?: SerializedClusterOverrides,
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
export type SerializedLocalOverrides = readonly (readonly [LocalCompressedId, string])[];
|
|
61
|
-
|
|
62
|
-
export interface SerializedLocalState {
|
|
63
|
-
/**
|
|
64
|
-
* The total number of local IDs created by this session
|
|
65
|
-
*/
|
|
66
|
-
readonly localIdCount: number;
|
|
67
|
-
/**
|
|
68
|
-
* Overrides generated by this session. Omitted if no local overrides exist in the session.
|
|
69
|
-
*/
|
|
70
|
-
readonly overrides?: SerializedLocalOverrides;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The most recent local ID in a range returned by `takeNextCreationRange`.
|
|
74
|
-
*/
|
|
75
|
-
readonly lastTakenLocalId: LocalCompressedId | undefined;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Serialized table for normalizing IDs made by the local session.
|
|
79
|
-
*/
|
|
80
|
-
readonly sessionNormalizer: SerializedSessionIdNormalizer;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Serialized table for normalizing IDs made by the local session.
|
|
85
|
-
*/
|
|
86
|
-
export interface SerializedSessionIdNormalizer {
|
|
87
|
-
readonly nextLocalId: LocalCompressedId;
|
|
88
|
-
readonly localRanges: readonly (readonly [
|
|
89
|
-
firstLocal: LocalCompressedId,
|
|
90
|
-
lastLocal: LocalCompressedId,
|
|
91
|
-
finalRanges?: readonly (readonly [
|
|
92
|
-
alignedLocal: LocalCompressedId,
|
|
93
|
-
firstFinal: FinalCompressedId,
|
|
94
|
-
lastFinal: FinalCompressedId,
|
|
95
|
-
])[],
|
|
96
|
-
])[];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The minimal required contents of a serialized IdCompressor.
|
|
101
|
-
*/
|
|
102
|
-
export interface VersionedSerializedIdCompressor {
|
|
103
|
-
readonly _versionedSerializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
|
|
104
|
-
readonly version: string;
|
|
105
|
-
}
|
|
6
|
+
import type { SessionId } from "../identifiers";
|
|
106
7
|
|
|
107
8
|
/**
|
|
108
9
|
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
109
10
|
*/
|
|
110
|
-
export
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/** All sessions except the local session. */
|
|
114
|
-
readonly sessions: readonly SerializedSessionData[];
|
|
115
|
-
/** All clusters in the compressor in the order they were created. */
|
|
116
|
-
readonly clusters: readonly SerializedCluster[];
|
|
117
|
-
}
|
|
11
|
+
export type SerializedIdCompressor = string & {
|
|
12
|
+
readonly _serializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
|
|
13
|
+
};
|
|
118
14
|
|
|
119
15
|
/**
|
|
120
16
|
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
121
17
|
*/
|
|
122
|
-
export
|
|
18
|
+
export type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {
|
|
123
19
|
readonly _noLocalState: "3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb";
|
|
124
|
-
}
|
|
20
|
+
};
|
|
125
21
|
|
|
126
22
|
/**
|
|
127
23
|
* The serialized contents of an IdCompressor, suitable for persistence in a summary.
|
|
128
24
|
*/
|
|
129
|
-
export
|
|
25
|
+
export type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {
|
|
130
26
|
readonly _hasLocalState: "1281acae-6d14-47e7-bc92-71c8ee0819cb";
|
|
131
|
-
|
|
132
|
-
readonly localSessionIndex: number;
|
|
133
|
-
/** This is only present if the local session made any IDs. */
|
|
134
|
-
readonly localState?: SerializedLocalState;
|
|
135
|
-
}
|
|
27
|
+
};
|
|
136
28
|
|
|
137
29
|
/**
|
|
138
30
|
* Data describing a range of session-local IDs (from a remote or local session).
|
|
139
31
|
*
|
|
140
|
-
* A range is composed of local IDs that were generated.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* Suppose an IdCompressor generated a sequence of local IDs as follows:
|
|
144
|
-
* ```
|
|
145
|
-
* compressor.generateLocalId()
|
|
146
|
-
* compressor.generateLocalId('0093cf29-9454-4034-8940-33b1077b41c3')
|
|
147
|
-
* compressor.generateLocalId()
|
|
148
|
-
* compressor.generateLocalId('0ed545f8-e97e-4dc1-acf9-c4a783258bdf')
|
|
149
|
-
* compressor.generateLocalId()
|
|
150
|
-
* compressor.generateLocalId()
|
|
151
|
-
* compressor.takeNextCreationRange()
|
|
152
|
-
* ```
|
|
153
|
-
* This would result in the following range:
|
|
154
|
-
* ```
|
|
155
|
-
* {
|
|
156
|
-
* first: localId1,
|
|
157
|
-
* last: localId6,
|
|
158
|
-
* overrides: [[localId2, '0093cf29-9454-4034-8940-33b1077b41c3'], [localId4, '0ed545f8-e97e-4dc1-acf9-c4a783258bdf']]
|
|
159
|
-
* }
|
|
160
|
-
* ```
|
|
32
|
+
* A range is composed of local IDs that were generated.
|
|
161
33
|
*/
|
|
162
34
|
export interface IdCreationRange {
|
|
163
35
|
readonly sessionId: SessionId;
|
|
164
|
-
readonly ids?:
|
|
36
|
+
readonly ids?: {
|
|
37
|
+
readonly firstGenCount: number;
|
|
38
|
+
readonly count: number;
|
|
39
|
+
};
|
|
165
40
|
}
|
|
166
41
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
| {
|
|
173
|
-
readonly first: UnackedLocalId;
|
|
174
|
-
readonly last: UnackedLocalId;
|
|
175
|
-
}
|
|
176
|
-
| ({
|
|
177
|
-
readonly first?: UnackedLocalId;
|
|
178
|
-
readonly last?: UnackedLocalId;
|
|
179
|
-
} & HasOverrides);
|
|
180
|
-
|
|
181
|
-
export interface HasOverrides {
|
|
182
|
-
readonly overrides: Overrides;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export type Override = readonly [id: UnackedLocalId, override: string];
|
|
186
|
-
export type Overrides = readonly [Override, ...Override[]];
|
|
187
|
-
}
|
|
42
|
+
/**
|
|
43
|
+
* Roughly equates to a minimum of 1M sessions before we start allocating 64 bit IDs.
|
|
44
|
+
* This value must *NOT* change without careful consideration to compatibility.
|
|
45
|
+
*/
|
|
46
|
+
export const initialClusterCapacity = 512;
|
|
188
47
|
|
|
189
48
|
export type IdCreationRangeWithStashedState = IdCreationRange & {
|
|
190
49
|
stashedState: SerializedIdCompressorWithOngoingSession;
|
|
@@ -5,16 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
7
|
IdCreationRange,
|
|
8
|
-
SerializedCluster,
|
|
9
|
-
SerializedClusterOverrides,
|
|
10
8
|
SerializedIdCompressor,
|
|
11
9
|
SerializedIdCompressorWithNoSession,
|
|
12
10
|
SerializedIdCompressorWithOngoingSession,
|
|
13
|
-
SerializedLocalOverrides,
|
|
14
|
-
SerializedLocalState,
|
|
15
|
-
SerializedSessionData,
|
|
16
|
-
SerializedSessionIdNormalizer,
|
|
17
|
-
UnackedLocalId,
|
|
18
|
-
VersionedSerializedIdCompressor,
|
|
19
11
|
IdCreationRangeWithStashedState,
|
|
12
|
+
initialClusterCapacity,
|
|
20
13
|
} from "./0.0.1";
|
package/src/index.ts
CHANGED
|
@@ -74,20 +74,8 @@ export {
|
|
|
74
74
|
SessionSpaceCompressedId,
|
|
75
75
|
OpSpaceCompressedId,
|
|
76
76
|
SessionId,
|
|
77
|
-
FinalCompressedId,
|
|
78
77
|
StableId,
|
|
79
|
-
UuidString,
|
|
80
|
-
CompressedId,
|
|
81
|
-
SessionUnique,
|
|
82
|
-
LocalCompressedId,
|
|
83
78
|
IdCreationRange,
|
|
84
|
-
VersionedSerializedIdCompressor,
|
|
85
|
-
SerializedCluster,
|
|
86
|
-
SerializedSessionData,
|
|
87
|
-
SerializedLocalState,
|
|
88
|
-
SerializedClusterOverrides,
|
|
89
|
-
SerializedLocalOverrides,
|
|
90
|
-
SerializedSessionIdNormalizer,
|
|
91
|
-
UnackedLocalId,
|
|
92
79
|
IdCreationRangeWithStashedState,
|
|
80
|
+
initialClusterCapacity,
|
|
93
81
|
} from "./id-compressor";
|