@quillsql/node 0.2.3 → 0.2.4
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/index.ts +39 -44
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -4,13 +4,13 @@ var PgError = require("pg-error");
|
|
|
4
4
|
Connection.prototype.parseE = PgError.parse;
|
|
5
5
|
Connection.prototype.parseN = PgError.parse;
|
|
6
6
|
|
|
7
|
-
const cache
|
|
7
|
+
const cache: any = {}; //set the cache
|
|
8
8
|
|
|
9
|
-
function setCache(key
|
|
9
|
+
function setCache(key: any, value: any) {
|
|
10
10
|
cache[key] = value;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function getCache(key
|
|
13
|
+
function getCache(key: any) {
|
|
14
14
|
return cache[key];
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -131,31 +131,31 @@ module.exports = ({
|
|
|
131
131
|
);
|
|
132
132
|
let dashConfig = response.data;
|
|
133
133
|
let newFilters = [];
|
|
134
|
-
|
|
135
|
-
if (dashConfig.filters.length) {
|
|
134
|
+
|
|
135
|
+
if (dashConfig.filters && dashConfig.filters.length) {
|
|
136
136
|
for (let i = 0; i < dashConfig.filters.length; i++) {
|
|
137
137
|
const queryResult = await targetPool.query(
|
|
138
138
|
dashConfig.filters[i].query
|
|
139
139
|
);
|
|
140
140
|
const { rows } = queryResult;
|
|
141
141
|
newFilters.push({ ...dashConfig.filters[i], options: rows });
|
|
142
|
-
dashConfig.filters[i].options = rows
|
|
142
|
+
dashConfig.filters[i].options = rows;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
dashConfig = { ...dashConfig, filters: newFilters };
|
|
147
147
|
|
|
148
148
|
const { fieldToRemove, newQueries } = response.data;
|
|
149
|
-
|
|
150
|
-
for (const newQuery of newQueries) {
|
|
151
|
-
const { query } = newQuery
|
|
149
|
+
|
|
150
|
+
for (const newQuery of newQueries) {
|
|
151
|
+
const { query } = newQuery;
|
|
152
152
|
const cacheKey = `config:${orgId}:${newQuery._id}`;
|
|
153
|
-
setCache(cacheKey, {fieldToRemove, query});
|
|
154
|
-
}
|
|
153
|
+
setCache(cacheKey, { fieldToRemove, query });
|
|
154
|
+
}
|
|
155
155
|
return {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
...dashConfig,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
159
|
|
|
160
160
|
if (task === "create") {
|
|
161
161
|
const response = await axios.post(
|
|
@@ -174,8 +174,7 @@ module.exports = ({
|
|
|
174
174
|
}
|
|
175
175
|
if (task === "item") {
|
|
176
176
|
try {
|
|
177
|
-
|
|
178
|
-
const {filters } = metadata;
|
|
177
|
+
const { filters } = metadata;
|
|
179
178
|
|
|
180
179
|
const resp = await axios.get(
|
|
181
180
|
"https://quill-344421.uc.r.appspot.com/selfhostitem",
|
|
@@ -189,38 +188,35 @@ module.exports = ({
|
|
|
189
188
|
},
|
|
190
189
|
}
|
|
191
190
|
);
|
|
192
|
-
let fieldToRemove
|
|
191
|
+
let fieldToRemove: any, query;
|
|
193
192
|
|
|
194
193
|
if (getCache(`config:${orgId}:${id}`) && !filters) {
|
|
195
|
-
getCache(`config:${orgId}:${id}`)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!filters && getCache(`config:${orgId}:${id}`)) {
|
|
199
|
-
({fieldToRemove, query} = getCache(`config:${orgId}:${id}`));
|
|
194
|
+
getCache(`config:${orgId}:${id}`);
|
|
200
195
|
}
|
|
201
|
-
else {
|
|
202
|
-
const response = await axios.post(
|
|
203
|
-
"https://quill-344421.uc.r.appspot.com/validate",
|
|
204
|
-
{ query: resp.data.queryString },
|
|
205
|
-
{
|
|
206
|
-
params: {
|
|
207
|
-
orgId,
|
|
208
|
-
filters
|
|
209
|
-
},
|
|
210
|
-
headers: {
|
|
211
|
-
Authorization: `Bearer ${privateKey}`,
|
|
212
|
-
},
|
|
213
|
-
}
|
|
214
|
-
);
|
|
215
|
-
({ fieldToRemove, query } = response.data);
|
|
216
196
|
|
|
217
|
-
|
|
197
|
+
if (!filters && getCache(`config:${orgId}:${id}`)) {
|
|
198
|
+
({ fieldToRemove, query } = getCache(`config:${orgId}:${id}`));
|
|
199
|
+
} else {
|
|
200
|
+
const response = await axios.post(
|
|
201
|
+
"https://quill-344421.uc.r.appspot.com/validate",
|
|
202
|
+
{ query: resp.data.queryString },
|
|
203
|
+
{
|
|
204
|
+
params: {
|
|
205
|
+
orgId,
|
|
206
|
+
filters,
|
|
207
|
+
},
|
|
208
|
+
headers: {
|
|
209
|
+
Authorization: `Bearer ${privateKey}`,
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
({ fieldToRemove, query } = response.data);
|
|
218
214
|
|
|
219
|
-
const cacheKey = `config:${orgId}:${id}`;
|
|
220
|
-
setCache(cacheKey, {fieldToRemove, query});
|
|
221
|
-
}
|
|
215
|
+
const cacheKey = `config:${orgId}:${id}`;
|
|
216
|
+
setCache(cacheKey, { fieldToRemove, query });
|
|
217
|
+
}
|
|
222
218
|
const queryResult = await targetPool.query(query);
|
|
223
|
-
|
|
219
|
+
|
|
224
220
|
return {
|
|
225
221
|
...resp.data,
|
|
226
222
|
fields: queryResult.fields.filter(
|
|
@@ -233,7 +229,6 @@ module.exports = ({
|
|
|
233
229
|
return row;
|
|
234
230
|
}),
|
|
235
231
|
};
|
|
236
|
-
|
|
237
232
|
} catch (err) {
|
|
238
233
|
return {
|
|
239
234
|
// @ts-ignore
|
|
@@ -245,4 +240,4 @@ module.exports = ({
|
|
|
245
240
|
}
|
|
246
241
|
},
|
|
247
242
|
};
|
|
248
|
-
};
|
|
243
|
+
};
|