Skip to content

Commit ea2f4c8

Browse files
authored
improvement(tree): Update table schema APIs to make underlying data representation safer / more opaque (microsoft#25979)
## Data format change Adds an extra layer to the table tree. The previous structure: ```typescript { columns: ListOfColumns; rows: ListOfRows; } ``` The new structure: ```typescript { table: { columns: ListOfColumns; rows: ListOfRows; } } ``` This extra root field/node will make future migrations to a new underlying format easier (we can migrate the node under the `table` field, rather than requiring the end-user to migrate the entire table node under its parent field in the application schema). ## API Safety Improvements Some editing operations on the `columns` and `rows` lists would allow users to make edits that would violate table invariants. The canonical example of this is deleting an entry from the `columns` list without removing corresponding cells from the `rows` list (cells live under `Row` nodes). Instead, the `Table` schema offers a series of safe editing APIs for the table as a whole (e.g., `deleteColumn`, which includes the deletion of corresponding cells). But we still wish to surface a subset of list-like editing options for the two lists. For example, since the ordering of these lists is intended to be significant, we would like to support rearrangement of elements within these lists. We would also like for users to be able to subscribe to shallow change notifications on the lists to learn when items have been inserted/removed/moved. `columns` and `rows` have had their typing updated to be more restrictive (forbidding direct insertion, deletion, and moving items _between_ lists), while still affording the subset of list functionality that is safe in terms of table invariants.
1 parent 1d33e00 commit ea2f4c8

File tree

12 files changed

+1407
-783
lines changed

12 files changed

+1407
-783
lines changed

examples/data-objects/table-tree/src/dataObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function getInitialTree(): Table {
9090
},
9191
});
9292

93-
return new Table({
93+
return Table.create({
9494
columns: [taskNameColumn, dateColumn, completedColumn],
9595
rows: [row0, row1],
9696
});

examples/utils/import-testing/src/test/importer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe("import tests", () => {
8282
row: Row,
8383
}) {}
8484

85-
const _table = new Table({
85+
const _table = Table.create({
8686
columns: [
8787
new Column({
8888
props: {

packages/dds/tree/api-report/tree.alpha.api.md

Lines changed: 29 additions & 12 deletions
Large diffs are not rendered by default.

packages/dds/tree/src/simple-tree/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export { asTreeViewAlpha } from "./tree.js";
2828
export { type SchemaStatics, schemaStatics } from "./schemaStatics.js";
2929
export {
3030
SchemaFactory,
31+
scoped,
3132
type ScopedSchemaName,
3233
type ObjectSchemaOptionsAlpha,
3334
type ObjectSchemaOptions,

packages/dds/tree/src/simple-tree/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export {
7575
type SchemaCompatibilityStatus,
7676
type ITreeConfigurationOptions,
7777
SchemaFactory,
78+
scoped,
7879
SchemaFactoryBeta,
7980
type SchemaStaticsBeta,
8081
SchemaFactoryAlpha,
@@ -248,6 +249,7 @@ export {
248249
type ObjectFromSchemaRecord,
249250
ObjectNodeSchema,
250251
type ObjectNodeSchemaPrivate,
252+
objectSchema,
251253
isObjectNodeSchema,
252254
type TreeObjectNode,
253255
setField,

0 commit comments

Comments
 (0)