UNPKG

5.98 kBTypeScriptView Raw
1import BigNumber from 'bignumber.js';
2import moment from 'moment';
3import { EdmTypeShared } from '../edm-types';
4import { Entity } from '../entity';
5import { Filter } from '../filter';
6import { Time } from '../time';
7import { ConstructorOrField } from './constructor-or-field';
8import { Field, FieldOptions, FieldType } from './field';
9/**
10 * Convenience type that maps the given [[FieldType]] to a new type that is either nullable or not, depending on the given `NullableT`.
11 * @typeparam FieldT - Field type of the field.
12 * @typeparam NullableT - Boolean type that represents whether the field is nullable.
13 */
14declare type NullableFieldType<FieldT extends FieldType, NullableT extends boolean> = NullableT extends true ? FieldT | null : FieldT;
15/**
16 * Convenience type that maps the given EDM type to a [[FieldType]] without considering whether it is nullable.
17 * @typeparam EdmOrFieldT - EDM type of the field. Deprecated: Field type of the field.
18 * @typeparam NullableT - Boolean type that represents whether the field is nullable.
19 */
20declare type NonNullableFieldTypeByEdmType<EdmOrFieldT extends EdmTypeShared<'any'> | FieldType> = EdmOrFieldT extends 'Edm.String' ? string : EdmOrFieldT extends 'Edm.Boolean' ? boolean : EdmOrFieldT extends 'Edm.Decimal' ? BigNumber : EdmOrFieldT extends 'Edm.Double' ? number : EdmOrFieldT extends 'Edm.Single' ? number : EdmOrFieldT extends 'Edm.Float' ? number : EdmOrFieldT extends 'Edm.Int16' ? number : EdmOrFieldT extends 'Edm.Int32' ? number : EdmOrFieldT extends 'Edm.Int64' ? BigNumber : EdmOrFieldT extends 'Edm.SByte' ? number : EdmOrFieldT extends 'Edm.Binary' ? string : EdmOrFieldT extends 'Edm.Guid' ? string : EdmOrFieldT extends 'Edm.Byte' ? number : EdmOrFieldT extends 'Edm.DateTime' ? moment.Moment : EdmOrFieldT extends 'Edm.DateTimeOffset' ? moment.Moment : EdmOrFieldT extends 'Edm.Time' ? Time : EdmOrFieldT extends 'Edm.Date' ? moment.Moment : EdmOrFieldT extends 'Edm.Duration' ? moment.Duration : EdmOrFieldT extends 'Edm.TimeOfDay' ? Time : EdmOrFieldT extends 'Edm.Enum' ? string : EdmOrFieldT extends 'Edm.Any' ? any : EdmOrFieldT extends FieldType ? EdmOrFieldT : never;
21/**
22 * Convenience type that maps the given EDM type to a [[FieldType]]. It also considers whether the field is nullable.
23 * @typeparam EdmOrFieldT - EDM type of the field. Deprecated: Field type of the field.
24 * @typeparam NullableT - Boolean type that represents whether the field is nullable.
25 */
26export declare type FieldTypeByEdmType<EdmOrFieldT extends EdmTypeShared<'any'> | FieldType, NullableT extends boolean> = NullableFieldType<EdmOrFieldT extends EdmTypeShared<'any'> ? NonNullableFieldTypeByEdmType<EdmOrFieldT> : EdmOrFieldT, NullableT>;
27/**
28 * Convenience type to support legacy `EdmTypeField` with field type as generic parameter.
29 * This will become obsolete in the next major version update.
30 */
31export declare type EdmTypeForEdmOrFieldType<EdmOrFieldT extends EdmTypeShared<'any'> | FieldType> = EdmOrFieldT extends EdmTypeShared<'any'> ? EdmOrFieldT : EdmTypeShared<'any'>;
32/**
33 * Represents a property of an OData entity with an EDM type.
34 *
35 * `EdmTypeField`s are used as static properties of entities or EDM typed fields of complex type fields. They are generated from the OData metadata, i.e. for each property of
36 * an OData entity, that has an EDM type, there is one static instance of `EdmTypeField` (or rather one of its subclasses) in the corresponding generated class file.
37 * `EdmTypeField`s are used to represent the domain of more or less primitive values that can be used in select, filter and order by functions.
38 * For example, when constructing a query on the BusinessPartner entity, an instance of `EdmTypeField<BusinessPartner, string>`
39 * can be supplied as argument to the select function, e.g. `BusinessPartner.FIRST_NAME`.
40 *
41 * See also: [[Selectable]]
42 * @typeparam EntityT - Type of the entity the field belongs to
43 * @typeparam EdmOrFieldT - EDM type of the field. Deprecated: Field type of the field.
44 * @typeparam NullableT - Boolean type that represents whether the field is nullable.
45 * @typeparam SelectableT - Boolean type that represents whether the field is selectable.
46 */
47export declare class EdmTypeField<EntityT extends Entity, EdmOrFieldT extends EdmTypeShared<'any'> | FieldType, NullableT extends boolean = false, SelectableT extends boolean = false> extends Field<EntityT, NullableT, SelectableT> {
48 readonly _fieldOf: ConstructorOrField<EntityT>;
49 readonly edmType: EdmTypeForEdmOrFieldType<EdmOrFieldT>;
50 /**
51 * Creates an instance of EdmTypeField.
52 * @param fieldName - Actual name of the field used in the OData request.
53 * @param _fieldOf - Constructor type of the entity the field belongs to.
54 * @param edmType - Type of the field according to the metadata description.
55 * @param fieldOptions - Optional settings for this field.
56 */
57 constructor(fieldName: string, _fieldOf: ConstructorOrField<EntityT>, edmType: EdmTypeForEdmOrFieldType<EdmOrFieldT>, fieldOptions?: FieldOptions<NullableT, SelectableT>);
58 /**
59 * Creates an instance of Filter for this field and the given value using the operator 'eq', i.e. `==`.
60 * @param value - Value to be used in the filter
61 * @returns The resulting filter
62 */
63 equals(value: FieldTypeByEdmType<EdmOrFieldT, NullableT>): Filter<EntityT, FieldTypeByEdmType<EdmOrFieldT, NullableT>>;
64 /**
65 * Creates an instance of Filter for this field and the given value using the operator 'ne', i.e. `!=`.
66 * @param value - Value to be used in the filter
67 * @returns The resulting filter
68 */
69 notEquals(value: FieldTypeByEdmType<EdmOrFieldT, NullableT>): Filter<EntityT, FieldTypeByEdmType<EdmOrFieldT, NullableT>>;
70 /**
71 * Path to the field to be used in filter and order by queries.
72 * @returns Path to the field to be used in filter and order by queries.
73 */
74 fieldPath(): string;
75}
76export {};
77//# sourceMappingURL=edm-type-field.d.ts.map
\No newline at end of file