telos-oql 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/oql.js +119 -105
- package/package.json +1 -1
- package/resolverUtils.js +49 -0
package/oql.js
CHANGED
|
@@ -5,6 +5,12 @@ let utils = {
|
|
|
5
5
|
context.operation = context.operation != null ? context.operation : {};
|
|
6
6
|
context.filters = context.filters != null ? context.filters : [];
|
|
7
7
|
|
|
8
|
+
context.operation.type =
|
|
9
|
+
context.operation.type != null ? context.operation.type : "read";
|
|
10
|
+
|
|
11
|
+
context.operation.data =
|
|
12
|
+
context.operation.data != null ? context.operation.data : [];
|
|
13
|
+
|
|
8
14
|
return context;
|
|
9
15
|
},
|
|
10
16
|
normalizeValue: (value) => {
|
|
@@ -25,147 +31,155 @@ module.exports = [
|
|
|
25
31
|
{
|
|
26
32
|
process: (context, args) => {
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
operation: {
|
|
39
|
-
type: "read"
|
|
40
|
-
}
|
|
41
|
-
}));
|
|
34
|
+
return context.local.operator == "access" ?
|
|
35
|
+
JSON.stringify(utils.normalizeContext({
|
|
36
|
+
access: {
|
|
37
|
+
url: utils.normalizeValue(args[0]),
|
|
38
|
+
options: args[1] != null ?
|
|
39
|
+
JSON.parse("" + args[1]) :
|
|
40
|
+
null
|
|
41
|
+
}
|
|
42
|
+
})) :
|
|
43
|
+
null;
|
|
42
44
|
},
|
|
43
45
|
tags: ["oql", "access"]
|
|
44
46
|
},
|
|
45
47
|
{
|
|
46
48
|
process: (context, args) => {
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
return context.local.operator == "append" ?
|
|
51
|
+
`(Array.isArray(${
|
|
52
|
+
args[0]
|
|
53
|
+
})?([${
|
|
54
|
+
args.slice(1).map(item => `(${item})`).join(",")
|
|
55
|
+
}].forEach(item=>{(${
|
|
56
|
+
args[0]
|
|
57
|
+
}).push(item);}):((context)=>{
|
|
58
|
+
context.operation.type="create";
|
|
59
|
+
${
|
|
60
|
+
args.slice(1).map(
|
|
61
|
+
item => `context.operation.data.push(${item});`
|
|
62
|
+
).join("")
|
|
63
|
+
}return context;})(${
|
|
64
|
+
args[0]
|
|
65
|
+
}))` :
|
|
66
|
+
null;
|
|
60
67
|
},
|
|
61
68
|
tags: ["oql", "append"]
|
|
62
69
|
},
|
|
63
70
|
{
|
|
64
71
|
process: (context, args) => {
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return JSON.stringify(data);
|
|
73
|
+
return context.local.operator == "at" ?
|
|
74
|
+
`(Array.isArray(${
|
|
75
|
+
args[0]
|
|
76
|
+
})?((${
|
|
77
|
+
args[0]
|
|
78
|
+
})${
|
|
79
|
+
args.slice(1).map(item => `[${item}]`).join("")
|
|
80
|
+
}):((context)=>{${
|
|
81
|
+
args.slice(1).map(item =>
|
|
82
|
+
`context.filters.push({type:"at",options:{value:(${
|
|
83
|
+
item
|
|
84
|
+
})}});`
|
|
85
|
+
).join("")
|
|
86
|
+
}return context;})(${
|
|
87
|
+
args[0]
|
|
88
|
+
}))` :
|
|
89
|
+
null;
|
|
85
90
|
},
|
|
86
91
|
tags: ["oql", "at"]
|
|
87
92
|
},
|
|
88
93
|
{
|
|
89
94
|
process: (context, args) => {
|
|
90
95
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
options: {
|
|
99
|
-
value: context.local.list[2]
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return JSON.stringify(data);
|
|
96
|
+
return context.local.operator == "filter" ?
|
|
97
|
+
`(((context)=>{context.filters.push(
|
|
98
|
+
{type:"filter",options:{value:(
|
|
99
|
+
${
|
|
100
|
+
JSON.stringify(context.local.list[2])
|
|
101
|
+
})}});return context;})(${args[0]}))` :
|
|
102
|
+
null;
|
|
104
103
|
},
|
|
105
104
|
tags: ["oql", "filter"]
|
|
106
105
|
},
|
|
107
106
|
{
|
|
108
107
|
process: (context, args) => {
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
return context.local.operator == "remove" ?
|
|
110
|
+
`(Array.isArray(${
|
|
111
|
+
args[0]
|
|
112
|
+
})?((${args[0]}).splice(${args[1], 1}))${
|
|
113
|
+
args.slice(1).map(item => `[${item}]`).join("")
|
|
114
|
+
}):(((context)=>{
|
|
115
|
+
context.operation.type="delete";return context;
|
|
116
|
+
})(${
|
|
117
|
+
args[0]
|
|
118
|
+
})))` :
|
|
119
|
+
null;
|
|
120
120
|
},
|
|
121
121
|
tags: ["oql", "remove"]
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
process: (context, args) => {
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
args[
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
args[0]
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
126
|
+
return context.local.operator == "set" ?
|
|
127
|
+
`((((item)=>{
|
|
128
|
+
if(item==null)return true;
|
|
129
|
+
return !(typeof item =="object"&&!Array.isArray(item));
|
|
130
|
+
})(typeof (${
|
|
131
|
+
args[0]
|
|
132
|
+
})=="undefined"?null:(${
|
|
133
|
+
args[0]
|
|
134
|
+
})))?(()=>{${
|
|
135
|
+
context.state[args[0]] != null ?
|
|
136
|
+
`${args[0]}=context.state[${args[0]}];` :
|
|
137
|
+
""
|
|
138
|
+
}(1, eval)(${
|
|
139
|
+
JSON.stringify(
|
|
140
|
+
context.state[args[0]] == null ?
|
|
141
|
+
`${
|
|
142
|
+
args[0]
|
|
143
|
+
}=${
|
|
144
|
+
args[1]
|
|
145
|
+
};` :
|
|
146
|
+
""
|
|
147
|
+
)
|
|
148
|
+
});${
|
|
149
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(args[0]) ?
|
|
150
|
+
`context.state["${
|
|
151
|
+
args[0]
|
|
152
|
+
}"]=${
|
|
153
|
+
args[0]
|
|
154
|
+
};` :
|
|
155
|
+
""
|
|
156
|
+
}})():((context)=>{
|
|
157
|
+
context.operation.type="update";
|
|
158
|
+
${
|
|
159
|
+
args.slice(1).map(
|
|
160
|
+
item => `context.operation.data.push(${item});`
|
|
161
|
+
).join("")
|
|
162
|
+
}return context;})(${
|
|
163
|
+
args[0]
|
|
164
|
+
}))\n` :
|
|
165
|
+
null;
|
|
150
166
|
},
|
|
151
167
|
tags: ["oql", "set"]
|
|
152
168
|
},
|
|
153
169
|
{
|
|
154
170
|
process: (context, args) => {
|
|
155
171
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return JSON.stringify(data);
|
|
172
|
+
return context.local.operator == "sort" ?
|
|
173
|
+
`(Array.isArray(${
|
|
174
|
+
args[0]
|
|
175
|
+
})?((${args[0]}).sort()):(((context)=>{
|
|
176
|
+
context.filters.push({type:"at",options:{value:(${
|
|
177
|
+
args[1]
|
|
178
|
+
})}});return context;
|
|
179
|
+
})(${
|
|
180
|
+
args[0]
|
|
181
|
+
})))` :
|
|
182
|
+
null;
|
|
169
183
|
},
|
|
170
184
|
tags: ["oql", "sort"]
|
|
171
185
|
},
|
package/package.json
CHANGED
package/resolverUtils.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var fusionLISP = require("fusion-lisp/fusionLISP.js");
|
|
2
|
+
|
|
3
|
+
var resolverUtils = {
|
|
4
|
+
getUser: (db, session, policies) => {
|
|
5
|
+
|
|
6
|
+
},
|
|
7
|
+
getSession: (db, username, password) => {
|
|
8
|
+
|
|
9
|
+
},
|
|
10
|
+
whitelist: [
|
|
11
|
+
// STUB - PREVENT INJECTION
|
|
12
|
+
],
|
|
13
|
+
resolve: (packet, context, options) => {
|
|
14
|
+
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
|
|
19
|
+
fusionLISP.run(
|
|
20
|
+
[
|
|
21
|
+
["use", "\"fusion-lisp\"", "\"telos-oql\""],
|
|
22
|
+
["return", ["query", fusionLISP.parse(packet)]]
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
fusionLISP.run([
|
|
26
|
+
["use", "\"fusion-lisp\"", "\"telos-oql\""],
|
|
27
|
+
["return", fusionLISP.parse(context)]
|
|
28
|
+
])
|
|
29
|
+
]
|
|
30
|
+
).then((data) => {
|
|
31
|
+
|
|
32
|
+
resolve({
|
|
33
|
+
body: JSON.stringify(data)
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
catch(error) {
|
|
39
|
+
|
|
40
|
+
resolve({
|
|
41
|
+
response: { status: 400 }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if(typeof module == "object")
|
|
49
|
+
module.exports = resolverUtils;
|