-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ts
117 lines (102 loc) · 2.74 KB
/
helpers.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
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
112
113
114
115
const createOperation = (operator: string) => (...args: Array<any>) => {
return {
"type": "operation",
"operator": operator,
"args": args
}
}
export const isiri = createOperation('isIri')
export const negate = createOperation('!')
export const isliteral = createOperation('isLiteral')
export const notEquals = createOperation('!=')
export const equals = createOperation('=')
export const datatype = createOperation('datatype')
export const lang = createOperation('lang')
export const and = createOperation('&&')
export const or = createOperation('||')
export const inOperator = createOperation('in')
export const optional = (inner: any) => {
return {
"type": "optional",
"patterns": Array.isArray(inner) ? inner : [inner]
}
}
export const bgp = (inner: any) => {
return {
"type": "bgp",
"triples": Array.isArray(inner) ? inner : [inner]
}
}
export const union = (inner: any) => {
return {
"type": "union",
"patterns": Array.isArray(inner) ? inner : [inner],
}
}
export const filterIn = (...args: Array<any>) => {
return {
"type": "filter",
"expression": inOperator(...args)
}
}
export const filterOr = (...args: Array<any>) => {
return {
"type": "filter",
"expression": or(...args)
}
}
export const filterIs = (...args: Array<any>) => {
return {
"type": "filter",
"expression": equals(...args)
}
}
export const filter = (...args: Array<any>) => {
return {
"type": "filter",
"expression": {
"type": "operation",
"args": args
}
}
}
export const bind = (variable: any, expression: any) => {
return {
"type": "bind",
"variable": variable,
"expression": expression
}
}
export const group = (inner: any) => {
return {
type: "group",
patterns: Array.isArray(inner) ? inner : [inner]
}
}
export const values = (variableName: string, inner: any) => {
return {
"type": "values",
"values": (Array.isArray(inner) ? inner : [inner]).map(item => ({
[`?${variableName}`]: item
}))
}
}
export const constructQuery = ({ template, where, prefixes }: { template: any, where: any, prefixes: any }) => {
return {
"queryType": "CONSTRUCT",
"template": template,
"where": where,
"type": "query",
"prefixes": prefixes
}
}
export const selectQuery = ({ variables, where, limit, offset }: { variables: any, where: any, limit: any, offset: any }) => {
return {
"queryType": "SELECT",
"type": "query",
"where": where,
"variables": variables,
"limit": limit,
"offset": offset,
}
}