@fluidframework/tree 2.101.1 → 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
@@ -173,8 +173,9 @@ export interface CodecWriteOptions extends ICodecOptions, CodecWriteOptionsBeta
173
173
  }
174
174
 
175
175
  /**
176
- * `TContext` allows passing context to the codec which may configure how data is encoded/decoded.
177
- * This parameter is typically used for:
176
+ * `TEncodeContext` and `TDecodeContext` allow passing context to the codec which may configure how data is encoded/decoded.
177
+ * `TDecodeContext` defaults to `TEncodeContext`; specify them separately when encode and decode need different context (for example, when encoding uses heuristics that are unneeded when decoding).
178
+ * These parameters are typically used for:
178
179
  * - Codecs which can pick from multiple encoding options, and imbue the encoded data with information about which option was used.
179
180
  * The caller of such a codec can provide context about which encoding choice to make as part of the `encode` call without creating
180
181
  * additional codecs. Note that this pattern can always be implemented by having the caller create multiple codecs and selecting the
@@ -196,9 +197,10 @@ export interface IJsonCodec<
196
197
  TDecoded,
197
198
  TEncoded = JsonCompatibleReadOnly,
198
199
  TValidate = TEncoded,
199
- TContext = void,
200
- > extends IEncoder<TDecoded, TEncoded, TContext>,
201
- IDecoder<TDecoded, TValidate, TContext> {
200
+ TEncodeContext = void,
201
+ TDecodeContext = TEncodeContext,
202
+ > extends IEncoder<TDecoded, TEncoded, TEncodeContext>,
203
+ IDecoder<TDecoded, TValidate, TDecodeContext> {
202
204
  encodedSchema?: TAnySchema;
203
205
  }
204
206
 
@@ -211,9 +213,13 @@ export interface IJsonCodec<
211
213
  *
212
214
  * This portion of a codec is not responsible for managing versioning or validation of the data against the schema.
213
215
  */
214
- export interface JsonCodecPart<TDecoded, TEncodedSchema extends TAnySchema, TContext = void>
215
- extends IEncoder<TDecoded, Static<TEncodedSchema>, TContext>,
216
- IDecoder<TDecoded, Static<TEncodedSchema>, TContext> {
216
+ export interface JsonCodecPart<
217
+ TDecoded,
218
+ TEncodedSchema extends TAnySchema,
219
+ TEncodeContext = void,
220
+ TDecodeContext = TEncodeContext,
221
+ > extends IEncoder<TDecoded, Static<TEncodedSchema>, TEncodeContext>,
222
+ IDecoder<TDecoded, Static<TEncodedSchema>, TDecodeContext> {
217
223
  /**
218
224
  * TypeBox schema which describes the encoded format for this chunk of data.
219
225
  * @remarks
@@ -230,11 +236,18 @@ export function eraseEncodedType<
230
236
  TDecoded,
231
237
  TEncoded = JsonCompatibleReadOnly,
232
238
  TValidate = TEncoded,
233
- TContext = void,
239
+ TEncodeContext = void,
240
+ TDecodeContext = TEncodeContext,
234
241
  >(
235
- codec: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,
236
- ): IJsonCodec<TDecoded, TValidate, TValidate, TContext> {
237
- return codec as unknown as IJsonCodec<TDecoded, TValidate, TValidate, TContext>;
242
+ codec: IJsonCodec<TDecoded, TEncoded, TValidate, TEncodeContext, TDecodeContext>,
243
+ ): IJsonCodec<TDecoded, TValidate, TValidate, TEncodeContext, TDecodeContext> {
244
+ return codec as unknown as IJsonCodec<
245
+ TDecoded,
246
+ TValidate,
247
+ TValidate,
248
+ TEncodeContext,
249
+ TDecodeContext
250
+ >;
238
251
  }
239
252
 
240
253
  /**
@@ -246,11 +259,15 @@ export function eraseEncodedType<
246
259
  * allows avoiding some duplicate work at encode/decode time, since the vast majority of document usage will not
247
260
  * involve mixed format versions.
248
261
  *
249
- * @privateRemarks This interface currently assumes all codecs in a family require the same encode/decode context,
250
- * which isn't necessarily true.
251
- * This may need to be relaxed in the future.
262
+ * @privateRemarks
263
+ * Encode and decode can be parameterized independently — the encode-side context type need not equal the decode-side context type.
264
+ * `TDecodeContext` defaults to `TEncodeContext` so callers that share a single context shape (the common case) don't need to specify it.
252
265
  */
253
- export interface ICodecFamily<TDecoded, TContext = void> {
266
+ export interface ICodecFamily<
267
+ TDecoded,
268
+ TEncodeContext = void,
269
+ TDecodeContext = TEncodeContext,
270
+ > {
254
271
  /**
255
272
  * @returns a codec that can be used to encode and decode data in the specified format.
256
273
  * @throws if the format version is not supported by this family.
@@ -260,7 +277,13 @@ export interface ICodecFamily<TDecoded, TContext = void> {
260
277
  */
261
278
  resolve(
262
279
  formatVersion: FormatVersion,
263
- ): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>;
280
+ ): IJsonCodec<
281
+ TDecoded,
282
+ JsonCompatibleReadOnly,
283
+ JsonCompatibleReadOnly,
284
+ TEncodeContext,
285
+ TDecodeContext
286
+ >;
264
287
 
265
288
  /**
266
289
  * @returns an iterable of all format versions supported by this family.
@@ -338,17 +361,29 @@ export const DependentFormatVersion = {
338
361
  /**
339
362
  * Creates a codec family from a registry of codecs.
340
363
  */
341
- export function makeCodecFamily<TDecoded, TContext>(
364
+ export function makeCodecFamily<TDecoded, TEncodeContext, TDecodeContext = TEncodeContext>(
342
365
  registry: Iterable<
343
366
  [
344
367
  formatVersion: FormatVersion,
345
- codec: IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,
368
+ codec: IJsonCodec<
369
+ TDecoded,
370
+ JsonCompatibleReadOnly,
371
+ JsonCompatibleReadOnly,
372
+ TEncodeContext,
373
+ TDecodeContext
374
+ >,
346
375
  ]
347
376
  >,
348
- ): ICodecFamily<TDecoded, TContext> {
377
+ ): ICodecFamily<TDecoded, TEncodeContext, TDecodeContext> {
349
378
  const codecs: Map<
350
379
  FormatVersion,
351
- IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>
380
+ IJsonCodec<
381
+ TDecoded,
382
+ JsonCompatibleReadOnly,
383
+ JsonCompatibleReadOnly,
384
+ TEncodeContext,
385
+ TDecodeContext
386
+ >
352
387
  > = new Map();
353
388
  for (const [formatVersion, codec] of registry) {
354
389
  if (codecs.has(formatVersion)) {
@@ -360,7 +395,13 @@ export function makeCodecFamily<TDecoded, TContext>(
360
395
  return {
361
396
  resolve(
362
397
  formatVersion: FormatVersion,
363
- ): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {
398
+ ): IJsonCodec<
399
+ TDecoded,
400
+ JsonCompatibleReadOnly,
401
+ JsonCompatibleReadOnly,
402
+ TEncodeContext,
403
+ TDecodeContext
404
+ > {
364
405
  const codec = codecs.get(formatVersion);
365
406
  assert(codec !== undefined, 0x5e6 /* Requested codec for unsupported format. */);
366
407
  return codec;
@@ -388,32 +429,39 @@ export const unitCodec: IJsonCodec<
388
429
  * Wraps a codec with JSON schema validation for its encoded type.
389
430
  * @returns An {@link IJsonCodec} which validates the data it encodes and decodes matches the provided schema.
390
431
  * @remarks
391
- * Eventually all codecs should use the same pattern implemented by ClientVersionDispatchingCodecBuilder, resulting in that having the only use of this API.
432
+ * Eventually all codecs should use the same pattern implemented by VersionDispatchingCodecBuilder, resulting in that having the only use of this API.
392
433
  */
393
434
  export function withSchemaValidation<
394
435
  TInMemoryFormat,
395
436
  EncodedSchema extends TSchema,
396
437
  TEncodedFormat,
397
438
  TValidate,
398
- TContext,
439
+ TEncodeContext,
440
+ TDecodeContext = TEncodeContext,
399
441
  >(
400
442
  schema: EncodedSchema,
401
- codec: IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext>,
443
+ codec: IJsonCodec<
444
+ TInMemoryFormat,
445
+ TEncodedFormat,
446
+ TValidate,
447
+ TEncodeContext,
448
+ TDecodeContext
449
+ >,
402
450
  validator?: JsonValidator | FormatValidator,
403
- ): IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext> {
451
+ ): IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TEncodeContext, TDecodeContext> {
404
452
  if (!validator) {
405
453
  return codec;
406
454
  }
407
455
  const compiledFormat = extractJsonValidator(validator).compile(schema);
408
456
  return {
409
- encode: (obj: TInMemoryFormat, context: TContext): TEncodedFormat => {
457
+ encode: (obj: TInMemoryFormat, context: TEncodeContext): TEncodedFormat => {
410
458
  const encoded = codec.encode(obj, context);
411
459
  if (!compiledFormat.check(encoded)) {
412
460
  fail(0xac0 /* Encoded data should validate */);
413
461
  }
414
462
  return encoded;
415
463
  },
416
- decode: (encoded: TValidate, context: TContext): TInMemoryFormat => {
464
+ decode: (encoded: TValidate, context: TDecodeContext): TInMemoryFormat => {
417
465
  if (!compiledFormat.check(encoded)) {
418
466
  fail(0xac1 /* Data being decoded should validate */);
419
467
  }
@@ -424,62 +472,23 @@ export function withSchemaValidation<
424
472
  }
425
473
 
426
474
  /**
427
- * Versions of Fluid Framework client packages.
475
+ * Versions of Fluid Framework client packages, usable as a {@link @fluidframework/runtime-definitions#MinimumVersionForCollab}.
428
476
  * @remarks
429
- * Used to express compatibility requirements by indicating the oldest version with which compatibility must be maintained.
430
- *
431
- * When no compatibility-impacting change is made in a given version, the value associated with its enum entry may point to the older version which it's fully compatible with.
432
- * Note that this can change if a future version of the framework introduces an option to use something which is only supported at a particular version. In which case, the values of the enum may shift,
433
- * but the semantics of keys in this enum will not change.
434
- *
435
- * Do not depend on the value of this enums's entries: only depend on the keys (enum members) themselves.
436
- *
437
- * Some release may also be omitted if there is currently no need to express that specific version.
438
- * If the need arises, they might be added in the future.
477
+ * Versions with no notable impact may be omitted, and added later if needed.
439
478
  *
440
479
  * @privateRemarks
441
- * The entries in these enums should document the following:
442
- * - The user facing impact of opting into a particular version. This will help customers decide if they want to opt into
443
- * a new version. For example, document if there is an encoding efficiency improvement of oping into that version or newer.
444
- * - Any new data formats that are introduced in that version. This will help developers tell which data formats a given
445
- * version will write. For example, document if a new summary or encoding format is added in a version.
446
- * - Whether the above features or data formats introduced in a version are enabled by default or require the
447
- * {@link minVersionForCollab} option to be set to that particular version.
448
- *
449
- * Versions with no notable impact can be omitted.
450
- *
451
- * This scheme assumes a single version will always be enough to communicate compatibility.
452
- * For this to work, compatibility has to be strictly increasing.
453
- * If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),
454
- * a more complex scheme may be needed to allow safely opting into incompatible features in those cases:
455
- * such a system can be added if/when its needed since it will be opt in and thus non-breaking.
456
- *
457
- * TODO: this should likely be defined higher in the stack and specified when creating the container, possibly as part of its schema.
458
- * TODO: compatibility requirements for how this enum can and cannot be changed should be clarified when/if it's used across multiple layers in the stack.
459
- * For example, if needed, would adding more leading zeros to the minor version break things.
480
+ * Each entry should document:
481
+ * - The user-facing impact of opting into it (e.g. encoding efficiency improvements).
482
+ * - Any new data formats introduced in that version.
483
+ * - Whether those features/formats are enabled by default or require {@link MinimumVersionForCollab | minVersionForCollab} to be set accordingly.
460
484
  * @alpha
461
485
  */
462
486
  export const FluidClientVersion = {
463
- /**
464
- * Fluid Framework Client 1.4 and newer.
465
- * @remarks
466
- * This opts into support for the 1.4 LTS branch.
467
- * @privateRemarks
468
- * As long as this code is in Tree, there is no reason to have this option as SharedTree did not exist in 1.4.
469
- */
470
- // v1_4 = 1.004,
471
-
472
487
  /**
473
488
  * Fluid Framework Client 2.0 and newer.
474
489
  */
475
490
  v2_0: "2.0.0",
476
491
 
477
- /** Fluid Framework Client 2.1 and newer. */
478
- // If we think we might want to start allowing opting into something that landed in 2.1 (without opting into something newer),
479
- // we could add an entry like this to allow users to indicate that they can be opted in once we are ready,
480
- // then update it to "2.001" once we actually have the opt in working.
481
- // v2_1 = v2_0,
482
-
483
492
  /**
484
493
  * Fluid Framework Client 2.43 and newer.
485
494
  * @remarks
@@ -38,7 +38,8 @@ export {
38
38
  export {
39
39
  Versioned,
40
40
  makeDiscontinuedCodecAndSchema,
41
- ClientVersionDispatchingCodecBuilder,
41
+ VersionDispatchingCodecBuilder,
42
+ type VersionDispatchingCodec,
42
43
  type CodecVersion,
43
44
  type CodecAndSchema,
44
45
  versionField,