-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
111 lines (99 loc) · 3.6 KB
/
index.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import Aggregate from './lib/Aggregate.js'
import AlternativePath from './lib/AlternativePath.js'
import Bind from './lib/Bind.js'
import CompareFilter from './lib/CompareFilter.js'
import Construct from './lib/Construct.js'
import Delete from './lib/Delete.js'
import DeleteData from './lib/DeleteData.js'
import Describe from './lib/Describe.js'
import Filters from './lib/Filters.js'
import Func from './lib/Func.js'
import Graph from './lib/Graph.js'
import InFilter from './lib/InFilter.js'
import Insert from './lib/Insert.js'
import InsertData from './lib/InsertData.js'
import InversePath from './lib/InversePath.js'
import NegatedPropertySet from './lib/NegatedPropertySet.js'
import Optional from './lib/Optional.js'
import Path from './lib/Path.js'
import QuantityPath from './lib/QuantityPath.js'
import Select from './lib/Select.js'
import SubQuery from './lib/SubQuery.js'
import Union from './lib/Union.js'
import smartAddPatterns from './lib/utils/smartAddPatterns.js'
const eq = (a, b) => new CompareFilter('=', a, b)
const ne = (a, b) => new CompareFilter('!=', a, b)
const lt = (a, b) => new CompareFilter('<', a, b)
const gt = (a, b) => new CompareFilter('>', a, b)
const lte = (a, b) => new CompareFilter('<=', a, b)
const gte = (a, b) => new CompareFilter('>=', a, b)
const inFilter = (variable, values) => new InFilter(variable, values)
const count = (variable, as) => new Aggregate('COUNT', variable, as)
const sum = (variable, as) => new Aggregate('SUM', variable, as)
const min = (variable, as) => new Aggregate('MIN', variable, as)
const max = (variable, as) => new Aggregate('MAX', variable, as)
const avg = (variable, as) => new Aggregate('AVG', variable, as)
const coalesce = (...args) => new Func('COALESCE', args)
const day = term => new Func('DAY', [term])
const lang = term => new Func('LANG', [term])
const langMatches = (tag, range) => new Func('LANGMATCHES', [tag, range])
const month = term => new Func('MONTH', [term])
const year = term => new Func('YEAR', [term])
const construct = (patterns, options) => new Construct(patterns, options)
const deleteQuery = (patterns, options) => new Delete(patterns, options)
const deleteData = (patterns, options) => new DeleteData(patterns, options)
const describe = (variables, options) => new Describe(variables, options)
const insert = (patterns, options) => new Insert(patterns, options)
const insertData = (patterns, options) => new InsertData(patterns, options)
const select = (variables, options) => new Select(variables, options)
const bind = (variable, content) => new Bind(variable, content)
const filter = filters => new Filters(filters)
const graph = (graph, children) => smartAddPatterns(new Graph(graph), children)
const optional = patterns => smartAddPatterns(new Optional(), patterns)
const union = queries => new Union(queries.map(query => smartAddPatterns(new SubQuery(), query)))
const alternative = elements => new AlternativePath(elements)
const inverse = element => new InversePath(element)
const negated = element => new NegatedPropertySet(element)
const oneOrMore = element => new QuantityPath('+', element)
const sequence = elements => new Path(elements)
const zeroOrMore = element => new QuantityPath('*', element)
const zeroOrOne = element => new QuantityPath('?', element)
export {
eq,
ne,
lt,
gt,
lte,
gte,
inFilter as in,
count,
sum,
min,
max,
avg,
coalesce,
day,
lang,
langMatches,
month,
year,
construct,
deleteQuery as delete,
deleteData,
describe,
insert,
insertData,
select,
bind,
filter,
graph,
optional,
union,
alternative,
inverse,
negated,
oneOrMore,
sequence,
zeroOrMore,
zeroOrOne
}