@@ -152,26 +152,32 @@ export class FieldSchema<out Kind extends FieldKind = FieldKind, out Types exten
152
152
readonly allowedTypes: Types ;
153
153
get allowedTypeSet(): ReadonlySet <TreeNodeSchema >;
154
154
readonly kind: Kind ;
155
- get metadata(): FieldSchemaMetadata <TCustomMetadata > | undefined ;
155
+ get metadata(): FieldSchemaMetadata <TCustomMetadata >;
156
156
readonly props? : FieldProps <TCustomMetadata > | undefined ;
157
157
readonly requiresValue: boolean ;
158
158
protected _typeCheck: MakeNominal ;
159
159
}
160
160
161
161
// @alpha @sealed
162
162
export class FieldSchemaAlpha <Kind extends FieldKind = FieldKind , Types extends ImplicitAllowedTypes = ImplicitAllowedTypes , TCustomMetadata = unknown > extends FieldSchema <Kind , Types , TCustomMetadata > implements SimpleFieldSchema {
163
+ protected constructor (kind : Kind , allowedTypes : Types , props ? : FieldProps <TCustomMetadata >);
163
164
// (undocumented)
164
165
get allowedTypesIdentifiers(): ReadonlySet <string >;
165
166
}
166
167
168
+ // @alpha @sealed
169
+ export interface FieldSchemaAlphaUnsafe <out Kind extends FieldKind , out Types extends ImplicitAllowedTypesUnsafe , out TCustomMetadata = unknown > extends FieldSchemaAlpha <Kind , any , TCustomMetadata >, FieldSchemaUnsafe <Kind , Types , TCustomMetadata > {
170
+ readonly allowedTypes: Types ;
171
+ }
172
+
167
173
// @public @sealed
168
174
export interface FieldSchemaMetadata <TCustomMetadata = unknown > {
169
175
readonly custom? : TCustomMetadata ;
170
176
readonly description? : string | undefined ;
171
177
}
172
178
173
179
// @public
174
- export interface FieldSchemaUnsafe <out Kind extends FieldKind , out Types extends ImplicitAllowedTypesUnsafe > extends FieldSchema <Kind , any > {
180
+ export interface FieldSchemaUnsafe <out Kind extends FieldKind , out Types extends ImplicitAllowedTypesUnsafe , out TCustomMetadata = unknown > extends FieldSchema <Kind , any , TCustomMetadata > {
175
181
readonly allowedTypes: Types ;
176
182
readonly allowedTypeSet: ReadonlySet <TreeNodeSchema >;
177
183
readonly kind: Kind ;
@@ -272,7 +278,9 @@ TSchema
272
278
] extends [ImplicitFieldSchema ] ? InsertableTreeFieldFromImplicitField <TSchema > : [TSchema ] extends [UnsafeUnknownSchema ] ? InsertableContent | undefined : never ;
273
279
274
280
// @public
275
- type InsertableObjectFromSchemaRecord <T extends RestrictiveStringRecord <ImplicitFieldSchema >> = Record <string , never > extends T ? Record <string , never > : FlattenKeys <{
281
+ type InsertableObjectFromSchemaRecord <T extends RestrictiveStringRecord <ImplicitFieldSchema >> = RestrictiveStringRecord <ImplicitFieldSchema > extends T ? {
282
+ arbitraryKey: " arbitraryValue" ;
283
+ } extends T ? Record <string , never > : never : FlattenKeys <{
276
284
readonly [Property in keyof T ]? : InsertableTreeFieldFromImplicitField <T [Property & string ]>;
277
285
} & {
278
286
readonly [Property in keyof T as FieldHasDefault <T [Property & string ]> extends false ? Property : never ]: InsertableTreeFieldFromImplicitField <T [Property & string ]>;
@@ -554,7 +562,7 @@ export interface NodeSchemaOptions<out TCustomMetadata = unknown> {
554
562
export const noopValidator: JsonValidator ;
555
563
556
564
// @public
557
- type ObjectFromSchemaRecord <T extends RestrictiveStringRecord <ImplicitFieldSchema >> = {
565
+ type ObjectFromSchemaRecord <T extends RestrictiveStringRecord <ImplicitFieldSchema >> = RestrictiveStringRecord < ImplicitFieldSchema > extends T ? {} : {
558
566
- readonly [Property in keyof T ]: Property extends string ? TreeFieldFromImplicitField <T [Property ]> : unknown ;
559
567
};
560
568
@@ -563,6 +571,16 @@ type ObjectFromSchemaRecordUnsafe<T extends Unenforced<RestrictiveStringRecord<I
563
571
- readonly [Property in keyof T ]: TreeFieldFromImplicitFieldUnsafe <T [Property ]>;
564
572
};
565
573
574
+ // @alpha @sealed
575
+ export interface ObjectNodeSchema <out TName extends string = string , in out T extends RestrictiveStringRecord <ImplicitFieldSchema > = RestrictiveStringRecord <ImplicitFieldSchema >, ImplicitlyConstructable extends boolean = boolean , out TCustomMetadata = unknown > extends TreeNodeSchemaClass <TName , NodeKind .Object , TreeObjectNode <T , TName >, InsertableObjectFromSchemaRecord <T >, ImplicitlyConstructable , T , never , TCustomMetadata >, SimpleObjectNodeSchema <TCustomMetadata > {
576
+ readonly fields: ReadonlyMap <string , FieldSchemaAlpha & SimpleObjectFieldSchema >;
577
+ }
578
+
579
+ // @alpha (undocumented)
580
+ export const ObjectNodeSchema: {
581
+ readonly [Symbol .hasInstance ]: (value : TreeNodeSchema ) => value is ObjectNodeSchema <string , RestrictiveStringRecord <ImplicitFieldSchema >, boolean , unknown >;
582
+ };
583
+
566
584
// @public @deprecated
567
585
export type Off = Off_2 ;
568
586
@@ -715,12 +733,12 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde
715
733
objectRecursive<const Name extends TName , const T extends RestrictiveStringRecord <Unenforced <ImplicitFieldSchema >>>(name : Name , t : T ): TreeNodeSchemaClass <ScopedSchemaName <TScope , Name >, NodeKind .Object , TreeObjectNodeUnsafe <T , ScopedSchemaName <TScope , Name >>, object & InsertableObjectFromSchemaRecordUnsafe <T >, false , T >;
716
734
readonly optional: <const T extends ImplicitAllowedTypes , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchema <FieldKind .Optional , T , TCustomMetadata >;
717
735
static readonly optional: <const T extends ImplicitAllowedTypes , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchema <FieldKind .Optional , T , TCustomMetadata >;
718
- readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe >(t : T , props ? : Omit <FieldProps <unknown >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Optional , T >;
719
- static readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe >(t : T , props ? : Omit <FieldProps <unknown >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Optional , T >;
736
+ readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Optional , T , TCustomMetadata >;
737
+ static readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Optional , T , TCustomMetadata >;
720
738
readonly required: <const T extends ImplicitAllowedTypes , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchema <FieldKind .Required , T , TCustomMetadata >;
721
739
static readonly required: <const T extends ImplicitAllowedTypes , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchema <FieldKind .Required , T , TCustomMetadata >;
722
- readonly requiredRecursive: <const T extends ImplicitAllowedTypesUnsafe >(t : T , props ? : Omit <FieldProps <unknown >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Required , T >;
723
- static readonly requiredRecursive: <const T extends ImplicitAllowedTypesUnsafe >(t : T , props ? : Omit <FieldProps <unknown >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Required , T >;
740
+ readonly requiredRecursive: <const T extends ImplicitAllowedTypesUnsafe , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Required , T , TCustomMetadata >;
741
+ static readonly requiredRecursive: <const T extends ImplicitAllowedTypesUnsafe , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Required , T , TCustomMetadata >;
724
742
readonly scope: TScope ;
725
743
readonly string: LeafSchema_2 <" string" , string >;
726
744
static readonly string: LeafSchema_2 <" string" , string >;
@@ -741,8 +759,9 @@ export class SchemaFactoryAlpha<out TScope extends string | undefined = string |
741
759
} | {
742
760
readonly [x : string ]: InsertableTreeNodeFromImplicitAllowedTypesUnsafe <T >;
743
761
}, false , T , undefined , TCustomMetadata >;
744
- object<const Name extends TName , const T extends RestrictiveStringRecord <ImplicitFieldSchema >, const TCustomMetadata = unknown >(name : Name , fields : T , options ? : SchemaFactoryObjectOptions <TCustomMetadata >): TreeNodeSchemaClass <ScopedSchemaName <TScope , Name >, NodeKind .Object , TreeObjectNode <T , ScopedSchemaName <TScope , Name >>, object & InsertableObjectFromSchemaRecord <T >, true , T , never , TCustomMetadata >;
745
- objectRecursive<const Name extends TName , const T extends Unenforced <RestrictiveStringRecord <ImplicitFieldSchema >>, const TCustomMetadata = unknown >(name : Name , t : T , options ? : SchemaFactoryObjectOptions <TCustomMetadata >): TreeNodeSchemaClass <ScopedSchemaName <TScope , Name >, NodeKind .Object , TreeObjectNodeUnsafe <T , ScopedSchemaName <TScope , Name >>, object & InsertableObjectFromSchemaRecordUnsafe <T >, false , T , never , TCustomMetadata >;
762
+ object<const Name extends TName , const T extends RestrictiveStringRecord <ImplicitFieldSchema >, const TCustomMetadata = unknown >(name : Name , fields : T , options ? : SchemaFactoryObjectOptions <TCustomMetadata >): ObjectNodeSchema <ScopedSchemaName <TScope , Name >, T , true , TCustomMetadata >;
763
+ objectRecursive<const Name extends TName , const T extends Unenforced <RestrictiveStringRecord <ImplicitFieldSchema >>, const TCustomMetadata = unknown >(name : Name , t : T , options ? : SchemaFactoryObjectOptions <TCustomMetadata >): TreeNodeSchemaClass <ScopedSchemaName <TScope , Name >, NodeKind .Object , TreeObjectNodeUnsafe <T , ScopedSchemaName <TScope , Name >>, object & InsertableObjectFromSchemaRecordUnsafe <T >, false , T , never , TCustomMetadata > & SimpleObjectNodeSchema <TCustomMetadata > & Pick <ObjectNodeSchema , " fields" >;
764
+ readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" >) => FieldSchemaAlphaUnsafe <FieldKind .Optional , T , TCustomMetadata >;
746
765
scopedFactory<const T extends TName , TNameInner extends number | string = string >(name : T ): SchemaFactoryAlpha <ScopedSchemaName <TScope , T >, TNameInner >;
747
766
}
748
767
@@ -761,8 +780,8 @@ export const schemaStatics: {
761
780
readonly leaves: readonly [LeafSchema_2 <" string" , string >, LeafSchema_2 <" number" , number >, LeafSchema_2 <" boolean" , boolean >, LeafSchema_2 <" null" , null >, LeafSchema_2 <" handle" , IFluidHandle <unknown >>];
762
781
readonly optional: <const T extends ImplicitAllowedTypes , const TCustomMetadata = unknown >(t : T , props ? : Omit <FieldProps <TCustomMetadata >, " defaultProvider" >) => FieldSchema <FieldKind .Optional , T , TCustomMetadata >;
763
782
readonly required: <const T_1 extends ImplicitAllowedTypes , const TCustomMetadata_1 = unknown >(t : T_1 , props ? : Omit <FieldProps <TCustomMetadata_1 >, " defaultProvider" > | undefined ) => FieldSchema <FieldKind .Required , T_1 , TCustomMetadata_1 >;
764
- readonly optionalRecursive: <const T_2 extends ImplicitAllowedTypesUnsafe >(t : T_2 , props ? : Omit <FieldProps , " defaultProvider" >) => FieldSchemaUnsafe <FieldKind .Optional , T_2 >;
765
- readonly requiredRecursive: <const T_3 extends ImplicitAllowedTypesUnsafe >(t : T_3 , props ? : Omit <FieldProps , " defaultProvider" >) => FieldSchemaUnsafe <FieldKind .Required , T_3 >;
783
+ readonly optionalRecursive: <const T_2 extends ImplicitAllowedTypesUnsafe , const TCustomMetadata_2 = unknown >(t : T_2 , props ? : Omit <FieldProps < TCustomMetadata_2 > , " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Optional , T_2 , TCustomMetadata_2 >;
784
+ readonly requiredRecursive: <const T_3 extends ImplicitAllowedTypesUnsafe , const TCustomMetadata_3 = unknown >(t : T_3 , props ? : Omit <FieldProps < TCustomMetadata_3 > , " defaultProvider" > | undefined ) => FieldSchemaUnsafe <FieldKind .Required , T_3 , TCustomMetadata_3 >;
766
785
};
767
786
768
787
// @alpha
@@ -796,7 +815,23 @@ export type SharedTreeOptions = Partial<ICodecOptions> & Partial<SharedTreeForma
796
815
export interface SimpleFieldSchema {
797
816
readonly allowedTypesIdentifiers: ReadonlySet <string >;
798
817
readonly kind: FieldKind ;
799
- readonly metadata? : FieldSchemaMetadata | undefined ;
818
+ readonly metadata: FieldSchemaMetadata ;
819
+ }
820
+
821
+ // @public @sealed
822
+ export interface SimpleNodeSchemaBase <out TNodeKind extends NodeKind , out TCustomMetadata = unknown > {
823
+ readonly kind: TNodeKind ;
824
+ readonly metadata: NodeSchemaMetadata <TCustomMetadata >;
825
+ }
826
+
827
+ // @alpha @sealed
828
+ export interface SimpleObjectFieldSchema extends SimpleFieldSchema {
829
+ readonly storedKey: string ;
830
+ }
831
+
832
+ // @alpha @sealed
833
+ export interface SimpleObjectNodeSchema <out TCustomMetadata = unknown > extends SimpleNodeSchemaBase <NodeKind .Object , TCustomMetadata > {
834
+ readonly fields: ReadonlyMap <string , SimpleObjectFieldSchema >;
800
835
}
801
836
802
837
// @alpha
@@ -1020,16 +1055,13 @@ export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind ext
1020
1055
}
1021
1056
1022
1057
// @public @sealed
1023
- export interface TreeNodeSchemaCore <out Name extends string , out Kind extends NodeKind , out ImplicitlyConstructable extends boolean , out Info = unknown , out TInsertable = never , out TCustomMetadata = unknown > {
1058
+ export interface TreeNodeSchemaCore <out Name extends string , out Kind extends NodeKind , out ImplicitlyConstructable extends boolean , out Info = unknown , out TInsertable = never , out TCustomMetadata = unknown > extends SimpleNodeSchemaBase < Kind , TCustomMetadata > {
1024
1059
readonly childTypes: ReadonlySet <TreeNodeSchema >;
1025
1060
// @sealed
1026
1061
createFromInsertable(data : TInsertable ): Unhydrated <TreeNode | TreeLeafValue >;
1027
1062
readonly identifier: Name ;
1028
1063
readonly implicitlyConstructable: ImplicitlyConstructable ;
1029
1064
readonly info: Info ;
1030
- // (undocumented)
1031
- readonly kind: Kind ;
1032
- readonly metadata? : NodeSchemaMetadata <TCustomMetadata > | undefined ;
1033
1065
}
1034
1066
1035
1067
// @public @sealed
@@ -1052,7 +1084,7 @@ type TreeNodeSchemaUnsafe<Name extends string = string, Kind extends NodeKind =
1052
1084
export type TreeObjectNode <T extends RestrictiveStringRecord <ImplicitFieldSchema >, TypeName extends string = string > = TreeNode & ObjectFromSchemaRecord <T > & WithType <TypeName , NodeKind .Object , T >;
1053
1085
1054
1086
// @public
1055
- export type TreeObjectNodeUnsafe <T extends Unenforced <RestrictiveStringRecord <ImplicitFieldSchema >>, TypeName extends string = string > = TreeNode & ObjectFromSchemaRecordUnsafe <T > & WithType <TypeName , NodeKind .Object >;
1087
+ export type TreeObjectNodeUnsafe <T extends Unenforced <RestrictiveStringRecord <ImplicitFieldSchema >>, TypeName extends string = string > = TreeNode & ObjectFromSchemaRecordUnsafe <T > & WithType <TypeName , NodeKind .Object , T >;
1056
1088
1057
1089
// @public
1058
1090
export enum TreeStatus {
0 commit comments