-
Notifications
You must be signed in to change notification settings - Fork 279
/
having-node.ts
43 lines (38 loc) · 1.03 KB
/
having-node.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
import { freeze } from '../util/object-utils.js'
import { AndNode } from './and-node.js'
import { FilterNode } from './filter-node.js'
import { OperationNode } from './operation-node.js'
import { OrNode } from './or-node.js'
import { ParensNode } from './parens-node.js'
export type HavingNodeChild = FilterNode | AndNode | OrNode | ParensNode
export interface HavingNode extends OperationNode {
readonly kind: 'HavingNode'
readonly having: HavingNodeChild
}
/**
* @internal
*/
export const HavingNode = freeze({
is(node: OperationNode): node is HavingNode {
return node.kind === 'HavingNode'
},
create(filter: HavingNodeChild): HavingNode {
return freeze({
kind: 'HavingNode',
having: filter,
})
},
cloneWithFilter(
havingNode: HavingNode,
op: 'And' | 'Or',
having: HavingNodeChild
): HavingNode {
return freeze({
...havingNode,
having:
op === 'And'
? AndNode.create(havingNode.having, having)
: OrNode.create(havingNode.having, having),
})
},
})