@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.
- package/api-report/tree.alpha.api.md +31 -27
- package/api-report/tree.beta.api.md +36 -1
- package/api-report/tree.legacy.beta.api.md +36 -1
- package/dist/alpha.d.ts +4 -4
- package/dist/beta.d.ts +4 -0
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +2 -2
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +9 -10
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -4
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -2
- package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +9 -7
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +34 -11
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
- package/dist/legacy.d.ts +4 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/serializableDomainSchema.d.ts +12 -10
- package/dist/serializableDomainSchema.d.ts.map +1 -1
- package/dist/serializableDomainSchema.js +7 -7
- package/dist/serializableDomainSchema.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +1 -1
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +2 -2
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +17 -13
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +8 -8
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts +2 -1
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryBeta.js +8 -7
- package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +3 -2
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts +4 -3
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.js +3 -2
- package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +4 -3
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +5 -5
- package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts +3 -10
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.js +3 -2
- package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/dist/tableSchema.d.ts +37 -24
- package/dist/tableSchema.d.ts.map +1 -1
- package/dist/tableSchema.js +81 -54
- package/dist/tableSchema.js.map +1 -1
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js +1 -1
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/utils.d.ts +11 -2
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +4 -4
- package/lib/beta.d.ts +4 -0
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +2 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +9 -10
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -4
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -2
- package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +9 -7
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +34 -11
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
- package/lib/legacy.d.ts +4 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/serializableDomainSchema.d.ts +12 -10
- package/lib/serializableDomainSchema.d.ts.map +1 -1
- package/lib/serializableDomainSchema.js +8 -8
- package/lib/serializableDomainSchema.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +1 -1
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -2
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +18 -14
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +8 -8
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts +2 -1
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryBeta.js +8 -7
- package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +3 -2
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts +4 -3
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js +3 -2
- package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +4 -3
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +5 -5
- package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts +3 -10
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.js +3 -2
- package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/lib/tableSchema.d.ts +37 -24
- package/lib/tableSchema.d.ts.map +1 -1
- package/lib/tableSchema.js +81 -54
- package/lib/tableSchema.js.map +1 -1
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js +1 -1
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/utils.d.ts +11 -2
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js.map +1 -1
- package/package.json +21 -21
- package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +16 -14
- package/src/feature-libraries/chunked-forest/codec/codecs.ts +8 -4
- package/src/feature-libraries/forest-summary/forestSummarizer.ts +2 -0
- package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +65 -13
- package/src/packageVersion.ts +1 -1
- package/src/serializableDomainSchema.ts +11 -11
- package/src/shared-tree/sharedTree.ts +2 -0
- package/src/simple-tree/api/schemaFactory.ts +38 -22
- package/src/simple-tree/api/schemaFactoryAlpha.ts +8 -17
- package/src/simple-tree/api/schemaFactoryBeta.ts +17 -23
- package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -1
- package/src/simple-tree/node-kinds/array/arrayNode.ts +5 -4
- package/src/simple-tree/node-kinds/map/mapNode.ts +5 -3
- package/src/simple-tree/node-kinds/object/objectNode.ts +8 -7
- package/src/simple-tree/node-kinds/record/recordNode.ts +6 -18
- package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +2 -2
- package/src/tableSchema.ts +143 -81
- package/src/treeFactory.ts +1 -0
- package/src/util/utils.ts +11 -2
package/src/tableSchema.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
type InsertableObjectFromSchemaRecord,
|
|
14
14
|
type InsertableTreeNodeFromImplicitAllowedTypes,
|
|
15
15
|
type NodeKind,
|
|
16
|
-
type
|
|
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
|
|
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
|
|
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:
|
|
165
|
+
inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
|
|
166
166
|
cellSchema: TCellSchema,
|
|
167
167
|
propsSchema: TPropsSchema,
|
|
168
168
|
) {
|
|
169
|
-
const schemaFactory = inputSchemaFactory.
|
|
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
|
|
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:
|
|
337
|
+
inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
|
|
338
338
|
cellSchema: TCellSchema,
|
|
339
339
|
propsSchema: TPropsSchema,
|
|
340
340
|
) {
|
|
341
|
-
const schemaFactory = inputSchemaFactory.
|
|
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
|
|
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:
|
|
556
|
+
inputSchemaFactory: SchemaFactoryBeta<TInputScope>,
|
|
557
557
|
_cellSchema: TCellSchema,
|
|
558
558
|
columnSchema: TColumnSchema,
|
|
559
559
|
rowSchema: TRowSchema,
|
|
560
560
|
) {
|
|
561
|
-
const schemaFactory = inputSchemaFactory.
|
|
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.
|
|
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(
|
|
595
|
-
|
|
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(
|
|
603
|
-
|
|
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:
|
|
614
|
-
const row = this._tryGetRow(
|
|
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(
|
|
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.
|
|
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:
|
|
829
|
-
const row = this._getRow(
|
|
830
|
-
const column = this._getColumn(
|
|
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
|
-
|
|
902
|
+
columnOrIdOrIndex: ColumnValueType | string | number,
|
|
910
903
|
): ColumnValueType | undefined {
|
|
911
|
-
|
|
912
|
-
|
|
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(
|
|
921
|
-
|
|
935
|
+
private _getColumn(
|
|
936
|
+
columnOrIdOrIndex: ColumnValueType | string | number,
|
|
937
|
+
): ColumnValueType {
|
|
938
|
+
const column = this._tryGetColumn(columnOrIdOrIndex);
|
|
922
939
|
if (column === undefined) {
|
|
923
|
-
|
|
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(
|
|
948
|
-
|
|
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(
|
|
957
|
-
|
|
958
|
-
|
|
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
|
|
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(
|
|
967
|
-
const row = this._tryGetRow(
|
|
1012
|
+
private _getRow(rowOrIdOrIndex: RowValueType | string | number): RowValueType {
|
|
1013
|
+
const row = this._tryGetRow(rowOrIdOrIndex);
|
|
968
1014
|
if (row === undefined) {
|
|
969
|
-
|
|
1015
|
+
Table._throwMissingRowError(rowOrIdOrIndex);
|
|
970
1016
|
}
|
|
971
1017
|
return row;
|
|
972
1018
|
}
|
|
973
1019
|
|
|
974
1020
|
/**
|
|
975
|
-
*
|
|
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
|
|
980
|
-
|
|
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
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
throw new UsageError(
|
|
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
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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}
|
|
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}
|
|
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
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
1772
|
+
params: System_TableSchema.TableFactoryOptionsBase<SchemaFactoryBeta<TScope>, TCell> & {
|
|
1711
1773
|
readonly column: TColumn;
|
|
1712
1774
|
readonly row: TRow;
|
|
1713
1775
|
},
|
package/src/treeFactory.ts
CHANGED
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|