-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconst-utils.ts
41 lines (35 loc) · 1.15 KB
/
const-utils.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
import * as Option from 'fp-ts/lib/Option'
import { pipe } from 'fp-ts/lib/function'
import { operators, builtinFunctions } from './constants'
import { Operator, SqlFunction, NullSafety } from './types'
export function findOperator(name: string): Option.Option<Operator> {
const upCaseName = name.toUpperCase()
return Option.fromNullable(operators.find((op) => op.op === upCaseName))
}
export function isOperatorCommutative(name: string): boolean {
return pipe(
findOperator(name),
Option.map((op) => op.commutative || false),
Option.getOrElse<boolean>(() => false)
)
}
export function operatorNullSafety(name: string): NullSafety | null {
return pipe(
findOperator(name),
Option.map((op) => op.nullSafety),
Option.toNullable
)
}
export function findBuiltinFunction(name: string): Option.Option<SqlFunction> {
const downCaseName = name.toLowerCase()
return Option.fromNullable(
builtinFunctions.find((f) => f.name === downCaseName)
)
}
export function builtinFunctionNullSafety(name: string): NullSafety | null {
return pipe(
findBuiltinFunction(name),
Option.map((func) => func.nullSafety),
Option.toNullable
)
}