@fluidframework/tree 2.81.0 → 2.82.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 (579) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/api-report/tree.alpha.api.md +54 -22
  3. package/api-report/tree.beta.api.md +150 -1
  4. package/api-report/tree.legacy.beta.api.md +150 -1
  5. package/api-report/tree.legacy.public.api.md +1 -0
  6. package/api-report/tree.public.api.md +1 -0
  7. package/dist/alpha.d.ts +8 -2
  8. package/dist/beta.d.ts +3 -0
  9. package/dist/codec/codec.d.ts +17 -8
  10. package/dist/codec/codec.d.ts.map +1 -1
  11. package/dist/codec/codec.js +8 -1
  12. package/dist/codec/codec.js.map +1 -1
  13. package/dist/codec/index.d.ts +1 -1
  14. package/dist/codec/index.d.ts.map +1 -1
  15. package/dist/codec/index.js +2 -1
  16. package/dist/codec/index.js.map +1 -1
  17. package/dist/codec/versioned/codec.d.ts +1 -1
  18. package/dist/codec/versioned/codec.d.ts.map +1 -1
  19. package/dist/codec/versioned/codec.js.map +1 -1
  20. package/dist/core/index.d.ts +1 -1
  21. package/dist/core/index.d.ts.map +1 -1
  22. package/dist/core/index.js +4 -2
  23. package/dist/core/index.js.map +1 -1
  24. package/dist/core/rebase/changeRebaser.d.ts +3 -2
  25. package/dist/core/rebase/changeRebaser.d.ts.map +1 -1
  26. package/dist/core/rebase/changeRebaser.js.map +1 -1
  27. package/dist/core/rebase/index.d.ts +1 -1
  28. package/dist/core/rebase/index.d.ts.map +1 -1
  29. package/dist/core/rebase/index.js +4 -2
  30. package/dist/core/rebase/index.js.map +1 -1
  31. package/dist/core/rebase/types.d.ts +23 -3
  32. package/dist/core/rebase/types.d.ts.map +1 -1
  33. package/dist/core/rebase/types.js +30 -16
  34. package/dist/core/rebase/types.js.map +1 -1
  35. package/dist/core/schema-stored/formatV1.d.ts +2 -2
  36. package/dist/core/schema-stored/formatV1.d.ts.map +1 -1
  37. package/dist/core/schema-stored/formatV1.js +0 -5
  38. package/dist/core/schema-stored/formatV1.js.map +1 -1
  39. package/dist/core/schema-stored/formatV2.d.ts +11 -10
  40. package/dist/core/schema-stored/formatV2.d.ts.map +1 -1
  41. package/dist/core/schema-stored/formatV2.js +1 -6
  42. package/dist/core/schema-stored/formatV2.js.map +1 -1
  43. package/dist/core/schema-stored/index.d.ts.map +1 -1
  44. package/dist/core/schema-stored/index.js.map +1 -1
  45. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  46. package/dist/core/schema-stored/schema.js.map +1 -1
  47. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  48. package/dist/core/tree/anchorSet.js.map +1 -1
  49. package/dist/core/tree/delta.d.ts +9 -7
  50. package/dist/core/tree/delta.d.ts.map +1 -1
  51. package/dist/core/tree/delta.js.map +1 -1
  52. package/dist/core/tree/deltaUtil.js +1 -1
  53. package/dist/core/tree/deltaUtil.js.map +1 -1
  54. package/dist/core/tree/visitDelta.js +2 -2
  55. package/dist/core/tree/visitDelta.js.map +1 -1
  56. package/dist/extensibleSchemaUnion.d.ts +72 -0
  57. package/dist/extensibleSchemaUnion.d.ts.map +1 -0
  58. package/dist/extensibleSchemaUnion.js +79 -0
  59. package/dist/extensibleSchemaUnion.js.map +1 -0
  60. package/dist/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  61. package/dist/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  62. package/dist/feature-libraries/changeAtomIdBTree.js +9 -1
  63. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -1
  64. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  65. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  66. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +20 -21
  67. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  68. package/dist/feature-libraries/default-schema/index.d.ts +1 -1
  69. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  70. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  71. package/dist/feature-libraries/forest-summary/codec.d.ts +2 -1
  72. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  73. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  74. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  75. package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -2
  76. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  77. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +1 -39
  78. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  79. package/dist/feature-libraries/forest-summary/formatCommon.js +1 -2
  80. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  81. package/dist/feature-libraries/forest-summary/formatV1.d.ts +1 -39
  82. package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  83. package/dist/feature-libraries/forest-summary/formatV2.d.ts +1 -39
  84. package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  85. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  86. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  87. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  88. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  89. package/dist/feature-libraries/index.d.ts +3 -3
  90. package/dist/feature-libraries/index.d.ts.map +1 -1
  91. package/dist/feature-libraries/index.js +4 -3
  92. package/dist/feature-libraries/index.js.map +1 -1
  93. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  94. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  95. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +42 -22
  96. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  97. package/dist/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  98. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  99. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  100. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  101. package/dist/feature-libraries/modular-schema/index.js +2 -1
  102. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  103. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +1 -1
  104. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  105. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +9 -5
  106. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  107. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  108. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  109. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +30 -7
  110. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  111. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  112. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +38 -27
  113. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  114. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  115. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  116. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  117. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  118. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  119. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  120. package/dist/feature-libraries/optional-field/optionalField.js +1 -1
  121. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  122. package/dist/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  123. package/dist/feature-libraries/optional-field/requiredField.js.map +1 -1
  124. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  125. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  126. package/dist/feature-libraries/schema-index/formatV2.d.ts +4 -4
  127. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  128. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  129. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  130. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  131. package/dist/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  132. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  133. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  134. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  135. package/dist/index.d.ts +5 -5
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +4 -1
  138. package/dist/index.js.map +1 -1
  139. package/dist/legacy.d.ts +3 -0
  140. package/dist/packageVersion.d.ts +1 -1
  141. package/dist/packageVersion.js +1 -1
  142. package/dist/packageVersion.js.map +1 -1
  143. package/dist/shared-tree/independentView.d.ts +36 -13
  144. package/dist/shared-tree/independentView.d.ts.map +1 -1
  145. package/dist/shared-tree/independentView.js +1 -0
  146. package/dist/shared-tree/independentView.js.map +1 -1
  147. package/dist/shared-tree/index.d.ts +1 -1
  148. package/dist/shared-tree/index.d.ts.map +1 -1
  149. package/dist/shared-tree/index.js.map +1 -1
  150. package/dist/shared-tree/schematizingTreeView.d.ts +10 -0
  151. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  152. package/dist/shared-tree/schematizingTreeView.js +25 -9
  153. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  154. package/dist/shared-tree/sharedTree.d.ts +3 -3
  155. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  156. package/dist/shared-tree/sharedTree.js +8 -32
  157. package/dist/shared-tree/sharedTree.js.map +1 -1
  158. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  159. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  160. package/dist/shared-tree/sharedTreeChangeCodecs.js +38 -4
  161. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  162. package/dist/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  163. package/dist/shared-tree/tree.js +1 -1
  164. package/dist/shared-tree/tree.js.map +1 -1
  165. package/dist/shared-tree/treeCheckout.d.ts +20 -0
  166. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  167. package/dist/shared-tree/treeCheckout.js +39 -3
  168. package/dist/shared-tree/treeCheckout.js.map +1 -1
  169. package/dist/shared-tree-core/editManagerSummarizer.js +1 -1
  170. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  171. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  172. package/dist/shared-tree-core/messageCodecV1ToV4.js +2 -2
  173. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  174. package/dist/shared-tree-core/transaction.d.ts +14 -3
  175. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  176. package/dist/shared-tree-core/transaction.js +59 -16
  177. package/dist/shared-tree-core/transaction.js.map +1 -1
  178. package/dist/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  179. package/dist/shared-tree-core/versionedSummarizer.js +1 -1
  180. package/dist/shared-tree-core/versionedSummarizer.js.map +1 -1
  181. package/dist/simple-tree/api/index.d.ts +1 -1
  182. package/dist/simple-tree/api/index.d.ts.map +1 -1
  183. package/dist/simple-tree/api/index.js +3 -2
  184. package/dist/simple-tree/api/index.js.map +1 -1
  185. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  186. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  187. package/dist/simple-tree/api/schemaCreationUtilities.js +16 -1
  188. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  189. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  190. package/dist/simple-tree/api/transactionTypes.d.ts +10 -0
  191. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  192. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  193. package/dist/simple-tree/api/tree.d.ts +81 -6
  194. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  195. package/dist/simple-tree/api/tree.js.map +1 -1
  196. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  197. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  198. package/dist/simple-tree/index.d.ts +2 -2
  199. package/dist/simple-tree/index.d.ts.map +1 -1
  200. package/dist/simple-tree/index.js +4 -2
  201. package/dist/simple-tree/index.js.map +1 -1
  202. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  203. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  204. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  205. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  206. package/dist/simple-tree/node-kinds/array/arrayNode.js +43 -1
  207. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  208. package/dist/simple-tree/node-kinds/array/index.d.ts +1 -1
  209. package/dist/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  210. package/dist/simple-tree/node-kinds/array/index.js +2 -1
  211. package/dist/simple-tree/node-kinds/array/index.js.map +1 -1
  212. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  213. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  214. package/dist/simple-tree/node-kinds/index.js +2 -1
  215. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  216. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  217. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  218. package/dist/tableSchema.d.ts +71 -48
  219. package/dist/tableSchema.d.ts.map +1 -1
  220. package/dist/tableSchema.js +200 -98
  221. package/dist/tableSchema.js.map +1 -1
  222. package/dist/text/textDomainFormatted.js +1 -1
  223. package/dist/text/textDomainFormatted.js.map +1 -1
  224. package/dist/util/bTreeUtils.d.ts +30 -4
  225. package/dist/util/bTreeUtils.d.ts.map +1 -1
  226. package/dist/util/bTreeUtils.js +29 -17
  227. package/dist/util/bTreeUtils.js.map +1 -1
  228. package/dist/util/brand.d.ts.map +1 -1
  229. package/dist/util/brand.js.map +1 -1
  230. package/dist/util/brandedMap.d.ts.map +1 -1
  231. package/dist/util/brandedMap.js.map +1 -1
  232. package/dist/util/breakable.d.ts.map +1 -1
  233. package/dist/util/breakable.js +2 -1
  234. package/dist/util/breakable.js.map +1 -1
  235. package/dist/util/index.d.ts +2 -2
  236. package/dist/util/index.d.ts.map +1 -1
  237. package/dist/util/index.js +6 -3
  238. package/dist/util/index.js.map +1 -1
  239. package/dist/util/opaque.d.ts.map +1 -1
  240. package/dist/util/opaque.js.map +1 -1
  241. package/dist/util/rangeMap.d.ts +3 -2
  242. package/dist/util/rangeMap.d.ts.map +1 -1
  243. package/dist/util/rangeMap.js +7 -1
  244. package/dist/util/rangeMap.js.map +1 -1
  245. package/dist/util/readSnapshotBlob.d.ts +1 -1
  246. package/dist/util/readSnapshotBlob.d.ts.map +1 -1
  247. package/dist/util/readSnapshotBlob.js.map +1 -1
  248. package/dist/util/typeCheck.d.ts.map +1 -1
  249. package/dist/util/typeCheck.js.map +1 -1
  250. package/dist/util/utils.d.ts +20 -16
  251. package/dist/util/utils.d.ts.map +1 -1
  252. package/dist/util/utils.js +49 -17
  253. package/dist/util/utils.js.map +1 -1
  254. package/eslint.config.mts +0 -9
  255. package/lib/alpha.d.ts +8 -2
  256. package/lib/beta.d.ts +3 -0
  257. package/lib/codec/codec.d.ts +17 -8
  258. package/lib/codec/codec.d.ts.map +1 -1
  259. package/lib/codec/codec.js +6 -0
  260. package/lib/codec/codec.js.map +1 -1
  261. package/lib/codec/index.d.ts +1 -1
  262. package/lib/codec/index.d.ts.map +1 -1
  263. package/lib/codec/index.js +1 -1
  264. package/lib/codec/index.js.map +1 -1
  265. package/lib/codec/versioned/codec.d.ts +1 -1
  266. package/lib/codec/versioned/codec.d.ts.map +1 -1
  267. package/lib/codec/versioned/codec.js.map +1 -1
  268. package/lib/core/index.d.ts +1 -1
  269. package/lib/core/index.d.ts.map +1 -1
  270. package/lib/core/index.js +1 -1
  271. package/lib/core/index.js.map +1 -1
  272. package/lib/core/rebase/changeRebaser.d.ts +3 -2
  273. package/lib/core/rebase/changeRebaser.d.ts.map +1 -1
  274. package/lib/core/rebase/changeRebaser.js.map +1 -1
  275. package/lib/core/rebase/index.d.ts +1 -1
  276. package/lib/core/rebase/index.d.ts.map +1 -1
  277. package/lib/core/rebase/index.js +1 -1
  278. package/lib/core/rebase/index.js.map +1 -1
  279. package/lib/core/rebase/types.d.ts +23 -3
  280. package/lib/core/rebase/types.d.ts.map +1 -1
  281. package/lib/core/rebase/types.js +27 -15
  282. package/lib/core/rebase/types.js.map +1 -1
  283. package/lib/core/schema-stored/formatV1.d.ts +2 -2
  284. package/lib/core/schema-stored/formatV1.d.ts.map +1 -1
  285. package/lib/core/schema-stored/formatV1.js +0 -5
  286. package/lib/core/schema-stored/formatV1.js.map +1 -1
  287. package/lib/core/schema-stored/formatV2.d.ts +11 -10
  288. package/lib/core/schema-stored/formatV2.d.ts.map +1 -1
  289. package/lib/core/schema-stored/formatV2.js +1 -6
  290. package/lib/core/schema-stored/formatV2.js.map +1 -1
  291. package/lib/core/schema-stored/index.d.ts.map +1 -1
  292. package/lib/core/schema-stored/index.js +2 -0
  293. package/lib/core/schema-stored/index.js.map +1 -1
  294. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  295. package/lib/core/schema-stored/schema.js.map +1 -1
  296. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  297. package/lib/core/tree/anchorSet.js.map +1 -1
  298. package/lib/core/tree/delta.d.ts +9 -7
  299. package/lib/core/tree/delta.d.ts.map +1 -1
  300. package/lib/core/tree/delta.js.map +1 -1
  301. package/lib/core/tree/deltaUtil.js +1 -1
  302. package/lib/core/tree/deltaUtil.js.map +1 -1
  303. package/lib/core/tree/visitDelta.js +2 -2
  304. package/lib/core/tree/visitDelta.js.map +1 -1
  305. package/lib/extensibleSchemaUnion.d.ts +72 -0
  306. package/lib/extensibleSchemaUnion.d.ts.map +1 -0
  307. package/lib/extensibleSchemaUnion.js +76 -0
  308. package/lib/extensibleSchemaUnion.js.map +1 -0
  309. package/lib/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  310. package/lib/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  311. package/lib/feature-libraries/changeAtomIdBTree.js +7 -0
  312. package/lib/feature-libraries/changeAtomIdBTree.js.map +1 -1
  313. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  314. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  315. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +4 -5
  316. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  317. package/lib/feature-libraries/default-schema/index.d.ts +1 -1
  318. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  319. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  320. package/lib/feature-libraries/forest-summary/codec.d.ts +2 -1
  321. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  322. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  323. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  324. package/lib/feature-libraries/forest-summary/forestSummarizer.js +6 -3
  325. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  326. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +1 -39
  327. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  328. package/lib/feature-libraries/forest-summary/formatCommon.js +2 -3
  329. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  330. package/lib/feature-libraries/forest-summary/formatV1.d.ts +1 -39
  331. package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  332. package/lib/feature-libraries/forest-summary/formatV2.d.ts +1 -39
  333. package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  334. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  335. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  336. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  337. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  338. package/lib/feature-libraries/index.d.ts +3 -3
  339. package/lib/feature-libraries/index.d.ts.map +1 -1
  340. package/lib/feature-libraries/index.js +3 -3
  341. package/lib/feature-libraries/index.js.map +1 -1
  342. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  343. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  344. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +41 -21
  345. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  346. package/lib/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  347. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  348. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  349. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  350. package/lib/feature-libraries/modular-schema/index.js +1 -1
  351. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  352. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +1 -1
  353. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  354. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +10 -6
  355. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  356. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  357. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  358. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +29 -6
  359. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  360. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  361. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +41 -30
  362. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  363. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  364. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  365. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  366. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  367. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  368. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  369. package/lib/feature-libraries/optional-field/optionalField.js +1 -1
  370. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  371. package/lib/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  372. package/lib/feature-libraries/optional-field/requiredField.js.map +1 -1
  373. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  374. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  375. package/lib/feature-libraries/schema-index/formatV2.d.ts +4 -4
  376. package/lib/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  377. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  378. package/lib/feature-libraries/sequence-field/invert.js +2 -2
  379. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  380. package/lib/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  381. package/lib/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  382. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  383. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  384. package/lib/index.d.ts +5 -5
  385. package/lib/index.d.ts.map +1 -1
  386. package/lib/index.js +4 -3
  387. package/lib/index.js.map +1 -1
  388. package/lib/legacy.d.ts +3 -0
  389. package/lib/packageVersion.d.ts +1 -1
  390. package/lib/packageVersion.js +1 -1
  391. package/lib/packageVersion.js.map +1 -1
  392. package/lib/shared-tree/independentView.d.ts +36 -13
  393. package/lib/shared-tree/independentView.d.ts.map +1 -1
  394. package/lib/shared-tree/independentView.js +1 -0
  395. package/lib/shared-tree/independentView.js.map +1 -1
  396. package/lib/shared-tree/index.d.ts +1 -1
  397. package/lib/shared-tree/index.d.ts.map +1 -1
  398. package/lib/shared-tree/index.js.map +1 -1
  399. package/lib/shared-tree/schematizingTreeView.d.ts +10 -0
  400. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  401. package/lib/shared-tree/schematizingTreeView.js +25 -9
  402. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  403. package/lib/shared-tree/sharedTree.d.ts +3 -3
  404. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  405. package/lib/shared-tree/sharedTree.js +10 -34
  406. package/lib/shared-tree/sharedTree.js.map +1 -1
  407. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  408. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  409. package/lib/shared-tree/sharedTreeChangeCodecs.js +39 -5
  410. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  411. package/lib/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  412. package/lib/shared-tree/tree.js +1 -1
  413. package/lib/shared-tree/tree.js.map +1 -1
  414. package/lib/shared-tree/treeCheckout.d.ts +20 -0
  415. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  416. package/lib/shared-tree/treeCheckout.js +39 -3
  417. package/lib/shared-tree/treeCheckout.js.map +1 -1
  418. package/lib/shared-tree-core/editManagerSummarizer.js +1 -1
  419. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  420. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  421. package/lib/shared-tree-core/messageCodecV1ToV4.js +2 -2
  422. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  423. package/lib/shared-tree-core/transaction.d.ts +14 -3
  424. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  425. package/lib/shared-tree-core/transaction.js +61 -18
  426. package/lib/shared-tree-core/transaction.js.map +1 -1
  427. package/lib/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  428. package/lib/shared-tree-core/versionedSummarizer.js +1 -1
  429. package/lib/shared-tree-core/versionedSummarizer.js.map +1 -1
  430. package/lib/simple-tree/api/index.d.ts +1 -1
  431. package/lib/simple-tree/api/index.d.ts.map +1 -1
  432. package/lib/simple-tree/api/index.js +1 -1
  433. package/lib/simple-tree/api/index.js.map +1 -1
  434. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  435. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  436. package/lib/simple-tree/api/schemaCreationUtilities.js +14 -0
  437. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  438. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  439. package/lib/simple-tree/api/transactionTypes.d.ts +10 -0
  440. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  441. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  442. package/lib/simple-tree/api/tree.d.ts +81 -6
  443. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  444. package/lib/simple-tree/api/tree.js.map +1 -1
  445. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  446. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  447. package/lib/simple-tree/index.d.ts +2 -2
  448. package/lib/simple-tree/index.d.ts.map +1 -1
  449. package/lib/simple-tree/index.js +2 -2
  450. package/lib/simple-tree/index.js.map +1 -1
  451. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  452. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  453. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  454. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  455. package/lib/simple-tree/node-kinds/array/arrayNode.js +41 -0
  456. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  457. package/lib/simple-tree/node-kinds/array/index.d.ts +1 -1
  458. package/lib/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  459. package/lib/simple-tree/node-kinds/array/index.js +1 -1
  460. package/lib/simple-tree/node-kinds/array/index.js.map +1 -1
  461. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  462. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  463. package/lib/simple-tree/node-kinds/index.js +1 -1
  464. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  465. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  466. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  467. package/lib/tableSchema.d.ts +71 -48
  468. package/lib/tableSchema.d.ts.map +1 -1
  469. package/lib/tableSchema.js +201 -99
  470. package/lib/tableSchema.js.map +1 -1
  471. package/lib/text/textDomainFormatted.js +1 -1
  472. package/lib/text/textDomainFormatted.js.map +1 -1
  473. package/lib/util/bTreeUtils.d.ts +30 -4
  474. package/lib/util/bTreeUtils.d.ts.map +1 -1
  475. package/lib/util/bTreeUtils.js +27 -16
  476. package/lib/util/bTreeUtils.js.map +1 -1
  477. package/lib/util/brand.d.ts.map +1 -1
  478. package/lib/util/brand.js.map +1 -1
  479. package/lib/util/brandedMap.d.ts.map +1 -1
  480. package/lib/util/brandedMap.js.map +1 -1
  481. package/lib/util/breakable.d.ts.map +1 -1
  482. package/lib/util/breakable.js +2 -1
  483. package/lib/util/breakable.js.map +1 -1
  484. package/lib/util/index.d.ts +2 -2
  485. package/lib/util/index.d.ts.map +1 -1
  486. package/lib/util/index.js +2 -2
  487. package/lib/util/index.js.map +1 -1
  488. package/lib/util/opaque.d.ts.map +1 -1
  489. package/lib/util/opaque.js.map +1 -1
  490. package/lib/util/rangeMap.d.ts +3 -2
  491. package/lib/util/rangeMap.d.ts.map +1 -1
  492. package/lib/util/rangeMap.js +7 -1
  493. package/lib/util/rangeMap.js.map +1 -1
  494. package/lib/util/readSnapshotBlob.d.ts +1 -1
  495. package/lib/util/readSnapshotBlob.d.ts.map +1 -1
  496. package/lib/util/readSnapshotBlob.js.map +1 -1
  497. package/lib/util/typeCheck.d.ts.map +1 -1
  498. package/lib/util/typeCheck.js.map +1 -1
  499. package/lib/util/utils.d.ts +20 -16
  500. package/lib/util/utils.d.ts.map +1 -1
  501. package/lib/util/utils.js +44 -15
  502. package/lib/util/utils.js.map +1 -1
  503. package/package.json +23 -23
  504. package/src/codec/codec.ts +30 -11
  505. package/src/codec/index.ts +2 -0
  506. package/src/codec/versioned/codec.ts +9 -13
  507. package/src/core/index.ts +3 -1
  508. package/src/core/rebase/changeRebaser.ts +3 -2
  509. package/src/core/rebase/index.ts +3 -1
  510. package/src/core/rebase/types.ts +51 -13
  511. package/src/core/schema-stored/formatV1.ts +2 -4
  512. package/src/core/schema-stored/formatV2.ts +9 -7
  513. package/src/core/schema-stored/index.ts +2 -0
  514. package/src/core/schema-stored/schema.ts +4 -1
  515. package/src/core/tree/anchorSet.ts +1 -3
  516. package/src/core/tree/delta.ts +9 -7
  517. package/src/core/tree/deltaUtil.ts +1 -1
  518. package/src/core/tree/visitDelta.ts +2 -2
  519. package/src/extensibleSchemaUnion.ts +135 -0
  520. package/src/feature-libraries/changeAtomIdBTree.ts +17 -2
  521. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +5 -6
  522. package/src/feature-libraries/default-schema/index.ts +0 -1
  523. package/src/feature-libraries/forest-summary/codec.ts +7 -2
  524. package/src/feature-libraries/forest-summary/forestSummarizer.ts +15 -3
  525. package/src/feature-libraries/forest-summary/formatCommon.ts +2 -3
  526. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +4 -5
  527. package/src/feature-libraries/index.ts +3 -2
  528. package/src/feature-libraries/modular-schema/defaultRevisionReplacer.ts +57 -31
  529. package/src/feature-libraries/modular-schema/genericFieldKind.ts +1 -1
  530. package/src/feature-libraries/modular-schema/index.ts +4 -1
  531. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +7 -6
  532. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +32 -7
  533. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +54 -33
  534. package/src/feature-libraries/modular-schema/modularChangeFormatV1.ts +2 -4
  535. package/src/feature-libraries/optional-field/optionalField.ts +1 -1
  536. package/src/feature-libraries/optional-field/requiredField.ts +2 -4
  537. package/src/feature-libraries/schema-index/codec.ts +1 -1
  538. package/src/feature-libraries/schema-index/schemaSummarizer.ts +1 -1
  539. package/src/feature-libraries/sequence-field/invert.ts +2 -2
  540. package/src/feature-libraries/sequence-field/replaceRevisions.ts +17 -10
  541. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +1 -1
  542. package/src/index.ts +12 -7
  543. package/src/packageVersion.ts +1 -1
  544. package/src/shared-tree/independentView.ts +42 -6
  545. package/src/shared-tree/index.ts +2 -0
  546. package/src/shared-tree/schematizingTreeView.ts +63 -18
  547. package/src/shared-tree/sharedTree.ts +19 -37
  548. package/src/shared-tree/sharedTreeChangeCodecs.ts +43 -9
  549. package/src/shared-tree/tree.ts +1 -1
  550. package/src/shared-tree/treeCheckout.ts +50 -3
  551. package/src/shared-tree-core/editManagerSummarizer.ts +1 -1
  552. package/src/shared-tree-core/messageCodecV1ToV4.ts +4 -3
  553. package/src/shared-tree-core/transaction.ts +125 -23
  554. package/src/shared-tree-core/versionedSummarizer.ts +3 -2
  555. package/src/simple-tree/api/index.ts +1 -0
  556. package/src/simple-tree/api/schemaCreationUtilities.ts +35 -5
  557. package/src/simple-tree/api/simpleTreeIndex.ts +1 -1
  558. package/src/simple-tree/api/transactionTypes.ts +10 -0
  559. package/src/simple-tree/api/tree.ts +88 -6
  560. package/src/simple-tree/core/treeNodeSchema.ts +5 -8
  561. package/src/simple-tree/index.ts +3 -0
  562. package/src/simple-tree/leafNodeSchema.ts +3 -2
  563. package/src/simple-tree/node-kinds/array/arrayNode.ts +86 -0
  564. package/src/simple-tree/node-kinds/array/index.ts +2 -0
  565. package/src/simple-tree/node-kinds/index.ts +2 -0
  566. package/src/simple-tree/node-kinds/object/objectNode.ts +19 -18
  567. package/src/tableSchema.ts +280 -140
  568. package/src/text/textDomainFormatted.ts +1 -1
  569. package/src/util/bTreeUtils.ts +45 -26
  570. package/src/util/brand.ts +4 -12
  571. package/src/util/brandedMap.ts +2 -6
  572. package/src/util/breakable.ts +3 -2
  573. package/src/util/index.ts +9 -3
  574. package/src/util/opaque.ts +2 -6
  575. package/src/util/rangeMap.ts +11 -5
  576. package/src/util/readSnapshotBlob.ts +3 -3
  577. package/src/util/typeCheck.ts +11 -9
  578. package/src/util/utils.ts +57 -28
  579. package/biome.jsonc +0 -4
@@ -17,8 +17,8 @@ var _TransactionStack_stack, _TransactionStack_onPush, _TransactionStack_events,
17
17
  import { createEmitter } from "@fluid-internal/client-utils";
18
18
  import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
19
19
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
20
- import { findAncestor, tagChange, } from "../core/index.js";
21
- import { getLast, getOrCreate, hasSome } from "../util/index.js";
20
+ import { diffHistories, findAncestor, findCommonAncestor, mintCommit, rebaseBranch, tagChange, } from "../core/index.js";
21
+ import { getLast, getOrCreate } from "../util/index.js";
22
22
  /**
23
23
  * Describes the result of a transaction.
24
24
  * Transactions may either succeed and commit, or fail and abort.
@@ -60,11 +60,18 @@ export class TransactionStack {
60
60
  this.ensureNotDisposed();
61
61
  return __classPrivateFieldGet(this, _TransactionStack_stack, "f").length > 0;
62
62
  }
63
- start() {
63
+ start(isAsync) {
64
64
  this.ensureNotDisposed();
65
- const onPushCurrent = hasSome(__classPrivateFieldGet(this, _TransactionStack_stack, "f")) ? getLast(__classPrivateFieldGet(this, _TransactionStack_stack, "f")).onPush : __classPrivateFieldGet(this, _TransactionStack_onPush, "f");
65
+ const last = getLast(__classPrivateFieldGet(this, _TransactionStack_stack, "f"));
66
+ if (last !== undefined && !last.isAsync && isAsync) {
67
+ throw new UsageError("An asynchronous transaction cannot be started while a synchronous transaction is in progress.");
68
+ }
69
+ const onPushCurrent = last === undefined ? __classPrivateFieldGet(this, _TransactionStack_onPush, "f") : last.callbacks.onPush;
66
70
  const { onPush, onPop } = onPushCurrent?.() ?? {};
67
- __classPrivateFieldGet(this, _TransactionStack_stack, "f").push({ onPop, onPush: onPush ?? onPushCurrent });
71
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").push({
72
+ callbacks: { onPop, onPush: onPush ?? onPushCurrent },
73
+ isAsync,
74
+ });
68
75
  __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("started");
69
76
  }
70
77
  commit() {
@@ -73,7 +80,7 @@ export class TransactionStack {
73
80
  throw new UsageError("No transaction to commit");
74
81
  }
75
82
  __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("committing");
76
- __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.onPop?.(TransactionResult.Commit);
83
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.callbacks.onPop?.(TransactionResult.Commit);
77
84
  }
78
85
  abort() {
79
86
  this.ensureNotDisposed();
@@ -81,7 +88,7 @@ export class TransactionStack {
81
88
  throw new UsageError("No transaction to abort");
82
89
  }
83
90
  __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("aborting");
84
- __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.onPop?.(TransactionResult.Abort);
91
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.callbacks.onPop?.(TransactionResult.Abort);
85
92
  }
86
93
  dispose() {
87
94
  this.ensureNotDisposed();
@@ -143,8 +150,8 @@ export class SquashingTransactionStack extends TransactionStack {
143
150
  // Invoked when an outer transaction starts
144
151
  () => {
145
152
  // Keep track of the commit that each transaction was on when it started
146
- // TODO:#8603: This may need to be computed differently if we allow rebasing during a transaction.
147
153
  const startHead = this.activeBranch.getHead();
154
+ const rebaser = this.branch.changeFamily.rebaser;
148
155
  const outerOnPop = onPush?.();
149
156
  let transactionRevision;
150
157
  const transactionBranch = this.branch.fork(startHead,
@@ -156,22 +163,58 @@ export class SquashingTransactionStack extends TransactionStack {
156
163
  const onOuterTransactionPop = (result) => {
157
164
  assert(!this.isInProgress(), 0xcae /* The outer transaction should be ending */);
158
165
  transactionBranch.editor.exitTransaction();
166
+ const sourcePath = [];
167
+ const targetPath = [];
168
+ const ancestor = findCommonAncestor([startHead, sourcePath], [branch.getHead(), targetPath]);
169
+ assert(ancestor !== undefined, 0xcce /* branches must be related */);
170
+ const transactionSteps = [];
171
+ findAncestor([transactionBranch.getHead(), transactionSteps], (c) => c === startHead);
172
+ let viewUpdate;
159
173
  switch (result) {
160
174
  case TransactionResult.Abort: {
161
- // When a transaction is aborted, roll back all the transaction's changes on the current branch
175
+ // When a transaction is aborted, roll back all the transaction's changes on the current branch.
176
+ // It is important that this happens before and separately from updating the view because the `TreeCheckout` needs to
177
+ // revert some internal (state to match what it was before the transaction began) before applying the view update (if any).
162
178
  transactionBranch.removeAfter(startHead);
179
+ // If changes were made on `branch` since the transaction began, the view will need to be updated to reflect those changes.
180
+ if (targetPath.length > 0) {
181
+ viewUpdate = diffHistories(rebaser, startHead, this.branch.getHead(), mintRevisionTag);
182
+ }
163
183
  break;
164
184
  }
165
185
  case TransactionResult.Commit: {
166
- // ...squash all the new commits on the transaction branch into a new commit on the original branch
167
- const removedCommits = [];
168
- findAncestor([transactionBranch.getHead(), removedCommits], (c) => c === startHead);
169
- if (removedCommits.length > 0) {
170
- for (const commit of removedCommits) {
186
+ if (transactionSteps.length > 0) {
187
+ assert(transactionRevision !== undefined, 0xccf /* Expected transaction revision in the presence of transaction steps */);
188
+ for (const commit of transactionSteps) {
171
189
  assert(commit.revision === transactionRevision, 0xcaf /* Unexpected commit in transaction */);
172
190
  }
173
- const squash = this.branch.changeFamily.rebaser.compose(removedCommits);
174
- this.branch.apply(tagChange(squash, transactionRevision));
191
+ // Squash all the new commits on the transaction branch into a new commit on the original branch
192
+ const squash = rebaser.compose(transactionSteps);
193
+ if (targetPath.length === 0) {
194
+ // No changes were made on the original branch since the transaction began
195
+ // The transaction commit can be applied directly
196
+ this.branch.apply(tagChange(squash, transactionRevision));
197
+ // The view is already up-to-date so there's nothing more to do
198
+ }
199
+ else {
200
+ // Some changes were made on `branch` since the transaction began
201
+ const unrebasedHead = mintCommit(startHead, {
202
+ change: squash,
203
+ revision: transactionRevision,
204
+ });
205
+ // We need to rebase the transaction commit on top of the new changes
206
+ const rebased = rebaseBranch(mintRevisionTag, rebaser, unrebasedHead, branch.getHead());
207
+ assert(rebased.newSourceHead.revision === transactionRevision, 0xcd0 /* The transaction commit should be rebased to the tip */);
208
+ this.branch.apply(rebased.newSourceHead);
209
+ viewUpdate = rebased.sourceChange;
210
+ }
211
+ }
212
+ else {
213
+ if (targetPath.length > 0) {
214
+ // Changes were made on `branch` since the transaction began.
215
+ // The view will need to be updated to reflect those changes.
216
+ viewUpdate = diffHistories(rebaser, startHead, this.branch.getHead(), mintRevisionTag);
217
+ }
175
218
  }
176
219
  break;
177
220
  }
@@ -181,7 +224,7 @@ export class SquashingTransactionStack extends TransactionStack {
181
224
  }
182
225
  transactionBranch.dispose();
183
226
  this.setTransactionBranch(undefined);
184
- outerOnPop?.(result);
227
+ outerOnPop?.(result, viewUpdate);
185
228
  };
186
229
  // Invoked when a nested transaction begins
187
230
  const onNestedTransactionPush = () => {
@@ -205,7 +248,7 @@ export class SquashingTransactionStack extends TransactionStack {
205
248
  unreachableCase(result);
206
249
  }
207
250
  }
208
- nestedOuterOnPop?.(result);
251
+ nestedOuterOnPop?.(result, undefined);
209
252
  },
210
253
  };
211
254
  };
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/shared-tree-core/transaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO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MAAM,CAAC,CAAC;oBAC5B,CAAC;iBACD,CAAC;YACH,CAAC,CAAC;YACF,OAAO,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;QAC1E,CAAC,CACD,CAAC;QApFc,WAAM,GAAN,MAAM,CAAoC;QA5D3D,+DAAwD;QAExD;;;;WAIG;QACa,uBAAkB,GAAG,IAAI,KAAK,CAAU,EAAwB,EAAE;YACjF,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE;gBACvB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC3D,CAAC;SACD,CAAC,CAAC;QAoCM,wDAAsB,IAAI,GAAG,EAKnC,EAAC;IA6FJ,CAAC;IAED,sGAAsG;IAC9F,oBAAoB,CAC3B,iBAAiE;QAEjE,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC;QAC1C,uBAAA,IAAI,gDAAsB,iBAAiB,MAAA,CAAC;QAC5C,KAAK,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,uBAAA,IAAI,qDAAoB,EAAE,CAAC;YAC/D,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBAClC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBAChD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { IDisposable, Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tfindAncestor,\n\ttagChange,\n\ttype ChangeFamilyEditor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n} from \"../core/index.js\";\nimport { getLast, getOrCreate, hasSome } from \"../util/index.js\";\n\nimport type { SharedTreeBranch, SharedTreeBranchEvents } from \"./branch.js\";\n\n/**\n * Describes the result of a transaction.\n * Transactions may either succeed and commit, or fail and abort.\n */\nexport enum TransactionResult {\n\t/**\n\t * Indicates the transaction failed.\n\t */\n\tAbort,\n\t/**\n\t * Indicates the transaction succeeded.\n\t */\n\tCommit,\n}\n\n/**\n * A simple API for managing transactions.\n */\nexport interface Transactor {\n\t/**\n\t * Start a new transaction.\n\t * If a transaction is already in progress when this new transaction starts, then this transaction will be \"nested\" inside of it,\n\t * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.\n\t *\n\t * @remarks Asynchronous transactions are not supported on the root checkout,\n\t * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate\n\t * the transaction) is not visible to the application author.\n\t * Instead,\n\t *\n\t * 1. fork the root checkout\n\t * 2. run the transaction on the fork\n\t * 3. merge the fork back into the root checkout\n\t *\n\t * @privateRemarks There is currently no enforcement that asynchronous transactions don't happen on the root checkout.\n\t * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.\n\t */\n\tstart(): void;\n\t/**\n\t * Close this transaction by squashing its edits and committing them as a single edit.\n\t * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.\n\t */\n\tcommit(): void;\n\t/**\n\t * Close this transaction and revert the state of the tree to what it was before this transaction began.\n\t */\n\tabort(): void;\n\t/**\n\t * True if there is at least one transaction currently in progress on this view, otherwise false.\n\t */\n\tisInProgress(): boolean;\n\t/**\n\t * Provides events for changes in transaction progress.\n\t */\n\tevents: Listenable<TransactionEvents>;\n}\n\nexport interface TransactionEvents {\n\t/**\n\t * Raised just after a transaction has begun.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will be true because the transaction has already begun.\n\t */\n\tstarted(): void;\n\t/**\n\t * Raised just before a transaction is aborted.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\taborting(): void;\n\t/**\n\t * Raised just before a transaction is committed.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\tcommitting(): void;\n}\n\n/**\n * Callbacks for transaction lifecycle events.\n */\nexport interface Callbacks {\n\t/**\n\t * Called when the current transaction is popped from the {@link TransactionStack | stack}.\n\t */\n\treadonly onPop?: OnPop;\n\t/**\n\t * Called when a nested transaction is pushed onto the {@link TransactionStack | stack}.\n\t * @remarks\n\t * Transactions may be arbitrarily nested (by {@link TransactionStack.start | start}ing a transaction within a transaction that is already in progress).\n\t * The `OnPush` callback for an (outer) transaction may optionally return another `OnPush` callback that is associated with any nested (inner) transaction(s).\n\t * In that case, the inner `OnPush` will be called when those inner transactions are pushed and the outer `OnPush` will not be called.\n\t * Put another way, a transaction always results in a call to exactly one `OnPush` callback - whichever is closest to the transaction.\n\t * The event \"bubbles up\" to (and no further past) its first registered callback.\n\t */\n\treadonly onPush?: OnPush;\n}\n\n/**\n * A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.\n * @remarks This function may return other functions that will be called when the transaction is popped from the stack or a nested transaction is pushed onto the stack.\n * This function runs just before the transaction begins, so if this is the beginning of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.\n */\nexport type OnPush = () => Callbacks | void;\n\n/**\n * A function that will be called when a transaction is popped from the {@link TransactionStack | stack}.\n * @remarks This function runs just after the transaction ends, so if this is the end of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.\n */\nexport type OnPop = (result: TransactionResult) => void;\n\n/**\n * An implementation of {@link Transactor} that uses a stack to manage transactions.\n * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.\n */\nexport class TransactionStack implements Transactor, IDisposable {\n\treadonly #stack: Callbacks[] = [];\n\treadonly #onPush?: OnPush;\n\n\treadonly #events = createEmitter<TransactionEvents>();\n\tpublic get events(): Listenable<TransactionEvents> {\n\t\treturn this.#events;\n\t}\n\n\t#disposed = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.#disposed;\n\t}\n\n\t/**\n\t * Construct a new {@link TransactionStack}.\n\t * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.\n\t */\n\tpublic constructor(onPush?: OnPush) {\n\t\tthis.#onPush = onPush;\n\t}\n\n\tpublic isInProgress(): boolean {\n\t\tthis.ensureNotDisposed();\n\t\treturn this.#stack.length > 0;\n\t}\n\n\tpublic start(): void {\n\t\tthis.ensureNotDisposed();\n\t\tconst onPushCurrent = hasSome(this.#stack) ? getLast(this.#stack).onPush : this.#onPush;\n\t\tconst { onPush, onPop } = onPushCurrent?.() ?? {};\n\t\tthis.#stack.push({ onPop, onPush: onPush ?? onPushCurrent });\n\t\tthis.#events.emit(\"started\");\n\t}\n\n\tpublic commit(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to commit\");\n\t\t}\n\t\tthis.#events.emit(\"committing\");\n\t\tthis.#stack.pop()?.onPop?.(TransactionResult.Commit);\n\t}\n\n\tpublic abort(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to abort\");\n\t\t}\n\t\tthis.#events.emit(\"aborting\");\n\t\tthis.#stack.pop()?.onPop?.(TransactionResult.Abort);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.ensureNotDisposed();\n\t\twhile (this.isInProgress()) {\n\t\t\tthis.abort();\n\t\t}\n\t\tthis.#disposed = true;\n\t}\n\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Transactor is disposed\");\n\t\t}\n\t}\n}\n\n/**\n * An implementation of {@link Transactor} that {@link TransactionStack | uses a stack} and a {@link SharedTreeBranch | branch} to manage transactions.\n * @remarks Given a branch, this class will fork the branch when a transaction begins and squash the forked branch back into the original branch when the transaction ends.\n * This class provides conveniences for interacting with the {@link SquashingTransactionStack.activeBranch | active branch} in a way that is stable across transaction boundaries.\n * For example, see {@link SquashingTransactionStack.activeBranchEditor | activeBranchEditor} and {@link SquashingTransactionStack.activeBranchEvents | activeBranchEvents}.\n */\nexport class SquashingTransactionStack<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n> extends TransactionStack {\n\t#transactionBranch?: SharedTreeBranch<TEditor, TChange>;\n\n\t/**\n\t * An editor for whichever branch is currently the {@link SquashingTransactionStack.activeBranch | active branch}.\n\t * @remarks This editor can safely be held on to across transaction boundaries, as it will properly delegate to the correct branch.\n\t * In contrast, it is not safe to hold onto e.g. `activeBranch.editor` across transaction boundaries, since the active branch may change.\n\t */\n\tpublic readonly activeBranchEditor = new Proxy<TEditor>({} as unknown as TEditor, {\n\t\tget: (_, p, receiver) => {\n\t\t\treturn Reflect.get(this.activeBranch.editor, p, receiver);\n\t\t},\n\t});\n\n\t/**\n\t * Get the \"active branch\" for this transactor - either the transaction branch if a transaction is in progress, or the original branch otherwise.\n\t */\n\tpublic get activeBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.#transactionBranch ?? this.branch;\n\t}\n\n\t/**\n\t * Provides events for changes in the {@link SquashingTransactionStack.activeBranch | active branch}.\n\t * @remarks When the active branch changes, the listeners for these events will automatically be transferred to the new active branch.\n\t * In contrast, binding an event to the {@link SquashingTransactionStack.activeBranch | active branch} directly will not automatically transfer the listener when the active branch changes.\n\t */\n\tpublic get activeBranchEvents(): Listenable<SharedTreeBranchEvents<TEditor, TChange>> {\n\t\tconst off = (\n\t\t\teventName: keyof SharedTreeBranchEvents<TEditor, TChange>,\n\t\t\tlistener: SharedTreeBranchEvents<TEditor, TChange>[typeof eventName],\n\t\t): void => {\n\t\t\tthis.activeBranch.events.off(eventName, listener);\n\t\t\tconst listeners = this.#activeBranchEvents.get(eventName);\n\t\t\tif (listeners?.delete(listener) === true && listeners.size === 0) {\n\t\t\t\tthis.#activeBranchEvents.delete(eventName);\n\t\t\t}\n\t\t};\n\n\t\treturn {\n\t\t\ton: (eventName, listener) => {\n\t\t\t\tconst listeners = getOrCreate(this.#activeBranchEvents, eventName, () => new Set());\n\t\t\t\tlisteners.add(listener);\n\t\t\t\tthis.activeBranch.events.on(eventName, listener);\n\t\t\t\treturn () => off(eventName, listener);\n\t\t\t},\n\t\t\toff,\n\t\t};\n\t}\n\treadonly #activeBranchEvents = new Map<\n\t\tkeyof SharedTreeBranchEvents<TEditor, TChange>,\n\t\tSet<\n\t\t\tSharedTreeBranchEvents<TEditor, TChange>[keyof SharedTreeBranchEvents<TEditor, TChange>]\n\t\t>\n\t>();\n\n\t/**\n\t * Construct a new {@link SquashingTransactionStack}.\n\t * @param branch - The {@link SquashingTransactionStack.branch | branch} that will be forked off of when a transaction begins.\n\t * @param onPush - A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly branch: SharedTreeBranch<TEditor, TChange>,\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tonPush?: () => OnPop | void,\n\t) {\n\t\tsuper(\n\t\t\t// Invoked when an outer transaction starts\n\t\t\t(): Callbacks => {\n\t\t\t\t// Keep track of the commit that each transaction was on when it started\n\t\t\t\t// TODO:#8603: This may need to be computed differently if we allow rebasing during a transaction.\n\t\t\t\tconst startHead = this.activeBranch.getHead();\n\t\t\t\tconst outerOnPop = onPush?.();\n\t\t\t\tlet transactionRevision: RevisionTag | undefined;\n\t\t\t\tconst transactionBranch = this.branch.fork(\n\t\t\t\t\tstartHead,\n\t\t\t\t\t// Lazily mint the revision tag for the transaction when it is first needed\n\t\t\t\t\t() => (transactionRevision ??= mintRevisionTag()),\n\t\t\t\t);\n\t\t\t\tthis.setTransactionBranch(transactionBranch);\n\t\t\t\ttransactionBranch.editor.enterTransaction();\n\t\t\t\t// Invoked when an outer transaction ends\n\t\t\t\tconst onOuterTransactionPop: OnPop = (result) => {\n\t\t\t\t\tassert(!this.isInProgress(), 0xcae /* The outer transaction should be ending */);\n\t\t\t\t\ttransactionBranch.editor.exitTransaction();\n\t\t\t\t\tswitch (result) {\n\t\t\t\t\t\tcase TransactionResult.Abort: {\n\t\t\t\t\t\t\t// When a transaction is aborted, roll back all the transaction's changes on the current branch\n\t\t\t\t\t\t\ttransactionBranch.removeAfter(startHead);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase TransactionResult.Commit: {\n\t\t\t\t\t\t\t// ...squash all the new commits on the transaction branch into a new commit on the original branch\n\t\t\t\t\t\t\tconst removedCommits: GraphCommit<TChange>[] = [];\n\t\t\t\t\t\t\tfindAncestor(\n\t\t\t\t\t\t\t\t[transactionBranch.getHead(), removedCommits],\n\t\t\t\t\t\t\t\t(c) => c === startHead,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (removedCommits.length > 0) {\n\t\t\t\t\t\t\t\tfor (const commit of removedCommits) {\n\t\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\t\tcommit.revision === transactionRevision,\n\t\t\t\t\t\t\t\t\t\t0xcaf /* Unexpected commit in transaction */,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst squash = this.branch.changeFamily.rebaser.compose(removedCommits);\n\t\t\t\t\t\t\t\tthis.branch.apply(tagChange(squash, transactionRevision));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\tunreachableCase(result);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\ttransactionBranch.dispose();\n\t\t\t\t\tthis.setTransactionBranch(undefined);\n\t\t\t\t\touterOnPop?.(result);\n\t\t\t\t};\n\t\t\t\t// Invoked when a nested transaction begins\n\t\t\t\tconst onNestedTransactionPush: OnPush = () => {\n\t\t\t\t\tconst nestedStartHead = this.activeBranch.getHead();\n\t\t\t\t\tconst nestedOuterOnPop = onPush?.();\n\t\t\t\t\ttransactionBranch.editor.enterTransaction();\n\t\t\t\t\treturn {\n\t\t\t\t\t\t// Invoked when a nested transaction ends\n\t\t\t\t\t\tonPop: (result) => {\n\t\t\t\t\t\t\ttransactionBranch.editor.exitTransaction();\n\t\t\t\t\t\t\tswitch (result) {\n\t\t\t\t\t\t\t\tcase TransactionResult.Abort: {\n\t\t\t\t\t\t\t\t\t// When a transaction is aborted, roll back all the transaction's changes on the current branch\n\t\t\t\t\t\t\t\t\ttransactionBranch.removeAfter(nestedStartHead);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcase TransactionResult.Commit: {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\t\tunreachableCase(result);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnestedOuterOnPop?.(result);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t\treturn { onPop: onOuterTransactionPop, onPush: onNestedTransactionPush };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Updates the transaction branch (and therefore the active branch) and rebinds the branch events. */\n\tprivate setTransactionBranch(\n\t\ttransactionBranch: SharedTreeBranch<TEditor, TChange> | undefined,\n\t): void {\n\t\tconst oldActiveBranch = this.activeBranch;\n\t\tthis.#transactionBranch = transactionBranch;\n\t\tfor (const [eventName, listeners] of this.#activeBranchEvents) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\toldActiveBranch.events.off(eventName, listener);\n\t\t\t\tthis.activeBranch.events.on(eventName, listener);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src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B,iBAAiE;QAEjE,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC;QAC1C,uBAAA,IAAI,gDAAsB,iBAAiB,MAAA,CAAC;QAC5C,KAAK,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,uBAAA,IAAI,qDAAoB,EAAE,CAAC;YAC/D,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBAClC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBAChD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { IDisposable, Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tdiffHistories,\n\tfindAncestor,\n\tfindCommonAncestor,\n\tmintCommit,\n\trebaseBranch,\n\ttagChange,\n\ttype ChangeFamilyEditor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n} from \"../core/index.js\";\nimport { getLast, getOrCreate } from \"../util/index.js\";\n\nimport type { SharedTreeBranch, SharedTreeBranchEvents } from \"./branch.js\";\n\n/**\n * Describes the result of a transaction.\n * Transactions may either succeed and commit, or fail and abort.\n */\nexport enum TransactionResult {\n\t/**\n\t * Indicates the transaction failed.\n\t */\n\tAbort,\n\t/**\n\t * Indicates the transaction succeeded.\n\t */\n\tCommit,\n}\n\n/**\n * A simple API for managing transactions.\n */\nexport interface Transactor {\n\t/**\n\t * Start a new transaction.\n\t * If a transaction is already in progress when this new transaction starts, then this transaction will be \"nested\" inside of it,\n\t * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.\n\t * @param isAsync - Whether the transaction is asynchronous.\n\t * An error will be thrown if an asynchronous transaction is started while a synchronous transaction is in progress.\n\t *\n\t * @remarks Asynchronous transactions are not supported on the root checkout,\n\t * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate\n\t * the transaction) is not visible to the application author.\n\t * Instead,\n\t *\n\t * 1. fork the root checkout\n\t * 2. run the transaction on the fork\n\t * 3. merge the fork back into the root checkout\n\t *\n\t * @privateRemarks There is currently no enforcement that asynchronous transactions don't happen on the root checkout.\n\t * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.\n\t */\n\tstart(isAsync: boolean): void;\n\t/**\n\t * Close this transaction by squashing its edits and committing them as a single edit.\n\t * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.\n\t */\n\tcommit(): void;\n\t/**\n\t * Close this transaction and revert the state of the tree to what it was before this transaction began.\n\t */\n\tabort(): void;\n\t/**\n\t * True if there is at least one transaction currently in progress on this view, otherwise false.\n\t */\n\tisInProgress(): boolean;\n\t/**\n\t * Provides events for changes in transaction progress.\n\t */\n\tevents: Listenable<TransactionEvents>;\n}\n\nexport interface TransactionEvents {\n\t/**\n\t * Raised just after a transaction has begun.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will be true because the transaction has already begun.\n\t */\n\tstarted(): void;\n\t/**\n\t * Raised just before a transaction is aborted.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\taborting(): void;\n\t/**\n\t * Raised just before a transaction is committed.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\tcommitting(): void;\n}\n\n/**\n * Callbacks for transaction lifecycle events.\n */\nexport interface Callbacks {\n\t/**\n\t * Called when the current transaction is popped from the {@link TransactionStack | stack}.\n\t */\n\treadonly onPop?: OnPop;\n\t/**\n\t * Called when a nested transaction is pushed onto the {@link TransactionStack | stack}.\n\t * @remarks\n\t * Transactions may be arbitrarily nested (by {@link TransactionStack.start | start}ing a transaction within a transaction that is already in progress).\n\t * The `OnPush` callback for an (outer) transaction may optionally return another `OnPush` callback that is associated with any nested (inner) transaction(s).\n\t * In that case, the inner `OnPush` will be called when those inner transactions are pushed and the outer `OnPush` will not be called.\n\t * Put another way, a transaction always results in a call to exactly one `OnPush` callback - whichever is closest to the transaction.\n\t * The event \"bubbles up\" to (and no further past) its first registered callback.\n\t */\n\treadonly onPush?: OnPush;\n}\n\n/**\n * A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.\n * @remarks This function may return other functions that will be called when the transaction is popped from the stack or a nested transaction is pushed onto the stack.\n * This function runs just before the transaction begins, so if this is the beginning of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.\n */\nexport type OnPush = () => Callbacks | void;\n\n/**\n * A function that will be called when a transaction is popped from the {@link TransactionStack | stack}.\n * @remarks This function runs just after the transaction ends, so if this is the end of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.\n */\nexport type OnPop = (result: TransactionResult) => void;\n\n/**\n * A frame in the transaction stack.\n */\ninterface TransactionStackFrame {\n\t/** The callbacks provided when this transaction frame was pushed onto the stack. */\n\treadonly callbacks: Callbacks;\n\t/** Whether this transaction frame is asynchronous. */\n\treadonly isAsync: boolean;\n}\n\n/**\n * An implementation of {@link Transactor} that uses a stack to manage transactions.\n * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.\n */\nexport class TransactionStack implements Transactor, IDisposable {\n\treadonly #stack: TransactionStackFrame[] = [];\n\treadonly #onPush?: OnPush;\n\n\treadonly #events = createEmitter<TransactionEvents>();\n\tpublic get events(): Listenable<TransactionEvents> {\n\t\treturn this.#events;\n\t}\n\n\t#disposed = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.#disposed;\n\t}\n\n\t/**\n\t * Construct a new {@link TransactionStack}.\n\t * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.\n\t */\n\tpublic constructor(onPush?: OnPush) {\n\t\tthis.#onPush = onPush;\n\t}\n\n\tpublic isInProgress(): boolean {\n\t\tthis.ensureNotDisposed();\n\t\treturn this.#stack.length > 0;\n\t}\n\n\tpublic start(isAsync: boolean): void {\n\t\tthis.ensureNotDisposed();\n\t\tconst last = getLast(this.#stack);\n\t\tif (last !== undefined && !last.isAsync && isAsync) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"An asynchronous transaction cannot be started while a synchronous transaction is in progress.\",\n\t\t\t);\n\t\t}\n\t\tconst onPushCurrent = last === undefined ? this.#onPush : last.callbacks.onPush;\n\t\tconst { onPush, onPop } = onPushCurrent?.() ?? {};\n\t\tthis.#stack.push({\n\t\t\tcallbacks: { onPop, onPush: onPush ?? onPushCurrent },\n\t\t\tisAsync,\n\t\t});\n\t\tthis.#events.emit(\"started\");\n\t}\n\n\tpublic commit(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to commit\");\n\t\t}\n\t\tthis.#events.emit(\"committing\");\n\t\tthis.#stack.pop()?.callbacks.onPop?.(TransactionResult.Commit);\n\t}\n\n\tpublic abort(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to abort\");\n\t\t}\n\t\tthis.#events.emit(\"aborting\");\n\t\tthis.#stack.pop()?.callbacks.onPop?.(TransactionResult.Abort);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.ensureNotDisposed();\n\t\twhile (this.isInProgress()) {\n\t\t\tthis.abort();\n\t\t}\n\t\tthis.#disposed = true;\n\t}\n\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Transactor is disposed\");\n\t\t}\n\t}\n}\n\n/**\n * A function that will be called when a transaction is popped from the {@link SquashingTransactionStack | stack}.\n * @remarks This function runs just after the transaction ends, so if this is the end of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.\n * @param result - The result of the transaction.\n * @param viewUpdate - The change that needs to be applied to the view to keep it up-to-date with the branch after the transaction ends.\n * This is needed in asynchronous transactions where new commits have been added to the branch while the transaction was in progress.\n * This will be `undefined` if no such change is necessary.\n */\nexport type OnPopWithViewUpdate<TChange> = (\n\tresult: TransactionResult,\n\tviewUpdate: TChange | undefined,\n) => void;\n\n/**\n * An implementation of {@link Transactor} that {@link TransactionStack | uses a stack} and a {@link SharedTreeBranch | branch} to manage transactions.\n * @remarks Given a branch, this class will fork the branch when a transaction begins and squash the forked branch back into the original branch when the transaction ends.\n * This class provides conveniences for interacting with the {@link SquashingTransactionStack.activeBranch | active branch} in a way that is stable across transaction boundaries.\n * For example, see {@link SquashingTransactionStack.activeBranchEditor | activeBranchEditor} and {@link SquashingTransactionStack.activeBranchEvents | activeBranchEvents}.\n */\nexport class SquashingTransactionStack<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n> extends TransactionStack {\n\t#transactionBranch?: SharedTreeBranch<TEditor, TChange>;\n\n\t/**\n\t * An editor for whichever branch is currently the {@link SquashingTransactionStack.activeBranch | active branch}.\n\t * @remarks This editor can safely be held on to across transaction boundaries, as it will properly delegate to the correct branch.\n\t * In contrast, it is not safe to hold onto e.g. `activeBranch.editor` across transaction boundaries, since the active branch may change.\n\t */\n\tpublic readonly activeBranchEditor = new Proxy<TEditor>({} as unknown as TEditor, {\n\t\tget: (_, p, receiver) => {\n\t\t\treturn Reflect.get(this.activeBranch.editor, p, receiver);\n\t\t},\n\t});\n\n\t/**\n\t * Get the \"active branch\" for this transactor - either the transaction branch if a transaction is in progress, or the original branch otherwise.\n\t */\n\tpublic get activeBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.#transactionBranch ?? this.branch;\n\t}\n\n\t/**\n\t * Provides events for changes in the {@link SquashingTransactionStack.activeBranch | active branch}.\n\t * @remarks When the active branch changes, the listeners for these events will automatically be transferred to the new active branch.\n\t * In contrast, binding an event to the {@link SquashingTransactionStack.activeBranch | active branch} directly will not automatically transfer the listener when the active branch changes.\n\t */\n\tpublic get activeBranchEvents(): Listenable<SharedTreeBranchEvents<TEditor, TChange>> {\n\t\tconst off = (\n\t\t\teventName: keyof SharedTreeBranchEvents<TEditor, TChange>,\n\t\t\tlistener: SharedTreeBranchEvents<TEditor, TChange>[typeof eventName],\n\t\t): void => {\n\t\t\tthis.activeBranch.events.off(eventName, listener);\n\t\t\tconst listeners = this.#activeBranchEvents.get(eventName);\n\t\t\tif (listeners?.delete(listener) === true && listeners.size === 0) {\n\t\t\t\tthis.#activeBranchEvents.delete(eventName);\n\t\t\t}\n\t\t};\n\n\t\treturn {\n\t\t\ton: (eventName, listener) => {\n\t\t\t\tconst listeners = getOrCreate(this.#activeBranchEvents, eventName, () => new Set());\n\t\t\t\tlisteners.add(listener);\n\t\t\t\tthis.activeBranch.events.on(eventName, listener);\n\t\t\t\treturn () => off(eventName, listener);\n\t\t\t},\n\t\t\toff,\n\t\t};\n\t}\n\treadonly #activeBranchEvents = new Map<\n\t\tkeyof SharedTreeBranchEvents<TEditor, TChange>,\n\t\tSet<\n\t\t\tSharedTreeBranchEvents<TEditor, TChange>[keyof SharedTreeBranchEvents<TEditor, TChange>]\n\t\t>\n\t>();\n\n\t/**\n\t * Construct a new {@link SquashingTransactionStack}.\n\t * @param branch - The {@link SquashingTransactionStack.branch | branch} that will be forked off of when a transaction begins.\n\t * @param onPush - A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly branch: SharedTreeBranch<TEditor, TChange>,\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tonPush?: () => OnPopWithViewUpdate<TChange> | void,\n\t) {\n\t\tsuper(\n\t\t\t// Invoked when an outer transaction starts\n\t\t\t(): Callbacks => {\n\t\t\t\t// Keep track of the commit that each transaction was on when it started\n\t\t\t\tconst startHead = this.activeBranch.getHead();\n\t\t\t\tconst rebaser = this.branch.changeFamily.rebaser;\n\t\t\t\tconst outerOnPop = onPush?.();\n\t\t\t\tlet transactionRevision: RevisionTag | undefined;\n\t\t\t\tconst transactionBranch = this.branch.fork(\n\t\t\t\t\tstartHead,\n\t\t\t\t\t// Lazily mint the revision tag for the transaction when it is first needed\n\t\t\t\t\t() => (transactionRevision ??= mintRevisionTag()),\n\t\t\t\t);\n\t\t\t\tthis.setTransactionBranch(transactionBranch);\n\t\t\t\ttransactionBranch.editor.enterTransaction();\n\n\t\t\t\t// Invoked when an outer transaction ends\n\t\t\t\tconst onOuterTransactionPop: OnPop = (result) => {\n\t\t\t\t\tassert(!this.isInProgress(), 0xcae /* The outer transaction should be ending */);\n\t\t\t\t\ttransactionBranch.editor.exitTransaction();\n\n\t\t\t\t\tconst sourcePath: GraphCommit<TChange>[] = [];\n\t\t\t\t\tconst targetPath: GraphCommit<TChange>[] = [];\n\t\t\t\t\tconst ancestor = findCommonAncestor(\n\t\t\t\t\t\t[startHead, sourcePath],\n\t\t\t\t\t\t[branch.getHead(), targetPath],\n\t\t\t\t\t);\n\t\t\t\t\tassert(ancestor !== undefined, 0xcce /* branches must be related */);\n\n\t\t\t\t\tconst transactionSteps: GraphCommit<TChange>[] = [];\n\t\t\t\t\tfindAncestor(\n\t\t\t\t\t\t[transactionBranch.getHead(), transactionSteps],\n\t\t\t\t\t\t(c) => c === startHead,\n\t\t\t\t\t);\n\n\t\t\t\t\tlet viewUpdate: TChange | undefined;\n\t\t\t\t\tswitch (result) {\n\t\t\t\t\t\tcase TransactionResult.Abort: {\n\t\t\t\t\t\t\t// When a transaction is aborted, roll back all the transaction's changes on the current branch.\n\t\t\t\t\t\t\t// It is important that this happens before and separately from updating the view because the `TreeCheckout` needs to\n\t\t\t\t\t\t\t// revert some internal (state to match what it was before the transaction began) before applying the view update (if any).\n\t\t\t\t\t\t\ttransactionBranch.removeAfter(startHead);\n\t\t\t\t\t\t\t// If changes were made on `branch` since the transaction began, the view will need to be updated to reflect those changes.\n\t\t\t\t\t\t\tif (targetPath.length > 0) {\n\t\t\t\t\t\t\t\tviewUpdate = diffHistories(\n\t\t\t\t\t\t\t\t\trebaser,\n\t\t\t\t\t\t\t\t\tstartHead,\n\t\t\t\t\t\t\t\t\tthis.branch.getHead(),\n\t\t\t\t\t\t\t\t\tmintRevisionTag,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase TransactionResult.Commit: {\n\t\t\t\t\t\t\tif (transactionSteps.length > 0) {\n\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\ttransactionRevision !== undefined,\n\t\t\t\t\t\t\t\t\t0xccf /* Expected transaction revision in the presence of transaction steps */,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tfor (const commit of transactionSteps) {\n\t\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\t\tcommit.revision === transactionRevision,\n\t\t\t\t\t\t\t\t\t\t0xcaf /* Unexpected commit in transaction */,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Squash all the new commits on the transaction branch into a new commit on the original branch\n\t\t\t\t\t\t\t\tconst squash = rebaser.compose(transactionSteps);\n\n\t\t\t\t\t\t\t\tif (targetPath.length === 0) {\n\t\t\t\t\t\t\t\t\t// No changes were made on the original branch since the transaction began\n\t\t\t\t\t\t\t\t\t// The transaction commit can be applied directly\n\t\t\t\t\t\t\t\t\tthis.branch.apply(tagChange(squash, transactionRevision));\n\t\t\t\t\t\t\t\t\t// The view is already up-to-date so there's nothing more to do\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// Some changes were made on `branch` since the transaction began\n\t\t\t\t\t\t\t\t\tconst unrebasedHead = mintCommit(startHead, {\n\t\t\t\t\t\t\t\t\t\tchange: squash,\n\t\t\t\t\t\t\t\t\t\trevision: transactionRevision,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t// We need to rebase the transaction commit on top of the new changes\n\t\t\t\t\t\t\t\t\tconst rebased = rebaseBranch(\n\t\t\t\t\t\t\t\t\t\tmintRevisionTag,\n\t\t\t\t\t\t\t\t\t\trebaser,\n\t\t\t\t\t\t\t\t\t\tunrebasedHead,\n\t\t\t\t\t\t\t\t\t\tbranch.getHead(),\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\t\trebased.newSourceHead.revision === transactionRevision,\n\t\t\t\t\t\t\t\t\t\t0xcd0 /* The transaction commit should be rebased to the tip */,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tthis.branch.apply(rebased.newSourceHead);\n\t\t\t\t\t\t\t\t\tviewUpdate = rebased.sourceChange;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tif (targetPath.length > 0) {\n\t\t\t\t\t\t\t\t\t// Changes were made on `branch` since the transaction began.\n\t\t\t\t\t\t\t\t\t// The view will need to be updated to reflect those changes.\n\t\t\t\t\t\t\t\t\tviewUpdate = diffHistories(\n\t\t\t\t\t\t\t\t\t\trebaser,\n\t\t\t\t\t\t\t\t\t\tstartHead,\n\t\t\t\t\t\t\t\t\t\tthis.branch.getHead(),\n\t\t\t\t\t\t\t\t\t\tmintRevisionTag,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\tunreachableCase(result);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\ttransactionBranch.dispose();\n\t\t\t\t\tthis.setTransactionBranch(undefined);\n\t\t\t\t\touterOnPop?.(result, viewUpdate);\n\t\t\t\t};\n\t\t\t\t// Invoked when a nested transaction begins\n\t\t\t\tconst onNestedTransactionPush: OnPush = () => {\n\t\t\t\t\tconst nestedStartHead = this.activeBranch.getHead();\n\t\t\t\t\tconst nestedOuterOnPop = onPush?.();\n\t\t\t\t\ttransactionBranch.editor.enterTransaction();\n\t\t\t\t\treturn {\n\t\t\t\t\t\t// Invoked when a nested transaction ends\n\t\t\t\t\t\tonPop: (result) => {\n\t\t\t\t\t\t\ttransactionBranch.editor.exitTransaction();\n\t\t\t\t\t\t\tswitch (result) {\n\t\t\t\t\t\t\t\tcase TransactionResult.Abort: {\n\t\t\t\t\t\t\t\t\t// When a transaction is aborted, roll back all the transaction's changes on the current branch\n\t\t\t\t\t\t\t\t\ttransactionBranch.removeAfter(nestedStartHead);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcase TransactionResult.Commit: {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\t\tunreachableCase(result);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnestedOuterOnPop?.(result, undefined);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t\treturn { onPop: onOuterTransactionPop, onPush: onNestedTransactionPush };\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Updates the transaction branch (and therefore the active branch) and rebinds the branch events. */\n\tprivate setTransactionBranch(\n\t\ttransactionBranch: SharedTreeBranch<TEditor, TChange> | undefined,\n\t): void {\n\t\tconst oldActiveBranch = this.activeBranch;\n\t\tthis.#transactionBranch = transactionBranch;\n\t\tfor (const [eventName, listeners] of this.#activeBranchEvents) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\toldActiveBranch.events.off(eventName, listener);\n\t\t\t\tthis.activeBranch.events.on(eventName, listener);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"versionedSummarizer.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/versionedSummariz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CAAC,QAAQ,CAAC;IACzD;;;;;OAKG;IACc,0BAA0B,EAAE,OAAO;IASrD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE;QAC3C,SAAS,EAAE,yBAAyB,CAAC;QACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;QACrC,yBAAyB,CAAC,EAAE,sCAAsC,CAAC;QACnE,OAAO,EAAE,kBAAkB,CAAC;KAC5B,GAAG,IAAI;IAER;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC9B,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,oBAAoB;IAC3B;;;OAGG;IACH,OAAO,EAAE,QAAQ,GAAG,SAAS,GAC3B,OAAO,CAAC,IAAI,CAAC;IAET,SAAS,CAAC,KAAK,EAAE;QACvB,SAAS,EAAE,yBAAyB,CAAC;QACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;QACrC,yBAAyB,CAAC,EAAE,sCAAsC,CAAC;KACnE,GAAG,qBAAqB;IAUZ,IAAI,CAChB,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,oBAAoB,GACzB,OAAO,CAAC,IAAI,CAAC;CAkBhB"}
@@ -45,7 +45,7 @@ export class VersionedSummarizer {
45
45
  async load(services, parse) {
46
46
  let version;
47
47
  if (await services.contains(summarizablesMetadataKey)) {
48
- const metadata = await readAndParseSnapshotBlob(summarizablesMetadataKey, services, (contents) => parse(contents));
48
+ const metadata = (await readAndParseSnapshotBlob(summarizablesMetadataKey, services, (contents) => parse(contents)));
49
49
  version = metadata.version;
50
50
  if (!this.supportedVersions.has(version)) {
51
51
  throw new UsageError(`Cannot read version ${version} of shared tree summary.`);
@@ -1 +1 @@
1
- {"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C;IACjC,CAAC;IAEM,KAAK,CAAC,IAAI,CAChB,QAAgC,EAChC,KAA2B;QAE3B,IAAI,OAA6B,CAAC;QAClC,IAAI,MAAM,QAAQ,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;YACvD,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAC9C,wBAAwB,EACxB,QAAQ,EACR,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAC7B,CAAC;YACF,OAAO,GAAG,QAAQ,CAAC,OAAmB,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1C,MAAM,IAAI,UAAU,CAAC,uBAAuB,OAAO,0BAA0B,CAAC,CAAC;YAChF,CAAC;QACF,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,CAAC;YAC7C,MAAM,IAAI,UAAU,CAAC,iEAAiE,CAAC,CAAC;QACzF,CAAC;QACD,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACD","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 { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { readAndParseSnapshotBlob } from \"../util/index.js\";\n\nimport {\n\tsummarizablesMetadataKey,\n\ttype SharedTreeSummarizableMetadata,\n\ttype Summarizable,\n\ttype SummaryElementParser,\n\ttype SummaryElementStringifier,\n} from \"./summaryTypes.js\";\n\n/**\n * Utility for implementing {@link Summarizable}s classes with versioning.\n * It handles versioning of summaries - writing version metadata to summaries\n * and checking version compatibility when loading.\n */\nexport abstract class VersionedSummarizer<TVersion extends number> implements Summarizable {\n\tpublic constructor(\n\t\t/** {@link Summarizable.key} */\n\t\tpublic readonly key: string,\n\t\t/** The format version of the summary to write in the summary metadata. */\n\t\tprivate readonly writeVersion: TVersion,\n\t\t/** The set of supported versions that a summary can have for this summarizer to load it. */\n\t\tprivate readonly supportedVersions: ReadonlySet<TVersion>,\n\t\t/**\n\t\t * Whether to support loading summaries before versioning was added, i.e., summaries without metadata blob.\n\t\t * @remarks\n\t\t * This version may not be supported if the support for the version before metadata blob was dropped.\n\t\t * In that case, this will not be present in `supportedVersions` and an error will be thrown during load.\n\t\t */\n\t\tprivate readonly supportPreVersioningFormat: boolean,\n\t) {\n\t\tassert(\n\t\t\tthis.supportedVersions.has(this.writeVersion),\n\t\t\t0xca6 /* Unsupported write version requested. */,\n\t\t\t() => `Write version ${this.writeVersion} requested but not supported with key ${key}.`,\n\t\t);\n\t}\n\n\t/**\n\t * The summarize function that derived classes must implement. They should use the passed summary tree builder to\n\t * add their summary data.\n\t */\n\tprotected abstract summarizeInternal(props: {\n\t\tstringify: SummaryElementStringifier;\n\t\tfullTree?: boolean;\n\t\ttrackState?: boolean;\n\t\ttelemetryContext?: ITelemetryContext;\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext;\n\t\tbuilder: SummaryTreeBuilder;\n\t}): void;\n\n\t/**\n\t * The load function that derived classes must implement to load their summary data.\n\t */\n\tprotected abstract loadInternal(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t\t/**\n\t\t * The format version of the summary being loaded, or undefined if this is pre-versioning format,\n\t\t * i.e., the summary has no version metadata.\n\t\t */\n\t\tversion: TVersion | undefined,\n\t): Promise<void>;\n\n\tpublic summarize(props: {\n\t\tstringify: SummaryElementStringifier;\n\t\tfullTree?: boolean;\n\t\ttrackState?: boolean;\n\t\ttelemetryContext?: ITelemetryContext;\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext;\n\t}): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst metadata: SharedTreeSummarizableMetadata = {\n\t\t\tversion: this.writeVersion,\n\t\t};\n\t\tbuilder.addBlob(summarizablesMetadataKey, props.stringify(metadata));\n\t\tthis.summarizeInternal({ ...props, builder });\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t): Promise<void> {\n\t\tlet version: TVersion | undefined;\n\t\tif (await services.contains(summarizablesMetadataKey)) {\n\t\t\tconst metadata = await readAndParseSnapshotBlob<SharedTreeSummarizableMetadata>(\n\t\t\t\tsummarizablesMetadataKey,\n\t\t\t\tservices,\n\t\t\t\t(contents) => parse(contents),\n\t\t\t);\n\t\t\tversion = metadata.version as TVersion;\n\t\t\tif (!this.supportedVersions.has(version)) {\n\t\t\t\tthrow new UsageError(`Cannot read version ${version} of shared tree summary.`);\n\t\t\t}\n\t\t} else if (!this.supportPreVersioningFormat) {\n\t\t\tthrow new UsageError(`Cannot read summary without versioning for shared tree summary.`);\n\t\t}\n\t\tawait this.loadInternal(services, parse, version);\n\t}\n}\n"]}
1
+ {"version":3,"file":"versionedSummarizer.js","sourceRoot":"","sources":["../../src/shared-tree-core/versionedSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAO7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EACN,wBAAwB,GAKxB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,OAAgB,mBAAmB;IACxC;IACC,+B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C,OAAO,CAAC,EAAE,CAAC;gBAC1C,MAAM,IAAI,UAAU,CAAC,uBAAuB,OAAO,0BAA0B,CAAC,CAAC;YAChF,CAAC;QACF,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,CAAC;YAC7C,MAAM,IAAI,UAAU,CAAC,iEAAiE,CAAC,CAAC;QACzF,CAAC;QACD,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACD","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 { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { readAndParseSnapshotBlob } from \"../util/index.js\";\n\nimport {\n\tsummarizablesMetadataKey,\n\ttype SharedTreeSummarizableMetadata,\n\ttype Summarizable,\n\ttype SummaryElementParser,\n\ttype SummaryElementStringifier,\n} from \"./summaryTypes.js\";\n\n/**\n * Utility for implementing {@link Summarizable}s classes with versioning.\n * It handles versioning of summaries - writing version metadata to summaries\n * and checking version compatibility when loading.\n */\nexport abstract class VersionedSummarizer<TVersion extends number> implements Summarizable {\n\tpublic constructor(\n\t\t/** {@link Summarizable.key} */\n\t\tpublic readonly key: string,\n\t\t/** The format version of the summary to write in the summary metadata. */\n\t\tprivate readonly writeVersion: TVersion,\n\t\t/** The set of supported versions that a summary can have for this summarizer to load it. */\n\t\tprivate readonly supportedVersions: ReadonlySet<TVersion>,\n\t\t/**\n\t\t * Whether to support loading summaries before versioning was added, i.e., summaries without metadata blob.\n\t\t * @remarks\n\t\t * This version may not be supported if the support for the version before metadata blob was dropped.\n\t\t * In that case, this will not be present in `supportedVersions` and an error will be thrown during load.\n\t\t */\n\t\tprivate readonly supportPreVersioningFormat: boolean,\n\t) {\n\t\tassert(\n\t\t\tthis.supportedVersions.has(this.writeVersion),\n\t\t\t0xca6 /* Unsupported write version requested. */,\n\t\t\t() => `Write version ${this.writeVersion} requested but not supported with key ${key}.`,\n\t\t);\n\t}\n\n\t/**\n\t * The summarize function that derived classes must implement. They should use the passed summary tree builder to\n\t * add their summary data.\n\t */\n\tprotected abstract summarizeInternal(props: {\n\t\tstringify: SummaryElementStringifier;\n\t\tfullTree?: boolean;\n\t\ttrackState?: boolean;\n\t\ttelemetryContext?: ITelemetryContext;\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext;\n\t\tbuilder: SummaryTreeBuilder;\n\t}): void;\n\n\t/**\n\t * The load function that derived classes must implement to load their summary data.\n\t */\n\tprotected abstract loadInternal(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t\t/**\n\t\t * The format version of the summary being loaded, or undefined if this is pre-versioning format,\n\t\t * i.e., the summary has no version metadata.\n\t\t */\n\t\tversion: TVersion | undefined,\n\t): Promise<void>;\n\n\tpublic summarize(props: {\n\t\tstringify: SummaryElementStringifier;\n\t\tfullTree?: boolean;\n\t\ttrackState?: boolean;\n\t\ttelemetryContext?: ITelemetryContext;\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext;\n\t}): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst metadata: SharedTreeSummarizableMetadata = {\n\t\t\tversion: this.writeVersion,\n\t\t};\n\t\tbuilder.addBlob(summarizablesMetadataKey, props.stringify(metadata));\n\t\tthis.summarizeInternal({ ...props, builder });\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async load(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t): Promise<void> {\n\t\tlet version: TVersion | undefined;\n\t\tif (await services.contains(summarizablesMetadataKey)) {\n\t\t\tconst metadata = (await readAndParseSnapshotBlob(\n\t\t\t\tsummarizablesMetadataKey,\n\t\t\t\tservices,\n\t\t\t\t(contents) => parse(contents),\n\t\t\t\t// TODO: this type cast should use a codec to validate the data instead of just type casting.\n\t\t\t)) as SharedTreeSummarizableMetadata;\n\t\t\tversion = metadata.version as TVersion;\n\t\t\tif (!this.supportedVersions.has(version)) {\n\t\t\t\tthrow new UsageError(`Cannot read version ${version} of shared tree summary.`);\n\t\t\t}\n\t\t} else if (!this.supportPreVersioningFormat) {\n\t\t\tthrow new UsageError(`Cannot read summary without versioning for shared tree summary.`);\n\t\t}\n\t\tawait this.loadInternal(services, parse, version);\n\t}\n}\n"]}
@@ -13,7 +13,7 @@ export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
13
13
  export { eraseSchemaDetails, eraseSchemaDetailsSubclassable, } from "./eraseSchemaDetails.js";
14
14
  export type { ValidateRecursiveSchema, FixRecursiveArraySchema, ValidateRecursiveSchemaTemplate, FixRecursiveRecursionLimit, } from "./schemaFactoryRecursive.js";
15
15
  export { allowUnused } from "./schemaFactoryRecursive.js";
16
- export { adaptEnum, enumFromStrings, singletonSchema, } from "./schemaCreationUtilities.js";
16
+ export { adaptEnum, enumFromStrings, singletonSchema, createCustomizedFluidFrameworkScopedFactory, } from "./schemaCreationUtilities.js";
17
17
  export { getIdentifierFromNode, getPropertyKeyFromStoredKey, getStoredKey, treeNodeApi, type TreeNodeApi, tryGetSchema, } from "./treeNodeApi.js";
18
18
  export { createFromCursor } from "./create.js";
19
19
  export { type DirtyTreeStatus, trackDirtyNodes, type DirtyTreeMap, } from "./dirtyIndex.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,qB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AM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,EACrB,KAAK,eAAe,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACN,wCAAwC,EACxC,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,EACjC,kBAAkB,EAClB,iCAAiC,EACjC,KAAK,kBAAkB,EACvB,KAAK,mCAAmC,GACxC,MAAM,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,yBAAyB,EACzB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EAC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AC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACN,wCAAwC,EACxC,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,EACjC,kBAAkB,EAClB,iCAAiC,EACjC,KAAK,kBAAkB,EACvB,KAAK,mCAAmC,GACxC,MAAM,mCAAmC,CAAC"}
@@ -10,7 +10,7 @@ export { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
10
10
  export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
11
11
  export { eraseSchemaDetails, eraseSchemaDetailsSubclassable, } from "./eraseSchemaDetails.js";
12
12
  export { allowUnused } from "./schemaFactoryRecursive.js";
13
- export { adaptEnum, enumFromStrings, singletonSchema, } from "./schemaCreationUtilities.js";
13
+ export { adaptEnum, enumFromStrings, singletonSchema, createCustomizedFluidFrameworkScopedFactory, } from "./schemaCreationUtilities.js";
14
14
  export { getIdentifierFromNode, getPropertyKeyFromStoredKey, getStoredKey, treeNodeApi, tryGetSchema, } from "./treeNodeApi.js";
15
15
  export { createFromCursor } from "./create.js";
16
16
  export { trackDirtyNodes, } from "./dirtyIndex.js";
@@ -1 +1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,kBAAkB,CAAC;AAE1B,OAAO,EACN,+BAA+B,EAC/B,aAAa,EACb,aAAa,EAEb,QAAQ,GAER,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,GAErB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAYN,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,EACN,wCAAwC,EACxC,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,EACjC,kBAAkB,EAClB,iCAAiC,GAGjC,MAAM,mCAAmC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type {\n\tITreeViewConfiguration,\n\tITreeConfigurationOptions,\n} from \"./configuration.js\";\nexport {\n\tTreeViewConfiguration,\n\tTreeViewConfigurationAlpha,\n} from \"./configuration.js\";\nexport type {\n\tITree,\n\tTreeView,\n\tViewableTree,\n\tTreeViewEvents,\n\tSchemaCompatibilityStatus,\n\tTreeViewAlpha,\n\tTreeViewBeta,\n\tTreeBranch,\n\tTreeBranchAlpha,\n\tTreeBranchEvents,\n\tITreeAlpha,\n} from \"./tree.js\";\nexport { asTreeViewAlpha } from \"./tree.js\";\nexport { type SchemaStatics, schemaStatics } from \"./schemaStatics.js\";\nexport {\n\tSchemaFactory,\n\tscoped,\n\ttype ScopedSchemaName,\n\ttype ObjectSchemaOptionsAlpha,\n\ttype ObjectSchemaOptions,\n\ttype NodeSchemaOptions,\n\ttype NodeSchemaOptionsAlpha,\n\ttype SchemaFactory_base,\n} from \"./schemaFactory.js\";\nexport { SchemaFactoryBeta, type SchemaStaticsBeta } from \"./schemaFactoryBeta.js\";\nexport { SchemaFactoryAlpha } from \"./schemaFactoryAlpha.js\";\nexport {\n\teraseSchemaDetails,\n\teraseSchemaDetailsSubclassable,\n} from \"./eraseSchemaDetails.js\";\nexport type {\n\tValidateRecursiveSchema,\n\tFixRecursiveArraySchema,\n\tValidateRecursiveSchemaTemplate,\n\tFixRecursiveRecursionLimit,\n} from \"./schemaFactoryRecursive.js\";\nexport { allowUnused } from \"./schemaFactoryRecursive.js\";\nexport {\n\tadaptEnum,\n\tenumFromStrings,\n\tsingletonSchema,\n} from \"./schemaCreationUtilities.js\";\nexport {\n\tgetIdentifierFromNode,\n\tgetPropertyKeyFromStoredKey,\n\tgetStoredKey,\n\ttreeNodeApi,\n\ttype TreeNodeApi,\n\ttryGetSchema,\n} from \"./treeNodeApi.js\";\nexport { createFromCursor } from \"./create.js\";\nexport {\n\ttype DirtyTreeStatus,\n\ttrackDirtyNodes,\n\ttype DirtyTreeMap,\n} from \"./dirtyIndex.js\";\nexport {\n\ttype JsonSchemaId,\n\ttype JsonSchemaType,\n\ttype JsonObjectNodeSchema,\n\ttype JsonArrayNodeSchema,\n\ttype JsonMapNodeSchema,\n\ttype JsonLeafNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonRefPath,\n\ttype JsonNodeSchema,\n\ttype JsonNodeSchemaBase,\n\ttype JsonTreeSchema,\n\ttype JsonFieldSchema,\n\ttype JsonLeafSchemaType,\n\ttype JsonRecordNodeSchema,\n\ttype JsonStringKeyPatternProperties,\n} from \"./jsonSchema.js\";\nexport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nexport { getJsonSchema } from \"./getJsonSchema.js\";\nexport { getSimpleSchema } from \"./getSimpleSchema.js\";\nexport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nexport type {\n\tUnenforced,\n\tFieldSchemaAlphaUnsafe,\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n\tUnannotateAllowedTypeUnsafe,\n\tAnnotatedAllowedTypeUnsafe,\n\tAnnotatedAllowedTypesUnsafe,\n\tAllowedTypesFullUnsafe,\n\tAllowedTypesFullFromMixedUnsafe,\n\tUnannotateAllowedTypesListUnsafe,\n\tAnnotateAllowedTypesListUnsafe,\n} from \"./typesUnsafe.js\";\n\nexport {\n\ttype VerboseTreeNode,\n\ttype VerboseTree,\n\tapplySchemaToParserOptions,\n\tcursorFromVerbose,\n\tverboseFromCursor,\n\treplaceVerboseTreeHandles,\n} from \"./verboseTree.js\";\n\nexport {\n\ttype TreeEncodingOptions,\n\tcustomFromCursorStored,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttryStoredSchemaAsArray,\n\treplaceHandles,\n\ttype HandleConverter,\n\tKeyEncodingOptions,\n\ttype TreeParsingOptions,\n} from \"./customTree.js\";\n\nexport {\n\ttype ConciseTree,\n\tconciseFromCursor,\n\treplaceConciseTreeHandles,\n} from \"./conciseTree.js\";\n\nexport {\n\tborrowCursorFromTreeNodeOrValue,\n\texportConcise,\n\timportConcise,\n\ttype NodeChangedData,\n\tTreeBeta,\n\ttype TreeChangeEventsBeta,\n} from \"./treeBeta.js\";\nexport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\nexport {\n\tcreateIdentifierIndex,\n\ttype IdentifierIndex,\n} from \"./identifierIndex.js\";\n\nexport {\n\textractPersistedSchema,\n\tcomparePersistedSchema,\n} from \"./storedSchema.js\";\n\nexport {\n\ttype TransactionConstraint,\n\ttype TransactionConstraintAlpha,\n\ttype NodeInDocumentConstraint,\n\ttype NoChangeConstraint,\n\ttype RunTransactionParams,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype TransactionResultSuccess,\n\ttype TransactionResultFailed,\n\trollback,\n} from \"./transactionTypes.js\";\n\nexport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nexport type { TreeChangeEvents } from \"./treeChangeEvents.js\";\nexport {\n\tincrementalEncodingPolicyForAllowedTypes,\n\tincrementalSummaryHint,\n} from \"./incrementalAllowedTypes.js\";\nexport {\n\tencodeSchemaCompatibilitySnapshot,\n\tdecodeSchemaCompatibilitySnapshot,\n} from \"./simpleSchemaCodec.js\";\nexport {\n\texportCompatibilitySchemaSnapshot,\n\timportCompatibilitySchemaSnapshot,\n\tcheckCompatibility,\n\tcheckSchemaCompatibilitySnapshots,\n\ttype SnapshotFileSystem,\n\ttype SchemaCompatibilitySnapshotsOptions,\n} from \"./snapshotCompatibilityChecker.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAc5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAsB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EACN,aAAa,EACb,MAAM,GAON,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACN,kBAAkB,EAClB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAOjC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,EACf,2CAA2C,GAC3C,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,EAEX,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAEN,eAAe,GAEf,MAAM,iBAAiB,CAAC;AAmBzB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAiB3E,OAAO,EAGN,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEN,sBAAsB,EAGtB,sBAAsB,EACtB,cAAc,EAEd,kBAAkB,GAElB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEN,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,+BAA+B,EAC/B,aAAa,EACb,aAAa,EAEb,QAAQ,GAER,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,GAErB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAYN,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,EACN,wCAAwC,EACxC,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,iCAAiC,EACjC,iCAAiC,EACjC,kBAAkB,EAClB,iCAAiC,GAGjC,MAAM,mCAAmC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type {\n\tITreeViewConfiguration,\n\tITreeConfigurationOptions,\n} from \"./configuration.js\";\nexport {\n\tTreeViewConfiguration,\n\tTreeViewConfigurationAlpha,\n} from \"./configuration.js\";\nexport type {\n\tITree,\n\tTreeView,\n\tViewableTree,\n\tTreeViewEvents,\n\tSchemaCompatibilityStatus,\n\tTreeViewAlpha,\n\tTreeViewBeta,\n\tTreeBranch,\n\tTreeBranchAlpha,\n\tTreeBranchEvents,\n\tITreeAlpha,\n} from \"./tree.js\";\nexport { asTreeViewAlpha } from \"./tree.js\";\nexport { type SchemaStatics, schemaStatics } from \"./schemaStatics.js\";\nexport {\n\tSchemaFactory,\n\tscoped,\n\ttype ScopedSchemaName,\n\ttype ObjectSchemaOptionsAlpha,\n\ttype ObjectSchemaOptions,\n\ttype NodeSchemaOptions,\n\ttype NodeSchemaOptionsAlpha,\n\ttype SchemaFactory_base,\n} from \"./schemaFactory.js\";\nexport { SchemaFactoryBeta, type SchemaStaticsBeta } from \"./schemaFactoryBeta.js\";\nexport { SchemaFactoryAlpha } from \"./schemaFactoryAlpha.js\";\nexport {\n\teraseSchemaDetails,\n\teraseSchemaDetailsSubclassable,\n} from \"./eraseSchemaDetails.js\";\nexport type {\n\tValidateRecursiveSchema,\n\tFixRecursiveArraySchema,\n\tValidateRecursiveSchemaTemplate,\n\tFixRecursiveRecursionLimit,\n} from \"./schemaFactoryRecursive.js\";\nexport { allowUnused } from \"./schemaFactoryRecursive.js\";\nexport {\n\tadaptEnum,\n\tenumFromStrings,\n\tsingletonSchema,\n\tcreateCustomizedFluidFrameworkScopedFactory,\n} from \"./schemaCreationUtilities.js\";\nexport {\n\tgetIdentifierFromNode,\n\tgetPropertyKeyFromStoredKey,\n\tgetStoredKey,\n\ttreeNodeApi,\n\ttype TreeNodeApi,\n\ttryGetSchema,\n} from \"./treeNodeApi.js\";\nexport { createFromCursor } from \"./create.js\";\nexport {\n\ttype DirtyTreeStatus,\n\ttrackDirtyNodes,\n\ttype DirtyTreeMap,\n} from \"./dirtyIndex.js\";\nexport {\n\ttype JsonSchemaId,\n\ttype JsonSchemaType,\n\ttype JsonObjectNodeSchema,\n\ttype JsonArrayNodeSchema,\n\ttype JsonMapNodeSchema,\n\ttype JsonLeafNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonRefPath,\n\ttype JsonNodeSchema,\n\ttype JsonNodeSchemaBase,\n\ttype JsonTreeSchema,\n\ttype JsonFieldSchema,\n\ttype JsonLeafSchemaType,\n\ttype JsonRecordNodeSchema,\n\ttype JsonStringKeyPatternProperties,\n} from \"./jsonSchema.js\";\nexport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nexport { getJsonSchema } from \"./getJsonSchema.js\";\nexport { getSimpleSchema } from \"./getSimpleSchema.js\";\nexport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nexport type {\n\tUnenforced,\n\tFieldSchemaAlphaUnsafe,\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n\tUnannotateAllowedTypeUnsafe,\n\tAnnotatedAllowedTypeUnsafe,\n\tAnnotatedAllowedTypesUnsafe,\n\tAllowedTypesFullUnsafe,\n\tAllowedTypesFullFromMixedUnsafe,\n\tUnannotateAllowedTypesListUnsafe,\n\tAnnotateAllowedTypesListUnsafe,\n} from \"./typesUnsafe.js\";\n\nexport {\n\ttype VerboseTreeNode,\n\ttype VerboseTree,\n\tapplySchemaToParserOptions,\n\tcursorFromVerbose,\n\tverboseFromCursor,\n\treplaceVerboseTreeHandles,\n} from \"./verboseTree.js\";\n\nexport {\n\ttype TreeEncodingOptions,\n\tcustomFromCursorStored,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttryStoredSchemaAsArray,\n\treplaceHandles,\n\ttype HandleConverter,\n\tKeyEncodingOptions,\n\ttype TreeParsingOptions,\n} from \"./customTree.js\";\n\nexport {\n\ttype ConciseTree,\n\tconciseFromCursor,\n\treplaceConciseTreeHandles,\n} from \"./conciseTree.js\";\n\nexport {\n\tborrowCursorFromTreeNodeOrValue,\n\texportConcise,\n\timportConcise,\n\ttype NodeChangedData,\n\tTreeBeta,\n\ttype TreeChangeEventsBeta,\n} from \"./treeBeta.js\";\nexport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\nexport {\n\tcreateIdentifierIndex,\n\ttype IdentifierIndex,\n} from \"./identifierIndex.js\";\n\nexport {\n\textractPersistedSchema,\n\tcomparePersistedSchema,\n} from \"./storedSchema.js\";\n\nexport {\n\ttype TransactionConstraint,\n\ttype TransactionConstraintAlpha,\n\ttype NodeInDocumentConstraint,\n\ttype NoChangeConstraint,\n\ttype RunTransactionParams,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype TransactionResultSuccess,\n\ttype TransactionResultFailed,\n\trollback,\n} from \"./transactionTypes.js\";\n\nexport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nexport type { TreeChangeEvents } from \"./treeChangeEvents.js\";\nexport {\n\tincrementalEncodingPolicyForAllowedTypes,\n\tincrementalSummaryHint,\n} from \"./incrementalAllowedTypes.js\";\nexport {\n\tencodeSchemaCompatibilitySnapshot,\n\tdecodeSchemaCompatibilitySnapshot,\n} from \"./simpleSchemaCodec.js\";\nexport {\n\texportCompatibilitySchemaSnapshot,\n\timportCompatibilitySchemaSnapshot,\n\tcheckCompatibility,\n\tcheckSchemaCompatibilitySnapshots,\n\ttype SnapshotFileSystem,\n\ttype SchemaCompatibilitySnapshotsOptions,\n} from \"./snapshotCompatibilityChecker.js\";\n"]}
@@ -5,6 +5,7 @@
5
5
  import type { UnionToTuple } from "../../util/index.js";
6
6
  import type { NodeKind, TreeNode, TreeNodeSchemaClass } from "../core/index.js";
7
7
  import type { SchemaFactory, ScopedSchemaName } from "./schemaFactory.js";
8
+ import { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
8
9
  /**
9
10
  * Create a schema for a node with no state.
10
11
  * @remarks
@@ -109,4 +110,12 @@ export declare function enumFromStrings<TScope extends string, const Members ext
109
110
  readonly value: Members[Index];
110
111
  }, Record<string, never>, true, Record<string, never>, undefined>; }[Members[number]] : never>;
111
112
  };
113
+ /**
114
+ * Declare a SchemaFactory for use in cases where the Fluid Framework's code creates the schema and owns its schema compatibility (and thus scope)
115
+ * but it is parameterized by user provided data, the `TUserScope`.
116
+ * @remarks
117
+ * This should allow future logic in {@link generateSchemaFromSimpleSchema} to recognize these schema as ones defined by Fluid Framework,
118
+ * and special case them to provide better APIs and maintain data invariants.
119
+ */
120
+ export declare function createCustomizedFluidFrameworkScopedFactory<TUserScope extends string, TCreatorDomain extends string>(inputSchemaFactory: SchemaFactoryBeta<TUserScope>, fluidDomainSuffix: TCreatorDomain): SchemaFactoryBeta<`com.fluidframework.${TCreatorDomain}<${TUserScope}>`>;
112
121
  //# sourceMappingURL=schemaCreationUtilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCreationUtilities.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCreationUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAGX,QAAQ,EACR,QAAQ,EAER,mBAAmB,EACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW1E;;;;;;;GAOG;AAGH,wBAAgB,eAAe,CAAC,MAAM,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,GAAG,MAAM,EACnF,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,EACrC,IAAI,EAAE,KAAK;oBAiB2C,KAAK;kEAkB3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,wBAAgB,SAAS,CACxB,MAAM,SAAS,MAAM,EACrB,KAA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xB,MAAM,SAAS,MAAM,EACrB,KAAK,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAClD,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,+CAsBG,MAAM;;;;;;;;EA4BxD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACzC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAAE,CAwB7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,eAAe,CAC9B,MAAM,SAAS,MAAM,EACrB,KAAK,CAAC,OAAO,SAAS,SAAS,MAAM,EAAE,EACtC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,4CAmBO,MAAM;;;;;;;;EA+B9D;AAoCD;;;;;;GAMG;AACH,wBAAgB,2CAA2C,CAC1D,UAAU,SAAS,MAAM,EACzB,cAAc,SAAS,MAAM,EAE7B,kBAAkB,EAAE,iBAAiB,CAAC,UAAU,CAAC,EACjD,iBAAiB,EAAE,cAAc,GAC/B,iBAAiB,CAAC,sBAAsB,cAAc,IAAI,UAAU,GAAG,CAAC,CAK1E"}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { assert, fail } from "@fluidframework/core-utils/internal";
6
6
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
+ import { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
7
8
  /*
8
9
  * This file does two things:
9
10
  *
@@ -218,4 +219,17 @@ function _enumFromStrings2(factory, members) {
218
219
  }
219
220
  return adaptEnum(factory, enumObject);
220
221
  }
222
+ function createCustomizedScopedFactory(inputSchemaFactory, creatorDomain) {
223
+ return new SchemaFactoryBeta(`${creatorDomain}<${inputSchemaFactory.scope}>`);
224
+ }
225
+ /**
226
+ * Declare a SchemaFactory for use in cases where the Fluid Framework's code creates the schema and owns its schema compatibility (and thus scope)
227
+ * but it is parameterized by user provided data, the `TUserScope`.
228
+ * @remarks
229
+ * This should allow future logic in {@link generateSchemaFromSimpleSchema} to recognize these schema as ones defined by Fluid Framework,
230
+ * and special case them to provide better APIs and maintain data invariants.
231
+ */
232
+ export function createCustomizedFluidFrameworkScopedFactory(inputSchemaFactory, fluidDomainSuffix) {
233
+ return createCustomizedScopedFactory(inputSchemaFactory, `com.fluidframework.${fluidDomainSuffix}`);
234
+ }
221
235
  //# sourceMappingURL=schemaCreationUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCreationUtilities.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCreationUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AActE;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wCAAwC;AACxC,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAC9B,OAAqC,EACrC,IAAW;;IAEX,MAAM,eAAgB,SAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACrD,YAAmB,IAA+C;YACjE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnB,CAAC;QACD,IAAW,KAAK;YACf,OAAO,IAAI,CAAC;QACb,CAAC;QAEM,MAAM,CAAU,QAAQ;YAC9B,OAAO,mBAAmB,IAAI,GAAG,CAAC;QACnC,CAAC;;SAEc,MAAM,CAAC,WAAW;IAAnB,mBAAoB,GAAG,mBAAmB,IAAI,GAAG,CAAC;IAKjE,8IAA8I;IAC9I,2CAA2C;IAC3C,yHAAyH;IACzH,iDAAiD;IACjD,qFAAqF;IACrF,MAAM,QAAQ,GAQV,eAAe,CAAC;IAEpB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;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ved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { UnionToTuple } from \"../../util/index.js\";\nimport type {\n\tNodeFromSchema,\n\tInternalTreeNode,\n\tNodeKind,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\n\nimport type { SchemaFactory, ScopedSchemaName } from \"./schemaFactory.js\";\n\n/*\n * This file does two things:\n *\n * 1. Provides tools for making schema for cases like enums.\n *\n * 2. Demonstrates the kinds of schema utilities apps can write.\n * Nothing in here needs access to package internal APIs.\n */\n\n/**\n * Create a schema for a node with no state.\n * @remarks\n * This is commonly used in unions when the only information needed is which kind of node the value is.\n * Enums are a common example of this pattern.\n * @see {@link adaptEnum}\n * @beta\n */\n// Return type is intentionally derived.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function singletonSchema<TScope extends string, TName extends string | number>(\n\tfactory: SchemaFactory<TScope, TName>,\n\tname: TName,\n) {\n\tclass SingletonSchema extends factory.object(name, {}) {\n\t\tpublic constructor(data?: InternalTreeNode | Record<string, never>) {\n\t\t\tsuper(data ?? {});\n\t\t}\n\t\tpublic get value(): TName {\n\t\t\treturn name;\n\t\t}\n\n\t\tpublic static override toString(): string {\n\t\t\treturn `SingletonSchema(${name})`;\n\t\t}\n\n\t\tpublic static [Symbol.toStringTag] = `SingletonSchema(${name})`;\n\t}\n\n\ttype SingletonNodeType = TreeNode & { readonly value: TName };\n\n\t// Returning SingletonSchema without a type conversion results in TypeScript generating something like `readonly \"__#124291@#brand\": unknown;`\n\t// for the private brand field of TreeNode.\n\t// This numeric id doesn't seem to be stable over incremental builds, and thus causes diffs in the API extractor reports.\n\t// This is avoided by doing this type conversion.\n\t// The conversion is done via assignment instead of `as` to get stronger type safety.\n\tconst toReturn: TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, TName>,\n\t\tNodeKind.Object,\n\t\tSingletonNodeType,\n\t\tRecord<string, never>,\n\t\ttrue,\n\t\tRecord<string, never>,\n\t\tundefined\n\t> = SingletonSchema;\n\n\treturn toReturn;\n}\n\n/**\n * Converts an enum into a collection of schema which can be used in a union.\n *\n * @typeParam TScope - The scope of the provided factory.\n * There is a known issue where if a factory is provided that is typed as a {@link SchemaFactoryAlpha}, and its scope contains a \".\" character,\n * the inferred type for the scope will end up as a union of the scope up to the first \".\" character and the scope as it should be.\n * This can be mitigated by explicitly providing the TScope type parameter or by typing the provided factory as a {@link SchemaFactory} instead of a {@link SchemaFactoryAlpha}.\n *\n * @remarks\n * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.\n * Numeric enums values have the value implicitly converted into a string.\n * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryBeta.scopedFactory}) to avoid the enum members colliding with other schema.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * // An enum for use in the tree. Must have string keys.\n * enum Mode {\n * \ta = \"A\",\n * \tb = \"B\",\n * }\n * // Define the schema for each member of the enum using a nested scope to group them together.\n * const ModeNodes = adaptEnum(new SchemaFactory(`${schemaFactory.scope}.Mode`), Mode);\n * // Defined the types of the nodes which correspond to this the schema.\n * type ModeNodes = TreeNodeFromImplicitAllowedTypes<(typeof ModeNodes.schema)>;\n * // An example schema which has an enum as a child.\n * class Parent extends schemaFactory.object(\"Parent\", {\n * \t// adaptEnum's return value has a \".schema\" property can be use as an `AllowedTypes` array allowing any of the members of the enum.\n * \tmode: ModeNodes.schema,\n * }) {}\n *\n * // Example usage of enum based nodes, showing what type to use and that `.value` can be used to read out the enum value.\n * function getValue(node: ModeNodes): Mode {\n * \treturn node.value;\n * }\n *\n * // Example constructing a tree containing an enum node from an enum value.\n * // The syntax `new ModeNodes.a()` is also supported.\n * function setValue(node: Parent): void {\n * \tnode.mode = ModeNodes(Mode.a);\n * }\n * ```\n * @privateRemarks\n * TODO: AB#43345: see TScope known issue above, and other references to this work item.\n *\n * @see {@link enumFromStrings} for a similar function that works on arrays of strings instead of an enum.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function adaptEnum<\n\tTScope extends string,\n\tconst TEnum extends Record<string, string | number>,\n>(factory: SchemaFactory<TScope>, members: TEnum) {\n\ttype Values = TEnum[keyof TEnum];\n\tconst values = Object.values(members) as Values[];\n\tconst inverse = new Map(Object.entries(members).map(([key, value]) => [value, key])) as Map<\n\t\tValues,\n\t\tkeyof TEnum\n\t>;\n\n\tif (inverse.size !== values.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct values.\");\n\t}\n\n\ttype TOut = {\n\t\treadonly [Property in keyof TEnum]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, TEnum[Property]>\n\t\t>;\n\t};\n\n\ttype SchemaArray = UnionToTuple<TOut[keyof TEnum]>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends Values>(value: TValue) => {\n\t\treturn new out[\n\t\t\tinverse.get(value) ?? fail(0xb31 /* missing enum value */)\n\t\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\t]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tfor (const [key, value] of enumEntries(members)) {\n\t\tconst schema = singletonSchema(factory, value);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n/**\n * Returns en \"entries\" (like Object.entries) for an enum object, omitting the\n * {@link https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings|reverse mappings}\n */\nexport function enumEntries(\n\tenumObject: Record<string, string | number>,\n): [string, string | number][] {\n\t// Skip reverse mapping for numeric entries.\n\t// For numeric entries, TypeScript defines an additional property keyed with the number implicitly converted to a string.\n\t// Note TypeScript can overwrite its own enum entries in some edge cases (see https://github.com/microsoft/TypeScript/issues/48956), so it's not possible to handle all cases correctly.\n\treturn Object.entries(enumObject).filter(([key, value]) => {\n\t\t// All reverse mapping must also have a inverse mapping (the regular forward mapping) to a number:\n\t\tconst inverse = enumObject[value];\n\t\tif (typeof inverse !== \"number\") {\n\t\t\t// Known not to be a reverse mapping, so keep it.\n\t\t\treturn true;\n\t\t}\n\t\t// At this point, it is expected that all remaining cases are reverse mappings,\n\t\t// but do some asserts to ensure that the above logic is sufficient.\n\t\tassert(\n\t\t\ttypeof value === \"string\",\n\t\t\t0xbe4 /* expected reverse mapping and thus a string value */,\n\t\t);\n\t\tassert(\n\t\t\tNumber.parseFloat(key).toString() === key,\n\t\t\t0xbe5 /* expected reverse mapping and thus a key that is a normalized number */,\n\t\t);\n\t\t// Discard the reverse mapping.\n\t\treturn false;\n\t});\n}\n\n/**\n * Converts an array of distinct strings into a collection of schema which can be used like an enum style union.\n * @remarks\n * The returned collection is also a function which can be used to convert strings into {@link Unhydrated} nodes in the union.\n * Each node type has a `.value` getter which returns the associated string.\n *\n * The produced nodes use the provided strings as their `name`, and don't store any data beyond that.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * const Mode = enumFromStrings(schemaFactory, [\"Fun\", \"Cool\"]);\n * type Mode = TreeNodeFromImplicitAllowedTypes<typeof Mode.schema>;\n * const nodeFromString: Mode = Mode(\"Fun\");\n * const nodeFromSchema: Mode = new Mode.Fun();\n *\n * // Schema nodes have a strongly typed `.value` property.\n * const nameFromNode: \"Fun\" | \"Cool\" = nodeFromSchema.value;\n *\n * class Parent extends schemaFactory.object(\"Parent\", { mode: Mode.schema }) {}\n * ```\n * @see {@link adaptEnum} for a similar function that works on enums instead of arrays of strings.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function enumFromStrings<\n\tTScope extends string,\n\tconst Members extends readonly string[],\n>(factory: SchemaFactory<TScope>, members: Members) {\n\tconst names = new Set(members);\n\tif (names.size !== members.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct names\");\n\t}\n\n\ttype MembersUnion = Members[number];\n\n\t// Get all keys of the Members tuple which are numeric strings as union of numbers:\n\ttype Indexes = Extract<keyof Members, `${number}`> extends `${infer N extends number}`\n\t\t? N\n\t\t: never;\n\n\ttype TOut = {\n\t\t[Index in Indexes as Members[Index]]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, Members[Index] & string>\n\t\t>;\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends MembersUnion>(value: TValue) => {\n\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\treturn new recordOut[value]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\n\ttype SchemaArray = UnionToTuple<MembersUnion extends unknown ? TOut[MembersUnion] : never>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tconst recordOut = out as Record<MembersUnion, new () => unknown>;\n\tfor (const name of members) {\n\t\tconst schema = singletonSchema(factory, name);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n// TODO: This generates an invalid d.ts file if exported due to a bug https://github.com/microsoft/TypeScript/issues/58688.\n// TODO: replace enumFromStrings above with this simpler implementation when the TypeScript bug is resolved.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction _enumFromStrings2<TScope extends string, const Members extends readonly string[]>(\n\tfactory: SchemaFactory<TScope>,\n\tmembers: Members,\n) {\n\tconst enumObject: {\n\t\t[key in keyof Members as Members[key] extends string\n\t\t\t? Members[key]\n\t\t\t: string]: Members[key] extends string ? Members[key] : string;\n\t} = Object.create(null);\n\tfor (const name of members) {\n\t\tObject.defineProperty(enumObject, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: name,\n\t\t});\n\t}\n\n\treturn adaptEnum(factory, enumObject);\n}\n"]}
1
+ {"version":3,"file":"schemaCreationUtilities.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCreationUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAatE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wCAAwC;AACxC,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAC9B,OAAqC,EACrC,IAAW;;IAEX,MAAM,eAAgB,SAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACrD,YAAmB,IAA+C;YACjE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnB,CAAC;QACD,IAAW,KAAK;YACf,OAAO,IAAI,CAAC;QACb,CAAC;QAEM,MAAM,CAAU,QAAQ;YAC9B,OAAO,mBAAmB,IAAI,GAAG,CAAC;QACnC,CAAC;;SAEc,MAAM,CAAC,WAAW;IAAnB,mBAAoB,GAAG,mBAAmB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B,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,IAAI;SACX,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,6BAA6B,CAIrC,kBAAiD,EACjD,aAA6B;IAE7B,OAAO,IAAI,iBAAiB,CAAC,GAAG,aAAa,IAAI,kBAAkB,CAAC,KAAK,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,2CAA2C,CAI1D,kBAAiD,EACjD,iBAAiC;IAEjC,OAAO,6BAA6B,CACnC,kBAAkB,EAClB,sBAAsB,iBAAiB,EAAW,CAClD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { UnionToTuple } from \"../../util/index.js\";\nimport type {\n\tNodeFromSchema,\n\tInternalTreeNode,\n\tNodeKind,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\n\nimport type { SchemaFactory, ScopedSchemaName } from \"./schemaFactory.js\";\nimport { SchemaFactoryBeta } from \"./schemaFactoryBeta.js\";\n\n/*\n * This file does two things:\n *\n * 1. Provides tools for making schema for cases like enums.\n *\n * 2. Demonstrates the kinds of schema utilities apps can write.\n * Nothing in here needs access to package internal APIs.\n */\n\n/**\n * Create a schema for a node with no state.\n * @remarks\n * This is commonly used in unions when the only information needed is which kind of node the value is.\n * Enums are a common example of this pattern.\n * @see {@link adaptEnum}\n * @beta\n */\n// Return type is intentionally derived.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function singletonSchema<TScope extends string, TName extends string | number>(\n\tfactory: SchemaFactory<TScope, TName>,\n\tname: TName,\n) {\n\tclass SingletonSchema extends factory.object(name, {}) {\n\t\tpublic constructor(data?: InternalTreeNode | Record<string, never>) {\n\t\t\tsuper(data ?? {});\n\t\t}\n\t\tpublic get value(): TName {\n\t\t\treturn name;\n\t\t}\n\n\t\tpublic static override toString(): string {\n\t\t\treturn `SingletonSchema(${name})`;\n\t\t}\n\n\t\tpublic static [Symbol.toStringTag] = `SingletonSchema(${name})`;\n\t}\n\n\ttype SingletonNodeType = TreeNode & { readonly value: TName };\n\n\t// Returning SingletonSchema without a type conversion results in TypeScript generating something like `readonly \"__#124291@#brand\": unknown;`\n\t// for the private brand field of TreeNode.\n\t// This numeric id doesn't seem to be stable over incremental builds, and thus causes diffs in the API extractor reports.\n\t// This is avoided by doing this type conversion.\n\t// The conversion is done via assignment instead of `as` to get stronger type safety.\n\tconst toReturn: TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, TName>,\n\t\tNodeKind.Object,\n\t\tSingletonNodeType,\n\t\tRecord<string, never>,\n\t\ttrue,\n\t\tRecord<string, never>,\n\t\tundefined\n\t> = SingletonSchema;\n\n\treturn toReturn;\n}\n\n/**\n * Converts an enum into a collection of schema which can be used in a union.\n *\n * @typeParam TScope - The scope of the provided factory.\n * There is a known issue where if a factory is provided that is typed as a {@link SchemaFactoryAlpha}, and its scope contains a \".\" character,\n * the inferred type for the scope will end up as a union of the scope up to the first \".\" character and the scope as it should be.\n * This can be mitigated by explicitly providing the TScope type parameter or by typing the provided factory as a {@link SchemaFactory} instead of a {@link SchemaFactoryAlpha}.\n *\n * @remarks\n * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.\n * Numeric enums values have the value implicitly converted into a string.\n * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryBeta.scopedFactory}) to avoid the enum members colliding with other schema.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * // An enum for use in the tree. Must have string keys.\n * enum Mode {\n * \ta = \"A\",\n * \tb = \"B\",\n * }\n * // Define the schema for each member of the enum using a nested scope to group them together.\n * const ModeNodes = adaptEnum(new SchemaFactory(`${schemaFactory.scope}.Mode`), Mode);\n * // Defined the types of the nodes which correspond to this the schema.\n * type ModeNodes = TreeNodeFromImplicitAllowedTypes<(typeof ModeNodes.schema)>;\n * // An example schema which has an enum as a child.\n * class Parent extends schemaFactory.object(\"Parent\", {\n * \t// adaptEnum's return value has a \".schema\" property can be use as an `AllowedTypes` array allowing any of the members of the enum.\n * \tmode: ModeNodes.schema,\n * }) {}\n *\n * // Example usage of enum based nodes, showing what type to use and that `.value` can be used to read out the enum value.\n * function getValue(node: ModeNodes): Mode {\n * \treturn node.value;\n * }\n *\n * // Example constructing a tree containing an enum node from an enum value.\n * // The syntax `new ModeNodes.a()` is also supported.\n * function setValue(node: Parent): void {\n * \tnode.mode = ModeNodes(Mode.a);\n * }\n * ```\n * @privateRemarks\n * TODO: AB#43345: see TScope known issue above, and other references to this work item.\n *\n * @see {@link enumFromStrings} for a similar function that works on arrays of strings instead of an enum.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function adaptEnum<\n\tTScope extends string,\n\tconst TEnum extends Record<string, string | number>,\n>(factory: SchemaFactory<TScope>, members: TEnum) {\n\ttype Values = TEnum[keyof TEnum];\n\tconst values = Object.values(members) as Values[];\n\tconst inverse = new Map(Object.entries(members).map(([key, value]) => [value, key])) as Map<\n\t\tValues,\n\t\tkeyof TEnum\n\t>;\n\n\tif (inverse.size !== values.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct values.\");\n\t}\n\n\ttype TOut = {\n\t\treadonly [Property in keyof TEnum]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, TEnum[Property]>\n\t\t>;\n\t};\n\n\ttype SchemaArray = UnionToTuple<TOut[keyof TEnum]>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends Values>(value: TValue) => {\n\t\treturn new out[\n\t\t\tinverse.get(value) ?? fail(0xb31 /* missing enum value */)\n\t\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\t]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tfor (const [key, value] of enumEntries(members)) {\n\t\tconst schema = singletonSchema(factory, value);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n/**\n * Returns en \"entries\" (like Object.entries) for an enum object, omitting the\n * {@link https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings|reverse mappings}\n */\nexport function enumEntries(\n\tenumObject: Record<string, string | number>,\n): [string, string | number][] {\n\t// Skip reverse mapping for numeric entries.\n\t// For numeric entries, TypeScript defines an additional property keyed with the number implicitly converted to a string.\n\t// Note TypeScript can overwrite its own enum entries in some edge cases (see https://github.com/microsoft/TypeScript/issues/48956), so it's not possible to handle all cases correctly.\n\treturn Object.entries(enumObject).filter(([key, value]) => {\n\t\t// All reverse mapping must also have a inverse mapping (the regular forward mapping) to a number:\n\t\tconst inverse = enumObject[value];\n\t\tif (typeof inverse !== \"number\") {\n\t\t\t// Known not to be a reverse mapping, so keep it.\n\t\t\treturn true;\n\t\t}\n\t\t// At this point, it is expected that all remaining cases are reverse mappings,\n\t\t// but do some asserts to ensure that the above logic is sufficient.\n\t\tassert(\n\t\t\ttypeof value === \"string\",\n\t\t\t0xbe4 /* expected reverse mapping and thus a string value */,\n\t\t);\n\t\tassert(\n\t\t\tNumber.parseFloat(key).toString() === key,\n\t\t\t0xbe5 /* expected reverse mapping and thus a key that is a normalized number */,\n\t\t);\n\t\t// Discard the reverse mapping.\n\t\treturn false;\n\t});\n}\n\n/**\n * Converts an array of distinct strings into a collection of schema which can be used like an enum style union.\n * @remarks\n * The returned collection is also a function which can be used to convert strings into {@link Unhydrated} nodes in the union.\n * Each node type has a `.value` getter which returns the associated string.\n *\n * The produced nodes use the provided strings as their `name`, and don't store any data beyond that.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * const Mode = enumFromStrings(schemaFactory, [\"Fun\", \"Cool\"]);\n * type Mode = TreeNodeFromImplicitAllowedTypes<typeof Mode.schema>;\n * const nodeFromString: Mode = Mode(\"Fun\");\n * const nodeFromSchema: Mode = new Mode.Fun();\n *\n * // Schema nodes have a strongly typed `.value` property.\n * const nameFromNode: \"Fun\" | \"Cool\" = nodeFromSchema.value;\n *\n * class Parent extends schemaFactory.object(\"Parent\", { mode: Mode.schema }) {}\n * ```\n * @see {@link adaptEnum} for a similar function that works on enums instead of arrays of strings.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function enumFromStrings<\n\tTScope extends string,\n\tconst Members extends readonly string[],\n>(factory: SchemaFactory<TScope>, members: Members) {\n\tconst names = new Set(members);\n\tif (names.size !== members.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct names\");\n\t}\n\n\ttype MembersUnion = Members[number];\n\n\t// Get all keys of the Members tuple which are numeric strings as union of numbers:\n\ttype Indexes =\n\t\tExtract<keyof Members, `${number}`> extends `${infer N extends number}` ? N : never;\n\n\ttype TOut = {\n\t\t[Index in Indexes as Members[Index]]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, Members[Index] & string>\n\t\t>;\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends MembersUnion>(value: TValue) => {\n\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\treturn new recordOut[value]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\n\ttype SchemaArray = UnionToTuple<MembersUnion extends unknown ? TOut[MembersUnion] : never>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tconst recordOut = out as Record<MembersUnion, new () => unknown>;\n\tfor (const name of members) {\n\t\tconst schema = singletonSchema(factory, name);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n// TODO: This generates an invalid d.ts file if exported due to a bug https://github.com/microsoft/TypeScript/issues/58688.\n// TODO: replace enumFromStrings above with this simpler implementation when the TypeScript bug is resolved.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction _enumFromStrings2<TScope extends string, const Members extends readonly string[]>(\n\tfactory: SchemaFactory<TScope>,\n\tmembers: Members,\n) {\n\tconst enumObject = Object.create(null) as {\n\t\t[key in keyof Members as Members[key] extends string\n\t\t\t? Members[key]\n\t\t\t: string]: Members[key] extends string ? Members[key] : string;\n\t};\n\tfor (const name of members) {\n\t\tObject.defineProperty(enumObject, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: name,\n\t\t});\n\t}\n\n\treturn adaptEnum(factory, enumObject);\n}\n\nfunction createCustomizedScopedFactory<\n\tTUserScope extends string,\n\tTCreatorDomain extends string,\n>(\n\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n\tcreatorDomain: TCreatorDomain,\n): SchemaFactoryBeta<`${TCreatorDomain}<${TUserScope}>`> {\n\treturn new SchemaFactoryBeta(`${creatorDomain}<${inputSchemaFactory.scope}>`);\n}\n\n/**\n * Declare a SchemaFactory for use in cases where the Fluid Framework's code creates the schema and owns its schema compatibility (and thus scope)\n * but it is parameterized by user provided data, the `TUserScope`.\n * @remarks\n * This should allow future logic in {@link generateSchemaFromSimpleSchema} to recognize these schema as ones defined by Fluid Framework,\n * and special case them to provide better APIs and maintain data invariants.\n */\nexport function createCustomizedFluidFrameworkScopedFactory<\n\tTUserScope extends string,\n\tTCreatorDomain extends string,\n>(\n\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n\tfluidDomainSuffix: TCreatorDomain,\n): SchemaFactoryBeta<`com.fluidframework.${TCreatorDomain}<${TUserScope}>`> {\n\treturn createCustomizedScopedFactory(\n\t\tinputSchemaFactory,\n\t\t`com.fluidframework.${fluidDomainSuffix}` as const,\n\t);\n}\n"]}