@quillsql/node 0.1.8 → 0.2.0
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 +38 -23
- package/index.ts +4 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,10 +21,11 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
21
21
|
connectionString: stagingDatabaseConnectionString,
|
|
22
22
|
});
|
|
23
23
|
return {
|
|
24
|
-
query: ({ orgId,
|
|
24
|
+
query: ({ orgId, metadata, environment }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
const targetPool = environment === "STAGING" ? stagingPool : pool;
|
|
26
|
+
const { task, query, id } = metadata;
|
|
26
27
|
if (task === "query") {
|
|
27
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query }, {
|
|
28
|
+
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query: query }, {
|
|
28
29
|
params: {
|
|
29
30
|
publicKey,
|
|
30
31
|
orgId,
|
|
@@ -44,21 +45,31 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
if (task === "config") {
|
|
47
|
-
const response = yield axios.get("https://quill-344421.uc.r.appspot.com/
|
|
48
|
+
const response = yield axios.get("https://quill-344421.uc.r.appspot.com/config", {
|
|
48
49
|
params: {
|
|
49
50
|
publicKey,
|
|
50
51
|
orgId,
|
|
51
52
|
// @ts-ignore
|
|
52
|
-
name:
|
|
53
|
+
name: metadata === null || metadata === void 0 ? void 0 : metadata.name,
|
|
53
54
|
},
|
|
54
55
|
headers: {
|
|
55
56
|
Authorization: `Bearer ${privateKey}`,
|
|
56
57
|
},
|
|
57
58
|
});
|
|
58
|
-
|
|
59
|
+
let dashConfig = response.data;
|
|
60
|
+
if (dashConfig.filters.length) {
|
|
61
|
+
for (let i = 0; i < dashConfig.filters.length; i++) {
|
|
62
|
+
// parse query
|
|
63
|
+
// run query
|
|
64
|
+
const queryResult = yield targetPool.query(dashConfig.filters[i].query);
|
|
65
|
+
const { rows } = queryResult;
|
|
66
|
+
dashConfig = { options: rows };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return dashConfig;
|
|
59
70
|
}
|
|
60
71
|
if (task === "create") {
|
|
61
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/item", {
|
|
72
|
+
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/item", Object.assign({}, metadata), {
|
|
62
73
|
params: {
|
|
63
74
|
publicKey,
|
|
64
75
|
orgId,
|
|
@@ -70,30 +81,34 @@ module.exports = ({ publicKey, privateKey, databaseConnectionString, stagingData
|
|
|
70
81
|
return response.data;
|
|
71
82
|
}
|
|
72
83
|
if (task === "item") {
|
|
73
|
-
const response = yield axios.
|
|
74
|
-
params: filters && filters.length
|
|
75
|
-
? {
|
|
76
|
-
publicKey,
|
|
77
|
-
orgId,
|
|
78
|
-
filters,
|
|
79
|
-
}
|
|
80
|
-
: { publicKey, orgId },
|
|
81
|
-
headers: {
|
|
82
|
-
Authorization: `Bearer ${privateKey}`,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
const queryResult = yield targetPool.query(response.data.query);
|
|
86
|
-
const resp = yield axios.get("https://quill-344421.uc.r.appspot.com/selfhostitem", {
|
|
84
|
+
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", { query }, {
|
|
87
85
|
params: {
|
|
88
|
-
id,
|
|
89
|
-
orgId,
|
|
90
86
|
publicKey,
|
|
87
|
+
orgId,
|
|
91
88
|
},
|
|
92
89
|
headers: {
|
|
93
90
|
Authorization: `Bearer ${privateKey}`,
|
|
94
91
|
},
|
|
95
92
|
});
|
|
96
|
-
|
|
93
|
+
try {
|
|
94
|
+
const queryResult = yield targetPool.query(response.data.query);
|
|
95
|
+
const resp = yield axios.get("https://quill-344421.uc.r.appspot.com/selfhostitem", {
|
|
96
|
+
params: {
|
|
97
|
+
id,
|
|
98
|
+
orgId,
|
|
99
|
+
publicKey,
|
|
100
|
+
},
|
|
101
|
+
headers: {
|
|
102
|
+
Authorization: `Bearer ${privateKey}`,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
return Object.assign(Object.assign({}, resp.data), { rows: queryResult.rows, fields: queryResult.fields });
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
return Object.assign(Object.assign({}, err), {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
errorMessage: err && err.message ? err.message : "" });
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
113
|
}),
|
|
99
114
|
};
|
package/index.ts
CHANGED
|
@@ -53,9 +53,6 @@ interface QuillRequestMetadata {
|
|
|
53
53
|
|
|
54
54
|
interface QuillQueryParams {
|
|
55
55
|
orgId: string;
|
|
56
|
-
query?: string;
|
|
57
|
-
filters?: any[];
|
|
58
|
-
id?: string;
|
|
59
56
|
metadata: QuillRequestMetadata;
|
|
60
57
|
environment?: string;
|
|
61
58
|
}
|
|
@@ -74,21 +71,14 @@ module.exports = ({
|
|
|
74
71
|
});
|
|
75
72
|
|
|
76
73
|
return {
|
|
77
|
-
query: async ({
|
|
78
|
-
orgId,
|
|
79
|
-
query,
|
|
80
|
-
filters,
|
|
81
|
-
id,
|
|
82
|
-
metadata,
|
|
83
|
-
environment,
|
|
84
|
-
}: QuillQueryParams) => {
|
|
74
|
+
query: async ({ orgId, metadata, environment }: QuillQueryParams) => {
|
|
85
75
|
const targetPool = environment === "STAGING" ? stagingPool : pool;
|
|
86
|
-
const { task } = metadata;
|
|
76
|
+
const { task, query, id } = metadata;
|
|
87
77
|
|
|
88
78
|
if (task === "query") {
|
|
89
79
|
const response = await axios.post(
|
|
90
80
|
"https://quill-344421.uc.r.appspot.com/validate",
|
|
91
|
-
{ query:
|
|
81
|
+
{ query: query },
|
|
92
82
|
{
|
|
93
83
|
params: {
|
|
94
84
|
publicKey,
|
|
@@ -162,7 +152,7 @@ module.exports = ({
|
|
|
162
152
|
if (task === "item") {
|
|
163
153
|
const response = await axios.post(
|
|
164
154
|
"https://quill-344421.uc.r.appspot.com/validate",
|
|
165
|
-
{ query
|
|
155
|
+
{ query },
|
|
166
156
|
{
|
|
167
157
|
params: {
|
|
168
158
|
publicKey,
|