@quillsql/node 0.2.3 → 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.
Files changed (2) hide show
  1. package/index.ts +62 -31
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -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
- "https://quill-344421.uc.r.appspot.com/validate",
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
- "https://quill-344421.uc.r.appspot.com/config",
122
+ `${process.env.SERVER_URL}/config`,
121
123
  {
122
124
  params: {
123
125
  orgId,
@@ -132,7 +134,8 @@ module.exports = ({
132
134
  let dashConfig = response.data;
133
135
  let newFilters = [];
134
136
 
135
- if (dashConfig.filters.length) {
137
+
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(
138
141
  dashConfig.filters[i].query
@@ -141,29 +144,45 @@ module.exports = ({
141
144
  newFilters.push({ ...dashConfig.filters[i], options: rows });
142
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;
149
153
 
154
+ if (newQueries) {
150
155
  for (const newQuery of newQueries) {
151
156
  const { query } = newQuery
152
- const cacheKey = `config:${orgId}:${newQuery._id}`;
157
+ const cacheKey = `config:${orgId}:${newQuery._id}}`;
153
158
  setCache(cacheKey, {fieldToRemove, query});
154
159
  };
160
+ }
161
+
155
162
  return {
156
163
  ...dashConfig
157
164
  };
158
- }
159
165
 
166
+ }
167
+ catch {
168
+ return {
169
+ // @ts-ignore
170
+ ...err,
171
+ // @ts-ignore
172
+ errorMessage: err && err.message ? err.message : "",
173
+ };
174
+ }
175
+ }
176
+
160
177
  if (task === "create") {
178
+ try {
161
179
  const response = await axios.post(
162
- "https://quill-344421.uc.r.appspot.com/item",
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,13 +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
 
178
207
  const {filters } = metadata;
208
+ console.log(filters);
179
209
 
180
210
  const resp = await axios.get(
181
- "https://quill-344421.uc.r.appspot.com/selfhostitem",
211
+ `${process.env.SERVER_URL}/selfhostitem`,
182
212
  {
183
213
  params: {
184
214
  id,
@@ -191,36 +221,37 @@ module.exports = ({
191
221
  );
192
222
  let fieldToRemove : any, query;
193
223
 
194
- 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}`));
224
+ if (false && getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
225
+ ({fieldToRemove, query} = getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`));
200
226
  }
201
227
  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
228
+ const response = await axios.post(
229
+ `${process.env.SERVER_URL}/validate`,
230
+ {
231
+ dashboardItemId: id,
232
+ query: resp.data.queryString,
233
+ filters: filters,
234
+ orgId: orgId
209
235
  },
210
- headers: {
211
- Authorization: `Bearer ${privateKey}`,
212
- },
213
- }
214
- );
215
- ({ fieldToRemove, query } = response.data);
236
+ {
237
+ headers: {
238
+ Authorization: `Bearer ${privateKey}`
239
+ }
240
+ }
241
+ );
216
242
 
217
-
243
+
244
+
245
+ ({ fieldToRemove, query } = response.data);
218
246
 
219
- const cacheKey = `config:${orgId}:${id}`;
247
+ const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
220
248
  setCache(cacheKey, {fieldToRemove, query});
221
249
  };
222
- const queryResult = await targetPool.query(query);
250
+
223
251
 
252
+ const queryResult = await targetPool.query(query);
253
+
254
+
224
255
  return {
225
256
  ...resp.data,
226
257
  fields: queryResult.fields.filter(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Quill SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {