@quillsql/node 0.2.6 → 0.2.7

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 (3) hide show
  1. package/index.js +13 -14
  2. package/index.ts +106 -112
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -23,7 +23,7 @@ function getCache(key) {
23
23
  module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnectionString, }) => {
24
24
  const pool = new Pool({
25
25
  connectionString: databaseConnectionString,
26
- ssl: { rejectUnauthorized: false }
26
+ ssl: { rejectUnauthorized: false },
27
27
  });
28
28
  const stagingPool = new Pool({
29
29
  connectionString: stagingDatabaseConnectionString,
@@ -34,10 +34,11 @@ module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnect
34
34
  const { task, query, id } = metadata;
35
35
  if (task === "query") {
36
36
  try {
37
- const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query: query }, {
38
- params: {
39
- orgId,
40
- },
37
+ const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", {
38
+ query: query,
39
+ orgId: orgId,
40
+ filters: [],
41
+ }, {
41
42
  headers: {
42
43
  Authorization: `Bearer ${privateKey}`,
43
44
  },
@@ -89,7 +90,6 @@ module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnect
89
90
  const cacheKey = `config:${orgId}:${newQuery._id}}`;
90
91
  setCache(cacheKey, { fieldToRemove, query });
91
92
  }
92
- ;
93
93
  }
94
94
  return Object.assign({}, dashConfig);
95
95
  }
@@ -104,7 +104,7 @@ module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnect
104
104
  const response = yield axios.post("https://quill-344421.uc.r.appspot.com/item", Object.assign({}, metadata), {
105
105
  params: {
106
106
  orgId,
107
- query
107
+ query,
108
108
  },
109
109
  headers: {
110
110
  Authorization: `Bearer ${privateKey}`,
@@ -131,7 +131,8 @@ module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnect
131
131
  },
132
132
  });
133
133
  let fieldToRemove, query;
134
- if (false && getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
134
+ if (false &&
135
+ getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
135
136
  ({ fieldToRemove, query } = getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`));
136
137
  }
137
138
  else {
@@ -139,20 +140,18 @@ module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnect
139
140
  dashboardItemId: id,
140
141
  query: resp.data.queryString,
141
142
  filters: filters,
142
- orgId: orgId
143
+ orgId: orgId,
143
144
  }, {
144
145
  headers: {
145
- Authorization: `Bearer ${privateKey}`
146
- }
146
+ Authorization: `Bearer ${privateKey}`,
147
+ },
147
148
  });
148
149
  ({ fieldToRemove, query } = response.data);
149
150
  const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
150
151
  setCache(cacheKey, { fieldToRemove, query });
151
152
  }
152
- ;
153
153
  const queryResult = yield targetPool.query(query);
154
- return Object.assign(Object.assign({}, resp.data), { fields: queryResult.fields
155
- .filter(
154
+ return Object.assign(Object.assign({}, resp.data), { fields: queryResult.fields.filter(
156
155
  // @ts-ignore
157
156
  (field) => field.name !== fieldToRemove),
158
157
  // @ts-ignore
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
 
@@ -70,7 +70,7 @@ module.exports = ({
70
70
  }: QuillConfig) => {
71
71
  const pool = new Pool({
72
72
  connectionString: databaseConnectionString,
73
- ssl: {rejectUnauthorized: false}
73
+ ssl: { rejectUnauthorized: false },
74
74
  });
75
75
  const stagingPool = new Pool({
76
76
  connectionString: stagingDatabaseConnectionString,
@@ -82,19 +82,20 @@ module.exports = ({
82
82
 
83
83
  if (task === "query") {
84
84
  try {
85
- const response = await axios.post(
86
- "https://quill-344421.uc.r.appspot.com/validate",
87
- { query: query },
88
- {
89
- params: {
90
- orgId,
91
- },
92
- headers: {
93
- Authorization: `Bearer ${privateKey}`,
85
+ const response = await axios.post(
86
+ "https://quill-344421.uc.r.appspot.com/validate",
87
+ {
88
+ query: query,
89
+ orgId: orgId,
90
+ filters: [],
94
91
  },
95
- }
96
- );
97
- const { fieldToRemove } = response.data;
92
+ {
93
+ headers: {
94
+ Authorization: `Bearer ${privateKey}`,
95
+ },
96
+ }
97
+ );
98
+ const { fieldToRemove } = response.data;
98
99
  const queryResult = await targetPool.query(response.data.query);
99
100
  return {
100
101
  ...queryResult,
@@ -119,93 +120,87 @@ module.exports = ({
119
120
  }
120
121
  if (task === "config") {
121
122
  try {
122
- const response = await axios.get(
123
- "https://quill-344421.uc.r.appspot.com/config",
124
- {
125
- params: {
126
- orgId,
127
- // @ts-ignore
128
- name: metadata?.name,
129
- },
130
- headers: {
131
- Authorization: `Bearer ${privateKey}`,
132
- },
133
- }
134
- );
135
- let dashConfig = response.data;
136
- let newFilters = [];
137
-
138
-
139
- if (dashConfig.filters && dashConfig.filters.length) {
140
- for (let i = 0; i < dashConfig.filters.length; i++) {
141
- const queryResult = await targetPool.query(
142
- dashConfig.filters[i].query
143
- );
144
- const { rows } = queryResult;
145
- newFilters.push({ ...dashConfig.filters[i], options: rows });
146
- dashConfig.filters[i].options = rows
123
+ const response = await axios.get(
124
+ "https://quill-344421.uc.r.appspot.com/config",
125
+ {
126
+ params: {
127
+ orgId,
128
+ // @ts-ignore
129
+ name: metadata?.name,
130
+ },
131
+ headers: {
132
+ Authorization: `Bearer ${privateKey}`,
133
+ },
134
+ }
135
+ );
136
+ let dashConfig = response.data;
137
+ let newFilters = [];
138
+
139
+ if (dashConfig.filters && dashConfig.filters.length) {
140
+ for (let i = 0; i < dashConfig.filters.length; i++) {
141
+ const queryResult = await targetPool.query(
142
+ dashConfig.filters[i].query
143
+ );
144
+ const { rows } = queryResult;
145
+ newFilters.push({ ...dashConfig.filters[i], options: rows });
146
+ dashConfig.filters[i].options = rows;
147
+ }
147
148
  }
148
-
149
- }
150
149
 
151
- dashConfig = { ...dashConfig, filters: newFilters };
150
+ dashConfig = { ...dashConfig, filters: newFilters };
152
151
 
153
- const { fieldToRemove, newQueries } = response.data;
154
-
155
- if (newQueries) {
156
- for (const newQuery of newQueries) {
157
- const { query } = newQuery
158
- const cacheKey = `config:${orgId}:${newQuery._id}}`;
159
- setCache(cacheKey, {fieldToRemove, query});
160
- };
161
- }
162
-
163
- return {
164
- ...dashConfig
165
- };
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
+ }
166
161
 
162
+ return {
163
+ ...dashConfig,
164
+ };
165
+ } catch {
166
+ return {
167
+ // @ts-ignore
168
+ ...err,
169
+ // @ts-ignore
170
+ errorMessage: err && err.message ? err.message : "",
171
+ };
167
172
  }
168
- catch {
169
- return {
170
- // @ts-ignore
171
- ...err,
172
- // @ts-ignore
173
- errorMessage: err && err.message ? err.message : "",
174
- };
175
173
  }
176
- }
177
-
174
+
178
175
  if (task === "create") {
179
176
  try {
180
- const response = await axios.post(
181
- "https://quill-344421.uc.r.appspot.com/item",
182
- { ...metadata },
183
- {
184
- params: {
185
- orgId,
186
- query
187
- },
188
- headers: {
189
- Authorization: `Bearer ${privateKey}`,
190
- },
191
- }
192
- );
193
- return response.data;
194
- }
195
- catch {
196
- return {
197
- // @ts-ignore
198
- ...err,
199
- // @ts-ignore
200
- errorMessage: err && err.message ? err.message : "",
201
- };
177
+ const response = await axios.post(
178
+ "https://quill-344421.uc.r.appspot.com/item",
179
+ { ...metadata },
180
+ {
181
+ params: {
182
+ orgId,
183
+ query,
184
+ },
185
+ headers: {
186
+ Authorization: `Bearer ${privateKey}`,
187
+ },
188
+ }
189
+ );
190
+ return response.data;
191
+ } catch {
192
+ return {
193
+ // @ts-ignore
194
+ ...err,
195
+ // @ts-ignore
196
+ errorMessage: err && err.message ? err.message : "",
197
+ };
198
+ }
202
199
  }
203
- }
204
200
 
205
201
  if (task === "item") {
206
202
  try {
207
-
208
- const {filters } = metadata;
203
+ const { filters } = metadata;
209
204
  const resp = await axios.get(
210
205
  "https://quill-344421.uc.r.appspot.com/selfhostitem",
211
206
  {
@@ -218,42 +213,42 @@ module.exports = ({
218
213
  },
219
214
  }
220
215
  );
221
- let fieldToRemove : any, query;
216
+ let fieldToRemove: any, query;
222
217
 
223
-
224
- if (false && getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
225
- ({fieldToRemove, query} = getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`));
226
- }
227
- else {
218
+ if (
219
+ false &&
220
+ getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)
221
+ ) {
222
+ ({ fieldToRemove, query } = getCache(
223
+ `config:${orgId}:${id}:${JSON.stringify(filters)}`
224
+ ));
225
+ } else {
228
226
  const response = await axios.post(
229
227
  "https://quill-344421.uc.r.appspot.com/validate",
230
- {
228
+ {
231
229
  dashboardItemId: id,
232
230
  query: resp.data.queryString,
233
231
  filters: filters,
234
- orgId: orgId
232
+ orgId: orgId,
235
233
  },
236
234
  {
237
235
  headers: {
238
- Authorization: `Bearer ${privateKey}`
239
- }
236
+ Authorization: `Bearer ${privateKey}`,
237
+ },
240
238
  }
241
239
  );
242
240
 
243
-
241
+ ({ fieldToRemove, query } = response.data);
244
242
 
245
- ({ fieldToRemove, query } = response.data);
243
+ const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
244
+ setCache(cacheKey, { fieldToRemove, query });
245
+ }
246
246
 
247
- const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
248
- setCache(cacheKey, {fieldToRemove, query});
249
- };
250
-
251
247
  const queryResult = await targetPool.query(query);
252
-
248
+
253
249
  return {
254
250
  ...resp.data,
255
- fields: queryResult.fields
256
- .filter(
251
+ fields: queryResult.fields.filter(
257
252
  // @ts-ignore
258
253
  (field) => field.name !== fieldToRemove
259
254
  ),
@@ -263,7 +258,6 @@ module.exports = ({
263
258
  return row;
264
259
  }),
265
260
  };
266
-
267
261
  } catch (err) {
268
262
  return {
269
263
  // @ts-ignore
@@ -275,4 +269,4 @@ module.exports = ({
275
269
  }
276
270
  },
277
271
  };
278
- };
272
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Quill SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {