-
Notifications
You must be signed in to change notification settings - Fork 45
/
any-field.ts
84 lines (77 loc) · 2.6 KB
/
any-field.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* eslint-disable max-classes-per-file */
import { EdmTypeShared } from '../edm-types';
import { EntityBase, ODataVersionOf } from '../entity';
import {
ComplexTypeField,
getEdmType,
getEntityConstructor
} from './complex-type-field';
import { ConstructorOrField } from './constructor-or-field';
import { EdmTypeField, SelectableEdmTypeField } from './edm-type-field';
/**
* Represents a property with an unknown or currently unsupported edm type like Edm.Geography.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
class AnyFieldBase<EntityT extends EntityBase> extends EdmTypeField<
EntityT,
any
> {}
/**
* Represents a selectable property with with an unknown or currently unsupported edm type like Edm.Geography.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
export class AnyField<EntityT extends EntityBase>
extends AnyFieldBase<EntityT>
implements SelectableEdmTypeField {
readonly selectable: true;
}
/**
* Represents a complex type property with with an unknown or currently unsupported edm type like Edm.Geography.
*
* @typeparam EntityT - Type of the entity the field belongs to
*/
export class ComplexTypeAnyPropertyField<
EntityT extends EntityBase,
ComplexT = any
> extends AnyFieldBase<EntityT> {
/**
* The constructor of the entity or the complex type this field belongs to
*/
readonly fieldOf: ConstructorOrField<EntityT, ComplexT>;
/**
* Creates an instance of ComplexTypeAnyPropertyField.
*
* @param fieldName - Actual name of the field used in the OData request
* @param fieldOf - The constructor of the entity or the complex type this field belongs to
* @param edmType - Type of the field according to the metadata description
*/
constructor(
fieldName: string,
fieldOf: ConstructorOrField<EntityT, ComplexT>,
edmType: EdmTypeShared<ODataVersionOf<EntityT>>
);
/*
* Union of the two possible constructors.
*/
constructor(
fieldName: string,
fieldOf: ConstructorOrField<EntityT, ComplexT>,
arg3: string | EdmTypeShared<ODataVersionOf<EntityT>>,
arg4?: EdmTypeShared<ODataVersionOf<EntityT>>
) {
super(fieldName, getEntityConstructor(fieldOf), getEdmType(arg3, arg4));
this.fieldOf = fieldOf;
}
/**
* Path to the field to be used in filter and order by queries. Combines the parent complex type name with the field name.
*
* @returns Path to the field to be used in filter and order by queries.
*/
fieldPath(): string {
return this.fieldOf instanceof ComplexTypeField
? `${this.fieldOf.fieldPath()}/${this._fieldName}`
: this._fieldName;
}
}