import { EdmTypeShared , isOrderableEdmType , OrderableEdmType } from '../edm-types' ; import { Constructable , EntityBase } from '../entity-base' ; import { DeSerializers } from '../de-serializers' ; import { ComplexTypeField } from './complex-type-field' ; import { EdmTypeField } from './edm-type-field' ; import { OrderableEdmTypeField } from './orderable-edm-type-field' ; import { CollectionField , CollectionFieldType } from './collection-field' ; import { ConstructorOrField } from './constructor-or-field' ; import { FieldOptions } from './field' ; import { EnumField } from './enum-field' ; type ComplexTypeFieldConstructor < ComplexTypeFieldT extends ComplexTypeField < EntityT , DeSerializersT , ComplexT , NullableT , SelectableT > , EntityT extends EntityBase , DeSerializersT extends DeSerializers , ComplexT , NullableT extends boolean , SelectableT extends boolean > = new ( fieldName , fieldOf , deSerializers , fieldOptions ? ) => ComplexTypeFieldT ; typeparam internal export type IsSelectableField < FieldOfT extends ConstructorOrField < any > > = FieldOfT extends Constructable < any > ? true : false ; typeparam internal export type IsOrderableField < EdmT extends EdmTypeShared < 'any' > > = EdmT extends OrderableEdmType ? true : false ; type EntityTypeFromFieldOf < FieldOfT extends ConstructorOrField < any > > = FieldOfT extends ConstructorOrField < infer EntityT > ? EntityT : never ; typeparam typeparam internal export class FieldBuilder < FieldOfT extends ConstructorOrField < any > , DeSerializersT extends DeSerializers > { param fieldOf constructor ( public fieldOf , private deSerializers ) { } buildEdmTypeField < EdmT extends OrderableEdmType , NullableT extends boolean > ( fieldName , edmType , isNullable ) ; buildEdmTypeField < EdmT extends Exclude < EdmTypeShared < 'any' > , OrderableEdmType > , NullableT extends boolean > ( fieldName , edmType , isNullable ) ; param fieldName param edmType param isNullable returns buildEdmTypeField < EdmT extends EdmTypeShared < 'any' > , NullableT extends boolean > ( fieldName , edmType , isNullable ) { const isSelectable = ( this . fieldOf instanceof ComplexTypeField ) as IsSelectableField < FieldOfT > ; const ctor = ( isOrderableEdmType ( edmType ) ? OrderableEdmTypeField : EdmTypeField ) as typeof EdmTypeField ; return new ctor ( fieldName , this . fieldOf , edmType , this . deSerializers , { isNullable , isSelectable } ) ; } param fieldName param complexTypeFieldCtor param isNullable returns buildComplexTypeField < ComplexTypeFieldT extends ComplexTypeField < EntityTypeFromFieldOf < FieldOfT > , DeSerializersT , any , NullableT , IsSelectableField < FieldOfT > > , ComplexT , NullableT extends boolean > ( fieldName , complexTypeFieldCtor , isNullable ) { const isSelectable = ( this . fieldOf instanceof ComplexTypeField ) as IsSelectableField < FieldOfT > ; return new complexTypeFieldCtor ( fieldName , this . fieldOf , this . deSerializers , { isNullable , isSelectable } ) ; } param fieldName param collectionFieldType param isNullable returns buildCollectionField < CollectionFieldT extends EdmTypeShared < 'any' > | Record < string , any > , NullableT extends boolean > ( fieldName , collectionFieldType , isNullable ) { const isSelectable = ( this . fieldOf instanceof ComplexTypeField ) as IsSelectableField < FieldOfT > ; return new CollectionField ( fieldName , this . fieldOf , collectionFieldType , { isNullable , isSelectable } ) ; } param fieldName param enumType param isNullable returns buildEnumField < EnumT extends string , NullableT extends boolean > ( fieldName , enumType , isNullable ) { const isSelectable = ( this . fieldOf instanceof ComplexTypeField ) as IsSelectableField < FieldOfT > ; return new EnumField ( fieldName , this . fieldOf , enumType , { isNullable , isSelectable } ) ; } }