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