@sap-cloud-sdk/odata-common
Version:
SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.
75 lines (74 loc) • 5.63 kB
TypeScript
import { ComplexTypeField } from './complex-type-field';
import { EdmTypeField } from './edm-type-field';
import { OrderableEdmTypeField } from './orderable-edm-type-field';
import { CollectionField } from './collection-field';
import { EnumField } from './enum-field';
import type { EdmTypeShared, OrderableEdmType } from '../edm-types';
import type { Constructable, EntityBase } from '../entity-base';
import type { DeSerializers } from '../de-serializers';
import type { CollectionFieldType } from './collection-field';
import type { ConstructorOrField } from './constructor-or-field';
import type { FieldOptions } from './field';
/**
* Constructor function creating a {@link ComplexTypeField}.
*/
export 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: string, fieldOf: ConstructorOrField<EntityT>, deSerializers: DeSerializersT, fieldOptions?: FieldOptions<NullableT, SelectableT>) => ComplexTypeFieldT;
/**
* Convenience type to determine whether a field should be selectable. If the given `FieldOfT` is the type of an entity, it is selectable.
* @typeParam FieldOfT - Type of the entity or complex type field this field belongs to.
*/
export type IsSelectableField<FieldOfT extends ConstructorOrField<any>> = FieldOfT extends Constructable<any> ? true : false;
/**
* Convenience type to determine whether a field should be orderable. If the given `EdmT` is of type `OrderableEdmTypes`, it is orderable.
* @typeParam EdmT - EDM type of the field.
* @internal
*/
export type IsOrderableField<EdmT extends EdmTypeShared<'any'>> = EdmT extends OrderableEdmType ? true : false;
/**
* Helper type to extract the entity from a field so EntityTypeFromFieldOf<EdmTypeField<MyEntity>> is `MyEntity`.
*/
export type EntityTypeFromFieldOf<FieldOfT extends ConstructorOrField<any>> = FieldOfT extends ConstructorOrField<infer EntityT> ? EntityT : never;
/**
* Field builder to orchestrate the creation of the different kinds of fields.
* @typeParam FieldOfT - Type of the entity or complex type field this field belongs to.
* @typeParam DeSerializersT - Type of the (de-)serializers.
*/
export declare class FieldBuilder<FieldOfT extends ConstructorOrField<any>, DeSerializersT extends DeSerializers> {
fieldOf: FieldOfT;
private deSerializers;
/**
* Creates an instance of `FieldBuilder`.
* @param fieldOf - Entity or complex type field, for which the field builder shall create fields.
* @param deSerializers - (De-)serializers used for transformation.
*/
constructor(fieldOf: FieldOfT, deSerializers: DeSerializersT);
buildEdmTypeField<EdmT extends OrderableEdmType, NullableT extends boolean>(fieldName: string, edmType: EdmT, isNullable: NullableT, precision?: number): OrderableEdmTypeField<EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, EdmT, NullableT, IsSelectableField<FieldOfT>>;
buildEdmTypeField<EdmT extends Exclude<EdmTypeShared<'any'>, OrderableEdmType>, NullableT extends boolean>(fieldName: string, edmType: EdmT, isNullable: NullableT, precision?: number): EdmTypeField<EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, EdmT, NullableT, IsSelectableField<FieldOfT>>;
/**
* Build a field for a property with a complex type.
* Fields of entities are selectable; fields of complex types are not selectable.
* @param fieldName - Name of the field.
* @param complexTypeFieldCtor - Constructor of the complex type field.
* @param isNullable - Whether the field is nullable.
* @returns A complex type field of the given type.
*/
buildComplexTypeField<ComplexTypeFieldT extends ComplexTypeField<EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, any, NullableT, IsSelectableField<FieldOfT>>, ComplexT, NullableT extends boolean>(fieldName: string, complexTypeFieldCtor: ComplexTypeFieldConstructor<ComplexTypeFieldT, EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, ComplexT, NullableT, IsSelectableField<FieldOfT>>, isNullable: NullableT): ComplexTypeFieldT;
/**
* Build a field for a property with a collection type.
* The type of the field can either be an EDM type or a complex type.
* Fields of entities are selectable; fields of complex types are not selectable.
* @param fieldName - Name of the field.
* @param collectionFieldType - Type of the collection. Can either be an EDM type or complex type (not complex type field).
* @param isNullable - Whether the field is nullable.
* @returns A collection field with the given collection type.
*/
buildCollectionField<CollectionFieldT extends EdmTypeShared<'any'> | Record<string, any>, NullableT extends boolean>(fieldName: string, collectionFieldType: CollectionFieldType<CollectionFieldT>, isNullable: NullableT): CollectionField<EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, CollectionFieldT, NullableT, IsSelectableField<FieldOfT>>;
/**
* Build a field for a property with a enum type.
* @param fieldName - Name of the field.
* @param enumType - Enum type of this field.
* @param isNullable - Whether the field is nullable.
* @returns A collection field with the given collection type.
*/
buildEnumField<EnumT extends string, NullableT extends boolean>(fieldName: string, enumType: Record<string, EnumT>, isNullable: NullableT): EnumField<EntityTypeFromFieldOf<FieldOfT>, DeSerializersT, EnumT, NullableT, IsSelectableField<FieldOfT>>;
}