@fluidframework/id-compressor 2.0.0-rc.1.0.3 → 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.
Files changed (264) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +5 -5
  2. package/{.mocharc.js → .mocharc.cjs} +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
  5. package/api-extractor-lint.json +1 -1
  6. package/api-extractor.json +1 -1
  7. package/api-report/id-compressor.api.md +5 -42
  8. package/dist/finalSpace.d.ts +2 -2
  9. package/dist/finalSpace.d.ts.map +1 -1
  10. package/dist/finalSpace.js +4 -4
  11. package/dist/finalSpace.js.map +1 -1
  12. package/dist/id-compressor-alpha.d.ts +117 -112
  13. package/dist/id-compressor-beta.d.ts +84 -77
  14. package/dist/id-compressor-public.d.ts +84 -77
  15. package/dist/id-compressor-untrimmed.d.ts +117 -112
  16. package/dist/idCompressor.d.ts +15 -19
  17. package/dist/idCompressor.d.ts.map +1 -1
  18. package/dist/idCompressor.js +107 -94
  19. package/dist/idCompressor.js.map +1 -1
  20. package/dist/identifiers.d.ts +1 -1
  21. package/dist/identifiers.d.ts.map +1 -1
  22. package/dist/identifiers.js.map +1 -1
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +9 -10
  26. package/dist/index.js.map +1 -1
  27. package/dist/package.json +3 -0
  28. package/dist/packageVersion.d.ts +1 -1
  29. package/dist/packageVersion.js +1 -1
  30. package/dist/packageVersion.js.map +1 -1
  31. package/dist/persistanceUtilities.d.ts +1 -1
  32. package/dist/persistanceUtilities.d.ts.map +1 -1
  33. package/dist/persistanceUtilities.js.map +1 -1
  34. package/dist/sessionSpaceNormalizer.d.ts +2 -2
  35. package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
  36. package/dist/sessionSpaceNormalizer.js +4 -4
  37. package/dist/sessionSpaceNormalizer.js.map +1 -1
  38. package/dist/sessions.d.ts +2 -2
  39. package/dist/sessions.d.ts.map +1 -1
  40. package/dist/sessions.js +12 -12
  41. package/dist/sessions.js.map +1 -1
  42. package/dist/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  43. package/dist/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  44. package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  45. package/dist/test/appendOnlySortedMap.spec.d.ts +6 -0
  46. package/dist/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  47. package/dist/test/appendOnlySortedMap.spec.js.map +1 -0
  48. package/dist/test/idCompressor.perf.spec.d.ts +6 -0
  49. package/dist/test/idCompressor.perf.spec.d.ts.map +1 -0
  50. package/dist/test/idCompressor.perf.spec.js.map +1 -0
  51. package/dist/test/idCompressor.spec.d.ts +6 -0
  52. package/dist/test/idCompressor.spec.d.ts.map +1 -0
  53. package/dist/test/idCompressor.spec.js.map +1 -0
  54. package/dist/test/idCompressorTestUtilities.d.ts +245 -0
  55. package/dist/test/idCompressorTestUtilities.d.ts.map +1 -0
  56. package/dist/test/idCompressorTestUtilities.js +589 -0
  57. package/dist/test/idCompressorTestUtilities.js.map +1 -0
  58. package/dist/test/index.d.ts +9 -0
  59. package/dist/test/index.d.ts.map +1 -0
  60. package/dist/test/index.js +13 -0
  61. package/dist/test/index.js.map +1 -0
  62. package/dist/test/numericUuid.spec.d.ts +6 -0
  63. package/dist/test/numericUuid.spec.d.ts.map +1 -0
  64. package/dist/test/numericUuid.spec.js.map +1 -0
  65. package/dist/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  66. package/dist/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  67. package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -0
  68. package/dist/test/snapshots/dirname.cjs +16 -0
  69. package/dist/test/snapshots/dirname.cjs.map +1 -0
  70. package/dist/test/snapshots/dirname.d.cts +6 -0
  71. package/dist/test/snapshots/dirname.d.cts.map +1 -0
  72. package/{lib/types/idCompressor.mjs → dist/test/snapshots/summary.spec.d.ts} +1 -1
  73. package/dist/test/snapshots/summary.spec.d.ts.map +1 -0
  74. package/dist/test/snapshots/summary.spec.js.map +1 -0
  75. package/dist/test/testCommon.d.ts +90 -0
  76. package/dist/test/testCommon.d.ts.map +1 -0
  77. package/dist/test/testCommon.js +90 -0
  78. package/dist/test/testCommon.js.map +1 -0
  79. package/dist/tsdoc-metadata.json +1 -1
  80. package/dist/types/idCompressor.d.ts +134 -67
  81. package/dist/types/idCompressor.d.ts.map +1 -1
  82. package/dist/types/idCompressor.js.map +1 -1
  83. package/dist/types/index.d.ts +3 -3
  84. package/dist/types/index.d.ts.map +1 -1
  85. package/dist/types/index.js.map +1 -1
  86. package/dist/types/persisted-types/0.0.1.d.ts +1 -1
  87. package/dist/types/persisted-types/0.0.1.d.ts.map +1 -1
  88. package/dist/types/persisted-types/0.0.1.js.map +1 -1
  89. package/dist/types/persisted-types/index.d.ts +1 -1
  90. package/dist/types/persisted-types/index.d.ts.map +1 -1
  91. package/dist/types/persisted-types/index.js.map +1 -1
  92. package/dist/utilities.d.ts +2 -2
  93. package/dist/utilities.d.ts.map +1 -1
  94. package/dist/utilities.js.map +1 -1
  95. package/lib/{appendOnlySortedMap.d.mts → appendOnlySortedMap.d.ts} +1 -1
  96. package/lib/appendOnlySortedMap.d.ts.map +1 -0
  97. package/lib/{appendOnlySortedMap.mjs → appendOnlySortedMap.js} +3 -1
  98. package/lib/appendOnlySortedMap.js.map +1 -0
  99. package/lib/{finalSpace.d.mts → finalSpace.d.ts} +3 -3
  100. package/lib/finalSpace.d.ts.map +1 -0
  101. package/lib/{finalSpace.mjs → finalSpace.js} +2 -2
  102. package/lib/finalSpace.js.map +1 -0
  103. package/lib/{id-compressor-alpha.d.mts → id-compressor-alpha.d.ts} +117 -112
  104. package/lib/id-compressor-beta.d.ts +179 -0
  105. package/lib/id-compressor-public.d.ts +179 -0
  106. package/lib/{id-compressor-untrimmed.d.mts → id-compressor-untrimmed.d.ts} +117 -112
  107. package/lib/{idCompressor.d.mts → idCompressor.d.ts} +16 -20
  108. package/lib/idCompressor.d.ts.map +1 -0
  109. package/lib/{idCompressor.mjs → idCompressor.js} +54 -41
  110. package/lib/idCompressor.js.map +1 -0
  111. package/lib/{identifiers.d.mts → identifiers.d.ts} +2 -2
  112. package/lib/identifiers.d.ts.map +1 -0
  113. package/lib/{identifiers.mjs → identifiers.js} +1 -1
  114. package/lib/identifiers.js.map +1 -0
  115. package/lib/{index.d.mts → index.d.ts} +7 -4
  116. package/lib/index.d.ts.map +1 -0
  117. package/lib/index.js +10 -0
  118. package/lib/index.js.map +1 -0
  119. package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
  120. package/lib/packageVersion.d.ts.map +1 -0
  121. package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
  122. package/lib/packageVersion.js.map +1 -0
  123. package/lib/{persistanceUtilities.d.mts → persistanceUtilities.d.ts} +2 -2
  124. package/lib/persistanceUtilities.d.ts.map +1 -0
  125. package/lib/{persistanceUtilities.mjs → persistanceUtilities.js} +1 -1
  126. package/lib/persistanceUtilities.js.map +1 -0
  127. package/lib/{sessionSpaceNormalizer.d.mts → sessionSpaceNormalizer.d.ts} +3 -3
  128. package/lib/sessionSpaceNormalizer.d.ts.map +1 -0
  129. package/lib/{sessionSpaceNormalizer.mjs → sessionSpaceNormalizer.js} +3 -3
  130. package/lib/sessionSpaceNormalizer.js.map +1 -0
  131. package/lib/{sessions.d.mts → sessions.d.ts} +3 -3
  132. package/lib/sessions.d.ts.map +1 -0
  133. package/lib/{sessions.mjs → sessions.js} +2 -2
  134. package/lib/sessions.js.map +1 -0
  135. package/lib/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  136. package/lib/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  137. package/lib/test/appendOnlySortedMap.perf.spec.js +49 -0
  138. package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  139. package/lib/test/appendOnlySortedMap.spec.d.ts +6 -0
  140. package/lib/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  141. package/lib/test/appendOnlySortedMap.spec.js +166 -0
  142. package/lib/test/appendOnlySortedMap.spec.js.map +1 -0
  143. package/lib/test/idCompressor.perf.spec.d.ts +6 -0
  144. package/lib/test/idCompressor.perf.spec.d.ts.map +1 -0
  145. package/lib/test/idCompressor.perf.spec.js +281 -0
  146. package/lib/test/idCompressor.perf.spec.js.map +1 -0
  147. package/lib/test/idCompressor.spec.d.ts +6 -0
  148. package/lib/test/idCompressor.spec.d.ts.map +1 -0
  149. package/lib/test/idCompressor.spec.js +953 -0
  150. package/lib/test/idCompressor.spec.js.map +1 -0
  151. package/lib/test/idCompressorTestUtilities.d.ts +245 -0
  152. package/lib/test/idCompressorTestUtilities.d.ts.map +1 -0
  153. package/lib/test/idCompressorTestUtilities.js +576 -0
  154. package/lib/test/idCompressorTestUtilities.js.map +1 -0
  155. package/lib/test/index.d.ts +9 -0
  156. package/lib/test/index.d.ts.map +1 -0
  157. package/lib/test/index.js +9 -0
  158. package/lib/test/index.js.map +1 -0
  159. package/lib/test/numericUuid.spec.d.ts +6 -0
  160. package/lib/test/numericUuid.spec.d.ts.map +1 -0
  161. package/lib/test/numericUuid.spec.js +74 -0
  162. package/lib/test/numericUuid.spec.js.map +1 -0
  163. package/lib/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  164. package/lib/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  165. package/lib/test/sessionSpaceNormalizer.spec.js +43 -0
  166. package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -0
  167. package/lib/test/snapshots/dirname.cjs +16 -0
  168. package/lib/test/snapshots/dirname.cjs.map +1 -0
  169. package/lib/test/snapshots/dirname.d.cts +6 -0
  170. package/lib/test/snapshots/dirname.d.cts.map +1 -0
  171. package/lib/test/snapshots/summary.spec.d.ts +6 -0
  172. package/lib/test/snapshots/summary.spec.d.ts.map +1 -0
  173. package/lib/test/snapshots/summary.spec.js +127 -0
  174. package/lib/test/snapshots/summary.spec.js.map +1 -0
  175. package/lib/test/testCommon.d.ts +90 -0
  176. package/lib/test/testCommon.d.ts.map +1 -0
  177. package/lib/test/testCommon.js +80 -0
  178. package/lib/test/testCommon.js.map +1 -0
  179. package/lib/types/{idCompressor.d.mts → idCompressor.d.ts} +135 -68
  180. package/lib/types/idCompressor.d.ts.map +1 -0
  181. package/lib/types/{identifiers.mjs → idCompressor.js} +1 -1
  182. package/lib/types/idCompressor.js.map +1 -0
  183. package/lib/types/{identifiers.d.mts → identifiers.d.ts} +1 -1
  184. package/lib/types/identifiers.d.ts.map +1 -0
  185. package/lib/types/identifiers.js +6 -0
  186. package/lib/types/identifiers.js.map +1 -0
  187. package/lib/types/{index.d.mts → index.d.ts} +4 -4
  188. package/lib/types/index.d.ts.map +1 -0
  189. package/lib/types/{persisted-types/0.0.1.mjs → index.js} +1 -1
  190. package/lib/types/index.js.map +1 -0
  191. package/lib/types/persisted-types/{0.0.1.d.mts → 0.0.1.d.ts} +2 -2
  192. package/lib/types/persisted-types/0.0.1.d.ts.map +1 -0
  193. package/lib/types/persisted-types/{index.mjs → 0.0.1.js} +1 -1
  194. package/lib/types/persisted-types/0.0.1.js.map +1 -0
  195. package/lib/types/persisted-types/{index.d.mts → index.d.ts} +2 -2
  196. package/lib/types/persisted-types/index.d.ts.map +1 -0
  197. package/lib/types/{index.mjs → persisted-types/index.js} +1 -1
  198. package/lib/types/persisted-types/index.js.map +1 -0
  199. package/lib/{utilities.d.mts → utilities.d.ts} +3 -3
  200. package/lib/utilities.d.ts.map +1 -0
  201. package/lib/{utilities.mjs → utilities.js} +2 -1
  202. package/lib/utilities.js.map +1 -0
  203. package/package.json +87 -21
  204. package/src/finalSpace.ts +2 -2
  205. package/src/idCompressor.ts +75 -59
  206. package/src/identifiers.ts +1 -1
  207. package/src/index.ts +3 -3
  208. package/src/packageVersion.ts +1 -1
  209. package/src/persistanceUtilities.ts +1 -1
  210. package/src/sessionSpaceNormalizer.ts +3 -3
  211. package/src/sessions.ts +3 -3
  212. package/src/test/idCompressorTestUtilities.ts +921 -0
  213. package/src/test/index.ts +10 -0
  214. package/src/test/snapshots/dirname.cts +13 -0
  215. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client +1 -0
  216. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client-client2 +1 -0
  217. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients +1 -0
  218. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients-client2 +1 -0
  219. package/src/test/snapshots/files/empty-compressor-summary +1 -0
  220. package/src/test/snapshots/files/expansion-semantics +1 -0
  221. package/src/test/snapshots/files/expansion-semantics-client2 +1 -0
  222. package/src/test/testCommon.ts +143 -0
  223. package/src/test/tsconfig.cjs.json +12 -0
  224. package/src/test/tsconfig.json +20 -0
  225. package/src/types/idCompressor.ts +147 -72
  226. package/src/types/index.ts +8 -3
  227. package/src/types/persisted-types/0.0.1.ts +1 -1
  228. package/src/types/persisted-types/index.ts +1 -1
  229. package/src/utilities.ts +2 -2
  230. package/tsconfig.cjs.json +7 -0
  231. package/tsconfig.json +2 -5
  232. package/lib/appendOnlySortedMap.d.mts.map +0 -1
  233. package/lib/appendOnlySortedMap.mjs.map +0 -1
  234. package/lib/finalSpace.d.mts.map +0 -1
  235. package/lib/finalSpace.mjs.map +0 -1
  236. package/lib/id-compressor-beta.d.mts +0 -172
  237. package/lib/id-compressor-public.d.mts +0 -172
  238. package/lib/idCompressor.d.mts.map +0 -1
  239. package/lib/idCompressor.mjs.map +0 -1
  240. package/lib/identifiers.d.mts.map +0 -1
  241. package/lib/identifiers.mjs.map +0 -1
  242. package/lib/index.d.mts.map +0 -1
  243. package/lib/index.mjs +0 -7
  244. package/lib/index.mjs.map +0 -1
  245. package/lib/packageVersion.d.mts.map +0 -1
  246. package/lib/packageVersion.mjs.map +0 -1
  247. package/lib/persistanceUtilities.d.mts.map +0 -1
  248. package/lib/persistanceUtilities.mjs.map +0 -1
  249. package/lib/sessionSpaceNormalizer.d.mts.map +0 -1
  250. package/lib/sessionSpaceNormalizer.mjs.map +0 -1
  251. package/lib/sessions.d.mts.map +0 -1
  252. package/lib/sessions.mjs.map +0 -1
  253. package/lib/types/idCompressor.d.mts.map +0 -1
  254. package/lib/types/idCompressor.mjs.map +0 -1
  255. package/lib/types/identifiers.d.mts.map +0 -1
  256. package/lib/types/identifiers.mjs.map +0 -1
  257. package/lib/types/index.d.mts.map +0 -1
  258. package/lib/types/index.mjs.map +0 -1
  259. package/lib/types/persisted-types/0.0.1.d.mts.map +0 -1
  260. package/lib/types/persisted-types/0.0.1.mjs.map +0 -1
  261. package/lib/types/persisted-types/index.d.mts.map +0 -1
  262. package/lib/types/persisted-types/index.mjs.map +0 -1
  263. package/lib/utilities.d.mts.map +0 -1
  264. package/lib/utilities.mjs.map +0 -1
@@ -0,0 +1,80 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { assert } from "@fluidframework/core-utils";
6
+ import { numericUuidFromStableId, offsetNumericUuid, stableIdFromNumericUuid, } from "../utilities.js";
7
+ /**
8
+ * @returns true if the supplied ID is a final ID.
9
+ */
10
+ export function isFinalId(id) {
11
+ return id >= 0;
12
+ }
13
+ /**
14
+ * @returns true if the supplied ID is a local ID.
15
+ */
16
+ export function isLocalId(id) {
17
+ return id < 0;
18
+ }
19
+ /**
20
+ * Turns a negative integer into a local compressed ID. For testing only.
21
+ */
22
+ export function makeLocalId(negativeInteger) {
23
+ const id = negativeInteger;
24
+ assert(isLocalId(id), "Not a negative integer.");
25
+ return id;
26
+ }
27
+ /**
28
+ * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
29
+ * @param map - The map to query/update
30
+ * @param key - The key to lookup in the map
31
+ * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists
32
+ * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)
33
+ */
34
+ export function getOrCreate(map, key, defaultValue) {
35
+ let value = map.get(key);
36
+ if (value === undefined) {
37
+ value = defaultValue(key);
38
+ map.set(key, value);
39
+ }
40
+ return value;
41
+ }
42
+ export function incrementStableId(stableId, offset) {
43
+ return stableIdFromNumericUuid(offsetNumericUuid(numericUuidFromStableId(stableId), offset));
44
+ }
45
+ /**
46
+ * Asserts a value is not undefined, and returns the value.
47
+ * Use when violations are logic errors in the program.
48
+ *
49
+ * @remarks
50
+ * When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.
51
+ * Using `?? fail` allows for message formatting without incurring the cost of formatting the message
52
+ * in the non failing case.
53
+ *
54
+ * Example:
55
+ * ```typescript
56
+ * x ?? fail(`x should exist for ${y}`)
57
+ * ```
58
+ *
59
+ * Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.
60
+ *
61
+ * Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.
62
+ * This pattern is preferred because it is more general (same approach works with typeof, instance of,
63
+ * comparison to other values etc.).
64
+ *
65
+ * @param value - Value to assert against is non undefined.
66
+ * @param message - Message to be printed if assertion fails.
67
+ */
68
+ export function assertNotUndefined(value, message = "value must not be undefined") {
69
+ assert(value !== undefined, message);
70
+ return value;
71
+ }
72
+ /**
73
+ * Fails an assertion. Throws an Error that the assertion failed.
74
+ * Use when violations are logic errors in the program.
75
+ * @param message - Message to be printed if assertion fails.
76
+ */
77
+ export function fail(message) {
78
+ assert(false, message);
79
+ }
80
+ //# sourceMappingURL=testCommon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testCommon.js","sourceRoot":"","sources":["../../src/test/testCommon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EACN,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,iBAAiB,CAAC;AAoCzB;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,EAAgB;IACzC,OAAO,EAAE,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,EAAgB;IACzC,OAAO,EAAE,GAAG,CAAC,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,eAAuB;IAClD,MAAM,EAAE,GAAG,eAA+B,CAAC;IAC3C,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,yBAAyB,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC;AACX,CAAC;AAOD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAO,GAAc,EAAE,GAAM,EAAE,YAA2B;IACpF,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,EAAE;QACxB,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KACpB;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAkB,EAAE,MAAc;IACnE,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC9F,CAAC;AAWD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAoB,EACpB,OAAO,GAAG,6BAA6B;IAEvC,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IACnC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { SessionSpaceCompressedId, StableId, OpSpaceCompressedId } from \"..//index.js\";\nimport {\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n} from \"../utilities.js\";\nimport { IdCompressor } from \"../idCompressor.js\";\n\n/**\n * An identifier (v4 UUID) that has been shortened by a distributed compression algorithm.\n * Lacks a space (session/op), meaning its scope is the same as the space-specific ID from which it was derived.\n * @alpha\n */\nexport type CompressedId =\n\t| SessionSpaceCompressedId\n\t| OpSpaceCompressedId\n\t| FinalCompressedId\n\t| LocalCompressedId;\n\n/**\n * A compressed ID that is stable and unique within the scope of network of compressors (i.e. a document).\n * It can only be used/decompressed in the context of the originating document.\n * @alpha\n */\nexport type FinalCompressedId = number & {\n\treadonly FinalCompressedId: \"5d83d1e2-98b7-4e4e-a889-54c855cfa73d\";\n\n\t// Same brand as OpNormalizedCompressedId, as final IDs are always finally normalized\n\treadonly OpNormalized: \"9209432d-a959-4df7-b2ad-767ead4dbcae\";\n};\n\n/**\n * A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).\n * Internally, it should not be persisted outside a scope annotated with the originating SessionId in order to be unambiguous.\n * If external persistence is needed (e.g. by a client), a StableId should be used instead.\n * @alpha\n */\nexport type LocalCompressedId = number & {\n\treadonly LocalCompressedId: \"6fccb42f-e2a4-4243-bd29-f13d12b9c6d1\";\n} & SessionSpaceCompressedId; // Same brand as CompressedId, as local IDs are always locally normalized\n\n/**\n * @returns true if the supplied ID is a final ID.\n */\nexport function isFinalId(id: CompressedId): id is FinalCompressedId {\n\treturn id >= 0;\n}\n\n/**\n * @returns true if the supplied ID is a local ID.\n */\nexport function isLocalId(id: CompressedId): id is LocalCompressedId {\n\treturn id < 0;\n}\n\n/**\n * Turns a negative integer into a local compressed ID. For testing only.\n */\nexport function makeLocalId(negativeInteger: number): LocalCompressedId {\n\tconst id = negativeInteger as CompressedId;\n\tassert(isLocalId(id), \"Not a negative integer.\");\n\treturn id;\n}\n\n/**\n * Remove `readonly` from all fields.\n */\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n */\nexport function getOrCreate<K, V>(map: Map<K, V>, key: K, defaultValue: (key: K) => V): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\nexport function incrementStableId(stableId: StableId, offset: number): StableId {\n\treturn stableIdFromNumericUuid(offsetNumericUuid(numericUuidFromStableId(stableId), offset));\n}\n\n/** An immutable view of an `IdCompressor` */\nexport type ReadonlyIdCompressor = Omit<\n\tIdCompressor,\n\t| \"generateCompressedId\"\n\t| \"generateCompressedIdRange\"\n\t| \"takeNextCreationRange\"\n\t| \"finalizeCreationRange\"\n>;\n\n/**\n * Asserts a value is not undefined, and returns the value.\n * Use when violations are logic errors in the program.\n *\n * @remarks\n * When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.\n * Using `?? fail` allows for message formatting without incurring the cost of formatting the message\n * in the non failing case.\n *\n * Example:\n * ```typescript\n * x ?? fail(`x should exist for ${y}`)\n * ```\n *\n * Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.\n *\n * Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.\n * This pattern is preferred because it is more general (same approach works with typeof, instance of,\n * comparison to other values etc.).\n *\n * @param value - Value to assert against is non undefined.\n * @param message - Message to be printed if assertion fails.\n */\nexport function assertNotUndefined<T>(\n\tvalue: T | undefined,\n\tmessage = \"value must not be undefined\",\n): T {\n\tassert(value !== undefined, message);\n\treturn value;\n}\n\n/**\n * Fails an assertion. Throws an Error that the assertion failed.\n * Use when violations are logic errors in the program.\n * @param message - Message to be printed if assertion fails.\n */\nexport function fail(message: string): never {\n\tassert(false, message);\n}\n"]}
@@ -2,56 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers.mjs";
6
- import { IdCreationRange, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession } from "./persisted-types/index.mjs";
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
- * Run a callback that is performed from the perspective of a special "ghost" session.
25
- * Any ids generated by this session will be immediately finalized on the local client as if
26
- * they were created by a remote client with `ghostSessionId`.
27
- *
28
- * *WARNING:* This API requires an external consensus mechanism to safely use:
29
- * In an attached container (i.e. multiple clients may have the document loaded), all clients must guarantee that:
30
- * - They invoke this API starting from the same finalized creation ranges
31
- * - This API is invoked with the same ghost session id
32
- * - `ghostSessionCallback` deterministically mints the same number of ids on each client within the ghost session
33
- * Failure to meet these requirement will result in divergence across clients and eventual consistency errors.
34
- * While the ghost sesion callback is running, IdCompressor does not support serialization.
35
- * @remarks This API is primarily intended for data migration scenarios which are able to deterministically transform
36
- * data in some format into data in a new format.
37
- * The first requirement (that all clients must invoke the API with the same finalized creation ranges) is guaranteed
38
- * for this scenario because the data transformation callback occurs at a specific ack within the op stream on all
39
- * clients, and clients don't finalize creation ranges for local changes they might have at this point in time.
40
- * @param ghostSessionId - The session id that minted ids generated within `ghostSessionCallback` should be attributed to.
41
- * @param ghostSessionCallback - Callback which mints ids attributed to the ghost session.
42
- */
43
- beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): any;
44
- /**
45
- * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
46
- * This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
47
- */
48
- serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
49
- /**
50
- * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
51
- * This only includes finalized state and is therefore suitable for use in summaries.
52
- */
53
- serialize(withSession: false): SerializedIdCompressorWithNoSession;
54
- }
5
+ import { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers.js";
6
+ import { IdCreationRange, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession } from "./persisted-types/index.js";
55
7
  /**
56
8
  * A distributed UUID generator and compressor.
57
9
  *
@@ -112,49 +64,164 @@ export interface IIdCompressorCore {
112
64
  *
113
65
  * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops
114
66
  * should use op-space IDs.
67
+ * @alpha
68
+ */
69
+ export interface IIdCompressorCore {
70
+ /**
71
+ * Returns a range of IDs created by this session in a format for sending to the server for finalizing.
72
+ * The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.
73
+ * @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before
74
+ * it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
75
+ */
76
+ takeNextCreationRange(): IdCreationRange;
77
+ /**
78
+ * Finalizes the supplied range of IDs (which may be from either a remote or local session).
79
+ * @param range - the range of session-local IDs to finalize.
80
+ */
81
+ finalizeCreationRange(range: IdCreationRange): void;
82
+ /**
83
+ * Run a callback that is performed from the perspective of a special "ghost" session.
84
+ * Any ids generated by this session will be immediately finalized on the local client as if
85
+ * they were created by a remote client with `ghostSessionId`.
86
+ *
87
+ * *WARNING:* This API requires an external consensus mechanism to safely use:
88
+ * In an attached container (i.e. multiple clients may have the document loaded), all clients must guarantee that:
89
+ * - They invoke this API starting from the same finalized creation ranges
90
+ * - This API is invoked with the same ghost session id
91
+ * - `ghostSessionCallback` deterministically mints the same number of ids on each client within the ghost session
92
+ * Failure to meet these requirement will result in divergence across clients and eventual consistency errors.
93
+ * While the ghost sesion callback is running, IdCompressor does not support serialization.
94
+ * @remarks This API is primarily intended for data migration scenarios which are able to deterministically transform
95
+ * data in some format into data in a new format.
96
+ * The first requirement (that all clients must invoke the API with the same finalized creation ranges) is guaranteed
97
+ * for this scenario because the data transformation callback occurs at a specific ack within the op stream on all
98
+ * clients, and clients don't finalize creation ranges for local changes they might have at this point in time.
99
+ * @param ghostSessionId - The session id that minted ids generated within `ghostSessionCallback` should be attributed to.
100
+ * @param ghostSessionCallback - Callback which mints ids attributed to the ghost session.
101
+ */
102
+ beginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void): any;
103
+ /**
104
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
105
+ * This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.
106
+ */
107
+ serialize(withSession: true): SerializedIdCompressorWithOngoingSession;
108
+ /**
109
+ * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.
110
+ * This only includes finalized state and is therefore suitable for use in summaries.
111
+ */
112
+ serialize(withSession: false): SerializedIdCompressorWithNoSession;
113
+ }
114
+ /**
115
+ * A distributed UUID generator and compressor.
116
+ * `IdCompressor` offers the ability to generate arbitrary non-colliding v4 UUIDs, called stable IDs, while compressing them into small integers
117
+ * for efficient storage and transmission. It also provides the ability to decompress these integers back into their original UUIDs.
118
+ *
119
+ * The compressor is designed to be used in a distributed environment, where multiple clients may be generating IDs concurrently.
120
+ * IDs generated by a compressor, via calls to `generateCompressedId`, are created in the compressor's "local" session.
121
+ * These IDs are unique within the session, but may not be unique across sessions. In the context of Fluid, the scope of a session
122
+ * is the same as the scope of a container. This means that anytime IDs are transferred between sessions, they must be translated
123
+ * through a process called "normalization":
124
+ * - The scope of a local session (in which local IDs are unique) is called the "session space" of the client.
125
+ * - The context of persisted state (in Fluid, this is the context of ops and summaries) is called "op space".
126
+ * - `SessionSpaceCompressedId`s, generated via calls to `generateCompressedId`, should NEVER be serialized directly.
127
+ * In Fluid, this means they should not be included in ops or summaries.
128
+ * - Before serialization, IDs must be normalized to op space to ensure they are interpretable by other clients.
129
+ * - Upon receipt, IDs should be normalized back to session space before use.
130
+ *
131
+ * Example Usage:
132
+ *
133
+ * ### Client A (Sender)
134
+ *
135
+ * ```typescript
136
+ * // Generate several local IDs
137
+ * const localId1 = idCompressor.generateCompressedId();
138
+ * const localId2 = idCompressor.generateCompressedId();
139
+ * const localId3 = idCompressor.generateCompressedId();
140
+ *
141
+ * // Normalize these IDs to op space for inclusion in a message
142
+ * const opSpaceId1 = idCompressor.normalizeToOpSpace(localId1);
143
+ * const opSpaceId2 = idCompressor.normalizeToOpSpace(localId2);
144
+ * const opSpaceId3 = idCompressor.normalizeToOpSpace(localId3);
145
+ *
146
+ * // Create and send a message containing these op space IDs along with the sender's session ID
147
+ * // In Fluid, this would be an op or summary
148
+ * const message = {
149
+ * sessionID: idCompressor.localSessionId,
150
+ * ids: [opSpaceId1, opSpaceId2, opSpaceId3]
151
+ * };
152
+ * ```
153
+ *
154
+ * ### Client B (Receiver)
155
+ *
156
+ * ```typescript
157
+ * // Receive the message from Client A
158
+ * const receivedMessage = ...; // In Fluid, this would be an op or summary
159
+ *
160
+ * // Normalize the received IDs back to session space, utilizing the sender's session ID
161
+ * const sessionSpaceId1 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[0], receivedMessage.sessionID);
162
+ * const sessionSpaceId2 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[1], receivedMessage.sessionID);
163
+ * const sessionSpaceId3 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[2], receivedMessage.sessionID);
164
+ * ```
115
165
  * @public
116
166
  */
117
167
  export interface IIdCompressor {
168
+ /**
169
+ * The local session ID.
170
+ */
118
171
  localSessionId: SessionId;
119
172
  /**
120
- * Generates a new compressed ID or returns an existing one.
121
- * This should ONLY be called to generate IDs for local operations.
173
+ * Generates a new compressed ID.
174
+ * The returned ID is in session space and should not be serialized directly. See `IIdCompressor` for more details.
122
175
  * @returns A new local ID in session space.
123
176
  */
124
177
  generateCompressedId(): SessionSpaceCompressedId;
178
+ /**
179
+ * Generates a new ID that is guaranteed to be unique across all sessions known to this compressor without the need for any
180
+ * normalization. The returned ID is not guaranteed to be a compressed ID (small number); it may be a stable ID (UUID string).
181
+ * In Fluid, the likelihood of generating the bulkier stable ID is dictated by network conditions and is highly probably in
182
+ * scenarios such as offline. This is still useful for use cases where simplicity is more important than performance and
183
+ * this approach will often be superior to generating a UUID.
184
+ * If small numbers are a requirement, `generateCompressedId` and normalization should be used instead.
185
+ * See `IIdCompressor` for more details.
186
+ * @returns A new local ID in session space.
187
+ */
188
+ generateDocumentUniqueId(): (SessionSpaceCompressedId & OpSpaceCompressedId) | StableId;
125
189
  /**
126
190
  * Normalizes a session space ID into op space.
127
- * @param id - the local ID to normalize.
128
- * @returns the ID in op space.
191
+ * The returned ID is in op space and can be safely serialized. However, it should be normalized back to session space before use.
192
+ * See `IIdCompressor` for more details.
193
+ * @param id - The local ID to normalize.
194
+ * @returns The ID in op space.
129
195
  */
130
196
  normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;
131
197
  /**
132
198
  * Normalizes an ID into session space.
133
- * @param id - the ID to normalize. If it is a local ID, it is assumed to have been created by the session corresponding
134
- * to `sessionId`.
135
- * @param originSessionId - the session from which `id` originated
136
- * @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
137
- * 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
138
- * range that contained it from the server.
199
+ * @param id - The ID to normalize.
200
+ * @param originSessionId - The session from which `id` originated. This should be the ID of the client that normalized `id` to op space.
201
+ * This means that it may not be the client that created `id` in the first place, but rather the client that serialized it.
202
+ * This is an important distinction in the case of a reference, where a client might refer to an ID created by another client.
203
+ * @returns The session-space ID in the local session corresponding to `id`.
139
204
  */
140
205
  normalizeToSessionSpace(id: OpSpaceCompressedId, originSessionId: SessionId): SessionSpaceCompressedId;
141
206
  /**
142
207
  * Decompresses a previously compressed ID into a UUID.
143
- * @param id - the compressed ID to be decompressed.
144
- * @returns the UUID associated with the compressed ID. Fails if the ID was not generated by this compressor.
208
+ * @param id - The compressed ID to be decompressed.
209
+ * @returns The UUID associated with the compressed ID.
210
+ * @throws If the ID was not generated by any session known to this compressor.
145
211
  */
146
212
  decompress(id: SessionSpaceCompressedId): StableId;
147
213
  /**
148
214
  * Recompresses a UUID.
149
- * @param uncompressed - the UUID to recompress.
150
- * @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
215
+ * @param uncompressed - The UUID to recompress.
216
+ * @returns The `CompressedId` associated with `uncompressed`.
217
+ * @throws If the UUID was not generated by any session known to this compressor.
151
218
  */
152
219
  recompress(uncompressed: StableId): SessionSpaceCompressedId;
153
220
  /**
154
- * Attempts to recompresses a UUID.
155
- * @param uncompressed - the UUID to recompress,
156
- * @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
221
+ * Attempts to recompress a UUID.
222
+ * @param uncompressed - The UUID to recompress.
223
+ * @returns The `CompressedId` associated with `uncompressed` or undefined if the UUID was not generated by any session known to this compressor.
157
224
  */
158
225
  tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;
159
226
  }
160
- //# sourceMappingURL=idCompressor.d.mts.map
227
+ //# sourceMappingURL=idCompressor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.d.ts","sourceRoot":"","sources":["../../src/types/idCompressor.ts"],"names":[],"mappings":"AAAA;;;G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U,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB,CAAC;IAE7D;;;;OAIG;IACH,aAAa,CAAC,YAAY,EAAE,QAAQ,GAAG,wBAAwB,GAAG,SAAS,CAAC;CAC5E"}
@@ -3,4 +3,4 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=identifiers.mjs.map
6
+ //# sourceMappingURL=idCompressor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.js","sourceRoot":"","sources":["../../src/types/idCompressor.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 {\n\tSessionSpaceCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n\tStableId,\n} from \"./identifiers.js\";\nimport {\n\tIdCreationRange,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n} from \"./persisted-types/index.js\";\n\n/**\n * A distributed UUID generator and compressor.\n *\n * Generates arbitrary non-colliding v4 UUIDs, called stable IDs, for multiple \"sessions\" (which can be distributed across the network),\n * providing each session with the ability to map these UUIDs to `numbers`.\n *\n * A session is a unique identifier that denotes a single compressor. New IDs are created through a single compressor API\n * which should then sent in ranges to the server for total ordering (and are subsequently relayed to other clients). When a new ID is\n * created it is said to be created by the compressor's \"local\" session.\n *\n * For each stable ID created, two numeric IDs are provided by the compressor:\n *\n * 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\n * be serialized for offline usage). Available as soon as the stable ID is allocated. These IDs are session-unique and are thus only\n * safely usable within the scope of the compressor that created it.\n *\n * 2. A final ID, which is stable across serialization and deserialization of an IdCompressor. Available as soon as the range containing\n * the corresponding session-local ID is totally ordered (via consensus) with respect to other sessions' allocations.\n * Final IDs are known to and publicly usable by any compressor that has received them.\n *\n * Compressors will allocate UUIDs in non-random ways to reduce entropy allowing for optimized storage of the data needed\n * to map the UUIDs to the numbers.\n *\n * The following invariants are upheld by IdCompressor:\n *\n * 1. Session-local IDs will always decompress to the same UUIDs for the lifetime of the session.\n *\n * 2. Final IDs will always decompress to the same UUIDs.\n *\n * 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\n * translated by the compressor into the corresponding final ID. For any given session-local ID, this translation will always yield the\n * same final ID.\n *\n * 4. A UUID will always compress into the same session-local ID for the lifetime of the session.\n *\n * Session-local IDs are sent across the wire in efficiently-represented ranges. These ranges are created by querying the compressor, and *must*\n * be ordered (i.e. sent to the server) in the order they are created in order to preserve the above invariants.\n *\n * Session-local IDs can be used immediately after creation, but will eventually (after being sequenced) have a corresponding final ID. This\n * could make reasoning about equality of those two forms difficult. For example, if a cache is keyed off of a\n * 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\n * produce a cache miss. In order to make using collections of both remotely created and locally created IDs easy, regardless of whether the\n * session-local IDs have been finalized, the compressor defines two \"spaces\" of IDs:\n *\n * 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\n * will be in local form, regardless of if they have been finalized. Remotely created IDs, which could only have been received after\n * 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\n * 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\n * these IDs across compressor objects, as the local IDs are specific to the compressor that created them.\n *\n * 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\n * 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\n * 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\n * out of Op space over time, namely, when a session-local ID in this space becomes finalized, and thereafter has a \"more final form\".\n * Consequentially, it may be useful to restrict parameters of a persisted type to this space (to optimize perf), but it is potentially\n * 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\n * \"local as possible\".\n *\n * These two spaces naturally define a rule: consumers of compressed IDs should use session-space IDs, but serialized forms such as ops\n * should use op-space IDs.\n * @alpha\n */\nexport interface IIdCompressorCore {\n\t/**\n\t * Returns a range of IDs created by this session in a format for sending to the server for finalizing.\n\t * The range will include all IDs generated via calls to `generateCompressedId` since the last time this method was called.\n\t * @returns the range of IDs, which may be empty. This range must be sent to the server for ordering before\n\t * it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.\n\t */\n\ttakeNextCreationRange(): IdCreationRange;\n\n\t/**\n\t * Finalizes the supplied range of IDs (which may be from either a remote or local session).\n\t * @param range - the range of session-local IDs to finalize.\n\t */\n\tfinalizeCreationRange(range: IdCreationRange): void;\n\n\t/**\n\t * Run a callback that is performed from the perspective of a special \"ghost\" session.\n\t * Any ids generated by this session will be immediately finalized on the local client as if\n\t * they were created by a remote client with `ghostSessionId`.\n\t *\n\t * *WARNING:* This API requires an external consensus mechanism to safely use:\n\t * In an attached container (i.e. multiple clients may have the document loaded), all clients must guarantee that:\n\t * - They invoke this API starting from the same finalized creation ranges\n\t * - This API is invoked with the same ghost session id\n\t * - `ghostSessionCallback` deterministically mints the same number of ids on each client within the ghost session\n\t * Failure to meet these requirement will result in divergence across clients and eventual consistency errors.\n\t * While the ghost sesion callback is running, IdCompressor does not support serialization.\n\t * @remarks This API is primarily intended for data migration scenarios which are able to deterministically transform\n\t * data in some format into data in a new format.\n\t * The first requirement (that all clients must invoke the API with the same finalized creation ranges) is guaranteed\n\t * for this scenario because the data transformation callback occurs at a specific ack within the op stream on all\n\t * clients, and clients don't finalize creation ranges for local changes they might have at this point in time.\n\t * @param ghostSessionId - The session id that minted ids generated within `ghostSessionCallback` should be attributed to.\n\t * @param ghostSessionCallback - Callback which mints ids attributed to the ghost session.\n\t */\n\tbeginGhostSession(ghostSessionId: SessionId, ghostSessionCallback: () => void);\n\n\t/**\n\t * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.\n\t * This includes finalized state as well as un-finalized state and is therefore suitable for use in offline scenarios.\n\t */\n\tserialize(withSession: true): SerializedIdCompressorWithOngoingSession;\n\n\t/**\n\t * Returns a persistable form of the current state of this `IdCompressor` which can be rehydrated via `IdCompressor.deserialize()`.\n\t * This only includes finalized state and is therefore suitable for use in summaries.\n\t */\n\tserialize(withSession: false): SerializedIdCompressorWithNoSession;\n}\n\n/**\n * A distributed UUID generator and compressor.\n * `IdCompressor` offers the ability to generate arbitrary non-colliding v4 UUIDs, called stable IDs, while compressing them into small integers\n * for efficient storage and transmission. It also provides the ability to decompress these integers back into their original UUIDs.\n *\n * The compressor is designed to be used in a distributed environment, where multiple clients may be generating IDs concurrently.\n * IDs generated by a compressor, via calls to `generateCompressedId`, are created in the compressor's \"local\" session.\n * These IDs are unique within the session, but may not be unique across sessions. In the context of Fluid, the scope of a session\n * is the same as the scope of a container. This means that anytime IDs are transferred between sessions, they must be translated\n * through a process called \"normalization\":\n * - The scope of a local session (in which local IDs are unique) is called the \"session space\" of the client.\n * - The context of persisted state (in Fluid, this is the context of ops and summaries) is called \"op space\".\n * - `SessionSpaceCompressedId`s, generated via calls to `generateCompressedId`, should NEVER be serialized directly.\n * In Fluid, this means they should not be included in ops or summaries.\n * - Before serialization, IDs must be normalized to op space to ensure they are interpretable by other clients.\n * - Upon receipt, IDs should be normalized back to session space before use.\n *\n * Example Usage:\n *\n * ### Client A (Sender)\n *\n * ```typescript\n * // Generate several local IDs\n * const localId1 = idCompressor.generateCompressedId();\n * const localId2 = idCompressor.generateCompressedId();\n * const localId3 = idCompressor.generateCompressedId();\n *\n * // Normalize these IDs to op space for inclusion in a message\n * const opSpaceId1 = idCompressor.normalizeToOpSpace(localId1);\n * const opSpaceId2 = idCompressor.normalizeToOpSpace(localId2);\n * const opSpaceId3 = idCompressor.normalizeToOpSpace(localId3);\n *\n * // Create and send a message containing these op space IDs along with the sender's session ID\n * // In Fluid, this would be an op or summary\n * const message = {\n * sessionID: idCompressor.localSessionId,\n * ids: [opSpaceId1, opSpaceId2, opSpaceId3]\n * };\n * ```\n *\n * ### Client B (Receiver)\n *\n * ```typescript\n * // Receive the message from Client A\n * const receivedMessage = ...; // In Fluid, this would be an op or summary\n *\n * // Normalize the received IDs back to session space, utilizing the sender's session ID\n * const sessionSpaceId1 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[0], receivedMessage.sessionID);\n * const sessionSpaceId2 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[1], receivedMessage.sessionID);\n * const sessionSpaceId3 = idCompressor.normalizeToSessionSpace(receivedMessage.ids[2], receivedMessage.sessionID);\n * ```\n * @public\n */\nexport interface IIdCompressor {\n\t/**\n\t * The local session ID.\n\t */\n\tlocalSessionId: SessionId;\n\n\t/**\n\t * Generates a new compressed ID.\n\t * The returned ID is in session space and should not be serialized directly. See `IIdCompressor` for more details.\n\t * @returns A new local ID in session space.\n\t */\n\tgenerateCompressedId(): SessionSpaceCompressedId;\n\n\t/**\n\t * Generates a new ID that is guaranteed to be unique across all sessions known to this compressor without the need for any\n\t * normalization. The returned ID is not guaranteed to be a compressed ID (small number); it may be a stable ID (UUID string).\n\t * In Fluid, the likelihood of generating the bulkier stable ID is dictated by network conditions and is highly probably in\n\t * scenarios such as offline. This is still useful for use cases where simplicity is more important than performance and\n\t * this approach will often be superior to generating a UUID.\n\t * If small numbers are a requirement, `generateCompressedId` and normalization should be used instead.\n\t * See `IIdCompressor` for more details.\n\t * @returns A new local ID in session space.\n\t */\n\tgenerateDocumentUniqueId(): (SessionSpaceCompressedId & OpSpaceCompressedId) | StableId;\n\n\t/**\n\t * Normalizes a session space ID into op space.\n\t * The returned ID is in op space and can be safely serialized. However, it should be normalized back to session space before use.\n\t * See `IIdCompressor` for more details.\n\t * @param id - The local ID to normalize.\n\t * @returns The ID in op space.\n\t */\n\tnormalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId;\n\n\t/**\n\t * Normalizes an ID into session space.\n\t * @param id - The ID to normalize.\n\t * @param originSessionId - The session from which `id` originated. This should be the ID of the client that normalized `id` to op space.\n\t * This means that it may not be the client that created `id` in the first place, but rather the client that serialized it.\n\t * This is an important distinction in the case of a reference, where a client might refer to an ID created by another client.\n\t * @returns The session-space ID in the local session corresponding to `id`.\n\t */\n\tnormalizeToSessionSpace(\n\t\tid: OpSpaceCompressedId,\n\t\toriginSessionId: SessionId,\n\t): SessionSpaceCompressedId;\n\n\t/**\n\t * Decompresses a previously compressed ID into a UUID.\n\t * @param id - The compressed ID to be decompressed.\n\t * @returns The UUID associated with the compressed ID.\n\t * @throws If the ID was not generated by any session known to this compressor.\n\t */\n\tdecompress(id: SessionSpaceCompressedId): StableId;\n\n\t/**\n\t * Recompresses a UUID.\n\t * @param uncompressed - The UUID to recompress.\n\t * @returns The `CompressedId` associated with `uncompressed`.\n\t * @throws If the UUID was not generated by any session known to this compressor.\n\t */\n\trecompress(uncompressed: StableId): SessionSpaceCompressedId;\n\n\t/**\n\t * Attempts to recompress a UUID.\n\t * @param uncompressed - The UUID to recompress.\n\t * @returns The `CompressedId` associated with `uncompressed` or undefined if the UUID was not generated by any session known to this compressor.\n\t */\n\ttryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined;\n}\n"]}
@@ -37,4 +37,4 @@ export type StableId = string & {
37
37
  export type SessionId = StableId & {
38
38
  readonly SessionId: "4498f850-e14e-4be9-8db0-89ec00997e58";
39
39
  };
40
- //# sourceMappingURL=identifiers.d.mts.map
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,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=identifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifiers.js","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"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./persisted-types/index.mjs";
6
- export { IIdCompressorCore, IIdCompressor } from "./idCompressor.mjs";
7
- export { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId } from "./identifiers.mjs";
8
- //# sourceMappingURL=index.d.mts.map
5
+ export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./persisted-types/index.js";
6
+ export { IIdCompressorCore, IIdCompressor } from "./idCompressor.js";
7
+ export { SessionSpaceCompressedId, OpSpaceCompressedId, SessionId, StableId, } from "./identifiers.js";
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,4BAA4B,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,QAAQ,GACR,MAAM,kBAAkB,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=0.0.1.mjs.map
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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/index.js\";\n\nexport { IIdCompressorCore, IIdCompressor } from \"./idCompressor.js\";\n\nexport {\n\tSessionSpaceCompressedId,\n\tOpSpaceCompressedId,\n\tSessionId,\n\tStableId,\n} from \"./identifiers.js\";\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { SessionId } from "../identifiers.mjs";
5
+ import type { SessionId } from "../identifiers.js";
6
6
  /**
7
7
  * The serialized contents of an IdCompressor, suitable for persistence in a summary.
8
8
  * @alpha
@@ -49,4 +49,4 @@ export interface IdCreationRange {
49
49
  readonly requestedClusterSize: number;
50
50
  };
51
51
  }
52
- //# sourceMappingURL=0.0.1.d.mts.map
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,mBAAmB,CAAC;AAEnD;;;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"}
@@ -3,4 +3,4 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=index.mjs.map
6
+ //# sourceMappingURL=0.0.1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0.0.1.js","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.js\";\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"]}
@@ -2,5 +2,5 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./0.0.1.mjs";
6
- //# sourceMappingURL=index.d.mts.map
5
+ export { IdCreationRange, SerializedIdCompressor, SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession, } from "./0.0.1.js";
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,YAAY,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=index.mjs.map
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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.js\";\n"]}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { SessionId, StableId } from "./types/index.mjs";
6
- import { LocalCompressedId, NumericUuid } from "./identifiers.mjs";
5
+ import { SessionId, StableId } from "./types/index.js";
6
+ import { LocalCompressedId, NumericUuid } from "./identifiers.js";
7
7
  /**
8
8
  * Generate a random session ID
9
9
  * @alpha
@@ -50,4 +50,4 @@ export declare function stableIdFromNumericUuid(numericUuid: NumericUuid): Stabl
50
50
  export declare function offsetNumericUuid(numericUuid: NumericUuid, offset: number): NumericUuid;
51
51
  export declare function subtractNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
52
52
  export declare function addNumericUuids(a: NumericUuid, b: NumericUuid): NumericUuid;
53
- //# sourceMappingURL=utilities.d.mts.map
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,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAmBlE;;;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;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAEtE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAEvE;AAeD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAWvE;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CAY1E;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAGvF;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAEhF;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAG3E"}
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ /* eslint-disable no-bitwise */
5
6
  import { assert } from "@fluidframework/core-utils";
6
7
  import { v4 } from "uuid";
7
8
  const hexadecimalCharCodes = Array.from("09afAF").map((c) => c.charCodeAt(0));
@@ -148,4 +149,4 @@ export function addNumericUuids(a, b) {
148
149
  // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
149
150
  return (a + b);
150
151
  }
151
- //# sourceMappingURL=utilities.mjs.map
152
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/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CAAC,CAAc,EAAE,CAAc;IAClE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAc,EAAE,CAAc;IAC7D,qEAAqE;IACrE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAgB,CAAC;AAC/B,CAAC","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/index.js\";\nimport { LocalCompressedId, NumericUuid } from \"./identifiers.js\";\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"]}