UNPKG

4.92 kBTypeScriptView Raw
1import { EdmTypeShared, OrderableEdmType } from '../edm-types';
2import { Constructable, Entity } from '../entity';
3import { ComplexTypeField } from './complex-type-field';
4import { EdmTypeField } from './edm-type-field';
5import { OrderableEdmTypeField } from './orderable-edm-type-field';
6import { CollectionField, CollectionFieldType } from './collection-field';
7import { ConstructorOrField } from './constructor-or-field';
8import { FieldOptions } from './field';
9import { EnumField } from './enum-field';
10declare type ComplexTypeFieldConstructor<ComplexTypeFieldT extends ComplexTypeField<EntityT, ComplexT, NullableT, SelectableT>, EntityT extends Entity, ComplexT, NullableT extends boolean, SelectableT extends boolean> = new (fieldName: string, fieldOf: ConstructorOrField<EntityT>, fieldOptions?: FieldOptions<NullableT, SelectableT>) => ComplexTypeFieldT;
11/**
12 * Convenience type to determine whether a field should be selectable. If the given `FieldOfT` is the type of an entity, it is selectable.
13 * @typeparam FieldOfT - Type of the entity or complex type field this field belongs to.
14 */
15export declare type IsSelectableField<FieldOfT extends ConstructorOrField<any>> = FieldOfT extends Constructable<any> ? true : false;
16/**
17 * Convenience type to determine whether a field should be orderable. If the given `EdmT` is of type `OrderableEdmTypes`, it is orderable.
18 * @typeparam EdmT - EDM type of the field.
19 */
20export declare type IsOrderableField<EdmT extends EdmTypeShared<'any'>> = EdmT extends OrderableEdmType ? true : false;
21declare type EntityTypeFromFieldOf<FieldOfT extends ConstructorOrField<any>> = FieldOfT extends ConstructorOrField<infer EntityT> ? EntityT : never;
22/**
23 * Field builder to orchestrate the creation of the different kinds of fields.
24 * @typeparam FieldOfT - Type of the entity or complex type field this field belongs to.
25 */
26export declare class FieldBuilder<FieldOfT extends ConstructorOrField<any>> {
27 fieldOf: FieldOfT;
28 /**
29 * Creates an instance of `FieldBuilder`.
30 * @param fieldOf - Entity or complex type field, for which the field builder shall create fields.
31 */
32 constructor(fieldOf: FieldOfT);
33 buildEdmTypeField<EdmT extends OrderableEdmType, NullableT extends boolean>(fieldName: string, edmType: EdmT, isNullable: NullableT): OrderableEdmTypeField<EntityTypeFromFieldOf<FieldOfT>, EdmT, NullableT, IsSelectableField<FieldOfT>>;
34 buildEdmTypeField<EdmT extends Exclude<EdmTypeShared<'any'>, OrderableEdmType>, NullableT extends boolean>(fieldName: string, edmType: EdmT, isNullable: NullableT): EdmTypeField<EntityTypeFromFieldOf<FieldOfT>, EdmT, NullableT, IsSelectableField<FieldOfT>>;
35 /**
36 * Build a field for a property with a complex type.
37 * Fields of entities are selectable; fields of complex types are not selectable.
38 * @param fieldName - Name of the field.
39 * @param complexTypeFieldCtor - Constructor of the complex type field.
40 * @param isNullable - Whether the field is nullable.
41 * @returns A complex type field of the given type.
42 */
43 buildComplexTypeField<ComplexTypeFieldT extends ComplexTypeField<EntityTypeFromFieldOf<FieldOfT>, any, NullableT, IsSelectableField<FieldOfT>>, ComplexT, NullableT extends boolean>(fieldName: string, complexTypeFieldCtor: ComplexTypeFieldConstructor<ComplexTypeFieldT, EntityTypeFromFieldOf<FieldOfT>, ComplexT, NullableT, IsSelectableField<FieldOfT>>, isNullable: NullableT): ComplexTypeFieldT;
44 /**
45 * Build a field for a property with a collection type.
46 * The type of the field can either be an EDM type or a complex type.
47 * Fields of entities are selectable; fields of complex types are not selectable.
48 * @param fieldName - Name of the field.
49 * @param collectionFieldType - Type of the collection. Can either be an EDM type or complex type (not complex type field).
50 * @param isNullable - Whether the field is nullable.
51 * @returns A collection field with the given collection type.
52 */
53 buildCollectionField<CollectionFieldT extends EdmTypeShared<'any'> | Record<string, any>, NullableT extends boolean>(fieldName: string, collectionFieldType: CollectionFieldType<CollectionFieldT>, isNullable: NullableT): CollectionField<EntityTypeFromFieldOf<FieldOfT>, CollectionFieldT, NullableT, IsSelectableField<FieldOfT>>;
54 /**
55 * Build a field for a property with a enum type.
56 * @param fieldName - Name of the field.
57 * @param enumType - Enum type of this field.
58 * @param isNullable - Whether the field is nullable.
59 * @returns A collection field with the given collection type.
60 */
61 buildEnumField<EnumT extends string, NullableT extends boolean>(fieldName: string, enumType: Record<string, EnumT>, isNullable: NullableT): EnumField<EntityTypeFromFieldOf<FieldOfT>, EnumT, NullableT, IsSelectableField<FieldOfT>>;
62}
63export {};
64//# sourceMappingURL=field-builder.d.ts.map
\No newline at end of file