@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,139 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers";
6
+ import { IdCreationRange, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession } from "./persisted-types";
7
+ /**
8
+ * @alpha
9
+ */
10
+ export interface IIdCompressorCore {
11
+ /**
12
+ * Returns a range of IDs created by this session in a format for sending to the server for finalizing.
13
+ * The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.
14
+ * @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before
15
+ * it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
16
+ */
17
+ takeNextCreationRange(): IdCreationRange;
18
+ /**
19
+ * Finalizes the supplied range of IDs (which may be from either a remote or local session).
20
+ * @param range - the range of session-local IDs to finalize.
21
+ */
22
+ finalizeCreationRange(range: IdCreationRange): void;
23
+ /**
24
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
25
+ * This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
26
+ */
27
+ serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
28
+ /**
29
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
30
+ * This only includes finalized state and is therefore suitable for use in summaries.
31
+ */
32
+ serialize(withSession: false): SerializedIdCompressorWithNoSession;
33
+ }
34
+ /**
35
+ * A distributed UUID generator and compressor.
36
+ *
37
+ * Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple "sessions" (which can be distributed across the network),
38
+ * providing each session with the ability to map these UUIDs to `numbers`.
39
+ *
40
+ * A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API
41
+ * which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is
42
+ * created it is said to be created by the compressor's "local" session.
43
+ *
44
+ * For each stable ID created, two numeric IDs are provided by the compressor:
45
+ *
46
+ * 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
47
+ * be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only
48
+ * safely usable within the scope of the compressor that created it.
49
+ *
50
+ * 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing
51
+ * the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.
52
+ * Final IDs are known to and publicly usable by any compressor that has received them.
53
+ *
54
+ * Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed
55
+ * to map the UUIDs to the numbers.
56
+ *
57
+ * The following invariants are upheld by IdCompressor:
58
+ *
59
+ * 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.
60
+ *
61
+ * 2. Final IDs will always decompress to the same UUIDs.
62
+ *
63
+ * 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
64
+ * translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the
65
+ * same final ID.
66
+ *
67
+ * 4. A UUID will always compress into the same session-local ID for the lifetime of the session.
68
+ *
69
+ * Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*
70
+ * be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.
71
+ *
72
+ * Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This
73
+ * could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a
74
+ * 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
75
+ * produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the
76
+ * session-local IDs have been finalized, the compressor defines two "spaces" of IDs:
77
+ *
78
+ * 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
79
+ * will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after
80
+ * 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
81
+ * 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
82
+ * these IDs across compressor objects, as the local IDs are specific to the compressor that created them.
83
+ *
84
+ * 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
85
+ * 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
86
+ * 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
87
+ * out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a "more final form".
88
+ * Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially
89
+ * 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
90
+ * "local as possible".
91
+ *
92
+ * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
93
+ * should use op-space IDs.
94
+ * @public
95
+ */
96
+ export interface IIdCompressor {
97
+ localSessionId: SessionId;
98
+ /**
99
+ * Generates a new compressed ID or returns an existing one.
100
+ * This should ONLY be called to generate IDs for local operations.
101
+ * @returns A new local ID in session space.
102
+ */
103
+ generateCompressedId(): SessionSpaceCompressedId;
104
+ /**
105
+ * Normalizes a session space ID into op space.
106
+ * @param id - the local ID to normalize.
107
+ * @returns the ID in op space.
108
+ */
109
+ normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
110
+ /**
111
+ * Normalizes an ID into session space.
112
+ * @param id - the ID to normalize. If it is a local ID, it is assumed to have been created by the session corresponding
113
+ * to `sessionId`.
114
+ * @param originSessionId - the session from which `id` originated
115
+ * @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
116
+ * 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
117
+ * range that contained it from the server.
118
+ */
119
+ normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
120
+ /**
121
+ * Decompresses a previously compressed ID into a UUID.
122
+ * @param id - the compressed ID to be decompressed.
123
+ * @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
124
+ */
125
+ decompress(id: SessionSpaceCompressedId): StableId;
126
+ /**
127
+ * Recompresses a UUID.
128
+ * @param uncompressed - the UUID to recompress.
129
+ * @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
130
+ */
131
+ recompress(uncompressed: StableId): SessionSpaceCompressedId;
132
+ /**
133
+ * Attempts to recompresses a UUID.
134
+ * @param uncompressed - the UUID to recompress,
135
+ * @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
136
+ */
137
+ tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
138
+ }
139
+ //# sourceMappingURL=idCompressor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.d.ts","sourceRoot":"","sources":["../../src/types/idCompressor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EACN,eAAe,EACf,mCAAmC,EACnC,wCAAwC,EACxC,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;;;OAKG;IACH,qBAAqB,IAAI,eAAe,CAAC;IAEzC;;;OAGG;IACH,qBAAqB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAEpD;;;OAGG;IACH,SAAS,CAAC,WAAW,EAAE,IAAI,GAAG,wCAAwC,CAAC;IAEvE;;;OAGG;IACH,SAAS,CAAC,WAAW,EAAE,KAAK,GAAG,mCAAmC,CAAC;CACnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,SAAS,CAAC;IAE1B;;;;OAIG;IACH,oBAAoB,IAAI,wBAAwB,CAAC;IACjD;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,EAAE,wBAAwB,GAAG,mBAAmB,CAAC;IACtE;;;;;;;;OAQG;IACH,uBAAuB,CACtB,EAAE,EAAE,mBAAmB,EACvB,eAAe,EAAE,SAAS,GACxB,wBAAwB,CAAC;IAE5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,wBAAwB,GAAG,QAAQ,CAAC;IAEnD;;;;OAIG;IACH,UAAU,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB,CAAC;IAE7D;;;;OAIG;IACH,aAAa,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB,GAAG,SAAS,CAAC;CAC5E"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=identifiers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifiers.cjs","sourceRoot":"","sources":["../../src/types/identifiers.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A compressed ID that has been normalized into \"session space\" (see `IdCompressor` for more).\n * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to\n * the scope of the session (i.e. compressor) that produced them.\n * @public\n */\nexport type SessionSpaceCompressedId = number & {\n\treadonly SessionUnique: \"cea55054-6b82-4cbf-ad19-1fa645ea3b3e\";\n};\n\n/**\n * A compressed ID that has been normalized into \"op space\".\n * Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when\n * received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.\n * @public\n */\nexport type OpSpaceCompressedId = number & {\n\treadonly OpNormalized: \"9209432d-a959-4df7-b2ad-767ead4dbcae\";\n};\n\n/**\n * A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).\n * A 128-bit Universally Unique IDentifier. Represented here\n * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,\n * where x is a lowercase hex digit.\n * @public\n */\nexport type StableId = string & { readonly StableId: \"53172b0d-a3d5-41ea-bd75-b43839c97f5a\" };\n\n/**\n * A StableId which is suitable for use as a session identifier\n * @public\n */\nexport type SessionId = StableId & { readonly SessionId: \"4498f850-e14e-4be9-8db0-89ec00997e58\" };\n"]}
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
7
+ * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to
8
+ * the scope of the session (i.e. compressor) that produced them.
9
+ * @public
10
+ */
11
+ export type SessionSpaceCompressedId = number & {
12
+ readonly SessionUnique: "cea55054-6b82-4cbf-ad19-1fa645ea3b3e";
13
+ };
14
+ /**
15
+ * A compressed ID that has been normalized into "op space".
16
+ * Serialized/persisted structures (e.g. ops) should use op-space IDs as a performance optimization, as they require less normalizing when
17
+ * received by a remote client due to the fact that op space for a given compressor is session space for all other compressors.
18
+ * @public
19
+ */
20
+ export type OpSpaceCompressedId = number & {
21
+ readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
22
+ };
23
+ /**
24
+ * A version 4, variant 1 uuid (https://datatracker.ietf.org/doc/html/rfc4122).
25
+ * A 128-bit Universally Unique IDentifier. Represented here
26
+ * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
27
+ * where x is a lowercase hex digit.
28
+ * @public
29
+ */
30
+ export type StableId = string & {
31
+ readonly StableId: "53172b0d-a3d5-41ea-bd75-b43839c97f5a";
32
+ };
33
+ /**
34
+ * A StableId which is suitable for use as a session identifier
35
+ * @public
36
+ */
37
+ export type SessionId = StableId & {
38
+ readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
39
+ };
40
+ //# sourceMappingURL=identifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/types/identifiers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG;IAC/C,QAAQ,CAAC,aAAa,EAAE,sCAAsC,CAAC;CAC/D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG;IAC1C,QAAQ,CAAC,YAAY,EAAE,sCAAsC,CAAC;CAC9D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,sCAAsC,CAAA;CAAE,CAAC;AAE9F;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,sCAAsC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tIdCreationRange,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n} from \"./persisted-types\";\n\nexport { IIdCompressorCore, IIdCompressor } from \"./idCompressor\";\n\nexport { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from \"./identifiers\";\n"]}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./persisted-types";
6
+ export { IIdCompressorCore, IIdCompressor } from "./idCompressor";
7
+ export { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,mCAAmC,EACnC,wCAAwC,GACxC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=0.0.1.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0.0.1.cjs","sourceRoot":"","sources":["../../../src/types/persisted-types/0.0.1.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { SessionId } from \"../identifiers\";\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressor = string & {\n\treadonly _serializedIdCompressor: \"8c73c57c-1cf4-4278-8915-6444cb4f6af5\";\n};\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {\n\treadonly _noLocalState: \"3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb\";\n};\n\n/**\n * The serialized contents of an IdCompressor, suitable for persistence in a summary.\n * @alpha\n */\nexport type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {\n\treadonly _hasLocalState: \"1281acae-6d14-47e7-bc92-71c8ee0819cb\";\n};\n\n/**\n * Data describing a range of session-local IDs (from a remote or local session).\n *\n * A range is composed of local IDs that were generated.\n * @alpha\n */\nexport interface IdCreationRange {\n\treadonly sessionId: SessionId;\n\treadonly ids?: {\n\t\t/**\n\t\t * The gen count of the first ID in the range created by `sessionId.`\n\t\t */\n\t\treadonly firstGenCount: number;\n\n\t\t/**\n\t\t * The number of IDs created in the range created by `sessionId.`\n\t\t */\n\t\treadonly count: number;\n\n\t\t/**\n\t\t * The size of the ID cluster to create if `count` overflows the existing cluster for\n\t\t * `sessionId`, if one exists. This request will be respected, and the size of the cluster\n\t\t * will be equal to overflow + `requestedClusterSize`.\n\t\t */\n\t\treadonly requestedClusterSize: number;\n\t};\n}\n"]}
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { SessionId } from "../identifiers";
6
+ /**
7
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
8
+ * @alpha
9
+ */
10
+ export type SerializedIdCompressor = string & {
11
+ readonly _serializedIdCompressor: "8c73c57c-1cf4-4278-8915-6444cb4f6af5";
12
+ };
13
+ /**
14
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
15
+ * @alpha
16
+ */
17
+ export type SerializedIdCompressorWithNoSession = SerializedIdCompressor & {
18
+ readonly _noLocalState: "3aa2e1e8-cc28-4ea7-bc1a-a11dc3f26dfb";
19
+ };
20
+ /**
21
+ * The serialized contents of an IdCompressor, suitable for persistence in a summary.
22
+ * @alpha
23
+ */
24
+ export type SerializedIdCompressorWithOngoingSession = SerializedIdCompressor & {
25
+ readonly _hasLocalState: "1281acae-6d14-47e7-bc92-71c8ee0819cb";
26
+ };
27
+ /**
28
+ * Data describing a range of session-local IDs (from a remote or local session).
29
+ *
30
+ * A range is composed of local IDs that were generated.
31
+ * @alpha
32
+ */
33
+ export interface IdCreationRange {
34
+ readonly sessionId: SessionId;
35
+ readonly ids?: {
36
+ /**
37
+ * The gen count of the first ID in the range created by `sessionId.`
38
+ */
39
+ readonly firstGenCount: number;
40
+ /**
41
+ * The number of IDs created in the range created by `sessionId.`
42
+ */
43
+ readonly count: number;
44
+ /**
45
+ * The size of the ID cluster to create if `count` overflows the existing cluster for
46
+ * `sessionId`, if one exists. This request will be respected, and the size of the cluster
47
+ * will be equal to overflow + `requestedClusterSize`.
48
+ */
49
+ readonly requestedClusterSize: number;
50
+ };
51
+ }
52
+ //# sourceMappingURL=0.0.1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0.0.1.d.ts","sourceRoot":"","sources":["../../../src/types/persisted-types/0.0.1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG;IAC7C,QAAQ,CAAC,uBAAuB,EAAE,sCAAsC,CAAC;CACzE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IAC1E,QAAQ,CAAC,aAAa,EAAE,sCAAsC,CAAC;CAC/D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wCAAwC,GAAG,sBAAsB,GAAG;IAC/E,QAAQ,CAAC,cAAc,EAAE,sCAAsC,CAAC;CAChE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE;QACd;;WAEG;QACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAE/B;;WAEG;QACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAEvB;;;;WAIG;QACH,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;KACtC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/types/persisted-types/index.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tIdCreationRange,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n} from \"./0.0.1\";\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./0.0.1";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/persisted-types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,mCAAmC,EACnC,wCAAwC,GACxC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.addNumericUuids = exports.subtractNumericUuids = exports.offsetNumericUuid = exports.stableIdFromNumericUuid = exports.numericUuidFromStableId = exports.localIdFromGenCount = exports.genCountFromLocalId = exports.compareBigints = exports.compareStrings = exports.compareFiniteNumbers = exports.isStableId = exports.generateStableId = exports.assertIsSessionId = exports.assertIsStableId = exports.createSessionId = void 0;
8
+ /* eslint-disable no-bitwise */
9
+ const core_utils_1 = require("@fluidframework/core-utils");
10
+ const uuid_1 = require("uuid");
11
+ const hexadecimalCharCodes = Array.from("09afAF").map((c) => c.charCodeAt(0));
12
+ function isHexadecimalCharacter(charCode) {
13
+ return ((charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||
14
+ (charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||
15
+ (charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5]));
16
+ }
17
+ /**
18
+ * Generate a random session ID
19
+ * @alpha
20
+ */
21
+ function createSessionId() {
22
+ return assertIsStableId((0, uuid_1.v4)());
23
+ }
24
+ exports.createSessionId = createSessionId;
25
+ /**
26
+ * Asserts that the given string is a stable ID.
27
+ * @internal
28
+ */
29
+ function assertIsStableId(stableId) {
30
+ (0, core_utils_1.assert)(isStableId(stableId), 0x4a3 /* Expected a StableId */);
31
+ return stableId;
32
+ }
33
+ exports.assertIsStableId = assertIsStableId;
34
+ /**
35
+ * Asserts that the given string is a stable ID.
36
+ */
37
+ function assertIsSessionId(stableId) {
38
+ assertIsStableId(stableId);
39
+ return stableId;
40
+ }
41
+ exports.assertIsSessionId = assertIsSessionId;
42
+ /**
43
+ * Generate a random stable ID
44
+ * @internal
45
+ */
46
+ function generateStableId() {
47
+ return assertIsStableId((0, uuid_1.v4)());
48
+ }
49
+ exports.generateStableId = generateStableId;
50
+ /**
51
+ * Returns true iff the given string is a valid Version 4, variant 2 UUID
52
+ * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
53
+ * @internal
54
+ */
55
+ function isStableId(str) {
56
+ if (str.length !== 36) {
57
+ return false;
58
+ }
59
+ for (let i = 0; i < str.length; i++) {
60
+ switch (i) {
61
+ case 8:
62
+ case 13:
63
+ case 18:
64
+ case 23:
65
+ if (str.charAt(i) !== "-") {
66
+ return false;
67
+ }
68
+ break;
69
+ case 14:
70
+ if (str.charAt(i) !== "4") {
71
+ return false;
72
+ }
73
+ break;
74
+ case 19: {
75
+ const char = str.charAt(i);
76
+ if (char !== "8" && char !== "9" && char !== "a" && char !== "b") {
77
+ return false;
78
+ }
79
+ break;
80
+ }
81
+ default:
82
+ if (!isHexadecimalCharacter(str.charCodeAt(i))) {
83
+ return false;
84
+ }
85
+ break;
86
+ }
87
+ }
88
+ return true;
89
+ }
90
+ exports.isStableId = isStableId;
91
+ /**
92
+ * A numeric comparator used for sorting in ascending order.
93
+ *
94
+ * Handles +/-0 like Map: -0 is equal to +0.
95
+ */
96
+ function compareFiniteNumbers(a, b) {
97
+ return a - b;
98
+ }
99
+ exports.compareFiniteNumbers = compareFiniteNumbers;
100
+ /**
101
+ * Compares strings lexically to form a strict partial ordering.
102
+ */
103
+ function compareStrings(a, b) {
104
+ return a > b ? 1 : a === b ? 0 : -1;
105
+ }
106
+ exports.compareStrings = compareStrings;
107
+ /**
108
+ * Compares bigints to form a strict partial ordering.
109
+ */
110
+ function compareBigints(a, b) {
111
+ return a > b ? 1 : a === b ? 0 : -1;
112
+ }
113
+ exports.compareBigints = compareBigints;
114
+ function genCountFromLocalId(localId) {
115
+ return -localId;
116
+ }
117
+ exports.genCountFromLocalId = genCountFromLocalId;
118
+ function localIdFromGenCount(genCount) {
119
+ return -genCount;
120
+ }
121
+ exports.localIdFromGenCount = localIdFromGenCount;
122
+ // xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
123
+ const versionMask = 0x4n << (19n * 4n); // Version 4
124
+ const variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)
125
+ const upperMask = 0xffffffffffffn << (20n * 4n);
126
+ // Upper mask when version/variant bits are removed
127
+ const strippedUpperMask = upperMask >> 6n;
128
+ const middieBittiesMask = 0xfffn << (16n * 4n);
129
+ // Middie mask when version/variant bits are removed
130
+ const strippedMiddieBittiesMask = middieBittiesMask >> 2n;
131
+ // Note: leading character should be 3 to mask at 0011
132
+ // The more-significant half of the N nibble is used to denote the variant (10xx)
133
+ const lowerMask = 0x3fffffffffffffffn;
134
+ function numericUuidFromStableId(stableId) {
135
+ const uuidU128 = BigInt(`0x${stableId.replace(/-/g, "")}`);
136
+ const upperMasked = uuidU128 & upperMask;
137
+ const middieBittiesMasked = uuidU128 & middieBittiesMask;
138
+ const lowerMasked = uuidU128 & lowerMask;
139
+ const upperMaskedPlaced = upperMasked >> 6n;
140
+ const middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;
141
+ const id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;
142
+ return id;
143
+ }
144
+ exports.numericUuidFromStableId = numericUuidFromStableId;
145
+ function stableIdFromNumericUuid(numericUuid) {
146
+ // bitwise reverse transform
147
+ const upperMasked = (numericUuid & strippedUpperMask) << 6n;
148
+ const middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;
149
+ const lowerMasked = numericUuid & lowerMask;
150
+ const uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;
151
+ // Pad to 32 characters, inserting leading zeroes if needed
152
+ const uuidString = uuidU128.toString(16).padStart(32, "0");
153
+ return `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(12, 16)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}`;
154
+ }
155
+ exports.stableIdFromNumericUuid = stableIdFromNumericUuid;
156
+ function offsetNumericUuid(numericUuid, offset) {
157
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
158
+ return (numericUuid + BigInt(offset));
159
+ }
160
+ exports.offsetNumericUuid = offsetNumericUuid;
161
+ function subtractNumericUuids(a, b) {
162
+ return (a - b);
163
+ }
164
+ exports.subtractNumericUuids = subtractNumericUuids;
165
+ function addNumericUuids(a, b) {
166
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
167
+ return (a + b);
168
+ }
169
+ exports.addNumericUuids = addNumericUuids;
170
+ //# sourceMappingURL=utilities.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.cjs","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAC/B,2DAAoD;AACpD,+BAA0B;AAI1B,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAO3E,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC/C,OAAO,CACN,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC9B,OAAO,gBAAgB,CAAC,IAAA,SAAE,GAAE,CAAc,CAAC;AAC5C,CAAC;AAFD,0CAEC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,QAAgB;IAChD,IAAA,mBAAM,EAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC;AACjB,CAAC;AAHD,4CAGC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,QAAgB;IACjD,gBAAgB,CAAC,QAAQ,CAA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AAE,EAAE,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,EAAc,CAAC;AACjF,CAAC;AAZD,0DAYC;AAED,SAAgB,iBAAiB,CAAC,WAAwB,EAAE,MAAc;IACzE,qEAAqE;IACrE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAgB,CAAC;AACtD,CAAC;AAHD,8CAGC;AAED,SAAgB,oBAAoB,CAAC,CAAc,EAAE,CAAc;IAClE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAFD,oDAEC;AAED,SAAgB,eAAe,CAAC,CAAc,EAAE,CAAc;IAC7D,qEAAqE;IACrE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAHD,0CAGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { v4 } from \"uuid\";\nimport { SessionId, StableId } from \"./types\";\nimport { LocalCompressedId, NumericUuid } from \"./identifiers\";\n\nconst hexadecimalCharCodes = Array.from(\"09afAF\").map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number,\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/**\n * Generate a random session ID\n * @alpha\n */\nexport function createSessionId(): SessionId {\n\treturn assertIsStableId(v4()) as SessionId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n * @internal\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassert(isStableId(stableId), 0x4a3 /* Expected a StableId */);\n\treturn stableId;\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsSessionId(stableId: string): SessionId {\n\tassertIsStableId(stableId);\n\treturn stableId as SessionId;\n}\n\n/**\n * Generate a random stable ID\n * @internal\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n * @internal\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== \"-\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== \"4\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== \"8\" && char !== \"9\" && char !== \"a\" && char !== \"b\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Compares bigints to form a strict partial ordering.\n */\nexport function compareBigints<T extends bigint>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\nexport function genCountFromLocalId(localId: LocalCompressedId): number {\n\treturn -localId;\n}\n\nexport function localIdFromGenCount(genCount: number): LocalCompressedId {\n\treturn -genCount as LocalCompressedId;\n}\n\n// xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx\nconst versionMask = 0x4n << (19n * 4n); // Version 4\nconst variantMask = 0x8n << (15n * 4n); // Variant RFC4122 (1 0 x x)\nconst upperMask = 0xffffffffffffn << (20n * 4n);\n// Upper mask when version/variant bits are removed\nconst strippedUpperMask = upperMask >> 6n;\nconst middieBittiesMask = 0xfffn << (16n * 4n);\n// Middie mask when version/variant bits are removed\nconst strippedMiddieBittiesMask = middieBittiesMask >> 2n;\n// Note: leading character should be 3 to mask at 0011\n// The more-significant half of the N nibble is used to denote the variant (10xx)\nconst lowerMask = 0x3fffffffffffffffn;\n\nexport function numericUuidFromStableId(stableId: StableId): NumericUuid {\n\tconst uuidU128 = BigInt(`0x${stableId.replace(/-/g, \"\")}`);\n\tconst upperMasked = uuidU128 & upperMask;\n\tconst middieBittiesMasked = uuidU128 & middieBittiesMask;\n\tconst lowerMasked = uuidU128 & lowerMask;\n\n\tconst upperMaskedPlaced = upperMasked >> 6n;\n\tconst middieBittiesMaskedPlaced = middieBittiesMasked >> 2n;\n\n\tconst id = upperMaskedPlaced | middieBittiesMaskedPlaced | lowerMasked;\n\treturn id as NumericUuid;\n}\n\nexport function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId {\n\t// bitwise reverse transform\n\tconst upperMasked = (numericUuid & strippedUpperMask) << 6n;\n\tconst middieBittiesMasked = (numericUuid & strippedMiddieBittiesMask) << 2n;\n\tconst lowerMasked = numericUuid & lowerMask;\n\tconst uuidU128 = upperMasked | versionMask | middieBittiesMasked | variantMask | lowerMasked;\n\t// Pad to 32 characters, inserting leading zeroes if needed\n\tconst uuidString = uuidU128.toString(16).padStart(32, \"0\");\n\treturn `${uuidString.substring(0, 8)}-${uuidString.substring(8, 12)}-${uuidString.substring(\n\t\t12,\n\t\t16,\n\t)}-${uuidString.substring(16, 20)}-${uuidString.substring(20, 32)}` as StableId;\n}\n\nexport function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (numericUuid + BigInt(offset)) as NumericUuid;\n}\n\nexport function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\treturn (a - b) as NumericUuid;\n}\n\nexport function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (a + b) as NumericUuid;\n}\n"]}
@@ -0,0 +1,53 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { SessionId, StableId } from "./types";
6
+ import { LocalCompressedId, NumericUuid } from "./identifiers";
7
+ /**
8
+ * Generate a random session ID
9
+ * @alpha
10
+ */
11
+ export declare function createSessionId(): SessionId;
12
+ /**
13
+ * Asserts that the given string is a stable ID.
14
+ * @internal
15
+ */
16
+ export declare function assertIsStableId(stableId: string): StableId;
17
+ /**
18
+ * Asserts that the given string is a stable ID.
19
+ */
20
+ export declare function assertIsSessionId(stableId: string): SessionId;
21
+ /**
22
+ * Generate a random stable ID
23
+ * @internal
24
+ */
25
+ export declare function generateStableId(): StableId;
26
+ /**
27
+ * Returns true iff the given string is a valid Version 4, variant 2 UUID
28
+ * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
29
+ * @internal
30
+ */
31
+ export declare function isStableId(str: string): str is StableId;
32
+ /**
33
+ * A numeric comparator used for sorting in ascending order.
34
+ *
35
+ * Handles +/-0 like Map: -0 is equal to +0.
36
+ */
37
+ export declare function compareFiniteNumbers<T extends number>(a: T, b: T): number;
38
+ /**
39
+ * Compares strings lexically to form a strict partial ordering.
40
+ */
41
+ export declare function compareStrings<T extends string>(a: T, b: T): number;
42
+ /**
43
+ * Compares bigints to form a strict partial ordering.
44
+ */
45
+ export declare function compareBigints<T extends bigint>(a: T, b: T): number;
46
+ export declare function genCountFromLocalId(localId: LocalCompressedId): number;
47
+ export declare function localIdFromGenCount(genCount: number): LocalCompressedId;
48
+ export declare function numericUuidFromStableId(stableId: StableId): NumericUuid;
49
+ export declare function stableIdFromNumericUuid(numericUuid: NumericUuid): StableId;
50
+ export declare function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid;
51
+ export declare function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
52
+ export declare function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
53
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAmB/D;;;GAGG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAG3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAG7D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,QAAQ,CAuCvD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEzE;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