@quillsql/node 0.2.0 → 0.2.2
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.js +28 -17
- package/index.ts +37 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const axios = require("axios");
|
|
|
13
13
|
var PgError = require("pg-error");
|
|
14
14
|
Connection.prototype.parseE = PgError.parse;
|
|
15
15
|
Connection.prototype.parseN = PgError.parse;
|
|
16
|
-
module.exports = ({
|
|
16
|
+
module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnectionString, }) => {
|
|
17
17
|
const pool = new Pool({
|
|
18
18
|
connectionString: databaseConnectionString,
|
|
19
19
|
});
|
|
@@ -27,16 +27,23 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
27
27
|
if (task === "query") {
|
|
28
28
|
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query: query }, {
|
|
29
29
|
params: {
|
|
30
|
-
publicKey,
|
|
31
30
|
orgId,
|
|
32
31
|
},
|
|
33
32
|
headers: {
|
|
34
33
|
Authorization: `Bearer ${privateKey}`,
|
|
35
34
|
},
|
|
36
35
|
});
|
|
36
|
+
const { fieldToRemove } = response.data;
|
|
37
37
|
try {
|
|
38
38
|
const queryResult = yield targetPool.query(response.data.query);
|
|
39
|
-
return queryResult
|
|
39
|
+
return Object.assign(Object.assign({}, queryResult), { fields: queryResult.fields.filter(
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
(field) => field.name !== fieldToRemove),
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
rows: queryResult.rows.map((row) => {
|
|
44
|
+
delete row[fieldToRemove];
|
|
45
|
+
return row;
|
|
46
|
+
}) });
|
|
40
47
|
}
|
|
41
48
|
catch (err) {
|
|
42
49
|
return Object.assign(Object.assign({}, err), {
|
|
@@ -47,7 +54,6 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
47
54
|
if (task === "config") {
|
|
48
55
|
const response = yield axios.get("https://quill-344421.uc.r.appspot.com/config", {
|
|
49
56
|
params: {
|
|
50
|
-
publicKey,
|
|
51
57
|
orgId,
|
|
52
58
|
// @ts-ignore
|
|
53
59
|
name: metadata === null || metadata === void 0 ? void 0 : metadata.name,
|
|
@@ -71,7 +77,6 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
71
77
|
if (task === "create") {
|
|
72
78
|
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/item", Object.assign({}, metadata), {
|
|
73
79
|
params: {
|
|
74
|
-
publicKey,
|
|
75
80
|
orgId,
|
|
76
81
|
},
|
|
77
82
|
headers: {
|
|
@@ -81,28 +86,34 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
81
86
|
return response.data;
|
|
82
87
|
}
|
|
83
88
|
if (task === "item") {
|
|
84
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query }, {
|
|
85
|
-
params: {
|
|
86
|
-
publicKey,
|
|
87
|
-
orgId,
|
|
88
|
-
},
|
|
89
|
-
headers: {
|
|
90
|
-
Authorization: `Bearer ${privateKey}`,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
89
|
try {
|
|
94
|
-
const queryResult = yield targetPool.query(response.data.query);
|
|
95
90
|
const resp = yield axios.get("https://quill-344421.uc.r.appspot.com/selfhostitem", {
|
|
96
91
|
params: {
|
|
97
92
|
id,
|
|
98
93
|
orgId,
|
|
99
|
-
publicKey,
|
|
100
94
|
},
|
|
101
95
|
headers: {
|
|
102
96
|
Authorization: `Bearer ${privateKey}`,
|
|
103
97
|
},
|
|
104
98
|
});
|
|
105
|
-
|
|
99
|
+
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query: resp.data.queryString }, {
|
|
100
|
+
params: {
|
|
101
|
+
orgId,
|
|
102
|
+
},
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: `Bearer ${privateKey}`,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
const { fieldToRemove } = response.data;
|
|
108
|
+
const queryResult = yield targetPool.query(response.data.query);
|
|
109
|
+
return Object.assign(Object.assign({}, resp.data), { fields: queryResult.fields.filter(
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
(field) => field.name !== fieldToRemove),
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
rows: queryResult.rows.map((row) => {
|
|
114
|
+
delete row[fieldToRemove];
|
|
115
|
+
return row;
|
|
116
|
+
}) });
|
|
106
117
|
}
|
|
107
118
|
catch (err) {
|
|
108
119
|
return Object.assign(Object.assign({}, err), {
|
package/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ Connection.prototype.parseE = PgError.parse;
|
|
|
5
5
|
Connection.prototype.parseN = PgError.parse;
|
|
6
6
|
|
|
7
7
|
interface QuillConfig {
|
|
8
|
-
publicKey: string;
|
|
9
8
|
privateKey: string;
|
|
10
9
|
databaseConnectionString: string;
|
|
11
10
|
stagingDatabaseConnectionString?: string;
|
|
@@ -49,6 +48,7 @@ interface QuillRequestMetadata {
|
|
|
49
48
|
dashboardName?: string;
|
|
50
49
|
columns?: FormattedColumn[];
|
|
51
50
|
dateField?: { table: string; field: string };
|
|
51
|
+
template?: boolean;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
interface QuillQueryParams {
|
|
@@ -58,7 +58,6 @@ interface QuillQueryParams {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
module.exports = ({
|
|
61
|
-
publicKey,
|
|
62
61
|
privateKey,
|
|
63
62
|
databaseConnectionString,
|
|
64
63
|
stagingDatabaseConnectionString,
|
|
@@ -81,7 +80,6 @@ module.exports = ({
|
|
|
81
80
|
{ query: query },
|
|
82
81
|
{
|
|
83
82
|
params: {
|
|
84
|
-
publicKey,
|
|
85
83
|
orgId,
|
|
86
84
|
},
|
|
87
85
|
headers: {
|
|
@@ -89,9 +87,21 @@ module.exports = ({
|
|
|
89
87
|
},
|
|
90
88
|
}
|
|
91
89
|
);
|
|
90
|
+
const { fieldToRemove } = response.data;
|
|
92
91
|
try {
|
|
93
92
|
const queryResult = await targetPool.query(response.data.query);
|
|
94
|
-
return
|
|
93
|
+
return {
|
|
94
|
+
...queryResult,
|
|
95
|
+
fields: queryResult.fields.filter(
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
(field) => field.name !== fieldToRemove
|
|
98
|
+
),
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
rows: queryResult.rows.map((row) => {
|
|
101
|
+
delete row[fieldToRemove];
|
|
102
|
+
return row;
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
95
105
|
} catch (err) {
|
|
96
106
|
return {
|
|
97
107
|
// @ts-ignore
|
|
@@ -107,7 +117,6 @@ module.exports = ({
|
|
|
107
117
|
"https://quill-344421.uc.r.appspot.com/config",
|
|
108
118
|
{
|
|
109
119
|
params: {
|
|
110
|
-
publicKey,
|
|
111
120
|
orgId,
|
|
112
121
|
// @ts-ignore
|
|
113
122
|
name: metadata?.name,
|
|
@@ -138,7 +147,6 @@ module.exports = ({
|
|
|
138
147
|
{ ...metadata },
|
|
139
148
|
{
|
|
140
149
|
params: {
|
|
141
|
-
publicKey,
|
|
142
150
|
orgId,
|
|
143
151
|
},
|
|
144
152
|
headers: {
|
|
@@ -150,38 +158,44 @@ module.exports = ({
|
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
if (task === "item") {
|
|
153
|
-
const response = await axios.post(
|
|
154
|
-
"https://quill-344421.uc.r.appspot.com/validate",
|
|
155
|
-
{ query },
|
|
156
|
-
{
|
|
157
|
-
params: {
|
|
158
|
-
publicKey,
|
|
159
|
-
orgId,
|
|
160
|
-
},
|
|
161
|
-
headers: {
|
|
162
|
-
Authorization: `Bearer ${privateKey}`,
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
161
|
try {
|
|
167
|
-
const queryResult = await targetPool.query(response.data.query);
|
|
168
162
|
const resp = await axios.get(
|
|
169
163
|
"https://quill-344421.uc.r.appspot.com/selfhostitem",
|
|
170
164
|
{
|
|
171
165
|
params: {
|
|
172
166
|
id,
|
|
173
167
|
orgId,
|
|
174
|
-
publicKey,
|
|
175
168
|
},
|
|
176
169
|
headers: {
|
|
177
170
|
Authorization: `Bearer ${privateKey}`,
|
|
178
171
|
},
|
|
179
172
|
}
|
|
180
173
|
);
|
|
174
|
+
const response = await axios.post(
|
|
175
|
+
"https://quill-344421.uc.r.appspot.com/validate",
|
|
176
|
+
{ query: resp.data.queryString },
|
|
177
|
+
{
|
|
178
|
+
params: {
|
|
179
|
+
orgId,
|
|
180
|
+
},
|
|
181
|
+
headers: {
|
|
182
|
+
Authorization: `Bearer ${privateKey}`,
|
|
183
|
+
},
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
const { fieldToRemove } = response.data;
|
|
187
|
+
const queryResult = await targetPool.query(response.data.query);
|
|
181
188
|
return {
|
|
182
189
|
...resp.data,
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
fields: queryResult.fields.filter(
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
(field) => field.name !== fieldToRemove
|
|
193
|
+
),
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
rows: queryResult.rows.map((row) => {
|
|
196
|
+
delete row[fieldToRemove];
|
|
197
|
+
return row;
|
|
198
|
+
}),
|
|
185
199
|
};
|
|
186
200
|
} catch (err) {
|
|
187
201
|
return {
|