-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathone-to-one-link.ts
80 lines (74 loc) · 2.67 KB
/
one-to-one-link.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
import { EntityBase } from '../entity';
import { Filterable, FilterLink } from '../filter';
import { Order, Orderable, OrderLink } from '../order';
import { Link } from './link';
/**
* Represents a link from one entity to one other linked entity (as opposed to a list of linked entities). In OData v2 a `OneToOneLink` can be used to filter and order a selection on an entity based on filters and orders on a linked entity.
*
* @typeparam EntityT - Type of the entity to be linked from
* @typeparam LinkedEntityT - Type of the entity to be linked to
*/
export class OneToOneLink<
EntityT extends EntityBase,
LinkedEntityT extends EntityBase
> extends Link<EntityT, LinkedEntityT> {
/**
* @deprecated Since v1.21.0. Use [[clone]] instead.
* Create a new one to one link based on a given link.
*
* @typeparam EntityT - Type of the entity to be linked from
* @typeparam LinkedEntityT - Type of the entity to be linked to
* @param link - Link to be cloned
* @returns Newly created link
*/
static clone<EntityT1 extends EntityBase, LinkedEntityT1 extends EntityBase>(
link: OneToOneLink<EntityT1, LinkedEntityT1>
): OneToOneLink<EntityT1, LinkedEntityT1> {
const clonedLink = link.clone() as OneToOneLink<EntityT1, LinkedEntityT1>;
clonedLink.orderBys = link.orderBys;
clonedLink.filters = link.filters;
return clonedLink;
}
/**
* List of criteria of the linked entity to order the given entity by with descending priority.
*/
orderBys: Order<LinkedEntityT>[] = [];
/**
* Filterables to apply to the given entity based on the linked entity.
*/
filters: Filterable<LinkedEntityT>;
clone(): this {
const clonedLink = super.clone();
clonedLink.filters = this.filters;
clonedLink.orderBys = this.orderBys;
return clonedLink;
}
/**
* Create order statements for the OData request based on the linked entity. The given statements have descending priority.
*
* Example:
* ```
* Entity.requestBuilder()
* .getAll()
* .orderBy(Entity.TO_LINKED_ENTITY.orderBy(asc(LinkedEntity.PROPERTY1), desc(LinkedEntity.PROPERTY2)));
* ```
* @param orderBy - Criteria to order by
* @returns Newly created order link
*/
orderBy(
...orderBy: Orderable<LinkedEntityT>[]
): OrderLink<EntityT, LinkedEntityT> {
return new OrderLink(this, orderBy);
}
/**
* Create filter statements to be applied to the OData request based on the linked entity values.
*
* @param filters - Filters based on the linked entity
* @returns Newly created Filterlink
*/
filter(
...filters: Filterable<LinkedEntityT>[]
): FilterLink<EntityT, LinkedEntityT> {
return new FilterLink(this, filters);
}
}