@quillsql/node 0.2.4 → 0.2.5
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 +74 -38
- 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: any = {}; //set the cache
|
|
7
|
+
const cache : any = {}; //set the cache
|
|
8
8
|
|
|
9
|
-
function setCache(key: any, value: any) {
|
|
9
|
+
function setCache(key : any, value : any) {
|
|
10
10
|
cache[key] = value;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function getCache(key: any) {
|
|
13
|
+
function getCache(key : any) {
|
|
14
14
|
return cache[key];
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,6 +19,7 @@ interface QuillConfig {
|
|
|
19
19
|
databaseConnectionString: string;
|
|
20
20
|
stagingDatabaseConnectionString?: string;
|
|
21
21
|
}
|
|
22
|
+
|
|
22
23
|
type FieldFormat =
|
|
23
24
|
| "whole_number"
|
|
24
25
|
| "one_decimal_place"
|
|
@@ -79,8 +80,9 @@ module.exports = ({
|
|
|
79
80
|
const { task, query, id } = metadata;
|
|
80
81
|
|
|
81
82
|
if (task === "query") {
|
|
83
|
+
try {
|
|
82
84
|
const response = await axios.post(
|
|
83
|
-
|
|
85
|
+
`${process.env.SERVER_URL}/validate`,
|
|
84
86
|
{ query: query },
|
|
85
87
|
{
|
|
86
88
|
params: {
|
|
@@ -89,10 +91,9 @@ module.exports = ({
|
|
|
89
91
|
headers: {
|
|
90
92
|
Authorization: `Bearer ${privateKey}`,
|
|
91
93
|
},
|
|
92
|
-
}
|
|
94
|
+
}
|
|
93
95
|
);
|
|
94
96
|
const { fieldToRemove } = response.data;
|
|
95
|
-
try {
|
|
96
97
|
const queryResult = await targetPool.query(response.data.query);
|
|
97
98
|
return {
|
|
98
99
|
...queryResult,
|
|
@@ -116,8 +117,9 @@ module.exports = ({
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
if (task === "config") {
|
|
120
|
+
try {
|
|
119
121
|
const response = await axios.get(
|
|
120
|
-
|
|
122
|
+
`${process.env.SERVER_URL}/config`,
|
|
121
123
|
{
|
|
122
124
|
params: {
|
|
123
125
|
orgId,
|
|
@@ -131,7 +133,8 @@ module.exports = ({
|
|
|
131
133
|
);
|
|
132
134
|
let dashConfig = response.data;
|
|
133
135
|
let newFilters = [];
|
|
134
|
-
|
|
136
|
+
|
|
137
|
+
|
|
135
138
|
if (dashConfig.filters && dashConfig.filters.length) {
|
|
136
139
|
for (let i = 0; i < dashConfig.filters.length; i++) {
|
|
137
140
|
const queryResult = await targetPool.query(
|
|
@@ -139,31 +142,47 @@ module.exports = ({
|
|
|
139
142
|
);
|
|
140
143
|
const { rows } = queryResult;
|
|
141
144
|
newFilters.push({ ...dashConfig.filters[i], options: rows });
|
|
142
|
-
dashConfig.filters[i].options = rows
|
|
145
|
+
dashConfig.filters[i].options = rows
|
|
143
146
|
}
|
|
147
|
+
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
dashConfig = { ...dashConfig, filters: newFilters };
|
|
147
151
|
|
|
148
152
|
const { fieldToRemove, newQueries } = response.data;
|
|
153
|
+
|
|
154
|
+
if (newQueries) {
|
|
155
|
+
for (const newQuery of newQueries) {
|
|
156
|
+
const { query } = newQuery
|
|
157
|
+
const cacheKey = `config:${orgId}:${newQuery._id}}`;
|
|
158
|
+
setCache(cacheKey, {fieldToRemove, query});
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
...dashConfig
|
|
164
|
+
};
|
|
149
165
|
|
|
150
|
-
for (const newQuery of newQueries) {
|
|
151
|
-
const { query } = newQuery;
|
|
152
|
-
const cacheKey = `config:${orgId}:${newQuery._id}`;
|
|
153
|
-
setCache(cacheKey, { fieldToRemove, query });
|
|
154
166
|
}
|
|
167
|
+
catch {
|
|
155
168
|
return {
|
|
156
|
-
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
...err,
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
errorMessage: err && err.message ? err.message : "",
|
|
157
173
|
};
|
|
158
174
|
}
|
|
159
|
-
|
|
175
|
+
}
|
|
176
|
+
|
|
160
177
|
if (task === "create") {
|
|
178
|
+
try {
|
|
161
179
|
const response = await axios.post(
|
|
162
|
-
|
|
180
|
+
`${process.env.SERVER_URL}/item`,
|
|
163
181
|
{ ...metadata },
|
|
164
182
|
{
|
|
165
183
|
params: {
|
|
166
184
|
orgId,
|
|
185
|
+
query
|
|
167
186
|
},
|
|
168
187
|
headers: {
|
|
169
188
|
Authorization: `Bearer ${privateKey}`,
|
|
@@ -172,12 +191,24 @@ module.exports = ({
|
|
|
172
191
|
);
|
|
173
192
|
return response.data;
|
|
174
193
|
}
|
|
194
|
+
catch {
|
|
195
|
+
return {
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
...err,
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
errorMessage: err && err.message ? err.message : "",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
175
204
|
if (task === "item") {
|
|
176
205
|
try {
|
|
177
|
-
|
|
206
|
+
|
|
207
|
+
const {filters } = metadata;
|
|
208
|
+
console.log(filters);
|
|
178
209
|
|
|
179
210
|
const resp = await axios.get(
|
|
180
|
-
|
|
211
|
+
`${process.env.SERVER_URL}/selfhostitem`,
|
|
181
212
|
{
|
|
182
213
|
params: {
|
|
183
214
|
id,
|
|
@@ -188,35 +219,39 @@ module.exports = ({
|
|
|
188
219
|
},
|
|
189
220
|
}
|
|
190
221
|
);
|
|
191
|
-
let fieldToRemove: any, query;
|
|
222
|
+
let fieldToRemove : any, query;
|
|
192
223
|
|
|
193
|
-
if (getCache(`config:${orgId}:${id}`)
|
|
194
|
-
getCache(`config:${orgId}:${id}`);
|
|
224
|
+
if (false && getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
|
|
225
|
+
({fieldToRemove, query} = getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`));
|
|
195
226
|
}
|
|
196
|
-
|
|
197
|
-
if (!filters && getCache(`config:${orgId}:${id}`)) {
|
|
198
|
-
({ fieldToRemove, query } = getCache(`config:${orgId}:${id}`));
|
|
199
|
-
} else {
|
|
227
|
+
else {
|
|
200
228
|
const response = await axios.post(
|
|
201
|
-
|
|
202
|
-
{
|
|
229
|
+
`${process.env.SERVER_URL}/validate`,
|
|
230
|
+
{
|
|
231
|
+
dashboardItemId: id,
|
|
232
|
+
query: resp.data.queryString,
|
|
233
|
+
filters: filters,
|
|
234
|
+
orgId: orgId
|
|
235
|
+
},
|
|
203
236
|
{
|
|
204
|
-
params: {
|
|
205
|
-
orgId,
|
|
206
|
-
filters,
|
|
207
|
-
},
|
|
208
237
|
headers: {
|
|
209
|
-
Authorization: `Bearer ${privateKey}
|
|
210
|
-
}
|
|
238
|
+
Authorization: `Bearer ${privateKey}`
|
|
239
|
+
}
|
|
211
240
|
}
|
|
212
241
|
);
|
|
213
|
-
({ fieldToRemove, query } = response.data);
|
|
214
242
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
({ fieldToRemove, query } = response.data);
|
|
246
|
+
|
|
247
|
+
const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
|
|
248
|
+
setCache(cacheKey, {fieldToRemove, query});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
|
|
218
252
|
const queryResult = await targetPool.query(query);
|
|
219
253
|
|
|
254
|
+
|
|
220
255
|
return {
|
|
221
256
|
...resp.data,
|
|
222
257
|
fields: queryResult.fields.filter(
|
|
@@ -229,6 +264,7 @@ module.exports = ({
|
|
|
229
264
|
return row;
|
|
230
265
|
}),
|
|
231
266
|
};
|
|
267
|
+
|
|
232
268
|
} catch (err) {
|
|
233
269
|
return {
|
|
234
270
|
// @ts-ignore
|
|
@@ -240,4 +276,4 @@ module.exports = ({
|
|
|
240
276
|
}
|
|
241
277
|
},
|
|
242
278
|
};
|
|
243
|
-
};
|
|
279
|
+
};
|