@fluidframework/tree 2.101.0 → 2.102.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 (291) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree.alpha.api.md +19 -0
  3. package/dist/codec/codec.d.ts +22 -53
  4. package/dist/codec/codec.d.ts.map +1 -1
  5. package/dist/codec/codec.js +7 -44
  6. package/dist/codec/codec.js.map +1 -1
  7. package/dist/codec/index.d.ts +1 -1
  8. package/dist/codec/index.d.ts.map +1 -1
  9. package/dist/codec/index.js +2 -2
  10. package/dist/codec/index.js.map +1 -1
  11. package/dist/codec/versioned/codec.d.ts +56 -28
  12. package/dist/codec/versioned/codec.d.ts.map +1 -1
  13. package/dist/codec/versioned/codec.js +29 -12
  14. package/dist/codec/versioned/codec.js.map +1 -1
  15. package/dist/codec/versioned/index.d.ts +1 -1
  16. package/dist/codec/versioned/index.d.ts.map +1 -1
  17. package/dist/codec/versioned/index.js +2 -2
  18. package/dist/codec/versioned/index.js.map +1 -1
  19. package/dist/core/tree/deltaUtil.d.ts +2 -2
  20. package/dist/core/tree/deltaUtil.js +2 -2
  21. package/dist/core/tree/deltaUtil.js.map +1 -1
  22. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  23. package/dist/core/tree/detachedFieldIndexCodecV1.js +3 -2
  24. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  25. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  26. package/dist/core/tree/detachedFieldIndexCodecV2.js +4 -2
  27. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  28. package/dist/core/tree/detachedFieldIndexCodecs.d.ts +3 -3
  29. package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  30. package/dist/core/tree/detachedFieldIndexCodecs.js +1 -1
  31. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +38 -1
  33. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  34. package/dist/feature-libraries/chunked-forest/chunkTree.js +62 -4
  35. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  36. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  37. package/dist/feature-libraries/chunked-forest/chunkedForest.js +18 -4
  38. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  39. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +34 -2
  40. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  41. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +106 -3
  42. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  43. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -5
  44. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  45. package/dist/feature-libraries/chunked-forest/codec/codecs.js +2 -2
  46. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  47. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +7 -7
  48. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  49. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +25 -5
  51. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js +9 -3
  53. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
  54. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +105 -0
  55. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -0
  56. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js +44 -0
  57. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -0
  58. package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts +2 -1
  59. package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
  60. package/dist/feature-libraries/chunked-forest/codec/format/index.js +5 -1
  61. package/dist/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
  62. package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts +38 -4
  63. package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
  64. package/dist/feature-libraries/chunked-forest/codec/format/versions.js +7 -1
  65. package/dist/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
  66. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts +7 -7
  67. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
  68. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js +1 -2
  69. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  70. package/dist/feature-libraries/forest-summary/codec.d.ts +5 -4
  71. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  72. package/dist/feature-libraries/forest-summary/codec.js +2 -2
  73. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  74. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +1 -1
  75. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  76. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  77. package/dist/feature-libraries/schema-index/codec.d.ts +2 -2
  78. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  79. package/dist/feature-libraries/schema-index/codec.js +1 -1
  80. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  81. package/dist/index.d.ts +1 -1
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +3 -1
  84. package/dist/index.js.map +1 -1
  85. package/dist/packageVersion.d.ts +1 -1
  86. package/dist/packageVersion.js +1 -1
  87. package/dist/packageVersion.js.map +1 -1
  88. package/dist/shared-tree/isAuditableFromOutcome.d.ts +20 -0
  89. package/dist/shared-tree/isAuditableFromOutcome.d.ts.map +1 -0
  90. package/dist/shared-tree/isAuditableFromOutcome.js +36 -0
  91. package/dist/shared-tree/isAuditableFromOutcome.js.map +1 -0
  92. package/dist/shared-tree/treeCheckout.d.ts +2 -0
  93. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  94. package/dist/shared-tree/treeCheckout.js +37 -8
  95. package/dist/shared-tree/treeCheckout.js.map +1 -1
  96. package/dist/shared-tree-core/editManagerCodecs.d.ts +3 -3
  97. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  98. package/dist/shared-tree-core/editManagerCodecs.js +2 -2
  99. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  100. package/dist/shared-tree-core/messageCodecs.d.ts +3 -3
  101. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  102. package/dist/shared-tree-core/messageCodecs.js +2 -2
  103. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  104. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  105. package/dist/simple-tree/core/treeNodeKernel.js +25 -11
  106. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  107. package/dist/text/codePointUtils.d.ts +48 -0
  108. package/dist/text/codePointUtils.d.ts.map +1 -0
  109. package/dist/text/codePointUtils.js +80 -0
  110. package/dist/text/codePointUtils.js.map +1 -0
  111. package/dist/text/index.d.ts +1 -0
  112. package/dist/text/index.d.ts.map +1 -1
  113. package/dist/text/index.js +4 -1
  114. package/dist/text/index.js.map +1 -1
  115. package/dist/text/textDomain.d.ts +93 -1
  116. package/dist/text/textDomain.d.ts.map +1 -1
  117. package/dist/text/textDomain.js +65 -8
  118. package/dist/text/textDomain.js.map +1 -1
  119. package/dist/text/textDomainFormatted.d.ts +24 -6
  120. package/dist/text/textDomainFormatted.d.ts.map +1 -1
  121. package/dist/text/textDomainFormatted.js +29 -1
  122. package/dist/text/textDomainFormatted.js.map +1 -1
  123. package/dist/treeFactory.d.ts.map +1 -1
  124. package/dist/treeFactory.js +9 -7
  125. package/dist/treeFactory.js.map +1 -1
  126. package/dist/util/breakable.d.ts +7 -1
  127. package/dist/util/breakable.d.ts.map +1 -1
  128. package/dist/util/breakable.js +18 -4
  129. package/dist/util/breakable.js.map +1 -1
  130. package/lib/codec/codec.d.ts +22 -53
  131. package/lib/codec/codec.d.ts.map +1 -1
  132. package/lib/codec/codec.js +7 -44
  133. package/lib/codec/codec.js.map +1 -1
  134. package/lib/codec/index.d.ts +1 -1
  135. package/lib/codec/index.d.ts.map +1 -1
  136. package/lib/codec/index.js +1 -1
  137. package/lib/codec/index.js.map +1 -1
  138. package/lib/codec/versioned/codec.d.ts +56 -28
  139. package/lib/codec/versioned/codec.d.ts.map +1 -1
  140. package/lib/codec/versioned/codec.js +27 -10
  141. package/lib/codec/versioned/codec.js.map +1 -1
  142. package/lib/codec/versioned/index.d.ts +1 -1
  143. package/lib/codec/versioned/index.d.ts.map +1 -1
  144. package/lib/codec/versioned/index.js +1 -1
  145. package/lib/codec/versioned/index.js.map +1 -1
  146. package/lib/core/tree/deltaUtil.d.ts +2 -2
  147. package/lib/core/tree/deltaUtil.js +2 -2
  148. package/lib/core/tree/deltaUtil.js.map +1 -1
  149. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  150. package/lib/core/tree/detachedFieldIndexCodecV1.js +3 -2
  151. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  152. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  153. package/lib/core/tree/detachedFieldIndexCodecV2.js +5 -3
  154. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  155. package/lib/core/tree/detachedFieldIndexCodecs.d.ts +3 -3
  156. package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  157. package/lib/core/tree/detachedFieldIndexCodecs.js +2 -2
  158. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  159. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +38 -1
  160. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  161. package/lib/feature-libraries/chunked-forest/chunkTree.js +61 -4
  162. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  163. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  164. package/lib/feature-libraries/chunked-forest/chunkedForest.js +20 -6
  165. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  166. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +34 -2
  167. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  168. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +102 -2
  169. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  170. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -5
  171. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  172. package/lib/feature-libraries/chunked-forest/codec/codecs.js +3 -3
  173. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  174. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +7 -7
  175. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  176. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  177. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +25 -5
  178. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
  179. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js +8 -2
  180. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
  181. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +105 -0
  182. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -0
  183. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js +41 -0
  184. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -0
  185. package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts +2 -1
  186. package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
  187. package/lib/feature-libraries/chunked-forest/codec/format/index.js +2 -1
  188. package/lib/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
  189. package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts +38 -4
  190. package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
  191. package/lib/feature-libraries/chunked-forest/codec/format/versions.js +6 -0
  192. package/lib/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
  193. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts +7 -7
  194. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
  195. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js +2 -3
  196. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  197. package/lib/feature-libraries/forest-summary/codec.d.ts +5 -4
  198. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  199. package/lib/feature-libraries/forest-summary/codec.js +3 -3
  200. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  201. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +1 -1
  202. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  203. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  204. package/lib/feature-libraries/schema-index/codec.d.ts +2 -2
  205. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  206. package/lib/feature-libraries/schema-index/codec.js +2 -2
  207. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  208. package/lib/index.d.ts +1 -1
  209. package/lib/index.d.ts.map +1 -1
  210. package/lib/index.js +1 -1
  211. package/lib/index.js.map +1 -1
  212. package/lib/packageVersion.d.ts +1 -1
  213. package/lib/packageVersion.js +1 -1
  214. package/lib/packageVersion.js.map +1 -1
  215. package/lib/shared-tree/isAuditableFromOutcome.d.ts +20 -0
  216. package/lib/shared-tree/isAuditableFromOutcome.d.ts.map +1 -0
  217. package/lib/shared-tree/isAuditableFromOutcome.js +32 -0
  218. package/lib/shared-tree/isAuditableFromOutcome.js.map +1 -0
  219. package/lib/shared-tree/treeCheckout.d.ts +2 -0
  220. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  221. package/lib/shared-tree/treeCheckout.js +37 -8
  222. package/lib/shared-tree/treeCheckout.js.map +1 -1
  223. package/lib/shared-tree-core/editManagerCodecs.d.ts +3 -3
  224. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  225. package/lib/shared-tree-core/editManagerCodecs.js +3 -3
  226. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  227. package/lib/shared-tree-core/messageCodecs.d.ts +3 -3
  228. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  229. package/lib/shared-tree-core/messageCodecs.js +3 -3
  230. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  231. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  232. package/lib/simple-tree/core/treeNodeKernel.js +25 -11
  233. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  234. package/lib/text/codePointUtils.d.ts +48 -0
  235. package/lib/text/codePointUtils.d.ts.map +1 -0
  236. package/lib/text/codePointUtils.js +75 -0
  237. package/lib/text/codePointUtils.js.map +1 -0
  238. package/lib/text/index.d.ts +1 -0
  239. package/lib/text/index.d.ts.map +1 -1
  240. package/lib/text/index.js +1 -0
  241. package/lib/text/index.js.map +1 -1
  242. package/lib/text/textDomain.d.ts +93 -1
  243. package/lib/text/textDomain.d.ts.map +1 -1
  244. package/lib/text/textDomain.js +56 -0
  245. package/lib/text/textDomain.js.map +1 -1
  246. package/lib/text/textDomainFormatted.d.ts +24 -6
  247. package/lib/text/textDomainFormatted.d.ts.map +1 -1
  248. package/lib/text/textDomainFormatted.js +30 -2
  249. package/lib/text/textDomainFormatted.js.map +1 -1
  250. package/lib/treeFactory.d.ts.map +1 -1
  251. package/lib/treeFactory.js +2 -0
  252. package/lib/treeFactory.js.map +1 -1
  253. package/lib/util/breakable.d.ts +7 -1
  254. package/lib/util/breakable.d.ts.map +1 -1
  255. package/lib/util/breakable.js +18 -4
  256. package/lib/util/breakable.js.map +1 -1
  257. package/package.json +24 -24
  258. package/src/codec/codec.ts +82 -73
  259. package/src/codec/index.ts +2 -1
  260. package/src/codec/versioned/codec.ts +173 -73
  261. package/src/codec/versioned/index.ts +2 -1
  262. package/src/core/tree/deltaUtil.ts +2 -2
  263. package/src/core/tree/detachedFieldIndexCodecV1.ts +3 -2
  264. package/src/core/tree/detachedFieldIndexCodecV2.ts +5 -3
  265. package/src/core/tree/detachedFieldIndexCodecs.ts +2 -2
  266. package/src/feature-libraries/chunked-forest/chunkTree.ts +85 -1
  267. package/src/feature-libraries/chunked-forest/chunkedForest.ts +27 -7
  268. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +143 -7
  269. package/src/feature-libraries/chunked-forest/codec/codecs.ts +30 -28
  270. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +7 -7
  271. package/src/feature-libraries/chunked-forest/codec/format/formatV2.ts +11 -7
  272. package/src/feature-libraries/chunked-forest/codec/format/formatVText.ts +83 -0
  273. package/src/feature-libraries/chunked-forest/codec/format/index.ts +6 -1
  274. package/src/feature-libraries/chunked-forest/codec/format/versions.ts +25 -4
  275. package/src/feature-libraries/chunked-forest/codec/nodeEncoder.ts +14 -18
  276. package/src/feature-libraries/forest-summary/codec.ts +9 -4
  277. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +1 -1
  278. package/src/feature-libraries/schema-index/codec.ts +2 -5
  279. package/src/index.ts +6 -1
  280. package/src/packageVersion.ts +1 -1
  281. package/src/shared-tree/isAuditableFromOutcome.ts +34 -0
  282. package/src/shared-tree/treeCheckout.ts +52 -9
  283. package/src/shared-tree-core/editManagerCodecs.ts +4 -6
  284. package/src/shared-tree-core/messageCodecs.ts +4 -4
  285. package/src/simple-tree/core/treeNodeKernel.ts +27 -13
  286. package/src/text/codePointUtils.ts +81 -0
  287. package/src/text/index.ts +1 -0
  288. package/src/text/textDomain.ts +155 -2
  289. package/src/text/textDomainFormatted.ts +73 -2
  290. package/src/treeFactory.ts +5 -0
  291. package/src/util/breakable.ts +27 -6
@@ -15,16 +15,16 @@ type VersionedJson = JsonCompatibleReadOnlyObject & Versioned;
15
15
  /**
16
16
  * Creates a codec version which always throws a UsageError when encoding or decoding, indicating that the format version is discontinued.
17
17
  */
18
- export declare function makeDiscontinuedCodecAndSchema<TDecoded, TContext, TFormatVersion extends FormatVersion = FormatVersion>(discontinuedVersion: TFormatVersion, discontinuedSince: SemanticVersion): CodecVersion<TDecoded, TContext, TFormatVersion>;
18
+ export declare function makeDiscontinuedCodecAndSchema<TDecoded, TFormatVersion extends FormatVersion = FormatVersion>(discontinuedVersion: TFormatVersion, discontinuedSince: SemanticVersion): CodecVersion<TDecoded, unknown, TFormatVersion, ICodecOptions, unknown>;
19
19
  /**
20
20
  * A friendly format for codec authors use to define their codec and schema for use in {@link CodecVersion}.
21
21
  * @remarks
22
22
  * The codec should not perform its own schema validation.
23
23
  * The schema validation gets added when normalizing to {@link NormalizedCodecVersion}.
24
24
  */
25
- export type CodecAndSchema<TDecoded, TContext = void> = {
25
+ export type CodecAndSchema<TDecoded, TEncodeContext = void, TDecodeContext = TEncodeContext> = {
26
26
  readonly schema: TSchema;
27
- } & IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>;
27
+ } & IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TEncodeContext, TDecodeContext>;
28
28
  /**
29
29
  * A codec alongside its format version and schema.
30
30
  */
@@ -48,7 +48,7 @@ export interface CodecVersionBase<T = unknown, TFormatVersion extends FormatVers
48
48
  * Removing support for this laziness would be nice to help prevent unexpected coupling and alteration to codec behavior,
49
49
  * helping ensure that tests and production code behave the same.
50
50
  */
51
- export interface CodecVersion<TDecoded, TContext, TFormatVersion extends FormatVersion, TBuildOptions extends ICodecOptions = ICodecOptions> extends CodecVersionBase<CodecAndSchema<TDecoded, TContext> | ((options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>), TFormatVersion> {
51
+ export interface CodecVersion<TDecoded, TEncodeContext, TFormatVersion extends FormatVersion, TBuildOptions extends ICodecOptions = ICodecOptions, TDecodeContext = TEncodeContext> extends CodecVersionBase<CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext> | ((options: TBuildOptions) => CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>), TFormatVersion> {
52
52
  }
53
53
  /**
54
54
  * {@link CodecVersion} after normalization into a consistent type.
@@ -56,29 +56,47 @@ export interface CodecVersion<TDecoded, TContext, TFormatVersion extends FormatV
56
56
  * Produced by {@link normalizeCodecVersion}.
57
57
  * Includes schema validation.
58
58
  */
59
- export interface NormalizedCodecVersion<TDecoded, TContext, TFormatVersion extends FormatVersion, TBuildOptions extends ICodecOptions> extends CodecVersionBase<(options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>, TFormatVersion> {
59
+ export interface NormalizedCodecVersion<TDecoded, TEncodeContext, TFormatVersion extends FormatVersion, TBuildOptions extends ICodecOptions, TDecodeContext = TEncodeContext> extends CodecVersionBase<(options: TBuildOptions) => CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>, TFormatVersion> {
60
60
  }
61
61
  /**
62
62
  * {@link NormalizedCodecVersion} after applying the build options.
63
63
  * @remarks
64
- * Produced by {@link ClientVersionDispatchingCodecBuilder.applyOptions}.
64
+ * Produced by {@link VersionDispatchingCodecBuilder.applyOptions}.
65
65
  */
66
- interface EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion extends FormatVersion> extends CodecVersionBase<CodecAndSchema<TDecoded, TContext>, TFormatVersion> {
66
+ interface EvaluatedCodecVersion<TDecoded, TEncodeContext, TFormatVersion extends FormatVersion, TDecodeContext = TEncodeContext> extends CodecVersionBase<CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>, TFormatVersion> {
67
67
  }
68
68
  /**
69
- * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the
70
- * version number in data it encounters for decode.
69
+ * A codec that can read multiple format versions and write a single selected version.
70
+ * @remarks
71
+ * Produced by {@link VersionDispatchingCodecBuilder.build}.
72
+ *
73
+ * @typeParam TDecoded - The in memory (not encoded) format.
74
+ * @typeParam TEncodeContext - Context type passed to encode operations.
75
+ * @typeParam TFormatVersion - The type of format version identifiers used by this codec.
76
+ * @typeParam TDecodeContext - Context type passed to decode operations. Defaults to `TEncodeContext`.
77
+ */
78
+ export interface VersionDispatchingCodec<TDecoded, TEncodeContext, TFormatVersion extends FormatVersion, TDecodeContext = TEncodeContext> extends IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TEncodeContext, TDecodeContext> {
79
+ /**
80
+ * The format version which this codec writes.
81
+ * @remarks
82
+ * Selected by {@link VersionDispatchingCodecBuilder.build} based on the provided options.
83
+ */
84
+ readonly writeVersion: TFormatVersion;
85
+ }
86
+ /**
87
+ * Creates a {@link VersionDispatchingCodec} using a {@link CodecVersion} to select the {@link VersionDispatchingCodec.writeVersion}.
71
88
  * @privateRemarks
72
- * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.
89
+ * This is a two stage builder so the first stage (the static build) can encapsulate all codec specific details and
90
+ * the second (the instance build) can bring in configuration.
73
91
  */
74
- export declare class ClientVersionDispatchingCodecBuilder<TBuildOptions extends ICodecOptions = ICodecOptions, TDecoded = unknown, TContext = unknown, TFormatVersion extends FormatVersion = FormatVersion, TName extends CodecName = string> {
92
+ export declare class VersionDispatchingCodecBuilder<TBuildOptions extends ICodecOptions = ICodecOptions, TDecoded = unknown, TEncodeContext = unknown, TFormatVersion extends FormatVersion = FormatVersion, TName extends CodecName = string, TDecodeContext = TEncodeContext> {
75
93
  /**
76
94
  * See {@link CodecName}.
77
95
  */
78
96
  readonly name: TName;
79
- readonly registry: readonly NormalizedCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>[];
97
+ readonly registry: readonly NormalizedCodecVersion<TDecoded, TEncodeContext, TFormatVersion, TBuildOptions, TDecodeContext>[];
80
98
  /**
81
- * Use {@link ClientVersionDispatchingCodecBuilder.build} to create an instance of this class.
99
+ * Use {@link VersionDispatchingCodecBuilder.build} to create an instance of this class.
82
100
  * @remarks
83
101
  * Inputs to this are assumed to be constants in the code controlled by the developers of this package,
84
102
  * and constructed at least once during tests.
@@ -87,37 +105,47 @@ export declare class ClientVersionDispatchingCodecBuilder<TBuildOptions extends
87
105
  */
88
106
  private constructor();
89
107
  /**
90
- * Applies the provided options to the codec registry to produce a list of evaluated codecs.
108
+ * Applies `options` to the codec registry to produce a list of evaluated codecs.
91
109
  * @remarks
92
110
  * This is used by build, which is what production code should use.
93
111
  * This is only exposed for testing purposes.
94
112
  */
95
- applyOptions(options: TBuildOptions): EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>[];
113
+ applyOptions(options: TBuildOptions): EvaluatedCodecVersion<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>[];
96
114
  /**
97
- * Produce a single codec which can read any supported format, and writes a version selected based on the provided options.
115
+ * Builds a complete {@link VersionDispatchingCodec} that can decode all registered versions
116
+ * and encode a version selected by the provided options.
98
117
  */
99
- build(options: TBuildOptions & CodecWriteOptions): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> & {
100
- /**
101
- * The format version which this codec writes.
102
- * @remarks
103
- * This is selected based on the provided {@link CodecWriteOptions}.
104
- */
105
- readonly writeVersion: TFormatVersion;
106
- };
118
+ build(options: TBuildOptions & CodecWriteOptions): VersionDispatchingCodec<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>;
107
119
  private buildDecoderInternal;
108
120
  /**
109
- * Produce a single codec which can read any supported format.
121
+ * Builds a decoder-only codec that can decode any supported format without encoding capability.
122
+ *
123
+ * @remarks
124
+ * The returned codec contains only the `decode` method and can be used when only decoding is needed.
125
+ * This is useful for scenarios where reading/decoding versioned data is sufficient.
126
+ *
127
+ * @param options - Build options (typically containing the `jsonValidator`)
128
+ * @returns An object with a `decode` method that can handle any supported format version
110
129
  */
111
- buildDecoder(options: TBuildOptions): Pick<IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>, "decode">;
130
+ buildDecoder(options: TBuildOptions): Pick<VersionDispatchingCodec<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>, "decode">;
112
131
  getCodecTree(clientVersion: MinimumVersionForCollab): CodecTree<TFormatVersion>;
113
132
  /**
114
- * Builds a ClientVersionDispatchingCodecBuilder from the provided registry.
133
+ * Creates a new VersionDispatchingCodecBuilder from the provided codec registry.
134
+ *
115
135
  * @remarks
116
136
  * This static method infers the types of the builder from the provided registry,
117
137
  * making it easier to create builders without needing to explicitly specify all type parameters.
118
138
  * This gets better type inference than the constructor.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const builder = VersionDispatchingCodecBuilder.build('myCodec', [
143
+ * { minVersionForCollab: lowestMinVersionForCollab, formatVersion: 1, codec: { encode, decode, schema } },
144
+ * { minVersionForCollab: '2.100.0', formatVersion: 2, codec: { encode, decode, schema } },
145
+ * ]);
146
+ * ```
119
147
  */
120
- static build<Name extends CodecName, Entry extends CodecVersion<unknown, unknown, FormatVersion, never>>(name: Name, inputRegistry: readonly Entry[]): ClientVersionDispatchingCodecBuilder<Entry extends CodecVersion<unknown, unknown, FormatVersion, infer B extends ICodecOptions> ? B : never, Entry extends CodecVersion<infer D, unknown, FormatVersion, never> ? D : never, unknown extends (Entry extends CodecVersion<unknown, infer C, FormatVersion, never> ? C : never) ? void : Entry extends CodecVersion<unknown, infer C, FormatVersion, never> ? C : never, Entry extends CodecVersion<unknown, unknown, infer F extends FormatVersion, never> ? F : never, Name>;
148
+ static build<Name extends CodecName, Entry extends CodecVersion<unknown, unknown, FormatVersion, never, unknown>>(name: Name, inputRegistry: readonly Entry[]): VersionDispatchingCodecBuilder<Entry extends CodecVersion<unknown, unknown, FormatVersion, infer B extends ICodecOptions, unknown> ? B : never, Entry extends CodecVersion<infer D, unknown, FormatVersion, never, unknown> ? D : never, unknown extends (Entry extends CodecVersion<unknown, infer C, FormatVersion, never, unknown> ? C : never) ? void : Entry extends CodecVersion<unknown, infer C, FormatVersion, never, unknown> ? C : never, Entry extends CodecVersion<unknown, unknown, infer F extends FormatVersion, never, unknown> ? F : never, Name, unknown extends (Entry extends CodecVersion<unknown, unknown, FormatVersion, never, infer D_1> ? D_1 : never) ? unknown extends (Entry extends CodecVersion<unknown, infer C, FormatVersion, never, unknown> ? C : never) ? void : Entry extends CodecVersion<unknown, infer C, FormatVersion, never, unknown> ? C : never : Entry extends CodecVersion<unknown, unknown, FormatVersion, never, infer D_1> ? D_1 : never>;
121
149
  }
122
150
  export {};
123
151
  //# sourceMappingURL=codec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/codec/versioned/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAIN,KAAK,eAAe,EACpB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,UAAU,EAEf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,KAAK,aAAa,GAAG,4BAA4B,GAAG,SAAS,CAAC;AA8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ensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ClientVersionDispatchingCodecBuilder = exports.makeDiscontinuedCodecAndSchema = void 0;
7
+ exports.VersionDispatchingCodecBuilder = exports.makeDiscontinuedCodecAndSchema = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/runtime-utils/internal");
10
10
  const internal_3 = require("@fluidframework/telemetry-utils/internal");
@@ -94,14 +94,14 @@ function normalizeCodecVersion(codecVersion) {
94
94
  };
95
95
  }
96
96
  /**
97
- * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the
98
- * version number in data it encounters for decode.
97
+ * Creates a {@link VersionDispatchingCodec} using a {@link CodecVersion} to select the {@link VersionDispatchingCodec.writeVersion}.
99
98
  * @privateRemarks
100
- * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.
99
+ * This is a two stage builder so the first stage (the static build) can encapsulate all codec specific details and
100
+ * the second (the instance build) can bring in configuration.
101
101
  */
102
- class ClientVersionDispatchingCodecBuilder {
102
+ class VersionDispatchingCodecBuilder {
103
103
  /**
104
- * Use {@link ClientVersionDispatchingCodecBuilder.build} to create an instance of this class.
104
+ * Use {@link VersionDispatchingCodecBuilder.build} to create an instance of this class.
105
105
  * @remarks
106
106
  * Inputs to this are assumed to be constants in the code controlled by the developers of this package,
107
107
  * and constructed at least once during tests.
@@ -141,7 +141,7 @@ class ClientVersionDispatchingCodecBuilder {
141
141
  this.registry = normalizedRegistry;
142
142
  }
143
143
  /**
144
- * Applies the provided options to the codec registry to produce a list of evaluated codecs.
144
+ * Applies `options` to the codec registry to produce a list of evaluated codecs.
145
145
  * @remarks
146
146
  * This is used by build, which is what production code should use.
147
147
  * This is only exposed for testing purposes.
@@ -154,7 +154,8 @@ class ClientVersionDispatchingCodecBuilder {
154
154
  }));
155
155
  }
156
156
  /**
157
- * Produce a single codec which can read any supported format, and writes a version selected based on the provided options.
157
+ * Builds a complete {@link VersionDispatchingCodec} that can decode all registered versions
158
+ * and encode a version selected by the provided options.
158
159
  */
159
160
  build(options) {
160
161
  const [applied, decoder] = this.buildDecoderInternal(options);
@@ -186,7 +187,14 @@ The client which encoded this data likely specified an "minVersionForCollab" val
186
187
  ];
187
188
  }
188
189
  /**
189
- * Produce a single codec which can read any supported format.
190
+ * Builds a decoder-only codec that can decode any supported format without encoding capability.
191
+ *
192
+ * @remarks
193
+ * The returned codec contains only the `decode` method and can be used when only decoding is needed.
194
+ * This is useful for scenarios where reading/decoding versioned data is sufficient.
195
+ *
196
+ * @param options - Build options (typically containing the `jsonValidator`)
197
+ * @returns An object with a `decode` method that can handle any supported format version
190
198
  */
191
199
  buildDecoder(options) {
192
200
  return this.buildDecoderInternal(options)[1];
@@ -200,20 +208,29 @@ The client which encoded this data likely specified an "minVersionForCollab" val
200
208
  };
201
209
  }
202
210
  /**
203
- * Builds a ClientVersionDispatchingCodecBuilder from the provided registry.
211
+ * Creates a new VersionDispatchingCodecBuilder from the provided codec registry.
212
+ *
204
213
  * @remarks
205
214
  * This static method infers the types of the builder from the provided registry,
206
215
  * making it easier to create builders without needing to explicitly specify all type parameters.
207
216
  * This gets better type inference than the constructor.
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const builder = VersionDispatchingCodecBuilder.build('myCodec', [
221
+ * { minVersionForCollab: lowestMinVersionForCollab, formatVersion: 1, codec: { encode, decode, schema } },
222
+ * { minVersionForCollab: '2.100.0', formatVersion: 2, codec: { encode, decode, schema } },
223
+ * ]);
224
+ * ```
208
225
  */
209
226
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
210
227
  static build(name, inputRegistry) {
211
228
  const input = inputRegistry;
212
- const builder = new ClientVersionDispatchingCodecBuilder(name, input);
229
+ const builder = new VersionDispatchingCodecBuilder(name, input);
213
230
  return builder;
214
231
  }
215
232
  }
216
- exports.ClientVersionDispatchingCodecBuilder = ClientVersionDispatchingCodecBuilder;
233
+ exports.VersionDispatchingCodecBuilder = VersionDispatchingCodecBuilder;
217
234
  /**
218
235
  * Selects which format should be used when writing data.
219
236
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/codec/versioned/codec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA0E;AAE1E,qEAKgD;AAChD,uEAAsE;AAEtE,yCAA+B;AAE/B,+DAAqD;AACrD,kDAI6B;AAC7B,0CAQqB;AAErB,2CAAwC;AAOxC;;;;;GAKG;AACH,SAAS,kBAAkB,CAM1B,iBAAqC,EACrC,EAAE,aAAa,EAAE,SAAS,EAAiB,EAC3C,KAA0D;IAE1D,MAAM,KAAK,GAAG;QACb,MAAM,EAAE,CAAC,IAAc,EAAE,OAAiB,EAAY,EAAE;YACvD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,IAAA,iBAAM,EACL,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EACtC,KAAK,CAAC,+CAA+C,CACrD,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,IAAe,EAAE,OAAiB,EAAY,EAAE;YACxD,MAAM,SAAS,GAAG,IAAiB,CAAC,CAAC,oCAAoC;YACzE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,MAAM,IAAI,qBAAU,CACnB,uBAAuB,SAAS,CAAC,OAAO,2EAA2E,CAAC,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;4JACG,8BAAU,KAAK,CACtK,CAAC;YACH,CAAC;YACD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;IAEF,4GAA4G;IAC5G,wIAAwI;IACx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F,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,OAAO,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAClC,QAAsB,EACtB,mBAA4C;IAE5C,MAAM,cAAc,GAAiE,EAAE,CAAC;IACxF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,IAAI,OAAO,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC/C,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAM,IAAA,kDAAuC,EACxD,mBAAmB,EACnB,cAAc,CACd,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,QAAqC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollabIterable,\n\tlowestMinVersionForCollab,\n\ttype MinimumMinorSemanticVersion,\n\ttype SemanticVersion,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { gt } from \"semver-ts\";\n\nimport { pkgVersion } from \"../../packageVersion.js\";\nimport {\n\tJsonCompatibleReadOnlySchema,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n} from \"../../util/index.js\";\nimport {\n\ttype ICodecOptions,\n\ttype IJsonCodec,\n\twithSchemaValidation,\n\ttype FormatVersion,\n\ttype CodecWriteOptions,\n\ttype CodecName,\n\ttype CodecTree,\n} from \"../codec.js\";\n\nimport { Versioned } from \"./format.js\";\n\n/**\n * Json compatible data with a format version.\n */\ntype VersionedJson = JsonCompatibleReadOnlyObject & Versioned;\n\n/**\n * Validate that the version is one of the supported values.\n * @remarks\n * If supportedVersions contains undefined, data with no version field is also accepted despite the return type indicating otherwise.\n * This is for legacy compatibility where older data may not have a version field.\n */\nfunction makeVersionedCodec<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\tsupportedVersions: Set<FormatVersion>,\n\t{ jsonValidator: validator }: ICodecOptions,\n\tinner: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> {\n\tconst codec = {\n\t\tencode: (data: TDecoded, context: TContext): TEncoded => {\n\t\t\tconst encoded = inner.encode(data, context);\n\t\t\tassert(\n\t\t\t\tsupportedVersions.has(encoded.version),\n\t\t\t\t0x88b /* version being encoded should be supported */,\n\t\t\t);\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: TValidate, context: TContext): TDecoded => {\n\t\t\tconst versioned = data as Versioned; // Validated by withSchemaValidation\n\t\t\tif (!supportedVersions.has(versioned.version)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding data. Supported versions for this data are: ${[...supportedVersions].join(\", \")}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = inner.decode(data, context);\n\t\t\treturn decoded;\n\t\t},\n\t};\n\n\t// If undefined is a supported version, skip using withSchemaValidation to enforce there is a version field.\n\t// Codec will still assert the content of the field is in supportedVersions, so it is still somewhat validated, just in a different way.\n\tif (supportedVersions.has(undefined)) {\n\t\treturn codec;\n\t}\n\n\treturn withSchemaValidation(Versioned, codec, validator);\n}\n\n/**\n * Wrap a codec with version checking and schema validation.\n * @remarks\n * The passed in codec should not perform its own schema validation.\n * The schema validation gets added here.\n */\nfunction makeVersionedValidatedCodec<\n\tEncodedSchema extends TSchema,\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\toptions: ICodecOptions,\n\tsupportedVersions: Set<FormatVersion>,\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> &\n\tPick<CodecAndSchema<TDecoded, TContext>, \"schema\"> {\n\treturn {\n\t\t...makeVersionedCodec(\n\t\t\tsupportedVersions,\n\t\t\toptions,\n\t\t\twithSchemaValidation(schema, codec, options.jsonValidator),\n\t\t),\n\t\tschema,\n\t};\n}\n\n/**\n * Creates a codec version which always throws a UsageError when encoding or decoding, indicating that the format version is discontinued.\n */\nexport function makeDiscontinuedCodecAndSchema<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n>(\n\tdiscontinuedVersion: TFormatVersion,\n\tdiscontinuedSince: SemanticVersion,\n): CodecVersion<TDecoded, TContext, TFormatVersion> {\n\treturn {\n\t\tminVersionForCollab: undefined,\n\t\tformatVersion: discontinuedVersion,\n\t\tcodec: {\n\t\t\tschema: JsonCompatibleReadOnlySchema,\n\t\t\tencode: (_data: TDecoded) => {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Cannot encode data to format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tdecode: (data: unknown) => {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Cannot decode data in format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * A friendly format for codec authors use to define their codec and schema for use in {@link CodecVersion}.\n * @remarks\n * The codec should not perform its own schema validation.\n * The schema validation gets added when normalizing to {@link NormalizedCodecVersion}.\n */\nexport type CodecAndSchema<TDecoded, TContext = void> = {\n\treadonly schema: TSchema;\n} & IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>;\n\n/**\n * A codec alongside its format version and schema.\n */\nexport interface CodecVersionBase<\n\tT = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n> {\n\t/**\n\t * When `undefined` the codec will never be selected as a write version except via override.\n\t * @remarks\n\t * This format will be used for decode if data in it needs to be decoded, regardless of `minVersionForCollab`.\n\t * `undefined` should be used for unstable codec versions (with string FormatVersions),\n\t * as well as previously stabilized formats that are discontinued (meaning we always prefer to use some other format for encoding).\n\t */\n\treadonly minVersionForCollab: MinimumVersionForCollab | undefined;\n\treadonly formatVersion: TFormatVersion;\n\treadonly codec: T;\n}\n\n/**\n * A particular version of a codec and when to use it.\n * @privateRemarks\n * This allows lazy building of the codec with options.\n * This option can likely be removed as the codec handling is made simpler and more consistent.\n * Removing support for this laziness would be nice to help prevent unexpected coupling and alteration to codec behavior,\n * helping ensure that tests and production code behave the same.\n */\nexport interface CodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions = ICodecOptions,\n> extends CodecVersionBase<\n\t\t| CodecAndSchema<TDecoded, TContext>\n\t\t| ((options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>),\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link CodecVersion} after normalization into a consistent type.\n * @remarks\n * Produced by {@link normalizeCodecVersion}.\n * Includes schema validation.\n */\nexport interface NormalizedCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions,\n> extends CodecVersionBase<\n\t\t(options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link NormalizedCodecVersion} after applying the build options.\n * @remarks\n * Produced by {@link ClientVersionDispatchingCodecBuilder.applyOptions}.\n */\ninterface EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion extends FormatVersion>\n\textends CodecVersionBase<CodecAndSchema<TDecoded, TContext>, TFormatVersion> {}\n\n/**\n * Normalize the codec to a single format.\n * @remarks\n * Bakes in schema validation, so output no longer exposes the schema.\n */\nfunction normalizeCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions,\n>(\n\tcodecVersion: CodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>,\n): NormalizedCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions> {\n\tconst codecBuilder: (options: TBuildOptions) => CodecAndSchema<TDecoded, TContext> =\n\t\ttypeof codecVersion.codec === \"function\"\n\t\t\t? codecVersion.codec\n\t\t\t: () => codecVersion.codec as CodecAndSchema<TDecoded, TContext>;\n\tconst codec = (options: TBuildOptions): CodecAndSchema<TDecoded, TContext> => {\n\t\tconst built = codecBuilder(options);\n\t\treturn makeVersionedValidatedCodec(\n\t\t\toptions,\n\t\t\tnew Set([codecVersion.formatVersion]),\n\t\t\tbuilt.schema,\n\t\t\tbuilt,\n\t\t);\n\t};\n\n\treturn {\n\t\tminVersionForCollab: codecVersion.minVersionForCollab,\n\t\tformatVersion: codecVersion.formatVersion,\n\t\tcodec,\n\t};\n}\n\n/**\n * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the\n * version number in data it encounters for decode.\n * @privateRemarks\n * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.\n */\nexport class ClientVersionDispatchingCodecBuilder<\n\tTBuildOptions extends ICodecOptions = ICodecOptions,\n\tTDecoded = unknown,\n\tTContext = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n\tTName extends CodecName = string,\n> {\n\tpublic readonly registry: readonly NormalizedCodecVersion<\n\t\tTDecoded,\n\t\tTContext,\n\t\tTFormatVersion,\n\t\tTBuildOptions\n\t>[];\n\n\t/**\n\t * Use {@link ClientVersionDispatchingCodecBuilder.build} to create an instance of this class.\n\t * @remarks\n\t * Inputs to this are assumed to be constants in the code controlled by the developers of this package,\n\t * and constructed at least once during tests.\n\t * Because of this, the validation of these inputs done with debugAssert should be sufficient,\n\t * and using debugAssert avoids bloating the bundle size for production users.\n\t */\n\tprivate constructor(\n\t\t/**\n\t\t * See {@link CodecName}.\n\t\t */\n\t\tpublic readonly name: TName,\n\t\t/**\n\t\t * The registry of codecs which this builder can use to encode and decode data.\n\t\t */\n\t\tinputRegistry: readonly CodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>[],\n\t) {\n\t\ttype Normalized = NormalizedCodecVersion<\n\t\t\tTDecoded,\n\t\t\tTContext,\n\t\t\tTFormatVersion,\n\t\t\tTBuildOptions\n\t\t>;\n\t\tconst normalizedRegistry: Normalized[] = [];\n\t\tconst formats: Set<FormatVersion> = new Set();\n\t\tconst versions: Set<string | undefined> = new Set();\n\n\t\tfor (const codec of inputRegistry) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\t!formats.has(codec.formatVersion) ||\n\t\t\t\t\t`duplicate codec format ${name} ${codec.formatVersion}`,\n\t\t\t);\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tcodec.minVersionForCollab === undefined ||\n\t\t\t\t\ttypeof codec.formatVersion !== \"string\" ||\n\t\t\t\t\t`unstable format ${JSON.stringify(codec.formatVersion)} (string formats) must not have a minVersionForCollab in ${name}`,\n\t\t\t);\n\t\t\tformats.add(codec.formatVersion);\n\t\t\tconst normalizedCodec = normalizeCodecVersion(codec);\n\t\t\tnormalizedRegistry.push(normalizedCodec);\n\t\t\tif (codec.minVersionForCollab !== undefined) {\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\t!versions.has(codec.minVersionForCollab) ||\n\t\t\t\t\t\t`Codec ${name} has multiple entries for version ${JSON.stringify(codec.minVersionForCollab)}`,\n\t\t\t\t);\n\t\t\t\tversions.add(codec.minVersionForCollab);\n\t\t\t}\n\t\t}\n\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tversions.has(lowestMinVersionForCollab) ||\n\t\t\t\t`Codec ${name} is missing entry for lowestMinVersionForCollab`,\n\t\t);\n\n\t\tthis.registry = normalizedRegistry;\n\t}\n\n\t/**\n\t * Applies the provided options to the codec registry to produce a list of evaluated codecs.\n\t * @remarks\n\t * This is used by build, which is what production code should use.\n\t * This is only exposed for testing purposes.\n\t */\n\tpublic applyOptions(\n\t\toptions: TBuildOptions,\n\t): EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>[] {\n\t\treturn this.registry.map((codec) => ({\n\t\t\tminVersionForCollab: codec.minVersionForCollab,\n\t\t\tformatVersion: codec.formatVersion,\n\t\t\tcodec: codec.codec(options),\n\t\t}));\n\t}\n\n\t/**\n\t * Produce a single codec which can read any supported format, and writes a version selected based on the provided options.\n\t */\n\tpublic build(options: TBuildOptions & CodecWriteOptions): IJsonCodec<\n\t\tTDecoded,\n\t\tJsonCompatibleReadOnly,\n\t\tJsonCompatibleReadOnly,\n\t\tTContext\n\t> & {\n\t\t/**\n\t\t * The format version which this codec writes.\n\t\t * @remarks\n\t\t * This is selected based on the provided {@link CodecWriteOptions}.\n\t\t */\n\t\treadonly writeVersion: TFormatVersion;\n\t} {\n\t\tconst [applied, decoder] = this.buildDecoderInternal(options);\n\t\tconst writeVersion = getWriteVersion(this.name, options, applied);\n\t\treturn {\n\t\t\t...decoder,\n\t\t\tencode: (data: TDecoded, context: TContext): JsonCompatibleReadOnly => {\n\t\t\t\treturn writeVersion.codec.encode(data, context);\n\t\t\t},\n\t\t\twriteVersion: writeVersion.formatVersion,\n\t\t};\n\t}\n\n\tprivate buildDecoderInternal(\n\t\toptions: TBuildOptions,\n\t): [\n\t\tEvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>[],\n\t\tPick<\n\t\t\tIJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n\t\t\t\"decode\"\n\t\t>,\n\t] {\n\t\tconst applied = this.applyOptions(options);\n\t\tconst fromFormatVersion = new Map<\n\t\t\tFormatVersion,\n\t\t\tEvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>\n\t\t>(applied.map((codec) => [codec.formatVersion, codec]));\n\t\treturn [\n\t\t\tapplied,\n\t\t\t{\n\t\t\t\tdecode: (data: JsonCompatibleReadOnly, context: TContext): TDecoded => {\n\t\t\t\t\tconst versioned = data as Partial<Versioned>;\n\t\t\t\t\tconst codec = fromFormatVersion.get(versioned.version);\n\t\t\t\t\tif (codec === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding ${this.name} data. Supported versions for this data are: ${versionList(applied)}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn codec.codec.decode(data, context);\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Produce a single codec which can read any supported format.\n\t */\n\tpublic buildDecoder(\n\t\toptions: TBuildOptions,\n\t): Pick<\n\t\tIJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n\t\t\"decode\"\n\t> {\n\t\treturn this.buildDecoderInternal(options)[1];\n\t}\n\n\tpublic getCodecTree(clientVersion: MinimumVersionForCollab): CodecTree<TFormatVersion> {\n\t\t// TODO: add support for children codecs.\n\t\tconst selected = getWriteVersionNoOverrides(this.registry, clientVersion);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tversion: selected.formatVersion,\n\t\t};\n\t}\n\n\t/**\n\t * Builds a ClientVersionDispatchingCodecBuilder from the provided registry.\n\t * @remarks\n\t * This static method infers the types of the builder from the provided registry,\n\t * making it easier to create builders without needing to explicitly specify all type parameters.\n\t * This gets better type inference than the constructor.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic static build<\n\t\tName extends CodecName,\n\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, never>,\n\t>(name: Name, inputRegistry: readonly Entry[]) {\n\t\ttype TDecoded2 =\n\t\t\tEntry extends CodecVersion<infer D, unknown, FormatVersion, never> ? D : never;\n\t\ttype TContext2 =\n\t\t\tEntry extends CodecVersion<unknown, infer C, FormatVersion, never> ? C : never;\n\t\ttype TFormatVersion2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, infer F, never> ? F : never;\n\t\ttype TBuildOptions2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, infer B> ? B : never;\n\n\t\ttype CodecFinal = CodecVersion<\n\t\t\tTDecoded2,\n\t\t\t// If it does not matter what context is provided, undefined is fine, so allow it to be omitted.\n\t\t\tunknown extends TContext2 ? void : TContext2,\n\t\t\tTFormatVersion2,\n\t\t\tTBuildOptions2\n\t\t>;\n\n\t\tconst input = inputRegistry as readonly unknown[] as readonly CodecFinal[];\n\n\t\tconst builder = new ClientVersionDispatchingCodecBuilder<\n\t\t\tTBuildOptions2,\n\t\t\tTDecoded2,\n\t\t\tunknown extends TContext2 ? void : TContext2,\n\t\t\tTFormatVersion2,\n\t\t\tName\n\t\t>(name, input);\n\t\treturn builder;\n\t}\n}\n\n/**\n * Selects which format should be used when writing data.\n * @remarks\n * This either uses the override specified in the options, or selects the newest format compatible with the provided minVersionForCollab.\n */\nfunction getWriteVersion<T extends CodecVersionBase>(\n\tname: CodecName,\n\toptions: CodecWriteOptions,\n\tversions: readonly T[],\n): T {\n\tif (options.writeVersionOverrides?.has(name) === true) {\n\t\tconst selectedFormatVersion = options.writeVersionOverrides.get(name);\n\t\tconst selected = versions.find((codec) => codec.formatVersion === selectedFormatVersion);\n\t\tif (selected === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)}. Supported versions are: ${versionList(versions)}.`,\n\t\t\t);\n\t\t} else if (options.allowPossiblyIncompatibleWriteVersionOverrides !== true) {\n\t\t\tconst selectedMinVersionForCollab = selected.minVersionForCollab;\n\t\t\tif (selectedMinVersionForCollab === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it has minVersionForCollab undefined. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t} else if (gt(selectedMinVersionForCollab, options.minVersionForCollab)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it is only compatible back to client version ${selectedMinVersionForCollab} and the requested oldest compatible client was ${options.minVersionForCollab}. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn selected;\n\t}\n\n\treturn getWriteVersionNoOverrides(versions, options.minVersionForCollab);\n}\n\n/**\n * Selects which format should be used when writing data, without consider overrides.\n */\nfunction getWriteVersionNoOverrides<T extends CodecVersionBase>(\n\tversions: readonly T[],\n\tminVersionForCollab: MinimumVersionForCollab,\n): T {\n\tconst stableVersions: [MinimumMinorSemanticVersion | MinimumVersionForCollab, T][] = [];\n\tfor (const version of versions) {\n\t\tif (version.minVersionForCollab !== undefined) {\n\t\t\tstableVersions.push([version.minVersionForCollab, version]);\n\t\t}\n\t}\n\n\tconst result: T = getConfigForMinVersionForCollabIterable(\n\t\tminVersionForCollab,\n\t\tstableVersions,\n\t);\n\treturn result;\n}\n\n/**\n * Formats a list of versions for use in UsageErrors.\n */\nfunction versionList(versions: readonly CodecVersionBase[]): string {\n\treturn JSON.stringify(Array.from(versions, (codec) => codec.formatVersion));\n}\n"]}
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/codec/versioned/codec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA0E;AAE1E,qEAKgD;AAChD,uEAAsE;AAEtE,yCAA+B;AAE/B,+DAAqD;AACrD,kDAI6B;AAC7B,0CAQqB;AAErB,2CAAwC;AAOxC;;;;;GAKG;AACH,SAAS,kBAAkB,CAO1B,iBAAqC,EACrC,EAAE,aAAa,EAAE,SAAS,EAAiB,EAC3C,KAAgF;IAEhF,MAAM,KAAK,GAAG;QACb,MAAM,EAAE,CAAC,IAAc,EAAE,OAAuB,EAAY,EAAE;YAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,IAAA,iBAAM,EACL,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EACtC,KAAK,CAAC,+CAA+C,CACrD,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,IAAe,EAAE,OAAuB,EAAY,EAAE;YAC9D,MAAM,SAAS,GAAG,IAAiB,CAAC,CAAC,oCAAoC;YACzE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,MAAM,IAAI,qBAAU,CACnB,uBAAuB,SAAS,CAAC,OAAO,2EAA2E,CAAC,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;4JACG,8BAAU,KAAK,CACtK,CAAC;YACH,CAAC;YACD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;IAEF,4GAA4G;IAC5G,wIAAwI;IACxI,IAAI,iBAAiB,CAA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F,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,OAAO,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAClC,QAAsB,EACtB,mBAA4C;IAE5C,MAAM,cAAc,GAAiE,EAAE,CAAC;IACxF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,IAAI,OAAO,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC/C,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAM,IAAA,kDAAuC,EACxD,mBAAmB,EACnB,cAAc,CACd,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,QAAqC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollabIterable,\n\tlowestMinVersionForCollab,\n\ttype MinimumMinorSemanticVersion,\n\ttype SemanticVersion,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { gt } from \"semver-ts\";\n\nimport { pkgVersion } from \"../../packageVersion.js\";\nimport {\n\tJsonCompatibleReadOnlySchema,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n} from \"../../util/index.js\";\nimport {\n\ttype ICodecOptions,\n\ttype IJsonCodec,\n\twithSchemaValidation,\n\ttype FormatVersion,\n\ttype CodecWriteOptions,\n\ttype CodecName,\n\ttype CodecTree,\n} from \"../codec.js\";\n\nimport { Versioned } from \"./format.js\";\n\n/**\n * Json compatible data with a format version.\n */\ntype VersionedJson = JsonCompatibleReadOnlyObject & Versioned;\n\n/**\n * Validate that the version is one of the supported values.\n * @remarks\n * If supportedVersions contains undefined, data with no version field is also accepted despite the return type indicating otherwise.\n * This is for legacy compatibility where older data may not have a version field.\n */\nfunction makeVersionedCodec<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTEncodeContext = void,\n\tTDecodeContext = TEncodeContext,\n>(\n\tsupportedVersions: Set<FormatVersion>,\n\t{ jsonValidator: validator }: ICodecOptions,\n\tinner: IJsonCodec<TDecoded, TEncoded, TValidate, TEncodeContext, TDecodeContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TEncodeContext, TDecodeContext> {\n\tconst codec = {\n\t\tencode: (data: TDecoded, context: TEncodeContext): TEncoded => {\n\t\t\tconst encoded = inner.encode(data, context);\n\t\t\tassert(\n\t\t\t\tsupportedVersions.has(encoded.version),\n\t\t\t\t0x88b /* version being encoded should be supported */,\n\t\t\t);\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: TValidate, context: TDecodeContext): TDecoded => {\n\t\t\tconst versioned = data as Versioned; // Validated by withSchemaValidation\n\t\t\tif (!supportedVersions.has(versioned.version)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding data. Supported versions for this data are: ${[...supportedVersions].join(\", \")}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = inner.decode(data, context);\n\t\t\treturn decoded;\n\t\t},\n\t};\n\n\t// If undefined is a supported version, skip using withSchemaValidation to enforce there is a version field.\n\t// Codec will still assert the content of the field is in supportedVersions, so it is still somewhat validated, just in a different way.\n\tif (supportedVersions.has(undefined)) {\n\t\treturn codec;\n\t}\n\n\treturn withSchemaValidation(Versioned, codec, validator);\n}\n\n/**\n * Wrap a codec with version checking and schema validation.\n * @remarks\n * The passed in codec should not perform its own schema validation.\n * The schema validation gets added here.\n */\nfunction makeVersionedValidatedCodec<\n\tEncodedSchema extends TSchema,\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTEncodeContext = void,\n\tTDecodeContext = TEncodeContext,\n>(\n\toptions: ICodecOptions,\n\tsupportedVersions: Set<FormatVersion>,\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TDecoded, TEncoded, TValidate, TEncodeContext, TDecodeContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TEncodeContext, TDecodeContext> &\n\tPick<CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>, \"schema\"> {\n\treturn {\n\t\t...makeVersionedCodec(\n\t\t\tsupportedVersions,\n\t\t\toptions,\n\t\t\twithSchemaValidation(schema, codec, options.jsonValidator),\n\t\t),\n\t\tschema,\n\t};\n}\n\n/**\n * Creates a codec version which always throws a UsageError when encoding or decoding, indicating that the format version is discontinued.\n */\nexport function makeDiscontinuedCodecAndSchema<\n\tTDecoded,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n>(\n\tdiscontinuedVersion: TFormatVersion,\n\tdiscontinuedSince: SemanticVersion,\n): CodecVersion<TDecoded, unknown, TFormatVersion, ICodecOptions, unknown> {\n\treturn {\n\t\tminVersionForCollab: undefined,\n\t\tformatVersion: discontinuedVersion,\n\t\tcodec: {\n\t\t\tschema: JsonCompatibleReadOnlySchema,\n\t\t\tencode: (_data: TDecoded) => {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Cannot encode data to format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tdecode: (data: unknown) => {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Cannot decode data in format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * A friendly format for codec authors use to define their codec and schema for use in {@link CodecVersion}.\n * @remarks\n * The codec should not perform its own schema validation.\n * The schema validation gets added when normalizing to {@link NormalizedCodecVersion}.\n */\nexport type CodecAndSchema<\n\tTDecoded,\n\tTEncodeContext = void,\n\tTDecodeContext = TEncodeContext,\n> = {\n\treadonly schema: TSchema;\n} & IJsonCodec<\n\tTDecoded,\n\tVersionedJson,\n\tJsonCompatibleReadOnly,\n\tTEncodeContext,\n\tTDecodeContext\n>;\n\n/**\n * A codec alongside its format version and schema.\n */\nexport interface CodecVersionBase<\n\tT = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n> {\n\t/**\n\t * When `undefined` the codec will never be selected as a write version except via override.\n\t * @remarks\n\t * This format will be used for decode if data in it needs to be decoded, regardless of `minVersionForCollab`.\n\t * `undefined` should be used for unstable codec versions (with string FormatVersions),\n\t * as well as previously stabilized formats that are discontinued (meaning we always prefer to use some other format for encoding).\n\t */\n\treadonly minVersionForCollab: MinimumVersionForCollab | undefined;\n\treadonly formatVersion: TFormatVersion;\n\treadonly codec: T;\n}\n\n/**\n * A particular version of a codec and when to use it.\n * @privateRemarks\n * This allows lazy building of the codec with options.\n * This option can likely be removed as the codec handling is made simpler and more consistent.\n * Removing support for this laziness would be nice to help prevent unexpected coupling and alteration to codec behavior,\n * helping ensure that tests and production code behave the same.\n */\nexport interface CodecVersion<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions = ICodecOptions,\n\tTDecodeContext = TEncodeContext,\n> extends CodecVersionBase<\n\t\t| CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>\n\t\t| ((options: TBuildOptions) => CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>),\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link CodecVersion} after normalization into a consistent type.\n * @remarks\n * Produced by {@link normalizeCodecVersion}.\n * Includes schema validation.\n */\nexport interface NormalizedCodecVersion<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions,\n\tTDecodeContext = TEncodeContext,\n> extends CodecVersionBase<\n\t\t(options: TBuildOptions) => CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link NormalizedCodecVersion} after applying the build options.\n * @remarks\n * Produced by {@link VersionDispatchingCodecBuilder.applyOptions}.\n */\ninterface EvaluatedCodecVersion<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion extends FormatVersion,\n\tTDecodeContext = TEncodeContext,\n> extends CodecVersionBase<\n\t\tCodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * Normalize the codec to a single format.\n * @remarks\n * Bakes in schema validation, so output no longer exposes the schema.\n */\nfunction normalizeCodecVersion<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends ICodecOptions,\n\tTDecodeContext = TEncodeContext,\n>(\n\tcodecVersion: CodecVersion<\n\t\tTDecoded,\n\t\tTEncodeContext,\n\t\tTFormatVersion,\n\t\tTBuildOptions,\n\t\tTDecodeContext\n\t>,\n): NormalizedCodecVersion<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion,\n\tTBuildOptions,\n\tTDecodeContext\n> {\n\tconst codecBuilder: (\n\t\toptions: TBuildOptions,\n\t) => CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext> =\n\t\ttypeof codecVersion.codec === \"function\"\n\t\t\t? codecVersion.codec\n\t\t\t: () => codecVersion.codec as CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext>;\n\tconst codec = (\n\t\toptions: TBuildOptions,\n\t): CodecAndSchema<TDecoded, TEncodeContext, TDecodeContext> => {\n\t\tconst built = codecBuilder(options);\n\t\treturn makeVersionedValidatedCodec(\n\t\t\toptions,\n\t\t\tnew Set([codecVersion.formatVersion]),\n\t\t\tbuilt.schema,\n\t\t\tbuilt,\n\t\t);\n\t};\n\n\treturn {\n\t\tminVersionForCollab: codecVersion.minVersionForCollab,\n\t\tformatVersion: codecVersion.formatVersion,\n\t\tcodec,\n\t};\n}\n\n/**\n * A codec that can read multiple format versions and write a single selected version.\n * @remarks\n * Produced by {@link VersionDispatchingCodecBuilder.build}.\n *\n * @typeParam TDecoded - The in memory (not encoded) format.\n * @typeParam TEncodeContext - Context type passed to encode operations.\n * @typeParam TFormatVersion - The type of format version identifiers used by this codec.\n * @typeParam TDecodeContext - Context type passed to decode operations. Defaults to `TEncodeContext`.\n */\nexport interface VersionDispatchingCodec<\n\tTDecoded,\n\tTEncodeContext,\n\tTFormatVersion extends FormatVersion,\n\tTDecodeContext = TEncodeContext,\n> extends IJsonCodec<\n\t\tTDecoded,\n\t\tJsonCompatibleReadOnly,\n\t\tJsonCompatibleReadOnly,\n\t\tTEncodeContext,\n\t\tTDecodeContext\n\t> {\n\t/**\n\t * The format version which this codec writes.\n\t * @remarks\n\t * Selected by {@link VersionDispatchingCodecBuilder.build} based on the provided options.\n\t */\n\treadonly writeVersion: TFormatVersion;\n}\n\n/**\n * Creates a {@link VersionDispatchingCodec} using a {@link CodecVersion} to select the {@link VersionDispatchingCodec.writeVersion}.\n * @privateRemarks\n * This is a two stage builder so the first stage (the static build) can encapsulate all codec specific details and\n * the second (the instance build) can bring in configuration.\n */\nexport class VersionDispatchingCodecBuilder<\n\tTBuildOptions extends ICodecOptions = ICodecOptions,\n\tTDecoded = unknown,\n\tTEncodeContext = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n\tTName extends CodecName = string,\n\tTDecodeContext = TEncodeContext,\n> {\n\tpublic readonly registry: readonly NormalizedCodecVersion<\n\t\tTDecoded,\n\t\tTEncodeContext,\n\t\tTFormatVersion,\n\t\tTBuildOptions,\n\t\tTDecodeContext\n\t>[];\n\n\t/**\n\t * Use {@link VersionDispatchingCodecBuilder.build} to create an instance of this class.\n\t * @remarks\n\t * Inputs to this are assumed to be constants in the code controlled by the developers of this package,\n\t * and constructed at least once during tests.\n\t * Because of this, the validation of these inputs done with debugAssert should be sufficient,\n\t * and using debugAssert avoids bloating the bundle size for production users.\n\t */\n\tprivate constructor(\n\t\t/**\n\t\t * See {@link CodecName}.\n\t\t */\n\t\tpublic readonly name: TName,\n\t\t/**\n\t\t * The registry of codecs which this builder can use to encode and decode data.\n\t\t */\n\t\tinputRegistry: readonly CodecVersion<\n\t\t\tTDecoded,\n\t\t\tTEncodeContext,\n\t\t\tTFormatVersion,\n\t\t\tTBuildOptions,\n\t\t\tTDecodeContext\n\t\t>[],\n\t) {\n\t\ttype Normalized = NormalizedCodecVersion<\n\t\t\tTDecoded,\n\t\t\tTEncodeContext,\n\t\t\tTFormatVersion,\n\t\t\tTBuildOptions,\n\t\t\tTDecodeContext\n\t\t>;\n\t\tconst normalizedRegistry: Normalized[] = [];\n\t\tconst formats: Set<FormatVersion> = new Set();\n\t\tconst versions: Set<string | undefined> = new Set();\n\n\t\tfor (const codec of inputRegistry) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\t!formats.has(codec.formatVersion) ||\n\t\t\t\t\t`duplicate codec format ${name} ${codec.formatVersion}`,\n\t\t\t);\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tcodec.minVersionForCollab === undefined ||\n\t\t\t\t\ttypeof codec.formatVersion !== \"string\" ||\n\t\t\t\t\t`unstable format ${JSON.stringify(codec.formatVersion)} (string formats) must not have a minVersionForCollab in ${name}`,\n\t\t\t);\n\t\t\tformats.add(codec.formatVersion);\n\t\t\tconst normalizedCodec = normalizeCodecVersion(codec);\n\t\t\tnormalizedRegistry.push(normalizedCodec);\n\t\t\tif (codec.minVersionForCollab !== undefined) {\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\t!versions.has(codec.minVersionForCollab) ||\n\t\t\t\t\t\t`Codec ${name} has multiple entries for version ${JSON.stringify(codec.minVersionForCollab)}`,\n\t\t\t\t);\n\t\t\t\tversions.add(codec.minVersionForCollab);\n\t\t\t}\n\t\t}\n\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tversions.has(lowestMinVersionForCollab) ||\n\t\t\t\t`Codec ${name} is missing entry for lowestMinVersionForCollab`,\n\t\t);\n\n\t\tthis.registry = normalizedRegistry;\n\t}\n\n\t/**\n\t * Applies `options` to the codec registry to produce a list of evaluated codecs.\n\t * @remarks\n\t * This is used by build, which is what production code should use.\n\t * This is only exposed for testing purposes.\n\t */\n\tpublic applyOptions(\n\t\toptions: TBuildOptions,\n\t): EvaluatedCodecVersion<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>[] {\n\t\treturn this.registry.map((codec) => ({\n\t\t\tminVersionForCollab: codec.minVersionForCollab,\n\t\t\tformatVersion: codec.formatVersion,\n\t\t\tcodec: codec.codec(options),\n\t\t}));\n\t}\n\n\t/**\n\t * Builds a complete {@link VersionDispatchingCodec} that can decode all registered versions\n\t * and encode a version selected by the provided options.\n\t */\n\tpublic build(\n\t\toptions: TBuildOptions & CodecWriteOptions,\n\t): VersionDispatchingCodec<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext> {\n\t\tconst [applied, decoder] = this.buildDecoderInternal(options);\n\t\tconst writeVersion = getWriteVersion(this.name, options, applied);\n\t\treturn {\n\t\t\t...decoder,\n\t\t\tencode: (data: TDecoded, context: TEncodeContext): JsonCompatibleReadOnly => {\n\t\t\t\treturn writeVersion.codec.encode(data, context);\n\t\t\t},\n\t\t\twriteVersion: writeVersion.formatVersion,\n\t\t};\n\t}\n\n\tprivate buildDecoderInternal(\n\t\toptions: TBuildOptions,\n\t): [\n\t\tEvaluatedCodecVersion<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>[],\n\t\tPick<\n\t\t\tIJsonCodec<\n\t\t\t\tTDecoded,\n\t\t\t\tJsonCompatibleReadOnly,\n\t\t\t\tJsonCompatibleReadOnly,\n\t\t\t\tTEncodeContext,\n\t\t\t\tTDecodeContext\n\t\t\t>,\n\t\t\t\"decode\"\n\t\t>,\n\t] {\n\t\tconst applied = this.applyOptions(options);\n\t\tconst fromFormatVersion = new Map<\n\t\t\tFormatVersion,\n\t\t\tEvaluatedCodecVersion<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>\n\t\t>(applied.map((codec) => [codec.formatVersion, codec]));\n\t\treturn [\n\t\t\tapplied,\n\t\t\t{\n\t\t\t\tdecode: (data: JsonCompatibleReadOnly, context: TDecodeContext): TDecoded => {\n\t\t\t\t\tconst versioned = data as Partial<Versioned>;\n\t\t\t\t\tconst codec = fromFormatVersion.get(versioned.version);\n\t\t\t\t\tif (codec === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding ${this.name} data. Supported versions for this data are: ${versionList(applied)}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn codec.codec.decode(data, context);\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Builds a decoder-only codec that can decode any supported format without encoding capability.\n\t *\n\t * @remarks\n\t * The returned codec contains only the `decode` method and can be used when only decoding is needed.\n\t * This is useful for scenarios where reading/decoding versioned data is sufficient.\n\t *\n\t * @param options - Build options (typically containing the `jsonValidator`)\n\t * @returns An object with a `decode` method that can handle any supported format version\n\t */\n\tpublic buildDecoder(\n\t\toptions: TBuildOptions,\n\t): Pick<\n\t\tVersionDispatchingCodec<TDecoded, TEncodeContext, TFormatVersion, TDecodeContext>,\n\t\t\"decode\"\n\t> {\n\t\treturn this.buildDecoderInternal(options)[1];\n\t}\n\n\tpublic getCodecTree(clientVersion: MinimumVersionForCollab): CodecTree<TFormatVersion> {\n\t\t// TODO: add support for children codecs.\n\t\tconst selected = getWriteVersionNoOverrides(this.registry, clientVersion);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tversion: selected.formatVersion,\n\t\t};\n\t}\n\n\t/**\n\t * Creates a new VersionDispatchingCodecBuilder from the provided codec registry.\n\t *\n\t * @remarks\n\t * This static method infers the types of the builder from the provided registry,\n\t * making it easier to create builders without needing to explicitly specify all type parameters.\n\t * This gets better type inference than the constructor.\n\t *\n\t * @example\n\t * ```typescript\n\t * const builder = VersionDispatchingCodecBuilder.build('myCodec', [\n\t * { minVersionForCollab: lowestMinVersionForCollab, formatVersion: 1, codec: { encode, decode, schema } },\n\t * { minVersionForCollab: '2.100.0', formatVersion: 2, codec: { encode, decode, schema } },\n\t * ]);\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic static build<\n\t\tName extends CodecName,\n\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, never, unknown>,\n\t>(name: Name, inputRegistry: readonly Entry[]) {\n\t\ttype TDecoded2 =\n\t\t\tEntry extends CodecVersion<infer D, unknown, FormatVersion, never, unknown> ? D : never;\n\t\ttype TEncodeContext2 =\n\t\t\tEntry extends CodecVersion<unknown, infer C, FormatVersion, never, unknown> ? C : never;\n\t\ttype TFormatVersion2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, infer F, never, unknown> ? F : never;\n\t\ttype TBuildOptions2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, infer B, unknown>\n\t\t\t\t? B\n\t\t\t\t: never;\n\t\ttype TDecodeContext2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, never, infer D> ? D : never;\n\n\t\ttype ResolvedEncodeContext = unknown extends TEncodeContext2 ? void : TEncodeContext2;\n\t\ttype ResolvedDecodeContext = unknown extends TDecodeContext2\n\t\t\t? ResolvedEncodeContext\n\t\t\t: TDecodeContext2;\n\n\t\ttype CodecFinal = CodecVersion<\n\t\t\tTDecoded2,\n\t\t\t// If it does not matter what context is provided, undefined is fine, so allow it to be omitted.\n\t\t\tResolvedEncodeContext,\n\t\t\tTFormatVersion2,\n\t\t\tTBuildOptions2,\n\t\t\tResolvedDecodeContext\n\t\t>;\n\n\t\tconst input = inputRegistry as readonly unknown[] as readonly CodecFinal[];\n\n\t\tconst builder = new VersionDispatchingCodecBuilder<\n\t\t\tTBuildOptions2,\n\t\t\tTDecoded2,\n\t\t\tResolvedEncodeContext,\n\t\t\tTFormatVersion2,\n\t\t\tName,\n\t\t\tResolvedDecodeContext\n\t\t>(name, input);\n\t\treturn builder;\n\t}\n}\n\n/**\n * Selects which format should be used when writing data.\n * @remarks\n * This either uses the override specified in the options, or selects the newest format compatible with the provided minVersionForCollab.\n */\nfunction getWriteVersion<T extends CodecVersionBase>(\n\tname: CodecName,\n\toptions: CodecWriteOptions,\n\tversions: readonly T[],\n): T {\n\tif (options.writeVersionOverrides?.has(name) === true) {\n\t\tconst selectedFormatVersion = options.writeVersionOverrides.get(name);\n\t\tconst selected = versions.find((codec) => codec.formatVersion === selectedFormatVersion);\n\t\tif (selected === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)}. Supported versions are: ${versionList(versions)}.`,\n\t\t\t);\n\t\t} else if (options.allowPossiblyIncompatibleWriteVersionOverrides !== true) {\n\t\t\tconst selectedMinVersionForCollab = selected.minVersionForCollab;\n\t\t\tif (selectedMinVersionForCollab === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it has minVersionForCollab undefined. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t} else if (gt(selectedMinVersionForCollab, options.minVersionForCollab)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it is only compatible back to client version ${selectedMinVersionForCollab} and the requested oldest compatible client was ${options.minVersionForCollab}. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn selected;\n\t}\n\n\treturn getWriteVersionNoOverrides(versions, options.minVersionForCollab);\n}\n\n/**\n * Selects which format should be used when writing data, without consider overrides.\n */\nfunction getWriteVersionNoOverrides<T extends CodecVersionBase>(\n\tversions: readonly T[],\n\tminVersionForCollab: MinimumVersionForCollab,\n): T {\n\tconst stableVersions: [MinimumMinorSemanticVersion | MinimumVersionForCollab, T][] = [];\n\tfor (const version of versions) {\n\t\tif (version.minVersionForCollab !== undefined) {\n\t\t\tstableVersions.push([version.minVersionForCollab, version]);\n\t\t}\n\t}\n\n\tconst result: T = getConfigForMinVersionForCollabIterable(\n\t\tminVersionForCollab,\n\t\tstableVersions,\n\t);\n\treturn result;\n}\n\n/**\n * Formats a list of versions for use in UsageErrors.\n */\nfunction versionList(versions: readonly CodecVersionBase[]): string {\n\treturn JSON.stringify(Array.from(versions, (codec) => codec.formatVersion));\n}\n"]}
@@ -3,5 +3,5 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export { Versioned, versionField } from "./format.js";
6
- export { makeDiscontinuedCodecAndSchema, ClientVersionDispatchingCodecBuilder, type CodecVersion, type CodecAndSchema, } from "./codec.js";
6
+ export { makeDiscontinuedCodecAndSchema, VersionDispatchingCodecBuilder, type VersionDispatchingCodec, type CodecVersion, type CodecAndSchema, } from "./codec.js";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codec/versioned/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACN,8BAA8B,EAC9B,oCAAoC,EACpC,KAAK,YAAY,EACjB,KAAK,cAAc,GACnB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codec/versioned/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACN,8BAA8B,EAC9B,8BAA8B,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,cAAc,GACnB,MAAM,YAAY,CAAC"}
@@ -4,11 +4,11 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ClientVersionDispatchingCodecBuilder = exports.makeDiscontinuedCodecAndSchema = exports.versionField = exports.Versioned = void 0;
7
+ exports.VersionDispatchingCodecBuilder = exports.makeDiscontinuedCodecAndSchema = exports.versionField = exports.Versioned = void 0;
8
8
  var format_js_1 = require("./format.js");
9
9
  Object.defineProperty(exports, "Versioned", { enumerable: true, get: function () { return format_js_1.Versioned; } });
10
10
  Object.defineProperty(exports, "versionField", { enumerable: true, get: function () { return format_js_1.versionField; } });
11
11
  var codec_js_1 = require("./codec.js");
12
12
  Object.defineProperty(exports, "makeDiscontinuedCodecAndSchema", { enumerable: true, get: function () { return codec_js_1.makeDiscontinuedCodecAndSchema; } });
13
- Object.defineProperty(exports, "ClientVersionDispatchingCodecBuilder", { enumerable: true, get: function () { return codec_js_1.ClientVersionDispatchingCodecBuilder; } });
13
+ Object.defineProperty(exports, "VersionDispatchingCodecBuilder", { enumerable: true, get: function () { return codec_js_1.VersionDispatchingCodecBuilder; } });
14
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/versioned/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAAsD;AAA7C,sGAAA,SAAS,OAAA;AAAE,yGAAA,YAAY,OAAA;AAChC,uCAKoB;AAJnB,0HAAA,8BAA8B,OAAA;AAC9B,gIAAA,oCAAoC,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { Versioned, versionField } from \"./format.js\";\nexport {\n\tmakeDiscontinuedCodecAndSchema,\n\tClientVersionDispatchingCodecBuilder,\n\ttype CodecVersion,\n\ttype CodecAndSchema,\n} from \"./codec.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codec/versioned/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAAsD;AAA7C,sGAAA,SAAS,OAAA;AAAE,yGAAA,YAAY,OAAA;AAChC,uCAMoB;AALnB,0HAAA,8BAA8B,OAAA;AAC9B,0HAAA,8BAA8B,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { Versioned, versionField } from \"./format.js\";\nexport {\n\tmakeDiscontinuedCodecAndSchema,\n\tVersionDispatchingCodecBuilder,\n\ttype VersionDispatchingCodec,\n\ttype CodecVersion,\n\ttype CodecAndSchema,\n} from \"./codec.js\";\n"]}
@@ -11,13 +11,13 @@ export declare function offsetDetachId(id: DetachedNodeId, offset: number): Deta
11
11
  export declare function offsetDetachId(id: DetachedNodeId | undefined, offset: number): DetachedNodeId | undefined;
12
12
  export declare function areDetachedNodeIdsEqual(a: DetachedNodeId, b: DetachedNodeId): boolean;
13
13
  /**
14
- * Returns true if a delta field map contains any changes that would be visible in the document (eg, an insert, move, edit)
14
+ * Returns true if a delta field map contains any changes that would be visible in the document (i.e., a detach or an attach)
15
15
  * @param fields - Delta FieldMap to check for visible changes
16
16
  * @returns True if change map contains any changes that would be visible in the document, false otherwise
17
17
  */
18
18
  export declare function deltaFieldMapHasVisibleChanges(fields: FieldMap | undefined): boolean;
19
19
  /**
20
- * Returns true if the given field changes contains any changes that would be visible in the document (eg, an insert, move, edit)
20
+ * Returns true if the given field changes contains any changes that would be visible in the document (i.e., a detach or an attach)
21
21
  * @param fieldChanges - Field changes to check for visible changes
22
22
  * @returns True if the field changes contain any changes that would be visible in the document, false otherwise
23
23
  */
@@ -44,7 +44,7 @@ function areDetachedNodeIdsEqual(a, b) {
44
44
  }
45
45
  exports.areDetachedNodeIdsEqual = areDetachedNodeIdsEqual;
46
46
  /**
47
- * Returns true if a delta field map contains any changes that would be visible in the document (eg, an insert, move, edit)
47
+ * Returns true if a delta field map contains any changes that would be visible in the document (i.e., a detach or an attach)
48
48
  * @param fields - Delta FieldMap to check for visible changes
49
49
  * @returns True if change map contains any changes that would be visible in the document, false otherwise
50
50
  */
@@ -61,7 +61,7 @@ function deltaFieldMapHasVisibleChanges(fields) {
61
61
  }
62
62
  exports.deltaFieldMapHasVisibleChanges = deltaFieldMapHasVisibleChanges;
63
63
  /**
64
- * Returns true if the given field changes contains any changes that would be visible in the document (eg, an insert, move, edit)
64
+ * Returns true if the given field changes contains any changes that would be visible in the document (i.e., a detach or an attach)
65
65
  * @param fieldChanges - Field changes to check for visible changes
66
66
  * @returns True if the field changes contain any changes that would be visible in the document, false otherwise
67
67
  */
@@ -1 +1 @@
1
- {"version":3,"file":"deltaUtil.js","sourceRoot":"","sources":["../../../src/core/tree/deltaUtil.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAA0C;AAE7B,QAAA,UAAU,GAAS,EAAE,CAAC;AAEnC,SAAgB,0BAA0B,CAAC,OAAkB;IAC5D,IAAI,OAAO,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,kBAAU,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAS;QACnB,KAAK,EAAE,CAAC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AE,CAAC;YACvD,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAVD,wEAUC;AAED;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,YAA0B;IAC7E,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QACvC,IACC,IAAI,CAAC,MAAM,KAAK,SAAS;YACzB,IAAI,CAAC,MAAM,KAAK,SAAS;YACzB,8BAA8B,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAZD,kFAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Mutable } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\nimport type { DetachedNodeId, FieldChanges, FieldMap, Root } from \"./delta.js\";\nimport { rootFieldKey } from \"./types.js\";\n\nexport const emptyDelta: Root = {};\n\nexport function deltaForRootInitialization(content: TreeChunk): Root {\n\tif (content.topLevelLength === 0) {\n\t\treturn emptyDelta;\n\t}\n\tconst buildId = { minor: 0 };\n\tconst delta: Root = {\n\t\tbuild: [{ id: buildId, trees: content }],\n\t\tfields: new Map<FieldKey, FieldChanges>([\n\t\t\t[rootFieldKey, { marks: [{ count: content.topLevelLength, attach: buildId }] }],\n\t\t]),\n\t};\n\treturn delta;\n}\n\nexport function makeDetachedNodeId(\n\tmajor: DetachedNodeId[\"major\"],\n\tminor: DetachedNodeId[\"minor\"],\n): DetachedNodeId {\n\tconst out: Mutable<DetachedNodeId> = { minor };\n\tif (major !== undefined) {\n\t\tout.major = major;\n\t}\n\treturn out;\n}\n\nexport function offsetDetachId(id: DetachedNodeId, offset: number): DetachedNodeId;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined {\n\tif (id === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...id,\n\t\tminor: id.minor + offset,\n\t};\n}\n\nexport function areDetachedNodeIdsEqual(a: DetachedNodeId, b: DetachedNodeId): boolean {\n\treturn a.major === b.major && a.minor === b.minor;\n}\n\n/**\n * Returns true if a delta field map contains any changes that would be visible in the document (eg, an insert, move, edit)\n * @param fields - Delta FieldMap to check for visible changes\n * @returns True if change map contains any changes that would be visible in the document, false otherwise\n */\nexport function deltaFieldMapHasVisibleChanges(fields: FieldMap | undefined): boolean {\n\tif (fields === undefined || fields.size === 0) {\n\t\treturn false;\n\t}\n\tfor (const [, fieldChanges] of fields) {\n\t\tif (deltaFieldChangesHaveVisibleChanges(fieldChanges)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true if the given field changes contains any changes that would be visible in the document (eg, an insert, move, edit)\n * @param fieldChanges - Field changes to check for visible changes\n * @returns True if the field changes contain any changes that would be visible in the document, false otherwise\n */\nexport function deltaFieldChangesHaveVisibleChanges(fieldChanges: FieldChanges): boolean {\n\tfor (const mark of fieldChanges.marks) {\n\t\tif (\n\t\t\tmark.attach !== undefined ||\n\t\t\tmark.detach !== undefined ||\n\t\t\tdeltaFieldMapHasVisibleChanges(mark.fields)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
1
+ {"version":3,"file":"deltaUtil.js","sourceRoot":"","sources":["../../../src/core/tree/deltaUtil.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAA0C;AAE7B,QAAA,UAAU,GAAS,EAAE,CAAC;AAEnC,SAAgB,0BAA0B,CAAC,OAAkB;IAC5D,IAAI,OAAO,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,kBAAU,CAAC;IACnB,C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CAAC;IACD,KAAK,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,MAAM,EAAE,CAAC;QACvC,IAAI,mCAAmC,CAAC,YAAY,CAAC,EAAE,CAAC;YACvD,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAVD,wEAUC;AAED;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,YAA0B;IAC7E,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QACvC,IACC,IAAI,CAAC,MAAM,KAAK,SAAS;YACzB,IAAI,CAAC,MAAM,KAAK,SAAS;YACzB,8BAA8B,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAZD,kFAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Mutable } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\nimport type { DetachedNodeId, FieldChanges, FieldMap, Root } from \"./delta.js\";\nimport { rootFieldKey } from \"./types.js\";\n\nexport const emptyDelta: Root = {};\n\nexport function deltaForRootInitialization(content: TreeChunk): Root {\n\tif (content.topLevelLength === 0) {\n\t\treturn emptyDelta;\n\t}\n\tconst buildId = { minor: 0 };\n\tconst delta: Root = {\n\t\tbuild: [{ id: buildId, trees: content }],\n\t\tfields: new Map<FieldKey, FieldChanges>([\n\t\t\t[rootFieldKey, { marks: [{ count: content.topLevelLength, attach: buildId }] }],\n\t\t]),\n\t};\n\treturn delta;\n}\n\nexport function makeDetachedNodeId(\n\tmajor: DetachedNodeId[\"major\"],\n\tminor: DetachedNodeId[\"minor\"],\n): DetachedNodeId {\n\tconst out: Mutable<DetachedNodeId> = { minor };\n\tif (major !== undefined) {\n\t\tout.major = major;\n\t}\n\treturn out;\n}\n\nexport function offsetDetachId(id: DetachedNodeId, offset: number): DetachedNodeId;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined {\n\tif (id === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...id,\n\t\tminor: id.minor + offset,\n\t};\n}\n\nexport function areDetachedNodeIdsEqual(a: DetachedNodeId, b: DetachedNodeId): boolean {\n\treturn a.major === b.major && a.minor === b.minor;\n}\n\n/**\n * Returns true if a delta field map contains any changes that would be visible in the document (i.e., a detach or an attach)\n * @param fields - Delta FieldMap to check for visible changes\n * @returns True if change map contains any changes that would be visible in the document, false otherwise\n */\nexport function deltaFieldMapHasVisibleChanges(fields: FieldMap | undefined): boolean {\n\tif (fields === undefined || fields.size === 0) {\n\t\treturn false;\n\t}\n\tfor (const [, fieldChanges] of fields) {\n\t\tif (deltaFieldChangesHaveVisibleChanges(fieldChanges)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true if the given field changes contains any changes that would be visible in the document (i.e., a detach or an attach)\n * @param fieldChanges - Field changes to check for visible changes\n * @returns True if the field changes contain any changes that would be visible in the document, false otherwise\n */\nexport function deltaFieldChangesHaveVisibleChanges(fieldChanges: FieldChanges): boolean {\n\tfor (const mark of fieldChanges.marks) {\n\t\tif (\n\t\t\tmark.attach !== undefined ||\n\t\t\tmark.detach !== undefined ||\n\t\t\tdeltaFieldMapHasVisibleChanges(mark.fields)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV1.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAEN,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AAkDpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
1
+ {"version":3,"file":"detachedFieldIndexCodecV1.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAEN,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AAkDpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.makeDetachedNodeToFieldCodecV1 = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const internal_2 = require("@fluidframework/id-compressor/internal");
9
10
  const index_js_1 = require("../../util/index.js");
10
11
  const index_js_2 = require("../rebase/index.js");
11
12
  const detachedFieldIndexCodecCommon_js_1 = require("./detachedFieldIndexCodecCommon.js");
@@ -35,11 +36,11 @@ class MajorCodec {
35
36
  * but not when the container is already attached and it's just the shared-tree that is attaching.
36
37
  * The assert below will fail in such a scenario. This is addressed in the v2 codec.
37
38
  */
38
- (0, internal_1.assert)(id === "root" || id >= 0, 0x88f /* Expected final id on encode of detached field index revision */);
39
+ (0, internal_1.assert)(id === "root" || (0, internal_2.isFinalId)(id), 0x88f /* Expected final id on encode of detached field index revision */);
39
40
  return id;
40
41
  }
41
42
  decode(major) {
42
- (0, internal_1.assert)(major === "root" || major >= 0, 0x890 /* Expected final id on decode of detached field index revision */);
43
+ (0, internal_1.assert)(major === "root" || (0, internal_2.isFinalId)(major), 0x890 /* Expected final id on decode of detached field index revision */);
43
44
  return this.revisionTagCodec.decode(major, {
44
45
  originatorId: this.revisionTagCodec.localSessionId,
45
46
  idCompressor: this.idCompressor,
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV1.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,kDAA4C;AAC5C,iDAK4B;AAE5B,yFAA+F;AAC/F,2FAAsF;AAGtF,MAAM,UAAU;IACf,YACkB,gBAAkC,EAClC,YAA2B;QAD3B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,iBAAY,GAAZ,YAAY,CAAe;IAC1C,CAAC;IAEG,MAAM,CAAC,KAAY;QACzB,IAAA,iBAAM,EAAC,KAAK,KAAK,SAAS,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvE,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C;;;;;;;;;;;;;;;;WAgBG;QACH,IAAA,iBAAM,EACL,EAAE,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,EACxB,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,MAAM,CAAC,KAAyB;QACtC,IAAA,iBAAM,EACL,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,EAC9B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc;YAClD,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,SAAS;YACnB,6DAA6D;YAC7D,SAAS,EAAE,IAAI;SACf,CAAC,CAAC;IACJ,CAAC;CACD;AAED,SAAgB,8BAA8B,CAC7C,gBAAkC,EAClC,YAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,IAAA,4EAAyC,EAC/C,UAAU,EACV,IAAA,gBAAK,EAAC,mEAA+B,CAAC,EAAE,CAAC,EACzC,4BAAiB,CACjB,CAAC;AACH,CAAC;AAVD,wEAUC","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/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport {\n\ttype EncodedRevisionTag,\n\ttype RevisionTagCodec,\n\ttype RevisionTag,\n\tRevisionTagSchema,\n} from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major, EncodedRevisionTag> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag {\n\t\tassert(major !== undefined, 0x88e /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\t\t/**\n\t\t * Preface: this codec is only used at summarization time (not for ops).\n\t\t * Note that the decode path must provide a session id in which to interpret the revision tag.\n\t\t * The revision associated with a detached root generally comes from the session which detaches that subtree,\n\t\t * which isn't generally the local session (nor is it available at decode time with the layering of the tree\n\t\t * package), despite decode using the local session id.\n\t\t *\n\t\t * This is made OK by enforcing that all ids on encode/decode are non-local, since local ids won't be interpretable\n\t\t * at decode time.\n\t\t * This assert is valid because the revision for an acked edit will have already been finalized, and a revision\n\t\t * for a local-only edit will be finalizable at summarization time (local edits can only occur on a summarizing client\n\t\t * if they're created while detached, and local ids made while detached are finalized before generating the attach summary).\n\t\t *\n\t\t * WARNING: the above is true when the whole container transitions from detached to attached,\n\t\t * but not when the container is already attached and it's just the shared-tree that is attaching.\n\t\t * The assert below will fail in such a scenario. This is addressed in the v2 codec.\n\t\t */\n\t\tassert(\n\t\t\tid === \"root\" || id >= 0,\n\t\t\t0x88f /* Expected final id on encode of detached field index revision */,\n\t\t);\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || major >= 0,\n\t\t\t0x890 /* Expected final id on decode of detached field index revision */,\n\t\t);\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t\t// DetachedFieldIndex codecs are only used by the summarizer.\n\t\t\tisSummary: true,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV1(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tbrand(DetachedFieldIndexFormatVersion.v1),\n\t\tRevisionTagSchema,\n\t);\n}\n"]}
1
+ {"version":3,"file":"detachedFieldIndexCodecV1.js","s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AU,EACV,IAAA,gBAAK,EAAC,mEAA+B,CAAC,EAAE,CAAC,EACzC,4BAAiB,CACjB,CAAC;AACH,CAAC;AAVD,wEAUC","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/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport { isFinalId } from \"@fluidframework/id-compressor/internal\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport {\n\ttype EncodedRevisionTag,\n\ttype RevisionTagCodec,\n\ttype RevisionTag,\n\tRevisionTagSchema,\n} from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major, EncodedRevisionTag> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag {\n\t\tassert(major !== undefined, 0x88e /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\t\t/**\n\t\t * Preface: this codec is only used at summarization time (not for ops).\n\t\t * Note that the decode path must provide a session id in which to interpret the revision tag.\n\t\t * The revision associated with a detached root generally comes from the session which detaches that subtree,\n\t\t * which isn't generally the local session (nor is it available at decode time with the layering of the tree\n\t\t * package), despite decode using the local session id.\n\t\t *\n\t\t * This is made OK by enforcing that all ids on encode/decode are non-local, since local ids won't be interpretable\n\t\t * at decode time.\n\t\t * This assert is valid because the revision for an acked edit will have already been finalized, and a revision\n\t\t * for a local-only edit will be finalizable at summarization time (local edits can only occur on a summarizing client\n\t\t * if they're created while detached, and local ids made while detached are finalized before generating the attach summary).\n\t\t *\n\t\t * WARNING: the above is true when the whole container transitions from detached to attached,\n\t\t * but not when the container is already attached and it's just the shared-tree that is attaching.\n\t\t * The assert below will fail in such a scenario. This is addressed in the v2 codec.\n\t\t */\n\t\tassert(\n\t\t\tid === \"root\" || isFinalId(id),\n\t\t\t0x88f /* Expected final id on encode of detached field index revision */,\n\t\t);\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || isFinalId(major),\n\t\t\t0x890 /* Expected final id on decode of detached field index revision */,\n\t\t);\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t\t// DetachedFieldIndex codecs are only used by the summarizer.\n\t\t\tisSummary: true,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV1(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tbrand(DetachedFieldIndexFormatVersion.v1),\n\t\tRevisionTagSchema,\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV2.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,+BAA+B,CAAC;AAG7E,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAsB,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAK5F,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AA0CpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
1
+ {"version":3,"file":"detachedFieldIndexCodecV2.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,+BAA+B,CAAC;AAG7E,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAsB,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAK5F,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AA4CpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
@@ -18,7 +18,7 @@ class MajorCodec {
18
18
  encode(major) {
19
19
  (0, internal_1.assert)(major !== undefined, 0xbfb /* Unexpected undefined revision */);
20
20
  const id = this.revisionTagCodec.encode(major);
21
- if (id !== "root" && id < 0) {
21
+ if (id !== "root" && !(0, internal_2.isFinalId)(id)) {
22
22
  /**
23
23
  * This code path handles the case where the major revision is not finalized.
24
24
  * This can happen the SharedTree is being attached to an already attached container.
@@ -30,7 +30,9 @@ class MajorCodec {
30
30
  return id;
31
31
  }
32
32
  decode(major) {
33
- (0, internal_1.assert)(major === "root" || (typeof major === "string" && (0, internal_2.isStableId)(major)) || major >= 0, 0xbfd /* Expected root, stable, or final compressed id */);
33
+ (0, internal_1.assert)(major === "root" ||
34
+ (typeof major === "string" && (0, internal_2.isStableId)(major)) ||
35
+ (typeof major === "number" && (0, internal_2.isFinalId)(major)), 0xbfd /* Expected root, stable, or final compressed id */);
34
36
  if (typeof major === "string" && (0, internal_2.isStableId)(major)) {
35
37
  return this.idCompressor.recompress(major);
36
38
  }