@fluidframework/tree 2.40.0-336023 → 2.40.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 (445) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/api-report/tree.alpha.api.md +4 -1
  3. package/dist/alpha.d.ts +1 -0
  4. package/dist/codec/codec.d.ts +5 -1
  5. package/dist/codec/codec.d.ts.map +1 -1
  6. package/dist/codec/codec.js +6 -2
  7. package/dist/codec/codec.js.map +1 -1
  8. package/dist/codec/index.d.ts +1 -1
  9. package/dist/codec/index.d.ts.map +1 -1
  10. package/dist/codec/index.js +2 -1
  11. package/dist/codec/index.js.map +1 -1
  12. package/dist/core/index.d.ts +2 -2
  13. package/dist/core/index.d.ts.map +1 -1
  14. package/dist/core/index.js +2 -3
  15. package/dist/core/index.js.map +1 -1
  16. package/dist/core/schema-stored/{format.d.ts → formatV1.d.ts} +1 -1
  17. package/dist/core/schema-stored/formatV1.d.ts.map +1 -0
  18. package/dist/core/schema-stored/{format.js → formatV1.js} +1 -1
  19. package/dist/core/schema-stored/formatV1.js.map +1 -0
  20. package/dist/core/schema-stored/index.d.ts +3 -3
  21. package/dist/core/schema-stored/index.d.ts.map +1 -1
  22. package/dist/core/schema-stored/index.js +3 -3
  23. package/dist/core/schema-stored/index.js.map +1 -1
  24. package/dist/core/schema-stored/schema.d.ts +3 -1
  25. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  26. package/dist/core/schema-stored/schema.js +8 -6
  27. package/dist/core/schema-stored/schema.js.map +1 -1
  28. package/dist/core/schema-stored/storedSchemaRepository.d.ts +1 -1
  29. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  30. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  31. package/dist/core/schema-view/index.d.ts +1 -1
  32. package/dist/core/schema-view/index.d.ts.map +1 -1
  33. package/dist/core/schema-view/index.js +1 -2
  34. package/dist/core/schema-view/index.js.map +1 -1
  35. package/dist/core/schema-view/view.d.ts +0 -27
  36. package/dist/core/schema-view/view.d.ts.map +1 -1
  37. package/dist/core/schema-view/view.js +1 -35
  38. package/dist/core/schema-view/view.js.map +1 -1
  39. package/dist/core/tree/persistedTreeTextFormat.d.ts +4 -4
  40. package/dist/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  41. package/dist/core/tree/persistedTreeTextFormat.js +1 -1
  42. package/dist/core/tree/persistedTreeTextFormat.js.map +1 -1
  43. package/dist/feature-libraries/forest-summary/format.d.ts +2 -2
  44. package/dist/feature-libraries/forest-summary/format.d.ts.map +1 -1
  45. package/dist/feature-libraries/forest-summary/format.js +1 -1
  46. package/dist/feature-libraries/forest-summary/format.js.map +1 -1
  47. package/dist/feature-libraries/index.d.ts +1 -1
  48. package/dist/feature-libraries/index.d.ts.map +1 -1
  49. package/dist/feature-libraries/index.js +4 -2
  50. package/dist/feature-libraries/index.js.map +1 -1
  51. package/dist/feature-libraries/mapTreeCursor.d.ts +3 -3
  52. package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  53. package/dist/feature-libraries/mapTreeCursor.js +2 -2
  54. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  55. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -9
  56. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  57. package/dist/feature-libraries/modular-schema/modularChangeFormat.js +2 -2
  58. package/dist/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
  59. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts +14 -1
  60. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  61. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +26 -5
  62. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  63. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  64. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  65. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  66. package/dist/feature-libraries/schema-index/codec.d.ts +34 -5
  67. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  68. package/dist/feature-libraries/schema-index/codec.js +63 -9
  69. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  70. package/{lib/feature-libraries/schema-index/format.d.ts → dist/feature-libraries/schema-index/formatV1.d.ts} +9 -9
  71. package/dist/feature-libraries/schema-index/formatV1.d.ts.map +1 -0
  72. package/dist/feature-libraries/schema-index/{format.js → formatV1.js} +4 -4
  73. package/dist/feature-libraries/schema-index/formatV1.js.map +1 -0
  74. package/dist/feature-libraries/schema-index/index.d.ts +2 -2
  75. package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
  76. package/dist/feature-libraries/schema-index/index.js +6 -3
  77. package/dist/feature-libraries/schema-index/index.js.map +1 -1
  78. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +5 -5
  79. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  80. package/dist/feature-libraries/schema-index/schemaSummarizer.js +4 -4
  81. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  82. package/dist/index.d.ts +1 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +10 -8
  85. package/dist/index.js.map +1 -1
  86. package/dist/packageVersion.d.ts +1 -1
  87. package/dist/packageVersion.d.ts.map +1 -1
  88. package/dist/packageVersion.js +1 -1
  89. package/dist/packageVersion.js.map +1 -1
  90. package/dist/shared-tree/independentView.d.ts.map +1 -1
  91. package/dist/shared-tree/independentView.js +1 -1
  92. package/dist/shared-tree/independentView.js.map +1 -1
  93. package/dist/shared-tree/index.d.ts +1 -1
  94. package/dist/shared-tree/index.d.ts.map +1 -1
  95. package/dist/shared-tree/index.js +2 -1
  96. package/dist/shared-tree/index.js.map +1 -1
  97. package/dist/shared-tree/schematizeTree.d.ts +8 -9
  98. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  99. package/dist/shared-tree/schematizeTree.js +9 -33
  100. package/dist/shared-tree/schematizeTree.js.map +1 -1
  101. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  102. package/dist/shared-tree/schematizingTreeView.js +1 -4
  103. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  104. package/dist/shared-tree/sharedTree.d.ts +28 -3
  105. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  106. package/dist/shared-tree/sharedTree.js +29 -3
  107. package/dist/shared-tree/sharedTree.js.map +1 -1
  108. package/dist/shared-tree/tree.d.ts +24 -0
  109. package/dist/shared-tree/tree.d.ts.map +1 -1
  110. package/dist/shared-tree/tree.js.map +1 -1
  111. package/dist/shared-tree/treeAlpha.d.ts +2 -0
  112. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  113. package/dist/shared-tree/treeAlpha.js +3 -2
  114. package/dist/shared-tree/treeAlpha.js.map +1 -1
  115. package/dist/shared-tree-core/branchCommitEnricher.d.ts +0 -1
  116. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  117. package/dist/shared-tree-core/branchCommitEnricher.js +0 -1
  118. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  119. package/dist/shared-tree-core/transactionEnricher.d.ts +1 -1
  120. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  121. package/dist/shared-tree-core/transactionEnricher.js +4 -1
  122. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  123. package/dist/simple-tree/api/index.d.ts +2 -1
  124. package/dist/simple-tree/api/index.d.ts.map +1 -1
  125. package/dist/simple-tree/api/index.js +2 -1
  126. package/dist/simple-tree/api/index.js.map +1 -1
  127. package/dist/simple-tree/api/schemaFactory.d.ts +9 -0
  128. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  129. package/dist/simple-tree/api/schemaFactory.js +7 -0
  130. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  131. package/dist/simple-tree/api/storedSchema.d.ts +8 -7
  132. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  133. package/dist/simple-tree/api/storedSchema.js +13 -9
  134. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  135. package/dist/simple-tree/api/tree.d.ts +25 -0
  136. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  137. package/dist/simple-tree/api/tree.js.map +1 -1
  138. package/dist/simple-tree/api/treeBeta.d.ts +4 -1
  139. package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
  140. package/dist/simple-tree/api/treeBeta.js.map +1 -1
  141. package/dist/simple-tree/api/treeChangeEvents.d.ts +83 -0
  142. package/dist/simple-tree/api/treeChangeEvents.d.ts.map +1 -0
  143. package/dist/simple-tree/api/treeChangeEvents.js +7 -0
  144. package/dist/simple-tree/api/treeChangeEvents.js.map +1 -0
  145. package/dist/simple-tree/api/treeNodeApi.d.ts +2 -1
  146. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  147. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  148. package/dist/simple-tree/arrayNode.d.ts +28 -0
  149. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  150. package/dist/simple-tree/arrayNode.js.map +1 -1
  151. package/dist/simple-tree/core/getOrCreateNode.d.ts +1 -1
  152. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  153. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  154. package/dist/simple-tree/core/index.d.ts +2 -1
  155. package/dist/simple-tree/core/index.d.ts.map +1 -1
  156. package/dist/simple-tree/core/index.js +5 -5
  157. package/dist/simple-tree/core/index.js.map +1 -1
  158. package/dist/simple-tree/core/treeNode.d.ts +94 -0
  159. package/dist/simple-tree/core/treeNode.d.ts.map +1 -0
  160. package/dist/simple-tree/core/treeNode.js +123 -0
  161. package/dist/simple-tree/core/treeNode.js.map +1 -0
  162. package/dist/simple-tree/core/treeNodeKernel.d.ts +2 -1
  163. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  164. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  165. package/dist/simple-tree/core/treeNodeSchema.d.ts +3 -1
  166. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  167. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  168. package/dist/simple-tree/core/types.d.ts +0 -165
  169. package/dist/simple-tree/core/types.d.ts.map +1 -1
  170. package/dist/simple-tree/core/types.js +1 -113
  171. package/dist/simple-tree/core/types.js.map +1 -1
  172. package/dist/simple-tree/core/withType.d.ts +1 -1
  173. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  174. package/dist/simple-tree/core/withType.js.map +1 -1
  175. package/dist/simple-tree/index.d.ts +2 -2
  176. package/dist/simple-tree/index.d.ts.map +1 -1
  177. package/dist/simple-tree/index.js +3 -2
  178. package/dist/simple-tree/index.js.map +1 -1
  179. package/dist/simple-tree/schemaTypes.d.ts +1 -0
  180. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  181. package/dist/simple-tree/schemaTypes.js.map +1 -1
  182. package/dist/simple-tree/toStoredSchema.d.ts +8 -8
  183. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  184. package/dist/simple-tree/toStoredSchema.js +27 -32
  185. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  186. package/dist/tableSchema.d.ts +302 -83
  187. package/dist/tableSchema.d.ts.map +1 -1
  188. package/dist/tableSchema.js +299 -57
  189. package/dist/tableSchema.js.map +1 -1
  190. package/dist/treeFactory.d.ts +1 -1
  191. package/dist/treeFactory.d.ts.map +1 -1
  192. package/dist/treeFactory.js +30 -75
  193. package/dist/treeFactory.js.map +1 -1
  194. package/lib/alpha.d.ts +1 -0
  195. package/lib/codec/codec.d.ts +5 -1
  196. package/lib/codec/codec.d.ts.map +1 -1
  197. package/lib/codec/codec.js +5 -1
  198. package/lib/codec/codec.js.map +1 -1
  199. package/lib/codec/index.d.ts +1 -1
  200. package/lib/codec/index.d.ts.map +1 -1
  201. package/lib/codec/index.js +1 -1
  202. package/lib/codec/index.js.map +1 -1
  203. package/lib/core/index.d.ts +2 -2
  204. package/lib/core/index.d.ts.map +1 -1
  205. package/lib/core/index.js +2 -2
  206. package/lib/core/index.js.map +1 -1
  207. package/lib/core/schema-stored/{format.d.ts → formatV1.d.ts} +1 -1
  208. package/lib/core/schema-stored/formatV1.d.ts.map +1 -0
  209. package/lib/core/schema-stored/{format.js → formatV1.js} +1 -1
  210. package/lib/core/schema-stored/formatV1.js.map +1 -0
  211. package/lib/core/schema-stored/index.d.ts +3 -3
  212. package/lib/core/schema-stored/index.d.ts.map +1 -1
  213. package/lib/core/schema-stored/index.js +2 -2
  214. package/lib/core/schema-stored/index.js.map +1 -1
  215. package/lib/core/schema-stored/schema.d.ts +3 -1
  216. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  217. package/lib/core/schema-stored/schema.js +3 -1
  218. package/lib/core/schema-stored/schema.js.map +1 -1
  219. package/lib/core/schema-stored/storedSchemaRepository.d.ts +1 -1
  220. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  221. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  222. package/lib/core/schema-view/index.d.ts +1 -1
  223. package/lib/core/schema-view/index.d.ts.map +1 -1
  224. package/lib/core/schema-view/index.js +1 -1
  225. package/lib/core/schema-view/index.js.map +1 -1
  226. package/lib/core/schema-view/view.d.ts +0 -27
  227. package/lib/core/schema-view/view.d.ts.map +1 -1
  228. package/lib/core/schema-view/view.js +0 -34
  229. package/lib/core/schema-view/view.js.map +1 -1
  230. package/lib/core/tree/persistedTreeTextFormat.d.ts +4 -4
  231. package/lib/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  232. package/lib/core/tree/persistedTreeTextFormat.js +2 -2
  233. package/lib/core/tree/persistedTreeTextFormat.js.map +1 -1
  234. package/lib/feature-libraries/forest-summary/format.d.ts +2 -2
  235. package/lib/feature-libraries/forest-summary/format.d.ts.map +1 -1
  236. package/lib/feature-libraries/forest-summary/format.js +2 -2
  237. package/lib/feature-libraries/forest-summary/format.js.map +1 -1
  238. package/lib/feature-libraries/index.d.ts +1 -1
  239. package/lib/feature-libraries/index.d.ts.map +1 -1
  240. package/lib/feature-libraries/index.js +1 -1
  241. package/lib/feature-libraries/index.js.map +1 -1
  242. package/lib/feature-libraries/mapTreeCursor.d.ts +3 -3
  243. package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  244. package/lib/feature-libraries/mapTreeCursor.js +2 -2
  245. package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
  246. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -9
  247. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  248. package/lib/feature-libraries/modular-schema/modularChangeFormat.js +3 -3
  249. package/lib/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
  250. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts +14 -1
  251. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  252. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +26 -6
  253. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  254. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  255. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  256. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
  257. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  258. package/lib/feature-libraries/schema-index/codec.d.ts +34 -5
  259. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  260. package/lib/feature-libraries/schema-index/codec.js +61 -9
  261. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  262. package/{dist/feature-libraries/schema-index/format.d.ts → lib/feature-libraries/schema-index/formatV1.d.ts} +9 -9
  263. package/lib/feature-libraries/schema-index/formatV1.d.ts.map +1 -0
  264. package/lib/feature-libraries/schema-index/{format.js → formatV1.js} +5 -5
  265. package/lib/feature-libraries/schema-index/formatV1.js.map +1 -0
  266. package/lib/feature-libraries/schema-index/index.d.ts +2 -2
  267. package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
  268. package/lib/feature-libraries/schema-index/index.js +2 -2
  269. package/lib/feature-libraries/schema-index/index.js.map +1 -1
  270. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +5 -5
  271. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  272. package/lib/feature-libraries/schema-index/schemaSummarizer.js +5 -5
  273. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  274. package/lib/index.d.ts +1 -0
  275. package/lib/index.d.ts.map +1 -1
  276. package/lib/index.js +1 -0
  277. package/lib/index.js.map +1 -1
  278. package/lib/packageVersion.d.ts +1 -1
  279. package/lib/packageVersion.d.ts.map +1 -1
  280. package/lib/packageVersion.js +1 -1
  281. package/lib/packageVersion.js.map +1 -1
  282. package/lib/shared-tree/independentView.d.ts.map +1 -1
  283. package/lib/shared-tree/independentView.js +2 -2
  284. package/lib/shared-tree/independentView.js.map +1 -1
  285. package/lib/shared-tree/index.d.ts +1 -1
  286. package/lib/shared-tree/index.d.ts.map +1 -1
  287. package/lib/shared-tree/index.js +1 -1
  288. package/lib/shared-tree/index.js.map +1 -1
  289. package/lib/shared-tree/schematizeTree.d.ts +8 -9
  290. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  291. package/lib/shared-tree/schematizeTree.js +10 -34
  292. package/lib/shared-tree/schematizeTree.js.map +1 -1
  293. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  294. package/lib/shared-tree/schematizingTreeView.js +2 -5
  295. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  296. package/lib/shared-tree/sharedTree.d.ts +28 -3
  297. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  298. package/lib/shared-tree/sharedTree.js +29 -4
  299. package/lib/shared-tree/sharedTree.js.map +1 -1
  300. package/lib/shared-tree/tree.d.ts +24 -0
  301. package/lib/shared-tree/tree.d.ts.map +1 -1
  302. package/lib/shared-tree/tree.js.map +1 -1
  303. package/lib/shared-tree/treeAlpha.d.ts +2 -0
  304. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  305. package/lib/shared-tree/treeAlpha.js +4 -3
  306. package/lib/shared-tree/treeAlpha.js.map +1 -1
  307. package/lib/shared-tree-core/branchCommitEnricher.d.ts +0 -1
  308. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  309. package/lib/shared-tree-core/branchCommitEnricher.js +0 -1
  310. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  311. package/lib/shared-tree-core/transactionEnricher.d.ts +1 -1
  312. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  313. package/lib/shared-tree-core/transactionEnricher.js +4 -1
  314. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  315. package/lib/simple-tree/api/index.d.ts +2 -1
  316. package/lib/simple-tree/api/index.d.ts.map +1 -1
  317. package/lib/simple-tree/api/index.js +1 -1
  318. package/lib/simple-tree/api/index.js.map +1 -1
  319. package/lib/simple-tree/api/schemaFactory.d.ts +9 -0
  320. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  321. package/lib/simple-tree/api/schemaFactory.js +7 -0
  322. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  323. package/lib/simple-tree/api/storedSchema.d.ts +8 -7
  324. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  325. package/lib/simple-tree/api/storedSchema.js +17 -11
  326. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  327. package/lib/simple-tree/api/tree.d.ts +25 -0
  328. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  329. package/lib/simple-tree/api/tree.js.map +1 -1
  330. package/lib/simple-tree/api/treeBeta.d.ts +4 -1
  331. package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
  332. package/lib/simple-tree/api/treeBeta.js.map +1 -1
  333. package/lib/simple-tree/api/treeChangeEvents.d.ts +83 -0
  334. package/lib/simple-tree/api/treeChangeEvents.d.ts.map +1 -0
  335. package/lib/simple-tree/api/treeChangeEvents.js +6 -0
  336. package/lib/simple-tree/api/treeChangeEvents.js.map +1 -0
  337. package/lib/simple-tree/api/treeNodeApi.d.ts +2 -1
  338. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  339. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  340. package/lib/simple-tree/arrayNode.d.ts +28 -0
  341. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  342. package/lib/simple-tree/arrayNode.js.map +1 -1
  343. package/lib/simple-tree/core/getOrCreateNode.d.ts +1 -1
  344. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  345. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  346. package/lib/simple-tree/core/index.d.ts +2 -1
  347. package/lib/simple-tree/core/index.d.ts.map +1 -1
  348. package/lib/simple-tree/core/index.js +1 -1
  349. package/lib/simple-tree/core/index.js.map +1 -1
  350. package/lib/simple-tree/core/treeNode.d.ts +94 -0
  351. package/lib/simple-tree/core/treeNode.d.ts.map +1 -0
  352. package/lib/simple-tree/core/treeNode.js +118 -0
  353. package/lib/simple-tree/core/treeNode.js.map +1 -0
  354. package/lib/simple-tree/core/treeNodeKernel.d.ts +2 -1
  355. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  356. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  357. package/lib/simple-tree/core/treeNodeSchema.d.ts +3 -1
  358. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  359. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  360. package/lib/simple-tree/core/types.d.ts +0 -165
  361. package/lib/simple-tree/core/types.d.ts.map +1 -1
  362. package/lib/simple-tree/core/types.js +0 -110
  363. package/lib/simple-tree/core/types.js.map +1 -1
  364. package/lib/simple-tree/core/withType.d.ts +1 -1
  365. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  366. package/lib/simple-tree/core/withType.js.map +1 -1
  367. package/lib/simple-tree/index.d.ts +2 -2
  368. package/lib/simple-tree/index.d.ts.map +1 -1
  369. package/lib/simple-tree/index.js +1 -1
  370. package/lib/simple-tree/index.js.map +1 -1
  371. package/lib/simple-tree/schemaTypes.d.ts +1 -0
  372. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  373. package/lib/simple-tree/schemaTypes.js.map +1 -1
  374. package/lib/simple-tree/toStoredSchema.d.ts +8 -8
  375. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  376. package/lib/simple-tree/toStoredSchema.js +26 -31
  377. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  378. package/lib/tableSchema.d.ts +302 -83
  379. package/lib/tableSchema.d.ts.map +1 -1
  380. package/lib/tableSchema.js +299 -57
  381. package/lib/tableSchema.js.map +1 -1
  382. package/lib/treeFactory.d.ts +1 -1
  383. package/lib/treeFactory.d.ts.map +1 -1
  384. package/lib/treeFactory.js +30 -75
  385. package/lib/treeFactory.js.map +1 -1
  386. package/package.json +21 -21
  387. package/src/codec/codec.ts +6 -1
  388. package/src/codec/index.ts +1 -0
  389. package/src/core/index.ts +1 -2
  390. package/src/core/schema-stored/index.ts +3 -3
  391. package/src/core/schema-stored/schema.ts +3 -1
  392. package/src/core/schema-stored/storedSchemaRepository.ts +1 -1
  393. package/src/core/schema-view/index.ts +0 -1
  394. package/src/core/schema-view/view.ts +0 -31
  395. package/src/core/tree/persistedTreeTextFormat.ts +2 -2
  396. package/src/feature-libraries/forest-summary/format.ts +2 -2
  397. package/src/feature-libraries/index.ts +7 -1
  398. package/src/feature-libraries/mapTreeCursor.ts +3 -3
  399. package/src/feature-libraries/modular-schema/modularChangeFormat.ts +3 -3
  400. package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +38 -9
  401. package/src/feature-libraries/schema-edits/schemaChangeFormat.ts +3 -4
  402. package/src/feature-libraries/schema-index/codec.ts +80 -12
  403. package/src/feature-libraries/schema-index/{format.ts → formatV1.ts} +4 -4
  404. package/src/feature-libraries/schema-index/index.ts +7 -2
  405. package/src/feature-libraries/schema-index/schemaSummarizer.ts +9 -9
  406. package/src/index.ts +1 -0
  407. package/src/packageVersion.ts +1 -1
  408. package/src/shared-tree/independentView.ts +3 -2
  409. package/src/shared-tree/index.ts +2 -0
  410. package/src/shared-tree/schematizeTree.ts +5 -35
  411. package/src/shared-tree/schematizingTreeView.ts +2 -10
  412. package/src/shared-tree/sharedTree.ts +67 -6
  413. package/src/shared-tree/tree.ts +24 -0
  414. package/src/shared-tree/treeAlpha.ts +6 -3
  415. package/src/shared-tree-core/branchCommitEnricher.ts +0 -1
  416. package/src/shared-tree-core/transactionEnricher.ts +4 -1
  417. package/src/simple-tree/api/index.ts +2 -0
  418. package/src/simple-tree/api/schemaFactory.ts +9 -0
  419. package/src/simple-tree/api/storedSchema.ts +24 -13
  420. package/src/simple-tree/api/tree.ts +25 -0
  421. package/src/simple-tree/api/treeBeta.ts +3 -1
  422. package/src/simple-tree/api/treeChangeEvents.ts +84 -0
  423. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  424. package/src/simple-tree/arrayNode.ts +28 -0
  425. package/src/simple-tree/core/getOrCreateNode.ts +1 -1
  426. package/src/simple-tree/core/index.ts +5 -4
  427. package/src/simple-tree/core/treeNode.ts +163 -0
  428. package/src/simple-tree/core/treeNodeKernel.ts +2 -1
  429. package/src/simple-tree/core/treeNodeSchema.ts +3 -1
  430. package/src/simple-tree/core/types.ts +0 -234
  431. package/src/simple-tree/core/withType.ts +1 -1
  432. package/src/simple-tree/index.ts +2 -1
  433. package/src/simple-tree/schemaTypes.ts +1 -0
  434. package/src/simple-tree/toStoredSchema.ts +42 -41
  435. package/src/tableSchema.ts +665 -197
  436. package/src/treeFactory.ts +56 -173
  437. package/dist/core/schema-stored/format.d.ts.map +0 -1
  438. package/dist/core/schema-stored/format.js.map +0 -1
  439. package/dist/feature-libraries/schema-index/format.d.ts.map +0 -1
  440. package/dist/feature-libraries/schema-index/format.js.map +0 -1
  441. package/lib/core/schema-stored/format.d.ts.map +0 -1
  442. package/lib/core/schema-stored/format.js.map +0 -1
  443. package/lib/feature-libraries/schema-index/format.d.ts.map +0 -1
  444. package/lib/feature-libraries/schema-index/format.js.map +0 -1
  445. /package/src/core/schema-stored/{format.ts → formatV1.ts} +0 -0
@@ -4,12 +4,12 @@
4
4
  */
5
5
 
6
6
  import { oob } from "@fluidframework/core-utils/internal";
7
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
8
 
8
9
  import { Tree } from "./shared-tree/index.js";
9
10
  import {
10
11
  type FieldHasDefault,
11
12
  type ImplicitAllowedTypes,
12
- type ImplicitFieldSchema,
13
13
  type InsertableObjectFromSchemaRecord,
14
14
  type InsertableTreeNodeFromImplicitAllowedTypes,
15
15
  type NodeKind,
@@ -24,17 +24,22 @@ import {
24
24
  type TreeFieldFromImplicitField,
25
25
  type InsertableTreeFieldFromImplicitField,
26
26
  type InternalTreeNode,
27
- type FieldSchema,
28
- type FieldKind,
29
27
  SchemaFactory,
30
28
  type ImplicitAnnotatedFieldSchema,
31
29
  type UnannotateImplicitFieldSchema,
32
30
  } from "./simple-tree/index.js";
33
31
 
34
- // Future improvement TODOs (ideally to be done before promoting these APIs to `@alpha`):
32
+ // Future improvement TODOs:
33
+ // - Omit `cells` property from Row insertion type.
35
34
  // - Record-like type parameters / input parameters?
36
35
  // - Omit `props` properties from Row and Column schemas when not provided?
37
36
 
37
+ // Longer-term work:
38
+ // - Add constraint APIs to make it possible to avoid situations that could yield "orphaned" cells.
39
+
40
+ /**
41
+ * The sub-scope applied to user-provided {@link SchemaFactory}s by table schema factories.
42
+ */
38
43
  const tableSchemaFactorySubScope = "table";
39
44
 
40
45
  /**
@@ -48,20 +53,28 @@ const tableSchemaFactorySubScope = "table";
48
53
  * @system @internal
49
54
  */
50
55
  export namespace System_TableSchema {
56
+ /**
57
+ * Default type used for column and row "props" fields.
58
+ * @privateRemarks
59
+ * Longer term, it would be better to simply omit "props" altogether by default.
60
+ * For now, this ensures that the user doesn't have to specify a "props" entry when initializing column/row nodes
61
+ * and ensures that they cannot set anything that might conflict with future evolutions of the schema.
62
+ * @system @internal
63
+ */
64
+ export type DefaultPropsType = ReturnType<typeof SchemaFactory.optional<[]>>;
65
+
51
66
  /**
52
67
  * A base interface for factory input options which include an schema factory.
53
68
  * @remarks This interface should not be referenced directly.
54
69
  * @privateRemarks This interface primarily exists to provide a single home for property documentation.
55
70
  * @system @internal
56
71
  */
57
- export interface OptionsWithSchemaFactory<
58
- TScope extends string | undefined = string | undefined,
59
- > {
72
+ export interface OptionsWithSchemaFactory<TSchemaFactory extends SchemaFactoryAlpha> {
60
73
  /**
61
74
  * Schema factory with which the Column schema will be associated.
62
75
  * @remarks Can be used to associate the resulting schema with an existing {@link SchemaFactory.scope|scope}.
63
76
  */
64
- readonly schemaFactory: SchemaFactoryAlpha<TScope>;
77
+ readonly schemaFactory: TSchemaFactory;
65
78
  }
66
79
 
67
80
  /**
@@ -70,9 +83,7 @@ export namespace System_TableSchema {
70
83
  * @privateRemarks This interface primarily exists to provide a single home for property documentation.
71
84
  * @system @internal
72
85
  */
73
- export interface OptionsWithCellSchema<
74
- TCellSchema extends ImplicitAllowedTypes = ImplicitAllowedTypes,
75
- > {
86
+ export interface OptionsWithCellSchema<TCellSchema extends ImplicitAllowedTypes> {
76
87
  /**
77
88
  * Schema for the table's cells.
78
89
  */
@@ -87,8 +98,8 @@ export namespace System_TableSchema {
87
98
  * @system @internal
88
99
  */
89
100
  export type CreateColumnOptionsBase<
90
- TInputScope extends string | undefined = string | undefined,
91
- > = OptionsWithSchemaFactory<TInputScope>;
101
+ TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
102
+ > = OptionsWithSchemaFactory<TSchemaFactory>;
92
103
 
93
104
  /**
94
105
  * Factory for creating new table column schema.
@@ -136,10 +147,10 @@ export namespace System_TableSchema {
136
147
  // Will make it easier to evolve this schema in the future.
137
148
  allowUnknownOptionalFields: true,
138
149
  })
139
- implements TableSchema.IColumn<TPropsSchema> {}
150
+ implements TableSchema.Column<TPropsSchema> {}
140
151
 
141
152
  type ColumnValueType = TreeNode &
142
- TableSchema.IColumn<TPropsSchema> &
153
+ TableSchema.Column<TPropsSchema> &
143
154
  WithType<ScopedSchemaName<Scope, "Column">>;
144
155
 
145
156
  // Note: ideally this type would just leverage `InsertableObjectFromSchemaRecord<typeof columnFields>`,
@@ -151,7 +162,7 @@ export namespace System_TableSchema {
151
162
  typeof columnFieldsBuiltInParts
152
163
  > &
153
164
  (FieldHasDefault<UnannotateImplicitFieldSchema<TPropsSchema>> extends true
154
- ? // Note: The docs on the below properties are copied from `IRow.props`' docs to ensure that the
165
+ ? // Note: The docs on the below properties are copied from `IColumn.props`' docs to ensure that the
155
166
  // documentation appears in the data insertion scenario.
156
167
  // The contents are duplicated instead of using `@inheritdoc`, as intellisense does not correctly
157
168
  // support `@inheritDoc`.
@@ -215,8 +226,8 @@ export namespace System_TableSchema {
215
226
  */
216
227
  export type ColumnSchemaBase<
217
228
  TScope extends string | undefined = string | undefined,
218
- TPropsSchema extends ImplicitFieldSchema = ImplicitFieldSchema,
219
- > = ReturnType<typeof TableSchema.createColumn<TScope, TPropsSchema>>;
229
+ TPropsSchema extends ImplicitAnnotatedFieldSchema = ImplicitAnnotatedFieldSchema,
230
+ > = ReturnType<typeof createColumnInternal<TScope, TPropsSchema>>;
220
231
 
221
232
  // #endregion
222
233
 
@@ -228,9 +239,9 @@ export namespace System_TableSchema {
228
239
  * @system @internal
229
240
  */
230
241
  export type CreateRowOptionsBase<
231
- TScope extends string | undefined = string | undefined,
242
+ TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
232
243
  TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
233
- > = OptionsWithSchemaFactory<TScope> & OptionsWithCellSchema<TCell>;
244
+ > = OptionsWithSchemaFactory<TSchemaFactory> & OptionsWithCellSchema<TCell>;
234
245
 
235
246
  /**
236
247
  * Factory for creating new table row schema.
@@ -241,7 +252,7 @@ export namespace System_TableSchema {
241
252
  export function createRowInternal<
242
253
  const TInputScope extends string | undefined,
243
254
  const TCellSchema extends ImplicitAllowedTypes,
244
- const TPropsSchema extends ImplicitFieldSchema,
255
+ const TPropsSchema extends ImplicitAnnotatedFieldSchema,
245
256
  >(
246
257
  inputSchemaFactory: SchemaFactoryAlpha<TInputScope>,
247
258
  cellSchema: TCellSchema,
@@ -289,32 +300,40 @@ export namespace System_TableSchema {
289
300
  // Will make it easier to evolve this schema in the future.
290
301
  allowUnknownOptionalFields: true,
291
302
  })
292
- implements TableSchema.IRow<TCellSchema, TPropsSchema>
303
+ implements TableSchema.Row<TCellSchema, TPropsSchema>
293
304
  {
294
- public getCell(columnOrId: TableSchema.IColumn | string): CellValueType | undefined {
305
+ public getCell(columnOrId: TableSchema.Column | string): CellValueType | undefined {
295
306
  const columnId = typeof columnOrId === "string" ? columnOrId : columnOrId.id;
296
307
  return this.cells.get(columnId) as CellValueType | undefined;
297
308
  }
298
309
 
299
310
  public setCell(
300
- columnOrId: TableSchema.IColumn | string,
311
+ columnOrId: TableSchema.Column | string,
301
312
  value: CellInsertableType | undefined,
302
313
  ): void {
314
+ // TODO: throw if column does not exist in the owning table.
315
+
303
316
  const columnId = typeof columnOrId === "string" ? columnOrId : columnOrId.id;
304
317
  this.cells.set(columnId, value);
305
318
  }
306
319
 
307
- public removeCell(columnOrId: TableSchema.IColumn | string): void {
320
+ public removeCell(columnOrId: TableSchema.Column | string): CellValueType | undefined {
321
+ // TODO: throw if column does not exist in the owning table.
322
+
308
323
  const columnId = typeof columnOrId === "string" ? columnOrId : columnOrId.id;
309
- if (!this.cells.has(columnId)) {
310
- return;
324
+
325
+ const cell: CellValueType | undefined = this.cells.get(columnId);
326
+ if (cell === undefined) {
327
+ return undefined;
311
328
  }
329
+
312
330
  this.cells.delete(columnId);
331
+ return cell;
313
332
  }
314
333
  }
315
334
 
316
335
  type RowValueType = TreeNode &
317
- TableSchema.IRow<TCellSchema, TPropsSchema> &
336
+ TableSchema.Row<TCellSchema, TPropsSchema> &
318
337
  WithType<ScopedSchemaName<Scope, "Row">>;
319
338
 
320
339
  // Note: ideally this type would just leverage `InsertableObjectFromSchemaRecord<typeof rowFields>`,
@@ -324,7 +343,7 @@ export namespace System_TableSchema {
324
343
  // the issue.
325
344
  // type RowInsertableType = InsertableObjectFromSchemaRecord<typeof rowFields>;
326
345
  type RowInsertableType = InsertableObjectFromSchemaRecord<typeof rowFieldsBuiltInParts> &
327
- (FieldHasDefault<TPropsSchema> extends true
346
+ (FieldHasDefault<UnannotateImplicitFieldSchema<TPropsSchema>> extends true
328
347
  ? // Note: The docs on the below properties are copied from `IRow.props`' docs to ensure that the
329
348
  // documentation appears in the data insertion scenario.
330
349
  // The contents are duplicated instead of using `@inheritdoc`, as intellisense does not correctly
@@ -336,7 +355,9 @@ export namespace System_TableSchema {
336
355
  * @remarks This is a user-defined schema that can be used to store additional information
337
356
  * about the row.
338
357
  */
339
- props?: InsertableTreeFieldFromImplicitField<TPropsSchema>;
358
+ props?: InsertableTreeFieldFromImplicitField<
359
+ UnannotateImplicitFieldSchema<TPropsSchema>
360
+ >;
340
361
  }
341
362
  : {
342
363
  /**
@@ -344,10 +365,12 @@ export namespace System_TableSchema {
344
365
  * @remarks This is a user-defined schema that can be used to store additional information
345
366
  * about the row.
346
367
  */
347
- props: InsertableTreeFieldFromImplicitField<TPropsSchema>;
368
+ props: InsertableTreeFieldFromImplicitField<
369
+ UnannotateImplicitFieldSchema<TPropsSchema>
370
+ >;
348
371
  });
349
372
 
350
- // Modified version of `Column` that ensures the constructor (and `createFromInsertable`) are
373
+ // Modified version of `Row` that ensures the constructor (and `createFromInsertable`) are
351
374
  // typed correctly in terms of our insertable type.
352
375
  // This lets us be selective in our type-cast for the value returned from this function,
353
376
  // preserving as much type-safety as we reasonably can.
@@ -388,8 +411,8 @@ export namespace System_TableSchema {
388
411
  export type RowSchemaBase<
389
412
  TScope extends string | undefined = string | undefined,
390
413
  TCellSchema extends ImplicitAllowedTypes = ImplicitAllowedTypes,
391
- TPropsSchema extends ImplicitFieldSchema = ImplicitFieldSchema,
392
- > = ReturnType<typeof TableSchema.createRow<TScope, TCellSchema, TPropsSchema>>;
414
+ TPropsSchema extends ImplicitAnnotatedFieldSchema = ImplicitAnnotatedFieldSchema,
415
+ > = ReturnType<typeof createRowInternal<TScope, TCellSchema, TPropsSchema>>;
393
416
 
394
417
  // #endregion
395
418
 
@@ -401,9 +424,9 @@ export namespace System_TableSchema {
401
424
  * @system @internal
402
425
  */
403
426
  export type TableFactoryOptionsBase<
404
- TScope extends string | undefined = string | undefined,
427
+ TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
405
428
  TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
406
- > = OptionsWithSchemaFactory<TScope> & OptionsWithCellSchema<TCell>;
429
+ > = OptionsWithSchemaFactory<TSchemaFactory> & OptionsWithCellSchema<TCell>;
407
430
 
408
431
  /**
409
432
  * Factory for creating new table schema.
@@ -413,11 +436,8 @@ export namespace System_TableSchema {
413
436
  export function createTableInternal<
414
437
  const TInputScope extends string | undefined,
415
438
  const TCellSchema extends ImplicitAllowedTypes,
416
- const TColumnSchema extends ColumnSchemaBase<TInputScope> = ColumnSchemaBase<TInputScope>,
417
- const TRowSchema extends RowSchemaBase<TInputScope, TCellSchema> = RowSchemaBase<
418
- TInputScope,
419
- TCellSchema
420
- >,
439
+ const TColumnSchema extends ColumnSchemaBase<TInputScope>,
440
+ const TRowSchema extends RowSchemaBase<TInputScope, TCellSchema>,
421
441
  >(
422
442
  inputSchemaFactory: SchemaFactoryAlpha<TInputScope>,
423
443
  _cellSchema: TCellSchema,
@@ -428,13 +448,8 @@ export namespace System_TableSchema {
428
448
  type Scope = ScopedSchemaName<TInputScope, typeof tableSchemaFactorySubScope>;
429
449
 
430
450
  type CellValueType = TreeNodeFromImplicitAllowedTypes<TCellSchema>;
431
- type CellInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TCellSchema>;
432
-
433
451
  type ColumnValueType = TreeNodeFromImplicitAllowedTypes<TColumnSchema>;
434
- type ColumnInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TColumnSchema>;
435
-
436
452
  type RowValueType = TreeNodeFromImplicitAllowedTypes<TRowSchema>;
437
- type RowInsertableType = InsertableTreeNodeFromImplicitAllowedTypes<TRowSchema>;
438
453
 
439
454
  /**
440
455
  * {@link Table} fields.
@@ -444,7 +459,7 @@ export namespace System_TableSchema {
444
459
  const tableFields = {
445
460
  rows: schemaFactory.array("Table.rows", rowSchema),
446
461
  columns: schemaFactory.array("Table.columns", columnSchema),
447
- } as const satisfies Record<string, ImplicitFieldSchema>;
462
+ } as const satisfies Record<string, ImplicitAnnotatedFieldSchema>;
448
463
 
449
464
  /**
450
465
  * The Table schema
@@ -454,7 +469,7 @@ export namespace System_TableSchema {
454
469
  // Will make it easier to evolve this schema in the future.
455
470
  allowUnknownOptionalFields: true,
456
471
  })
457
- implements TableSchema.ITable<TCellSchema, TColumnSchema, TRowSchema>
472
+ implements TableSchema.Table<TCellSchema, TColumnSchema, TRowSchema>
458
473
  {
459
474
  public getColumn(id: string): ColumnValueType | undefined {
460
475
  // TypeScript is unable to narrow the types correctly here, hence the casts.
@@ -472,51 +487,130 @@ export namespace System_TableSchema {
472
487
  | undefined;
473
488
  }
474
489
 
475
- public getCell(key: TableSchema.CellKey): CellValueType | undefined {
476
- const { columnId, rowId } = key;
477
- const row = this.getRow(rowId);
478
- if (row !== undefined) {
479
- const column = this.getColumn(columnId);
480
- if (column !== undefined) {
481
- return row.getCell(column.id);
482
- }
490
+ public getCell(
491
+ key: TableSchema.CellKey<TColumnSchema, TRowSchema>,
492
+ ): CellValueType | undefined {
493
+ const { column: columnOrId, row: rowOrId } = key;
494
+ const row = this._getRow(rowOrId);
495
+ if (row === undefined) {
496
+ return undefined;
497
+ }
498
+
499
+ const column = this._getColumn(columnOrId);
500
+ if (column === undefined) {
501
+ return undefined;
483
502
  }
484
- // If the cell does not exist return undefined
485
- return undefined;
503
+
504
+ return row.getCell(column);
486
505
  }
487
506
 
488
507
  public insertColumn({
489
508
  column,
490
509
  index,
491
- }: TableSchema.InsertColumnParameters<ColumnInsertableType>): ColumnValueType {
492
- if (index === undefined) {
493
- // TypeScript is unable to narrow the types correctly here, hence the cast.
510
+ }: TableSchema.InsertColumnParameters<TColumnSchema>): ColumnValueType {
511
+ const inserted = this.insertColumns({
512
+ columns: [column],
513
+ index,
514
+ });
515
+ return inserted[0] ?? oob();
516
+ }
517
+
518
+ public insertColumns({
519
+ columns,
520
+ index,
521
+ }: TableSchema.InsertColumnsParameters<TColumnSchema>): ColumnValueType[] {
522
+ // #region Input validation
523
+
524
+ // Ensure index is valid
525
+ if (index !== undefined) {
526
+ Table.validateInsertionIndex(index, this.columns);
527
+ }
528
+
529
+ // Check all of the columns being inserted an ensure the table does not already contain any with the same ID.
530
+ for (const column of columns) {
531
+ // TypeScript is unable to narrow the type of the column type correctly here, hence the casts below.
494
532
  // See: https://github.com/microsoft/TypeScript/issues/52144
533
+ const maybeId = (column as ColumnValueType).id;
534
+ if (maybeId !== undefined && this.containsColumnWithId(maybeId)) {
535
+ throw new UsageError(
536
+ `A column with ID "${(column as ColumnValueType).id}" already exists in the table.`,
537
+ );
538
+ }
539
+ }
540
+
541
+ // #endregion
542
+
543
+ // TypeScript is unable to narrow the column type correctly here, hence the casts below.
544
+ // See: https://github.com/microsoft/TypeScript/issues/52144
545
+ if (index === undefined) {
495
546
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
496
- this.columns.insertAtEnd(column as any);
547
+ this.columns.insertAtEnd(TreeArrayNode.spread(columns) as any);
497
548
  } else {
498
- // TypeScript is unable to narrow the types correctly here, hence the cast.
499
- // See: https://github.com/microsoft/TypeScript/issues/52144
500
549
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
501
- this.columns.insertAt(index, column as any);
550
+ this.columns.insertAt(index, TreeArrayNode.spread(columns) as any);
502
551
  }
503
552
 
504
- // Inserting the input node into the tree hydrates it, making it usable as a node.
505
- return column as ColumnValueType;
553
+ // Inserting the input nodes into the tree hydrates them, making them usable as nodes.
554
+ return columns as unknown as ColumnValueType[];
555
+ }
556
+
557
+ public insertRow({
558
+ row,
559
+ index,
560
+ }: TableSchema.InsertRowParameters<TRowSchema>): RowValueType {
561
+ const inserted = this.insertRows({
562
+ rows: [row],
563
+ index,
564
+ });
565
+ return inserted[0] ?? oob();
506
566
  }
507
567
 
508
568
  public insertRows({
509
569
  index,
510
570
  rows,
511
- }: TableSchema.InsertRowsParameters<RowInsertableType>): RowValueType[] {
571
+ }: TableSchema.InsertRowsParameters<TRowSchema>): RowValueType[] {
572
+ // #region Input validation
573
+
574
+ // Ensure index is valid
575
+ if (index !== undefined) {
576
+ Table.validateInsertionIndex(index, this.rows);
577
+ }
578
+
579
+ // Note: TypeScript is unable to narrow the type of the row type correctly here, hence the casts below.
580
+ // See: https://github.com/microsoft/TypeScript/issues/52144
581
+ for (const newRow of rows) {
582
+ // Check all of the rows being inserted an ensure the table does not already contain any with the same ID.
583
+ const maybeId = (newRow as RowValueType).id;
584
+ if (maybeId !== undefined && this.containsRowWithId(maybeId)) {
585
+ throw new UsageError(
586
+ `A row with ID "${(newRow as RowValueType).id}" already exists in the table.`,
587
+ );
588
+ }
589
+
590
+ // If the row contains cells, verify that the table contains the columns for those cells.
591
+ // Note: we intentionally hide `cells` on `IRow` to avoid leaking the internal data representation as much as possible, so we have to cast here.
592
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
593
+ if ((newRow as any).cells !== undefined) {
594
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
595
+ const keys: string[] = Object.keys((newRow as any).cells);
596
+ for (const key of keys) {
597
+ if (!this.containsColumnWithId(key)) {
598
+ throw new UsageError(
599
+ `Attempted to insert row a cell under column ID "${key}", but the table does not contain a column with that ID.`,
600
+ );
601
+ }
602
+ }
603
+ }
604
+ }
605
+
606
+ // #endregion
607
+
608
+ // TypeScript is unable to narrow the row type correctly here, hence the casts below.
609
+ // See: https://github.com/microsoft/TypeScript/issues/52144
512
610
  if (index === undefined) {
513
- // TypeScript is unable to narrow the types correctly here, hence the cast.
514
- // See: https://github.com/microsoft/TypeScript/issues/52144
515
611
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
516
612
  this.rows.insertAtEnd(TreeArrayNode.spread(rows) as any);
517
613
  } else {
518
- // TypeScript is unable to narrow the types correctly here, hence the cast.
519
- // See: https://github.com/microsoft/TypeScript/issues/52144
520
614
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
521
615
  this.rows.insertAt(index, TreeArrayNode.spread(rows) as any);
522
616
  }
@@ -525,65 +619,204 @@ export namespace System_TableSchema {
525
619
  return rows as unknown as RowValueType[];
526
620
  }
527
621
 
528
- public setCell({ key, cell }: TableSchema.SetCellParameters<CellInsertableType>): void {
529
- const { columnId, rowId } = key;
530
- const row = this.getRow(rowId);
531
- if (row !== undefined) {
532
- const column = this.getColumn(columnId);
533
- if (column !== undefined) {
534
- row.setCell(column.id, cell);
535
- }
622
+ public setCell({
623
+ key,
624
+ cell,
625
+ }: TableSchema.SetCellParameters<TCellSchema, TColumnSchema, TRowSchema>): void {
626
+ const { column: columnOrId, row: rowOrId } = key;
627
+
628
+ const row = this._getRow(rowOrId);
629
+ if (row === undefined) {
630
+ const rowId = this._getRowId(rowOrId);
631
+ throw new UsageError(`No row with ID "${rowId}" exists in the table.`);
536
632
  }
633
+
634
+ const column = this._getColumn(columnOrId);
635
+ if (column === undefined) {
636
+ const columnId = this._getColumnId(columnOrId);
637
+ throw new UsageError(`No column with ID "${columnId}" exists in the table.`);
638
+ }
639
+
640
+ row.setCell(column, cell);
537
641
  }
538
642
 
539
- public removeColumn(column: ColumnValueType): void {
540
- const index = this.columns.indexOf(column);
541
- // If the column is not in the table, do nothing
542
- if (index === -1) return;
643
+ public removeColumns(
644
+ columns: readonly string[] | readonly ColumnValueType[],
645
+ ): ColumnValueType[] {
646
+ // If there are no columns to remove, do nothing
647
+ if (columns.length === 0) {
648
+ return [];
649
+ }
650
+
651
+ // If there is only one column to remove, remove it (and don't incur cost of transaction)
652
+ if (columns.length === 1) {
653
+ const removedColumn = this.removeColumn(columns[0] ?? oob());
654
+ return [removedColumn];
655
+ }
656
+
657
+ // If there are multiple columns to remove, remove them in a transaction.
658
+ const removedColumns: ColumnValueType[] = [];
659
+ Tree.runTransaction(this, () => {
660
+ // Note, throwing an error within a transaction will abort the entire transaction.
661
+ // So if we throw an error here for any row, no columns will be removed.
662
+ for (const columnToRemove of columns) {
663
+ const removedRow = this.removeColumn(columnToRemove);
664
+ removedColumns.push(removedRow);
665
+ }
666
+ });
667
+ return removedColumns;
668
+ }
669
+
670
+ public removeColumn(columnOrId: string | ColumnValueType): ColumnValueType {
671
+ const column = this._getColumn(columnOrId);
672
+ const index = column === undefined ? -1 : this.columns.indexOf(column);
673
+ if (index === -1) {
674
+ const columnId = this._getColumnId(columnOrId);
675
+ throw new UsageError(
676
+ `Specified column with ID "${columnId}" does not exist in the table.`,
677
+ );
678
+ }
543
679
  this.columns.removeAt(index);
680
+ return column as ColumnValueType;
681
+ }
682
+
683
+ public removeAllColumns(): ColumnValueType[] {
684
+ // TypeScript is unable to narrow the row type correctly here, hence the cast.
685
+ // See: https://github.com/microsoft/TypeScript/issues/52144
686
+ return this.removeColumns(this.columns as unknown as ColumnValueType[]);
544
687
  }
545
688
 
546
- public removeRows(rows: readonly RowValueType[]): void {
689
+ public removeRows(rows: readonly string[] | readonly RowValueType[]): RowValueType[] {
547
690
  // If there are no rows to remove, do nothing
548
691
  if (rows.length === 0) {
549
- return;
692
+ return [];
550
693
  }
551
694
 
552
- // If there is only one row to remove, remove it
695
+ // If there is only one row to remove, remove it (and don't incur cost of transaction)
553
696
  if (rows.length === 1) {
554
- const index = this.rows.indexOf(rows[0] ?? oob());
555
- this.rows.removeAt(index);
556
- return;
697
+ const removedRow = this.removeRow(rows[0] ?? oob());
698
+ return [removedRow];
557
699
  }
558
- // If there are multiple rows to remove, remove them in a transaction
559
- // This is to avoid the performance issues of deleting multiple rows at once
700
+
701
+ // If there are multiple rows to remove, remove them in a transaction.
702
+ const removedRows: RowValueType[] = [];
560
703
  Tree.runTransaction(this, () => {
561
- // Iterate over the rows and remove them
562
- for (const row of rows) {
563
- const index = this.rows.indexOf(row);
564
- this.rows.removeAt(index);
704
+ // Note, throwing an error within a transaction will abort the entire transaction.
705
+ // So if we throw an error here for any row, no rows will be removed.
706
+ for (const rowToRemove of rows) {
707
+ const removedRow = this.removeRow(rowToRemove);
708
+ removedRows.push(removedRow);
565
709
  }
566
710
  });
711
+ return removedRows;
712
+ }
713
+
714
+ public removeRow(rowOrId: string | RowValueType): RowValueType {
715
+ const rowToRemove = this._getRow(rowOrId);
716
+ const index = rowToRemove === undefined ? -1 : this.rows.indexOf(rowToRemove);
717
+
718
+ // If the row does not exist in the table, throw an error.
719
+ if (index === -1) {
720
+ const rowId = this._getRowId(rowOrId);
721
+ throw new UsageError(
722
+ `Specified row with ID "${rowId}" does not exist in the table.`,
723
+ );
724
+ }
725
+
726
+ this.rows.removeAt(index);
727
+ return rowToRemove as RowValueType;
567
728
  }
568
729
 
569
- public removeAllRows(): void {
570
- this.rows.removeRange();
730
+ public removeAllRows(): RowValueType[] {
731
+ // TypeScript is unable to narrow the row type correctly here, hence the cast.
732
+ // See: https://github.com/microsoft/TypeScript/issues/52144
733
+ return this.removeRows(this.rows as unknown as RowValueType[]);
571
734
  }
572
735
 
573
- public removeCell(key: TableSchema.CellKey): void {
574
- const { columnId, rowId } = key;
575
- const row = this.getRow(rowId);
576
- if (row !== undefined) {
577
- const column = this.getColumn(columnId);
578
- if (column !== undefined) {
579
- row.removeCell(column.id);
580
- }
736
+ public removeCell(
737
+ key: TableSchema.CellKey<TColumnSchema, TRowSchema>,
738
+ ): CellValueType | undefined {
739
+ const { column: columnOrId, row: rowOrId } = key;
740
+ const row = this._getRow(rowOrId);
741
+ if (row === undefined) {
742
+ const rowId = this._getRowId(rowOrId);
743
+ throw new UsageError(
744
+ `Specified row with ID "${rowId}" does not exist in the table.`,
745
+ );
746
+ }
747
+
748
+ const column = this._getColumn(columnOrId);
749
+ if (column === undefined) {
750
+ const columnId = this._getColumnId(columnOrId);
751
+ throw new UsageError(
752
+ `Specified column with ID "${columnId}" does not exist in the table.`,
753
+ );
754
+ }
755
+
756
+ const cell: CellValueType | undefined = row.getCell(column.id);
757
+ if (cell === undefined) {
758
+ return undefined;
759
+ }
760
+
761
+ row.removeCell(column.id);
762
+ return cell;
763
+ }
764
+
765
+ private _getColumn(columnOrId: string | ColumnValueType): ColumnValueType | undefined {
766
+ return typeof columnOrId === "string" ? this.getColumn(columnOrId) : columnOrId;
767
+ }
768
+
769
+ private _getColumnId(columnOrId: string | ColumnValueType): string {
770
+ return typeof columnOrId === "string" ? columnOrId : columnOrId.id;
771
+ }
772
+
773
+ private _getRow(rowOrId: string | RowValueType): RowValueType | undefined {
774
+ return typeof rowOrId === "string" ? this.getRow(rowOrId) : rowOrId;
775
+ }
776
+
777
+ private _getRowId(rowOrId: string | RowValueType): string {
778
+ return typeof rowOrId === "string" ? rowOrId : rowOrId.id;
779
+ }
780
+
781
+ private containsColumnWithId(columnId: string): boolean {
782
+ // TypeScript is unable to narrow the types correctly here, hence the cast.
783
+ // See: https://github.com/microsoft/TypeScript/issues/52144
784
+ return (
785
+ this.columns.find((column) => (column as TableSchema.Column).id === columnId) !==
786
+ undefined
787
+ );
788
+ }
789
+
790
+ private containsRowWithId(rowId: string): boolean {
791
+ // TypeScript is unable to narrow the types correctly here, hence the cast.
792
+ // See: https://github.com/microsoft/TypeScript/issues/52144
793
+ return this.rows.find((row) => (row as TableSchema.Row).id === rowId) !== undefined;
794
+ }
795
+
796
+ /**
797
+ * Ensure that the specified index is a valid location for item insertion in the destination list.
798
+ * @throws Throws a usage error if the destination is invalid.
799
+ */
800
+ private static validateInsertionIndex(
801
+ index: number,
802
+ destinationList: readonly unknown[],
803
+ ): void {
804
+ if (index < 0) {
805
+ throw new UsageError("The index must be greater than or equal to 0.");
806
+ }
807
+
808
+ if (index > destinationList.length) {
809
+ throw new UsageError("The index specified for insertion is out of bounds.");
810
+ }
811
+
812
+ if (!Number.isInteger(index)) {
813
+ throw new UsageError("The index must be an integer.");
581
814
  }
582
815
  }
583
816
  }
584
817
 
585
818
  type TableValueType = TreeNode &
586
- TableSchema.ITable<TCellSchema, TColumnSchema, TRowSchema> &
819
+ TableSchema.Table<TCellSchema, TColumnSchema, TRowSchema> &
587
820
  WithType<ScopedSchemaName<Scope, "Table">>;
588
821
  type TableInsertableType = InsertableObjectFromSchemaRecord<typeof tableFields>;
589
822
 
@@ -612,20 +845,100 @@ export namespace System_TableSchema {
612
845
  export type TableSchemaBase<
613
846
  TScope extends string | undefined,
614
847
  TCell extends ImplicitAllowedTypes,
615
- TColumn extends ColumnSchemaBase<TScope> = ColumnSchemaBase<TScope>,
616
- TRow extends RowSchemaBase<TScope, TCell, ImplicitAllowedTypes> = RowSchemaBase<
617
- TScope,
618
- TCell,
619
- ImplicitAllowedTypes
620
- >,
621
- > = ReturnType<typeof TableSchema.createTable<TScope, TCell, TColumn, TRow>>;
848
+ TColumn extends ColumnSchemaBase<TScope>,
849
+ TRow extends RowSchemaBase<TScope, TCell>,
850
+ > = ReturnType<typeof createTableInternal<TScope, TCell, TColumn, TRow>>;
622
851
 
623
852
  // #endregion
624
853
  }
625
854
 
626
855
  /**
627
856
  * Contains types and factories for creating schema to represent dynamic tabular data.
628
- * @privateRemarks TODO: document in more detail and add `@example`s.
857
+ *
858
+ * @remarks
859
+ *
860
+ * Tables created using these APIs are...
861
+ *
862
+ * - sparse, meaning that cells may be omitted, and new rows are empty by default.
863
+ *
864
+ * - dynamic, meaning that their structure can be modified at runtime.
865
+ * Columns and rows can be inserted, removed, modified, and reordered.
866
+ * Cells can be inserted, removed, and modified.
867
+ *
868
+ * - row-major, meaning that operating on rows (including inserts, removal, moves, and traversal) is more efficient than operating on columns.
869
+ *
870
+ * Column and Row schema created using these APIs are extensible via the `props` field.
871
+ * This allows association of additional properties with column and row nodes.
872
+ *
873
+ * Note: for now it is possible for table cells to become "orphaned".
874
+ * That is, it is possible to enter a state where one or more rows contain cells with no corresponding column.
875
+ * To help avoid this situation, you can manually remove corresponding cells when removing columns.
876
+ * Either way, it is possible to enter such a state via the merging of edits.
877
+ * For example: one client might add a row while another concurrently removes a column, orphaning the cell where the column and row intersected.
878
+ *
879
+ * @example Using default Column and Row schema
880
+ *
881
+ * ```typescript
882
+ * class Cell extends schemaFactory.object("TableCell", {
883
+ * value: schemaFactory.string,
884
+ * }) {}
885
+ *
886
+ * class Table extends TableSchema.createTable({
887
+ * schemaFactory,
888
+ * cell: Cell,
889
+ * }) {}
890
+ *
891
+ * const table = new Table({
892
+ * columns: [{ id: "column-0" }],
893
+ * rows: [{ id: "row-0", cells: {} }],
894
+ * });
895
+ * ```
896
+ *
897
+ * @example Customizing Column and Row schema
898
+ *
899
+ * ```typescript
900
+ * class Cell extends schemaFactory.object("TableCell", {
901
+ * value: schemaFactory.string,
902
+ * }) {}
903
+ *
904
+ * class ColumnProps extends schemaFactory.object("TableColumnProps", {
905
+ * // Column label to display.
906
+ * label: schemaFactory.string,
907
+ * // The type of data represented by the cells. Default: string.
908
+ * dataType: schemaFactory.optional(schemaFactory.string),
909
+ * }) {}
910
+ *
911
+ * class Column extends TableSchema.createColumn({
912
+ * schemaFactory,
913
+ * props: ColumnProps,
914
+ * }) {}
915
+ *
916
+ * class Row extends TableSchema.createRow({
917
+ * schemaFactory,
918
+ * cell: Cell,
919
+ * }) {}
920
+ *
921
+ * class Table extends TableSchema.createTable({
922
+ * schemaFactory,
923
+ * cell: Cell,
924
+ * column: Column,
925
+ * row: Row,
926
+ * }) {}
927
+ *
928
+ * const table = new Table({
929
+ * columns: [
930
+ * new Column({ props: { label: "Entry", dataType: "string" } }),
931
+ * new Column({ props: { label: "Date", dataType: "date" } }),
932
+ * new Column({ props: { label: "Amount", dataType: "number" } }),
933
+ * ],
934
+ * rows: [],
935
+ * });
936
+ * ```
937
+ *
938
+ * @privateRemarks
939
+ * The above examples are backed by tests in `tableSchema.spec.ts`.
940
+ * Those tests and these examples should be kept in-sync to ensure that the examples are correct.
941
+ *
629
942
  * @internal
630
943
  */
631
944
  export namespace TableSchema {
@@ -636,7 +949,7 @@ export namespace TableSchema {
636
949
  * @remarks Implemented by the schema class returned from {@link TableSchema.(createColumn:2)}.
637
950
  * @sealed @internal
638
951
  */
639
- export interface IColumn<
952
+ export interface Column<
640
953
  TProps extends ImplicitAnnotatedFieldSchema = ImplicitAnnotatedFieldSchema,
641
954
  > {
642
955
  /**
@@ -652,7 +965,7 @@ export namespace TableSchema {
652
965
  * Note: these docs are duplicated on the inline type definitions in {@link createColumn}.
653
966
  * If you update the docs here, please also update the inline type definitions.
654
967
  */
655
- get props(): TreeFieldFromImplicitField<UnannotateImplicitFieldSchema<TProps>> | undefined;
968
+ get props(): TreeFieldFromImplicitField<UnannotateImplicitFieldSchema<TProps>>;
656
969
  set props(value: InsertableTreeFieldFromImplicitField<
657
970
  UnannotateImplicitFieldSchema<TProps>
658
971
  >);
@@ -664,28 +977,25 @@ export namespace TableSchema {
664
977
  */
665
978
  export function createColumn<const TScope extends string | undefined>({
666
979
  schemaFactory,
667
- }: System_TableSchema.CreateColumnOptionsBase<TScope>): ReturnType<
668
- typeof System_TableSchema.createColumnInternal<
669
- TScope,
670
- FieldSchema<FieldKind.Optional, typeof SchemaFactoryAlpha.null>
671
- >
672
- >;
980
+ }: System_TableSchema.CreateColumnOptionsBase<
981
+ SchemaFactoryAlpha<TScope>
982
+ >): System_TableSchema.ColumnSchemaBase<TScope, System_TableSchema.DefaultPropsType>;
673
983
  /**
674
984
  * Factory for creating new table column schema.
675
985
  * @internal
676
986
  */
677
987
  export function createColumn<
678
988
  const TScope extends string | undefined,
679
- const TProps extends ImplicitFieldSchema,
989
+ const TProps extends ImplicitAnnotatedFieldSchema,
680
990
  >({
681
991
  schemaFactory,
682
992
  props,
683
- }: System_TableSchema.CreateColumnOptionsBase<TScope> & {
993
+ }: System_TableSchema.CreateColumnOptionsBase<SchemaFactoryAlpha<TScope>> & {
684
994
  /**
685
995
  * Optional column properties.
686
996
  */
687
997
  readonly props: TProps;
688
- }): ReturnType<typeof System_TableSchema.createColumnInternal<TScope, TProps>>;
998
+ }): System_TableSchema.ColumnSchemaBase<TScope, TProps>;
689
999
  /**
690
1000
  * Overload implementation
691
1001
  */
@@ -693,7 +1003,7 @@ export namespace TableSchema {
693
1003
  schemaFactory,
694
1004
  props = SchemaFactory.optional(SchemaFactory.null),
695
1005
  }: System_TableSchema.CreateColumnOptionsBase & {
696
- readonly props?: ImplicitFieldSchema;
1006
+ readonly props?: ImplicitAnnotatedFieldSchema;
697
1007
  }): TreeNodeSchema {
698
1008
  return System_TableSchema.createColumnInternal(schemaFactory, props);
699
1009
  }
@@ -707,8 +1017,8 @@ export namespace TableSchema {
707
1017
  * @remarks Implemented by the schema class returned from {@link TableSchema.(createRow:2)}.
708
1018
  * @sealed @internal
709
1019
  */
710
- export interface IRow<
711
- TCell extends ImplicitAllowedTypes,
1020
+ export interface Row<
1021
+ TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
712
1022
  TProps extends ImplicitAnnotatedFieldSchema = ImplicitAnnotatedFieldSchema,
713
1023
  > {
714
1024
  /**
@@ -720,8 +1030,9 @@ export namespace TableSchema {
720
1030
  /**
721
1031
  * Gets the cell in the specified column.
722
1032
  * @returns The cell if it exists, otherwise undefined.
1033
+ * @privateRemarks TODO: throw if the column does not belong to the same table as the row.
723
1034
  */
724
- getCell(column: IColumn): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
1035
+ getCell(column: Column): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
725
1036
  /**
726
1037
  * Gets the cell in the specified column, denoted by column ID.
727
1038
  * @returns The cell if it exists, otherwise undefined.
@@ -730,25 +1041,27 @@ export namespace TableSchema {
730
1041
 
731
1042
  /**
732
1043
  * Sets the cell in the specified column.
733
- * @remarks To remove a cell, call {@link TableSchema.IRow.(removeCell:1)} instead.
1044
+ * @remarks To remove a cell, call {@link TableSchema.Row.(removeCell:1)} instead.
1045
+ * @privateRemarks TODO: Throw an error if the column does not exist in the table.
734
1046
  */
735
- setCell(column: IColumn, value: InsertableTreeNodeFromImplicitAllowedTypes<TCell>): void;
1047
+ setCell(column: Column, value: InsertableTreeNodeFromImplicitAllowedTypes<TCell>): void;
736
1048
  /**
737
1049
  * Sets the cell in the specified column, denoted by column ID.
738
- * @remarks To remove a cell, call {@link TableSchema.IRow.(removeCell:2)} instead.
1050
+ * @remarks To remove a cell, call {@link TableSchema.Row.(removeCell:2)} instead.
739
1051
  */
740
1052
  setCell(columnId: string, value: InsertableTreeNodeFromImplicitAllowedTypes<TCell>): void;
741
1053
 
742
1054
  /**
743
1055
  * Removes the cell in the specified column.
744
- * @privateRemarks TODO: return removed cell
1056
+ * @returns The cell if it exists, otherwise undefined.
1057
+ * @privateRemarks TODO: Throw if the column does not belong to the same table as the row.
745
1058
  */
746
- removeCell(column: IColumn): void;
1059
+ removeCell(column: Column): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
747
1060
  /**
748
1061
  * Removes the cell in the specified column, denoted by column ID.
749
- * @privateRemarks TODO: return removed cell
1062
+ * @returns The cell if it exists, otherwise undefined.
750
1063
  */
751
- removeCell(columnId: string): void;
1064
+ removeCell(columnId: string): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
752
1065
 
753
1066
  /**
754
1067
  * The row's properties.
@@ -773,13 +1086,10 @@ export namespace TableSchema {
773
1086
  >({
774
1087
  schemaFactory,
775
1088
  cell,
776
- }: System_TableSchema.CreateRowOptionsBase<TScope, TCell>): ReturnType<
777
- typeof System_TableSchema.createRowInternal<
778
- TScope,
779
- TCell,
780
- FieldSchema<FieldKind.Optional, typeof SchemaFactoryAlpha.null>
781
- >
782
- >;
1089
+ }: System_TableSchema.CreateRowOptionsBase<
1090
+ SchemaFactoryAlpha<TScope>,
1091
+ TCell
1092
+ >): System_TableSchema.RowSchemaBase<TScope, TCell, System_TableSchema.DefaultPropsType>;
783
1093
  /**
784
1094
  * Factory for creating new table column schema.
785
1095
  * @internal
@@ -787,17 +1097,17 @@ export namespace TableSchema {
787
1097
  export function createRow<
788
1098
  const TScope extends string | undefined,
789
1099
  const TCell extends ImplicitAllowedTypes,
790
- const TProps extends ImplicitFieldSchema,
1100
+ const TProps extends ImplicitAnnotatedFieldSchema,
791
1101
  >({
792
1102
  schemaFactory,
793
1103
  cell,
794
1104
  props,
795
- }: System_TableSchema.CreateRowOptionsBase<TScope, TCell> & {
1105
+ }: System_TableSchema.CreateRowOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
796
1106
  /**
797
1107
  * Optional row properties.
798
1108
  */
799
1109
  readonly props: TProps;
800
- }): ReturnType<typeof System_TableSchema.createRowInternal<TScope, TCell, TProps>>;
1110
+ }): System_TableSchema.RowSchemaBase<TScope, TCell, TProps>;
801
1111
  /**
802
1112
  * Overload implementation
803
1113
  */
@@ -806,7 +1116,7 @@ export namespace TableSchema {
806
1116
  cell,
807
1117
  props = SchemaFactory.optional(SchemaFactory.null),
808
1118
  }: System_TableSchema.CreateRowOptionsBase & {
809
- readonly props?: ImplicitFieldSchema;
1119
+ readonly props?: ImplicitAnnotatedFieldSchema;
810
1120
  }): TreeNodeSchema {
811
1121
  return System_TableSchema.createRowInternal(schemaFactory, cell, props);
812
1122
  }
@@ -816,26 +1126,29 @@ export namespace TableSchema {
816
1126
  // #region Table
817
1127
 
818
1128
  /**
819
- * A key to uniquely identify a cell in a table.
1129
+ * A key to uniquely identify a cell within a table.
820
1130
  * @internal
821
1131
  */
822
- export interface CellKey {
1132
+ export interface CellKey<
1133
+ TColumn extends ImplicitAllowedTypes,
1134
+ TRow extends ImplicitAllowedTypes,
1135
+ > {
823
1136
  /**
824
- * {@link TableSchema.IColumn.id} of the containing {@link TableSchema.IColumn}.
1137
+ * {@link TableSchema.Column} or {@link TableSchema.Column.id} at which the cell is located.
825
1138
  */
826
- readonly columnId: string;
1139
+ readonly column: string | TreeNodeFromImplicitAllowedTypes<TColumn>;
827
1140
 
828
1141
  /**
829
- * {@link TableSchema.IRow.id} of the containing {@link TableSchema.IRow}.
1142
+ * {@link TableSchema.Row} or {@link TableSchema.Row.id} at which the cell is located.
830
1143
  */
831
- readonly rowId: string;
1144
+ readonly row: string | TreeNodeFromImplicitAllowedTypes<TRow>;
832
1145
  }
833
1146
 
834
1147
  /**
835
- * {@link TableSchema.ITable.insertColumn} parameters.
1148
+ * {@link TableSchema.Table.insertColumn} parameters.
836
1149
  * @internal
837
1150
  */
838
- export interface InsertColumnParameters<TInsertableColumn> {
1151
+ export interface InsertColumnParameters<TColumn extends ImplicitAllowedTypes> {
839
1152
  /**
840
1153
  * The index at which to insert the new column.
841
1154
  * @remarks If not provided, the column will be appended to the end of the table.
@@ -845,14 +1158,48 @@ export namespace TableSchema {
845
1158
  /**
846
1159
  * The column to insert.
847
1160
  */
848
- readonly column: TInsertableColumn;
1161
+ readonly column: InsertableTreeNodeFromImplicitAllowedTypes<TColumn>;
1162
+ }
1163
+
1164
+ /**
1165
+ * {@link TableSchema.Table.insertColumns} parameters.
1166
+ * @internal
1167
+ */
1168
+ export interface InsertColumnsParameters<TColumn extends ImplicitAllowedTypes> {
1169
+ /**
1170
+ * The index at which to insert the new columns.
1171
+ * @remarks If not provided, the columns will be appended to the end of the table.
1172
+ */
1173
+ readonly index?: number | undefined;
1174
+
1175
+ /**
1176
+ * The columns to insert.
1177
+ */
1178
+ readonly columns: InsertableTreeNodeFromImplicitAllowedTypes<TColumn>[];
1179
+ }
1180
+
1181
+ /**
1182
+ * {@link TableSchema.Table.insertRow} parameters.
1183
+ * @internal
1184
+ */
1185
+ export interface InsertRowParameters<TRow extends ImplicitAllowedTypes> {
1186
+ /**
1187
+ * The index at which to insert the new row.
1188
+ * @remarks If not provided, the row will be appended to the end of the table.
1189
+ */
1190
+ readonly index?: number | undefined;
1191
+
1192
+ /**
1193
+ * The row to insert.
1194
+ */
1195
+ readonly row: InsertableTreeNodeFromImplicitAllowedTypes<TRow>;
849
1196
  }
850
1197
 
851
1198
  /**
852
- * {@link TableSchema.ITable.insertRows} parameters.
1199
+ * {@link TableSchema.Table.insertRows} parameters.
853
1200
  * @internal
854
1201
  */
855
- export interface InsertRowsParameters<TInsertableRow> {
1202
+ export interface InsertRowsParameters<TRow extends ImplicitAllowedTypes> {
856
1203
  /**
857
1204
  * The index at which to insert the new rows.
858
1205
  * @remarks If not provided, the rows will be appended to the end of the table.
@@ -862,30 +1209,34 @@ export namespace TableSchema {
862
1209
  /**
863
1210
  * The rows to insert.
864
1211
  */
865
- readonly rows: TInsertableRow[];
1212
+ readonly rows: InsertableTreeNodeFromImplicitAllowedTypes<TRow>[];
866
1213
  }
867
1214
 
868
1215
  /**
869
- * {@link TableSchema.ITable.setCell} parameters.
1216
+ * {@link TableSchema.Table.setCell} parameters.
870
1217
  * @internal
871
1218
  */
872
- export interface SetCellParameters<TInsertableCell> {
1219
+ export interface SetCellParameters<
1220
+ TCell extends ImplicitAllowedTypes,
1221
+ TColumn extends ImplicitAllowedTypes,
1222
+ TRow extends ImplicitAllowedTypes,
1223
+ > {
873
1224
  /**
874
1225
  * The key to uniquely identify a cell in a table.
875
1226
  */
876
- readonly key: CellKey;
1227
+ readonly key: CellKey<TColumn, TRow>;
877
1228
 
878
1229
  /**
879
1230
  * The cell to set.
880
1231
  */
881
- readonly cell: TInsertableCell;
1232
+ readonly cell: InsertableTreeNodeFromImplicitAllowedTypes<TCell>;
882
1233
  }
883
1234
 
884
1235
  /**
885
1236
  * A table.
886
1237
  * @sealed @internal
887
1238
  */
888
- export interface ITable<
1239
+ export interface Table<
889
1240
  TCell extends ImplicitAllowedTypes,
890
1241
  TColumn extends ImplicitAllowedTypes,
891
1242
  TRow extends ImplicitAllowedTypes,
@@ -901,73 +1252,179 @@ export namespace TableSchema {
901
1252
  readonly rows: TreeArrayNode<TRow>;
902
1253
 
903
1254
  /**
904
- * Gets a table column by its {@link TableSchema.IRow.id}.
1255
+ * Gets a table column by its {@link TableSchema.Column.id}.
905
1256
  */
906
1257
  getColumn(id: string): TreeNodeFromImplicitAllowedTypes<TColumn> | undefined;
907
1258
 
908
1259
  /**
909
- * Gets a table row by its {@link TableSchema.IRow.id}.
1260
+ * Gets a table row by its {@link TableSchema.Row.id}.
910
1261
  */
911
1262
  getRow(id: string): TreeNodeFromImplicitAllowedTypes<TRow> | undefined;
912
1263
 
913
1264
  /**
914
1265
  * Gets a cell in the table by column and row IDs.
915
1266
  * @param key - A key that uniquely distinguishes a cell in the table, represented as a combination of the column ID and row ID.
916
- * @privateRemarks TODO: add overload that takes row and column nodes.
917
1267
  */
918
- getCell(key: CellKey): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
1268
+ getCell(key: CellKey<TColumn, TRow>): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
919
1269
 
920
1270
  /**
921
1271
  * Inserts a column into the table.
922
- * @throws Throws an error if the column is already in the tree, or if the specified index is out of range.
1272
+ *
1273
+ * @throws
1274
+ * Throws an error in the following cases:
1275
+ *
1276
+ * - The column, or a column with the same ID is already in the tree.
1277
+ *
1278
+ * - The specified index is out of range.
1279
+ *
1280
+ * No column is inserted in these cases.
923
1281
  */
924
1282
  insertColumn(
925
- params: InsertColumnParameters<InsertableTreeNodeFromImplicitAllowedTypes<TColumn>>,
1283
+ params: InsertColumnParameters<TColumn>,
926
1284
  ): TreeNodeFromImplicitAllowedTypes<TColumn>;
927
1285
 
1286
+ /**
1287
+ * Inserts 0 or more columns into the table.
1288
+ *
1289
+ * @throws
1290
+ * Throws an error in the following cases:
1291
+ *
1292
+ * - At least one column, or a column with the same ID is already in the tree.
1293
+ *
1294
+ * - The specified index is out of range.
1295
+ *
1296
+ * No columns are inserted in these cases.
1297
+ */
1298
+ insertColumns(
1299
+ params: InsertColumnsParameters<TColumn>,
1300
+ ): TreeNodeFromImplicitAllowedTypes<TColumn>[];
1301
+
1302
+ /**
1303
+ * Inserts a row into the table.
1304
+ *
1305
+ * @throws
1306
+ * Throws an error in the following cases:
1307
+ *
1308
+ * - The row, or a row with the same ID is already in the tree.
1309
+ *
1310
+ * - The row contains cells, but the table does not contain matching columns for one or more of those cells.
1311
+ *
1312
+ * - The specified index is out of range.
1313
+ *
1314
+ * No row is inserted in these cases.
1315
+ */
1316
+ insertRow(params: InsertRowParameters<TRow>): TreeNodeFromImplicitAllowedTypes<TRow>;
1317
+
928
1318
  /**
929
1319
  * Inserts 0 or more rows into the table.
930
- * @throws Throws an error if any of the rows are already in the tree, or if the specified index is out of range.
1320
+ *
1321
+ * @throws
1322
+ * Throws an error in the following cases:
1323
+ *
1324
+ * - At least one row, or a row with the same ID is already in the tree.
1325
+ *
1326
+ * - The row contains cells, but the table does not contain matching columns for one or more of those cells.
1327
+ *
1328
+ * - The specified index is out of range.
1329
+ *
1330
+ * No rows are inserted in these cases.
931
1331
  */
932
- insertRows(
933
- params: InsertRowsParameters<InsertableTreeNodeFromImplicitAllowedTypes<TRow>>,
934
- ): TreeNodeFromImplicitAllowedTypes<TRow>[];
1332
+ insertRows(params: InsertRowsParameters<TRow>): TreeNodeFromImplicitAllowedTypes<TRow>[];
935
1333
 
936
1334
  /**
937
1335
  * Sets the cell at the specified location in the table.
938
- * @remarks To remove a cell, call {@link TableSchema.ITable.removeCell} instead.
939
- * @privateRemarks TODO: add overload that takes column/row nodes?
1336
+ * @remarks To remove a cell, call {@link TableSchema.Table.removeCell} instead.
940
1337
  */
941
- setCell(
942
- params: SetCellParameters<InsertableTreeNodeFromImplicitAllowedTypes<TCell>>,
943
- ): void;
1338
+ setCell(params: SetCellParameters<TCell, TColumn, TRow>): void;
944
1339
 
945
1340
  /**
946
1341
  * Removes the specified column from the table.
947
- * @remarks Note: this does not remove any cells from the table's rows.
948
- * @privateRemarks
949
- * TODO:
950
- * - Policy for when the column is not in the table.
951
- * - Actually remove corresponding cells from table rows.
1342
+ *
1343
+ * @remarks
1344
+ * Note: this does not remove any cells from the table's rows.
1345
+ * To remove the corresponding cells, use {@link TableSchema.Table.removeCell}.
1346
+ *
1347
+ * @param column - The {@link TableSchema.Column | column} or {@link TableSchema.Column.id | column ID} to remove.
1348
+ * @throws Throws an error if the column is not in the table.
1349
+ * @privateRemarks TODO (future): Actually remove corresponding cells from table rows.
952
1350
  */
953
- removeColumn: (column: TreeNodeFromImplicitAllowedTypes<TColumn>) => void;
1351
+ removeColumn(
1352
+ column: string | TreeNodeFromImplicitAllowedTypes<TColumn>,
1353
+ ): TreeNodeFromImplicitAllowedTypes<TColumn>;
1354
+
1355
+ /**
1356
+ * Removes 0 or more columns from the table.
1357
+ *
1358
+ * @remarks
1359
+ * Note: this does not remove any cells from the table's rows.
1360
+ * To remove the corresponding cells, use {@link TableSchema.Table.removeCell}.
1361
+ *
1362
+ * @param columns - The columns to remove.
1363
+ * @throws Throws an error if any of the columns are not in the table.
1364
+ * In this case, no columns are removed.
1365
+ */
1366
+ removeColumns(
1367
+ columns: readonly TreeNodeFromImplicitAllowedTypes<TColumn>[],
1368
+ ): TreeNodeFromImplicitAllowedTypes<TColumn>[];
1369
+ /**
1370
+ * Removes 0 or more columns from the table.
1371
+ *
1372
+ * @remarks
1373
+ * Note: this does not remove any cells from the table's rows.
1374
+ * To remove the corresponding cells, use {@link TableSchema.Table.removeCell}.
1375
+ *
1376
+ * @param columns - The columns to remove, specified by their {@link TableSchema.Column.id}.
1377
+ * @throws Throws an error if any of the columns are not in the table.
1378
+ * In this case, no columns are removed.
1379
+ */
1380
+ removeColumns(columns: readonly string[]): TreeNodeFromImplicitAllowedTypes<TColumn>[];
1381
+
1382
+ /**
1383
+ * Removes all columns from the table.
1384
+ * @returns The removed columns.
1385
+ */
1386
+ removeAllColumns(): TreeNodeFromImplicitAllowedTypes<TColumn>[];
1387
+
1388
+ /**
1389
+ * Removes the specified row from the table.
1390
+ * @param row - The {@link TableSchema.Row | row} or {@link TableSchema.Row.id | row ID} to remove.
1391
+ * @throws Throws an error if the row is not in the table.
1392
+ */
1393
+ removeRow(
1394
+ row: string | TreeNodeFromImplicitAllowedTypes<TRow>,
1395
+ ): TreeNodeFromImplicitAllowedTypes<TRow>;
954
1396
 
955
1397
  /**
956
1398
  * Removes 0 or more rows from the table.
957
- * @privateRemarks TODO: policy for when 1 or more rows are not in the table.
1399
+ * @param rows - The rows to remove.
1400
+ * @throws Throws an error if any of the rows are not in the table.
1401
+ * In this case, no rows are removed.
958
1402
  */
959
- removeRows: (rows: readonly TreeNodeFromImplicitAllowedTypes<TRow>[]) => void;
1403
+ removeRows(
1404
+ rows: readonly TreeNodeFromImplicitAllowedTypes<TRow>[],
1405
+ ): TreeNodeFromImplicitAllowedTypes<TRow>[];
1406
+ /**
1407
+ * Removes 0 or more rows from the table.
1408
+ * @param rows - The rows to remove, specified by their {@link TableSchema.Row.id}.
1409
+ * @throws Throws an error if any of the rows are not in the table.
1410
+ * In this case, no rows are removed.
1411
+ */
1412
+ removeRows(rows: readonly string[]): TreeNodeFromImplicitAllowedTypes<TRow>[];
960
1413
 
961
1414
  /**
962
1415
  * Removes all rows from the table.
1416
+ * @returns The removed rows.
963
1417
  */
964
- removeAllRows: () => void;
1418
+ removeAllRows(): TreeNodeFromImplicitAllowedTypes<TRow>[];
965
1419
 
966
1420
  /**
967
1421
  * Removes the cell at the specified location in the table.
968
- * @privateRemarks TODO: add overload that takes column/row nodes?
1422
+ * @returns The cell if it exists, otherwise undefined.
1423
+ * @throws Throws an error if the location does not exist in the table.
969
1424
  */
970
- removeCell: (key: CellKey) => void;
1425
+ removeCell(
1426
+ key: CellKey<TColumn, TRow>,
1427
+ ): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
971
1428
  }
972
1429
 
973
1430
  /**
@@ -980,8 +1437,14 @@ export namespace TableSchema {
980
1437
  >({
981
1438
  schemaFactory,
982
1439
  cell,
983
- }: System_TableSchema.TableFactoryOptionsBase<TScope, TCell>): ReturnType<
984
- typeof System_TableSchema.createTableInternal<TScope, TCell>
1440
+ }: System_TableSchema.TableFactoryOptionsBase<
1441
+ SchemaFactoryAlpha<TScope>,
1442
+ TCell
1443
+ >): System_TableSchema.TableSchemaBase<
1444
+ TScope,
1445
+ TCell,
1446
+ System_TableSchema.ColumnSchemaBase<TScope, System_TableSchema.DefaultPropsType>,
1447
+ System_TableSchema.RowSchemaBase<TScope, TCell, System_TableSchema.DefaultPropsType>
985
1448
  >;
986
1449
  /**
987
1450
  * Factory for creating new table schema without specifying row schema.
@@ -995,9 +1458,14 @@ export namespace TableSchema {
995
1458
  schemaFactory,
996
1459
  cell,
997
1460
  column,
998
- }: System_TableSchema.TableFactoryOptionsBase<TScope, TCell> & {
1461
+ }: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
999
1462
  readonly column: TColumn;
1000
- }): ReturnType<typeof System_TableSchema.createTableInternal<TScope, TCell, TColumn>>;
1463
+ }): System_TableSchema.TableSchemaBase<
1464
+ TScope,
1465
+ TCell,
1466
+ TColumn,
1467
+ System_TableSchema.RowSchemaBase<TScope, TCell, System_TableSchema.DefaultPropsType>
1468
+ >;
1001
1469
  /**
1002
1470
  * Factory for creating new table schema.
1003
1471
  * @internal
@@ -1012,10 +1480,10 @@ export namespace TableSchema {
1012
1480
  cell,
1013
1481
  column,
1014
1482
  row,
1015
- }: System_TableSchema.TableFactoryOptionsBase<TScope, TCell> & {
1483
+ }: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1016
1484
  readonly column: TColumn;
1017
1485
  readonly row: TRow;
1018
- }): ReturnType<typeof System_TableSchema.createTableInternal<TScope, TCell, TColumn, TRow>>;
1486
+ }): System_TableSchema.TableSchemaBase<TScope, TCell, TColumn, TRow>;
1019
1487
  /**
1020
1488
  * Overload implementation
1021
1489
  */