@fluidframework/tree 2.63.0 → 2.70.0-360753

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 (167) hide show
  1. package/api-report/tree.alpha.api.md +31 -27
  2. package/api-report/tree.beta.api.md +36 -1
  3. package/api-report/tree.legacy.beta.api.md +36 -1
  4. package/dist/alpha.d.ts +4 -4
  5. package/dist/beta.d.ts +4 -0
  6. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +2 -2
  7. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  8. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +9 -10
  9. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  10. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -4
  11. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  12. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  13. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +1 -1
  14. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  15. package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -2
  16. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  17. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +9 -7
  18. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  19. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +34 -11
  20. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  21. package/dist/legacy.d.ts +4 -0
  22. package/dist/packageVersion.d.ts +1 -1
  23. package/dist/packageVersion.d.ts.map +1 -1
  24. package/dist/packageVersion.js +1 -1
  25. package/dist/packageVersion.js.map +1 -1
  26. package/dist/serializableDomainSchema.d.ts +12 -10
  27. package/dist/serializableDomainSchema.d.ts.map +1 -1
  28. package/dist/serializableDomainSchema.js +7 -7
  29. package/dist/serializableDomainSchema.js.map +1 -1
  30. package/dist/shared-tree/sharedTree.d.ts +1 -1
  31. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  32. package/dist/shared-tree/sharedTree.js +2 -2
  33. package/dist/shared-tree/sharedTree.js.map +1 -1
  34. package/dist/simple-tree/api/schemaFactory.d.ts +1 -1
  35. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  36. package/dist/simple-tree/api/schemaFactory.js +17 -13
  37. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  38. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  39. package/dist/simple-tree/api/schemaFactoryAlpha.js +8 -8
  40. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  41. package/dist/simple-tree/api/schemaFactoryBeta.d.ts +2 -1
  42. package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  43. package/dist/simple-tree/api/schemaFactoryBeta.js +8 -7
  44. package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  45. package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  46. package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  47. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
  48. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  49. package/dist/simple-tree/node-kinds/array/arrayNode.js +3 -2
  50. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  51. package/dist/simple-tree/node-kinds/map/mapNode.d.ts +4 -3
  52. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  53. package/dist/simple-tree/node-kinds/map/mapNode.js +3 -2
  54. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  55. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +4 -3
  56. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  57. package/dist/simple-tree/node-kinds/object/objectNode.js +5 -5
  58. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  59. package/dist/simple-tree/node-kinds/record/recordNode.d.ts +3 -10
  60. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  61. package/dist/simple-tree/node-kinds/record/recordNode.js +3 -2
  62. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  63. package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
  64. package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
  65. package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
  66. package/dist/tableSchema.d.ts +37 -24
  67. package/dist/tableSchema.d.ts.map +1 -1
  68. package/dist/tableSchema.js +81 -54
  69. package/dist/tableSchema.js.map +1 -1
  70. package/dist/treeFactory.d.ts.map +1 -1
  71. package/dist/treeFactory.js +1 -1
  72. package/dist/treeFactory.js.map +1 -1
  73. package/dist/util/utils.d.ts +11 -2
  74. package/dist/util/utils.d.ts.map +1 -1
  75. package/dist/util/utils.js.map +1 -1
  76. package/lib/alpha.d.ts +4 -4
  77. package/lib/beta.d.ts +4 -0
  78. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +2 -2
  79. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  80. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +9 -10
  81. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  82. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -4
  83. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  84. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  85. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +1 -1
  86. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  87. package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -2
  88. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  89. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +9 -7
  90. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  91. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +34 -11
  92. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  93. package/lib/legacy.d.ts +4 -0
  94. package/lib/packageVersion.d.ts +1 -1
  95. package/lib/packageVersion.d.ts.map +1 -1
  96. package/lib/packageVersion.js +1 -1
  97. package/lib/packageVersion.js.map +1 -1
  98. package/lib/serializableDomainSchema.d.ts +12 -10
  99. package/lib/serializableDomainSchema.d.ts.map +1 -1
  100. package/lib/serializableDomainSchema.js +8 -8
  101. package/lib/serializableDomainSchema.js.map +1 -1
  102. package/lib/shared-tree/sharedTree.d.ts +1 -1
  103. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  104. package/lib/shared-tree/sharedTree.js +2 -2
  105. package/lib/shared-tree/sharedTree.js.map +1 -1
  106. package/lib/simple-tree/api/schemaFactory.d.ts +1 -1
  107. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  108. package/lib/simple-tree/api/schemaFactory.js +18 -14
  109. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  110. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  111. package/lib/simple-tree/api/schemaFactoryAlpha.js +8 -8
  112. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  113. package/lib/simple-tree/api/schemaFactoryBeta.d.ts +2 -1
  114. package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  115. package/lib/simple-tree/api/schemaFactoryBeta.js +8 -7
  116. package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  117. package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  118. package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  119. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
  120. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  121. package/lib/simple-tree/node-kinds/array/arrayNode.js +3 -2
  122. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  123. package/lib/simple-tree/node-kinds/map/mapNode.d.ts +4 -3
  124. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  125. package/lib/simple-tree/node-kinds/map/mapNode.js +3 -2
  126. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  127. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +4 -3
  128. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  129. package/lib/simple-tree/node-kinds/object/objectNode.js +5 -5
  130. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  131. package/lib/simple-tree/node-kinds/record/recordNode.d.ts +3 -10
  132. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  133. package/lib/simple-tree/node-kinds/record/recordNode.js +3 -2
  134. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  135. package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
  136. package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
  137. package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
  138. package/lib/tableSchema.d.ts +37 -24
  139. package/lib/tableSchema.d.ts.map +1 -1
  140. package/lib/tableSchema.js +81 -54
  141. package/lib/tableSchema.js.map +1 -1
  142. package/lib/treeFactory.d.ts.map +1 -1
  143. package/lib/treeFactory.js +1 -1
  144. package/lib/treeFactory.js.map +1 -1
  145. package/lib/util/utils.d.ts +11 -2
  146. package/lib/util/utils.d.ts.map +1 -1
  147. package/lib/util/utils.js.map +1 -1
  148. package/package.json +21 -21
  149. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +16 -14
  150. package/src/feature-libraries/chunked-forest/codec/codecs.ts +8 -4
  151. package/src/feature-libraries/forest-summary/forestSummarizer.ts +2 -0
  152. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +65 -13
  153. package/src/packageVersion.ts +1 -1
  154. package/src/serializableDomainSchema.ts +11 -11
  155. package/src/shared-tree/sharedTree.ts +2 -0
  156. package/src/simple-tree/api/schemaFactory.ts +38 -22
  157. package/src/simple-tree/api/schemaFactoryAlpha.ts +8 -17
  158. package/src/simple-tree/api/schemaFactoryBeta.ts +17 -23
  159. package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -1
  160. package/src/simple-tree/node-kinds/array/arrayNode.ts +5 -4
  161. package/src/simple-tree/node-kinds/map/mapNode.ts +5 -3
  162. package/src/simple-tree/node-kinds/object/objectNode.ts +8 -7
  163. package/src/simple-tree/node-kinds/record/recordNode.ts +6 -18
  164. package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +2 -2
  165. package/src/tableSchema.ts +143 -81
  166. package/src/treeFactory.ts +1 -0
  167. package/src/util/utils.ts +11 -2
@@ -13,7 +13,7 @@ import {
13
13
  type InsertableObjectFromSchemaRecord,
14
14
  type InsertableTreeNodeFromImplicitAllowedTypes,
15
15
  type NodeKind,
16
- type SchemaFactoryAlpha,
16
+ type SchemaFactoryBeta,
17
17
  type ScopedSchemaName,
18
18
  TreeArrayNode,
19
19
  type TreeNode,
@@ -119,7 +119,7 @@ export namespace System_TableSchema {
119
119
  * @privateRemarks This interface primarily exists to provide a single home for property documentation.
120
120
  * @system @alpha
121
121
  */
122
- export interface OptionsWithSchemaFactory<TSchemaFactory extends SchemaFactoryAlpha> {
122
+ export interface OptionsWithSchemaFactory<TSchemaFactory extends SchemaFactoryBeta> {
123
123
  /**
124
124
  * Schema factory with which the Column schema will be associated.
125
125
  * @remarks Can be used to associate the resulting schema with an existing {@link SchemaFactory.scope|scope}.
@@ -148,7 +148,7 @@ export namespace System_TableSchema {
148
148
  * @system @alpha
149
149
  */
150
150
  export type CreateColumnOptionsBase<
151
- TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
151
+ TSchemaFactory extends SchemaFactoryBeta = SchemaFactoryBeta,
152
152
  TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
153
153
  > = OptionsWithSchemaFactory<TSchemaFactory> & OptionsWithCellSchema<TCell>;
154
154
 
@@ -162,11 +162,11 @@ export namespace System_TableSchema {
162
162
  const TCellSchema extends ImplicitAllowedTypes,
163
163
  const TPropsSchema extends ImplicitFieldSchema,
164
164
  >(
165
- inputSchemaFactory: SchemaFactoryAlpha<TInputScope>,
165
+ inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
166
166
  cellSchema: TCellSchema,
167
167
  propsSchema: TPropsSchema,
168
168
  ) {
169
- const schemaFactory = inputSchemaFactory.scopedFactoryAlpha(tableSchemaFactorySubScope);
169
+ const schemaFactory = inputSchemaFactory.scopedFactory(tableSchemaFactorySubScope);
170
170
  type Scope = ScopedSchemaName<TInputScope, typeof tableSchemaFactorySubScope>;
171
171
 
172
172
  type CellValueType = TreeNodeFromImplicitAllowedTypes<TCellSchema>;
@@ -320,7 +320,7 @@ export namespace System_TableSchema {
320
320
  * @system @alpha
321
321
  */
322
322
  export type CreateRowOptionsBase<
323
- TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
323
+ TSchemaFactory extends SchemaFactoryBeta = SchemaFactoryBeta,
324
324
  TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
325
325
  > = OptionsWithSchemaFactory<TSchemaFactory> & OptionsWithCellSchema<TCell>;
326
326
 
@@ -334,11 +334,11 @@ export namespace System_TableSchema {
334
334
  const TCellSchema extends ImplicitAllowedTypes,
335
335
  const TPropsSchema extends ImplicitFieldSchema,
336
336
  >(
337
- inputSchemaFactory: SchemaFactoryAlpha<TInputScope>,
337
+ inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
338
338
  cellSchema: TCellSchema,
339
339
  propsSchema: TPropsSchema,
340
340
  ) {
341
- const schemaFactory = inputSchemaFactory.scopedFactoryAlpha(tableSchemaFactorySubScope);
341
+ const schemaFactory = inputSchemaFactory.scopedFactory(tableSchemaFactorySubScope);
342
342
  type Scope = ScopedSchemaName<TInputScope, typeof tableSchemaFactorySubScope>;
343
343
 
344
344
  type CellValueType = TreeNodeFromImplicitAllowedTypes<TCellSchema>;
@@ -538,7 +538,7 @@ export namespace System_TableSchema {
538
538
  * @system @alpha
539
539
  */
540
540
  export type TableFactoryOptionsBase<
541
- TSchemaFactory extends SchemaFactoryAlpha = SchemaFactoryAlpha,
541
+ TSchemaFactory extends SchemaFactoryBeta = SchemaFactoryBeta,
542
542
  TCell extends ImplicitAllowedTypes = ImplicitAllowedTypes,
543
543
  > = OptionsWithSchemaFactory<TSchemaFactory> & OptionsWithCellSchema<TCell>;
544
544
 
@@ -553,12 +553,12 @@ export namespace System_TableSchema {
553
553
  const TColumnSchema extends ColumnSchemaBase<TInputScope, TCellSchema>,
554
554
  const TRowSchema extends RowSchemaBase<TInputScope, TCellSchema>,
555
555
  >(
556
- inputSchemaFactory: SchemaFactoryAlpha<TInputScope>,
556
+ inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
557
557
  _cellSchema: TCellSchema,
558
558
  columnSchema: TColumnSchema,
559
559
  rowSchema: TRowSchema,
560
560
  ) {
561
- const schemaFactory = inputSchemaFactory.scopedFactoryAlpha(tableSchemaFactorySubScope);
561
+ const schemaFactory = inputSchemaFactory.scopedFactory(tableSchemaFactorySubScope);
562
562
  type Scope = ScopedSchemaName<TInputScope, typeof tableSchemaFactorySubScope>;
563
563
 
564
564
  type CellValueType = TreeNodeFromImplicitAllowedTypes<TCellSchema>;
@@ -579,7 +579,7 @@ export namespace System_TableSchema {
579
579
  * The Table schema
580
580
  */
581
581
  class Table
582
- extends schemaFactory.objectAlpha("Table", tableFields, {
582
+ extends schemaFactory.object("Table", tableFields, {
583
583
  // Will make it easier to evolve this schema in the future.
584
584
  allowUnknownOptionalFields: true,
585
585
  })
@@ -591,32 +591,24 @@ export namespace System_TableSchema {
591
591
  return new this({ columns: [], rows: [] }) as InstanceType<TThis>;
592
592
  }
593
593
 
594
- public getColumn(id: string): ColumnValueType | undefined {
595
- // TypeScript is unable to narrow the types correctly here, hence the casts.
596
- // See: https://github.com/microsoft/TypeScript/issues/52144
597
- return this.columns.find((column) => (column as ColumnValueType).id === id) as
598
- | ColumnValueType
599
- | undefined;
594
+ public getColumn(indexOrId: number | string): ColumnValueType | undefined {
595
+ return this._tryGetColumn(indexOrId);
600
596
  }
601
597
 
602
- public getRow(id: string): RowValueType | undefined {
603
- // TypeScript is unable to narrow the types correctly here, hence the casts.
604
- // See: https://github.com/microsoft/TypeScript/issues/52144
605
- return this.rows.find((_row) => (_row as RowValueType).id === id) as
606
- | RowValueType
607
- | undefined;
598
+ public getRow(indexOrId: number | string): RowValueType | undefined {
599
+ return this._tryGetRow(indexOrId);
608
600
  }
609
601
 
610
602
  public getCell(
611
603
  key: TableSchema.CellKey<TColumnSchema, TRowSchema>,
612
604
  ): CellValueType | undefined {
613
- const { column: columnOrId, row: rowOrId } = key;
614
- const row = this._tryGetRow(rowOrId);
605
+ const { column: columnOrIdOrIndex, row: rowOrIdOrIndex } = key;
606
+ const row = this._tryGetRow(rowOrIdOrIndex);
615
607
  if (row === undefined) {
616
608
  return undefined;
617
609
  }
618
610
 
619
- const column = this._tryGetColumn(columnOrId);
611
+ const column = this._tryGetColumn(columnOrIdOrIndex);
620
612
  if (column === undefined) {
621
613
  return undefined;
622
614
  }
@@ -816,7 +808,8 @@ export namespace System_TableSchema {
816
808
  // So if we throw an error here for any row, no rows will be removed.
817
809
  for (const rowToRemove of rowsToRemove) {
818
810
  // We have already validated that all of the rows exist above, so this is safe.
819
- this.rows.removeAt(this.rows.indexOf(rowToRemove));
811
+ const index = this.rows.indexOf(rowToRemove);
812
+ this.rows.removeAt(index);
820
813
  }
821
814
  });
822
815
  return rowsToRemove;
@@ -825,9 +818,9 @@ export namespace System_TableSchema {
825
818
  public removeCell(
826
819
  key: TableSchema.CellKey<TColumnSchema, TRowSchema>,
827
820
  ): CellValueType | undefined {
828
- const { column: columnOrId, row: rowOrId } = key;
829
- const row = this._getRow(rowOrId);
830
- const column = this._getColumn(columnOrId);
821
+ const { column: columnOrIdOrIndex, row: rowOrIdOrIndex } = key;
822
+ const row = this._getRow(rowOrIdOrIndex);
823
+ const column = this._getColumn(columnOrIdOrIndex);
831
824
 
832
825
  const cell: CellValueType | undefined = row.getCell(column.id);
833
826
  if (cell === undefined) {
@@ -906,10 +899,32 @@ export namespace System_TableSchema {
906
899
  * @remarks Searches for a match based strictly on the ID and returns that result.
907
900
  */
908
901
  private _tryGetColumn(
909
- columnOrId: string | ColumnValueType,
902
+ columnOrIdOrIndex: ColumnValueType | string | number,
910
903
  ): ColumnValueType | undefined {
911
- const columnId = this._getColumnId(columnOrId);
912
- return this.getColumn(columnId);
904
+ if (typeof columnOrIdOrIndex === "number") {
905
+ if (columnOrIdOrIndex < 0 || columnOrIdOrIndex >= this.columns.length) {
906
+ return undefined;
907
+ }
908
+ // TypeScript is unable to narrow the types correctly here, hence the cast.
909
+ // See: https://github.com/microsoft/TypeScript/issues/52144
910
+ return this.columns[columnOrIdOrIndex] as ColumnValueType;
911
+ }
912
+
913
+ if (typeof columnOrIdOrIndex === "string") {
914
+ const columnId = columnOrIdOrIndex;
915
+ // TypeScript is unable to narrow the types correctly here, hence the casts.
916
+ // See: https://github.com/microsoft/TypeScript/issues/52144
917
+ return this.columns.find((col) => (col as ColumnValueType).id === columnId) as
918
+ | ColumnValueType
919
+ | undefined;
920
+ }
921
+
922
+ // If the user provided a node, ensure it actually exists in this table.
923
+ if (!this.columns.includes(columnOrIdOrIndex)) {
924
+ return undefined;
925
+ }
926
+
927
+ return columnOrIdOrIndex;
913
928
  }
914
929
 
915
930
  /**
@@ -917,23 +932,16 @@ export namespace System_TableSchema {
917
932
  * @throws Throws a `UsageError` if there is no match.
918
933
  * @remarks Searches for a match based strictly on the ID and returns that result.
919
934
  */
920
- private _getColumn(columnOrId: string | ColumnValueType): ColumnValueType {
921
- const column = this._tryGetColumn(columnOrId);
935
+ private _getColumn(
936
+ columnOrIdOrIndex: ColumnValueType | string | number,
937
+ ): ColumnValueType {
938
+ const column = this._tryGetColumn(columnOrIdOrIndex);
922
939
  if (column === undefined) {
923
- this._throwMissingColumnError(this._getColumnId(columnOrId));
940
+ Table._throwMissingColumnError(columnOrIdOrIndex);
924
941
  }
925
942
  return column;
926
943
  }
927
944
 
928
- /**
929
- * Resolves a Column node or ID to its ID.
930
- * If an ID is provided, it is returned as-is.
931
- * If a node is provided, its ID is returned.
932
- */
933
- private _getColumnId(columnOrId: string | ColumnValueType): string {
934
- return typeof columnOrId === "string" ? columnOrId : columnOrId.id;
935
- }
936
-
937
945
  /**
938
946
  * Checks if a Column with the specified ID exists in the table.
939
947
  */
@@ -942,10 +950,24 @@ export namespace System_TableSchema {
942
950
  }
943
951
 
944
952
  /**
945
- * Throw a `UsageError` for a missing Column by its ID.
953
+ * Throw a `UsageError` for a missing Column by its ID or index.
946
954
  */
947
- private _throwMissingColumnError(columnId: string): never {
948
- throw new UsageError(`No column with ID "${columnId}" exists in the table.`);
955
+ private static _throwMissingColumnError(
956
+ columnOrIdOrIndex: ColumnValueType | string | number,
957
+ ): never {
958
+ if (typeof columnOrIdOrIndex === "number") {
959
+ throw new UsageError(`No column exists at index ${columnOrIdOrIndex}.`);
960
+ }
961
+
962
+ if (typeof columnOrIdOrIndex === "string") {
963
+ throw new UsageError(
964
+ `No column with ID "${columnOrIdOrIndex}" exists in the table.`,
965
+ );
966
+ }
967
+
968
+ throw new UsageError(
969
+ `The specified column node with ID "${columnOrIdOrIndex.id}" does not exist in the table.`,
970
+ );
949
971
  }
950
972
 
951
973
  /**
@@ -953,38 +975,65 @@ export namespace System_TableSchema {
953
975
  * Returns `undefined` if there is no match.
954
976
  * @remarks Searches for a match based strictly on the ID and returns that result.
955
977
  */
956
- private _tryGetRow(rowOrId: string | RowValueType): RowValueType | undefined {
957
- const rowId = this._getRowId(rowOrId);
958
- return this.getRow(rowId);
978
+ private _tryGetRow(
979
+ rowOrIdOrIndex: RowValueType | string | number,
980
+ ): RowValueType | undefined {
981
+ if (typeof rowOrIdOrIndex === "number") {
982
+ if (rowOrIdOrIndex < 0 || rowOrIdOrIndex >= this.rows.length) {
983
+ return undefined;
984
+ }
985
+ // TypeScript is unable to narrow the types correctly here, hence the cast.
986
+ // See: https://github.com/microsoft/TypeScript/issues/52144
987
+ return this.rows[rowOrIdOrIndex] as RowValueType;
988
+ }
989
+
990
+ if (typeof rowOrIdOrIndex === "string") {
991
+ const rowId = rowOrIdOrIndex;
992
+ // TypeScript is unable to narrow the types correctly here, hence the casts.
993
+ // See: https://github.com/microsoft/TypeScript/issues/52144
994
+ return this.rows.find((row) => (row as RowValueType).id === rowId) as
995
+ | RowValueType
996
+ | undefined;
997
+ }
998
+
999
+ // If the user provided a node, ensure it actually exists in this table.
1000
+ if (!this.rows.includes(rowOrIdOrIndex)) {
1001
+ return undefined;
1002
+ }
1003
+
1004
+ return rowOrIdOrIndex;
959
1005
  }
960
1006
 
961
1007
  /**
962
- * Attempts to resolve the provided Row node or ID to a Row node in the table.
1008
+ * Attempts to resolve the provided Row node, ID, or index to a Row node in the table.
963
1009
  * @throws Throws a `UsageError` if there is no match.
964
1010
  * @remarks Searches for a match based strictly on the ID and returns that result.
965
1011
  */
966
- private _getRow(rowOrId: string | RowValueType): RowValueType {
967
- const row = this._tryGetRow(rowOrId);
1012
+ private _getRow(rowOrIdOrIndex: RowValueType | string | number): RowValueType {
1013
+ const row = this._tryGetRow(rowOrIdOrIndex);
968
1014
  if (row === undefined) {
969
- this._throwMissingRowError(this._getRowId(rowOrId));
1015
+ Table._throwMissingRowError(rowOrIdOrIndex);
970
1016
  }
971
1017
  return row;
972
1018
  }
973
1019
 
974
1020
  /**
975
- * Resolves a Row node or ID to its ID.
976
- * If an ID is provided, it is returned as-is.
977
- * If a node is provided, its ID is returned.
1021
+ * Throw a `UsageError` for a missing Row by its ID or index.
978
1022
  */
979
- private _getRowId(rowOrId: string | RowValueType): string {
980
- return typeof rowOrId === "string" ? rowOrId : rowOrId.id;
981
- }
1023
+ private static _throwMissingRowError(
1024
+ rowOrIdOrIndex: RowValueType | string | number,
1025
+ ): never {
1026
+ if (typeof rowOrIdOrIndex === "number") {
1027
+ throw new UsageError(`No row exists at index ${rowOrIdOrIndex}.`);
1028
+ }
982
1029
 
983
- /**
984
- * Throw a `UsageError` for a missing Row by its ID.
985
- */
986
- private _throwMissingRowError(rowId: string): never {
987
- throw new UsageError(`No row with ID "${rowId}" exists in the table.`);
1030
+ if (typeof rowOrIdOrIndex === "string") {
1031
+ throw new UsageError(`No row with ID "${rowOrIdOrIndex}" exists in the table.`);
1032
+ }
1033
+
1034
+ throw new UsageError(
1035
+ `The specified row node with ID "${rowOrIdOrIndex.id}" does not exist in the table.`,
1036
+ );
988
1037
  }
989
1038
 
990
1039
  private static _removeRange<TNodeSchema extends ImplicitAllowedTypes>(
@@ -1225,7 +1274,7 @@ export namespace TableSchema {
1225
1274
 
1226
1275
  /**
1227
1276
  * Gets all of the populated cells in the column, keyed by their associated row IDs.
1228
- * @throws Throws an error if the column is not in a table.
1277
+ * @throws Throws an error if the column is not in a table.
1229
1278
  */
1230
1279
  getCells(): readonly {
1231
1280
  rowId: string;
@@ -1243,7 +1292,7 @@ export namespace TableSchema {
1243
1292
  const TScope extends string | undefined,
1244
1293
  const TCell extends ImplicitAllowedTypes,
1245
1294
  >(
1246
- params: System_TableSchema.CreateColumnOptionsBase<SchemaFactoryAlpha<TScope>, TCell>,
1295
+ params: System_TableSchema.CreateColumnOptionsBase<SchemaFactoryBeta<TScope>, TCell>,
1247
1296
  ): System_TableSchema.ColumnSchemaBase<TScope, TCell, System_TableSchema.DefaultPropsType>;
1248
1297
  /**
1249
1298
  * Factory for creating new table column schema.
@@ -1257,7 +1306,7 @@ export namespace TableSchema {
1257
1306
  const TCell extends ImplicitAllowedTypes,
1258
1307
  const TProps extends ImplicitFieldSchema,
1259
1308
  >(
1260
- params: System_TableSchema.CreateColumnOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1309
+ params: System_TableSchema.CreateColumnOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
1261
1310
  /**
1262
1311
  * Optional column properties.
1263
1312
  */
@@ -1366,7 +1415,7 @@ export namespace TableSchema {
1366
1415
  const TScope extends string | undefined,
1367
1416
  const TCell extends ImplicitAllowedTypes,
1368
1417
  >(
1369
- params: System_TableSchema.CreateRowOptionsBase<SchemaFactoryAlpha<TScope>, TCell>,
1418
+ params: System_TableSchema.CreateRowOptionsBase<SchemaFactoryBeta<TScope>, TCell>,
1370
1419
  ): System_TableSchema.RowSchemaBase<TScope, TCell, System_TableSchema.DefaultPropsType>;
1371
1420
  /**
1372
1421
  * Factory for creating new table row schema.
@@ -1380,7 +1429,7 @@ export namespace TableSchema {
1380
1429
  const TCell extends ImplicitAllowedTypes,
1381
1430
  const TProps extends ImplicitFieldSchema,
1382
1431
  >(
1383
- params: System_TableSchema.CreateRowOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1432
+ params: System_TableSchema.CreateRowOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
1384
1433
  /**
1385
1434
  * Optional row properties.
1386
1435
  */
@@ -1413,14 +1462,14 @@ export namespace TableSchema {
1413
1462
  TRow extends ImplicitAllowedTypes,
1414
1463
  > {
1415
1464
  /**
1416
- * {@link TableSchema.Column} or {@link TableSchema.Column.id} at which the cell is located.
1465
+ * {@link TableSchema.Column}, {@link TableSchema.Column.id}, or column index at which the cell is located.
1417
1466
  */
1418
- readonly column: string | TreeNodeFromImplicitAllowedTypes<TColumn>;
1467
+ readonly column: string | number | TreeNodeFromImplicitAllowedTypes<TColumn>;
1419
1468
 
1420
1469
  /**
1421
- * {@link TableSchema.Row} or {@link TableSchema.Row.id} at which the cell is located.
1470
+ * {@link TableSchema.Row}, {@link TableSchema.Row.id}, or row index at which the cell is located.
1422
1471
  */
1423
- readonly row: string | TreeNodeFromImplicitAllowedTypes<TRow>;
1472
+ readonly row: string | number | TreeNodeFromImplicitAllowedTypes<TRow>;
1424
1473
  }
1425
1474
 
1426
1475
  /**
@@ -1503,17 +1552,30 @@ export namespace TableSchema {
1503
1552
 
1504
1553
  /**
1505
1554
  * Gets a table column by its {@link TableSchema.Column.id}.
1555
+ * @returns The column, if it exists. Otherwise, `undefined`.
1506
1556
  */
1507
1557
  getColumn(id: string): TreeNodeFromImplicitAllowedTypes<TColumn> | undefined;
1558
+ /**
1559
+ * Gets a table column by its index in the table.
1560
+ * @returns The column, if it exists. Otherwise, `undefined`.
1561
+ */
1562
+ getColumn(index: number): TreeNodeFromImplicitAllowedTypes<TColumn> | undefined;
1508
1563
 
1509
1564
  /**
1510
1565
  * Gets a table row by its {@link TableSchema.Row.id}.
1566
+ * @returns The row, if it exists. Otherwise, `undefined`.
1511
1567
  */
1512
1568
  getRow(id: string): TreeNodeFromImplicitAllowedTypes<TRow> | undefined;
1569
+ /**
1570
+ * Gets a table row by its index in the table.
1571
+ * @returns The row, if it exists. Otherwise, `undefined`.
1572
+ */
1573
+ getRow(index: number): TreeNodeFromImplicitAllowedTypes<TRow> | undefined;
1513
1574
 
1514
1575
  /**
1515
- * Gets a cell in the table by column and row IDs.
1576
+ * Gets a cell in the table by corresponding column and row.
1516
1577
  * @param key - A key that uniquely distinguishes a cell in the table, represented as a combination of the column ID and row ID.
1578
+ * @returns The cell, if it exists. Otherwise, `undefined`.
1517
1579
  */
1518
1580
  getCell(key: CellKey<TColumn, TRow>): TreeNodeFromImplicitAllowedTypes<TCell> | undefined;
1519
1581
 
@@ -1644,7 +1706,7 @@ export namespace TableSchema {
1644
1706
  const TScope extends string | undefined,
1645
1707
  const TCell extends ImplicitAllowedTypes,
1646
1708
  >(
1647
- params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell>,
1709
+ params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryBeta<TScope>, TCell>,
1648
1710
  ): System_TableSchema.TableSchemaBase<
1649
1711
  TScope,
1650
1712
  TCell,
@@ -1663,7 +1725,7 @@ export namespace TableSchema {
1663
1725
  const TCell extends ImplicitAllowedTypes,
1664
1726
  const TColumn extends System_TableSchema.ColumnSchemaBase<TScope, TCell>,
1665
1727
  >(
1666
- params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1728
+ params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
1667
1729
  readonly column: TColumn;
1668
1730
  },
1669
1731
  ): System_TableSchema.TableSchemaBase<
@@ -1684,7 +1746,7 @@ export namespace TableSchema {
1684
1746
  const TCell extends ImplicitAllowedTypes,
1685
1747
  const TRow extends System_TableSchema.RowSchemaBase<TScope, TCell>,
1686
1748
  >(
1687
- params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1749
+ params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
1688
1750
  readonly row: TRow;
1689
1751
  },
1690
1752
  ): System_TableSchema.TableSchemaBase<
@@ -1707,7 +1769,7 @@ export namespace TableSchema {
1707
1769
  const TColumn extends System_TableSchema.ColumnSchemaBase<TScope, TCell>,
1708
1770
  const TRow extends System_TableSchema.RowSchemaBase<TScope, TCell>,
1709
1771
  >(
1710
- params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryAlpha<TScope>, TCell> & {
1772
+ params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
1711
1773
  readonly column: TColumn;
1712
1774
  readonly row: TRow;
1713
1775
  },
@@ -72,6 +72,7 @@ function treeKernelFactory(
72
72
  args.serializer,
73
73
  args.submitLocalMessage,
74
74
  args.lastSequenceNumber,
75
+ args.initialSequenceNumber,
75
76
  args.logger,
76
77
  args.idCompressor,
77
78
  adjustedOptions,
package/src/util/utils.ts CHANGED
@@ -291,7 +291,11 @@ export function count(iterable: Iterable<unknown>): number {
291
291
  * @remarks
292
292
  * This does not robustly forbid non json comparable data via type checking,
293
293
  * but instead mostly restricts access to it.
294
- * @alpha
294
+ *
295
+ * @privateRemarks
296
+ * TODO (before promoting to public): consider moving this to a more general location - this isn't SharedTree-specific.
297
+ *
298
+ * @beta
295
299
  */
296
300
  export type JsonCompatible<TExtra = never> =
297
301
  | string
@@ -305,10 +309,15 @@ export type JsonCompatible<TExtra = never> =
305
309
 
306
310
  /**
307
311
  * Use for Json object compatible data.
312
+ *
308
313
  * @remarks
309
314
  * This does not robustly forbid non json comparable data via type checking,
310
315
  * but instead mostly restricts access to it.
311
- * @alpha
316
+ *
317
+ * @privateRemarks
318
+ * TODO (before promoting to public): consider moving this to a more general location - this isn't SharedTree-specific.
319
+ *
320
+ * @beta
312
321
  */
313
322
  export type JsonCompatibleObject<TExtra = never> = { [P in string]?: JsonCompatible<TExtra> };
314
323